Skip to content

Commit 3aee420

Browse files
committed
wifi-scripts: add modular wps button handler scripts
Execute scripts in /etc/rc.wps until one of them returns a exit code of 0. Split up sta and ap handling of wps into separate scripts. Signed-off-by: Felix Fietkau <[email protected]>
1 parent 8eea855 commit 3aee420

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
[ "$ACTION" = "pressed" ] && exit 5
3+
for script in /etc/rc.wps/*; do
4+
[ -x "$script" ] || continue
5+
"$script" && break
6+
done
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
[ "$SEEN" -ge 3 ] && exit 1
4+
wps_done=0
5+
ubusobjs="$( ubus -S list hostapd.* )"
6+
for ubusobj in $ubusobjs; do
7+
ubus -S call $ubusobj wps_start && wps_done=1
8+
done
9+
[ $wps_done = 1 ]
10+

package/network/services/hostapd/files/wps-hotplug.sh renamed to package/network/config/wifi-scripts/files/etc/rc.wps/50-wps_sta

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/sh
2+
[ "$SEEN" -lt 3 ] && exit 1
3+
[ "$ACTION" = "released" ] || exit 1
24

35
wps_catch_credentials() {
46
local iface ifaces ifc ifname ssid encryption key radio radios
@@ -38,32 +40,18 @@ wps_catch_credentials() {
3840
done
3941
}
4042

41-
if [ "$ACTION" = "released" ] && [ "$BUTTON" = "wps" ]; then
42-
# If the button was pressed for 3 seconds or more, trigger WPS on
43-
# wpa_supplicant only, no matter if hostapd is running or not. If
44-
# was pressed for less than 3 seconds, try triggering on
45-
# hostapd. If there is no hostapd instance to trigger it on or WPS
46-
# is not enabled on them, trigger it on wpa_supplicant.
47-
if [ "$SEEN" -lt 3 ] ; then
48-
wps_done=0
49-
ubusobjs="$( ubus -S list hostapd.* )"
50-
for ubusobj in $ubusobjs; do
51-
ubus -S call $ubusobj wps_start && wps_done=1
52-
done
53-
[ $wps_done = 0 ] || return 0
43+
wps_done=0
44+
ubusobjs="$( ubus -S list wpa_supplicant.* )"
45+
for ubusobj in $ubusobjs; do
46+
ifname="$(echo $ubusobj | cut -d'.' -f2 )"
47+
multi_ap=""
48+
if [ -e "/var/run/wpa_supplicant-${ifname}.conf.is_multiap" ]; then
49+
ubus -S call $ubusobj wps_start '{ "multi_ap": true }' && wps_done=1
50+
else
51+
ubus -S call $ubusobj wps_start && wps_done=1
5452
fi
55-
wps_done=0
56-
ubusobjs="$( ubus -S list wpa_supplicant.* )"
57-
for ubusobj in $ubusobjs; do
58-
ifname="$(echo $ubusobj | cut -d'.' -f2 )"
59-
multi_ap=""
60-
if [ -e "/var/run/wpa_supplicant-${ifname}.conf.is_multiap" ]; then
61-
ubus -S call $ubusobj wps_start '{ "multi_ap": true }' && wps_done=1
62-
else
63-
ubus -S call $ubusobj wps_start && wps_done=1
64-
fi
65-
done
66-
[ $wps_done = 0 ] || wps_catch_credentials &
67-
fi
53+
done
54+
[ $wps_done = 0 ] && exit 1
6855

69-
return 0
56+
wps_catch_credentials &
57+
exit 0

package/network/services/hostapd/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,14 +726,12 @@ endef
726726
define Package/hostapd-common/install
727727
$(INSTALL_DIR) \
728728
$(1)/etc/capabilities \
729-
$(1)/etc/rc.button \
730729
$(1)/etc/hotplug.d/ieee80211 \
731730
$(1)/etc/init.d $(1)/lib/netifd \
732731
$(1)/usr/share/acl.d \
733732
$(1)/usr/share/hostap
734733
$(INSTALL_BIN) ./files/dhcp-get-server.sh $(1)/lib/netifd/dhcp-get-server.sh
735734
$(INSTALL_BIN) ./files/wpad.init $(1)/etc/init.d/wpad
736-
$(INSTALL_BIN) ./files/wps-hotplug.sh $(1)/etc/rc.button/wps
737735
$(INSTALL_DATA) ./files/wpad_acl.json $(1)/usr/share/acl.d
738736
$(INSTALL_DATA) ./files/wpad.json $(1)/etc/capabilities
739737
endef

0 commit comments

Comments
 (0)