thalib Engineer/Designer

Working with Bluetooth in Linux (Part 2)

2016-11-24

hcitool

hcitool has 3 commands scan, dev and inq for querying deivce information

hcitool scan scans for any device and returns the name and the MAC address.

$ hcitool scan --refresh
Scanning ...
	00:25:56:D3:DF:78	Dell Wireless 365 Bluetooth Module
	00:1E:DE:21:D0:85	Nokia BH-505
	30:F7:72:67:FF:28	ubuntu-0
	44:1C:A8:25:9B:30	ubuntu-0

hcitool dev gets the self bt address, that is your bt dongle/adapter

$ hcitool dev
Devices:
	hci0	5C:F3:70:66:9D:06

hcitool scan inquires about the device, and receives the MAC address, clock offset and class. The class tells you what type of device you are talking too, whether it be a bluetooth headset, phone or speakers etc. more info on class can be found on bluetooth.com

$ hcitool inq
Inquiring ...
	00:1E:DE:21:D0:85	clock offset: 0x67b8	class: 0x240404

Note: You can decode class using a tool named btclassify.

python btclassify.py 0x240404
0x240404: Audio/Video (Wearable Headset Device): Audio, Rendering

hcitool name You can get the name of the bt device with name command

$ hcitool name 00:1E:DE:21:D0:85
Nokia BH-505

sdptool

sdptool commands provides the interface for performing SDP queries on Bluetooth devices.

sdptool
sdptool - SDP tool v4.101
Usage:
	sdptool [options] <command> [command parameters]
Options:
	-h		Display help
	-i		Specify source interface
Commands:
	search		Search for a service
	browse		Browse all available services
	records		Request all records
	add 		Add local service
	del 		Delete local service
	get 		Get local service
	setattr		Set/Add attribute to a SDP record
	setseq		Set/Add attribute sequence to a SDP record

Services:
	DID SP DUN LAN FAX OPUSH FTP PRINT HS HSAG HF HFAG SAP PBAP NAP
	GN PANU HCRP HID KEYB WIIMOTE CIP CTP A2SRC A2SNK AVRCT AVRTG
	UDIUE UDITE SEMCHLA SR1 SYNCML SYNCMLSERV ACTIVESYNC HOTSYNC
	PALMOS NOKID PCSUITE NFTP NSYNCML NGAGE APPLE ISYNC GATT

Get the local bluetooth adpater information

sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service Name: SIM Access Server
Service RecHandle: 0x10000
Service Class ID List:
  "SIM Access" (0x112d)
  "Generic Telephony" (0x1204)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 8
Profile Descriptor List:
  "SIM Access" (0x112d)
    Version: 0x0101

Service Name: Headset Audio Gateway
Service RecHandle: 0x10001
Service Class ID List:
  "Headset Audio Gateway" (0x1112)
  "Generic Audio" (0x1203)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 12
Profile Descriptor List:
  "Headset" (0x1108)
    Version: 0x0102

...
...
...

Here is a simpler way to list services supported by any device

$ sdptool browse 44:1C:A8:25:9A:2C | grep 'Service Name:'
Service Name: SIM Access Server
Service Name: Headset Audio Gateway
Service Name: Hands-Free Audio Gateway
Service Name: Hands-Free
Service Name: AVRCP TG
Service Name: AVRCP CT
Service Name: Audio Source
Service Name: Audio Sink
Service Name: OBEX Object Push
Service Name: OBEX File Transfer

Like wise to find services supported by other devices can be listed using

sdptool search --bdaddr 00:1E:DE:21:D0:85 SP

To queries all bluetooth devices nearby for a specifc service.

sdptool search SP

To register a service to local bluetooth device.

sdptool add SP
Serial Port service registered

When we try to run sdptool browse on the headset, we do not receive any records. here we can use the records subcommand to receive these records.

Here is the service list when ran on Headset

$ sdptool records 00:1E:DE:21:D0:85 | grep 'Service Name:'
Service Name: Hands-Free unit
Service Name: Headset

There are some more commands which I found usefull is on


Comments