More on Android’s Bluetooth

By default, you can use the Bluetooth functionality on the Android to connect a Bluetooth headset and use it for phone calls. See:
device-bt1
Besides this, things like Bluetooth file transfer, HID Bluetooth devices are not supported.

Still, here are a few things you can do with the default software:

1. Connect to your device:
adb shell

2. Use the hcitool android command
# hcitool
hcitool - HCI Tool ver 3.36
Usage:
hcitool [options] [command parameters]
Options:
--help Display help
-i dev HCI device
Commands:
dev Display local devices
inq Inquire remote devices
scan Scan for remote devices
name Get name from remote device
info Get information from remote device
spinq Start periodic inquiry
epinq Exit periodic inquiry
cmd Submit arbitrary HCI commands
con Display active connections
cc Create connection to remote device
dc Disconnect from remote device
sr Switch master/slave role
cpt Change connection packet type
rssi Display connection RSSI
lq Display link quality
tpl Display transmit power level
afh Display AFH channel map
lp Set/display link policy settings
lst Set/display link supervision timeout
auth Request authentication
enc Set connection encryption
key Change connection link key
clkoff Read clock offset
clock Read local or remote clock

For more information on the usage of each command use:
hcitool --help

You can use hcitool to:
List own Bluetooth address (hcitool dev):
# hcitool dev
Devices:
hci0 00:17:E8:B5:20:08

List nearby discoverable bluetooth devices (hcitool scan):
# hcitool scan
Scanning ...
00:09:2D:20:0D:E7 n/a

Get more info on a nearby Bluetooth device (hcitool info):
# hcitool info 00:09:2D:20:0D:E7
Requesting information ...
BD Address: 00:09:2D:20:0D:E7
Device Name: Pocket_PC
LMP Version: 1.1 (0x1) LMP Subversion: 0x990
Manufacturer: Texas Instruments Inc. (13)
Features: 0xff 0xfb 0x75 0x00 0x00 0x00 0x00 0x00
<3-slot packets> <5-slot packets>

Send an arbitrary HCI command to the Bluetooth chip - Powerful feature (hcitool cmd):
First, have a look on the possible HCI commands here.
Now let's try to retrieve the Bluetooth name of our device.
If you look at this picture above, you can see that it is "T-Mobile G1". From the HCI Commands list we will use:
Host Controller and Baseband Commands (OGF=0×03)

12 Read_Local_Name 0×0014 Command to read the user friendly name of the device.

So we need to type:
# hcitool cmd 0x03 0x0014
< HCI Command: ogf 0x03, ocf 0x0014, plen 0 > HCI Event: 0x0e plen 252
01 14 0C 00 54 2D 4D 6F 62 69 6C 65 20 47 31 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 88 1F 97

String 01:14:0C:00:54:2D:4D:6F:62:69:6C:65:20:47:31 at the begining of the command's response is ????T-Mobile G1

As you can see it is quite easy to use these powerful commands to extend the bluetooth functionality on the Android G1. For more info you can type hcitool --help

3. Check/configure Bluetooth parameters
# hciconfig
hci0: Type: UART
BD Address: 00:17:E8:B5:20:08 ACL MTU: 1021:4 SCO MTU: 180:4
UP RUNNING PSCAN
RX bytes:11424 acl:125 sco:0 events:272 errors:16
TX bytes:3379 acl:60 sco:0 commands:107 errors:0

Using native code programming you can go even further. In a future tutorial I will show how to write a simple C program to list the nearby Bluetooth devices programmatically.

Best regards,
Radu Motisan

Related Post

This article has 8 Comments

  1. Hello,

    I am wondering, which version of Android are you running? Currently I am working on getting hcitool to work with the Samsung Spica which runs 1.5.

    Thanks in advance,

    Didier

  2. Hi Didier,

    I’m using several versions. Can’t remember which firmware was when I did this article, but you can get the hcitool native executable and put it on your device.

  3. Hello Radu,

    Ok, I have been able to copy hcitool to /system/bin and gave it the right permissions to execute. That’s working fine, except hcitool dev doesn’t give me any devices. Is this due to the poor Bluez implementation? The bluetooth chipset is one of Ericsson’s, don’t know if I need another firmware.

    I am using hcitool 3.36.

    The only thing I want to be able to do with my Android telephone is to scan with the hcitool. Any suggestions which telephone would fit my needs? Cause the Galaxy Spica is pretty much an dead end for now (until Android 2 comes out for it I guess).

    I guess that I’ll need at least Android 1.6 to fit my needs, which telephone(s) did you use?

    Cheers

  4. Radu,

    Hi Radu!

    Would you be interested in a freelance Android project?

    I saw from your softs & articles that you had bluetooth skills and we are working on something special on the Android platform.

    email me if you are interested to know more,

    Cheers!

    Jérôme

  5. Dear all

    I am working on a local positioning in Bluetooth, for this purpose i need to find out Bluetooth RSSI,

    Please guide me about the plateform where i will implement these commands for getting rssi. i mean the language and commands.

    Thanks

Leave a Reply