• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2020-2022 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 NfcReadPending : uint32_t {
39   MODE_NFC_RESET_READ_PENDING = 0x0,
40   MODE_NFC_SET_READ_PENDING
41 };
42 
43 enum EseResetType : uint32_t {
44   MODE_ESE_POWER_ON = 0,
45   MODE_ESE_POWER_OFF,
46   MODE_ESE_POWER_STATE,
47   /*Request from eSE HAL/Service*/
48   MODE_ESE_COLD_RESET,
49   MODE_ESE_RESET_PROTECTION_ENABLE,
50   MODE_ESE_RESET_PROTECTION_DISABLE,
51   /*Request from NFC HAL/Service*/
52   MODE_ESE_COLD_RESET_NFC = MODE_ESE_COLD_RESET | SRC_NFC,
53   MODE_ESE_RESET_PROTECTION_ENABLE_NFC =
54       MODE_ESE_RESET_PROTECTION_ENABLE | SRC_NFC,
55   MODE_ESE_RESET_PROTECTION_DISABLE_NFC =
56       MODE_ESE_RESET_PROTECTION_DISABLE | SRC_NFC,
57 };
58 
59 extern phTmlNfc_i2cfragmentation_t fragmentation_enabled;
60 
61 class NfccTransport {
62  public:
63   /*****************************************************************************
64    **
65    ** Function         Close
66    **
67    ** Description      Closes NFCC device
68    **
69    ** Parameters       pDevHandle - device handle
70    **
71    ** Returns          None
72    **
73    *****************************************************************************/
74   virtual void Close(void* pDevHandle) = 0;
75 
76   /*****************************************************************************
77    **
78    ** Function         OpenAndConfigure
79    **
80    ** Description      Open and configure NFCC device and transport layer
81    **
82    ** Parameters       pConfig     - hardware information
83    **                  pLinkHandle - device handle
84    **
85    ** Returns          NFC status:
86    **                  NFCSTATUS_SUCCESS - open_and_configure operation success
87    **                  NFCSTATUS_INVALID_DEVICE - device open operation failure
88    **
89    ****************************************************************************/
90   virtual NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig,
91                                      void** pLinkHandle) = 0;
92 
93   /*****************************************************************************
94    **
95    ** Function         Read
96    **
97    ** Description      Reads requested number of bytes from NFCC device into
98    **                 given buffer
99    **
100    ** Parameters       pDevHandle       - valid device handle
101    **                  pBuffer          - buffer for read data
102    **                  nNbBytesToRead   - number of bytes requested to be read
103    **
104    ** Returns          numRead   - number of successfully read bytes
105    **                  -1        - read operation failure
106    **
107    ****************************************************************************/
108   virtual int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead) = 0;
109 
110   /*****************************************************************************
111    **
112    ** Function         Write
113    **
114    ** Description      Writes requested number of bytes from given buffer into
115    **                  NFCC device
116    **
117    ** Parameters       pDevHandle       - valid device handle
118    **                  pBuffer          - buffer for read data
119    **                  nNbBytesToWrite  - number of bytes requested to be
120    *written
121    **
122    ** Returns          numWrote   - number of successfully written bytes
123    **                  -1         - write operation failure
124    **
125    *****************************************************************************/
126   virtual int Write(void* pDevHandle, uint8_t* pBuffer,
127                     int nNbBytesToWrite) = 0;
128 
129   /*****************************************************************************
130    **
131    ** Function         Reset
132    **
133    ** Description      Reset NFCC device, using VEN pin
134    **
135    ** Parameters       pDevHandle     - valid device handle
136    **                  eType          - NfccResetType
137    **
138    ** Returns           0   - reset operation success
139    **                  -1   - reset operation failure
140    **
141    ****************************************************************************/
142   virtual int NfccReset(void* pDevHandle, NfccResetType eType);
143 
144   /*****************************************************************************
145    **
146    ** Function         UpdateReadPending
147    **
148    ** Description      Set or Reset Read Pending of NFC
149    **
150    ** Parameters       pDevHandle     - valid device handle
151    **                  eType          - set or clear the flag
152    **
153    ** Returns           0   - operation success
154    **                  -1   - operation failure
155    **
156    ****************************************************************************/
157   virtual int UpdateReadPending(void* pDevHandle, NfcReadPending eType);
158 
159   /*****************************************************************************
160    **
161    ** Function         NfcGetGpioStatus
162    **
163    ** Description      Get the gpio status flag byte from kernel space
164    **
165    ** Parameters       pDevHandle     - valid device handle
166    **
167    **
168    ** Returns           0   - operation success
169    **                  -1   - operation failure
170    **
171    ****************************************************************************/
172   virtual int NfcGetGpioStatus(void* pDevHandle, uint32_t* status);
173 
174   /*****************************************************************************
175    **
176    ** Function         EseReset
177    **
178    ** Description      Request NFCC to reset the eSE
179    **
180    ** Parameters       pDevHandle     - valid device handle
181    **                  eType          - EseResetType
182    **
183    ** Returns           0   - reset operation success
184    **                  else - reset operation failure
185    **
186    ****************************************************************************/
187   virtual int EseReset(void* pDevHandle, EseResetType eType);
188 
189   /*****************************************************************************
190    **
191    ** Function         EseGetPower
192    **
193    ** Description      Request NFCC to reset the eSE
194    **
195    ** Parameters       pDevHandle     - valid device handle
196    **                  level          - reset level
197    **
198    ** Returns           0   - reset operation success
199    **                  else - reset operation failure
200    **
201    ****************************************************************************/
202   virtual int EseGetPower(void* pDevHandle, uint32_t level);
203 
204   /*****************************************************************************
205    **
206    ** Function         EnableFwDnldMode
207    **
208    ** Description      updates the state to Download mode
209    **
210    ** Parameters       True/False
211    **
212    ** Returns          None
213    ****************************************************************************/
214   virtual void EnableFwDnldMode(bool mode);
215 
216   /*****************************************************************************
217    **
218    ** Function         IsFwDnldModeEnabled
219    **
220    ** Description      Returns the current mode
221    **
222    ** Parameters       none
223    **
224    ** Returns          Current mode download/NCI
225    ****************************************************************************/
226   virtual bool_t IsFwDnldModeEnabled(void);
227 
228   /*******************************************************************************
229   **
230   ** Function         Flushdata
231   **
232   ** Description      Reads payload of FW rsp from NFCC device into given buffer
233   **
234   ** Parameters       pConfig     - hardware information
235   **
236   ** Returns          True(Success)/False(Fail)
237   **
238   *******************************************************************************/
239   virtual bool Flushdata(pphTmlNfc_Config_t pConfig);
240 
241   /*****************************************************************************
242    **
243    ** Function         ~NfccTransport
244    **
245    ** Description      TransportLayer destructor
246    **
247    ** Parameters       none
248    **
249    ** Returns          None
250    ****************************************************************************/
~NfccTransport()251   virtual ~NfccTransport(){};
252 };
253