google / bumble

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibility of connecting bumble tcp-server controller with Zephyr application?

vChavezB opened this issue · comments

I am reading the docs but something was not clear to me.

My use case is the following, I am developing a BLE peripheral with Zephyr OS. This RTOS has the option of compiling as a linux posix binary to do unit tests, host debugging, etc. It also allows to use an hci linux interface to use the bluetooth controller from host.

https://github.com/zephyrproject-rtos/zephyr/blob/e47fc45c4d4ed3c04d6a147e10d2a52630b7f0d7/drivers/bluetooth/hci/userchan.c#L193

My question is if its possible to add a virtual hci with bumble and make my linux binary (BLE Peripheral) connect to it. Afterwards I would like to have a second virtual hci that I can connect to test that my bluetooth application (BLE Central) works (integration tests).

(BLE Peripheral)_________________________________________________________________(BLE Central)
Zephyr OS Linux Binary <----> Virtual HCI < -----> Virtual HCI <-----> Integration test application (python, C, java...)

From the bumble website I see that this would be covered in Use Case 4. Which example should I refer to create the two virtual HCI interfaces and link my "emulated devices" to these virtual HCIs.?

In addition I might be interested in Use Case 3, where I do my integration tests directly with Bumble. Which example should I refer to for this purpose?

Yes, this should be possible. What's needed here is to link the two 'virtual HCI' interfaces together. Unfortunately, the Linux HCI interfaces don't support that themselves. But you can do that with the Bumble 'local link', to which any number of virtual controllers can be attached, and communicate with each other. The app bumble-controllers (apps/controllers.py) does exactly that: instantiate N controllers, each with its own HCI transport, and link them together. For the HCI transport, you have a choice of several candidates (see the doc for a list of all the transports supported), but typically, for a local link, tcp-server:_:<port> is a reasonable choice, this will create a TCP socket on localhost:, on which HCI packets can be sent/received (the counterpart transport for a Bumble app that needs to connect to that controller is tcp-client:localhost:<port>). Now, what's left to do is tell the Zephyr app to also connect to one of the virtual HCI transports. Unfortunately, it seems that the userchan transport in Zephyr only supports HCI sockets (socket(PF_BLUETOOTH, ... in userchan.c), there's no way to ask for a TCP socket instead. So what would need to be done is to either create a new HCI transport in Zephyr, for which Bumble can act at the server (tcp socket, websocket, PTY, UDP, ...). Looks like a pretty straightforward addition (or modification of userchan.c).
Another option with Zephyr would be to configure your build to do HCI over UART, and enable the virtual PTTY UART mode, which can then be bridged to the Bumble controller (https://google.github.io/bumble/transports/pty.html), but I don't know if Zephyr can be configured that way.

For the HCI transport over TCP is there document I could refer to implement it or any client example (any language is fine).

Zephyr has an example with HCI Uart but I would have to check if its available for the posix port

samples/bluetooth/hci_uart

Thanks for the detailed answer!

For HCI over TCP, it's just like HCI or UART and many other stream-based channels: the data is a one-byte packet type (see the H4_XXX constants followed by the packet payload).
For a TCP socket instead of a BLUETOOTH socket, you would need to call connect instead of bind, to connect to the address/port of the TCP server.
NOTE: the hci_socket.py transport from Bumble is yet another type of transport, not a TCP socket, but an "HCI socket" which exists on Linux and allows connecting to the Bluetooth controller managed by the kernel, so that's not applicable here. The Python equivalent of what you want with Zephyr here is Bumble's tcp_client.py transport.

Thanks that should give me a good starting point.

I checked more in detail what zephyr does and from what I understand it uses the H4 transport protocol. So if I make a TCP client it should be able to connect to the TCP Server of Bumble.

I will try to implement it as it could be a nice use case to do integration tests with Zephyr OS without hardware :)

Another question. For my endeavor of integrating Zephyr to bumble I want to do a simple test.

  1. Build a BLE Heart rate sensor peripheral with Zephyr.
  2. Create a virtual controller with apps/controllers.py tcp-server:localhost:port.
  3. Run the zephyr binary and connect to the controller in point 2.
  4. Create another controller and verify that I get advertisement packets.

For the last point can I run run_controller_with_scanner.py tcp-client:localhost:<port> ?

