blob: 5ca827926fb912448ebb90e0cbeebfce76f32110 [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 Welte35dfe822021-04-21 10:50:12 +020027from pySim.ts_51_011 import EF_AD, EF_SMS, EF_SMSS, EF_SMSR, EF_SMSP
Harald Welte71290072021-04-21 10:58:24 +020028from pySim.ts_31_102 import ADF_USIM, EF_FromPreferred
Harald Welteb2edd142021-01-08 23:29:35 +010029import pySim.ts_102_221
Harald Weltefc4833e2021-05-02 21:46:06 +020030from pySim.ts_102_221 import EF_ARR
Harald Welteb2edd142021-01-08 23:29:35 +010031
Supreeth Herle8b72c272020-03-22 08:55:50 +010032# Mapping between ISIM Service Number and its description
33EF_IST_map = {
34 1: 'P-CSCF address',
35 2: 'Generic Bootstrapping Architecture (GBA)',
36 3: 'HTTP Digest',
37 4: 'GBA-based Local Key Establishment Mechanism',
38 5: 'Support of P-CSCF discovery for IMS Local Break Out',
39 6: 'Short Message Storage (SMS)',
40 7: 'Short Message Status Reports (SMSR)',
41 8: 'Support for SM-over-IP including data download via SMS-PP as defined in TS 31.111 [31]',
42 9: 'Communication Control for IMS by ISIM',
43 10: 'Support of UICC access to IMS',
44 11: 'URI support by UICC',
45 12: 'Media Type support',
46 13: 'IMS call disconnection cause',
47 14: 'URI support for MO SHORT MESSAGE CONTROL',
48 15: 'MCPTT',
49 16: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [31]',
50 17: 'From Preferred',
51 18: 'IMS configuration data',
Supreeth Herle28484d02020-03-25 15:00:20 +010052 19: 'XCAP Configuration Data',
53 20: 'WebRTC URI',
Harald Welte16ec96a2021-04-21 10:46:19 +020054 21: 'MuD and MiD configuration data',
Supreeth Herle8b72c272020-03-22 08:55:50 +010055}
herlesupreeth75c14c02020-12-23 09:41:07 +010056
57EF_ISIM_ADF_map = {
58 'IST': '6F07',
59 'IMPI': '6F02',
60 'DOMAIN': '6F03',
61 'IMPU': '6F04',
62 'AD': '6FAD',
63 'ARR': '6F06',
64 'PCSCF': '6F09',
65 'GBAP': '6FD5',
66 'GBANL': '6FD7',
67 'NAFKCA': '6FDD',
68 'UICCIARI': '6FE7',
69 'SMS': '6F3C',
70 'SMSS': '6F43',
71 'SMSR': '6F47',
72 'SMSP': '6F42',
73 'FromPreferred': '6FF7',
74 'IMSConfigData': '6FF8',
75 'XCAPConfigData': '6FFC',
76 'WebRTCURI': '6FFA'
77}
Harald Welteb2edd142021-01-08 23:29:35 +010078
79# TS 31.103 Section 4.2.2
80class EF_IMPI(TransparentEF):
81 def __init__(self, fid='6f02', sfid=0x02, name='EF.IMPI', desc='IMS private user identity'):
82 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
83
84# TS 31.103 Section 4.2.3
85class EF_DOMAIN(TransparentEF):
86 def __init__(self, fid='6f05', sfid=0x05, name='EF.DOMAIN', desc='Home Network Domain Name'):
87 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
88
89# TS 31.103 Section 4.2.4
90class EF_IMPU(LinFixedEF):
91 def __init__(self, fid='6f04', sfid=0x04, name='EF.IMPU', desc='IMS public user identity'):
92 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
93
Harald Welteb2edd142021-01-08 23:29:35 +010094# TS 31.103 Section 4.2.7
95class EF_IST(TransparentEF):
96 def __init__(self, fid='6f07', sfid=0x07, name='EF.IST', desc='ISIM Service Table'):
97 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, size={1,4})
98 # add those commands to the general commands of a TransparentEF
99 self.shell_commands += [self.AddlShellCommands()]
100
101 @with_default_category('File-Specific Commands')
102 class AddlShellCommands(CommandSet):
103 def __init__(self):
104 super().__init__()
105
106 def do_ist_service_activate(self, arg):
107 """Activate a service within EF.IST"""
108 self._cmd.card.update_ist(int(arg), 1)
109
110 def do_ist_service_deactivate(self, arg):
111 """Deactivate a service within EF.IST"""
112 self._cmd.card.update_ist(int(arg), 0)
113
114# TS 31.103 Section 4.2.8
115class EF_PCSCF(LinFixedEF):
116 def __init__(self, fid='6f09', sfid=None, name='EF.P-CSCF', desc='P-CSCF Address'):
117 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
118 def _decode_record_hex(self, raw_hex):
Philipp Maier86b09da2021-04-30 15:13:57 +0200119 addr, addr_type = dec_addr_tlv(raw_hex)
120 return {"addr": addr, "addr_type": addr_type}
Harald Welteb2edd142021-01-08 23:29:35 +0100121 def _encode_record_hex(self, json_in):
Philipp Maier86b09da2021-04-30 15:13:57 +0200122 addr = json_in['addr']
123 addr_type = json_in['addr_type']
124 return enc_addr_tlv(addr, addr_type)
Harald Welteb2edd142021-01-08 23:29:35 +0100125
126# TS 31.103 Section 4.2.9
Harald Welte89e59542021-04-02 21:33:13 +0200127class EF_GBABP(TransparentEF):
Harald Weltec9cdce32021-04-11 10:28:28 +0200128 def __init__(self, fid='6fd5', sfid=None, name='EF.GBABP', desc='GBA Bootstrapping'):
Harald Welteb2edd142021-01-08 23:29:35 +0100129 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
130
131# TS 31.103 Section 4.2.10
132class EF_GBANL(LinFixedEF):
133 def __init__(self, fid='6fd7', sfid=None, name='EF.GBANL', desc='GBA NAF List'):
134 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
135
136# TS 31.103 Section 4.2.11
137class EF_NAFKCA(LinFixedEF):
138 def __init__(self, fid='6fdd', sfid=None, name='EF.NAFKCA', desc='NAF Key Centre Address'):
139 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
140
141# TS 31.103 Section 4.2.16
142class EF_UICCIARI(LinFixedEF):
143 def __init__(self, fid='6fe7', sfid=None, name='EF.UICCIARI', desc='UICC IARI'):
144 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
145
146# TS 31.103 Section 4.2.18
Harald Welte27881622021-04-21 11:16:31 +0200147class EF_IMSConfigData(BerTlvEF):
Harald Welteb2edd142021-01-08 23:29:35 +0100148 def __init__(self, fid='6ff8', sfid=None, name='EF.IMSConfigData', desc='IMS Configuration Data'):
149 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
150
151# TS 31.103 Section 4.2.19
Harald Welte27881622021-04-21 11:16:31 +0200152class EF_XCAPConfigData(BerTlvEF):
Harald Welteb2edd142021-01-08 23:29:35 +0100153 def __init__(self, fid='6ffc', sfid=None, name='EF.XCAPConfigData', desc='XCAP Configuration Data'):
154 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
155
156# TS 31.103 Section 4.2.20
157class EF_WebRTCURI(TransparentEF):
158 def __init__(self, fid='6ffa', sfid=None, name='EF.WebRTCURI', desc='WebRTC URI'):
159 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
160
Harald Welte16ec96a2021-04-21 10:46:19 +0200161# TS 31.103 Section 4.2.21
Harald Welte27881622021-04-21 11:16:31 +0200162class EF_MuDMiDConfigData(BerTlvEF):
Harald Welte16ec96a2021-04-21 10:46:19 +0200163 def __init__(self, fid='6ffe', sfid=None, name='EF.MuDMiDConfigData',
164 desc='MuD and MiD Configuration Data'):
165 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc)
166
Harald Welteb2edd142021-01-08 23:29:35 +0100167
168class ADF_ISIM(CardADF):
169 def __init__(self, aid='a0000000871004', name='ADF.ISIM', fid=None, sfid=None,
170 desc='ISIM Application'):
171 super().__init__(aid=aid, fid=fid, sfid=sfid, name=name, desc=desc)
172
173 files = [
174 EF_IMPI(),
175 EF_DOMAIN(),
176 EF_IMPU(),
177 EF_AD(),
Harald Weltefc4833e2021-05-02 21:46:06 +0200178 EF_ARR('6f06', 0x06),
Harald Welteb2edd142021-01-08 23:29:35 +0100179 EF_IST(),
180 EF_PCSCF(),
181 EF_GBABP(),
182 EF_GBANL(),
183 EF_NAFKCA(),
Harald Welte35dfe822021-04-21 10:50:12 +0200184 EF_SMS(),
185 EF_SMSS(),
186 EF_SMSR(),
187 EF_SMSP(),
Harald Welteb2edd142021-01-08 23:29:35 +0100188 EF_UICCIARI(),
Harald Welte71290072021-04-21 10:58:24 +0200189 EF_FromPreferred(),
Harald Welteb2edd142021-01-08 23:29:35 +0100190 EF_IMSConfigData(),
191 EF_XCAPConfigData(),
192 EF_WebRTCURI(),
Harald Welte16ec96a2021-04-21 10:46:19 +0200193 EF_MuDMiDConfigData(),
Harald Welteb2edd142021-01-08 23:29:35 +0100194 ]
195 self.add_files(files)
Harald Welte15fae982021-04-10 10:22:27 +0200196 # add those commands to the general commands of a TransparentEF
197 self.shell_commands += [ADF_USIM.AddlShellCommands()]
Harald Welteb2edd142021-01-08 23:29:35 +0100198
199 def decode_select_response(self, data_hex):
200 return pySim.ts_102_221.decode_select_response(data_hex)
201
202# TS 31.103 Section 7.1
203sw_isim = {
204 'Security management': {
205 '9862': 'Authentication error, incorrect MAC',
206 '9864': 'Authentication error, security context not supported',
207 }
208}
209
210CardApplicationISIM = CardApplication('ISIM', adf=ADF_ISIM(), sw=sw_isim)