Waspmote Libelium User manual

RFID/NFC 13.56MHz
Networking Guide

-2-
v7.0
Index
Document version: v7.0 - 02/2017
© Libelium Comunicaciones Distribuidas S.L.
INDEX
1. Introduction......................................................................................................................................... 4
1.1. The standard ..................................................................................................................................................................................4
2. Hardware.............................................................................................................................................. 6
3. Dual radio with the Expansion Board ................................................................................................ 7
3.1. Expansion Radio Board ..............................................................................................................................................................7
3.2. Setting on .......................................................................................................................................................................................8
3.3. Setting o .......................................................................................................................................................................................8
4. RFID Tags .............................................................................................................................................. 9
5. Usage .................................................................................................................................................. 10
6. Security with RFID/NFC at 13.56 MHz .............................................................................................. 11
7. RFID 13.56 MHz and NFC................................................................................................................... 13
8. Libelium’s library ............................................................................................................................... 14
8.1. Library constructor...................................................................................................................................................................15
8.2. Switching the module on.......................................................................................................................................................16
8.3. Switching the module o ......................................................................................................................................................16
8.4. Initiating the module...............................................................................................................................................................16
8.5. Authenticating a sector .......................................................................................................................................................... 17
8.6. Reading a block .........................................................................................................................................................................17
8.7. Reading a block with authentication................................................................................................................................. 18
8.8. Writing in a block ......................................................................................................................................................................18
8.9. Writing in a block with authentication..............................................................................................................................18
8.10. Writing in a block and checking it ....................................................................................................................................19
8.11. Writing in a block with authentication and checking it ...........................................................................................19
8.12. Setting keys in a sector.........................................................................................................................................................19
8.13. Powering down ......................................................................................................................................................................20
8.14. Waking up .................................................................................................................................................................................20
8.15. Printing data.............................................................................................................................................................................21
8.16. Comparing UIDs......................................................................................................................................................................21
8.17. Searching a UID among a group of UIDs .......................................................................................................................21
8.18. Converting from a string to a uint8_t pointer..............................................................................................................22
8.19. Converting from a uint8_t pointer to an integer........................................................................................................22
9. Time of execution of the functions................................................................................................... 23

-3-
v7.0
10. Certications.................................................................................................................................... 24
11. Code examples and extended information................................................................................... 25
12. API changelog.................................................................................................................................. 28
Index

-4-
v7.0
Introduction
1. Introduction
This guide explains the RFID/NFC module features and functions. This product was designed for Waspmote v12 and continues
with no changes forWaspmote v15.There are no great variations in this library for our new product lines Waspmote v15, released
on October 2016.
Anyway, if you are using previous versions of our products, please use the corresponding guides, available on our Development
website.
You can get more information about the generation change on the document “New generation of Libelium product lines”.
1.1. The standard
RFID (Radio Frequency Identication) is a technology that uses electromagnetic elds to identify objects in a contactless way; it
is also called proximity identication. There are 2 elements in RFID communications: the RFID module (or reader/writer device)
and an RFID card (or tag). The RFID module acts as the master and the card acts as the slave; this means the module queries the
card and sends instructions to it. In a normal RFID communication, the RFID module is xed and the user takes his card near it
when he needs to start the interaction.
Figure : Waspmote with RFID/NFC module on socket 0 (below antenna) and ZigBee radio on socket 1
An RFID card can be understood as a remote storage unit where we can read and write information without contact. Most of the
RFID tags are passive, which implies that the RFID module must create an electromagnetic eld in order to power the tag. The
RFID card’s antenna (in fact it is an inductive coupler) gets the power from this eld. Also, an RFID card has a very basic micro-
controller which manages the communications and memory access.
Many RFID standards have been released by the industry. Most of them have as operating frequency 13.56 MHz or 125 kHz. In
the present document we will be explaining the RFID/NFC module, which works at 13.56 MHz.
In particular, Libelium has created an ISO/IEC 14443-A and NFC compliant module for Waspmote. The ISO/IEC 14443-A protocol
is widely accepted as the de facto RFID at 13.56 MHz standard. Billions of ISO/IEC14443-A cards have been sold over the world.
NFC (Near Field Communication) is an extension of RFID which focuses on communications between smartphones and other
advanced devices. NFC is a set of standards based on previous RFID protocols like ISO/IEC 14443-A.
There are basically 3 ways to interact with an RFID card; Libelium’s RFID/NFC module allows the developer to implement the 3 of them:
1. the RFID/NFC module reads the RFID card’s unique identication (UID)
2. the RFID/NFC module reads the RFID card’s internal memory (16 bytes each time)
3. the RFID/NFC module writes in the RFID card’s internal memory (16 bytes each time)

