freecwmp
[Top] [All Lists]

[PATCH v2 10/10] Use ubus for set parameter attribute

To: freecwmp@linux-mips.org
Subject: [PATCH v2 10/10] Use ubus for set parameter attribute
From: Mohamed Kallel <mohamed.kallel@pivasoftware.com>
Date: Fri, 28 Dec 2012 16:59:47 +0100
Cc: freecwmp@lukaperkov.net, jogo@openwrt.org, Mohamed <mohamed.kallel@pivasoftware.com>, Ahmed Zribi <ahmed.zribi@pivasoftware.com>
In-reply-to: <1356710387-3043-1-git-send-email-mohamed.kallel@pivasoftware.com>
Original-recipient: rfc822;freecwmp@linux-mips.org
References: <1356710387-3043-1-git-send-email-mohamed.kallel@pivasoftware.com>
Sender: freecwmp-bounce@linux-mips.org
From: Mohamed <mohamed.kallel@pivasoftware.com>

Update set parameter attribute in order to get external command output from Ubus
Contributed by Inteno Broadband Technology AB & PIVA SOFTWARE

Signed-off-by: Mohamed Kallel <mohamed.kallel@pivasoftware.com>
Signed-off-by: Ahmed Zribi <ahmed.zribi@pivasoftware.com>
---
 ext/openwrt/scripts/freecwmp.sh                 |   42 +++-
 ext/openwrt/scripts/functions/common            |    3 +
 ext/openwrt/scripts/functions/device_hosts      |    2 +
 ext/openwrt/scripts/functions/device_info       |   11 +
 ext/openwrt/scripts/functions/device_ip         |    2 +
 ext/openwrt/scripts/functions/device_routing    |    2 +
 ext/openwrt/scripts/functions/device_users      |    2 +
 ext/openwrt/scripts/functions/lan_device        |   57 +++++-
 ext/openwrt/scripts/functions/management_server |  259 +++++++++++++++++++----
 ext/openwrt/scripts/functions/misc              |    2 +
 ext/openwrt/scripts/functions/wan_device        |   71 ++++++-
 src/external.c                                  |   16 ++
 src/external.h                                  |    2 +
 src/ubus.c                                      |   31 +++
 src/xml.c                                       |   25 ++-
 15 files changed, 458 insertions(+), 69 deletions(-)

diff --git a/ext/openwrt/scripts/freecwmp.sh b/ext/openwrt/scripts/freecwmp.sh
index 294f2f0..22e524a 100644
--- a/ext/openwrt/scripts/freecwmp.sh
+++ b/ext/openwrt/scripts/freecwmp.sh
@@ -24,7 +24,7 @@ USAGE: $0 [flags] command [parameter] [values]
 command:
   get [value|notification|tags|name|all]
   set [value|notification|tag]
-  apply [value]
+  apply [value|notification]
   download
   factory_reset
   reboot
@@ -93,7 +93,13 @@ case "$1" in
                action="reboot"
                ;;
        apply)
-               action="apply_value"
+               if [ "$2" = "notification" ]; then
+                       action="apply_notification"
+               elif [ "$2" = "value" ]; then
+                       action="apply_value"
+               else
+                       action="apply_value"
+               fi
                ;;
 esac
 
@@ -110,7 +116,8 @@ get_value_functions=""
 set_value_functions=""
 get_name_functions=""
 get_notification_functions=""
-
+set_notification_functions=""
+       
 load_script() {
        . $1 
 }
