diff options
author | Robert Falkenberg <robert.falkenberg@tu-dortmund.de> | 2021-05-07 15:23:20 +0200 |
---|---|---|
committer | Robert Falkenberg <robert.falkenberg@tu-dortmund.de> | 2021-05-10 06:15:39 +0200 |
commit | b07a3e9c87fc742aab2515ce1e6f9e4d20c91cae (patch) | |
tree | a73e9b021eeeeede426702535923a6eb3a933d4c /pySim/cards.py | |
parent | c957ce8adc4ecd5084cd8f7ed86b8c4e200c22f6 (diff) |
Add codecs for EF_SPN and GSM strings via construct
This will replace the hand-crafted codec for EF_SPN
by a struct definition using the construct library.
Old encoders are updated and kept for API compatibility
but are not used internally anymore.
New data structures:
* Rpad(Adapter): Right-padded bytestring (0xff, adjustable)
* GsmStringAdapter(Adapter): Codec for "SMS default 7-bit
coded alphabet as defined int TS 23.038" using
the gsm0338 library.
* GsmString(n): Convenient wrapper of both above
Adjustments:
* utils: update+deprecate old dec_spn(), enc_spn()
* remove refs to deprecated functions
Change-Id: Ia1d3a3835933bac0002b7c52511481dd8094b994
Diffstat (limited to 'pySim/cards.py')
-rw-r--r-- | pySim/cards.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/pySim/cards.py b/pySim/cards.py index 30857b3..dcba26c 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -25,7 +25,7 @@ from typing import Optional, Dict, Tuple import abc -from pySim.ts_51_011 import EF, DF, EF_AD +from pySim.ts_51_011 import EF, DF, EF_AD, EF_SPN from pySim.ts_31_102 import EF_USIM_ADF_map from pySim.ts_31_103 import EF_ISIM_ADF_map from pySim.utils import * @@ -203,15 +203,24 @@ class Card(object): return sw def read_spn(self): - (spn, sw) = self._scc.read_binary(EF['SPN']) + (content, sw) = self._scc.read_binary(EF['SPN']) if sw == '9000': - return (dec_spn(spn), sw) + abstract_data = EF_SPN().decode_hex(content) + show_in_hplmn = abstract_data['show_in_hplmn'] + hide_in_oplmn = abstract_data['hide_in_oplmn'] + name = abstract_data['spn'] + return ((name, show_in_hplmn, hide_in_oplmn), sw) else: return (None, sw) - def update_spn(self, name, hplmn_disp=False, oplmn_disp=False): - content = enc_spn(name, hplmn_disp, oplmn_disp) - data, sw = self._scc.update_binary(EF['SPN'], rpad(content, 32)) + def update_spn(self, name="", show_in_hplmn=False, hide_in_oplmn=False): + abstract_data = { + 'hide_in_oplmn' : hide_in_oplmn, + 'show_in_hplmn' : show_in_hplmn, + 'spn' : name, + } + content = EF_SPN().encode_hex(abstract_data) + data, sw = self._scc.update_binary(EF['SPN'], content) return sw def read_binary(self, ef, length=None, offset=0): @@ -915,8 +924,7 @@ class SysmoUSIMSJS1(UsimCard): # set Service Provider Name if p.get('name') is not None: - content = enc_spn(p['name'], True, True) - data, sw = self._scc.update_binary('6F46', rpad(content, 32)) + self.update_spn(p['name'], True, True) if p.get('acc') is not None: self.update_acc(p['acc']) @@ -1310,8 +1318,7 @@ class SysmoISIMSJA2(UsimCard, IsimCard): # set Service Provider Name if p.get('name') is not None: - content = enc_spn(p['name'], True, True) - data, sw = self._scc.update_binary('6F46', rpad(content, 32)) + self.update_spn(p['name'], True, True) # write EF.IMSI if p.get('imsi'): |