• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2012-2013 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> /* Android must include HAL header */
28 #include "data_types.h"
29 
30 /****************************************************************************
31 ** NFC_HDR header definition for NFC messages
32 *****************************************************************************/
33 typedef 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 are defined in hardware/libhardware/include/hardware/nfc.h
44 ** #define HAL_NFC_STATUS_OK               0
45 ** #define HAL_NFC_STATUS_FAILED           1
46 ** #define HAL_NFC_STATUS_ERR_TRANSPORT    2
47 ** #define HAL_NFC_STATUS_ERR_CMD_TIMEOUT  3
48 ** #define HAL_NFC_STATUS_REFUSED          4
49 *******************************************************************************/
50 
51 typedef 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 
60 /*******************************************************************************
61 ** tHAL_NFC_CBACK Definitions
62 *******************************************************************************/
63 
64 /*******************************************************************************
65 ** tHAL_NFC_CBACK events are defined in hardware/libhardware/include/hardware/nfc.h
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 
75 
76 typedef void (tHAL_NFC_STATUS_CBACK) (tHAL_NFC_STATUS status);
77 typedef void (tHAL_NFC_CBACK) (UINT8 event, tHAL_NFC_STATUS status);
78 typedef void (tHAL_NFC_DATA_CBACK) (UINT16 data_len, UINT8   *p_data);
79 
80 /*******************************************************************************
81 ** tHAL_NFC_ENTRY HAL entry-point lookup table
82 *******************************************************************************/
83 
84 typedef void (tHAL_API_INITIALIZE) (void);
85 typedef void (tHAL_API_TERMINATE) (void);
86 typedef void (tHAL_API_OPEN) (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback);
87 typedef void (tHAL_API_CLOSE) (void);
88 typedef void (tHAL_API_CORE_INITIALIZED) (UINT8 *p_core_init_rsp_params);
89 typedef void (tHAL_API_WRITE) (UINT16 data_len, UINT8 *p_data);
90 typedef BOOLEAN (tHAL_API_PREDISCOVER) (void);
91 typedef void (tHAL_API_CONTROL_GRANTED) (void);
92 typedef void (tHAL_API_POWER_CYCLE) (void);
93 
94 
95 /* data members for NFC_HAL-HCI */
96 typedef struct
97 {
98     BOOLEAN nfc_hal_prm_nvm_required;       /* set nfc_hal_prm_nvm_required to TRUE, if the platform wants to abort PRM process without NVM */
99     UINT16  nfc_hal_nfcc_enable_timeout;    /* max time to wait for RESET NTF after setting REG_PU to high */
100     UINT16  nfc_hal_post_xtal_timeout;      /* max time to wait for RESET NTF after setting Xtal frequency */
101     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) */
102 } tNFC_HAL_CFG;
103 
104 typedef struct
105 {
106     tHAL_API_INITIALIZE *initialize;
107     tHAL_API_TERMINATE *terminate;
108     tHAL_API_OPEN *open;
109     tHAL_API_CLOSE *close;
110     tHAL_API_CORE_INITIALIZED *core_initialized;
111     tHAL_API_WRITE *write;
112     tHAL_API_PREDISCOVER *prediscover;
113     tHAL_API_CONTROL_GRANTED *control_granted;
114     tHAL_API_POWER_CYCLE *power_cycle;
115 
116 
117 } tHAL_NFC_ENTRY;
118 
119 
120 /*******************************************************************************
121 ** HAL API Function Prototypes
122 *******************************************************************************/
123 #ifdef __cplusplus
124 extern "C"
125 {
126 #endif
127 
128 /* Toolset-specific macro for exporting API funcitons */
129 #if (defined(NFC_HAL_TARGET) && (NFC_HAL_TARGET == TRUE)) && (defined(_WINDLL))
130 #define EXPORT_HAL_API  __declspec(dllexport)
131 #else
132 #define EXPORT_HAL_API
133 #endif
134 
135 /*******************************************************************************
136 **
137 ** Function         HAL_NfcInitialize
138 **
139 ** Description      Called when HAL library is loaded.
140 **
141 **                  Initialize GKI and start the HCIT task
142 **
143 ** Returns          void
144 **
145 *******************************************************************************/
146 EXPORT_HAL_API void HAL_NfcInitialize(void);
147 
148 /*******************************************************************************
149 **
150 ** Function         HAL_NfcTerminate
151 **
152 ** Description      Called to terminate NFC HAL
153 **
154 ** Returns          void
155 **
156 *******************************************************************************/
157 EXPORT_HAL_API void HAL_NfcTerminate(void);
158 
159 /*******************************************************************************
160 **
161 ** Function         HAL_NfcOpen
162 **
163 ** Description      Open transport and intialize the NFCC, and
164 **                  Register callback for HAL event notifications,
165 **
166 **                  HAL_OPEN_CPLT_EVT will notify when operation is complete.
167 **
168 ** Returns          void
169 **
170 *******************************************************************************/
171 EXPORT_HAL_API void HAL_NfcOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback);
172 
173 /*******************************************************************************
174 **
175 ** Function         HAL_NfcClose
176 **
177 ** Description      Prepare for shutdown. A HAL_CLOSE_CPLT_EVT will be
178 **                  reported when complete.
179 **
180 ** Returns          void
181 **
182 *******************************************************************************/
183 EXPORT_HAL_API void HAL_NfcClose (void);
184 
185 /*******************************************************************************
186 **
187 ** Function         HAL_NfcCoreInitialized
188 **
189 ** Description      Called after the CORE_INIT_RSP is received from the NFCC.
190 **                  At this time, the HAL can do any chip-specific configuration,
191 **                  and when finished signal the libnfc-nci with event
192 **                  HAL_POST_INIT_CPLT_EVT.
193 **
194 ** Returns          void
195 **
196 *******************************************************************************/
197 EXPORT_HAL_API void HAL_NfcCoreInitialized (UINT8 *p_core_init_rsp_params);
198 
199 /*******************************************************************************
200 **
201 ** Function         HAL_NfcWrite
202 **
203 ** Description      Send an NCI control message or data packet to the
204 **                  transport. If an NCI command message exceeds the transport
205 **                  size, HAL is responsible for fragmenting it, Data packets
206 **                  must be of the correct size.
207 **
208 ** Returns          void
209 **
210 *******************************************************************************/
211 EXPORT_HAL_API void HAL_NfcWrite (UINT16 data_len, UINT8 *p_data);
212 
213 /*******************************************************************************
214 **
215 ** Function         HAL_NfcPreDiscover
216 **
217 ** Description      Perform any vendor-specific pre-discovery actions (if needed)
218 **                  If any actions were performed TRUE will be returned, and
219 **                  HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are
220 **                  completed.
221 **
222 ** Returns          TRUE if vendor-specific pre-discovery actions initialized
223 **                  FALSE if no vendor-specific pre-discovery actions are needed.
224 **
225 *******************************************************************************/
226 EXPORT_HAL_API BOOLEAN HAL_NfcPreDiscover (void);
227 
228 /*******************************************************************************
229 **
230 ** Function         HAL_NfcControlGranted
231 **
232 ** Description      Grant control to HAL control for sending NCI commands.
233 **
234 **                  Call in response to HAL_REQUEST_CONTROL_EVT.
235 **
236 **                  Must only be called when there are no NCI commands pending.
237 **
238 **                  HAL_RELEASE_CONTROL_EVT will notify when HAL no longer
239 **                  needs control of NCI.
240 **
241 **
242 ** Returns          void
243 **
244 *******************************************************************************/
245 EXPORT_HAL_API void HAL_NfcControlGranted (void);
246 
247 /*******************************************************************************
248 **
249 ** Function         HAL_NfcPowerCycle
250 **
251 ** Description      Restart NFCC by power cyle
252 **
253 **                  HAL_OPEN_CPLT_EVT will notify when operation is complete.
254 **
255 ** Returns          void
256 **
257 *******************************************************************************/
258 EXPORT_HAL_API void HAL_NfcPowerCycle (void);
259 
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 
265 #endif /* NFC_HAL_API_H  */
266