Supreeth Herle | 8b72c27 | 2020-03-22 08:55:50 +0100 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | """ |
Harald Welte | 16ec96a | 2021-04-21 10:46:19 +0200 | [diff] [blame] | 4 | Various constants from 3GPP TS 31.103 V16.1.0 |
Supreeth Herle | 8b72c27 | 2020-03-22 08:55:50 +0100 | [diff] [blame] | 5 | """ |
| 6 | |
| 7 | # |
| 8 | # Copyright (C) 2020 Supreeth Herle <herlesupreeth@gmail.com> |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 9 | # Copyright (C) 2021 Harald Welte <laforge@osmocom.org> |
Supreeth Herle | 8b72c27 | 2020-03-22 08:55:50 +0100 | [diff] [blame] | 10 | # |
| 11 | # This program is free software: you can redistribute it and/or modify |
| 12 | # it under the terms of the GNU General Public License as published by |
| 13 | # the Free Software Foundation, either version 2 of the License, or |
| 14 | # (at your option) any later version. |
| 15 | # |
| 16 | # This program is distributed in the hope that it will be useful, |
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | # GNU General Public License for more details. |
| 20 | # |
| 21 | # You should have received a copy of the GNU General Public License |
| 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | # |
| 24 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 25 | from pySim.filesystem import * |
| 26 | from pySim.utils import * |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 27 | from pySim.tlv import * |
Harald Welte | 35dfe82 | 2021-04-21 10:50:12 +0200 | [diff] [blame] | 28 | from pySim.ts_51_011 import EF_AD, EF_SMS, EF_SMSS, EF_SMSR, EF_SMSP |
Harald Welte | e894749 | 2022-02-10 10:33:20 +0100 | [diff] [blame] | 29 | from pySim.ts_31_102 import ADF_USIM, EF_FromPreferred, EF_UServiceTable |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 30 | import pySim.ts_102_221 |
Harald Welte | fc4833e | 2021-05-02 21:46:06 +0200 | [diff] [blame] | 31 | from pySim.ts_102_221 import EF_ARR |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 32 | |
Supreeth Herle | 8b72c27 | 2020-03-22 08:55:50 +0100 | [diff] [blame] | 33 | # Mapping between ISIM Service Number and its description |
| 34 | EF_IST_map = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 35 | 1: 'P-CSCF address', |
| 36 | 2: 'Generic Bootstrapping Architecture (GBA)', |
| 37 | 3: 'HTTP Digest', |
| 38 | 4: 'GBA-based Local Key Establishment Mechanism', |
| 39 | 5: 'Support of P-CSCF discovery for IMS Local Break Out', |
| 40 | 6: 'Short Message Storage (SMS)', |
| 41 | 7: 'Short Message Status Reports (SMSR)', |
| 42 | 8: 'Support for SM-over-IP including data download via SMS-PP as defined in TS 31.111 [31]', |
| 43 | 9: 'Communication Control for IMS by ISIM', |
| 44 | 10: 'Support of UICC access to IMS', |
| 45 | 11: 'URI support by UICC', |
| 46 | 12: 'Media Type support', |
| 47 | 13: 'IMS call disconnection cause', |
| 48 | 14: 'URI support for MO SHORT MESSAGE CONTROL', |
| 49 | 15: 'MCPTT', |
| 50 | 16: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [31]', |
| 51 | 17: 'From Preferred', |
| 52 | 18: 'IMS configuration data', |
| 53 | 19: 'XCAP Configuration Data', |
| 54 | 20: 'WebRTC URI', |
| 55 | 21: 'MuD and MiD configuration data', |
Supreeth Herle | 8b72c27 | 2020-03-22 08:55:50 +0100 | [diff] [blame] | 56 | } |
herlesupreeth | 75c14c0 | 2020-12-23 09:41:07 +0100 | [diff] [blame] | 57 | |
| 58 | EF_ISIM_ADF_map = { |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 59 | 'IST': '6F07', |
| 60 | 'IMPI': '6F02', |
| 61 | 'DOMAIN': '6F03', |
| 62 | 'IMPU': '6F04', |
| 63 | 'AD': '6FAD', |
| 64 | 'ARR': '6F06', |
| 65 | 'PCSCF': '6F09', |
| 66 | 'GBAP': '6FD5', |
| 67 | 'GBANL': '6FD7', |
| 68 | 'NAFKCA': '6FDD', |
| 69 | 'UICCIARI': '6FE7', |
| 70 | 'SMS': '6F3C', |
| 71 | 'SMSS': '6F43', |
| 72 | 'SMSR': '6F47', |
| 73 | 'SMSP': '6F42', |
| 74 | 'FromPreferred': '6FF7', |
| 75 | 'IMSConfigData': '6FF8', |
| 76 | 'XCAPConfigData': '6FFC', |
| 77 | 'WebRTCURI': '6FFA' |
herlesupreeth | 75c14c0 | 2020-12-23 09:41:07 +0100 | [diff] [blame] | 78 | } |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 79 | |
| 80 | # TS 31.103 Section 4.2.2 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 81 | |
| 82 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 83 | class EF_IMPI(TransparentEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 84 | class nai(BER_TLV_IE, tag=0x80): |
| 85 | _construct = GreedyString("utf8") |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 86 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 87 | def __init__(self, fid='6f02', sfid=0x02, name='EF.IMPI', desc='IMS private user identity'): |
| 88 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 89 | self._tlv = EF_IMPI.nai |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 90 | |
| 91 | # TS 31.103 Section 4.2.3 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 92 | |
| 93 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 94 | class EF_DOMAIN(TransparentEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 95 | class domain(BER_TLV_IE, tag=0x80): |
| 96 | _construct = GreedyString("utf8") |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 97 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 98 | def __init__(self, fid='6f05', sfid=0x05, name='EF.DOMAIN', desc='Home Network Domain Name'): |
| 99 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 100 | self._tlv = EF_DOMAIN.domain |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 101 | |
| 102 | # TS 31.103 Section 4.2.4 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 103 | |
| 104 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 105 | class EF_IMPU(LinFixedEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 106 | class impu(BER_TLV_IE, tag=0x80): |
| 107 | _construct = GreedyString("utf8") |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 108 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 109 | def __init__(self, fid='6f04', sfid=0x04, name='EF.IMPU', desc='IMS public user identity'): |
| 110 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 111 | self._tlv = EF_IMPU.impu |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 112 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 113 | # TS 31.103 Section 4.2.8 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 114 | |
| 115 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 116 | class EF_PCSCF(LinFixedEF): |
| 117 | def __init__(self, fid='6f09', sfid=None, name='EF.P-CSCF', desc='P-CSCF Address'): |
| 118 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 119 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 120 | def _decode_record_hex(self, raw_hex): |
Philipp Maier | 86b09da | 2021-04-30 15:13:57 +0200 | [diff] [blame] | 121 | addr, addr_type = dec_addr_tlv(raw_hex) |
| 122 | return {"addr": addr, "addr_type": addr_type} |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 123 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 124 | def _encode_record_hex(self, json_in): |
Philipp Maier | 86b09da | 2021-04-30 15:13:57 +0200 | [diff] [blame] | 125 | addr = json_in['addr'] |
| 126 | addr_type = json_in['addr_type'] |
| 127 | return enc_addr_tlv(addr, addr_type) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 128 | |
| 129 | # TS 31.103 Section 4.2.9 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 130 | |
| 131 | |
Harald Welte | 89e5954 | 2021-04-02 21:33:13 +0200 | [diff] [blame] | 132 | class EF_GBABP(TransparentEF): |
Harald Welte | c9cdce3 | 2021-04-11 10:28:28 +0200 | [diff] [blame] | 133 | def __init__(self, fid='6fd5', sfid=None, name='EF.GBABP', desc='GBA Bootstrapping'): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 134 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
| 135 | |
| 136 | # TS 31.103 Section 4.2.10 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 137 | |
| 138 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 139 | class EF_GBANL(LinFixedEF): |
| 140 | def __init__(self, fid='6fd7', sfid=None, name='EF.GBANL', desc='GBA NAF List'): |
| 141 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
| 142 | |
| 143 | # TS 31.103 Section 4.2.11 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 144 | |
| 145 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 146 | class EF_NAFKCA(LinFixedEF): |
| 147 | def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', desc='NAF Key Centre Address'): |
| 148 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
| 149 | |
| 150 | # TS 31.103 Section 4.2.16 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 151 | |
| 152 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 153 | class EF_UICCIARI(LinFixedEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 154 | class iari(BER_TLV_IE, tag=0x80): |
| 155 | _construct = GreedyString("utf8") |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 156 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 157 | def __init__(self, fid='6fe7', sfid=None, name='EF.UICCIARI', desc='UICC IARI'): |
| 158 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 159 | self._tlv = EF_UICCIARI.iari |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 160 | |
| 161 | # TS 31.103 Section 4.2.18 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 162 | |
| 163 | |
Harald Welte | 2788162 | 2021-04-21 11:16:31 +0200 | [diff] [blame] | 164 | class EF_IMSConfigData(BerTlvEF): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 165 | def __init__(self, fid='6ff8', sfid=None, name='EF.IMSConfigData', desc='IMS Configuration Data'): |
| 166 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
| 167 | |
| 168 | # TS 31.103 Section 4.2.19 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 169 | |
| 170 | |
Harald Welte | 2788162 | 2021-04-21 11:16:31 +0200 | [diff] [blame] | 171 | class EF_XCAPConfigData(BerTlvEF): |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 172 | def __init__(self, fid='6ffc', sfid=None, name='EF.XCAPConfigData', desc='XCAP Configuration Data'): |
| 173 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
| 174 | |
| 175 | # TS 31.103 Section 4.2.20 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 176 | |
| 177 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 178 | class EF_WebRTCURI(TransparentEF): |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 179 | class uri(BER_TLV_IE, tag=0x80): |
| 180 | _construct = GreedyString("utf8") |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 181 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 182 | def __init__(self, fid='6ffa', sfid=None, name='EF.WebRTCURI', desc='WebRTC URI'): |
| 183 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
Harald Welte | 14105dc | 2021-05-31 08:48:51 +0200 | [diff] [blame] | 184 | self._tlv = EF_WebRTCURI.uri |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 185 | |
Harald Welte | 16ec96a | 2021-04-21 10:46:19 +0200 | [diff] [blame] | 186 | # TS 31.103 Section 4.2.21 |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 187 | |
| 188 | |
Harald Welte | 2788162 | 2021-04-21 11:16:31 +0200 | [diff] [blame] | 189 | class EF_MuDMiDConfigData(BerTlvEF): |
Harald Welte | 16ec96a | 2021-04-21 10:46:19 +0200 | [diff] [blame] | 190 | def __init__(self, fid='6ffe', sfid=None, name='EF.MuDMiDConfigData', |
| 191 | desc='MuD and MiD Configuration Data'): |
| 192 | super().__init__(fid=fid, sfid=sfid, name=name, desc=desc) |
| 193 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 194 | |
| 195 | class ADF_ISIM(CardADF): |
| 196 | def __init__(self, aid='a0000000871004', name='ADF.ISIM', fid=None, sfid=None, |
| 197 | desc='ISIM Application'): |
| 198 | super().__init__(aid=aid, fid=fid, sfid=sfid, name=name, desc=desc) |
| 199 | |
| 200 | files = [ |
| 201 | EF_IMPI(), |
| 202 | EF_DOMAIN(), |
| 203 | EF_IMPU(), |
| 204 | EF_AD(), |
Harald Welte | fc4833e | 2021-05-02 21:46:06 +0200 | [diff] [blame] | 205 | EF_ARR('6f06', 0x06), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 206 | EF_UServiceTable('6f07', 0x07, 'EF.IST', |
| 207 | 'ISIM Service Table', {1, None}, EF_IST_map), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 208 | EF_PCSCF(), |
| 209 | EF_GBABP(), |
| 210 | EF_GBANL(), |
| 211 | EF_NAFKCA(), |
Harald Welte | 35dfe82 | 2021-04-21 10:50:12 +0200 | [diff] [blame] | 212 | EF_SMS(), |
| 213 | EF_SMSS(), |
| 214 | EF_SMSR(), |
| 215 | EF_SMSP(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 216 | EF_UICCIARI(), |
Harald Welte | 7129007 | 2021-04-21 10:58:24 +0200 | [diff] [blame] | 217 | EF_FromPreferred(), |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 218 | EF_IMSConfigData(), |
| 219 | EF_XCAPConfigData(), |
| 220 | EF_WebRTCURI(), |
Harald Welte | 16ec96a | 2021-04-21 10:46:19 +0200 | [diff] [blame] | 221 | EF_MuDMiDConfigData(), |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 222 | ] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 223 | self.add_files(files) |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 224 | # add those commands to the general commands of a TransparentEF |
| 225 | self.shell_commands += [ADF_USIM.AddlShellCommands()] |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 226 | |
| 227 | def decode_select_response(self, data_hex): |
Philipp Maier | 5998a3a | 2021-11-16 15:16:39 +0100 | [diff] [blame] | 228 | return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex) |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 229 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 230 | |
Harald Welte | b2edd14 | 2021-01-08 23:29:35 +0100 | [diff] [blame] | 231 | # TS 31.103 Section 7.1 |
| 232 | sw_isim = { |
| 233 | 'Security management': { |
| 234 | '9862': 'Authentication error, incorrect MAC', |
| 235 | '9864': 'Authentication error, security context not supported', |
| 236 | } |
| 237 | } |
| 238 | |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 239 | |
Philipp Maier | 57f65ee | 2021-10-18 14:09:02 +0200 | [diff] [blame] | 240 | class CardApplicationISIM(CardApplication): |
| 241 | def __init__(self): |
Harald Welte | c91085e | 2022-02-10 18:05:45 +0100 | [diff] [blame] | 242 | super().__init__('ISIM', adf=ADF_ISIM(), sw=sw_isim) |