You are on page 1of 136

Contents

1 RC522 Basic Function Library Main Page 1


1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 The BFL Organisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Liability Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 RC522 Basic Function Library Module Documentation 4


2.1 Peripheral Device Bus Abstraction Layer Component . . . . . . . . . . . . . . . . . . . 4
2.2 Register Control Unit Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Hardware Dependent IO Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Operation Control Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 RC-I/O Functionality (Receive/Transmit) . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.6 ISO 14443-3 Type A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.7 Auxilary Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.8 Hardware Independent Communication Protocols . . . . . . . . . . . . . . . . . . . . . 23
2.9 MIFARE Reader Command Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.10 ISO/IEC 14443-4 (T=CL) Protocol Activation for Type A . . . . . . . . . . . . . . 27
2.11 ISO/IEC 14443-4 (T=CL) Protocol Functionality . . . . . . . . . . . . . . . . . . . 29
2.12 ID Manger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.13 Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.14 Building the ExampleProject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

3 RC522 Basic Function Library Data Structure Documentation 38


3.1 BAL WRITEBUS PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . . 38
3.2 C BAL Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.3 C ISO14443 4 Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.4 C ISO14443 4A ACTIVATION Struct Reference . . . . . . . . . . . . . . . . . . . . . 43
3.5 C ISO 14443 3A Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
CONTENTS ii

3.6 C JOINER ISO 14443 3 PARAMETERS Struct Reference . . . . . . . . . . . . . . . 48


3.7 C JOINER RC IO PARAMETERS Struct Reference . . . . . . . . . . . . . . . . . . . 49
3.8 C JOINER RC OP CTL PARAMETERS Struct Reference . . . . . . . . . . . . . . . 50
3.9 C JOINER RS 232 PC BAL PARAMS Struct Reference . . . . . . . . . . . . . . . . . 51
3.10 C JOINER RS 232 PC RC REG CTL PARAMS Struct Reference . . . . . . . . . . . 52
3.11 C MF RD INTL PARAMS Struct Reference . . . . . . . . . . . . . . . . . . . . . . . 53
3.12 C MIFARE READER Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.13 C RC IO Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.14 C RC OP CTL Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.15 C RC REG CTL Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.16 C RCL ID MANAGER Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.17 IDMAN PARAMETERS Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.18 ISO14443 3 ANTICOLLISIONSELECT PARAM Struct Reference . . . . . . . . . . . 66
3.19 ISO14443 3 HALT A PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . 68
3.20 ISO14443 3 REQUEST A PARAM Struct Reference . . . . . . . . . . . . . . . . . . . 69
3.21 ISO14443 4 CB SET READER PARAM Struct Reference . . . . . . . . . . . . . . . . 70
3.22 ISO14443 4 CB SET WTX PARAM Struct Reference . . . . . . . . . . . . . . . . . . 71
3.23 ISO14443 4 COMMUNICATION PARAMETERS Struct Reference . . . . . . . . . . 72
3.24 ISO14443 4 DESELECT PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . 75
3.25 ISO14443 4 EXCHANGE PARAM Struct Reference . . . . . . . . . . . . . . . . . . . 76
3.26 ISO14443 4 PPS PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . 79
3.27 ISO14443 4 PROTOCOL PARAM Struct Reference . . . . . . . . . . . . . . . . . . . 81
3.28 ISO14443 4 RATS PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . . 83
3.29 ISO14443 4 SET CB PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . 86
3.30 MIFARE CMD PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . 87
3.31 RCIO RECEIVE PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . 89
3.32 RCIO TRANSCEIVE PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . 90
3.33 RCIO TRANSMIT PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . . 92
3.34 RCL IDMAN PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . . . . . 93
3.35 RCOPCTL ATTRIB PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . . . 94
3.36 RCREGCTL MODIFY PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . 96
3.37 RCREGCTL SETREG PARAM Struct Reference . . . . . . . . . . . . . . . . . . . . 98

4 RC522 Basic Function Library Example Documentation 99


4.1 Iso14443 4 Reader.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.2 Iso14443 4 ReaderC.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.3 MifareReader.cpp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

RC522 Basic Function Library Documentation


CONTENTS iii

4.4 MifareReaderC.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123

RC522 Basic Function Library Documentation


Chapter 1

RC522 Basic Function Library


Main Page

1.1 Introduction
This document is a comprehensive documentation of the RCL/BFL (RF Component Library / Basic
Function Library) architecture, parts and usage. It includes a description of the component design,
the different components including their internal parts and how to connect the different components
to use them in a functional framework. Example code demonstrates the usage of the library. No
detailed description of the source code is contained, however the source code itself is available.

1. Basic Function Library (BFL)


(a) Peripheral Device Bus Abstraction Layer Component
(b) Register Control Unit Component
(c) Hardware Dependent IO Functionality
Operation Control Component
RC-I/O Functionality (Receive/Transmit)
ISO 14443-3 Type A
Auxilary Functionality
(d) Hardware Independent Communication Protocols
MIFARE Reader Command Set
ISO 14443 Part 4, Reader (PCD) side
ISO/IEC 14443-4 (T=CL) Protocol Activation for Type A
ISO/IEC 14443-4 (T=CL) Protocol Functionality
ID Manger
(e) Error Messages
2. Building the ExampleProject

1.2 Intended Audience


This library consists of a C-kernel and a C++ wrapper built around. This is because the design is to
accomplish two goals:
1.3 Revision History 2

First, the library must fully support all features on small systems (microcontrollers) with low
resources, and
second, the library shall add convenience for larger systems.

As a consequence, those who build small microcontroller-based software, will rely on the C-part of the
BFL, while others, writing e.g. handheld or even PC programs will tend to use the C++ wrapper.
Important note: The macro RCL CPP must be globally (e.g compiler settings) defined in order
to be able to use the C++ library extensions.

1.3 Revision History


Revision Date Page Description
1.0 September 2004 first version
1.1 October 2004 this version

1. Changes to the previous release:

New chapter about BFL Organisation.


Minor changes in descriptions.

1.4 The BFL Organisation


The BFL consists of the Components listed below:

RC522 Basic Function Library Documentation


1.5 Liability Information 3

Figure 1.1: The BFL Layout

Note: The components with the dotted line in the figure above mark components that are currently
not implemented.

1.5 Liability Information


The software included in the evaluation package will be provided free of charge and shall be used for testing purposes
only. No further license or right of use is granted hereunder under any patent or patentable right, copyright, trademark
or other proprietary right. Customer acknowledges that the software and the attached documentation will be provided
as is and without any warranty,express, implied or otherwise. Unless liability is mandatory at law, e.g. in cases of
personal injury, gross negligence or intent, supplier does not assume any liability for any damages arising in any way
out of or in connection with the use of the software included in this evaluation package.

No warranties of any kind are given with respect to the information provided herein except that Philips Semiconduc-
tors, Business Unit Identification warrants it has the right to make the disclosure. No patent, copyright, trademark
or other proprietary right or license is granted by this publication. No warranties of any kind are made as to the
particular application of the data and information contained in these materials and Philips Semiconductors, Business
Unit Identification hereby disclaims liability for any consequences relation to the use of this information.

Philips Semiconductors, Business Unit Identification does not assume any liability arising out of the applications and
application software wihich is included in the Evaluation Package or use of any product or circuit described herein.

RC522 Basic Function Library Documentation


Chapter 2

RC522 Basic Function Library


Module Documentation

2.1 Peripheral Device Bus Abstraction Layer Component

2.1.1 Detailed Description

This layer is optional. Its purpose is to abstract the bus specific details. In most cases the BAL is
omitted and the Register Control Unit is the lowest level. In some cases however the BAL can help
to increase portability (e.g. to hide the different system calls between LINUX and Windows).

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct C JOINER RS 232 PC BAL PARAMS
struct BAL WRITEBUS PARAM
struct C BAL

Typedefs
typedef BAL WRITEBUS PARAM BAL READBUS PARAM
typedef RCLSTATUS( C BAL WRITEBUS )(BAL WRITEBUS PARAM )
typedef RCLSTATUS( C BAL READBUS )(BAL READBUS PARAM )

Functions
void JoinerBalRs232PcInitialise (C BAL cif, void communication parameters)
RCLSTATUS JoinerBalRs232PcWriteBus (BAL WRITEBUS PARAM writebus param)
RCLSTATUS JoinerBalRs232PcReadBus (BAL WRITEBUS PARAM readbus param)
void JoinerBalRs232LinuxInitialise (C BAL cif, void communication parameters)
RCLSTATUS JoinerBalRs232LinuxWriteBus (BAL WRITEBUS PARAM writebus param)
RCLSTATUS JoinerBalRs232LinuxReadBus (BAL WRITEBUS PARAM readbus param)
2.1 Peripheral Device Bus Abstraction Layer Component 5

2.1.2 Function Documentation

2.1.2.1 void JoinerBalRs232PcInitialise (C BAL cif, void


communication parameters)

Parameters:
cif [in/out] C object interface structure, see rclstruct.h
communication parameters [in/out] Pointer to the communication parameter structure.

This function should be called first to initialise the BAL-Layer and set required parameters. An own
function pointer is typedefed for this function to enable the call within a generic C++ BAL wrapper.
See INCBAL.H .

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

2.1.2.2 RCLSTATUS JoinerBalRs232PcWriteBus (BAL WRITEBUS PARAM


writebus param)

Parameters:
writebus param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INVALID DEVICE STATE
RCLSTATUS INTERFACE ERROR
RCLSTATUS INSUFFICIENT RESOURCES

This function writes the data byte directly to the used bus. All interface specific actions for writing
are done here also.

2.1.2.3 RCLSTATUS JoinerBalRs232PcReadBus (BAL WRITEBUS PARAM


readbus param)

Parameters:
readbus param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INVALID DEVICE STATE
RCLSTATUS INTERFACE ERROR
RCLSTATUS INSUFFICIENT RESOURCES

This function reads one byte directly from the used bus. All interface specific actions for reading are
done here also.

RC522 Basic Function Library Documentation


2.1 Peripheral Device Bus Abstraction Layer Component 6

2.1.2.4 void JoinerBalRs232LinuxInitialise (C BAL cif, void


communication parameters)

Parameters:
cif [in/out] C object interface structure, see rclstruct.h
communication parameters [in/out] Pointer to the communication parameter structure.

An own function pointer is typedefed for this function to enable the call within a generic C++ BAL
wrapper. See INCBAL.H .

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

2.1.2.5 RCLSTATUS JoinerBalRs232LinuxWriteBus (BAL WRITEBUS PARAM


writebus param)

Parameters:
writebus param [in/out] Struct with communication parameters - its members: See
RCLSTRUCT.H .

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INTERFACE ERROR

Write a byte to the serial bus (Linux).

2.1.2.6 RCLSTATUS JoinerBalRs232LinuxReadBus (BAL WRITEBUS PARAM


readbus param)

Parameters:
readbus param [in/out] Struct with communication parameters - its members: See
RCLSTRUCT.H .

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INTERFACE ERROR

Read a byte from the serial bus (Linux).

RC522 Basic Function Library Documentation


2.2 Register Control Unit Component 7

2.2 Register Control Unit Component

2.2.1 Detailed Description

This component is responsible for reading and writing from and to the registers of the RC522. Its
lower layer is the Bal and the upper layers are RcOpCtl, RcIo and Iso14443 3.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct RCREGCTL SETREG PARAM
struct RCREGCTL MODIFY PARAM
struct C RC REG CTL
struct C JOINER RS 232 PC RC REG CTL PARAMS

Typedefs
typedef RCREGCTL SETREG PARAM RCREGCTL GETREG PARAM
typedef RCLSTATUS( C RC REG CTL SETREG )(RCREGCTL SETREG PARAM )
typedef RCLSTATUS( C RC REG CTL GETREG )(RCREGCTL GETREG PARAM )

typedef RCLSTATUS( C RC REG CTL MODREG )(RCREGCTL MODIFY PARAM )

Functions
void JoinerRcRegCtlRs232PcInitialise (C RC REG CTL cif, void p params, C BAL p -
lower)
RCLSTATUS JoinerRcRegCtlRs232PcSetRegister (RCREGCTL SETREG PARAM setreg -
param)
RCLSTATUS JoinerRcRegCtlRs232PcGetRegister (RCREGCTL GETREG PARAM getreg -
param)
RCLSTATUS JoinerRcRegCtlRs232PcModifyRegister (RCREGCTL MODIFY PARAM
modify param)

2.2.2 Typedef Documentation

2.2.2.1 typedef RCREGCTL SETREG PARAM RCREGCTL GETREG PARAM

Parameter structure for GetRegister functionality (equal to the one of SetRegister).


Definition at line 173 of file rclstruct.h.

RC522 Basic Function Library Documentation


2.2 Register Control Unit Component 8

2.2.3 Function Documentation

2.2.3.1 void JoinerRcRegCtlRs232PcInitialise (C RC REG CTL cif, void


p params, C BAL p lower)

Parameters:
cif [in] Pointer to the instance of the C object interface structure, see rclstruct.h
p params [in] Pointer to the internal operation variables structure instance.
p lower [in] Pointer to the underlying layer.

This function shall be called first to initialise the register control component. An own function
pointer is typedefed for this function to enable the call within a generic C++ RC-Reg-Ctl wrapper.
See INCRCREGCTL.H .

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

2.2.3.2 RCLSTATUS JoinerRcRegCtlRs232PcSetRegister (RCREGCTL SETREG -


PARAM setreg param)

Parameters:
setreg param [in] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INTERFACE ERROR

This function handles the write access to the RC522.

2.2.3.3 RCLSTATUS JoinerRcRegCtlRs232PcGetRegister (RCREGCTL GETREG -


PARAM getreg param)

Parameters:
getreg param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS

This function handles the read access to the RC522.

2.2.3.4 RCLSTATUS JoinerRcRegCtlRs232PcModifyRegister


(RCREGCTL MODIFY PARAM modify param)

Parameters:
modify param [in] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INTERFACE ERROR

RC522 Basic Function Library Documentation


2.2 Register Control Unit Component 9

This function handles bit modifications on the RC522. Therefore a JoinerRcRegCtlRs232PcGet-


Register command is performed before a JoinerRcRegCtlRs232PcSetRegister. In between the modi-
fication is done. The bit which are 1 in the mask byte are set or cleared according to the parameter
set. If set is 0, the bits are cleared, otherwise they are set.

RC522 Basic Function Library Documentation


2.3 Hardware Dependent IO Functionality 10

2.3 Hardware Dependent IO Functionality

2.3.1 Detailed Description

The blocks listed here contain hardware dependent code since they access registers.
The I/O components thus rely on the component supporting register manipulation, namely the RC
Register Control. The various components are listed below. Except of the auxilary functionality
all components have an object interface to the upper layers. The auxilary function combines some
often used transmit and receive functionality and error checking and is directly called by the other
components using their pointer to the lower layer.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Modules
Operation Control Component
RC-I/O Functionality (Receive/Transmit)
ISO 14443-3 Type A
Auxilary Functionality

RC522 Basic Function Library Documentation


2.4 Operation Control Component 11

2.4 Operation Control Component

2.4.1 Detailed Description

This component abstacts access to the registers or RF chip configuration respectively by combining
multiple register accesses, or changing only certain bits of a register.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct RCOPCTL ATTRIB PARAM
struct C RC OP CTL
struct C JOINER RC OP CTL PARAMETERS

Typedefs

C-interface member function pointer types:

typedef RCLSTATUS( C RCOPCTL SETATR )(RCOPCTL ATTRIB PARAM )


typedef RCLSTATUS( C RCOPCTL GETATR )(RCOPCTL ATTRIB PARAM )

Functions
void JoinerRcOpCtlInitialise (C RC OP CTL cif, void km, C RC REG CTL p lower)
void JoinerRcOpCtlSetWaitEventCb (RCL SET WAIT EVENT CB PARAM set wec param)
RCLSTATUS JoinerRcOpCtlSetAttribute (RCOPCTL ATTRIB PARAM attrib param)
RCLSTATUS JoinerRcOpCtlGetAttribute (RCOPCTL ATTRIB PARAM attrib param)

2.4.2 Function Documentation

2.4.2.1 void JoinerRcOpCtlInitialise (C RC OP CTL cif, void km,


C RC REG CTL p lower)

Parameters:
cif [in] Pointer to an instance of the C object interface structure, see rclstruct.h
km [in] Pointer to the internal control variables structure instance.
p lower [in] Pointer to the underlying functionality.

This function shall be called first to initialise the operation control component. There the C-Layer, the
internal variables and the underlaying layer are initialised. An own function pointer is typedefed for
this function to enable the call within a generic C++ RC-OperationControl wrapper. See INCRCIO.H
.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

RC522 Basic Function Library Documentation


2.4 Operation Control Component 12

2.4.2.2 void JoinerRcOpCtlSetWaitEventCb (RCL SET WAIT EVENT CB PARAM


set wec param)

SetWaitEventCb: Read more about this function in the documentation of rclstruct.h .

2.4.2.3 RCLSTATUS JoinerRcOpCtlSetAttribute (RCOPCTL ATTRIB PARAM


attrib param)

Parameters:
attrib param [in] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INTERFACE ERROR

This function does various hardware dependent settings, e.g. store IDs, set RxGain.

2.4.2.4 RCLSTATUS JoinerRcOpCtlGetAttribute (RCOPCTL ATTRIB PARAM


attrib param)

Parameters:
attrib param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INTERFACE ERROR

This function reads out various hardware dependent settings, e.g. read IDs, get actual RxGain value.

RC522 Basic Function Library Documentation


2.5 RC-I/O Functionality (Receive/Transmit) 13

2.5 RC-I/O Functionality (Receive/Transmit)

2.5.1 Detailed Description

This component handles the I/O functionality. Therefore the functions Transmit, Receive, Transceive
and the special function MfAuthent are implemented. All functions use the function RcAux for
common processing functions. Some functionality is mode-depending supporting easier handling of
the peripheral.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct RCIO TRANSCEIVE PARAM
struct RCIO TRANSMIT PARAM
struct RCIO RECEIVE PARAM
struct C RC IO
struct C JOINER RC IO PARAMETERS

Typedefs
typedef RCIO TRANSMIT PARAM RCIO MFAUTHENT PARAM
typedef RCLSTATUS( C RCIO TRANSCEIVE )(RCIO TRANSCEIVE PARAM )
typedef RCLSTATUS( C RCIO TRANSMIT )(RCIO TRANSMIT PARAM )
typedef RCLSTATUS( C RCIO RECEIVE )(RCIO RECEIVE PARAM )
typedef RCLSTATUS( C RCIO MFAUTHENT )(RCIO MFAUTHENT PARAM )

Functions
void JoinerRcIoInitialise (C RC IO cif, void rp, C RC REG CTL p lower, unsigned char
initiator not target)
void JoinerRcIoSetWaitEventCb (RCL SET WAIT EVENT CB PARAM set wec param)
RCLSTATUS JoinerRcIoTransceive (RCIO TRANSCEIVE PARAM transceive param)
RCLSTATUS JoinerRcIoTransmit (RCIO TRANSMIT PARAM transmit param)
RCLSTATUS JoinerRcIoReceive (RCIO RECEIVE PARAM receive param)
RCLSTATUS JoinerRcIoMfAuthent (RCIO MFAUTHENT PARAM mfauthent param)

2.5.2 Typedef Documentation

2.5.2.1 typedef RCIO TRANSMIT PARAM RCIO MFAUTHENT PARAM

Parameter structure for MF-Authent helper is equal to Transmit parameter. Since the Mifare (R)
function for Authentication is part of the RF chips I/O capabilities, it must be handled here. The
function takes the authentication parameters in the tx buffer member. Composition of the data is
done in the Mifare component.
Definition at line 413 of file rclstruct.h.

RC522 Basic Function Library Documentation


2.5 RC-I/O Functionality (Receive/Transmit) 14

2.5.3 Function Documentation

2.5.3.1 void JoinerRcIoInitialise (C RC IO cif, void rp, C RC REG CTL


p lower, unsigned char initiator not target)

Parameters:
cif [in] C object interface structure, see rclstruct.h.
rp [in] Pointer to the internal control variables structure.
p lower [in] Pointer to the underlying layer, in this case register control.
initiator not target [in] Specifier for mode whether to support Initiator or Target.

This function shall be called first to initialise the IO component. There the C-Layer, the internal
variables, the underlaying layer and the device mode are initialised. An own function pointer is
typedefed for this function to enable the call within a generic C++ RC-I/O wrapper. See file
INCRCIO.H .

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

2.5.3.2 void JoinerRcIoSetWaitEventCb (RCL SET WAIT EVENT CB PARAM


set wec param)

SetWaitEventCb: Read more about this function in the documentation of rclstruct.h .

2.5.3.3 RCLSTATUS JoinerRcIoTransceive (RCIO TRANSCEIVE PARAM


transceive param)

Parameters:
transceive param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INVALID DEVICE STATE

This function directly uses the auxiliary function JoinerRcAuxSingleCommand for initiator mode.
For target mode this function is disabled and replaced by JoinerRcIoTransmit and JoinerRcIoReceive
which also use the transceive command for bit syncronicity.
The rx buffer size parameter sets the maximum receive data length in bytes. Even if more data is
received, no buffer overflow may occure.
In combination with a transparent register read and write command set, this function enables a
completely transparent communication between two devices.

Note:
TX and RX buffers may overlap or even be the same.
In case of an error, the appropriate error code is set. Nevertheless all received data during the
RF-Communication is returned. This is done for debugging reasons.
Neither framing and speed nor timeout and CRC are modified by this function. These parameters
should be set in advance.

RC522 Basic Function Library Documentation


2.5 RC-I/O Functionality (Receive/Transmit) 15

2.5.3.4 RCLSTATUS JoinerRcIoTransmit (RCIO TRANSMIT PARAM


transmit param)

Parameters:
transmit param [in] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INVALID DEVICE STATE

This function is devided into two parts. One for the initiator mode and one for the reader mode.
In initiator mode the function JoinerRcAuxSingleCommand is called and the transmit command of
RC522 is executed. No response is expected.
In target mode there is first a check if the transceive command is active, because sending without any
previous reception is forbidden. Then the function JoinerRcAuxSingleCommand is called using the
transceive command of RC522.

Note:
Neither framing and speed nor timeout and CRC are modified by this function. These parameters
should be set in advance.

2.5.3.5 RCLSTATUS JoinerRcIoReceive (RCIO RECEIVE PARAM receive param)

Parameters:
receive param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS

This function is devided into two parts. One for the initiator mode and one for the reader mode.
In initiator mode the function JoinerRcAuxSingleCommand is called and the receive command of
RC522 is executed.
In target mode the function JoinerRcAuxSingleCommand is called and the transceive command of
RC522 is executed.
In both modes the rx buffer size parameter sets the maximum receive data length in bytes. Even if
more data is received, no buffer overflow may occure.

Note:
In case of an error, the appropriate error code is set. Nevertheless all received data during the
RF-Communication is returned. This is done for debugging reasons.
Neither framing and speed nor timeout and CRC are modified by this function. These parameters
should be set in advance.

