diff --git a/pySim-prog.py b/pySim-prog.py index 3abd0bd6..cf503d09 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -162,6 +162,9 @@ def parse_options(): parser.add_option("--impi", dest="impi", help="Set IMS private user identity", ) + parser.add_option("--impu", dest="impu", + help="Set IMS public user identity", + ) parser.add_option("--read-imsi", dest="read_imsi", action="store_true", help="Read the IMSI from the CARD", default=False ) @@ -471,7 +474,8 @@ def gen_parameters(opts): 'epdgSelection' : opts.epdgSelection, 'pcscf' : opts.pcscf, 'ims_hdomain': opts.ims_hdomain, - 'impi' : opts.impi + 'impi' : opts.impi, + 'impu' : opts.impu, } diff --git a/pySim/cards.py b/pySim/cards.py index 62163a14..ac6d2235 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -411,6 +411,19 @@ class IsimCard(Card): impu_recs += "IMS public user identity: Can't read, response code = %s\n" % (sw) return impu_recs + def update_impu(self, impu=None): + hex_str = "" + if impu: + hex_str = s2h(impu) + # Build TLV + tlv = TLV(['80']) + content = tlv.build({'80': hex_str}) + + rec_size_bytes = self._scc.record_size(EF_ISIM_ADF_map['IMPU']) + impu_tlv = rpad(content, rec_size_bytes*2) + data, sw = self._scc.update_record(EF_ISIM_ADF_map['IMPU'], 1, impu_tlv) + return sw + class _MagicSimBase(Card): """ @@ -1323,6 +1336,17 @@ class SysmoISIMSJA2(UsimCard, IsimCard): if sw != '9000': print("Programming IMPI failed with code %s"%sw) + # update EF.IMPU in ADF.ISIM + # TODO: Validate IMPU input + # Support multiple IMPU if there is enough space + if self.file_exists(EF_ISIM_ADF_map['IMPU']): + if p.get('impu'): + sw = self.update_impu(p['impu']) + else: + sw = self.update_impu() + if sw != '9000': + print("Programming IMPU failed with code %s"%sw) + if '9000' == self.select_adf_by_aid(): # update EF-USIM_AUTH_KEY in ADF.USIM if p.get('ki'):