You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

212 lines
6.0 KiB
Bash

#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
send_to_son()
{
local staname1
local staname2
local ret
local pattern
local count
[ -r /var/run/son.conf ] || return 0
staname1=$(grep sta /var/run/son.conf | head -n 1 | cut -f3 -d" " )
staname2=$(grep sta /var/run/son.conf | tail -n 1 | cut -f3 -d" " )
echo "$staname1 $staname2"
count=0
pattern="Not-Associated"
for sta in $staname1 $staname2;do
result=$(iwconfig $sta | head -2 | tail -1 | grep -o "Not-Associated")
if [ $result == $pattern ];then
count=$((count+1))
fi
done
if [ $count -lt 2 ];then
echo "Sending to son"
echo "wps_pbc $SEEN" > /var/run/sonwps.pipe &
touch /var/run/son_active
ret=1
else
ret=0
echo "Son not processing push - sta not connected"
fi
return $ret
}
check_options()
{ (
count=0
breakup=0
json_init
get_section() {
[ "$(config_get $1 ifname)" = "$2" ] && echo $1
}
config_load wireless
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
for vap_dir in $dir/ath* $dir/wlan*; do
[ -r "$vap_dir" ] || continue
localbreakup=0
name=$(config_foreach get_section wifi-iface "$(basename "$vap_dir")")
json_add_object "$name"
hidden="$(config_get "$name" hidden)"
enabled="$(config_get "$name" wps_config)"
encrypted="$(config_get "$name" encryption)"
if [ -z "$enabled" ]; then
json_add_string "enabled" "failed"
localbreakup=1
else
json_add_string "enabled" "ok"
fi
if [ "$hidden" -eq 1 ]; then
json_add_string "hidden" "failed"
localbreakup=1
else
json_add_string "hidden" "ok"
fi
if [ "$encrypted" = "none" ]; then
json_add_string "encrypted" "failed"
localbreakup=1
else
json_add_string "encrypted" "ok"
fi
count=$(expr $count + 1)
if [ $localbreakup -eq 1 ]; then
json_add_string "status" "failed"
breakup=$(expr $breakup + 1)
else
json_add_string "status" "ok"
fi
json_close_object
done
done
if [ $breakup -eq $count ]; then
json_add_string "status" "failed"
breakup=1
else
json_add_string "status" "ok"
breakup=0
fi
json_dump
return $breakup
) }
start_wps_pbc()
{
local retval breakup dir vap_dir
retval="$(check_options)"
breakup=$?
json_load "$retval"
if [ $breakup -eq 0 ]; then
# cleanup old file
rm -f /var/run/son_active
#check for son.conf - if not there exit
# ret is 1 if push is consumed by son , if ret == 0 continue to next scripts
send_to_son
ret=$?
[ $ret -eq 1 ] && exit 0
# Son did not process the push call wps-extender if confgured
[ -r /var/run/wifi-wps-enhc-extn.conf ] && exit 0
# son and wps_extender are not processing the push
json_add_object "WPS_state"
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
for vap_dir in $dir/ath* $dir/wlan*; do
[ -r "$vap_dir" ] || continue
nopbn=`iwpriv "${vap_dir#"$dir/"}" get_nopbn | cut -d':' -f2`
if [ $nopbn != 1 ]; then
retval=$(hostapd_cli -i "${vap_dir#"$dir/"}" -p "$dir" wps_pbc)
json_add_string "${vap_dir#"$dir/"}" "$retval"
fi
done
done
json_close_object
fi
/usr/sbin/updateled.sh > /dev/null 2>/dev/null </dev/null &
json_dump
}
start_wps_pin()
{
local retval breakup dir vap_dir
retval="$(check_options)"
breakup=$?
json_load "$retval"
if [ $breakup -eq 0 ]; then
local pin=$1
json_add_object "WPS_state"
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
for vap_dir in $dir/ath* $dir/wlan*; do
[ -r "$vap_dir" ] || continue
retval=$(hostapd_cli -i "${vap_dir#"$dir/"}" -p "$dir" wps_pin any $pin)
json_add_string "${vap_dir#"$dir/"}" "$retval"
done
done
json_close_object
fi
/usr/sbin/updateled.sh > /dev/null 2>/dev/null </dev/null &
json_dump
}
get_wps_status()
{
local status
status=""
json_init
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
for vap_dir in $dir/ath* $dir/wlan*; do
[ -r "$vap_dir" ] || continue
retval=$(hostapd_cli -i "${vap_dir#"$dir/"}" -p "$dir" wps_get_status | grep "PBC Status:")
temp1="${retval#PBC Status: }"
status="${temp1%% *}"
json_add_string "${vap_dir#"$dir/"}" "$status"
done
done
json_dump
}
get_wps_pin_status()
{
local status
status=""
json_init
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
for vap_dir in $dir/ath* $dir/wlan*; do
[ -r "$vap_dir" ] || continue
if [ ${vap_dir#"$dir/"} = $device ]; then
retval=$(hostapd_cli -i "${vap_dir#"$dir/"}" -p "$dir" wps_get_pin_status)
json_add_string "${vap_dir#"$dir/"}" "$retval"
fi
done
done
json_dump
}
get_interface_state()
{
json_init
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
for vap_dir in $dir/ath* $dir/wlan*; do
[ -r "$vap_dir" ] || continue
retval=$(hostapd_cli -i "${vap_dir#"$dir/"}" -p "$dir" interface_state)
json_add_string "${vap_dir#"$dir/"}" "$retval"
done
done
json_dump
}