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.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/18225 )
Change subject: Treat MCC and MNC as strings, not integers
......................................................................
Treat MCC and MNC as strings, not integers
A MNC of 02 and 002 are *not* equal. The former is a two-digit MNC
and the latter is a three-digit MNC. Hence, we shouldn't treat
MNCs as integer values as we have no clue how many leading zeroes
(if any) the user entered.
Change-Id: I9d1d07a64888c76703c3e430bbdd822080c05819
Closes: OS#4523
---
M pySim-prog.py
M pySim/utils.py
2 files changed, 19 insertions(+), 8 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/25/18225/1
diff --git a/pySim-prog.py b/pySim-prog.py
index 67719b4..4ac480c 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -98,13 +98,13 @@
help="Country code [default: %default]",
default=1,
)
- parser.add_option("-x", "--mcc", dest="mcc", type="int",
+ parser.add_option("-x", "--mcc", dest="mcc", type="string",
help="Mobile Country Code [default: %default]",
- default=901,
+ default="901",
)
- parser.add_option("-y", "--mnc", dest="mnc", type="int",
+ parser.add_option("-y", "--mnc", dest="mnc", type="string",
help="Mobile Network Code [default: %default]",
- default=55,
+ default="55",
)
parser.add_option("--mnclen", dest="mnclen", type="choice",
help="Length of Mobile Network Code [default: %default]",
@@ -219,7 +219,7 @@
return d[0:len]
def _mcc_mnc_digits(mcc, mnc):
- return ('%03d%03d' if mnc > 100 else '%03d%02d') % (mcc, mnc)
+ return '%s%s' % (mcc, mnc)
def _cc_digits(cc):
return ('%03d' if cc > 100 else '%02d') % cc
@@ -272,8 +272,17 @@
mcc = opts.mcc
mnc = opts.mnc
- if not ((0 < mcc < 999) and (0 < mnc < 999)):
- raise ValueError('mcc & mnc must be between 0 and 999')
+ if not mcc.isdigit() or not mnc.isdigit():
+ raise ValueError('mcc & mnc must only contain decimal digits')
+ if len(mcc) < 1 or len(mcc) > 3:
+ raise ValueError('mcc must be between 1 .. 3 digits')
+ if len(mnc) < 1 or len(mnc) > 3:
+ raise ValueError('mnc must be between 1 .. 3 digits')
+
+ # MCC always has 3 digits
+ mcc = lpad(mcc, 3, "0")
+ # MNC must be at least 2 digits
+ mnc = lpad(mnc, 2, "0")
# Digitize country code (2 or 3 digits)
cc_digits = _cc_digits(opts.country)
diff --git a/pySim/utils.py b/pySim/utils.py
index a1689ca..43616a9 100644
--- a/pySim/utils.py
+++ b/pySim/utils.py
@@ -102,7 +102,9 @@
def enc_plmn(mcc, mnc):
"""Converts integer MCC/MNC into 3 bytes for EF"""
- return swap_nibbles(lpad('%d' % int(mcc), 3) + lpad('%d' % int(mnc), 3))
+ if len(mnc) == 2:
+ mnc = "F%s" % mnc
+ return swap_nibbles("%s%s" % (mcc, mnc))
def dec_spn(ef):
byte1 = int(ef[0:2])
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/18225
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I9d1d07a64888c76703c3e430bbdd822080c05819
Gerrit-Change-Number: 18225
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200512/747c1d2e/attachment.htm>