1 #!/bin/sh /etc/rc.common
10 # NOTE: all functions write the result to the $result variable
17 channelsets
=$
(uci show
$CONFIGURATION |
grep "=channel-set$")
18 for channelset
in $channelsets; do
19 channelset
=$
(echo "$channelset" |
sed -rn "s/$CONFIGURATION\.(.*)=.*/\1/p")
20 result
="$result $channelset"
22 if [ $VERBOSE -eq 1 ]; then
23 echo "Channel Sets: $result" 2>&1 | logger
27 # $1 : the channel set name
28 get_channelset_enabled
()
33 result
=$
(uci get
$CONFIGURATION.
"$1".enabled
)
35 if [ $VERBOSE -eq 1 ]; then
36 echo "Channel Set \"$1\" Enabled: $result" 2>&1 | logger
40 # $1 : the channel set name
45 result
=$
(uci get
$CONFIGURATION.
"$1".bridge
)
47 if [ $VERBOSE -eq 1 ]; then
48 echo "Channel Set \"$1\" Primary Bridge: $result" 2>&1 | logger
52 # $1 : the channel set name
58 result
=$
(uci get
$CONFIGURATION.
"$1".data_channels
)
60 if [ $VERBOSE -eq 1 ]; then
61 echo "Channel Set \"$1\" Data Channels: $result" 2>&1 | logger
65 # $1 : the wlan interface name
70 #result=$(echo "$1" | sed -n "s/wlan//p")
71 result
=$
(echo "$1" |
sed -rn "s/wlan([0-9]*).*/\1/p")
75 # $1 : the bridge name
76 get_bridge_network_name
()
80 result
=$
(echo "$1" |
sed -n "s/br-//p")
84 # $1 : the wlan interface name
85 set_iface_init_state
()
90 # need to extract the "X" from wlanX
91 get_wifi_iface_num
"$iface"
93 if [ -n "$iface_num" ]; then
94 # get the iface network
95 init_net
=$
(uci get wireless.@wifi-iface
[$iface_num].network
)
96 if [ -n "$init_net" ]; then
97 # if the iface network is a bridge, but doesn't start with "br-"
98 # I think we need to prepend it?
99 net_type
=$
(uci get network.
"$init_net".
type)
100 if [ -n "$net_type" ] && [ "$net_type" = "bridge" ]; then
101 prefix_ok
=$
(echo "$init_net" |
grep "^br-")
102 if [ -z "$prefix_ok" ]; then
103 init_net
="br-$init_net"
108 # make sure that the init_net section exists
109 init_net_section
=$
(uci get dcwapd.init_net
)
110 if [ "$init_net_section" != "init_net" ]; then
111 # the section did not exist
112 uci
set dcwapd.init_net
=init_net
115 # save the initial network
116 if [ $VERBOSE -eq 1 ]; then
117 echo "Saving '$iface' initial network '$init_net'" 2>&1 | logger
119 uci
set $CONFIGURATION.init_net.
"$iface"="$init_net"
122 # save the initial network in the result variable
128 # $1 : the wlan interface name
129 get_iface_init_state
()
133 init_net
=$
(uci get
$CONFIGURATION.init_net.
"$iface")
135 # if the response starts with "uci: ", it was an error not the real result
136 err
=$
(echo "$init_net" |
grep "^uci: ")
137 if [ -z "$err" ]; then
138 # no error, set the result
141 if [ $VERBOSE -eq 1 ]; then
142 echo "Got '$iface' initial network '$init_net'" 2>&1 | logger
148 # $1 : the name of the data channel name to bring up
152 bridge
=$
(uci get
$CONFIGURATION.
"$1".bridge
)
153 interfaces
=$
(uci get
$CONFIGURATION.
"$1".interfaces
)
154 if [ $VERBOSE -eq 1 ]; then
155 echo "Creating Data Channel Bridge: $bridge" 2>&1 | logger
158 get_bridge_network_name
"$bridge"
160 if [ -n "$netname" ]; then
161 uci
set network.
"$netname"=interface
162 uci
set network.
"$netname".
type=bridge
163 uci
set network.
"$netname".proto
=static
164 uci
set network.
"$netname".bridge_empty
='1'
169 /etc
/init.d
/network reload
171 for iface
in $interfaces; do
172 # if iface is in a bridge, the bridge name should be stored in result
173 set_iface_init_state
"$iface"
176 # update uci with the new bridge info
177 get_wifi_iface_num
"$iface"
179 if [ -n "$iface_num" ]; then
180 uci
set wireless.@wifi-iface
[$iface_num].network
="$netname"
183 # manually put the interface into the data bridge
184 # if iface is in a bridge, remove it before adding it to the data bridge
185 if [ -n "$init_bridge" ]; then
186 brctl delif
"$init_bridge" "$iface" 2>&1 | logger
188 brctl addif
"$bridge" "$iface" 2>&1 | logger
191 # commit uci changes and reload the network
193 /etc
/init.d
/network reload
194 #/etc/init.d/network restart
196 # ifconfig "$bridge" > /dev/null 2>&1
197 # if [ $? == 0 ]; then
205 # $1 : the name of the data channel to bring down
209 bridge
=$
(uci get
$CONFIGURATION.
"$1".bridge
)
210 interfaces
=$
(uci get
$CONFIGURATION.
"$1".interfaces
)
211 for iface
in $interfaces; do
212 if [ $VERBOSE -eq 1 ]; then
213 echo "Deconfiguring Data Channel Interface: $iface" 2>&1 | logger
216 # manually remove the interface from the data bridge
217 brctl delif
"$bridge" "$iface" 2>&1 | logger
219 get_iface_init_state
"$iface"
221 if [ -n "$init_bridge" ]; then
222 # manually move the interface back to the original bridge
223 brctl addif
"$init_bridge" "$iface" 2>&1 | logger
225 # update uci with the new bridge and interface configuration
226 get_wifi_iface_num
"$iface"
228 get_bridge_network_name
"$init_bridge"
230 if [ -n "$iface_num" ] && [ -n "$netname" ]; then
231 uci
set wireless.@wifi-iface
[$iface_num].network
="$netname"
235 if [ $VERBOSE -eq 1 ]; then
236 echo "Deconfiguring Data Channel Bridge: $bridge" 2>&1 | logger
239 # delete the bridge from uci
240 get_bridge_network_name
"$bridge"
242 if [ -n "$netname" ]; then
243 uci delete network.
"$netname"
246 # commit uci changes and reload the network
248 /etc
/init.d
/network reload
249 #`/etc/init.d/network restart`
254 config_load
"$CONFIGURATION"
257 config_get enabled general enabled
258 if [ "$enabled" != "1" ]; then
259 echo "dcwapd is disabled in UCI"
264 # get the list of channel sets
267 for channelset
in $channelsets; do
268 if [ -n "$channelset" ]; then
269 get_channelset_enabled
"$channelset"
271 if [ "$enabled" = "1" ]; then
272 # the channel set is enabled
274 # get the list of data channels used by the channel set
275 get_datachannels
"$channelset"
277 for datachannel
in $datachannels; do
278 datachannel_up
"$datachannel"
285 procd_set_param
file /etc
/config
/dcwapd
286 procd_set_param
command dcwapd
287 procd_set_param stdout
1
288 procd_set_param stderr
1
294 # get the list of channel sets
297 for channelset
in $channelsets; do
298 if [ -n "$channelset" ]; then
299 # we don't care if it is enabled, tear it down
300 # get_channelset_enabled $channelset
302 # if [ $enabled = "1" ]; then
303 # # the channel set is enabled
305 # get the list of data channels used by the channel set
306 get_datachannels
"$channelset"
308 for datachannel
in $datachannels; do
309 datachannel_down
"$datachannel"
320 procd_add_reload_trigger dcwapd