diff options
Diffstat (limited to 'test/headless/headless.cc')
-rw-r--r-- | test/headless/headless.cc | 101 |
1 files changed, 78 insertions, 23 deletions
diff --git a/test/headless/headless.cc b/test/headless/headless.cc index 9083e9c42..a3b54410a 100644 --- a/test/headless/headless.cc +++ b/test/headless/headless.cc @@ -17,17 +17,44 @@ #define LOG_TAG "bt_headless" #include <dlfcn.h> // dlopen +#include <algorithm> +#include <iostream> +#include <map> #include "base/logging.h" // LOG() stdout and android log #include "include/hardware/bluetooth.h" #include "osi/include/log.h" // android log only #include "test/headless/get_options.h" #include "test/headless/headless.h" +#include "test/headless/interface.h" extern bt_interface_t bluetoothInterface; using namespace bluetooth::test::headless; +std::map<const std::string, std::list<callback_function_t>> + interface_api_callback_map_; + +void headless_add_callback(const std::string interface_name, + callback_function_t function) { + if (interface_api_callback_map_.find(interface_name) == + interface_api_callback_map_.end()) { + interface_api_callback_map_.emplace(interface_name, + std::list<callback_function_t>()); + } + interface_api_callback_map_[interface_name].push_back(function); +} + +void headless_remove_callback(const std::string interface_name, + callback_function_t function) { + if (interface_api_callback_map_.find(interface_name) == + interface_api_callback_map_.end()) { + ASSERT_LOG(false, "No callbacks registered for interface:%s", + interface_name.c_str()); + } + interface_api_callback_map_[interface_name].remove(function); +} + namespace { std::mutex adapter_state_mutex_; std::condition_variable adapter_state_cv_; @@ -40,59 +67,79 @@ void adapter_state_changed(bt_state_t state) { } void adapter_properties(bt_status_t status, int num_properties, bt_property_t* properties) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } void remote_device_properties(bt_status_t status, RawAddress* bd_addr, int num_properties, bt_property_t* properties) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } void device_found(int num_properties, bt_property_t* properties) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } void discovery_state_changed(bt_discovery_state_t state) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } /** Bluetooth Legacy PinKey Request callback */ void pin_request(RawAddress* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod, bool min_16_digit) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } void ssp_request(RawAddress* remote_bd_addr, bt_bdname_t* bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } /** Bluetooth Bond state changed callback */ /* Invoked in response to create_bond, cancel_bond or remove_bond */ void bond_state_changed(bt_status_t status, RawAddress* remote_bd_addr, bt_bond_state_t state) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } /** Bluetooth ACL connection state changed callback */ void acl_state_changed(bt_status_t status, RawAddress* remote_bd_addr, - bt_acl_state_t state) { - LOG_INFO(LOG_TAG, "%s", __func__); -} - -void thread_event(bt_cb_thread_evt evt) { LOG_INFO(LOG_TAG, "%s", __func__); } + bt_acl_state_t state, bt_hci_error_code_t hci_reason) { + auto callback_list = interface_api_callback_map_.at(__func__); + for (auto callback : callback_list) { + interface_data_t params{ + .name = __func__, + .params.acl_state_changed.status = status, + .params.acl_state_changed.remote_bd_addr = remote_bd_addr, + .params.acl_state_changed.state = state, + .params.acl_state_changed.hci_reason = hci_reason, + }; + (callback)(params); + } + LOG_INFO("%s status:%s device:%s state:%s", __func__, + bt_status_text(status).c_str(), remote_bd_addr->ToString().c_str(), + (state) ? "disconnected" : "connected"); +} + +/** Bluetooth Link Quality Report callback */ +void link_quality_report(uint64_t timestamp, int report_id, int rssi, int snr, + int retransmission_count, int packets_not_receive_count, + int negative_acknowledgement_count) { + LOG_INFO("%s", __func__); +} + +void thread_event(bt_cb_thread_evt evt) { LOG_INFO("%s", __func__); } void dut_mode_recv(uint16_t opcode, uint8_t* buf, uint8_t len) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } void le_test_mode(bt_status_t status, uint16_t num_packets) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } void energy_info(bt_activity_energy_info* energy_info, bt_uid_traffic_t* uid_data) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); } bt_callbacks_t bt_callbacks{ @@ -111,22 +158,23 @@ bt_callbacks_t bt_callbacks{ .dut_mode_recv_cb = dut_mode_recv, .le_test_mode_cb = le_test_mode, .energy_info_cb = energy_info, + .link_quality_report_cb = link_quality_report, }; // HAL HARDWARE CALLBACKS // OS CALLOUTS bool set_wake_alarm_co(uint64_t delay_millis, bool should_wake, alarm_cb cb, void* data) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); return true; } int acquire_wake_lock_co(const char* lock_name) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); return 1; } int release_wake_lock_co(const char* lock_name) { - LOG_INFO(LOG_TAG, "%s", __func__); + LOG_INFO("%s", __func__); return 0; } @@ -141,7 +189,14 @@ bt_os_callouts_t bt_os_callouts{ void HeadlessStack::SetUp() { LOG(INFO) << __func__ << " Entry"; - int status = bluetoothInterface.init(&bt_callbacks, false, false, 0, false); + const bool start_restricted = false; + const bool is_common_criteria_mode = false; + const int config_compare_result = 0; + const bool is_atv = false; + int status = bluetoothInterface.init( + &bt_callbacks, start_restricted, is_common_criteria_mode, + config_compare_result, StackInitFlags(), is_atv); + (status == BT_STATUS_SUCCESS) ? LOG(INFO) << __func__ << " Initialized bluetooth callbacks" : LOG(FATAL) << "Failed to initialize Bluetooth stack"; @@ -152,15 +207,15 @@ void HeadlessStack::SetUp() { : LOG(ERROR) << "Failed to set up Bluetooth OS callouts"; bluetoothInterface.enable(); - LOG_INFO(LOG_TAG, "%s HeadlessStack stack has enabled", __func__); + LOG_INFO("%s HeadlessStack stack has enabled", __func__); std::unique_lock<std::mutex> lck(adapter_state_mutex_); while (bt_state_ != BT_STATE_ON) adapter_state_cv_.wait(lck); - LOG_INFO(LOG_TAG, "%s HeadlessStack stack is operational", __func__); + LOG_INFO("%s HeadlessStack stack is operational", __func__); } void HeadlessStack::TearDown() { - LOG_INFO(LOG_TAG, "Stack has disabled"); + LOG_INFO("Stack has disabled"); int status = bluetoothInterface.disable(); LOG(INFO) << __func__ << " Interface has been disabled status:" << status; @@ -170,5 +225,5 @@ void HeadlessStack::TearDown() { std::unique_lock<std::mutex> lck(adapter_state_mutex_); while (bt_state_ != BT_STATE_OFF) adapter_state_cv_.wait(lck); - LOG_INFO(LOG_TAG, "%s HeadlessStack stack has exited", __func__); + LOG_INFO("%s HeadlessStack stack has exited", __func__); } |