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