nfc_int.h revision 512ee63c7cc8feb016863e507a5d33cd0f4242bf
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 * 22 * this file contains the main NFC Upper Layer internal definitions and 23 * functions. 24 * 25 ******************************************************************************/ 26 27#ifndef NFC_INT_H_ 28#define NFC_INT_H_ 29 30#include "nfc_target.h" 31#include "gki.h" 32#include "nci_defs.h" 33#include "nfc_api.h" 34 35#ifdef __cplusplus 36extern "C" { 37#endif 38 39/**************************************************************************** 40** Internal NFC constants and definitions 41****************************************************************************/ 42 43/**************************************************************************** 44** NFC_TASK definitions 45****************************************************************************/ 46 47/* NFC_TASK event masks */ 48#define NFC_TASK_EVT_TRANSPORT_READY EVENT_MASK (APPL_EVT_0) 49 50/* NFC Timer events */ 51#define NFC_TTYPE_NCI_WAIT_RSP 0 52#define NFC_TTYPE_WAIT_2_DEACTIVATE 1 53 54#define NFC_TTYPE_LLCP_LINK_MANAGER 100 55#define NFC_TTYPE_LLCP_LINK_INACT 101 56#define NFC_TTYPE_LLCP_DATA_LINK 102 57#define NFC_TTYPE_LLCP_DELAY_FIRST_PDU 103 58#define NFC_TTYPE_RW_T1T_RESPONSE 104 59#define NFC_TTYPE_RW_T2T_RESPONSE 105 60#define NFC_TTYPE_RW_T3T_RESPONSE 106 61#define NFC_TTYPE_RW_T4T_RESPONSE 107 62#define NFC_TTYPE_RW_I93_RESPONSE 108 63#define NFC_TTYPE_CE_T4T_UPDATE 109 64#define NFC_TTYPE_P2P_PRIO_RESPONSE 110 /* added for p2p prio logic timer */ 65#define NFC_TTYPE_P2P_PRIO_LOGIC_CLEANUP 111 /* added for p2p prio logic clenaup */ 66#define NFC_TTYPE_VS_BASE 200 67 68 69/* NFC Task event messages */ 70 71enum 72{ 73 NFC_STATE_NONE, /* not start up yet */ 74 NFC_STATE_W4_HAL_OPEN, /* waiting for HAL_NFC_OPEN_CPLT_EVT */ 75 NFC_STATE_CORE_INIT, /* sending CORE_RESET and CORE_INIT */ 76 NFC_STATE_W4_POST_INIT_CPLT, /* waiting for HAL_NFC_POST_INIT_CPLT_EVT */ 77 NFC_STATE_IDLE, /* normal operation (discovery state) */ 78 NFC_STATE_OPEN, /* NFC link is activated */ 79 NFC_STATE_CLOSING, /* de-activating */ 80 NFC_STATE_W4_HAL_CLOSE, /* waiting for HAL_NFC_POST_INIT_CPLT_EVT */ 81 NFC_STATE_NFCC_POWER_OFF_SLEEP /* NFCC is power-off sleep mode */ 82}; 83typedef uint8_t tNFC_STATE; 84 85/* DM P2P Priority event type */ 86enum 87{ 88 NFA_DM_P2P_PRIO_RSP = 0x01, /* P2P priority event from RSP */ 89 NFA_DM_P2P_PRIO_NTF /* P2P priority event from NTF */ 90}; 91 92/* NFC control block flags */ 93#define NFC_FL_DEACTIVATING 0x0001 /* NFC_Deactivate () is called and the NCI cmd is not sent */ 94#define NFC_FL_RESTARTING 0x0002 /* restarting NFCC after PowerOffSleep */ 95#define NFC_FL_POWER_OFF_SLEEP 0x0004 /* enterning power off sleep mode */ 96#define NFC_FL_POWER_CYCLE_NFCC 0x0008 /* Power cycle NFCC */ 97#define NFC_FL_CONTROL_REQUESTED 0x0010 /* HAL requested control on NCI command window */ 98#define NFC_FL_CONTROL_GRANTED 0x0020 /* NCI command window is on the HAL side */ 99#define NFC_FL_DISCOVER_PENDING 0x0040 /* NCI command window is on the HAL side */ 100#define NFC_FL_HAL_REQUESTED 0x0080 /* NFC_FL_CONTROL_REQUESTED on HAL request */ 101 102#define NFC_PEND_CONN_ID 0xFE 103#define NFC_CONN_ID_INT_MASK 0xF0 104#define NFC_CONN_ID_ID_MASK NCI_CID_MASK 105#define NFC_CONN_NO_FC 0xFF /* set num_buff to this for no flow control */ 106#define NFC_NCI_CONN_NO_FC 0xFF 107 108#if (NFC_RW_ONLY == FALSE) 109/* only allow the entries that the NFCC can support */ 110#define NFC_CHECK_MAX_CONN() {if (max > nfc_cb.max_conn) max = nfc_cb.max_conn;} 111#else 112#define NFC_CHECK_MAX_CONN() 113#endif 114 115typedef struct 116{ 117 tNFC_CONN_CBACK *p_cback; /* the callback function to receive the data */ 118 BUFFER_Q tx_q; /* transmit queue */ 119 BUFFER_Q rx_q; /* receive queue */ 120 uint8_t id; /* NFCEE ID or RF Discovery ID or NFC_TEST_ID */ 121 uint8_t act_protocol; /* the active protocol on this logical connection */ 122 uint8_t conn_id; /* the connection id assigned by NFCC for this conn */ 123 uint8_t buff_size; /* the max buffer size for this connection. . */ 124 uint8_t num_buff; /* num of buffers left to send on this connection */ 125 uint8_t init_credits; /* initial num of buffer credits */ 126} tNFC_CONN_CB; 127 128/* This data type is for NFC task to send a NCI VS command to NCIT task */ 129typedef struct 130{ 131 BT_HDR bt_hdr; /* the NCI command */ 132 tNFC_VS_CBACK *p_cback; /* the callback function to receive RSP */ 133} tNFC_NCI_VS_MSG; 134 135/* This data type is for HAL event */ 136typedef struct 137{ 138 BT_HDR hdr; 139 uint8_t hal_evt; /* HAL event code */ 140 uint8_t status; /* tHAL_NFC_STATUS */ 141} tNFC_HAL_EVT_MSG; 142 143#define NFC_RECEIVE_MSGS_OFFSET (10) /* callback function pointer(8; use 8 to be safe + NFC_SAVED_CMD_SIZE(2) */ 144 145/* NFCC power state change pending callback */ 146typedef void (tNFC_PWR_ST_CBACK) (void); 147#define NFC_SAVED_HDR_SIZE (2) 148/* data Reassembly error (in BT_HDR.layer_specific) */ 149#define NFC_RAS_TOO_BIG 0x08 150#define NFC_RAS_FRAGMENTED 0x01 151 152/* NCI command buffer contains a VSC (in BT_HDR.layer_specific) */ 153#define NFC_WAIT_RSP_VSC 0x01 154 155/* NFC control blocks */ 156typedef struct 157{ 158 uint16_t flags; /* NFC control block flags - NFC_FL_* */ 159 tNFC_CONN_CB conn_cb[NCI_MAX_CONN_CBS]; 160 uint8_t conn_id[NFC_MAX_CONN_ID+1]; /* index: conn_id; conn_id[]: index(1 based) to conn_cb[] */ 161 tNFC_DISCOVER_CBACK *p_discv_cback; 162 tNFC_RESPONSE_CBACK *p_resp_cback; 163 tNFC_TEST_CBACK *p_test_cback; 164 tNFC_VS_CBACK *p_vs_cb[NFC_NUM_VS_CBACKS];/* Register for vendor specific events */ 165 166#if (NFC_RW_ONLY == FALSE) 167 /* NFCC information at init rsp */ 168 uint32_t nci_features; /* the NCI features supported by NFCC */ 169 uint16_t max_ce_table; /* the max routing table size */ 170 uint8_t max_conn; /* the num of connections supported by NFCC */ 171#endif 172 uint8_t nci_ctrl_size; /* Max Control Packet Payload Size */ 173 174 const tNCI_DISCOVER_MAPS *p_disc_maps; /* NCI RF Discovery interface mapping */ 175 uint8_t vs_interface[NFC_NFCC_MAX_NUM_VS_INTERFACE]; /* the NCI VS interfaces of NFCC */ 176 uint16_t nci_interfaces; /* the NCI interfaces of NFCC */ 177 uint8_t num_disc_maps; /* number of RF Discovery interface mappings */ 178 void *p_disc_pending; /* the parameters associated with pending NFC_DiscoveryStart */ 179 180 /* NFC_TASK timer management */ 181 TIMER_LIST_Q timer_queue; /* 1-sec timer event queue */ 182 TIMER_LIST_Q quick_timer_queue; 183 184 TIMER_LIST_ENT deactivate_timer; /* Timer to wait for deactivation */ 185 186 tNFC_STATE nfc_state; 187 bool reassembly; /* Reassemble fragmented data pkt */ 188 uint8_t trace_level; 189 uint8_t last_hdr[NFC_SAVED_HDR_SIZE];/* part of last NCI command header */ 190 uint8_t last_cmd[NFC_SAVED_CMD_SIZE];/* part of last NCI command payload */ 191 void *p_vsc_cback; /* the callback function for last VSC command */ 192 BUFFER_Q nci_cmd_xmit_q; /* NCI command queue */ 193 TIMER_LIST_ENT nci_wait_rsp_timer; /* Timer for waiting for nci command response */ 194 uint16_t nci_wait_rsp_tout; /* NCI command timeout (in ms) */ 195 uint8_t nci_wait_rsp; /* layer_specific for last NCI message */ 196 197 uint8_t nci_cmd_window; /* Number of commands the controller can accecpt without waiting for response */ 198 199 BT_HDR *p_nci_init_rsp; /* holding INIT_RSP until receiving HAL_NFC_POST_INIT_CPLT_EVT */ 200 tHAL_NFC_ENTRY *p_hal; 201 202} tNFC_CB; 203 204 205/***************************************************************************** 206** EXTERNAL FUNCTION DECLARATIONS 207*****************************************************************************/ 208 209/* Global NFC data */ 210NFC_API extern tNFC_CB nfc_cb; 211 212/**************************************************************************** 213** Internal nfc functions 214****************************************************************************/ 215 216NFC_API extern void nfc_init(void); 217 218/* from nfc_utils.c */ 219NFC_API extern tNFC_CONN_CB * nfc_alloc_conn_cb ( tNFC_CONN_CBACK *p_cback); 220NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_conn_id (uint8_t conn_id); 221NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_handle (uint8_t target_handle); 222NFC_API extern void nfc_set_conn_id (tNFC_CONN_CB * p_cb, uint8_t conn_id); 223NFC_API extern void nfc_free_conn_cb (tNFC_CONN_CB *p_cb); 224NFC_API extern void nfc_reset_all_conn_cbs (void); 225NFC_API extern void nfc_data_event (tNFC_CONN_CB * p_cb); 226 227void nfc_ncif_send (BT_HDR *p_buf, bool is_cmd); 228extern uint8_t nfc_ncif_send_data (tNFC_CONN_CB *p_cb, BT_HDR *p_data); 229NFC_API extern void nfc_ncif_cmd_timeout (void); 230NFC_API extern void nfc_wait_2_deactivate_timeout (void); 231 232NFC_API extern bool nfc_ncif_process_event (BT_HDR *p_msg); 233NFC_API extern void nfc_ncif_check_cmd_queue (BT_HDR *p_buf); 234NFC_API extern void nfc_ncif_send_cmd (BT_HDR *p_buf); 235NFC_API extern void nfc_ncif_proc_discover_ntf (uint8_t *p, uint16_t plen); 236NFC_API extern void nfc_ncif_rf_management_status (tNFC_DISCOVER_EVT event, uint8_t status); 237NFC_API extern void nfc_ncif_set_config_status (uint8_t *p, uint8_t len); 238NFC_API extern void nfc_ncif_event_status (tNFC_RESPONSE_EVT event, uint8_t status); 239NFC_API extern void nfc_ncif_error_status (uint8_t conn_id, uint8_t status); 240NFC_API extern void nfc_ncif_proc_credits(uint8_t *p, uint16_t plen); 241NFC_API extern void nfc_ncif_proc_activate (uint8_t *p, uint8_t len); 242NFC_API extern void nfc_ncif_proc_deactivate (uint8_t status, uint8_t deact_type, bool is_ntf); 243#if ((NFC_NFCEE_INCLUDED == TRUE) && (NFC_RW_ONLY == FALSE)) 244NFC_API extern void nfc_ncif_proc_ee_action (uint8_t *p, uint16_t plen); 245NFC_API extern void nfc_ncif_proc_ee_discover_req (uint8_t *p, uint16_t plen); 246NFC_API extern void nfc_ncif_proc_get_routing (uint8_t *p, uint8_t len); 247#endif 248NFC_API extern void nfc_ncif_proc_conn_create_rsp (uint8_t *p, uint16_t plen, uint8_t dest_type); 249NFC_API extern void nfc_ncif_report_conn_close_evt (uint8_t conn_id, tNFC_STATUS status); 250NFC_API extern void nfc_ncif_proc_t3t_polling_ntf (uint8_t *p, uint16_t plen); 251NFC_API extern void nfc_ncif_proc_reset_rsp (uint8_t *p, bool is_ntf); 252NFC_API extern void nfc_ncif_proc_init_rsp (BT_HDR *p_msg); 253NFC_API extern void nfc_ncif_proc_get_config_rsp (BT_HDR *p_msg); 254NFC_API extern void nfc_ncif_proc_data (BT_HDR *p_msg); 255NFC_API extern bool nfa_dm_p2p_prio_logic(uint8_t event, uint8_t *p, uint8_t ntf_rsp); 256NFC_API extern void nfa_dm_p2p_timer_event (); 257NFC_API extern void nfa_dm_p2p_prio_logic_cleanup (); 258 259#if (NFC_RW_ONLY == FALSE) 260NFC_API extern void nfc_ncif_proc_rf_field_ntf (uint8_t rf_status); 261#else 262#define nfc_ncif_proc_rf_field_ntf(rf_status) 263#endif 264 265/* From nfc_task.c */ 266NFC_API extern uint32_t nfc_task (uint32_t param); 267void nfc_task_shutdown_nfcc (void); 268 269/* From nfc_main.c */ 270void nfc_enabled (tNFC_STATUS nfc_status, BT_HDR *p_init_rsp_msg); 271void nfc_set_state (tNFC_STATE nfc_state); 272void nfc_main_flush_cmd_queue (void); 273void nfc_gen_cleanup (void); 274void nfc_main_handle_hal_evt (tNFC_HAL_EVT_MSG *p_msg); 275 276/* Timer functions */ 277void nfc_start_timer (TIMER_LIST_ENT *p_tle, uint16_t type, uint32_t timeout); 278uint32_t nfc_remaining_time (TIMER_LIST_ENT *p_tle); 279void nfc_stop_timer (TIMER_LIST_ENT *p_tle); 280 281void nfc_start_quick_timer (TIMER_LIST_ENT *p_tle, uint16_t type, uint32_t timeout); 282void nfc_stop_quick_timer (TIMER_LIST_ENT *p_tle); 283void nfc_process_quick_timer_evt (void); 284 285 286#ifdef __cplusplus 287} 288#endif 289 290#endif /* NFC_INT_H_ */ 291