upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Classes | Public Member Functions | List of all members

API for the PN532 based NFC/RFID reader/writer. More...

Detailed Description

Identify a card and print out basic info

Add a URI to an already NDEF formatted ultralight or NTAG2XX tag

Classes

class  BAUD_T
 
class  MIFARE_CMD_T
 
class  NDEF_URI_T
 
class  PN532_CMD_T
 
class  PN532_RSP_T
 
class  TAG_TYPE_T
 

Public Member Functions

synchronized void delete ()
 
 PN532 (int irq, int reset, int bus, short address)
 
 PN532 (int irq, int reset, int bus)
 
 PN532 (int irq, int reset)
 
boolean init ()
 
long getFirmwareVersion ()
 
boolean sendCommandCheckAck (byte[] cmd, short cmdlen, int timeout)
 
boolean sendCommandCheckAck (byte[] cmd, short cmdlen)
 
boolean SAMConfig ()
 
boolean setPassiveActivationRetries (short maxRetries)
 
boolean readPassiveTargetID (PN532.BAUD_T cardbaudrate, byte[] uid, short[] uidLength, int timeout)
 
boolean inDataExchange (byte[] send, short sendLength, byte[] response, short[] responseLength)
 
boolean inListPassiveTarget ()
 
boolean mifareclassic_IsFirstBlock (long uiBlock)
 
boolean mifareclassic_IsTrailerBlock (long uiBlock)
 
boolean mifareclassic_AuthenticateBlock (byte[] uid, short uidLen, long blockNumber, short keyNumber, byte[] keyData)
 
boolean mifareclassic_ReadDataBlock (short blockNumber, byte[] data)
 
boolean mifareclassic_WriteDataBlock (short blockNumber, byte[] data)
 
boolean mifareclassic_FormatNDEF ()
 
boolean mifareclassic_WriteNDEFURI (short sectorNumber, PN532.NDEF_URI_T uriIdentifier, String url)
 
boolean ntag2xx_ReadPage (short page, byte[] buffer)
 
boolean ntag2xx_WritePage (short page, byte[] data)
 
boolean ntag2xx_WriteNDEFURI (PN532.NDEF_URI_T uriIdentifier, String url, short dataLen)
 
int getATQA ()
 
short getSAK ()
 
void pn532Debug (boolean enable)
 
void mifareDebug (boolean enable)
 
PN532.TAG_TYPE_T tagType ()
 

Constructor & Destructor Documentation

PN532 ( int  irq,
int  reset,
int  bus,
short  address 
)

pn532 constructor

Parameters
irqpin to use for IRQ
resetreset pin
busi2c bus to use
addressthe address for this device

Member Function Documentation

int getATQA ( )

return the ATQA (Answer to Request Acknowlege) value. This value is only valid after a successfull call to readPassiveTargetID()

Returns
ATQA value
long getFirmwareVersion ( )

Checks the firmware version of the PN5xx chip

Returns
the chip's firmware version and ID
short getSAK ( )

return the SAK (Select Acknowlege) value. This value is only valid after a successfull call to readPassiveTargetID()

Returns
SAK value
boolean inDataExchange ( byte[]  send,
short  sendLength,
byte[]  response,
short[]  responseLength 
)

exchanges an APDU (Application Protocol Data Unit) with the currently inlisted peer

Parameters
sendPointer to data to send
sendLengthLength of the data to send
responsePointer to response data
responseLengthPointer to the response data length
Returns
true if everything executed properly, false for an error
boolean init ( )

set up initial values and start operation

Returns
true if successful
boolean inListPassiveTarget ( )

'InLists' a passive target. PN532 acting as reader/initiator, peer acting as card/responder.

