1 /****************************************************************************** 2 * 3 * Copyright 2020-2021 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 : uint32_t { 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 : uint32_t { 34 SRC_SPI = 0x0, 35 SRC_NFC = 0x10, 36 }; 37 38 enum EseResetType : uint32_t { 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 NFCC 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 NFCC 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 NFCC 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 ** NFCC 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 NFCC 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 EseReset 142 ** 143 ** Description Request NFCC to reset the eSE 144 ** 145 ** Parameters pDevHandle - valid device handle 146 ** eType - EseResetType 147 ** 148 ** Returns 0 - reset operation success 149 ** else - reset operation failure 150 ** 151 ****************************************************************************/ 152 virtual int EseReset(void* pDevHandle, EseResetType eType); 153 154 /***************************************************************************** 155 ** 156 ** Function EseGetPower 157 ** 158 ** Description Request NFCC to reset the eSE 159 ** 160 ** Parameters pDevHandle - valid device handle 161 ** level - reset level 162 ** 163 ** Returns 0 - reset operation success 164 ** else - reset operation failure 165 ** 166 ****************************************************************************/ 167 virtual int EseGetPower(void* pDevHandle, uint32_t level); 168 169 /***************************************************************************** 170 ** 171 ** Function EnableFwDnldMode 172 ** 173 ** Description updates the state to Download mode 174 ** 175 ** Parameters True/False 176 ** 177 ** Returns None 178 ****************************************************************************/ 179 virtual void EnableFwDnldMode(bool mode); 180 181 /***************************************************************************** 182 ** 183 ** Function IsFwDnldModeEnabled 184 ** 185 ** Description Returns the current mode 186 ** 187 ** Parameters none 188 ** 189 ** Returns Current mode download/NCI 190 ****************************************************************************/ 191 virtual bool_t IsFwDnldModeEnabled(void); 192 193 /******************************************************************************* 194 ** 195 ** Function Flushdata 196 ** 197 ** Description Reads payload of FW rsp from NFCC device into given 198 *buffer 199 ** 200 ** Parameters pConfig - hardware information 201 ** 202 ** Returns True(Success)/False(Fail) 203 ** 204 *******************************************************************************/ 205 virtual bool Flushdata(pphTmlNfc_Config_t pConfig); 206 207 /***************************************************************************** 208 ** 209 ** Function ~NfccTransport 210 ** 211 ** Description TransportLayer destructor 212 ** 213 ** Parameters none 214 ** 215 ** Returns None 216 ****************************************************************************/ ~NfccTransport()217 virtual ~NfccTransport(){}; 218 }; 219