diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 9e62509..4d87474 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -622,8 +622,6 @@ pn53x_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool bEn byte_t btValue; byte_t abtCmd[sizeof(pncmd_rf_configure)]; - pnd->iLastError = 0; - memcpy(abtCmd,pncmd_rf_configure,sizeof(pncmd_rf_configure)); // Make sure we are dealing with a active device @@ -698,8 +696,6 @@ bool pn53x_initiator_select_dep_target(nfc_device_t* pnd, const nfc_modulation_t size_t offset; byte_t abtCmd[sizeof(pncmd_initiator_jump_for_dep)]; - pnd->iLastError = 0; - memcpy(abtCmd,pncmd_initiator_jump_for_dep,sizeof(pncmd_initiator_jump_for_dep)); if(nmInitModulation == NM_ACTIVE_DEP) { @@ -749,8 +745,6 @@ bool pn53x_initiator_transceive_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx 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 @@ -786,8 +780,6 @@ bool pn53x_initiator_transceive_bits(nfc_device_t* pnd, const byte_t* pbtTx, con uint8_t ui8Bits = 0; byte_t abtCmd[sizeof(pncmd_initiator_exchange_raw_data)]; - pnd->iLastError = 0; - memcpy(abtCmd,pncmd_initiator_exchange_raw_data,sizeof(pncmd_initiator_exchange_raw_data)); // Check if we should prepare the parity bits ourself @@ -844,8 +836,6 @@ bool pn53x_initiator_transceive_bytes(nfc_device_t* pnd, const byte_t* pbtTx, co size_t szRxLen; byte_t abtCmd[sizeof(pncmd_initiator_exchange_raw_data)]; - pnd->iLastError = 0; - 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 @@ -876,9 +866,6 @@ bool pn53x_target_receive_dep_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* ps byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; - pnd->iLastError = 0; - - // Try to gather a received frame from the reader if (!pn53x_transceive(pnd,pncmd_target_get_data,2,abtRx,&szRxLen)) return false; @@ -896,8 +883,6 @@ bool pn53x_target_send_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const s { byte_t abtCmd[sizeof(pncmd_target_set_data)]; - pnd->iLastError = 0; - 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 @@ -923,8 +908,6 @@ bool pn53x_target_init(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits) bool bPar = pnd->bPar; byte_t abtCmd[sizeof(pncmd_target_init)]; - pnd->iLastError = 0; - memcpy(abtCmd,pncmd_target_init,sizeof(pncmd_target_init)); // Clear the target init struct, reset to all zeros @@ -975,9 +958,6 @@ bool pn53x_target_receive_bits(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBi size_t szFrameBits; uint8_t ui8Bits; - pnd->iLastError = 0; - - // Try to gather a received frame from the reader if (!pn53x_transceive(pnd,pncmd_target_receive,2,abtRx,&szRxLen)) return false; @@ -1008,9 +988,6 @@ bool pn53x_target_receive_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxL byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; - pnd->iLastError = 0; - - // Try to gather a received frame from the reader if (!pn53x_transceive(pnd,pncmd_target_receive,2,abtRx,&szRxLen)) return false; @@ -1031,8 +1008,6 @@ bool pn53x_target_send_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t uint8_t ui8Bits = 0; byte_t abtCmd[sizeof(pncmd_target_send)]; - pnd->iLastError = 0; - memcpy(abtCmd,pncmd_target_send,sizeof(pncmd_target_send)); // Check if we should prepare the parity bits ourself @@ -1067,8 +1042,6 @@ bool pn53x_target_send_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_ { byte_t abtCmd[sizeof(pncmd_target_send)]; - pnd->iLastError = 0; - 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 diff --git a/libnfc/nfc.c b/libnfc/nfc.c index d563eaf..73c57b2 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -238,6 +238,8 @@ void nfc_disconnect(nfc_device_t* pnd) */ bool nfc_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool bEnable) { + pnd->iLastError = 0; + return pn53x_configure(pnd, ndo, bEnable); } @@ -253,7 +255,6 @@ bool nfc_configure(nfc_device_t* pnd, const nfc_device_option_t ndo, const bool */ bool nfc_initiator_init(nfc_device_t* pnd) { - pnd->iLastError = 0; // Make sure we are dealing with a active device @@ -286,6 +287,8 @@ bool nfc_initiator_init(nfc_device_t* pnd) */ bool nfc_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) { + pnd->iLastError = 0; + return pn53x_initiator_select_dep_target(pnd, nmInitModulation, pbtPidData, szPidDataLen, pbtNFCID3i, szNFCID3iDataLen, pbtGbData, szGbDataLen, pnti); } @@ -317,7 +320,6 @@ nfc_initiator_select_passive_target(nfc_device_t* pnd, pnd->iLastError = 0; - // Make sure we are dealing with a active device if (!pnd->bActive) return false; // TODO Put this in a function @@ -412,7 +414,6 @@ nfc_initiator_list_passive_targets(nfc_device_t* pnd, const nfc_modulation_t nmI pnd->iLastError = 0; - // Let the reader only try once to find a target nfc_configure (pnd, NDO_INFINITE_SELECT, false); @@ -443,7 +444,6 @@ nfc_initiator_list_passive_targets(nfc_device_t* pnd, const nfc_modulation_t nmI */ bool nfc_initiator_deselect_target(nfc_device_t* pnd) { - pnd->iLastError = 0; return (pn53x_InDeselect(pnd, 0)); // 0 mean deselect all selected targets @@ -485,6 +485,8 @@ nfc_initiator_poll_targets(nfc_device_t* pnd, */ 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) { + pnd->iLastError = 0; + return pn53x_initiator_transceive_bits (pnd, pbtTx, szTxBits, pbtTxPar, pbtRx, pszRxBits, pbtRxPar); } @@ -496,6 +498,8 @@ 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) { + pnd->iLastError = 0; + return pn53x_initiator_transceive_dep_bytes(pnd, pbtTx, szTxLen, pbtRx, pszRxLen); } @@ -514,6 +518,8 @@ bool nfc_initiator_transceive_dep_bytes(nfc_device_t* pnd, const byte_t* pbtTx, */ bool nfc_initiator_transceive_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_bytes (pnd, pbtTx, szTxLen, pbtRx, pszRxLen); } @@ -527,6 +533,8 @@ bool nfc_initiator_transceive_bytes(nfc_device_t* pnd, const byte_t* pbtTx, cons */ bool nfc_target_init(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits) { + pnd->iLastError = 0; + return pn53x_target_init(pnd, pbtRx, pszRxBits); } @@ -538,6 +546,8 @@ bool nfc_target_init(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits) */ bool nfc_target_receive_bits(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits, byte_t* pbtRxPar) { + pnd->iLastError = 0; + return pn53x_target_receive_bits (pnd, pbtRx, pszRxBits, pbtRxPar); } @@ -549,6 +559,8 @@ bool nfc_target_receive_bits(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxBits */ 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); } @@ -560,6 +572,8 @@ bool nfc_target_receive_dep_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszR */ bool nfc_target_receive_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen) { + pnd->iLastError = 0; + return pn53x_target_receive_bytes(pnd, pbtRx, pszRxLen); } @@ -571,6 +585,8 @@ bool nfc_target_receive_bytes(nfc_device_t* pnd, byte_t* pbtRx, size_t* pszRxLen */ bool nfc_target_send_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxBits, const byte_t* pbtTxPar) { + pnd->iLastError = 0; + return pn53x_target_send_bits(pnd, pbtTx, szTxBits, pbtTxPar); } @@ -583,6 +599,8 @@ bool nfc_target_send_bits(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s */ bool nfc_target_send_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t szTxLen) { + pnd->iLastError = 0; + return pn53x_target_send_bytes (pnd, pbtTx, szTxLen); } @@ -594,6 +612,8 @@ bool nfc_target_send_bytes(nfc_device_t* pnd, const byte_t* pbtTx, const size_t */ 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); }