2.5.3.6 RCLSTATUS JoinerRcIoMfAuthent (RCIO MFAUTHENT PARAM


mfauthent param)

Parameters:
mfauthent param [in] Pointer to the parameter structure, see rclstruct.h

RC522 Basic Function Library Documentation


2.5 RC-I/O Functionality (Receive/Transmit) 16

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INVALID DEVICE STATE

This function is directly called from Mifare Authentication function where the data is prepared and
handled over using the tx buffer. The function calls JoinerRcAuxSingleCommand where the Authen-
tication command of RC522 is performed.

Note:
Neither framing and speed nor timeout and CRC are modified by this function. These parameters
should be set in advance.

RC522 Basic Function Library Documentation


2.6 ISO 14443-3 Type A 17

2.6 ISO 14443-3 Type A

2.6.1 Detailed Description

This component contains the activation and deactivation commands according to the ISO 14443 Part
3 Type A which are functions for Request, Anticollission/Select and HaltA.
These are used to start communication to either a MIFARE card, a card supporting ISO14443 Part
4.
An overview about the commands and what commands must be followed by which one will be done
in the table below.
Command Abbr. Code Argument Response Possible after
Request ALL REQ 52 None Tag Type cards POR, HALT,
(ATQA) communication failure
Request IDLE REQ 26 None Tag Type cards POR,
(ATQA) communication failure
Anticollision AC 93, 95, 97 (optional parts of the (rest of) cds REQ, AC
cards serial number) serial number
Select SEL 93, 95, 97 Card serial number Answer To REQ, AC
Select communication failure
Halt HALT 50 Dummy address None AC, SEL,
any MIFARE command

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct ISO14443 3 REQUEST A PARAM
struct ISO14443 3 ANTICOLLISIONSELECT PARAM
struct ISO14443 3 HALT A PARAM
struct C ISO 14443 3A
struct C JOINER ISO 14443 3 PARAMETERS

Typedefs
typedef ISO14443 3 ANTICOLLISIONSELECT PARAM ISO14443 3 SELECT PARAM
typedef RCLSTATUS( REQUESTA )(ISO14443 3 REQUEST A PARAM )
typedef RCLSTATUS( ANTICOLLISIONSELECT )(ISO14443 3 -
ANTICOLLISIONSELECT PARAM )
typedef RCLSTATUS( SELECT )(ISO14443 3 SELECT PARAM )
typedef RCLSTATUS( HALTA )(ISO14443 3 HALT A PARAM )

Functions
void JoinerIso14443 3Initialise (C ISO 14443 3A cif, void rp, C RC REG CTL p lower, un-
signed char initiator not target)
void JoinerIso14443 3SetWaitEventCb (RCL SET WAIT EVENT CB PARAM set wec -
param)

RC522 Basic Function Library Documentation


2.6 ISO 14443-3 Type A 18

RCLSTATUS JoinerIso14443 3RequestA (ISO14443 3 REQUEST A PARAM request a -


param)
RCLSTATUS JoinerIso14443 3AnticollisionSelect (ISO14443 3 ANTICOLLISIONSELECT -
PARAM anticollisionselect param)
RCLSTATUS JoinerIso14443 3Select (ISO14443 3 SELECT PARAM select param)
RCLSTATUS JoinerIso14443 3HaltA (ISO14443 3 HALT A PARAM halt a param)

2.6.2 Function Documentation

2.6.2.1 void JoinerIso14443 3Initialise (C ISO 14443 3A cif, void rp,


C RC REG CTL p lower, unsigned char initiator not target)

Parameters:
cif [in/out] C object interface structure, see rclstruct.h
rp [in/out] Pointer to the internal control variables structure.
p lower [in] Pointer to the underlying layers function.
initiator not target [in] Specifier for mode whether to support Initiator or Target.

This function shall be called first to initialise the ISO14443-3 component. There the C-Layer, the
internal variables, the underlaying layer and the device mode are initialised. An own function pointer
is typedefed for this function to enable the call within a generic C++ ISO14443 3 wrapper. See
INCRCIO.H.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

2.6.2.2 void JoinerIso14443 3SetWaitEventCb (RCL SET WAIT EVENT CB -


PARAM set wec param)

SetWaitEventCb: Read more about this function in the documentation of rclstruct.h .

2.6.2.3 RCLSTATUS JoinerIso14443 3RequestA (ISO14443 3 REQUEST A PARAM


request a param)

Parameters:
request a param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS COLLISION ERROR
RCLSTATUS PROTOCOL ERROR
RCLSTATUS INVALID DEVICE STATE

This command handles the Request procedure of ISO14443-3. Depending on the Request Code and
the state of the cards in the field all cards reply with their Tag-Type synchronously. The time between
end of the Request command and start of reply of the card is exactly 8 9.44 us long. The Tag-Type
field is 16 bits long and only one bit out of 16 is set.
When cards with different Tag-Types are in field, the MF RC500 is able to identify all types of cards
in the RF-field. Further more, the Tag-Type is used to identify a card with cascaded serial number.
Double and Triple serial numbers are possible.

RC522 Basic Function Library Documentation


2.6 ISO 14443-3 Type A 19

Relevant bit positions LSByte:


[8..7] UID size
00 standard 32 bit long UID
01 UID size double (56 bit long)
10 UID size triple (80 bit long)
[5..1] if any bit is set, frame anticollision is supported; tag type recognition
The complete MSByte is RFU.
All error messages from the lower layers are directly propagated to the calling procedure.

Note:
In case of an error, the appropriate error code is set. Nevertheless all received data during the
RF-Communication is returned for debugging reasons.
Future cards will work also with other request codes.

2.6.2.4 RCLSTATUS JoinerIso14443 3AnticollisionSelect (ISO14443 3 -


ANTICOLLISIONSELECT PARAM anticollisionselect param)

Parameters:
anticollisionselect param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INVALID PARAMETER
RCLSTATUS BITCOUNT ERROR
RCLSTATUS WRONG UID CHECKBYTE
RCLSTATUS INVALID DEVICE STATE

This command combines the ISO14443-3 functions of anticollision and select. The functionality is
split up into two independent internal procedures. One to do the anticollision, the other one to do the
select. The cascade level is automatically increased if the Cascade Tag for a further level is received.
The checkbyte is verified, but not stored in the buffer.
The sel lv1 code contains the select code of cascade level 1. This is 0x93 for ISO14443-3 compatible
devices.
The uid references a buffer which may contain the known part of the uid when the function is called.
When the function returns to the calling procedure, this buffer contains the received serial number
of the target device. The length is according to the cascade level of the ID. The indicator of another
cascade level (0x88) is not removed and also stored in the buffer.
The uid length parameter is the bit count (!) of the ID. As input it is the number of known bits, as
output it shows the ID length, in bits, which is always a multiple of 32.
At the end this function selects a card by the specified serial number. All other cards in the field fall
back into the idle mode and they are not longer involved during the further communication.

Note:
In case of an error, the appropriate error code is set. Nevertheless all received data during the
RF-Communication is returned for debugging reasons.

RC522 Basic Function Library Documentation


2.6 ISO 14443-3 Type A 20

2.6.2.5 RCLSTATUS JoinerIso14443 3Select (ISO14443 3 SELECT PARAM


select param)

Parameters:
select param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS INVALID PARAMETER
RCLSTATUS BITCOUNT ERROR
RCLSTATUS INVALID DEVICE STATE

This command only performs the select of a known device. For detailed information on the parameters
see the decription of JoinerIso14443 3AnticollisionSelect command.
The sel lv1 code is the first command to be sent to the passive device.
The uid contains the ID of the device. All 3 cascade levels can be transferred at once to the function.
The uid length parameter defines whether the ID is single, double or triple.
At the end this function selects a card by the specified serial number. All other cards in the field fall
back into the idle mode and they are not longer involved during the further communication.

Note:
In case of an error, the appropriate error code is set. Nevertheless all received data during the
RF-Communication is returned. This is done for debugging reasons.

2.6.2.6 RCLSTATUS JoinerIso14443 3HaltA (ISO14443 3 HALT A PARAM


halt a param)

Parameters:
halt a param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS

This function handles the halt command for ISO14443-3.


This function sets a MIFARE174 Classic compatible card into the halt state. Having send the com-
mand to the card, the function does not expect a cards response. Only in case of any error the card
sends back a NACK. If the command was successful, the card does not return with an ACK. Thus,
the function is successful, if a timeout is indicated.

RC522 Basic Function Library Documentation


2.7 Auxilary Functionality 21

2.7 Auxilary Functionality

2.7.1 Detailed Description

This block conains the helper functions for the IO, the operation control and the ISO14443 Part 3
component. It is directly called by these functions (not via the RCL/BFL interface logic). The pointer
to the lower layer is directly handed over via one member in the parameter data structure. One helper
function is called JoinerRcAuxSingleCommand and handles transmission, reception and error checking
of the received data. A so called waterlevel is defined here but not used in the implementation for
the serial interface. Therefore this function is able to handle only up to 64 bytes of data.
The struct RCAUX SINGLE COMMAND PARAM contains the pointer to the lower component, the
command to operate, the pointer to the transmit buffer, the transmit buffer size, the pointer to the
receive buffer, the information about the received bytes and the received bits.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Functions
RCLSTATUS JoinerRcAuxSingleCommand (RCAUX SINGLE COMMAND PARAM single -
command param)

2.7.2 Function Documentation

2.7.2.1 RCLSTATUS JoinerRcAuxSingleCommand (RCAUX SINGLE COMMAND -


PARAM single command param)

Parameters:
single command param [in/out] Pointer to the parameter structure, see rclstruct.h

Returns:
RCLSTATUS SUCCESS
RCLSTATUS ACK SUPPOSED
RCLSTATUS BUFFER OVERFLOW
RCLSTATUS COLLISION ERROR
RCLSTATUS CRC ERROR
RCLSTATUS JOINER TEMP ERROR
RCLSTATUS UNSUPPORTED COMMAND
RCLSTATUS PARITY ERROR
RCLSTATUS PROTOCOL ERROR
RCLSTATUS RF ERROR
RCLSTATUS ERROR NY IMPLEMENTED

This module handles the common part of the send and receive functionality. It also does the filling
of the FIFO of the RC522 and all the error checking for the response data. It is mainly used by all
components of the hardware dependent layer of the BFL.
For this module there is only the C-Interface existing. It shall be called directly.

RC522 Basic Function Library Documentation


2.7 Auxilary Functionality 22

Note:
TX and RX buffers may overlap or even be the same.
In case of an error, the appropriate error code is set. Nevertheless all received data during the
RF-Communication is returned. This is done for debugging reasons.
Neither framing and speed nor timeout and CRC are modified by this function. These parameters
should be set in advance.

RC522 Basic Function Library Documentation


2.8 Hardware Independent Communication Protocols 23

2.8 Hardware Independent Communication Protocols

2.8.1 Detailed Description

This group contains hardware independent communication protocols. These are

MIFARE Reader Command Set,

ISO/IEC 14443-4 (T=CL) Protocol Activation for Type A and ISO/IEC 14443-4 (T=CL)
Protocol Functionality and
ID Manger.

The lower layer of the functions is the RC-IO component. The upper layer is an application, a
surrounding library (e.g. shared lib) some middleware or any embedding software.

Modules
MIFARE Reader Command Set
ISO/IEC 14443-4 (T=CL) Protocol Activation for Type A
ISO/IEC 14443-4 (T=CL) Protocol Functionality
ID Manger

RC522 Basic Function Library Documentation


2.9 MIFARE Reader Command Set 24

2.9 MIFARE Reader Command Set

2.9.1 Detailed Description

The MIFARE Reader command set is supported by this component.


This component consists of a hardware-independent implementation.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct MIFARE CMD PARAM
struct C MIFARE READER
struct C MF RD INTL PARAMS

Commands

Command definitions for Mifare operation. These command bytes comply to the MIFARE specifica-
tion and serve as one parameter for the MIFARE transaction commands defined within the scope of
this implementation.

#define MIFARE AUTHENT A ((unsigned char)0x60)


#define MIFARE AUTHENT B ((unsigned char)0x61)
#define MIFARE READ ((unsigned char)0x30)
#define MIFARE WRITE ((unsigned char)0xA0)
#define MIFARE WRITE4 ((unsigned char)0xA2)
#define MIFARE INCREMENT ((unsigned char)0xC1)
#define MIFARE DECREMENT ((unsigned char)0xC0)
#define MIFARE RESTORE ((unsigned char)0xC2)
#define MIFARE TRANSFER ((unsigned char)0xB0)
#define MIFARE NOCOMMAND ((unsigned char)0x00)

Size Definitions

These definitions are important for the caller (user). The sizes are also internally checked and used
for request/response processing.

#define MIFARE MAX DATABUFFER SIZE ((unsigned char)32)


#define MIFARE STD BLOCK SIZE ((unsigned char)16)
#define MIFARE UL PAGE SIZE ((unsigned char)4)
#define MIFARE VALUE DATA SIZE ((unsigned char)4)

Typedefs
typedef RCLSTATUS( MIFARE GENERIC SINGLE )(MIFARE CMD PARAM )
typedef RCLSTATUS( MIFARE GENERIC DOUBLE )(MIFARE CMD PARAM )
typedef RCLSTATUS( MIFARE CMD )(MIFARE CMD PARAM )

RC522 Basic Function Library Documentation


2.9 MIFARE Reader Command Set 25

Functions
void MifareReaderInitialise (C MIFARE READER cif, void mp, C RC IO p lower, unsigned
char p trxbuffer)
RCLSTATUS MifareReaderTransaction (MIFARE CMD PARAM cmd param)

2.9.2 Define Documentation

2.9.2.1 #define MIFARE MAX DATABUFFER SIZE ((unsigned char)32)

Size of MF exchange buffer, used for underlying Transceive:


Definition at line 104 of file mifare.h.

2.9.2.2 #define MIFARE STD BLOCK SIZE ((unsigned char)16)

Size of a Mifare Standard card data block, in bytes.


Definition at line 106 of file mifare.h.

2.9.2.3 #define MIFARE UL PAGE SIZE ((unsigned char)4)

Size of a Mifare Ultra Light card/label data block, in bytes.


Definition at line 108 of file mifare.h.

2.9.2.4 #define MIFARE VALUE DATA SIZE ((unsigned char)4)

Data size of a Mifare value block, in bytes.


Definition at line 110 of file mifare.h.

2.9.3 Function Documentation

2.9.3.1 void MifareReaderInitialise (C MIFARE READER cif, void mp, C RC IO


p lower, unsigned char p trxbuffer)

Parameters:
cif [in] Pointer to an instance of the C object interface structure, see rclstruct.h
mp [in] Pointer to the alredy allocated internal control variables structure.
p lower [in] Pointer to the underlying layer RC-I/O.
p trxbuffer [in] Pointer to the system-wide TRx buffer, allocated and managed by the embed-
ding software. The buffer serves as the source/destination buffer for the underlying RC-I/O
Transceive functionality.

Examples:
MifareReaderC.c.

RC522 Basic Function Library Documentation


2.9 MIFARE Reader Command Set 26

2.9.3.2 RCLSTATUS MifareReaderTransaction (MIFARE CMD PARAM


cmd param)

