aboutsummaryrefslogtreecommitdiffstats
path: root/pySim/commands.py
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2019-12-20 13:39:24 +0100
committerPhilipp Maier <pmaier@sysmocom.de>2019-12-20 13:42:41 +0100
commitcdfdd41293b2ee72641eb925e2451d2389874dd6 (patch)
treecf71e29ef72038a931ebb84705bfcb0b9d61c9f3 /pySim/commands.py
parent4e724391e042cf8a45bf32b2d069120b749bda40 (diff)
commands: fix __record_len()
When working with USIM/ISIMs, The method __record_len() that is used by the record_count() method returns the length of the file instead the actual record count. This causes record_count() to return always 1 Change-Id: If810c691893c022e9e9d87218dd0a334c5b2d579
Diffstat (limited to 'pySim/commands.py')
-rw-r--r--pySim/commands.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/pySim/commands.py b/pySim/commands.py
index 03540b6..f2bdf7a 100644
--- a/pySim/commands.py
+++ b/pySim/commands.py
@@ -30,8 +30,8 @@ class SimCardCommands(object):
self._cla_byte = "a0"
self.sel_ctrl = "0000"
- # Get file size from FCP
- def __get_len_from_tlv(self, fcp):
+ # Extract a single FCP item from TLV
+ def __parse_fcp(self, fcp):
# see also: ETSI TS 102 221, chapter 11.1.1.3.1 Response for MF,
# DF or ADF
from pytlv.TLV import TLV
@@ -58,9 +58,7 @@ class SimCardCommands(object):
# Skip FCP tag and length
tlv = fcp[skip:]
- tlv_parsed = tlvparser.parse(tlv)
-
- return int(tlv_parsed['80'], 16)
+ return tlvparser.parse(tlv)
# Tell the length of a record by the card response
# USIMs respond with an FCP template, which is different
@@ -69,7 +67,10 @@ class SimCardCommands(object):
# SIM: GSM 11.11, chapter 9.2.1 SELECT
def __record_len(self, r):
if self.sel_ctrl == "0004":
- return self.__get_len_from_tlv(r[-1])
+ tlv_parsed = self.__parse_fcp(r[-1])
+ file_descriptor = tlv_parsed['82']
+ # See also ETSI TS 102 221, chapter 11.1.1.4.3 File Descriptor
+ return int(file_descriptor[4:8], 16)
else:
return int(r[-1][28:30], 16)
@@ -77,7 +78,8 @@ class SimCardCommands(object):
# above.
def __len(self, r):
if self.sel_ctrl == "0004":
- return self.__get_len_from_tlv(r[-1])
+ tlv_parsed = self.__parse_fcp(r[-1])
+ return int(tlv_parsed['80'], 16)
else:
return int(r[-1][4:8], 16)