IMX Bluetooth Krogoth

From Variscite Wiki
Bluetooth

Bluetooth boot messages

During boot the following Bluetooth kernel messages are received:

$ dmesg | grep -i Bluetooth
Bluetooth: Core ver 2.18
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: L2CAP socket layer initialized
Bluetooth: SCO socket layer initialized
Bluetooth: HCI UART driver ver 2.2
Bluetooth: HCI H4 protocol initialized
Bluetooth: HCI BCSP protocol initialized
Bluetooth: HCIATH3K protocol initialized
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM ver 1.11
Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Bluetooth: BNEP filters: protocol multicast
Bluetooth: BNEP socket layer initialized
Bluetooth: HIDP (Human Interface Emulation) ver 1.2
Bluetooth: HIDP socket layer initialized

Device identification

After the File system is up 'hciconfig' should show the connected bluetooth module.

hciconfig
hci0:   Type: BR/EDR  Bus: UART
        BD Address: 64:A3:CB:5B:69:F0  ACL MTU: 1021:8  SCO MTU: 64:1
        UP RUNNING PSCAN 
        RX bytes:1772 acl:0 sco:0 events:69 errors:0
        TX bytes:1152 acl:0 sco:0 commands:65 errors:0

The hcitool can be used to show the Bluetooth MAC address of the Bluetooth module with the respective hci connection. Type help to show commands.

root@var-som-mx6:~# hcitool dev
Devices:
        hci0    64:A3:CB:5B:69:F0

Connecting to classic Bluetooth devices

You can manage bluetooth with bluetoothctl, type 'bluetoothctl' and enter the interface. Type help to show commands.
For connecting a device do the following:

$ bluetoothctl
[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# default-agent
[bluetooth]# pairable on

Push the connect button in the device (if exists)

[bluetooth]# scan on

Copy mac address

[bluetooth]# scan off
[bluetooth]# pair <mac address>

Approve pairing on Device if required

[bluetooth]# trust <mac address>
[bluetooth]# connect <mac address>
[bluetooth]# quit

For example when connecting a microsoft bluetooth mouse the following is done:

root@var-som-mx6:~# bluetoothctl
[NEW] Controller 50:72:24:11:EF:B0 BlueZ 5.37 [default]
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller 50:72:24:11:EF:B0 Discovering: yes
[NEW] Device 00:1D:D8:39:93:46 Microsoft Bluetooth Notebook Mouse 5000
[bluetooth]# scan off
[CHG] Device 00:1D:D8:39:93:46 RSSI is nil
Discovery stopped
[CHG] Controller 50:72:24:11:EF:B0 Discovering: no
[bluetooth]# pair 00:1D:D8:39:93:46
Attempting to pair with 00:1D:D8:39:93:46
[CHG] Device 00:1D:D8:39:93:46 Connected: yes
[CHG] Device 00:1D:D8:39:93:46 Modalias: usb:v045Ep0700d0100
[CHG] Device 00:1D:D8:39:93:46 UUIDs:
        00001000-0000-1000-8000-00805f9b34fb
        00001124-0000-1000-8000-00805f9b34fb
        00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 00:1D:D8:39:93:46 Paired: yes
Pairing successful
[CHG] Device 00:1D:D8:39:93:46 Connected: no
[bluetooth]# trust 00:1D:D8:39:93:46
[CHG] Device 00:1D:D8:39:93:46 Trusted: yes
Changing 00:1D:D8:39:93:46 trust succeeded
[bluetooth]# connect 00:1D:D8:39:93:46
Attempting to connect to 00:1D:D8:39:93:46
[CHG] Device 00:1D:D8:39:93:46 Connected: yes
[bluetooth]# hid-generic 0005:045E:0700.0001: unknown main item tag 0x0
input: Microsoft Bluetooth Notebook Mouse 5000 as /devices/soc0/soc.0/2100000.aips-bus/21e8000.serial/tty/ttymxc1/hci0/hci0:1/0005:045E:0700.0001/input/input1
Connection successful
[bhid-generic 0005:045E:0700.0001: input: BLUETOOTH HID v1.00 Mouse [Microsoft Bluetooth Notebook Mouse 5000] on 50:72:24:11:ef:b0
[bluetooth]# quit
[DEL] Controller 50:72:24:11:EF:B0 BlueZ 5.37 [default]
root@var-som-mx6:~#

Connecting to BLE devices

Connecting to BLE devices requires different command sequence. The btmgmt tool is used to scan for LE devices and report MAC address type (random vs public).

$ btmgmt find

Copy MAC address of LE device, use "-t random" gatttool parameter if scan reports random MAC address. 

$ gatttool -b <MAC> [-t random] -I

For example when connecting to "BLE Peripheral Simulator" on Android phone the following is done:

 
root@var-som-mx6:~# btmgmt find
Discovery started
hci0 type 7 discovering on
hci0 dev_found: 74:B9:AB:CF:13:A9 type LE Random rssi -90 flags 0x0000 
AD flags 0x1a 
name Galaxy S5
hci0 dev_found: 00:1A:7D:DA:71:0B type BR/EDR rssi -79 flags 0x0000 
name SMTBT
hci0 dev_found: 00:1A:7D:DA:71:11 type BR/EDR rssi -96 flags 0x0001 
eir_len 5
confirm_name succeeded for 00:1A:7D:DA:71:11
hci0 type 7 discovering off

root@var-som-mx6:~# gatttool -t random -b 74:B9:AB:CF:13:A9 -I
[74:B9:AB:CF:13:A9][LE]> connect
Attempting to connect to 74:B9:AB:CF:13:A9
[74:B9:AB:CF:13:A9][LE]>
Connection successful
Indication   handle = 0x0003 value: 01 00 ff ff 
[74:B9:AB:CF:13:A9][LE]>

Sending Files

Sending a file from the board to the bluetooth device using the obex transfer.

1) First, perform pairing with the device as described above. No need to establish connection

2) Start obexctl. Type help to show commands.


$ obexctl

3) connect to Device

[obex]# connect <mac addr>

4) Send a file from obexctl to the device

[<mac addr>]# send <file>

5) Once it's done, close the session

[<mac addr>]# disconnect
[<mac addr>]# quit

For example, sending file to Ubuntu PC:

root@imx6ul-var-dart:~# obexctl 
[NEW] Client /org/bluez/obex 
[obex]# connect 00:1A:7D:DA:71:0B
Attempting to connect to 00:1A:7D:DA:71:0B
[NEW] Session /org/bluez/obex/client/session0 [default]
[NEW] ObjectPush /org/bluez/obex/client/session0 
Connection successful
[00:1A:7D:DA:71:0B]# send /etc/fstab
Attempting to send /etc/fstab to /org/bluez/obex/client/session0
[NEW] Transfer /org/bluez/obex/client/session0/transfer0 
Transfer /org/bluez/obex/client/session0/transfer0
        Status: queued
        Name: fstab
        Size: 637
        Filename: /etc/fstab
        Session: /org/bluez/obex/client/session0
[CHG] Transfer /org/bluez/obex/client/session0/transfer0 Status: complete
[DEL] Transfer /org/bluez/obex/client/session0/transfer0 

Receiving Files

Receiving files from paired devices is also supported. The files are stored under /tmp/bluetooth-inbox.