blob: 0614a0c926fb19b2780917a78e1637b8c0434e6a [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
Harald Welte53762512023-12-21 20:16:17 +010034from pySim.ts_51_011 import EF_CBMID, EF_CBMIR, EF_ADN, EF_CFIS, EF_SMS, EF_MSISDN, EF_SMSP, EF_SMSS
Harald Weltec91085e2022-02-10 18:05:45 +010035from 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 Welte91842b42024-01-11 22:03:37 +010042from pySim.utils import is_hexstr
Harald Weltef56b6b22022-07-30 16:36:06 +020043from pySim.cat import SMS_TPDU, DeviceIdentities, SMSPPDownload
Harald Weltec91085e2022-02-10 18:05:45 +010044from construct import Optional as COptional
45from construct import *
46from typing import Tuple
47from struct import unpack, pack
48import enum
Supreeth Herle475dcaa2020-03-20 18:57:39 +010049EF_UST_map = {
Harald Weltec91085e2022-02-10 18:05:45 +010050 1: 'Local Phone Book',
51 2: 'Fixed Dialling Numbers (FDN)',
52 3: 'Extension 2',
53 4: 'Service Dialling Numbers (SDN)',
54 5: 'Extension3',
55 6: 'Barred Dialling Numbers (BDN)',
56 7: 'Extension4',
57 8: 'Outgoing Call Information (OCI and OCT)',
58 9: 'Incoming Call Information (ICI and ICT)',
59 10: 'Short Message Storage (SMS)',
60 11: 'Short Message Status Reports (SMSR)',
61 12: 'Short Message Service Parameters (SMSP)',
62 13: 'Advice of Charge (AoC)',
63 14: 'Capability Configuration Parameters 2 (CCP2)',
64 15: 'Cell Broadcast Message Identifier',
65 16: 'Cell Broadcast Message Identifier Ranges',
66 17: 'Group Identifier Level 1',
67 18: 'Group Identifier Level 2',
68 19: 'Service Provider Name',
69 20: 'User controlled PLMN selector with Access Technology',
70 21: 'MSISDN',
71 22: 'Image (IMG)',
72 23: 'Support of Localised Service Areas (SoLSA)',
73 24: 'Enhanced Multi-Level Precedence and Pre-emption Service',
74 25: 'Automatic Answer for eMLPP',
75 26: 'RFU',
76 27: 'GSM Access',
77 28: 'Data download via SMS-PP',
78 29: 'Data download via SMS-CB',
79 30: 'Call Control by USIM',
80 31: 'MO-SMS Control by USIM',
81 32: 'RUN AT COMMAND command',
82 33: 'shall be set to 1',
83 34: 'Enabled Services Table',
84 35: 'APN Control List (ACL)',
85 36: 'Depersonalisation Control Keys',
86 37: 'Co-operative Network List',
87 38: 'GSM security context',
88 39: 'CPBCCH Information',
89 40: 'Investigation Scan',
90 41: 'MexE',
91 42: 'Operator controlled PLMN selector with Access Technology',
92 43: 'HPLMN selector with Access Technology',
93 44: 'Extension 5',
94 45: 'PLMN Network Name',
95 46: 'Operator PLMN List',
96 47: 'Mailbox Dialling Numbers',
97 48: 'Message Waiting Indication Status',
98 49: 'Call Forwarding Indication Status',
99 50: 'Reserved and shall be ignored',
100 51: 'Service Provider Display Information',
101 52: 'Multimedia Messaging Service (MMS)',
102 53: 'Extension 8',
103 54: 'Call control on GPRS by USIM',
104 55: 'MMS User Connectivity Parameters',
105 56: 'Network\'s indication of alerting in the MS (NIA)',
106 57: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)',
107 58: 'VBS Group Identifier List (EFVBS and EFVBSS)',
108 59: 'Pseudonym',
109 60: 'User Controlled PLMN selector for I-WLAN access',
110 61: 'Operator Controlled PLMN selector for I-WLAN access',
111 62: 'User controlled WSID list',
112 63: 'Operator controlled WSID list',
113 64: 'VGCS security',
114 65: 'VBS security',
115 66: 'WLAN Reauthentication Identity',
116 67: 'Multimedia Messages Storage',
117 68: 'Generic Bootstrapping Architecture (GBA)',
118 69: 'MBMS security',
119 70: 'Data download via USSD and USSD application mode',
120 71: 'Equivalent HPLMN',
121 72: 'Additional TERMINAL PROFILE after UICC activation',
122 73: 'Equivalent HPLMN Presentation Indication',
123 74: 'Last RPLMN Selection Indication',
124 75: 'OMA BCAST Smart Card Profile',
125 76: 'GBA-based Local Key Establishment Mechanism',
126 77: 'Terminal Applications',
127 78: 'Service Provider Name Icon',
128 79: 'PLMN Network Name Icon',
129 80: 'Connectivity Parameters for USIM IP connections',
130 81: 'Home I-WLAN Specific Identifier List',
131 82: 'I-WLAN Equivalent HPLMN Presentation Indication',
132 83: 'I-WLAN HPLMN Priority Indication',
133 84: 'I-WLAN Last Registered PLMN',
134 85: 'EPS Mobility Management Information',
135 86: 'Allowed CSG Lists and corresponding indications',
136 87: 'Call control on EPS PDN connection by USIM',
137 88: 'HPLMN Direct Access',
138 89: 'eCall Data',
139 90: 'Operator CSG Lists and corresponding indications',
140 91: 'Support for SM-over-IP',
141 92: 'Support of CSG Display Control',
142 93: 'Communication Control for IMS by USIM',
143 94: 'Extended Terminal Applications',
144 95: 'Support of UICC access to IMS',
145 96: 'Non-Access Stratum configuration by USIM',
146 97: 'PWS configuration by USIM',
147 98: 'RFU',
148 99: 'URI support by UICC',
149 100: 'Extended EARFCN support',
150 101: 'ProSe',
151 102: 'USAT Application Pairing',
152 103: 'Media Type support',
153 104: 'IMS call disconnection cause',
154 105: 'URI support for MO SHORT MESSAGE CONTROL',
155 106: 'ePDG configuration Information support',
156 107: 'ePDG configuration Information configured',
157 108: 'ACDC support',
158 109: 'MCPTT',
159 110: 'ePDG configuration Information for Emergency Service support',
160 111: 'ePDG configuration Information for Emergency Service configured',
161 112: 'eCall Data over IMS',
162 113: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [12]',
163 114: 'From Preferred',
164 115: 'IMS configuration data',
165 116: 'TV configuration',
166 117: '3GPP PS Data Off',
167 118: '3GPP PS Data Off Service List',
168 119: 'V2X',
169 120: 'XCAP Configuration Data',
170 121: 'EARFCN list for MTC/NB-IOT UEs',
171 122: '5GS Mobility Management Information',
172 123: '5G Security Parameters',
173 124: 'Subscription identifier privacy support',
174 125: 'SUCI calculation by the USIM',
175 126: 'UAC Access Identities support',
176 127: 'Expect control plane-based Steering of Roaming information during initial registration in VPLMN',
177 128: 'Call control on PDU Session by USIM',
178 129: '5GS Operator PLMN List',
179 130: 'Support for SUPI of type NSI or GLI or GCI',
180 131: '3GPP PS Data Off separate Home and Roaming lists',
181 132: 'Support for URSP by USIM',
182 133: '5G Security Parameters extended',
183 134: 'MuD and MiD configuration data',
Harald Weltefc67de22023-05-23 20:29:49 +0200184 135: 'Support for Trusted non-3GPP access networks by USIM',
185 136: 'Support for multiple records of NAS security context storage for multiple registration',
186 137: 'Pre-configured CAG information list',
187 138: 'SOR-CMCI storage in USIM',
188 139: '5G ProSe',
189 140: 'Storage of disaster roaming information in USIM',
190 141: 'Pre-configured eDRX parameters',
191 142: '5G NSWO support',
192 143: 'PWS configuration for SNPN in USIM',
193 144: 'Multiplier Coefficient for Higher Priority PLMN search via NG-RAN satellite access',
194 145: 'K_AUSF derivation configuration',
195 146: 'Network Identifier for SNPN (NID)',
196}
197
198EF_5G_PROSE_ST_map = {
199 1: '5G ProSe configuration data for direct discovery',
200 2: '5G ProSe configuration data for direct communication',
201 3: '5G ProSe configuration data for UE-to-network relay UE',
202 4: '5G ProSe configuration data for remote UE',
203 5: '5G ProSe configuration data for usage information reporting',
Sebastian Viviani0dc8f692020-05-29 00:14:55 +0100204}
205
Harald Weltee8947492022-02-10 10:33:20 +0100206# Mapping between USIM Enbled Service Number and its description
207EF_EST_map = {
208 1: 'Fixed Dialling Numbers (FDN)',
209 2: 'Barred Dialling Numbers (BDN)',
210 3: 'APN Control List (ACL)'
211}
212
Harald Welte21caf322022-07-16 14:06:46 +0200213# 3gPP TS 31.102 Section 7.5.2.1
214class SUCI_TlvDataObject(BER_TLV_IE, tag=0xA1):
215 _construct = HexAdapter(GreedyBytes)
216
Harald Welteb2edd142021-01-08 23:29:35 +0100217######################################################################
218# ADF.USIM
219######################################################################
220
Harald Welteb2edd142021-01-08 23:29:35 +0100221
Harald Weltef12979d2021-05-29 21:47:13 +0200222# 3GPP TS 31.102 Section 4.4.11.4 (EF_5GS3GPPNSC)
223class EF_5GS3GPPNSC(LinFixedEF):
224 class NgKSI(BER_TLV_IE, tag=0x80):
225 _construct = Int8ub
226
227 class K_AMF(BER_TLV_IE, tag=0x81):
228 _construct = HexAdapter(Bytes(32))
229
230 class UplinkNASCount(BER_TLV_IE, tag=0x82):
231 _construct = Int32ub
232
233 class DownlinkNASCount(BER_TLV_IE, tag=0x83):
234 _construct = Int32ub
235
236 class IdsOfSelectedNasAlgos(BER_TLV_IE, tag=0x84):
237 # 3GPP TS 24.501 Section 9.11.3.34
238 _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
239
240 class IdsOfSelectedEpsAlgos(BER_TLV_IE, tag=0x85):
241 # 3GPP TS 24.301 Section 9.9.3.23
242 _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble)
243
244 class FiveGSNasSecurityContext(BER_TLV_IE, tag=0xA0,
Harald Weltec91085e2022-02-10 18:05:45 +0100245 nested=[NgKSI, K_AMF, UplinkNASCount,
246 DownlinkNASCount, IdsOfSelectedNasAlgos,
247 IdsOfSelectedEpsAlgos]):
Harald Weltef12979d2021-05-29 21:47:13 +0200248 pass
249
Harald Welte99e4cc02022-07-21 15:25:47 +0200250 def __init__(self, fid="4f03", sfid=0x03, name='EF.5GS3GPPNSC', rec_len=(57, None),
Harald Welte419bb492022-02-12 21:39:35 +0100251 desc='5GS 3GPP Access NAS Security Context', **kwargs):
252 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte65516272022-02-10 17:51:05 +0100253 self._tlv = EF_5GS3GPPNSC.FiveGSNasSecurityContext
Harald Weltef12979d2021-05-29 21:47:13 +0200254
255# 3GPP TS 31.102 Section 4.4.11.6
256class EF_5GAUTHKEYS(TransparentEF):
257 class K_AUSF(BER_TLV_IE, tag=0x80):
258 _construct = HexAdapter(GreedyBytes)
259
260 class K_SEAF(BER_TLV_IE, tag=0x81):
261 _construct = HexAdapter(GreedyBytes)
262
263 class FiveGAuthKeys(TLV_IE_Collection, nested=[K_AUSF, K_SEAF]):
264 pass
265
Harald Welte13edf302022-07-21 15:19:23 +0200266 def __init__(self, fid='4f05', sfid=0x05, name='EF.5GAUTHKEYS', size=(68, None),
Harald Welte419bb492022-02-12 21:39:35 +0100267 desc='5G authentication keys', **kwargs):
268 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte65516272022-02-10 17:51:05 +0100269 self._tlv = EF_5GAUTHKEYS.FiveGAuthKeys
Harald Weltef12979d2021-05-29 21:47:13 +0200270
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200271# TS 31.102 4.4.11.8
272class EF_SUCI_Calc_Info(TransparentEF):
Harald Welte324175f2023-12-21 20:25:30 +0100273 _test_de_encode = [
274 ( 'A00401010000A14A80010A81204E858C4D49D1343E6181284C47CA721730C98742CB7C6182D2E8126E08088D3680010B8120D1BC365F4997D17CE4374E72181431CBFEBA9E1B98D7618F79D48561B144672A',
275 {"prot_scheme_id_list": [{"priority": 0, "identifier": 1, "key_index": 1}, {"priority": 1,
276 "identifier": 0,
277 "key_index": 0}],
278 "hnet_pubkey_list": [{"hnet_pubkey_identifier": 10, "hnet_pubkey":
279 "4e858c4d49d1343e6181284c47ca721730c98742cb7c6182d2e8126e08088d36"},
280 {"hnet_pubkey_identifier": 11, "hnet_pubkey":
281 "d1bc365f4997d17ce4374e72181431cbfeba9e1b98d7618f79d48561b144672a"}]} ),
282 ]
Harald Welte19d2b932023-12-21 21:14:46 +0100283 # 3GPP TS 31.102 Section 4.4.11.8
284 class ProtSchemeIdList(BER_TLV_IE, tag=0xa0):
285 # FIXME: 3GPP TS 24.501 Protection Scheme Identifier
286 # repeated sequence of (id, index) tuples
287 _construct = GreedyRange(
288 Struct('identifier'/Enum(Byte, null=0, A=1, B=2), 'key_index'/Int8ub))
289
Harald Welte19d2b932023-12-21 21:14:46 +0100290 class HnetPubkeyIdentifier(BER_TLV_IE, tag=0x80):
291 # 3GPP TS 24.501 / 3GPP TS 23.003
292 _construct = Int8ub
293
Harald Welte19d2b932023-12-21 21:14:46 +0100294 class HnetPubkey(BER_TLV_IE, tag=0x81):
Harald Weltee13403b2023-12-21 22:02:34 +0100295 # contents according to RFC 7748 / RFC 5480
Harald Welte19d2b932023-12-21 21:14:46 +0100296 _construct = HexAdapter(GreedyBytes)
297
Harald Welte19d2b932023-12-21 21:14:46 +0100298 class HnetPubkeyList(BER_TLV_IE, tag=0xa1, nested=[HnetPubkeyIdentifier, HnetPubkey]):
299 pass
300
301 # 3GPP TS 31.102 Section 4.4.11.6
302 class SUCI_CalcInfo(TLV_IE_Collection, nested=[ProtSchemeIdList, HnetPubkeyList]):
303 pass
304
Harald Welte13edf302022-07-21 15:19:23 +0200305 def __init__(self, fid="4f07", sfid=0x07, name='EF.SUCI_Calc_Info', size=(2, None),
Harald Welte419bb492022-02-12 21:39:35 +0100306 desc='SUCI Calc Info', **kwargs):
307 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200308
309 def _encode_prot_scheme_id_list(self, in_list):
310 out_bytes = [0xa0]
Harald Weltec91085e2022-02-10 18:05:45 +0100311 out_bytes.append(len(in_list)*2) # two byte per entry
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200312
313 # position in list determines priority; high-priority items (low index) come first
314 for scheme in sorted(in_list, key=lambda item: item["priority"]):
315 out_bytes.append(scheme["identifier"])
316 out_bytes.append(scheme["key_index"])
317
318 return out_bytes
319
Harald Weltee13403b2023-12-21 22:02:34 +0100320 @staticmethod
321 def _compact_pubkey_list(l: List[dict]) -> List[dict]:
322 """conversion method to generate list of {hnet_pubkey_identifier, hnet_pubkey} dicts
323 from flat [{hnet_pubkey_identifier: }, {net_pubkey: }, ...] list"""
324 out = []
325 while len(l):
326 a = l.pop(0)
327 b = l.pop(0)
328 z = {**a, **b}
329 out.append(z)
330 return out
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200331
Harald Weltee13403b2023-12-21 22:02:34 +0100332 @staticmethod
333 def _expand_pubkey_list(l: List[dict]) -> List[dict]:
334 """conversion method to generate flat [{hnet_pubkey_identifier: }, {net_pubkey: }, ...] list
335 from compacted list of {hnet_pubkey_identifier, hnet_pubkey} dicts"""
336 out = []
337 for d in l:
338 for k, v in d.items():
339 out.append({k: v})
340 return out
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200341
342 def _encode_hex(self, in_json):
Harald Weltec91085e2022-02-10 18:05:45 +0100343 out_bytes = self._encode_prot_scheme_id_list(
344 in_json['prot_scheme_id_list'])
Harald Weltee13403b2023-12-21 22:02:34 +0100345 d = self._expand_pubkey_list(in_json['hnet_pubkey_list'])
346 hpkl = EF_SUCI_Calc_Info.HnetPubkeyList()
347 hpkl.from_dict({'hnet_pubkey_list': d})
348 out_bytes += hpkl.to_tlv()
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200349 return "".join(["%02X" % i for i in out_bytes])
350
351 def _decode_prot_scheme_id_list(self, in_bytes):
352 prot_scheme_id_list = []
353 pos = 0
354 # two bytes per entry
355 while pos < len(in_bytes):
356 prot_scheme = {
Harald Weltec91085e2022-02-10 18:05:45 +0100357 'priority': pos//2, # first in list: high priority
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200358 'identifier': in_bytes[pos],
359 'key_index': in_bytes[pos+1]
360 }
361 pos += 2
362 prot_scheme_id_list.append(prot_scheme)
363 return prot_scheme_id_list
364
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200365 def _decode_bin(self, in_bin):
Vadim Yanitskiy5e41eeb2021-05-02 02:20:33 +0200366 return self._decode_hex(b2h(in_bin))
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200367
368 def _decode_hex(self, in_hex):
369 in_bytes = h2b(in_hex)
370 pos = 0
371
372 if in_bytes[pos] != 0xa0:
373 print("missing Protection Scheme Identifier List data object tag")
374 return {}
375 pos += 1
376
Harald Weltec91085e2022-02-10 18:05:45 +0100377 prot_scheme_id_list_len = in_bytes[pos] # TODO maybe more than 1 byte
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200378 pos += 1
379 # decode Protection Scheme Identifier List data object
Harald Weltec91085e2022-02-10 18:05:45 +0100380 prot_scheme_id_list = self._decode_prot_scheme_id_list(
381 in_bytes[pos:pos+prot_scheme_id_list_len])
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200382 pos += prot_scheme_id_list_len
383
384 # remaining data holds Home Network Public Key Data Object
Harald Weltee13403b2023-12-21 22:02:34 +0100385 hpkl = EF_SUCI_Calc_Info.HnetPubkeyList()
386 hpkl.from_tlv(in_bytes[pos:])
387 hnet_pubkey_list = self._compact_pubkey_list(hpkl.to_dict()['hnet_pubkey_list'])
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200388
389 return {
390 'prot_scheme_id_list': prot_scheme_id_list,
391 'hnet_pubkey_list': hnet_pubkey_list
392 }
393
394 def _encode_bin(self, in_json):
395 return h2b(self._encode_hex(in_json))
396
Harald Weltec91085e2022-02-10 18:05:45 +0100397
Harald Welteb2edd142021-01-08 23:29:35 +0100398class EF_LI(TransRecEF):
Harald Welte13edf302022-07-21 15:19:23 +0200399 def __init__(self, fid='6f05', sfid=None, name='EF.LI', size=(2, None), rec_len=2,
Harald Welteb2edd142021-01-08 23:29:35 +0100400 desc='Language Indication'):
401 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
Harald Weltec91085e2022-02-10 18:05:45 +0100402
Harald Weltef6b37af2023-01-24 15:42:26 +0100403 def _decode_record_bin(self, in_bin, **kwargs):
Harald Welteb2edd142021-01-08 23:29:35 +0100404 if in_bin == b'\xff\xff':
405 return None
406 else:
407 # officially this is 7-bit GSM alphabet with one padding bit in each byte
408 return in_bin.decode('ascii')
Harald Weltec91085e2022-02-10 18:05:45 +0100409
Harald Weltef6b37af2023-01-24 15:42:26 +0100410 def _encode_record_bin(self, in_json, **kwargs):
Harald Welteb2edd142021-01-08 23:29:35 +0100411 if in_json == None:
412 return b'\xff\xff'
413 else:
414 # officially this is 7-bit GSM alphabet with one padding bit in each byte
415 return in_json.encode('ascii')
416
Harald Weltec91085e2022-02-10 18:05:45 +0100417
Harald Welteb2edd142021-01-08 23:29:35 +0100418class EF_Keys(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200419 def __init__(self, fid='6f08', sfid=0x08, name='EF.Keys', size=(33, 33),
Harald Welteb2edd142021-01-08 23:29:35 +0100420 desc='Ciphering and Integrity Keys'):
421 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
Harald Weltec91085e2022-02-10 18:05:45 +0100422 self._construct = Struct(
423 'ksi'/Int8ub, 'ck'/HexAdapter(Bytes(16)), 'ik'/HexAdapter(Bytes(16)))
Harald Welteb2edd142021-01-08 23:29:35 +0100424
Harald Welte14105dc2021-05-31 08:48:51 +0200425# TS 31.102 Section 4.2.6
426class EF_HPPLMN(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100427 _test_de_encode = [ ( '05', 5 ) ]
Harald Welte13edf302022-07-21 15:19:23 +0200428 def __init__(self, fid='6f31', sfid=0x12, name='EF.HPPLMN', size=(1, 1),
Harald Welte14105dc2021-05-31 08:48:51 +0200429 desc='Higher Priority PLMN search period'):
430 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
431 self._construct = Int8ub
432
Harald Welte6ca2fa72022-02-12 16:29:31 +0100433class EF_UST(EF_UServiceTable):
434 def __init__(self, **kwargs):
Harald Welte13edf302022-07-21 15:19:23 +0200435 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 +0100436 # add those commands to the general commands of a TransparentEF
437 self.shell_commands += [self.AddlShellCommands()]
438
Harald Welteb2edd142021-01-08 23:29:35 +0100439 @with_default_category('File-Specific Commands')
440 class AddlShellCommands(CommandSet):
441 def __init__(self):
442 super().__init__()
443
444 def do_ust_service_activate(self, arg):
445 """Activate a service within EF.UST"""
Alexander Couzens6c5c3f82023-07-28 05:13:06 +0200446 selected_file = self._cmd.lchan.selected_file
447 selected_file.ust_update(self._cmd, [int(arg)], [])
Harald Welteb2edd142021-01-08 23:29:35 +0100448
449 def do_ust_service_deactivate(self, arg):
450 """Deactivate a service within EF.UST"""
Alexander Couzens6c5c3f82023-07-28 05:13:06 +0200451 selected_file = self._cmd.lchan.selected_file
452 selected_file.ust_update(self._cmd, [], [int(arg)])
Harald Welteb2edd142021-01-08 23:29:35 +0100453
Harald Welte4c5e2312022-02-12 14:37:48 +0100454 def do_ust_service_check(self, arg):
Harald Welte3bb516b2022-02-12 21:53:18 +0100455 """Check consistency between services of this file and files present/activated.
456
457 Many services determine if one or multiple files shall be present/activated or if they shall be
458 absent/deactivated. This performs a consistency check to ensure that no services are activated
459 for files that are not - and vice-versa, no files are activated for services that are not. Error
460 messages are printed for every inconsistency found."""
Harald Weltea6c0f882022-07-17 14:23:17 +0200461 selected_file = self._cmd.lchan.selected_file
Harald Welte82f75c22022-02-12 18:22:28 +0100462 num_problems = selected_file.ust_service_check(self._cmd)
463 # obtain list of currently active services
464 active_services = selected_file.get_active_services(self._cmd)
465 # Service n°46 can only be declared "available" if service n°45 is declared "available"
466 if 46 in active_services and not 45 in active_services:
Harald Weltefa8b8d12022-02-12 18:30:28 +0100467 self._cmd.perror("ERROR: Service 46 available, but it requires Service 45")
Harald Welte82f75c22022-02-12 18:22:28 +0100468 num_problems += 1
469 # Service n°125 shall only be taken into account if Service n°124 is declared "available"
470 if 125 in active_services and not 124 in active_services:
Harald Weltefa8b8d12022-02-12 18:30:28 +0100471 self._cmd.perror("ERROR: Service 125 is ignored as Service 124 not available")
Harald Welte82f75c22022-02-12 18:22:28 +0100472 num_problems += 1
473 # Service n°95, n°99 and n°115 shall not be declared "available" if an ISIM application is present on the UICC
474 non_isim_services = [95, 99, 115]
475 app_names = selected_file.get_mf().get_app_names()
476 if 'ADF.ISIM' in app_names:
477 for s in non_isim_services:
478 if s in active_services:
Harald Weltefa8b8d12022-02-12 18:30:28 +0100479 self._cmd.perror("ERROR: Service %u shall not be available as ISIM application is present" % s)
Harald Welte82f75c22022-02-12 18:22:28 +0100480 num_problems += 1
481 self._cmd.poutput("===> %u service / file inconsistencies detected" % num_problems)
Harald Welte4c5e2312022-02-12 14:37:48 +0100482
483
Harald Welte89e59542021-04-02 21:33:13 +0200484# TS 31.103 Section 4.2.7 - *not* the same as DF.GSM/EF.ECC!
485class EF_ECC(LinFixedEF):
Harald Welte865eea62023-01-27 19:26:12 +0100486 _test_de_encode = [
487 ( '19f1ff01', { "call_code": "911f",
488 "service_category": { "police": True, "ambulance": False, "fire_brigade": False,
489 "marine_guard": False, "mountain_rescue": False,
490 "manual_ecall": False, "automatic_ecall": False } } ),
491 ( '19f3ff02', { "call_code": "913f",
492 "service_category": { "police": False, "ambulance": True, "fire_brigade": False,
493 "marine_guard": False, "mountain_rescue": False,
494 "manual_ecall": False, "automatic_ecall": False } } ),
495 ]
Harald Weltece01f482023-12-28 09:41:35 +0100496 _test_no_pad = True
Harald Welte865eea62023-01-27 19:26:12 +0100497 cc_construct = BcdAdapter(Rpad(Bytes(3)))
Harald Welteff2d86d2022-01-21 15:19:47 +0100498 category_construct = FlagsEnum(Byte, police=1, ambulance=2, fire_brigade=3, marine_guard=4,
499 mountain_rescue=5, manual_ecall=6, automatic_ecall=7)
Harald Welte6e6caa82023-12-27 22:04:50 +0100500 alpha_construct = GsmOrUcs2Adapter(Rpad(GreedyBytes))
Harald Weltec91085e2022-02-10 18:05:45 +0100501
Harald Welte89e59542021-04-02 21:33:13 +0200502 def __init__(self, fid='6fb7', sfid=0x01, name='EF.ECC',
503 desc='Emergency Call Codes'):
Harald Welte99e4cc02022-07-21 15:25:47 +0200504 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(4, 20))
Harald Weltec91085e2022-02-10 18:05:45 +0100505
Harald Weltef6b37af2023-01-24 15:42:26 +0100506 def _decode_record_bin(self, in_bin, **kwargs):
Harald Welteff2d86d2022-01-21 15:19:47 +0100507 # mandatory parts
508 code = in_bin[:3]
509 if code == b'\xff\xff\xff':
510 return None
511 svc_category = in_bin[-1:]
512 ret = {'call_code': parse_construct(EF_ECC.cc_construct, code),
Harald Weltec91085e2022-02-10 18:05:45 +0100513 'service_category': parse_construct(EF_ECC.category_construct, svc_category)}
Harald Welteff2d86d2022-01-21 15:19:47 +0100514 # optional alpha identifier
515 if len(in_bin) > 4:
516 alpha_id = in_bin[3:-1]
517 ret['alpha_id'] = parse_construct(EF_ECC.alpha_construct, alpha_id)
518 return ret
Harald Weltec91085e2022-02-10 18:05:45 +0100519
Harald Weltef6b37af2023-01-24 15:42:26 +0100520 def _encode_record_bin(self, in_json, **kwargs):
Harald Welteff2d86d2022-01-21 15:19:47 +0100521 if in_json is None:
522 return b'\xff\xff\xff\xff'
523 code = EF_ECC.cc_construct.build(in_json['call_code'])
Harald Welte9b9efb62023-01-31 16:40:54 +0100524 svc_category = EF_ECC.category_construct.build(in_json['service_category'])
525 if 'alpha_id' in in_json:
526 alpha_id = EF_ECC.alpha_construct.build(in_json['alpha_id'])
527 # FIXME: alpha_id needs padding up to 'record_length - 4'
528 else:
529 alpha_id = b''
Harald Welteff2d86d2022-01-21 15:19:47 +0100530 return code + alpha_id + svc_category
531
Harald Welte89e59542021-04-02 21:33:13 +0200532
Harald Welte790b2702021-04-11 00:01:35 +0200533# TS 31.102 Section 4.2.17
534class EF_LOCI(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100535 _test_de_encode = [
536 ( '47d1264a62f21037211e00',
Harald Welte842fbdb2023-12-27 17:06:58 +0100537 { "tmsi": "47d1264a", "lai": { "mcc_mnc": "262-01", "lac": "3721" },
Harald Welte865eea62023-01-27 19:26:12 +0100538 "rfu": 30, "lu_status": 0 } ),
Harald Welte324175f2023-12-21 20:25:30 +0100539 ( 'ffffffff62f2200000ff01',
Harald Welte842fbdb2023-12-27 17:06:58 +0100540 {"tmsi": "ffffffff", "lai": {"mcc_mnc": "262-02", "lac": "0000"}, "rfu": 255, "lu_status": 1} ),
Harald Welte865eea62023-01-27 19:26:12 +0100541 ]
Harald Welte13edf302022-07-21 15:19:23 +0200542 def __init__(self, fid='6f7e', sfid=0x0b, name='EF.LOCI', desc='Location information', size=(11, 11)):
Harald Welte790b2702021-04-11 00:01:35 +0200543 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
Harald Welte842fbdb2023-12-27 17:06:58 +0100544 Lai = Struct('mcc_mnc'/PlmnAdapter(Bytes(3)), 'lac'/HexAdapter(Bytes(2)))
Harald Welte3a5afff2022-02-25 15:33:46 +0100545 self._construct = Struct('tmsi'/HexAdapter(Bytes(4)), 'lai'/Lai, 'rfu'/Int8ub, 'lu_status'/Int8ub)
Harald Welte865eea62023-01-27 19:26:12 +0100546
Harald Welte592b32e2021-06-05 11:26:36 +0200547# TS 31.102 Section 4.2.18
548class EF_AD(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100549 _test_de_encode = [
550 ( '00000002', { "ms_operation_mode": "normal",
551 "additional_info": { "ciphering_indicator": False, "csg_display_control": False,
552 "prose_services": False, "extended_drx": False },
553 "rfu": 0, "mnc_len": 2, "extensions": b'' } ),
554 ( '01000102', { "ms_operation_mode": "normal_and_specific_facilities",
555 "additional_info": { "ciphering_indicator": True, "csg_display_control": False,
556 "prose_services": False, "extended_drx": False },
557 "rfu": 0, "mnc_len": 2, "extensions": b'' } ),
558 ]
Harald Weltece01f482023-12-28 09:41:35 +0100559 _test_no_pad = True
560
Harald Welte592b32e2021-06-05 11:26:36 +0200561 class OP_MODE(enum.IntEnum):
Harald Weltec91085e2022-02-10 18:05:45 +0100562 normal = 0x00
563 type_approval = 0x80
564 normal_and_specific_facilities = 0x01
565 type_approval_and_specific_facilities = 0x81
566 maintenance_off_line = 0x02
567 cell_test = 0x04
Harald Welte592b32e2021-06-05 11:26:36 +0200568
Harald Welte13edf302022-07-21 15:19:23 +0200569 def __init__(self, fid='6fad', sfid=0x03, name='EF.AD', desc='Administrative Data', size=(4, 6)):
Harald Welte592b32e2021-06-05 11:26:36 +0200570 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
571 self._construct = BitStruct(
572 # Byte 1
573 'ms_operation_mode'/Bytewise(Enum(Byte, EF_AD.OP_MODE)),
574 # Byte 2 + 3
575 'additional_info'/Bytewise(FlagsEnum(Int16ub, ciphering_indicator=1, csg_display_control=2,
576 prose_services=4, extended_drx=8)),
577 'rfu'/BitsRFU(4),
578 'mnc_len'/BitsInteger(4),
579 'extensions'/COptional(Bytewise(GreedyBytesRFU))
580 )
Harald Welte790b2702021-04-11 00:01:35 +0200581
582# TS 31.102 Section 4.2.23
583class EF_PSLOCI(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200584 def __init__(self, fid='6f73', sfid=0x0c, name='EF.PSLOCI', desc='PS Location information', size=(14, 14)):
Harald Welte790b2702021-04-11 00:01:35 +0200585 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
586 self._construct = Struct('ptmsi'/HexAdapter(Bytes(4)), 'ptmsi_sig'/HexAdapter(Bytes(3)),
587 'rai'/HexAdapter(Bytes(6)), 'rau_status'/Int8ub)
588
589# TS 31.102 Section 4.2.33
590class EF_ICI(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200591 def __init__(self, fid='6f80', sfid=0x14, name='EF.ICI', rec_len=(28, 48),
Harald Welte6169c722022-02-12 09:05:15 +0100592 desc='Incoming Call Information', **kwargs):
593 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200594 self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-28)),
Harald Welte790b2702021-04-11 00:01:35 +0200595 'len_of_bcd_contents'/Int8ub,
596 'ton_npi'/Int8ub,
597 'call_number'/BcdAdapter(Bytes(10)),
598 'cap_cfg2_record_id'/Int8ub,
599 'ext5_record_id'/Int8ub,
600 'date_and_time'/BcdAdapter(Bytes(7)),
601 'duration'/Int24ub,
602 'status'/Byte,
Harald Welte3c98d5e2022-07-20 07:40:05 +0200603 'link_to_phonebook'/HexAdapter(Bytes(3)))
Harald Welte790b2702021-04-11 00:01:35 +0200604
605# TS 31.102 Section 4.2.34
606class EF_OCI(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200607 def __init__(self, fid='6f81', sfid=0x15, name='EF.OCI', rec_len=(27, 47),
Harald Welte6169c722022-02-12 09:05:15 +0100608 desc='Outgoing Call Information', **kwargs):
609 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200610 self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-27)),
Harald Welte790b2702021-04-11 00:01:35 +0200611 'len_of_bcd_contents'/Int8ub,
612 'ton_npi'/Int8ub,
613 'call_number'/BcdAdapter(Bytes(10)),
614 'cap_cfg2_record_id'/Int8ub,
615 'ext5_record_id'/Int8ub,
616 'date_and_time'/BcdAdapter(Bytes(7)),
617 'duration'/Int24ub,
Harald Welte3c98d5e2022-07-20 07:40:05 +0200618 'link_to_phonebook'/HexAdapter(Bytes(3)))
Harald Welte790b2702021-04-11 00:01:35 +0200619
620# TS 31.102 Section 4.2.35
621class EF_ICT(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200622 def __init__(self, fid='6f82', sfid=None, name='EF.ICT', rec_len=(3, 3),
Harald Welte6169c722022-02-12 09:05:15 +0100623 desc='Incoming Call Timer', **kwargs):
624 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200625 self._construct = Struct('accumulated_call_timer'/Int24ub)
626
627# TS 31.102 Section 4.2.38
628class EF_CCP2(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100629 def __init__(self, fid='6f4f', sfid=0x16, name='EF.CCP2', desc='Capability Configuration Parameters 2', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200630 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(15, None), **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200631
Harald Welte6ca2fa72022-02-12 16:29:31 +0100632# TS 31.102 Section 4.2.47
633class EF_EST(EF_UServiceTable):
634 def __init__(self, **kwargs):
Harald Welte13edf302022-07-21 15:19:23 +0200635 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 +0100636 # add those commands to the general commands of a TransparentEF
637 self.shell_commands += [self.AddlShellCommands()]
638
639 @with_default_category('File-Specific Commands')
640 class AddlShellCommands(CommandSet):
641 def __init__(self):
642 super().__init__()
643
Harald Welte18b75392023-02-23 10:00:51 +0100644 def do_est_service_enable(self, arg):
Alexander Couzensc8facea2023-07-29 05:01:57 +0200645 """Enable a service within EF.EST"""
646 selected_file = self._cmd.lchan.selected_file
647 selected_file.ust_update(self._cmd, [int(arg)], [])
Harald Welte6ca2fa72022-02-12 16:29:31 +0100648
Harald Welte18b75392023-02-23 10:00:51 +0100649 def do_est_service_disable(self, arg):
Alexander Couzensc8facea2023-07-29 05:01:57 +0200650 """Disable a service within EF.EST"""
651 selected_file = self._cmd.lchan.selected_file
652 selected_file.ust_update(self._cmd, [], [int(arg)])
Harald Welte6ca2fa72022-02-12 16:29:31 +0100653
Harald Welte790b2702021-04-11 00:01:35 +0200654# TS 31.102 Section 4.2.48
655class EF_ACL(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200656 def __init__(self, fid='6f57', sfid=None, name='EF.ACL', size=(32, None),
Harald Welte6169c722022-02-12 09:05:15 +0100657 desc='Access Point Name Control List', **kwargs):
658 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200659 self._construct = Struct('num_of_apns'/Int8ub, 'tlvs'/HexAdapter(GreedyBytes))
Harald Welte790b2702021-04-11 00:01:35 +0200660
661# TS 31.102 Section 4.2.51
662class EF_START_HFN(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100663 _test_de_encode = [
664 ( 'f00000f00000', { "start_cs": 15728640, "start_ps": 15728640 } ),
665 ]
Harald Welte13edf302022-07-21 15:19:23 +0200666 def __init__(self, fid='6f5b', sfid=0x0f, name='EF.START-HFN', size=(6, 6),
Harald Welte6169c722022-02-12 09:05:15 +0100667 desc='Initialisation values for Hyperframe number', **kwargs):
668 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200669 self._construct = Struct('start_cs'/Int24ub, 'start_ps'/Int24ub)
670
671# TS 31.102 Section 4.2.52
672class EF_THRESHOLD(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100673 _test_de_encode = [
674 ( 'f01000', { "max_start": 15732736 } ),
675 ]
Harald Welte13edf302022-07-21 15:19:23 +0200676 def __init__(self, fid='6f5c', sfid=0x10, name='EF.THRESHOLD', size=(3, 3),
Harald Welte6169c722022-02-12 09:05:15 +0100677 desc='Maximum value of START', **kwargs):
678 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200679 self._construct = Struct('max_start'/Int24ub)
680
Harald Welte363edd92022-07-17 22:24:03 +0200681# TS 31.102 (old releases like 3.8.0) Section 4.2.56
682class EF_RPLMNAcT(TransRecEF):
Harald Welte13edf302022-07-21 15:19:23 +0200683 def __init__(self, fid='6f65', sfid=None, name='EF.RPLMNAcTD', size=(2, 4), rec_len=2,
Harald Welte363edd92022-07-17 22:24:03 +0200684 desc='RPLMN Last used Access Technology', **kwargs):
685 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs)
Harald Weltef6b37af2023-01-24 15:42:26 +0100686 def _decode_record_hex(self, in_hex, **kwargs):
Harald Welte363edd92022-07-17 22:24:03 +0200687 return dec_act(in_hex)
688 # TODO: Encode
689
Harald Welte790b2702021-04-11 00:01:35 +0200690# TS 31.102 Section 4.2.77
691class EF_VGCSCA(TransRecEF):
Harald Welte13edf302022-07-21 15:19:23 +0200692 def __init__(self, fid='6fd4', sfid=None, name='EF.VGCSCA', size=(2, 100), rec_len=2,
Harald Welte6169c722022-02-12 09:05:15 +0100693 desc='Voice Group Call Service Ciphering Algorithm', **kwargs):
694 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200695 self._construct = Struct('alg_v_ki_1'/Int8ub, 'alg_v_ki_2'/Int8ub)
696
697# TS 31.102 Section 4.2.79
698class EF_GBABP(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200699 def __init__(self, fid='6fd6', sfid=None, name='EF.GBABP', size=(3, 50),
Harald Welte6169c722022-02-12 09:05:15 +0100700 desc='GBA Bootstrapping parameters', **kwargs):
701 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200702 self._construct = Struct('rand'/LV, 'b_tid'/LV, 'key_lifetime'/LV)
703
704# TS 31.102 Section 4.2.80
705class EF_MSK(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100706 def __init__(self, fid='6fd7', sfid=None, name='EF.MSK', desc='MBMS Service Key List', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200707 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(20, None), **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200708 msk_ts_constr = Struct('msk_id'/Int32ub, 'timestamp_counter'/Int32ub)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200709 self._construct = Struct('key_domain_id'/HexAdapter(Bytes(3)),
Harald Welte790b2702021-04-11 00:01:35 +0200710 'num_msk_id'/Int8ub,
711 'msk_ids'/msk_ts_constr[this.num_msk_id])
Harald Welte14105dc2021-05-31 08:48:51 +0200712# TS 31.102 Section 4.2.81
713class EF_MUK(LinFixedEF):
714 class MUK_Idr(BER_TLV_IE, tag=0x80):
715 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100716
Harald Welte14105dc2021-05-31 08:48:51 +0200717 class MUK_Idi(BER_TLV_IE, tag=0x82):
718 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100719
Harald Welte14105dc2021-05-31 08:48:51 +0200720 class MUK_ID(BER_TLV_IE, tag=0xA0, nested=[MUK_Idr, MUK_Idi]):
721 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100722
Harald Welte14105dc2021-05-31 08:48:51 +0200723 class TimeStampCounter(BER_TLV_IE, tag=0x81):
724 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100725
Harald Welte14105dc2021-05-31 08:48:51 +0200726 class EF_MUK_Collection(TLV_IE_Collection, nested=[MUK_ID, TimeStampCounter]):
727 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100728
Harald Welte6169c722022-02-12 09:05:15 +0100729 def __init__(self, fid='6fd8', sfid=None, name='EF.MUK', desc='MBMS User Key', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200730 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(None, None), **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200731 self._tlv = EF_MUK.EF_MUK_Collection
732
733# TS 31.102 Section 4.2.83
734class EF_GBANL(LinFixedEF):
735 class NAF_ID(BER_TLV_IE, tag=0x80):
736 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100737
Harald Welte14105dc2021-05-31 08:48:51 +0200738 class B_TID(BER_TLV_IE, tag=0x81):
739 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100740
Harald Welte14105dc2021-05-31 08:48:51 +0200741 class EF_GBANL_Collection(BER_TLV_IE, nested=[NAF_ID, B_TID]):
742 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100743
Harald Welte6169c722022-02-12 09:05:15 +0100744 def __init__(self, fid='6fda', sfid=None, name='EF.GBANL', desc='GBA NAF List', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +0200745 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(None, None), **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200746 self._tlv = EF_GBANL.EF_GBANL_Collection
Harald Welte790b2702021-04-11 00:01:35 +0200747
748# TS 31.102 Section 4.2.85
749class EF_EHPLMNPI(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100750 _test_de_encode = [
Harald Welte324175f2023-12-21 20:25:30 +0100751 ( '00', {"presentation_ind": "no_preference"} ),
Harald Welte865eea62023-01-27 19:26:12 +0100752 ( '02', { "presentation_ind": "display_all" } ),
753 ]
Harald Welte13edf302022-07-21 15:19:23 +0200754 def __init__(self, fid='6fdb', sfid=None, name='EF.EHPLMNPI', size=(1, 1),
Harald Welte6169c722022-02-12 09:05:15 +0100755 desc='Equivalent HPLMN Presentation Indication', **kwargs):
756 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100757 self._construct = Struct('presentation_ind' /
Harald Welte790b2702021-04-11 00:01:35 +0200758 Enum(Byte, no_preference=0, display_highest_prio_only=1, display_all=2))
Harald Welte14105dc2021-05-31 08:48:51 +0200759
760# TS 31.102 Section 4.2.87
761class EF_NAFKCA(LinFixedEF):
762 class NAF_KeyCentreAddress(BER_TLV_IE, tag=0x80):
763 _construct = HexAdapter(GreedyBytes)
Harald Welte99e4cc02022-07-21 15:25:47 +0200764 def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', rec_len=(None, None),
Harald Welte6169c722022-02-12 09:05:15 +0100765 desc='NAF Key Centre Address', **kwargs):
766 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200767 self._tlv = EF_NAFKCA.NAF_KeyCentreAddress
768
769# TS 31.102 Section 4.2.90
770class EF_NCP_IP(LinFixedEF):
771 class DataDestAddrRange(TLV_IE, tag=0x83):
772 _construct = Struct('type_of_address'/Enum(Byte, IPv4=0x21, IPv6=0x56),
773 'prefix_length'/Int8ub,
774 'prefix'/HexAdapter(GreedyBytes))
Harald Weltec91085e2022-02-10 18:05:45 +0100775
Harald Welte14105dc2021-05-31 08:48:51 +0200776 class AccessPointName(TLV_IE, tag=0x80):
777 # coded as per TS 23.003
778 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100779
Harald Welte14105dc2021-05-31 08:48:51 +0200780 class Login(TLV_IE, tag=0x81):
781 # as per SMS DCS TS 23.038
782 _construct = GsmStringAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100783
Harald Welte14105dc2021-05-31 08:48:51 +0200784 class Password(TLV_IE, tag=0x82):
785 # as per SMS DCS TS 23.038
786 _construct = GsmStringAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100787
Harald Welte14105dc2021-05-31 08:48:51 +0200788 class BearerDescription(TLV_IE, tag=0x84):
789 # Bearer descriptionTLV DO as per TS 31.111
790 pass
Harald Weltec91085e2022-02-10 18:05:45 +0100791
Harald Welte14105dc2021-05-31 08:48:51 +0200792 class EF_NCP_IP_Collection(TLV_IE_Collection,
793 nested=[AccessPointName, Login, Password, BearerDescription]):
794 pass
Harald Welte99e4cc02022-07-21 15:25:47 +0200795 def __init__(self, fid='6fe2', sfid=None, name='EF.NCP-IP', rec_len=(None, None),
Harald Welte6169c722022-02-12 09:05:15 +0100796 desc='Network Connectivity Parameters for USIM IP connections', **kwargs):
797 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200798 self._tlv = EF_NCP_IP.EF_NCP_IP_Collection
799
Harald Welte790b2702021-04-11 00:01:35 +0200800# TS 31.102 Section 4.2.91
801class EF_EPSLOCI(TransparentEF):
Harald Welte12721292022-07-21 15:33:06 +0200802 def __init__(self, fid='6fe3', sfid=0x1e, name='EF.EPSLOCI',
803 desc='EPS Location Information', size=(18,18), **kwargs):
Harald Welte6169c722022-02-12 09:05:15 +0100804 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100805 upd_status_constr = Enum(
806 Byte, updated=0, not_updated=1, roaming_not_allowed=2)
Harald Welte3c98d5e2022-07-20 07:40:05 +0200807 self._construct = Struct('guti'/HexAdapter(Bytes(12)),
808 'last_visited_registered_tai'/HexAdapter(Bytes(5)),
Harald Welte790b2702021-04-11 00:01:35 +0200809 'eps_update_status'/upd_status_constr)
810
Harald Welte14105dc2021-05-31 08:48:51 +0200811# TS 31.102 Section 4.2.92
812class EF_EPSNSC(LinFixedEF):
Harald Weltec91085e2022-02-10 18:05:45 +0100813 class KSI_ASME(BER_TLV_IE, tag=0x80):
Harald Welte14105dc2021-05-31 08:48:51 +0200814 _construct = Int8ub
Harald Weltec91085e2022-02-10 18:05:45 +0100815
816 class K_ASME(BER_TLV_IE, tag=0x81):
Harald Welte14105dc2021-05-31 08:48:51 +0200817 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100818
Harald Welte14105dc2021-05-31 08:48:51 +0200819 class UplinkNASCount(BER_TLV_IE, tag=0x82):
820 _construct = Int32ub
Harald Weltec91085e2022-02-10 18:05:45 +0100821
Harald Welte14105dc2021-05-31 08:48:51 +0200822 class DownlinkNASCount(BER_TLV_IE, tag=0x83):
823 _construct = Int32ub
Harald Weltec91085e2022-02-10 18:05:45 +0100824
Harald Welte14105dc2021-05-31 08:48:51 +0200825 class IDofNASAlgorithms(BER_TLV_IE, tag=0x84):
826 _construct = HexAdapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100827
Harald Welte14105dc2021-05-31 08:48:51 +0200828 class EPS_NAS_Security_Context(BER_TLV_IE, tag=0xa0,
Harald Weltec91085e2022-02-10 18:05:45 +0100829 nested=[KSI_ASME, K_ASME, UplinkNASCount, DownlinkNASCount,
830 IDofNASAlgorithms]):
Harald Welte14105dc2021-05-31 08:48:51 +0200831 pass
Harald Welte99e4cc02022-07-21 15:25:47 +0200832 def __init__(self, fid='6fe4', sfid=0x18, name='EF.EPSNSC', rec_len=(54, 128),
Harald Welte6169c722022-02-12 09:05:15 +0100833 desc='EPS NAS Security Context', **kwargs):
834 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200835 self._tlv = EF_EPSNSC.EPS_NAS_Security_Context
836
Harald Welte790b2702021-04-11 00:01:35 +0200837# TS 31.102 Section 4.2.96
838class EF_PWS(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +0100839 _test_de_encode = [
840 ( '00', { "pws_configuration": { "ignore_pws_in_hplmn_and_equivalent": False,
841 "ignore_pws_in_vplmn": False } } ),
842 ]
Harald Welte13edf302022-07-21 15:19:23 +0200843 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 +0100844 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100845 pws_config = FlagsEnum(
846 Byte, ignore_pws_in_hplmn_and_equivalent=1, ignore_pws_in_vplmn=2)
Harald Welte790b2702021-04-11 00:01:35 +0200847 self._construct = Struct('pws_configuration'/pws_config)
848
849# TS 31.102 Section 4.2.101
850class EF_IPS(CyclicEF):
Harald Welte99e4cc02022-07-21 15:25:47 +0200851 def __init__(self, fid='6ff1', sfid=None, name='EF.IPS', rec_len=(4, 4),
Harald Welte6169c722022-02-12 09:05:15 +0100852 desc='IMEI(SV) Pairing Status', **kwargs):
853 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +0200854 self._construct = Struct('status'/PaddedString(2, 'ascii'),
855 'link_to_ef_ipd'/Int8ub, 'rfu'/Byte)
856
Harald Welte14105dc2021-05-31 08:48:51 +0200857# TS 31.102 Section 4.2.103
858class EF_ePDGId(TransparentEF):
Harald Welte478b5fe2023-12-08 14:27:50 +0100859 _test_de_encode = [
860 ( '801100657064672e6f736d6f636f6d2e6f7267', {'e_pdg_id': {"type_of_ePDG_address": "FQDN", "ePDG_address" : "epdg.osmocom.org" } } ),
Harald Welte6e9ae8a2023-12-08 14:57:19 +0100861 ( '800501c0a8a001', {'e_pdg_id': {"type_of_ePDG_address": "IPv4", "ePDG_address" : "192.168.160.1" } } ),
862 ( '80110220010db8000000000000000000000023', {'e_pdg_id': {"type_of_ePDG_address": "IPv6", "ePDG_address" : "2001:db8::23" } } ),
Harald Welte478b5fe2023-12-08 14:27:50 +0100863 ]
864 class ePDGId(BER_TLV_IE, tag=0x80):
Harald Welte14105dc2021-05-31 08:48:51 +0200865 _construct = Struct('type_of_ePDG_address'/Enum(Byte, FQDN=0, IPv4=1, IPv6=2),
Harald Welte478b5fe2023-12-08 14:27:50 +0100866 'ePDG_address'/Switch(this.type_of_ePDG_address,
Philipp Maier791f80a2023-07-26 17:01:37 +0200867 {'FQDN': Utf8Adapter(GreedyBytes),
Harald Welte6e9ae8a2023-12-08 14:57:19 +0100868 'IPv4': Ipv4Adapter(GreedyBytes),
869 'IPv6': Ipv6Adapter(GreedyBytes)}))
Harald Weltec91085e2022-02-10 18:05:45 +0100870
iw040ef2262023-11-07 13:41:12 +0100871 def __init__(self, fid='6ff3', sfid=None, name='EF.ePDGId', desc='Home ePDG Identifier', **kwargs):
Harald Welte6169c722022-02-12 09:05:15 +0100872 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200873 self._tlv = EF_ePDGId.ePDGId
874
Harald Weltecdfe1c22023-12-08 12:30:21 +0100875# TS 31.102 Section 4.2.104
876class EF_ePDGSelection(TransparentEF):
Harald Welte478b5fe2023-12-08 14:27:50 +0100877 _test_de_encode = [
Harald Welte842fbdb2023-12-27 17:06:58 +0100878 ( '800600f110000100', {'e_pdg_selection': [{'plmn': '001-01', 'epdg_priority': 1, 'epdg_fqdn_format': 'operator_identified' }] }),
879 ( '800600011000a001', {'e_pdg_selection': [{'plmn': '001-001', 'epdg_priority': 160, 'epdg_fqdn_format': 'location_based' }] }),
Harald Welte478b5fe2023-12-08 14:27:50 +0100880 ]
881 class ePDGSelection(BER_TLV_IE, tag=0x80):
Harald Welte842fbdb2023-12-27 17:06:58 +0100882 _construct = GreedyRange(Struct('plmn'/PlmnAdapter(Bytes(3)),
Harald Weltecdfe1c22023-12-08 12:30:21 +0100883 'epdg_priority'/Int16ub,
884 'epdg_fqdn_format'/Enum(Int8ub, operator_identified=0, location_based=1)))
885
886 def __init__(self, fid='6ff4', sfid=None, name='EF.ePDGSelection', desc='ePDG Selection Information', **kwargs):
887 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
888 self._tlv = EF_ePDGSelection.ePDGSelection
889
Harald Welte71290072021-04-21 10:58:24 +0200890# TS 31.102 Section 4.2.106
891class EF_FromPreferred(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +0200892 def __init__(self, fid='6ff7', sfid=None, name='EF.FromPreferred', size=(1, 1),
Harald Welte6169c722022-02-12 09:05:15 +0100893 desc='From Preferred', **kwargs):
894 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte45477a72023-11-03 01:33:06 +0100895 self._construct = BitStruct('rfu'/BitsRFU(7), 'from_preferred'/Flag)
Harald Welte71290072021-04-21 10:58:24 +0200896
Harald Weltefc67de22023-05-23 20:29:49 +0200897# TS 31.102 Section 4.2.114
898class EF_eAKA(TransparentEF):
899 def __init__(self, fid='6f01', sfid=None, name='EF.eAKA', size=(1, 1),
900 desc='enhanced AKA support', **kwargs):
901 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte45477a72023-11-03 01:33:06 +0100902 self._construct = BitStruct('rfu'/BitsRFU(7), 'enhanced_sqn_calculation_supported'/Flag)
Harald Weltefc67de22023-05-23 20:29:49 +0200903
Harald Welted90ceb82022-07-17 22:10:58 +0200904
905######################################################################
906# DF.GSM-ACCESS
907######################################################################
908
909class DF_GSM_ACCESS(CardDF):
910 def __init__(self, fid='5F3B', name='DF.GSM-ACCESS', desc='GSM Access', **kwargs):
911 super().__init__(fid=fid, name=name, desc=desc, service=27, **kwargs)
912 files = [
913 EF_Kc(fid='4f20', sfid=0x01, service=27),
914 EF_Kc(fid='4f52', sfid=0x02, name='EF.KcGPRS', desc='GPRS Ciphering key KcGPRS', service=27),
915 EF_CPBCCH(fid='4f63', service=39),
916 EF_InvScan(fid='4f64', service=40),
917 ]
918 self.add_files(files)
919
920
Harald Welte790b2702021-04-11 00:01:35 +0200921######################################################################
Harald Weltea77f7e12023-12-27 16:29:00 +0100922# DF.NHB
923######################################################################
924
925# 3GPP TS 31.102 Section 4.4.6.2
926class EF_ACSGL(LinFixedEF):
927 _test_de_encode = [
928 ( 'a00d800362f21081060000000002e0',
929 {'csg_list': [{'plmn': '262-01'},
930 {'csg_information': { 'csg_type': 'from_other_sources',
931 'hnb_name_indication': 'from_other_sources',
932 'csg_id': { 'id': 23 } } } ] } ),
933 ]
934 class Plmn(BER_TLV_IE, tag=0x80):
935 _construct = PlmnAdapter(Bytes(3))
936 class CsgInformation(BER_TLV_IE, tag=0x81):
937 _construct = Struct('csg_type'/Enum(Int8ub, from_other_sources=0),
938 'hnb_name_indication'/Enum(Int8ub, from_other_sources=0),
939 'csg_id'/BitStruct('id'/BitsInteger(27), Padding(5)))
940 class CsgList(BER_TLV_IE, tag=0xa0, nested=[Plmn, CsgInformation]):
941 pass
942 def __init__(self, fid='4f81', sfid=0x01, name='EF.ACSGL', desc='Allowed CSG Lists', service=86, **kwargs):
943 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs)
944 self._tlv = EF_ACSGL.CsgList
945
946# 3GPP TS 31.102 Section 4.4.6.3
947class EF_CSGT(LinFixedEF):
948 _test_de_encode = [
949 ( '8906810300666f6f', [{ 'text_csg_type': 'foo' }] ),
950 ( '8906810300666f6f801068747470733a2f2f666f6f2e6261722f',
951 [{ 'text_csg_type': 'foo' }, { "graphics_csg_type_uri": "https://foo.bar/" }] ),
952 ]
953 class TextCsgType(BER_TLV_IE, tag=0x89):
954 _construct = Ucs2Adapter(GreedyBytes)
955 class GraphicsCsgTypeURI(BER_TLV_IE, tag=0x80):
956 _construct = Utf8Adapter(GreedyBytes)
957 class GraphicsCsgTypeEfImg(BER_TLV_IE, tag=0x81):
958 _construct = Int8ub
959 class Csgt_TLV_Collection(TLV_IE_Collection,
960 nested=[TextCsgType, GraphicsCsgTypeURI, GraphicsCsgTypeEfImg]):
961 pass
962 def __init__(self, fid='4f82', sfid=0x02, name='EF.CSGT', desc='CSG Types', service=86, **kwargs):
963 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs)
964 self._tlv = EF_CSGT.Csgt_TLV_Collection
965
966
967# 3GPP TS 31.102 Section 4.4.6.4
968class EF_HNBN(LinFixedEF):
969 _test_de_encode = [
970 ( '800b8108006d61686c7a656974', { 'hnb_name': 'mahlzeit' }),
971 ]
972 class HnbName(BER_TLV_IE, tag=0x80):
973 _construct = Ucs2Adapter(GreedyBytes)
974 def __init__(self, fid='4f83', sfid=0x03, name='EF.HNBN', desc='Home NodeB Name', service=86, **kwargs):
975 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs)
976 self._tlv = EF_HNBN.HnbName
977
978# 3GPP TS 31.102 Section 4.4.6.5
979class EF_OCSGL(LinFixedEF):
980 _test_de_encode = [
981 ( 'a010800362f21081060000000002e0820100',
982 {'operator_csg_list': [{'plmn': '262-01'},
983 {'csg_information': { 'csg_type': 'from_other_sources',
984 'hnb_name_indication': 'from_other_sources',
985 'csg_id': { 'id': 23 } } },
986 {'csg_display_indicator': 'all_available_csg_ids' } ] } ),
987
988 ]
989 class CsgDisplayIndicator(BER_TLV_IE, tag=0x82):
990 _construct = Enum(Int8ub, all_available_csg_ids=0, only_ocsgl_csg_ids=1)
991 class OperatorCsgList(BER_TLV_IE, tag=0xa0, nested=[EF_ACSGL.Plmn, EF_ACSGL.CsgInformation, CsgDisplayIndicator]):
992 pass
993 def __init__(self, fid='4f84', sfid=0x04, name='EF.OCSGL', desc='Operator CSG Lists', service=90, **kwargs):
994 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs)
995 self._tlv = EF_OCSGL.OperatorCsgList
996
997
998######################################################################
Harald Welte790b2702021-04-11 00:01:35 +0200999# DF.5GS
1000######################################################################
1001
1002# TS 31.102 Section 4.4.11.2
1003class EF_5GS3GPPLOCI(TransparentEF):
Harald Welte13edf302022-07-21 15:19:23 +02001004 def __init__(self, fid='4f01', sfid=0x01, name='EF.5GS3GPPLOCI', size=(20, 20),
Harald Welte419bb492022-02-12 21:39:35 +01001005 desc='5S 3GP location information', **kwargs):
1006 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +01001007 upd_status_constr = Enum(
1008 Byte, updated=0, not_updated=1, roaming_not_allowed=2)
Harald Welte3c98d5e2022-07-20 07:40:05 +02001009 self._construct = Struct('5g_guti'/HexAdapter(Bytes(13)),
1010 'last_visited_registered_tai_in_5gs'/HexAdapter(Bytes(6)),
Harald Welte790b2702021-04-11 00:01:35 +02001011 '5gs_update_status'/upd_status_constr)
1012
1013# TS 31.102 Section 4.4.11.7
1014class EF_UAC_AIC(TransparentEF):
Harald Welte865eea62023-01-27 19:26:12 +01001015 _test_de_encode = [
1016 ( '03', { "uac_access_id_config": { "multimedia_priority_service": True,
1017 "mission_critical_service": True } } ),
1018 ]
Harald Welte13edf302022-07-21 15:19:23 +02001019 def __init__(self, fid='4f06', sfid=0x06, name='EF.UAC_AIC', size=(4, 4),
Harald Welte419bb492022-02-12 21:39:35 +01001020 desc='UAC Access Identities Configuration', **kwargs):
1021 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs)
Harald Welte790b2702021-04-11 00:01:35 +02001022 cfg_constr = FlagsEnum(Byte, multimedia_priority_service=1,
Harald Weltec91085e2022-02-10 18:05:45 +01001023 mission_critical_service=2)
Harald Welte790b2702021-04-11 00:01:35 +02001024 self._construct = Struct('uac_access_id_config'/cfg_constr)
1025
Harald Welte14105dc2021-05-31 08:48:51 +02001026# TS 31.102 Section 4.4.11.9
Harald Welte790b2702021-04-11 00:01:35 +02001027class EF_OPL5G(LinFixedEF):
Harald Welte52064292023-05-24 15:25:26 +02001028 def __init__(self, fid='4f08', sfid=0x08, name='EF.OPL5G', desc='5GS Operator PLMN List', **kwargs):
Harald Welte99e4cc02022-07-21 15:25:47 +02001029 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(10, None), **kwargs)
Harald Welte842fbdb2023-12-27 17:06:58 +01001030 Tai = Struct('mcc_mnc'/PlmnAdapter(Bytes(3)), 'tac_min'/HexAdapter(Bytes(3)),
Harald Welte3c98d5e2022-07-20 07:40:05 +02001031 'tac_max'/HexAdapter(Bytes(3)))
Harald Weltea0377622022-02-25 15:36:44 +01001032 self._construct = Struct('tai'/Tai, 'pnn_record_id'/Int8ub)
Harald Welte790b2702021-04-11 00:01:35 +02001033
Harald Welte14105dc2021-05-31 08:48:51 +02001034# TS 31.102 Section 4.4.11.10
1035class EF_SUPI_NAI(TransparentEF):
1036 class NetworkSpecificIdentifier(TLV_IE, tag=0x80):
1037 # RFC 7542 encoded as UTF-8 string
Philipp Maier791f80a2023-07-26 17:01:37 +02001038 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +01001039
Harald Welte14105dc2021-05-31 08:48:51 +02001040 class GlobalLineIdentifier(TLV_IE, tag=0x81):
1041 # TS 23.003 clause 28.16.2
Philipp Maier791f80a2023-07-26 17:01:37 +02001042 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +01001043
Harald Welte14105dc2021-05-31 08:48:51 +02001044 class GlobalCableIdentifier(TLV_IE, tag=0x82):
1045 # TS 23.003 clause 28.15.2
Philipp Maier791f80a2023-07-26 17:01:37 +02001046 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +01001047
Harald Welte14105dc2021-05-31 08:48:51 +02001048 class NAI_TLV_Collection(TLV_IE_Collection,
Harald Weltec91085e2022-02-10 18:05:45 +01001049 nested=[NetworkSpecificIdentifier, GlobalLineIdentifier, GlobalCableIdentifier]):
Harald Welte14105dc2021-05-31 08:48:51 +02001050 pass
1051 def __init__(self, fid='4f09', sfid=0x09, name='EF.SUPI_NAI',
Harald Welte419bb492022-02-12 21:39:35 +01001052 desc='SUPI as Network Access Identifier', **kwargs):
1053 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +02001054 self._tlv = EF_SUPI_NAI.NAI_TLV_Collection
1055
Harald Welte455611c2023-05-27 12:48:54 +02001056# TS 31.102 Section 4.4.11.11
1057class EF_Routing_Indicator(TransparentEF):
1058 def __init__(self, fid='4f0a', sfid=0x0a, name='EF.Routing_Indicator', desc='Routing Indicator', **kwargs):
1059 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1060 # 3GPP TS 24.501 Table 9.11.3.4.1:
1061 # Routing Indicator shall consist of 1 to 4 digits. The coding of this field is the
1062 # responsibility of home network operator but BCD coding shall be used. If a network
1063 # operator decides to assign less than 4 digits to Routing Indicator, the remaining digits
1064 # shall be coded as "1111" to fill the 4 digits coding of Routing Indicator
Harald Weltef9a5ba52023-06-09 09:17:05 +02001065 self._construct = Struct('routing_indicator'/Rpad(BcdAdapter(Bytes(2)), 'f', 2),
1066 'rfu'/HexAdapter(Bytes(2)))
Harald Weltec91085e2022-02-10 18:05:45 +01001067
Harald Weltefc67de22023-05-23 20:29:49 +02001068# TS 31.102 Section 4.4.11.13
Harald Welte14105dc2021-05-31 08:48:51 +02001069class EF_TN3GPPSNN(TransparentEF):
1070 class ServingNetworkName(BER_TLV_IE, tag=0x80):
Philipp Maier791f80a2023-07-26 17:01:37 +02001071 _construct = Utf8Adapter(GreedyBytes)
Harald Welte14105dc2021-05-31 08:48:51 +02001072 def __init__(self, fid='4f0c', sfid=0x0c, name='EF.TN3GPPSNN',
Harald Welte419bb492022-02-12 21:39:35 +01001073 desc='Trusted non-3GPP Serving network names list', **kwargs):
1074 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +02001075 self._tlv = EF_TN3GPPSNN.ServingNetworkName
1076
Harald Weltefc67de22023-05-23 20:29:49 +02001077# TS 31.102 Section 4.4.11.14 (Rel 17)
1078class EF_CAG(TransparentEF):
1079 def __init__(self, fid='4f0d', sfid=0x0d, name='EF.CAG',
1080 desc='Pre-configured CAG information list EF', **kwargs):
1081 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1082 self._construct = HexAdapter(GreedyBytes)
1083
1084# TS 31.102 Section 4.4.11.15 (Rel 17)
1085class EF_SOR_CMCI(TransparentEF):
1086 def __init__(self, fid='4f0e', sfid=0x0e, name='EF.SOR-CMCI',
1087 desc='Steering Of Roaming - Connected Mode Control Information', **kwargs):
1088 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1089 self._construct = HexAdapter(GreedyBytes)
1090
1091# TS 31.102 Section 4.4.11.17 (Rel 17)
1092class EF_DRI(TransparentEF):
1093 def __init__(self, fid='4f0f', sfid=0x0f, name='EF.DRI',
1094 desc='Disaster roaming information EF', **kwargs):
1095 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1096 self._construct = Struct('disaster_roaming_enabled'/Byte,
1097 'parameters_indicator_status'/FlagsEnum(Byte, roaming_wait_range=1,
1098 return_wait_range=2,
1099 applicability_indicator=3),
1100 'roaming_wait_range'/HexAdapter(Bytes(2)),
1101 'return_wait_range'/HexAdapter(Bytes(2)),
1102 'applicability_indicator'/HexAdapter(Byte))
1103
1104# TS 31.102 Section 4.4.12.2 (Rel 17)
1105class EF_PWS_SNPN(TransparentEF):
1106 def __init__(self, fid='4f01', sfid=0x01, name='EF.PWS_SNPN',
1107 desc='Public Warning System in SNPNs', **kwargs):
1108 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1109 self._construct = Struct('pws_config_in_snpns'/FlagsEnum(Byte, ignore_all_pws_in_subscribed=1,
1110 ignore_all_pws_in_non_subscribed=2))
1111
1112# TS 31.102 Section 4.4.12.2 (Rel 17)
1113class EF_NID(LinFixedEF):
1114 def __init__(self, fid='4f02', sfid=0x02, name='EF.NID',
1115 desc='Network Identifier for SNPN', **kwargs):
1116 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(6,6), **kwargs)
1117 self._construct = Struct('assignment_mode'/Enum(Byte, coordinated_ass_opt1=0,
1118 self_ass=1,
1119 coordinated_ass_opt2=2),
1120 'network_identifier'/HexAdapter(Bytes(5)))
1121
1122# TS 31.102 Section 4.4.12 (Rel 17)
1123class DF_SNPN(CardDF):
1124 def __init__(self, fid='5fe0', name='DF.SNPN', desc='Files for SNPN purpose', **kwargs):
1125 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
1126 files = [
1127 EF_PWS_SNPN(service=143),
1128 EF_NID(service=146),
1129 ]
1130 self.add_files(files)
1131
1132# TS 31.102 Section 4.4.13.2 (Rel 17)
1133class EF_5G_PROSE_ST(EF_UServiceTable):
1134 def __init__(self, **kwargs):
1135 super().__init__(fid='4f01', sfid=0x01, name='EF.5G_PROSE_ST',
1136 desc='5G ProSe Service Table', size=(1,2), table=EF_5G_PROSE_ST_map, **kwargs)
1137 # add those commands to the general commands of a TransparentEF
1138 self.shell_commands += [self.AddlShellCommands()]
1139
1140 @with_default_category('File-Specific Commands')
1141 class AddlShellCommands(CommandSet):
1142 def __init__(self):
1143 super().__init__()
1144
1145 def do_prose_service_activate(self, arg):
1146 """Activate a service within EF.5G_PROSE_ST"""
Alexander Couzensc8facea2023-07-29 05:01:57 +02001147 selected_file = self._cmd.lchan.selected_file
1148 selected_file.ust_update(self._cmd, [int(arg)], [])
Harald Weltefc67de22023-05-23 20:29:49 +02001149
1150 def do_prose_service_deactivate(self, arg):
1151 """Deactivate a service within EF.5G_PROSE_ST"""
Alexander Couzensc8facea2023-07-29 05:01:57 +02001152 selected_file = self._cmd.lchan.selected_file
1153 selected_file.ust_update(self._cmd, [], [int(arg)])
Harald Weltefc67de22023-05-23 20:29:49 +02001154
1155# TS 31.102 Section 4.4.13.3 (Rel 17)
1156class EF_5G_PROSE_DD(TransparentEF):
1157 class ServedByNgRan(BER_TLV_IE, tag=0x80):
1158 pass
1159 class NotServedByNgran(BER_TLV_IE, tag=0x81):
1160 pass
1161 class ProSeIdentifiers(BER_TLV_IE, tag=0x82):
1162 pass
1163 class ProSeIdToDefaultDestL2Id(BER_TLV_IE, tag=0x83):
1164 pass
1165 class GroupMemberDiscoveryParameters(BER_TLV_IE, tag=0x84):
1166 pass
1167 class ValidityTimer(BER_TLV_IE, tag=0x85):
1168 pass
1169 class ProSeDirectDiscoveryUeId(BER_TLV_IE, tag=0x86):
1170 pass
1171 class Hplmn5GDdnmfAddressInformation(BER_TLV_IE, tag=0x87):
1172 pass
1173 class ProSeConfigForDirectDiscovery(BER_TLV_IE, tag=0xA0,
1174 nested=[ServedByNgRan, NotServedByNgran, ProSeIdentifiers,
1175 ProSeIdToDefaultDestL2Id, GroupMemberDiscoveryParameters,
1176 ValidityTimer, ProSeDirectDiscoveryUeId,
1177 Hplmn5GDdnmfAddressInformation]):
1178 pass
1179 def __init__(self, fid='4f02', sfid=0x02, name='EF.5G_PROSE_DD',
1180 desc='5G ProSe configuration data for direct discovery', **kwargs):
1181 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1182 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1183 self._tlv = EF_5G_PROSE_DD.ProSeConfigForDirectDiscovery
1184
1185# TS 31.102 Section 4.4.13.4 (Rel 17)
1186class EF_5G_PROSE_DC(TransparentEF):
1187 class PrivacyConfig(BER_TLV_IE, tag=0x87):
1188 pass
1189 class DirectCommInNrPc5(BER_TLV_IE, tag=0x88):
1190 pass
1191 class ApplicationToPathPreferenceMappingRules(BER_TLV_IE, tag=0x89):
1192 pass
1193 class ProSeIdToNrTxProfileForBroadcastAndGroupcastMappingRules(BER_TLV_IE, tag=0x91):
1194 pass
1195 class ProSeConfigForDirectCommunication(BER_TLV_IE, tag=0xA0,
1196 nested=[EF_5G_PROSE_DD.ServedByNgRan,
1197 EF_5G_PROSE_DD.NotServedByNgran,
1198 PrivacyConfig, DirectCommInNrPc5,
1199 ApplicationToPathPreferenceMappingRules,
1200 EF_5G_PROSE_DD.ValidityTimer,
1201 ProSeIdToNrTxProfileForBroadcastAndGroupcastMappingRules]):
1202 pass
1203 def __init__(self, fid='4f03', sfid=0x03, name='EF.5G_PROSE_DC',
1204 desc='5G ProSe configuration data for direct communication', **kwargs):
1205 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1206 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1207 self._tlv = EF_5G_PROSE_DC.ProSeConfigForDirectCommunication
1208
1209# TS 31.102 Section 4.4.13.5 (Rel 17)
1210class EF_5G_PROSE_U2NRU(TransparentEF):
1211 class ProSeIdToDefaultDestL2Id(BER_TLV_IE, tag=0x8a):
1212 pass
1213 class RxcInfoList(BER_TLV_IE, tag=0x8b):
1214 pass
1215 class FiveQiToPc65QosParametersMappingRules(BER_TLV_IE, tag=0x8c):
1216 pass
1217 class ProSeIdToAppSrvAddrMappingRules(BER_TLV_IE, tag=0x8d):
1218 pass
1219 class UserInfoIdForDiscovery(BER_TLV_IE, tag=0x8e):
1220 pass
1221 class PrivacyTimer(BER_TLV_IE, tag=0x92):
1222 pass
1223 class FiveGPkkmfAddressInformation(BER_TLV_IE, tag=0x93):
1224 pass
1225 class ProSeConfigDataForUeToNetworkRelayUe(BER_TLV_IE, tag=0xA0,
1226 nested=[EF_5G_PROSE_DD.ServedByNgRan,
1227 EF_5G_PROSE_DD.NotServedByNgran,
1228 ProSeIdToDefaultDestL2Id,
1229 RxcInfoList,
1230 FiveQiToPc65QosParametersMappingRules,
1231 ProSeIdToAppSrvAddrMappingRules,
1232 EF_5G_PROSE_DD.ValidityTimer,
1233 UserInfoIdForDiscovery,
1234 PrivacyTimer,
1235 FiveGPkkmfAddressInformation]):
1236 pass
1237 def __init__(self, fid='4f04', sfid=0x04, name='EF.5G_PROSE_U2NRU',
1238 desc='5G ProSe configuration data for UE-to-network relay UE', **kwargs):
1239 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1240 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1241 self._tlv = EF_5G_PROSE_U2NRU.ProSeConfigDataForUeToNetworkRelayUe
1242
1243# TS 31.102 Section 4.4.13.6 (Rel 17)
1244class EF_5G_PROSE_RU(TransparentEF):
1245 class DefaultDestL2Ids(BER_TLV_IE, tag=0x8f):
1246 pass
1247 class N3IwfSelectionInfoFor5GProSeL3RemoteUE(BER_TLV_IE, tag=0x90):
1248 pass
1249 class ProSeConfigDataForRemoteUe(BER_TLV_IE, tag=0xa0,
1250 nested=[EF_5G_PROSE_DD.ServedByNgRan,
1251 EF_5G_PROSE_DD.NotServedByNgran,
1252 DefaultDestL2Ids,
1253 EF_5G_PROSE_U2NRU.RxcInfoList,
1254 N3IwfSelectionInfoFor5GProSeL3RemoteUE,
1255 EF_5G_PROSE_DD.ValidityTimer,
1256 EF_5G_PROSE_U2NRU.UserInfoIdForDiscovery,
1257 EF_5G_PROSE_U2NRU.PrivacyTimer,
1258 EF_5G_PROSE_U2NRU.FiveGPkkmfAddressInformation]):
1259 pass
1260 def __init__(self, fid='4f05', sfid=0x05, name='EF.5G_PROSE_RU',
1261 desc='5G ProSe configuration data for remote UE', **kwargs):
1262 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1263 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1264 self._tlv = EF_5G_PROSE_RU.ProSeConfigDataForRemoteUe
1265
1266# TS 31.102 Section 4.4.13.7 (Rel 17)
1267class EF_5G_PROSE_UIR(TransparentEF):
1268 class CollectionPeriod(BER_TLV_IE, tag=0x94):
1269 pass
1270 class ReportingWindow(BER_TLV_IE, tag=0x95):
1271 pass
1272 class ReportingIndicators(BER_TLV_IE, tag=0x96):
1273 pass
1274 class FiveGDdnmfCtfAddrForUploading(BER_TLV_IE, tag=0x97):
1275 pass
1276 class ProSeConfigDataForUeToNetworkRelayUE(BER_TLV_IE, tag=0xa0,
1277 nested=[EF_5G_PROSE_DD.ValidityTimer,
1278 CollectionPeriod, ReportingWindow,
1279 ReportingIndicators,
1280 FiveGDdnmfCtfAddrForUploading]):
1281 pass
1282 def __init__(self, fid='4f06', sfid=0x06, name='EF.5G_PROSE_UIR',
1283 desc='5G ProSe configuration data for usage information reporting', **kwargs):
1284 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1285 # contains TLV structure despite being TransparentEF, not BER-TLV ?!?
1286 self._tlv = EF_5G_PROSE_UIR.ProSeConfigDataForUeToNetworkRelayUE
1287
1288# TS 31.102 Section 4.4.13 (Rel 17)
1289class DF_5G_ProSe(CardDF):
1290 def __init__(self, fid='5ff0', name='DF.5G_ProSe', desc='Files for 5G ProSe purpose', **kwargs):
1291 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
1292 files = [
1293 EF_5G_PROSE_ST(),
1294 EF_5G_PROSE_DD(service=1),
1295 EF_5G_PROSE_DC(service=2),
1296 EF_5G_PROSE_U2NRU(service=3),
1297 EF_5G_PROSE_RU(service=4),
1298 EF_5G_PROSE_UIR(service=5),
1299 ]
1300 self.add_files(files)
1301
1302# TS 31.102 Section 4.4.11.18 (Rel 17)
1303class EF_5GSEDRX(TransparentEF):
1304 def __init__(self, fid='4f10', sfid=0x10, name='EF.5GSEDRX',
1305 desc='5GS eDRX Parameters', **kwargs):
1306 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1307 self._construct = Struct('5gs_rat_type'/FlagsEnum(Byte, ng_ran=1, sat_ng_ran=2),
1308 'edrx_cycle_length'/Int8ub)
1309
1310# TS 31.102 Section 4.4.11.19 (Rel 17)
1311class EF_5GNSWO_CONF(TransparentEF):
1312 def __init__(self, fid='4f11', sfid=0x11, name='EF.5GNSWO_CONF',
1313 desc='5G Non-Seamless WLAN Offload configuration', **kwargs):
1314 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1315 self._construct = Struct('5g_nswo_usage_ind'/Enum(Byte, disabled=0, enabled=1))
1316
1317# TS 31.102 Section 4.4.11.20 (Rel 17)
1318class EF_MCHPPLMN(TransparentEF):
Harald Welte24e77a72023-05-24 15:26:29 +02001319 def __init__(self, fid='4f15', sfid=0x15, name='EF.MCHPPLMN',
Harald Weltefc67de22023-05-23 20:29:49 +02001320 desc='Multiplier Coefficient for Higher Priority PLMN search', **kwargs):
1321 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1322 self._construct = Struct('multiplier_coefficient'/Int8ub)
1323
1324# TS 31.102 Section 4.4.11.21 (Rel 17)
1325class EF_KAUSF_DERIVATION(TransparentEF):
1326 def __init__(self, fid='4f16', sfid=0x16, name='EF.KAUSF_DERIVATION',
1327 desc='K_AUSF derivation configuration', **kwargs):
1328 super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs)
1329 self._construct = Struct('k_ausf_deriv_cfg'/FlagsEnum(Byte, use_msk=1), 'rfu'/HexAdapter(GreedyBytes))
1330
Harald Welte3990ebb2021-04-20 23:55:14 +02001331# TS 31.102 Section 4.4.5
1332class DF_WLAN(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001333 def __init__(self, fid='5f40', name='DF.WLAN', desc='Files for WLAN purpose', **kwargs):
1334 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Harald Welte3990ebb2021-04-20 23:55:14 +02001335 files = [
Harald Welte419bb492022-02-12 21:39:35 +01001336 TransparentEF('4f41', 0x01, 'EF.Pseudo', 'Pseudonym', service=59),
Harald Weltec91085e2022-02-10 18:05:45 +01001337 TransparentEF('4f42', 0x02, 'EF.UPLMNWLAN',
Harald Welte419bb492022-02-12 21:39:35 +01001338 'User controlled PLMN selector for I-WLAN Access', service=60),
Harald Weltec91085e2022-02-10 18:05:45 +01001339 TransparentEF('4f43', 0x03, 'EF.OPLMNWLAN',
Harald Welte419bb492022-02-12 21:39:35 +01001340 'Operator controlled PLMN selector for I-WLAN Access', service=61),
Harald Weltec91085e2022-02-10 18:05:45 +01001341 LinFixedEF('4f44', 0x04, 'EF.UWSIDL',
Harald Welte419bb492022-02-12 21:39:35 +01001342 'User controlled WLAN Specific Identifier List', service=62),
Harald Weltec91085e2022-02-10 18:05:45 +01001343 LinFixedEF('4f45', 0x05, 'EF.OWSIDL',
Harald Welte419bb492022-02-12 21:39:35 +01001344 'Operator controlled WLAN Specific Identifier List', service=63),
Harald Weltec91085e2022-02-10 18:05:45 +01001345 TransparentEF('4f46', 0x06, 'EF.WRI',
Harald Welte419bb492022-02-12 21:39:35 +01001346 'WLAN Reauthentication Identity', service=66),
Harald Weltec91085e2022-02-10 18:05:45 +01001347 LinFixedEF('4f47', 0x07, 'EF.HWSIDL',
Harald Welte419bb492022-02-12 21:39:35 +01001348 'Home I-WLAN Specific Identifier List', service=81),
Harald Weltec91085e2022-02-10 18:05:45 +01001349 TransparentEF('4f48', 0x08, 'EF.WEHPLMNPI',
Harald Welte419bb492022-02-12 21:39:35 +01001350 'I-WLAN Equivalent HPLMN Presentation Indication', service=82),
Harald Weltec91085e2022-02-10 18:05:45 +01001351 TransparentEF('4f49', 0x09, 'EF.WHPI',
Harald Welte419bb492022-02-12 21:39:35 +01001352 'I-WLAN HPLMN Priority Indication', service=83),
Harald Weltec91085e2022-02-10 18:05:45 +01001353 TransparentEF('4f4a', 0x0a, 'EF.WLRPLMN',
Harald Welte419bb492022-02-12 21:39:35 +01001354 'I-WLAN Last Registered PLMN', service=84),
Harald Weltec91085e2022-02-10 18:05:45 +01001355 TransparentEF('4f4b', 0x0b, 'EF.HPLMNDAI',
Harald Welte419bb492022-02-12 21:39:35 +01001356 'HPLMN Direct Access Indicator', service=88),
Harald Weltec91085e2022-02-10 18:05:45 +01001357 ]
Harald Welte3990ebb2021-04-20 23:55:14 +02001358 self.add_files(files)
1359
1360# TS 31.102 Section 4.4.6
1361class DF_HNB(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001362 def __init__(self, fid='5f50', name='DF.HNB', desc='Files for HomeNodeB purpose', **kwargs):
1363 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Harald Welte3990ebb2021-04-20 23:55:14 +02001364 files = [
Harald Weltea77f7e12023-12-27 16:29:00 +01001365 EF_ACSGL(),
1366 EF_CSGT(),
1367 EF_HNBN(),
1368 EF_OCSGL(),
1369 EF_CSGT('4f85', 0x05, 'EF.OCSGT', 'Operator CSG Type', service=90),
1370 EF_HNBN('4f86', 0x06, 'EF.OHNBN', 'Operator Home NodeB Name', service=90),
Harald Weltec91085e2022-02-10 18:05:45 +01001371 ]
Harald Welte3990ebb2021-04-20 23:55:14 +02001372 self.add_files(files)
1373
1374# TS 31.102 Section 4.4.8
1375class DF_ProSe(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001376 def __init__(self, fid='5f90', name='DF.ProSe', desc='Files for ProSe purpose', **kwargs):
1377 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Harald Welte3990ebb2021-04-20 23:55:14 +02001378 files = [
Harald Weltec91085e2022-02-10 18:05:45 +01001379 LinFixedEF('4f01', 0x01, 'EF.PROSE_MON',
1380 'ProSe Monitoring Parameters'),
1381 LinFixedEF('4f02', 0x02, 'EF.PROSE_ANN',
1382 'ProSe Announcing Parameters'),
Harald Welte3990ebb2021-04-20 23:55:14 +02001383 LinFixedEF('4f03', 0x03, 'EF.PROSEFUNC', 'HPLMN ProSe Function'),
Harald Weltec91085e2022-02-10 18:05:45 +01001384 TransparentEF('4f04', 0x04, 'EF.PROSE_RADIO_COM',
1385 'ProSe Direct Communication Radio Parameters'),
1386 TransparentEF('4f05', 0x05, 'EF.PROSE_RADIO_MON',
1387 'ProSe Direct Discovery Monitoring Radio Parameters'),
1388 TransparentEF('4f06', 0x06, 'EF.PROSE_RADIO_ANN',
1389 'ProSe Direct Discovery Announcing Radio Parameters'),
1390 LinFixedEF('4f07', 0x07, 'EF.PROSE_POLICY',
1391 'ProSe Policy Parameters'),
Harald Welte3990ebb2021-04-20 23:55:14 +02001392 LinFixedEF('4f08', 0x08, 'EF.PROSE_PLMN', 'ProSe PLMN Parameters'),
1393 TransparentEF('4f09', 0x09, 'EF.PROSE_GC', 'ProSe Group Counter'),
1394 TransparentEF('4f10', 0x10, 'EF.PST', 'ProSe Service Table'),
Harald Weltec91085e2022-02-10 18:05:45 +01001395 TransparentEF('4f11', 0x11, 'EF.UIRC',
1396 'ProSe UsageInformationReportingConfiguration'),
1397 LinFixedEF('4f12', 0x12, 'EF.PROSE_GM_DISCOVERY',
1398 'ProSe Group Member Discovery Parameters'),
1399 LinFixedEF('4f13', 0x13, 'EF.PROSE_RELAY',
1400 'ProSe Relay Parameters'),
1401 TransparentEF('4f14', 0x14, 'EF.PROSE_RELAY_DISCOVERY',
1402 'ProSe Relay Discovery Parameters'),
1403 ]
Harald Welte3990ebb2021-04-20 23:55:14 +02001404 self.add_files(files)
1405
Harald Weltec91085e2022-02-10 18:05:45 +01001406
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001407class DF_USIM_5GS(CardDF):
Harald Welte6169c722022-02-12 09:05:15 +01001408 def __init__(self, fid='5FC0', name='DF.5GS', desc='5GS related files', **kwargs):
1409 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001410 files = [
Harald Weltec91085e2022-02-10 18:05:45 +01001411 # I'm looking at 31.102 R16.6
Harald Welte419bb492022-02-12 21:39:35 +01001412 EF_5GS3GPPLOCI(service=122),
Harald Weltec91085e2022-02-10 18:05:45 +01001413 EF_5GS3GPPLOCI('4f02', 0x02, 'EF.5GSN3GPPLOCI',
Harald Welte28accc82023-10-18 23:21:46 +02001414 desc='5GS non-3GPP location information', service=122),
Harald Welte419bb492022-02-12 21:39:35 +01001415 EF_5GS3GPPNSC(service=122),
Harald Weltec91085e2022-02-10 18:05:45 +01001416 EF_5GS3GPPNSC('4f04', 0x04, 'EF.5GSN3GPPNSC',
Harald Welte28accc82023-10-18 23:21:46 +02001417 desc='5GS non-3GPP Access NAS Security Context', service=122),
Harald Welte419bb492022-02-12 21:39:35 +01001418 EF_5GAUTHKEYS(service=123),
1419 EF_UAC_AIC(service=126),
1420 EF_SUCI_Calc_Info(service=124),
1421 EF_OPL5G(service=129),
1422 EF_SUPI_NAI(service=130),
Harald Welte455611c2023-05-27 12:48:54 +02001423 EF_Routing_Indicator(service=124),
Harald Weltec91085e2022-02-10 18:05:45 +01001424 TransparentEF('4F0B', 0x0b, 'EF.URSP',
Harald Welte28accc82023-10-18 23:21:46 +02001425 desc='UE Route Selector Policies per PLMN', service=132),
Harald Welte419bb492022-02-12 21:39:35 +01001426 EF_TN3GPPSNN(service=133),
Harald Weltefc67de22023-05-23 20:29:49 +02001427 # Rel-17 additions below
1428 EF_CAG(service=137),
1429 EF_SOR_CMCI(service=138),
1430 EF_DRI(service=140),
1431 EF_5GSEDRX(service=141),
1432 EF_5GNSWO_CONF(service=142),
1433 EF_MCHPPLMN(service=144),
1434 EF_KAUSF_DERIVATION(service=145),
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001435 ]
Merlin Chlosta05ca36b2021-04-01 16:15:28 +02001436 self.add_files(files)
1437
Harald Weltec91085e2022-02-10 18:05:45 +01001438
Harald Welte2bee70c2023-05-25 09:14:28 +02001439class DF_SAIP(CardDF):
1440 """This is not really TS 31.102 but part of the eUICC Profile Package: Interoperable Format Technical
1441 Specification as released by TCA (formerly SIMalliance)"""
1442 def __init__(self, fid='5FD0', name='DF.SAIP', desc='SIMalliance Interoperable Profile', **kwargs):
1443 super().__init__(fid=fid, name=name, desc=desc, **kwargs)
1444 files = [
1445 # uses the same file format as DF.5GS/EF_SUCI_Calc_Info, but different FID
1446 EF_SUCI_Calc_Info(fid='4f01')
1447 ]
1448 self.add_files(files)
1449
1450
Harald Welteb2edd142021-01-08 23:29:35 +01001451class ADF_USIM(CardADF):
Philipp Maiera1850ae2023-10-25 18:05:09 +02001452 def __init__(self, aid='a0000000871002', has_fs=True, name='ADF.USIM', fid=None, sfid=None,
Harald Welteb2edd142021-01-08 23:29:35 +01001453 desc='USIM Application'):
Philipp Maiera1850ae2023-10-25 18:05:09 +02001454 super().__init__(aid=aid, has_fs=has_fs, fid=fid, sfid=sfid, name=name, desc=desc)
Harald Welte15fae982021-04-10 10:22:27 +02001455 # add those commands to the general commands of a TransparentEF
1456 self.shell_commands += [self.AddlShellCommands()]
Harald Welteb2edd142021-01-08 23:29:35 +01001457
1458 files = [
Harald Weltec91085e2022-02-10 18:05:45 +01001459 EF_LI(sfid=0x02),
1460 EF_IMSI(sfid=0x07),
1461 EF_Keys(),
1462 EF_Keys('6f09', 0x09, 'EF.KeysPS',
1463 desc='Ciphering and Integrity Keys for PS domain'),
1464 EF_xPLMNwAcT('6f60', 0x0a, 'EF.PLMNwAcT',
Harald Welte509ecf82023-10-18 23:32:57 +02001465 desc='User controlled PLMN Selector with Access Technology', service=20),
Harald Weltec91085e2022-02-10 18:05:45 +01001466 EF_HPPLMN(),
Harald Welte6169c722022-02-12 09:05:15 +01001467 EF_ACMmax(service=13),
Harald Welte6ca2fa72022-02-12 16:29:31 +01001468 EF_UST(),
Harald Weltec91085e2022-02-10 18:05:45 +01001469 CyclicEF('6f39', None, 'EF.ACM',
Harald Welte509ecf82023-10-18 23:32:57 +02001470 desc='Accumulated call meter', rec_len=(3, 3), service=13),
1471 TransparentEF('6f3e', None, 'EF.GID1', desc='Group Identifier Level 1', service=17),
1472 TransparentEF('6f3f', None, 'EF.GID2', desc='Group Identifier Level 2', service=18),
Harald Welte6169c722022-02-12 09:05:15 +01001473 EF_SPN(service=19),
Harald Weltec91085e2022-02-10 18:05:45 +01001474 TransparentEF('6f41', None, 'EF.PUCT',
Harald Welte509ecf82023-10-18 23:32:57 +02001475 desc='Price per unit and currency table', size=(5, 5), service=13),
Harald Welte6169c722022-02-12 09:05:15 +01001476 EF_CBMI(service=15),
Harald Weltec91085e2022-02-10 18:05:45 +01001477 EF_ACC(sfid=0x06),
Harald Welte509ecf82023-10-18 23:32:57 +02001478 EF_PLMNsel('6f7b', 0x0d, 'EF.FPLMN', desc='Forbidden PLMNs', size=(12, None)),
Harald Weltec91085e2022-02-10 18:05:45 +01001479 EF_LOCI(),
1480 EF_AD(),
Harald Welte6169c722022-02-12 09:05:15 +01001481 EF_CBMID(sfid=0x0e, service=29),
Harald Weltec91085e2022-02-10 18:05:45 +01001482 EF_ECC(),
Harald Welte6169c722022-02-12 09:05:15 +01001483 EF_CBMIR(service=16),
Harald Weltec91085e2022-02-10 18:05:45 +01001484 EF_PSLOCI(),
Harald Welte509ecf82023-10-18 23:32:57 +02001485 EF_ADN('6f3b', None, 'EF.FDN', desc='Fixed Dialling Numbers', service=[2, 89], ext=2),
Harald Welte6169c722022-02-12 09:05:15 +01001486 EF_SMS('6f3c', None, service=10),
1487 EF_MSISDN(service=21),
1488 EF_SMSP(service=12),
1489 EF_SMSS(service=10),
Harald Welte509ecf82023-10-18 23:32:57 +02001490 EF_ADN('6f49', None, 'EF.SDN', desc='Service Dialling Numbers', service=[4, 89], ext=3),
1491 EF_EXT('6f4b', None, 'EF.EXT2', desc='Extension2 (FDN)', service=3),
1492 EF_EXT('6f4c', None, 'EF.EXT3', desc='Extension2 (SDN)', service=5),
Harald Welte6169c722022-02-12 09:05:15 +01001493 EF_SMSR(service=11),
1494 EF_ICI(service=9),
1495 EF_OCI(service=8),
1496 EF_ICT(service=9),
Harald Welte509ecf82023-10-18 23:32:57 +02001497 EF_ICT('6f83', None, 'EF.OCT', desc='Outgoing Call Timer', service=8),
1498 EF_EXT('6f4e', None, 'EF.EXT5', desc='Extension5 (ICI/OCI/MSISDN)', service=44),
Harald Welte6169c722022-02-12 09:05:15 +01001499 EF_CCP2(service=14),
1500 EF_eMLPP(service=24),
1501 EF_AAeM(service=25),
Harald Weltec91085e2022-02-10 18:05:45 +01001502 # EF_Hiddenkey
Harald Welte509ecf82023-10-18 23:32:57 +02001503 EF_ADN('6f4d', None, 'EF.BDN', desc='Barred Dialling Numbers', service=6, ext=4),
1504 EF_EXT('6f55', None, 'EF.EXT4', desc='Extension4 (BDN/SSC)', service=7),
Harald Welte6169c722022-02-12 09:05:15 +01001505 EF_CMI(service=6),
Harald Welte6ca2fa72022-02-12 16:29:31 +01001506 EF_EST(service=[2, 6, 34, 35]),
Harald Welte6169c722022-02-12 09:05:15 +01001507 EF_ACL(service=35),
1508 EF_DCK(service=36),
1509 EF_CNL(service=37),
Harald Weltec91085e2022-02-10 18:05:45 +01001510 EF_START_HFN(),
1511 EF_THRESHOLD(),
Harald Welte509ecf82023-10-18 23:32:57 +02001512 EF_xPLMNwAcT('6f61', 0x11, 'EF.OPLMNwAcT', desc='User controlled PLMN Selector with Access Technology', service=42),
1513 EF_xPLMNwAcT('6f62', 0x13, 'EF.HPLMNwAcT', desc='HPLMN Selector with Access Technology', service=43),
Harald Weltec91085e2022-02-10 18:05:45 +01001514 EF_ARR('6f06', 0x17),
Harald Welte363edd92022-07-17 22:24:03 +02001515 EF_RPLMNAcT(),
Harald Welte509ecf82023-10-18 23:32:57 +02001516 TransparentEF('6fc4', None, 'EF.NETPAR', desc='Network Parameters'),
Harald Welte6169c722022-02-12 09:05:15 +01001517 EF_PNN('6fc5', 0x19, service=45),
1518 EF_OPL(service=46),
Harald Welte509ecf82023-10-18 23:32:57 +02001519 EF_ADN('6fc7', None, 'EF.MBDN', desc='Mailbox Dialling Numbers', service=47, ext=6),
1520 EF_EXT('6fc8', None, 'EF.EXT6', desc='Extension6 (MBDN)'),
Harald Welte6169c722022-02-12 09:05:15 +01001521 EF_MBI(service=47),
1522 EF_MWIS(service=48),
Harald Welte53762512023-12-21 20:16:17 +01001523 EF_CFIS(service=49, ext=7),
Harald Welte509ecf82023-10-18 23:32:57 +02001524 EF_EXT('6fcc', None, 'EF.EXT7', desc='Extension7 (CFIS)'),
1525 TransparentEF('6fcd', None, 'EF.SPDI', desc='Service Provider Display Information', service=51),
Harald Welte6169c722022-02-12 09:05:15 +01001526 EF_MMSN(service=52),
Harald Welte509ecf82023-10-18 23:32:57 +02001527 EF_EXT('6fcf', None, 'EF.EXT8', desc='Extension8 (MMSN)', service=53),
Harald Welte6169c722022-02-12 09:05:15 +01001528 EF_MMSICP(service=52),
1529 EF_MMSUP(service=52),
1530 EF_MMSUCP(service=(52, 55)),
Harald Welte04bd5142023-05-24 15:23:53 +02001531 EF_NIA(service=56, fid='6fd3'),
Harald Welte6169c722022-02-12 09:05:15 +01001532 EF_VGCS(service=57),
1533 EF_VGCSS(service=57),
Harald Welte509ecf82023-10-18 23:32:57 +02001534 EF_VGCS('6fb3', None, 'EF.VBS', desc='Voice Broadcast Service', service=58),
1535 EF_VGCSS('6fb4', None, 'EF.VBSS', desc='Voice Broadcast Service Status', service=58),
Harald Welte6169c722022-02-12 09:05:15 +01001536 EF_VGCSCA(service=64),
Harald Welte509ecf82023-10-18 23:32:57 +02001537 EF_VGCSCA('6fd5', None, 'EF.VBCSCA', desc='Voice Broadcast Service Ciphering Algorithm', service=65),
Harald Welte6169c722022-02-12 09:05:15 +01001538 EF_GBABP(service=68),
1539 EF_MSK(service=69),
1540 EF_MUK(service=69),
1541 EF_GBANL(service=68),
Harald Welte509ecf82023-10-18 23:32:57 +02001542 EF_PLMNsel('6fd9', 0x1d, 'EF.EHPLMN', desc='Equivalent HPLMN', size=(12, None), service=71),
Harald Welte6169c722022-02-12 09:05:15 +01001543 EF_EHPLMNPI(service=(71, 73)),
1544 # EF_LRPLMNSI ('6fdc', service=74)
1545 EF_NAFKCA(service=(68, 76)),
Harald Welte509ecf82023-10-18 23:32:57 +02001546 TransparentEF('6fde', None, 'EF.SPNI', desc='Service Provider Name Icon', service=78),
1547 LinFixedEF('6fdf', None, 'EF.PNNI', desc='PLMN Network Name Icon', service=79),
Harald Welte6169c722022-02-12 09:05:15 +01001548 EF_NCP_IP(service=80),
Harald Welte509ecf82023-10-18 23:32:57 +02001549 EF_EPSLOCI('6fe3', 0x1e, 'EF.EPSLOCI', desc='EPS location information', service=85),
Harald Welte6169c722022-02-12 09:05:15 +01001550 EF_EPSNSC(service=85),
Harald Welte324175f2023-12-21 20:25:30 +01001551 # EF.UFC Test data: 801e60c01e900080040000000000000000f0000000004000000000000080
Harald Welte509ecf82023-10-18 23:32:57 +02001552 TransparentEF('6fe6', None, 'EF.UFC', desc='USAT Facility Control', size=(1, 16)),
1553 TransparentEF('6fe8', None, 'EF.NASCONFIG', desc='Non Access Stratum Configuration', service=96),
Harald Welte6169c722022-02-12 09:05:15 +01001554 # UICC IARI (only in cards that have no ISIM) service=95
1555 EF_PWS(service=97),
Harald Welte509ecf82023-10-18 23:32:57 +02001556 LinFixedEF('6fed', None, 'EF.FDNURI', desc='Fixed Dialling Numbers URI', service=(2, 99)),
1557 LinFixedEF('6fee', None, 'EF.BDNURI', desc='Barred Dialling Numbers URI', service=(6, 99)),
1558 LinFixedEF('6fef', None, 'EF.SDNURI', desc='Service Dialling Numbers URI', service=(4, 99)),
Harald Welte6169c722022-02-12 09:05:15 +01001559 # EF_IWL (IMEI(SV) White List)
Harald Weltec91085e2022-02-10 18:05:45 +01001560 EF_IPS(),
Harald Welte6169c722022-02-12 09:05:15 +01001561 EF_ePDGId(service=(106, 107)),
Harald Weltecdfe1c22023-12-08 12:30:21 +01001562 EF_ePDGSelection(service=(106, 107)),
Harald Welte5277b5c2023-12-08 12:22:28 +01001563 EF_ePDGId('6ff5', None, 'EF.ePDGIdEm', desc='Emergency ePDG Identifier', service=(110, 111)),
Harald Weltecdfe1c22023-12-08 12:30:21 +01001564 EF_ePDGSelection('6ff6', None, 'EF.ePDGSelectionEm',
1565 desc='ePDG Selection Information for Emergency Services', service=(110, 111)),
Harald Welte6169c722022-02-12 09:05:15 +01001566 EF_FromPreferred(service=114),
Harald Weltefc67de22023-05-23 20:29:49 +02001567 EF_eAKA(),
Harald Welte6169c722022-02-12 09:05:15 +01001568 # FIXME: DF_SoLSA service=23
Harald Weltede4c14c2022-07-16 11:53:59 +02001569 DF_PHONEBOOK(),
Harald Welted90ceb82022-07-17 22:10:58 +02001570 DF_GSM_ACCESS(),
Harald Welte6169c722022-02-12 09:05:15 +01001571 DF_WLAN(service=[59, 60, 61, 62, 63, 66, 81, 82, 83, 84, 88]),
1572 DF_HNB(service=[86, 90]),
1573 DF_ProSe(service=101),
1574 # FIXME: DF_ACDC service=108
1575 # FIXME: DF_TV service=116
1576 DF_USIM_5GS(service=[122, 123, 124, 125, 126, 127, 129, 130]),
Harald Weltefc67de22023-05-23 20:29:49 +02001577 DF_SNPN(service=[143,146]),
1578 DF_5G_ProSe(service=139),
Harald Welte2bee70c2023-05-25 09:14:28 +02001579 DF_SAIP(),
Harald Weltec91085e2022-02-10 18:05:45 +01001580 ]
Harald Welteb2edd142021-01-08 23:29:35 +01001581 self.add_files(files)
1582
1583 def decode_select_response(self, data_hex):
Philipp Maier5998a3a2021-11-16 15:16:39 +01001584 return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex)
Harald Welteb2edd142021-01-08 23:29:35 +01001585
Harald Welte15fae982021-04-10 10:22:27 +02001586 @with_default_category('Application-Specific Commands')
1587 class AddlShellCommands(CommandSet):
1588 def __init__(self):
1589 super().__init__()
1590
1591 authenticate_parser = argparse.ArgumentParser()
Harald Welte91842b42024-01-11 22:03:37 +01001592 authenticate_parser.add_argument('rand', type=is_hexstr, help='Random challenge')
1593 authenticate_parser.add_argument('autn', type=is_hexstr, help='Authentication Nonce')
Harald Welte15fae982021-04-10 10:22:27 +02001594 #authenticate_parser.add_argument('--context', help='Authentication context', default='3G')
Harald Weltec91085e2022-02-10 18:05:45 +01001595
Harald Welte15fae982021-04-10 10:22:27 +02001596 @cmd2.with_argparser(authenticate_parser)
1597 def do_authenticate(self, opts):
1598 """Perform Authentication and Key Agreement (AKA)."""
Harald Welte46255122023-10-21 23:40:42 +02001599 (data, sw) = self._cmd.lchan.scc.authenticate(opts.rand, opts.autn)
Harald Welte15fae982021-04-10 10:22:27 +02001600 self._cmd.poutput_json(data)
1601
Harald Welte12af7932022-02-15 16:39:08 +01001602 term_prof_parser = argparse.ArgumentParser()
Harald Welte91842b42024-01-11 22:03:37 +01001603 term_prof_parser.add_argument('PROFILE', type=is_hexstr, help='Hexstring of encoded terminal profile')
Harald Welte12af7932022-02-15 16:39:08 +01001604
1605 @cmd2.with_argparser(term_prof_parser)
Harald Welte51b3abb2022-07-30 16:30:33 +02001606 def do_terminal_profile(self, opts):
Harald Welte12af7932022-02-15 16:39:08 +01001607 """Send a TERMINAL PROFILE command to the card.
1608 This is used to inform the card about which optional
1609 features the terminal (modem/phone) supports, particularly
1610 in the context of SIM Toolkit, Proactive SIM and OTA. You
1611 must specify a hex-string with the encoded terminal profile
1612 you want to send to the card."""
Harald Welte46255122023-10-21 23:40:42 +02001613 (data, sw) = self._cmd.lchan.scc.terminal_profile(opts.PROFILE)
Harald Welte846a8982021-10-08 15:47:16 +02001614 self._cmd.poutput('SW: %s, data: %s' % (sw, data))
Harald Welte15fae982021-04-10 10:22:27 +02001615
Harald Welte12af7932022-02-15 16:39:08 +01001616 envelope_parser = argparse.ArgumentParser()
Harald Welte91842b42024-01-11 22:03:37 +01001617 envelope_parser.add_argument('PAYLOAD', type=is_hexstr, help='Hexstring of encoded payload to ENVELOPE')
Harald Welte12af7932022-02-15 16:39:08 +01001618
1619 @cmd2.with_argparser(envelope_parser)
Harald Welte51b3abb2022-07-30 16:30:33 +02001620 def do_envelope(self, opts):
Harald Welte12af7932022-02-15 16:39:08 +01001621 """Send an ENVELOPE command to the card. This is how a
1622 variety of information is communicated from the terminal
1623 (modem/phone) to the card, particularly in the context of
1624 SIM Toolkit, Proactive SIM and OTA."""
Harald Welte46255122023-10-21 23:40:42 +02001625 (data, sw) = self._cmd.lchan.scc.envelope(opts.PAYLOAD)
Harald Welte7cb94e42021-10-08 15:47:57 +02001626 self._cmd.poutput('SW: %s, data: %s' % (sw, data))
1627
Harald Welte12af7932022-02-15 16:39:08 +01001628 envelope_sms_parser = argparse.ArgumentParser()
Harald Welte91842b42024-01-11 22:03:37 +01001629 envelope_sms_parser.add_argument('TPDU', type=is_hexstr, help='Hexstring of encoded SMS TPDU')
Harald Welte12af7932022-02-15 16:39:08 +01001630
1631 @cmd2.with_argparser(envelope_sms_parser)
Harald Welte51b3abb2022-07-30 16:30:33 +02001632 def do_envelope_sms(self, opts):
Harald Welte12af7932022-02-15 16:39:08 +01001633 """Send an ENVELOPE(SMS-PP-Download) command to the card.
1634 This emulates a terminal (modem/phone) having received a SMS
1635 with a PID of 'SMS for the SIM card'. You can use this
1636 command in the context of testing OTA related features
Philipp Maier4e5aa302023-06-06 19:22:19 +02001637 without a modem/phone or a cellular network."""
Harald Welte7cb94e42021-10-08 15:47:57 +02001638 tpdu_ie = SMS_TPDU()
Harald Welte51b3abb2022-07-30 16:30:33 +02001639 tpdu_ie.from_bytes(h2b(opts.TPDU))
Harald Weltec91085e2022-02-10 18:05:45 +01001640 dev_ids = DeviceIdentities(
1641 decoded={'source_dev_id': 'network', 'dest_dev_id': 'uicc'})
Harald Welte7cb94e42021-10-08 15:47:57 +02001642 sms_dl = SMSPPDownload(children=[dev_ids, tpdu_ie])
Harald Welte46255122023-10-21 23:40:42 +02001643 (data, sw) = self._cmd.lchan.scc.envelope(b2h(sms_dl.to_tlv()))
Harald Welte7cb94e42021-10-08 15:47:57 +02001644 self._cmd.poutput('SW: %s, data: %s' % (sw, data))
1645
Harald Welte7ec82232023-06-06 18:15:52 +02001646 get_id_parser = argparse.ArgumentParser()
1647 get_id_parser.add_argument("--nswo-context", action='store_true')
1648
1649 @cmd2.with_argparser(get_id_parser)
1650 def do_get_identity(self, opts):
1651 """Send a GET IDENTITY command to the card. This is part of the
1652 procedure for "SUCI calculation performed on USIM" supported
1653 by USIM with support for both EF.UST service 124 and 125."""
1654 context = 0x01 # SUCI
1655 if opts.nswo_context:
1656 context = 0x02 # SUCI 5G NSWO
Harald Welte46255122023-10-21 23:40:42 +02001657 (data, sw) = self._cmd.lchan.scc.get_identity(context)
Harald Welte7ec82232023-06-06 18:15:52 +02001658 do = SUCI_TlvDataObject()
1659 do.from_tlv(h2b(data))
1660 do_d = do.to_dict()
1661 self._cmd.poutput('SUCI TLV Data Object: %s' % do_d['suci__tlv_data_object'])
1662
Harald Welte15fae982021-04-10 10:22:27 +02001663
Harald Welteb2edd142021-01-08 23:29:35 +01001664# TS 31.102 Section 7.3
1665sw_usim = {
1666 'Security management': {
1667 '9862': 'Authentication error, incorrect MAC',
1668 '9864': 'Authentication error, security context not supported',
1669 '9865': 'Key freshness failure',
1670 '9866': 'Authentication error, no memory space available',
1671 '9867': 'Authentication error, no memory space available in EF MUK',
1672 }
1673}
1674
Harald Weltec91085e2022-02-10 18:05:45 +01001675
Philipp Maier57f65ee2021-10-18 14:09:02 +02001676class CardApplicationUSIM(CardApplication):
1677 def __init__(self):
Harald Weltec91085e2022-02-10 18:05:45 +01001678 super().__init__('USIM', adf=ADF_USIM(), sw=sw_usim)