How can I extract MCC and MNC from PLMN?

I run the AT AT + KCELL command to get information about the cell, and it returns, among other things, PLMN ( Public Land and Mobile Network ) - a description of this from the documentation:

PLMN identifiers (3 bytes) made from MCC (Mobile Country Code) and MNC (Mobile Network Code).

OK, which corresponds to what Wikipedia says - there are MCC and MNC. Now I do not understand how to extract the above MCC and MNC values?

Here is an example. I'm coming back:

 32f210 

and they tell me (although I'm skeptical) that this should lead to:

 MNC: 1 MCC: 232 

but I can’t figure out for life how to get this result from PLMN, so how can I make it out?

+7
source share
2 answers

Well, I found this and thought that I would add an answer here if there is some other unsuccessful soul that should do this - a PDF called GSM Technical Specification (section 10.2.4) contains an answer corresponding to a bit:

PLMN Content: Mobile Country Code (MCC), followed by a Mobile Network Code (MNC). Coding: according to TS GSM 04.08 [14].

  • If the storage is for less than the maximum possible number n, the excess bytes should be set to 'FF'. For example, using 246 for MCC and 81 for MNC, and if it is the first and only PLMN, the contents read as follows: Bytes 1-3: '42' 'F6' '18' Bytes 4-6: 'FF' 'FF' ' Ff 'etc.

Therefore, I was wrong to be skeptical!

I need to read on the left, replacing the numbers around, so the first two bytes will be MCC, so that will be 232f , and MNC will be 01 , then I just canceled f, and I have 232 and 1! Glad he's sorted.

For example, in C # you can do it like this:

 string plmn = "whatever the plmn is"; string mcc = new string(plmn.Substring(0, 2).Reverse().ToArray()) + new string(plmn.Substring(2, 2).Reverse().ToArray()) .Replace('f', ' ') .Trim(); string mnc = new string(plmn.Substring(4, 2).Reverse().ToArray()) .Replace('f', ' ') .Trim(); 
+11
source

Here is the answer in Java with bitwise operations:

 public static String mcc(byte[] plmnId) { if (plmnId == null || plmnId.length != 3) throw new IllegalArgumentException(String.format("Wrong plmnid %s", Arrays.toString(plmnId))); int a1 = plmnId[0] & 0x0F; int a2 = (plmnId[0] & 0xF0) >> 4; int a3 = plmnId[1] & 0x0F; return "" + a1 + a2 + a3; } public static String mnc(byte[] plmnId) { if (plmnId == null || plmnId.length != 3) throw new IllegalArgumentException(String.format("Wrong plmnid %s", Arrays.toString(plmnId))); int a1 = plmnId[2] & 0x0F; int a2 = (plmnId[2] & 0xF0) >> 4; int a3 = (plmnId[1] & 0xF0) >> 4; if (a3 == 15) return "" + a1 + a2; else return "" + a1 + a2 + a3; } 
0
source

All Articles