Is there a way to create a multiple connections BLE device in BlueZ? - bluetooth-lowenergy

I am broadcasting a BLE advertisement using the following command in linux :
sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 63 6F 3F 8F 64 91 4B EE 95 F7 D8 CC 64 A8 63 B5 00 00 00 00 C8
The BLE devce is visible, but don't allow any connection (since it follows the iBeacon specs, I think).
So my question is, is there a way to create with BlueZ a BLE device that allows not just one, but several connections ?
I read somewhere that A BLE device should be able to allow up to 20 connections, against 7 for a classic bluetooth.
Thank you very much

This depends on your hardware and the Bluetooth version that it supports. With Bluetooth v4.1, all restrictions have been removed and your device can be a peripheral connected to multiple centrals. This is mentioned at this link:-
Beginning with version 4.1 of the specification, any restrictions on
role combinations have been removed, and the following are all
possible:
A device can act as a central and a peripheral at the same time.
A central can be connected to multiple peripherals.
A peripheral can be connected to multiple centrals.
Previous versions of the specification limited the peripheral to a
single central connection (although not conversely) and limited the
role combinations.
You can find out the Bluetooth version of your device via hciconfig -a:-
hci0: Type: Primary Bus: USB
BD Address: 00:11:22:33:44:55 ACL MTU: 310:10 SCO MTU: 64:8
UP RUNNING
RX bytes:736 acl:0 sco:0 events:57 errors:0
TX bytes:5366 acl:0 sco:0 commands:57 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: 'uknown'
Class: 0x1c0000
Service Classes: Rendering, Capturing, Object Transfer
Device Class: Miscellaneous,
**HCI Version: 4.0 (0x6) Revision: 0x22bb**
LMP Version: 4.0 (0x6) Subversion: 0x22bb
Manufacturer: Cambridge Silicon Radio (10)
I would recommend using the bluetoothctl utility on Linux to advertise, instead of doing it through hcitool given that hcitool is deprecated and is also not very user friendly. More information on using bluetoothctl to advertise and accept incoming connections can be found here:-
BlueZ: How to set up a GATT server from the command line

Related

Hostapd doesn't launch with udev

I have a problem, I want to launch a script to start "hostapd" when I insert a vga/hdmi adapter on my Asus E200ha.
The script works well when I launch it directly in a commmand line but don't work when it's called by "udev"
This is the line for the udev's capture:
ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1", RUN="/home/user/hotspot.sh"
This is the script "hotspot.sh"
#!/bin/bash
exec > /var/log/hotplug-vga.log 2>&1;
service NetworkManager stop
killall wpasupplicant
hostapd -dd /etc/hostapd/hostapd.conf &
This is the "hostapd.conf" file
interface=wlan0
ieee80211n=1
driver=nl80211
ssid=chingpro
hw_mode=g
channel=6
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
When I execute the instruction "/usr/sbin/hostapd /home/user/hostapd.sh", all work fine:
wpasupplicant: aucun processus trouvé
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
ctrl_interface_group=0
nl80211: TDLS supported
nl80211: TDLS external setup
nl80211: Supported cipher 00-0f-ac:1
nl80211: Supported cipher 00-0f-ac:5
[...]
nl80211: assocresp_ies - hexdump(len=10): 7f 08 04 00 00 02 00 00 00 40
nl80211: Set wlan0 operstate 0->1 (UP)
netlink: Operstate: ifindex=18 linkmode=-1 (no change), operstate=6 (IF_OPER_UP)
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
wlan0: Setup of interface done.
ctrl_iface not configured!
[...]
But when I connect my vga/hdmi, I can see that my script is executed with the log inside the "/var/log/hotplug-vga.log" but the launch of "hostapd" fail:
wpasupplicant: no process found
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
ctrl_interface_group=0
nl80211: TDLS supported
nl80211: TDLS external setup
nl80211: Supported cipher 00-0f-ac:1
nl80211: Supported cipher 00-0f-ac:5
nl80211: Supported cipher 00-0f-ac:2
nl80211: Supported cipher 00-0f-ac:4
nl80211: Supported cipher 00-0f-ac:6
nl80211: Supported cipher 00-0f-ac:13
nl80211: Supported cipher 00-0f-ac:11
nl80211: Supported cipher 00-0f-ac:12
nl80211: Supports Probe Response offload in AP mode
nl80211: Using driver-based off-channel TX
nl80211: Driver-advertised extended capabilities (default) - hexdump(len=8): 04 00 00 00 00 00 00 40
nl80211: Driver-advertised extended capabilities mask (default) - hexdump(len=8): 04 00 00 00 00 00 00 40
nl80211: Use separate P2P group interface (driver advertised support)
nl80211: Enable multi-channel concurrent (driver advertised support)
nl80211: use P2P_DEVICE support
nl80211: interface wlan0 in phy phy15
nl80211: Set mode ifindex 18 iftype 3 (AP)
nl80211: Setup AP(wlan0) - device_ap_sme=0 use_monitor=0
nl80211: Subscribe to mgmt frames with AP handle 0x557d15b300e0
nl80211: Register frame type=0xb0 (WLAN_FC_STYPE_AUTH) nl_handle=0x557d15b300e0 match=
nl80211: Register frame command failed (type=176): ret=-114 (Operation already in progress)
nl80211: Register frame match - hexdump(len=0): [NULL]
nl80211: Could not configure driver mode
nl80211: deinit ifname=wlan0 disabled_11b_rates=0
nl80211: Remove monitor interface: refcount=0
nl80211: Remove beacon (ifindex=18)
netlink: Operstate: ifindex=18 linkmode=0 (kernel-control), operstate=6 (IF_OPER_UP)
nl80211 driver initialization failed.
hostapd_interface_deinit_free(0x557d15b294c0)
hostapd_interface_deinit_free: num_bss=1 conf->num_bss=1
hostapd_interface_deinit(0x557d15b294c0)
wlan0: interface state UNINITIALIZED->DISABLED
hostapd_bss_deinit: deinit bss wlan0
wlan0: AP-DISABLED
hostapd_cleanup(hapd=0x557d15b2a730 (wlan0))
hostapd_free_hapd_data: Interface wlan0 wasn't started
hostapd_interface_deinit_free: driver=(nil) drv_priv=(nil) -> hapd_deinit
hostapd_interface_free(0x557d15b294c0)
hostapd_interface_free: free hapd 0x557d15b2a730
hostapd_cleanup_iface(0x557d15b294c0)
hostapd_cleanup_iface_partial(0x557d15b294c0)
hostapd_cleanup_iface: free iface=0x557d15b294c0
I spent a lot of hours to understand the difference for sending this script directly or by udev but without success for the moment.
I'm working on a fresh "debian buster" install
I install Ubuntu 18.04 with the same scripts and i have the same problems : the script work well in command line but fail when it is launched by udev!
Thanks for your help
First, are you sure the "service NetworkManager stop" actually runs? Lot of problems in "runs manually but not from cron/udev/initscript" is caused by differences in PATH. It's possible "service" is not on path from udev.
Second, is that really command you should be running? On https://bugs.launchpad.net/ubuntu/+source/wpa/+bug/1289047 the following solution is recommended:
nmcli nm wifi off
rfkill unblock wlan
or in case of suspicous path perhaps it would be better to write it as
/usr/bin/nmcli nm wifi off
/usr/sbin/rfkill unblock wlan
I know it is an old question, but I also struggled with this problem and found a workround.
I dont know why hostapd behaves differently when called from udev, however the page
https://wiki.archlinux.org/index.php/udev#Spawning_long-running_processes
gives a solution, yet conceived for a different problem. The idea is to handle the execution of hostapd to a daemon outside udev, in this case the atd. This daemon is in the package 'at' at debian. Once installed, you can call hostapd from the udev script with
echo "/usr/sbin/hostapd -B -P /path/to/pidfile /path/to/hostapd.config" | at now

