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 typedef UINT8 (tHAL_API_GET_MAX_NFCEE) (void); 94 95 96 /* data members for NFC_HAL-HCI */ 97 typedef struct 98 { 99 BOOLEAN nfc_hal_prm_nvm_required; /* set nfc_hal_prm_nvm_required to TRUE, if the platform wants to abort PRM process without NVM */ 100 UINT16 nfc_hal_nfcc_enable_timeout; /* max time to wait for RESET NTF after setting REG_PU to high */ 101 UINT16 nfc_hal_post_xtal_timeout; /* max time to wait for RESET NTF after setting Xtal frequency */ 102 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) */ 103 } tNFC_HAL_CFG; 104 105 typedef struct 106 { 107 tHAL_API_INITIALIZE *initialize; 108 tHAL_API_TERMINATE *terminate; 109 tHAL_API_OPEN *open; 110 tHAL_API_CLOSE *close; 111 tHAL_API_CORE_INITIALIZED *core_initialized; 112 tHAL_API_WRITE *write; 113 tHAL_API_PREDISCOVER *prediscover; 114 tHAL_API_CONTROL_GRANTED *control_granted; 115 tHAL_API_POWER_CYCLE *power_cycle; 116 tHAL_API_GET_MAX_NFCEE *get_max_ee; 117 118 119 } tHAL_NFC_ENTRY; 120 121 122 /******************************************************************************* 123 ** HAL API Function Prototypes 124 *******************************************************************************/ 125 #ifdef __cplusplus 126 extern "C" 127 { 128 #endif 129 130 /* Toolset-specific macro for exporting API funcitons */ 131 #if (defined(NFC_HAL_TARGET) && (NFC_HAL_TARGET == TRUE)) && (defined(_WINDLL)) 132 #define EXPORT_HAL_API __declspec(dllexport) 133 #else 134 #define EXPORT_HAL_API 135 #endif 136 137 /******************************************************************************* 138 ** 139 ** Function HAL_NfcInitialize 140 ** 141 ** Description Called when HAL library is loaded. 142 ** 143 ** Initialize GKI and start the HCIT task 144 ** 145 ** Returns void 146 ** 147 *******************************************************************************/ 148 EXPORT_HAL_API void HAL_NfcInitialize(void); 149 150 /******************************************************************************* 151 ** 152 ** Function HAL_NfcTerminate 153 ** 154 ** Description Called to terminate NFC HAL 155 ** 156 ** Returns void 157 ** 158 *******************************************************************************/ 159 EXPORT_HAL_API void HAL_NfcTerminate(void); 160 161 /******************************************************************************* 162 ** 163 ** Function HAL_NfcOpen 164 ** 165 ** Description Open transport and intialize the NFCC, and 166 ** Register callback for HAL event notifications, 167 ** 168 ** HAL_OPEN_CPLT_EVT will notify when operation is complete. 169 ** 170 ** Returns void 171 ** 172 *******************************************************************************/ 173 EXPORT_HAL_API void HAL_NfcOpen (tHAL_NFC_CBACK *p_hal_cback, tHAL_NFC_DATA_CBACK *p_data_cback); 174 175 /******************************************************************************* 176 ** 177 ** Function HAL_NfcClose 178 ** 179 ** Description Prepare for shutdown. A HAL_CLOSE_CPLT_EVT will be 180 ** reported when complete. 181 ** 182 ** Returns void 183 ** 184 *******************************************************************************/ 185 EXPORT_HAL_API void HAL_NfcClose (void); 186 187 /******************************************************************************* 188 ** 189 ** Function HAL_NfcCoreInitialized 190 ** 191 ** Description Called after the CORE_INIT_RSP is received from the NFCC. 192 ** At this time, the HAL can do any chip-specific configuration, 193 ** and when finished signal the libnfc-nci with event 194 ** HAL_POST_INIT_CPLT_EVT. 195 ** 196 ** Returns void 197 ** 198 *******************************************************************************/ 199 EXPORT_HAL_API void HAL_NfcCoreInitialized (UINT8 *p_core_init_rsp_params); 200 201 /******************************************************************************* 202 ** 203 ** Function HAL_NfcWrite 204 ** 205 ** Description Send an NCI control message or data packet to the 206 ** transport. If an NCI command message exceeds the transport 207 ** size, HAL is responsible for fragmenting it, Data packets 208 ** must be of the correct size. 209 ** 210 ** Returns void 211 ** 212 *******************************************************************************/ 213 EXPORT_HAL_API void HAL_NfcWrite (UINT16 data_len, UINT8 *p_data); 214 215 /******************************************************************************* 216 ** 217 ** Function HAL_NfcPreDiscover 218 ** 219 ** Description Perform any vendor-specific pre-discovery actions (if needed) 220 ** If any actions were performed TRUE will be returned, and 221 ** HAL_PRE_DISCOVER_CPLT_EVT will notify when actions are 222 ** completed. 223 ** 224 ** Returns TRUE if vendor-specific pre-discovery actions initialized 225 ** FALSE if no vendor-specific pre-discovery actions are needed. 226 ** 227 *******************************************************************************/ 228 EXPORT_HAL_API BOOLEAN HAL_NfcPreDiscover (void); 229 230 /******************************************************************************* 231 ** 232 ** Function HAL_NfcControlGranted 233 ** 234 ** Description Grant control to HAL control for sending NCI commands. 235 ** 236 ** Call in response to HAL_REQUEST_CONTROL_EVT. 237 ** 238 ** Must only be called when there are no NCI commands pending. 239 ** 240 ** HAL_RELEASE_CONTROL_EVT will notify when HAL no longer 241 ** needs control of NCI. 242 ** 243 ** 244 ** Returns void 245 ** 246 *******************************************************************************/ 247 EXPORT_HAL_API void HAL_NfcControlGranted (void); 248 249 /******************************************************************************* 250 ** 251 ** Function HAL_NfcPowerCycle 252 ** 253 ** Description Restart NFCC by power cyle 254 ** 255 ** HAL_OPEN_CPLT_EVT will notify when operation is complete. 256 ** 257 ** Returns void 258 ** 259 *******************************************************************************/ 260 EXPORT_HAL_API void HAL_NfcPowerCycle (void); 261 262 /******************************************************************************* 263 ** 264 ** Function HAL_NfcGetMaxNfcee 265 ** 266 ** Description Retrieve the maximum number of NFCEEs supported by NFCC 267 ** 268 ** Returns the maximum number of NFCEEs supported by NFCC 269 ** 270 *******************************************************************************/ 271 EXPORT_HAL_API UINT8 HAL_NfcGetMaxNfcee (void); 272 273 274 #ifdef __cplusplus 275 } 276 #endif 277 278 #endif /* NFC_HAL_API_H */ 279