-5-
v7.0
Introduction
Among the RFID/NFC applications, the most common are:
• access control/security
• events ticketing
• public transport
• equipment and personnel tracking
• logistics
• real-time inventories
• marketing information (kiosks)
Figure : Some application examples

-6-
v7.0
Hardware
2. Hardware
Libelium’s RFID/NFC module integrates an RFID/NFC reader/writer integrated circuit.
Features
• Compatibility: Reader/writer mode supporting ISO 14443A / MIFARE / FeliCaTM / NFCIP-1
• Distance: 5cm
• Max capacity: 4KB
• Tags: cards, keyrings, stickers
Figure : RFID/NFC module for 13.56 MHz and antenna
Among several RFID standards; Libelium’s RFID/NFC module is compliant with ISO/IEC 14443-A/Mifare®, which probably are
the most successful international standards in RFID technology. Mifare® is a proprietary technology by NXP which is based on
the ISO/IEC 14443-A standard. This technology operates at the 13.56 MHz ISM frequency band, so it can be deployed anywhere
without authorization or license.
The RFID/NFC module implements the radio-frequency, analog and digital tasks in transmission and reception, whileWaspmote’s
role is to control these operations. Waspmote is connected to the RFID/NFC module through its UART interface.
The ISO/IEC 14443-A/Mifare® standard oers a 3-pass authentication method to enable secure, encrypted communications
between the RFID/NFC module and the card. Also, there are dierent mechanisms (CRC, parity, bit encoding, etc) to ensure the
data integrity.
The RFID/NFC module is also compatible with NFC, in particular with the standards ISO/IEC 18098 and NFCIP-1. The NFC
technology allows two-way communications between end-points that normally are smartphones or other advanced electronic
devices. An NFC communication can be set in a very quick way, which is a benet with regard to WiFi or Bluetooth.
The antenna is 57x57x10 mm and can be plugged in 2 directions, but for the best range we suggest to place it like in the photos,
standing out of the surface of Waspmote. Obviously, for projects with strict form factor specications, the antenna can be placed
over Waspmote. The antenna has a gain of around 33 dB and is congurable by the user.

-7-
v7.0
Dual radio with the Expansion Board
3. Dual radio with the Expansion Board
Before starting to use a module, it needs to be initialized. During this process, conguration parameters are sent to the module.
USB and SD card are also initialized.
3.1. Expansion Radio Board
The Expansion Board allows to connect two communication modules at the same time in the Waspmote sensor platform. This
means a lot of dierent combinations are possible using any of the wireless radios available for Waspmote: 802.15.4, ZigBee,
DigiMesh, 868 MHz, 900 MHz, LoRa, WiFi, GPRS, GPRS+GPS, 3G, 4G, Sigfox, LoRaWAN, Bluetooth Pro, Bluetooth Low Energy and
RFID/NFC. Besides, the following Industrial Protocols modules are available: RS-485/Modbus, RS-232 Serial/Modbus and CAN
Bus.
Some of the possible combinations are:
• LoRaWAN - GPRS
• 802.15.4 - Sigfox
• 868 MHz - RS-485
• RS-232 - WiFi
• DigiMesh - 4G
• RS-232 - RFID/NFC
• WiFi - 3G
• CAN bus - Bluetooth
• etc.
Remark: GPRS, GPRS+GPS, 3G and 4G modules do not need the Expansion Board to be connected to Waspmote. They can be plugged
directly in the socket1.
Next image shows the sockets available along with the UART assigned. On one hand, SOCKET0 allows to plug any kind of radio
module through the UART0. On the other hand, SOCKET1 permits to connect a radio module through the UART1.
Figure : Waspmote with XBee radio on socket 0 and Bluetooth module on socket 1

-8-
v7.0
Dual radio with the Expansion Board
This API provides a function in order to initialize the RFID/NFC module called RFID13.ON(socket). This function supports a
new parameter which permits to select the socket. It is possible to choose between socket0 or socket1.
An example of use the initialization function is the following:
• Selecting socket0: RFID13.ON(SOCKET0);
• Selecting socket1: RFID13.ON(SOCKET1);
The rest of functions are used the same way as they are used with older API versions. In order to understand them we recommend
to read this guide.
Warnings:
• Warnings:
• Avoid to use DIGITAL7 pin when working with the Expansion Board. This pin is used for setting the XBee into sleep mode.
• Avoid to use DIGITAL6 pin when working with the Expansion Board. This pin is used as power supply for the Expansion
Board.
• Incompatibility with Sensor Boards:
- Agriculture v30 and Agriculture PRO v30: Incompatible with Watermark and solar radiation sensors
- Events v30: Incompatible with interruption shift register
- Gases v30: DIGITAL6 is incompatible with CO2 (SOCKET_2) and DIGITAL7 is incompatible with NO2 (SOCKET_3)
- Smart Water v30: DIGITAL7 incompatible with conductivity sensor
- Smart Water Ions v30: Incompatible with ADC conversion (sensors cannot be read if the Expansion Board is in use)
- Gases PRO v30: Incompatible with SOCKET_2 and SOCKET_3
- Cities PRO v30: Incompatible with SOCKET_3. I2C bus can be used. No gas sensor can be used.
3.2. Setting on
With the function ON() module is powered and the UART is opened to communicate with the module. It also enters in command
mode and sets some default congurations.
// switches ON the RFID/NFC module using expansion board
RFID13.ON(SOCKET1);
3.3. Setting o
The RFID/NFC API function OFF() exits from the radio RFID/NFC command-mode securely, closes the UART and switches the
module o.
// closes the UART and powers off the module
RFID13.OFF();

-9-
v7.0
RFID Tags
4. RFID Tags
Libelium oers Mifare® Classic 1k cards tags and stickers along with the Waspmote RFID/NFC module. More than 3.5 billions of
this type of cards have been sold around the world up now.
An RFID card has a thin form factor (81x54x1 mm), like a driving license or identication card, and can be kept in the user’s wallet.
However, an RFID tag is smaller and thicker (around 20x20x5 mm) but can be kept in the user’s keyring. Last, an RFID sticker has
an intermediate size (50x50) and it is really thin and exible. Of course, a sticker can be stuck in any object so it focuses on the
Internet of Things (IoT) and logistics applications.
It is important to note that a card always has a longer range than a tag or sticker because the antenna of a card has more surface.
Figure : RFID cards Figure : RFID keyrings Figure : RFID sticker
A Mifare® Classic 1k card has 1024 bytes of internal storage capacity, divided into 16 sectors. Each sector is composed of 4 blocks, and
each block is composed of 16 bytes. That is to say, each card has 64 blocks, from number 0 to 63. Let’s describe the structure of a card:
1. In each sector, the last block (blocks number 3, 7, 11..) is called the sector trailer. This block stores the 2 keys or passwords
and controls the access to the rest of the blocks in the sector (e.g. block number 7 controls block 4, 5 and 6). The rst 6 bytes
(0..5) are the key A, and the last 5 bytes (10..15) are the key B. As we will see, before reading or writing in any block, we must
rst authenticate us to that sector by providing one of the two keys (normally the A key). The bytes number 6, 7 and 8 store
the control bytes, which control the way the the blocks may be accessed (read/write). Byte number 9 is not dened in all
sector trailers.
2. The very rst block (number 0) is called the manufacturer block and has special characteristics. The rst 4 bytes (0..3) are the
unique identication (UID). The UID can be seen as the serial number of the card and identify the card in a unequivocal way
(read more in the“Security with RFID/NFC at 13.56 MHz” chapter). The next byte (number 4) is the CRC check byte so it can
be used to check the correct read; it is calculated with the XOR of the 4-byte UID. The rest of the bytes in the block number
0 (bytes 5..15) are the manufacturer data. This block 0 has read-only access for security reasons. We need to authenticate
before reading the block number 0 but the UID can be obtained anyway, without the key.
3. The rest of the blocks (1 and 2; 4, 5 and 6; 8, 9 and 10; etc) are known as data blocks and they are available to read and write
operations, after the needed authentication process.
To sum up, the Mifare® 1k cards have a net storage capacity of:
(16 sectors/card x 3 data blocks/sector X 16 bytes/block) – 16 bytes (rst block) = 752 bytes/card
The cards have been tested to conserve data for 10 years and to have a write endurance of 100,000 cycles.

