Giter Site home page Giter Site logo

italia / cie-pn532 Goto Github PK

View Code? Open in Web Editor NEW
24.0 17.0 8.0 2.12 MB

Arduino library for SPI and I2C access to the NFC chip in the Italian Electronic Identity Card (CIE)

License: BSD 3-Clause "New" or "Revised" License

C++ 99.34% C 0.66%
arduino nfc cie

cie-pn532's Introduction

cie-PN532

Arduino library for SPI access to the PN532 NFC chip in the Italian Electronic Identity Card (CIE).


Warning


Online resources

Online documentation Demonstration video

Prerequisites

This library depends upon a modified version of the Adafruit_PN532 library which you can obtain from this GitHub Repository.

https://github.com/BrightSoul/Adafruit-PN532

You must install the Adafruit_PN532 and cie_PN532 in your Arduino libraries directory. Plese follow the instructions from the Arduino guide.

https://www.arduino.cc/en/Guide/Libraries

Wiring PN532 breakout to the Arduino Uno for SPI communication

At present, just the SPI connection is supported. The examples provided will work with this wiring.

images/pn532-wiring-spi.png

This wiring is also described in detail on this page at the Adafruit website.

https://learn.adafruit.com/adafruit-pn532-rfid-nfc/breakout-wiring

Getting started

Create a new arduino project and set it up like this:

//Include some libraries
#include <Wire.h>
#include <SPI.h>
#include <cie_PN532.h>

//Use the cie_PN532 with the typical wiring, as pointed out above
cie_PN532 cie();

void setup(void) {
  #ifndef ESP8266
    while (!Serial); // for Leonardo/Micro/Zero
  #endif
  Serial.begin(115200);
  //Initialize the PN532 breakout board
  cie.begin();
}

Then, in your loop, wait for a card then read its ID_Servizi (a low-security unique identifier)

void loop(void) {
  //Let's see if a card is present
  bool cardDetected = cie.detectCard();
  if (!cardDetected) {
    //No card present, we wait for one
    delay(100);
    return;
  }

  //Good! A card is present, let's read the ID!
  word bufferLength = EF_ID_SERVIZI_LENGTH;
  byte buffer[EF_ID_SERVIZI_LENGTH];

  if (!cie.read_EF_ID_Servizi(buffer, &bufferLength)) {
    Serial.print(F("Error reading EF.ID_SERVIZI"));
    delay(1000);
    return;
  }

  //We were able to read the ID_Servizi, print it out!
  Serial.print(F("EF.ID_Servizi: "));
  cie.printHex(buffer, bufferLength);
}

More examples

This library comes with an examples directory. You can load and run examples from the Arduino IDE by clicking the File menu -> Examples -> cie 532.

Useful links

  • The CIE 3.0 chip specification (italian)

http://www.agid.gov.it/sites/default/files/documentazione/cie_3.0_-_specifiche_chip.pdf

  • Technical specification for the European Card for e-Services and National e-ID Applications

http://www.unsads.com/specs/IASECC/IAS_ECC_v1.0.1_UK.pdf

  • Specifiche tecniche del documento digitale unificato (italian)

http://www.agid.gov.it/sites/default/files/leggi_decreti_direttive/specifiche_tecniche_del_documento_digitale_unificato_v.1.0.0.pdf

cie-pn532's People

Contributors

alranel avatar azzeccagarbugli avatar brightsoul avatar ruphy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cie-pn532's Issues

Development of an Arduino library for reading the NIS code

Reading most data from an Italian Electronic Identity Card (CIE) requires user interaction for entering a PIN. This is handled by the middleware which runs on a full fledged operating system.
Still, there's an important bit of information which can be retrieved from a CIE without any pin, just by swiping it on a NFC reader: it's the NIS code which identifies each card uniquely.

The NIS code can be mapped to the person's Codice Fiscale just by querying a web service operated by the Government (not available yet). Such feature allows third parties to use CIE cards for access turnstiles (offices, gyms, etc.) because users can be mapped to the local database using the Codice Fiscale.

It would be very useful if people could read the NIS code using an Arduino connected to a NFC card reader. Any reader which supports ISO14443 works with CIE. The most common NFC chip for Arduino is the PN532 which supports that standard, so it should just work (although nobody tested so far).

The most complete library for lower level access to PN532 is the one from Adafruit: https://github.com/adafruit/Adafruit-PN532

See italia/cie-nis-python-sdk#1 for more guidance.

(Hint for people participating in the Hack.Developers code sprint: build an actual physical prototype! We will have test CIE cards in the 5 main locations.)

NIS read error for some CIEs

I'm using a ModeMCU - ESP8266 board
with this NFC reader: https://it.aliexpress.com/item/33014782756.html?spm=a2g0s.9042311.0.0.6d6e4c4dy4vnIS

and running this code:

#include <SPI.h> // Serial Peripheral Interface
#include <cie_PN532.h> //For read CIE's NIS with PN532 NFC RFID Module

#define PN532_SCK  (D5)
#define PN532_MISO (D6)
#define PN532_MOSI (D7)
#define PN532_SS   (D4)

