thalib Engineer/Designer

Working with Bluetooth in Linux (Part 1)


Once the Bluetooth controllers are registered with the kernel, the bluetooth interface can be listed from sys entry

# ls /sys/class/bluetooth


Lets make sure the bluetooth device is turned on and not blocked using rfkill command.

sudo rfkill list
[sudo] password for mohamed:
2: hci0: Bluetooth
	Soft blocked: no
	Hard blocked: no

If bluetooth device is blocked it can be unblocked

sudo rfkill unblock bluetooth


hciconfig is similar to ifconfig command, which is used to list the local bluetooth interfaces information, turn up/down are more. Refer help for more commands/options.

Now, lets bring up the bluetooth device with hciconfig command.

sudo hciconfig hci0 up

List all bluetooth interfaces

mohamed @ turnip (master)
 └─ $ hciconfig  -a
hci0:	Type: BR/EDR  Bus: USB
	BD Address: 5C:F3:70:66:9D:06  ACL MTU: 1021:8  SCO MTU: 64:1
	RX bytes:606 acl:0 sco:0 events:36 errors:0
	TX bytes:939 acl:0 sco:0 commands:36 errors:0
	Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
	Link policy: RSWITCH SNIFF
	Link mode: SLAVE ACCEPT
	Name: 'turnip-0'
	Class: 0x600100
	Service Classes: Audio, Telephony
	Device Class: Computer, Uncategorized
	HCI Version: 4.0 (0x6)  Revision: 0x1000
	LMP Version: 4.0 (0x6)  Subversion: 0x220e
	Manufacturer: Broadcom Corporation (15)

Start/Stop bluetoothd

In ubuntu sudo service bluetooth [options]

Here options are [options] - start/stop/restart


Manual start/stop

  • stop bluetoothd daemon sudo killall -9 bluetoothd
  • start bluetoothd in debug mode sudo bluetoothd -d -n


Using rfkill command

  • to block a adapter sudo rfkill block bluetooth
  • to unblock a adapter sudo rfkill unblock bluetooth