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/.
Falkenber9 gerrit-no-reply at lists.osmocom.orgFalkenber9 has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/24160 )
Change subject: SimCardCommands: detect whether UICC or Classic SIM
......................................................................
SimCardCommands: detect whether UICC or Classic SIM
Distinction between UICC or Classic SIM was done
in pySim-read only.
This patch moves is into SimCardCommands
and adds function calls into
* pySim-read.py
* pySim-prog.py
* pySim-shell.py
Change-Id: I224bd6c91cdaf444e2a94117f64030c024a776a7
---
M pySim-prog.py
M pySim-read.py
M pySim-shell.py
M pySim/commands.py
4 files changed, 26 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/60/24160/1
diff --git a/pySim-prog.py b/pySim-prog.py
index 4c85be7..9191ed6 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -656,6 +656,9 @@
card_handler.get(first)
if opts.dry_run is False:
+ # Testing for Classic SIM or UICC
+ scc.detect_card_type()
+
# Get card
card = card_detect(opts.type, scc)
if card is None:
diff --git a/pySim-read.py b/pySim-read.py
index ebe0e29..2c848dc 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -60,16 +60,8 @@
# Wait for SIM card
sl.wait_for_card()
- # Assuming UICC SIM
- scc.cla_byte = "00"
- scc.sel_ctrl = "0004"
-
# Testing for Classic SIM or UICC
- (res, sw) = sl.send_apdu(scc.cla_byte + "a4" + scc.sel_ctrl + "02" + "3f00")
- if sw == '6e00':
- # Just a Classic SIM
- scc.cla_byte = "a0"
- scc.sel_ctrl = "0000"
+ scc.detect_card_type()
# Read the card
print("Reading ...")
diff --git a/pySim-shell.py b/pySim-shell.py
index bbfe7e9..7a6eaf7 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -475,6 +475,8 @@
sl.wait_for_card();
+ scc.detect_card_type()
+
card_handler = card_handler(sl)
card = card_detect("auto", scc)
diff --git a/pySim/commands.py b/pySim/commands.py
index 0b3d9b6..1e14296 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -29,7 +29,7 @@
class SimCardCommands(object):
def __init__(self, transport):
self._tp = transport
- self._cla_byte = "a0"
+ self._cla_byte = "a0" # Non-UICC GSM SIM (see 3GPP TS 11.11, chapter 4.4.1)
self.sel_ctrl = "0000"
# Extract a single FCP item from TLV
@@ -103,6 +103,25 @@
def sel_ctrl(self, value):
self._sel_ctrl = value
+ def detect_card_type(self):
+ """
+ Detect whether we have UICC or classic SIM and
+ adjust CLA/CTRL bytes accordingly.
+ """
+ # Assume UICC SIM first
+ self.cla_byte = "00"
+ self.sel_ctrl = "0004"
+
+ # Try to access MF via UICC command class
+ (res, sw) = self._tp.send_apdu(self.cla_byte + "a4" + self.sel_ctrl + "02" + "3f00")
+ if sw == '6e00':
+ # Didn't work, try command class for Classic SIM
+ self.cla_byte = "a0" # Non-UICC GSM SIM (see 3GPP TS 11.11, chapter 4.4.1)
+ self.sel_ctrl = "0000"
+ (res, sw) = self._tp.send_apdu(self.cla_byte + "a4" + self.sel_ctrl + "02" + "3f00")
+ if sw == '6e00':
+ raise ProtocolError("Card is neither UICC nor Classic SIM")
+
def try_select_path(self, dir_list):
""" Try to select a specified path given as list of hex-string FIDs"""
rv = []
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/24160
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I224bd6c91cdaf444e2a94117f64030c024a776a7
Gerrit-Change-Number: 24160
Gerrit-PatchSet: 1
Gerrit-Owner: Falkenber9 <robert.falkenberg at tu-dortmund.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210506/21e051ca/attachment.htm>