freecwmp
[Top] [All Lists]

Re: [PATCH 19/27] update the script wan_device in order to output parame

To: mohamed.kallel@pivasoftware.com
Subject: Re: [PATCH 19/27] update the script wan_device in order to output parameters with ubus Contributed by Inteno Broadband Technology AB
From: Luka Perkov <freecwmp@lukaperkov.net>
Date: Sat, 8 Dec 2012 11:55:56 +0100
Cc: freecwmp@linux-mips.org, ahmed.zribi@pivasoftware.com, freecwmp@lukaperkov.net, jogo@openwrt.org
In-reply-to: <1354809292-2467-20-git-send-email-mohamed.kallel@pivasoftware.com>
Mail-followup-to: mohamed.kallel@pivasoftware.com, freecwmp@linux-mips.org, ahmed.zribi@pivasoftware.com, jogo@openwrt.org
Original-recipient: rfc822;freecwmp@linux-mips.org
References: <mohamed.kallel@pivasoftware.com> <1354809292-2467-1-git-send-email-mohamed.kallel@pivasoftware.com> <1354809292-2467-20-git-send-email-mohamed.kallel@pivasoftware.com>
Sender: freecwmp-bounce@linux-mips.org
User-agent: Mutt/1.5.21 (2010-09-15)
Missing commit message. Contributed by must go in commit message and not
in subject.

On Thu, Dec 06, 2012 at 04:54:44PM +0100, Mohamed wrote:
> 
> Signed-off-by: Mohamed <mohamed.kallel@pivasoftware.com>
> Signed-off-by: Ahmed ZRIBI <ahmed.zribi@pivasoftware.com>
> ---
>  ext/openwrt/scripts/freecwmp.sh          |  127 +++++++++---------
>  ext/openwrt/scripts/functions/wan_device |  223 
> +++++++++++++++++++++++++++---
>  src/freecwmp.c                           |    2 +-
>  3 files changed, 267 insertions(+), 85 deletions(-)
> 
> diff --git a/ext/openwrt/scripts/freecwmp.sh b/ext/openwrt/scripts/freecwmp.sh
> index c5a0d53..a2f2bc1 100644
> --- a/ext/openwrt/scripts/freecwmp.sh
> +++ b/ext/openwrt/scripts/freecwmp.sh
> @@ -1,5 +1,6 @@
>  #!/bin/sh
>  # Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
> +# Copyright (C) 2012-2013 Ahmed ZRIBI <ahmed.zribi@pivasoftware.com>
>  
>  . /lib/functions.sh
>  . /usr/share/libubox/jshn.sh
> @@ -68,10 +69,10 @@ case "$1" in
>               elif [ "$2" = "value" ]; then
>                       __arg1="$3"
>                       action="get_value"
> -        elif [ "$2" = "name" ]; then
> -            __arg1="$3"
> -            __arg2=`echo $4| tr '[A-Z]' '[a-z]'`
> -            action="get_name"
> +             elif [ "$2" = "name" ]; then
> +                     __arg1="$3"
> +                     __arg2=`echo $4| tr '[A-Z]' '[a-z]'`
> +                     action="get_name"

Again space/tabs fixes must be changed when they are introduced...

