Skip to content

Commit

Permalink
Add FPLMN read and program
Browse files Browse the repository at this point in the history
Change-Id: I9ce8c1af691c28ea9ed69e7b5f03f0c02d1f029b
  • Loading branch information
matan1008 authored and laf0rge committed Jun 7, 2023
1 parent 1de62c4 commit 777ee9e
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pySim-prog.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def parse_options():
default=None,
choices=['{:02X}'.format(int(m)) for m in EF_AD.OP_MODE],
)
parser.add_option("-f", "--fplmn", dest="fplmn", action="append",
help="Set Forbidden PLMN. Add multiple time for multiple FPLMNS",
)
parser.add_option("--epdgid", dest="epdgid",
help="Set Home Evolved Packet Data Gateway (ePDG) Identifier. (Only FQDN format supported)",
)
Expand Down Expand Up @@ -498,6 +501,7 @@ def gen_parameters(opts):
'impi': opts.impi,
'impu': opts.impu,
'opmode': opts.opmode,
'fplmn': opts.fplmn,
}


Expand Down
8 changes: 8 additions & 0 deletions pySim-read.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ def select_app(adf: str, card: SimCard):
else:
print("EHPLMN: Can't read, response code = %s" % (sw,))

# EF.FPLMN
if usim_card.file_exists(EF_USIM_ADF_map['FPLMN']):
res, sw = usim_card.read_fplmn()
if sw == '9000':
print(f'FPLMN:\n{res}')
else:
print(f'FPLMN: Can\'t read, response code = {sw}')

# EF.UST
try:
if usim_card.file_exists(EF_USIM_ADF_map['UST']):
Expand Down
18 changes: 18 additions & 0 deletions pySim/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,22 @@ def update_ehplmn(self, mcc, mnc):
data, sw = self._scc.update_binary(EF_USIM_ADF_map['EHPLMN'], ehplmn)
return sw

def read_fplmn(self):
res, sw = self._scc.read_binary(EF_USIM_ADF_map['FPLMN'])
if sw == '9000':
return format_xplmn(res), sw
else:
return None, sw

def update_fplmn(self, fplmn):
self._scc.select_file('3f00')
self.select_adf_by_aid('USIM')
size = self._scc.binary_size(EF_USIM_ADF_map['FPLMN'])
encoded = ''.join([enc_plmn(plmn[:3], plmn[3:]) for plmn in fplmn])
encoded = rpad(encoded, size)
data, sw = self._scc.update_binary(EF_USIM_ADF_map['FPLMN'], encoded)
return sw

def read_epdgid(self):
(res, sw) = self._scc.read_binary(EF_USIM_ADF_map['ePDGId'])
if sw == '9000':
Expand Down Expand Up @@ -1702,6 +1718,7 @@ def __init__(self, ssc):
'smsp': self.update_smsp,
'ki': self.update_ki,
'opc': self.update_opc,
'fplmn': self.update_fplmn,
}

@classmethod
Expand All @@ -1715,6 +1732,7 @@ def autodetect(cls, scc):
return None

def program(self, p):
self.set_apdu_parameter('00', '0004')
# Authenticate
self._scc.verify_chv(0xc, h2b('3834373936313533'))
for handler in self._program_handlers:
Expand Down
12 changes: 12 additions & 0 deletions pysim-testdata/Fairwaves-SIM.ok
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ SIM Service Table: ff3cc3ff030fff0f000fff03f0c0
Service 58 - Extension 8
Service 59 - MMS User Connectivity Parameters

FPLMN:
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused

USIM Service Table: 01ea1ffc21360480010000
Service 1 - Local Phone Book
Service 10 - Short Message Storage (SMS)
Expand Down
6 changes: 6 additions & 0 deletions pysim-testdata/Wavemobile-SIM.ok
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ SIM Service Table: ff33ff0f3c00ff0f000cf0c0f0030000
Service 58 - Extension 8
Service 59 - MMS User Connectivity Parameters

FPLMN:
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused

USIM Service Table: 9eff1b3c37fe5900000000
Service 2 - Fixed Dialling Numbers (FDN)
Service 3 - Extension 2
Expand Down
6 changes: 6 additions & 0 deletions pysim-testdata/sysmoISIM-SJA2.ok
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ EHPLMN:
ffffff # unused
ffffff # unused

FPLMN:
ffffff # unused
ffffff # unused
ffffff # unused
ffffff # unused

USIM Service Table: beff9f9de73e0408400170330000002e00000000
Service 2 - Fixed Dialling Numbers (FDN)
Service 3 - Extension 2
Expand Down
6 changes: 6 additions & 0 deletions pysim-testdata/sysmoUSIM-SJS1.ok
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ SIM Service Table: ff3fffff3f003f1ff00c00c0f00000
Service 58 - Extension 8
Service 59 - MMS User Connectivity Parameters

FPLMN:
62f201 # MCC: 262 MNC: 010
62f202 # MCC: 262 MNC: 020
62f203 # MCC: 262 MNC: 030
62f207 # MCC: 262 MNC: 070

USIM Service Table: 9e6b1dfc67f6580000
Service 2 - Fixed Dialling Numbers (FDN)
Service 3 - Extension 2
Expand Down

0 comments on commit 777ee9e

Please sign in to comment.