Bluetooth

From Tizen Wiki
Jump to: navigation, search

The purpose of this page is to:

  • Introduce the Bluetooth technology.
  • Document the Linux Bluetooth stack BlueZ.
  • Document Bluetooth on Tizen Common.


About Bluetooth

Bluetooth is a wireless technology standard for exchanging data over short distances.

Profiles

The Bluetooth technology works with profiles. Profiles define standards to deliver a large choice of services. Profiles use Bluetooth protocols and some profiles even require other profiles.

BlueZ

BlueZ is the name of the official Bluetooth stack on Linux. It implements the Bluetooth 4.0 Core specification and supports a large choice of profiles (see the Supported profiles section for a complete list) .

BlueZ official website: bluez.org

Bluetooth agent

Bluetooth connections are generally managed through a Bluetooth agent whose role is to automatically configure and chose the right options to manage Bluetooth connections leaving the user the tasks to chose the devices to connect/disconnect to and enter PIN codes.

The CLI client bluetoothctl come with its own agent but can also use a different one. BlueZ also provides an external Bluetooth agent called simple-agent.

Supported profiles and protocols

Here is a list of all existing profiles and protocols with the ones supported in BlueZ. Note that you can find the complete, updated list of supported profiles and their versions in the file doc/supported-features.txt from the bluez package. Also some profiles/roles depend on external components such as oFono or ConnMan.

Profile/Protocol Links Specification versions Version in BlueZ
3DSP 3D Synchronization Profile 1.0 / 1.0.1
A2DP Advanced Audio Distribution Profile 1.0 / 1.2 / 1.3 1.3
AVCTP Audio/Video Control Transport Protocol 1.0 / 1.2 / 1.3 / 1.4 1.3
ANP Alert Notification Profile 1.0
AVDTP Audio/Video Distribution Transport Protocol 1.0 / 1.2 / 1.3 1.3
AVRCP Audio/Video Remote Control Profile 1.0 / 1.3 / 1.4 / 1.5 1.5
BIP Basic Image Profile 1.0 / 1.1 / 1.2
BLP Blood Pressure Profile 1.0
BNEP Bluetooth Network Encapsulation Protocol 1.0 1.0
BPP Basic Printing Profile 1.0 / 1.2
CPP Cycling Power Profile 1.0
CSCP Cycling Speed and Cadence Profile 1.0 1.0
DI (DIP/DID) Device Identification Profile 1.2 / 1.3 1.3
DUN Dial-Up Network Profile 1.1 / 1.2 1.1
FMP Find Me Profile 1.0
FTP File Transfer Profile 1.1/ 1.2 / 1.3 1.2
GAP 2.0 / 2.1 / 3.0 / 4.0 / 4.1 / 4.2 4.2
GATT Generic Attribute Profile 2.0 / 2.1 / 3.0 / 4.0 / 4.1 / 4.2 4.2
GAVDP (GAVDTP) Generic Audio/Video Distribution Profile 1.0 / 1.2 / 1.3 1.2
GLP Glucose Profile 1.0
GNSS Global Navigation Satellite System Profile 1.0
GOEP Generic Object Profile 1.1 / 2.0 / 2.1 2.0
HCRP Hard Copy Cable Replacement 1.0 / 1.2 1.2
HDP Health Device Profile 1.0 / 1.1 1.0
HFP Hands-Free Profile 1.5 / 1.6 1.6
HID Human Interface Device Profile 1.0 / 1.1 1.1
HOGP (HoG/HOG) HID Over GATT Profile 1.0 1.0
HRP Heart Rate profile 1.0
HSP Headset Profile 1.1 / 1.2 1.2
HTP Health Thermometer Profile 1.0 1.0
IrDA IrDA Interoperability 1.1 / 2.0
L2CAP Logical Link Control and Adaptation 2.0 / 2.1 / 3.0 / 4.0 / 4.1 / 4.2 4.2
LNP Location and Navigation Profile 1.0
MAP MAP Message Access Profile 1.0 / 1.1 / 1.2 1.0
MCAP Multi-Channel Adaptation Protocol 1.0 1.0
MPS ​Multi Profile Specification 1.0
OPP Object Push Profile 1.1 / 1.2 1.2
PAN Personal Area Network Profile 1.0 1.0
PASP Phone Alert Status Profile 1.0
PBAP (PBA) Phone Book Access Profile 1.0 / 1.1 / 1.1.1 / 1.2 1.1
PXP Proximity Profile 1.0 1.0
RFCOMM 1.1 / 1.2 1.1
RSCP Running Speed and Cadence Profile 1.0
ScPP Scan Parameters Profile 1.0
SAP SIM Access Profile 1.0 / 1.1 1.1
SDAP ​Service Discovery Application Profile 1.1 1.1
SDP 2.0 / 2.1 / 3.0 / 4.0 / 4.1 / 4.2 4.2
SPP Serial Port Profile 1.1 / 1.2 1.1
SYNC (SYNCH) Synchronization Profile 1.1 / 1.2 1.1
TIP Time Profile 1.0 1.0
VDP Video Distribution Profile 1.0 / 1.1

BlueZ CLI clients

The BlueZ project provides several CLI clients allowing users to use some of the supported profiles.

bluetooth-player

Allow the user to remotely control media players through he AVRCP profile.

Use example

# bluetooth-player
[bluetooth]# list             // List available remote players
[bluetooth]# show [player]    // Display information about <player>
[bluetooth]# select <player>  // Select the player to send commands to (optional if there is only one player available)
[bluetooth]# play             // Send the "play" command to the player
[bluetooth]# pause            // Send the "pause" command to the player
[bluetooth]# ...

bluetoothctl

CLI client to manage connections between devices. It includes a default bluetooth-agent.

Use example:

# bluetoothctl
[bluetooth]# power on                          // Power on the Bluetooth device
[bluetooth]# agent on                          // Start the agent
[bluetooth]# default-agent                     // Set agent as the default one
[bluetooth]# pairable on                       // Allow pairing
[bluetooth]# scan on                           // Enable scan so discoverable devices will be displayed
[bluetooth]# pair <remote_device_MAC@>         // Pair with a discovered device
[bluetooth]# connect <remote_device_MAC@>      // Connect to a device

Due to https://bugs.tizen.org/jira/browse/TC-1511, "power on" fails with "org.bluez.Error.Blocked" and journalctl reports "Operation not possible due to RF-kill". As a workaround, install connman-test, run "connmanctl" as root, and enter "enable bluetooth".

obexctl

CLI client for the FTP profile that manages file transfer and browsing over Bluetooth.

Usage :


app@lenovo11:~$ obexctl 
[NEW] Client /org/bluez/obex 
[obex]# connect ${address}
Attempting to connect to ${address}
[NEW] Session /org/bluez/obex/client/session0 [default]
[NEW] ObjectPush /org/bluez/obex/client/session0 
Connection successful
[${address}]# help
Available commands:
  connect <dev> [uuid]       Connect session
  disconnect [session]       Disconnect session
  list                       List available sessions
  show [session]             Session information
  select <session>           Select default session
  info <object>              Object information
  cancel <transfer>          Cancel transfer
  send <file>                Send file
  cd <path>                  Change current folder
  ls                         List current folder
  cp <source file> <destination file> Copy source file to destination file
  mv <source file> <destination file> Move source file to destination file
  rm <file>                  Delete file
  mkdir <folder>             Create folder
  quit                       Quit program
[${address}]# send /etc/passwd
Attempting to send /etc/passwd to /org/bluez/obex/client/session0
[NEW] Transfer /org/bluez/obex/client/session0/transfer0 
Transfer /org/bluez/obex/client/session0/transfer0
        Status: queued
        Name: passwd
        Size: 2228
        Filename: /etc/passwd
        Session: /org/bluez/obex/client/session0
[CHG] Transfer /org/bluez/obex/client/session0/transfer0 Status: complete
[DEL] Transfer /org/bluez/obex/client/session0/transfer0 

BlueZ test tools

This section introduces some of the Bluetooth test tools from the BlueZ project. Those tools are mostly made for development and debugging purposes.

btmon

Bluetooth monitor - Display all HCI commands and events in a human readable format (and with color !). Can dump data in with the btsnoop format.

Note that this format is now supported by Wireshark (1.11.x). Also supported by development libpcap for realtime capturing.

hciconfig

hciconfig is used to configure Bluetooth devices. hciX is the name of a Bluetooth device installed in the system (ie., hci0).

Display Basic Info About Available Bluetooth Devices:

target# hciconfig
hci0:	Type: BR/EDR  Bus: USB
	BD Address: xx:xx:xx:xx:xx:xx  ACL MTU: 310:10  SCO MTU: 64:8
	UP RUNNING PSCAN ISCAN 
	RX bytes:4234 acl:19 sco:0 events:176 errors:0
	TX bytes:6354 acl:18 sco:0 commands:140 errors:0

Display Info About A Specific Bluetooth Device:

target# hciconfig hci0 -a
hci0:	Type: BR/EDR  Bus: USB
	BD Address: xx:xx:xx:xx:xx:xx  ACL MTU: 310:10  SCO MTU: 64:8
	UP RUNNING PSCAN ISCAN 
	RX bytes:4234 acl:19 sco:0 events:176 errors:0
	TX bytes:6354 acl:18 sco:0 commands:140 errors:0
	Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH HOLD SNIFF PARK 
	Link mode: SLAVE ACCEPT 
	Name: 'xyz'
	Class: 0x400104
	Service Classes: Telephony
	Device Class: Computer, Desktop workstation
	HCI Version: 4.0 (0x6)  Revision: 0x22bb
	LMP Version: 4.0 (0x6)  Subversion: 0x22bb
	Manufacturer: Cambridge Silicon Radio (10)

UP or DOWN A Bluetooth Device Manually:

target# sudo hciconfig hci0 up
target# sudo hciconfig hci0 down

hcidump

Dump all HCI events and commands

Realize a dump file readable with Wireshark

hcidump -R -w <dest_file>

hcitool

hcitool provides a simplified way of sending commands to the HCI device.

To launch an arbitrary command not present in the command list the command "cmd" can be used.

For example:

hcitool cmd 0x03 0x000A 0x01

sets the PIN type as fixed. For more details about the commands values, please refer to the Bluetooth Core Specification V.4.1 (https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=282159).

list-devices

List paired devices and information about them for all available Bluetooth controllers.

l2ping

Bluetooth layer 2 ping.

mpris-player

Tool to test AVRCP on the player/receiver side.

This tool uses the MPRIS specification which defines a standard way to control media players.

MPRIS specification: http://specifications.freedesktop.org/mpris-spec/latest/

sdptool

sdptool provides the interface for performing SDP queries on Bluetooth devices, and administering a local SDP database called sdpd.

Usage:

target# sdptool browse xx:xx:xx:xx:xx:xx

Browsing xx:xx:xx:xx:xx:xx ...
Service RecHandle: 0x10000
Service Class ID List:
  "Generic Attribute" (0x1801)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 31
  "ATT" (0x0007)
    uint16: 0x0001
    uint16: 0x0005

Service RecHandle: 0x10001
Service Class ID List:
  "Generic Access" (0x1800)
Protocol Descriptor List:
  "L2CAP" (0x0100)
    PSM: 31
  "ATT" (0x0007)
    uint16: 0x0014
    uint16: 0x001e

...

The search results can be viewed in three formats XML, RAW and TREE. It also provides option to add/del/get local service.

test-manager

Simple tool that displays available Bluetooth adapters.

External test tools

Wireshark
Network analyser with a GUI. Can analyze Bluetooth frames.
You can open a capture file made with the command "hcidump -R -w <dest_file>" or "btmon" with Wireshark.
Wireshark wiki page on Bluetooth: http://wiki.wireshark.org/Bluetooth
Tshark
CLI network analyser. Has the same features as Wireshark.

Using Bluetooth

Connecting devices

The simplest ans easiest way to connect to a device on Tizen is to use the bluetoothctl tool.

A2DP

To connect to and use an A2DP device an A2DP sink or source is required. PulseAudio provides such features. Make sure that PulseAudio is running before attempting a Bluetooth connection otherwise you won't be advertising for A2DP support which will lead in a connection failure with some devices like Bluetooth headsets.

