blob: fb164ef22b4b742317789d6b1ee94306f6ac5089 [file] [log] [blame]
Supreeth Herle8b72c272020-03-22 08:55:50 +01001# -*- coding: utf-8 -*-
2
3"""
Harald Welte16ec96a2021-04-21 10:46:19 +02004Various constants from 3GPP TS 31.103 V16.1.0
Supreeth Herle8b72c272020-03-22 08:55:50 +01005"""
6
7#
8# Copyright (C) 2020 Supreeth Herle <herlesupreeth@gmail.com>
Harald Welteb2edd142021-01-08 23:29:35 +01009# Copyright (C) 2021 Harald Welte <laforge@osmocom.org>
Supreeth Herle8b72c272020-03-22 08:55:50 +010010#
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 Welteb2edd142021-01-08 23:29:35 +010025from pySim.filesystem import *
26from pySim.utils import *
Harald Welte14105dc2021-05-31 08:48:51 +020027from pySim.tlv import *
Harald Welte35dfe822021-04-21 10:50:12 +020028from pySim.ts_51_011 import EF_AD, EF_SMS, EF_SMSS, EF_SMSR, EF_SMSP
Harald Weltee8947492022-02-10 10:33:20 +010029from pySim.ts_31_102 import ADF_USIM, EF_FromPreferred, EF_UServiceTable
Harald Welteb2edd142021-01-08 23:29:35 +010030import pySim.ts_102_221
Harald Weltefc4833e2021-05-02 21:46:06 +020031from pySim.ts_102_221 import EF_ARR
Harald Welteb2edd142021-01-08 23:29:35 +010032
Supreeth Herle8b72c272020-03-22 08:55:50 +010033# Mapping between ISIM Service Number and its description
34EF_IST_map = {
Harald Weltec91085e2022-02-10 18:05:45 +010035 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 Herle8b72c272020-03-22 08:55:50 +010056}
herlesupreeth75c14c02020-12-23 09:41:07 +010057
58EF_ISIM_ADF_map = {
Harald Weltec91085e2022-02-10 18:05:45 +010059 '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'
herlesupreeth75c14c02020-12-23 09:41:07 +010078}
Harald Welteb2edd142021-01-08 23:29:35 +010079
80# TS 31.103 Section 4.2.2
81class EF_IMPI(TransparentEF):
Harald Welte14105dc2021-05-31 08:48:51 +020082 class nai(BER_TLV_IE, tag=0x80):
83 _construct = GreedyString("utf8")
Harald Weltec91085e2022-02-10 18:05:45 +010084
Harald Welte6169c722022-02-12 09:05:15 +010085 def __init__(self, fid='6f02', sfid=0x02, name='EF.IMPI', desc='IMS private user identity', **kwargs):
86 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +020087 self._tlv = EF_IMPI.nai
Harald Welteb2edd142021-01-08 23:29:35 +010088
89# TS 31.103 Section 4.2.3
90class EF_DOMAIN(TransparentEF):
Harald Welte14105dc2021-05-31 08:48:51 +020091 class domain(BER_TLV_IE, tag=0x80):
92 _construct = GreedyString("utf8")
Harald Weltec91085e2022-02-10 18:05:45 +010093
Harald Welte6169c722022-02-12 09:05:15 +010094 def __init__(self, fid='6f05', sfid=0x05, name='EF.DOMAIN', desc='Home Network Domain Name', **kwargs):
95 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +020096 self._tlv = EF_DOMAIN.domain
Harald Welteb2edd142021-01-08 23:29:35 +010097
98# TS 31.103 Section 4.2.4
99class EF_IMPU(LinFixedEF):
Harald Welte14105dc2021-05-31 08:48:51 +0200100 class impu(BER_TLV_IE, tag=0x80):
101 _construct = GreedyString("utf8")
Harald Weltec91085e2022-02-10 18:05:45 +0100102
Harald Welte6169c722022-02-12 09:05:15 +0100103 def __init__(self, fid='6f04', sfid=0x04, name='EF.IMPU', desc='IMS public user identity', **kwargs):
104 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200105 self._tlv = EF_IMPU.impu
Harald Welteb2edd142021-01-08 23:29:35 +0100106
Harald Welte6ca2fa72022-02-12 16:29:31 +0100107# TS 31.103 Section 4.2.7
108class EF_IST(EF_UServiceTable):
109 def __init__(self, **kwargs):
110 super().__init__('6f07', 0x07, 'EF.IST', 'ISIM Service Table', {1, None}, EF_IST_map)
111 # add those commands to the general commands of a TransparentEF
112 self.shell_commands += [self.AddlShellCommands()]
113
114 @with_default_category('File-Specific Commands')
115 class AddlShellCommands(CommandSet):
116 def __init__(self):
117 super().__init__()
118
119 def do_ist_service_activate(self, arg):
120 """Activate a service within EF.IST"""
121 self._cmd.card.update_ist(int(arg), 1)
122
123 def do_ist_service_deactivate(self, arg):
124 """Deactivate a service within EF.IST"""
125 self._cmd.card.update_ist(int(arg), 0)
126
127 def do_ist_service_check(self, arg):
Harald Welte3bb516b2022-02-12 21:53:18 +0100128 """Check consistency between services of this file and files present/activated.
129
130 Many services determine if one or multiple files shall be present/activated or if they shall be
131 absent/deactivated. This performs a consistency check to ensure that no services are activated
132 for files that are not - and vice-versa, no files are activated for services that are not. Error
133 messages are printed for every inconsistency found."""
Harald Welte6ca2fa72022-02-12 16:29:31 +0100134 selected_file = self._cmd.rs.selected_file
Harald Welte3bb516b2022-02-12 21:53:18 +0100135 num_problems = selected_file.ust_service_check(self._cmd)
136 self._cmd.poutput("===> %u service / file inconsistencies detected" % num_problems)
137
Harald Welte6ca2fa72022-02-12 16:29:31 +0100138
Harald Welteb2edd142021-01-08 23:29:35 +0100139# TS 31.103 Section 4.2.8
140class EF_PCSCF(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100141 def __init__(self, fid='6f09', sfid=None, name='EF.P-CSCF', desc='P-CSCF Address', **kwargs):
142 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Weltec91085e2022-02-10 18:05:45 +0100143
Harald Welteb2edd142021-01-08 23:29:35 +0100144 def _decode_record_hex(self, raw_hex):
Philipp Maier86b09da2021-04-30 15:13:57 +0200145 addr, addr_type = dec_addr_tlv(raw_hex)
146 return {"addr": addr, "addr_type": addr_type}
Harald Weltec91085e2022-02-10 18:05:45 +0100147
Harald Welteb2edd142021-01-08 23:29:35 +0100148 def _encode_record_hex(self, json_in):
Philipp Maier86b09da2021-04-30 15:13:57 +0200149 addr = json_in['addr']
150 addr_type = json_in['addr_type']
151 return enc_addr_tlv(addr, addr_type)
Harald Welteb2edd142021-01-08 23:29:35 +0100152
153# TS 31.103 Section 4.2.9
Harald Welte89e59542021-04-02 21:33:13 +0200154class EF_GBABP(TransparentEF):
Harald Welte6169c722022-02-12 09:05:15 +0100155 def __init__(self, fid='6fd5', sfid=None, name='EF.GBABP', desc='GBA Bootstrapping', **kwargs):
156 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welteb2edd142021-01-08 23:29:35 +0100157
158# TS 31.103 Section 4.2.10
159class EF_GBANL(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100160 def __init__(self, fid='6fd7', sfid=None, name='EF.GBANL', desc='GBA NAF List', **kwargs):
161 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welteb2edd142021-01-08 23:29:35 +0100162
163# TS 31.103 Section 4.2.11
164class EF_NAFKCA(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100165 def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', desc='NAF Key Centre Address', **kwargs):
166 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welteb2edd142021-01-08 23:29:35 +0100167
168# TS 31.103 Section 4.2.16
169class EF_UICCIARI(LinFixedEF):
Harald Welte14105dc2021-05-31 08:48:51 +0200170 class iari(BER_TLV_IE, tag=0x80):
171 _construct = GreedyString("utf8")
Harald Weltec91085e2022-02-10 18:05:45 +0100172
Harald Welte6169c722022-02-12 09:05:15 +0100173 def __init__(self, fid='6fe7', sfid=None, name='EF.UICCIARI', desc='UICC IARI', **kwargs):
174 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200175 self._tlv = EF_UICCIARI.iari
Harald Welteb2edd142021-01-08 23:29:35 +0100176
177# TS 31.103 Section 4.2.18
Harald Welte27881622021-04-21 11:16:31 +0200178class EF_IMSConfigData(BerTlvEF):
Harald Welte226b8662022-02-13 11:53:08 +0100179 class ImsConfigDataEncoding(BER_TLV_IE, tag=0x80):
180 _construct = HexAdapter(Bytes(1))
181 class ImsConfigData(BER_TLV_IE, tag=0x81):
182 _construct = GreedyString
183 # pylint: disable=undefined-variable
184 class ImsConfigDataCollection(TLV_IE_Collection, neted=[ImsConfigDataEncoding, ImsConfigData]):
185 pass
Harald Welte6169c722022-02-12 09:05:15 +0100186 def __init__(self, fid='6ff8', sfid=None, name='EF.IMSConfigData', desc='IMS Configuration Data', **kwargs):
187 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte226b8662022-02-13 11:53:08 +0100188 self._tlv = EF_IMSConfigData.ImsConfigDataCollection
Harald Welteb2edd142021-01-08 23:29:35 +0100189
190# TS 31.103 Section 4.2.19
Harald Welte27881622021-04-21 11:16:31 +0200191class EF_XCAPConfigData(BerTlvEF):
Harald Welte226b8662022-02-13 11:53:08 +0100192 class Access(BER_TLV_IE, tag=0x81):
193 pass
194 class ApplicationName(BER_TLV_IE, tag=0x82):
195 pass
196 class ProviderID(BER_TLV_IE, tag=0x83):
197 pass
198 class URI(BER_TLV_IE, tag=0x84):
199 pass
200 class XcapAuthenticationUserName(BER_TLV_IE, tag=0x85):
201 pass
202 class XcapAuthenticationPassword(BER_TLV_IE, tag=0x86):
203 pass
204 class XcapAuthenticationType(BER_TLV_IE, tag=0x87):
205 pass
206 class AddressType(BER_TLV_IE, tag=0x88):
207 pass
208 class Address(BER_TLV_IE, tag=0x89):
209 pass
210 class PDPAuthenticationType(BER_TLV_IE, tag=0x8a):
211 pass
212 class PDPAuthenticationName(BER_TLV_IE, tag=0x8b):
213 pass
214 class PDPAuthenticationSecret(BER_TLV_IE, tag=0x8c):
215 pass
216
217 class AccessForXCAP(BER_TLV_IE, tag=0x81):
218 pass
219 class NumberOfXcapConnParPolicy(BER_TLV_IE, tag=0x82):
220 _construct = Int8ub
221 # pylint: disable=undefined-variable
222 class XcapConnParamsPolicyPart(BER_TLV_IE, tag=0xa1, nested=[Access, ApplicationName, ProviderID, URI,
223 XcapAuthenticationUserName, XcapAuthenticationPassword,
224 XcapAuthenticationType, AddressType, Address, PDPAuthenticationType,
225 PDPAuthenticationName, PDPAuthenticationSecret]):
226 pass
227 class XcapConnParamsPolicy(BER_TLV_IE, tag=0xa0, nested=[AccessForXCAP, NumberOfXcapConnParPolicy, XcapConnParamsPolicyPart]):
228 pass
229 class XcapConnParamsPolicyDO(BER_TLV_IE, tag=0x80, nested=[XcapConnParamsPolicy]):
230 pass
Harald Welte6169c722022-02-12 09:05:15 +0100231 def __init__(self, fid='6ffc', sfid=None, name='EF.XCAPConfigData', desc='XCAP Configuration Data', **kwargs):
232 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte226b8662022-02-13 11:53:08 +0100233 self._tlv = EF_XCAPConfigData.XcapConnParamsPolicy
Harald Welteb2edd142021-01-08 23:29:35 +0100234
235# TS 31.103 Section 4.2.20
236class EF_WebRTCURI(TransparentEF):
Harald Welte14105dc2021-05-31 08:48:51 +0200237 class uri(BER_TLV_IE, tag=0x80):
238 _construct = GreedyString("utf8")
Harald Weltec91085e2022-02-10 18:05:45 +0100239
Harald Welte6169c722022-02-12 09:05:15 +0100240 def __init__(self, fid='6ffa', sfid=None, name='EF.WebRTCURI', desc='WebRTC URI', **kwargs):
241 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200242 self._tlv = EF_WebRTCURI.uri
Harald Welteb2edd142021-01-08 23:29:35 +0100243
Harald Welte16ec96a2021-04-21 10:46:19 +0200244# TS 31.103 Section 4.2.21
Harald Welte27881622021-04-21 11:16:31 +0200245class EF_MuDMiDConfigData(BerTlvEF):
Harald Welte226b8662022-02-13 11:53:08 +0100246 class MudMidConfigDataEncoding(BER_TLV_IE, tag=0x80):
247 _construct = HexAdapter(Bytes(1))
248 class MudMidConfigData(BER_TLV_IE, tag=0x81):
249 _construct = GreedyString
250 # pylint: disable=undefined-variable
251 class MudMidConfigDataCollection(TLV_IE_Collection, neted=[MudMidConfigDataEncoding, MudMidConfigData]):
252 pass
Harald Welte16ec96a2021-04-21 10:46:19 +0200253 def __init__(self, fid='6ffe', sfid=None, name='EF.MuDMiDConfigData',
Harald Welte6169c722022-02-12 09:05:15 +0100254 desc='MuD and MiD Configuration Data', **kwargs):
255 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte226b8662022-02-13 11:53:08 +0100256 self._tlv = EF_MuDMiDConfigData.MudMidConfigDataCollection
Harald Welte16ec96a2021-04-21 10:46:19 +0200257
Harald Welteb2edd142021-01-08 23:29:35 +0100258
259class ADF_ISIM(CardADF):
260 def __init__(self, aid='a0000000871004', name='ADF.ISIM', fid=None, sfid=None,
261 desc='ISIM Application'):
262 super().__init__(aid=aid, fid=fid, sfid=sfid, name=name, desc=desc)
263
264 files = [
265 EF_IMPI(),
266 EF_DOMAIN(),
267 EF_IMPU(),
268 EF_AD(),
Harald Weltefc4833e2021-05-02 21:46:06 +0200269 EF_ARR('6f06', 0x06),
Harald Welte6ca2fa72022-02-12 16:29:31 +0100270 EF_IST(),
Harald Welte6169c722022-02-12 09:05:15 +0100271 EF_PCSCF(service=5),
272 EF_GBABP(service=2),
273 EF_GBANL(service=2),
274 EF_NAFKCA(service=2),
275 EF_SMS(service=(6,8)),
276 EF_SMSS(service=(6,8)),
277 EF_SMSR(service=(7,8)),
278 EF_SMSP(service=8),
279 EF_UICCIARI(service=10),
280 EF_FromPreferred(service=17),
281 EF_IMSConfigData(service=18),
282 EF_XCAPConfigData(service=19),
283 EF_WebRTCURI(service=20),
284 EF_MuDMiDConfigData(service=21),
Harald Weltec91085e2022-02-10 18:05:45 +0100285 ]
Harald Welteb2edd142021-01-08 23:29:35 +0100286 self.add_files(files)
Harald Welte15fae982021-04-10 10:22:27 +0200287 # add those commands to the general commands of a TransparentEF
288 self.shell_commands += [ADF_USIM.AddlShellCommands()]
Harald Welteb2edd142021-01-08 23:29:35 +0100289
290 def decode_select_response(self, data_hex):
Philipp Maier5998a3a2021-11-16 15:16:39 +0100291 return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex)
Harald Welteb2edd142021-01-08 23:29:35 +0100292
Harald Weltec91085e2022-02-10 18:05:45 +0100293
Harald Welteb2edd142021-01-08 23:29:35 +0100294# TS 31.103 Section 7.1
295sw_isim = {
296 'Security management': {
297 '9862': 'Authentication error, incorrect MAC',
298 '9864': 'Authentication error, security context not supported',
299 }
300}
301
Harald Weltec91085e2022-02-10 18:05:45 +0100302
Philipp Maier57f65ee2021-10-18 14:09:02 +0200303class CardApplicationISIM(CardApplication):
304 def __init__(self):
Harald Weltec91085e2022-02-10 18:05:45 +0100305 super().__init__('ISIM', adf=ADF_ISIM(), sw=sw_isim)