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 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 # Local changes

View File

@ -71,7 +71,8 @@
*/ */
/*! Card Detection NFC technology type */ /*! Card Detection NFC technology type */
typedef enum { typedef enum
{
RFAL_CD_TECH_NONE = 0x00, /*!< No NFC Technology */ RFAL_CD_TECH_NONE = 0x00, /*!< No NFC Technology */
RFAL_CD_TECH_NFCA = 0x01, /*!< NFC Technology NFCB */ RFAL_CD_TECH_NFCA = 0x01, /*!< NFC Technology NFCB */
RFAL_CD_TECH_NFCB = 0x02, /*!< 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 */ RFAL_CD_TECH_OTHER = 0x10 /*!< NFC Technology OTHER */
}rfalCdTech; }rfalCdTech;
/*! Card Detection result|outcome type */ /*! Card Detection result|outcome type */
typedef enum { typedef enum
{
RFAL_CD_NOT_FOUND = 0, /*<! No NFC device found */ RFAL_CD_NOT_FOUND = 0, /*<! No NFC device found */
RFAL_CD_SINGLE_DEV = 1, /*<! An NFC card was found */ RFAL_CD_SINGLE_DEV = 1, /*<! An NFC card was found */
RFAL_CD_MULTIPLE_DEV = 2, /*<! Multiple NFC devices found */ RFAL_CD_MULTIPLE_DEV = 2, /*<! Multiple NFC devices found */
RFAL_CD_MULTIPLE_TECH = RFAL_CD_MULTIPLE_TECH = 3, /*<! Multiple NFC technologies observed in a single RF carrier */
3, /*<! Multiple NFC technologies observed in a single RF carrier */
RFAL_CD_CARD_TECH = 4, /*<! A card-exclusive NFC technology found */ RFAL_CD_CARD_TECH = 4, /*<! A card-exclusive NFC technology found */
RFAL_CD_SINGLE_MULTI_TECH = RFAL_CD_SINGLE_MULTI_TECH = 5, /*<! A single NFC device which supports multiple technologies found */
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_P2P = RFAL_CD_SINGLE_HB = 7, /*<! A single NFC device where heartbeat was detected */
6, /*<! A single NFC device which supports NFC-DEP|P2P found */ RFAL_CD_UNKOWN = 8 /*<! Unable to complete the Card Detection due to unknow|unexpected event */
RFAL_CD_SINGLE_HB = }
7, /*<! A single NFC device where heartbeat was detected */ rfalCdDetType;
RFAL_CD_UNKOWN = 8 /*<! Unable to complete the Card Detection due to
unknow|unexpected event */
} rfalCdDetType;
/*! Card Detection result|outcome */ /*! Card Detection result|outcome */
typedef struct { typedef struct
{
bool detected; /*!< Card detected flag */ bool detected; /*!< Card detected flag */
rfalCdDetType detType; /*!< Card detection type */ rfalCdDetType detType; /*!< Card detection type */
} rfalCdRes; }
rfalCdRes;
/* /*
****************************************************************************** ******************************************************************************
@ -129,6 +132,7 @@ typedef struct {
*/ */
ReturnCode rfalCdDetectCard( rfalCdRes *result ); ReturnCode rfalCdDetectCard( rfalCdRes *result );
/*! /*!
***************************************************************************** *****************************************************************************
* \brief Start Card Detection * \brief Start Card Detection
@ -146,6 +150,7 @@ ReturnCode rfalCdDetectCard(rfalCdRes *result);
*/ */
ReturnCode rfalCdStartDetectCard( rfalCdRes *result ); ReturnCode rfalCdStartDetectCard( rfalCdRes *result );
/*! /*!
***************************************************************************** *****************************************************************************
* \brief Get Card Detection Status * \brief Get Card Detection Status
@ -162,6 +167,7 @@ ReturnCode rfalCdStartDetectCard(rfalCdRes *result);
*/ */
ReturnCode rfalCdGetDetectCardStatus( void ); ReturnCode rfalCdGetDetectCardStatus( void );
#endif /* RFAL_CD_H */ #endif /* RFAL_CD_H */
/** /**

View File

@ -27,11 +27,9 @@
* Algorith details * Algorith details
* - The algorithm treats multiple devices as if a card is present * - The algorithm treats multiple devices as if a card is present
* - The algorithm will identify cards by the following distinguishing features * - 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 * - Compliant cards support only a single technology
* - The algorithm will identify phones by the following distinguishing * - The algorithm will identify phones by the following distinguishing features
* features
* - Only phones support P2P (NFC-DEP) * - Only phones support P2P (NFC-DEP)
* - Only phones are able to communicate on different NFC technologies * - Only phones are able to communicate on different NFC technologies
* *
@ -43,11 +41,11 @@
****************************************************************************** ******************************************************************************
*/ */
#include "rfal_cd.h" #include "rfal_cd.h"
#include "rfal_rf.h"
#include "rfal_nfca.h" #include "rfal_nfca.h"
#include "rfal_nfcb.h" #include "rfal_nfcb.h"
#include "rfal_nfcf.h" #include "rfal_nfcf.h"
#include "rfal_nfcv.h" #include "rfal_nfcv.h"
#include "rfal_rf.h"
#include "rfal_st25tb.h" #include "rfal_st25tb.h"
/* /*
@ -102,6 +100,7 @@ typedef enum {
RFAL_CD_ST_ERROR /*!< Error during card detection */ RFAL_CD_ST_ERROR /*!< Error during card detection */
}rfalCdState; }rfalCdState;
/*! Card Detection context */ /*! Card Detection context */
typedef struct{ typedef struct{
rfalCdState st; /*!< CD state */ rfalCdState st; /*!< CD state */
@ -117,6 +116,7 @@ typedef struct {
uint32_t tmr; /*!< Field reset timer */ uint32_t tmr; /*!< Field reset timer */
}rfalCdCtx; }rfalCdCtx;
/* /*
****************************************************************************** ******************************************************************************
* LOCAL VARIABLES * LOCAL VARIABLES
@ -125,6 +125,7 @@ typedef struct {
static rfalCdCtx gCd; static rfalCdCtx gCd;
/* /*
****************************************************************************** ******************************************************************************
* LOCAL FUNCTION PROTOTYPES * LOCAL FUNCTION PROTOTYPES
@ -141,7 +142,8 @@ extern bool rfalCdHbDetect(rfalCdTech tech);
*/ */
/*******************************************************************************/ /*******************************************************************************/
ReturnCode rfalCdDetectCard(rfalCdRes *result) { ReturnCode rfalCdDetectCard( rfalCdRes *result )
{
ReturnCode err; ReturnCode err;
RFAL_EXIT_ON_ERR( err, rfalCdStartDetectCard( result ) ); RFAL_EXIT_ON_ERR( err, rfalCdStartDetectCard( result ) );
@ -150,9 +152,12 @@ ReturnCode rfalCdDetectCard(rfalCdRes *result) {
return err; return err;
} }
/*******************************************************************************/ /*******************************************************************************/
ReturnCode rfalCdStartDetectCard(rfalCdRes *result) { ReturnCode rfalCdStartDetectCard( rfalCdRes *result )
if (result == NULL) { {
if( result == NULL )
{
return RFAL_ERR_PARAM; return RFAL_ERR_PARAM;
} }
@ -162,14 +167,18 @@ ReturnCode rfalCdStartDetectCard(rfalCdRes *result) {
return RFAL_ERR_NONE; return RFAL_ERR_NONE;
} }
/*******************************************************************************/ /*******************************************************************************/
ReturnCode rfalCdGetDetectCardStatus(void) { ReturnCode rfalCdGetDetectCardStatus( void )
{
ReturnCode err; ReturnCode err;
rfalNfcaSensRes sensRes; rfalNfcaSensRes sensRes;
rfalNfcbSensbRes sensbRes; rfalNfcbSensbRes sensbRes;
rfalNfcvInventoryRes invRes; rfalNfcvInventoryRes invRes;
switch (gCd.st) {
switch( gCd.st )
{
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_START: case RFAL_CD_ST_START:
@ -181,99 +190,96 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_NFCA_INIT; gCd.st = RFAL_CD_ST_NFCA_INIT;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCA_INIT: case RFAL_CD_ST_NFCA_INIT:
/* Verify if we are performing multi technology check */ /* Verify if we are performing multi technology check */
if ((gCd.skipTechFound)) { if( (gCd.skipTechFound) )
/* If staring multi technology check if field has been Off long enough {
*/ /* If staring multi technology check if field has been Off long enough */
if ((!platformTimerIsExpired(gCd.tmr))) { if( (!platformTimerIsExpired(gCd.tmr)) )
{
break; break;
} }
if (gCd.techFound == RFAL_CD_TECH_NFCA) { 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 */ gCd.st = RFAL_CD_ST_NFCB_INIT; /* If single card card found before was NFC-A skip tech now */
break; break;
} }
} }
rfalNfcaPollerInitialize(); /* Initialize for NFC-A */ rfalNfcaPollerInitialize(); /* Initialize for NFC-A */
err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
start GT timer */ if( err != RFAL_ERR_NONE )
if (err != RFAL_ERR_NONE) { {
gCd.lastErr = err; gCd.lastErr = err;
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
continue Card Detection */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCA_TECHDET; gCd.st = RFAL_CD_ST_NFCA_TECHDET;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCA_TECHDET: case RFAL_CD_ST_NFCA_TECHDET:
if (!rfalIsGTExpired()) { if( !rfalIsGTExpired() )
{
break; /* Wait until GT has been fulfilled */ break; /* Wait until GT has been fulfilled */
} }
err = err = rfalNfcaPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_ISO, &sensRes );
rfalNfcaPollerTechnologyDetection(RFAL_COMPLIANCE_MODE_ISO, &sensRes); if( err == RFAL_ERR_NONE )
if (err == RFAL_ERR_NONE) { {
if (gCd.skipTechFound) /* Verify if we are performing multi technology if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
check */
{ {
gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH; gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device was another gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-A */
technology and now NFC-A */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCA_COLRES_START; /* NFC-A detected perform gCd.st = RFAL_CD_ST_NFCA_COLRES_START; /* NFC-A detected perform collision resolution */
collision resolution */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCB_INIT; /* NFC-A not detected, move to NFC-B */ gCd.st = RFAL_CD_ST_NFCB_INIT; /* NFC-A not detected, move to NFC-B */
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCA_COLRES_START: case RFAL_CD_ST_NFCA_COLRES_START:
err = rfalNfcaPollerStartFullCollisionResolution( err = rfalNfcaPollerStartFullCollisionResolution( RFAL_COMPLIANCE_MODE_ISO, 0, &gCd.nfcaDev, &gCd.devCnt );
RFAL_COMPLIANCE_MODE_ISO, 0, &gCd.nfcaDev, &gCd.devCnt); if( err != RFAL_ERR_NONE )
if (err != RFAL_ERR_NONE) { {
gCd.lastErr = err; gCd.lastErr = err;
gCd.st = gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCA_COLRES; gCd.st = RFAL_CD_ST_NFCA_COLRES;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCA_COLRES: case RFAL_CD_ST_NFCA_COLRES:
err = rfalNfcaPollerGetFullCollisionResolutionStatus(); err = rfalNfcaPollerGetFullCollisionResolutionStatus();
if (err != RFAL_ERR_BUSY) { if( err != RFAL_ERR_BUSY )
if ((err == RFAL_ERR_NONE) && {
(gCd.devCnt == if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
1U)) /* Collision resolution OK and a single card was found */
{ {
gCd.mulDevCnt++; gCd.mulDevCnt++;
gCd.techFound = RFAL_CD_TECH_NFCA; gCd.techFound = RFAL_CD_TECH_NFCA;
} }
/* Check if multiple cards or technologies have already been identified /* Check if multiple cards or technologies have already been identified */
*/ if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
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.res->detType =
RFAL_CD_MULTIPLE_DEV; /* Report multiple devices. A T1T will also
fail at ColRes */
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
@ -283,123 +289,123 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
} }
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCB_INIT: case RFAL_CD_ST_NFCB_INIT:
/* Verify if we are performing multi technology check */ /* Verify if we are performing multi technology check */
if ((gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCB)) { 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 */ gCd.st = RFAL_CD_ST_NFCF_INIT; /* If single card card found before was NFC-B skip tech now */
break; break;
} }
rfalNfcbPollerInitialize(); /* Initialize for NFC-B */ rfalNfcbPollerInitialize(); /* Initialize for NFC-B */
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
timer */
gCd.st = RFAL_CD_ST_NFCB_TECHDET; gCd.st = RFAL_CD_ST_NFCB_TECHDET;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCB_TECHDET: case RFAL_CD_ST_NFCB_TECHDET:
if (!rfalIsGTExpired()) { if( !rfalIsGTExpired() )
{
break; /* Wait until GT has been fulfilled */ break; /* Wait until GT has been fulfilled */
} }
err = rfalNfcbPollerTechnologyDetection(RFAL_COMPLIANCE_MODE_NFC, err = rfalNfcbPollerTechnologyDetection( RFAL_COMPLIANCE_MODE_NFC, &sensbRes, &gCd.devCnt );
&sensbRes, &gCd.devCnt); if( err == RFAL_ERR_NONE )
if (err == RFAL_ERR_NONE) { {
/* Verify if we are performing multi technology check OR already found /* Verify if we are performing multi technology check OR already found one on the first round */
* one on the first round */ if( gCd.skipTechFound )
if (gCd.skipTechFound) { {
gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH; gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device was another gCd.st = RFAL_CD_ST_NOT_DETECTED;/* Single device was another technology and now NFC-B */
technology and now NFC-B */
break; break;
} else if (gCd.techFound != }
RFAL_CD_TECH_NONE) /* If on the first round check if other else if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
Tech was already found */
{ {
gCd.res->detType = RFAL_CD_MULTIPLE_TECH; gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
} else { }
else
{
/* MISRA 15.7 - Empty else */ /* MISRA 15.7 - Empty else */
} }
gCd.st = RFAL_CD_ST_NFCB_COLRES_START; /* NFC-B detected perform gCd.st = RFAL_CD_ST_NFCB_COLRES_START; /* NFC-B detected perform collision resolution */
collision resolution */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCF_INIT; /* NFC-B not detected, move to NFC-B */ gCd.st = RFAL_CD_ST_NFCF_INIT; /* NFC-B not detected, move to NFC-B */
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCB_COLRES_START: case RFAL_CD_ST_NFCB_COLRES_START:
err = rfalNfcbPollerStartCollisionResolution(RFAL_COMPLIANCE_MODE_NFC, 0, err = rfalNfcbPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, 0, &gCd.nfcbDev, &gCd.devCnt );
&gCd.nfcbDev, &gCd.devCnt); if( err != RFAL_ERR_NONE )
if (err != RFAL_ERR_NONE) { {
gCd.lastErr = err; gCd.lastErr = err;
gCd.st = gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCB_COLRES; gCd.st = RFAL_CD_ST_NFCB_COLRES;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCB_COLRES: case RFAL_CD_ST_NFCB_COLRES:
err = rfalNfcbPollerGetCollisionResolutionStatus(); err = rfalNfcbPollerGetCollisionResolutionStatus();
if (err != RFAL_ERR_BUSY) { if( err != RFAL_ERR_BUSY )
if ((err == RFAL_ERR_NONE) && {
(gCd.devCnt == if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
1U)) /* Collision resolution OK and a single card was found */
{ {
gCd.mulDevCnt++; gCd.mulDevCnt++;
gCd.techFound = RFAL_CD_TECH_NFCB; gCd.techFound = RFAL_CD_TECH_NFCB;
} }
/* Check if multiple cards or technologies have already been identified /* Check if multiple cards or technologies have already been identified */
*/ if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
if ((err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || {
(gCd.mulDevCnt > 1U)) {
gCd.res->detType = RFAL_CD_MULTIPLE_DEV; gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
} }
gCd.st = ((RFAL_SUPPORT_MODE_POLL_NFCF) gCd.st = ( (RFAL_SUPPORT_MODE_POLL_NFCF) ? RFAL_CD_ST_NFCF_INIT : RFAL_CD_ST_NFCV_INIT); /* Move to NFC-F or NFC-V */
? RFAL_CD_ST_NFCF_INIT
: RFAL_CD_ST_NFCV_INIT); /* Move to NFC-F or NFC-V */
} }
break; break;
#if RFAL_SUPPORT_MODE_POLL_NFCF #if RFAL_SUPPORT_MODE_POLL_NFCF
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCF_INIT: case RFAL_CD_ST_NFCF_INIT:
/* Verify if we are performing multi technology check */ /* Verify if we are performing multi technology check */
if ((gCd.skipTechFound) && (gCd.techFound == RFAL_CD_TECH_NFCF)) { 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 */ gCd.st = RFAL_CD_ST_PROPRIETARY; /* If single card card found before was NFC-F skip tech now */
break; break;
} }
rfalNfcfPollerInitialize(RFAL_BR_212); /* Initialize for NFC-F */ rfalNfcfPollerInitialize(RFAL_BR_212); /* Initialize for NFC-F */
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
timer */
gCd.st = RFAL_CD_ST_NFCF_TECHDET_START; gCd.st = RFAL_CD_ST_NFCF_TECHDET_START;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCF_TECHDET_START: case RFAL_CD_ST_NFCF_TECHDET_START:
if (!rfalIsGTExpired()) { if( !rfalIsGTExpired() )
{
break; /* Wait until GT has been fulfilled */ break; /* Wait until GT has been fulfilled */
} }
@ -407,79 +413,76 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_NFCF_TECHDET; gCd.st = RFAL_CD_ST_NFCF_TECHDET;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCF_TECHDET: case RFAL_CD_ST_NFCF_TECHDET:
err = rfalNfcfPollerGetCheckPresenceStatus(); err = rfalNfcfPollerGetCheckPresenceStatus();
if (err == RFAL_ERR_BUSY) { if( err == RFAL_ERR_BUSY )
{
break; /* Wait until NFC-F Technlogy Detection is completed */ break; /* Wait until NFC-F Technlogy Detection is completed */
} }
if (gCd.skipTechFound) /* Verify if we are performing multi technology if( gCd.skipTechFound ) /* Verify if we are performing multi technology check */
check */
{ {
gCd.st = RFAL_CD_ST_PROPRIETARY; gCd.st = RFAL_CD_ST_PROPRIETARY;
/* If single device was another technology and now NFC-F, otherwise /* If single device was another technology and now NFC-F, otherwise conclude*/
* conclude*/ if(err == RFAL_ERR_NONE)
if (err == RFAL_ERR_NONE) { {
gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH; gCd.res->detType = RFAL_CD_SINGLE_MULTI_TECH;
gCd.st = RFAL_CD_ST_NOT_DETECTED; gCd.st = RFAL_CD_ST_NOT_DETECTED;
} }
break; break;
} }
if (err == RFAL_ERR_NONE) { if( err == RFAL_ERR_NONE )
if (gCd.techFound != {
RFAL_CD_TECH_NONE) /* If on the first round check if other Tech was if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If on the first round check if other Tech was already found */
already found */
{ {
gCd.res->detType = RFAL_CD_MULTIPLE_TECH; gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
} }
gCd.st = RFAL_CD_ST_NFCF_COLRES_START; /* NFC-F detected, perform gCd.st = RFAL_CD_ST_NFCF_COLRES_START; /* NFC-F detected, perform collision resolution */
collision resolution */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCV_INIT; /* NFC-F not detected, move to NFC-V */ gCd.st = RFAL_CD_ST_NFCV_INIT; /* NFC-F not detected, move to NFC-V */
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCF_COLRES_START: case RFAL_CD_ST_NFCF_COLRES_START:
err = rfalNfcfPollerStartCollisionResolution(RFAL_COMPLIANCE_MODE_NFC, err = rfalNfcfPollerStartCollisionResolution( RFAL_COMPLIANCE_MODE_NFC, RFAL_CD_NFCF_DEVLIMIT, gCd.nfcfDev, &gCd.devCnt );
RFAL_CD_NFCF_DEVLIMIT, if( err != RFAL_ERR_NONE )
gCd.nfcfDev, &gCd.devCnt); {
if (err != RFAL_ERR_NONE) {
gCd.lastErr = err; gCd.lastErr = err;
gCd.st = gCd.st = RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
RFAL_CD_ST_ERROR; /* Collision resolution could not be performed */
break; break;
} }
gCd.st = RFAL_CD_ST_NFCF_COLRES; gCd.st = RFAL_CD_ST_NFCF_COLRES;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCF_COLRES: case RFAL_CD_ST_NFCF_COLRES:
err = rfalNfcfPollerGetCollisionResolutionStatus(); err = rfalNfcfPollerGetCollisionResolutionStatus();
if (err != RFAL_ERR_BUSY) { if( err != RFAL_ERR_BUSY )
if ((err == RFAL_ERR_NONE) && {
(gCd.devCnt == if( (err == RFAL_ERR_NONE) && (gCd.devCnt == 1U) ) /* Collision resolution OK and a single card was found */
1U)) /* Collision resolution OK and a single card was found */
{ {
gCd.mulDevCnt++; gCd.mulDevCnt++;
gCd.techFound = RFAL_CD_TECH_NFCF; gCd.techFound = RFAL_CD_TECH_NFCF;
} }
/* Check if multiple cards or technologies have already been identified /* Check if multiple cards or technologies have already been identified */
*/ if( (err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || (gCd.mulDevCnt > 1U) )
if ((err != RFAL_ERR_NONE) || (gCd.devCnt > 1U) || {
(gCd.mulDevCnt > 1U)) {
gCd.res->detType = RFAL_CD_MULTIPLE_DEV; gCd.res->detType = RFAL_CD_MULTIPLE_DEV;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
@ -494,8 +497,7 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
case RFAL_CD_ST_NFCV_INIT: case RFAL_CD_ST_NFCV_INIT:
rfalNfcvPollerInitialize(); /* Initialize for NFC-V */ rfalNfcvPollerInitialize(); /* Initialize for NFC-V */
rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
timer */
gCd.st = RFAL_CD_ST_NFCV_TECHDET; gCd.st = RFAL_CD_ST_NFCV_TECHDET;
break; break;
@ -503,32 +505,31 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_NFCV_TECHDET: case RFAL_CD_ST_NFCV_TECHDET:
if (!rfalIsGTExpired()) { if( !rfalIsGTExpired() )
{
break; /* Wait until GT has been fulfilled */ break; /* Wait until GT has been fulfilled */
} }
err = rfalNfcvPollerCheckPresence( &invRes ); err = rfalNfcvPollerCheckPresence( &invRes );
if (err == RFAL_ERR_NONE) { if( err == RFAL_ERR_NONE )
if (gCd.techFound != {
RFAL_CD_TECH_NONE) /* If other Tech was already found */ if( gCd.techFound != RFAL_CD_TECH_NONE ) /* If other Tech was already found */
{ {
gCd.res->detType = RFAL_CD_MULTIPLE_TECH; gCd.res->detType = RFAL_CD_MULTIPLE_TECH;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
} }
gCd.techFound = gCd.techFound = RFAL_CD_TECH_NFCV; /* If NFC-V is regarded as card as CE NFC-V is currently not supported by active devices */
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.res->detType = RFAL_CD_CARD_TECH;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
} }
gCd.st = gCd.st = RFAL_CD_ST_PROPRIETARY; /* Move to Proprietary NFC Technologies */
RFAL_CD_ST_PROPRIETARY; /* Move to Proprietary NFC Technologies */
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_PROPRIETARY: case RFAL_CD_ST_PROPRIETARY:
@ -536,12 +537,13 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
platformTimerDestroy( gCd.tmr ); platformTimerDestroy( gCd.tmr );
gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) ); gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
/* If none of the other NFC technologies was not seen on a second round, /* If none of the other NFC technologies was not seen on a second round, regard as card */
* regard as card */ if( gCd.skipTechFound )
if (gCd.skipTechFound) { {
gCd.res->detType = RFAL_CD_SINGLE_DEV; gCd.res->detType = RFAL_CD_SINGLE_DEV;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
/*******************************************************************************/ /*******************************************************************************/
/* Only one device found which does not support NFC-DEP and only * /* Only one device found which does not support NFC-DEP and only *
* answered in one technology, perform heartbeat detection */ * answered in one technology, perform heartbeat detection */
@ -558,41 +560,41 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_ST25TB_INIT; gCd.st = RFAL_CD_ST_ST25TB_INIT;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_ST25TB_INIT: case RFAL_CD_ST_ST25TB_INIT:
if ((!platformTimerIsExpired( if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
gCd.tmr))) /* Check if field has been Off long enough */
{ {
break; break;
} }
rfalSt25tbPollerInitialize(); /* Initialize for ST25TB */ rfalSt25tbPollerInitialize(); /* Initialize for ST25TB */
err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and err = rfalFieldOnAndStartGT(); /* Turns the Field On if not already and start GT timer */
start GT timer */
if (err != RFAL_ERR_NONE) { if( err != RFAL_ERR_NONE )
{
gCd.lastErr = err; gCd.lastErr = err;
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
continue Card Detection */
break; break;
} }
gCd.st = RFAL_CD_ST_ST25TB_TECHDET; gCd.st = RFAL_CD_ST_ST25TB_TECHDET;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_ST25TB_TECHDET: case RFAL_CD_ST_ST25TB_TECHDET:
if ((!rfalIsGTExpired())) { if( (!rfalIsGTExpired()) )
{
break; /* Wait until GT has been fulfilled */ break; /* Wait until GT has been fulfilled */
} }
err = rfalSt25tbPollerCheckPresence( NULL ); err = rfalSt25tbPollerCheckPresence( NULL );
if (err == RFAL_ERR_NONE) { if( err == RFAL_ERR_NONE )
gCd.techFound = {
RFAL_CD_TECH_OTHER; /* If ST25TB is regarded as card as CE is not gCd.techFound = RFAL_CD_TECH_OTHER; /* If ST25TB is regarded as card as CE is not supported by active devices */
supported by active devices */
gCd.res->detType = RFAL_CD_CARD_TECH; gCd.res->detType = RFAL_CD_CARD_TECH;
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
@ -601,6 +603,7 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_CHECK_PROTO; gCd.st = RFAL_CD_ST_CHECK_PROTO;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_CHECK_PROTO: case RFAL_CD_ST_CHECK_PROTO:
@ -614,25 +617,20 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
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 */ /* Check if it supports NFC-DEP protocol */
if (((gCd.techFound == RFAL_CD_TECH_NFCA) && if( ( (gCd.techFound == RFAL_CD_TECH_NFCA) && ((gCd.nfcaDev.type == RFAL_NFCA_NFCDEP) || (gCd.nfcaDev.type == RFAL_NFCA_T4T_NFCDEP)) ) ||
((gCd.nfcaDev.type == RFAL_NFCA_NFCDEP) || ( (gCd.techFound == RFAL_CD_TECH_NFCF) && rfalNfcfIsNfcDepSupported( &gCd.nfcfDev[0] ) ) )
(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.res->detType = RFAL_CD_SINGLE_P2P;
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* NFC-DEP supported, regarded as gCd.st = RFAL_CD_ST_NOT_DETECTED;/* NFC-DEP supported, regarded as non passive card */
non passive card */
break; break;
} }
/* If a single NFC listener has been detected, and did not announce /* If a single NFC listener has been detected, and did not announce NFC-DEP support, *
* NFC-DEP support, * check if it supports mutiple NFC technologies * check if it supports mutiple NFC technologies (skip the one it was previous seen) */
* (skip the one it was previous seen) */
gCd.skipTechFound = true; gCd.skipTechFound = true;
gCd.st = RFAL_CD_ST_NFCA_INIT; gCd.st = RFAL_CD_ST_NFCA_INIT;
/* Reset Field once again to avoid unwanted effect of Proprietary NFC /* Reset Field once again to avoid unwanted effect of Proprietary NFC Tech modulation */
* Tech modulation */
rfalFieldOff(); rfalFieldOff();
platformTimerDestroy( gCd.tmr ); platformTimerDestroy( gCd.tmr );
gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) ); gCd.tmr = platformTimerCreate( (uint8_t)rfalConv1fcToMs(RFAL_GT_NFCA) );
@ -643,17 +641,18 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
gCd.st = RFAL_CD_ST_DETECTED; gCd.st = RFAL_CD_ST_DETECTED;
break; break;
#ifdef RFAL_CD_HB #ifdef RFAL_CD_HB
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_HB_START: case RFAL_CD_ST_HB_START:
if ((!platformTimerIsExpired( if( (!platformTimerIsExpired( gCd.tmr )) ) /* Check if field has been Off long enough */
gCd.tmr))) /* Check if field has been Off long enough */
{ {
break; break;
} }
switch (gCd.techFound) { switch( gCd.techFound )
{
case RFAL_CD_TECH_NFCF: case RFAL_CD_TECH_NFCF:
rfalNfcfPollerInitialize( RFAL_BR_212 ); rfalNfcfPollerInitialize( RFAL_BR_212 );
break; break;
@ -669,16 +668,17 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
} }
err = rfalFieldOnAndStartGT(); err = rfalFieldOnAndStartGT();
if (err != RFAL_ERR_NONE) { if( err != RFAL_ERR_NONE )
{
gCd.lastErr = err; gCd.lastErr = err;
gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot gCd.st = RFAL_CD_ST_ERROR; /* Unable to turn the field On, cannot continue Card Detection */
continue Card Detection */
break; break;
} }
gCd.st = RFAL_CD_ST_HB; gCd.st = RFAL_CD_ST_HB;
break; break;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_HB: case RFAL_CD_ST_HB:
if( !rfalIsGTExpired() ) /* Check if GT has been fulfilled */ if( !rfalIsGTExpired() ) /* Check if GT has been fulfilled */
@ -686,21 +686,19 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
break; break;
} }
if (rfalCdHbDetect( if( rfalCdHbDetect( gCd.techFound ) ) /* Perform tha heartbeat detection sequence */
gCd.techFound)) /* Perform tha heartbeat detection sequence */
{ {
gCd.res->detType = RFAL_CD_SINGLE_HB; gCd.res->detType = RFAL_CD_SINGLE_HB;
gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device performing ALM, no gCd.st = RFAL_CD_ST_NOT_DETECTED; /* Single device performing ALM, no passive card */
passive card */
break; break;
} }
gCd.res->detType = RFAL_CD_SINGLE_DEV; gCd.res->detType = RFAL_CD_SINGLE_DEV;
gCd.st = RFAL_CD_ST_DETECTED; /* ALM not detected on single device, regard gCd.st = RFAL_CD_ST_DETECTED; /* ALM not detected on single device, regard as card */
as card */
break; break;
#endif /* RFAL_CD_HB */ #endif /* RFAL_CD_HB */
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_DETECTED: case RFAL_CD_ST_DETECTED:
case RFAL_CD_ST_NOT_DETECTED: case RFAL_CD_ST_NOT_DETECTED:
@ -713,22 +711,24 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
return RFAL_ERR_NONE; return RFAL_ERR_NONE;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_IDLE: case RFAL_CD_ST_IDLE:
return RFAL_ERR_WRONG_STATE; return RFAL_ERR_WRONG_STATE;
/*******************************************************************************/ /*******************************************************************************/
case RFAL_CD_ST_ERROR: case RFAL_CD_ST_ERROR:
gCd.res->detType = RFAL_CD_UNKOWN; gCd.res->detType = RFAL_CD_UNKOWN;
gCd.res->detected = gCd.res->detected = true; /* Error ocurred, mark as card present to avoid damage */
true; /* Error ocurred, mark as card present to avoid damage */
rfalFieldOff(); rfalFieldOff();
gCd.st = RFAL_CD_ST_IDLE; gCd.st = RFAL_CD_ST_IDLE;
return gCd.lastErr; return gCd.lastErr;
/*******************************************************************************/ /*******************************************************************************/
default: default:
return RFAL_ERR_INTERNAL; return RFAL_ERR_INTERNAL;
@ -736,3 +736,4 @@ ReturnCode rfalCdGetDetectCardStatus(void) {
return RFAL_ERR_BUSY; return RFAL_ERR_BUSY;
} }

File diff suppressed because it is too large Load Diff