mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-02-12 19:10:07 +01:00
198 lines
4.8 KiB
Bash
198 lines
4.8 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
# Copyright (C) 2015 Inteno Broadband Technology AB
|
|
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
|
|
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
|
|
# Author Anis Ellouze <anis.ellouze@pivasoftware.com>
|
|
include /lib/network
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
START=99
|
|
STOP=10
|
|
|
|
USE_PROCD=1
|
|
PROG="/usr/sbin/icwmpd"
|
|
|
|
EXTRA_HELP=" start [GetRPCMethods] Start icwmpd service and send GetRPCMethods"
|
|
|
|
check_url_format() {
|
|
# SCHEMA_LIST: contain list of possible schemas that could be present in the acs url
|
|
# Example: SCHEMA_LIST="http https"
|
|
SCHEMA_LIST="http"
|
|
|
|
for schema in $SCHEMA_LIST; do
|
|
dest=`echo $1 | sed 's/$schema:\/\///g' | cut -f1 -d \/ | cut -f1 -d:`
|
|
if [ "_$dest" != "_" ]; then
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
check_acs_url() {
|
|
default_acs="http://10.10.1.6:8000/openacs/acs"
|
|
acs_dhcp_discovery=`uci -q get cwmp.acs.dhcp_discovery`
|
|
url=`uci -q get cwmp.acs.url`
|
|
dhcp_url_path=`uci -q get cwmp.acs.dhcp_url_path`
|
|
if [ \( "_$acs_dhcp_discovery" = "_enable" \) -o \( "_$url" = "_" \) ];then
|
|
url=`uci -P /var/state -q get $dhcp_url_path`
|
|
echo "ACS URL from dhcp: $url"
|
|
if [ "_$url" != "_" ];then
|
|
uci -P /var/state -q set cwmp.acs.url=$url
|
|
fi
|
|
elif [ "_$url" != "_" ];then
|
|
url=`uci -q get cwmp.acs.url`
|
|
echo "ACS URL from configuration: $url"
|
|
else
|
|
url=$default_acs
|
|
echo "Using default ACS URL: $url"
|
|
if [ "_$url" != "_" ];then
|
|
uci -P /var/state -q set cwmp.acs.url=$url
|
|
fi
|
|
fi
|
|
|
|
check_url_format $url
|
|
if [ "$?" != "0" ];then
|
|
echo "Invalid ACS URL: $url"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
enable_dhcp_option43() {
|
|
local wan=$1
|
|
local discovery=0
|
|
case $2 in
|
|
enable|1) discovery=1 ;;
|
|
esac
|
|
|
|
### Ask for DHCP Option 43 only if CWMP is enabled ###
|
|
local enabled
|
|
local newreqopts=
|
|
local baseopts=
|
|
local reqopts="$(uci -q get network.$wan.reqopts)"
|
|
local proto="$(uci -q get network.$wan.proto)"
|
|
local tropts="43"
|
|
local ropt iopt
|
|
for ropt in $reqopts; do
|
|
case $ropt in
|
|
43) ;;
|
|
*) baseopts="$baseopts $ropt" ;;
|
|
esac
|
|
done
|
|
ropt=""
|
|
reqopts="$baseopts $tropts"
|
|
for ropt in $reqopts; do
|
|
case $ropt in
|
|
43) [ $discovery -eq 1 ] && newreqopts="$newreqopts $ropt" ;;
|
|
*) newreqopts="$newreqopts $ropt" ;;
|
|
esac
|
|
done
|
|
if [ $proto == "dhcp" ]; then
|
|
newreqopts="$(echo $newreqopts | tr ' ' '\n' | sort -n | tr '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')"
|
|
uci -q set network.$wan.reqopts="$newreqopts"
|
|
uci commit network
|
|
ubus call network reload
|
|
fi
|
|
########################################################
|
|
}
|
|
|
|
check_dhcp() {
|
|
local default_wan_interface dhcp_discovery url dhcp_url_path
|
|
# config_load cwmp is called in set_wan_interface function
|
|
config_get default_wan_interface cpe default_wan_interface "wan"
|
|
config_get dhcp_discovery acs dhcp_discovery "0"
|
|
config_get url acs url
|
|
config_get dhcp_url_path acs dhcp_url_path
|
|
|
|
enable_dhcp_option43 $default_wan_interface $dhcp_discovery
|
|
|
|
i=0
|
|
#if [ \( "_$dhcp_discovery" = "_enable" \) -o \( "_$url" = "_" \) ] # this is the old way, below we wait for DHCP discovery only if it is enabled
|
|
if [ "$dhcp_discovery" == "enable" -o "$dhcp_discovery" == "1" ]
|
|
then
|
|
while [ $i -le 10 ]
|
|
do
|
|
acs_url=`uci -P /var/state -q get $dhcp_url_path`
|
|
if [ "$acs_url" != "" ]
|
|
then
|
|
break
|
|
else
|
|
echo "Waiting for discovery of acs url from dhcp server ..."
|
|
sleep 10
|
|
fi
|
|
i=`expr $i + 1`
|
|
done
|
|
fi
|
|
}
|
|
|
|
set_wan_interface() {
|
|
local l3_device=""
|
|
local default_wan_interface=""
|
|
config_load cwmp
|
|
config_get default_wan_interface cpe default_wan_interface "wan"
|
|
json_load "$(ifstatus $default_wan_interface)"
|
|
json_get_var l3_device l3_device
|
|
if [ "$l3_device" != "" ];then
|
|
uci_set cwmp cpe interface "$l3_device"
|
|
uci_commit
|
|
fi
|
|
}
|
|
|
|
start_msg="Start icwmpd ..."
|
|
stop_msg="Stop icwmpd ..."
|
|
|
|
cwmp_wait_net() {
|
|
local tm=1
|
|
if [ -f /usr/sbin/nvram ]; then
|
|
while [ "$(nvram get wlmngr)" != "done" ]; do
|
|
sleep $tm
|
|
[ $tm -ge 10 ] && break
|
|
tm=$((tm+1))
|
|
done
|
|
elif [ -n "$(ubus list led.wifi_5g 2>/dev/null)" ]; then
|
|
while [ "$(ubus call led.wifi_5g status | grep -c ok)" == "0" ]; do
|
|
sleep $tm
|
|
[ $tm -ge 5 ] && break
|
|
tm=$((tm+1))
|
|
done
|
|
fi
|
|
}
|
|
|
|
cwmp_wait_dnsmasq() {
|
|
local resolvfile="$(uci -q get dhcp.@dnsmasq[0].resolvfile)"
|
|
[ -n "$resolvfile" ] || return
|
|
while [ ! -f $resolvfile ]; do
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
service_running() {
|
|
ubus -t 2 wait_for asterisk
|
|
}
|
|
|
|
start_service() {
|
|
if [ ! -f /tmp/.icwmpd_boot ]; then
|
|
touch /etc/icwmpd/.icwmpd_boot
|
|
touch /tmp/.icwmpd_boot
|
|
else
|
|
echo $start_msg;printf "\033[A" ;sleep 1
|
|
set_wan_interface
|
|
check_dhcp
|
|
check_acs_url
|
|
cwmp_wait_net
|
|
cwmp_wait_dnsmasq
|
|
procd_open_instance
|
|
procd_set_param command "$PROG"
|
|
if [ "$1" = "GetRPCMethods" ];then
|
|
procd_append_param command -g
|
|
elif [ -f /etc/icwmpd/.icwmpd_boot ]; then
|
|
procd_append_param command -b
|
|
fi
|
|
procd_set_param respawn "3" "7" "0"
|
|
procd_close_instance
|
|
fi
|
|
}
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger cwmp
|
|
}
|
|
|