blob: 02b0aea3ab9002a7c15592be3c280477cc0d465f [file] [log] [blame]
Supreeth Herle475dcaa2020-03-20 18:57:39 +01001# -*- coding: utf-8 -*-
2
3"""
4Various constants from ETSI TS 131 102
5"""
6
7#
8# Copyright (C) 2020 Supreeth Herle <herlesupreeth@gmail.com>
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
23
24# Mapping between USIM Service Number and its description
25EF_UST_map = {
26 1: 'Local Phone Book',
27 2: 'Fixed Dialling Numbers (FDN)',
28 3: 'Extension 2',
29 4: 'Service Dialling Numbers (SDN)',
30 5: 'Extension3',
31 6: 'Barred Dialling Numbers (BDN)',
32 7: 'Extension4',
33 8: 'Outgoing Call Information (OCI and OCT)',
34 9: 'Incoming Call Information (ICI and ICT)',
35 10: 'Short Message Storage (SMS)',
36 11: 'Short Message Status Reports (SMSR)',
37 12: 'Short Message Service Parameters (SMSP)',
38 13: 'Advice of Charge (AoC)',
39 14: 'Capability Configuration Parameters 2 (CCP2)',
40 15: 'Cell Broadcast Message Identifier',
41 16: 'Cell Broadcast Message Identifier Ranges',
42 17: 'Group Identifier Level 1',
43 18: 'Group Identifier Level 2',
44 19: 'Service Provider Name',
45 20: 'User controlled PLMN selector with Access Technology',
46 21: 'MSISDN',
47 22: 'Image (IMG)',
48 23: 'Support of Localised Service Areas (SoLSA)',
49 24: 'Enhanced Multi-Level Precedence and Pre-emption Service',
50 25: 'Automatic Answer for eMLPP',
51 26: 'RFU',
52 27: 'GSM Access',
53 28: 'Data download via SMS-PP',
54 29: 'Data download via SMS-CB',
55 30: 'Call Control by USIM',
56 31: 'MO-SMS Control by USIM',
57 32: 'RUN AT COMMAND command',
58 33: 'shall be set to 1',
59 34: 'Enabled Services Table',
60 35: 'APN Control List (ACL)',
61 36: 'Depersonalisation Control Keys',
62 37: 'Co-operative Network List',
63 38: 'GSM security context',
64 39: 'CPBCCH Information',
65 40: 'Investigation Scan',
66 41: 'MexE',
67 42: 'Operator controlled PLMN selector with Access Technology',
68 43: 'HPLMN selector with Access Technology',
69 44: 'Extension 5',
70 45: 'PLMN Network Name',
71 46: 'Operator PLMN List',
72 47: 'Mailbox Dialling Numbers',
73 48: 'Message Waiting Indication Status',
74 49: 'Call Forwarding Indication Status',
75 50: 'Reserved and shall be ignored',
76 51: 'Service Provider Display Information',
77 52: 'Multimedia Messaging Service (MMS)',
78 53: 'Extension 8',
79 54: 'Call control on GPRS by USIM',
80 55: 'MMS User Connectivity Parameters',
81 56: 'Network\'s indication of alerting in the MS (NIA)',
82 57: 'VGCS Group Identifier List (EFVGCS and EFVGCSS)',
83 58: 'VBS Group Identifier List (EFVBS and EFVBSS)',
84 59: 'Pseudonym',
85 60: 'User Controlled PLMN selector for I-WLAN access',
86 61: 'Operator Controlled PLMN selector for I-WLAN access',
87 62: 'User controlled WSID list',
88 63: 'Operator controlled WSID list',
89 64: 'VGCS security',
90 65: 'VBS security',
91 66: 'WLAN Reauthentication Identity',
92 67: 'Multimedia Messages Storage',
93 68: 'Generic Bootstrapping Architecture (GBA)',
94 69: 'MBMS security',
95 70: 'Data download via USSD and USSD application mode',
96 71: 'Equivalent HPLMN',
97 72: 'Additional TERMINAL PROFILE after UICC activation',
98 73: 'Equivalent HPLMN Presentation Indication',
99 74: 'Last RPLMN Selection Indication',
100 75: 'OMA BCAST Smart Card Profile',
101 76: 'GBA-based Local Key Establishment Mechanism',
102 77: 'Terminal Applications',
103 78: 'Service Provider Name Icon',
104 79: 'PLMN Network Name Icon',
105 80: 'Connectivity Parameters for USIM IP connections',
106 81: 'Home I-WLAN Specific Identifier List',
107 82: 'I-WLAN Equivalent HPLMN Presentation Indication',
108 83: 'I-WLAN HPLMN Priority Indication',
109 84: 'I-WLAN Last Registered PLMN',
110 85: 'EPS Mobility Management Information',
111 86: 'Allowed CSG Lists and corresponding indications',
112 87: 'Call control on EPS PDN connection by USIM',
113 88: 'HPLMN Direct Access',
114 89: 'eCall Data',
115 90: 'Operator CSG Lists and corresponding indications',
116 91: 'Support for SM-over-IP',
117 92: 'Support of CSG Display Control',
118 93: 'Communication Control for IMS by USIM',
119 94: 'Extended Terminal Applications',
120 95: 'Support of UICC access to IMS',
121 96: 'Non-Access Stratum configuration by USIM',
122 97: 'PWS configuration by USIM',
123 98: 'RFU',
124 99: 'URI support by UICC',
125 100: 'Extended EARFCN support',
126 101: 'ProSe',
127 102: 'USAT Application Pairing',
128 103: 'Media Type support',
129 104: 'IMS call disconnection cause',
130 105: 'URI support for MO SHORT MESSAGE CONTROL',
131 106: 'ePDG configuration Information support',
132 107: 'ePDG configuration Information configured',
133 108: 'ACDC support',
134 109: 'MCPTT',
135 110: 'ePDG configuration Information for Emergency Service support',
136 111: 'ePDG configuration Information for Emergency Service configured',
Supreeth Herle4d9e6be2020-03-24 12:13:45 +0100137 112: 'eCall Data over IMS',
138 113: 'URI support for SMS-PP DOWNLOAD as defined in 3GPP TS 31.111 [12]',
139 114: 'From Preferred',
140 115: 'IMS configuration data',
141 116: 'TV configuration',
142 117: '3GPP PS Data Off',
143 118: '3GPP PS Data Off Service List',
144 119: 'V2X',
145 120: 'XCAP Configuration Data',
146 121: 'EARFCN list for MTC/NB-IOT UEs',
147 122: '5GS Mobility Management Information',
148 123: '5G Security Parameters',
149 124: 'Subscription identifier privacy support',
150 125: 'SUCI calculation by the USIM',
151 126: 'UAC Access Identities support',
152 127: 'Expect control plane-based Steering of Roaming information during initial registration in VPLMN',
153 128: 'Call control on PDU Session by USIM',
Sebastian Viviani0dc8f692020-05-29 00:14:55 +0100154}
155
Sebastian Vivianie61170c2020-06-03 08:57:00 +0100156LOCI_STATUS_map = {
157 0: 'updated',
158 1: 'not updated',
159 2: 'plmn not allowed',
160 3: 'locatation area not allowed'
161}
herlesupreetha562ea02020-09-16 20:17:22 +0200162
Sebastian Viviani0dc8f692020-05-29 00:14:55 +0100163EF_USIM_ADF_map = {
164 'LI': '6F05',
165 'ARR': '6F06',
166 'IMSI': '6F07',
167 'Keys': '6F08',
168 'KeysPS': '6F09',
169 'DCK': '6F2C',
170 'HPPLMN': '6F31',
171 'CNL': '6F32',
172 'ACMmax': '6F37',
173 'UST': '6F38',
174 'ACM': '6F39',
175 'FDN': '6F3B',
176 'SMS': '6F3C',
177 'GID1': '6F3E',
178 'GID2': '6F3F',
179 'MSISDN': '6F40',
180 'PUCT': '6F41',
181 'SMSP': '6F42',
182 'SMSS': '6F42',
183 'CBMI': '6F45',
184 'SPN': '6F46',
185 'SMSR': '6F47',
186 'CBMID': '6F48',
187 'SDN': '6F49',
188 'EXT2': '6F4B',
189 'EXT3': '6F4C',
190 'BDN': '6F4D',
191 'EXT5': '6F4E',
192 'CCP2': '6F4F',
193 'CBMIR': '6F50',
194 'EXT4': '6F55',
195 'EST': '6F56',
196 'ACL': '6F57',
197 'CMI': '6F58',
198 'START-HFN': '6F5B',
199 'THRESHOLD': '6F5C',
200 'PLMNwAcT': '6F60',
201 'OPLMNwAcT': '6F61',
202 'HPLMNwAcT': '6F62',
203 'PSLOCI': '6F73',
204 'ACC': '6F78',
205 'FPLMN': '6F7B',
206 'LOCI': '6F7E',
207 'ICI': '6F80',
208 'OCI': '6F81',
209 'ICT': '6F82',
210 'OCT': '6F83',
211 'AD': '6FAD',
212 'VGCS': '6FB1',
213 'VGCSS': '6FB2',
214 'VBS': '6FB3',
215 'VBSS': '6FB4',
216 'eMLPP': '6FB5',
217 'AAeM': '6FB6',
218 'ECC': '6FB7',
219 'Hiddenkey': '6FC3',
220 'NETPAR': '6FC4',
221 'PNN': '6FC5',
222 'OPL': '6FC6',
223 'MBDN': '6FC7',
224 'EXT6': '6FC8',
225 'MBI': '6FC9',
226 'MWIS': '6FCA',
227 'CFIS': '6FCB',
228 'EXT7': '6FCC',
229 'SPDI': '6FCD',
230 'MMSN': '6FCE',
231 'EXT8': '6FCF',
232 'MMSICP': '6FD0',
233 'MMSUP': '6FD1',
234 'MMSUCP': '6FD2',
235 'NIA': '6FD3',
236 'VGCSCA': '6FD4',
237 'VBSCA': '6FD5',
238 'GBAP': '6FD6',
239 'MSK': '6FD7',
240 'MUK': '6FD8',
241 'EHPLMN': '6FD9',
242 'GBANL': '6FDA',
243 'EHPLMNPI': '6FDB',
244 'LRPLMNSI': '6FDC',
245 'NAFKCA': '6FDD',
246 'SPNI': '6FDE',
247 'PNNI': '6FDF',
248 'NCP-IP': '6FE2',
249 'EPSLOCI': '6FE3',
250 'EPSNSC': '6FE4',
251 'UFC': '6FE6',
252 'UICCIARI': '6FE7',
253 'NASCONFIG': '6FE8',
254 'PWC': '6FEC',
255 'FDNURI': '6FED',
256 'BDNURI': '6FEE',
257 'SDNURI': '6FEF',
258 'IWL': '6FF0',
259 'IPS': '6FF1',
260 'IPD': '6FF2',
261 'ePDGId': '6FF3',
262 'ePDGSelection': '6FF4',
263 'ePDGIdEm': '6FF5',
264 'ePDGSelectionEm': '6FF6',
265}
Harald Welteb2edd142021-01-08 23:29:35 +0100266
267######################################################################
268# ADF.USIM
269######################################################################
270
271from pySim.filesystem import *
272from pySim.ts_51_011 import EF_IMSI, EF_xPLMNwAcT, EF_SPN, EF_CBMI, EF_ACC, EF_PLMNsel, EF_AD
273from pySim.ts_51_011 import EF_CBMID, EF_ECC, EF_CBMIR
274
275import pySim.ts_102_221
276
277class EF_LI(TransRecEF):
278 def __init__(self, fid='6f05', sfid=None, name='EF.LI', size={2,None}, rec_len=2,
279 desc='Language Indication'):
280 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
281 def _decode_record_bin(self, in_bin):
282 if in_bin == b'\xff\xff':
283 return None
284 else:
285 # officially this is 7-bit GSM alphabet with one padding bit in each byte
286 return in_bin.decode('ascii')
287 def _encode_record_bin(self, in_json):
288 if in_json == None:
289 return b'\xff\xff'
290 else:
291 # officially this is 7-bit GSM alphabet with one padding bit in each byte
292 return in_json.encode('ascii')
293
294class EF_Keys(TransparentEF):
295 def __init__(self, fid='6f08', sfid=0x08, name='EF.Keys', size={33,33},
296 desc='Ciphering and Integrity Keys'):
297 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
298 def _decode_bin(self, in_bin):
299 return {'ksi': in_bin[0],
300 'ck': b2h(in_bin[1:17]),
301 'ik': b2h(in_bin[17:33])}
302 def _encode_bin(self, in_json):
303 return h2b(in_json['ksi']) + h2b(in_json['ck']) + h2b(in_json['ik'])
304
305# TS 31.103 Section 4.2.7
306class EF_UST(TransparentEF):
307 def __init__(self, fid='6f38', sfid=0x04, name='EF.UST', desc='USIM Service Table'):
308 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, size={1,17})
309 # add those commands to the general commands of a TransparentEF
310 self.shell_commands += [self.AddlShellCommands()]
311 def _decode_bin(self, in_bin):
312 ret = []
313 for i in range (0, len(in_bin)):
314 byte = in_bin[i]
315 for bitno in range(0,7):
316 if byte & (1 << bitno):
317 ret.append(i * 8 + bitno + 1)
318 return ret
319 def _encode_bin(self, in_json):
320 # FIXME: size this to length of file
321 ret = bytearray(20)
322 for srv in in_json:
323 print("srv=%d"%srv)
324 srv = srv-1
325 byte_nr = srv // 8
326 # FIXME: detect if service out of range was selected
327 bit_nr = srv % 8
328 ret[byte_nr] |= (1 << bit_nr)
329 return ret
330 @with_default_category('File-Specific Commands')
331 class AddlShellCommands(CommandSet):
332 def __init__(self):
333 super().__init__()
334
335 def do_ust_service_activate(self, arg):
336 """Activate a service within EF.UST"""
337 self._cmd.card.update_ust(int(arg), 1)
338
339 def do_ust_service_deactivate(self, arg):
340 """Deactivate a service within EF.UST"""
341 self._cmd.card.update_ust(int(arg), 0)
342
343
344class ADF_USIM(CardADF):
345 def __init__(self, aid='a0000000871002', name='ADF.USIM', fid=None, sfid=None,
346 desc='USIM Application'):
347 super().__init__(aid=aid, fid=fid, sfid=sfid, name=name, desc=desc)
348 self.shell_commands = [self.ShellCommands()]
349
350 files = [
351 EF_LI(sfid=0x02),
352 EF_IMSI(sfid=0x07),
353 EF_Keys(),
354 EF_Keys('6f09', 0x09, 'EF.KeysPS', desc='Ciphering and Integrity Keys for PS domain'),
355 EF_xPLMNwAcT('6f60', 0x0a, 'EF.PLMNwAcT',
356 'User controlled PLMN Selector with Access Technology'),
357 TransparentEF('6f31', 0x12, 'EF.HPPLMN', 'Higher Priority PLMN search period'),
358 # EF.ACMmax
359 EF_UST(),
360 CyclicEF('6f39', None, 'EF.ACM', 'Accumulated call meter', rec_len={3,3}),
361 TransparentEF('6f3e', None, 'EF.GID1', 'Group Identifier Level 1'),
362 TransparentEF('6f3f', None, 'EF.GID2', 'Group Identifier Level 2'),
363 EF_SPN(),
364 TransparentEF('6f41', None, 'EF.PUCT', 'Price per unit and currency table', size={5,5}),
365 EF_CBMI(),
366 EF_ACC(sfid=0x06),
367 EF_PLMNsel('6f7b', 0x0d, 'EF.FPLMN', 'Forbidden PLMNs', size={12,None}),
368 TransparentEF('6f7e', 0x0b, 'EF.LOCI', 'Locationn information', size={11,11}),
369 EF_AD(sfid=0x03),
370 EF_CBMID(sfid=0x0e),
371 EF_ECC(sfid=0x01),
372 EF_CBMIR(),
373 ]
374 self.add_files(files)
375
376 def decode_select_response(self, data_hex):
377 return pySim.ts_102_221.decode_select_response(data_hex)
378
379 @with_default_category('File-Specific Commands')
380 class ShellCommands(CommandSet):
381 def __init__(self):
382 super().__init__()
383
384
385# TS 31.102 Section 7.3
386sw_usim = {
387 'Security management': {
388 '9862': 'Authentication error, incorrect MAC',
389 '9864': 'Authentication error, security context not supported',
390 '9865': 'Key freshness failure',
391 '9866': 'Authentication error, no memory space available',
392 '9867': 'Authentication error, no memory space available in EF MUK',
393 }
394}
395
396CardApplicationUSIM = CardApplication('USIM', adf=ADF_USIM(), sw=sw_usim)