Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2014 Google, Inc. |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [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 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 19 | #define LOG_TAG "bt_controller" |
| 20 | |
Chris Manton | 79ecab5 | 2014-10-31 14:54:51 -0700 | [diff] [blame] | 21 | #include "device/include/controller.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 22 | |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 23 | #include <base/logging.h> |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 24 | |
cb | a7cdd8e | 2017-09-28 16:31:59 +0800 | [diff] [blame] | 25 | #include "bt_target.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 26 | #include "bt_types.h" |
Sharvil Nanavati | 95b74f2 | 2015-03-12 15:55:21 -0700 | [diff] [blame] | 27 | #include "btcore/include/event_mask.h" |
Sharvil Nanavati | 95b74f2 | 2015-03-12 15:55:21 -0700 | [diff] [blame] | 28 | #include "btcore/include/module.h" |
Sharvil Nanavati | 95b74f2 | 2015-03-12 15:55:21 -0700 | [diff] [blame] | 29 | #include "btcore/include/version.h" |
Marie Janssen | 49a8670 | 2015-07-08 11:48:57 -0700 | [diff] [blame] | 30 | #include "hcimsgs.h" |
| 31 | #include "osi/include/future.h" |
| 32 | #include "stack/include/btm_ble_api.h" |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 33 | |
Jakub Pawlowski | 692a0ca | 2018-04-19 02:32:40 -0700 | [diff] [blame] | 34 | const bt_event_mask_t BLE_EVENT_MASK = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x02, |
| 35 | #if (BLE_PRIVACY_SPT == TRUE) |
| 36 | 0x1E, |
| 37 | #else |
| 38 | /* Disable "LE Enhanced Connection |
| 39 | Complete" when privacy is off */ |
| 40 | 0x1C, |
| 41 | #endif |
| 42 | 0x7f}}; |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 43 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 44 | const bt_event_mask_t CLASSIC_EVENT_MASK = {HCI_DUMO_EVENT_MASK_EXT}; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 45 | |
| 46 | // TODO(zachoverflow): factor out into common module |
| 47 | const uint8_t SCO_HOST_BUFFER_SIZE = 0xff; |
| 48 | |
| 49 | #define HCI_SUPPORTED_COMMANDS_ARRAY_SIZE 64 |
| 50 | #define MAX_FEATURES_CLASSIC_PAGE_COUNT 3 |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 51 | #define BLE_SUPPORTED_STATES_SIZE 8 |
| 52 | #define BLE_SUPPORTED_FEATURES_SIZE 8 |
| 53 | #define MAX_LOCAL_SUPPORTED_CODECS_SIZE 8 |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 54 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 55 | static const hci_t* hci; |
| 56 | static const hci_packet_factory_t* packet_factory; |
| 57 | static const hci_packet_parser_t* packet_parser; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 58 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 59 | static RawAddress address; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 60 | static bt_version_t bt_version; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 61 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 62 | static uint8_t supported_commands[HCI_SUPPORTED_COMMANDS_ARRAY_SIZE]; |
| 63 | static bt_device_features_t features_classic[MAX_FEATURES_CLASSIC_PAGE_COUNT]; |
| 64 | static uint8_t last_features_classic_page_index; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 65 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 66 | static uint16_t acl_data_size_classic; |
| 67 | static uint16_t acl_data_size_ble; |
| 68 | static uint16_t acl_buffer_count_classic; |
| 69 | static uint8_t acl_buffer_count_ble; |
| 70 | |
| 71 | static uint8_t ble_white_list_size; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 72 | static uint8_t ble_resolving_list_max_size; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 73 | static uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE]; |
| 74 | static bt_device_features_t features_ble; |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 75 | static uint16_t ble_suggested_default_data_length; |
Jakub Pawlowski | 4f0c5b5 | 2018-02-02 22:05:11 -0800 | [diff] [blame] | 76 | static uint16_t ble_supported_max_tx_octets; |
| 77 | static uint16_t ble_supported_max_tx_time; |
| 78 | static uint16_t ble_supported_max_rx_octets; |
| 79 | static uint16_t ble_supported_max_rx_time; |
| 80 | |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 81 | static uint16_t ble_maxium_advertising_data_length; |
| 82 | static uint8_t ble_number_of_supported_advertising_sets; |
Srinu Jella | f6dcf79 | 2015-07-22 17:30:32 +0530 | [diff] [blame] | 83 | static uint8_t local_supported_codecs[MAX_LOCAL_SUPPORTED_CODECS_SIZE]; |
| 84 | static uint8_t number_of_local_supported_codecs = 0; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 85 | |
| 86 | static bool readable; |
| 87 | static bool ble_supported; |
Srinu Jella | 6e7a335 | 2015-08-24 21:00:28 +0530 | [diff] [blame] | 88 | static bool ble_offload_features_supported; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 89 | static bool simple_pairing_supported; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 90 | static bool secure_connections_supported; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 91 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 92 | #define AWAIT_COMMAND(command) \ |
| 93 | static_cast<BT_HDR*>(future_await(hci->transmit_command_futured(command))) |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 94 | |
| 95 | // Module lifecycle functions |
| 96 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 97 | static future_t* start_up(void) { |
| 98 | BT_HDR* response; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 99 | |
| 100 | // Send the initial reset command |
| 101 | response = AWAIT_COMMAND(packet_factory->make_reset()); |
| 102 | packet_parser->parse_generic_command_complete(response); |
| 103 | |
| 104 | // Request the classic buffer size next |
| 105 | response = AWAIT_COMMAND(packet_factory->make_read_buffer_size()); |
| 106 | packet_parser->parse_read_buffer_size_response( |
| 107 | response, &acl_data_size_classic, &acl_buffer_count_classic); |
| 108 | |
| 109 | // Tell the controller about our buffer sizes and buffer counts next |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 110 | // TODO(zachoverflow): factor this out. eww l2cap contamination. And why just |
| 111 | // a hardcoded 10? |
| 112 | response = AWAIT_COMMAND(packet_factory->make_host_buffer_size( |
| 113 | L2CAP_MTU_SIZE, SCO_HOST_BUFFER_SIZE, L2CAP_HOST_FC_ACL_BUFS, 10)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 114 | |
| 115 | packet_parser->parse_generic_command_complete(response); |
| 116 | |
| 117 | // Read the local version info off the controller next, including |
| 118 | // information such as manufacturer and supported HCI version |
| 119 | response = AWAIT_COMMAND(packet_factory->make_read_local_version_info()); |
| 120 | packet_parser->parse_read_local_version_info_response(response, &bt_version); |
| 121 | |
| 122 | // Read the bluetooth address off the controller next |
| 123 | response = AWAIT_COMMAND(packet_factory->make_read_bd_addr()); |
| 124 | packet_parser->parse_read_bd_addr_response(response, &address); |
| 125 | |
| 126 | // Request the controller's supported commands next |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 127 | response = |
| 128 | AWAIT_COMMAND(packet_factory->make_read_local_supported_commands()); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 129 | packet_parser->parse_read_local_supported_commands_response( |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 130 | response, supported_commands, HCI_SUPPORTED_COMMANDS_ARRAY_SIZE); |
cb | a7cdd8e | 2017-09-28 16:31:59 +0800 | [diff] [blame] | 131 | #if (BTM_SCO_ENHANCED_SYNC_ENABLED == FALSE) |
| 132 | supported_commands[29] &= ~0x08; |
| 133 | #endif |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 134 | |
| 135 | // Read page 0 of the controller features next |
| 136 | uint8_t page_number = 0; |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 137 | response = AWAIT_COMMAND( |
| 138 | packet_factory->make_read_local_extended_features(page_number)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 139 | packet_parser->parse_read_local_extended_features_response( |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 140 | response, &page_number, &last_features_classic_page_index, |
| 141 | features_classic, MAX_FEATURES_CLASSIC_PAGE_COUNT); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 142 | |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 143 | CHECK(page_number == 0); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 144 | page_number++; |
| 145 | |
| 146 | // Inform the controller what page 0 features we support, based on what |
| 147 | // it told us it supports. We need to do this first before we request the |
| 148 | // next page, because the controller's response for page 1 may be |
| 149 | // dependent on what we configure from page 0 |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 150 | simple_pairing_supported = |
| 151 | HCI_SIMPLE_PAIRING_SUPPORTED(features_classic[0].as_array); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 152 | if (simple_pairing_supported) { |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 153 | response = AWAIT_COMMAND( |
| 154 | packet_factory->make_write_simple_pairing_mode(HCI_SP_MODE_ENABLED)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 155 | packet_parser->parse_generic_command_complete(response); |
| 156 | } |
| 157 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 158 | if (HCI_LE_SPT_SUPPORTED(features_classic[0].as_array)) { |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 159 | uint8_t simultaneous_le_host = |
| 160 | HCI_SIMUL_LE_BREDR_SUPPORTED(features_classic[0].as_array) |
| 161 | ? BTM_BLE_SIMULTANEOUS_HOST |
| 162 | : 0; |
| 163 | response = AWAIT_COMMAND(packet_factory->make_ble_write_host_support( |
| 164 | BTM_BLE_HOST_SUPPORT, simultaneous_le_host)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 165 | |
| 166 | packet_parser->parse_generic_command_complete(response); |
Frédéric Dalleau | ebc367a | 2015-08-18 12:23:12 +0200 | [diff] [blame] | 167 | |
| 168 | // If we modified the BT_HOST_SUPPORT, we will need ext. feat. page 1 |
| 169 | if (last_features_classic_page_index < 1) |
| 170 | last_features_classic_page_index = 1; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 171 | } |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 172 | |
| 173 | // Done telling the controller about what page 0 features we support |
| 174 | // Request the remaining feature pages |
| 175 | while (page_number <= last_features_classic_page_index && |
| 176 | page_number < MAX_FEATURES_CLASSIC_PAGE_COUNT) { |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 177 | response = AWAIT_COMMAND( |
| 178 | packet_factory->make_read_local_extended_features(page_number)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 179 | packet_parser->parse_read_local_extended_features_response( |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 180 | response, &page_number, &last_features_classic_page_index, |
| 181 | features_classic, MAX_FEATURES_CLASSIC_PAGE_COUNT); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 182 | |
| 183 | page_number++; |
| 184 | } |
| 185 | |
Srinu Jella | 6e7a335 | 2015-08-24 21:00:28 +0530 | [diff] [blame] | 186 | // read BLE offload features support from controller |
| 187 | response = AWAIT_COMMAND(packet_factory->make_ble_read_offload_features_support()); |
| 188 | packet_parser->parse_ble_read_offload_features_response(response, &ble_offload_features_supported); |
Andre Eisenbach | 67a784b | 2015-05-26 17:40:12 -0700 | [diff] [blame] | 189 | #if (SC_MODE_INCLUDED == TRUE) |
Srinu Jella | 6e7a335 | 2015-08-24 21:00:28 +0530 | [diff] [blame] | 190 | if(ble_offload_features_supported) { |
| 191 | secure_connections_supported = |
| 192 | HCI_SC_CTRLR_SUPPORTED(features_classic[2].as_array); |
| 193 | if (secure_connections_supported) { |
| 194 | response = AWAIT_COMMAND( |
| 195 | packet_factory->make_write_secure_connections_host_support( |
| 196 | HCI_SC_MODE_ENABLED)); |
| 197 | packet_parser->parse_generic_command_complete(response); |
| 198 | } |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 199 | } |
Andre Eisenbach | 67a784b | 2015-05-26 17:40:12 -0700 | [diff] [blame] | 200 | #endif |
Mudumba Ananth | 899b771 | 2015-01-30 02:33:02 -0800 | [diff] [blame] | 201 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 202 | ble_supported = last_features_classic_page_index >= 1 && |
| 203 | HCI_LE_HOST_SUPPORTED(features_classic[1].as_array); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 204 | if (ble_supported) { |
| 205 | // Request the ble white list size next |
| 206 | response = AWAIT_COMMAND(packet_factory->make_ble_read_white_list_size()); |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 207 | packet_parser->parse_ble_read_white_list_size_response( |
| 208 | response, &ble_white_list_size); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 209 | |
| 210 | // Request the ble buffer size next |
| 211 | response = AWAIT_COMMAND(packet_factory->make_ble_read_buffer_size()); |
| 212 | packet_parser->parse_ble_read_buffer_size_response( |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 213 | response, &acl_data_size_ble, &acl_buffer_count_ble); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 214 | |
| 215 | // Response of 0 indicates ble has the same buffer size as classic |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 216 | if (acl_data_size_ble == 0) acl_data_size_ble = acl_data_size_classic; |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 217 | |
| 218 | // Request the ble supported states next |
| 219 | response = AWAIT_COMMAND(packet_factory->make_ble_read_supported_states()); |
| 220 | packet_parser->parse_ble_read_supported_states_response( |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 221 | response, ble_supported_states, sizeof(ble_supported_states)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 222 | |
| 223 | // Request the ble supported features next |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 224 | response = |
| 225 | AWAIT_COMMAND(packet_factory->make_ble_read_local_supported_features()); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 226 | packet_parser->parse_ble_read_local_supported_features_response( |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 227 | response, &features_ble); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 228 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 229 | if (HCI_LE_ENHANCED_PRIVACY_SUPPORTED(features_ble.as_array)) { |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 230 | response = |
| 231 | AWAIT_COMMAND(packet_factory->make_ble_read_resolving_list_size()); |
| 232 | packet_parser->parse_ble_read_resolving_list_size_response( |
| 233 | response, &ble_resolving_list_max_size); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 236 | if (HCI_LE_DATA_LEN_EXT_SUPPORTED(features_ble.as_array)) { |
Jakub Pawlowski | 4f0c5b5 | 2018-02-02 22:05:11 -0800 | [diff] [blame] | 237 | response = |
| 238 | AWAIT_COMMAND(packet_factory->make_ble_read_maximum_data_length()); |
| 239 | packet_parser->parse_ble_read_maximum_data_length_response( |
| 240 | response, &ble_supported_max_tx_octets, &ble_supported_max_tx_time, |
| 241 | &ble_supported_max_rx_octets, &ble_supported_max_rx_time); |
| 242 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 243 | response = AWAIT_COMMAND( |
| 244 | packet_factory->make_ble_read_suggested_default_data_length()); |
| 245 | packet_parser->parse_ble_read_suggested_default_data_length_response( |
| 246 | response, &ble_suggested_default_data_length); |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 249 | if (HCI_LE_EXTENDED_ADVERTISING_SUPPORTED(features_ble.as_array)) { |
| 250 | response = AWAIT_COMMAND( |
| 251 | packet_factory->make_ble_read_maximum_advertising_data_length()); |
| 252 | packet_parser->parse_ble_read_maximum_advertising_data_length( |
| 253 | response, &ble_maxium_advertising_data_length); |
| 254 | |
| 255 | response = AWAIT_COMMAND( |
| 256 | packet_factory->make_ble_read_number_of_supported_advertising_sets()); |
| 257 | packet_parser->parse_ble_read_number_of_supported_advertising_sets( |
| 258 | response, &ble_number_of_supported_advertising_sets); |
Jakub Pawlowski | 5a8a162 | 2017-03-16 18:19:20 -0700 | [diff] [blame] | 259 | } else { |
| 260 | /* If LE Excended Advertising is not supported, use the default value */ |
| 261 | ble_maxium_advertising_data_length = 31; |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 264 | // Set the ble event mask next |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 265 | response = |
| 266 | AWAIT_COMMAND(packet_factory->make_ble_set_event_mask(&BLE_EVENT_MASK)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 267 | packet_parser->parse_generic_command_complete(response); |
| 268 | } |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 269 | |
| 270 | if (simple_pairing_supported) { |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 271 | response = |
| 272 | AWAIT_COMMAND(packet_factory->make_set_event_mask(&CLASSIC_EVENT_MASK)); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 273 | packet_parser->parse_generic_command_complete(response); |
| 274 | } |
| 275 | |
Srinu Jella | f6dcf79 | 2015-07-22 17:30:32 +0530 | [diff] [blame] | 276 | // read local supported codecs |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 277 | if (HCI_READ_LOCAL_CODECS_SUPPORTED(supported_commands)) { |
| 278 | response = |
| 279 | AWAIT_COMMAND(packet_factory->make_read_local_supported_codecs()); |
Srinu Jella | f6dcf79 | 2015-07-22 17:30:32 +0530 | [diff] [blame] | 280 | packet_parser->parse_read_local_supported_codecs_response( |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 281 | response, &number_of_local_supported_codecs, local_supported_codecs); |
Srinu Jella | f6dcf79 | 2015-07-22 17:30:32 +0530 | [diff] [blame] | 282 | } |
| 283 | |
Jakub Pawlowski | 3c03d4f | 2019-02-14 12:44:06 +0100 | [diff] [blame] | 284 | if (!HCI_READ_ENCR_KEY_SIZE_SUPPORTED(supported_commands)) { |
| 285 | LOG(FATAL) << " Controller must support Read Encryption Key Size command"; |
| 286 | } |
| 287 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 288 | readable = true; |
| 289 | return future_new_immediate(FUTURE_SUCCESS); |
| 290 | } |
| 291 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 292 | static future_t* shut_down(void) { |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 293 | readable = false; |
| 294 | return future_new_immediate(FUTURE_SUCCESS); |
| 295 | } |
| 296 | |
Pavlin Radoslavov | b2a292b | 2016-10-14 19:34:48 -0700 | [diff] [blame] | 297 | EXPORT_SYMBOL extern const module_t controller_module = { |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 298 | .name = CONTROLLER_MODULE, |
| 299 | .init = NULL, |
| 300 | .start_up = start_up, |
| 301 | .shut_down = shut_down, |
| 302 | .clean_up = NULL, |
| 303 | .dependencies = {HCI_MODULE, NULL}}; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 304 | |
| 305 | // Interface functions |
| 306 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 307 | static bool get_is_ready(void) { return readable; } |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 308 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 309 | static const RawAddress* get_address(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 310 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 311 | return &address; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 314 | static const bt_version_t* get_bt_version(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 315 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 316 | return &bt_version; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 319 | // TODO(zachoverflow): hide inside, move decoder inside too |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 320 | static const bt_device_features_t* get_features_classic(int index) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 321 | CHECK(readable); |
| 322 | CHECK(index < MAX_FEATURES_CLASSIC_PAGE_COUNT); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 323 | return &features_classic[index]; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 326 | static uint8_t get_last_features_classic_index(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 327 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 328 | return last_features_classic_page_index; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 331 | static uint8_t* get_local_supported_codecs(uint8_t* number_of_codecs) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 332 | CHECK(readable); |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 333 | if (number_of_local_supported_codecs) { |
Srinu Jella | f6dcf79 | 2015-07-22 17:30:32 +0530 | [diff] [blame] | 334 | *number_of_codecs = number_of_local_supported_codecs; |
| 335 | return local_supported_codecs; |
| 336 | } |
| 337 | return NULL; |
| 338 | } |
| 339 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 340 | static const bt_device_features_t* get_features_ble(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 341 | CHECK(readable); |
| 342 | CHECK(ble_supported); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 343 | return &features_ble; |
| 344 | } |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 345 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 346 | static const uint8_t* get_ble_supported_states(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 347 | CHECK(readable); |
| 348 | CHECK(ble_supported); |
Zach Johnson | a87c821 | 2014-10-28 17:59:13 -0700 | [diff] [blame] | 349 | return ble_supported_states; |
| 350 | } |
| 351 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 352 | static bool supports_simple_pairing(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 353 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 354 | return simple_pairing_supported; |
| 355 | } |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 356 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 357 | static bool supports_secure_connections(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 358 | CHECK(readable); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 359 | return secure_connections_supported; |
| 360 | } |
| 361 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 362 | static bool supports_simultaneous_le_bredr(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 363 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 364 | return HCI_SIMUL_LE_BREDR_SUPPORTED(features_classic[0].as_array); |
| 365 | } |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 366 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 367 | static bool supports_reading_remote_extended_features(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 368 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 369 | return HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(supported_commands); |
| 370 | } |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 371 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 372 | static bool supports_interlaced_inquiry_scan(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 373 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 374 | return HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(features_classic[0].as_array); |
| 375 | } |
| 376 | |
| 377 | static bool supports_rssi_with_inquiry_results(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 378 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 379 | return HCI_LMP_INQ_RSSI_SUPPORTED(features_classic[0].as_array); |
| 380 | } |
| 381 | |
| 382 | static bool supports_extended_inquiry_response(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 383 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 384 | return HCI_EXT_INQ_RSP_SUPPORTED(features_classic[0].as_array); |
| 385 | } |
| 386 | |
| 387 | static bool supports_master_slave_role_switch(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 388 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 389 | return HCI_SWITCH_SUPPORTED(features_classic[0].as_array); |
| 390 | } |
| 391 | |
Mudumba Ananth | 57f6508 | 2017-02-09 09:05:48 -0800 | [diff] [blame] | 392 | static bool supports_enhanced_setup_synchronous_connection(void) { |
| 393 | assert(readable); |
| 394 | return HCI_ENH_SETUP_SYNCH_CONN_SUPPORTED(supported_commands); |
| 395 | } |
| 396 | |
| 397 | static bool supports_enhanced_accept_synchronous_connection(void) { |
| 398 | assert(readable); |
| 399 | return HCI_ENH_ACCEPT_SYNCH_CONN_SUPPORTED(supported_commands); |
| 400 | } |
| 401 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 402 | static bool supports_ble(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 403 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 404 | return ble_supported; |
| 405 | } |
| 406 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 407 | static bool supports_ble_privacy(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 408 | CHECK(readable); |
| 409 | CHECK(ble_supported); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 410 | return HCI_LE_ENHANCED_PRIVACY_SUPPORTED(features_ble.as_array); |
| 411 | } |
| 412 | |
Jakub Pawlowski | ba78601 | 2017-06-26 11:26:46 -0700 | [diff] [blame] | 413 | static bool supports_ble_set_privacy_mode() { |
| 414 | CHECK(readable); |
| 415 | CHECK(ble_supported); |
| 416 | return HCI_LE_ENHANCED_PRIVACY_SUPPORTED(features_ble.as_array) && |
| 417 | HCI_LE_SET_PRIVACY_MODE_SUPPORTED(supported_commands); |
| 418 | } |
| 419 | |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 420 | static bool supports_ble_packet_extension(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 421 | CHECK(readable); |
| 422 | CHECK(ble_supported); |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 423 | return HCI_LE_DATA_LEN_EXT_SUPPORTED(features_ble.as_array); |
| 424 | } |
| 425 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 426 | static bool supports_ble_connection_parameters_request(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 427 | CHECK(readable); |
| 428 | CHECK(ble_supported); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 429 | return HCI_LE_CONN_PARAM_REQ_SUPPORTED(features_ble.as_array); |
| 430 | } |
| 431 | |
Jakub Pawlowski | 4b1feb6 | 2017-03-09 18:11:43 -0800 | [diff] [blame] | 432 | static bool supports_ble_2m_phy(void) { |
| 433 | CHECK(readable); |
| 434 | CHECK(ble_supported); |
| 435 | return HCI_LE_2M_PHY_SUPPORTED(features_ble.as_array); |
| 436 | } |
| 437 | |
| 438 | static bool supports_ble_coded_phy(void) { |
| 439 | CHECK(readable); |
| 440 | CHECK(ble_supported); |
| 441 | return HCI_LE_CODED_PHY_SUPPORTED(features_ble.as_array); |
| 442 | } |
| 443 | |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 444 | static bool supports_ble_extended_advertising(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 445 | CHECK(readable); |
| 446 | CHECK(ble_supported); |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 447 | return HCI_LE_EXTENDED_ADVERTISING_SUPPORTED(features_ble.as_array); |
| 448 | } |
| 449 | |
| 450 | static bool supports_ble_periodic_advertising(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 451 | CHECK(readable); |
| 452 | CHECK(ble_supported); |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 453 | return HCI_LE_PERIODIC_ADVERTISING_SUPPORTED(features_ble.as_array); |
| 454 | } |
| 455 | |
Srinu Jella | 6e7a335 | 2015-08-24 21:00:28 +0530 | [diff] [blame] | 456 | static bool supports_ble_offload_features(void) { |
| 457 | assert(readable); |
| 458 | assert(ble_supported); |
| 459 | return ble_offload_features_supported; |
| 460 | } |
| 461 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 462 | static uint16_t get_acl_data_size_classic(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 463 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 464 | return acl_data_size_classic; |
| 465 | } |
| 466 | |
| 467 | static uint16_t get_acl_data_size_ble(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 468 | CHECK(readable); |
| 469 | CHECK(ble_supported); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 470 | return acl_data_size_ble; |
| 471 | } |
| 472 | |
| 473 | static uint16_t get_acl_packet_size_classic(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 474 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 475 | return acl_data_size_classic + HCI_DATA_PREAMBLE_SIZE; |
| 476 | } |
| 477 | |
| 478 | static uint16_t get_acl_packet_size_ble(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 479 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 480 | return acl_data_size_ble + HCI_DATA_PREAMBLE_SIZE; |
| 481 | } |
| 482 | |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 483 | static uint16_t get_ble_suggested_default_data_length(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 484 | CHECK(readable); |
| 485 | CHECK(ble_supported); |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 486 | return ble_suggested_default_data_length; |
| 487 | } |
| 488 | |
Jakub Pawlowski | 4f0c5b5 | 2018-02-02 22:05:11 -0800 | [diff] [blame] | 489 | static uint16_t get_ble_maximum_tx_data_length(void) { |
| 490 | CHECK(readable); |
| 491 | CHECK(ble_supported); |
| 492 | return ble_supported_max_tx_octets; |
| 493 | } |
| 494 | |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 495 | static uint16_t get_ble_maxium_advertising_data_length(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 496 | CHECK(readable); |
| 497 | CHECK(ble_supported); |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 498 | return ble_maxium_advertising_data_length; |
| 499 | } |
| 500 | |
| 501 | static uint8_t get_ble_number_of_supported_advertising_sets(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 502 | CHECK(readable); |
| 503 | CHECK(ble_supported); |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 504 | return ble_number_of_supported_advertising_sets; |
| 505 | } |
| 506 | |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 507 | static uint16_t get_acl_buffer_count_classic(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 508 | CHECK(readable); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 509 | return acl_buffer_count_classic; |
| 510 | } |
| 511 | |
| 512 | static uint8_t get_acl_buffer_count_ble(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 513 | CHECK(readable); |
| 514 | CHECK(ble_supported); |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 515 | return acl_buffer_count_ble; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Priti Aghera | b8b3e80 | 2015-04-17 18:11:24 -0700 | [diff] [blame] | 518 | static uint8_t get_ble_white_list_size(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 519 | CHECK(readable); |
| 520 | CHECK(ble_supported); |
Priti Aghera | b8b3e80 | 2015-04-17 18:11:24 -0700 | [diff] [blame] | 521 | return ble_white_list_size; |
| 522 | } |
| 523 | |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 524 | static uint8_t get_ble_resolving_list_max_size(void) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 525 | CHECK(readable); |
| 526 | CHECK(ble_supported); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 527 | return ble_resolving_list_max_size; |
| 528 | } |
| 529 | |
| 530 | static void set_ble_resolving_list_max_size(int resolving_list_max_size) { |
Pavlin Radoslavov | 58318f4 | 2016-05-05 16:20:15 -0700 | [diff] [blame] | 531 | // Setting "resolving_list_max_size" to 0 is done during cleanup, |
| 532 | // hence we ignore the "readable" flag already set to false during shutdown. |
| 533 | if (resolving_list_max_size != 0) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 534 | CHECK(readable); |
Pavlin Radoslavov | 58318f4 | 2016-05-05 16:20:15 -0700 | [diff] [blame] | 535 | } |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 536 | CHECK(ble_supported); |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 537 | ble_resolving_list_max_size = resolving_list_max_size; |
| 538 | } |
| 539 | |
Jakub Pawlowski | 96fb273 | 2017-03-24 17:52:02 -0700 | [diff] [blame] | 540 | static uint8_t get_le_all_initiating_phys() { |
| 541 | uint8_t phy = PHY_LE_1M; |
| 542 | // TODO(jpawlowski): uncomment after next FW udpate |
| 543 | // if (supports_ble_2m_phy()) phy |= PHY_LE_2M; |
| 544 | // if (supports_ble_coded_phy()) phy |= PHY_LE_CODED; |
| 545 | return phy; |
| 546 | } |
| 547 | |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 548 | static const controller_t interface = { |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 549 | get_is_ready, |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 550 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 551 | get_address, |
| 552 | get_bt_version, |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 553 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 554 | get_features_classic, |
| 555 | get_last_features_classic_index, |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 556 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 557 | get_features_ble, |
| 558 | get_ble_supported_states, |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 559 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 560 | supports_simple_pairing, |
| 561 | supports_secure_connections, |
| 562 | supports_simultaneous_le_bredr, |
| 563 | supports_reading_remote_extended_features, |
| 564 | supports_interlaced_inquiry_scan, |
| 565 | supports_rssi_with_inquiry_results, |
| 566 | supports_extended_inquiry_response, |
| 567 | supports_master_slave_role_switch, |
Mudumba Ananth | 57f6508 | 2017-02-09 09:05:48 -0800 | [diff] [blame] | 568 | supports_enhanced_setup_synchronous_connection, |
| 569 | supports_enhanced_accept_synchronous_connection, |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 570 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 571 | supports_ble, |
| 572 | supports_ble_packet_extension, |
| 573 | supports_ble_connection_parameters_request, |
| 574 | supports_ble_privacy, |
Jakub Pawlowski | ba78601 | 2017-06-26 11:26:46 -0700 | [diff] [blame] | 575 | supports_ble_set_privacy_mode, |
Jakub Pawlowski | 4b1feb6 | 2017-03-09 18:11:43 -0800 | [diff] [blame] | 576 | supports_ble_2m_phy, |
| 577 | supports_ble_coded_phy, |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 578 | supports_ble_extended_advertising, |
| 579 | supports_ble_periodic_advertising, |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 580 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 581 | get_acl_data_size_classic, |
| 582 | get_acl_data_size_ble, |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 583 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 584 | get_acl_packet_size_classic, |
| 585 | get_acl_packet_size_ble, |
| 586 | get_ble_suggested_default_data_length, |
Jakub Pawlowski | 4f0c5b5 | 2018-02-02 22:05:11 -0800 | [diff] [blame] | 587 | get_ble_maximum_tx_data_length, |
Jakub Pawlowski | 1f4cc6d | 2016-11-28 11:16:04 -0800 | [diff] [blame] | 588 | get_ble_maxium_advertising_data_length, |
| 589 | get_ble_number_of_supported_advertising_sets, |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 590 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 591 | get_acl_buffer_count_classic, |
| 592 | get_acl_buffer_count_ble, |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 593 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 594 | get_ble_white_list_size, |
Priti Aghera | b8b3e80 | 2015-04-17 18:11:24 -0700 | [diff] [blame] | 595 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 596 | get_ble_resolving_list_max_size, |
| 597 | set_ble_resolving_list_max_size, |
Jakub Pawlowski | 96fb273 | 2017-03-24 17:52:02 -0700 | [diff] [blame] | 598 | get_local_supported_codecs, |
Srinu Jella | 6e7a335 | 2015-08-24 21:00:28 +0530 | [diff] [blame] | 599 | supports_ble_offload_features, |
Jakub Pawlowski | 96fb273 | 2017-03-24 17:52:02 -0700 | [diff] [blame] | 600 | get_le_all_initiating_phys}; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 601 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 602 | const controller_t* controller_get_interface() { |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 603 | static bool loaded = false; |
| 604 | if (!loaded) { |
| 605 | loaded = true; |
| 606 | |
| 607 | hci = hci_layer_get_interface(); |
| 608 | packet_factory = hci_packet_factory_get_interface(); |
| 609 | packet_parser = hci_packet_parser_get_interface(); |
| 610 | } |
| 611 | |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 612 | return &interface; |
| 613 | } |
| 614 | |
Myles Watson | 4451b3b | 2016-11-09 10:20:44 -0800 | [diff] [blame] | 615 | const controller_t* controller_get_test_interface( |
| 616 | const hci_t* hci_interface, |
| 617 | const hci_packet_factory_t* packet_factory_interface, |
| 618 | const hci_packet_parser_t* packet_parser_interface) { |
Zach Johnson | 30e5806 | 2014-09-26 21:14:34 -0700 | [diff] [blame] | 619 | hci = hci_interface; |
Zach Johnson | bf8193b | 2014-09-08 09:56:35 -0700 | [diff] [blame] | 620 | packet_factory = packet_factory_interface; |
| 621 | packet_parser = packet_parser_interface; |
| 622 | return &interface; |
| 623 | } |