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