>               elif [ "$2" = "all" ]; then
>                       __arg1="$3"
>                       action="get_all"
> @@ -111,7 +112,7 @@ handle_scripts() {
>       config_get prefix "$section" "prefix"
>       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_name_functions "$section" "get_name_function"

Same here.

>       config_get set_value_functions "$section" "set_value_function"
>  }
>  
> @@ -142,16 +143,57 @@ FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED="18"
>  FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION="19"
>  
>  if [ "$action" = "get_value" -o "$action" = "get_all" ]; then
> -    no_fault="0"
> -    freecwmp_check_fault "$__arg1"
> -    fault_code="$?"
> -    if [ "$fault_code" = "0" ]; then
> -        if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" = "" 
> \) ]; then
> -            __arg1="InternetGatewayDevice."
> +     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_value_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
> -     for function_name in $get_value_functions
> -     do
> -             $function_name "$__arg1"
> +     if [ "$fault_code" != "0" ]; then
> +             let fault_code=$fault_code+9000
> +             ubus_freecwmp_output "$__arg1" "" "" "$fault_code"
> +     fi
> +fi
> +
> +if [ "$action" = "get_name" -o "$action" = "get_all" ]; then
> +     no_fault="0"
> +     freecwmp_check_fault "$__arg1"
> +     fault_code="$?"
> +     if [ "$fault_code" = "0" ]; then
> +             if [ \( "$__arg2" != "0" \) -a \( "$__arg2" != "1" \) -a \( 
> "$__arg2" != "true" \) -a \( "$__arg2" != "false" \) ]; then
> +                     fault_code="$FAULT_CPE_INVALID_ARGUMENTS"
> +             else
> +                     if [ "$__arg2" = "true" ]; then
> +                             __arg2="1"
> +                     elif [ "$__arg2" = "false" ]; then
> +                             __arg2="0"
> +                     fi
> +             fi
> +             if [ "$fault_code" = "0" ]; then
> +                     if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( 
> "$__arg1" = "" \) ]; then
> +                             ubus_freecwmp_output "InternetGatewayDevice." 
> "0"
> +                             if [ \( "$__arg1" = "" \) -a \( "$__arg2" = "1" 
> \) ]; then
> +                                     exit 0
> +                             fi
> +                             __arg1="InternetGatewayDevice."
> +                     fi
> +                     for function_name in $get_name_functions
> +                     do
> +                             $function_name "$__arg1" "$__arg2"
>                               fault_code="$?"
>                               if [ "$fault_code" = "0" ]; then
>                                       no_fault="1"
> @@ -159,55 +201,14 @@ if [ "$action" = "get_value" -o "$action" = "get_all" 
> ]; then
>                               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" = "get_name" -o "$action" = "get_all" ]; then
> -    no_fault="0"
> -    freecwmp_check_fault "$__arg1"
> -    fault_code="$?"
> -    if [ "$fault_code" = "0" ]; then
> -        if [ \( "$__arg2" != "0" \) -a \( "$__arg2" != "1" \) -a \( 
> "$__arg2" != "true" \) -a \( "$__arg2" != "false" \) ]; then
> -            fault_code="$FAULT_CPE_INVALID_ARGUMENTS"
> -        else
> -            if [ "$__arg2" = "true" ]; then
> -                __arg2="1"
> -            elif [ "$__arg2" = "false" ]; then
> -                __arg2="0"
> -            fi
> -        fi
> -        if [ "$fault_code" = "0" ]; then
> -            if [ \( "$__arg1" = "InternetGatewayDevice." \) -o \( "$__arg1" 
> = "" \) ]; then
> -                ubus_freecwmp_output "InternetGatewayDevice." "0"
> -                if [ \( "$__arg1" = "" \) -a \( "$__arg2" = "1" \) ]; then
> -                    exit 0
> -                fi
> -                __arg1="InternetGatewayDevice."
> -            fi
> -            for function_name in $get_name_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
> -    fi
> -    if [ "$fault_code" != "0" ]; then
> -        let fault_code=$fault_code+9000
> -        ubus_freecwmp_output "$__arg1" "" "" "$fault_code"
> -    fi

Am I missing something here? Why are you removing code that was added in one of
the previous patches?

