Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Bluetooth service timeout on MT6797/Chuwi Hi9 Air #399

@ius

Description

@ius

Bluetooth fails to enable on AOSP 9.0 r31 / Chuwi Hi9 Air (MT6797).

Logcat reveals an ANR in com.android.bluetooth

02-10 00:13:16.732  1031  1112 E ActivityManager: ANR in com.android.bluetooth

Root cause is a timeout during bt module intialization, specifically in controller_module

02-10 00:12:51.322  9903  9942 I bt_core_module: module_start_up Starting module "controller_module"
02-10 00:12:55.064  9903  9919 E AdapterState: BLE_TURNING_ON : BLE_START_TIMEOUT

/system/bt/device/src/controller.cc attempts to discover device capabilities using HCI commands, enabling the HCI snoop log shows it times out after having sent LE Read Maximum Data Length, receiving a response of Status: Unknown HCI command

This command is sent conditionally based on whether the device declares support for it (LE Read Local Supported Features).

It appears MT6797 Bluetooth firmware as used in Chuwi Hi9 Air falsely claims to support this command. The controller_module's response parser on the other hand does not account for command failure, leading to a lockup and eventually the timeout.

Hack to demonstrate a workaround:

diff --git a/device/src/controller.cc b/device/src/controller.cc
index a07e54b..24bae28 100644
--- a/device/src/controller.cc
+++ b/device/src/controller.cc
@@ -66,9 +66,9 @@ static uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE];
 static bt_device_features_t features_ble;
 static uint16_t ble_suggested_default_data_length;
 static uint16_t ble_supported_max_tx_octets;
-static uint16_t ble_supported_max_tx_time;
-static uint16_t ble_supported_max_rx_octets;
-static uint16_t ble_supported_max_rx_time;
+//static uint16_t ble_supported_max_tx_time;
+//static uint16_t ble_supported_max_rx_octets;
+//static uint16_t ble_supported_max_rx_time;
 
 static uint16_t ble_maxium_advertising_data_length;
 static uint8_t ble_number_of_supported_advertising_sets;
@@ -216,6 +216,7 @@ static future_t* start_up(void) {
           response, &ble_resolving_list_max_size);
     }
 
+    /*
     if (HCI_LE_DATA_LEN_EXT_SUPPORTED(features_ble.as_array)) {
       response =
           AWAIT_COMMAND(packet_factory->make_ble_read_maximum_data_length());
@@ -228,6 +229,7 @@ static future_t* start_up(void) {
       packet_parser->parse_ble_read_suggested_default_data_length_response(
           response, &ble_suggested_default_data_length);
     }
+    */
 
     if (HCI_LE_EXTENDED_ADVERTISING_SUPPORTED(features_ble.as_array)) {
       response = AWAIT_COMMAND(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions