From cdfdd41293b2ee72641eb925e2451d2389874dd6 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Fri, 20 Dec 2019 13:39:24 +0100 Subject: 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 --- pySim/commands.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'pySim/commands.py') 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) -- cgit v1.2.3