What you need is a single controller with two transports (one for the Zephyr stack to use, and one for the Bumble stack with scanner to use). If you run two separate controllers, they won't "see" each other.
So, something like: bumble-controllers tcp-server:_:9000 tcp-server:_:9001 to start a controller accepting TCP connections on port 9000 and 9001. You can then connect the Zephyr binary to localhost:9000 and run a Bumble scanner connected to port 9001: bumble-scan tcp-client:localhost:9001.
The run_controller_with_scanner.py example does something a bit different: in the same process, it starts two controllers: one on which it also attaches a scanner, and the other one an external transport (so you could attach zephyr by using tcp-server:_:<port> for that transport). Running the controllers in a process and the scanner in a separate process, as described above with the controllers app, is more flexible, because you're not limited to attaching a scanner app, you can attach anything you want (like a GATT client, server, whatever). You can also use the controllers app with more than two controllers, if you want to attach many things to it (like more than one Zephyr device, or more than one Bumble device/app).

As you said the modification to TCP was relatively easy. I now get from bumble the following when the Zephyr app starts

INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_RESET_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_RESET_COMMAND
  return_parameters:       HCI_SUCCESS
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
  return_parameters:       000000000060000000
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_READ_LOCAL_VERSION_INFORMATION_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_VERSION_INFORMATION_COMMAND
  return_parameters:       0009000009ffff0000
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_READ_LOCAL_SUPPORTED_COMMANDS_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_SUPPORTED_COMMANDS_COMMAND
  return_parameters:       002000800000c000000000e40000002822000000000000040000f7ffff7f00000030f0f9ff01008004000000000000000000000000000000000000000000000000
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       0042c7fe1ed1d6b59a
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       00f07260669a2f1525
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       006f2c904e14a0fa47
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       006a1b0306bb6ba7fd
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       002cbb21bfe4c3e27f
INFO:bumble.controller:<<< [C0] HOST -> CONTROLLER: HCI_HOST_BUFFER_SIZE_COMMAND:
  host_acl_data_packet_length:             69
  host_synchronous_data_packet_length:     0
  host_total_num_acl_data_packets:         6
  host_total_num_synchronous_data_packets: 0
WARNING:bumble.controller:--- Unsupported command HCI_HOST_BUFFER_SIZE_COMMAND:
  host_acl_data_packet_length:             69
  host_synchronous_data_packet_length:     0
  host_total_num_acl_data_packets:         6
  host_total_num_synchronous_data_packets: 0
DEBUG:bumble.controller:>>> [C0] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_HOST_BUFFER_SIZE_COMMAND
  return_parameters:       HCI_UNKNOWN_HCI_COMMAND_ERROR

Do you make sense of why it fails? I see in Bumble that the command is implemented here

class HCI_Host_Buffer_Size_Command(HCI_Command):

Here is btw the commands that zephyr sends up to the point of the warning from bumble

