blob: abf52bfeac7c1c4f868f358849c1ea487e07b280 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2009-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#include <stdio.h>
19#include <stdlib.h>
20
21#include "bta_api.h"
22#include "bta_sys.h"
23#include "bta_dm_co.h"
24#include "bta_dm_ci.h"
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080025#include "bt_utils.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080026#if (BTM_OOB_INCLUDED == TRUE)
27#include "btif_dm.h"
28#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080029#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
30#include "bte_appl.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080031
32tBTE_APPL_CFG bte_appl_cfg = { 0x5, 0x4, 0x7, 0x7, 0x10 };
Matthew Xiefc4b2f12013-05-06 20:51:02 -070033#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080034
The Android Open Source Project5738f832012-12-12 16:00:35 -080035/*******************************************************************************
36**
37** Function bta_dm_co_get_compress_memory
38**
39** Description This callout function is executed by DM to get memory for compression
40
41** Parameters id - BTA SYS ID
42** memory_p - memory return by callout
43** memory_size - memory size
44**
45** Returns TRUE for success, FALSE for fail.
46**
47*******************************************************************************/
48BOOLEAN bta_dm_co_get_compress_memory(tBTA_SYS_ID id, UINT8 **memory_p, UINT32 *memory_size)
49{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080050 UNUSED(id);
51 UNUSED(memory_p);
52 UNUSED(memory_size);
The Android Open Source Project5738f832012-12-12 16:00:35 -080053 return TRUE;
54}
55
56/*******************************************************************************
57**
58** Function bta_dm_co_io_req
59**
60** Description This callout function is executed by DM to get IO capabilities
61** of the local device for the Simple Pairing process
62**
63** Parameters bd_addr - The peer device
64** *p_io_cap - The local Input/Output capabilities
65** *p_oob_data - TRUE, if OOB data is available for the peer device.
66** *p_auth_req - TRUE, if MITM protection is required.
67**
68** Returns void.
69**
70*******************************************************************************/
71void bta_dm_co_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
72 tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
73{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -080074 UNUSED(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -080075#if (BTM_OOB_INCLUDED == TRUE)
76 btif_dm_set_oob_for_io_req(p_oob_data);
77#endif
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -070078 btif_dm_proc_io_req(bd_addr, p_io_cap, p_oob_data, p_auth_req, is_orig);
The Android Open Source Project5738f832012-12-12 16:00:35 -080079 BTIF_TRACE_DEBUG1("bta_dm_co_io_req *p_oob_data = %d", *p_oob_data);
80 BTIF_TRACE_DEBUG1("bta_dm_co_io_req *p_io_cap = %d", *p_io_cap);
81 BTIF_TRACE_DEBUG1("bta_dm_co_io_req *p_auth_req = %d", *p_auth_req);
82 BTIF_TRACE_DEBUG1("bta_dm_co_io_req is_orig = %d", is_orig);
83}
84
85/*******************************************************************************
86**
87** Function bta_dm_co_io_rsp
88**
89** Description This callout function is executed by DM to report IO capabilities
90** of the peer device for the Simple Pairing process
91**
92** Parameters bd_addr - The peer device
93** io_cap - The remote Input/Output capabilities
94** oob_data - TRUE, if OOB data is available for the peer device.
95** auth_req - TRUE, if MITM protection is required.
96**
97** Returns void.
98**
99*******************************************************************************/
100void bta_dm_co_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
101 tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
102{
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -0700103 btif_dm_proc_io_rsp(bd_addr, io_cap, oob_data, auth_req);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800104}
105
106/*******************************************************************************
107**
108** Function bta_dm_co_lk_upgrade
109**
110** Description This callout function is executed by DM to check if the
111** platform wants allow link key upgrade
112**
113** Parameters bd_addr - The peer device
114** *p_upgrade - TRUE, if link key upgrade is desired.
115**
116** Returns void.
117**
118*******************************************************************************/
119void bta_dm_co_lk_upgrade(BD_ADDR bd_addr, BOOLEAN *p_upgrade )
120{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800121 UNUSED(bd_addr);
122 UNUSED(p_upgrade);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800123}
124
125#if (BTM_OOB_INCLUDED == TRUE)
126/*******************************************************************************
127**
128** Function bta_dm_co_loc_oob
129**
130** Description This callout function is executed by DM to report the OOB
131** data of the local device for the Simple Pairing process
132**
133** Parameters valid - TRUE, if the local OOB data is retrieved from LM
134** c - Simple Pairing Hash C
135** r - Simple Pairing Randomnizer R
136**
137** Returns void.
138**
139*******************************************************************************/
140void bta_dm_co_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
141{
142 BTIF_TRACE_DEBUG1("bta_dm_co_loc_oob, valid = %d", valid);
143#ifdef BTIF_DM_OOB_TEST
144 btif_dm_proc_loc_oob(valid, c, r);
145#endif
146}
147
148/*******************************************************************************
149**
150** Function bta_dm_co_rmt_oob
151**
152** Description This callout function is executed by DM to request the OOB
153** data for the remote device for the Simple Pairing process
154** Need to call bta_dm_ci_rmt_oob() in response
155**
156** Parameters bd_addr - The peer device
157**
158** Returns void.
159**
160*******************************************************************************/
161void bta_dm_co_rmt_oob(BD_ADDR bd_addr)
162{
163 BT_OCTET16 p_c;
164 BT_OCTET16 p_r;
165 BOOLEAN result = FALSE;
166
167#ifdef BTIF_DM_OOB_TEST
168 result = btif_dm_proc_rmt_oob(bd_addr, p_c, p_r);
169#endif
170
171 BTIF_TRACE_DEBUG1("bta_dm_co_rmt_oob: result=%d",result);
172 bta_dm_ci_rmt_oob(result, bd_addr, p_c, p_r);
173}
174
175#endif /* BTM_OOB_INCLUDED */
176
177
178// REMOVE FOR BLUEDROID ?
179
180#if (BTM_SCO_HCI_INCLUDED == TRUE ) && (BTM_SCO_INCLUDED == TRUE)
181
182/*******************************************************************************
183**
184** Function btui_sco_codec_callback
185**
186** Description Callback for btui codec.
187**
188**
189** Returns void
190**
191*******************************************************************************/
192static void btui_sco_codec_callback(UINT16 event, UINT16 sco_handle)
193{
194 bta_dm_sco_ci_data_ready(event, sco_handle);
195}
196/*******************************************************************************
197**
198** Function bta_dm_sco_co_init
199**
200** Description This function can be used by the phone to initialize audio
201** codec or for other initialization purposes before SCO connection
202** is opened.
203**
204**
205** Returns tBTA_DM_SCO_ROUTE_TYPE: SCO routing configuration type.
206**
207*******************************************************************************/
208tBTA_DM_SCO_ROUTE_TYPE bta_dm_sco_co_init(UINT32 rx_bw, UINT32 tx_bw,
209 tBTA_CODEC_INFO * p_codec_type, UINT8 app_id)
210{
211 tBTM_SCO_ROUTE_TYPE route = BTA_DM_SCO_ROUTE_PCM;
212
213 BTIF_TRACE_DEBUG0("bta_dm_sco_co_init");
214
215 /* set up SCO routing configuration if SCO over HCI app ID is used and run time
216 configuration is set to SCO over HCI */
217 /* HS invoke this call-out */
218 if (
219#if (BTA_HS_INCLUDED == TRUE ) && (BTA_HS_INCLUDED == TRUE)
220 (app_id == BTUI_DM_SCO_4_HS_APP_ID && btui_cfg.hs_sco_over_hci) ||
221#endif
222 /* AG invoke this call-out */
223 (app_id != BTUI_DM_SCO_4_HS_APP_ID && btui_cfg.ag_sco_over_hci ))
224 {
225 route = btui_cb.sco_hci = BTA_DM_SCO_ROUTE_HCI;
226 }
227 /* no codec is is used for the SCO data */
228 if (p_codec_type->codec_type == BTA_SCO_CODEC_PCM && route == BTA_DM_SCO_ROUTE_HCI)
229 {
230 /* initialize SCO codec */
231 if (!btui_sco_codec_init(rx_bw, tx_bw))
232 {
233 BTIF_TRACE_ERROR0("codec initialization exception!");
234 }
235 }
236
237 return route;
238}
239
240
241
242/*******************************************************************************
243**
244** Function bta_dm_sco_co_open
245**
246** Description This function is executed when a SCO connection is open.
247**
248**
249** Returns void
250**
251*******************************************************************************/
252void bta_dm_sco_co_open(UINT16 handle, UINT8 pkt_size, UINT16 event)
253{
254 tBTUI_SCO_CODEC_CFG cfg;
255
256 if (btui_cb.sco_hci)
257 {
258 BTIF_TRACE_DEBUG2("bta_dm_sco_co_open handle:%d pkt_size:%d", handle, pkt_size);
259 /* use dedicated SCO buffer pool for SCO TX data */
260 cfg.pool_id = HCI_SCO_POOL_ID;
261 cfg.p_cback = btui_sco_codec_callback;
262 cfg.pkt_size = pkt_size;
263 cfg.cb_event = event;
264 /* open and start the codec */
265 btui_sco_codec_open(&cfg);
266 btui_sco_codec_start(handle);
267 }
268}
269
270/*******************************************************************************
271**
272** Function bta_dm_sco_co_close
273**
274** Description This function is called when a SCO connection is closed
275**
276**
277** Returns void
278**
279*******************************************************************************/
280void bta_dm_sco_co_close(void)
281{
282 if (btui_cb.sco_hci)
283 {
284 BTIF_TRACE_DEBUG0("bta_dm_sco_co_close close codec");
285 /* close sco codec */
286 btui_sco_codec_close();
287
288 btui_cb.sco_hci = FALSE;
289 }
290}
291
292/*******************************************************************************
293**
294** Function bta_dm_sco_co_in_data
295**
296** Description This function is called to send incoming SCO data to application.
297**
298** Returns void
299**
300*******************************************************************************/
301void bta_dm_sco_co_in_data(BT_HDR *p_buf)
302{
303 if (btui_cfg.sco_use_mic)
304 btui_sco_codec_inqdata (p_buf);
305 else
306 GKI_freebuf(p_buf);
307}
308
309/*******************************************************************************
310**
311** Function bta_dm_sco_co_out_data
312**
313** Description This function is called to send SCO data over HCI.
314**
315** Returns void
316**
317*******************************************************************************/
318void bta_dm_sco_co_out_data(BT_HDR **p_buf)
319{
320 btui_sco_codec_readbuf(p_buf);
321}
322
323#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) && (BTM_SCO_INCLUDED == TRUE)*/
324
325
326#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
327/*******************************************************************************
328**
329** Function bta_dm_co_le_io_key_req
330**
331** Description This callout function is executed by DM to get BLE key information
332** before SMP pairing gets going.
333**
334** Parameters bd_addr - The peer device
335** *p_max_key_size - max key size local device supported.
336** *p_init_key - initiator keys.
337** *p_resp_key - responder keys.
338**
339** Returns void.
340**
341*******************************************************************************/
342void bta_dm_co_le_io_key_req(BD_ADDR bd_addr, UINT8 *p_max_key_size,
343 tBTA_LE_KEY_TYPE *p_init_key,
344 tBTA_LE_KEY_TYPE *p_resp_key )
345{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800346 UNUSED(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800347 BTIF_TRACE_ERROR0("##################################");
348 BTIF_TRACE_ERROR0("bta_dm_co_le_io_key_req: only setting max size to 16");
349 BTIF_TRACE_ERROR0("##################################");
350 *p_max_key_size = 16;
351 *p_init_key = *p_resp_key =
352 (BTA_LE_KEY_PENC|BTA_LE_KEY_PID|BTA_LE_KEY_PCSRK|BTA_LE_KEY_LENC|BTA_LE_KEY_LID|BTA_LE_KEY_LCSRK);
353}
354
355
356/*******************************************************************************
357**
358** Function bta_dm_co_ble_local_key_reload
359**
360** Description This callout function is to load the local BLE keys if available
361** on the device.
362**
363** Parameters none
364**
365** Returns void.
366**
367*******************************************************************************/
368void bta_dm_co_ble_load_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
369 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
370{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800371 BTIF_TRACE_DEBUG0("##################################");
372 BTIF_TRACE_DEBUG0("bta_dm_co_ble_load_local_keys: Load local keys if any are persisted");
373 BTIF_TRACE_DEBUG0("##################################");
374 btif_dm_get_ble_local_keys( p_key_mask, er, p_id_keys);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800375}
376
377/*******************************************************************************
378**
379** Function bta_dm_co_ble_io_req
380**
381** Description This callout function is executed by DM to get BLE IO capabilities
382** before SMP pairing gets going.
383**
384** Parameters bd_addr - The peer device
385** *p_io_cap - The local Input/Output capabilities
386** *p_oob_data - TRUE, if OOB data is available for the peer device.
387** *p_auth_req - Auth request setting (Bonding and MITM required or not)
388** *p_max_key_size - max key size local device supported.
389** *p_init_key - initiator keys.
390** *p_resp_key - responder keys.
391**
392** Returns void.
393**
394*******************************************************************************/
395void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap,
396 tBTA_OOB_DATA *p_oob_data,
397 tBTA_LE_AUTH_REQ *p_auth_req,
398 UINT8 *p_max_key_size,
399 tBTA_LE_KEY_TYPE *p_init_key,
400 tBTA_LE_KEY_TYPE *p_resp_key )
401{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -0800402 UNUSED(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800403 /* if OOB is not supported, this call-out function does not need to do anything
404 * otherwise, look for the OOB data associated with the address and set *p_oob_data accordingly
405 * If the answer can not be obtained right away,
406 * set *p_oob_data to BTA_OOB_UNKNOWN and call bta_dm_ci_io_req() when the answer is available */
407
The Android Open Source Project5738f832012-12-12 16:00:35 -0800408 *p_oob_data = FALSE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800409
410 /* *p_auth_req by default is FALSE for devices with NoInputNoOutput; TRUE for other devices. */
411
The Android Open Source Project5738f832012-12-12 16:00:35 -0800412 if (bte_appl_cfg.ble_auth_req)
413 *p_auth_req = bte_appl_cfg.ble_auth_req | (bte_appl_cfg.ble_auth_req & 0x04) | ((*p_auth_req) & 0x04);
414
415 if (bte_appl_cfg.ble_io_cap <=4)
416 *p_io_cap = bte_appl_cfg.ble_io_cap;
417
418 if (bte_appl_cfg.ble_init_key<=7)
419 *p_init_key = bte_appl_cfg.ble_init_key;
420
421 if (bte_appl_cfg.ble_resp_key<=7)
422 *p_resp_key = bte_appl_cfg.ble_resp_key;
423
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800424 if (bte_appl_cfg.ble_max_key_size > 7 && bte_appl_cfg.ble_max_key_size <= 16)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800425 *p_max_key_size = bte_appl_cfg.ble_max_key_size;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800426}
427
428
429#endif
430