cie_PN532 cie(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

word bufferLength = EF_ID_SERVIZI_LENGTH;
byte NIScode[EF_ID_SERVIZI_LENGTH];
  
void setup(void) {
  Serial.begin(115200);
  cie.begin();
}


void loop(void) {
  
  bool cardDetected = cie.detectCard();
  if (!cardDetected) {
    //No card present, we wait for one
    delay(100);
    return;
  }

  //Good! A card is present, let's read the NIS!
  
  if (!cie.read_EF_ID_Servizi(NIScode, &bufferLength)) {
    Serial.print("Error reading EF.ID_SERVIZI"); Serial.println(); Serial.println();
    delay(1000);
    return;
  }

  
  Serial.print(F("EF.ID_Servizi: "));
  
  String NIS_cie = "";
  for(int n = 0; n < bufferLength; n++){
  NIS_cie += String(NIScode[n]);
  }
  
  Serial.println(NIS_cie);
  Serial.println("Read complete, you can remove the card now");
  Serial.println();
  
}

I've the following issue:
Trying to read three different CIEs, one of these NIS cannot be read.
This is the output from Serial Monitor:

11:52:23.583 -> Tag number: 1
11:52:23.939 -> EF.ID_Servizi: 57<censored><censored>6
11:52:23.939 -> Read complete, you can remove the card now
11:52:23.939 -> 
11:53:00.175 -> Tag number: 1
11:53:00.406 -> File or application not found 0x6A 0x82   //Error reading this second CIE's NIS
11:53:00.406 -> Couldn't select the IAS application
11:53:00.406 -> Error reading EF.ID_SERVIZI
11:53:00.406 -> 
11:53:08.652 -> Tag number: 1
11:53:09.043 -> EF.ID_Servizi: 56<censored><censored>9
11:53:09.043 -> Read complete, you can remove the card now
11:53:09.043 -> 

How can I fix it?

Thank you in advance

Failure with PN532

I tried using this library with one of the popular red PN532 modules.
It didn't work. Was this library tested only with the Adafruit module?

This is the serial output using the ReadAll example (with cie.verbose = true):

Found chip PN532
Firmware ver. 1.6
PN53x initialized, waiting for a CIE card...
TIMEOUT!
TIMEOUT!
TIMEOUT!
Tag number: 1
Command (success): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Command (success): 0x00 0xA4 0x00 0x0C 0x02 0x3F 0x00
Command (success): 0x00 0xA4 0x02 0x0C 0x02 0xD0 0x03
Command (success): 0x00 0xB1 0x00 0x00 0x04 0x54 0x02 0x00 0x00 0x0E
EF_SN_ICC (12 bytes, 651 ms) [12 OCTETS STRIPPED]
We have 1302 bytes of memory left
Command (success): 0x00 0xA4 0x02 0x0C 0x02 0xD0 0x04
Command (success): 0x00 0xB1 0x00 0x00 0x04 0x54 0x02 0x00 0x00 0x03
Command (failure): 0x00 0xB1 0x00 0x00 0x04 0x54 0x02 0x00 0x01 0x03
Couldn't fetch the elementary file content
Couldn't detect a tag in the BER content
Error reading EF_DH
We have 1302 bytes of memory left
Command (failure): 0x00 0xB1 0x00 0x1D 0x04 0x54 0x02 0x00 0x21 0x06
Couldn't fetch the elementary file content
Error reading EF_ATR
We have 1302 bytes of memory left
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_ID_Servizi
We have 1302 bytes of memory left
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_Int_Kpub
We have 1318 bytes of memory left
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_Servizi_Int_Kpub
We have 1318 bytes of memory left
EF_SOD
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Couldn't detect a tag in the BER content
EF_SOD length was 0
We have 1318 bytes of memory left

Read complete, you can remove the card now

Verifica PIN Code

Sulla documentazione e sul codice non ho trovato nessun riferimento alla funzione di verifica del PIN. รˆ possibile avere maggiori info a riguardo? La versione attuale, consente il check del PIN?
@alranel o @BrightSoul potreste darmi qualche indicazione? Grazie.

"File or application not found; Command (failure) [...]" for every field

Ciao! I've received my CIE a few days ago and i wanted to test it with this library. I happend to have a PN532 shield from Adafruit. I've installed this lib and the modified PN532 library linked in the readme, i've uploaded the ReadAll example to my arduino Uno, to which i've connected the shield with power and the 4 SPI signals following the pin numbering suggested by the example.
I've left out the reset and IRQ pins, as their declaration is commented in the example.

Sadly i don't have anything else to test that my CIE is properly working, any suggestion will be appreciated.

Following is the log with the verbose option:

Found chip PN532
Firmware ver. 1.6
PN53x initialized, waiting for a CIE card...
TIMEOUT!
Tag number: 1
File or application not found 0x6A 0x82
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_SN_ICC
We have 1302 bytes of memory left
File or application not found 0x6A 0x82
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Couldn't detect a tag in the BER content
Error reading EF_DH
We have 1302 bytes of memory left
File or application not found 0x6A 0x82
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_ATR
We have 1302 bytes of memory left
File or application not found 0x6A 0x82
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_ID_Servizi
We have 1302 bytes of memory left
File or application not found 0x6A 0x82
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_Int_Kpub
We have 1318 bytes of memory left
File or application not found 0x6A 0x82
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Error reading EF_Servizi_Int_Kpub
We have 1318 bytes of memory left
EF_SOD
File or application not found 0x6A 0x82
Command (failure): 0x00 0xA4 0x04 0x0C 0x0D 0xA0 0x00 0x00 0x00 0x30 0x80 0x00 0x00 0x00 0x09 0x81 0x60 0x01
Couldn't select the IAS application
Couldn't detect a tag in the BER content
EF_SOD length was 0
We have 1318 bytes of memory left

Read complete, you can remove the card now
TIMEOUT!
TIMEOUT!

As a test, i've also tryed with a regular MiFare card, the output is slightly different, giving "Don't know how to handle this command: 81" instead of "File or application not found 0x6A 0x82"

I've opened a different issue from #3 since in my case it doesn't run succesfully the first commands

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.