Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2016 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #include "vendor_interface.h" |
| 18 | |
Dan Albert | 3d0263f | 2017-01-26 15:33:15 -0800 | [diff] [blame] | 19 | #include <assert.h> |
| 20 | |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 21 | #define LOG_TAG "android.hardware.bluetooth@1.0-impl" |
| 22 | #include <android-base/logging.h> |
Myles Watson | 6a7d622 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 23 | #include <cutils/properties.h> |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 24 | #include <utils/Log.h> |
| 25 | |
| 26 | #include <dlfcn.h> |
Myles Watson | 6a7d622 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 27 | #include <fcntl.h> |
| 28 | |
| 29 | #include "bluetooth_address.h" |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 30 | |
| 31 | static const char* VENDOR_LIBRARY_NAME = "libbt-vendor.so"; |
| 32 | static const char* VENDOR_LIBRARY_SYMBOL_NAME = |
| 33 | "BLUETOOTH_VENDOR_LIB_INTERFACE"; |
| 34 | |
| 35 | static const int INVALID_FD = -1; |
| 36 | |
| 37 | namespace { |
| 38 | |
| 39 | using android::hardware::bluetooth::V1_0::implementation::VendorInterface; |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 40 | using android::hardware::hidl_vec; |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 41 | |
| 42 | tINT_CMD_CBACK internal_command_cb; |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame^] | 43 | uint16_t internal_command_opcode; |
| 44 | |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 45 | VendorInterface* g_vendor_interface = nullptr; |
| 46 | |
| 47 | const size_t preamble_size_for_type[] = { |
| 48 | 0, HCI_COMMAND_PREAMBLE_SIZE, HCI_ACL_PREAMBLE_SIZE, HCI_SCO_PREAMBLE_SIZE, |
| 49 | HCI_EVENT_PREAMBLE_SIZE}; |
| 50 | const size_t packet_length_offset_for_type[] = { |
| 51 | 0, HCI_LENGTH_OFFSET_CMD, HCI_LENGTH_OFFSET_ACL, HCI_LENGTH_OFFSET_SCO, |
| 52 | HCI_LENGTH_OFFSET_EVT}; |
| 53 | |
Myles Watson | 7139018 | 2017-01-24 13:34:59 -0800 | [diff] [blame] | 54 | size_t HciGetPacketLengthForType(HciPacketType type, const uint8_t* preamble) { |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 55 | size_t offset = packet_length_offset_for_type[type]; |
Myles Watson | 7139018 | 2017-01-24 13:34:59 -0800 | [diff] [blame] | 56 | if (type != HCI_PACKET_TYPE_ACL_DATA) return preamble[offset]; |
| 57 | return (((preamble[offset + 1]) << 8) | preamble[offset]); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 60 | HC_BT_HDR* WrapPacketAndCopy(uint16_t event, const hidl_vec<uint8_t>& data) { |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 61 | size_t packet_size = data.size() + sizeof(HC_BT_HDR); |
| 62 | HC_BT_HDR* packet = reinterpret_cast<HC_BT_HDR*>(new uint8_t[packet_size]); |
| 63 | packet->offset = 0; |
| 64 | packet->len = data.size(); |
| 65 | packet->layer_specific = 0; |
| 66 | packet->event = event; |
Myles Watson | 6a7d622 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 67 | // TODO(eisenbach): Avoid copy here; if BT_HDR->data can be ensured to |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 68 | // be the only way the data is accessed, a pointer could be passed here... |
| 69 | memcpy(packet->data, data.data(), data.size()); |
| 70 | return packet; |
| 71 | } |
| 72 | |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame^] | 73 | bool internal_command_event_match(const hidl_vec<uint8_t>& packet) { |
| 74 | uint8_t event_code = packet[0]; |
| 75 | if (event_code != HCI_COMMAND_COMPLETE_EVENT) { |
| 76 | ALOGE("%s: Unhandled event type %02X", __func__, event_code); |
| 77 | return false; |
| 78 | } |
| 79 | |
| 80 | size_t opcode_offset = HCI_EVENT_PREAMBLE_SIZE + 1; // Skip num packets. |
| 81 | |
| 82 | uint16_t opcode = packet[opcode_offset] | (packet[opcode_offset + 1] << 8); |
| 83 | |
| 84 | ALOGV("%s internal_command_opcode = %04X opcode = %04x", __func__, |
| 85 | internal_command_opcode, opcode); |
| 86 | return opcode == internal_command_opcode; |
| 87 | } |
| 88 | |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 89 | uint8_t transmit_cb(uint16_t opcode, void* buffer, tINT_CMD_CBACK callback) { |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame^] | 90 | ALOGV("%s opcode: 0x%04x, ptr: %p, cb: %p", __func__, opcode, buffer, |
| 91 | callback); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 92 | internal_command_cb = callback; |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame^] | 93 | internal_command_opcode = opcode; |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 94 | uint8_t type = HCI_PACKET_TYPE_COMMAND; |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 95 | VendorInterface::get()->Send(&type, 1); |
| 96 | HC_BT_HDR* bt_hdr = reinterpret_cast<HC_BT_HDR*>(buffer); |
| 97 | VendorInterface::get()->Send(bt_hdr->data, bt_hdr->len); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 98 | return true; |
| 99 | } |
| 100 | |
| 101 | void firmware_config_cb(bt_vendor_op_result_t result) { |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 102 | ALOGV("%s result: %d", __func__, result); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 103 | VendorInterface::get()->OnFirmwareConfigured(result); |
| 104 | } |
| 105 | |
| 106 | void sco_config_cb(bt_vendor_op_result_t result) { |
| 107 | ALOGD("%s result: %d", __func__, result); |
| 108 | } |
| 109 | |
| 110 | void low_power_mode_cb(bt_vendor_op_result_t result) { |
| 111 | ALOGD("%s result: %d", __func__, result); |
| 112 | } |
| 113 | |
| 114 | void sco_audiostate_cb(bt_vendor_op_result_t result) { |
| 115 | ALOGD("%s result: %d", __func__, result); |
| 116 | } |
| 117 | |
| 118 | void* buffer_alloc_cb(int size) { |
| 119 | void* p = new uint8_t[size]; |
| 120 | ALOGV("%s pts: %p, size: %d", __func__, p, size); |
| 121 | return p; |
| 122 | } |
| 123 | |
| 124 | void buffer_free_cb(void* buffer) { |
| 125 | ALOGV("%s ptr: %p", __func__, buffer); |
| 126 | delete[] reinterpret_cast<uint8_t*>(buffer); |
| 127 | } |
| 128 | |
| 129 | void epilog_cb(bt_vendor_op_result_t result) { |
| 130 | ALOGD("%s result: %d", __func__, result); |
| 131 | } |
| 132 | |
| 133 | void a2dp_offload_cb(bt_vendor_op_result_t result, bt_vendor_opcode_t op, |
| 134 | uint8_t av_handle) { |
| 135 | ALOGD("%s result: %d, op: %d, handle: %d", __func__, result, op, av_handle); |
| 136 | } |
| 137 | |
| 138 | const bt_vendor_callbacks_t lib_callbacks = { |
| 139 | sizeof(lib_callbacks), firmware_config_cb, sco_config_cb, |
| 140 | low_power_mode_cb, sco_audiostate_cb, buffer_alloc_cb, |
| 141 | buffer_free_cb, transmit_cb, epilog_cb, |
| 142 | a2dp_offload_cb}; |
| 143 | |
| 144 | } // namespace |
| 145 | |
| 146 | namespace android { |
| 147 | namespace hardware { |
| 148 | namespace bluetooth { |
| 149 | namespace V1_0 { |
| 150 | namespace implementation { |
| 151 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 152 | class FirmwareStartupTimer { |
| 153 | public: |
| 154 | FirmwareStartupTimer() : start_time_(std::chrono::steady_clock::now()) {} |
| 155 | |
| 156 | ~FirmwareStartupTimer() { |
| 157 | std::chrono::duration<double> duration = |
| 158 | std::chrono::steady_clock::now() - start_time_; |
| 159 | double s = duration.count(); |
| 160 | if (s == 0) return; |
Myles Watson | 8ffcbc7 | 2017-01-20 10:09:38 -0800 | [diff] [blame] | 161 | ALOGI("Firmware configured in %.3fs", s); |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | private: |
| 165 | std::chrono::steady_clock::time_point start_time_; |
| 166 | }; |
| 167 | |
| 168 | bool VendorInterface::Initialize( |
| 169 | InitializeCompleteCallback initialize_complete_cb, |
| 170 | PacketReadCallback packet_read_cb) { |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 171 | assert(!g_vendor_interface); |
| 172 | g_vendor_interface = new VendorInterface(); |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 173 | return g_vendor_interface->Open(initialize_complete_cb, packet_read_cb); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void VendorInterface::Shutdown() { |
| 177 | CHECK(g_vendor_interface); |
| 178 | g_vendor_interface->Close(); |
| 179 | delete g_vendor_interface; |
| 180 | g_vendor_interface = nullptr; |
| 181 | } |
| 182 | |
| 183 | VendorInterface* VendorInterface::get() { return g_vendor_interface; } |
| 184 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 185 | bool VendorInterface::Open(InitializeCompleteCallback initialize_complete_cb, |
| 186 | PacketReadCallback packet_read_cb) { |
| 187 | initialize_complete_cb_ = initialize_complete_cb; |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 188 | packet_read_cb_ = packet_read_cb; |
| 189 | |
| 190 | // Initialize vendor interface |
| 191 | |
| 192 | lib_handle_ = dlopen(VENDOR_LIBRARY_NAME, RTLD_NOW); |
| 193 | if (!lib_handle_) { |
| 194 | ALOGE("%s unable to open %s (%s)", __func__, VENDOR_LIBRARY_NAME, |
| 195 | dlerror()); |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | lib_interface_ = reinterpret_cast<bt_vendor_interface_t*>( |
| 200 | dlsym(lib_handle_, VENDOR_LIBRARY_SYMBOL_NAME)); |
| 201 | if (!lib_interface_) { |
| 202 | ALOGE("%s unable to find symbol %s in %s (%s)", __func__, |
| 203 | VENDOR_LIBRARY_SYMBOL_NAME, VENDOR_LIBRARY_NAME, dlerror()); |
| 204 | return false; |
| 205 | } |
| 206 | |
Myles Watson | 6a7d622 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 207 | // Get the local BD address |
| 208 | |
| 209 | uint8_t local_bda[BluetoothAddress::kBytes]; |
| 210 | CHECK(BluetoothAddress::get_local_address(local_bda)); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 211 | int status = lib_interface_->init(&lib_callbacks, (unsigned char*)local_bda); |
| 212 | if (status) { |
| 213 | ALOGE("%s unable to initialize vendor library: %d", __func__, status); |
| 214 | return false; |
| 215 | } |
| 216 | |
| 217 | ALOGD("%s vendor library loaded", __func__); |
| 218 | |
| 219 | // Power cycle chip |
| 220 | |
| 221 | int power_state = BT_VND_PWR_OFF; |
| 222 | lib_interface_->op(BT_VND_OP_POWER_CTRL, &power_state); |
| 223 | power_state = BT_VND_PWR_ON; |
| 224 | lib_interface_->op(BT_VND_OP_POWER_CTRL, &power_state); |
| 225 | |
| 226 | // Get the UART socket |
| 227 | |
| 228 | int fd_list[CH_MAX] = {0}; |
| 229 | int fd_count = lib_interface_->op(BT_VND_OP_USERIAL_OPEN, &fd_list); |
| 230 | |
| 231 | if (fd_count != 1) { |
| 232 | ALOGE("%s fd count %d != 1; we can't handle this currently...", __func__, |
| 233 | fd_count); |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | uart_fd_ = fd_list[0]; |
| 238 | if (uart_fd_ == INVALID_FD) { |
| 239 | ALOGE("%s unable to determine UART fd", __func__); |
| 240 | return false; |
| 241 | } |
| 242 | |
Myles Watson | 8ffcbc7 | 2017-01-20 10:09:38 -0800 | [diff] [blame] | 243 | ALOGI("%s UART fd: %d", __func__, uart_fd_); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 244 | |
| 245 | fd_watcher_.WatchFdForNonBlockingReads(uart_fd_, |
| 246 | [this](int fd) { OnDataReady(fd); }); |
| 247 | |
| 248 | // Start configuring the firmware |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 249 | firmware_startup_timer_ = new FirmwareStartupTimer(); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 250 | lib_interface_->op(BT_VND_OP_FW_CFG, nullptr); |
| 251 | |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | void VendorInterface::Close() { |
| 256 | fd_watcher_.StopWatchingFileDescriptor(); |
| 257 | |
| 258 | if (lib_interface_ != nullptr) { |
| 259 | lib_interface_->op(BT_VND_OP_USERIAL_CLOSE, nullptr); |
| 260 | uart_fd_ = INVALID_FD; |
| 261 | int power_state = BT_VND_PWR_OFF; |
| 262 | lib_interface_->op(BT_VND_OP_POWER_CTRL, &power_state); |
| 263 | } |
| 264 | |
| 265 | if (lib_handle_ != nullptr) { |
| 266 | dlclose(lib_handle_); |
| 267 | lib_handle_ = nullptr; |
| 268 | } |
| 269 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 270 | if (firmware_startup_timer_ != nullptr) { |
| 271 | delete firmware_startup_timer_; |
| 272 | firmware_startup_timer_ = nullptr; |
| 273 | } |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | size_t VendorInterface::Send(const uint8_t* data, size_t length) { |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 277 | if (uart_fd_ == INVALID_FD) return 0; |
| 278 | |
| 279 | size_t transmitted_length = 0; |
| 280 | while (length > 0) { |
| 281 | ssize_t ret = |
| 282 | TEMP_FAILURE_RETRY(write(uart_fd_, data + transmitted_length, length)); |
| 283 | |
| 284 | if (ret == -1) { |
| 285 | if (errno == EAGAIN) continue; |
| 286 | ALOGE("%s error writing to UART (%s)", __func__, strerror(errno)); |
| 287 | break; |
| 288 | |
| 289 | } else if (ret == 0) { |
| 290 | // Nothing written :( |
| 291 | ALOGE("%s zero bytes written - something went wrong...", __func__); |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | transmitted_length += ret; |
| 296 | length -= ret; |
| 297 | } |
| 298 | |
| 299 | return transmitted_length; |
| 300 | } |
| 301 | |
| 302 | void VendorInterface::OnFirmwareConfigured(uint8_t result) { |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 303 | ALOGD("%s result: %d", __func__, result); |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 304 | |
| 305 | if (firmware_startup_timer_ != nullptr) { |
| 306 | delete firmware_startup_timer_; |
| 307 | firmware_startup_timer_ = nullptr; |
| 308 | } |
| 309 | |
| 310 | if (initialize_complete_cb_ != nullptr) { |
| 311 | initialize_complete_cb_(result == 0); |
| 312 | initialize_complete_cb_ = nullptr; |
| 313 | } |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void VendorInterface::OnDataReady(int fd) { |
| 317 | switch (hci_parser_state_) { |
| 318 | case HCI_IDLE: { |
| 319 | uint8_t buffer[1] = {0}; |
| 320 | size_t bytes_read = TEMP_FAILURE_RETRY(read(fd, buffer, 1)); |
| 321 | CHECK(bytes_read == 1); |
| 322 | hci_packet_type_ = static_cast<HciPacketType>(buffer[0]); |
| 323 | // TODO(eisenbach): Check for workaround(s) |
| 324 | CHECK(hci_packet_type_ >= HCI_PACKET_TYPE_ACL_DATA && |
| 325 | hci_packet_type_ <= HCI_PACKET_TYPE_EVENT) |
Myles Watson | 8ffcbc7 | 2017-01-20 10:09:38 -0800 | [diff] [blame] | 326 | << "buffer[0] = " << static_cast<unsigned int>(buffer[0]); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 327 | hci_parser_state_ = HCI_TYPE_READY; |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 328 | hci_packet_bytes_remaining_ = preamble_size_for_type[hci_packet_type_]; |
| 329 | hci_packet_bytes_read_ = 0; |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | case HCI_TYPE_READY: { |
| 334 | size_t bytes_read = TEMP_FAILURE_RETRY( |
Myles Watson | 7139018 | 2017-01-24 13:34:59 -0800 | [diff] [blame] | 335 | read(fd, hci_packet_preamble_ + hci_packet_bytes_read_, |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 336 | hci_packet_bytes_remaining_)); |
| 337 | CHECK(bytes_read > 0); |
| 338 | hci_packet_bytes_remaining_ -= bytes_read; |
| 339 | hci_packet_bytes_read_ += bytes_read; |
| 340 | if (hci_packet_bytes_remaining_ == 0) { |
| 341 | size_t packet_length = |
Myles Watson | 7139018 | 2017-01-24 13:34:59 -0800 | [diff] [blame] | 342 | HciGetPacketLengthForType(hci_packet_type_, hci_packet_preamble_); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 343 | hci_packet_.resize(preamble_size_for_type[hci_packet_type_] + |
| 344 | packet_length); |
Myles Watson | 7139018 | 2017-01-24 13:34:59 -0800 | [diff] [blame] | 345 | memcpy(hci_packet_.data(), hci_packet_preamble_, |
| 346 | preamble_size_for_type[hci_packet_type_]); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 347 | hci_packet_bytes_remaining_ = packet_length; |
| 348 | hci_parser_state_ = HCI_PAYLOAD; |
| 349 | hci_packet_bytes_read_ = 0; |
| 350 | } |
| 351 | break; |
| 352 | } |
| 353 | |
| 354 | case HCI_PAYLOAD: { |
| 355 | size_t bytes_read = TEMP_FAILURE_RETRY( |
| 356 | read(fd, |
| 357 | hci_packet_.data() + preamble_size_for_type[hci_packet_type_] + |
| 358 | hci_packet_bytes_read_, |
| 359 | hci_packet_bytes_remaining_)); |
| 360 | hci_packet_bytes_remaining_ -= bytes_read; |
| 361 | hci_packet_bytes_read_ += bytes_read; |
| 362 | if (hci_packet_bytes_remaining_ == 0) { |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame^] | 363 | if (internal_command_cb != nullptr && |
| 364 | hci_packet_type_ == HCI_PACKET_TYPE_EVENT && |
| 365 | internal_command_event_match(hci_packet_)) { |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 366 | HC_BT_HDR* bt_hdr = |
| 367 | WrapPacketAndCopy(HCI_PACKET_TYPE_EVENT, hci_packet_); |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame^] | 368 | |
| 369 | // The callbacks can send new commands, so don't zero after calling. |
| 370 | tINT_CMD_CBACK saved_cb = internal_command_cb; |
| 371 | internal_command_cb = nullptr; |
| 372 | saved_cb(bt_hdr); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 373 | } else { |
Myles Watson | a7d33b3 | 2017-01-24 09:09:58 -0800 | [diff] [blame^] | 374 | packet_read_cb_(hci_packet_type_, hci_packet_); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 375 | } |
| 376 | hci_parser_state_ = HCI_IDLE; |
| 377 | } |
| 378 | break; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | } // namespace implementation |
| 384 | } // namespace V1_0 |
| 385 | } // namespace bluetooth |
| 386 | } // namespace hardware |
| 387 | } // namespace android |