-10-
v7.0
Usage
5. Usage
• The maximum operational range is about 7 cm for a card and 5 cm for a tag or a sticker. A target beyond this distance
will not be detected, or the communications with it will be full of errors. Some RF-related registers in the module can be
trimmed to try to improve this range, but it is not really recommended.
• Besides, the minimum range is of a few mm. A card which is closer than this to the RFID/NFC module’s antenna could not
be detected.
• Optimal results are obtained when the card is placed parallel to the surface of the antenna, still and at a distance of 1 cm.
• It is advised to execute one init() function each time that we need to do some RFID operation, just like shown in the
examples. That will reset the module to the correct conguration and avoid problems.
• As shown in the examples, it is good to use“if’s”to control which functions are executed. For example, if the authenticate()
function was not successful, it does not make sense to execute one read() after that. Also, if the init() function was
not successful, or if it did not deliver an UID and a valid ATQ-A, it does not make sense to execute an authenticate()
afterwards. All functions should deliver ‘0’when executed correctly.
• When any of the functions does not deliver a successful execution, it is advised to end the loop and start the RFID/NFC
process from the beginning (from the init() function).
• A typical read or write process can take around 80 ms. Make sure the card remains within the eld until the whole process
is completed.
Figure : Typical RFID/NFC operation
• Some kind of indicator is strongly advised to let the user know that data exchange was successful. Waspmote can control a
LED (built-in or external) or a buzzer for this goal.
• After a successful operation, it is advised to execute a short delay (e.g. 2 seconds) to let the user take his card away. This way
we avoid to execute the same operation more than one time.
• The RFID/NFC antenna should be located in an accessible and comfortable place for the user.
• The RFID/NFC antenna, the RFID/NFC module, the battery or Waspmote are not waterproof, so an enclosure is mandatory
when the system is going to work outdoors. The antenna should be xed really close to the wall of the enclosure. Metallic
enclosures are not advised.
• In general, avoid placing the RFID/NFC antenna near metallic objects, since the communication range could decrease.
• It can be a good idea to place the antenna near the top of the enclosure, in parallel with the ground. This way the user can
just let the card lie still on top of the case for a while. Wherever the antenna is, do not forget to indicate in your enclosure
where it is.
• Use the Waspmote’s Expansion Board to enable another communication module to transmit certain (or all) RFID/NFC
operations to another device or to a data center.
• Use a micro SD card to store certain (or all) RFID/NFC operations. This can be a security back up.
• Add one Meshlium device to your ecosystem for advanced features such as Linux OS tools, MySQL data base storing system,
WiFi and Ethernet connectivity, remote web server or higher computing speed.

-11-
v7.0
Security with RFID/NFC at 13.56 MHz
6. Security with RFID/NFC at 13.56 MHz
The standard RFID ISO/IEC 14443-A cards have an UID with a length of 4 bytes, so there are 4,200 millions of dierent UIDs.
Besides, the A or B key has a length of 6 bytes. That means there are 2.8·1014 dierent possible passwords.
These numbers, along with the three pass authentication and the data integrity mechanisms, demonstrate RFID/NFC is a pretty
secure technology.
FAQs:
Q: Can I change the UID in a given card?
A: No, it is impossible. The block number 0, where the UID is stored, has read-only access. There are security reasons to do so:
if the block number 0 could be written, it would be possible to duplicate or forge cards.
Q: I heard that lately there are 7-byte UID cards, so there could exist a 7-byte UID card with the same beginning UID
than the standard 4-byte UID card. So the UID is not so “unique”. Is that true?
A: Yes, the manufacturers started producing cards with a UID of 7 bytes and there could be a 7-byte UID with its rst 4 bytes
equal than the ones in a standard 4-byte card.
Q: So can I consider a 4-byte UID card as unique or not?
A: No, but there is just one possibility among thousands of millions that you nd another card like yours.
Q: Can I order or select a specic UID for my card?
A: No, the cards’ UIDs are set in a random way.
Q: I do not know/remember the key for a certain block, can I read or write in that block?
A: No, it is not possible to access a block unless we have authenticated us in it. All cards are provided with both A and B keys by
default (0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF). If the user changes them, he must remember the change. The only thing we can
do without the keys of a card is to read its UID and ATQ.
Q: Are the RFID ISO/IEC 14443-A/Mifare® standards a 100% secure system?
A: No. Any security system has bugs that can be hacked. Besides, there are “security enhancers” integrated chips for RFID/NFC
that Libelium does not implement.
Q: Does Libelium recommend its RFID/NFC module for electronic money exchange?
A: No. The RFID/NFC module by Libelium is not intended for payment applications but for control of usage.
Q: Should I change the key to the cards?
A: Yes, you should if it is possible that someone is interested in reading or changing the stored information. Setting a new
key is a quick process and will ensure only the authorized agents can read or write the data. Avoid sharing or losing this
information.
We advise to set a random key. As a tip, it would be an even more secure system if each card has its own key (maybe
depending on its own UID).

-12-
v7.0
Security with RFID/NFC at 13.56 MHz
Since each sector can have dierent access keys, note it is possible to store public data in certain sectors and private, protected
data in other sectors. One example:
• sector 2: personal, general info (key only known by all the institutions of the city council)
• sector 3: city’s transport info (key only known by the bus company)
• sector 4: city’s library info (key only known by the library)
• sector 5: city’s gym (key only known by the gym)
• ...
On the other hand, if your system is just going to read UIDs, there is no point in changing keys.

-13-
v7.0
RFID 13.56 MHz and NFC
7. RFID 13.56 MHz and NFC
The aim of this chapter is to explain the dierences between RFID @ 13.56 MHz and NFC.
As said before, the NFC technology is dened by protocols like ISO/IEC 18098 and NFCIP-1. NFC is an extension of RFID @ 13.56
MHz (ISO/IEC 14443-A/Mifare® protocols) and bases on those protocols to build a technology which focuses on allowing an
instant and easy dialog between advanced electronic devices like smartphones. While RFID is meant to interchange very little
amounts of data (few bytes), NFC is meant to interchange bigger amounts of data.
Libelium’s RFID/NFC module supports both operations in a native way: RFID @ 13.56 MHz (ISO/IEC 14443-A/Mifare® protocols)
and NFC (NFCIP-1), but Libelium has not implemented software functions to handle the NFC operations. The reason to that
is that the most important applications of the RFID/NFC module for Wireless Sensor Networks are identifying and reading/
writing cards and tags, and not interchanging big amounts of data in very short range communications. Besides, only the most
advanced smartphones support NFC, so there are not many potential users yet with NFC-capable phones.
To sum up, the applications which benet the most from the RFID/NFC module are those related to access control, logistics,
assets tracking, supply chain, etc.

