How to get bluetooth pair-able & discover-able status - linux

Is there any way to get to know bluetooth pair-able & discover-able status such as pair-able On or Off in raspberrypi-3 using python 3.6 or linux command ?
I am using bluetoothctl functionality , through that i can change the pair-able & discover-able state from On to Off vise versa ,but unable to get current state.
if any way to get it , kindly let me know.
Thanks in advance.

btmgmt can do the work.
# btmgmt info
Index list with 1 item
hci0: Primary controller
addr XX:XX:XX:XX:XX:XX version X manufacturer XX class 0x000000
supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy static-addr
current settings: powered connectable discoverable bondable ssp br/edr le advertising secure-conn
name XXXXXXXX
short name XXXXXXXX

There is this library: https://pypi.org/project/btmgmt/ .
According to the page, it was tested with Python 3.7 .

Related

Using bluetoothctl to reset time on smartwatch (linux)

I am new to using bluetoothctl and am looking for some advice.
So, I try the following:
$ bluetoothctl power on
Changing power on succeeded
$ bluetoothctl devices
Device B3:50:46:84:F1:CF M6
The M6 is the smartwatch.
$ bluetoothctl connect B3:50:46:84:F1:CF
Attempting to connect to B3:50:46:84:F1:CF
Connection successful
Great!
$ bluetoothctl
Agent registered
[M6 ]# info
Device B3:50:46:84:F1:CF (public)
Name: M6
Alias: M6
Appearance: 0x00c8
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
WakeAllowed: yes
LegacyPairing: no
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Battery Service (0000180f-0000-1000-8000-00805f9b34fb)
UUID: Human Interface Device (00001812-0000-1000-8000-00805f9b34fb)
UUID: Unknown (0000fffa-0000-1000-8000-00805f9b34fb)
UUID: Unknown (0000ffff-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (6e400001-b5a3-f393-e0a9-e50e24dcca9d)
Modalias: usb:v1915pEEEEd0001
Battery Percentage: 0x36 (54)
[M6 ]# menu gatt
Menu gatt:
Available commands:
-------------------
list-attributes [dev/local] List attributes
select-attribute <attribute/UUID> Select attribute
attribute-info [attribute/UUID] Select attribute
read [offset] Read attribute value
write <data=xx xx ...> [offset] [type] Write attribute value
acquire-write Acquire Write file descriptor
release-write Release Write file descriptor
acquire-notify Acquire Notify file descriptor
release-notify Release Notify file descriptor
notify <on/off> Notify attribute value
clone [dev/attribute/UUID] Clone a device or attribute
register-application [UUID ...] Register profile to connect
unregister-application Unregister profile
register-service <UUID> [handle] Register application service.
unregister-service <UUID/object> Unregister application service
register-includes <UUID> [handle] Register as Included service in.
unregister-includes <Service-UUID><Inc-UUID> Unregister Included service.
register-characteristic <UUID> <Flags=read,write,notify...> [handle] Register application characteristic
unregister-characteristic <UUID/object> Unregister application characteristic
register-descriptor <UUID> <Flags=read,write...> [handle] Register application descriptor
unregister-descriptor <UUID/object> Unregister application descriptor
back Return to main menu
version Display version
quit Quit program
exit Quit program
help Display help about this program
export Print environment variables
Now, what i want to do is to set the date and time on this smartwatch. I am also interested in reading other information such as heart rate, temperature, etc. How do I do that?
Thanks!

Howto read Voice Data from Amazon Fire TV Remote Control?

I am using a Fire TV Remote Control Version 1, the old one which has no volume and power buttons.
What I want to achieve is, receive audio samples from the build in mic of this remote.
I am using a Raspberry Pi 4 with debian
Linux raspi4box 5.4.79-v7l+ #1373 SMP Mon Nov 23 13:27:40 GMT 2020 armv7l GNU/Linux
I have paired the Remote with bluetoothctl successfully and can read the key events.
When the Mic button is pressed, i want to establish a connect to the device and read
audio. I can receive the Mic button events correctly so far.
bluetoothctl -- info FC:65:DE:E8:E8:FD
Name: Amazon Fire TV Remote
Alias: Amazon Fire TV Remote
Class: 0x00001f00
Paired: yes
Trusted: yes
Blocked: no
Connected: yes
LegacyPairing: no
UUID: Serial Port (00001101-0000-1000-8000-00805f9b34fb)
UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1949p0410d0304
sdptool browse FC:65:DE:E8:E8:FD
Browsing FC:65:DE:E8:E8:FD ...
Service Name: SPPSERVER
Service RecHandle: 0x20000002
Service Class ID List:
UUID 128: 00001101-0000-1000-8000-00805f9b34fb
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 6
Language Base Attr List:
code_ISO639: 0x656e
encoding: 0x6a
base_offset: 0x100
As You can see, the Remote exposes a Serial Port Profile.
I can connect to the service with:
sudo rfcomm connect /dev/rfcomm1 FC:65:DE:E8:E8:FD 1
...
Connected /dev/rfcomm1 to FC:65:DE:E8:E8:FD on channel 1
Press CTRL-C for hangup
I can use a teminal programm on /dev/rfcomm1 which comes up with a request from the remote:
AT+BRSF=253
At this point you should be able to answer the request and finally initiate the
recording on channel 6.
At this point i am stuck, because i get not further response
from the device.
Regards
Dezi

HSP and HFP profiles for hands-free telephony

I am attempting to implement hands-free telephony on my board, I successfully connected my android phone to the board via bluetooth module in phone and media audio sharing mode.
The chip i use is Qualcomm Atheros QCA6174. I have pulseaudio 11.1, bluetoothctl: 5.49, and ofono 1.22 setup on my board.
I was able to play media files via bluetooth by this. But when a call connected the bluetooth speaker works properly, i.e. I can hear what is said on the other end of call via my headphone, but what I say is not heard at the other end( I guess there is some error in getting the data from mic or in transmitting data from bluetooth device). I get the following log message keeps appearing many times as soon as a call is initiated
"***Bluetooth: hci0 SCO packet for unknown connection handle 0***
***Bluetooth: hci0 sending frame failed (-27)***
***Bluetooth: hci0 sending frame failed (-27)***"
The microphone on the phone is also not functioning(after bluetooth connection is established).
Also in *hciconfig -a* it is found as follows
hci0: Type: Primary Bus: USB
BD Address: 00:0E:8E:76:00:55 ACL MTU: 1024:8 SCO MTU: 50:8
UP RUNNING PSCAN
RX bytes:810924 acl:982 sco:18885 events:670 errors:0
**TX bytes:528349 acl:530 sco:10271 commands:108 errors:111**
Features: 0xff 0xfe 0x8f 0xfe 0xd8 0x3f 0x5b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF
Link mode: SLAVE ACCEPT
Name: mydevice
Class: 0x2c041c
Service Classes: Rendering, Capturing, Audio
Device Class: Audio/Video, Portable Audio
HCI Version: 4.2 (0x8) Revision: 0x0
LMP Version: 4.2 (0x8) Subversion: 0x25a
Manufacturer: Qualcomm
The steps I followed to setup connection are as follows
$ hciconfig hci0 up
$ pactl list sources short
$ pactl list sinks short
$ bluetoothctl
agent on
scan on
scan off
pair <address>
connect<address>
My hcitool connections gives the following
$ hcitool con
Connections:
< ACL 78:C3:E9:21:1B:0B handle 2 state 1 lm MASTER AUTH ENCRYPT
No SCO connection is shown here.
How can I solve this and implement proper hands-free telephony?

Bluez DBus API to set duplicate filter to disable

How to set scan parameters and disable the filter duplicates, so that I can receive all advertisement from the controller ?
StartDiscovery API only notifies, whenever new device is identified but I want to set filter duplicate to disabled, so that I can receive each and every advertisement from the controller?.
But I didn't find any DBus API to set the scan parameters nor set scan enable API.
My Goal is simple I need get notify each advertisement received on controller to my client app, How can I do that with Bluez?
Note : I might missing some basic points because new to bluetooth and bluez.
In the below output you can see that the Device "Parthiban" is already present under /org/bluez/hci0/dev_44_D8_84_02_A3_17. I have started the scan which in turn triggers "StartDiscovery()" method and the same device is updated with RSSI value.
root#mx6q:~# bluetoothctl
[NEW] Controller 5C:F3:70:6E:26:02 Adapter [default]
**[NEW] Device 44:D8:84:02:A3:17 Parthiban**
[NEW] Device 2C:F0:A2:26:D7:F5 iPhone tteam
[NEW] Device 78:F8:82:10:E7:0C Nexus 5X
[bluetooth]# scan on
Discovery started
[CHG] Controller 5C:F3:70:6E:26:02 Discovering: yes
**[CHG] Device 44:D8:84:02:A3:17 RSSI: -52**
So you can use "g_dbus_connection_signal_subscribe" on the interface "org.freedesktop.DBus.Properties" for "PropertiesChanged" signal.
while(g_variant_iter_loop(&iter, "{sv}", &property, &value)) {
if(strcasecmp(property, "RSSI") == 0) {
/*
* - Extract the device address from object path
* /org/bluez/hci0/dev_44_D8_84_02_A3_17
* - Play with the device
*/
}

How to get Disconnect Event from GATT Server on Bluez/Linux

Environment: Bluez 5.14, Linux 3.1, USB Plugable BLE radio, TI BLE keyfob (CC2541 dev kit)
Linux Device <---hci----> USB BLE Radio
We enabled key press events on TI keyfob using gatttool and started to listen for events
gatttool -b [hardware ID] --char-write-req -a [handle] -n [value] --listen
(gatttool -b 90:59:AF:09:E1:5D --char-write-req -a 0x0048 -n 0100 --listen)
Pressing buttons on the keyfob and see these events
Notification handle = 0x0047 value: 02
Notification handle = 0x0047 value: 00
Notification handle = 0x0047 value: 02
Hence we can receive the key press events from the Keyfob through the Bluez stack
Objective:
We need to catch the GATT Disconnect Event i.e. When we remove the battery from the keyfob sooner or later the GATT connection is broken. We would like to receive a disconnect event from Bluez stack. Bluez has this capability since Android supports GATT disconnect event which is built over Bluez.
Question:
How do we receive the GATT Disconnect event using Bluez command line hcitool/gatttool or Bluez API.
Watch for G_IO_HUP and shutdown gracefully.
chan = gatt_connect(opt_src, opt_dst, opt_dst_type, opt_sec_level,
opt_psm, opt_mtu, connect_cb, &gerr);
if (chan == NULL) {
log_printf(LOG_LEVEL_ERROR,"%s: chan is NULL\n",__func__);
log_printf(LOG_LEVEL_ERROR,"%s\n", gerr->message);
g_error_free(gerr);
g_main_loop_quit(event_loop);
} else {
log_printf(LOG_LEVEL_INFO,"Connected to %s\n",opt_dst);
g_io_add_watch(chan, G_IO_HUP, channel_watcher, NULL);
}

Resources