blob: e4a26a3c91fa9968dae899bfa1299ccac3d68555 [file] [log] [blame]
Alexander Chemeris067f69c2017-07-18 16:44:26 +03001# -*- coding: utf-8 -*-
2
Harald Welteb2edd142021-01-08 23:29:35 +01003""" Various constants from ETSI TS 151.011 +
4Representation of the GSM SIM/USIM/ISIM filesystem hierarchy.
5
6The File (and its derived classes) uses the classes of pySim.filesystem in
7order to describe the files specified in the relevant ETSI + 3GPP specifications.
Alexander Chemeris067f69c2017-07-18 16:44:26 +03008"""
9
10#
11# Copyright (C) 2017 Alexander.Chemeris <Alexander.Chemeris@gmail.com>
Harald Welteb2edd142021-01-08 23:29:35 +010012# Copyright (C) 2021 Harald Welte <laforge@osmocom.org>
Alexander Chemeris067f69c2017-07-18 16:44:26 +030013#
14# This program is free software: you can redistribute it and/or modify
15# it under the terms of the GNU General Public License as published by
16# the Free Software Foundation, either version 2 of the License, or
17# (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program. If not, see <http://www.gnu.org/licenses/>.
26#
27
28MF_num = '3F00'
29
30DF_num = {
31'TELECOM': '7F10',
32
33'GSM': '7F20',
34'IS-41': '7F22',
35'FP-CTS': '7F23',
36
37'GRAPHICS': '5F50',
38
39'IRIDIUM': '5F30',
40'GLOBST': '5F31',
41'ICO': '5F32',
42'ACeS': '5F33',
43
44'EIA/TIA-553': '5F40',
45'CTS': '5F60',
46'SOLSA': '5F70',
47
48'MExE': '5F3C',
49}
50
51EF_num = {
52# MF
53'ICCID': '2FE2',
54'ELP': '2F05',
Sebastian Viviani0dc8f692020-05-29 00:14:55 +010055'DIR': '2F00',
Alexander Chemeris067f69c2017-07-18 16:44:26 +030056
57# DF_TELECOM
58'ADN': '6F3A',
59'FDN': '6F3B',
60'SMS': '6F3C',
61'CCP': '6F3D',
62'MSISDN': '6F40',
63'SMSP': '6F42',
64'SMSS': '6F43',
65'LND': '6F44',
66'SMSR': '6F47',
67'SDN': '6F49',
68'EXT1': '6F4A',
69'EXT2': '6F4B',
70'EXT3': '6F4C',
71'BDN': '6F4D',
72'EXT4': '6F4E',
73'CMI': '6F58',
74'ECCP': '6F4F',
75
76# DF_GRAPHICS
77'IMG': '4F20',
78
79# DF_SoLSA
80'SAI': '4F30',
81'SLL': '4F31',
82
83# DF_MExE
84'MExE-ST': '4F40',
85'ORPK': '4F41',
86'ARPK': '4F42',
87'TPRPK': '4F43',
88
89# DF_GSM
90'LP': '6F05',
91'IMSI': '6F07',
92'Kc': '6F20',
93'DCK': '6F2C',
94'PLMNsel': '6F30',
95'HPPLMN': '6F31',
96'CNL': '6F32',
97'ACMmax': '6F37',
98'SST': '6F38',
99'ACM': '6F39',
100'GID1': '6F3E',
101'GID2': '6F3F',
102'PUCT': '6F41',
103'CBMI': '6F45',
104'SPN': '6F46',
105'CBMID': '6F48',
106'BCCH': '6F74',
107'ACC': '6F78',
108'FPLMN': '6F7B',
109'LOCI': '6F7E',
110'AD': '6FAD',
111'PHASE': '6FAE',
112'VGCS': '6FB1',
113'VGCSS': '6FB2',
114'VBS': '6FB3',
115'VBSS': '6FB4',
116'eMLPP': '6FB5',
117'AAeM': '6FB6',
118'ECC': '6FB7',
119'CBMIR': '6F50',
120'NIA': '6F51',
121'KcGPRS': '6F52',
122'LOCIGPRS': '6F53',
123'SUME': '6F54',
124'PLMNwAcT': '6F60',
125'OPLMNwAcT': '6F61',
126# Figure 8 names it HPLMNAcT, but in the text it's names it HPLMNwAcT
127'HPLMNAcT': '6F62',
128'HPLMNwAcT': '6F62',
129'CPBCCH': '6F63',
130'INVSCAN': '6F64',
131'PNN': '6FC5',
132'OPL': '6FC6',
133'MBDN': '6FC7',
134'EXT6': '6FC8',
135'MBI': '6FC9',
136'MWIS': '6FCA',
137'CFIS': '6FCB',
138'EXT7': '6FCC',
139'SPDI': '6FCD',
140'MMSN': '6FCE',
141'EXT8': '6FCF',
142'MMSICP': '6FD0',
143'MMSUP': '6FD1',
144'MMSUCP': '6FD2',
145}
146
147DF = {
148'TELECOM': [MF_num, DF_num['TELECOM']],
149
150'GSM': [MF_num, DF_num['GSM']],
151'IS-41': [MF_num, DF_num['IS-41']],
152'FP-CTS': [MF_num, DF_num['FP-CTS']],
153
154'GRAPHICS': [MF_num, DF_num['GRAPHICS']],
155
156'IRIDIUM': [MF_num, DF_num['IRIDIUM']],
157'GLOBST': [MF_num, DF_num['GLOBST']],
158'ICO': [MF_num, DF_num['ICO']],
159'ACeS': [MF_num, DF_num['ACeS']],
160
161'EIA/TIA-553': [MF_num, DF_num['EIA/TIA-553']],
162'CTS': [MF_num, DF_num['CTS']],
163'SoLSA': [MF_num, DF_num['SOLSA']],
164
165'MExE': [MF_num, DF_num['MExE']],
166}
167
168
169EF = {
170'ICCID': [MF_num, EF_num['ICCID']],
171'ELP': [MF_num, EF_num['ELP']],
Sebastian Viviani0dc8f692020-05-29 00:14:55 +0100172'DIR': [MF_num, EF_num['DIR']],
Alexander Chemeris067f69c2017-07-18 16:44:26 +0300173
174'ADN': DF['TELECOM']+[EF_num['ADN']],
175'FDN': DF['TELECOM']+[EF_num['FDN']],
176'SMS': DF['TELECOM']+[EF_num['SMS']],
177'CCP': DF['TELECOM']+[EF_num['CCP']],
178'MSISDN': DF['TELECOM']+[EF_num['MSISDN']],
179'SMSP': DF['TELECOM']+[EF_num['SMSP']],
180'SMSS': DF['TELECOM']+[EF_num['SMSS']],
181'LND': DF['TELECOM']+[EF_num['LND']],
182'SMSR': DF['TELECOM']+[EF_num['SMSR']],
183'SDN': DF['TELECOM']+[EF_num['SDN']],
184'EXT1': DF['TELECOM']+[EF_num['EXT1']],
185'EXT2': DF['TELECOM']+[EF_num['EXT2']],
186'EXT3': DF['TELECOM']+[EF_num['EXT3']],
187'BDN': DF['TELECOM']+[EF_num['BDN']],
188'EXT4': DF['TELECOM']+[EF_num['EXT4']],
189'CMI': DF['TELECOM']+[EF_num['CMI']],
190'ECCP': DF['TELECOM']+[EF_num['ECCP']],
191
192'IMG': DF['GRAPHICS']+[EF_num['IMG']],
193
194'SAI': DF['SoLSA']+[EF_num['SAI']],
195'SLL': DF['SoLSA']+[EF_num['SLL']],
196
197'MExE-ST': DF['MExE']+[EF_num['MExE-ST']],
198'ORPK': DF['MExE']+[EF_num['ORPK']],
199'ARPK': DF['MExE']+[EF_num['ARPK']],
200'TPRPK': DF['MExE']+[EF_num['TPRPK']],
201
202'LP': DF['GSM']+[EF_num['LP']],
203'IMSI': DF['GSM']+[EF_num['IMSI']],
204'Kc': DF['GSM']+[EF_num['Kc']],
205'DCK': DF['GSM']+[EF_num['DCK']],
206'PLMNsel': DF['GSM']+[EF_num['PLMNsel']],
207'HPPLMN': DF['GSM']+[EF_num['HPPLMN']],
208'CNL': DF['GSM']+[EF_num['CNL']],
209'ACMmax': DF['GSM']+[EF_num['ACMmax']],
210'SST': DF['GSM']+[EF_num['SST']],
211'ACM': DF['GSM']+[EF_num['ACM']],
212'GID1': DF['GSM']+[EF_num['GID1']],
213'GID2': DF['GSM']+[EF_num['GID2']],
214'PUCT': DF['GSM']+[EF_num['PUCT']],
215'CBMI': DF['GSM']+[EF_num['CBMI']],
216'SPN': DF['GSM']+[EF_num['SPN']],
217'CBMID': DF['GSM']+[EF_num['CBMID']],
218'BCCH': DF['GSM']+[EF_num['BCCH']],
219'ACC': DF['GSM']+[EF_num['ACC']],
220'FPLMN': DF['GSM']+[EF_num['FPLMN']],
221'LOCI': DF['GSM']+[EF_num['LOCI']],
222'AD': DF['GSM']+[EF_num['AD']],
223'PHASE': DF['GSM']+[EF_num['PHASE']],
224'VGCS': DF['GSM']+[EF_num['VGCS']],
225'VGCSS': DF['GSM']+[EF_num['VGCSS']],
226'VBS': DF['GSM']+[EF_num['VBS']],
227'VBSS': DF['GSM']+[EF_num['VBSS']],
228'eMLPP': DF['GSM']+[EF_num['eMLPP']],
229'AAeM': DF['GSM']+[EF_num['AAeM']],
230'ECC': DF['GSM']+[EF_num['ECC']],
231'CBMIR': DF['GSM']+[EF_num['CBMIR']],
232'NIA': DF['GSM']+[EF_num['NIA']],
233'KcGPRS': DF['GSM']+[EF_num['KcGPRS']],
234'LOCIGPRS': DF['GSM']+[EF_num['LOCIGPRS']],
235'SUME': DF['GSM']+[EF_num['SUME']],
236'PLMNwAcT': DF['GSM']+[EF_num['PLMNwAcT']],
237'OPLMNwAcT': DF['GSM']+[EF_num['OPLMNwAcT']],
238# Figure 8 names it HPLMNAcT, but in the text it's names it HPLMNwAcT
239'HPLMNAcT': DF['GSM']+[EF_num['HPLMNAcT']],
240'HPLMNwAcT': DF['GSM']+[EF_num['HPLMNAcT']],
241'CPBCCH': DF['GSM']+[EF_num['CPBCCH']],
242'INVSCAN': DF['GSM']+[EF_num['INVSCAN']],
243'PNN': DF['GSM']+[EF_num['PNN']],
244'OPL': DF['GSM']+[EF_num['OPL']],
245'MBDN': DF['GSM']+[EF_num['MBDN']],
246'EXT6': DF['GSM']+[EF_num['EXT6']],
247'MBI': DF['GSM']+[EF_num['MBI']],
248'MWIS': DF['GSM']+[EF_num['MWIS']],
249'CFIS': DF['GSM']+[EF_num['CFIS']],
250'EXT7': DF['GSM']+[EF_num['EXT7']],
251'SPDI': DF['GSM']+[EF_num['SPDI']],
252'MMSN': DF['GSM']+[EF_num['MMSN']],
253'EXT8': DF['GSM']+[EF_num['EXT8']],
254'MMSICP': DF['GSM']+[EF_num['MMSICP']],
255'MMSUP': DF['GSM']+[EF_num['MMSUP']],
256'MMSUCP': DF['GSM']+[EF_num['MMSUCP']],
257}
Supreeth Herlebf5d6022020-03-20 15:18:27 +0100258
259# Mapping between SIM Service Number and its description
260EF_SST_map = {
261 1: 'CHV1 disable function',
262 2: 'Abbreviated Dialling Numbers (ADN)',
263 3: 'Fixed Dialling Numbers (FDN)',
264 4: 'Short Message Storage (SMS)',
265 5: 'Advice of Charge (AoC)',
266 6: 'Capability Configuration Parameters (CCP)',
267 7: 'PLMN selector',
268 8: 'RFU',
269 9: 'MSISDN',
270 10: 'Extension1',
271 11: 'Extension2',
272 12: 'SMS Parameters',
273 13: 'Last Number Dialled (LND)',
274 14: 'Cell Broadcast Message Identifier',
275 15: 'Group Identifier Level 1',
276 16: 'Group Identifier Level 2',
277 17: 'Service Provider Name',
278 18: 'Service Dialling Numbers (SDN)',
279 19: 'Extension3',
280 20: 'RFU',
281 21: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)',
282 22: 'VBS Group Identifier List (EFVBS and EFVBSS)',
283 23: 'enhanced Multi-Level Precedence and Pre-emption Service',
284 24: 'Automatic Answer for eMLPP',
285 25: 'Data download via SMS-CB',
286 26: 'Data download via SMS-PP',
287 27: 'Menu selection',
288 28: 'Call control',
289 29: 'Proactive SIM',
290 30: 'Cell Broadcast Message Identifier Ranges',
291 31: 'Barred Dialling Numbers (BDN)',
292 32: 'Extension4',
293 33: 'De-personalization Control Keys',
294 34: 'Co-operative Network List',
295 35: 'Short Message Status Reports',
296 36: 'Network\'s indication of alerting in the MS',
297 37: 'Mobile Originated Short Message control by SIM',
298 38: 'GPRS',
299 39: 'Image (IMG)',
300 40: 'SoLSA (Support of Local Service Area)',
301 41: 'USSD string data object supported in Call Control',
302 42: 'RUN AT COMMAND command',
303 43: 'User controlled PLMN Selector with Access Technology',
304 44: 'Operator controlled PLMN Selector with Access Technology',
305 45: 'HPLMN Selector with Access Technology',
306 46: 'CPBCCH Information',
307 47: 'Investigation Scan',
308 48: 'Extended Capability Configuration Parameters',
309 49: 'MExE',
310 50: 'Reserved and shall be ignored',
311 51: 'PLMN Network Name',
312 52: 'Operator PLMN List',
313 53: 'Mailbox Dialling Numbers',
314 54: 'Message Waiting Indication Status',
315 55: 'Call Forwarding Indication Status',
316 56: 'Service Provider Display Information',
317 57: 'Multimedia Messaging Service (MMS)',
318 58: 'Extension 8',
319 59: 'MMS User Connectivity Parameters',
Vadim Yanitskiydfe3dbb2020-07-28 05:26:02 +0700320}
321
322# 10.3.18 "EF.AD (Administrative data) "
323EF_AD_mode_map = {
324 '00' : 'normal operation',
325 '80' : 'type approval operations',
326 '01' : 'normal operation + specific facilities',
327 '81' : 'type approval operations + specific facilities',
328 '02' : 'maintenance (off line)',
329 '04' : 'cell test operation',
330}
Harald Welteb2edd142021-01-08 23:29:35 +0100331
332
333from pySim.utils import *
334from struct import pack, unpack
335
336from pySim.filesystem import *
337import pySim.ts_102_221
338
339######################################################################
340# DF.TELECOM
341######################################################################
342
343# TS 51.011 Section 10.5.1
344class EF_ADN(LinFixedEF):
345 def __init__(self, fid='6f3a', sfid=None, name='EF.ADN', desc='Abbreviated Dialing Numbers'):
346 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={14, 30})
347 def _decode_record_bin(self, raw_bin_data):
348 alpha_id_len = len(raw_bin_data) - 14
349 alpha_id = raw_bin_data[:alpha_id_len]
350 u = unpack('!BB10sBB', raw_bin_data[-14:])
351 return {'alpha_id': alpha_id, 'len_of_bcd': u[0], 'ton_npi': u[1],
352 'dialing_nr': u[2], 'cap_conf_id': u[3], 'ext1_record_id': u[4]}
353
354# TS 51.011 Section 10.5.5
355class EF_MSISDN(LinFixedEF):
356 def __init__(self, fid='6f4f', sfid=None, name='EF.MSISDN', desc='MSISDN'):
357 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={15, None})
358 def _decode_record_hex(self, raw_hex_data):
359 return {'msisdn': dec_msisdn(raw_hex_data)}
360 def _encode_record_hex(self, abstract):
361 return enc_msisdn(abstract['msisdn'])
362
363# TS 51.011 Section 10.5.6
364class EF_SMSP(LinFixedEF):
365 def __init__(self, fid='6f42', sfid=None, name='EF.SMSP', desc='Short message service parameters'):
366 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={28, None})
367
368class DF_TELECOM(CardDF):
369 def __init__(self, fid='7f10', name='DF.TELECOM', desc=None):
370 super().__init__(fid=fid, name=name, desc=desc)
371 files = [
372 EF_ADN(),
373 # FDN, SMS, CCP, ECCP
374 EF_MSISDN(),
375 EF_SMSP(),
376 # SMSS, LND, SDN, EXT1, EXT2, EXT3, BDN, EXT4, SMSR, CMI
377 ]
378 self.add_files(files)
379
380 def decode_select_response(self, data_hex):
381 return decode_select_response(data_hex)
382
383######################################################################
384# DF.GSM
385######################################################################
386
387# TS 51.011 Section 10.3.1
388class EF_LP(TransRecEF):
389 def __init__(self, fid='6f05', sfid=None, name='EF.LP', size={1,None}, rec_len=1,
390 desc='Language Preference'):
391 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
392 def _decode_record_bin(self, in_bin):
393 return b2h(in_bin)
394 def _encode_record_bin(self, in_json):
395 return h2b(in_json)
396
397# TS 51.011 Section 10.3.2
398class EF_IMSI(TransparentEF):
399 def __init__(self, fid='6f07', sfid=None, name='EF.IMSI', desc='IMSI', size={9,9}):
400 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
401 def _decode_hex(self, raw_hex):
402 return {'imsi': dec_imsi(raw_hex)}
403 def _encode_hex(self, abstract):
404 return enc_imsi(abstract['imsi'])
405
406# TS 51.011 Section 10.3.4
407class EF_PLMNsel(TransRecEF):
408 def __init__(self, fid='6f30', sfid=None, name='EF.PLMNsel', desc='PLMN selector',
409 size={24,None}, rec_len=3):
410 super().__init__(fid, name=name, sfid=sfid, desc=desc, size=size, rec_len=rec_len)
411 def _decode_record_hex(self, in_hex):
412 if in_hex[:6] == "ffffff":
413 return None
414 else:
415 return dec_plmn(in_hex)
416 def _encode_record_hex(self, in_json):
417 if in_json == None:
418 return "ffffff"
419 else:
420 return enc_plmn(in_json['mcc'], in_json['mnc'])
421
422# TS 51.011 Section 10.3.7
423class EF_ServiceTable(TransparentEF):
424 def __init__(self, fid, sfid, name, desc, size, table):
425 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
426 self.table = table
427 def _decode_bin(self, raw_bin):
428 ret = {}
429 for i in range(0, len(raw_bin)*4):
430 service_nr = i+1
431 byte = int(raw_bin[i//4])
432 bit_offset = (i % 4) * 2
433 bits = (byte >> bit_offset) & 3
434 ret[service_nr] = {
435 'description': self.table[service_nr] or None,
436 'allocated': True if bits & 1 else False,
437 'activated': True if bits & 2 else False,
438 }
439 return ret
440 # TODO: encoder
441
442# TS 51.011 Section 10.3.11
443class EF_SPN(TransparentEF):
444 def __init__(self, fid='6f46', sfid=None, name='EF.SPN', desc='Service Provider Name', size={17,17}):
445 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
446 def _decode_hex(self, raw_hex):
447 return {'spn': dec_spn(raw_hex)}
448 def _encode_hex(self, abstract):
449 return enc_spn(abstract['spn'])
450
451# TS 51.011 Section 10.3.13
452class EF_CBMI(TransRecEF):
453 def __init__(self, fid='6f45', sfid=None, name='EF.CBMI', size={2,None}, rec_len=2,
454 desc='Cell Broadcast message identifier selection'):
455 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
456
457# TS 51.011 Section 10.3.15
458class EF_ACC(TransparentEF):
459 def __init__(self, fid='6f78', sfid=None, name='EF.ACC', desc='Access Control Class', size={2,2}):
460 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
461 def _decode_bin(self, raw_bin):
462 return {'acc': unpack('!H', raw_bin)[0]}
463 def _encode_bin(self, abstract):
464 return pack('!H', abstract['acc'])
465
466# TS 51.011 Section 10.3.18
467class EF_AD(TransparentEF):
468 OP_MODE = {
469 0x00: 'normal operation',
470 0x80: 'type approval operations',
471 0x01: 'normal operation + specific facilities',
472 0x81: 'type approval + specific facilities',
473 0x02: 'maintenance (off line)',
474 0x04: 'cell test operation',
475 }
476 def __init__(self, fid='6fad', sfid=None, name='EF.AD', desc='Administrative Data', size={3,4}):
477 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
478 def _decode_bin(self, raw_bin):
479 u = unpack('!BH', raw_bin[:3])
480
481# TS 51.011 Section 10.3.13
482class EF_CBMID(EF_CBMI):
483 def __init__(self, fid='6f48', sfid=None, name='EF.CBMID', size={2,None}, rec_len=2,
484 desc='Cell Broadcast Message Identifier for Data Download'):
485 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
486
487# TS 51.011 Section 10.3.26
488class EF_ECC(LinFixedEF):
489 def __init__(self, fid='6fb7', sfid=None, name='EF.ECC', desc='Emergency Call Codes'):
490 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={4, 20})
491
492# TS 51.011 Section 10.3.28
493class EF_CBMIR(TransRecEF):
494 def __init__(self, fid='6f50', sfid=None, name='EF.CBMIR', size={4,None}, rec_len=4,
495 desc='Cell Broadcast message identifier range selection'):
496 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
497
498
499# TS 51.011 Section 10.3.35..37
500class EF_xPLMNwAcT(TransRecEF):
501 def __init__(self, fid, sfid=None, name=None, desc=None, size={40,None}, rec_len=5):
502 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
503 def _decode_record_hex(self, in_hex):
504 if in_hex[:6] == "ffffff":
505 return None
506 else:
507 return dec_xplmn_w_act(in_hex)
508 def _encode_record_hex(self, in_json):
509 if in_json == None:
510 return "ffffff0000"
511 else:
512 hplmn = enc_plmn(in_json['mcc'], in_json['mnc'])
513 act = self.enc_act(in_json['act'])
514 return hplmn + act
515 @staticmethod
516 def enc_act(in_list):
517 u16 = 0
518 # first the simple ones
519 if 'UTRAN' in in_list:
520 u16 |= 0x8000
521 if 'NG-RAN' in in_list:
522 u16 |= 0x0800
523 if 'GSM COMPACT' in in_list:
524 u16 |= 0x0040
525 if 'cdma2000 HRPD' in in_list:
526 u16 |= 0x0020
527 if 'cdma2000 1xRTT' in in_list:
528 u16 |= 0x0010
529 # E-UTRAN
Vadim Yanitskiy5452d642021-03-07 21:45:34 +0100530 if 'E-UTRAN WB-S1' in in_list:
531 u16 |= 0x6000
532 if 'E-UTRAN NB-S1' in in_list:
533 u16 |= 0x5000
Harald Welteb2edd142021-01-08 23:29:35 +0100534 # GSM mess
535 if 'GSM' in in_list and 'EC-GSM-IoT' in in_list:
536 u16 |= 0x008C
537 elif 'GSM' in in_list:
538 u16 |= 0x0084
539 elif 'EC-GSM-IuT' in in_list:
540 u16 |= 0x0088
541 return '%04X'%(u16)
542
543
544class DF_GSM(CardDF):
545 def __init__(self, fid='7f20', name='DF.GSM', desc='GSM Network related files'):
546 super().__init__(fid=fid, name=name, desc=desc)
547 files = [
548 EF_LP(),
549 EF_IMSI(),
550 TransparentEF('5f20', None, 'EF.Kc', 'Ciphering key Kc'),
551 EF_PLMNsel(),
552 TransparentEF('6f31', None, 'EF.HPPLMN', 'Higher Priority PLMN search period'),
553 # ACMmax
554 EF_ServiceTable('6f37', None, 'EF.SST', 'SIM service table', table=EF_SST_map, size={2,16}),
555 CyclicEF('6f39', None, 'EF.ACM', 'Accumulated call meter', rec_len={4,3}),
556 TransparentEF('6f3e', None, 'EF.GID1', 'Group Identifier Level 1'),
557 TransparentEF('6f3f', None, 'EF.GID2', 'Group Identifier Level 2'),
558 EF_SPN(),
559 TransparentEF('6f41', None, 'EF.PUCT', 'Price per unit and currency table', size={5,5}),
560 EF_CBMI(),
561 TransparentEF('6f7f', None, 'EF.BCCH', 'Broadcast control channels', size={16,16}),
562 EF_ACC(),
563 EF_PLMNsel('6f7b', None, 'EF.FPLMN', 'Forbidden PLMNs', size={12,12}),
564 TransparentEF('6f7e', None, 'EF.LOCI', 'Locationn information', size={11,11}),
565 EF_AD(),
566 TransparentEF('6fa3', None, 'EF.Phase', 'Phase identification', size={1,1}),
567 # TODO EF.VGCS VGCSS, VBS, VBSS, eMLPP, AAeM
568 EF_CBMID(),
569 EF_ECC(),
570 EF_CBMIR(),
571 # DCK, CNL, NIA, KcGRS, LOCIGPRS, SUME
572 EF_xPLMNwAcT('6f60', None, 'EF.PLMNwAcT',
573 'User controlled PLMN Selector with Access Technology'),
574 EF_xPLMNwAcT('6f61', None, 'EF.OPLMNwAcT',
575 'Operator controlled PLMN Selector with Access Technology'),
576 EF_xPLMNwAcT('6f62', None, 'EF.HPLMNwAcT', 'HPLMN Selector with Access Technology'),
577 # CPBCCH, InvScan, PNN, OPL, MBDN, MBI, MWIS, CFIS, EXT5, EXT6, EXT7, SPDI, MMSN, EXT8
578 # MMSICP, MMSUP, MMSUCP
579 ]
580 self.add_files(files)
581
582 def decode_select_response(self, data_hex):
583 return decode_select_response(data_hex)
584
585def decode_select_response(resp_hex):
586 resp_bin = h2b(resp_hex)
587 if resp_bin[0] == 0x62:
588 return pySim.ts_102_221.decode_select_response(resp_hex)
589 struct_of_file_map = {
590 0: 'transparent',
591 1: 'linear_fixed',
592 3: 'cyclic'
593 }
594 type_of_file_map = {
595 1: 'mf',
596 2: 'df',
597 4: 'working_ef'
598 }
599 ret = {
600 'file_descriptor': {},
601 'proprietary_info': {},
602 }
603 ret['file_id'] = b2h(resp_bin[4:6])
604 ret['proprietary_info']['available_memory'] = int.from_bytes(resp_bin[2:4], 'big')
605 file_type = type_of_file_map[resp_bin[6]] if resp_bin[6] in type_of_file_map else resp_bin[6]
606 ret['file_descriptor']['file_type'] = file_type
607 if file_type in ['mf', 'df']:
608 ret['file_characteristics'] = b2h(resp_bin[13])
609 ret['num_direct_child_df'] = int(resp_bin[14], 16)
610 ret['num_direct_child_ef'] = int(resp_bin[15], 16)
611 ret['num_chv_unbkock_adm_codes'] = int(resp_bin[16])
612 # CHV / UNBLOCK CHV stats
613 elif file_type in ['working_ef']:
614 file_struct = struct_of_file_map[resp_bin[13]] if resp_bin[13] in struct_of_file_map else resp_bin[13]
615 ret['file_descriptor']['structure'] = file_struct
616 ret['access_conditions'] = b2h(resp_bin[8:10])
617 if resp_bin[11] & 0x01 == 0:
618 ret['life_cycle_status_int'] = 'operational_activated'
619 elif resp_bin[11] & 0x04:
620 ret['life_cycle_status_int'] = 'operational_deactivated'
621 else:
622 ret['life_cycle_status_int'] = 'terminated'
623
624 return ret
625
626CardProfileSIM = CardProfile('SIM', desc='GSM SIM Card', files_in_mf=[DF_TELECOM(), DF_GSM()])