hciconfig -a Connection timed out (110) , bluez, btusb - linux

I am experiencing this issue on my raspberry pi.
After a while of my python program running, it seems like one (or more) of the bluetooth adapters will "lock up" and hciconfig -a will output:
: Connection timed out (110)
root ~ # hciconfig -a
hci3: Type: BR/EDR Bus: USB
BD Address: 5C:F3:70:61:CA:D6 ACL MTU: 9000:8 SCO MTU: 64:1
UP RUNNING
RX bytes:5315773 acl:178107 sco:0 events:287995 errors:0
TX bytes:487424645 acl:527773 sco:0 commands:13454 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
Can't read local name on hci3: Connection timed out (110)
The problem seems to manifest more frequently when multiple adapters are used.
The project I am working on involves using multiple (and sometimes single) USB bluetooth adapters to obex-push files to phones.
The python program that does the following things:
1.automatically detects adapters - #hciconfig -a
2.configures them - #hciconfig CMD
3.Inquires devices - #hcitool -i inq
4.Obex push files on (possibly simultaneously with other threads and other ) - bluez dbus
Some info from my system:
root ~ # modinfo btusb
filename: /lib/modules/3.12.29-1-ARCH/kernel/drivers/bluetooth/btusb.ko.gz
license: GPL
version: 0.6
description: Generic Bluetooth USB driver ver 0.6
author: Marcel Holtmann <marcel#holtmann.org>
srcversion: 61D6539530170376DCAF49C
alias: usb:v*p*d*dcE0dsc01dp01ic*isc*ip*in*
...
depends: bluetooth
intree: Y
vermagic: 3.12.29-1-ARCH preempt mod_unload modversions ARMv6
...
root ~ # pacman -Q
...
bluez 5.24-1
bluez-utils 5.24-1
...
dbus 1.8.0-1
dbus-glib 0.102-1
...
libusb 1.0.18-1
...
linux-api-headers 3.13.2-1
linux-firmware 20140217.343e460-1
linux-raspberrypi 3.12.29-1
Any ideas/or suggestions?
Is there a newer version of btusb? I looked, but I came up mostly empty handed
Note: I am somewhat of a Linux newb (though I am learning) =-)
...
PS:
These forums seem to suggest that something similar may have been fixed:
https://bbs.archlinux.org/viewtopic.php?id=183411
https://bbs.archlinux.org/viewtopic.php?id=183038
but the referenced problem appears to be specifically with the Atheros adapter chipset and I am using Broadcom chipset. Also, it appears the latest version of linux I can get for the rpi is 13.13 headers and linux-raspberrypi 13.12

Related

bluez rfcomm connect fail

I am trying connect Ubuntu pc with device. While command entered, it returns various error including rfcomm connect address already in use 、 host is down 、 rfcomm connect now in progress.
Device environment and procedure as below
Device environment
Linux 3.4
Bluez 5.19
bt addr xx:xx:xx:xx:38:A4
PC environment
Ubuntu 14.04
bluez 4
bt addr xx:xx:xx:xx:CF:F0
steps
device
insmod rfcomm.ko rtk_btusb.ko
dbus-daemon --config-file=/etc/dbus-1/system.conf
bluetoothd -C &
hciconfig hci0 up
hciconfig hci0 piscan
sdptool add SP
bluetoothctl scan on
bluetoothctl agent on
bluetoothctl default-agent
bluetoothctl trust xx:xx:xx:xx:CF:F0
bluetoothctl pair xx:xx:xx:xx:CF:F0
rfcomm bind 0 xx:xx:xx:xx:CF:F0 1
chmod 666 /dev/rfcomm0
rfcomm connect 0 xx:xx:xx:xx:CF:F0 1
PC
sdptool add SP
rfcomm bind 0 xx:xx:xx:xx:38:A4 1
chmod 666 /dev/rfcomm0
rfcomm watch 0 1
Device show Can't connect RFCOMM socket: Host is down
hciconfig -a output
hci0: Type: BR/EDR Bus: USB
BD Address: 5C:F3:70:1B:38:A4 ACL MTU: 820:8 SCO MTU: 255:16
UP RUNNING PSCAN ISCAN
RX bytes:6888 acl:88 sco:0 events:230 errors:0
TX bytes:4341 acl:84 sco:0 commands:87 errors:0
Features: 0xff 0xff 0xff 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH HOLD SNIFF PARK
Link mode: SLAVE ACCEPT
Name: 'BlueZ 5.19'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: 4.0 (0x6) Revision: 0xe2f
LMP Version: 4.0 (0x6) Subversion: 0x9f73
Manufacturer: Realtek Semiconductor Corporation (93)
Is any step missed in my procedure?
below steps works for me.
PC side
sdptool add SP
rfcomm -i hci0 watch 0 1 ./picocom /dev/rfcomm0
Device side
sdptool add SP
rfcomm connect 0 xx:xx:xx:xx:xx:F0 1 &
picocom /dev/rfcomm0
reference

