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 | b07a3e9 | 2021-05-07 15:23:20 +0200 | [diff] [blame] | 326 | from pySim.construct import * |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 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 | f9cbe09 | 2021-04-23 19:37:36 +0200 | [diff] [blame] | 384 | msisdn = abstract['msisdn'] |
| 385 | if type(msisdn) == str: |
| 386 | encoded_msisdn = enc_msisdn(msisdn) |
| 387 | else: |
| 388 | encoded_msisdn = enc_msisdn(msisdn[2],msisdn[0],msisdn[1]) |
Philipp Maier | b46cb3f | 2021-04-20 22:38:21 +0200 | [diff] [blame] | 389 | alpha_identifier = (list(self.rec_len)[0] - len(encoded_msisdn) // 2) * "ff" |
| 390 | return alpha_identifier + encoded_msisdn |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 391 | |
| 392 | # TS 51.011 Section 10.5.6 |
| 393 | class EF_SMSP(LinFixedEF): |
| 394 | def __init__(self, fid='6f42', sfid=None, name='EF.SMSP', desc='Short message service parameters'): |
| 395 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={28, None}) |
| 396 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 397 | # TS 51.011 Section 10.5.7 |
| 398 | class EF_SMSS(TransparentEF): |
| 399 | class MemCapAdapter(Adapter): |
| 400 | def _decode(self, obj, context, path): |
| 401 | return False if obj & 1 else True |
| 402 | def _encode(self, obj, context, path): |
| 403 | return 0 if obj else 1 |
| 404 | def __init__(self, fid='6f43', sfid=None, name='EF.SMSS', desc='SMS status', size={2,8}): |
| 405 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 406 | self._construct = Struct('last_used_tpmr'/Int8ub, 'memory_capacity_exceeded'/self.MemCapAdapter(Int8ub)) |
| 407 | |
| 408 | # TS 51.011 Section 10.5.8 |
| 409 | class EF_SMSR(LinFixedEF): |
| 410 | def __init__(self, fid='6f47', sfid=None, name='EF.SMSR', desc='SMS status reports', rec_len={30,30}): |
| 411 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 412 | self._construct = Struct('sms_record_id'/Int8ub, 'sms_status_report'/HexAdapter(Bytes(29))) |
| 413 | |
| 414 | class EF_EXT(LinFixedEF): |
| 415 | def __init__(self, fid, sfid=None, name='EF.EXT', desc='Extension', rec_len={13,13}): |
| 416 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 417 | self._construct = Struct('record_type'/Int8ub, 'extension_data'/HexAdapter(Bytes(11)), 'identifier'/Int8ub) |
| 418 | |
| 419 | # TS 51.011 Section 10.5.16 |
| 420 | class EF_CMI(LinFixedEF): |
| 421 | 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] | 422 | desc='Comparison Method Information'): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 423 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 424 | self._construct = Struct('alpha_id'/Bytes(this._.total_len-1), 'comparison_method_id'/Int8ub) |
| 425 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 426 | class DF_TELECOM(CardDF): |
| 427 | def __init__(self, fid='7f10', name='DF.TELECOM', desc=None): |
| 428 | super().__init__(fid=fid, name=name, desc=desc) |
| 429 | files = [ |
| 430 | EF_ADN(), |
Harald Welte | ec7d0da | 2021-04-02 22:01:19 +0200 | [diff] [blame] | 431 | EF_ADN(fid='6f3b', name='EF_FDN', desc='Fixed dialling numbers'), |
| 432 | EF_SMS(), |
| 433 | LinFixedEF(fid='6f3d', name='EF.CCP', desc='Capability Configuration Parameters', rec_len={14,14}), |
| 434 | 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] | 435 | EF_MSISDN(), |
| 436 | EF_SMSP(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 437 | EF_SMSS(), |
| 438 | # LND, SDN |
| 439 | EF_EXT('6f4a', None, 'EF.EXT1', 'Extension1 (ADN/SSC)'), |
| 440 | EF_EXT('6f4b', None, 'EF.EXT2', 'Extension2 (FDN/SSC)'), |
| 441 | EF_EXT('6f4c', None, 'EF.EXT3', 'Extension3 (SDN)'), |
| 442 | EF_ADN(fid='6f4d', name='EF.BDN', desc='Barred Dialling Numbers'), |
| 443 | EF_EXT('6f4e', None, 'EF.EXT4', 'Extension4 (BDN/SSC)'), |
| 444 | EF_SMSR(), |
| 445 | EF_CMI(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 446 | ] |
| 447 | self.add_files(files) |
| 448 | |
| 449 | def decode_select_response(self, data_hex): |
| 450 | return decode_select_response(data_hex) |
| 451 | |
| 452 | ###################################################################### |
| 453 | # DF.GSM |
| 454 | ###################################################################### |
| 455 | |
| 456 | # TS 51.011 Section 10.3.1 |
| 457 | class EF_LP(TransRecEF): |
| 458 | def __init__(self, fid='6f05', sfid=None, name='EF.LP', size={1,None}, rec_len=1, |
| 459 | desc='Language Preference'): |
| 460 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 461 | def _decode_record_bin(self, in_bin): |
| 462 | return b2h(in_bin) |
| 463 | def _encode_record_bin(self, in_json): |
| 464 | return h2b(in_json) |
| 465 | |
| 466 | # TS 51.011 Section 10.3.2 |
| 467 | class EF_IMSI(TransparentEF): |
| 468 | def __init__(self, fid='6f07', sfid=None, name='EF.IMSI', desc='IMSI', size={9,9}): |
| 469 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 470 | def _decode_hex(self, raw_hex): |
| 471 | return {'imsi': dec_imsi(raw_hex)} |
| 472 | def _encode_hex(self, abstract): |
| 473 | return enc_imsi(abstract['imsi']) |
| 474 | |
| 475 | # TS 51.011 Section 10.3.4 |
| 476 | class EF_PLMNsel(TransRecEF): |
| 477 | def __init__(self, fid='6f30', sfid=None, name='EF.PLMNsel', desc='PLMN selector', |
| 478 | size={24,None}, rec_len=3): |
| 479 | super().__init__(fid, name=name, sfid=sfid, desc=desc, size=size, rec_len=rec_len) |
| 480 | def _decode_record_hex(self, in_hex): |
| 481 | if in_hex[:6] == "ffffff": |
| 482 | return None |
| 483 | else: |
| 484 | return dec_plmn(in_hex) |
| 485 | def _encode_record_hex(self, in_json): |
| 486 | if in_json == None: |
| 487 | return "ffffff" |
| 488 | else: |
| 489 | return enc_plmn(in_json['mcc'], in_json['mnc']) |
| 490 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 491 | # TS 51.011 Section 10.3.6 |
| 492 | class EF_ACMmax(TransparentEF): |
| 493 | def __init__(self, fid='6f37', sfid=None, name='EF.ACMmax', size={3,3}, |
| 494 | desc='ACM maximum value'): |
| 495 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 496 | self._construct = Struct('acm_max'/Int24ub) |
| 497 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 498 | # TS 51.011 Section 10.3.7 |
| 499 | class EF_ServiceTable(TransparentEF): |
| 500 | def __init__(self, fid, sfid, name, desc, size, table): |
| 501 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 502 | self.table = table |
| 503 | def _decode_bin(self, raw_bin): |
| 504 | ret = {} |
| 505 | for i in range(0, len(raw_bin)*4): |
| 506 | service_nr = i+1 |
| 507 | byte = int(raw_bin[i//4]) |
| 508 | bit_offset = (i % 4) * 2 |
| 509 | bits = (byte >> bit_offset) & 3 |
| 510 | ret[service_nr] = { |
| 511 | 'description': self.table[service_nr] or None, |
| 512 | 'allocated': True if bits & 1 else False, |
| 513 | 'activated': True if bits & 2 else False, |
| 514 | } |
| 515 | return ret |
| 516 | # TODO: encoder |
| 517 | |
| 518 | # TS 51.011 Section 10.3.11 |
| 519 | class EF_SPN(TransparentEF): |
| 520 | def __init__(self, fid='6f46', sfid=None, name='EF.SPN', desc='Service Provider Name', size={17,17}): |
| 521 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Robert Falkenberg | b07a3e9 | 2021-05-07 15:23:20 +0200 | [diff] [blame] | 522 | self._construct = BitStruct( |
| 523 | # Byte 1 |
| 524 | 'rfu'/BitsRFU(6), |
| 525 | 'hide_in_oplmn'/Flag, |
| 526 | 'show_in_hplmn'/Flag, |
| 527 | # Bytes 2..17 |
| 528 | 'spn'/Bytewise(GsmString(16)) |
| 529 | ) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 530 | |
| 531 | # TS 51.011 Section 10.3.13 |
| 532 | class EF_CBMI(TransRecEF): |
| 533 | def __init__(self, fid='6f45', sfid=None, name='EF.CBMI', size={2,None}, rec_len=2, |
| 534 | desc='Cell Broadcast message identifier selection'): |
| 535 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 536 | |
| 537 | # TS 51.011 Section 10.3.15 |
| 538 | class EF_ACC(TransparentEF): |
| 539 | def __init__(self, fid='6f78', sfid=None, name='EF.ACC', desc='Access Control Class', size={2,2}): |
| 540 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 541 | def _decode_bin(self, raw_bin): |
| 542 | return {'acc': unpack('!H', raw_bin)[0]} |
| 543 | def _encode_bin(self, abstract): |
| 544 | return pack('!H', abstract['acc']) |
| 545 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 546 | # TS 51.011 Section 10.3.16 |
| 547 | class EF_LOCI(TransparentEF): |
| 548 | def __init__(self, fid='6f7e', sfid=None, name='EF.LOCI', desc='Location Information', size={11,11}): |
| 549 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 550 | self._construct = Struct('tmsi'/Bytes(4), 'lai'/Bytes(5), 'tmsi_time'/Int8ub, |
| 551 | 'lu_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, |
| 552 | location_area_not_allowed=3)) |
| 553 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 554 | # TS 51.011 Section 10.3.18 |
| 555 | class EF_AD(TransparentEF): |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 556 | class OP_MODE(enum.IntEnum): |
| 557 | normal = 0x00 |
| 558 | type_approval = 0x80 |
| 559 | normal_and_specific_facilities = 0x01 |
| 560 | type_approval_and_specific_facilities = 0x81 |
| 561 | maintenance_off_line = 0x02 |
| 562 | cell_test = 0x04 |
| 563 | #OP_MODE_DICT = {int(v) : str(v) for v in EF_AD.OP_MODE} |
| 564 | #OP_MODE_DICT_REVERSED = {str(v) : int(v) for v in EF_AD.OP_MODE} |
| 565 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 566 | def __init__(self, fid='6fad', sfid=None, name='EF.AD', desc='Administrative Data', size={3,4}): |
| 567 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 568 | self._construct = BitStruct( |
| 569 | # Byte 1 |
| 570 | 'ms_operation_mode'/Bytewise(Enum(Byte, EF_AD.OP_MODE)), |
| 571 | # Byte 2 |
| 572 | 'rfu1'/Bytewise(ByteRFU), |
| 573 | # Byte 3 |
| 574 | 'rfu2'/BitsRFU(7), |
| 575 | 'ofm'/Flag, |
| 576 | # Byte 4 (optional), |
| 577 | 'extensions'/COptional(Struct( |
| 578 | 'rfu3'/BitsRFU(4), |
| 579 | 'mnc_len'/BitsInteger(4), |
| 580 | # Byte 5..N-4 (optional, RFU) |
| 581 | 'extensions'/Bytewise(GreedyBytesRFU) |
| 582 | )) |
| 583 | ) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 584 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 585 | # TS 51.011 Section 10.3.20 / 10.3.22 |
| 586 | class EF_VGCS(TransRecEF): |
| 587 | def __init__(self, fid='6fb1', sfid=None, name='EF.VGCS', size={4,200}, rec_len=4, |
| 588 | desc='Voice Group Call Service'): |
| 589 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 590 | self._construct = BcdAdapter(Bytes(4)) |
| 591 | |
| 592 | # TS 51.011 Section 10.3.21 / 10.3.23 |
| 593 | class EF_VGCSS(TransparentEF): |
| 594 | def __init__(self, fid='6fb2', sfid=None, name='EF.VGCSS', size={7,7}, |
| 595 | desc='Voice Group Call Service Status'): |
| 596 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 597 | self._construct = BitStruct('flags'/Bit[50], Padding(6, pattern=b'\xff')) |
| 598 | |
| 599 | # TS 51.011 Section 10.3.24 |
| 600 | class EF_eMLPP(TransparentEF): |
| 601 | def __init__(self, fid='6fb5', sfid=None, name='EF.eMLPP', size={2,2}, |
| 602 | desc='enhanced Multi Level Pre-emption and Priority'): |
| 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('levels'/FlagsConstruct, 'fast_call_setup_cond'/FlagsConstruct) |
| 606 | |
| 607 | # TS 51.011 Section 10.3.25 |
| 608 | class EF_AAeM(TransparentEF): |
| 609 | def __init__(self, fid='6fb6', sfid=None, name='EF.AAeM', size={1,1}, |
| 610 | desc='Automatic Answer for eMLPP Service'): |
| 611 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 612 | FlagsConstruct = FlagsEnum(Byte, A=1, B=2, zero=4, one=8, two=16, three=32, four=64) |
| 613 | self._construct = Struct('auto_answer_prio_levels'/FlagsConstruct) |
| 614 | |
| 615 | # TS 51.011 Section 10.3.26 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 616 | class EF_CBMID(EF_CBMI): |
| 617 | def __init__(self, fid='6f48', sfid=None, name='EF.CBMID', size={2,None}, rec_len=2, |
| 618 | desc='Cell Broadcast Message Identifier for Data Download'): |
| 619 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 620 | |
Harald Welte | 89e5954 | 2021-04-02 21:33:13 +0200 | [diff] [blame] | 621 | # TS 51.011 Section 10.3.27 |
| 622 | class EF_ECC(TransRecEF): |
| 623 | def __init__(self, fid='6fb7', sfid=None, name='EF.ECC', size={3,15}, rec_len=3, |
| 624 | desc='Emergency Call Codes'): |
| 625 | 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] | 626 | |
| 627 | # TS 51.011 Section 10.3.28 |
| 628 | class EF_CBMIR(TransRecEF): |
| 629 | def __init__(self, fid='6f50', sfid=None, name='EF.CBMIR', size={4,None}, rec_len=4, |
| 630 | desc='Cell Broadcast message identifier range selection'): |
| 631 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 632 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 633 | # TS 51.011 Section 10.3.29 |
| 634 | class EF_DCK(TransparentEF): |
| 635 | def __init__(self, fid='6f2c', sfid=None, name='EF.DCK', size={16,16}, |
| 636 | desc='Depersonalisation Control Keys'): |
| 637 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 638 | self._construct = Struct('network'/BcdAdapter(Bytes(4)), |
| 639 | 'network_subset'/BcdAdapter(Bytes(4)), |
| 640 | 'service_provider'/BcdAdapter(Bytes(4)), |
| 641 | 'corporate'/BcdAdapter(Bytes(4))) |
| 642 | # TS 51.011 Section 10.3.30 |
| 643 | class EF_CNL(TransRecEF): |
| 644 | def __init__(self, fid='6f32', sfid=None, name='EF.CNL', size={6,None}, rec_len=6, |
| 645 | desc='Co-operative Network List'): |
| 646 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 647 | def _decode_record_hex(self, in_hex): |
| 648 | (in_plmn, sub, svp, corp) = unpack('!3sBBB', h2b(in_hex)) |
| 649 | res = dec_plmn(b2h(in_plmn)) |
| 650 | res['network_subset'] = sub |
| 651 | res['service_provider_id'] = svp |
| 652 | res['corporate_id'] = corp |
| 653 | return res |
| 654 | def _encode_record_hex(self, in_json): |
| 655 | plmn = enc_plmn(in_json['mcc'], in_json['mnc']) |
Vadim Yanitskiy | 1a95d2b | 2021-05-02 01:42:09 +0200 | [diff] [blame] | 656 | return b2h(pack('!3sBBB', |
| 657 | h2b(plmn), |
| 658 | in_json['network_subset'], |
| 659 | in_json['service_provider_id'], |
| 660 | in_json['corporate_id'])) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 661 | |
| 662 | # TS 51.011 Section 10.3.31 |
| 663 | class EF_NIA(LinFixedEF): |
| 664 | def __init__(self, fid='6f51', sfid=None, name='EF.NIA', rec_len={1,32}, |
| 665 | desc='Network\'s Indication of Alerting'): |
| 666 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 667 | self._construct = Struct('alerting_category'/Int8ub, 'category'/GreedyBytes) |
| 668 | |
| 669 | # TS 51.011 Section 10.3.32 |
| 670 | class EF_Kc(TransparentEF): |
| 671 | def __init__(self, fid='6f20', sfid=None, name='EF.Kc', desc='Ciphering key Kc', size={9,9}): |
| 672 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 673 | self._construct = Struct('kc'/HexAdapter(Bytes(8)), 'cksn'/Int8ub) |
| 674 | |
| 675 | # TS 51.011 Section 10.3.33 |
| 676 | class EF_LOCIGPRS(TransparentEF): |
| 677 | def __init__(self, fid='6f53', sfid=None, name='EF.LOCIGPRS', desc='GPRS Location Information', size={14,14}): |
| 678 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 679 | self._construct = Struct('ptmsi'/Bytes(4), 'ptmsi_sig'/Int8ub, 'rai'/Bytes(6), |
| 680 | 'rau_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, |
| 681 | routing_area_not_allowed=3)) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 682 | |
| 683 | # TS 51.011 Section 10.3.35..37 |
| 684 | class EF_xPLMNwAcT(TransRecEF): |
| 685 | def __init__(self, fid, sfid=None, name=None, desc=None, size={40,None}, rec_len=5): |
| 686 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 687 | def _decode_record_hex(self, in_hex): |
| 688 | if in_hex[:6] == "ffffff": |
| 689 | return None |
| 690 | else: |
| 691 | return dec_xplmn_w_act(in_hex) |
| 692 | def _encode_record_hex(self, in_json): |
| 693 | if in_json == None: |
| 694 | return "ffffff0000" |
| 695 | else: |
| 696 | hplmn = enc_plmn(in_json['mcc'], in_json['mnc']) |
| 697 | act = self.enc_act(in_json['act']) |
| 698 | return hplmn + act |
| 699 | @staticmethod |
| 700 | def enc_act(in_list): |
| 701 | u16 = 0 |
| 702 | # first the simple ones |
| 703 | if 'UTRAN' in in_list: |
| 704 | u16 |= 0x8000 |
| 705 | if 'NG-RAN' in in_list: |
| 706 | u16 |= 0x0800 |
| 707 | if 'GSM COMPACT' in in_list: |
| 708 | u16 |= 0x0040 |
| 709 | if 'cdma2000 HRPD' in in_list: |
| 710 | u16 |= 0x0020 |
| 711 | if 'cdma2000 1xRTT' in in_list: |
| 712 | u16 |= 0x0010 |
| 713 | # E-UTRAN |
Philipp Maier | e7d4179 | 2021-04-29 16:20:07 +0200 | [diff] [blame] | 714 | if 'E-UTRAN' in in_list: |
| 715 | u16 |= 0x4000 |
Vadim Yanitskiy | 5452d64 | 2021-03-07 21:45:34 +0100 | [diff] [blame] | 716 | if 'E-UTRAN WB-S1' in in_list: |
| 717 | u16 |= 0x6000 |
| 718 | if 'E-UTRAN NB-S1' in in_list: |
| 719 | u16 |= 0x5000 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 720 | # GSM mess |
| 721 | if 'GSM' in in_list and 'EC-GSM-IoT' in in_list: |
| 722 | u16 |= 0x008C |
| 723 | elif 'GSM' in in_list: |
| 724 | u16 |= 0x0084 |
| 725 | elif 'EC-GSM-IuT' in in_list: |
| 726 | u16 |= 0x0088 |
| 727 | return '%04X'%(u16) |
| 728 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 729 | # TS 51.011 Section 10.3.38 |
| 730 | class EF_CPBCCH(TransRecEF): |
| 731 | def __init__(self, fid='6f63', sfid=None, name='EF.CPBCCH', size={2,14}, rec_len=2, |
| 732 | desc='CPBCCH Information'): |
| 733 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
| 734 | self._construct = Struct('cpbcch'/Int16ub) |
| 735 | |
| 736 | # TS 51.011 Section 10.3.39 |
| 737 | class EF_InvScan(TransparentEF): |
| 738 | def __init__(self, fid='6f64', sfid=None, name='EF.InvScan', size={1,1}, |
| 739 | desc='IOnvestigation Scan'): |
| 740 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 741 | self._construct = FlagsEnum(Byte, in_limited_service_mode=1, after_successful_plmn_selection=2) |
| 742 | |
| 743 | # TS 51.011 Section 10.3.42 |
| 744 | class EF_OPL(LinFixedEF): |
| 745 | def __init__(self, fid='6fc6', sfid=None, name='EF.OPL', rec_len={8,8}, desc='Operator PLMN List'): |
| 746 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 747 | self._construct = Struct('lai'/Bytes(5), 'pnn_record_id'/Int8ub) |
| 748 | |
| 749 | # TS 51.011 Section 10.3.44 + TS 31.102 4.2.62 |
| 750 | class EF_MBI(LinFixedEF): |
| 751 | def __init__(self, fid='6fc9', sfid=None, name='EF.MBI', rec_len={4,5}, desc='Mailbox Identifier'): |
| 752 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 753 | self._construct = Struct('mbi_voicemail'/Int8ub, 'mbi_fax'/Int8ub, 'mbi_email'/Int8ub, |
| 754 | 'mbi_other'/Int8ub, 'mbi_videocall'/COptional(Int8ub)) |
| 755 | |
| 756 | # TS 51.011 Section 10.3.45 + TS 31.102 4.2.63 |
| 757 | class EF_MWIS(LinFixedEF): |
| 758 | def __init__(self, fid='6fca', sfid=None, name='EF.MWIS', rec_len={5,6}, |
| 759 | desc='Message Waiting Indication Status'): |
| 760 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 761 | self._construct = Struct('mwi_status'/FlagsEnum(Byte, voicemail=1, fax=2, email=4, other=8, videomail=16), |
| 762 | 'num_waiting_voicemail'/Int8ub, |
| 763 | 'num_waiting_fax'/Int8ub, 'num_waiting_email'/Int8ub, |
| 764 | 'num_waiting_other'/Int8ub, 'num_waiting_videomail'/COptional(Int8ub)) |
| 765 | |
| 766 | # TS 51.011 Section 10.3.51 |
| 767 | class EF_MMSN(LinFixedEF): |
| 768 | def __init__(self, fid='6fce', sfid=None, name='EF.MMSN', rec_len={4,20}, desc='MMS Notification'): |
| 769 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 770 | self._construct = Struct('mms_status'/Bytes(2), 'mms_implementation'/Bytes(1), |
| 771 | 'mms_notification'/Bytes(this._.total_len-4), 'ext_record_nr'/Byte) |
| 772 | |
| 773 | # TS 51.011 Section 10.3.53 |
| 774 | class EF_MMSICP(TransparentEF): |
| 775 | def __init__(self, fid='6fd0', sfid=None, name='EF.MMSICP', size={1,None}, |
| 776 | desc='MMS Issuer Connectivity Parameters'): |
| 777 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 778 | |
| 779 | # TS 51.011 Section 10.3.54 |
| 780 | class EF_MMSUP(LinFixedEF): |
| 781 | def __init__(self, fid='6fd1', sfid=None, name='EF.MMSUP', rec_len={1,None}, |
| 782 | desc='MMS User Preferences'): |
| 783 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len) |
| 784 | |
| 785 | # TS 51.011 Section 10.3.55 |
| 786 | class EF_MMSUCP(TransparentEF): |
| 787 | def __init__(self, fid='6fd2', sfid=None, name='EF.MMSUCP', size={1,None}, |
| 788 | desc='MMS User Connectivity Parameters'): |
| 789 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 790 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 791 | |
| 792 | class DF_GSM(CardDF): |
| 793 | def __init__(self, fid='7f20', name='DF.GSM', desc='GSM Network related files'): |
| 794 | super().__init__(fid=fid, name=name, desc=desc) |
| 795 | files = [ |
| 796 | EF_LP(), |
| 797 | EF_IMSI(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 798 | EF_Kc(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 799 | EF_PLMNsel(), |
| 800 | TransparentEF('6f31', None, 'EF.HPPLMN', 'Higher Priority PLMN search period'), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 801 | EF_ACMmax(), |
| 802 | EF_ServiceTable('6f38', None, 'EF.SST', 'SIM service table', table=EF_SST_map, size={2,16}), |
| 803 | CyclicEF('6f39', None, 'EF.ACM', 'Accumulated call meter', rec_len={3,3}), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 804 | TransparentEF('6f3e', None, 'EF.GID1', 'Group Identifier Level 1'), |
| 805 | TransparentEF('6f3f', None, 'EF.GID2', 'Group Identifier Level 2'), |
| 806 | EF_SPN(), |
| 807 | TransparentEF('6f41', None, 'EF.PUCT', 'Price per unit and currency table', size={5,5}), |
| 808 | EF_CBMI(), |
| 809 | TransparentEF('6f7f', None, 'EF.BCCH', 'Broadcast control channels', size={16,16}), |
| 810 | EF_ACC(), |
| 811 | EF_PLMNsel('6f7b', None, 'EF.FPLMN', 'Forbidden PLMNs', size={12,12}), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 812 | EF_LOCI(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 813 | EF_AD(), |
| 814 | TransparentEF('6fa3', None, 'EF.Phase', 'Phase identification', size={1,1}), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 815 | EF_VGCS(), |
| 816 | EF_VGCSS(), |
| 817 | EF_VGCS('6fb3', None, 'EF.VBS', 'Voice Broadcast Service'), |
| 818 | EF_VGCSS('6fb4', None, 'EF.VBSS', 'Voice Broadcast Service Status'), |
| 819 | EF_eMLPP(), |
| 820 | EF_AAeM(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 821 | EF_CBMID(), |
| 822 | EF_ECC(), |
| 823 | EF_CBMIR(), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 824 | EF_DCK(), |
| 825 | EF_CNL(), |
| 826 | EF_NIA(), |
| 827 | EF_Kc('6f52', None, 'EF.KcGPRS', 'GPRS Ciphering key KcGPRS'), |
| 828 | EF_LOCIGPRS(), |
| 829 | TransparentEF('6f54', None, 'EF.SUME', 'SetUpMenu Elements'), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 830 | EF_xPLMNwAcT('6f60', None, 'EF.PLMNwAcT', |
| 831 | 'User controlled PLMN Selector with Access Technology'), |
| 832 | EF_xPLMNwAcT('6f61', None, 'EF.OPLMNwAcT', |
| 833 | 'Operator controlled PLMN Selector with Access Technology'), |
| 834 | EF_xPLMNwAcT('6f62', None, 'EF.HPLMNwAcT', 'HPLMN Selector with Access Technology'), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 835 | EF_CPBCCH(), |
| 836 | EF_InvScan(), |
| 837 | LinFixedEF('6fc5', None,'EF.PNN', 'PLMN Network Name'), |
| 838 | EF_OPL(), |
| 839 | EF_ADN('6fc7', None, 'EF.MBDN', 'Mailbox Dialling Numbers'), |
| 840 | EF_MBI(), |
| 841 | EF_MWIS(), |
| 842 | EF_ADN('6fcb', None, 'EF.CFIS', 'Call Forwarding Indication Status'), |
| 843 | EF_EXT('6fc8', None, 'EF.EXT6', 'Externsion6 (MBDN)'), |
| 844 | EF_EXT('6fcc', None, 'EF.EXT7', 'Externsion7 (CFIS)'), |
| 845 | TransparentEF('6fcd', None, 'EF.SPDI', 'Service Provider Display Information'), |
| 846 | EF_MMSN(), |
| 847 | EF_EXT('6fcf', None, 'EF.EXT8', 'Extension8 (MMSN)'), |
| 848 | EF_MMSICP(), |
| 849 | EF_MMSUP(), |
| 850 | EF_MMSUCP(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 851 | ] |
| 852 | self.add_files(files) |
| 853 | |
| 854 | def decode_select_response(self, data_hex): |
| 855 | return decode_select_response(data_hex) |
| 856 | |
| 857 | def decode_select_response(resp_hex): |
| 858 | resp_bin = h2b(resp_hex) |
| 859 | if resp_bin[0] == 0x62: |
| 860 | return pySim.ts_102_221.decode_select_response(resp_hex) |
| 861 | struct_of_file_map = { |
| 862 | 0: 'transparent', |
| 863 | 1: 'linear_fixed', |
| 864 | 3: 'cyclic' |
| 865 | } |
| 866 | type_of_file_map = { |
| 867 | 1: 'mf', |
| 868 | 2: 'df', |
| 869 | 4: 'working_ef' |
| 870 | } |
| 871 | ret = { |
| 872 | 'file_descriptor': {}, |
| 873 | 'proprietary_info': {}, |
| 874 | } |
| 875 | ret['file_id'] = b2h(resp_bin[4:6]) |
| 876 | ret['proprietary_info']['available_memory'] = int.from_bytes(resp_bin[2:4], 'big') |
| 877 | file_type = type_of_file_map[resp_bin[6]] if resp_bin[6] in type_of_file_map else resp_bin[6] |
| 878 | ret['file_descriptor']['file_type'] = file_type |
| 879 | if file_type in ['mf', 'df']: |
| 880 | ret['file_characteristics'] = b2h(resp_bin[13]) |
| 881 | ret['num_direct_child_df'] = int(resp_bin[14], 16) |
| 882 | ret['num_direct_child_ef'] = int(resp_bin[15], 16) |
Harald Welte | c9cdce3 | 2021-04-11 10:28:28 +0200 | [diff] [blame] | 883 | ret['num_chv_unblock_adm_codes'] = int(resp_bin[16]) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 884 | # CHV / UNBLOCK CHV stats |
| 885 | elif file_type in ['working_ef']: |
| 886 | file_struct = struct_of_file_map[resp_bin[13]] if resp_bin[13] in struct_of_file_map else resp_bin[13] |
| 887 | ret['file_descriptor']['structure'] = file_struct |
| 888 | ret['access_conditions'] = b2h(resp_bin[8:10]) |
| 889 | if resp_bin[11] & 0x01 == 0: |
| 890 | ret['life_cycle_status_int'] = 'operational_activated' |
| 891 | elif resp_bin[11] & 0x04: |
| 892 | ret['life_cycle_status_int'] = 'operational_deactivated' |
| 893 | else: |
| 894 | ret['life_cycle_status_int'] = 'terminated' |
| 895 | |
| 896 | return ret |
| 897 | |
| 898 | CardProfileSIM = CardProfile('SIM', desc='GSM SIM Card', files_in_mf=[DF_TELECOM(), DF_GSM()]) |