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