OSDN Git Service

Merge "[DO NOT MERGE] Add KDDI carkit into IOP table to disable sniff" into rvc-qpr...
[android-x86/system-bt.git] / bta / dm / bta_dm_int.h
1 /******************************************************************************
2  *
3  *  Copyright 2003-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 is the private interface file for the BTA device manager.
22  *
23  ******************************************************************************/
24 #ifndef BTA_DM_INT_H
25 #define BTA_DM_INT_H
26
27 #include <memory>
28 #include "bt_target.h"
29 #include "bta/sys/bta_sys.h"
30
31 #include "bta/include/bta_gatt_api.h"
32
33 /*****************************************************************************
34  *  Constants and data types
35  ****************************************************************************/
36
37 #define BTA_COPY_DEVICE_CLASS(coddst, codsrc)          \
38   {                                                    \
39     ((uint8_t*)(coddst))[0] = ((uint8_t*)(codsrc))[0]; \
40     ((uint8_t*)(coddst))[1] = ((uint8_t*)(codsrc))[1]; \
41     ((uint8_t*)(coddst))[2] = ((uint8_t*)(codsrc))[2]; \
42   }
43
44 #define BTA_DM_MSG_LEN 50
45
46 #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
47
48 /* DM search events */
49 enum {
50   /* DM search API events */
51   BTA_DM_API_SEARCH_EVT = BTA_SYS_EVT_START(BTA_ID_DM_SEARCH),
52   BTA_DM_API_DISCOVER_EVT,
53   BTA_DM_INQUIRY_CMPL_EVT,
54   BTA_DM_REMT_NAME_EVT,
55   BTA_DM_SDP_RESULT_EVT,
56   BTA_DM_SEARCH_CMPL_EVT,
57   BTA_DM_DISCOVERY_RESULT_EVT,
58   BTA_DM_DISC_CLOSE_TOUT_EVT
59 };
60
61 /* data type for BTA_DM_API_SEARCH_EVT */
62 typedef struct {
63   BT_HDR hdr;
64   tBTA_SERVICE_MASK services;
65   tBTA_DM_SEARCH_CBACK* p_cback;
66 } tBTA_DM_API_SEARCH;
67
68 /* data type for BTA_DM_API_DISCOVER_EVT */
69 typedef struct {
70   BT_HDR hdr;
71   RawAddress bd_addr;
72   tBTA_DM_SEARCH_CBACK* p_cback;
73   tBT_TRANSPORT transport;
74 } tBTA_DM_API_DISCOVER;
75
76 typedef struct {
77   RawAddress bd_addr;
78   bool accept;
79   uint8_t pin_len;
80   uint8_t p_pin[PIN_CODE_LEN];
81 } tBTA_DM_API_PIN_REPLY;
82
83 typedef struct {
84   BT_HDR hdr;
85   RawAddress bd_addr;
86   tBTM_IO_CAP io_cap;
87   tBTM_OOB_DATA oob_data;
88   tBTM_AUTH_REQ auth_req;
89 } tBTA_DM_CI_IO_REQ;
90
91 typedef struct {
92   RawAddress bd_addr;
93   Octet16 c;
94   Octet16 r;
95   bool accept;
96 } tBTA_DM_CI_RMT_OOB;
97
98 /* data type for BTA_DM_REMT_NAME_EVT */
99 typedef struct {
100   BT_HDR hdr;
101   tBTA_DM_SEARCH result;
102 } tBTA_DM_REM_NAME;
103
104 /* data type for tBTA_DM_DISC_RESULT */
105 typedef struct {
106   BT_HDR hdr;
107   tBTA_DM_SEARCH result;
108 } tBTA_DM_DISC_RESULT;
109
110 /* data type for BTA_DM_INQUIRY_CMPL_EVT */
111 typedef struct {
112   BT_HDR hdr;
113   uint8_t num;
114 } tBTA_DM_INQUIRY_CMPL;
115
116 /* data type for BTA_DM_SDP_RESULT_EVT */
117 typedef struct {
118   BT_HDR hdr;
119   uint16_t sdp_result;
120 } tBTA_DM_SDP_RESULT;
121
122 typedef struct {
123   RawAddress bd_addr;
124   DEV_CLASS dc;
125   LinkKey link_key;
126   uint8_t key_type;
127   bool link_key_known;
128   bool dc_known;
129   BD_NAME bd_name;
130   uint8_t pin_length;
131 } tBTA_DM_API_ADD_DEVICE;
132
133 typedef struct {
134   BT_HDR hdr;
135   bool enable;
136 } tBTA_DM_API_BLE_FEATURE;
137
138 /* union of all data types */
139 typedef union {
140   /* GKI event buffer header */
141   BT_HDR hdr;
142
143   tBTA_DM_API_SEARCH search;
144
145   tBTA_DM_API_DISCOVER discover;
146
147   tBTA_DM_REM_NAME rem_name;
148
149   tBTA_DM_DISC_RESULT disc_result;
150
151   tBTA_DM_INQUIRY_CMPL inq_cmpl;
152
153   tBTA_DM_SDP_RESULT sdp_event;
154
155 } tBTA_DM_MSG;
156
157 #define BTA_DM_NUM_PEER_DEVICE 7
158
159 #define BTA_DM_NOT_CONNECTED 0
160 #define BTA_DM_CONNECTED 1
161 #define BTA_DM_UNPAIRING 2
162 typedef uint8_t tBTA_DM_CONN_STATE;
163
164 #define BTA_DM_DI_NONE 0x00 /* nothing special */
165 #define BTA_DM_DI_USE_SSR \
166   0x10 /* set this bit if ssr is supported for this link */
167 #define BTA_DM_DI_AV_ACTIVE \
168   0x20 /* set this bit if AV is active for this link */
169 #define BTA_DM_DI_SET_SNIFF \
170   0x01 /* set this bit if call BTM_SetPowerMode(sniff) */
171 #define BTA_DM_DI_INT_SNIFF \
172   0x02 /* set this bit if call BTM_SetPowerMode(sniff) & enter sniff mode */
173 #define BTA_DM_DI_ACP_SNIFF 0x04 /* set this bit if peer init sniff */
174 typedef uint8_t tBTA_DM_DEV_INFO;
175
176 /* set power mode request type */
177 #define BTA_DM_PM_RESTART 1
178 #define BTA_DM_PM_NEW_REQ 2
179 #define BTA_DM_PM_EXECUTE 3
180 typedef uint8_t tBTA_DM_PM_REQ;
181
182 typedef struct {
183   RawAddress peer_bdaddr;
184   tBTA_DM_CONN_STATE conn_state;
185   tBTA_PREF_ROLES pref_role;
186   bool in_use;
187   tBTA_DM_DEV_INFO info;
188   tBTA_DM_ENCRYPT_CBACK* p_encrypt_cback;
189   tBTM_PM_STATUS prev_low; /* previous low power mode used */
190   tBTA_DM_PM_ACTION pm_mode_attempted;
191   tBTA_DM_PM_ACTION pm_mode_failed;
192   bool remove_dev_pending;
193   tBT_TRANSPORT transport;
194 } tBTA_DM_PEER_DEVICE;
195
196 /* structure to store list of
197   active connections */
198 typedef struct {
199   tBTA_DM_PEER_DEVICE peer_device[BTA_DM_NUM_PEER_DEVICE];
200   uint8_t count;
201   uint8_t le_count;
202 } tBTA_DM_ACTIVE_LINK;
203
204 typedef struct {
205   RawAddress peer_bdaddr;
206   tBTA_SYS_ID id;
207   uint8_t app_id;
208   tBTA_SYS_CONN_STATUS state;
209   bool new_request;
210
211 } tBTA_DM_SRVCS;
212
213 #ifndef BTA_DM_NUM_CONN_SRVS
214 #define BTA_DM_NUM_CONN_SRVS 30
215 #endif
216
217 typedef struct {
218   uint8_t count;
219   tBTA_DM_SRVCS conn_srvc[BTA_DM_NUM_CONN_SRVS];
220
221 } tBTA_DM_CONNECTED_SRVCS;
222
223 typedef struct {
224 #define BTA_DM_PM_SNIFF_TIMER_IDX 0
225 #define BTA_DM_PM_PARK_TIMER_IDX 1
226 #define BTA_DM_PM_SUSPEND_TIMER_IDX 2
227 #define BTA_DM_PM_MODE_TIMER_MAX 3
228   /*
229    * Keep three different timers for PARK, SNIFF and SUSPEND if TBFC is
230    * supported.
231    */
232   alarm_t* timer[BTA_DM_PM_MODE_TIMER_MAX];
233
234   uint8_t srvc_id[BTA_DM_PM_MODE_TIMER_MAX];
235   uint8_t pm_action[BTA_DM_PM_MODE_TIMER_MAX];
236   uint8_t active; /* number of active timer */
237
238   RawAddress peer_bdaddr;
239   bool in_use;
240 } tBTA_PM_TIMER;
241
242 extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
243
244 #define BTA_DM_NUM_PM_TIMER 7
245
246 /* DM control block */
247 typedef struct {
248   bool is_bta_dm_active;
249   tBTA_DM_ACTIVE_LINK device_list;
250   tBTA_DM_SEC_CBACK* p_sec_cback;
251   tBTA_BLE_ENERGY_INFO_CBACK* p_energy_info_cback;
252   uint16_t state;
253   bool disabling;
254   alarm_t* disable_timer;
255   uint32_t wbt_sdp_handle; /* WIDCOMM Extensions SDP record handle */
256   uint8_t wbt_scn;         /* WIDCOMM Extensions SCN */
257   uint8_t num_central_only;
258   uint8_t pm_id;
259   tBTA_PM_TIMER pm_timer[BTA_DM_NUM_PM_TIMER];
260   uint8_t cur_av_count;   /* current AV connecions */
261   bool disable_pair_mode; /* disable pair mode or not */
262   bool conn_paired_only;  /* allow connectable to paired device only or not */
263   tBTA_DM_API_SEARCH search_msg;
264
265   /* Storage for pin code request parameters */
266   RawAddress pin_bd_addr;
267   DEV_CLASS pin_dev_class;
268   tBTA_DM_SEC_EVT pin_evt;
269   tBTM_IO_CAP loc_io_caps;    /* IO Capabilities of local device */
270   tBTM_IO_CAP rmt_io_caps;    /* IO Capabilities of remote device */
271   tBTM_AUTH_REQ loc_auth_req; /* Authentication required for local device */
272   tBTM_AUTH_REQ rmt_auth_req;
273   uint32_t num_val; /* the numeric value for comparison. If just_works, do not
274                        show this number to UI */
275   bool just_works;  /* true, if "Just Works" association model */
276 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
277   /* store UUID list for EIR */
278   uint32_t eir_uuid[BTM_EIR_SERVICE_ARRAY_SIZE];
279 #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0)
280   tBTA_CUSTOM_UUID bta_custom_uuid[BTA_EIR_SERVER_NUM_CUSTOM_UUID];
281 #endif
282
283 #endif
284
285   tBTA_DM_ENCRYPT_CBACK* p_encrypt_cback;
286   alarm_t* switch_delay_timer;
287
288 } tBTA_DM_CB;
289
290 /* DM search control block */
291 typedef struct {
292   tBTA_DM_SEARCH_CBACK* p_search_cback;
293   tBTM_INQ_INFO* p_btm_inq_info;
294   tBTA_SERVICE_MASK services;
295   tBTA_SERVICE_MASK services_to_search;
296   tBTA_SERVICE_MASK services_found;
297   tSDP_DISCOVERY_DB* p_sdp_db;
298   uint16_t state;
299   RawAddress peer_bdaddr;
300   bool name_discover_done;
301   BD_NAME peer_name;
302   alarm_t* search_timer;
303   uint8_t service_index;
304   tBTA_DM_MSG* p_pending_search;
305   tBTA_DM_MSG* p_pending_discovery;
306   bool wait_disc;
307   bool sdp_results;
308   bluetooth::Uuid uuid;
309   uint8_t peer_scn;
310   tBT_TRANSPORT transport;
311   tBTA_DM_SEARCH_CBACK* p_scan_cback;
312   tGATT_IF client_if;
313   uint8_t uuid_to_search;
314   bool gatt_disc_active;
315   uint16_t conn_id;
316   alarm_t* gatt_close_timer; /* GATT channel close delay timer */
317   RawAddress pending_close_bda; /* pending GATT channel remote device address */
318
319 } tBTA_DM_SEARCH_CB;
320
321 /* DI control block */
322 typedef struct {
323   uint8_t di_num;                     /* total local DI record number */
324   uint32_t di_handle[BTA_DI_NUM_MAX]; /* local DI record handle, the first one
325                                          is primary record */
326 } tBTA_DM_DI_CB;
327
328 /* DM search state */
329 enum {
330
331   BTA_DM_SEARCH_IDLE,
332   BTA_DM_SEARCH_ACTIVE,
333   BTA_DM_SEARCH_CANCELLING,
334   BTA_DM_DISCOVER_ACTIVE
335
336 };
337
338 typedef struct {
339   DEV_CLASS dev_class; /* local device class */
340   uint16_t page_timeout; /* timeout for page in slots */
341   uint16_t link_timeout; /* link supervision timeout in slots */
342   bool avoid_scatter; /* true to avoid scatternet when av is streaming (be the
343                          central) */
344
345 } tBTA_DM_CFG;
346
347 extern const uint32_t bta_service_id_to_btm_srv_id_lkup_tbl[];
348
349 typedef struct {
350   uint8_t id;
351   uint8_t app_id;
352   uint8_t cfg;
353
354 } tBTA_DM_RM;
355
356 extern const tBTA_DM_CFG* p_bta_dm_cfg;
357 extern const tBTA_DM_RM* p_bta_dm_rm_cfg;
358
359 typedef struct {
360   uint8_t id;
361   uint8_t app_id;
362   uint8_t spec_idx; /* index of spec table to use */
363
364 } tBTA_DM_PM_CFG;
365
366 typedef struct {
367   tBTA_DM_PM_ACTION power_mode;
368   uint16_t timeout;
369
370 } tBTA_DM_PM_ACTN;
371
372 typedef struct {
373   uint8_t allow_mask; /* mask of sniff/hold/park modes to allow */
374   uint8_t ssr; /* set SSR on conn open/unpark */
375   tBTA_DM_PM_ACTN actn_tbl[BTA_DM_PM_NUM_EVTS][2];
376
377 } tBTA_DM_PM_SPEC;
378
379 typedef struct {
380   uint16_t max_lat;
381   uint16_t min_rmt_to;
382   uint16_t min_loc_to;
383 } tBTA_DM_SSR_SPEC;
384
385 typedef struct {
386   uint16_t manufacturer;
387   uint16_t lmp_sub_version;
388   uint8_t lmp_version;
389 } tBTA_DM_LMP_VER_INFO;
390
391 extern const uint16_t bta_service_id_to_uuid_lkup_tbl[];
392
393 extern const tBTA_DM_PM_CFG* p_bta_dm_pm_cfg;
394 extern const tBTA_DM_PM_SPEC* p_bta_dm_pm_spec;
395 extern const tBTM_PM_PWR_MD* p_bta_dm_pm_md;
396 extern tBTA_DM_SSR_SPEC* p_bta_dm_ssr_spec;
397
398 /* update dynamic BRCM Aware EIR data */
399 extern const tBTA_DM_EIR_CONF bta_dm_eir_cfg;
400 extern const tBTA_DM_EIR_CONF* p_bta_dm_eir_cfg;
401
402 /* DM control block */
403 extern tBTA_DM_CB bta_dm_cb;
404
405 /* DM search control block */
406 extern tBTA_DM_SEARCH_CB bta_dm_search_cb;
407
408 /* DI control block */
409 extern tBTA_DM_DI_CB bta_dm_di_cb;
410
411 extern bool bta_dm_search_sm_execute(BT_HDR* p_msg);
412 extern void bta_dm_search_sm_disable(void);
413
414 extern void bta_dm_enable(tBTA_DM_SEC_CBACK*);
415 extern void bta_dm_disable();
416 extern void bta_dm_init_cb(void);
417 extern void bta_dm_set_dev_name(const std::vector<uint8_t>&);
418 extern void bta_dm_set_visibility(tBTA_DM_DISC, tBTA_DM_CONN);
419 extern void bta_dm_set_scan_config(tBTA_DM_MSG* p_data);
420 extern void bta_dm_vendor_spec_command(tBTA_DM_MSG* p_data);
421 extern void bta_dm_bond(const RawAddress&, tBLE_ADDR_TYPE, tBT_TRANSPORT, int);
422 extern void bta_dm_bond_cancel(const RawAddress&);
423 extern void bta_dm_pin_reply(std::unique_ptr<tBTA_DM_API_PIN_REPLY> msg);
424 extern void bta_dm_add_device(std::unique_ptr<tBTA_DM_API_ADD_DEVICE> msg);
425 extern void bta_dm_remove_device(const RawAddress& bd_addr);
426 extern void bta_dm_close_acl(const RawAddress&, bool, tBT_TRANSPORT);
427
428 extern void bta_dm_pm_btm_status(const RawAddress&, tBTM_PM_STATUS, uint16_t,
429                                  uint8_t);
430 extern void bta_dm_pm_timer(const RawAddress&, tBTA_DM_PM_ACTION);
431 extern void bta_dm_add_ampkey(tBTA_DM_MSG* p_data);
432
433 extern void bta_dm_add_blekey(const RawAddress& bd_addr,
434                               tBTA_LE_KEY_VALUE blekey,
435                               tBTM_LE_KEY_TYPE key_type);
436 extern void bta_dm_add_ble_device(const RawAddress& bd_addr,
437                                   tBLE_ADDR_TYPE addr_type,
438                                   tBT_DEVICE_TYPE dev_type);
439 extern void bta_dm_ble_passkey_reply(const RawAddress& bd_addr, bool accept,
440                                      uint32_t passkey);
441 extern void bta_dm_ble_confirm_reply(const RawAddress&, bool);
442 extern void bta_dm_ble_set_conn_params(const RawAddress&, uint16_t, uint16_t,
443                                        uint16_t, uint16_t);
444 extern void bta_dm_close_gatt_conn(tBTA_DM_MSG* p_data);
445 extern void bta_dm_ble_observe(bool, uint8_t, tBTA_DM_SEARCH_CBACK*);
446 extern void bta_dm_ble_update_conn_params(const RawAddress&, uint16_t, uint16_t,
447                                           uint16_t, uint16_t, uint16_t,
448                                           uint16_t);
449 extern void bta_dm_ble_config_local_privacy(bool);
450
451 extern void bta_dm_ble_set_data_length(const RawAddress&, uint16_t);
452
453 extern void bta_dm_ble_get_energy_info(tBTA_BLE_ENERGY_INFO_CBACK*);
454
455 extern void bta_dm_set_encryption(const RawAddress&, tBT_TRANSPORT,
456                                   tBTA_DM_ENCRYPT_CBACK*, tBTM_BLE_SEC_ACT);
457 extern void bta_dm_confirm(const RawAddress&, bool);
458
459 extern void bta_dm_ci_rmt_oob_act(std::unique_ptr<tBTA_DM_CI_RMT_OOB> msg);
460
461 extern void bta_dm_init_pm(void);
462 extern void bta_dm_disable_pm(void);
463
464 extern uint8_t bta_dm_get_av_count(void);
465 extern void bta_dm_search_start(tBTA_DM_MSG* p_data);
466 extern void bta_dm_search_cancel();
467 extern void bta_dm_discover(tBTA_DM_MSG* p_data);
468 extern void bta_dm_inq_cmpl(uint8_t num);
469 extern void bta_dm_rmt_name(tBTA_DM_MSG* p_data);
470 extern void bta_dm_sdp_result(tBTA_DM_MSG* p_data);
471 extern void bta_dm_search_cmpl();
472 extern void bta_dm_free_sdp_db();
473 extern void bta_dm_disc_result(tBTA_DM_MSG* p_data);
474 extern void bta_dm_search_result(tBTA_DM_MSG* p_data);
475 extern void bta_dm_discovery_cmpl(tBTA_DM_MSG* p_data);
476 extern void bta_dm_queue_search(tBTA_DM_MSG* p_data);
477 extern void bta_dm_queue_disc(tBTA_DM_MSG* p_data);
478 extern void bta_dm_search_clear_queue();
479 extern void bta_dm_search_cancel_cmpl();
480 extern void bta_dm_search_cancel_notify();
481 extern void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data);
482 extern tBTA_DM_PEER_DEVICE* bta_dm_find_peer_device(
483     const RawAddress& peer_addr);
484
485 uint8_t bta_dm_search_get_state();
486 void bta_dm_search_set_state(uint8_t state);
487
488 void bta_dm_eir_update_uuid(uint16_t uuid16, bool adding);
489 void bta_dm_eir_update_cust_uuid(const tBTA_CUSTOM_UUID &curr, bool adding);
490 #endif /* BTA_DM_INT_H */