AVRDude/USBTiny failing to initialize with ATMega2560 using AVR Pocket Programmer

I have a brand new Atmega2560 sitting on a board that I made. I'm trying to use a Sparkfun AVR Pocket Programmer to program the board with USBTiny/AVRdude but when I input avrdude -c usbtiny -p atmega2560 -v -v -v into the CMD for avrdude, I'm getting an error as seen below
avrdude: programmer operation not supported
avrdude: Using SCK period of 10 usec
CMD: [ac 53 00 00] [00 00 00 00]
CMD: [ac 53 00 00] [00 00 00 00]
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
I checked connections and the board is fine. I was able to program it with a friends AVR Pocket Programmer without issue. For some reason, this one isn't working. I programmed another board I have without issue so I don't think it's the pocket programmer. I would use his again, but he's in another state.
Any ideas?
So I ended up triple checking my connections and MOSI wasn't fully connected to the board. Strange.
Suggestions for those who run into this issue in the future:
Check connections. Double check connections. Triple check connections. Make sure the pad from the MCU is touching the pad of the board
Try slowing the speed of the read. ex: avrdude -c usbtiny -p atmega2560 -B 250
Make sure your avrdude is upto date - I'm currently using avrdude version 6.0.1
Make sure your drivers are up to date
From what I've read, with other peoples experiences, is that it is usually number 1 - the connections not being correct.
For others, if you changed your fuses and it stopped responding. You may have 'bricked' your MCU and need the programmer/debugger from AVR to unbrick it.

Peripheral not connecting to iOS

