Alse remove nfc_target_receive_dep_bytes() and nfc_target_send_dep_bytes().
Update issue 106 Implement what's described in comment 3, 7 and 8.
This commit is contained in:
parent
a5676ecd94
commit
cbbe559f94
6 changed files with 20 additions and 73 deletions
|
@ -21,7 +21,7 @@ Changes:
|
|||
- API: new types: nfc_target_type_t and nfc_target_t
|
||||
- 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: nfc_initiator_transceive_dep_bytes(), nfc_target_receive_dep_bytes() and nfc_target_send_dep_bytes() have been removed (unset NDO_EASY_FRAMING instead of these functions)
|
||||
- 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
|
||||
|
|
|
@ -49,7 +49,7 @@ int main(int argc, const char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (!nfc_target_receive_dep_bytes(pnd, abtRecv, &szRecvBits)) {
|
||||
if (!nfc_target_receive_bytes(pnd, abtRecv, &szRecvBits)) {
|
||||
printf("unable to receive data\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ int main(int argc, const char *argv[])
|
|||
printf("Received: %s\n", abtRecv);
|
||||
printf("Sending : %s\n", send);
|
||||
|
||||
if (!nfc_target_send_dep_bytes(pnd, send, 11)) {
|
||||
if (!nfc_target_send_bytes(pnd, send, 11)) {
|
||||
printf("unable to send data\n");
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -73,10 +73,8 @@ NFC_EXPORT bool nfc_initiator_transceive_bytes(nfc_device_t* pnd, const byte_t*
|
|||
NFC_EXPORT bool nfc_target_init(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits);
|
||||
NFC_EXPORT bool nfc_target_receive_bits(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar);
|
||||
NFC_EXPORT bool nfc_target_receive_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen);
|
||||
NFC_EXPORT bool nfc_target_receive_dep_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen);
|
||||
NFC_EXPORT bool nfc_target_send_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar);
|
||||
NFC_EXPORT bool nfc_target_send_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen);
|
||||
NFC_EXPORT bool nfc_target_send_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen);
|
||||
|
||||
/* Error reporting */
|
||||
NFC_EXPORT const char *nfc_strerror (const nfc_device_t *pnd);
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#define snprintf sprintf_s
|
||||
#endif
|
||||
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
// PN53X configuration
|
||||
const byte_t pncmd_get_firmware_version [ 2] = { 0xD4,0x02 };
|
||||
const byte_t pncmd_get_general_status [ 2] = { 0xD4,0x04 };
|
||||
|
@ -852,43 +854,6 @@ bool pn53x_initiator_transceive_bytes(nfc_device_t* pnd, const byte_t* pbtTx, co
|
|||
return true;
|
||||
}
|
||||
|
||||
bool pn53x_target_receive_dep_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen)
|
||||
{
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
size_t szRxLen;
|
||||
|
||||
// Try to gather a received frame from the reader
|
||||
if (!pn53x_transceive(pnd,pncmd_target_get_data,2,abtRx,&szRxLen)) return false;
|
||||
|
||||
// Save the received byte count
|
||||
*pszRxLen = szRxLen-1;
|
||||
|
||||
// Copy the received bytes
|
||||
memcpy(pbtRx,abtRx+1,*pszRxLen);
|
||||
|
||||
// Everyting seems ok, return true
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pn53x_target_send_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen)
|
||||
{
|
||||
byte_t abtCmd[sizeof(pncmd_target_set_data)];
|
||||
|
||||
memcpy(abtCmd,pncmd_target_set_data,sizeof(pncmd_target_set_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);
|
||||
|
||||
// Try to send the bits to the reader
|
||||
if (!pn53x_transceive(pnd,abtCmd,szTxLen+2,NULL,NULL)) return false;
|
||||
|
||||
// Everyting seems ok, return true
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pn53x_target_init(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits)
|
||||
{
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
|
@ -980,11 +945,18 @@ bool pn53x_target_receive_bits(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBi
|
|||
|
||||
bool pn53x_target_receive_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen)
|
||||
{
|
||||
byte_t const *pbtTx;
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
size_t szRxLen;
|
||||
|
||||
if (pnd->bEasyFraming) {
|
||||
pbtTx = pncmd_target_get_data;
|
||||
} else {
|
||||
pbtTx = pncmd_target_receive;
|
||||
}
|
||||
|
||||
// Try to gather a received frame from the reader
|
||||
if (!pn53x_transceive(pnd,pncmd_target_receive,2,abtRx,&szRxLen)) return false;
|
||||
if (!pn53x_transceive(pnd,pbtTx,2,abtRx,&szRxLen)) return false;
|
||||
|
||||
// Save the received byte count
|
||||
*pszRxLen = szRxLen-1;
|
||||
|
@ -1035,13 +1007,18 @@ bool pn53x_target_send_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t
|
|||
|
||||
bool pn53x_target_send_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen)
|
||||
{
|
||||
byte_t abtCmd[sizeof(pncmd_target_send)];
|
||||
byte_t abtCmd[MAX(sizeof(pncmd_target_send), sizeof(pncmd_target_set_data))];
|
||||
|
||||
memcpy(abtCmd,pncmd_target_send,sizeof(pncmd_target_send));
|
||||
|
||||
// We can not just send bytes without parity if while the PN53X expects we handled them
|
||||
if (!pnd->bPar) return false;
|
||||
|
||||
if (pnd->bEasyFraming) {
|
||||
memcpy(abtCmd,pncmd_target_set_data,sizeof(pncmd_target_set_data));
|
||||
} else {
|
||||
memcpy(abtCmd,pncmd_target_send,sizeof(pncmd_target_send));
|
||||
}
|
||||
|
||||
// Copy the data into the command frame
|
||||
memcpy(abtCmd+2,pbtTx,szTxLen);
|
||||
|
||||
|
|
|
@ -100,8 +100,6 @@ bool pn53x_initiator_select_dep_target(nfc_device_t* pnd, const nfc_modulation_t
|
|||
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);
|
||||
|
||||
bool pn53x_target_receive_dep_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen);
|
||||
bool pn53x_target_send_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen);
|
||||
bool pn53x_target_init(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits);
|
||||
bool pn53x_target_receive_bits(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar);
|
||||
bool pn53x_target_receive_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen);
|
||||
|
|
26
libnfc/nfc.c
26
libnfc/nfc.c
|
@ -510,19 +510,6 @@ bool nfc_target_receive_bits(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits
|
|||
return pn53x_target_receive_bits (pnd, pbtRx, pszRxBits, pbtRxPar);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive data
|
||||
* @return Returns true if action was successfully performed; otherwise returns false.
|
||||
*
|
||||
* The main receive function that returns the received data from a nearby reader. The difference between this function and nfc_target_receive_bytes is that here pbtRx contains *only* the data received and not any additional commands, that is all handled internally by the PN53X.
|
||||
*/
|
||||
bool nfc_target_receive_dep_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_target_receive_dep_bytes (pnd, pbtRx, pszRxLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Receive bytes and APDU frames
|
||||
* @return Returns true if action was successfully performed; otherwise returns false.
|
||||
|
@ -563,19 +550,6 @@ bool nfc_target_send_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t
|
|||
return pn53x_target_send_bytes (pnd, pbtTx, szTxLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Send data
|
||||
* @return Returns true if action was successfully performed; otherwise returns false.
|
||||
*
|
||||
* To communicate data to the reader, this function could be used. The difference between this function and nfc_target_send_bytes is that here pbtTx contains *only* the data sent and not any additional commands, that is all handled internally by the PN53X.
|
||||
*/
|
||||
bool nfc_target_send_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_target_send_dep_bytes(pnd, pbtTx, szTxLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the PCD error string
|
||||
* @return Returns a string
|
||||
|
|
Loading…
Reference in a new issue