Parameters:
cmd param (
[in/out] Struct with communication parameters - its members: See RCLSTRUCT.H .

Returns:
RCLSTATUS SUCCESS
RCLSTATUS COLLISION ERROR
RCLSTATUS PROTOCOL ERROR
RCLSTATUS INVALID DEVICE STATE
Other RCLSTATUS values depending on the underlying RC-I/O features.

The main MIFARE reader protocol entry point. All MIFARE functionality is concentrated in this
place.

RC522 Basic Function Library Documentation


2.10 ISO/IEC 14443-4 (T=CL) Protocol Activation for Type A 27

2.10 ISO/IEC 14443-4 (T=CL) Protocol Activation for


Type A

2.10.1 Detailed Description

The ISO 14443-4 (T=CL) protocol handles APDU-based data exchange with contactless cards
(PICCs). All protocol-related actions such as frame-composition/analysis, chaining of information,
error-handling and the like are done internally.
This component is designed to be independent from the RF chip hardware and the I/O subsystem.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct ISO14443 4 RATS PARAM
struct ISO14443 4 PPS PARAM
struct C ISO14443 4A ACTIVATION

Typedefs

C-interface member function pointer types:

typedef RCLSTATUS( ISO14443 4 RATS )(ISO14443 4 RATS PARAM )


typedef RCLSTATUS( ISO14443 4 PPS )(ISO14443 4 PPS PARAM )

Functions
RCLSTATUS Iso14443 4A Activation Initialise (C ISO14443 4A ACTIVATION cif,
ISO14443 4 PROTOCOL PARAM p td, unsigned char p trxbuffer, unsigned short trxbuffer-
size, C RC IO p lower)
RCLSTATUS Iso14443 4A Rats (ISO14443 4 RATS PARAM rats param)
RCLSTATUS Iso14443 4A Pps (ISO14443 4 PPS PARAM pps param)

2.10.2 Function Documentation

2.10.2.1 RCLSTATUS Iso14443 4A Activation Initialise (C ISO14443 4A -


ACTIVATION cif, ISO14443 4 PROTOCOL PARAM p td, unsigned char
p trxbuffer, unsigned short trxbuffersize, C RC IO p lower)

Parameters:
cif [in] C object interface structure, see rclstruct.h .
p td [in] Pointer to the Communication Parameters structure. This structure is filled by RATS
and PPS and to be handed over to the exchange protocol (ISO14443 4) object.
p trxbuffer [in] Pointers to TX and RX buffer, used by the protocol for intermediate storage.
trxbuffersize [in] Size of TX and RX buffer, used by the protocol for intermediate storage.
p lower [in] Pointer to the underlying layers TRx function.

RC522 Basic Function Library Documentation


2.10 ISO/IEC 14443-4 (T=CL) Protocol Activation for Type A 28

Set up the ISO 14443-4 protocol entry. After this function the Component is operational.

Examples:
Iso14443 4 ReaderC.c.

2.10.2.2 RCLSTATUS Iso14443 4A Rats (ISO14443 4 RATS PARAM rats param)

Parameters:
rats param [in/out] Parameter structure, see rclstruct.h;

Returns:
RCLSTATUS code.

Issue an ISO 14443-4 RATS.

2.10.2.3 RCLSTATUS Iso14443 4A Pps (ISO14443 4 PPS PARAM pps param)

Parameters:
pps param [in/out] Parameter structure, see rclstruct.h .

Returns:
RCLSTATUS code.

Issue an ISO 14443-4 PPS.

RC522 Basic Function Library Documentation


2.11 ISO/IEC 14443-4 (T=CL) Protocol Functionality 29

2.11 ISO/IEC 14443-4 (T=CL) Protocol Functionality

2.11.1 Detailed Description

The ISO 14443-4 (T=CL) protocol handles APDU-based data exchange with contactless cards
(PICCs). All protocol-related actions such as frame-composition/analysis, chaining of information,
error-handling and the like are done internally.
This component is designed to be independent from the RF chip hardware and the I/O subsystem.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct ISO14443 4 PROTOCOL PARAM
struct ISO14443 4 EXCHANGE PARAM
struct ISO14443 4 DESELECT PARAM
struct ISO14443 4 CB SET WTX PARAM
struct ISO14443 4 CB SET READER PARAM
struct ISO14443 4 SET CB PARAM
struct C ISO14443 4
struct ISO14443 4 COMMUNICATION PARAMETERS

Member Typedefs

Member function pointer types:

typedef RCLSTATUS( ISO14443 4 EXCHANGE )(ISO14443 4 EXCHANGE PARAM )

typedef RCLSTATUS( ISO14443 4 PRESENCE CHECK )(ISO14443 4 PRESENCE -


CHECK PARAM )
typedef RCLSTATUS( ISO14443 4 DESELECT )(ISO14443 4 DESELECT PARAM )
typedef void( ISO14443 4 SET PROTOCOL PARAMS )(void , void , unsigned char)
typedef void( ISO14443 4 RESET PROTOCOL )(void )

Protocol Typedefs

Protocol callback function pointers for PCD parameter/attribute modification:

typedef RCLSTATUS( ISO14443 4 CB SET WTX )(ISO14443 4 CB SET WTX PARAM )


typedef RCLSTATUS( ISO14443 4 CB SET READER PARAMS )(ISO14443 4 CB SET -
READER PARAM )

Callback Typedefs

Callback function address initialiser.

typedef void( ISO14443 4 SET CB )(ISO14443 4 SET CB PARAM )

RC522 Basic Function Library Documentation


2.11 ISO/IEC 14443-4 (T=CL) Protocol Functionality 30

Defines
#define ISO14443 4 CONTINUE CHAINING (0x01)

Typedefs
typedef ISO14443 4 DESELECT PARAM ISO14443 4 PRESENCE CHECK PARAM

Functions
RCLSTATUS Iso14443 4Initialise (C ISO14443 4 cif, ISO14443 4 COMMUNICATION -
PARAMETERS p td, C RC IO p lower)
void Iso14443 4SetCallbacks (ISO14443 4 SET CB PARAM set cb param)
void Iso14443 4SetProtocolParameters (void cif, void p protocol param, unsigned char max -
retry)
void Iso14443 4ResetProtocol (void cif)
RCLSTATUS Iso14443 4Exchange (ISO14443 4 EXCHANGE PARAM exchange param)
RCLSTATUS Iso14443 4PresenceCheck (ISO14443 4 PRESENCE CHECK PARAM
presence check param)
RCLSTATUS Iso14443 4Deselect (ISO14443 4 DESELECT PARAM deselect param)

2.11.2 Define Documentation

2.11.2.1 #define ISO14443 4 CONTINUE CHAINING (0x01)

Structure with general internal operation parameters: This bit instructs the EXCHANGE function to
accept a further filled user buffer for data transfer to the PICC. If set, the function continues chaining
to the PICC with the following call. This makes two or more subsequent calls appear as one from the
PICCs point of view. OR this value into the flags member of EXCHANGE PARAM.
Definition at line 82 of file iso14443 4.h.

2.11.3 Typedef Documentation

2.11.3.1 typedef ISO14443 4 DESELECT PARAM ISO14443 4 PRESENCE -


CHECK PARAM

Parameter structure for Presence Check functionality. Has the same parameters as the DESELECT
command.
Definition at line 722 of file rclstruct.h.

2.11.3.2 typedef RCLSTATUS( ISO14443 4 CB SET WTX)(ISO14443 4 CB SET -


WTX PARAM)

This function is embedding-software defined and called by the protocol when there is the need to
set the timeout to an extended value (WTX) in order to allow the card to do more time-consuming
processing before returning data.
If the pointer is set to NULL, the protocol ignores the call and continues operation. In any other case
the pointer is considered valid.
Definition at line 798 of file rclstruct.h.

RC522 Basic Function Library Documentation


2.11 ISO/IEC 14443-4 (T=CL) Protocol Functionality 31

2.11.3.3 typedef RCLSTATUS( ISO14443 4 CB SET READER -


PARAMS)(ISO14443 4 CB SET READER PARAM)

This function is embedding-software defined and called by the protocol when there is the need to set
the bitrate of the PCD, e.g. when using higher baudrates. In general, this function is called before
each communication cycle. The action taken upon this depends on the applications implementation.
If the pointer is set to NULL, the protocol ignores the call and continues operation. In any other case
the pointer is considered valid.
Definition at line 808 of file rclstruct.h.

2.11.4 Function Documentation

2.11.4.1 RCLSTATUS Iso14443 4Initialise (C ISO14443 4 cif,


ISO14443 4 COMMUNICATION PARAMETERS p td, C RC IO
p lower)

Parameters:
cif [in] C object interface structure, see rclstruct.h
p td [in] Pointer to the Communication Parameters structure.
p lower [in] Pointer to the underlying layers TRx function.

This function binds the pre-allocated interface Component structure to its internal variables - con-
taining structure. Additionally the lower-edge interface pointer is required by this function.

Examples:
Iso14443 4 ReaderC.c.

2.11.4.2 void Iso14443 4SetCallbacks (ISO14443 4 SET CB PARAM set cb param)

Parameters:
set cb param [in] Pointer to a ISO14443 4 SET CB PARAM structure, defined in rclstruct.h.
The function initialises the callback pointers to embedding software-defined functionality
responsible for the application of reader settings.

The function pointers in the set cb param must point to valid locations or NULL. A detailed descrip-
tion is listed in rclstruct.h .

2.11.4.3 void Iso14443 4SetProtocolParameters (void cif, void p protocol param,


unsigned char max retry)

Parameters:
cif [in] C object interface structure, see rclstruct.h.
p protocol param [in] Pointer to a ISO14443 4 PROTOCOL PARAM structure which holds
the already initialised items the communication protocol requires for operation. The function
generates a copy of the values.
max retry [in] Number of retry attempts before the protocol bails out responding to communi-
cation errors.

This function applies the session parameters (determined during activation) to the communication
protocol. See rclstruct.h .

RC522 Basic Function Library Documentation


2.11 ISO/IEC 14443-4 (T=CL) Protocol Functionality 32

2.11.4.4 void Iso14443 4ResetProtocol (void cif)

Parameters:
cif [in/out] C object interface structure, see rclstruct.h.

This function sets the protocol to initial state. The SetProtocolParameters() function internally calls
this method. Use for protocol-reinitialisation only - when ended up in an unrecoverable communication
error condition, for example.

2.11.4.5 RCLSTATUS Iso14443 4Exchange (ISO14443 4 EXCHANGE PARAM


exchange param)

Parameters:
exchange param [in/out] Parameter structure, see rclstruct.h .

Returns:
RCLSTATUS code.

Data exchange protocol according to ISO 14443-4. The exchange param of type ISO14443 4 -
EXCHANGE PARAM is described en detail in rclstruct.h .

2.11.4.6 RCLSTATUS Iso14443 4PresenceCheck (ISO14443 4 PRESENCE CHECK -


PARAM presence check param)

Parameters:
presence check param [in/out] Parameter structure, see rclstruct.h .

Returns:
RCLSTATUS code.

This function checks the presence of a PICC in the field without altering its state. This is done by
exploiting the scenarios in response to a R(NACK) block.

2.11.4.7 RCLSTATUS Iso14443 4Deselect (ISO14443 4 DESELECT PARAM


deselect param)

Parameters:
deselect param [in/out] Parameter structure, see rclstruct.h .

Returns:
RCLSTATUS code.

Deselect functionality according to ISO 14443-4.

RC522 Basic Function Library Documentation


2.12 ID Manger 33

2.12 ID Manger

2.12.1 Detailed Description

The ID-Manager Component is intended as an auxiliary device for the ISO 14443-4 protocol. Both
protocols use logical IDs for communication with their conterparts (Smart Card). While the name is
different (CID in ISO 14443-4) the rules are the same. An application or calling software can choose
randomly an ID ranging from 1 to 14. ID 15 is reserved. ID 0 is, by definition the last ID to initialise.
According to the rules, the ID ZERO prevents, as long as it is occupied, further cards to be acquired
and put into the protocol flow. The ID manager has these rules built in. For example, the GetFreeID
function wont return ID ZERO as long as it finds free entries within 1..14. Consequently, no ID is
returned if ZERO is alread in use.
This component is designed to be independent from the RF chip hardware and the I/O subsystem.

Note:
For detailed information about the components, structures and parameters see this chapter or
follow the links to the source files.

Data Structures
struct RCL IDMAN PARAM
struct C RCL ID MANAGER
struct IDMAN PARAMETERS

Typedefs

C-interface member function pointer type:

typedef RCLSTATUS( RCL IDMAN MEMBER )(RCL IDMAN PARAM )

Functions
RCLSTATUS IdmanInitialise (C RCL ID MANAGER cif, IDMAN PARAMETERS p td)
RCLSTATUS IdmanGetFreeID (RCL IDMAN PARAM idman param)
RCLSTATUS IdmanIsFreeID (RCL IDMAN PARAM idman param)
RCLSTATUS IdmanAssignID (RCL IDMAN PARAM idman param)
RCLSTATUS IdmanFreeIDByNumber (RCL IDMAN PARAM idman param)
RCLSTATUS IdmanFreeIDByInstance (RCL IDMAN PARAM idman param)

2.12.2 Function Documentation

2.12.2.1 RCLSTATUS IdmanInitialise (C RCL ID MANAGER cif,


IDMAN PARAMETERS p td)

Parameters:
cif [in] C object interface structure, see rclstruct.h
p td [in] Pointer to the IDMAN PARAMETERS Parameters structure (pre-allocated).

RC522 Basic Function Library Documentation


2.12 ID Manger 34

Returns:
RCLSTATUS code.

This function initialises the C-object of the IdMan Component and expects valid pointers to the
internal parameters structure as well as to a pre-allocated Component structure, (rclstruct.h).

2.12.2.2 RCLSTATUS IdmanGetFreeID (RCL IDMAN PARAM idman param)

Parameters:
idman param [in] Parameter structure, defined in rclstruct.h , for ID Manager actions. The
ID member of the structure contains the free ID number. The instance and ID members
can be left dangling.

Returns:
RCLSTATUS code.

The Get Free ID function returns the first free ID in its parameter idman param. First ID 1..14
are searched, finally the function examines ID 0 if all other IDs are occupied.

2.12.2.3 RCLSTATUS IdmanIsFreeID (RCL IDMAN PARAM idman param)

Parameters:
idman param [in/out] Parameter structure, defined in rclstruct.h , for ID Manager actions.
The ID to examine must be supplied by the caller in the ID member. The instance member
can be left dangling.

Returns:
RCLSTATUS code.

This function checks whether a specified ID is free.

2.12.2.4 RCLSTATUS IdmanAssignID (RCL IDMAN PARAM idman param)

Parameters:
idman param [in] Parameter structure, defined in rclstruct.h , for ID Manager actions. The
caller has to specify the address of the protocol object operating under a certain ID. Both
members, instance and ID must be initialised by the caller.

Returns:
RCLSTATUS code.

This function binds an ID to the corresponding address of the object operating unter this logical
number.

2.12.2.5 RCLSTATUS IdmanFreeIDByNumber (RCL IDMAN PARAM


idman param)

Parameters:
idman param [in] Parameter structure, defined in rclstruct.h , for ID Manager actions. The
caller must specify the ID to clear in the ID member of the parameter. The instance member
can be left dangling.

RC522 Basic Function Library Documentation


2.12 ID Manger 35

Returns:
RCLSTATUS code.

By specifying an ID number the function deletes the corresponding protocol object entry.

2.12.2.6 RCLSTATUS IdmanFreeIDByInstance (RCL IDMAN PARAM


idman param)

Parameters:
idman param [in] Parameter structure, defined in rclstruct.h , for ID Manager actions. The
caller must specify the instance to clear in the instance member of the parameter. The ID
member can be left dangling.

Returns:
RCLSTATUS code.

The ID under which the object (instance address) is listed becomes available again.

RC522 Basic Function Library Documentation


2.13 Error Messages 36

2.13 Error Messages


For communication commands with PICCs and special commands for the IC, there is a set of codes
depending on underlying features and causes and therefore they are not described explicitely together
with a function.
Error messages are grouped in

Success Indicator,

Communication Errors between Reader and Card,

Interface Errors on each components interface,

MIFARE Protocol Errors,

ISO/IEC 14443 Part 3 Errors,

ISO/IEC 14443 Part 4 Errors,

other Errors.

RC522 Basic Function Library Documentation


2.14 Building the ExampleProject 37

2.14 Building the ExampleProject


The ExampleProject shows how to integrate the BFL into an application. This application can be
built and executed on top of the following Operating Systems:

Microsoft Windows 2000 + Microsoft Visual .NET


Fedora Linux Core 1 + GNU Compiler Collection (GCC 3.2)

How to build the ExampleProject

Using ExampleProject on Windows platforms


Open the ExampleProject.dsw using Microsoft Visual C++ 6 (SP5)
Set the appropriate subproject to active (by using the context menu over the subproject).
The active project can be recognized by the bold characters. All the build commands are
then applied to the active project.
Use the Rebuild all to generate the library and the application.
Define the arguments in the Project Settings (e.g. 1 COM1:)
Using ExampleProject on Linux
The command lines are valid for the bash shell. The second line has to be adapted if a different
shell is used. The makefiles are valid with the GNU compiler collection.
C - ExampleProject
make clib // Generate the BFL library

export LD LIBRARY PATH=. // Tell the application where to find the library

make capp // Generate the application

./CExample 1 /dev/ttyS0 // Start the ExampleApp (Example: Mifare Reader, First Serial Port)

C++ - ExampleProject
make cpplib // Generate the BFL

export LD LIBRARY PATH=. // Tell the location of the library

make cppapp // Generate the application

./CppExample 1 /dev/ttyS0 // Start the application with the given parameters

Note:
If the Linux implementation is used, the files have to be placed on top of a file system which
supports symbolic links (such as ext2, ext3, reiserfs). This is needed since the library is linked
via symbolic links.
Sometimes the Linux implementation has problems with the case senstivity of filenames. If
the project cannot be compiled, it is very likely that (due to the copy operation from the case
insensitive to the case senstive file system) some of the directories are incorrect regarding case
sensitivity. This can be either resolved by modifying the Makefile (preferred) of by modifying the
filenames themselves.
The application and the library is built as debug version. Optimization on size and speed can
be done by disabling the approprate flags (In Linux the CXXOPTIONS can be used to specify if
the library should contain debug info or not.
Since the ExampleProject does not use very system specific calls, the application should also run
on similar platforms like Windows XP, SuSE Linux, ....

RC522 Basic Function Library Documentation


Chapter 3

RC522 Basic Function Library


Data Structure Documentation

3.1 BAL WRITEBUS PARAM Struct Reference


#include <rclstruct.h>

3.1.1 Detailed Description

Parameter structure for the BAL WriteBus functionality.


Definition at line 80 of file rclstruct.h.

Data Fields
unsigned char bus data
void self

3.1.2 Field Documentation

3.1.2.1 unsigned char BAL WRITEBUS PARAM::bus data

[in/out] Data to write to (BAL WRITEBUS PARAM) / read from (BAL READBUS PARAM) the
periperal (RF chip) via the connecting bus.
Definition at line 82 of file rclstruct.h.

3.1.2.2 void BAL WRITEBUS PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.
Definition at line 85 of file rclstruct.h.
3.2 C BAL Struct Reference 39

3.2 C BAL Struct Reference


#include <rclstruct.h>

3.2.1 Detailed Description

C-interface structure of BUS ABSTRACTION LAYER (BAL). The BAL takes away the need to
be aware of the bus-interface specifics from upper layers. Usually the BAL is the lowest layer /
component of the RCL stack. In most cases, the bal can be omitted. Sometimes however it can be
useful, especially when using the RS 232 serial lnk.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 109 of file rclstruct.h.

Data Fields
C BAL WRITEBUS WriteBus
C BAL READBUS ReadBus
void mp Members
void mp CallingObject

3.2.2 Field Documentation

3.2.2.1 C BAL WRITEBUS C BAL::WriteBus

WriteBus member function.


Definition at line 112 of file rclstruct.h.

3.2.2.2 C BAL READBUS C BAL::ReadBus

ReadBus member function.


Definition at line 113 of file rclstruct.h.

3.2.2.3 void C BAL::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 115 of file rclstruct.h.

3.2.2.4 void C BAL::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 119 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.3 C ISO14443 4 Struct Reference 40

3.3 C ISO14443 4 Struct Reference


#include <rclstruct.h>
Collaboration diagram for C ISO14443 4:

C_BAL

mp_Lower

C_RC_REG_CTL

mp_Lower

C_RC_IO

mp_Lower

C_ISO14443_4

3.3.1 Detailed Description

C - Component interface of ISO 14443.4 data exchange protocol: This component does only data
exchange, card presence check and deselecting of a PICC. This is because only these three types of
functionality reflect the commonalities between ISO/IEC 14443.4 PICC type A and B. Protocol entry
functionality is only provided for PICC type A, however by a different interface, namely C ISO14443 -
4A ACTIVATION .

Examples:
Iso14443 4 ReaderC.c.

Definition at line 844 of file rclstruct.h.

Data Fields
ISO14443 4 EXCHANGE Exchange
ISO14443 4 PRESENCE CHECK PresenceCheck
ISO14443 4 DESELECT Deselect
ISO14443 4 SET PROTOCOL PARAMS SetProtocolParams
ISO14443 4 RESET PROTOCOL ResetProtocol
ISO14443 4 CB SET WTX CbSetWtx
ISO14443 4 CB SET READER PARAMS CbSetReaderParams
ISO14443 4 SET CB SetCallbacks
void mp Members
void mp CallingObject
void mp CppWrapper
C RC IO mp Lower

RC522 Basic Function Library Documentation


3.3 C ISO14443 4 Struct Reference 41

3.3.2 Field Documentation

3.3.2.1 ISO14443 4 EXCHANGE C ISO14443 4::Exchange

Data exchange protocol

Examples:
Iso14443 4 ReaderC.c.

Definition at line 847 of file rclstruct.h.

3.3.2.2 ISO14443 4 PRESENCE CHECK C ISO14443 4::PresenceCheck

PICC presence check function.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 848 of file rclstruct.h.

3.3.2.3 ISO14443 4 DESELECT C ISO14443 4::Deselect

Deselect function.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 849 of file rclstruct.h.

3.3.2.4 ISO14443 4 SET PROTOCOL PARAMS C ISO14443 4::SetProtocolParams

Apply session settings.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 850 of file rclstruct.h.

3.3.2.5 ISO14443 4 RESET PROTOCOL C ISO14443 4::ResetProtocol

Reset to initial state.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 851 of file rclstruct.h.

3.3.2.6 ISO14443 4 CB SET WTX C ISO14443 4::CbSetWtx

Callback for WTX handling.


Definition at line 854 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.3 C ISO14443 4 Struct Reference 42

3.3.2.7 ISO14443 4 CB SET READER PARAMS C ISO14443 4::CbSetReader-


Params

Callback for bitrate changing.


Definition at line 855 of file rclstruct.h.

3.3.2.8 ISO14443 4 SET CB C ISO14443 4::SetCallbacks

Callback initialiser interface.


Definition at line 858 of file rclstruct.h.

3.3.2.9 void C ISO14443 4::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 860 of file rclstruct.h.

3.3.2.10 void C ISO14443 4::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 864 of file rclstruct.h.

3.3.2.11 void C ISO14443 4::mp CppWrapper

Used, if wrapped by the C++ feature. This location stores the C++ objects address in order to be
available for the C-only feature for handing it over to a callback or the like.
Definition at line 866 of file rclstruct.h.

3.3.2.12 C RC IO C ISO14443 4::mp Lower

Point to the lower RC-I/O device:


Definition at line 878 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.4 C ISO14443 4A ACTIVATION Struct Reference 43

3.4 C ISO14443 4A ACTIVATION Struct Reference


#include <rclstruct.h>
Collaboration diagram for C ISO14443 4A ACTIVATION:

C_BAL

mp_Lower

C_RC_REG_CTL

mp_Lower

C_RC_IO

mp_Lower

C_ISO14443_4A_ACTIVATION

3.4.1 Detailed Description

C - Component interface of ISO 14443.4 PICC type A protocol entry. In the context of ISO 14443.4
this library exposes the PICC type A protocol entry with RATS and PPS. This component comes
without the ISO 14443.3 part (Initialisation and Anticollision) since that part is covered by a different
component. Moreover, this part initialises the ISO14443 4 PROTOCOL PARAM to be handed over
to the ISO 14443.4 transmission protocol.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 945 of file rclstruct.h.

Data Fields
ISO14443 4 RATS Rats
ISO14443 4 PPS Pps
unsigned short m trx buffer size
void mp Members
void mp CallingObject
C RC IO mp Lower

3.4.2 Field Documentation

3.4.2.1 ISO14443 4 RATS C ISO14443 4A ACTIVATION::Rats

Request for Answer to Select.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 948 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.4 C ISO14443 4A ACTIVATION Struct Reference 44

3.4.2.2 ISO14443 4 PPS C ISO14443 4A ACTIVATION::Pps

Protocol and Parameter Selection.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 949 of file rclstruct.h.

3.4.2.3 unsigned short C ISO14443 4A ACTIVATION::m trx buffer size

Buffer size for frames composed by the activation. Typical values are 64, 128 or 256[Bytes]
Definition at line 951 of file rclstruct.h.

3.4.2.4 void C ISO14443 4A ACTIVATION::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 955 of file rclstruct.h.

3.4.2.5 void C ISO14443 4A ACTIVATION::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 959 of file rclstruct.h.

3.4.2.6 C RC IO C ISO14443 4A ACTIVATION::mp Lower

Point to the lower RC-I/O device:


Definition at line 963 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.5 C ISO 14443 3A Struct Reference 45

3.5 C ISO 14443 3A Struct Reference


#include <rclstruct.h>
Collaboration diagram for C ISO 14443 3A:

C_BAL

mp_Lower

C_RC_REG_CTL

mp_Lower

C_ISO_14443_3A

3.5.1 Detailed Description

C - Component interface: Structure to call ISO 14443 Part 3 Type A functionality. ISO 14443.3
functionality represents PICC Initialisation and Anticollision as well as Halt.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 532 of file rclstruct.h.

Data Fields
RCL SET WAIT EVENT CB SetWaitEventCb
REQUESTA RequestA
ANTICOLLISIONSELECT AnticollisionSelect
SELECT Select
HALTA HaltA
void mp Members
void mp CallingObject
void mp UserRef
RCL WAIT EVENT CB mp WaitEventCB
C RC REG CTL mp Lower

3.5.2 Field Documentation

3.5.2.1 RCL SET WAIT EVENT CB C ISO 14443 3A::SetWaitEventCb

Event detection CB address submission.


Definition at line 535 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.5 C ISO 14443 3A Struct Reference 46

3.5.2.2 REQUESTA C ISO 14443 3A::RequestA

RequestA member function pointer.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 537 of file rclstruct.h.

3.5.2.3 ANTICOLLISIONSELECT C ISO 14443 3A::AnticollisionSelect

AnticollisionSelect member function pointer.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 538 of file rclstruct.h.

3.5.2.4 SELECT C ISO 14443 3A::Select

Select member function pointer.


Definition at line 539 of file rclstruct.h.

3.5.2.5 HALTA C ISO 14443 3A::HaltA

HaltA member function pointer.

Examples:
MifareReaderC.c.

Definition at line 540 of file rclstruct.h.

3.5.2.6 void C ISO 14443 3A::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 542 of file rclstruct.h.

3.5.2.7 void C ISO 14443 3A::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 546 of file rclstruct.h.

3.5.2.8 void C ISO 14443 3A::mp UserRef

[in] User reference. RCL WAIT EVENT CB receives this value with the parameter structure RCL -
WAIT EVENT CB PARAM.
Definition at line 552 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.5 C ISO 14443 3A Struct Reference 47

3.5.2.9 RCL WAIT EVENT CB C ISO 14443 3A::mp WaitEventCB

[in] Pointer to the event-detecting callback function, to be implemented by the embedding SW.
Definition at line 554 of file rclstruct.h.

3.5.2.10 C RC REG CTL C ISO 14443 3A::mp Lower

[in] Point to the lower RC-I/O device:


Definition at line 556 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.6 C JOINER ISO 14443 3 PARAMETERS Struct Reference 48

3.6 C JOINER ISO 14443 3 PARAMETERS Struct Refer-


ence
#include <iso14443 3 joiner.h>

3.6.1 Detailed Description

Internal control variable structure

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 55 of file iso14443 3 joiner.h.

Data Fields
unsigned char m InitiatorNotTarget

3.6.2 Field Documentation

3.6.2.1 unsigned char C JOINER ISO 14443 3 PARAMETERS::m InitiatorNotTarget

I: Initiator access
Definition at line 57 of file iso14443 3 joiner.h.

RC522 Basic Function Library Documentation


3.7 C JOINER RC IO PARAMETERS Struct Reference 49

3.7 C JOINER RC IO PARAMETERS Struct Reference


#include <rcio joiner.h>

3.7.1 Detailed Description

Internal control variables:

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 48 of file rcio joiner.h.

Data Fields
unsigned char m InitiatorNotTarget

3.7.2 Field Documentation

3.7.2.1 unsigned char C JOINER RC IO PARAMETERS::m InitiatorNotTarget

I: Initiator access
Definition at line 50 of file rcio joiner.h.

RC522 Basic Function Library Documentation


3.8 C JOINER RC OP CTL PARAMETERS Struct Reference 50

3.8 C JOINER RC OP CTL PARAMETERS Struct Refer-


ence
#include <rcopctl joiner.h>

3.8.1 Detailed Description

Internal control variables: Up until now there are no internals to keep track of. However, in order to be
ready for future extensions possibly requiring some internal variables to temporarly store information
the structure already exists.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 50 of file rcopctl joiner.h.

Data Fields
unsigned char dummy

3.8.2 Field Documentation

3.8.2.1 unsigned char C JOINER RC OP CTL PARAMETERS::dummy

dummy variable
Definition at line 52 of file rcopctl joiner.h.

RC522 Basic Function Library Documentation


3.9 C JOINER RS 232 PC BAL PARAMS Struct Reference 51

3.9 C JOINER RS 232 PC BAL PARAMS Struct Reference


#include <bal joiner rs232 pc.h>

3.9.1 Detailed Description

C-Interface (to be called via structure defined in rclstruct.h.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 46 of file bal joiner rs232 pc.h.

Data Fields
void com handle
unsigned char reverse bit order

3.9.2 Field Documentation

3.9.2.1 void C JOINER RS 232 PC BAL PARAMS::com handle

For the current implementation we require a handle to the PC-RS232 link: For other implementations
different parameters may be required.
Definition at line 52 of file bal joiner rs232 pc.h.

3.9.2.2 unsigned char C JOINER RS 232 PC BAL PARAMS::reverse bit order

Testchip needs reversed bit order:


Definition at line 53 of file bal joiner rs232 pc.h.

RC522 Basic Function Library Documentation


3.10 C JOINER RS 232 PC RC REG CTL PARAMS Struct Reference 52

3.10 C JOINER RS 232 PC RC REG CTL PARAMS


Struct Reference
#include <rcregctl joiner rs232 pc.h>

3.10.1 Detailed Description

Parameter structure for testchip

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 45 of file rcregctl joiner rs232 pc.h.

Data Fields
unsigned char shl address

3.10.2 Field Documentation

3.10.2.1 unsigned char C JOINER RS 232 PC RC REG CTL PARAMS::shl address

For the current implementation we require a flag which indicates the members to shift left the address
of the register by one position, as required by the test-chip.
Definition at line 50 of file rcregctl joiner rs232 pc.h.

RC522 Basic Function Library Documentation


3.11 C MF RD INTL PARAMS Struct Reference 53

3.11 C MF RD INTL PARAMS Struct Reference


#include <mifare.h>

3.11.1 Detailed Description

Internal control variables: This structure holds all component-related variables and is referenced by
the mp Members element of C MIFARE READER.

Examples:
MifareReaderC.c.

Definition at line 86 of file mifare.h.

Data Fields
unsigned char m TrxBuffer

3.11.2 Field Documentation

3.11.2.1 unsigned char C MF RD INTL PARAMS::m TrxBuffer

The TX/RX buffer used for underlying operations. Since the minimum size of this buffer is specified
to be 64 bytes no length information needs to be present because all Mifare requests / responses are
well below this boundary.
Definition at line 93 of file mifare.h.

RC522 Basic Function Library Documentation


3.12 C MIFARE READER Struct Reference 54

3.12 C MIFARE READER Struct Reference


#include <rclstruct.h>
Collaboration diagram for C MIFARE READER:

C_BAL

mp_Lower

C_RC_REG_CTL

mp_Lower

C_RC_IO

mp_Lower

C_MIFARE_READER

3.12.1 Detailed Description

C - Component interface: Structure to call MIFARE Reader functionality.


This interface exposes the MIFARE Reader functionality without the ISO 14443.3 Initialisation and
Anticollision part.

Examples:
MifareReaderC.c.

Definition at line 622 of file rclstruct.h.

Data Fields
MIFARE GENERIC SINGLE GenericSingle
MIFARE GENERIC DOUBLE GenericDouble
MIFARE CMD Transaction
void mp Members
void mp CallingObject
C RC IO mp Lower

3.12.2 Field Documentation

3.12.2.1 MIFARE GENERIC SINGLE C MIFARE READER::GenericSingle

Internally used! Performs a TX-RX cycle.


Definition at line 625 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.12 C MIFARE READER Struct Reference 55

3.12.2.2 MIFARE GENERIC DOUBLE C MIFARE READER::GenericDouble

Internally used! Performs a TX-RX-TX-RX cycle


Definition at line 626 of file rclstruct.h.

3.12.2.3 MIFARE CMD C MIFARE READER::Transaction

Mifare functionality according to spec.

Examples:
MifareReaderC.c.

Definition at line 627 of file rclstruct.h.

3.12.2.4 void C MIFARE READER::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 629 of file rclstruct.h.

3.12.2.5 void C MIFARE READER::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 633 of file rclstruct.h.

3.12.2.6 C RC IO C MIFARE READER::mp Lower

Point to the lower RC-I/O device:


Definition at line 637 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.13 C RC IO Struct Reference 56

3.13 C RC IO Struct Reference


#include <rclstruct.h>
Collaboration diagram for C RC IO:

C_BAL

mp_Lower

C_RC_REG_CTL

mp_Lower

C_RC_IO

3.13.1 Detailed Description

C - Component interface: Structure to call RC/IO functionality: The RC-I/O component is respon-
sible for all transparent I/O operations and other I/O commands of the RF chip. The layer of this
component is the topmost of the hardware-depending layers. This component is required by protocols
(e.g. Mifare, ISO 14443.4) to perform I/O operations.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 429 of file rclstruct.h.

Data Fields
RCL SET WAIT EVENT CB SetWaitEventCb
C RCIO TRANSCEIVE Transceive
C RCIO TRANSMIT Transmit
C RCIO RECEIVE Receive
C RCIO MFAUTHENT MfAuthent
void mp Members
void mp CallingObject
void mp UserRef
RCL WAIT EVENT CB mp WaitEventCB
C RC REG CTL mp Lower

3.13.2 Field Documentation

3.13.2.1 RCL SET WAIT EVENT CB C RC IO::SetWaitEventCb

Event detection CB address submission.


Definition at line 432 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.13 C RC IO Struct Reference 57

3.13.2.2 C RCIO TRANSCEIVE C RC IO::Transceive

Transceive member function pointer.


Definition at line 434 of file rclstruct.h.

3.13.2.3 C RCIO TRANSMIT C RC IO::Transmit

Transmit member function pointer.


Definition at line 435 of file rclstruct.h.

3.13.2.4 C RCIO RECEIVE C RC IO::Receive

Receive member function pointer.


Definition at line 436 of file rclstruct.h.

3.13.2.5 C RCIO MFAUTHENT C RC IO::MfAuthent

MfAuthent member function pointer.


Definition at line 437 of file rclstruct.h.

3.13.2.6 void C RC IO::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 439 of file rclstruct.h.

3.13.2.7 void C RC IO::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 443 of file rclstruct.h.

3.13.2.8 void C RC IO::mp UserRef

[in] User reference. RCL WAIT EVENT CB receives this value with the parameter structure RCL -
WAIT EVENT CB PARAM.
Definition at line 449 of file rclstruct.h.

3.13.2.9 RCL WAIT EVENT CB C RC IO::mp WaitEventCB

[in] Pointer to the event-detecting callback function, to be implemented by the embedding SW.
Definition at line 451 of file rclstruct.h.

3.13.2.10 C RC REG CTL C RC IO::mp Lower

[in] Lower edge:

RC522 Basic Function Library Documentation


3.13 C RC IO Struct Reference 58

Definition at line 453 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.14 C RC OP CTL Struct Reference 59

3.14 C RC OP CTL Struct Reference


#include <rclstruct.h>
Collaboration diagram for C RC OP CTL:

C_BAL

mp_Lower

C_RC_REG_CTL

mp_Lower

C_RC_OP_CTL

3.14.1 Detailed Description

C - Component interface: Structure reflecting operation control functionality. This functionality


allows configuration of the RF-chip on a higher level than the register access functions.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 304 of file rclstruct.h.

Data Fields
RCL SET WAIT EVENT CB SetWaitEventCb
C RCOPCTL GETATR SetAttrib
C RCOPCTL GETATR GetAttrib
void mp Members
void mp CallingObject
void mp UserRef
RCL WAIT EVENT CB mp WaitEventCB
C RC REG CTL mp Lower

3.14.2 Field Documentation

3.14.2.1 RCL SET WAIT EVENT CB C RC OP CTL::SetWaitEventCb

Event detection CB address submission.


Definition at line 307 of file rclstruct.h.

3.14.2.2 C RCOPCTL GETATR C RC OP CTL::SetAttrib

Set Attrib member function.


Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

RC522 Basic Function Library Documentation


3.14 C RC OP CTL Struct Reference 60

Definition at line 309 of file rclstruct.h.

3.14.2.3 C RCOPCTL GETATR C RC OP CTL::GetAttrib

Get Attrib member function.


Definition at line 310 of file rclstruct.h.

3.14.2.4 void C RC OP CTL::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 312 of file rclstruct.h.

3.14.2.5 void C RC OP CTL::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 316 of file rclstruct.h.

3.14.2.6 void C RC OP CTL::mp UserRef

[in] User reference. RCL WAIT EVENT CB receives this value with the parameter structure RCL -
WAIT EVENT CB PARAM.
Definition at line 322 of file rclstruct.h.

3.14.2.7 RCL WAIT EVENT CB C RC OP CTL::mp WaitEventCB

[in] Pointer to the event-detecting callback function, to be implemented by the embedding SW.
Definition at line 324 of file rclstruct.h.

3.14.2.8 C RC REG CTL C RC OP CTL::mp Lower

[in] Lower edge:


Definition at line 326 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.15 C RC REG CTL Struct Reference 61

3.15 C RC REG CTL Struct Reference


#include <rclstruct.h>
Collaboration diagram for C RC REG CTL:

C_RC_REG_CTL

C_BAL
mp_Lower

3.15.1 Detailed Description

C-interface structure of register access functionality. The Register Control interface is the basic RC-
related interface. It allows access of RC registers and their bits. This component is the most versatile,
but least specific one. Usually this component is the lowest one.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 187 of file rclstruct.h.

Data Fields
C RC REG CTL SETREG SetRegister
C RC REG CTL GETREG GetRegister
C RC REG CTL MODREG ModifyRegister
void mp Members
void mp CallingObject
C BAL mp Lower

3.15.2 Field Documentation

3.15.2.1 C RC REG CTL SETREG C RC REG CTL::SetRegister

SetRegister member function.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 190 of file rclstruct.h.

3.15.2.2 C RC REG CTL GETREG C RC REG CTL::GetRegister

GetRegister member function.

RC522 Basic Function Library Documentation


3.15 C RC REG CTL Struct Reference 62

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 191 of file rclstruct.h.

3.15.2.3 C RC REG CTL MODREG C RC REG CTL::ModifyRegister

ModifyRegister member function.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 192 of file rclstruct.h.

3.15.2.4 void C RC REG CTL::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 194 of file rclstruct.h.

3.15.2.5 void C RC REG CTL::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 198 of file rclstruct.h.

3.15.2.6 C BAL C RC REG CTL::mp Lower

[in] Lower edge:


Definition at line 203 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.16 C RCL ID MANAGER Struct Reference 63

3.16 C RCL ID MANAGER Struct Reference


#include <rclstruct.h>

3.16.1 Detailed Description

C-interface structure for ID-Manager:


Definition at line 1003 of file rclstruct.h.

Data Fields
RCL IDMAN MEMBER GetFreeID
RCL IDMAN MEMBER IsFreeID
RCL IDMAN MEMBER AssignID
RCL IDMAN MEMBER FreeIDByNumber
RCL IDMAN MEMBER FreeIDByInstance
void mp Members
void mp CallingObject

3.16.2 Field Documentation

3.16.2.1 RCL IDMAN MEMBER C RCL ID MANAGER::GetFreeID

Get the first free ID available.


Definition at line 1007 of file rclstruct.h.

3.16.2.2 RCL IDMAN MEMBER C RCL ID MANAGER::IsFreeID

Check whether the ID is available.


Definition at line 1008 of file rclstruct.h.

3.16.2.3 RCL IDMAN MEMBER C RCL ID MANAGER::AssignID

Enter new instance into the ID manager list.


Definition at line 1009 of file rclstruct.h.

3.16.2.4 RCL IDMAN MEMBER C RCL ID MANAGER::FreeIDByNumber

Free ID by specifying the number.


Definition at line 1010 of file rclstruct.h.

3.16.2.5 RCL IDMAN MEMBER C RCL ID MANAGER::FreeIDByInstance

Free ID by specifying the object instance.


Definition at line 1011 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.16 C RCL ID MANAGER Struct Reference 64

3.16.2.6 void C RCL ID MANAGER::mp Members

Internal variables of the C-interface. Usually a structure is behind this pointer. The type of the
structure depends on the implementation requirements.
Definition at line 1013 of file rclstruct.h.

3.16.2.7 void C RCL ID MANAGER::mp CallingObject

Used by the Glue-Class to reference the wrapping C++ object, calling into the C-interface.
Definition at line 1017 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.17 IDMAN PARAMETERS Struct Reference 65

3.17 IDMAN PARAMETERS Struct Reference


#include <idman.h>

3.17.1 Detailed Description

Internal control variables: This structure holds all component-related variables and is referenced by
the mp Members element of C RCL ID MANAGER.
Definition at line 50 of file idman.h.

Data Fields
void mp Instances [MAX ID COUNT]

RC522 Basic Function Library Documentation


3.18 ISO14443 3 ANTICOLLISIONSELECT PARAM Struct Reference 66

3.18 ISO14443 3 ANTICOLLISIONSELECT PARAM


Struct Reference
#include <rclstruct.h>

3.18.1 Detailed Description

Parameter structure for Anticollission/Select functionality. The AnticollisionSelect function which


takes this parameter performs the acquisition loop according to ISO 14443-3.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 485 of file rclstruct.h.

Data Fields
unsigned char sel lv1 code
unsigned char uid
unsigned char uid length
unsigned char sak
void self

3.18.2 Field Documentation

3.18.2.1 unsigned char ISO14443 3 ANTICOLLISIONSELECT PARAM::sel lv1 code

[in] Select code for 1st cascade level according to ISO 14443-3. default: 0x93

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 487 of file rclstruct.h.

3.18.2.2 unsigned char ISO14443 3 ANTICOLLISIONSELECT PARAM::uid

[in] Buffer for up to 3 cascade levels of serial number.


Note: All unused bytes have to be initialised with 0 for correct results.
[out] received serial number from PICC.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 488 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.18 ISO14443 3 ANTICOLLISIONSELECT PARAM Struct Reference 67

3.18.2.3 unsigned char ISO14443 3 ANTICOLLISIONSELECT PARAM::uid length

[in] number of known (valid) bits to send.


[out] length of (U)ID in bits. Also the cascaded byte (0x88) is included.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 491 of file rclstruct.h.

3.18.2.4 unsigned char ISO14443 3 ANTICOLLISIONSELECT PARAM::sak

[out] Select Acknowledge byte from the Card (if cascaded, only last SAK byte is returned).

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 493 of file rclstruct.h.

3.18.2.5 void ISO14443 3 ANTICOLLISIONSELECT PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Remark: Should be left dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 495 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.19 ISO14443 3 HALT A PARAM Struct Reference 68

3.19 ISO14443 3 HALT A PARAM Struct Reference


#include <rclstruct.h>

3.19.1 Detailed Description

Parameter structure for Halt functionality. The HaltA function moves an ISO 14443-3 Type A PICC
out of protocol in Initator/Reader mode and checks if the incoming data according to Halt format in
Target/Card mode.

Examples:
MifareReader.cpp, and MifareReaderC.c.

Definition at line 505 of file rclstruct.h.

Data Fields
unsigned char buffer
unsigned short buffer length
void self

3.19.2 Field Documentation

3.19.2.1 unsigned char ISO14443 3 HALT A PARAM::buffer

[in] This parameter shall be set to NULL.


Definition at line 507 of file rclstruct.h.

3.19.2.2 unsigned short ISO14443 3 HALT A PARAM::buffer length

[in] This parameter shall be set to 0.


Definition at line 508 of file rclstruct.h.

3.19.2.3 void ISO14443 3 HALT A PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Remark: Should be left dangling when calling the C++ wrapper.

Examples:
MifareReaderC.c.

Definition at line 509 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.20 ISO14443 3 REQUEST A PARAM Struct Reference 69

3.20 ISO14443 3 REQUEST A PARAM Struct Reference


#include <rclstruct.h>

3.20.1 Detailed Description

Parameter structure for Request functionality. The RequestA function issues a REQA or WUPA
request, depending on the req code parameter.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 467 of file rclstruct.h.

Data Fields
unsigned char req code
unsigned char atq
void self

3.20.2 Field Documentation

3.20.2.1 unsigned char ISO14443 3 REQUEST A PARAM::req code

[in] Request code according to ISO 14443-3. Possible values are ISO14443 3 REQIDL (0x26) and
ISO14443 3 REQALL (0x52).

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 469 of file rclstruct.h.

3.20.2.2 unsigned char ISO14443 3 REQUEST A PARAM::atq

[in] Already allocated buffer of two bytes (16 bits).


[out] ATQA (Answer to Request type A), received from PICC (16 bit). atq[0] ... LSB, atq[1] ...
MSB
Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 471 of file rclstruct.h.

3.20.2.3 void ISO14443 3 REQUEST A PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Remark: Should be left dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 474 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.21 ISO14443 4 CB SET READER PARAM Struct Reference 70

3.21 ISO14443 4 CB SET READER PARAM Struct Refer-


ence
#include <rclstruct.h>

3.21.1 Detailed Description

Parameter structure for SET BITRATE CALLBACK functionality. The callback function expects a
pointer to this parameter.
Definition at line 753 of file rclstruct.h.

Data Fields
void object
unsigned char dri
unsigned char dsi
unsigned char fwi

3.21.2 Field Documentation

3.21.2.1 void ISO14443 4 CB SET READER PARAM::object

[in] Pointer to reference the current object:


Using pure C only, this parameter holds the address of the C-structure instance of the protocol.
Using C++ however, this parameter points to the C++ object, embedding the C-part.
Definition at line 755 of file rclstruct.h.

3.21.2.2 unsigned char ISO14443 4 CB SET READER PARAM::dri

[in] Divisor Recive Integer, as specified by ISO/IEC 14443-4, determining the bitrates used from PICC
to PCD.
Definition at line 760 of file rclstruct.h.

3.21.2.3 unsigned char ISO14443 4 CB SET READER PARAM::dsi

[in] Divisor Send Integer, as specified by ISO/IEC 14443-4, determining the bitrates used from PCD
to PICC.
Definition at line 762 of file rclstruct.h.

3.21.2.4 unsigned char ISO14443 4 CB SET READER PARAM::fwi

[in] Frame waiting time-i: This value has to be applied according to ISO 14443-4 to the reader by the
application-defined callback function.
Definition at line 764 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.22 ISO14443 4 CB SET WTX PARAM Struct Reference 71

3.22 ISO14443 4 CB SET WTX PARAM Struct Reference


#include <rclstruct.h>

3.22.1 Detailed Description

Parameter structure for the SET WTX CALLBACK function. The callback function expects a pointer
to this parameter.
Definition at line 729 of file rclstruct.h.

Data Fields
void object
unsigned char set
unsigned char wtxm
unsigned char fwi

3.22.2 Field Documentation

3.22.2.1 void ISO14443 4 CB SET WTX PARAM::object

[in] Pointer to reference the current object:


Using pure C only, this parameter holds the address of the C-structure instance of the protocol.
Using C++ however, this parameter points to the C++ object, embedding the C-part.
Definition at line 731 of file rclstruct.h.

3.22.2.2 unsigned char ISO14443 4 CB SET WTX PARAM::set

[in] Boolean value: If set it indicates that the value specified in the wtxm parameter member shall be
applied.
If zero, the timeout shall be reset to the default and the value in wtxm is not valid.
Definition at line 736 of file rclstruct.h.

3.22.2.3 unsigned char ISO14443 4 CB SET WTX PARAM::wtxm

[in] WTXM, encoded as specified by ISO 14443-4. This value has to be applied according to ISO
14443-4 to the reader by the application-defined callback function.
Definition at line 740 of file rclstruct.h.

3.22.2.4 unsigned char ISO14443 4 CB SET WTX PARAM::fwi

[in] Frame waiting time-i: This value has to be applied according to ISO 14443-4 to the reader by the
application-defined callback function.
Definition at line 743 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.23 ISO14443 4 COMMUNICATION PARAMETERS Struct Reference 72

3.23 ISO14443 4 COMMUNICATION PARAMETERS


Struct Reference
#include <iso14443 4.h>

3.23.1 Detailed Description

Structure with general internal operation parameters:

Examples:
Iso14443 4 ReaderC.c.

Definition at line 92 of file iso14443 4.h.

Data Fields
unsigned char mp TRxBuffer
unsigned short m MaxTRxBufferSize
unsigned char m DSI
unsigned char m DRI
unsigned char m CID
unsigned char m NAD
unsigned char m Flags
unsigned char m State
unsigned char m BlockNumber
unsigned char mp CopyBytes
unsigned char mp StartOfBlock
unsigned char m MaxRetryCounter
unsigned char m FWI
unsigned char m Index
unsigned char m Size

3.23.2 Field Documentation

3.23.2.1 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::mp TRx-


Buffer

System-mamaged TRx buffer reference, used for internal APDU composition / analysis.
Definition at line 94 of file iso14443 4.h.

3.23.2.2 unsigned short ISO14443 4 COMMUNICATION PARAMETERS::m Max-


TRxBufferSize

Size of TRx buffer.


Definition at line 96 of file iso14443 4.h.

RC522 Basic Function Library Documentation


3.23 ISO14443 4 COMMUNICATION PARAMETERS Struct Reference 73

3.23.2.3 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m DSI

Selected divisor integer from PICC to PCD.


Definition at line 97 of file iso14443 4.h.

3.23.2.4 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m DRI

Selected divisor integer from PCD to PICC.


Definition at line 98 of file iso14443 4.h.

3.23.2.5 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m CID

CID used for the current session.


Definition at line 99 of file iso14443 4.h.

3.23.2.6 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m NAD

NAD for chaining (only first block).


Definition at line 100 of file iso14443 4.h.

3.23.2.7 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m Flags

Contains information about CID/NAD support by the PCD/PICC as well as their usage. Furthermore
this byte controls the internal flow in connection with e.g. timeout or chaining.
Definition at line 101 of file iso14443 4.h.

3.23.2.8 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m State

Stores the current and previous state of data exchange.


Definition at line 105 of file iso14443 4.h.

3.23.2.9 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m Block-


Number

Block Number used by Data Exchange function.


Definition at line 107 of file iso14443 4.h.

3.23.2.10 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::mp -


CopyBytes

Pointer used for chaining and copying of data.


Definition at line 108 of file iso14443 4.h.

RC522 Basic Function Library Documentation


3.23 ISO14443 4 COMMUNICATION PARAMETERS Struct Reference 74

3.23.2.11 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::mp -


StartOfBlock

Pointer to indicate the protocol where the current block to transfer starts.
Definition at line 109 of file iso14443 4.h.

3.23.2.12 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m Max-


RetryCounter

Maximum number of attempts to re-establish a connection after errors.


Definition at line 111 of file iso14443 4.h.

3.23.2.13 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m FWI

Frame Waiting Time


Definition at line 114 of file iso14443 4.h.

3.23.2.14 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m Index

Index for APDU Picc chaining if userbuffer full


Definition at line 116 of file iso14443 4.h.

3.23.2.15 unsigned char ISO14443 4 COMMUNICATION PARAMETERS::m Size

current TRX buffer size (for PICC APDU chaining)


Definition at line 118 of file iso14443 4.h.

RC522 Basic Function Library Documentation


3.24 ISO14443 4 DESELECT PARAM Struct Reference 75

3.24 ISO14443 4 DESELECT PARAM Struct Reference


#include <rclstruct.h>

3.24.1 Detailed Description

Parameter structure for Deselect functionality.


This function issues a DESELECT command.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 710 of file rclstruct.h.

Data Fields
void self

3.24.2 Field Documentation

3.24.2.1 void ISO14443 4 DESELECT PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 712 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.25 ISO14443 4 EXCHANGE PARAM Struct Reference 76

3.25 ISO14443 4 EXCHANGE PARAM Struct Reference


#include <rclstruct.h>

3.25.1 Detailed Description

Parameter structure for Data Exchange functionality. The function for data exchange in the ISO/IEC
14443.4 protocol takes a pointer to this structure. The buffers for sending and receiving may overlap
or even be the same.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 683 of file rclstruct.h.

Data Fields
unsigned char nad send
unsigned char snd buf
unsigned long snd buf len
unsigned char nad receive
unsigned char rec buf
unsigned long rec buf len
unsigned char flags
void self

3.25.2 Field Documentation

3.25.2.1 unsigned char ISO14443 4 EXCHANGE PARAM::nad send

[in] NAD to send from the PCD to the PICC.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 685 of file rclstruct.h.

3.25.2.2 unsigned char ISO14443 4 EXCHANGE PARAM::snd buf

[in] A large (64k) buffer which must be pre-allocated and initialised with the data to send.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 686 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.25 ISO14443 4 EXCHANGE PARAM Struct Reference 77

3.25.2.3 unsigned long ISO14443 4 EXCHANGE PARAM::snd buf len

[in] Number of data bytes to send to the PICC.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 688 of file rclstruct.h.

3.25.2.4 unsigned char ISO14443 4 EXCHANGE PARAM::nad receive

[out] NAD received from the Target, if used.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 689 of file rclstruct.h.

3.25.2.5 unsigned char ISO14443 4 EXCHANGE PARAM::rec buf

[out] A large (64k) buffer which must be pre-allocated is the destination for data to receive.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 690 of file rclstruct.h.

3.25.2.6 unsigned long ISO14443 4 EXCHANGE PARAM::rec buf len

[in] Number of bytes available in the receive buffer: The function checks this value against the number
of bytes being received. In case of insufficient space the function breaks and returns an error.
[out] Number of bytes received from the PICC.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 692 of file rclstruct.h.

3.25.2.7 unsigned char ISO14443 4 EXCHANGE PARAM::flags

[in/out] Contains flags to control the behaviour of Exchange. The flag masks are defined in iso14443 -
4.h .
Definition at line 697 of file rclstruct.h.

3.25.2.8 void ISO14443 4 EXCHANGE PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.

RC522 Basic Function Library Documentation


3.25 ISO14443 4 EXCHANGE PARAM Struct Reference 78

Examples:
Iso14443 4 ReaderC.c.

Definition at line 699 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.26 ISO14443 4 PPS PARAM Struct Reference 79

3.26 ISO14443 4 PPS PARAM Struct Reference


#include <rclstruct.h>

3.26.1 Detailed Description

Parameter structure for Protocol Parameter Select functionality.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 913 of file rclstruct.h.

Data Fields
unsigned char cid
unsigned char dsi
unsigned char dri
void self

3.26.2 Field Documentation

3.26.2.1 unsigned char ISO14443 4 PPS PARAM::cid

[in] CID assigned to the PICC. The function checks the range.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 915 of file rclstruct.h.

3.26.2.2 unsigned char ISO14443 4 PPS PARAM::dsi

[in] Dividor Send Integer: ISO/IEC 14443.4 reference value for baud rate used when sending data to
the PICC.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 916 of file rclstruct.h.

3.26.2.3 unsigned char ISO14443 4 PPS PARAM::dri

[in] Dividor Receive Integer: ISO/IEC 14443.4 reference value for baud rate used when receiving data
from the PICC.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 918 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.26 ISO14443 4 PPS PARAM Struct Reference 80

3.26.2.4 void ISO14443 4 PPS PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 920 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.27 ISO14443 4 PROTOCOL PARAM Struct Reference 81

3.27 ISO14443 4 PROTOCOL PARAM Struct Reference


#include <rclstruct.h>

3.27.1 Detailed Description

Structure for ISO/IEC 14443.4 data transmission protocol initialisation. This structure has to be
handed over to the protocol component instance prior to communication and after PICC protocol
entry. The purpose is to inform the data exchange protocol about the PICC and Reader properties
(parameters) to use during communication.
This structure is filled automatically be the protocol entry interface C ISO14443 4A ACTIVATION
for type A PICCs but has to be initialised member-by-member when operating type B PICCs.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 656 of file rclstruct.h.

Data Fields
unsigned char trx buffer
unsigned short trx buffer size
unsigned char cid supported
unsigned char nad supported
unsigned char cid
unsigned char tx baud int
unsigned char rx baud int
unsigned char fwi

3.27.2 Field Documentation

3.27.2.1 unsigned char ISO14443 4 PROTOCOL PARAM::trx buffer

[in] Pointer to a pre - allocated TX/RX buffer. This buffer is used by the protocol for data exchange
frame composition and handed over to the underlying I/O features (RC-I/O).
Definition at line 658 of file rclstruct.h.

3.27.2.2 unsigned short ISO14443 4 PROTOCOL PARAM::trx buffer size

[in] Buffer size for frames composed by the protocol. Typical values are 64, 128 or 256 [bytes].
Definition at line 661 of file rclstruct.h.

3.27.2.3 unsigned char ISO14443 4 PROTOCOL PARAM::cid supported

[in] A value other than zero (TRUE) indicates that CID is supported and shall be used by the protocol.
Definition at line 663 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.27 ISO14443 4 PROTOCOL PARAM Struct Reference 82

3.27.2.4 unsigned char ISO14443 4 PROTOCOL PARAM::nad supported

[in] A value other than zero (TRUE) indicates that NAD is supported and shall be used by the
protocol.
Definition at line 665 of file rclstruct.h.

3.27.2.5 unsigned char ISO14443 4 PROTOCOL PARAM::cid

[in] If CID is supported this value will be inserted into the CID field of exchanged frames.
Definition at line 667 of file rclstruct.h.

3.27.2.6 unsigned char ISO14443 4 PROTOCOL PARAM::tx baud int

[in] ISO/IEC 14443.4 definitions for the baud rate (DSI) used for sending information to the PICC.
Definition at line 669 of file rclstruct.h.

3.27.2.7 unsigned char ISO14443 4 PROTOCOL PARAM::rx baud int

[in] ISO/IEC 14443.4 definitions for the baud rate (DRI) used for receiving information from the
PICC.
Definition at line 671 of file rclstruct.h.

3.27.2.8 unsigned char ISO14443 4 PROTOCOL PARAM::fwi

Definition at line 673 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.28 ISO14443 4 RATS PARAM Struct Reference 83

3.28 ISO14443 4 RATS PARAM Struct Reference


#include <rclstruct.h>

3.28.1 Detailed Description

Parameter structure for RATS command (Get Ats of the PICC).

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 890 of file rclstruct.h.

Data Fields
unsigned char cid
unsigned char fsi
unsigned char ats
unsigned short ats len
unsigned char ta1
unsigned char tb1
unsigned char tc1
unsigned char app inf
unsigned char app inf len
void self

3.28.2 Field Documentation

3.28.2.1 unsigned char ISO14443 4 RATS PARAM::cid

[in] CID assigned to the PICC. The function only checks the range, but not the rules in the context
of the value 0.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 892 of file rclstruct.h.

3.28.2.2 unsigned char ISO14443 4 RATS PARAM::fsi

[in] FSDI, the PCD frame size integer, according to ISO/IEC 14443.4.
[out] FSDI, the PCD frame size integer, according to ISO/IEC 14443.4.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 894 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.28 ISO14443 4 RATS PARAM Struct Reference 84

3.28.2.3 unsigned char ISO14443 4 RATS PARAM::ats

[in/out] Pointer to a pre-allocated buffer receiving the ATS. The size of the buffer has to comply to
the ISO/IEC 14443.4 - defined maximum size of the ATS.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 896 of file rclstruct.h.

3.28.2.4 unsigned short ISO14443 4 RATS PARAM::ats len

[out] Length of the ATS, received from the PICC.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 899 of file rclstruct.h.

3.28.2.5 unsigned char ISO14443 4 RATS PARAM::ta1

[out] Pointer to the TA(1) location within the ATS.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 900 of file rclstruct.h.

3.28.2.6 unsigned char ISO14443 4 RATS PARAM::tb1

[out] Pointer to the TB(1) location within the ATS.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 901 of file rclstruct.h.

3.28.2.7 unsigned char ISO14443 4 RATS PARAM::tc1

[out] Pointer to the TC(1) location within the ATS.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 902 of file rclstruct.h.

3.28.2.8 unsigned char ISO14443 4 RATS PARAM::app inf

[out] Pointer to the Historical byte begin within the ATS.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 903 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.28 ISO14443 4 RATS PARAM Struct Reference 85

3.28.2.9 unsigned char ISO14443 4 RATS PARAM::app inf len

[out] Length of the Historical Bytes within the ATS.

Examples:
Iso14443 4 Reader.cpp, and Iso14443 4 ReaderC.c.

Definition at line 904 of file rclstruct.h.

3.28.2.10 void ISO14443 4 RATS PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c.

Definition at line 905 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.29 ISO14443 4 SET CB PARAM Struct Reference 86

3.29 ISO14443 4 SET CB PARAM Struct Reference


#include <rclstruct.h>

3.29.1 Detailed Description

Parameter structure for the function for setting the callback addresses.
Definition at line 815 of file rclstruct.h.

Data Fields
ISO14443 4 CB SET WTX set wtx cb
ISO14443 4 CB SET READER PARAMS set reader params cb
void self

3.29.2 Field Documentation

3.29.2.1 ISO14443 4 CB SET WTX ISO14443 4 SET CB PARAM::set wtx cb

[in] Pointer to the callback function handling the WTX request. If NULL, the protocol operates
without WTX capability.
Definition at line 817 of file rclstruct.h.

3.29.2.2 ISO14443 4 CB SET READER PARAMS ISO14443 4 SET CB -


PARAM::set reader params cb

[in] Pointer to the callback function handling the bitrate switching. If NULL, the protocol operates
without bitrate changing capability.
Definition at line 820 of file rclstruct.h.

3.29.2.3 void ISO14443 4 SET CB PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.
Definition at line 823 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.30 MIFARE CMD PARAM Struct Reference 87

3.30 MIFARE CMD PARAM Struct Reference


#include <rclstruct.h>

3.30.1 Detailed Description

Parameter structure for Mifare Reader functionality.

Examples:
MifareReader.cpp, and MifareReaderC.c.

Definition at line 574 of file rclstruct.h.

Data Fields
unsigned char cmd
unsigned char addr
unsigned char buffer
unsigned char buffer length
unsigned char reply type
void self

3.30.2 Field Documentation

3.30.2.1 unsigned char MIFARE CMD PARAM::cmd

[in] MIFARE specification-compliant command byte (according to MIFARE specification) or defined


in file mifare.h .

Examples:
MifareReader.cpp, and MifareReaderC.c.

Definition at line 578 of file rclstruct.h.

3.30.2.2 unsigned char MIFARE CMD PARAM::addr

[in] MIFARE block address: MIFARE operates block-oriented, although authentication is sector-
based.

Examples:
MifareReader.cpp, and MifareReaderC.c.

Definition at line 582 of file rclstruct.h.

3.30.2.3 unsigned char MIFARE CMD PARAM::buffer

[in] For sending bytes this must be a pre-allocated and initialised buffer. For receiving data, the buffer
must be pre-allocated and of a size of MIFARE MAX DATABUFFER SIZE, defined in mifare.h .
[out] Data copied into the buffer by this function e.g. as a result of a READ operation.

RC522 Basic Function Library Documentation


3.30 MIFARE CMD PARAM Struct Reference 88

Examples:
MifareReader.cpp, and MifareReaderC.c.

Definition at line 588 of file rclstruct.h.

3.30.2.4 unsigned char MIFARE CMD PARAM::buffer length

[in] Length of data to send: Usually this value is 16 for a block to write.
For a READ operation this value should be initialised with 0.
[out] Receive buffer length: Number of data bytes received.

Examples:
MifareReader.cpp, and MifareReaderC.c.

Definition at line 593 of file rclstruct.h.

3.30.2.5 unsigned char MIFARE CMD PARAM::reply type

[in] When using the Transaction member of the MIFARE functionality this parameter should be left
dangling.
When using the generic Mifare methods, this parameter specifies what type of response (none or
timeout respectively, acknowledge or data) to expect.
Definition at line 599 of file rclstruct.h.

3.30.2.6 void MIFARE CMD PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.

Examples:
MifareReaderC.c.

Definition at line 600 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.31 RCIO RECEIVE PARAM Struct Reference 89

3.31 RCIO RECEIVE PARAM Struct Reference


#include <rclstruct.h>

3.31.1 Detailed Description

Parameter structure for Receive functionality. This structure reflects a transparent Receive channel.
The Receive function enters wait mode and finally returns after all bytes have been received or an
error (e.g. timeout) occurs.
Definition at line 388 of file rclstruct.h.

Data Fields
unsigned char rx buffer
unsigned short rx buffer size
void self

3.31.2 Field Documentation

3.31.2.1 unsigned char RCIO RECEIVE PARAM::rx buffer

[in] Already allocated memory space sufficiently large to receive incoming data.
[out] Data copied to the provided buffer.
Definition at line 390 of file rclstruct.h.

3.31.2.2 unsigned short RCIO RECEIVE PARAM::rx buffer size

[in] Maximum return buffer size in bytes. This member informs the function about the size of the
buffer for incoming data. The function checkes the buffer boundaries and returns an error in case of
too many bytes being returned by the underlying features.
[out] Yields the number of bytes actually returned.
Definition at line 393 of file rclstruct.h.

3.31.2.3 void RCIO RECEIVE PARAM::self

[in] Pointer to the C-interface in order to let this member function find its object. Should be left
dangling when calling the C++ wrapper.
Definition at line 398 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.32 RCIO TRANSCEIVE PARAM Struct Reference 90

3.32 RCIO TRANSCEIVE PARAM Struct Reference


#include <rclstruct.h>

3.32.1 Detailed Description

Parameter structure for Transceive functionality. The members of this structure reflect a simple
transparent I/O channel through lower layers and finally the chip. The Transceive function (which
takes this structure as its parameter) always waits for I/O completion (all bytes received or error
encountered (e.g. timeout). No overlapped Transceive operation is possible. The send- and receive-
buffers may overlap or even be the same, no double-buffering is required.
Definition at line 344 of file rclstruct.h.

Data Fields
unsigned char tx buffer
unsigned short tx buffer size
unsigned char rx buffer
unsigned short rx buffer size
void self

3.32.2 Field Documentation

3.32.2.1 unsigned char RCIO TRANSCEIVE PARAM::tx buffer

[in] References data to transmit via the UART. The location referenced must contain an initialised
buffer holding the data to transmit. The maximum size of the buffer depends on the underlying
systems capabilities regarding how many bytes it can transmit in one frame.
Definition at line 346 of file rclstruct.h.

3.32.2.2 unsigned short RCIO TRANSCEIVE PARAM::tx buffer size

[in] Number of bytes to transmit.


Definition at line 351 of file rclstruct.h.

3.32.2.3 unsigned char RCIO TRANSCEIVE PARAM::rx buffer

[in] Already allocated memory space sufficiently large to receive incoming data.
[out] Data copied to the provided buffer.
Definition at line 352 of file rclstruct.h.

3.32.2.4 unsigned short RCIO TRANSCEIVE PARAM::rx buffer size

[in] Maximum return buffer size in bytes. This member informs the function about the size of the
buffer for incoming data. The function checkes the buffer boundaries and returns an error in case of
too many bytes being returned by the underlying features.

RC522 Basic Function Library Documentation


3.32 RCIO TRANSCEIVE PARAM Struct Reference 91

[out] Yields the number of bytes actually returned.


Definition at line 355 of file rclstruct.h.

3.32.2.5 void RCIO TRANSCEIVE PARAM::self

[in] Pointer to the C-interface in order to let this member function find its object. Should be left
dangling when calling the C++ wrapper.
Definition at line 360 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.33 RCIO TRANSMIT PARAM Struct Reference 92

3.33 RCIO TRANSMIT PARAM Struct Reference


#include <rclstruct.h>

3.33.1 Detailed Description

Parameter structure for Transmit functionality. This structure reflects a transparent Transmit chan-
nel. The Transmit function returns after all bytes have been sent.
Definition at line 369 of file rclstruct.h.

Data Fields
unsigned char tx buffer
unsigned short tx buffer size
void self

3.33.2 Field Documentation

3.33.2.1 unsigned char RCIO TRANSMIT PARAM::tx buffer

[in] References data to transmit via the UART. The location referenced must contain an initialised
buffer holding the data to transmit. The maximum size of the buffer depends on the underlying
systems capabilities regarding how many bytes it can transmit in one frame.
Definition at line 371 of file rclstruct.h.

3.33.2.2 unsigned short RCIO TRANSMIT PARAM::tx buffer size

[in] Number of bytes to transmit.


Definition at line 376 of file rclstruct.h.

3.33.2.3 void RCIO TRANSMIT PARAM::self

[in] Pointer to the C-interface in order to let this member function find its object. Should be left
dangling when calling the C++ wrapper.
Definition at line 377 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.34 RCL IDMAN PARAM Struct Reference 93

3.34 RCL IDMAN PARAM Struct Reference


#include <rclstruct.h>

3.34.1 Detailed Description

Parameter structure for all ID manager functions:


Definition at line 978 of file rclstruct.h.

Data Fields
unsigned char ID
void instance
void self

3.34.2 Field Documentation

3.34.2.1 unsigned char RCL IDMAN PARAM::ID

[in/out] ID, ranging from 0..14.


Definition at line 980 of file rclstruct.h.

3.34.2.2 void RCL IDMAN PARAM::instance

[in/out] Adress/location of the instance (object) of ISO14443.4 to be assigned.


Definition at line 981 of file rclstruct.h.

3.34.2.3 void RCL IDMAN PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.
Definition at line 983 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.35 RCOPCTL ATTRIB PARAM Struct Reference 94

3.35 RCOPCTL ATTRIB PARAM Struct Reference


#include <rclstruct.h>

3.35.1 Detailed Description

Parameter structure for Attrib functionality.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 279 of file rclstruct.h.

Data Fields
unsigned char group ordinal
unsigned char attrtype ordinal
unsigned char param a
unsigned char param b
unsigned char buffer
void self

3.35.2 Field Documentation

3.35.2.1 unsigned char RCOPCTL ATTRIB PARAM::group ordinal

[in/out] Ordinal of the command group.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 281 of file rclstruct.h.

3.35.2.2 unsigned char RCOPCTL ATTRIB PARAM::attrtype ordinal

[in/out] Ordinal of the attribute within a group.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 282 of file rclstruct.h.

3.35.2.3 unsigned char RCOPCTL ATTRIB PARAM::param a

[in/out] Parameter A of the attribute.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 283 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.35 RCOPCTL ATTRIB PARAM Struct Reference 95

3.35.2.4 unsigned char RCOPCTL ATTRIB PARAM::param b

[in/out] Parameter B of the attribute.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 284 of file rclstruct.h.

3.35.2.5 unsigned char RCOPCTL ATTRIB PARAM::buffer

[in/out] Pointer to data buffer.


Definition at line 285 of file rclstruct.h.

3.35.2.6 void RCOPCTL ATTRIB PARAM::self

[in] Pointer to the C-interface in order to let this member function find its object. Should be left
dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 286 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.36 RCREGCTL MODIFY PARAM Struct Reference 96

3.36 RCREGCTL MODIFY PARAM Struct Reference


#include <rclstruct.h>

3.36.1 Detailed Description

Parameter structure for ModifyRegister functionality. The function performs a Read-Modify-Write


operation.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 151 of file rclstruct.h.

Data Fields
unsigned char address
unsigned char mask
unsigned char set
void self

3.36.2 Field Documentation

3.36.2.1 unsigned char RCREGCTL MODIFY PARAM::address

[in] References a register location within the RF chip. This member is not modified by the func-
tion.
Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 153 of file rclstruct.h.

3.36.2.2 unsigned char RCREGCTL MODIFY PARAM::mask

[in] A mask, specifying which register bits to modify. While bits set to one in the mask are touched
in the register, those set to zero remain unchanged.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 155 of file rclstruct.h.

3.36.2.3 unsigned char RCREGCTL MODIFY PARAM::set

[in] Type of operation - Set = 1, Clear = 0. The bits set to one in the mask are modified in the
register, according to the value of this member.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 158 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.36 RCREGCTL MODIFY PARAM Struct Reference 97

3.36.2.4 void RCREGCTL MODIFY PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 161 of file rclstruct.h.

RC522 Basic Function Library Documentation


3.37 RCREGCTL SETREG PARAM Struct Reference 98

3.37 RCREGCTL SETREG PARAM Struct Reference


#include <rclstruct.h>

3.37.1 Detailed Description

Parameter structure for SetRegister functionality.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 136 of file rclstruct.h.

Data Fields
unsigned char address
unsigned char reg data
void self

3.37.2 Field Documentation

3.37.2.1 unsigned char RCREGCTL SETREG PARAM::address

[in] References a register location within the RF chip. This member is not modified by the func-
tion.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 138 of file rclstruct.h.

3.37.2.2 unsigned char RCREGCTL SETREG PARAM::reg data

[in/out] Data to write to (or read from - see RCREGCTL GETREG PARAM) the specified regis-
ter.

Examples:
Iso14443 4 Reader.cpp, Iso14443 4 ReaderC.c, MifareReader.cpp, and MifareReaderC.c.

Definition at line 140 of file rclstruct.h.

3.37.2.3 void RCREGCTL SETREG PARAM::self

[in] Pointer to the C-interface of this component in order to let this member function find its object.
Should be left dangling when calling the C++ wrapper.

Examples:
Iso14443 4 ReaderC.c, and MifareReaderC.c.

Definition at line 142 of file rclstruct.h.

RC522 Basic Function Library Documentation


Chapter 4

RC522 Basic Function Library


Example Documentation

4.1 Iso14443 4 Reader.cpp


/* /////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Philips Semiconductors
//
// (C)PHILIPS Electronics N.V.2004
// All rights are reserved. Reproduction in whole or in part is
// prohibited without the written consent of the copyright owner.
// Philips reserves the right to make changes without notice at any time.
// Philips makes no warranty, expressed, implied or statutory, including but
// not limited to any implied warranty of merchantability or fitness for any
// particular purpose, or that the use will not infringe any third party patent,
// copyright or trademark. Philips must not be liable for any loss or damage
// arising from its use.

#define MAX_BUFFER_SIZE 64

#include <stdio.h> /* For debugging purposes (printf) */

/* Common headers */
#include <joinerreg.h>
#include <rclstruct.h>

/* Needed for any Operating Mode */


#include <incbal.h>
#include <incrcregctl.h>
#include <incrcopctl.h>
#include <rcopctl_ordinals.h>
#include <incrcio.h>

/* Needed for ISO14443-4 */


#include <inciso14443_3.h>
#include <inciso14443_4A_activation.h>
#include <inciso14443_4.h>

/*
* This example shows how to act as ISO14443-4 reader
*/
int ActivateIso14443_4_Reader(int comHandle)
{
/* BAL either for Windows xor for Linux */
#ifdef WIN32
4.1 Iso14443 4 Reader.cpp 100

Bal<C_JOINER_RS_232_PC_BAL_PARAMS> bal;
#else
Bal<C_JOINER_RS_232_LINUX_BAL_PARAMS> bal;
#endif
RcRegCtl<C_JOINER_RS_232_PC_RC_REG_CTL_PARAMS> rc_reg_ctl;
RcIo<C_JOINER_RC_IO_PARAMETERS> rcio;
RcOpCtl<C_JOINER_RC_OP_CTL_PARAMETERS> rc_op_ctl;
Iso14443_3<C_JOINER_ISO_14443_3_PARAMETERS> iso14443_3;
Iso14443_4A_Activation iso14443_4A;
Iso14443_4 iso14443_4;

/* Register control parameters */


RCREGCTL_MODIFY_PARAM mrp;
RCREGCTL_SETREG_PARAM srp;
RCREGCTL_GETREG_PARAM grp;

/* Operation control parameters */


RCOPCTL_ATTRIB_PARAM opp;

/* ISO14443-3A parameters */
ISO14443_3_REQUEST_A_PARAM req_p;
ISO14443_3_ANTICOLLISIONSELECT_PARAM sel_p;

/* ISO14443-4A activation parameters */


ISO14443_4_RATS_PARAM rat_p;
ISO14443_4_PPS_PARAM pps_p;

/* Transparent protocol operations */


ISO14443_4_EXCHANGE_PARAM exc_p;
ISO14443_4_PRESENCE_CHECK_PARAM prs_p;
ISO14443_4_DESELECT_PARAM dsl_p;

/*
* Generic variables
*/
RCLSTATUS status = RCLSTATUS_SUCCESS;
/* Buffer for data transfer (send/receive) */
unsigned char buffer[MAX_BUFFER_SIZE];
/* Buffer serial number */
unsigned char serial[12];
/* Counter variable */
unsigned char i;

/* Mifare EvalOS command to read data from Mifare EEProm area using PasswordRead function */
unsigned char readMFblock [14] = { 0xB8, 0x80, 0x04, 0x00, 0x08, 0x0b, 0x54, 0x57, 0x07, 0x45, 0xfe,
0x3a, 0xe7, 0x10 };
unsigned char rcvBuf[MAX_BUFFER_SIZE];
unsigned char ats[MAX_BUFFER_SIZE];

/* Build up stack for serial communication.


* Start with the lowest layer, so that the upper ones can refer to this already.
*/
#ifdef WIN32
bal.Initialise(JoinerBalRs232PcInitialise);
#else
bal.Initialise(JoinerBalRs232LinuxInitialise);
#endif
/* Initialise Register Control Layer component */
rc_reg_ctl.Initialise(JoinerRcRegCtlRs232PcInitialise, &bal);
/* Initialise RcIo component */
rcio.Initialise(JoinerRcIoInitialise, &rc_reg_ctl, 1);
/* Initialise Operation Control component */
rc_op_ctl.Initialise(JoinerRcOpCtlInitialise, &rc_reg_ctl);
/* Initialise ISO14443-3 component */
iso14443_3.Initialise(JoinerIso14443_3Initialise, &rc_reg_ctl, 1);

RC522 Basic Function Library Documentation


4.1 Iso14443 4 Reader.cpp 101

/* Initialise ISO14443-4A Activation component */


iso14443_4A.Initialise(buffer, 64, &rcio);
/* Initialise ISO14443-4 transport protocol */
iso14443_4.Initialise(&rcio);

/* Let the BAL know about the used serial Port which is initialised outside of this function */
#ifdef WIN32
((C_JOINER_RS_232_PC_BAL_PARAMS*)bal.m_Interface.mp_Members)->com_handle = (void*) comHandle;
#else
((C_JOINER_RS_232_LINUX_BAL_PARAMS*)bal.m_Interface.mp_Members)->com_handle = comHandle;
#endif

/*
* Configure RC522 to act as a Mifare Reader. All register which are set in other modes
* are configured to the right values.
* Remark: Operation control function do not perform a softreset and does not know anything
* about the antanne configuration, so these things have to be handled here!
*/
opp.group_ordinal = RCO_GROUP_MODE;
opp.attrtype_ordinal = RCO_ATTR_MFRD_A;
opp.param_a = RCO_VAL_RF106K;
opp.param_b = RCO_VAL_RF106K;
status = rc_op_ctl.SetAttrib(&opp);
/* Check status and display error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR performing Mifare Reader configuration! Status = %04x \n", status);

/*
* Set the timer to auto mode, 5ms using operation control commands before HF is
* switched on to guarantee Iso14443-3 compliance of the polling procedure
*/
opp.group_ordinal = RCO_GROUP_TIMER; /* Set operation control group parameter to Timer */
opp.attrtype_ordinal = RCO_ATTR_TIMER_AUTO; /* Set function for Timer automatic mode */
opp.param_a = RCO_VAL_TIMER_AUTO_ON; /* Use parameter a to switch it on */
status = rc_op_ctl.SetAttrib(&opp);
/* Check status and display error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer auto mode. Status = %04x \n", status);

/*
* Set prescaler steps to 100us
*/
opp.group_ordinal = RCO_GROUP_TIMER;
opp.attrtype_ordinal = RCO_ATTR_TIMER_PRESCALER;
/* Calculation of the values: 100us = 6.78MHz/678 = 6.78MHz/0x2A6 */
opp.param_a = 0xA6; /* Low value */
opp.param_b = 0x02; /* High value */
status = rc_op_ctl.SetAttrib(&opp);
/* Check status and display error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer Prescaler. Status = %04x \n", status);

/* Set the reload value */


opp.group_ordinal = RCO_GROUP_TIMER; // set operation control group parameter to Timer
opp.attrtype_ordinal = RCO_ATTR_TIMER_RELOAD; // set to 50 for 5 ms
opp.param_a = 50; // Low value
opp.param_b = 0; // High value (max 0xFF)
status = rc_op_ctl.SetAttrib(&opp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer Reload. Status = %04x \n", status);

/* Activate the field */


mrp.address = JREG_TXCONTROL;
mrp.mask = JBIT_TX2RFEN | JBIT_TX1RFEN;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);

RC522 Basic Function Library Documentation


4.1 Iso14443 4 Reader.cpp 102

if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/* start timer manually to check the initial waiting time */


mrp.address = JREG_CONTROL;
mrp.mask = JBIT_TSTARTNOW;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/*
* After switching on the timer wait until the timer interrupt occures, so that
* the field is on and the 5ms delay have been passed.
*/
grp.address = JREG_COMMIRQ;
do {
status = rc_reg_ctl.GetRegister(&grp);
}
while(!(grp.reg_data & JBIT_TIMERI) && status == RCLSTATUS_SUCCESS);
/* Check status and diplay error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! GetRegister: Address=%02X, Data=02X, Status = %04x \n",
grp.address, grp.reg_data, status);

/* Clear the status flag afterwards (use again register commands) */


srp.address = JREG_COMMIRQ;
srp.reg_data = JBIT_TIMERI;
status = rc_reg_ctl.SetRegister(&srp);
/* Check status and display error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! SetRegister: Address=%02X, Data=02X, Status = %04x \n",
srp.address, srp.reg_data, status);

/*
* Reset timer 1 ms using operation control commands (AutoMode and Prescaler are the same)
* set reload value
*/
opp.group_ordinal = RCO_GROUP_TIMER; /* set operation control group parameter to Timer */
opp.attrtype_ordinal = RCO_ATTR_TIMER_RELOAD; /* set to 10 for 1 ms */
opp.param_a = 10; /* Low value */
opp.param_b = 0; /* High value (max 0xFF) */
status = rc_op_ctl.SetAttrib(&opp);
// check status and diplay error if something went wrong
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer Reload. Status = %04x \n", status);

/* Activate receiver for communication


The RcvOff bit and the PowerDown bit are cleared, the command is not changed. */
srp.address = JREG_COMMAND;
srp.reg_data = JCMD_NOCMDCHANGE;
status = rc_reg_ctl.SetRegister(&srp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! SetRegister: Address=%02X, Data=02X, Status = %04x \n",
srp.address, srp.reg_data, status);

/*
* Do activation according to ISO14443A Part3
* Prepare the Request command
*/
buffer[0] = 0;
buffer[1] = 0;
req_p.req_code = ISO14443_3_REQIDL; /* Set Request command code (or Wakeup: ISO14443_3_REQALL) */
req_p.atq = buffer; /* Let Request use the defined return buffer */

RC522 Basic Function Library Documentation


4.1 Iso14443 4 Reader.cpp 103

status = iso14443_3.RequestA(&req_p); /* Start Request command */


/* Check return code: This code could be either
* RCLSTATUS_SUCCESSS (only one card in field) or
* RCLSTATUS_COLLISION_ERROR (if more than one card is in the field).
*/
if(status == RCLSTATUS_SUCCESS || status == RCLSTATUS_COLLISION_ERROR)
{
/* There was at least one response */
if(status == RCLSTATUS_COLLISION_ERROR)
printf("Collission occured during Request! Multiple Cards detected!\n");
printf("ATQA = %02x %02x \n", req_p.atq[0],req_p.atq[1]);
} else
{
/* No response at all */
printf("*** ERROR! RequestA: RequestCode=%02X, ATQA=%02X %02X, Status = %04x \n",
req_p.req_code, req_p.atq[0],req_p.atq[1], status);
}

/* Prepare data for combined anticollision/select command to get one complete ID */


for(i=0;i<12;i++)
serial[i] = 0x00; /* Clear all unused bytes of the I/O buffer */

sel_p.sel_lv1_code = SELECT_CASCADE_LEVEL_1; /* Set first cascade level for start */


sel_p.uid = serial; /* Put serial buffer for ID */
sel_p.uid_length = 0; /* No bits are known from ID, so set to 0 */
/* Start Anticollision/Select command */
status = iso14443_3.AnticollisionSelect(&sel_p);
/* Check return code: If the command was ok, is always returns RCLSTATUS_SUCCESSS.
* If nothing was received, parameter uid_length is 0. */
if(status == RCLSTATUS_SUCCESS)
{
/* Display UID and SAK if anything was ok */
printf("Anticollision/Select: \t UID: ");
for(i=0;i<(sel_p.uid_length/8);i++)
printf("%02X", sel_p.uid[i]);
printf("\tSAK: %02X \n",sel_p.sak);
} else
{
printf("*** ERROR! Anticollision/Select: Command=%02X, Status = %04x \n",
sel_p.sel_lv1_code, status);
}

/* Example how to use the Iso14443 Part4 (T=CL) specific command set of the BFL */

/* Prepare for RATS command */


rat_p.cid = 0;
rat_p.fsi = 3;
rat_p.ats = ats;
/* Issue the RATS command */
status = iso14443_4A.Rats(&rat_p);
if(status == RCLSTATUS_SUCCESS)
{
/* Display all received parameters if anything was ok */
printf("RATS: \t ATS Length: %04X, ", rat_p.ats_len);
/* Display TA(1) */
if(rat_p.ta1)
printf("TA(1)=%02X, ", *rat_p.ta1);
else
printf("no TA(1), ");
/* display TB(1) */
if(rat_p.tb1)
printf("Tb(1)=%02X, ", *rat_p.tb1);
else
printf("no TB(1), ");
/* display TC(1) if applicable */
if(rat_p.tc1)
printf("TC(1)=%02X, ", *rat_p.tc1);

RC522 Basic Function Library Documentation


4.1 Iso14443 4 Reader.cpp 104

else
printf("no TC(1), ");
if(rat_p.app_inf_len)
{
printf("%02X \nHistorical characters: ", rat_p.app_inf_len);
for(i=0;i<(rat_p.app_inf_len);i++)
printf("%02X ", rat_p.app_inf[i]);
} else
{
printf("\nNo Historcal characters. ");
}
printf("\n");
} else
{
printf("*** ERROR! ISO14443 Part4 -> RATS: Status = %04x \n", status);
}

/* Check speed capability of the remote card (stored in TA(1) byte) */


if ( !status)
{
if ((*rat_p.ta1 & 0x80) == 0)
{
printf("Asymmetric datarates supported! \n Possible data rates (besides 106kBit/s) for PCD -> PICC are: ");
if(*rat_p.ta1 & 0x01)
printf("212kbps, ");
if(*rat_p.ta1 & 0x02)
printf("424kbps, ");
if(*rat_p.ta1 & 0x04)
printf("848kbps");
printf("\n Possible data rates (besides 106kBit/s) for PICC -> PCD are: ");
if(*rat_p.ta1 & 0x10)
printf("212kbps, ");
if(*rat_p.ta1 & 0x20)
printf("424kbps, ");
if(*rat_p.ta1 & 0x40)
printf("848kbps");
} else
{
printf("Only symmetrical datarates supported! \n Possible data rates (besides 106kBit/s) are: ");
if(*rat_p.ta1 & 0x01 && *rat_p.ta1 & 0x10)
printf("212kbps, ");
if(*rat_p.ta1 & 0x02 && *rat_p.ta1 & 0x20)
printf("424kbps, ");
if(*rat_p.ta1 & 0x04 && *rat_p.ta1 & 0x40)
printf("848kbps");
}
printf("\n");
}

/* Change data rate with PPS directly afterwards (not allowed later on) */
pps_p.cid = 0x00; /* no card identifier used */
pps_p.dri = RCO_VAL_RF106K; /* data rate PCD -> PICC */
pps_p.dsi = RCO_VAL_RF106K; /* data rate PICC -> PCD */

status = iso14443_4A.Pps(&pps_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("PPS handled without errors, reconfiguration is possible.\n");
/* Call operation control function with new data rate */
opp.group_ordinal = RCO_GROUP_MODE;
opp.attrtype_ordinal = RCO_ATTR_MFRD_A;
opp.param_a = RCO_VAL_RF106K;
opp.param_b = RCO_VAL_RF106K;
/* Start set attribute command */
status = rc_op_ctl.SetAttrib(&opp);

RC522 Basic Function Library Documentation


4.1 Iso14443 4 Reader.cpp 105

/* Check status and diplay error if something went wrong */


if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR performing Mifare Reader configuration for higher data rates! Status = %04x \n", status);
} else
{
printf("*** ERROR! ISO14443 Part4 -> PPS: Status = %04x \n", status);
}

/* Hand over parameters generated in activatin part to transparent protocol part of ISO 14443-4
Comment: this is only necessary in CPP implementation because there the struct is generated internally. */
iso14443_4.SetProtocolParameters(iso14443_4A.ProtocolParameters(), 1);

exc_p.nad_receive = 0;
exc_p.nad_send = 0;
exc_p.snd_buf = readMFblock;
exc_p.snd_buf_len = 14;
exc_p.rec_buf = rcvBuf;
exc_p.rec_buf_len = 64;
status = iso14443_4.Exchange(&exc_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("Exchange handled without errors, Mifare Read OK. \n Data: ");
for (i=0; i<exc_p.rec_buf_len; i++)
printf("%02X ", exc_p.rec_buf[i]);
printf("\n");
} else
{
printf("*** ERROR! ISO14443 Part4 -> Exchange: MifareRead: Status = %04x \n", status);
}

/* check if the card is still in the field */


status = iso14443_4.PresenceCheck(&prs_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("Presence check OK, Card available. \n");
} else
{
printf("Presence check FAIL, No card available any more! \n");
}

/* Deselect device at the end of communication */


status = iso14443_4.Deselect(&dsl_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("Deselect OK. \n");
} else
{
printf("Deselect FAIL, No card available any more! Try error handling. \n");
}

/*
* To start a communication with a new device all internal status variables have to be reset.
*/
iso14443_4.ResetProtocol(); /* This function has no return value. All variables are reset! */

return status; /* Last relevant status */


}

RC522 Basic Function Library Documentation


4.2 Iso14443 4 ReaderC.c 106

4.2 Iso14443 4 ReaderC.c


/* /////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Philips Semiconductors
//
// (C)PHILIPS Electronics N.V.2004
// All rights are reserved. Reproduction in whole or in part is
// prohibited without the written consent of the copyright owner.
// Philips reserves the right to make changes without notice at any time.
// Philips makes no warranty, expressed, implied or statutory, including but
// not limited to any implied warranty of merchantability or fitness for any
// particular purpose, or that the use will not infringe any third party patent,
// copyright or trademark. Philips must not be liable for any loss or damage
// arising from its use.

#define MAX_BUFFER_SIZE 64

/* Include all necessary component headers for Mifare Reader operation and additional definitions.
(BAL, RegisterControl, Iso14443Part3, OperationControl, RcIo, Mifare) */

/* For debugging purposes (printf) */


#include <stdio.h>

/* Common headers */
#include <joinerreg.h>
#include <rclstruct.h>

/* Needed for any Operating Mode */


#include <bal.h>
#include <rcregctl.h>
#include <rcio.h>
#include <rcopctl_ordinals.h>
#include <rcopctl.h>

/* Needed for this Operating Mode */


#include <iso14443_3.h>
#include <iso14443_4.h>
#include <iso14443_4A_activation.h>

/*
* This example shows how to act as ISO14443-4 reader
*/
int ActivateIso14443_4_Reader(int comHandle)
{
/* Declaration of variables, buffer, ... */
RCLSTATUS status = RCLSTATUS_SUCCESS;
/* Buffer for data transfer (send/receive) */
unsigned char buffer[64];
unsigned char rcvBuf[64];
/* Buffer serial number */
unsigned char serial[12];
/* Counter variable */
unsigned char i;
/* Buffer for ATS */
unsigned char ats[64];

unsigned char readMFblock [14] = { 0xB8, 0x80, 0x04, 0x00, 0x08, 0x0b, 0x54, 0x57, 0x07, 0x45,
0xfe, 0x3a, 0xe7, 0x10 };

/* BFL Stack */
C_BAL bal;
C_RC_REG_CTL rc_reg_ctl;
C_RC_IO rcio;
C_RC_OP_CTL rc_op_ctl;
C_ISO_14443_3A iso14443_3;
C_ISO14443_4 iso14443_4;

RC522 Basic Function Library Documentation


4.2 Iso14443 4 ReaderC.c 107

C_ISO14443_4A_ACTIVATION iso14443_4A;

/* Operation control parameters (needed for the BFL) */


RCOPCTL_ATTRIB_PARAM opp;
RCREGCTL_SETREG_PARAM srp;
RCREGCTL_GETREG_PARAM grp;
RCREGCTL_MODIFY_PARAM mrp;

#ifdef WIN32
C_JOINER_RS_232_PC_BAL_PARAMS bal_params;
#else
C_JOINER_RS_232_LINUX_BAL_PARAMS bal_params;
#endif
C_JOINER_RS_232_PC_RC_REG_CTL_PARAMS rc_reg_ctl_params;
C_JOINER_RC_IO_PARAMETERS rc_io_params;
C_JOINER_RC_OP_CTL_PARAMETERS rc_op_ctl_params;
C_JOINER_ISO_14443_3_PARAMETERS iso_14443_3_params;

ISO14443_3_REQUEST_A_PARAM req_p;
ISO14443_3_ANTICOLLISIONSELECT_PARAM sel_p;
/* T=CL activation parameters */
ISO14443_4_PROTOCOL_PARAM pro_p;
ISO14443_4_RATS_PARAM rat_p;
ISO14443_4_PPS_PARAM pps_p;
/* Transparent protocol operations */
ISO14443_4_EXCHANGE_PARAM exc_p;
ISO14443_4_COMMUNICATION_PARAMETERS com_p;
ISO14443_4_PRESENCE_CHECK_PARAM prs_p;
ISO14443_4_DESELECT_PARAM dsl_p;

/* Build up stack for serial communication.


Start with the lowest layer, so that the upper ones may refer to this already. */

/* Initialise Bus Abstraction Layer component (RS232) */


#ifdef WIN32
/* Either for Windows... */
JoinerBalRs232PcInitialise(&bal, &bal_params);
#else
/* ... or for Linux */
JoinerBalRs232LinuxInitialise(&bal, &bal_params);
#endif
/* Initialise Register Control Layer component */
JoinerRcRegCtlRs232PcInitialise(&rc_reg_ctl, &rc_reg_ctl_params, &bal);
/* initialise RcIo component */
JoinerRcIoInitialise(&rcio, &rc_io_params, &rc_reg_ctl, 1);
/* initialise Operation Control component */
JoinerRcOpCtlInitialise(&rc_op_ctl, &rc_op_ctl_params, &rc_reg_ctl);
/* initialise ISO14443-3 component */
JoinerIso14443_3Initialise(&iso14443_3, &iso_14443_3_params, &rc_reg_ctl, 1);
/* Initialise ISO14443-4A Activation */
Iso14443_4A_Activation_Initialise(&iso14443_4A, &pro_p, buffer, 64, &rcio);
/* Initialise ISO14443-4 */
Iso14443_4Initialise(&iso14443_4, &com_p, &rcio);

/* Let the BAL know about the used serial Port which is initialised outside of this function */
#ifdef WIN32
/* This is for Windows */
((C_JOINER_RS_232_PC_BAL_PARAMS*) (bal.mp_Members))->com_handle = (void*) comHandle;
#else
/* And this one for Linux */
((C_JOINER_RS_232_LINUX_BAL_PARAMS*) (bal.mp_Members))->com_handle = comHandle;
#endif

/* Initialisation of the self parameters */


/* Set self parameters only once in program flow */
srp.self = &rc_reg_ctl;
mrp.self = &rc_reg_ctl;

RC522 Basic Function Library Documentation


4.2 Iso14443 4 ReaderC.c 108

grp.self = &rc_reg_ctl;
opp.self = &rc_op_ctl;
req_p.self = &iso14443_3;
sel_p.self = &iso14443_3;
rat_p.self = &iso14443_4A;
pps_p.self = &iso14443_4A;
exc_p.self = &iso14443_4;
prs_p.self = &iso14443_4;
dsl_p.self = &iso14443_4;

/* Configure RC522 to act as a Mifare Reader. All register which are set in other modes
are configured to the right values.
Remark: operation control function do not perform a softreset and does not know anything
about the antanne configuration, so these things have to be handled here! */
opp.group_ordinal = RCO_GROUP_MODE;
opp.attrtype_ordinal = RCO_ATTR_MFRD_A;
opp.param_a = RCO_VAL_RF106K;
opp.param_b = RCO_VAL_RF106K;
/* Start set attribute command */
status = rc_op_ctl.SetAttrib(&opp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR performing Mifare Reader configuration! Status = %04x \n", status);

/* Set the timer to auto mode, 5ms using operation control commands before HF is switched on to
guarantee Iso14443-3 compliance of Polling procedure */
/* activate automatic start/stop of timer */
opp.group_ordinal = RCO_GROUP_TIMER; /* set operation control group parameter to Timer */
opp.attrtype_ordinal = RCO_ATTR_TIMER_AUTO; /* set function for Timer automatic mode */
opp.param_a = RCO_VAL_TIMER_AUTO_ON; /* use parameter a to switch it on */
/* Start set attribute command */
status = rc_op_ctl.SetAttrib(&opp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer auto mode. Status = %04x \n", status);

/* Set prescaler value to steps of 100s


(group parameter is set from above and not modified during operation) */
opp.attrtype_ordinal = RCO_ATTR_TIMER_PRESCALER; /* set to 677 -> 100s steps */
opp.param_a = 0xA6; /* Low value */
opp.param_b = 0x02; /* High value (max 0x0F) */
status = rc_op_ctl.SetAttrib(&opp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer Prescaler. Status = %04x \n", status);

/* set reload value


(group parameter is set from above and not modified during operation) */
opp.attrtype_ordinal = RCO_ATTR_TIMER_RELOAD; /* set to 50 for 5 ms */
opp.param_a = 50; /* Low value */
opp.param_b = 0; /* High value (max 0xFF) */
status = rc_op_ctl.SetAttrib(&opp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer Reload. Status = %04x \n", status);

/* Activate the field (automatically if there is no external field detected) */


mrp.address = JREG_TXCONTROL;
mrp.mask = JBIT_TX2RFEN | JBIT_TX1RFEN;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/* start timer manually to check the initial waiting time */


mrp.address = JREG_CONTROL;
mrp.mask = JBIT_TSTARTNOW;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);

RC522 Basic Function Library Documentation


4.2 Iso14443 4 ReaderC.c 109

if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/* After switching on the timer wait until the timer Interrupt occures, so that
the field is on and the 5ms delay have been passed. */
grp.address = JREG_COMMIRQ;
do
{
status = rc_reg_ctl.GetRegister(&grp);
}
while(!(grp.reg_data & JBIT_TIMERI) && status == RCLSTATUS_SUCCESS);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! GetRegister: Address=%02X, Data=02X, Status = %04x \n",
grp.address, grp.reg_data, status);

/* Clear the status flag afterwards */


srp.address = JREG_COMMIRQ;
srp.reg_data = JBIT_TIMERI;
status = rc_reg_ctl.SetRegister(&srp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! SetRegister: Address=%02X, Data=02X, Status = %04x \n",
srp.address, srp.reg_data, status);

/*
* Reset timer 1 ms using operation control commands (AutoMode and Prescaler are the same)
* set reload value */
opp.group_ordinal = RCO_GROUP_TIMER; /* set operation control group parameter to Timer */
opp.attrtype_ordinal = RCO_ATTR_TIMER_RELOAD; /* set to 10 for 1 ms */
opp.param_a = 10; /* Low value */
opp.param_b = 0; /* High value (max 0xFF) */
status = rc_op_ctl.SetAttrib(&opp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! OperationControl settings Timer Reload. Status = %04x \n", status);

/* Activate Receiver for Communication


* The RcvOff bit and the PowerDown bit are cleared, the command is not changed.
*/
srp.address = JREG_COMMAND;
srp.reg_data = JCMD_NOCMDCHANGE;
status = rc_reg_ctl.SetRegister(&srp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! SetRegister: Address=%02X, Data=02X, Status = %04x \n",
srp.address, srp.reg_data, status);

/* Do activation according to ISO14443A Part3 */


buffer[0] = 0;
buffer[1] = 0;
req_p.req_code = ISO14443_3_REQIDL; /* Set Request command code (or Wakeup: ISO14443_3_REQALL) */
req_p.atq = buffer; /* Let Request use the defined return buffer */
status = iso14443_3.RequestA(&req_p); /* Start Request command */
/* Check return code: This code could be either
* RCLSTATUS_SUCCESSS (only one card in field) or
* RCLSTATUS_COLLISION_ERROR (if more than one card is in the field).
*/
if(status == RCLSTATUS_SUCCESS || status == RCLSTATUS_COLLISION_ERROR)
{
if(status == RCLSTATUS_COLLISION_ERROR)
printf("Collission occured during Request! Multiple Cards detected!\n");
printf("ATQA = %02x %02x \n", req_p.atq[0],req_p.atq[1]);
} else
{
printf("*** ERROR! RequestA: RequestCode=%02X, ATQA=%02X %02X, Status = %04x \n",
req_p.req_code, req_p.atq[0],req_p.atq[1], status);
}

RC522 Basic Function Library Documentation


4.2 Iso14443 4 ReaderC.c 110

/* Prepare data for combined anticollision/select command to get one complete ID */


for(i=0;i<12;i++)
serial[i] = 0x00;

sel_p.sel_lv1_code = SELECT_CASCADE_LEVEL_1; /* set first cascade level for start */


sel_p.uid = serial; /* put serial buffer for ID */
sel_p.uid_length = 0; /* no bits are known from ID, so set to 0 */
status = iso14443_3.AnticollisionSelect(&sel_p);
/* check return code: If command was ok, shall alwas return RCLSTATUS_SUCCESSS.
* If nothing was received, parameter uid_length is 0. */
if(status == RCLSTATUS_SUCCESS)
{
/* display UID and SAK if everything was ok */
printf("Anticollision/Select: \t UID: ");
for(i=0;i<(sel_p.uid_length/8);i++)
printf("%02X", sel_p.uid[i]);
printf("\tSAK: %02X \n",sel_p.sak);
} else
{
printf("*** ERROR! Anticollision/Select: Command=%02X, Status = %04x \n",
sel_p.sel_lv1_code, status);
}

/* ---------------------------------------------------------------------------- */
/* Example how to use the Iso14443 Part4 (T=CL) specific command set of the BFL */

/* Configure all the necessay parameters */


rat_p.cid = 0;
rat_p.fsi = 3;
rat_p.ats = ats;
/* Start RATS command */
status = iso14443_4A.Rats(&rat_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("RATS: \t ATS Length: %04X, ", rat_p.ats_len);
/* display TA(1) */
if(rat_p.ta1)
printf("TA(1)=%02X, ", *rat_p.ta1);
else
printf("no TA(1), ");
/* display TB(1) */
if(rat_p.tb1)
printf("Tb(1)=%02X, ", *rat_p.tb1);
else
printf("no TB(1), ");
/* display TC(1) */
if(rat_p.tc1)
printf("TC(1)=%02X, ", *rat_p.tc1);
else
printf("no TC(1), ");
if(rat_p.app_inf_len)
{
printf("%02X \n Historical characters: ", rat_p.app_inf_len);
for(i=0;i<(rat_p.app_inf_len);i++)
printf("%02X ", rat_p.app_inf[i]);
} else
{
printf("\n No Historcal characters. ");
}
printf("\n");
} else /* ERROR */
{
printf("*** ERROR! ISO14443 Part4 -> RATS: Status = %04x \n", status);
}

RC522 Basic Function Library Documentation


4.2 Iso14443 4 ReaderC.c 111

/* check speed capability of Card (stored in TA(1) byte) */


if ( !status)
{
if((*rat_p.ta1 & 0x80) == 0)
{
printf("Asymmetric datarates supported! \n Possible data rates (besides 106kBit/s) for PCD -> PICC are: ");
if(*rat_p.ta1 & 0x01)
printf("212kbps, ");
if(*rat_p.ta1 & 0x02)
printf("424kbps, ");
if(*rat_p.ta1 & 0x04)
printf("848kbps");
printf("\n Possible data rates (besides 106kBit/s) for PICC -> PCD are: ");
if(*rat_p.ta1 & 0x10)
printf("212kbps, ");
if(*rat_p.ta1 & 0x20)
printf("424kbps, ");
if(*rat_p.ta1 & 0x40)
printf("848kbps");
} else
{
printf("Only symmetrical datarates supported! \n Possible data rates (besides 106kBit/s) are: ");
if(*rat_p.ta1 & 0x01 && *rat_p.ta1 & 0x10)
printf("212kbps, ");
if(*rat_p.ta1 & 0x02 && *rat_p.ta1 & 0x20)
printf("424kbps, ");
if(*rat_p.ta1 & 0x04 && *rat_p.ta1 & 0x40)
printf("848kbps");
}
printf("\n");
}

/* change data rate with PPS directly afterwards (not allowed later on) */
pps_p.cid = 0x00; /* no card identifier used */
pps_p.dri = RCO_VAL_RF106K; /* data rate PCD -> PICC */
pps_p.dsi = RCO_VAL_RF106K; /* data rate PCD -> PICC */

status = iso14443_4A.Pps(&pps_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("PPS handled without errors, reconfiguration is possible.\n");
/* call Operation control function with new data rate */
opp.group_ordinal = RCO_GROUP_MODE;
opp.attrtype_ordinal = RCO_ATTR_MFRD_A;
opp.param_a = RCO_VAL_RF106K;
opp.param_b = RCO_VAL_RF106K;
status = rc_op_ctl.SetAttrib(&opp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR performing Mifare Reader configuration for higher data rates! Status = %04x \n", status);

} else
{
printf("*** ERROR! ISO14443 Part4 -> PPS: Status = %04x \n", status);
}

/* Hand over parameters to transparent protocol */


iso14443_4.SetProtocolParams(&iso14443_4, &pro_p, 1);

exc_p.nad_receive = 0;
exc_p.nad_send = 0;
exc_p.snd_buf = readMFblock;
exc_p.snd_buf_len = 14;
exc_p.rec_buf = rcvBuf;

RC522 Basic Function Library Documentation


4.2 Iso14443 4 ReaderC.c 112

exc_p.rec_buf_len = 64;
status = iso14443_4.Exchange(&exc_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("Exchange handled without errors, Mifare Read OK. \nData: ");
for (i=0; i<exc_p.rec_buf_len; i++)
printf("%02X ", exc_p.rec_buf[i]);
printf("\n");
} else
{
printf("*** ERROR! ISO14443 Part4 -> Exchange: MifareRead: Status = %04x \n", status);
}

/* Check if card is still in field */


status = iso14443_4.PresenceCheck(&prs_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("Presence check OK, Card available. \n");
} else
{
printf("Presence check FAIL, No card available any more! \n");
}

/* Deselect device at the end of communication */


status = iso14443_4.Deselect(&dsl_p);
if(status == RCLSTATUS_SUCCESS)
{
printf("Deselect OK. \n");
} else
{
printf("Deselect FAIL, No card available any more! Try error handling. \n");
}

/* To start a communication with a new device all internal status variables have to be reset. */
iso14443_4.ResetProtocol(&iso14443_4); /* This function has no return value. All variables are reset! */

return status;
}

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 113

4.3 MifareReader.cpp
The following code contains an example for implementing the Mifare Reader functionality using the
BFL.
The MifareParams function show the necessary settings of the RC522 hardware to act like a Mifare
Reader.
In the main procedure (ActivateMifareReader) first all necessary components of the BFL are declared.
After this, all relevant data structs are declared. Doing this you may start to initialise the BFL stack.
In this example the serial interface of a PC is used. The initialisation of this part is not shown in this
example. The BAL needs only to know about the interface, so the handle is set to the com handle of
the BAL.
Then everything is ready to initialise the RC522. This is done by using dedicated functions of the
operation control component.
Then a timeout value has to be defined and the first command of the activation can be started.
After successful activation there are exapmles shown how to authenticate a Mifare Card and how to
read or write data from the authenticated sector.
At the end an HaltA command is processed, to set the Card into halt state.

/* /////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Philips Semiconductors
//
// (C)PHILIPS Electronics N.V.2004
// All rights are reserved. Reproduction in whole or in part is
// prohibited without the written consent of the copyright owner.
// Philips reserves the right to make changes without notice at any time.
// Philips makes no warranty, expressed, implied or statutory, including but
// not limited to any implied warranty of merchantability or fitness for any
// particular purpose, or that the use will not infringe any third party patent,
// copyright or trademark. Philips must not be liable for any loss or damage
// arising from its use.

/* Include all necessary component headers for Mifare Reader operation and additional definitions.
(BAL, RegisterControl, Iso14443Part3, OperationControl, RcIo, Mifare) */

#include <stdio.h> /* For debugging purposes (printf) */

/* Common headers */
#include <joinerreg.h>
#include <rclstruct.h>

/* Needed for any Operating Mode */


#include <incbal.h>
#include <incrcregctl.h>
#include <incrcopctl.h>
#include <rcopctl_ordinals.h>
#include <incrcio.h>

#include "ExampleUtils.h"

/* Needed for ISO14443-3A protocol */


#include <inciso14443_3.h>

/* Needed for Mifare commands */


#include <incmifare.h>

/*
* This example shows how to act as Mifare reader
*/

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 114

int ActivateMifareReader(int comHandle)


{
/* BAL either for Windows xor for Linux */
#ifdef WIN32
Bal<C_JOINER_RS_232_PC_BAL_PARAMS> bal;
#else
Bal<C_JOINER_RS_232_LINUX_BAL_PARAMS> bal;
#endif
RcRegCtl<C_JOINER_RS_232_PC_RC_REG_CTL_PARAMS> rc_reg_ctl;
RcIo<C_JOINER_RC_IO_PARAMETERS> rcio;
RcOpCtl<C_JOINER_RC_OP_CTL_PARAMETERS> rc_op_ctl;
Iso14443_3<C_JOINER_ISO_14443_3_PARAMETERS> iso14443_3;
MifareReader mfrd;

/* Register control parameters */


RCREGCTL_SETREG_PARAM srp;
RCREGCTL_GETREG_PARAM grp;
RCREGCTL_MODIFY_PARAM mrp;

/* Operation control parameters */


RCOPCTL_ATTRIB_PARAM opp;

/* ISO14443-3A parameters */
ISO14443_3_REQUEST_A_PARAM req_p;
ISO14443_3_ANTICOLLISIONSELECT_PARAM sel_p;
ISO14443_3_HALT_A_PARAM hlt_p;

/* Mifare parameters */
MIFARE_CMD_PARAM mfr_p;

/*
* Generic variables
*/
RCLSTATUS status = RCLSTATUS_SUCCESS;
/* Buffer for data transfer (send/receive) */
unsigned char buffer[64];
/* Buffer serial number */
unsigned char serial[12];
/* Counter variable */
unsigned char i, index;

/*
* Build up stack for serial communication.
* Start with the lowest layer, so that the upper ones may refer to this already.
*/
#ifdef WIN32
bal.Initialise(JoinerBalRs232PcInitialise);
#else
bal.Initialise(JoinerBalRs232LinuxInitialise);
#endif
/* Initialise Register Control Layer component */
rc_reg_ctl.Initialise(JoinerRcRegCtlRs232PcInitialise, &bal);
/* Initialise RcIo component */
rcio.Initialise(JoinerRcIoInitialise, &rc_reg_ctl, 1);
/* Initialise Operation Control component */
rc_op_ctl.Initialise(JoinerRcOpCtlInitialise, &rc_reg_ctl);
/* initialise ISO14443-3 component */
iso14443_3.Initialise(JoinerIso14443_3Initialise, &rc_reg_ctl, ISO14443_3_INITIATOR);
/* Initialise Mifare component */
mfrd.Initialise(&rcio, buffer+20);

/* Let the BAL know about the used serial Port which is initialised outside of this function */
#ifdef WIN32
((C_JOINER_RS_232_PC_BAL_PARAMS*) (bal.m_Interface.mp_Members))->com_handle = (void*) comHandle;
#else
((C_JOINER_RS_232_LINUX_BAL_PARAMS*) (bal.m_Interface.mp_Members))->com_handle = comHandle;

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 115

#endif

/* Configure RC522 to act as a Mifare Reader. All register which are set in other modes
* are configured to the right values.
* Remark: The operation control function does not perform a softreset and does not know anything
* about the antanna configuration, so these things have to be handled separately!
*/
opp.group_ordinal = RCO_GROUP_MODE;
opp.attrtype_ordinal = RCO_ATTR_MFRD_A;
opp.param_a = RCO_VAL_RF106K;
opp.param_b = RCO_VAL_RF106K;
status = rc_op_ctl.SetAttrib(&opp);
/* Check status and display error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR performing Mifare Reader configuration! Status = %04x \n", status);

/* Set the timer to auto mode, 5ms using operation control commands before HF is switched on to
* guarantee Iso14443-3 compliance of Polling procedure
*/
status = SetTimeOut(&rc_op_ctl, 5000);

/* Activate the field (automatically if there is no external field detected) */


mrp.address = JREG_TXCONTROL;
mrp.mask = JBIT_TX2RFEN | JBIT_TX1RFEN;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/* start timer manually to check the initial waiting time */


mrp.address = JREG_CONTROL;
mrp.mask = JBIT_TSTARTNOW;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/*
* After switching on the timer wait until the timer interrupt occures, so that
* the field is on and the 5ms delay have been passed.
*/
grp.address = JREG_COMMIRQ;
do {
status = rc_reg_ctl.GetRegister(&grp);
}
while(!(grp.reg_data & JBIT_TIMERI) && status == RCLSTATUS_SUCCESS);
/* Check status and diplay error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! GetRegister: Address=%02X, Data=%02X, Status = %04x \n",
grp.address, grp.reg_data, status);

/* Clear the status flag afterwards */


srp.address = JREG_COMMIRQ;
srp.reg_data = JBIT_TIMERI;
status = rc_reg_ctl.SetRegister(&srp);

/*
* Reset timer 1 ms using operation control commands (AutoMode and Prescaler are the same)
* set reload value
*/
status = SetTimeOut(&rc_op_ctl, 5000);

/* Activate receiver for communication


The RcvOff bit and the PowerDown bit are cleared, the command is not changed. */
srp.address = JREG_COMMAND;

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 116

srp.reg_data = JCMD_NOCMDCHANGE;
status = rc_reg_ctl.SetRegister(&srp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! SetRegister: Address=%02X, Data=%02X, Status = %04x \n",
srp.address, srp.reg_data, status);

/* Set timeout for REQA, ANTICOLL, SELECT to 200us */


SetTimeOut(&rc_op_ctl, 200);

/*
* Do activation according to ISO14443A Part3
* Prepare the Request command
*/
buffer[0] = 0;
buffer[1] = 0;
req_p.req_code = ISO14443_3_REQIDL; /* Set Request command code (or Wakeup: ISO14443_3_REQALL) */
req_p.atq = buffer; /* Let Request use the defined return buffer */
status = iso14443_3.RequestA(&req_p); /* Start Request command */
/*
* In normal operation this command returns one of the following three return codes:
* - RCLSTATUS_SUCCESS At least one card has responded
* - RCLSTATUS_COLLISION_ERROR At least two cards have responded
* - RCLSTATUS_IO_TIMEOUT No response at all
*/
if(status == RCLSTATUS_SUCCESS || status == RCLSTATUS_COLLISION_ERROR)
{
/* There was at least one response */
if(status == RCLSTATUS_COLLISION_ERROR)
printf("[W] Multiple Cards detected!! Collission occured during Request!\n");
printf("ATQA = %02x %02x \n", req_p.atq[0],req_p.atq[1]);
} else
/* No response at all */
printf("*** ERROR! RequestA: RequestCode=%02X, ATQA=%02X %02X, Status = %04x \n",
req_p.req_code, req_p.atq[0],req_p.atq[1], status);

/* Prepare data for combined anticollision/select command to get one complete ID */


for(i=0;i<12;i++)
serial[i] = 0x00;

sel_p.sel_lv1_code = SELECT_CASCADE_LEVEL_1; /* Set first cascade level for start */


sel_p.uid = serial; /* Put serial buffer for ID */
sel_p.uid_length = 0; /* No bits are known from ID, so set to 0 */
/* Start Anticollision/Select command */
status = iso14443_3.AnticollisionSelect(&sel_p);
/* Check return code: If the command was ok, is always returns RCLSTATUS_SUCCESSS.
* If nothing was received, parameter uid_length is 0. */
if(status == RCLSTATUS_SUCCESS)
{
/* Display UID and SAK if everything was ok */
printf("UID: ");
for(i=0;i<(sel_p.uid_length/8);i++)
printf("%02X", sel_p.uid[i]);
printf("\tSAK: %02X \n",sel_p.sak);
} else
{
printf("*** ERROR! Anticollision/Select: Command=%02X, Status = %04x \n",
sel_p.sel_lv1_code, status);
}

/*
* Up to this point the ISO14443-3A protocol has been used
* Now part 3 is finished and one has to choose between the several branches. Here is the
* example how to use the Mifare Standard specific command set of the BFL
*/

/* Set timeout for Authentication */


SetTimeOut(&rc_op_ctl, 1000);

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 117

/* Prepare data for Mifare Authentication */


index = 6;
/* Copy UID to Tx buffer */
for(i=0;i<4;i++)
buffer[index++] = serial[i];
/* Copy secret key to buffer */
for(i=0;i<6;i++)
buffer[i] = 0xFF;
/* Initialize all the variables of authentication structure */
mfr_p.cmd = MIFARE_AUTHENT_A; // Set Authenticate with KeyA
mfr_p.addr = 0x05; // Block 5
mfr_p.buffer = buffer; // Set the mifare buffer to the one initialised
mfr_p.buffer_length = 10; // 6 bytes of key and 4 bytes SNR in buffer
/* Start the Mifare authentication */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! Mifare Authentication: Command=%01X, Block=%02X, Status = %04x \n",
mfr_p.cmd, mfr_p.addr, status);
else
printf("Authentication of block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall now be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read */


mfr_p.cmd = MIFARE_READ; // set Read command
mfr_p.addr = 0x05; // Block 5, must be authenticated before
mfr_p.buffer = buffer; // set return buffer to buffer
mfr_p.buffer_length = 0; // nothing is handed over in the buffer
/* Start Mifare Read */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Response shall now be sent within 10ms */


SetTimeOut(&rc_op_ctl, 10000);

/* Prepare data for Mifare Write */


mfr_p.cmd = MIFARE_WRITE ; // set Write command
mfr_p.addr = 0x05; // Block 5, must be authenticated before
mfr_p.buffer_length = MIFARE_STD_BLOCK_SIZE; // 16 bytes in the buffer valid
for(i=0; i < mfr_p.buffer_length; i++)
buffer[i] = (unsigned char)(i + 0x10); // configure data to write
mfr_p.buffer = buffer; // set send buffer to buffer
/* Start Mifare Write */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareWrite: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Write of block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written */
mfr_p.cmd = MIFARE_READ;

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 118

mfr_p.addr = 0x05;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);

/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/*
* Mifare Value Block operation example
*/

/* Set timeout for authentication */


SetTimeOut(&rc_op_ctl, 1000);

/*
* Prepare data for Mifare Authentication for example of Value block operation.
* The same as in the previous example.
*/
index = 6;
for(i=0;i<4;i++)
buffer[index++] = serial[i];
for(i=0;i<6;i++)
buffer[i] = 0xFF;
mfr_p.cmd = MIFARE_AUTHENT_A;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 10;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! Mifare Authentication: Command=%01X, Block=%02X, Status = %04x \n",
mfr_p.cmd, mfr_p.addr, status);
else
printf("Authentication of block %02X successful, continue operation.\n", mfr_p.addr);

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 10000);

/* Init Block 9 as value block with value 100 with Mifare write
* Data in hex: 64 00 00 00 9B FF FF FF 64 00 00 00 09 F6 09 F6 */
mfr_p.cmd = MIFARE_WRITE ;
mfr_p.addr = 0x09;
mfr_p.buffer_length = MIFARE_STD_BLOCK_SIZE;

i=0;
/* init 1st 4 bytes with the specified value */
buffer[i++] = 0x64; // 0x64 == 100
buffer[i++] = 0x00;
buffer[i++] = 0x00;
buffer[i++] = 0x00;
/* 2nd 4 bytes must have bit-inverted value */
for( ; i<8; i++)
buffer[i] = (unsigned char)(~buffer[i-4]);
/* 3rd 4 bytes must have same value as 1st 4 bytes */
for( ; i<12; i++)
buffer[i] = buffer[i-8];
/* 4th 4 byte contain the address, twice plain, twice bit inverted */
buffer[i++] = mfr_p.addr;

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 119

buffer[i++] = (unsigned char)(~mfr_p.addr);


buffer[i++] = mfr_p.addr;
buffer[i++] = (unsigned char)(~mfr_p.addr);

/* Set the send buffer pointer to the user buffer pointer */


mfr_p.buffer = buffer;
/* Start Mifare Write */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareWrite: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Write successful, continue operation.\n");

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 5000);

/* Use Mifare Increment to increase the value */


mfr_p.cmd = MIFARE_INCREMENT;
mfr_p.addr = 0x09;
mfr_p.buffer_length = MIFARE_VALUE_DATA_SIZE;
/* Increment by the value 16 */
buffer[0] = 0x10;
buffer[1] = 0x00;
buffer[2] = 0x00;
buffer[3] = 0x00;
mfr_p.buffer = buffer;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareIncrement: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Increment successful, continue operation.\n");

/* Timeout set to 10ms */


SetTimeOut(&rc_op_ctl, 10000);

/* Use the transfer directly afterwards to store data in EEProm */


mfr_p.cmd = MIFARE_TRANSFER;
mfr_p.addr = 0x09;
/* Start Mifare Transfer command */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareTransfer: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Transfer successful, continue operation.\n");

/* Response shall be sent within 5ms */

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 120

SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written with increment */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
/* Start Mifare Read */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 5000);

/* Use Mifare Decrement to reduce the value */


mfr_p.cmd = MIFARE_DECREMENT;
mfr_p.addr = 0x09;
mfr_p.buffer_length = MIFARE_VALUE_DATA_SIZE;
/* Decrement by the value 32 */
buffer[0] = 0x20;
buffer[1] = 0x00;
buffer[2] = 0x00;
buffer[3] = 0x00;
mfr_p.buffer = buffer;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareDecrement: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Decrement of block %02X successful, continue operation.\n", mfr_p.addr);

/* Timeout set to 10ms */


SetTimeOut(&rc_op_ctl, 10000);

/* Use transfer directly afterwards to store data in EEProm */


mfr_p.cmd = MIFARE_TRANSFER;
mfr_p.addr = 0x09;
/* Start Mifare Transfer */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareTransfer: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Transfer to block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written with decrement */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 121

for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 5000);

/* Use restore to copy one block to another */


mfr_p.cmd = MIFARE_RESTORE;
mfr_p.addr = 0x09;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRestore: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Restore of block %02X successful, continue operation.\n", mfr_p.addr);

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 10000);

/* Use transfer directly afterwards to store data in EEProm */


mfr_p.cmd = MIFARE_TRANSFER;
mfr_p.addr = 0x08;
/* Start Mifare Transfer */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareTransfer: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Transfer to block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x08;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* This is just an example implementation how to write to a Mifare UltraLight card */


/* perform Mifare Write 4 (only valid for Mifare Ultralight cards!!) */
/*

SetTimeOut(&rc_op_ctl, 10000);

mfr_p.cmd = MIFARE_WRITE4;
mfr_p.addr = 0x07;
mfr_p.buffer_length = MIFARE_UL_PAGE_SIZE;
for(i=0; i < mfr_p.buffer_length; i++)
buffer[i] = (unsigned char)(i + 0x90);
mfr_p.buffer = buffer;
*/
/* Start Mifare Write 4 */
/*
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)

RC522 Basic Function Library Documentation


4.3 MifareReader.cpp 122

printf("*** ERROR! MifareWrite4: Page=%02X, Status = %04x \n", mfr_p.addr, status);


else
printf("Write4 successful, continue operation.\n");
*/

/*
* Do ISO14443-3 HaltA for deactivation of the card
*/

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 1000);

status = iso14443_3.HaltA(&hlt_p);
/* Check return code: If timeout occures, RCLSTATUS_SUCCESS is returned */
if(status == RCLSTATUS_SUCCESS)
{
printf("Halt probably successful, timeout occured\n");
}
else
{
printf("*** ERROR! HaltA: Status = %04x \n", status);
}

return status;
}

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 123