[00:00:00.020,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 10 OCF 3
[00:00:00.040,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 10 OCF 1
[00:00:00.060,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 10 OCF 2
[00:00:00.080,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 20 OCF 18
[00:00:00.100,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 20 OCF 18
[00:00:00.120,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 20 OCF 18
[00:00:00.140,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 20 OCF 18
[00:00:00.160,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 3 cmd OGF 20 OCF 18
[00:00:00.180,000] <inf> bt_driver: uc_send: buf 0x55977d7b98c0 type 0 len 10 cmd OGF c OCF 33

I named the opcode as the OGF and OCF as you did here so we are speaking on the same name syntax

def hci_command_op_code(ogf, ocf):

The Unsupported command HCI_HOST_BUFFER_SIZE_COMMAND error means that the Bumble virtual controller doesn't implement this command. The virtual controller is pretty minimal at this stage, so it doesn't implement all the HCI commands that a full featured (real) controller would, it only implements enough to get some basic interop working. It hasn't been tested much with other stacks than Bumble, so it's not surprising to encounter stacks that issue commands that it doesn't yet support.
There's a longer term plan to replace the Bumble virtual controller implementation with something much more comprehensive, from another open source project. But that's not quite ready yet, so for now, I will add support for that command in the controller.
Expect a PR soon.

thanks, will be looking forward to test the changes :)

I made a fork from the PR you made since the Zephyr App still did not work. The controller was missing the Set Controller To Host Flow Control Command.

See the changes I made

vChavezB@66620db

I am not sure if thats enough to fool the Zephyr stack but now with bumble-scan I do not get any adv. packets.

Commands (seperate terminals)

python3 controllers.py tcp-server:172.22.13.123:9000 tcp-server:172.22.13.123:9001
 ./zephyr.exe --bt-dev=172.22.13.123:9001
python3 scan.py tcp-client:172.22.13.123:9001

Note I did not find the bumble-controllers binary for python so I ran the script directly from source.

Zephyr Log:

*** Booting Zephyr OS build v3.3.99-ncs1 ***
[00:00:00.420,000] <wrn> bt_ecc: bt_pub_key_gen: ECC HCI commands not available
[00:00:00.420,000] <inf> bt_hci_core: bt_dev_show_info: Identity: F4:27:2F:2A:4D:FE (random)
[00:00:00.420,000] <inf> bt_hci_core: bt_dev_show_info: HCI: version 5.0 (0x09) revision 0x0000, manufacturer 0xffff
[00:00:00.420,000] <inf> bt_hci_core: bt_dev_show_info: LMP: version 5.0 (0x09) subver 0x0000
Bluetooth initialized
Advertising successfully started

Bumble controller log

DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_RESET_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_RESET_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_READ_LOCAL_SUPPORTED_COMMANDS_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_SUPPORTED_COMMANDS_COMMAND
  return_parameters:       002000800000c000000000e40000002822000000000000040000f7ffff7f00000030f0f9ff01008004000000000000000000000000000000000000000000000000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
  return_parameters:       00ff49010000000000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_READ_LOCAL_VERSION_INFORMATION_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_VERSION_INFORMATION_COMMAND
  return_parameters:       0009000009ffff0000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_SET_EVENT_MASK_COMMAND:
  event_mask: ffffffffffffff3f
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_SET_EVENT_MASK_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_EVENT_MASK_COMMAND:
  le_event_mask: fffff00000000000
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_EVENT_MASK_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_BUFFER_SIZE_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_BUFFER_SIZE_COMMAND
  return_parameters:       001b0040
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH_COMMAND
  return_parameters:       001b004801
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_COMMAND:
  suggested_max_tx_octets: 251
  suggested_max_tx_time:   2120
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_READ_BD_ADDR_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_BD_ADDR_COMMAND
  return_parameters:       00000000000000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_RANDOM_ADDRESS_COMMAND:
  random_address: F0:F1:F2:F3:F4:F5
DEBUG:bumble.controller:new random address: F0:F1:F2:F3:F4:F5
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_RANDOM_ADDRESS_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_CLEAR_RESOLVING_LIST_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_CLEAR_RESOLVING_LIST_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_SCAN_PARAMETERS_COMMAND:
  le_scan_type:           1
  le_scan_interval:       96
  le_scan_window:         96
  own_address_type:       RANDOM
  scanning_filter_policy: 0
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_SCAN_PARAMETERS_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_SCAN_ENABLE_COMMAND:
  le_scan_enable:    1
  filter_duplicates: 1
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_SCAN_ENABLE_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.transport.tcp_server:connection from None
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_RESET_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_RESET_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
  return_parameters:       000000000060000000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_READ_LOCAL_VERSION_INFORMATION_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_VERSION_INFORMATION_COMMAND
  return_parameters:       0009000009ffff0000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_READ_LOCAL_SUPPORTED_COMMANDS_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_LOCAL_SUPPORTED_COMMANDS_COMMAND
  return_parameters:       002000800000c000000000e40000002822000000000000040000f7ffff7f00000030f0f9ff01008004000000000000000000000000000000000000000000000000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       0068448f4e3cffed7a
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       003d89bb1016505b53
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       00e49e3ea8d624e8e0
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       0026422ad6acd3d5d2
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_RAND_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_RAND_COMMAND
  return_parameters:       001da9c42991d7943e
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_HOST_BUFFER_SIZE_COMMAND:
  host_acl_data_packet_length:             69
  host_synchronous_data_packet_length:     0
  host_total_num_acl_data_packets:         6
  host_total_num_synchronous_data_packets: 0
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_HOST_BUFFER_SIZE_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_SET_CONTROLLER_TO_HOST_FLOW_CONTROL_COMMAND: 01
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_SET_CONTROLLER_TO_HOST_FLOW_CONTROL_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_LOCAL_SUPPORTED_FEATURES_COMMAND
  return_parameters:       00ff49010000000000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_BUFFER_SIZE_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_BUFFER_SIZE_COMMAND
  return_parameters:       001b0040
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_SUPPORTED_STATES_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_SUPPORTED_STATES_COMMAND
  return_parameters:       00ffff3fffff030000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_MAXIMUM_DATA_LENGTH_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_MAXIMUM_DATA_LENGTH_COMMAND
  return_parameters:       001b0010271b001027
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_COMMAND:
  suggested_max_tx_octets: 27
  suggested_max_tx_time:   10000
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_READ_RESOLVING_LIST_SIZE_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_READ_RESOLVING_LIST_SIZE_COMMAND
  return_parameters:       0008
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_EVENT_MASK_COMMAND:
  le_event_mask: 7e0a000000000000
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_EVENT_MASK_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_SET_EVENT_MASK_COMMAND:
  event_mask: 9088000200800020
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_SET_EVENT_MASK_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_READ_BD_ADDR_COMMAND
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_READ_BD_ADDR_COMMAND
  return_parameters:       00000000000000
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_RANDOM_ADDRESS_COMMAND:
  random_address: F4:27:2F:2A:4D:FE
DEBUG:bumble.controller:new random address: F4:27:2F:2A:4D:FE
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_RANDOM_ADDRESS_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_ADVERTISING_PARAMETERS_COMMAND:
  advertising_interval_min:  160
  advertising_interval_max:  240
  advertising_type:          ADV_IND
  own_address_type:          RANDOM
  peer_address_type:         PUBLIC_DEVICE_ADDRESS
  peer_address:              00:00:00:00:00:00/P
  advertising_channel_map:   7
  advertising_filter_policy: 0
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_ADVERTISING_PARAMETERS_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_ADVERTISING_DATA_COMMAND:
  advertising_data: 02010607030d180f180a18
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_ADVERTISING_DATA_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_SCAN_RESPONSE_DATA_COMMAND:
  scan_response_data: 18095a6570687972204865617274726174652053656e736f72
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_SCAN_RESPONSE_DATA_COMMAND
  return_parameters:       HCI_SUCCESS
DEBUG:bumble.controller:<<< [C1] HOST -> CONTROLLER: HCI_LE_SET_ADVERTISING_ENABLE_COMMAND:
  advertising_enable: 1
DEBUG:bumble.controller:>>> [C1] CONTROLLER -> HOST: HCI_COMMAND_COMPLETE_EVENT:
  num_hci_command_packets: 1
  command_opcode:          HCI_LE_SET_ADVERTISING_ENABLE_COMMAND
  return_parameters:       HCI_SUCCESS

Bumble scan log

<<< connecting to HCI...
<<< connected

Nevermind my last comment, I understood incorrectly how to use the script app/controllers.py. The connecting port hast to be different for each device.

python3 controllers.py tcp-server:172.22.13.123:9000 tcp-server:172.22.13.123:9001
 ./zephyr.exe --bt-dev=172.22.13.123:9000
python3 scan.py tcp-client:172.22.13.123:9001

Now I get the following :)

 C5:DE:28:83:D1:CE [RANDOM](static):
  RSSI: -50 ██████████████████████
  [Flags]: LE General,No BR/EDR
  [Complete List of 16-bit Service Class UUIDs]: UUID-16:180D (Heart Rate), UUID-16:180F (Battery), UUID-16:180A (Device Information)
  [Flags]: LE General,No BR/EDR
  [Complete List of 16-bit Service Class UUIDs]: UUID-16:180D (Heart Rate), UUID-16:180F (Battery), UUID-16:180A (Device Information)

I want to do a small proof of concept with android emulator to showcase what could be done if the TCP client patch I made is added to zephyr.

Would it be possible to make the bluetooth interface from Android Emulator (Android Studio) connect to bumble´s virtual controller?

I saw this here

https://google.github.io/bumble/transports/android_emulator.html

I am familiar with Android Studio and Android Emulator as some time ago I developed an app but honestly I do not know how can I setup the Android emulator to connect to bumble. I made a device but Im trying to figure out where are the settings that bumble needs

grafik

I think I found the docs about the android emulator, I will try to follow them to see if I can make it work

https://google.github.io/bumble/platforms/android.html

Update:

I think I figured out how to run the bumble sample with the gatt_server. Now I need to check how to direct traffic from Android studio in windows to my WSL subsystem where bumble and zephyr are running.

grafik

Thats a screenshot of the NRF connect app connected to bumble.

This issue should be solved by PR

#216

plus this commit I made

vChavezB@66620db

Just as a follow up, I was testing another zephyr app and the following commands also need to be mocked in controllers.py

  • hci_le_set_extended_advertising_parameters_command
  • hci_le_set_advertising_set_random_address_command
  • hci_le_set_extended_advertising_data_command
  • hci_le_set_extended_scan_response_data_command
  • hci_le_set_extended_advertising_enable_command