upm
0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
|
API for the PN532 based NFC/RFID reader/writer. More...
Identify a card and print out basic info
Add a URI to an already NDEF formatted ultralight or NTAG2XX tag
Public Types | |
enum | PN532_CMD_T { CMD_DIAGNOSE = 0x00, CMD_GETFIRMWAREVERSION = 0x02, CMD_GETGENERALSTATUS = 0x04, CMD_READREGISTER = 0x06, CMD_WRITEREGISTER = 0x08, CMD_READGPIO = 0x0C, CMD_WRITEGPIO = 0x0E, CMD_SETSERIALBAUDRATE = 0x10, CMD_SETPARAMETERS = 0x12, CMD_SAMCONFIGURATION = 0x14, CMD_POWERDOWN = 0x16, CMD_RFCONFIGURATION = 0x32, CMD_RFREGULATIONTEST = 0x58, CMD_INJUMPFORDEP = 0x56, CMD_INJUMPFORPSL = 0x46, CMD_INLISTPASSIVETARGET = 0x4A, CMD_INATR = 0x50, CMD_INPSL = 0x4E, CMD_INDATAEXCHANGE = 0x40, CMD_INCOMMUNICATETHRU = 0x42, CMD_INDESELECT = 0x44, CMD_INRELEASE = 0x52, CMD_INSELECT = 0x54, CMD_INAUTOPOLL = 0x60, CMD_TGINITASTARGET = 0x8C, CMD_TGSETGENERALBYTES = 0x92, CMD_TGGETDATA = 0x86, CMD_TGSETDATA = 0x8E, CMD_TGSETMETADATA = 0x94, CMD_TGGETINITIATORCOMMAND = 0x88, CMD_TGRESPONSETOINITIATOR = 0x90, CMD_TGGETTARGETSTATUS = 0x8A } |
enum | PN532_RSP_T { RSP_INDATAEXCHANGE = 0x41, RSP_INLISTPASSIVETARGET = 0x4B } |
enum | MIFARE_CMD_T { MIFARE_CMD_AUTH_A = 0x60, MIFARE_CMD_AUTH_B = 0x61, MIFARE_CMD_READ = 0x30, MIFARE_CMD_WRITE = 0xA0, MIFARE_CMD_TRANSFER = 0xB0, MIFARE_CMD_DECREMENT = 0xC0, MIFARE_CMD_INCREMENT = 0xC1, MIFARE_CMD_STORE = 0xC2, MIFARE_ULTRALIGHT_CMD_WRITE = 0xA2 } |
enum | NDEF_URI_T { NDEF_URIPREFIX_NONE = 0x00, NDEF_URIPREFIX_HTTP_WWWDOT = 0x01, NDEF_URIPREFIX_HTTPS_WWWDOT = 0x02, NDEF_URIPREFIX_HTTP = 0x03, NDEF_URIPREFIX_HTTPS = 0x04, NDEF_URIPREFIX_TEL = 0x05, NDEF_URIPREFIX_MAILTO = 0x06, NDEF_URIPREFIX_FTP_ANONAT = 0x07, NDEF_URIPREFIX_FTP_FTPDOT = 0x08, NDEF_URIPREFIX_FTPS = 0x09, NDEF_URIPREFIX_SFTP = 0x0A, NDEF_URIPREFIX_SMB = 0x0B, NDEF_URIPREFIX_NFS = 0x0C, NDEF_URIPREFIX_FTP = 0x0D, NDEF_URIPREFIX_DAV = 0x0E, NDEF_URIPREFIX_NEWS = 0x0F, NDEF_URIPREFIX_TELNET = 0x10, NDEF_URIPREFIX_IMAP = 0x11, NDEF_URIPREFIX_RTSP = 0x12, NDEF_URIPREFIX_URN = 0x13, NDEF_URIPREFIX_POP = 0x14, NDEF_URIPREFIX_SIP = 0x15, NDEF_URIPREFIX_SIPS = 0x16, NDEF_URIPREFIX_TFTP = 0x17, NDEF_URIPREFIX_BTSPP = 0x18, NDEF_URIPREFIX_BTL2CAP = 0x19, NDEF_URIPREFIX_BTGOEP = 0x1A, NDEF_URIPREFIX_TCPOBEX = 0x1B, NDEF_URIPREFIX_IRDAOBEX = 0x1C, NDEF_URIPREFIX_FILE = 0x1D, NDEF_URIPREFIX_URN_EPC_ID = 0x1E, NDEF_URIPREFIX_URN_EPC_TAG = 0x1F, NDEF_URIPREFIX_URN_EPC_PAT = 0x20, NDEF_URIPREFIX_URN_EPC_RAW = 0x21, NDEF_URIPREFIX_URN_EPC = 0x22, NDEF_URIPREFIX_URN_NFC = 0x23 } |
enum | BAUD_T { BAUD_MIFARE_ISO14443A = 0x00 } |
enum | TAG_TYPE_T { TAG_TYPE_UNKNOWN = 0, TAG_TYPE_MIFARE_CLASSIC = 1, TAG_TYPE_NFC2 = 2 } |
Public Member Functions | |
PN532 (int irq, int reset, int bus=PN532_I2C_BUS, uint8_t address=PN532_DEFAULT_I2C_ADDR) | |
~PN532 () | |
bool | init () |
uint32_t | getFirmwareVersion () |
Checks the firmware version of the PN5xx chip. More... | |
bool | sendCommandCheckAck (uint8_t *cmd, uint8_t cmdlen, uint16_t timeout=1000) |
Sends a command and waits a specified period for the ACK. More... | |
bool | SAMConfig (void) |
Configures the SAM (Secure Access Module) More... | |
bool | setPassiveActivationRetries (uint8_t maxRetries) |
bool | readPassiveTargetID (BAUD_T cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t timeout) |
bool | inDataExchange (uint8_t *send, uint8_t sendLength, uint8_t *response, uint8_t *responseLength) |
Exchanges an APDU with the currently inlisted peer. More... | |
bool | inListPassiveTarget () |
'InLists' a passive target. PN532 acting as reader/initiator, peer acting as card/responder. More... | |
bool | mifareclassic_IsFirstBlock (uint32_t uiBlock) |
bool | mifareclassic_IsTrailerBlock (uint32_t uiBlock) |
bool | mifareclassic_AuthenticateBlock (uint8_t *uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t *keyData) |
bool | mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t *data) |
bool | mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t *data) |
bool | mifareclassic_FormatNDEF (void) |
bool | mifareclassic_WriteNDEFURI (uint8_t sectorNumber, NDEF_URI_T uriIdentifier, const char *url) |
bool | ntag2xx_ReadPage (uint8_t page, uint8_t *buffer) |
bool | ntag2xx_WritePage (uint8_t page, uint8_t *data) |
bool | ntag2xx_WriteNDEFURI (NDEF_URI_T uriIdentifier, char *url, uint8_t dataLen) |
uint16_t | getATQA () |
uint8_t | getSAK () |
mraa::I2c & | i2cContext () |
void | pn532Debug (bool enable) |
void | mifareDebug (bool enable) |
TAG_TYPE_T | tagType () |
Protected Member Functions | |
bool | readAck () |
Tries to read/verify the ACK packet. | |
bool | isReady () |
Return true if the PN532 is ready with a response. | |
bool | waitForReady (uint16_t timeout) |
Waits until the PN532 is ready. More... | |
void | readData (uint8_t *buff, uint8_t n) |
Reads n bytes of data from the PN532 via SPI or I2C. More... | |
void | writeCommand (uint8_t *cmd, uint8_t cmdlen) |
Writes a command to the PN532, automatically inserting the preamble and required frame details (checksum, len, etc.) More... | |
Protected Attributes | |
mraa::I2c | m_i2c |
mraa::Gpio | m_gpioIRQ |
mraa::Gpio | m_gpioReset |
enum PN532_CMD_T |
PN532 commands
enum PN532_RSP_T |
Response bytes
enum MIFARE_CMD_T |
MIFARE commands
enum NDEF_URI_T |
NDEF prefixes
enum BAUD_T |
Card baud rates
enum TAG_TYPE_T |
Tag types
PN532 | ( | int | irq, |
int | reset, | ||
int | bus = PN532_I2C_BUS , |
||
uint8_t | address = PN532_DEFAULT_I2C_ADDR |
||
) |
pn532 constructor
irq | pin to use for IRQ |
reset | reset pin |
bus | i2c bus to use |
address | the address for this device |
bool init | ( | ) |
set up initial values and start operation
uint32_t getFirmwareVersion | ( | ) |
Checks the firmware version of the PN5xx chip
bool sendCommandCheckAck | ( | uint8_t * | cmd, |
uint8_t | cmdlen, | ||
uint16_t | timeout = 1000 |
||
) |
sends a command and waits a specified period for the ACK
cmd | Pointer to the command buffer |
cmdlen | the size of the command in bytes |
timeout | timeout before giving up (in ms) |
cmd | Pointer to the command buffer |
cmdlen | The size of the command in bytes |
timeout | timeout before giving up |
bool SAMConfig | ( | void | ) |
configures the SAM (Secure Access Module)
bool setPassiveActivationRetries | ( | uint8_t | maxRetries | ) |
sets the MxRtyPassiveActivation byte of the RFConfiguration register. By default the pn532 will retry indefinitely.
maxRetries | 0xFF to wait forever, 0x00..0xFE to timeout after maxRetries. 0x00 means try once, with no retries on failure. |
Sets the MxRtyPassiveActivation byte of the RFConfiguration register
maxRetries | 0xFF to wait forever, 0x00..0xFE to timeout after mxRetries |
bool readPassiveTargetID | ( | BAUD_T | cardbaudrate, |
uint8_t * | uid, | ||
uint8_t * | uidLength, | ||
uint16_t | timeout | ||
) |
waits for an ISO14443A target to enter the field
cardbaudbate | baud rate of the card, one of the BAUD_T values |
uid | Pointer to the array that will be populated with the cards UID, up to 7 bytes |
uidLength | Pointer to the variable that will hold the length of the card's UID. |
timeout | the number of milliseconds to wait |
Waits for an ISO14443A target to enter the field
cardBaudRate | Baud rate of the card |
uid | Pointer to the array that will be populated with the card's UID (up to 7 bytes) |
uidLength | Pointer to the variable that will hold the length of the card's UID. |
bool inDataExchange | ( | uint8_t * | send, |
uint8_t | sendLength, | ||
uint8_t * | response, | ||
uint8_t * | responseLength | ||
) |
exchanges an APDU (Application Protocol Data Unit) with the currently inlisted peer
send | Pointer to data to send |
sendLength | Length of the data to send |
response | Pointer to response data |
responseLength | Pointer to the response data length |
send | Pointer to data to send |
sendLength | Length of the data to send |
response | Pointer to response data |
responseLength | Pointer to the response data length |
bool inListPassiveTarget | ( | ) |
'InLists' a passive target. PN532 acting as reader/initiator, peer acting as card/responder.
bool mifareclassic_IsFirstBlock | ( | uint32_t | uiBlock | ) |
Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)
Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)
bool mifareclassic_IsTrailerBlock | ( | uint32_t | uiBlock | ) |
indicates whether the specified block number is the sector trailer
Indicates whether the specified block number is the sector trailer
bool mifareclassic_AuthenticateBlock | ( | uint8_t * | uid, |
uint8_t | uidLen, | ||
uint32_t | blockNumber, | ||
uint8_t | keyNumber, | ||
uint8_t * | keyData | ||
) |
tries to authenticate a block of memory on a MIFARE card using the INDATAEXCHANGE command. See section 7.3.8 of the PN532 User Manual for more information on sending MIFARE and other commands.
uid | Pointer to a byte array containing the card UID |
uidLen | The length (in bytes) of the card's UID (Should be 4 for MIFARE Classic) |
blockNumber | The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards). |
keyNumber | Which key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B) |
keyData | Pointer to a byte array containing the 6 byte key value |
Tries to authenticate a block of memory on a MIFARE card using the INDATAEXCHANGE command. See section 7.3.8 of the PN532 User Manual for more information on sending MIFARE and other commands.
uid | Pointer to a byte array containing the card UID |
uidLen | The length (in bytes) of the card's UID (Should be 4 for MIFARE Classic) |
blockNumber | The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards). |
keyNumber | Which key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B) |
keyData | Pointer to a byte array containing the 6 byte key value |
bool mifareclassic_ReadDataBlock | ( | uint8_t | blockNumber, |
uint8_t * | data | ||
) |
tries to read an entire 16-byte data block at the specified block address.
blockNumber | The block number to read (0..63 for 1KB cards, and 0..255 for 4KB cards). |
data | Pointer to the byte array that will hold the retrieved data (if any) |
Tries to read an entire 16-byte data block at the specified block address.
blockNumber | The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards). |
data | Pointer to the byte array that will hold the retrieved data (if any) |
bool mifareclassic_WriteDataBlock | ( | uint8_t | blockNumber, |
uint8_t * | data | ||
) |
tries to write an entire 16-byte data block at the specified block address.
blockNumber | The block number to write. (0..63 for 1KB cards, and 0..255 for 4KB cards). |
data | The byte array that contains the data to write. |
Tries to write an entire 16-byte data block at the specified block address.
blockNumber | The block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards). |
data | The byte array that contains the data to write. |
bool mifareclassic_FormatNDEF | ( | void | ) |
formats a Mifare Classic card to store NDEF Records
Formats a Mifare Classic card to store NDEF Records
bool mifareclassic_WriteNDEFURI | ( | uint8_t | sectorNumber, |
NDEF_URI_T | uriIdentifier, | ||
const char * | url | ||
) |
writes an NDEF URI Record to the specified sector (1..15)
Note that this function assumes that the Mifare Classic card is already formatted to work as an "NFC Forum Tag" and uses a MAD1 file system. You can use the NXP TagWriter app on Android to properly format cards for this.
sectorNumber | The sector that the URI record should be written to (can be 1..15 for a 1K card) |
uriIdentifier | The uri identifier code (one of the NDEF_URI_T values |
url | the uri text to write (max 38 characters). |
Writes an NDEF URI Record to the specified sector (1..15)
Note that this function assumes that the Mifare Classic card is already formatted to work as an "NFC Forum Tag" and uses a MAD1 file system. You can use the NXP TagWriter app on Android to properly format cards for this.
sectorNumber | The sector that the URI record should be written to (can be 1..15 for a 1K card) |
uriIdentifier | The uri identifier code (0 = none, 0x01 = "http://www.", etc.) |
url | The uri text to write (max 38 characters). |
bool ntag2xx_ReadPage | ( | uint8_t | page, |
uint8_t * | buffer | ||
) |
read an entire 4-byte page at the specified address
page | The page number (0..63 in most cases) |
buffer | Pointer to the byte array that will hold the retrieved data (if any) |
Tries to read an entire 4-byte page at the specified address.
page | The page number (0..63 in most cases) |
buffer | Pointer to the byte array that will hold the retrieved data (if any) |
bool ntag2xx_WritePage | ( | uint8_t | page, |
uint8_t * | data | ||
) |
write an entire 4-byte page at the specified block address
page | The page number to write. (0..63 for most cases) |
data | The byte array that contains the data to write. Should be exactly 4 bytes long. |
Tries to write an entire 4-byte page at the specified block address.
page | The page number to write. (0..63 for most cases) |
data | The byte array that contains the data to write. Should be exactly 4 bytes long. |
bool ntag2xx_WriteNDEFURI | ( | NDEF_URI_T | uriIdentifier, |
char * | url, | ||
uint8_t | dataLen | ||
) |
writes an NDEF URI Record starting at the specified page (4..nn)
Note that this function assumes that the NTAG2xx card is already formatted to work as an "NFC Forum Tag".
uriIdentifier | The uri identifier code (one of the NDEF_URI_T values |
url | The uri text to write (null-terminated string). |
dataLen | The size of the data area for overflow checks. |
Writes an NDEF URI Record starting at the specified page (4..nn)
Note that this function assumes that the NTAG2xx card is already formatted to work as an "NFC Forum Tag".
uriIdentifier | The uri identifier code (0 = none, 0x01 = "http://www.", etc.) |
url | The uri text to write (null-terminated string). |
dataLen | The size of the data area for overflow checks. |
|
inline |
return the ATQA (Answer to Request Acknowlege) value. This value is only valid after a successfull call to readPassiveTargetID()
|
inline |
return the SAK (Select Acknowlege) value. This value is only valid after a successfull call to readPassiveTargetID()
|
inline |
provide public access to the class's MRAA i2C context for direct user access
|
inline |
enable or disable debugging output for pn532 related operations
enable | true to enabloe debug output, false to disable |
|
inline |
enable or disable debugging output for mifare related operations
enable | true to enabloe debug output, false to disable |
PN532::TAG_TYPE_T tagType | ( | ) |
try to determine the tag type
|
protected |
timeout | Timeout before giving up |
|
protected |
buff | Pointer to the buffer where data will be written |
n | Number of bytes to be read |
|
protected |
cmd | Pointer to the command buffer |
cmdlen | Command length in bytes |