1/******************************************************************************
2 *
3 *  Copyright (C) 2012-2014 Broadcom Corporation
4 *
5 *  Licensed under the Apache License, Version 2.0 (the "License");
6 *  you may not use this file except in compliance with the License.
7 *  You may obtain a copy of the License at:
8 *
9 *  http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 *
17 ******************************************************************************/
18
19
20/******************************************************************************
21 *
22 *  NFC Hardware Abstraction Layer API
23 *
24 ******************************************************************************/
25#ifndef NFC_HAL_API_H
26#define NFC_HAL_API_H
27#include <hardware/nfc.h>
28#include "data_types.h"
29
30/****************************************************************************
31** NFC_HDR header definition for NFC messages
32*****************************************************************************/
33typedef struct
34{
35    UINT16          event;
36    UINT16          len;
37    UINT16          offset;
38    UINT16          layer_specific;
39} NFC_HDR;
40#define NFC_HDR_SIZE (sizeof (NFC_HDR))
41
42/*******************************************************************************
43** tHAL_STATUS Definitions
44*******************************************************************************/
45#define HAL_NFC_STATUS_OK               0
46#define HAL_NFC_STATUS_FAILED           1
47#define HAL_NFC_STATUS_ERR_TRANSPORT    2
48#define HAL_NFC_STATUS_ERR_CMD_TIMEOUT  3
49#define HAL_NFC_STATUS_REFUSED          4
50
51typedef UINT8 tHAL_NFC_STATUS;
52
53/*******************************************************************************
54** tHAL_HCI_NETWK_CMD Definitions
55*******************************************************************************/
56#define HAL_NFC_HCI_NO_UICC_HOST    0x00
57#define HAL_NFC_HCI_UICC0_HOST      0x01
58#define HAL_NFC_HCI_UICC1_HOST      0x02
59#define HAL_NFC_HCI_UICC2_HOST      0x04
60
61/*******************************************************************************
62** tHAL_NFC_CBACK Definitions
63*******************************************************************************/
64
65/* tHAL_NFC_CBACK events */
66#define HAL_NFC_OPEN_CPLT_EVT           0x00
67#define HAL_NFC_CLOSE_CPLT_EVT          0x01
68#define HAL_NFC_POST_INIT_CPLT_EVT      0x02
69#define HAL_NFC_PRE_DISCOVER_CPLT_EVT   0x03
70#define HAL_NFC_REQUEST_CONTROL_EVT     0x04
71#define HAL_NFC_RELEASE_CONTROL_EVT     0x05
72#define HAL_NFC_ERROR_EVT               0x06
73
74
75typedef void (tHAL_NFC_STATUS_CBACK) (tHAL_NFC_STATUS status);
76typedef void (tHAL_NFC_CBACK) (UINT8 event, tHAL_NFC_STATUS status);
77typedef void (tHAL_NFC_DATA_CBACK) (UINT16 data_len, UINT8   *p_data);
78
79/*******************************************************************************
80** tHAL_NFC_ENTRY HAL entry-point lookup table
81*******************************************************************************/
82
83typedef void (tHAL_API_INITIALIZE) (void);
84typedef void (tHAL_API_TERMINATE) (void);
85typedef void (tHAL_API_OPEN) (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback);
86typedef void (tHAL_API_CLOSE) (void);
87typedef void (tHAL_API_CORE_INITIALIZED) (UINT8 *p_core_init_rsp_params);
88typedef void (tHAL_API_WRITE) (UINT16 data_len, UINT8 *p_data);
89typedef BOOLEAN (tHAL_API_PREDISCOVER) (void);
90typedef void (tHAL_API_CONTROL_GRANTED) (void);
91typedef void (tHAL_API_POWER_CYCLE) (void);
92typedef UINT8 (tHAL_API_GET_MAX_NFCEE) (void);
93
94
95#define NFC_HAL_DM_PRE_SET_MEM_LEN  5
96typedef struct
97{
98    UINT32          addr;
99    UINT32          data;
100} tNFC_HAL_DM_PRE_SET_MEM;
101
102/* data members for NFC_HAL-HCI */
103typedef struct
104{
105    BOOLEAN nfc_hal_prm_nvm_required;       /* set nfc_hal_prm_nvm_required to TRUE, if the platform wants to abort PRM process without NVM */
106    UINT16  nfc_hal_nfcc_enable_timeout;    /* max time to wait for RESET NTF after setting REG_PU to high */
107    UINT16  nfc_hal_post_xtal_timeout;      /* max time to wait for RESET NTF after setting Xtal frequency */
108#if (defined(NFC_HAL_HCI_INCLUDED) && (NFC_HAL_HCI_INCLUDED == TRUE))
109    BOOLEAN nfc_hal_first_boot;             /* set nfc_hal_first_boot to TRUE, if platform enables NFC for the first time after bootup */
110    UINT8   nfc_hal_hci_uicc_support;       /* set nfc_hal_hci_uicc_support to Zero, if no UICC is supported otherwise set corresponding bit(s) for every supported UICC(s) */
111#endif
112} tNFC_HAL_CFG;
113
114typedef struct
115{
116    tHAL_API_INITIALIZE *initialize;
117    tHAL_API_TERMINATE *terminate;
118    tHAL_API_OPEN *open;
119    tHAL_API_CLOSE *close;
120    tHAL_API_CORE_INITIALIZED *core_initialized;
121    tHAL_API_WRITE *write;
122    tHAL_API_PREDISCOVER *prediscover;
123    tHAL_API_CONTROL_GRANTED *control_granted;
124    tHAL_API_POWER_CYCLE *power_cycle;
125    tHAL_API_GET_MAX_NFCEE *get_max_ee;
126
127
128} tHAL_NFC_ENTRY;
129
130
131/*******************************************************************************
132** HAL API Function Prototypes
133*******************************************************************************/
134#ifdef __cplusplus
135extern "C"
136{
137#endif
138
139/* Toolset-specific macro for exporting API funcitons */
140#if (defined(NFC_HAL_TARGET) && (NFC_HAL_TARGET == TRUE)) && (defined(_WINDLL))
141#define EXPORT_HAL_API  __declspec(dllexport)
142#else
143#define EXPORT_HAL_API
144#endif
145
146/*******************************************************************************
147**
148** Function         HAL_NfcInitialize
149**
150** Description      Called when HAL library is loaded.
151**
152**                  Initialize GKI and start the HCIT task
153**
154** Returns          void
155**
156*******************************************************************************/
157EXPORT_HAL_API void HAL_NfcInitialize(void);
158
159/*******************************************************************************
160**
161** Function         HAL_NfcTerminate
162**
163** Description      Called to terminate NFC HAL
164**
165** Returns          void
166**
167*******************************************************************************/
168EXPORT_HAL_API void HAL_NfcTerminate(void);
169
170/*******************************************************************************
171**
172** Function         HAL_NfcOpen
173**
174** Description      Open transport and intialize the NFCC, and
175**                  Register callback for HAL event notifications,
176**
177**                  HAL_OPEN_CPLT_EVT will notify when operation is complete.
178**
179** Returns          void
180**
181*******************************************************************************/
182EXPORT_HAL_API void HAL_NfcOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback);
183
184/*******************************************************************************
185**
186** Function         HAL_NfcClose
187**
188** Description      Prepare for shutdown. A HAL_CLOSE_CPLT_EVT will be
189**                  reported when complete.
190**
191** Returns          void
192**
193*******************************************************************************/
194EXPORT_HAL_API void HAL_NfcClose (void);
195
196/*******************************************************************************
197**
198** Function         HAL_NfcCoreInitialized
199**
200** Description      Called after the CORE_INIT_RSP is received from the NFCC.
201**                  At this time, the HAL can do any chip-specific configuration,
202**                  and when finished signal the libnfc-nci with event
203**                  HAL_POST_INIT_CPLT_EVT.
204**
205** Returns          void
206**
207*******************************************************************************/
208EXPORT_HAL_API void HAL_NfcCoreInitialized (UINT8 *p_core_init_rsp_params);
209
210/*******************************************************************************
211**
212** Function         HAL_NfcWrite
213**
214** Description      Send an NCI control message or data packet to the
215**                  transport. If an NCI command message exceeds the transport
216**                  size, HAL is responsible for fragmenting it, Data packets
217**                  must be of the correct size.
218**
219** Returns          void
220**
221*******************************************************************************/
222EXPORT_HAL_API void HAL_NfcWrite (UINT16 data_len, UINT8 *p_data);
223
224/*******************************************************************************
225**
226** Function         HAL_NfcPreDiscover
227**
228** Description      Perform any vendor-specific pre-discovery actions (if needed)
229**                  If any actions were performed TRUE will be returned, and
230**                  HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are
231**                  completed.
232**
233** Returns          TRUE if vendor-specific pre-discovery actions initialized
234**                  FALSE if no vendor-specific pre-discovery actions are needed.
235**
236*******************************************************************************/
237EXPORT_HAL_API BOOLEAN HAL_NfcPreDiscover (void);
238
239/*******************************************************************************
240**
241** Function         HAL_NfcControlGranted
242**
243** Description      Grant control to HAL control for sending NCI commands.
244**
245**                  Call in response to HAL_REQUEST_CONTROL_EVT.
246**
247**                  Must only be called when there are no NCI commands pending.
248**
249**                  HAL_RELEASE_CONTROL_EVT will notify when HAL no longer
250**                  needs control of NCI.
251**
252**
253** Returns          void
254**
255*******************************************************************************/
256EXPORT_HAL_API void HAL_NfcControlGranted (void);
257
258/*******************************************************************************
259**
260** Function         HAL_NfcPowerCycle
261**
262** Description      Restart NFCC by power cyle
263**
264**                  HAL_OPEN_CPLT_EVT will notify when operation is complete.
265**
266** Returns          void
267**
268*******************************************************************************/
269EXPORT_HAL_API void HAL_NfcPowerCycle (void);
270
271/*******************************************************************************
272**
273** Function         HAL_NfcGetMaxNfcee
274**
275** Description      Retrieve the maximum number of NFCEEs supported by NFCC
276**
277** Returns          the maximum number of NFCEEs supported by NFCC
278**
279*******************************************************************************/
280EXPORT_HAL_API UINT8 HAL_NfcGetMaxNfcee (void);
281
282
283#ifdef __cplusplus
284}
285#endif
286
287#endif /* NFC_HAL_API_H  */
288