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