@@ -120,6 +127,7 @@ load_function() {
        set_value_functions="$set_value_functions set_$1"
        get_name_functions="$get_name_functions get_$1_name"
        get_notification_functions="$get_notification_functions 
get_$1_notification"
+       set_notification_functions="$set_notification_functions 
set_$1_notification"
 }
 
 handle_scripts() {
@@ -277,8 +285,26 @@ if [ "$action" = "get_notification" -o "$action" = 
"get_all" ]; then
 fi
 
 if [ "$action" = "set_notification" ]; then
-       freecwmp_set_parameter_notification "$__arg1" "$__arg2"
-       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit
+       if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
+               __tmp_arg="Device."
+               # TODO: don't check only string length ; but this is only used
+               #       for getting correct prefix of CWMP parameter anyway
+               if [  ${#__arg1} -lt ${#__tmp_arg} ]; then
+                       echo "CWMP parameters usualy begin with 
'InternetGatewayDevice.' or 'Device.'     "
+                       echo "if you want to force script execution with 
provided parameter use '-f' flag."
+                       exit -1
+               fi
+       fi
+       freecwmp_check_fault "$__arg1"
+       fault_code="$?"
+       if [ "$fault_code" = "0" ]; then
+               freecwmp_execute_functions "$set_notification_functions" 
"$__parm" "$__arg2"
+               fault_code="$?"
+       fi
+       if [ "$fault_code" != "0" ]; then
+               let fault_code=$fault_code+9000
+               freecwmp_set_parameter_fault "$__arg1" "$fault_code"
+       fi
 fi
 
 if [ "$action" = "get_tags" -o "$action" = "get_all" ]; then
@@ -325,7 +351,7 @@ if [ "$action" = "reboot" ]; then
        fi
 fi
 
-if [ "$action" = "apply_value" ]; then
+if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then
        __fault_count=`cat /var/state/freecwmp 2> /dev/null |wc -l 2> /dev/null`
        let __fault_count=$__fault_count/3
        if [ "$__fault_count" = "0" ]; then
@@ -334,6 +360,9 @@ if [ "$action" = "apply_value" ]; then
                if [ "$action" = "apply_value" ]; then 
                        ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 
set_parameter_values_status '{ "status": "0" }' 2> /dev/null
                fi
+               if [ "$action" = "apply_notification" ]; then 
+                       freecwmp_fault_output "" "" "0"
+               fi
        else
                let n=$__fault_count-1
                for i in `seq 0 $n`
@@ -341,6 +370,7 @@ if [ "$action" = "apply_value" ]; then
                        local parm=`/sbin/uci ${UCI_CONFIG_DIR:+-c 
$UCI_CONFIG_DIR} -P /var/state get freecwmp.@fault[$i].parameter 2> /dev/null`
                        local fault_code=`/sbin/uci ${UCI_CONFIG_DIR:+-c 
$UCI_CONFIG_DIR} -P /var/state get freecwmp.@fault[$i].fault_code 2> /dev/null`
                        freecwmp_fault_output "$parm" "$fault_code"
+                       if [ "$action" = "apply_notification" ]; then break; fi
                done
                rm -rf /var/state/freecwmp 2> /dev/null
                /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} revert freecwmp
diff --git a/ext/openwrt/scripts/functions/common 
b/ext/openwrt/scripts/functions/common
index f6a3e8b..bb883fc 100644
--- a/ext/openwrt/scripts/functions/common
+++ b/ext/openwrt/scripts/functions/common
@@ -78,6 +78,9 @@ case "$action" in
        apply_value)
        ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET}  call tr069 
set_parameter_values_fault '{ "parameter": "'$parameter'", "fault_code": 
"'$fault_code'" }' 2> /dev/null
        ;;
+       apply_notification)
+       ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET}  call tr069 
set_parameter_attributes '{ "success": "'$success'", "fault_code": 
"'$fault_code'" }' 2> /dev/null
+       ;;
 esac
 }
 
diff --git a/ext/openwrt/scripts/functions/device_hosts 
b/ext/openwrt/scripts/functions/device_hosts
index 330125a..1450135 100644
--- a/ext/openwrt/scripts/functions/device_hosts
+++ b/ext/openwrt/scripts/functions/device_hosts
@@ -195,3 +195,5 @@ get_device_hosts_name() { return $E_INVALID_PARAMETER_NAME; 
}
 get_device_hosts_notification() { return $E_INVALID_PARAMETER_NAME; }
 
 set_device_hosts() { return $E_INVALID_PARAMETER_NAME; }
+
+set_device_hosts_notification() { return $E_INVALID_PARAMETER_NAME; }
diff --git a/ext/openwrt/scripts/functions/device_info 
b/ext/openwrt/scripts/functions/device_info
index 37b930e..74f5e11 100644
--- a/ext/openwrt/scripts/functions/device_info
+++ b/ext/openwrt/scripts/functions/device_info
@@ -403,6 +403,10 @@ esac
 return $E_INVALID_PARAMETER_NAME
 }
 
+set_device_info_notification() {
+return $E_INVALID_PARAMETER_NAME
+}
+
 check_parameter_device_info_generic() {
 case "$1" in
        InternetGatewayDevice.DeviceInfo.ModelName|\
@@ -468,3 +472,10 @@ set_device_info_generic() {
        freecwmp_set_parameter_value "$1" "$2"
        return 0
 }
+
+set_device_info_generic_notification() {
+       check_parameter_device_info_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 
]; then return $E_INVALID_PARAMETER_NAME; fi
+
+       freecwmp_set_parameter_notification "$1" "$2"
+       return 0
+}
diff --git a/ext/openwrt/scripts/functions/device_ip 
b/ext/openwrt/scripts/functions/device_ip
index dc2147d..e5a4ea9 100644
--- a/ext/openwrt/scripts/functions/device_ip
+++ b/ext/openwrt/scripts/functions/device_ip
@@ -128,3 +128,5 @@ get_device_ip_name() { return $E_INVALID_PARAMETER_NAME; }
 get_device_ip_notification() { return $E_INVALID_PARAMETER_NAME; }
 
 set_device_ip() { return $E_INVALID_PARAMETER_NAME; }
+
+set_device_ip_notification() { return $E_INVALID_PARAMETER_NAME; }
diff --git a/ext/openwrt/scripts/functions/device_routing 
b/ext/openwrt/scripts/functions/device_routing
index dff6f4d..0f40592 100644
--- a/ext/openwrt/scripts/functions/device_routing
+++ b/ext/openwrt/scripts/functions/device_routing
@@ -358,3 +358,5 @@ get_device_routing_name() { return 
$E_INVALID_PARAMETER_NAME; }
 get_device_routing_notification() { return $E_INVALID_PARAMETER_NAME; }
 
 set_device_routing() { return $E_INVALID_PARAMETER_NAME; }
+
+set_device_routing_notification() { return $E_INVALID_PARAMETER_NAME; }
diff --git a/ext/openwrt/scripts/functions/device_users 
b/ext/openwrt/scripts/functions/device_users
index f8264e0..22c9309 100644
--- a/ext/openwrt/scripts/functions/device_users
+++ b/ext/openwrt/scripts/functions/device_users
@@ -132,3 +132,5 @@ get_device_users_name() { return $E_INVALID_PARAMETER_NAME; 
}
 get_device_users_notification() { return $E_INVALID_PARAMETER_NAME; }
 
 set_device_users() { return $E_INVALID_PARAMETER_NAME; }
+
+set_device_users_notification() { return $E_INVALID_PARAMETER_NAME; }
diff --git a/ext/openwrt/scripts/functions/lan_device 
b/ext/openwrt/scripts/functions/lan_device
index 5d5c84f..f7b91c1 100644
--- a/ext/openwrt/scripts/functions/lan_device
+++ b/ext/openwrt/scripts/functions/lan_device
@@ -34,13 +34,22 @@ esac
 set_wlan_enable() {
 local num="$1"
 local val="$2"
-if [ "$val" = "1" ]; then
-       val="0"
-else
-       val="1"
-fi
-delay_command "wifi" "wifi" "45"
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
wireless.@wifi-device[$num].disabled="$val"
+local parm="InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.Enable"
+case $action in
+       set_value)
+       if [ "$val" = "1" ]; then
+               val="0"
+       else
+               val="1"
+       fi
+       delay_command "wifi" "wifi" "45"
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
wireless.@wifi-device[$num].disabled="$val"
+       ;;
+       set_notification)
+       let num=$num+1
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_wlan_ssid() {
@@ -69,8 +78,17 @@ esac
 set_wlan_ssid() {
 local num="$1"
 local val="$2"
-delay_command "wifi" "wifi" "45"
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
wireless.@wifi-iface[$num].ssid="$val"
+local parm="InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num.SSID"
+case $action in
+       set_value)
+       delay_command "wifi" "wifi" "45"
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
wireless.@wifi-iface[$num].ssid="$val"
+       ;;
+       set_notification)
+       let num=$num+1
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_lan_device() {
@@ -233,3 +251,24 @@ case "$1" in
 esac
 return $E_INVALID_PARAMETER_NAME
 }
