Daniel Willmann | de07b95 | 2020-10-19 10:32:34 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 2 | |
| 3 | # |
| 4 | # Utility to display some informations about a SIM card |
| 5 | # |
| 6 | # |
| 7 | # Copyright (C) 2009 Sylvain Munaut <tnt@246tNt.com> |
| 8 | # Copyright (C) 2010 Harald Welte <laforge@gnumonks.org> |
| 9 | # Copyright (C) 2013 Alexander Chemeris <alexander.chemeris@gmail.com> |
| 10 | # |
| 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 | |
| 25 | import hashlib |
| 26 | from optparse import OptionParser |
| 27 | import os |
| 28 | import random |
| 29 | import re |
| 30 | import sys |
Vadim Yanitskiy | dfe3dbb | 2020-07-28 05:26:02 +0700 | [diff] [blame] | 31 | from pySim.ts_51_011 import EF, DF, EF_SST_map, EF_AD_mode_map |
Sebastian Viviani | 0dc8f69 | 2020-05-29 00:14:55 +0100 | [diff] [blame] | 32 | from pySim.ts_31_102 import EF_UST_map, EF_USIM_ADF_map |
Supreeth Herle | 5ad9aec | 2020-03-24 17:26:40 +0100 | [diff] [blame] | 33 | from pySim.ts_31_103 import EF_IST_map, EF_ISIM_ADF_map |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 34 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 35 | from pySim.commands import SimCardCommands |
Harald Welte | 6e0458d | 2021-04-03 11:52:37 +0200 | [diff] [blame^] | 36 | from pySim.transport import init_reader |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 37 | from pySim.cards import card_detect, Card, UsimCard, IsimCard |
Philipp Maier | ff84c23 | 2020-05-12 17:24:18 +0200 | [diff] [blame] | 38 | from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn |
Harald Welte | 6e0458d | 2021-04-03 11:52:37 +0200 | [diff] [blame^] | 39 | from pySim.utils import format_xplmn_w_act, dec_spn, dec_st, dec_addr_tlv |
Supreeth Herle | 99d5555 | 2020-03-24 13:03:43 +0100 | [diff] [blame] | 40 | from pySim.utils import h2s, format_ePDGSelection |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 41 | |
| 42 | def parse_options(): |
| 43 | |
| 44 | parser = OptionParser(usage="usage: %prog [options]") |
| 45 | |
| 46 | parser.add_option("-d", "--device", dest="device", metavar="DEV", |
| 47 | help="Serial Device for SIM access [default: %default]", |
| 48 | default="/dev/ttyUSB0", |
| 49 | ) |
| 50 | parser.add_option("-b", "--baud", dest="baudrate", type="int", metavar="BAUD", |
| 51 | help="Baudrate used for SIM access [default: %default]", |
| 52 | default=9600, |
| 53 | ) |
| 54 | parser.add_option("-p", "--pcsc-device", dest="pcsc_dev", type='int', metavar="PCSC", |
| 55 | help="Which PC/SC reader number for SIM access", |
| 56 | default=None, |
| 57 | ) |
Vadim Yanitskiy | 29ca804 | 2020-05-09 21:23:37 +0700 | [diff] [blame] | 58 | parser.add_option("--modem-device", dest="modem_dev", metavar="DEV", |
| 59 | help="Serial port of modem for Generic SIM Access (3GPP TS 27.007)", |
| 60 | default=None, |
| 61 | ) |
| 62 | parser.add_option("--modem-baud", dest="modem_baud", type="int", metavar="BAUD", |
| 63 | help="Baudrate used for modem's port [default: %default]", |
| 64 | default=115200, |
| 65 | ) |
Vadim Yanitskiy | 9f9f5a6 | 2018-10-27 02:10:34 +0700 | [diff] [blame] | 66 | parser.add_option("--osmocon", dest="osmocon_sock", metavar="PATH", |
| 67 | help="Socket path for Calypso (e.g. Motorola C1XX) based reader (via OsmocomBB)", |
| 68 | default=None, |
| 69 | ) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 70 | |
| 71 | (options, args) = parser.parse_args() |
| 72 | |
| 73 | if args: |
| 74 | parser.error("Extraneous arguments") |
| 75 | |
| 76 | return options |
| 77 | |
| 78 | |
| 79 | if __name__ == '__main__': |
| 80 | |
| 81 | # Parse options |
| 82 | opts = parse_options() |
| 83 | |
Vadim Yanitskiy | 588f3ac | 2018-10-27 06:30:33 +0700 | [diff] [blame] | 84 | # Init card reader driver |
Philipp Maier | ff84c23 | 2020-05-12 17:24:18 +0200 | [diff] [blame] | 85 | sl = init_reader(opts) |
Philipp Maier | c8caec2 | 2021-02-22 16:07:53 +0100 | [diff] [blame] | 86 | if sl is None: |
| 87 | exit(1) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 88 | |
| 89 | # Create command layer |
| 90 | scc = SimCardCommands(transport=sl) |
| 91 | |
| 92 | # Wait for SIM card |
| 93 | sl.wait_for_card() |
| 94 | |
Supreeth Herle | 3e6f16d | 2020-03-23 10:00:50 +0100 | [diff] [blame] | 95 | # Assuming UICC SIM |
| 96 | scc.cla_byte = "00" |
| 97 | scc.sel_ctrl = "0004" |
| 98 | |
| 99 | # Testing for Classic SIM or UICC |
| 100 | (res, sw) = sl.send_apdu(scc.cla_byte + "a4" + scc.sel_ctrl + "02" + "3f00") |
| 101 | if sw == '6e00': |
| 102 | # Just a Classic SIM |
| 103 | scc.cla_byte = "a0" |
| 104 | scc.sel_ctrl = "0000" |
| 105 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 106 | # Program the card |
| 107 | print("Reading ...") |
| 108 | |
Supreeth Herle | 4c306ab | 2020-03-18 11:38:00 +0100 | [diff] [blame] | 109 | # Initialize Card object by auto detecting the card |
| 110 | card = card_detect("auto", scc) or Card(scc) |
| 111 | |
Supreeth Herle | 3bf4363 | 2020-03-20 20:20:27 +0100 | [diff] [blame] | 112 | # Read all AIDs on the UICC |
| 113 | card.read_aids() |
| 114 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 115 | # EF.ICCID |
Supreeth Herle | 3566b8e | 2020-03-18 12:02:34 +0100 | [diff] [blame] | 116 | (res, sw) = card.read_iccid() |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 117 | if sw == '9000': |
Supreeth Herle | 3566b8e | 2020-03-18 12:02:34 +0100 | [diff] [blame] | 118 | print("ICCID: %s" % (res,)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 119 | else: |
| 120 | print("ICCID: Can't read, response code = %s" % (sw,)) |
| 121 | |
| 122 | # EF.IMSI |
Supreeth Herle | f9762dc | 2020-03-18 12:05:06 +0100 | [diff] [blame] | 123 | (res, sw) = card.read_imsi() |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 124 | if sw == '9000': |
Supreeth Herle | f9762dc | 2020-03-18 12:05:06 +0100 | [diff] [blame] | 125 | print("IMSI: %s" % (res,)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 126 | else: |
| 127 | print("IMSI: Can't read, response code = %s" % (sw,)) |
| 128 | |
Supreeth Herle | ab46d62 | 2020-03-05 15:30:22 +0100 | [diff] [blame] | 129 | # EF.GID1 |
| 130 | try: |
Supreeth Herle | 98a6927 | 2020-03-18 12:14:48 +0100 | [diff] [blame] | 131 | (res, sw) = card.read_gid1() |
Supreeth Herle | ab46d62 | 2020-03-05 15:30:22 +0100 | [diff] [blame] | 132 | if sw == '9000': |
| 133 | print("GID1: %s" % (res,)) |
| 134 | else: |
| 135 | print("GID1: Can't read, response code = %s" % (sw,)) |
| 136 | except Exception as e: |
| 137 | print("GID1: Can't read file -- %s" % (str(e),)) |
| 138 | |
Supreeth Herle | 0e90e6c | 2020-03-05 15:33:00 +0100 | [diff] [blame] | 139 | # EF.GID2 |
| 140 | try: |
Supreeth Herle | e573ccb | 2020-04-01 09:21:20 +0200 | [diff] [blame] | 141 | (res, sw) = card.read_binary('GID2') |
Supreeth Herle | 0e90e6c | 2020-03-05 15:33:00 +0100 | [diff] [blame] | 142 | if sw == '9000': |
| 143 | print("GID2: %s" % (res,)) |
| 144 | else: |
| 145 | print("GID2: Can't read, response code = %s" % (sw,)) |
| 146 | except Exception as e: |
| 147 | print("GID2: Can't read file -- %s" % (str(e),)) |
| 148 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 149 | # EF.SMSP |
Supreeth Herle | ebe6dba | 2020-03-19 12:08:20 +0100 | [diff] [blame] | 150 | (res, sw) = card.read_record('SMSP', 1) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 151 | if sw == '9000': |
| 152 | print("SMSP: %s" % (res,)) |
| 153 | else: |
| 154 | print("SMSP: Can't read, response code = %s" % (sw,)) |
| 155 | |
Supreeth Herle | f829945 | 2019-06-08 07:49:08 +0200 | [diff] [blame] | 156 | # EF.SPN |
| 157 | try: |
Supreeth Herle | 846cefb | 2020-03-19 12:11:25 +0100 | [diff] [blame] | 158 | (res, sw) = card.read_spn() |
Supreeth Herle | f829945 | 2019-06-08 07:49:08 +0200 | [diff] [blame] | 159 | if sw == '9000': |
Supreeth Herle | 846cefb | 2020-03-19 12:11:25 +0100 | [diff] [blame] | 160 | print("SPN: %s" % (res[0] or "Not available")) |
| 161 | print("Display HPLMN: %s" % (res[1],)) |
| 162 | print("Display OPLMN: %s" % (res[2],)) |
Supreeth Herle | f829945 | 2019-06-08 07:49:08 +0200 | [diff] [blame] | 163 | else: |
| 164 | print("SPN: Can't read, response code = %s" % (sw,)) |
| 165 | except Exception as e: |
| 166 | print("SPN: Can't read file -- %s" % (str(e),)) |
| 167 | |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 168 | # EF.PLMNsel |
| 169 | try: |
Supreeth Herle | 9efd8ef | 2020-03-19 12:14:10 +0100 | [diff] [blame] | 170 | (res, sw) = card.read_binary('PLMNsel') |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 171 | if sw == '9000': |
| 172 | print("PLMNsel: %s" % (res)) |
| 173 | else: |
| 174 | print("PLMNsel: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 175 | except Exception as e: |
Vadim Yanitskiy | a3bb334 | 2020-01-25 12:45:37 +0700 | [diff] [blame] | 176 | print("PLMNsel: Can't read file -- " + str(e)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 177 | |
| 178 | # EF.PLMNwAcT |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 179 | try: |
Supreeth Herle | 1408440 | 2020-03-19 12:42:10 +0100 | [diff] [blame] | 180 | (res, sw) = card.read_plmn_act() |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 181 | if sw == '9000': |
Supreeth Herle | 1408440 | 2020-03-19 12:42:10 +0100 | [diff] [blame] | 182 | print("PLMNwAcT:\n%s" % (res)) |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 183 | else: |
| 184 | print("PLMNwAcT: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 185 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 186 | print("PLMNwAcT: Can't read file -- " + str(e)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 187 | |
| 188 | # EF.OPLMNwAcT |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 189 | try: |
Supreeth Herle | 1757b26 | 2020-03-19 12:43:11 +0100 | [diff] [blame] | 190 | (res, sw) = card.read_oplmn_act() |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 191 | if sw == '9000': |
Supreeth Herle | 1757b26 | 2020-03-19 12:43:11 +0100 | [diff] [blame] | 192 | print("OPLMNwAcT:\n%s" % (res)) |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 193 | else: |
| 194 | print("OPLMNwAcT: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 195 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 196 | print("OPLMNwAcT: Can't read file -- " + str(e)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 197 | |
| 198 | # EF.HPLMNAcT |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 199 | try: |
Supreeth Herle | a850a47 | 2020-03-19 12:44:11 +0100 | [diff] [blame] | 200 | (res, sw) = card.read_hplmn_act() |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 201 | if sw == '9000': |
Supreeth Herle | a850a47 | 2020-03-19 12:44:11 +0100 | [diff] [blame] | 202 | print("HPLMNAcT:\n%s" % (res)) |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 203 | else: |
| 204 | print("HPLMNAcT: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 205 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 206 | print("HPLMNAcT: Can't read file -- " + str(e)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 207 | |
| 208 | # EF.ACC |
Supreeth Herle | d1fb6fc | 2020-03-19 12:45:45 +0100 | [diff] [blame] | 209 | (res, sw) = card.read_binary('ACC') |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 210 | if sw == '9000': |
| 211 | print("ACC: %s" % (res,)) |
| 212 | else: |
| 213 | print("ACC: Can't read, response code = %s" % (sw,)) |
| 214 | |
| 215 | # EF.MSISDN |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 216 | try: |
Supreeth Herle | 6d66af6 | 2020-03-19 12:49:16 +0100 | [diff] [blame] | 217 | (res, sw) = card.read_msisdn() |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 218 | if sw == '9000': |
Supreeth Herle | 6d66af6 | 2020-03-19 12:49:16 +0100 | [diff] [blame] | 219 | # (npi, ton, msisdn) = res |
| 220 | if res is not None: |
| 221 | print("MSISDN (NPI=%d ToN=%d): %s" % res) |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 222 | else: |
| 223 | print("MSISDN: Not available") |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 224 | else: |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 225 | print("MSISDN: Can't read, response code = %s" % (sw,)) |
Philipp Maier | ea6bdf0 | 2018-07-11 23:02:36 +0200 | [diff] [blame] | 226 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 227 | print("MSISDN: Can't read file -- " + str(e)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 228 | |
Philipp Maier | ee908ae | 2019-03-21 16:21:12 +0100 | [diff] [blame] | 229 | # EF.AD |
Supreeth Herle | 52ef675 | 2020-03-19 12:50:27 +0100 | [diff] [blame] | 230 | (res, sw) = card.read_binary('AD') |
Philipp Maier | ee908ae | 2019-03-21 16:21:12 +0100 | [diff] [blame] | 231 | if sw == '9000': |
Vadim Yanitskiy | dfe3dbb | 2020-07-28 05:26:02 +0700 | [diff] [blame] | 232 | print("Administrative data: %s" % (res,)) |
| 233 | if res[:2] in EF_AD_mode_map: |
| 234 | print("\tMS operation mode: %s" % (EF_AD_mode_map[res[:2]],)) |
| 235 | else: |
| 236 | print("\tMS operation mode: (unknown 0x%s)" % (res[:2],)) |
| 237 | if int(res[4:6], 16) & 0x01: |
| 238 | print("\tCiphering Indicator: enabled") |
| 239 | else: |
| 240 | print("\tCiphering Indicator: disabled") |
Philipp Maier | ee908ae | 2019-03-21 16:21:12 +0100 | [diff] [blame] | 241 | else: |
| 242 | print("AD: Can't read, response code = %s" % (sw,)) |
| 243 | |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 244 | # EF.SST |
Supreeth Herle | d3b13d0 | 2020-04-20 13:30:34 +0200 | [diff] [blame] | 245 | (res, sw) = card.read_binary('SST') |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 246 | if sw == '9000': |
Supreeth Herle | d3b13d0 | 2020-04-20 13:30:34 +0200 | [diff] [blame] | 247 | print("SIM Service Table: %s" % res) |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 248 | # Print those which are available |
Supreeth Herle | d3b13d0 | 2020-04-20 13:30:34 +0200 | [diff] [blame] | 249 | print("%s" % dec_st(res)) |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 250 | else: |
| 251 | print("SIM Service Table: Can't read, response code = %s" % (sw,)) |
| 252 | |
Supreeth Herle | 9641299 | 2020-03-22 08:20:11 +0100 | [diff] [blame] | 253 | # Check whether we have th AID of USIM, if so select it by its AID |
| 254 | # EF.UST - File Id in ADF USIM : 6f38 |
Philipp Maier | cba6dbc | 2021-03-11 13:03:18 +0100 | [diff] [blame] | 255 | data, sw = card.select_adf_by_aid(adf="usim") |
| 256 | if sw == '9000': |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 257 | # Select USIM profile |
| 258 | usim_card = UsimCard(scc) |
| 259 | |
Harald Welte | ca67394 | 2020-06-03 15:19:40 +0200 | [diff] [blame] | 260 | # EF.EHPLMN |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 261 | if usim_card.file_exists(EF_USIM_ADF_map['EHPLMN']): |
| 262 | (res, sw) = usim_card.read_ehplmn() |
Harald Welte | ca67394 | 2020-06-03 15:19:40 +0200 | [diff] [blame] | 263 | if sw == '9000': |
| 264 | print("EHPLMN:\n%s" % (res)) |
| 265 | else: |
| 266 | print("EHPLMN: Can't read, response code = %s" % (sw,)) |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 267 | |
Supreeth Herle | 9641299 | 2020-03-22 08:20:11 +0100 | [diff] [blame] | 268 | # EF.UST |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 269 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 270 | if usim_card.file_exists(EF_USIM_ADF_map['UST']): |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 271 | # res[0] - EF content of UST |
| 272 | # res[1] - Human readable format of services marked available in UST |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 273 | (res, sw) = usim_card.read_ust() |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 274 | if sw == '9000': |
| 275 | print("USIM Service Table: %s" % res[0]) |
| 276 | print("%s" % res[1]) |
| 277 | else: |
| 278 | print("USIM Service Table: Can't read, response code = %s" % (sw,)) |
| 279 | except Exception as e: |
| 280 | print("USIM Service Table: Can't read file -- " + str(e)) |
Supreeth Herle | 9641299 | 2020-03-22 08:20:11 +0100 | [diff] [blame] | 281 | |
Supreeth Herle | b1634db | 2020-03-22 10:00:43 +0100 | [diff] [blame] | 282 | #EF.ePDGId - Home ePDG Identifier |
| 283 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 284 | if usim_card.file_exists(EF_USIM_ADF_map['ePDGId']): |
| 285 | (res, sw) = usim_card.read_epdgid() |
herlesupreeth | f8232db | 2020-09-29 10:03:06 +0200 | [diff] [blame] | 286 | if sw == '9000': |
| 287 | print("ePDGId:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 288 | else: |
| 289 | print("ePDGId: Can't read, response code = %s" % (sw,)) |
Supreeth Herle | b1634db | 2020-03-22 10:00:43 +0100 | [diff] [blame] | 290 | except Exception as e: |
| 291 | print("ePDGId: Can't read file -- " + str(e)) |
| 292 | |
Supreeth Herle | 99d5555 | 2020-03-24 13:03:43 +0100 | [diff] [blame] | 293 | #EF.ePDGSelection - ePDG Selection Information |
| 294 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 295 | if usim_card.file_exists(EF_USIM_ADF_map['ePDGSelection']): |
| 296 | (res, sw) = usim_card.read_ePDGSelection() |
Supreeth Herle | 99d5555 | 2020-03-24 13:03:43 +0100 | [diff] [blame] | 297 | if sw == '9000': |
| 298 | print("ePDGSelection:\n%s" % (res,)) |
| 299 | else: |
| 300 | print("ePDGSelection: Can't read, response code = %s" % (sw,)) |
| 301 | except Exception as e: |
| 302 | print("ePDGSelection: Can't read file -- " + str(e)) |
| 303 | |
Supreeth Herle | 5ad9aec | 2020-03-24 17:26:40 +0100 | [diff] [blame] | 304 | # Select ISIM application by its AID |
Philipp Maier | cba6dbc | 2021-03-11 13:03:18 +0100 | [diff] [blame] | 305 | data, sw = card.select_adf_by_aid(adf="isim") |
| 306 | if sw == '9000': |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 307 | # Select USIM profile |
| 308 | isim_card = IsimCard(scc) |
| 309 | |
Supreeth Herle | 5ad9aec | 2020-03-24 17:26:40 +0100 | [diff] [blame] | 310 | #EF.P-CSCF - P-CSCF Address |
| 311 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 312 | if isim_card.file_exists(EF_ISIM_ADF_map['PCSCF']): |
| 313 | res = isim_card.read_pcscf() |
Supreeth Herle | 5ad9aec | 2020-03-24 17:26:40 +0100 | [diff] [blame] | 314 | print("P-CSCF:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 315 | except Exception as e: |
| 316 | print("P-CSCF: Can't read file -- " + str(e)) |
| 317 | |
Supreeth Herle | 05b2807 | 2020-03-25 10:23:48 +0100 | [diff] [blame] | 318 | # EF.DOMAIN - Home Network Domain Name e.g. ims.mncXXX.mccXXX.3gppnetwork.org |
| 319 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 320 | if isim_card.file_exists(EF_ISIM_ADF_map['DOMAIN']): |
| 321 | (res, sw) = isim_card.read_domain() |
Supreeth Herle | 05b2807 | 2020-03-25 10:23:48 +0100 | [diff] [blame] | 322 | if sw == '9000': |
| 323 | print("Home Network Domain Name: %s" % (len(res) and res or 'Not available',)) |
| 324 | else: |
| 325 | print("Home Network Domain Name: Can't read, response code = %s" % (sw,)) |
| 326 | except Exception as e: |
| 327 | print("Home Network Domain Name: Can't read file -- " + str(e)) |
| 328 | |
Supreeth Herle | 3f67f9c | 2020-03-25 15:38:02 +0100 | [diff] [blame] | 329 | # EF.IMPI - IMS private user identity |
| 330 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 331 | if isim_card.file_exists(EF_ISIM_ADF_map['IMPI']): |
| 332 | (res, sw) = isim_card.read_impi() |
Supreeth Herle | 3f67f9c | 2020-03-25 15:38:02 +0100 | [diff] [blame] | 333 | if sw == '9000': |
| 334 | print("IMS private user identity: %s" % (len(res) and res or 'Not available',)) |
| 335 | else: |
| 336 | print("IMS private user identity: Can't read, response code = %s" % (sw,)) |
| 337 | except Exception as e: |
| 338 | print("IMS private user identity: Can't read file -- " + str(e)) |
| 339 | |
Supreeth Herle | 0c02d8a | 2020-03-26 09:00:06 +0100 | [diff] [blame] | 340 | # EF.IMPU - IMS public user identity |
| 341 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 342 | if isim_card.file_exists(EF_ISIM_ADF_map['IMPU']): |
| 343 | res = isim_card.read_impu() |
Supreeth Herle | 0c02d8a | 2020-03-26 09:00:06 +0100 | [diff] [blame] | 344 | print("IMS public user identity:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 345 | except Exception as e: |
| 346 | print("IMS public user identity: Can't read file -- " + str(e)) |
| 347 | |
Supreeth Herle | be3b641 | 2020-06-01 12:53:57 +0200 | [diff] [blame] | 348 | # EF.UICCIARI - UICC IARI |
| 349 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 350 | if isim_card.file_exists(EF_ISIM_ADF_map['UICCIARI']): |
| 351 | res = isim_card.read_iari() |
Supreeth Herle | be3b641 | 2020-06-01 12:53:57 +0200 | [diff] [blame] | 352 | print("UICC IARI:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 353 | except Exception as e: |
| 354 | print("UICC IARI: Can't read file -- " + str(e)) |
| 355 | |
Supreeth Herle | ee15c77 | 2020-03-22 08:58:33 +0100 | [diff] [blame] | 356 | # Check whether we have th AID of ISIM, if so select it by its AID |
| 357 | # EF.IST - File Id in ADF ISIM : 6f07 |
Philipp Maier | cba6dbc | 2021-03-11 13:03:18 +0100 | [diff] [blame] | 358 | data, sw = card.select_adf_by_aid(adf="isim") |
| 359 | if sw == '9000': |
Supreeth Herle | ee15c77 | 2020-03-22 08:58:33 +0100 | [diff] [blame] | 360 | # EF.IST |
| 361 | (res, sw) = card.read_binary('6f07') |
| 362 | if sw == '9000': |
| 363 | print("ISIM Service Table: %s" % res) |
| 364 | # Print those which are available |
| 365 | print("%s" % dec_st(res, table="isim")) |
| 366 | else: |
| 367 | print("ISIM Service Table: Can't read, response code = %s" % (sw,)) |
| 368 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 369 | # Done for this card and maybe for everything ? |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 370 | print("Done !\n") |