2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* \attention
|
|
|
|
*
|
|
|
|
* <h2><center>© COPYRIGHT 2020 STMicroelectronics</center></h2>
|
|
|
|
*
|
|
|
|
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* www.st.com/myliberty
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
|
|
|
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PROJECT: ST25R391x firmware
|
|
|
|
* Revision:
|
|
|
|
* LANGUAGE: ISO C99
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file rfal_nfcb.c
|
|
|
|
*
|
|
|
|
* \author Gustavo Patricio
|
|
|
|
*
|
|
|
|
* \brief Implementation of NFC-B (ISO14443B) helpers
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* INCLUDES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
#include "rfal_nfcb.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* ENABLE SWITCH
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RFAL_FEATURE_NFCB
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_FEATURE_NFCB false /* NFC-B module configuration missing. Disabled by default */
|
2021-10-17 22:54:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RFAL_FEATURE_NFCB
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL DEFINES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_NFCB_SENSB_REQ_EXT_SENSB_RES_SUPPORTED \
|
|
|
|
0x10U /*!< Bit mask for Extended SensB Response support in SENSB_REQ */
|
|
|
|
#define RFAL_NFCB_SENSB_RES_PROT_TYPE_RFU \
|
|
|
|
0x08U /*!< Bit mask for Protocol Type RFU in SENSB_RES */
|
|
|
|
#define RFAL_NFCB_SLOT_MARKER_SC_SHIFT \
|
|
|
|
4U /*!< Slot Code position on SLOT_MARKER APn */
|
2021-10-17 22:54:19 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_NFCB_SLOTMARKER_SLOTCODE_MIN \
|
|
|
|
1U /*!< SLOT_MARKER Slot Code minimum Digital 1.1 Table 37 */
|
|
|
|
#define RFAL_NFCB_SLOTMARKER_SLOTCODE_MAX \
|
|
|
|
16U /*!< SLOT_MARKER Slot Code maximum Digital 1.1 Table 37 */
|
2021-10-17 22:54:19 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_NFCB_ACTIVATION_FWT \
|
|
|
|
(RFAL_NFCB_FWTSENSB + RFAL_NFCB_DTPOLL_20) /*!< FWT(SENSB) + dTbPoll Digital 2.0 7.9.1.3 */
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*! Advanced and Extended bit mask in Parameter of SENSB_REQ */
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_NFCB_SENSB_REQ_PARAM \
|
|
|
|
(RFAL_NFCB_SENSB_REQ_ADV_FEATURE | RFAL_NFCB_SENSB_REQ_EXT_SENSB_RES_SUPPORTED)
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*! NFC-B commands definition */
|
2022-01-05 16:10:18 +00:00
|
|
|
enum {
|
|
|
|
RFAL_NFCB_CMD_SENSB_REQ = 0x05, /*!< SENSB_REQ (REQB) & SLOT_MARKER Digital 1.1 Table 24 */
|
|
|
|
RFAL_NFCB_CMD_SENSB_RES = 0x50, /*!< SENSB_RES (ATQB) & SLOT_MARKER Digital 1.1 Table 27 */
|
|
|
|
RFAL_NFCB_CMD_SLPB_REQ = 0x50, /*!< SLPB_REQ (HLTB command) Digital 1.1 Table 38 */
|
|
|
|
RFAL_NFCB_CMD_SLPB_RES = 0x00 /*!< SLPB_RES (HLTB Answer) Digital 1.1 Table 39 */
|
2021-10-17 22:54:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL MACROS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#define rfalNfcbNI2NumberOfSlots(ni) \
|
|
|
|
(uint8_t)(1U << (ni)) /*!< Converts the Number of slots Identifier to slot number */
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL TYPES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! ALLB_REQ (WUPB) and SENSB_REQ (REQB) Command Format Digital 1.1 7.6.1 */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t cmd; /*!< xxxxB_REQ: 05h */
|
|
|
|
uint8_t AFI; /*!< NFC Identifier */
|
|
|
|
uint8_t PARAM; /*!< Application Data */
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcbSensbReq;
|
|
|
|
|
|
|
|
/*! SLOT_MARKER Command format Digital 1.1 7.7.1 */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t APn; /*!< Slot number 2..16 | 0101b */
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcbSlotMarker;
|
|
|
|
|
|
|
|
/*! SLPB_REQ (HLTB) Command Format Digital 1.1 7.8.1 */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t cmd; /*!< SLPB_REQ: 50h */
|
|
|
|
uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcbSlpbReq;
|
|
|
|
|
|
|
|
/*! SLPB_RES (HLTB) Response Format Digital 1.1 7.8.2 */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t cmd; /*!< SLPB_RES: 00h */
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcbSlpbRes;
|
|
|
|
|
|
|
|
/*! RFAL NFC-B instance */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t AFI; /*!< AFI to be used */
|
|
|
|
uint8_t PARAM; /*!< PARAM to be used */
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL FUNCTION PROTOTYPES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
static ReturnCode rfalNfcbCheckSensbRes(const rfalNfcbSensbRes* sensbRes, uint8_t sensbResLen);
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL VARIABLES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
static rfalNfcb gRfalNfcb; /*!< RFAL NFC-B Instance */
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL FUNCTIONS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
static ReturnCode rfalNfcbCheckSensbRes(const rfalNfcbSensbRes* sensbRes, uint8_t sensbResLen) {
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Check response length */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(((sensbResLen != RFAL_NFCB_SENSB_RES_LEN) &&
|
|
|
|
(sensbResLen != RFAL_NFCB_SENSB_RES_EXT_LEN))) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_PROTO;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Check SENSB_RES and Protocol Type Digital 1.1 7.6.2.19 */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(((sensbRes->protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROT_TYPE_RFU) != 0U) ||
|
|
|
|
(sensbRes->cmd != (uint8_t)RFAL_NFCB_CMD_SENSB_RES)) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_PROTO;
|
|
|
|
}
|
|
|
|
return ERR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalNfcbPollerInitialize(void) {
|
2021-10-17 22:54:19 +00:00
|
|
|
ReturnCode ret;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
EXIT_ON_ERR(ret, rfalSetMode(RFAL_MODE_POLL_NFCB, RFAL_BR_106, RFAL_BR_106));
|
|
|
|
rfalSetErrorHandling(RFAL_ERRORHANDLING_NFC);
|
|
|
|
|
|
|
|
rfalSetGT(RFAL_GT_NFCB);
|
|
|
|
rfalSetFDTListen(RFAL_FDT_LISTEN_NFCB_POLLER);
|
|
|
|
rfalSetFDTPoll(RFAL_FDT_POLL_NFCB_POLLER);
|
|
|
|
|
|
|
|
gRfalNfcb.AFI = RFAL_NFCB_AFI;
|
|
|
|
gRfalNfcb.PARAM = RFAL_NFCB_PARAM;
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalNfcbPollerInitializeWithParams(uint8_t AFI, uint8_t PARAM) {
|
2021-10-17 22:54:19 +00:00
|
|
|
ReturnCode ret;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
EXIT_ON_ERR(ret, rfalNfcbPollerInitialize());
|
|
|
|
|
|
|
|
gRfalNfcb.AFI = AFI;
|
2021-10-17 22:54:19 +00:00
|
|
|
gRfalNfcb.PARAM = (PARAM & RFAL_NFCB_SENSB_REQ_PARAM);
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalNfcbPollerCheckPresence(
|
|
|
|
rfalNfcbSensCmd cmd,
|
|
|
|
rfalNfcbSlots slots,
|
|
|
|
rfalNfcbSensbRes* sensbRes,
|
|
|
|
uint8_t* sensbResLen) {
|
|
|
|
uint16_t rxLen;
|
|
|
|
ReturnCode ret;
|
2021-10-17 22:54:19 +00:00
|
|
|
rfalNfcbSensbReq sensbReq;
|
|
|
|
|
|
|
|
/* Check if the command requested and given the slot number are valid */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(((RFAL_NFCB_SENS_CMD_SENSB_REQ != cmd) && (RFAL_NFCB_SENS_CMD_ALLB_REQ != cmd)) ||
|
|
|
|
(slots > RFAL_NFCB_SLOT_NUM_16) || (sensbRes == NULL) || (sensbResLen == NULL)) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_PARAM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
*sensbResLen = 0;
|
2022-01-05 16:10:18 +00:00
|
|
|
ST_MEMSET(sensbRes, 0x00, sizeof(rfalNfcbSensbRes));
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Compute SENSB_REQ */
|
2022-01-05 16:10:18 +00:00
|
|
|
sensbReq.cmd = RFAL_NFCB_CMD_SENSB_REQ;
|
|
|
|
sensbReq.AFI = gRfalNfcb.AFI;
|
|
|
|
sensbReq.PARAM =
|
|
|
|
(((uint8_t)gRfalNfcb.PARAM & RFAL_NFCB_SENSB_REQ_PARAM) | (uint8_t)cmd | (uint8_t)slots);
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Send SENSB_REQ and disable AGC to detect collisions */
|
2022-01-05 16:10:18 +00:00
|
|
|
ret = rfalTransceiveBlockingTxRx(
|
|
|
|
(uint8_t*)&sensbReq,
|
|
|
|
sizeof(rfalNfcbSensbReq),
|
|
|
|
(uint8_t*)sensbRes,
|
|
|
|
sizeof(rfalNfcbSensbRes),
|
|
|
|
&rxLen,
|
|
|
|
RFAL_TXRX_FLAGS_DEFAULT,
|
|
|
|
RFAL_NFCB_FWTSENSB);
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
*sensbResLen = (uint8_t)rxLen;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Check if a transmission error was detected */
|
2022-01-05 16:10:18 +00:00
|
|
|
if((ret == ERR_CRC) || (ret == ERR_FRAMING)) {
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Invalidate received frame as an error was detected (CollisionResolution checks if valid) */
|
|
|
|
*sensbResLen = 0;
|
|
|
|
return ERR_NONE;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
if(ret == ERR_NONE) {
|
|
|
|
return rfalNfcbCheckSensbRes(sensbRes, *sensbResLen);
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalNfcbPollerSleep(const uint8_t* nfcid0) {
|
|
|
|
uint16_t rxLen;
|
|
|
|
ReturnCode ret;
|
2021-10-17 22:54:19 +00:00
|
|
|
rfalNfcbSlpbReq slpbReq;
|
|
|
|
rfalNfcbSlpbRes slpbRes;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
if(nfcid0 == NULL) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_PARAM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Compute SLPB_REQ */
|
|
|
|
slpbReq.cmd = RFAL_NFCB_CMD_SLPB_REQ;
|
2022-01-05 16:10:18 +00:00
|
|
|
ST_MEMCPY(slpbReq.nfcid0, nfcid0, RFAL_NFCB_NFCID0_LEN);
|
|
|
|
|
|
|
|
EXIT_ON_ERR(
|
|
|
|
ret,
|
|
|
|
rfalTransceiveBlockingTxRx(
|
|
|
|
(uint8_t*)&slpbReq,
|
|
|
|
sizeof(rfalNfcbSlpbReq),
|
|
|
|
(uint8_t*)&slpbRes,
|
|
|
|
sizeof(rfalNfcbSlpbRes),
|
|
|
|
&rxLen,
|
|
|
|
RFAL_TXRX_FLAGS_DEFAULT,
|
|
|
|
RFAL_NFCB_ACTIVATION_FWT));
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Check SLPB_RES */
|
2022-01-05 16:10:18 +00:00
|
|
|
if((rxLen != sizeof(rfalNfcbSlpbRes)) || (slpbRes.cmd != (uint8_t)RFAL_NFCB_CMD_SLPB_RES)) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_PROTO;
|
|
|
|
}
|
|
|
|
return ERR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode
|
|
|
|
rfalNfcbPollerSlotMarker(uint8_t slotCode, rfalNfcbSensbRes* sensbRes, uint8_t* sensbResLen) {
|
|
|
|
ReturnCode ret;
|
2021-10-17 22:54:19 +00:00
|
|
|
rfalNfcbSlotMarker slotMarker;
|
2022-01-05 16:10:18 +00:00
|
|
|
uint16_t rxLen;
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Check parameters */
|
2022-01-05 16:10:18 +00:00
|
|
|
if((sensbRes == NULL) || (sensbResLen == NULL) ||
|
|
|
|
(slotCode < RFAL_NFCB_SLOTMARKER_SLOTCODE_MIN) ||
|
|
|
|
(slotCode > RFAL_NFCB_SLOTMARKER_SLOTCODE_MAX)) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_PARAM;
|
|
|
|
}
|
|
|
|
/* Compose and send SLOT_MARKER with disabled AGC to detect collisions */
|
2022-01-05 16:10:18 +00:00
|
|
|
slotMarker.APn =
|
|
|
|
((slotCode << RFAL_NFCB_SLOT_MARKER_SC_SHIFT) | (uint8_t)RFAL_NFCB_CMD_SENSB_REQ);
|
|
|
|
|
|
|
|
ret = rfalTransceiveBlockingTxRx(
|
|
|
|
(uint8_t*)&slotMarker,
|
|
|
|
sizeof(rfalNfcbSlotMarker),
|
|
|
|
(uint8_t*)sensbRes,
|
|
|
|
sizeof(rfalNfcbSensbRes),
|
|
|
|
&rxLen,
|
|
|
|
RFAL_TXRX_FLAGS_DEFAULT,
|
|
|
|
RFAL_NFCB_ACTIVATION_FWT);
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
*sensbResLen = (uint8_t)rxLen;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Check if a transmission error was detected */
|
2022-01-05 16:10:18 +00:00
|
|
|
if((ret == ERR_CRC) || (ret == ERR_FRAMING)) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ERR_RF_COLLISION;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
if(ret == ERR_NONE) {
|
|
|
|
return rfalNfcbCheckSensbRes(sensbRes, *sensbResLen);
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalNfcbPollerTechnologyDetection(
|
|
|
|
rfalComplianceMode compMode,
|
|
|
|
rfalNfcbSensbRes* sensbRes,
|
|
|
|
uint8_t* sensbResLen) {
|
2021-10-17 22:54:19 +00:00
|
|
|
NO_WARNING(compMode);
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
return rfalNfcbPollerCheckPresence(
|
|
|
|
RFAL_NFCB_SENS_CMD_SENSB_REQ, RFAL_NFCB_SLOT_NUM_1, sensbRes, sensbResLen);
|
|
|
|
}
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalNfcbPollerCollisionResolution(
|
|
|
|
rfalComplianceMode compMode,
|
|
|
|
uint8_t devLimit,
|
|
|
|
rfalNfcbListenDevice* nfcbDevList,
|
|
|
|
uint8_t* devCnt) {
|
2021-10-17 22:54:19 +00:00
|
|
|
bool colPending; /* dummy */
|
2022-01-05 16:10:18 +00:00
|
|
|
return rfalNfcbPollerSlottedCollisionResolution(
|
|
|
|
compMode,
|
|
|
|
devLimit,
|
|
|
|
RFAL_NFCB_SLOT_NUM_1,
|
|
|
|
RFAL_NFCB_SLOT_NUM_16,
|
|
|
|
nfcbDevList,
|
|
|
|
devCnt,
|
|
|
|
&colPending);
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalNfcbPollerSlottedCollisionResolution(
|
|
|
|
rfalComplianceMode compMode,
|
|
|
|
uint8_t devLimit,
|
|
|
|
rfalNfcbSlots initSlots,
|
|
|
|
rfalNfcbSlots endSlots,
|
|
|
|
rfalNfcbListenDevice* nfcbDevList,
|
|
|
|
uint8_t* devCnt,
|
|
|
|
bool* colPending) {
|
|
|
|
ReturnCode ret;
|
|
|
|
uint8_t slotsNum;
|
|
|
|
uint8_t slotCode;
|
|
|
|
uint8_t curDevCnt;
|
|
|
|
|
|
|
|
/* Check parameters. In ISO | Activity 1.0 mode the initial slots must be 1 as continuation of Technology Detection */
|
|
|
|
if((nfcbDevList == NULL) || (devCnt == NULL) || (colPending == NULL) ||
|
|
|
|
(initSlots > RFAL_NFCB_SLOT_NUM_16) || (endSlots > RFAL_NFCB_SLOT_NUM_16) ||
|
|
|
|
((compMode == RFAL_COMPLIANCE_MODE_ISO) && (initSlots != RFAL_NFCB_SLOT_NUM_1))) {
|
|
|
|
return ERR_PARAM;
|
|
|
|
}
|
2021-10-17 22:54:19 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
/* Initialise as no error in case Activity 1.0 where the previous SENSB_RES from technology detection should be used */
|
|
|
|
ret = ERR_NONE;
|
|
|
|
*devCnt = 0;
|
|
|
|
curDevCnt = 0;
|
|
|
|
*colPending = false;
|
|
|
|
|
|
|
|
/* Send ALLB_REQ Activity 1.1 9.3.5.2 and 9.3.5.3 (Symbol 1 and 2) */
|
|
|
|
if(compMode != RFAL_COMPLIANCE_MODE_ISO) {
|
|
|
|
ret = rfalNfcbPollerCheckPresence(
|
|
|
|
RFAL_NFCB_SENS_CMD_ALLB_REQ,
|
|
|
|
initSlots,
|
|
|
|
&nfcbDevList->sensbRes,
|
|
|
|
&nfcbDevList->sensbResLen);
|
|
|
|
if((ret != ERR_NONE) && (initSlots == RFAL_NFCB_SLOT_NUM_1)) {
|
|
|
|
return ret;
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if there was a transmission error on WUPB EMVCo 2.6 9.3.3.1 */
|
|
|
|
if((compMode == RFAL_COMPLIANCE_MODE_EMV) && (nfcbDevList->sensbResLen == 0U)) {
|
|
|
|
return ERR_FRAMING;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(slotsNum = (uint8_t)initSlots; slotsNum <= (uint8_t)endSlots; slotsNum++) {
|
|
|
|
do {
|
|
|
|
/* Activity 1.1 9.3.5.23 - Symbol 22 */
|
|
|
|
if((compMode == RFAL_COMPLIANCE_MODE_NFC) && (curDevCnt != 0U)) {
|
|
|
|
rfalNfcbPollerSleep(nfcbDevList[((*devCnt) - (uint8_t)1U)].sensbRes.nfcid0);
|
|
|
|
nfcbDevList[((*devCnt) - (uint8_t)1U)].isSleep = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send SENSB_REQ with number of slots if not the first Activity 1.1 9.3.5.24 - Symbol 23 */
|
|
|
|
if((slotsNum != (uint8_t)initSlots) || *colPending) {
|
|
|
|
/* PRQA S 4342 1 # MISRA 10.5 - Layout of rfalNfcbSlots and above loop guarantee that no invalid enum values are created. */
|
|
|
|
ret = rfalNfcbPollerCheckPresence(
|
|
|
|
RFAL_NFCB_SENS_CMD_SENSB_REQ,
|
|
|
|
(rfalNfcbSlots)slotsNum,
|
|
|
|
&nfcbDevList[*devCnt].sensbRes,
|
|
|
|
&nfcbDevList[*devCnt].sensbResLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Activity 1.1 9.3.5.6 - Symbol 5 */
|
|
|
|
slotCode = 0;
|
|
|
|
curDevCnt = 0;
|
|
|
|
*colPending = false;
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
do {
|
2022-01-05 16:10:18 +00:00
|
|
|
/* Activity 1.1 9.3.5.26 - Symbol 25 */
|
|
|
|
if(slotCode != 0U) {
|
|
|
|
ret = rfalNfcbPollerSlotMarker(
|
|
|
|
slotCode,
|
|
|
|
&nfcbDevList[*devCnt].sensbRes,
|
|
|
|
&nfcbDevList[*devCnt].sensbResLen);
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
/* Activity 1.1 9.3.5.7 and 9.3.5.8 - Symbol 6 */
|
|
|
|
if(ret != ERR_TIMEOUT) {
|
|
|
|
/* Activity 1.1 9.3.5.8 - Symbol 7 */
|
|
|
|
if((rfalNfcbCheckSensbRes(
|
|
|
|
&nfcbDevList[*devCnt].sensbRes, nfcbDevList[*devCnt].sensbResLen) ==
|
|
|
|
ERR_NONE) &&
|
|
|
|
(ret == ERR_NONE)) {
|
|
|
|
nfcbDevList[*devCnt].isSleep = false;
|
|
|
|
|
|
|
|
if(compMode == RFAL_COMPLIANCE_MODE_EMV) {
|
|
|
|
(*devCnt)++;
|
|
|
|
return ret;
|
|
|
|
} else if(compMode == RFAL_COMPLIANCE_MODE_ISO) {
|
|
|
|
/* Activity 1.0 9.3.5.8 - Symbol 7 */
|
|
|
|
(*devCnt)++;
|
|
|
|
curDevCnt++;
|
|
|
|
|
|
|
|
/* Activity 1.0 9.3.5.10 - Symbol 9 */
|
|
|
|
if((*devCnt >= devLimit) ||
|
|
|
|
(slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1)) {
|
2021-10-17 22:54:19 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
/* Activity 1.0 9.3.5.11 - Symbol 10 */
|
|
|
|
rfalNfcbPollerSleep(nfcbDevList[*devCnt - 1U].sensbRes.nfcid0);
|
|
|
|
nfcbDevList[*devCnt - 1U].isSleep = true;
|
|
|
|
} else if(compMode == RFAL_COMPLIANCE_MODE_NFC) {
|
|
|
|
/* Activity 1.1 9.3.5.10 and 9.3.5.11 - Symbol 9 and Symbol 11*/
|
|
|
|
if(curDevCnt != 0U) {
|
|
|
|
rfalNfcbPollerSleep(
|
|
|
|
nfcbDevList[(*devCnt) - (uint8_t)1U].sensbRes.nfcid0);
|
|
|
|
nfcbDevList[(*devCnt) - (uint8_t)1U].isSleep = true;
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
/* Activity 1.1 9.3.5.12 - Symbol 11 */
|
|
|
|
(*devCnt)++;
|
|
|
|
curDevCnt++;
|
|
|
|
|
|
|
|
/* Activity 1.1 9.3.5.6 - Symbol 13 */
|
|
|
|
if((*devCnt >= devLimit) ||
|
|
|
|
(slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1)) {
|
|
|
|
return ret;
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
} else {
|
|
|
|
/* MISRA 15.7 - Empty else */
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
} else {
|
|
|
|
/* If deviceLimit is set to 0 the NFC Forum Device is configured to perform collision detection only Activity 1.0 and 1.1 9.3.5.5 - Symbol 4 */
|
|
|
|
if((devLimit == 0U) && (slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1)) {
|
|
|
|
return ERR_RF_COLLISION;
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
/* Activity 1.1 9.3.5.9 - Symbol 8 */
|
|
|
|
*colPending = true;
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
/* Activity 1.1 9.3.5.15 - Symbol 14 */
|
|
|
|
slotCode++;
|
|
|
|
} while(slotCode < rfalNfcbNI2NumberOfSlots(slotsNum));
|
|
|
|
|
|
|
|
/* Activity 1.1 9.3.5.17 - Symbol 16 */
|
|
|
|
if(!(*colPending)) {
|
|
|
|
return ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2021-10-17 22:54:19 +00:00
|
|
|
/* Activity 1.1 9.3.5.18 - Symbol 17 */
|
2022-01-05 16:10:18 +00:00
|
|
|
} while(
|
|
|
|
curDevCnt !=
|
|
|
|
0U); /* If a collision is detected and card(s) were found on this loop keep the same number of available slots */
|
|
|
|
}
|
2021-10-17 22:54:19 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
return ERR_NONE;
|
|
|
|
}
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
uint32_t rfalNfcbTR2ToFDT(uint8_t tr2Code) {
|
2021-10-17 22:54:19 +00:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* MISRA 8.9 An object should be defined at block scope if its identifier only appears in a single function */
|
|
|
|
/*! TR2 Table according to Digital 1.1 Table 33 */
|
2022-01-05 16:10:18 +00:00
|
|
|
const uint16_t rfalNfcbTr2Table[] = {1792, 3328, 5376, 9472};
|
2021-10-17 22:54:19 +00:00
|
|
|
/*******************************************************************************/
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
return rfalNfcbTr2Table[(tr2Code & RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK)];
|
2021-10-17 22:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* RFAL_FEATURE_NFCB */
|