blob: df91ea1284c8944f6081a69fb2c470d5288e8c7e [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 Welte6f8a8702022-07-17 21:50:31 +020029from pySim.ts_31_102 import ADF_USIM, EF_FromPreferred
30from pySim.ts_31_102_telecom import EF_UServiceTable
Harald Welteb2edd142021-01-08 23:29:35 +010031import pySim.ts_102_221
Harald Weltefc4833e2021-05-02 21:46:06 +020032from pySim.ts_102_221 import EF_ARR
Philipp Maier791f80a2023-07-26 17:01:37 +020033from pySim.construct import *
Harald Welteb2edd142021-01-08 23:29:35 +010034
Supreeth Herle8b72c272020-03-22 08:55:50 +010035# Mapping between ISIM Service Number and its description
36EF_IST_map = {
Harald Weltec91085e2022-02-10 18:05:45 +010037 1: 'P-CSCF address',
38 2: 'Generic Bootstrapping Architecture (GBA)',
39 3: 'HTTP Digest',
40 4: 'GBA-based Local Key Establishment Mechanism',
41 5: 'Support of P-CSCF discovery for IMS Local Break Out',
42 6: 'Short Message Storage (SMS)',
43 7: 'Short Message Status Reports (SMSR)',
44 8: 'Support for SM-over-IP including data download via SMS-PP as defined in TS 31.111 [31]',
45 9: 'Communication Control for IMS by ISIM',
46 10: 'Support of UICC access to IMS',
47 11: 'URI support by UICC',
48 12: 'Media Type support',
49 13: 'IMS call disconnection cause',
50 14: 'URI support for MO SHORT MESSAGE CONTROL',
51 15: 'MCPTT',
52 16: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [31]',
53 17: 'From Preferred',
54 18: 'IMS configuration data',
55 19: 'XCAP Configuration Data',
56 20: 'WebRTC URI',
57 21: 'MuD and MiD configuration data',
Supreeth Herle8b72c272020-03-22 08:55:50 +010058}
herlesupreeth75c14c02020-12-23 09:41:07 +010059
Harald Welteb2edd142021-01-08 23:29:35 +010060# TS 31.103 Section 4.2.2
61class EF_IMPI(TransparentEF):
Harald Weltefa9f3482023-06-26 10:51:38 +020062 _test_de_encode = [
Harald Welte865eea62023-01-27 19:26:12 +010063 ( '803137333830303630303030303031303140696d732e6d6e633030302e6d63633733382e336770706e6574776f726b2e6f7267',
64 { "nai": "738006000000101@ims.mnc000.mcc738.3gppnetwork.org" } ),
65 ]
Philipp Maier791f80a2023-07-26 17:01:37 +020066
Harald Welte14105dc2021-05-31 08:48:51 +020067 class nai(BER_TLV_IE, tag=0x80):
Philipp Maier791f80a2023-07-26 17:01:37 +020068 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +010069
Harald Welte6169c722022-02-12 09:05:15 +010070 def __init__(self, fid='6f02', sfid=0x02, name='EF.IMPI', desc='IMS private user identity', **kwargs):
71 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +020072 self._tlv = EF_IMPI.nai
Harald Welteb2edd142021-01-08 23:29:35 +010073
74# TS 31.103 Section 4.2.3
75class EF_DOMAIN(TransparentEF):
Harald Weltefa9f3482023-06-26 10:51:38 +020076 _test_de_encode = [
Harald Welte865eea62023-01-27 19:26:12 +010077 ( '8021696d732e6d6e633030302e6d63633733382e336770706e6574776f726b2e6f7267',
78 { "domain": "ims.mnc000.mcc738.3gppnetwork.org" } ),
79 ]
Harald Welte14105dc2021-05-31 08:48:51 +020080 class domain(BER_TLV_IE, tag=0x80):
Philipp Maier791f80a2023-07-26 17:01:37 +020081 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +010082
æstrid smithb7f35ac2022-03-26 19:59:54 -070083 def __init__(self, fid='6f03', sfid=0x05, name='EF.DOMAIN', desc='Home Network Domain Name', **kwargs):
Harald Welte6169c722022-02-12 09:05:15 +010084 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +020085 self._tlv = EF_DOMAIN.domain
Harald Welteb2edd142021-01-08 23:29:35 +010086
87# TS 31.103 Section 4.2.4
88class EF_IMPU(LinFixedEF):
Harald Weltefa9f3482023-06-26 10:51:38 +020089 _test_de_encode = [
Harald Welte865eea62023-01-27 19:26:12 +010090 ( '80357369703a37333830303630303030303031303140696d732e6d6e633030302e6d63633733382e336770706e6574776f726b2e6f7267',
91 { "impu": "sip:738006000000101@ims.mnc000.mcc738.3gppnetwork.org" } ),
92 ]
Harald Welte14105dc2021-05-31 08:48:51 +020093 class impu(BER_TLV_IE, tag=0x80):
Philipp Maier791f80a2023-07-26 17:01:37 +020094 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +010095
Harald Welte6169c722022-02-12 09:05:15 +010096 def __init__(self, fid='6f04', sfid=0x04, name='EF.IMPU', desc='IMS public user identity', **kwargs):
97 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +020098 self._tlv = EF_IMPU.impu
Harald Welteb2edd142021-01-08 23:29:35 +010099
Harald Welte6ca2fa72022-02-12 16:29:31 +0100100# TS 31.103 Section 4.2.7
101class EF_IST(EF_UServiceTable):
102 def __init__(self, **kwargs):
Harald Welte13edf302022-07-21 15:19:23 +0200103 super().__init__('6f07', 0x07, 'EF.IST', 'ISIM Service Table', (1, None), EF_IST_map)
Harald Welte6ca2fa72022-02-12 16:29:31 +0100104 # add those commands to the general commands of a TransparentEF
105 self.shell_commands += [self.AddlShellCommands()]
106
107 @with_default_category('File-Specific Commands')
108 class AddlShellCommands(CommandSet):
109 def __init__(self):
110 super().__init__()
111
112 def do_ist_service_activate(self, arg):
113 """Activate a service within EF.IST"""
Alexander Couzensc8facea2023-07-29 05:01:57 +0200114 selected_file = self._cmd.lchan.selected_file
115 selected_file.ust_update(self._cmd, [int(arg)], [])
Harald Welte6ca2fa72022-02-12 16:29:31 +0100116
117 def do_ist_service_deactivate(self, arg):
118 """Deactivate a service within EF.IST"""
Alexander Couzensc8facea2023-07-29 05:01:57 +0200119 selected_file = self._cmd.lchan.selected_file
120 selected_file.ust_update(self._cmd, [], [int(arg)])
Harald Welte6ca2fa72022-02-12 16:29:31 +0100121
122 def do_ist_service_check(self, arg):
Harald Welte3bb516b2022-02-12 21:53:18 +0100123 """Check consistency between services of this file and files present/activated.
124
125 Many services determine if one or multiple files shall be present/activated or if they shall be
126 absent/deactivated. This performs a consistency check to ensure that no services are activated
127 for files that are not - and vice-versa, no files are activated for services that are not. Error
128 messages are printed for every inconsistency found."""
Harald Weltea6c0f882022-07-17 14:23:17 +0200129 selected_file = self._cmd.lchan.selected_file
Harald Welte3bb516b2022-02-12 21:53:18 +0100130 num_problems = selected_file.ust_service_check(self._cmd)
131 self._cmd.poutput("===> %u service / file inconsistencies detected" % num_problems)
132
Harald Welte6ca2fa72022-02-12 16:29:31 +0100133
Harald Welteb2edd142021-01-08 23:29:35 +0100134# TS 31.103 Section 4.2.8
135class EF_PCSCF(LinFixedEF):
Harald Welte865eea62023-01-27 19:26:12 +0100136 _test_de_encode = [
137 ( '802c0070637363662e696d732e6d6e633030302e6d63633733382e7075622e336770706e6574776f726b2e6f7267',
Harald Welte301d6ed2023-12-08 15:06:29 +0100138 {'pcscf_address': { "address": "pcscf.ims.mnc000.mcc738.pub.3gppnetwork.org", "type_of_address": "FQDN" } } ),
Harald Welte324175f2023-12-21 20:25:30 +0100139 ( '800501c0a80c22',
140 {'pcscf_address': { "address": "192.168.12.34", "type_of_address": "IPv4" } } ),
141 ( '801102fe800000000000000042d7fffe530335',
142 {'pcscf_address': { "address": "fe80::42:d7ff:fe53:335", "type_of_address": "IPv6" } } ),
Harald Welte865eea62023-01-27 19:26:12 +0100143 ]
Harald Welte301d6ed2023-12-08 15:06:29 +0100144 class PcscfAddress(BER_TLV_IE, tag=0x80):
145 _construct = Struct('type_of_address'/Enum(Byte, FQDN=0, IPv4=1, IPv6=2),
146 'address'/Switch(this.type_of_address,
147 {'FQDN': Utf8Adapter(GreedyBytes),
148 'IPv4': Ipv4Adapter(GreedyBytes),
149 'IPv6': Ipv6Adapter(GreedyBytes)}))
150
Harald Welte6169c722022-02-12 09:05:15 +0100151 def __init__(self, fid='6f09', sfid=None, name='EF.P-CSCF', desc='P-CSCF Address', **kwargs):
152 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte301d6ed2023-12-08 15:06:29 +0100153 self._tlv = EF_PCSCF.PcscfAddress
Harald Welteb2edd142021-01-08 23:29:35 +0100154
155# TS 31.103 Section 4.2.9
Harald Welte89e59542021-04-02 21:33:13 +0200156class EF_GBABP(TransparentEF):
Harald Welte6169c722022-02-12 09:05:15 +0100157 def __init__(self, fid='6fd5', sfid=None, name='EF.GBABP', desc='GBA Bootstrapping', **kwargs):
158 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welteb2edd142021-01-08 23:29:35 +0100159
160# TS 31.103 Section 4.2.10
161class EF_GBANL(LinFixedEF):
Harald Welte6169c722022-02-12 09:05:15 +0100162 def __init__(self, fid='6fd7', sfid=None, name='EF.GBANL', desc='GBA NAF List', **kwargs):
163 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welteb2edd142021-01-08 23:29:35 +0100164
165# TS 31.103 Section 4.2.11
166class EF_NAFKCA(LinFixedEF):
Harald Welte865eea62023-01-27 19:26:12 +0100167 # TODO: 80296273662e696d732e6d6e633030302e6d63633733382e7075622e336770706e6574776f726b2e6f7267ffffffffffffff
168 # TODO: 8030656e65746e61667830312e696d732e6d6e633030302e6d63633733382e7075622e336770706e6574776f726b2e6f7267
Harald Welte6169c722022-02-12 09:05:15 +0100169 def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', desc='NAF Key Centre Address', **kwargs):
170 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welteb2edd142021-01-08 23:29:35 +0100171
172# TS 31.103 Section 4.2.16
173class EF_UICCIARI(LinFixedEF):
Harald Welte14105dc2021-05-31 08:48:51 +0200174 class iari(BER_TLV_IE, tag=0x80):
Philipp Maier791f80a2023-07-26 17:01:37 +0200175 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100176
Harald Welte6169c722022-02-12 09:05:15 +0100177 def __init__(self, fid='6fe7', sfid=None, name='EF.UICCIARI', desc='UICC IARI', **kwargs):
178 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200179 self._tlv = EF_UICCIARI.iari
Harald Welteb2edd142021-01-08 23:29:35 +0100180
181# TS 31.103 Section 4.2.18
Harald Welte27881622021-04-21 11:16:31 +0200182class EF_IMSConfigData(BerTlvEF):
Harald Welte226b8662022-02-13 11:53:08 +0100183 class ImsConfigDataEncoding(BER_TLV_IE, tag=0x80):
184 _construct = HexAdapter(Bytes(1))
185 class ImsConfigData(BER_TLV_IE, tag=0x81):
186 _construct = GreedyString
187 # pylint: disable=undefined-variable
Harald Welteafe093c2022-07-17 21:39:51 +0200188 class ImsConfigDataCollection(TLV_IE_Collection, nested=[ImsConfigDataEncoding, ImsConfigData]):
Harald Welte226b8662022-02-13 11:53:08 +0100189 pass
Harald Welte6169c722022-02-12 09:05:15 +0100190 def __init__(self, fid='6ff8', sfid=None, name='EF.IMSConfigData', desc='IMS Configuration Data', **kwargs):
191 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte226b8662022-02-13 11:53:08 +0100192 self._tlv = EF_IMSConfigData.ImsConfigDataCollection
Harald Welteb2edd142021-01-08 23:29:35 +0100193
194# TS 31.103 Section 4.2.19
Harald Welte27881622021-04-21 11:16:31 +0200195class EF_XCAPConfigData(BerTlvEF):
Harald Welte226b8662022-02-13 11:53:08 +0100196 class Access(BER_TLV_IE, tag=0x81):
197 pass
198 class ApplicationName(BER_TLV_IE, tag=0x82):
199 pass
200 class ProviderID(BER_TLV_IE, tag=0x83):
201 pass
202 class URI(BER_TLV_IE, tag=0x84):
203 pass
204 class XcapAuthenticationUserName(BER_TLV_IE, tag=0x85):
205 pass
206 class XcapAuthenticationPassword(BER_TLV_IE, tag=0x86):
207 pass
208 class XcapAuthenticationType(BER_TLV_IE, tag=0x87):
209 pass
210 class AddressType(BER_TLV_IE, tag=0x88):
211 pass
212 class Address(BER_TLV_IE, tag=0x89):
213 pass
214 class PDPAuthenticationType(BER_TLV_IE, tag=0x8a):
215 pass
216 class PDPAuthenticationName(BER_TLV_IE, tag=0x8b):
217 pass
218 class PDPAuthenticationSecret(BER_TLV_IE, tag=0x8c):
219 pass
220
221 class AccessForXCAP(BER_TLV_IE, tag=0x81):
222 pass
223 class NumberOfXcapConnParPolicy(BER_TLV_IE, tag=0x82):
224 _construct = Int8ub
225 # pylint: disable=undefined-variable
226 class XcapConnParamsPolicyPart(BER_TLV_IE, tag=0xa1, nested=[Access, ApplicationName, ProviderID, URI,
227 XcapAuthenticationUserName, XcapAuthenticationPassword,
228 XcapAuthenticationType, AddressType, Address, PDPAuthenticationType,
229 PDPAuthenticationName, PDPAuthenticationSecret]):
230 pass
231 class XcapConnParamsPolicy(BER_TLV_IE, tag=0xa0, nested=[AccessForXCAP, NumberOfXcapConnParPolicy, XcapConnParamsPolicyPart]):
232 pass
233 class XcapConnParamsPolicyDO(BER_TLV_IE, tag=0x80, nested=[XcapConnParamsPolicy]):
234 pass
Harald Welte6169c722022-02-12 09:05:15 +0100235 def __init__(self, fid='6ffc', sfid=None, name='EF.XCAPConfigData', desc='XCAP Configuration Data', **kwargs):
236 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte226b8662022-02-13 11:53:08 +0100237 self._tlv = EF_XCAPConfigData.XcapConnParamsPolicy
Harald Welteb2edd142021-01-08 23:29:35 +0100238
239# TS 31.103 Section 4.2.20
240class EF_WebRTCURI(TransparentEF):
Harald Welte14105dc2021-05-31 08:48:51 +0200241 class uri(BER_TLV_IE, tag=0x80):
Philipp Maier791f80a2023-07-26 17:01:37 +0200242 _construct = Utf8Adapter(GreedyBytes)
Harald Weltec91085e2022-02-10 18:05:45 +0100243
Harald Welte6169c722022-02-12 09:05:15 +0100244 def __init__(self, fid='6ffa', sfid=None, name='EF.WebRTCURI', desc='WebRTC URI', **kwargs):
245 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte14105dc2021-05-31 08:48:51 +0200246 self._tlv = EF_WebRTCURI.uri
Harald Welteb2edd142021-01-08 23:29:35 +0100247
Harald Welte16ec96a2021-04-21 10:46:19 +0200248# TS 31.103 Section 4.2.21
Harald Welte27881622021-04-21 11:16:31 +0200249class EF_MuDMiDConfigData(BerTlvEF):
Harald Welte226b8662022-02-13 11:53:08 +0100250 class MudMidConfigDataEncoding(BER_TLV_IE, tag=0x80):
251 _construct = HexAdapter(Bytes(1))
252 class MudMidConfigData(BER_TLV_IE, tag=0x81):
253 _construct = GreedyString
254 # pylint: disable=undefined-variable
Harald Welteafe093c2022-07-17 21:39:51 +0200255 class MudMidConfigDataCollection(TLV_IE_Collection, nested=[MudMidConfigDataEncoding, MudMidConfigData]):
Harald Welte226b8662022-02-13 11:53:08 +0100256 pass
Harald Welte16ec96a2021-04-21 10:46:19 +0200257 def __init__(self, fid='6ffe', sfid=None, name='EF.MuDMiDConfigData',
Harald Welte6169c722022-02-12 09:05:15 +0100258 desc='MuD and MiD Configuration Data', **kwargs):
259 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, **kwargs)
Harald Welte226b8662022-02-13 11:53:08 +0100260 self._tlv = EF_MuDMiDConfigData.MudMidConfigDataCollection
Harald Welte16ec96a2021-04-21 10:46:19 +0200261
Harald Welteb2edd142021-01-08 23:29:35 +0100262
263class ADF_ISIM(CardADF):
Philipp Maiera1850ae2023-10-25 18:05:09 +0200264 def __init__(self, aid='a0000000871004', has_fs=True, name='ADF.ISIM', fid=None, sfid=None,
Harald Welteb2edd142021-01-08 23:29:35 +0100265 desc='ISIM Application'):
Philipp Maiera1850ae2023-10-25 18:05:09 +0200266 super().__init__(aid=aid, has_fs=has_fs, fid=fid, sfid=sfid, name=name, desc=desc)
Harald Welteb2edd142021-01-08 23:29:35 +0100267
268 files = [
269 EF_IMPI(),
270 EF_DOMAIN(),
271 EF_IMPU(),
272 EF_AD(),
Harald Weltefc4833e2021-05-02 21:46:06 +0200273 EF_ARR('6f06', 0x06),
Harald Welte6ca2fa72022-02-12 16:29:31 +0100274 EF_IST(),
Harald Welte6169c722022-02-12 09:05:15 +0100275 EF_PCSCF(service=5),
276 EF_GBABP(service=2),
277 EF_GBANL(service=2),
278 EF_NAFKCA(service=2),
279 EF_SMS(service=(6,8)),
280 EF_SMSS(service=(6,8)),
281 EF_SMSR(service=(7,8)),
282 EF_SMSP(service=8),
283 EF_UICCIARI(service=10),
284 EF_FromPreferred(service=17),
285 EF_IMSConfigData(service=18),
286 EF_XCAPConfigData(service=19),
287 EF_WebRTCURI(service=20),
288 EF_MuDMiDConfigData(service=21),
Harald Weltec91085e2022-02-10 18:05:45 +0100289 ]
Harald Welteb2edd142021-01-08 23:29:35 +0100290 self.add_files(files)
Harald Welte15fae982021-04-10 10:22:27 +0200291 # add those commands to the general commands of a TransparentEF
292 self.shell_commands += [ADF_USIM.AddlShellCommands()]
Harald Welteb2edd142021-01-08 23:29:35 +0100293
294 def decode_select_response(self, data_hex):
Philipp Maier5998a3a2021-11-16 15:16:39 +0100295 return pySim.ts_102_221.CardProfileUICC.decode_select_response(data_hex)
Harald Welteb2edd142021-01-08 23:29:35 +0100296
Harald Weltec91085e2022-02-10 18:05:45 +0100297
Harald Welteb2edd142021-01-08 23:29:35 +0100298# TS 31.103 Section 7.1
299sw_isim = {
300 'Security management': {
301 '9862': 'Authentication error, incorrect MAC',
302 '9864': 'Authentication error, security context not supported',
303 }
304}
305
Harald Weltec91085e2022-02-10 18:05:45 +0100306
Philipp Maier57f65ee2021-10-18 14:09:02 +0200307class CardApplicationISIM(CardApplication):
308 def __init__(self):
Harald Weltec91085e2022-02-10 18:05:45 +0100309 super().__init__('ISIM', adf=ADF_ISIM(), sw=sw_isim)