Project

General

Profile

Actions

Bug #5421

closed

cardem: failure to correctly detect end of reset of CardMan 3121

Added by laforge about 2 years ago. Updated about 2 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Start date:
01/26/2022
Due date:
% Done:

100%

Spec Reference:

Description

I'm observing the following weird situation when using the following setup:

pySim-shell --pcsc/ccid--> CardMan3121 --> simtrace2(cardem) --> simtrace2-cardem-pcscs --pcsc/ccid--> sysmoISIM-SJA2

pySIM-shell (no card)> equip
Waiting for card...
Autodetected card type: sysmoISIM-SJA2
Info: Card is of type: UICC
AIDs on card:
 USIM: a0000000871002ffffffff8907090000 (EF.DIR)
 ISIM: a0000000871004ffffffff8907090000 (EF.DIR)
 ARA-M: a00000015141434c00
EXCEPTION of type 'RuntimeError' occurred with message: '6e00: Checking errors - Class not supported'
To enable full traceback, run the following command: 'set debug true'

And indeed, looking at the communication, the SIM card responds with a 6300 to the final "select MF" apdu:

DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 c0 00 00 2f 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_pb_and_tx(pb=c0, tx=62 2d 82 02 78 21 83 02 3f 00 a5 09 80 01 71 83 04 00 01 8d 08 8a 01 05 8c 04 26 1a 00 00 c6 0f 90 01 70 83 01 01 83 01 81 83 01 0a 83 01 0b , len=47)
DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=9000)
DLGLOBAL INFO =====================================
DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 a4 00 04 02 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_pb_and_rx(pb=a4, le=2)
DLGLOBAL INFO => DATA: flags=0x02 (FINAL ), 2f 00 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=6124)
DLGLOBAL INFO =====================================
DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 c0 00 00 24 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_pb_and_tx(pb=c0, tx=62 22 82 05 42 21 00 2b 08 83 02 2f 00 a5 06 d0 01 20 d2 01 0b 8a 01 05 8b 03 2f 06 04 80 02 01 58 88 01 f0 , len=36)
DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=9000)
DLGLOBAL INFO =====================================
DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 b2 08 04 2b 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_pb_and_tx(pb=b2, tx=ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff , len=43)
DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=9000)
DLGLOBAL INFO =====================================
DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 a4 04 04 09 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_pb_and_rx(pb=a4, le=9)
DLGLOBAL INFO => DATA: flags=0x02 (FINAL ), a0 00 00 01 51 41 43 4c 00 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=9000)
DLGLOBAL NOTICE => IRQ STATUS: flags=0x13, fi=9, di=6, wi=10 wtime=9600 (RESET VCC CLK )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x12, fi=9, di=6, wi=10 wtime=9600 (RESET CLK )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x10, fi=9, di=6, wi=10 wtime=9600 (RESET )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x0, fi=9, di=6, wi=10 wtime=9600 ()
DLGLOBAL NOTICE => IRQ STATUS: flags=0x10, fi=9, di=6, wi=10 wtime=9600 (RESET )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x0, fi=9, di=6, wi=10 wtime=9600 ()
DLGLOBAL NOTICE => IRQ STATUS: flags=0x1, fi=9, di=6, wi=10 wtime=9600 (VCC )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x3, fi=1, di=1, wi=10 wtime=9600 (VCC CLK )
DLGLOBAL NOTICE => PTS req: ff 10 96 79
DLGLOBAL INFO =====================================
DLGLOBAL INFO => DATA: flags=0x01 (HDR ), 00 a4 00 04 02 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_pb_and_rx(pb=a4, le=2)
DLGLOBAL INFO => DATA: flags=0x02 (FINAL ), 3f 00 
 DLINP DEBUG [0] <= osmo_st2_cardem_request_sw_tx(sw=6e00)

so what's happening here? We are issuing a CLA byte of 00 after having most recently selected the ARA-M application. Apparently this is not a supported CLA byte within ARA-M.

However, why does this not show up when accessing the card directly? Because the card-reset happening between selcting ARA-M and the final "SELECT MF" (00 a4 00 04 02 3f 00) is not properly detected, and we don't execute it on the card.

DLGLOBAL NOTICE => IRQ STATUS: flags=0x13, fi=9, di=6, wi=10 wtime=9600 (RESET VCC CLK )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x12, fi=9, di=6, wi=10 wtime=9600 (RESET CLK )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x10, fi=9, di=6, wi=10 wtime=9600 (RESET )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x0, fi=9, di=6, wi=10 wtime=9600 ()
DLGLOBAL NOTICE => IRQ STATUS: flags=0x10, fi=9, di=6, wi=10 wtime=9600 (RESET )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x0, fi=9, di=6, wi=10 wtime=9600 ()
DLGLOBAL NOTICE => IRQ STATUS: flags=0x1, fi=9, di=6, wi=10 wtime=9600 (VCC )
DLGLOBAL NOTICE => IRQ STATUS: flags=0x3, fi=1, di=1, wi=10 wtime=9600 (VCC CLK )

So we see various changes of RESET/VCC/CLK lines reported by the firmware, but our "Detect reset and pass it on to the remote card" logic triggers on the following logic:

        if ((flags & CEMU_STATUS_F_VCC_PRESENT) && (flags & CEMU_STATUS_F_CLK_ACTIVE) &&
            !(flags & CEMU_STATUS_F_RESET_ACTIVE)) {
                if (last_status_flags & CEMU_STATUS_F_RESET_ACTIVE) {
                        /* a reset has just ended, forward it to the real card */
                        bool cold_reset = true;
                        if (last_status_flags & CEMU_STATUS_F_VCC_PRESENT)
                                cold_reset = false;
                        LOGCI(ci, LOGL_NOTICE, "%s Resetting card in reader...\n",
                                cold_reset ? "Cold" : "Warm");
                        osim_card_reset(card, cold_reset);
                }
        }
So,
  1. VCC + CLK must be present while RST is absent, and
  2. previously, RST must have been active

In the sequence used by the CM3121 (or at least as reported by the carem firmware), RST is turned off as VCC is turned off, so second condition above doens't hold true.


Related issues

Related to pySim - Bug #5418: one cannot run 'export' after an 'export'Resolveddexter01/25/2022

Actions
Actions #1

Updated by laforge about 2 years ago

  • Related to Bug #5418: one cannot run 'export' after an 'export' added
Actions #2

Updated by laforge about 2 years ago

  • % Done changed from 30 to 90

fix in https://gerrit.osmocom.org/c/simtrace2/+/27001 - this problem should not exist in osmo-remsim, as the reset/power-up detection logic there is different.

Actions #3

Updated by laforge about 2 years ago

  • Status changed from In Progress to Resolved
  • % Done changed from 90 to 100
Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)