4.4 MifareReaderC.c
The following code contains an example for implementing the Mifare Reader functionality using the
BFL.
The MifareParams function show the necessary settings of the RC522 hardware to act like a Mifare
Reader.
In the main procedure (ActivateMifareReader) first all necessary components of the BFL are declared.
After this, all relevant data structs are declared. Doing this you may start to initialise the BFL stack.
In this example the serial interface of a PC is used. The initialisation of this part is not shown in this
example. The BAL needs only to know about the interface, so the handle is set to the com handle of
the BAL.
Then everything is ready to initialise the RC522. This is done by using dedicated functions of the
operation control component.
Then a timeout value has to be defined and the first command of the activation can be started.
After successful activation there are exapmles shown how to authenticate a Mifare Card and how to
read or write data from the authenticated sector.
At the end an HaltA command is processed, to set the Card into halt state.

/* /////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Philips Semiconductors
//
// (C)PHILIPS Electronics N.V.2004
// All rights are reserved. Reproduction in whole or in part is
// prohibited without the written consent of the copyright owner.
// Philips reserves the right to make changes without notice at any time.
// Philips makes no warranty, expressed, implied or statutory, including but
// not limited to any implied warranty of merchantability or fitness for any
// particular purpose, or that the use will not infringe any third party patent,
// copyright or trademark. Philips must not be liable for any loss or damage
// arising from its use.

/* For debugging purposes (printf) */


