Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Last active January 25, 2020 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gro-Tsen/f40f122507954fb0cd987fa7f8f3e67a to your computer and use it in GitHub Desktop.
Save Gro-Tsen/f40f122507954fb0cd987fa7f8f3e67a to your computer and use it in GitHub Desktop.
ACTION=="add", SUBSYSTEM=="net", ATTRS{idVendor}=="0cf3", ATTRS{idProduct}=="9271", ENV{DMADORE_WIFI_STICK}="1", RUN+="/root/bin/wifi-stick-added-netlevel"
ACTION=="remove", SUBSYSTEM=="net", ENV{DMADORE_WIFI_STICK}=="1", RUN+="/root/bin/wifi-stick-removed-netlevel"
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
Line 55: DEPRECATED: 'dump_file' configuration variable is not used anymore
ctrl_interface_group=0
rfkill: initial event: idx=23 type=1 op=0 soft=0 hard=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:10
nl80211: Supported cipher 00-0f-ac:8
nl80211: Supported cipher 00-0f-ac:9
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: Using driver-based off-channel TX
nl80211: Use separate P2P group interface (driver advertised support)
nl80211: interface wlan0 in phy phy23
nl80211: Set mode ifindex 29 iftype 3 (AP)
nl80211: Failed to set interface 29 to mode 3: -16 (Device or resource busy)
nl80211: Try mode change after setting interface down
nl80211: Set mode ifindex 29 iftype 3 (AP)
nl80211: Mode change succeeded while interface is down
nl80211: Setup AP(wlan0) - device_ap_sme=0 use_monitor=0
nl80211: Subscribe to mgmt frames with AP handle 0x564aed4430e0
nl80211: Register frame type=0xb0 (WLAN_FC_STYPE_AUTH) nl_handle=0x564aed4430e0 match=
nl80211: Register frame type=0x0 (WLAN_FC_STYPE_ASSOC_REQ) nl_handle=0x564aed4430e0 match=
nl80211: Register frame type=0x20 (WLAN_FC_STYPE_REASSOC_REQ) nl_handle=0x564aed4430e0 match=
nl80211: Register frame type=0xa0 (WLAN_FC_STYPE_DISASSOC) nl_handle=0x564aed4430e0 match=
nl80211: Register frame type=0xc0 (WLAN_FC_STYPE_DEAUTH) nl_handle=0x564aed4430e0 match=
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x564aed4430e0 match=
nl80211: Register frame type=0x40 (WLAN_FC_STYPE_PROBE_REQ) nl_handle=0x564aed4430e0 match=
nl80211: deinit ifname=wlan0 disabled_11b_rates=0
nl80211: Remove monitor interface: refcount=0
nl80211: Remove beacon (ifindex=29)
netlink: Operstate: ifindex=29 linkmode=0 (kernel-control), operstate=6 (IF_OPER_UP)
nl80211: Set mode ifindex 29 iftype 2 (STATION)
nl80211: Failed to set interface 29 to mode 2: -16 (Device or resource busy)
nl80211: Try mode change after setting interface down
nl80211: Set mode ifindex 29 iftype 2 (STATION)
nl80211: Mode change succeeded while interface is down
nl80211: Teardown AP(wlan0) - device_ap_sme=0 use_monitor=0
nl80211: Unsubscribe mgmt frames handle 0x8888dec265ccb869 (AP teardown)
nl80211 driver initialization failed.
hostapd_interface_deinit_free(0x564aed444720)
hostapd_interface_deinit_free: num_bss=1 conf->num_bss=1
hostapd_interface_deinit(0x564aed444720)
wlan0: interface state UNINITIALIZED->DISABLED
hostapd_bss_deinit: deinit bss wlan0
wlan0: AP-DISABLED
hostapd_cleanup(hapd=0x564aed445680 (wlan0))
hostapd_free_hapd_data: Interface wlan0 wasn't started
hostapd_interface_deinit_free: driver=(nil) drv_priv=(nil) -> hapd_deinit
hostapd_interface_free(0x564aed444720)
hostapd_interface_free: free hapd 0x564aed445680
hostapd_cleanup_iface(0x564aed444720)
hostapd_cleanup_iface_partial(0x564aed444720)
hostapd_cleanup_iface: free iface=0x564aed444720
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
Line 55: DEPRECATED: 'dump_file' configuration variable is not used anymore
ctrl_interface_group=0
rfkill: initial event: idx=22 type=1 op=0 soft=0 hard=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:10
nl80211: Supported cipher 00-0f-ac:8
nl80211: Supported cipher 00-0f-ac:9
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: Using driver-based off-channel TX
nl80211: Use separate P2P group interface (driver advertised support)
nl80211: interface wlan0 in phy phy22
nl80211: Set mode ifindex 28 iftype 3 (AP)
nl80211: Failed to set interface 28 to mode 3: -16 (Device or resource busy)
nl80211: Try mode change after setting interface down
nl80211: Set mode ifindex 28 iftype 3 (AP)
nl80211: Mode change succeeded while interface is down
nl80211: Setup AP(wlan0) - device_ap_sme=0 use_monitor=0
nl80211: Subscribe to mgmt frames with AP handle 0x5561541b10e0
nl80211: Register frame type=0xb0 (WLAN_FC_STYPE_AUTH) nl_handle=0x5561541b10e0 match=
nl80211: Register frame type=0x0 (WLAN_FC_STYPE_ASSOC_REQ) nl_handle=0x5561541b10e0 match=
nl80211: Register frame type=0x20 (WLAN_FC_STYPE_REASSOC_REQ) nl_handle=0x5561541b10e0 match=
nl80211: Register frame type=0xa0 (WLAN_FC_STYPE_DISASSOC) nl_handle=0x5561541b10e0 match=
nl80211: Register frame type=0xc0 (WLAN_FC_STYPE_DEAUTH) nl_handle=0x5561541b10e0 match=
nl80211: Register frame type=0xd0 (WLAN_FC_STYPE_ACTION) nl_handle=0x5561541b10e0 match=
nl80211: Register frame type=0x40 (WLAN_FC_STYPE_PROBE_REQ) nl_handle=0x5561541b10e0 match=
nl80211: Add own interface ifindex 5
nl80211: if_indices[16]: 5
nl80211: Add own interface ifindex 28
nl80211: if_indices[16]: 5 28
nl80211: Adding interface wlan0 into bridge br0
phy: phy22
BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)
wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
Previous country code 98, new country code FR
Continue interface setup after channel list update
ctrl_iface not configured!
interface=wlan0
bridge=br0
driver=nl80211
logger_syslog=-1
logger_syslog_level=3
logger_stdout=-1
logger_stdout_level=3
dump_file=/tmp/hostapd.dump
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
ssid=Madore
country_code=FR
hw_mode=g
channel=1
beacon_int=250
dtim_period=3
max_num_sta=30
rts_threshold=2347
fragm_threshold=2346
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wmm_enabled=1
wmm_ac_bk_cwmin=4
wmm_ac_bk_cwmax=10
wmm_ac_bk_aifs=7
wmm_ac_bk_txop_limit=0
wmm_ac_bk_acm=0
wmm_ac_be_aifs=3
wmm_ac_be_cwmin=4
wmm_ac_be_cwmax=10
wmm_ac_be_txop_limit=0
wmm_ac_be_acm=0
wmm_ac_vi_aifs=2
wmm_ac_vi_cwmin=3
wmm_ac_vi_cwmax=4
wmm_ac_vi_txop_limit=94
wmm_ac_vi_acm=0
wmm_ac_vo_aifs=2
wmm_ac_vo_cwmin=2
wmm_ac_vo_cwmax=3
wmm_ac_vo_txop_limit=47
wmm_ac_vo_acm=0
ap_max_inactivity=600
ieee80211n=1
ht_capab=[HT40+][SHORT-GI-20][SHORT-GI-40]
eapol_key_index_workaround=0
eap_server=0
wpa=3
wpa_passphrase=REDACTED
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
wpa_group_rekey=10800
wpa_gmk_rekey=86400
ID_BUS=usb
ACTION=add
ID_VENDOR_FROM_DATABASE=Qualcomm Atheros Communications
ID_NET_DRIVER=ath9k_htc
SEQNUM=4879
USEC_INITIALIZED=68182946939
ID_SERIAL_SHORT=12345
ID_USB_DRIVER=ath9k_htc
TAGS=:systemd:
IFINDEX=36
ID_TYPE=generic
ID_USB_CLASS_FROM_DATABASE=Vendor Specific Class
ID_USB_SUBCLASS_FROM_DATABASE=Vendor Specific Subclass
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/net/wlan0
ID_OUI_FROM_DATABASE=TP-LINK TECHNOLOGIES CO.,LTD.
DMADORE_WIFI_STICK=1
ID_MODEL_ENC=USB2.0\x20WLAN
ID_USB_INTERFACES=:ff0000:
ID_MODEL=USB2.0_WLAN
SUBSYSTEM=net
ID_SERIAL=ATHEROS_USB2.0_WLAN_12345
ID_MODEL_ID=9271
ID_NET_NAME_MAC=wlxc04a001e4cd4
ID_MODEL_FROM_DATABASE=AR9271 802.11n
ID_PATH=pci-0000:00:14.0-usb-0:4:1.0
ID_USB_PROTOCOL_FROM_DATABASE=Vendor Specific Protocol
ID_VENDOR_ENC=ATHEROS
ID_NET_NAME=wlp0s20f0u4
INTERFACE=wlan0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_4_1_0
ID_VENDOR=ATHEROS
PWD=/
DEVTYPE=wlan
ID_USB_INTERFACE_NUM=00
ID_VENDOR_ID=0cf3
ID_NET_NAME_PATH=wlp0s20f0u4
ID_NET_LINK_FILE=/lib/systemd/network/99-default.link
SYSTEMD_ALIAS=/sys/subsystem/net/devices/wlan0
ID_REVISION=0108
hostapd fails when run from udev, works fine when started manually: WHY???
/etc/udev/rules.d/99-wifi-stick.rules runs /root/bin/wifi-stick-added-netlevel when wlan0 interface appears:
this script is run as expected, the interface is present, but hostapd produces the output in hostapd-debug-bad.log and exits
Manually running `/usr/sbin/hostapd -dd -B -P "/run/hostapd.wlan0.pid" /etc/hostapd/hostapd.conf`, OTOH, works,
and produces the output in hostapd-debug-good.log (and hostapd continues running).
#! /bin/sh
logger -p local0.notice -- "Wifi stick added (network-level script, simplified script, just starting hostapd)"
ip link set dev wlan0 up
iw reg set fr
(sleep 5 ; /usr/sbin/hostapd -dd -B -P "/run/hostapd.wlan0.pid" /etc/hostapd/hostapd.conf > /tmp/hostapd-debug.log 2>&1) &
exit 0
#! /bin/sh
if [ -e "/run/hostapd.wlan0.pid" ]; then
logger -p local0.notice -- "Wifi stick removed (network-level simplified script, just killing hostapd)"
kill $(cat "/run/hostapd.wlan0.pid")
else
logger -p local0.notice -- "Wifi stick removed (network-level simplified script, nothing to kill)"
fi
exit 0
@Gro-Tsen
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment