7 proto_wing_init_config() {
10 proto_config_add_string "ipaddr"
11 proto_config_add_string "netmask"
14 proto_wing_teardown() {
16 local link="wing-$config"
17 [ -f "/var/run/$link.pid" ] && {
18 kill -9 $(cat /var/run/$link.pid)
21 env -i ACTION="ifdown" INTERFACE="$config" DEVICE="$link" PROTO=wing /sbin/hotplug-call "link" &
28 local link="wing-$config"
35 # temporary hack waiting for a way to delay wing interfaces until the
36 # wifi sub-system has been brought up
40 config_foreach wing_list_interfaces wifi-iface
43 if [ "$hwmodes" = "" -o "$freqs" = "" -o "$ifnames" = "" -o "$hwaddrs" = "" ]; then
44 logger -t "$config" "No raw interfaces available. Exiting."
48 local profile rc ls metric prefix period tau debug
50 config_get profile $config profile "bulk"
51 config_get rc $config rc "minstrel"
52 config_get ls $config ls "fcfs"
53 config_get metric $config metric "wcett"
54 config_get prefix $config prefix "6"
55 config_get period $config period "10000"
56 config_get tau $config tau "100000"
57 config_get_bool debug $config debug "false"
59 local hwaddr=$(echo $hwaddrs | sed 's/ .*//');
60 local ipaddr=$(printf "$prefix.%d.%d.%d" $(echo $hwaddr | awk -F: '{printf "0x%s 0x%s 0x%s",$4,$5,$6}'))
61 local bcast="$prefix.255.255.255"
62 local netmask=255.0.0.0
64 if ! wing_template_available "profile" "$profile"; then
65 logger -t "$config" "Unable to configure router. Exiting."
69 if ! wing_template_available "rc" "$rc"; then
70 logger -t "$config" "Unable to configure rate control. Exiting."
74 if ! wing_template_available "ls" "$ls"; then
75 logger -t "$config" "Unable to configure link scheduler. Exiting."
79 if [ "$profile" = "" -o "$rc" = "" ]; then
80 logger -t "$config" "Unable to generate template. Exiting."
84 [ "$debug" == 0 ] && dbg="" || dbg="-d"
86 /usr/bin/click_config -p $profile -r $rc -s $ls -l $metric \
87 -m "$hwmodes" -c "$freqs" -n "$ifnames" -a "$hwaddrs" $dbg \
88 | sed -e "s/__XR_IFNAME__/$link/g" \
89 | sed -e "s/__XR_IP__/$ipaddr/g" \
90 | sed -e "s/__XR_BCAST__/$bcast/g" \
91 | sed -e "s/__XR_NM__/$netmask/g" \
92 | sed -e "s/__XR_PERIOD__/$period/g" \
93 | sed -e "s/__XR_TAU__/$tau/g" > /tmp/$link.click
95 /usr/bin/click-align /tmp/$link.click > /tmp/$link-aligned.click 2>/var/log/$link.log
96 [ ! -c /dev/net/tun ] && {
98 mknod /dev/net/tun c 10 200
99 if [ ! -c /dev/net/tun ]; then
100 logger -t "$config" "Device not available (/dev/net/tun). Exiting."
105 (/usr/bin/click /tmp/$link-aligned.click >> /var/log/$link.log 2>&1 &) &
107 ps | grep /usr/bin/click | grep -q -v grep || {
108 logger -t "$config" "Unable to start click. Exiting."
112 ps | grep /usr/bin/click | grep -v grep | awk '{print $1}' > /var/run/$link.pid
114 env -i ACTION="ifup" INTERFACE="$config" DEVICE="$link" PROTO=wing /sbin/hotplug-call "link" &
116 proto_init_update "$link" 1
117 proto_add_ipv4_address "$ipaddr" "$netmasj"
119 route -n | grep -q '^0.0.0.0' || {
120 proto_add_ipv4_route "0.0.0.0" 0
123 proto_send_update "$config"
127 wing_template_available() { # prefix, template, default
128 local template="/etc/wing/$1.$2.click"
129 [ ! -f $template ] && {
135 wing_list_interfaces() {
136 local channel freq hwmode hwaddr ifname mode
137 config_get mode $1 mode
138 config_get_bool up $1 up
139 [ "$up" = "1" -a "$mode" = "monitor" ] || return 0
140 config_get ifname $1 ifname
141 config_get device $1 device
142 config_get hwmode $device hwmode "11bg"
143 config_get channel $device channel "0"
144 [ "$channel" = "0" -o "$channel" = "auto" ] && {
145 logger -t "$device" "Channel not specified. Ignoring."
148 freq=$(iwlist $ifname freq | sed -n "s/^.*Channel 0*$channel : \([0-9.]*\).*/\1/p" | awk '{print $1*1000}')
149 hwaddr=$(/sbin/ifconfig $ifname 2>&1 | sed -n 's/^.*HWaddr \([0-9A-Za-z\-]*\).*/\1/p' | sed -e 's/\-/:/g' | cut -c1-17)
150 freqs=${freqs:+"$freqs "}$freq
151 hwmodes=${hwmodes:+"$hwmodes "}$hwmode
152 hwaddrs=${hwaddrs:+"$hwaddrs "}$hwaddr
153 ifnames=${ifnames:+"$ifnames "}$ifname
154 /sbin/ifconfig $ifname mtu 1900
155 /sbin/ifconfig $ifname txqueuelen 5
156 /sbin/ifconfig $ifname up