freecwmp
[Top] [All Lists]

[PATCH 20/27] update the get notification in order to put the returned d

To: freecwmp@linux-mips.org
Subject: [PATCH 20/27] update the get notification in order to put the returned data via ubus instead of pipe TODO: develop the xml handle message to perform send of GetParameterAttributeResponse Contributed by Inteno Broadband Technology AB
From: Mohamed <mohamed.kallel@pivasoftware.com>
Date: Thu, 6 Dec 2012 16:54:45 +0100
Cc: freecwmp@lukaperkov.net, Mohamed <mohamed.kallel@pivasoftware.com>, Ahmed ZRIBI <ahmed.zribi@pivasoftware.com>
In-reply-to: <1354809292-2467-1-git-send-email-mohamed.kallel@pivasoftware.com>
Original-recipient: rfc822;freecwmp@linux-mips.org
References: <mohamed.kallel@pivasoftware.com> <1354809292-2467-1-git-send-email-mohamed.kallel@pivasoftware.com>
Sender: freecwmp-bounce@linux-mips.org
Signed-off-by: Mohamed <mohamed.kallel@pivasoftware.com>
Signed-off-by: Ahmed ZRIBI <ahmed.zribi@pivasoftware.com>
---
 ext/openwrt/config/freecwmp          |    6 ++++
 ext/openwrt/scripts/freecwmp.sh      |   27 +++++++++++++++++++-
 ext/openwrt/scripts/functions/common |   21 +++++++++++++++-
 src/ubus.c                           |   43 ++++++++++++++++++++++++++++++++++
 4 files changed, 94 insertions(+), 3 deletions(-)

diff --git a/ext/openwrt/config/freecwmp b/ext/openwrt/config/freecwmp
index 1379afd..1f72c27 100644
--- a/ext/openwrt/config/freecwmp
+++ b/ext/openwrt/config/freecwmp
@@ -30,24 +30,30 @@ config scripts
        list location /usr/share/freecwmp/functions/device_info
        list get_value_function get_device_info
        list get_name_function get_device_info_name
+       list get_notification_function get_device_info_notification
        list set_value_function set_device_info
        list get_value_function get_device_info_generic
        list get_name_function get_device_info_generic_name
+       list get_notification_function get_device_info_generic_notification
        list set_value_function set_device_info_generic
        list location /usr/share/freecwmp/functions/lan_device
        list get_value_function get_lan_device
        list get_name_function get_lan_device_name
+       list get_notification_function get_lan_device_notification
        list set_value_function set_lan_device
        list location /usr/share/freecwmp/functions/management_server
        list get_value_function get_management_server
        list get_name_function get_management_server_name
+       list get_notification_function get_management_server_notification
        list set_value_function set_management_server
        list get_value_function get_management_server_generic
        list get_name_function get_management_server_generic_name
+       list get_notification_function 
get_management_server_generic_notification
        list set_value_function set_management_server_generic
        list location /usr/share/freecwmp/functions/wan_device
        list get_value_function get_wan_device
        list get_name_function get_wan_device_name
+       list get_notification_function get_wan_device_notification
        list set_value_function set_wan_device
        list location /usr/share/freecwmp/functions/misc
        list get_value_function get_misc
diff --git a/ext/openwrt/scripts/freecwmp.sh b/ext/openwrt/scripts/freecwmp.sh
index a2f2bc1..02a923e 100644
--- a/ext/openwrt/scripts/freecwmp.sh
+++ b/ext/openwrt/scripts/freecwmp.sh
@@ -113,6 +113,7 @@ handle_scripts() {
        config_list_foreach "$section" 'location' load_script
        config_get get_value_functions "$section" "get_value_function"
        config_get get_name_functions "$section" "get_name_function"
+       config_get get_notification_functions "$section" 
"get_notification_function"
        config_get set_value_functions "$section" "set_value_function"
 }
 
@@ -219,8 +220,30 @@ if [ "$action" = "set_value" ]; then
 fi
 
 if [ "$action" = "get_notification" -o "$action" = "get_all" ]; then
-       freecwmp_get_parameter_notification "x_notification" "$__arg1"
-       freecwmp_notification_output "$__arg1" "$x_notification"
+       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 $get_notification_functions
+               do
+                       $function_name "$__arg1"
+                       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
+               ubus_freecwmp_output "$__arg1" "" "" "$fault_code"
+       fi
 fi
 
 if [ "$action" = "set_notification" ]; then
diff --git a/ext/openwrt/scripts/functions/common 
b/ext/openwrt/scripts/functions/common
index abba220..fd98a01 100644
--- a/ext/openwrt/scripts/functions/common
+++ b/ext/openwrt/scripts/functions/common
@@ -51,7 +51,9 @@ case "$action" in
        get_name)
        ubus call tr069 get_parameter_names '{"parameter": "'$parameter'", 
"writable": "'$value'", "fault_code":"'$fault_code'"}' 2> /dev/null
        ;;
