mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-28 08:18:36 +03:00
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
This commit is contained in:
@@ -30,8 +30,8 @@ class SimCardCommands(object):
|
|||||||
self._cla_byte = "a0"
|
self._cla_byte = "a0"
|
||||||
self.sel_ctrl = "0000"
|
self.sel_ctrl = "0000"
|
||||||
|
|
||||||
# Get file size from FCP
|
# Extract a single FCP item from TLV
|
||||||
def __get_len_from_tlv(self, fcp):
|
def __parse_fcp(self, fcp):
|
||||||
# see also: ETSI TS 102 221, chapter 11.1.1.3.1 Response for MF,
|
# see also: ETSI TS 102 221, chapter 11.1.1.3.1 Response for MF,
|
||||||
# DF or ADF
|
# DF or ADF
|
||||||
from pytlv.TLV import TLV
|
from pytlv.TLV import TLV
|
||||||
@@ -58,9 +58,7 @@ class SimCardCommands(object):
|
|||||||
|
|
||||||
# Skip FCP tag and length
|
# Skip FCP tag and length
|
||||||
tlv = fcp[skip:]
|
tlv = fcp[skip:]
|
||||||
tlv_parsed = tlvparser.parse(tlv)
|
return tlvparser.parse(tlv)
|
||||||
|
|
||||||
return int(tlv_parsed['80'], 16)
|
|
||||||
|
|
||||||
# Tell the length of a record by the card response
|
# Tell the length of a record by the card response
|
||||||
# USIMs respond with an FCP template, which is different
|
# 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
|
# SIM: GSM 11.11, chapter 9.2.1 SELECT
|
||||||
def __record_len(self, r):
|
def __record_len(self, r):
|
||||||
if self.sel_ctrl == "0004":
|
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:
|
else:
|
||||||
return int(r[-1][28:30], 16)
|
return int(r[-1][28:30], 16)
|
||||||
|
|
||||||
@@ -77,7 +78,8 @@ class SimCardCommands(object):
|
|||||||
# above.
|
# above.
|
||||||
def __len(self, r):
|
def __len(self, r):
|
||||||
if self.sel_ctrl == "0004":
|
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:
|
else:
|
||||||
return int(r[-1][4:8], 16)
|
return int(r[-1][4:8], 16)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user