# Bluetooth on Raspberry Pi: ng_h4

<span class="badge badge-part">code done, radio silent</span> FreeBSD 15.1-RELEASE-p7. The repository is not public yet. Everything below has run against a simulated radio, not yet against the real chip.

## The plan

```text
tty  <->  ng_tty(4)  <->  ng_h4  <->  ng_hci(4)  <->  ng_l2cap(4)
```

`ng_h4` is a netgraph node of type `h4` that frames HCI packets over a UART. Around it sit four small tools: `rpibtpower` (the radio's power GPIO), `rpibtprobe`, `rpibtfw` (sends the `.hcd` firmware patch: `BCM43430B0.hcd`, `BCM43430A1.hcd` or `BCM4345C0.hcd`) and `rpibtattach`, plus an `rc.d/rpibt` script and man pages for all of them.

| Board | Status |
|---|---|
| Zero 2 W (43430) | First target. Against the simulator: load/unload 10 of 10, all 174 firmware records sent, `read_bd_addr` 10 of 10. |
| Pi 4 (CYW43455) | Built, never run. |
| Pi 5 | Blocked: FreeBSD 15.1 has no driver for the Pi 5 UART or the radio's power GPIO. |

## Planned setup (untested on the real radio)

<ol class="steps">
<li>

Free the radio's UART from the serial console first. Then build and install:

```sh
make module tools
make install
```

</li>
<li>

Enable it in `/etc/rc.conf`. On a Zero 2 W that is one line:

```sh
rpibt_enable="YES"
```

On a Pi 4 add the power line:

```sh
rpibt_gpio_device="/dev/gpioc1"
rpibt_power_pin="0"
rpibt_power_flags="-H -I"
```

</li>
<li>

Start it and ask the radio for its address:

```sh
service rpibt start
service rpibt status
hccontrol -n ubt8hci read_bd_addr
```

</li>
</ol>

## Where it is stuck

With the radio on the PL011 UART the chip comes out of reset and signals ready, and then the UART sends nothing. FreeBSD's `uart_pl011` takes no baud clock from the `clocks` property and has no RTS/CTS flow control. That report is drafted (see [Upstream reports](/reports/)).

On the mini UART it was worse: the Zero 2 W kernel stopped right after `armv8crypto0: CPU lacks AES instructions` in 3 boots out of 3, and the only way back was editing `config.txt` from another computer.

Along the way the tests (2749 C assertions plus 1030 in stubs) turned up a NULL pointer dereference in the FreeBSD HCI event code at `ng_hci_evnt.c:972`. It is on the list for a report.
