-#!/bin/sh
+#!/bin/sh /etc/rc.common
-#
-# Dual Channel Wi-Fi Startup Script
-#
-# This script creates the proper network bridge configuration
-# necessary for Dual Channel Wi-Fi, and starts the dcwapd daemon
-#
+USE_PROCD=1
-verbose=1
-
-uciconfig=dcwapd
-
-result=
+START=99
+STOP=01
+CONFIGURATION=dcwapd
+VERBOSE=1
# NOTE: all functions write the result to the $result variable
+result=
get_channelsets()
{
# default to empty
result=
- channelsets=$(uci show $uciconfig | grep "=channel-set$")
+ channelsets=$(uci show $CONFIGURATION | grep "=channel-set$")
for channelset in $channelsets; do
- channelset=$(echo "$channelset" | sed -rn "s/$uciconfig\.(.*)=.*/\1/p")
+ channelset=$(echo "$channelset" | sed -rn "s/$CONFIGURATION\.(.*)=.*/\1/p")
result="$result $channelset"
done
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Channel Sets: $result" 2>&1 | logger
fi
}
# default to disabled
result=0
if [ -n "$1" ]; then
- result=$(uci get $uciconfig."$1".enabled)
+ result=$(uci get $CONFIGURATION."$1".enabled)
fi
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Channel Set \"$1\" Enabled: $result" 2>&1 | logger
fi
}
{
result=
if [ -n "$1" ]; then
- result=$(uci get $uciconfig."$1".bridge)
+ result=$(uci get $CONFIGURATION."$1".bridge)
fi
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Channel Set \"$1\" Primary Bridge: $result" 2>&1 | logger
fi
}
# default to empty
result=
if [ -n "$1" ]; then
- result=$(uci get $uciconfig."$1".data_channels)
+ result=$(uci get $CONFIGURATION."$1".data_channels)
fi
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Channel Set \"$1\" Data Channels: $result" 2>&1 | logger
fi
}
fi
# save the initial network
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Saving '$iface' initial network '$init_net'" 2>&1 | logger
fi
- uci set $uciconfig.init_net."$iface"="$init_net"
+ uci set $CONFIGURATION.init_net."$iface"="$init_net"
uci commit
# save the initial network in the result variable
{
result=
if [ -n "$1" ];then
- init_net=$(uci get $uciconfig.init_net."$iface")
+ init_net=$(uci get $CONFIGURATION.init_net."$iface")
# if the response starts with "uci: ", it was an error not the real result
err=$(echo "$init_net" | grep "^uci: ")
# no error, set the result
result=$init_net
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Got '$iface' initial network '$init_net'" 2>&1 | logger
fi
fi
datachannel_up()
{
if [ -n "$1" ]; then
- bridge=$(uci get $uciconfig."$1".bridge)
- interfaces=$(uci get $uciconfig."$1".interfaces)
- if [ $verbose -eq 1 ]; then
+ bridge=$(uci get $CONFIGURATION."$1".bridge)
+ interfaces=$(uci get $CONFIGURATION."$1".interfaces)
+ if [ $VERBOSE -eq 1 ]; then
echo "Creating Data Channel Bridge: $bridge" 2>&1 | logger
fi
get_bridge_network_name "$bridge"
netname=$result
if [ -n "$netname" ]; then
- uci set network."$netname"=interface
- uci set network."$netname".type=bridge
- uci set network."$netname".proto=static
- uci set network."$netname".bridge_empty='1'
+ uci set network."$netname"=interface
+ uci set network."$netname".type=bridge
+ uci set network."$netname".proto=static
+ uci set network."$netname".bridge_empty='1'
fi
# create the bridge
get_wifi_iface_num "$iface"
iface_num=$result
if [ -n "$iface_num" ]; then
- uci set wireless.@wifi-iface[$iface_num].network="$netname"
+ uci set wireless.@wifi-iface[$iface_num].network="$netname"
fi
# manually put the interface into the data bridge
datachannel_down()
{
if [ -n "$1" ]; then
- bridge=$(uci get $uciconfig."$1".bridge)
- interfaces=$(uci get $uciconfig."$1".interfaces)
+ bridge=$(uci get $CONFIGURATION."$1".bridge)
+ interfaces=$(uci get $CONFIGURATION."$1".interfaces)
for iface in $interfaces; do
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Deconfiguring Data Channel Interface: $iface" 2>&1 | logger
fi
brctl addif "$init_bridge" "$iface" 2>&1 | logger
# update uci with the new bridge and interface configuration
- get_wifi_iface_num "$iface"
+ get_wifi_iface_num "$iface"
iface_num=$result
get_bridge_network_name "$init_bridge"
netname=$result
if [ -n "$iface_num" ] && [ -n "$netname" ]; then
- uci set wireless.@wifi-iface[$iface_num].network="$netname"
+ uci set wireless.@wifi-iface[$iface_num].network="$netname"
fi
fi
done
- if [ $verbose -eq 1 ]; then
+ if [ $VERBOSE -eq 1 ]; then
echo "Deconfiguring Data Channel Bridge: $bridge" 2>&1 | logger
fi
get_bridge_network_name "$bridge"
netname=$result
if [ -n "$netname" ]; then
- uci delete network."$netname"
+ uci delete network."$netname"
fi
# commit uci changes and reload the network
#`/etc/init.d/network restart`
fi
}
+
+start_service() {
+ config_load "$CONFIGURATION"
+ local enabled
+
+ config_get enabled general enabled
+ if [ "$enabled" != "1" ]; then
+ echo "dcwapd is disabled in UCI"
+ return 1
+ fi
+
+ get_channelsets
+ # get the list of channel sets
+ channelsets=$result
+
+ for channelset in $channelsets; do
+ if [ -n "$channelset" ]; then
+ get_channelset_enabled "$channelset"
+ enabled=$result
+ if [ "$enabled" = "1" ]; then
+ # the channel set is enabled
+
+ # get the list of data channels used by the channel set
+ get_datachannels "$channelset"
+ datachannels=$result
+ for datachannel in $datachannels; do
+ datachannel_up "$datachannel"
+ done
+ fi
+ fi
+ done
+
+ procd_open_instance
+ procd_set_param file /etc/config/dcwapd
+ procd_set_param command dcwapd
+ procd_set_param stdout 1
+ procd_set_param stderr 1
+ procd_close_instance
+}
+
+stop_service() {
+ get_channelsets
+ # get the list of channel sets
+ channelsets=$result
+
+ for channelset in $channelsets; do
+ if [ -n "$channelset" ]; then
+# we don't care if it is enabled, tear it down
+# get_channelset_enabled $channelset
+# enabled=$result
+# if [ $enabled = "1" ]; then
+# # the channel set is enabled
+
+ # get the list of data channels used by the channel set
+ get_datachannels "$channelset"
+ datachannels=$result
+ for datachannel in $datachannels; do
+ datachannel_down "$datachannel"
+ done
+# fi
+ fi
+ done
+
+ sleep 1
+}
+
+service_triggers()
+{
+ procd_add_reload_trigger dcwapd
+}
+
+reload_service() {
+ stop
+ start
+}
-######################################################
-# Copyright 2018 EWSI
-#
-# Licensed to the public under the Apache License 2.0.
-######################################################
-# Dual Channel Wi-Fi AP Daemon configuration
-
-###################
-# General Options #
-###################
-# The "enabled" option controls the run state of the Dual Channel Wi-Fi AP Daemon
-# 0 - disabled, 1 - enabled
-# The "tmpdir" option MUST be specified
-# option tmpdir '<path_of_temp_dir>'
-
config general 'general'
option enabled 0
option tmpdir '/tmp/dcwapd'
-################
-# Channel Sets #
-################
-# Sections of type "channel-set" define a Dual Channel Wi-Fi primary channel,
-# along with it's associated data channels
-#
-# The "data_channels" option is a space-delimited list of "datachannel"-typed instance names
-
config channel-set 'channelset0'
option enabled 0
-# option enabled 1
option ssid 'OpenWrt'
option bridge 'br-lan'
option data_channels 'datachannel0'
-#config channel-set 'channelset1'
-# option enabled 0
-# option ssid 'OpenWrt2'
-# option bridge 'br-lan'
-# option data_channels 'datachannel1'
-
-#################
-# Data Channels #
-#################
-# Sections of type "datachannel" define a Dual Channel Wi-Fi data channel,
-# along with it's associated bridge and wireless interfaces
-#
-# The "interfaces" option is a space-delimited list of wireless interface names
-
config datachannel 'datachannel0'
- option ssid 'DCW0'
+ option ssid 'OpenWrt-DCW'
option bridge 'br-dc0'
- option interfaces 'wlan2 wlan5'
-
-#config datachannel 'datachannel1'
-# option ssid 'DCW1'
-# option bridge 'br-dc1'
-# option interfaces 'wlan4'
-
-####################
-# Init Net Options #
-####################
-# The "init_net" section MUST be specified
-# This section will be used to save and restore the state of the data interfaces
-config init_net 'init_net'
-
-###############
-# Filter Sets #
-###############
-# Sections of type "filter-set" define a Dual Channel Wi-Fi group of filters,
-# along with it's associated MAC address and filter rules
-#
-# The "TFP_Default" filter set MUST be defined, although it is not required
-# to have any associated filter rules
-# The "TFP_Default" filter mac option can have the value of '*', meaning match
-# all MAC addresses
-#
-# The "filters" option is a space-delimited list of "filter"-typed instance names
+ option interfaces ''
config filter-set 'TFP_Default'
option mac '*'
option filters 'filter0 filter1'
-#config filter-set 'filterset0'
-# option mac '00:00:BE:EF:F0:0D'
-# option filters 'filter2'
-
-
-################
-# Filter Rules #
-################
-# Sections of type "filter" define a Dual Channel Wi-Fi filter,
-# along with it's associated filter parameters
-#
-# Any or all of the filter options may be set to '*' to match
-# all values
-
config filter 'filter0'
option packet_size '*'
option source_ip '*'
option source_port '443'
option protocol 'tcp'
option dest_port '*'
-
-#config filter 'filter2'
-# option packet_size '*'
-# option source_ip '*'
-# option source_port '22'
-# option protocol 'tcp'
-# option dest_port '*'