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 | |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame^] | 33 | Return<void> BluetoothHci::initialize( |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 34 | const ::android::sp<IBluetoothHciCallbacks>& cb) { |
| 35 | ALOGW("BluetoothHci::initialize()"); |
| 36 | event_cb_ = cb; |
| 37 | |
| 38 | bool rc = VendorInterface::Initialize( |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame^] | 39 | [this](bool status) { |
| 40 | event_cb_->initializationComplete( |
| 41 | status ? Status::SUCCESS : Status::INITIALIZATION_ERROR); |
| 42 | }, |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 43 | [this](HciPacketType type, const hidl_vec<uint8_t>& packet) { |
| 44 | switch (type) { |
| 45 | case HCI_PACKET_TYPE_EVENT: |
| 46 | event_cb_->hciEventReceived(packet); |
| 47 | break; |
| 48 | case HCI_PACKET_TYPE_ACL_DATA: |
| 49 | event_cb_->aclDataReceived(packet); |
| 50 | break; |
| 51 | case HCI_PACKET_TYPE_SCO_DATA: |
| 52 | event_cb_->scoDataReceived(packet); |
| 53 | break; |
| 54 | default: |
| 55 | ALOGE("%s Unexpected event type %d", __func__, type); |
| 56 | break; |
| 57 | } |
| 58 | }); |
Andre Eisenbach | 9041d97 | 2017-01-17 18:23:12 -0800 | [diff] [blame^] | 59 | if (!rc) event_cb_->initializationComplete(Status::INITIALIZATION_ERROR); |
| 60 | return Void(); |
Andre Eisenbach | 89ba528 | 2016-10-13 15:45:02 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | Return<void> BluetoothHci::close() { |
| 64 | ALOGW("BluetoothHci::close()"); |
| 65 | VendorInterface::Shutdown(); |
| 66 | return Void(); |
| 67 | } |
| 68 | |
| 69 | Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& command) { |
| 70 | sendDataToController(HCI_DATA_TYPE_COMMAND, command); |
| 71 | return Void(); |
| 72 | } |
| 73 | |
| 74 | Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& data) { |
| 75 | sendDataToController(HCI_DATA_TYPE_ACL, data); |
| 76 | return Void(); |
| 77 | } |
| 78 | |
| 79 | Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& data) { |
| 80 | sendDataToController(HCI_DATA_TYPE_SCO, data); |
| 81 | return Void(); |
| 82 | } |
| 83 | |
| 84 | void BluetoothHci::sendDataToController(const uint8_t type, |
| 85 | const hidl_vec<uint8_t>& data) { |
| 86 | VendorInterface::get()->Send(&type, 1); |
| 87 | VendorInterface::get()->Send(data.data(), data.size()); |
| 88 | } |
| 89 | |
| 90 | IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) { |
| 91 | return new BluetoothHci(); |
| 92 | } |
| 93 | |
| 94 | } // namespace implementation |
| 95 | } // namespace V1_0 |
| 96 | } // namespace bluetooth |
| 97 | } // namespace hardware |
| 98 | } // namespace android |