Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +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 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 7 | """ Various constants from ETSI TS 151.011 + |
| 8 | Representation of the GSM SIM/USIM/ISIM filesystem hierarchy. |
| 9 | |
| 10 | The File (and its derived classes) uses the classes of pySim.filesystem in |
| 11 | order to describe the files specified in the relevant ETSI + 3GPP specifications. |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 12 | """ |
| 13 | |
| 14 | # |
| 15 | # Copyright (C) 2017 Alexander.Chemeris <Alexander.Chemeris@gmail.com> |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 16 | # Copyright (C) 2021 Harald Welte <laforge@osmocom.org> |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 17 | # |
| 18 | # This program is free software: you can redistribute it and/or modify |
| 19 | # it under the terms of the GNU General Public License as published by |
| 20 | # the Free Software Foundation, either version 2 of the License, or |
| 21 | # (at your option) any later version. |
| 22 | # |
| 23 | # This program is distributed in the hope that it will be useful, |
| 24 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | # GNU General Public License for more details. |
| 27 | # |
| 28 | # You should have received a copy of the GNU General Public License |
| 29 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 30 | # |
| 31 | |
| 32 | MF_num = '3F00' |
| 33 | |
| 34 | DF_num = { |
| 35 | 'TELECOM': '7F10', |
| 36 | |
| 37 | 'GSM': '7F20', |
| 38 | 'IS-41': '7F22', |
| 39 | 'FP-CTS': '7F23', |
| 40 | |
| 41 | 'GRAPHICS': '5F50', |
| 42 | |
| 43 | 'IRIDIUM': '5F30', |
| 44 | 'GLOBST': '5F31', |
| 45 | 'ICO': '5F32', |
| 46 | 'ACeS': '5F33', |
| 47 | |
| 48 | 'EIA/TIA-553': '5F40', |
| 49 | 'CTS': '5F60', |
| 50 | 'SOLSA': '5F70', |
| 51 | |
| 52 | 'MExE': '5F3C', |
| 53 | } |
| 54 | |
| 55 | EF_num = { |
| 56 | # MF |
| 57 | 'ICCID': '2FE2', |
| 58 | 'ELP': '2F05', |
Sebastian Viviani | 0dc8f69 | 2020-05-29 00:14:55 +0100 | [diff] [blame] | 59 | 'DIR': '2F00', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 60 | |
| 61 | # DF_TELECOM |
| 62 | 'ADN': '6F3A', |
| 63 | 'FDN': '6F3B', |
| 64 | 'SMS': '6F3C', |
| 65 | 'CCP': '6F3D', |
| 66 | 'MSISDN': '6F40', |
| 67 | 'SMSP': '6F42', |
| 68 | 'SMSS': '6F43', |
| 69 | 'LND': '6F44', |
| 70 | 'SMSR': '6F47', |
| 71 | 'SDN': '6F49', |
| 72 | 'EXT1': '6F4A', |
| 73 | 'EXT2': '6F4B', |
| 74 | 'EXT3': '6F4C', |
| 75 | 'BDN': '6F4D', |
| 76 | 'EXT4': '6F4E', |
| 77 | 'CMI': '6F58', |
| 78 | 'ECCP': '6F4F', |
| 79 | |
| 80 | # DF_GRAPHICS |
| 81 | 'IMG': '4F20', |
| 82 | |
| 83 | # DF_SoLSA |
| 84 | 'SAI': '4F30', |
| 85 | 'SLL': '4F31', |
| 86 | |
| 87 | # DF_MExE |
| 88 | 'MExE-ST': '4F40', |
| 89 | 'ORPK': '4F41', |
| 90 | 'ARPK': '4F42', |
| 91 | 'TPRPK': '4F43', |
| 92 | |
| 93 | # DF_GSM |
| 94 | 'LP': '6F05', |
| 95 | 'IMSI': '6F07', |
| 96 | 'Kc': '6F20', |
| 97 | 'DCK': '6F2C', |
| 98 | 'PLMNsel': '6F30', |
| 99 | 'HPPLMN': '6F31', |
| 100 | 'CNL': '6F32', |
| 101 | 'ACMmax': '6F37', |
| 102 | 'SST': '6F38', |
| 103 | 'ACM': '6F39', |
| 104 | 'GID1': '6F3E', |
| 105 | 'GID2': '6F3F', |
| 106 | 'PUCT': '6F41', |
| 107 | 'CBMI': '6F45', |
| 108 | 'SPN': '6F46', |
| 109 | 'CBMID': '6F48', |
| 110 | 'BCCH': '6F74', |
| 111 | 'ACC': '6F78', |
| 112 | 'FPLMN': '6F7B', |
| 113 | 'LOCI': '6F7E', |
| 114 | 'AD': '6FAD', |
| 115 | 'PHASE': '6FAE', |
| 116 | 'VGCS': '6FB1', |
| 117 | 'VGCSS': '6FB2', |
| 118 | 'VBS': '6FB3', |
| 119 | 'VBSS': '6FB4', |
| 120 | 'eMLPP': '6FB5', |
| 121 | 'AAeM': '6FB6', |
| 122 | 'ECC': '6FB7', |
| 123 | 'CBMIR': '6F50', |
| 124 | 'NIA': '6F51', |
| 125 | 'KcGPRS': '6F52', |
| 126 | 'LOCIGPRS': '6F53', |
| 127 | 'SUME': '6F54', |
| 128 | 'PLMNwAcT': '6F60', |
| 129 | 'OPLMNwAcT': '6F61', |
| 130 | # Figure 8 names it HPLMNAcT, but in the text it's names it HPLMNwAcT |
| 131 | 'HPLMNAcT': '6F62', |
| 132 | 'HPLMNwAcT': '6F62', |
| 133 | 'CPBCCH': '6F63', |
| 134 | 'INVSCAN': '6F64', |
| 135 | 'PNN': '6FC5', |
| 136 | 'OPL': '6FC6', |
| 137 | 'MBDN': '6FC7', |
| 138 | 'EXT6': '6FC8', |
| 139 | 'MBI': '6FC9', |
| 140 | 'MWIS': '6FCA', |
| 141 | 'CFIS': '6FCB', |
| 142 | 'EXT7': '6FCC', |
| 143 | 'SPDI': '6FCD', |
| 144 | 'MMSN': '6FCE', |
| 145 | 'EXT8': '6FCF', |
| 146 | 'MMSICP': '6FD0', |
| 147 | 'MMSUP': '6FD1', |
| 148 | 'MMSUCP': '6FD2', |
| 149 | } |
| 150 | |
| 151 | DF = { |
| 152 | 'TELECOM': [MF_num, DF_num['TELECOM']], |
| 153 | |
| 154 | 'GSM': [MF_num, DF_num['GSM']], |
| 155 | 'IS-41': [MF_num, DF_num['IS-41']], |
| 156 | 'FP-CTS': [MF_num, DF_num['FP-CTS']], |
| 157 | |
| 158 | 'GRAPHICS': [MF_num, DF_num['GRAPHICS']], |
| 159 | |
| 160 | 'IRIDIUM': [MF_num, DF_num['IRIDIUM']], |
| 161 | 'GLOBST': [MF_num, DF_num['GLOBST']], |
| 162 | 'ICO': [MF_num, DF_num['ICO']], |
| 163 | 'ACeS': [MF_num, DF_num['ACeS']], |
| 164 | |
| 165 | 'EIA/TIA-553': [MF_num, DF_num['EIA/TIA-553']], |
| 166 | 'CTS': [MF_num, DF_num['CTS']], |
| 167 | 'SoLSA': [MF_num, DF_num['SOLSA']], |
| 168 | |
| 169 | 'MExE': [MF_num, DF_num['MExE']], |
| 170 | } |
| 171 | |
| 172 | |
| 173 | EF = { |
| 174 | 'ICCID': [MF_num, EF_num['ICCID']], |
| 175 | 'ELP': [MF_num, EF_num['ELP']], |
Sebastian Viviani | 0dc8f69 | 2020-05-29 00:14:55 +0100 | [diff] [blame] | 176 | 'DIR': [MF_num, EF_num['DIR']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 177 | |
| 178 | 'ADN': DF['TELECOM']+[EF_num['ADN']], |
| 179 | 'FDN': DF['TELECOM']+[EF_num['FDN']], |
| 180 | 'SMS': DF['TELECOM']+[EF_num['SMS']], |
| 181 | 'CCP': DF['TELECOM']+[EF_num['CCP']], |
| 182 | 'MSISDN': DF['TELECOM']+[EF_num['MSISDN']], |
| 183 | 'SMSP': DF['TELECOM']+[EF_num['SMSP']], |
| 184 | 'SMSS': DF['TELECOM']+[EF_num['SMSS']], |
| 185 | 'LND': DF['TELECOM']+[EF_num['LND']], |
| 186 | 'SMSR': DF['TELECOM']+[EF_num['SMSR']], |
| 187 | 'SDN': DF['TELECOM']+[EF_num['SDN']], |
| 188 | 'EXT1': DF['TELECOM']+[EF_num['EXT1']], |
| 189 | 'EXT2': DF['TELECOM']+[EF_num['EXT2']], |
| 190 | 'EXT3': DF['TELECOM']+[EF_num['EXT3']], |
| 191 | 'BDN': DF['TELECOM']+[EF_num['BDN']], |
| 192 | 'EXT4': DF['TELECOM']+[EF_num['EXT4']], |
| 193 | 'CMI': DF['TELECOM']+[EF_num['CMI']], |
| 194 | 'ECCP': DF['TELECOM']+[EF_num['ECCP']], |
| 195 | |
| 196 | 'IMG': DF['GRAPHICS']+[EF_num['IMG']], |
| 197 | |
| 198 | 'SAI': DF['SoLSA']+[EF_num['SAI']], |
| 199 | 'SLL': DF['SoLSA']+[EF_num['SLL']], |
| 200 | |
| 201 | 'MExE-ST': DF['MExE']+[EF_num['MExE-ST']], |
| 202 | 'ORPK': DF['MExE']+[EF_num['ORPK']], |
| 203 | 'ARPK': DF['MExE']+[EF_num['ARPK']], |
| 204 | 'TPRPK': DF['MExE']+[EF_num['TPRPK']], |
| 205 | |
| 206 | 'LP': DF['GSM']+[EF_num['LP']], |
| 207 | 'IMSI': DF['GSM']+[EF_num['IMSI']], |
| 208 | 'Kc': DF['GSM']+[EF_num['Kc']], |
| 209 | 'DCK': DF['GSM']+[EF_num['DCK']], |
| 210 | 'PLMNsel': DF['GSM']+[EF_num['PLMNsel']], |
| 211 | 'HPPLMN': DF['GSM']+[EF_num['HPPLMN']], |
| 212 | 'CNL': DF['GSM']+[EF_num['CNL']], |
| 213 | 'ACMmax': DF['GSM']+[EF_num['ACMmax']], |
| 214 | 'SST': DF['GSM']+[EF_num['SST']], |
| 215 | 'ACM': DF['GSM']+[EF_num['ACM']], |
| 216 | 'GID1': DF['GSM']+[EF_num['GID1']], |
| 217 | 'GID2': DF['GSM']+[EF_num['GID2']], |
| 218 | 'PUCT': DF['GSM']+[EF_num['PUCT']], |
| 219 | 'CBMI': DF['GSM']+[EF_num['CBMI']], |
| 220 | 'SPN': DF['GSM']+[EF_num['SPN']], |
| 221 | 'CBMID': DF['GSM']+[EF_num['CBMID']], |
| 222 | 'BCCH': DF['GSM']+[EF_num['BCCH']], |
| 223 | 'ACC': DF['GSM']+[EF_num['ACC']], |
| 224 | 'FPLMN': DF['GSM']+[EF_num['FPLMN']], |
| 225 | 'LOCI': DF['GSM']+[EF_num['LOCI']], |
| 226 | 'AD': DF['GSM']+[EF_num['AD']], |
| 227 | 'PHASE': DF['GSM']+[EF_num['PHASE']], |
| 228 | 'VGCS': DF['GSM']+[EF_num['VGCS']], |
| 229 | 'VGCSS': DF['GSM']+[EF_num['VGCSS']], |
| 230 | 'VBS': DF['GSM']+[EF_num['VBS']], |
| 231 | 'VBSS': DF['GSM']+[EF_num['VBSS']], |
| 232 | 'eMLPP': DF['GSM']+[EF_num['eMLPP']], |
| 233 | 'AAeM': DF['GSM']+[EF_num['AAeM']], |
| 234 | 'ECC': DF['GSM']+[EF_num['ECC']], |
| 235 | 'CBMIR': DF['GSM']+[EF_num['CBMIR']], |
| 236 | 'NIA': DF['GSM']+[EF_num['NIA']], |
| 237 | 'KcGPRS': DF['GSM']+[EF_num['KcGPRS']], |
| 238 | 'LOCIGPRS': DF['GSM']+[EF_num['LOCIGPRS']], |
| 239 | 'SUME': DF['GSM']+[EF_num['SUME']], |
| 240 | 'PLMNwAcT': DF['GSM']+[EF_num['PLMNwAcT']], |
| 241 | 'OPLMNwAcT': DF['GSM']+[EF_num['OPLMNwAcT']], |
| 242 | # Figure 8 names it HPLMNAcT, but in the text it's names it HPLMNwAcT |
| 243 | 'HPLMNAcT': DF['GSM']+[EF_num['HPLMNAcT']], |
| 244 | 'HPLMNwAcT': DF['GSM']+[EF_num['HPLMNAcT']], |
| 245 | 'CPBCCH': DF['GSM']+[EF_num['CPBCCH']], |
| 246 | 'INVSCAN': DF['GSM']+[EF_num['INVSCAN']], |
| 247 | 'PNN': DF['GSM']+[EF_num['PNN']], |
| 248 | 'OPL': DF['GSM']+[EF_num['OPL']], |
| 249 | 'MBDN': DF['GSM']+[EF_num['MBDN']], |
| 250 | 'EXT6': DF['GSM']+[EF_num['EXT6']], |
| 251 | 'MBI': DF['GSM']+[EF_num['MBI']], |
| 252 | 'MWIS': DF['GSM']+[EF_num['MWIS']], |
| 253 | 'CFIS': DF['GSM']+[EF_num['CFIS']], |
| 254 | 'EXT7': DF['GSM']+[EF_num['EXT7']], |
| 255 | 'SPDI': DF['GSM']+[EF_num['SPDI']], |
| 256 | 'MMSN': DF['GSM']+[EF_num['MMSN']], |
| 257 | 'EXT8': DF['GSM']+[EF_num['EXT8']], |
| 258 | 'MMSICP': DF['GSM']+[EF_num['MMSICP']], |
| 259 | 'MMSUP': DF['GSM']+[EF_num['MMSUP']], |
| 260 | 'MMSUCP': DF['GSM']+[EF_num['MMSUCP']], |
| 261 | } |
Supreeth Herle | bf5d602 | 2020-03-20 15:18:27 +0100 | [diff] [blame] | 262 | |
| 263 | # Mapping between SIM Service Number and its description |
| 264 | EF_SST_map = { |
| 265 | 1: 'CHV1 disable function', |
| 266 | 2: 'Abbreviated Dialling Numbers (ADN)', |
| 267 | 3: 'Fixed Dialling Numbers (FDN)', |
| 268 | 4: 'Short Message Storage (SMS)', |
| 269 | 5: 'Advice of Charge (AoC)', |
| 270 | 6: 'Capability Configuration Parameters (CCP)', |
| 271 | 7: 'PLMN selector', |
| 272 | 8: 'RFU', |
| 273 | 9: 'MSISDN', |
| 274 | 10: 'Extension1', |
| 275 | 11: 'Extension2', |
| 276 | 12: 'SMS Parameters', |
| 277 | 13: 'Last Number Dialled (LND)', |
| 278 | 14: 'Cell Broadcast Message Identifier', |
| 279 | 15: 'Group Identifier Level 1', |
| 280 | 16: 'Group Identifier Level 2', |
| 281 | 17: 'Service Provider Name', |
| 282 | 18: 'Service Dialling Numbers (SDN)', |
| 283 | 19: 'Extension3', |
| 284 | 20: 'RFU', |
| 285 | 21: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)', |
| 286 | 22: 'VBS Group Identifier List (EFVBS and EFVBSS)', |
| 287 | 23: 'enhanced Multi-Level Precedence and Pre-emption Service', |
| 288 | 24: 'Automatic Answer for eMLPP', |
| 289 | 25: 'Data download via SMS-CB', |
| 290 | 26: 'Data download via SMS-PP', |
| 291 | 27: 'Menu selection', |
| 292 | 28: 'Call control', |
| 293 | 29: 'Proactive SIM', |
| 294 | 30: 'Cell Broadcast Message Identifier Ranges', |
| 295 | 31: 'Barred Dialling Numbers (BDN)', |
| 296 | 32: 'Extension4', |
| 297 | 33: 'De-personalization Control Keys', |
| 298 | 34: 'Co-operative Network List', |
| 299 | 35: 'Short Message Status Reports', |
| 300 | 36: 'Network\'s indication of alerting in the MS', |
| 301 | 37: 'Mobile Originated Short Message control by SIM', |
| 302 | 38: 'GPRS', |
| 303 | 39: 'Image (IMG)', |
| 304 | 40: 'SoLSA (Support of Local Service Area)', |
| 305 | 41: 'USSD string data object supported in Call Control', |
| 306 | 42: 'RUN AT COMMAND command', |
| 307 | 43: 'User controlled PLMN Selector with Access Technology', |
| 308 | 44: 'Operator controlled PLMN Selector with Access Technology', |
| 309 | 45: 'HPLMN Selector with Access Technology', |
| 310 | 46: 'CPBCCH Information', |
| 311 | 47: 'Investigation Scan', |
| 312 | 48: 'Extended Capability Configuration Parameters', |
| 313 | 49: 'MExE', |
| 314 | 50: 'Reserved and shall be ignored', |
| 315 | 51: 'PLMN Network Name', |
| 316 | 52: 'Operator PLMN List', |
| 317 | 53: 'Mailbox Dialling Numbers', |
| 318 | 54: 'Message Waiting Indication Status', |
| 319 | 55: 'Call Forwarding Indication Status', |
| 320 | 56: 'Service Provider Display Information', |
| 321 | 57: 'Multimedia Messaging Service (MMS)', |
| 322 | 58: 'Extension 8', |
| 323 | 59: 'MMS User Connectivity Parameters', |
Vadim Yanitskiy | dfe3dbb | 2020-07-28 05:26:02 +0700 | [diff] [blame] | 324 | } |
| 325 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 326 | from pySim.utils import * |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 327 | from pySim.tlv import * |
Harald Welte | aaf5931 | 2022-02-10 14:53:12 +0100 | [diff] [blame] | 328 | from typing import Tuple |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 329 | from struct import pack, unpack |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 330 | from construct import * |
| 331 | from construct import Optional as COptional |
Robert Falkenberg | b07a3e9 | 2021-05-07 15:23:20 +0200 | [diff] [blame] | 332 | from pySim.construct import * |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 333 | import enum |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 334 | |
| 335 | from pySim.filesystem import * |
Philipp Maier | a028c7d | 2021-11-08 16:12:03 +0100 | [diff] [blame] | 336 | from pySim.profile import CardProfile |
| 337 | from pySim.profile import match_sim |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 338 | |
| 339 | ###################################################################### |
| 340 | # DF.TELECOM |
| 341 | ###################################################################### |
| 342 | |
| 343 | # TS 51.011 Section 10.5.1 |
| 344 | class EF_ADN(LinFixedEF): |
| 345 | def __init__(self, fid='6f3a', sfid=None, name='EF.ADN', desc='Abbreviated Dialing Numbers'): |
| 346 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={14, 30}) |
| 347 | def _decode_record_bin(self, raw_bin_data): |
| 348 | alpha_id_len = len(raw_bin_data) - 14 |
| 349 | alpha_id = raw_bin_data[:alpha_id_len] |
| 350 | u = unpack('!BB10sBB', raw_bin_data[-14:]) |
| 351 | return {'alpha_id': alpha_id, 'len_of_bcd': u[0], 'ton_npi': u[1], |
| 352 | 'dialing_nr': u[2], 'cap_conf_id': u[3], 'ext1_record_id': u[4]} |
| 353 | |
| 354 | # TS 51.011 Section 10.5.5 |
Harald Welte | ec7d0da | 2021-04-02 22:01:19 +0200 | [diff] [blame] | 355 | class EF_SMS(LinFixedEF): |
| 356 | def __init__(self, fid='6f3c', sfid=None, name='EF.SMS', desc='Short messages'): |
| 357 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={176,176}) |
| 358 | def _decode_record_bin(self, raw_bin_data): |
| 359 | def decode_status(status): |
| 360 | if status & 0x01 == 0x00: |
| 361 | return (None, 'free_space') |
| 362 | elif status & 0x07 == 0x01: |
| 363 | return ('mt', 'message_read') |
| 364 | elif status & 0x07 == 0x03: |
| 365 | return ('mt', 'message_to_be_read') |
| 366 | elif status & 0x07 == 0x07: |
| 367 | return ('mo', 'message_to_be_sent') |
| 368 | elif status & 0x1f == 0x05: |
| 369 | return ('mo', 'sent_status_not_requested') |
| 370 | elif status & 0x1f == 0x0d: |
| 371 | return ('mo', 'sent_status_req_but_not_received') |
| 372 | elif status & 0x1f == 0x15: |
| 373 | return ('mo', 'sent_status_req_rx_not_stored_smsr') |
| 374 | elif status & 0x1f == 0x1d: |
| 375 | return ('mo', 'sent_status_req_rx_stored_smsr') |
| 376 | else: |
| 377 | return (None, 'rfu') |
| 378 | |
| 379 | status = decode_status(raw_bin_data[0]) |
| 380 | remainder = raw_bin_data[1:] |
| 381 | return {'direction': status[0], 'status': status[1], 'remainder': b2h(remainder)} |
| 382 | |
| 383 | |
| 384 | # TS 51.011 Section 10.5.5 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 385 | class EF_MSISDN(LinFixedEF): |
Harald Welte | ec7d0da | 2021-04-02 22:01:19 +0200 | [diff] [blame] | 386 | def __init__(self, fid='6f40', sfid=None, name='EF.MSISDN', desc='MSISDN'): |
Philipp Maier | b46cb3f | 2021-04-20 22:38:21 +0200 | [diff] [blame] | 387 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={15, 34}) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 388 | def _decode_record_hex(self, raw_hex_data): |
| 389 | return {'msisdn': dec_msisdn(raw_hex_data)} |
| 390 | def _encode_record_hex(self, abstract): |
Philipp Maier | f9cbe09 | 2021-04-23 19:37:36 +0200 | [diff] [blame] | 391 | msisdn = abstract['msisdn'] |
| 392 | if type(msisdn) == str: |
| 393 | encoded_msisdn = enc_msisdn(msisdn) |
| 394 | else: |
| 395 | encoded_msisdn = enc_msisdn(msisdn[2],msisdn[0],msisdn[1]) |
Philipp Maier | b46cb3f | 2021-04-20 22:38:21 +0200 | [diff] [blame] | 396 | alpha_identifier = (list(self.rec_len)[0] - len(encoded_msisdn) // 2) * "ff" |
| 397 | return alpha_identifier + encoded_msisdn |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 398 | |
| 399 | # TS 51.011 Section 10.5.6 |
| 400 | class EF_SMSP(LinFixedEF): |
| 401 | def __init__(self, fid='6f42', sfid=None, name='EF.SMSP', desc='Short message service parameters'): |
| 402 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={28, None}) |
| 403 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 404 | # TS 51.011 Section 10.5.7 |
| 405 | class EF_SMSS(TransparentEF): |
| 406 | class MemCapAdapter(Adapter): |
| 407 | def _decode(self, obj, context, path): |
| 408 | return False if obj & 1 else True |
| 409 | def _encode(self, obj, context, path): |
| 410 | return 0 if obj else 1 |
| 411 | def __init__(self, fid='6f43', sfid=None, name='EF.SMSS', desc='SMS status', size={2,8}): |
| 412 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 413 | self._construct = Struct('last_used_tpmr'/Int8ub, 'memory_capacity_exceeded'/self.MemCapAdapter(Int8ub)) |
| 414 | |
| 415 | # TS 51.011 Section 10.5.8 |
| 416 | class EF_SMSR(LinFixedEF): |
| 417 | def __init__(self, fid='6f47', sfid=None, name='EF.SMSR', desc='SMS status reports', rec_len={30,30}): |
| 418 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 419 | self._construct = Struct('sms_record_id'/Int8ub, 'sms_status_report'/HexAdapter(Bytes(29))) |
| 420 | |
| 421 | class EF_EXT(LinFixedEF): |
| 422 | def __init__(self, fid, sfid=None, name='EF.EXT', desc='Extension', rec_len={13,13}): |
| 423 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 424 | self._construct = Struct('record_type'/Int8ub, 'extension_data'/HexAdapter(Bytes(11)), 'identifier'/Int8ub) |
| 425 | |
| 426 | # TS 51.011 Section 10.5.16 |
| 427 | class EF_CMI(LinFixedEF): |
| 428 | def __init__(self, fid='6f58', sfid=None, name='EF.CMI', rec_len={2,21}, |
Harald Welte | c9cdce3 | 2021-04-11 10:28:28 +0200 | [diff] [blame] | 429 | desc='Comparison Method Information'): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 430 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 431 | self._construct = Struct('alpha_id'/Bytes(this._.total_len-1), 'comparison_method_id'/Int8ub) |
| 432 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 433 | class DF_TELECOM(CardDF): |
| 434 | def __init__(self, fid='7f10', name='DF.TELECOM', desc=None): |
| 435 | super().__init__(fid=fid, name=name, desc=desc) |
| 436 | files = [ |
| 437 | EF_ADN(), |
Harald Welte | 2a701ee | 2022-01-21 15:20:42 +0100 | [diff] [blame] | 438 | EF_ADN(fid='6f3b', name='EF.FDN', desc='Fixed dialling numbers'), |
Harald Welte | ec7d0da | 2021-04-02 22:01:19 +0200 | [diff] [blame] | 439 | EF_SMS(), |
| 440 | LinFixedEF(fid='6f3d', name='EF.CCP', desc='Capability Configuration Parameters', rec_len={14,14}), |
| 441 | LinFixedEF(fid='6f4f', name='EF.ECCP', desc='Extended Capability Configuration Parameters', rec_len={15,32}), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 442 | EF_MSISDN(), |
| 443 | EF_SMSP(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 444 | EF_SMSS(), |
| 445 | # LND, SDN |
| 446 | EF_EXT('6f4a', None, 'EF.EXT1', 'Extension1 (ADN/SSC)'), |
| 447 | EF_EXT('6f4b', None, 'EF.EXT2', 'Extension2 (FDN/SSC)'), |
| 448 | EF_EXT('6f4c', None, 'EF.EXT3', 'Extension3 (SDN)'), |
| 449 | EF_ADN(fid='6f4d', name='EF.BDN', desc='Barred Dialling Numbers'), |
| 450 | EF_EXT('6f4e', None, 'EF.EXT4', 'Extension4 (BDN/SSC)'), |
| 451 | EF_SMSR(), |
| 452 | EF_CMI(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 453 | ] |
| 454 | self.add_files(files) |
| 455 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 456 | ###################################################################### |
| 457 | # DF.GSM |
| 458 | ###################################################################### |
| 459 | |
| 460 | # TS 51.011 Section 10.3.1 |
| 461 | class EF_LP(TransRecEF): |
| 462 | def __init__(self, fid='6f05', sfid=None, name='EF.LP', size={1,None}, rec_len=1, |
| 463 | desc='Language Preference'): |
| 464 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 465 | def _decode_record_bin(self, in_bin): |
| 466 | return b2h(in_bin) |
| 467 | def _encode_record_bin(self, in_json): |
| 468 | return h2b(in_json) |
| 469 | |
| 470 | # TS 51.011 Section 10.3.2 |
| 471 | class EF_IMSI(TransparentEF): |
| 472 | def __init__(self, fid='6f07', sfid=None, name='EF.IMSI', desc='IMSI', size={9,9}): |
| 473 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 474 | # add those commands to the general commands of a TransparentEF |
| 475 | self.shell_commands += [self.AddlShellCommands(self)] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 476 | def _decode_hex(self, raw_hex): |
| 477 | return {'imsi': dec_imsi(raw_hex)} |
| 478 | def _encode_hex(self, abstract): |
| 479 | return enc_imsi(abstract['imsi']) |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 480 | @with_default_category('File-Specific Commands') |
| 481 | class AddlShellCommands(CommandSet): |
| 482 | def __init__(self,ef:TransparentEF): |
| 483 | super().__init__() |
| 484 | self._ef=ef |
| 485 | |
| 486 | def do_update_imsi_plmn(self, arg: str): |
| 487 | """Change the plmn part of the IMSI""" |
| 488 | plmn = arg.strip() |
| 489 | if len(plmn) == 5 or len(plmn) == 6: |
| 490 | (data, sw) = self._cmd.rs.read_binary_dec() |
| 491 | if sw == '9000' and len(data['imsi'])-len(plmn) == 10: |
| 492 | imsi = data['imsi'] |
| 493 | msin = imsi[len(plmn):] |
| 494 | (data, sw) = self._cmd.rs.update_binary_dec({'imsi': plmn+msin}) |
| 495 | if sw == '9000' and data: |
| 496 | self._cmd.poutput_json(self._cmd.rs.selected_file.decode_hex(data)) |
| 497 | else: |
| 498 | raise ValueError("PLMN length does not match IMSI length") |
| 499 | else: |
| 500 | raise ValueError("PLMN has wrong length!") |
| 501 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 502 | |
| 503 | # TS 51.011 Section 10.3.4 |
| 504 | class EF_PLMNsel(TransRecEF): |
| 505 | def __init__(self, fid='6f30', sfid=None, name='EF.PLMNsel', desc='PLMN selector', |
| 506 | size={24,None}, rec_len=3): |
| 507 | super().__init__(fid, name=name, sfid=sfid, desc=desc, size=size, rec_len=rec_len) |
| 508 | def _decode_record_hex(self, in_hex): |
| 509 | if in_hex[:6] == "ffffff": |
| 510 | return None |
| 511 | else: |
| 512 | return dec_plmn(in_hex) |
| 513 | def _encode_record_hex(self, in_json): |
| 514 | if in_json == None: |
| 515 | return "ffffff" |
| 516 | else: |
| 517 | return enc_plmn(in_json['mcc'], in_json['mnc']) |
| 518 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 519 | # TS 51.011 Section 10.3.6 |
| 520 | class EF_ACMmax(TransparentEF): |
| 521 | def __init__(self, fid='6f37', sfid=None, name='EF.ACMmax', size={3,3}, |
| 522 | desc='ACM maximum value'): |
| 523 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 524 | self._construct = Struct('acm_max'/Int24ub) |
| 525 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 526 | # TS 51.011 Section 10.3.7 |
| 527 | class EF_ServiceTable(TransparentEF): |
| 528 | def __init__(self, fid, sfid, name, desc, size, table): |
| 529 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 530 | self.table = table |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 531 | @staticmethod |
Harald Welte | aaf5931 | 2022-02-10 14:53:12 +0100 | [diff] [blame] | 532 | def _bit_byte_offset_for_service(service:int) -> Tuple[int, int]: |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 533 | i = service - 1 |
| 534 | byte_offset = i//4 |
| 535 | bit_offset = (i % 4) * 2 |
| 536 | return (byte_offset, bit_offset) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 537 | def _decode_bin(self, raw_bin): |
| 538 | ret = {} |
| 539 | for i in range(0, len(raw_bin)*4): |
| 540 | service_nr = i+1 |
| 541 | byte = int(raw_bin[i//4]) |
| 542 | bit_offset = (i % 4) * 2 |
| 543 | bits = (byte >> bit_offset) & 3 |
| 544 | ret[service_nr] = { |
Harald Welte | f898c28 | 2021-10-14 16:13:23 +0200 | [diff] [blame] | 545 | 'description': self.table[service_nr] if service_nr in self.table else None, |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 546 | 'allocated': True if bits & 1 else False, |
| 547 | 'activated': True if bits & 2 else False, |
| 548 | } |
| 549 | return ret |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 550 | def _encode_bin(self, in_json): |
| 551 | # compute the required binary size |
| 552 | bin_len = 0 |
| 553 | for srv in in_json.keys(): |
| 554 | service_nr = int(srv) |
| 555 | (byte_offset, bit_offset) = EF_ServiceTable._bit_byte_offset_for_service(service_nr) |
| 556 | if byte_offset >= bin_len: |
| 557 | bin_len = byte_offset+1 |
| 558 | # encode the actual data |
| 559 | out = bytearray(b'\x00' * bin_len) |
| 560 | for srv in in_json.keys(): |
| 561 | service_nr = int(srv) |
| 562 | (byte_offset, bit_offset) = EF_ServiceTable._bit_byte_offset_for_service(service_nr) |
| 563 | bits = 0 |
| 564 | if in_json[srv]['allocated'] == True: |
| 565 | bits |= 1 |
| 566 | if in_json[srv]['activated'] == True: |
| 567 | bits |= 2 |
| 568 | out[byte_offset] |= ((bits & 3) << bit_offset) |
| 569 | return out |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 570 | |
| 571 | # TS 51.011 Section 10.3.11 |
| 572 | class EF_SPN(TransparentEF): |
| 573 | def __init__(self, fid='6f46', sfid=None, name='EF.SPN', desc='Service Provider Name', size={17,17}): |
| 574 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Robert Falkenberg | b07a3e9 | 2021-05-07 15:23:20 +0200 | [diff] [blame] | 575 | self._construct = BitStruct( |
| 576 | # Byte 1 |
| 577 | 'rfu'/BitsRFU(6), |
| 578 | 'hide_in_oplmn'/Flag, |
| 579 | 'show_in_hplmn'/Flag, |
| 580 | # Bytes 2..17 |
| 581 | 'spn'/Bytewise(GsmString(16)) |
| 582 | ) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 583 | |
| 584 | # TS 51.011 Section 10.3.13 |
| 585 | class EF_CBMI(TransRecEF): |
| 586 | def __init__(self, fid='6f45', sfid=None, name='EF.CBMI', size={2,None}, rec_len=2, |
| 587 | desc='Cell Broadcast message identifier selection'): |
| 588 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 589 | self._construct = GreedyRange(Int16ub) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 590 | |
| 591 | # TS 51.011 Section 10.3.15 |
| 592 | class EF_ACC(TransparentEF): |
| 593 | def __init__(self, fid='6f78', sfid=None, name='EF.ACC', desc='Access Control Class', size={2,2}): |
| 594 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 595 | def _decode_bin(self, raw_bin): |
| 596 | return {'acc': unpack('!H', raw_bin)[0]} |
| 597 | def _encode_bin(self, abstract): |
| 598 | return pack('!H', abstract['acc']) |
| 599 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 600 | # TS 51.011 Section 10.3.16 |
| 601 | class EF_LOCI(TransparentEF): |
| 602 | def __init__(self, fid='6f7e', sfid=None, name='EF.LOCI', desc='Location Information', size={11,11}): |
| 603 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 604 | self._construct = Struct('tmsi'/Bytes(4), 'lai'/Bytes(5), 'tmsi_time'/Int8ub, |
| 605 | 'lu_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, |
| 606 | location_area_not_allowed=3)) |
| 607 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 608 | # TS 51.011 Section 10.3.18 |
| 609 | class EF_AD(TransparentEF): |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 610 | class OP_MODE(enum.IntEnum): |
| 611 | normal = 0x00 |
| 612 | type_approval = 0x80 |
| 613 | normal_and_specific_facilities = 0x01 |
| 614 | type_approval_and_specific_facilities = 0x81 |
| 615 | maintenance_off_line = 0x02 |
| 616 | cell_test = 0x04 |
| 617 | #OP_MODE_DICT = {int(v) : str(v) for v in EF_AD.OP_MODE} |
| 618 | #OP_MODE_DICT_REVERSED = {str(v) : int(v) for v in EF_AD.OP_MODE} |
| 619 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 620 | def __init__(self, fid='6fad', sfid=None, name='EF.AD', desc='Administrative Data', size={3,4}): |
| 621 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 622 | self._construct = BitStruct( |
| 623 | # Byte 1 |
| 624 | 'ms_operation_mode'/Bytewise(Enum(Byte, EF_AD.OP_MODE)), |
| 625 | # Byte 2 |
| 626 | 'rfu1'/Bytewise(ByteRFU), |
| 627 | # Byte 3 |
| 628 | 'rfu2'/BitsRFU(7), |
| 629 | 'ofm'/Flag, |
| 630 | # Byte 4 (optional), |
| 631 | 'extensions'/COptional(Struct( |
| 632 | 'rfu3'/BitsRFU(4), |
| 633 | 'mnc_len'/BitsInteger(4), |
| 634 | # Byte 5..N-4 (optional, RFU) |
| 635 | 'extensions'/Bytewise(GreedyBytesRFU) |
| 636 | )) |
| 637 | ) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 638 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 639 | # TS 51.011 Section 10.3.20 / 10.3.22 |
| 640 | class EF_VGCS(TransRecEF): |
| 641 | def __init__(self, fid='6fb1', sfid=None, name='EF.VGCS', size={4,200}, rec_len=4, |
| 642 | desc='Voice Group Call Service'): |
| 643 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 644 | self._construct = BcdAdapter(Bytes(4)) |
| 645 | |
| 646 | # TS 51.011 Section 10.3.21 / 10.3.23 |
| 647 | class EF_VGCSS(TransparentEF): |
| 648 | def __init__(self, fid='6fb2', sfid=None, name='EF.VGCSS', size={7,7}, |
| 649 | desc='Voice Group Call Service Status'): |
| 650 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 651 | self._construct = BitStruct('flags'/Bit[50], Padding(6, pattern=b'\xff')) |
| 652 | |
| 653 | # TS 51.011 Section 10.3.24 |
| 654 | class EF_eMLPP(TransparentEF): |
| 655 | def __init__(self, fid='6fb5', sfid=None, name='EF.eMLPP', size={2,2}, |
| 656 | desc='enhanced Multi Level Pre-emption and Priority'): |
| 657 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 658 | FlagsConstruct = FlagsEnum(Byte, A=1, B=2, zero=4, one=8, two=16, three=32, four=64) |
| 659 | self._construct = Struct('levels'/FlagsConstruct, 'fast_call_setup_cond'/FlagsConstruct) |
| 660 | |
| 661 | # TS 51.011 Section 10.3.25 |
| 662 | class EF_AAeM(TransparentEF): |
| 663 | def __init__(self, fid='6fb6', sfid=None, name='EF.AAeM', size={1,1}, |
| 664 | desc='Automatic Answer for eMLPP Service'): |
| 665 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 666 | FlagsConstruct = FlagsEnum(Byte, A=1, B=2, zero=4, one=8, two=16, three=32, four=64) |
| 667 | self._construct = Struct('auto_answer_prio_levels'/FlagsConstruct) |
| 668 | |
| 669 | # TS 51.011 Section 10.3.26 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 670 | class EF_CBMID(EF_CBMI): |
| 671 | def __init__(self, fid='6f48', sfid=None, name='EF.CBMID', size={2,None}, rec_len=2, |
| 672 | desc='Cell Broadcast Message Identifier for Data Download'): |
| 673 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 674 | self._construct = GreedyRange(Int16ub) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 675 | |
Harald Welte | 89e5954 | 2021-04-02 21:33:13 +0200 | [diff] [blame] | 676 | # TS 51.011 Section 10.3.27 |
| 677 | class EF_ECC(TransRecEF): |
| 678 | def __init__(self, fid='6fb7', sfid=None, name='EF.ECC', size={3,15}, rec_len=3, |
| 679 | desc='Emergency Call Codes'): |
| 680 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 681 | self._construct = GreedyRange(BcdAdapter(Bytes(3))) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 682 | |
| 683 | # TS 51.011 Section 10.3.28 |
| 684 | class EF_CBMIR(TransRecEF): |
| 685 | def __init__(self, fid='6f50', sfid=None, name='EF.CBMIR', size={4,None}, rec_len=4, |
| 686 | desc='Cell Broadcast message identifier range selection'): |
| 687 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 688 | self._construct = GreedyRange(Struct('lower'/Int16ub, 'upper'/Int16ub)) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 689 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 690 | # TS 51.011 Section 10.3.29 |
| 691 | class EF_DCK(TransparentEF): |
| 692 | def __init__(self, fid='6f2c', sfid=None, name='EF.DCK', size={16,16}, |
| 693 | desc='Depersonalisation Control Keys'): |
| 694 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 695 | self._construct = Struct('network'/BcdAdapter(Bytes(4)), |
| 696 | 'network_subset'/BcdAdapter(Bytes(4)), |
| 697 | 'service_provider'/BcdAdapter(Bytes(4)), |
| 698 | 'corporate'/BcdAdapter(Bytes(4))) |
| 699 | # TS 51.011 Section 10.3.30 |
| 700 | class EF_CNL(TransRecEF): |
| 701 | def __init__(self, fid='6f32', sfid=None, name='EF.CNL', size={6,None}, rec_len=6, |
| 702 | desc='Co-operative Network List'): |
| 703 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 704 | def _decode_record_hex(self, in_hex): |
| 705 | (in_plmn, sub, svp, corp) = unpack('!3sBBB', h2b(in_hex)) |
| 706 | res = dec_plmn(b2h(in_plmn)) |
| 707 | res['network_subset'] = sub |
| 708 | res['service_provider_id'] = svp |
| 709 | res['corporate_id'] = corp |
| 710 | return res |
| 711 | def _encode_record_hex(self, in_json): |
| 712 | plmn = enc_plmn(in_json['mcc'], in_json['mnc']) |
Vadim Yanitskiy | 1a95d2b | 2021-05-02 01:42:09 +0200 | [diff] [blame] | 713 | return b2h(pack('!3sBBB', |
| 714 | h2b(plmn), |
| 715 | in_json['network_subset'], |
| 716 | in_json['service_provider_id'], |
| 717 | in_json['corporate_id'])) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 718 | |
| 719 | # TS 51.011 Section 10.3.31 |
| 720 | class EF_NIA(LinFixedEF): |
| 721 | def __init__(self, fid='6f51', sfid=None, name='EF.NIA', rec_len={1,32}, |
| 722 | desc='Network\'s Indication of Alerting'): |
| 723 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 724 | self._construct = Struct('alerting_category'/Int8ub, 'category'/GreedyBytes) |
| 725 | |
| 726 | # TS 51.011 Section 10.3.32 |
| 727 | class EF_Kc(TransparentEF): |
| 728 | def __init__(self, fid='6f20', sfid=None, name='EF.Kc', desc='Ciphering key Kc', size={9,9}): |
| 729 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 730 | self._construct = Struct('kc'/HexAdapter(Bytes(8)), 'cksn'/Int8ub) |
| 731 | |
| 732 | # TS 51.011 Section 10.3.33 |
| 733 | class EF_LOCIGPRS(TransparentEF): |
| 734 | def __init__(self, fid='6f53', sfid=None, name='EF.LOCIGPRS', desc='GPRS Location Information', size={14,14}): |
| 735 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 736 | self._construct = Struct('ptmsi'/Bytes(4), 'ptmsi_sig'/Int8ub, 'rai'/Bytes(6), |
| 737 | 'rau_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, |
| 738 | routing_area_not_allowed=3)) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 739 | |
| 740 | # TS 51.011 Section 10.3.35..37 |
| 741 | class EF_xPLMNwAcT(TransRecEF): |
| 742 | def __init__(self, fid, sfid=None, name=None, desc=None, size={40,None}, rec_len=5): |
| 743 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 744 | def _decode_record_hex(self, in_hex): |
| 745 | if in_hex[:6] == "ffffff": |
| 746 | return None |
| 747 | else: |
| 748 | return dec_xplmn_w_act(in_hex) |
| 749 | def _encode_record_hex(self, in_json): |
| 750 | if in_json == None: |
| 751 | return "ffffff0000" |
| 752 | else: |
| 753 | hplmn = enc_plmn(in_json['mcc'], in_json['mnc']) |
| 754 | act = self.enc_act(in_json['act']) |
| 755 | return hplmn + act |
| 756 | @staticmethod |
| 757 | def enc_act(in_list): |
| 758 | u16 = 0 |
| 759 | # first the simple ones |
| 760 | if 'UTRAN' in in_list: |
| 761 | u16 |= 0x8000 |
| 762 | if 'NG-RAN' in in_list: |
| 763 | u16 |= 0x0800 |
| 764 | if 'GSM COMPACT' in in_list: |
| 765 | u16 |= 0x0040 |
| 766 | if 'cdma2000 HRPD' in in_list: |
| 767 | u16 |= 0x0020 |
| 768 | if 'cdma2000 1xRTT' in in_list: |
| 769 | u16 |= 0x0010 |
| 770 | # E-UTRAN |
Philipp Maier | e7d4179 | 2021-04-29 16:20:07 +0200 | [diff] [blame] | 771 | if 'E-UTRAN' in in_list: |
| 772 | u16 |= 0x4000 |
Vadim Yanitskiy | 5452d64 | 2021-03-07 21:45:34 +0100 | [diff] [blame] | 773 | if 'E-UTRAN WB-S1' in in_list: |
| 774 | u16 |= 0x6000 |
| 775 | if 'E-UTRAN NB-S1' in in_list: |
| 776 | u16 |= 0x5000 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 777 | # GSM mess |
| 778 | if 'GSM' in in_list and 'EC-GSM-IoT' in in_list: |
| 779 | u16 |= 0x008C |
| 780 | elif 'GSM' in in_list: |
| 781 | u16 |= 0x0084 |
| 782 | elif 'EC-GSM-IuT' in in_list: |
| 783 | u16 |= 0x0088 |
| 784 | return '%04X'%(u16) |
| 785 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 786 | # TS 51.011 Section 10.3.38 |
| 787 | class EF_CPBCCH(TransRecEF): |
| 788 | def __init__(self, fid='6f63', sfid=None, name='EF.CPBCCH', size={2,14}, rec_len=2, |
| 789 | desc='CPBCCH Information'): |
| 790 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 791 | self._construct = Struct('cpbcch'/Int16ub) |
| 792 | |
| 793 | # TS 51.011 Section 10.3.39 |
| 794 | class EF_InvScan(TransparentEF): |
| 795 | def __init__(self, fid='6f64', sfid=None, name='EF.InvScan', size={1,1}, |
| 796 | desc='IOnvestigation Scan'): |
| 797 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 798 | self._construct = FlagsEnum(Byte, in_limited_service_mode=1, after_successful_plmn_selection=2) |
| 799 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 800 | # TS 51.011 Section 4.2.58 |
| 801 | class EF_PNN(LinFixedEF): |
| 802 | class FullNameForNetwork(BER_TLV_IE, tag=0x43): |
| 803 | # TS 24.008 10.5.3.5a |
| 804 | pass |
| 805 | class ShortNameForNetwork(BER_TLV_IE, tag=0x45): |
| 806 | # TS 24.008 10.5.3.5a |
| 807 | pass |
| 808 | class NetworkNameCollection(TLV_IE_Collection, nested=[FullNameForNetwork, ShortNameForNetwork]): |
| 809 | pass |
| 810 | def __init__(self, fid='6fc5', sfid=None, name='EF.PNN', desc='PLMN Network Name'): |
| 811 | super().__init__(fid, sfid=sfid, name=name, desc=desc) |
| 812 | self._tlv = EF_PNN.NetworkNameCollection |
| 813 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 814 | # TS 51.011 Section 10.3.42 |
| 815 | class EF_OPL(LinFixedEF): |
| 816 | def __init__(self, fid='6fc6', sfid=None, name='EF.OPL', rec_len={8,8}, desc='Operator PLMN List'): |
| 817 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 818 | self._construct = Struct('lai'/Bytes(5), 'pnn_record_id'/Int8ub) |
| 819 | |
| 820 | # TS 51.011 Section 10.3.44 + TS 31.102 4.2.62 |
| 821 | class EF_MBI(LinFixedEF): |
| 822 | def __init__(self, fid='6fc9', sfid=None, name='EF.MBI', rec_len={4,5}, desc='Mailbox Identifier'): |
| 823 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 824 | self._construct = Struct('mbi_voicemail'/Int8ub, 'mbi_fax'/Int8ub, 'mbi_email'/Int8ub, |
| 825 | 'mbi_other'/Int8ub, 'mbi_videocall'/COptional(Int8ub)) |
| 826 | |
| 827 | # TS 51.011 Section 10.3.45 + TS 31.102 4.2.63 |
| 828 | class EF_MWIS(LinFixedEF): |
| 829 | def __init__(self, fid='6fca', sfid=None, name='EF.MWIS', rec_len={5,6}, |
| 830 | desc='Message Waiting Indication Status'): |
| 831 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 832 | self._construct = Struct('mwi_status'/FlagsEnum(Byte, voicemail=1, fax=2, email=4, other=8, videomail=16), |
| 833 | 'num_waiting_voicemail'/Int8ub, |
| 834 | 'num_waiting_fax'/Int8ub, 'num_waiting_email'/Int8ub, |
| 835 | 'num_waiting_other'/Int8ub, 'num_waiting_videomail'/COptional(Int8ub)) |
| 836 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 837 | # TS 51.011 Section 10.3.66 |
| 838 | class EF_SPDI(TransparentEF): |
| 839 | class ServiceProviderPLMN(BER_TLV_IE, tag=0x80): |
| 840 | # flexible numbers of 3-byte PLMN records |
| 841 | _construct = GreedyRange(BcdAdapter(Bytes(3))) |
| 842 | class SPDI(BER_TLV_IE, tag=0xA3, nested=[ServiceProviderPLMN]): |
| 843 | pass |
| 844 | def __init__(self, fid='6fcd', sfid=None, name='EF.SPDI', |
| 845 | desc='Service Provider Display Information'): |
| 846 | super().__init__(fid, sfid=sfid, name=name, desc=desc) |
| 847 | self._tlv = EF_SPDI.SPDI |
| 848 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 849 | # TS 51.011 Section 10.3.51 |
| 850 | class EF_MMSN(LinFixedEF): |
| 851 | def __init__(self, fid='6fce', sfid=None, name='EF.MMSN', rec_len={4,20}, desc='MMS Notification'): |
| 852 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 853 | self._construct = Struct('mms_status'/Bytes(2), 'mms_implementation'/Bytes(1), |
| 854 | 'mms_notification'/Bytes(this._.total_len-4), 'ext_record_nr'/Byte) |
| 855 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 856 | # TS 51.011 Annex K.1 |
| 857 | class MMS_Implementation(BER_TLV_IE, tag=0x80): |
| 858 | _construct = FlagsEnum(Byte, WAP=1) |
| 859 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 860 | # TS 51.011 Section 10.3.53 |
| 861 | class EF_MMSICP(TransparentEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 862 | class MMS_Relay_Server(BER_TLV_IE, tag=0x81): |
| 863 | # 3GPP TS 23.140 |
| 864 | pass |
| 865 | class Interface_to_CN(BER_TLV_IE, tag=0x82): |
| 866 | # 3GPP TS 23.140 |
| 867 | pass |
| 868 | class Gateway(BER_TLV_IE, tag=0x83): |
| 869 | # Address, Type of address, Port, Service, AuthType, AuthId, AuthPass / 3GPP TS 23.140 |
| 870 | pass |
| 871 | class MMS_ConnectivityParamters(TLV_IE_Collection, |
| 872 | nested=[MMS_Implementation, MMS_Relay_Server, Interface_to_CN, Gateway]): |
| 873 | pass |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 874 | def __init__(self, fid='6fd0', sfid=None, name='EF.MMSICP', size={1,None}, |
| 875 | desc='MMS Issuer Connectivity Parameters'): |
| 876 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 877 | self._tlv = EF_MMSICP.MMS_ConnectivityParamters |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 878 | |
| 879 | # TS 51.011 Section 10.3.54 |
| 880 | class EF_MMSUP(LinFixedEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 881 | class MMS_UserPref_ProfileName(BER_TLV_IE, tag=0x81): |
| 882 | pass |
| 883 | class MMS_UserPref_Info(BER_TLV_IE, tag=0x82): |
| 884 | pass |
| 885 | class MMS_User_Preferences(TLV_IE_Collection, |
| 886 | nested=[MMS_Implementation,MMS_UserPref_ProfileName,MMS_UserPref_Info]): |
| 887 | pass |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 888 | def __init__(self, fid='6fd1', sfid=None, name='EF.MMSUP', rec_len={1,None}, |
| 889 | desc='MMS User Preferences'): |
| 890 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
Harald Welte | 6113fe9 | 2022-01-21 15:51:35 +0100 | [diff] [blame] | 891 | self._tlv = EF_MMSUP.MMS_User_Preferences |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 892 | |
| 893 | # TS 51.011 Section 10.3.55 |
| 894 | class EF_MMSUCP(TransparentEF): |
| 895 | def __init__(self, fid='6fd2', sfid=None, name='EF.MMSUCP', size={1,None}, |
| 896 | desc='MMS User Connectivity Parameters'): |
| 897 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 898 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 899 | |
| 900 | class DF_GSM(CardDF): |
| 901 | def __init__(self, fid='7f20', name='DF.GSM', desc='GSM Network related files'): |
| 902 | super().__init__(fid=fid, name=name, desc=desc) |
| 903 | files = [ |
| 904 | EF_LP(), |
| 905 | EF_IMSI(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 906 | EF_Kc(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 907 | EF_PLMNsel(), |
| 908 | TransparentEF('6f31', None, 'EF.HPPLMN', 'Higher Priority PLMN search period'), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 909 | EF_ACMmax(), |
| 910 | EF_ServiceTable('6f38', None, 'EF.SST', 'SIM service table', table=EF_SST_map, size={2,16}), |
| 911 | CyclicEF('6f39', None, 'EF.ACM', 'Accumulated call meter', rec_len={3,3}), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 912 | TransparentEF('6f3e', None, 'EF.GID1', 'Group Identifier Level 1'), |
| 913 | TransparentEF('6f3f', None, 'EF.GID2', 'Group Identifier Level 2'), |
| 914 | EF_SPN(), |
| 915 | TransparentEF('6f41', None, 'EF.PUCT', 'Price per unit and currency table', size={5,5}), |
| 916 | EF_CBMI(), |
| 917 | TransparentEF('6f7f', None, 'EF.BCCH', 'Broadcast control channels', size={16,16}), |
| 918 | EF_ACC(), |
| 919 | EF_PLMNsel('6f7b', None, 'EF.FPLMN', 'Forbidden PLMNs', size={12,12}), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 920 | EF_LOCI(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 921 | EF_AD(), |
| 922 | TransparentEF('6fa3', None, 'EF.Phase', 'Phase identification', size={1,1}), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 923 | EF_VGCS(), |
| 924 | EF_VGCSS(), |
| 925 | EF_VGCS('6fb3', None, 'EF.VBS', 'Voice Broadcast Service'), |
| 926 | EF_VGCSS('6fb4', None, 'EF.VBSS', 'Voice Broadcast Service Status'), |
| 927 | EF_eMLPP(), |
| 928 | EF_AAeM(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 929 | EF_CBMID(), |
| 930 | EF_ECC(), |
| 931 | EF_CBMIR(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 932 | EF_DCK(), |
| 933 | EF_CNL(), |
| 934 | EF_NIA(), |
| 935 | EF_Kc('6f52', None, 'EF.KcGPRS', 'GPRS Ciphering key KcGPRS'), |
| 936 | EF_LOCIGPRS(), |
| 937 | TransparentEF('6f54', None, 'EF.SUME', 'SetUpMenu Elements'), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 938 | EF_xPLMNwAcT('6f60', None, 'EF.PLMNwAcT', |
| 939 | 'User controlled PLMN Selector with Access Technology'), |
| 940 | EF_xPLMNwAcT('6f61', None, 'EF.OPLMNwAcT', |
| 941 | 'Operator controlled PLMN Selector with Access Technology'), |
| 942 | EF_xPLMNwAcT('6f62', None, 'EF.HPLMNwAcT', 'HPLMN Selector with Access Technology'), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 943 | EF_CPBCCH(), |
| 944 | EF_InvScan(), |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 945 | EF_PNN(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 946 | EF_OPL(), |
| 947 | EF_ADN('6fc7', None, 'EF.MBDN', 'Mailbox Dialling Numbers'), |
| 948 | EF_MBI(), |
| 949 | EF_MWIS(), |
| 950 | EF_ADN('6fcb', None, 'EF.CFIS', 'Call Forwarding Indication Status'), |
| 951 | EF_EXT('6fc8', None, 'EF.EXT6', 'Externsion6 (MBDN)'), |
| 952 | EF_EXT('6fcc', None, 'EF.EXT7', 'Externsion7 (CFIS)'), |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 953 | EF_SPDI(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 954 | EF_MMSN(), |
| 955 | EF_EXT('6fcf', None, 'EF.EXT8', 'Extension8 (MMSN)'), |
| 956 | EF_MMSICP(), |
| 957 | EF_MMSUP(), |
| 958 | EF_MMSUCP(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 959 | ] |
| 960 | self.add_files(files) |
| 961 | |
Philipp Maier | c8387dc | 2021-10-29 17:59:50 +0200 | [diff] [blame] | 962 | class CardProfileSIM(CardProfile): |
Philipp Maier | a028c7d | 2021-11-08 16:12:03 +0100 | [diff] [blame] | 963 | |
| 964 | ORDER = 2 |
| 965 | |
Philipp Maier | c8387dc | 2021-10-29 17:59:50 +0200 | [diff] [blame] | 966 | def __init__(self): |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 967 | sw = { |
| 968 | 'Normal': { |
| 969 | '9000': 'Normal ending of the command', |
| 970 | '91xx': 'normal ending of the command, with extra information from the proactive SIM containing a command for the ME', |
| 971 | '9exx': 'length XX of the response data given in case of a SIM data download error', |
| 972 | '9fxx': 'length XX of the response data', |
| 973 | }, |
| 974 | 'Postponed processing': { |
| 975 | '9300': 'SIM Application Toolkit is busy. Command cannot be executed at present, further normal commands are allowed', |
| 976 | }, |
| 977 | 'Memory management': { |
| 978 | '920x': 'command successful but after using an internal update retry routine X times', |
| 979 | '9240': 'memory problem', |
| 980 | }, |
| 981 | 'Referencing management': { |
| 982 | '9400': 'no EF selected', |
| 983 | '9402': 'out of range (invalid address)', |
| 984 | '9404': 'file ID not found or pattern not found', |
| 985 | '9408': 'file is inconsistent with the command', |
| 986 | }, |
| 987 | 'Security management': { |
| 988 | '9802': 'no CHV initialized', |
| 989 | '9804': 'access condition not fulfilled, unsuccessful CHV verification or authentication failed', |
| 990 | '9808': 'in contradiction with CHV status', |
| 991 | '9810': 'in contradiction with invalidation status', |
| 992 | '9840': 'unsuccessful verification, CHV blocked, UNBLOCK CHV blocked', |
| 993 | '9850': 'increase cannot be performed, Max value reached', |
| 994 | }, |
| 995 | 'Application independent errors': { |
| 996 | '67xx': 'incorrect parameter P3', |
| 997 | '6bxx': 'incorrect parameter P1 or P2', |
| 998 | '6dxx': 'unknown instruction code given in the command', |
| 999 | '6exx': 'wrong instruction class given in the command', |
| 1000 | '6fxx': 'technical problem with no diagnostic given', |
| 1001 | }, |
| 1002 | } |
| 1003 | |
| 1004 | super().__init__('SIM', desc='GSM SIM Card', cla="a0", sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM()], sw=sw) |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1005 | |
Philipp Maier | 5998a3a | 2021-11-16 15:16:39 +0100 | [diff] [blame] | 1006 | @staticmethod |
Philipp Maier | 9e42e7f | 2021-11-16 15:46:42 +0100 | [diff] [blame] | 1007 | def decode_select_response(resp_hex:str) -> object: |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1008 | resp_bin = h2b(resp_hex) |
| 1009 | struct_of_file_map = { |
| 1010 | 0: 'transparent', |
| 1011 | 1: 'linear_fixed', |
| 1012 | 3: 'cyclic' |
| 1013 | } |
| 1014 | type_of_file_map = { |
| 1015 | 1: 'mf', |
| 1016 | 2: 'df', |
| 1017 | 4: 'working_ef' |
| 1018 | } |
| 1019 | ret = { |
| 1020 | 'file_descriptor': {}, |
| 1021 | 'proprietary_info': {}, |
| 1022 | } |
| 1023 | ret['file_id'] = b2h(resp_bin[4:6]) |
| 1024 | ret['proprietary_info']['available_memory'] = int.from_bytes(resp_bin[2:4], 'big') |
| 1025 | file_type = type_of_file_map[resp_bin[6]] if resp_bin[6] in type_of_file_map else resp_bin[6] |
| 1026 | ret['file_descriptor']['file_type'] = file_type |
| 1027 | if file_type in ['mf', 'df']: |
| 1028 | ret['file_characteristics'] = b2h(resp_bin[13:14]) |
| 1029 | ret['num_direct_child_df'] = resp_bin[14] |
| 1030 | ret['num_direct_child_ef'] = resp_bin[15] |
| 1031 | ret['num_chv_unblock_adm_codes'] = int(resp_bin[16]) |
| 1032 | # CHV / UNBLOCK CHV stats |
| 1033 | elif file_type in ['working_ef']: |
| 1034 | file_struct = struct_of_file_map[resp_bin[13]] if resp_bin[13] in struct_of_file_map else resp_bin[13] |
| 1035 | ret['file_descriptor']['structure'] = file_struct |
| 1036 | ret['access_conditions'] = b2h(resp_bin[8:10]) |
| 1037 | if resp_bin[11] & 0x01 == 0: |
| 1038 | ret['life_cycle_status_int'] = 'operational_activated' |
| 1039 | elif resp_bin[11] & 0x04: |
| 1040 | ret['life_cycle_status_int'] = 'operational_deactivated' |
| 1041 | else: |
| 1042 | ret['life_cycle_status_int'] = 'terminated' |
| 1043 | return ret |
Philipp Maier | a028c7d | 2021-11-08 16:12:03 +0100 | [diff] [blame] | 1044 | |
| 1045 | @staticmethod |
| 1046 | def match_with_card(scc:SimCardCommands) -> bool: |
| 1047 | return match_sim(scc) |