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 submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/16946 ) Change subject: pySim-prog.py: add support for MSISDN programming ...................................................................... pySim-prog.py: add support for MSISDN programming This change implements programming of EF.MSISDN as per 3GPP TS 31.102, sections 4.2.26 and 4.4.2.3, excluding the following fields: - Alpha Identifier (currently 'FF'O * 20), - Capability/Configuration1 Record Identifier ('FF'O), - Extension1 Record Identifier ('FF'O). This feature is introduced exclusively for sysmoUSIM-SJS1. Othere SIM card types need to be tested. Change-Id: Ie033a0ffc3697ae562eaa7a241a0f6af6c2b0594 --- M pySim-prog.py M pySim/cards.py M pySim/utils.py M pysim-testdata/sysmoUSIM-SJS1.data M pysim-testdata/sysmoUSIM-SJS1.ok M tests/pysim-test.sh M tests/sysmoUSIM-SJS1.data.example 7 files changed, 57 insertions(+), 3 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim-prog.py b/pySim-prog.py index 09a5d70..a7081ff 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -119,6 +119,9 @@ parser.add_option("-i", "--imsi", dest="imsi", help="International Mobile Subscriber Identity", ) + parser.add_option("--msisdn", dest="msisdn", + help="Mobile Subscriber Integrated Services Digital Number", + ) parser.add_option("-k", "--ki", dest="ki", help="Ki (default is to randomize)", ) @@ -165,7 +168,6 @@ parser.add_option("--dry-run", dest="dry_run", help="Perform a 'dry run', don't actually program the card", default=False, action="store_true") - parser.add_option("--card_handler", dest="card_handler", metavar="FILE", help="Use automatic card handling machine") @@ -278,6 +280,17 @@ if len(opts.name) > 16: raise ValueError('Service Provider Name must max 16 characters!'); + if opts.msisdn is not None: + msisdn = opts.msisdn + if msisdn[0] == '+': + msisdn = msisdn[1:] + if not msisdn.isdigit(): + raise ValueError('MSISDN must be digits only! ' + 'Start with \'+\' for international numbers.') + if len(msisdn) > 10 * 2: + # TODO: Support MSISDN of length > 20 (10 Bytes) + raise ValueError('MSISDNs longer than 20 digits are not (yet) supported.') + # ICCID (19 digits, E.118), though some phase1 vendors use 20 :( if opts.iccid is not None: iccid = opts.iccid @@ -426,6 +439,7 @@ 'opc' : opc, 'acc' : acc, 'pin_adm' : pin_adm, + 'msisdn' : opts.msisdn, } diff --git a/pySim/cards.py b/pySim/cards.py index 802ad69..b4b5fdf 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -658,6 +658,17 @@ r = self._scc.select_file(['3f00', '7f10']) data, sw = self._scc.update_record('6f42', 1, lpad(p['smsp'], 104), force_len=True) + # EF.MSISDN + # TODO: Alpha Identifier (currently 'ff'O * 20) + # TODO: Capability/Configuration1 Record Identifier + # TODO: Extension1 Record Identifier + if p.get('msisdn') is not None: + msisdn = enc_msisdn(p['msisdn']) + data = 'ff' * 20 + msisdn + 'ff' * 2 + + r = self._scc.select_file(['3f00', '7f10']) + data, sw = self._scc.update_record('6F40', 1, data, force_len=True) + def erase(self): return diff --git a/pySim/utils.py b/pySim/utils.py index 12f66b9..8420b23 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -299,3 +299,29 @@ msisdn = '+' + msisdn return (npi, ton, msisdn) + +def enc_msisdn(msisdn, npi=0x01, ton=0x03): + """ + Encode MSISDN as LHV so it can be stored to EF.MSISDN. + See 3GPP TS 31.102, section 4.2.26 and 4.4.2.3. + + Default NPI / ToN values: + - NPI: ISDN / telephony numbering plan (E.164 / E.163), + - ToN: network specific or international number (if starts with '+'). + """ + + # Leading '+' indicates International Number + if msisdn[0] == '+': + msisdn = msisdn[1:] + ton = 0x01 + + # Append 'f' padding if number of digits is odd + if len(msisdn) % 2 > 0: + msisdn += 'f' + + # BCD length also includes NPI/ToN header + bcd_len = len(msisdn) // 2 + 1 + npi_ton = (npi & 0x0f) | ((ton & 0x07) << 4) | 0x80 + bcd = rpad(swap_nibbles(msisdn), 10 * 2) # pad to 10 octets + + return ('%02x' % bcd_len) + ('%02x' % npi_ton) + bcd diff --git a/pysim-testdata/sysmoUSIM-SJS1.data b/pysim-testdata/sysmoUSIM-SJS1.data index b7c1e81..c23f9f1 100644 --- a/pysim-testdata/sysmoUSIM-SJS1.data +++ b/pysim-testdata/sysmoUSIM-SJS1.data @@ -4,4 +4,5 @@ KI=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF OPC=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF IMSI=001010000000102 +MSISDN=+77776336143 ADM=55538407 diff --git a/pysim-testdata/sysmoUSIM-SJS1.ok b/pysim-testdata/sysmoUSIM-SJS1.ok index 6d85f38..290c470 100644 --- a/pysim-testdata/sysmoUSIM-SJS1.ok +++ b/pysim-testdata/sysmoUSIM-SJS1.ok @@ -50,7 +50,7 @@ ffffff0000 # unused ACC: 0008 -MSISDN: Can't read file -- Length of MSISDN (136 bytes) is out of range +MSISDN (NPI=1 ToN=1): +77776336143 AD: 00000002 Done ! diff --git a/tests/pysim-test.sh b/tests/pysim-test.sh index 0d469c9..a22c372 100755 --- a/tests/pysim-test.sh +++ b/tests/pysim-test.sh @@ -162,6 +162,7 @@ KI=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF OPC=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF IMSI=001010000000001 + MSISDN=6766266 ADM=00000000 ADM_HEX="" ADM_OPT="-a" @@ -171,7 +172,7 @@ ADM_OPT="-A" ADM=$ADM_HEX fi - python $PYSIM_PROG -p $I -t $CARD_NAME -o $OPC -k $KI -x $MCC -y $MNC -i $IMSI -s $ICCID $ADM_OPT $ADM + python $PYSIM_PROG -p $I -t $CARD_NAME -o $OPC -k $KI -x $MCC -y $MNC -i $IMSI -s $ICCID --msisdn $MSISDN $ADM_OPT $ADM check_card $I $CARD_NAME echo "" done diff --git a/tests/sysmoUSIM-SJS1.data.example b/tests/sysmoUSIM-SJS1.data.example index d711dcb..19efd15 100644 --- a/tests/sysmoUSIM-SJS1.data.example +++ b/tests/sysmoUSIM-SJS1.data.example @@ -4,4 +4,5 @@ KI=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF OPC=FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF IMSI=001010000000102 +MSISDN=+77776336143 ADM=12345678 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/16946 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: Ie033a0ffc3697ae562eaa7a241a0f6af6c2b0594 Gerrit-Change-Number: 16946 Gerrit-PatchSet: 11 Gerrit-Owner: herlesupreeth <herlesupreeth at gmail.com> Gerrit-Assignee: dexter <pmaier at sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: fixeria <axilirator at gmail.com> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-CC: dexter <pmaier at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200215/e0786fa8/attachment.htm>