1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-07-03 13:22:33 +00:00

chore(core): Align RFAL library with most relevant public version 3.0.1.

This commit is contained in:
kopecdav 2025-02-11 16:35:21 +01:00
parent 9a41feb683
commit 073bd6ce2a
4 changed files with 1388 additions and 1471 deletions

View File

@ -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

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
******************************************************************************/
/*
* PROJECT: ST25R firmware
@ -71,38 +71,41 @@
*/
/*! 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 */
RFAL_CD_TECH_NFCF = 0x04, /*!< NFC Technology NFCF */
RFAL_CD_TECH_NFCV = 0x08, /*!< NFC Technology NFCV */
RFAL_CD_TECH_OTHER = 0x10 /*!< NFC Technology OTHER */
} rfalCdTech;
}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;
/*
******************************************************************************
@ -127,7 +130,8 @@ typedef struct {
*
*****************************************************************************
*/
ReturnCode rfalCdDetectCard(rfalCdRes *result);
ReturnCode rfalCdDetectCard( rfalCdRes *result );
/*!
*****************************************************************************
@ -144,7 +148,8 @@ ReturnCode rfalCdDetectCard(rfalCdRes *result);
*
*****************************************************************************
*/
ReturnCode rfalCdStartDetectCard(rfalCdRes *result);
ReturnCode rfalCdStartDetectCard( rfalCdRes *result );
/*!
*****************************************************************************
@ -160,7 +165,8 @@ ReturnCode rfalCdStartDetectCard(rfalCdRes *result);
*
*****************************************************************************
*/
ReturnCode rfalCdGetDetectCardStatus(void);
ReturnCode rfalCdGetDetectCardStatus( void );
#endif /* RFAL_CD_H */

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
******************************************************************************/
/*! \file rfal_cd.c
*
@ -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"
/*
@ -71,7 +69,7 @@
*/
/*! Card Detection states */
typedef enum {
typedef enum{
RFAL_CD_ST_IDLE, /*!< CD idle */
RFAL_CD_ST_START, /*!< CD starting */
RFAL_CD_ST_NFCA_INIT, /*!< NFC-A Initialization */
@ -100,10 +98,11 @@ typedef enum {
RFAL_CD_ST_DETECTED, /*!< CD completed: card detected */
RFAL_CD_ST_NOT_DETECTED, /*!< CD completed: No card detected */
RFAL_CD_ST_ERROR /*!< Error during card detection */
} rfalCdState;
}rfalCdState;
/*! Card Detection context */
typedef struct {
typedef struct{
rfalCdState st; /*!< CD state */
ReturnCode lastErr; /*!< Last occured error */
rfalNfcaListenDevice nfcaDev; /*!< NFC-A Device Info */
@ -115,7 +114,8 @@ typedef struct {
bool skipTechFound; /*!< Second round ongoing, skip techFound */
rfalCdRes *res; /*!< Card Detection output result location */
uint32_t tmr; /*!< Field reset timer */
} rfalCdCtx;
}rfalCdCtx;
/*
******************************************************************************
@ -125,13 +125,14 @@ typedef struct {
static rfalCdCtx gCd;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
#ifdef RFAL_CD_HB
extern bool rfalCdHbDetect(rfalCdTech tech);
extern bool rfalCdHbDetect( rfalCdTech tech );
#endif /* RFAL_CD_HB */
/*
@ -141,18 +142,22 @@ extern bool rfalCdHbDetect(rfalCdTech tech);
*/
/*******************************************************************************/
ReturnCode rfalCdDetectCard(rfalCdRes *result) {
ReturnCode rfalCdDetectCard( rfalCdRes *result )
{
ReturnCode err;
RFAL_EXIT_ON_ERR(err, rfalCdStartDetectCard(result));
rfalRunBlocking(err, rfalCdGetDetectCardStatus());
RFAL_EXIT_ON_ERR( err, rfalCdStartDetectCard( result ) );
rfalRunBlocking( err, rfalCdGetDetectCardStatus() );
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
#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;
@ -488,14 +491,13 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_NFCV_INIT; /* Move to NFC-V */
}
break;
#endif /* RFAL_SUPPORT_MODE_POLL_NFCF*/
#endif /* RFAL_SUPPORT_MODE_POLL_NFCF*/
/*******************************************************************************/
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,52 +505,52 @@ 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 */
err = rfalNfcvPollerCheckPresence( &invRes );
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:
rfalFieldOff();
platformTimerDestroy(gCd.tmr);
gCd.tmr = platformTimerCreate((uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA));
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 */
#ifdef RFAL_CD_HB
#ifdef RFAL_CD_HB
gCd.st = RFAL_CD_ST_HB_START;
#endif /* RFAL_CD_HB */
#endif /* RFAL_CD_HB */
/*******************************************************************************/
@ -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 */
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 */
gCd.res->detType = RFAL_CD_CARD_TECH;
gCd.st = RFAL_CD_ST_DETECTED;
break;
@ -601,41 +603,37 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_CHECK_PROTO;
break;
/*******************************************************************************/
case RFAL_CD_ST_CHECK_PROTO:
if (gCd.mulDevCnt == 0U) /* No NFC listener has been detected */
if( gCd.mulDevCnt == 0U ) /* No NFC listener has been detected */
{
gCd.res->detType = RFAL_CD_NOT_FOUND;
gCd.st = RFAL_CD_ST_NOT_DETECTED;
break;
}
if (gCd.mulDevCnt == 1U) /* A single NFC listener has been identified */
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));
platformTimerDestroy( gCd.tmr );
gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
break;
}
@ -643,19 +641,20 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_DETECTED;
break;
#ifdef RFAL_CD_HB
#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);
rfalNfcfPollerInitialize( RFAL_BR_212 );
break;
case RFAL_CD_TECH_NFCB:
@ -669,37 +668,36 @@ 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 */
if( !rfalIsGTExpired() ) /* Check if GT has been fulfilled */
{
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 */
#endif /* RFAL_CD_HB */
/*******************************************************************************/
case RFAL_CD_ST_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