Note that PulseAudio requires the module "module-bluetooth-discover" to be loaded in order to get A2DP working. You can either:

  • Launch it at the same time as PulseAudio
# pulseaudio -L module-bluetooth-discover
  • Load it while PulseAudio is working (not tested)
# pactl load-module module-bluetooth-discover source=bluez_source.XX_XX_XX_XX_XX_XX sink=alsa_output.pci-0000_00_1b.0.analog-stereo
  • Get it automatically loaded at PulseAudio launch by adding a few lines in its configuration file (called default.pa by default and generally located in /etc/pulse/). Note that those lines are already present in the default configuration file.
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

Tizen / Links

Reference / Links

HFP

Please refer the to the article about Connecting to a Smartphone with Bluetooth and Making Phone Calls for step by step instructions and example usage on Bluetooth on devices with Tizen:Common.

On TIVI :

As App :

 sudo zypper install bluez-test
 bluetoothctl
 power on
 scan on
 list
 pair $address
 connect $address

As Root :

 zypper in ofono-test
 sudo /usr/lib/ofono/test/dial-number $number
 #| Using modem /hfp/org/bluez/hci0/dev_$address
 #| /hfp/org/bluez/hci0/dev_$address/voicecall01

Tizen / Links

Reference / Links

AVRCP

If the AVRCP profile is supported by the remote device, the remote control feature should automatically work once the two devices are connected. Note that AVRCP requires the A2DP profile.

To test the AVRCP profile on the receiver side use the mpris-player test-tool.

To test the AVRCP profile on the controller side use the bluetooth-player CLI client.

Reference / Links

HID

Connecting a mouse or a keyboard

Getting a wireless mouse or keyboard to work on Tizen should be pretty straightforward since the only thing to do is to establish the Bluetooth connection.

Using Bluetoothctl
# bluetoothctl
[bluetooth]# power on                 // Power on the Bluetooth device
[bluetooth]# agent on                 // Start the agent
[bluetooth]# default-agent            // Set agent as the default one
[bluetooth]# pairable on              // Allow pairing
[bluetooth]# scan on                  // Enable scan so discoverable the remote Bluetooth mouse or keyboard
[bluetooth]# pair <remote_device>     // Pair with the mouse or keyboard
[bluetooth]# connect <remote_device>  // Connect to the mouse or keyboard (might not be necessary since the pairing process or the remote device may automatically trigger the connection)

bluetoothctl might ask you to enter a PIN code; if so, just enter "0000" which is the default PIN code generally used by devices without display and keyboard.

Bluetooth on Tizen

Note that Bluetooth features are only supported on reference target devices, not on the SDK Emulator.
Specification for Tizen mobile :

https://source.tizen.org/sites/default/files/page/tizen-2.2.1-compliance-specification-for-mobile-profile-v1.0.pdf

{ Mobile device implementations SHOULD implement the Audio/Video Remote Control Profile (AVRCP) and the Object Exchange (OBEX) protocol. }

see also:


Software versions

Software Version
BlueZ 5.10
PulseAudio 4.0


Tested profiles and devices

(TO UPDATE with more recent tests.)

Type Device Bluetooth Version Profiles Notes Tizen image date creation
Mouse Microsoft Bluetooth Notebook Mouse 500  ? HID OK 2013-11-28
Keyboard Microsoft Wedge Mobile Keyboard  ? HID OK 2013-11-28
Headset Motorola Motorokr S305 2.0 A2DP sink
AVRCP controller
Pairing/connection OK; A2DP profile looked fine but the lack of a proper media player prevents further tests
AVRCP not tested
2013-11-28
Jabra Easygo 3.0 HSP 1.1 (headset)
HFP 1.5
Not tested yet
Not tested yet
2013-11-28
Phone Motorola EX130 2.1 A2DP source
AVRCP receiver
HFP
HSP (Audio Gateway)
OPP source
OPP destination
OK
OK
Not tested yet
Not tested yet
Fails
Not tested yet
2013-11-28

BLE


GATT


Resources