-14-
v7.0
Libelium’s library
8. Libelium’s library
It is mandatory to include the RFID library when using this module. The following line must be introduced at the beginning of
the code:
#include <WaspRFID13.h>
Waspmote’s API RFID/NFC les:
• WaspRFID13.cpp
• WaspRFID13.h
API functions
• Private functions:
The following functions are executed inside the API functions. In normal conditions, the user must NOT manage or use
them.
Function Brief description
bool congureSAM(void); set internal parameters of the PN532
sendTX(uint8_t *dataTX, uint8_t length, uint8_t outLength); Send data stored in dataTX
getACK(void); Wait for ACK response
waitResponse(void);* Wait the response of the module
getData(uint8_t outLength); Get data from the module
checkSum(uint8_t *dataTX); Calculates the checksum
uint8_t lengthCheckSum(uint8_t *dataTX); Calculates the length checksum
* To avoid the hang of the module this function will wait for 5 seconds approximately. If no tag is detected, the program will continue
after this time. The waiting time can be congured in the library.

-15-
v7.0
Libelium’s library
8.1. Library constructor
It is the class constructor. It is only executed inside the API’s function init().
• Public functions:
The following functions are public and therefore they can be executed in the loop() or setup() functions. They provide
the tools to perform all the features of the RFID/NFC module.
Function Brief description
OFF() switches the module o
ON(socket) switches the module on, in one of the 2 sockets
init(*UID, *ATQ) inits the module, congures it and searches for new cards
authenticate(*UID, ad, *key) authenticates one card’s sector
bool getFirmware(void) The PN532 sends back the version of the embedded rmware.
read(ad ,*data) reads one card’s block
readWithAuth(*UID, *key, *data, ad) authenticates one card's sector and reads one block
write(ad, *data) writes one card’s block
writeWithAuth(*UID, *key, *data, ad) authenticates one card's sector and writes one block
writeAndCheck(*data, ad) writes one card's block and checks that
writeAndCheckWithAuth(*UID, *key,
*data, ad) authenticates one card's sector, writes one block and checks that
uint8_t powerDown(void) put the module into Power Down mode
wakeUp(void) wake up from power dowm mode.
print( *data, length) print data stored in vectors
setKeys(*UID, *keyOld, *keyA, *keyB,
*cfg, *data, ad) changes both keys and access conditions to one card's sector
equalUIDs(*UID1, *UID2) compares 2 UIDs
searchUID(*vCards, *UID, nCards) searches one UID inside one group of UIDs
string2vector(*inp, *outp) converts from a string to a uint8_t vector
vector2int(*inp) converts from a uint8_t vector to a integer

-16-
v7.0
Libelium’s library
8.2. Switching the module on
This function takes the RFID/NFC module out of the power-down mode by starting the wake up procedure.
If you connected the RFID/NFC module into the usual XBee socket, please use SOCKET0; if you connected the RFID/NFC module
into the Expansion Board, you must use SOCKET1.
Example of use:
{
RFID13.ON(SOCKET0); // switches the module on with the socket 0 (the normal socket, without
// using the Expansion Board)
}
http://www.libelium.com/development/waspmote/examples/RFID1356-01-basic-example
8.3. Switching the module o
This function takes the RFID/NFC module to the software power-down mode.
Example of use:
{
RFID13.OFF(); // switches the module off
}
http://www.libelium.com/development/waspmote/examples/RFID1356-01-basic-example
8.4. Initiating the module
This function initializes the necessary variables, requests if there is an ISO/IEC 14443-A card in the eld, does the anti-collision
loop and selects the card to operate.
This function is enough for those applications which just require to get the UID of cards, since most of the ISO/IEC 14443-A
processes are executed inside.
It is highly advised to execute this function in the beginning of each loop, just as shown in any of the examples. Even if the
module is already initialized, it is good to start from the same point every time.
This function initializes many internal registers and variables. All the settings are optimized for the best operation. Changing
those settings may result in a defective operation.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t ATQ[2]; // stores the ATQ-A (answer to request, type 14443- A). Generally stored in
// a bigger buffer (16B)
uint8_t UID[4]; // stores the UID (unique identication) of a card
...
state = RFID13.init(UID, ATQ); // The goal of this command is to detect as many targets
// (maximum MaxTg) as possible in passive mode.
}
http://www.libelium.com/development/waspmote/examples/RFID1356-01-basic-example

-17-
v7.0
Libelium’s library
8.5. Authenticating a sector
This function authenticates a sector of the card thanks to the key or password. It is important to remark that before doing any
read or write in a block, it is mandatory to authenticate us in it.
The only exception is the UID, which can be read without authentication; it is returned by the init() function.
One authentication is enough to validate all the 4 blocks in a sector.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t ATQ[2]; // stores the ATQ-A
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t key[6]; // stores the key or password
...
memset(key, 0xFF, 6); // the key by default, edit if needed
state = RFID13.init(UID, ATQ); // inits systems and look for cards
state = RFID13.authenticate(UID, 2, key); // authenticates block number 2 (all sector 0
// actually)of the selected card. State of the executed
// function is stored.
}
http://www.libelium.com/development/waspmote/examples/RFID1356-01-basic-example
8.6. Reading a block
This function reads the 16 bytes stored in a block. This block must have been authenticated before reading.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t aux[16]; // auxiliar buffer
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t key[6]; // stores the key or password
...
memset(key, 0xFF, 6); // the key by default, edit if needed
state = RFID13.init(UID, aux); // inits systems and look for cards
state = RFID13.authenticate(UID, 2, key); // authenticates block 2
state = RFID13.read(2, aux);// reads the block 2. Data is stored in aux.
}
http://www.libelium.com/development/waspmote/examples/RFID1356-02-read-all-blocks

-18-
v7.0
Libelium’s library
8.7. Reading a block with authentication
This function authenticates a block of the card rst, and then reads the 16 bytes stored in a block. This function is useful to do
these 2 steps in just one.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t aux[16]; // auxiliar buffer
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t key[6]; // stores the key or password
...
memset(key, 0xFF, 6); // the key by default, edit if needed
state = RFID13.init(UID, aux); // inits systems and look for cards
state = RFID13.readWithAuth(UID, key, aux, 2); // authenticates block 2, then reads it.
// Data is stored in aux.
}
8.8. Writing in a block
This function writes 16 bytes in a block. This block must have been authenticated before writing.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t aux[16]; // auxiliar buffer
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t key[6]; // stores the key or password
...
memset(key, 0xFF, 6); // the key by default, edit if needed
state = RFID13.init(UID, aux); // inits systems and look for cards
state = RFID13.authenticate(UID, 2, key); // authenticates block 2
memset(aux, 0x00, 16); // stores 0’s in aux, 16 bytes
state = RFID13.write(2, aux); // writes the content of aux in block number 2
}
http://www.libelium.com/development/waspmote/examples/RFID1356-03-bus-ticketing
8.9. Writing in a block with authentication
This function authenticates a block of the card rst, and then writes 16 bytes in the block. This function is useful to do these 2
steps in just one.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t aux[16]; // auxiliar buffer
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t key[6]; // stores the key or password
...
memset(key, 0xFF, 6); // the key by default, edit if needed
state = RFID13.init(UID, aux); // inits systems and look for cards
memset(aux, 0x00, 16); // stores 0’s in aux, 16 bytes
state = RFID13.writeWithAuth(UID, key, aux, 2); // authenticates block 2, then writes the
// content of aux in it
}

