[RFC 3/3] Load Wifi Settings
Christian Dresel
fff at chrisi01.de
So Aug 20 10:29:39 CEST 2017
If we have internet we connect directly to the keyxchangev2 and load
the settings
if we haven't internet we try to connect to a hidden AP as station and
load the settings from the keyxchangev2
after set the new wireless settings we copy back the 60-fff-wireless
uci default and reboot the node
Signed-off-by: Christian Dresel <fff at chrisi01.de>
---
.../fff/fff-vpn-select/files/usr/sbin/vpn-select | 83 +++++++++++++++++++++-
.../fff-wireless/files/lib/functions/fff/wireless | 31 ++++++++
2 files changed, 112 insertions(+), 2 deletions(-)
diff --git a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
index c3d003f..e0904d6 100755
--- a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
+++ b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
@@ -1,7 +1,41 @@
#!/bin/sh
+. /lib/functions/fff/wireless
+
test -f /tmp/started || exit
+set_wifi() {
+wget -T15 "http://keyserver.freifunk-franken.de/${project}/wireless.php?mac=$mac" -O /tmp/wireless_${project}_output
+$NEWSETTINGS=$(cat /tmp/wireless_${project}_output)
+#check the settings the same as set if not set it new and reboot the Node if it the same do nothing
+#we get the settings in this format from keyxchangev2: ESSID_AP;ESSID_MESH;BSSID_MESH
+ESSID_AP_AKT=$(cat /etc/community.cfg | grep ESSID_AP | cut -d "=" -f 2)
+ESSID_MESH_AKT=$(cat /etc/community.cfg | grep ESSID_MESH | cut -d "=" -f 2)
+BSSID_MESH_AKT=$(cat /etc/community.cfg | grep BSSID_MESH | cut -d "=" -f 2)
+CHECKSAME="$ESSID_AP_AKT;$ESSID_MESH_AKT;$BSSID_MESH_AKT"
+if [ "$CHECKSAME" == "$NEWSETTINGS" ]; then
+ echo "We have same settings and do nothing"
+else
+ #here we must write the config file new and reboot after
+ ESSID_AP_NEW=$(cat /tmp/wireless_${project}_output | cut -d ";" -f 0)
+ ESSID_MESH_NEW=$(cat /tmp/wireless_${project}_output | cut -d ";" -f 1)
+ BSSID_MESH_NEW=$(cat /tmp/wireless_${project}_output | cut -d ";" -f 2)
+ rm /etc/community.cfg
+ touch /etc/community.cfg
+ echo 'BATMAN_CHANNEL=1' >> /etc/community.cfg
+ echo 'BATMAN_CHANNEL_5GHZ=36' >> /etc/community.cfg
+ echo 'ESSID_AP=$ESSID_AP_NEW' >> /etc/community.cfg
+ echo 'ESSID_MESH=$ESSID_MESH_NEW' >> /etc/community.cfg
+ echo 'BSSID_MESH=$BSSID_MESH_NEW' >> /etc/community.cfg
+ echo 'VPN_PROJECT=fff' >> /etc/community.cfg
+ echo 'NTPD_IP=fe80::ff:feee:1%br-mesh' >> /etc/community.cfg
+ echo 'UPGRADE_PATH=http://[fe80::ff:feee:1%br-mesh]/dev/firmware/current' >> /etc/community.cfg
+ #and now reboot the Router to set the new settings
+ cp /rom/etc/uci-defaults/60-fff-wireless /etc/uci-defaults/60-fff-wireless
+ reboot
+fi
+}
+
make_config() {
# remove old config
>/etc/config/tunneldigger
@@ -35,6 +69,8 @@ for file in $filecounts; do
rm /etc/fastd/${project}/peers/$file
fi
done
+#now we load the wireless Information from the keyxchangev2:
+set_wifi
}
# main
@@ -43,9 +79,10 @@ test_ipv4_host2="8.8.8.8" # Google DNS
test_ipv6_host1="heise.de" # heise Zeitschriftenverlag
# Only do something when the router has internet connection
-if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
+if (ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
- ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
+ ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null) &&
+ [ $(cat /tmp/novpn) != "1" ]; then
# set some vars
. /etc/community.cfg
@@ -86,4 +123,46 @@ if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
fi
fi
+else
+ # now we check to have Batmangateways in range
+ if [ "$(batctl gwl | grep "no gateway")" ]; then
+ #now we haven't a gateway in Range, we search for a hidden AP to get Internet and reach the KeyXchangev2
+ #set this to not open a vpn because we have in the next step Internet
+ echo "1" > /tmp/novpn
+ #first we delete all wifi settings
+ if ! wifiDelAll; then
+ echo "Can't delete current wifi setup"
+ exit 1
+ fi
+ #now we look for phy and add this
+ for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
+ if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
+ echo "$phy is 2.4 GHz"
+ radio=$(wifiAddPhy "$phy" "$BATMAN_CHANNEL")
+ if [ -z "$radio" ]; then
+ echo "Can't create radio for $phy"
+ exit 1
+ fi
+ fi
+ if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
+ echo "$phy is 5 GHz"
+ radio=$(wifiAddPhy "$phy" "$BATMAN_CHANNEL_5GHZ")
+ if [ -z "$radio" ]; then
+ echo "Can't create radio for $phy"
+ exit 1
+ fi
+ fi
+ #and here we add the station
+ if ! wifiAddSta "$radio" "$ESSID_AP"; then
+ echo "Can't add Sta interface on $radio."
+ exit 1
+ fi
+ done
+ #and here we can check to reach the keyxchangev2
+
+ set_wifi
+ else
+ echo "we have a gateway in range and do nothing"
+ fi
+
fi
diff --git a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
index 32cfdb5..9ed9826 100644
--- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
+++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
@@ -116,4 +116,35 @@ wifiAddAP() {
echo "${iface}"
}
+wifiAddSta() {
+ if [ $# -ne "2" ]
+ then
+ echo "Usage: wifiAddSta <radio> <essid>"
+ return 1
+ fi
+
+ local radio=$1
+ local essid=$2
+
+ local channel=$(uci get "wireless.${radio}.channel")
+ local iface="w2Sta"
+ if [ "$channel" -gt "14" ]; then
+ iface="w5Sta"
+ fi
+ uci batch <<-__EOF__
+ set wireless.${iface}='wifi-iface'
+ set wireless.${iface}.device='${radio}'
+ set wireless.${iface}.network='StaWiFi'
+ set wireless.${iface}.ifname='${iface}'
+ set wireless.${iface}.mode='sta'
+ set wireless.${iface}.ssid='${essid}'
+
+ commit wireless
+ __EOF__
+
+ #i think we need here some settings in uci network to geht a IP via DHCP!
+
+ echo "${iface}"
+}
+
# vim: set noexpandtab:tabstop=4
--
2.1.4
Mehr Informationen über die Mailingliste franken-dev