Returns
true if everything executed properly, false for an error
boolean mifareclassic_AuthenticateBlock ( byte[]  uid,
short  uidLen,
long  blockNumber,
short  keyNumber,
byte[]  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.

Parameters
uidPointer to a byte array containing the card UID
uidLenThe length (in bytes) of the card's UID (Should be 4 for MIFARE Classic)
blockNumberThe block number to authenticate. (0..63 for 1KB cards, and 0..255 for 4KB cards).
keyNumberWhich key type to use during authentication (0 = MIFARE_CMD_AUTH_A, 1 = MIFARE_CMD_AUTH_B)
keyDataPointer to a byte array containing the 6 byte key value
Returns
true if everything executed properly, false for an error
boolean mifareclassic_IsFirstBlock ( long  uiBlock)

Indicates whether the specified block number is the first block in the sector (block 0 relative to the current sector)

Returns
true if it's the first block, false otherwise
boolean mifareclassic_IsTrailerBlock ( long  uiBlock)

indicates whether the specified block number is the sector trailer

Returns
true if it's the trailer block, false otherwise
boolean mifareclassic_ReadDataBlock ( short  blockNumber,
byte[]  data 
)

tries to read an entire 16-byte data block at the specified block address.

Parameters
blockNumberThe block number to read (0..63 for 1KB cards, and 0..255 for 4KB cards).
dataPointer to the byte array that will hold the retrieved data (if any)
Returns
true if everything executed properly, false for an error
boolean mifareclassic_WriteDataBlock ( short  blockNumber,
byte[]  data 
)

tries to write an entire 16-byte data block at the specified block address.

Parameters
blockNumberThe block number to write. (0..63 for 1KB cards, and 0..255 for 4KB cards).
dataThe byte array that contains the data to write.
Returns
true if everything executed properly, false for an error
boolean mifareclassic_WriteNDEFURI ( short  sectorNumber,
PN532.NDEF_URI_T  uriIdentifier,
String  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.

Parameters
sectorNumberThe sector that the URI record should be written to (can be 1..15 for a 1K card)
uriIdentifierThe uri identifier code (one of the NDEF_URI_T values
urlthe uri text to write (max 38 characters).
Returns
true if everything executed properly, false for an error
void mifareDebug ( boolean  enable)

enable or disable debugging output for mifare related operations

Parameters
enabletrue to enabloe debug output, false to disable
boolean ntag2xx_ReadPage ( short  page,
byte[]  buffer 
)

read an entire 4-byte page at the specified address

Parameters
pageThe page number (0..63 in most cases)
bufferPointer to the byte array that will hold the retrieved data (if any)
Returns
true if everything executed properly, false for an error
boolean ntag2xx_WriteNDEFURI ( PN532.NDEF_URI_T  uriIdentifier,
String  url,
short  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".

Parameters
uriIdentifierThe uri identifier code (one of the NDEF_URI_T values
urlThe uri text to write (null-terminated string).
dataLenThe size of the data area for overflow checks.
Returns
true if everything executed properly, false for an error
boolean ntag2xx_WritePage ( short  page,
byte[]  data 
)

write an entire 4-byte page at the specified block address

Parameters
pageThe page number to write. (0..63 for most cases)
dataThe byte array that contains the data to write. Should be exactly 4 bytes long.
Returns
true if everything executed properly, false for an error
void pn532Debug ( boolean  enable)

enable or disable debugging output for pn532 related operations

Parameters
enabletrue to enabloe debug output, false to disable
boolean readPassiveTargetID ( PN532.BAUD_T  cardbaudrate,
byte[]  uid,
short[]  uidLength,
int  timeout 
)

waits for an ISO14443A target to enter the field

Parameters
cardbaudbatebaud rate of the card, one of the BAUD_T values
uidPointer to the array that will be populated with the cards UID, up to 7 bytes
uidLengthPointer to the variable that will hold the length of the card's UID.
timeoutthe number of milliseconds to wait
Returns
true if everything executed properly, false for an error
boolean sendCommandCheckAck ( byte[]  cmd,
short  cmdlen,
int  timeout 
)

sends a command and waits a specified period for the ACK

Parameters
cmdPointer to the command buffer
cmdlenthe size of the command in bytes
timeouttimeout before giving up (in ms)
Returns
true if everything is OK, false if timeout occured before an ACK was recieved
boolean setPassiveActivationRetries ( short  maxRetries)

sets the MxRtyPassiveActivation byte of the RFConfiguration register. By default the pn532 will retry indefinitely.

Parameters
maxRetries0xFF to wait forever, 0x00..0xFE to timeout after maxRetries. 0x00 means try once, with no retries on failure.
Returns
true if everything executed properly, false for an error
PN532.TAG_TYPE_T tagType ( )

try to determine the tag type

Returns
one of the TAG_TYPE_T values

The documentation for this class was generated from the following file: