[RFC PATCH v4 01/10] fff-hoods: add initial hood configuration package
Jan Kraus
mayosemmel at googlemail.com
Fr Aug 19 20:45:13 CEST 2016
From: Tim Niemeyer <tim.niemeyer at mastersword.de>
Signed-off-by: Tim Niemeyer <tim.niemeyer at mastersword.de>
Rebased to current master
Fixed some Errors
removed dhcp configuration from fff-hoods because no dhcp server is in use
moved IPv6-Hood configuration from configurehood to configurenetwork
added check if IPv6 prefix is set in configurenetwork
made hoods update persistent
Signed-off-by: Jan Kraus <mayosemmel at gmail.com>
---
bsp/default/root_file_system/etc/rc.local | 1 +
community/franken.cfg | 8 +-
src/packages/fff/fff-hoods/Makefile | 39 ++++++
.../fff/fff-hoods/files/usr/sbin/configurehood | 142 +++++++++++++++++++++
.../fff-network/files/usr/sbin/configurenetwork | 8 +-
.../fff/fff-sysupgrade/files/etc/sysupgrade.conf | 1 +
src/packages/fff/fff-wireless/Makefile | 4 +-
.../fff/fff-wireless/files/etc/config/wireless | 0
.../files/etc/uci-defaults/60-fff-wireless | 43 -------
.../fff-wireless/files/lib/functions/fff/wireless | 7 +-
src/packages/fff/fff/Makefile | 3 +-
11 files changed, 196 insertions(+), 60 deletions(-)
create mode 100644 src/packages/fff/fff-hoods/Makefile
create mode 100755 src/packages/fff/fff-hoods/files/usr/sbin/configurehood
delete mode 100644 src/packages/fff/fff-wireless/files/etc/config/wireless
delete mode 100644 src/packages/fff/fff-wireless/files/etc/uci-defaults/60-fff-wireless
diff --git a/bsp/default/root_file_system/etc/rc.local b/bsp/default/root_file_system/etc/rc.local
index bd972fb..c980d8e 100755
--- a/bsp/default/root_file_system/etc/rc.local
+++ b/bsp/default/root_file_system/etc/rc.local
@@ -2,6 +2,7 @@
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
+/usr/sbin/configurehood
/usr/sbin/configurenetwork
touch /tmp/started
diff --git a/community/franken.cfg b/community/franken.cfg
index 833e98e..b5ad7e1 100644
--- a/community/franken.cfg
+++ b/community/franken.cfg
@@ -1,8 +1,2 @@
-BATMAN_CHANNEL=1
-BATMAN_CHANNEL_5GHZ=36
-ESSID_AP=franken.freifunk.net
-ESSID_MESH=batman.franken.freifunk.net
-BSSID_MESH=02:CA:FF:EE:BA:BE
-VPN_PROJECT=fff
NTPD_IP=fe80::ff:feee:1%br-mesh
-UPGRADE_PATH=http://[fe80::ff:feee:1%br-mesh]/dev/firmware/current
+UPGRADE_PATH=http://[fe80::ff:feee:1%br-mesh]/dev/firmware/current
\ No newline at end of file
diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
new file mode 100644
index 0000000..ac48760
--- /dev/null
+++ b/src/packages/fff/fff-hoods/Makefile
@@ -0,0 +1,39 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=fff-hoods
+PKG_VERSION:=0.0.1
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/fff-hoods
+ SECTION:=base
+ CATEGORY:=Freifunk
+ TITLE:= Freifunk-Franken hoods
+ URL:=http://www.freifunk-franken.de
+ DEPENDS:=+mdns +fff-network
+endef
+
+define Package/fff-hoods/description
+ This package load and configures the current hood
+endef
+
+define Build/Prepare
+ echo "all: " > $(PKG_BUILD_DIR)/Makefile
+endef
+
+define Build/Configure
+ # nothing
+endef
+
+define Build/Compile
+ # nothing
+endef
+
+define Package/fff-hoods/install
+ $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,fff-hoods))
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
new file mode 100755
index 0000000..484ca1b
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -0,0 +1,142 @@
+#!/bin/sh
+
+HOODDIR=/etc/hoods
+
+. /usr/share/libubox/jshn.sh
+. /lib/functions/fff/wireless
+
+myLat=$(uci get 'system. at system[0].latitude')
+myLon=$(uci get 'system. at system[0].longitude')
+
+if [ -z "$myLat" ] || [ -z "$myLon" ]; then
+ nearestHood="/etc/hoods/trainstation.hood"
+else
+ for filename in $HOODDIR/*.hood; do
+ hood=$(basename "$filename")
+ echo "Parsing $hood"
+ json_load "$(cat $filename)"
+ json_get_var ret version
+ if [ "$ret" -ne "1" ]; then
+ echo "Wrong version for $hood"
+ continue
+ fi
+
+ json_select hood
+ json_get_var protocol protocol
+ if [ "$protocol" != "batman-adv-v14" ]; then
+ echo "Unknown protocol in $hood"
+ continue
+ fi
+ json_get_var type2 type2
+ json_get_var type5 type5
+ if [ "$type2" != "adhoc" -o "$type5" != "adhoc" ]; then
+ echo "Unknown mesh type in $hood"
+ continue
+ fi
+ json_get_var hoodname name
+ if ! json_select location; then
+ echo "No location for $hood"
+ continue
+ fi
+ json_get_var lat lat
+ json_get_var lon lon
+
+ d=$(echo "$lat $lon $myLat $myLon" | awk '
+ function rad(deg) { # degrees to radians
+ return deg * (3.1415926 / 180.)
+ }
+ function distance(lat1,lon1,lat2,lon2) {
+ dlat = rad(lat2-lat1)
+ dlon = rad(lon2-lon1)
+ lat1 = rad(lat1)
+ lat2 = rad(lat2)
+ a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
+ return 6371 * 2 * atan2(sqrt(a),sqrt(1-a)) * 1000
+ }
+ {
+ printf("%d", distance($1, $2, $3, $4))
+ }')
+ if [ -z "$nearestDistance" ]; then
+ nearestDistance=$d
+ nearestHood=$filename
+ else
+ if [ "$d" -lt "$nearestDistance" ]; then
+ nearestDistance=$d
+ nearestHood=$filename
+ fi
+ fi
+ done
+fi
+
+echo "Found Hood: $nearestHood in $nearestDistance m"
+
+json_load "$(cat $nearestHood)"
+json_select hood
+
+json_get_var hood name
+json_get_var mesh_bssid mesh_bssid
+json_get_var mesh_essid mesh_essid
+json_get_var essid essid
+json_get_var channel2 channel2
+json_get_var mode2 mode2
+json_get_var type2 type2
+json_get_var channel5 channel5
+json_get_var mode5 mode5
+json_get_var type5 type5
+json_get_var protocol protocol
+
+echo "Setting hood name: $hood"
+uci set system. at system[0].hood=$hood
+
+if ! wifiDelAll; then
+ echo "Can't delete current wifi setup"
+ exit 1
+fi
+
+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" "$channel2" "$mode2")
+ 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" "$channel5" "mode5")
+ if [ -z "$radio" ]; then
+ echo "Can't create radio for $phy"
+ exit 1
+ fi
+ fi
+
+ if ! wifiAddAP "$radio" "$essid"; then
+ echo "Can't add AP interface on $radio0."
+ exit 1
+ fi
+
+ if ! wifiAddAdHocMesh "$radio" "$mesh_essid" "$mesh_bssid"; then
+ echo "Can't add AP interface on $radio0."
+ exit 1
+ fi
+done
+
+echo "Loading wifi"
+wifi
+
+json_select ..
+json_select network
+
+json_get_var prefix ula_prefix
+echo "Setting prefix: $prefix"
+suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address)
+addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
+
+uci -q batch <<-EOF >/dev/null
+ del network.globals
+ set network.globals=globals
+ set network.globals.ula_prefix="$prefix"
+ set network.mesh.ip6addr="$addr"
+ commit network
+EOF
diff --git a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
index 3b21411..1bbc6fb 100755
--- a/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
+++ b/src/packages/fff/fff-network/files/usr/sbin/configurenetwork
@@ -111,18 +111,16 @@ if [[ -n "$ETH0MAC" ]]; then
/etc/init.d/network restart
fi
-if uci get network.mesh.ip6addr
+if uci get network.globals.ula_prefix
then
- echo "IPv6 for mesh is set already"
-else
# Some time needed :(
sleep 5
+ prefix=$(uci get network.globals.ula_prefix)
for ip in $(ip -6 addr show br-mesh | awk '/fdff/{ print $2 }'); do
ip -6 addr del $ip dev br-mesh
done
- prefix="fdff:0::/64"
# Set $prefix::MAC as IP
suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address)
addr=$(echo $prefix | sed -e 's/\//'$suffix'\//')
@@ -149,4 +147,6 @@ else
uci -q commit network
/etc/init.d/fff-uradvd restart
+else
+ echo "IPv6 Prefix is not set"
fi
diff --git a/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.conf b/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.conf
index ed45476..06166d5 100644
--- a/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.conf
+++ b/src/packages/fff/fff-sysupgrade/files/etc/sysupgrade.conf
@@ -4,3 +4,4 @@
/etc/dropbear/authorized_keys
/etc/network.mode
/etc/config/system
+/etc/hoods/
diff --git a/src/packages/fff/fff-wireless/Makefile b/src/packages/fff/fff-wireless/Makefile
index 12456e5..046d932 100644
--- a/src/packages/fff/fff-wireless/Makefile
+++ b/src/packages/fff/fff-wireless/Makefile
@@ -1,8 +1,8 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=fff-wireless
-PKG_VERSION:=0.0.1
-PKG_RELEASE:=1
+PKG_VERSION:=0.0.2
+PKG_RELEASE:=2
PKG_BUILD_DIR:=$(BUILD_DIR)/fff-wireless
diff --git a/src/packages/fff/fff-wireless/files/etc/config/wireless b/src/packages/fff/fff-wireless/files/etc/config/wireless
deleted file mode 100644
index e69de29..0000000
diff --git a/src/packages/fff/fff-wireless/files/etc/uci-defaults/60-fff-wireless b/src/packages/fff/fff-wireless/files/etc/uci-defaults/60-fff-wireless
deleted file mode 100644
index 59239b3..0000000
--- a/src/packages/fff/fff-wireless/files/etc/uci-defaults/60-fff-wireless
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-# Copyright 2016 Tim Niemeyer
-# License GPLv3
-
-. /lib/functions/fff/wireless
-
-. /etc/community.cfg
-
-if ! wifiDelAll; then
- echo "Can't delete current wifi setup"
- exit 1
-fi
-
-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
-
- if ! wifiAddAP "$radio" "$ESSID_AP"; then
- echo "Can't add AP interface on $radio0."
- exit 1
- fi
-
- if ! wifiAddAdHocMesh "$radio" "$ESSID_MESH" "$BSSID_MESH"; then
- echo "Can't add AP interface on $radio0."
- exit 1
- fi
-done
-
-# vim: set noexpandtab:tabstop=4
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 59c8ce2..69bc000 100644
--- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
+++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
@@ -15,14 +15,15 @@ wifiDelAll() {
}
wifiAddPhy() {
- if [ $# -ne "2" ]
+ if [ $# -ne "3" ]
then
- echo "Usage: wifiAddPhy <phy> <channel>"
+ echo "Usage: wifiAddPhy <phy> <channel> <htmode>"
return 1
fi
local phy=$1
local channel=$2
+ local htmode=$3
local radio="radio$(echo $phy | tr -d -C [0-9])"
local hwmode="11g"
if [ "$channel" -gt "14" ]; then
@@ -35,7 +36,7 @@ wifiAddPhy() {
set wireless.${radio}.channel='${channel}'
set wireless.${radio}.phy='${phy}'
set wireless.${radio}.hwmode='${hwmode}'
- set wireless.${radio}.htmode='HT20'
+ set wireless.${radio}.htmode='${htmode}'
set wireless.${radio}.country='DE'
commit wireless
__EOF__
diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
index a5b7df5..41e53d7 100644
--- a/src/packages/fff/fff/Makefile
+++ b/src/packages/fff/fff/Makefile
@@ -25,7 +25,8 @@ define Package/fff-base
+fff-sysupgrade \
+fff-wireless \
+fff-timeserver \
- +fff-vpn-select
+ +fff-vpn-select \
+ +fff-hoods
endef
define Package/fff-base/description
--
2.1.4
Mehr Informationen über die Mailingliste franken-dev