code update
[adaptation/devices/nfc-plugin-nxp.git] / inc / phNfcInterface.h
1 /*\r
2  * Copyright (C) 2010 NXP Semiconductors\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *      http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 \r
18 /*!\r
19 * =============================================================================\r
20 * \file  phNfcInterface.h\r
21 * \brief Generic Interface Layer Function Definitions.\r
22 *\r
23 * Project: NFC-FRI-1.1\r
24 *\r
25 * $Date: Thu Feb 11 19:01:36 2010 $\r
26 * $Author: ing04880 $\r
27 * $Revision: 1.42 $\r
28 * $Aliases: NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $\r
29 *\r
30 * =============================================================================\r
31 */\r
32 \r
33 #ifndef PHNFCINTERFACE_H /* */\r
34 #define PHNFCINTERFACE_H /* */\r
35 \r
36 /**\r
37 *  \name NFC Inteface\r
38 *\r
39 * File: \ref phNfcInterface.h\r
40 *\r
41 */\r
42 \r
43 /*@{*/\r
44 #define PHNFCINTERFACE_FILEREVISION "$Revision: 1.42 $" /**< \ingroup grp_file_attributes */\r
45 #define PHNFCINTERFACE_FILEALIASES  "$Aliases: NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $"   /**< \ingroup grp_file_attributes */\r
46 /*@}*/\r
47 \r
48 /*\r
49 ################################################################################\r
50 ***************************** Header File Inclusion ****************************\r
51 ################################################################################\r
52 */\r
53 \r
54 #include <phNfcTypes.h>\r
55 #include <phNfcHalTypes.h>\r
56 \r
57 \r
58 /*\r
59 ################################################################################\r
60 ****************************** Macro Definitions *******************************\r
61 ################################################################################\r
62 */\r
63 \r
64 #define NFC_FSM_IN_PROGRESS 0x01U\r
65 #define NFC_FSM_COMPLETE    0x00U\r
66 \r
67 #define NFC_FSM_CURRENT     0x00U\r
68 #define NFC_FSM_NEXT        0x01U\r
69 \r
70 /* NFC Notification Types */\r
71 \r
72 #define NFC_NOTIFY_INIT_COMPLETED       0x01\r
73 #define NFC_NOTIFY_INIT_FAILED          0xF1\r
74 \r
75 #define NFC_NOTIFY_DEINIT_COMPLETED     0x02\r
76 #define NFC_NOTIFY_DEINIT_FAILED        0xF2\r
77 \r
78 #define NFC_NOTIFY_EVENT                                0x70\r
79 \r
80 #define NFC_NOTIFY_DEVICE_ACTIVATED     0x82\r
81 #define NFC_NOTIFY_DEVICE_DEACTIVATED   0x83\r
82 \r
83 #define NFC_NOTIFY_SEND_COMPLETED       0x03\r
84 #define NFC_NOTIFY_SEND_ERROR           0xF3\r
85 \r
86 #define NFC_NOTIFY_RECV_COMPLETED       0x04\r
87 #define NFC_NOTIFY_RECV_ERROR           0xF4\r
88 #define NFC_NOTIFY_RECV_EVENT                   0x74\r
89 #define NFC_NOTIFY_RECV_CANCELLED       0x34\r
90 \r
91 #define NFC_NOTIFY_TRANSCEIVE_COMPLETED 0x05\r
92 #define NFC_NOTIFY_TRANSCEIVE_ERROR     0xF5\r
93 \r
94 #define NFC_NOTIFY_POLL_ENABLED         0x06\r
95 #define NFC_NOTIFY_POLL_RESTARTED               0x16\r
96 #define NFC_NOTIFY_POLL_DISABLED        0x26\r
97 #define NFC_NOTIFY_CONFIG_SUCCESS               0x36\r
98 #define NFC_NOTIFY_CONFIG_ERROR                 0xF6\r
99 \r
100 #define NFC_NOTIFY_TARGET_DISCOVERED    0x10\r
101 #define NFC_NOTIFY_DISCOVERY_ERROR      0xFA\r
102 #define NFC_NOTIFY_TARGET_RELEASED      0x11\r
103 #define NFC_NOTIFY_TARGET_CONNECTED     0x12\r
104 #define NFC_NOTIFY_TARGET_PRESENT       0x13\r
105 #define NFC_NOTIFY_TARGET_REACTIVATED   0x14\r
106 #define NFC_NOTIFY_CONNECT_FAILED       0xFC\r
107 #define NFC_NOTIFY_TARGET_DISCONNECTED  0x15\r
108 #define NFC_NOTIFY_DISCONNECT_FAILED    0xFD\r
109 \r
110 #define NFC_NOTIFY_TRANSACTION                  0x07\r
111 \r
112 #define NFC_NOTIFY_RESULT                               0x08\r
113 \r
114 #define NFC_NOTIFY_DEVICE_ERROR         0xFEU\r
115 #define NFC_NOTIFY_ERROR                0xFFU\r
116 \r
117 \r
118 #define BYTE_SIZE                       0x08U\r
119 #define BYTE_MASK                       0xFFU\r
120 /* HCI GET and SET BITS Macros */\r
121 #define MASK_BITS8(p,l) \\r
122     ( ( (((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE )? \\r
123     (~(0xFFU<<((p)+(l))) & (0xFFU<<(p))):(0U) )\r
124 #ifdef MASK_BITS\r
125 #define GET_BITS8(num,p,l) \\r
126     ( ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \\r
127     (((num)& (MASK_BITS8(p,l)))>>(p)):(0U) )\r
128 #else\r
129 #define GET_BITS8(num,p,l) \\r
130     ( ((((p)+(l))<=BYTE_SIZE))? \\r
131     (((num)>>(p))& (~(0xFFU<<(l)))):(0U) )\r
132 #endif\r
133 #define SET_BITS8(num,p,l,val) \\r
134     (  ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \\r
135     (((num)& (~MASK_BITS8(p,l)))|((val)<<(p))):(0U))\r
136 \r
137 /*\r
138 ################################################################################\r
139 ******************** Enumeration and Structure Definition **********************\r
140 ################################################################################\r
141 */\r
142 \r
143 \r
144 enum phNfcIF_eExecution{\r
145     NFC_EXEC_NORMAL                   = 0x00, /**<  Normal Execution Sequence */\r
146     NFC_EXEC_CALLBACK                 = 0x01, /**<  Callback Execution Sequence */\r
147     NFC_EXEC_UNKNOWN                  = 0xFF /**<  Callback Execution Sequence */\r
148 };\r
149 \r
150 \r
151 typedef enum phNfc_eModeType{\r
152         MODE_ON         = 0x00U,       /**<  Switches the particular feature ON*/\r
153         MODE_OFF                                   /**<  Switches the particular feature OFF*/\r
154 }phNfc_eModeType_t;\r
155 \r
156 /**\r
157  * State Structure to hold the State Information\r
158  *\r
159  * This structure holds the state Information of a specified \r
160  * Layer .\r
161  * \r
162  */\r
163 \r
164 typedef struct phNfc_sState\r
165 {\r
166     uint8_t     cur_state;\r
167     uint8_t     transition;\r
168     uint8_t     next_state;\r
169     /* uint8_t      event; */\r
170 \r
171 }phNfc_sState_t;\r
172 \r
173 \r
174 \r
175 /**\r
176  * Transaction Completion Information Structure \r
177  *\r
178  * This structure holds the completion callback information of the \r
179  * transaction passed from the lower layer to the upper layer \r
180  * along with the completion callback.\r
181  */\r
182 \r
183 typedef struct phNfc_sTransactionInfo\r
184 {\r
185         /* Returns the status of the Transaction Completion routine */\r
186     NFCSTATUS           status;\r
187         /* Indicates the Type of the Transaction */\r
188         uint8_t                         type;\r
189         /* To contain more Transaction Notification specific info */\r
190         void                *info;\r
191         /* The data response from the Transaction */\r
192     uint8_t             *buffer;\r
193         /* The size of the data response from the Transaction */\r
194     uint16_t             length;\r
195 }phNfc_sTransactionInfo_t;\r
196 \r
197 /**\r
198  * Notification Information Structure \r
199  *\r
200  * This structure holds the notification callback information passed from \r
201  * the lower layer to the upper layer along with the notification callback.\r
202  */\r
203 \r
204 typedef struct phNfc_sCompletionInfo\r
205 {\r
206     /* Returns the status of the completion routine */\r
207     NFCSTATUS           status;\r
208 \r
209         /* Indicates the Type of the Information\r
210          * associated with the completion\r
211          */\r
212         uint8_t                         type;\r
213 \r
214         /* To contain more completion specific info */\r
215     void                *info;\r
216 \r
217 }phNfc_sCompletionInfo_t;\r
218 \r
219 \r
220 /**\r
221  *  Notification Information \r
222  * \r
223  */\r
224 typedef struct phNfc_sNotificationInfo\r
225 {\r
226         /* Returns the status of the Notification routine */\r
227         NFCSTATUS                                               status;\r
228         /* Indicates the Type of the Notification */\r
229         phHal_eNotificationType_t               type;\r
230         /* To contain more Notification specific info */\r
231         void                                                    *info;\r
232 \r
233 }phNfc_sNotificationInfo_t;\r
234 \r
235 \r
236 /*\r
237 ################################################################################\r
238 ********************* Callback Function Type Definition ************************\r
239 ################################################################################\r
240 */\r
241 \r
242 /**\r
243 * Interface Notification Callback\r
244 *\r
245 * This callback notifies the occurrance of an event in the Lower Interface.\r
246 *\r
247 * \param [in] pContext  Context for the Callback Function\r
248 * \param [in] pHwRef    Pointer to the Hardware Reference\r
249 * \param [in] type      Type of the Notification sent\r
250 * \param [out] pInfo    Pointer to the Transaction Information Structure\r
251 *                       which contains the Status of the operation, data\r
252 *                       obtained or sent and size of the data sent or received\r
253 */\r
254 \r
255 typedef void (*pphNfcIF_Notification_CB_t) (\r
256                                                 void *pContext,\r
257                                                 void *pHwRef,\r
258                                                 uint8_t type,\r
259                                                 void *pInfo\r
260                                              );\r
261 \r
262 /**\r
263 * asynchronous Interface Transaction Completion callback\r
264 *\r
265 * This callback signals the completion of the asynchronous send or receive\r
266 * operation. The number of bytes sent or recieved is returned back.\r
267 *\r
268 * \param [in] pContext  Context for the Callback Function\r
269 * \param [in] pHwRef    Pointer to the Hardware Reference\r
270 * \param [out] pInfo    Pointer to the Transaction Information Structure\r
271 *                       which contains the Status of the operation, data\r
272 *                       obtained or sent and size of the data sent or received\r
273 */\r
274 \r
275 typedef void (*pphNfcIF_Transact_Completion_CB_t) (\r
276                                                     void *pContext,\r
277                                                     void *pHwRef,\r
278                                                     phNfc_sTransactionInfo_t *pInfo\r
279                                                 );\r
280 \r
281 /*\r
282 ################################################################################\r
283 ********************** Generic Interface Function Prototype ********************\r
284 ################################################################################\r
285 */\r
286 \r
287 /**\r
288  * Generic NFC Interface Function Type .\r
289  *\r
290  * \param [in] pContext     Context pointer for the Generic Interface.\r
291  * \param [in] pHwRef       pointer for the device interface link information.\r
292  */\r
293 \r
294 typedef NFCSTATUS (*pphNfcIF_Interface_t) (\r
295                                                     void *pContext,\r
296                                                     void *pHwRef\r
297                                           );\r
298 /**\r
299  * Data Transaction between the lower layer interface\r
300  *\r
301  * Sends or Receives the given amount of data to the lower layer. \r
302  * The call returns immediately and the registered callback is \r
303  * called when all data has been written.\r
304  * <p>\r
305  *\r
306  * @note If the interface is not initialized the function does nothing.\r
307  *\r
308  * \param [in] pContext     Context pointer for sending the data.\r
309  * \param [in] pHwRef       pointer for the device interface link information.\r
310  * \param[in]  data         pointer to data buffer containing the data to be sent or\r
311  *                          to be received. The data pointer is valid at least until\r
312  *                          the registered callback is called.\r
313  * \param[in] length        length of the data to be sent or to be received.\r
314  */\r
315 \r
316 typedef NFCSTATUS (*pphNfcIF_Transact_t) (\r
317                                                 void *pContext,\r
318                                                 void *pHwRef,\r
319                                                 uint8_t *data,\r
320                                                 uint16_t length\r
321                                         );\r
322 \r
323 \r
324 /**\r
325  * Generic Interface structure with the Lower Layer\r
326  *\r
327  * This structure holds the context and function pointers of all functions\r
328  * required to interface with the Lower Layers.\r
329  */\r
330 \r
331 typedef struct phNfc_sLowerIF\r
332 {\r
333     void                        *pcontext;\r
334     pphNfcIF_Interface_t        init;\r
335     pphNfcIF_Interface_t        release;\r
336     pphNfcIF_Transact_t         send;\r
337     pphNfcIF_Transact_t         receive;\r
338     pphNfcIF_Transact_t         receive_wait;\r
339     pphNfcIF_Interface_t        transact_abort;\r
340     pphNfcIF_Interface_t        unregister;\r
341 } phNfc_sLowerIF_t,*pphNfc_sLowerIF_t;\r
342 \r
343 \r
344 /**\r
345  * Generic Callback interface structure for the Lower layer.\r
346  *\r
347  * This structure holds the callback function pointers of the functions that\r
348  * performs the completion of a particular operation. These functions are used\r
349  * by the Lower Layer interface to convey the completion of an operation.\r
350  */\r
351 \r
352 typedef struct phNfcIF_sCallBack\r
353 {\r
354         /**<Holds context info to be sent to lower layer*/\r
355     void                                        *pif_ctxt;\r
356         /**<Callback notifies occurrance of event in Lower Interface*/\r
357     pphNfcIF_Notification_CB_t                  notify;\r
358         /**<asynchronous Interface Transaction Completion callback*/\r
359     pphNfcIF_Transact_Completion_CB_t           send_complete;\r
360     pphNfcIF_Transact_Completion_CB_t           receive_complete;\r
361 \r
362 } phNfcIF_sCallBack_t ,*pphNfcIF_sCallBack_t ;\r
363 \r
364 \r
365 /**\r
366  * Interface Reference structure.\r
367  *\r
368  * This structure holds the reference parameters, callback function pointers and\r
369  * lower interface functions .\r
370  */\r
371 \r
372 typedef struct phNfcIF_sReference\r
373 {\r
374         /**<Generic Interface structure with the Lower Layer*/  \r
375     phNfc_sLowerIF_t                        *plower_if;\r
376         /**<pointer to the data to be sent*/\r
377     uint8_t                                 *tx_data;\r
378         /**<pointer to the data to be received*/\r
379     uint8_t                                 *rx_data;\r
380 }phNfcIF_sReference_t, *pphNfcIF_sReference_t;\r
381 \r
382 \r
383 /*\r
384 ################################################################################\r
385 ********************** Register Function Type Definition ***********************\r
386 ################################################################################\r
387 */\r
388 \r
389 /**\r
390 * Registers the interface functions and passes the callback functions to the\r
391 * lower layer.\r
392 *\r
393 * This function passes the callback functions of the interface to the\r
394 * lower interface and the lower interface registers its functions.\r
395 */\r
396 \r
397 typedef NFCSTATUS ( *pphNfcIF_Register_t) (\r
398                                 phNfcIF_sReference_t        *psReference,\r
399                                 phNfcIF_sCallBack_t         if_callback,\r
400                                 void                        *psIFConfig\r
401                                 );\r
402 \r
403 \r
404 /**\r
405  * Layer Specific Configuration structure.\r
406  *\r
407  * This structure holds the Lower Layer Name and the registry function for registering\r
408  * the lower layer interface functions .\r
409  */\r
410 \r
411 \r
412 typedef struct phNfcLayer_sCfg\r
413 {\r
414     uint8_t                 layer_index;\r
415     uint8_t                 *layer_name;\r
416     pphNfcIF_Register_t     layer_registry;\r
417     struct phNfcLayer_sCfg  *layer_next;\r
418 }phNfcLayer_sCfg_t, *pphNfcLayer_sCfg_t;\r
419 \r
420 \r
421 #endif /* PHNFCINTERFACE_H */\r
422 \r