hcitool commands on firmware level

Dear all,

I am trying to build bluetooth hci controller for Home Assistant. 

I used official example for create usb bluetooth hci controller here:

~/ncs/v3.2.0/zephyr/samples/bluetooth/hci_usb

Due to the fact I want to listen to sensor which uses extended advertising and PHY CODED, I modified prj.conf to activate extended advertising and PHY CODED this way:

CONFIG_BT=y
CONFIG_BT_HCI_RAW=y
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=n
CONFIG_SAMPLE_USBD_PID=0x000B
CONFIG_SAMPLE_USBD_PRODUCT="Zephyr USBD BT HCI"
CONFIG_USBD_BT_HCI=y

CONFIG_BT_CTLR_ADV_EXT=y
CONFIG_BT_EXT_ADV=y
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191
CONFIG_BT_CTLR_ADV_SET=1

#added
CONFIG_BT_CTLR_PHY_CODED=y

With this setup I can listen to PHY CODED devices even in Home Assistant. But there is a problem. Home Assistant OS does not support hcitool commands. So I need to run Home Asisstant on top of Raspberry Pi OS in docker and on this setup I can control bluez stack as I wish, but definitely, I have to issue a command:

hcitool cmd 0x08 31 00 04 04 to activate PHY CODED (in btmgmt tool i see LECODEDRX,LECODEDTX).

Only then I see sensor advertising via PHY CODED.

What I wanted to achieve is the same purpose in Home Assistant OS. The problem is that in Home Assistant OS (without Raspberry Pi OS), I cannot issue command:

hcitool cmd 0x08 31 00 04 04

It simply is not possible, Home Assistant OS does not expose hcitool nor btmgmt commands which casual Linux can

BUT since I think hcitool just sends command to the bluetooth nrf52840 chip to activate PHY CODED, isn't it possible to activate PHY CODED on firmware level of NordicSDK/Zephyr build? I mean, I want to mimic the behaviour of hcitool command right on the firmware level of Zephyr and activate,what hcitool activates,directly in firmware, not on OS Linux level.


Does anyone know if this is even possible?

I tried a simple tuning on prj.conf like this:

#CONFIG_BT_CTLR_PHY=y
#CONFIG_BT_CTLR_PHY_CODED_SUPPORT=y
#CONFIG_HAS_BT_CTLR=y

#CONFIG_BT_HCI=y
#CONFIG_BT_PHY_UPDATE=y
#CONFIG_BT_AUTO_PHY_UPDATE=y

CONFIG_BT_USER_PHY_UPDATE=y
CONFIG_BT_OBSERVER=y

But none of these settings make any sense for me and I cannot find any reasonable example how to modify the sample to activate PHY CODED from start actually I hope the command 

hcitool cmd 0x08 31 00 04 04 does exactly what I am describing, I am not an expert in this.

Thank you

Parents
  • I want to mimic the behaviour of hcitool command right on the firmware level of Zephyr and activate,what hcitool activates,directly in firmware, not on OS Linux level.

    Not in a compliant HCI‑controller design. The HCI USB sample exposes raw HCI (CONFIG_BT_HCI_RAW=y), and by definition it waits for the host to send commands. There is no host stack in the firmware to issue HCI commands on its own.

    If I am not mistaken hcitool cmd 0x08 31 00 04 04 is LE Set Default PHY . That command only sets the default connection PHY preference. It does not enable coded scanning. Coded advertising discovery is controlled by LE Set Extended Scan Parameters followed by LE Set Extended Scan Enable , and those commands must come from the BlueZ host in your case.

    The hci_usb sample is a controller‑only build. By design it does not issue HCI commands to itself; it waits for the host to send them. So there isn’t a supported way to force coded scanning purely in the controller firmware without breaking HCI behavior.

    I think you can try to keep HCI USB, but make the host send the proper extended scan commands (0x2041/0x2042) with Coded PHY enabled. I do not have a Linux machine but I read somewhere that on standard Linux you can do this via btmgmt/btmon or a custom script. On Home Assistant OS, you might need an add‑on or integration that can send those HCI commands. I am also no expert in that area.

Reply
  • I want to mimic the behaviour of hcitool command right on the firmware level of Zephyr and activate,what hcitool activates,directly in firmware, not on OS Linux level.

    Not in a compliant HCI‑controller design. The HCI USB sample exposes raw HCI (CONFIG_BT_HCI_RAW=y), and by definition it waits for the host to send commands. There is no host stack in the firmware to issue HCI commands on its own.

    If I am not mistaken hcitool cmd 0x08 31 00 04 04 is LE Set Default PHY . That command only sets the default connection PHY preference. It does not enable coded scanning. Coded advertising discovery is controlled by LE Set Extended Scan Parameters followed by LE Set Extended Scan Enable , and those commands must come from the BlueZ host in your case.

    The hci_usb sample is a controller‑only build. By design it does not issue HCI commands to itself; it waits for the host to send them. So there isn’t a supported way to force coded scanning purely in the controller firmware without breaking HCI behavior.

    I think you can try to keep HCI USB, but make the host send the proper extended scan commands (0x2041/0x2042) with Coded PHY enabled. I do not have a Linux machine but I read somewhere that on standard Linux you can do this via btmgmt/btmon or a custom script. On Home Assistant OS, you might need an add‑on or integration that can send those HCI commands. I am also no expert in that area.

Children
No Data
Related