Bluetooth
The wireless variant of the ConnectCore 6UL SOM integrates a Qualcomm QCA6564A wireless chipset with the following features:
- Bluetooth (BT) 4.2, AND+, backwards compatible with BT 4.1, 4.0 3.x 2.x and 1.0
- BT and WLAN coexistence
Digi Embedded Yocto defines the dey-bluetooth feature that builds the bluez5 package for working with the bluetooth interface. This package installs all the required libraries and tools to use Bluetooth.
Digi Embedded Yocto supports the core specification 4.2 (GAP, L2CAP, RFCOMM, SDP, GATT), including Classic Bluetooth and Bluetooth Smart (Low Energy). The Linux Bluez stack supports additional Bluetooth Classic and Low Energy profiles that are not specifically validated. See the Bluez documentation for details.
Kernel configuration
The Bluetooth interface is managed by the following kernel configuration options:
- HCI UART driver (CONFIG_BT_HCIUART)
- Atheros AR300x serial support (CONFIG_BT_HCIUART_ATH3K)
- HCI_IBS protocol support (CONFIG_BT_HCIUART_IBS)
These options are enabled as built-in on the default ConnectCore 6UL kernel configuration file.
Platform driver mapping
The Bluetooth drivers are located at:
File |
Description |
---|---|
Atheros AR300x serial support |
|
HCI_IBS protocol support |
Device tree bindings
U-boot fills in the Bluetooth interface MAC address on the "bluetooth" node of the device tree. This address is then programmed into the device by Digi Embedded Yocto bluez init script.
Bluetooth classic
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 HGz).
The bluetooth interface is made out of two different stacks, the controller and the host.
The controller stack is implemented in the QCA6564 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 QCA6564 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]
Scanning and device detection
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
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
Pairing
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.
Trusting 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 within Bluez5 the obex-client-tool and obex-server-tool command line application 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.
# obex-client-tool -b -s <LOCAL_BT_MAC> -c 13 -d <SERVER_BT_MAC>
After issuing this, a new prompt is launched where you can perform FTP operations. For example:
# put <FILE_PATH>
Bluetooth Low Energy
Bluetooth Low Energy (BLE) or Bluetooth Smart is a wireless personal area network technology that is not backwards compatible with Bluetooth Classic while using the same radio frequencies. Compared to Bluetooth Classic, it provides reduced power consumption while maintaining a similar communication range (typically between 10m and 100m). It was incorporated in the Bluetooth Core Specification Version 4.0.
Bluetooth Low Energy has two core protocols:
- Generic Access Profile (GAP): Controls connections and advertisements between devices. GAP defines two core device roles:
- Peripheral: Small, low-power, and resource-constrained devices that connect to a central device. They are usually sensors. A peripheral can only connect to one central device.
- Central: This is the usual role for the ConnectCore 6UL device, processing the connection from peripheral devices.
- Generic Attribute Profile (GATT): Used to transfer data between BLE devices. GATT defines services and characteristics, and defines two roles:
- Server or slave, which holds the service and characteristic definitions and is typically the peripherals above.
- Client or master, typically the central device above which sends request to the server.
GATT transactions are started by the master device by establishing a connection and suggesting a connection interval to the slave. The slave will then attempt to reconnect at the connection interval to recover data.
BLE defines a set of profiles for low energy devices that are based over the services and characteristics of the Generic Attribute Profile (GATT) protocol. A profile is a pre-defined collection of services, which in turn contain a set of characteristics. Each service identifies itself with a UUID, 16 bits for official BLE services or 128 bits for custom services, and each characteristic is identified by a pre-defined 16 bits or 128 bits UUID.
User space usage
Digi Embedded Yocto includes the bluetoothctl and the gattool command line applications that can be used to test the Bluetooth functionality as follows:
Scanning and discovering devices
You can use the bluetoothctl tool to scan for devices as above. You can also scan only for BLE devices using hcitool as follows:
$ hcitool -i hci0 lescan --duplicates LE Scan ... 00:18:31:85:28:3E (unknown) 00:18:31:85:28:3E Keyfobdemo
Connection
Once the remote device is identified, you can connect to it with the gatttool command line application. You will see the prompt change to the MAC of the remote device.
$ gatttool -i hci0 -b <Remote MAC> -I [00:18:31:85:28:3E][LE]> connect
Service discovery
You can request to discover the services offered by the remote device.
[CON][00:18:31:85:28:3E][LE]> primary attr handle: 0x0001, end grp handle: 0x000b uuid: 00001800-0000-1000-8000-00805f9b34fb attr handle: 0x000c, end grp handle: 0x000f uuid: 00001801-0000-1000-8000-00805f9b34fb attr handle: 0x0010, end grp handle: 0x0022 uuid: 0000180a-0000-1000-8000-00805f9b34fb attr handle: 0x0023, end grp handle: 0x0025 uuid: 00001803-0000-1000-8000-00805f9b34fb attr handle: 0x0026, end grp handle: 0x0028 uuid: 00001802-0000-1000-8000-00805f9b34fb attr handle: 0x0029, end grp handle: 0x002c uuid: 00001804-0000-1000-8000-00805f9b34fb attr handle: 0x002d, end grp handle: 0x0031 uuid: 0000180f-0000-1000-8000-00805f9b34fb attr handle: 0x0032, end grp handle: 0x0044 uuid: 0000ffa0-0000-1000-8000-00805f9b34fb attr handle: 0x0045, end grp handle: 0xffff uuid: 0000ffe0-0000-1000-8000-00805f9b34fb
Accessing characteristics
You can then read/write the characteristics. In the current example we are using an accelerometer device which can be enabled as follows:
[CON][00:18:31:85:28:3E][LE]> char-read-hnd 34 Characteristic value/descriptor: 00 [CON][00:18:31:85:28:3E][LE]> char-write-req 34 01 [CON][00:18:31:85:28:3E][LE]> Characteristic value was written successfully
Known issues and Limitations
- The maximum number of supported simultaneous Bluetooth Low Energy connections is 15.