{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Software Quickstart" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import and connect to LEIA" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# We import the leia package\n", "import smartleia as sl" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Connect to the reader\n", "reader = sl.LEIA()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Open a connection to a smartcard" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Verify the card is detected\n", "reader.is_card_inserted()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Initialize a connection to a card\n", "reader.configure_smartcard(protocol_to_use=1, # Use T=1\n", " ETU_to_use=None, # Let the reader determine the ETU to use\n", " freq_to_use=None, # Let the reader determine the freq to use\n", " negotiate_pts=True, # Let the reader negotiate the PTS\n", " negotiate_baudrate=True\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "# This is the same, but there is no need to force optionnal parameters\n", "reader.configure_smartcard(protocol_to_use=1) # Use T=1" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "ATR(\n", " ts=0x3B,\n", " t0=0xF9,\n", " ta=[0x13, 0x00, 0xFE, 0x00],\n", " tb=[0x00, 0x00, 0x45, 0x00],\n", " tc=[0x00, 0x00, 0x00, 0x00],\n", " td=[0x81, 0x31, 0x00, 0x00],\n", " h=[0x4A, 0x43, 0x4F, 0x50,\n", " 0x32, 0x34, 0x32, 0x52,\n", " 0x33, 0x00, 0x00, 0x00,\n", " 0x00, 0x00, 0x00, 0x00],\n", " t_mask=[0x05, 0x05, 0x01, 0x03],\n", " h_num=0x09,\n", " tck=0xA2,\n", " tck_present=0x01,\n", " D_i_curr=4,\n", " F_i_curr=372,\n", " f_max_curr=5000000,\n", " T_protocol_curr=1,\n", " ifsc=0\n", ")" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ATR = reader.get_ATR()\n", "ATR" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "We are using protocol T=1 and the frequence of the ISO7816 clock is 5000.0 kHz !\n" ] } ], "source": [ "# We can pick parameters\n", "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 !\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## It's time to send our first APDU !" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "APDU(cla=0x0, ins=0x1, p1=0x0, p2=0x0, lc=0, le=0, send_le=1)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "apdu_select = sl.APDU(cla=0x00, ins=0x01, p1=0x00, p2=0x00)\n", "apdu_select" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "RESP(sw1=0x6D, sw2=0x00, le=0x0)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "resp = reader.send_APDU(apdu_select)\n", "resp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Because we always should to that..." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "reader.close()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Other things we can do..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Restart LEIA in DFU mode for flashing an update\n", "reader.dfu()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Restart LEIA in Funcard AVR flasher mode (since LEIA-Solo v1.4)\n", "reader.flasher()" ] } ], "metadata": { "kernelspec": { "display_name": "smartleia", "language": "python", "name": "smartleia" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.1" } }, "nbformat": 4, "nbformat_minor": 4 }