Hostapd doesn't launch with udev - 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

Related

BLE: WriteValue of GattCharacteristic doesn't get called

I followed the tutorial from The Bluetooth Technology for Linux Developers Study Guide (I skipped the 5th guide because I'm doing a gatt server), and everything worked fine until I got to Handling Characteristic Writes.
(Also, I am using a Raspberry PI 4 Model B)
In nRF Connect I have the following in the logs:
Writing request to characteristic e95d93ee-251d-470a-a062-fa1922dfa9a8
Data written to e95d93ee-251d-470a-a062-fa1922dfa9a8, value: (0x)68-65-6C-6C-6F, "hello"
"hello" sent
so the data should have been sent.
sudo btmon gives the following:
> ACL Data RX: Handle 64 flags 0x02 dlen 14 #129 [hci0] 82.584227
ATT: Prepare Write Request (0x16) len 9
Handle: 0x0019
Offset: 0x0000
Data: 68656c6c6f
< ACL Data TX: Handle 64 flags 0x00 dlen 14 #130 [hci0] 82.585053
ATT: Prepare Write Response (0x17) len 9
Handle: 0x0019
Offset: 0x0000
Data: 68656c6c6f
> HCI Event: Number of Completed Packets (0x13) plen 5 #131 [hci0] 82.814773
Num handles: 1
Handle: 64
Count: 1
so the data was indeed received. Though I don't understand why it says Prepare Write Request instead of just Write Request.
bluetoothd with -nd flag and tail -f /var/log/syslog gives the following:
Jul 28 09:20:45 raspberrypi bluetoothd[820]: bluetoothd[820]: src/device.c:gatt_debug() (chan 0x1bb9dd0) ATT PDU received: 0x16
Jul 28 09:20:45 raspberrypi bluetoothd[820]: bluetoothd[820]: src/device.c:gatt_debug() Prep Write Req - handle: 0x0019
Jul 28 09:20:45 raspberrypi bluetoothd[820]: src/device.c:gatt_debug() (chan 0x1bb9dd0) ATT PDU received: 0x16
Jul 28 09:20:45 raspberrypi bluetoothd[820]: src/device.c:gatt_debug() Prep Write Req - handle: 0x0019
but there is no reaction using sudo dbus-monitor --system, and nothing either in the program output terminal.
Do you have any Idea where the problem might come from?
(I tried reinstalling nRF Connect twice already, so I think the problem is from somewhere in the Raspberry, but is it from bluez? from dbus? or somewhere else?)
After reinstalling bluez, and not solving anything, I tried with an old samsung tablet, and it works. So it appears my assumption was wrong and the problem could be from my phone.

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

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

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.

Raspberry Pi sim900 Default Internet Access

I have set up a ITEAD sim900 GSM module to interface with raspberry pi. I believe I have established a gprs connection to AT&T though wvdial as I get these results.
--> WvDial: Internet dialer version 1.61
--> Initializing modem.
--> Sending: AT+CGDCONT=1,"IP","Broadband"
AT+CGDCONT=1,"IP","Broadband"
OK
--> Modem initialized.
--> Sending: ATDT*99#
--> Waiting for carrier.
ATDT*99#
CONNECT
--> Carrier detected. Starting PPP immediately.
--> Starting pppd at Thu Aug 14 05:49:20 2014
--> Pid of pppd: 2794
I have been looking all over the internet for some answers to a few questions that I have, but I can't seem to find any. Any help with the following questions will be greatly appreciated! Thanks!
I have three questions, and some may be stupid as I am VERY new to this field.
Am I actually connected to AT&T's GPRS network?
How can I make this module (serial port /dev/ttyAMA0) my default internet connection? What I mean is I want all internet traffic routed through this modem(web surfing, email etc.). I am connected to the Raspberry via ssh so I have to have either ethernet or wifi active to access the computer--I am currently using ethernet. After I connect through wvdial in the way shown above, and disable all other internet sources I have no access. It seems to still be looking to the active ethernet port for data(I could be wrong).
For my project I need to have the sim900 modem as the internet access point, but I also need to be able to connect to a LAN via wifi that has no internet access. Is this possible?
Finally i got the ( raspberrypi + ppp + gprs/gsm-modem ) working.
Some notes before start:
Make sure the power supply you used for raspberrypi is exact 5V and it can provide at-least 2A current without voltage drop-out.The SIM900 power-source must be 3.3V 2A
Set the SIM900 baud rate to 115200 via: AT+IPR=115200
Check the modem serial peripheral via: $ screen /dev/ttyAMA0 115200 type AT<enter> it will echo: OK. Hit ctrl+a k y to exit.
/etc/ppp/options-mobile
ttyAMA0
115200
lock
crtscts
modem
passive
novj
defaultroute
replacedefaultroute
noipdefault
usepeerdns
noauth
hide-password
persist
holdoff 10
maxfail 0
debug
Create the /etc/ppp/peers directory:
$ mkdir /etc/ppp/peers
$ cd /etc/ppp/peers
/etc/ppp/peers/mobile-auth
file /etc/ppp/options-mobile
user "your_usr"
password "your_pass"
connect "/usr/sbin/chat -v -t15 -f /etc/ppp/chatscripts/mobile-modem.chat"
/etc/ppp/peers/mobile-noauth
file /etc/ppp/options-mobile
connect "/usr/sbin/chat -v -t15 -f /etc/ppp/chatscripts/mobile-modem.chat"
Create the /etc/ppp/chatscripts directory:
$ mkdir /etc/ppp/chatscripts
/etc/ppp/chatscripts/mobile-modem.chat
ABORT 'BUSY'
ABORT 'NO CARRIER'
ABORT 'VOICE'
ABORT 'NO DIALTONE'
ABORT 'NO DIAL TONE'
ABORT 'NO ANSWER'
ABORT 'DELAYED'
REPORT CONNECT
TIMEOUT 6
'' 'ATQ0'
'OK-AT-OK' 'ATZ'
TIMEOUT 3
'OK' #/etc/ppp/chatscripts/pin
'OK\d-AT-OK' 'ATI'
'OK' 'ATZ'
'OK' 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0'
'OK' #/etc/ppp/chatscripts/mode
'OK-AT-OK' #/etc/ppp/chatscripts/apn
'OK' 'ATDT*99***1#'
TIMEOUT 30
CONNECT ''
/etc/ppp/chatscripts/my-operator-apn
AT+CGDCONT=1,"IP","<apn-name>"
/etc/ppp/chatscripts/pin.CODE
AT+CPIN=1234
/etc/ppp/chatscripts/pin.NONE
AT
/etc/ppp/chatscripts/mode.3G-only
AT\^SYSCFG=14,2,3fffffff,0,1
/etc/ppp/chatscripts/mode.3G-pref
AT\^SYSCFG=2,2,3fffffff,0,1
/etc/ppp/chatscripts/mode.GPRS-only
AT\^SYSCFG=13,1,3fffffff,0,0
/etc/ppp/chatscripts/mode.GPRS-pref
AT\^SYSCFG=2,1,3fffffff,0,0
The SYSCFG line in the mode.* files is device-dependent, and likely Huawei-specific, So You may use the mode.NONE file if your modem is
SIM900.
*
/etc/ppp/chatscripts/mode.NONE
AT
Make some symbolic links:
$ ln -s /etc/ppp/chatscripts/my-operator-apn /etc/ppp/chatscripts/apn
$ ln -s /etc/ppp/chatscripts/mode.NONE /etc/ppp/chatscripts/mode
$ ln -s /etc/ppp/chatscripts/pin.NONE /etc/ppp/chatscripts/pin
If you have to enter credentials use mobile-auth
$ mv provider provider.example
$ ln -s /etc/ppp/peers/mobile-noauth /etc/ppp/peers/provider
Check syslog in another console:
$ tail -f /var/log/syslog | grep -Ei 'pppd|chat'
Finally issue the pon command to see the result:
$ pon
The base instruction : https://wiki.archlinux.org/index.php/3G_and_GPRS_modems_with_pppd

Resources