+
+set_lan_device_notification() {
+case "$1" in
+       InternetGatewayDevice.LANDevice.|\
+       InternetGatewayDevice.LANDevice.1.|\
+       InternetGatewayDevice.LANDevice.1.WLANConfiguration.|\
+       InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.)
+       freecwmp_set_parameter_notification "$1" "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.Enable)
+       set_wlan_enable 0 "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID)
+       set_wlan_ssid 0 "$2"
+       return 0
+       ;;
+esac
+return $E_INVALID_PARAMETER_NAME
+}
diff --git a/ext/openwrt/scripts/functions/management_server 
b/ext/openwrt/scripts/functions/management_server
index 1dd69e1..f58447b 100644
--- a/ext/openwrt/scripts/functions/management_server
+++ b/ext/openwrt/scripts/functions/management_server
@@ -31,33 +31,42 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_url() {
-local url=$1
-local scheme
-local hostname
-local path
-local port
-
-scheme=`echo $url | awk -F "://" '{ print $1 }'`
-hostname=`echo $url | awk -F "$scheme://" '{ print $2 }' | awk -F ":" '{ print 
$1 }' | awk -F "/" '{ print $1 }'`
-port=`echo $url | awk -F "$scheme://$hostname:" '{ print $2 }' | awk -F '/' '{ 
print $1 }'`
-
-if [ -z "$port" ]; then
-       port=80
-       path=`echo $url | awk -F "$scheme://$hostname" '{ print $2 }'`
-else
-       path=`echo $url | awk -F "$scheme://$hostname:$port" '{ print $2 }'`
-fi
-
-if [ -z "$path" ]; then
-       path="/"
-fi
-
-set_management_server_x_freecwmp_org__acs_scheme $scheme
-set_management_server_x_freecwmp_org__acs_hostname $hostname
-set_management_server_x_freecwmp_org__acs_port $port
-set_management_server_x_freecwmp_org__acs_path $path
-
-ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 inform '{ "event": 
"value_change" }' &
+local parm="InternetGatewayDevice.ManagementServer.URL"
+case "$action" in
+       set_value)
+       local url=$1
+       local scheme
+       local hostname
+       local path
+       local port
+       
+       scheme=`echo $url | awk -F "://" '{ print $1 }'`
+       hostname=`echo $url | awk -F "$scheme://" '{ print $2 }' | awk -F ":" 
'{ print $1 }' | awk -F "/" '{ print $1 }'`
+       port=`echo $url | awk -F "$scheme://$hostname:" '{ print $2 }' | awk -F 
'/' '{ print $1 }'`
+       
+       if [ -z "$port" ]; then
+               port=80
+               path=`echo $url | awk -F "$scheme://$hostname" '{ print $2 }'`
+       else
+               path=`echo $url | awk -F "$scheme://$hostname:$port" '{ print 
$2 }'`
+       fi
+       
+       if [ -z "$path" ]; then
+               path="/"
+       fi
+       
+       set_management_server_x_freecwmp_org__acs_scheme $scheme
+       set_management_server_x_freecwmp_org__acs_hostname $hostname
+       set_management_server_x_freecwmp_org__acs_port $port
+       set_management_server_x_freecwmp_org__acs_path $path
+       
+       ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 inform '{ "event": 
"value_change" }' &
+       ;;
+       set_notification)
+       local val=$1
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_username() {
@@ -79,7 +88,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_username() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].username="$1"
+local val=$1
+local parm="InternetGatewayDevice.ManagementServer.Username"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].username="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_password() {
@@ -101,7 +119,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_password() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].password="$1"
+local val=$1
+local parm="InternetGatewayDevice.ManagementServer.Password"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].password="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_periodic_inform_enable() {
@@ -124,8 +151,16 @@ freecwmp_output "$parm" "$val" "$permissions" "$type"
 }
 
 set_management_server_periodic_inform_enable() {
+local val=$1
 local parm="InternetGatewayDevice.ManagementServer.PeriodicInformEnable"
-freecwmp_set_parameter_value "$parm" "$1"
+case "$action" in
+       set_value)
+       freecwmp_set_parameter_value "$parm" "$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_periodic_inform_interval() {
@@ -148,8 +183,16 @@ freecwmp_output "$parm" "$val" "$permissions" "$type"
 }
 
 set_management_server_periodic_inform_interval() {
+local val=$1
 local parm="InternetGatewayDevice.ManagementServer.PeriodicInformInterval"
-freecwmp_set_parameter_value "$parm" "$1"
+case "$action" in
+       set_value)
+       freecwmp_set_parameter_value "$parm" "$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_connection_request_url() {
@@ -204,7 +247,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_connection_request_username() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@local[0].username="$1"
+local val=$1
+local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@local[0].username="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_connection_request_password() {
@@ -226,7 +278,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_connection_request_password() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@local[0].password="$1"
+local val=$1
+local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@local[0].password="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 # TODO: InternetGatewayDevice.ManagementServer.PeriodicInformTime
@@ -249,7 +310,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_x_freecwmp_org__acs_scheme() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].scheme="$1"
+local val=$1
+local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Scheme"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].scheme="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_x_freecwmp_org__acs_hostname() {
@@ -271,11 +341,20 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_x_freecwmp_org__acs_hostname() {
-if [ -z "$default_management_server_acs_hostname" ]; then
-       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].hostname="$1"
-else
-       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].hostname="$default_management_server_acs_hostname"
-fi
+local val=$1
+local 
parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Hostname"
+case "$action" in
+       set_value)
+       if [ -z "$default_management_server_acs_hostname" ]; then
+                       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].hostname="$val"
+       else
+               /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].hostname="$default_management_server_acs_hostname"
+       fi
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_x_freecwmp_org__acs_port() {
@@ -297,7 +376,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_x_freecwmp_org__acs_port() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set freecwmp.@acs[0].port="$1"
+local val=$1
+local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Port"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].port="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_x_freecwmp_org__acs_path() {
@@ -319,7 +407,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_x_freecwmp_org__acs_path() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set freecwmp.@acs[0].path="$1"
+local val=$1
+local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Path"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@acs[0].path="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server_x_freecwmp_org__connection_request_port() {
@@ -341,7 +438,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_management_server_x_freecwmp_org__connection_request_port() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@local[0].port="$1"
+local val=$1
+local 
parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__Connection_Request_Port"
+case "$action" in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
freecwmp.@local[0].port="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_management_server() {
@@ -726,6 +832,68 @@ esac
 return $E_INVALID_PARAMETER_NAME
 }
 
+set_management_server_notification() {
+case "$1" in
+       InternetGatewayDevice.ManagementServer.)
+       freecwmp_set_parameter_notification "$1" "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.URL)
+       set_management_server_url "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.Username)
+       set_management_server_username "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.Password)
+       set_management_server_password "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.PeriodicInformEnable)
+       set_management_server_periodic_inform_enable "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.PeriodicInformInterval)
+       set_management_server_periodic_inform_interval "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.ConnectionRequestURL)
+       set_management_server_connection_request_url "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.ConnectionRequestUsername)
+       set_management_server_connection_request_username "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.ConnectionRequestPassword)
+       set_management_server_connection_request_password "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Scheme)
+       set_management_server_x_freecwmp_org__acs_scheme "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Hostname)
+       set_management_server_x_freecwmp_org__acs_hostname "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Port)
+       set_management_server_x_freecwmp_org__acs_port "$2"
+       return 0
+       ;;
+       InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Path)
+       set_management_server_x_freecwmp_org__acs_path "$2"
+       return 0
+       ;;
+       
InternetGatewayDevice.ManagementServer.X_freecwmp_org__Connection_Request_Port)
+       set_management_server_x_freecwmp_org__connection_request_port "$2"
+       return 0
+       ;;
+esac
+return $E_INVALID_PARAMETER_NAME
+}
+
 check_parameter_management_server_generic() {
 case "$1" in
        InternetGatewayDevice.ManagementServer.UpgradesManaged)
@@ -766,3 +934,10 @@ set_management_server_generic() {
        freecwmp_set_parameter_value "$1" "$2"
        return 0
 }
+
+set_management_server_generic_notification() {
+       check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" 
-eq 1 ]; then return $E_INVALID_PARAMETER_NAME; fi
+
+       freecwmp_set_parameter_notification "$1" "$2"
+       return 0
+}
diff --git a/ext/openwrt/scripts/functions/misc 
b/ext/openwrt/scripts/functions/misc
index 457e284..cd75a5a 100644
--- a/ext/openwrt/scripts/functions/misc
+++ b/ext/openwrt/scripts/functions/misc
@@ -32,3 +32,5 @@ get_misc_name () { return $E_INVALID_PARAMETER_NAME; }
 get_misc_notification () { return $E_INVALID_PARAMETER_NAME; }
 
 set_misc() { return $E_INVALID_PARAMETER_NAME; }
+
+set_misc_notification () { return $E_INVALID_PARAMETER_NAME; }
diff --git a/ext/openwrt/scripts/functions/wan_device 
b/ext/openwrt/scripts/functions/wan_device
index 699450f..15c3890 100644
--- a/ext/openwrt/scripts/functions/wan_device
+++ b/ext/openwrt/scripts/functions/wan_device
@@ -90,13 +90,21 @@ freecwmp_output "$parm" "$val" "$permissions" "$type"
 
 set_wan_device_wan_ppp_enable() {
 local val=$1
-if [ "$val" -eq 0 ]; then
-       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set network.wan.auto=0
-       ifdown wan &
-elif [ "$val" -eq 1 ]; then
-       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set network.wan.auto=1
-       ifup wan &
-fi
+local 
parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable"
+case $action in
+       set_value)
+       if [ "$val" -eq 0 ]; then
+               /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
network.wan.auto=0
+               ifdown wan &
+       elif [ "$val" -eq 1 ]; then
+               /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
network.wan.auto=1
+               ifup wan &
+       fi
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_wan_device_wan_ppp_username() {
@@ -118,7 +126,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_wan_device_wan_ppp_username() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set network.wan.username="$1"
+local val=$1
+local 
parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username"
+case $action in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
network.wan.username="$val"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_wan_device_wan_ppp_password() {
@@ -140,7 +157,16 @@ freecwmp_output "$parm" "$val" "$permissions"
 }
 
 set_wan_device_wan_ppp_password() {
-/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set network.wan.password="$1"
+local val=$1
+local 
parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password"
+case $action in
+       set_value)
+       /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set 
network.wan.password="$1"
+       ;;
+       set_notification)
+       freecwmp_set_parameter_notification "$parm" "$val"
+       ;;
+esac
 }
 
 get_wan_device() {
@@ -463,3 +489,30 @@ case "$1" in
 esac
 return $E_INVALID_PARAMETER_NAME
 }