#include <stdio.h>

/* Common headers */
#include <joinerreg.h>
#include <rclstruct.h>

/* Needed for any Operating Mode */


#include <bal.h>
#include <rcregctl.h>
#include <rcio.h>
#include <rcopctl_ordinals.h>
#include <rcopctl.h>

/* Needed for this Operating Mode */


#include <iso14443_3.h>
#include <mifare.h>

#include "ExampleUtilsC.h"

/*
* This example shows how to act as Mifare reader
*/
int ActivateMifareReader(int comHandle)
{
/* Declaration of RCL Component Structures (auto), C variant: */
C_BAL bal;

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 124

C_RC_REG_CTL rc_reg_ctl;
C_RC_IO rcio;
C_RC_OP_CTL rc_op_ctl;
C_ISO_14443_3A iso14443_3;
C_MIFARE_READER mfrd;
/* Declaration of internal Component Structures: */
#ifdef WIN32
C_JOINER_RS_232_PC_BAL_PARAMS bal_params;
#else
C_JOINER_RS_232_LINUX_BAL_PARAMS bal_params;
#endif
C_JOINER_RS_232_PC_RC_REG_CTL_PARAMS rc_reg_ctl_params;
C_JOINER_RC_IO_PARAMETERS rc_io_params;
C_JOINER_RC_OP_CTL_PARAMETERS rc_op_ctl_params;
C_JOINER_ISO_14443_3_PARAMETERS iso_14443_3_params;
C_MF_RD_INTL_PARAMS mifare_params;

/*
* Declaration of used parameter structures
*/
/* Register control parameters */
RCREGCTL_GETREG_PARAM grp;
RCREGCTL_SETREG_PARAM srp;
RCREGCTL_MODIFY_PARAM mrp;
/* Operation control parameters */
RCOPCTL_ATTRIB_PARAM opp;
/* ISO14443-3 parameters */
ISO14443_3_REQUEST_A_PARAM req_p;
ISO14443_3_ANTICOLLISIONSELECT_PARAM sel_p;
ISO14443_3_HALT_A_PARAM hlt_p;
/* Mifare parameters */
MIFARE_CMD_PARAM mfr_p;

/* Declaration of variables, buffer, ... */


/* Status variable */
RCLSTATUS status = RCLSTATUS_SUCCESS;
/* Buffer for data transfer (send/receive) */
unsigned char buffer[64];
/* Buffer serial number */
unsigned char serial[12];
/* Counter variable */
unsigned char i, index;

/* Initialisation of self parameters */


srp.self = &rc_reg_ctl;
grp.self = &rc_reg_ctl;
mrp.self = &rc_reg_ctl;
opp.self = &rc_op_ctl;
req_p.self = &iso14443_3;
sel_p.self = &iso14443_3;
hlt_p.self = &iso14443_3;
mfr_p.self = &mfrd;

/* Build up stack for serial communication: */


#ifdef WIN32
JoinerBalRs232PcInitialise(&bal, &bal_params);
#else
JoinerBalRs232LinuxInitialise(&bal, &bal_params);
#endif
/* Initialise Register Control Layer component */
JoinerRcRegCtlRs232PcInitialise(&rc_reg_ctl, &rc_reg_ctl_params, &bal);
/* Initialise RcIo component */
JoinerRcIoInitialise(&rcio, &rc_io_params, &rc_reg_ctl, 1);
/* Initialise Operation Control component */
JoinerRcOpCtlInitialise(&rc_op_ctl, &rc_op_ctl_params, &rc_reg_ctl);
/* Initialise ISO14443-3 component */

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 125

JoinerIso14443_3Initialise(&iso14443_3, &iso_14443_3_params, &rc_reg_ctl, 1);


/* Initialise Mifare component */
MifareReaderInitialise(&mfrd, &mifare_params, &rcio, buffer+20);

/* Let the BAL know about the used serial Port which is initialiesed outside of this function */
#ifdef WIN32
((C_JOINER_RS_232_PC_BAL_PARAMS*) (bal.mp_Members))->com_handle = (void*) comHandle;
#else
((C_JOINER_RS_232_LINUX_BAL_PARAMS*) (bal.mp_Members))->com_handle = comHandle;
#endif

/* Configure RC522 to act as a Mifare Reader. All register which are set in other modes
* are configured to the right values.
* Remark: The operation control function does not perform a softreset and does not know anything
* about the antanna configuration, so these things have to be handled separately!
*/
opp.group_ordinal = RCO_GROUP_MODE;
opp.attrtype_ordinal = RCO_ATTR_MFRD_A;
opp.param_a = RCO_VAL_RF106K;
opp.param_b = RCO_VAL_RF106K;
status = rc_op_ctl.SetAttrib(&opp);
/* Check status and display error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR performing Mifare Reader configuration! Status = %04x \n", status);

/* Set the timer to auto mode, 5ms using operation control commands before HF is switched on to
* guarantee Iso14443-3 compliance of Polling procedure
*/
status = SetTimeOut(&rc_op_ctl, 5000);

/* Activate the field (automatically if there is no external field detected) */


mrp.address = JREG_TXCONTROL;
mrp.mask = JBIT_TX2RFEN | JBIT_TX1RFEN;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/* start timer manually to check the initial waiting time */


mrp.address = JREG_CONTROL;
mrp.mask = JBIT_TSTARTNOW;
mrp.set = 1;
status = rc_reg_ctl.ModifyRegister(&mrp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! ModifyRegister: Set=%1d, Address=%02X, Mask=%02X, Status = %04x \n",
mrp.set, mrp.address, mrp.mask, status);

/*
* After switching on the timer wait until the timer interrupt occures, so that
* the field is on and the 5ms delay have been passed.
*/
grp.address = JREG_COMMIRQ;
do {
status = rc_reg_ctl.GetRegister(&grp);
}
while(!(grp.reg_data & JBIT_TIMERI) && status == RCLSTATUS_SUCCESS);
/* Check status and diplay error if something went wrong */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! GetRegister: Address=%02X, Data=%02X, Status = %04x \n",
grp.address, grp.reg_data, status);

