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