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