libnfc  1.7.1
Functions
NFC target

Functions

int nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRx, int timeout)
 Initialize NFC device as an emulated tag.
int nfc_target_send_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, int timeout)
 Send bytes and APDU frames.
int nfc_target_receive_bytes (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, int timeout)
 Receive bytes and APDU frames.
int nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar)
 Send raw bit-frames.
int nfc_target_receive_bits (nfc_device *pnd, uint8_t *pbtRx, const size_t szRx, uint8_t *pbtRxPar)
 Receive bit-frames.

Detailed Description

This page details how to act as tag (i.e. MIFARE Classic) or NFC target device.


Function Documentation

int nfc_target_init ( nfc_device pnd,
nfc_target pnt,
uint8_t *  pbtRx,
const size_t  szRx,
int  timeout 
)

Initialize NFC device as an emulated tag.

Returns:
Returns received bytes count on success, otherwise returns libnfc's error code
Parameters:
pndnfc_device struct pointer that represent currently used device
pntpointer to nfc_target struct that represents the wanted emulated target
Note:
pnt can be updated by this function: if you set NBR_UNDEFINED and/or NDM_UNDEFINED (ie. for DEP mode), these fields will be updated.
Parameters:
[out]pbtRxRx buffer pointer
[out]szRxreceived bytes count
timeoutin milliseconds

This function initializes NFC device in target mode in order to emulate a tag using the specified nfc_target_mode_t.

  • Crc is handled by the device (NP_HANDLE_CRC = true)
  • Parity is handled the device (NP_HANDLE_PARITY = true)
  • Cryto1 cipher is disabled (NP_ACTIVATE_CRYPTO1 = false)
  • Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = true)
  • Easy framing is disabled (NP_EASY_FRAMING = false)
  • Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = false)
  • Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
  • RF field is dropped
Warning:
Be aware that this function will wait (hang) until a command is received that is not part of the anti-collision. The RATS command for example would wake up the emulator. After this is received, the send and receive functions can be used.

If timeout equals to 0, the function blocks indefinitely (until an error is raised or function is completed) If timeout equals to -1, the default timeout will be used

Definition at line 933 of file nfc.c.

int nfc_target_receive_bits ( nfc_device pnd,
uint8_t *  pbtRx,
const size_t  szRx,
uint8_t *  pbtRxPar 
)

Receive bit-frames.

Returns:
Returns received bits count on success, otherwise returns libnfc's error code
Parameters:
pndnfc_device struct pointer that represent currently used device
pbtRxpointer to Rx buffer
szRxsize of Rx buffer
[out]pbtRxParparameter contains a byte array of the corresponding parity bits

This function makes it possible to receive (raw) bit-frames. It returns all the messages that are stored in the FIFO buffer of the PN53x chip. It does not require to send any frame and thereby could be used to snoop frames that are transmitted by a nearby initiator.

Note:
Check out the NP_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted frames.

Definition at line 1071 of file nfc.c.

int nfc_target_receive_bytes ( nfc_device pnd,
uint8_t *  pbtRx,
const size_t  szRx,
int  timeout 
)

Receive bytes and APDU frames.

Returns:
Returns received bytes count on success, otherwise returns libnfc's error code
Parameters:
pndnfc_device struct pointer that represent currently used device
pbtRxpointer to Rx buffer
szRxsize of Rx buffer
timeoutin milliseconds

This function retrieves bytes frames (e.g. ADPU) sent by the initiator to the NFC device (configured as target).

If timeout equals to 0, the function blocks indefinitely (until an error is raised or function is completed) If timeout equals to -1, the default timeout will be used

Definition at line 1032 of file nfc.c.

int nfc_target_send_bits ( nfc_device pnd,
const uint8_t *  pbtTx,
const size_t  szTxBits,
const uint8_t *  pbtTxPar 
)

Send raw bit-frames.

Returns:
Returns sent bits count on success, otherwise returns libnfc's error code.
Parameters:
pndnfc_device struct pointer that represent currently used device
pbtTxpointer to Tx buffer
szTxBitssize of Tx buffer
pbtTxParparameter contains a byte array of the corresponding parity bits needed to send per byte. This function can be used to transmit (raw) bit-frames to the initiator using the specified NFC device (configured as target).

Definition at line 1049 of file nfc.c.

int nfc_target_send_bytes ( nfc_device pnd,
const uint8_t *  pbtTx,
const size_t  szTx,
int  timeout 
)

Send bytes and APDU frames.

Returns:
Returns sent bytes count on success, otherwise returns libnfc's error code
Parameters:
pndnfc_device struct pointer that represent currently used device
pbtTxpointer to Tx buffer
szTxsize of Tx buffer
timeoutin milliseconds

This function make the NFC device (configured as target) send byte frames (e.g. APDU responses) to the initiator.

If timeout equals to 0, the function blocks indefinitely (until an error is raised or function is completed) If timeout equals to -1, the default timeout will be used

Definition at line 1012 of file nfc.c.