Change in ...pysim[master]: pySim-prog: use functions to derive MCC/MNC from IMSI
laforge has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/pysim/+/15497 ) Change subject: pySim-prog: use functions to derive MCC/MNC from IMSI .. pySim-prog: use functions to derive MCC/MNC from IMSI In case the MCC/MNC are not supplied with a CSV file we cut out the missing values from the IMSI string. Lets use a function to do this and also check the input parameters. Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 --- M pySim-prog.py M pySim/utils.py 2 files changed, 31 insertions(+), 2 deletions(-) Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved diff --git a/pySim-prog.py b/pySim-prog.py index 9149709..990fe15 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -43,6 +43,7 @@ from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn, dec_iccid from pySim.ts_51_011 import EF from pySim.card_handler import * +from pySim.utils import * def parse_options(): @@ -483,8 +484,9 @@ 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'] = row.get('mcc', row['imsi'][0:3]) - row['mnc'] = row.get('mnc', row['imsi'][3:5]) + row['mcc'] = row.get('mcc', mcc_from_imsi(row.get('imsi'))) + row['mnc'] = row.get('mnc', mnc_from_imsi(row.get('imsi'))) + 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 a68af0a..e8dd531 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -206,3 +206,30 @@ num = map(int, str(cc)) check_digit = 10 - sum(num[-2::-2] + [sum(divmod(d * 2, 10)) for d in num[::-2]]) % 10 return 0 if check_digit == 10 else check_digit + +def mcc_from_imsi(imsi): + """ + Derive the MCC (Mobile Country Code) from the first three digits of an IMSI + """ + if imsi == None: + return None + + if len(imsi) > 3: + return imsi[:3] + else: + return None + +def mnc_from_imsi(imsi, long=False): + """ + Derive the MNC (Mobile Country Code) from the 4th to 6th digit of an IMSI + """ + if imsi == None: + return None + + if len(imsi) > 3: + if long: + return imsi[3:6] + else: + return imsi[3:5] + else: + return None -- To view, visit https://gerrit.osmocom.org/c/pysim/+/15497 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 Gerrit-Change-Number: 15497 Gerrit-PatchSet: 3 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: dexter Gerrit-Reviewer: laforge Gerrit-MessageType: merged
Change in ...pysim[master]: pySim-prog: use functions to derive MCC/MNC from IMSI
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/15497 ) Change subject: pySim-prog: use functions to derive MCC/MNC from IMSI .. Patch Set 3: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/15497 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 Gerrit-Change-Number: 15497 Gerrit-PatchSet: 3 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: dexter Gerrit-Reviewer: laforge Gerrit-Comment-Date: Sat, 14 Sep 2019 15:34:28 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in ...pysim[master]: pySim-prog: use functions to derive MCC/MNC from IMSI
Hello daniel, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/c/pysim/+/15497 to look at the new patch set (#2). Change subject: pySim-prog: use functions to derive MCC/MNC from IMSI .. pySim-prog: use functions to derive MCC/MNC from IMSI In case the MCC/MNC are not supplied with a CSV file we cut out the missing values from the IMSI string. Lets use a function to do this and also check the input parameters. Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 --- M pySim-prog.py M pySim/utils.py 2 files changed, 31 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/97/15497/2 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/15497 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 Gerrit-Change-Number: 15497 Gerrit-PatchSet: 2 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: dexter Gerrit-CC: laforge Gerrit-MessageType: newpatchset
Change in ...pysim[master]: pySim-prog: use functions to derive MCC/MNC from IMSI
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/15497 ) Change subject: pySim-prog: use functions to derive MCC/MNC from IMSI .. Patch Set 1: (1 comment) https://gerrit.osmocom.org/#/c/15497/1/pySim/utils.py File pySim/utils.py: https://gerrit.osmocom.org/#/c/15497/1/pySim/utils.py@226 PS1, Line 226: if imsi == None: : return None : : if len(imsi) > 3: : if there's a mixture of spaces and tabs, which may not be the best idea if working with python. The existing code seems to use tabs more or less everywhere, while the new code here uses spaces. -- To view, visit https://gerrit.osmocom.org/c/pysim/+/15497 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 Gerrit-Change-Number: 15497 Gerrit-PatchSet: 1 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: dexter Gerrit-CC: laforge Gerrit-Comment-Date: Thu, 12 Sep 2019 12:59:23 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in ...pysim[master]: pySim-prog: use functions to derive MCC/MNC from IMSI
daniel has posted comments on this change. ( https://gerrit.osmocom.org/c/pysim/+/15497 ) Change subject: pySim-prog: use functions to derive MCC/MNC from IMSI .. Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/pysim/+/15497 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 Gerrit-Change-Number: 15497 Gerrit-PatchSet: 1 Gerrit-Owner: dexter Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel Gerrit-Reviewer: dexter Gerrit-Comment-Date: Thu, 12 Sep 2019 12:43:58 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in ...pysim[master]: pySim-prog: use functions to derive MCC/MNC from IMSI
dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/15497 Change subject: pySim-prog: use functions to derive MCC/MNC from IMSI .. pySim-prog: use functions to derive MCC/MNC from IMSI In case the MCC/MNC are not supplied with a CSV file we cut out the missing values from the IMSI string. Lets use a function to do this and also check the input parameters. Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 --- M pySim-prog.py M pySim/utils.py 2 files changed, 31 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/97/15497/1 diff --git a/pySim-prog.py b/pySim-prog.py index 57a24d4..974dbd1 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -43,6 +43,7 @@ from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn, dec_iccid from pySim.ts_51_011 import EF from pySim.card_handler import * +from pySim.utils import * def parse_options(): @@ -479,8 +480,9 @@ 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'] = row.get('mcc', row['imsi'][0:3]) - row['mnc'] = row.get('mnc', row['imsi'][3:5]) + row['mcc'] = row.get('mcc', mcc_from_imsi(row.get('imsi'))) + row['mnc'] = row.get('mnc', mnc_from_imsi(row.get('imsi'))) + 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..09d4f86 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -206,3 +206,30 @@ num = map(int, str(cc)) check_digit = 10 - sum(num[-2::-2] + [sum(divmod(d * 2, 10)) for d in num[::-2]]) % 10 return 0 if check_digit == 10 else check_digit + +def mcc_from_imsi(imsi): +""" +Derive the MCC (Mobile Country Code) from the first three digits of an IMSI +""" + if imsi == None: + return None + +if len(imsi) > 3: +return imsi[:3] +else: +return None + +def mnc_from_imsi(imsi, long=False): +""" +Derive the MNC (Mobile Country Code) from the 4th to 6th digit of an IMSI +""" + if imsi == None: + return None + +if len(imsi) > 3: +if long: +return imsi[3:6] +else: +return imsi[3:5] +else: +return None -- To view, visit https://gerrit.osmocom.org/c/pysim/+/15497 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I98e5bf8f9ff2a852efb190cc789edf42c5075bf8 Gerrit-Change-Number: 15497 Gerrit-PatchSet: 1 Gerrit-Owner: dexter Gerrit-MessageType: newchange