> +                     done
> +                     if [ "$no_fault" = "1" ]; then fault_code="0"; fi
> +             fi
> +     fi
> +     if [ "$fault_code" != "0" ]; then
> +             let fault_code=$fault_code+9000
> +             ubus_freecwmp_output "$__arg1" "" "" "$fault_code"
> +     fi
>  fi
>  
>  if [ "$action" = "set_value" ]; then
> diff --git a/ext/openwrt/scripts/functions/wan_device 
> b/ext/openwrt/scripts/functions/wan_device
> index a8b6361..9c7cd14 100644
> --- a/ext/openwrt/scripts/functions/wan_device
> +++ b/ext/openwrt/scripts/functions/wan_device
> @@ -1,20 +1,38 @@
>  #!/bin/sh
>  # Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
> +# Copyright (C) 2012-2013 Ahmed ZRIBI <ahmed.zribi@pivasoftware.com>
>  
>  get_wan_device_mng_status() {
>  # TODO: Unconfigured ; Connecting ; Connected ; PendingDisconnect ; 
> Disconneting ; Disconnected 
> -local val="Connected"
> -ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus"
>  "$val" "xsd:boolean"
> +local val=""
> +local type="xsd:boolean"
> +local 
> parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus"
> +case "$action" in
> +     get_value)
> +     val="Connected"
> +     ;;
> +     get_name)
> +     val="0"
> +     ;;
> +esac
> +ubus_freecwmp_output "$parm" "$val" "$type"
>  }
>  
>  get_wan_device_mng_interface_ip() {
> -local val
> +local val=""
>  local 
> parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress"
> -if [ -z "$default_wan_device_mng_interface_ip" ]; then
> -     val=`network_get_ipaddr val mng`
> -else
> -     val=$default_wan_device_mng_interface_ip
> -fi
> +case "$action" in
> +     get_value)
> +     if [ -z "$default_wan_device_mng_interface_ip" ]; then
> +             val=`network_get_ipaddr val mng`
> +     else
> +             val=$default_wan_device_mng_interface_ip
> +     fi
> +     ;;
> +     get_name)
> +     val="0"
> +     ;;
> +esac
>  if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then
>       ubus_freecwmp_output "$parm" "$val"
>  else
> @@ -25,11 +43,18 @@ fi
>  get_wan_device_mng_interface_mac() {
>  local val=""
>  local 
> parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress"
> -if [ -z "$default_wan_device_mng_interface_mac" ]; then
> -     val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.mng.macaddr`
> -else
> -     val=$default_wan_device_mng_interface_mac
> -fi
> +case "$action" in
> +     get_value)
> +     if [ -z "$default_wan_device_mng_interface_mac" ]; then
> +             val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.mng.macaddr`
> +     else
> +             val=$default_wan_device_mng_interface_mac
> +     fi
> +     ;;
> +     get_name)
> +     val="0"
> +     ;;
> +esac
>  if [ "$FLAGS_value" != "${FLAGS_TRUE}" ]; then
>       ubus_freecwmp_output "$parm" "$val"
>  else
> @@ -38,11 +63,21 @@ fi
>  }
>  
>  get_wan_device_wan_ppp_enable() {
> -local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.wan.auto 2> /dev/null`
> -if [ -z $val ]; then
> +local val=""
> +local type="xsd:boolean"
> +local 
> parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable"
> +case "$action" in
> +     get_value)
> +     val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.wan.auto 2> /dev/null`
> +     if [ -z $val ]; then
> +             val="1"
> +     fi
> +     ;;
> +     get_name)
>       val="1"
> -fi
> -ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable"
>  "$val" "xsd:boolean"
> +     ;;
> +esac
> +ubus_freecwmp_output "$parm" "$val" "$type"
>  }
>  
>  set_wan_device_wan_ppp_enable() {
> @@ -57,8 +92,17 @@ fi
>  }
>  
>  get_wan_device_wan_ppp_username() {
> -local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.wan.username 2> /dev/null`
> -ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username"
>  "$val"
> +local val=""
> +local 
> parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username"
> +case "$action" in
> +     get_value)
> +     val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.wan.username 2> /dev/null`
> +     ;;
> +     get_name)
> +     val="1"
> +     ;;
> +esac
> +ubus_freecwmp_output "$parm" "$val"
>  }
>  
>  set_wan_device_wan_ppp_username() {
> @@ -67,8 +111,16 @@ set_wan_device_wan_ppp_username() {
>  
>  get_wan_device_wan_ppp_password() {
>  local val=""
> -val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.wan.password 2> /dev/null`
> -ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password"
>  "$val"
> +local 
> parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password"
> +case "$action" in
> +     get_value)
> +     val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
> network.wan.password 2> /dev/null`
> +     ;;
> +     get_name)
> +     val="1"
> +     ;;
> +esac
> +ubus_freecwmp_output "$parm" "$val"
>  }
>  
>  set_wan_device_wan_ppp_password() {
> @@ -162,6 +214,135 @@ esac
>  return $FAULT_CPE_INVALID_PARAMETER_NAME
>  }
>  
> +get_wan_device_name() {
> +case "$1" in
> +     InternetGatewayDevice.)
> +     ubus_freecwmp_output "InternetGatewayDevice.WANDevice." "1"
> +     if [ "$2" = "0" ]; then
> +             get_wan_device_mng_status
> +             get_wan_device_mng_interface_ip
> +             get_wan_device_mng_interface_mac
> +             get_wan_device_wan_ppp_enable
> +             get_wan_device_wan_ppp_username
> +             get_wan_device_wan_ppp_password
> +     fi
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     InternetGatewayDevice.WANDevice.)
> +     ubus_freecwmp_output "InternetGatewayDevice.WANDevice." "1"
> +     ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1." "1"
> +     if [ "$2" = "0" ]; then
> +     get_wan_device_mng_status
> +     get_wan_device_mng_interface_ip
> +     get_wan_device_mng_interface_mac
> +     get_wan_device_wan_ppp_enable
> +     get_wan_device_wan_ppp_username
> +     get_wan_device_wan_ppp_password
> +     fi
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     InternetGatewayDevice.WANDevice.1.)
> +     ubus_freecwmp_output "InternetGatewayDevice.WANDevice.1." "1"
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "1"
> +     if [ "$2" = "0" ]; then
> +     get_wan_device_mng_status
> +     get_wan_device_mng_interface_ip
> +     get_wan_device_mng_interface_mac
> +     get_wan_device_wan_ppp_enable
> +     get_wan_device_wan_ppp_username
> +     get_wan_device_wan_ppp_password
> +     fi
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     InternetGatewayDevice.WANDevice.1.WANConnectionDevice.)
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "1"
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "1"
> +     if [ "$2" = "0" ]; then
> +     get_wan_device_mng_status
> +     get_wan_device_mng_interface_ip
> +     get_wan_device_mng_interface_mac
> +     get_wan_device_wan_ppp_enable
> +     get_wan_device_wan_ppp_username
> +     get_wan_device_wan_ppp_password
> +     fi
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.)
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "1"
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "1"
> +     if [ "$2" = "0" ]; then
> +     get_wan_device_mng_status
> +     get_wan_device_mng_interface_ip
> +     get_wan_device_mng_interface_mac
> +     get_wan_device_wan_ppp_enable
> +     get_wan_device_wan_ppp_username
> +     get_wan_device_wan_ppp_password
> +     fi
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.)
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "1"
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." 
> "1"
> +     if [ "$2" = "0" ]; then
> +     get_wan_device_mng_status
> +     get_wan_device_mng_interface_ip
> +     get_wan_device_mng_interface_mac
> +     fi
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.)
> +     ubus_freecwmp_output 
> "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." 
> "1"
> +     get_wan_device_mng_status
> +     get_wan_device_mng_interface_ip
> +     get_wan_device_mng_interface_mac
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus)
> +     if [ "$2" = "1" ]; then
> +             return $FAULT_CPE_INVALID_ARGUMENTS
> +     fi
> +     get_wan_device_mng_status
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress)
> +     if [ "$2" = "1" ]; then
> +             return $FAULT_CPE_INVALID_ARGUMENTS
> +     fi
> +     get_wan_device_mng_interface_ip
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress)
> +     if [ "$2" = "1" ]; then
> +             return $FAULT_CPE_INVALID_ARGUMENTS
> +     fi
> +     get_wan_device_mng_interface_mac
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable)
> +     if [ "$2" = "1" ]; then
> +             return $FAULT_CPE_INVALID_ARGUMENTS
> +     fi
> +     get_wan_device_wan_ppp_enable
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username)
> +     if [ "$2" = "1" ]; then
> +             return $FAULT_CPE_INVALID_ARGUMENTS
> +     fi
> +     get_wan_device_wan_ppp_username
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +     
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password)
> +     if [ "$2" = "1" ]; then
> +             return $FAULT_CPE_INVALID_ARGUMENTS
> +     fi
> +     get_wan_device_wan_ppp_password
> +     return $FAULT_CPE_NO_FAULT
> +     ;;
> +esac
> +return $FAULT_CPE_INVALID_PARAMETER_NAME
> +}
> +
>  set_wan_device() {
>  case "$1" in
>       
> InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable)
> diff --git a/src/freecwmp.c b/src/freecwmp.c
> index f4c9cb1..eb2783c 100644
> --- a/src/freecwmp.c
> +++ b/src/freecwmp.c
> @@ -197,7 +197,7 @@ netlink_init(void)
>  
>  void signal_kill_all_handler(int sig)
>  {
> -     pthread_exit(NULL);
> +     pthread_exit(NULL);
>  }
>  
>  
> -- 
> 1.7.4.1

Luka 

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