[RFC PATCH 2/8] fff-hoods: add initial hood configuration package
Jan Kraus
mayosemmel at googlemail.com
Di Mai 3 23:20:51 CEST 2016
From: Tim Niemeyer <tim.niemeyer at mastersword.de>
Signed-off-by: Tim Niemeyer <tim.niemeyer at mastersword.de>
Rebased Patch
Signed-off-by: Jan Kraus <mayosemmel at gmail.com>
---
src/packages/fff/fff-hoods/Makefile | 39 ++++++
.../fff/fff-hoods/files/etc/hoods/fuerth.hood | 18 +++
.../fff/fff-hoods/files/etc/hoods/nuernberg.hood | 18 +++
.../fff/fff-hoods/files/etc/hoods/test.hood | 18 +++
.../fff-hoods/files/etc/hoods/trainstation.hood | 17 +++
.../fff/fff-hoods/files/etc/uci-defaults/hood-dhcp | 18 +++
.../fff/fff-hoods/files/usr/sbin/configurehood | 144 +++++++++++++++++++++
src/packages/fff/fff/Makefile | 5 +-
8 files changed, 275 insertions(+), 2 deletions(-)
create mode 100644 src/packages/fff/fff-hoods/Makefile
create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/fuerth.hood
create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood
create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/test.hood
create mode 100644 src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood
create mode 100644 src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp
create mode 100755 src/packages/fff/fff-hoods/files/usr/sbin/configurehood
diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
new file mode 100644
index 0000000..bf92689
--- /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 +odhcpd
+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/etc/hoods/fuerth.hood b/src/packages/fff/fff-hoods/files/etc/hoods/fuerth.hood
new file mode 100644
index 0000000..fd5c9ea
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/fuerth.hood
@@ -0,0 +1,18 @@
+{
+ "version": 1,
+ "hood": {
+ "name": "fuerth",
+ "bssid": "ca:ff:ee:ba:be:02",
+ "protocol": "batman-adv-v14",
+ "channel2": 1,
+ "mode2": "ht20",
+ "type2": "adhoc",
+ "channel5": 40,
+ "mode5": "ht40+",
+ "type5": "adhoc",
+ "location": { "lat": 49.478330, "lon": 10.990270 },
+ },
+ "network": {
+ "ula_prefix": "fdff:2::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood b/src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood
new file mode 100644
index 0000000..6c26ab3
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/nuernberg.hood
@@ -0,0 +1,18 @@
+{
+ "version": 1,
+ "hood": {
+ "name": "nuernberg",
+ "bssid": "ca:ff:ee:ba:be:03",
+ "protocol": "batman-adv-v14",
+ "channel2": 1,
+ "mode2": "HT20",
+ "type": "adhoc",
+ "channel5": 40,
+ "mode5": "HT40+",
+ "type": "adhoc",
+ "location": { "lat": 49.448856, "lon": 11.082108 },
+ },
+ "network": {
+ "ula_prefix": "fdff:3::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/hoods/test.hood b/src/packages/fff/fff-hoods/files/etc/hoods/test.hood
new file mode 100644
index 0000000..18a93f1
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/test.hood
@@ -0,0 +1,18 @@
+{
+ "version": 0,
+ "hood": {
+ "name": "test",
+ "bssid": "ca:ff:ee:ba:be:ff",
+ "protocol": "batman-adv-v14",
+ "channel2": 13,
+ "mode2": "ht20",
+ "type2": "adhoc",
+ "channel5": 40,
+ "mode5": "ht40+",
+ "type5": "adhoc",
+ "location": { "lat": 49.46654, "lon": 10.992 },
+ },
+ "network": {
+ "ula_prefix": "fdff:ff::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood b/src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood
new file mode 100644
index 0000000..41ac75e
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hoods/trainstation.hood
@@ -0,0 +1,17 @@
+{
+ "version": 1,
+ "hood": {
+ "name": "trainstation",
+ "bssid": "ca:ff:ee:ba:be:00",
+ "protocol": "batman-adv-v14",
+ "channel2": 1,
+ "mode2": "ht20",
+ "type2": "adhoc",
+ "channel5": 40,
+ "mode5": "ht40+",
+ "type5": "adhoc",
+ },
+ "network": {
+ "ula_prefix": "fdff:0::/64"
+ }
+}
diff --git a/src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp b/src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp
new file mode 100644
index 0000000..d9fdb6d
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/uci-defaults/hood-dhcp
@@ -0,0 +1,18 @@
+#!/bin/sh
+>/etc/config/dhcp
+
+uci batch <<EOF
+set dhcp.odhcpd=odhcpd
+set dhcp.odhcpd.maindhcp=0
+set dhcp.odhcpd.leasefile=/tmp/hosts/odhcpd
+set dhcp.odhcpd.leasetrigger=/usr/sbin/odhcpd-update
+set dhcp.local=dhcp
+set dhcp.local.interface=mesh
+set dhcp.local.ra=server
+set dhcp.local.dhcpv6=server
+set dhcp.local.dhcpv4=disabled
+set dhcp.local.ndp=disabled
+set dhcp.local.ra_default=0
+set dhcp.local.ra_preference=low
+commit dhcp
+EOF
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..480b35c
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -0,0 +1,144 @@
+#!/bin/sh
+
+HOODDIR=/etc/hoods
+
+. /usr/share/libubox/jshn.sh
+
+myGeo=$(uci get 'system. at system[0].geo')
+
+if [ -z "$myGeo" ]; then
+ nearestHood=trainstation
+else
+ for hood in $HOODDIR/*.hood; do
+ echo "Parsing $hood"
+ filename=$(basename "$hood" .hood)
+ json_load "$(cat $hood)"
+ 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 $myGeo" | 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 $HOODDIR/$nearestHood.hood)"
+json_select hood
+
+json_get_var hood name
+json_get_var bssid bssid
+json_get_var channel2 channel2
+json_get_var mode2 mode2
+json_get_var protocol protocol
+json_get_var type2 type2
+
+echo "Setting hood name: $hood"
+echo "Setting channel 2.4 Ghz: $channel2"
+echo "Setting mode 2.4 GHz: $mode2"
+echo "Setting mesh 2.4 GHz type: $type2"
+
+echo "Shutting down wifi"
+wifi down
+
+uci set wireless.radio0=wifi-device
+uci set wireless.radio0.type=mac80211
+uci set wireless.radio0.channel=$channel2
+uci set wireless.radio0.phy=phy0
+uci set wireless.radio0.hwmode=11g
+uci set wireless.radio0.htmode=$mode2
+uci set wireless.radio0.country=DE
+uci set wireless. at wifi-iface[0]=wifi-iface
+uci set wireless. at wifi-iface[0].device=radio0
+uci set wireless. at wifi-iface[0].network=w2mesh
+uci set wireless. at wifi-iface[0].ifname=w2mesh
+uci set wireless. at wifi-iface[0].mode=$type2
+uci set wireless. at wifi-iface[0].bssid=$bssid
+uci set wireless. at wifi-iface[0].ssid=${protocol}.${hood}.freifunk.net
+uci set wireless. at wifi-iface[0].mcast_rate=6000
+uci set wireless. at wifi-iface[0].encryption=none
+uci set wireless. at wifi-iface[1]=wifi-iface
+uci set wireless. at wifi-iface[1].device=radio0
+uci set wireless. at wifi-iface[1].network=mesh
+uci set wireless. at wifi-iface[1].ifname=w2ap
+uci set wireless. at wifi-iface[1].mode=ap
+uci set wireless. at wifi-iface[1].ssid=${hood}.freifunk.net
+uci set wireless. at wifi-iface[1].encryption=none
+uci commit
+
+echo "Loading wifi"
+wifi
+
+json_select ..
+json_select network
+
+echo "Setting prefix: $prefix"
+json_get_var prefix ula_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
+ add network.globals
+ set network.globals.ula_prefix=$prefix
+ set network.mesh.ip6addr=$addr
+ commit network
+EOF
+
+echo "Restarting network"
+for ip in $(ip -6 addr show br-mesh | awk '/fdff/{ print $2 }'); do
+ ip -6 addr del $ip dev br-mesh
+done
+ip -6 addr add $addr dev br-mesh
+#/etc/init.d/odhcpd stop
+#/etc/init.d/network restart
+#/etc/init.d/odhcpd start
+
+echo "Finding fastd Gateways, if online. Configure fastd."
+
+echo "Done"
diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
index e709987..bbfa99e 100644
--- a/src/packages/fff/fff/Makefile
+++ b/src/packages/fff/fff/Makefile
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=fff
PKG_VERSION:=0.0.2
-PKG_RELEASE:=1
+PKG_RELEASE:=2
PKG_BUILD_DIR:=$(BUILD_DIR)/fff
@@ -20,7 +20,8 @@ define Package/fff-base
+fff-uradvd \
+fff-batman-adv-legacy \
+fff-fastd \
- +fff-firewall
+ +fff-firewall \
+ +fff-hoods
endef
define Package/fff-base/description
--
2.1.4
Mehr Informationen über die Mailingliste franken-dev