Change in pysim[master]: utils: fix dec_xplmn_w_act() and format_xplmn_w_act()

dexter gerrit-no-reply at lists.osmocom.org
Fri Apr 30 15:21:14 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/24003 )


Change subject: utils: fix dec_xplmn_w_act() and format_xplmn_w_act()
......................................................................

utils: fix dec_xplmn_w_act() and format_xplmn_w_act()

The function dec_xplmn_w_act(), which is also used by
format_xplmn_w_act() is using integer numbers as MCC/MNC representation.
This causes various problems since the information about leading zeros
gets lost.

Change-Id: I57f7dff80f48071ef9a3732ae1088882b127a6d4
---
M pySim/utils.py
M tests/test_utils.py
2 files changed, 8 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/03/24003/1

diff --git a/pySim/utils.py b/pySim/utils.py
index ac28624..00cbb5d 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -234,13 +234,13 @@
 	return sel
 
 def dec_xplmn_w_act(fivehexbytes:Hexstr) -> Dict[str,Any]:
-	res = {'mcc': 0, 'mnc': 0, 'act': []}
+	res = {'mcc': "0", 'mnc': "0", 'act': []}
 	plmn_chars = 6
 	act_chars = 4
 	plmn_str = fivehexbytes[:plmn_chars]				# first three bytes (six ascii hex chars)
 	act_str = fivehexbytes[plmn_chars:plmn_chars + act_chars]	# two bytes after first three bytes
-	res['mcc'] = dec_mcc_from_plmn(plmn_str)
-	res['mnc'] = dec_mnc_from_plmn(plmn_str)
+	res['mcc'] = dec_mcc_from_plmn_str(plmn_str)
+	res['mnc'] = dec_mnc_from_plmn_str(plmn_str)
 	res['act'] = dec_act(act_str)
 	return res
 
@@ -248,10 +248,10 @@
 	s = ""
 	for rec_data in hexstr_to_Nbytearr(hexstr, 5):
 		rec_info = dec_xplmn_w_act(rec_data)
-		if rec_info['mcc'] == 0xFFF and rec_info['mnc'] == 0xFFF:
+		if rec_info['mcc'] == "" and rec_info['mnc'] == "":
 			rec_str = "unused"
 		else:
-			rec_str = "MCC: %03d MNC: %03d AcT: %s" % (rec_info['mcc'], rec_info['mnc'], ", ".join(rec_info['act']))
+			rec_str = "MCC: %s MNC: %s AcT: %s" % (rec_info['mcc'], rec_info['mnc'], ", ".join(rec_info['act']))
 		s += "\t%s # %s\n" % (rec_data, rec_str)
 	return s
 
diff --git a/tests/test_utils.py b/tests/test_utils.py
index b70b17b..558b5e7 100755
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -96,13 +96,13 @@
 		self.assertEqual(utils.dec_act("ffff"), ["UTRAN", "E-UTRAN", "GSM", "GSM COMPACT", "cdma2000 HRPD", "cdma2000 1xRTT"])
 
 	def testDecxPlmn_w_act(self):
-		expected = {'mcc': 295, 'mnc': 10, 'act': ["UTRAN"]}
+		expected = {'mcc': '295', 'mnc': '10', 'act': ["UTRAN"]}
 		self.assertEqual(utils.dec_xplmn_w_act("92f5018000"), expected)
 
 	def testFormatxPlmn_w_act(self):
 		input_str = "92f501800092f5508000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000ffffff0000"
-		expected  = "\t92f5018000 # MCC: 295 MNC: 010 AcT: UTRAN\n"
-		expected += "\t92f5508000 # MCC: 295 MNC: 005 AcT: UTRAN\n"
+		expected  = "\t92f5018000 # MCC: 295 MNC: 10 AcT: UTRAN\n"
+		expected += "\t92f5508000 # MCC: 295 MNC: 05 AcT: UTRAN\n"
 		expected += "\tffffff0000 # unused\n"
 		expected += "\tffffff0000 # unused\n"
 		expected += "\tffffff0000 # unused\n"

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I57f7dff80f48071ef9a3732ae1088882b127a6d4
Gerrit-Change-Number: 24003
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210430/2a4c0057/attachment.htm>


More information about the gerrit-log mailing list