Fork of the GitHub
rfal_nfcf.cpp@0:75fc82583a41, 2019-11-14 (annotated)
- Committer:
- DiegoOstuni
- Date:
- Thu Nov 14 14:34:50 2019 +0000
- Revision:
- 0:75fc82583a41
Add files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DiegoOstuni | 0:75fc82583a41 | 1 | |
DiegoOstuni | 0:75fc82583a41 | 2 | /****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 3 | * @attention |
DiegoOstuni | 0:75fc82583a41 | 4 | * |
DiegoOstuni | 0:75fc82583a41 | 5 | * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2> |
DiegoOstuni | 0:75fc82583a41 | 6 | * |
DiegoOstuni | 0:75fc82583a41 | 7 | * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); |
DiegoOstuni | 0:75fc82583a41 | 8 | * You may not use this file except in compliance with the License. |
DiegoOstuni | 0:75fc82583a41 | 9 | * You may obtain a copy of the License at: |
DiegoOstuni | 0:75fc82583a41 | 10 | * |
DiegoOstuni | 0:75fc82583a41 | 11 | * http://www.st.com/myliberty |
DiegoOstuni | 0:75fc82583a41 | 12 | * |
DiegoOstuni | 0:75fc82583a41 | 13 | * Unless required by applicable law or agreed to in writing, software |
DiegoOstuni | 0:75fc82583a41 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
DiegoOstuni | 0:75fc82583a41 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, |
DiegoOstuni | 0:75fc82583a41 | 16 | * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, |
DiegoOstuni | 0:75fc82583a41 | 17 | * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. |
DiegoOstuni | 0:75fc82583a41 | 18 | * See the License for the specific language governing permissions and |
DiegoOstuni | 0:75fc82583a41 | 19 | * limitations under the License. |
DiegoOstuni | 0:75fc82583a41 | 20 | * |
DiegoOstuni | 0:75fc82583a41 | 21 | ******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 22 | |
DiegoOstuni | 0:75fc82583a41 | 23 | /* |
DiegoOstuni | 0:75fc82583a41 | 24 | * PROJECT: ST25R391x firmware |
DiegoOstuni | 0:75fc82583a41 | 25 | * $Revision: $ |
DiegoOstuni | 0:75fc82583a41 | 26 | * LANGUAGE: ISO C99 |
DiegoOstuni | 0:75fc82583a41 | 27 | */ |
DiegoOstuni | 0:75fc82583a41 | 28 | |
DiegoOstuni | 0:75fc82583a41 | 29 | /*! \file rfal_nfcf.c |
DiegoOstuni | 0:75fc82583a41 | 30 | * |
DiegoOstuni | 0:75fc82583a41 | 31 | * \author Gustavo Patricio |
DiegoOstuni | 0:75fc82583a41 | 32 | * |
DiegoOstuni | 0:75fc82583a41 | 33 | * \brief Implementation of NFC-F Poller (FeliCa PCD) device |
DiegoOstuni | 0:75fc82583a41 | 34 | * |
DiegoOstuni | 0:75fc82583a41 | 35 | * The definitions and helpers methods provided by this module are |
DiegoOstuni | 0:75fc82583a41 | 36 | * aligned with NFC-F (FeliCa - JIS X6319-4) |
DiegoOstuni | 0:75fc82583a41 | 37 | * |
DiegoOstuni | 0:75fc82583a41 | 38 | */ |
DiegoOstuni | 0:75fc82583a41 | 39 | |
DiegoOstuni | 0:75fc82583a41 | 40 | /* |
DiegoOstuni | 0:75fc82583a41 | 41 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 42 | * INCLUDES |
DiegoOstuni | 0:75fc82583a41 | 43 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 44 | */ |
DiegoOstuni | 0:75fc82583a41 | 45 | #include <platform1.h> |
DiegoOstuni | 0:75fc82583a41 | 46 | #include "rfal_nfcf.h" |
DiegoOstuni | 0:75fc82583a41 | 47 | #include "utils.h" |
DiegoOstuni | 0:75fc82583a41 | 48 | |
DiegoOstuni | 0:75fc82583a41 | 49 | /* |
DiegoOstuni | 0:75fc82583a41 | 50 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 51 | * ENABLE SWITCH |
DiegoOstuni | 0:75fc82583a41 | 52 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 53 | */ |
DiegoOstuni | 0:75fc82583a41 | 54 | |
DiegoOstuni | 0:75fc82583a41 | 55 | #ifndef RFAL_FEATURE_NFCF |
DiegoOstuni | 0:75fc82583a41 | 56 | #error " RFAL: Module configuration missing. Please enable/disable NFC-F module by setting: RFAL_FEATURE_NFCF " |
DiegoOstuni | 0:75fc82583a41 | 57 | #endif |
DiegoOstuni | 0:75fc82583a41 | 58 | |
DiegoOstuni | 0:75fc82583a41 | 59 | #if RFAL_FEATURE_NFCF |
DiegoOstuni | 0:75fc82583a41 | 60 | |
DiegoOstuni | 0:75fc82583a41 | 61 | /* |
DiegoOstuni | 0:75fc82583a41 | 62 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 63 | * GLOBAL DEFINES |
DiegoOstuni | 0:75fc82583a41 | 64 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 65 | */ |
DiegoOstuni | 0:75fc82583a41 | 66 | #define RFAL_NFCF_SENSF_REQ_LEN_MIN 5 /*!< SENSF_RES minimum length */ |
DiegoOstuni | 0:75fc82583a41 | 67 | |
DiegoOstuni | 0:75fc82583a41 | 68 | #define RFAL_NFCF_READ_WO_ENCRYPTION_MIN_LEN 15 /*!< Minimum length for a Check Command - T3T 5.4.1 */ |
DiegoOstuni | 0:75fc82583a41 | 69 | #define RFAL_NFCF_WRITE_WO_ENCRYPTION_MIN_LEN 31 /*!< Minimum length for an Update Command - T3T 5.5.1 */ |
DiegoOstuni | 0:75fc82583a41 | 70 | |
DiegoOstuni | 0:75fc82583a41 | 71 | |
DiegoOstuni | 0:75fc82583a41 | 72 | /* |
DiegoOstuni | 0:75fc82583a41 | 73 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 74 | * GLOBAL MACROS |
DiegoOstuni | 0:75fc82583a41 | 75 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 76 | */ |
DiegoOstuni | 0:75fc82583a41 | 77 | #define rfalNfcfSlots2CardNum( s ) (s+1) /*!< Converts Time Slot Number (TSN) into num of slots */ |
DiegoOstuni | 0:75fc82583a41 | 78 | |
DiegoOstuni | 0:75fc82583a41 | 79 | /* |
DiegoOstuni | 0:75fc82583a41 | 80 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 81 | * GLOBAL TYPES |
DiegoOstuni | 0:75fc82583a41 | 82 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 83 | */ |
DiegoOstuni | 0:75fc82583a41 | 84 | |
DiegoOstuni | 0:75fc82583a41 | 85 | /*! Structure/Buffer to hold the SENSF_RES with LEN byte prepended */ |
DiegoOstuni | 0:75fc82583a41 | 86 | typedef struct{ |
DiegoOstuni | 0:75fc82583a41 | 87 | uint8_t LEN; /*!< NFC-F LEN byte */ |
DiegoOstuni | 0:75fc82583a41 | 88 | rfalNfcfSensfRes SENSF_RES; /*!< SENSF_RES */ |
DiegoOstuni | 0:75fc82583a41 | 89 | } rfalNfcfSensfResBuf; |
DiegoOstuni | 0:75fc82583a41 | 90 | |
DiegoOstuni | 0:75fc82583a41 | 91 | |
DiegoOstuni | 0:75fc82583a41 | 92 | /*! Greedy collection for NFCF GRE_POLL_F Activity 1.0 Table 10 */ |
DiegoOstuni | 0:75fc82583a41 | 93 | typedef struct{ |
DiegoOstuni | 0:75fc82583a41 | 94 | uint8_t pollFound; /*!< Number of devices found by the Poll */ |
DiegoOstuni | 0:75fc82583a41 | 95 | uint8_t pollCollision; /*!< Number of collisions detected */ |
DiegoOstuni | 0:75fc82583a41 | 96 | rfalFeliCaPollRes POLL_F[RFAL_NFCF_POLL_MAXCARDS]; /*!< GRE_POLL_F Activity 1.0 Table 10 */ |
DiegoOstuni | 0:75fc82583a41 | 97 | } rfalNfcfGreedyF; |
DiegoOstuni | 0:75fc82583a41 | 98 | |
DiegoOstuni | 0:75fc82583a41 | 99 | |
DiegoOstuni | 0:75fc82583a41 | 100 | /*! NFC-F SENSF_REQ format Digital 1.1 8.6.1 */ |
DiegoOstuni | 0:75fc82583a41 | 101 | typedef struct |
DiegoOstuni | 0:75fc82583a41 | 102 | { |
DiegoOstuni | 0:75fc82583a41 | 103 | uint8_t CMD; /*!< Command code: 00h */ |
DiegoOstuni | 0:75fc82583a41 | 104 | uint8_t SC[RFAL_NFCF_SENSF_SC_LEN]; /*!< System Code */ |
DiegoOstuni | 0:75fc82583a41 | 105 | uint8_t RC; /*!< Request Code */ |
DiegoOstuni | 0:75fc82583a41 | 106 | uint8_t TSN; /*!< Time Slot Number */ |
DiegoOstuni | 0:75fc82583a41 | 107 | } rfalNfcfSensfReq; |
DiegoOstuni | 0:75fc82583a41 | 108 | |
DiegoOstuni | 0:75fc82583a41 | 109 | |
DiegoOstuni | 0:75fc82583a41 | 110 | /* |
DiegoOstuni | 0:75fc82583a41 | 111 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 112 | * LOCAL VARIABLES |
DiegoOstuni | 0:75fc82583a41 | 113 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 114 | */ |
DiegoOstuni | 0:75fc82583a41 | 115 | static rfalNfcfGreedyF gRfalNfcfGreedyF; /*!< Activity's NFCF Greedy collection */ |
DiegoOstuni | 0:75fc82583a41 | 116 | |
DiegoOstuni | 0:75fc82583a41 | 117 | |
DiegoOstuni | 0:75fc82583a41 | 118 | /* |
DiegoOstuni | 0:75fc82583a41 | 119 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 120 | * LOCAL FUNCTION PROTOTYPES |
DiegoOstuni | 0:75fc82583a41 | 121 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 122 | */ |
DiegoOstuni | 0:75fc82583a41 | 123 | static void rfalNfcfComputeValidSENF( rfalNfcfListenDevice *outDevInfo, uint8_t *curDevIdx, uint8_t devLimit, bool overwrite, bool *nfcDepFound ); |
DiegoOstuni | 0:75fc82583a41 | 124 | |
DiegoOstuni | 0:75fc82583a41 | 125 | |
DiegoOstuni | 0:75fc82583a41 | 126 | /* |
DiegoOstuni | 0:75fc82583a41 | 127 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 128 | * LOCAL VARIABLES |
DiegoOstuni | 0:75fc82583a41 | 129 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 130 | */ |
DiegoOstuni | 0:75fc82583a41 | 131 | |
DiegoOstuni | 0:75fc82583a41 | 132 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 133 | static void rfalNfcfComputeValidSENF( rfalNfcfListenDevice *outDevInfo, uint8_t *curDevIdx, uint8_t devLimit, bool overwrite, bool *nfcDepFound ) |
DiegoOstuni | 0:75fc82583a41 | 134 | { |
DiegoOstuni | 0:75fc82583a41 | 135 | uint8_t tmpIdx; |
DiegoOstuni | 0:75fc82583a41 | 136 | bool duplicate; |
DiegoOstuni | 0:75fc82583a41 | 137 | rfalNfcfSensfResBuf *sensfBuf; |
DiegoOstuni | 0:75fc82583a41 | 138 | |
DiegoOstuni | 0:75fc82583a41 | 139 | |
DiegoOstuni | 0:75fc82583a41 | 140 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 141 | /* Go through all responses check if valid and duplicates */ |
DiegoOstuni | 0:75fc82583a41 | 142 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 143 | while( (gRfalNfcfGreedyF.pollFound > 0) && ((*curDevIdx) < devLimit) ) |
DiegoOstuni | 0:75fc82583a41 | 144 | { |
DiegoOstuni | 0:75fc82583a41 | 145 | duplicate = false; |
DiegoOstuni | 0:75fc82583a41 | 146 | gRfalNfcfGreedyF.pollFound--; |
DiegoOstuni | 0:75fc82583a41 | 147 | |
DiegoOstuni | 0:75fc82583a41 | 148 | /* Point to received SENSF_RES */ |
DiegoOstuni | 0:75fc82583a41 | 149 | sensfBuf = (rfalNfcfSensfResBuf*) &gRfalNfcfGreedyF.POLL_F[gRfalNfcfGreedyF.pollFound]; |
DiegoOstuni | 0:75fc82583a41 | 150 | |
DiegoOstuni | 0:75fc82583a41 | 151 | |
DiegoOstuni | 0:75fc82583a41 | 152 | /* Check for devices that are already in device list */ |
DiegoOstuni | 0:75fc82583a41 | 153 | for( tmpIdx = 0; tmpIdx < (*curDevIdx); tmpIdx++ ) |
DiegoOstuni | 0:75fc82583a41 | 154 | { |
DiegoOstuni | 0:75fc82583a41 | 155 | if( !ST_BYTECMP( sensfBuf->SENSF_RES.NFCID2, outDevInfo[tmpIdx].sensfRes.NFCID2, RFAL_NFCF_NFCID2_LEN ) ) |
DiegoOstuni | 0:75fc82583a41 | 156 | { |
DiegoOstuni | 0:75fc82583a41 | 157 | duplicate = true; |
DiegoOstuni | 0:75fc82583a41 | 158 | break; |
DiegoOstuni | 0:75fc82583a41 | 159 | } |
DiegoOstuni | 0:75fc82583a41 | 160 | } |
DiegoOstuni | 0:75fc82583a41 | 161 | |
DiegoOstuni | 0:75fc82583a41 | 162 | /* If is a duplicate skip this (and not to overwrite)*/ |
DiegoOstuni | 0:75fc82583a41 | 163 | if(duplicate && !overwrite) |
DiegoOstuni | 0:75fc82583a41 | 164 | { |
DiegoOstuni | 0:75fc82583a41 | 165 | continue; |
DiegoOstuni | 0:75fc82583a41 | 166 | } |
DiegoOstuni | 0:75fc82583a41 | 167 | |
DiegoOstuni | 0:75fc82583a41 | 168 | /* Check if response length is OK */ |
DiegoOstuni | 0:75fc82583a41 | 169 | if( (( sensfBuf->LEN - RFAL_NFCF_HEADER_LEN) < RFAL_NFCF_SENSF_RES_LEN_MIN) || ((sensfBuf->LEN - RFAL_NFCF_HEADER_LEN) > RFAL_NFCF_SENSF_RES_LEN_MAX) ) |
DiegoOstuni | 0:75fc82583a41 | 170 | { |
DiegoOstuni | 0:75fc82583a41 | 171 | continue; |
DiegoOstuni | 0:75fc82583a41 | 172 | } |
DiegoOstuni | 0:75fc82583a41 | 173 | |
DiegoOstuni | 0:75fc82583a41 | 174 | /* Check if the response is a SENSF_RES / Polling response */ |
DiegoOstuni | 0:75fc82583a41 | 175 | if( sensfBuf->SENSF_RES.CMD != RFAL_NFCF_CMD_POLLING_RES ) |
DiegoOstuni | 0:75fc82583a41 | 176 | { |
DiegoOstuni | 0:75fc82583a41 | 177 | continue; |
DiegoOstuni | 0:75fc82583a41 | 178 | } |
DiegoOstuni | 0:75fc82583a41 | 179 | |
DiegoOstuni | 0:75fc82583a41 | 180 | /* Check if is an overwrite request or new device*/ |
DiegoOstuni | 0:75fc82583a41 | 181 | if(duplicate && overwrite) |
DiegoOstuni | 0:75fc82583a41 | 182 | { |
DiegoOstuni | 0:75fc82583a41 | 183 | /* overwrite deviceInfo/GRE_SENSF_RES with SENSF_RES */ |
DiegoOstuni | 0:75fc82583a41 | 184 | outDevInfo[tmpIdx].sensfResLen = (sensfBuf->LEN - RFAL_NFCF_LENGTH_LEN); |
DiegoOstuni | 0:75fc82583a41 | 185 | ST_MEMCPY( &outDevInfo[tmpIdx].sensfRes, &sensfBuf->SENSF_RES.CMD, outDevInfo[tmpIdx].sensfResLen ); |
DiegoOstuni | 0:75fc82583a41 | 186 | continue; |
DiegoOstuni | 0:75fc82583a41 | 187 | } |
DiegoOstuni | 0:75fc82583a41 | 188 | else |
DiegoOstuni | 0:75fc82583a41 | 189 | { |
DiegoOstuni | 0:75fc82583a41 | 190 | /* fill deviceInfo/GRE_SENSF_RES with new SENSF_RES */ |
DiegoOstuni | 0:75fc82583a41 | 191 | outDevInfo[(*curDevIdx)].sensfResLen = (sensfBuf->LEN - RFAL_NFCF_LENGTH_LEN); |
DiegoOstuni | 0:75fc82583a41 | 192 | ST_MEMCPY( &outDevInfo[(*curDevIdx)].sensfRes, &sensfBuf->SENSF_RES.CMD, outDevInfo[(*curDevIdx)].sensfResLen ); |
DiegoOstuni | 0:75fc82583a41 | 193 | } |
DiegoOstuni | 0:75fc82583a41 | 194 | |
DiegoOstuni | 0:75fc82583a41 | 195 | /* Check if this device supports NFC-DEP and signal it (ACTIVITY 1.1 9.3.6.63) */ |
DiegoOstuni | 0:75fc82583a41 | 196 | *nfcDepFound = rfalNfcfIsNfcDepSupported( &outDevInfo[(*curDevIdx)] ); |
DiegoOstuni | 0:75fc82583a41 | 197 | |
DiegoOstuni | 0:75fc82583a41 | 198 | (*curDevIdx)++; |
DiegoOstuni | 0:75fc82583a41 | 199 | } |
DiegoOstuni | 0:75fc82583a41 | 200 | } |
DiegoOstuni | 0:75fc82583a41 | 201 | |
DiegoOstuni | 0:75fc82583a41 | 202 | /* |
DiegoOstuni | 0:75fc82583a41 | 203 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 204 | * GLOBAL FUNCTIONS |
DiegoOstuni | 0:75fc82583a41 | 205 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 206 | */ |
DiegoOstuni | 0:75fc82583a41 | 207 | |
DiegoOstuni | 0:75fc82583a41 | 208 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 209 | ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:75fc82583a41 | 210 | { |
DiegoOstuni | 0:75fc82583a41 | 211 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 212 | |
DiegoOstuni | 0:75fc82583a41 | 213 | if( (bitRate != RFAL_BR_212) && (bitRate != RFAL_BR_424) ) |
DiegoOstuni | 0:75fc82583a41 | 214 | { |
DiegoOstuni | 0:75fc82583a41 | 215 | return ERR_PARAM; |
DiegoOstuni | 0:75fc82583a41 | 216 | } |
DiegoOstuni | 0:75fc82583a41 | 217 | |
DiegoOstuni | 0:75fc82583a41 | 218 | EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCF, bitRate, bitRate, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ); |
DiegoOstuni | 0:75fc82583a41 | 219 | rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); |
DiegoOstuni | 0:75fc82583a41 | 220 | |
DiegoOstuni | 0:75fc82583a41 | 221 | rfalSetGT( RFAL_GT_NFCF ); |
DiegoOstuni | 0:75fc82583a41 | 222 | rfalSetFDTListen( RFAL_FDT_LISTEN_NFCF_POLLER ); |
DiegoOstuni | 0:75fc82583a41 | 223 | rfalSetFDTPoll( RFAL_FDT_POLL_NFCF_POLLER ); |
DiegoOstuni | 0:75fc82583a41 | 224 | |
DiegoOstuni | 0:75fc82583a41 | 225 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 226 | } |
DiegoOstuni | 0:75fc82583a41 | 227 | |
DiegoOstuni | 0:75fc82583a41 | 228 | |
DiegoOstuni | 0:75fc82583a41 | 229 | |
DiegoOstuni | 0:75fc82583a41 | 230 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 231 | ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:75fc82583a41 | 232 | { |
DiegoOstuni | 0:75fc82583a41 | 233 | return rfalFeliCaPoll( slots, sysCode, reqCode, cardList, rfalNfcfSlots2CardNum(slots), devCnt, collisions, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 234 | } |
DiegoOstuni | 0:75fc82583a41 | 235 | |
DiegoOstuni | 0:75fc82583a41 | 236 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 237 | ReturnCode rfalNfcfPollerCheckPresence( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:75fc82583a41 | 238 | { |
DiegoOstuni | 0:75fc82583a41 | 239 | gRfalNfcfGreedyF.pollFound = 0; |
DiegoOstuni | 0:75fc82583a41 | 240 | gRfalNfcfGreedyF.pollCollision = 0; |
DiegoOstuni | 0:75fc82583a41 | 241 | |
DiegoOstuni | 0:75fc82583a41 | 242 | /* ACTIVITY 1.0 & 1.1 - 9.2.3.17 SENSF_REQ must be with number of slots equal to 4 |
DiegoOstuni | 0:75fc82583a41 | 243 | * SC must be 0xFFFF |
DiegoOstuni | 0:75fc82583a41 | 244 | * RC must be 0x00 (No system code info required) */ |
DiegoOstuni | 0:75fc82583a41 | 245 | return rfalFeliCaPoll( RFAL_FELICA_4_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_NO_REQUEST, gRfalNfcfGreedyF.POLL_F, rfalNfcfSlots2CardNum(RFAL_FELICA_4_SLOTS), &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 246 | } |
DiegoOstuni | 0:75fc82583a41 | 247 | |
DiegoOstuni | 0:75fc82583a41 | 248 | |
DiegoOstuni | 0:75fc82583a41 | 249 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 250 | ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 ) |
DiegoOstuni | 0:75fc82583a41 | 251 | { |
DiegoOstuni | 0:75fc82583a41 | 252 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 253 | bool nfcDepFound; |
DiegoOstuni | 0:75fc82583a41 | 254 | |
DiegoOstuni | 0:75fc82583a41 | 255 | if( nfcfDevList == NULL || devCnt == NULL ) |
DiegoOstuni | 0:75fc82583a41 | 256 | { |
DiegoOstuni | 0:75fc82583a41 | 257 | return ERR_PARAM; |
DiegoOstuni | 0:75fc82583a41 | 258 | } |
DiegoOstuni | 0:75fc82583a41 | 259 | |
DiegoOstuni | 0:75fc82583a41 | 260 | *devCnt = 0; |
DiegoOstuni | 0:75fc82583a41 | 261 | nfcDepFound = false; |
DiegoOstuni | 0:75fc82583a41 | 262 | |
DiegoOstuni | 0:75fc82583a41 | 263 | |
DiegoOstuni | 0:75fc82583a41 | 264 | /*******************************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 265 | /* ACTIVITY 1.0 - 9.3.6.3 Copy valid SENSF_RES in GRE_POLL_F into GRE_SENSF_RES */ |
DiegoOstuni | 0:75fc82583a41 | 266 | /* ACTIVITY 1.0 - 9.3.6.6 The NFC Forum Device MUST remove all entries from GRE_SENSF_RES[]*/ |
DiegoOstuni | 0:75fc82583a41 | 267 | /* ACTIVITY 1.1 - 9.3.63.59 Populate GRE_SENSF_RES with data from GRE_POLL_F */ |
DiegoOstuni | 0:75fc82583a41 | 268 | /* */ |
DiegoOstuni | 0:75fc82583a41 | 269 | /* CON_DEVICES_LIMIT = 0 Just check if devices from Tech Detection exceeds -> always true */ |
DiegoOstuni | 0:75fc82583a41 | 270 | /* Allow the number of slots open on Technology Detection */ |
DiegoOstuni | 0:75fc82583a41 | 271 | /*******************************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 272 | rfalNfcfComputeValidSENF( nfcfDevList, devCnt, (devLimit == 0 ? rfalNfcfSlots2CardNum( RFAL_FELICA_4_SLOTS ) : devLimit), false, &nfcDepFound ); |
DiegoOstuni | 0:75fc82583a41 | 273 | |
DiegoOstuni | 0:75fc82583a41 | 274 | |
DiegoOstuni | 0:75fc82583a41 | 275 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 276 | /* ACTIVITY 1.0 - 9.3.6.4 */ |
DiegoOstuni | 0:75fc82583a41 | 277 | /* ACTIVITY 1.1 - 9.3.63.60 Check if devices found are lower than the limit */ |
DiegoOstuni | 0:75fc82583a41 | 278 | /* and send a SENSF_REQ if so */ |
DiegoOstuni | 0:75fc82583a41 | 279 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 280 | if( *devCnt < devLimit ) |
DiegoOstuni | 0:75fc82583a41 | 281 | { |
DiegoOstuni | 0:75fc82583a41 | 282 | /* ACTIVITY 1.0 - 9.3.6.5 Copy valid SENSF_RES and then to remove it |
DiegoOstuni | 0:75fc82583a41 | 283 | * ACTIVITY 1.1 - 9.3.6.65 Copy and filter duplicates |
DiegoOstuni | 0:75fc82583a41 | 284 | * For now, due to some devices keep generating different nfcid2, we use 1.0 |
DiegoOstuni | 0:75fc82583a41 | 285 | * Phones detected: Samsung Galaxy Nexus,Samsung Galaxy S3,Samsung Nexus S */ |
DiegoOstuni | 0:75fc82583a41 | 286 | *devCnt = 0; |
DiegoOstuni | 0:75fc82583a41 | 287 | |
DiegoOstuni | 0:75fc82583a41 | 288 | ret = rfalNfcfPollerPoll( RFAL_FELICA_16_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_NO_REQUEST, gRfalNfcfGreedyF.POLL_F, &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 289 | if( ret == ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 290 | { |
DiegoOstuni | 0:75fc82583a41 | 291 | rfalNfcfComputeValidSENF( nfcfDevList, devCnt, devLimit, false, &nfcDepFound ); |
DiegoOstuni | 0:75fc82583a41 | 292 | } |
DiegoOstuni | 0:75fc82583a41 | 293 | |
DiegoOstuni | 0:75fc82583a41 | 294 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 295 | /* ACTIVITY 1.1 - 9.3.6.63 Check if any device supports NFC DEP */ |
DiegoOstuni | 0:75fc82583a41 | 296 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 297 | if( nfcDepFound && (compMode == RFAL_COMPLIANCE_MODE_NFC) ) |
DiegoOstuni | 0:75fc82583a41 | 298 | { |
DiegoOstuni | 0:75fc82583a41 | 299 | ret = rfalNfcfPollerPoll( RFAL_FELICA_16_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_SYSTEM_CODE, gRfalNfcfGreedyF.POLL_F, &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 300 | if( ret == ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 301 | { |
DiegoOstuni | 0:75fc82583a41 | 302 | rfalNfcfComputeValidSENF( nfcfDevList, devCnt, devLimit, true, &nfcDepFound ); |
DiegoOstuni | 0:75fc82583a41 | 303 | } |
DiegoOstuni | 0:75fc82583a41 | 304 | } |
DiegoOstuni | 0:75fc82583a41 | 305 | } |
DiegoOstuni | 0:75fc82583a41 | 306 | |
DiegoOstuni | 0:75fc82583a41 | 307 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 308 | } |
DiegoOstuni | 0:75fc82583a41 | 309 | |
DiegoOstuni | 0:75fc82583a41 | 310 | |
DiegoOstuni | 0:75fc82583a41 | 311 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 312 | bool rfalNfcfListenerIsT3TReq( uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 ) |
DiegoOstuni | 0:75fc82583a41 | 313 | { |
DiegoOstuni | 0:75fc82583a41 | 314 | /* Check cmd byte */ |
DiegoOstuni | 0:75fc82583a41 | 315 | switch( *buf ) |
DiegoOstuni | 0:75fc82583a41 | 316 | { |
DiegoOstuni | 0:75fc82583a41 | 317 | case RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION: |
DiegoOstuni | 0:75fc82583a41 | 318 | if( bufLen < RFAL_NFCF_READ_WO_ENCRYPTION_MIN_LEN ) |
DiegoOstuni | 0:75fc82583a41 | 319 | { |
DiegoOstuni | 0:75fc82583a41 | 320 | return false; |
DiegoOstuni | 0:75fc82583a41 | 321 | } |
DiegoOstuni | 0:75fc82583a41 | 322 | break; |
DiegoOstuni | 0:75fc82583a41 | 323 | |
DiegoOstuni | 0:75fc82583a41 | 324 | case RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION: |
DiegoOstuni | 0:75fc82583a41 | 325 | if( bufLen < RFAL_NFCF_WRITE_WO_ENCRYPTION_MIN_LEN ) |
DiegoOstuni | 0:75fc82583a41 | 326 | { |
DiegoOstuni | 0:75fc82583a41 | 327 | return false; |
DiegoOstuni | 0:75fc82583a41 | 328 | } |
DiegoOstuni | 0:75fc82583a41 | 329 | break; |
DiegoOstuni | 0:75fc82583a41 | 330 | |
DiegoOstuni | 0:75fc82583a41 | 331 | default: |
DiegoOstuni | 0:75fc82583a41 | 332 | return false; |
DiegoOstuni | 0:75fc82583a41 | 333 | } |
DiegoOstuni | 0:75fc82583a41 | 334 | |
DiegoOstuni | 0:75fc82583a41 | 335 | /* Output NFID2 if requested */ |
DiegoOstuni | 0:75fc82583a41 | 336 | if( nfcid2 != NULL ) |
DiegoOstuni | 0:75fc82583a41 | 337 | { |
DiegoOstuni | 0:75fc82583a41 | 338 | ST_MEMCPY( nfcid2, (uint8_t*)(buf + RFAL_NFCF_CMD_LEN), RFAL_NFCF_NFCID2_LEN ); |
DiegoOstuni | 0:75fc82583a41 | 339 | } |
DiegoOstuni | 0:75fc82583a41 | 340 | |
DiegoOstuni | 0:75fc82583a41 | 341 | return true; |
DiegoOstuni | 0:75fc82583a41 | 342 | } |
DiegoOstuni | 0:75fc82583a41 | 343 | |
DiegoOstuni | 0:75fc82583a41 | 344 | #endif /* RFAL_FEATURE_NFCF */ |