google / bumble

Apache License 2.0
259 stars 74 forks source link

Android Emulator - Receiving UNEXPECTED commands #453

Closed sbsos closed 4 weeks ago

sbsos commented 7 months ago

Nevermind this issue. After handling specific packets, and filtering others, it now can enable BLE

I have a nRF Dongle I flashed with the zypher firmware that was mentioned in the documentation.

I am using Android emulator version 34.1.19.0, with a Android 14 Pixel 8 simulator.

Running: bumble-hci-bridge android-netsim:_:8877,mode=controller usb:0 ./emulator -packet-streamer-endpoint localhost:8877 -avd Pickle -no-snapshot-load

When I attempt to toggle BLE on the emulator, I see a lot of proper communication on the bridge, but there are a couple packets that always are breaking, which prevent me from turning BLE on, on the emulator. I tried filtering the breaking packets, but

Bridge: INFO:bumble.bridge:[HOST->CONTROLLER] HCI_WRITE_LE_HOST_SUPPORT_COMMAND: le_supported_host: 1 simultaneous_le_host: 0 INFO:bumble.bridge:[CONTROLLER->HOST] HCI_COMMAND_STATUS_EVENT: status: HCI_UNKNOWN_HCI_COMMAND_ERROR num_hci_command_packets: 1 command_opcode: HCI_WRITE_LE_HOST_SUPPORT_COMMAND INFO:bumble.bridge:[HOST->CONTROLLER] HCI_READ_LOCAL_NAME_COMMAND INFO:bumble.bridge:[CONTROLLER->HOST] HCI_COMMAND_STATUS_EVENT: status: HCI_UNKNOWN_HCI_COMMAND_ERROR num_hci_command_packets: 1 command_opcode: HCI_READ_LOCAL_NAME_COMMAND

Logcat: 03-22 09:28:15.545 2771 2901 E bluetooth: packages/modules/Bluetooth/system/gd/hci/hci_layer.cc:162 on_command_status: Received UNEXPECTED command status:UNKNOWN_HCI_COMMAND opcode:0xc6d (WRITE_LE_HOST_SUPPORT) 03-22 09:28:15.546 2771 2901 F bluetooth: assertion 'view.IsValid()' failed 03-22 09:28:15.546 2771 2901 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 2901 (bt_stack_manage), pid 2771 (droid.bluetooth) 03-22 09:28:16.298 2911 2911 F DEBUG : Cmdline: com.google.android.bluetooth 03-22 09:28:16.299 2911 2911 F DEBUG : pid: 2771, tid: 2901, name: bt_stack_manage >>> com.google.android.bluetooth <<< 03-22 09:28:16.302 2911 2911 F DEBUG : pc 0000000000aba8c1 /apex/com.android.btservices/lib64/libbluetooth_jni.so (void bluetooth::hci::Controller::impl::check_status(bluetooth::hci::CommandCompleteView)+561) (BuildId: 07f121772f0589874ca9fdd71c8d3406)

03-22 09:51:09.668 1279 1313 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 1313 (bt_stack_manage), pid 1279 (droid.bluetooth) 03-22 09:51:22.532 558 581 D ActivityManagerTiming: OnBootPhase_1000_com.android.server.bluetooth.BluetoothService 03-22 09:51:23.400 1326 1326 F DEBUG : Cmdline: com.google.android.bluetooth 03-22 09:51:23.400 1326 1326 F DEBUG : pid: 1279, tid: 1313, name: bt_stack_manage >>> com.google.android.bluetooth <<< 03-22 09:51:23.401 1326 1326 F DEBUG : pc 0000000000ab5067 /apex/com.android.btservices/lib64/libbluetooth_jni.so (bluetooth::hci::Controller::impl::read_local_name_complete_handler(bluetooth::hci::CommandCompleteView)+951) (BuildId: 07f121772f0589874ca9fdd71c8d3406)

If there is anything else that would be helpful, please let me know.

Thank you!

barbibulle commented 6 months ago

It seems that the Android Bluetooth stack isn't happy when the controller it is talking to does not support the HCI_WRITE_LE_HOST_SUPPORT_COMMAND command. One way around this is to tell the bumble-hci-bridge app to short-circuit this command (always answer SUCCESS). That command has the following opcode: hci_command_op_code(0x03, 0x006D). So you can include 0x03:0x006D on the bumble-hci-bridge command-line (the last parameter is a command-short-circuit-list, which is a command-separated list of commands to short-circuit, expressed as hex-value tuple.