google / google/bumble

Connection between android-netsim and Zephyr BT Stack work arounds

Open
#220 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
555
Forks
138
Avg merge
3d 15h
Merged PRs (30d)
9

Description

As a follow upt to the issues I posted

https://github.com/google/bumble/issues/215
https://github.com/google/bumble/issues/217

I have managed to connect the Zephyr Bluetooth stack to the Android emulator with the bumble hci-bridge 👍

I open this issue to discuss the workarounds to make it work.

After some trial and error I figured out that the following commands from host to controller (zephyr tcp-client to android-netsim) should be filtered and not sent to the android-netsim.

- HCI_SET_CONTROLLER_TO_HOST_FLOW_CONTROL_COMMAND
- HCI_LE_CONNECTION_UPDATE_COMMAND
- HCI_LE_SET_PHY_COMMAND
- HCI_LE_READ_REMOTE_FEATURES_COMMAND
- HCI_HOST_NUMBER_OF_COMPLETED_PACKETS_COMMAND

An example of how to make it work

1. Make sure your Zephyr OS is updated to at least this commit

https://github.com/zephyrproject-rtos/zephyr/commit/33c922a771aee12e329de1a10c6fc65b0e01ed4a

2. Compile the BLE Hearbeat sensor sample from zephyr located [here ](https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/bluetooth/peripheral_hr).

For any other zephyr project be sure to set these configurations as follows
- `CONFIG_BT_HCI_ACL_FLOW_CONTROL=n`
- `CONFIG_BT_SMP_SC_PAIR_ONLY=n`

3. Run the android emulator.

`emulator -avd Pixel_7_API_34 -packet-streamer-endpoint default`

Note: Only tested with API 34, other APIs <34 gave me some problems

4. Create the hci-bridge with bumble and the filters for hci commands I mentioned above

`bumble-hci-bridge tcp-server:_:9000 android-netsim 0x03:0x0031,0x08:0x013,0x08:0x032,0x08:0x016,0x03:0x035`

update: If in zephyr you set `CONFIG_BT_HCI_ACL_FLOW_CONTROL=n` you do not need to filter the hci commands. I.e., you can run `bumble-hci-bridge tcp-server:_:9000 android-netsim`

5. Run the zephyr binary

`zephyr.exe --bt-dev=127.0.0.1:9000`

Note: This instruction assume that zephyr binary has access to localhost. In case Android emulator and bumble are installed in Windows and using WSL to compile and execute the zephyr binary, then you need to get the proxy IP for localhost by running `cat /etc/resolv.conf ` and obtaining the nameserver ip address.

And here a small video of the Proof of concept. Note I have not tested every option from the BT Zephyr stack or the APIs so this is still experimental.

Upper left screen is the HCI traffice between zephyr bluetooth stack (host) and the android-netsim (Controller). Lower window is the zephyr binary running the peripheral_hr example in the Windows Subsystem for Linux. And on the right is the Android emulator running with Android API 34 and the NRF Connect App to test the GATT notification of the peripheral_hr sample.

https://github.com/google/bumble/assets/47216966/5c312c5e-54c0-4b74-b368-830735f45605

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.