The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2009-2012 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 | |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 19 | /******************************************************************************* |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 20 | * |
| 21 | * Filename: bluetooth.c |
| 22 | * |
| 23 | * Description: Bluetooth HAL implementation |
| 24 | * |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 25 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 26 | |
Andre Eisenbach | b7a077b | 2015-10-29 11:18:20 -0700 | [diff] [blame] | 27 | #define LOG_TAG "bt_btif" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 28 | |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 29 | #include <base/logging.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
Scott James Remnant | 933926c | 2015-04-02 15:22:14 -0700 | [diff] [blame] | 32 | #include <string.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 33 | #include <unistd.h> |
| 34 | |
| 35 | #include <hardware/bluetooth.h> |
Jack He | 12a576d | 2017-12-14 15:00:39 -0800 | [diff] [blame] | 36 | #include <hardware/bluetooth_headset_interface.h> |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 37 | #include <hardware/bt_av.h> |
| 38 | #include <hardware/bt_gatt.h> |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 39 | #include <hardware/bt_hd.h> |
Jakub Pawlowski | 89b0ccb | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 40 | #include <hardware/bt_hearing_aid.h> |
Hemant Gupta | 41d4a26 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 41 | #include <hardware/bt_hf_client.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | #include <hardware/bt_hh.h> |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 43 | #include <hardware/bt_mce.h> |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 44 | #include <hardware/bt_pan.h> |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 45 | #include <hardware/bt_rc.h> |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 46 | #include <hardware/bt_sdp.h> |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 47 | #include <hardware/bt_sock.h> |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 48 | |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 49 | #include "bt_utils.h" |
Hansong Zhang | b596bb1 | 2018-05-09 14:39:56 -0700 | [diff] [blame] | 50 | #include "bta/include/bta_hearing_aid_api.h" |
Sanket Agarwal | 5eccd90 | 2016-11-30 19:43:47 -0800 | [diff] [blame] | 51 | #include "bta/include/bta_hf_client_api.h" |
Jakub Pawlowski | 9e81461 | 2018-05-25 09:31:26 -0700 | [diff] [blame] | 52 | #include "btif/avrcp/avrcp_service.h" |
Pavlin Radoslavov | 08406e9 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 53 | #include "btif_a2dp.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 54 | #include "btif_api.h" |
Pavlin Radoslavov | d752229 | 2017-11-24 19:12:11 -0800 | [diff] [blame] | 55 | #include "btif_av.h" |
Ray | 6e63247 | 2019-01-03 21:19:16 +0800 | [diff] [blame] | 56 | #include "btif_bqr.h" |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 57 | #include "btif_config.h" |
Andre Eisenbach | 89f5e41 | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 58 | #include "btif_debug.h" |
Jack He | 12a576d | 2017-12-14 15:00:39 -0800 | [diff] [blame] | 59 | #include "btif_debug_btsnoop.h" |
| 60 | #include "btif_debug_conn.h" |
| 61 | #include "btif_hf.h" |
weichinweng | b30bb98 | 2020-04-21 09:42:27 +0800 | [diff] [blame] | 62 | #include "btif_keystore.h" |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 63 | #include "btif_storage.h" |
Zach Johnson | 9891f32 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 64 | #include "btsnoop.h" |
Andre Eisenbach | 89f5e41 | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 65 | #include "btsnoop_mem.h" |
Jack He | 78b69d9 | 2018-11-16 02:59:43 -0800 | [diff] [blame] | 66 | #include "common/address_obfuscator.h" |
Chen Chen | 4f6a3b2 | 2020-03-05 15:02:46 -0800 | [diff] [blame] | 67 | #include "common/metric_id_allocator.h" |
Jack He | 959bc33 | 2018-08-15 12:38:37 -0700 | [diff] [blame] | 68 | #include "common/metrics.h" |
Andre Eisenbach | e42d1d7 | 2016-01-14 02:00:24 -0800 | [diff] [blame] | 69 | #include "device/include/interop.h" |
Chris Manton | 0cb19c8 | 2020-01-13 21:11:48 -0800 | [diff] [blame] | 70 | #include "main/shim/dumpsys.h" |
Chris Manton | a2a9faa | 2019-09-11 19:53:32 -0700 | [diff] [blame] | 71 | #include "main/shim/shim.h" |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 72 | #include "osi/include/alarm.h" |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 73 | #include "osi/include/allocation_tracker.h" |
Sharvil Nanavati | 4480276 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 74 | #include "osi/include/log.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 75 | #include "osi/include/osi.h" |
Pavlin Radoslavov | d2e2508 | 2015-08-24 16:29:21 -0700 | [diff] [blame] | 76 | #include "osi/include/wakelock.h" |
Jakub Pawlowski | 8ae68be | 2018-11-13 15:41:42 +0100 | [diff] [blame] | 77 | #include "stack/gatt/connection_manager.h" |
Zach Johnson | 8df0d80 | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 78 | #include "stack_manager.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 79 | |
Jakub Pawlowski | 89b0ccb | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 80 | using bluetooth::hearing_aid::HearingAidInterface; |
| 81 | |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 82 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 83 | * Static variables |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 84 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 85 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 86 | bt_callbacks_t* bt_hal_cbacks = NULL; |
Marie Janssen | b7f64bc | 2016-06-22 12:52:19 -0700 | [diff] [blame] | 87 | bool restricted_mode = false; |
weichinweng | 14b98e0 | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 88 | bool niap_mode = false; |
| 89 | const int CONFIG_COMPARE_ALL_PASS = 0b11; |
| 90 | int niap_config_compare_result = CONFIG_COMPARE_ALL_PASS; |
Rahul Sabnis | e198eb9 | 2020-07-31 19:44:27 -0700 | [diff] [blame] | 91 | bool is_local_device_atv = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 92 | |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 93 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 94 | * Externs |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 95 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 96 | |
| 97 | /* list all extended interfaces here */ |
| 98 | |
Hemant Gupta | 41d4a26 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 99 | /* handsfree profile - client */ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 100 | extern const bthf_client_interface_t* btif_hf_client_get_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 101 | /* advanced audio profile */ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 102 | extern const btav_source_interface_t* btif_av_get_src_interface(); |
| 103 | extern const btav_sink_interface_t* btif_av_get_sink_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 104 | /*rfc l2cap*/ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 105 | extern const btsock_interface_t* btif_sock_get_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 106 | /* hid host profile */ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 107 | extern const bthh_interface_t* btif_hh_get_interface(); |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 108 | /* hid device profile */ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 109 | extern const bthd_interface_t* btif_hd_get_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 110 | /*pan*/ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 111 | extern const btpan_interface_t* btif_pan_get_interface(); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 112 | /*map client*/ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 113 | extern const btmce_interface_t* btif_mce_get_interface(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 114 | /* gatt */ |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 115 | extern const btgatt_interface_t* btif_gatt_get_interface(); |
Mike Lockwood | 4ad470e | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 116 | /* avrc target */ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 117 | extern const btrc_interface_t* btif_rc_get_interface(); |
Mike Lockwood | 4ad470e | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 118 | /* avrc controller */ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 119 | extern const btrc_ctrl_interface_t* btif_rc_ctrl_get_interface(); |
Kim Schulz | 8372aa5 | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 120 | /*SDP search client*/ |
Jack He | ff99791 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 121 | extern const btsdp_interface_t* btif_sdp_get_interface(); |
Jakub Pawlowski | 89b0ccb | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 122 | /*Hearing Aid client*/ |
| 123 | extern HearingAidInterface* btif_hearing_aid_get_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 124 | |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 125 | /******************************************************************************* |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 126 | * Functions |
Myles Watson | ee96a3c | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 127 | ******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 128 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 129 | static bool interface_ready(void) { return bt_hal_cbacks != NULL; } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 130 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 131 | static bool is_profile(const char* p1, const char* p2) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 132 | CHECK(p1); |
| 133 | CHECK(p2); |
Andre Eisenbach | df5c69c | 2016-02-17 12:43:12 -0800 | [diff] [blame] | 134 | return strlen(p1) == strlen(p2) && strncmp(p1, p2, strlen(p2)) == 0; |
| 135 | } |
| 136 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 137 | /***************************************************************************** |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 138 | * |
| 139 | * BLUETOOTH HAL INTERFACE FUNCTIONS |
| 140 | * |
| 141 | ****************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 142 | |
Martin Brabham | 1a88ace | 2019-05-10 12:42:15 -0700 | [diff] [blame] | 143 | static int init(bt_callbacks_t* callbacks, bool start_restricted, |
Rahul Sabnis | e198eb9 | 2020-07-31 19:44:27 -0700 | [diff] [blame] | 144 | bool is_niap_mode, int config_compare_result, bool is_atv) { |
weichinweng | 14b98e0 | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 145 | LOG_INFO(LOG_TAG, |
| 146 | "%s: start restricted = %d ; niap = %d, config compare result = %d", |
| 147 | __func__, start_restricted, is_niap_mode, config_compare_result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 148 | |
Chris Manton | a2a9faa | 2019-09-11 19:53:32 -0700 | [diff] [blame] | 149 | if (bluetooth::shim::is_gd_shim_enabled()) { |
| 150 | LOG_INFO(LOG_TAG, "%s Enable Gd bluetooth functionality", __func__); |
| 151 | } else { |
| 152 | LOG_INFO(LOG_TAG, "%s Preserving legacy bluetooth functionality", __func__); |
| 153 | } |
| 154 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 155 | if (interface_ready()) return BT_STATUS_DONE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 156 | |
Sharvil Nanavati | c0745da | 2014-11-13 01:04:19 -0800 | [diff] [blame] | 157 | #ifdef BLUEDROID_DEBUG |
| 158 | allocation_tracker_init(); |
| 159 | #endif |
| 160 | |
Zach Johnson | 8df0d80 | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 161 | bt_hal_cbacks = callbacks; |
Martin Brabham | 1a88ace | 2019-05-10 12:42:15 -0700 | [diff] [blame] | 162 | restricted_mode = start_restricted; |
weichinweng | 14b98e0 | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 163 | niap_mode = is_niap_mode; |
| 164 | niap_config_compare_result = config_compare_result; |
Rahul Sabnis | e198eb9 | 2020-07-31 19:44:27 -0700 | [diff] [blame] | 165 | is_local_device_atv = is_atv; |
weichinweng | 14b98e0 | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 166 | |
Zach Johnson | 8df0d80 | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 167 | stack_manager_get_interface()->init_stack(); |
Andre Eisenbach | 89f5e41 | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 168 | btif_debug_init(); |
Zach Johnson | 8df0d80 | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 169 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Martin Brabham | 1a88ace | 2019-05-10 12:42:15 -0700 | [diff] [blame] | 172 | static int enable() { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 173 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 174 | |
Zach Johnson | 8df0d80 | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 175 | stack_manager_get_interface()->start_up_stack_async(); |
| 176 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Zach Johnson | 8df0d80 | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 179 | static int disable(void) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 180 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 181 | |
Zach Johnson | 8df0d80 | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 182 | stack_manager_get_interface()->shut_down_stack_async(); |
| 183 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 186 | static void cleanup(void) { stack_manager_get_interface()->clean_up_stack(); } |
| 187 | |
| 188 | bool is_restricted_mode() { return restricted_mode; } |
weichinweng | 14b98e0 | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 189 | bool is_niap_mode() { return niap_mode; } |
| 190 | // if niap mode disable, will always return CONFIG_COMPARE_ALL_PASS(0b11) |
| 191 | // indicate don't check config checksum. |
| 192 | int get_niap_config_compare_result() { |
| 193 | return niap_mode ? niap_config_compare_result : CONFIG_COMPARE_ALL_PASS; |
| 194 | } |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 195 | |
Rahul Sabnis | e198eb9 | 2020-07-31 19:44:27 -0700 | [diff] [blame] | 196 | bool is_atv_device() { return is_local_device_atv; } |
| 197 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 198 | static int get_adapter_properties(void) { |
| 199 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 200 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 201 | |
| 202 | return btif_get_adapter_properties(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 205 | static int get_adapter_property(bt_property_type_t type) { |
| 206 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 207 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 208 | |
| 209 | return btif_get_adapter_property(type); |
Ajay Panicker | 7b266be | 2016-03-17 17:09:24 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 212 | static int set_adapter_property(const bt_property_t* property) { |
| 213 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 214 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 215 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 216 | return btif_set_adapter_property(property); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 219 | int get_remote_device_properties(RawAddress* remote_addr) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 220 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 221 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 223 | return btif_get_remote_device_properties(remote_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 226 | int get_remote_device_property(RawAddress* remote_addr, |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 227 | bt_property_type_t type) { |
| 228 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 229 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 230 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 231 | return btif_get_remote_device_property(remote_addr, type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 234 | int set_remote_device_property(RawAddress* remote_addr, |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 235 | const bt_property_t* property) { |
| 236 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 237 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 238 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 239 | return btif_set_remote_device_property(remote_addr, property); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 242 | int get_remote_service_record(const RawAddress& remote_addr, |
| 243 | const bluetooth::Uuid& uuid) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 244 | /* sanity check */ |
Myles Watson | 5d5fcf2 | 2017-10-06 16:51:21 -0700 | [diff] [blame] | 245 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 246 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 247 | return btif_get_remote_service_record(remote_addr, uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 248 | } |
| 249 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 250 | int get_remote_services(RawAddress* remote_addr) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 251 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 252 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 253 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 254 | return btif_dm_get_remote_services(*remote_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 257 | static int start_discovery(void) { |
| 258 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 259 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 260 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 261 | return btif_dm_start_discovery(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 264 | static int cancel_discovery(void) { |
| 265 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 266 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 267 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 268 | return btif_dm_cancel_discovery(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 271 | static int create_bond(const RawAddress* bd_addr, int transport) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 272 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 273 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 274 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 275 | return btif_dm_create_bond(bd_addr, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 278 | static int create_bond_out_of_band(const RawAddress* bd_addr, int transport, |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 279 | const bt_out_of_band_data_t* oob_data) { |
| 280 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 281 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 282 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 283 | return btif_dm_create_bond_out_of_band(bd_addr, transport, oob_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 286 | static int cancel_bond(const RawAddress* bd_addr) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 287 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 288 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 289 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 290 | return btif_dm_cancel_bond(bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 293 | static int remove_bond(const RawAddress* bd_addr) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 294 | if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr)) |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 295 | return BT_STATUS_SUCCESS; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 296 | |
| 297 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 298 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 299 | |
| 300 | return btif_dm_remove_bond(bd_addr); |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 303 | static int get_connection_state(const RawAddress* bd_addr) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 304 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 305 | if (!interface_ready()) return 0; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 306 | |
| 307 | return btif_dm_get_connection_state(bd_addr); |
| 308 | } |
| 309 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 310 | static int pin_reply(const RawAddress* bd_addr, uint8_t accept, uint8_t pin_len, |
| 311 | bt_pin_code_t* pin_code) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 312 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 313 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 314 | |
| 315 | return btif_dm_pin_reply(bd_addr, accept, pin_len, pin_code); |
| 316 | } |
| 317 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 318 | static int ssp_reply(const RawAddress* bd_addr, bt_ssp_variant_t variant, |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 319 | uint8_t accept, uint32_t passkey) { |
| 320 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 321 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 322 | |
| 323 | return btif_dm_ssp_reply(bd_addr, variant, accept, passkey); |
| 324 | } |
| 325 | |
| 326 | static int read_energy_info() { |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 327 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 328 | btif_dm_read_energy_info(); |
| 329 | return BT_STATUS_SUCCESS; |
| 330 | } |
| 331 | |
| 332 | static void dump(int fd, const char** arguments) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 333 | btif_debug_conn_dump(fd); |
| 334 | btif_debug_bond_event_dump(fd); |
| 335 | btif_debug_a2dp_dump(fd); |
Pavlin Radoslavov | d752229 | 2017-11-24 19:12:11 -0800 | [diff] [blame] | 336 | btif_debug_av_dump(fd); |
| 337 | bta_debug_av_dump(fd); |
| 338 | stack_debug_avdtp_api_dump(fd); |
Ajay Panicker | 774eb4c | 2018-05-02 16:23:13 -0700 | [diff] [blame] | 339 | bluetooth::avrcp::AvrcpService::DebugDump(fd); |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 340 | btif_debug_config_dump(fd); |
Sanket Agarwal | 5eccd90 | 2016-11-30 19:43:47 -0800 | [diff] [blame] | 341 | BTA_HfClientDumpStatistics(fd); |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 342 | wakelock_debug_dump(fd); |
Pavlin Radoslavov | 0b4f3f7 | 2017-02-01 03:55:33 -0800 | [diff] [blame] | 343 | osi_allocator_debug_dump(fd); |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 344 | alarm_debug_dump(fd); |
Hansong Zhang | b596bb1 | 2018-05-09 14:39:56 -0700 | [diff] [blame] | 345 | HearingAid::DebugDump(fd); |
Jakub Pawlowski | f20d94a | 2018-12-28 19:03:09 +0100 | [diff] [blame] | 346 | connection_manager::dump(fd); |
Ray | 6e63247 | 2019-01-03 21:19:16 +0800 | [diff] [blame] | 347 | bluetooth::bqr::DebugDump(fd); |
Chris Manton | 0cb19c8 | 2020-01-13 21:11:48 -0800 | [diff] [blame] | 348 | if (bluetooth::shim::is_gd_shim_enabled()) { |
| 349 | bluetooth::shim::Dump(fd); |
| 350 | } else { |
Marie Janssen | b7f64bc | 2016-06-22 12:52:19 -0700 | [diff] [blame] | 351 | #if (BTSNOOP_MEM == TRUE) |
Chris Manton | 0cb19c8 | 2020-01-13 21:11:48 -0800 | [diff] [blame] | 352 | btif_debug_btsnoop_dump(fd); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 353 | #endif |
Chris Manton | 0cb19c8 | 2020-01-13 21:11:48 -0800 | [diff] [blame] | 354 | } |
Andre Eisenbach | 89f5e41 | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Jack He | 9af0078 | 2018-01-31 16:51:26 -0800 | [diff] [blame] | 357 | static void dumpMetrics(std::string* output) { |
Jack He | 959bc33 | 2018-08-15 12:38:37 -0700 | [diff] [blame] | 358 | bluetooth::common::BluetoothMetricsLogger::GetInstance()->WriteString(output); |
Jack He | 9af0078 | 2018-01-31 16:51:26 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 361 | static const void* get_profile_interface(const char* profile_id) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 362 | LOG_INFO(LOG_TAG, "%s: id = %s", __func__, profile_id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 363 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 364 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 365 | if (!interface_ready()) return NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 367 | /* check for supported profile interfaces */ |
| 368 | if (is_profile(profile_id, BT_PROFILE_HANDSFREE_ID)) |
Jack He | 12a576d | 2017-12-14 15:00:39 -0800 | [diff] [blame] | 369 | return bluetooth::headset::GetInterface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 370 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 371 | if (is_profile(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID)) |
| 372 | return btif_hf_client_get_interface(); |
Hemant Gupta | 41d4a26 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 373 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 374 | if (is_profile(profile_id, BT_PROFILE_SOCKETS_ID)) |
| 375 | return btif_sock_get_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 376 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 377 | if (is_profile(profile_id, BT_PROFILE_PAN_ID)) |
| 378 | return btif_pan_get_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 379 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 380 | if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID)) |
| 381 | return btif_av_get_src_interface(); |
Mike Lockwood | 3e8a242f | 2014-05-23 12:42:24 -0700 | [diff] [blame] | 382 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 383 | if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID)) |
| 384 | return btif_av_get_sink_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 385 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 386 | if (is_profile(profile_id, BT_PROFILE_HIDHOST_ID)) |
| 387 | return btif_hh_get_interface(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 388 | |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 389 | if (is_profile(profile_id, BT_PROFILE_HIDDEV_ID)) |
| 390 | return btif_hd_get_interface(); |
| 391 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 392 | if (is_profile(profile_id, BT_PROFILE_SDP_CLIENT_ID)) |
| 393 | return btif_sdp_get_interface(); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 394 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 395 | if (is_profile(profile_id, BT_PROFILE_GATT_ID)) |
| 396 | return btif_gatt_get_interface(); |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 397 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 398 | if (is_profile(profile_id, BT_PROFILE_AV_RC_ID)) |
| 399 | return btif_rc_get_interface(); |
Ravi Nagarajan | 9adddf4 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 400 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 401 | if (is_profile(profile_id, BT_PROFILE_AV_RC_CTRL_ID)) |
| 402 | return btif_rc_ctrl_get_interface(); |
Mike Lockwood | 4ad470e | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 403 | |
Jakub Pawlowski | 89b0ccb | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 404 | if (is_profile(profile_id, BT_PROFILE_HEARING_AID_ID)) |
| 405 | return btif_hearing_aid_get_interface(); |
weichinweng | b30bb98 | 2020-04-21 09:42:27 +0800 | [diff] [blame] | 406 | |
| 407 | if (is_profile(profile_id, BT_KEYSTORE_ID)) |
| 408 | return bluetooth::bluetooth_keystore::getBluetoothKeystoreInterface(); |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 409 | return NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 412 | int dut_mode_configure(uint8_t enable) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 413 | LOG_INFO(LOG_TAG, "%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 414 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 415 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 416 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 417 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 418 | return btif_dut_mode_configure(enable); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 421 | int dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 422 | LOG_INFO(LOG_TAG, "%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 423 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 424 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 425 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 426 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 427 | return btif_dut_mode_send(opcode, buf, len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 428 | } |
Matthew Xie | fc4b2f1 | 2013-05-06 20:51:02 -0700 | [diff] [blame] | 429 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 430 | int le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 431 | LOG_INFO(LOG_TAG, "%s", __func__); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 432 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 433 | /* sanity check */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 434 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 435 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 436 | return btif_le_test_mode(opcode, buf, len); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 437 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 438 | |
Pavlin Radoslavov | c788ad7 | 2018-08-24 18:45:16 -0700 | [diff] [blame] | 439 | static bt_os_callouts_t* wakelock_os_callouts_saved = nullptr; |
| 440 | |
| 441 | static int acquire_wake_lock_cb(const char* lock_name) { |
| 442 | return do_in_jni_thread( |
| 443 | FROM_HERE, base::Bind(base::IgnoreResult( |
| 444 | wakelock_os_callouts_saved->acquire_wake_lock), |
| 445 | lock_name)); |
| 446 | } |
| 447 | |
| 448 | static int release_wake_lock_cb(const char* lock_name) { |
| 449 | return do_in_jni_thread( |
| 450 | FROM_HERE, base::Bind(base::IgnoreResult( |
| 451 | wakelock_os_callouts_saved->release_wake_lock), |
| 452 | lock_name)); |
| 453 | } |
| 454 | |
| 455 | static bt_os_callouts_t wakelock_os_callouts_jni = { |
| 456 | sizeof(wakelock_os_callouts_jni), |
| 457 | nullptr /* not used */, |
| 458 | acquire_wake_lock_cb, |
| 459 | release_wake_lock_cb, |
| 460 | }; |
| 461 | |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 462 | static int set_os_callouts(bt_os_callouts_t* callouts) { |
Pavlin Radoslavov | c788ad7 | 2018-08-24 18:45:16 -0700 | [diff] [blame] | 463 | wakelock_os_callouts_saved = callouts; |
| 464 | wakelock_set_os_callouts(&wakelock_os_callouts_jni); |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 465 | return BT_STATUS_SUCCESS; |
Sharvil Nanavati | 10aecea | 2014-05-28 17:09:46 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Ajay Panicker | aa3be1a | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 468 | static int config_clear(void) { |
Myles Watson | 6bd442f | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 469 | LOG_INFO(LOG_TAG, "%s", __func__); |
| 470 | return btif_config_clear() ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; |
Ajay Panicker | aa3be1a | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Ajay Panicker | 6640179 | 2018-03-14 23:45:54 -0700 | [diff] [blame] | 473 | static bluetooth::avrcp::ServiceInterface* get_avrcp_service(void) { |
| 474 | return bluetooth::avrcp::AvrcpService::GetServiceInterface(); |
| 475 | } |
| 476 | |
Jack He | 78b69d9 | 2018-11-16 02:59:43 -0800 | [diff] [blame] | 477 | static std::string obfuscate_address(const RawAddress& address) { |
| 478 | return bluetooth::common::AddressObfuscator::GetInstance()->Obfuscate( |
| 479 | address); |
| 480 | } |
| 481 | |
Chen Chen | 4f6a3b2 | 2020-03-05 15:02:46 -0800 | [diff] [blame] | 482 | static int get_metric_id(const RawAddress& address) { |
| 483 | return bluetooth::common::MetricIdAllocator::GetInstance().AllocateId( |
| 484 | address); |
| 485 | } |
| 486 | |
Jakub Pawlowski | 2d262d5 | 2017-10-16 15:57:16 -0700 | [diff] [blame] | 487 | EXPORT_SYMBOL bt_interface_t bluetoothInterface = { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 488 | sizeof(bluetoothInterface), |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 489 | init, |
| 490 | enable, |
| 491 | disable, |
| 492 | cleanup, |
| 493 | get_adapter_properties, |
| 494 | get_adapter_property, |
| 495 | set_adapter_property, |
| 496 | get_remote_device_properties, |
| 497 | get_remote_device_property, |
| 498 | set_remote_device_property, |
| 499 | get_remote_service_record, |
| 500 | get_remote_services, |
| 501 | start_discovery, |
| 502 | cancel_discovery, |
| 503 | create_bond, |
Jakub Pawlowski | 1a5bb5f | 2015-12-01 12:14:22 -0800 | [diff] [blame] | 504 | create_bond_out_of_band, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 505 | remove_bond, |
| 506 | cancel_bond, |
Andre Eisenbach | 5c0b052 | 2014-06-18 12:20:37 -0700 | [diff] [blame] | 507 | get_connection_state, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 508 | pin_reply, |
| 509 | ssp_reply, |
| 510 | get_profile_interface, |
| 511 | dut_mode_configure, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 512 | dut_mode_send, |
Zhihai Xu | bad70b1 | 2013-06-04 18:21:25 -0700 | [diff] [blame] | 513 | le_test_mode, |
Sharvil Nanavati | 10aecea | 2014-05-28 17:09:46 -0700 | [diff] [blame] | 514 | set_os_callouts, |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 515 | read_energy_info, |
Ajay Panicker | aa3be1a | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 516 | dump, |
Jack He | 9af0078 | 2018-01-31 16:51:26 -0800 | [diff] [blame] | 517 | dumpMetrics, |
Andre Eisenbach | e42d1d7 | 2016-01-14 02:00:24 -0800 | [diff] [blame] | 518 | config_clear, |
| 519 | interop_database_clear, |
| 520 | interop_database_add, |
Ajay Panicker | 6640179 | 2018-03-14 23:45:54 -0700 | [diff] [blame] | 521 | get_avrcp_service, |
Jack He | 78b69d9 | 2018-11-16 02:59:43 -0800 | [diff] [blame] | 522 | obfuscate_address, |
Chen Chen | 4f6a3b2 | 2020-03-05 15:02:46 -0800 | [diff] [blame] | 523 | get_metric_id, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 524 | }; |