mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-14 07:06:05 +00:00
chore(core): Align RFAL library with most relevant public version 3.0.1.
This commit is contained in:
parent
9a41feb683
commit
073bd6ce2a
core/embed/io/nfc/rfal
@ -1,6 +1,6 @@
|
||||
|
||||
RFAL middleware was imported into trezor-firmware to support a low level NFC operations of st25r3916b from
|
||||
https://www.st.com/en/embedded-software/stsw-st25r-lib.html#overview (version 1.7.0)
|
||||
https://www.st.com/en/embedded-software/stsw-st25rfal002.html (version 3.0.1)
|
||||
|
||||
# Local changes
|
||||
|
||||
|
@ -71,7 +71,8 @@
|
||||
*/
|
||||
|
||||
/*! Card Detection NFC technology type */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
RFAL_CD_TECH_NONE = 0x00, /*!< No NFC Technology */
|
||||
RFAL_CD_TECH_NFCA = 0x01, /*!< NFC Technology NFCB */
|
||||
RFAL_CD_TECH_NFCB = 0x02, /*!< NFC Technology NFCB */
|
||||
@ -80,29 +81,31 @@ typedef enum {
|
||||
RFAL_CD_TECH_OTHER = 0x10 /*!< NFC Technology OTHER */
|
||||
}rfalCdTech;
|
||||
|
||||
|
||||
/*! Card Detection result|outcome type */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
RFAL_CD_NOT_FOUND = 0, /*<! No NFC device found */
|
||||
RFAL_CD_SINGLE_DEV = 1, /*<! An NFC card was found */
|
||||
RFAL_CD_MULTIPLE_DEV = 2, /*<! Multiple NFC devices found */
|
||||
RFAL_CD_MULTIPLE_TECH =
|
||||
3, /*<! Multiple NFC technologies observed in a single RF carrier */
|
||||
RFAL_CD_MULTIPLE_TECH = 3, /*<! Multiple NFC technologies observed in a single RF carrier */
|
||||
RFAL_CD_CARD_TECH = 4, /*<! A card-exclusive NFC technology found */
|
||||
RFAL_CD_SINGLE_MULTI_TECH =
|
||||
5, /*<! A single NFC device which supports multiple technologies found */
|
||||
RFAL_CD_SINGLE_P2P =
|
||||
6, /*<! A single NFC device which supports NFC-DEP|P2P found */
|
||||
RFAL_CD_SINGLE_HB =
|
||||
7, /*<! A single NFC device where heartbeat was detected */
|
||||
RFAL_CD_UNKOWN = 8 /*<! Unable to complete the Card Detection due to
|
||||
unknow|unexpected event */
|
||||
} rfalCdDetType;
|
||||
RFAL_CD_SINGLE_MULTI_TECH = 5, /*<! A single NFC device which supports multiple technologies found */
|
||||
RFAL_CD_SINGLE_P2P = 6, /*<! A single NFC device which supports NFC-DEP|P2P found */
|
||||
RFAL_CD_SINGLE_HB = 7, /*<! A single NFC device where heartbeat was detected */
|
||||
RFAL_CD_UNKOWN = 8 /*<! Unable to complete the Card Detection due to unknow|unexpected event */
|
||||
}
|
||||
rfalCdDetType;
|
||||
|
||||
|
||||
/*! Card Detection result|outcome */
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
bool detected; /*!< Card detected flag */
|
||||
rfalCdDetType detType; /*!< Card detection type */
|
||||
} rfalCdRes;
|
||||
}
|
||||
rfalCdRes;
|
||||
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
@ -129,6 +132,7 @@ typedef struct {
|
||||
*/
|
||||
ReturnCode rfalCdDetectCard( rfalCdRes *result );
|
||||
|
||||
|
||||
/*!
|
||||
*****************************************************************************
|
||||
* \brief Start Card Detection
|
||||
@ -146,6 +150,7 @@ ReturnCode rfalCdDetectCard(rfalCdRes *result);
|
||||
*/
|
||||
ReturnCode rfalCdStartDetectCard( rfalCdRes *result );
|
||||
|
||||
|
||||
/*!
|
||||
*****************************************************************************
|
||||
* \brief Get Card Detection Status
|
||||
@ -162,6 +167,7 @@ ReturnCode rfalCdStartDetectCard(rfalCdRes *result);
|
||||
*/
|
||||
ReturnCode rfalCdGetDetectCardStatus( void );
|
||||
|
||||
|
||||
#endif /* RFAL_CD_H */
|
||||
|
||||
/**
|
||||
|
@ -27,11 +27,9 @@
|
||||
* Algorith details
|
||||
* - The algorithm treats multiple devices as if a card is present
|
||||
* - The algorithm will identify cards by the following distinguishing features
|
||||
* - Only cards support NFC-V or other non standard technologies (ST25TB,
|
||||
* ...)
|
||||
* - Only cards support NFC-V or other non standard technologies (ST25TB, ...)
|
||||
* - Compliant cards support only a single technology
|
||||
* - The algorithm will identify phones by the following distinguishing
|
||||
* features
|
||||
* - The algorithm will identify phones by the following distinguishing features
|
||||
* - Only phones support P2P (NFC-DEP)
|
||||
* - Only phones are able to communicate on different NFC technologies
|
||||
*
|
||||
@ -43,11 +41,11 @@
|
||||
******************************************************************************
|
||||
*/
|
||||
#include "rfal_cd.h"
|
||||
#include "rfal_rf.h"
|
||||
#include "rfal_nfca.h"
|
||||
#include "rfal_nfcb.h"
|
||||
#include "rfal_nfcf.h"
|
||||
#include "rfal_nfcv.h"
|
||||
#include "rfal_rf.h"
|
||||
#include "rfal_st25tb.h"
|
||||
|
||||
/*
|
||||
@ -102,6 +100,7 @@ typedef enum {
|
||||
RFAL_CD_ST_ERROR /*!< Error during card detection */
|
||||
}rfalCdState;
|
||||
|
||||
|
||||
/*! Card Detection context */
|
||||
typedef struct{
|
||||
rfalCdState st; /*!< CD state */
|
||||
@ -117,6 +116,7 @@ typedef struct {
|
||||
uint32_t tmr; /*!< Field reset timer */
|
||||
}rfalCdCtx;
|
||||
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
* LOCAL VARIABLES
|
||||
@ -125,6 +125,7 @@ typedef struct {
|
||||
|
||||
static rfalCdCtx gCd;
|
||||
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
* LOCAL FUNCTION PROTOTYPES
|
||||
@ -141,7 +142,8 @@ extern bool rfalCdHbDetect(rfalCdTech tech);
|
||||
*/
|
||||
|
||||
/*******************************************************************************/
|
||||
ReturnCode rfalCdDetectCard(rfalCdRes *result) {
|
||||
ReturnCode rfalCdDetectCard( rfalCdRes *result )
|
||||
{
|
||||
ReturnCode err;
|
||||
|
||||
RFAL_EXIT_ON_ERR( err, rfalCdStartDetectCard( result ) );
|
||||
@ -150,9 +152,12 @@ ReturnCode rfalCdDetectCard(rfalCdRes *result) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
ReturnCode rfalCdStartDetectCard(rfalCdRes *result) {
|
||||
if (result == NULL) {
|
||||
ReturnCode rfalCdStartDetectCard( rfalCdRes *result )
|
||||
{
|
||||
if( result == NULL )
|
||||
{
|
||||
return RFAL_ERR_PARAM;
|
||||
}
|
||||
|
||||
@ -162,14 +167,18 @@ ReturnCode rfalCdStartDetectCard(rfalCdRes *result) {
|
||||
return RFAL_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
ReturnCode rfalCdGetDetectCardStatus( void )
|
||||
{
|
||||
ReturnCode err;
|
||||
rfalNfcaSensRes sensRes;
|
||||
rfalNfcbSensbRes sensbRes;
|
||||
rfalNfcvInventoryRes invRes;
|
||||
|
||||
switch (gCd.st) {
|
||||
|
||||
switch( gCd.st )
|
||||
{
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_START:
|
||||
|
||||
@ -181,99 +190,96 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
gCd.st = RFAL_CD_ST_NFCA_INIT;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCA_INIT:
|
||||
|
||||
/* Verify if we are performing multi technology check */
|
||||
if ((gCd.skipTechFound)) {
|
||||
/* If staring multi technology check if field has been Off long enough
|
||||
*/
|
||||
if ((!platformTimerIsExpired(gCd.tmr))) {
|
||||
if( (gCd.skipTechFound) )
|
||||
{
|
||||
/* If staring multi technology check if field has been Off long enough */
|
||||
if( (!platformTimerIsExpired(gCd.tmr)) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (gCd.techFound == RFAL_CD_TECH_NFCA) {
|
||||
gCd.st = RFAL_CD_ST_NFCB_INIT; /* If single card card found before was
|
||||
NFC-A skip tech now */
|
||||
if( gCd.techFound == RFAL_CD_TECH_NFCA )
|
||||
{
|
||||
gCd.st = RFAL_CD_ST_NFCB_INIT; /* If single card card found before was NFC-A skip tech now */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rfalNfcaPollerInitialize(); /* Initialize for NFC-A */
|
||||
err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and
|
||||
start GT timer */
|
||||
if (err != RFAL_ERR_NONE) {
|
||||
err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
|
||||
if( err != RFAL_ERR_NONE )
|
||||
{
|
||||
gCd.lastErr = err;
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot
|
||||
continue Card Detection */
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCA_TECHDET;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCA_TECHDET:
|
||||
|
||||
if (!rfalIsGTExpired()) {
|
||||
if( !rfalIsGTExpired() )
|
||||
{
|
||||
break; /* Wait until GT has been fulfilled */
|
||||
}
|
||||
|
||||
err =
|
||||
rfalNfcaPollerTechnologyDetection(RFAL_COMPLIANCE_MODE_ISO, &sensRes);
|
||||
if (err == RFAL_ERR_NONE) {
|
||||
if (gCd.skipTechFound) /* Verify if we are performing multi technology
|
||||
check */
|
||||
err = rfalNfcaPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_ISO, &sensRes );
|
||||
if( err == RFAL_ERR_NONE )
|
||||
{
|
||||
if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device was another
|
||||
technology and now NFC-A */
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-A */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCA_COLRES_START; /* NFC-A detected perform
|
||||
collision resolution */
|
||||
gCd.st = RFAL_CD_ST_NFCA_COLRES_START; /* NFC-A detected perform collision resolution */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCB_INIT; /* NFC-A not detected, move to NFC-B */
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCA_COLRES_START:
|
||||
|
||||
err = rfalNfcaPollerStartFullCollisionResolution(
|
||||
RFAL_COMPLIANCE_MODE_ISO, 0, &gCd.nfcaDev, &gCd.devCnt);
|
||||
if (err != RFAL_ERR_NONE) {
|
||||
err = rfalNfcaPollerStartFullCollisionResolution( RFAL_COMPLIANCE_MODE_ISO, 0, &gCd.nfcaDev, &gCd.devCnt );
|
||||
if( err != RFAL_ERR_NONE )
|
||||
{
|
||||
gCd.lastErr = err;
|
||||
gCd.st =
|
||||
RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCA_COLRES;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCA_COLRES:
|
||||
|
||||
err = rfalNfcaPollerGetFullCollisionResolutionStatus();
|
||||
if (err != RFAL_ERR_BUSY) {
|
||||
if ((err == RFAL_ERR_NONE) &&
|
||||
(gCd.devCnt ==
|
||||
1U)) /* Collision resolution OK and a single card was found */
|
||||
if( err != RFAL_ERR_BUSY )
|
||||
{
|
||||
if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
|
||||
{
|
||||
gCd.mulDevCnt++;
|
||||
gCd.techFound = RFAL_CD_TECH_NFCA;
|
||||
}
|
||||
|
||||
/* Check if multiple cards or technologies have already been identified
|
||||
*/
|
||||
if ((err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) ||
|
||||
(gCd.mulDevCnt > 1U)) {
|
||||
gCd.res->detType =
|
||||
RFAL_CD_MULTIPLE_DEV; /* Report multiple devices. A T1T will also
|
||||
fail at ColRes */
|
||||
/* Check if multiple cards or technologies have already been identified */
|
||||
if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_MULTIPLE_DEV; /* Report multiple devices. A T1T will also fail at ColRes */
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
|
||||
break;
|
||||
@ -283,123 +289,123 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCB_INIT:
|
||||
|
||||
/* Verify if we are performing multi technology check */
|
||||
if ((gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCB)) {
|
||||
gCd.st = RFAL_CD_ST_NFCF_INIT; /* If single card card found before was
|
||||
NFC-B skip tech now */
|
||||
if( (gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCB) )
|
||||
{
|
||||
gCd.st = RFAL_CD_ST_NFCF_INIT; /* If single card card found before was NFC-B skip tech now */
|
||||
break;
|
||||
}
|
||||
|
||||
rfalNfcbPollerInitialize(); /* Initialize for NFC-B */
|
||||
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT
|
||||
timer */
|
||||
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCB_TECHDET;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCB_TECHDET:
|
||||
|
||||
if (!rfalIsGTExpired()) {
|
||||
if( !rfalIsGTExpired() )
|
||||
{
|
||||
break; /* Wait until GT has been fulfilled */
|
||||
}
|
||||
|
||||
err = rfalNfcbPollerTechnologyDetection(RFAL_COMPLIANCE_MODE_NFC,
|
||||
&sensbRes, &gCd.devCnt);
|
||||
if (err == RFAL_ERR_NONE) {
|
||||
/* Verify if we are performing multi technology check OR already found
|
||||
* one on the first round */
|
||||
if (gCd.skipTechFound) {
|
||||
err = rfalNfcbPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_NFC, &sensbRes, &gCd.devCnt );
|
||||
if( err == RFAL_ERR_NONE )
|
||||
{
|
||||
/* Verify if we are performing multi technology check OR already found one on the first round */
|
||||
if( gCd.skipTechFound )
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device was another
|
||||
technology and now NFC-B */
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-B */
|
||||
break;
|
||||
} else if (gCd.techFound !=
|
||||
RFAL_CD_TECH_NONE) /* If on the first round check if other
|
||||
Tech was already found */
|
||||
}
|
||||
else if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* MISRA 15.7 - Empty else */
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCB_COLRES_START; /* NFC-B detected perform
|
||||
collision resolution */
|
||||
gCd.st = RFAL_CD_ST_NFCB_COLRES_START; /* NFC-B detected perform collision resolution */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCF_INIT; /* NFC-B not detected, move to NFC-B */
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCB_COLRES_START:
|
||||
|
||||
err = rfalNfcbPollerStartCollisionResolution(RFAL_COMPLIANCE_MODE_NFC, 0,
|
||||
&gCd.nfcbDev, &gCd.devCnt);
|
||||
if (err != RFAL_ERR_NONE) {
|
||||
err = rfalNfcbPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, 0, &gCd.nfcbDev, &gCd.devCnt );
|
||||
if( err != RFAL_ERR_NONE )
|
||||
{
|
||||
gCd.lastErr = err;
|
||||
gCd.st =
|
||||
RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCB_COLRES;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCB_COLRES:
|
||||
|
||||
err = rfalNfcbPollerGetCollisionResolutionStatus();
|
||||
if (err != RFAL_ERR_BUSY) {
|
||||
if ((err == RFAL_ERR_NONE) &&
|
||||
(gCd.devCnt ==
|
||||
1U)) /* Collision resolution OK and a single card was found */
|
||||
if( err != RFAL_ERR_BUSY )
|
||||
{
|
||||
if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
|
||||
{
|
||||
gCd.mulDevCnt++;
|
||||
gCd.techFound = RFAL_CD_TECH_NFCB;
|
||||
}
|
||||
|
||||
/* Check if multiple cards or technologies have already been identified
|
||||
*/
|
||||
if ((err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) ||
|
||||
(gCd.mulDevCnt > 1U)) {
|
||||
/* Check if multiple cards or technologies have already been identified */
|
||||
if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = ((RFAL_SUPPORT_MODE_POLL_NFCF)
|
||||
? RFAL_CD_ST_NFCF_INIT
|
||||
: RFAL_CD_ST_NFCV_INIT); /* Move to NFC-F or NFC-V */
|
||||
gCd.st = ( (RFAL_SUPPORT_MODE_POLL_NFCF) ? RFAL_CD_ST_NFCF_INIT : RFAL_CD_ST_NFCV_INIT); /* Move to NFC-F or NFC-V */
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
#if RFAL_SUPPORT_MODE_POLL_NFCF
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCF_INIT:
|
||||
|
||||
/* Verify if we are performing multi technology check */
|
||||
if ((gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCF)) {
|
||||
gCd.st = RFAL_CD_ST_PROPRIETARY; /* If single card card found before was
|
||||
NFC-F skip tech now */
|
||||
if( (gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCF) )
|
||||
{
|
||||
gCd.st = RFAL_CD_ST_PROPRIETARY; /* If single card card found before was NFC-F skip tech now */
|
||||
break;
|
||||
}
|
||||
|
||||
rfalNfcfPollerInitialize(RFAL_BR_212); /* Initialize for NFC-F */
|
||||
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT
|
||||
timer */
|
||||
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCF_TECHDET_START;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCF_TECHDET_START:
|
||||
if (!rfalIsGTExpired()) {
|
||||
if( !rfalIsGTExpired() )
|
||||
{
|
||||
break; /* Wait until GT has been fulfilled */
|
||||
}
|
||||
|
||||
@ -407,79 +413,76 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
gCd.st = RFAL_CD_ST_NFCF_TECHDET;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCF_TECHDET:
|
||||
|
||||
err = rfalNfcfPollerGetCheckPresenceStatus();
|
||||
if (err == RFAL_ERR_BUSY) {
|
||||
if( err == RFAL_ERR_BUSY )
|
||||
{
|
||||
break; /* Wait until NFC-F Technlogy Detection is completed */
|
||||
}
|
||||
|
||||
if (gCd.skipTechFound) /* Verify if we are performing multi technology
|
||||
check */
|
||||
if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
|
||||
{
|
||||
gCd.st = RFAL_CD_ST_PROPRIETARY;
|
||||
|
||||
/* If single device was another technology and now NFC-F, otherwise
|
||||
* conclude*/
|
||||
if (err == RFAL_ERR_NONE) {
|
||||
/* If single device was another technology and now NFC-F, otherwise conclude*/
|
||||
if(err == RFAL_ERR_NONE)
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (err == RFAL_ERR_NONE) {
|
||||
if (gCd.techFound !=
|
||||
RFAL_CD_TECH_NONE) /* If on the first round check if other Tech was
|
||||
already found */
|
||||
if( err == RFAL_ERR_NONE )
|
||||
{
|
||||
if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCF_COLRES_START; /* NFC-F detected, perform
|
||||
collision resolution */
|
||||
gCd.st = RFAL_CD_ST_NFCF_COLRES_START; /* NFC-F detected, perform collision resolution */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCV_INIT; /* NFC-F not detected, move to NFC-V */
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCF_COLRES_START:
|
||||
|
||||
err = rfalNfcfPollerStartCollisionResolution(RFAL_COMPLIANCE_MODE_NFC,
|
||||
RFAL_CD_NFCF_DEVLIMIT,
|
||||
gCd.nfcfDev, &gCd.devCnt);
|
||||
if (err != RFAL_ERR_NONE) {
|
||||
err = rfalNfcfPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, RFAL_CD_NFCF_DEVLIMIT, gCd.nfcfDev, &gCd.devCnt );
|
||||
if( err != RFAL_ERR_NONE )
|
||||
{
|
||||
gCd.lastErr = err;
|
||||
gCd.st =
|
||||
RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCF_COLRES;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCF_COLRES:
|
||||
|
||||
err = rfalNfcfPollerGetCollisionResolutionStatus();
|
||||
if (err != RFAL_ERR_BUSY) {
|
||||
if ((err == RFAL_ERR_NONE) &&
|
||||
(gCd.devCnt ==
|
||||
1U)) /* Collision resolution OK and a single card was found */
|
||||
if( err != RFAL_ERR_BUSY )
|
||||
{
|
||||
if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
|
||||
{
|
||||
gCd.mulDevCnt++;
|
||||
gCd.techFound = RFAL_CD_TECH_NFCF;
|
||||
}
|
||||
|
||||
/* Check if multiple cards or technologies have already been identified
|
||||
*/
|
||||
if ((err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) ||
|
||||
(gCd.mulDevCnt > 1U)) {
|
||||
/* Check if multiple cards or technologies have already been identified */
|
||||
if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
@ -494,8 +497,7 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
case RFAL_CD_ST_NFCV_INIT:
|
||||
|
||||
rfalNfcvPollerInitialize(); /* Initialize for NFC-V */
|
||||
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT
|
||||
timer */
|
||||
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
|
||||
|
||||
gCd.st = RFAL_CD_ST_NFCV_TECHDET;
|
||||
break;
|
||||
@ -503,32 +505,31 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_NFCV_TECHDET:
|
||||
|
||||
if (!rfalIsGTExpired()) {
|
||||
if( !rfalIsGTExpired() )
|
||||
{
|
||||
break; /* Wait until GT has been fulfilled */
|
||||
}
|
||||
|
||||
err = rfalNfcvPollerCheckPresence( &invRes );
|
||||
if (err == RFAL_ERR_NONE) {
|
||||
if (gCd.techFound !=
|
||||
RFAL_CD_TECH_NONE) /* If other Tech was already found */
|
||||
if( err == RFAL_ERR_NONE )
|
||||
{
|
||||
if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If other Tech was already found */
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.techFound =
|
||||
RFAL_CD_TECH_NFCV; /* If NFC-V is regarded as card as CE NFC-V is
|
||||
currently not supported by active devices */
|
||||
gCd.techFound = RFAL_CD_TECH_NFCV; /* If NFC-V is regarded as card as CE NFC-V is currently not supported by active devices */
|
||||
gCd.res->detType = RFAL_CD_CARD_TECH;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st =
|
||||
RFAL_CD_ST_PROPRIETARY; /* Move to Proprietary NFC Technologies */
|
||||
gCd.st = RFAL_CD_ST_PROPRIETARY; /* Move to Proprietary NFC Technologies */
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_PROPRIETARY:
|
||||
|
||||
@ -536,12 +537,13 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
platformTimerDestroy( gCd.tmr );
|
||||
gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
|
||||
|
||||
/* If none of the other NFC technologies was not seen on a second round,
|
||||
* regard as card */
|
||||
if (gCd.skipTechFound) {
|
||||
/* If none of the other NFC technologies was not seen on a second round, regard as card */
|
||||
if( gCd.skipTechFound )
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_SINGLE_DEV;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Only one device found which does not support NFC-DEP and only *
|
||||
* answered in one technology, perform heartbeat detection */
|
||||
@ -558,41 +560,41 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
gCd.st = RFAL_CD_ST_ST25TB_INIT;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_ST25TB_INIT:
|
||||
|
||||
if ((!platformTimerIsExpired(
|
||||
gCd.tmr))) /* Check if field has been Off long enough */
|
||||
if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
rfalSt25tbPollerInitialize(); /* Initialize for ST25TB */
|
||||
err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and
|
||||
start GT timer */
|
||||
err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
|
||||
|
||||
if (err != RFAL_ERR_NONE) {
|
||||
if( err != RFAL_ERR_NONE )
|
||||
{
|
||||
gCd.lastErr = err;
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot
|
||||
continue Card Detection */
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_ST25TB_TECHDET;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_ST25TB_TECHDET:
|
||||
|
||||
if ((!rfalIsGTExpired())) {
|
||||
if( (!rfalIsGTExpired()) )
|
||||
{
|
||||
break; /* Wait until GT has been fulfilled */
|
||||
}
|
||||
|
||||
err = rfalSt25tbPollerCheckPresence( NULL );
|
||||
if (err == RFAL_ERR_NONE) {
|
||||
gCd.techFound =
|
||||
RFAL_CD_TECH_OTHER; /* If ST25TB is regarded as card as CE is not
|
||||
supported by active devices */
|
||||
if( err == RFAL_ERR_NONE )
|
||||
{
|
||||
gCd.techFound = RFAL_CD_TECH_OTHER; /* If ST25TB is regarded as card as CE is not supported by active devices */
|
||||
gCd.res->detType = RFAL_CD_CARD_TECH;
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
@ -601,6 +603,7 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
gCd.st = RFAL_CD_ST_CHECK_PROTO;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_CHECK_PROTO:
|
||||
|
||||
@ -614,25 +617,20 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
if( gCd.mulDevCnt == 1U ) /* A single NFC listener has been identified */
|
||||
{
|
||||
/* Check if it supports NFC-DEP protocol */
|
||||
if (((gCd.techFound == RFAL_CD_TECH_NFCA) &&
|
||||
((gCd.nfcaDev.type == RFAL_NFCA_NFCDEP) ||
|
||||
(gCd.nfcaDev.type == RFAL_NFCA_T4T_NFCDEP))) ||
|
||||
((gCd.techFound == RFAL_CD_TECH_NFCF) &&
|
||||
rfalNfcfIsNfcDepSupported(&gCd.nfcfDev[0]))) {
|
||||
if( ( (gCd.techFound == RFAL_CD_TECH_NFCA) && ((gCd.nfcaDev.type == RFAL_NFCA_NFCDEP) || (gCd.nfcaDev.type == RFAL_NFCA_T4T_NFCDEP)) ) ||
|
||||
( (gCd.techFound == RFAL_CD_TECH_NFCF) && rfalNfcfIsNfcDepSupported( &gCd.nfcfDev[0] ) ) )
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_SINGLE_P2P;
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* NFC-DEP supported, regarded as
|
||||
non passive card */
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED;/* NFC-DEP supported, regarded as non passive card */
|
||||
break;
|
||||
}
|
||||
|
||||
/* If a single NFC listener has been detected, and did not announce
|
||||
* NFC-DEP support, * check if it supports mutiple NFC technologies
|
||||
* (skip the one it was previous seen) */
|
||||
/* If a single NFC listener has been detected, and did not announce NFC-DEP support, *
|
||||
* check if it supports mutiple NFC technologies (skip the one it was previous seen) */
|
||||
gCd.skipTechFound = true;
|
||||
gCd.st = RFAL_CD_ST_NFCA_INIT;
|
||||
|
||||
/* Reset Field once again to avoid unwanted effect of Proprietary NFC
|
||||
* Tech modulation */
|
||||
/* Reset Field once again to avoid unwanted effect of Proprietary NFC Tech modulation */
|
||||
rfalFieldOff();
|
||||
platformTimerDestroy( gCd.tmr );
|
||||
gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
|
||||
@ -643,17 +641,18 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
gCd.st = RFAL_CD_ST_DETECTED;
|
||||
break;
|
||||
|
||||
|
||||
#ifdef RFAL_CD_HB
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_HB_START:
|
||||
|
||||
if ((!platformTimerIsExpired(
|
||||
gCd.tmr))) /* Check if field has been Off long enough */
|
||||
if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch (gCd.techFound) {
|
||||
switch( gCd.techFound )
|
||||
{
|
||||
case RFAL_CD_TECH_NFCF:
|
||||
rfalNfcfPollerInitialize( RFAL_BR_212 );
|
||||
break;
|
||||
@ -669,16 +668,17 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
}
|
||||
|
||||
err = rfalFieldOnAndStartGT();
|
||||
if (err != RFAL_ERR_NONE) {
|
||||
if( err != RFAL_ERR_NONE )
|
||||
{
|
||||
gCd.lastErr = err;
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot
|
||||
continue Card Detection */
|
||||
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.st = RFAL_CD_ST_HB;
|
||||
break;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_HB:
|
||||
if( !rfalIsGTExpired() ) /* Check if GT has been fulfilled */
|
||||
@ -686,21 +686,19 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (rfalCdHbDetect(
|
||||
gCd.techFound)) /* Perform tha heartbeat detection sequence */
|
||||
if( rfalCdHbDetect( gCd.techFound ) ) /* Perform tha heartbeat detection sequence */
|
||||
{
|
||||
gCd.res->detType = RFAL_CD_SINGLE_HB;
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device performing ALM, no
|
||||
passive card */
|
||||
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device performing ALM, no passive card */
|
||||
break;
|
||||
}
|
||||
|
||||
gCd.res->detType = RFAL_CD_SINGLE_DEV;
|
||||
gCd.st = RFAL_CD_ST_DETECTED; /* ALM not detected on single device, regard
|
||||
as card */
|
||||
gCd.st = RFAL_CD_ST_DETECTED; /* ALM not detected on single device, regard as card */
|
||||
break;
|
||||
#endif /* RFAL_CD_HB */
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_DETECTED:
|
||||
case RFAL_CD_ST_NOT_DETECTED:
|
||||
@ -713,22 +711,24 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
|
||||
return RFAL_ERR_NONE;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_IDLE:
|
||||
return RFAL_ERR_WRONG_STATE;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
case RFAL_CD_ST_ERROR:
|
||||
|
||||
gCd.res->detType = RFAL_CD_UNKOWN;
|
||||
gCd.res->detected =
|
||||
true; /* Error ocurred, mark as card present to avoid damage */
|
||||
gCd.res->detected = true; /* Error ocurred, mark as card present to avoid damage */
|
||||
|
||||
rfalFieldOff();
|
||||
gCd.st = RFAL_CD_ST_IDLE;
|
||||
|
||||
return gCd.lastErr;
|
||||
|
||||
|
||||
/*******************************************************************************/
|
||||
default:
|
||||
return RFAL_ERR_INTERNAL;
|
||||
@ -736,3 +736,4 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
|
||||
|
||||
return RFAL_ERR_BUSY;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user