btu.h revision 307381ef1ed1b434c956a9a98ca25ba6b415d7c7
1/****************************************************************************** 2 * 3 * Copyright (C) 1999-2012 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 main Bluetooth Upper Layer definitions. The Broadcom 22 * implementations of L2CAP RFCOMM, SDP and the BTIf run as one GKI task. The 23 * btu_task switches between them. 24 * 25 ******************************************************************************/ 26 27#ifndef BTU_H 28#define BTU_H 29 30#include "bt_target.h" 31#include "gki.h" 32 33// HACK(zachoverflow): temporary dark magic 34#define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK 0x1700 // didn't look used in bt_types...here goes nothing 35typedef struct { 36 void (*callback)(BT_HDR *); 37} post_to_task_hack_t; 38 39typedef struct { 40 void (*callback)(BT_HDR *); 41 BT_HDR *response; 42 void *context; 43} command_complete_hack_t; 44 45typedef struct { 46 void (*callback)(BT_HDR *); 47 uint8_t status; 48 BT_HDR *command; 49 void *context; 50} command_status_hack_t; 51 52/* Define the BTU mailbox usage 53*/ 54#define BTU_HCI_RCV_MBOX TASK_MBOX_0 /* Messages from HCI */ 55#define BTU_BTIF_MBOX TASK_MBOX_1 /* Messages to BTIF */ 56 57/* callbacks 58*/ 59typedef void (*tBTU_TIMER_CALLBACK)(TIMER_LIST_ENT *p_tle); 60typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr); 61 62 63/* Define the timer types maintained by BTU 64*/ 65#define BTU_TTYPE_BTM_DEV_CTL 1 66#define BTU_TTYPE_L2CAP_LINK 2 67#define BTU_TTYPE_L2CAP_CHNL 3 68#define BTU_TTYPE_L2CAP_HOLD 4 69#define BTU_TTYPE_SDP 5 70#define BTU_TTYPE_BTM_SCO 6 71#define BTU_TTYPE_BTM_ACL 9 72#define BTU_TTYPE_BTM_RMT_NAME 10 73#define BTU_TTYPE_RFCOMM_MFC 11 74#define BTU_TTYPE_RFCOMM_PORT 12 75#define BTU_TTYPE_TCS_L2CAP 13 76#define BTU_TTYPE_TCS_CALL 14 77#define BTU_TTYPE_TCS_WUG 15 78#define BTU_TTYPE_AUTO_SYNC 16 79#define BTU_TTYPE_CTP_RECON 17 80#define BTU_TTYPE_CTP_T100 18 81#define BTU_TTYPE_CTP_GUARD 19 82#define BTU_TTYPE_CTP_DETACH 20 83 84#define BTU_TTYPE_SPP_CONN_RETRY 21 85#define BTU_TTYPE_USER_FUNC 22 86 87#define BTU_TTYPE_FTP_DISC 25 88#define BTU_TTYPE_OPP_DISC 26 89 90#define BTU_TTYPE_CTP_TL_DISCVY 28 91#define BTU_TTYPE_IPFRAG_TIMER 29 92#define BTU_TTYPE_HSP2_AT_CMD_TO 30 93#define BTU_TTYPE_HSP2_REPEAT_RING 31 94 95#define BTU_TTYPE_CTP_GW_INIT 32 96#define BTU_TTYPE_CTP_GW_CONN 33 97#define BTU_TTYPE_CTP_GW_IDLE 35 98 99#define BTU_TTYPE_ICP_L2CAP 36 100#define BTU_TTYPE_ICP_T100 37 101 102#define BTU_TTYPE_HSP2_WAIT_OK 38 103 104/* HCRP Timers */ 105#define BTU_TTYPE_HCRP_NOTIF_REG 39 106#define BTU_TTYPE_HCRP_PROTO_RSP 40 107#define BTU_TTYPE_HCRP_CR_GRANT 41 108#define BTU_TTYPE_HCRP_CR_CHECK 42 109#define BTU_TTYPE_HCRP_W4_CLOSE 43 110 111/* HCRPM Timers */ 112#define BTU_TTYPE_HCRPM_NOTIF_REG 44 113#define BTU_TTYPE_HCRPM_NOTIF_KEEP 45 114#define BTU_TTYPE_HCRPM_API_RSP 46 115#define BTU_TTYPE_HCRPM_W4_OPEN 47 116#define BTU_TTYPE_HCRPM_W4_CLOSE 48 117 118/* BNEP Timers */ 119#define BTU_TTYPE_BNEP 50 120 121/* OBX */ 122#define BTU_TTYPE_OBX_CLIENT_TO 51 123#define BTU_TTYPE_OBX_SERVER_TO 52 124#define BTU_TTYPE_OBX_SVR_SESS_TO 53 125 126 127#define BTU_TTYPE_HSP2_SDP_FAIL_TO 55 128#define BTU_TTYPE_HSP2_SDP_RTRY_TO 56 129 130/* BTU internal */ 131/* unused 60 */ 132 133#define BTU_TTYPE_AVDT_CCB_RET 61 134#define BTU_TTYPE_AVDT_CCB_RSP 62 135#define BTU_TTYPE_AVDT_CCB_IDLE 63 136#define BTU_TTYPE_AVDT_SCB_TC 64 137 138#define BTU_TTYPE_HID_DEV_REPAGE_TO 65 139#define BTU_TTYPE_HID_HOST_REPAGE_TO 66 140 141#define BTU_TTYPE_HSP2_DELAY_CKPD_RCV 67 142 143#define BTU_TTYPE_SAP_TO 68 144 145/* BPP Timer */ 146#define BTU_TTYPE_BPP_REF_CHNL 72 147 148/* LP HC idle Timer */ 149#define BTU_TTYPE_LP_HC_IDLE_TO 74 150 151/* Patch RAM Timer */ 152#define BTU_TTYPE_PATCHRAM_TO 75 153 154/* eL2CAP Info Request and other proto cmds timer */ 155#define BTU_TTYPE_L2CAP_FCR_ACK 78 156#define BTU_TTYPE_L2CAP_INFO 79 157 158#define BTU_TTYPE_MCA_CCB_RSP 98 159 160/* BTU internal timer for BLE activity */ 161#define BTU_TTYPE_BLE_INQUIRY 99 162#define BTU_TTYPE_BLE_GAP_LIM_DISC 100 163#define BTU_TTYPE_ATT_WAIT_FOR_RSP 101 164#define BTU_TTYPE_SMP_PAIRING_CMD 102 165#define BTU_TTYPE_BLE_RANDOM_ADDR 103 166#define BTU_TTYPE_ATT_WAIT_FOR_APP_RSP 104 167#define BTU_TTYPE_ATT_WAIT_FOR_IND_ACK 105 168 169#define BTU_TTYPE_BLE_GAP_FAST_ADV 106 170#define BTU_TTYPE_BLE_OBSERVE 107 171 172 173#define BTU_TTYPE_UCD_TO 108 174 175 176 177/* Define the BTU_TASK APPL events 178*/ 179#if (defined(NFC_SHARED_TRANSPORT_ENABLED) && (NFC_SHARED_TRANSPORT_ENABLED==TRUE)) 180#define BTU_NFC_AVAILABLE_EVT EVENT_MASK(APPL_EVT_0) /* Notifies BTU task that NFC is available (used for shared NFC+BT transport) */ 181#endif 182 183/* This is the inquiry response information held by BTU, and available 184** to applications. 185*/ 186typedef struct 187{ 188 BD_ADDR remote_bd_addr; 189 UINT8 page_scan_rep_mode; 190 UINT8 page_scan_per_mode; 191 UINT8 page_scan_mode; 192 DEV_CLASS dev_class; 193 UINT16 clock_offset; 194} tBTU_INQ_INFO; 195 196 197 198#define BTU_MAX_REG_TIMER (2) /* max # timer callbacks which may register */ 199#define BTU_MAX_REG_EVENT (6) /* max # event callbacks which may register */ 200#define BTU_DEFAULT_DATA_SIZE (0x2a0) 201 202#if (BLE_INCLUDED == TRUE) 203#define BTU_DEFAULT_BLE_DATA_SIZE (27) 204#endif 205 206/* structure to hold registered timers */ 207typedef struct 208{ 209 TIMER_LIST_ENT *p_tle; /* timer entry */ 210 tBTU_TIMER_CALLBACK timer_cb; /* callback triggered when timer expires */ 211} tBTU_TIMER_REG; 212 213/* structure to hold registered event callbacks */ 214typedef struct 215{ 216 UINT16 event_range; /* start of event range */ 217 tBTU_EVENT_CALLBACK event_cb; /* callback triggered when event is in range */ 218} tBTU_EVENT_REG; 219 220#define NFC_MAX_LOCAL_CTRLS 0 221 222/* the index to BTU command queue array */ 223#define NFC_CONTROLLER_ID (1) 224#define BTU_MAX_LOCAL_CTRLS (1 + NFC_MAX_LOCAL_CTRLS) /* only BR/EDR */ 225 226/* AMP HCI control block */ 227typedef struct 228{ 229 BUFFER_Q cmd_xmit_q; 230 BUFFER_Q cmd_cmpl_q; 231 UINT16 cmd_window; 232 TIMER_LIST_ENT cmd_cmpl_timer; /* Command complete timer */ 233} tHCI_CMD_CB; 234 235/* Define structure holding BTU variables 236*/ 237typedef struct 238{ 239 tBTU_TIMER_REG timer_reg[BTU_MAX_REG_TIMER]; 240 tBTU_EVENT_REG event_reg[BTU_MAX_REG_EVENT]; 241 242 TIMER_LIST_Q quick_timer_queue; /* Timer queue for transport level (100/10 msec)*/ 243 TIMER_LIST_Q timer_queue; /* Timer queue for normal BTU task (1 second) */ 244 TIMER_LIST_Q timer_queue_oneshot; /* Timer queue for oneshot BTU tasks */ 245 246 TIMER_LIST_ENT cmd_cmpl_timer; /* Command complete timer */ 247 248 UINT16 hcit_acl_data_size; /* Max ACL data size across HCI transport */ 249 UINT16 hcit_acl_pkt_size; /* Max ACL packet size across HCI transport */ 250 /* (this is data size plus 4 bytes overhead) */ 251 252#if BLE_INCLUDED == TRUE 253 UINT16 hcit_ble_acl_data_size; /* Max BLE ACL data size across HCI transport */ 254 UINT16 hcit_ble_acl_pkt_size; /* Max BLE ACL packet size across HCI transport */ 255 /* (this is data size plus 4 bytes overhead) */ 256#endif 257 258 BOOLEAN reset_complete; /* TRUE after first ack from device received */ 259 UINT8 trace_level; /* Trace level for HCI layer */ 260 261 tHCI_CMD_CB hci_cmd_cb[BTU_MAX_LOCAL_CTRLS]; /* including BR/EDR */ 262} tBTU_CB; 263 264#ifdef __cplusplus 265extern "C" { 266#endif 267 268/* Global BTU data */ 269#if BTU_DYNAMIC_MEMORY == FALSE 270BTU_API extern tBTU_CB btu_cb; 271#else 272BTU_API extern tBTU_CB *btu_cb_ptr; 273#define btu_cb (*btu_cb_ptr) 274#endif 275 276BTU_API extern const BD_ADDR BT_BD_ANY; 277 278/* Functions provided by btu_task.c 279************************************ 280*/ 281extern void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); 282extern void btu_stop_timer (TIMER_LIST_ENT *p_tle); 283extern void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); 284extern void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle); 285extern UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle); 286 287BTU_API extern UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle); 288BTU_API extern void btu_uipc_rx_cback(BT_HDR *p_msg); 289 290BTU_API extern void btu_hcif_flush_cmd_queue(void); 291/* 292** Quick Timer 293*/ 294#if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0) 295#define QUICK_TIMER_TICKS (GKI_SECS_TO_TICKS (1)/QUICK_TIMER_TICKS_PER_SEC) 296BTU_API extern void btu_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout); 297BTU_API extern void btu_stop_quick_timer (TIMER_LIST_ENT *p_tle); 298BTU_API extern void btu_process_quick_timer_evt (void); 299BTU_API extern void process_quick_timer_evt (TIMER_LIST_Q *p_tlq); 300#endif 301 302#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE) 303BTU_API extern void btu_check_bt_sleep (void); 304#endif 305 306/* Functions provided by btu_hcif.c 307************************************ 308*/ 309BTU_API extern void btu_hcif_process_event (UINT8 controller_id, BT_HDR *p_buf); 310BTU_API extern void btu_hcif_send_cmd (UINT8 controller_id, BT_HDR *p_msg); 311BTU_API extern void btu_hcif_send_host_rdy_for_data(void); 312BTU_API extern void btu_hcif_cmd_timeout (UINT8 controller_id); 313 314/* Functions provided by btu_core.c 315************************************ 316*/ 317BTU_API extern void btu_init_core(void); 318BTU_API extern void btu_free_core(void); 319 320void BTU_StartUp(void); 321void BTU_ShutDown(void); 322 323BTU_API extern UINT16 BTU_AclPktSize(void); 324BTU_API extern UINT16 BTU_BleAclPktSize(void); 325 326#ifdef __cplusplus 327} 328#endif 329 330#endif 331