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