blob: d12bfb9642367a09080ffcc2450f481728f7d079 [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
33Return<Status> BluetoothHci::initialize(
34 const ::android::sp<IBluetoothHciCallbacks>& cb) {
35 ALOGW("BluetoothHci::initialize()");
36 event_cb_ = cb;
37
38 bool rc = VendorInterface::Initialize(
39 [this](HciPacketType type, const hidl_vec<uint8_t>& packet) {
40 switch (type) {
41 case HCI_PACKET_TYPE_EVENT:
42 event_cb_->hciEventReceived(packet);
43 break;
44 case HCI_PACKET_TYPE_ACL_DATA:
45 event_cb_->aclDataReceived(packet);
46 break;
47 case HCI_PACKET_TYPE_SCO_DATA:
48 event_cb_->scoDataReceived(packet);
49 break;
50 default:
51 ALOGE("%s Unexpected event type %d", __func__, type);
52 break;
53 }
54 });
55 if (!rc) return Status::INITIALIZATION_ERROR;
56
57 return Status::SUCCESS;
58}
59
60Return<void> BluetoothHci::close() {
61 ALOGW("BluetoothHci::close()");
62 VendorInterface::Shutdown();
63 return Void();
64}
65
66Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& command) {
67 sendDataToController(HCI_DATA_TYPE_COMMAND, command);
68 return Void();
69}
70
71Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& data) {
72 sendDataToController(HCI_DATA_TYPE_ACL, data);
73 return Void();
74}
75
76Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& data) {
77 sendDataToController(HCI_DATA_TYPE_SCO, data);
78 return Void();
79}
80
81void BluetoothHci::sendDataToController(const uint8_t type,
82 const hidl_vec<uint8_t>& data) {
83 VendorInterface::get()->Send(&type, 1);
84 VendorInterface::get()->Send(data.data(), data.size());
85}
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