Can't set fast-connectable on my Bluetooth controller with BlueZ5 - linux

I can't set fast-connectable on my Bluetooth controller:
# btmgmt fast-conn on
Set Fast Connectable for hci0 failed with status 0x0c (Not Supported)
though fast-connectable is supported according to btmgmt!
# btmgmt info
Index list with 1 item
hci0: Primary controller
addr 4C:74:03:64:82:1F version 7 manufacturer 15 class 0x000000
supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy configuration static-addr
current settings: powered connectable bondable le secure-conn
name mybox
short name
hci0: Configuration options
supported options: public-address
missing options:
Same problem if the controller is powered off
# btmgmt power off
before trying to apply fast-connectable...
Would you have any idea why?
I'm running a Linux 4.1.20 kernel, with BlueZ 5.49.
I searched the Internet, the BlueZ documentation, but couldn't find much information about the setting fast-connectable. Help would be appreciated.

Related

[RPi3][Bluez] Managed to connect to a BLE device but can't list GATT attributes

I am doing a project where I need to create communication between two Raspberry Pi 3 on stretch (RPi) wirelessly with callback functionalities using C++ code. The first is supposed to send data to the second one. I decided to create a bluetooth connexion between the two using the on-board bluetooth-chips.
So first I decided to compile Linux Bluetooth Stack: Bluez on both RPi from source, version 5.50. Following this tutorial : https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation on Adafruit. I managed to send a message from one pi to another using these codes :https://people.csail.mit.edu/albert/bluez-intro/x502.html. But to read a message sent by the client, I have to call the function "read(client, buf, sizeof(buf))" as shown in the server code which is a bit restrictive. I want to be notified whenever a message is received so that a callback function can be called. I saw it could be done by enabling notifications on the GATT Characteristics used for the communication.
This level of specification is not really shown on the C++ codes I got from https://people.csail.mit.edu/albert/bluez-intro/x502.html. After having improved my knowledge on GATT with this : https://www.novelbits.io/bluetooth-gatt-services-characteristics/ , I decided to follow Tony D's youtube tutorial on how to use Bluez APi
https://www.youtube.com/watch?v=5fQR2PHMDWE.
To make it easier, I decided to left one RPi aside and tried to connect a Bluetooth audio headset JBL T450BT which use Bluetooth 4.0, so it is supposed to support Bluetooth Low Energy.
On bluetoothctl here's the problem, I manage to power on the controller, scan on and detect the headset. I then trust, pair and connect. In GATT menu, I enter the command : list-attributes [dev address]. Bluetoothctl prints no error but returns nothing and is ready to receive other command lines.
sudo bluetoothctl
[bluetooth]# show
Controller XX:XX:XX:XX:XX:XX (public)
Name: VoitureRPi
Alias: VoitureRPi
Class: 0x004c0000
Powered: yes
Discoverable: no
Pairable: yes
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: Handsfree Audio Gateway (0000111f-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0532
Discovering: no
[bluetooth]# scan on
Device 78:44:05:BC:12:0C JBL T450BT
[bluetooth]# trust 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Trusted: yes
Changing 78:44:05:BC:12:0C trust succeeded
[bluetooth]# pair 78:44:05:BC:12:0C
Attempting to pair with 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Connected: yes
[CHG] Device 78:44:05:BC:12:0C UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: yes
[CHG] Device 78:44:05:BC:12:0C Paired: yes
Pairing successful
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: no
[CHG] Device 78:44:05:BC:12:0C Connected: no
[bluetooth]# connect 78:44:05:BC:12:0C
Attempting to connect to 78:44:05:BC:12:0C
[CHG] Device 78:44:05:BC:12:0C Connected: yes
Connection successful
[CHG] Device 78:44:05:BC:12:0C ServicesResolved: yes
[JBL T450BT]# menu gatt
[JBL T450BT]# list-attributes 78:44:05:BC:12:0C
[JBL T450BT]#
From there I get no answer from bluetoothctl but no error as well, as I told you. I am not able to discover services/characteristics.
On the youtube tuto I followed,it was told that the GATT services and Characteristics discovery was done during the pairing/first connexion. I assume that the Pi intends to do it but fails. That's maybe why I get the sequence :
connected: yes, ServicesResolved: yes Paired successfully and then ServicesResolved: no, connected no. Nothing like : [NEW] XXX Service or Characteristcs is shown.
I don't think the problem comes from the headset because it does the same thing on other devices I connect to. I have both pulseaudio and bluealsa packages installed on the RPi.
As mentionned in this tuto
Here the bluetooth status :
systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-11-08 11:29:38 CET; 27min ago
Docs: man:bluetoothd(8)
Main PID: 2646 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─2646 /usr/local/libexec/bluetooth/bluetoothd --experimental
Here's what hciconfig gives :
hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: B8:27:EB:A8:0C:20 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:11205 acl:76 sco:0 events:520 errors:0
TX bytes:219869 acl:433 sco:0 commands:150 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: 'VoitureRPi'
Class: 0x4c0000
Service Classes: Rendering, Capturing, Telephony
Device Class: Miscellaneous,
HCI Version: 4.1 (0x7) Revision: 0x168
LMP Version: 4.1 (0x7) Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
Here's also what the D-Bus introspection tool returns :
busctl tree org.bluez
└─/org
└─/org/bluez
└─/org/bluez/hci0
└─/org/bluez/hci0/dev_78_44_05_BC_12_0C
├─/org/bluez/hci0/dev_78_44_05_BC_12_0C/fd1
└─/org/bluez/hci0/dev_78_44_05_BC_12_0C/player0
For people who got problems with pairing and connecting, this source was a huge help :https://www.sigmdel.ca/michel/ha/rpi/bluetooth_02_en.html
Anyway so that's my problem. I want to access Characteristics and their UUID's to be able to modify their permission or to create a new service with its own characteristics suited to my project.
To this point I think this is the only way to implement a notifier with a callback in a bluetooth communication. Maybe I'm wrong. Do you have any clue whatsoever ? :)
Thanks to A.Baur, the "--experimental" option was the last missing thing.
My system:Debian 10 + KDE
Installed:
- bluez-*
- bluetooth
- pulseaudio-module-bluetooth
Steps:
1. stop bluetooth service: >sudo systemctl stop bluetooth
2. modify: /etc/init.d/bluetooth ; by adding to the line:
SSD_OPTIONS="**--experimental** --oknodo --quiet --exec $DAEMON -- $NOPLUGIN_OPTION"
3. start bluetooth service: >sudo systemctl start bluetooth
4. connect to Bose QC35 II by bluetoothctl or other GUI tool.
I got it working in RPi with python examples of advertisement and gatt server from bluez-5.50. I used nRF tool to test it.

Raspberry Pi as a audio Transmitter to a Bluetooth Speaker

i wanted to ask you guys, if it is possible to use the Raspberry Pi as a transmitter from a audio source, lets say a TV for example.
I want to send the sound from the TV to the Raspberry Pi via audio Jack and then send the sound via Bluetooth to a wireless speaker. So the Rasberry should act like a bridge between TV and the speaker.
It should look like this in the end:
TV --Sound via audio jack--> Raspberry Pi ~~Sound via Bluetooth~~>
speaker
So, if there is a way, how can i do this ? Thanks in advance
RPi doen't have audio input. You need one of these adapter like this (http://raspberry-projects.com/pi/pi-hardware/audio-input) and connect input to TV and RPi output to wireless / bluetooth speakers. I haven't tried it yet. Let me your feedback.
Since a web search might bring others here as it did me, here's how I did this connecting my record player through a Raspberry Pi 3 to a Bose Portable Home/Smart Speaker.
Get an audio input into the Pi
I used a cheap USB soundcard bought on Adafruit
Identify your new PulseAudio input/source and note name
This can be done by calling pactl list sources (mine was identifiable from its name and description)
$ pactl list sources
...
Source #2
State: RUNNING
Name: alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback
Description: USB Audio Device Mono
...
Connect your Pi to your bluetooth speaker
Run sudo bluetoothctl (running this without sudo resulted in settings being forgotten upon reboot) and enter the commands below
(Optional) Give your Pi an alias when connecting over bluetooth: [bluetooth]# system-alias 'Your New BT Alias'
Enter scanning mode [bluetooth]# scan on
Put your speaker in pairing mode and wait for it to be listed in the rolling output. E.g.
[NEW] Device AA:AA:AA:AA:AA:AA AA-AA-AA-AA-AA-AA
[NEW] Device BB:BB:BB:BB:BB:BB BB-BB-BB-BB-BB-BB
[NEW] Device CC:CC:CC:CC:CC:CC My speaker's name
Pair with it referencing its address:
[bluetooth]# pair CC:CC:CC:CC:CC:CC
Attempting to pair with CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Connected: yes
Request confirmation
[agent] Confirm passkey 123456 (yes/no): yes
Connect to the speaker now
[bluetooth]# connect CC:CC:CC:CC:CC:CC
Attempting to connect to CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Connected: yes
Connection successful
Trust the speaker so it is automatically connected to when available
[My speaker's name]# trust CC:CC:CC:CC:CC:CC
[CHG] Device CC:CC:CC:CC:CC:CC Trusted: yes
Changing CC:CC:CC:CC:CC:CC trust succeeded
Note your bluetooth speaker's associated PulseAudio output/sink name
This can be done by calling pactl list sinks (again, should be identifiable by name and description)
$ pactl list sinks
...
Sink #2
State: RUNNING
Name: bluez_sink.CC_CC_CC_CC_CC_CC.a2dp_sink
Description: My speaker's name
...
Set up PulseAudio defaults
Identify a good volume level for your input so distortion is minimal. E.g.
pactl set-source-volume alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback 16000
Add your version of the following lines to /etc/pulse/default.pa to set up an audio loopback and ensure the correct devices (based on the names you noted above) are used by default:
### Make some devices default
set-default-sink bluez_sink.60_AB_D2_57_42_A9.a2dp_sink
set-default-source alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback
# Set up loopback
load-module module-loopback latency_msec=1
# Set input volume
set-source-volume alsa_input.usb-GeneralPlus_USB_Audio_Device-00.mono-fallback 16000

Is there a way to find out which Bluetooth device is plugged into which USB port?

I'm using two Bluetooth adaptors with BlueZ, both are the same device but with different types of antenna, is there any method to find out which usb port the identifier on BlueZ (hci0/hci1) is referring to?
I can discover the MAC address of the device through hcitool dev, so if there was a way to discover which USB port the adaptor with that MAC address was connected to, that would also solve my problem.
As both the adaptors are the same model, lsusb does not provide any identifying information I can use.
Using Ubuntu 16.04. I am looking for a solution in any form, whether it is a shell command or java/C/python/etc.
This answer should point you in the right direction, though doesn't give you a complete solution.
You should be able to use the contents of the "sys" filesystem, under /sys/class/bluetooth:
$ ls -lA /sys/class/bluetooth/
total 0
lrwxrwxrwx 1 root root 0 Dec 8 09:35 hci0 -> ../../devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/bluetooth/hci0
lrwxrwxrwx 1 root root 0 Dec 8 09:35 hci1 -> ../../devices/platform/soc/3f201000.serial/tty/ttyAMA0/hci1
That's from my Raspberry Pi, with a builtin adapter on the /dev/ttyAMA0 UART interface, and an added Bluetooth adapter on USB. The information in the symlink target technically tells you which physical port the adapter is plugged into.
If you're not familiar with the convention for USB device numbering (which forms a tree of nodes, since a port can have a USB hub with multiple additional ports, etc), look under /sys/bus/usb/devices, and match that up with the "lsusb" output and you should figure it out. In my case, "lsusb" shows that adapter as "Bus 001 Device 004: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0", which if I recall corresponds to the "1-3" stuff in the /sys/class/bluetooth path (where unfortunately it appears the bus value uses index origin 1, while the device number uses index origin 0 so the 4 turns into a 3 there).
If you experiment with moving your USB adapter around to different physical ports, you should be able to work out the pattern.
I don't know if this is what you need, but you should find detailed information about the devices attached through the following command:-
hciconfig -a
This will give you enough details to identify the specific devices. You can add this in a shell script and use some string manipulation and conditionals to figure out your devices.
In my case, I have one BT dongle connected, and running hciconfig -a give the following output:-
hci0: Type: BR/EDR Bus: USB
BD Address: 00:16:A4:06:AC:E6 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:670 acl:0 sco:0 events:46 errors:0
TX bytes:2495 acl:0 sco:0 commands:46 errors:0
Features: 0xff 0xff 0xcf 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: 'youssif'
Class: 0x0c0000
Service Classes: Rendering, Capturing
Device Class: Miscellaneous,
HCI Version: 4.0 (0x6) Revision: 0x22bb
LMP Version: 4.0 (0x6) Subversion: 0x22bb
Manufacturer: Cambridge Silicon Radio (10)
If this is not sufficient, you can use also use a combination of lsusb and hciconfig commands to figure out which device is connected to what port.

Bluetooth in Terminal

I want to see the Bluetooth adapter details in terminal without using Bluetooth GUI. Initially Bluetooth is turned off both in terminal and GUI.
My commands for different functions in Terminal
View status of Bluetooth (it will show active/inactive and status in some cases, and just active/inactive in some other cases)
sudo /etc/init.d/bluetooth status
Turn on Bluetooth
sudo /etc/init.d/bluetooth start
Turn off Bluetooth
sudo /etc/init.d/bluetooth stop
View the Bluetooth adapter details
hciconfig
I can see the adapter details with the help of Bluetooth GUI in Settings GUI.
I researched the status of Bluetooth in different cases by doing following steps in order:
1. Turn on Bluetooth via terminal
Status = "Running"
Active = "active (running)"
Bluetooth adapter details: Doesn't display anything
2. Turn off Bluetooth via terminal
Status = Not shown
Active = "inactive (dead)"
Bluetooth adapter details: Doesn't display anything
3. Turn on Bluetooth via GUI
Status = "Running"
Active = "active (running)"
Bluetooth adapter details: Shows the adapter details
4. Turn off Bluetooth via terminal, but doesn't change in GUI
Status = "Quitting"
Active = "inactive (dead)"
Bluetooth adapter details: Shows the adapter details
5. Turn on Bluetooth via terminal
Status = "Running"
Active = "active (running)"
Bluetooth adapter details: Shows the adapter details
6. Turn off Bluetooth via terminal, but doesn't change in GUI
Status = "Quitting"
Active = "inactive (dead)"
Bluetooth adapter details: Shows the adapter details
7. Turn off Bluetooth in GUI
Status = Not shown
Active = "inactive (dead)"
Bluetooth adapter details: Doesn't display anything
Can someone please help me what's wrong in my commands? Also, why it works fine along with GUI? What does GUI actually do?
Give this tool a try:
bluetoothctl
Here is the installation guide:
(https://wiki.archlinux.org/index.php/bluetooth#Installation)
it gives you a lot of posibilities:
Menu main:
Available commands:
-------------------
advertise Advertise Options Submenu
scan Scan Options Submenu
gatt Generic Attribute Submenu
list List available controllers
show [ctrl] Controller information
select <ctrl> Select default controller
devices List available devices
paired-devices List paired devices
system-alias <name> Set controller alias
reset-alias Reset controller alias
power <on/off> Set controller power
pairable <on/off> Set controller pairable mode
discoverable <on/off> Set controller discoverable mode
agent <on/off/capability> Enable/disable agent with given capability
default-agent Set agent as the default one
advertise <on/off/type> Enable/disable advertising with given type
set-alias <alias> Set device alias
scan <on/off> Scan for devices
info [dev] Device information
pair [dev] Pair with device
trust [dev] Trust device
untrust [dev] Untrust device
block [dev] Block device
unblock [dev] Unblock device
remove <dev> Remove device
connect <dev> Connect device
disconnect [dev] Disconnect device
menu <name> Select submenu
version Display version
quit Quit program
exit Quit program
help Display help about this program
you can even drill down into the advertise policies and more:
# menu advertise
Menu advertise:
Available commands:
-------------------
uuids [uuid1 uuid2 ...] Set/Get advertise uuids
service [uuid] [data=xx xx ...] Set/Get advertise service data
manufacturer [id] [data=xx xx ...] Set/Get advertise manufacturer data
tx-power [on/off] Show/Enable/Disable TX power to be advertised
name [on/off/name] Configure local name to be advertised
appearance [on/off/value] Configure custom appearance to be advertised
duration [seconds] Set/Get advertise duration
timeout [seconds] Set/Get advertise timeout
clear [uuids/service/manufacturer/config-name...] Clear advertise config
back Return to main menu
version Display version
quit Quit program
exit Quit program
help Display help about this program
That is a lot of information you can pull (and set) directly.

Legacy pairing, SSP - enable from command line [Linux]

As part of my automation project, I have two USB dongles and I need to automate the bluetooth test-cases. Both the devices seem to support SSP. This I infer from the hciconfig output. For ex: typing $hciconfig hci0 sspmode
I get,
hci0: Type: BR/EDR Bus: USB
BD Address: xx:xx:xx:xx:xx:xx ACL MTU: 1021:8 SCO MTU: 64:1
Simple Pairing mode: Enabled
and I get a similar output for hci1. My questions are as follows:
a) How do I make them do SSP from command line [with and without encryption]?
b) How do I make them pair using legacy pairing method from command line [with and without encryption]?
For both #a and #b, how do I validate that indeed SSP and legacy pairing have happened using hcidump [if someone can point me to what to expect from the hci logs, I Would be very thankful.

Resources