3.3. Software Quickstart

3.3.1. Import and connect to LEIA

[1]:
# We import the leia package
import smartleia as sl
[2]:
# Connect to the reader
reader = sl.LEIA()

3.3.2. Open a connection to a smartcard

[3]:
# Verify the card is detected
reader.is_card_inserted()
[3]:
True
[4]:
# Initialize a connection to a card
reader.configure_smartcard(protocol_to_use=1,  # Use T=1
                           ETU_to_use=None,    # Let the reader determine the ETU to use
                           freq_to_use=None,   # Let the reader determine the freq to use
                           negotiate_pts=True, # Let the reader negotiate the PTS
                           negotiate_baudrate=True
)
[5]:
# This is the same, but there is no need to force optionnal parameters
reader.configure_smartcard(protocol_to_use=1)  # Use T=1
[6]:
ATR = reader.get_ATR()
ATR
[6]:
ATR(
    ts=0x3B,
    t0=0xF9,
    ta=[0x13, 0x00, 0xFE, 0x00],
    tb=[0x00, 0x00, 0x45, 0x00],
    tc=[0x00, 0x00, 0x00, 0x00],
    td=[0x81, 0x31, 0x00, 0x00],
    h=[0x4A, 0x43, 0x4F, 0x50,
       0x32, 0x34, 0x32, 0x52,
       0x33, 0x00, 0x00, 0x00,
       0x00, 0x00, 0x00, 0x00],
    t_mask=[0x05, 0x05, 0x01, 0x03],
    h_num=0x09,
    tck=0xA2,
    tck_present=0x01,
    D_i_curr=4,
    F_i_curr=372,
    f_max_curr=5000000,
    T_protocol_curr=1,
    ifsc=0
)
[7]:
# We can pick parameters
print(f"We are using protocol T={ATR.T_protocol_curr} and the frequence of the ISO7816 clock is {ATR.f_max_curr/1000} kHz !")
We are using protocol T=1 and the frequence of the ISO7816 clock is 5000.0 kHz !

3.3.3. It’s time to send our first APDU !

[8]:
apdu_select = sl.APDU(cla=0x00, ins=0x01, p1=0x00, p2=0x00)
apdu_select
[8]:
APDU(cla=0x0, ins=0x1, p1=0x0, p2=0x0, lc=0, le=0, send_le=1)
[9]:
resp = reader.send_APDU(apdu_select)
resp
[9]:
RESP(sw1=0x6D, sw2=0x00, le=0x0)

3.3.4. Because we always should to that…

[10]:
reader.close()

3.3.5. Other things we can do…

[ ]:
# Restart LEIA in DFU mode for flashing an update
reader.dfu()
[ ]:
# Restart LEIA in Funcard AVR flasher mode (since LEIA-Solo v1.4)
reader.flasher()