Change in pysim[master]: pySim-shell: do not use usim/isim APDUs in the beginnning

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

dexter gerrit-no-reply at lists.osmocom.org
Fri Oct 15 13:31:31 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/25804 )


Change subject: pySim-shell: do not use usim/isim APDUs in the beginnning
......................................................................

pySim-shell: do not use usim/isim APDUs in the beginnning

Some simcards like sysmo-usim-sjs1 and sysmo-usim-sja2 might tolerate it
when USIM or ISIM APDUs are used without selecting either the ISIM or
USIM application first. However, this tolerance is not specified. As
long as no USIM or ISIM application is selected it is not guaranteed
that the card will accept APDUs with class byte 0x00. It might be that
only class 0x0A APDUs are accepted.

To make pySim-shell more spec complient lets start with 0x0A class byte
and 0x00 for p1 and p2 during select. With this setting we will read out
the application identifiers. Then we select the first USIM or ISIM
application on the card. For this we will change to 0x00 and 0x04 for p2
during select.

Change-Id: I985261a1bddae60ffeaccb9c8d8d1b8a2ae4d0fc
---
M pySim-shell.py
1 file changed, 23 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/04/25804/1

diff --git a/pySim-shell.py b/pySim-shell.py
index 9258bd6..a0031a5 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -78,8 +78,13 @@
 
 	card = card_detect("auto", scc)
 	if card is None:
-		print("Could not detect card type!")
-		return None, None;
+		print("Warning: Could not detect card type, assuming generic SIM card type!")
+		card = SimCard(scc);
+
+	# Until no USIM or ISIM application is selected, we will use only
+	# classic 3GPP TS 51.011 class APDUs.
+	scc.cla_byte = "a0"
+	scc.sel_ctrl = "0000"
 
 	# Create runtime state with card profile
 	profile = CardProfileUICC()
@@ -87,6 +92,19 @@
 	profile.add_application(CardApplicationISIM)
 	rs = RuntimeState(card, profile)
 
+	# Select the first application on the card.
+	aids_card = card.read_aids()
+	apps_profile = profile.applications
+	app_name = None
+	for f in apps_profile:
+		if f.aid in aids_card[0]:
+			app_name = f.name
+	if app_name:
+		print("Selecting first application on card: " + app_name)
+		card._scc.cla_byte = "00"
+		card._scc.sel_ctrl = "0004" #request an FCP
+		rs.select("ADF." + app_name)
+
 	# FIXME: do this dynamically
 	rs.mf.add_file(DF_TELECOM())
 	rs.mf.add_file(DF_GSM())
@@ -96,6 +114,9 @@
 	# inform the transport that we can do context-specific SW interpretation
 	sl.set_sw_interpreter(rs)
 
+	# Make sure the MF is selected after the initialization is done.
+	rs.select('MF')
+
 	return rs, card
 
 class PysimApp(cmd2.Cmd):

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/25804
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I985261a1bddae60ffeaccb9c8d8d1b8a2ae4d0fc
Gerrit-Change-Number: 25804
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211015/e5a91b96/attachment.htm>


More information about the gerrit-log mailing list