Bluetooth is a short range (typically between 10m and 100m) wireless standard that uses UHF radio waves on the ISM band (2.4 to 2.485 GHz).

The Bluetooth interface is made out of two different stacks, the controller and the host. 

The controller stack is implemented in the QCA6574 wireless chip. The controller implements the link layer protocols and is responsible for transporting Bluetooth packets between devices using logical transports. The controller communicates with the host using the Host controller interface (HCI) protocol, and on the QCA6574 this is conveyed through the UART interface.

The host stack is the Linux Bluez stack which is in turn split between the Linux kernel and user space.

The Linux kernel implements the hardware driver and the low level control, data and security protocols, including:

  • Logical link control and adaptation protocol (L2CAP): It passes packets to the Host Controller Interface (HCI), performing segmentation and reassembly if needed, multicast and QoS management.

  • Radio frequency communication (RFCOMM): Over L2CAP, it’s a simple set of transport protocols providing emulated RS-232 serial ports and a simple reliable data stream similar to TCP, based on the ETSI standard TS 07.10. 

  • Service discovery protocol (SDP): Working over L2CAP, it is used to allow devices to discover what services are supported by each other, and what parameters to use to connect to them. Each service is identified by a 128 bits Universally Unique Identifier (UUID), with official services (Bluetooth profiles) assigned a short form UUID of 16 bits.

The Linux kernel exposes configuration options in /sys/class/bluetooth.

Bluetooth classic profiles are implemented over the protocols listed above.

User space usage

In user space, Digi Embedded Yocto includes the bluetoothd and obexd (for OBEX profiles) daemons which expose a D-Bus interface for configuration and management that applications can use to integrate Bluetooth functionality, as well as some other tools used for testing, development and tracing which includes the bluetoothctl and obexctl command line agents.

Digi Embedded Yocto includes a Bluetooth initialization script that makes use of the hciattach tool to bring up the Bluetooth interface.

The user space components provide all configuration files under /etc/bluetooth (main.conf, input.conf, network.conf).

Digi Embedded Yocto includes the bluetoothctl command line application that can be used to test the Bluetooth functionality as follows:

~# bluetoothctl
[NEW] Controller 00:00:00:00:5A:AD BlueZ 5.41 [default]

Scan and detect devices

Instruct the bluetooth device to scan for bluetooth devices in the neighborhood with:

[bluetooth]# scan on
[NEW] Device 00:16:A4:06:B2:A0 log-linux-hp-agonzal

Get device information

Query a specific device for information as follows:

[bluetooth]# info 00:16:A4:06:B2:A0
Device 00:16:A4:06:B2:A0
Name: log-linux-hp-agonzal
Alias: log-linux-hp-agonzal
Class: 0x1c0104
Icon: computer
Paired: yes
Trusted: no
Blocked: no
Connected: no
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Message Notification Se.. (00001133-0000-1000-8000-00805f9b34fb)
UUID: Message Access Server (00001132-0000-1000-8000-00805f9b34fb)
UUID: Phonebook Access Server (0000112f-0000-1000-8000-00805f9b34fb)
UUID: IrMC Sync (00001104-0000-1000-8000-00805f9b34fb)
UUID: OBEX File Transfer (00001106-0000-1000-8000-00805f9b34fb)
UUID: OBEX Object Push (00001105-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (00005005-0000-1000-8000-0002ee000001)
Modalias: usb:v1D6Bp0246d0525

Pair

Once the remote device is identified, you can request to pair with it:

[bluetooth]# agent on
Agent registered
 
[bluetooth]# default-agent
Default agent request successful
 
[bluetooth]# pair 00:16:A4:06:B2:A0
[CHG] Device 00:16:A4:06:B2:A0 Connected: yes
Request confirmation
[agent] Confirm passkey 284380 (yes/no): yes

A confirmation will be required at both ends.

Trust a device

You can also add the device to the trusted list so that pairing will happen automatically.

[bluetooth]# trust 00:16:A4:06:B2:A0

Ping the remote device

Digi Embedded Yocto includes the l2ping command line application to send L2CAP echo requests.

To test that the L2CAP layer is functional:

~# l2ping 00:16:A4:06:B2:A0
Ping: 00:16:A4:06:B2:A0 from 00:04:5C:02:49:03 (data size 44) ...
44 bytes from 00:16:A4:06:B2:A0 id 0 time 69.91ms
44 bytes from 00:16:A4:06:B2:A0 id 1 time 96.75ms

RFCOMM file transfer

Digi Embedded Yocto also includes the rctest application, which can be used to test the RFCOMM layer.

On the host target, issue:

~# rctest

A message similar to the following displays:

rctest[1332]: Waiting for connection on channel 10 ...

Then, on the transmitter, type:

~# rctest -s <Remote MAC>

Monitoring and debugging tools

Digi Embedded Yocto includes the following command line applications that can be used to monitor and debug Bluetooth connections:

  • btmon: Provides access to the Bluetooth subsystem monitor infrastructure for reading HCI traces

  • hcidump: Reads raw HCI data coming from and going to a Bluetooth device and prints to screen commands, events and data in a human-readable form

  • sdptool: Used to perform SDP queries on Bluetooth devices 

OBEX file transfers

Digi Embedded Yocto includes the obex-client-tool and obex-server-tool command line application within Bluez5 to test an OBEX FTP transfer. You can use the following instructions to send a file via OBEX FTP from a client to a host:

  • Host (obex-server-tool):

    ~# obex-server-tool -b -c 13 -r /home/root/

    "-b" is the Bluetooth transport, "-c" is the channel number and "-r" the FTP root directory.

  • Client (client-server-tool):

    ~# obex-client-tool -b -s <LOCAL_BT_MAC> -c 13 -d <SERVER_BT_MAC>

After issuing these instructions, a new prompt is launched where you can perform FTP operations. For example:

~# put <FILE_PATH>