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 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 32 | from pySim.profile import match_sim |
| 33 | from pySim.profile import CardProfile |
| 34 | from pySim.filesystem import * |
Harald Welte | 228ae8e | 2022-07-17 22:01:04 +0200 | [diff] [blame] | 35 | from pySim.ts_31_102_telecom import DF_PHONEBOOK, DF_MULTIMEDIA, DF_MCS, DF_V2X |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 36 | import enum |
| 37 | from pySim.construct import * |
| 38 | from construct import Optional as COptional |
| 39 | from construct import * |
| 40 | from struct import pack, unpack |
| 41 | from typing import Tuple |
| 42 | from pySim.tlv import * |
| 43 | from pySim.utils import * |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 44 | MF_num = '3F00' |
| 45 | |
| 46 | DF_num = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 47 | 'TELECOM': '7F10', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 48 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 49 | 'GSM': '7F20', |
| 50 | 'IS-41': '7F22', |
| 51 | 'FP-CTS': '7F23', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 52 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 53 | 'GRAPHICS': '5F50', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 54 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 55 | 'IRIDIUM': '5F30', |
| 56 | 'GLOBST': '5F31', |
| 57 | 'ICO': '5F32', |
| 58 | 'ACeS': '5F33', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 59 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 60 | 'EIA/TIA-553': '5F40', |
| 61 | 'CTS': '5F60', |
| 62 | 'SOLSA': '5F70', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 63 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 64 | 'MExE': '5F3C', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | EF_num = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 68 | # MF |
| 69 | 'ICCID': '2FE2', |
| 70 | 'ELP': '2F05', |
| 71 | 'DIR': '2F00', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 72 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 73 | # DF_TELECOM |
| 74 | 'ADN': '6F3A', |
| 75 | 'FDN': '6F3B', |
| 76 | 'SMS': '6F3C', |
| 77 | 'CCP': '6F3D', |
| 78 | 'MSISDN': '6F40', |
| 79 | 'SMSP': '6F42', |
| 80 | 'SMSS': '6F43', |
| 81 | 'LND': '6F44', |
| 82 | 'SMSR': '6F47', |
| 83 | 'SDN': '6F49', |
| 84 | 'EXT1': '6F4A', |
| 85 | 'EXT2': '6F4B', |
| 86 | 'EXT3': '6F4C', |
| 87 | 'BDN': '6F4D', |
| 88 | 'EXT4': '6F4E', |
| 89 | 'CMI': '6F58', |
| 90 | 'ECCP': '6F4F', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 91 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 92 | # DF_GRAPHICS |
| 93 | 'IMG': '4F20', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 94 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 95 | # DF_SoLSA |
| 96 | 'SAI': '4F30', |
| 97 | 'SLL': '4F31', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 98 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 99 | # DF_MExE |
| 100 | 'MExE-ST': '4F40', |
| 101 | 'ORPK': '4F41', |
| 102 | 'ARPK': '4F42', |
| 103 | 'TPRPK': '4F43', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 104 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 105 | # DF_GSM |
| 106 | 'LP': '6F05', |
| 107 | 'IMSI': '6F07', |
| 108 | 'Kc': '6F20', |
| 109 | 'DCK': '6F2C', |
| 110 | 'PLMNsel': '6F30', |
| 111 | 'HPPLMN': '6F31', |
| 112 | 'CNL': '6F32', |
| 113 | 'ACMmax': '6F37', |
| 114 | 'SST': '6F38', |
| 115 | 'ACM': '6F39', |
| 116 | 'GID1': '6F3E', |
| 117 | 'GID2': '6F3F', |
| 118 | 'PUCT': '6F41', |
| 119 | 'CBMI': '6F45', |
| 120 | 'SPN': '6F46', |
| 121 | 'CBMID': '6F48', |
| 122 | 'BCCH': '6F74', |
| 123 | 'ACC': '6F78', |
| 124 | 'FPLMN': '6F7B', |
| 125 | 'LOCI': '6F7E', |
| 126 | 'AD': '6FAD', |
| 127 | 'PHASE': '6FAE', |
| 128 | 'VGCS': '6FB1', |
| 129 | 'VGCSS': '6FB2', |
| 130 | 'VBS': '6FB3', |
| 131 | 'VBSS': '6FB4', |
| 132 | 'eMLPP': '6FB5', |
| 133 | 'AAeM': '6FB6', |
| 134 | 'ECC': '6FB7', |
| 135 | 'CBMIR': '6F50', |
| 136 | 'NIA': '6F51', |
| 137 | 'KcGPRS': '6F52', |
| 138 | 'LOCIGPRS': '6F53', |
| 139 | 'SUME': '6F54', |
| 140 | 'PLMNwAcT': '6F60', |
| 141 | 'OPLMNwAcT': '6F61', |
| 142 | # Figure 8 names it HPLMNAcT, but in the text it's names it HPLMNwAcT |
| 143 | 'HPLMNAcT': '6F62', |
| 144 | 'HPLMNwAcT': '6F62', |
| 145 | 'CPBCCH': '6F63', |
| 146 | 'INVSCAN': '6F64', |
| 147 | 'PNN': '6FC5', |
| 148 | 'OPL': '6FC6', |
| 149 | 'MBDN': '6FC7', |
| 150 | 'EXT6': '6FC8', |
| 151 | 'MBI': '6FC9', |
| 152 | 'MWIS': '6FCA', |
| 153 | 'CFIS': '6FCB', |
| 154 | 'EXT7': '6FCC', |
| 155 | 'SPDI': '6FCD', |
| 156 | 'MMSN': '6FCE', |
| 157 | 'EXT8': '6FCF', |
| 158 | 'MMSICP': '6FD0', |
| 159 | 'MMSUP': '6FD1', |
| 160 | 'MMSUCP': '6FD2', |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | DF = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 164 | 'TELECOM': [MF_num, DF_num['TELECOM']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 165 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 166 | 'GSM': [MF_num, DF_num['GSM']], |
| 167 | 'IS-41': [MF_num, DF_num['IS-41']], |
| 168 | 'FP-CTS': [MF_num, DF_num['FP-CTS']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 169 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 170 | 'GRAPHICS': [MF_num, DF_num['GRAPHICS']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 171 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 172 | 'IRIDIUM': [MF_num, DF_num['IRIDIUM']], |
| 173 | 'GLOBST': [MF_num, DF_num['GLOBST']], |
| 174 | 'ICO': [MF_num, DF_num['ICO']], |
| 175 | 'ACeS': [MF_num, DF_num['ACeS']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 176 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 177 | 'EIA/TIA-553': [MF_num, DF_num['EIA/TIA-553']], |
| 178 | 'CTS': [MF_num, DF_num['CTS']], |
| 179 | 'SoLSA': [MF_num, DF_num['SOLSA']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 180 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 181 | 'MExE': [MF_num, DF_num['MExE']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
| 185 | EF = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 186 | 'ICCID': [MF_num, EF_num['ICCID']], |
| 187 | 'ELP': [MF_num, EF_num['ELP']], |
| 188 | 'DIR': [MF_num, EF_num['DIR']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 189 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 190 | 'ADN': DF['TELECOM']+[EF_num['ADN']], |
| 191 | 'FDN': DF['TELECOM']+[EF_num['FDN']], |
| 192 | 'SMS': DF['TELECOM']+[EF_num['SMS']], |
| 193 | 'CCP': DF['TELECOM']+[EF_num['CCP']], |
| 194 | 'MSISDN': DF['TELECOM']+[EF_num['MSISDN']], |
| 195 | 'SMSP': DF['TELECOM']+[EF_num['SMSP']], |
| 196 | 'SMSS': DF['TELECOM']+[EF_num['SMSS']], |
| 197 | 'LND': DF['TELECOM']+[EF_num['LND']], |
| 198 | 'SMSR': DF['TELECOM']+[EF_num['SMSR']], |
| 199 | 'SDN': DF['TELECOM']+[EF_num['SDN']], |
| 200 | 'EXT1': DF['TELECOM']+[EF_num['EXT1']], |
| 201 | 'EXT2': DF['TELECOM']+[EF_num['EXT2']], |
| 202 | 'EXT3': DF['TELECOM']+[EF_num['EXT3']], |
| 203 | 'BDN': DF['TELECOM']+[EF_num['BDN']], |
| 204 | 'EXT4': DF['TELECOM']+[EF_num['EXT4']], |
| 205 | 'CMI': DF['TELECOM']+[EF_num['CMI']], |
| 206 | 'ECCP': DF['TELECOM']+[EF_num['ECCP']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 207 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 208 | 'IMG': DF['GRAPHICS']+[EF_num['IMG']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 209 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 210 | 'SAI': DF['SoLSA']+[EF_num['SAI']], |
| 211 | 'SLL': DF['SoLSA']+[EF_num['SLL']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 212 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 213 | 'MExE-ST': DF['MExE']+[EF_num['MExE-ST']], |
| 214 | 'ORPK': DF['MExE']+[EF_num['ORPK']], |
| 215 | 'ARPK': DF['MExE']+[EF_num['ARPK']], |
| 216 | 'TPRPK': DF['MExE']+[EF_num['TPRPK']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 217 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 218 | 'LP': DF['GSM']+[EF_num['LP']], |
| 219 | 'IMSI': DF['GSM']+[EF_num['IMSI']], |
| 220 | 'Kc': DF['GSM']+[EF_num['Kc']], |
| 221 | 'DCK': DF['GSM']+[EF_num['DCK']], |
| 222 | 'PLMNsel': DF['GSM']+[EF_num['PLMNsel']], |
| 223 | 'HPPLMN': DF['GSM']+[EF_num['HPPLMN']], |
| 224 | 'CNL': DF['GSM']+[EF_num['CNL']], |
| 225 | 'ACMmax': DF['GSM']+[EF_num['ACMmax']], |
| 226 | 'SST': DF['GSM']+[EF_num['SST']], |
| 227 | 'ACM': DF['GSM']+[EF_num['ACM']], |
| 228 | 'GID1': DF['GSM']+[EF_num['GID1']], |
| 229 | 'GID2': DF['GSM']+[EF_num['GID2']], |
| 230 | 'PUCT': DF['GSM']+[EF_num['PUCT']], |
| 231 | 'CBMI': DF['GSM']+[EF_num['CBMI']], |
| 232 | 'SPN': DF['GSM']+[EF_num['SPN']], |
| 233 | 'CBMID': DF['GSM']+[EF_num['CBMID']], |
| 234 | 'BCCH': DF['GSM']+[EF_num['BCCH']], |
| 235 | 'ACC': DF['GSM']+[EF_num['ACC']], |
| 236 | 'FPLMN': DF['GSM']+[EF_num['FPLMN']], |
| 237 | 'LOCI': DF['GSM']+[EF_num['LOCI']], |
| 238 | 'AD': DF['GSM']+[EF_num['AD']], |
| 239 | 'PHASE': DF['GSM']+[EF_num['PHASE']], |
| 240 | 'VGCS': DF['GSM']+[EF_num['VGCS']], |
| 241 | 'VGCSS': DF['GSM']+[EF_num['VGCSS']], |
| 242 | 'VBS': DF['GSM']+[EF_num['VBS']], |
| 243 | 'VBSS': DF['GSM']+[EF_num['VBSS']], |
| 244 | 'eMLPP': DF['GSM']+[EF_num['eMLPP']], |
| 245 | 'AAeM': DF['GSM']+[EF_num['AAeM']], |
| 246 | 'ECC': DF['GSM']+[EF_num['ECC']], |
| 247 | 'CBMIR': DF['GSM']+[EF_num['CBMIR']], |
| 248 | 'NIA': DF['GSM']+[EF_num['NIA']], |
| 249 | 'KcGPRS': DF['GSM']+[EF_num['KcGPRS']], |
| 250 | 'LOCIGPRS': DF['GSM']+[EF_num['LOCIGPRS']], |
| 251 | 'SUME': DF['GSM']+[EF_num['SUME']], |
| 252 | 'PLMNwAcT': DF['GSM']+[EF_num['PLMNwAcT']], |
| 253 | 'OPLMNwAcT': DF['GSM']+[EF_num['OPLMNwAcT']], |
| 254 | # Figure 8 names it HPLMNAcT, but in the text it's names it HPLMNwAcT |
| 255 | 'HPLMNAcT': DF['GSM']+[EF_num['HPLMNAcT']], |
| 256 | 'HPLMNwAcT': DF['GSM']+[EF_num['HPLMNAcT']], |
| 257 | 'CPBCCH': DF['GSM']+[EF_num['CPBCCH']], |
| 258 | 'INVSCAN': DF['GSM']+[EF_num['INVSCAN']], |
| 259 | 'PNN': DF['GSM']+[EF_num['PNN']], |
| 260 | 'OPL': DF['GSM']+[EF_num['OPL']], |
| 261 | 'MBDN': DF['GSM']+[EF_num['MBDN']], |
| 262 | 'EXT6': DF['GSM']+[EF_num['EXT6']], |
| 263 | 'MBI': DF['GSM']+[EF_num['MBI']], |
| 264 | 'MWIS': DF['GSM']+[EF_num['MWIS']], |
| 265 | 'CFIS': DF['GSM']+[EF_num['CFIS']], |
| 266 | 'EXT7': DF['GSM']+[EF_num['EXT7']], |
| 267 | 'SPDI': DF['GSM']+[EF_num['SPDI']], |
| 268 | 'MMSN': DF['GSM']+[EF_num['MMSN']], |
| 269 | 'EXT8': DF['GSM']+[EF_num['EXT8']], |
| 270 | 'MMSICP': DF['GSM']+[EF_num['MMSICP']], |
| 271 | 'MMSUP': DF['GSM']+[EF_num['MMSUP']], |
| 272 | 'MMSUCP': DF['GSM']+[EF_num['MMSUCP']], |
Alexander Chemeris | 067f69c | 2017-07-18 16:44:26 +0300 | [diff] [blame] | 273 | } |
Supreeth Herle | bf5d602 | 2020-03-20 15:18:27 +0100 | [diff] [blame] | 274 | |
| 275 | # Mapping between SIM Service Number and its description |
| 276 | EF_SST_map = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 277 | 1: 'CHV1 disable function', |
| 278 | 2: 'Abbreviated Dialling Numbers (ADN)', |
| 279 | 3: 'Fixed Dialling Numbers (FDN)', |
| 280 | 4: 'Short Message Storage (SMS)', |
| 281 | 5: 'Advice of Charge (AoC)', |
| 282 | 6: 'Capability Configuration Parameters (CCP)', |
| 283 | 7: 'PLMN selector', |
| 284 | 8: 'RFU', |
| 285 | 9: 'MSISDN', |
| 286 | 10: 'Extension1', |
| 287 | 11: 'Extension2', |
| 288 | 12: 'SMS Parameters', |
| 289 | 13: 'Last Number Dialled (LND)', |
| 290 | 14: 'Cell Broadcast Message Identifier', |
| 291 | 15: 'Group Identifier Level 1', |
| 292 | 16: 'Group Identifier Level 2', |
| 293 | 17: 'Service Provider Name', |
| 294 | 18: 'Service Dialling Numbers (SDN)', |
| 295 | 19: 'Extension3', |
| 296 | 20: 'RFU', |
| 297 | 21: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)', |
| 298 | 22: 'VBS Group Identifier List (EFVBS and EFVBSS)', |
| 299 | 23: 'enhanced Multi-Level Precedence and Pre-emption Service', |
| 300 | 24: 'Automatic Answer for eMLPP', |
| 301 | 25: 'Data download via SMS-CB', |
| 302 | 26: 'Data download via SMS-PP', |
| 303 | 27: 'Menu selection', |
| 304 | 28: 'Call control', |
| 305 | 29: 'Proactive SIM', |
| 306 | 30: 'Cell Broadcast Message Identifier Ranges', |
| 307 | 31: 'Barred Dialling Numbers (BDN)', |
| 308 | 32: 'Extension4', |
| 309 | 33: 'De-personalization Control Keys', |
| 310 | 34: 'Co-operative Network List', |
| 311 | 35: 'Short Message Status Reports', |
| 312 | 36: 'Network\'s indication of alerting in the MS', |
| 313 | 37: 'Mobile Originated Short Message control by SIM', |
| 314 | 38: 'GPRS', |
| 315 | 39: 'Image (IMG)', |
| 316 | 40: 'SoLSA (Support of Local Service Area)', |
| 317 | 41: 'USSD string data object supported in Call Control', |
| 318 | 42: 'RUN AT COMMAND command', |
| 319 | 43: 'User controlled PLMN Selector with Access Technology', |
| 320 | 44: 'Operator controlled PLMN Selector with Access Technology', |
| 321 | 45: 'HPLMN Selector with Access Technology', |
| 322 | 46: 'CPBCCH Information', |
| 323 | 47: 'Investigation Scan', |
| 324 | 48: 'Extended Capability Configuration Parameters', |
| 325 | 49: 'MExE', |
| 326 | 50: 'Reserved and shall be ignored', |
| 327 | 51: 'PLMN Network Name', |
| 328 | 52: 'Operator PLMN List', |
| 329 | 53: 'Mailbox Dialling Numbers', |
| 330 | 54: 'Message Waiting Indication Status', |
| 331 | 55: 'Call Forwarding Indication Status', |
| 332 | 56: 'Service Provider Display Information', |
| 333 | 57: 'Multimedia Messaging Service (MMS)', |
| 334 | 58: 'Extension 8', |
| 335 | 59: 'MMS User Connectivity Parameters', |
Vadim Yanitskiy | dfe3dbb | 2020-07-28 05:26:02 +0700 | [diff] [blame] | 336 | } |
| 337 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 338 | |
| 339 | ###################################################################### |
| 340 | # DF.TELECOM |
| 341 | ###################################################################### |
| 342 | |
Harald Welte | f11f130 | 2023-01-24 17:59:59 +0100 | [diff] [blame] | 343 | |
| 344 | # TS 51.011 Section 10.5.1 / Table 12 |
| 345 | class ExtendedBcdAdapter(Adapter): |
| 346 | """Replace some hex-characters with other ASCII characters""" |
| 347 | # we only translate a=* / b=# as they habe a clear representation |
| 348 | # in terms of USSD / SS service codes |
| 349 | def _decode(self, obj, context, path): |
| 350 | if not isinstance(obj, str): |
| 351 | return obj |
| 352 | return obj.lower().replace("a","*").replace("b","#") |
| 353 | |
| 354 | def _encode(self, obj, context, path): |
| 355 | if not isinstance(obj, str): |
| 356 | return obj |
| 357 | return obj.replace("*","a").replace("#","b") |
| 358 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 359 | # TS 51.011 Section 10.5.1 |
| 360 | class EF_ADN(LinFixedEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 361 | _test_decode = [ |
| 362 | ( '42204841203120536963ffffffff06810628560810ffffffffffffff', |
| 363 | { "alpha_id": "B HA 1 Sic", "len_of_bcd": 6, "ton_npi": { "ext": True, "type_of_number": |
| 364 | "unknown", "numbering_plan_id": |
| 365 | "isdn_e164" }, "dialing_nr": |
| 366 | "6082658001", "cap_conf_id": 255, "ext1_record_id": 255 }), |
| 367 | ] |
| 368 | |
Harald Welte | 0dc6c20 | 2023-01-24 18:10:13 +0100 | [diff] [blame] | 369 | def __init__(self, fid='6f3a', sfid=None, name='EF.ADN', desc='Abbreviated Dialing Numbers', ext=1, **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 370 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(14, 30), **kwargs) |
Harald Welte | 0dc6c20 | 2023-01-24 18:10:13 +0100 | [diff] [blame] | 371 | ext_name = 'ext%u_record_id' % ext |
Harald Welte | 1e73d22 | 2022-02-13 11:32:50 +0100 | [diff] [blame] | 372 | self._construct = Struct('alpha_id'/COptional(GsmStringAdapter(Rpad(Bytes(this._.total_len-14)), codec='ascii')), |
| 373 | 'len_of_bcd'/Int8ub, |
| 374 | 'ton_npi'/TonNpi, |
Harald Welte | f11f130 | 2023-01-24 17:59:59 +0100 | [diff] [blame] | 375 | 'dialing_nr'/ExtendedBcdAdapter(BcdAdapter(Rpad(Bytes(10)))), |
Harald Welte | 1e73d22 | 2022-02-13 11:32:50 +0100 | [diff] [blame] | 376 | 'cap_conf_id'/Int8ub, |
Harald Welte | 0dc6c20 | 2023-01-24 18:10:13 +0100 | [diff] [blame] | 377 | ext_name/Int8ub) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 378 | |
| 379 | # TS 51.011 Section 10.5.5 |
Harald Welte | ec7d0da | 2021-04-02 22:01:19 +0200 | [diff] [blame] | 380 | class EF_SMS(LinFixedEF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 381 | def __init__(self, fid='6f3c', sfid=None, name='EF.SMS', desc='Short messages', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 382 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(176, 176), **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 383 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 384 | def _decode_record_bin(self, raw_bin_data, **kwargs): |
Harald Welte | ec7d0da | 2021-04-02 22:01:19 +0200 | [diff] [blame] | 385 | def decode_status(status): |
| 386 | if status & 0x01 == 0x00: |
| 387 | return (None, 'free_space') |
| 388 | elif status & 0x07 == 0x01: |
| 389 | return ('mt', 'message_read') |
| 390 | elif status & 0x07 == 0x03: |
| 391 | return ('mt', 'message_to_be_read') |
| 392 | elif status & 0x07 == 0x07: |
| 393 | return ('mo', 'message_to_be_sent') |
| 394 | elif status & 0x1f == 0x05: |
| 395 | return ('mo', 'sent_status_not_requested') |
| 396 | elif status & 0x1f == 0x0d: |
| 397 | return ('mo', 'sent_status_req_but_not_received') |
| 398 | elif status & 0x1f == 0x15: |
| 399 | return ('mo', 'sent_status_req_rx_not_stored_smsr') |
| 400 | elif status & 0x1f == 0x1d: |
| 401 | return ('mo', 'sent_status_req_rx_stored_smsr') |
| 402 | else: |
| 403 | return (None, 'rfu') |
| 404 | |
| 405 | status = decode_status(raw_bin_data[0]) |
| 406 | remainder = raw_bin_data[1:] |
| 407 | return {'direction': status[0], 'status': status[1], 'remainder': b2h(remainder)} |
| 408 | |
| 409 | |
| 410 | # TS 51.011 Section 10.5.5 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 411 | class EF_MSISDN(LinFixedEF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 412 | def __init__(self, fid='6f40', sfid=None, name='EF.MSISDN', desc='MSISDN', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 413 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(15, 34), **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 414 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 415 | def _decode_record_hex(self, raw_hex_data, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 416 | return {'msisdn': dec_msisdn(raw_hex_data)} |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 417 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 418 | def _encode_record_hex(self, abstract, **kwargs): |
Philipp Maier | f9cbe09 | 2021-04-23 19:37:36 +0200 | [diff] [blame] | 419 | msisdn = abstract['msisdn'] |
| 420 | if type(msisdn) == str: |
| 421 | encoded_msisdn = enc_msisdn(msisdn) |
| 422 | else: |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 423 | encoded_msisdn = enc_msisdn(msisdn[2], msisdn[0], msisdn[1]) |
| 424 | alpha_identifier = (list(self.rec_len)[ |
| 425 | 0] - len(encoded_msisdn) // 2) * "ff" |
Philipp Maier | b46cb3f | 2021-04-20 22:38:21 +0200 | [diff] [blame] | 426 | return alpha_identifier + encoded_msisdn |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 427 | |
| 428 | # TS 51.011 Section 10.5.6 |
| 429 | class EF_SMSP(LinFixedEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 430 | # FIXME: re-encode fails / missing alpha_id at start of output |
| 431 | _test_decode = [ |
| 432 | ( '454e6574776f726b73fffffffffffffff1ffffffffffffffffffffffffffffffffffffffffffffffff0000a7', |
| 433 | { "alpha_id": "ENetworks", "parameter_indicators": { "tp_dest_addr": False, "tp_sc_addr": True, |
| 434 | "tp_pid": True, "tp_dcs": True, "tp_vp": True }, |
| 435 | "tp_dest_addr": { "length": 255, "ton_npi": { "ext": True, "type_of_number": "reserved_for_extension", |
| 436 | "numbering_plan_id": "reserved_for_extension" }, |
| 437 | "call_number": "" }, |
| 438 | "tp_sc_addr": { "length": 255, "ton_npi": { "ext": True, "type_of_number": "reserved_for_extension", |
| 439 | "numbering_plan_id": "reserved_for_extension" }, |
| 440 | "call_number": "" }, |
| 441 | "tp_pid": "00", "tp_dcs": "00", "tp_vp_minutes": 1440 } ), |
| 442 | ] |
Harald Welte | bc0e209 | 2022-02-13 10:54:58 +0100 | [diff] [blame] | 443 | class ValidityPeriodAdapter(Adapter): |
| 444 | def _decode(self, obj, context, path): |
| 445 | if obj <= 143: |
| 446 | return obj + 1 * 5 |
| 447 | elif obj <= 167: |
| 448 | return 12 * 60 + ((obj - 143) * 30) |
| 449 | elif obj <= 196: |
| 450 | return (obj - 166) * (24 * 60) |
| 451 | elif obj <= 255: |
| 452 | return (obj - 192) * (7 * 24 * 60) |
| 453 | else: |
| 454 | raise ValueError |
| 455 | def _encode(self, obj, context, path): |
| 456 | if obj <= 12*60: |
| 457 | return obj/5 - 1 |
| 458 | elif obj <= 24*60: |
Harald Welte | 136bdb0 | 2023-01-31 16:23:32 +0100 | [diff] [blame] | 459 | return 143 + ((obj - (12 * 60)) // 30) |
Harald Welte | bc0e209 | 2022-02-13 10:54:58 +0100 | [diff] [blame] | 460 | elif obj <= 30 * 24 * 60: |
| 461 | return 166 + (obj / (24 * 60)) |
| 462 | elif obj <= 63 * 7 * 24 * 60: |
Harald Welte | 136bdb0 | 2023-01-31 16:23:32 +0100 | [diff] [blame] | 463 | return 192 + (obj // (7 * 24 * 60)) |
Harald Welte | bc0e209 | 2022-02-13 10:54:58 +0100 | [diff] [blame] | 464 | else: |
| 465 | raise ValueError |
| 466 | |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 467 | def __init__(self, fid='6f42', sfid=None, name='EF.SMSP', desc='Short message service parameters', **kwargs): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 468 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=(28, None), **kwargs) |
Harald Welte | bc0e209 | 2022-02-13 10:54:58 +0100 | [diff] [blame] | 469 | ScAddr = Struct('length'/Int8ub, 'ton_npi'/TonNpi, 'call_number'/BcdAdapter(Rpad(Bytes(10)))) |
| 470 | self._construct = Struct('alpha_id'/COptional(GsmStringAdapter(Rpad(Bytes(this._.total_len-28)))), |
| 471 | 'parameter_indicators'/InvertAdapter(FlagsEnum(Byte, tp_dest_addr=1, tp_sc_addr=2, |
| 472 | tp_pid=3, tp_dcs=4, tp_vp=5)), |
| 473 | 'tp_dest_addr'/ScAddr, |
| 474 | 'tp_sc_addr'/ScAddr, |
| 475 | |
| 476 | 'tp_pid'/HexAdapter(Bytes(1)), |
| 477 | 'tp_dcs'/HexAdapter(Bytes(1)), |
| 478 | 'tp_vp_minutes'/EF_SMSP.ValidityPeriodAdapter(Byte)) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 479 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 480 | # TS 51.011 Section 10.5.7 |
| 481 | class EF_SMSS(TransparentEF): |
| 482 | class MemCapAdapter(Adapter): |
| 483 | def _decode(self, obj, context, path): |
| 484 | return False if obj & 1 else True |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 485 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 486 | def _encode(self, obj, context, path): |
| 487 | return 0 if obj else 1 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 488 | |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 489 | def __init__(self, fid='6f43', sfid=None, name='EF.SMSS', desc='SMS status', size=(2, 8), **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 490 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 491 | self._construct = Struct( |
| 492 | 'last_used_tpmr'/Int8ub, 'memory_capacity_exceeded'/self.MemCapAdapter(Int8ub)) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 493 | |
| 494 | # TS 51.011 Section 10.5.8 |
| 495 | class EF_SMSR(LinFixedEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 496 | def __init__(self, fid='6f47', sfid=None, name='EF.SMSR', desc='SMS status reports', rec_len=(30, 30), **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 497 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 498 | self._construct = Struct( |
| 499 | 'sms_record_id'/Int8ub, 'sms_status_report'/HexAdapter(Bytes(29))) |
| 500 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 501 | |
| 502 | class EF_EXT(LinFixedEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 503 | def __init__(self, fid, sfid=None, name='EF.EXT', desc='Extension', rec_len=(13, 13), **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 504 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 505 | self._construct = Struct( |
| 506 | 'record_type'/Int8ub, 'extension_data'/HexAdapter(Bytes(11)), 'identifier'/Int8ub) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 507 | |
| 508 | # TS 51.011 Section 10.5.16 |
| 509 | class EF_CMI(LinFixedEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 510 | def __init__(self, fid='6f58', sfid=None, name='EF.CMI', rec_len=(2, 21), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 511 | desc='Comparison Method Information', **kwargs): |
| 512 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 513 | self._construct = Struct( |
Harald Welte | 540adb0 | 2022-02-13 11:33:21 +0100 | [diff] [blame] | 514 | 'alpha_id'/GsmStringAdapter(Rpad(Bytes(this._.total_len-1))), 'comparison_method_id'/Int8ub) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 515 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 516 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 517 | class DF_TELECOM(CardDF): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 518 | def __init__(self, fid='7f10', name='DF.TELECOM', desc=None, **kwargs): |
| 519 | super().__init__(fid=fid, name=name, desc=desc, **kwargs) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 520 | files = [ |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 521 | EF_ADN(), |
Harald Welte | 0dc6c20 | 2023-01-24 18:10:13 +0100 | [diff] [blame] | 522 | EF_ADN(fid='6f3b', name='EF.FDN', desc='Fixed dialling numbers', ext=2), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 523 | EF_SMS(), |
| 524 | LinFixedEF(fid='6f3d', name='EF.CCP', |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 525 | desc='Capability Configuration Parameters', rec_len=(14, 14)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 526 | LinFixedEF(fid='6f4f', name='EF.ECCP', |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 527 | desc='Extended Capability Configuration Parameters', rec_len=(15, 32)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 528 | EF_MSISDN(), |
| 529 | EF_SMSP(), |
| 530 | EF_SMSS(), |
Harald Welte | a1bb3f7 | 2023-01-24 18:15:56 +0100 | [diff] [blame] | 531 | EF_ADN('6f44', None, 'EF.LND', 'Last Number Dialled', ext=1), |
Harald Welte | 0dc6c20 | 2023-01-24 18:10:13 +0100 | [diff] [blame] | 532 | EF_ADN('6f49', None, 'EF.SDN', 'Service Dialling Numbers', ext=3), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 533 | EF_EXT('6f4a', None, 'EF.EXT1', 'Extension1 (ADN/SSC)'), |
| 534 | EF_EXT('6f4b', None, 'EF.EXT2', 'Extension2 (FDN/SSC)'), |
| 535 | EF_EXT('6f4c', None, 'EF.EXT3', 'Extension3 (SDN)'), |
| 536 | EF_ADN(fid='6f4d', name='EF.BDN', desc='Barred Dialling Numbers'), |
| 537 | EF_EXT('6f4e', None, 'EF.EXT4', 'Extension4 (BDN/SSC)'), |
| 538 | EF_SMSR(), |
| 539 | EF_CMI(), |
Harald Welte | de4c14c | 2022-07-16 11:53:59 +0200 | [diff] [blame] | 540 | # not really part of 51.011 but something that TS 31.102 specifies may exist here. |
| 541 | DF_PHONEBOOK(), |
Harald Welte | a045221 | 2022-07-17 21:23:21 +0200 | [diff] [blame] | 542 | DF_MULTIMEDIA(), |
Harald Welte | 650f612 | 2022-07-17 21:42:50 +0200 | [diff] [blame] | 543 | DF_MCS(), |
Harald Welte | 228ae8e | 2022-07-17 22:01:04 +0200 | [diff] [blame] | 544 | DF_V2X(), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 545 | ] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 546 | self.add_files(files) |
| 547 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 548 | ###################################################################### |
| 549 | # DF.GSM |
| 550 | ###################################################################### |
| 551 | |
| 552 | # TS 51.011 Section 10.3.1 |
| 553 | class EF_LP(TransRecEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 554 | _test_de_encode = [ |
| 555 | ( "24", "24"), |
| 556 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 557 | def __init__(self, fid='6f05', sfid=None, name='EF.LP', size=(1, None), rec_len=1, |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 558 | desc='Language Preference'): |
| 559 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 560 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 561 | def _decode_record_bin(self, in_bin, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 562 | return b2h(in_bin) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 563 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 564 | def _encode_record_bin(self, in_json, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 565 | return h2b(in_json) |
| 566 | |
| 567 | # TS 51.011 Section 10.3.2 |
| 568 | class EF_IMSI(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 569 | _test_de_encode = [ |
| 570 | ( "082982608200002080", { "imsi": "228062800000208" } ), |
| 571 | ( "082926101160845740", { "imsi": "262011106487504" } ), |
| 572 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 573 | def __init__(self, fid='6f07', sfid=None, name='EF.IMSI', desc='IMSI', size=(9, 9)): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 574 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 575 | # add those commands to the general commands of a TransparentEF |
| 576 | self.shell_commands += [self.AddlShellCommands(self)] |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 577 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 578 | def _decode_hex(self, raw_hex): |
| 579 | return {'imsi': dec_imsi(raw_hex)} |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 580 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 581 | def _encode_hex(self, abstract): |
| 582 | return enc_imsi(abstract['imsi']) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 583 | |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 584 | @with_default_category('File-Specific Commands') |
| 585 | class AddlShellCommands(CommandSet): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 586 | def __init__(self, ef: TransparentEF): |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 587 | super().__init__() |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 588 | self._ef = ef |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 589 | |
| 590 | def do_update_imsi_plmn(self, arg: str): |
| 591 | """Change the plmn part of the IMSI""" |
| 592 | plmn = arg.strip() |
| 593 | if len(plmn) == 5 or len(plmn) == 6: |
Harald Welte | a6c0f88 | 2022-07-17 14:23:17 +0200 | [diff] [blame] | 594 | (data, sw) = self._cmd.lchan.read_binary_dec() |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 595 | if sw == '9000' and len(data['imsi'])-len(plmn) == 10: |
| 596 | imsi = data['imsi'] |
| 597 | msin = imsi[len(plmn):] |
Harald Welte | a6c0f88 | 2022-07-17 14:23:17 +0200 | [diff] [blame] | 598 | (data, sw) = self._cmd.lchan.update_binary_dec( |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 599 | {'imsi': plmn+msin}) |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 600 | if sw == '9000' and data: |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 601 | self._cmd.poutput_json( |
Harald Welte | a6c0f88 | 2022-07-17 14:23:17 +0200 | [diff] [blame] | 602 | self._cmd.lchan.selected_file.decode_hex(data)) |
Bjoern Riemer | e91405e | 2021-12-17 15:16:35 +0100 | [diff] [blame] | 603 | else: |
| 604 | raise ValueError("PLMN length does not match IMSI length") |
| 605 | else: |
| 606 | raise ValueError("PLMN has wrong length!") |
| 607 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 608 | |
| 609 | # TS 51.011 Section 10.3.4 |
| 610 | class EF_PLMNsel(TransRecEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 611 | _test_de_encode = [ |
| 612 | ( "22F860", { "mcc": "228", "mnc": "06" } ), |
| 613 | ( "330420", { "mcc": "334", "mnc": "020" } ), |
| 614 | ] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 615 | def __init__(self, fid='6f30', sfid=None, name='EF.PLMNsel', desc='PLMN selector', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 616 | size=(24, None), rec_len=3, **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 617 | super().__init__(fid, name=name, sfid=sfid, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 618 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 619 | def _decode_record_hex(self, in_hex, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 620 | if in_hex[:6] == "ffffff": |
| 621 | return None |
| 622 | else: |
| 623 | return dec_plmn(in_hex) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 624 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 625 | def _encode_record_hex(self, in_json, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 626 | if in_json == None: |
| 627 | return "ffffff" |
| 628 | else: |
| 629 | return enc_plmn(in_json['mcc'], in_json['mnc']) |
| 630 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 631 | # TS 51.011 Section 10.3.6 |
| 632 | class EF_ACMmax(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 633 | _test_de_encode = [ |
| 634 | ( "000000", { "acm_max": 0 } ), |
| 635 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 636 | def __init__(self, fid='6f37', sfid=None, name='EF.ACMmax', size=(3, 3), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 637 | desc='ACM maximum value', **kwargs): |
| 638 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 639 | self._construct = Struct('acm_max'/Int24ub) |
| 640 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 641 | # TS 51.011 Section 10.3.7 |
| 642 | class EF_ServiceTable(TransparentEF): |
| 643 | def __init__(self, fid, sfid, name, desc, size, table): |
| 644 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
| 645 | self.table = table |
Harald Welte | c224b3b | 2023-05-23 18:44:44 +0200 | [diff] [blame] | 646 | self.shell_commands += [self.AddlShellCommands()] |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 647 | |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 648 | @staticmethod |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 649 | def _bit_byte_offset_for_service(service: int) -> Tuple[int, int]: |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 650 | i = service - 1 |
| 651 | byte_offset = i//4 |
| 652 | bit_offset = (i % 4) * 2 |
| 653 | return (byte_offset, bit_offset) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 654 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 655 | def _decode_bin(self, raw_bin): |
| 656 | ret = {} |
| 657 | for i in range(0, len(raw_bin)*4): |
| 658 | service_nr = i+1 |
| 659 | byte = int(raw_bin[i//4]) |
| 660 | bit_offset = (i % 4) * 2 |
| 661 | bits = (byte >> bit_offset) & 3 |
| 662 | ret[service_nr] = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 663 | 'description': self.table[service_nr] if service_nr in self.table else None, |
| 664 | 'allocated': True if bits & 1 else False, |
| 665 | 'activated': True if bits & 2 else False, |
| 666 | } |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 667 | return ret |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 668 | |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 669 | def _encode_bin(self, in_json): |
| 670 | # compute the required binary size |
| 671 | bin_len = 0 |
| 672 | for srv in in_json.keys(): |
| 673 | service_nr = int(srv) |
Vadim Yanitskiy | 6b19d80 | 2023-04-22 19:55:00 +0700 | [diff] [blame] | 674 | (byte_offset, bit_offset) = self._bit_byte_offset_for_service(service_nr) |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 675 | if byte_offset >= bin_len: |
| 676 | bin_len = byte_offset+1 |
| 677 | # encode the actual data |
| 678 | out = bytearray(b'\x00' * bin_len) |
| 679 | for srv in in_json.keys(): |
| 680 | service_nr = int(srv) |
Vadim Yanitskiy | 6b19d80 | 2023-04-22 19:55:00 +0700 | [diff] [blame] | 681 | (byte_offset, bit_offset) = self._bit_byte_offset_for_service(service_nr) |
Harald Welte | 7a8aa86 | 2021-10-14 20:46:19 +0200 | [diff] [blame] | 682 | bits = 0 |
| 683 | if in_json[srv]['allocated'] == True: |
| 684 | bits |= 1 |
| 685 | if in_json[srv]['activated'] == True: |
| 686 | bits |= 2 |
| 687 | out[byte_offset] |= ((bits & 3) << bit_offset) |
| 688 | return out |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 689 | |
Harald Welte | c224b3b | 2023-05-23 18:44:44 +0200 | [diff] [blame] | 690 | @with_default_category('File-Specific Commands') |
| 691 | class AddlShellCommands(CommandSet): |
| 692 | def _adjust_service(self, service_nr: int, allocate: Optional[bool] = None, activate : Optional[bool] = None): |
| 693 | (byte_offset, bit_offset) = EF_ServiceTable._bit_byte_offset_for_service(service_nr) |
| 694 | hex_data, sw = self._cmd.lchan.read_binary(length=1, offset=byte_offset) |
| 695 | data = h2b(hex_data) |
| 696 | if allocate is not None: |
| 697 | if allocate: |
| 698 | data[0] |= (1 << bit_offset) |
| 699 | else: |
| 700 | data[0] &= ~(1 << bit_offset) |
| 701 | if activate is not None: |
| 702 | if activate: |
| 703 | data[0] |= (2 << bit_offset) |
| 704 | else: |
| 705 | data[0] &= ~(2 << bit_offset) |
| 706 | total_data, sw = self._cmd.lchan.update_binary(b2h(data), offset=byte_offset) |
| 707 | return sw |
| 708 | |
| 709 | def do_sst_service_allocate(self, arg): |
| 710 | """Allocate a service within EF.SST""" |
| 711 | self._adjust_service(int(arg), allocate = True) |
| 712 | |
| 713 | def do_sst_service_deallocate(self, arg): |
| 714 | """Deallocate a service within EF.SST""" |
| 715 | self._adjust_service(int(arg), allocate = False) |
| 716 | |
| 717 | def do_sst_service_activate(self, arg): |
| 718 | """Activate a service within EF.SST""" |
| 719 | self._adjust_service(int(arg), activate = True) |
| 720 | |
| 721 | def do_sst_service_deactivate(self, arg): |
| 722 | """Deactivate a service within EF.SST""" |
| 723 | self._adjust_service(int(arg), activate = False) |
| 724 | |
| 725 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 726 | # TS 51.011 Section 10.3.11 |
| 727 | class EF_SPN(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 728 | _test_de_encode = [ |
| 729 | ( "0147534d2d52204348ffffffffffffffff", |
| 730 | { "rfu": 0, "hide_in_oplmn": False, "show_in_hplmn": True, "spn": "GSM-R CH" } ), |
| 731 | ] |
| 732 | |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 733 | def __init__(self, fid='6f46', sfid=None, name='EF.SPN', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 734 | desc='Service Provider Name', size=(17, 17), **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 735 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Robert Falkenberg | b07a3e9 | 2021-05-07 15:23:20 +0200 | [diff] [blame] | 736 | self._construct = BitStruct( |
| 737 | # Byte 1 |
| 738 | 'rfu'/BitsRFU(6), |
| 739 | 'hide_in_oplmn'/Flag, |
| 740 | 'show_in_hplmn'/Flag, |
| 741 | # Bytes 2..17 |
| 742 | 'spn'/Bytewise(GsmString(16)) |
| 743 | ) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 744 | |
| 745 | # TS 51.011 Section 10.3.13 |
| 746 | class EF_CBMI(TransRecEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 747 | # TODO: Test vectors |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 748 | def __init__(self, fid='6f45', sfid=None, name='EF.CBMI', size=(2, None), rec_len=2, |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 749 | desc='Cell Broadcast message identifier selection', **kwargs): |
| 750 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 751 | self._construct = GreedyRange(Int16ub) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 752 | |
| 753 | # TS 51.011 Section 10.3.15 |
| 754 | class EF_ACC(TransparentEF): |
Vadim Yanitskiy | b34f234 | 2023-04-18 04:25:27 +0700 | [diff] [blame] | 755 | # example: acc_list(15) will produce a dict with only ACC15 being True |
| 756 | # example: acc_list(2, 4) will produce a dict with ACC2 and ACC4 being True |
| 757 | # example: acc_list() will produce a dict with all ACCs being False |
| 758 | acc_list = lambda *active: {'ACC{}'.format(c) : c in active for c in range(16)} |
| 759 | |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 760 | _test_de_encode = [ |
Vadim Yanitskiy | b34f234 | 2023-04-18 04:25:27 +0700 | [diff] [blame] | 761 | ( "0000", acc_list() ), |
| 762 | ( "0001", acc_list(0) ), |
| 763 | ( "0002", acc_list(1) ), |
| 764 | ( "0100", acc_list(8) ), |
| 765 | ( "8000", acc_list(15) ), |
| 766 | ( "802b", acc_list(0,1,3,5,15) ), |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 767 | ] |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 768 | def __init__(self, fid='6f78', sfid=None, name='EF.ACC', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 769 | desc='Access Control Class', size=(2, 2), **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 770 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Vadim Yanitskiy | b34f234 | 2023-04-18 04:25:27 +0700 | [diff] [blame] | 771 | # LSB of octet 2 is ACC=0 ... MSB of octet 1 is ACC=15 |
| 772 | flags = ['ACC{}'.format(c) / Flag for c in range(16)] |
| 773 | self._construct = ByteSwapped(BitsSwapped(BitStruct(*flags))) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 774 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 775 | # TS 51.011 Section 10.3.16 |
| 776 | class EF_LOCI(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 777 | _test_de_encode = [ |
| 778 | ( "7802570222f81009780000", |
| 779 | { "tmsi": "78025702", "lai": "22f8100978", "tmsi_time": 0, "lu_status": "updated" } ), |
| 780 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 781 | def __init__(self, fid='6f7e', sfid=None, name='EF.LOCI', desc='Location Information', size=(11, 11)): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 782 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 783 | self._construct = Struct('tmsi'/HexAdapter(Bytes(4)), 'lai'/HexAdapter(Bytes(5)), 'tmsi_time'/Int8ub, |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 784 | 'lu_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, |
| 785 | location_area_not_allowed=3)) |
| 786 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 787 | # TS 51.011 Section 10.3.18 |
| 788 | class EF_AD(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 789 | _test_de_encode = [ |
| 790 | ( "00ffff", |
| 791 | { "ms_operation_mode": "normal", "rfu1": 255, "rfu2": 127, "ofm": True, "extensions": None } ), |
| 792 | ] |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 793 | class OP_MODE(enum.IntEnum): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 794 | normal = 0x00 |
| 795 | type_approval = 0x80 |
| 796 | normal_and_specific_facilities = 0x01 |
| 797 | type_approval_and_specific_facilities = 0x81 |
| 798 | maintenance_off_line = 0x02 |
| 799 | cell_test = 0x04 |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 800 | #OP_MODE_DICT = {int(v) : str(v) for v in EF_AD.OP_MODE} |
| 801 | #OP_MODE_DICT_REVERSED = {str(v) : int(v) for v in EF_AD.OP_MODE} |
| 802 | |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 803 | def __init__(self, fid='6fad', sfid=None, name='EF.AD', desc='Administrative Data', size=(3, 4)): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 804 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 805 | self._construct = BitStruct( |
| 806 | # Byte 1 |
| 807 | 'ms_operation_mode'/Bytewise(Enum(Byte, EF_AD.OP_MODE)), |
| 808 | # Byte 2 |
| 809 | 'rfu1'/Bytewise(ByteRFU), |
| 810 | # Byte 3 |
| 811 | 'rfu2'/BitsRFU(7), |
| 812 | 'ofm'/Flag, |
| 813 | # Byte 4 (optional), |
| 814 | 'extensions'/COptional(Struct( |
| 815 | 'rfu3'/BitsRFU(4), |
| 816 | 'mnc_len'/BitsInteger(4), |
| 817 | # Byte 5..N-4 (optional, RFU) |
| 818 | 'extensions'/Bytewise(GreedyBytesRFU) |
| 819 | )) |
| 820 | ) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 821 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 822 | # TS 51.011 Section 10.3.20 / 10.3.22 |
| 823 | class EF_VGCS(TransRecEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 824 | _test_de_encode = [ |
| 825 | ( "92f9ffff", "299fffff" ), |
| 826 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 827 | def __init__(self, fid='6fb1', sfid=None, name='EF.VGCS', size=(4, 200), rec_len=4, |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 828 | desc='Voice Group Call Service', **kwargs): |
| 829 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 830 | self._construct = BcdAdapter(Bytes(4)) |
| 831 | |
| 832 | # TS 51.011 Section 10.3.21 / 10.3.23 |
| 833 | class EF_VGCSS(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 834 | _test_decode = [ |
| 835 | ( "010000004540fc", |
| 836 | { "flags": [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 837 | 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ] } |
| 838 | ), |
| 839 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 840 | def __init__(self, fid='6fb2', sfid=None, name='EF.VGCSS', size=(7, 7), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 841 | desc='Voice Group Call Service Status', **kwargs): |
| 842 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 5b9472d | 2023-01-24 17:26:59 +0100 | [diff] [blame] | 843 | self._construct = BitsSwapped(BitStruct( |
| 844 | 'flags'/Bit[50], Padding(6, pattern=b'\xff'))) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 845 | |
| 846 | # TS 51.011 Section 10.3.24 |
| 847 | class EF_eMLPP(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 848 | _test_de_encode = [ |
| 849 | ( "7c04", { "levels": { "A": False, "B": False, "zero": True, "one": True, |
| 850 | "two": True, "three": True, "four": True }, |
| 851 | "fast_call_setup_cond": { "A": False, "B": False, "zero": True, "one": False, |
| 852 | "two": False, "three": False, "four": False } |
| 853 | }), |
| 854 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 855 | def __init__(self, fid='6fb5', sfid=None, name='EF.eMLPP', size=(2, 2), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 856 | desc='enhanced Multi Level Pre-emption and Priority', **kwargs): |
| 857 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 858 | FlagsConstruct = FlagsEnum( |
| 859 | Byte, A=1, B=2, zero=4, one=8, two=16, three=32, four=64) |
| 860 | self._construct = Struct( |
| 861 | 'levels'/FlagsConstruct, 'fast_call_setup_cond'/FlagsConstruct) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 862 | |
| 863 | # TS 51.011 Section 10.3.25 |
| 864 | class EF_AAeM(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 865 | _test_de_encode = [ |
| 866 | ( "3c", { "auto_answer_prio_levels": { "A": False, "B": False, "zero": True, "one": True, |
| 867 | "two": True, "three": True, "four": False } } ), |
| 868 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 869 | def __init__(self, fid='6fb6', sfid=None, name='EF.AAeM', size=(1, 1), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 870 | desc='Automatic Answer for eMLPP Service', **kwargs): |
| 871 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 872 | FlagsConstruct = FlagsEnum( |
| 873 | Byte, A=1, B=2, zero=4, one=8, two=16, three=32, four=64) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 874 | self._construct = Struct('auto_answer_prio_levels'/FlagsConstruct) |
| 875 | |
| 876 | # TS 51.011 Section 10.3.26 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 877 | class EF_CBMID(EF_CBMI): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 878 | def __init__(self, fid='6f48', sfid=None, name='EF.CBMID', size=(2, None), rec_len=2, |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 879 | desc='Cell Broadcast Message Identifier for Data Download', **kwargs): |
| 880 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 881 | self._construct = GreedyRange(Int16ub) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 882 | |
Harald Welte | 89e5954 | 2021-04-02 21:33:13 +0200 | [diff] [blame] | 883 | # TS 51.011 Section 10.3.27 |
| 884 | class EF_ECC(TransRecEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 885 | def __init__(self, fid='6fb7', sfid=None, name='EF.ECC', size=(3, 15), rec_len=3, |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 886 | desc='Emergency Call Codes', **kwargs): |
| 887 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 888 | self._construct = GreedyRange(BcdAdapter(Bytes(3))) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 889 | |
| 890 | # TS 51.011 Section 10.3.28 |
| 891 | class EF_CBMIR(TransRecEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 892 | def __init__(self, fid='6f50', sfid=None, name='EF.CBMIR', size=(4, None), rec_len=4, |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 893 | desc='Cell Broadcast message identifier range selection', **kwargs): |
| 894 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 895 | self._construct = GreedyRange(Struct('lower'/Int16ub, 'upper'/Int16ub)) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 896 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 897 | # TS 51.011 Section 10.3.29 |
| 898 | class EF_DCK(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 899 | def __init__(self, fid='6f2c', sfid=None, name='EF.DCK', size=(16, 16), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 900 | desc='Depersonalisation Control Keys', **kwargs): |
| 901 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 902 | self._construct = Struct('network'/BcdAdapter(Bytes(4)), |
| 903 | 'network_subset'/BcdAdapter(Bytes(4)), |
| 904 | 'service_provider'/BcdAdapter(Bytes(4)), |
| 905 | 'corporate'/BcdAdapter(Bytes(4))) |
| 906 | # TS 51.011 Section 10.3.30 |
| 907 | class EF_CNL(TransRecEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 908 | def __init__(self, fid='6f32', sfid=None, name='EF.CNL', size=(6, None), rec_len=6, |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 909 | desc='Co-operative Network List', **kwargs): |
| 910 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 911 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 912 | def _decode_record_hex(self, in_hex, **kwargs): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 913 | (in_plmn, sub, svp, corp) = unpack('!3sBBB', h2b(in_hex)) |
| 914 | res = dec_plmn(b2h(in_plmn)) |
| 915 | res['network_subset'] = sub |
| 916 | res['service_provider_id'] = svp |
| 917 | res['corporate_id'] = corp |
| 918 | return res |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 919 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 920 | def _encode_record_hex(self, in_json, **kwargs): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 921 | plmn = enc_plmn(in_json['mcc'], in_json['mnc']) |
Vadim Yanitskiy | 1a95d2b | 2021-05-02 01:42:09 +0200 | [diff] [blame] | 922 | return b2h(pack('!3sBBB', |
| 923 | h2b(plmn), |
| 924 | in_json['network_subset'], |
| 925 | in_json['service_provider_id'], |
| 926 | in_json['corporate_id'])) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 927 | |
| 928 | # TS 51.011 Section 10.3.31 |
| 929 | class EF_NIA(LinFixedEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 930 | def __init__(self, fid='6f51', sfid=None, name='EF.NIA', rec_len=(1, 32), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 931 | desc='Network\'s Indication of Alerting', **kwargs): |
| 932 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 933 | self._construct = Struct( |
| 934 | 'alerting_category'/Int8ub, 'category'/GreedyBytes) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 935 | |
| 936 | # TS 51.011 Section 10.3.32 |
| 937 | class EF_Kc(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 938 | _test_de_encode = [ |
| 939 | ( "837d783609a3858f05", { "kc": "837d783609a3858f", "cksn": 5 } ), |
| 940 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 941 | def __init__(self, fid='6f20', sfid=None, name='EF.Kc', desc='Ciphering key Kc', size=(9, 9), **kwargs): |
Harald Welte | d90ceb8 | 2022-07-17 22:10:58 +0200 | [diff] [blame] | 942 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 943 | self._construct = Struct('kc'/HexAdapter(Bytes(8)), 'cksn'/Int8ub) |
| 944 | |
| 945 | # TS 51.011 Section 10.3.33 |
| 946 | class EF_LOCIGPRS(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 947 | _test_de_encode = [ |
| 948 | ( "ffffffffffffff22f8990000ff01", |
| 949 | { "ptmsi": "ffffffff", "ptmsi_sig": "ffffff", "rai": "22f8990000ff", "rau_status": "not_updated" } ), |
| 950 | ] |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 951 | def __init__(self, fid='6f53', sfid=None, name='EF.LOCIGPRS', desc='GPRS Location Information', size=(14, 14)): |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 952 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size) |
Harald Welte | d2edd41 | 2023-01-31 16:49:03 +0100 | [diff] [blame] | 953 | self._construct = Struct('ptmsi'/HexAdapter(Bytes(4)), 'ptmsi_sig'/HexAdapter(Bytes(3)), |
| 954 | 'rai'/HexAdapter(Bytes(6)), |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 955 | 'rau_status'/Enum(Byte, updated=0, not_updated=1, plmn_not_allowed=2, |
| 956 | routing_area_not_allowed=3)) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 957 | |
| 958 | # TS 51.011 Section 10.3.35..37 |
| 959 | class EF_xPLMNwAcT(TransRecEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 960 | _test_de_encode = [ |
| 961 | ( '62F2104000', { "mcc": "262", "mnc": "01", "act": [ "E-UTRAN" ] } ), |
| 962 | ( '62F2108000', { "mcc": "262", "mnc": "01", "act": [ "UTRAN" ] } ), |
| 963 | ] |
| 964 | def __init__(self, fid='1234', sfid=None, name=None, desc=None, size=(40, None), rec_len=5, **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 965 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 966 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 967 | def _decode_record_hex(self, in_hex, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 968 | if in_hex[:6] == "ffffff": |
| 969 | return None |
| 970 | else: |
| 971 | return dec_xplmn_w_act(in_hex) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 972 | |
Harald Welte | f6b37af | 2023-01-24 15:42:26 +0100 | [diff] [blame] | 973 | def _encode_record_hex(self, in_json, **kwargs): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 974 | if in_json == None: |
| 975 | return "ffffff0000" |
| 976 | else: |
| 977 | hplmn = enc_plmn(in_json['mcc'], in_json['mnc']) |
| 978 | act = self.enc_act(in_json['act']) |
| 979 | return hplmn + act |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 980 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 981 | @staticmethod |
| 982 | def enc_act(in_list): |
| 983 | u16 = 0 |
| 984 | # first the simple ones |
| 985 | if 'UTRAN' in in_list: |
| 986 | u16 |= 0x8000 |
| 987 | if 'NG-RAN' in in_list: |
| 988 | u16 |= 0x0800 |
| 989 | if 'GSM COMPACT' in in_list: |
| 990 | u16 |= 0x0040 |
| 991 | if 'cdma2000 HRPD' in in_list: |
| 992 | u16 |= 0x0020 |
| 993 | if 'cdma2000 1xRTT' in in_list: |
| 994 | u16 |= 0x0010 |
| 995 | # E-UTRAN |
Philipp Maier | e7d4179 | 2021-04-29 16:20:07 +0200 | [diff] [blame] | 996 | if 'E-UTRAN' in in_list: |
| 997 | u16 |= 0x4000 |
Vadim Yanitskiy | 5452d64 | 2021-03-07 21:45:34 +0100 | [diff] [blame] | 998 | if 'E-UTRAN WB-S1' in in_list: |
| 999 | u16 |= 0x6000 |
| 1000 | if 'E-UTRAN NB-S1' in in_list: |
| 1001 | u16 |= 0x5000 |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1002 | # GSM mess |
| 1003 | if 'GSM' in in_list and 'EC-GSM-IoT' in in_list: |
| 1004 | u16 |= 0x008C |
| 1005 | elif 'GSM' in in_list: |
| 1006 | u16 |= 0x0084 |
| 1007 | elif 'EC-GSM-IuT' in in_list: |
| 1008 | u16 |= 0x0088 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1009 | return '%04X' % (u16) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1010 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1011 | # TS 51.011 Section 10.3.38 |
| 1012 | class EF_CPBCCH(TransRecEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1013 | def __init__(self, fid='6f63', sfid=None, name='EF.CPBCCH', size=(2, 14), rec_len=2, |
Harald Welte | d90ceb8 | 2022-07-17 22:10:58 +0200 | [diff] [blame] | 1014 | desc='CPBCCH Information', **kwargs): |
| 1015 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1016 | self._construct = Struct('cpbcch'/Int16ub) |
| 1017 | |
| 1018 | # TS 51.011 Section 10.3.39 |
| 1019 | class EF_InvScan(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1020 | def __init__(self, fid='6f64', sfid=None, name='EF.InvScan', size=(1, 1), |
Harald Welte | d90ceb8 | 2022-07-17 22:10:58 +0200 | [diff] [blame] | 1021 | desc='IOnvestigation Scan', **kwargs): |
| 1022 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1023 | self._construct = FlagsEnum( |
| 1024 | Byte, in_limited_service_mode=1, after_successful_plmn_selection=2) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1025 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1026 | # TS 51.011 Section 4.2.58 |
| 1027 | class EF_PNN(LinFixedEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 1028 | # TODO: 430a82d432bbbc7eb75de432450a82d432bbbc7eb75de432ffffffff |
| 1029 | # TODO: 430a82c596b34cbfbfe5eb39ffffffffffffffffffffffffffffffffffff |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1030 | class FullNameForNetwork(BER_TLV_IE, tag=0x43): |
| 1031 | # TS 24.008 10.5.3.5a |
Harald Welte | 857f110 | 2022-07-20 07:44:25 +0200 | [diff] [blame] | 1032 | # TODO: proper decode |
| 1033 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1034 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1035 | class ShortNameForNetwork(BER_TLV_IE, tag=0x45): |
| 1036 | # TS 24.008 10.5.3.5a |
Harald Welte | 857f110 | 2022-07-20 07:44:25 +0200 | [diff] [blame] | 1037 | # TODO: proper decode |
| 1038 | _construct = HexAdapter(GreedyBytes) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1039 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1040 | class NetworkNameCollection(TLV_IE_Collection, nested=[FullNameForNetwork, ShortNameForNetwork]): |
| 1041 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1042 | |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1043 | def __init__(self, fid='6fc5', sfid=None, name='EF.PNN', desc='PLMN Network Name', **kwargs): |
| 1044 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1045 | self._tlv = EF_PNN.NetworkNameCollection |
| 1046 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1047 | # TS 51.011 Section 10.3.42 |
| 1048 | class EF_OPL(LinFixedEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 1049 | _test_de_encode = [ |
| 1050 | ( '62f2100000fffe01', |
| 1051 | { "lai": { "mcc_mnc": "262f01", "lac_min": "0000", "lac_max": "fffe" }, "pnn_record_id": 1 } ), |
| 1052 | ] |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 1053 | def __init__(self, fid='6fc6', sfid=None, name='EF.OPL', rec_len=(8, 8), desc='Operator PLMN List', **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1054 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 1055 | self._construct = Struct('lai'/Struct('mcc_mnc'/BcdAdapter(Bytes(3)), |
| 1056 | 'lac_min'/HexAdapter(Bytes(2)), 'lac_max'/HexAdapter(Bytes(2))), 'pnn_record_id'/Int8ub) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1057 | |
| 1058 | # TS 51.011 Section 10.3.44 + TS 31.102 4.2.62 |
| 1059 | class EF_MBI(LinFixedEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 1060 | _test_de_encode = [ |
| 1061 | ( '0100000000', |
| 1062 | { "mbi_voicemail": 1, "mbi_fax": 0, "mbi_email": 0, "mbi_other": 0, "mbi_videocall": 0 } ), |
| 1063 | ] |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 1064 | def __init__(self, fid='6fc9', sfid=None, name='EF.MBI', rec_len=(4, 5), desc='Mailbox Identifier', **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1065 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1066 | self._construct = Struct('mbi_voicemail'/Int8ub, 'mbi_fax'/Int8ub, 'mbi_email'/Int8ub, |
| 1067 | 'mbi_other'/Int8ub, 'mbi_videocall'/COptional(Int8ub)) |
| 1068 | |
| 1069 | # TS 51.011 Section 10.3.45 + TS 31.102 4.2.63 |
| 1070 | class EF_MWIS(LinFixedEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 1071 | def __init__(self, fid='6fca', sfid=None, name='EF.MWIS', rec_len=(5, 6), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1072 | desc='Message Waiting Indication Status', **kwargs): |
| 1073 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1074 | self._construct = Struct('mwi_status'/FlagsEnum(Byte, voicemail=1, fax=2, email=4, other=8, videomail=16), |
| 1075 | 'num_waiting_voicemail'/Int8ub, |
| 1076 | 'num_waiting_fax'/Int8ub, 'num_waiting_email'/Int8ub, |
| 1077 | 'num_waiting_other'/Int8ub, 'num_waiting_videomail'/COptional(Int8ub)) |
| 1078 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1079 | # TS 51.011 Section 10.3.66 |
| 1080 | class EF_SPDI(TransparentEF): |
Harald Welte | 865eea6 | 2023-01-27 19:26:12 +0100 | [diff] [blame] | 1081 | # TODO: a305800337f800ffffffffffffffffffffffffffffffffffffffffffffff |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1082 | class ServiceProviderPLMN(BER_TLV_IE, tag=0x80): |
| 1083 | # flexible numbers of 3-byte PLMN records |
| 1084 | _construct = GreedyRange(BcdAdapter(Bytes(3))) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1085 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1086 | class SPDI(BER_TLV_IE, tag=0xA3, nested=[ServiceProviderPLMN]): |
| 1087 | pass |
| 1088 | def __init__(self, fid='6fcd', sfid=None, name='EF.SPDI', |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1089 | desc='Service Provider Display Information', **kwargs): |
| 1090 | super().__init__(fid, sfid=sfid, name=name, desc=desc, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1091 | self._tlv = EF_SPDI.SPDI |
| 1092 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1093 | # TS 51.011 Section 10.3.51 |
| 1094 | class EF_MMSN(LinFixedEF): |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 1095 | def __init__(self, fid='6fce', sfid=None, name='EF.MMSN', rec_len=(4, 20), desc='MMS Notification', **kwargs): |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1096 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 3c98d5e | 2022-07-20 07:40:05 +0200 | [diff] [blame] | 1097 | self._construct = Struct('mms_status'/HexAdapter(Bytes(2)), 'mms_implementation'/HexAdapter(Bytes(1)), |
| 1098 | 'mms_notification'/HexAdapter(Bytes(this._.total_len-4)), 'ext_record_nr'/Byte) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1099 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1100 | # TS 51.011 Annex K.1 |
| 1101 | class MMS_Implementation(BER_TLV_IE, tag=0x80): |
| 1102 | _construct = FlagsEnum(Byte, WAP=1) |
| 1103 | |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1104 | # TS 51.011 Section 10.3.53 |
| 1105 | class EF_MMSICP(TransparentEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1106 | class MMS_Relay_Server(BER_TLV_IE, tag=0x81): |
| 1107 | # 3GPP TS 23.140 |
| 1108 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1109 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1110 | class Interface_to_CN(BER_TLV_IE, tag=0x82): |
| 1111 | # 3GPP TS 23.140 |
| 1112 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1113 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1114 | class Gateway(BER_TLV_IE, tag=0x83): |
| 1115 | # Address, Type of address, Port, Service, AuthType, AuthId, AuthPass / 3GPP TS 23.140 |
| 1116 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1117 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1118 | class MMS_ConnectivityParamters(TLV_IE_Collection, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1119 | nested=[MMS_Implementation, MMS_Relay_Server, Interface_to_CN, Gateway]): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1120 | pass |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1121 | def __init__(self, fid='6fd0', sfid=None, name='EF.MMSICP', size=(1, None), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1122 | desc='MMS Issuer Connectivity Parameters', **kwargs): |
| 1123 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1124 | self._tlv = EF_MMSICP.MMS_ConnectivityParamters |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1125 | |
| 1126 | # TS 51.011 Section 10.3.54 |
| 1127 | class EF_MMSUP(LinFixedEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1128 | class MMS_UserPref_ProfileName(BER_TLV_IE, tag=0x81): |
| 1129 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1130 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1131 | class MMS_UserPref_Info(BER_TLV_IE, tag=0x82): |
| 1132 | pass |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1133 | |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1134 | class MMS_User_Preferences(TLV_IE_Collection, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1135 | nested=[MMS_Implementation, MMS_UserPref_ProfileName, MMS_UserPref_Info]): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 1136 | pass |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 1137 | def __init__(self, fid='6fd1', sfid=None, name='EF.MMSUP', rec_len=(1, None), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1138 | desc='MMS User Preferences', **kwargs): |
| 1139 | super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len=rec_len, **kwargs) |
Harald Welte | 6113fe9 | 2022-01-21 15:51:35 +0100 | [diff] [blame] | 1140 | self._tlv = EF_MMSUP.MMS_User_Preferences |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1141 | |
| 1142 | # TS 51.011 Section 10.3.55 |
| 1143 | class EF_MMSUCP(TransparentEF): |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1144 | def __init__(self, fid='6fd2', sfid=None, name='EF.MMSUCP', size=(1, None), |
Harald Welte | 6169c72 | 2022-02-12 09:05:15 +0100 | [diff] [blame] | 1145 | desc='MMS User Connectivity Parameters', **kwargs): |
| 1146 | super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, **kwargs) |
Harald Welte | 790b270 | 2021-04-11 00:01:35 +0200 | [diff] [blame] | 1147 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1148 | |
| 1149 | class DF_GSM(CardDF): |
| 1150 | def __init__(self, fid='7f20', name='DF.GSM', desc='GSM Network related files'): |
| 1151 | super().__init__(fid=fid, name=name, desc=desc) |
Harald Welte | 61ef157 | 2023-03-09 19:42:38 +0100 | [diff] [blame] | 1152 | self.shell_commands += [self.AddlShellCommands()] |
| 1153 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1154 | files = [ |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1155 | EF_LP(), |
| 1156 | EF_IMSI(), |
| 1157 | EF_Kc(), |
| 1158 | EF_PLMNsel(), |
| 1159 | TransparentEF('6f31', None, 'EF.HPPLMN', |
| 1160 | 'Higher Priority PLMN search period'), |
| 1161 | EF_ACMmax(), |
| 1162 | EF_ServiceTable('6f38', None, 'EF.SST', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1163 | 'SIM service table', table=EF_SST_map, size=(2, 16)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1164 | CyclicEF('6f39', None, 'EF.ACM', |
Harald Welte | 99e4cc0 | 2022-07-21 15:25:47 +0200 | [diff] [blame] | 1165 | 'Accumulated call meter', rec_len=(3, 3)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1166 | TransparentEF('6f3e', None, 'EF.GID1', 'Group Identifier Level 1'), |
| 1167 | TransparentEF('6f3f', None, 'EF.GID2', 'Group Identifier Level 2'), |
| 1168 | EF_SPN(), |
| 1169 | TransparentEF('6f41', None, 'EF.PUCT', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1170 | 'Price per unit and currency table', size=(5, 5)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1171 | EF_CBMI(), |
Harald Welte | 10a1a0a | 2023-05-24 15:19:28 +0200 | [diff] [blame] | 1172 | TransparentEF('6f74', None, 'EF.BCCH', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1173 | 'Broadcast control channels', size=(16, 16)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1174 | EF_ACC(), |
| 1175 | EF_PLMNsel('6f7b', None, 'EF.FPLMN', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1176 | 'Forbidden PLMNs', size=(12, 12)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1177 | EF_LOCI(), |
| 1178 | EF_AD(), |
Harald Welte | 33eef85 | 2023-05-24 15:20:34 +0200 | [diff] [blame] | 1179 | TransparentEF('6fae', None, 'EF.Phase', |
Harald Welte | 13edf30 | 2022-07-21 15:19:23 +0200 | [diff] [blame] | 1180 | 'Phase identification', size=(1, 1)), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1181 | EF_VGCS(), |
| 1182 | EF_VGCSS(), |
| 1183 | EF_VGCS('6fb3', None, 'EF.VBS', 'Voice Broadcast Service'), |
| 1184 | EF_VGCSS('6fb4', None, 'EF.VBSS', |
| 1185 | 'Voice Broadcast Service Status'), |
| 1186 | EF_eMLPP(), |
| 1187 | EF_AAeM(), |
| 1188 | EF_CBMID(), |
| 1189 | EF_ECC(), |
| 1190 | EF_CBMIR(), |
| 1191 | EF_DCK(), |
| 1192 | EF_CNL(), |
| 1193 | EF_NIA(), |
| 1194 | EF_Kc('6f52', None, 'EF.KcGPRS', 'GPRS Ciphering key KcGPRS'), |
| 1195 | EF_LOCIGPRS(), |
| 1196 | TransparentEF('6f54', None, 'EF.SUME', 'SetUpMenu Elements'), |
| 1197 | EF_xPLMNwAcT('6f60', None, 'EF.PLMNwAcT', |
| 1198 | 'User controlled PLMN Selector with Access Technology'), |
| 1199 | EF_xPLMNwAcT('6f61', None, 'EF.OPLMNwAcT', |
| 1200 | 'Operator controlled PLMN Selector with Access Technology'), |
| 1201 | EF_xPLMNwAcT('6f62', None, 'EF.HPLMNwAcT', |
| 1202 | 'HPLMN Selector with Access Technology'), |
| 1203 | EF_CPBCCH(), |
| 1204 | EF_InvScan(), |
| 1205 | EF_PNN(), |
| 1206 | EF_OPL(), |
| 1207 | EF_ADN('6fc7', None, 'EF.MBDN', 'Mailbox Dialling Numbers'), |
| 1208 | EF_MBI(), |
| 1209 | EF_MWIS(), |
| 1210 | EF_ADN('6fcb', None, 'EF.CFIS', |
| 1211 | 'Call Forwarding Indication Status'), |
| 1212 | EF_EXT('6fc8', None, 'EF.EXT6', 'Externsion6 (MBDN)'), |
| 1213 | EF_EXT('6fcc', None, 'EF.EXT7', 'Externsion7 (CFIS)'), |
| 1214 | EF_SPDI(), |
| 1215 | EF_MMSN(), |
| 1216 | EF_EXT('6fcf', None, 'EF.EXT8', 'Extension8 (MMSN)'), |
| 1217 | EF_MMSICP(), |
| 1218 | EF_MMSUP(), |
| 1219 | EF_MMSUCP(), |
| 1220 | ] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 1221 | self.add_files(files) |
| 1222 | |
Harald Welte | 61ef157 | 2023-03-09 19:42:38 +0100 | [diff] [blame] | 1223 | @with_default_category('Application-Specific Commands') |
| 1224 | class AddlShellCommands(CommandSet): |
| 1225 | def __init__(self): |
| 1226 | super().__init__() |
| 1227 | |
| 1228 | authenticate_parser = argparse.ArgumentParser() |
| 1229 | authenticate_parser.add_argument('rand', help='Random challenge') |
| 1230 | |
| 1231 | @cmd2.with_argparser(authenticate_parser) |
| 1232 | def do_authenticate(self, opts): |
| 1233 | """Perform GSM Authentication.""" |
| 1234 | (data, sw) = self._cmd.card._scc.run_gsm(opts.rand) |
| 1235 | self._cmd.poutput_json(data) |
| 1236 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1237 | |
Philipp Maier | c8387dc | 2021-10-29 17:59:50 +0200 | [diff] [blame] | 1238 | class CardProfileSIM(CardProfile): |
Philipp Maier | a028c7d | 2021-11-08 16:12:03 +0100 | [diff] [blame] | 1239 | |
Vadim Yanitskiy | 87dd020 | 2023-04-22 20:45:29 +0700 | [diff] [blame] | 1240 | ORDER = 3 |
Philipp Maier | a028c7d | 2021-11-08 16:12:03 +0100 | [diff] [blame] | 1241 | |
Philipp Maier | c8387dc | 2021-10-29 17:59:50 +0200 | [diff] [blame] | 1242 | def __init__(self): |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1243 | sw = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1244 | 'Normal': { |
| 1245 | '9000': 'Normal ending of the command', |
| 1246 | '91xx': 'normal ending of the command, with extra information from the proactive SIM containing a command for the ME', |
| 1247 | '9exx': 'length XX of the response data given in case of a SIM data download error', |
| 1248 | '9fxx': 'length XX of the response data', |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1249 | }, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1250 | 'Postponed processing': { |
| 1251 | '9300': 'SIM Application Toolkit is busy. Command cannot be executed at present, further normal commands are allowed', |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1252 | }, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1253 | 'Memory management': { |
| 1254 | '920x': 'command successful but after using an internal update retry routine X times', |
| 1255 | '9240': 'memory problem', |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1256 | }, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1257 | 'Referencing management': { |
| 1258 | '9400': 'no EF selected', |
| 1259 | '9402': 'out of range (invalid address)', |
| 1260 | '9404': 'file ID not found or pattern not found', |
| 1261 | '9408': 'file is inconsistent with the command', |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1262 | }, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1263 | 'Security management': { |
| 1264 | '9802': 'no CHV initialized', |
| 1265 | '9804': 'access condition not fulfilled, unsuccessful CHV verification or authentication failed', |
| 1266 | '9808': 'in contradiction with CHV status', |
| 1267 | '9810': 'in contradiction with invalidation status', |
| 1268 | '9840': 'unsuccessful verification, CHV blocked, UNBLOCK CHV blocked', |
| 1269 | '9850': 'increase cannot be performed, Max value reached', |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1270 | }, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1271 | 'Application independent errors': { |
| 1272 | '67xx': 'incorrect parameter P3', |
| 1273 | '6bxx': 'incorrect parameter P1 or P2', |
| 1274 | '6dxx': 'unknown instruction code given in the command', |
| 1275 | '6exx': 'wrong instruction class given in the command', |
| 1276 | '6fxx': 'technical problem with no diagnostic given', |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1277 | }, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1278 | } |
Philipp Maier | a4df942 | 2021-11-10 17:13:40 +0100 | [diff] [blame] | 1279 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1280 | super().__init__('SIM', desc='GSM SIM Card', cla="a0", |
| 1281 | sel_ctrl="0000", files_in_mf=[DF_TELECOM(), DF_GSM()], sw=sw) |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1282 | |
Philipp Maier | 5998a3a | 2021-11-16 15:16:39 +0100 | [diff] [blame] | 1283 | @staticmethod |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1284 | def decode_select_response(resp_hex: str) -> object: |
Harald Welte | 5924ec4 | 2023-01-24 19:49:24 +0100 | [diff] [blame] | 1285 | # we try to build something that resembles a dict resulting from the TLV decoder |
| 1286 | # of TS 102.221 (FcpTemplate), so that higher-level code only has to deal with one |
| 1287 | # format of SELECT response |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1288 | resp_bin = h2b(resp_hex) |
| 1289 | struct_of_file_map = { |
| 1290 | 0: 'transparent', |
| 1291 | 1: 'linear_fixed', |
| 1292 | 3: 'cyclic' |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1293 | } |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1294 | type_of_file_map = { |
| 1295 | 1: 'mf', |
| 1296 | 2: 'df', |
| 1297 | 4: 'working_ef' |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1298 | } |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1299 | ret = { |
Harald Welte | 747a978 | 2022-02-13 17:52:28 +0100 | [diff] [blame] | 1300 | 'file_descriptor': { |
| 1301 | 'file_descriptor_byte': {}, |
| 1302 | }, |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1303 | 'proprietary_info': {}, |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1304 | } |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1305 | ret['file_id'] = b2h(resp_bin[4:6]) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1306 | file_type = type_of_file_map[resp_bin[6] |
| 1307 | ] if resp_bin[6] in type_of_file_map else resp_bin[6] |
Harald Welte | 747a978 | 2022-02-13 17:52:28 +0100 | [diff] [blame] | 1308 | ret['file_descriptor']['file_descriptor_byte']['file_type'] = file_type |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1309 | if file_type in ['mf', 'df']: |
Harald Welte | 5924ec4 | 2023-01-24 19:49:24 +0100 | [diff] [blame] | 1310 | ret['proprietary_info']['available_memory'] = int.from_bytes(resp_bin[2:4], 'big') |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1311 | ret['file_characteristics'] = b2h(resp_bin[13:14]) |
| 1312 | ret['num_direct_child_df'] = resp_bin[14] |
| 1313 | ret['num_direct_child_ef'] = resp_bin[15] |
| 1314 | ret['num_chv_unblock_adm_codes'] = int(resp_bin[16]) |
| 1315 | # CHV / UNBLOCK CHV stats |
| 1316 | elif file_type in ['working_ef']: |
Harald Welte | 5924ec4 | 2023-01-24 19:49:24 +0100 | [diff] [blame] | 1317 | ret['file_size'] = int.from_bytes(resp_bin[2:4], 'big') |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1318 | file_struct = struct_of_file_map[resp_bin[13] |
| 1319 | ] if resp_bin[13] in struct_of_file_map else resp_bin[13] |
Harald Welte | 747a978 | 2022-02-13 17:52:28 +0100 | [diff] [blame] | 1320 | ret['file_descriptor']['file_descriptor_byte']['structure'] = file_struct |
Harald Welte | 5924ec4 | 2023-01-24 19:49:24 +0100 | [diff] [blame] | 1321 | if file_struct != 'transparent': |
| 1322 | record_len = resp_bin[14] |
| 1323 | ret['file_descriptor']['record_len'] = record_len |
| 1324 | ret['file_descriptor']['num_of_rec'] = ret['file_size'] // record_len |
Philipp Maier | 4ab971c | 2021-11-11 11:53:49 +0100 | [diff] [blame] | 1325 | ret['access_conditions'] = b2h(resp_bin[8:10]) |
| 1326 | if resp_bin[11] & 0x01 == 0: |
| 1327 | ret['life_cycle_status_int'] = 'operational_activated' |
| 1328 | elif resp_bin[11] & 0x04: |
| 1329 | ret['life_cycle_status_int'] = 'operational_deactivated' |
| 1330 | else: |
| 1331 | ret['life_cycle_status_int'] = 'terminated' |
| 1332 | return ret |
Philipp Maier | a028c7d | 2021-11-08 16:12:03 +0100 | [diff] [blame] | 1333 | |
| 1334 | @staticmethod |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 1335 | def match_with_card(scc: SimCardCommands) -> bool: |
Philipp Maier | a028c7d | 2021-11-08 16:12:03 +0100 | [diff] [blame] | 1336 | return match_sim(scc) |