Cannot connect bluetooth remote control to SBC running linux

I am running a buildroot-generated linux image (kernel 4.11.2) on a nanopi NEO air board, and I struggle to connect to my ruwido remote control.
I can see it when I scan the devices using hcitool :
# hcitool lescan
LE Scan ...
<snip>
5C:F8:21:85:8E:67 ruwido
<snip>
But I cannot get a connection (it acts like the remote is not here) :
# hcitool cc 5C:F8:21:85:8E:67
Can't create connection: Input/output error
The only thing I can do is get some information about it :
# hcitool leinfo 5C:F8:21:85:8E:67
Requesting information ...
Handle: 64 (0x0040)
LMP Version: 4.0 (0x6) LMP Subversion: 0x140
Manufacturer: Texas Instruments Inc. (13)
Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
I also cannot use bluetoothctl since it doesn't detect my interface, even though it's initialized, bluetoothd is running and the modules are loaded :
# lsmod
Module Size Used by
bnep 20480 2
hci_uart 61440 1
btbcm 16384 1 hci_uart
btqca 16384 1 hci_uart
btintel 16384 1 hci_uart
bluetooth 348160 12 hci_uart,btintel,btqca,bnep,btbcm
brcmfmac 245760 0
brcmutil 16384 1 brcmfmac
sunxi_cir 16384 0
# ps -e | grep bluetooth
553 root /usr/sbin/bluetoothd
731 root grep bluetooth
# sudo hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: F7:93:3E:74:CF:62 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING
RX bytes:12593 acl:7 sco:0 events:292 errors:0
TX bytes:2050 acl:4 sco:0 commands:155 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: 'NanoPi-NEO-Air'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: 4.1 (0x7) Revision: 0x0
LMP Version: 4.1 (0x7) Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
# bluetoothctl
Agent registered
[bluetooth]# power on
No default controller available
My question is, how do I get the remote paired and connected to the board ? It doesn't matter if it's through hcitool, bluetoothctl or another tool.
Update
Thanks to Prabhakar Lad's comment, bluetoothctl is now detecting the interface, however the problem still remains and the problem seems to have narrowed :
# rfkill unblock all
# hciconfig hci0 up
# hciconfig -a
hci0: Type: Primary Bus: UART
BD Address: AA:AA:AA:AA:AA:AA ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:1930 acl:0 sco:0 events:101 errors:0
TX bytes:1587 acl:0 sco:0 commands:103 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: 'BlueZ 5.47'
Class: 0x000000
Service Classes: Unspecified
Device Class: Miscellaneous,
HCI Version: 4.1 (0x7) Revision: 0x0
LMP Version: 4.1 (0x7) Subversion: 0x2209
Manufacturer: Broadcom Corporation (15)
# bluetoothctl
[NEW] Controller F7:93:3E:74:CF:62 BlueZ 5.47 [default]
[NEW] Device 5C:F8:21:85:8E:67 ruwido
Agent registered
[bluetooth]# agent on
Agent is already registered
[bluetooth]# power on
Changing power on succeeded
[bluetooth]# scan on
Discovery started
[CHG] Controller F7:93:3E:74:CF:62 Discovering: yes
<snip>
[NEW] Device 5C:F8:21:85:8E:67 ruwido
<snip>
[bluetooth]# scan off
<snip>
[CHG] Device 5C:F8:21:85:8E:67 RSSI is nil
<snip>
[CHG] Controller F7:93:3E:74:CF:62 Discovering: no
Discovery stopped
[bluetooth]# pair 5C:F8:21:85:8E:67
Attempting to pair with 5C:F8:21:85:8E:67
[CHG] Device 5C:F8:21:85:8E:67 Connected: yes
[ruwido]# [ 501.424858] Bluetooth: hci0 unexpected SMP command 0x0b from 5c:f8:21:85:8e:67
[CHG] Device 5C:F8:21:85:8E:67 Connected: no
[bluetooth]# pair 5C:F8:21:85:8E:67
Attempting to pair with 5C:F8:21:85:8E:67
Failed to pair: org.bluez.Error.ConnectionAttemptFailed
The SMP error seems to be related to bluetooth low-energy security, so am I supposed to use a different tool for pairing ?
Additional information
I actually use the busybox init system with bluetooth init scripts I found in the manufacturer's image (which is nanopi-neo-air_FriendlyCore-Xenial_4.11.2_20171113.img) and adapted so that they could be used with busybox init (the init system on the image is systemd/upstart).
So I have two files :
/etc/init.d/S35brcm_patchram_plus : patches firmware (the card uses an AMPAK ap6212 bluetooth/wifi combo module)
/etc/init.d/S38bluetooth : starts bluetoothd
I use bluez 5.47 with the following options in buildroot 2017.08.1 :
BR2_PACKAGE_BLUEZ_TOOLS=y
# BR2_PACKAGE_BLUEZ_UTILS is not set
BR2_PACKAGE_BLUEZ5_UTILS=y
BR2_PACKAGE_BLUEZ5_UTILS_OBEX=y
BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y
BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y
# BR2_PACKAGE_BLUEZ5_UTILS_EXPERIMENTAL is not set
# BR2_PACKAGE_BLUEZ5_PLUGINS_HEALTH is not set
# BR2_PACKAGE_BLUEZ5_PLUGINS_MIDI is not set
# BR2_PACKAGE_BLUEZ5_PLUGINS_NFC is not set
# BR2_PACKAGE_BLUEZ5_PLUGINS_SAP is not set
BR2_PACKAGE_BLUEZ5_UTILS_TEST=y
# BR2_PACKAGE_BLUEZ5_UTILS_GATTTOOL is not set
You didnt go through my complete post, you need to perform following
steps after you have done with rfkill and service restart:
a] bluetoothctl
Start the tool, this should detect the controller
b] [bluetooth]# agent on
Turn on the pairing agent
c] [bluetooth]# scan on
Let bluez detect your device, look in my post it should print you baddr (5C:F8:21:85:8E:67)
d] [bluetooth]# scan off
Turn off scanning once your device is discovered
e] [bluetooth]# pair 5C:F8:21:85:8E:67
Now pair to the device
It should now be paired.
Note: you cannot pair a device until the bluez has scanned it.

