Incorrect ICCID value from modem_info

Hi, I encountered an issue where I used modem_info_params_get() to retrieve and print various SIM values.
The ICCID value which can be of various length, contained an additional garbage character for me.

Expected a 18 digit value, but got 19 where the final "1" did not belong to the registered ICCID: xxxxxxxxxxxxxxxxxx1
Fixed this locally in my project by just memcpy to extract the 18 correct values, but thought I'd mention it here in case anyone else wonder why the printed ICCID is invalid.

Didn't look too closely on this, but ICCID in modem_info is of type AT_PARAM_TYPE_STRING and variable length 18-22 char, so I assumed the issue occurred somewhere in this handling, and moved on with my hotfix.

Tested on sdk-nrf v2.5.0 with nRF9160-DK and iBasis SIM card.

  • Hello, 

    What modem FW are you running on your nRF9160DK? Could you please provide some more details on when you are issuing modem_info_params_get()? Did you try AT%XICCID in the AT Client just to verify?

    Please provide more logs. 

    Kind regards,
    Øyvind

  • I did try to use AT%XICCID with the AT Client sample, but it only returns ERROR. I get a response from other commands such as AT+CFUN?

    I am using nRF Connect SDK 2.5.0 with Modem Firmware v1.3.5

    While I can't go too much into detail on the code, I will try to explain the relevant parts of what happens.
    The sequence of what happens (that seems relevant for this):

    - waiting indefinitely while network_lte_is_connected() returns false
    - various init, net_if, etc
    - run modem_info_init()
    - run modem_info_params_init(&modem_info)
    - run lte_print_stats function I made:

    	if (!lte_info_is_connected()) {
    		return;
    	}
    
    	int err = modem_info_params_get(&modem_info);
    	if (err != 0) {
    		LOG_ERR("Failed to get params, errno: %d", err);
    		return;
    	}
    
    	char *iccid = modem_info.sim.iccid.value_string;
    	char *imsi = modem_info.sim.imsi.value_string;
    	char *imei = modem_info.device.imei.value_string;
    	
    	LOG_INF("ICCID:%s, IMSI:%s, IMEI:%s", iccid, imsi, imei);

    And below is a portion of the log (removed unrelated modules and censored certain values):

    *** Booting nRF Connect SDK v2.5.0 ***
    Attempting to boot slot 0.
    Attempting to boot from address 0x8200.
    Verifying signature against key 0.
    Hash: <censored>
    Firmware signature verified.
    Firmware version 1
    Setting monotonic counter (version: 1, slot: 0)
    *** Booting nRF Connect SDK v2.5.0 ***
    *** Booting nRF Connect SDK v2.5.0 ***
    [00:00:00.264,434] <inf> MAIN: Waiting for lte connection.
    [00:00:00.264,678] <inf> network: Bringing network interface up and connecting to the network
    +CEREG: 2,"816B","014A4703",7
    +CSCON: 1
    +CGEV: ME PDN ACT 0,0
    +CNEC_ESM: 50,0
    +CEREG: 5,"816B","014A4703",7,,,"11100000","11100000"
    [00:00:04.912,902] <inf> network: Network connectivity established
    %XTIME: "40","42207080655340","00"
    [00:00:05.265,472] <inf> MAIN: Lte connection established
    [00:00:05.329,772] <inf> lte_info: ICCID:<censored, value is correct but has a "1" at end that should not exist>, IMSI:<censored>, IMEI:<censored>

  • The ICCID is read from the SIM card, which requires, that the modem is enabled (e.g. CFUN=1 for normal operation or CFUN=41 for SIM only).

    You may read it with some low level cmds, e.g.:

    >AT+CRSM=176,12258,0,0,10
    +CRSM: 144,0,"985317015002405498F6"

    (File 12258 => 2FE2)

    or with

    >AT%XICCID
    %XICCID: 8935711005200445896F

    You may have already noticed, that the hexdigits of the bytes are swapped.

    A "traditional" ICCID itself contains 18 digits and 1 checksum digit. If you put that into 10 bytes in swapped order, the last byte will be "xC", where x is "whatever" and "C" contains the checksum. In some references that turns into a 20 digit ICCID (see ICCID ).

    So, in order to extract the "traditional ICCID", just remove that final "extra digit".

  • Oh, that explains it! I was not aware of the checksum digit, thank you for clarifying. It had me fooled for a while as I tried registering my SIM in nrf cloud directly with the whole ICCID including the checksum digit, which resulted in an invalid ICCID.

    Also thank you for mentioning CFUN=1 to enable modem, I was not aware of this. Have not played around much with the AT Client before, just used LTE with prj.conf flags for the most part.

Related