1 /****************************************************************************** 2 * 3 * Copyright 2020 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #pragma once 20 #include <phNfcTypes.h> 21 #include <phTmlNfc.h> 22 23 enum NfccResetType : long { 24 MODE_POWER_OFF = 0x00, 25 MODE_POWER_ON, 26 MODE_FW_DWNLD_WITH_VEN, 27 MODE_ISO_RST, 28 MODE_FW_DWND_HIGH, 29 MODE_POWER_RESET, 30 MODE_FW_GPIO_LOW 31 }; 32 33 enum EseResetCallSrc : long { 34 SRC_SPI = 0x0, 35 SRC_NFC = 0x10, 36 }; 37 38 enum EseResetType : long { 39 MODE_ESE_POWER_ON = 0, 40 MODE_ESE_POWER_OFF, 41 MODE_ESE_POWER_STATE, 42 /*Request from eSE HAL/Service*/ 43 MODE_ESE_COLD_RESET, 44 MODE_ESE_RESET_PROTECTION_ENABLE, 45 MODE_ESE_RESET_PROTECTION_DISABLE, 46 /*Request from NFC HAL/Service*/ 47 MODE_ESE_COLD_RESET_NFC = MODE_ESE_COLD_RESET | SRC_NFC, 48 MODE_ESE_RESET_PROTECTION_ENABLE_NFC = 49 MODE_ESE_RESET_PROTECTION_ENABLE | SRC_NFC, 50 MODE_ESE_RESET_PROTECTION_DISABLE_NFC = 51 MODE_ESE_RESET_PROTECTION_DISABLE | SRC_NFC, 52 }; 53 54 extern phTmlNfc_i2cfragmentation_t fragmentation_enabled; 55 56 class NfccTransport { 57 public: 58 /***************************************************************************** 59 ** 60 ** Function Close 61 ** 62 ** Description Closes PN54X device 63 ** 64 ** Parameters pDevHandle - device handle 65 ** 66 ** Returns None 67 ** 68 *****************************************************************************/ 69 virtual void Close(void* pDevHandle) = 0; 70 71 /***************************************************************************** 72 ** 73 ** Function OpenAndConfigure 74 ** 75 ** Description Open and configure PN54X device and transport layer 76 ** 77 ** Parameters pConfig - hardware information 78 ** pLinkHandle - device handle 79 ** 80 ** Returns NFC status: 81 ** NFCSTATUS_SUCCESS - open_and_configure operation success 82 ** NFCSTATUS_INVALID_DEVICE - device open operation failure 83 ** 84 ****************************************************************************/ 85 virtual NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig, 86 void** pLinkHandle) = 0; 87 88 /***************************************************************************** 89 ** 90 ** Function Read 91 ** 92 ** Description Reads requested number of bytes from PN54X device into 93 ** given buffer 94 ** 95 ** Parameters pDevHandle - valid device handle 96 ** pBuffer - buffer for read data 97 ** nNbBytesToRead - number of bytes requested to be read 98 ** 99 ** Returns numRead - number of successfully read bytes 100 ** -1 - read operation failure 101 ** 102 ****************************************************************************/ 103 virtual int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead) = 0; 104 105 /***************************************************************************** 106 ** 107 ** Function Write 108 ** 109 ** Description Writes requested number of bytes from given buffer into 110 ** PN54X device 111 ** 112 ** Parameters pDevHandle - valid device handle 113 ** pBuffer - buffer for read data 114 ** nNbBytesToWrite - number of bytes requested to be 115 *written 116 ** 117 ** Returns numWrote - number of successfully written bytes 118 ** -1 - write operation failure 119 ** 120 *****************************************************************************/ 121 virtual int Write(void* pDevHandle, uint8_t* pBuffer, 122 int nNbBytesToWrite) = 0; 123 124 /***************************************************************************** 125 ** 126 ** Function Reset 127 ** 128 ** Description Reset PN54X device, using VEN pin 129 ** 130 ** Parameters pDevHandle - valid device handle 131 ** eType - NfccResetType 132 ** 133 ** Returns 0 - reset operation success 134 ** -1 - reset operation failure 135 ** 136 ****************************************************************************/ 137 virtual int NfccReset(void* pDevHandle, NfccResetType eType); 138 139 /***************************************************************************** 140 ** 141 ** Function GetNfcState 142 ** 143 ** Description Get NFC state 144 ** 145 ** Parameters pDevHandle - valid device handle 146 ** Returns 0 - unknown 147 ** 1 - FW DWL 148 ** 2 - NCI 149 ** 150 *****************************************************************************/ 151 virtual int GetNfcState(void* pDevHandle); 152 /***************************************************************************** 153 ** 154 ** Function EseReset 155 ** 156 ** Description Request NFCC to reset the eSE 157 ** 158 ** Parameters pDevHandle - valid device handle 159 ** eType - EseResetType 160 ** 161 ** Returns 0 - reset operation success 162 ** else - reset operation failure 163 ** 164 ****************************************************************************/ 165 virtual int EseReset(void* pDevHandle, EseResetType eType); 166 167 /***************************************************************************** 168 ** 169 ** Function EseGetPower 170 ** 171 ** Description Request NFCC to reset the eSE 172 ** 173 ** Parameters pDevHandle - valid device handle 174 ** level - reset level 175 ** 176 ** Returns 0 - reset operation success 177 ** else - reset operation failure 178 ** 179 ****************************************************************************/ 180 virtual int EseGetPower(void* pDevHandle, long level); 181 182 /***************************************************************************** 183 ** 184 ** Function GetPlatform 185 ** 186 ** Description Get platform interface type (i2c or i3c) for common mw 187 ** 188 ** Parameters pDevHandle - valid device handle 189 ** 190 ** Returns 0 - i2c 191 ** 1 - i3c 192 ** 193 ****************************************************************************/ 194 virtual int GetPlatform(void* pDevHandle); 195 196 /***************************************************************************** 197 ** 198 ** Function EnableFwDnldMode 199 ** 200 ** Description updates the state to Download mode 201 ** 202 ** Parameters True/False 203 ** 204 ** Returns None 205 ****************************************************************************/ 206 virtual void EnableFwDnldMode(bool mode); 207 208 /***************************************************************************** 209 ** 210 ** Function IsFwDnldModeEnabled 211 ** 212 ** Description Returns the current mode 213 ** 214 ** Parameters none 215 ** 216 ** Returns Current mode download/NCI 217 ****************************************************************************/ 218 virtual bool_t IsFwDnldModeEnabled(void); 219 220 /******************************************************************************* 221 ** 222 ** Function GetIrqState 223 ** 224 ** Description Get state of IRQ GPIO 225 ** 226 ** Parameters pDevHandle - valid device handle 227 ** 228 ** Returns The state of IRQ line i.e. +ve if read is pending else 229 *Zer0. 230 ** In the case of IOCTL error, it returns -ve value. 231 ** 232 *******************************************************************************/ 233 virtual int GetIrqState(void* pDevHandle); 234 235 /***************************************************************************** 236 ** 237 ** Function ~NfccTransport 238 ** 239 ** Description TransportLayer destructor 240 ** 241 ** Parameters none 242 ** 243 ** Returns None 244 ****************************************************************************/ ~NfccTransport()245 virtual ~NfccTransport(){}; 246 }; 247