+
+set_wan_device_notification() {
+case "$1" in
+       InternetGatewayDevice.WANDevice.|\
+       InternetGatewayDevice.WANDevice.1.|\
+       InternetGatewayDevice.WANDevice.1.WANConnectionDevice.|\
+       InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.|\
+       
InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.|\
+       
InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.)
+       freecwmp_set_parameter_notification "$1" "$2"
+       return 0
+       ;;
+       
InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable)
+       set_wan_device_wan_ppp_enable "$2"
+       return 0
+       ;;
+       
InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username)
+       set_wan_device_wan_ppp_username "$2"
+       return 0
+       ;;
+       
InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password)
+       set_wan_device_wan_ppp_password "$2"
+       return 0
+       ;;
+esac
+return $E_INVALID_PARAMETER_NAME
+}
diff --git a/src/external.c b/src/external.c
index e4da88b..2925d09 100644
--- a/src/external.c
+++ b/src/external.c
@@ -80,6 +80,22 @@ void external_fetch_set_param_val_resp_status(char **status)
        external_method_status = NULL;
 }
 
+void external_set_param_attr_resp (char *status, char *fault)
+{
+       free(external_method_status);
+       external_method_status = status ? strdup(status) : NULL;
+       free(external_method_fault);
+       external_method_fault = fault ? strdup(fault) : NULL;
+}
+
+void external_fetch_set_param_attr_resp (char **status, char **fault)
+{
+       *status = external_method_status;
+       external_method_status = NULL;
+       *fault = external_method_fault;
+       external_method_fault = NULL;
+}
+
 int external_get_action_data(char *action, char *name, char **value)
 {
        struct external_parameter *external_parameter;
diff --git a/src/external.h b/src/external.h
index e51b784..cd528a0 100644
--- a/src/external.h
+++ b/src/external.h
@@ -33,6 +33,8 @@ struct external_parameter {
 
 void external_set_param_val_resp_status (char *status);
 void external_fetch_set_param_val_resp_status (char **status);
+void external_set_param_attr_resp (char *status, char *fault);
+void external_fetch_set_param_attr_resp (char **status, char **fault);
 int external_get_action(char *action, char *name, char *arg);
 int external_get_action_data(char *action, char *name, char **value);
 int external_get_action_write(char *action, char *name, char *arg);
diff --git a/src/ubus.c b/src/ubus.c
index 3de874f..e7fcbfd 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -279,6 +279,36 @@ freecwmpd_handle_get_param_attributes(struct ubus_context 
*ctx, struct ubus_obje
        return 0;
 }
 
+static enum set_param_attributes {
+       SET_PARAM_ATTRIBUTES_SUCCESS,
+       SET_PARAM_ATTRIBUTES_FAULT,
+       __SET_PARAM_ATTRIBUTES_MAX
+};
+
+static const struct blobmsg_policy set_param_attributes_policy[] = {
+       [SET_PARAM_ATTRIBUTES_SUCCESS] = { .name = "success", .type = 
BLOBMSG_TYPE_STRING },
+       [SET_PARAM_ATTRIBUTES_FAULT] = { .name = "fault_code", .type = 
BLOBMSG_TYPE_STRING },
+};
+
+static int
+freecwmpd_handle_set_param_attributes(struct ubus_context *ctx, struct 
ubus_object *obj,
+                       struct ubus_request_data *req, const char *method,
+                       struct blob_attr *msg)
+{
+       struct blob_attr *tb[__SET_PARAM_ATTRIBUTES_MAX];
+
+       blobmsg_parse(set_param_attributes_policy, 
ARRAY_SIZE(set_param_attributes_policy), tb,
+                     blob_data(msg), blob_len(msg));
+
+       lfc_log_message(NAME, L_NOTICE,
+                            "triggered ubus set_parameter_attributes\n");
+
+       external_set_param_attr_resp(tb[SET_PARAM_ATTRIBUTES_SUCCESS] ? 
blobmsg_data(tb[SET_PARAM_ATTRIBUTES_SUCCESS]) : NULL,
+                       tb[SET_PARAM_ATTRIBUTES_FAULT] ? 
blobmsg_data(tb[SET_PARAM_ATTRIBUTES_FAULT]) : NULL);
+
+       return 0;
+}
+
 static enum set_param_values_fault {
        SET_PARAM_VALUES_FAULT_PARAM,
        SET_PARAM_VALUES_FAULT__FAULT,
@@ -360,6 +390,7 @@ static const struct ubus_method freecwmp_methods[] = {
        UBUS_METHOD("set_parameter_values_status", 
freecwmpd_handle_set_param_values_status, set_param_values_status_policy),
        UBUS_METHOD("get_parameter_names", freecwmpd_handle_get_param_names, 
get_param_names_policy),
        UBUS_METHOD("get_parameter_attributes", 
freecwmpd_handle_get_param_attributes, get_param_attributes_policy),
+       UBUS_METHOD("set_parameter_attributes", 
freecwmpd_handle_set_param_attributes, set_param_attributes_policy),
 };
 
 static struct ubus_object_type main_object_type =
diff --git a/src/xml.c b/src/xml.c
index 2fb7434..48d42cd 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -863,7 +863,7 @@ static int xml_handle_set_parameter_attributes(mxml_node_t 
*body_in,
                                               mxml_node_t *tree_out) {
 
        mxml_node_t *n, *b = body_in;
-       char *c, *parameter_name, *parameter_notification;
+       char *c, *parameter_name, *parameter_notification, *success=NULL, 
*fault=NULL;
        uint8_t attr_notification_update;
 
        /* handle cwmp:SetParameterAttributes */
@@ -915,15 +915,34 @@ static int 
xml_handle_set_parameter_attributes(mxml_node_t *body_in,
        if (external_set_action_execute("notification"))
                return -1;
 
+       external_fetch_set_param_attr_resp(&success, &fault);
+
+       if (fault && fault[0]=='9') {
+               goto error;
+               //TODO return a fault message here with fault indicated in the 
fault string
+       }
+
+       if(!success) {
+               goto error;
+               //TODO return a fault message here
+       }
+
        b = mxmlFindElement(tree_out, tree_out, "soap_env:Body", NULL, NULL, 
MXML_DESCEND);
-       if (!b) return -1;
+       if (!b) goto error;
 
        b = mxmlNewElement(b, "cwmp:SetParameterAttributesResponse");
-       if (!b) return -1;
+       if (!b) goto error;
 
        config_load();
 
+       free(success);
+       free(fault);
        return 0;
+
+error:
+       free(success);
+       free(fault);
+       return -1;
 }
 
 static int xml_handle_download(mxml_node_t *body_in,
-- 
1.7.4.1


<Prev in Thread] Current Thread [Next in Thread>