• 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_BLE_GAP_FAST_ADV                  106
157 #define BTU_TTYPE_BLE_OBSERVE                       107
158 
159 
160 #define BTU_TTYPE_UCD_TO                            108
161 
162 
163 
164 /* Define the BTU_TASK APPL events
165 */
166 #if (defined(NFC_SHARED_TRANSPORT_ENABLED) && (NFC_SHARED_TRANSPORT_ENABLED==TRUE))
167 #define BTU_NFC_AVAILABLE_EVT   EVENT_MASK(APPL_EVT_0)  /* Notifies BTU task that NFC is available (used for shared NFC+BT transport) */
168 #endif
169 
170 /* This is the inquiry response information held by BTU, and available
171 ** to applications.
172 */
173 typedef struct
174 {
175     BD_ADDR     remote_bd_addr;
176     UINT8       page_scan_rep_mode;
177     UINT8       page_scan_per_mode;
178     UINT8       page_scan_mode;
179     DEV_CLASS   dev_class;
180     UINT16      clock_offset;
181 } tBTU_INQ_INFO;
182 
183 
184 
185 #define BTU_MAX_REG_TIMER     (2)   /* max # timer callbacks which may register */
186 #define BTU_MAX_REG_EVENT     (6)   /* max # event callbacks which may register */
187 #define BTU_DEFAULT_DATA_SIZE (0x2a0)
188 
189 #if (BLE_INCLUDED == TRUE)
190 #define BTU_DEFAULT_BLE_DATA_SIZE   (27)
191 #endif
192 
193 /* structure to hold registered timers */
194 typedef struct
195 {
196     TIMER_LIST_ENT          *p_tle;      /* timer entry */
197     tBTU_TIMER_CALLBACK     timer_cb;    /* callback triggered when timer expires */
198 } tBTU_TIMER_REG;
199 
200 /* structure to hold registered event callbacks */
201 typedef struct
202 {
203     UINT16                  event_range;  /* start of event range */
204     tBTU_EVENT_CALLBACK     event_cb;     /* callback triggered when event is in range */
205 } tBTU_EVENT_REG;
206 
207 #define NFC_MAX_LOCAL_CTRLS     0
208 
209 /* the index to BTU command queue array */
210 #define NFC_CONTROLLER_ID       (1)
211 #define BTU_MAX_LOCAL_CTRLS     (1 + NFC_MAX_LOCAL_CTRLS) /* only BR/EDR */
212 
213 /* AMP HCI control block */
214 typedef struct
215 {
216     BUFFER_Q         cmd_xmit_q;
217     BUFFER_Q         cmd_cmpl_q;
218     UINT16           cmd_window;
219     TIMER_LIST_ENT   cmd_cmpl_timer;        /* Command complete timer */
220 #if (defined(BTU_CMD_CMPL_TOUT_DOUBLE_CHECK) && BTU_CMD_CMPL_TOUT_DOUBLE_CHECK == TRUE)
221     BOOLEAN          checked_hcisu;
222 #endif
223 } tHCI_CMD_CB;
224 
225 /* Define structure holding BTU variables
226 */
227 typedef struct
228 {
229     tBTU_TIMER_REG   timer_reg[BTU_MAX_REG_TIMER];
230     tBTU_EVENT_REG   event_reg[BTU_MAX_REG_EVENT];
231 
232     TIMER_LIST_Q  quick_timer_queue;        /* Timer queue for transport level (100/10 msec)*/
233     TIMER_LIST_Q  timer_queue;              /* Timer queue for normal BTU task (1 second)   */
234     TIMER_LIST_Q  timer_queue_oneshot;      /* Timer queue for oneshot BTU tasks */
235 
236     TIMER_LIST_ENT   cmd_cmpl_timer;        /* Command complete timer */
237 
238     UINT16    hcit_acl_data_size;           /* Max ACL data size across HCI transport    */
239     UINT16    hcit_acl_pkt_size;            /* Max ACL packet size across HCI transport  */
240                                             /* (this is data size plus 4 bytes overhead) */
241 
242 #if BLE_INCLUDED == TRUE
243     UINT16    hcit_ble_acl_data_size;           /* Max BLE ACL data size across HCI transport    */
244     UINT16    hcit_ble_acl_pkt_size;            /* Max BLE ACL packet size across HCI transport  */
245                                             /* (this is data size plus 4 bytes overhead) */
246 #endif
247 
248     BOOLEAN     reset_complete;             /* TRUE after first ack from device received */
249     UINT8       trace_level;                /* Trace level for HCI layer */
250 
251     tHCI_CMD_CB hci_cmd_cb[BTU_MAX_LOCAL_CTRLS]; /* including BR/EDR */
252 } tBTU_CB;
253 
254 #ifdef __cplusplus
255 extern "C" {
256 #endif
257 
258 /* Global BTU data */
259 #if BTU_DYNAMIC_MEMORY == FALSE
260 BTU_API extern tBTU_CB  btu_cb;
261 #else
262 BTU_API extern tBTU_CB *btu_cb_ptr;
263 #define btu_cb (*btu_cb_ptr)
264 #endif
265 
266 BTU_API extern const BD_ADDR        BT_BD_ANY;
267 
268 /* Functions provided by btu_task.c
269 ************************************
270 */
271 BTU_API extern void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
272 BTU_API extern void btu_stop_timer (TIMER_LIST_ENT *p_tle);
273 BTU_API extern void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
274 BTU_API extern void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle);
275 
276 BTU_API extern UINT32 btu_remaining_time (TIMER_LIST_ENT *p_tle);
277 
278 BTU_API extern void btu_uipc_rx_cback(BT_HDR *p_msg);
279 
280 BTU_API extern void btu_hcif_flush_cmd_queue(void);
281 /*
282 ** Quick Timer
283 */
284 #if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
285 #define QUICK_TIMER_TICKS (GKI_SECS_TO_TICKS (1)/QUICK_TIMER_TICKS_PER_SEC)
286 BTU_API extern void btu_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
287 BTU_API extern void btu_stop_quick_timer (TIMER_LIST_ENT *p_tle);
288 BTU_API extern void btu_process_quick_timer_evt (void);
289 BTU_API extern void process_quick_timer_evt (TIMER_LIST_Q *p_tlq);
290 #endif
291 
292 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
293 BTU_API extern void btu_check_bt_sleep (void);
294 #endif
295 
296 /* Functions provided by btu_hcif.c
297 ************************************
298 */
299 BTU_API extern void  btu_hcif_process_event (UINT8 controller_id, BT_HDR *p_buf);
300 BTU_API extern void  btu_hcif_send_cmd (UINT8 controller_id, BT_HDR *p_msg);
301 BTU_API extern void  btu_hcif_send_host_rdy_for_data(void);
302 BTU_API extern void  btu_hcif_cmd_timeout (UINT8 controller_id);
303 
304 /* Functions provided by btu_core.c
305 ************************************
306 */
307 BTU_API extern void  btu_init_core(void);
308 BTU_API extern void  BTE_Init(void);
309 BTU_API extern UINT16 BTU_AclPktSize(void);
310 BTU_API extern UINT16 BTU_BleAclPktSize(void);
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 
316 #endif
317