Developing lightweight computation at the DSG edge

Commit 42ccfe02 authored by hitz's avatar hitz
Browse files

First functional version of autoconfig

parent 4d8a2263
src-link qmp_packages /home/hitz/13f/qmp/packages
src-link eigennet_packages /home/hitz/13f/eigennet/packages
src-svn packages svn://svn.openwrt.org/openwrt/packages
src-svn luci http://svn.luci.subsignal.org/luci/branches/luci-0.10/contrib/package
#src-svn xwrt http://x-wrt.googlecode.com/svn/branches/backfire_10.03/package
#src-svn phone svn://svn.openwrt.org/openwrt/feeds/phone
#src-svn efl svn://svn.openwrt.org/openwrt/feeds/efl
#src-svn desktop svn://svn.openwrt.org/openwrt/feeds/desktop
#src-svn xfce svn://svn.openwrt.org/openwrt/feeds/xfce
#src-link custom /usr/src/openwrt/custom-feed
## this config should work for fonera, alix, ...
config qmp interfaces
# option configure_switch 'eth0' # remove (comment line if not available)
option lan_devices 'eth0' # will be used as is! alix: eth0 wgt634u: eth0.1, ns5: eth0 or remove
option wan_device 'eth1' # will be used as is! alix: eth1, wgt634u: eth0.2, ns5: eth0 or remove
option mesh_devices 'eth0 ath0' # will be extended by vlan tag! alix: eth0 ath1 ath2, wgt634u: eth0 ath0, ns5: eth0 ath0
config qmp node
# if commented out then last byte of the MAC address is used (0x000-0x0FF):
# option community_node_id 901 # value between 0x0100 and 0xFFFF
config qmp networks
option niit_prefix96 '0:0:0:0:0:ffff' # omit trailing 32 ipv4 bits !
option mesh_protocol_vids 'olsr6:1 bmx6:2' # or "olsr6:1 bmx6:2 babel:3", means olsr6 use vlantag 10+1, bmx6 use vlantag 10+2
option mesh_vid_offset '10'
option olsr6_mesh_prefix48 'fd01:0:0'
option olsr6_ripe_prefix48 '2011:0:0'
option olsr6_ipv4_prefix24 '10.201'
# option olsr6_ipv4_address '10.201.9.01'
# option olsr6_ipv4_netmask '255.255.255.0'
# option olsr6_6to4_netmask '120'
option bmx6_mesh_prefix48 'fd02:0:0'
option bmx6_ripe_prefix48 '2012:0:0'
option bmx6_ipv4_prefix24 '10.202'
# option bmx6_ipv4_address '10.202.9.01'
# option bmx6_ipv4_netmask '255.255.255.0'
# option bmx6_6to4_netmask '120'
option babel_mesh_prefix48 'fd03:0:0'
config qmp wireless
option driver mac80211
option country 800
option bssid 02:CA:FF:EE:BA:BE
config wireless
option channel 10
option mode ap
option mac 00:80:48:6B:25:b6
option name AP-qmp
config wireless
option channel 44
option mode adhoc
option mac 00:80:48:6b:25:b5
option name qmp
config 'qmp' 'interfaces'
option 'lan_devices' 'eth0'
option 'wan_device' 'eth1'
option 'mesh_devices' 'eth0 ath0'
config 'qmp' 'node'
config 'qmp' 'networks'
option 'niit_prefix96' '0:0:0:0:0:ffff'
option 'mesh_protocol_vids' 'olsr6:1 bmx6:2'
option 'mesh_vid_offset' '10'
option 'olsr6_mesh_prefix48' 'fd01:0:0'
option 'olsr6_ripe_prefix48' '2011:0:0'
option 'olsr6_ipv4_prefix24' '10.201'
option 'bmx6_mesh_prefix48' 'fd02:0:0'
option 'bmx6_ripe_prefix48' '2012:0:0'
option 'bmx6_ipv4_prefix24' '10.202'
option 'babel_mesh_prefix48' 'fd03:0:0'
config 'qmp' 'wireless'
option 'driver' 'mac80211' # mac80211/madwifi
option 'country' 'UZ'
# option 'country' '800' # for madwifi
option 'bssid' '02:CA:FF:EE:BA:BE'
config 'wireless'
option 'channel' '44'
option 'mode' 'adhoc'
option 'name' 'qmp'
config 'wireless'
option 'channel' '10'
option 'mode' 'ap'
option 'name' 'qmp.cat'
......@@ -2,22 +2,30 @@
# Copyright (C) 2011 qmp.cat
START=99
CONTROL_FILE="/qmp_configured"
QMP_PATH="/etc/qmp"
QMP_DIR="/etc/qmp"
configure() {
echo "Starting qmp configuration..."
. $QMP_PATH/qmp_functions.sh
echo "[Configuring networking]"
. $QMP_DIR/qmp_functions.sh
qmp_configure
echo "[Configuring wireless]"
. $QMP_DIR/qmp_wireless.sh
qmp_configure_wifi_initial
qmp_configure_wifi
touch "$CONTROL_FILE"
echo "Done"
}
start() {
if [ ! -f "$CONTROL_FILE" ]; then
configure
else
echo "QMP configured. Remove $CONTROL_FILE to force reconfiguration"
fi
if [ ! -f "$CONTROL_FILE" ]; then
configure
else
echo "QMP configured. Remove $CONTROL_FILE to force reconfiguration"
fi
}
stop() {
......@@ -28,16 +36,3 @@ restart() {
stop
start
}
enable()
{
rm "$CONTROL_FILE" 2>/dev/null
echo "Autoconfiguration enabled..."
}
dissable()
{
touch "$CONTROL_FILE"
echo "Autoconfiguration dissabled..."
}
#!/bin/sh
qmp_uci_get() {
echo "$(uci get qmp.$1)" 2>/dev/null
echo "$(uci get qmp.$1 2>/dev/null)"
}
qmp_uci_set() {
uci set qmp.$1=$2
uci commit
}
qmp_uci_add() {
uci add qmp $1
uci commit
}
qmp_error() {
......@@ -9,3 +19,11 @@ qmp_error() {
exit 1
}
qmp_get_wifi_devices() {
echo "$(ip link | grep -E ": (wifi|wlan).: "| cut -d: -f2)"
}
qmp_get_wifi_mac_devices() {
echo "$(ip link | grep -A1 -E ": (wifi|wlan).: " | grep link | cut -d' ' -f6)"
}
#!/bin/sh
QMP_PATH="/etc/qmp"
OWRT_WIRELESS_CONFIG="/etc/config/wireless"
TEMPLATE_BASE="$QMP_PATH/templates/wireless"
TEMPLATE_BASE="$QMP_PATH/templates/wireless" # followed by .driver.mode (wireless.mac80211.adhoc)
WIFI_DEFAULT_CONFIG="$QMP_PATH/templates/wireless.default.config"
#Importing files
. $QMP_PATH/qmp_common.sh
qmp_configure_wifi_device() {
echo "Configuring device $1"
mac="$(qmp_uci_get @wireless[$1].mac)"
channel="$(qmp_uci_get @wireless[$1].channel)"
mode="$(qmp_uci_get @wireless[$1].mode)"
name="$(qmp_uci_get @wireless[$1].name)"
#Configure a wifi device according qmp config file
#Parameters are: 1-> qmp config id, 2-> device name
echo ""
echo "Configuring device $2"
id=$1
device=$2
mac="$(qmp_uci_get @wireless[$id].mac)"
channel="$(qmp_uci_get @wireless[$id].channel)"
mode="$(qmp_uci_get @wireless[$id].mode)"
name="$(qmp_uci_get @wireless[$id].name)"
driver="$(qmp_uci_get wireless.driver)"
country="$(qmp_uci_get wireless.country)"
bssid="$(qmp_uci_get wireless.bssid)"
......@@ -28,7 +38,7 @@ qmp_configure_wifi_device() {
[ ! -f "$template" ] && qmp_error "Template $template not found"
cat $template | sed -e s/"#QMP_DEVICE"/"wifi$1"/ \
cat $template | sed -e s/"#QMP_DEVICE"/"$device"/ \
-e s/"#QMP_TYPE"/"$driver"/ \
-e s/"#QMP_MAC"/"$mac"/ \
-e s/"#QMP_CHANNEL"/"$channel"/ \
......@@ -39,24 +49,80 @@ qmp_configure_wifi_device() {
}
qmp_configure_wifi() {
#This function search for all wifi devices and leave them configured according qmp config file
echo "Backuping wireless config file to: $OWRT_WIRELESS_CONFIG.qmp_backup"
cp $OWRT_WIRELESS_CONFIG $OWRT_WIRELESS_CONFIG.qmp_backup
echo "" > $OWRT_WIRELESS_CONFIG
devices="$(ip link | grep -E ": (wifi|wlan).: "| cut -d: -f2)"
macs="$(ip link | grep -A1 -E ": (wifi|wlan).: " | grep link | cut -d' ' -f6)"
devices="$(qmp_get_wifi_devices)"
macs="$(qmp_get_wifi_mac_devices)"
i=1
for d in $devices; do
m=$(echo $macs | cut -d' ' -f$i)
j=0
configured_mac="$(qmp_uci_get @wireless[$j].mac | tr [A-Z] [a-z])"
while [ ! -z "$configured_mac" ]; do
[ "$configured_mac" == "$m" ] && { qmp_configure_wifi_device $j ; break; }
j=$(( $j + 1 ))
while [ ! -z "$(qmp_uci_get @wireless[$j])" ]; do
configured_mac="$(qmp_uci_get @wireless[$j].mac | tr [A-Z] [a-z])"
[ "$configured_mac" == "$m" ] && { qmp_configure_wifi_device $j $d ; break; }
j=$(( $j + 1 ))
done
i=$(( $i + 1 ))
done
echo "Done. All devices configured according qmp configuration"
}
qmp_wifi_get_default() {
[ ! -f "$WIFI_DEFAULT_CONFIG" ] && qmp_error "Template not found $WIFI_DEFAULT_CONFIG"
cat $WIFI_DEFAULT_CONFIG | grep $1 | cut -d' ' -f2
}
qmp_configure_wifi_initial() {
macs="$(qmp_get_wifi_mac_devices)"
#Looking for configured devices
id_configured=""
to_configure=""
for m in $macs; do
found=0
j=0
while [ ! -z "$(qmp_uci_get @wireless[$j])" ]; do
configured_mac="$(qmp_uci_get @wireless[$j].mac | tr [A-Z] [a-z])"
if [ "$configured_mac" == "$m" ]; then
#If we found configured device, we are going to check all needed parameters
found=1
id_configured="$id_configured $j"
echo "Found configured device: $m"
[ -z "$(qmp_uci_get @wireless[$j].channel)" ] && qmp_uci_set @wireless[$j].channel $(qmp_wifi_get_default channel)
[ -z "$(qmp_uci_get @wireless[$j].mode)" ] && qmp_uci_set @wireless[$j].mode $(qmp_wifi_get_default mode)
[ -z "$(qmp_uci_get @wireless[$j].name)" ] && qmp_uci_set @wireless[$j].name $(qmp_wifi_get_default name)
break
fi
j=$(( $j + 1 ))
done
[ $found -eq 0 ] && to_configure="$to_configure $m"
done
#Configuring devices not found before
for m in $to_configure; do
echo "Configuring device $m"
#Looking for a free slot to put new configuration
j=0
while [ ! -z "$(echo $id_configured | grep $j)" ]; do j=$(( $j +1 )); done
#Now we have a free slot, let's go to configure device
[ -z "$(qmp_uci_get @wireless[$j])" ] && qmp_uci_add wireless
[ -z "$(qmp_uci_get @wireless[$j].channel)" ] && qmp_uci_set @wireless[$j].channel $(qmp_wifi_get_default channel)
[ -z "$(qmp_uci_get @wireless[$j].mode)" ] && qmp_uci_set @wireless[$j].mode $(qmp_wifi_get_default mode)
[ -z "$(qmp_uci_get @wireless[$j].name)" ] && qmp_uci_set @wireless[$j].name $(qmp_wifi_get_default name)
qmp_uci_set @wireless[$j].mac $m
id_configured="$id_configured $j"
done
#Finally we are going to configure default parameters if they are not present
[ -z "$(qmp_uci_get wireless)" ] && qmp_uci_set wireless qmp
[ -z "$(qmp_uci_get wireless.driver)" ] && qmp_uci_set wireless.driver $(qmp_wifi_get_default driver)
[ -z "$(qmp_uci_get wireless.country)" ] && qmp_uci_set wireless.country $(qmp_wifi_get_default country)
[ -z "$(qmp_uci_get wireless.bssid)" ] && qmp_uci_set wireless.bssid $(qmp_wifi_get_default bssid)
}
driver mac80211
country UZ
bssid 02:CA:FF:EE:BA:BE
channel 44
mode adhoc
name qmp
config wifi-device #QMP_DEVICE
option type #QMP_TYPE
option macaddr #QMP_MAC
option channel #QMP_CHANNEL
option diversity 0 # 0:off, 1:on
option txantenna 0 # 0:auto, 1:main, 2:aux
option rxantenna 0 # 0:auto, 1:main, 2:aux
option country #QMP_COUNTRY
option outdoor 1
# option txpower 1
config wifi-iface
option device #QMP_DEVICE
option mode #QMP_MODE
option ssid #QMP_SSID
option bssid #QMP_BSSID
option encryption none
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment