Remove nfc_initiator_transceive_dep_bytes() and introduce NDO_EASY_FRAMING option.
Always use nfc_initiator_transceive_bytes(). If you where using advanced features and already relying on nfc_initiator_transceive_bytes(), then your code has to be updated to unset the NDO_EASY_FRAMING option. See an example of such a change in the libfreefare's repository: http://code.google.com/p/nfc-tools/source/detail?r=566 Updates issue 106 Status: Feedback Romuald: I am not sure about the option enum values. I took 0x02 thinking it would not hurt but am not really sure about that because I can see many 'holes' in the sequence.
This commit is contained in:
parent
b1f4c38f8f
commit
a5676ecd94
9 changed files with 34 additions and 57 deletions
|
@ -9,7 +9,7 @@ Fixes:
|
|||
Improvments:
|
||||
- libnfc: rearrange source code
|
||||
- libnfc: enhance documentation
|
||||
- libnfc: add regression tests (not much as expected but its here!)
|
||||
- libnfc: add regression tests (not as much as expected but its here!)
|
||||
- build: configure script now supports --with-drivers option instead of --disable-pcsclite and --disable-libusb (see --help)
|
||||
- nfc-mfultralight: we now can write OTP bytes if user want to
|
||||
|
||||
|
@ -19,7 +19,9 @@ Changes:
|
|||
- API: new function nfc_initiator_list_passive_targets() to list available targets in field
|
||||
- API: new nfc_perror(), nfc_strerror() and nfc_strerror_r() functions to handle errors
|
||||
- API: new types: nfc_target_type_t and nfc_target_t
|
||||
- API: add configuration option to enable/disable auto iso14443-4 mode.
|
||||
- API: new configuration option NDO_AUTO_ISO14443_4 to enable/disable auto iso14443-4 mode.
|
||||
- API: new configuration option NDO_EASY_FRAMING to enable/disable auto frames encapsulation and chaining
|
||||
- API: nfc_initiator_transceive_dep_bytes() has been removed (use NDO_EASY_FRAMING instead)
|
||||
- API: (experimental) new nfc_initiator_poll_targets() which allow to use hardware polling function
|
||||
- examples: add draft of a new example: nfc-sam. It tests the comunication with a connected SAM (Secure Access Module)
|
||||
- examples: add new example to show how to use new polling function
|
||||
|
|
|
@ -66,8 +66,8 @@ bool nfc_initiator_mifare_cmd(nfc_device_t* pnd, const mifare_cmd mc, const uint
|
|||
if (szParamLen) memcpy(abtCmd+2,(byte_t*)pmp,szParamLen);
|
||||
|
||||
// Fire the mifare command
|
||||
if (!nfc_initiator_transceive_dep_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) {
|
||||
nfc_perror (pnd, "nfc_initiator_transceive_dep_bytes");
|
||||
if (!nfc_initiator_transceive_bytes(pnd,abtCmd,2+szParamLen,abtRx,&szRxLen)) {
|
||||
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,11 @@ int main(int argc,char* argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!nfc_configure(pnd, NDO_EASY_FRAMING, false)) {
|
||||
nfc_perror (pnd, "nfc_configure");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("\nConnected to NFC reader: %s\n\n",pnd->acName);
|
||||
|
||||
// Send the 7 bits request command specified in ISO 14443A (0x26)
|
||||
|
|
|
@ -55,7 +55,7 @@ int main(int argc, const char *argv[])
|
|||
}
|
||||
|
||||
printf("Sending : %s\n", send);
|
||||
if (!nfc_initiator_transceive_dep_bytes(pnd,
|
||||
if (!nfc_initiator_transceive_bytes(pnd,
|
||||
send,
|
||||
strlen((char*)send), abtRecv,
|
||||
&szRecvBits)) {
|
||||
|
|
|
@ -67,6 +67,8 @@ typedef struct {
|
|||
bool bCrc;
|
||||
/** Does the PN53x chip handles parity bits, all parities are handled as data */
|
||||
bool bPar;
|
||||
/** Should the PN53x chip handle frames encapsulation and chaining */
|
||||
bool bEasyFraming;
|
||||
/** The last tx bits setting, we need to reset this if it does not apply anymore */
|
||||
uint8_t ui8TxBits;
|
||||
/** Last error reported by the PCD / encountered by the PCD driver
|
||||
|
@ -142,6 +144,8 @@ typedef enum {
|
|||
NDO_HANDLE_CRC = 0x00,
|
||||
/** Parity bits in the network layer of ISO14443-A are by default generated and validated in the PN53X chip. This is a very convenient feature. On certain times though it is useful to get full control of the transmitted data. The proprietary MIFARE Classic protocol uses for example custom (encrypted) parity bits. For interoperability it is required to be completely compatible, including the arbitrary parity bits. When this option is disabled, the functions to communicating bits should be used. */
|
||||
NDO_HANDLE_PARITY = 0x01,
|
||||
/** Use automatic frames encapsulation and chaining. */
|
||||
NDO_EASY_FRAMING = 0x02,
|
||||
/** This option can be used to enable or disable the electronic field of the NFC device. */
|
||||
NDO_ACTIVATE_FIELD = 0x10,
|
||||
/** The internal CRYPTO1 co-processor can be used to transmit messages encrypted. This option is automatically activated after a successful MIFARE Classic authentication. */
|
||||
|
|
|
@ -68,7 +68,6 @@ NFC_EXPORT bool nfc_initiator_select_dep_target(nfc_device_t* pnd, const nfc_mod
|
|||
NFC_EXPORT bool nfc_initiator_deselect_target(nfc_device_t* pnd);
|
||||
NFC_EXPORT bool nfc_initiator_transceive_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar);
|
||||
NFC_EXPORT bool nfc_initiator_transceive_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
NFC_EXPORT bool nfc_initiator_transceive_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
|
||||
/* NFC target: act as tag (i.e. MIFARE Classic) or NFC target device. */
|
||||
NFC_EXPORT bool nfc_target_init(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits);
|
||||
|
|
|
@ -654,6 +654,10 @@ pn53x_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool bEn
|
|||
pnd->bPar = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_EASY_FRAMING:
|
||||
pnd->bEasyFraming = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_ACTIVATE_FIELD:
|
||||
abtCmd[2] = RFCI_FIELD;
|
||||
abtCmd[3] = (bEnable) ? 1 : 0;
|
||||
|
@ -748,38 +752,6 @@ bool pn53x_initiator_select_dep_target(nfc_device_t* pnd, const nfc_modulation_t
|
|||
return true;
|
||||
}
|
||||
|
||||
bool pn53x_initiator_transceive_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
{
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
size_t szRxLen;
|
||||
byte_t abtCmd[sizeof(pncmd_initiator_exchange_data)];
|
||||
|
||||
memcpy(abtCmd,pncmd_initiator_exchange_data,sizeof(pncmd_initiator_exchange_data));
|
||||
|
||||
// We can not just send bytes without parity if while the PN53X expects we handled them
|
||||
if (!pnd->bPar) return false;
|
||||
|
||||
// Copy the data into the command frame
|
||||
abtCmd[2] = 1; /* target number */
|
||||
memcpy(abtCmd+3,pbtTx,szTxLen);
|
||||
|
||||
// To transfer command frames bytes we can not have any leading bits, reset this to zero
|
||||
if (!pn53x_set_tx_bits(pnd,0)) return false;
|
||||
|
||||
// Send the frame to the PN53X chip and get the answer
|
||||
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x40)
|
||||
if (!pn53x_transceive(pnd,abtCmd,szTxLen+3,abtRx,&szRxLen)) return false;
|
||||
|
||||
// Save the received byte count
|
||||
*pszRxLen = szRxLen-1;
|
||||
|
||||
// Copy the received bytes
|
||||
memcpy(pbtRx,abtRx+1,*pszRxLen);
|
||||
|
||||
// Everything went successful
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pn53x_initiator_transceive_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar)
|
||||
{
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
|
@ -845,23 +817,30 @@ bool pn53x_initiator_transceive_bits(nfc_device_t* pnd, const byte_t* pbtTx, con
|
|||
bool pn53x_initiator_transceive_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
{
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
size_t szRxLen;
|
||||
size_t szExtraTxLen, szRxLen;
|
||||
byte_t abtCmd[sizeof(pncmd_initiator_exchange_raw_data)];
|
||||
|
||||
memcpy(abtCmd,pncmd_initiator_exchange_raw_data,sizeof(pncmd_initiator_exchange_raw_data));
|
||||
|
||||
// We can not just send bytes without parity if while the PN53X expects we handled them
|
||||
if (!pnd->bPar) return false;
|
||||
|
||||
// Copy the data into the command frame
|
||||
memcpy(abtCmd+2,pbtTx,szTxLen);
|
||||
if (pnd->bEasyFraming) {
|
||||
memcpy(abtCmd,pncmd_initiator_exchange_data,sizeof(pncmd_initiator_exchange_data));
|
||||
abtCmd[2] = 1; /* target number */
|
||||
memcpy(abtCmd+3,pbtTx,szTxLen);
|
||||
szExtraTxLen = 3;
|
||||
} else {
|
||||
memcpy(abtCmd,pncmd_initiator_exchange_raw_data,sizeof(pncmd_initiator_exchange_raw_data));
|
||||
memcpy(abtCmd+2,pbtTx,szTxLen);
|
||||
szExtraTxLen = 2;
|
||||
}
|
||||
|
||||
// To transfer command frames bytes we can not have any leading bits, reset this to zero
|
||||
if (!pn53x_set_tx_bits(pnd,0)) return false;
|
||||
|
||||
// Send the frame to the PN53X chip and get the answer
|
||||
// We have to give the amount of bytes + (the two command bytes 0xD4, 0x42)
|
||||
if (!pn53x_transceive(pnd,abtCmd,szTxLen+2,abtRx,&szRxLen)) return false;
|
||||
if (!pn53x_transceive(pnd,abtCmd,szTxLen + szExtraTxLen,abtRx,&szRxLen)) return false;
|
||||
|
||||
// Save the received byte count
|
||||
*pszRxLen = szRxLen-1;
|
||||
|
|
|
@ -97,7 +97,6 @@ bool pn53x_InAutoPoll(nfc_device_t* pnd, const nfc_target_type_t* pnttTargetType
|
|||
bool pn53x_get_firmware_version (nfc_device_t *pnd);
|
||||
bool pn53x_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool bEnable);
|
||||
bool pn53x_initiator_select_dep_target(nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, const byte_t* pbtPidData, const size_t szPidDataLen, const byte_t* pbtNFCID3i, const size_t szNFCID3iDataLen, const byte_t *pbtGbData, const size_t szGbDataLen, nfc_target_info_t* pnti);
|
||||
bool pn53x_initiator_transceive_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
bool pn53x_initiator_transceive_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar);
|
||||
bool pn53x_initiator_transceive_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||
|
||||
|
|
15
libnfc/nfc.c
15
libnfc/nfc.c
|
@ -236,6 +236,8 @@ bool nfc_initiator_init(nfc_device_t* pnd)
|
|||
// Configure the PN53X to be an Initiator or Reader/Writer
|
||||
if (!pn53x_set_reg(pnd,REG_CIU_CONTROL,SYMBOL_INITIATOR,0x10)) return false;
|
||||
|
||||
nfc_configure (pnd, NDO_EASY_FRAMING, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -460,19 +462,6 @@ bool nfc_initiator_transceive_bits(nfc_device_t* pnd, const byte_t* pbtTx, const
|
|||
return pn53x_initiator_transceive_bits (pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transceive data
|
||||
* @return Returns true if action was successfully performed; otherwise returns false.
|
||||
*
|
||||
* The reader will transmit the supplied (data) bytes in pbtTx to the target (tag). It waits for the response and stores the received bytes in the pbtRx byte array. The difference between this function and nfc_initiator_transceive_bytes is that here pbtTx and pbtRx contain *only* the data sent and received and not any additional commands, that is all handled internally by the PN53X.
|
||||
*/
|
||||
bool nfc_initiator_transceive_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_initiator_transceive_dep_bytes(pnd, pbtTx, szTxLen, pbtRx, pszRxLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send raw data to target then retrieve raw data from target
|
||||
* @return Returns true if action was successfully performed; otherwise returns false.
|
||||
|
|
Loading…
Reference in a new issue