1 /****************************************************************************** 2 * 3 * Copyright (C) 2009-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 * this file contains the NCI transport internal definitions and functions. 22 * 23 ******************************************************************************/ 24 25 #ifndef NFC_HAL_INT_H 26 #define NFC_HAL_INT_H 27 28 #include "gki.h" 29 #include "nci_defs.h" 30 #include "nfc_brcm_defs.h" 31 #include "nfc_hal_api.h" 32 #include "nfc_hal_int_api.h" 33 #include "nfc_hal_target.h" 34 35 using android::base::StringPrintf; 36 37 /* NFC HAL Task Timer events */ 38 #ifndef NFC_HAL_QUICK_TIMER_EVT_MASK 39 #define NFC_HAL_QUICK_TIMER_EVT_MASK (TIMER_0_EVT_MASK) 40 #endif 41 42 #ifndef NFC_HAL_QUICK_TIMER_ID 43 #define NFC_HAL_QUICK_TIMER_ID (TIMER_0) 44 #endif 45 46 typedef uint8_t tNFC_HAL_WAIT_RSP; 47 48 #if (NFC_HAL_HCI_INCLUDED == TRUE) 49 50 #endif 51 52 /* NFC HAL transport configuration */ 53 typedef struct { 54 bool shared_transport; /* TRUE if using shared HCI/NCI transport */ 55 uint8_t userial_baud; 56 uint8_t userial_fc; 57 } tNFC_HAL_TRANS_CFG; 58 59 #ifdef TESTER 60 /* For Insight, ncit_cfg is runtime-configurable */ 61 #define NFC_HAL_TRANS_CFG_QUALIFIER 62 #else 63 /* For all other platforms, ncit_cfg is constant */ 64 #define NFC_HAL_TRANS_CFG_QUALIFIER const 65 #endif 66 extern NFC_HAL_TRANS_CFG_QUALIFIER tNFC_HAL_TRANS_CFG nfc_hal_trans_cfg; 67 68 /**************************************************************************** 69 ** Internal constants and definitions 70 ****************************************************************************/ 71 72 typedef uint8_t tNFC_HAL_NCI_RAS; 73 74 typedef uint8_t tNFC_HAL_POWER_MODE; 75 76 #define NFC_HAL_SAVED_HDR_SIZE (2) 77 #define NFC_HAL_SAVED_CMD_SIZE (2) 78 79 #ifndef NFC_HAL_DEBUG 80 #define NFC_HAL_DEBUG TRUE 81 #endif 82 83 #if (NFC_HAL_DEBUG == TRUE) 84 extern const char* const nfc_hal_init_state_str[]; 85 #define NFC_HAL_SET_INIT_STATE(state) \ 86 LOG(VERBOSE) << StringPrintf("init state: %d->%d(%s)", \ 87 nfc_hal_cb.dev_cb.initializing_state, state, \ 88 nfc_hal_init_state_str[state]); \ 89 nfc_hal_cb.dev_cb.initializing_state = state; 90 #else 91 #define NFC_HAL_SET_INIT_STATE(state) \ 92 nfc_hal_cb.dev_cb.initializing_state = state; 93 #endif 94 95 typedef uint8_t tNFC_HAL_INIT_STATE; 96 97 typedef uint8_t tNFC_HAL_DM_CONFIG; 98 99 /* callback function prototype */ 100 typedef struct { 101 uint16_t opcode; 102 uint16_t param_len; 103 uint8_t* p_param_buf; 104 } tNFC_HAL_BTVSC_CPLT; 105 106 #if (NFC_HAL_HCI_INCLUDED == TRUE) 107 108 /* data type for NFC_HAL_HCI_RSP_NV_READ_EVT */ 109 typedef struct { 110 NFC_HDR hdr; 111 uint8_t block; 112 uint16_t size; 113 tHAL_NFC_STATUS status; 114 } tNFC_HAL_HCI_RSP_NV_READ_EVT; 115 116 /* data type for NFC_HAL_HCI_RSP_NV_WRITE_EVT */ 117 typedef struct { 118 NFC_HDR hdr; 119 tHAL_NFC_STATUS status; 120 } tNFC_HAL_HCI_RSP_NV_WRITE_EVT; 121 122 /* union of all event data types */ 123 typedef union { 124 NFC_HDR hdr; 125 /* Internal events */ 126 tNFC_HAL_HCI_RSP_NV_READ_EVT nv_read; 127 tNFC_HAL_HCI_RSP_NV_WRITE_EVT nv_write; 128 } tNFC_HAL_HCI_EVENT_DATA; 129 130 #endif 131 /***************************************************************************** 132 ** Control block for NFC HAL 133 *****************************************************************************/ 134 135 /* Information about current patch in NVM */ 136 typedef struct { 137 uint16_t project_id; /* Current project_id of patch in nvm */ 138 uint16_t ver_major; /* Current major version of patch in nvm */ 139 uint16_t ver_minor; /* Current minor version of patch in nvm */ 140 uint16_t fpm_size; /* Current size of FPM patch in nvm */ 141 uint16_t lpm_size; /* Current size of LPM patch in nvm */ 142 uint8_t flags; /* See NFC_HAL_NVM_FLAGS_* flag definitions */ 143 uint8_t nvm_type; /* Current NVM Type - UICC/EEPROM */ 144 uint8_t chip_ver[NFC_HAL_PRM_MAX_CHIP_VER_LEN]; /* patch chip version */ 145 } tNFC_HAL_NVM; 146 147 /* Patch for I2C fix */ 148 typedef struct { 149 uint8_t* p_patch; /* patch for i2c fix */ 150 uint32_t prei2c_delay; /* the dealy after preI2C patch */ 151 uint16_t len; /* i2c patch length */ 152 } tNFC_HAL_PRM_I2C_FIX_CB; 153 154 /* Control block for NCI transport */ 155 typedef struct { 156 uint8_t nci_ctrl_size; /* Max size for NCI messages */ 157 uint8_t rcv_state; /* current rx state */ 158 uint16_t rcv_len; /* bytes remaining to be received in current rx state */ 159 NFC_HDR* p_rcv_msg; /* buffer to receive NCI message */ 160 NFC_HDR* p_frag_msg; /* fragmented NCI message; waiting for last fragment */ 161 NFC_HDR* 162 p_pend_cmd; /* pending NCI message; waiting for NFCC state to be free */ 163 tNFC_HAL_NCI_RAS nci_ras; /* nci reassembly error status */ 164 TIMER_LIST_ENT 165 nci_wait_rsp_timer; /* Timer for waiting for nci command response */ 166 tNFC_HAL_WAIT_RSP nci_wait_rsp; /* nci wait response flag */ 167 uint8_t 168 last_hdr[NFC_HAL_SAVED_HDR_SIZE]; /* part of last NCI command header */ 169 uint8_t 170 last_cmd[NFC_HAL_SAVED_CMD_SIZE]; /* part of last NCI command payload */ 171 void* p_vsc_cback; /* the callback function for last VSC command */ 172 } tNFC_HAL_NCIT_CB; 173 174 /* Control block for device initialization */ 175 typedef struct { 176 tNFC_HAL_INIT_STATE initializing_state; /* state of initializing NFCC */ 177 178 uint32_t brcm_hw_id; /* BRCM NFCC HW ID */ 179 tNFC_HAL_DM_CONFIG next_dm_config; /* next config in post initialization */ 180 uint8_t next_startup_vsc; /* next start-up VSC offset in post init */ 181 182 tNFC_HAL_POWER_MODE power_mode; /* NFCC power mode */ 183 uint8_t snooze_mode; /* current snooze mode */ 184 uint8_t new_snooze_mode; /* next snooze mode after receiving cmpl */ 185 uint8_t nfc_wake_active_mode; /* NFC_HAL_LP_ACTIVE_LOW/HIGH */ 186 TIMER_LIST_ENT lp_timer; /* timer for low power mode */ 187 188 tHAL_NFC_STATUS_CBACK* 189 p_prop_cback; /* callback to notify complete of proprietary update */ 190 } tNFC_HAL_DEV_CB; 191 192 #if (NFC_HAL_HCI_INCLUDED == TRUE) 193 194 /* data members for NFC_HAL-HCI */ 195 typedef struct { 196 TIMER_LIST_ENT 197 hci_timer; /* Timer to avoid indefinitely waiting for response */ 198 uint8_t* 199 p_hci_netwk_info_buf; /* Buffer for reading HCI Network information */ 200 uint8_t* p_hci_netwk_dh_info_buf; /* Buffer for reading HCI Network DH 201 information */ 202 uint8_t hci_netwk_config_block; /* Rsp awaiting for hci network configuration 203 block */ 204 bool b_wait_hcp_conn_create_rsp; /* Waiting for hcp connection create response 205 */ 206 bool clear_all_pipes_to_uicc1; /* UICC1 was restarted for patch download */ 207 bool update_session_id; /* Next response from NFCC is to Get Session id cmd */ 208 bool hci_fw_workaround; /* HAL HCI Workaround need */ 209 bool hci_fw_validate_netwk_cmd; /* Flag to indicate if hci network ntf to 210 validate */ 211 uint8_t hcp_conn_id; /* NCI Connection id for HCP */ 212 uint8_t dh_session_id[1]; /* Byte 0 of DH Session ID */ 213 } tNFC_HAL_HCI_CB; 214 215 #endif 216 217 typedef uint8_t tNFC_HAL_FLAGS; 218 219 typedef struct { 220 tHAL_NFC_CBACK* p_stack_cback; /* Callback for HAL event notification */ 221 tHAL_NFC_DATA_CBACK* p_data_cback; /* Callback for data event notification */ 222 223 TIMER_LIST_Q quick_timer_queue; /* timer list queue */ 224 TIMER_LIST_ENT timer; /* timer for NCI transport task */ 225 226 tNFC_HAL_NCIT_CB ncit_cb; /* NCI transport */ 227 tNFC_HAL_DEV_CB dev_cb; /* device initialization */ 228 tNFC_HAL_NVM nvm_cb; /* Information about current patch in NVM */ 229 230 /* Patchram control block */ 231 tNFC_HAL_PRM_CB prm; 232 tNFC_HAL_PRM_I2C_FIX_CB prm_i2c; 233 234 #if (NFC_HAL_HCI_INCLUDED == TRUE) 235 /* data members for NFC_HAL-HCI */ 236 tNFC_HAL_HCI_CB hci_cb; 237 #endif 238 239 uint8_t pre_discover_done; /* TRUE, when the prediscover config is complete */ 240 tNFC_HAL_FLAGS hal_flags; 241 uint8_t pre_set_mem_idx; 242 243 uint8_t max_rf_credits; /* NFC Max RF data credits */ 244 uint8_t max_ee; /* NFC Max number of NFCEE supported by NFCC */ 245 } tNFC_HAL_CB; 246 247 /* Global NCI data */ 248 extern tNFC_HAL_CB nfc_hal_cb; 249 250 extern uint8_t* p_nfc_hal_pre_discover_cfg; 251 252 /**************************************************************************** 253 ** Internal nfc functions 254 ****************************************************************************/ 255 256 #if (NFC_HAL_HCI_INCLUDED == TRUE) 257 /* nfc_hal_hci.c */ 258 void nfc_hal_hci_enable(void); 259 void nfc_hal_hci_evt_hdlr(tNFC_HAL_HCI_EVENT_DATA* p_evt_data); 260 261 void nfc_hal_hci_handle_build_info(uint8_t chipverlen, uint8_t* p_chipverstr); 262 #else 263 #define nfc_hal_hci_enable() NFC_HAL_SET_INIT_STATE(NFC_HAL_INIT_STATE_IDLE); 264 #define nfc_hal_hci_handle_build_info(p, a) 265 #define nfc_hal_hci_evt_hdlr(p) ; 266 #endif 267 268 #endif /* NFC_HAL_INT_H */ 269