add timeout on nfc_target_init() and this function returns now received bytes count on success.
This commit is contained in:
parent
c80ebdca25
commit
239fd750c4
14 changed files with 22 additions and 21 deletions
|
|
@ -1589,7 +1589,7 @@ pn53x_initiator_deselect_target (struct nfc_device *pnd)
|
|||
#define SAK_ISO14443_4_COMPLIANT 0x20
|
||||
#define SAK_ISO18092_COMPLIANT 0x40
|
||||
int
|
||||
pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx)
|
||||
pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, int timeout)
|
||||
{
|
||||
pn53x_reset_settings(pnd);
|
||||
|
||||
|
|
@ -1742,7 +1742,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
|
|||
while (!targetActivated) {
|
||||
uint8_t btActivatedMode;
|
||||
|
||||
if((res = pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode)) < 0) {
|
||||
if((res = pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode, timeout)) < 0) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -1807,7 +1807,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
|
|||
}
|
||||
}
|
||||
|
||||
return NFC_SUCCESS;
|
||||
return *pszRx;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -2420,7 +2420,7 @@ pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm,
|
|||
const uint8_t *pbtTkt, size_t szTkt,
|
||||
const uint8_t *pbtFeliCaParams,
|
||||
const uint8_t *pbtNFCID3t, const uint8_t *pbtGBt, const size_t szGBt,
|
||||
uint8_t *pbtRx, size_t *pszRx, uint8_t *pbtModeByte)
|
||||
uint8_t *pbtRx, size_t *pszRx, uint8_t *pbtModeByte, int timeout)
|
||||
{
|
||||
uint8_t abtCmd[39 + 47 + 48] = { TgInitAsTarget }; // Worst case: 39-byte base, 47 bytes max. for General Bytes, 48 bytes max. for Historical Bytes
|
||||
size_t szOptionalBytes = 0;
|
||||
|
|
@ -2469,7 +2469,7 @@ pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm,
|
|||
// Request the initialization as a target
|
||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||
size_t szRx = sizeof (abtRx);
|
||||
if ((res = pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, -1)) < 0)
|
||||
if ((res = pn53x_transceive (pnd, abtCmd, 36 + szOptionalBytes, abtRx, &szRx, timeout)) < 0)
|
||||
return res;
|
||||
|
||||
// Note: the first byte is skip:
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ int pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const uin
|
|||
int pn53x_initiator_deselect_target (struct nfc_device *pnd);
|
||||
|
||||
// NFC device as Target functions
|
||||
int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx);
|
||||
int pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx, int timeout);
|
||||
int pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar);
|
||||
int pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout);
|
||||
int pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);
|
||||
|
|
@ -342,7 +342,7 @@ int pn53x_TgInitAsTarget (struct nfc_device *pnd, pn53x_target_mode ptm,
|
|||
const uint8_t *pbtTkt, size_t szTkt,
|
||||
const uint8_t *pbtFeliCaParams,
|
||||
const uint8_t *pbtNFCID3t, const uint8_t *pbtGB, const size_t szGB,
|
||||
uint8_t *pbtRx, size_t *pszRx, uint8_t *pbtModeByte);
|
||||
uint8_t *pbtRx, size_t *pszRx, uint8_t *pbtModeByte, int timeout);
|
||||
|
||||
// RFConfiguration
|
||||
int pn53x_RFConfiguration__RF_field (struct nfc_device *pnd, bool bEnable);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ nfc_emulate_target (nfc_device *pnd, struct nfc_emulator *emulator)
|
|||
uint8_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN];
|
||||
int res = 0;
|
||||
|
||||
if (nfc_target_init (pnd, emulator->target, abtRx, &szRx) < 0) {
|
||||
if (nfc_target_init (pnd, emulator->target, abtRx, &szRx, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ struct nfc_driver_t {
|
|||
int (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, uint32_t * cycles);
|
||||
int (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, uint8_t * pbtRxPar, uint32_t * cycles);
|
||||
|
||||
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx);
|
||||
int (*target_init) (struct nfc_device *pnd, nfc_target * pnt, uint8_t * pbtRx, size_t * pszRx, int timeout);
|
||||
int (*target_send_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, int timeout);
|
||||
int (*target_receive_bytes) (struct nfc_device *pnd, uint8_t * pbtRx, size_t * pszRx, int timeout);
|
||||
int (*target_send_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);
|
||||
|
|
|
|||
|
|
@ -599,7 +599,7 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
|||
|
||||
/**
|
||||
* @brief Initialize NFC device as an emulated tag
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code
|
||||
* @return Returns received bytes count on success, otherwise returns libnfc's error code
|
||||
*
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param ntm target mode restriction that you want to emulate (eg. NTM_PASSIVE_ONLY)
|
||||
|
|
@ -610,6 +610,7 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
|||
*
|
||||
* @param[out] pbtRx Rx buffer pointer
|
||||
* @param[out] pszRx received bytes count
|
||||
* @param timeout in milliseconds
|
||||
*
|
||||
* This function initializes NFC device in \e target mode in order to emulate a
|
||||
* tag using the specified \a nfc_target_mode_t.
|
||||
|
|
@ -628,7 +629,7 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
|||
* receive functions can be used.
|
||||
*/
|
||||
int
|
||||
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszRx)
|
||||
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszRx, int timeout)
|
||||
{
|
||||
int res = 0;
|
||||
// Disallow invalid frame
|
||||
|
|
@ -655,7 +656,7 @@ nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszR
|
|||
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false)) < 0)
|
||||
return res;
|
||||
|
||||
HAL (target_init, pnd, pnt, pbtRx, pszRx);
|
||||
HAL (target_init, pnd, pnt, pbtRx, pszRx, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue