mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-02-05 15:00:11 +01:00
330 lines
9.7 KiB
Bash
330 lines
9.7 KiB
Bash
#!/bin/sh
|
|
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
|
|
# Copyright (C) 2013 Inteno Broadband Technology AB
|
|
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
|
|
|
|
get_wan_device_wan_mng_enable() {
|
|
local val=""
|
|
local intf="$1"
|
|
|
|
json_load "$(ifstatus $intf)"
|
|
json_get_var up up
|
|
val="$up"
|
|
echo $val
|
|
}
|
|
|
|
set_wan_device_wan_mng_enable() {
|
|
local val="$1"
|
|
local intf="$2"
|
|
if [ "$val" -eq 0 ]; then
|
|
ubus call network.interface.wan down '{}' &
|
|
elif [ "$val" -eq 1 ]; then
|
|
ubus call network.interface.wan up '{}' &
|
|
fi
|
|
}
|
|
|
|
get_wan_device_mng_status() {
|
|
# TODO: Unconfigured ; Connecting ; Connected ; PendingDisconnect ; Disconneting ; Disconnected
|
|
local val=""
|
|
local intf="$1"
|
|
|
|
json_load "$(ifstatus $intf)"
|
|
json_get_var up up
|
|
if [ "$up" = "1" ];then
|
|
json_get_var uptime uptime
|
|
json_get_var pending pending
|
|
else
|
|
uptime=0
|
|
fi
|
|
if [ $uptime -gt 0 ];then
|
|
val="Connected"
|
|
elif [ "$pending" = "1" ];then
|
|
val="Pending Disconnect"
|
|
else
|
|
val="Disconnected"
|
|
fi
|
|
echo $val
|
|
}
|
|
|
|
get_wan_device_ppp_status() {
|
|
# TODO: Unconfigured ; Connecting ; Connected ; PendingDisconnect ; Disconneting ; Disconnected
|
|
local val=""
|
|
local intf="$1"
|
|
|
|
json_load "$(ifstatus $intf)"
|
|
json_get_var up up
|
|
if [ "$up" = "1" ];then
|
|
json_get_var uptime uptime
|
|
json_get_var pending pending
|
|
else
|
|
uptime=0
|
|
fi
|
|
if [ $uptime -gt 0 ];then
|
|
val="Connected"
|
|
elif [ $pending = 1 ];then
|
|
val="Pending Disconnect"
|
|
else
|
|
val="Disconnected"
|
|
fi
|
|
echo $val
|
|
}
|
|
|
|
get_wan_device_mng_interface_ip() {
|
|
local val=""
|
|
local intf="$1"
|
|
|
|
if [ -z "$default_wan_device_mng_interface_ip" ]; then
|
|
network_get_ipaddr val $intf
|
|
else
|
|
val=$default_wan_device_mng_interface_ip
|
|
fi
|
|
echo $val
|
|
}
|
|
|
|
get_wan_device_ppp_interface_ip() {
|
|
local val=""
|
|
local intf="$1"
|
|
|
|
if [ -z "$default_wan_device_mng_interface_ip" ]; then
|
|
network_get_ipaddr val $intf
|
|
else
|
|
val=$default_wan_device_mng_interface_ip
|
|
fi
|
|
echo $val
|
|
}
|
|
|
|
get_wan_device_mng_interface_mac() {
|
|
local val=""
|
|
local intf="$1"
|
|
local device
|
|
|
|
json_load "$(ifstatus $intf)"
|
|
json_get_var device device
|
|
json_load "$(devstatus $device)"
|
|
json_get_var macaddr macaddr
|
|
val="$macaddr"
|
|
echo $val
|
|
}
|
|
|
|
get_wan_device_wan_ppp_enable() {
|
|
local val=""
|
|
local intf="$1"
|
|
local up
|
|
|
|
json_load "$(ifstatus $intf)"
|
|
json_get_var up up
|
|
val="$up"
|
|
echo $val
|
|
}
|
|
|
|
set_wan_device_wan_ppp_enable() {
|
|
local val="$1"
|
|
local intf="$2"
|
|
if [ "$val" -eq 0 ]; then
|
|
ubus call network.interface.wan down '{}' &
|
|
elif [ "$val" -eq 1 ]; then
|
|
ubus call network.interface.wan up '{}' &
|
|
fi
|
|
}
|
|
|
|
get_wan_device_wan_access_type() {
|
|
local val=""
|
|
local intf="$1"
|
|
|
|
json_load "$(ifstatus $intf)"
|
|
json_get_var device device
|
|
if [ "${device:0:3}" = "eth" ];then
|
|
val="Ethernet"
|
|
elif [ "${device:0:3}" = "atm" -o "${device:0:3}" = "ptm" ];then
|
|
val="DSL"
|
|
fi
|
|
echo $val
|
|
}
|
|
|
|
get_wan_device_wan_dsl_interface_config_status() {
|
|
local val=""
|
|
local intf="$1"
|
|
adsl_shown=`adsl info --stats|grep "^Status:"|cut -f2 -d:|sed 's/\t*//g'|sed 's/^ *//g'|sed 's/ *$//g'`
|
|
case "$adsl_shown" in
|
|
"Showtime")
|
|
val="Up"
|
|
;;
|
|
"Training")
|
|
val="Initializing"
|
|
;;
|
|
"Channel Analysis")
|
|
val="EstablishingLink"
|
|
;;
|
|
"Disabled")
|
|
val="Disabled"
|
|
;;
|
|
esac
|
|
echo $val
|
|
}
|
|
|
|
get_wan_device_wan_dsl_interface_config_modulation_type() {
|
|
local val=""
|
|
local intf="$1"
|
|
adsl_shown=`adsl info --stats|grep "Mode:"|cut -f2 -d:|sed 's/\t*//g'|sed 's/^ *//g'|cut -f1 -d ' '`
|
|
case "$adsl_shown" in
|
|
G.Dmt)
|
|
val="ADSL_G.dmt"
|
|
;;
|
|
G.lite)
|
|
val="ADSL_G.lite"
|
|
;;
|
|
T1.413)
|
|
val="ADSL_ANSI_T1 .413"
|
|
;;
|
|
ADSL2)
|
|
val="ADSL_G.dmt.bis"
|
|
;;
|
|
AnnexL)
|
|
val="ADSL_re-adsl"
|
|
;;
|
|
ADSL2+)
|
|
val="ADSL_2plus"
|
|
;;
|
|
*)
|
|
val="$adsl_shown"
|
|
;;
|
|
esac
|
|
echo $val
|
|
}
|
|
|
|
get_wan_logical_intf() {
|
|
local intf="$1"
|
|
local list_intf=`handle_wan_interface|sort -u|cut -f1 -d:`
|
|
for i in $list_intf;do
|
|
if [ "`echo $i|cut -c1-3`" != "`echo $prev_i|cut -c1-3`" ];then
|
|
n=1
|
|
elif [ "$i" != "$prev_i" ];then
|
|
let n=$n+1
|
|
fi
|
|
if [ "$i" = "$intf" ];then
|
|
echo $n
|
|
return 0
|
|
fi
|
|
prev_i=$i
|
|
done
|
|
}
|
|
|
|
handle_wan_interface() {
|
|
for config in `ubus list|sed -n 's/network\.interface\.//p'`;do
|
|
local ifname="`$UCI_GET network.$config.ifname|cut -f1 -d ' '`"
|
|
local _orig_ifname="`$UCI_GET network.$config._orig_ifname|cut -f1 -d ' '`"
|
|
local logical_intf
|
|
local instance
|
|
local device
|
|
json_load "$(ifstatus $config)"
|
|
json_get_var device device
|
|
if [ "$device" != "" ];then
|
|
logical_intf=$device
|
|
elif [ "$_orig_ifname" != "" ];then
|
|
logical_intf=$_orig_ifname
|
|
else
|
|
logical_intf=$ifname
|
|
fi
|
|
if [ "`echo $logical_intf|grep eth`" != "" ];then
|
|
instance=1
|
|
elif [ "`echo $logical_intf|grep atm`" != "" ];then
|
|
instance=2
|
|
elif [ "`echo $logical_intf|grep ptm`" != "" ];then
|
|
instance=3
|
|
fi
|
|
if [ "`$UCI_GET network.$config.is_lan`" != "1" ];then
|
|
echo $logical_intf:$instance:$config
|
|
fi
|
|
done
|
|
}
|
|
|
|
get_wandevice_dev_parent_objects() {
|
|
local dev="$1"
|
|
local notif_permission="$2"
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev." "0" "$notif_permission"
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice." "0" "$notif_permission"
|
|
}
|
|
|
|
get_cache_InternetGatewayDevice_WANDevice() {
|
|
local list_interface=`handle_wan_interface|sort -u`
|
|
local logical_intf
|
|
local dev=0
|
|
local wan=0
|
|
local wan_ppp=1
|
|
local wan_ip=1
|
|
local default_wan=`$UCI_GET cwmp.cpe.default_wan_interface`
|
|
local dev_notif_permission=""
|
|
local prev_wan=""
|
|
local prev_dev=""
|
|
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice." "0" "0"
|
|
for intf in $list_interface;do
|
|
iface=`echo $intf|cut -f3 -d:`
|
|
dev=`echo $intf|cut -f2 -d:`
|
|
logical_intf=`echo $intf|cut -f1 -d:`
|
|
wan=`get_wan_logical_intf $logical_intf`
|
|
local forced_inform_eip=""
|
|
local forced_notify=""
|
|
local notif_permission=""
|
|
if [ "$default_wan" = "$iface" ];then
|
|
forced_inform_eip="1"
|
|
forced_notify="2"
|
|
notif_permission="0"
|
|
dev_notif_permission="0"
|
|
fi
|
|
if [ "$prev_dev" != "$dev" -a "$prev_dev" != "" ];then
|
|
wan_ip=1
|
|
wan_ppp=1
|
|
get_wandevice_dev_parent_objects "$prev_dev" "$dev_notif_permission"
|
|
dev_notif_permission=""
|
|
fi
|
|
if [ "$prev_wan" != "$wan" -a "$prev_wan" != "" ];then
|
|
wan_ip=1
|
|
wan_ppp=1
|
|
fi
|
|
proto=`$UCI_GET network.$iface.proto`
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan." "0" "$notif_permission"
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANCommonInterfaceConfig." "0"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANCommonInterfaceConfig.WANAccessType" "0" "get_wan_device_wan_access_type $iface"
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANDSLInterfaceConfig." "0"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANDSLInterfaceConfig.Status" "0" "" "" "get_wan_device_wan_dsl_interface_config_status"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANDSLInterfaceConfig.ModulationType" "0" "get_wan_device_wan_dsl_interface_config_modulation_type"
|
|
|
|
if [ "$proto" = "dhcp" -o "$proto" = "static" ];then
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANIPConnection." "0" "$notif_permission"
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANIPConnection.$wan_ip." "0" "$notif_permission"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANIPConnection.$wan_ip.Enable" "1" "" "set_wan_device_wan_mng_enable \$val $iface" "get_wan_device_wan_mng_enable $iface" "xsd:boolean"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANIPConnection.$wan_ip.ConnectionStatus" "0" "" "" "get_wan_device_mng_status $iface"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANIPConnection.$wan_ip.ExternalIPAddress" "0" "" "" "get_wan_device_mng_interface_ip $iface" "" "$notif_permission" "$forced_inform_eip" "$forced_notify"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANIPConnection.$wan_ip.MACAddress" "0" "get_wan_device_mng_interface_mac $iface"
|
|
let wan_ip=$wan_ip+1
|
|
fi
|
|
if [ "$proto" = "pppoa" -o "$proto" = "pppoe" ];then
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANPPPConnection." "0" "$notif_permission"
|
|
get_object_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANPPPConnection.$wan_ppp." "0" "$notif_permission"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANPPPConnection.$wan_ppp.Enable" "1" "" "set_wan_device_wan_ppp_enable \$val $iface" "get_wan_device_wan_ppp_enable $iface" "xsd:boolean"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANPPPConnection.$wan_ppp.ConnectionStatus" "0" "" "" "get_wan_device_ppp_status $iface"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANPPPConnection.$wan_ppp.ExternalIPAddress" "0" "" "" "get_wan_device_ppp_interface_ip $iface" "" "$notif_permission" "$forced_inform_eip" "$forced_notify"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANPPPConnection.$wan_ppp.Username" "1" "$UCI_GET network.$iface.username" "$UCI_SET network.$iface.username=\$val"
|
|
get_param_cache_generic "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANPPPConnection.$wan_ppp.Password" "1" "" "$UCI_SET network.$iface.password=\$val" "" "" "" "" "" "1"
|
|
let wan_ppp=$wan_ppp+1
|
|
fi
|
|
prev_wan="$wan"
|
|
prev_dev="$dev"
|
|
done
|
|
if [ "$prev_dev" != "" ]; then
|
|
get_wandevice_dev_parent_objects "$prev_dev" "$dev_notif_permission"
|
|
fi
|
|
}
|
|
|
|
get_dynamic_InternetGatewayDevice_WANDevice() {
|
|
return $FAULT_CPE_NO_FAULT
|
|
}
|
|
|
|
add_object_InternetGatewayDevice_WANDevice() {
|
|
return $FAULT_CPE_INVALID_PARAMETER_NAME
|
|
}
|
|
|
|
delete_object_InternetGatewayDevice_WANDevice() {
|
|
return $FAULT_CPE_INVALID_PARAMETER_NAME
|
|
}
|