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
51 config_get profile $config profile "bulk"
52 config_get rc $config rc "minstrel"
53 config_get ls $config ls "fcfs"
54 config_get metric $config metric "wcett"
55 config_get prefix $config prefix "6"
56 config_get period $config period "10000"
57 config_get tau $config tau "100000"
58 config_get_bool debug $config debug "false"
60 local hwaddr=$(echo $hwaddrs | sed 's/ .*//');
61 local ipaddr=$(printf "$prefix.%d.%d.%d" $(echo $hwaddr | awk -F: '{printf "0x%s 0x%s 0x%s",$4,$5,$6}'))
62 local bcast="$prefix.255.255.255"
63 local netmask=255.0.0.0
65 if ! wing_template_available "profile" "$profile"; then
66 logger -t "$config" "Unable to configure router. Exiting."
70 if ! wing_template_available "rc" "$rc"; then
71 logger -t "$config" "Unable to configure rate control. Exiting."
75 if ! wing_template_available "ls" "$ls"; then
76 logger -t "$config" "Unable to configure link scheduler. Exiting."
80 if [ "$profile" = "" -o "$rc" = "" ]; then
81 logger -t "$config" "Unable to generate template. Exiting."
85 [ "$debug" == 0 ] && dbg="" || dbg="-d"
87 export CLICK_BACKTRACE=1
89 /usr/bin/click_config -p $profile -r $rc -s $ls -l $metric \
90 -m "$hwmodes" -c "$freqs" -n "$ifnames" -a "$hwaddrs" $dbg \
91 | sed -e "s/__XR_IFNAME__/$link/g" \
92 | sed -e "s/__XR_IP__/$ipaddr/g" \
93 | sed -e "s/__XR_BCAST__/$bcast/g" \
94 | sed -e "s/__XR_NM__/$netmask/g" \
95 | sed -e "s/__XR_PERIOD__/$period/g" \
96 | sed -e "s/__XR_TAU__/$tau/g" > /tmp/$link.click
98 /usr/bin/click-align /tmp/$link.click > /tmp/$link-aligned.click 2>/var/log/$link.log
99 [ ! -c /dev/net/tun ] && {
101 mknod /dev/net/tun c 10 200
102 if [ ! -c /dev/net/tun ]; then
103 logger -t "$config" "Device not available (/dev/net/tun). Exiting."
108 (/usr/bin/click /tmp/$link-aligned.click >> /var/log/$link.log 2>&1 &) &
110 ps | grep /usr/bin/click | grep -q -v grep || {
111 logger -t "$config" "Unable to start click. Exiting."
115 ps | grep /usr/bin/click | grep -v grep | awk '{print $1}' > /var/run/$link.pid
117 uci_set_state network $config ifname "$iface"
118 uci_set_state network $config ipaddr "$ipaddr"
119 uci_set_state network $config netmask "$netmask"
120 uci_set_state network $config gateway "0.0.0.0"
122 env -i ACTION="ifup" INTERFACE="$config" DEVICE="$link" PROTO=wing /sbin/hotplug-call "link" &
124 proto_init_update "$link" 1
125 proto_add_ipv4_address "$ipaddr" "$netmask"
126 proto_add_ipv4_route "$prefix.0.0.0" "255.0.0.0" "$iface"
128 route -n | grep -q '^0.0.0.0' || {
129 proto_add_ipv4_route "0.0.0.0" "0" "$iface"
132 proto_send_update "$config"
136 wing_template_available() { # prefix, template, default
137 local template="/etc/wing/$1.$2.click"
138 [ ! -f $template ] && {
144 wing_list_interfaces() {
145 local channel freq hwmode hwaddr ifname mode
146 config_get mode $1 mode
147 config_get_bool up $1 up
148 [ "$up" = "1" -a "$mode" = "monitor" ] || return 0
149 config_get ifname $1 ifname
150 config_get device $1 device
151 config_get hwmode $device hwmode "11bg"
152 config_get channel $device channel "0"
153 [ "$channel" = "0" -o "$channel" = "auto" ] && {
154 logger -t "$device" "Channel not specified. Ignoring."
157 freq=$(iwlist $ifname freq | sed -n "s/^.*Channel 0*$channel : \([0-9.]*\).*/\1/p" | awk '{print $1*1000}')
158 hwaddr=$(/sbin/ifconfig $ifname 2>&1 | sed -n 's/^.*HWaddr \([0-9A-Za-z\-]*\).*/\1/p' | sed -e 's/\-/:/g' | cut -c1-17)
159 freqs=${freqs:+"$freqs "}$freq
160 hwmodes=${hwmodes:+"$hwmodes "}$hwmode
161 hwaddrs=${hwaddrs:+"$hwaddrs "}$hwaddr
162 ifnames=${ifnames:+"$ifnames "}$ifname
163 /sbin/ifconfig $ifname mtu 1900
164 /sbin/ifconfig $ifname txqueuelen 5
165 /sbin/ifconfig $ifname up