Exemplo n.º 1
0
        from pySim.transport.pcsc import PcscSimLink
        sl = PcscSimLink(opts.pcsc_dev)

    # Create command layer
    scc = SimCardCommands(transport=sl)

    # Wait for SIM card
    sl.wait_for_card()

    # Program the card
    print("Reading ...")

    # EF.ICCID
    (res, sw) = scc.read_binary(['3f00', '2fe2'])
    if sw == '9000':
        print("ICCID: %s" % (dec_iccid(res), ))
    else:
        print("ICCID: Can't read, response code = %s" % (sw, ))

    # EF.IMSI
    (res, sw) = scc.read_binary(['3f00', '7f20', '6f07'])
    if sw == '9000':
        print("IMSI: %s" % (dec_imsi(res), ))
    else:
        print("IMSI: Can't read, response code = %s" % (sw, ))

    # EF.SMSP
    (res, sw) = scc.read_record(['3f00', '7f10', '6f42'], 1)
    if sw == '9000':
        print("SMSP: %s" % (res, ))
    else:
Exemplo n.º 2
0
		from pySim.transport.pcsc import PcscSimLink
		sl = PcscSimLink(opts.pcsc_dev)

	# Create command layer
	scc = SimCardCommands(transport=sl)

	# Wait for SIM card
	sl.wait_for_card()

	# Program the card
	print("Reading ...")

	# EF.ICCID
	(res, sw) = scc.read_binary(['3f00', '2fe2'])
	if sw == '9000':
		print("ICCID: %s" % (dec_iccid(res),))
	else:
		print("ICCID: Can't read, response code = %s" % (sw,))

	# EF.IMSI
	(res, sw) = scc.read_binary(['3f00', '7f20', '6f07'])
	if sw == '9000':
		print("IMSI: %s" % (dec_imsi(res),))
	else:
		print("IMSI: Can't read, response code = %s" % (sw,))

	# EF.SMSP
	(res, sw) = scc.read_record(['3f00', '7f10', '6f42'], 1)
	if sw == '9000':
		print("SMSP: %s" % (res,))
	else:
Exemplo n.º 3
0
def process_card(opts, first, card_handler):

    if opts.dry_run is False:
        # Connect transport
        card_handler.get(first)

    if opts.dry_run is False:
        # Get card
        card = card_detect(opts.type, scc)
        if card is None:
            print("No card detected!")
            return -1

        # Probe only
        if opts.probe:
            return 0

        # Erase if requested
        if opts.erase:
            print("Formatting ...")
            card.erase()
            card.reset()

    # Generate parameters
    if opts.source == 'cmdline':
        cp = gen_parameters(opts)
    elif opts.source == 'csv':
        imsi = None
        iccid = None
        if opts.read_iccid:
            if opts.dry_run:
                # Connect transport
                card_handler.get(False)
            (res, _) = scc.read_binary(['3f00', '2fe2'], length=10)
            iccid = dec_iccid(res)
        elif opts.read_imsi:
            if opts.dry_run:
                # Connect transport
                card_handler.get(False)
            (res, _) = scc.read_binary(EF['IMSI'])
            imsi = swap_nibbles(res)[3:]
        else:
            imsi = opts.imsi
        cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
    if cp is None:
        print("Error reading parameters from CSV file!\n")
        return 2
    print_parameters(cp)

    if opts.dry_run is False:
        # Program the card
        print("Programming ...")
        card.program(cp)
    else:
        print("Dry Run: NOT PROGRAMMING!")

    # Write parameters permanently
    write_parameters(opts, cp)

    # Batch mode state update and save
    if opts.num is not None:
        opts.num += 1
    save_batch(opts)

    card_handler.done()
    return 0
Exemplo n.º 4
0
				card.erase()
				card.reset()

		# Generate parameters
		if opts.source == 'cmdline':
			cp = gen_parameters(opts)
		elif opts.source == 'csv':
                        imsi = None
                        iccid = None
			if opts.read_iccid:
				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', '2fe2'], length=10)
				iccid = dec_iccid(res)
                                print iccid
                        elif 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(EF['IMSI'])
				imsi = swap_nibbles(res)[3:]
			else:
				imsi = opts.imsi
			cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
		if cp is None:
			print "Error reading parameters\n"
			sys.exit(2)
		print_parameters(cp)