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