From be069e26ae6e6d0e6aaa50498f274bddebe8e99e Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Thu, 12 Sep 2019 12:52:43 +0200 Subject: cards: use string representation for MNC/MCC At the moment MNC and MCC are represented as integer numbers inside the parameter array while all other parameters are represented as strings. Lets use strings for MNC/MCC as well to simplify the parameter handling. We will also not loose the length information in case of leading zeros. Change-Id: Ia2333921a4863f0f26ee923ca796e62ec5e2d59a --- pySim-prog.py | 6 +++--- pySim/utils.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pySim-prog.py b/pySim-prog.py index ee5bc98..9149709 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -432,7 +432,7 @@ def print_parameters(params): if 'smsp' in params: s.append(" > SMSP : %(smsp)s") s.append(" > ICCID : %(iccid)s") - s.append(" > MCC/MNC : %(mcc)d/%(mnc)d") + s.append(" > MCC/MNC : %(mcc)s/%(mnc)s") s.append(" > IMSI : %(imsi)s") s.append(" > Ki : %(ki)s") s.append(" > OPC : %(opc)s") @@ -483,8 +483,8 @@ def _read_params_csv(opts, iccid=None, imsi=None): def read_params_csv(opts, imsi=None, iccid=None): row = _read_params_csv(opts, iccid=iccid, imsi=imsi) if row is not None: - row['mcc'] = int(row.get('mcc', row['imsi'][0:3])) - row['mnc'] = int(row.get('mnc', row['imsi'][3:5])) + row['mcc'] = row.get('mcc', row['imsi'][0:3]) + row['mnc'] = row.get('mnc', row['imsi'][3:5]) pin_adm = None # We need to escape the pin_adm we get from the csv if 'pin_adm' in row: diff --git a/pySim/utils.py b/pySim/utils.py index 65f10c5..a68af0a 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -98,7 +98,7 @@ def enc_iccid(iccid): def enc_plmn(mcc, mnc): """Converts integer MCC/MNC into 3 bytes for EF""" - return swap_nibbles(lpad('%d' % mcc, 3) + lpad('%d' % mnc, 3)) + return swap_nibbles(lpad('%d' % int(mcc), 3) + lpad('%d' % int(mnc), 3)) def dec_spn(ef): byte1 = int(ef[0:2]) -- cgit v1.2.3