1 /******************************************************************************
2  *
3  *  Copyright 2018 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 /**
20  * \addtogroup spi_libese
21  * \brief ESE Lib layer interface to application
22  * @{ */
23 
24 #ifndef _PHNXPSPILIB_API_H_
25 #define _PHNXPSPILIB_API_H_
26 
27 #include <phEseStatus.h>
28 
29 /**
30  * \ingroup spi_libese
31  * \brief Ese data buffer
32  *
33  */
34 typedef struct phNxpEse_data {
35   uint32_t len;    /*!< length of the buffer */
36   uint8_t* p_data; /*!< pointer to a buffer */
37 } phNxpEse_data;
38 
39 /**
40  * \ingroup spi_libese
41  * \brief Ese Channel mode
42  *
43  */
44 typedef enum {
45   ESE_MODE_NORMAL = 0, /*!< All wired transaction other OSU */
46   ESE_MODE_OSU         /*!< Jcop Os update mode */
47 } phNxpEse_initMode;
48 
49 /**
50  * \ingroup spi_libese
51  * \brief Ese library init parameters to be set while calling phNxpEse_init
52  *
53  */
54 typedef struct phNxpEse_initParams {
55   phNxpEse_initMode initMode; /*!< Ese communication mode */
56 } phNxpEse_initParams;
57 
58 /*!
59  * \brief SEAccess kit MW Android version
60  */
61 #define NXP_ANDROID_VER (8U)
62 
63 /*!
64  * \brief SEAccess kit MW Major version
65  */
66 #define ESELIB_MW_VERSION_MAJ (0x3)
67 
68 /*!
69  * \brief SEAccess kit MW Minor version
70  */
71 #define ESELIB_MW_VERSION_MIN (0x00)
72 
73 /******************************************************************************
74  * \ingroup spi_libese
75  *
76  * \brief  It Initializes protocol stack instance variables
77  *
78  * \retval This function return ESESTATUS_SUCCES (0) in case of success
79  *         In case of failure returns other failure value.
80  *
81  ******************************************************************************/
82 ESESTATUS phNxpEse_init(phNxpEse_initParams initParams);
83 
84 /******************************************************************************
85  * \ingroup spi_libese
86  *
87  * \brief  Check if libese has opened
88  *
89  * \retval return false if it is close, otherwise true.
90  *
91  ******************************************************************************/
92 bool phNxpEse_isOpen();
93 
94 /******************************************************************************
95  * \ingroup spi_libese
96  *
97  * \brief  This function is used to communicate from nfc-hal to ese-hal
98  *
99  * \retval This function return ESESTATUS_SUCCES (0) in case of success
100  *         In case of failure returns other failure value.
101  *
102  ******************************************************************************/
103 ESESTATUS phNxpEse_spiIoctl(uint64_t ioctlType, void* p_data);
104 
105 /**
106  * \ingroup spi_libese
107  * \brief This function is called by Jni during the
108  *        initialization of the ESE. It opens the physical connection
109  *        with ESE () and initializes the protocol stack
110  *
111  *
112  * \retval ESESTATUS_SUCCESS On Success ESESTATUS_SUCCESS else proper error code
113  *
114  */
115 ESESTATUS phNxpEse_open(phNxpEse_initParams initParams);
116 
117 /**
118  * \ingroup spi_libese
119  * \brief It opens the physical connectio with ESE () and creates required
120  *        client thread for operation. This will get priority access to ESE
121  *        for timeout period.
122  *
123  * \retval ESESTATUS_SUCCESS On Success ESESTATUS_SUCCESS else proper error code
124  *
125  */
126 ESESTATUS phNxpEse_openPrioSession(phNxpEse_initParams initParams);
127 
128 /**
129  * \ingroup spi_libese
130  * \brief This function prepares the C-APDU, send to ESE and then receives the
131  *response from ESE,
132  *         decode it and returns data.
133  *
134  * \param[in]       phNxpEse_data: Command to ESE
135  * \param[out]     phNxpEse_data: Response from ESE (Returned data to be freed
136  *after copying)
137  *
138  * \retval ESESTATUS_SUCCESS On Success ESESTATUS_SUCCESS else proper error code
139  *
140  */
141 
142 ESESTATUS phNxpEse_Transceive(phNxpEse_data* pCmd, phNxpEse_data* pRsp);
143 
144 /******************************************************************************
145  * \ingroup spi_libese
146  *
147  * \brief  This function is called by Jni/phNxpEse_close during the
148  *         de-initialization of the ESE. It de-initializes protocol stack
149  *instance variables
150  *
151  * \retval This function return ESESTATUS_SUCCES (0) in case of success
152  *         In case of failure returns other failure value.
153  *
154  ******************************************************************************/
155 ESESTATUS phNxpEse_deInit(void);
156 
157 /**
158  * \ingroup spi_libese
159  * \brief This function close the ESE interface and free all resources.
160  *
161  * \param[in]       void
162  *
163  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
164  *
165  */
166 
167 ESESTATUS phNxpEse_close(void);
168 
169 /**
170  * \ingroup spi_libese
171  * \brief This function reset the ESE interface and free all
172  *
173  * \param[in]       void
174  *
175  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
176  *
177  */
178 ESESTATUS phNxpEse_reset(void);
179 
180 /**
181  * \ingroup spi_libese
182  * \brief This function reset the ESE
183  *
184  * \param[in]       void
185  *
186  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
187  *
188  */
189 ESESTATUS phNxpEse_resetJcopUpdate(void);
190 
191 /**
192  * \ingroup spi_libese
193  * \brief This function reset the P73 through ISO RST pin
194  *
195  * \param[in]       void
196  *
197  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
198  *
199  */
200 ESESTATUS phNxpEse_chipReset(void);
201 
202 /**
203  * \ingroup spi_libese
204  * \brief This function is used to set IFSC size
205  *
206  * \param[in]       uint16_t IFSC_Size
207  *
208  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
209  *
210  */
211 ESESTATUS phNxpEse_setIfsc(uint16_t IFSC_Size);
212 
213 /**
214  * \ingroup spi_libese
215  * \brief This function sends the S-frame to indicate END_OF_APDU
216  *
217  * \param[in]       void
218  *
219  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
220  *
221  */
222 ESESTATUS phNxpEse_EndOfApdu(void);
223 
224 /**
225  * \ingroup spi_libese
226  * \brief This function  suspends execution of the calling thread for
227  *           (at least) usec microseconds
228  *
229  * \param[in]       void
230  *
231  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
232  *
233  */
234 ESESTATUS phNxpEse_Sleep(uint32_t usec);
235 
236 /**
237  * \ingroup spi_libese
238  * \brief This function updates destination buffer with val
239  *                 data in len size
240  *
241  * \param[in]    buff                - Array to be udpated
242  * \param[in]    val                 - value to be updated
243  * \param[in]    len                 - length of array to be updated
244  *
245  * \retval   void
246  *
247  */
248 void* phNxpEse_memset(void* buff, int val, size_t len);
249 
250 /**
251  * \ingroup spi_libese
252  * \brief This function copies source buffer to  destination buffer
253  *                 data in len size
254  *
255  * \param[in]    dest                - Destination array to be updated
256  * \param[in]    src                 - Source array to be updated
257  * \param[in]    len                 - length of array to be updated
258  *
259  * \retval   void
260  *
261  */
262 void* phNxpEse_memcpy(void* dest, const void* src, size_t len);
263 
264 /**
265  * \ingroup spi_libese
266  * \brief This function  suspends allocate memory
267  *
268  * \param[in]       uint32_t size
269  *
270  * \retval allocated memory.
271  *
272  */
273 void* phNxpEse_memalloc(uint32_t size);
274 
275 /**
276  * \ingroup spi_libese
277  * \brief This is utility function for runtime heap memory allocation
278  *
279  * \param[in]    len                 - number of bytes to be allocated
280  *
281  * \retval   void
282  *
283  */
284 void* phNxpEse_calloc(size_t dataType, size_t size);
285 
286 /**
287  * \ingroup spi_libese
288  * \brief This is utility function for freeeing heap memory allocated
289  *
290  * \param[in]    ptr                 - Address pointer to previous allocation
291  *
292  * \retval   void
293  *
294  */
295 void phNxpEse_free(void* ptr);
296 
297 /**
298 + * \ingroup spi_libese
299 + * \brief This function perfroms disbale/enable power control
300 + *
301 + * \param[in]       void
302 + *
303 + * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
304 + *
305 +*/
306 ESESTATUS phNxpEse_DisablePwrCntrl(void);
307 
308 /**
309  * \ingroup spi_libese
310  * \brief This function is used to get the ESE timer status
311  *
312  * \param[in]       phNxpEse_data timer_buffer
313  *
314  * \retval ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0).
315  *
316  */
317 ESESTATUS phNxpEse_GetEseStatus(phNxpEse_data* timer_buffer);
318 /** @} */
319 #endif /* _PHNXPSPILIB_API_H_ */
320