The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2009-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
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 | |
Andre Eisenbach | 80c23e5 | 2016-02-17 12:43:12 -0800 | [diff] [blame] | 29 | #include <assert.h> |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
Scott James Remnant | 34121f5 | 2015-04-02 15:22:14 -0700 | [diff] [blame] | 32 | #include <string.h> |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 33 | #include <unistd.h> |
| 34 | |
| 35 | #include <hardware/bluetooth.h> |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 36 | #include <hardware/bt_av.h> |
| 37 | #include <hardware/bt_gatt.h> |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 38 | #include <hardware/bt_hf.h> |
Hemant Gupta | d9e9cf9 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 39 | #include <hardware/bt_hf_client.h> |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 40 | #include <hardware/bt_hh.h> |
| 41 | #include <hardware/bt_hl.h> |
Hemant Gupta | d0ecdbb | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 42 | #include <hardware/bt_mce.h> |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 43 | #include <hardware/bt_pan.h> |
Ravi Nagarajan | 78b3520 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 44 | #include <hardware/bt_rc.h> |
Kim Schulz | b2337fe | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 45 | #include <hardware/bt_sdp.h> |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 46 | #include <hardware/bt_sock.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" |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 49 | #include "btif/include/btif_debug_btsnoop.h" |
| 50 | #include "btif/include/btif_debug_conn.h" |
Pavlin Radoslavov | cd10201 | 2016-09-23 16:36:47 -0700 | [diff] [blame] | 51 | #include "btif_a2dp.h" |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 52 | #include "btif_api.h" |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 53 | #include "btif_config.h" |
Andre Eisenbach | 8f6c5be | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 54 | #include "btif_debug.h" |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 55 | #include "btif_storage.h" |
Zach Johnson | 0323466 | 2014-09-22 22:11:55 -0700 | [diff] [blame] | 56 | #include "btsnoop.h" |
Andre Eisenbach | 8f6c5be | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 57 | #include "btsnoop_mem.h" |
Andre Eisenbach | 35c0c1d6 | 2016-01-14 02:00:24 -0800 | [diff] [blame] | 58 | #include "device/include/interop.h" |
Pavlin Radoslavov | 30698fa | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 59 | #include "osi/include/alarm.h" |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 60 | #include "osi/include/allocation_tracker.h" |
Sharvil Nanavati | 8395177 | 2014-12-23 23:08:58 -0800 | [diff] [blame] | 61 | #include "osi/include/log.h" |
Marie Janssen | a84a4ee | 2016-01-15 16:14:14 -0800 | [diff] [blame] | 62 | #include "osi/include/metrics.h" |
Marie Janssen | e06e151 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 63 | #include "osi/include/osi.h" |
Pavlin Radoslavov | 5bb6cac | 2015-08-24 16:29:21 -0700 | [diff] [blame] | 64 | #include "osi/include/wakelock.h" |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 65 | #include "stack_manager.h" |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 66 | |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame^] | 67 | /******************************************************************************* |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 68 | * Static variables |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame^] | 69 | ******************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 70 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 71 | bt_callbacks_t* bt_hal_cbacks = NULL; |
Marie Janssen | 0fc1f13 | 2016-06-22 12:52:19 -0700 | [diff] [blame] | 72 | bool restricted_mode = false; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 73 | |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame^] | 74 | /******************************************************************************* |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 75 | * Externs |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame^] | 76 | ******************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 77 | |
| 78 | /* list all extended interfaces here */ |
| 79 | |
| 80 | /* handsfree profile */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 81 | extern bthf_interface_t* btif_hf_get_interface(); |
Hemant Gupta | d9e9cf9 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 82 | /* handsfree profile - client */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 83 | extern bthf_client_interface_t* btif_hf_client_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 84 | /* advanced audio profile */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 85 | extern btav_interface_t* btif_av_get_src_interface(); |
| 86 | extern btav_interface_t* btif_av_get_sink_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 87 | /*rfc l2cap*/ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 88 | extern btsock_interface_t* btif_sock_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 89 | /* hid host profile */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 90 | extern bthh_interface_t* btif_hh_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 91 | /* health device profile */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 92 | extern bthl_interface_t* btif_hl_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 93 | /*pan*/ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 94 | extern btpan_interface_t* btif_pan_get_interface(); |
Hemant Gupta | d0ecdbb | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 95 | /*map client*/ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 96 | extern btmce_interface_t* btif_mce_get_interface(); |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 97 | /* gatt */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 98 | extern const btgatt_interface_t* btif_gatt_get_interface(); |
Mike Lockwood | c02ef77 | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 99 | /* avrc target */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 100 | extern btrc_interface_t* btif_rc_get_interface(); |
Mike Lockwood | c02ef77 | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 101 | /* avrc controller */ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 102 | extern btrc_interface_t* btif_rc_ctrl_get_interface(); |
Kim Schulz | b2337fe | 2015-03-25 10:39:40 +0100 | [diff] [blame] | 103 | /*SDP search client*/ |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 104 | extern btsdp_interface_t* btif_sdp_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 105 | |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame^] | 106 | /******************************************************************************* |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 107 | * Functions |
Myles Watson | fbfa1a5 | 2016-11-23 14:49:54 -0800 | [diff] [blame^] | 108 | ******************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 109 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 110 | 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] | 111 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 112 | static bool is_profile(const char* p1, const char* p2) { |
Andre Eisenbach | 80c23e5 | 2016-02-17 12:43:12 -0800 | [diff] [blame] | 113 | assert(p1); |
| 114 | assert(p2); |
| 115 | return strlen(p1) == strlen(p2) && strncmp(p1, p2, strlen(p2)) == 0; |
| 116 | } |
| 117 | |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 118 | /***************************************************************************** |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 119 | * |
| 120 | * BLUETOOTH HAL INTERFACE FUNCTIONS |
| 121 | * |
| 122 | ****************************************************************************/ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 123 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 124 | static int init(bt_callbacks_t* callbacks) { |
Marie Janssen | fc8006e | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 125 | LOG_INFO(LOG_TAG, "%s", __func__); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 126 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 127 | if (interface_ready()) return BT_STATUS_DONE; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 128 | |
Sharvil Nanavati | 19f4b18 | 2014-11-13 01:04:19 -0800 | [diff] [blame] | 129 | #ifdef BLUEDROID_DEBUG |
| 130 | allocation_tracker_init(); |
| 131 | #endif |
| 132 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 133 | bt_hal_cbacks = callbacks; |
| 134 | stack_manager_get_interface()->init_stack(); |
Andre Eisenbach | 8f6c5be | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 135 | btif_debug_init(); |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 136 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 137 | } |
| 138 | |
Ajay Panicker | c796ac8 | 2016-03-17 17:09:24 -0700 | [diff] [blame] | 139 | static int enable(bool start_restricted) { |
| 140 | LOG_INFO(LOG_TAG, "%s: start restricted = %d", __func__, start_restricted); |
| 141 | |
| 142 | restricted_mode = start_restricted; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 143 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 144 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 145 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 146 | stack_manager_get_interface()->start_up_stack_async(); |
| 147 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 148 | } |
| 149 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 150 | static int disable(void) { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 151 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 152 | |
Zach Johnson | ed9491b | 2014-09-09 16:31:14 -0700 | [diff] [blame] | 153 | stack_manager_get_interface()->shut_down_stack_async(); |
| 154 | return BT_STATUS_SUCCESS; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 155 | } |
| 156 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 157 | static void cleanup(void) { stack_manager_get_interface()->clean_up_stack(); } |
| 158 | |
| 159 | bool is_restricted_mode() { return restricted_mode; } |
| 160 | |
| 161 | static int get_adapter_properties(void) { |
| 162 | /* sanity check */ |
| 163 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
| 164 | |
| 165 | return btif_get_adapter_properties(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 168 | static int get_adapter_property(bt_property_type_t type) { |
| 169 | /* sanity check */ |
| 170 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
| 171 | |
| 172 | return btif_get_adapter_property(type); |
Ajay Panicker | c796ac8 | 2016-03-17 17:09:24 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 175 | static int set_adapter_property(const bt_property_t* property) { |
| 176 | /* sanity check */ |
| 177 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 178 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 179 | return btif_set_adapter_property(property); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 182 | int get_remote_device_properties(bt_bdaddr_t* remote_addr) { |
| 183 | /* sanity check */ |
| 184 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 185 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 186 | return btif_get_remote_device_properties(remote_addr); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 187 | } |
| 188 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 189 | int get_remote_device_property(bt_bdaddr_t* remote_addr, |
| 190 | bt_property_type_t type) { |
| 191 | /* sanity check */ |
| 192 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 193 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 194 | return btif_get_remote_device_property(remote_addr, type); |
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 | int set_remote_device_property(bt_bdaddr_t* remote_addr, |
| 198 | const bt_property_t* property) { |
| 199 | /* sanity check */ |
| 200 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 201 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 202 | return btif_set_remote_device_property(remote_addr, property); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 205 | int get_remote_service_record(bt_bdaddr_t* remote_addr, bt_uuid_t* uuid) { |
| 206 | /* sanity check */ |
| 207 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 208 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 209 | return btif_get_remote_service_record(remote_addr, uuid); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 212 | int get_remote_services(bt_bdaddr_t* remote_addr) { |
| 213 | /* sanity check */ |
| 214 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 215 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 216 | return btif_dm_get_remote_services(remote_addr); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 219 | static int start_discovery(void) { |
| 220 | /* sanity check */ |
| 221 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 223 | return btif_dm_start_discovery(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 226 | static int cancel_discovery(void) { |
| 227 | /* sanity check */ |
| 228 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 229 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 230 | return btif_dm_cancel_discovery(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 233 | static int create_bond(const bt_bdaddr_t* bd_addr, int transport) { |
| 234 | /* sanity check */ |
| 235 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 236 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 237 | return btif_dm_create_bond(bd_addr, transport); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 240 | static int create_bond_out_of_band(const bt_bdaddr_t* bd_addr, int transport, |
| 241 | const bt_out_of_band_data_t* oob_data) { |
| 242 | /* sanity check */ |
| 243 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 244 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 245 | return btif_dm_create_bond_out_of_band(bd_addr, transport, oob_data); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 248 | static int cancel_bond(const bt_bdaddr_t* bd_addr) { |
| 249 | /* sanity check */ |
| 250 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 251 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 252 | return btif_dm_cancel_bond(bd_addr); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 255 | static int remove_bond(const bt_bdaddr_t* bd_addr) { |
| 256 | if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr)) |
Satya Calloji | 75fd880 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 257 | return BT_STATUS_SUCCESS; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 258 | |
| 259 | /* sanity check */ |
| 260 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
| 261 | |
| 262 | return btif_dm_remove_bond(bd_addr); |
Satya Calloji | 75fd880 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 265 | static int get_connection_state(const bt_bdaddr_t* bd_addr) { |
| 266 | /* sanity check */ |
| 267 | if (interface_ready() == false) return 0; |
| 268 | |
| 269 | return btif_dm_get_connection_state(bd_addr); |
| 270 | } |
| 271 | |
| 272 | static int pin_reply(const bt_bdaddr_t* bd_addr, uint8_t accept, |
| 273 | uint8_t pin_len, bt_pin_code_t* pin_code) { |
| 274 | /* sanity check */ |
| 275 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
| 276 | |
| 277 | return btif_dm_pin_reply(bd_addr, accept, pin_len, pin_code); |
| 278 | } |
| 279 | |
| 280 | static int ssp_reply(const bt_bdaddr_t* bd_addr, bt_ssp_variant_t variant, |
| 281 | uint8_t accept, uint32_t passkey) { |
| 282 | /* sanity check */ |
| 283 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
| 284 | |
| 285 | return btif_dm_ssp_reply(bd_addr, variant, accept, passkey); |
| 286 | } |
| 287 | |
| 288 | static int read_energy_info() { |
| 289 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
| 290 | btif_dm_read_energy_info(); |
| 291 | return BT_STATUS_SUCCESS; |
| 292 | } |
| 293 | |
| 294 | static void dump(int fd, const char** arguments) { |
| 295 | if (arguments != NULL && arguments[0] != NULL) { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 296 | if (strncmp(arguments[0], "--proto-bin", 11) == 0) { |
| 297 | btif_update_a2dp_metrics(); |
| 298 | metrics_write(fd, true); |
| 299 | return; |
| 300 | } |
| 301 | } |
| 302 | btif_debug_conn_dump(fd); |
| 303 | btif_debug_bond_event_dump(fd); |
| 304 | btif_debug_a2dp_dump(fd); |
| 305 | btif_debug_config_dump(fd); |
| 306 | wakelock_debug_dump(fd); |
| 307 | alarm_debug_dump(fd); |
Marie Janssen | 0fc1f13 | 2016-06-22 12:52:19 -0700 | [diff] [blame] | 308 | #if (BTSNOOP_MEM == TRUE) |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 309 | btif_debug_btsnoop_dump(fd); |
Pavlin Radoslavov | 30698fa | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 310 | #endif |
| 311 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 312 | close(fd); |
Andre Eisenbach | 8f6c5be | 2014-12-05 09:40:20 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 315 | static const void* get_profile_interface(const char* profile_id) { |
| 316 | LOG_INFO(LOG_TAG, "get_profile_interface %s", profile_id); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 317 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 318 | /* sanity check */ |
| 319 | if (interface_ready() == false) return NULL; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 320 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 321 | /* check for supported profile interfaces */ |
| 322 | if (is_profile(profile_id, BT_PROFILE_HANDSFREE_ID)) |
| 323 | return btif_hf_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 324 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 325 | if (is_profile(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID)) |
| 326 | return btif_hf_client_get_interface(); |
Hemant Gupta | d9e9cf9 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 327 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 328 | if (is_profile(profile_id, BT_PROFILE_SOCKETS_ID)) |
| 329 | return btif_sock_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 330 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 331 | if (is_profile(profile_id, BT_PROFILE_PAN_ID)) |
| 332 | return btif_pan_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 333 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 334 | if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID)) |
| 335 | return btif_av_get_src_interface(); |
Mike Lockwood | c80e2d7 | 2014-05-23 12:42:24 -0700 | [diff] [blame] | 336 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 337 | if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID)) |
| 338 | return btif_av_get_sink_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 339 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 340 | if (is_profile(profile_id, BT_PROFILE_HIDHOST_ID)) |
| 341 | return btif_hh_get_interface(); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 342 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 343 | if (is_profile(profile_id, BT_PROFILE_HEALTH_ID)) |
| 344 | return btif_hl_get_interface(); |
Ravi Nagarajan | 78b3520 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 345 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 346 | if (is_profile(profile_id, BT_PROFILE_SDP_CLIENT_ID)) |
| 347 | return btif_sdp_get_interface(); |
Hemant Gupta | d0ecdbb | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 348 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 349 | if (is_profile(profile_id, BT_PROFILE_GATT_ID)) |
| 350 | return btif_gatt_get_interface(); |
Ravi Nagarajan | 78b3520 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 351 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 352 | if (is_profile(profile_id, BT_PROFILE_AV_RC_ID)) |
| 353 | return btif_rc_get_interface(); |
Ravi Nagarajan | 78b3520 | 2013-03-06 05:29:48 -0800 | [diff] [blame] | 354 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 355 | if (is_profile(profile_id, BT_PROFILE_AV_RC_CTRL_ID)) |
| 356 | return btif_rc_ctrl_get_interface(); |
Mike Lockwood | c02ef77 | 2014-06-02 16:21:49 -0700 | [diff] [blame] | 357 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 358 | return NULL; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 361 | int dut_mode_configure(uint8_t enable) { |
| 362 | LOG_INFO(LOG_TAG, "dut_mode_configure"); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 363 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 364 | /* sanity check */ |
| 365 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 367 | return btif_dut_mode_configure(enable); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 370 | int dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len) { |
| 371 | LOG_INFO(LOG_TAG, "dut_mode_send"); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 372 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 373 | /* sanity check */ |
| 374 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 375 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 376 | return btif_dut_mode_send(opcode, buf, len); |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 377 | } |
Matthew Xie | 41fb436 | 2013-05-06 20:51:02 -0700 | [diff] [blame] | 378 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 379 | int le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { |
| 380 | LOG_INFO(LOG_TAG, "le_test_mode"); |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 381 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 382 | /* sanity check */ |
| 383 | if (interface_ready() == false) return BT_STATUS_NOT_READY; |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 384 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 385 | return btif_le_test_mode(opcode, buf, len); |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 386 | } |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 387 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 388 | int config_hci_snoop_log(uint8_t enable) { |
| 389 | LOG_INFO(LOG_TAG, "config_hci_snoop_log"); |
Zhihai Xu | 8572d79 | 2013-06-04 18:21:25 -0700 | [diff] [blame] | 390 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 391 | if (!interface_ready()) return BT_STATUS_NOT_READY; |
Zhihai Xu | 8572d79 | 2013-06-04 18:21:25 -0700 | [diff] [blame] | 392 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 393 | btsnoop_get_interface()->set_api_wants_to_log(enable); |
| 394 | return BT_STATUS_SUCCESS; |
Zhihai Xu | 8572d79 | 2013-06-04 18:21:25 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 397 | static int set_os_callouts(bt_os_callouts_t* callouts) { |
| 398 | wakelock_set_os_callouts(callouts); |
| 399 | return BT_STATUS_SUCCESS; |
Sharvil Nanavati | 55e690a | 2014-05-28 17:09:46 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Ajay Panicker | ec10208 | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 402 | static int config_clear(void) { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 403 | LOG_INFO(LOG_TAG, "%s", __func__); |
| 404 | return btif_config_clear() ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; |
Ajay Panicker | ec10208 | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 405 | } |
| 406 | |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 407 | static const bt_interface_t bluetoothInterface = { |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 408 | sizeof(bluetoothInterface), |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 409 | init, |
| 410 | enable, |
| 411 | disable, |
| 412 | cleanup, |
| 413 | get_adapter_properties, |
| 414 | get_adapter_property, |
| 415 | set_adapter_property, |
| 416 | get_remote_device_properties, |
| 417 | get_remote_device_property, |
| 418 | set_remote_device_property, |
| 419 | get_remote_service_record, |
| 420 | get_remote_services, |
| 421 | start_discovery, |
| 422 | cancel_discovery, |
| 423 | create_bond, |
Jakub Pawlowski | df0ab81 | 2015-12-01 12:14:22 -0800 | [diff] [blame] | 424 | create_bond_out_of_band, |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 425 | remove_bond, |
| 426 | cancel_bond, |
Andre Eisenbach | 4a6f8cf | 2014-06-18 12:20:37 -0700 | [diff] [blame] | 427 | get_connection_state, |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 428 | pin_reply, |
| 429 | ssp_reply, |
| 430 | get_profile_interface, |
| 431 | dut_mode_configure, |
Ganesh Ganapathi Batta | 1def255 | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 432 | dut_mode_send, |
Zhihai Xu | 8572d79 | 2013-06-04 18:21:25 -0700 | [diff] [blame] | 433 | le_test_mode, |
Sharvil Nanavati | 55e690a | 2014-05-28 17:09:46 -0700 | [diff] [blame] | 434 | config_hci_snoop_log, |
| 435 | set_os_callouts, |
Satya Calloji | 75fd880 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 436 | read_energy_info, |
Ajay Panicker | ec10208 | 2015-07-28 16:54:53 -0700 | [diff] [blame] | 437 | dump, |
Andre Eisenbach | 35c0c1d6 | 2016-01-14 02:00:24 -0800 | [diff] [blame] | 438 | config_clear, |
| 439 | interop_database_clear, |
| 440 | interop_database_add, |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 441 | }; |
| 442 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 443 | const bt_interface_t* bluetooth__get_bluetooth_interface() { |
| 444 | /* fixme -- add property to disable bt interface ? */ |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 445 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 446 | return &bluetoothInterface; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Myles Watson | 824963f | 2016-11-15 16:33:22 -0800 | [diff] [blame] | 449 | static int close_bluetooth_stack(UNUSED_ATTR struct hw_device_t* device) { |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 450 | cleanup(); |
| 451 | return 0; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 454 | static int open_bluetooth_stack(const struct hw_module_t* module, |
| 455 | UNUSED_ATTR char const* name, |
| 456 | struct hw_device_t** abstraction) { |
Jakub Pawlowski | 4a81383 | 2016-04-21 13:16:45 -0700 | [diff] [blame] | 457 | static bluetooth_device_t device; |
| 458 | device.common.tag = HARDWARE_DEVICE_TAG; |
| 459 | device.common.version = 0; |
| 460 | device.common.close = close_bluetooth_stack; |
| 461 | device.get_bluetooth_interface = bluetooth__get_bluetooth_interface; |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 462 | device.common.module = (struct hw_module_t*)module; |
| 463 | *abstraction = (struct hw_device_t*)&device; |
Sharvil Nanavati | 7e1f98a | 2014-08-29 15:39:56 -0700 | [diff] [blame] | 464 | return 0; |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 465 | } |
| 466 | |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 467 | static struct hw_module_methods_t bt_stack_module_methods = { |
| 468 | .open = open_bluetooth_stack, |
| 469 | }; |
| 470 | |
Ian Coolidge | 231c4ac | 2015-04-21 16:25:08 -0700 | [diff] [blame] | 471 | EXPORT_SYMBOL struct hw_module_t HAL_MODULE_INFO_SYM = { |
The Android Open Source Project | 624a787 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 472 | .tag = HARDWARE_MODULE_TAG, |
| 473 | .version_major = 1, |
| 474 | .version_minor = 0, |
| 475 | .id = BT_HARDWARE_MODULE_ID, |
| 476 | .name = "Bluetooth Stack", |
| 477 | .author = "The Android Open Source Project", |
Myles Watson | 3f68a75 | 2016-10-19 09:50:22 -0700 | [diff] [blame] | 478 | .methods = &bt_stack_module_methods}; |