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_nfcf.c
|
|
|
|
*
|
|
|
|
* \author Gustavo Patricio
|
|
|
|
*
|
|
|
|
* \brief Implementation of NFC-F Poller (FeliCa PCD) device
|
|
|
|
*
|
|
|
|
* The definitions and helpers methods provided by this module are
|
|
|
|
* aligned with NFC-F (FeliCa - JIS X6319-4)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* INCLUDES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
#include "rfal_nfcf.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* ENABLE SWITCH
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RFAL_FEATURE_NFCF
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_FEATURE_NFCF false /* NFC-F module configuration missing. Disabled by default */
|
2021-10-17 22:54:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if RFAL_FEATURE_NFCF
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL DEFINES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_NFCF_SENSF_REQ_LEN_MIN \
|
|
|
|
5U /*!< SENSF_RES minimum length */
|
|
|
|
|
|
|
|
#define RFAL_NFCF_READ_WO_ENCRYPTION_MIN_LEN \
|
|
|
|
15U /*!< Minimum length for a Check Command T3T 5.4.1 */
|
|
|
|
#define RFAL_NFCF_WRITE_WO_ENCRYPTION_MIN_LEN \
|
|
|
|
31U /*!< Minimum length for an Update Command T3T 5.5.1 */
|
|
|
|
|
|
|
|
#define RFAL_NFCF_CHECK_RES_MIN_LEN \
|
|
|
|
11U /*!< CHECK Response minimum length T3T 1.0 Table 8 */
|
|
|
|
#define RFAL_NFCF_UPDATE_RES_MIN_LEN \
|
|
|
|
11U /*!< UPDATE Response minimum length T3T 1.0 Table 8 */
|
|
|
|
|
|
|
|
#define RFAL_NFCF_CHECK_REQ_MAX_LEN \
|
|
|
|
86U /*!< Max length of a Check request T3T 1.0 Table 7 */
|
|
|
|
#define RFAL_NFCF_CHECK_REQ_MAX_SERV \
|
|
|
|
15U /*!< Max Services number on Check request T3T 1.0 5.4.1.5 */
|
|
|
|
#define RFAL_NFCF_CHECK_REQ_MAX_BLOCK \
|
|
|
|
15U /*!< Max Blocks number on Check request T3T 1.0 5.4.1.10 */
|
|
|
|
#define RFAL_NFCF_UPDATE_REQ_MAX_SERV \
|
|
|
|
15U /*!< Max Services number Update request T3T 1.0 5.4.1.5 */
|
|
|
|
#define RFAL_NFCF_UPDATE_REQ_MAX_BLOCK \
|
|
|
|
13U /*!< Max Blocks number on Update request T3T 1.0 5.4.1.10 */
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*! MRT Check | Uupdate = (Tt3t x ((A+1) + n (B+1)) x 4^E) + dRWTt3t T3T 5.8
|
|
|
|
Max values used: A = 7 ; B = 7 ; E = 3 ; n = 15 (NFC Forum n = 15, JIS n = 32)
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_NFCF_MRT_CHECK_UPDATE ((4096 * (8 + (15 * 8)) * 64) + 16)
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL MACROS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
#define rfalNfcfSlots2CardNum(s) \
|
|
|
|
((uint8_t)(s) + 1U) /*!< Converts Time Slot Number (TSN) into num of slots */
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL TYPES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! Structure/Buffer to hold the SENSF_RES with LEN byte prepended */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t LEN; /*!< NFC-F LEN byte */
|
|
|
|
rfalNfcfSensfRes SENSF_RES; /*!< SENSF_RES */
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcfSensfResBuf;
|
|
|
|
|
|
|
|
/*! Greedy collection for NFCF GRE_POLL_F Activity 1.0 Table 10 */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t pollFound; /*!< Number of devices found by the Poll */
|
|
|
|
uint8_t pollCollision; /*!< Number of collisions detected */
|
|
|
|
rfalFeliCaPollRes POLL_F[RFAL_NFCF_POLL_MAXCARDS]; /*!< GRE_POLL_F Activity 1.0 Table 10 */
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcfGreedyF;
|
|
|
|
|
|
|
|
/*! NFC-F SENSF_REQ format Digital 1.1 8.6.1 */
|
2022-01-05 16:10:18 +00:00
|
|
|
typedef struct {
|
|
|
|
uint8_t CMD; /*!< Command code: 00h */
|
|
|
|
uint8_t SC[RFAL_NFCF_SENSF_SC_LEN]; /*!< System Code */
|
|
|
|
uint8_t RC; /*!< Request Code */
|
|
|
|
uint8_t TSN; /*!< Time Slot Number */
|
2021-10-17 22:54:19 +00:00
|
|
|
} rfalNfcfSensfReq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL VARIABLES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
static rfalNfcfGreedyF gRfalNfcfGreedyF; /*!< Activity's NFCF Greedy collection */
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL FUNCTION PROTOTYPES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
static void rfalNfcfComputeValidSENF(
|
|
|
|
rfalNfcfListenDevice* outDevInfo,
|
|
|
|
uint8_t* curDevIdx,
|
|
|
|
uint8_t devLimit,
|
|
|
|
bool overwrite,
|
|
|
|
bool* nfcDepFound);
|
2021-10-17 22:54:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL VARIABLES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
2022-01-05 16:10:18 +00:00
|
|
|
static void rfalNfcfComputeValidSENF(
|
|
|
|
rfalNfcfListenDevice* outDevInfo,
|
|
|
|
uint8_t* curDevIdx,
|
|
|
|
uint8_t |