Signed-off-by: Mohamed <mohamed.kallel@pivasoftware.com>
Signed-off-by: Ahmed ZRIBI <ahmed.zribi@pivasoftware.com>
---
ext/openwrt/scripts/freecwmp.sh | 58 +++++++++++++++++++++++++++++++--
ext/openwrt/scripts/functions/common | 20 ++++++++++++
2 files changed, 74 insertions(+), 4 deletions(-)
diff --git a/ext/openwrt/scripts/freecwmp.sh b/ext/openwrt/scripts/freecwmp.sh
index 02a923e..54c0924 100644
--- a/ext/openwrt/scripts/freecwmp.sh
+++ b/ext/openwrt/scripts/freecwmp.sh
@@ -90,6 +90,15 @@ case "$1" in
reboot)
action="reboot"
;;
+ apply)
+ if [ "$2" = "notification" ]; then
+ action="apply_notification"
+ elif [ "$2" = "value" ]; then
+ action="apply_value"
+ else
+ action="apply_value"
+ fi
+ ;;
esac
if [ -z "$action" ]; then
@@ -213,10 +222,30 @@ if [ "$action" = "get_name" -o "$action" = "get_all" ];
then
fi
if [ "$action" = "set_value" ]; then
- for function_name in $set_value_functions
- do
- $function_name "$__arg1" "$__arg2"
- done
+ no_fault="0"
+ freecwmp_check_fault "$__arg1"
+ fault_code="$?"
+ if [ "$fault_code" = "0" ]; then
+ if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1"
= "" \) ]; then
+ __arg1="InternetGatewayDevice."
+ fi
+ for function_name in $set_value_functions
+ do
+ $function_name "$__arg1" "$__arg2"
+ fault_code="$?"
+ if [ "$fault_code" = "0" ]; then
+ no_fault="1"
+ fi
+ if [ "$fault_code" = "$FAULT_CPE_INVALID_ARGUMENTS" ];
then
+ break
+ fi
+ done
+ if [ "$no_fault" = "1" ]; then fault_code="0"; fi
+ fi
+ if [ "$fault_code" != "0" ]; then
+ let fault_code=$fault_code+9000
+ freecwmp_set_parameter_fault "$__arg1" "$fault_code"
+ fi
fi
if [ "$action" = "get_notification" -o "$action" = "get_all" ]; then
@@ -295,6 +324,27 @@ if [ "$action" = "reboot" ]; then
fi
fi
+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
+ # applying
+ /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit
+ if [ "$action" = "apply_value" ]; then ubus call tr069
set_parameter_values_status '{"status": "0"}'; fi
+ else
+ let n=$__fault_count-1
+ for i in `seq 0 $n`
+ do
+ local parm=`/sbin/uci -P /var/state get
freecwmp.@fault[$i].parameter 2> /dev/null`
+ local fault_code=`/sbin/uci -P /var/state get
freecwmp.@fault[$i].fault_code 2> /dev/null`
+ ubus_freecwmp_fault_output "$parm" "$fault_code"
+ done
+ rm -rf /var/state/freecwmp 2> /dev/null
+ /sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} revert freecwmp
+ fi
+fi
+
+
if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then
echo "[debug] exited at \"`date`\""
fi
diff --git a/ext/openwrt/scripts/functions/common
b/ext/openwrt/scripts/functions/common
index fd98a01..f701eb9 100644
--- a/ext/openwrt/scripts/functions/common
+++ b/ext/openwrt/scripts/functions/common
@@ -56,6 +56,16 @@ case "$action" in
;;
esac
}
+
+ubus_freecwmp_fault_output() {
+local parameter="$1"
+local fault_code="$2"
+case "$action" in
+ apply_value)
+ ubus call tr069 set_parameter_values_fault '{"parameter":
"'$parameter'", "fault_code":"'$fault_code'"}' 2> /dev/null
+ ;;
+esac
+}
freecwmp_value_output() {
freecwmp_output "$1" "$2" "V"
}
@@ -295,3 +305,13 @@ if [ "$1" = "." ]; then
fi
return $FAULT_CPE_NO_FAULT
}
+
+freecwmp_set_parameter_fault() {
+ local _parm="$1"
+ local _fault="$2"
+ /sbin/uci -P /var/state batch << EOF 2>&1 >/dev/null
+ add freecwmp fault
+ set freecwmp.@fault[-1].parameter="$_parm"
+ set freecwmp.@fault[-1].fault_code="$_fault"
+EOF
+}
--
1.7.4.1
|