/* Clear the status flag afterwards */


srp.address = JREG_COMMIRQ;
srp.reg_data = JBIT_TIMERI;
status = rc_reg_ctl.SetRegister(&srp);

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 126

/*
* Reset timer 1 ms using operation control commands (AutoMode and Prescaler are the same)
* set reload value
*/
status = SetTimeOut(&rc_op_ctl, 5000);

/* Activate receiver for communication


The RcvOff bit and the PowerDown bit are cleared, the command is not changed. */
srp.address = JREG_COMMAND;
srp.reg_data = JCMD_NOCMDCHANGE;
status = rc_reg_ctl.SetRegister(&srp);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! SetRegister: Address=%02X, Data=%02X, Status = %04x \n",
srp.address, srp.reg_data, status);

/* Set timeout for REQA, ANTICOLL, SELECT to 200us */


SetTimeOut(&rc_op_ctl, 200);

/*
* Do activation according to ISO14443A Part3
* Prepare the Request command
*/
buffer[0] = 0;
buffer[1] = 0;
req_p.req_code = ISO14443_3_REQIDL; /* Set Request command code (or Wakeup: ISO14443_3_REQALL) */
req_p.atq = buffer; /* Let Request use the defined return buffer */
status = iso14443_3.RequestA(&req_p); /* Start Request command */
/*
* In normal operation this command returns one of the following three return codes:
* - RCLSTATUS_SUCCESS At least one card has responded
* - RCLSTATUS_COLLISION_ERROR At least two cards have responded
* - RCLSTATUS_IO_TIMEOUT No response at all
*/
if(status == RCLSTATUS_SUCCESS || status == RCLSTATUS_COLLISION_ERROR)
{
/* There was at least one response */
if(status == RCLSTATUS_COLLISION_ERROR)
printf("[W] Multiple Cards detected!! Collission occured during Request!\n");
printf("ATQA = %02x %02x \n", req_p.atq[0],req_p.atq[1]);
} else
/* No response at all */
printf("*** ERROR! RequestA: RequestCode=%02X, ATQA=%02X %02X, Status = %04x \n",
req_p.req_code, req_p.atq[0],req_p.atq[1], status);

