nfc_int.h revision e29968cf3e053557a9c2efc5a7a42d0767c51d9d
1/**************************************************************************** 2** 3** File: nfc_int.h 4** 5** Description: this file contains the main NFC Upper Layer 6** internal definitions and functions. 7** 8** Copyright (c) 2009-2012, Broadcom Corp., All Rights Reserved. 9** Broadcom Bluetooth Core. Proprietary and confidential. 10****************************************************************************/ 11 12#ifndef NFC_INT_H_ 13#define NFC_INT_H_ 14 15 16#include "nfc_target.h" 17#include "gki.h" 18#include "nci_defs.h" 19#include "nfc_api.h" 20#include "btu_api.h" 21 22#ifdef __cplusplus 23extern "C" { 24#endif 25 26/**************************************************************************** 27** Internal NFC constants and definitions 28****************************************************************************/ 29 30/**************************************************************************** 31** NFC_TASK definitions 32****************************************************************************/ 33 34/* NFC_TASK event masks */ 35#define NFC_TASK_EVT_TRANSPORT_READY EVENT_MASK(APPL_EVT_0) 36#define NFC_TASK_EVT_ENABLE EVENT_MASK(APPL_EVT_1) 37#define NFC_TASK_EVT_TERMINATE EVENT_MASK(APPL_EVT_7) 38 39/* Error codes (in layer_specific) for BT_EVT_TO_NFC_ERR event */ 40#define NFC_ERR_TRANSPORT 0 /* fatal error in NCI transport */ 41#define NFC_ERR_CMD_TIMEOUT 1 /* NCI command timeout */ 42 43/* Message codes (in layer_specific) for BT_EVT_TO_NFC_MSGS event */ 44#define NFC_MSGS_RF_ACT_CREDITS 0x00 /* NFC->NCI: The buffer size and credits for RF ACTIVATE NTF */ 45#define NFC_MSGS_RF_DEACT_CHECK 0x01 /* NFC->NCI: RF DEACTIVATE: check for outstanding data */ 46#define NFC_MSGS_RF_DEACT_CONFIRM 0x10 /* NCI->NFC: RF DEACTIVATE: confirm to deactivate */ 47 48/* NFC Timer events */ 49#define NFC_TTYPE_WAIT_2_DEACTIVATE 1 50 51#define NFC_TTYPE_LLCP_LINK_MANAGER 100 52#define NFC_TTYPE_LLCP_LINK_INACT 101 53#define NFC_TTYPE_LLCP_DATA_LINK 102 54#define NFC_TTYPE_LLCP_DELAY_FIRST_PDU 103 55#define NFC_TTYPE_RW_T1T_RESPONSE 104 56#define NFC_TTYPE_RW_T2T_RESPONSE 105 57#define NFC_TTYPE_RW_T3T_RESPONSE 106 58#define NFC_TTYPE_RW_T4T_RESPONSE 107 59#define NFC_TTYPE_RW_I93_RESPONSE 108 60#define NFC_TTYPE_CE_T4T_UPDATE 109 61#define NFC_TTYPE_VS_BASE 200 62 63 64/* NFC Task event messages */ 65 66enum 67{ 68 NFC_STATE_NONE, /* not start up yet */ 69 NFC_STATE_IDLE, /* reset/init */ 70 NFC_STATE_OPEN, /* NFC link is activated */ 71 NFC_STATE_CLOSING, /* de-activating */ 72 NFC_STATE_RESTARTING, /* restarting NFCC after reboot */ 73 NFC_STATE_NFCC_POWER_OFF_SLEEP /* NFCC is power-off sleep mode */ 74}; 75typedef UINT8 tNFC_STATE; 76 77/* NFC control block flags */ 78#define NFC_FL_ENABLED 0x0001 /* NFC enabled */ 79#define NFC_FL_ENABLE_PENDING 0x0002 /* NFC is being enabled (NFC_ENABLE_EVT pending)*/ 80#define NFC_FL_NCI_TRANSPORT_ENABLED 0x0004 /* Transport enabled */ 81#define NFC_FL_DEACTIVATING 0x0008 /* NFC_Deactivate() is called and the NCI cmd is not sent */ 82#define NFC_FL_W4_TRANSPORT_READY 0x0010 /* Waiting for NCI transport to be ready before enabling NFC*/ 83#define NFC_FL_POWER_CYCLE_NFCC 0x0020 /* Power cycle NFCC */ 84 85#define NFC_PEND_CONN_ID 0xFE 86#define NFC_CONN_ID_INT_MASK 0xF0 87#define NFC_CONN_ID_ID_MASK NCI_CID_MASK 88#define NFC_CONN_NO_FC 0xFF /* set num_buff to this for no flow control */ 89#define NFC_NCI_CONN_NO_FC 0xFF 90 91#if (NFC_RW_ONLY == FALSE) 92/* only allow the entries that the NFCC can support */ 93#define NFC_CHECK_MAX_CONN() { if (max > nfc_cb.max_conn) max = nfc_cb.max_conn;} 94#else 95#define NFC_CHECK_MAX_CONN() 96#endif 97 98typedef struct 99{ 100 tNFC_CONN_CBACK *p_cback; /* the callback function to receive the data */ 101 BUFFER_Q rx_q; /* receive queue */ 102 UINT8 id; /* NFCEE ID or RF Discovery ID or NFC_TEST_ID */ 103 UINT8 act_protocol; /* the active protocol on this logical connection */ 104 UINT8 conn_id; /* the connection id assigned by NFCC for this conn */ 105} tNFC_CONN_CB; 106 107/* This data type is for NFC task to send a NCI VS command to NCI task */ 108typedef struct 109{ 110 BT_HDR bt_hdr; /* the NCI command */ 111 tNFC_VS_CBACK *p_cback; /* the callback function to receive RSP */ 112} tNFC_NCI_VS_MSG; 113 114/* This data type is for NFC task to send BT_EVT_TO_NFC_MSGS/NFC_MSGS_RF_ACT_CREDITS to NCI task */ 115typedef struct 116{ 117 BT_HDR bt_hdr; /* the NCI message header */ 118 UINT8 buff_size; /* The event status. */ 119 UINT8 num_buff; /* num of buffers left to send on this connection */ 120} tNFC_ACTIVATE_MSGS; 121 122/* This data type is for NCI task to report a received message to NFC task */ 123typedef struct 124{ 125 BT_HDR bt_hdr; /* the NCI RSP/NTF/DATA received from NFCC */ 126 tNFC_VS_CBACK *p_cback; /* If VS RSP, the callback function to report RSP */ 127 UINT8 cmd[NFC_SAVED_CMD_SIZE]; /* If msg is RSP, first bytes of CMD */ 128} tNFC_NCI_MSG; 129#define NFC_RECEIVE_MSGS_OFFSET (10) /* callback function pointer(8; use 8 to be safe + NFC_SAVED_CMD_SIZE(2) */ 130 131enum 132{ 133 NFC_INT_ENABLE_END_EVT, /* Right before reporting NFC_ENABLE_EVT */ 134 NFC_INT_MBOX_EVT, /* Received mailbox event */ 135 NFC_INT_NCI_VS_RSP_EVT, /* Received NCI VS response */ 136 NFC_INT_NCI_VS_NTF_EVT, /* Received NCI VS notification */ 137 NFC_INT_TIMEOUT_EVT, /* timeout event */ 138 NFC_INT_DISABLE_EVT /* Disabling the stack */ 139}; 140typedef UINT16 tNFC_INT_EVT; 141typedef BOOLEAN (tNFC_VS_EVT_HDLR) (tNFC_INT_EVT event, void *p); 142 143/* NFCC power state change pending callback */ 144typedef void (tNFC_PWR_ST_CBACK) (void); 145 146/* NFC control blocks */ 147typedef struct 148{ 149 UINT16 flags; /* NFC control block flags - NFC_FL_* */ 150 tNFC_CONN_CB conn_cb[NCI_MAX_CONN_CBS]; 151 UINT8 conn_id[NFC_MAX_CONN_ID+1]; /* index: conn_id; conn_id[]: index(1 based) to conn_cb[] */ 152 tNFC_DISCOVER_CBACK *p_discv_cback; 153 tNFC_RESPONSE_CBACK *p_resp_cback; 154 tNFC_TEST_CBACK *p_test_cback; 155 tNFC_VS_CBACK *p_vs_cb[NFC_NUM_VS_CBACKS];/* Register for vendor specific events */ 156 157#if (NFC_RW_ONLY == FALSE) 158 /* NFCC information at init rsp */ 159 UINT32 nci_features; /* the NCI features supported by NFCC */ 160 UINT16 max_ce_table; /* the max routing table size */ 161 UINT8 max_conn; /* the num of connections supported by NFCC */ 162#endif 163 UINT8 nci_ctrl_size; /* Max Control Packet Payload Size */ 164 165 /* the data members in this section may be changed by NFC_<VendorSpecific>Init() */ 166 tNFC_VS_EVT_HDLR *p_vs_evt_hdlr; /* VS processing for internal events */ 167 const tNCI_DISCOVER_MAPS *p_disc_maps; /* NCI RF Discovery interface mapping */ 168 UINT8 vs_interface[NFC_NFCC_MAX_NUM_VS_INTERFACE]; /* the NCI VS interfaces of NFCC */ 169 UINT16 nci_interfaces; /* the NCI interfaces of NFCC */ 170 UINT8 num_disc_maps; /* number of RF Discovery interface mappings */ 171 172 /* NFC_TASK timer management */ 173 TIMER_LIST_Q timer_queue; /* 1-sec timer event queue */ 174 TIMER_LIST_Q quick_timer_queue; 175 176 TIMER_LIST_ENT deactivate_timer; /* Timer to wait for deactivation */ 177 178 tNFC_STATE nfc_state; 179 UINT8 trace_level; 180} tNFC_CB; 181 182 183/***************************************************************************** 184** EXTERNAL FUNCTION DECLARATIONS 185*****************************************************************************/ 186 187/* Global NFC data */ 188#if NFC_DYNAMIC_MEMORY == FALSE 189NFC_API extern tNFC_CB nfc_cb; 190#else 191NFC_API extern tNFC_CB *nfc_cb_ptr; 192#define nfc_cb (*nfc_cb_ptr) 193#endif 194 195/**************************************************************************** 196** Internal nfc functions 197****************************************************************************/ 198 199NFC_API extern void nfc_init(void); 200 201/* from nfc_utils.c */ 202NFC_API extern tNFC_CONN_CB * nfc_alloc_conn_cb( tNFC_CONN_CBACK *p_cback); 203NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_conn_id(UINT8 conn_id); 204NFC_API extern tNFC_CONN_CB * nfc_find_conn_cb_by_handle(UINT8 target_handle); 205NFC_API extern void nfc_set_conn_id(tNFC_CONN_CB * p_cb, UINT8 conn_id); 206NFC_API extern void nfc_free_conn_cb( tNFC_CONN_CB *p_cb); 207NFC_API extern void nfc_reset_all_conn_cbs( void); 208NFC_API extern void nfc_data_event(tNFC_CONN_CB * p_cb); 209 210void nfc_ncif_send (BT_HDR *p_buf, BOOLEAN is_cmd); 211extern UINT8 nfc_ncif_send_data (tNFC_CONN_CB *p_cb, BT_HDR *p_data); 212NFC_API extern void nfc_wait_2_deactivate_timeout (void); 213 214NFC_API extern BOOLEAN nfc_ncif_process_event (BT_HDR *p_msg); 215NFC_API extern void nfc_ncif_send_vsc (BT_HDR *p_buf); 216NFC_API extern void nfc_ncif_send_cmd (BT_HDR *p_buf); 217NFC_API extern void nfc_ncif_proc_discover_ntf(UINT8 *p, UINT16 plen); 218NFC_API extern void nfc_ncif_rf_management_status(tNFC_DISCOVER_EVT event, UINT8 status); 219NFC_API extern void nfc_ncif_set_config_status (UINT8 *p, UINT8 len); 220NFC_API extern void nfc_ncif_event_status(tNFC_RESPONSE_EVT event, UINT8 status); 221NFC_API extern void nfc_ncif_error_status(UINT8 conn_id, UINT8 status); 222NFC_API extern void nfc_ncif_proc_activate(UINT8 *p, UINT8 len); 223NFC_API extern void nfc_ncif_proc_deactivate(UINT8 status, UINT8 deact_type, BOOLEAN is_ntf); 224#if ((NFC_NFCEE_INCLUDED == TRUE) && (NFC_RW_ONLY == FALSE)) 225NFC_API extern void nfc_ncif_proc_ee_action(UINT8 *p, UINT16 plen); 226NFC_API extern void nfc_ncif_proc_ee_discover_req(UINT8 *p, UINT16 plen); 227NFC_API extern void nfc_ncif_proc_get_routing(UINT8 *p, UINT8 len); 228#endif 229NFC_API extern void nfc_ncif_proc_conn_create_rsp (UINT8 *p, UINT16 plen, UINT8 dest_type); 230NFC_API extern void nfc_ncif_report_conn_close_evt (UINT8 conn_id, tNFC_STATUS status); 231NFC_API extern void nfc_ncif_proc_t3t_polling_ntf(UINT8 *p, UINT16 plen); 232NFC_API extern void nfc_ncif_proc_reset_rsp (UINT8 *p, BOOLEAN is_ntf); 233NFC_API extern void nfc_ncif_proc_init_rsp (BT_HDR *p_msg); 234NFC_API extern void nfc_ncif_proc_get_config_rsp (BT_HDR *p_msg); 235NFC_API extern void nfc_ncif_proc_data (BT_HDR *p_msg); 236extern void nfc_main_disable_complete(tNFC_STATUS status); 237 238#if (NFC_RW_ONLY == FALSE) 239NFC_API extern void nfc_ncif_proc_rf_field_ntf(UINT8 rf_status); 240#else 241#define nfc_ncif_proc_rf_field_ntf(rf_status) 242#endif 243 244/* From nci_main.c */ 245NFC_API extern void nfc_notify_shared_transport_ready(void); 246 247/* From nfc_main.c */ 248void nfc_enabled (tNFC_STATUS nfc_status, BT_HDR *p_init_rsp_msg); 249void nfc_set_state (tNFC_STATE nfc_state); 250void nfc_gen_cleanup(void); 251void nfc_main_cleanup(void); 252void nfc_main_handle_err(BT_HDR *p_err_msg); 253void nfc_main_handle_msgs(BT_HDR *p_msg); 254 255/* Timer functions */ 256void nfc_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); 257UINT32 nfc_remaining_time (TIMER_LIST_ENT *p_tle); 258void nfc_stop_timer (TIMER_LIST_ENT *p_tle); 259 260void nfc_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); 261void nfc_stop_quick_timer (TIMER_LIST_ENT *p_tle); 262void nfc_process_quick_timer_evt (void); 263#ifdef __cplusplus 264} 265#endif 266 267#endif /* NFC_INT_H_ */ 268