nfc_target_init() function returns now 0 on succes and libnfc error code on failure.

This commit is contained in:
Audrey Diacre 2011-12-19 15:35:37 +00:00
parent 145cc4b2ad
commit ba2a7cfe2e
14 changed files with 36 additions and 36 deletions

View file

@ -1534,7 +1534,7 @@ pn53x_initiator_deselect_target (struct nfc_device *pnd)
#define SAK_ISO14443_4_COMPLIANT 0x20
#define SAK_ISO18092_COMPLIANT 0x40
bool
int
pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *pszRx)
{
pn53x_reset_settings(pnd);
@ -1548,7 +1548,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
ptm = PTM_PASSIVE_ONLY;
if ((pnt->nti.nai.abtUid[0] != 0x08) || (pnt->nti.nai.szUidLen != 4)) {
pnd->last_error = NFC_EINVARG;
return false;
return pnd->last_error;
}
pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, false);
if (CHIP_DATA(pnd)->type == PN532) { // We have a PN532
@ -1577,13 +1577,13 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
case NMT_ISO14443B2CT:
case NMT_JEWEL:
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
return pnd->last_error;
break;
}
// Let the PN53X be activated by the RF level detector from power down mode
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxAuto, SYMBOL_INITIAL_RF_ON, 0x04))
return false;
return NFC_ECHIP;
uint8_t abtMifareParams[6];
uint8_t *pbtMifareParams = NULL;
@ -1679,7 +1679,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
case NMT_ISO14443B2CT:
case NMT_JEWEL:
pnd->last_error = NFC_EDEVNOTSUPP;
return false;
return pnd->last_error;
break;
}
@ -1688,7 +1688,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
uint8_t btActivatedMode;
if(!pn53x_TgInitAsTarget(pnd, ptm, pbtMifareParams, pbtTkt, szTkt, pbtFeliCaParams, pbtNFCID3t, pbtGBt, szGBt, pbtRx, pszRx, &btActivatedMode)) {
return false;
return NFC_ECHIP;
}
nfc_modulation nm = {
@ -1752,7 +1752,7 @@ pn53x_target_init (struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size
}
}
return true;
return NFC_SUCCESS;
}
bool

View file

@ -312,7 +312,7 @@ bool pn53x_initiator_transceive_bytes_timed (struct nfc_device *pnd, const ui
bool pn53x_initiator_deselect_target (struct nfc_device *pnd);
// NFC device as Target functions
bool 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);
bool pn53x_target_receive_bits (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar);
bool pn53x_target_receive_bytes (struct nfc_device *pnd, uint8_t *pbtRx, size_t *pszRx, int timeout);
bool pn53x_target_send_bits (struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar);

View file

@ -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)) {
if (nfc_target_init (pnd, emulator->target, abtRx, &szRx) < 0) {
return -1;
}

View file

@ -142,7 +142,7 @@ struct nfc_driver_t {
bool (*initiator_transceive_bytes_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, uint32_t * cycles);
bool (*initiator_transceive_bits_timed) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar, uint32_t * cycles);
bool (*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);
bool (*target_send_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, int timeout);
bool (*target_receive_bytes) (struct nfc_device *pnd, uint8_t * pbtRx, size_t * pszRx, int timeout);
bool (*target_send_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);

View file

@ -601,7 +601,7 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
/**
* @brief Initialize NFC device as an emulated tag
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
* @return Returns 0 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)
@ -629,31 +629,32 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
* example would wake up the emulator. After this is received, the send and
* receive functions can be used.
*/
bool
int
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszRx)
{
int res = 0;
// Disallow invalid frame
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false)) < 0)
return false;
// Disallow multiple frames
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false)) < 0)
return false;
// Make sure we reset the CRC and parity to chip handling.
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true)) < 0)
return false;
if (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true)) < 0)
return false;
// Activate auto ISO14443-4 switching by default
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true)) < 0)
return false;
// Activate "easy framing" feature by default
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true)) < 0)
return false;
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false)) < 0)
return false;
// Drop explicitely the field
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false) < 0)
if ((res = nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false)) < 0)
return false;
HAL (target_init, pnd, pnt, pbtRx, pszRx);