API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Functions

Functions

void TSMART_NFC_Init (tsmart_nfc_t *TSMART_NFC)
 Initializes the NFC device. More...
 
void TSMART_NFC_WakeUp (tsmart_nfc_t *TSMART_NFC, portTickType TSMART_NFC_xticks)
 Exit from Power Down mode. More...
 
int8_t TSMART_NFC_SamConfiguration (tsmart_nfc_t *TSMART_NFC, tsmart_nfc_sam_mode_t TSMART_NFC_sam_mode, uint8_t TSMART_NFC_timeout, tsmart_nfc_boolean_t TSMART_NFC_irq, portTickType TSMART_NFC_xticks)
 Send to the NFC device a SAMConfiguration Command. More...
 
int8_t TSMART_NFC_InListPassiveTarget (tsmart_nfc_t *TSMART_NFC, tsmart_nfc_target_number_t TSMART_NFC_max_tg, tsmart_nfc_baud_mod_t TSMART_NFC_br_ty, uint8_t *TSMART_NFC_initiator_data, uint8_t TSMART_NFC_initiator_data_size, uint8_t *TSMART_NFC_target_data, portTickType TSMART_NFC_xticks)
 The goal of this command is to detect as many targets (maximum MaxTg) as possible in passive mode. More...
 
int8_t TSMART_NFC_GetId (tsmart_nfc_t *TSMART_NFC, tsmart_nfc_id_t *TSMART_NFC_id, portTickType TSMART_NFC_xticks)
 Get the ID from a Tag. More...
 
int8_t TSMART_NFC_List (tsmart_nfc_t *TSMART_NFC, tsmart_nfc_id_t TSMART_NFC_id[2], portTickType TSMART_NFC_xticks)
 List Tags. More...
 
int8_t TSMART_NFC_InSelect (tsmart_nfc_t *TSMART_NFC, uint8_t TSMART_NFC_tg, portTickType TSMART_NFC_xticks)
 The goal of this command is to select the target Tg (obtained by InListPassiveTarget). More...
 
int8_t TSMART_NFC_InDataExchange (tsmart_nfc_t *TSMART_NFC, tsmart_nfc_target_number_t TSMART_NFC_tg, uint8_t *TSMART_NFC_data_out, uint8_t TSMART_NFC_data_out_size, uint8_t *TSMART_NFC_data_in, portTickType TSMART_NFC_xticks)
 This command is used to support protocol data exchanges between the PN532 as initiator and a target. More...
 
int8_t TSMART_NFC_AuthenticateA (tsmart_nfc_t *TSMART_NFC, tsmart_nfc_id_t TSMART_NFC_id, uint8_t TSMART_NFC_block, uint8_t *TSMART_NFC_key, portTickType TSMART_NFC_xticks)
 Authenticate in a block from a selected Tag. More...
 
int8_t TSMART_NFC_AuthenticateB (tsmart_nfc_t *TSMART_NFC, tsmart_nfc_id_t TSMART_NFC_id, uint8_t TSMART_NFC_block, uint8_t *TSMART_NFC_key, portTickType TSMART_NFC_xticks)
 Authenticate in a block from a selected Tag. More...
 
int8_t TSMART_NFC_ReadCard (tsmart_nfc_t *TSMART_NFC, uint8_t *TSMART_NFC_buf, uint8_t TSMART_NFC_addr, portTickType TSMART_NFC_xticks)
 Read one block from a selected Tag. More...
 
int8_t TSMART_NFC_WriteCard4B (tsmart_nfc_t *TSMART_NFC, uint8_t *TSMART_NFC_buf, uint8_t TSMART_NFC_addr, portTickType TSMART_NFC_xticks)
 Write one block from a selected Tag. More...
 
int8_t TSMART_NFC_WriteCard16B (tsmart_nfc_t *TSMART_NFC, uint8_t *TSMART_NFC_buf, uint8_t TSMART_NFC_addr, portTickType TSMART_NFC_xticks)
 Write one block from a selected Tag. More...
 
int32_t TSMART_NFC_Receive (tsmart_nfc_t *TSMART_NFC, uint8_t *TSMART_NFC_buf, uint16_t TSMART_NFC_nbytes, portTickType TSMART_NFC_xticks)
 Receives the answer to a command sent to the NFC device. More...
 
int32_t TSMART_NFC_Send (tsmart_nfc_t *TSMART_NFC, uint8_t *TSMART_NFC_buf, uint16_t TSMART_NFC_nbytes, portTickType TSMART_NFC_xticks)
 Sends a command to the NFC device. More...
 
int8_t TSMART_NFC_TgInitAsTarget (tsmart_nfc_t *TSMART_NFC, uint8_t TSMART_NFC_mode, uint8_t *TSMART_NFC_mifare_params, uint8_t *TSMART_NFC_felica_params, uint8_t *TSMART_NFC_nfcid, uint8_t TSMART_NFC_l_gt, uint8_t *TSMART_NFC_gt, uint8_t TSMART_NFC_l_tk, uint8_t *TSMART_NFC_tk, portTickType TSMART_NFC_xticks)
 Configures the NFC devices as target. More...
 
int8_t TSMART_NFC_TgGetData (tsmart_nfc_t *TSMART_NFC, uint8_t *TSMART_NFC_data, portTickType TSMART_NFC_xticks)
 Get data from remote NFC device. More...
 
int8_t TSMART_NFC_TgSetData (tsmart_nfc_t *TSMART_NFC, uint8_t *TSMART_NFC_data, uint16_t TSMART_NFC_data_size, portTickType TSMART_NFC_xticks)
 Set data to remote NFC device. More...
 

Detailed Description

Function Documentation

int8_t TSMART_NFC_AuthenticateA ( tsmart_nfc_t TSMART_NFC,
tsmart_nfc_id_t  TSMART_NFC_id,
uint8_t  TSMART_NFC_block,
uint8_t *  TSMART_NFC_key,
portTickType  TSMART_NFC_xticks 
)

Authenticate in a block from a selected Tag.

Only applicable to Mifare Classic tags

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_idNFC ID from a Selected Tag
TSMART_NFC_blockMifare Card Address
TSMART_NFC_keyKey in the Mifare Card Address
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_NFC_FAIL - Failure
Examples:
nfc_read.c.
int8_t TSMART_NFC_AuthenticateB ( tsmart_nfc_t TSMART_NFC,
tsmart_nfc_id_t  TSMART_NFC_id,
uint8_t  TSMART_NFC_block,
uint8_t *  TSMART_NFC_key,
portTickType  TSMART_NFC_xticks 
)

Authenticate in a block from a selected Tag.

Only applicable to Mifare Classic tags

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_idNFC ID from a Selected Tag
TSMART_NFC_blockMifare Card Address
TSMART_NFC_keyKey in the Mifare Card Address
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_NFC_FAIL - Failure
Examples:
nfc_write.c.
int8_t TSMART_NFC_GetId ( tsmart_nfc_t TSMART_NFC,
tsmart_nfc_id_t TSMART_NFC_id,
portTickType  TSMART_NFC_xticks 
)

Get the ID from a Tag.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_idStruct to store the ID –> |Tg|LenID|ID|
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Number target.
  • TSMART_NFC_PASS - There's not target.
  • TSMART_NFC_FAIL - Not answer or bad answer.
Examples:
cumulocity_nfc_wifi_xbee.c, nfc_read.c, nfc_write.c, and xv_nfc_wifi_xbee.c.
int8_t TSMART_NFC_InDataExchange ( tsmart_nfc_t TSMART_NFC,
tsmart_nfc_target_number_t  TSMART_NFC_tg,
uint8_t *  TSMART_NFC_data_out,
uint8_t  TSMART_NFC_data_out_size,
uint8_t *  TSMART_NFC_data_in,
portTickType  TSMART_NFC_xticks 
)

This command is used to support protocol data exchanges between the PN532 as initiator and a target.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_tgLogical number of the target to be selected. Is a byte containing the logical number of the relevant target. This byte contains also a More Information (MI) bit (bit 6) indicating, when set to 1, that the host controller wants to send more data that all the data contained in the DataOut [ ] array. This bit is only valid for a TPE target.
TSMART_NFC_data_outIs an array of raw data (from 0 up to 262 bytes) to be sent to the target by the PN532
TSMART_NFC_data_out_sizeDataOut Size
TSMART_NFC_data_inIs an array of raw data received by the PN532.
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_NFC_FAIL - Failure
void TSMART_NFC_Init ( tsmart_nfc_t TSMART_NFC)

Initializes the NFC device.

This functions initializes the hardware configuration of the NFC device and the associated OS mechanisms.

Parameters
TSMART_NFCNFC structure handler.
Examples:
cumulocity_nfc_wifi_xbee.c, nfc_read.c, nfc_write.c, and xv_nfc_wifi_xbee.c.
int8_t TSMART_NFC_InListPassiveTarget ( tsmart_nfc_t TSMART_NFC,
tsmart_nfc_target_number_t  TSMART_NFC_max_tg,
tsmart_nfc_baud_mod_t  TSMART_NFC_br_ty,
uint8_t *  TSMART_NFC_initiator_data,
uint8_t  TSMART_NFC_initiator_data_size,
uint8_t *  TSMART_NFC_target_data,
portTickType  TSMART_NFC_xticks 
)

The goal of this command is to detect as many targets (maximum MaxTg) as possible in passive mode.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_max_tgThe maximum number of targets to be initialized by the PN532. The PN532 is capable of handling 2 targets maximum at once, so this field should not exceed 0x02. For Jewel card, only one target can be initialized.
TSMART_NFC_br_tyThe baud rate and the modulation type to be used during the initialization
TSMART_NFC_initiator_dataArray of data to be used during the initialization of the target(s). Depending on the Baud Rate specified, the content of this field is different
TSMART_NFC_initiator_data_sizeData Size of Initiator Data
TSMART_NFC_target_dataBuffer to store data received
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Number target.
  • TSMART_NFC_PASS - There's not target.
  • TSMART_NFC_FAIL - Not answer or bad answer.
int8_t TSMART_NFC_InSelect ( tsmart_nfc_t TSMART_NFC,
uint8_t  TSMART_NFC_tg,
portTickType  TSMART_NFC_xticks 
)

The goal of this command is to select the target Tg (obtained by InListPassiveTarget).

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_tgLogical number of the target to be selected.
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Selected target.
  • TSMART_NFC_PASS - There's not target.
  • TSMART_NFC_FAIL - Not answer or bad answer.
Examples:
cumulocity_nfc_wifi_xbee.c, nfc_read.c, nfc_write.c, and xv_nfc_wifi_xbee.c.
int8_t TSMART_NFC_List ( tsmart_nfc_t TSMART_NFC,
tsmart_nfc_id_t  TSMART_NFC_id[2],
portTickType  TSMART_NFC_xticks 
)

List Tags.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_idBuffer to store the IDs –> |Tg|LenID|ID|Tg|LenID|ID|
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Number of Tag Listed
int8_t TSMART_NFC_ReadCard ( tsmart_nfc_t TSMART_NFC,
uint8_t *  TSMART_NFC_buf,
uint8_t  TSMART_NFC_addr,
portTickType  TSMART_NFC_xticks 
)

Read one block from a selected Tag.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_bufBuffer to store the data (16 bytes)
TSMART_NFC_addrThe address associated with the Mifare command
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_NFC_FAIL - Failure
Examples:
nfc_read.c, and nfc_write.c.
int32_t TSMART_NFC_Receive ( tsmart_nfc_t TSMART_NFC,
uint8_t *  TSMART_NFC_buf,
uint16_t  TSMART_NFC_nbytes,
portTickType  TSMART_NFC_xticks 
)

Receives the answer to a command sent to the NFC device.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_bufBuffer to store the data
TSMART_NFC_nbytesNumber of Bytes to receive
TSMART_NFC_xticksMaximum waiting timeout.
Returns
nb_bytes - Number of bytes received
Attention
Use this function to receive RAW NXP PN5xx messages at your own risk
int8_t TSMART_NFC_SamConfiguration ( tsmart_nfc_t TSMART_NFC,
tsmart_nfc_sam_mode_t  TSMART_NFC_sam_mode,
uint8_t  TSMART_NFC_timeout,
tsmart_nfc_boolean_t  TSMART_NFC_irq,
portTickType  TSMART_NFC_xticks 
)

Send to the NFC device a SAMConfiguration Command.

This command is used to select the data flow path by configuring the internal serial data switch. It shall be executed before using the device, but after executing TSMART_NFC_Init

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_sam_modeMode defines the way of using the SAM (Security Access Module):
  • 0x01: Normal mode, the SAM is not used; this is the default mode
  • 0x02: Virtual Card, the couple PN532+SAM is seen as only one contactless SAM card from the external world,
  • 0x03: Wired Card, the host controller can access to the SAM with standard PCD commands (InListPassiveTarget,InDataExchange, …)
  • 0x04: Dual Card, both the PN532 and the SAM are visible from the external world as two separated targets
TSMART_NFC_timeoutDefines the time-out only in Virtual card configuration (Mode = 0x02). In Virtual Card mode, this field is mandatory; whereas in the other mode, it is optional. This parameter indicates the timeout value with a LSB of 50ms. There is no timeout control if the value is null (Timeout = 0). The maximum value for the timeout is 12.75 sec (Timeout = 0xFF).
TSMART_NFC_irqIRQ specifies if the PN532 takes care of the P70_IRQ pin or not. If the value is null (IRQ =0x00), the P70_IRQ pin remains at high level; whereas if the value is 0x01, the P70_IRQ pin is driven by the
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • TSMART_NFC_PASS - OK
  • TSMART_NFC_FAIL - Failure
Examples:
cumulocity_nfc_wifi_xbee.c, nfc_read.c, nfc_write.c, and xv_nfc_wifi_xbee.c.
int32_t TSMART_NFC_Send ( tsmart_nfc_t TSMART_NFC,
uint8_t *  TSMART_NFC_buf,
uint16_t  TSMART_NFC_nbytes,
portTickType  TSMART_NFC_xticks 
)

Sends a command to the NFC device.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_bufData buffer to send (including command)
TSMART_NFC_nbytesNumber of Bytes to send
TSMART_NFC_xticksMaximum waiting timeout.
Returns
nb_bytes - Number of bytes sent
Attention
Use this function to send RAW NXP PN5xx messages at your own risk
int8_t TSMART_NFC_TgGetData ( tsmart_nfc_t TSMART_NFC,
uint8_t *  TSMART_NFC_data,
portTickType  TSMART_NFC_xticks 
)

Get data from remote NFC device.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_dataMemory buffer to store received data (Maximum size 262 Bytes).
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_FAIL - Failure
int8_t TSMART_NFC_TgInitAsTarget ( tsmart_nfc_t TSMART_NFC,
uint8_t  TSMART_NFC_mode,
uint8_t *  TSMART_NFC_mifare_params,
uint8_t *  TSMART_NFC_felica_params,
uint8_t *  TSMART_NFC_nfcid,
uint8_t  TSMART_NFC_l_gt,
uint8_t *  TSMART_NFC_gt,
uint8_t  TSMART_NFC_l_tk,
uint8_t *  TSMART_NFC_tk,
portTickType  TSMART_NFC_xticks 
)

Configures the NFC devices as target.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_modeMode
TSMART_NFC_mifare_paramsInformation needed to be able to be activated at 106 kbps in passive mode
TSMART_NFC_felica_paramsContain the information to be able to respond to a polling request at 212/424 kbps in passive mode.
TSMART_NFC_nfcidNFC id
TSMART_NFC_l_gtThis field is mandatory. When set to 0, there are no general bytes following.
TSMART_NFC_gtIs an array containing the general bytes to be used in the ATR_RES (max. 47 bytes).
TSMART_NFC_l_tkThis field is mandatory. When set to 0, there are no historical bytes following.
TSMART_NFC_tkIs an array containing the historical bytes to be used in the ATS when PN532 is in ISO/IEC14443-4 PICC emulation mode. This information is optional. (max. 48 bytes).
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_FAIL - Failure
int8_t TSMART_NFC_TgSetData ( tsmart_nfc_t TSMART_NFC,
uint8_t *  TSMART_NFC_data,
uint16_t  TSMART_NFC_data_size,
portTickType  TSMART_NFC_xticks 
)

Set data to remote NFC device.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_dataData buffer to send.
TSMART_NFC_data_sizeSize of the data (Maximum size 262 Bytes).
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_FAIL - Failure
void TSMART_NFC_WakeUp ( tsmart_nfc_t TSMART_NFC,
portTickType  TSMART_NFC_xticks 
)

Exit from Power Down mode.

When the host controller sends a command to the PN532 on the HSU link in order to exit from Power Down mode, the PN532 needs some delay to be fully operational (the real waking up condition is the 5th rising edge on the serial line)

As a consequence, if the host controller wants to be sure that the command will not be lost or partially received, some precautions must be taken:

  • Either send a command with large preamble containing dummy data
  • Or send first a 0x55 dummy byte and wait for the waking up delay (Twake up time) before sending the command frame
Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_xticksMaximum waiting timeout.
Examples:
cumulocity_nfc_wifi_xbee.c, nfc_read.c, nfc_write.c, and xv_nfc_wifi_xbee.c.
int8_t TSMART_NFC_WriteCard16B ( tsmart_nfc_t TSMART_NFC,
uint8_t *  TSMART_NFC_buf,
uint8_t  TSMART_NFC_addr,
portTickType  TSMART_NFC_xticks 
)

Write one block from a selected Tag.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_bufData to store in Card (16 bytes)
TSMART_NFC_addrThe address associated with the Mifare command
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_NFC_FAIL - Failure
Examples:
nfc_write.c.
int8_t TSMART_NFC_WriteCard4B ( tsmart_nfc_t TSMART_NFC,
uint8_t *  TSMART_NFC_buf,
uint8_t  TSMART_NFC_addr,
portTickType  TSMART_NFC_xticks 
)

Write one block from a selected Tag.

Parameters
TSMART_NFCNFC structure handler.
TSMART_NFC_bufData to store in Card (4 bytes)
TSMART_NFC_addrThe address associated with the Mifare command
TSMART_NFC_xticksMaximum waiting timeout.
Returns
  • Status
  • TSMART_NFC_FAIL - Failure
Examples:
nfc_write.c.