diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 617e31f..a4fa47a 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -742,3 +742,37 @@ bool pn53x_select_dep_target(nfc_device_t* pnd, const nfc_modulation_t nmInitMod } return true; } + +bool pn53x_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)]; + + pnd->iLastError = 0; + + 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; +} diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index ed2df50..7a6c19f 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -97,6 +97,7 @@ 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_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_transceive_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen); const char *pn53x_strerror (const nfc_device_t *pnd); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 7d9b42c..d7c2b05 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -63,7 +63,7 @@ nfc_device_desc_t * nfc_pick_device (void); // extern const byte_t pncmd_initiator_deselect [ 3]; // extern const byte_t pncmd_initiator_release [ 3]; // extern const byte_t pncmd_initiator_set_baud_rate [ 5]; -extern const byte_t pncmd_initiator_exchange_data [265]; +// extern const byte_t pncmd_initiator_exchange_data [265]; extern const byte_t pncmd_initiator_exchange_raw_data [266]; // extern const byte_t pncmd_initiator_auto_poll [ 5]; // @@ -552,36 +552,7 @@ bool nfc_initiator_transceive_bits(nfc_device_t* pnd, const byte_t* pbtTx, const */ bool nfc_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)]; - - pnd->iLastError = 0; - - 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; + return pn53x_transceive_dep_bytes(pnd, pbtTx, szTxLen, pbtRx, pszRxLen); } /**