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 | #define LOG_TAG "android.hardware.bluetooth@1.0-impl" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include "bluetooth_hci.h" |
| 21 | #include "vendor_interface.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace bluetooth { |
| 26 | namespace V1_0 { |
| 27 | namespace implementation { |
| 28 | |
| 29 | static const uint8_t HCI_DATA_TYPE_COMMAND = 1; |
| 30 | static const uint8_t HCI_DATA_TYPE_ACL = 2; |
| 31 | static const uint8_t HCI_DATA_TYPE_SCO = 3; |
| 32 | |
Martijn Coenen | 678af7f | 2017-02-23 17:25:18 +0100 | [diff] [blame] | 33 | BluetoothHci::BluetoothHci() |
| 34 | : deathRecipient(new BluetoothDeathRecipient(this)) {} |
| 35 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 36 | Return<void> BluetoothHci::initialize( |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 37 | const ::android::sp<IBluetoothHciCallbacks>& cb) { |
| 38 | ALOGW("BluetoothHci::initialize()"); |
Martijn Coenen | 678af7f | 2017-02-23 17:25:18 +0100 | [diff] [blame] | 39 | cb->linkToDeath(deathRecipient, 0); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 40 | event_cb_ = cb; |
| 41 | |
| 42 | bool rc = VendorInterface::Initialize( |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 43 | [this](bool status) { |
| 44 | event_cb_->initializationComplete( |
| 45 | status ? Status::SUCCESS : Status::INITIALIZATION_ERROR); |
| 46 | }, |
Zach Johnson | 917efb1 | 2017-02-26 23:46:05 -0800 | [diff] [blame^] | 47 | [this](const hidl_vec<uint8_t>& packet) { |
| 48 | event_cb_->hciEventReceived(packet); |
| 49 | }, |
| 50 | [this](const hidl_vec<uint8_t>& packet) { |
| 51 | event_cb_->aclDataReceived(packet); |
| 52 | }, |
| 53 | [this](const hidl_vec<uint8_t>& packet) { |
| 54 | event_cb_->scoDataReceived(packet); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 55 | }); |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame] | 56 | if (!rc) event_cb_->initializationComplete(Status::INITIALIZATION_ERROR); |
| 57 | return Void(); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | Return<void> BluetoothHci::close() { |
| 61 | ALOGW("BluetoothHci::close()"); |
Martijn Coenen | 678af7f | 2017-02-23 17:25:18 +0100 | [diff] [blame] | 62 | event_cb_->unlinkToDeath(deathRecipient); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 63 | VendorInterface::Shutdown(); |
| 64 | return Void(); |
| 65 | } |
| 66 | |
| 67 | Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& command) { |
| 68 | sendDataToController(HCI_DATA_TYPE_COMMAND, command); |
| 69 | return Void(); |
| 70 | } |
| 71 | |
| 72 | Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& data) { |
| 73 | sendDataToController(HCI_DATA_TYPE_ACL, data); |
| 74 | return Void(); |
| 75 | } |
| 76 | |
| 77 | Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& data) { |
| 78 | sendDataToController(HCI_DATA_TYPE_SCO, data); |
| 79 | return Void(); |
| 80 | } |
| 81 | |
| 82 | void BluetoothHci::sendDataToController(const uint8_t type, |
| 83 | const hidl_vec<uint8_t>& data) { |
Myles Watson | df765ea | 2017-01-30 09:07:37 -0800 | [diff] [blame] | 84 | VendorInterface::get()->Send(type, data.data(), data.size()); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) { |
| 88 | return new BluetoothHci(); |
| 89 | } |
| 90 | |
| 91 | } // namespace implementation |
| 92 | } // namespace V1_0 |
| 93 | } // namespace bluetooth |
| 94 | } // namespace hardware |
| 95 | } // namespace android |