Bluez tools and programming – Part II

In this post I will continue exploration of bluez tools and programming. Please check back my last post for part I.

hcitool

Let us explore the information extracted by hcitool. The format of the command is

$ hcitool [options] [command]

$hcitool dev

This will output the local devices in the format [hciX] [BD Address]

hcitool inq

This will inquire remote bluetooth devices and output information of the device. On my machine the output was

[BD Address] [Clock offset] [class]

This will scan the remote device. As opposed to inquiry, this will just output the bluetooth address and the user friendly name of the remote device.

hcitool name [BD address]

Given the address of the remote device, this command outputs the user friendly name.

$ hcitool info [BD address]

This will output the information of the remote device given its address. On my machine, it gave me this:

Requesting information …
BD Address: 00:20:E0:CC:29:7B
OUI Company: Actiontec Electronics, Inc. (00-20-E0)
Device Name: Blue1-0
LMP Version: 1.1 (0x1) LMP Subversion: 0x322
Manufacturer: Cambridge Silicon Radio (10)
Features: 0xff 0xff 0x0f 0x00 0x00 0x00 0x00 0x00

As you can see, it outputs information needed for making a connection.

hcitool cc [BD address]

This creates a ACL connection to the bluetooth device whose address is given. You can specify the role of the local device as master or slave using -m option. Please note that this connection is not meant to stay endless. They will be disconnected. You should use other methods for persistent connections (I will talk about them later).

hcitool dc [BD address]

This will disconnect from the connected bluetooth device.

hcitool con

This displays the list of connections. The output might look like this:

Connections:
< ACL 00:20:E0:CC:29:7B handle 0 state 2 lm MASTER

This tells us that the host is connected to a device with address 00:20:E0:CC:29:7B. It is a ACL link and it is the master in the connection.

hcitool sr

This enables switching of roles of the host device. If it is master, you can switch it to slave.

hcitool rssi [BD address]

This displays the connection signal strength. The output might look like this (it says 1 for my connection).

RSSI return value: 1

hcitool lq [BD address]

This displays the link quality of the current connection. The output might look like this.

Link quality: 255

hcitool tpl [BD address]

This displays the transmit power level of the current connection. The output might look like this (it shows 0 for my connection).

Current transmit power level: 0

hcitool afh [BD address]

This displays the AFH map in hexadecimal. The output might look like this.

AFH map: 0xffffffffffffffffff7f

hcitool lp [BD address]

This displays the link policies of the current connection.

hcitool lst [BD address]

This displays the link supervision timeout settings. The output might look like this.

Link supervision timeout: 32000 slots (20000.00 msec)

hcitool clkoff [BD address]

This displays the clock offset setting of the remote device. The output might look like this.

Clock offset: 0x5206

hcitool clock [BD address]

This displays the clock of the remote device.

hcitool key [BD address]

This changes the link key (the pin) between the two devices.

This completes the most useful options for the command. There might be others that you might want to see. But the most important thing about hcitool is to know the various connection parameters.

In the next post, I will look into the BlueZ API. This will give us the capability to program these devices.

Leave a comment