blob: cd0d99c34af1b96807581f3417711eda7cedd5bb [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 Weltefc67de22023-05-23 20:29:49 +02008Various constants from 3GPP TS 31.102 V17.9.0
Supreeth Herle475dcaa2020-03-20 18:57:39 +01009"""
10
11#
12# Copyright (C) 2020 Supreeth Herle <herlesupreeth@gmail.com>
Harald Weltefc67de22023-05-23 20:29:49 +020013# Copyright (C) 2021-2023 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
Harald Weltec91085e2022-02-10 18:05:45 +010030import pySim.ts_102_221
31from pySim.ts_51_011 import EF_ACMmax, EF_AAeM, EF_eMLPP, EF_CMI, EF_PNN
32from pySim.ts_51_011 import EF_MMSN, EF_MMSICP, EF_MMSUP, EF_MMSUCP, EF_VGCS, EF_VGCSS, EF_NIA
33from pySim.ts_51_011 import EF_SMSR, EF_DCK, EF_EXT, EF_CNL, EF_OPL, EF_MBI, EF_MWIS
34from pySim.ts_51_011 import EF_CBMID, EF_CBMIR, EF_ADN, EF_SMS, EF_MSISDN, EF_SMSP, EF_SMSS
35from pySim.ts_51_011 import EF_IMSI, EF_xPLMNwAcT, EF_SPN, EF_CBMI, EF_ACC, EF_PLMNsel
Harald Welted90ceb82022-07-17 22:10:58 +020036from pySim.ts_51_011 import EF_Kc, EF_CPBCCH, EF_InvScan
Harald Weltec91085e2022-02-10 18:05:45 +010037from pySim.ts_102_221 import EF_ARR
38from pySim.tlv import *
39from pySim.filesystem import *
Harald Welte6f8a8702022-07-17 21:50:31 +020040from pySim.ts_31_102_telecom import DF_PHONEBOOK, EF_UServiceTable
Harald Weltec91085e2022-02-10 18:05:45 +010041from pySim.construct import *
Harald Weltef56b6b22022-07-30 16:36:06 +020042from pySim.cat import SMS_TPDU, DeviceIdentities, SMSPPDownload
Harald Weltec91085e2022-02-10 18:05:45 +010043from construct import Optional as COptional
44from construct import *
45from typing import Tuple
46from struct import unpack, pack
47import enum
Supreeth Herle475dcaa2020-03-20 18:57:39 +010048EF_UST_map = {
Harald Weltec91085e2022-02-10 18:05:45 +010049 1: 'Local Phone Book',
50 2: 'Fixed Dialling Numbers (FDN)',
51 3: 'Extension 2',
52 4: 'Service Dialling Numbers (SDN)',
53 5: 'Extension3',
54 6: 'Barred Dialling Numbers (BDN)',
55 7: 'Extension4',
56 8: 'Outgoing Call Information (OCI and OCT)',
57 9: 'Incoming Call Information (ICI and ICT)',
58 10: 'Short Message Storage (SMS)',
59 11: 'Short Message Status Reports (SMSR)',
60 12: 'Short Message Service Parameters (SMSP)',
61 13: 'Advice of Charge (AoC)',
62 14: 'Capability Configuration Parameters 2 (CCP2)',
63 15: 'Cell Broadcast Message Identifier',
64 16: 'Cell Broadcast Message Identifier Ranges',
65 17: 'Group Identifier Level 1',
66 18: 'Group Identifier Level 2',
67 19: 'Service Provider Name',
68 20: 'User controlled PLMN selector with Access Technology',
69 21: 'MSISDN',
70 22: 'Image (IMG)',
71 23: 'Support of Localised Service Areas (SoLSA)',
72 24: 'Enhanced Multi-Level Precedence and Pre-emption Service',
73 25: 'Automatic Answer for eMLPP',
74 26: 'RFU',
75 27: 'GSM Access',
76 28: 'Data download via SMS-PP',
77 29: 'Data download via SMS-CB',
78 30: 'Call Control by USIM',
79 31: 'MO-SMS Control by USIM',
80 32: 'RUN AT COMMAND command',
81 33: 'shall be set to 1',
82 34: 'Enabled Services Table',
83 35: 'APN Control List (ACL)',
84 36: 'Depersonalisation Control Keys',
85 37: 'Co-operative Network List',
86 38: 'GSM security context',
87 39: 'CPBCCH Information',
88 40: 'Investigation Scan',
89 41: 'MexE',
90 42: 'Operator controlled PLMN selector with Access Technology',
91 43: 'HPLMN selector with Access Technology',
92 44: 'Extension 5',
93 45: 'PLMN Network Name',
94 46: 'Operator PLMN List',
95 47: 'Mailbox Dialling Numbers',
96 48: 'Message Waiting Indication Status',
97 49: 'Call Forwarding Indication Status',
98 50: 'Reserved and shall be ignored',
99 51: 'Service Provider Display Information',
100 52: 'Multimedia Messaging Service (MMS)',
101 53: 'Extension 8',
102 54: 'Call control on GPRS by USIM',
103 55: 'MMS User Connectivity Parameters',
104 56: 'Network\'s indication of alerting in the MS (NIA)',
105 57: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)',
106 58: 'VBS Group Identifier List (EFVBS and EFVBSS)',
107 59: 'Pseudonym',
108 60: 'User Controlled PLMN selector for I-WLAN access',
109 61: 'Operator Controlled PLMN selector for I-WLAN access',
110 62: 'User controlled WSID list',
111 63: 'Operator controlled WSID list',
112 64: 'VGCS security',
113 65: 'VBS security',
114 66: 'WLAN Reauthentication Identity',
115 67: 'Multimedia Messages Storage',
116 68: 'Generic Bootstrapping Architecture (GBA)',
117 69: 'MBMS security',
118 70: 'Data download via USSD and USSD application mode',
119 71: 'Equivalent HPLMN',
120 72: 'Additional TERMINAL PROFILE after UICC activation',
121 73: 'Equivalent HPLMN Presentation Indication',
122 74: 'Last RPLMN Selection Indication',
123 75: 'OMA BCAST Smart Card Profile',
124 76: 'GBA-based Local Key Establishment Mechanism',
125 77: 'Terminal Applications',
126 78: 'Service Provider Name Icon',
127 79: 'PLMN Network Name Icon',
128 80: 'Connectivity Parameters for USIM IP connections',
129 81: 'Home I-WLAN Specific Identifier List',
130 82: 'I-WLAN Equivalent HPLMN Presentation Indication',
131 83: 'I-WLAN HPLMN Priority Indication',
132 84: 'I-WLAN Last Registered PLMN',
133 85: 'EPS Mobility Management Information',
134 86: 'Allowed CSG Lists and corresponding indications',
135 87: 'Call control on EPS PDN connection by USIM',
136 88: 'HPLMN Direct Access',
137 89: 'eCall Data',
138 90: 'Operator CSG Lists and corresponding indications',
139 91: 'Support for SM-over-IP',
140 92: 'Support of CSG Display Control',
141 93: 'Communication Control for IMS by USIM',
142 94: 'Extended Terminal Applications',
143 95: 'Support of UICC access to IMS',
144 96: 'Non-Access Stratum configuration by USIM',
145 97: 'PWS configuration by USIM',
146 98: 'RFU',
147 99: 'URI support by UICC',
148 100: 'Extended EARFCN support',
149 101: 'ProSe',
150 102: 'USAT Application Pairing',
151 103: 'Media Type support',
152 104: 'IMS call disconnection cause',
153 105: 'URI support for MO SHORT MESSAGE CONTROL',
154 106: 'ePDG configuration Information support',
155 107: 'ePDG configuration Information configured',
156 108: 'ACDC support',
157 109: 'MCPTT',
158 110: 'ePDG configuration Information for Emergency Service support',
159 111: 'ePDG configuration Information for Emergency Service configured',
160 112: 'eCall Data over IMS',
161 113: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [12]',
162 114: 'From Preferred',
163 115: 'IMS configuration data',
164 116: 'TV configuration',
165 117: '3GPP PS Data Off',
166 118: '3GPP PS Data Off Service List',
167 119: 'V2X',
168 120: 'XCAP Configuration Data',
169 121: 'EARFCN list for MTC/NB-IOT UEs',
170 122: '5GS Mobility Management Information',
171 123: '5G Security Parameters',
172 124: 'Subscription identifier privacy support',
173 125: 'SUCI calculation by the USIM',
174 126: 'UAC Access Identities support',
175 127: 'Expect control plane-based Steering of Roaming information during initial registration in VPLMN',
176 128: 'Call control on PDU Session by USIM',
177 129: '5GS Operator PLMN List',
178 130: 'Support for SUPI of type NSI or GLI or GCI',
179 131: '3GPP PS Data Off separate Home and Roaming lists',
180 132: 'Support for URSP by USIM',
181 133: '5G Security Parameters extended',
182 134: 'MuD and MiD configuration data',
Harald Weltefc67de22023-05-23 20:29:49 +0200183 135: 'Support for Trusted non-3GPP access networks by USIM',
184 136: 'Support for multiple records of NAS security context storage for multiple registration',
185 137: 'Pre-configured CAG information list',
186 138: 'SOR-CMCI storage in USIM',
187 139: '5G ProSe',
188 140: 'Storage of disaster roaming information in USIM',
189 141: 'Pre-configured eDRX parameters',
190 142: '5G NSWO support',
191 143: 'PWS configuration for SNPN in USIM',
192 144: 'Multiplier Coefficient for Higher Priority PLMN search via NG-RAN satellite access',
193 145: 'K_AUSF derivation configuration',
194 146: 'Network Identifier for SNPN (NID)',
195}
196
197EF_5G_PROSE_ST_map = {
198 1: '5G ProSe configuration data for direct discovery',
199 2: '5G ProSe configuration data for direct communication',
200 3: '5G ProSe configuration data for UE-to-network relay UE',
201 4: '5G ProSe configuration data for remote UE',
202 5: '5G ProSe configuration data for usage information reporting',
Sebastian Viviani0dc8f692020-05-29 00:14:55 +0100203}
204
Harald Weltee8947492022-02-10 10:33:20 +0100205# Mapping between USIM Enbled Service Number and its description
206EF_EST_map = {
207 1: 'Fixed Dialling Numbers (FDN)',
208 2: 'Barred Dialling Numbers (BDN)',
209 3: 'APN Control List (ACL)'
210}
211
Harald Welte21caf322022-07-16 14:06:46 +0200212# 3gPP TS 31.102 Section 7.5.2.1
213class SUCI_TlvDataObject(BER_TLV_IE, tag=0xA1):
214 _construct = HexAdapter(GreedyBytes)
215
Harald Welteb2edd142021-01-08 23:29:35 +0100216######################################################################
217# ADF.USIM
218######################################################################
219
Harald Welteb2edd142021-01-08 23:29:35 +0100220
Harald Weltef12979d2021-05-29 21:47:13 +0200221# 3GPP TS 31.102 Section 4.4.11.4 (EF_5GS3GPPNSC)
222class EF_5GS3GPPNSC(LinFixedEF):
223 class NgKSI(BER_TLV_IE, tag=0x80):
224 _construct = Int8ub
225
226 class K_AMF(BER_TLV_IE, tag=0x81):
227 _construct = HexAdapter(Bytes(32))
228
229 class UplinkNASCount(BER_TLV_IE, tag=0x82):
230 _construct = Int32ub
231
232 class DownlinkNASCount(BER_TLV_IE, tag=0x83):
233 _construct = Int32ub
234
235 class IdsOfSelectedNasAlgos(BER_TLV_IE, tag=0x84):
236 # 3GPP TS 24.501 Section 9.11.3.34
237 _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
238
239 class IdsOfSelectedEpsAlgos(BER_TLV_IE, tag=0x85):
240 # 3GPP TS 24.301 Section 9.9.3.23
241 _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
242
243 class FiveGSNasSecurityContext(BER_TLV_IE, tag=0xA0,
Harald Weltec91085e2022-02-10 18:05:45 +0100244 nested=[NgKSI, K_AMF, UplinkNASCount,
245 DownlinkNASCount, IdsOfSelectedNasAlgos,
246 IdsOfSelectedEpsAlgos]):
Harald Weltef12979d2021-05-29 21:47:13 +0200247 pass
248
Harald Welte99e4cc02022-07-21 15:25:47 +0200249 def __init__(self, fid="4f03", sfid=0x03, name='EF.5GS3GPPNSC', rec_len=(57, None),
Harald Welte419bb492022-02-12 21:39:35 +0100250 desc='5GS 3GPP Access NAS Security Context', **kwargs):
251 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte65516272022-02-10 17:51:05 +0100252 self._tlv = EF_5GS3GPPNSC.FiveGSNasSecurityContext
Harald Weltef12979d2021-05-29 21:47:13 +0200253
254# 3GPP TS 31.102 Section 4.4.11.6
255class EF_5GAUTHKEYS(TransparentEF):
256 class K_AUSF(BER_TLV_IE, tag=0x80):
257 _construct = HexAdapter(GreedyBytes)
258
259 class K_SEAF(BER_TLV_IE, tag=0x81):
260 _construct = HexAdapter(GreedyBytes)
261
262 class FiveGAuthKeys(TLV_IE_Collection, nested=[K_AUSF, K_SEAF]):
263 pass
264
Harald Welte13edf302022-07-21 15:19:23 +0200265 def __init__(self, fid='4f05', sfid=0x05, name='EF.5GAUTHKEYS', size=(68, None),
Harald Welte419bb492022-02-12 21:39:35 +0100266 desc='5G authentication keys', **kwargs):
267 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte65516272022-02-10 17:51:05 +0100268 self._tlv = EF_5GAUTHKEYS.FiveGAuthKeys
Harald Weltef12979d2021-05-29 21:47:13 +0200269
270# 3GPP TS 31.102 Section 4.4.11.8
271class ProtSchemeIdList(BER_TLV_IE, tag=0xa0):
272 # FIXME: 3GPP TS 24.501 Protection Scheme Identifier
273 # repeated sequence of (id, index) tuples
Harald Weltec91085e2022-02-10 18:05:45 +0100274 _construct = GreedyRange(
275 Struct('id'/Enum(Byte, null=0, A=1, B=2), 'index'/Int8ub))
276
Harald Weltef12979d2021-05-29 21:47:13 +0200277
278class HomeNetPubKeyId(BER_TLV_IE, tag=0x80):
279 # 3GPP TS 24.501 / 3GPP TS 23.003
280 _construct = Int8ub
281
Harald Weltec91085e2022-02-10 18:05:45 +0100282
Harald Weltef12979d2021-05-29 21:47:13 +0200283class HomeNetPubKey(BER_TLV_IE, tag=0x81):
284 # FIXME: RFC 5480
285 _construct = HexAdapter(GreedyBytes)
286
Harald Weltec91085e2022-02-10 18:05:45 +0100287
Harald Weltef12979d2021-05-29 21:47:13 +0200288class HomeNetPubKeyList(BER_TLV_IE, tag=0xa1,
Harald Weltec91085e2022-02-10 18:05:45 +0100289 nested=[HomeNetPubKeyId, HomeNetPubKey]):
Harald Weltef12979d2021-05-29 21:47:13 +0200290 pass
291
292# 3GPP TS 31.102 Section 4.4.11.6
Harald Weltec91085e2022-02-10 18:05:45 +0100293class SUCI_CalcInfo(TLV_IE_Collection, nested=[ProtSchemeIdList, HomeNetPubKeyList]):
Harald Weltef12979d2021-05-29 21:47:13 +0200294 pass
295
296
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200297# TS 31.102 4.4.11.8
298class EF_SUCI_Calc_Info(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200299 def __init__(self, fid="4f07", sfid=0x07, name='EF.SUCI_Calc_Info', size=(2, None),
Harald Welte419bb492022-02-12 21:39:35 +0100300 desc='SUCI Calc Info', **kwargs):
301 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200302
303 def _encode_prot_scheme_id_list(self, in_list):
304 out_bytes = [0xa0]
Harald Weltec91085e2022-02-10 18:05:45 +0100305 out_bytes.append(len(in_list)*2) # two byte per entry
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200306
307 # position in list determines priority; high-priority items (low index) come first
308 for scheme in sorted(in_list, key=lambda item: item["priority"]):
309 out_bytes.append(scheme["identifier"])
310 out_bytes.append(scheme["key_index"])
311
312 return out_bytes
313
314 def _encode_hnet_pubkey_list(self, hnet_pubkey_list):
Harald Weltec91085e2022-02-10 18:05:45 +0100315 out_bytes = [0xa1] # pubkey list tag
316 out_bytes.append(0x00) # length filled later
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200317 length = 0
318
319 for key in hnet_pubkey_list:
Harald Weltec91085e2022-02-10 18:05:45 +0100320 out_bytes.append(0x80) # identifier tag
321 out_bytes.append(0x01) # TODO size, fixed to 1 byte
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200322 out_bytes.append(key["hnet_pubkey_identifier"])
Harald Weltec91085e2022-02-10 18:05:45 +0100323 out_bytes.append(0x81) # key tag
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200324 out_bytes.append(len(key["hnet_pubkey"])//2)
325 length += 5+len(key["hnet_pubkey"])//2
326
327 pubkey_bytes = h2b(key["hnet_pubkey"])
328 out_bytes += pubkey_bytes
329
330 # fill length
331 out_bytes[1] = length
332 return out_bytes
333
334 def _encode_hex(self, in_json):
Harald Weltec91085e2022-02-10 18:05:45 +0100335 out_bytes = self._encode_prot_scheme_id_list(
336 in_json['prot_scheme_id_list'])
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200337 out_bytes += self._encode_hnet_pubkey_list(in_json['hnet_pubkey_list'])
338 return "".join(["%02X" % i for i in out_bytes])
339
340 def _decode_prot_scheme_id_list(self, in_bytes):
341 prot_scheme_id_list = []
342 pos = 0
343 # two bytes per entry
344 while pos < len(in_bytes):
345 prot_scheme = {
Harald Weltec91085e2022-02-10 18:05:45 +0100346 'priority': pos//2, # first in list: high priority
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200347 'identifier': in_bytes[pos],
348 'key_index': in_bytes[pos+1]
349 }
350 pos += 2
351 prot_scheme_id_list.append(prot_scheme)
352 return prot_scheme_id_list
353
354 def _decode_hnet_pubkey_list(self, in_bytes):
355 hnet_pubkey_list = []
356 pos = 0
357 if in_bytes[pos] != 0xa1:
358 print("missing Home Network Public Key List data object")
359 return {}
360 pos += 1
361 hnet_pubkey_list_len = in_bytes[pos]
362 pos += 1
363
364 while pos < hnet_pubkey_list_len:
365 if in_bytes[pos] != 0x80:
366 print("missing Home Network Public Key Identifier tag")
367 return {}
368 pos += 1
Harald Weltec91085e2022-02-10 18:05:45 +0100369 # TODO might be more than 1 byte?
370 hnet_pubkey_id_len = in_bytes[pos]
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200371 pos += 1
372 hnet_pubkey_id = in_bytes[pos:pos+hnet_pubkey_id_len][0]
373 pos += hnet_pubkey_id_len
374 if in_bytes[pos] != 0x81:
375 print("missing Home Network Public Key tag")
376 return {}
377 pos += 1
378 hnet_pubkey_len = in_bytes[pos]
379 pos += 1
380 hnet_pubkey = in_bytes[pos:pos+hnet_pubkey_len]
381 pos += hnet_pubkey_len
382
383 hnet_pubkey_list.append({
384 'hnet_pubkey_identifier': hnet_pubkey_id,
385 'hnet_pubkey': b2h(hnet_pubkey)
386 })
387
388 return hnet_pubkey_list
389
390 def _decode_bin(self, in_bin):
Vadim Yanitskiy5e41eeb2021-05-02 02:20:33 +0200391 return self._decode_hex(b2h(in_bin))
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200392
393 def _decode_hex(self, in_hex):
394 in_bytes = h2b(in_hex)
395 pos = 0
396
397 if in_bytes[pos] != 0xa0:
398 print("missing Protection Scheme Identifier List data object tag")
399 return {}
400 pos += 1
401
Harald Weltec91085e2022-02-10 18:05:45 +0100402 prot_scheme_id_list_len = in_bytes[pos] # TODO maybe more than 1 byte
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200403 pos += 1
404 # decode Protection Scheme Identifier List data object
Harald Weltec91085e2022-02-10 18:05:45 +0100405 prot_scheme_id_list = self._decode_prot_scheme_id_list(
406 in_bytes[pos:pos+prot_scheme_id_list_len])
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200407 pos += prot_scheme_id_list_len
408
409 # remaining data holds Home Network Public Key Data Object
410 hnet_pubkey_list = self._decode_hnet_pubkey_list(in_bytes[pos:])
411
412 return {
413 'prot_scheme_id_list': prot_scheme_id_list,
414 'hnet_pubkey_list': hnet_pubkey_list
415 }
416
417 def _encode_bin(self, in_json):
418 return h2b(self._encode_hex(in_json))
419
Harald Weltec91085e2022-02-10 18:05:45 +0100420
Harald Welteb2edd142021-01-08 23:29:35 +0100421class EF_LI(TransRecEF):
Harald Welte13edf302022-07-21 15:19:23 +0200422 def __init__(self, fid='6f05', sfid=None, name='EF.LI', size=(2, None), rec_len=2,
Harald Welteb2edd142021-01-08 23:29:35 +0100423 desc='Language Indication'):
424 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
Harald Weltec91085e2022-02-10 18:05:45 +0100425
Harald Weltef6b37af2023-01-24 15:42:26 +0100426 def _decode_record_bin(self, in_bin, **kwargs):
Harald Welteb2edd142021-01-08 23:29:35 +0100427 if in_bin == b'\xff\xff':
428 return None
429 else:
430 # officially this is 7-bit GSM alphabet with one padding bit in each byte
431 return in_bin.decode('ascii')
Harald Weltec91085e2022-02-10 18:05:45 +0100432
Harald Weltef6b37af2023-01-24 15:42:26 +0100433 def _encode_record_bin(self, in_json, **kwargs):
Harald Welteb2edd142021-01-08 23:29:35 +0100434 if in_json == None:
435 return b'\xff\xff'
436 else:
437 # officially this is 7-bit GSM alphabet with one padding bit in each byte
438 return in_json.encode('ascii')
439
Harald Weltec91085e2022-02-10 18:05:45 +0100440
Harald Welteb2edd142021-01-08 23:29:35 +0100441class EF_Keys(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200442 def __init__(self, fid='6f08', sfid=0x08, name='EF.Keys', size=(33, 33),
Harald Welteb2edd142021-01-08 23:29:35 +0100443 desc='Ciphering and Integrity Keys'):
444 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
Harald Weltec91085e2022-02-10 18:05:45 +0100445 self._construct = Struct(
446 'ksi'/Int8ub, 'ck'/HexAdapter(Bytes(16)), 'ik'/HexAdapter(Bytes(16)))
Harald Welteb2edd142021-01-08 23:29:35 +0100447
Harald Welte14105dc2021-05-31 08:48:51 +0200448# TS 31.102 Section 4.2.6
449class EF_HPPLMN(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100450 _test_de_encode = [ ( '05', 5 ) ]
Harald Welte13edf302022-07-21 15:19:23 +0200451 def __init__(self, fid='6f31', sfid=0x12, name='EF.HPPLMN', size=(1, 1),
Harald Welte14105dc2021-05-31 08:48:51 +0200452 desc='Higher Priority PLMN search period'):
453 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
454 self._construct = Int8ub
455
Harald Welte6ca2fa72022-02-12 16:29:31 +0100456class EF_UST(EF_UServiceTable):
457 def __init__(self, **kwargs):
Harald Welte13edf302022-07-21 15:19:23 +0200458 super().__init__(fid='6f38', sfid=0x04, name='EF.UST', desc='USIM Service Table', size=(1,17), table=EF_UST_map, **kwargs)
Harald Welte6ca2fa72022-02-12 16:29:31 +0100459 # add those commands to the general commands of a TransparentEF
460 self.shell_commands += [self.AddlShellCommands()]
461
Harald Welteb2edd142021-01-08 23:29:35 +0100462 @with_default_category('File-Specific Commands')
463 class AddlShellCommands(CommandSet):
464 def __init__(self):
465 super().__init__()
466
467 def do_ust_service_activate(self, arg):
468 """Activate a service within EF.UST"""
Alexander Couzens6c5c3f82023-07-28 05:13:06 +0200469 selected_file = self._cmd.lchan.selected_file
470 selected_file.ust_update(self._cmd, [int(arg)], [])
Harald Welteb2edd142021-01-08 23:29:35 +0100471
472 def do_ust_service_deactivate(self, arg):
473 """Deactivate a service within EF.UST"""
Alexander Couzens6c5c3f82023-07-28 05:13:06 +0200474 selected_file = self._cmd.lchan.selected_file
475 selected_file.ust_update(self._cmd, [], [int(arg)])
Harald Welteb2edd142021-01-08 23:29:35 +0100476
Harald Welte4c5e2312022-02-12 14:37:48 +0100477 def do_ust_service_check(self, arg):
Harald Welte3bb516b2022-02-12 21:53:18 +0100478 """Check consistency between services of this file and files present/activated.
479
480 Many services determine if one or multiple files shall be present/activated or if they shall be
481 absent/deactivated. This performs a consistency check to ensure that no services are activated
482 for files that are not - and vice-versa, no files are activated for services that are not. Error
483 messages are printed for every inconsistency found."""
Harald Weltea6c0f882022-07-17 14:23:17 +0200484 selected_file = self._cmd.lchan.selected_file
Harald Welte82f75c22022-02-12 18:22:28 +0100485 num_problems = selected_file.ust_service_check(self._cmd)
486 # obtain list of currently active services
487 active_services = selected_file.get_active_services(self._cmd)
488 # Service n°46 can only be declared "available" if service n°45 is declared "available"
489 if 46 in active_services and not 45 in active_services:
Harald Weltefa8b8d12022-02-12 18:30:28 +0100490 self._cmd.perror("ERROR: Service 46 available, but it requires Service 45")
Harald Welte82f75c22022-02-12 18:22:28 +0100491 num_problems += 1
492 # Service n°125 shall only be taken into account if Service n°124 is declared "available"
493 if 125 in active_services and not 124 in active_services:
Harald Weltefa8b8d12022-02-12 18:30:28 +0100494 self._cmd.perror("ERROR: Service 125 is ignored as Service 124 not available")
Harald Welte82f75c22022-02-12 18:22:28 +0100495 num_problems += 1
496 # Service n°95, n°99 and n°115 shall not be declared "available" if an ISIM application is present on the UICC
497 non_isim_services = [95, 99, 115]
498 app_names = selected_file.get_mf().get_app_names()
499 if 'ADF.ISIM' in app_names:
500 for s in non_isim_services:
501 if s in active_services:
Harald Weltefa8b8d12022-02-12 18:30:28 +0100502 self._cmd.perror("ERROR: Service %u shall not be available as ISIM application is present" % s)
Harald Welte82f75c22022-02-12 18:22:28 +0100503 num_problems += 1
504 self._cmd.poutput("===> %u service / file inconsistencies detected" % num_problems)
Harald Welte4c5e2312022-02-12 14:37:48 +0100505
506
Harald Welte89e59542021-04-02 21:33:13 +0200507# TS 31.103 Section 4.2.7 - *not* the same as DF.GSM/EF.ECC!
508class EF_ECC(LinFixedEF):
Harald Welte865eea62023-01-27 19:26:12 +0100509 _test_de_encode = [
510 ( '19f1ff01', { "call_code": "911f",
511 "service_category": { "police": True, "ambulance": False, "fire_brigade": False,
512 "marine_guard": False, "mountain_rescue": False,
513 "manual_ecall": False, "automatic_ecall": False } } ),
514 ( '19f3ff02', { "call_code": "913f",
515 "service_category": { "police": False, "ambulance": True, "fire_brigade": False,
516 "marine_guard": False, "mountain_rescue": False,
517 "manual_ecall": False, "automatic_ecall": False } } ),
518 ]
519 cc_construct = BcdAdapter(Rpad(Bytes(3)))
Harald Welteff2d86d2022-01-21 15:19:47 +0100520 category_construct = FlagsEnum(Byte, police=1, ambulance=2, fire_brigade=3, marine_guard=4,
521 mountain_rescue=5, manual_ecall=6, automatic_ecall=7)
522 alpha_construct = GsmStringAdapter(Rpad(GreedyBytes))
Harald Weltec91085e2022-02-10 18:05:45 +0100523
Harald Welte89e59542021-04-02 21:33:13 +0200524 def __init__(self, fid='6fb7', sfid=0x01, name='EF.ECC',
525 desc='Emergency Call Codes'):
Harald Welte99e4cc02022-07-21 15:25:47 +0200526 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(4, 20))
Harald Weltec91085e2022-02-10 18:05:45 +0100527
Harald Weltef6b37af2023-01-24 15:42:26 +0100528 def _decode_record_bin(self, in_bin, **kwargs):
Harald Welteff2d86d2022-01-21 15:19:47 +0100529 # mandatory parts
530 code = in_bin[:3]
531 if code == b'\xff\xff\xff':
532 return None
533 svc_category = in_bin[-1:]
534 ret = {'call_code': parse_construct(EF_ECC.cc_construct, code),
Harald Weltec91085e2022-02-10 18:05:45 +0100535 'service_category': parse_construct(EF_ECC.category_construct, svc_category)}
Harald Welteff2d86d2022-01-21 15:19:47 +0100536 # optional alpha identifier
537 if len(in_bin) > 4:
538 alpha_id = in_bin[3:-1]
539 ret['alpha_id'] = parse_construct(EF_ECC.alpha_construct, alpha_id)
540 return ret
Harald Weltec91085e2022-02-10 18:05:45 +0100541
Harald Weltef6b37af2023-01-24 15:42:26 +0100542 def _encode_record_bin(self, in_json, **kwargs):
Harald Welteff2d86d2022-01-21 15:19:47 +0100543 if in_json is None:
544 return b'\xff\xff\xff\xff'
545 code = EF_ECC.cc_construct.build(in_json['call_code'])
Harald Welte9b9efb62023-01-31 16:40:54 +0100546 svc_category = EF_ECC.category_construct.build(in_json['service_category'])
547 if 'alpha_id' in in_json:
548 alpha_id = EF_ECC.alpha_construct.build(in_json['alpha_id'])
549 # FIXME: alpha_id needs padding up to 'record_length - 4'
550 else:
551 alpha_id = b''
Harald Welteff2d86d2022-01-21 15:19:47 +0100552 return code + alpha_id + svc_category
553
Harald Welte89e59542021-04-02 21:33:13 +0200554
Harald Welte790b2702021-04-11 00:01:35 +0200555# TS 31.102 Section 4.2.17
556class EF_LOCI(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100557 _test_de_encode = [
558 ( '47d1264a62f21037211e00',
559 { "tmsi": "47d1264a", "lai": { "mcc_mnc": "262f01", "lac": "3721" },
560 "rfu": 30, "lu_status": 0 } ),
561 ]
Harald Welte13edf302022-07-21 15:19:23 +0200562 def __init__(self, fid='6f7e', sfid=0x0b, name='EF.LOCI', desc='Location information', size=(11, 11)):
Harald Welte790b2702021-04-11 00:01:35 +0200563 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
Harald Welte3a5afff2022-02-25 15:33:46 +0100564 Lai = Struct('mcc_mnc'/BcdAdapter(Bytes(3)), 'lac'/HexAdapter(Bytes(2)))
565 self._construct = Struct('tmsi'/HexAdapter(Bytes(4)), 'lai'/Lai, 'rfu'/Int8ub, 'lu_status'/Int8ub)
Harald Welte865eea62023-01-27 19:26:12 +0100566
Harald Welte592b32e2021-06-05 11:26:36 +0200567# TS 31.102 Section 4.2.18
568class EF_AD(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100569 _test_de_encode = [
570 ( '00000002', { "ms_operation_mode": "normal",
571 "additional_info": { "ciphering_indicator": False, "csg_display_control": False,
572 "prose_services": False, "extended_drx": False },
573 "rfu": 0, "mnc_len": 2, "extensions": b'' } ),
574 ( '01000102', { "ms_operation_mode": "normal_and_specific_facilities",
575 "additional_info": { "ciphering_indicator": True, "csg_display_control": False,
576 "prose_services": False, "extended_drx": False },
577 "rfu": 0, "mnc_len": 2, "extensions": b'' } ),
578 ]
Harald Welte592b32e2021-06-05 11:26:36 +0200579 class OP_MODE(enum.IntEnum):
Harald Weltec91085e2022-02-10 18:05:45 +0100580 normal = 0x00
581 type_approval = 0x80
582 normal_and_specific_facilities = 0x01
583 type_approval_and_specific_facilities = 0x81
584 maintenance_off_line = 0x02
585 cell_test = 0x04
Harald Welte592b32e2021-06-05 11:26:36 +0200586
Harald Welte13edf302022-07-21 15:19:23 +0200587 def __init__(self, fid='6fad', sfid=0x03, name='EF.AD', desc='Administrative Data', size=(4, 6)):
Harald Welte592b32e2021-06-05 11:26:36 +0200588 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
589 self._construct = BitStruct(
590 # Byte 1
591 'ms_operation_mode'/Bytewise(Enum(Byte, EF_AD.OP_MODE)),
592 # Byte 2 + 3
593 'additional_info'/Bytewise(FlagsEnum(Int16ub, ciphering_indicator=1, csg_display_control=2,
594 prose_services=4, extended_drx=8)),
595 'rfu'/BitsRFU(4),
596 'mnc_len'/BitsInteger(4),
597 'extensions'/COptional(Bytewise(GreedyBytesRFU))
598 )
Harald Welte790b2702021-04-11 00:01:35 +0200599
600# TS 31.102 Section 4.2.23
601class EF_PSLOCI(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200602 def __init__(self, fid='6f73', sfid=0x0c, name='EF.PSLOCI', desc='PS Location information', size=(14, 14)):
Harald Welte790b2702021-04-11 00:01:35 +0200603 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
604 self._construct = Struct('ptmsi'/HexAdapter(Bytes(4)), 'ptmsi_sig'/HexAdapter(Bytes(3)),
605 'rai'/HexAdapter(Bytes(6)), 'rau_status'/Int8ub)
606
607# TS 31.102 Section 4.2.33
608class EF_ICI(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200609 def __init__(self, fid='6f80', sfid=0x14, name='EF.ICI', rec_len=(28, 48),
Harald Welte6169c722022-02-12 09:05:15 +0100610 desc='Incoming Call Information', **kwargs):
611 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200612 self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-28)),
Harald Welte790b2702021-04-11 00:01:35 +0200613 'len_of_bcd_contents'/Int8ub,
614 'ton_npi'/Int8ub,
615 'call_number'/BcdAdapter(Bytes(10)),
616 'cap_cfg2_record_id'/Int8ub,
617 'ext5_record_id'/Int8ub,
618 'date_and_time'/BcdAdapter(Bytes(7)),
619 'duration'/Int24ub,
620 'status'/Byte,
Harald Welte3c98d5e2022-07-20 07:40:05 +0200621 'link_to_phonebook'/HexAdapter(Bytes(3)))
Harald Welte790b2702021-04-11 00:01:35 +0200622
623# TS 31.102 Section 4.2.34
624class EF_OCI(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200625 def __init__(self, fid='6f81', sfid=0x15, name='EF.OCI', rec_len=(27, 47),
Harald Welte6169c722022-02-12 09:05:15 +0100626 desc='Outgoing Call Information', **kwargs):
627 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200628 self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-27)),
Harald Welte790b2702021-04-11 00:01:35 +0200629 'len_of_bcd_contents'/Int8ub,
630 'ton_npi'/Int8ub,
631 'call_number'/BcdAdapter(Bytes(10)),
632 'cap_cfg2_record_id'/Int8ub,
633 'ext5_record_id'/Int8ub,
634 'date_and_time'/BcdAdapter(Bytes(7)),
635 'duration'/Int24ub,
Harald Welte3c98d5e2022-07-20 07:40:05 +0200636 'link_to_phonebook'/HexAdapter(Bytes(3)))
Harald Welte790b2702021-04-11 00:01:35 +0200637
638# TS 31.102 Section 4.2.35
639class EF_ICT(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200640 def __init__(self, fid='6f82', sfid=None, name='EF.ICT', rec_len=(3, 3),
Harald Welte6169c722022-02-12 09:05:15 +0100641 desc='Incoming Call Timer', **kwargs):
642 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200643 self._construct = Struct('accumulated_call_timer'/Int24ub)
644
645# TS 31.102 Section 4.2.38
646class EF_CCP2(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100647 def __init__(self, fid='6f4f', sfid=0x16, name='EF.CCP2', desc='Capability Configuration Parameters 2', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200648 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(15, None), **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200649
Harald Welte6ca2fa72022-02-12 16:29:31 +0100650# TS 31.102 Section 4.2.47
651class EF_EST(EF_UServiceTable):
652 def __init__(self, **kwargs):
Harald Welte13edf302022-07-21 15:19:23 +0200653 super().__init__(fid='6f56', sfid=0x05, name='EF.EST', desc='Enabled Services Table', size=(1,None), table=EF_EST_map, **kwargs)
Harald Welte6ca2fa72022-02-12 16:29:31 +0100654 # add those commands to the general commands of a TransparentEF
655 self.shell_commands += [self.AddlShellCommands()]
656
657 @with_default_category('File-Specific Commands')
658 class AddlShellCommands(CommandSet):
659 def __init__(self):
660 super().__init__()
661
Harald Welte18b75392023-02-23 10:00:51 +0100662 def do_est_service_enable(self, arg):
Alexander Couzensc8facea2023-07-29 05:01:57 +0200663 """Enable a service within EF.EST"""
664 selected_file = self._cmd.lchan.selected_file
665 selected_file.ust_update(self._cmd, [int(arg)], [])
Harald Welte6ca2fa72022-02-12 16:29:31 +0100666
Harald Welte18b75392023-02-23 10:00:51 +0100667 def do_est_service_disable(self, arg):
Alexander Couzensc8facea2023-07-29 05:01:57 +0200668 """Disable a service within EF.EST"""
669 selected_file = self._cmd.lchan.selected_file
670 selected_file.ust_update(self._cmd, [], [int(arg)])
Harald Welte6ca2fa72022-02-12 16:29:31 +0100671
Harald Welte790b2702021-04-11 00:01:35 +0200672# TS 31.102 Section 4.2.48
673class EF_ACL(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200674 def __init__(self, fid='6f57', sfid=None, name='EF.ACL', size=(32, None),
Harald Welte6169c722022-02-12 09:05:15 +0100675 desc='Access Point Name Control List', **kwargs):
676 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200677 self._construct = Struct('num_of_apns'/Int8ub, 'tlvs'/HexAdapter(GreedyBytes))
Harald Welte790b2702021-04-11 00:01:35 +0200678
679# TS 31.102 Section 4.2.51
680class EF_START_HFN(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100681 _test_de_encode = [
682 ( 'f00000f00000', { "start_cs": 15728640, "start_ps": 15728640 } ),
683 ]
Harald Welte13edf302022-07-21 15:19:23 +0200684 def __init__(self, fid='6f5b', sfid=0x0f, name='EF.START-HFN', size=(6, 6),
Harald Welte6169c722022-02-12 09:05:15 +0100685 desc='Initialisation values for Hyperframe number', **kwargs):
686 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200687 self._construct = Struct('start_cs'/Int24ub, 'start_ps'/Int24ub)
688
689# TS 31.102 Section 4.2.52
690class EF_THRESHOLD(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100691 _test_de_encode = [
692 ( 'f01000', { "max_start": 15732736 } ),
693 ]
Harald Welte13edf302022-07-21 15:19:23 +0200694 def __init__(self, fid='6f5c', sfid=0x10, name='EF.THRESHOLD', size=(3, 3),
Harald Welte6169c722022-02-12 09:05:15 +0100695 desc='Maximum value of START', **kwargs):
696 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200697 self._construct = Struct('max_start'/Int24ub)
698
Harald Welte363edd92022-07-17 22:24:03 +0200699# TS 31.102 (old releases like 3.8.0) Section 4.2.56
700class EF_RPLMNAcT(TransRecEF):
Harald Welte13edf302022-07-21 15:19:23 +0200701 def __init__(self, fid='6f65', sfid=None, name='EF.RPLMNAcTD', size=(2, 4), rec_len=2,
Harald Welte363edd92022-07-17 22:24:03 +0200702 desc='RPLMN Last used Access Technology', **kwargs):
703 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs)
Harald Weltef6b37af2023-01-24 15:42:26 +0100704 def _decode_record_hex(self, in_hex, **kwargs):
Harald Welte363edd92022-07-17 22:24:03 +0200705 return dec_act(in_hex)
706 # TODO: Encode
707
Harald Welte790b2702021-04-11 00:01:35 +0200708# TS 31.102 Section 4.2.77
709class EF_VGCSCA(TransRecEF):
Harald Welte13edf302022-07-21 15:19:23 +0200710 def __init__(self, fid='6fd4', sfid=None, name='EF.VGCSCA', size=(2, 100), rec_len=2,
Harald Welte6169c722022-02-12 09:05:15 +0100711 desc='Voice Group Call Service Ciphering Algorithm', **kwargs):
712 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200713 self._construct = Struct('alg_v_ki_1'/Int8ub, 'alg_v_ki_2'/Int8ub)
714
715# TS 31.102 Section 4.2.79
716class EF_GBABP(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200717 def __init__(self, fid='6fd6', sfid=None, name='EF.GBABP', size=(3, 50),
Harald Welte6169c722022-02-12 09:05:15 +0100718 desc='GBA Bootstrapping parameters', **kwargs):
719 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200720 self._construct = Struct('rand'/LV, 'b_tid'/LV, 'key_lifetime'/LV)
721
722# TS 31.102 Section 4.2.80
723class EF_MSK(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100724 def __init__(self, fid='6fd7', sfid=None, name='EF.MSK', desc='MBMS Service Key List', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200725 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(20, None), **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200726 msk_ts_constr = Struct('msk_id'/Int32ub, 'timestamp_counter'/Int32ub)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200727 self._construct = Struct('key_domain_id'/HexAdapter(Bytes(3)),
Harald Welte790b2702021-04-11 00:01:35 +0200728 'num_msk_id'/Int8ub,
729 'msk_ids'/msk_ts_constr[this.num_msk_id])
Harald Welte14105dc2021-05-31 08:48:51 +0200730# TS 31.102 Section 4.2.81
731class EF_MUK(LinFixedEF):
732 class MUK_Idr(BER_TLV_IE, tag=0x80):
733 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100734
Harald Welte14105dc2021-05-31 08:48:51 +0200735 class MUK_Idi(BER_TLV_IE, tag=0x82):
736 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100737
Harald Welte14105dc2021-05-31 08:48:51 +0200738 class MUK_ID(BER_TLV_IE, tag=0xA0, nested=[MUK_Idr, MUK_Idi]):
739 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100740
Harald Welte14105dc2021-05-31 08:48:51 +0200741 class TimeStampCounter(BER_TLV_IE, tag=0x81):
742 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100743
Harald Welte14105dc2021-05-31 08:48:51 +0200744 class EF_MUK_Collection(TLV_IE_Collection, nested=[MUK_ID, TimeStampCounter]):
745 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100746
Harald Welte6169c722022-02-12 09:05:15 +0100747 def __init__(self, fid='6fd8', sfid=None, name='EF.MUK', desc='MBMS User Key', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200748 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(None, None), **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200749 self._tlv = EF_MUK.EF_MUK_Collection
750
751# TS 31.102 Section 4.2.83
752class EF_GBANL(LinFixedEF):
753 class NAF_ID(BER_TLV_IE, tag=0x80):
754 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100755
Harald Welte14105dc2021-05-31 08:48:51 +0200756 class B_TID(BER_TLV_IE, tag=0x81):
757 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100758
Harald Welte14105dc2021-05-31 08:48:51 +0200759 class EF_GBANL_Collection(BER_TLV_IE, nested=[NAF_ID, B_TID]):
760 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100761
Harald Welte6169c722022-02-12 09:05:15 +0100762 def __init__(self, fid='6fda', sfid=None, name='EF.GBANL', desc='GBA NAF List', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200763 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(None, None), **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200764 self._tlv = EF_GBANL.EF_GBANL_Collection
Harald Welte790b2702021-04-11 00:01:35 +0200765
766# TS 31.102 Section 4.2.85
767class EF_EHPLMNPI(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100768 _test_de_encode = [
769 ( '02', { "presentation_ind": "display_all" } ),
770 ]
Harald Welte13edf302022-07-21 15:19:23 +0200771 def __init__(self, fid='6fdb', sfid=None, name='EF.EHPLMNPI', size=(1, 1),
Harald Welte6169c722022-02-12 09:05:15 +0100772 desc='Equivalent HPLMN Presentation Indication', **kwargs):
773 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100774 self._construct = Struct('presentation_ind' /
Harald Welte790b2702021-04-11 00:01:35 +0200775 Enum(Byte, no_preference=0, display_highest_prio_only=1, display_all=2))
Harald Welte14105dc2021-05-31 08:48:51 +0200776
777# TS 31.102 Section 4.2.87
778class EF_NAFKCA(LinFixedEF):
779 class NAF_KeyCentreAddress(BER_TLV_IE, tag=0x80):
780 _construct = HexAdapter(GreedyBytes)
Harald Welte99e4cc02022-07-21 15:25:47 +0200781 def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', rec_len=(None, None),
Harald Welte6169c722022-02-12 09:05:15 +0100782 desc='NAF Key Centre Address', **kwargs):
783 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200784 self._tlv = EF_NAFKCA.NAF_KeyCentreAddress
785
786# TS 31.102 Section 4.2.90
787class EF_NCP_IP(LinFixedEF):
788 class DataDestAddrRange(TLV_IE, tag=0x83):
789 _construct = Struct('type_of_address'/Enum(Byte, IPv4=0x21, IPv6=0x56),
790 'prefix_length'/Int8ub,
791 'prefix'/HexAdapter(GreedyBytes))
Harald Weltec91085e2022-02-10 18:05:45 +0100792
Harald Welte14105dc2021-05-31 08:48:51 +0200793 class AccessPointName(TLV_IE, tag=0x80):
794 # coded as per TS 23.003
795 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100796
Harald Welte14105dc2021-05-31 08:48:51 +0200797 class Login(TLV_IE, tag=0x81):
798 # as per SMS DCS TS 23.038
799 _construct = GsmStringAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100800
Harald Welte14105dc2021-05-31 08:48:51 +0200801 class Password(TLV_IE, tag=0x82):
802 # as per SMS DCS TS 23.038
803 _construct = GsmStringAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100804
Harald Welte14105dc2021-05-31 08:48:51 +0200805 class BearerDescription(TLV_IE, tag=0x84):
806 # Bearer descriptionTLV DO as per TS 31.111
807 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100808
Harald Welte14105dc2021-05-31 08:48:51 +0200809 class EF_NCP_IP_Collection(TLV_IE_Collection,
810 nested=[AccessPointName, Login, Password, BearerDescription]):
811 pass
Harald Welte99e4cc02022-07-21 15:25:47 +0200812 def __init__(self, fid='6fe2', sfid=None, name='EF.NCP-IP', rec_len=(None, None),
Harald Welte6169c722022-02-12 09:05:15 +0100813 desc='Network Connectivity Parameters for USIM IP connections', **kwargs):
814 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200815 self._tlv = EF_NCP_IP.EF_NCP_IP_Collection
816
Harald Welte790b2702021-04-11 00:01:35 +0200817# TS 31.102 Section 4.2.91
818class EF_EPSLOCI(TransparentEF):
Harald Welte12721292022-07-21 15:33:06 +0200819 def __init__(self, fid='6fe3', sfid=0x1e, name='EF.EPSLOCI',
820 desc='EPS Location Information', size=(18,18), **kwargs):
Harald Welte6169c722022-02-12 09:05:15 +0100821 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100822 upd_status_constr = Enum(
823 Byte, updated=0, not_updated=1, roaming_not_allowed=2)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200824 self._construct = Struct('guti'/HexAdapter(Bytes(12)),
825 'last_visited_registered_tai'/HexAdapter(Bytes(5)),
Harald Welte790b2702021-04-11 00:01:35 +0200826 'eps_update_status'/upd_status_constr)
827
Harald Welte14105dc2021-05-31 08:48:51 +0200828# TS 31.102 Section 4.2.92
829class EF_EPSNSC(LinFixedEF):
Harald Weltec91085e2022-02-10 18:05:45 +0100830 class KSI_ASME(BER_TLV_IE, tag=0x80):
Harald Welte14105dc2021-05-31 08:48:51 +0200831 _construct = Int8ub
Harald Weltec91085e2022-02-10 18:05:45 +0100832
833 class K_ASME(BER_TLV_IE, tag=0x81):
Harald Welte14105dc2021-05-31 08:48:51 +0200834 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100835
Harald Welte14105dc2021-05-31 08:48:51 +0200836 class UplinkNASCount(BER_TLV_IE, tag=0x82):
837 _construct = Int32ub
Harald Weltec91085e2022-02-10 18:05:45 +0100838
Harald Welte14105dc2021-05-31 08:48:51 +0200839 class DownlinkNASCount(BER_TLV_IE, tag=0x83):
840 _construct = Int32ub
Harald Weltec91085e2022-02-10 18:05:45 +0100841
Harald Welte14105dc2021-05-31 08:48:51 +0200842 class IDofNASAlgorithms(BER_TLV_IE, tag=0x84):
843 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100844
Harald Welte14105dc2021-05-31 08:48:51 +0200845 class EPS_NAS_Security_Context(BER_TLV_IE, tag=0xa0,
Harald Weltec91085e2022-02-10 18:05:45 +0100846 nested=[KSI_ASME, K_ASME, UplinkNASCount, DownlinkNASCount,
847 IDofNASAlgorithms]):
Harald Welte14105dc2021-05-31 08:48:51 +0200848 pass
Harald Welte99e4cc02022-07-21 15:25:47 +0200849 def __init__(self, fid='6fe4', sfid=0x18, name='EF.EPSNSC', rec_len=(54, 128),
Harald Welte6169c722022-02-12 09:05:15 +0100850 desc='EPS NAS Security Context', **kwargs):
851 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200852 self._tlv = EF_EPSNSC.EPS_NAS_Security_Context
853
Harald Welte790b2702021-04-11 00:01:35 +0200854# TS 31.102 Section 4.2.96
855class EF_PWS(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100856 _test_de_encode = [
857 ( '00', { "pws_configuration": { "ignore_pws_in_hplmn_and_equivalent": False,
858 "ignore_pws_in_vplmn": False } } ),
859 ]
Harald Welte13edf302022-07-21 15:19:23 +0200860 def __init__(self, fid='6fec', sfid=None, name='EF.PWS', desc='Public Warning System', size=(1, 1), **kwargs):
Harald Welte6169c722022-02-12 09:05:15 +0100861 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100862 pws_config = FlagsEnum(
863 Byte, ignore_pws_in_hplmn_and_equivalent=1, ignore_pws_in_vplmn=2)
Harald Welte790b2702021-04-11 00:01:35 +0200864 self._construct = Struct('pws_configuration'/pws_config)
865
866# TS 31.102 Section 4.2.101
867class EF_IPS(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200868 def __init__(self, fid='6ff1', sfid=None, name='EF.IPS', rec_len=(4, 4),
Harald Welte6169c722022-02-12 09:05:15 +0100869 desc='IMEI(SV) Pairing Status', **kwargs):
870 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200871 self._construct = Struct('status'/PaddedString(2, 'ascii'),
872 'link_to_ef_ipd'/Int8ub, 'rfu'/Byte)
873
Harald Welte14105dc2021-05-31 08:48:51 +0200874# TS 31.102 Section 4.2.103
875class EF_ePDGId(TransparentEF):
876 class ePDGId(BER_TLV_IE, tag=0x80, nested=[]):
877 _construct = Struct('type_of_ePDG_address'/Enum(Byte, FQDN=0, IPv4=1, IPv6=2),
878 'ePDG_address'/Switch(this.type_of_address,
Philipp Maier791f80a2023-07-26 17:01:37 +0200879 {'FQDN': Utf8Adapter(GreedyBytes),
Harald Weltec91085e2022-02-10 18:05:45 +0100880 'IPv4': HexAdapter(GreedyBytes),
881 'IPv6': HexAdapter(GreedyBytes)}))
882
Harald Welte6169c722022-02-12 09:05:15 +0100883 def __init__(self, fid='6ff3', sfid=None, name='EF.eDPDGId', desc='Home ePDG Identifier', **kwargs):
884 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200885 self._tlv = EF_ePDGId.ePDGId
886
Harald Welte71290072021-04-21 10:58:24 +0200887# TS 31.102 Section 4.2.106
888class EF_FromPreferred(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200889 def __init__(self, fid='6ff7', sfid=None, name='EF.FromPreferred', size=(1, 1),
Harald Welte6169c722022-02-12 09:05:15 +0100890 desc='From Preferred', **kwargs):
891 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte71290072021-04-21 10:58:24 +0200892 self._construct = BitStruct('rfu'/BitsRFU(7), 'from_preferred'/Bit)
893
Harald Weltefc67de22023-05-23 20:29:49 +0200894# TS 31.102 Section 4.2.114
895class EF_eAKA(TransparentEF):
896 def __init__(self, fid='6f01', sfid=None, name='EF.eAKA', size=(1, 1),
897 desc='enhanced AKA support', **kwargs):
898 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
899 self._construct = BitStruct('rfu'/BitsRFU(7), 'enhanced_sqn_calculation_supported'/Bit)
900
Harald Welted90ceb82022-07-17 22:10:58 +0200901
902######################################################################
903# DF.GSM-ACCESS
904######################################################################
905
906class DF_GSM_ACCESS(CardDF):
907 def __init__(self, fid='5F3B', name='DF.GSM-ACCESS', desc='GSM Access', **kwargs):
908 super().__init__(fid=fid, name=name, desc=desc, service=27, **kwargs)
909 files = [
910 EF_Kc(fid='4f20', sfid=0x01, service=27),
911 EF_Kc(fid='4f52', sfid=0x02, name='EF.KcGPRS', desc='GPRS Ciphering key KcGPRS', service=27),
912 EF_CPBCCH(fid='4f63', service=39),
913 EF_InvScan(fid='4f64', service=40),
914 ]
915 self.add_files(files)
916
917
Harald Welte790b2702021-04-11 00:01:35 +0200918######################################################################
919# DF.5GS
920######################################################################
921
922# TS 31.102 Section 4.4.11.2
923class EF_5GS3GPPLOCI(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200924 def __init__(self, fid='4f01', sfid=0x01, name='EF.5GS3GPPLOCI', size=(20, 20),
Harald Welte419bb492022-02-12 21:39:35 +0100925 desc='5S 3GP location information', **kwargs):
926 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100927 upd_status_constr = Enum(
928 Byte, updated=0, not_updated=1, roaming_not_allowed=2)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200929 self._construct = Struct('5g_guti'/HexAdapter(Bytes(13)),
930 'last_visited_registered_tai_in_5gs'/HexAdapter(Bytes(6)),
Harald Welte790b2702021-04-11 00:01:35 +0200931 '5gs_update_status'/upd_status_constr)
932
933# TS 31.102 Section 4.4.11.7
934class EF_UAC_AIC(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100935 _test_de_encode = [
936 ( '03', { "uac_access_id_config": { "multimedia_priority_service": True,
937 "mission_critical_service": True } } ),
938 ]
Harald Welte13edf302022-07-21 15:19:23 +0200939 def __init__(self, fid='4f06', sfid=0x06, name='EF.UAC_AIC', size=(4, 4),
Harald Welte419bb492022-02-12 21:39:35 +0100940 desc='UAC Access Identities Configuration', **kwargs):
941 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200942 cfg_constr = FlagsEnum(Byte, multimedia_priority_service=1,
Harald Weltec91085e2022-02-10 18:05:45 +0100943 mission_critical_service=2)
Harald Welte790b2702021-04-11 00:01:35 +0200944 self._construct = Struct('uac_access_id_config'/cfg_constr)
945
Harald Welte14105dc2021-05-31 08:48:51 +0200946# TS 31.102 Section 4.4.11.9
Harald Welte790b2702021-04-11 00:01:35 +0200947class EF_OPL5G(LinFixedEF):
Harald Welte52064292023-05-24 15:25:26 +0200948 def __init__(self, fid='4f08', sfid=0x08, name='EF.OPL5G', desc='5GS Operator PLMN List', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200949 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(10, None), **kwargs)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200950 Tai = Struct('mcc_mnc'/BcdAdapter(Bytes(3)), 'tac_min'/HexAdapter(Bytes(3)),
951 'tac_max'/HexAdapter(Bytes(3)))
Harald Weltea0377622022-02-25 15:36:44 +0100952 self._construct = Struct('tai'/Tai, 'pnn_record_id'/Int8ub)
Harald Welte790b2702021-04-11 00:01:35 +0200953
Harald Welte14105dc2021-05-31 08:48:51 +0200954# TS 31.102 Section 4.4.11.10
955class EF_SUPI_NAI(TransparentEF):
956 class NetworkSpecificIdentifier(TLV_IE, tag=0x80):
957 # RFC 7542 encoded as UTF-8 string
Philipp Maier791f80a2023-07-26 17:01:37 +0200958 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100959
Harald Welte14105dc2021-05-31 08:48:51 +0200960 class GlobalLineIdentifier(TLV_IE, tag=0x81):
961 # TS 23.003 clause 28.16.2
Philipp Maier791f80a2023-07-26 17:01:37 +0200962 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100963
Harald Welte14105dc2021-05-31 08:48:51 +0200964 class GlobalCableIdentifier(TLV_IE, tag=0x82):
965 # TS 23.003 clause 28.15.2
Philipp Maier791f80a2023-07-26 17:01:37 +0200966 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100967
Harald Welte14105dc2021-05-31 08:48:51 +0200968 class NAI_TLV_Collection(TLV_IE_Collection,
Harald Weltec91085e2022-02-10 18:05:45 +0100969 nested=[NetworkSpecificIdentifier, GlobalLineIdentifier, GlobalCableIdentifier]):
Harald Welte14105dc2021-05-31 08:48:51 +0200970 pass
971 def __init__(self, fid='4f09', sfid=0x09, name='EF.SUPI_NAI',
Harald Welte419bb492022-02-12 21:39:35 +0100972 desc='SUPI as Network Access Identifier', **kwargs):
973 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200974 self._tlv = EF_SUPI_NAI.NAI_TLV_Collection
975
Harald Welte455611c2023-05-27 12:48:54 +0200976# TS 31.102 Section 4.4.11.11
977class EF_Routing_Indicator(TransparentEF):
978 def __init__(self, fid='4f0a', sfid=0x0a, name='EF.Routing_Indicator', desc='Routing Indicator', **kwargs):
979 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
980 # 3GPP TS 24.501 Table 9.11.3.4.1:
981 # Routing Indicator shall consist of 1 to 4 digits. The coding of this field is the
982 # responsibility of home network operator but BCD coding shall be used. If a network
983 # operator decides to assign less than 4 digits to Routing Indicator, the remaining digits
984 # shall be coded as "1111" to fill the 4 digits coding of Routing Indicator
Harald Weltef9a5ba52023-06-09 09:17:05 +0200985 self._construct = Struct('routing_indicator'/Rpad(BcdAdapter(Bytes(2)), 'f', 2),
986 'rfu'/HexAdapter(Bytes(2)))
Harald Weltec91085e2022-02-10 18:05:45 +0100987
Harald Weltefc67de22023-05-23 20:29:49 +0200988# TS 31.102 Section 4.4.11.13
Harald Welte14105dc2021-05-31 08:48:51 +0200989class EF_TN3GPPSNN(TransparentEF):
990 class ServingNetworkName(BER_TLV_IE, tag=0x80):
Philipp Maier791f80a2023-07-26 17:01:37 +0200991 _construct = Utf8Adapter(GreedyBytes)
Harald Welte14105dc2021-05-31 08:48:51 +0200992 def __init__(self, fid='4f0c', sfid=0x0c, name='EF.TN3GPPSNN',
Harald Welte419bb492022-02-12 21:39:35 +0100993 desc='Trusted non-3GPP Serving network names list', **kwargs):
994 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200995 self._tlv = EF_TN3GPPSNN.ServingNetworkName
996
Harald Weltefc67de22023-05-23 20:29:49 +0200997# TS 31.102 Section 4.4.11.14 (Rel 17)
998class EF_CAG(TransparentEF):
999 def __init__(self, fid='4f0d', sfid=0x0d, name='EF.CAG',
1000 desc='Pre-configured CAG information list EF', **kwargs):
1001 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1002 self._construct = HexAdapter(GreedyBytes)
1003
1004# TS 31.102 Section 4.4.11.15 (Rel 17)
1005class EF_SOR_CMCI(TransparentEF):
1006 def __init__(self, fid='4f0e', sfid=0x0e, name='EF.SOR-CMCI',
1007 desc='Steering Of Roaming - Connected Mode Control Information', **kwargs):
1008 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1009 self._construct = HexAdapter(GreedyBytes)
1010
1011# TS 31.102 Section 4.4.11.17 (Rel 17)
1012class EF_DRI(TransparentEF):
1013 def __init__(self, fid='4f0f', sfid=0x0f, name='EF.DRI',
1014 desc='Disaster roaming information EF', **kwargs):
1015 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1016 self._construct = Struct('disaster_roaming_enabled'/Byte,
1017 'parameters_indicator_status'/FlagsEnum(Byte, roaming_wait_range=1,
1018 return_wait_range=2,
1019 applicability_indicator=3),
1020 'roaming_wait_range'/HexAdapter(Bytes(2)),
1021 'return_wait_range'/HexAdapter(Bytes(2)),
1022 'applicability_indicator'/HexAdapter(Byte))
1023
1024# TS 31.102 Section 4.4.12.2 (Rel 17)
1025class EF_PWS_SNPN(TransparentEF):
1026 def __init__(self, fid='4f01', sfid=0x01, name='EF.PWS_SNPN',
1027 desc='Public Warning System in SNPNs', **kwargs):
1028 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1029 self._construct = Struct('pws_config_in_snpns'/FlagsEnum(Byte, ignore_all_pws_in_subscribed=1,
1030 ignore_all_pws_in_non_subscribed=2))
1031
1032# TS 31.102 Section 4.4.12.2 (Rel 17)
1033class EF_NID(LinFixedEF):
1034 def __init__(self, fid='4f02', sfid=0x02, name='EF.NID',
1035 desc='Network Identifier for SNPN', **kwargs):
1036 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(6,6), **kwargs)
1037 self._construct = Struct('assignment_mode'/Enum(Byte, coordinated_ass_opt1=0,
1038 self_ass=1,
1039 coordinated_ass_opt2=2),
1040 'network_identifier'/HexAdapter(Bytes(5)))
1041
1042# TS 31.102 Section 4.4.12 (Rel 17)
1043class DF_SNPN(CardDF):
1044 def __init__(self, fid='5fe0', name='DF.SNPN', desc='Files for SNPN purpose', **kwargs):
1045 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
1046 files = [
1047 EF_PWS_SNPN(service=143),
1048 EF_NID(service=146),
1049 ]
1050 self.add_files(files)
1051
1052# TS 31.102 Section 4.4.13.2 (Rel 17)
1053class EF_5G_PROSE_ST(EF_UServiceTable):
1054 def __init__(self, **kwargs):
1055 super().__init__(fid='4f01', sfid=0x01, name='EF.5G_PROSE_ST',
1056 desc='5G ProSe Service Table', size=(1,2), table=EF_5G_PROSE_ST_map, **kwargs)
1057 # add those commands to the general commands of a TransparentEF
1058 self.shell_commands += [self.AddlShellCommands()]
1059
1060 @with_default_category('File-Specific Commands')
1061 class AddlShellCommands(CommandSet):
1062 def __init__(self):
1063 super().__init__()
1064
1065 def do_prose_service_activate(self, arg):
1066 """Activate a service within EF.5G_PROSE_ST"""
Alexander Couzensc8facea2023-07-29 05:01:57 +02001067 selected_file = self._cmd.lchan.selected_file
1068 selected_file.ust_update(self._cmd, [int(arg)], [])
Harald Weltefc67de22023-05-23 20:29:49 +02001069
1070 def do_prose_service_deactivate(self, arg):
1071 """Deactivate a service within EF.5G_PROSE_ST"""
Alexander Couzensc8facea2023-07-29 05:01:57 +02001072 selected_file = self._cmd.lchan.selected_file
1073 selected_file.ust_update(self._cmd, [], [int(arg)])
Harald Weltefc67de22023-05-23 20:29:49 +02001074
1075# TS 31.102 Section 4.4.13.3 (Rel 17)
1076class EF_5G_PROSE_DD(TransparentEF):
1077 class ServedByNgRan(BER_TLV_IE, tag=0x80):
1078 pass
1079 class NotServedByNgran(BER_TLV_IE, tag=0x81):
1080 pass
1081 class ProSeIdentifiers(BER_TLV_IE, tag=0x82):
1082 pass
1083 class ProSeIdToDefaultDestL2Id(BER_TLV_IE, tag=0x83):
1084 pass
1085 class GroupMemberDiscoveryParameters(BER_TLV_IE, tag=0x84):
1086 pass
1087 class ValidityTimer(BER_TLV_IE, tag=0x85):
1088 pass
1089 class ProSeDirectDiscoveryUeId(BER_TLV_IE, tag=0x86):
1090 pass
1091 class Hplmn5GDdnmfAddressInformation(BER_TLV_IE, tag=0x87):
1092 pass
1093 class ProSeConfigForDirectDiscovery(BER_TLV_IE, tag=0xA0,
1094 nested=[ServedByNgRan, NotServedByNgran, ProSeIdentifiers,
1095 ProSeIdToDefaultDestL2Id, GroupMemberDiscoveryParameters,
1096 ValidityTimer, ProSeDirectDiscoveryUeId,
1097 Hplmn5GDdnmfAddressInformation]):
1098 pass
1099 def __init__(self, fid='4f02', sfid=0x02, name='EF.5G_PROSE_DD',
1100 desc='5G ProSe configuration data for direct discovery', **kwargs):
1101 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1102 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1103 self._tlv = EF_5G_PROSE_DD.ProSeConfigForDirectDiscovery
1104
1105# TS 31.102 Section 4.4.13.4 (Rel 17)
1106class EF_5G_PROSE_DC(TransparentEF):
1107 class PrivacyConfig(BER_TLV_IE, tag=0x87):
1108 pass
1109 class DirectCommInNrPc5(BER_TLV_IE, tag=0x88):
1110 pass
1111 class ApplicationToPathPreferenceMappingRules(BER_TLV_IE, tag=0x89):
1112 pass
1113 class ProSeIdToNrTxProfileForBroadcastAndGroupcastMappingRules(BER_TLV_IE, tag=0x91):
1114 pass
1115 class ProSeConfigForDirectCommunication(BER_TLV_IE, tag=0xA0,
1116 nested=[EF_5G_PROSE_DD.ServedByNgRan,
1117 EF_5G_PROSE_DD.NotServedByNgran,
1118 PrivacyConfig, DirectCommInNrPc5,
1119 ApplicationToPathPreferenceMappingRules,
1120 EF_5G_PROSE_DD.ValidityTimer,
1121 ProSeIdToNrTxProfileForBroadcastAndGroupcastMappingRules]):
1122 pass
1123 def __init__(self, fid='4f03', sfid=0x03, name='EF.5G_PROSE_DC',
1124 desc='5G ProSe configuration data for direct communication', **kwargs):
1125 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1126 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1127 self._tlv = EF_5G_PROSE_DC.ProSeConfigForDirectCommunication
1128
1129# TS 31.102 Section 4.4.13.5 (Rel 17)
1130class EF_5G_PROSE_U2NRU(TransparentEF):
1131 class ProSeIdToDefaultDestL2Id(BER_TLV_IE, tag=0x8a):
1132 pass
1133 class RxcInfoList(BER_TLV_IE, tag=0x8b):
1134 pass
1135 class FiveQiToPc65QosParametersMappingRules(BER_TLV_IE, tag=0x8c):
1136 pass
1137 class ProSeIdToAppSrvAddrMappingRules(BER_TLV_IE, tag=0x8d):
1138 pass
1139 class UserInfoIdForDiscovery(BER_TLV_IE, tag=0x8e):
1140 pass
1141 class PrivacyTimer(BER_TLV_IE, tag=0x92):
1142 pass
1143 class FiveGPkkmfAddressInformation(BER_TLV_IE, tag=0x93):
1144 pass
1145 class ProSeConfigDataForUeToNetworkRelayUe(BER_TLV_IE, tag=0xA0,
1146 nested=[EF_5G_PROSE_DD.ServedByNgRan,
1147 EF_5G_PROSE_DD.NotServedByNgran,
1148 ProSeIdToDefaultDestL2Id,
1149 RxcInfoList,
1150 FiveQiToPc65QosParametersMappingRules,
1151 ProSeIdToAppSrvAddrMappingRules,
1152 EF_5G_PROSE_DD.ValidityTimer,
1153 UserInfoIdForDiscovery,
1154 PrivacyTimer,
1155 FiveGPkkmfAddressInformation]):
1156 pass
1157 def __init__(self, fid='4f04', sfid=0x04, name='EF.5G_PROSE_U2NRU',
1158 desc='5G ProSe configuration data for UE-to-network relay UE', **kwargs):
1159 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1160 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1161 self._tlv = EF_5G_PROSE_U2NRU.ProSeConfigDataForUeToNetworkRelayUe
1162
1163# TS 31.102 Section 4.4.13.6 (Rel 17)
1164class EF_5G_PROSE_RU(TransparentEF):
1165 class DefaultDestL2Ids(BER_TLV_IE, tag=0x8f):
1166 pass
1167 class N3IwfSelectionInfoFor5GProSeL3RemoteUE(BER_TLV_IE, tag=0x90):
1168 pass
1169 class ProSeConfigDataForRemoteUe(BER_TLV_IE, tag=0xa0,
1170 nested=[EF_5G_PROSE_DD.ServedByNgRan,
1171 EF_5G_PROSE_DD.NotServedByNgran,
1172 DefaultDestL2Ids,
1173 EF_5G_PROSE_U2NRU.RxcInfoList,
1174 N3IwfSelectionInfoFor5GProSeL3RemoteUE,
1175 EF_5G_PROSE_DD.ValidityTimer,
1176 EF_5G_PROSE_U2NRU.UserInfoIdForDiscovery,
1177 EF_5G_PROSE_U2NRU.PrivacyTimer,
1178 EF_5G_PROSE_U2NRU.FiveGPkkmfAddressInformation]):
1179 pass
1180 def __init__(self, fid='4f05', sfid=0x05, name='EF.5G_PROSE_RU',
1181 desc='5G ProSe configuration data for remote UE', **kwargs):
1182 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1183 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1184 self._tlv = EF_5G_PROSE_RU.ProSeConfigDataForRemoteUe
1185
1186# TS 31.102 Section 4.4.13.7 (Rel 17)
1187class EF_5G_PROSE_UIR(TransparentEF):
1188 class CollectionPeriod(BER_TLV_IE, tag=0x94):
1189 pass
1190 class ReportingWindow(BER_TLV_IE, tag=0x95):
1191 pass
1192 class ReportingIndicators(BER_TLV_IE, tag=0x96):
1193 pass
1194 class FiveGDdnmfCtfAddrForUploading(BER_TLV_IE, tag=0x97):
1195 pass
1196 class ProSeConfigDataForUeToNetworkRelayUE(BER_TLV_IE, tag=0xa0,
1197 nested=[EF_5G_PROSE_DD.ValidityTimer,
1198 CollectionPeriod, ReportingWindow,
1199 ReportingIndicators,
1200 FiveGDdnmfCtfAddrForUploading]):
1201 pass
1202 def __init__(self, fid='4f06', sfid=0x06, name='EF.5G_PROSE_UIR',
1203 desc='5G ProSe configuration data for usage information reporting', **kwargs):
1204 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1205 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1206 self._tlv = EF_5G_PROSE_UIR.ProSeConfigDataForUeToNetworkRelayUE
1207
1208# TS 31.102 Section 4.4.13 (Rel 17)
1209class DF_5G_ProSe(CardDF):
1210 def __init__(self, fid='5ff0', name='DF.5G_ProSe', desc='Files for 5G ProSe purpose', **kwargs):
1211 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
1212 files = [
1213 EF_5G_PROSE_ST(),
1214 EF_5G_PROSE_DD(service=1),
1215 EF_5G_PROSE_DC(service=2),
1216 EF_5G_PROSE_U2NRU(service=3),
1217 EF_5G_PROSE_RU(service=4),
1218 EF_5G_PROSE_UIR(service=5),
1219 ]
1220 self.add_files(files)
1221
1222# TS 31.102 Section 4.4.11.18 (Rel 17)
1223class EF_5GSEDRX(TransparentEF):
1224 def __init__(self, fid='4f10', sfid=0x10, name='EF.5GSEDRX',
1225 desc='5GS eDRX Parameters', **kwargs):
1226 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1227 self._construct = Struct('5gs_rat_type'/FlagsEnum(Byte, ng_ran=1, sat_ng_ran=2),
1228 'edrx_cycle_length'/Int8ub)
1229
1230# TS 31.102 Section 4.4.11.19 (Rel 17)
1231class EF_5GNSWO_CONF(TransparentEF):
1232 def __init__(self, fid='4f11', sfid=0x11, name='EF.5GNSWO_CONF',
1233 desc='5G Non-Seamless WLAN Offload configuration', **kwargs):
1234 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1235 self._construct = Struct('5g_nswo_usage_ind'/Enum(Byte, disabled=0, enabled=1))
1236
1237# TS 31.102 Section 4.4.11.20 (Rel 17)
1238class EF_MCHPPLMN(TransparentEF):
Harald Welte24e77a72023-05-24 15:26:29 +02001239 def __init__(self, fid='4f15', sfid=0x15, name='EF.MCHPPLMN',
Harald Weltefc67de22023-05-23 20:29:49 +02001240 desc='Multiplier Coefficient for Higher Priority PLMN search', **kwargs):
1241 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1242 self._construct = Struct('multiplier_coefficient'/Int8ub)
1243
1244# TS 31.102 Section 4.4.11.21 (Rel 17)
1245class EF_KAUSF_DERIVATION(TransparentEF):
1246 def __init__(self, fid='4f16', sfid=0x16, name='EF.KAUSF_DERIVATION',
1247 desc='K_AUSF derivation configuration', **kwargs):
1248 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1249 self._construct = Struct('k_ausf_deriv_cfg'/FlagsEnum(Byte, use_msk=1), 'rfu'/HexAdapter(GreedyBytes))
1250
Harald Welte3990ebb2021-04-20 23:55:14 +02001251# TS 31.102 Section 4.4.5
1252class DF_WLAN(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001253 def __init__(self, fid='5f40', name='DF.WLAN', desc='Files for WLAN purpose', **kwargs):
1254 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Harald Welte3990ebb2021-04-20 23:55:14 +02001255 files = [
Harald Welte419bb492022-02-12 21:39:35 +01001256 TransparentEF('4f41', 0x01, 'EF.Pseudo', 'Pseudonym', service=59),
Harald Weltec91085e2022-02-10 18:05:45 +01001257 TransparentEF('4f42', 0x02, 'EF.UPLMNWLAN',
Harald Welte419bb492022-02-12 21:39:35 +01001258 'User controlled PLMN selector for I-WLAN Access', service=60),
Harald Weltec91085e2022-02-10 18:05:45 +01001259 TransparentEF('4f43', 0x03, 'EF.OPLMNWLAN',
Harald Welte419bb492022-02-12 21:39:35 +01001260 'Operator controlled PLMN selector for I-WLAN Access', service=61),
Harald Weltec91085e2022-02-10 18:05:45 +01001261 LinFixedEF('4f44', 0x04, 'EF.UWSIDL',
Harald Welte419bb492022-02-12 21:39:35 +01001262 'User controlled WLAN Specific Identifier List', service=62),
Harald Weltec91085e2022-02-10 18:05:45 +01001263 LinFixedEF('4f45', 0x05, 'EF.OWSIDL',
Harald Welte419bb492022-02-12 21:39:35 +01001264 'Operator controlled WLAN Specific Identifier List', service=63),
Harald Weltec91085e2022-02-10 18:05:45 +01001265 TransparentEF('4f46', 0x06, 'EF.WRI',
Harald Welte419bb492022-02-12 21:39:35 +01001266 'WLAN Reauthentication Identity', service=66),
Harald Weltec91085e2022-02-10 18:05:45 +01001267 LinFixedEF('4f47', 0x07, 'EF.HWSIDL',
Harald Welte419bb492022-02-12 21:39:35 +01001268 'Home I-WLAN Specific Identifier List', service=81),
Harald Weltec91085e2022-02-10 18:05:45 +01001269 TransparentEF('4f48', 0x08, 'EF.WEHPLMNPI',
Harald Welte419bb492022-02-12 21:39:35 +01001270 'I-WLAN Equivalent HPLMN Presentation Indication', service=82),
Harald Weltec91085e2022-02-10 18:05:45 +01001271 TransparentEF('4f49', 0x09, 'EF.WHPI',
Harald Welte419bb492022-02-12 21:39:35 +01001272 'I-WLAN HPLMN Priority Indication', service=83),
Harald Weltec91085e2022-02-10 18:05:45 +01001273 TransparentEF('4f4a', 0x0a, 'EF.WLRPLMN',
Harald Welte419bb492022-02-12 21:39:35 +01001274 'I-WLAN Last Registered PLMN', service=84),
Harald Weltec91085e2022-02-10 18:05:45 +01001275 TransparentEF('4f4b', 0x0b, 'EF.HPLMNDAI',
Harald Welte419bb492022-02-12 21:39:35 +01001276 'HPLMN Direct Access Indicator', service=88),
Harald Weltec91085e2022-02-10 18:05:45 +01001277 ]
Harald Welte3990ebb2021-04-20 23:55:14 +02001278 self.add_files(files)
1279
1280# TS 31.102 Section 4.4.6
1281class DF_HNB(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001282 def __init__(self, fid='5f50', name='DF.HNB', desc='Files for HomeNodeB purpose', **kwargs):
1283 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Harald Welte3990ebb2021-04-20 23:55:14 +02001284 files = [
Harald Welteeb882052022-07-17 21:13:57 +02001285 LinFixedEF('4f81', 0x01, 'EF.ACSGL', 'Allowed CSG Lists', service=86),
1286 LinFixedEF('4f82', 0x02, 'EF.CSGTL', 'CSG Types', service=86),
1287 LinFixedEF('4f83', 0x03, 'EF.HNBN', 'Home NodeB Name', service=86),
1288 LinFixedEF('4f84', 0x04, 'EF.OCSGL', 'Operator CSG Lists', service=90),
1289 LinFixedEF('4f85', 0x05, 'EF.OCSGT', 'Operator CSG Type', service=90),
1290 LinFixedEF('4f86', 0x06, 'EF.OHNBN', 'Operator Home NodeB Name', service=90),
Harald Weltec91085e2022-02-10 18:05:45 +01001291 ]
Harald Welte3990ebb2021-04-20 23:55:14 +02001292 self.add_files(files)
1293
1294# TS 31.102 Section 4.4.8
1295class DF_ProSe(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001296 def __init__(self, fid='5f90', name='DF.ProSe', desc='Files for ProSe purpose', **kwargs):
1297 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Harald Welte3990ebb2021-04-20 23:55:14 +02001298 files = [
Harald Weltec91085e2022-02-10 18:05:45 +01001299 LinFixedEF('4f01', 0x01, 'EF.PROSE_MON',
1300 'ProSe Monitoring Parameters'),
1301 LinFixedEF('4f02', 0x02, 'EF.PROSE_ANN',
1302 'ProSe Announcing Parameters'),
Harald Welte3990ebb2021-04-20 23:55:14 +02001303 LinFixedEF('4f03', 0x03, 'EF.PROSEFUNC', 'HPLMN ProSe Function'),
Harald Weltec91085e2022-02-10 18:05:45 +01001304 TransparentEF('4f04', 0x04, 'EF.PROSE_RADIO_COM',
1305 'ProSe Direct Communication Radio Parameters'),
1306 TransparentEF('4f05', 0x05, 'EF.PROSE_RADIO_MON',
1307 'ProSe Direct Discovery Monitoring Radio Parameters'),
1308 TransparentEF('4f06', 0x06, 'EF.PROSE_RADIO_ANN',
1309 'ProSe Direct Discovery Announcing Radio Parameters'),
1310 LinFixedEF('4f07', 0x07, 'EF.PROSE_POLICY',
1311 'ProSe Policy Parameters'),
Harald Welte3990ebb2021-04-20 23:55:14 +02001312 LinFixedEF('4f08', 0x08, 'EF.PROSE_PLMN', 'ProSe PLMN Parameters'),
1313 TransparentEF('4f09', 0x09, 'EF.PROSE_GC', 'ProSe Group Counter'),
1314 TransparentEF('4f10', 0x10, 'EF.PST', 'ProSe Service Table'),
Harald Weltec91085e2022-02-10 18:05:45 +01001315 TransparentEF('4f11', 0x11, 'EF.UIRC',
1316 'ProSe UsageInformationReportingConfiguration'),
1317 LinFixedEF('4f12', 0x12, 'EF.PROSE_GM_DISCOVERY',
1318 'ProSe Group Member Discovery Parameters'),
1319 LinFixedEF('4f13', 0x13, 'EF.PROSE_RELAY',
1320 'ProSe Relay Parameters'),
1321 TransparentEF('4f14', 0x14, 'EF.PROSE_RELAY_DISCOVERY',
1322 'ProSe Relay Discovery Parameters'),
1323 ]
Harald Welte3990ebb2021-04-20 23:55:14 +02001324 self.add_files(files)
1325
Harald Weltec91085e2022-02-10 18:05:45 +01001326
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001327class DF_USIM_5GS(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001328 def __init__(self, fid='5FC0', name='DF.5GS', desc='5GS related files', **kwargs):
1329 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001330 files = [
Harald Weltec91085e2022-02-10 18:05:45 +01001331 # I'm looking at 31.102 R16.6
Harald Welte419bb492022-02-12 21:39:35 +01001332 EF_5GS3GPPLOCI(service=122),
Harald Weltec91085e2022-02-10 18:05:45 +01001333 EF_5GS3GPPLOCI('4f02', 0x02, 'EF.5GSN3GPPLOCI',
Harald Welte28accc82023-10-18 23:21:46 +02001334 desc='5GS non-3GPP location information', service=122),
Harald Welte419bb492022-02-12 21:39:35 +01001335 EF_5GS3GPPNSC(service=122),
Harald Weltec91085e2022-02-10 18:05:45 +01001336 EF_5GS3GPPNSC('4f04', 0x04, 'EF.5GSN3GPPNSC',
Harald Welte28accc82023-10-18 23:21:46 +02001337 desc='5GS non-3GPP Access NAS Security Context', service=122),
Harald Welte419bb492022-02-12 21:39:35 +01001338 EF_5GAUTHKEYS(service=123),
1339 EF_UAC_AIC(service=126),
1340 EF_SUCI_Calc_Info(service=124),
1341 EF_OPL5G(service=129),
1342 EF_SUPI_NAI(service=130),
Harald Welte455611c2023-05-27 12:48:54 +02001343 EF_Routing_Indicator(service=124),
Harald Weltec91085e2022-02-10 18:05:45 +01001344 TransparentEF('4F0B', 0x0b, 'EF.URSP',
Harald Welte28accc82023-10-18 23:21:46 +02001345 desc='UE Route Selector Policies per PLMN', service=132),
Harald Welte419bb492022-02-12 21:39:35 +01001346 EF_TN3GPPSNN(service=133),
Harald Weltefc67de22023-05-23 20:29:49 +02001347 # Rel-17 additions below
1348 EF_CAG(service=137),
1349 EF_SOR_CMCI(service=138),
1350 EF_DRI(service=140),
1351 EF_5GSEDRX(service=141),
1352 EF_5GNSWO_CONF(service=142),
1353 EF_MCHPPLMN(service=144),
1354 EF_KAUSF_DERIVATION(service=145),
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001355 ]
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001356 self.add_files(files)
1357
Harald Weltec91085e2022-02-10 18:05:45 +01001358
Harald Welte2bee70c2023-05-25 09:14:28 +02001359class DF_SAIP(CardDF):
1360 """This is not really TS 31.102 but part of the eUICC Profile Package: Interoperable Format Technical
1361 Specification as released by TCA (formerly SIMalliance)"""
1362 def __init__(self, fid='5FD0', name='DF.SAIP', desc='SIMalliance Interoperable Profile', **kwargs):
1363 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
1364 files = [
1365 # uses the same file format as DF.5GS/EF_SUCI_Calc_Info, but different FID
1366 EF_SUCI_Calc_Info(fid='4f01')
1367 ]
1368 self.add_files(files)
1369
1370
Harald Welteb2edd142021-01-08 23:29:35 +01001371class ADF_USIM(CardADF):
1372 def __init__(self, aid='a0000000871002', name='ADF.USIM', fid=None, sfid=None,
1373 desc='USIM Application'):
1374 super().__init__(aid=aid, fid=fid, sfid=sfid, name=name, desc=desc)
Harald Welte15fae982021-04-10 10:22:27 +02001375 # add those commands to the general commands of a TransparentEF
1376 self.shell_commands += [self.AddlShellCommands()]
Harald Welteb2edd142021-01-08 23:29:35 +01001377
1378 files = [
Harald Weltec91085e2022-02-10 18:05:45 +01001379 EF_LI(sfid=0x02),
1380 EF_IMSI(sfid=0x07),
1381 EF_Keys(),
1382 EF_Keys('6f09', 0x09, 'EF.KeysPS',
1383 desc='Ciphering and Integrity Keys for PS domain'),
1384 EF_xPLMNwAcT('6f60', 0x0a, 'EF.PLMNwAcT',
Harald Welte509ecf82023-10-18 23:32:57 +02001385 desc='User controlled PLMN Selector with Access Technology', service=20),
Harald Weltec91085e2022-02-10 18:05:45 +01001386 EF_HPPLMN(),
Harald Welte6169c722022-02-12 09:05:15 +01001387 EF_ACMmax(service=13),
Harald Welte6ca2fa72022-02-12 16:29:31 +01001388 EF_UST(),
Harald Weltec91085e2022-02-10 18:05:45 +01001389 CyclicEF('6f39', None, 'EF.ACM',
Harald Welte509ecf82023-10-18 23:32:57 +02001390 desc='Accumulated call meter', rec_len=(3, 3), service=13),
1391 TransparentEF('6f3e', None, 'EF.GID1', desc='Group Identifier Level 1', service=17),
1392 TransparentEF('6f3f', None, 'EF.GID2', desc='Group Identifier Level 2', service=18),
Harald Welte6169c722022-02-12 09:05:15 +01001393 EF_SPN(service=19),
Harald Weltec91085e2022-02-10 18:05:45 +01001394 TransparentEF('6f41', None, 'EF.PUCT',
Harald Welte509ecf82023-10-18 23:32:57 +02001395 desc='Price per unit and currency table', size=(5, 5), service=13),
Harald Welte6169c722022-02-12 09:05:15 +01001396 EF_CBMI(service=15),
Harald Weltec91085e2022-02-10 18:05:45 +01001397 EF_ACC(sfid=0x06),
Harald Welte509ecf82023-10-18 23:32:57 +02001398 EF_PLMNsel('6f7b', 0x0d, 'EF.FPLMN', desc='Forbidden PLMNs', size=(12, None)),
Harald Weltec91085e2022-02-10 18:05:45 +01001399 EF_LOCI(),
1400 EF_AD(),
Harald Welte6169c722022-02-12 09:05:15 +01001401 EF_CBMID(sfid=0x0e, service=29),
Harald Weltec91085e2022-02-10 18:05:45 +01001402 EF_ECC(),
Harald Welte6169c722022-02-12 09:05:15 +01001403 EF_CBMIR(service=16),
Harald Weltec91085e2022-02-10 18:05:45 +01001404 EF_PSLOCI(),
Harald Welte509ecf82023-10-18 23:32:57 +02001405 EF_ADN('6f3b', None, 'EF.FDN', desc='Fixed Dialling Numbers', service=[2, 89], ext=2),
Harald Welte6169c722022-02-12 09:05:15 +01001406 EF_SMS('6f3c', None, service=10),
1407 EF_MSISDN(service=21),
1408 EF_SMSP(service=12),
1409 EF_SMSS(service=10),
Harald Welte509ecf82023-10-18 23:32:57 +02001410 EF_ADN('6f49', None, 'EF.SDN', desc='Service Dialling Numbers', service=[4, 89], ext=3),
1411 EF_EXT('6f4b', None, 'EF.EXT2', desc='Extension2 (FDN)', service=3),
1412 EF_EXT('6f4c', None, 'EF.EXT3', desc='Extension2 (SDN)', service=5),
Harald Welte6169c722022-02-12 09:05:15 +01001413 EF_SMSR(service=11),
1414 EF_ICI(service=9),
1415 EF_OCI(service=8),
1416 EF_ICT(service=9),
Harald Welte509ecf82023-10-18 23:32:57 +02001417 EF_ICT('6f83', None, 'EF.OCT', desc='Outgoing Call Timer', service=8),
1418 EF_EXT('6f4e', None, 'EF.EXT5', desc='Extension5 (ICI/OCI/MSISDN)', service=44),
Harald Welte6169c722022-02-12 09:05:15 +01001419 EF_CCP2(service=14),
1420 EF_eMLPP(service=24),
1421 EF_AAeM(service=25),
Harald Weltec91085e2022-02-10 18:05:45 +01001422 # EF_Hiddenkey
Harald Welte509ecf82023-10-18 23:32:57 +02001423 EF_ADN('6f4d', None, 'EF.BDN', desc='Barred Dialling Numbers', service=6, ext=4),
1424 EF_EXT('6f55', None, 'EF.EXT4', desc='Extension4 (BDN/SSC)', service=7),
Harald Welte6169c722022-02-12 09:05:15 +01001425 EF_CMI(service=6),
Harald Welte6ca2fa72022-02-12 16:29:31 +01001426 EF_EST(service=[2, 6, 34, 35]),
Harald Welte6169c722022-02-12 09:05:15 +01001427 EF_ACL(service=35),
1428 EF_DCK(service=36),
1429 EF_CNL(service=37),
Harald Weltec91085e2022-02-10 18:05:45 +01001430 EF_START_HFN(),
1431 EF_THRESHOLD(),
Harald Welte509ecf82023-10-18 23:32:57 +02001432 EF_xPLMNwAcT('6f61', 0x11, 'EF.OPLMNwAcT', desc='User controlled PLMN Selector with Access Technology', service=42),
1433 EF_xPLMNwAcT('6f62', 0x13, 'EF.HPLMNwAcT', desc='HPLMN Selector with Access Technology', service=43),
Harald Weltec91085e2022-02-10 18:05:45 +01001434 EF_ARR('6f06', 0x17),
Harald Welte363edd92022-07-17 22:24:03 +02001435 EF_RPLMNAcT(),
Harald Welte509ecf82023-10-18 23:32:57 +02001436 TransparentEF('6fc4', None, 'EF.NETPAR', desc='Network Parameters'),
Harald Welte6169c722022-02-12 09:05:15 +01001437 EF_PNN('6fc5', 0x19, service=45),
1438 EF_OPL(service=46),
Harald Welte509ecf82023-10-18 23:32:57 +02001439 EF_ADN('6fc7', None, 'EF.MBDN', desc='Mailbox Dialling Numbers', service=47, ext=6),
1440 EF_EXT('6fc8', None, 'EF.EXT6', desc='Extension6 (MBDN)'),
Harald Welte6169c722022-02-12 09:05:15 +01001441 EF_MBI(service=47),
1442 EF_MWIS(service=48),
Harald Welte509ecf82023-10-18 23:32:57 +02001443 EF_ADN('6fcb', None, 'EF.CFIS', desc='Call Forwarding Indication Status', service=49, ext=7),
1444 EF_EXT('6fcc', None, 'EF.EXT7', desc='Extension7 (CFIS)'),
1445 TransparentEF('6fcd', None, 'EF.SPDI', desc='Service Provider Display Information', service=51),
Harald Welte6169c722022-02-12 09:05:15 +01001446 EF_MMSN(service=52),
Harald Welte509ecf82023-10-18 23:32:57 +02001447 EF_EXT('6fcf', None, 'EF.EXT8', desc='Extension8 (MMSN)', service=53),
Harald Welte6169c722022-02-12 09:05:15 +01001448 EF_MMSICP(service=52),
1449 EF_MMSUP(service=52),
1450 EF_MMSUCP(service=(52, 55)),
Harald Welte04bd5142023-05-24 15:23:53 +02001451 EF_NIA(service=56, fid='6fd3'),
Harald Welte6169c722022-02-12 09:05:15 +01001452 EF_VGCS(service=57),
1453 EF_VGCSS(service=57),
Harald Welte509ecf82023-10-18 23:32:57 +02001454 EF_VGCS('6fb3', None, 'EF.VBS', desc='Voice Broadcast Service', service=58),
1455 EF_VGCSS('6fb4', None, 'EF.VBSS', desc='Voice Broadcast Service Status', service=58),
Harald Welte6169c722022-02-12 09:05:15 +01001456 EF_VGCSCA(service=64),
Harald Welte509ecf82023-10-18 23:32:57 +02001457 EF_VGCSCA('6fd5', None, 'EF.VBCSCA', desc='Voice Broadcast Service Ciphering Algorithm', service=65),
Harald Welte6169c722022-02-12 09:05:15 +01001458 EF_GBABP(service=68),
1459 EF_MSK(service=69),
1460 EF_MUK(service=69),
1461 EF_GBANL(service=68),
Harald Welte509ecf82023-10-18 23:32:57 +02001462 EF_PLMNsel('6fd9', 0x1d, 'EF.EHPLMN', desc='Equivalent HPLMN', size=(12, None), service=71),
Harald Welte6169c722022-02-12 09:05:15 +01001463 EF_EHPLMNPI(service=(71, 73)),
1464 # EF_LRPLMNSI ('6fdc', service=74)
1465 EF_NAFKCA(service=(68, 76)),
Harald Welte509ecf82023-10-18 23:32:57 +02001466 TransparentEF('6fde', None, 'EF.SPNI', desc='Service Provider Name Icon', service=78),
1467 LinFixedEF('6fdf', None, 'EF.PNNI', desc='PLMN Network Name Icon', service=79),
Harald Welte6169c722022-02-12 09:05:15 +01001468 EF_NCP_IP(service=80),
Harald Welte509ecf82023-10-18 23:32:57 +02001469 EF_EPSLOCI('6fe3', 0x1e, 'EF.EPSLOCI', desc='EPS location information', service=85),
Harald Welte6169c722022-02-12 09:05:15 +01001470 EF_EPSNSC(service=85),
Harald Welte509ecf82023-10-18 23:32:57 +02001471 TransparentEF('6fe6', None, 'EF.UFC', desc='USAT Facility Control', size=(1, 16)),
1472 TransparentEF('6fe8', None, 'EF.NASCONFIG', desc='Non Access Stratum Configuration', service=96),
Harald Welte6169c722022-02-12 09:05:15 +01001473 # UICC IARI (only in cards that have no ISIM) service=95
1474 EF_PWS(service=97),
Harald Welte509ecf82023-10-18 23:32:57 +02001475 LinFixedEF('6fed', None, 'EF.FDNURI', desc='Fixed Dialling Numbers URI', service=(2, 99)),
1476 LinFixedEF('6fee', None, 'EF.BDNURI', desc='Barred Dialling Numbers URI', service=(6, 99)),
1477 LinFixedEF('6fef', None, 'EF.SDNURI', desc='Service Dialling Numbers URI', service=(4, 99)),
Harald Welte6169c722022-02-12 09:05:15 +01001478 # EF_IWL (IMEI(SV) White List)
Harald Weltec91085e2022-02-10 18:05:45 +01001479 EF_IPS(),
Harald Welte6169c722022-02-12 09:05:15 +01001480 EF_ePDGId(service=(106, 107)),
Harald Weltec91085e2022-02-10 18:05:45 +01001481 # FIXME: from EF_ePDGSelection onwards
Harald Welte6169c722022-02-12 09:05:15 +01001482 EF_FromPreferred(service=114),
Harald Weltefc67de22023-05-23 20:29:49 +02001483 EF_eAKA(),
Harald Welte6169c722022-02-12 09:05:15 +01001484 # FIXME: DF_SoLSA service=23
Harald Weltede4c14c2022-07-16 11:53:59 +02001485 DF_PHONEBOOK(),
Harald Welted90ceb82022-07-17 22:10:58 +02001486 DF_GSM_ACCESS(),
Harald Welte6169c722022-02-12 09:05:15 +01001487 DF_WLAN(service=[59, 60, 61, 62, 63, 66, 81, 82, 83, 84, 88]),
1488 DF_HNB(service=[86, 90]),
1489 DF_ProSe(service=101),
1490 # FIXME: DF_ACDC service=108
1491 # FIXME: DF_TV service=116
1492 DF_USIM_5GS(service=[122, 123, 124, 125, 126, 127, 129, 130]),
Harald Weltefc67de22023-05-23 20:29:49 +02001493 DF_SNPN(service=[143,146]),
1494 DF_5G_ProSe(service=139),
Harald Welte2bee70c2023-05-25 09:14:28 +02001495 DF_SAIP(),
Harald Weltec91085e2022-02-10 18:05:45 +01001496 ]
Harald Welteb2edd142021-01-08 23:29:35 +01001497 self.add_files(files)
1498
1499 def decode_select_response(self, data_hex):
Philipp Maier5998a3a2021-11-16 15:16:39 +01001500 return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex)
Harald Welteb2edd142021-01-08 23:29:35 +01001501
Harald Welte15fae982021-04-10 10:22:27 +02001502 @with_default_category('Application-Specific Commands')
1503 class AddlShellCommands(CommandSet):
1504 def __init__(self):
1505 super().__init__()
1506
1507 authenticate_parser = argparse.ArgumentParser()
1508 authenticate_parser.add_argument('rand', help='Random challenge')
1509 authenticate_parser.add_argument('autn', help='Authentication Nonce')
1510 #authenticate_parser.add_argument('--context', help='Authentication context', default='3G')
Harald Weltec91085e2022-02-10 18:05:45 +01001511
Harald Welte15fae982021-04-10 10:22:27 +02001512 @cmd2.with_argparser(authenticate_parser)
1513 def do_authenticate(self, opts):
1514 """Perform Authentication and Key Agreement (AKA)."""
Harald Welte46255122023-10-21 23:40:42 +02001515 (data, sw) = self._cmd.lchan.scc.authenticate(opts.rand, opts.autn)
Harald Welte15fae982021-04-10 10:22:27 +02001516 self._cmd.poutput_json(data)
1517
Harald Welte12af7932022-02-15 16:39:08 +01001518 term_prof_parser = argparse.ArgumentParser()
1519 term_prof_parser.add_argument('PROFILE', help='Hexstring of encoded terminal profile')
1520
1521 @cmd2.with_argparser(term_prof_parser)
Harald Welte51b3abb2022-07-30 16:30:33 +02001522 def do_terminal_profile(self, opts):
Harald Welte12af7932022-02-15 16:39:08 +01001523 """Send a TERMINAL PROFILE command to the card.
1524 This is used to inform the card about which optional
1525 features the terminal (modem/phone) supports, particularly
1526 in the context of SIM Toolkit, Proactive SIM and OTA. You
1527 must specify a hex-string with the encoded terminal profile
1528 you want to send to the card."""
Harald Welte46255122023-10-21 23:40:42 +02001529 (data, sw) = self._cmd.lchan.scc.terminal_profile(opts.PROFILE)
Harald Welte846a8982021-10-08 15:47:16 +02001530 self._cmd.poutput('SW: %s, data: %s' % (sw, data))
Harald Welte15fae982021-04-10 10:22:27 +02001531
Harald Welte12af7932022-02-15 16:39:08 +01001532 envelope_parser = argparse.ArgumentParser()
1533 envelope_parser.add_argument('PAYLOAD', help='Hexstring of encoded payload to ENVELOPE')
1534
1535 @cmd2.with_argparser(envelope_parser)
Harald Welte51b3abb2022-07-30 16:30:33 +02001536 def do_envelope(self, opts):
Harald Welte12af7932022-02-15 16:39:08 +01001537 """Send an ENVELOPE command to the card. This is how a
1538 variety of information is communicated from the terminal
1539 (modem/phone) to the card, particularly in the context of
1540 SIM Toolkit, Proactive SIM and OTA."""
Harald Welte46255122023-10-21 23:40:42 +02001541 (data, sw) = self._cmd.lchan.scc.envelope(opts.PAYLOAD)
Harald Welte7cb94e42021-10-08 15:47:57 +02001542 self._cmd.poutput('SW: %s, data: %s' % (sw, data))
1543
Harald Welte12af7932022-02-15 16:39:08 +01001544 envelope_sms_parser = argparse.ArgumentParser()
1545 envelope_sms_parser.add_argument('TPDU', help='Hexstring of encoded SMS TPDU')
1546
1547 @cmd2.with_argparser(envelope_sms_parser)
Harald Welte51b3abb2022-07-30 16:30:33 +02001548 def do_envelope_sms(self, opts):
Harald Welte12af7932022-02-15 16:39:08 +01001549 """Send an ENVELOPE(SMS-PP-Download) command to the card.
1550 This emulates a terminal (modem/phone) having received a SMS
1551 with a PID of 'SMS for the SIM card'. You can use this
1552 command in the context of testing OTA related features
Philipp Maier4e5aa302023-06-06 19:22:19 +02001553 without a modem/phone or a cellular network."""
Harald Welte7cb94e42021-10-08 15:47:57 +02001554 tpdu_ie = SMS_TPDU()
Harald Welte51b3abb2022-07-30 16:30:33 +02001555 tpdu_ie.from_bytes(h2b(opts.TPDU))
Harald Weltec91085e2022-02-10 18:05:45 +01001556 dev_ids = DeviceIdentities(
1557 decoded={'source_dev_id': 'network', 'dest_dev_id': 'uicc'})
Harald Welte7cb94e42021-10-08 15:47:57 +02001558 sms_dl = SMSPPDownload(children=[dev_ids, tpdu_ie])
Harald Welte46255122023-10-21 23:40:42 +02001559 (data, sw) = self._cmd.lchan.scc.envelope(b2h(sms_dl.to_tlv()))
Harald Welte7cb94e42021-10-08 15:47:57 +02001560 self._cmd.poutput('SW: %s, data: %s' % (sw, data))
1561
Harald Welte7ec82232023-06-06 18:15:52 +02001562 get_id_parser = argparse.ArgumentParser()
1563 get_id_parser.add_argument("--nswo-context", action='store_true')
1564
1565 @cmd2.with_argparser(get_id_parser)
1566 def do_get_identity(self, opts):
1567 """Send a GET IDENTITY command to the card. This is part of the
1568 procedure for "SUCI calculation performed on USIM" supported
1569 by USIM with support for both EF.UST service 124 and 125."""
1570 context = 0x01 # SUCI
1571 if opts.nswo_context:
1572 context = 0x02 # SUCI 5G NSWO
Harald Welte46255122023-10-21 23:40:42 +02001573 (data, sw) = self._cmd.lchan.scc.get_identity(context)
Harald Welte7ec82232023-06-06 18:15:52 +02001574 do = SUCI_TlvDataObject()
1575 do.from_tlv(h2b(data))
1576 do_d = do.to_dict()
1577 self._cmd.poutput('SUCI TLV Data Object: %s' % do_d['suci__tlv_data_object'])
1578
Harald Welte15fae982021-04-10 10:22:27 +02001579
Harald Welteb2edd142021-01-08 23:29:35 +01001580# TS 31.102 Section 7.3
1581sw_usim = {
1582 'Security management': {
1583 '9862': 'Authentication error, incorrect MAC',
1584 '9864': 'Authentication error, security context not supported',
1585 '9865': 'Key freshness failure',
1586 '9866': 'Authentication error, no memory space available',
1587 '9867': 'Authentication error, no memory space available in EF MUK',
1588 }
1589}
1590
Harald Weltec91085e2022-02-10 18:05:45 +01001591
Philipp Maier57f65ee2021-10-18 14:09:02 +02001592class CardApplicationUSIM(CardApplication):
1593 def __init__(self):
Harald Weltec91085e2022-02-10 18:05:45 +01001594 super().__init__('USIM', adf=ADF_USIM(), sw=sw_usim)