3 config_set
"$1" device
"wing-$1"
6 coldplug_interface_wing
() {
7 setup_interface_wing
"wing-$1" "$1"
10 stop_interface_wing
() {
12 local iface
="wing-$config"
13 env
-i ACTION
="ifdown" INTERFACE
="$config" DEVICE
="$iface" PROTO
=wing
/sbin
/hotplug-call
"iface"&
14 [ -f "/var/run/$iface.pid" ]&& {
15 kill -9 $
(cat /var
/run
/$iface.pid
)
16 rm /var
/run
/$iface.pid
20 setup_interface_wing
() {
31 config_foreach wing_list_interfaces wifi-iface
34 if [ "$hwmodes" = "" -o "$freqs" = "" -o "$ifnames" = "" -o "$hwaddrs" = "" ]; then
35 logger
-t "$config" "No raw interfaces available. Exiting."
39 local profile rc
ls prefix debug
41 config_get profile
$config profile
"bulk"
42 config_get rc
$config rc
"static"
43 config_get
ls $config ls "fcfs"
44 config_get metric
$config metric
"wcett"
45 config_get prefix
$config prefix
"6"
46 config_get period
$config period
"10000"
47 config_get tau
$config tau
"100000"
48 config_get_bool debug
$config debug
"False"
50 local hwaddr
=$
(echo $hwaddrs |
sed 's/ .*//');
51 local ipaddr
=$
(printf "$prefix.%d.%d.%d" $
(echo $hwaddr |
awk -F: '{printf "0x%s 0x%s 0x%s",$4,$5,$6}'))
52 local netmask
=255.0.0.0
54 if ! wing_template_available
"profile" "$profile" "bulk"; then
55 logger
-t "$config" "Unable to configure router. Exiting."
59 if ! wing_template_available
"rc" "$rc" "static"; then
60 logger
-t "$config" "Unable to configure rate control. Exiting."
64 if ! wing_template_available
"ls" "$ls" "radiotap"; then
65 logger
-t "$config" "Unable to configure link scheduler. Exiting."
69 if [ "$profile" = "" -o "$rc" = "" ]; then
70 logger
-t "$config" "Unable to generate template. Exiting."
74 [ "$debug" == 0 ]&& dbg
="" || dbg
="-d"
76 /usr
/bin
/click_config
-p $profile -r $rc -s $ls -l $metric \
77 -m "$hwmodes" -c "$freqs" -n "$ifnames" -a "$hwaddrs" $dbg \
78 |
sed -e "s/__XR_IFNAME__/$iface/g" \
79 |
sed -e "s/__XR_IP__/$ipaddr/g" \
80 |
sed -e "s/__XR_NM__/$netmask/g" \
81 |
sed -e "s/__XR_PERIOD__/$period/g" \
82 |
sed -e "s/__XR_TAU__/$tau/g"> /tmp
/$iface.click
84 /usr
/bin
/click-align
/tmp
/$iface.click
> /tmp
/$iface-aligned.click
2>/var
/log
/$iface.log
85 [ ! -c /dev
/net
/tun
]&& {
87 mknod
/dev
/net
/tun c
10 200
88 if [ ! -c /dev
/net
/tun
]; then
89 logger
-t "$config" "Device not available (/dev/net/tun). Exiting."
94 # creating the tun interface below will trigger a net subsystem event
95 # prevent it from touching iface by disabling .auto here
96 uci_set_state network
"$config" auto
0
98 (/usr
/bin
/click
/tmp
/$iface-aligned.click
>> /var
/log
/$iface.log
2>&1&)&
100 ps |
grep /usr
/bin
/click |
grep -q -v grep ||
{
101 logger
-t "$config" "Unable to start click. Exiting."
105 ps |
grep /usr
/bin
/click |
grep -v grep |
awk '{print $1}'> /var
/run
/$iface.pid
107 ifconfig
"$iface" "$ipaddr" netmask
"$netmask"
108 uci_set_state network
$config ipaddr
"$ipaddr"
109 uci_set_state network
$config netmask
"$netmask"
111 env
-i ACTION
="ifup" INTERFACE
="$config" DEVICE
="$iface" PROTO
=wing
/sbin
/hotplug-call
"iface"&
115 wing_template_available
() { # prefix, template, default
116 local template
="/etc/wing/$1.$2.click"
117 [ ! -f $template ]&& {
118 template
="/etc/wing/$1.$3.click"
119 [ ! -f $template ]&& {
126 wing_list_interfaces
() {
127 local channel freq hwmode hwaddr ifname mode
128 config_get ifname
$1 ifname
129 config_get mode
$1 mode
130 config_get device
$1 device
131 config_get_bool up
$1 up
132 [ "$up" = "1" -a "$mode" = "monitor" ] ||
return 0
133 config_get hwmode
$device hwmode
"11b"
134 config_get channel
$device channel
"1"
135 freq
=$
(iwlist
$ifname freq |
sed -n "s/^.*Channel 0*$channel : \([0-9.]*\).*/\1/p" |
awk '{print $1*1000}')
136 hwaddr
=$
(/sbin
/ifconfig
$ifname 2>&1 |
sed -n 's/^.*HWaddr \([0-9A-Za-z\-]*\).*/\1/p' |
sed -e 's/\-/:/g' | cut
-c1-17)
137 freqs
=${freqs:+"$freqs "}$freq
138 hwmodes
=${hwmodes:+"$hwmodes "}$hwmode
139 hwaddrs
=${hwaddrs:+"$hwaddrs "}$hwaddr
140 ifnames
=${ifnames:+"$ifnames "}$ifname
141 /sbin
/ifconfig
$ifname mtu
1900
142 /sbin
/ifconfig
$ifname txqueuelen
5
143 /sbin
/ifconfig
$ifname up