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 |
Harald Welte | 8fe1d20 | 2021-04-11 12:31:40 +0200 | [diff] [blame] | 26 | import argparse |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 27 | import os |
| 28 | import random |
| 29 | import re |
| 30 | import sys |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 31 | from pySim.ts_51_011 import EF, DF, EF_SST_map, EF_AD |
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 | 8fe1d20 | 2021-04-11 12:31:40 +0200 | [diff] [blame] | 36 | from pySim.transport import init_reader, argparse_add_reader_args |
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 |
Robert Falkenberg | b07a3e9 | 2021-05-07 15:23:20 +0200 | [diff] [blame^] | 39 | from pySim.utils import format_xplmn_w_act, 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 | |
Harald Welte | 8fe1d20 | 2021-04-11 12:31:40 +0200 | [diff] [blame] | 42 | option_parser = argparse.ArgumentParser(prog='pySim-read', |
| 43 | description='Legacy tool for reading some parts of a SIM card', |
| 44 | formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
| 45 | argparse_add_reader_args(option_parser) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 46 | |
| 47 | if __name__ == '__main__': |
| 48 | |
| 49 | # Parse options |
Harald Welte | 8fe1d20 | 2021-04-11 12:31:40 +0200 | [diff] [blame] | 50 | opts = option_parser.parse_args() |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 51 | |
Vadim Yanitskiy | 588f3ac | 2018-10-27 06:30:33 +0700 | [diff] [blame] | 52 | # Init card reader driver |
Philipp Maier | ff84c23 | 2020-05-12 17:24:18 +0200 | [diff] [blame] | 53 | sl = init_reader(opts) |
Philipp Maier | c8caec2 | 2021-02-22 16:07:53 +0100 | [diff] [blame] | 54 | if sl is None: |
| 55 | exit(1) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 56 | |
| 57 | # Create command layer |
| 58 | scc = SimCardCommands(transport=sl) |
| 59 | |
| 60 | # Wait for SIM card |
| 61 | sl.wait_for_card() |
| 62 | |
Supreeth Herle | 3e6f16d | 2020-03-23 10:00:50 +0100 | [diff] [blame] | 63 | # Assuming UICC SIM |
| 64 | scc.cla_byte = "00" |
| 65 | scc.sel_ctrl = "0004" |
| 66 | |
| 67 | # Testing for Classic SIM or UICC |
| 68 | (res, sw) = sl.send_apdu(scc.cla_byte + "a4" + scc.sel_ctrl + "02" + "3f00") |
| 69 | if sw == '6e00': |
| 70 | # Just a Classic SIM |
| 71 | scc.cla_byte = "a0" |
| 72 | scc.sel_ctrl = "0000" |
| 73 | |
Philipp Maier | 4210a70 | 2021-05-05 14:17:59 +0200 | [diff] [blame] | 74 | # Read the card |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 75 | print("Reading ...") |
| 76 | |
Supreeth Herle | 4c306ab | 2020-03-18 11:38:00 +0100 | [diff] [blame] | 77 | # Initialize Card object by auto detecting the card |
| 78 | card = card_detect("auto", scc) or Card(scc) |
| 79 | |
Supreeth Herle | 3bf4363 | 2020-03-20 20:20:27 +0100 | [diff] [blame] | 80 | # Read all AIDs on the UICC |
| 81 | card.read_aids() |
| 82 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 83 | # EF.ICCID |
Supreeth Herle | 3566b8e | 2020-03-18 12:02:34 +0100 | [diff] [blame] | 84 | (res, sw) = card.read_iccid() |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 85 | if sw == '9000': |
Supreeth Herle | 3566b8e | 2020-03-18 12:02:34 +0100 | [diff] [blame] | 86 | print("ICCID: %s" % (res,)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 87 | else: |
| 88 | print("ICCID: Can't read, response code = %s" % (sw,)) |
| 89 | |
| 90 | # EF.IMSI |
Supreeth Herle | f9762dc | 2020-03-18 12:05:06 +0100 | [diff] [blame] | 91 | (res, sw) = card.read_imsi() |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 92 | if sw == '9000': |
Supreeth Herle | f9762dc | 2020-03-18 12:05:06 +0100 | [diff] [blame] | 93 | print("IMSI: %s" % (res,)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 94 | else: |
| 95 | print("IMSI: Can't read, response code = %s" % (sw,)) |
| 96 | |
Supreeth Herle | ab46d62 | 2020-03-05 15:30:22 +0100 | [diff] [blame] | 97 | # EF.GID1 |
| 98 | try: |
Supreeth Herle | 98a6927 | 2020-03-18 12:14:48 +0100 | [diff] [blame] | 99 | (res, sw) = card.read_gid1() |
Supreeth Herle | ab46d62 | 2020-03-05 15:30:22 +0100 | [diff] [blame] | 100 | if sw == '9000': |
| 101 | print("GID1: %s" % (res,)) |
| 102 | else: |
| 103 | print("GID1: Can't read, response code = %s" % (sw,)) |
| 104 | except Exception as e: |
| 105 | print("GID1: Can't read file -- %s" % (str(e),)) |
| 106 | |
Supreeth Herle | 0e90e6c | 2020-03-05 15:33:00 +0100 | [diff] [blame] | 107 | # EF.GID2 |
| 108 | try: |
Supreeth Herle | e573ccb | 2020-04-01 09:21:20 +0200 | [diff] [blame] | 109 | (res, sw) = card.read_binary('GID2') |
Supreeth Herle | 0e90e6c | 2020-03-05 15:33:00 +0100 | [diff] [blame] | 110 | if sw == '9000': |
| 111 | print("GID2: %s" % (res,)) |
| 112 | else: |
| 113 | print("GID2: Can't read, response code = %s" % (sw,)) |
| 114 | except Exception as e: |
| 115 | print("GID2: Can't read file -- %s" % (str(e),)) |
| 116 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 117 | # EF.SMSP |
Supreeth Herle | ebe6dba | 2020-03-19 12:08:20 +0100 | [diff] [blame] | 118 | (res, sw) = card.read_record('SMSP', 1) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 119 | if sw == '9000': |
| 120 | print("SMSP: %s" % (res,)) |
| 121 | else: |
| 122 | print("SMSP: Can't read, response code = %s" % (sw,)) |
| 123 | |
Supreeth Herle | f829945 | 2019-06-08 07:49:08 +0200 | [diff] [blame] | 124 | # EF.SPN |
| 125 | try: |
Supreeth Herle | 846cefb | 2020-03-19 12:11:25 +0100 | [diff] [blame] | 126 | (res, sw) = card.read_spn() |
Supreeth Herle | f829945 | 2019-06-08 07:49:08 +0200 | [diff] [blame] | 127 | if sw == '9000': |
Supreeth Herle | 846cefb | 2020-03-19 12:11:25 +0100 | [diff] [blame] | 128 | print("SPN: %s" % (res[0] or "Not available")) |
| 129 | print("Display HPLMN: %s" % (res[1],)) |
| 130 | print("Display OPLMN: %s" % (res[2],)) |
Supreeth Herle | f829945 | 2019-06-08 07:49:08 +0200 | [diff] [blame] | 131 | else: |
| 132 | print("SPN: Can't read, response code = %s" % (sw,)) |
| 133 | except Exception as e: |
| 134 | print("SPN: Can't read file -- %s" % (str(e),)) |
| 135 | |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 136 | # EF.PLMNsel |
| 137 | try: |
Supreeth Herle | 9efd8ef | 2020-03-19 12:14:10 +0100 | [diff] [blame] | 138 | (res, sw) = card.read_binary('PLMNsel') |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 139 | if sw == '9000': |
| 140 | print("PLMNsel: %s" % (res)) |
| 141 | else: |
| 142 | print("PLMNsel: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 143 | except Exception as e: |
Vadim Yanitskiy | a3bb334 | 2020-01-25 12:45:37 +0700 | [diff] [blame] | 144 | print("PLMNsel: Can't read file -- " + str(e)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 145 | |
| 146 | # EF.PLMNwAcT |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 147 | try: |
Supreeth Herle | 1408440 | 2020-03-19 12:42:10 +0100 | [diff] [blame] | 148 | (res, sw) = card.read_plmn_act() |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 149 | if sw == '9000': |
Supreeth Herle | 1408440 | 2020-03-19 12:42:10 +0100 | [diff] [blame] | 150 | print("PLMNwAcT:\n%s" % (res)) |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 151 | else: |
| 152 | print("PLMNwAcT: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 153 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 154 | print("PLMNwAcT: Can't read file -- " + str(e)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 155 | |
| 156 | # EF.OPLMNwAcT |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 157 | try: |
Supreeth Herle | 1757b26 | 2020-03-19 12:43:11 +0100 | [diff] [blame] | 158 | (res, sw) = card.read_oplmn_act() |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 159 | if sw == '9000': |
Supreeth Herle | 1757b26 | 2020-03-19 12:43:11 +0100 | [diff] [blame] | 160 | print("OPLMNwAcT:\n%s" % (res)) |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 161 | else: |
| 162 | print("OPLMNwAcT: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 163 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 164 | print("OPLMNwAcT: Can't read file -- " + str(e)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 165 | |
| 166 | # EF.HPLMNAcT |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 167 | try: |
Supreeth Herle | a850a47 | 2020-03-19 12:44:11 +0100 | [diff] [blame] | 168 | (res, sw) = card.read_hplmn_act() |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 169 | if sw == '9000': |
Supreeth Herle | a850a47 | 2020-03-19 12:44:11 +0100 | [diff] [blame] | 170 | print("HPLMNAcT:\n%s" % (res)) |
Denis 'GNUtoo' Carikli | 84d2cb3 | 2019-09-12 01:46:25 +0200 | [diff] [blame] | 171 | else: |
| 172 | print("HPLMNAcT: Can't read, response code = %s" % (sw,)) |
Philipp Maier | a265049 | 2018-07-11 23:05:58 +0200 | [diff] [blame] | 173 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 174 | print("HPLMNAcT: Can't read file -- " + str(e)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 175 | |
| 176 | # EF.ACC |
Supreeth Herle | d1fb6fc | 2020-03-19 12:45:45 +0100 | [diff] [blame] | 177 | (res, sw) = card.read_binary('ACC') |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 178 | if sw == '9000': |
| 179 | print("ACC: %s" % (res,)) |
| 180 | else: |
| 181 | print("ACC: Can't read, response code = %s" % (sw,)) |
| 182 | |
| 183 | # EF.MSISDN |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 184 | try: |
Supreeth Herle | 6d66af6 | 2020-03-19 12:49:16 +0100 | [diff] [blame] | 185 | (res, sw) = card.read_msisdn() |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 186 | if sw == '9000': |
Supreeth Herle | 6d66af6 | 2020-03-19 12:49:16 +0100 | [diff] [blame] | 187 | # (npi, ton, msisdn) = res |
| 188 | if res is not None: |
| 189 | print("MSISDN (NPI=%d ToN=%d): %s" % res) |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 190 | else: |
| 191 | print("MSISDN: Not available") |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 192 | else: |
Sylvain Munaut | 9f13897 | 2013-07-18 10:36:51 +0200 | [diff] [blame] | 193 | print("MSISDN: Can't read, response code = %s" % (sw,)) |
Philipp Maier | ea6bdf0 | 2018-07-11 23:02:36 +0200 | [diff] [blame] | 194 | except Exception as e: |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 195 | print("MSISDN: Can't read file -- " + str(e)) |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 196 | |
Philipp Maier | ee908ae | 2019-03-21 16:21:12 +0100 | [diff] [blame] | 197 | # EF.AD |
Supreeth Herle | 52ef675 | 2020-03-19 12:50:27 +0100 | [diff] [blame] | 198 | (res, sw) = card.read_binary('AD') |
Philipp Maier | ee908ae | 2019-03-21 16:21:12 +0100 | [diff] [blame] | 199 | if sw == '9000': |
Vadim Yanitskiy | dfe3dbb | 2020-07-28 05:26:02 +0700 | [diff] [blame] | 200 | print("Administrative data: %s" % (res,)) |
Robert Falkenberg | 9d16fbc | 2021-04-12 11:43:22 +0200 | [diff] [blame] | 201 | ad = EF_AD() |
| 202 | decoded_data = ad.decode_hex(res) |
| 203 | print("\tMS operation mode: %s" % decoded_data['ms_operation_mode']) |
| 204 | if decoded_data['ofm']: |
Vadim Yanitskiy | dfe3dbb | 2020-07-28 05:26:02 +0700 | [diff] [blame] | 205 | print("\tCiphering Indicator: enabled") |
| 206 | else: |
| 207 | print("\tCiphering Indicator: disabled") |
Philipp Maier | ee908ae | 2019-03-21 16:21:12 +0100 | [diff] [blame] | 208 | else: |
| 209 | print("AD: Can't read, response code = %s" % (sw,)) |
| 210 | |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 211 | # EF.SST |
Supreeth Herle | d3b13d0 | 2020-04-20 13:30:34 +0200 | [diff] [blame] | 212 | (res, sw) = card.read_binary('SST') |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 213 | if sw == '9000': |
Supreeth Herle | d3b13d0 | 2020-04-20 13:30:34 +0200 | [diff] [blame] | 214 | print("SIM Service Table: %s" % res) |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 215 | # Print those which are available |
Supreeth Herle | d3b13d0 | 2020-04-20 13:30:34 +0200 | [diff] [blame] | 216 | print("%s" % dec_st(res)) |
Supreeth Herle | e26331e | 2020-03-20 18:50:39 +0100 | [diff] [blame] | 217 | else: |
| 218 | print("SIM Service Table: Can't read, response code = %s" % (sw,)) |
| 219 | |
Supreeth Herle | 9641299 | 2020-03-22 08:20:11 +0100 | [diff] [blame] | 220 | # Check whether we have th AID of USIM, if so select it by its AID |
| 221 | # EF.UST - File Id in ADF USIM : 6f38 |
Philipp Maier | cba6dbc | 2021-03-11 13:03:18 +0100 | [diff] [blame] | 222 | data, sw = card.select_adf_by_aid(adf="usim") |
| 223 | if sw == '9000': |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 224 | # Select USIM profile |
| 225 | usim_card = UsimCard(scc) |
| 226 | |
Harald Welte | ca67394 | 2020-06-03 15:19:40 +0200 | [diff] [blame] | 227 | # EF.EHPLMN |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 228 | if usim_card.file_exists(EF_USIM_ADF_map['EHPLMN']): |
| 229 | (res, sw) = usim_card.read_ehplmn() |
Harald Welte | ca67394 | 2020-06-03 15:19:40 +0200 | [diff] [blame] | 230 | if sw == '9000': |
| 231 | print("EHPLMN:\n%s" % (res)) |
| 232 | else: |
| 233 | print("EHPLMN: Can't read, response code = %s" % (sw,)) |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 234 | |
Supreeth Herle | 9641299 | 2020-03-22 08:20:11 +0100 | [diff] [blame] | 235 | # EF.UST |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 236 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 237 | if usim_card.file_exists(EF_USIM_ADF_map['UST']): |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 238 | # res[0] - EF content of UST |
| 239 | # res[1] - Human readable format of services marked available in UST |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 240 | (res, sw) = usim_card.read_ust() |
herlesupreeth | 4a3580b | 2020-09-29 10:11:36 +0200 | [diff] [blame] | 241 | if sw == '9000': |
| 242 | print("USIM Service Table: %s" % res[0]) |
| 243 | print("%s" % res[1]) |
| 244 | else: |
| 245 | print("USIM Service Table: Can't read, response code = %s" % (sw,)) |
| 246 | except Exception as e: |
| 247 | print("USIM Service Table: Can't read file -- " + str(e)) |
Supreeth Herle | 9641299 | 2020-03-22 08:20:11 +0100 | [diff] [blame] | 248 | |
Supreeth Herle | b1634db | 2020-03-22 10:00:43 +0100 | [diff] [blame] | 249 | #EF.ePDGId - Home ePDG Identifier |
| 250 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 251 | if usim_card.file_exists(EF_USIM_ADF_map['ePDGId']): |
| 252 | (res, sw) = usim_card.read_epdgid() |
herlesupreeth | f8232db | 2020-09-29 10:03:06 +0200 | [diff] [blame] | 253 | if sw == '9000': |
| 254 | print("ePDGId:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 255 | else: |
| 256 | print("ePDGId: Can't read, response code = %s" % (sw,)) |
Supreeth Herle | b1634db | 2020-03-22 10:00:43 +0100 | [diff] [blame] | 257 | except Exception as e: |
| 258 | print("ePDGId: Can't read file -- " + str(e)) |
| 259 | |
Supreeth Herle | 99d5555 | 2020-03-24 13:03:43 +0100 | [diff] [blame] | 260 | #EF.ePDGSelection - ePDG Selection Information |
| 261 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 262 | if usim_card.file_exists(EF_USIM_ADF_map['ePDGSelection']): |
| 263 | (res, sw) = usim_card.read_ePDGSelection() |
Supreeth Herle | 99d5555 | 2020-03-24 13:03:43 +0100 | [diff] [blame] | 264 | if sw == '9000': |
| 265 | print("ePDGSelection:\n%s" % (res,)) |
| 266 | else: |
| 267 | print("ePDGSelection: Can't read, response code = %s" % (sw,)) |
| 268 | except Exception as e: |
| 269 | print("ePDGSelection: Can't read file -- " + str(e)) |
| 270 | |
Supreeth Herle | 5ad9aec | 2020-03-24 17:26:40 +0100 | [diff] [blame] | 271 | # Select ISIM application by its AID |
Philipp Maier | cba6dbc | 2021-03-11 13:03:18 +0100 | [diff] [blame] | 272 | data, sw = card.select_adf_by_aid(adf="isim") |
| 273 | if sw == '9000': |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 274 | # Select USIM profile |
| 275 | isim_card = IsimCard(scc) |
| 276 | |
Supreeth Herle | 5ad9aec | 2020-03-24 17:26:40 +0100 | [diff] [blame] | 277 | #EF.P-CSCF - P-CSCF Address |
| 278 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 279 | if isim_card.file_exists(EF_ISIM_ADF_map['PCSCF']): |
| 280 | res = isim_card.read_pcscf() |
Supreeth Herle | 5ad9aec | 2020-03-24 17:26:40 +0100 | [diff] [blame] | 281 | print("P-CSCF:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 282 | except Exception as e: |
| 283 | print("P-CSCF: Can't read file -- " + str(e)) |
| 284 | |
Supreeth Herle | 05b2807 | 2020-03-25 10:23:48 +0100 | [diff] [blame] | 285 | # EF.DOMAIN - Home Network Domain Name e.g. ims.mncXXX.mccXXX.3gppnetwork.org |
| 286 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 287 | if isim_card.file_exists(EF_ISIM_ADF_map['DOMAIN']): |
| 288 | (res, sw) = isim_card.read_domain() |
Supreeth Herle | 05b2807 | 2020-03-25 10:23:48 +0100 | [diff] [blame] | 289 | if sw == '9000': |
| 290 | print("Home Network Domain Name: %s" % (len(res) and res or 'Not available',)) |
| 291 | else: |
| 292 | print("Home Network Domain Name: Can't read, response code = %s" % (sw,)) |
| 293 | except Exception as e: |
| 294 | print("Home Network Domain Name: Can't read file -- " + str(e)) |
| 295 | |
Supreeth Herle | 3f67f9c | 2020-03-25 15:38:02 +0100 | [diff] [blame] | 296 | # EF.IMPI - IMS private user identity |
| 297 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 298 | if isim_card.file_exists(EF_ISIM_ADF_map['IMPI']): |
| 299 | (res, sw) = isim_card.read_impi() |
Supreeth Herle | 3f67f9c | 2020-03-25 15:38:02 +0100 | [diff] [blame] | 300 | if sw == '9000': |
| 301 | print("IMS private user identity: %s" % (len(res) and res or 'Not available',)) |
| 302 | else: |
| 303 | print("IMS private user identity: Can't read, response code = %s" % (sw,)) |
| 304 | except Exception as e: |
| 305 | print("IMS private user identity: Can't read file -- " + str(e)) |
| 306 | |
Supreeth Herle | 0c02d8a | 2020-03-26 09:00:06 +0100 | [diff] [blame] | 307 | # EF.IMPU - IMS public user identity |
| 308 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 309 | if isim_card.file_exists(EF_ISIM_ADF_map['IMPU']): |
| 310 | res = isim_card.read_impu() |
Supreeth Herle | 0c02d8a | 2020-03-26 09:00:06 +0100 | [diff] [blame] | 311 | print("IMS public user identity:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 312 | except Exception as e: |
| 313 | print("IMS public user identity: Can't read file -- " + str(e)) |
| 314 | |
Supreeth Herle | be3b641 | 2020-06-01 12:53:57 +0200 | [diff] [blame] | 315 | # EF.UICCIARI - UICC IARI |
| 316 | try: |
herlesupreeth | cebf8b1 | 2021-01-21 05:57:06 +0100 | [diff] [blame] | 317 | if isim_card.file_exists(EF_ISIM_ADF_map['UICCIARI']): |
| 318 | res = isim_card.read_iari() |
Supreeth Herle | be3b641 | 2020-06-01 12:53:57 +0200 | [diff] [blame] | 319 | print("UICC IARI:\n%s" % (len(res) and res or '\tNot available\n',)) |
| 320 | except Exception as e: |
| 321 | print("UICC IARI: Can't read file -- " + str(e)) |
| 322 | |
Supreeth Herle | ee15c77 | 2020-03-22 08:58:33 +0100 | [diff] [blame] | 323 | # Check whether we have th AID of ISIM, if so select it by its AID |
| 324 | # EF.IST - File Id in ADF ISIM : 6f07 |
Philipp Maier | cba6dbc | 2021-03-11 13:03:18 +0100 | [diff] [blame] | 325 | data, sw = card.select_adf_by_aid(adf="isim") |
| 326 | if sw == '9000': |
Supreeth Herle | ee15c77 | 2020-03-22 08:58:33 +0100 | [diff] [blame] | 327 | # EF.IST |
| 328 | (res, sw) = card.read_binary('6f07') |
| 329 | if sw == '9000': |
| 330 | print("ISIM Service Table: %s" % res) |
| 331 | # Print those which are available |
| 332 | print("%s" % dec_st(res, table="isim")) |
| 333 | else: |
| 334 | print("ISIM Service Table: Can't read, response code = %s" % (sw,)) |
| 335 | |
Alexander Chemeris | 6e58914 | 2013-07-04 17:34:06 +0400 | [diff] [blame] | 336 | # Done for this card and maybe for everything ? |
Vadim Yanitskiy | 6727f0c | 2020-01-22 23:38:24 +0700 | [diff] [blame] | 337 | print("Done !\n") |