blob: 5a282bf2a3511879cc9a9811908d97d0fb5de0ff [file] [log] [blame]
Andre Eisenbach89ba5282016-10-13 15:45:02 -07001//
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
23namespace android {
24namespace hardware {
25namespace bluetooth {
26namespace V1_0 {
27namespace implementation {
28
29static const uint8_t HCI_DATA_TYPE_COMMAND = 1;
30static const uint8_t HCI_DATA_TYPE_ACL = 2;
31static const uint8_t HCI_DATA_TYPE_SCO = 3;
32
Martijn Coenen678af7f2017-02-23 17:25:18 +010033BluetoothHci::BluetoothHci()
34 : deathRecipient(new BluetoothDeathRecipient(this)) {}
35
Andre Eisenbach9041d972017-01-17 18:23:12 -080036Return<void> BluetoothHci::initialize(
Andre Eisenbach89ba5282016-10-13 15:45:02 -070037 const ::android::sp<IBluetoothHciCallbacks>& cb) {
38 ALOGW("BluetoothHci::initialize()");
Martijn Coenen678af7f2017-02-23 17:25:18 +010039 cb->linkToDeath(deathRecipient, 0);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070040 event_cb_ = cb;
41
42 bool rc = VendorInterface::Initialize(
Andre Eisenbach9041d972017-01-17 18:23:12 -080043 [this](bool status) {
44 event_cb_->initializationComplete(
45 status ? Status::SUCCESS : Status::INITIALIZATION_ERROR);
46 },
Zach Johnson917efb12017-02-26 23:46:05 -080047 [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 Eisenbach89ba5282016-10-13 15:45:02 -070055 });
Andre Eisenbach9041d972017-01-17 18:23:12 -080056 if (!rc) event_cb_->initializationComplete(Status::INITIALIZATION_ERROR);
57 return Void();
Andre Eisenbach89ba5282016-10-13 15:45:02 -070058}
59
60Return<void> BluetoothHci::close() {
61 ALOGW("BluetoothHci::close()");
Martijn Coenen678af7f2017-02-23 17:25:18 +010062 event_cb_->unlinkToDeath(deathRecipient);
Andre Eisenbach89ba5282016-10-13 15:45:02 -070063 VendorInterface::Shutdown();
64 return Void();
65}
66
67Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& command) {
68 sendDataToController(HCI_DATA_TYPE_COMMAND, command);
69 return Void();
70}
71
72Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& data) {
73 sendDataToController(HCI_DATA_TYPE_ACL, data);
74 return Void();
75}
76
77Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& data) {
78 sendDataToController(HCI_DATA_TYPE_SCO, data);
79 return Void();
80}
81
82void BluetoothHci::sendDataToController(const uint8_t type,
83 const hidl_vec<uint8_t>& data) {
Myles Watsondf765ea2017-01-30 09:07:37 -080084 VendorInterface::get()->Send(type, data.data(), data.size());
Andre Eisenbach89ba5282016-10-13 15:45:02 -070085}
86
87IBluetoothHci* 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