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