ASUS N751JK, bluetooth doesn't work, ubuntu 17.10

Can't make my bluetooth work on Ubuntu.
The toggle is active.But it means nothing. Since system is not reacting on it
rfkill list output is normal:
0: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
1: hci0: Bluetooth
Soft blocked: no
Hard blocked: no
hciconfig -a gives the following info
hci0: Type: Primary Bus: USB
BD Address: 9C:D2:1E:0D:2F:B2 ACL MTU: 1021:4 SCO MTU: 128:2
DOWN
RX bytes:1160 acl:0 sco:0 events:62 errors:0
TX bytes:742 acl:0 sco:0 commands:62 errors:0
Features: 0xff 0xff 0x8f 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
Typping of sudo hciconfig hci0 up results in:
Can't init device hci0: Invalid request code (56)
The output of hcitool dev command is empty:
Devices:
This is hcitool scan output
Device is not available: No such device
I seached for similar problems, checked their solutions if it works in my case, but failed - nothing has helped me. So I've decided to ask it here
There may be another usefull information which is not given here for now. But I don't know yet what should be provided in order to make the problem be solved easier.
Download the driver for the Mediatek MT7630E wireless card here
https://community.linuxmint.com/tutorial/view/1796
and execute the commands to compile and install the driver.
If wifi works after installing the driver but bluetooth doesn't, you should check "Readme.md" in driver file directory (/Downloads/MT7630E-release).
It worked for me in Linux Mint 18.3. Both wifi and bluetooth. But wifi only at 2.4GHz

Change bluetooth mac address in Raspbian

hi i need to change the bluetooth mac address from my device. i've download the bdaddr utility from here! and i compiled it.
Then...
wget -U "Mozilla" http://www.petrilopia.net/wordpress/wp-content/uploads/bdaddrtar.bz2
...
mv bdaddrtar.bz2 bdaddr.tar.bz2
tar xvjf bdaddr.tar.bz2
cd bdaddr
sudo apt-get install libbluetooth-dev
...
make
...
pi#raspberrypi ~/bdaddr $ hcitool dev
Devices:
hci0 00:1F:81:00:08:30
pi#raspberrypi ~/bdaddr $ hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:1F:81:00:08:30 ACL MTU: 1021:4 SCO MTU: 180:1
UP RUNNING PSCAN ISCAN
RX bytes:2296 acl:0 sco:0 events:100 errors:0
TX bytes:1081 acl:0 sco:0 commands:98 errors:0
pi#raspberrypi ~/bdaddr $ sudo ./bdaddr -i hci0 00:1F:81:00:48:30
Manufacturer: Cambridge Silicon Radio (10)
Device address: 00:1F:81:00:08:30
New BD address: 00:1F:81:00:48:30
Can't write new address
Why can't i write the address? some idea?
thanks
The bdaddr utility is not part of the bluez package because it uses manufacturer specific code and as such does not work on all devices.
http://ubuntuforums.org/archive/index.php/t-925611.html

How to tell whether bluetooth adapter supports bluetooth LE (4.0)?

I have two Bluetooth adapters, an old internal adapter and a new Bluetooth 4.0 adapter.
I am writing an application that uses a socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP) to connect to a Bluetooth LE device on Linux. When I call connect() with a sockaddr_l2 {.l2_family = AF_BLUETOOTH, .l2_bdaddr = {...}, .l2_cid = L2CAP_CID_ATT, .l2_bdaddr_type = BRADDR_LE_PUBLIC}, connect fails with errno=0x38000000=939524096 Unknown error, because Linux arbitrarily chooses the old adapter that only supports Bluetooth 2.1, not Bluetooth 4.0. The solution is to bind the socket to the bd_addr of the adapter that supports Bluetooth 4.0.
Question: How to tell which adapter is the Bluetooth 4.0 adapter? hciconfig does not tell which one is the one to use; they both say BR/EDR and not LE.
$ hciconfig
hci1: Type: BR/EDR Bus: USB
BD Address: 00:25:00:F6:97:F0 ACL MTU: 1021:5 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:1074 acl:0 sco:0 events:56 errors:0
TX bytes:1462 acl:0 sco:0 commands:56 errors:0
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:D6:A0:BF ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:146505 acl:328 sco:0 events:4189 errors:0
TX bytes:6213 acl:215 sco:0 commands:83 errors:0
$ modinfo bluetooth | grep ^version:
version: 2.17
$ modinfo btusb | grep ^version:
version: 0.6
$ lsb_release --description
Description: Ubuntu 14.04.1 LTS
$ uname --kernel-release
3.13.0-40-generic
To answer your question there is btmgmt info which will list the HCI version (on the same line as addr), you will have to look into Host Controller Interface Assigned numbers for the meaning of the numbers, version 6 below mean Bluetooth 4.0.
# btmgmt info
hci0: Primary controller
addr 5C:F3:70:XX:XX:XX version 6 manufacturer 15 class 0x1c010c
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 bondable ssp br/edr le secure-conn
name BlueZ 5.47
short name
If you need to know if the adapter support LE, you will have to look for le in Supported settings: because LE is not mandatory in bluetooth 4.0/4.1.
Try: hciconfig hci[0|1] version

Resources