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> |
Łukasz Rymanowski | 06a5be2 | 2020-12-15 09:14:51 +0000 | [diff] [blame] | 33 | #include <hardware/bt_csis.h> |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 34 | #include <hardware/bt_gatt.h> |
Jakub Tyszkowski | b87fc99 | 2021-04-08 15:08:35 +0000 | [diff] [blame] | 35 | #include <hardware/bt_has.h> |
Hemant Gupta | 2842522 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 36 | #include <hardware/bt_hd.h> |
Jakub Pawlowski | 7d06e57 | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 37 | #include <hardware/bt_hearing_aid.h> |
Hemant Gupta | d9e9cf9 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 38 | #include <hardware/bt_hf_client.h> |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 39 | #include <hardware/bt_hh.h> |
Grzegorz Kołodziejczyk | 177328a | 2020-11-30 13:51:05 +0100 | [diff] [blame] | 40 | #include <hardware/bt_le_audio.h> |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 41 | #include <hardware/bt_pan.h> |
Ravi Nagarajan | 78b3520 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 42 | #include <hardware/bt_rc.h> |
Kim Schulz | b2337fe | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 43 | #include <hardware/bt_sdp.h> |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 44 | #include <hardware/bt_sock.h> |
Łukasz Rymanowski | 35b0836 | 2021-01-29 09:05:10 +0000 | [diff] [blame] | 45 | #include <hardware/bt_vc.h> |
Jack He | 028bf63 | 2020-08-04 01:28:36 -0700 | [diff] [blame] | 46 | #include <stdio.h> |
| 47 | #include <stdlib.h> |
| 48 | #include <string.h> |
| 49 | #include <unistd.h> |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 50 | |
Chen Chen | 2fb6ce3 | 2022-01-31 15:50:01 -0800 | [diff] [blame] | 51 | #include "audio_hal_interface/a2dp_encoding.h" |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 52 | #include "bt_utils.h" |
Łukasz Rymanowski | d853b3a | 2021-10-07 16:58:07 +0000 | [diff] [blame] | 53 | #include "bta/include/bta_csis_api.h" |
Jakub Tyszkowski | b87fc99 | 2021-04-08 15:08:35 +0000 | [diff] [blame] | 54 | #include "bta/include/bta_has_api.h" |
Hansong Zhang | c5df6b0 | 2018-05-09 14:39:56 -0700 | [diff] [blame] | 55 | #include "bta/include/bta_hearing_aid_api.h" |
Sanket Agarwal | d338a64 | 2016-11-30 19:43:47 -0800 | [diff] [blame] | 56 | #include "bta/include/bta_hf_client_api.h" |
Grzegorz Kołodziejczyk | 926fd43 | 2021-10-06 11:54:53 +0000 | [diff] [blame] | 57 | #include "bta/include/bta_le_audio_api.h" |
Jakub Tyszkowski | 8604826 | 2021-12-13 12:32:59 +0100 | [diff] [blame] | 58 | #include "bta/include/bta_le_audio_broadcaster_api.h" |
Łukasz Rymanowski | 1cf5999 | 2022-03-07 09:19:18 +0000 | [diff] [blame] | 59 | #include "bta/include/bta_vc_api.h" |
Jakub Pawlowski | 4533a27 | 2018-05-25 09:31:26 -0700 | [diff] [blame] | 60 | #include "btif/avrcp/avrcp_service.h" |
Chris Manton | 813de98 | 2021-06-08 22:54:06 -0700 | [diff] [blame] | 61 | #include "btif/include/stack_manager.h" |
Pavlin Radoslavov | cd10201 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 62 | #include "btif_a2dp.h" |
Michael Sun | 7cc8f12 | 2020-11-23 18:54:29 +0000 | [diff] [blame] | 63 | #include "btif_activity_attribution.h" |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 64 | #include "btif_api.h" |
Pavlin Radoslavov | 5c6e64c | 2017-11-24 19:12:11 -0800 | [diff] [blame] | 65 | #include "btif_av.h" |
Ray | 4a73d96 | 2019-01-03 21:19:16 +0800 | [diff] [blame] | 66 | #include "btif_bqr.h" |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 67 | #include "btif_config.h" |
Jack He | e43b237 | 2017-12-14 15:00:39 -0800 | [diff] [blame] | 68 | #include "btif_debug_conn.h" |
| 69 | #include "btif_hf.h" |
weichinweng | 6033dfb | 2020-04-21 09:42:27 +0800 | [diff] [blame] | 70 | #include "btif_keystore.h" |
Chen Chen | 534bf24 | 2021-03-10 15:41:42 -0800 | [diff] [blame] | 71 | #include "btif_metrics_logging.h" |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 72 | #include "btif_storage.h" |
Jack He | 9183fd3 | 2018-11-16 02:59:43 -0800 | [diff] [blame] | 73 | #include "common/address_obfuscator.h" |
Chen Chen | 88ca6ae | 2020-03-05 15:02:46 -0800 | [diff] [blame] | 74 | #include "common/metric_id_allocator.h" |
Jack He | 4282398 | 2018-08-15 12:38:37 -0700 | [diff] [blame] | 75 | #include "common/metrics.h" |
weichinweng | 5afd289 | 2021-03-05 14:12:09 +0800 | [diff] [blame] | 76 | #include "common/os_utils.h" |
Andre Eisenbach | 35c0c1d6 | 2016-01-14 02:00:24 -0800 | [diff] [blame] | 77 | #include "device/include/interop.h" |
Zach Johnson | 8ba246e | 2020-05-22 10:02:41 -0700 | [diff] [blame] | 78 | #include "gd/common/init_flags.h" |
weichinweng | 08b6b58 | 2021-09-23 11:41:52 +0800 | [diff] [blame] | 79 | #include "gd/os/parameter_provider.h" |
Chris Manton | ed91660 | 2020-01-13 21:11:48 -0800 | [diff] [blame] | 80 | #include "main/shim/dumpsys.h" |
Chris Manton | b0ecaa7 | 2019-09-11 19:53:32 -0700 | [diff] [blame] | 81 | #include "main/shim/shim.h" |
Pavlin Radoslavov | 30698fa | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 82 | #include "osi/include/alarm.h" |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 83 | #include "osi/include/allocation_tracker.h" |
Chris Manton | 1fd0261 | 2021-08-28 16:03:54 -0700 | [diff] [blame] | 84 | #include "osi/include/allocator.h" |
Sharvil Nanavati | 8395177 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 85 | #include "osi/include/log.h" |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 86 | #include "osi/include/osi.h" |
Pavlin Radoslavov | 5bb6cac | 2015-08-24 16:29:21 -0700 | [diff] [blame] | 87 | #include "osi/include/wakelock.h" |
Jakub Pawlowski | 6037e03 | 2018-11-13 15:41:42 +0100 | [diff] [blame] | 88 | #include "stack/gatt/connection_manager.h" |
Chris Manton | a87686c | 2021-01-30 15:59:29 -0800 | [diff] [blame] | 89 | #include "stack/include/avdt_api.h" |
Martin Brabham | afea75b | 2021-06-30 12:08:02 -0700 | [diff] [blame] | 90 | #include "stack/include/btm_api.h" |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 91 | #include "stack/include/btu.h" |
Chris Manton | 2a9d9f2 | 2021-09-10 23:05:47 -0700 | [diff] [blame] | 92 | #include "types/raw_address.h" |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 93 | |
Łukasz Rymanowski | 06a5be2 | 2020-12-15 09:14:51 +0000 | [diff] [blame] | 94 | using bluetooth::csis::CsisClientInterface; |
Jakub Tyszkowski | b87fc99 | 2021-04-08 15:08:35 +0000 | [diff] [blame] | 95 | using bluetooth::has::HasClientInterface; |
Jakub Pawlowski | 7d06e57 | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 96 | using bluetooth::hearing_aid::HearingAidInterface; |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 97 | #ifndef TARGET_FLOSS |
Jakub Tyszkowski | 8604826 | 2021-12-13 12:32:59 +0100 | [diff] [blame] | 98 | using bluetooth::le_audio::LeAudioBroadcasterInterface; |
Grzegorz Kołodziejczyk | 177328a | 2020-11-30 13:51:05 +0100 | [diff] [blame] | 99 | using bluetooth::le_audio::LeAudioClientInterface; |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 100 | #endif |
Łukasz Rymanowski | 35b0836 | 2021-01-29 09:05:10 +0000 | [diff] [blame] | 101 | using bluetooth::vc::VolumeControlInterface; |
Jakub Pawlowski | 7d06e57 | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 102 | |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 103 | /******************************************************************************* |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 104 | * Static variables |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 105 | ******************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 106 | |
Zach Johnson | d6e1036 | 2020-08-14 16:58:12 -0700 | [diff] [blame] | 107 | static bt_callbacks_t* bt_hal_cbacks = NULL; |
Marie Janssen | 0fc1f13 | 2016-06-22 12:52:19 -0700 | [diff] [blame] | 108 | bool restricted_mode = false; |
weichinweng | 8cd854f | 2021-03-04 09:11:30 +0800 | [diff] [blame] | 109 | bool common_criteria_mode = false; |
weichinweng | 7107d8f | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 110 | const int CONFIG_COMPARE_ALL_PASS = 0b11; |
weichinweng | 8cd854f | 2021-03-04 09:11:30 +0800 | [diff] [blame] | 111 | int common_criteria_config_compare_result = CONFIG_COMPARE_ALL_PASS; |
Rahul Sabnis | 0c983e2 | 2020-07-31 19:44:27 -0700 | [diff] [blame] | 112 | bool is_local_device_atv = false; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 113 | |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 114 | /******************************************************************************* |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 115 | * Externs |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 116 | ******************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 117 | |
| 118 | /* list all extended interfaces here */ |
| 119 | |
Hemant Gupta | d9e9cf9 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 120 | /* handsfree profile - client */ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 121 | 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] | 122 | /* advanced audio profile */ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 123 | extern const btav_source_interface_t* btif_av_get_src_interface(); |
| 124 | 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] | 125 | /*rfc l2cap*/ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 126 | extern const btsock_interface_t* btif_sock_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 127 | /* hid host profile */ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 128 | extern const bthh_interface_t* btif_hh_get_interface(); |
Hemant Gupta | 2842522 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 129 | /* hid device profile */ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 130 | extern const bthd_interface_t* btif_hd_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | /*pan*/ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 132 | extern const btpan_interface_t* btif_pan_get_interface(); |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 133 | /* gatt */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 134 | extern const btgatt_interface_t* btif_gatt_get_interface(); |
Mike Lockwood | c02ef77 | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 135 | /* avrc target */ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 136 | extern const btrc_interface_t* btif_rc_get_interface(); |
Mike Lockwood | c02ef77 | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 137 | /* avrc controller */ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 138 | extern const btrc_ctrl_interface_t* btif_rc_ctrl_get_interface(); |
Kim Schulz | b2337fe | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 139 | /*SDP search client*/ |
Jack He | 13d8b74 | 2017-12-04 14:30:42 -0800 | [diff] [blame] | 140 | extern const btsdp_interface_t* btif_sdp_get_interface(); |
Jakub Pawlowski | 7d06e57 | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 141 | /*Hearing Aid client*/ |
| 142 | extern HearingAidInterface* btif_hearing_aid_get_interface(); |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 143 | #ifndef TARGET_FLOSS |
Jakub Tyszkowski | b87fc99 | 2021-04-08 15:08:35 +0000 | [diff] [blame] | 144 | /* Hearing Access client */ |
| 145 | extern HasClientInterface* btif_has_client_get_interface(); |
Grzegorz Kołodziejczyk | 177328a | 2020-11-30 13:51:05 +0100 | [diff] [blame] | 146 | /* LeAudio testi client */ |
| 147 | extern LeAudioClientInterface* btif_le_audio_get_interface(); |
Jakub Tyszkowski | 8604826 | 2021-12-13 12:32:59 +0100 | [diff] [blame] | 148 | /* LeAudio Broadcaster */ |
| 149 | extern LeAudioBroadcasterInterface* btif_le_audio_broadcaster_get_interface(); |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 150 | #endif |
Łukasz Rymanowski | 06a5be2 | 2020-12-15 09:14:51 +0000 | [diff] [blame] | 151 | /* Coordinated Set Service Client */ |
| 152 | extern CsisClientInterface* btif_csis_client_get_interface(); |
Łukasz Rymanowski | 35b0836 | 2021-01-29 09:05:10 +0000 | [diff] [blame] | 153 | /* Volume Control client */ |
| 154 | extern VolumeControlInterface* btif_volume_control_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 155 | |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 156 | /******************************************************************************* |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 157 | * Functions |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame] | 158 | ******************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 159 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 160 | static bool interface_ready(void) { return bt_hal_cbacks != NULL; } |
Chris Manton | f93fece | 2021-04-08 16:16:53 -0700 | [diff] [blame] | 161 | void set_hal_cbacks(bt_callbacks_t* callbacks) { bt_hal_cbacks = callbacks; } |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 162 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 163 | static bool is_profile(const char* p1, const char* p2) { |
Jack He | 358dd11 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 164 | CHECK(p1); |
| 165 | CHECK(p2); |
Andre Eisenbach | 80c23e5 | 2016-02-17 12:43:12 -0800 | [diff] [blame] | 166 | return strlen(p1) == strlen(p2) && strncmp(p1, p2, strlen(p2)) == 0; |
| 167 | } |
| 168 | |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 169 | /***************************************************************************** |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 170 | * |
| 171 | * BLUETOOTH HAL INTERFACE FUNCTIONS |
| 172 | * |
| 173 | ****************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 174 | |
William Escande | b94e4d7 | 2022-05-27 12:03:36 -0700 | [diff] [blame] | 175 | const std::vector<std::string> get_allowed_bt_package_name(void); |
| 176 | void handle_migration(const std::string& dst, |
| 177 | const std::vector<std::string>& allowed_bt_package_name); |
| 178 | |
Martin Brabham | e02a8be | 2019-05-10 12:42:15 -0700 | [diff] [blame] | 179 | static int init(bt_callbacks_t* callbacks, bool start_restricted, |
weichinweng | 8cd854f | 2021-03-04 09:11:30 +0800 | [diff] [blame] | 180 | bool is_common_criteria_mode, int config_compare_result, |
William Escande | b94e4d7 | 2022-05-27 12:03:36 -0700 | [diff] [blame] | 181 | const char** init_flags, bool is_atv, |
| 182 | const char* user_data_directory) { |
weichinweng | 8cd854f | 2021-03-04 09:11:30 +0800 | [diff] [blame] | 183 | LOG_INFO( |
| 184 | "%s: start restricted = %d ; common criteria mode = %d, config compare " |
| 185 | "result = %d", |
| 186 | __func__, start_restricted, is_common_criteria_mode, |
| 187 | config_compare_result); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 188 | |
William Escande | b94e4d7 | 2022-05-27 12:03:36 -0700 | [diff] [blame] | 189 | if (user_data_directory != nullptr) { |
| 190 | handle_migration(std::string(user_data_directory), |
| 191 | get_allowed_bt_package_name()); |
| 192 | } |
| 193 | |
Zach Johnson | 8ba246e | 2020-05-22 10:02:41 -0700 | [diff] [blame] | 194 | bluetooth::common::InitFlags::Load(init_flags); |
Chris Manton | b0ecaa7 | 2019-09-11 19:53:32 -0700 | [diff] [blame] | 195 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 196 | if (interface_ready()) return BT_STATUS_DONE; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 197 | |
Sharvil Nanavati | 19f4b18 | 2014-11-13 01:04:19 -0800 | [diff] [blame] | 198 | #ifdef BLUEDROID_DEBUG |
| 199 | allocation_tracker_init(); |
| 200 | #endif |
| 201 | |
Chris Manton | f93fece | 2021-04-08 16:16:53 -0700 | [diff] [blame] | 202 | set_hal_cbacks(callbacks); |
| 203 | |
Martin Brabham | e02a8be | 2019-05-10 12:42:15 -0700 | [diff] [blame] | 204 | restricted_mode = start_restricted; |
weichinweng | 08b6b58 | 2021-09-23 11:41:52 +0800 | [diff] [blame] | 205 | |
Chris Manton | 11ca0bb | 2021-10-01 13:54:42 -0700 | [diff] [blame] | 206 | bluetooth::os::ParameterProvider::SetBtKeystoreInterface( |
| 207 | bluetooth::bluetooth_keystore::getBluetoothKeystoreInterface()); |
| 208 | bluetooth::os::ParameterProvider::SetCommonCriteriaMode( |
| 209 | is_common_criteria_mode); |
| 210 | if (is_bluetooth_uid() && is_common_criteria_mode) { |
| 211 | bluetooth::os::ParameterProvider::SetCommonCriteriaConfigCompareResult( |
| 212 | config_compare_result); |
weichinweng | 08b6b58 | 2021-09-23 11:41:52 +0800 | [diff] [blame] | 213 | } else { |
Chris Manton | 11ca0bb | 2021-10-01 13:54:42 -0700 | [diff] [blame] | 214 | bluetooth::os::ParameterProvider::SetCommonCriteriaConfigCompareResult( |
| 215 | CONFIG_COMPARE_ALL_PASS); |
weichinweng | 08b6b58 | 2021-09-23 11:41:52 +0800 | [diff] [blame] | 216 | } |
| 217 | |
Rahul Sabnis | 0c983e2 | 2020-07-31 19:44:27 -0700 | [diff] [blame] | 218 | is_local_device_atv = is_atv; |
weichinweng | 7107d8f | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 219 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 220 | stack_manager_get_interface()->init_stack(); |
| 221 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Martin Brabham | e02a8be | 2019-05-10 12:42:15 -0700 | [diff] [blame] | 224 | static int enable() { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 225 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 226 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 227 | stack_manager_get_interface()->start_up_stack_async(); |
| 228 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 229 | } |
| 230 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 231 | static int disable(void) { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 232 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 233 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 234 | stack_manager_get_interface()->shut_down_stack_async(); |
| 235 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 236 | } |
| 237 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 238 | static void cleanup(void) { stack_manager_get_interface()->clean_up_stack(); } |
| 239 | |
| 240 | bool is_restricted_mode() { return restricted_mode; } |
weichinweng | 5afd289 | 2021-03-05 14:12:09 +0800 | [diff] [blame] | 241 | bool is_common_criteria_mode() { |
| 242 | return is_bluetooth_uid() && common_criteria_mode; |
| 243 | } |
weichinweng | 8cd854f | 2021-03-04 09:11:30 +0800 | [diff] [blame] | 244 | // if common criteria mode disable, will always return |
| 245 | // CONFIG_COMPARE_ALL_PASS(0b11) indicate don't check config checksum. |
| 246 | int get_common_criteria_config_compare_result() { |
weichinweng | 5afd289 | 2021-03-05 14:12:09 +0800 | [diff] [blame] | 247 | return is_common_criteria_mode() ? common_criteria_config_compare_result |
| 248 | : CONFIG_COMPARE_ALL_PASS; |
weichinweng | 7107d8f | 2020-04-21 10:26:26 +0800 | [diff] [blame] | 249 | } |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 250 | |
Rahul Sabnis | 0c983e2 | 2020-07-31 19:44:27 -0700 | [diff] [blame] | 251 | bool is_atv_device() { return is_local_device_atv; } |
| 252 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 253 | static int get_adapter_properties(void) { |
Zach Johnson | 3f7946d | 2020-08-14 10:11:14 -0700 | [diff] [blame] | 254 | if (!btif_is_enabled()) return BT_STATUS_NOT_READY; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 255 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 256 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_get_adapter_properties)); |
Zach Johnson | 3f7946d | 2020-08-14 10:11:14 -0700 | [diff] [blame] | 257 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 258 | } |
| 259 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 260 | static int get_adapter_property(bt_property_type_t type) { |
Zach Johnson | 1ee3486 | 2020-08-14 10:23:10 -0700 | [diff] [blame] | 261 | /* Allow get_adapter_property only for BDADDR and BDNAME if BT is disabled */ |
| 262 | if (!btif_is_enabled() && (type != BT_PROPERTY_BDADDR) && |
| 263 | (type != BT_PROPERTY_BDNAME) && (type != BT_PROPERTY_CLASS_OF_DEVICE)) |
| 264 | return BT_STATUS_NOT_READY; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 265 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 266 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_get_adapter_property, type)); |
Zach Johnson | 1ee3486 | 2020-08-14 10:23:10 -0700 | [diff] [blame] | 267 | return BT_STATUS_SUCCESS; |
Ajay Panicker | c796ac8 | 2016-03-17 17:09:24 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 270 | static int set_adapter_property(const bt_property_t* property) { |
Zach Johnson | f0f1c0c | 2020-08-14 11:24:35 -0700 | [diff] [blame] | 271 | if (!btif_is_enabled()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 272 | |
Zach Johnson | f0f1c0c | 2020-08-14 11:24:35 -0700 | [diff] [blame] | 273 | switch (property->type) { |
| 274 | case BT_PROPERTY_BDNAME: |
| 275 | case BT_PROPERTY_ADAPTER_SCAN_MODE: |
Katherine Lai | b68a4b5 | 2022-02-14 18:41:22 +0000 | [diff] [blame] | 276 | case BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT: |
Zach Johnson | f0f1c0c | 2020-08-14 11:24:35 -0700 | [diff] [blame] | 277 | case BT_PROPERTY_CLASS_OF_DEVICE: |
| 278 | case BT_PROPERTY_LOCAL_IO_CAPS: |
| 279 | case BT_PROPERTY_LOCAL_IO_CAPS_BLE: |
| 280 | break; |
| 281 | default: |
| 282 | return BT_STATUS_FAIL; |
| 283 | } |
| 284 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 285 | do_in_main_thread(FROM_HERE, base::BindOnce( |
| 286 | [](bt_property_t* property) { |
| 287 | btif_set_adapter_property(property); |
| 288 | osi_free(property); |
| 289 | }, |
| 290 | property_deep_copy(property))); |
Zach Johnson | f0f1c0c | 2020-08-14 11:24:35 -0700 | [diff] [blame] | 291 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 294 | int get_remote_device_properties(RawAddress* remote_addr) { |
Zach Johnson | 28d5bde | 2020-08-14 12:07:19 -0700 | [diff] [blame] | 295 | if (!btif_is_enabled()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 296 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 297 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_get_remote_device_properties, |
| 298 | *remote_addr)); |
Zach Johnson | 28d5bde | 2020-08-14 12:07:19 -0700 | [diff] [blame] | 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 | int get_remote_device_property(RawAddress* remote_addr, |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 303 | bt_property_type_t type) { |
Zach Johnson | dbda78c | 2020-08-14 11:58:08 -0700 | [diff] [blame] | 304 | if (!btif_is_enabled()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 305 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 306 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_get_remote_device_property, |
| 307 | *remote_addr, type)); |
Zach Johnson | dbda78c | 2020-08-14 11:58:08 -0700 | [diff] [blame] | 308 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 311 | int set_remote_device_property(RawAddress* remote_addr, |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 312 | const bt_property_t* property) { |
Zach Johnson | 7cfca2e | 2020-08-14 12:17:08 -0700 | [diff] [blame] | 313 | if (!btif_is_enabled()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 314 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 315 | do_in_main_thread( |
Zach Johnson | 7cfca2e | 2020-08-14 12:17:08 -0700 | [diff] [blame] | 316 | FROM_HERE, base::BindOnce( |
| 317 | [](RawAddress remote_addr, bt_property_t* property) { |
| 318 | btif_set_remote_device_property(&remote_addr, property); |
| 319 | osi_free(property); |
| 320 | }, |
| 321 | *remote_addr, property_deep_copy(property))); |
| 322 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 323 | } |
| 324 | |
Alice Kuo | af6ec99 | 2021-08-13 00:30:48 +0800 | [diff] [blame] | 325 | int get_remote_services(RawAddress* remote_addr, int transport) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 326 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 327 | |
Chris Manton | 29e7029 | 2021-06-22 10:16:00 -0700 | [diff] [blame] | 328 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_get_remote_services, |
Alice Kuo | af6ec99 | 2021-08-13 00:30:48 +0800 | [diff] [blame] | 329 | *remote_addr, transport)); |
Zach Johnson | 947f265 | 2020-08-14 12:34:06 -0700 | [diff] [blame] | 330 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 333 | static int start_discovery(void) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 334 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 335 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 336 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_start_discovery)); |
Zach Johnson | 1653a20 | 2020-08-14 12:44:42 -0700 | [diff] [blame] | 337 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 340 | static int cancel_discovery(void) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 341 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 342 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 343 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_cancel_discovery)); |
Zach Johnson | 5cd06df | 2020-08-14 12:47:29 -0700 | [diff] [blame] | 344 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 347 | static int create_bond(const RawAddress* bd_addr, int transport) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 348 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zach Johnson | 35f416e | 2020-08-14 12:52:58 -0700 | [diff] [blame] | 349 | 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] | 350 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 351 | do_in_main_thread(FROM_HERE, |
| 352 | base::BindOnce(btif_dm_create_bond, *bd_addr, transport)); |
Zach Johnson | 35f416e | 2020-08-14 12:52:58 -0700 | [diff] [blame] | 353 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 356 | static int create_bond_out_of_band(const RawAddress* bd_addr, int transport, |
Martin Brabham | c5c2413 | 2021-01-21 10:37:43 -0800 | [diff] [blame] | 357 | const bt_oob_data_t* p192_data, |
| 358 | const bt_oob_data_t* p256_data) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 359 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zach Johnson | 106ceb4 | 2020-08-14 13:00:54 -0700 | [diff] [blame] | 360 | 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] | 361 | |
Martin Brabham | c5c2413 | 2021-01-21 10:37:43 -0800 | [diff] [blame] | 362 | do_in_main_thread(FROM_HERE, |
| 363 | base::BindOnce(btif_dm_create_bond_out_of_band, *bd_addr, |
| 364 | transport, *p192_data, *p256_data)); |
Zach Johnson | 106ceb4 | 2020-08-14 13:00:54 -0700 | [diff] [blame] | 365 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | } |
| 367 | |
Martin Brabham | bbe7f09 | 2021-03-31 09:41:34 -0700 | [diff] [blame] | 368 | static int generate_local_oob_data(tBT_TRANSPORT transport) { |
| 369 | LOG_INFO("%s", __func__); |
| 370 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
| 371 | |
| 372 | return do_in_main_thread( |
| 373 | FROM_HERE, base::BindOnce(btif_dm_generate_local_oob_data, transport)); |
| 374 | } |
| 375 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 376 | static int cancel_bond(const RawAddress* bd_addr) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 377 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 378 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 379 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_cancel_bond, *bd_addr)); |
Zach Johnson | 030162a | 2020-08-14 13:06:01 -0700 | [diff] [blame] | 380 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 383 | static int remove_bond(const RawAddress* bd_addr) { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 384 | if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr)) |
Satya Calloji | 75fd880 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 385 | return BT_STATUS_SUCCESS; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 386 | |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 387 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 388 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 389 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_remove_bond, *bd_addr)); |
Zach Johnson | 62b79ea | 2020-08-14 13:08:57 -0700 | [diff] [blame] | 390 | return BT_STATUS_SUCCESS; |
Satya Calloji | 75fd880 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 393 | static int get_connection_state(const RawAddress* bd_addr) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 394 | if (!interface_ready()) return 0; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 395 | |
| 396 | return btif_dm_get_connection_state(bd_addr); |
| 397 | } |
| 398 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 399 | static int pin_reply(const RawAddress* bd_addr, uint8_t accept, uint8_t pin_len, |
| 400 | bt_pin_code_t* pin_code) { |
Brian Delwiche | 2c09d20 | 2022-08-10 06:47:52 +0000 | [diff] [blame] | 401 | bt_pin_code_t tmp_pin_code; |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 402 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zach Johnson | da4e25f | 2020-08-14 13:39:45 -0700 | [diff] [blame] | 403 | 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] | 404 | |
Brian Delwiche | 2c09d20 | 2022-08-10 06:47:52 +0000 | [diff] [blame] | 405 | memcpy(&tmp_pin_code, pin_code, pin_len); |
| 406 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 407 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_pin_reply, *bd_addr, |
Brian Delwiche | 2c09d20 | 2022-08-10 06:47:52 +0000 | [diff] [blame] | 408 | accept, pin_len, tmp_pin_code)); |
Zach Johnson | da4e25f | 2020-08-14 13:39:45 -0700 | [diff] [blame] | 409 | return BT_STATUS_SUCCESS; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Jakub Pawlowski | d8e815c | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 412 | 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] | 413 | uint8_t accept, uint32_t passkey) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 414 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zach Johnson | 418fb35 | 2020-08-14 14:02:15 -0700 | [diff] [blame] | 415 | if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY) return BT_STATUS_FAIL; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 416 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 417 | do_in_main_thread( |
Zach Johnson | 418fb35 | 2020-08-14 14:02:15 -0700 | [diff] [blame] | 418 | FROM_HERE, base::BindOnce(btif_dm_ssp_reply, *bd_addr, variant, accept)); |
| 419 | return BT_STATUS_SUCCESS; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static int read_energy_info() { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 423 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zach Johnson | d590bb1 | 2020-08-14 14:03:44 -0700 | [diff] [blame] | 424 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 425 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_read_energy_info)); |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 426 | return BT_STATUS_SUCCESS; |
| 427 | } |
| 428 | |
Martin Brabham | 08eeffa | 2022-01-26 18:50:36 +0000 | [diff] [blame] | 429 | static int clear_event_filter() { |
| 430 | LOG_VERBOSE("%s", __func__); |
| 431 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
| 432 | |
| 433 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dm_clear_event_filter)); |
| 434 | return BT_STATUS_SUCCESS; |
| 435 | } |
| 436 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 437 | static void dump(int fd, const char** arguments) { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 438 | btif_debug_conn_dump(fd); |
| 439 | btif_debug_bond_event_dump(fd); |
Josh Wu | 6ea85d4 | 2022-03-23 01:54:04 -0700 | [diff] [blame] | 440 | btif_debug_linkkey_type_dump(fd); |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 441 | btif_debug_a2dp_dump(fd); |
Pavlin Radoslavov | 5c6e64c | 2017-11-24 19:12:11 -0800 | [diff] [blame] | 442 | btif_debug_av_dump(fd); |
| 443 | bta_debug_av_dump(fd); |
| 444 | stack_debug_avdtp_api_dump(fd); |
Ajay Panicker | 13d845b | 2018-05-02 16:23:13 -0700 | [diff] [blame] | 445 | bluetooth::avrcp::AvrcpService::DebugDump(fd); |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 446 | btif_debug_config_dump(fd); |
Sanket Agarwal | d338a64 | 2016-11-30 19:43:47 -0800 | [diff] [blame] | 447 | BTA_HfClientDumpStatistics(fd); |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 448 | wakelock_debug_dump(fd); |
Pavlin Radoslavov | 64c3093 | 2017-02-01 03:55:33 -0800 | [diff] [blame] | 449 | osi_allocator_debug_dump(fd); |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 450 | alarm_debug_dump(fd); |
Łukasz Rymanowski | d853b3a | 2021-10-07 16:58:07 +0000 | [diff] [blame] | 451 | bluetooth::csis::CsisClient::DebugDump(fd); |
Abhishek Pandit-Subedi | 9931137 | 2022-02-03 16:25:54 -0800 | [diff] [blame] | 452 | #ifndef TARGET_FLOSS |
Jakub Tyszkowski | b87fc99 | 2021-04-08 15:08:35 +0000 | [diff] [blame] | 453 | le_audio::has::HasClient::DebugDump(fd); |
Abhishek Pandit-Subedi | 9931137 | 2022-02-03 16:25:54 -0800 | [diff] [blame] | 454 | #endif |
Hansong Zhang | c5df6b0 | 2018-05-09 14:39:56 -0700 | [diff] [blame] | 455 | HearingAid::DebugDump(fd); |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 456 | #ifndef TARGET_FLOSS |
Grzegorz Kołodziejczyk | 926fd43 | 2021-10-06 11:54:53 +0000 | [diff] [blame] | 457 | LeAudioClient::DebugDump(fd); |
Jakub Tyszkowski | 8604826 | 2021-12-13 12:32:59 +0100 | [diff] [blame] | 458 | LeAudioBroadcaster::DebugDump(fd); |
Łukasz Rymanowski | 1cf5999 | 2022-03-07 09:19:18 +0000 | [diff] [blame] | 459 | VolumeControl::DebugDump(fd); |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 460 | #endif |
Jakub Pawlowski | e80bfd5 | 2018-12-28 19:03:09 +0100 | [diff] [blame] | 461 | connection_manager::dump(fd); |
Ray | 4a73d96 | 2019-01-03 21:19:16 +0800 | [diff] [blame] | 462 | bluetooth::bqr::DebugDump(fd); |
Chris Manton | b939d84 | 2021-10-01 13:50:06 -0700 | [diff] [blame] | 463 | bluetooth::shim::Dump(fd, arguments); |
Andre Eisenbach | 8f6c5be | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Jack He | d20346ab | 2018-01-31 16:51:26 -0800 | [diff] [blame] | 466 | static void dumpMetrics(std::string* output) { |
Jack He | 4282398 | 2018-08-15 12:38:37 -0700 | [diff] [blame] | 467 | bluetooth::common::BluetoothMetricsLogger::GetInstance()->WriteString(output); |
Jack He | d20346ab | 2018-01-31 16:51:26 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 470 | static const void* get_profile_interface(const char* profile_id) { |
Jakub Pawlowski | 13ee9b8 | 2020-03-05 21:16:10 +0100 | [diff] [blame] | 471 | LOG_INFO("%s: id = %s", __func__, profile_id); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 472 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 473 | /* sanity check */ |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 474 | if (!interface_ready()) return NULL; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 475 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 476 | /* check for supported profile interfaces */ |
| 477 | if (is_profile(profile_id, BT_PROFILE_HANDSFREE_ID)) |
Jack He | e43b237 | 2017-12-14 15:00:39 -0800 | [diff] [blame] | 478 | return bluetooth::headset::GetInterface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 479 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 480 | if (is_profile(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID)) |
| 481 | return btif_hf_client_get_interface(); |
Hemant Gupta | d9e9cf9 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 482 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 483 | if (is_profile(profile_id, BT_PROFILE_SOCKETS_ID)) |
| 484 | return btif_sock_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 485 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 486 | if (is_profile(profile_id, BT_PROFILE_PAN_ID)) |
| 487 | return btif_pan_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 488 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 489 | if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID)) |
| 490 | return btif_av_get_src_interface(); |
Mike Lockwood | c80e2d7 | 2014-05-23 12:42:24 -0700 | [diff] [blame] | 491 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 492 | if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID)) |
| 493 | return btif_av_get_sink_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 494 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 495 | if (is_profile(profile_id, BT_PROFILE_HIDHOST_ID)) |
| 496 | return btif_hh_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 497 | |
Hemant Gupta | 2842522 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 498 | if (is_profile(profile_id, BT_PROFILE_HIDDEV_ID)) |
| 499 | return btif_hd_get_interface(); |
| 500 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 501 | if (is_profile(profile_id, BT_PROFILE_SDP_CLIENT_ID)) |
| 502 | return btif_sdp_get_interface(); |
Hemant Gupta | d0ecdbb | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 503 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 504 | if (is_profile(profile_id, BT_PROFILE_GATT_ID)) |
| 505 | return btif_gatt_get_interface(); |
Ravi Nagarajan | 78b3520 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 506 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 507 | if (is_profile(profile_id, BT_PROFILE_AV_RC_ID)) |
| 508 | return btif_rc_get_interface(); |
Ravi Nagarajan | 78b3520 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 509 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 510 | if (is_profile(profile_id, BT_PROFILE_AV_RC_CTRL_ID)) |
| 511 | return btif_rc_ctrl_get_interface(); |
Mike Lockwood | c02ef77 | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 512 | |
Jakub Pawlowski | 7d06e57 | 2018-02-28 22:44:42 -0800 | [diff] [blame] | 513 | if (is_profile(profile_id, BT_PROFILE_HEARING_AID_ID)) |
| 514 | return btif_hearing_aid_get_interface(); |
weichinweng | 6033dfb | 2020-04-21 09:42:27 +0800 | [diff] [blame] | 515 | |
Abhishek Pandit-Subedi | 9931137 | 2022-02-03 16:25:54 -0800 | [diff] [blame] | 516 | #ifndef TARGET_FLOSS |
Jakub Tyszkowski | b87fc99 | 2021-04-08 15:08:35 +0000 | [diff] [blame] | 517 | if (is_profile(profile_id, BT_PROFILE_HAP_CLIENT_ID)) |
| 518 | return btif_has_client_get_interface(); |
Abhishek Pandit-Subedi | 9931137 | 2022-02-03 16:25:54 -0800 | [diff] [blame] | 519 | #endif |
Jakub Tyszkowski | b87fc99 | 2021-04-08 15:08:35 +0000 | [diff] [blame] | 520 | |
weichinweng | 6033dfb | 2020-04-21 09:42:27 +0800 | [diff] [blame] | 521 | if (is_profile(profile_id, BT_KEYSTORE_ID)) |
| 522 | return bluetooth::bluetooth_keystore::getBluetoothKeystoreInterface(); |
Michael Sun | 80dff5c | 2020-11-02 07:17:47 +0000 | [diff] [blame] | 523 | |
| 524 | if (is_profile(profile_id, BT_ACTIVITY_ATTRIBUTION_ID)) { |
Michael Sun | 7cc8f12 | 2020-11-23 18:54:29 +0000 | [diff] [blame] | 525 | return bluetooth::activity_attribution::get_activity_attribution_instance(); |
Michael Sun | 80dff5c | 2020-11-02 07:17:47 +0000 | [diff] [blame] | 526 | } |
| 527 | |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 528 | #ifndef TARGET_FLOSS |
Grzegorz Kołodziejczyk | 177328a | 2020-11-30 13:51:05 +0100 | [diff] [blame] | 529 | if (is_profile(profile_id, BT_PROFILE_LE_AUDIO_ID)) |
| 530 | return btif_le_audio_get_interface(); |
| 531 | |
Jakub Tyszkowski | 8604826 | 2021-12-13 12:32:59 +0100 | [diff] [blame] | 532 | if (is_profile(profile_id, BT_PROFILE_LE_AUDIO_BROADCASTER_ID)) |
| 533 | return btif_le_audio_broadcaster_get_interface(); |
Abhishek Pandit-Subedi | 83a3fa8 | 2022-01-28 17:08:55 -0800 | [diff] [blame] | 534 | #endif |
Jakub Tyszkowski | 8604826 | 2021-12-13 12:32:59 +0100 | [diff] [blame] | 535 | |
Łukasz Rymanowski | 35b0836 | 2021-01-29 09:05:10 +0000 | [diff] [blame] | 536 | if (is_profile(profile_id, BT_PROFILE_VC_ID)) |
| 537 | return btif_volume_control_get_interface(); |
| 538 | |
Łukasz Rymanowski | 06a5be2 | 2020-12-15 09:14:51 +0000 | [diff] [blame] | 539 | if (is_profile(profile_id, BT_PROFILE_CSIS_CLIENT_ID)) |
| 540 | return btif_csis_client_get_interface(); |
| 541 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 542 | return NULL; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 543 | } |
| 544 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 545 | int dut_mode_configure(uint8_t enable) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 546 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zach Johnson | 9a32572 | 2020-08-14 14:08:26 -0700 | [diff] [blame] | 547 | if (!stack_manager_get_interface()->get_stack_is_running()) |
| 548 | return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 549 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 550 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_dut_mode_configure, enable)); |
Zach Johnson | 9a32572 | 2020-08-14 14:08:26 -0700 | [diff] [blame] | 551 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 554 | int dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 555 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zach Johnson | c401e25 | 2020-08-14 14:16:35 -0700 | [diff] [blame] | 556 | if (!btif_is_dut_mode()) return BT_STATUS_FAIL; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 557 | |
Zach Johnson | c401e25 | 2020-08-14 14:16:35 -0700 | [diff] [blame] | 558 | uint8_t* copy = (uint8_t*)osi_calloc(len); |
| 559 | memcpy(copy, buf, len); |
| 560 | |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 561 | do_in_main_thread(FROM_HERE, |
| 562 | base::BindOnce( |
| 563 | [](uint16_t opcode, uint8_t* buf, uint8_t len) { |
| 564 | btif_dut_mode_send(opcode, buf, len); |
| 565 | osi_free(buf); |
| 566 | }, |
| 567 | opcode, copy, len)); |
Zach Johnson | c401e25 | 2020-08-14 14:16:35 -0700 | [diff] [blame] | 568 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 569 | } |
Matthew Xie | 41fb436 | 2013-05-06 20:51:02 -0700 | [diff] [blame] | 570 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 571 | int le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { |
Myles Watson | 6a7e1ac | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 572 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 573 | |
Zach Johnson | b2bc710 | 2020-08-14 14:25:49 -0700 | [diff] [blame] | 574 | switch (opcode) { |
| 575 | case HCI_BLE_TRANSMITTER_TEST: |
| 576 | if (len != 3) return BT_STATUS_PARM_INVALID; |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 577 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_ble_transmitter_test, |
| 578 | buf[0], buf[1], buf[2])); |
Zach Johnson | b2bc710 | 2020-08-14 14:25:49 -0700 | [diff] [blame] | 579 | break; |
| 580 | case HCI_BLE_RECEIVER_TEST: |
| 581 | if (len != 1) return BT_STATUS_PARM_INVALID; |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 582 | do_in_main_thread(FROM_HERE, |
| 583 | base::BindOnce(btif_ble_receiver_test, buf[0])); |
Zach Johnson | b2bc710 | 2020-08-14 14:25:49 -0700 | [diff] [blame] | 584 | break; |
| 585 | case HCI_BLE_TEST_END: |
Zach Johnson | af85a8b | 2020-08-14 17:33:35 -0700 | [diff] [blame] | 586 | do_in_main_thread(FROM_HERE, base::BindOnce(btif_ble_test_end)); |
Zach Johnson | b2bc710 | 2020-08-14 14:25:49 -0700 | [diff] [blame] | 587 | break; |
| 588 | default: |
| 589 | return BT_STATUS_UNSUPPORTED; |
| 590 | } |
| 591 | return BT_STATUS_SUCCESS; |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 592 | } |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 593 | |
Pavlin Radoslavov | 34bd633 | 2018-08-24 18:45:16 -0700 | [diff] [blame] | 594 | static bt_os_callouts_t* wakelock_os_callouts_saved = nullptr; |
| 595 | |
| 596 | static int acquire_wake_lock_cb(const char* lock_name) { |
Jack He | 85ec113 | 2021-05-20 17:59:45 -0700 | [diff] [blame] | 597 | return do_in_jni_thread( |
Pavlin Radoslavov | 34bd633 | 2018-08-24 18:45:16 -0700 | [diff] [blame] | 598 | FROM_HERE, base::Bind(base::IgnoreResult( |
| 599 | wakelock_os_callouts_saved->acquire_wake_lock), |
| 600 | lock_name)); |
| 601 | } |
| 602 | |
| 603 | static int release_wake_lock_cb(const char* lock_name) { |
Jack He | 85ec113 | 2021-05-20 17:59:45 -0700 | [diff] [blame] | 604 | return do_in_jni_thread( |
Pavlin Radoslavov | 34bd633 | 2018-08-24 18:45:16 -0700 | [diff] [blame] | 605 | FROM_HERE, base::Bind(base::IgnoreResult( |
| 606 | wakelock_os_callouts_saved->release_wake_lock), |
| 607 | lock_name)); |
| 608 | } |
| 609 | |
| 610 | static bt_os_callouts_t wakelock_os_callouts_jni = { |
| 611 | sizeof(wakelock_os_callouts_jni), |
| 612 | nullptr /* not used */, |
| 613 | acquire_wake_lock_cb, |
| 614 | release_wake_lock_cb, |
| 615 | }; |
| 616 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 617 | static int set_os_callouts(bt_os_callouts_t* callouts) { |
Pavlin Radoslavov | 34bd633 | 2018-08-24 18:45:16 -0700 | [diff] [blame] | 618 | wakelock_os_callouts_saved = callouts; |
| 619 | wakelock_set_os_callouts(&wakelock_os_callouts_jni); |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 620 | return BT_STATUS_SUCCESS; |
Sharvil Nanavati | 55e690a | 2014-05-28 17:09:46 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Ajay Panicker | ec10208 | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 623 | static int config_clear(void) { |
Jakub Pawlowski | 13ee9b8 | 2020-03-05 21:16:10 +0100 | [diff] [blame] | 624 | LOG_INFO("%s", __func__); |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 625 | return btif_config_clear() ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; |
Ajay Panicker | ec10208 | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Ajay Panicker | 9e1c958 | 2018-03-14 23:45:54 -0700 | [diff] [blame] | 628 | static bluetooth::avrcp::ServiceInterface* get_avrcp_service(void) { |
| 629 | return bluetooth::avrcp::AvrcpService::GetServiceInterface(); |
| 630 | } |
| 631 | |
Jack He | 9183fd3 | 2018-11-16 02:59:43 -0800 | [diff] [blame] | 632 | static std::string obfuscate_address(const RawAddress& address) { |
| 633 | return bluetooth::common::AddressObfuscator::GetInstance()->Obfuscate( |
| 634 | address); |
| 635 | } |
| 636 | |
Chen Chen | 88ca6ae | 2020-03-05 15:02:46 -0800 | [diff] [blame] | 637 | static int get_metric_id(const RawAddress& address) { |
Chen Chen | 534bf24 | 2021-03-10 15:41:42 -0800 | [diff] [blame] | 638 | return allocate_metric_id_from_metric_id_allocator(address); |
Chen Chen | 88ca6ae | 2020-03-05 15:02:46 -0800 | [diff] [blame] | 639 | } |
| 640 | |
More Kuo | 82c341f | 2020-08-13 14:30:33 +0800 | [diff] [blame] | 641 | static int set_dynamic_audio_buffer_size(int codec, int size) { |
| 642 | return btif_set_dynamic_audio_buffer_size(codec, size); |
| 643 | } |
| 644 | |
Chen Chen | 31348f2 | 2022-01-13 17:57:01 -0800 | [diff] [blame] | 645 | static bool allow_low_latency_audio(bool allowed, const RawAddress& address) { |
| 646 | LOG_INFO("%s %s", __func__, allowed ? "true" : "false"); |
Chen Chen | c989bf8 | 2022-02-14 18:26:50 -0800 | [diff] [blame] | 647 | bluetooth::audio::a2dp::set_audio_low_latency_mode_allowed(allowed); |
| 648 | return true; |
Chen Chen | 31348f2 | 2022-01-13 17:57:01 -0800 | [diff] [blame] | 649 | } |
| 650 | |
Jakub Pawlowski | 5f52ab0 | 2017-10-16 15:57:16 -0700 | [diff] [blame] | 651 | EXPORT_SYMBOL bt_interface_t bluetoothInterface = { |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 652 | sizeof(bluetoothInterface), |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 653 | init, |
| 654 | enable, |
| 655 | disable, |
| 656 | cleanup, |
| 657 | get_adapter_properties, |
| 658 | get_adapter_property, |
| 659 | set_adapter_property, |
| 660 | get_remote_device_properties, |
| 661 | get_remote_device_property, |
| 662 | set_remote_device_property, |
Zach Johnson | a322993 | 2020-08-17 12:55:28 -0700 | [diff] [blame] | 663 | nullptr, |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 664 | get_remote_services, |
| 665 | start_discovery, |
| 666 | cancel_discovery, |
| 667 | create_bond, |
Jakub Pawlowski | df0ab81 | 2015-12-01 12:14:22 -0800 | [diff] [blame] | 668 | create_bond_out_of_band, |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 669 | remove_bond, |
| 670 | cancel_bond, |
Andre Eisenbach | 4a6f8cf | 2014-06-18 12:20:37 -0700 | [diff] [blame] | 671 | get_connection_state, |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 672 | pin_reply, |
| 673 | ssp_reply, |
| 674 | get_profile_interface, |
| 675 | dut_mode_configure, |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 676 | dut_mode_send, |
Zhihai Xu | 8572d79 | 2013-06-04 18:21:25 -0700 | [diff] [blame] | 677 | le_test_mode, |
Sharvil Nanavati | 55e690a | 2014-05-28 17:09:46 -0700 | [diff] [blame] | 678 | set_os_callouts, |
Satya Calloji | 75fd880 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 679 | read_energy_info, |
Ajay Panicker | ec10208 | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 680 | dump, |
Jack He | d20346ab | 2018-01-31 16:51:26 -0800 | [diff] [blame] | 681 | dumpMetrics, |
Andre Eisenbach | 35c0c1d6 | 2016-01-14 02:00:24 -0800 | [diff] [blame] | 682 | config_clear, |
| 683 | interop_database_clear, |
| 684 | interop_database_add, |
Ajay Panicker | 9e1c958 | 2018-03-14 23:45:54 -0700 | [diff] [blame] | 685 | get_avrcp_service, |
Jack He | 9183fd3 | 2018-11-16 02:59:43 -0800 | [diff] [blame] | 686 | obfuscate_address, |
Chen Chen | 88ca6ae | 2020-03-05 15:02:46 -0800 | [diff] [blame] | 687 | get_metric_id, |
More Kuo | 82c341f | 2020-08-13 14:30:33 +0800 | [diff] [blame] | 688 | set_dynamic_audio_buffer_size, |
Chen Chen | 31348f2 | 2022-01-13 17:57:01 -0800 | [diff] [blame] | 689 | generate_local_oob_data, |
Martin Brabham | 08eeffa | 2022-01-26 18:50:36 +0000 | [diff] [blame] | 690 | allow_low_latency_audio, |
| 691 | clear_event_filter}; |
Zach Johnson | b3b0a03 | 2020-08-14 15:42:22 -0700 | [diff] [blame] | 692 | |
| 693 | // callback reporting helpers |
| 694 | |
| 695 | bt_property_t* property_deep_copy_array(int num_properties, |
| 696 | bt_property_t* properties) { |
| 697 | bt_property_t* copy = nullptr; |
| 698 | if (num_properties > 0) { |
| 699 | size_t content_len = 0; |
| 700 | for (int i = 0; i < num_properties; i++) { |
| 701 | auto len = properties[i].len; |
| 702 | if (len > 0) { |
| 703 | content_len += len; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | copy = (bt_property_t*)osi_calloc((sizeof(bt_property_t) * num_properties) + |
| 708 | content_len); |
Chris Manton | 43fd493 | 2021-07-11 10:51:26 -0700 | [diff] [blame] | 709 | ASSERT(copy != nullptr); |
Zach Johnson | b3b0a03 | 2020-08-14 15:42:22 -0700 | [diff] [blame] | 710 | uint8_t* content = (uint8_t*)(copy + num_properties); |
| 711 | |
| 712 | for (int i = 0; i < num_properties; i++) { |
| 713 | auto len = properties[i].len; |
| 714 | copy[i].type = properties[i].type; |
| 715 | copy[i].len = len; |
| 716 | if (len <= 0) { |
| 717 | continue; |
| 718 | } |
| 719 | copy[i].val = content; |
| 720 | memcpy(content, properties[i].val, len); |
| 721 | content += len; |
| 722 | } |
| 723 | } |
| 724 | return copy; |
| 725 | } |
| 726 | |
Zach Johnson | 96f0c59 | 2020-08-14 15:52:36 -0700 | [diff] [blame] | 727 | void invoke_adapter_state_changed_cb(bt_state_t state) { |
| 728 | do_in_jni_thread(FROM_HERE, base::BindOnce( |
| 729 | [](bt_state_t state) { |
| 730 | HAL_CBACK(bt_hal_cbacks, |
| 731 | adapter_state_changed_cb, state); |
| 732 | }, |
| 733 | state)); |
| 734 | } |
| 735 | |
Zach Johnson | b3b0a03 | 2020-08-14 15:42:22 -0700 | [diff] [blame] | 736 | void invoke_adapter_properties_cb(bt_status_t status, int num_properties, |
| 737 | bt_property_t* properties) { |
| 738 | do_in_jni_thread(FROM_HERE, |
| 739 | base::BindOnce( |
| 740 | [](bt_status_t status, int num_properties, |
| 741 | bt_property_t* properties) { |
| 742 | HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, status, |
| 743 | num_properties, properties); |
| 744 | if (properties) { |
| 745 | osi_free(properties); |
| 746 | } |
| 747 | }, |
| 748 | status, num_properties, |
| 749 | property_deep_copy_array(num_properties, properties))); |
| 750 | } |
Zach Johnson | ac73b31 | 2020-08-14 16:02:11 -0700 | [diff] [blame] | 751 | |
| 752 | void invoke_remote_device_properties_cb(bt_status_t status, RawAddress bd_addr, |
| 753 | int num_properties, |
| 754 | bt_property_t* properties) { |
| 755 | do_in_jni_thread( |
| 756 | FROM_HERE, base::BindOnce( |
| 757 | [](bt_status_t status, RawAddress bd_addr, |
| 758 | int num_properties, bt_property_t* properties) { |
| 759 | HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, |
| 760 | status, &bd_addr, num_properties, properties); |
| 761 | if (properties) { |
| 762 | osi_free(properties); |
| 763 | } |
| 764 | }, |
| 765 | status, bd_addr, num_properties, |
| 766 | property_deep_copy_array(num_properties, properties))); |
| 767 | } |
Zach Johnson | 66bbfee | 2020-08-14 16:06:59 -0700 | [diff] [blame] | 768 | |
| 769 | void invoke_device_found_cb(int num_properties, bt_property_t* properties) { |
| 770 | do_in_jni_thread(FROM_HERE, |
| 771 | base::BindOnce( |
| 772 | [](int num_properties, bt_property_t* properties) { |
| 773 | HAL_CBACK(bt_hal_cbacks, device_found_cb, |
| 774 | num_properties, properties); |
| 775 | if (properties) { |
| 776 | osi_free(properties); |
| 777 | } |
| 778 | }, |
| 779 | num_properties, |
| 780 | property_deep_copy_array(num_properties, properties))); |
| 781 | } |
Zach Johnson | 4ae115e | 2020-08-14 16:11:09 -0700 | [diff] [blame] | 782 | |
| 783 | void invoke_discovery_state_changed_cb(bt_discovery_state_t state) { |
| 784 | do_in_jni_thread(FROM_HERE, base::BindOnce( |
| 785 | [](bt_discovery_state_t state) { |
| 786 | HAL_CBACK(bt_hal_cbacks, |
| 787 | discovery_state_changed_cb, |
| 788 | state); |
| 789 | }, |
| 790 | state)); |
| 791 | } |
Zach Johnson | 28f22c4 | 2020-08-14 16:15:26 -0700 | [diff] [blame] | 792 | |
| 793 | void invoke_pin_request_cb(RawAddress bd_addr, bt_bdname_t bd_name, |
| 794 | uint32_t cod, bool min_16_digit) { |
| 795 | do_in_jni_thread(FROM_HERE, base::BindOnce( |
| 796 | [](RawAddress bd_addr, bt_bdname_t bd_name, |
| 797 | uint32_t cod, bool min_16_digit) { |
| 798 | HAL_CBACK(bt_hal_cbacks, pin_request_cb, |
| 799 | &bd_addr, &bd_name, cod, |
| 800 | min_16_digit); |
| 801 | }, |
| 802 | bd_addr, bd_name, cod, min_16_digit)); |
| 803 | } |
Zach Johnson | 66ba306 | 2020-08-14 16:23:45 -0700 | [diff] [blame] | 804 | |
| 805 | void invoke_ssp_request_cb(RawAddress bd_addr, bt_bdname_t bd_name, |
| 806 | uint32_t cod, bt_ssp_variant_t pairing_variant, |
| 807 | uint32_t pass_key) { |
| 808 | do_in_jni_thread(FROM_HERE, |
| 809 | base::BindOnce( |
| 810 | [](RawAddress bd_addr, bt_bdname_t bd_name, uint32_t cod, |
| 811 | bt_ssp_variant_t pairing_variant, uint32_t pass_key) { |
| 812 | HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, |
| 813 | &bd_name, cod, pairing_variant, pass_key); |
| 814 | }, |
| 815 | bd_addr, bd_name, cod, pairing_variant, pass_key)); |
| 816 | } |
Zach Johnson | 31cea6c | 2020-08-14 16:35:12 -0700 | [diff] [blame] | 817 | |
Martin Brabham | bbe7f09 | 2021-03-31 09:41:34 -0700 | [diff] [blame] | 818 | void invoke_oob_data_request_cb(tBT_TRANSPORT t, bool valid, Octet16 c, |
Martin Brabham | db03553 | 2021-05-20 14:30:09 -0700 | [diff] [blame] | 819 | Octet16 r, RawAddress raw_address, |
| 820 | uint8_t address_type) { |
Martin Brabham | bbe7f09 | 2021-03-31 09:41:34 -0700 | [diff] [blame] | 821 | LOG_INFO("%s", __func__); |
Martin Brabham | 0c64cea | 2021-04-26 21:35:22 -0700 | [diff] [blame] | 822 | bt_oob_data_t oob_data = {}; |
Chris Manton | 9ce9711 | 2022-01-15 14:47:12 -0800 | [diff] [blame] | 823 | const char* local_name; |
Martin Brabham | afea75b | 2021-06-30 12:08:02 -0700 | [diff] [blame] | 824 | BTM_ReadLocalDeviceName(&local_name); |
| 825 | for (int i = 0; i < BTM_MAX_LOC_BD_NAME_LEN; i++) { |
| 826 | oob_data.device_name[i] = local_name[i]; |
| 827 | } |
Martin Brabham | 0c64cea | 2021-04-26 21:35:22 -0700 | [diff] [blame] | 828 | |
| 829 | // Set the local address |
| 830 | int j = 5; |
| 831 | for (int i = 0; i < 6; i++) { |
| 832 | oob_data.address[i] = raw_address.address[j]; |
| 833 | j--; |
| 834 | } |
Martin Brabham | db03553 | 2021-05-20 14:30:09 -0700 | [diff] [blame] | 835 | oob_data.address[6] = address_type; |
Martin Brabham | 0c64cea | 2021-04-26 21:35:22 -0700 | [diff] [blame] | 836 | |
Martin Brabham | bbe7f09 | 2021-03-31 09:41:34 -0700 | [diff] [blame] | 837 | // Each value (for C and R) is 16 octets in length |
| 838 | bool c_empty = true; |
| 839 | for (int i = 0; i < 16; i++) { |
| 840 | // C cannot be all 0s, if so then we want to fail |
| 841 | if (c[i] != 0) c_empty = false; |
| 842 | oob_data.c[i] = c[i]; |
| 843 | // R is optional and may be empty |
| 844 | oob_data.r[i] = r[i]; |
| 845 | } |
| 846 | oob_data.is_valid = valid && !c_empty; |
| 847 | // The oob_data_length is 2 octects in length. The value includes the length |
| 848 | // of itself. 16 + 16 + 2 = 34 Data 0x0022 Little Endian order 0x2200 |
| 849 | oob_data.oob_data_length[0] = 0; |
| 850 | oob_data.oob_data_length[1] = 34; |
| 851 | bt_status_t status = do_in_jni_thread( |
| 852 | FROM_HERE, base::BindOnce( |
| 853 | [](tBT_TRANSPORT t, bt_oob_data_t oob_data) { |
| 854 | HAL_CBACK(bt_hal_cbacks, generate_local_oob_data_cb, t, |
| 855 | oob_data); |
| 856 | }, |
| 857 | t, oob_data)); |
| 858 | if (status != BT_STATUS_SUCCESS) { |
| 859 | LOG_ERROR("%s: Failed to call callback!", __func__); |
| 860 | } |
| 861 | } |
| 862 | |
Zach Johnson | 31cea6c | 2020-08-14 16:35:12 -0700 | [diff] [blame] | 863 | void invoke_bond_state_changed_cb(bt_status_t status, RawAddress bd_addr, |
wescande | b819e4e | 2021-07-27 11:15:49 +0200 | [diff] [blame] | 864 | bt_bond_state_t state, int fail_reason) { |
| 865 | do_in_jni_thread(FROM_HERE, base::BindOnce( |
| 866 | [](bt_status_t status, RawAddress bd_addr, |
| 867 | bt_bond_state_t state, int fail_reason) { |
| 868 | HAL_CBACK(bt_hal_cbacks, |
| 869 | bond_state_changed_cb, status, |
| 870 | &bd_addr, state, fail_reason); |
| 871 | }, |
| 872 | status, bd_addr, state, fail_reason)); |
Zach Johnson | 31cea6c | 2020-08-14 16:35:12 -0700 | [diff] [blame] | 873 | } |
Zach Johnson | 9de212d | 2020-08-14 16:38:27 -0700 | [diff] [blame] | 874 | |
Chienyuan | 21c28c4 | 2021-11-09 15:10:56 +0800 | [diff] [blame] | 875 | void invoke_address_consolidate_cb(RawAddress main_bd_addr, |
| 876 | RawAddress secondary_bd_addr) { |
| 877 | do_in_jni_thread( |
| 878 | FROM_HERE, base::BindOnce( |
| 879 | [](RawAddress main_bd_addr, RawAddress secondary_bd_addr) { |
| 880 | HAL_CBACK(bt_hal_cbacks, address_consolidate_cb, |
| 881 | &main_bd_addr, &secondary_bd_addr); |
| 882 | }, |
| 883 | main_bd_addr, secondary_bd_addr)); |
| 884 | } |
| 885 | |
Rahul Sabnis | 7391423 | 2022-07-01 14:03:28 -0700 | [diff] [blame] | 886 | void invoke_le_address_associate_cb(RawAddress main_bd_addr, |
| 887 | RawAddress secondary_bd_addr) { |
| 888 | do_in_jni_thread( |
| 889 | FROM_HERE, base::BindOnce( |
| 890 | [](RawAddress main_bd_addr, RawAddress secondary_bd_addr) { |
| 891 | HAL_CBACK(bt_hal_cbacks, le_address_associate_cb, |
| 892 | &main_bd_addr, &secondary_bd_addr); |
| 893 | }, |
| 894 | main_bd_addr, secondary_bd_addr)); |
| 895 | } |
Zach Johnson | 9de212d | 2020-08-14 16:38:27 -0700 | [diff] [blame] | 896 | void invoke_acl_state_changed_cb(bt_status_t status, RawAddress bd_addr, |
wescande | b819e4e | 2021-07-27 11:15:49 +0200 | [diff] [blame] | 897 | bt_acl_state_t state, int transport_link_type, |
| 898 | bt_hci_error_code_t hci_reason) { |
Zach Johnson | 9de212d | 2020-08-14 16:38:27 -0700 | [diff] [blame] | 899 | do_in_jni_thread( |
| 900 | FROM_HERE, |
| 901 | base::BindOnce( |
Andrew Cheng | 261f360 | 2021-01-14 17:28:13 -0800 | [diff] [blame] | 902 | [](bt_status_t status, RawAddress bd_addr, bt_acl_state_t state, |
wescande | b819e4e | 2021-07-27 11:15:49 +0200 | [diff] [blame] | 903 | int transport_link_type, bt_hci_error_code_t hci_reason) { |
Zach Johnson | 9de212d | 2020-08-14 16:38:27 -0700 | [diff] [blame] | 904 | HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, status, &bd_addr, |
wescande | b819e4e | 2021-07-27 11:15:49 +0200 | [diff] [blame] | 905 | state, transport_link_type, hci_reason); |
Zach Johnson | 9de212d | 2020-08-14 16:38:27 -0700 | [diff] [blame] | 906 | }, |
wescande | b819e4e | 2021-07-27 11:15:49 +0200 | [diff] [blame] | 907 | status, bd_addr, state, transport_link_type, hci_reason)); |
Zach Johnson | 9de212d | 2020-08-14 16:38:27 -0700 | [diff] [blame] | 908 | } |
Zach Johnson | 21c7378 | 2020-08-14 16:43:57 -0700 | [diff] [blame] | 909 | |
| 910 | void invoke_thread_evt_cb(bt_cb_thread_evt event) { |
| 911 | do_in_jni_thread(FROM_HERE, base::BindOnce( |
| 912 | [](bt_cb_thread_evt event) { |
| 913 | HAL_CBACK(bt_hal_cbacks, thread_evt_cb, |
| 914 | event); |
| 915 | if (event == DISASSOCIATE_JVM) { |
| 916 | bt_hal_cbacks = NULL; |
| 917 | } |
| 918 | }, |
| 919 | event)); |
| 920 | } |
Zach Johnson | 9a82297 | 2020-08-14 16:48:46 -0700 | [diff] [blame] | 921 | |
| 922 | void invoke_le_test_mode_cb(bt_status_t status, uint16_t count) { |
| 923 | do_in_jni_thread(FROM_HERE, base::BindOnce( |
| 924 | [](bt_status_t status, uint16_t count) { |
| 925 | HAL_CBACK(bt_hal_cbacks, le_test_mode_cb, |
| 926 | status, count); |
| 927 | }, |
| 928 | status, count)); |
| 929 | } |
Zach Johnson | a259473 | 2020-08-14 16:56:42 -0700 | [diff] [blame] | 930 | |
| 931 | // takes ownership of |uid_data| |
| 932 | void invoke_energy_info_cb(bt_activity_energy_info energy_info, |
| 933 | bt_uid_traffic_t* uid_data) { |
| 934 | do_in_jni_thread( |
| 935 | FROM_HERE, |
| 936 | base::BindOnce( |
| 937 | [](bt_activity_energy_info energy_info, bt_uid_traffic_t* uid_data) { |
| 938 | HAL_CBACK(bt_hal_cbacks, energy_info_cb, &energy_info, uid_data); |
| 939 | osi_free(uid_data); |
| 940 | }, |
| 941 | energy_info, uid_data)); |
| 942 | } |
Chen Chen | d35a71e | 2021-02-04 17:38:31 -0800 | [diff] [blame] | 943 | |
| 944 | void invoke_link_quality_report_cb( |
| 945 | uint64_t timestamp, int report_id, int rssi, int snr, |
| 946 | int retransmission_count, int packets_not_receive_count, |
| 947 | int negative_acknowledgement_count) { |
| 948 | do_in_jni_thread( |
| 949 | FROM_HERE, |
| 950 | base::BindOnce( |
| 951 | [](uint64_t timestamp, int report_id, int rssi, int snr, |
| 952 | int retransmission_count, int packets_not_receive_count, |
| 953 | int negative_acknowledgement_count) { |
| 954 | HAL_CBACK(bt_hal_cbacks, link_quality_report_cb, |
| 955 | timestamp, report_id, rssi, snr, retransmission_count, |
| 956 | packets_not_receive_count, |
| 957 | negative_acknowledgement_count); |
| 958 | }, |
| 959 | timestamp, report_id, rssi, snr, retransmission_count, |
| 960 | packets_not_receive_count, negative_acknowledgement_count)); |
| 961 | } |
Chen Chen | a81d2c6 | 2022-01-19 12:10:20 -0800 | [diff] [blame] | 962 | |
Chen Chen | f41721c | 2022-02-11 12:13:48 -0800 | [diff] [blame] | 963 | void invoke_switch_buffer_size_cb(bool is_low_latency_buffer_size) { |
Chen Chen | a81d2c6 | 2022-01-19 12:10:20 -0800 | [diff] [blame] | 964 | do_in_jni_thread( |
| 965 | FROM_HERE, |
| 966 | base::BindOnce( |
Chen Chen | f41721c | 2022-02-11 12:13:48 -0800 | [diff] [blame] | 967 | [](bool is_low_latency_buffer_size) { |
| 968 | HAL_CBACK(bt_hal_cbacks, switch_buffer_size_cb, |
Chen Chen | a81d2c6 | 2022-01-19 12:10:20 -0800 | [diff] [blame] | 969 | is_low_latency_buffer_size); |
| 970 | }, |
Chen Chen | f41721c | 2022-02-11 12:13:48 -0800 | [diff] [blame] | 971 | is_low_latency_buffer_size)); |
Chen Chen | a81d2c6 | 2022-01-19 12:10:20 -0800 | [diff] [blame] | 972 | } |
Chen Chen | 63cee1a | 2022-02-15 18:39:16 -0800 | [diff] [blame] | 973 | |
| 974 | void invoke_switch_codec_cb(bool is_low_latency_buffer_size) { |
| 975 | do_in_jni_thread(FROM_HERE, base::BindOnce( |
| 976 | [](bool is_low_latency_buffer_size) { |
| 977 | HAL_CBACK(bt_hal_cbacks, switch_codec_cb, |
| 978 | is_low_latency_buffer_size); |
| 979 | }, |
| 980 | is_low_latency_buffer_size)); |
| 981 | } |