/* Prepare data for combined anticollision/select command to get one complete ID */


for(i=0;i<12;i++)
serial[i] = 0x00;

sel_p.sel_lv1_code = SELECT_CASCADE_LEVEL_1; /* Set first cascade level for start */


sel_p.uid = serial; /* Put serial buffer for ID */
sel_p.uid_length = 0; /* No bits are known from ID, so set to 0 */
/* Start Anticollision/Select command */
status = iso14443_3.AnticollisionSelect(&sel_p);
/* Check return code: If the command was ok, is always returns RCLSTATUS_SUCCESSS.
* If nothing was received, parameter uid_length is 0. */
if(status == RCLSTATUS_SUCCESS)
{
/* Display UID and SAK if everything was ok */
printf("UID: ");
for(i=0;i<(sel_p.uid_length/8);i++)
printf("%02X", sel_p.uid[i]);
printf("\tSAK: %02X \n",sel_p.sak);
} else
{

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 127

printf("*** ERROR! Anticollision/Select: Command=%02X, Status = %04x \n",


sel_p.sel_lv1_code, status);
}

/*
* Up to this point the ISO14443-3A protocol has been used
* Now part 3 is finished and one has to choose between the several branches. Here is the
* example how to use the Mifare Standard specific command set of the BFL
*/

