2016-10-14 00:45:02 +02:00
|
|
|
//
|
|
|
|
// Copyright 2016 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
|
|
|
#define LOG_TAG "android.hardware.bluetooth@1.0-impl"
|
2017-03-17 00:23:23 +01:00
|
|
|
#include "bluetooth_hci.h"
|
|
|
|
|
2017-04-11 21:22:27 +02:00
|
|
|
#include <log/log.h>
|
2016-10-14 00:45:02 +02:00
|
|
|
|
|
|
|
#include "vendor_interface.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace hardware {
|
|
|
|
namespace bluetooth {
|
|
|
|
namespace V1_0 {
|
|
|
|
namespace implementation {
|
|
|
|
|
|
|
|
static const uint8_t HCI_DATA_TYPE_COMMAND = 1;
|
|
|
|
static const uint8_t HCI_DATA_TYPE_ACL = 2;
|
|
|
|
static const uint8_t HCI_DATA_TYPE_SCO = 3;
|
|
|
|
|
2017-03-17 06:19:19 +01:00
|
|
|
class BluetoothDeathRecipient : public hidl_death_recipient {
|
|
|
|
public:
|
|
|
|
BluetoothDeathRecipient(const sp<IBluetoothHci> hci) : mHci(hci) {}
|
|
|
|
|
|
|
|
virtual void serviceDied(
|
|
|
|
uint64_t /*cookie*/,
|
|
|
|
const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
|
|
|
|
ALOGE("BluetoothDeathRecipient::serviceDied - Bluetooth service died");
|
2017-03-17 00:23:23 +01:00
|
|
|
has_died_ = true;
|
2017-03-17 06:19:19 +01:00
|
|
|
mHci->close();
|
|
|
|
}
|
|
|
|
sp<IBluetoothHci> mHci;
|
2017-03-17 00:23:23 +01:00
|
|
|
bool getHasDied() const { return has_died_; }
|
|
|
|
void setHasDied(bool has_died) { has_died_ = has_died; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool has_died_;
|
2017-03-17 06:19:19 +01:00
|
|
|
};
|
|
|
|
|
2017-02-23 17:25:18 +01:00
|
|
|
BluetoothHci::BluetoothHci()
|
2017-03-17 00:23:23 +01:00
|
|
|
: death_recipient_(new BluetoothDeathRecipient(this)) {}
|
2017-02-23 17:25:18 +01:00
|
|
|
|
2017-01-18 03:23:12 +01:00
|
|
|
Return<void> BluetoothHci::initialize(
|
2016-10-14 00:45:02 +02:00
|
|
|
const ::android::sp<IBluetoothHciCallbacks>& cb) {
|
2017-03-17 00:23:23 +01:00
|
|
|
ALOGI("BluetoothHci::initialize()");
|
|
|
|
if (cb == nullptr) {
|
|
|
|
ALOGE("cb == nullptr! -> Unable to call initializationComplete(ERR)");
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
death_recipient_->setHasDied(false);
|
|
|
|
cb->linkToDeath(death_recipient_, 0);
|
2016-10-14 00:45:02 +02:00
|
|
|
|
|
|
|
bool rc = VendorInterface::Initialize(
|
2017-03-17 00:23:23 +01:00
|
|
|
[cb](bool status) {
|
|
|
|
auto hidl_status = cb->initializationComplete(
|
2017-01-18 03:23:12 +01:00
|
|
|
status ? Status::SUCCESS : Status::INITIALIZATION_ERROR);
|
2017-03-17 06:19:19 +01:00
|
|
|
if (!hidl_status.isOk()) {
|
|
|
|
ALOGE("VendorInterface -> Unable to call initializationComplete()");
|
|
|
|
}
|
2017-01-18 03:23:12 +01:00
|
|
|
},
|
2017-03-17 00:23:23 +01:00
|
|
|
[cb](const hidl_vec<uint8_t>& packet) {
|
|
|
|
auto hidl_status = cb->hciEventReceived(packet);
|
2017-03-17 06:19:19 +01:00
|
|
|
if (!hidl_status.isOk()) {
|
|
|
|
ALOGE("VendorInterface -> Unable to call hciEventReceived()");
|
|
|
|
}
|
2017-02-27 08:46:05 +01:00
|
|
|
},
|
2017-03-17 00:23:23 +01:00
|
|
|
[cb](const hidl_vec<uint8_t>& packet) {
|
|
|
|
auto hidl_status = cb->aclDataReceived(packet);
|
2017-03-17 06:19:19 +01:00
|
|
|
if (!hidl_status.isOk()) {
|
|
|
|
ALOGE("VendorInterface -> Unable to call aclDataReceived()");
|
|
|
|
}
|
2017-02-27 08:46:05 +01:00
|
|
|
},
|
2017-03-17 00:23:23 +01:00
|
|
|
[cb](const hidl_vec<uint8_t>& packet) {
|
|
|
|
auto hidl_status = cb->scoDataReceived(packet);
|
2017-03-17 06:19:19 +01:00
|
|
|
if (!hidl_status.isOk()) {
|
|
|
|
ALOGE("VendorInterface -> Unable to call scoDataReceived()");
|
|
|
|
}
|
2016-10-14 00:45:02 +02:00
|
|
|
});
|
2017-03-17 06:19:19 +01:00
|
|
|
if (!rc) {
|
2017-03-17 00:23:23 +01:00
|
|
|
auto hidl_status = cb->initializationComplete(Status::INITIALIZATION_ERROR);
|
2017-03-17 06:19:19 +01:00
|
|
|
if (!hidl_status.isOk()) {
|
|
|
|
ALOGE("VendorInterface -> Unable to call initializationComplete(ERR)");
|
|
|
|
}
|
|
|
|
}
|
2017-03-17 00:23:23 +01:00
|
|
|
|
|
|
|
unlink_cb_ = [cb](sp<BluetoothDeathRecipient>& death_recipient) {
|
|
|
|
if (death_recipient->getHasDied())
|
|
|
|
ALOGI("Skipping unlink call, service died.");
|
|
|
|
else
|
|
|
|
cb->unlinkToDeath(death_recipient);
|
|
|
|
};
|
|
|
|
|
2017-01-18 03:23:12 +01:00
|
|
|
return Void();
|
2016-10-14 00:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> BluetoothHci::close() {
|
2017-03-17 00:23:23 +01:00
|
|
|
ALOGI("BluetoothHci::close()");
|
|
|
|
unlink_cb_(death_recipient_);
|
2016-10-14 00:45:02 +02:00
|
|
|
VendorInterface::Shutdown();
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& command) {
|
|
|
|
sendDataToController(HCI_DATA_TYPE_COMMAND, command);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& data) {
|
|
|
|
sendDataToController(HCI_DATA_TYPE_ACL, data);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& data) {
|
|
|
|
sendDataToController(HCI_DATA_TYPE_SCO, data);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BluetoothHci::sendDataToController(const uint8_t type,
|
|
|
|
const hidl_vec<uint8_t>& data) {
|
2017-01-30 18:07:37 +01:00
|
|
|
VendorInterface::get()->Send(type, data.data(), data.size());
|
2016-10-14 00:45:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) {
|
|
|
|
return new BluetoothHci();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace implementation
|
|
|
|
} // namespace V1_0
|
|
|
|
} // namespace bluetooth
|
|
|
|
} // namespace hardware
|
|
|
|
} // namespace android
|