blob: cdb66124bbf35cce2a7ff955092a78c9b78866a5 [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
Harald Welte15fae982021-04-10 10:22:27 +0200271from struct import unpack, pack
Harald Welteb2edd142021-01-08 23:29:35 +0100272from pySim.filesystem import *
273from pySim.ts_51_011 import EF_IMSI, EF_xPLMNwAcT, EF_SPN, EF_CBMI, EF_ACC, EF_PLMNsel, EF_AD
Harald Welte89e59542021-04-02 21:33:13 +0200274from pySim.ts_51_011 import EF_CBMID, EF_CBMIR
Harald Welteb2edd142021-01-08 23:29:35 +0100275
276import pySim.ts_102_221
277
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200278# TS 31.102 4.4.11.8
279class EF_SUCI_Calc_Info(TransparentEF):
280 def __init__(self, fid="4f07", sfid=0x07, name='EF.SUCI_Calc_Info', size={2, None},
281 desc='SUCI Calc Info'):
282 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
283
284 def _encode_prot_scheme_id_list(self, in_list):
285 out_bytes = [0xa0]
286 out_bytes.append(len(in_list)*2) # two byte per entry
287
288 # position in list determines priority; high-priority items (low index) come first
289 for scheme in sorted(in_list, key=lambda item: item["priority"]):
290 out_bytes.append(scheme["identifier"])
291 out_bytes.append(scheme["key_index"])
292
293 return out_bytes
294
295 def _encode_hnet_pubkey_list(self, hnet_pubkey_list):
296 out_bytes = [0xa1] # pubkey list tag
297 out_bytes.append(0x00) # length filled later
298 length = 0
299
300 for key in hnet_pubkey_list:
301 out_bytes.append(0x80) # identifier tag
302 out_bytes.append(0x01) # TODO size, fixed to 1 byte
303 out_bytes.append(key["hnet_pubkey_identifier"])
304 out_bytes.append(0x81) # key tag
305 out_bytes.append(len(key["hnet_pubkey"])//2)
306 length += 5+len(key["hnet_pubkey"])//2
307
308 pubkey_bytes = h2b(key["hnet_pubkey"])
309 out_bytes += pubkey_bytes
310
311 # fill length
312 out_bytes[1] = length
313 return out_bytes
314
315 def _encode_hex(self, in_json):
316 out_bytes = self._encode_prot_scheme_id_list(in_json['prot_scheme_id_list'])
317 out_bytes += self._encode_hnet_pubkey_list(in_json['hnet_pubkey_list'])
318 return "".join(["%02X" % i for i in out_bytes])
319
320 def _decode_prot_scheme_id_list(self, in_bytes):
321 prot_scheme_id_list = []
322 pos = 0
323 # two bytes per entry
324 while pos < len(in_bytes):
325 prot_scheme = {
326 'priority': pos//2, # first in list: high priority
327 'identifier': in_bytes[pos],
328 'key_index': in_bytes[pos+1]
329 }
330 pos += 2
331 prot_scheme_id_list.append(prot_scheme)
332 return prot_scheme_id_list
333
334 def _decode_hnet_pubkey_list(self, in_bytes):
335 hnet_pubkey_list = []
336 pos = 0
337 if in_bytes[pos] != 0xa1:
338 print("missing Home Network Public Key List data object")
339 return {}
340 pos += 1
341 hnet_pubkey_list_len = in_bytes[pos]
342 pos += 1
343
344 while pos < hnet_pubkey_list_len:
345 if in_bytes[pos] != 0x80:
346 print("missing Home Network Public Key Identifier tag")
347 return {}
348 pos += 1
349 hnet_pubkey_id_len = in_bytes[pos] # TODO might be more than 1 byte?
350 pos += 1
351 hnet_pubkey_id = in_bytes[pos:pos+hnet_pubkey_id_len][0]
352 pos += hnet_pubkey_id_len
353 if in_bytes[pos] != 0x81:
354 print("missing Home Network Public Key tag")
355 return {}
356 pos += 1
357 hnet_pubkey_len = in_bytes[pos]
358 pos += 1
359 hnet_pubkey = in_bytes[pos:pos+hnet_pubkey_len]
360 pos += hnet_pubkey_len
361
362 hnet_pubkey_list.append({
363 'hnet_pubkey_identifier': hnet_pubkey_id,
364 'hnet_pubkey': b2h(hnet_pubkey)
365 })
366
367 return hnet_pubkey_list
368
369 def _decode_bin(self, in_bin):
370 return self._decode_hex(b2h(in_hex))
371
372 def _decode_hex(self, in_hex):
373 in_bytes = h2b(in_hex)
374 pos = 0
375
376 if in_bytes[pos] != 0xa0:
377 print("missing Protection Scheme Identifier List data object tag")
378 return {}
379 pos += 1
380
381 prot_scheme_id_list_len = in_bytes[pos] # TODO maybe more than 1 byte
382 pos += 1
383 # decode Protection Scheme Identifier List data object
384 prot_scheme_id_list = self._decode_prot_scheme_id_list(in_bytes[pos:pos+prot_scheme_id_list_len])
385 pos += prot_scheme_id_list_len
386
387 # remaining data holds Home Network Public Key Data Object
388 hnet_pubkey_list = self._decode_hnet_pubkey_list(in_bytes[pos:])
389
390 return {
391 'prot_scheme_id_list': prot_scheme_id_list,
392 'hnet_pubkey_list': hnet_pubkey_list
393 }
394
395 def _encode_bin(self, in_json):
396 return h2b(self._encode_hex(in_json))
397
Harald Welteb2edd142021-01-08 23:29:35 +0100398class EF_LI(TransRecEF):
399 def __init__(self, fid='6f05', sfid=None, name='EF.LI', size={2,None}, rec_len=2,
400 desc='Language Indication'):
401 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size, rec_len=rec_len)
402 def _decode_record_bin(self, in_bin):
403 if in_bin == b'\xff\xff':
404 return None
405 else:
406 # officially this is 7-bit GSM alphabet with one padding bit in each byte
407 return in_bin.decode('ascii')
408 def _encode_record_bin(self, in_json):
409 if in_json == None:
410 return b'\xff\xff'
411 else:
412 # officially this is 7-bit GSM alphabet with one padding bit in each byte
413 return in_json.encode('ascii')
414
415class EF_Keys(TransparentEF):
416 def __init__(self, fid='6f08', sfid=0x08, name='EF.Keys', size={33,33},
417 desc='Ciphering and Integrity Keys'):
418 super().__init__(fid, sfid=sfid, name=name, desc=desc, size=size)
419 def _decode_bin(self, in_bin):
420 return {'ksi': in_bin[0],
421 'ck': b2h(in_bin[1:17]),
422 'ik': b2h(in_bin[17:33])}
423 def _encode_bin(self, in_json):
424 return h2b(in_json['ksi']) + h2b(in_json['ck']) + h2b(in_json['ik'])
425
426# TS 31.103 Section 4.2.7
427class EF_UST(TransparentEF):
428 def __init__(self, fid='6f38', sfid=0x04, name='EF.UST', desc='USIM Service Table'):
429 super().__init__(fid=fid, sfid=sfid, name=name, desc=desc, size={1,17})
430 # add those commands to the general commands of a TransparentEF
431 self.shell_commands += [self.AddlShellCommands()]
432 def _decode_bin(self, in_bin):
433 ret = []
434 for i in range (0, len(in_bin)):
435 byte = in_bin[i]
436 for bitno in range(0,7):
437 if byte & (1 << bitno):
438 ret.append(i * 8 + bitno + 1)
439 return ret
440 def _encode_bin(self, in_json):
441 # FIXME: size this to length of file
442 ret = bytearray(20)
443 for srv in in_json:
444 print("srv=%d"%srv)
445 srv = srv-1
446 byte_nr = srv // 8
447 # FIXME: detect if service out of range was selected
448 bit_nr = srv % 8
449 ret[byte_nr] |= (1 << bit_nr)
450 return ret
451 @with_default_category('File-Specific Commands')
452 class AddlShellCommands(CommandSet):
453 def __init__(self):
454 super().__init__()
455
456 def do_ust_service_activate(self, arg):
457 """Activate a service within EF.UST"""
458 self._cmd.card.update_ust(int(arg), 1)
459
460 def do_ust_service_deactivate(self, arg):
461 """Deactivate a service within EF.UST"""
462 self._cmd.card.update_ust(int(arg), 0)
463
Harald Welte89e59542021-04-02 21:33:13 +0200464# TS 31.103 Section 4.2.7 - *not* the same as DF.GSM/EF.ECC!
465class EF_ECC(LinFixedEF):
466 def __init__(self, fid='6fb7', sfid=0x01, name='EF.ECC',
467 desc='Emergency Call Codes'):
468 super().__init__(fid, sfid=sfid, name=name, desc=desc, rec_len={4,20})
469
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200470class DF_USIM_5GS(CardDF):
471 def __init__(self, fid='5FC0', name='DF.5GS', desc='5GS related files'):
472 super().__init__(fid=fid, name=name, desc=desc)
473 files = [
474 # I'm looking at 31.102 R15.9
475 TransparentEF('4F01', None, 'EF.5GS3GPPLOCI', '5GS 3GPP location information', size={20,20}),
476 TransparentEF('4F02', None, 'EF.5GSN3GPPLOCI', '5GS non-3GPP location information', size={20,20}),
477 #LinFixedEF('4F03', None, 'EF.5GS3GPPNSC', '5GS 3GPP Access NAS Security Context'),
478 #LinFixedEF('4F04', None, 'EF.5GSN3GPPNSC', '5GS non-3GPP Access NAS Security Context'),
479 TransparentEF('4F05', None, 'EF.5GAUTHKEYS', '5G authentication keys', size={68, None}),
480 TransparentEF('4F06', None, 'EF.UAC_AIC', 'UAC Access Identities Configuration', size={4, 4}),
481 EF_SUCI_Calc_Info(), #TransparentEF('4F07', None, 'EF.SUCI_Calc_Info', 'SUCI Calculation Information', size={2, None}),
Harald Welte89e59542021-04-02 21:33:13 +0200482 LinFixedEF('4F08', None, 'EF.OPL5G', '5GS Operator PLMN List', rec_len={10, None}),
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200483 # TransparentEF('4F09', None, 'EF.NSI', 'Network Specific Identifier'), # FFS
484 TransparentEF('4F0A', None, 'EF.Routing_Indicator', 'Routing Indicator', size={4,4}),
485 ]
486
487 self.add_files(files)
488
Harald Welteb2edd142021-01-08 23:29:35 +0100489class ADF_USIM(CardADF):
490 def __init__(self, aid='a0000000871002', name='ADF.USIM', fid=None, sfid=None,
491 desc='USIM Application'):
492 super().__init__(aid=aid, fid=fid, sfid=sfid, name=name, desc=desc)
Harald Welte15fae982021-04-10 10:22:27 +0200493 # add those commands to the general commands of a TransparentEF
494 self.shell_commands += [self.AddlShellCommands()]
Harald Welteb2edd142021-01-08 23:29:35 +0100495
496 files = [
497 EF_LI(sfid=0x02),
498 EF_IMSI(sfid=0x07),
499 EF_Keys(),
500 EF_Keys('6f09', 0x09, 'EF.KeysPS', desc='Ciphering and Integrity Keys for PS domain'),
501 EF_xPLMNwAcT('6f60', 0x0a, 'EF.PLMNwAcT',
502 'User controlled PLMN Selector with Access Technology'),
503 TransparentEF('6f31', 0x12, 'EF.HPPLMN', 'Higher Priority PLMN search period'),
504 # EF.ACMmax
505 EF_UST(),
506 CyclicEF('6f39', None, 'EF.ACM', 'Accumulated call meter', rec_len={3,3}),
507 TransparentEF('6f3e', None, 'EF.GID1', 'Group Identifier Level 1'),
508 TransparentEF('6f3f', None, 'EF.GID2', 'Group Identifier Level 2'),
509 EF_SPN(),
510 TransparentEF('6f41', None, 'EF.PUCT', 'Price per unit and currency table', size={5,5}),
511 EF_CBMI(),
512 EF_ACC(sfid=0x06),
513 EF_PLMNsel('6f7b', 0x0d, 'EF.FPLMN', 'Forbidden PLMNs', size={12,None}),
514 TransparentEF('6f7e', 0x0b, 'EF.LOCI', 'Locationn information', size={11,11}),
515 EF_AD(sfid=0x03),
516 EF_CBMID(sfid=0x0e),
Harald Welte89e59542021-04-02 21:33:13 +0200517 EF_ECC(),
Harald Welteb2edd142021-01-08 23:29:35 +0100518 EF_CBMIR(),
Merlin Chlosta05ca36b2021-04-01 16:15:28 +0200519 DF_USIM_5GS(),
Harald Welteb2edd142021-01-08 23:29:35 +0100520 ]
521 self.add_files(files)
522
523 def decode_select_response(self, data_hex):
524 return pySim.ts_102_221.decode_select_response(data_hex)
525
Harald Welte15fae982021-04-10 10:22:27 +0200526 @with_default_category('Application-Specific Commands')
527 class AddlShellCommands(CommandSet):
528 def __init__(self):
529 super().__init__()
530
531 authenticate_parser = argparse.ArgumentParser()
532 authenticate_parser.add_argument('rand', help='Random challenge')
533 authenticate_parser.add_argument('autn', help='Authentication Nonce')
534 #authenticate_parser.add_argument('--context', help='Authentication context', default='3G')
535 @cmd2.with_argparser(authenticate_parser)
536 def do_authenticate(self, opts):
537 """Perform Authentication and Key Agreement (AKA)."""
538 (data, sw) = self._cmd.card._scc.authenticate(opts.rand, opts.autn)
539 self._cmd.poutput_json(data)
540
541
542
Harald Welteb2edd142021-01-08 23:29:35 +0100543# TS 31.102 Section 7.3
544sw_usim = {
545 'Security management': {
546 '9862': 'Authentication error, incorrect MAC',
547 '9864': 'Authentication error, security context not supported',
548 '9865': 'Key freshness failure',
549 '9866': 'Authentication error, no memory space available',
550 '9867': 'Authentication error, no memory space available in EF MUK',
551 }
552}
553
554CardApplicationUSIM = CardApplication('USIM', adf=ADF_USIM(), sw=sw_usim)