freecwmp
[Top] [All Lists]

[PATCH 16/27] update the script device_info in order to output parameter

To: freecwmp@linux-mips.org
Subject: [PATCH 16/27] update the script device_info in order to output parameters with ubus Contributed by Inteno Broadband Technology AB
From: Mohamed <mohamed.kallel@pivasoftware.com>
Date: Thu, 6 Dec 2012 16:54:41 +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/scripts/functions/device_info |  199 +++++++++++++++++++++++++++--
 1 files changed, 187 insertions(+), 12 deletions(-)

diff --git a/ext/openwrt/scripts/functions/device_info 
b/ext/openwrt/scripts/functions/device_info
index 86ff5c9..c3c6c33 100644
--- a/ext/openwrt/scripts/functions/device_info
+++ b/ext/openwrt/scripts/functions/device_info
@@ -2,7 +2,15 @@
 # Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
 
 get_device_info_manufacturer() {
-local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].manufacturer 2> /dev/null`
+local val=""
+case "$action" in
+       get_value)
+       val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].manufacturer 2> /dev/null`
+       ;;
+       get_name)
+       val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.Manufacturer" "$val"
 }
 
@@ -11,7 +19,15 @@ set_device_info_manufacturer() {
 }
 
 get_device_info_oui() {
-local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].oui 2> /dev/null`
+local val=""
+case "$action" in
+       get_value)
+       val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].oui 2> /dev/null`
+       ;;
+       get_name)
+       val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" "$val"
 }
 
@@ -20,7 +36,15 @@ set_device_info_oui() {
 }
 
 get_device_info_product_class() {
-local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].product_class 2> /dev/null`
+local val=""
+case "$action" in
+       get_value)
+       val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].product_class 2> /dev/null`
+       ;;
+       get_name)
+       val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.ProductClass" "$val"    
 }
 
@@ -29,7 +53,15 @@ set_device_info_product_class() {
 }
 
 get_device_info_serial_number() {
-local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].serial_number 2> /dev/null`
+local val=""
+case "$action" in
+       get_value)
+       local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].serial_number 2> /dev/null`
+       ;;
+       get_name)
+       local val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.SerialNumber" "$val"
 }
 
@@ -38,7 +70,15 @@ set_device_info_serial_number() {
 }
 
 get_device_info_hardware_version() {
-local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].hardware_version 2> /dev/null`
+local val=""
+case "$action" in
+       get_value)
+       val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].hardware_version 2> /dev/null`
+       ;;
+       get_name)
+       val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.HardwareVersion" "$val"
 }
 
@@ -47,7 +87,15 @@ set_device_info_hardware_version() {
 }
 
 get_device_info_software_version() {
-local val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].software_version 2> /dev/null`
+local val=""
+case "$action" in
+       get_value)
+       val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get 
freecwmp.@device[0].software_version 2> /dev/null`
+       ;;
+       get_name)
+       val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.SoftwareVersion" "$val"
 }
 
@@ -56,17 +104,32 @@ set_device_info_software_version() {
 }
 
 get_device_info_uptime() {
-local val=`cat /proc/uptime | awk -F "." '{ print $1 }'`
+local val=""
+case "$action" in
+       get_value)
+       val=`cat /proc/uptime | awk -F "." '{ print $1 }'`
+       ;;
+       get_name)
+       val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.UpTime" "$val"
 }
 
 get_device_info_device_log() {
 local val=""
-if [ ${FLAGS_last} -eq ${FLAGS_TRUE} ]; then
-       val=`dmesg | tail -n1`
-else
-       val=`dmesg | tail -n10`
-fi
+case "$action" in
+       get_value)
+       if [ ${FLAGS_last} -eq ${FLAGS_TRUE} ]; then
+               val=`dmesg | tail -n1`
+       else
+               val=`dmesg | tail -n10`
+       fi
+       ;;
+       get_name)
+       val="0"
+       ;;
+esac
 ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo.DeviceLog" "$val"
 }
 
@@ -130,6 +193,94 @@ esac
 return $FAULT_CPE_INVALID_PARAMETER_NAME
 }
 
+get_device_info_name() {
+case "$1" in
+       InternetGatewayDevice.)
+       ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo." "0"
+       if [ "$2" = "0" ]; then
+               get_device_info_manufacturer
+               get_device_info_oui
+               get_device_info_product_class
+               get_device_info_serial_number
+               get_device_info_hardware_version
+               get_device_info_software_version
+               get_device_info_uptime
+               get_device_info_device_log
+       fi
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.)
+       ubus_freecwmp_output "InternetGatewayDevice.DeviceInfo." "0"
+       get_device_info_manufacturer
+       get_device_info_oui
+       get_device_info_product_class
+       get_device_info_serial_number
+       get_device_info_hardware_version
+       get_device_info_software_version
+       get_device_info_uptime
+       get_device_info_device_log
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.Manufacturer)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_manufacturer
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.ManufacturerOUI)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_oui
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.ProductClass)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_product_class
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.SerialNumber)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_serial_number
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.HardwareVersion)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_hardware_version
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.SoftwareVersion)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_software_version
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.UpTime)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_uptime
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.DeviceLog)
+       if [ "$2" = "1" ]; then
+               return $FAULT_CPE_INVALID_ARGUMENTS
+       fi
+       get_device_info_device_log
+       return $FAULT_CPE_NO_FAULT
+       ;;
+esac
+return $FAULT_CPE_INVALID_PARAMETER_NAME
+}
+
 set_device_info() {
 case "$1" in
        InternetGatewayDevice.DeviceInfo.Manufacturer)
@@ -179,6 +330,30 @@ get_device_info_generic() {
        return $FAULT_CPE_NO_FAULT
 }
 
+get_device_info_generic_name() {
+       local val=""
+       case "$1" in
+       InternetGatewayDevice.DeviceInfo.ModelName|\
+       InternetGatewayDevice.DeviceInfo.Description|\
+       InternetGatewayDevice.DeviceInfo.ModemFirmwareVersion|\
+       InternetGatewayDevice.DeviceInfo.EnabledOptions|\
+       InternetGatewayDevice.DeviceInfo.AdditionalHardwareVersion|\
+       InternetGatewayDevice.DeviceInfo.AdditionalSoftwareVersion|\
+       InternetGatewayDevice.DeviceInfo.SpecVersion|\
+       InternetGatewayDevice.DeviceInfo.FirstUseDate)
+       val="0"
+       ubus_freecwmp_output "$1" "$val"
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       InternetGatewayDevice.DeviceInfo.ProvisioningCode)
+       val="1"
+       ubus_freecwmp_output "$1" "$val"
+       return $FAULT_CPE_NO_FAULT
+       ;;
+       esac
+return $FAULT_CPE_INVALID_PARAMETER_NAME
+}
+
 set_device_info_generic() {
        check_parameter_device_info_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 
]; then return 0; fi
 
-- 
1.7.4.1


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