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 Atheros AR6233 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 Atheros AR6233 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
Bluetooth classic profiles are implemented over the protocols listed above.
User space usage
In user space, Digi Embedded Yocto includes the
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
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 the
bluetoothctl command line utility
Digi Embedded Yocto includes the
bluetoothctl command line application that you can use to test the Bluetooth functionality.
Run the application to enter its command line:
# bluetoothctl [bluetooth]#
Identify your device
List your Bluetooth devices with:
[bluetooth]# list Controller 00:04:F3:15:34:DA platform_82928 [default]
Make your device discoverable and pairable
Make your device discoverable with:
[bluetooth]# discoverable on Changing discoverable on succeeded [CHG] Controller 00:04:F3:15:34:DA Discoverable: yes
Allow other devices to pair with your device with:
[bluetooth]# pairable on Changing pairable on succeeded
Scan and detect devices
Instruct the Bluetooth device to scan for other Bluetooth devices in the neighborhood with:
[bluetooth]# scan on Discovery started [CHG] Controller 00:04:F3:15:34:DA Discovering: yes
List the detected devices with:
[bluetooth]# devices [NEW] Device 00:16:A4:06:B2:A0 log-linux-hp-agonzal
Get device information
Query a specific device for information with the
info command, followed by its MAC address:
[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: no 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
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. After confirmation on both ends, the agent reports:
[CHG] Device 00:16:A4:06:B2:A0 Paired: yes Pairing successful
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 [CHG] Device 00:16:A4:06:B2:A0 Trusted: yes Changing 00:16:A4:06:B2:A0 trust succeeded
Quit the command line
To quit the
bluetoothctl command line:
Ping the remote device
Digi Embedded Yocto includes the
l2ping command line application to send L2CAP echo requests.
Test that the L2CAP layer is functional by pinging a remote Bluetooth MAC address:
# 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 you can use to test the RFCOMM layer.
Before running this test you need to pair the devices.
On the receiving target, issue:
# rctest rctest: Waiting for connection on channel 10 ...
Then, on the transmitter, type:
# rctest -s <Remote MAC>
The receiver starts receiving packets.
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-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:
# obex-server-tool -b -c 13 -r /home/root/
-bis the Bluetooth transport,
-cis the channel number and
-rthe FTP root directory.
# 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>