Skip to content

Bluetooth

Lucas Holt edited this page Aug 1, 2023 · 3 revisions

Setting up Bluetooth

A quick how-to on Bluetooth devices. (taken from https://freebsdfoundation.org/freebsd-project/resourcesold/audio-on-freebsd/)

Loading Bluetooth Support

Before attaching a Bluetooth device, determine which Bluetooth driver it uses. A wide variety of Bluetooth USB dongles are supported by ng_ubt(4). Broadcom BCM2033-based Bluetooth devices are supported by the ubtbcmfw(4) and ng_ubt(4) drivers. Serial and UART-based Bluetooth devices are supported by ng_h4(4) and hcseriald(8). For example, if the device uses the ng_ubt(4) driver:

kldload ng_ubt

If the Bluetooth device is attached to the system during system startup, the system can be configured to load the module at boot by adding the driver to /boot/loader.conf:

ng_ubt_load="YES" Once the driver is loaded, connect the Bluetooth device. If the driver load was successful, output similar to the following should appear on the console and in /var/log/messages:

ubt0: vendor 0x0a12 product 0x0001, rev 1.10/5.25, addr 2
ubt0: Interface 0 endpoints: interrupt=0x81, bulk-in=0x82, bulk-out=0x2
ubt0: Interface 1 (alt.config 5) endpoints: isoc-in=0x83, isoc-out=0x3,
      wMaxPacketSize=49, nframes=6, buffer size=294

To start and stop Bluetooth, use the driver’s startup script:

service bluetooth start ubt0

Finding Other Bluetooth Devices

MidnightBSD uses hccontrol(8) to find and identify Bluetooth devices within RF proximity.

One of the most common tasks is the discovery of Bluetooth devices within RF proximity. This operation is called inquiry. Inquiry and other HCI-related operations are made using hccontrol(8). To display a list of devices that are in range use:

hccontrol -n ubt0hci inquiry
Inquiry result, num_responses=1
Inquiry result #0
       BD_ADDR: 00:80:37:29:19:a4
       Page Scan Rep. Mode: 0x1
       Page Scan Period Mode: 00
       Page Scan Mode: 00
       Class: 52:02:04
       Clock offset: 0x78ef
Inquiry complete. Status: No error [00]
Note: only devices that are set to discoverable mode will be listed.

The BD_ADDR is a Bluetooth device's unique address, similar to a network card's MAC address. This address is needed for further communication with a device. To obtain the human-readable name that was assigned to the remote device:

hccontrol -n ubt0hci remote_name_request 00:80:37:29:19:a4
BD_ADDR: 00:80:37:29:19:a4
Name: Example Bluetooth

The Bluetooth system provides a point-to-point connection between two Bluetooth units or a point-to-multipoint connection shared among several Bluetooth devices. The following example shows how to create a connection to a remote device:

hccontrol -n ubt0hci create_connection BT_ADDR

create_connection accepts BT_ADDR and host aliases in /etc/bluetooth/hosts.

The following example shows how to obtain the list of active baseband connections for the local device:

hccontrol -n ubt0hci read_connection_list
Remote BD_ADDR    Handle Type Mode Role Encrypt Pending Queue State
00:80:37:29:19:a4     41  ACL    0 MAST    NONE       0     0 OPEN