APDU Structure & String Encoding for PNN in EF.PNN

Hi, I am having a hard time figuring out how to structure an APDU command to update the the first PNN record on a SIM, the main issue is the PNN specific data formatting and figuring out what it is expecting…

I have looked at the 3GPP specs TS 131 102 (go to page 62) TS 124 008 (go to page 537) and will paste a figure below ( I am a new user so I can embed only one…):

Using these my thought process has been the following:

APDU command for updating a record:
| CLA | INS | P1 | P2 | Lc | Data | Le |
| 00 | DC | 01 | 04 | Lc | data | ff |

DC = Update record
P1 = 0x01 specifies record 1 to be updated
P2 = 0x04 = 0 0 0 0 0 (first 5 bits 0 = currently selected EF) 1 0 0 (use Record number given in P1)
Lc = Length, bytes of data field.

Now the data field, this will follow the Network Name info element figure, where
first byte = Network Name IEI = 0x43 for updating the Full Network Name.
second byte = Length of Network Name contents in bytes.
third byte is where I am getting a bit stuck I believe. I am using it to set what I want the actual Full Network Name to be but it doesn’t seem to work.

FYI I have tried in pySIM but also a private tool that can send APDUs to SIMs…

Examples below of the data I want to update the record with:

43 04 48 45 4C 50 ff

where 48 45 4C 50 is just a hex string using GSM3.38 encoding…

with the APDU command this would potentially look like
00 DC 01 04 06 43 04 48 45 4C 50

I have also tried using the third octet defined in Table 10.5.94/3GPP TS 24.008 but that also doesn’t seem to be right.

If anyone has any ideas or guidance, I would be very thankful. Hopefully, this isn’t a silly ask, I am relatively new to the industry.

EDIT: aware it says to-do in the pysim source code for EF.PNN full and short network names

1 Like

Sadly I could not find anywhere in your post what exactly was the error you encountered when doing the above?

1 Like

also, you can avoid dealing with raw APDUs and simply use pySim-shells update_record command. This way you don’t need to worry about CLA/INS/P1/P2 and Lc values.

1 Like

Hello, what is the exact error code?

My guess is that you are not fully writing the record.
As stated in the specs it is compulsory to fully update the whole record.
So basically you need to know the record size and fully update it.
You should add GSM.filler 0xFF.
Good luck

1 Like

Yes, however when I read the record_decoded the output is purely in hex instead of decoded similar to the EF.SPN record_decoded and when I attach a UE with the SIM to a network, the configured PNN name doesn’t show up. Though, this could be down to the UE/ 5GC configuration.

With regards to your other response, the error I am seeing is 6700 (wrong length) when attempting to update the record with the APDU command.

Hi,
Thank you for this. Where about in the APDU command would you include the 0xFF though?

Hello,
you put the filler at the end, and you have to add as many 0xFF until you complete the record size.

so for example if your pnn in your profile is record size 9dec,
then the command would be:

00 DC 01 04 09 43 04 48 45 4C 50 FF FF FF

BR
Victor Moreno

In general I still think the proper solution for this problem is for someone to either write a patch (or fund the development of it) to implement the proper decode/encode of EF.PNN records in pySim-shell.

However, as a fall-back, I do think it would be a good idea for pySim-shell to offer a command-line option for raw/binary write commands update_record and update_binary which would add padding til EOF. Currently they only write the first number of bytes if given incomplete content.

I’ve created a feature ticket in Feature #6802: Implement --pad-with-ff option for update_{record,binary} commands - pySim - Open Source Mobile Communications so we don’t forget about it.

Once again, patches would be very welcome!

1 Like