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.

102 lines
2.8 KiB
Bash

#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/config/uci.sh
# get all enabled radio names to start clone on
get_radios_for_wps_clone()
{
local radio
for radio in wifi0 wifi1; do
[ -n "$(uci_get wireless $radio)" ] && [ $(uci_get wireless $radio disabled 0) -eq 0 ] && echo $radio
done
}
start_wps_clone()
{
local global_pid="/var/run/wpa_supplicant-global.pid"
local global_ctrl="/var/run/wpa_supplicantglobal"
local radio=''
json_init
uci_get_state wireless wps_clone > /dev/null || uci_set_state wireless wps_clone "" wps_clone
if [ "$(uci_get_state wireless wps_clone state)" != "running" ]; then
local radios=$(get_radios_for_wps_clone)
if [ -z "$radios" ]; then
json_add_string "status" "failed: no radio activated"
json_dump
return 1
fi
local uuid="87654321-9abc-def0-1234-$(tr -d : < /sys/class/net/eth0/address)"
for radio in $radios; do
local interface=
# note: adding the same json_property again overrides the former
case "$radio" in
wifi0)
interface=athClone0
json_add_string "status" "Ok"
json_add_string "frequency" "2.4G"
;;
wifi1)
interface=athClone1
json_add_string "status" "Ok"
json_add_string "frequency" "5G"
;;
*)
json_add_string "status" "Failed: no radio activated"
json_add_string "reason" "No radio activated"
json_dump
return 1
;;
esac
interface=$(wlanconfig $interface create wlandev $radio wlanmode sta)
local ctrl_socket="/var/run/wpa_supplicant-$interface"
cat > /var/run/wpa_supplicant-$interface.conf <<EOF
ctrl_interface=/var/run/wpa_supplicant-$interface
config_methods=display virtual_display push_button virtual_push_button physical_push_button
wps_cred_processing=2
update_config=1
uuid=$uuid
network={
scan_ssid=1
key_mgmt=WPA-PSK
proto=RSN
pairwise=CCMP
group=CCMP TKIP
}
EOF
wpa_cli -g $global_ctrl interface_add $interface /var/run/wpa_supplicant-$interface.conf athr /var/run/wpa_supplicant-$interface \"\" br-lan > /dev/null
touch /var/run/wpa_supplicant-$interface.lock
wpa_cli -i $interface -p $ctrl_socket wps_pbc > /dev/null
wpa_cli -p $ctrl_socket -a /usr/libexec/delos/delos-clone-mode-uci -P /var/run/wpa_supplicant-$interface.pid -B > /dev/null
done
/usr/sbin/updateled.sh > /dev/null 2>/dev/null </dev/null &
# use toggle here to cleanup former state history completely when new run starts
uci_toggle_state wireless wps_clone state running
else
for ifpath in $(ls -d /sys/class/net/athClone? 2>/dev/null); do
local radio=$(cat $ifpath/parent)
local interface=$(basename $ifpath)
local ctrl_socket="/var/run/wpa_supplicant-$interface"
wpa_cli -i $interface -p $ctrl_socket > /dev/null
json_add_string status "restarted"
case $radio in
wifi0)
json_add_string frequency "2.4G"
;;
wifi1)
json_add_string frequency "5G"
;;
esac
done
fi
json_dump
}