I'm attempting to connect a bluez peripheral to an iOS device; it's not working.
Please find below logs on peripheral side. I'm advertising using hciconfig hci0 leadv but I don't see any "Connect" option on Scanner applications on phone. Also bluez-4.101 doesn't have hciconfig hci0 leadv0 option to make it connectable.
With the same device acting as a Central I am able to make LE connections with other BLE devices, so that confirms kernel LE support and device is fine, only some bluez issues I assume are there.
> HCI Event: LE Meta Event (0x3e) plen 19
LE Connection Complete
status 0x00 handle 1025, role slave
bdaddr 67:5D:F6:87:3D:2C (Random)
> ACL data: handle 1025 flags 0x02 dlen 7
ATT: MTU req (0x02)
client rx mtu 158
> ACL data: handle 1025 flags 0x02 dlen 27
> ACL data: handle 1025 flags 0x01 dlen 27
> ACL data: handle 1025 flags 0x01 dlen 9
L2CAP(d): cid 0x003a len 59 [psm 0]
0000: .9......com.appl
0010: e.BT.TS."....com
0020: .apple.BTLEServe
0030: r.classic..
> ACL data: handle 1025 flags 0x02 dlen 11
L2CAP(d): cid 0x003a len 7 [psm 0]
0000: ......
> HCI Event: Disconn Complete (0x05) plen 4
status 0x00 handle 1025 reason 0x13
Reason: Remote User Terminated Connection
How can I get this peripheral to connect?
Upgrading to the latest BlueZ version will solve the GATT related issues.
Quote from the linked page:
The 2.x , 3.x and 4.x series of libraries and packages are deprecated and not supported anymore by BlueZ developers. If you are using them please update to the 5.x series. The download link is only provided for reference.

how can I use GATT_Notification command with BTool

im using BTool to send commands to CC2540 bluetooth module. I want to get notifications. when I send notification command, btool displayed the sent command
[43] : <Tx> - 11:11:47.051
-Type : 0x01 (Command)
-OpCode : 0xFD9B (GATT_Notification)
-Data Length : 0x06 (6) byte(s)
ConnHandle : 0x0000 (0)
Authentic : 0x00 (0) (No)
Handle : 0x1B00 (6912)
Value : 00:50
Dump(Tx):
0000:01 9B FD 06 00 00 00 1B 00 50
the values of the Handle (temperature characteristic) and connHandle are correct, but I dont get any response from the server. is there any prior configuration to perform, like enabling notifications somewhere?
You need to enable notification for the characteristic. First you need to query for the client characteristic configuration uuid:
08 1B 00 1C 00 02 29
where first byte is the op read request, next two bytes are you handle id, subsequent two bytes are the range limit (handle id + 1), and the last two bytes are the GATT_CLIENT_CHARAC_CFG_UUID filter. You'll get a response similar to this:
09 04 LL HH 00 00
where the first byte is the response (read by type response), next byte is payload length, LL HH is the configuration characteristic handle, and the last two bytes are it's value.
At this step you can enable the notification by writing a 0x0001 to this handle id:
12 LL HH 01 00
At his point the notification for you characteristic should be enabled.

JOGL Native Crash

I am running a JOGL based application, and it has been crashing when I perform certain drawing operations. However, The line it crashes on is a call to gl.glGenLists(1), so I'm not really sure how this could cause an error in the underlying application, since this line is a trivial line (unless the stack is in some sort of bad state - is that possible?).
I also tried updating my video card drivers and now it just freezes in the same place instead of crashing.
The relevant part of the crash report is below. Any help would be appreciated. I'm running an NVIDIA Quadro NVS 160M video card. Thanks.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6dd7ccac, pid=5520, tid=5684
#
# JRE version: 6.0_16-b01
# Java VM: Java HotSpot(TM) Client VM (14.2-b01 mixed mode windows-x86 )
# Problematic frame:
# C [nvoglnt.dll+0x23ccac]
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
--------------- T H R E A D ---------------
Current thread (0x692c4c00): JavaThread "AWT-EventQueue-0" [_thread_in_native, id=5684, stack(0x696f0000,0x69740000)]
siginfo: ExceptionCode=0xc0000005, writing address 0x00040008
Registers:
EAX=0x6d360798, EBX=0x6e562ffc, ECX=0x00040000, EDX=0xffffffff
ESP=0x6973ee1c, EBP=0x0000000d, ESI=0x6d360650, EDI=0x6d362311
EIP=0x6dd7ccac, EFLAGS=0x00010246
Top of Stack: (sp=0x6973ee1c)
0x6973ee1c: 00001343 00000014 00001344 6e563040
0x6973ee2c: 00000000 6d362310 00000040 7ffad000
0x6973ee3c: 6dd7cdb8 6e562ffc 00001343 6e3c7540
0x6973ee4c: 6dc792a8 00000014 6dbdb13b 00000001
0x6973ee5c: 6e3c7540 6d620000 6973ee90 6dc06fb8
0x6973ee6c: 6d620000 6e3c7540 00000001 692c4c00
0x6973ee7c: 63e576a0 63d38030 6b6c4c0e 00000001
0x6973ee8c: 0ab4f368 6973eeb8 010669c7 692c4d10
Instructions: (pc=0x6dd7ccac)
0x6dd7cc9c: 00 8b 4b 08 8b 7b 04 89 79 04 8b 4b 04 8b 7b 08
0x6dd7ccac: 89 79 08 0f 84 8c 00 00 00 8b 4c 24 14 8b 7c d1
Stack: [0x696f0000,0x69740000], sp=0x6973ee1c, free space=315k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [nvoglnt.dll+0x23ccac]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J com.sun.opengl.impl.GLImpl.glGenLists0(I)I
...I omitted the rest of the stack, as this is the offending line ...
Despite the stack it seems to be nvoglnt.dll that is causing the trouble. Have you absolutely definitely installed the correct driver for your graphics device?

Resources