aboutsummaryrefslogtreecommitdiffstats
path: root/pySim-prog.py
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2012-08-15 15:56:05 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-08-15 21:09:01 +0200
commit44e4636755f2218a57fa2c983e5905e91f096462 (patch)
tree5d2fcb38360a2d613afa98d1aa35b776b9bca559 /pySim-prog.py
parent93315bd4663c87856cb5a64c16d7fedcab4a8bb6 (diff)
re-program: Instead of specifying the IMSI, read it from the card.zecke/hacks
Diffstat (limited to 'pySim-prog.py')
-rwxr-xr-xpySim-prog.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/pySim-prog.py b/pySim-prog.py
index 65b625f..02e99ea 100755
--- a/pySim-prog.py
+++ b/pySim-prog.py
@@ -111,6 +111,9 @@ def parse_options():
parser.add_option("--op", dest="op",
help="Set OP to derive OPC from OP and KI",
)
+ parser.add_option("--read-imsi", dest="read_imsi", action="store_true",
+ help="Read the IMSI from the CARD", default=False
+ )
parser.add_option("-z", "--secret", dest="secret", metavar="STR",
@@ -150,8 +153,8 @@ def parse_options():
sys.exit(0)
if options.source == 'csv':
- if (options.imsi is None) and (options.batch_mode is False):
- parser.error("CSV mode needs either an IMSI or batch mode")
+ if (options.imsi is None) and (options.batch_mode is False) and (options.read_imsi is False):
+ parser.error("CSV mode needs either an IMSI, --read-imsi or batch mode")
if options.read_csv is None:
parser.error("CSV mode requires a CSV input file")
elif options.source == 'cmdline':
@@ -404,7 +407,7 @@ def _read_params_csv(opts, imsi):
cr = csv.DictReader(f, row)
i = 0
for row in cr:
- if opts.num is not None:
+ if opts.num is not None and opts.read_imsi is False:
if opts.num == i:
f.close()
return row;
@@ -585,7 +588,16 @@ if __name__ == '__main__':
if opts.source == 'cmdline':
cp = gen_parameters(opts)
elif opts.source == 'csv':
- cp = read_params_csv(opts, opts.imsi)
+ if opts.read_imsi:
+ if opts.dry_run:
+ # Connect transport
+ print "Insert card now (or CTRL-C to cancel)"
+ sl.wait_for_card(newcardonly=not first)
+ (res,_) = scc.read_binary(['3f00', '7f20', '6f07'])
+ imsi = swap_nibbles(res)[3:]
+ else:
+ imsi = opts.imsi
+ cp = read_params_csv(opts, imsi)
if cp is None:
print "Error reading parameters\n"
sys.exit(2)