Supreeth Herle | 475dcaa | 2020-03-20 18:57:39 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 3 | # 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 Herle | 475dcaa | 2020-03-20 18:57:39 +0100 | [diff] [blame] | 7 | """ |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 8 | Various constants from 3GPP TS 31.102 V17.9.0 |
Supreeth Herle | 475dcaa | 2020-03-20 18:57:39 +0100 | [diff] [blame] | 9 | """ |
| 10 | |
| 11 | # |
| 12 | # Copyright (C) 2020 Supreeth Herle <herlesupreeth@gmail.com> |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 13 | # Copyright (C) 2021-2023 Harald Welte <laforge@osmocom.org> |
Supreeth Herle | 475dcaa | 2020-03-20 18:57:39 +0100 | [diff] [blame] | 14 | # |
| 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 Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 30 | import pySim.ts_102_221 |
| 31 | from pySim.ts_51_011 import EF_ACMmax, EF_AAeM, EF_eMLPP, EF_CMI, EF_PNN |
| 32 | from pySim.ts_51_011 import EF_MMSN, EF_MMSICP, EF_MMSUP, EF_MMSUCP, EF_VGCS, EF_VGCSS, EF_NIA |
| 33 | from pySim.ts_51_011 import EF_SMSR, EF_DCK, EF_EXT, EF_CNL, EF_OPL, EF_MBI, EF_MWIS |
Harald Welte | 5376251 | 2023-12-21 20:16:17 +0100 | [diff] [blame] | 34 | from pySim.ts_51_011 import EF_CBMID, EF_CBMIR, EF_ADN, EF_CFIS, EF_SMS, EF_MSISDN, EF_SMSP, EF_SMSS |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 35 | from pySim.ts_51_011 import EF_IMSI, EF_xPLMNwAcT, EF_SPN, EF_CBMI, EF_ACC, EF_PLMNsel |
Harald Welte | d90ceb8 | 2022-07-17 22:10:58 +0200 | [diff] [blame] | 36 | from pySim.ts_51_011 import EF_Kc, EF_CPBCCH, EF_InvScan |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 37 | from pySim.ts_102_221 import EF_ARR |
| 38 | from pySim.tlv import * |
| 39 | from pySim.filesystem import * |
Harald Welte | 6f8a870 | 2022-07-17 21:50:31 +0200 | [diff] [blame] | 40 | from pySim.ts_31_102_telecom import DF_PHONEBOOK, EF_UServiceTable |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 41 | from pySim.construct import * |
Harald Welte | f56b6b2 | 2022-07-30 16:36:06 +0200 | [diff] [blame] | 42 | from pySim.cat import SMS_TPDU, DeviceIdentities, SMSPPDownload |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 43 | from construct import Optional as COptional |
| 44 | from construct import * |
| 45 | from typing import Tuple |
| 46 | from struct import unpack, pack |
| 47 | import enum |
Supreeth Herle | 475dcaa | 2020-03-20 18:57:39 +0100 | [diff] [blame] | 48 | EF_UST_map = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 49 | 1: 'Local Phone Book', |
| 50 | 2: 'Fixed Dialling Numbers (FDN)', |
| 51 | 3: 'Extension 2', |
| 52 | 4: 'Service Dialling Numbers (SDN)', |
| 53 | 5: 'Extension3', |
| 54 | 6: 'Barred Dialling Numbers (BDN)', |
| 55 | 7: 'Extension4', |
| 56 | 8: 'Outgoing Call Information (OCI and OCT)', |
| 57 | 9: 'Incoming Call Information (ICI and ICT)', |
| 58 | 10: 'Short Message Storage (SMS)', |
| 59 | 11: 'Short Message Status Reports (SMSR)', |
| 60 | 12: 'Short Message Service Parameters (SMSP)', |
| 61 | 13: 'Advice of Charge (AoC)', |
| 62 | 14: 'Capability Configuration Parameters 2 (CCP2)', |
| 63 | 15: 'Cell Broadcast Message Identifier', |
| 64 | 16: 'Cell Broadcast Message Identifier Ranges', |
| 65 | 17: 'Group Identifier Level 1', |
| 66 | 18: 'Group Identifier Level 2', |
| 67 | 19: 'Service Provider Name', |
| 68 | 20: 'User controlled PLMN selector with Access Technology', |
| 69 | 21: 'MSISDN', |
| 70 | 22: 'Image (IMG)', |
| 71 | 23: 'Support of Localised Service Areas (SoLSA)', |
| 72 | 24: 'Enhanced Multi-Level Precedence and Pre-emption Service', |
| 73 | 25: 'Automatic Answer for eMLPP', |
| 74 | 26: 'RFU', |
| 75 | 27: 'GSM Access', |
| 76 | 28: 'Data download via SMS-PP', |
| 77 | 29: 'Data download via SMS-CB', |
| 78 | 30: 'Call Control by USIM', |
| 79 | 31: 'MO-SMS Control by USIM', |
| 80 | 32: 'RUN AT COMMAND command', |
| 81 | 33: 'shall be set to 1', |
| 82 | 34: 'Enabled Services Table', |
| 83 | 35: 'APN Control List (ACL)', |
| 84 | 36: 'Depersonalisation Control Keys', |
| 85 | 37: 'Co-operative Network List', |
| 86 | 38: 'GSM security context', |
| 87 | 39: 'CPBCCH Information', |
| 88 | 40: 'Investigation Scan', |
| 89 | 41: 'MexE', |
| 90 | 42: 'Operator controlled PLMN selector with Access Technology', |
| 91 | 43: 'HPLMN selector with Access Technology', |
| 92 | 44: 'Extension 5', |
| 93 | 45: 'PLMN Network Name', |
| 94 | 46: 'Operator PLMN List', |
| 95 | 47: 'Mailbox Dialling Numbers', |
| 96 | 48: 'Message Waiting Indication Status', |
| 97 | 49: 'Call Forwarding Indication Status', |
| 98 | 50: 'Reserved and shall be ignored', |
| 99 | 51: 'Service Provider Display Information', |
| 100 | 52: 'Multimedia Messaging Service (MMS)', |
| 101 | 53: 'Extension 8', |
| 102 | 54: 'Call control on GPRS by USIM', |
| 103 | 55: 'MMS User Connectivity Parameters', |
| 104 | 56: 'Network\'s indication of alerting in the MS (NIA)', |
| 105 | 57: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)', |
| 106 | 58: 'VBS Group Identifier List (EFVBS and EFVBSS)', |
| 107 | 59: 'Pseudonym', |
| 108 | 60: 'User Controlled PLMN selector for I-WLAN access', |
| 109 | 61: 'Operator Controlled PLMN selector for I-WLAN access', |
| 110 | 62: 'User controlled WSID list', |
| 111 | 63: 'Operator controlled WSID list', |
| 112 | 64: 'VGCS security', |
| 113 | 65: 'VBS security', |
| 114 | 66: 'WLAN Reauthentication Identity', |
| 115 | 67: 'Multimedia Messages Storage', |
| 116 | 68: 'Generic Bootstrapping Architecture (GBA)', |
| 117 | 69: 'MBMS security', |
| 118 | 70: 'Data download via USSD and USSD application mode', |
| 119 | 71: 'Equivalent HPLMN', |
| 120 | 72: 'Additional TERMINAL PROFILE after UICC activation', |
| 121 | 73: 'Equivalent HPLMN Presentation Indication', |
| 122 | 74: 'Last RPLMN Selection Indication', |
| 123 | 75: 'OMA BCAST Smart Card Profile', |
| 124 | 76: 'GBA-based Local Key Establishment Mechanism', |
| 125 | 77: 'Terminal Applications', |
| 126 | 78: 'Service Provider Name Icon', |
| 127 | 79: 'PLMN Network Name Icon', |
| 128 | 80: 'Connectivity Parameters for USIM IP connections', |
| 129 | 81: 'Home I-WLAN Specific Identifier List', |
| 130 | 82: 'I-WLAN Equivalent HPLMN Presentation Indication', |
| 131 | 83: 'I-WLAN HPLMN Priority Indication', |
| 132 | 84: 'I-WLAN Last Registered PLMN', |
| 133 | 85: 'EPS Mobility Management Information', |
| 134 | 86: 'Allowed CSG Lists and corresponding indications', |
| 135 | 87: 'Call control on EPS PDN connection by USIM', |
| 136 | 88: 'HPLMN Direct Access', |
| 137 | 89: 'eCall Data', |
| 138 | 90: 'Operator CSG Lists and corresponding indications', |
| 139 | 91: 'Support for SM-over-IP', |
| 140 | 92: 'Support of CSG Display Control', |
| 141 | 93: 'Communication Control for IMS by USIM', |
| 142 | 94: 'Extended Terminal Applications', |
| 143 | 95: 'Support of UICC access to IMS', |
| 144 | 96: 'Non-Access Stratum configuration by USIM', |
| 145 | 97: 'PWS configuration by USIM', |
| 146 | 98: 'RFU', |
| 147 | 99: 'URI support by UICC', |
| 148 | 100: 'Extended EARFCN support', |
| 149 | 101: 'ProSe', |
| 150 | 102: 'USAT Application Pairing', |
| 151 | 103: 'Media Type support', |
| 152 | 104: 'IMS call disconnection cause', |
| 153 | 105: 'URI support for MO SHORT MESSAGE CONTROL', |
| 154 | 106: 'ePDG configuration Information support', |
| 155 | 107: 'ePDG configuration Information configured', |
| 156 | 108: 'ACDC support', |
| 157 | 109: 'MCPTT', |
| 158 | 110: 'ePDG configuration Information for Emergency Service support', |
| 159 | 111: 'ePDG configuration Information for Emergency Service configured', |
| 160 | 112: 'eCall Data over IMS', |
| 161 | 113: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [12]', |
| 162 | 114: 'From Preferred', |
| 163 | 115: 'IMS configuration data', |
| 164 | 116: 'TV configuration', |
| 165 | 117: '3GPP PS Data Off', |
| 166 | 118: '3GPP PS Data Off Service List', |
| 167 | 119: 'V2X', |
| 168 | 120: 'XCAP Configuration Data', |
| 169 | 121: 'EARFCN list for MTC/NB-IOT UEs', |
| 170 | 122: '5GS Mobility Management Information', |
| 171 | 123: '5G Security Parameters', |
| 172 | 124: 'Subscription identifier privacy support', |
| 173 | 125: 'SUCI calculation by the USIM', |
| 174 | 126: 'UAC Access Identities support', |
| 175 | 127: 'Expect control plane-based Steering of Roaming information during initial registration in VPLMN', |
| 176 | 128: 'Call control on PDU Session by USIM', |
| 177 | 129: '5GS Operator PLMN List', |
| 178 | 130: 'Support for SUPI of type NSI or GLI or GCI', |
| 179 | 131: '3GPP PS Data Off separate Home and Roaming lists', |
| 180 | 132: 'Support for URSP by USIM', |
| 181 | 133: '5G Security Parameters extended', |
| 182 | 134: 'MuD and MiD configuration data', |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 183 | 135: 'Support for Trusted non-3GPP access networks by USIM', |
| 184 | 136: 'Support for multiple records of NAS security context storage for multiple registration', |
| 185 | 137: 'Pre-configured CAG information list', |
| 186 | 138: 'SOR-CMCI storage in USIM', |
| 187 | 139: '5G ProSe', |
| 188 | 140: 'Storage of disaster roaming information in USIM', |
| 189 | 141: 'Pre-configured eDRX parameters', |
| 190 | 142: '5G NSWO support', |
| 191 | 143: 'PWS configuration for SNPN in USIM', |
| 192 | 144: 'Multiplier Coefficient for Higher Priority PLMN search via NG-RAN satellite access', |
| 193 | 145: 'K_AUSF derivation configuration', |
| 194 | 146: 'Network Identifier for SNPN (NID)', |
| 195 | } |
| 196 | |
| 197 | EF_5G_PROSE_ST_map = { |
| 198 | 1: '5G ProSe configuration data for direct discovery', |
| 199 | 2: '5G ProSe configuration data for direct communication', |
| 200 | 3: '5G ProSe configuration data for UE-to-network relay UE', |
| 201 | 4: '5G ProSe configuration data for remote UE', |
| 202 | 5: '5G ProSe configuration data for usage information reporting', |
Sebastian Viviani | 0dc8f69 | 2020-05-29 00:14:55 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Harald Welte | e894749 | 2022-02-10 10:33:20 +0100 | [diff] [blame] | 205 | # Mapping between USIM Enbled Service Number and its description |
| 206 | EF_EST_map = { |
| 207 | 1: 'Fixed Dialling Numbers (FDN)', |
| 208 | 2: 'Barred Dialling Numbers (BDN)', |
| 209 | 3: 'APN Control List (ACL)' |
| 210 | } |
| 211 | |
Harald Welte | 21caf32 | 2022-07-16 14:06:46 +0200 | [diff] [blame] | 212 | # 3gPP TS 31.102 Section 7.5.2.1 |
| 213 | class SUCI_TlvDataObject(BER_TLV_IE, tag=0xA1): |
| 214 | _construct = HexAdapter(GreedyBytes) |
| 215 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 216 | ###################################################################### |
| 217 | # ADF.USIM |
| 218 | ###################################################################### |
| 219 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 220 | |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 221 | # 3GPP TS 31.102 Section 4.4.11.4 (EF_5GS3GPPNSC) |
| 222 | class EF_5GS3GPPNSC(LinFixedEF): |
| 223 | class NgKSI(BER_TLV_IE, tag=0x80): |
| 224 | _construct = Int8ub |
| 225 | |
| 226 | class K_AMF(BER_TLV_IE, tag=0x81): |
| 227 | _construct = HexAdapter(Bytes(32)) |
| 228 | |
| 229 | class UplinkNASCount(BER_TLV_IE, tag=0x82): |
| 230 | _construct = Int32ub |
| 231 | |
| 232 | class DownlinkNASCount(BER_TLV_IE, tag=0x83): |
| 233 | _construct = Int32ub |
| 234 | |
| 235 | class IdsOfSelectedNasAlgos(BER_TLV_IE, tag=0x84): |
| 236 | # 3GPP TS 24.501 Section 9.11.3.34 |
| 237 | _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble) |
| 238 | |
| 239 | class IdsOfSelectedEpsAlgos(BER_TLV_IE, tag=0x85): |
| 240 | # 3GPP TS 24.301 Section 9.9.3.23 |
| 241 | _construct = BitStruct('ciphering'/Nibble, 'integrity'/Nibble) |
| 242 | |
| 243 | class FiveGSNasSecurityContext(BER_TLV_IE, tag=0xA0, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 244 | nested=[NgKSI, K_AMF, UplinkNASCount, |
| 245 | DownlinkNASCount, IdsOfSelectedNasAlgos, |
| 246 | IdsOfSelectedEpsAlgos]): |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 247 | pass |
| 248 | |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 249 | def __init__(self, fid="4f03", sfid=0x03, name='EF.5GS3GPPNSC', rec_len=(57, None), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 250 | desc='5GS 3GPP Access NAS Security Context', **kwargs): |
| 251 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 6551627 | 2022-02-10 17:51:05 +0100 | [diff] [blame] | 252 | self._tlv = EF_5GS3GPPNSC.FiveGSNasSecurityContext |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 253 | |
| 254 | # 3GPP TS 31.102 Section 4.4.11.6 |
| 255 | class EF_5GAUTHKEYS(TransparentEF): |
| 256 | class K_AUSF(BER_TLV_IE, tag=0x80): |
| 257 | _construct = HexAdapter(GreedyBytes) |
| 258 | |
| 259 | class K_SEAF(BER_TLV_IE, tag=0x81): |
| 260 | _construct = HexAdapter(GreedyBytes) |
| 261 | |
| 262 | class FiveGAuthKeys(TLV_IE_Collection, nested=[K_AUSF, K_SEAF]): |
| 263 | pass |
| 264 | |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 265 | def __init__(self, fid='4f05', sfid=0x05, name='EF.5GAUTHKEYS', size=(68, None), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 266 | desc='5G authentication keys', **kwargs): |
| 267 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 6551627 | 2022-02-10 17:51:05 +0100 | [diff] [blame] | 268 | self._tlv = EF_5GAUTHKEYS.FiveGAuthKeys |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 269 | |
| 270 | # 3GPP TS 31.102 Section 4.4.11.8 |
| 271 | class ProtSchemeIdList(BER_TLV_IE, tag=0xa0): |
| 272 | # FIXME: 3GPP TS 24.501 Protection Scheme Identifier |
| 273 | # repeated sequence of (id, index) tuples |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 274 | _construct = GreedyRange( |
| 275 | Struct('id'/Enum(Byte, null=0, A=1, B=2), 'index'/Int8ub)) |
| 276 | |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 277 | |
| 278 | class HomeNetPubKeyId(BER_TLV_IE, tag=0x80): |
| 279 | # 3GPP TS 24.501 / 3GPP TS 23.003 |
| 280 | _construct = Int8ub |
| 281 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 282 | |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 283 | class HomeNetPubKey(BER_TLV_IE, tag=0x81): |
| 284 | # FIXME: RFC 5480 |
| 285 | _construct = HexAdapter(GreedyBytes) |
| 286 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 287 | |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 288 | class HomeNetPubKeyList(BER_TLV_IE, tag=0xa1, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 289 | nested=[HomeNetPubKeyId, HomeNetPubKey]): |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 290 | pass |
| 291 | |
| 292 | # 3GPP TS 31.102 Section 4.4.11.6 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 293 | class SUCI_CalcInfo(TLV_IE_Collection, nested=[ProtSchemeIdList, HomeNetPubKeyList]): |
Harald Welte | f12979d | 2021-05-29 21:47:13 +0200 | [diff] [blame] | 294 | pass |
| 295 | |
| 296 | |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 297 | # TS 31.102 4.4.11.8 |
| 298 | class EF_SUCI_Calc_Info(TransparentEF): |
Harald Welte | 324175f | 2023-12-21 20:25:30 +0100 | [diff] [blame] | 299 | _test_de_encode = [ |
| 300 | ( 'A00401010000A14A80010A81204E858C4D49D1343E6181284C47CA721730C98742CB7C6182D2E8126E08088D3680010B8120D1BC365F4997D17CE4374E72181431CBFEBA9E1B98D7618F79D48561B144672A', |
| 301 | {"prot_scheme_id_list": [{"priority": 0, "identifier": 1, "key_index": 1}, {"priority": 1, |
| 302 | "identifier": 0, |
| 303 | "key_index": 0}], |
| 304 | "hnet_pubkey_list": [{"hnet_pubkey_identifier": 10, "hnet_pubkey": |
| 305 | "4e858c4d49d1343e6181284c47ca721730c98742cb7c6182d2e8126e08088d36"}, |
| 306 | {"hnet_pubkey_identifier": 11, "hnet_pubkey": |
| 307 | "d1bc365f4997d17ce4374e72181431cbfeba9e1b98d7618f79d48561b144672a"}]} ), |
| 308 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 309 | def __init__(self, fid="4f07", sfid=0x07, name='EF.SUCI_Calc_Info', size=(2, None), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 310 | desc='SUCI Calc Info', **kwargs): |
| 311 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 312 | |
| 313 | def _encode_prot_scheme_id_list(self, in_list): |
| 314 | out_bytes = [0xa0] |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 315 | out_bytes.append(len(in_list)*2) # two byte per entry |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 316 | |
| 317 | # position in list determines priority; high-priority items (low index) come first |
| 318 | for scheme in sorted(in_list, key=lambda item: item["priority"]): |
| 319 | out_bytes.append(scheme["identifier"]) |
| 320 | out_bytes.append(scheme["key_index"]) |
| 321 | |
| 322 | return out_bytes |
| 323 | |
| 324 | def _encode_hnet_pubkey_list(self, hnet_pubkey_list): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 325 | out_bytes = [0xa1] # pubkey list tag |
| 326 | out_bytes.append(0x00) # length filled later |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 327 | length = 0 |
| 328 | |
| 329 | for key in hnet_pubkey_list: |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 330 | out_bytes.append(0x80) # identifier tag |
| 331 | out_bytes.append(0x01) # TODO size, fixed to 1 byte |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 332 | out_bytes.append(key["hnet_pubkey_identifier"]) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 333 | out_bytes.append(0x81) # key tag |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 334 | out_bytes.append(len(key["hnet_pubkey"])//2) |
| 335 | length += 5+len(key["hnet_pubkey"])//2 |
| 336 | |
| 337 | pubkey_bytes = h2b(key["hnet_pubkey"]) |
| 338 | out_bytes += pubkey_bytes |
| 339 | |
| 340 | # fill length |
| 341 | out_bytes[1] = length |
| 342 | return out_bytes |
| 343 | |
| 344 | def _encode_hex(self, in_json): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 345 | out_bytes = self._encode_prot_scheme_id_list( |
| 346 | in_json['prot_scheme_id_list']) |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 347 | out_bytes += self._encode_hnet_pubkey_list(in_json['hnet_pubkey_list']) |
| 348 | return "".join(["%02X" % i for i in out_bytes]) |
| 349 | |
| 350 | def _decode_prot_scheme_id_list(self, in_bytes): |
| 351 | prot_scheme_id_list = [] |
| 352 | pos = 0 |
| 353 | # two bytes per entry |
| 354 | while pos < len(in_bytes): |
| 355 | prot_scheme = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 356 | 'priority': pos//2, # first in list: high priority |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 357 | 'identifier': in_bytes[pos], |
| 358 | 'key_index': in_bytes[pos+1] |
| 359 | } |
| 360 | pos += 2 |
| 361 | prot_scheme_id_list.append(prot_scheme) |
| 362 | return prot_scheme_id_list |
| 363 | |
| 364 | def _decode_hnet_pubkey_list(self, in_bytes): |
| 365 | hnet_pubkey_list = [] |
| 366 | pos = 0 |
| 367 | if in_bytes[pos] != 0xa1: |
| 368 | print("missing Home Network Public Key List data object") |
| 369 | return {} |
| 370 | pos += 1 |
| 371 | hnet_pubkey_list_len = in_bytes[pos] |
| 372 | pos += 1 |
| 373 | |
| 374 | while pos < hnet_pubkey_list_len: |
| 375 | if in_bytes[pos] != 0x80: |
| 376 | print("missing Home Network Public Key Identifier tag") |
| 377 | return {} |
| 378 | pos += 1 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 379 | # TODO might be more than 1 byte? |
| 380 | hnet_pubkey_id_len = in_bytes[pos] |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 381 | pos += 1 |
| 382 | hnet_pubkey_id = in_bytes[pos:pos+hnet_pubkey_id_len][0] |
| 383 | pos += hnet_pubkey_id_len |
| 384 | if in_bytes[pos] != 0x81: |
| 385 | print("missing Home Network Public Key tag") |
| 386 | return {} |
| 387 | pos += 1 |
| 388 | hnet_pubkey_len = in_bytes[pos] |
| 389 | pos += 1 |
| 390 | hnet_pubkey = in_bytes[pos:pos+hnet_pubkey_len] |
| 391 | pos += hnet_pubkey_len |
| 392 | |
| 393 | hnet_pubkey_list.append({ |
| 394 | 'hnet_pubkey_identifier': hnet_pubkey_id, |
| 395 | 'hnet_pubkey': b2h(hnet_pubkey) |
| 396 | }) |
| 397 | |
| 398 | return hnet_pubkey_list |
| 399 | |
| 400 | def _decode_bin(self, in_bin): |
Vadim Yanitskiy | 5e41eeb | 2021-05-02 02:20:33 +0200 | [diff] [blame] | 401 | return self._decode_hex(b2h(in_bin)) |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 402 | |
| 403 | def _decode_hex(self, in_hex): |
| 404 | in_bytes = h2b(in_hex) |
| 405 | pos = 0 |
| 406 | |
| 407 | if in_bytes[pos] != 0xa0: |
| 408 | print("missing Protection Scheme Identifier List data object tag") |
| 409 | return {} |
| 410 | pos += 1 |
| 411 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 412 | prot_scheme_id_list_len = in_bytes[pos] # TODO maybe more than 1 byte |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 413 | pos += 1 |
| 414 | # decode Protection Scheme Identifier List data object |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 415 | prot_scheme_id_list = self._decode_prot_scheme_id_list( |
| 416 | in_bytes[pos:pos+prot_scheme_id_list_len]) |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 417 | pos += prot_scheme_id_list_len |
| 418 | |
| 419 | # remaining data holds Home Network Public Key Data Object |
| 420 | hnet_pubkey_list = self._decode_hnet_pubkey_list(in_bytes[pos:]) |
| 421 | |
| 422 | return { |
| 423 | 'prot_scheme_id_list': prot_scheme_id_list, |
| 424 | 'hnet_pubkey_list': hnet_pubkey_list |
| 425 | } |
| 426 | |
| 427 | def _encode_bin(self, in_json): |
| 428 | return h2b(self._encode_hex(in_json)) |
| 429 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 430 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 431 | class EF_LI(TransRecEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 432 | def __init__(self, fid='6f05', sfid=None, name='EF.LI', size=(2, None), rec_len=2, |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 433 | desc='Language Indication'): |
| 434 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 435 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 436 | def _decode_record_bin(self, in_bin, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 437 | if in_bin == b'\xff\xff': |
| 438 | return None |
| 439 | else: |
| 440 | # officially this is 7-bit GSM alphabet with one padding bit in each byte |
| 441 | return in_bin.decode('ascii') |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 442 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 443 | def _encode_record_bin(self, in_json, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 444 | if in_json == None: |
| 445 | return b'\xff\xff' |
| 446 | else: |
| 447 | # officially this is 7-bit GSM alphabet with one padding bit in each byte |
| 448 | return in_json.encode('ascii') |
| 449 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 450 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 451 | class EF_Keys(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 452 | def __init__(self, fid='6f08', sfid=0x08, name='EF.Keys', size=(33, 33), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 453 | desc='Ciphering and Integrity Keys'): |
| 454 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 455 | self._construct = Struct( |
| 456 | 'ksi'/Int8ub, 'ck'/HexAdapter(Bytes(16)), 'ik'/HexAdapter(Bytes(16))) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 457 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 458 | # TS 31.102 Section 4.2.6 |
| 459 | class EF_HPPLMN(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 460 | _test_de_encode = [ ( '05', 5 ) ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 461 | def __init__(self, fid='6f31', sfid=0x12, name='EF.HPPLMN', size=(1, 1), |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 462 | desc='Higher Priority PLMN search period'): |
| 463 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 464 | self._construct = Int8ub |
| 465 | |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 466 | class EF_UST(EF_UServiceTable): |
| 467 | def __init__(self, **kwargs): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 468 | super().__init__(fid='6f38', sfid=0x04, name='EF.UST', desc='USIM Service Table', size=(1,17), table=EF_UST_map, **kwargs) |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 469 | # add those commands to the general commands of a TransparentEF |
| 470 | self.shell_commands += [self.AddlShellCommands()] |
| 471 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 472 | @with_default_category('File-Specific Commands') |
| 473 | class AddlShellCommands(CommandSet): |
| 474 | def __init__(self): |
| 475 | super().__init__() |
| 476 | |
| 477 | def do_ust_service_activate(self, arg): |
| 478 | """Activate a service within EF.UST""" |
Alexander Couzens | 6c5c3f8 | 2023-07-28 05:13:06 +0200 | [diff] [blame] | 479 | selected_file = self._cmd.lchan.selected_file |
| 480 | selected_file.ust_update(self._cmd, [int(arg)], []) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 481 | |
| 482 | def do_ust_service_deactivate(self, arg): |
| 483 | """Deactivate a service within EF.UST""" |
Alexander Couzens | 6c5c3f8 | 2023-07-28 05:13:06 +0200 | [diff] [blame] | 484 | selected_file = self._cmd.lchan.selected_file |
| 485 | selected_file.ust_update(self._cmd, [], [int(arg)]) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 486 | |
Harald Welte | 4c5e231 | 2022-02-12 14:37:48 +0100 | [diff] [blame] | 487 | def do_ust_service_check(self, arg): |
Harald Welte | 3bb516b | 2022-02-12 21:53:18 +0100 | [diff] [blame] | 488 | """Check consistency between services of this file and files present/activated. |
| 489 | |
| 490 | Many services determine if one or multiple files shall be present/activated or if they shall be |
| 491 | absent/deactivated. This performs a consistency check to ensure that no services are activated |
| 492 | for files that are not - and vice-versa, no files are activated for services that are not. Error |
| 493 | messages are printed for every inconsistency found.""" |
Harald Welte | a6c0f88 | 2022-07-17 14:23:17 +0200 | [diff] [blame] | 494 | selected_file = self._cmd.lchan.selected_file |
Harald Welte | 82f75c2 | 2022-02-12 18:22:28 +0100 | [diff] [blame] | 495 | num_problems = selected_file.ust_service_check(self._cmd) |
| 496 | # obtain list of currently active services |
| 497 | active_services = selected_file.get_active_services(self._cmd) |
| 498 | # Service n°46 can only be declared "available" if service n°45 is declared "available" |
| 499 | if 46 in active_services and not 45 in active_services: |
Harald Welte | fa8b8d1 | 2022-02-12 18:30:28 +0100 | [diff] [blame] | 500 | self._cmd.perror("ERROR: Service 46 available, but it requires Service 45") |
Harald Welte | 82f75c2 | 2022-02-12 18:22:28 +0100 | [diff] [blame] | 501 | num_problems += 1 |
| 502 | # Service n°125 shall only be taken into account if Service n°124 is declared "available" |
| 503 | if 125 in active_services and not 124 in active_services: |
Harald Welte | fa8b8d1 | 2022-02-12 18:30:28 +0100 | [diff] [blame] | 504 | self._cmd.perror("ERROR: Service 125 is ignored as Service 124 not available") |
Harald Welte | 82f75c2 | 2022-02-12 18:22:28 +0100 | [diff] [blame] | 505 | num_problems += 1 |
| 506 | # Service n°95, n°99 and n°115 shall not be declared "available" if an ISIM application is present on the UICC |
| 507 | non_isim_services = [95, 99, 115] |
| 508 | app_names = selected_file.get_mf().get_app_names() |
| 509 | if 'ADF.ISIM' in app_names: |
| 510 | for s in non_isim_services: |
| 511 | if s in active_services: |
Harald Welte | fa8b8d1 | 2022-02-12 18:30:28 +0100 | [diff] [blame] | 512 | self._cmd.perror("ERROR: Service %u shall not be available as ISIM application is present" % s) |
Harald Welte | 82f75c2 | 2022-02-12 18:22:28 +0100 | [diff] [blame] | 513 | num_problems += 1 |
| 514 | self._cmd.poutput("===> %u service / file inconsistencies detected" % num_problems) |
Harald Welte | 4c5e231 | 2022-02-12 14:37:48 +0100 | [diff] [blame] | 515 | |
| 516 | |
Harald Welte | 89e5954 | 2021-04-02 21:33:13 +0200 | [diff] [blame] | 517 | # TS 31.103 Section 4.2.7 - *not* the same as DF.GSM/EF.ECC! |
| 518 | class EF_ECC(LinFixedEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 519 | _test_de_encode = [ |
| 520 | ( '19f1ff01', { "call_code": "911f", |
| 521 | "service_category": { "police": True, "ambulance": False, "fire_brigade": False, |
| 522 | "marine_guard": False, "mountain_rescue": False, |
| 523 | "manual_ecall": False, "automatic_ecall": False } } ), |
| 524 | ( '19f3ff02', { "call_code": "913f", |
| 525 | "service_category": { "police": False, "ambulance": True, "fire_brigade": False, |
| 526 | "marine_guard": False, "mountain_rescue": False, |
| 527 | "manual_ecall": False, "automatic_ecall": False } } ), |
| 528 | ] |
| 529 | cc_construct = BcdAdapter(Rpad(Bytes(3))) |
Harald Welte | ff2d86d | 2022-01-21 15:19:47 +0100 | [diff] [blame] | 530 | category_construct = FlagsEnum(Byte, police=1, ambulance=2, fire_brigade=3, marine_guard=4, |
| 531 | mountain_rescue=5, manual_ecall=6, automatic_ecall=7) |
Harald Welte | 6e6caa8 | 2023-12-27 22:04:50 +0100 | [diff] [blame] | 532 | alpha_construct = GsmOrUcs2Adapter(Rpad(GreedyBytes)) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 533 | |
Harald Welte | 89e5954 | 2021-04-02 21:33:13 +0200 | [diff] [blame] | 534 | def __init__(self, fid='6fb7', sfid=0x01, name='EF.ECC', |
| 535 | desc='Emergency Call Codes'): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 536 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(4, 20)) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 537 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 538 | def _decode_record_bin(self, in_bin, **kwargs): |
Harald Welte | ff2d86d | 2022-01-21 15:19:47 +0100 | [diff] [blame] | 539 | # mandatory parts |
| 540 | code = in_bin[:3] |
| 541 | if code == b'\xff\xff\xff': |
| 542 | return None |
| 543 | svc_category = in_bin[-1:] |
| 544 | ret = {'call_code': parse_construct(EF_ECC.cc_construct, code), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 545 | 'service_category': parse_construct(EF_ECC.category_construct, svc_category)} |
Harald Welte | ff2d86d | 2022-01-21 15:19:47 +0100 | [diff] [blame] | 546 | # optional alpha identifier |
| 547 | if len(in_bin) > 4: |
| 548 | alpha_id = in_bin[3:-1] |
| 549 | ret['alpha_id'] = parse_construct(EF_ECC.alpha_construct, alpha_id) |
| 550 | return ret |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 551 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 552 | def _encode_record_bin(self, in_json, **kwargs): |
Harald Welte | ff2d86d | 2022-01-21 15:19:47 +0100 | [diff] [blame] | 553 | if in_json is None: |
| 554 | return b'\xff\xff\xff\xff' |
| 555 | code = EF_ECC.cc_construct.build(in_json['call_code']) |
Harald Welte | 9b9efb6 | 2023-01-31 16:40:54 +0100 | [diff] [blame] | 556 | svc_category = EF_ECC.category_construct.build(in_json['service_category']) |
| 557 | if 'alpha_id' in in_json: |
| 558 | alpha_id = EF_ECC.alpha_construct.build(in_json['alpha_id']) |
| 559 | # FIXME: alpha_id needs padding up to 'record_length - 4' |
| 560 | else: |
| 561 | alpha_id = b'' |
Harald Welte | ff2d86d | 2022-01-21 15:19:47 +0100 | [diff] [blame] | 562 | return code + alpha_id + svc_category |
| 563 | |
Harald Welte | 89e5954 | 2021-04-02 21:33:13 +0200 | [diff] [blame] | 564 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 565 | # TS 31.102 Section 4.2.17 |
| 566 | class EF_LOCI(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 567 | _test_de_encode = [ |
| 568 | ( '47d1264a62f21037211e00', |
Harald Welte | 842fbdb | 2023-12-27 17:06:58 +0100 | [diff] [blame] | 569 | { "tmsi": "47d1264a", "lai": { "mcc_mnc": "262-01", "lac": "3721" }, |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 570 | "rfu": 30, "lu_status": 0 } ), |
Harald Welte | 324175f | 2023-12-21 20:25:30 +0100 | [diff] [blame] | 571 | ( 'ffffffff62f2200000ff01', |
Harald Welte | 842fbdb | 2023-12-27 17:06:58 +0100 | [diff] [blame] | 572 | {"tmsi": "ffffffff", "lai": {"mcc_mnc": "262-02", "lac": "0000"}, "rfu": 255, "lu_status": 1} ), |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 573 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 574 | def __init__(self, fid='6f7e', sfid=0x0b, name='EF.LOCI', desc='Location information', size=(11, 11)): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 575 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Harald Welte | 842fbdb | 2023-12-27 17:06:58 +0100 | [diff] [blame] | 576 | Lai = Struct('mcc_mnc'/PlmnAdapter(Bytes(3)), 'lac'/HexAdapter(Bytes(2))) |
Harald Welte | 3a5afff | 2022-02-25 15:33:46 +0100 | [diff] [blame] | 577 | self._construct = Struct('tmsi'/HexAdapter(Bytes(4)), 'lai'/Lai, 'rfu'/Int8ub, 'lu_status'/Int8ub) |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 578 | |
Harald Welte | 592b32e | 2021-06-05 11:26:36 +0200 | [diff] [blame] | 579 | # TS 31.102 Section 4.2.18 |
| 580 | class EF_AD(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 581 | _test_de_encode = [ |
| 582 | ( '00000002', { "ms_operation_mode": "normal", |
| 583 | "additional_info": { "ciphering_indicator": False, "csg_display_control": False, |
| 584 | "prose_services": False, "extended_drx": False }, |
| 585 | "rfu": 0, "mnc_len": 2, "extensions": b'' } ), |
| 586 | ( '01000102', { "ms_operation_mode": "normal_and_specific_facilities", |
| 587 | "additional_info": { "ciphering_indicator": True, "csg_display_control": False, |
| 588 | "prose_services": False, "extended_drx": False }, |
| 589 | "rfu": 0, "mnc_len": 2, "extensions": b'' } ), |
| 590 | ] |
Harald Welte | 592b32e | 2021-06-05 11:26:36 +0200 | [diff] [blame] | 591 | class OP_MODE(enum.IntEnum): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 592 | normal = 0x00 |
| 593 | type_approval = 0x80 |
| 594 | normal_and_specific_facilities = 0x01 |
| 595 | type_approval_and_specific_facilities = 0x81 |
| 596 | maintenance_off_line = 0x02 |
| 597 | cell_test = 0x04 |
Harald Welte | 592b32e | 2021-06-05 11:26:36 +0200 | [diff] [blame] | 598 | |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 599 | def __init__(self, fid='6fad', sfid=0x03, name='EF.AD', desc='Administrative Data', size=(4, 6)): |
Harald Welte | 592b32e | 2021-06-05 11:26:36 +0200 | [diff] [blame] | 600 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 601 | self._construct = BitStruct( |
| 602 | # Byte 1 |
| 603 | 'ms_operation_mode'/Bytewise(Enum(Byte, EF_AD.OP_MODE)), |
| 604 | # Byte 2 + 3 |
| 605 | 'additional_info'/Bytewise(FlagsEnum(Int16ub, ciphering_indicator=1, csg_display_control=2, |
| 606 | prose_services=4, extended_drx=8)), |
| 607 | 'rfu'/BitsRFU(4), |
| 608 | 'mnc_len'/BitsInteger(4), |
| 609 | 'extensions'/COptional(Bytewise(GreedyBytesRFU)) |
| 610 | ) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 611 | |
| 612 | # TS 31.102 Section 4.2.23 |
| 613 | class EF_PSLOCI(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 614 | def __init__(self, fid='6f73', sfid=0x0c, name='EF.PSLOCI', desc='PS Location information', size=(14, 14)): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 615 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 616 | self._construct = Struct('ptmsi'/HexAdapter(Bytes(4)), 'ptmsi_sig'/HexAdapter(Bytes(3)), |
| 617 | 'rai'/HexAdapter(Bytes(6)), 'rau_status'/Int8ub) |
| 618 | |
| 619 | # TS 31.102 Section 4.2.33 |
| 620 | class EF_ICI(CyclicEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 621 | def __init__(self, fid='6f80', sfid=0x14, name='EF.ICI', rec_len=(28, 48), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 622 | desc='Incoming Call Information', **kwargs): |
| 623 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 624 | self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-28)), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 625 | 'len_of_bcd_contents'/Int8ub, |
| 626 | 'ton_npi'/Int8ub, |
| 627 | 'call_number'/BcdAdapter(Bytes(10)), |
| 628 | 'cap_cfg2_record_id'/Int8ub, |
| 629 | 'ext5_record_id'/Int8ub, |
| 630 | 'date_and_time'/BcdAdapter(Bytes(7)), |
| 631 | 'duration'/Int24ub, |
| 632 | 'status'/Byte, |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 633 | 'link_to_phonebook'/HexAdapter(Bytes(3))) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 634 | |
| 635 | # TS 31.102 Section 4.2.34 |
| 636 | class EF_OCI(CyclicEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 637 | def __init__(self, fid='6f81', sfid=0x15, name='EF.OCI', rec_len=(27, 47), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 638 | desc='Outgoing Call Information', **kwargs): |
| 639 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 640 | self._construct = Struct('alpha_id'/HexAdapter(Bytes(this._.total_len-27)), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 641 | 'len_of_bcd_contents'/Int8ub, |
| 642 | 'ton_npi'/Int8ub, |
| 643 | 'call_number'/BcdAdapter(Bytes(10)), |
| 644 | 'cap_cfg2_record_id'/Int8ub, |
| 645 | 'ext5_record_id'/Int8ub, |
| 646 | 'date_and_time'/BcdAdapter(Bytes(7)), |
| 647 | 'duration'/Int24ub, |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 648 | 'link_to_phonebook'/HexAdapter(Bytes(3))) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 649 | |
| 650 | # TS 31.102 Section 4.2.35 |
| 651 | class EF_ICT(CyclicEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 652 | def __init__(self, fid='6f82', sfid=None, name='EF.ICT', rec_len=(3, 3), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 653 | desc='Incoming Call Timer', **kwargs): |
| 654 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 655 | self._construct = Struct('accumulated_call_timer'/Int24ub) |
| 656 | |
| 657 | # TS 31.102 Section 4.2.38 |
| 658 | class EF_CCP2(LinFixedEF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 659 | def __init__(self, fid='6f4f', sfid=0x16, name='EF.CCP2', desc='Capability Configuration Parameters 2', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 660 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(15, None), **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 661 | |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 662 | # TS 31.102 Section 4.2.47 |
| 663 | class EF_EST(EF_UServiceTable): |
| 664 | def __init__(self, **kwargs): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 665 | super().__init__(fid='6f56', sfid=0x05, name='EF.EST', desc='Enabled Services Table', size=(1,None), table=EF_EST_map, **kwargs) |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 666 | # add those commands to the general commands of a TransparentEF |
| 667 | self.shell_commands += [self.AddlShellCommands()] |
| 668 | |
| 669 | @with_default_category('File-Specific Commands') |
| 670 | class AddlShellCommands(CommandSet): |
| 671 | def __init__(self): |
| 672 | super().__init__() |
| 673 | |
Harald Welte | 18b7539 | 2023-02-23 10:00:51 +0100 | [diff] [blame] | 674 | def do_est_service_enable(self, arg): |
Alexander Couzens | c8facea | 2023-07-29 05:01:57 +0200 | [diff] [blame] | 675 | """Enable a service within EF.EST""" |
| 676 | selected_file = self._cmd.lchan.selected_file |
| 677 | selected_file.ust_update(self._cmd, [int(arg)], []) |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 678 | |
Harald Welte | 18b7539 | 2023-02-23 10:00:51 +0100 | [diff] [blame] | 679 | def do_est_service_disable(self, arg): |
Alexander Couzens | c8facea | 2023-07-29 05:01:57 +0200 | [diff] [blame] | 680 | """Disable a service within EF.EST""" |
| 681 | selected_file = self._cmd.lchan.selected_file |
| 682 | selected_file.ust_update(self._cmd, [], [int(arg)]) |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 683 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 684 | # TS 31.102 Section 4.2.48 |
| 685 | class EF_ACL(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 686 | def __init__(self, fid='6f57', sfid=None, name='EF.ACL', size=(32, None), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 687 | desc='Access Point Name Control List', **kwargs): |
| 688 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 689 | self._construct = Struct('num_of_apns'/Int8ub, 'tlvs'/HexAdapter(GreedyBytes)) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 690 | |
| 691 | # TS 31.102 Section 4.2.51 |
| 692 | class EF_START_HFN(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 693 | _test_de_encode = [ |
| 694 | ( 'f00000f00000', { "start_cs": 15728640, "start_ps": 15728640 } ), |
| 695 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 696 | def __init__(self, fid='6f5b', sfid=0x0f, name='EF.START-HFN', size=(6, 6), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 697 | desc='Initialisation values for Hyperframe number', **kwargs): |
| 698 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 699 | self._construct = Struct('start_cs'/Int24ub, 'start_ps'/Int24ub) |
| 700 | |
| 701 | # TS 31.102 Section 4.2.52 |
| 702 | class EF_THRESHOLD(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 703 | _test_de_encode = [ |
| 704 | ( 'f01000', { "max_start": 15732736 } ), |
| 705 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 706 | def __init__(self, fid='6f5c', sfid=0x10, name='EF.THRESHOLD', size=(3, 3), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 707 | desc='Maximum value of START', **kwargs): |
| 708 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 709 | self._construct = Struct('max_start'/Int24ub) |
| 710 | |
Harald Welte | 363edd9 | 2022-07-17 22:24:03 +0200 | [diff] [blame] | 711 | # TS 31.102 (old releases like 3.8.0) Section 4.2.56 |
| 712 | class EF_RPLMNAcT(TransRecEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 713 | def __init__(self, fid='6f65', sfid=None, name='EF.RPLMNAcTD', size=(2, 4), rec_len=2, |
Harald Welte | 363edd9 | 2022-07-17 22:24:03 +0200 | [diff] [blame] | 714 | desc='RPLMN Last used Access Technology', **kwargs): |
| 715 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 716 | def _decode_record_hex(self, in_hex, **kwargs): |
Harald Welte | 363edd9 | 2022-07-17 22:24:03 +0200 | [diff] [blame] | 717 | return dec_act(in_hex) |
| 718 | # TODO: Encode |
| 719 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 720 | # TS 31.102 Section 4.2.77 |
| 721 | class EF_VGCSCA(TransRecEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 722 | def __init__(self, fid='6fd4', sfid=None, name='EF.VGCSCA', size=(2, 100), rec_len=2, |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 723 | desc='Voice Group Call Service Ciphering Algorithm', **kwargs): |
| 724 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 725 | self._construct = Struct('alg_v_ki_1'/Int8ub, 'alg_v_ki_2'/Int8ub) |
| 726 | |
| 727 | # TS 31.102 Section 4.2.79 |
| 728 | class EF_GBABP(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 729 | def __init__(self, fid='6fd6', sfid=None, name='EF.GBABP', size=(3, 50), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 730 | desc='GBA Bootstrapping parameters', **kwargs): |
| 731 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 732 | self._construct = Struct('rand'/LV, 'b_tid'/LV, 'key_lifetime'/LV) |
| 733 | |
| 734 | # TS 31.102 Section 4.2.80 |
| 735 | class EF_MSK(LinFixedEF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 736 | def __init__(self, fid='6fd7', sfid=None, name='EF.MSK', desc='MBMS Service Key List', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 737 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(20, None), **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 738 | msk_ts_constr = Struct('msk_id'/Int32ub, 'timestamp_counter'/Int32ub) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 739 | self._construct = Struct('key_domain_id'/HexAdapter(Bytes(3)), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 740 | 'num_msk_id'/Int8ub, |
| 741 | 'msk_ids'/msk_ts_constr[this.num_msk_id]) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 742 | # TS 31.102 Section 4.2.81 |
| 743 | class EF_MUK(LinFixedEF): |
| 744 | class MUK_Idr(BER_TLV_IE, tag=0x80): |
| 745 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 746 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 747 | class MUK_Idi(BER_TLV_IE, tag=0x82): |
| 748 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 749 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 750 | class MUK_ID(BER_TLV_IE, tag=0xA0, nested=[MUK_Idr, MUK_Idi]): |
| 751 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 752 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 753 | class TimeStampCounter(BER_TLV_IE, tag=0x81): |
| 754 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 755 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 756 | class EF_MUK_Collection(TLV_IE_Collection, nested=[MUK_ID, TimeStampCounter]): |
| 757 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 758 | |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 759 | def __init__(self, fid='6fd8', sfid=None, name='EF.MUK', desc='MBMS User Key', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 760 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(None, None), **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 761 | self._tlv = EF_MUK.EF_MUK_Collection |
| 762 | |
| 763 | # TS 31.102 Section 4.2.83 |
| 764 | class EF_GBANL(LinFixedEF): |
| 765 | class NAF_ID(BER_TLV_IE, tag=0x80): |
| 766 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 767 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 768 | class B_TID(BER_TLV_IE, tag=0x81): |
| 769 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 770 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 771 | class EF_GBANL_Collection(BER_TLV_IE, nested=[NAF_ID, B_TID]): |
| 772 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 773 | |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 774 | def __init__(self, fid='6fda', sfid=None, name='EF.GBANL', desc='GBA NAF List', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 775 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(None, None), **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 776 | self._tlv = EF_GBANL.EF_GBANL_Collection |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 777 | |
| 778 | # TS 31.102 Section 4.2.85 |
| 779 | class EF_EHPLMNPI(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 780 | _test_de_encode = [ |
Harald Welte | 324175f | 2023-12-21 20:25:30 +0100 | [diff] [blame] | 781 | ( '00', {"presentation_ind": "no_preference"} ), |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 782 | ( '02', { "presentation_ind": "display_all" } ), |
| 783 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 784 | def __init__(self, fid='6fdb', sfid=None, name='EF.EHPLMNPI', size=(1, 1), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 785 | desc='Equivalent HPLMN Presentation Indication', **kwargs): |
| 786 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 787 | self._construct = Struct('presentation_ind' / |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 788 | Enum(Byte, no_preference=0, display_highest_prio_only=1, display_all=2)) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 789 | |
| 790 | # TS 31.102 Section 4.2.87 |
| 791 | class EF_NAFKCA(LinFixedEF): |
| 792 | class NAF_KeyCentreAddress(BER_TLV_IE, tag=0x80): |
| 793 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 794 | def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', rec_len=(None, None), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 795 | desc='NAF Key Centre Address', **kwargs): |
| 796 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 797 | self._tlv = EF_NAFKCA.NAF_KeyCentreAddress |
| 798 | |
| 799 | # TS 31.102 Section 4.2.90 |
| 800 | class EF_NCP_IP(LinFixedEF): |
| 801 | class DataDestAddrRange(TLV_IE, tag=0x83): |
| 802 | _construct = Struct('type_of_address'/Enum(Byte, IPv4=0x21, IPv6=0x56), |
| 803 | 'prefix_length'/Int8ub, |
| 804 | 'prefix'/HexAdapter(GreedyBytes)) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 805 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 806 | class AccessPointName(TLV_IE, tag=0x80): |
| 807 | # coded as per TS 23.003 |
| 808 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 809 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 810 | class Login(TLV_IE, tag=0x81): |
| 811 | # as per SMS DCS TS 23.038 |
| 812 | _construct = GsmStringAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 813 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 814 | class Password(TLV_IE, tag=0x82): |
| 815 | # as per SMS DCS TS 23.038 |
| 816 | _construct = GsmStringAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 817 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 818 | class BearerDescription(TLV_IE, tag=0x84): |
| 819 | # Bearer descriptionTLV DO as per TS 31.111 |
| 820 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 821 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 822 | class EF_NCP_IP_Collection(TLV_IE_Collection, |
| 823 | nested=[AccessPointName, Login, Password, BearerDescription]): |
| 824 | pass |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 825 | def __init__(self, fid='6fe2', sfid=None, name='EF.NCP-IP', rec_len=(None, None), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 826 | desc='Network Connectivity Parameters for USIM IP connections', **kwargs): |
| 827 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 828 | self._tlv = EF_NCP_IP.EF_NCP_IP_Collection |
| 829 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 830 | # TS 31.102 Section 4.2.91 |
| 831 | class EF_EPSLOCI(TransparentEF): |
Harald Welte | 1272129 | 2022-07-21 15:33:06 +0200 | [diff] [blame] | 832 | def __init__(self, fid='6fe3', sfid=0x1e, name='EF.EPSLOCI', |
| 833 | desc='EPS Location Information', size=(18,18), **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 834 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 835 | upd_status_constr = Enum( |
| 836 | Byte, updated=0, not_updated=1, roaming_not_allowed=2) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 837 | self._construct = Struct('guti'/HexAdapter(Bytes(12)), |
| 838 | 'last_visited_registered_tai'/HexAdapter(Bytes(5)), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 839 | 'eps_update_status'/upd_status_constr) |
| 840 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 841 | # TS 31.102 Section 4.2.92 |
| 842 | class EF_EPSNSC(LinFixedEF): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 843 | class KSI_ASME(BER_TLV_IE, tag=0x80): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 844 | _construct = Int8ub |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 845 | |
| 846 | class K_ASME(BER_TLV_IE, tag=0x81): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 847 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 848 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 849 | class UplinkNASCount(BER_TLV_IE, tag=0x82): |
| 850 | _construct = Int32ub |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 851 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 852 | class DownlinkNASCount(BER_TLV_IE, tag=0x83): |
| 853 | _construct = Int32ub |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 854 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 855 | class IDofNASAlgorithms(BER_TLV_IE, tag=0x84): |
| 856 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 857 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 858 | class EPS_NAS_Security_Context(BER_TLV_IE, tag=0xa0, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 859 | nested=[KSI_ASME, K_ASME, UplinkNASCount, DownlinkNASCount, |
| 860 | IDofNASAlgorithms]): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 861 | pass |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 862 | def __init__(self, fid='6fe4', sfid=0x18, name='EF.EPSNSC', rec_len=(54, 128), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 863 | desc='EPS NAS Security Context', **kwargs): |
| 864 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 865 | self._tlv = EF_EPSNSC.EPS_NAS_Security_Context |
| 866 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 867 | # TS 31.102 Section 4.2.96 |
| 868 | class EF_PWS(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 869 | _test_de_encode = [ |
| 870 | ( '00', { "pws_configuration": { "ignore_pws_in_hplmn_and_equivalent": False, |
| 871 | "ignore_pws_in_vplmn": False } } ), |
| 872 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 873 | def __init__(self, fid='6fec', sfid=None, name='EF.PWS', desc='Public Warning System', size=(1, 1), **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 874 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 875 | pws_config = FlagsEnum( |
| 876 | Byte, ignore_pws_in_hplmn_and_equivalent=1, ignore_pws_in_vplmn=2) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 877 | self._construct = Struct('pws_configuration'/pws_config) |
| 878 | |
| 879 | # TS 31.102 Section 4.2.101 |
| 880 | class EF_IPS(CyclicEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 881 | def __init__(self, fid='6ff1', sfid=None, name='EF.IPS', rec_len=(4, 4), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 882 | desc='IMEI(SV) Pairing Status', **kwargs): |
| 883 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 884 | self._construct = Struct('status'/PaddedString(2, 'ascii'), |
| 885 | 'link_to_ef_ipd'/Int8ub, 'rfu'/Byte) |
| 886 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 887 | # TS 31.102 Section 4.2.103 |
| 888 | class EF_ePDGId(TransparentEF): |
Harald Welte | 478b5fe | 2023-12-08 14:27:50 +0100 | [diff] [blame] | 889 | _test_de_encode = [ |
| 890 | ( '801100657064672e6f736d6f636f6d2e6f7267', {'e_pdg_id': {"type_of_ePDG_address": "FQDN", "ePDG_address" : "epdg.osmocom.org" } } ), |
Harald Welte | 6e9ae8a | 2023-12-08 14:57:19 +0100 | [diff] [blame] | 891 | ( '800501c0a8a001', {'e_pdg_id': {"type_of_ePDG_address": "IPv4", "ePDG_address" : "192.168.160.1" } } ), |
| 892 | ( '80110220010db8000000000000000000000023', {'e_pdg_id': {"type_of_ePDG_address": "IPv6", "ePDG_address" : "2001:db8::23" } } ), |
Harald Welte | 478b5fe | 2023-12-08 14:27:50 +0100 | [diff] [blame] | 893 | ] |
| 894 | class ePDGId(BER_TLV_IE, tag=0x80): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 895 | _construct = Struct('type_of_ePDG_address'/Enum(Byte, FQDN=0, IPv4=1, IPv6=2), |
Harald Welte | 478b5fe | 2023-12-08 14:27:50 +0100 | [diff] [blame] | 896 | 'ePDG_address'/Switch(this.type_of_ePDG_address, |
Philipp Maier | 791f80a | 2023-07-26 17:01:37 +0200 | [diff] [blame] | 897 | {'FQDN': Utf8Adapter(GreedyBytes), |
Harald Welte | 6e9ae8a | 2023-12-08 14:57:19 +0100 | [diff] [blame] | 898 | 'IPv4': Ipv4Adapter(GreedyBytes), |
| 899 | 'IPv6': Ipv6Adapter(GreedyBytes)})) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 900 | |
iw0 | 40ef226 | 2023-11-07 13:41:12 +0100 | [diff] [blame] | 901 | def __init__(self, fid='6ff3', sfid=None, name='EF.ePDGId', desc='Home ePDG Identifier', **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 902 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 903 | self._tlv = EF_ePDGId.ePDGId |
| 904 | |
Harald Welte | cdfe1c2 | 2023-12-08 12:30:21 +0100 | [diff] [blame] | 905 | # TS 31.102 Section 4.2.104 |
| 906 | class EF_ePDGSelection(TransparentEF): |
Harald Welte | 478b5fe | 2023-12-08 14:27:50 +0100 | [diff] [blame] | 907 | _test_de_encode = [ |
Harald Welte | 842fbdb | 2023-12-27 17:06:58 +0100 | [diff] [blame] | 908 | ( '800600f110000100', {'e_pdg_selection': [{'plmn': '001-01', 'epdg_priority': 1, 'epdg_fqdn_format': 'operator_identified' }] }), |
| 909 | ( '800600011000a001', {'e_pdg_selection': [{'plmn': '001-001', 'epdg_priority': 160, 'epdg_fqdn_format': 'location_based' }] }), |
Harald Welte | 478b5fe | 2023-12-08 14:27:50 +0100 | [diff] [blame] | 910 | ] |
| 911 | class ePDGSelection(BER_TLV_IE, tag=0x80): |
Harald Welte | 842fbdb | 2023-12-27 17:06:58 +0100 | [diff] [blame] | 912 | _construct = GreedyRange(Struct('plmn'/PlmnAdapter(Bytes(3)), |
Harald Welte | cdfe1c2 | 2023-12-08 12:30:21 +0100 | [diff] [blame] | 913 | 'epdg_priority'/Int16ub, |
| 914 | 'epdg_fqdn_format'/Enum(Int8ub, operator_identified=0, location_based=1))) |
| 915 | |
| 916 | def __init__(self, fid='6ff4', sfid=None, name='EF.ePDGSelection', desc='ePDG Selection Information', **kwargs): |
| 917 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 918 | self._tlv = EF_ePDGSelection.ePDGSelection |
| 919 | |
Harald Welte | 7129007 | 2021-04-21 10:58:24 +0200 | [diff] [blame] | 920 | # TS 31.102 Section 4.2.106 |
| 921 | class EF_FromPreferred(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 922 | def __init__(self, fid='6ff7', sfid=None, name='EF.FromPreferred', size=(1, 1), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 923 | desc='From Preferred', **kwargs): |
| 924 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 45477a7 | 2023-11-03 01:33:06 +0100 | [diff] [blame] | 925 | self._construct = BitStruct('rfu'/BitsRFU(7), 'from_preferred'/Flag) |
Harald Welte | 7129007 | 2021-04-21 10:58:24 +0200 | [diff] [blame] | 926 | |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 927 | # TS 31.102 Section 4.2.114 |
| 928 | class EF_eAKA(TransparentEF): |
| 929 | def __init__(self, fid='6f01', sfid=None, name='EF.eAKA', size=(1, 1), |
| 930 | desc='enhanced AKA support', **kwargs): |
| 931 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 45477a7 | 2023-11-03 01:33:06 +0100 | [diff] [blame] | 932 | self._construct = BitStruct('rfu'/BitsRFU(7), 'enhanced_sqn_calculation_supported'/Flag) |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 933 | |
Harald Welte | d90ceb8 | 2022-07-17 22:10:58 +0200 | [diff] [blame] | 934 | |
| 935 | ###################################################################### |
| 936 | # DF.GSM-ACCESS |
| 937 | ###################################################################### |
| 938 | |
| 939 | class DF_GSM_ACCESS(CardDF): |
| 940 | def __init__(self, fid='5F3B', name='DF.GSM-ACCESS', desc='GSM Access', **kwargs): |
| 941 | super().__init__(fid=fid, name=name, desc=desc, service=27, **kwargs) |
| 942 | files = [ |
| 943 | EF_Kc(fid='4f20', sfid=0x01, service=27), |
| 944 | EF_Kc(fid='4f52', sfid=0x02, name='EF.KcGPRS', desc='GPRS Ciphering key KcGPRS', service=27), |
| 945 | EF_CPBCCH(fid='4f63', service=39), |
| 946 | EF_InvScan(fid='4f64', service=40), |
| 947 | ] |
| 948 | self.add_files(files) |
| 949 | |
| 950 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 951 | ###################################################################### |
Harald Welte | a77f7e1 | 2023-12-27 16:29:00 +0100 | [diff] [blame^] | 952 | # DF.NHB |
| 953 | ###################################################################### |
| 954 | |
| 955 | # 3GPP TS 31.102 Section 4.4.6.2 |
| 956 | class EF_ACSGL(LinFixedEF): |
| 957 | _test_de_encode = [ |
| 958 | ( 'a00d800362f21081060000000002e0', |
| 959 | {'csg_list': [{'plmn': '262-01'}, |
| 960 | {'csg_information': { 'csg_type': 'from_other_sources', |
| 961 | 'hnb_name_indication': 'from_other_sources', |
| 962 | 'csg_id': { 'id': 23 } } } ] } ), |
| 963 | ] |
| 964 | class Plmn(BER_TLV_IE, tag=0x80): |
| 965 | _construct = PlmnAdapter(Bytes(3)) |
| 966 | class CsgInformation(BER_TLV_IE, tag=0x81): |
| 967 | _construct = Struct('csg_type'/Enum(Int8ub, from_other_sources=0), |
| 968 | 'hnb_name_indication'/Enum(Int8ub, from_other_sources=0), |
| 969 | 'csg_id'/BitStruct('id'/BitsInteger(27), Padding(5))) |
| 970 | class CsgList(BER_TLV_IE, tag=0xa0, nested=[Plmn, CsgInformation]): |
| 971 | pass |
| 972 | def __init__(self, fid='4f81', sfid=0x01, name='EF.ACSGL', desc='Allowed CSG Lists', service=86, **kwargs): |
| 973 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs) |
| 974 | self._tlv = EF_ACSGL.CsgList |
| 975 | |
| 976 | # 3GPP TS 31.102 Section 4.4.6.3 |
| 977 | class EF_CSGT(LinFixedEF): |
| 978 | _test_de_encode = [ |
| 979 | ( '8906810300666f6f', [{ 'text_csg_type': 'foo' }] ), |
| 980 | ( '8906810300666f6f801068747470733a2f2f666f6f2e6261722f', |
| 981 | [{ 'text_csg_type': 'foo' }, { "graphics_csg_type_uri": "https://foo.bar/" }] ), |
| 982 | ] |
| 983 | class TextCsgType(BER_TLV_IE, tag=0x89): |
| 984 | _construct = Ucs2Adapter(GreedyBytes) |
| 985 | class GraphicsCsgTypeURI(BER_TLV_IE, tag=0x80): |
| 986 | _construct = Utf8Adapter(GreedyBytes) |
| 987 | class GraphicsCsgTypeEfImg(BER_TLV_IE, tag=0x81): |
| 988 | _construct = Int8ub |
| 989 | class Csgt_TLV_Collection(TLV_IE_Collection, |
| 990 | nested=[TextCsgType, GraphicsCsgTypeURI, GraphicsCsgTypeEfImg]): |
| 991 | pass |
| 992 | def __init__(self, fid='4f82', sfid=0x02, name='EF.CSGT', desc='CSG Types', service=86, **kwargs): |
| 993 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs) |
| 994 | self._tlv = EF_CSGT.Csgt_TLV_Collection |
| 995 | |
| 996 | |
| 997 | # 3GPP TS 31.102 Section 4.4.6.4 |
| 998 | class EF_HNBN(LinFixedEF): |
| 999 | _test_de_encode = [ |
| 1000 | ( '800b8108006d61686c7a656974', { 'hnb_name': 'mahlzeit' }), |
| 1001 | ] |
| 1002 | class HnbName(BER_TLV_IE, tag=0x80): |
| 1003 | _construct = Ucs2Adapter(GreedyBytes) |
| 1004 | def __init__(self, fid='4f83', sfid=0x03, name='EF.HNBN', desc='Home NodeB Name', service=86, **kwargs): |
| 1005 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs) |
| 1006 | self._tlv = EF_HNBN.HnbName |
| 1007 | |
| 1008 | # 3GPP TS 31.102 Section 4.4.6.5 |
| 1009 | class EF_OCSGL(LinFixedEF): |
| 1010 | _test_de_encode = [ |
| 1011 | ( 'a010800362f21081060000000002e0820100', |
| 1012 | {'operator_csg_list': [{'plmn': '262-01'}, |
| 1013 | {'csg_information': { 'csg_type': 'from_other_sources', |
| 1014 | 'hnb_name_indication': 'from_other_sources', |
| 1015 | 'csg_id': { 'id': 23 } } }, |
| 1016 | {'csg_display_indicator': 'all_available_csg_ids' } ] } ), |
| 1017 | |
| 1018 | ] |
| 1019 | class CsgDisplayIndicator(BER_TLV_IE, tag=0x82): |
| 1020 | _construct = Enum(Int8ub, all_available_csg_ids=0, only_ocsgl_csg_ids=1) |
| 1021 | class OperatorCsgList(BER_TLV_IE, tag=0xa0, nested=[EF_ACSGL.Plmn, EF_ACSGL.CsgInformation, CsgDisplayIndicator]): |
| 1022 | pass |
| 1023 | def __init__(self, fid='4f84', sfid=0x04, name='EF.OCSGL', desc='Operator CSG Lists', service=90, **kwargs): |
| 1024 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, service=service, rec_len=(1, None), **kwargs) |
| 1025 | self._tlv = EF_OCSGL.OperatorCsgList |
| 1026 | |
| 1027 | |
| 1028 | ###################################################################### |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1029 | # DF.5GS |
| 1030 | ###################################################################### |
| 1031 | |
| 1032 | # TS 31.102 Section 4.4.11.2 |
| 1033 | class EF_5GS3GPPLOCI(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1034 | def __init__(self, fid='4f01', sfid=0x01, name='EF.5GS3GPPLOCI', size=(20, 20), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1035 | desc='5S 3GP location information', **kwargs): |
| 1036 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1037 | upd_status_constr = Enum( |
| 1038 | Byte, updated=0, not_updated=1, roaming_not_allowed=2) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 1039 | self._construct = Struct('5g_guti'/HexAdapter(Bytes(13)), |
| 1040 | 'last_visited_registered_tai_in_5gs'/HexAdapter(Bytes(6)), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1041 | '5gs_update_status'/upd_status_constr) |
| 1042 | |
| 1043 | # TS 31.102 Section 4.4.11.7 |
| 1044 | class EF_UAC_AIC(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 1045 | _test_de_encode = [ |
| 1046 | ( '03', { "uac_access_id_config": { "multimedia_priority_service": True, |
| 1047 | "mission_critical_service": True } } ), |
| 1048 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1049 | def __init__(self, fid='4f06', sfid=0x06, name='EF.UAC_AIC', size=(4, 4), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1050 | desc='UAC Access Identities Configuration', **kwargs): |
| 1051 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1052 | cfg_constr = FlagsEnum(Byte, multimedia_priority_service=1, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1053 | mission_critical_service=2) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1054 | self._construct = Struct('uac_access_id_config'/cfg_constr) |
| 1055 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1056 | # TS 31.102 Section 4.4.11.9 |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1057 | class EF_OPL5G(LinFixedEF): |
Harald Welte | 5206429 | 2023-05-24 15:25:26 +0200 | [diff] [blame] | 1058 | def __init__(self, fid='4f08', sfid=0x08, name='EF.OPL5G', desc='5GS Operator PLMN List', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 1059 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=(10, None), **kwargs) |
Harald Welte | 842fbdb | 2023-12-27 17:06:58 +0100 | [diff] [blame] | 1060 | Tai = Struct('mcc_mnc'/PlmnAdapter(Bytes(3)), 'tac_min'/HexAdapter(Bytes(3)), |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 1061 | 'tac_max'/HexAdapter(Bytes(3))) |
Harald Welte | a037762 | 2022-02-25 15:36:44 +0100 | [diff] [blame] | 1062 | self._construct = Struct('tai'/Tai, 'pnn_record_id'/Int8ub) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1063 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1064 | # TS 31.102 Section 4.4.11.10 |
| 1065 | class EF_SUPI_NAI(TransparentEF): |
| 1066 | class NetworkSpecificIdentifier(TLV_IE, tag=0x80): |
| 1067 | # RFC 7542 encoded as UTF-8 string |
Philipp Maier | 791f80a | 2023-07-26 17:01:37 +0200 | [diff] [blame] | 1068 | _construct = Utf8Adapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1069 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1070 | class GlobalLineIdentifier(TLV_IE, tag=0x81): |
| 1071 | # TS 23.003 clause 28.16.2 |
Philipp Maier | 791f80a | 2023-07-26 17:01:37 +0200 | [diff] [blame] | 1072 | _construct = Utf8Adapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1073 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1074 | class GlobalCableIdentifier(TLV_IE, tag=0x82): |
| 1075 | # TS 23.003 clause 28.15.2 |
Philipp Maier | 791f80a | 2023-07-26 17:01:37 +0200 | [diff] [blame] | 1076 | _construct = Utf8Adapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1077 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1078 | class NAI_TLV_Collection(TLV_IE_Collection, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1079 | nested=[NetworkSpecificIdentifier, GlobalLineIdentifier, GlobalCableIdentifier]): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1080 | pass |
| 1081 | def __init__(self, fid='4f09', sfid=0x09, name='EF.SUPI_NAI', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1082 | desc='SUPI as Network Access Identifier', **kwargs): |
| 1083 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1084 | self._tlv = EF_SUPI_NAI.NAI_TLV_Collection |
| 1085 | |
Harald Welte | 455611c | 2023-05-27 12:48:54 +0200 | [diff] [blame] | 1086 | # TS 31.102 Section 4.4.11.11 |
| 1087 | class EF_Routing_Indicator(TransparentEF): |
| 1088 | def __init__(self, fid='4f0a', sfid=0x0a, name='EF.Routing_Indicator', desc='Routing Indicator', **kwargs): |
| 1089 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1090 | # 3GPP TS 24.501 Table 9.11.3.4.1: |
| 1091 | # Routing Indicator shall consist of 1 to 4 digits. The coding of this field is the |
| 1092 | # responsibility of home network operator but BCD coding shall be used. If a network |
| 1093 | # operator decides to assign less than 4 digits to Routing Indicator, the remaining digits |
| 1094 | # shall be coded as "1111" to fill the 4 digits coding of Routing Indicator |
Harald Welte | f9a5ba5 | 2023-06-09 09:17:05 +0200 | [diff] [blame] | 1095 | self._construct = Struct('routing_indicator'/Rpad(BcdAdapter(Bytes(2)), 'f', 2), |
| 1096 | 'rfu'/HexAdapter(Bytes(2))) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1097 | |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1098 | # TS 31.102 Section 4.4.11.13 |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1099 | class EF_TN3GPPSNN(TransparentEF): |
| 1100 | class ServingNetworkName(BER_TLV_IE, tag=0x80): |
Philipp Maier | 791f80a | 2023-07-26 17:01:37 +0200 | [diff] [blame] | 1101 | _construct = Utf8Adapter(GreedyBytes) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1102 | def __init__(self, fid='4f0c', sfid=0x0c, name='EF.TN3GPPSNN', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1103 | desc='Trusted non-3GPP Serving network names list', **kwargs): |
| 1104 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1105 | self._tlv = EF_TN3GPPSNN.ServingNetworkName |
| 1106 | |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1107 | # TS 31.102 Section 4.4.11.14 (Rel 17) |
| 1108 | class EF_CAG(TransparentEF): |
| 1109 | def __init__(self, fid='4f0d', sfid=0x0d, name='EF.CAG', |
| 1110 | desc='Pre-configured CAG information list EF', **kwargs): |
| 1111 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1112 | self._construct = HexAdapter(GreedyBytes) |
| 1113 | |
| 1114 | # TS 31.102 Section 4.4.11.15 (Rel 17) |
| 1115 | class EF_SOR_CMCI(TransparentEF): |
| 1116 | def __init__(self, fid='4f0e', sfid=0x0e, name='EF.SOR-CMCI', |
| 1117 | desc='Steering Of Roaming - Connected Mode Control Information', **kwargs): |
| 1118 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1119 | self._construct = HexAdapter(GreedyBytes) |
| 1120 | |
| 1121 | # TS 31.102 Section 4.4.11.17 (Rel 17) |
| 1122 | class EF_DRI(TransparentEF): |
| 1123 | def __init__(self, fid='4f0f', sfid=0x0f, name='EF.DRI', |
| 1124 | desc='Disaster roaming information EF', **kwargs): |
| 1125 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1126 | self._construct = Struct('disaster_roaming_enabled'/Byte, |
| 1127 | 'parameters_indicator_status'/FlagsEnum(Byte, roaming_wait_range=1, |
| 1128 | return_wait_range=2, |
| 1129 | applicability_indicator=3), |
| 1130 | 'roaming_wait_range'/HexAdapter(Bytes(2)), |
| 1131 | 'return_wait_range'/HexAdapter(Bytes(2)), |
| 1132 | 'applicability_indicator'/HexAdapter(Byte)) |
| 1133 | |
| 1134 | # TS 31.102 Section 4.4.12.2 (Rel 17) |
| 1135 | class EF_PWS_SNPN(TransparentEF): |
| 1136 | def __init__(self, fid='4f01', sfid=0x01, name='EF.PWS_SNPN', |
| 1137 | desc='Public Warning System in SNPNs', **kwargs): |
| 1138 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1139 | self._construct = Struct('pws_config_in_snpns'/FlagsEnum(Byte, ignore_all_pws_in_subscribed=1, |
| 1140 | ignore_all_pws_in_non_subscribed=2)) |
| 1141 | |
| 1142 | # TS 31.102 Section 4.4.12.2 (Rel 17) |
| 1143 | class EF_NID(LinFixedEF): |
| 1144 | def __init__(self, fid='4f02', sfid=0x02, name='EF.NID', |
| 1145 | desc='Network Identifier for SNPN', **kwargs): |
| 1146 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(6,6), **kwargs) |
| 1147 | self._construct = Struct('assignment_mode'/Enum(Byte, coordinated_ass_opt1=0, |
| 1148 | self_ass=1, |
| 1149 | coordinated_ass_opt2=2), |
| 1150 | 'network_identifier'/HexAdapter(Bytes(5))) |
| 1151 | |
| 1152 | # TS 31.102 Section 4.4.12 (Rel 17) |
| 1153 | class DF_SNPN(CardDF): |
| 1154 | def __init__(self, fid='5fe0', name='DF.SNPN', desc='Files for SNPN purpose', **kwargs): |
| 1155 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
| 1156 | files = [ |
| 1157 | EF_PWS_SNPN(service=143), |
| 1158 | EF_NID(service=146), |
| 1159 | ] |
| 1160 | self.add_files(files) |
| 1161 | |
| 1162 | # TS 31.102 Section 4.4.13.2 (Rel 17) |
| 1163 | class EF_5G_PROSE_ST(EF_UServiceTable): |
| 1164 | def __init__(self, **kwargs): |
| 1165 | super().__init__(fid='4f01', sfid=0x01, name='EF.5G_PROSE_ST', |
| 1166 | desc='5G ProSe Service Table', size=(1,2), table=EF_5G_PROSE_ST_map, **kwargs) |
| 1167 | # add those commands to the general commands of a TransparentEF |
| 1168 | self.shell_commands += [self.AddlShellCommands()] |
| 1169 | |
| 1170 | @with_default_category('File-Specific Commands') |
| 1171 | class AddlShellCommands(CommandSet): |
| 1172 | def __init__(self): |
| 1173 | super().__init__() |
| 1174 | |
| 1175 | def do_prose_service_activate(self, arg): |
| 1176 | """Activate a service within EF.5G_PROSE_ST""" |
Alexander Couzens | c8facea | 2023-07-29 05:01:57 +0200 | [diff] [blame] | 1177 | selected_file = self._cmd.lchan.selected_file |
| 1178 | selected_file.ust_update(self._cmd, [int(arg)], []) |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1179 | |
| 1180 | def do_prose_service_deactivate(self, arg): |
| 1181 | """Deactivate a service within EF.5G_PROSE_ST""" |
Alexander Couzens | c8facea | 2023-07-29 05:01:57 +0200 | [diff] [blame] | 1182 | selected_file = self._cmd.lchan.selected_file |
| 1183 | selected_file.ust_update(self._cmd, [], [int(arg)]) |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1184 | |
| 1185 | # TS 31.102 Section 4.4.13.3 (Rel 17) |
| 1186 | class EF_5G_PROSE_DD(TransparentEF): |
| 1187 | class ServedByNgRan(BER_TLV_IE, tag=0x80): |
| 1188 | pass |
| 1189 | class NotServedByNgran(BER_TLV_IE, tag=0x81): |
| 1190 | pass |
| 1191 | class ProSeIdentifiers(BER_TLV_IE, tag=0x82): |
| 1192 | pass |
| 1193 | class ProSeIdToDefaultDestL2Id(BER_TLV_IE, tag=0x83): |
| 1194 | pass |
| 1195 | class GroupMemberDiscoveryParameters(BER_TLV_IE, tag=0x84): |
| 1196 | pass |
| 1197 | class ValidityTimer(BER_TLV_IE, tag=0x85): |
| 1198 | pass |
| 1199 | class ProSeDirectDiscoveryUeId(BER_TLV_IE, tag=0x86): |
| 1200 | pass |
| 1201 | class Hplmn5GDdnmfAddressInformation(BER_TLV_IE, tag=0x87): |
| 1202 | pass |
| 1203 | class ProSeConfigForDirectDiscovery(BER_TLV_IE, tag=0xA0, |
| 1204 | nested=[ServedByNgRan, NotServedByNgran, ProSeIdentifiers, |
| 1205 | ProSeIdToDefaultDestL2Id, GroupMemberDiscoveryParameters, |
| 1206 | ValidityTimer, ProSeDirectDiscoveryUeId, |
| 1207 | Hplmn5GDdnmfAddressInformation]): |
| 1208 | pass |
| 1209 | def __init__(self, fid='4f02', sfid=0x02, name='EF.5G_PROSE_DD', |
| 1210 | desc='5G ProSe configuration data for direct discovery', **kwargs): |
| 1211 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1212 | # contains TLV structure despite being TransparentEF, not BER-TLV ?!? |
| 1213 | self._tlv = EF_5G_PROSE_DD.ProSeConfigForDirectDiscovery |
| 1214 | |
| 1215 | # TS 31.102 Section 4.4.13.4 (Rel 17) |
| 1216 | class EF_5G_PROSE_DC(TransparentEF): |
| 1217 | class PrivacyConfig(BER_TLV_IE, tag=0x87): |
| 1218 | pass |
| 1219 | class DirectCommInNrPc5(BER_TLV_IE, tag=0x88): |
| 1220 | pass |
| 1221 | class ApplicationToPathPreferenceMappingRules(BER_TLV_IE, tag=0x89): |
| 1222 | pass |
| 1223 | class ProSeIdToNrTxProfileForBroadcastAndGroupcastMappingRules(BER_TLV_IE, tag=0x91): |
| 1224 | pass |
| 1225 | class ProSeConfigForDirectCommunication(BER_TLV_IE, tag=0xA0, |
| 1226 | nested=[EF_5G_PROSE_DD.ServedByNgRan, |
| 1227 | EF_5G_PROSE_DD.NotServedByNgran, |
| 1228 | PrivacyConfig, DirectCommInNrPc5, |
| 1229 | ApplicationToPathPreferenceMappingRules, |
| 1230 | EF_5G_PROSE_DD.ValidityTimer, |
| 1231 | ProSeIdToNrTxProfileForBroadcastAndGroupcastMappingRules]): |
| 1232 | pass |
| 1233 | def __init__(self, fid='4f03', sfid=0x03, name='EF.5G_PROSE_DC', |
| 1234 | desc='5G ProSe configuration data for direct communication', **kwargs): |
| 1235 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1236 | # contains TLV structure despite being TransparentEF, not BER-TLV ?!? |
| 1237 | self._tlv = EF_5G_PROSE_DC.ProSeConfigForDirectCommunication |
| 1238 | |
| 1239 | # TS 31.102 Section 4.4.13.5 (Rel 17) |
| 1240 | class EF_5G_PROSE_U2NRU(TransparentEF): |
| 1241 | class ProSeIdToDefaultDestL2Id(BER_TLV_IE, tag=0x8a): |
| 1242 | pass |
| 1243 | class RxcInfoList(BER_TLV_IE, tag=0x8b): |
| 1244 | pass |
| 1245 | class FiveQiToPc65QosParametersMappingRules(BER_TLV_IE, tag=0x8c): |
| 1246 | pass |
| 1247 | class ProSeIdToAppSrvAddrMappingRules(BER_TLV_IE, tag=0x8d): |
| 1248 | pass |
| 1249 | class UserInfoIdForDiscovery(BER_TLV_IE, tag=0x8e): |
| 1250 | pass |
| 1251 | class PrivacyTimer(BER_TLV_IE, tag=0x92): |
| 1252 | pass |
| 1253 | class FiveGPkkmfAddressInformation(BER_TLV_IE, tag=0x93): |
| 1254 | pass |
| 1255 | class ProSeConfigDataForUeToNetworkRelayUe(BER_TLV_IE, tag=0xA0, |
| 1256 | nested=[EF_5G_PROSE_DD.ServedByNgRan, |
| 1257 | EF_5G_PROSE_DD.NotServedByNgran, |
| 1258 | ProSeIdToDefaultDestL2Id, |
| 1259 | RxcInfoList, |
| 1260 | FiveQiToPc65QosParametersMappingRules, |
| 1261 | ProSeIdToAppSrvAddrMappingRules, |
| 1262 | EF_5G_PROSE_DD.ValidityTimer, |
| 1263 | UserInfoIdForDiscovery, |
| 1264 | PrivacyTimer, |
| 1265 | FiveGPkkmfAddressInformation]): |
| 1266 | pass |
| 1267 | def __init__(self, fid='4f04', sfid=0x04, name='EF.5G_PROSE_U2NRU', |
| 1268 | desc='5G ProSe configuration data for UE-to-network relay UE', **kwargs): |
| 1269 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1270 | # contains TLV structure despite being TransparentEF, not BER-TLV ?!? |
| 1271 | self._tlv = EF_5G_PROSE_U2NRU.ProSeConfigDataForUeToNetworkRelayUe |
| 1272 | |
| 1273 | # TS 31.102 Section 4.4.13.6 (Rel 17) |
| 1274 | class EF_5G_PROSE_RU(TransparentEF): |
| 1275 | class DefaultDestL2Ids(BER_TLV_IE, tag=0x8f): |
| 1276 | pass |
| 1277 | class N3IwfSelectionInfoFor5GProSeL3RemoteUE(BER_TLV_IE, tag=0x90): |
| 1278 | pass |
| 1279 | class ProSeConfigDataForRemoteUe(BER_TLV_IE, tag=0xa0, |
| 1280 | nested=[EF_5G_PROSE_DD.ServedByNgRan, |
| 1281 | EF_5G_PROSE_DD.NotServedByNgran, |
| 1282 | DefaultDestL2Ids, |
| 1283 | EF_5G_PROSE_U2NRU.RxcInfoList, |
| 1284 | N3IwfSelectionInfoFor5GProSeL3RemoteUE, |
| 1285 | EF_5G_PROSE_DD.ValidityTimer, |
| 1286 | EF_5G_PROSE_U2NRU.UserInfoIdForDiscovery, |
| 1287 | EF_5G_PROSE_U2NRU.PrivacyTimer, |
| 1288 | EF_5G_PROSE_U2NRU.FiveGPkkmfAddressInformation]): |
| 1289 | pass |
| 1290 | def __init__(self, fid='4f05', sfid=0x05, name='EF.5G_PROSE_RU', |
| 1291 | desc='5G ProSe configuration data for remote UE', **kwargs): |
| 1292 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1293 | # contains TLV structure despite being TransparentEF, not BER-TLV ?!? |
| 1294 | self._tlv = EF_5G_PROSE_RU.ProSeConfigDataForRemoteUe |
| 1295 | |
| 1296 | # TS 31.102 Section 4.4.13.7 (Rel 17) |
| 1297 | class EF_5G_PROSE_UIR(TransparentEF): |
| 1298 | class CollectionPeriod(BER_TLV_IE, tag=0x94): |
| 1299 | pass |
| 1300 | class ReportingWindow(BER_TLV_IE, tag=0x95): |
| 1301 | pass |
| 1302 | class ReportingIndicators(BER_TLV_IE, tag=0x96): |
| 1303 | pass |
| 1304 | class FiveGDdnmfCtfAddrForUploading(BER_TLV_IE, tag=0x97): |
| 1305 | pass |
| 1306 | class ProSeConfigDataForUeToNetworkRelayUE(BER_TLV_IE, tag=0xa0, |
| 1307 | nested=[EF_5G_PROSE_DD.ValidityTimer, |
| 1308 | CollectionPeriod, ReportingWindow, |
| 1309 | ReportingIndicators, |
| 1310 | FiveGDdnmfCtfAddrForUploading]): |
| 1311 | pass |
| 1312 | def __init__(self, fid='4f06', sfid=0x06, name='EF.5G_PROSE_UIR', |
| 1313 | desc='5G ProSe configuration data for usage information reporting', **kwargs): |
| 1314 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1315 | # contains TLV structure despite being TransparentEF, not BER-TLV ?!? |
| 1316 | self._tlv = EF_5G_PROSE_UIR.ProSeConfigDataForUeToNetworkRelayUE |
| 1317 | |
| 1318 | # TS 31.102 Section 4.4.13 (Rel 17) |
| 1319 | class DF_5G_ProSe(CardDF): |
| 1320 | def __init__(self, fid='5ff0', name='DF.5G_ProSe', desc='Files for 5G ProSe purpose', **kwargs): |
| 1321 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
| 1322 | files = [ |
| 1323 | EF_5G_PROSE_ST(), |
| 1324 | EF_5G_PROSE_DD(service=1), |
| 1325 | EF_5G_PROSE_DC(service=2), |
| 1326 | EF_5G_PROSE_U2NRU(service=3), |
| 1327 | EF_5G_PROSE_RU(service=4), |
| 1328 | EF_5G_PROSE_UIR(service=5), |
| 1329 | ] |
| 1330 | self.add_files(files) |
| 1331 | |
| 1332 | # TS 31.102 Section 4.4.11.18 (Rel 17) |
| 1333 | class EF_5GSEDRX(TransparentEF): |
| 1334 | def __init__(self, fid='4f10', sfid=0x10, name='EF.5GSEDRX', |
| 1335 | desc='5GS eDRX Parameters', **kwargs): |
| 1336 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1337 | self._construct = Struct('5gs_rat_type'/FlagsEnum(Byte, ng_ran=1, sat_ng_ran=2), |
| 1338 | 'edrx_cycle_length'/Int8ub) |
| 1339 | |
| 1340 | # TS 31.102 Section 4.4.11.19 (Rel 17) |
| 1341 | class EF_5GNSWO_CONF(TransparentEF): |
| 1342 | def __init__(self, fid='4f11', sfid=0x11, name='EF.5GNSWO_CONF', |
| 1343 | desc='5G Non-Seamless WLAN Offload configuration', **kwargs): |
| 1344 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1345 | self._construct = Struct('5g_nswo_usage_ind'/Enum(Byte, disabled=0, enabled=1)) |
| 1346 | |
| 1347 | # TS 31.102 Section 4.4.11.20 (Rel 17) |
| 1348 | class EF_MCHPPLMN(TransparentEF): |
Harald Welte | 24e77a7 | 2023-05-24 15:26:29 +0200 | [diff] [blame] | 1349 | def __init__(self, fid='4f15', sfid=0x15, name='EF.MCHPPLMN', |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1350 | desc='Multiplier Coefficient for Higher Priority PLMN search', **kwargs): |
| 1351 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1352 | self._construct = Struct('multiplier_coefficient'/Int8ub) |
| 1353 | |
| 1354 | # TS 31.102 Section 4.4.11.21 (Rel 17) |
| 1355 | class EF_KAUSF_DERIVATION(TransparentEF): |
| 1356 | def __init__(self, fid='4f16', sfid=0x16, name='EF.KAUSF_DERIVATION', |
| 1357 | desc='K_AUSF derivation configuration', **kwargs): |
| 1358 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
| 1359 | self._construct = Struct('k_ausf_deriv_cfg'/FlagsEnum(Byte, use_msk=1), 'rfu'/HexAdapter(GreedyBytes)) |
| 1360 | |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1361 | # TS 31.102 Section 4.4.5 |
| 1362 | class DF_WLAN(CardDF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1363 | def __init__(self, fid='5f40', name='DF.WLAN', desc='Files for WLAN purpose', **kwargs): |
| 1364 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1365 | files = [ |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1366 | TransparentEF('4f41', 0x01, 'EF.Pseudo', 'Pseudonym', service=59), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1367 | TransparentEF('4f42', 0x02, 'EF.UPLMNWLAN', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1368 | 'User controlled PLMN selector for I-WLAN Access', service=60), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1369 | TransparentEF('4f43', 0x03, 'EF.OPLMNWLAN', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1370 | 'Operator controlled PLMN selector for I-WLAN Access', service=61), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1371 | LinFixedEF('4f44', 0x04, 'EF.UWSIDL', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1372 | 'User controlled WLAN Specific Identifier List', service=62), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1373 | LinFixedEF('4f45', 0x05, 'EF.OWSIDL', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1374 | 'Operator controlled WLAN Specific Identifier List', service=63), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1375 | TransparentEF('4f46', 0x06, 'EF.WRI', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1376 | 'WLAN Reauthentication Identity', service=66), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1377 | LinFixedEF('4f47', 0x07, 'EF.HWSIDL', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1378 | 'Home I-WLAN Specific Identifier List', service=81), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1379 | TransparentEF('4f48', 0x08, 'EF.WEHPLMNPI', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1380 | 'I-WLAN Equivalent HPLMN Presentation Indication', service=82), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1381 | TransparentEF('4f49', 0x09, 'EF.WHPI', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1382 | 'I-WLAN HPLMN Priority Indication', service=83), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1383 | TransparentEF('4f4a', 0x0a, 'EF.WLRPLMN', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1384 | 'I-WLAN Last Registered PLMN', service=84), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1385 | TransparentEF('4f4b', 0x0b, 'EF.HPLMNDAI', |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1386 | 'HPLMN Direct Access Indicator', service=88), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1387 | ] |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1388 | self.add_files(files) |
| 1389 | |
| 1390 | # TS 31.102 Section 4.4.6 |
| 1391 | class DF_HNB(CardDF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1392 | def __init__(self, fid='5f50', name='DF.HNB', desc='Files for HomeNodeB purpose', **kwargs): |
| 1393 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1394 | files = [ |
Harald Welte | a77f7e1 | 2023-12-27 16:29:00 +0100 | [diff] [blame^] | 1395 | EF_ACSGL(), |
| 1396 | EF_CSGT(), |
| 1397 | EF_HNBN(), |
| 1398 | EF_OCSGL(), |
| 1399 | EF_CSGT('4f85', 0x05, 'EF.OCSGT', 'Operator CSG Type', service=90), |
| 1400 | EF_HNBN('4f86', 0x06, 'EF.OHNBN', 'Operator Home NodeB Name', service=90), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1401 | ] |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1402 | self.add_files(files) |
| 1403 | |
| 1404 | # TS 31.102 Section 4.4.8 |
| 1405 | class DF_ProSe(CardDF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1406 | def __init__(self, fid='5f90', name='DF.ProSe', desc='Files for ProSe purpose', **kwargs): |
| 1407 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1408 | files = [ |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1409 | LinFixedEF('4f01', 0x01, 'EF.PROSE_MON', |
| 1410 | 'ProSe Monitoring Parameters'), |
| 1411 | LinFixedEF('4f02', 0x02, 'EF.PROSE_ANN', |
| 1412 | 'ProSe Announcing Parameters'), |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1413 | LinFixedEF('4f03', 0x03, 'EF.PROSEFUNC', 'HPLMN ProSe Function'), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1414 | TransparentEF('4f04', 0x04, 'EF.PROSE_RADIO_COM', |
| 1415 | 'ProSe Direct Communication Radio Parameters'), |
| 1416 | TransparentEF('4f05', 0x05, 'EF.PROSE_RADIO_MON', |
| 1417 | 'ProSe Direct Discovery Monitoring Radio Parameters'), |
| 1418 | TransparentEF('4f06', 0x06, 'EF.PROSE_RADIO_ANN', |
| 1419 | 'ProSe Direct Discovery Announcing Radio Parameters'), |
| 1420 | LinFixedEF('4f07', 0x07, 'EF.PROSE_POLICY', |
| 1421 | 'ProSe Policy Parameters'), |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1422 | LinFixedEF('4f08', 0x08, 'EF.PROSE_PLMN', 'ProSe PLMN Parameters'), |
| 1423 | TransparentEF('4f09', 0x09, 'EF.PROSE_GC', 'ProSe Group Counter'), |
| 1424 | TransparentEF('4f10', 0x10, 'EF.PST', 'ProSe Service Table'), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1425 | TransparentEF('4f11', 0x11, 'EF.UIRC', |
| 1426 | 'ProSe UsageInformationReportingConfiguration'), |
| 1427 | LinFixedEF('4f12', 0x12, 'EF.PROSE_GM_DISCOVERY', |
| 1428 | 'ProSe Group Member Discovery Parameters'), |
| 1429 | LinFixedEF('4f13', 0x13, 'EF.PROSE_RELAY', |
| 1430 | 'ProSe Relay Parameters'), |
| 1431 | TransparentEF('4f14', 0x14, 'EF.PROSE_RELAY_DISCOVERY', |
| 1432 | 'ProSe Relay Discovery Parameters'), |
| 1433 | ] |
Harald Welte | 3990ebb | 2021-04-20 23:55:14 +0200 | [diff] [blame] | 1434 | self.add_files(files) |
| 1435 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1436 | |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 1437 | class DF_USIM_5GS(CardDF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1438 | def __init__(self, fid='5FC0', name='DF.5GS', desc='5GS related files', **kwargs): |
| 1439 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 1440 | files = [ |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1441 | # I'm looking at 31.102 R16.6 |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1442 | EF_5GS3GPPLOCI(service=122), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1443 | EF_5GS3GPPLOCI('4f02', 0x02, 'EF.5GSN3GPPLOCI', |
Harald Welte | 28accc8 | 2023-10-18 23:21:46 +0200 | [diff] [blame] | 1444 | desc='5GS non-3GPP location information', service=122), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1445 | EF_5GS3GPPNSC(service=122), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1446 | EF_5GS3GPPNSC('4f04', 0x04, 'EF.5GSN3GPPNSC', |
Harald Welte | 28accc8 | 2023-10-18 23:21:46 +0200 | [diff] [blame] | 1447 | desc='5GS non-3GPP Access NAS Security Context', service=122), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1448 | EF_5GAUTHKEYS(service=123), |
| 1449 | EF_UAC_AIC(service=126), |
| 1450 | EF_SUCI_Calc_Info(service=124), |
| 1451 | EF_OPL5G(service=129), |
| 1452 | EF_SUPI_NAI(service=130), |
Harald Welte | 455611c | 2023-05-27 12:48:54 +0200 | [diff] [blame] | 1453 | EF_Routing_Indicator(service=124), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1454 | TransparentEF('4F0B', 0x0b, 'EF.URSP', |
Harald Welte | 28accc8 | 2023-10-18 23:21:46 +0200 | [diff] [blame] | 1455 | desc='UE Route Selector Policies per PLMN', service=132), |
Harald Welte | 419bb49 | 2022-02-12 21:39:35 +0100 | [diff] [blame] | 1456 | EF_TN3GPPSNN(service=133), |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1457 | # Rel-17 additions below |
| 1458 | EF_CAG(service=137), |
| 1459 | EF_SOR_CMCI(service=138), |
| 1460 | EF_DRI(service=140), |
| 1461 | EF_5GSEDRX(service=141), |
| 1462 | EF_5GNSWO_CONF(service=142), |
| 1463 | EF_MCHPPLMN(service=144), |
| 1464 | EF_KAUSF_DERIVATION(service=145), |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 1465 | ] |
Merlin Chlosta | 05ca36b | 2021-04-01 16:15:28 +0200 | [diff] [blame] | 1466 | self.add_files(files) |
| 1467 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1468 | |
Harald Welte | 2bee70c | 2023-05-25 09:14:28 +0200 | [diff] [blame] | 1469 | class DF_SAIP(CardDF): |
| 1470 | """This is not really TS 31.102 but part of the eUICC Profile Package: Interoperable Format Technical |
| 1471 | Specification as released by TCA (formerly SIMalliance)""" |
| 1472 | def __init__(self, fid='5FD0', name='DF.SAIP', desc='SIMalliance Interoperable Profile', **kwargs): |
| 1473 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
| 1474 | files = [ |
| 1475 | # uses the same file format as DF.5GS/EF_SUCI_Calc_Info, but different FID |
| 1476 | EF_SUCI_Calc_Info(fid='4f01') |
| 1477 | ] |
| 1478 | self.add_files(files) |
| 1479 | |
| 1480 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1481 | class ADF_USIM(CardADF): |
Philipp Maier | a1850ae | 2023-10-25 18:05:09 +0200 | [diff] [blame] | 1482 | def __init__(self, aid='a0000000871002', has_fs=True, name='ADF.USIM', fid=None, sfid=None, |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1483 | desc='USIM Application'): |
Philipp Maier | a1850ae | 2023-10-25 18:05:09 +0200 | [diff] [blame] | 1484 | super().__init__(aid=aid, has_fs=has_fs, fid=fid, sfid=sfid, name=name, desc=desc) |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 1485 | # add those commands to the general commands of a TransparentEF |
| 1486 | self.shell_commands += [self.AddlShellCommands()] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1487 | |
| 1488 | files = [ |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1489 | EF_LI(sfid=0x02), |
| 1490 | EF_IMSI(sfid=0x07), |
| 1491 | EF_Keys(), |
| 1492 | EF_Keys('6f09', 0x09, 'EF.KeysPS', |
| 1493 | desc='Ciphering and Integrity Keys for PS domain'), |
| 1494 | EF_xPLMNwAcT('6f60', 0x0a, 'EF.PLMNwAcT', |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1495 | desc='User controlled PLMN Selector with Access Technology', service=20), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1496 | EF_HPPLMN(), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1497 | EF_ACMmax(service=13), |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 1498 | EF_UST(), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1499 | CyclicEF('6f39', None, 'EF.ACM', |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1500 | desc='Accumulated call meter', rec_len=(3, 3), service=13), |
| 1501 | TransparentEF('6f3e', None, 'EF.GID1', desc='Group Identifier Level 1', service=17), |
| 1502 | TransparentEF('6f3f', None, 'EF.GID2', desc='Group Identifier Level 2', service=18), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1503 | EF_SPN(service=19), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1504 | TransparentEF('6f41', None, 'EF.PUCT', |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1505 | desc='Price per unit and currency table', size=(5, 5), service=13), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1506 | EF_CBMI(service=15), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1507 | EF_ACC(sfid=0x06), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1508 | EF_PLMNsel('6f7b', 0x0d, 'EF.FPLMN', desc='Forbidden PLMNs', size=(12, None)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1509 | EF_LOCI(), |
| 1510 | EF_AD(), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1511 | EF_CBMID(sfid=0x0e, service=29), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1512 | EF_ECC(), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1513 | EF_CBMIR(service=16), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1514 | EF_PSLOCI(), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1515 | EF_ADN('6f3b', None, 'EF.FDN', desc='Fixed Dialling Numbers', service=[2, 89], ext=2), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1516 | EF_SMS('6f3c', None, service=10), |
| 1517 | EF_MSISDN(service=21), |
| 1518 | EF_SMSP(service=12), |
| 1519 | EF_SMSS(service=10), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1520 | EF_ADN('6f49', None, 'EF.SDN', desc='Service Dialling Numbers', service=[4, 89], ext=3), |
| 1521 | EF_EXT('6f4b', None, 'EF.EXT2', desc='Extension2 (FDN)', service=3), |
| 1522 | EF_EXT('6f4c', None, 'EF.EXT3', desc='Extension2 (SDN)', service=5), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1523 | EF_SMSR(service=11), |
| 1524 | EF_ICI(service=9), |
| 1525 | EF_OCI(service=8), |
| 1526 | EF_ICT(service=9), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1527 | EF_ICT('6f83', None, 'EF.OCT', desc='Outgoing Call Timer', service=8), |
| 1528 | EF_EXT('6f4e', None, 'EF.EXT5', desc='Extension5 (ICI/OCI/MSISDN)', service=44), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1529 | EF_CCP2(service=14), |
| 1530 | EF_eMLPP(service=24), |
| 1531 | EF_AAeM(service=25), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1532 | # EF_Hiddenkey |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1533 | EF_ADN('6f4d', None, 'EF.BDN', desc='Barred Dialling Numbers', service=6, ext=4), |
| 1534 | EF_EXT('6f55', None, 'EF.EXT4', desc='Extension4 (BDN/SSC)', service=7), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1535 | EF_CMI(service=6), |
Harald Welte | 6ca2fa7 | 2022-02-12 16:29:31 +0100 | [diff] [blame] | 1536 | EF_EST(service=[2, 6, 34, 35]), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1537 | EF_ACL(service=35), |
| 1538 | EF_DCK(service=36), |
| 1539 | EF_CNL(service=37), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1540 | EF_START_HFN(), |
| 1541 | EF_THRESHOLD(), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1542 | EF_xPLMNwAcT('6f61', 0x11, 'EF.OPLMNwAcT', desc='User controlled PLMN Selector with Access Technology', service=42), |
| 1543 | EF_xPLMNwAcT('6f62', 0x13, 'EF.HPLMNwAcT', desc='HPLMN Selector with Access Technology', service=43), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1544 | EF_ARR('6f06', 0x17), |
Harald Welte | 363edd9 | 2022-07-17 22:24:03 +0200 | [diff] [blame] | 1545 | EF_RPLMNAcT(), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1546 | TransparentEF('6fc4', None, 'EF.NETPAR', desc='Network Parameters'), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1547 | EF_PNN('6fc5', 0x19, service=45), |
| 1548 | EF_OPL(service=46), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1549 | EF_ADN('6fc7', None, 'EF.MBDN', desc='Mailbox Dialling Numbers', service=47, ext=6), |
| 1550 | EF_EXT('6fc8', None, 'EF.EXT6', desc='Extension6 (MBDN)'), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1551 | EF_MBI(service=47), |
| 1552 | EF_MWIS(service=48), |
Harald Welte | 5376251 | 2023-12-21 20:16:17 +0100 | [diff] [blame] | 1553 | EF_CFIS(service=49, ext=7), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1554 | EF_EXT('6fcc', None, 'EF.EXT7', desc='Extension7 (CFIS)'), |
| 1555 | TransparentEF('6fcd', None, 'EF.SPDI', desc='Service Provider Display Information', service=51), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1556 | EF_MMSN(service=52), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1557 | EF_EXT('6fcf', None, 'EF.EXT8', desc='Extension8 (MMSN)', service=53), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1558 | EF_MMSICP(service=52), |
| 1559 | EF_MMSUP(service=52), |
| 1560 | EF_MMSUCP(service=(52, 55)), |
Harald Welte | 04bd514 | 2023-05-24 15:23:53 +0200 | [diff] [blame] | 1561 | EF_NIA(service=56, fid='6fd3'), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1562 | EF_VGCS(service=57), |
| 1563 | EF_VGCSS(service=57), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1564 | EF_VGCS('6fb3', None, 'EF.VBS', desc='Voice Broadcast Service', service=58), |
| 1565 | EF_VGCSS('6fb4', None, 'EF.VBSS', desc='Voice Broadcast Service Status', service=58), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1566 | EF_VGCSCA(service=64), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1567 | EF_VGCSCA('6fd5', None, 'EF.VBCSCA', desc='Voice Broadcast Service Ciphering Algorithm', service=65), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1568 | EF_GBABP(service=68), |
| 1569 | EF_MSK(service=69), |
| 1570 | EF_MUK(service=69), |
| 1571 | EF_GBANL(service=68), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1572 | EF_PLMNsel('6fd9', 0x1d, 'EF.EHPLMN', desc='Equivalent HPLMN', size=(12, None), service=71), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1573 | EF_EHPLMNPI(service=(71, 73)), |
| 1574 | # EF_LRPLMNSI ('6fdc', service=74) |
| 1575 | EF_NAFKCA(service=(68, 76)), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1576 | TransparentEF('6fde', None, 'EF.SPNI', desc='Service Provider Name Icon', service=78), |
| 1577 | LinFixedEF('6fdf', None, 'EF.PNNI', desc='PLMN Network Name Icon', service=79), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1578 | EF_NCP_IP(service=80), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1579 | EF_EPSLOCI('6fe3', 0x1e, 'EF.EPSLOCI', desc='EPS location information', service=85), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1580 | EF_EPSNSC(service=85), |
Harald Welte | 324175f | 2023-12-21 20:25:30 +0100 | [diff] [blame] | 1581 | # EF.UFC Test data: 801e60c01e900080040000000000000000f0000000004000000000000080 |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1582 | TransparentEF('6fe6', None, 'EF.UFC', desc='USAT Facility Control', size=(1, 16)), |
| 1583 | TransparentEF('6fe8', None, 'EF.NASCONFIG', desc='Non Access Stratum Configuration', service=96), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1584 | # UICC IARI (only in cards that have no ISIM) service=95 |
| 1585 | EF_PWS(service=97), |
Harald Welte | 509ecf8 | 2023-10-18 23:32:57 +0200 | [diff] [blame] | 1586 | LinFixedEF('6fed', None, 'EF.FDNURI', desc='Fixed Dialling Numbers URI', service=(2, 99)), |
| 1587 | LinFixedEF('6fee', None, 'EF.BDNURI', desc='Barred Dialling Numbers URI', service=(6, 99)), |
| 1588 | LinFixedEF('6fef', None, 'EF.SDNURI', desc='Service Dialling Numbers URI', service=(4, 99)), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1589 | # EF_IWL (IMEI(SV) White List) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1590 | EF_IPS(), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1591 | EF_ePDGId(service=(106, 107)), |
Harald Welte | cdfe1c2 | 2023-12-08 12:30:21 +0100 | [diff] [blame] | 1592 | EF_ePDGSelection(service=(106, 107)), |
Harald Welte | 5277b5c | 2023-12-08 12:22:28 +0100 | [diff] [blame] | 1593 | EF_ePDGId('6ff5', None, 'EF.ePDGIdEm', desc='Emergency ePDG Identifier', service=(110, 111)), |
Harald Welte | cdfe1c2 | 2023-12-08 12:30:21 +0100 | [diff] [blame] | 1594 | EF_ePDGSelection('6ff6', None, 'EF.ePDGSelectionEm', |
| 1595 | desc='ePDG Selection Information for Emergency Services', service=(110, 111)), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1596 | EF_FromPreferred(service=114), |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1597 | EF_eAKA(), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1598 | # FIXME: DF_SoLSA service=23 |
Harald Welte | de4c14c | 2022-07-16 11:53:59 +0200 | [diff] [blame] | 1599 | DF_PHONEBOOK(), |
Harald Welte | d90ceb8 | 2022-07-17 22:10:58 +0200 | [diff] [blame] | 1600 | DF_GSM_ACCESS(), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1601 | DF_WLAN(service=[59, 60, 61, 62, 63, 66, 81, 82, 83, 84, 88]), |
| 1602 | DF_HNB(service=[86, 90]), |
| 1603 | DF_ProSe(service=101), |
| 1604 | # FIXME: DF_ACDC service=108 |
| 1605 | # FIXME: DF_TV service=116 |
| 1606 | DF_USIM_5GS(service=[122, 123, 124, 125, 126, 127, 129, 130]), |
Harald Welte | fc67de2 | 2023-05-23 20:29:49 +0200 | [diff] [blame] | 1607 | DF_SNPN(service=[143,146]), |
| 1608 | DF_5G_ProSe(service=139), |
Harald Welte | 2bee70c | 2023-05-25 09:14:28 +0200 | [diff] [blame] | 1609 | DF_SAIP(), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1610 | ] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1611 | self.add_files(files) |
| 1612 | |
| 1613 | def decode_select_response(self, data_hex): |
Philipp Maier | 5998a3a | 2021-11-16 15:16:39 +0100 | [diff] [blame] | 1614 | return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1615 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 1616 | @with_default_category('Application-Specific Commands') |
| 1617 | class AddlShellCommands(CommandSet): |
| 1618 | def __init__(self): |
| 1619 | super().__init__() |
| 1620 | |
| 1621 | authenticate_parser = argparse.ArgumentParser() |
| 1622 | authenticate_parser.add_argument('rand', help='Random challenge') |
| 1623 | authenticate_parser.add_argument('autn', help='Authentication Nonce') |
| 1624 | #authenticate_parser.add_argument('--context', help='Authentication context', default='3G') |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1625 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 1626 | @cmd2.with_argparser(authenticate_parser) |
| 1627 | def do_authenticate(self, opts): |
| 1628 | """Perform Authentication and Key Agreement (AKA).""" |
Harald Welte | 4625512 | 2023-10-21 23:40:42 +0200 | [diff] [blame] | 1629 | (data, sw) = self._cmd.lchan.scc.authenticate(opts.rand, opts.autn) |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 1630 | self._cmd.poutput_json(data) |
| 1631 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 1632 | term_prof_parser = argparse.ArgumentParser() |
| 1633 | term_prof_parser.add_argument('PROFILE', help='Hexstring of encoded terminal profile') |
| 1634 | |
| 1635 | @cmd2.with_argparser(term_prof_parser) |
Harald Welte | 51b3abb | 2022-07-30 16:30:33 +0200 | [diff] [blame] | 1636 | def do_terminal_profile(self, opts): |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 1637 | """Send a TERMINAL PROFILE command to the card. |
| 1638 | This is used to inform the card about which optional |
| 1639 | features the terminal (modem/phone) supports, particularly |
| 1640 | in the context of SIM Toolkit, Proactive SIM and OTA. You |
| 1641 | must specify a hex-string with the encoded terminal profile |
| 1642 | you want to send to the card.""" |
Harald Welte | 4625512 | 2023-10-21 23:40:42 +0200 | [diff] [blame] | 1643 | (data, sw) = self._cmd.lchan.scc.terminal_profile(opts.PROFILE) |
Harald Welte | 846a898 | 2021-10-08 15:47:16 +0200 | [diff] [blame] | 1644 | self._cmd.poutput('SW: %s, data: %s' % (sw, data)) |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 1645 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 1646 | envelope_parser = argparse.ArgumentParser() |
| 1647 | envelope_parser.add_argument('PAYLOAD', help='Hexstring of encoded payload to ENVELOPE') |
| 1648 | |
| 1649 | @cmd2.with_argparser(envelope_parser) |
Harald Welte | 51b3abb | 2022-07-30 16:30:33 +0200 | [diff] [blame] | 1650 | def do_envelope(self, opts): |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 1651 | """Send an ENVELOPE command to the card. This is how a |
| 1652 | variety of information is communicated from the terminal |
| 1653 | (modem/phone) to the card, particularly in the context of |
| 1654 | SIM Toolkit, Proactive SIM and OTA.""" |
Harald Welte | 4625512 | 2023-10-21 23:40:42 +0200 | [diff] [blame] | 1655 | (data, sw) = self._cmd.lchan.scc.envelope(opts.PAYLOAD) |
Harald Welte | 7cb94e4 | 2021-10-08 15:47:57 +0200 | [diff] [blame] | 1656 | self._cmd.poutput('SW: %s, data: %s' % (sw, data)) |
| 1657 | |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 1658 | envelope_sms_parser = argparse.ArgumentParser() |
| 1659 | envelope_sms_parser.add_argument('TPDU', help='Hexstring of encoded SMS TPDU') |
| 1660 | |
| 1661 | @cmd2.with_argparser(envelope_sms_parser) |
Harald Welte | 51b3abb | 2022-07-30 16:30:33 +0200 | [diff] [blame] | 1662 | def do_envelope_sms(self, opts): |
Harald Welte | 12af793 | 2022-02-15 16:39:08 +0100 | [diff] [blame] | 1663 | """Send an ENVELOPE(SMS-PP-Download) command to the card. |
| 1664 | This emulates a terminal (modem/phone) having received a SMS |
| 1665 | with a PID of 'SMS for the SIM card'. You can use this |
| 1666 | command in the context of testing OTA related features |
Philipp Maier | 4e5aa30 | 2023-06-06 19:22:19 +0200 | [diff] [blame] | 1667 | without a modem/phone or a cellular network.""" |
Harald Welte | 7cb94e4 | 2021-10-08 15:47:57 +0200 | [diff] [blame] | 1668 | tpdu_ie = SMS_TPDU() |
Harald Welte | 51b3abb | 2022-07-30 16:30:33 +0200 | [diff] [blame] | 1669 | tpdu_ie.from_bytes(h2b(opts.TPDU)) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1670 | dev_ids = DeviceIdentities( |
| 1671 | decoded={'source_dev_id': 'network', 'dest_dev_id': 'uicc'}) |
Harald Welte | 7cb94e4 | 2021-10-08 15:47:57 +0200 | [diff] [blame] | 1672 | sms_dl = SMSPPDownload(children=[dev_ids, tpdu_ie]) |
Harald Welte | 4625512 | 2023-10-21 23:40:42 +0200 | [diff] [blame] | 1673 | (data, sw) = self._cmd.lchan.scc.envelope(b2h(sms_dl.to_tlv())) |
Harald Welte | 7cb94e4 | 2021-10-08 15:47:57 +0200 | [diff] [blame] | 1674 | self._cmd.poutput('SW: %s, data: %s' % (sw, data)) |
| 1675 | |
Harald Welte | 7ec8223 | 2023-06-06 18:15:52 +0200 | [diff] [blame] | 1676 | get_id_parser = argparse.ArgumentParser() |
| 1677 | get_id_parser.add_argument("--nswo-context", action='store_true') |
| 1678 | |
| 1679 | @cmd2.with_argparser(get_id_parser) |
| 1680 | def do_get_identity(self, opts): |
| 1681 | """Send a GET IDENTITY command to the card. This is part of the |
| 1682 | procedure for "SUCI calculation performed on USIM" supported |
| 1683 | by USIM with support for both EF.UST service 124 and 125.""" |
| 1684 | context = 0x01 # SUCI |
| 1685 | if opts.nswo_context: |
| 1686 | context = 0x02 # SUCI 5G NSWO |
Harald Welte | 4625512 | 2023-10-21 23:40:42 +0200 | [diff] [blame] | 1687 | (data, sw) = self._cmd.lchan.scc.get_identity(context) |
Harald Welte | 7ec8223 | 2023-06-06 18:15:52 +0200 | [diff] [blame] | 1688 | do = SUCI_TlvDataObject() |
| 1689 | do.from_tlv(h2b(data)) |
| 1690 | do_d = do.to_dict() |
| 1691 | self._cmd.poutput('SUCI TLV Data Object: %s' % do_d['suci__tlv_data_object']) |
| 1692 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 1693 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1694 | # TS 31.102 Section 7.3 |
| 1695 | sw_usim = { |
| 1696 | 'Security management': { |
| 1697 | '9862': 'Authentication error, incorrect MAC', |
| 1698 | '9864': 'Authentication error, security context not supported', |
| 1699 | '9865': 'Key freshness failure', |
| 1700 | '9866': 'Authentication error, no memory space available', |
| 1701 | '9867': 'Authentication error, no memory space available in EF MUK', |
| 1702 | } |
| 1703 | } |
| 1704 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1705 | |
Philipp Maier | 57f65ee | 2021-10-18 14:09:02 +0200 | [diff] [blame] | 1706 | class CardApplicationUSIM(CardApplication): |
| 1707 | def __init__(self): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1708 | super().__init__('USIM', adf=ADF_USIM(), sw=sw_usim) |