summaryrefslogtreecommitdiffstats
path: root/inc/phNfcInterface.h
blob: 3a2d9c4adc45e7381c4ee3de9a979a861cb8400a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/*
 * Copyright (C) 2010 NXP Semiconductors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


/*!
* =============================================================================
* \file  phNfcInterface.h
* \brief Generic Interface Layer Function Definitions.
*
* Project: NFC-FRI-1.1
*
* $Date: Thu Feb 11 19:01:36 2010 $
* $Author: ing04880 $
* $Revision: 1.42 $
* $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 $
*
* =============================================================================
*/

#ifndef PHNFCINTERFACE_H /* */
#define PHNFCINTERFACE_H /* */

/**
*  \name NFC Inteface
*
* File: \ref phNfcInterface.h
*
*/

/*@{*/
#define PHNFCINTERFACE_FILEREVISION "$Revision: 1.42 $" /**< \ingroup grp_file_attributes */
#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 */
/*@}*/

/*
################################################################################
***************************** Header File Inclusion ****************************
################################################################################
*/

#include <phNfcTypes.h>
#include <phNfcHalTypes.h>


/*
################################################################################
****************************** Macro Definitions *******************************
################################################################################
*/

#define NFC_FSM_IN_PROGRESS 0x01U
#define NFC_FSM_COMPLETE    0x00U

#define NFC_FSM_CURRENT     0x00U
#define NFC_FSM_NEXT        0x01U

/* NFC Notification Types */

#define NFC_NOTIFY_INIT_COMPLETED       0x01
#define NFC_NOTIFY_INIT_FAILED          0xF1

#define NFC_NOTIFY_DEINIT_COMPLETED     0x02
#define NFC_NOTIFY_DEINIT_FAILED        0xF2

#define NFC_NOTIFY_EVENT        0x70

#define NFC_NOTIFY_DEVICE_ACTIVATED     0x82
#define NFC_NOTIFY_DEVICE_DEACTIVATED   0x83

#define NFC_NOTIFY_SEND_COMPLETED       0x03
#define NFC_NOTIFY_SEND_CE_A_COMPLETED       0x76
#define NFC_NOTIFY_SEND_CE_B_COMPLETED       0x77
#define NFC_NOTIFY_SEND_ERROR           0xF3

#define NFC_NOTIFY_RECV_COMPLETED       0x04
#define NFC_NOTIFY_RECV_ERROR           0xF4
#define NFC_NOTIFY_RECV_EVENT     0x74
#define NFC_NOTIFY_CE_A_RECV_EVENT 0x75
#define NFC_NOTIFY_CE_B_RECV_EVENT 0x78
#define NFC_NOTIFY_RECV_CANCELLED       0x34

#define NFC_NOTIFY_TRANSCEIVE_COMPLETED 0x05
#define NFC_NOTIFY_TRANSCEIVE_ERROR     0xF5

#define NFC_NOTIFY_POLL_ENABLED         0x06
#define NFC_NOTIFY_POLL_RESTARTED   0x16
#define NFC_NOTIFY_POLL_DISABLED        0x26
#define NFC_NOTIFY_CONFIG_SUCCESS   0x36
#define NFC_NOTIFY_CONFIG_ERROR     0xF6

#define NFC_NOTIFY_TARGET_DISCOVERED    0x10
#define NFC_NOTIFY_DISCOVERY_ERROR      0xFA
#define NFC_NOTIFY_TARGET_RELEASED      0x11
#define NFC_NOTIFY_TARGET_CONNECTED     0x12
#define NFC_NOTIFY_TARGET_PRESENT       0x13
#define NFC_NOTIFY_TARGET_REACTIVATED   0x14
#define NFC_NOTIFY_CONNECT_FAILED       0xFC
#define NFC_NOTIFY_TARGET_DISCONNECTED  0x15
#define NFC_NOTIFY_DISCONNECT_FAILED    0xFD

#define NFC_NOTIFY_TRANSACTION      0x07

#define NFC_NOTIFY_RESULT       0x08

#define NFC_NOTIFY_DEVICE_ERROR         0xFEU
#define NFC_NOTIFY_ERROR                0xFFU


