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:
Romain Tartiere 2010-09-03 16:45:24 +00:00
parent a5676ecd94
commit cbbe559f94
6 changed files with 20 additions and 73 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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