Change in pysim[master]: commands: fix __record_len()

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/.

laforge gerrit-no-reply at lists.osmocom.org
Mon Dec 23 17:15:14 UTC 2019


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/16660 )

Change subject: commands: fix __record_len()
......................................................................

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
---
M pySim/commands.py
1 file changed, 9 insertions(+), 7 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



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 @@
 		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 @@
 
 		# 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 @@
 	# 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 @@
 	# 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)
 

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: If810c691893c022e9e9d87218dd0a334c5b2d579
Gerrit-Change-Number: 16660
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191223/2c4e78fb/attachment.htm>


More information about the gerrit-log mailing list