blob: f347f67a66455f3c3467d2af18c8f40d0f130b5f [file] [log] [blame]
Supreeth Herle475dcaa2020-03-20 18:57:39 +01001# -*- coding: utf-8 -*-
2
Harald Weltef12979d2021-05-29 21:47:13 +02003# without this, pylint will fail when inner classes are used
4# within the 'nested' kwarg of our TlvMeta metaclass on python 3.7 :(
5# pylint: disable=undefined-variable
6
Supreeth Herle475dcaa2020-03-20 18:57:39 +01007"""
Harald Welte2f831032021-04-20 23:54:53 +02008Various constants from 3GPP TS 31.102 V16.6.0
Supreeth Herle475dcaa2020-03-20 18:57:39 +01009"""
10
11#
12# Copyright (C) 2020 Supreeth Herle <herlesupreeth@gmail.com>
Harald Welte790b2702021-04-11 00:01:35 +020013# Copyright (C) 2021 Harald Welte <laforge@osmocom.org>
Supreeth Herle475dcaa2020-03-20 18:57:39 +010014#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 2 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
27#
28
29# Mapping between USIM Service Number and its description
30EF_UST_map = {
31 1: 'Local Phone Book',
32 2: 'Fixed Dialling Numbers (FDN)',
33 3: 'Extension 2',
34 4: 'Service Dialling Numbers (SDN)',
35 5: 'Extension3',
36 6: 'Barred Dialling Numbers (BDN)',
37 7: 'Extension4',
38 8: 'Outgoing Call Information (OCI and OCT)',
39 9: 'Incoming Call Information (ICI and ICT)',
40 10: 'Short Message Storage (SMS)',
41 11: 'Short Message Status Reports (SMSR)',
42 12: 'Short Message Service Parameters (SMSP)',
43 13: 'Advice of Charge (AoC)',
44 14: 'Capability Configuration Parameters 2 (CCP2)',
45 15: 'Cell Broadcast Message Identifier',
46 16: 'Cell Broadcast Message Identifier Ranges',
47 17: 'Group Identifier Level 1',
48 18: 'Group Identifier Level 2',
49 19: 'Service Provider Name',
50 20: 'User controlled PLMN selector with Access Technology',
51 21: 'MSISDN',
52 22: 'Image (IMG)',
53 23: 'Support of Localised Service Areas (SoLSA)',
54 24: 'Enhanced Multi-Level Precedence and Pre-emption Service',
55 25: 'Automatic Answer for eMLPP',
56 26: 'RFU',
57 27: 'GSM Access',
58 28: 'Data download via SMS-PP',
59 29: 'Data download via SMS-CB',
60 30: 'Call Control by USIM',
61 31: 'MO-SMS Control by USIM',
62 32: 'RUN AT COMMAND command',
63 33: 'shall be set to 1',
64 34: 'Enabled Services Table',
65 35: 'APN Control List (ACL)',
66 36: 'Depersonalisation Control Keys',
67 37: 'Co-operative Network List',
68 38: 'GSM security context',
69 39: 'CPBCCH Information',
70 40: 'Investigation Scan',
71 41: 'MexE',
72 42: 'Operator controlled PLMN selector with Access Technology',
73 43: 'HPLMN selector with Access Technology',
74 44: 'Extension 5',
75 45: 'PLMN Network Name',
76 46: 'Operator PLMN List',
77 47: 'Mailbox Dialling Numbers',
78 48: 'Message Waiting Indication Status',
79 49: 'Call Forwarding Indication Status',
80 50: 'Reserved and shall be ignored',
81 51: 'Service Provider Display Information',
82 52: 'Multimedia Messaging Service (MMS)',
83 53: 'Extension 8',
84 54: 'Call control on GPRS by USIM',
85 55: 'MMS User Connectivity Parameters',
86 56: 'Network\'s indication of alerting in the MS (NIA)',
87 57: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)',
88 58: 'VBS Group Identifier List (EFVBS and EFVBSS)',
89 59: 'Pseudonym',
90 60: 'User Controlled PLMN selector for I-WLAN access',
91 61: 'Operator Controlled PLMN selector for I-WLAN access',
92 62: 'User controlled WSID list',
93 63: 'Operator controlled WSID list',
94 64: 'VGCS security',
95 65: 'VBS security',
96 66: 'WLAN Reauthentication Identity',
97 67: 'Multimedia Messages Storage',
98 68: 'Generic Bootstrapping Architecture (GBA)',
99 69: 'MBMS security',
100 70: 'Data download via USSD and USSD application mode',
101 71: 'Equivalent HPLMN',
102 72: 'Additional TERMINAL PROFILE after UICC activation',
103 73: 'Equivalent HPLMN Presentation Indication',
104 74: 'Last RPLMN Selection Indication',
105 75: 'OMA BCAST Smart Card Profile',
106 76: 'GBA-based Local Key Establishment Mechanism',
107 77: 'Terminal Applications',
108 78: 'Service Provider Name Icon',
109 79: 'PLMN Network Name Icon',
110 80: 'Connectivity Parameters for USIM IP connections',
111 81: 'Home I-WLAN Specific Identifier List',
112 82: 'I-WLAN Equivalent HPLMN Presentation Indication',
113 83: 'I-WLAN HPLMN Priority Indication',
114 84: 'I-WLAN Last Registered PLMN',
115 85: 'EPS Mobility Management Information',
116 86: 'Allowed CSG Lists and corresponding indications',
117 87: 'Call control on EPS PDN connection by USIM',
118 88: 'HPLMN Direct Access',
119 89: 'eCall Data',
120 90: 'Operator CSG Lists and corresponding indications',
121 91: 'Support for SM-over-IP',
122 92: 'Support of CSG Display Control',
123 93: 'Communication Control for IMS by USIM',
124 94: 'Extended Terminal Applications',
125 95: 'Support of UICC access to IMS',
126 96: 'Non-Access Stratum configuration by USIM',
127 97: 'PWS configuration by USIM',
128 98: 'RFU',
129 99: 'URI support by UICC',
130 100: 'Extended EARFCN support',
131 101: 'ProSe',
132 102: 'USAT Application Pairing',
133 103: 'Media Type support',
134 104: 'IMS call disconnection cause',
135 105: 'URI support for MO SHORT MESSAGE CONTROL',
136 106: 'ePDG configuration Information support',
137 107: 'ePDG configuration Information configured',
138 108: 'ACDC support',
139 109: 'MCPTT',
140 110: 'ePDG configuration Information for Emergency Service support',
141 111: 'ePDG configuration Information for Emergency Service configured',
Supreeth Herle4d9e6be2020-03-24 12:13:45 +0100142 112: 'eCall Data over IMS',
143 113: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [12]',
144 114: 'From Preferred',
145 115: 'IMS configuration data',
146 116: 'TV configuration',
147 117: '3GPP PS Data Off',
148 118: '3GPP PS Data Off Service List',
149 119: 'V2X',
150 120: 'XCAP Configuration Data',
151 121: 'EARFCN list for MTC/NB-IOT UEs',
152 122: '5GS Mobility Management Information',
153 123: '5G Security Parameters',
154 124: 'Subscription identifier privacy support',
155 125: 'SUCI calculation by the USIM',
156 126: 'UAC Access Identities support',
157 127: 'Expect control plane-based Steering of Roaming information during initial registration in VPLMN',
158 128: 'Call control on PDU Session by USIM',
Harald Welte2f831032021-04-20 23:54:53 +0200159 129: '5GS Operator PLMN List',
160 130: 'Support for SUPI of type NSI or GLI or GCI',
161 131: '3GPP PS Data Off separate Home and Roaming lists',
162 132: 'Support for URSP by USIM',
163 133: '5G Security Parameters extended',
164 134: 'MuD and MiD configuration data',
165 135: 'Support for Trusted non-3GPP access networks by USIM'
Sebastian Viviani0dc8f692020-05-29 00:14:55 +0100166}
167
Sebastian Vivianie61170c2020-06-03 08:57:00 +0100168LOCI_STATUS_map = {
169 0: 'updated',
170 1: 'not updated',
171 2: 'plmn not allowed',
172 3: 'locatation area not allowed'
173}
herlesupreetha562ea02020-09-16 20:17:22 +0200174
Sebastian Viviani0dc8f692020-05-29 00:14:55 +0100175EF_USIM_ADF_map = {
176 'LI': '6F05',
177 'ARR': '6F06',
178 'IMSI': '6F07',
179 'Keys': '6F08',
180 'KeysPS': '6F09',
181 'DCK': '6F2C',
182 'HPPLMN': '6F31',
183 'CNL': '6F32',
184 'ACMmax': '6F37',
185 'UST': '6F38',
186 'ACM': '6F39',
187 'FDN': '6F3B',
188 'SMS': '6F3C',
189 'GID1': '6F3E',
190 'GID2': '6F3F',
191 'MSISDN': '6F40',
192 'PUCT': '6F41',
193 'SMSP': '6F42',
194 'SMSS': '6F42',
195 'CBMI': '6F45',
196 'SPN': '6F46',
197 'SMSR': '6F47',
198 'CBMID': '6F48',
199 'SDN': '6F49',
200 'EXT2': '6F4B',
201 'EXT3': '6F4C',
202 'BDN': '6F4D',
203 'EXT5': '6F4E',
204 'CCP2': '6F4F',
205 'CBMIR': '6F50',
206 'EXT4': '6F55',
207 'EST': '6F56',
208 'ACL': '6F57',
209 'CMI': '6F58',
210 'START-HFN': '6F5B',
211 'THRESHOLD': '6F5C',
212 'PLMNwAcT': '6F60',
213 'OPLMNwAcT': '6F61',
214 'HPLMNwAcT': '6F62',
215 'PSLOCI': '6F73',
216 'ACC': '6F78',
217 'FPLMN': '6F7B',
218 'LOCI': '6F7E',
219 'ICI': '6F80',
220 'OCI': '6F81',
221 'ICT': '6F82',
222 'OCT': '6F83',
223 'AD': '6FAD',
224 'VGCS': '6FB1',
225 'VGCSS': '6FB2',
226 'VBS': '6FB3',
227 'VBSS': '6FB4',
228 'eMLPP': '6FB5',
229 'AAeM': '6FB6',
230 'ECC': '6FB7',
231 'Hiddenkey': '6FC3',
232 'NETPAR': '6FC4',
233 'PNN': '6FC5',
234 'OPL': '6FC6',
235 'MBDN': '6FC7',
236 'EXT6': '6FC8',
237 'MBI': '6FC9',
238 'MWIS': '6FCA',
239 'CFIS': '6FCB',
240 'EXT7': '6FCC',
241 'SPDI': '6FCD',
242 'MMSN': '6FCE',
243 'EXT8': '6FCF',
244 'MMSICP': '6FD0',
245 'MMSUP': '6FD1',
246 'MMSUCP': '6FD2',
247 'NIA': '6FD3',
248 'VGCSCA': '6FD4',
249 'VBSCA': '6FD5',
250 'GBAP': '6FD6',
251 'MSK': '6FD7',
252 'MUK': '6FD8',
253 'EHPLMN': '6FD9',
254 'GBANL': '6FDA',
255 'EHPLMNPI': '6FDB',
256 'LRPLMNSI': '6FDC',
257 'NAFKCA': '6FDD',
258 'SPNI': '6FDE',
259 'PNNI': '6FDF',
260 'NCP-IP': '6FE2',
261 'EPSLOCI': '6FE3',
262 'EPSNSC': '6FE4',
263 'UFC': '6FE6',
264 'UICCIARI': '6FE7',
265 'NASCONFIG': '6FE8',
266 'PWC': '6FEC',
267 'FDNURI': '6FED',
268 'BDNURI': '6FEE',
269 'SDNURI': '6FEF',
270 'IWL': '6FF0',
271 'IPS': '6FF1',
272 'IPD': '6FF2',
273 'ePDGId': '6FF3',
274 'ePDGSelection': '6FF4',
275 'ePDGIdEm': '6FF5',
276 'ePDGSelectionEm': '6FF6',
277}
Harald Welteb2edd142021-01-08 23:29:35 +0100278
279######################################################################
280# ADF.USIM
281######################################################################
282
Harald Welte592b32e2021-06-05 11:26:36 +0200283import enum
Harald Welte15fae982021-04-10 10:22:27 +0200284from struct import unpack, pack
Harald Welte9853e242021-04-10 19:08:25 +0200285from construct import *
Harald Welte592b32e2021-06-05 11:26:36 +0200286from construct import Optional as COptional
Harald Weltef12979d2021-05-29 21:47:13 +0200287from pySim.construct import *
Harald Welteb2edd142021-01-08 23:29:35 +0100288from pySim.filesystem import *
Harald Weltef12979d2021-05-29 21:47:13 +0200289from pySim.tlv import *
Harald Welte790b2702021-04-11 00:01:35 +0200290from pySim.ts_102_221 import EF_ARR
Harald Welte592b32e2021-06-05 11:26:36 +0200291from pySim.ts_51_011 import EF_IMSI, EF_xPLMNwAcT, EF_SPN, EF_CBMI, EF_ACC, EF_PLMNsel
Harald Welte790b2702021-04-11 00:01:35 +0200292from pySim.ts_51_011 import EF_CBMID, EF_CBMIR, EF_ADN, EF_SMS, EF_MSISDN, EF_SMSP, EF_SMSS
293from pySim.ts_51_011 import EF_SMSR, EF_DCK, EF_EXT, EF_CNL, EF_OPL, EF_MBI, EF_MWIS
294from pySim.ts_51_011 import EF_MMSN, EF_MMSICP, EF_MMSUP, EF_MMSUCP, EF_VGCS, EF_VGCSS, EF_NIA
295from pySim.ts_51_011 import EF_ACMmax, EF_AAeM, EF_eMLPP, EF_CMI
Harald Welteb2edd142021-01-08 23:29:35 +0100296
297import pySim.ts_102_221
298
Harald Weltef12979d2021-05-29 21:47:13 +0200299# 3GPP TS 31.102 Section 4.4.11.4 (EF_5GS3GPPNSC)
300class EF_5GS3GPPNSC(LinFixedEF):
301 class NgKSI(BER_TLV_IE, tag=0x80):
302 _construct = Int8ub
303
304 class K_AMF(BER_TLV_IE, tag=0x81):
305 _construct = HexAdapter(Bytes(32))
306
307 class UplinkNASCount(BER_TLV_IE, tag=0x82):
308 _construct = Int32ub
309
310 class DownlinkNASCount(BER_TLV_IE, tag=0x83):
311 _construct = Int32ub
312
313 class IdsOfSelectedNasAlgos(BER_TLV_IE, tag=0x84):
314 # 3GPP TS 24.501 Section 9.11.3.34
315 _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
316
317 class IdsOfSelectedEpsAlgos(BER_TLV_IE, tag=0x85):
318 # 3GPP TS 24.301 Section 9.9.3.23
319 _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
320
321 class FiveGSNasSecurityContext(BER_TLV_IE, tag=0xA0,
322 nested=[NgKSI, K_AMF, UplinkNASCount,
323 DownlinkNASCount, IdsOfSelectedNasAlgos,
324 IdsOfSelectedEpsAlgos]):
325 pass
326
327 def __init__(self, fid="4f03", sfid=0x03, name='EF.5GS3GPPNSC', rec_len={57, None},
328 desc='5GS 3GPP Access NAS Security Context'):
329 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
330 self._tlv = EF_5GS3GPPNSC.FiveGSNasSecurityContext()
331
332# 3GPP TS 31.102 Section 4.4.11.6
333class EF_5GAUTHKEYS(TransparentEF):
334 class K_AUSF(BER_TLV_IE, tag=0x80):
335 _construct = HexAdapter(GreedyBytes)
336
337 class K_SEAF(BER_TLV_IE, tag=0x81):
338 _construct = HexAdapter(GreedyBytes)
339
340 class FiveGAuthKeys(TLV_IE_Collection, nested=[K_AUSF, K_SEAF]):
341 pass
342
343 def __init__(self, fid='4f05', sfid=0x05, name='EF.5GAUTHKEYS', size={68, None},
344 desc='5G authentication keys'):
345 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
346 self._tlv = EF_5GAUTHKEYS.FiveGAuthKeys()
347
348# 3GPP TS 31.102 Section 4.4.11.8
349class ProtSchemeIdList(BER_TLV_IE, tag=0xa0):
350 # FIXME: 3GPP TS 24.501 Protection Scheme Identifier
351 # repeated sequence of (id, index) tuples
352 _construct = GreedyRange(Struct('id'/Enum(Byte, null=0, A=1, B=2), 'index'/Int8ub))
353
354class HomeNetPubKeyId(BER_TLV_IE, tag=0x80):
355 # 3GPP TS 24.501 / 3GPP TS 23.003
356 _construct = Int8ub
357
358class HomeNetPubKey(BER_TLV_IE, tag=0x81):
359 # FIXME: RFC 5480
360 _construct = HexAdapter(GreedyBytes)
361
362class HomeNetPubKeyList(BER_TLV_IE, tag=0xa1,
363 nested=[HomeNetPubKeyId, HomeNetPubKey]):
364 pass
365
366# 3GPP TS 31.102 Section 4.4.11.6
367class SUCI_CalcInfo(TLV_IE_Collection, nested=[ProtSchemeIdList,HomeNetPubKeyList]):
368 pass
369
370
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200371# TS 31.102 4.4.11.8
372class EF_SUCI_Calc_Info(TransparentEF):
373 def __init__(self, fid="4f07", sfid=0x07, name='EF.SUCI_Calc_Info', size={2, None},
374 desc='SUCI Calc Info'):
375 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
376
377 def _encode_prot_scheme_id_list(self, in_list):
378 out_bytes = [0xa0]
379 out_bytes.append(len(in_list)*2) # two byte per entry
380
381 # position in list determines priority; high-priority items (low index) come first
382 for scheme in sorted(in_list, key=lambda item: item["priority"]):
383 out_bytes.append(scheme["identifier"])
384 out_bytes.append(scheme["key_index"])
385
386 return out_bytes
387
388 def _encode_hnet_pubkey_list(self, hnet_pubkey_list):
389 out_bytes = [0xa1] # pubkey list tag
390 out_bytes.append(0x00) # length filled later
391 length = 0
392
393 for key in hnet_pubkey_list:
394 out_bytes.append(0x80) # identifier tag
395 out_bytes.append(0x01) # TODO size, fixed to 1 byte
396 out_bytes.append(key["hnet_pubkey_identifier"])
397 out_bytes.append(0x81) # key tag
398 out_bytes.append(len(key["hnet_pubkey"])//2)
399 length += 5+len(key["hnet_pubkey"])//2
400
401 pubkey_bytes = h2b(key["hnet_pubkey"])
402 out_bytes += pubkey_bytes
403
404 # fill length
405 out_bytes[1] = length
406 return out_bytes
407
408 def _encode_hex(self, in_json):
409 out_bytes = self._encode_prot_scheme_id_list(in_json['prot_scheme_id_list'])
410 out_bytes += self._encode_hnet_pubkey_list(in_json['hnet_pubkey_list'])
411 return "".join(["%02X" % i for i in out_bytes])
412
413 def _decode_prot_scheme_id_list(self, in_bytes):
414 prot_scheme_id_list = []
415 pos = 0
416 # two bytes per entry
417 while pos < len(in_bytes):
418 prot_scheme = {
419 'priority': pos//2, # first in list: high priority
420 'identifier': in_bytes[pos],
421 'key_index': in_bytes[pos+1]
422 }
423 pos += 2
424 prot_scheme_id_list.append(prot_scheme)
425 return prot_scheme_id_list
426
427 def _decode_hnet_pubkey_list(self, in_bytes):
428 hnet_pubkey_list = []
429 pos = 0
430 if in_bytes[pos] != 0xa1:
431 print("missing Home Network Public Key List data object")
432 return {}
433 pos += 1
434 hnet_pubkey_list_len = in_bytes[pos]
435 pos += 1
436
437 while pos < hnet_pubkey_list_len:
438 if in_bytes[pos] != 0x80:
439 print("missing Home Network Public Key Identifier tag")
440 return {}
441 pos += 1
442 hnet_pubkey_id_len = in_bytes[pos] # TODO might be more than 1 byte?
443 pos += 1
444 hnet_pubkey_id = in_bytes[pos:pos+hnet_pubkey_id_len][0]
445 pos += hnet_pubkey_id_len
446 if in_bytes[pos] != 0x81:
447 print("missing Home Network Public Key tag")
448 return {}
449 pos += 1
450 hnet_pubkey_len = in_bytes[pos]
451 pos += 1
452 hnet_pubkey = in_bytes[pos:pos+hnet_pubkey_len]
453 pos += hnet_pubkey_len
454
455 hnet_pubkey_list.append({
456 'hnet_pubkey_identifier': hnet_pubkey_id,
457 'hnet_pubkey': b2h(hnet_pubkey)
458 })
459
460 return hnet_pubkey_list
461
462 def _decode_bin(self, in_bin):
Vadim Yanitskiy5e41eeb2021-05-02 02:20:33 +0200463 return self._decode_hex(b2h(in_bin))
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200464
465 def _decode_hex(self, in_hex):
466 in_bytes = h2b(in_hex)
467 pos = 0
468
469 if in_bytes[pos] != 0xa0:
470 print("missing Protection Scheme Identifier List data object tag")
471 return {}
472 pos += 1
473
474 prot_scheme_id_list_len = in_bytes[pos] # TODO maybe more than 1 byte
475 pos += 1
476 # decode Protection Scheme Identifier List data object
477 prot_scheme_id_list = self._decode_prot_scheme_id_list(in_bytes[pos:pos+prot_scheme_id_list_len])
478 pos += prot_scheme_id_list_len
479
480 # remaining data holds Home Network Public Key Data Object
481 hnet_pubkey_list = self._decode_hnet_pubkey_list(in_bytes[pos:])
482
483 return {
484 'prot_scheme_id_list': prot_scheme_id_list,
485 'hnet_pubkey_list': hnet_pubkey_list
486 }
487
488 def _encode_bin(self, in_json):
489 return h2b(self._encode_hex(in_json))
490
Harald Welteb2edd142021-01-08 23:29:35 +0100491class EF_LI(TransRecEF):
492 def __init__(self, fid='6f05', sfid=None, name='EF.LI', size={2,None}, rec_len=2,
493 desc='Language Indication'):
494 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
495 def _decode_record_bin(self, in_bin):
496 if in_bin == b'\xff\xff':
497 return None
498 else:
499 # officially this is 7-bit GSM alphabet with one padding bit in each byte
500 return in_bin.decode('ascii')
501 def _encode_record_bin(self, in_json):
502 if in_json == None:
503 return b'\xff\xff'
504 else:
505 # officially this is 7-bit GSM alphabet with one padding bit in each byte
506 return in_json.encode('ascii')
507
508class EF_Keys(TransparentEF):
509 def __init__(self, fid='6f08', sfid=0x08, name='EF.Keys', size={33,33},
510 desc='Ciphering and Integrity Keys'):
511 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
Harald Welte9853e242021-04-10 19:08:25 +0200512 self._construct = Struct('ksi'/Int8ub, 'ck'/HexAdapter(Bytes(16)), 'ik'/HexAdapter(Bytes(16)))
Harald Welteb2edd142021-01-08 23:29:35 +0100513
Harald Welte14105dc2021-05-31 08:48:51 +0200514# TS 31.102 Section 4.2.6
515class EF_HPPLMN(TransparentEF):
516 def __init__(self, fid='6f31', sfid=0x12, name='EF.HPPLMN', size={1,1},
517 desc='Higher Priority PLMN search period'):
518 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
519 self._construct = Int8ub
520
521# TS 31.102 Section 4.2.8
Harald Welteb2edd142021-01-08 23:29:35 +0100522class EF_UST(TransparentEF):
Harald Welte790b2702021-04-11 00:01:35 +0200523 def __init__(self, fid='6f38', sfid=0x04, name='EF.UST', desc='USIM Service Table', size={1,17}):
524 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, size=size)
Harald Welteb2edd142021-01-08 23:29:35 +0100525 # add those commands to the general commands of a TransparentEF
526 self.shell_commands += [self.AddlShellCommands()]
527 def _decode_bin(self, in_bin):
528 ret = []
529 for i in range (0, len(in_bin)):
530 byte = in_bin[i]
531 for bitno in range(0,7):
532 if byte & (1 << bitno):
533 ret.append(i * 8 + bitno + 1)
534 return ret
535 def _encode_bin(self, in_json):
536 # FIXME: size this to length of file
537 ret = bytearray(20)
538 for srv in in_json:
539 print("srv=%d"%srv)
540 srv = srv-1
541 byte_nr = srv // 8
542 # FIXME: detect if service out of range was selected
543 bit_nr = srv % 8
544 ret[byte_nr] |= (1 << bit_nr)
545 return ret
546 @with_default_category('File-Specific Commands')
547 class AddlShellCommands(CommandSet):
548 def __init__(self):
549 super().__init__()
550
551 def do_ust_service_activate(self, arg):
552 """Activate a service within EF.UST"""
553 self._cmd.card.update_ust(int(arg), 1)
554
555 def do_ust_service_deactivate(self, arg):
556 """Deactivate a service within EF.UST"""
557 self._cmd.card.update_ust(int(arg), 0)
558
Harald Welte89e59542021-04-02 21:33:13 +0200559# TS 31.103 Section 4.2.7 - *not* the same as DF.GSM/EF.ECC!
560class EF_ECC(LinFixedEF):
561 def __init__(self, fid='6fb7', sfid=0x01, name='EF.ECC',
562 desc='Emergency Call Codes'):
563 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={4,20})
564
Harald Welte790b2702021-04-11 00:01:35 +0200565# TS 31.102 Section 4.2.17
566class EF_LOCI(TransparentEF):
Harald Weltec9cdce32021-04-11 10:28:28 +0200567 def __init__(self, fid='6f7e', sfid=0x0b, name='EF.LOCI', desc='Location information', size={11,11}):
Harald Welte790b2702021-04-11 00:01:35 +0200568 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
569 self._construct = Struct('tmsi'/HexAdapter(Bytes(4)), 'lai'/HexAdapter(Bytes(5)), 'rfu'/Int8ub,
570 'lu_status'/Int8ub)
Harald Welte592b32e2021-06-05 11:26:36 +0200571# TS 31.102 Section 4.2.18
572class EF_AD(TransparentEF):
573 class OP_MODE(enum.IntEnum):
574 normal = 0x00
575 type_approval = 0x80
576 normal_and_specific_facilities = 0x01
577 type_approval_and_specific_facilities = 0x81
578 maintenance_off_line = 0x02
579 cell_test = 0x04
580
581 def __init__(self, fid='6fad', sfid=0x03, name='EF.AD', desc='Administrative Data', size={4,6}):
582 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
583 self._construct = BitStruct(
584 # Byte 1
585 'ms_operation_mode'/Bytewise(Enum(Byte, EF_AD.OP_MODE)),
586 # Byte 2 + 3
587 'additional_info'/Bytewise(FlagsEnum(Int16ub, ciphering_indicator=1, csg_display_control=2,
588 prose_services=4, extended_drx=8)),
589 'rfu'/BitsRFU(4),
590 'mnc_len'/BitsInteger(4),
591 'extensions'/COptional(Bytewise(GreedyBytesRFU))
592 )
Harald Welte790b2702021-04-11 00:01:35 +0200593
594# TS 31.102 Section 4.2.23
595class EF_PSLOCI(TransparentEF):
Harald Weltec9cdce32021-04-11 10:28:28 +0200596 def __init__(self, fid='6f73', sfid=0x0c, name='EF.PSLOCI', desc='PS Location information', size={14,14}):
Harald Welte790b2702021-04-11 00:01:35 +0200597 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
598 self._construct = Struct('ptmsi'/HexAdapter(Bytes(4)), 'ptmsi_sig'/HexAdapter(Bytes(3)),
599 'rai'/HexAdapter(Bytes(6)), 'rau_status'/Int8ub)
600
601# TS 31.102 Section 4.2.33
602class EF_ICI(CyclicEF):
603 def __init__(self, fid='6f80', sfid=0x14, name='EF.ICI', rec_len={28,48},
604 desc='Incoming Call Information'):
605 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
606 self._construct = Struct('alpha_id'/Bytes(this._.total_len-28),
607 'len_of_bcd_contents'/Int8ub,
608 'ton_npi'/Int8ub,
609 'call_number'/BcdAdapter(Bytes(10)),
610 'cap_cfg2_record_id'/Int8ub,
611 'ext5_record_id'/Int8ub,
612 'date_and_time'/BcdAdapter(Bytes(7)),
613 'duration'/Int24ub,
614 'status'/Byte,
615 'link_to_phonebook'/Bytes(3))
616
617# TS 31.102 Section 4.2.34
618class EF_OCI(CyclicEF):
619 def __init__(self, fid='6f81', sfid=0x15, name='EF.OCI', rec_len={27,47},
620 desc='Outgoing Call Information'):
621 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
622 self._construct = Struct('alpha_id'/Bytes(this._.total_len-27),
623 'len_of_bcd_contents'/Int8ub,
624 'ton_npi'/Int8ub,
625 'call_number'/BcdAdapter(Bytes(10)),
626 'cap_cfg2_record_id'/Int8ub,
627 'ext5_record_id'/Int8ub,
628 'date_and_time'/BcdAdapter(Bytes(7)),
629 'duration'/Int24ub,
630 'link_to_phonebook'/Bytes(3))
631
632# TS 31.102 Section 4.2.35
633class EF_ICT(CyclicEF):
634 def __init__(self, fid='6f82', sfid=None, name='EF.ICT', rec_len={3,3},
635 desc='Incoming Call Timer'):
636 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
637 self._construct = Struct('accumulated_call_timer'/Int24ub)
638
639# TS 31.102 Section 4.2.38
640class EF_CCP2(LinFixedEF):
641 def __init__(self, fid='6f4f', sfid=0x16, name='EF.CCP2', desc='Capability Configuration Parameters 2'):
642 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={15,None})
643
644# TS 31.102 Section 4.2.48
645class EF_ACL(TransparentEF):
646 def __init__(self, fid='6f57', sfid=None, name='EF.ACL', size={32,None},
647 desc='Access Point Name Control List'):
648 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
649 self._construct = Struct('num_of_apns'/Int8ub, 'tlvs'/GreedyBytes)
650
651# TS 31.102 Section 4.2.51
652class EF_START_HFN(TransparentEF):
653 def __init__(self, fid='6f5b', sfid=0x0f, name='EF.START-HFN', size={6,6},
654 desc='Initialisation values for Hyperframe number'):
655 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
656 self._construct = Struct('start_cs'/Int24ub, 'start_ps'/Int24ub)
657
658# TS 31.102 Section 4.2.52
659class EF_THRESHOLD(TransparentEF):
660 def __init__(self, fid='6f5c', sfid=0x10, name='EF.THRESHOLD', size={3,3},
661 desc='Maximum value of START'):
662 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
663 self._construct = Struct('max_start'/Int24ub)
664
665# TS 31.102 Section 4.2.77
666class EF_VGCSCA(TransRecEF):
667 def __init__(self, fid='6fd4', sfid=None, name='EF.VGCSCA', size={2,100}, rec_len=2,
668 desc='Voice Group Call Service Ciphering Algorithm'):
669 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
670 self._construct = Struct('alg_v_ki_1'/Int8ub, 'alg_v_ki_2'/Int8ub)
671
672# TS 31.102 Section 4.2.79
673class EF_GBABP(TransparentEF):
674 def __init__(self, fid='6fd6', sfid=None, name='EF.GBABP', size={3,50},
675 desc='GBA Bootstrapping parameters'):
676 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
677 self._construct = Struct('rand'/LV, 'b_tid'/LV, 'key_lifetime'/LV)
678
679# TS 31.102 Section 4.2.80
680class EF_MSK(LinFixedEF):
681 def __init__(self, fid='6fd7', sfid=None, name='EF.MSK', desc='MBMS Service Key List'):
682 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={20,None})
683 msk_ts_constr = Struct('msk_id'/Int32ub, 'timestamp_counter'/Int32ub)
684 self._construct = Struct('key_domain_id'/Bytes(3),
685 'num_msk_id'/Int8ub,
686 'msk_ids'/msk_ts_constr[this.num_msk_id])
Harald Welte14105dc2021-05-31 08:48:51 +0200687# TS 31.102 Section 4.2.81
688class EF_MUK(LinFixedEF):
689 class MUK_Idr(BER_TLV_IE, tag=0x80):
690 _construct = HexAdapter(GreedyBytes)
691 class MUK_Idi(BER_TLV_IE, tag=0x82):
692 _construct = HexAdapter(GreedyBytes)
693 class MUK_ID(BER_TLV_IE, tag=0xA0, nested=[MUK_Idr, MUK_Idi]):
694 pass
695 class TimeStampCounter(BER_TLV_IE, tag=0x81):
696 pass
697 class EF_MUK_Collection(TLV_IE_Collection, nested=[MUK_ID, TimeStampCounter]):
698 pass
699 def __init__(self, fid='6fd8', sfid=None, name='EF.MUK', desc='MBMS User Key'):
700 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={None,None})
701 self._tlv = EF_MUK.EF_MUK_Collection
702
703# TS 31.102 Section 4.2.83
704class EF_GBANL(LinFixedEF):
705 class NAF_ID(BER_TLV_IE, tag=0x80):
706 _construct = HexAdapter(GreedyBytes)
707 class B_TID(BER_TLV_IE, tag=0x81):
708 _construct = HexAdapter(GreedyBytes)
709 class EF_GBANL_Collection(BER_TLV_IE, nested=[NAF_ID, B_TID]):
710 pass
711 def __init__(self, fid='6fda', sfid=None, name='EF.GBANL', desc='GBA NAF List'):
712 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={None,None})
713 self._tlv = EF_GBANL.EF_GBANL_Collection
Harald Welte790b2702021-04-11 00:01:35 +0200714
715# TS 31.102 Section 4.2.85
716class EF_EHPLMNPI(TransparentEF):
717 def __init__(self, fid='6fdb', sfid=None, name='EF.EHPLMNPI', size={1,1},
718 desc='Equivalent HPLMN Presentation Indication'):
719 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
720 self._construct = Struct('presentation_ind'/
721 Enum(Byte, no_preference=0, display_highest_prio_only=1, display_all=2))
Harald Welte14105dc2021-05-31 08:48:51 +0200722
723# TS 31.102 Section 4.2.87
724class EF_NAFKCA(LinFixedEF):
725 class NAF_KeyCentreAddress(BER_TLV_IE, tag=0x80):
726 _construct = HexAdapter(GreedyBytes)
727 def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', rec_len={None, None},
728 desc='NAF Key Centre Address'):
729 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
730 self._tlv = EF_NAFKCA.NAF_KeyCentreAddress
731
732# TS 31.102 Section 4.2.90
733class EF_NCP_IP(LinFixedEF):
734 class DataDestAddrRange(TLV_IE, tag=0x83):
735 _construct = Struct('type_of_address'/Enum(Byte, IPv4=0x21, IPv6=0x56),
736 'prefix_length'/Int8ub,
737 'prefix'/HexAdapter(GreedyBytes))
738 class AccessPointName(TLV_IE, tag=0x80):
739 # coded as per TS 23.003
740 _construct = HexAdapter(GreedyBytes)
741 class Login(TLV_IE, tag=0x81):
742 # as per SMS DCS TS 23.038
743 _construct = GsmStringAdapter(GreedyBytes)
744 class Password(TLV_IE, tag=0x82):
745 # as per SMS DCS TS 23.038
746 _construct = GsmStringAdapter(GreedyBytes)
747 class BearerDescription(TLV_IE, tag=0x84):
748 # Bearer descriptionTLV DO as per TS 31.111
749 pass
750 class EF_NCP_IP_Collection(TLV_IE_Collection,
751 nested=[AccessPointName, Login, Password, BearerDescription]):
752 pass
753 def __init__(self, fid='6fe2', sfid=None, name='EF.NCP-IP', rec_len={None, None},
754 desc='Network Connectivity Parameters for USIM IP connections'):
755 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
756 self._tlv = EF_NCP_IP.EF_NCP_IP_Collection
757
Harald Welte790b2702021-04-11 00:01:35 +0200758# TS 31.102 Section 4.2.91
759class EF_EPSLOCI(TransparentEF):
760 def __init__(self, fid='6fe3', sfid=0x1e, name='EF.EPSLOCI', size={18,18},
761 desc='EPS Location Information'):
762 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
763 upd_status_constr = Enum(Byte, updated=0, not_updated=1, roaming_not_allowed=2)
764 self._construct = Struct('guti'/Bytes(12), 'last_visited_registered_tai'/Bytes(5),
765 'eps_update_status'/upd_status_constr)
766
Harald Welte14105dc2021-05-31 08:48:51 +0200767# TS 31.102 Section 4.2.92
768class EF_EPSNSC(LinFixedEF):
769 class KSI_ASME(BER_TLV_IE, tag= 0x80):
770 _construct = Int8ub
771 class K_ASME(BER_TLV_IE, tag= 0x81):
772 _construct = HexAdapter(GreedyBytes)
773 class UplinkNASCount(BER_TLV_IE, tag=0x82):
774 _construct = Int32ub
775 class DownlinkNASCount(BER_TLV_IE, tag=0x83):
776 _construct = Int32ub
777 class IDofNASAlgorithms(BER_TLV_IE, tag=0x84):
778 _construct = HexAdapter(GreedyBytes)
779 class EPS_NAS_Security_Context(BER_TLV_IE, tag=0xa0,
780 nested=[KSI_ASME, K_ASME, UplinkNASCount, DownlinkNASCount,
781 IDofNASAlgorithms]):
782 pass
783 def __init__(self,fid='6fe4', sfid=0x18, name='EF.EPSNSC', rec_len={54,128},
784 desc='EPS NAS Security Context'):
785 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
786 self._tlv = EF_EPSNSC.EPS_NAS_Security_Context
787
Harald Welte790b2702021-04-11 00:01:35 +0200788# TS 31.102 Section 4.2.96
789class EF_PWS(TransparentEF):
790 def __init__(self, fid='6fec', sfid=None, name='EF.PWS', desc='Public Warning System', size={1,1}):
791 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
792 pws_config = FlagsEnum(Byte, ignore_pws_in_hplmn_and_equivalent=1, ignore_pws_in_vplmn=2)
793 self._construct = Struct('pws_configuration'/pws_config)
794
795# TS 31.102 Section 4.2.101
796class EF_IPS(CyclicEF):
797 def __init__(self, fid='6ff1', sfid=None, name='EF.IPS', rec_len={4,4},
798 desc='IMEI(SV) Pairing Status'):
799 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len)
800 self._construct = Struct('status'/PaddedString(2, 'ascii'),
801 'link_to_ef_ipd'/Int8ub, 'rfu'/Byte)
802
Harald Welte14105dc2021-05-31 08:48:51 +0200803# TS 31.102 Section 4.2.103
804class EF_ePDGId(TransparentEF):
805 class ePDGId(BER_TLV_IE, tag=0x80, nested=[]):
806 _construct = Struct('type_of_ePDG_address'/Enum(Byte, FQDN=0, IPv4=1, IPv6=2),
807 'ePDG_address'/Switch(this.type_of_address,
808 { 'FQDN': GreedyString("utf8"),
809 'IPv4': HexAdapter(GreedyBytes),
810 'IPv6': HexAdapter(GreedyBytes) }))
811 def __init__(self, fid='6ff3', sfid=None, name='EF.eDPDGId', desc='Home ePDG Identifier'):
812 super().__init__(fid, sfid=sfid, name=name, desc=desc)
813 self._tlv = EF_ePDGId.ePDGId
814
Harald Welte71290072021-04-21 10:58:24 +0200815# TS 31.102 Section 4.2.106
816class EF_FromPreferred(TransparentEF):
817 def __init__(self, fid='6ff7', sfid=None, name='EF.FromPreferred', size={1,1},
818 desc='From Preferred'):
819 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
820 self._construct = BitStruct('rfu'/BitsRFU(7), 'from_preferred'/Bit)
821
Harald Welte790b2702021-04-11 00:01:35 +0200822######################################################################
823# DF.5GS
824######################################################################
825
826# TS 31.102 Section 4.4.11.2
827class EF_5GS3GPPLOCI(TransparentEF):
828 def __init__(self, fid='4f01', sfid=0x01, name='EF.5GS3GPPLOCI', size={20,20},
829 desc='5S 3GP location information'):
830 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
831 upd_status_constr = Enum(Byte, updated=0, not_updated=1, roaming_not_allowed=2)
832 self._construct = Struct('5g_guti'/Bytes(13), 'last_visited_registered_tai_in_5gs'/Bytes(6),
833 '5gs_update_status'/upd_status_constr)
834
835# TS 31.102 Section 4.4.11.7
836class EF_UAC_AIC(TransparentEF):
837 def __init__(self, fid='4f06', sfid=0x06, name='EF.UAC_AIC', size={4,4},
838 desc='UAC Access Identities Configuration'):
839 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
840 cfg_constr = FlagsEnum(Byte, multimedia_priority_service=1,
841 mission_critical_service=2)
842 self._construct = Struct('uac_access_id_config'/cfg_constr)
843
Harald Welte14105dc2021-05-31 08:48:51 +0200844# TS 31.102 Section 4.4.11.9
Harald Welte790b2702021-04-11 00:01:35 +0200845class EF_OPL5G(LinFixedEF):
846 def __init__(self, fid='6f08', sfid=0x08, name='EF.OPL5G', desc='5GS Operator PLMN List'):
847 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len={10,None})
848 self._construct = Struct('tai'/Bytes(9), 'pnn_record_id'/Int8ub)
849
Harald Welte14105dc2021-05-31 08:48:51 +0200850# TS 31.102 Section 4.4.11.10
851class EF_SUPI_NAI(TransparentEF):
852 class NetworkSpecificIdentifier(TLV_IE, tag=0x80):
853 # RFC 7542 encoded as UTF-8 string
854 _construct = GreedyString("utf8")
855 class GlobalLineIdentifier(TLV_IE, tag=0x81):
856 # TS 23.003 clause 28.16.2
857 pass
858 class GlobalCableIdentifier(TLV_IE, tag=0x82):
859 # TS 23.003 clause 28.15.2
860 pass
861 class NAI_TLV_Collection(TLV_IE_Collection,
862 nested=[NetworkSpecificIdentifier, GlobalLineIdentifier, GlobalCableIdentifier]):
863 pass
864 def __init__(self, fid='4f09', sfid=0x09, name='EF.SUPI_NAI',
865 desc='SUPI as Network Access Identifier'):
866 super().__init__(fid, sfid=sfid, name=name, desc=desc)
867 self._tlv = EF_SUPI_NAI.NAI_TLV_Collection
868
869class EF_TN3GPPSNN(TransparentEF):
870 class ServingNetworkName(BER_TLV_IE, tag=0x80):
871 _construct = GreedyString("utf8")
872 def __init__(self, fid='4f0c', sfid=0x0c, name='EF.TN3GPPSNN',
873 desc='Trusted non-3GPP Serving network names list'):
874 super().__init__(fid, sfid=sfid, name=name, desc=desc)
875 self._tlv = EF_TN3GPPSNN.ServingNetworkName
876
Harald Welte3990ebb2021-04-20 23:55:14 +0200877# TS 31.102 Section 4.4.5
878class DF_WLAN(CardDF):
879 def __init__(self, fid='5f40', name='DF.WLAN', desc='Files for WLAN purpose'):
880 super().__init__(fid=fid, name=name, desc=desc)
881 files = [
882 TransparentEF('4f41', 0x01, 'EF.Pseudo', 'Pseudonym'),
883 TransparentEF('4f42', 0x02, 'EF.UPLMNWLAN', 'User controlled PLMN selector for I-WLAN Access'),
884 TransparentEF('4f43', 0x03, 'EF.OPLMNWLAN', 'Operator controlled PLMN selector for I-WLAN Access'),
885 LinFixedEF('4f44', 0x04, 'EF.UWSIDL', 'User controlled WLAN Specific Identifier List'),
886 LinFixedEF('4f45', 0x05, 'EF.OWSIDL', 'Operator controlled WLAN Specific Identifier List'),
887 TransparentEF('4f46', 0x06, 'EF.WRI', 'WLAN Reauthentication Identity'),
888 LinFixedEF('4f47', 0x07, 'EF.HWSIDL', 'Home I-WLAN Specific Identifier List'),
889 TransparentEF('4f48', 0x08, 'EF.WEHPLMNPI', 'I-WLAN Equivalent HPLMN Presentation Indication'),
890 TransparentEF('4f49', 0x09, 'EF.WHPI', 'I-WLAN HPLMN Priority Indication'),
891 TransparentEF('4f4a', 0x0a, 'EF.WLRPLMN', 'I-WLAN Last Registered PLMN'),
892 TransparentEF('4f4b', 0x0b, 'EF.HPLMNDAI', 'HPLMN Direct Access Indicator'),
893 ]
894 self.add_files(files)
895
896# TS 31.102 Section 4.4.6
897class DF_HNB(CardDF):
898 def __init__(self, fid='5f50', name='DF.HNB', desc='Files for HomeNodeB purpose'):
899 super().__init__(fid=fid, name=name, desc=desc)
900 files = [
901 LinFixedEF('4f01', 0x01, 'EF.ACSGL', 'Allowed CSG Lists'),
902 LinFixedEF('4f02', 0x02, 'EF.CSGTL', 'CSG Types'),
903 LinFixedEF('4f03', 0x03, 'EF.HNBN', 'Home NodeB Name'),
904 LinFixedEF('4f04', 0x04, 'EF.OCSGL', 'Operator CSG Lists'),
905 LinFixedEF('4f05', 0x05, 'EF.OCSGT', 'Operator CSG Type'),
906 LinFixedEF('4f06', 0x06, 'EF.OHNBN', 'Operator Home NodeB Name'),
907 ]
908 self.add_files(files)
909
910# TS 31.102 Section 4.4.8
911class DF_ProSe(CardDF):
912 def __init__(self, fid='5f90', name='DF.ProSe', desc='Files for ProSe purpose'):
913 super().__init__(fid=fid, name=name, desc=desc)
914 files = [
915 LinFixedEF('4f01', 0x01, 'EF.PROSE_MON', 'ProSe Monitoring Parameters'),
916 LinFixedEF('4f02', 0x02, 'EF.PROSE_ANN', 'ProSe Announcing Parameters'),
917 LinFixedEF('4f03', 0x03, 'EF.PROSEFUNC', 'HPLMN ProSe Function'),
918 TransparentEF('4f04', 0x04, 'EF.PROSE_RADIO_COM', 'ProSe Direct Communication Radio Parameters'),
919 TransparentEF('4f05', 0x05, 'EF.PROSE_RADIO_MON', 'ProSe Direct Discovery Monitoring Radio Parameters'),
920 TransparentEF('4f06', 0x06, 'EF.PROSE_RADIO_ANN', 'ProSe Direct Discovery Announcing Radio Parameters'),
921 LinFixedEF('4f07', 0x07, 'EF.PROSE_POLICY', 'ProSe Policy Parameters'),
922 LinFixedEF('4f08', 0x08, 'EF.PROSE_PLMN', 'ProSe PLMN Parameters'),
923 TransparentEF('4f09', 0x09, 'EF.PROSE_GC', 'ProSe Group Counter'),
924 TransparentEF('4f10', 0x10, 'EF.PST', 'ProSe Service Table'),
925 TransparentEF('4f11', 0x11, 'EF.UIRC', 'ProSe UsageInformationReportingConfiguration'),
926 LinFixedEF('4f12', 0x12, 'EF.PROSE_GM_DISCOVERY', 'ProSe Group Member Discovery Parameters'),
927 LinFixedEF('4f13', 0x13, 'EF.PROSE_RELAY', 'ProSe Relay Parameters'),
928 TransparentEF('4f14', 0x14, 'EF.PROSE_RELAY_DISCOVERY', 'ProSe Relay Discovery Parameters'),
929 ]
930 self.add_files(files)
931
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200932class DF_USIM_5GS(CardDF):
933 def __init__(self, fid='5FC0', name='DF.5GS', desc='5GS related files'):
934 super().__init__(fid=fid, name=name, desc=desc)
935 files = [
Harald Welte2f831032021-04-20 23:54:53 +0200936 # I'm looking at 31.102 R16.6
Harald Welte790b2702021-04-11 00:01:35 +0200937 EF_5GS3GPPLOCI(),
938 EF_5GS3GPPLOCI('4f02', 0x02, 'EF.5GSN3GPPLOCI', '5GS non-3GPP location information'),
Harald Weltef12979d2021-05-29 21:47:13 +0200939 EF_5GS3GPPNSC(),
940 EF_5GS3GPPNSC('4f04', 0x04, 'EF.5GSN3GPPNSC', '5GS non-3GPP Access NAS Security Context'),
941 EF_5GAUTHKEYS(),
Harald Welte790b2702021-04-11 00:01:35 +0200942 EF_UAC_AIC(),
943 EF_SUCI_Calc_Info(),
944 EF_OPL5G(),
Harald Welte14105dc2021-05-31 08:48:51 +0200945 EF_SUPI_NAI(),
Harald Welte790b2702021-04-11 00:01:35 +0200946 TransparentEF('4F0A', 0x0a, 'EF.Routing_Indicator', 'Routing Indicator', size={4,4}),
Harald Welte2f831032021-04-20 23:54:53 +0200947 TransparentEF('4F0B', 0x0b, 'EF.URSP', 'UE Route Selector Policies per PLMN'),
Harald Welte14105dc2021-05-31 08:48:51 +0200948 EF_TN3GPPSNN(),
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200949 ]
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200950 self.add_files(files)
951
Harald Welteb2edd142021-01-08 23:29:35 +0100952class ADF_USIM(CardADF):
953 def __init__(self, aid='a0000000871002', name='ADF.USIM', fid=None, sfid=None,
954 desc='USIM Application'):
955 super().__init__(aid=aid, fid=fid, sfid=sfid, name=name, desc=desc)
Harald Welte15fae982021-04-10 10:22:27 +0200956 # add those commands to the general commands of a TransparentEF
957 self.shell_commands += [self.AddlShellCommands()]
Harald Welteb2edd142021-01-08 23:29:35 +0100958
959 files = [
960 EF_LI(sfid=0x02),
961 EF_IMSI(sfid=0x07),
962 EF_Keys(),
963 EF_Keys('6f09', 0x09, 'EF.KeysPS', desc='Ciphering and Integrity Keys for PS domain'),
964 EF_xPLMNwAcT('6f60', 0x0a, 'EF.PLMNwAcT',
965 'User controlled PLMN Selector with Access Technology'),
Harald Welte14105dc2021-05-31 08:48:51 +0200966 EF_HPPLMN(),
Harald Welte790b2702021-04-11 00:01:35 +0200967 EF_ACMmax(),
Harald Welteb2edd142021-01-08 23:29:35 +0100968 EF_UST(),
969 CyclicEF('6f39', None, 'EF.ACM', 'Accumulated call meter', rec_len={3,3}),
970 TransparentEF('6f3e', None, 'EF.GID1', 'Group Identifier Level 1'),
971 TransparentEF('6f3f', None, 'EF.GID2', 'Group Identifier Level 2'),
972 EF_SPN(),
973 TransparentEF('6f41', None, 'EF.PUCT', 'Price per unit and currency table', size={5,5}),
974 EF_CBMI(),
975 EF_ACC(sfid=0x06),
976 EF_PLMNsel('6f7b', 0x0d, 'EF.FPLMN', 'Forbidden PLMNs', size={12,None}),
Harald Welte790b2702021-04-11 00:01:35 +0200977 EF_LOCI(),
Harald Welte592b32e2021-06-05 11:26:36 +0200978 EF_AD(),
Harald Welteb2edd142021-01-08 23:29:35 +0100979 EF_CBMID(sfid=0x0e),
Harald Welte89e59542021-04-02 21:33:13 +0200980 EF_ECC(),
Harald Welteb2edd142021-01-08 23:29:35 +0100981 EF_CBMIR(),
Harald Welte790b2702021-04-11 00:01:35 +0200982 EF_PSLOCI(),
983 EF_ADN('6f3b', None, 'EF.FDN', 'Fixed Dialling Numbers'),
984 EF_SMS('6f3c', None),
985 EF_MSISDN(),
986 EF_SMSP(),
987 EF_SMSS(),
988 EF_ADN('6f49', None, 'EF.SDN', 'Service Dialling Numbers'),
989 EF_EXT('6f4b', None, 'EF.EXT2', 'Extension2 (FDN)'),
990 EF_EXT('6f4c', None, 'EF.EXT3', 'Extension2 (SDN)'),
991 EF_SMSR(),
992 EF_ICI(),
993 EF_OCI(),
994 EF_ICT(),
995 EF_ICT('6f83', None, 'EF.OCT', 'Outgoing Call Timer'),
996 EF_EXT('6f4e', None, 'EF.EXT5', 'Extension5 (ICI/OCI/MSISDN)'),
997 EF_CCP2(),
998 EF_eMLPP(),
999 EF_AAeM(),
1000 # EF_Hiddenkey
1001 EF_ADN('6f4d', None, 'EF.BDN', 'Barred Dialling Numbers'),
1002 EF_EXT('6f55', None, 'EF.EXT4', 'Extension4 (BDN/SSC)'),
1003 EF_CMI(),
1004 EF_UST('6f56', 0x05, 'EF.EST', 'Enabled Services Table', size={1,None}),
1005 EF_ACL(),
1006 EF_DCK(),
1007 EF_CNL(),
1008 EF_START_HFN(),
1009 EF_THRESHOLD(),
1010 EF_xPLMNwAcT('6f61', 0x11, 'EF.OPLMNwAcT',
1011 'User controlled PLMN Selector with Access Technology'),
1012 EF_ARR('6f06', 0x17),
1013 TransparentEF('6fc4', None, 'EF.NETPAR', 'Network Parameters'),
1014 LinFixedEF('6fc5', 0x19, 'EF.PNN', 'PLMN Network Name'),
1015 EF_OPL(),
1016 EF_ADN('6fc7', None, 'EF.MBDN', 'Mailbox Dialling Numbers'),
1017 EF_MBI(),
1018 EF_MWIS(),
1019 EF_ADN('6fcb', None, 'EF.CFIS', 'Call Forwarding Indication Status'),
1020 EF_EXT('6fcc', None, 'EF.EXT7', 'Extension7 (CFIS)'),
1021 TransparentEF('6fcd', None, 'EF.SPDI', 'Service Provider Display Information'),
1022 EF_MMSN(),
1023 EF_EXT('6fcf', None, 'EF.EXT8', 'Extension8 (MMSN)'),
1024 EF_MMSICP(),
1025 EF_MMSUP(),
1026 EF_MMSUCP(),
1027 EF_NIA(),
1028 EF_VGCS(),
1029 EF_VGCSS(),
1030 EF_VGCS('6fb3', None, 'EF.VBS', 'Voice Broadcast Service'),
1031 EF_VGCSS('6fb4', None, 'EF.VBSS', 'Voice Broadcast Service Status'),
1032 EF_VGCSCA(),
1033 EF_VGCSCA('6fd5', None, 'EF.VBCSCA', 'Voice Broadcast Service Ciphering Algorithm'),
1034 EF_GBABP(),
1035 EF_MSK(),
Harald Welte14105dc2021-05-31 08:48:51 +02001036 EF_MUK(),
1037 EF_GBANL(),
Harald Welte790b2702021-04-11 00:01:35 +02001038 EF_PLMNsel('6fd9', 0x1d, 'EF.EHPLMN', 'Equivalent HPLMN', size={12,None}),
1039 EF_EHPLMNPI(),
Harald Welte14105dc2021-05-31 08:48:51 +02001040 EF_NAFKCA(),
Harald Welte790b2702021-04-11 00:01:35 +02001041 TransparentEF('6fde', None, 'EF.SPNI', 'Service Provider Name Icon'),
1042 LinFixedEF('6fdf', None, 'EF.PNNI', 'PLMN Network Name Icon'),
Harald Welte14105dc2021-05-31 08:48:51 +02001043 EF_NCP_IP(),
Harald Welte790b2702021-04-11 00:01:35 +02001044 EF_EPSLOCI('6fe3', 0x1e, 'EF.EPSLOCI', 'EPS location information'),
Harald Welte14105dc2021-05-31 08:48:51 +02001045 EF_EPSNSC(),
Harald Welte790b2702021-04-11 00:01:35 +02001046 TransparentEF('6fe6', None, 'EF.UFC', 'USAT Facility Control', size={1,16}),
1047 TransparentEF('6fe8', None, 'EF.NASCONFIG', 'Non Access Stratum Configuration'),
1048 # UICC IARI (only in cards that have no ISIM)
1049 EF_PWS(),
1050 LinFixedEF('6fed', None, 'EF.FDNURI', 'Fixed Dialling Numbers URI'),
1051 LinFixedEF('6fee', None, 'EF.BDNURI', 'Barred Dialling Numbers URI'),
1052 LinFixedEF('6fef', None, 'EF.SDNURI', 'Service Dialling Numbers URI'),
1053 EF_IPS(),
Harald Welte14105dc2021-05-31 08:48:51 +02001054 EF_ePDGId(),
1055 # FIXME: from EF_ePDGSelection onwards
Harald Welte71290072021-04-21 10:58:24 +02001056 EF_FromPreferred(),
Harald Welte790b2702021-04-11 00:01:35 +02001057 # FIXME: DF_SoLSA
1058 # FIXME: DF_PHONEBOOK
1059 # FIXME: DF_GSM_ACCESS
Harald Welte3990ebb2021-04-20 23:55:14 +02001060 DF_WLAN(),
1061 DF_HNB(),
1062 DF_ProSe(),
Harald Welte790b2702021-04-11 00:01:35 +02001063 # FIXME: DF_ACDC
1064 # FIXME: DF_TV
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001065 DF_USIM_5GS(),
Harald Welteb2edd142021-01-08 23:29:35 +01001066 ]
1067 self.add_files(files)
1068
1069 def decode_select_response(self, data_hex):
1070 return pySim.ts_102_221.decode_select_response(data_hex)
1071
Harald Welte15fae982021-04-10 10:22:27 +02001072 @with_default_category('Application-Specific Commands')
1073 class AddlShellCommands(CommandSet):
1074 def __init__(self):
1075 super().__init__()
1076
1077 authenticate_parser = argparse.ArgumentParser()
1078 authenticate_parser.add_argument('rand', help='Random challenge')
1079 authenticate_parser.add_argument('autn', help='Authentication Nonce')
1080 #authenticate_parser.add_argument('--context', help='Authentication context', default='3G')
1081 @cmd2.with_argparser(authenticate_parser)
1082 def do_authenticate(self, opts):
1083 """Perform Authentication and Key Agreement (AKA)."""
1084 (data, sw) = self._cmd.card._scc.authenticate(opts.rand, opts.autn)
1085 self._cmd.poutput_json(data)
1086
Harald Welte846a8982021-10-08 15:47:16 +02001087 def do_terminal_profile(self, arg):
1088 """Send a TERMINAL PROFILE command to the card."""
1089 (data, sw) = self._cmd.card._scc.terminal_profile(arg)
1090 self._cmd.poutput('SW: %s, data: %s' % (sw, data))
Harald Welte15fae982021-04-10 10:22:27 +02001091
1092
Harald Welteb2edd142021-01-08 23:29:35 +01001093# TS 31.102 Section 7.3
1094sw_usim = {
1095 'Security management': {
1096 '9862': 'Authentication error, incorrect MAC',
1097 '9864': 'Authentication error, security context not supported',
1098 '9865': 'Key freshness failure',
1099 '9866': 'Authentication error, no memory space available',
1100 '9867': 'Authentication error, no memory space available in EF MUK',
1101 }
1102}
1103
1104CardApplicationUSIM = CardApplication('USIM', adf=ADF_USIM(), sw=sw_usim)