marek d12ba985c2 batman-adv: few makefile changes & upgrade dev to latest
git-svn-id: svn://svn.openwrt.org/openwrt/packages@21541 3c298f89-4303-0410-b956-a3cf2f4a3e73
2010-05-23 13:17:09 +00:00

109 lines
2.2 KiB
Bash

#!/bin/sh /etc/rc.common
START=90
MODULE_DIR="/sys/module/batman_adv"
detect_version() {
local version
if [ ! -d "$MODULE_DIR" ]; then
echo "batman-adv module directory not found - is the module loaded ?" >&2
return 1
fi
version=$(cat $MODULE_DIR/version)
if [ "$version" != "${version#0.3*}" ]; then
BAT_VER="0.3"
elif [ "$version" != "${version#0.2*}" ]; then
BAT_VER="0.2"
else
echo "Error - unknown version encountered: $version" >&2
return 1
fi
return 0
}
start_mesh () {
local meshif="$1"
detect_version
[ $? -ne 0 ] && return 1
config_get interfaces "$meshif" interfaces
config_get orig_interval "$meshif" orig_interval
config_get log_level "$meshif" log_level
if [ "$interfaces" = "" ]; then
echo Error, you must specify at least a network interface
return
fi
for interface in $interfaces
do
if [ "$BAT_VER" = "0.2" ]; then
echo $interface > /proc/net/batman-adv/interfaces
else
[ ! -f "/sys/class/net/$interface/batman_adv/mesh_iface" ] && echo "Can't add interface $interface - ignoring" && continue
echo $meshif > /sys/class/net/$interface/batman_adv/mesh_iface
fi
done
if [ $orig_interval ]; then
if [ "$BAT_VER" = "0.2" ]; then
echo $orig_interval > /proc/net/batman-adv/orig_interval
else
echo $orig_interval > /sys/class/net/$meshif/batman_adv/originator_interval
fi
fi
if [ $log_level ]; then
echo $log_level > /sys/module/batman_adv/parameters/debug 2>&-
fi
}
stop_mesh() {
local meshif="$1"
detect_version
[ $? -ne 0 ] && return 1
if [ "$BAT_VER" = "0.2" ]; then
echo "" > /proc/net/batman-adv/interfaces
return
fi
for iface in $(ls /sys/class/net/*)
do
[ ! -f "$iface/batman_adv/mesh_iface" ] && continue
[ "$(head -1 $iface/batman_adv/mesh_iface)" != "status: $meshif" ] && continue
echo "none" > $iface/batman_adv/mesh_iface
done
}
# can also be used with "batman-adv start bat0"
start() {
config_load batman-adv
if [ -n "$1" ]; then
start_mesh $1
else
config_foreach start_mesh mesh
fi
}
# can also be used with "batman-adv stop bat0"
stop () {
config_load batman-adv
if [ -n "$1" ]; then
stop_mesh $1
else
config_foreach stop_mesh mesh
fi
}