diff --git a/ext/openwrt/config/easycwmp b/ext/openwrt/config/easycwmp index bf42f67..e587dea 100644 --- a/ext/openwrt/config/easycwmp +++ b/ext/openwrt/config/easycwmp @@ -40,5 +40,7 @@ config scripts list function lan_device list location /usr/share/easycwmp/functions/management_server list function management_server + list location /usr/share/easycwmp/functions/user + list function user list location /usr/share/easycwmp/functions/wan_device list function wan_device diff --git a/ext/openwrt/init.d/easycwmpd b/ext/openwrt/init.d/easycwmpd index a3a2f56..ee98f4c 100644 --- a/ext/openwrt/init.d/easycwmpd +++ b/ext/openwrt/init.d/easycwmpd @@ -3,14 +3,29 @@ START=90 +change_config() { + local iface=`uci get easycwmp.@local[0].interface` + if [ "$iface" = "eth0" ]; then + . /lib/functions/network.sh; network_get_device if_wan wan; + if [ "$if_wan" = "$iface" ]; then + return 0 + fi + uci set easycwmp.@local[0].interface="$if_wan" + uci commit easycwmp + fi + return 0 +} + boot() { - service_start /usr/sbin/easycwmpd --boot + change_config + service_start /usr/sbin/easycwmpd --boot } start() { - service_start /usr/sbin/easycwmpd --getrpcmethod + change_config + service_start /usr/sbin/easycwmpd --getrpcmethod } stop() { - service_stop /usr/sbin/easycwmpd -} \ No newline at end of file + service_stop /usr/sbin/easycwmpd +} diff --git a/ext/openwrt/scripts/easycwmp.sh b/ext/openwrt/scripts/easycwmp.sh index 3313ecc..805253f 100644 --- a/ext/openwrt/scripts/easycwmp.sh +++ b/ext/openwrt/scripts/easycwmp.sh @@ -1,8 +1,8 @@ #!/bin/sh # Copyright (C) 2012-2014 PIVA Software -# Author: MOHAMED Kallel -# Author: AHMED Zribi -# Author: ANIS ELLOUZE +# Author: MOHAMED Kallel +# Author: AHMED Zribi +# Author: ANIS ELLOUZE # Copyright (C) 2011-2012 Luka Perkov . /lib/functions.sh @@ -76,342 +76,347 @@ FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" if [ ${FLAGS_help} -eq ${FLAGS_TRUE} ]; then - exit 1 + exit 1 fi __arg1=""; __arg2=""; __arg3=""; __arg4=""; __arg5=""; json_get_opt() { - __arg1=""; __arg2=""; __arg3=""; __arg4=""; __arg5=""; - json_init - json_load "$1" - local command class - json_get_var command command - case "$command" in - set|get|add|delete) - json_get_var class class - json_get_var __arg1 parameter - json_get_var __arg2 argument - if [ "$class" != "" ]; then - action="$command""_$class" - else - action="$command""_value" - fi - ;; - download) - action="download" - json_get_var __arg1 url - json_get_var __arg2 file_type - json_get_var __arg3 file_size - json_get_var __arg4 user_name - json_get_var __arg5 password - ;; - factory_reset|reboot) - action="$command" - ;; - inform) - json_get_var class class - if [ "$class" != "" ]; then - action="inform_$class" - else - action="inform_parameter" - fi - ;; - apply) - json_get_var class class - json_get_var __arg1 argument - if [ "$class" != "" ]; then - action="apply_$class" - else - action="apply_value" - fi - ;; - end) - action="end" - echo "$EASYCWMP_PROMPT" - ;; - exit) - exit 0 - ;; - esac + __arg1=""; __arg2=""; __arg3=""; __arg4=""; __arg5=""; + json_init + json_load "$1" + local command class + json_get_var command command + case "$command" in + set|get|add|delete) + json_get_var class class + json_get_var __arg1 parameter + json_get_var __arg2 argument + if [ "$class" != "" ]; then + action="$command""_$class" + else + action="$command""_value" + fi + ;; + download) + action="download" + json_get_var __arg1 url + json_get_var __arg2 file_type + json_get_var __arg3 file_size + json_get_var __arg4 user_name + json_get_var __arg5 password + ;; + factory_reset|reboot) + action="$command" + ;; + inform) + json_get_var class class + if [ "$class" != "" ]; then + action="inform_$class" + else + action="inform_parameter" + fi + ;; + apply) + json_get_var class class + json_get_var __arg1 argument + if [ "$class" != "" ]; then + action="apply_$class" + else + action="apply_value" + fi + ;; + end) + action="end" + echo "$EASYCWMP_PROMPT" + ;; + exit) + exit 0 + ;; + esac } case "$1" in - set|get|add|delete) - if [ "$2" = "notification" -o "$2" = "value" -o "$2" = "name" -o "$2" = "object" ]; then - __arg1="$3" - __arg2="$4" - action="$1_""$2" - else - __arg1="$2" - __arg2="$3" - action="$1""_value" - fi - ;; - download) - action="download" - __arg1="$2" - __arg2="$3" - __arg3="$4" - __arg4="$5" - __arg5="$6" - ;; - factory_reset|reboot) - action="$1" - ;; - inform) - if [ "$2" != "" ]; then - action="inform_$2" - else - action="inform_parameter" - fi - ;; - apply) - if [ "$2" != "" ]; then - __arg1="$3" - action="apply_$2" - else - __arg1="$2" - action="apply_value" - fi - ;; - json_input) - action="json_input" - ;; + set|get|add|delete) + if [ "$2" = "notification" -o "$2" = "value" -o "$2" = "name" -o "$2" = "object" ]; then + __arg1="$3" + __arg2="$4" + action="$1_""$2" + else + __arg1="$2" + __arg2="$3" + action="$1""_value" + fi + ;; + download) + action="download" + __arg1="$2" + __arg2="$3" + __arg3="$4" + __arg4="$5" + __arg5="$6" + ;; + factory_reset|reboot) + action="$1" + ;; + inform) + if [ "$2" != "" ]; then + action="inform_$2" + else + action="inform_parameter" + fi + ;; + apply) + if [ "$2" != "" ]; then + __arg1="$3" + action="apply_$2" + else + __arg1="$2" + action="apply_value" + fi + ;; + json_input) + action="json_input" + ;; esac if [ -z "$action" ]; then - echo invalid action \'$1\' - exit 1 + echo invalid action \'$1\' + exit 1 fi load_script() { - . $1 + . $1 } load_function() { - get_functions="$get_functions get_$1" - set_functions="$set_functions set_$1" - add_object_functions="$add_object_functions add_object_$1" - delete_object_functions="$delete_object_functions delete_object_$1" - build_instances_$1 2> /dev/null + get_functions="$get_functions get_$1" + set_functions="$set_functions set_$1" + add_object_functions="$add_object_functions add_object_$1" + delete_object_functions="$delete_object_functions delete_object_$1" + build_instances_$1 2> /dev/null } handle_scripts() { - local section="$1" - config_get prefix "$section" "prefix" - config_list_foreach "$section" 'location' load_script - config_list_foreach "$section" 'function' load_function + local section="$1" + config_get prefix "$section" "prefix" + config_list_foreach "$section" 'location' load_script + config_list_foreach "$section" 'function' load_function } config_load easycwmp config_foreach handle_scripts "scripts" handle_action() { - if [ "$action" = "get_value" ]; then - local __param - [ "$__arg1" = "" ] && __param="InternetGatewayDevice." || __param="$__arg1" - easycwmp_execute_functions "$get_functions" "$__param" - fault_code="$?" - - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - easycwmp_output "$__arg1" "" "" "" "$fault_code" - fi - fi - - if [ "$action" = "get_name" ]; then - local __param="$__arg1" - [ "`echo $__arg2 | awk '{print tolower($0)}'`" = "false" ] && __arg2="0" - [ "`echo $__arg2 | awk '{print tolower($0)}'`" = "true" ] && __arg2="1" - if [ "$__arg2" != "0" -a "$__arg2" != "1" ]; then - let fault_code=$E_INVALID_ARGUMENTS+9000 - easycwmp_output "$__arg1" "" "" "" "$fault_code" - return - fi - if [ "$__arg1" = "InternetGatewayDevice." -a "$__arg2" = "0" ]; then - easycwmp_output "InternetGatewayDevice." "" "0" - fi - if [ "$__arg1" = "" ]; then - easycwmp_output "InternetGatewayDevice." "" "0" - if [ "$__arg2" = "1" ]; then - return - fi - __param="InternetGatewayDevice." - fi - easycwmp_execute_functions "$get_functions" "$__param" "$__arg2" - fault_code="$?" - - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - easycwmp_output "$__arg1" "" "" "" "$fault_code" - fi - fi - - if [ "$action" = "get_notification" ]; then - local __param - [ "$__arg1" = "" ] && __param="InternetGatewayDevice." || __param="$__arg1" - easycwmp_execute_functions "$get_functions" "$__param" - fault_code="$?" - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - easycwmp_output "$__arg1" "" "" "" "$fault_code" - fi - fi - - if [ "$action" = "set_value" ]; then + if [ "$action" = "get_value" ]; then + local __param + [ "$__arg1" = "" ] && __param="InternetGatewayDevice." || __param="$__arg1" + easycwmp_execute_functions "$get_functions" "$__param" + fault_code="$?" + + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + easycwmp_output "$__arg1" "" "" "" "$fault_code" + fi + fi + + if [ "$action" = "get_name" ]; then + local __param="$__arg1" + [ "`echo $__arg2 | awk '{print tolower($0)}'`" = "false" ] && __arg2="0" + [ "`echo $__arg2 | awk '{print tolower($0)}'`" = "true" ] && __arg2="1" + if [ "$__arg2" != "0" -a "$__arg2" != "1" ]; then + let fault_code=$E_INVALID_ARGUMENTS+9000 + easycwmp_output "$__arg1" "" "" "" "$fault_code" + return + fi + if [ "$__arg1" = "InternetGatewayDevice." -a "$__arg2" = "0" ]; then + easycwmp_output "InternetGatewayDevice." "" "0" + fi + if [ "$__arg1" = "" ]; then + easycwmp_output "InternetGatewayDevice." "" "0" + if [ "$__arg2" = "1" ]; then + return + fi + __param="InternetGatewayDevice." + fi + easycwmp_execute_functions "$get_functions" "$__param" "$__arg2" + fault_code="$?" + + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + easycwmp_output "$__arg1" "" "" "" "$fault_code" + fi + fi + + if [ "$action" = "get_notification" ]; then + local __param + [ "$__arg1" = "" ] && __param="InternetGatewayDevice." || __param="$__arg1" + easycwmp_execute_functions "$get_functions" "$__param" + fault_code="$?" + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + easycwmp_output "$__arg1" "" "" "" "$fault_code" + fi + fi + + if [ "$action" = "set_value" ]; then - local fault_code="0" - [ "$__arg1" = "" ] && fault_code=$E_INVALID_PARAMETER_NAME - if [ "$fault_code" = "0" ]; then - easycwmp_execute_functions "$set_functions" "$__arg1" "$__arg2" - fault_code="$?" - fi - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - easycwmp_set_parameter_fault "$__arg1" "$fault_code" - fi - fi - - if [ "$action" = "set_notification" ]; then - local fault_code="0" - [ "$__arg1" = "" ] && fault_code=$E_INVALID_PARAMETER_NAME - if [ "$fault_code" = "0" ]; then - easycwmp_execute_functions "$set_functions" "$__arg1" "$__arg2" - fault_code="$?" - fi - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - easycwmp_set_parameter_fault "$__arg1" "$fault_code" - fi - fi - - if [ "$action" = "download" ]; then -# TODO: check firmaware size with falsh to be improved - dl_size=`df |grep /tmp | awk '{print $4;}'` - dl_size_byte=$((${dl_size}*1024)) - if [ "$dl_size_byte" -lt "$__arg3" ]; then - let fault_code=9000+$E_DOWNLOAD_FAILURE - easycwmp_status_output "" "$fault_code" - else - rm -f $DOWNLOAD_FILE 2> /dev/null - local dw_url="$__arg1" - [ "$__arg4" != "" -o "$__arg5" != "" ] && dw_url=`echo "$__arg1" | sed -e "s@://@://$__arg4:$__arg5\@@g` - wget -O $DOWNLOAD_FILE "$dw_url" - fault_code="$?" - if [ "$fault_code" != "0" ]; then - let fault_code=9000+$E_DOWNLOAD_FAILURE - easycwmp_status_output "" "$fault_code" - else - easycwmp_status_output "" "" "1" - fi - fi - fi - if [ "$action" = "apply_download" ]; then - if [ "$__arg1" = "3 Vendor Configuration File" ]; then - /sbin/uci import < $DOWNLOAD_FILE - fault_code="$?" - if [ "$fault_code" != "0" ]; then - let fault_code=$E_DOWNLOAD_FAIL_FILE_CORRUPTED+9000 - easycwmp_status_output "" "$fault_code" - else - $UCI_COMMIT - sync - reboot - easycwmp_status_output "" "" "1" - fi - elif [ "$__arg1" = "1 Firmware Upgrade Image" ]; then - /sbin/sysupgrade $DOWNLOAD_FILE - fault_code="$?" - if [ "$fault_code" != "0" ]; then - let fault_code=$E_DOWNLOAD_FAIL_FILE_CORRUPTED+9000 - easycwmp_status_output "" "$fault_code" - else - easycwmp_status_output "" "" "1" - fi - else - easycwmp_status_output "" "$(($E_INVALID_ARGUMENTS+9000))" - fi - fi - if [ "$action" = "factory_reset" ]; then - jffs2_mark_erase "rootfs_data" - sync - reboot - fi - - if [ "$action" = "reboot" ]; then - sync - reboot - fi - - if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then - if [ ! -f "$set_fault_tmp_file" ]; then - $UCI_COMMIT - if [ "$action" = "apply_value" ]; then - $UCI_SET easycwmp.@acs[0].parameter_key="$__arg1" - $UCI_COMMIT - easycwmp_status_output "" "" "1" - fi - if [ "$action" = "apply_notification" ]; then - easycwmp_status_output "" "" "0" - fi - else - cat "$set_fault_tmp_file" - local cfg - local cfg_reverts=`$UCI_CHANGES | cut -d'.' -f1 | sort -u` - for cfg in $cfg_reverts; do - $UCI_REVERT $cfg - done - fi - rm -f "$set_fault_tmp_file" - fi - if [ "$action" = "apply_object" ]; then - $UCI_SET easycwmp.@acs[0].parameter_key="$__arg1" - $UCI_COMMIT - fi - if [ "$action" = "apply_service" ]; then - if [ -f "$apply_service_tmp_file" ]; then - chmod +x "$apply_service_tmp_file" - /bin/sh "$apply_service_tmp_file" - rm -f "$apply_service_tmp_file" - fi - fi - - if [ "$action" = "add_object" ]; then - easycwmp_execute_functions "$add_object_functions" "$__arg1" - fault_code="$?" - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - easycwmp_status_output "" "$fault_code" - fi - fi - - if [ "$action" = "delete_object" ]; then - easycwmp_execute_functions "$delete_object_functions" "$__arg1" - fault_code="$?" - if [ "$fault_code" != "0" ]; then - let fault_code=$fault_code+9000 - easycwmp_status_output "" "$fault_code" - fi - fi + local fault_code="0" + [ "$__arg1" = "" ] && fault_code=$E_INVALID_PARAMETER_NAME + if [ "$fault_code" = "0" ]; then + easycwmp_execute_functions "$set_functions" "$__arg1" "$__arg2" + fault_code="$?" + fi + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + easycwmp_set_parameter_fault "$__arg1" "$fault_code" + fi + fi + + if [ "$action" = "set_notification" ]; then + local fault_code="0" + [ "$__arg1" = "" ] && fault_code=$E_INVALID_PARAMETER_NAME + if [ "$fault_code" = "0" ]; then + easycwmp_execute_functions "$set_functions" "$__arg1" "$__arg2" + fault_code="$?" + fi + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + easycwmp_set_parameter_fault "$__arg1" "$fault_code" + fi + fi + + if [ "$action" = "download" ]; then + # TODO: check firmaware size with falsh to be improved + dl_size=`df |grep "/tmp$" | awk '{print $4;}'` + dl_size_byte=$((${dl_size}*1024)) + if [ "$dl_size_byte" -lt "$__arg3" ]; then + let fault_code=9000+$E_DOWNLOAD_FAILURE + easycwmp_status_output "" "$fault_code" + else + rm -f $DOWNLOAD_FILE 2> /dev/null + local dw_url="$__arg1" + [ "$__arg4" != "" -o "$__arg5" != "" ] && dw_url=`echo "$__arg1" | sed -e "s@://@://$__arg4:$__arg5\@@g` + wget -O $DOWNLOAD_FILE "$dw_url" + ORG_FILE_NAME=${dw_url##*'/'} + fault_code="$?" + if [ "$fault_code" != "0" ]; then + let fault_code=9000+$E_DOWNLOAD_FAILURE + easycwmp_status_output "" "$fault_code" + else + easycwmp_status_output "" "" "1" + fi + fi + fi + if [ "$action" = "apply_download" ]; then + if [ "$__arg1" = "3 Vendor Configuration File" ]; then + /sbin/uci import $ORG_FILE_NAME -f $DOWNLOAD_FILE + fault_code="$?" + if [ "$fault_code" != "0" ]; then + let fault_code=$E_DOWNLOAD_FAIL_FILE_CORRUPTED+9000 + easycwmp_status_output "" "$fault_code" + else + $UCI_COMMIT $ORG_FILE_NAME + sync + easycwmp_status_output "" "" "1" + fi + elif [ "$__arg1" = "1 Firmware Upgrade Image" ]; then + #/sbin/sysupgrade $DOWNLOAD_FILE + local minute=`date '+%M'` + local next_minute=$(( $minute + 1)) + local tmp=`date '+%H %d %m'` + #can not run sysupgrade now, should put it into cron + (crontab -l; echo "$next_minute $tmp * sysupgrade $DOWNLOAD_FILE; reboot") | crontab - + fault_code="$?" + if [ "$fault_code" != "0" ]; then + let fault_code=$E_DOWNLOAD_FAIL_FILE_CORRUPTED+9000 + easycwmp_status_output "" "$fault_code" + else + easycwmp_status_output "" "" "1" + fi + else + easycwmp_status_output "" "$(($E_INVALID_ARGUMENTS+9000))" + fi + fi + if [ "$action" = "factory_reset" ]; then + jffs2_mark_erase "rootfs_data" + sync + reboot + fi + + if [ "$action" = "reboot" ]; then + sync + reboot + fi + + if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then + if [ ! -f "$set_fault_tmp_file" ]; then + $UCI_COMMIT + if [ "$action" = "apply_value" ]; then + $UCI_SET easycwmp.@acs[0].parameter_key="$__arg1" + $UCI_COMMIT + easycwmp_status_output "" "" "1" + fi + if [ "$action" = "apply_notification" ]; then + easycwmp_status_output "" "" "0" + fi + else + cat "$set_fault_tmp_file" + local cfg + local cfg_reverts=`$UCI_CHANGES | cut -d'.' -f1 | sort -u` + for cfg in $cfg_reverts; do + $UCI_REVERT $cfg + done + fi + rm -f "$set_fault_tmp_file" + fi + if [ "$action" = "apply_object" ]; then + $UCI_SET easycwmp.@acs[0].parameter_key="$__arg1" + $UCI_COMMIT + fi + if [ "$action" = "apply_service" ]; then + if [ -f "$apply_service_tmp_file" ]; then + chmod +x "$apply_service_tmp_file" + /bin/sh "$apply_service_tmp_file" + rm -f "$apply_service_tmp_file" + fi + fi + + if [ "$action" = "add_object" ]; then + easycwmp_execute_functions "$add_object_functions" "$__arg1" + fault_code="$?" + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + easycwmp_status_output "" "$fault_code" + fi + fi + + if [ "$action" = "delete_object" ]; then + easycwmp_execute_functions "$delete_object_functions" "$__arg1" + fault_code="$?" + if [ "$fault_code" != "0" ]; then + let fault_code=$fault_code+9000 + easycwmp_status_output "" "$fault_code" + fi + fi - if [ "$action" = "inform_parameter" ]; then - easycwmp_get_inform_parameters - fi - - if [ "$action" = "inform_device_id" ]; then - easycwmp_get_inform_deviceid - fi - - if [ "$action" = "json_input" ]; then - echo "$EASYCWMP_PROMPT" - while read CMD; do - [ -z "$CMD" ] && continue - json_get_opt "$CMD" - handle_action - done - exit 0 - fi + if [ "$action" = "inform_parameter" ]; then + easycwmp_get_inform_parameters + fi + + if [ "$action" = "inform_device_id" ]; then + easycwmp_get_inform_deviceid + fi + + if [ "$action" = "json_input" ]; then + echo "$EASYCWMP_PROMPT" + while read CMD; do + [ -z "$CMD" ] && continue + json_get_opt "$CMD" + handle_action + done + exit 0 + fi } handle_action 2>/dev/null diff --git a/ext/openwrt/scripts/functions/common b/ext/openwrt/scripts/functions/common index ddc5082..43ad751 100644 --- a/ext/openwrt/scripts/functions/common +++ b/ext/openwrt/scripts/functions/common @@ -1,304 +1,322 @@ #!/bin/sh # Copyright (C) 2012-2014 PIVA Software -# Author: MOHAMED Kallel -# Author: AHMED Zribi +# Author: MOHAMED Kallel +# Author: AHMED Zribi +# Author: sinkcup # Copyright (C) 2011-2012 Luka Perkov +machine=$(grep "machine" /proc/cpuinfo | awk -F: '{print $2}' | sed -e 's/\(^ *\)//' -e 's/\( *$\)//') +openwrt_version=$(cat /etc/openwrt_version | head -1) + +#on the router hull, there is a device mac address, it's lan mac not wan mac. +network_get_mac() { + local iface="$1" + network_get_device ifname $iface + local cmd="ifconfig "$ifname" | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'" + local tmp=$(eval $cmd) + echo ${tmp//:/} + return $? +} +lan_mac=$(network_get_mac lan) +#see http://en.wikipedia.org/wiki/Organizationally_unique_identifier +#http://standards.ieee.org/develop/regauth/oui/public.html +oui=${lan_mac:0:6} + # TODO: merge this one somewhere in OpenWrt uci_remove_list_element() { - local option="$1" - local value="$2" - local list="$($UCI_GET get $option)" - local elem - - $UCI_DELETE $option - for elem in $list; do - if [ "$elem" != "$value" ]; then - $UCI_ADD_LIST $option=$elem - fi - done + local option="$1" + local value="$2" + local list="$($UCI_GET get $option)" + local elem + + $UCI_DELETE $option + for elem in $list; do + if [ "$elem" != "$value" ]; then + $UCI_ADD_LIST $option=$elem + fi + done } easycwmp_output() { -if [ "$FLAGS_json" = "${FLAGS_TRUE}" ]; then - local parameter="$1" - local value="$2" - local permissions="$3" - local type="$4" - local fault_code="$5" - easycwmp_json_output "$parameter" "$value" "$permissions" "$type" "$fault_code" -fi + if [ "$FLAGS_json" = "${FLAGS_TRUE}" ]; then + local parameter="$1" + local value="$2" + local permissions="$3" + local type="$4" + local fault_code="$5" + easycwmp_json_output "$parameter" "$value" "$permissions" "$type" "$fault_code" + fi } easycwmp_json_output() { - local parameter="$1" - local value="$2" - local permissions="$3" - local type="$4" - local fault_code="$5" + local parameter="$1" + local value="$2" + local permissions="$3" + local type="$4" + local fault_code="$5" - [ "$type" = "" ] && type="xsd:string" + [ "$type" = "" ] && type="xsd:string" - json_init - json_add_string "parameter" "$parameter" + json_init + json_add_string "parameter" "$parameter" json_add_string "fault_code" "$fault_code" - case "$action" in - get_value) - json_add_string "value" "$value" - json_add_string "type" "$type" - ;; - get_name) - json_add_string "writable" "$permissions" - ;; - get_notification) - json_add_string "notification" "$value" - ;; - esac - json_close_object - local msg=`json_dump` - echo "$msg" + case "$action" in + get_value) + json_add_string "value" "$value" + json_add_string "type" "$type" + ;; + get_name) + json_add_string "writable" "$permissions" + ;; + get_notification) + json_add_string "notification" "$value" + ;; + esac + json_close_object + local msg=`json_dump` + echo "$msg" } easycwmp_status_output() { - local parameter="$1" - local fault_code="$2" - local status="$3" - local instance="$4" - - json_init - [ "$parameter" != "" ] && json_add_string "parameter" "$parameter" - [ "$fault_code" != "" ] && json_add_string "fault_code" "$fault_code" - [ "$status" != "" ] && json_add_string "status" "$status" - [ "$instance" != "" ] && json_add_string "instance" "$instance" - [ "$easycwmp_config_changed" = "1" ] && json_add_string "config_load" "1" - json_close_object - local msg=`json_dump` - echo "$msg" + local parameter="$1" + local fault_code="$2" + local status="$3" + local instance="$4" + + json_init + [ "$parameter" != "" ] && json_add_string "parameter" "$parameter" + [ "$fault_code" != "" ] && json_add_string "fault_code" "$fault_code" + [ "$status" != "" ] && json_add_string "status" "$status" + [ "$instance" != "" ] && json_add_string "instance" "$instance" + [ "$easycwmp_config_changed" = "1" ] && json_add_string "config_load" "1" + json_close_object + local msg=`json_dump` + echo "$msg" } easycwmp_parse_formated_parameter() { - local _clean_parameter="$1" - local _formated_parameter="$2" - local _values - - if [ "${_formated_parameter#${_formated_parameter%?}}" != "${_clean_parameter#${_clean_parameter%?}}" -o\ - "${_clean_parameter//../}" != "$_clean_parameter" ]; then - eval "export -- \"$3=-1\"" - return - fi - - local _clean_parameter_array=`echo $_clean_parameter | sed 's/\./ /g'` - local _formated_parameter_array=`echo $_formated_parameter | sed 's/\./ /g'` - - if [ "`echo $_clean_parameter_array | wc -w`" != "`echo $_formated_parameter_array | wc -w`" ]; then - eval "export -- \"$3=-1\"" - return - fi - - local i - local j=0 - for i in $_formated_parameter_array - do - let j=$j+1 - if [ "x$i" == "x{i}" ]; then - # get value for sections maked as {i} - local m - local n=0 - for m in $_clean_parameter_array - do - let n=$n+1 - if [ $n -eq $j ]; then - if [ "x$_values" == "x" ]; then - _values="$m" - else - _values="$_values $m" - fi - fi - done - else - # check if sections not marked as {i} match - local m - local n=0 - for m in $_clean_parameter_array - do - let n=$n+1 - if [ $n -eq $j -a "x$m" != "x$i" ]; then - eval "export -- \"$3=-1\"" - return - fi - done - fi - done - - eval "export -- \"$3=0\"" - eval "export -- \"$4=\"\"$_values\"\"\"" + local _clean_parameter="$1" + local _formated_parameter="$2" + local _values + + if [ "${_formated_parameter#${_formated_parameter%?}}" != "${_clean_parameter#${_clean_parameter%?}}" -o\ + "${_clean_parameter//../}" != "$_clean_parameter" ]; then + eval "export -- \"$3=-1\"" + return + fi + + local _clean_parameter_array=`echo $_clean_parameter | sed 's/\./ /g'` + local _formated_parameter_array=`echo $_formated_parameter | sed 's/\./ /g'` + + if [ "`echo $_clean_parameter_array | wc -w`" != "`echo $_formated_parameter_array | wc -w`" ]; then + eval "export -- \"$3=-1\"" + return + fi + + local i + local j=0 + for i in $_formated_parameter_array + do + let j=$j+1 + if [ "x$i" == "x{i}" ]; then + # get value for sections maked as {i} + local m + local n=0 + for m in $_clean_parameter_array + do + let n=$n+1 + if [ $n -eq $j ]; then + if [ "x$_values" == "x" ]; then + _values="$m" + else + _values="$_values $m" + fi + fi + done + else + # check if sections not marked as {i} match + local m + local n=0 + for m in $_clean_parameter_array + do + let n=$n+1 + if [ $n -eq $j -a "x$m" != "x$i" ]; then + eval "export -- \"$3=-1\"" + return + fi + done + fi + done + + eval "export -- \"$3=0\"" + eval "export -- \"$4=\"\"$_values\"\"\"" } easycwmp_config_cwmp() { - config_get __parameter "$1" "parameter" - config_get __value "$1" "value" - - if [ "$__parameter" = "$4" ]; then - if [ "get" = "$2" ]; then - if [ "value" = "$3" ]; then - eval "export -- \"$5=\"\"$__value\"\"\"" - fi - elif [ "set" = "$2" ]; then - if [ "value" = "$3" ]; then - $UCI_SET easycwmp.$1.value=$5 2> /dev/null - fi - elif [ "check" = "$2" ]; then - if [ "parameter" = "$3" ]; then - eval "export -- \"$5=\"$1\"\"" - fi - fi - fi + config_get __parameter "$1" "parameter" + config_get __value "$1" "value" + + if [ "$__parameter" = "$4" ]; then + if [ "get" = "$2" ]; then + if [ "value" = "$3" ]; then + eval "export -- \"$5=\"\"$__value\"\"\"" + fi + elif [ "set" = "$2" ]; then + if [ "value" = "$3" ]; then + $UCI_SET easycwmp.$1.value=$5 2> /dev/null + fi + elif [ "check" = "$2" ]; then + if [ "parameter" = "$3" ]; then + eval "export -- \"$5=\"$1\"\"" + fi + fi + fi } easycwmp_config_notifications() { - config_get __active "$1" "active" - config_get __passive "$1" "passive" - - for item in $__active - do - 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 - do - 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 + config_get __active "$1" "active" + config_get __passive "$1" "passive" + + for item in $__active + do + 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 + do + 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 } easycwmp_get_parameter_value() { - local _dest="$1" - local _parm="$2" - local _val - config_load easycwmp - config_foreach easycwmp_config_cwmp "cwmp" "get" "value" "$_parm" "_val" - eval "export -- \"$_dest=\"\"$_val\"\"\"" + local _dest="$1" + local _param="$2" + local _val + config_load easycwmp + config_foreach easycwmp_config_cwmp "cwmp" "get" "value" "$_param" "_val" + eval "export -- \"$_dest=\"\"$_val\"\"\"" } easycwmp_set_parameter_value() { - local _parm="$1" - local _val="$2" - config_load easycwmp - config_foreach easycwmp_config_cwmp "cwmp" "check" "parameter" "$_parm" "_section" - if [ ! "$_section" = "" ]; then - $UCI_SET easycwmp.$_section.value=$_val 2> /dev/null - else - $UCI_BATCH << EOF 2>&1 >/dev/null - add easycwmp cwmp - set easycwmp.@cwmp[-1].parameter="$_parm" - set easycwmp.@cwmp[-1].value="$_val" + local _param="$1" + local _val="$2" + config_load easycwmp + config_foreach easycwmp_config_cwmp "cwmp" "check" "parameter" "$_param" "_section" + if [ ! "$_section" = "" ]; then + $UCI_SET easycwmp.$_section.value=$_val 2> /dev/null + else + $UCI_BATCH << EOF 2>&1 >/dev/null + add easycwmp cwmp + set easycwmp.@cwmp[-1].parameter="$_param" + set easycwmp.@cwmp[-1].value="$_val" EOF - fi - config_foreach easycwmp_config_notifications "notifications" "get" "$_parm" "tmp" + fi + config_foreach easycwmp_config_notifications "notifications" "get" "$_param" "tmp" } easycwmp_get_parameter_notification() { - local _dest="$1" - local _parm="$2" - local _val=0 - local p ntype len maxlen=0 - - for ntype in "active:2" "passive:1" "none:0"; do - local list_notif=`$UCI_GET easycwmp.@notifications[0].${ntype%:*}` - for p in $list_notif; do - if [ "$p" = "$_parm" ]; then - _val=${ntype#*:} - eval "export -- \"$_dest=$_val\"" - return - fi - case $p in - *.) - case $_parm in - $p*) - len=${#p} - if [ $len -gt $maxlen ]; then - _val=${ntype#*:} - maxlen=$len - fi - esac - ;; - esac - done - done - eval "export -- \"$_dest=$_val\"" + local _dest="$1" + local _param="$2" + local _val=0 + local p ntype len maxlen=0 + + for ntype in "active:2" "passive:1" "none:0"; do + local list_notif=`$UCI_GET easycwmp.@notifications[0].${ntype%:*}` + for p in $list_notif; do + if [ "$p" = "$_param" ]; then + _val=${ntype#*:} + eval "export -- \"$_dest=$_val\"" + return + fi + case $p in + *.) + case $_param in + $p*) + len=${#p} + if [ $len -gt $maxlen ]; then + _val=${ntype#*:} + maxlen=$len + fi + esac + ;; + esac + done + done + eval "export -- \"$_dest=$_val\"" } easycwmp_remove_parameter_notification() { - local _parm="$1" - local ntype - for ntype in active passive none; do - case $_parm in - *.) - local list_del=`$UCI_GET easycwmp.@notifications[0].$ntype` - local del - for del in $list_del; do - case $del in - $_parm*) - $UCI_DEL_LIST easycwmp.@notifications[0].$ntype=$del 2>/dev/null - ;; - esac - done - ;; - *) - $UCI_DEL_LIST easycwmp.@notifications[0].$ntype=$_parm 2>/dev/null - ;; - esac - done + local _param="$1" + local ntype + for ntype in active passive none; do + case $_param in + *.) + local list_del=`$UCI_GET easycwmp.@notifications[0].$ntype` + local del + for del in $list_del; do + case $del in + $_param*) + $UCI_DEL_LIST easycwmp.@notifications[0].$ntype=$del 2>/dev/null + ;; + esac + done + ;; + *) + $UCI_DEL_LIST easycwmp.@notifications[0].$ntype=$_param 2>/dev/null + ;; + esac + done } easycwmp_set_parameter_notification() { - local _parm="$1" - local _val="$2" - local tmp=`$UCI_GET easycwmp.@notifications[0] 2>/dev/null` - if [ "$tmp" = "" ]; then - $UCI_ADD easycwmp notifications 2>&1 >/dev/null - else - easycwmp_remove_parameter_notification $_parm - fi - local notif - easycwmp_get_parameter_notification notif $_parm - [ "$notif" = "$_val" ] && return - if [ "$_val" -eq "1" ]; then - $UCI_ADD_LIST easycwmp.@notifications[0].passive="$_parm" 2>&1 >/dev/null - elif [ "$_val" -eq "2" ]; then - $UCI_ADD_LIST easycwmp.@notifications[0].active="$_parm" 2>&1 >/dev/null - elif [ "$_val" -eq "0" ]; then - local list_prm="`$UCI_GET easycwmp.@notifications[0].active` `$UCI_GET easycwmp.@notifications[0].passive`" - for prm in $list_prm; do - case $prm in - *.) - case $_parm in - $prm*) - $UCI_ADD_LIST easycwmp.@notifications[0].none="$_parm" 2>&1 >/dev/null - break - ;; - esac - ;; - esac - done - fi + local _param="$1" + local _val="$2" + local tmp=`$UCI_GET easycwmp.@notifications[0] 2>/dev/null` + if [ "$tmp" = "" ]; then + $UCI_ADD easycwmp notifications 2>&1 >/dev/null + else + easycwmp_remove_parameter_notification $_param + fi + local notif + easycwmp_get_parameter_notification notif $_param + [ "$notif" = "$_val" ] && return + if [ "$_val" -eq "1" ]; then + $UCI_ADD_LIST easycwmp.@notifications[0].passive="$_param" 2>&1 >/dev/null + elif [ "$_val" -eq "2" ]; then + $UCI_ADD_LIST easycwmp.@notifications[0].active="$_param" 2>&1 >/dev/null + elif [ "$_val" -eq "0" ]; then + local list_prm="`$UCI_GET easycwmp.@notifications[0].active` `$UCI_GET easycwmp.@notifications[0].passive`" + for prm in $list_prm; do + case $prm in + *.) + case $_param in + $prm*) + $UCI_ADD_LIST easycwmp.@notifications[0].none="$_param" 2>&1 >/dev/null + break + ;; + esac + ;; + esac + done + fi } delay_service_restart_in_apply_service() { -local service="$1" -local delay="$2" -[ "`cat $apply_service_tmp_file 2>/dev/null | grep /etc/init.d/$service`" != "" ] && return + local service="$1" + local delay="$2" + [ "`cat $apply_service_tmp_file 2>/dev/null | grep /etc/init.d/$service`" != "" ] && return cat >> "$apply_service_tmp_file" </dev/null 2>/dev/null sleep $delay @@ -307,75 +325,82 @@ EOF } execute_command_in_apply_service() { -local command="$1" -local chk=`cat "$apply_service_tmp_file" 2>/dev/null | grep "^$command "` -[ "$chk" != "" ] && return + local command="$1" + local chk=`cat "$apply_service_tmp_file" 2>/dev/null | grep "^$command "` + [ "$chk" != "" ] && return cat >> "$apply_service_tmp_file" </dev/null 2>/dev/null EOF } easycwmp_set_parameter_fault() { - local _parm="$1" - local _fault="$2" - easycwmp_output "$_parm" "" "" "" "$_fault" >> $set_fault_tmp_file + local _param="$1" + local _fault="$2" + easycwmp_output "$_param" "" "" "" "$_fault" >> $set_fault_tmp_file } easycwmp_execute_functions() { - local function_list="$1" - local arg1="$2" - local arg2="$3" - local arg3="$4" - local no_fault="0" - local fault_code="" - - for function_name in $function_list - do - $function_name "$arg1" "$arg2" "$arg3" - fault_code="$?" - if [ "$fault_code" = "0" ]; then - no_fault="1" - fi - if [ "$fault_code" != "0" -a "$fault_code" != "$E_INVALID_PARAMETER_NAME" ]; then - return $fault_code - fi - done - if [ "$no_fault" = "1" ]; then fault_code="0"; fi - return $fault_code + local function_list="$1" + local arg1="$2" + local arg2="$3" + local arg3="$4" + local no_fault="0" + local fault_code="" + + for function_name in $function_list + do + $function_name "$arg1" "$arg2" "$arg3" + fault_code="$?" + if [ "$fault_code" = "0" ]; then + no_fault="1" + fi + if [ "$fault_code" != "0" -a "$fault_code" != "$E_INVALID_PARAMETER_NAME" ]; then + return $fault_code + fi + done + if [ "$no_fault" = "1" ]; then fault_code="0"; fi + return $fault_code } easycwmp_get_inform_parameters() { - action="get_value" - 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_management_server_connection_request_url - get_wan_device_mng_interface_ip - get_device_info_specversion - get_device_info_provisioningcode - get_management_server_parameterkey + action="get_value" + 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_management_server_connection_request_url + get_wan_device_mng_interface_ip + get_device_info_specversion + get_device_info_provisioningcode + get_management_server_parameterkey } easycwmp_get_inform_deviceid() { - local msg - json_init - - json_add_string "manufacturer" "`$UCI_GET easycwmp.@device[0].manufacturer 2> /dev/null`" - json_add_string "oui" "`$UCI_GET easycwmp.@device[0].oui 2> /dev/null`" - json_add_string "product_class" "`$UCI_GET easycwmp.@device[0].product_class 2> /dev/null`" - json_add_string "serial_number" "`$UCI_GET easycwmp.@device[0].serial_number 2> /dev/null`" + local msg + json_init - json_close_object - local msg=`json_dump` - echo "$msg" + local val=$(_get_device_info_manufacturer) + json_add_string "manufacturer" "$val" + + val=$(_get_device_info_oui) + json_add_string "oui" "$val" + + val=$(_get_device_info_product_class) + json_add_string "product_class" "$val" + + val=$(_get_device_info_serial_number) + json_add_string "serial_number" "$val" + + json_close_object + local msg=`json_dump` + echo "$msg" } easycwmp_config_load() { - easycwmp_config_changed="1" -} \ No newline at end of file + easycwmp_config_changed="1" +} diff --git a/ext/openwrt/scripts/functions/device_info b/ext/openwrt/scripts/functions/device_info index 6fa8d64..ef7c60d 100644 --- a/ext/openwrt/scripts/functions/device_info +++ b/ext/openwrt/scripts/functions/device_info @@ -1,364 +1,436 @@ #!/bin/sh # Copyright (C) 2012-2014 PIVA Software -# Author: MOHAMED Kallel -# Author: AHMED Zribi +# Author: MOHAMED Kallel +# Author: AHMED Zribi # Copyright (C) 2011-2012 Luka Perkov +get_device_info_mac() { + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.MACAddress" + local permissions="0" + case "$action" in + get_value) + #see http://wiki.openwrt.org/doc/uci + val=$(network_get_mac "lan") + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + + easycwmp_output "$param" "$val" "$permissions" + return 0 +} + get_device_info_specversion() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.SpecVersion" -local permissions="0" -case "$action" in - get_value) - val="1.0" - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.SpecVersion" + local permissions="0" + case "$action" in + get_value) + val="1.0" + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_device_info_provisioningcode() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.ProvisioningCode" -local permissions="1" -case "$action" in - get_value) - easycwmp_get_parameter_value "val" "$param" - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.ProvisioningCode" + local permissions="1" + case "$action" in + get_value) + easycwmp_get_parameter_value "val" "$param" + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_device_info_provisioningcode() { -local val=$1 -local param="InternetGatewayDevice.DeviceInfo.ProvisioningCode" -case "$action" in - set_value) - easycwmp_set_parameter_value "$param" "$val" - ;; - set_notification) - easycwmp_set_parameter_notification "$param" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.DeviceInfo.ProvisioningCode" + case "$action" in + set_value) + easycwmp_set_parameter_value "$param" "$val" + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac + return $? +} + +_get_device_info_manufacturer() { + local val=`$UCI_GET easycwmp.@device[0].manufacturer 2> /dev/null` + if [ -z "$val" ] || [ "$val" = "easycwmp" ]; then + val=$(echo $machine | tr A-Z a-z | awk '{print $1}') + fi + echo "$val" + return 0 } get_device_info_manufacturer() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.Manufacturer" -local permissions="0" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@device[0].manufacturer 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.Manufacturer" + local permissions="0" + case "$action" in + get_value) + val=$(_get_device_info_manufacturer) + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 +} + +_get_device_info_oui() { + local val=`$UCI_GET easycwmp.@device[0].oui 2> /dev/null` + if [ -z "$val" ] || [ "$val" = "FFFFFF" ]; then + val=$oui + fi + echo "$val" + return 0 } get_device_info_oui() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.ManufacturerOUI" -local permissions="0" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@device[0].oui 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.ManufacturerOUI" + local permissions="0" + case "$action" in + get_value) + val=$(_get_device_info_oui) + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 +} + +_get_device_info_product_class() { + local val=`$UCI_GET easycwmp.@device[0].product_class 2> /dev/null` + if [ -z "$val" ] || [ "$val" = "easycwmp" ]; then + tmp=${machine// /_} + val=$(echo $tmp | tr A-Z a-z) + fi + echo "$val" + return 0 } get_device_info_product_class() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.ProductClass" -local permissions="0" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@device[0].product_class 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.ProductClass" + local permissions="0" + case "$action" in + get_value) + val=$(_get_device_info_product_class) + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 +} + +_get_device_info_serial_number() { + local val=`$UCI_GET easycwmp.@device[0].serial_number 2> /dev/null` + if [ -z "$val" ] || [ "$val" = "FFFFFF123456" ]; then + val=$(network_get_mac "lan") + fi + echo "$val" + return 0 } get_device_info_serial_number() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.SerialNumber" -local permissions="0" -case "$action" in - get_value) - local val=`$UCI_GET easycwmp.@device[0].serial_number 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.SerialNumber" + local permissions="0" + case "$action" in + get_value) + val=$(_get_device_info_serial_number) + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_device_info_hardware_version() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.HardwareVersion" -local permissions="0" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@device[0].hardware_version 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.HardwareVersion" + local permissions="0" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@device[0].hardware_version 2> /dev/null` + if [ -z "$val" ] || [ "$val" = "example_hw_version" ]; then + val=$(cat /proc/cmdline | awk '{print $1}' | awk -F= '{print $2}') + fi + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_device_info_software_version() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.SoftwareVersion" -local permissions="0" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@device[0].software_version 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.SoftwareVersion" + local permissions="0" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@device[0].software_version 2> /dev/null` + if [ -z "$val" ] || [ "$val" = "example_sw_version" ]; then + val=$(cat /etc/openwrt_version) + fi + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_device_info_uptime() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.UpTime" -local permissions="0" -case "$action" in - get_value) - val=`cat /proc/uptime | awk -F "." '{ print $1 }'` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.UpTime" + local permissions="0" + case "$action" in + get_value) + val=`cat /proc/uptime | awk -F "." '{ print $1 }'` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_device_info_device_log() { -local nl="$1" -local val="" -local param="InternetGatewayDevice.DeviceInfo.DeviceLog" -local permissions="0" -case "$action" in - #get_value) - #if [ ${FLAGS_last} -eq ${FLAGS_TRUE} ]; then - # val=`dmesg | tail -n1` - #else - # val=`dmesg | tail -n10` - #fi - #;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$param" - ;; -esac -easycwmp_output "$param" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.DeviceInfo.DeviceLog" + local permissions="0" + case "$action" in + #get_value) + #if [ ${FLAGS_last} -eq ${FLAGS_TRUE} ]; then + # val=`dmesg | tail -n1` + #else + # val=`dmesg | tail -n10` + #fi + #;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_device_info_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.DeviceInfo." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.DeviceInfo." "" "0" + ;; + esac } get_device_info() { -case "$1" in - InternetGatewayDevice.) - get_device_info_object 0 - get_device_info_manufacturer "$2" - get_device_info_oui "$2" - get_device_info_product_class "$2" - get_device_info_serial_number "$2" - get_device_info_hardware_version "$2" - get_device_info_software_version "$2" - get_device_info_uptime "$2" - get_device_info_device_log "$2" - get_device_info_specversion "$2" - get_device_info_provisioningcode "$2" - return 0 - ;; - InternetGatewayDevice.DeviceInfo.) - get_device_info_object "$2" - get_device_info_manufacturer 0 - get_device_info_oui 0 - get_device_info_product_class 0 - get_device_info_serial_number 0 - get_device_info_hardware_version 0 - get_device_info_software_version 0 - get_device_info_uptime 0 - get_device_info_device_log 0 - get_device_info_specversion 0 - get_device_info_provisioningcode 0 - return 0 - ;; - InternetGatewayDevice.DeviceInfo.SpecVersion) - get_device_info_specversion "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.ProvisioningCode) - get_device_info_provisioningcode "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.Manufacturer) - get_device_info_manufacturer "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.ManufacturerOUI) - get_device_info_oui "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.ProductClass) - get_device_info_product_class "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.SerialNumber) - get_device_info_serial_number "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.HardwareVersion) - get_device_info_hardware_version "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.SoftwareVersion) - get_device_info_software_version "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.UpTime) - get_device_info_uptime "$2" - return $? - ;; - InternetGatewayDevice.DeviceInfo.DeviceLog) - get_device_info_device_log "$2" - return $? - ;; -esac -return $E_INVALID_PARAMETER_NAME + case "$1" in + InternetGatewayDevice.) + get_device_info_object 0 + get_device_info_manufacturer "$2" + get_device_info_oui "$2" + get_device_info_product_class "$2" + get_device_info_serial_number "$2" + get_device_info_hardware_version "$2" + get_device_info_software_version "$2" + get_device_info_uptime "$2" + get_device_info_device_log "$2" + get_device_info_mac "$2" + get_device_info_specversion "$2" + get_device_info_provisioningcode "$2" + return 0 + ;; + InternetGatewayDevice.DeviceInfo.) + get_device_info_object "$2" + get_device_info_manufacturer 0 + get_device_info_oui 0 + get_device_info_product_class 0 + get_device_info_serial_number 0 + get_device_info_hardware_version 0 + get_device_info_software_version 0 + get_device_info_uptime 0 + get_device_info_device_log 0 + get_device_info_mac 0 + get_device_info_specversion 0 + get_device_info_provisioningcode 0 + return 0 + ;; + InternetGatewayDevice.DeviceInfo.MACAddress) + get_device_info_mac "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.SpecVersion) + get_device_info_specversion "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.ProvisioningCode) + get_device_info_provisioningcode "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.Manufacturer) + get_device_info_manufacturer "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.ManufacturerOUI) + get_device_info_oui "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.ProductClass) + get_device_info_product_class "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.SerialNumber) + get_device_info_serial_number "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.HardwareVersion) + get_device_info_hardware_version "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.SoftwareVersion) + get_device_info_software_version "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.UpTime) + get_device_info_uptime "$2" + return $? + ;; + InternetGatewayDevice.DeviceInfo.DeviceLog) + get_device_info_device_log "$2" + return $? + ;; + esac + return $E_INVALID_PARAMETER_NAME } set_device_info() { -local fcode -case "$action" in - set_value) - fcode=$E_NON_WRITABLE_PARAMETER - ;; - set_notification) - fcode=$E_NOTIFICATION_REJECTED - ;; -esac + local fcode + case "$action" in + set_value) + fcode=$E_NON_WRITABLE_PARAMETER + ;; + set_notification) + fcode=$E_NOTIFICATION_REJECTED + ;; + esac -case "$1" in - InternetGatewayDevice.) - [ "$action" = "set_notification" ] && return $fcode - ;; - InternetGatewayDevice.DeviceInfo.) - [ "$action" = "set_notification" ] && return $fcode - ;; - InternetGatewayDevice.DeviceInfo.SpecVersion) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.Manufacturer) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.ManufacturerOUI) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.ProductClass) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.SerialNumber) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.HardwareVersion) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.SoftwareVersion) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.UpTime) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.DeviceLog) - return $fcode - ;; - InternetGatewayDevice.DeviceInfo.ProvisioningCode) - set_device_info_provisioningcode "$2" - return 0 - ;; -esac -return $E_INVALID_PARAMETER_NAME + case "$1" in + InternetGatewayDevice.) + [ "$action" = "set_notification" ] && return $fcode + ;; + InternetGatewayDevice.DeviceInfo.) + [ "$action" = "set_notification" ] && return $fcode + ;; + InternetGatewayDevice.DeviceInfo.SpecVersion) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.Manufacturer) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.ManufacturerOUI) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.ProductClass) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.SerialNumber) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.HardwareVersion) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.SoftwareVersion) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.UpTime) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.DeviceLog) + return $fcode + ;; + InternetGatewayDevice.DeviceInfo.ProvisioningCode) + set_device_info_provisioningcode "$2" + return 0 + ;; + esac + return $E_INVALID_PARAMETER_NAME } build_instances_device_info() { return 0; } add_object_device_info() { return $E_INVALID_PARAMETER_NAME; } -delete_object_device_info() { return $E_INVALID_PARAMETER_NAME; } \ No newline at end of file +delete_object_device_info() { return $E_INVALID_PARAMETER_NAME; } diff --git a/ext/openwrt/scripts/functions/lan_device b/ext/openwrt/scripts/functions/lan_device index 362cc48..f802678 100644 --- a/ext/openwrt/scripts/functions/lan_device +++ b/ext/openwrt/scripts/functions/lan_device @@ -1,315 +1,656 @@ #!/bin/sh # Copyright (C) 2012-2014 PIVA Software -# Author: MOHAMED Kallel -# Author: AHMED Zribi +# Author: MOHAMED Kallel +# Author: AHMED Zribi +# Author: sinkcup # Copyright (C) 2011-2012 Luka Perkov +wireless_devices=`$UCI_SHOW wireless | grep "wireless.[a-z0-9]\+=wifi-device" | awk -F= '{print $1}' | awk -F. '{print $2}'` +wireless_devices_cnt=$(echo "$wireless_devices" | wc -l) + +is_special=0 +#see http://standards.ieee.org/develop/regauth/oui/public.html +#D4EE07 (base 16) HIWIFI Co., Ltd. +if [ "$oui" = "D4EE07" ]; then + # from 0.9008.2.8061s, hiwifi use special config + # config wifi-device 'radio0' + # option type 'ralink' + # option channel '0' + # option txpwr 'max' + # + # config wifi-iface 'master' + # option device 'radio0' + # option ifname 'ra0' + # option ifname2 'rai0' + # option network 'lan' + # option mode 'ap' + # option ssid 'HiFree_1313FC' + # option encryption 'mixed-psk' + # option key '1234' + # option disabled '0' + # + # config wifi-iface 'slave' + # option device 'radio0' + # option ifname 'apcli0' + # option network 'lan' + # option mode 'sta' + # option ssid 'HiWiFi_1313FC' + # option encryption 'none' + # option disabled '1' + # + # config wifi-iface 'guest' + # option device 'radio0' + # option ifname 'ra1' + # option ifname2 'rai1' + # option network 'lan' + # option mode 'ap' + # option ssid 'HiWiFi_guest' + # option encryption 'none' + # option isolate '1' + # option disabled '1' + + is_special=1 + tmp=$(printf "0.9008.2.8061s\n$openwrt_version\n" | sort | head -1) + if [ "$tmp" != "0.9008.2.8061s" ];then + is_special=0 + fi + + if [ $is_special -eq 1 ];then + wireless_ifaces=`$UCI_SHOW wireless | grep "wireless.[a-z]\+=wifi-iface" | awk -F= '{print $1}' | awk -F. '{print $2}'` + fi +fi + +# for most of routers +if [ $is_special -eq 0 ];then + wireless_ifaces=`$UCI_SHOW wireless| grep "wireless\.@wifi-iface\[[0-9]\+\]\.device" | cut -d'.' -f2` +fi +wireless_ifaces_cnt=$(echo "$wireless_ifaces" | wc -l) get_wlan_enable() { -local parm="InternetGatewayDevice.LANDevice.1.WLANConfiguration.$1.Enable" -local uci_iface="$2" -local nl="$3" -local type="xsd:boolean" -local val="" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET wireless.wl0.disabled 2> /dev/null` - [ "$val" = "1" ] && val="0" || val="1" - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" "$type" -return 0 + local param="InternetGatewayDevice.LANDevice.$1.WLANConfiguration.$3.Enable" + local uci_device="$2" + local uci_iface="$4" + local nl="$5" + local type="xsd:boolean" + local val="" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET wireless.$uci_iface.disabled 2> /dev/null` + [ "$val" = "1" ] && val="0" || val="1" + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 } get_wlan_enable_all() { - local nl="$1" - local iface - local ifaces=`$UCI_SHOW wireless| grep "wireless\.@wifi-iface\[[0-9]\+\]\.instance" | cut -d'.' -f2` - for iface in $ifaces; do - local num=`$UCI_GET wireless.$iface.instance` - get_wlan_enable "$num" "$iface" "$nl" - done + local nl="$1" + local device + local iface + for device in $wireless_devices; do + local device_num=`$UCI_GET wireless.$device.instance` + get_wlan_enable_by_device "$device_num" "$device" "$nl" + done +} + +get_wlan_enable_by_device() { + local device_num="$1" + local device="$2" + local nl="$3" + local iface + for iface in $wireless_ifaces; do + local iface_num=`$UCI_GET wireless.$iface.instance` + local iface_device=`$UCI_GET wireless.$iface.device` + if [ "$iface_device" = "$device" ]; then + get_wlan_enable "$device_num" "$device" "$iface_num" "$iface" "$nl" + fi + done } set_wlan_enable() { -local parm="InternetGatewayDevice.LANDevice.1.WLANConfiguration.$1.Enable" -local uci_iface="$2" -local val="$3" -case $action in - set_value) - [ "$val" = "1" ] && val="0" || val="1" - execute_command_in_apply_service "wifi" - $UCI_SET wireless.wl0.disabled="$val" - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local param="InternetGatewayDevice.LANDevice.$1.WLANConfiguration.$3.Enable" + local uci_iface="$4" + local val="$5" + case $action in + set_value) + local disabled="1" + if [ "$val" = "1" -o "$val" = "true" ]; then + disabled="0" + fi + $UCI_SET wireless.$uci_iface.disabled="$disabled" + $UCI_COMMIT wireless + execute_command_in_apply_service "wifi" + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac +} + +get_wlan_maxassoc() { + local param="InternetGatewayDevice.LANDevice.$1.WLANConfiguration.$3.MaxAssoc" + local uci_device="$2" + local uci_iface="$4" + local nl="$5" + local type="xsd:unsignedInt" + local val="" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET wireless.$uci_iface.maxassoc 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 +} + +get_wlan_maxassoc_all() { + local nl="$1" + local device + local iface + for device in $wireless_devices; do + local device_num=`$UCI_GET wireless.$device.instance` + get_wlan_maxassoc_by_device "$device_num" "$device" "$nl" + done +} + +get_wlan_maxassoc_by_device() { + local device_num="$1" + local device="$2" + local nl="$3" + local iface + for iface in $wireless_ifaces; do + local iface_num=`$UCI_GET wireless.$iface.instance` + local iface_device=`$UCI_GET wireless.$iface.device` + if [ "$iface_device" = "$device" ]; then + get_wlan_maxassoc "$device_num" "$device" "$iface_num" "$iface" "$nl" + fi + done +} + +set_wlan_maxassoc() { + local param="InternetGatewayDevice.LANDevice.$1.WLANConfiguration.$3.MaxAssoc" + local uci_iface="$4" + local val="$5" + case $action in + set_value) + $UCI_SET wireless.$uci_iface.maxassoc="$val" + $UCI_COMMIT wireless + execute_command_in_apply_service "wifi" + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_wlan_ssid() { -local parm="InternetGatewayDevice.LANDevice.1.WLANConfiguration.$1.SSID" -local uci_iface="$2" -local nl="$3" -local val="" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET wireless.$uci_iface.ssid 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local param="InternetGatewayDevice.LANDevice.$1.WLANConfiguration.$3.SSID" + local uci_device="$2" + local uci_iface="$4" + local nl="$5" + local val="" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET wireless.$uci_iface.ssid 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } +#TODO: DRY, same as get_wlan_enable_all get_wlan_ssid_all() { - local nl="$1" - local iface - local ifaces=`$UCI_SHOW wireless| grep "wireless\.@wifi-iface\[[0-9]\+\]\.instance" | cut -d'.' -f2` - for iface in $ifaces; do - local num=`$UCI_GET wireless.$iface.instance` - get_wlan_ssid "$num" "$iface" "$nl" - done + local nl="$1" + local device + local iface + for device in $wireless_devices; do + local device_num=`$UCI_GET wireless.$device.instance` + get_wlan_ssid_by_device "$device_num" "$device" "$nl" + done +} + +#TODO: DRY, same as get_wlan_enable_by_device +get_wlan_ssid_by_device() { + local device_num="$1" + local device="$2" + local nl="$3" + local iface + for iface in $wireless_ifaces; do + local iface_num=`$UCI_GET wireless.$iface.instance` + local iface_device=`$UCI_GET wireless.$iface.device` + if [ "$iface_device" = "$device" ]; then + get_wlan_ssid "$device_num" "$device" "$iface_num" "$iface" "$nl" + fi + done } set_wlan_ssid() { -local parm="InternetGatewayDevice.LANDevice.1.WLANConfiguration.$1.SSID" -local uci_iface="$2" -local val="$3" -case $action in - set_value) - execute_command_in_apply_service "wifi" - $UCI_SET wireless.$uci_iface.ssid="$val" - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local param="InternetGatewayDevice.LANDevice.$1.WLANConfiguration.$3.SSID" + local uci_iface="$4" + local val="$5" + case $action in + set_value) + $UCI_SET wireless.$uci_iface.ssid="$val" + $UCI_COMMIT wireless + execute_command_in_apply_service "wifi" + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac +} + +get_lan_device_channel() { + local param="InternetGatewayDevice.LANDevice.$1.Channel" + local uci_device="$2" + local nl="$3" + local val="" + local permissions="1" + local type="xsd:unsignedInt" + case "$action" in + get_value) + val=`$UCI_GET wireless.$uci_device.channel 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 +} + +get_lan_device_channel_all() { + local nl="$1" + local device + local iface + for device in $wireless_devices; do + local device_num=`$UCI_GET wireless.$device.instance` + get_lan_device_channel "$device_num" "$device" "$nl" + done +} + +set_lan_device_channel() { + local param="InternetGatewayDevice.LANDevice.$1.Channel" + local uci_device="$2" + local val="$3" + case $action in + set_value) + $UCI_SET wireless.$uci_device.channel="$val" + $UCI_COMMIT wireless + execute_command_in_apply_service "wifi" + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } add_wlan_iface() { - local instance=`get_max_instance` - local wifi_iface=`$UCI_ADD wireless wifi-iface` - $UCI_SET wireless.$wifi_iface.device=wl0 - $UCI_SET wireless.$wifi_iface.encryption=none - $UCI_SET wireless.$wifi_iface.mode=ap - $UCI_SET wireless.$wifi_iface.ssid=DefaultSSID - $UCI_SET wireless.$wifi_iface.instance=$((++instance)) - $UCI_COMMIT - execute_command_in_apply_service "wifi" - echo $instance + local instance=`get_max_instance` + local wifi_iface=`$UCI_ADD wireless wifi-iface` + $UCI_SET wireless.$wifi_iface.device=wl0 + $UCI_SET wireless.$wifi_iface.encryption=none + $UCI_SET wireless.$wifi_iface.mode=ap + $UCI_SET wireless.$wifi_iface.ssid=DefaultSSID + $UCI_SET wireless.$wifi_iface.instance=$((++instance)) + $UCI_COMMIT + execute_command_in_apply_service "wifi" + echo $instance } delete_wlan_iface() { - $UCI_DELETE wireless.$1 - $UCI_COMMIT - execute_command_in_apply_service "wifi" + $UCI_DELETE wireless.$1 + $UCI_COMMIT + execute_command_in_apply_service "wifi" } get_wlan_configuration_instances() { - local nl="$1" - [ "$action" != "get_name" -o "$nl" = "1" ] && return - local num - local instances=`$UCI_SHOW wireless| grep "wireless\.@wifi-iface\[[0-9]\+\]\.instance" | cut -d'=' -f2` - for num in $instances; do - easycwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration.$num." "" "1" - done -} + local nl="$1" + [ "$action" != "get_name" -o "$nl" = "1" ] && return + for device in $wireless_devices; do + local device_num=`$UCI_GET wireless.$device.instance` + for iface in $wireless_ifaces; do + local iface_num=`$UCI_GET wireless.$iface.instance` + easycwmp_output "InternetGatewayDevice.LANDevice.$device_num.WLANConfiguration.$iface_num." "" "1" + done + done +} + +get_wlan_device_num_and_uci_device() { + local param="$1" + local param_check="$2" + easycwmp_parse_formated_parameter "$param" "$param_check" "rc" "__nums" + [ "$rc" != "0" ] && return + local __device_num=`echo $__nums | awk '{print $1}'` + local device + for device in $wireless_devices; do + local tmp=`$UCI_GET wireless.$device.instance` + if [ "$tmp" = "$__device_num" ];then + eval "export -- \"$3=\"\"$__device_num\"\"\"" + eval "export -- \"$4=\"\"$device\"\"\"" + break + fi + done +} get_wlan_num_and_uci_iface() { - local parm="$1" - local parm_check="$2" - easycwmp_parse_formated_parameter "$parm" "$parm_check" "rc" "__num" - [ "$rc" != "0" ] && return - local __uci_iface=`$UCI_SHOW wireless | grep "wireless\.@wifi-iface\[[0-9]\+\].instance=$__num" | head -1 | cut -d'.' -f2` - eval "export -- \"$3=\"\"$__num\"\"\"" - eval "export -- \"$4=\"\"$__uci_iface\"\"\"" + local param="$1" + local param_check="$2" + local uci_device="$4" + easycwmp_parse_formated_parameter "$param" "$param_check" "rc" "__nums" + [ "$rc" != "0" ] && return + local __iface_num=`echo $__nums | awk '{print $2}'` + local iface + local __tmp_device + local __tmp_iface_num + for iface in $wireless_ifaces; do + __tmp_uci_device=`$UCI_GET wireless.$iface.device` + __tmp_iface_num=`$UCI_GET wireless.$iface.instance` + if [ "$__tmp_uci_device" = "$uci_device" -a "$__tmp_iface_num" = "$__iface_num" ];then + eval "export -- \"$5=\"\"$__iface_num\"\"\"" + eval "export -- \"$6=\"\"$iface\"\"\"" + break + fi + done } get_max_instance() { - local max=`$UCI_SHOW wireless | grep "wireless\.@wifi-iface\[[0-9]\+\].instance=" | cut -d'=' -f2 | sort -ru | head -1` - echo ${max:-0} + local max=0 + for iface in $wireless_ifaces; do + local num=`$UCI_GET wireless.$iface.instance` + if [ $num -gt $max ]; then + max=$num + fi + done + echo $max } get_lan_device_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.LANDevice." "" "0" - ;; -esac + local nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.LANDevice." "" "0" + ;; + esac } -get_lan_device_instance() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.LANDevice.1." "" "0" - ;; -esac +get_lan_device_instances() { + local nl="$1" + [ "$action" != "get_name" -o "$nl" = "1" ] && return + local device + local num + for device in $wireless_devices; do + num=`$UCI_GET wireless.$device.instance` + easycwmp_output "InternetGatewayDevice.LANDevice.$num." "" "1" + done } get_lan_device_wlan_configuration_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.LANDevice.1.WLANConfiguration." "" "1" - ;; -esac + local nl="$1" + [ "$action" != "get_name" -o "$nl" = "1" ] && return + local device + for device in $wireless_devices; do + local device_num=`$UCI_GET wireless.$device.instance` + easycwmp_output "InternetGatewayDevice.LANDevice.$device_num.WLANConfiguration." "" "1" + done } get_lan_device_wlan_configuration_instance() { -param="$1" -nl="$2" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "$param" "" "1" - ;; -esac + param="$1" + nl="$2" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "$param" "" "1" + ;; + esac } get_lan_device() { -case "$1" in - InternetGatewayDevice.) - get_lan_device_object 0 - get_lan_device_instance "$2" - get_lan_device_wlan_configuration_object "$2" - get_wlan_configuration_instances "$2" - get_wlan_enable_all "$2" - get_wlan_ssid_all "$2" - return 0 - ;; - InternetGatewayDevice.LANDevice.) - get_lan_device_object "$2" - get_lan_device_instance 0 - get_lan_device_wlan_configuration_object "$2" - get_wlan_configuration_instances "$2" - get_wlan_enable_all "$2" - get_wlan_ssid_all "$2" - return 0 - ;; - InternetGatewayDevice.LANDevice.1.) - get_lan_device_instance "$2" - get_lan_device_wlan_configuration_object 0 - get_wlan_configuration_instances "$2" - get_wlan_enable_all "$2" - get_wlan_ssid_all "$2" - return 0 - ;; - InternetGatewayDevice.LANDevice.1.WLANConfiguration.) - get_lan_device_wlan_configuration_object "$2" - get_wlan_configuration_instances 0 - get_wlan_enable_all "$2" - get_wlan_ssid_all "$2" - return 0 - ;; - InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.Enable) - get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}.Enable" num uci_iface - [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME - get_wlan_enable "$num" "$uci_iface" "$2" - return $? - ;; - InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.SSID) - get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}.SSID" num uci_iface - [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME - get_wlan_ssid "$num" "$uci_iface" "$2" - return $? - ;; - InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.) - get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}." num uci_iface - [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME - get_lan_device_wlan_configuration_instance "$1" "$2" - get_wlan_enable "$num" "$uci_iface" 0 - get_wlan_ssid "$num" "$uci_iface" 0 - return 0 - ;; -esac -return $E_INVALID_PARAMETER_NAME + case "$1" in + InternetGatewayDevice.) + get_lan_device_object 0 + get_lan_device_channel_all "$2" + get_lan_device_instances "$2" + get_lan_device_wlan_configuration_object "$2" + get_wlan_configuration_instances "$2" + get_wlan_enable_all "$2" + get_wlan_maxassoc_all "$2" + get_wlan_ssid_all "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.) + get_lan_device_object "$2" + get_lan_device_channel_all "$2" + get_lan_device_instances "$2" + get_lan_device_wlan_configuration_object "$2" + get_wlan_configuration_instances "$2" + get_wlan_enable_all "$2" + get_wlan_maxassoc_all "$2" + get_wlan_ssid_all "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.Enable) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.Enable" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.Enable" "$device_num" "$uci_device" iface_num uci_iface + [ "$uci_iface" = "" -o "$iface_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_enable "$device_num" "$uci_device" "$iface_num" "$uci_iface" "$2" + return $? + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.MaxAssoc) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.MaxAssoc" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.MaxAssoc" "$device_num" "$uci_device" iface_num uci_iface + [ "$uci_iface" = "" -o "$iface_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_maxassoc "$device_num" "$uci_device" "$iface_num" "$uci_iface" "$2" + return $? + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.SSID) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.SSID" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.SSID" "$device_num" "$uci_device" iface_num uci_iface + [ "$uci_iface" = "" -o "$iface_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_ssid "$device_num" "$uci_device" "$iface_num" "$uci_iface" "$2" + return $? + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}." device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}." "$device_num" "$uci_device" iface_num uci_iface + [ "$uci_iface" = "" -o "$iface_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_lan_device_wlan_configuration_instance "$1" "$2" + get_wlan_enable "$device_num" "$uci_device" "$iface_num" "$uci_iface" 0 + get_wlan_maxassoc "$device_num" "$uci_device" "$iface_num" "$uci_iface" 0 + get_wlan_ssid "$device_num" "$uci_device" "$iface_num" "$uci_iface" 0 + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.) + get_lan_device_wlan_configuration_object "$2" "$3" + get_wlan_configuration_instances 0 + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration." device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_enable_by_device "$device_num" "$uci_device" "$2" + get_wlan_maxassoc_by_device "$device_num" "$uci_device" "$2" + get_wlan_ssid_by_device "$device_num" "$uci_device" "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.Channel) + get_lan_device_wlan_configuration_object "$2" "$3" + get_wlan_configuration_instances 0 + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.Channel" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_lan_device_channel "$device_num" "$uci_device" "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.) + get_lan_device_instances "$2" "$3" + get_lan_device_wlan_configuration_object 0 + get_wlan_configuration_instances "$2" + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}." device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_enable_by_device "$device_num" "$uci_device" "$2" + get_wlan_maxassoc_by_device "$device_num" "$uci_device" "$2" + get_wlan_ssid_by_device "$device_num" "$uci_device" "$2" + get_lan_device_channel "$device_num" "$uci_device" "$2" + return 0 + ;; + esac + return $E_INVALID_PARAMETER_NAME } set_lan_device() { -local num uci_iface -case "$1" in - InternetGatewayDevice.LANDevice.|\ - InternetGatewayDevice.LANDevice.1.|\ - InternetGatewayDevice.LANDevice.1.WLANConfiguration.|\ - InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.) - [ "$action" = "set_value" ] && return $E_INVALID_PARAMETER_NAME - easycwmp_set_parameter_notification "$1" "$2" - return 0 - ;; - InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.Enable) - get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}.Enable" num uci_iface - [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME - set_wlan_enable "$num" "$uci_iface" "$2" - return 0 - ;; - InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.SSID) - get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}.SSID" num uci_iface - [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME - set_wlan_ssid "$num" "$uci_iface" "$2" - return 0 - ;; - InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.) - [ "$action" = "set_value" ] && return $E_INVALID_PARAMETER_NAME - get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}." num uci_iface - [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME - easycwmp_set_parameter_notification "$1" "$2" - return 0 - ;; -esac -return $E_INVALID_PARAMETER_NAME + local num uci_iface + case "$1" in + InternetGatewayDevice.LANDevice.|\ + InternetGatewayDevice.LANDevice.[0-9]*.|\ + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.|\ + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.1.) + [ "$action" = "set_value" ] && return $E_INVALID_PARAMETER_NAME + easycwmp_set_parameter_notification "$1" "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.Enable) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.Enable" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.Enable" "$device_num" "$uci_device" iface_num uci_iface + [ "$uci_iface" = "" -o "$iface_num" = "" ] && return $E_INVALID_PARAMETER_NAME + set_wlan_enable "$device_num" "$uci_device" "$iface_num" "$uci_iface" "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.MaxAssoc) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.MaxAssoc" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.MaxAssoc" "$device_num" "$uci_device" iface_num uci_iface + [ "$uci_iface" = "" -o "$iface_num" = "" ] && return $E_INVALID_PARAMETER_NAME + set_wlan_maxassoc "$device_num" "$uci_device" "$iface_num" "$uci_iface" "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.SSID) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.SSID" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.{i}.WLANConfiguration.{i}.SSID" "$device_num" "$uci_device" iface_num uci_iface + [ "$uci_iface" = "" -o "$iface_num" = "" ] && return $E_INVALID_PARAMETER_NAME + set_wlan_ssid "$device_num" "$uci_device" "$iface_num" "$uci_iface" "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.WLANConfiguration.[0-9]*.) + [ "$action" = "set_value" ] && return $E_INVALID_PARAMETER_NAME + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}." num uci_iface + [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME + easycwmp_set_parameter_notification "$1" "$2" + return 0 + ;; + InternetGatewayDevice.LANDevice.[0-9]*.Channel) + get_wlan_device_num_and_uci_device "$1" "InternetGatewayDevice.LANDevice.{i}.Channel" device_num uci_device + [ "$uci_device" = "" -o "$device_num" = "" ] && return $E_INVALID_PARAMETER_NAME + set_lan_device_channel "$device_num" "$uci_device" "$2" + return 0 + ;; + esac + return $E_INVALID_PARAMETER_NAME } build_instances_lan_device() { - local iface - local ifaces=`$UCI_SHOW wireless | grep "wireless\.@wifi-iface\[[0-9]\+\]=wifi-iface" | cut -d'.' -f2 | cut -d'=' -f1` - local instance=`get_max_instance` - for iface in $ifaces; do - if [ "`$UCI_GET wireless.$iface.instance`" = "" ]; then - $UCI_SET wireless.$iface.instance=$((++instance)) - $UCI_COMMIT - fi - done + build_instances_wifi_device + build_instances_wifi_iface +} + +#some routers' config "config wifi-device" don't have "option instance" +build_instances_wifi_device() { + local device + local is_need_reset=0 + + for device in $wireless_devices; do + if [ "`$UCI_GET wireless.$device.instance`" = "" ]; then + is_need_reset=1 + break + fi + done + + if [ $is_need_reset -eq 1 ];then + local num=1 + for device in $wireless_devices; do + $UCI_SET wireless.$device.instance=$((num++)) + done + $UCI_COMMIT + fi + return 0 } +#some routers' config "config wifi-iface" don't have "option instance" +build_instances_wifi_iface() { + local iface + local is_need_reset=0 + + for iface in $wireless_ifaces; do + if [ "`$UCI_GET wireless.$iface.instance`" = "" ]; then + is_need_reset=1 + break + fi + done + + if [ $is_need_reset -eq 1 ]; then + local device + for device in $wireless_devices; do + local device_num=`$UCI_GET wireless.$device.instance` + local num_$device_num=1 + done + for iface in $wireless_ifaces; do + local iface_device=`$UCI_GET wireless.$iface.device` + local device_num=`$UCI_GET wireless.$iface_device.instance` + $UCI_SET wireless.$iface.instance=$(((num_$device_num)++)) + done + fi + return 0 +} add_object_lan_device() { -case "$1" in - InternetGatewayDevice.LANDevice.1.WLANConfiguration.) - local instance=`add_wlan_iface` - easycwmp_set_parameter_notification "$1$instance." "0" - easycwmp_status_output "" "" "1" "$instance" - return 0 - ;; -esac -return $E_INVALID_PARAMETER_NAME + case "$1" in + InternetGatewayDevice.LANDevice.1.WLANConfiguration.) + local instance=`add_wlan_iface` + easycwmp_set_parameter_notification "$1$instance." "0" + easycwmp_status_output "" "" "1" "$instance" + return 0 + ;; + esac + return $E_INVALID_PARAMETER_NAME } delete_object_lan_device() { -local num uci_iface -case "$1" in - InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.) - get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}." num uci_iface - [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME - delete_wlan_iface $uci_iface - easycwmp_remove_parameter_notification "$1" - easycwmp_status_output "" "" "1" - return 0 - ;; -esac -return $E_INVALID_PARAMETER_NAME -} \ No newline at end of file + local num uci_iface + case "$1" in + InternetGatewayDevice.LANDevice.1.WLANConfiguration.[0-9]*.) + get_wlan_num_and_uci_iface "$1" "InternetGatewayDevice.LANDevice.1.WLANConfiguration.{i}." num uci_iface + [ "$uci_iface" = "" -o "$num" = "" ] && return $E_INVALID_PARAMETER_NAME + delete_wlan_iface $uci_iface + easycwmp_remove_parameter_notification "$1" + easycwmp_status_output "" "" "1" + 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 8c1c73f..dd776fc 100644 --- a/ext/openwrt/scripts/functions/management_server +++ b/ext/openwrt/scripts/functions/management_server @@ -1,740 +1,740 @@ #!/bin/sh # Copyright (C) 2012-2014 PIVA Software -# Author: MOHAMED Kallel -# Author: AHMED Zribi +# Author: MOHAMED Kallel +# Author: AHMED Zribi # Copyright (C) 2011-2012 Luka Perkov get_management_server_url() { -local nl="$1" -local val="" -local permissions="1" -local tmp_value=${FLAGS_value} -FLAGS_value=${FLAGS_TRUE} -local scheme=`$UCI_GET easycwmp.@acs[0].scheme 2> /dev/null` -local hostname=`$UCI_GET easycwmp.@acs[0].hostname 2> /dev/null` -local port=`$UCI_GET easycwmp.@acs[0].port 2> /dev/null` -local path=`$UCI_GET easycwmp.@acs[0].path 2> /dev/null` -FLAGS_value=$tmp_value -FLAGS_ubus=$tmp_ubus -local parm="InternetGatewayDevice.ManagementServer.URL" -case "$action" in - get_value) - val="$scheme://$hostname:$port$path" - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local permissions="1" + local tmp_value=${FLAGS_value} + FLAGS_value=${FLAGS_TRUE} + local scheme=`$UCI_GET easycwmp.@acs[0].scheme 2> /dev/null` + local hostname=`$UCI_GET easycwmp.@acs[0].hostname 2> /dev/null` + local port=`$UCI_GET easycwmp.@acs[0].port 2> /dev/null` + local path=`$UCI_GET easycwmp.@acs[0].path 2> /dev/null` + FLAGS_value=$tmp_value + FLAGS_ubus=$tmp_ubus + local param="InternetGatewayDevice.ManagementServer.URL" + case "$action" in + get_value) + val="$scheme://$hostname:$port$path" + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_url() { -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_easycwmp_org__acs_scheme $scheme -set_management_server_x_easycwmp_org__acs_hostname $hostname -set_management_server_x_easycwmp_org__acs_port $port -set_management_server_x_easycwmp_org__acs_path $path -easycwmp_config_load - ;; - set_notification) - local val=$1 - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local param="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_easycwmp_org__acs_scheme $scheme + set_management_server_x_easycwmp_org__acs_hostname $hostname + set_management_server_x_easycwmp_org__acs_port $port + set_management_server_x_easycwmp_org__acs_path $path + easycwmp_config_load + ;; + set_notification) + local val=$1 + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_username() { -local nl="$1" -local val="" -local permissions="1" -local parm="InternetGatewayDevice.ManagementServer.Username" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].username 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local permissions="1" + local param="InternetGatewayDevice.ManagementServer.Username" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].username 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_username() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.Username" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].username="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.Username" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].username="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_password() { -local nl="$1" -local val="" -local permissions="1" -local parm="InternetGatewayDevice.ManagementServer.Password" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].password 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local permissions="1" + local param="InternetGatewayDevice.ManagementServer.Password" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].password 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_password() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.Password" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].password="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.Password" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].password="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_periodic_inform_enable() { -local nl="$1" -local val="" -local type="xsd:boolean" -local parm="InternetGatewayDevice.ManagementServer.PeriodicInformEnable" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].periodic_enable` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" "$type" -return 0 + local nl="$1" + local val="" + local type="xsd:boolean" + local param="InternetGatewayDevice.ManagementServer.PeriodicInformEnable" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].periodic_enable` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 } set_management_server_periodic_inform_enable() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.PeriodicInformEnable" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].periodic_enable="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.PeriodicInformEnable" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].periodic_enable="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_periodic_inform_interval() { -local nl="$1" -local val="" -local type="xsd:unsignedInt" -local parm="InternetGatewayDevice.ManagementServer.PeriodicInformInterval" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].periodic_interval` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" "$type" -return 0 + local nl="$1" + local val="" + local type="xsd:unsignedInt" + local param="InternetGatewayDevice.ManagementServer.PeriodicInformInterval" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].periodic_interval` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 } set_management_server_periodic_inform_interval() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.PeriodicInformInterval" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].periodic_interval="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.PeriodicInformInterval" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].periodic_interval="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_periodic_time() { -local nl="$1" -local val="" -local type="xs:date" -local parm="InternetGatewayDevice.ManagementServer.PeriodicInformTime" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].periodic_time` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" "$type" -return 0 + local nl="$1" + local val="" + local type="xs:date" + local param="InternetGatewayDevice.ManagementServer.PeriodicInformTime" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].periodic_time` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 } set_management_server_periodic_time() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.PeriodicInformTime" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].periodic_time="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.PeriodicInformTime" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].periodic_time="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_connection_request_url() { -local nl="$1" -local val -local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestURL" -local permissions="0" -case "$action" in - get_value) -if [ -z "$default_management_server_connection_request_url" ]; then - local intf=`$UCI_GET easycwmp.@local[0].interface 2> /dev/null` - local ip=`ifconfig "$intf" | grep inet | sed 's/^ *//g' | cut -f 2 -d ' '|cut -f 2 -d ':'` - local port=`$UCI_GET easycwmp.@local[0].port 2> /dev/null` - - if [ -n "$ip" -a -n "$port" ]; then - val="http://$ip:$port/" - fi -else - val=$default_management_server_connection_request_url -fi - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val + local param="InternetGatewayDevice.ManagementServer.ConnectionRequestURL" + local permissions="0" + case "$action" in + get_value) + if [ -z "$default_management_server_connection_request_url" ]; then + local intf=`$UCI_GET easycwmp.@local[0].interface 2> /dev/null` + local ip=`ifconfig "$intf" | grep inet | sed 's/^ *//g' | cut -f 2 -d ' '|cut -f 2 -d ':'` + local port=`$UCI_GET easycwmp.@local[0].port 2> /dev/null` + + if [ -n "$ip" -a -n "$port" ]; then + val="http://$ip:$port/" + fi + else + val=$default_management_server_connection_request_url + fi + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_connection_request_url() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestURL" -case "$action" in - set_value) - return $E_NON_WRITABLE_PARAMETER - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac -return 0 + local val=$1 + local param="InternetGatewayDevice.ManagementServer.ConnectionRequestURL" + case "$action" in + set_value) + return $E_NON_WRITABLE_PARAMETER + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac + return 0 } get_management_server_connection_request_username() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@local[0].username 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@local[0].username 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_connection_request_username() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" -case "$action" in - set_value) - $UCI_SET easycwmp.@local[0].username="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" + case "$action" in + set_value) + $UCI_SET easycwmp.@local[0].username="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_connection_request_password() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@local[0].password 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@local[0].password 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_connection_request_password() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" -case "$action" in - set_value) - $UCI_SET easycwmp.@local[0].password="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" + case "$action" in + set_value) + $UCI_SET easycwmp.@local[0].password="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } # TODO: InternetGatewayDevice.ManagementServer.PeriodicInformTime get_management_server_x_easycwmp_org__acs_scheme() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Scheme" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].scheme 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Scheme" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].scheme 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_x_easycwmp_org__acs_scheme() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Scheme" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].scheme="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Scheme" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].scheme="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_x_easycwmp_org__acs_hostname() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].hostname 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].hostname 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_x_easycwmp_org__acs_hostname() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname" -case "$action" in - set_value) -if [ -z "$default_management_server_acs_hostname" ]; then - $UCI_SET easycwmp.@acs[0].hostname="$val" -else - $UCI_SET easycwmp.@acs[0].hostname="$default_management_server_acs_hostname" -fi -easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname" + case "$action" in + set_value) + if [ -z "$default_management_server_acs_hostname" ]; then + $UCI_SET easycwmp.@acs[0].hostname="$val" + else + $UCI_SET easycwmp.@acs[0].hostname="$default_management_server_acs_hostname" + fi + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_x_easycwmp_org__acs_port() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].port 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].port 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_x_easycwmp_org__acs_port() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].port="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].port="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_x_easycwmp_org__acs_path() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].path 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].path 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_x_easycwmp_org__acs_path() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path" -case "$action" in - set_value) - $UCI_SET easycwmp.@acs[0].path="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path" + case "$action" in + set_value) + $UCI_SET easycwmp.@acs[0].path="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_x_easycwmp_org__connection_request_port() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@local[0].port 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@local[0].port 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_management_server_x_easycwmp_org__connection_request_port() { -local val=$1 -local parm="InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port" -case "$action" in - set_value) - $UCI_SET easycwmp.@local[0].port="$val" - easycwmp_config_load - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port" + case "$action" in + set_value) + $UCI_SET easycwmp.@local[0].port="$val" + easycwmp_config_load + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_management_server_parameterkey() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.ManagementServer.ParameterKey" -local permissions="0" -case "$action" in - get_value) - val=`$UCI_GET easycwmp.@acs[0].parameter_key 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.ManagementServer.ParameterKey" + local permissions="0" + case "$action" in + get_value) + val=`$UCI_GET easycwmp.@acs[0].parameter_key 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_management_server_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.ManagementServer." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.ManagementServer." "" "0" + ;; + esac } get_management_server() { -case "$1" in - InternetGatewayDevice.) - get_management_server_object 0 - get_management_server_url "$2" - get_management_server_username "$2" - get_management_server_password "$2" - get_management_server_periodic_inform_enable "$2" - get_management_server_periodic_inform_interval "$2" - get_management_server_periodic_time "$2" - get_management_server_connection_request_url "$2" - get_management_server_connection_request_username "$2" - get_management_server_connection_request_password "$2" - get_management_server_x_easycwmp_org__acs_scheme "$2" - get_management_server_x_easycwmp_org__acs_hostname "$2" - get_management_server_x_easycwmp_org__acs_port "$2" - get_management_server_x_easycwmp_org__acs_path "$2" - get_management_server_x_easycwmp_org__connection_request_port "$2" - get_management_server_parameterkey "$2" - return 0 - ;; - InternetGatewayDevice.ManagementServer.) - get_management_server_object "$2" - get_management_server_url 0 - get_management_server_username 0 - get_management_server_password 0 - get_management_server_periodic_inform_enable 0 - get_management_server_periodic_inform_interval 0 - get_management_server_periodic_time 0 - get_management_server_connection_request_url 0 - get_management_server_connection_request_username 0 - get_management_server_connection_request_password 0 - get_management_server_x_easycwmp_org__acs_scheme 0 - get_management_server_x_easycwmp_org__acs_hostname 0 - get_management_server_x_easycwmp_org__acs_port 0 - get_management_server_x_easycwmp_org__acs_path 0 - get_management_server_x_easycwmp_org__connection_request_port 0 - get_management_server_parameterkey 0 - return 0 - ;; - InternetGatewayDevice.ManagementServer.URL) - get_management_server_url "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.Username) - get_management_server_username "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.Password) - get_management_server_password "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.PeriodicInformEnable) - get_management_server_periodic_inform_enable "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.PeriodicInformInterval) - get_management_server_periodic_inform_interval "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.PeriodicInformTime) - get_management_server_periodic_time "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.ConnectionRequestURL) - get_management_server_connection_request_url "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.ConnectionRequestUsername) - get_management_server_connection_request_username "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.ConnectionRequestPassword) - get_management_server_connection_request_password "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Scheme) - get_management_server_x_easycwmp_org__acs_scheme "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname) - get_management_server_x_easycwmp_org__acs_hostname "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port) - get_management_server_x_easycwmp_org__acs_port "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path) - get_management_server_x_easycwmp_org__acs_path "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port) - get_management_server_x_easycwmp_org__connection_request_port "$2" - return $? - ;; - InternetGatewayDevice.ManagementServer.ParameterKey) - get_management_server_parameterkey "$2" - return $? - ;; -esac -return $E_INVALID_PARAMETER_NAME + case "$1" in + InternetGatewayDevice.) + get_management_server_object 0 + get_management_server_url "$2" + get_management_server_username "$2" + get_management_server_password "$2" + get_management_server_periodic_inform_enable "$2" + get_management_server_periodic_inform_interval "$2" + get_management_server_periodic_time "$2" + get_management_server_connection_request_url "$2" + get_management_server_connection_request_username "$2" + get_management_server_connection_request_password "$2" + get_management_server_x_easycwmp_org__acs_scheme "$2" + get_management_server_x_easycwmp_org__acs_hostname "$2" + get_management_server_x_easycwmp_org__acs_port "$2" + get_management_server_x_easycwmp_org__acs_path "$2" + get_management_server_x_easycwmp_org__connection_request_port "$2" + get_management_server_parameterkey "$2" + return 0 + ;; + InternetGatewayDevice.ManagementServer.) + get_management_server_object "$2" + get_management_server_url 0 + get_management_server_username 0 + get_management_server_password 0 + get_management_server_periodic_inform_enable 0 + get_management_server_periodic_inform_interval 0 + get_management_server_periodic_time 0 + get_management_server_connection_request_url 0 + get_management_server_connection_request_username 0 + get_management_server_connection_request_password 0 + get_management_server_x_easycwmp_org__acs_scheme 0 + get_management_server_x_easycwmp_org__acs_hostname 0 + get_management_server_x_easycwmp_org__acs_port 0 + get_management_server_x_easycwmp_org__acs_path 0 + get_management_server_x_easycwmp_org__connection_request_port 0 + get_management_server_parameterkey 0 + return 0 + ;; + InternetGatewayDevice.ManagementServer.URL) + get_management_server_url "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.Username) + get_management_server_username "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.Password) + get_management_server_password "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.PeriodicInformEnable) + get_management_server_periodic_inform_enable "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.PeriodicInformInterval) + get_management_server_periodic_inform_interval "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.PeriodicInformTime) + get_management_server_periodic_time "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.ConnectionRequestURL) + get_management_server_connection_request_url "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.ConnectionRequestUsername) + get_management_server_connection_request_username "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.ConnectionRequestPassword) + get_management_server_connection_request_password "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Scheme) + get_management_server_x_easycwmp_org__acs_scheme "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname) + get_management_server_x_easycwmp_org__acs_hostname "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port) + get_management_server_x_easycwmp_org__acs_port "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path) + get_management_server_x_easycwmp_org__acs_path "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port) + get_management_server_x_easycwmp_org__connection_request_port "$2" + return $? + ;; + InternetGatewayDevice.ManagementServer.ParameterKey) + get_management_server_parameterkey "$2" + return $? + ;; + esac + return $E_INVALID_PARAMETER_NAME } set_management_server() { -case "$1" in - InternetGatewayDevice.|\ - InternetGatewayDevice.ManagementServer.) - [ "$action" = "set_notification" ] && return $E_NOTIFICATION_REJECTED - ;; - 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.PeriodicInformTime) - set_management_server_periodic_time "$2" - return 0 - ;; - InternetGatewayDevice.ManagementServer.ConnectionRequestURL) - set_management_server_connection_request_url "$2" - return $? - ;; - 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_easycwmp_org__ACS_Scheme) - set_management_server_x_easycwmp_org__acs_scheme "$2" - return 0 - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname) - set_management_server_x_easycwmp_org__acs_hostname "$2" - return 0 - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port) - set_management_server_x_easycwmp_org__acs_port "$2" - return 0 - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path) - set_management_server_x_easycwmp_org__acs_path "$2" - return 0 - ;; - InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port) - set_management_server_x_easycwmp_org__connection_request_port "$2" - return 0 - ;; - InternetGatewayDevice.ManagementServer.ParameterKey) - [ "$action" = "set_notification" ] && return $E_NOTIFICATION_REJECTED || return $E_NON_WRITABLE_PARAMETER - ;; -esac -return $E_INVALID_PARAMETER_NAME + case "$1" in + InternetGatewayDevice.|\ + InternetGatewayDevice.ManagementServer.) + [ "$action" = "set_notification" ] && return $E_NOTIFICATION_REJECTED + ;; + 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.PeriodicInformTime) + set_management_server_periodic_time "$2" + return 0 + ;; + InternetGatewayDevice.ManagementServer.ConnectionRequestURL) + set_management_server_connection_request_url "$2" + return $? + ;; + 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_easycwmp_org__ACS_Scheme) + set_management_server_x_easycwmp_org__acs_scheme "$2" + return 0 + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Hostname) + set_management_server_x_easycwmp_org__acs_hostname "$2" + return 0 + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Port) + set_management_server_x_easycwmp_org__acs_port "$2" + return 0 + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__ACS_Path) + set_management_server_x_easycwmp_org__acs_path "$2" + return 0 + ;; + InternetGatewayDevice.ManagementServer.X_easycwmp_org__Connection_Request_Port) + set_management_server_x_easycwmp_org__connection_request_port "$2" + return 0 + ;; + InternetGatewayDevice.ManagementServer.ParameterKey) + [ "$action" = "set_notification" ] && return $E_NOTIFICATION_REJECTED || return $E_NON_WRITABLE_PARAMETER + ;; + esac + return $E_INVALID_PARAMETER_NAME } build_instances_management_server() { return 0; } add_object_management_server() { return $E_INVALID_PARAMETER_NAME; } -delete_object_management_server() { return $E_INVALID_PARAMETER_NAME; } \ No newline at end of file +delete_object_management_server() { return $E_INVALID_PARAMETER_NAME; } diff --git a/ext/openwrt/scripts/functions/user b/ext/openwrt/scripts/functions/user new file mode 100644 index 0000000..12b4907 --- /dev/null +++ b/ext/openwrt/scripts/functions/user @@ -0,0 +1,155 @@ +#!/bin/sh +# EasyCwmp is a GPLv2 open source implementation of the TR069 cwmp standard. +# Author: sinkcup + +get_user_encrypted_password() { + local param="InternetGatewayDevice.User.1.EncryptedPassword" + local nl="$2" + local type="xsd:string" + local val="" + local permissions="1" + case "$action" in + get_value) + val=`grep '^root:' /etc/shadow | awk -F: '{print $2}'` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 +} + +get_user_last_changed() { + local param="InternetGatewayDevice.User.1.LastChanged" + local nl="$2" + local type="xsd:unsignedInt" + local val="" + local permissions="0" + case "$action" in + get_value) + val=`grep '^root:' /etc/shadow | awk -F: '{print $3}'` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 +} + +get_user_username() { + local param="InternetGatewayDevice.User.1.Username" + local nl="$2" + local type="xsd:string" + local val="" + local permissions="0" + case "$action" in + get_value) + val=`grep '^root:' /etc/shadow | awk -F: '{print $1}'` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 +} + +set_user_encrypted_password() { + local param="InternetGatewayDevice.User.1.EncryptedPassword" + local val="$2" + case $action in + set_value) + #sh is diff vs shell, can't use ${string/substring/replacement} + local v1=`grep '^root:' /etc/shadow | awk -F: '{print $1}'` + local n3=$(($(date +%s) / 60 / 60 / 24)) + local v4=`grep '^root:' /etc/shadow | awk -F: '{print $4}'` + local v5=`grep '^root:' /etc/shadow | awk -F: '{print $5}'` + local v6=`grep '^root:' /etc/shadow | awk -F: '{print $6}'` + local new_line=$v1:$val:$n3:$v4:$v5:$v6::: + local content=`sed '/^root:.*$/d' /etc/shadow` + echo -e "$new_line\n""$content" > /etc/shadow + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac +} + +get_user_object() { + local nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.User." "" "0" + ;; + esac +} + +get_user_instances() { + local nl="$1" + [ "$action" != "get_name" -o "$nl" = "1" ] && return + easycwmp_output "InternetGatewayDevice.User.1." "" "1" +} + +get_user() { + case "$1" in + InternetGatewayDevice.|\ + InternetGatewayDevice.User.) + get_user_object 0 + get_user_instances "$2" + get_user_encrypted_password "$2" + get_user_last_changed "$2" + get_user_username "$2" + return 0 + ;; + InternetGatewayDevice.User.[0-9]*.EncryptedPassword) + get_user_encrypted_password "$2" + return $? + ;; + InternetGatewayDevice.User.[0-9]*.LastChanged) + get_user_last_changed "$2" + return $? + ;; + InternetGatewayDevice.User.[0-9]*.Username) + get_user_username "$2" + return $? + ;; + InternetGatewayDevice.User.[0-9]*.) + get_user_encrypted_password "$2" + get_user_last_changed "$2" + get_user_username "$2" + return 0 + ;; + esac + return $E_INVALID_PARAMETER_NAME +} + +set_user() { + case "$1" in + InternetGatewayDevice.User.|\ + InternetGatewayDevice.User.[0-9]*.) + [ "$action" = "set_value" ] && return $E_INVALID_PARAMETER_NAME + easycwmp_set_parameter_notification "$1" "$2" + return 0 + ;; + InternetGatewayDevice.User.[0-9]*.EncryptedPassword) + set_user_encrypted_password "$2" + return 0 + ;; + esac + return $E_INVALID_PARAMETER_NAME +} + +build_instances_user() { + return 0 +} diff --git a/ext/openwrt/scripts/functions/wan_device b/ext/openwrt/scripts/functions/wan_device index 504c83c..9e33003 100644 --- a/ext/openwrt/scripts/functions/wan_device +++ b/ext/openwrt/scripts/functions/wan_device @@ -1,446 +1,443 @@ #!/bin/sh # Copyright (C) 2012-2014 PIVA Software -# Author: MOHAMED Kallel -# Author: AHMED Zribi +# Author: MOHAMED Kallel +# Author: AHMED Zribi # Copyright (C) 2011-2012 Luka Perkov get_wan_device_mng_status() { -# TODO: Unconfigured ; Connecting ; Connected ; PendingDisconnect ; Disconneting ; Disconnected -local nl="$1" -local val="" -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus" -local permissions="0" -case "$action" in - get_value) - val="Connected" - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + # TODO: Unconfigured ; Connecting ; Connected ; PendingDisconnect ; Disconneting ; Disconnected + local nl="$1" + local val="" + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus" + local permissions="0" + case "$action" in + get_value) + val="Connected" + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_wan_device_mng_interface_ip() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress" -local permissions="0" -case "$action" in - get_value) - if [ -z "$default_wan_device_mng_interface_ip" ]; then - network_get_ipaddr val mng - else - val=$default_wan_device_mng_interface_ip - fi - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress" + local permissions="0" + case "$action" in + get_value) + #see http://wiki.openwrt.org/doc/uci + network_get_ipaddr val wan + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_wan_device_mng_interface_mac() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress" -local permissions="0" -case "$action" in - get_value) - if [ -z "$default_wan_device_mng_interface_mac" ]; then - val=`$UCI_GET network.mng.macaddr` - else - val=$default_wan_device_mng_interface_mac - fi - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress" + local permissions="0" + case "$action" in + get_value) + #see http://wiki.openwrt.org/doc/uci + local if_lan=$(network_get_device ifname wan; echo $ifname) + local cmd="ifconfig "$if_lan" | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'" + local tmp=$(eval $cmd) + val=${tmp//:/} + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } get_wan_device_wan_ppp_enable() { -local nl="$1" -local val="" -local type="xsd:boolean" -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET network.wan.auto 2> /dev/null` - if [ -z $val ]; then - val="1" - fi - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" "$type" -return 0 + local nl="$1" + local val="" + local type="xsd:boolean" + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET network.wan.auto 2> /dev/null` + if [ -z $val ]; then + val="1" + fi + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" "$type" + return 0 } set_wan_device_wan_ppp_enable() { -local val=$1 -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable" -case $action in - set_value) - if [ "$val" -eq 0 ]; then - $UCI_SET network.wan.auto=0 - ifdown wan & - elif [ "$val" -eq 1 ]; then - $UCI_SET network.wan.auto=1 - ifup wan & - fi - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable" + case $action in + set_value) + if [ "$val" -eq 0 ]; then + $UCI_SET network.wan.auto=0 + ifdown wan & + elif [ "$val" -eq 1 ]; then + $UCI_SET network.wan.auto=1 + ifup wan & + fi + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_wan_device_wan_ppp_username() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET network.wan.username 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET network.wan.username 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_wan_device_wan_ppp_username() { -local val=$1 -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username" -case $action in - set_value) - $UCI_SET network.wan.username="$val" - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username" + case $action in + set_value) + $UCI_SET network.wan.username="$val" + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_wan_device_wan_ppp_password() { -local nl="$1" -local val="" -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password" -local permissions="1" -case "$action" in - get_value) - val=`$UCI_GET network.wan.password 2> /dev/null` - ;; - get_name) - [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS - ;; - get_notification) - easycwmp_get_parameter_notification "val" "$parm" - ;; -esac -easycwmp_output "$parm" "$val" "$permissions" -return 0 + local nl="$1" + local val="" + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password" + local permissions="1" + case "$action" in + get_value) + val=`$UCI_GET network.wan.password 2> /dev/null` + ;; + get_name) + [ "$nl" = "1" ] && return $E_INVALID_ARGUMENTS + ;; + get_notification) + easycwmp_get_parameter_notification "val" "$param" + ;; + esac + easycwmp_output "$param" "$val" "$permissions" + return 0 } set_wan_device_wan_ppp_password() { -local val=$1 -local parm="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password" -case $action in - set_value) - $UCI_SET network.wan.password="$1" - ;; - set_notification) - easycwmp_set_parameter_notification "$parm" "$val" - ;; -esac + local val=$1 + local param="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password" + case $action in + set_value) + $UCI_SET network.wan.password="$1" + ;; + set_notification) + easycwmp_set_parameter_notification "$param" "$val" + ;; + esac } get_wan_device_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice." "" "0" + ;; + esac } get_wan_device_instance() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1." "" "0" + ;; + esac } get_wan_device_wan_connection_device_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice." "" "0" + ;; + esac } get_wan_device_wan_connection_device_instance() { -nl="$1" -case "$action" in - get_name) - if [ "$nl" = "0" ]; then - [ "$2" != "2" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "" "0" - [ "$2" != "1" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2." "" "0" - fi - ;; -esac + nl="$1" + case "$action" in + get_name) + if [ "$nl" = "0" ]; then + [ "$2" != "2" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1." "" "0" + [ "$2" != "1" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2." "" "0" + fi + ;; + esac } get_wan_device_wan_connection_device_wan_ip_connection_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection." "" "0" + ;; + esac } get_wan_device_wan_connection_device_wan_ip_connection_instance() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1." "" "0" + ;; + esac } get_wan_device_wan_connection_device_wan_ppp_connection_object() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection." "" "0" + ;; + esac } get_wan_device_wan_connection_device_wan_ppp_connection_instance() { -nl="$1" -case "$action" in - get_name) - [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1." "" "0" - ;; -esac + nl="$1" + case "$action" in + get_name) + [ "$nl" = "0" ] && easycwmp_output "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1." "" "0" + ;; + esac } get_wan_device() { -case "$1" in - InternetGatewayDevice.) - get_wan_device_object 0 - get_wan_device_instance "$2" - get_wan_device_wan_connection_device_object "$2" - get_wan_device_wan_connection_device_instance "$2" - get_wan_device_wan_connection_device_wan_ip_connection_object "$2" - get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" - get_wan_device_mng_status "$2" - get_wan_device_mng_interface_ip "$2" - get_wan_device_mng_interface_mac "$2" - get_wan_device_wan_ppp_enable "$2" - get_wan_device_wan_ppp_username "$2" - get_wan_device_wan_ppp_password "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.) - get_wan_device_object "$2" - get_wan_device_instance 0 - get_wan_device_wan_connection_device_object "$2" - get_wan_device_wan_connection_device_instance "$2" - get_wan_device_wan_connection_device_wan_ip_connection_object "$2" - get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" - get_wan_device_mng_status "$2" - get_wan_device_mng_interface_ip "$2" - get_wan_device_mng_interface_mac "$2" - get_wan_device_wan_ppp_enable "$2" - get_wan_device_wan_ppp_username "$2" - get_wan_device_wan_ppp_password "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.) - get_wan_device_instance "$2" - get_wan_device_wan_connection_device_object 0 - get_wan_device_wan_connection_device_instance "$2" - get_wan_device_wan_connection_device_wan_ip_connection_object "$2" - get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" - get_wan_device_mng_status "$2" - get_wan_device_mng_interface_ip "$2" - get_wan_device_mng_interface_mac "$2" - get_wan_device_wan_ppp_enable "$2" - get_wan_device_wan_ppp_username "$2" - get_wan_device_wan_ppp_password "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.) - get_wan_device_wan_connection_device_object "$2" - get_wan_device_wan_connection_device_instance 0 - get_wan_device_wan_connection_device_wan_ip_connection_object "$2" - get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" - get_wan_device_mng_status "$2" - get_wan_device_mng_interface_ip "$2" - get_wan_device_mng_interface_mac "$2" - get_wan_device_wan_ppp_enable "$2" - get_wan_device_wan_ppp_username "$2" - get_wan_device_wan_ppp_password "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.) - get_wan_device_wan_connection_device_instance "$2" "1" - get_wan_device_wan_connection_device_wan_ip_connection_object 0 - get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" - get_wan_device_mng_status "$2" - get_wan_device_mng_interface_ip "$2" - get_wan_device_mng_interface_mac "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.) - get_wan_device_wan_connection_device_instance "$2" "2" - get_wan_device_wan_connection_device_wan_ppp_connection_object 0 - get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" - get_wan_device_wan_ppp_enable "$2" - get_wan_device_wan_ppp_username "$2" - get_wan_device_wan_ppp_password "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.) - get_wan_device_wan_connection_device_wan_ip_connection_object "$2" - get_wan_device_wan_connection_device_wan_ip_connection_instance 0 - get_wan_device_mng_status "$2" - get_wan_device_mng_interface_ip "$2" - get_wan_device_mng_interface_mac "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.) - get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" - get_wan_device_mng_status 0 - get_wan_device_mng_interface_ip 0 - get_wan_device_mng_interface_mac 0 - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.) - get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" - get_wan_device_wan_connection_device_wan_ppp_connection_instance 0 - get_wan_device_wan_ppp_enable "$2" - get_wan_device_wan_ppp_username "$2" - get_wan_device_wan_ppp_password "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.) - get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" - get_wan_device_wan_ppp_enable 0 - get_wan_device_wan_ppp_username 0 - get_wan_device_wan_ppp_password 0 - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus) - get_wan_device_mng_status "$2" - return $? - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress) - get_wan_device_mng_interface_ip "$2" - return $? - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress) - get_wan_device_mng_interface_mac "$2" - return $? - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable) - get_wan_device_wan_ppp_enable "$2" - return $? - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username) - get_wan_device_wan_ppp_username "$2" - return $? - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password) - get_wan_device_wan_ppp_password "$2" - return $? - ;; -esac -return $E_INVALID_PARAMETER_NAME + case "$1" in + InternetGatewayDevice.) + get_wan_device_object 0 + get_wan_device_instance "$2" + get_wan_device_wan_connection_device_object "$2" + get_wan_device_wan_connection_device_instance "$2" + get_wan_device_wan_connection_device_wan_ip_connection_object "$2" + get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" + get_wan_device_mng_status "$2" + get_wan_device_mng_interface_ip "$2" + get_wan_device_mng_interface_mac "$2" + get_wan_device_wan_ppp_enable "$2" + get_wan_device_wan_ppp_username "$2" + get_wan_device_wan_ppp_password "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.) + get_wan_device_object "$2" + get_wan_device_instance 0 + get_wan_device_wan_connection_device_object "$2" + get_wan_device_wan_connection_device_instance "$2" + get_wan_device_wan_connection_device_wan_ip_connection_object "$2" + get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" + get_wan_device_mng_status "$2" + get_wan_device_mng_interface_ip "$2" + get_wan_device_mng_interface_mac "$2" + get_wan_device_wan_ppp_enable "$2" + get_wan_device_wan_ppp_username "$2" + get_wan_device_wan_ppp_password "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.) + get_wan_device_instance "$2" + get_wan_device_wan_connection_device_object 0 + get_wan_device_wan_connection_device_instance "$2" + get_wan_device_wan_connection_device_wan_ip_connection_object "$2" + get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" + get_wan_device_mng_status "$2" + get_wan_device_mng_interface_ip "$2" + get_wan_device_mng_interface_mac "$2" + get_wan_device_wan_ppp_enable "$2" + get_wan_device_wan_ppp_username "$2" + get_wan_device_wan_ppp_password "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.) + get_wan_device_wan_connection_device_object "$2" + get_wan_device_wan_connection_device_instance 0 + get_wan_device_wan_connection_device_wan_ip_connection_object "$2" + get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" + get_wan_device_mng_status "$2" + get_wan_device_mng_interface_ip "$2" + get_wan_device_mng_interface_mac "$2" + get_wan_device_wan_ppp_enable "$2" + get_wan_device_wan_ppp_username "$2" + get_wan_device_wan_ppp_password "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.) + get_wan_device_wan_connection_device_instance "$2" "1" + get_wan_device_wan_connection_device_wan_ip_connection_object 0 + get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" + get_wan_device_mng_status "$2" + get_wan_device_mng_interface_ip "$2" + get_wan_device_mng_interface_mac "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.) + get_wan_device_wan_connection_device_instance "$2" "2" + get_wan_device_wan_connection_device_wan_ppp_connection_object 0 + get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" + get_wan_device_wan_ppp_enable "$2" + get_wan_device_wan_ppp_username "$2" + get_wan_device_wan_ppp_password "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.) + get_wan_device_wan_connection_device_wan_ip_connection_object "$2" + get_wan_device_wan_connection_device_wan_ip_connection_instance 0 + get_wan_device_mng_status "$2" + get_wan_device_mng_interface_ip "$2" + get_wan_device_mng_interface_mac "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.) + get_wan_device_wan_connection_device_wan_ip_connection_instance "$2" + get_wan_device_mng_status 0 + get_wan_device_mng_interface_ip 0 + get_wan_device_mng_interface_mac 0 + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.) + get_wan_device_wan_connection_device_wan_ppp_connection_object "$2" + get_wan_device_wan_connection_device_wan_ppp_connection_instance 0 + get_wan_device_wan_ppp_enable "$2" + get_wan_device_wan_ppp_username "$2" + get_wan_device_wan_ppp_password "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.) + get_wan_device_wan_connection_device_wan_ppp_connection_instance "$2" + get_wan_device_wan_ppp_enable 0 + get_wan_device_wan_ppp_username 0 + get_wan_device_wan_ppp_password 0 + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus) + get_wan_device_mng_status "$2" + return $? + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress) + get_wan_device_mng_interface_ip "$2" + return $? + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress) + get_wan_device_mng_interface_mac "$2" + return $? + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Enable) + get_wan_device_wan_ppp_enable "$2" + return $? + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Username) + get_wan_device_wan_ppp_username "$2" + return $? + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.Password) + get_wan_device_wan_ppp_password "$2" + return $? + ;; + esac + return $E_INVALID_PARAMETER_NAME } set_wan_device() { -case "$1" in - InternetGatewayDevice.WANDevice.|\ - InternetGatewayDevice.WANDevice.1.|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.) - [ "$action" = "set_value" ] && return $E_INVALID_PARAMETER_NAME - easycwmp_set_parameter_notification "$1" "$2" - return 0 - ;; - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus|\ - InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress) - [ "$action" = "set_value" ] && return $E_NON_WRITABLE_PARAMETER - easycwmp_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 + case "$1" in + InternetGatewayDevice.WANDevice.|\ + InternetGatewayDevice.WANDevice.1.|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1.) + [ "$action" = "set_value" ] && return $E_INVALID_PARAMETER_NAME + easycwmp_set_parameter_notification "$1" "$2" + return 0 + ;; + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ConnectionStatus|\ + InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress) + [ "$action" = "set_value" ] && return $E_NON_WRITABLE_PARAMETER + easycwmp_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 } build_instances_wan_device() { return 0; } add_object_wan_device() { return $E_INVALID_PARAMETER_NAME; } -delete_object_wan_device() { return $E_INVALID_PARAMETER_NAME; } \ No newline at end of file +delete_object_wan_device() { return $E_INVALID_PARAMETER_NAME; }