-19-
v7.0
Libelium’s library
8.10. Writing in a block and checking it
This function writes 16 bytes in a block, and then checks the correct data was written. This block must be authenticated before
writing. This function is useful to do these 2 steps in just one.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t aux[16]; // auxiliar buffer
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t key[6]; // stores the key or password
...
memset(key, 0xFF, 6); // the key by default, edit if needed
state = RFID13.init(UID, aux); // inits systems and look for cards
state = RFID13.authenticate(UID, 2, key); // authenticates the block
memset(aux, 0x00, 16); // stores 0’s in aux, 16 bytes
state = RFID13.writeAndCheck(aux, 2); // writes the content of aux in block 2, then checks
// its content is OK
}
8.11. Writing in a block with authentication and checking it
This function authenticates a block of the card rst, then writes 16 bytes in the block, and then checks the correct data was
written. It is useful to do these 3 steps in just one.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t aux[16]; // auxiliar buffer
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t key[6]; // stores the key or password
...
memset(key, 0xFF, 6); // the key by default, edit if needed
state = RFID13.init(UID, aux); // inits systems and look for cards
state = RFID13.authenticate(UID, 2, key); // authenticates the block
memset(aux, 0x00, 16); // stores 0’s in aux, 16 bytes
writeAndCheckWithAuth(UID, key, aux, 2); // authenticates block 2, then writes the content of
// aux in it and checks its content is OK
}
8.12. Setting keys in a sector
This function authenticates a block of the card rst, then sets the new keys A and B, and the access bits for a sector. After that, it
authenticates again and reads the trailer block. This function is useful to do these 4 steps in just one.
This function should be executed with care because if any of the internal functions is not successfully executed, then the sector
could be damaged or left unaccessible. That is why it is highly recommended to read the output status in order to check if all the
process was completed. Please place the card still and close distance from the RFID/NFC module’s antenna when setting new
keys; if the whole process is not properly completed, the access to that sector might be lost forever.
There are many options for the conguration of the access bits. We suggest to use the same options that the card has by default:
{0xFF, 0x07, 0x80, 0x69}. With this conguration:
• data blocks must be authenticated with the key A, and then can be read/written
• key A can only be changed (written) after an authentication with key A
• access bits can be read or written after an authentication with key A
• in the sector trailer, the key B has no use and can be read/written after an authentication with key A. It can be used as
additional storage space, for instance.

-20-
v7.0
Libelium’s library
With any conguration, the key A can never be read (the module returns 0’s instead of the key) for security reasons. As we can
see, the key A of each RFID/NFC card is the master key and we must avoid losing or sharing this information.
Any new card is delivered with the same A and B keys by default: 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF. That is to say, 48 logic 1’s.
As shown, the key length is 6 bytes so t here are more than 2.8·1014 dierent possible passwords.
Example of use:
{
uint8_t state; // stores the status of the executed command
uint8_t aux[16]; // auxiliar buffer
uint8_t UID[4]; // stores the UID (unique identication) of a card
uint8_t keyA_old[6]; // stores the old key A
uint8_t keyA_new[6]; // stores the new key A
uint8_t keyB_new[6]; // stores the new key B
uint8_t cong_new[4] = {0xFF, 0x07, 0x80, 0x00}; // same cfg
...
memset(keyA_old, 0xFF, 6); // the key by default, edit if needed
memset(keyA_new, 0x88, 6); // the new key A, edit if needed
memset(keyB_new, 0x99, 6); // the new key B, edit if needed
state = RFID13.init(UID, aux); // inits systems and look for cards
state = RFID13.setKeys(UID, keyA_old, keyA_new, keyB_new, cong_new, aux, 2); //
// authenticates block 2, then writes the new trailer block, with new key A
// and B. The access bits are the same.
}
http://www.libelium.com/development/waspmote/examples/RFID1356-05-password-simple
8.13. Powering down
This function puts the module into Power Down mode in order to save power consumption.
Example of use:
{
RFID.powerDown(); // After this function you must wake up the module.
}
8.14. Waking up
This function wakes up the module from power down mode.
Example of use:
{
RFID.wakeUp(); //Wake Up from Power Down mode.
}
Table of contents