/* Set timeout for Authentication */


SetTimeOut(&rc_op_ctl, 1000);

/* Prepare data for Mifare Authentication */


index = 6;
/* Copy UID to Tx buffer */
for(i=0;i<4;i++)
buffer[index++] = serial[i];
/* Copy secret key to buffer */
for(i=0;i<6;i++)
buffer[i] = 0xFF;
/* Initialize all the variables of authentication structure */
mfr_p.cmd = MIFARE_AUTHENT_A; // Set Authenticate with KeyA
mfr_p.addr = 0x05; // Block 5
mfr_p.buffer = buffer; // Set the mifare buffer to the one initialised
mfr_p.buffer_length = 10; // 6 bytes of key and 4 bytes SNR in buffer
/* Start the Mifare authentication */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! Mifare Authentication: Command=%01X, Block=%02X, Status = %04x \n",
mfr_p.cmd, mfr_p.addr, status);
else
printf("Authentication of block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall now be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read */


mfr_p.cmd = MIFARE_READ; // set Read command
mfr_p.addr = 0x05; // Block 5, must be authenticated before
mfr_p.buffer = buffer; // set return buffer to buffer
mfr_p.buffer_length = 0; // nothing is handed over in the buffer
/* Start Mifare Read */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Response shall now be sent within 10ms */


SetTimeOut(&rc_op_ctl, 10000);

/* Prepare data for Mifare Write */


mfr_p.cmd = MIFARE_WRITE ; // set Write command
mfr_p.addr = 0x05; // Block 5, must be authenticated before
mfr_p.buffer_length = MIFARE_STD_BLOCK_SIZE; // 16 bytes in the buffer valid
for(i=0; i < mfr_p.buffer_length; i++)
buffer[i] = (unsigned char)(i + 0x10); // configure data to write
mfr_p.buffer = buffer; // set send buffer to buffer
/* Start Mifare Write */

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 128

status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareWrite: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Write of block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x05;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/*
* Mifare Value Block operation example
*/

/* Set timeout for authentication */


SetTimeOut(&rc_op_ctl, 1000);

/*
* Prepare data for Mifare Authentication for example of Value block operation.
* The same as in the previous example.
*/
index = 6;
for(i=0;i<4;i++)
buffer[index++] = serial[i];
for(i=0;i<6;i++)
buffer[i] = 0xFF;
mfr_p.cmd = MIFARE_AUTHENT_A;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 10;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! Mifare Authentication: Command=%01X, Block=%02X, Status = %04x \n",
mfr_p.cmd, mfr_p.addr, status);
else
printf("Authentication of block %02X successful, continue operation.\n", mfr_p.addr);

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 10000);

/* Init Block 9 as value block with value 100 with Mifare write
* Data in hex: 64 00 00 00 9B FF FF FF 64 00 00 00 09 F6 09 F6 */
mfr_p.cmd = MIFARE_WRITE ;
mfr_p.addr = 0x09;
mfr_p.buffer_length = MIFARE_STD_BLOCK_SIZE;

i=0;
/* init 1st 4 bytes with the specified value */
buffer[i++] = 0x64; // 0x64 == 100

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 129

buffer[i++] = 0x00;
buffer[i++] = 0x00;
buffer[i++] = 0x00;
/* 2nd 4 bytes must have bit-inverted value */
for( ; i<8; i++)
buffer[i] = (unsigned char)(~buffer[i-4]);
/* 3rd 4 bytes must have same value as 1st 4 bytes */
for( ; i<12; i++)
buffer[i] = buffer[i-8];
/* 4th 4 byte contain the address, twice plain, twice bit inverted */
buffer[i++] = mfr_p.addr;
buffer[i++] = (unsigned char)(~mfr_p.addr);
buffer[i++] = mfr_p.addr;
buffer[i++] = (unsigned char)(~mfr_p.addr);

/* Set the send buffer pointer to the user buffer pointer */


mfr_p.buffer = buffer;
/* Start Mifare Write */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareWrite: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Write successful, continue operation.\n");

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 5000);

/* Use Mifare Increment to increase the value */


mfr_p.cmd = MIFARE_INCREMENT;
mfr_p.addr = 0x09;
mfr_p.buffer_length = MIFARE_VALUE_DATA_SIZE;
/* Increment by the value 16 */
buffer[0] = 0x10;
buffer[1] = 0x00;
buffer[2] = 0x00;
buffer[3] = 0x00;
mfr_p.buffer = buffer;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareIncrement: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Increment successful, continue operation.\n");

/* Timeout set to 10ms */


SetTimeOut(&rc_op_ctl, 10000);

/* Use the transfer directly afterwards to store data in EEProm */

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 130

mfr_p.cmd = MIFARE_TRANSFER;
mfr_p.addr = 0x09;
/* Start Mifare Transfer command */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareTransfer: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Transfer successful, continue operation.\n");

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written with increment */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
/* Start Mifare Read */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 5000);

/* Use Mifare Decrement to reduce the value */


mfr_p.cmd = MIFARE_DECREMENT;
mfr_p.addr = 0x09;
mfr_p.buffer_length = MIFARE_VALUE_DATA_SIZE;
/* Decrement by the value 32 */
buffer[0] = 0x20;
buffer[1] = 0x00;
buffer[2] = 0x00;
buffer[3] = 0x00;
mfr_p.buffer = buffer;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareDecrement: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Decrement of block %02X successful, continue operation.\n", mfr_p.addr);

/* Timeout set to 10ms */


SetTimeOut(&rc_op_ctl, 10000);

/* Use transfer directly afterwards to store data in EEProm */


mfr_p.cmd = MIFARE_TRANSFER;
mfr_p.addr = 0x09;
/* Start Mifare Transfer */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareTransfer: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Transfer to block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 131

/* Prepare data for Mifare Read again to check what has been written with decrement */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x09;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 5000);

/* Use restore to copy one block to another */


mfr_p.cmd = MIFARE_RESTORE;
mfr_p.addr = 0x09;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRestore: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Restore of block %02X successful, continue operation.\n", mfr_p.addr);

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 10000);

/* Use transfer directly afterwards to store data in EEProm */


mfr_p.cmd = MIFARE_TRANSFER;
mfr_p.addr = 0x08;
/* Start Mifare Transfer */
status = mfrd.Transaction(&mfr_p);
/* Check return code and display error number if an error occured, else display data */
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareTransfer: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Transfer to block %02X successful, continue operation.\n", mfr_p.addr);

/* Response shall be sent within 5ms */


SetTimeOut(&rc_op_ctl, 5000);

/* Prepare data for Mifare Read again to check what has been written */
mfr_p.cmd = MIFARE_READ;
mfr_p.addr = 0x08;
mfr_p.buffer = buffer;
mfr_p.buffer_length = 0;
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareRead: Block=%02X, Status = %04x \n", mfr_p.addr, status);
else
{
printf("Mifare Read: Block=%02X, Data: ", mfr_p.addr);
for(i=0;i<mfr_p.buffer_length;i++)
printf("%02X",mfr_p.buffer[i]);
printf("\n");
}

/* This is just an example implementation how to write to a Mifare UltraLight card */


/* perform Mifare Write 4 (only valid for Mifare Ultralight cards!!) */
/*
SetTimeOut(&rc_op_ctl, 10000);

mfr_p.cmd = MIFARE_WRITE4;

RC522 Basic Function Library Documentation


4.4 MifareReaderC.c 132

mfr_p.addr = 0x07;
mfr_p.buffer_length = MIFARE_UL_PAGE_SIZE;
for(i=0; i < mfr_p.buffer_length; i++)
buffer[i] = (unsigned char)(i + 0x90);
mfr_p.buffer = buffer;
*/
/* Start Mifare Write 4 */
/*
status = mfrd.Transaction(&mfr_p);
if(status != RCLSTATUS_SUCCESS)
printf("*** ERROR! MifareWrite4: Page=%02X, Status = %04x \n", mfr_p.addr, status);
else
printf("Write4 successful, continue operation.\n");
*/

/*
* Do ISO14443-3 HaltA for deactivation of the card
*/

/* Set timeouts */
SetTimeOut(&rc_op_ctl, 1000);

status = iso14443_3.HaltA(&hlt_p);
/* Check return code: If timeout occures, RCLSTATUS_SUCCESSS is returned */
if(status == RCLSTATUS_SUCCESS)
{
printf("Halt probably successful, timeout occured\n");
}
else
{
printf("*** ERROR! HaltA: Status = %04x \n", status);
}

return status;
}

RC522 Basic Function Library Documentation

You might also like