blob: 6cea623348ec3d23b10d6d0a9a38c4947bcbfb4d [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
Andre Eisenbach9041d972017-01-17 18:23:12 -080033Return<void> BluetoothHci::initialize(
Andre Eisenbach89ba5282016-10-13 15:45:02 -070034 const ::android::sp<IBluetoothHciCallbacks>& cb) {
35 ALOGW("BluetoothHci::initialize()");
36 event_cb_ = cb;
37
38 bool rc = VendorInterface::Initialize(
Andre Eisenbach9041d972017-01-17 18:23:12 -080039 [this](bool status) {
40 event_cb_->initializationComplete(
41 status ? Status::SUCCESS : Status::INITIALIZATION_ERROR);
42 },
Andre Eisenbach89ba5282016-10-13 15:45:02 -070043 [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 Eisenbach9041d972017-01-17 18:23:12 -080059 if (!rc) event_cb_->initializationComplete(Status::INITIALIZATION_ERROR);
60 return Void();
Andre Eisenbach89ba5282016-10-13 15:45:02 -070061}
62
63Return<void> BluetoothHci::close() {
64 ALOGW("BluetoothHci::close()");
65 VendorInterface::Shutdown();
66 return Void();
67}
68
69Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& command) {
70 sendDataToController(HCI_DATA_TYPE_COMMAND, command);
71 return Void();
72}
73
74Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& data) {
75 sendDataToController(HCI_DATA_TYPE_ACL, data);
76 return Void();
77}
78
79Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& data) {
80 sendDataToController(HCI_DATA_TYPE_SCO, data);
81 return Void();
82}
83
84void BluetoothHci::sendDataToController(const uint8_t type,
85 const hidl_vec<uint8_t>& data) {
Myles Watsondf765ea2017-01-30 09:07:37 -080086 VendorInterface::get()->Send(type, data.data(), data.size());
Andre Eisenbach89ba5282016-10-13 15:45:02 -070087}
88
89IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) {
90 return new BluetoothHci();
91}
92
93} // namespace implementation
94} // namespace V1_0
95} // namespace bluetooth
96} // namespace hardware
97} // namespace android