Skip to content

Commit

Permalink
Add properties to disable some features/commands/states that the ble …
Browse files Browse the repository at this point in the history
…chip declared but doesnt actually support
  • Loading branch information
phhusson committed May 27, 2023
1 parent e717a2f commit 44f470e
Showing 1 changed file with 69 additions and 4 deletions.
73 changes: 69 additions & 4 deletions system/gd/hci/controller.cc
Expand Up @@ -16,6 +16,7 @@

#include "hci/controller.h"

#include <base/strings/string_split.h>
#include <future>
#include <memory>
#include <string>
Expand All @@ -25,6 +26,8 @@
#include "hci/hci_layer.h"
#include "hci_controller_generated.h"
#include "os/metrics.h"
#include "os/system_properties.h"
using bluetooth::os::GetSystemProperty;

namespace bluetooth {
namespace hci {
Expand Down Expand Up @@ -259,7 +262,23 @@ struct Controller::impl {
ASSERT(complete_view.IsValid());
ErrorCode status = complete_view.GetStatus();
ASSERT_LOG(status == ErrorCode::SUCCESS, "Status 0x%02hhx, %s", status, ErrorCodeText(status).c_str());
local_supported_commands_ = complete_view.GetSupportedCommands();
//local_supported_commands_ = complete_view.GetSupportedCommands();

auto local_commands = complete_view.GetSupportedCommands();
std::string ignored_commands = GetSystemProperty("persist.sys.bt.unsupported.commands").value_or("");

if (ignored_commands != "") {
auto s = base::SplitString(ignored_commands, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for(auto command: s) {
int index = std::stoi(command);
LOG_WARN("Ignoring local supported command %d", index);
uint16_t byte_index = index / 10;
uint16_t bit_index = index % 10;
local_commands[byte_index] &= ~(1 << bit_index);
}
}

local_supported_commands_ = local_commands;
}

void read_local_extended_features_complete_handler(std::promise<void> promise, CommandCompleteView view) {
Expand All @@ -268,7 +287,25 @@ struct Controller::impl {
ErrorCode status = complete_view.GetStatus();
ASSERT_LOG(status == ErrorCode::SUCCESS, "Status 0x%02hhx, %s", status, ErrorCodeText(status).c_str());
uint8_t page_number = complete_view.GetPageNumber();
extended_lmp_features_array_.push_back(complete_view.GetExtendedLmpFeatures());

//extended_lmp_features_array_.push_back(complete_view.GetExtendedLmpFeatures());
auto lmp_features = complete_view.GetExtendedLmpFeatures();

std::string ignored_features = GetSystemProperty("persist.sys.bt.unsupported.ogfeatures").value_or("");

if (ignored_features != "") {
auto s = base::SplitString(ignored_features, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
int offset = page_number * 64;
for(auto feature: s) {
int index = std::stoi(feature) - offset;
if(index >= 0 && index < 64) {
LOG_WARN("Ignoring local supported feature %d", index);
lmp_features &= ~(1ULL << index);
}
}
}
extended_lmp_features_array_.push_back(lmp_features);

bluetooth::os::LogMetricBluetoothLocalSupportedFeatures(page_number, complete_view.GetExtendedLmpFeatures());
// Query all extended features
if (page_number < complete_view.GetMaximumPageNumber()) {
Expand Down Expand Up @@ -348,15 +385,43 @@ struct Controller::impl {
ASSERT(complete_view.IsValid());
ErrorCode status = complete_view.GetStatus();
ASSERT_LOG(status == ErrorCode::SUCCESS, "Status 0x%02hhx, %s", status, ErrorCodeText(status).c_str());
le_local_supported_features_ = complete_view.GetLeFeatures();

//le_local_supported_features_ = complete_view.GetLeFeatures();
auto local_features = complete_view.GetLeFeatures();
std::string ignored_features = GetSystemProperty("persist.sys.bt.unsupported.lefeatures").value_or("");

if (ignored_features != "") {
auto s = base::SplitString(ignored_features, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for(auto feature: s) {
int index = std::stoi(feature);
LOG_WARN("Ignoring local supported feature %d", index);
local_features &= ~(1ULL << index);
}
}

le_local_supported_features_ = local_features;
}

void le_read_supported_states_handler(CommandCompleteView view) {
auto complete_view = LeReadSupportedStatesCompleteView::Create(view);
ASSERT(complete_view.IsValid());
ErrorCode status = complete_view.GetStatus();
ASSERT_LOG(status == ErrorCode::SUCCESS, "Status 0x%02hhx, %s", status, ErrorCodeText(status).c_str());
le_supported_states_ = complete_view.GetLeStates();
//le_supported_states_ = complete_view.GetLeStates();

auto local_states = complete_view.GetLeStates();
std::string ignored_states = GetSystemProperty("persist.sys.bt.unsupported.states").value_or("");

if (ignored_states != "") {
auto s = base::SplitString(ignored_states, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
for(auto state: s) {
int index = std::stoi(state);
LOG_WARN("Ignoring local supported state %d", index);
local_states &= ~(1ULL << index);
}
}

le_supported_states_ = local_states;
}

void le_read_connect_list_size_handler(CommandCompleteView view) {
Expand Down

3 comments on commit 44f470e

@ildar
Copy link

@ildar ildar commented on 44f470e Aug 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any guide how to use this? Or at least maybe an example for some phone?

@phhusson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum no sorry. Next time I debug a device with such an issue I'll try to think of writing a little something. Do you have a bluetooth issue that you think is related to this you want me to check?

@ildar
Copy link

@ildar ildar commented on 44f470e Aug 17, 2023 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.