2 // Copyright 2015 The Android Open Source Project
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "bt_vendor"
19 #include "vendor_manager.h"
21 #include "base/logging.h"
24 #include "osi/include/log.h"
29 namespace test_vendor_lib {
31 // Initializes vendor manager for test controller. |p_cb| are the callbacks to
32 // be in TestVendorOp(). |local_bdaddr| points to the address of the Bluetooth
33 // device. Returns 0 on success, -1 on error.
34 static int TestVendorInitialize(const bt_vendor_callbacks_t* p_cb,
35 unsigned char* /* local_bdaddr */) {
36 LOG_INFO(LOG_TAG, "Initializing test controller.");
39 VendorManager::Initialize();
40 VendorManager* manager = VendorManager::Get();
41 manager->SetVendorCallbacks(*(const_cast<bt_vendor_callbacks_t*>(p_cb)));
42 return manager->Run() ? 0 : -1;
45 // Vendor specific operations. |opcode| is the opcode for Bluedroid's vendor op
46 // definitions. |param| points to operation specific arguments. Return value is
47 // dependent on the operation invoked, or -1 on error.
48 static int TestVendorOp(bt_vendor_opcode_t opcode, void* param) {
49 LOG_INFO(LOG_TAG, "Opcode received in vendor library: %d", opcode);
51 VendorManager* manager = VendorManager::Get();
55 case BT_VND_OP_POWER_CTRL: {
56 LOG_INFO(LOG_TAG, "Doing op: BT_VND_OP_POWER_CTRL");
57 int* state = static_cast<int*>(param);
58 if (*state == BT_VND_PWR_OFF)
59 LOG_INFO(LOG_TAG, "Turning Bluetooth off.");
60 else if (*state == BT_VND_PWR_ON)
61 LOG_INFO(LOG_TAG, "Turning Bluetooth on.");
65 // Give the HCI its fd to communicate with the HciTransport.
66 case BT_VND_OP_USERIAL_OPEN: {
67 LOG_INFO(LOG_TAG, "Doing op: BT_VND_OP_USERIAL_OPEN");
68 int* fd_list = static_cast<int*>(param);
69 fd_list[0] = manager->GetHciFd();
70 LOG_INFO(LOG_TAG, "Setting HCI's fd to: %d", fd_list[0]);
74 // Close the HCI's file descriptor.
75 case BT_VND_OP_USERIAL_CLOSE:
76 LOG_INFO(LOG_TAG, "Doing op: BT_VND_OP_USERIAL_CLOSE");
77 LOG_INFO(LOG_TAG, "Closing HCI's fd (fd: %d)", manager->GetHciFd());
78 manager->CloseHciFd();
81 case BT_VND_OP_FW_CFG:
82 LOG_INFO(LOG_TAG, "Unsupported op: BT_VND_OP_FW_CFG");
83 manager->GetVendorCallbacks().fwcfg_cb(BT_VND_OP_RESULT_FAIL);
87 LOG_INFO(LOG_TAG, "Op not recognized.");
93 // Closes the vendor interface and cleans up the global vendor manager object.
94 static void TestVendorCleanUp(void) {
95 LOG_INFO(LOG_TAG, "Cleaning up vendor library.");
96 VendorManager::CleanUp();
99 } // namespace test_vendor_lib
101 // Entry point of DLib.
102 const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
103 sizeof(bt_vendor_interface_t),
104 test_vendor_lib::TestVendorInitialize,
105 test_vendor_lib::TestVendorOp,
106 test_vendor_lib::TestVendorCleanUp