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 "common/bt_target.h"
31 #include "common/bt_defs.h"
32 #include "osi/thread.h"
33 
34 // HACK(zachoverflow): temporary dark magic
35 #define BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK 0x1700 // didn't look used in bt_types...here goes nothing
36 typedef struct {
37     void (*callback)(BT_HDR *);
38 } post_to_task_hack_t;
39 
40 typedef struct {
41     void (*callback)(BT_HDR *);
42     BT_HDR *response;
43     void *context;
44 } command_complete_hack_t;
45 
46 typedef struct {
47     void (*callback)(BT_HDR *);
48     uint8_t status;
49     BT_HDR *command;
50     void *context;
51 } command_status_hack_t;
52 
53 /* callbacks
54 */
55 typedef void (*tBTU_TIMER_CALLBACK)(TIMER_LIST_ENT *p_tle);
56 typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr);
57 
58 
59 /* Define the timer types maintained by BTU
60 */
61 #define BTU_TTYPE_BTM_DEV_CTL       1
62 #define BTU_TTYPE_L2CAP_LINK        2
63 #define BTU_TTYPE_L2CAP_CHNL        3
64 #define BTU_TTYPE_L2CAP_HOLD        4
65 #define BTU_TTYPE_SDP               5
66 #define BTU_TTYPE_BTM_SCO           6
67 #define BTU_TTYPE_BTM_ACL           9
68 #define BTU_TTYPE_BTM_RMT_NAME      10
69 #define BTU_TTYPE_RFCOMM_MFC        11
70 #define BTU_TTYPE_RFCOMM_PORT       12
71 #define BTU_TTYPE_TCS_L2CAP         13
72 #define BTU_TTYPE_TCS_CALL          14
73 #define BTU_TTYPE_TCS_WUG           15
74 #define BTU_TTYPE_AUTO_SYNC         16
75 #define BTU_TTYPE_CTP_RECON         17
76 #define BTU_TTYPE_CTP_T100          18
77 #define BTU_TTYPE_CTP_GUARD         19
78 #define BTU_TTYPE_CTP_DETACH        20
79 
80 #define BTU_TTYPE_SPP_CONN_RETRY    21
81 #define BTU_TTYPE_USER_FUNC         22
82 
83 #define BTU_TTYPE_FTP_DISC          25
84 #define BTU_TTYPE_OPP_DISC          26
85 
86 #define BTU_TTYPE_CTP_TL_DISCVY     28
87 #define BTU_TTYPE_IPFRAG_TIMER      29
88 #define BTU_TTYPE_HSP2_AT_CMD_TO    30
89 #define BTU_TTYPE_HSP2_REPEAT_RING  31
90 
91 #define BTU_TTYPE_CTP_GW_INIT       32
92 #define BTU_TTYPE_CTP_GW_CONN       33
93 #define BTU_TTYPE_CTP_GW_IDLE       35
94 
95 #define BTU_TTYPE_ICP_L2CAP         36
96 #define BTU_TTYPE_ICP_T100          37
97 
98 #define BTU_TTYPE_HSP2_WAIT_OK      38
99 
100 /* HCRP Timers */
101 #define BTU_TTYPE_HCRP_NOTIF_REG    39
102 #define BTU_TTYPE_HCRP_PROTO_RSP    40
103 #define BTU_TTYPE_HCRP_CR_GRANT     41
104 #define BTU_TTYPE_HCRP_CR_CHECK     42
105 #define BTU_TTYPE_HCRP_W4_CLOSE     43
106 
107 /* HCRPM Timers */
108 #define BTU_TTYPE_HCRPM_NOTIF_REG   44
109 #define BTU_TTYPE_HCRPM_NOTIF_KEEP  45
110 #define BTU_TTYPE_HCRPM_API_RSP     46
111 #define BTU_TTYPE_HCRPM_W4_OPEN     47
112 #define BTU_TTYPE_HCRPM_W4_CLOSE    48
113 
114 /* BNEP Timers */
115 #define BTU_TTYPE_BNEP              50
116 
117 #define BTU_TTYPE_HSP2_SDP_FAIL_TO  55
118 #define BTU_TTYPE_HSP2_SDP_RTRY_TO  56
119 
120 /* BTU internal */
121 /* unused                           60 */
122 
123 #define BTU_TTYPE_AVDT_CCB_RET      61
124 #define BTU_TTYPE_AVDT_CCB_RSP      62
125 #define BTU_TTYPE_AVDT_CCB_IDLE     63
126 #define BTU_TTYPE_AVDT_SCB_TC       64
127 
128 #define BTU_TTYPE_HID_DEV_REPAGE_TO 65
129 #define BTU_TTYPE_HID_HOST_REPAGE_TO 66
130 
131 #define BTU_TTYPE_HSP2_DELAY_CKPD_RCV 67
132 
133 #define BTU_TTYPE_SAP_TO            68
134 
135 /* BPP Timer */
136 #define BTU_TTYPE_BPP_REF_CHNL     72
137 
138 /* LP HC idle Timer */
139 #define BTU_TTYPE_LP_HC_IDLE_TO 74
140 
141 /* Patch RAM Timer */
142 #define BTU_TTYPE_PATCHRAM_TO 75
143 
144 /* eL2CAP Info Request and other proto cmds timer */
145 #define BTU_TTYPE_L2CAP_FCR_ACK     78
146 #define BTU_TTYPE_L2CAP_INFO        79
147 /* L2CAP update connection parameters timer */
148 #define BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS            80
149 
150 #define BTU_TTYPE_MCA_CCB_RSP                       98
151 
152 /* BTU internal timer for BLE activity */
153 #define BTU_TTYPE_BLE_INQUIRY                       99
154 #define BTU_TTYPE_BLE_GAP_LIM_DISC                  100
155 #define BTU_TTYPE_ATT_WAIT_FOR_RSP                  101
156 #define BTU_TTYPE_SMP_PAIRING_CMD                   102
157 #define BTU_TTYPE_BLE_RANDOM_ADDR                   103
158 #define BTU_TTYPE_ATT_WAIT_FOR_APP_RSP              104
159 #define BTU_TTYPE_ATT_WAIT_FOR_IND_ACK              105
160 
161 #define BTU_TTYPE_BLE_GAP_FAST_ADV                  106
162 #define BTU_TTYPE_BLE_OBSERVE                       107
163 
164 #define BTU_TTYPE_UCD_TO                            108
165 #define BTU_TTYPE_BLE_SCAN                          109
166 
167 /* BTU internal timer for QOS */
168 #define BTU_TTYPE_BTM_QOS                           110
169 
170 /* BTU Task Signal */
171 typedef enum {
172     SIG_BTU_START_UP = 0,
173     SIG_BTU_HCI_MSG,
174     SIG_BTU_BTA_MSG,
175     SIG_BTU_BTA_ALARM,
176     SIG_BTU_GENERAL_ALARM,
177     SIG_BTU_ONESHOT_ALARM,
178     SIG_BTU_L2CAP_ALARM,
179     SIG_BTU_NUM,
180 } SIG_BTU_t;
181 
182 /* This is the inquiry response information held by BTU, and available
183 ** to applications.
184 */
185 typedef struct {
186     BD_ADDR     remote_bd_addr;
187     UINT8       page_scan_rep_mode;
188     UINT8       page_scan_per_mode;
189     UINT8       page_scan_mode;
190     DEV_CLASS   dev_class;
191     UINT16      clock_offset;
192 } tBTU_INQ_INFO;
193 
194 
195 
196 #define BTU_MAX_REG_TIMER     (2)   /* max # timer callbacks which may register */
197 #define BTU_MAX_REG_EVENT     (6)   /* max # event callbacks which may register */
198 #define BTU_DEFAULT_DATA_SIZE (0x2a0)
199 
200 #if (BLE_INCLUDED == TRUE)
201 #define BTU_DEFAULT_BLE_DATA_SIZE   (27)
202 #endif
203 
204 /* structure to hold registered timers */
205 typedef struct {
206     TIMER_LIST_ENT          *p_tle;      /* timer entry */
207     tBTU_TIMER_CALLBACK     timer_cb;    /* callback triggered when timer expires */
208 } tBTU_TIMER_REG;
209 
210 /* structure to hold registered event callbacks */
211 typedef struct {
212     UINT16                  event_range;  /* start of event range */
213     tBTU_EVENT_CALLBACK     event_cb;     /* callback triggered when event is in range */
214 } tBTU_EVENT_REG;
215 
216 #define NFC_MAX_LOCAL_CTRLS     0
217 
218 /* the index to BTU command queue array */
219 #define NFC_CONTROLLER_ID       (1)
220 #define BTU_MAX_LOCAL_CTRLS     (1 + NFC_MAX_LOCAL_CTRLS) /* only BR/EDR */
221 
222 /* Define structure holding BTU variables
223 */
224 typedef struct {
225     tBTU_TIMER_REG   timer_reg[BTU_MAX_REG_TIMER];
226     tBTU_EVENT_REG   event_reg[BTU_MAX_REG_EVENT];
227 
228     BOOLEAN     reset_complete;             /* TRUE after first ack from device received */
229     UINT8       trace_level;                /* Trace level for HCI layer */
230 } tBTU_CB;
231 
232 /*
233 #ifdef __cplusplus
234 extern "C" {
235 #endif
236 */
237 /* Global BTU data */
238 #if BTU_DYNAMIC_MEMORY == FALSE
239 extern tBTU_CB  btu_cb;
240 #else
241 extern tBTU_CB *btu_cb_ptr;
242 #define btu_cb (*btu_cb_ptr)
243 #endif
244 
245 extern const BD_ADDR        BT_BD_ANY;
246 
247 /* Functions provided by btu_task.c
248 ************************************
249 */
250 void btu_start_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
251 void btu_stop_timer (TIMER_LIST_ENT *p_tle);
252 void btu_free_timer (TIMER_LIST_ENT *p_tle);
253 void btu_start_timer_oneshot(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
254 void btu_stop_timer_oneshot(TIMER_LIST_ENT *p_tle);
255 
256 void btu_uipc_rx_cback(BT_HDR *p_msg);
257 
258 /*
259 ** Quick Timer
260 */
261 #if defined(QUICK_TIMER_TICKS_PER_SEC) && (QUICK_TIMER_TICKS_PER_SEC > 0)
262 void btu_start_quick_timer (TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout);
263 void btu_stop_quick_timer (TIMER_LIST_ENT *p_tle);
264 void btu_free_quick_timer (TIMER_LIST_ENT *p_tle);
265 void btu_process_quick_timer_evt (void);
266 #endif
267 
268 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
269 void btu_check_bt_sleep (void);
270 #endif
271 
272 /* Functions provided by btu_hcif.c
273 ************************************
274 */
275 void  btu_hcif_process_event (UINT8 controller_id, BT_HDR *p_buf);
276 void  btu_hcif_send_cmd (UINT8 controller_id, BT_HDR *p_msg);
277 #if (BLE_50_FEATURE_SUPPORT == TRUE)
278 UINT8  btu_hcif_send_cmd_sync (UINT8 controller_id, BT_HDR *p_buf);
279 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
280 void  btu_hcif_send_host_rdy_for_data(void);
281 void  btu_hcif_cmd_timeout (UINT8 controller_id);
282 
283 /* Functions provided by btu_core.c
284 ************************************
285 */
286 void  btu_init_core(void);
287 void  btu_free_core(void);
288 
289 void BTU_StartUp(void);
290 void BTU_ShutDown(void);
291 
292 void btu_task_start_up(void *param);
293 void btu_task_shut_down(void);
294 
295 UINT16 BTU_BleAclPktSize(void);
296 
297 bool btu_task_post(uint32_t sig, void *param, uint32_t timeout);
298 
299 int get_btu_work_queue_size(void);
300 
301 /*
302 #ifdef __cplusplus
303 }
304 #endif
305 */
306 
307 #endif
308