2013-03-13 18:11:25 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2018-11-22 19:53:09 +00:00
|
|
|
wps_catch_credentials() {
|
|
|
|
local iface ifaces ifc ifname ssid encryption key radio radios
|
|
|
|
local found=0
|
|
|
|
|
|
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
ubus -S -t 30 listen wps_credentials | while read creds; do
|
|
|
|
json_init
|
|
|
|
json_load "$creds"
|
|
|
|
json_select wps_credentials || continue
|
|
|
|
json_get_vars ifname ssid key encryption
|
|
|
|
local ifcname="$ifname"
|
|
|
|
json_init
|
|
|
|
json_load "$(ubus -S call network.wireless status)"
|
|
|
|
json_get_keys radios
|
|
|
|
for radio in $radios; do
|
|
|
|
json_select $radio
|
|
|
|
json_select interfaces
|
|
|
|
json_get_keys ifaces
|
|
|
|
for ifc in $ifaces; do
|
|
|
|
json_select $ifc
|
|
|
|
json_get_vars ifname
|
|
|
|
[ "$ifname" = "$ifcname" ] && {
|
|
|
|
ubus -S call uci set "{\"config\":\"wireless\", \"type\":\"wifi-iface\", \
|
|
|
|
\"match\": { \"device\": \"$radio\", \"encryption\": \"wps\" }, \
|
|
|
|
\"values\": { \"encryption\": \"$encryption\", \
|
|
|
|
\"ssid\": \"$ssid\", \
|
|
|
|
\"key\": \"$key\" } }"
|
|
|
|
ubus -S call uci commit '{"config": "wireless"}'
|
|
|
|
ubus -S call uci apply
|
|
|
|
}
|
|
|
|
json_select ..
|
|
|
|
done
|
|
|
|
json_select ..
|
|
|
|
json_select ..
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
hostapd: add fallback for WPS on stations
Up to now the WPS script triggered WPS on the stations only if it
could not trigger it successfully on any hostapd instance.
In a Multi-AP context, there can be a need (to establish a new
wireless backhaul link) to trigger WPS on the stations, regardless of
whether there is already a hostapd instance configured or not. The
current script makes it impossible, as if hostapd is running and
configured, WPS would always be triggered on hostapd only.
To allow both possibilities, the following changes are made:
- Change the "pressed" action to "release", so that we can make use of
the "$SEEN" variables (to know for how long the button was pressed).
- If the button is pressed for less than 3 seconds, keep the original
behavior.
- If the button is pressed for 3 seconds or more, trigger WPS on the
stations, regardless of the status of any running hostapd instance.
- Add comments explaining both behaviors.
- While at it, replace the usage of '-a' with a '[] && []'
construct (see [1]).
This gives users a "fallback" mechanism to onboard a device to a
Multi-AP network, even if the device already has a configured hostapd
instance running.
[1]: https://github.com/koalaman/shellcheck/wiki/SC2166
Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
2021-10-29 08:45:06 +00:00
|
|
|
if [ "$ACTION" = "released" ] && [ "$BUTTON" = "wps" ]; then
|
|
|
|
# If the button was pressed for 3 seconds or more, trigger WPS on
|
|
|
|
# wpa_supplicant only, no matter if hostapd is running or not. If
|
|
|
|
# was pressed for less than 3 seconds, try triggering on
|
|
|
|
# hostapd. If there is no hostapd instance to trigger it on or WPS
|
|
|
|
# is not enabled on them, trigger it on wpa_supplicant.
|
|
|
|
if [ "$SEEN" -lt 3 ] ; then
|
|
|
|
wps_done=0
|
|
|
|
ubusobjs="$( ubus -S list hostapd.* )"
|
|
|
|
for ubusobj in $ubusobjs; do
|
|
|
|
ubus -S call $ubusobj wps_start && wps_done=1
|
|
|
|
done
|
|
|
|
[ $wps_done = 0 ] || return 0
|
|
|
|
fi
|
2018-11-22 19:53:09 +00:00
|
|
|
wps_done=0
|
|
|
|
ubusobjs="$( ubus -S list wpa_supplicant.* )"
|
|
|
|
for ubusobj in $ubusobjs; do
|
2018-12-10 16:02:27 +00:00
|
|
|
ifname="$(echo $ubusobj | cut -d'.' -f2 )"
|
|
|
|
multi_ap=""
|
|
|
|
if [ -e "/var/run/wpa_supplicant-${ifname}.conf.is_multiap" ]; then
|
|
|
|
ubus -S call $ubusobj wps_start '{ "multi_ap": true }' && wps_done=1
|
|
|
|
else
|
|
|
|
ubus -S call $ubusobj wps_start && wps_done=1
|
|
|
|
fi
|
2010-07-08 18:36:17 +00:00
|
|
|
done
|
2018-11-22 19:53:09 +00:00
|
|
|
[ $wps_done = 0 ] || wps_catch_credentials &
|
2010-07-08 18:36:17 +00:00
|
|
|
fi
|
2015-07-24 09:11:35 +00:00
|
|
|
|
|
|
|
return 0
|