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