New nfc_initiator_init_secure_element() function to set SAM as wired card (only relevant with a PN532 SAM-equipped)
This commit is contained in:
parent
6f10d6e321
commit
b4ef1a3a5d
14 changed files with 84 additions and 34 deletions
|
|
@ -998,7 +998,12 @@ int
|
|||
pn53x_initiator_init(struct nfc_device *pnd)
|
||||
{
|
||||
pn53x_reset_settings(pnd);
|
||||
int res = 0;
|
||||
int res;
|
||||
if (CHIP_DATA(pnd)->sam_mode != PSM_NORMAL) {
|
||||
if ((res = pn532_SAMConfiguration(pnd, PSM_NORMAL, -1)) < 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
// Configure the PN53X to be an Initiator or Reader/Writer
|
||||
if ((res = pn53x_write_register(pnd, PN53X_REG_CIU_Control, SYMBOL_INITIATOR, 0x10)) < 0)
|
||||
|
|
@ -1008,6 +1013,12 @@ pn53x_initiator_init(struct nfc_device *pnd)
|
|||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
pn532_initiator_init_secure_element(struct nfc_device *pnd)
|
||||
{
|
||||
return pn532_SAMConfiguration(pnd, PSM_WIRED_CARD, -1);
|
||||
}
|
||||
|
||||
static int
|
||||
pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
|
|
@ -2204,9 +2215,9 @@ pn53x_SetParameters(struct nfc_device *pnd, const uint8_t ui8Value)
|
|||
}
|
||||
|
||||
int
|
||||
pn53x_SAMConfiguration(struct nfc_device *pnd, const pn532_sam_mode ui8Mode, int timeout)
|
||||
pn532_SAMConfiguration(struct nfc_device *pnd, const pn532_sam_mode sam_mode, int timeout)
|
||||
{
|
||||
uint8_t abtCmd[] = { SAMConfiguration, ui8Mode, 0x00, 0x00 };
|
||||
uint8_t abtCmd[] = { SAMConfiguration, sam_mode, 0x00, 0x00 };
|
||||
size_t szCmd = sizeof(abtCmd);
|
||||
|
||||
if (CHIP_DATA(pnd)->type != PN532) {
|
||||
|
|
@ -2215,12 +2226,12 @@ pn53x_SAMConfiguration(struct nfc_device *pnd, const pn532_sam_mode ui8Mode, int
|
|||
return pnd->last_error;
|
||||
}
|
||||
|
||||
switch (ui8Mode) {
|
||||
switch (sam_mode) {
|
||||
case PSM_NORMAL: // Normal mode
|
||||
case PSM_WIRED_CARD: // Wired card mode
|
||||
szCmd = 2;
|
||||
break;
|
||||
case PSM_VIRTUAL_CARD: // Virtual card mode
|
||||
case PSM_WIRED_CARD: // Wired card mode
|
||||
case PSM_DUAL_CARD: // Dual card mode
|
||||
// TODO Implement timeout handling
|
||||
szCmd = 3;
|
||||
|
|
@ -2229,6 +2240,7 @@ pn53x_SAMConfiguration(struct nfc_device *pnd, const pn532_sam_mode ui8Mode, int
|
|||
pnd->last_error = NFC_EINVARG;
|
||||
return pnd->last_error;
|
||||
}
|
||||
CHIP_DATA(pnd)->sam_mode = sam_mode;
|
||||
return (pn53x_transceive(pnd, abtCmd, szCmd, NULL, 0, timeout));
|
||||
}
|
||||
|
||||
|
|
@ -3080,6 +3092,9 @@ pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io)
|
|||
// Set current target to NULL
|
||||
CHIP_DATA(pnd)->current_target = NULL;
|
||||
|
||||
// Set current sam_mode to normal mode
|
||||
CHIP_DATA(pnd)->sam_mode = PSM_NORMAL;
|
||||
|
||||
// WriteBack cache is clean
|
||||
CHIP_DATA(pnd)->wb_trigged = false;
|
||||
memset(CHIP_DATA(pnd)->wb_mask, 0x00, PN53X_CACHE_REGISTER_SIZE);
|
||||
|
|
|
|||
|
|
@ -134,6 +134,17 @@ typedef enum {
|
|||
TARGET,
|
||||
} pn53x_operating_mode;
|
||||
|
||||
/**
|
||||
* @enum pn532_sam_mode
|
||||
* @brief PN532 SAM mode enumeration
|
||||
*/
|
||||
typedef enum {
|
||||
PSM_NORMAL = 0x01,
|
||||
PSM_VIRTUAL_CARD = 0x02,
|
||||
PSM_WIRED_CARD = 0x03,
|
||||
PSM_DUAL_CARD = 0x04
|
||||
} pn532_sam_mode;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @struct pn53x_io
|
||||
|
|
@ -165,6 +176,8 @@ struct pn53x_data {
|
|||
pn53x_operating_mode operating_mode;
|
||||
/** Current emulated target */
|
||||
nfc_target *current_target;
|
||||
/** Current sam mode (only applicable for PN532) */
|
||||
pn532_sam_mode sam_mode;
|
||||
/** PN53x I/O functions stored in struct */
|
||||
const struct pn53x_io *io;
|
||||
/** Last status byte returned by PN53x */
|
||||
|
|
@ -262,17 +275,6 @@ typedef enum {
|
|||
PTT_DEP_ACTIVE_424 = 0x82,
|
||||
} pn53x_target_type;
|
||||
|
||||
/**
|
||||
* @enum pn532_sam_mode
|
||||
* @brief PN53x SAM mode enumeration
|
||||
*/
|
||||
typedef enum {
|
||||
PSM_NORMAL = 0x01,
|
||||
PSM_VIRTUAL_CARD = 0x02,
|
||||
PSM_WIRED_CARD = 0x03,
|
||||
PSM_DUAL_CARD = 0x04
|
||||
} pn532_sam_mode;
|
||||
|
||||
/**
|
||||
* @enum pn53x_target_mode
|
||||
* @brief PN53x target mode enumeration
|
||||
|
|
@ -312,6 +314,7 @@ int pn53x_idle(struct nfc_device *pnd);
|
|||
|
||||
// NFC device as Initiator functions
|
||||
int pn53x_initiator_init(struct nfc_device *pnd);
|
||||
int pn532_initiator_init_secure_element(struct nfc_device *pnd);
|
||||
int pn53x_initiator_select_passive_target(struct nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
|
|
@ -348,7 +351,7 @@ const char *pn53x_strerror(const struct nfc_device *pnd);
|
|||
|
||||
// C wrappers for PN53x commands
|
||||
int pn53x_SetParameters(struct nfc_device *pnd, const uint8_t ui8Value);
|
||||
int pn53x_SAMConfiguration(struct nfc_device *pnd, const pn532_sam_mode mode, int timeout);
|
||||
int pn532_SAMConfiguration(struct nfc_device *pnd, const pn532_sam_mode mode, int timeout);
|
||||
int pn53x_PowerDown(struct nfc_device *pnd);
|
||||
int pn53x_InListPassiveTarget(struct nfc_device *pnd, const pn53x_modulation pmInitModulation,
|
||||
const uint8_t szMaxTargets, const uint8_t *pbtInitiatorData,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue