fixeria has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/32351 )
Change subject: filesystem: define more convenient codec for EF.ACC ......................................................................
filesystem: define more convenient codec for EF.ACC
This patch improves the output of the 'read_binary_decoded' command:
pySIM-shell (MF/DF.GSM/EF.ACC)> read_binary_decoded { "ACC0": false, "ACC1": false, "ACC2": false, "ACC3": false, "ACC4": false, "ACC5": false, "ACC6": false, "ACC7": false, "ACC8": false, "ACC9": false, "ACC10": false, "ACC11": false, "ACC12": false, "ACC13": false, "ACC14": false, "ACC15": true }
And allows to set/unset individual ACCs using 'update_binary_decoded':
pySIM-shell (MF/DF.GSM/EF.ACC)> update_binary_decoded --json-path 'ACC15' 0 "0000" pySIM-shell (MF/DF.GSM/EF.ACC)> update_binary_decoded --json-path 'ACC8' 1 "0100" pySIM-shell (MF/DF.GSM/EF.ACC)> update_binary_decoded --json-path 'ACC0' 1 "0101"
Change-Id: I805b3277410745815d3fdc44b9c0f8c5be8d7a10 Related: SYS#6425 --- M pySim/ts_51_011.py 1 file changed, 55 insertions(+), 2 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, approved
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py index b9e19b2..3dc21c8 100644 --- a/pySim/ts_51_011.py +++ b/pySim/ts_51_011.py @@ -717,13 +717,25 @@
# TS 51.011 Section 10.3.15 class EF_ACC(TransparentEF): + # example: acc_list(15) will produce a dict with only ACC15 being True + # example: acc_list(2, 4) will produce a dict with ACC2 and ACC4 being True + # example: acc_list() will produce a dict with all ACCs being False + acc_list = lambda *active: {'ACC{}'.format(c) : c in active for c in range(16)} + _test_de_encode = [ - ( "0100", "0100" ), + ( "0000", acc_list() ), + ( "0001", acc_list(0) ), + ( "0002", acc_list(1) ), + ( "0100", acc_list(8) ), + ( "8000", acc_list(15) ), + ( "802b", acc_list(0,1,3,5,15) ), ] def __init__(self, fid='6f78', sfid=None, name='EF.ACC', desc='Access Control Class', size=(2, 2), **kwargs): super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) - self._construct = HexAdapter(Bytes(2)) + # LSB of octet 2 is ACC=0 ... MSB of octet 1 is ACC=15 + flags = ['ACC{}'.format(c) / Flag for c in range(16)] + self._construct = ByteSwapped(BitsSwapped(BitStruct(*flags)))
# TS 51.011 Section 10.3.16 class EF_LOCI(TransparentEF):