• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *                                                                             *
21  * \file  phHciNfc_Generic.h                                                   *
22  * \brief Common HCI Header for the Generic HCI Management.                    *
23  *                                                                             *
24  *                                                                             *
25  * Project: NFC-FRI-1.1                                                        *
26  *                                                                             *
27  * $Date: Mon Mar 29 17:34:47 2010 $                                           *
28  * $Author: ing04880 $                                                         *
29  * $Revision: 1.73 $                                                           *
30  * $Aliases: 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 $
31  *                                                                             *
32  * =========================================================================== *
33  */
34  
35  /*@{*/
36  #ifndef PHHCINFC_GENERIC_H
37  #define PHHCINFC_GENERIC_H
38  
39  /*@}*/
40  
41  
42  /**
43   *  \name HCI
44   *
45   * File: \ref phHciNfc_Generic.h
46   *
47   */
48  /*@{*/
49  #define PHHCINFC_GENERIC_FILEREVISION "$Revision: 1.73 $" /**< \ingroup grp_file_attributes */
50  #define PHHCINFC_GENERIC_FILEALIASES  "$Aliases: 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 */
51  /*@}*/
52  /*
53  
54  ################################################################################
55  ***************************** Header File Inclusion ****************************
56  ################################################################################
57  */
58  #define LOG_TAG "NFC-HCI"
59  #include <cutils/log.h>
60  #include <phNfcIoctlCode.h>
61  #include<phNfcInterface.h>
62  #include <phHciNfc.h>
63  /*
64  ################################################################################
65  ****************************** Macro Definitions *******************************
66  ################################################################################
67  */
68  
69  #define Trace_buffer    phOsalNfc_DbgTraceBuffer
70  
71  /* HCI TRACE Macros */
72  #if defined(HCI_TRACE)&& !defined(SILENT_HCI)
73  #include <phOsalNfc.h>
74  #include <stdio.h>
75  extern char phOsalNfc_DbgTraceBuffer[];
76  #define MAX_TRACE_BUFFER    150
77  /* #define HCI_PRINT( str )  phOsalNfc_DbgTrace(str) */
78  #define HCI_PRINT( str )  phOsalNfc_DbgString(str)
79  #define HCI_DEBUG(...) ALOGD(__VA_ARGS__)
80  
81  
82  
83  
84  #define HCI_PRINT_BUFFER(msg,buf,len)               \
85      {                                               \
86          snprintf(Trace_buffer,MAX_TRACE_BUFFER,"\t %s:",msg); \
87          phOsalNfc_DbgString(Trace_buffer);              \
88          phOsalNfc_DbgTrace(buf,len);                \
89          phOsalNfc_DbgString("\r");                  \
90                                                      \
91      }
92  #else
93  #include <phDbgTrace.h>
94  #if defined(PHDBG_TRACES) && !defined(HCI_TRACE)
95  #define HCI_PRINT( str )  PHDBG_INFO(str)
96  #define HCI_DEBUG(str, arg)
97  #define HCI_PRINT_BUFFER(msg,buf,len)
98  #else
99  #define HCI_PRINT( str )
100  #define HCI_DEBUG(...)
101  #define HCI_PRINT_BUFFER(msg,buf,len)
102  #endif  /* #if defined(PHDBG_TRACES) */
103  /* #if defined(PHDBG_INFO) && defined (PHDBG_CRITICAL_ERROR) */
104  
105  #endif /* #if defined(HCI_TRACE) */
106  
107  #define ZERO                        0x00U
108  
109  
110  #ifdef MASK_BITS
111  #define BYTE_SIZE                   0x08U
112  
113  /* HCI GET and SET BITS Macros */
114  #define MASK_BITS8(p,l) \
115                           ( ( (((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE )? \
116                            (~(0xFFU<<((p)+(l))) & (0xFFU<<(p))):(0U) )
117  #ifdef MASK_BITS
118  #define GET_BITS8(num,p,l) \
119                            ( ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \
120                             (((num)& (MASK_BITS8(p,l)))>>(p)):(0U) )
121  #else
122  #define GET_BITS8(num,p,l) \
123                            ( ((((p)+(l))<=BYTE_SIZE))? \
124                             (((num)>>(p))& (~(0xFFU<<(l)))):(0U) )
125  #endif
126  #define SET_BITS8(num,p,l,val) \
127                           (  ((((uint8_t)(p))+((uint8_t)(l)))<=BYTE_SIZE)? \
128                             (((num)& (~MASK_BITS8(p,l)))|((val)<<(p))):(0U))
129  
130  #endif
131  
132  /** \ingroup grp_hci_retval
133      The Corresponding HCI Gate Not Supported.
134   */
135  #define NFCSTATUS_HCI_GATE_NOT_SUPPORTED    (0x71U)
136  
137  /** \ingroup grp_hci_retval
138      Invalid Command from the HCI Layer
139   */
140  #define NFCSTATUS_INVALID_HCI_COMMAND       (0x72U)
141  
142  /** \ingroup grp_hci_retval
143      HCI Command not supported . */
144  #define NFCSTATUS_COMMAND_NOT_SUPPORTED     (0x73U)
145  
146  /** \ingroup grp_hci_retval
147      Invalide Response from the HCI Layer
148   */
149  #define NFCSTATUS_INVALID_HCI_RESPONSE      (0x74U)
150  
151  /** \ingroup grp_hci_retval
152      The Invalid Instruction type (Neither Command/Response nor Event ).
153   */
154  #define NFCSTATUS_INVALID_HCI_INSTRUCTION   (0x75U)
155  
156  /** \ingroup grp_hci_retval
157      The Invalid Instruction type (Neither Command/Response nor Event ).
158   */
159  #define NFCSTATUS_INVALID_HCI_INFORMATION   (0x76U)
160  
161  /** \ingroup grp_hci_retval
162      The Invalid HCI Sequence.
163   */
164  #define NFCSTATUS_INVALID_HCI_SEQUENCE      (0x78U)
165  
166  
167  /** \ingroup grp_hci_retval
168      The HCI Error Response with Response code.
169   */
170  #define NFCSTATUS_HCI_RESPONSE(code)        (code)
171  
172  
173  /* Length of the HCP and the HCP Message Header in Bytes */
174  #define HCP_HEADER_LEN          0x02U
175  
176  /* Length of the HCP Message Header in Bytes */
177  #define HCP_MESSAGE_LEN         0x01U
178  
179  /* HCP Header Chaining Bit Offset */
180  #define HCP_CHAINBIT_OFFSET     0x07U
181  /* HCP Header Chaining Bit Length */
182  #define HCP_CHAINBIT_LEN        0x01U
183  
184  /* Chaining Bit Values */
185  #define HCP_CHAINBIT_DEFAULT    0x01U
186  #define HCP_CHAINBIT_BEGIN      0x00U
187  #define HCP_CHAINBIT_END        HCP_CHAINBIT_DEFAULT
188  
189  /* HCP Header Pipe ID Offset */
190  #define HCP_PIPEID_OFFSET       0x00U
191  /* HCP Header Pipe ID Length */
192  #define HCP_PIPEID_LEN          0x07U
193  
194  /* HCP Message Header Type  Offset */
195  #define HCP_MSG_TYPE_OFFSET     0x06U
196  /* HCP Message Header Type Length */
197  #define HCP_MSG_TYPE_LEN        0x02U
198  
199  /* HCP Message Type Values */
200  #define HCP_MSG_TYPE_COMMAND        0x00U
201  #define HCP_MSG_TYPE_EVENT          0x01U
202  #define HCP_MSG_TYPE_RESPONSE       0x02U
203  #define HCP_MSG_TYPE_RESERVED       0x03U
204  
205  /* HCP Message Header Instruction  Offset */
206  #define HCP_MSG_INSTRUCTION_OFFSET  0x00U
207  /* HCP Message Header Instruction Length */
208  #define HCP_MSG_INSTRUCTION_LEN     0x06U
209  /* HCP Invalid Message Instruction */
210  #define HCP_MSG_INSTRUCTION_INVALID 0x3FU
211  
212  
213  /* HCP Packet Zero Length */
214  #define HCP_ZERO_LEN                0x00U
215  
216  
217  
218      /** \internal Generic HCI Commands for all the Gates */
219  #define ANY_SET_PARAMETER                   0x01U
220  #define ANY_GET_PARAMETER                   0x02U
221  #define ANY_OPEN_PIPE                       0x03U
222  #define ANY_CLOSE_PIPE                      0x04U
223  #define ANY_GENERIC_CMD_RFU_B               0x05U
224  #define ANY_GENERIC_CMD_RFU_E               0x0FU
225  
226  /*
227   *  0x05-0x0F is Reserved for Future Use
228   */
229  
230  /** \internal HCI Administration Com mands for the Management of the Host Network */
231  
232  #define ADM_CREATE_PIPE                     0x10U
233  #define ADM_DELETE_PIPE                     0x11U
234  #define ADM_NOTIFY_PIPE_CREATED             0x12U
235  #define ADM_NOTIFY_PIPE_DELETED             0x13U
236  #define ADM_CLEAR_ALL_PIPE                  0x14U
237  #define ADM_NOTIFY_ALL_PIPE_CLEARED         0x15U
238  #define ADM_CMD_RFU_B                       0x16U
239  #define ADM_CMD_RFU_E                       0x3FU
240  
241  #define MSG_INSTRUCTION_UNKNWON             0x3FU
242  
243      /*
244       *  0x16-0x3F is Reserved for Future Use
245       */
246  
247  
248  /** \internal HCI Generic Responses from the Gates */
249  #define ANY_OK                              0x00U
250  #define ANY_E_NOT_CONNECTED                 0x01U
251  #define ANY_E_CMD_PAR_UNKNOWN               0x02U
252  #define ANY_E_NOK                           0x03U
253  #define ANY_E_PIPES_FULL                    0x04U
254  #define ANY_E_REG_PAR_UNKNOWN               0x05U
255  #define ANY_E_PIPE_NOT_OPENED               0x06U
256  #define ANY_E_CMD_NOT_SUPPORTED             0x07U
257  #define ANY_E_INHIBITED                     0x08U
258  #define ANY_E_TIMEOUT                       0x09U
259  #define ANY_E_REG_ACCESS_DENIED             0x0AU
260  #define ANY_E_PIPE_ACCESS_DENIED            0x0BU
261  
262  /* Response Error Code for RF Reader Gate */
263  #define WR_RF_ERROR                         0x10U
264  
265  /*
266  *  0x08, 0x0B-0x3F is Reserved for Future Use
267  */
268  
269  
270  /** \internal HCI Generic Events from the Gates */
271  #define EVT_HCI_END_OF_OPERATION    0x01
272  #define EVT_POST_DATA               0x02
273  #define EVT_HOT_PLUG                0x03
274  
275  
276  /* Maximum Buffer Size for the HCI Data */
277  #define PHHCINFC_MAX_BUFFERSIZE     (PHHAL_MAX_DATASIZE + 0x50U)
278  
279  #define PHHCINFC_MAX_OPENPIPE       0x6FU
280  #define PHHCINFC_MAX_PIPE           0x6FU
281  #define PHHCINFC_MIN_PIPE           0x02U
282  
283  
284  /* Maximum Payload Length of HCI. */
285  #define PHHCINFC_MAX_PACKET_DATA    0x1CU
286  #define PHHCINFC_MAX_HCP_LEN        PHHCINFC_MAX_PACKET_DATA + 1
287  
288  
289  
290  /* Maximum Payload Length of HCI. */
291  
292  
293  /*
294  ################################################################################
295  ******************** Enumeration and Structure Definition **********************
296  ################################################################################
297  */
298  #if 1
299  typedef NFCSTATUS (*pphHciNfc_Pipe_Receive_t) (
300                                                  void *pContext,
301                                                  void *pHwRef,
302                                                  uint8_t *data,
303  #ifdef ONE_BYTE_LEN
304                                                  uint8_t length
305  #else
306                                                  uint16_t length
307  #endif
308                                          );
309  #else
310  
311  typedef pphNfcIF_Transact_t pphHciNfc_Pipe_Receive_t;
312  
313  #endif
314  
315  /** \defgroup grp_hci_nfc HCI Component
316   *
317   *
318   */
319  
320  typedef enum phHciNfc_HostID {
321      phHciNfc_HostControllerID                   = 0x00U,
322      phHciNfc_TerminalHostID                     = 0x01U,
323      phHciNfc_UICCHostID                         = 0x02U
324  /*
325      phHciNfc_HostID_RFU_B                       = 0x03U,
326      phHciNfc_HostID_RFU_E                       = 0xBFU,
327      phHciNfc_HostIDProprietary_B                = 0xC0U,
328      phHciNfc_HostIDProprietary_E                = 0xFFU
329  */
330  }phHciNfc_HostID_t;
331  
332  
333  typedef enum phHciNfc_GateID{
334      phHciNfc_AdminGate                          = 0x00U,
335  /*
336      phHciNfc_evGateIDProprietary_B              = 0x01U,
337      phHciNfc_evGateIDProprietary_E              = 0x03U,
338  */
339      phHciNfc_LoopBackGate                       = 0x04U,
340      phHciNfc_IdentityMgmtGate                   = 0x05U,
341      phHciNfc_LinkMgmtGate                       = 0x06U,
342  /*
343      phHciNfc_GateID_RFU_B                       = 0x07U,
344      phHciNfc_GateID_RFU_E                       = 0x0FU,
345  */
346  
347  /*  TODO: Fillin Other Gate Information */
348      /* ETSI HCI Specific RF Reader Gates */
349      phHciNfc_RFReaderAGate                      = 0x13,
350      phHciNfc_RFReaderBGate                      = 0x11,
351  
352      /* Proprietary Reader Gate */
353      phHciNfc_ISO15693Gate                       = 0x12,
354      phHciNfc_RFReaderFGate                      = 0x14,
355      phHciNfc_JewelReaderGate                    = 0x15,
356  
357      /* ETSI HCI Card RF Gates */
358      phHciNfc_CETypeBGate                        = 0x21,
359      phHciNfc_CETypeBPrimeGate                   = 0x22,
360      phHciNfc_CETypeAGate                        = 0x23,
361      phHciNfc_CETypeFGate                        = 0x24,
362  
363      /* NFC-IP1 Gates */
364      phHciNfc_NFCIP1InitRFGate                   = 0x30,
365      phHciNfc_NFCIP1TargetRFGate                 = 0x31,
366  
367      /* ETSI HCI Connectivity Gate */
368      phHciNfc_ConnectivityGate                   = 0x41,
369  
370  
371      /*  Device Configuration Gates */
372      phHciNfc_PN544MgmtGate                      = 0x90,
373      phHciNfc_HostCommGate                       = 0x91,
374      phHciNfc_GPIOGate                           = 0x92,
375      phHciNfc_RFMgmtGate                         = 0x93,
376      phHciNfc_PollingLoopGate                    = 0x94,
377      phHciNfc_DownloadMgmtGate                   = 0x95,
378  
379      /* Card Emulation Managment Gates */
380      phHciNfc_SwpMgmtGate                        = 0xA0,
381      phHciNfc_NfcWIMgmtGate                      = 0xA1,
382      phHciNfc_UnknownGate                        = 0xFF
383  
384  }phHciNfc_GateID_t;
385  
386  
387  typedef enum phHciNfc_PipeID{
388      HCI_LINKMGMT_PIPE_ID                = 0x00U,
389      HCI_ADMIN_PIPE_ID                   = 0x01U,
390      HCI_DYNAMIC_PIPE_ID                 = 0x02U,
391      HCI_RESERVED_PIPE_ID                = 0x70U,
392      HCI_UNKNOWN_PIPE_ID                 = PHHCINFC_MAX_PIPE
393  /*
394      phHciNfc_evOtherGatePipeID_B                = 0x02U,
395      phHciNfc_evOtherGatePipeID_E                = 0x6FU,
396      phHciNfc_evGatePipeID_RFU_B                 = 0x70U,
397      phHciNfc_evGatePipeID_RFU_E                 = 0x7FU,
398  */
399  }phHciNfc_PipeID_t;
400  
401  
402  typedef enum phHciNfc_eState {
403      hciState_Reset              = 0x00U,
404      hciState_Initialise,
405      hciState_Test,
406      hciState_Config,
407      hciState_IO,
408      hciState_Select,
409      hciState_Listen,
410      hciState_Activate,
411      hciState_Reactivate,
412      hciState_Connect,
413      hciState_Transact,
414      hciState_Disconnect,
415      hciState_Presence,
416      hciState_Release,
417      hciState_Unknown
418  }phHciNfc_eState_t;
419  
420  typedef enum phHciNfc_eMode {
421      hciMode_Reset               = 0x00U,
422      hciMode_Session,
423      hciMode_Override,
424      hciMode_Test,
425      hciMode_Unknown
426  }phHciNfc_eMode_t;
427  
428  
429  typedef enum phHciNfc_eSeq{
430      /* HCI Admin Sequence */
431      ADMIN_INIT_SEQ              = 0x00U,
432      ADMIN_SESSION_SEQ,
433      ADMIN_CE_SEQ,
434      ADMIN_REL_SEQ,
435      ADMIN_EVT_HOTPLUG_SEQ,
436  
437      /* HCI Link Management Sequence */
438      LINK_MGMT_INIT_SEQ,
439      LINK_MGMT_REL_SEQ,
440  
441      /* HCI Identity Management Sequence */
442      IDENTITY_INIT_SEQ,
443      IDENTITY_INFO_SEQ,
444      IDENTITY_REL_SEQ,
445  
446      /* HCI Polling Loop Sequence */
447      PL_INIT_SEQ,
448      PL_DURATION_SEQ,
449      PL_CONFIG_PHASE_SEQ,
450      PL_TGT_DISABLE_SEQ,
451      PL_RESTART_SEQ,
452      PL_STOP_SEQ,
453      PL_REL_SEQ,
454  
455      /* HCI Device Management Sequence */
456      DEV_INIT_SEQ,
457      DEV_HAL_INFO_SEQ,
458      DEV_CONFIG_SEQ,
459      DEV_REL_SEQ,
460  
461      /* HCI Reader Management Sequence */
462      READER_MGMT_INIT_SEQ,
463      READER_ENABLE_SEQ,
464      READER_SELECT_SEQ,
465      READER_REACTIVATE_SEQ,
466      READER_SW_AUTO_SEQ,
467      READER_PRESENCE_CHK_SEQ,
468      READER_UICC_DISPATCH_SEQ,
469      READER_DESELECT_SEQ,
470      READER_RESELECT_SEQ,
471      READER_DISABLE_SEQ,
472      READER_MGMT_REL_SEQ,
473  
474      /* HCI NFC-IP1 Sequence */
475      NFCIP1_INIT_SEQ,
476      INITIATOR_SPEED_SEQ,
477      INITIATOR_GENERAL_SEQ,
478      TARGET_GENERAL_SEQ,
479      TARGET_SPEED_SEQ,
480      NFCIP1_REL_SEQ,
481  
482      /* HCI Emulation Management Sequence */
483      EMULATION_INIT_SEQ,
484      EMULATION_SWP_SEQ,
485      EMULATION_CONFIG_SEQ,
486      EMULATION_REL_SEQ,
487  
488      HCI_END_SEQ,
489      HCI_INVALID_SEQ
490  } phHciNfc_eSeq_t;
491  
492  
493  
494  typedef enum phHciNfc_eSeqType{
495      RESET_SEQ                   = 0x00U,
496      INIT_SEQ,
497      UPDATE_SEQ,
498      INFO_SEQ,
499      CONFIG_SEQ,
500      REL_SEQ,
501      END_SEQ
502  } phHciNfc_eSeqType_t;
503  
504  
505  typedef enum phHciNfc_eConfigType{
506      INVALID_CFG                 = 0x00U,
507      POLL_LOOP_CFG,
508      SMX_WI_CFG,
509      SMX_WI_MODE,
510      UICC_SWP_CFG,
511      SWP_EVT_CFG,
512      SWP_PROTECT_CFG,
513      NFC_GENERAL_CFG,
514      NFC_TARGET_CFG,
515      NFC_CE_A_CFG,
516      NFC_CE_B_CFG
517  } phHciNfc_eConfigType_t;
518  
519  
520  typedef struct phHciNfc_HCP_Message{
521      /** \internal Identifies the Type and Kind of Instruction */
522      uint8_t     msg_header;
523      /** \internal Host Controller Protocol (HCP) Packet Message Payload */
524      uint8_t     payload[PHHCINFC_MAX_PACKET_DATA - 1];
525  }phHciNfc_HCP_Message_t;
526  
527  
528  typedef struct phHciNfc_HCP_Packet{
529      /** \internal Chaining Information and Pipe Identifier */
530      uint8_t     hcp_header;
531      /** \internal Host Controller Protocol (HCP) Packet Message or Payload */
532      union
533      {
534      /** \internal Host Controller Protocol (HCP) Packet Message */
535          phHciNfc_HCP_Message_t message;
536      /** \internal Host Controller Protocol (HCP) Packet Payload */
537          uint8_t payload[PHHCINFC_MAX_PACKET_DATA];
538      }msg;
539  }phHciNfc_HCP_Packet_t;
540  
541  
542  
543  typedef struct phHciNfc_Gate_Info{
544      /** \internal HCI Host Identifier  */
545      uint8_t     host_id;
546      /** \internal HCI Gate Identifier  */
547      uint8_t     gate_id;
548  }phHciNfc_Gate_Info_t;
549  
550  
551  typedef struct phHciNfc_Pipe_Params{
552      /** \internal HCI Source Gate Information for the pipe  */
553      phHciNfc_Gate_Info_t    source;
554      /** \internal HCI Destination Gate Information for the pipe  */
555      phHciNfc_Gate_Info_t    dest;
556      /** \internal HCI Pipe Identifier  */
557      uint8_t                 pipe_id;
558  }phHciNfc_Pipe_Params_t;
559  
560  
561  typedef struct phHciNfc_Pipe_Info{
562      /** \internal Structure containing the created dynamic pipe information */
563      phHciNfc_Pipe_Params_t      pipe;
564      /** \internal Status of the previous command sent to this pipe */
565      NFCSTATUS                   prev_status;
566      /** \internal previous message type Sent to this pipe */
567      uint8_t                     sent_msg_type;
568      /** \internal Message type Received in this pipe */
569      uint8_t                     recv_msg_type;
570      /** \internal previous message sent to this pipe */
571      uint8_t                     prev_msg;
572      /** \internal Index of the previous Set/Get Parameter command
573       *  sent to this pipe */
574      uint8_t                     reg_index;
575      /** \internal length of Parameter of the Set/Get Parameter
576       *  command sent to this pipe */
577      uint16_t                    param_length;
578      /** \internal Parameter of the Set/Get Parameter command
579       *  sent to this pipe */
580      void                        *param_info;
581      /** \internal Pointer to a Pipe specific Receive Response function */
582      pphHciNfc_Pipe_Receive_t    recv_resp;
583      /** \internal Pointer to a Pipe specific Receive Event function */
584      pphHciNfc_Pipe_Receive_t    recv_event;
585      /** \internal Pointer to a Pipe specific Receive Command function */
586      pphHciNfc_Pipe_Receive_t    recv_cmd;
587  }phHciNfc_Pipe_Info_t;
588  
589  
590  typedef struct phHciNfc_sContext{
591      /** \internal HCI Layer Pointer from the upper layer for
592                          lower layer function registration */
593      phNfcLayer_sCfg_t           *p_hci_layer;
594      /** \internal Pointer to the upper layer context */
595      void                        *p_upper_context;
596      /** \internal Pointer to the Hardware Reference Sturcture */
597      phHal_sHwReference_t        *p_hw_ref;
598      /** \internal Pointer to the upper layer notification callback function */
599      pphNfcIF_Notification_CB_t  p_upper_notify;
600      /** \internal Structure to store the lower interface operations */
601      phNfc_sLowerIF_t            lower_interface;
602      /** \internal Execution Sequence using the HCI Context */
603      volatile phHciNfc_eSeq_t    hci_seq;
604  
605      /** \internal State of the HCI Context */
606      volatile phNfc_sState_t     hci_state;
607  
608      /** \internal Mode of HCI Initialisation */
609      phHciNfc_Init_t             init_mode;
610  
611      /** \internal Memory Information for HCI Initialisation */
612      uint8_t                     hal_mem_info[NXP_HAL_MEM_INFO_SIZE];
613  
614      /** \internal HCI Configuration Type */
615      phHciNfc_eConfigType_t      config_type;
616      /** \internal HCI SmartMX Mode Configuration */
617      phHal_eSmartMX_Mode_t       smx_mode;
618      /** \internal HCI Configuration Information */
619      void                        *p_config_params;
620  
621      /** \internal Current RF Reader/Emulation Gate in Use */
622      phHal_eRFDevType_t          host_rf_type;
623  
624      /** \internal Connected Target Information */
625      phHal_sRemoteDevInformation_t *p_target_info;
626  
627      /** \internal Information of all the pipes created and opened */
628      phHciNfc_Pipe_Info_t        *p_pipe_list[PHHCINFC_MAX_PIPE+1];
629  
630      /** \internal Tag */
631      phHciNfc_XchgInfo_t         *p_xchg_info;
632  
633      /** \internal Information of the HCI Gates */
634      /** \internal HCI Admin Management Gate Information */
635      void                        *p_admin_info;
636      /** \internal HCI Link Management Gate Information */
637      void                        *p_link_mgmt_info;
638      /** \internal HCI Identity Management Gate Information */
639      void                        *p_identity_info;
640      /** \internal HCI Polling Loop Gate Information */
641      void                        *p_poll_loop_info;
642      /** \internal HCI NFC Device Management Information */
643      void                        *p_device_mgmt_info;
644      /** \internal HCI RF Reader Gates Management Information */
645      void                        *p_reader_mgmt_info;
646      /** \internal HCI Card Application Gates and Emulation
647                    Information */
648      void                        *p_emulation_mgmt_info;
649      /** \internal HCI RF Reader A Gate Information */
650      void                        *p_reader_a_info;
651  #ifdef TYPE_B
652      /** \internal HCI RF Reader B Gate Information */
653      void                        *p_reader_b_info;
654  #endif
655  #ifdef TYPE_FELICA
656      /** \internal HCI Felica Reader Gate Information */
657      void                        *p_felica_info;
658  #endif
659  #ifdef TYPE_JEWEL
660      /** \internal HCI Jewel Reader Gate Information */
661      void                        *p_jewel_info;
662  #endif
663  #ifdef TYPE_ISO15693
664      /** \internal HCI ISO15693 Reader Gate Information */
665      void                        *p_iso_15693_info;
666  #endif
667  
668  #ifdef ENABLE_P2P
669      /** \internal HCI NFC-IP1 Peer to Peer Information */
670      void                        *p_nfcip_info;
671  #endif
672      /** \internal HCI Secure Element Management Information */
673      void                        *p_wi_info;
674      /** \internal HCI UICC Information */
675      void                        *p_uicc_info;
676      /** \internal HCI SWP Information */
677      void                        *p_swp_info;
678  #ifdef HOST_EMULATION
679      /** \internal HCI Card Emulation A Gate Information */
680      void                        *p_ce_a_info;
681      /** \internal HCI Card Emulation B Gate Information */
682      void                        *p_ce_b_info;
683  #endif
684  
685      /** \internal HCI Packet Data to be sent to the lower layer */
686      phHciNfc_HCP_Packet_t       tx_packet;
687      /** \internal HCI Packet Data to be received from the lower layer */
688      phHciNfc_HCP_Packet_t       rx_packet;
689  
690      /** \internal Previous Status (To Store the Error Status ) */
691      NFCSTATUS                   error_status;
692  
693      /** \internal Pointer to HCI Send Buffer */
694      uint8_t                     send_buffer[PHHCINFC_MAX_BUFFERSIZE];
695      /** \internal Pointer to HCI Receive Buffer */
696      uint8_t                     recv_buffer[PHHCINFC_MAX_BUFFERSIZE];
697  
698      /** \internal Total Number of bytes to be Sent */
699      volatile uint16_t           tx_total;
700      /** \internal Number of bytes Remaining to be Sent */
701      volatile uint16_t           tx_remain;
702      /** \internal Number of bytes sent */
703      volatile uint16_t           tx_sent;
704  
705      volatile uint16_t           rx_index;
706  
707      /** \internal Total Number of bytes received */
708      volatile uint16_t           rx_total;
709      /** \internal Number of bytes received */
710      volatile uint16_t           rx_recvd;
711      /** \internal Index of the received data in the
712      *   response packet
713      */
714  
715      /** \internal Send HCP Chaining Information */
716      volatile uint8_t            tx_hcp_chaining;
717      /** \internal Send HCP  Fragment Index */
718      volatile uint16_t           tx_hcp_frgmnt_index;
719  
720      /** \internal Receive HCP Chaining Information */
721      volatile uint8_t            rx_hcp_chaining;
722      /** \internal Receive HCP Fragment Index */
723      volatile uint16_t           rx_hcp_frgmnt_index;
724  
725      /** \internal The Device under Test */
726      volatile uint8_t            hci_mode;
727      /** \internal Wait for Response if Response is Pending  */
728      volatile uint8_t            response_pending;
729      /** \internal Notify the Event if Notifcation is Pending  */
730      volatile uint8_t            event_pending;
731  
732      /** \internal Pending Release of the detected Target */
733      uint8_t                     target_release;
734  
735  }phHciNfc_sContext_t;
736  
737  /*
738  ################################################################################
739  *********************** Function Prototype Declaration *************************
740  ################################################################################
741  */
742  
743  
744  /**
745   *
746   * \ingroup grp_hci_nfc
747   *
748   *  The phHciNfc_Receive function receives the HCI Events or Response from the
749   *  corresponding peripheral device, described by the HCI Context Structure.
750   *
751   *  \param[in]  psContext               psContext is the context of
752   *                                      the HCI Layer.
753   *  \param[in]  pHwRef                  pHwRef is the Information of
754   *                                      the Device Interface Link .
755   *  \param[out] pdata                   Pointer to the response buffer that
756   *                                      receives the response read.
757   *  \param[in] length                   Variable that receives
758   *                                      the number of bytes read.
759   *
760   *  \retval NFCSTATUS_PENDING           Data successfully read.
761   *  \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
762   *                                      could not be interpreted properly.
763   *  \retval Other errors                Other related errors
764   *
765   */
766  
767  extern
768  NFCSTATUS
769  phHciNfc_Receive(
770                          void                *psContext,
771                          void                *pHwRef,
772                          uint8_t             *pdata,
773  #ifdef ONE_BYTE_LEN
774                          uint8_t             length
775  #else
776                          uint16_t            length
777  #endif
778                  );
779  
780  /**
781   * \ingroup grp_hci_nfc
782   *
783   *  The phHciNfc_Send_Complete function acknowledges the completion of the HCI
784   *  Commands sent to the device.
785   *
786   *  \param[in]  psContext               psContext is the context of
787   *                                      the HCI Layer.
788   *  \param[in]  pHwRef                  pHwRef is the Information of
789   *                                      the Device Interface Link .
790   *  \param[in]  pInfo                   Transaction information like
791   *                                      status and length after the
792   *                                      completion of the send.
793   *
794   *  \retval NONE.
795   *
796   */
797  
798  extern
799  void
800  phHciNfc_Send_Complete (
801                              void                    *psContext,
802                              void                    *pHwRef,
803                              phNfc_sTransactionInfo_t *pInfo
804                         );
805  
806  /**
807   * \ingroup grp_hci_nfc
808   *
809   *  The phHciNfc_Receive_Complete function acknowledges the completion of the HCI
810   *  Event Information or Response received from the device.
811   *
812   *  \param[in]  psContext               psContext is the context of
813   *                                      the HCI Layer.
814   *  \param[in]  pHwRef                  pHwRef is the Information of
815   *                                      the Device Interface Link .
816   *  \param[in]  pInfo                   Transaction information like status
817   *                                      data and length after the completely
818   *                                      receiving the response .
819   *  \retval NONE.
820   *
821   *
822   */
823  
824  extern
825  void
826  phHciNfc_Receive_Complete (
827                                  void                    *psContext,
828                                  void                    *pHwRef,
829                                  phNfc_sTransactionInfo_t *pInfo
830                            );
831  
832  /**
833   * \ingroup grp_hci_nfc
834   *
835   *  The phHciNfc_Notify_Event function notifies the occurence of the HCI
836   *  Event from the device.
837   *
838   *  \param[in]  psContext               psContext is the context of
839   *                                      the HCI Layer.
840   *  \param[in]  pHwRef                  pHwRef is the Information of
841   *                                      the Device Interface Link .
842   *  \param[in]  type                    reason returned for the notification to
843   *                                      the HCI.
844   *  \param[in]  pInfo                   Notification information like status
845   *                                      data,length etc from the lower layer
846   *                                      to the HCI Layer.
847   *  \retval NONE.
848   *
849   */
850  
851  extern
852  void
853  phHciNfc_Notify_Event(
854                              void                    *psContext,
855                              void                    *pHwRef,
856                              uint8_t                 type,
857                              void                    *pInfo
858                      );
859  
860  /**
861   * \ingroup grp_hci_nfc
862   *
863   *  The phHciNfc_Tag_Notify function notifies the the upper layer
864   *  with the Tag Specific Notifications .
865   *
866   *  \param[in]  psContext               psContext is the context of
867   *                                      the HCI Layer.
868   *  \param[in]  pHwRef                  pHwRef is the Information of
869   *                                      the Device Interface Link .
870   *  \param[in]  type                    reason returned for the notification to
871   *                                      the HCI.
872   *  \param[in]  pInfo                   Notification information like status
873   *                                      data,length etc from the lower layer
874   *                                      to the HCI Layer.
875   *  \retval NONE.
876   *
877   */
878  extern
879  void
880  phHciNfc_Tag_Notify(
881                              phHciNfc_sContext_t     *psHciContext,
882                              void                    *pHwRef,
883                              uint8_t                 type,
884                              void                    *pInfo
885                 );
886  
887  /**
888   * \ingroup grp_hci_nfc
889   *
890   *  The phHciNfc_Tag_Notify function notifies the the upper layer
891   *  with the Tag Specific Notifications .
892   *
893   *  \param[in]  psContext               psContext is the context of
894   *                                      the HCI Layer.
895   *  \param[in]  pHwRef                  pHwRef is the Information of
896   *                                      the Device Interface Link .
897   *  \param[in]  type                    reason returned for the notification to
898   *                                      the HCI.
899   *  \param[in]  pInfo                   Notification information like status
900   *                                      data,length etc from the lower layer
901   *                                      to the HCI Layer.
902   *  \retval NONE.
903   *
904   */
905  
906  extern
907  void
908  phHciNfc_Target_Select_Notify(
909                              phHciNfc_sContext_t     *psHciContext,
910                              void                    *pHwRef,
911                              uint8_t                 type,
912                              void                    *pInfo
913                 );
914  
915  
916  /**
917   * \ingroup grp_hci_nfc
918   *
919   *  The phHciNfc_Transceive_Notify function notifies the the upper layer
920   *  with the after the transceive operation.
921   *
922   *  \param[in]  psContext               psContext is the context of
923   *                                      the HCI Layer.
924   *  \param[in]  pHwRef                  pHwRef is the Information of
925   *                                      the Device Interface Link .
926   *  \param[in]  type                    reason returned for the notification to
927   *                                      the HCI.
928   *  \param[in]  pInfo                   Notification information like status
929   *                                      data,length etc from the lower layer
930   *                                      to the HCI Layer.
931   *  \retval NONE.
932   *
933   */
934  extern
935  void
936  phHciNfc_Transceive_Notify(
937                              phHciNfc_sContext_t     *psHciContext,
938                              void                    *pHwRef,
939                              uint8_t                 type,
940                              void                    *pInfo
941                 );
942  
943  /**
944   * \ingroup grp_hci_nfc
945   *
946   *  The phHciNfc_Notify function calls the upper layer notification callback.
947   *
948   *  \param[in]  pUpperNotify            pUpperNotify is the notification
949   *                                      callback of the upper HAL Layer.
950   *  \param[in]  pUpperContext           pUpperContext is the context of
951   *                                      the upper HAL Layer.
952   *  \param[in]  pHwRef                  pHwRef is the Information of
953   *                                      the Device Interface Link .
954   *  \param[in]  type                    type of the notification to
955   *                                      the upper HAL layer.
956   *  \param[in]  pInfo                   completion information returned
957   *                                      to the Upper HAL Layer.
958   *  NFCSTATUS_SUCCESS                   Notification successfully completed .
959   *  NFCSTATUS_INVALID_PARAMETER         One or more of the supplied parameters
960   *                                      could not be interpreted properly.
961   *  Other errors                        Errors related to the HCI or lower layers
962   *
963   *  \retval NONE.
964   *
965   */
966  
967  extern
968  void
969  phHciNfc_Notify(
970                      pphNfcIF_Notification_CB_t  p_upper_notify,
971                      void                        *p_upper_context,
972                      void                        *pHwRef,
973                      uint8_t                     type,
974                      void                        *pInfo
975                 );
976  
977  /**
978   * \ingroup grp_hci_nfc
979   *
980   *  The phHciNfc_Release_Notify function Releases HCI and notifies
981   *  the upper layer.
982   *
983   *  \param[in]  psHciContext            psHciContext is the context of
984   *                                      the HCI Layer.
985   *  \param[in]  pHwRef                  pHwRef is the Information of
986   *                                      the Device Interface Link .
987   *  \param[in]  type                    reason returned for the notification to
988   *                                      the HCI.
989   *  \param[in]  pInfo                   Notification information like status
990   *                                      data,length etc from the lower layer
991   *                                      to the HCI Layer.
992   *  \retval NONE.
993   *
994   */
995  extern
996  void
997  phHciNfc_Release_Notify(
998                              phHciNfc_sContext_t     *psHciContext,
999                              void                    *pHwRef,
1000                              uint8_t                 type,
1001                              void                    *pInfo
1002                 );
1003  
1004  
1005  
1006  /**
1007   * \ingroup grp_hci_nfc
1008   *
1009   *  The phHciNfc_Send_Generic_Cmd function sends the HCI Generic Commands
1010   *  to the device.
1011   *
1012   *  \param[in]  psHciContext            psHciContext is the context of
1013   *                                      the HCI Layer.
1014   *  \param[in]  pHwRef                  pHwRef is the Information of
1015   *                                      the Device Interface Link .
1016   *  \param[in]  pipe_id                 The pipe to which the command
1017   *                                      is being sent.
1018   *  \param[in]  cmd                     The HCI Generic command sent to a
1019   *                                      particular pipe .
1020   *
1021   *  \retval NFCSTATUS_PENDING           HCI Generic Command send in progress .
1022   *  \retval
1023   *  NFCSTATUS_INSUFFICIENT_RESOURCES    The memory could not be allocated
1024   *                                      as required amount of memory
1025   *                                      is not sufficient.
1026   *
1027   */
1028  
1029  extern
1030  NFCSTATUS
1031  phHciNfc_Send_Generic_Cmd (
1032                                  phHciNfc_sContext_t *psHciContext,
1033                                  void                *pHwRef,
1034                                  uint8_t             pipe_id,
1035                                  uint8_t             cmd
1036                      );
1037  
1038  /**
1039   * \ingroup grp_hci_nfc
1040   *
1041   *  The phHciNfc_Set_Param function configures the Gate specific register
1042   *  with the provided value.
1043   *
1044   *  \param[in]  psHciContext            psHciContext is the context of
1045   *                                      the HCI Layer.
1046   *  \param[in]  pHwRef                  pHwRef is the Information of
1047   *                                      the Device Interface Link .
1048   *  \param[in]  p_pipe_info             Pointer to pipe specific information.
1049   *  \param[in]  reg_index               Index of the register to be
1050   *                                      configured .
1051   *  \param[in]  p_param                 Value to the configured in
1052   *                                      particular register.
1053   *  \param[in]  param_length            Length of the parameter provided
1054   *                                      for the configuration.
1055   *
1056   *  \retval NFCSTATUS_PENDING           HCI Set parameter in progress .
1057   *  \retval
1058   *  NFCSTATUS_INVALID_HCI_INFORMATION   The Information like p_pipe_info,
1059   *                                      p_param or param_length is invalid
1060   *
1061   */
1062  
1063  extern
1064  NFCSTATUS
1065  phHciNfc_Set_Param (
1066                              phHciNfc_sContext_t     *psHciContext,
1067                              void                    *pHwRef,
1068                              phHciNfc_Pipe_Info_t    *p_pipe_info,
1069                              uint8_t                 reg_index,
1070                              void                    *p_param,
1071                              uint16_t                 param_length
1072                  );
1073  
1074  /**
1075   * \ingroup grp_hci_nfc
1076   *
1077   *  The phHciNfc_Send_HCP function sends the HCI Host Control Packet
1078   *  Frames to the device.
1079   *
1080   *  \param[in]  psHciContext            psHciContext is the context of
1081   *                                      the HCI Layer.
1082   *  \param[in]  pHwRef                  pHwRef is the Information of
1083   *                                      the Device Interface Link .
1084   *
1085   *  \retval NFCSTATUS_PENDING           HCP Frame send pending.
1086   *  \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
1087   *                                      could not be interpreted properly.
1088   *  \retval Other errors                Other related errors
1089   *
1090   *
1091   */
1092  
1093  extern
1094  NFCSTATUS
1095  phHciNfc_Send_HCP (
1096                              phHciNfc_sContext_t *psHciContext,
1097                              void                *pHwRef
1098                          );
1099  
1100  
1101  /**
1102   * \ingroup grp_hci_nfc
1103   *
1104   *  The phHciNfc_Build_HCPFrame function initially builds the HCP Packet Frame
1105   *  with the values passed in the arguments .
1106   *
1107   *  \param[in]  hcp_packet              hcp_packet is the frame packet structure
1108   *                                      in which the frame is populated with the
1109   *                                      appropriate fields.
1110   *  \param[in]  chainbit                chainbit specifies whether the following
1111   *                                      HCP frames are chained or the frame is a
1112   *                                      normal frame.
1113   *  \param[in]  pipe_id                 pipe_id of the pipe to which the frame has
1114   *                                      to be sent.
1115   *  \param[in]  msg_type                type of message sent to the pipe.
1116   *  \param[in]  instruction             type of message instruction send to the pipe.
1117   *
1118   *  \retval NONE.
1119   *
1120   */
1121  
1122  
1123  extern
1124  void
1125  phHciNfc_Build_HCPFrame (
1126                                  phHciNfc_HCP_Packet_t *hcp_packet,
1127                                  uint8_t             chainbit,
1128                                  uint8_t             pipe_id,
1129                                  uint8_t             msg_type,
1130                                  uint8_t             instruction
1131                        );
1132  
1133  /**
1134   * \ingroup grp_hci_nfc
1135   *
1136   *  The phHciNfc_Append_HCPFrame function Appends the HCP Packet Frame
1137   *  with the values passed in the arguments .
1138   *
1139   *  \param[in]  hcp_data            hcp_data is the pointer to the HCP
1140   *                                  payload to which the data is to be
1141   *                                  appended.
1142   *  \param[in]  hcp_index           hcp_index is the index from which
1143   *                                  the data source needs to be appended.
1144   *  \param[in]  src_data            src_data that is to be appended to the
1145   *                                  HCP packet.
1146   *  \param[in]  src_len             The length of the data source that is
1147   *                                  to be appended.
1148   *  \retval NONE.
1149   *
1150   */
1151  
1152  extern
1153  void
1154   phHciNfc_Append_HCPFrame (
1155                                  uint8_t                 *hcp_data,
1156                                  uint16_t                hcp_index,
1157                                  uint8_t                 *src_data,
1158                                  uint16_t                src_len
1159                            );
1160  
1161  /**
1162   * \ingroup grp_hci_nfc
1163   *
1164   *  The phHciNfc_Allocate_Resource function allocates and initialises the
1165   *  resource memory for the HCI layer.
1166   *
1167   *  \param[in] ppBuffer                 ppBuffer is the pointer to which the
1168   *                                      resource memory is allocated.
1169   *  \param[in] size                     Variable that specifies the size of
1170   *                                      the memory that needs to be created.
1171   *
1172   *  \retval NFCSTATUS_SUCCESS           The Resource Memory was allocated
1173   *                                      successfully .
1174   *  \retval
1175   *  NFCSTATUS_INSUFFICIENT_RESOURCES    The memory could not be allocated
1176   *                                      as required amount of memory
1177   *                                      is not suffient.
1178   *
1179   */
1180  
1181  extern
1182  NFCSTATUS
1183   phHciNfc_Allocate_Resource (
1184                                  void                **ppBuffer,
1185                                  uint16_t            size
1186                              );
1187  /**
1188   * \ingroup grp_hci_nfc
1189   *
1190   *  The phHciNfc_Release_Resources function releases all the resources
1191   *  allocated in the HCI Layer.
1192   *
1193   *  \param[in]  psHciContext            psHciContext is the context of
1194   *                                      the HCI Layer.
1195   *
1196   *  \retval NONE.
1197   *
1198   */
1199  
1200  extern
1201   void
1202   phHciNfc_Release_Resources (
1203                                  phHciNfc_sContext_t **ppsHciContext
1204                              );
1205  
1206  /**
1207   * \ingroup grp_hci_nfc
1208   *
1209   *  The phHciNfc_Release_Lower function initiates the release of the
1210   *  lower layers.
1211   *
1212   *  \param[in]  psHciContext            psHciContext is the context of
1213   *                                      the HCI Layer.
1214   *  \param[in]  pHwRef                  pHwRef is the Information of
1215   *                                      the Device Interface Link .
1216   *
1217   *  \retval NONE.
1218   *
1219   */
1220  
1221  extern
1222  void
1223  phHciNfc_Release_Lower(
1224                      phHciNfc_sContext_t         *psHciContext,
1225                      void                        *pHwRef
1226                 );
1227  
1228  
1229  
1230  #endif
1231  
1232