- 
+       get_notification)
+       ubus call tr069 get_parameter_attributes '{"parameter": "'$parameter'", 
"notification": "'$value'", "fault_code":"'$fault_code'"}' 2> /dev/null
+       ;;
 esac
 }
 freecwmp_value_output() {
@@ -151,6 +153,9 @@ freecwmp_config_notifications() {
                if [ "$item" = "$3" ]; then
                        eval "export -- \"$4=2\""
                        return 0
+               elif [ "`echo $3|grep $item`" = "$3" ]; then
+                       eval "export -- \"$4=2\""
+                       return 0
                fi
        done
        for item in $__passive
@@ -158,6 +163,9 @@ freecwmp_config_notifications() {
                if [ "$item" = "$3" ]; then
                        eval "export -- \"$4=1\""
                        return 0
+               elif [ "`echo $3|grep $item`" = "$3" ]; then
+                       eval "export -- \"$4=1\""
+                       return 0
                fi
        done
 }
@@ -193,7 +201,18 @@ freecwmp_get_parameter_notification() {
        local _dest="$1"
        local _parm="$2"
        local _val
+       local _parent
        config_foreach freecwmp_config_notifications "notifications" "get" 
"$_parm" "_val"
+       if [ "$_val" = "" ]; then
+               if [ "`echo $_parm|grep '\.$'`" = "" ]; then
+                       _parent="${_parm%.*}."
+                       config_foreach freecwmp_config_notifications 
"notifications" "get" "$_parent" "_val"
+               else
+                       _parent="${_parm%.*.}."
+                       config_foreach freecwmp_config_notifications 
"notifications" "get" "$_parent" "_val"
+               fi
+       fi
+       if [ "$_val" = "" ];then _val="0" ;fi
        eval "export -- \"$_dest=$_val\""
 }
 
diff --git a/src/ubus.c b/src/ubus.c
index cbf94b0..072b2a1 100644
--- a/src/ubus.c
+++ b/src/ubus.c
@@ -5,6 +5,7 @@
  *     (at your option) any later version.
  *
  *     Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
+ *     Copyright (C) 2012 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
  */
 
 #include <unistd.h>
@@ -239,12 +240,54 @@ freecwmpd_handle_get_param_names(struct ubus_context 
*ctx, struct ubus_object *o
        return 0;
 }
 
+static enum get_param_attributes {
+       GET_PARAM_ATTRIBUTES_PARAM,
+       GET_PARAM_ATTRIBUTES_NOTIF,
+       GET_PARAM_ATTRIBUTES_FAULT,
+       __GET_PARAM_ATTRIBUTES_MAX
+};
+
+static const struct blobmsg_policy get_param_attributes_policy[] = {
+       [GET_PARAM_ATTRIBUTES_PARAM] = { .name = "parameter", .type = 
BLOBMSG_TYPE_STRING },
+       [GET_PARAM_ATTRIBUTES_NOTIF] = { .name = "notification", .type = 
BLOBMSG_TYPE_STRING },
+       [GET_PARAM_ATTRIBUTES_FAULT] = { .name = "fault_code", .type = 
BLOBMSG_TYPE_STRING },
+};
+
+static int
+freecwmpd_handle_get_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[__GET_PARAM_ATTRIBUTES_MAX];
+
+       blobmsg_parse(get_param_attributes_policy, 
ARRAY_SIZE(get_param_attributes_policy), tb,
+                     blob_data(msg), blob_len(msg));
+
+       if (!tb[GET_PARAM_ATTRIBUTES_PARAM])
+               return UBUS_STATUS_INVALID_ARGUMENT;
+
+       if (!tb[GET_PARAM_ATTRIBUTES_NOTIF])
+               return UBUS_STATUS_INVALID_ARGUMENT;
+
+       freecwmp_log_message(NAME, L_NOTICE,
+                            "triggered ubus get_parameter_attributes for the 
parameter %s\n",
+                            blobmsg_data(tb[GET_PARAM_ATTRIBUTES_PARAM]));
+
+       
external_add_list_paramameter(blobmsg_data(tb[GET_PARAM_ATTRIBUTES_PARAM]),
+                                     
blobmsg_data(tb[GET_PARAM_ATTRIBUTES_NOTIF]),
+                                     NULL,
+                                     
blobmsg_data(tb[GET_PARAM_ATTRIBUTES_FAULT]));
+
+       return 0;
+}
+
 static const struct ubus_method freecwmp_methods[] = {
        UBUS_METHOD("notify", freecwmpd_handle_notify, notify_policy),
        UBUS_METHOD("inform", freecwmpd_handle_inform, inform_policy),
        UBUS_METHOD("command", freecwmpd_handle_command, command_policy),
        UBUS_METHOD("get_parameter_values", freecwmpd_handle_get_param_values, 
get_param_values_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),
 };
 
 static struct ubus_object_type main_object_type =
-- 
1.7.4.1


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