#define BYTE_SIZE                       0x08U
#define BYTE_MASK                       0xFFU
/* HCI GET and SET BITS Macros */
#define MASK_BITS8(p,l) \
    ( ( (((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE )? \
    (~(0xFFU<<((p)+(l))) & (0xFFU<<(p))):(0U) )
#ifdef MASK_BITS
#define GET_BITS8(num,p,l) \
    ( ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \
    (((num)& (MASK_BITS8(p,l)))>>(p)):(0U) )
#else
#define GET_BITS8(num,p,l) \
    ( ((((p)+(l))<=BYTE_SIZE))? \
    (((num)>>(p))& (~(0xFFU<<(l)))):(0U) )
#endif
#define SET_BITS8(num,p,l,val) \
    (  ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \
    (((num)& (~MASK_BITS8(p,l)))|((val)<<(p))):(0U))

/*
################################################################################
******************** Enumeration and Structure Definition **********************
################################################################################
*/


enum phNfcIF_eExecution{
    NFC_EXEC_NORMAL                   = 0x00, /**<  Normal Execution Sequence */
    NFC_EXEC_CALLBACK                 = 0x01, /**<  Callback Execution Sequence */
    NFC_EXEC_UNKNOWN                  = 0xFF /**<  Callback Execution Sequence */
};


typedef enum phNfc_eModeType{
  MODE_ON   = 0x00U,       /**<  Switches the particular feature ON*/
  MODE_OFF           /**<  Switches the particular feature OFF*/
}phNfc_eModeType_t;

/**
 * State Structure to hold the State Information
 *
 * This structure holds the state Information of a specified
 * Layer .
 *
 */

typedef struct phNfc_sState
{
    uint8_t     cur_state;
    uint8_t     transition;
    uint8_t     next_state;
    /* uint8_t      event; */

}phNfc_sState_t;



/**
 * Transaction Completion Information Structure
 *
 * This structure holds the completion callback information of the
 * transaction passed from the lower layer to the upper layer
 * along with the completion callback.
 */

typedef struct phNfc_sTransactionInfo
{
  /* Returns the status of the Transaction Completion routine */
    NFCSTATUS           status;
  /* Indicates the Type of the Transaction */
  uint8_t       type;
  /* To contain more Transaction Notification specific info */
  void                *info;
  /* The data response from the Transaction */
    uint8_t             *buffer;
  /* The size of the data response from the Transaction */
    uint16_t             length;
}phNfc_sTransactionInfo_t;

/**
 * Notification Information Structure
 *
 * This structure holds the notification callback information passed from
 * the lower layer to the upper layer along with the notification callback.
 */

typedef struct phNfc_sCompletionInfo
{
    /* Returns the status of the completion routine */
    NFCSTATUS           status;

  /* Indicates the Type of the Information
   * associated with the completion
   */
  uint8_t       type;

  /* To contain more completion specific info */
    void                *info;

}phNfc_sCompletionInfo_t;


/**
 *  Notification Information
 *
 */
typedef struct phNfc_sNotificationInfo
{
  /* Returns the status of the Notification routine */
  NFCSTATUS           status;
  /* Indicates the Type of the Notification */
  phHal_eNotificationType_t   type;
  /* To contain more Notification specific info */
  void              *info;

}phNfc_sNotificationInfo_t;


/*
################################################################################
********************* Callback Function Type Definition ************************
################################################################################
*/

/**
* Interface Notification Callback
*
* This callback notifies the occurrance of an event in the Lower Interface.
*
* \param [in] pContext  Context for the Callback Function
* \param [in] pHwRef    Pointer to the Hardware Reference
* \param [in] type      Type of the Notification sent
* \param [out] pInfo    Pointer to the Transaction Information Structure
*                       which contains the Status of the operation, data
*                       obtained or sent and size of the data sent or received
*/

typedef void (*pphNfcIF_Notification_CB_t) (
                                                void *pContext,
                                                void *pHwRef,
                                                uint8_t type,
                                                void *pInfo
                                             );

/**
* asynchronous Interface Transaction Completion callback
*
* This callback signals the completion of the asynchronous send or receive
* operation. The number of bytes sent or recieved is returned back.
*
* \param [in] pContext  Context for the Callback Function
* \param [in] pHwRef    Pointer to the Hardware Reference
* \param [out] pInfo    Pointer to the Transaction Information Structure
*                       which contains the Status of the operation, data
*                       obtained or sent and size of the data sent or received
*/

typedef void (*pphNfcIF_Transact_Completion_CB_t) (
                                                    void *pContext,
                                                    void *pHwRef,
                                                    phNfc_sTransactionInfo_t *pInfo
                                                );

/*
################################################################################
********************** Generic Interface Function Prototype ********************
################################################################################
*/

/**
 * Generic NFC Interface Function Type .
 *
 * \param [in] pContext     Context pointer for the Generic Interface.
 * \param [in] pHwRef       pointer for the device interface link information.
 */

typedef NFCSTATUS (*pphNfcIF_Interface_t) (
                                                    void *pContext,
                                                    void *pHwRef
                                          );
/**
 * Data Transaction between the lower layer interface
 *
 * Sends or Receives the given amount of data to the lower layer.
 * The call returns immediately and the registered callback is
 * called when all data has been written.
 * <p>
 *
 * @note If the interface is not initialized the function does nothing.
 *
 * \param [in] pContext     Context pointer for sending the data.
 * \param [in] pHwRef       pointer for the device interface link information.
 * \param[in]  data         pointer to data buffer containing the data to be sent or
 *                          to be received. The data pointer is valid at least until
 *                          the registered callback is called.
 * \param[in] length        length of the data to be sent or to be received.
 */

typedef NFCSTATUS (*pphNfcIF_Transact_t) (
                                                void *pContext,
                                                void *pHwRef,
                                                uint8_t *data,
                                                uint16_t length
                                        );


/**
 * Generic Interface structure with the Lower Layer
 *
 * This structure holds the context and function pointers of all functions
 * required to interface with the Lower Layers.
 */

typedef struct phNfc_sLowerIF
{
    void                        *pcontext;
    pphNfcIF_Interface_t        init;
    pphNfcIF_Interface_t        release;
    pphNfcIF_Transact_t         send;
    pphNfcIF_Transact_t         receive;
    pphNfcIF_Transact_t         receive_wait;
    pphNfcIF_Interface_t        transact_abort;
    pphNfcIF_Interface_t        unregister;
} phNfc_sLowerIF_t,*pphNfc_sLowerIF_t;


/**
 * Generic Callback interface structure for the Lower layer.
 *
 * This structure holds the callback function pointers of the functions that
 * performs the completion of a particular operation. These functions are used
 * by the Lower Layer interface to convey the completion of an operation.
 */

typedef struct phNfcIF_sCallBack
{
  /**<Holds context info to be sent to lower layer*/
    void                                        *pif_ctxt;
  /**<Callback notifies occurrance of event in Lower Interface*/
    pphNfcIF_Notification_CB_t                  notify;
  /**<asynchronous Interface Transaction Completion callback*/
    pphNfcIF_Transact_Completion_CB_t           send_complete;
    pphNfcIF_Transact_Completion_CB_t           receive_complete;

} phNfcIF_sCallBack_t ,*pphNfcIF_sCallBack_t ;


/**
 * Interface Reference structure.
 *
 * This structure holds the reference parameters, callback function pointers and
 * lower interface functions .
 */

typedef struct phNfcIF_sReference
{
  /**<Generic Interface structure with the Lower Layer*/
    phNfc_sLowerIF_t                        *plower_if;
  /**<pointer to the data to be sent*/
    uint8_t                                 *tx_data;
  /**<pointer to the data to be received*/
    uint8_t                                 *rx_data;
}phNfcIF_sReference_t, *pphNfcIF_sReference_t;


/*
################################################################################
********************** Register Function Type Definition ***********************
################################################################################
*/

/**
* Registers the interface functions and passes the callback functions to the
* lower layer.
*
* This function passes the callback functions of the interface to the
* lower interface and the lower interface registers its functions.
*/

typedef NFCSTATUS ( *pphNfcIF_Register_t) (
                                phNfcIF_sReference_t        *psReference,
                                phNfcIF_sCallBack_t         if_callback,
                                void                        *psIFConfig
                                );


/**
 * Layer Specific Configuration structure.
 *
 * This structure holds the Lower Layer Name and the registry function for registering
 * the lower layer interface functions .
 */


typedef struct phNfcLayer_sCfg
{
    uint8_t                 layer_index;
    uint8_t                 *layer_name;
    pphNfcIF_Register_t     layer_registry;
    struct phNfcLayer_sCfg  *layer_next;
}phNfcLayer_sCfg_t, *pphNfcLayer_sCfg_t;


#endif /* PHNFCINTERFACE_H */