Optimization Phase2 using cache first delivery

This commit is contained in:
Mohamed Kallel 2013-09-16 17:52:55 +01:00 committed by Strhuan Blomquist
parent d903a255c9
commit 40e86bb5ab
22 changed files with 1610 additions and 9703 deletions

View file

@ -310,6 +310,7 @@ void bkp_session_insert_transfer_complete(struct transfer_complete *ptransfer_co
bkp_session_insert(b,"command_key",ptransfer_complete->command_key);
bkp_session_insert(b,"start_time",ptransfer_complete->start_time);
bkp_session_insert(b,"complete_time",ptransfer_complete->complete_time);
bkp_session_insert(b,"old_software_version",ptransfer_complete->old_software_version);
bkp_session_insert(b,"fault_code",fault_code);
}
pthread_mutex_unlock (&mutex_backup_session);
@ -641,6 +642,17 @@ void load_transfer_complete(mxml_node_t *tree,struct cwmp *cwmp)
}
}
}
else if (strcmp(b->value.element.name,"old_software_version") == 0)
{
c = mxmlWalkNext(b, b, MXML_DESCEND);
if (c && c->type == MXML_TEXT)
{
if(c->value.text.string != NULL)
{
ptransfer_complete->old_software_version = strdup(c->value.text.string);
}
}
}
else if (strcmp(b->value.element.name,"fault_code") == 0)
{
c = mxmlWalkNext(b, b, MXML_DESCEND);
@ -656,6 +668,7 @@ void load_transfer_complete(mxml_node_t *tree,struct cwmp *cwmp)
b = mxmlWalkNext(b, tree, MXML_NO_DESCEND);
}
cwmp_root_cause_TransferComplete (cwmp, ptransfer_complete);
sotfware_version_value_change(cwmp, ptransfer_complete);
}
void bkp_session_create_file()

View file

@ -419,7 +419,7 @@ int get_global_config(struct config *conf)
}
error = uci_get_value(UCI_DHCP_DISCOVERY_PATH,&value);
error2 = uci_get_value(UCI_ACS_URL_PATH,&value2);
error2 = uci_get_state_value(UCI_ACS_URL_PATH,&value2);
error3 = uci_get_state_value(conf->dhcp_url_path,&value3);
if ((((error == CWMP_OK) && (value != NULL) && (strcmp(value,"enable") == 0)) ||

View file

@ -32,45 +32,18 @@ config scripts
list location /usr/share/freecwmp/functions/common
# freecwmp specific functions
list location /usr/share/freecwmp/functions/device_info
list function device_info
list function device_info_generic
list prefix InternetGatewayDevice.DeviceInfo.
list location /usr/share/freecwmp/functions/lan_device
list function lan_device
list prefix InternetGatewayDevice.LANDevice.
list location /usr/share/freecwmp/functions/management_server
list function management_server
list function management_server_generic
list prefix InternetGatewayDevice.ManagementServer.
list location /usr/share/freecwmp/functions/wan_device
list function wan_device
list location /usr/share/freecwmp/functions/misc
list function misc
list location /usr/share/freecwmp/functions/device_users
list function device_users
list location /usr/share/freecwmp/functions/device_hosts
list function device_hosts
list location /usr/share/freecwmp/functions/device_routing
list function device_routing
list prefix InternetGatewayDevice.WANDevice.
list location /usr/share/freecwmp/functions/voice_service
list function voice_service
config notifications
list active 'InternetGatewayDevice.ManagementServer.URL'
list active 'InternetGatewayDevice.ManagementServer.ParameterKey'
list prefix InternetGatewayDevice.Services.
list location /usr/share/freecwmp/functions/models
list prefix InternetGatewayDevice.
config cwmp
option parameter 'InternetGatewayDevice.DeviceInfo.SpecVersion'
option value '1.0'
config DeviceInfo
list function 'device_info'
config Services
list function 'voice_service'
config LANDevice
list function 'lan_device'
config ManagementServer
list function 'management_server'
config WANDevice
list function 'wan_device'

28
event.c
View file

@ -16,6 +16,7 @@
#include "backupSession.h"
#include "log.h"
#include "jshn.h"
#include "external.h"
const struct EVENT_CONST_STRUCT EVENT_CONST [] = {
[EVENT_IDX_0BOOTSTRAP] = {"0 BOOTSTRAP", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
@ -409,6 +410,31 @@ int cwmp_root_cause_event_periodic (struct cwmp *cwmp)
return CWMP_OK;
}
void sotfware_version_value_change(struct cwmp *cwmp, struct transfer_complete *p)
{
struct parameter_container *parameter_container;
char *current_software_version = NULL;
external_init();
external_get_action("value", DM_SOFTWARE_VERSION_PATH, NULL);
external_handle_action(cwmp_handle_getParamValues);
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if ((!parameter_container->fault_code || parameter_container->fault_code[0] != '9') &&
strcmp(parameter_container->name, DM_SOFTWARE_VERSION_PATH) == 0)
{
current_software_version = strdup(parameter_container->data);
}
external_free_list_parameter();
external_exit();
if (p->old_software_version && current_software_version &&
strcmp(p->old_software_version, current_software_version) != 0) {
pthread_mutex_lock (&(cwmp->mutex_session_queue));
cwmp_add_event_container (cwmp, EVENT_IDX_4VALUE_CHANGE, "");
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
}
}
void connection_request_ip_value_change(struct cwmp *cwmp)
{
char *bip = NULL;
@ -432,8 +458,6 @@ void connection_request_ip_value_change(struct cwmp *cwmp)
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
return;
}
parameter_container_add(&(event_container->head_parameter_container),
"InternetGatewayDevice.ManagementServer.ConnectionRequestURL", NULL, NULL, NULL);
cwmp_save_event_container (cwmp,event_container);
bkp_session_simple_insert("connection_request", "ip", cwmp->conf.ip);
bkp_session_save();

View file

@ -50,6 +50,8 @@
#define UCI_CPE_LOG_MAX_SIZE "cwmp.cpe.log_max_size"
#define UCI_CPE_ENABLE_STDOUT_LOG "cwmp.cpe.log_to_console"
#define UCI_CPE_ENABLE_FILE_LOG "cwmp.cpe.log_to_file"
#define DM_SOFTWARE_VERSION_PATH "InternetGatewayDevice.DeviceInfo.SoftwareVersion"
enum end_session {
END_SESSION_REBOOT = 1,

View file

@ -128,6 +128,7 @@ typedef struct transfer_complete {
char *command_key;
char *start_time;
char *complete_time;
char *old_software_version;
} transfer_complete;
#define MXML_DELETE(X) do {if (X) { mxmlDelete(X); X = NULL; } } while(0)

View file

@ -1,5 +1,8 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2012 Inteno
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
include /lib/network
. /usr/share/libubox/jshn.sh
@ -103,10 +106,13 @@ boot() {
touch /etc/cwmpd/.cwmpd_boot
}
start() {
run=$(ps | grep /usr/sbin/cwmpd | grep -v grep | grep -v rc.common)
if [ "$run" = "" ]
then
start_cwmpd() {
run=$(ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common)
if [ "$run" = "" ];then
stop_freecwmp_cache
echo "Building cache. This action may take time..."
/bin/sh /usr/sbin/freecwmp get cache ""
printf "\033[A"
if [ "$1" = "GetRPCMethods" ];then
run "GetRPCMethods"
else
@ -122,21 +128,102 @@ start() {
fi
}
get_process_childs() {
local pid_list="$1"
local proc="" line="" pt="" ppid="" pid="" pid_tmp="" pid_grep=""
pid_grep=${pid_list// /\\|}
while [ "_$pid_grep" != "_" ];do
proc=`cat /proc/[0-9]*/stat | grep "$pid_grep"`
proc=${proc// /;;;;;}
pid_tmp=""
for line in $proc; do
pid="${line%%;;;;;*}"
ppid="${line#*;;;;;*;;;;;*;;;;;}"; ppid="${ppid%%;;;;;*}"
pt=`echo "$pid" | grep "$pid_grep"`
if [ "_$pt" != "_" -a "$pt" = "$pid" ]; then
continue
fi
pt=`echo "$ppid" | grep "$pid_grep"`
if [ "$pt" != "$ppid" -o "_$pid" = "_" ]; then
continue
fi
pid_list="$pid_list $pid"
if [ "_$pid_tmp" = "_" ]; then
pid_tmp="$pid"
else
pid_tmp="$pid_tmp\|$pid"
fi
done
pid_grep="$pid_tmp"
done
echo "$pid_list"
}
pidof_cwmp() {
local pids=""
pids="`ps aux|grep /usr/sbin/cwmpd|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v \" Z \"|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
pids=${pids% }
pids=${pids# }
echo "$pids"
}
pidof_freecwmp() {
local pids=""
pids="`ps aux|grep /usr/sbin/freecwmp|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
pids=${pids% }
pids=${pids# }
echo "$pids"
}
stop_freecwmp_cache() {
local pid_list="" pid="" pids="" found="1" p name state ppid rest cmd
while [ "$found" = "1" ]; do
found="0"
pid_list="`pidof_freecwmp`"
for pid in $pid_list; do
read p name state ppid rest < /proc/$pid/stat
cmd=`cat /proc/$ppid/cmdline | grep /etc/init.d/cwmpd`
if [ "_$cmd" = "_" ]; then
continue
fi
kill -stop $ppid
found="1"
pids=`get_process_childs $ppid`
kill -9 "$pids"
done
done
}
stop_cwmpd() {
echo $stop_msg;printf "\033[A"
local pid_list="" pids="" str=""
pid_list=`pidof_cwmp`
if [ "_$pid_list" != "_" ]; then
pid_list=`get_process_childs "$pid_list"`
ubus call tr069 command '{"command": "exit"}' -t 3 &> /dev/null
kill -9 $pid_list
pids="`pidof_cwmp`"
local cnt=0
while [ "_$pids" != "_" -a $cnt -lt 100 ];do
pid_list="$pid_list $pids"
kill -stop $pid_list
pid_list=`get_process_childs "$pid_list"`
kill -9 $pid_list
pids="`pidof_cwmp`"
done
fi
stop_freecwmp_cache
}
start() {
start_cwmpd 2> /dev/null
}
stop() {
echo $stop_msg;printf "\033[A" ;sleep 1
ubus call tr069 command '{"command": "exit"}' -t 3 &> /dev/null
pids="`ps | grep /usr/sbin/cwmpd | sed 's/^ \+//g' | sed 's/ \+/:/g' | grep -v \" Z \" | grep -v grep | cut -f1 -d:|tr '\n' ' '`"
while [ "_$pids" != "_" ];do
kill -9 $pids 2> /dev/null
pids="`ps | grep /usr/sbin/cwmpd | sed 's/^ \+//g' | sed 's/ \+/:/g' | grep -v \" Z \" | grep -v grep | cut -f1 -d:|tr '\n' ' '`"
done
pids="`ps | grep /usr/sbin/freecwmp | sed 's/^ \+//g' | sed 's/ \+/:/g' | grep -v grep | cut -f1 -d: | tr '\n' ' '`"
while [ "_$pids" != "_" ];do
kill -9 $pids 2> /dev/null
pids="`ps | grep /usr/sbin/freecwmp | sed 's/^ \+//g' | sed 's/ \+/:/g' | grep -v grep | cut -f1 -d: | tr '\n' ' '`"
done
stop_cwmpd 2> /dev/null
}
restart() {

View file

@ -22,8 +22,8 @@ DEFINE_boolean 'force' false 'force getting values for certain parameters' 'f'
FLAGS_HELP=`cat << EOF
USAGE: $0 [flags] command [parameter] [values]
command:
get [value|notification|tags|name|all]
set [value|notification|tag]
get [value|notification|name|cache]
set [value|notification]
apply [value|notification|download]
add [object]
delete [object]
@ -47,6 +47,22 @@ if [ ${FLAGS_newline} -eq ${FLAGS_TRUE} ]; then
ECHO_newline='-n'
fi
UCI_GET="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get -q"
UCI_SET="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set -q"
UCI_BATCH="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} batch -q"
UCI_ADD="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} add -q"
UCI_GET_VARSTATE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get -q"
UCI_SHOW="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show -q"
UCI_DELETE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} delete -q"
UCI_COMMIT="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit -q"
NEW_LINE='\n'
cache_path="/etc/cwmpd/.cache"
set_tmp_file="/etc/cwmpd/.set_tmp_file"
prefix_list=""
mkdir -p $cache_path
rm -f "$cache_path/"*"_dynamic"
case "$1" in
set)
if [ "$2" = "notification" ]; then
@ -54,10 +70,6 @@ case "$1" in
__arg2="$4"
__arg3="$5"
action="set_notification"
elif [ "$2" = "tag" ]; then
__arg1="$3"
__arg2="$4"
action="set_tag"
elif [ "$2" = "value" ]; then
__arg1="$3"
__arg2="$4"
@ -72,9 +84,6 @@ case "$1" in
if [ "$2" = "notification" ]; then
__arg1="$3"
action="get_notification"
elif [ "$2" = "tags" ]; then
__arg1="$3"
action="get_tags"
elif [ "$2" = "value" ]; then
__arg1="$3"
action="get_value"
@ -82,9 +91,9 @@ case "$1" in
__arg1="$3"
__arg2="$4"
action="get_name"
elif [ "$2" = "all" ]; then
elif [ "$2" = "cache" ]; then
__arg1="$3"
action="get_all"
action="get_cache"
else
__arg1="$2"
action="get_value"
@ -156,39 +165,22 @@ if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then
echo "[debug] started at \"`date`\""
fi
get_value_functions=""
set_value_functions=""
get_name_functions=""
get_notification_functions=""
set_notification_functions=""
add_object_functions=""
delete_object_functions=""
load_script() {
. $1
}
load_function() {
get_value_functions="$get_value_functions get_$1"
set_value_functions="$set_value_functions set_$1"
get_name_functions="$get_name_functions get_$1_name"
get_notification_functions="$get_notification_functions get_$1_notification"
set_notification_functions="$set_notification_functions set_$1_notification"
add_object_functions="$add_object_functions add_$1"
delete_object_functions="$delete_object_functions delete_$1"
load_prefix() {
prefix_list="$prefix_list $1"
}
handle_scripts() {
local section="$1"
config_get prefix "$section" "prefix"
config_list_foreach "$section" 'location' load_script
config_list_foreach "$section" 'function' load_function
config_list_foreach "$section" 'prefix' load_prefix
}
config_load cwmp
config_foreach handle_scripts "scripts"
# load instance number for TR104
load_voice
# Fault code
@ -214,239 +206,125 @@ FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED="18"
FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION="19"
handle_action() {
if [ "$action" = "get_value" -o "$action" = "get_all" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
# TODO: don't check only string length ; but this is only used
# for getting correct prefix of CWMP parameter anyway and accepting empty string
if [ ${#__arg1} -lt ${#__tmp_arg} -a ${#__arg1} -ne 0 ]; then
echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' or '' "
echo "if you want to force script execution with provided parameter use '-f' flag."
local fault_code=$FAULT_CPE_NO_FAULT
if [ "$action" = "get_cache" ]; then
if [ "$__arg1" != "" ];then
local l=${#__arg1}
let l--
local c=${__arg1:$l:1}
if [ "$c" != "." ];then
echo "Invalid prefix argument"
exit -1
fi
fi
freecwmp_check_fault "$__arg1"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
# TODO: don't return only 'InternetGatewayDevice.' when getting an empty string; but we should both
# parameter with prefix 'InternetGatewayDevice.' and 'Device.'
if [ "$__arg1" = "InternetGatewayDevice." -a "$__arg1" = "" ]; then
__param="InternetGatewayDevice."
else
__param="$__arg1"
local tmp_cache="/tmp/.freecwmp_dm"
local ls_cache=`ls $tmp_cache`
local pid=""
for pid in $ls_cache; do
if [ ! -d /proc/$pid ]; then
rm -rf "$tmp_cache/$pid"
fi
done
pid="$$"
mkdir -p "$tmp_cache/$pid"
for prefix in $prefix_list; do
case $prefix in $__arg1*)
local found=1
local f=${prefix%.}
f=${f//./_}
f="get_cache_""$f"
$f > "$tmp_cache/$pid/$prefix"
mv "$tmp_cache/$pid/$prefix" "$cache_path/$prefix"
;;
esac
done
rm -rf "$tmp_cache/$pid"
ls_cache=`ls $tmp_cache`
for pid in $ls_cache; do
if [ ! -d /proc/$pid ]; then
rm -rf "$tmp_cache/$pid"
fi
done
ls_cache=`ls $tmp_cache`
if [ "_$ls_cache" = "_" ]; then
rm -rf "$tmp_cache"
fi
freecwmp_execute_functions "$get_value_functions" "$__param"
fi
if [ "$action" = "get_value" ]; then
get_param_value_generic "$__arg1"
fault_code="$?"
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "$__arg1" "" "" "" "$fault_code"
freecwmp_output "$__arg1" "" "" "" "" "$fault_code"
fi
fi
if [ "$action" = "get_name" -o "$action" = "get_all" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
# TODO: don't check only string length ; but this is only used
# for getting correct prefix of CWMP parameter anyway and accepting empty string
if [ ${#__arg1} -lt ${#__tmp_arg} -a ${#__arg1} -ne 0 ]; then
echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' or '' "
echo "if you want to force script execution with provided parameter use '-f' flag."
exit -1
fi
fi
freecwmp_check_fault "$__arg1"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
if [ "$action" = "get_name" ]; then
if [ "$__arg2" != "0" -a "$__arg2" != "1" ]; then
fault_code="$FAULT_CPE_INVALID_ARGUMENTS"
fi
if [ "$fault_code" = "0" ]; then
# TODO: don't return only 'InternetGatewayDevice.' when getting an empty string; but we should both
# parameters with prefix 'InternetGatewayDevice.' and 'Device.'
if [ "$__arg1" = "InternetGatewayDevice." -o "$__arg1" = "" ]; then
freecwmp_output "InternetGatewayDevice." "" "0"
if [ "$__arg1" = "" -a "$__arg2" = "1" ]; then
exit 0
fi
__parm="InternetGatewayDevice."
else
__parm="$__arg1"
fi
freecwmp_execute_functions "$get_name_functions" "$__parm" "$__arg2"
get_param_name_generic "$__arg1" "$__arg2"
fault_code="$?"
fi
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "$__arg1" "" "" "" "$fault_code"
freecwmp_output "$__arg1" "" "" "" "" "$fault_code"
fi
fi
if [ "$action" = "set_value" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
# TODO: don't check only string length ; but this is only used
# for getting correct prefix of CWMP parameter anyway
if [ ${#__arg1} -lt ${#__tmp_arg} ]; then
echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' "
echo "if you want to force script execution with provided parameter use '-f' flag."
exit -1
fi
fi
freecwmp_check_fault "$__arg1"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
freecwmp_execute_functions "$set_value_functions" "$__arg1" "$__arg2"
if [ "$action" = "get_notification" ]; then
get_param_notification_generic "$__arg1"
fault_code="$?"
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_set_parameter_fault "$__arg1" "$fault_code"
freecwmp_output "$__arg1" "" "" "" "" "$fault_code"
fi
fi
if [ "$action" = "get_notification" -o "$action" = "get_all" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
# TODO: don't check only string length ; but this is only used
# for getting correct prefix of CWMP parameter anyway and accepting empty string
if [ ${#__arg1} -lt ${#__tmp_arg} -a ${#__arg1} -ne 0 ]; then
echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' or '' "
echo "if you want to force script execution with provided parameter use '-f' flag."
exit -1
fi
fi
freecwmp_check_fault "$__arg1"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
# TODO: don't return only 'InternetGatewayDevice.' when getting an empty string; but we should both
# parameters with prefix 'InternetGatewayDevice.' and 'Device.'
if [ "$__arg1" = "InternetGatewayDevice." -a "$__arg1" = "" ]; then
__param="InternetGatewayDevice."
else
__param="$__arg1"
fi
freecwmp_execute_functions "$get_notification_functions" "$__param"
if [ "$action" = "set_value" ]; then
set_param_value_generic "$__arg1" "$__arg2"
fault_code="$?"
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "$__arg1" "" "" "" "$fault_code"
freecwmp_set_parameter_fault "$__arg1" "$fault_code"
fi
fi
if [ "$action" = "set_notification" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
# TODO: don't check only string length ; but this is only used
# for getting correct prefix of CWMP parameter anyway
if [ ${#__arg1} -lt ${#__tmp_arg} ]; then
echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' "
echo "if you want to force script execution with provided parameter use '-f' flag."
exit -1
fi
fi
freecwmp_check_fault "$__arg1"
fault_code="$?"
if [ "$__arg3" != "0" ];then
if [ "$__arg1" = "InternetGatewayDevice." -o "$__arg1" = "" ]; then
__parm="InternetGatewayDevice."
else
__parm="$__arg1"
fi
if [ "$fault_code" = "0" ]; then
tmp_empty=${FLAGS_empty}
FLAGS_empty=${FLAGS_TRUE}
tmp_json=${FLAGS_json}
FLAGS_json=${FLAGS_FALSE}
action="get_value"
parameters=`freecwmp_execute_functions "$get_value_functions" "$__parm"`
for parameter in $parameters;do
uci_remove_list_element "cwmp.@notifications[0].passive" "$parameter" 2>/dev/null
uci_remove_list_element "cwmp.@notifications[0].active" "$parameter" 2>/dev/null
uci_remove_list_element "cwmp.@notifications[0].disabled" "$parameter" 2>/dev/null
done
FLAGS_empty=${tmp_empty}
FLAGS_json=${tmp_json}
action="set_notification"
freecwmp_execute_functions "$set_notification_functions" "$__parm" "$__arg2"
if [ "$action" = "set_notification" -a "$__arg3" = "1" ]; then
set_param_notification_generic "$__arg1" "$__arg2"
fault_code="$?"
fi
if [ "$__parm" = "InternetGatewayDevice." ]; then
freecwmp_set_parameter_notification "$__parm" "$__arg2"
fault_code="$FAULT_CPE_NO_FAULT"
fi
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_set_parameter_fault "$__parm" "$fault_code"
freecwmp_set_parameter_fault "$__arg1" "$fault_code"
fi
fi
if [ "$action" = "add_object" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
# TODO: don't check only string length ; but this is only used
# for getting correct prefix of CWMP parameter anyway
if [ ${#__arg1} -lt ${#__tmp_arg} ]; then
echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' "
echo "if you want to force script execution with provided parameter use '-f' flag."
exit -1
fi
fi
no_fault="0"
freecwmp_check_fault "$__arg1"
object_fn_generic "$__arg1"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
freecwmp_execute_functions "$add_object_functions" "$__arg1"
fault_code="$?"
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "" "" "" "" "$fault_code"
freecwmp_output "" "" "" "" "" "$fault_code"
fi
fi
if [ "$action" = "delete_object" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
# TODO: don't check only string length ; but this is only used
# for getting correct prefix of CWMP parameter anyway
if [ ${#__arg1} -lt ${#__tmp_arg} ]; then
echo "CWMP parameters usualy begin with 'InternetGatewayDevice.' or 'Device.' "
echo "if you want to force script execution with provided parameter use '-f' flag."
exit -1
fi
fi
no_fault="0"
freecwmp_check_fault "$__arg1"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
freecwmp_execute_functions "$delete_object_functions" "$__arg1"
object_fn_generic "$__arg1"
fault_code="$?"
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "" "" "" "" "$fault_code"
fi
freecwmp_output "" "" "" "" "" "$fault_code"
fi
if [ "$action" = "get_tags" -o "$action" = "get_all" ]; then
freecwmp_get_parameter_tags "x_tags" "$__arg1"
freecwmp_tags_output "$__arg1" "$x_tags"
fi
if [ "$action" = "set_tag" ]; then
freecwmp_set_parameter_tag "$__arg1" "$__arg2"
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q commit
fi
if [ "$action" = "download" ]; then
local fault_code="9000"
if [ "$__arg4" = "" -o "$__arg5" = "" ];then
wget -O /tmp/freecwmp_download "$__arg1" > /dev/null
wget -O /tmp/freecwmp_download "$__arg1" 2> /dev/null
if [ "$?" != "0" ];then
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE
freecwmp_fault_output "" "$fault_code"
@ -454,7 +332,7 @@ if [ "$action" = "download" ]; then
fi
else
local url="http://$__arg4:$__arg5@`echo $__arg1|sed 's/http:\/\///g'`"
wget -O /tmp/freecwmp_download "$url" > /dev/null
wget -O /tmp/freecwmp_download "$url" 2> /dev/null
if [ "$?" != "0" ];then
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE
freecwmp_fault_output "" "$fault_code"
@ -533,12 +411,71 @@ if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then
let __fault_count=$__fault_count/3
if [ "$__fault_count" = "0" ]; then
# applying
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q commit
if [ "$action" = "apply_notification" ]; then
freecwmp_output "" "" "" "" "" "" "" "0"
elif [ "$action" = "apply_value" ]; then
freecwmp_output "" "" "" "" "" "1"
$UCI_COMMIT
local prefix=""
local filename=""
local max_len=0
local len=0
case $action in
apply_notification)
cat $set_tmp_file | while read line; do
json_init
json_load "$line"
json_get_var parameter parameter
json_get_var notification notification
max_len=0
for prefix in $prefix_list; do
case "$parameter" in "$prefix"*)
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
filename="$prefix"
fi
esac
done
local l=${#parameter}
let l--
if [ "${parameter:$l:1}" != "." ]; then
sed -i "/\<$parameter\>/s/.*/$line/" $cache_path/$filename
else
cat $cache_path/$filename|grep "$parameter"|grep "\"notification\""| while read line; do
json_init
json_load "$line"
json_get_var parameter_name parameter
json_add_string "notification" "$notification"
json_close_object
param=`json_dump`
sed -i "/\<$parameter_name\>/s/.*/$param/" $cache_path/$filename
done
fi
done
freecwmp_output "" "" "" "" "" "" "" "" "0"
;;
apply_value)
cat $set_tmp_file | while read line; do
json_init
json_load "$line"
json_get_var parameter parameter
json_get_var value value
json_get_var notification notification
json_get_var type type
max_len=0
for prefix in $prefix_list; do
case "$parameter" in "$prefix"*)
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
filename="$prefix"
fi
esac
done
sed -i "/\<$parameter\>/s/.*/$line/" $cache_path/$filename
freecwmp_notify "$parameter" "$value" "$notification" "$type"
done
freecwmp_output "" "" "" "" "" "" "1"
;;
esac
else
let n=$__fault_count-1
for i in `seq 0 $n`
@ -551,38 +488,24 @@ if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then
rm -rf /var/state/cwmp 2> /dev/null
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q revert cwmp
fi
rm -f $set_tmp_file
fi
if [ "$action" = "inform" ]; then
action="get_value"
extern_intf=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.cpe.default_wan_interface`
get_device_info_manufacturer
get_device_info_oui
get_device_info_product_class
get_device_info_serial_number
get_device_info_hardware_version
get_device_info_software_version
get_device_info_generic "InternetGatewayDevice.DeviceInfo.ProvisioningCode"
get_device_info_generic "InternetGatewayDevice.DeviceInfo.SpecVersion"
get_wan_device_instance "get_pop_inform" "" "" "" "" "fault"
get_management_server_connection_request_url
get_management_server_parameter_key
cat "$cache_path/"* | grep "\"forced_inform\"" | grep -v "\"get_cmd\""
cat "$cache_path/"* | grep "\"forced_inform\"" | grep "\"get_cmd\"" | while read line; do
json_init
json_load "$line"
json_get_var exec_get_cmd get_cmd
json_get_var param parameter
json_get_var type type
val=`eval "$exec_get_cmd"`
freecwmp_output "$param" "$val" "" "$type"
done
fi
if [ "$action" = "notify" ]; then
if [ "$__arg1" = "InternetGatewayDevice." -a "$__arg1" = "" ]; then
__param="InternetGatewayDevice."
else
__param="$__arg1"
fi
freecwmp_execute_functions "$get_notification_functions" "$__param"
fault_code="$?"
if [ "$fault_code" = "$FAULT_CPE_NO_FAULT" ]; then
freecwmp_notify "$__arg1" "$__arg2" "$__arg3"
else
echo "Invalid parameter name" 1>&2
fi
freecwmp_notify "$__arg1" "$__arg2"
fi
if [ "$action" = "end_session" ]; then
@ -616,7 +539,10 @@ fi
fi
;;
get)
if [ "$action" = "notification" ]; then
if [ "$action" = "cache" ]; then
json_get_var __arg1 parameter
action="get_cache"
elif [ "$action" = "notification" ]; then
json_get_var __arg1 parameter
action="get_notification"
elif [ "$action" = "value" ]; then
@ -688,7 +614,7 @@ fi
fi
}
handle_action
handle_action 2> /dev/null
if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then
echo "[debug] exited at \"`date`\""

View file

@ -2,6 +2,7 @@
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
# TODO: merge this one somewhere in OpenWrt
uci_remove_list_element() {
@ -19,65 +20,25 @@ uci_remove_list_element() {
}
freecwmp_output() {
if [ "$FLAGS_value" = "${FLAGS_TRUE}" ]; then
local parameter="$1"
local value="$2"
local delimiter="$3"
if [ "$delimiter" = "" ]; then
delimiter=":"
fi
if [ -n "$value" -o ${FLAGS_empty} -eq ${FLAGS_TRUE} ]; then
if [ ${FLAGS_value} -eq ${FLAGS_TRUE} ]; then
echo $ECHO_newline $value
else
echo $ECHO_newline $parameter "$delimiter" $value
fi
fi
fi
if [ ${FLAGS_empty} -eq ${FLAGS_TRUE} ]; then
local parameter="$1"
echo $ECHO_newline $parameter
fi
if [ "$FLAGS_json" = "${FLAGS_TRUE}" ]; then
local parameter="$1"
local value="$2"
local permissions="$3"
local type="$4"
local fault_code="$5"
local status="$6"
local instance="$7"
local success="$8"
echo `freecwmp_json_output "$parameter" "$value" "$permissions" "$type" "$fault_code" "$status" "$instance" "$success"`
fi
}
freecwmp_json_output() {
local MSG=""
local parameter="$1"
local value="$2"
local permissions="$3"
local type="$4"
local fault_code="$5"
local status="$6"
local instance="$7"
local success="$8"
if [ "$type" = "" ]; then
type="xsd:string"
fi
local notification="$4"
local type="$5"
local fault_code="$6"
local status="$7"
local instance="$8"
local success="$9"
case "$action" in
get_value)
get_value|inform)
json_init
json_add_string "parameter" "$parameter"
json_add_string "value" "$value"
json_add_string "type" "$type"
json_add_string "fault_code" "$fault_code"
if [ "$type" != "" ]; then json_add_string "type" "$type"; fi
json_close_object
MSG=`json_dump`
;;
@ -92,7 +53,7 @@ freecwmp_json_output() {
get_notification)
json_init
json_add_string "parameter" "$parameter"
json_add_string "notification" "$value"
if [ "$notification" != "" ]; then json_add_string "notification" "$notification"; fi
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
@ -130,6 +91,36 @@ freecwmp_json_output() {
echo "$MSG"
}
freecwmp_cache_output() {
local MSG=""
local parameter="$1"
local value="$2"
local permission="$3"
local notification="$4"
local type="$5"
local set_cmd="$6"
local get_cmd="$7"
local notif_permission="$8"
local forced_inform="$9"
json_init
json_add_string "parameter" "$parameter"
json_add_string "writable" "$permission"
if [ "$type" != "" ]; then json_add_string "type" "$type"; fi
if [ "$get_cmd" != "" ]; then json_add_string "get_cmd" "$get_cmd"; fi
if [ "$set_cmd" != "" ]; then json_add_string "set_cmd" "$set_cmd"; fi
if [ "$notif_permission" != "" ]; then json_add_string "notif_permission" "$notif_permission"; fi
if [ "$notification" != "" ]; then
json_add_string "notification" "$notification"
json_add_string "value" "$value"
fi
if [ "$forced_inform" != "" ]; then json_add_string "forced_inform" "$forced_inform"; fi
json_close_object
MSG=`json_dump`
echo "$MSG"
}
freecwmp_fault_output() {
local MSG=""
@ -163,94 +154,50 @@ freecwmp_fault_output() {
echo "$MSG"
}
freecwmp_value_output() {
local tmp_value=${FLAGS_value}
FLAGS_value=${FLAGS_TRUE}
local tmp_json=${FLAGS_json}
FLAGS_json=${FLAGS_FALSE}
freecwmp_output "$1" "$2" "V"
FLAGS_value=$tmp_value
FLAGS_json=$tmp_json
}
freecwmp_notification_output() {
local tmp_value=${FLAGS_value}
FLAGS_value=${FLAGS_TRUE}
local tmp_json=${FLAGS_json}
FLAGS_json=${FLAGS_FALSE}
freecwmp_output "$1" "$2" "N"
FLAGS_value=$tmp_value
FLAGS_json=$tmp_json
}
freecwmp_tags_output() {
local tmp_value=${FLAGS_value}
FLAGS_value=${FLAGS_TRUE}
local tmp_json=${FLAGS_json}
FLAGS_json=${FLAGS_FALSE}
freecwmp_output "$1" "$2" "T"
FLAGS_value=$tmp_value
FLAGS_json=$tmp_json
}
freecwmp_not_implemented() {
local tmp_value=${FLAGS_value}
FLAGS_value=${FLAGS_TRUE}
local tmp_json=${FLAGS_json}
FLAGS_json=${FLAGS_FALSE}
freecwmp_output "$1" "NOT_IMPLEMENTED"
FLAGS_value=$tmp_value
FLAGS_json=$tmp_json
}
freecwmp_parse_formated_parameter() {
local _clean_parameter="$1"
local _formated_parameter="$2"
local _values
local _clean_parameter_array=`echo $_clean_parameter | sed 's/\./ /g'`
local _formated_parameter_array=`echo $_formated_parameter | sed 's/\./ /g'`
local parameter="$1"
local pattern="$2"
local p="" q=""
local _values="" n=""
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"
while [ true ]; do
if [ "_" = "_$parameter" -o "_" = "_$pattern" ]; then
if [ "_$parameter" != "_$pattern" ]; then
eval "export -- \"$3=-1\""
return
else
_values="$_values $m"
break
fi
fi
done
split_param=${parameter%%.*}
split_pattr=${pattern%%.*}
p="$parameter"; q="$pattern"
parameter=${parameter#*.}
pattern=${pattern#*.}
if [ "$p" = "$parameter" -o "$q" = "$pattern" ]; then
if [ "$parameter" != "$pattern" -a "_$pattern" != "_{i}" ]; then
eval "export -- \"$3=-1\""
return
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
break
fi
fi
if [ "_$split_pattr" = "_{i}" ]; then
let n=$split_param-1
if [ $n -lt 0 ]; then
eval "export -- \"$3=-1\""
return
fi
done
if [ "_$_values" == "_" ]; then
_values="$split_param"
else
_values="$_values $split_param"
fi
elif [ "_$split_param" != "_$split_pattr" ]; then
eval "export -- \"$3=-1\""
return
fi
done
@ -333,7 +280,7 @@ freecwmp_get_parameter_value() {
local _parm="$2"
local _val
config_foreach freecwmp_config_cwmp "cwmp" "get" "value" "$_parm" "_val"
eval "export -- \"$_dest=\"\"$_val\"\"\""
echo "$_val"
}
freecwmp_set_parameter_value() {
@ -349,10 +296,6 @@ freecwmp_set_parameter_value() {
set cwmp.@cwmp[-1].value="$_val"
EOF
fi
config_foreach freecwmp_config_notifications "notifications" "get" "$_parm" "tmp"
# TODO: notify freecwmpd about the change
# if [ "$tmp" -eq "2" ]; then
# fi
}
freecwmp_get_parameter_notification() {
@ -377,11 +320,20 @@ freecwmp_get_parameter_notification() {
freecwmp_notify() {
local parm="$1"
local val="$2"
local attribute
local type="$3"
local attribute="$3"
local type="$4"
local param_check="$parm"
freecwmp_get_parameter_notification "attribute" "$parm"
if [ "$attribute" != "0" ];then
if [ "_$attribute" = "_" ]; then
json_msg=`get_param_notification_generic "$parm" | head -1`
json_init
json_load "$json_msg"
json_get_var attribute notification
json_get_var param_check parameter
json_get_var type type
fi
if [ "$param_check" = "$parm" -a "_$attribute" != "_0" ]; then
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 notify '{ "parameter": "'$parm'", "value": "'$val'", "attribute": "'$attribute'", "type": "'$type'" }' &
fi
}
@ -427,28 +379,6 @@ freecwmp_set_parameter_notification() {
fi
}
freecwmp_get_parameter_tags() {
local _dest="$1"
local _parm="$2"
config_foreach freecwmp_config_cwmp "cwmp" "get" "tags" "$_parm" "_tags"
eval "export -- \"$_dest=\"\"$_tags\"\"\""
}
freecwmp_set_parameter_tag() {
local _parm="$1"
local _tag="$2"
config_foreach freecwmp_config_cwmp "cwmp" "check" "parameter" "$_parm" "_section"
if [ ! "$_section" = "" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q add_list cwmp.$_section.tag=$_tag 2> /dev/null
else
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q batch << EOF 2>&1 >/dev/null
add cwmp cwmp
set cwmp.@cwmp[-1].parameter="$_parm"
add_list cwmp.@cwmp[-1].tag="$_tag"
EOF
fi
}
delay_service_restart() {
local service="$1"
local delay="$2"
@ -492,13 +422,6 @@ $command &> /dev/null
EOF
}
freecwmp_check_fault() {
if [ "$1" = "." ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
return $FAULT_CPE_NO_FAULT
}
freecwmp_set_parameter_fault() {
local _parm="$1"
local _fault="$2"
@ -509,57 +432,6 @@ freecwmp_set_parameter_fault() {
EOF
}
freecwmp_add_lan_device_ip_interface() {
local _parm="$1"
local _instance="$2"
if [ "$_instance" = "1" ];then
indice=""
else
indice=$_instance
fi
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q batch << EOF 2>&1 >/dev/null
add cwmp object
set cwmp.@object[-1].parameter="$_parm"
set cwmp.@object[-1].instance="$_instance"
set cwmp.@object[-1].interface="lan$indice"
EOF
if [ "$indice" != "" ]; then
let i=$indice-1
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set network.lan$indice=interface 2> /dev/null
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set network.lan$indice.ifname=eth$i 2> /dev/null
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set network.lan$indice.type=bridge 2> /dev/null
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set network.lan$indice.proto=dhcp 2> /dev/null
fi
}
freecwmp_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
func=$(echo "$arg1" | cut -d "." -f 2)
func_config=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get -q cwmp.@$func[0].function`
if [ "`echo $function_name|grep \"$func_config\"`" != "" -o "$func" = "" ];then
$function_name "$arg1" "$arg2" "$arg3"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
no_fault="1"
fi
if [ "$fault_code" != "0" -a "$fault_code" != "$FAULT_CPE_INVALID_PARAMETER_NAME" ]; then
return $fault_code
fi
fi
done
if [ "$no_fault" = "1" ]; then fault_code="0"; fi
return $fault_code
}
freecwmp_check_image()
{
. /etc/functions.sh; include /lib/upgrade; platform_check_image /tmp/firmware_upgrade_image
@ -648,4 +520,343 @@ freecwmp_apply_vendor_configuration()
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED
freecwmp_fault_output "" "$fault_code"
fi
}
get_param_cache_generic() {
local param="$1"
local permission="$2"
local val_cmd="$3"
local set_cmd="$4"
local get_cmd="$5"
local type="$6"
local notif_permission="$7"
local forced_inform="$8"
local forced_notify="$9"
local val=""
local notification="0"
if [ "$val_cmd" != "" ]; then
val=`eval "$val_cmd"`
fi
if [ "_$forced_notify" = "_" ]; then
freecwmp_get_parameter_notification "notification" $param
else
notification="$forced_notify"
fi
freecwmp_cache_output "$param" "$val" "$permission" "$notification" "$type" "$set_cmd" "$get_cmd" "$notif_permission" "$forced_inform"
}
get_object_cache_generic() {
local param=$1
local permission=$2
local notif_permission=$3
freecwmp_cache_output "$param" "" "$permission" "" "" "" "" "$notif_permission"
}
get_generic_dynamic() {
local found_prefix="$1"
local param="$2"
local prefix="" get_func=""
for prefix in $prefix_list; do
case "$prefix" in "$found_prefix"*)
get_func=${prefix%.}
get_func=${get_func//./_}
get_func="get_dynamic_""$get_func"
$get_func "$param" >"$cache_path/$prefix""_dynamic"
esac
done
}
cat_cache_filter_param() {
cat "$1"* | grep "$2"
}
get_param_prefix() {
local parameter="$1"
local max_len=0
local found="" prefix="" len=0
if [ "$parameter" != "" ]; then
for prefix in $prefix_list; do
case "$parameter" in "$prefix"*)
if [ "$parameter" = "$prefix"]; then
found="$prefix"
break
fi
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found="$prefix"
fi
esac
done
if [ "$found" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
fi
eval "export -- $2='$found'"
return $FAULT_CPE_NO_FAULT
}
get_generic_cmd() {
local parameter="$1"
local found="$2"
local msgs="" command=""
if [ "$parameter" != "" -a "$parameter" != "$found" ]; then
msgs=`cat "$cache_path/$found"* | grep "\"$parameter\""`
if [ "$msgs" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
l=${#parameter}
let l--
if [ "${parameter:$l:1}" != "." ]; then
command="echo $msgs"
else
command="cat_cache_filter_param $cache_path/$found $parameter"
fi
else
command="cat $cache_path/$found*"
fi
eval "export -- $3='$command'"
return $FAULT_CPE_NO_FAULT
}
get_param_value_generic() {
local parameter=$1
local param="" val="" type="" found_prefix="" cmd=""
get_param_prefix "$parameter" "found_prefix"
local ret="$?"
if [ "$ret" != $FAULT_CPE_NO_FAULT ]; then
return "$ret"
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$parameter"
get_generic_cmd "$parameter" "$found_prefix" "cmd"
ret="$?"
if [ "$ret" = $FAULT_CPE_NO_FAULT ]; then
eval '$cmd' | grep "\"value\"" | grep -v "\"get_cmd\""
eval '$cmd' | grep "\"get_cmd\"" | while read line; do
json_init
json_load "$line"
json_get_var exec_get_cmd get_cmd
json_get_var param parameter
json_get_var type type
val=`eval "$exec_get_cmd"`
freecwmp_output "$param" "$val" "" "$type"
done
fi
rm -f "$cache_path/"*"_dynamic"
return "$ret"
}
get_param_name_generic() {
local parameter=$1
local next_level=$2
local found_prefix="" cmd=""
get_param_prefix "$parameter" "found_prefix"
local ret="$?"
if [ "$ret" != $FAULT_CPE_NO_FAULT ]; then
return "$ret"
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$parameter"
get_generic_cmd "$parameter" "$found_prefix" "cmd"
ret="$?"
if [ "$ret" = "$FAULT_CPE_NO_FAULT" ]; then
if [ "$next_level" = "0" ]; then
eval '$cmd'
else
local len=${#parameter}
let len--
if [ "${parameter:$len:1}" != "." ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
eval '$cmd' | grep -v "$parameter[A-Za-z_0-9]\+\.[A-Za-z_0-9]"
fi
fi
rm -f "$cache_path/"*"_dynamic"
return $ret
}
get_param_notification_generic() {
local parameter=$1
local found_prefix="" cmd=""
get_param_prefix "$parameter" "found_prefix"
local ret="$?"
if [ "$ret" != $FAULT_CPE_NO_FAULT ]; then
return "$ret"
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$parameter"
get_generic_cmd "$parameter" "$found_prefix" "cmd"
ret="$?"
if [ "$ret" = "$FAULT_CPE_NO_FAULT" ]; then
eval '$cmd' | grep "\"notification\""
fi
rm -f "$cache_path/"*"_dynamic"
return $ret
}
set_param_value_generic() {
local param="$1"
local val="$2"
local max_len=0
local found_prefix="" msgs="" prefix="" len="" permission="" set_cmd=""
if [ "$param" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
for prefix in $prefix_list; do
case "$param" in "$prefix"*)
if [ "$param" = "$prefix" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found_prefix="$prefix"
fi
esac
done
if [ "$found_prefix" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$param"
msgs=`cat "$cache_path/$found_prefix"* | grep "\"$param\"" | grep "\"value\"" | head -1`
rm -f "$cache_path/"*"_dynamic"
if [ "$msgs" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
json_init
json_load "$msgs"
json_get_var writable writable
if [ "$writable" != "1" ];then
return $FAULT_CPE_NON_WRITABLE_PARAMETER
fi
json_get_var set_cmd set_cmd
if [ "$set_cmd" = "" ];then
return $FAULT_CPE_NON_WRITABLE_PARAMETER
fi
eval "$set_cmd"
json_add_string "value" "$val"
json_close_object
echo "`json_dump`" >> $set_tmp_file
return $FAULT_CPE_NO_FAULT
}
set_param_notification_generic() {
local param="$1"
local notification="$2"
local max_len=0
local same="0"
local found_prefix="" msgs="" cmd="" prefix="" len="" line="" notif_permission=""
if [ "$param" != "" ]; then
for prefix in $prefix_list; do
case "$param" in "$prefix"*)
if [ "$param" = "$prefix"]; then
same="1"
found_prefix="$prefix"
break
fi
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found_prefix="$prefix"
fi
esac
done
if [ "$found_prefix" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$param"
msgs=`cat "$cache_path/$found_prefix"* | grep "\"$param\""`
rm -f "$cache_path/"*"_dynamic"
if [ "$msgs" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
else
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$param"
msgs=`cat "$cache_path/"* | grep "\"[A-Za-z_0-9]\+\.\""`
rm -f "$cache_path/"*"_dynamic"
fi
echo "$msgs" | while read line; do
json_init
json_load "$line"
json_get_var notif_permission notif_permission
if [ "$notif_permission" = "0" ]; then
return $FAULT_CPE_NOTIFICATION_REJECTED
fi
json_get_var param parameter
freecwmp_set_parameter_notification "$param" "$notification"
json_add_string "notification" "$notification"
json_close_object
echo "`json_dump`" >> $set_tmp_file
done
return $?
}
object_fn_generic() {
local object="$1"
local prefix=""
local found=""
local max_len=0
local len=0
for prefix in $prefix_list; do
case "$object" in "$prefix"*)
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found="$prefix"
fi
esac
done
if [ "$found" = "" ];then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
local fn=${found%.}
fn=${fn//./_}
local f="$action"_"$fn"
$f "$1" "$found"
return $?
}

View file

@ -1,205 +0,0 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_device_hosts_number_of_leases() {
local _static=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show dhcp 2> /dev/null | fgrep 'dhcp.' | fgrep '.mac=' | wc -l`
local _dynamic=`wc -l /var/dhcp.leases | awk '{ print $1 }'`
eval "export -- \"$2=\"\"$_static\"\"\""
eval "export -- \"$3=\"\"$_dynamic\"\"\""
}
get_device_hosts_ip_address() {
local _leases_file=$1
local _num=$2
local _num_static_leases=$3
local _num_dynamic_leases=$4
local _ip
if [ $_num -le $_num_static_leases ]; then
let local _uci_num=$_num-1
_ip=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get dhcp.@host[$_uci_num].ip 2> /dev/null`
fi
let _num=$_num-$_num_static_leases
if [ $_num -gt 0 -a $_num -le $_num_dynamic_leases ]; then
local _sed_cmd=`echo -n \'$_num; echo p\'`
_ip=`eval sed -n $_sed_cmd $_leases_file | awk '{ print $3 }'`
fi
eval "export -- \"$5=\"\"$_ip\"\"\""
}
get_device_hosts() {
local leases_file
if [ -z "$default_dnsmasq_leases_file" ]; then
leases_file="/var/dhcp.leases"
else
leases_file=$default_dnsmasq_leases_file
fi
local num_static_leases
local num_dynamic_leases
get_device_hosts_number_of_leases "$leases_file" "num_static_leases" "num_dynamic_leases"
# internal TR-069 to TR-181 parameter transformation
local parameter=`echo -n $1 | sed "s/InternetGatewayDevice\.LANDevice\.1\./Device\./g"`
case "$parameter" in
Device.Hosts.HostNumberOfEntries)
let local val=$num_static_leases+$num_dynamic_leases
freecwmp_output "$parameter" "$val"
return
;;
esac
local rc
local num
# TODO: Device.Hosts.Host.{i}.Alias (alias support does not exist)
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.PhysAddress" "rc" "num"
if [ $rc -eq 0 ]; then
local val
if [ $num -le $num_static_leases ]; then
let local uci_num=$num-1
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get dhcp.@host[$uci_num].mac 2> /dev/null`
fi
let num=$num-$num_static_leases
if [ $num -gt 0 -a $num -le $num_dynamic_leases ]; then
local sed_cmd=`echo -n \'$num; echo p\'`
val=`eval sed -n $sed_cmd $leases_file | awk '{ print $2 }'`
fi
freecwmp_value_output "$parameter" "$val"
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.IPAddress" "rc" "num"
if [ $rc -eq 0 ]; then
local val
get_device_hosts_ip_address "$leases_file" "$num" "$num_static_leases" "$num_dynamic_leases" "val"
freecwmp_value_output "$parameter" "$val"
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.AddressSource" "rc" "num"
if [ $rc -eq 0 ]; then
local val
if [ $num -le $num_static_leases ]; then
val="Static"
fi
let num=$num-$num_static_leases
if [ $num -gt 0 -a $num -le $num_dynamic_leases ]; then
val="DHCP"
fi
freecwmp_value_output "$parameter" "$val"
return
fi
# TODO: Device.Hosts.Host.{i}.DHCPClient (freecwmp needs to support other parameters first)
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.LeaseTimeRemaining" "rc" "num"
if [ $rc -eq 0 ]; then
local val
if [ $num -le $num_static_leases ]; then
val="-1"
fi
let num=$num-$num_static_leases
if [ $num -gt 0 -a $num -le $num_dynamic_leases ]; then
local sed_cmd=`echo -n \'$num; echo p\'`
local t1=`eval sed -n $sed_cmd $leases_file | awk '{ print $1 }'`
local t2=`date +%s`
let val=$t1-$t2
fi
freecwmp_value_output "$parameter" "$val"
return
fi
# TODO: Device.Hosts.Host.{i}.AssociatedDevice (freecwmp needs to support other parameters first)
# TODO: Device.Hosts.Host.{i}.Layer1Interface (freecwmp needs to support other parameters first)
# TODO: Device.Hosts.Host.{i}.Layer3Interface (freecwmp needs to support other parameters first)
# TODO: Device.Hosts.Host.{i}.VendorClassID (DHCP option 60 not supported with dnsmasq)
# TODO: Device.Hosts.Host.{i}.ClientID (DHCP option 61 not supported with dnsmasq)
# TODO: Device.Hosts.Host.{i}.UserClassID (DHCP option 77 not supported with dnsmasq)
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.HostName" "rc" "num"
if [ $rc -eq 0 ]; then
local val
if [ $num -le $num_static_leases ]; then
let local uci_num=$num-1
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get dhcp.@host[$uci_num].name 2> /dev/null`
fi
let num=$num-$num_static_leases
if [ $num -gt 0 -a $num -le $num_dynamic_leases ]; then
local sed_cmd=`echo -n \'$num; echo p\'`
val=`eval sed -n $sed_cmd $leases_file | awk '{ print $4 }'`
if [ "x$val" == "x*" ]; then val=""; fi
fi
freecwmp_value_output "$parameter" "$val"
return
fi
# TODO: Device.Hosts.Host.{i}.ClientID (DHCP option 61 not supported with dnsmasq)
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.Active" "rc" "num"
if [ $rc -eq 0 ]; then
local val
local ip
get_device_hosts_ip_address "$leases_file" "$num" "$num_static_leases" "$num_dynamic_leases" "ip"
val=`ping -c 1 $ip 2>&1 > /dev/null ; echo $?`
let val=!$val
freecwmp_value_output "$parameter" "$val"
return
fi
# TODO: we support only one IPv4 address per host
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.IPv4AddressNumberOfEntries" "rc" "num"
if [ $rc -eq 0 ]; then
local val
let local n=$num_static_leases+$num_dynamic_leases
if [ $num -le $n ]; then
val=1
fi
freecwmp_value_output "$parameter" "$val"
return
fi
# TODO: we do not support IPv6 address
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.IPv6AddressNumberOfEntries" "rc" "num"
if [ $rc -eq 0 ]; then
local val
let local n=$num_static_leases+$num_dynamic_leases
if [ $num -le $n ]; then
val=0
fi
freecwmp_value_output "$parameter" "$val"
return
fi
# TODO: we support only one IPv4 address per host
freecwmp_parse_formated_parameter "$parameter" "Device.Hosts.Host.{i}.IPv4Address.{i}.IPAddress" "rc" "num"
if [ $rc -eq 0 ]; then
local val
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
let local n=$num_static_leases+$num_dynamic_leases
if [ $num2 -eq 1 ]; then
get_device_hosts_ip_address "$leases_file" "$num1" "$num_static_leases" "$num_dynamic_leases" "val"
fi
freecwmp_value_output "$parameter" "$val"
return
fi
# TODO: Device.Hosts.Host.{i}.IPv6Address.{i}.IPAddress (no IPv6 support yet)
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_device_hosts_name() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
get_device_hosts_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_device_hosts() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_device_hosts_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
add_device_hosts() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_device_hosts() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }

View file

@ -2,498 +2,38 @@
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_device_info_manufacturer() {
local val=""
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.cpe.manufacturer 2> /dev/null`
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.Manufacturer"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.Manufacturer" "$val" "$permissions"
}
get_device_info_oui() {
local val=""
local permissions=""
case "$action" in
get_value)
val=`cat /proc/nvram/BaseMacAddr | awk '{ print $1$2$3}' 2> /dev/null`
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.ManufacturerOUI"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" "$val" "$permissions"
}
get_device_info_product_class() {
local val=""
case "$action" in
get_value)
val=`cat /etc/iop_version | cut -d'_' -f1 2> /dev/null`
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.ProductClass"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.ProductClass" "$val" "$permissions"
}
get_device_info_serial_number() {
local val=""
local permissions=""
case "$action" in
get_value)
local val=`cat /proc/nvram/SerialNumber 2> /dev/null`
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.SerialNumber"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.SerialNumber" "$val" "$permissions"
}
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
get_device_info_hardware_version() {
local val=""
local permissions=""
local dslAnnex=""
case "$action" in
get_value)
dslAnnex=`cat /proc/nvram/dslAnnex 2> /dev/null`
val=`cat /etc/iop_version | cut -d'-' -f1 | sed s/$/"$dslAnnex"/ 2> /dev/null`
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.HardwareVersion"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.HardwareVersion" "$val" "$permissions"
echo "$val"
}
get_device_info_software_version() {
local val=""
local permissions=""
case "$action" in
get_value)
val=`cat /etc/iop_version | cut -d'_' -f2 2> /dev/null`
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.SoftwareVersion"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.SoftwareVersion" "$val" "$permissions"
get_cache_InternetGatewayDevice_DeviceInfo() {
get_object_cache_generic "InternetGatewayDevice.DeviceInfo." "0" "0"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.Manufacturer" "0" "$UCI_GET cwmp.cpe.manufacturer" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" "0" "cat /proc/nvram/BaseMacAddr | awk '{ print \$1\$2\$3}'" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.ProductClass" "0" "cat /etc/iop_version | cut -d'_' -f1" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.SerialNumber" "0" "cat /proc/nvram/SerialNumber" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.HardwareVersion" "0" "get_device_info_hardware_version" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.SoftwareVersion" "0" "cat /etc/iop_version | cut -d'_' -f2" "" "" "" "0" "1" "2"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.UpTime" "0" "cat /proc/uptime | awk -F \".\" '{ print \$1 }'" "" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.DeviceLog" "0" "dmesg | tail -n10"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.SpecVersion" "0" "freecwmp_get_parameter_value \$param" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.ProvisioningCode" "1" "freecwmp_get_parameter_value \$param" "freecwmp_set_parameter_value \$param \$val" "" "" "0" "1" "2"
}
get_device_info_uptime() {
local val=""
local permissions=""
local type="xsd:unsignedInt"
case "$action" in
get_value)
val=`cat /proc/uptime | awk -F "." '{ print $1 }'`
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.UpTime"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.UpTime" "$val" "$permissions" "$type"
get_dynamic_InternetGatewayDevice_DeviceInfo() {
return $FAULT_CPE_NO_FAULT
}
get_device_info_device_log() {
local val=""
local permissions=""
case "$action" in
get_value)
#if [ ${FLAGS_last} -eq ${FLAGS_TRUE} ]; then
# val=`dmesg | tail -n1`
#else
# val=`dmesg | tail -n10`
#fi
val=""
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.DeviceLog"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.DeviceLog" "$val" "$permissions"
}
get_device_info() {
case "$1" in
InternetGatewayDevice.)
get_device_info_manufacturer
get_device_info_oui
get_device_info_product_class
get_device_info_serial_number
get_device_info_hardware_version
get_device_info_software_version
get_device_info_uptime
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.)
get_device_info_manufacturer
get_device_info_oui
get_device_info_product_class
get_device_info_serial_number
get_device_info_hardware_version
get_device_info_software_version
get_device_info_uptime
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.Manufacturer)
get_device_info_manufacturer
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.ManufacturerOUI)
get_device_info_oui
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.ProductClass)
get_device_info_product_class
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.SerialNumber)
get_device_info_serial_number
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.HardwareVersion)
get_device_info_hardware_version
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.SoftwareVersion)
get_device_info_software_version
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.UpTime)
get_device_info_uptime
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.DeviceLog)
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
esac
add_object_InternetGatewayDevice_DeviceInfo() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_device_info_name() {
case "$1" in
InternetGatewayDevice.)
freecwmp_output "InternetGatewayDevice.DeviceInfo." "" "0"
if [ "$2" = "0" ]; then
get_device_info_manufacturer
get_device_info_oui
get_device_info_product_class
get_device_info_serial_number
get_device_info_hardware_version
get_device_info_software_version
get_device_info_uptime
get_device_info_device_log
fi
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.)
freecwmp_output "InternetGatewayDevice.DeviceInfo." "" "0"
get_device_info_manufacturer
get_device_info_oui
get_device_info_product_class
get_device_info_serial_number
get_device_info_hardware_version
get_device_info_software_version
get_device_info_uptime
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.Manufacturer)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_manufacturer
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.ManufacturerOUI)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_oui
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.ProductClass)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_product_class
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.SerialNumber)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_serial_number
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.HardwareVersion)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_hardware_version
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.SoftwareVersion)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_software_version
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.UpTime)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_uptime
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.DeviceLog)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
esac
delete_object_InternetGatewayDevice_DeviceInfo() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_device_info_notification() {
case "$1" in
InternetGatewayDevice.)
get_device_info_manufacturer
get_device_info_oui
get_device_info_product_class
get_device_info_serial_number
get_device_info_hardware_version
get_device_info_software_version
get_device_info_uptime
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.)
get_device_info_manufacturer
get_device_info_oui
get_device_info_product_class
get_device_info_serial_number
get_device_info_hardware_version
get_device_info_software_version
get_device_info_uptime
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.Manufacturer)
get_device_info_manufacturer
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.ManufacturerOUI)
get_device_info_oui
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.ProductClass)
get_device_info_product_class
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.SerialNumber)
get_device_info_serial_number
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.HardwareVersion)
get_device_info_hardware_version
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.SoftwareVersion)
get_device_info_software_version
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.UpTime)
get_device_info_uptime
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.DeviceLog)
get_device_info_device_log
return $FAULT_CPE_NO_FAULT
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
set_device_info() {
case "$1" in
InternetGatewayDevice.DeviceInfo.Manufacturer)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
InternetGatewayDevice.DeviceInfo.ManufacturerOUI)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
InternetGatewayDevice.DeviceInfo.ProductClass)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
InternetGatewayDevice.DeviceInfo.SerialNumber)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
InternetGatewayDevice.DeviceInfo.HardwareVersion)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
InternetGatewayDevice.DeviceInfo.SoftwareVersion)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
InternetGatewayDevice.DeviceInfo.UpTime)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
InternetGatewayDevice.DeviceInfo.DeviceLog)
return $FAULT_CPE_NON_WRITABLE_PARAMETER
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
set_device_info_notification() {
case "$1" in
InternetGatewayDevice.DeviceInfo.)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.Manufacturer)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.ManufacturerOUI)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.ProductClass)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.SerialNumber)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.HardwareVersion)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.SoftwareVersion)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.UpTime)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
InternetGatewayDevice.DeviceInfo.DeviceLog)
return $FAULT_CPE_NOTIFICATION_REJECTED
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
check_parameter_device_info_generic() {
case "$1" in
InternetGatewayDevice.DeviceInfo.ModelName|\
InternetGatewayDevice.DeviceInfo.Description|\
InternetGatewayDevice.DeviceInfo.ModemFirmwareVersion|\
InternetGatewayDevice.DeviceInfo.EnabledOptions|\
InternetGatewayDevice.DeviceInfo.AdditionalHardwareVersion|\
InternetGatewayDevice.DeviceInfo.AdditionalSoftwareVersion|\
InternetGatewayDevice.DeviceInfo.SpecVersion|\
InternetGatewayDevice.DeviceInfo.ProvisioningCode|\
InternetGatewayDevice.DeviceInfo.FirstUseDate)
return 0
;;
esac
return 1
}
get_device_info_generic() {
check_parameter_device_info_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
freecwmp_get_parameter_value "value" "$1"
freecwmp_output "$1" "$value"
return $FAULT_CPE_NO_FAULT
}
get_device_info_generic_name() {
local val=""
local permissions=""
case "$1" in
InternetGatewayDevice.DeviceInfo.ModelName|\
InternetGatewayDevice.DeviceInfo.Description|\
InternetGatewayDevice.DeviceInfo.ModemFirmwareVersion|\
InternetGatewayDevice.DeviceInfo.EnabledOptions|\
InternetGatewayDevice.DeviceInfo.AdditionalHardwareVersion|\
InternetGatewayDevice.DeviceInfo.AdditionalSoftwareVersion|\
InternetGatewayDevice.DeviceInfo.SpecVersion|\
InternetGatewayDevice.DeviceInfo.FirstUseDate)
permissions="0"
freecwmp_output "$1" "" "$permissions"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.DeviceInfo.ProvisioningCode)
permissions="1"
freecwmp_output "$1" "" "$permissions"
return $FAULT_CPE_NO_FAULT
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_device_info_generic_notification() {
check_parameter_device_info_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
local val
freecwmp_get_parameter_notification "val" "$1"
freecwmp_output "$1" "$val"
return 0
}
set_device_info_generic() {
check_parameter_device_info_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
freecwmp_set_parameter_value "$1" "$2"
return $FAULT_CPE_NO_FAULT
}
set_device_info_generic_notification() {
check_parameter_device_info_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
freecwmp_set_parameter_notification "$1" "$2"
return $FAULT_CPE_NO_FAULT
}
add_device_info() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_device_info() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
add_device_info_generic() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_device_info_generic() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
}

View file

@ -1,367 +0,0 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# TODO: LIMITATIONS: we only handle one device router at the moment
# ordering of routes:
# 1) inactive routes found in uci network config file
# 2) active routes found in uci network config file
# 3) active routes but not found in uci network config file
FREECWMP_DEVICE_ROUTES="/tmp/freecwmp_routes"
FREECWMP_DEVICE_ROUTES_STATIC="/tmp/freecwmp_routes_static"
FREECWMP_DEVICE_ROUTES_DYNAMIC="/tmp/freecwmp_routes_dynamic"
get_device_routing_ipv4_check_route() {
local __uci_target=$1
local __uci_gateway=$2
local __uci_netmask=$3
local __active=0
# TODO: remove this file
echo -n > $FREECWMP_DEVICE_ROUTES_DYNAMIC
local __route_target
local __route_gateway
local __route_netmask
local line
while read line
do
__route_target=`echo -n $line | awk '{ print $1 }'`
__route_gateway=`echo -n $line | awk '{ print $2 }'`
__route_netmask=`echo -n $line | awk '{ print $3 }'`
if [ "x$__uci_target" != "x$__route_target" ]; then
echo $line >> $FREECWMP_DEVICE_ROUTES_DYNAMIC
continue
fi
if [ "x$__uci_gateway" != "x$__route_gateway" ]; then
echo $line >> $FREECWMP_DEVICE_ROUTES_DYNAMIC
continue
fi
if [ "x$__uci_netmask" != "x$__route_netmask" ]; then
echo $line >> $FREECWMP_DEVICE_ROUTES_DYNAMIC
continue
fi
echo $line >> $FREECWMP_DEVICE_ROUTES_STATIC
__active=1
done < $FREECWMP_DEVICE_ROUTES
eval "export -- \"$4=\"\"$__active\"\"\""
}
get_device_routing_ipv4_ordering_information() {
local _static=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show network 2> /dev/null | grep '=route$' | wc -l`
local _active=`cat $FREECWMP_DEVICE_ROUTES | wc -l`
local _inactive=0
local _uci_target
local _uci_gateway
local _uci_netmask
local _route_active
local i
let local _count=$_static-1
for i in `seq 0 $_count`
do
_uci_target=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].target 2> /dev/null`
_uci_gateway=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].gateway 2> /dev/null`
_uci_netmask=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].netmask 2> /dev/null`
get_device_routing_ipv4_check_route "$_uci_target" "$_uci_gateway" "$_uci_netmask" "_route_active"
if [ $_route_active -ne 1 ]; then
let _inactive=$_inactive+1
fi
done
let local _total=$_active+$_inactive
eval "export -- \"$1=\"\"$_total\"\"\""
eval "export -- \"$2=\"\"$_active\"\"\""
eval "export -- \"$3=\"\"$_inactive\"\"\""
eval "export -- \"$4=\"\"$_static\"\"\""
}
get_device_routing() {
local parameter=$1
case "$parameter" in
Device.Routing.RouterNumberOfEntries)
freecwmp_output "$parameter" "1"
return
;;
esac
local rc
local num
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.Enable" "rc" "num"
if [ $rc -eq 0 ]; then
local val
if [ $num -eq 1 ]; then
val="1"
else
val="0"
fi
freecwmp_output "$parameter" "$val"
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.Status" "rc" "num"
if [ $rc -eq 0 ]; then
local val
if [ $num -eq 1 ]; then
val="Enabled"
else
val="Disabled"
fi
freecwmp_output "$parameter" "$val"
return
fi
# TODO: Device.Routing.Router.{i}.Alias (alias support does not exist)
# TODO: remove this file
route -n | grep -v '^Kernel ' | grep -v '^Destination ' > $FREECWMP_DEVICE_ROUTES
local total
local active
local inactive
local static
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4ForwardingNumberOfEntries" "rc" "num"
if [ $rc -eq 0 ]; then
if [ "x$num" == "x1" ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
else
return
fi
freecwmp_output "$parameter" "$total"
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv6ForwardingNumberOfEntries" "rc" "num"
if [ $rc -eq 0 ]; then
local val
if [ $num -eq 1 ]; then
val=0
else
return
fi
freecwmp_output "$parameter" "$val"
return
fi
# TODO: Device.Routing.Router.{i}.IPv4Forwarding.{i}.Enable
# TODO: routes can not be disabled, they should be disabled by default
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4Forwarding.{i}.Status" "rc" "num"
if [ $rc -eq 0 ]; then
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
if [ $num1 -eq 1 ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
if [ $num2 -le 0 ]; then
return
fi
if [ $num2 -gt $total ]; then
return
fi
if [ $num2 -gt $static ]; then
freecwmp_output "$parameter" "Enabled"
return
fi
if [ $num2 -le $inactive ]; then
freecwmp_output "$parameter" "Error: not active but enabled"
return
fi
if [ $num2 -le $static ]; then
freecwmp_output "$parameter" "Enabled"
return
fi
else
return
fi
fi
# TODO: Device.Routing.Router.{i}.IPv4Forwarding.{i}.Alias (alias support does not exist)
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4Forwarding.{i}.StaticRoute" "rc" "num"
if [ $rc -eq 0 ]; then
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
if [ $num1 -eq 1 ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
if [ $num2 -le 0 ]; then
return
fi
if [ $num2 -gt $total ]; then
return
fi
if [ $num2 -gt $static ]; then
freecwmp_output "$parameter" "0"
return
fi
if [ $num2 -le $static ]; then
freecwmp_output "$parameter" "1"
return
fi
else
return
fi
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestIPAddress" "rc" "num"
if [ $rc -eq 0 ]; then
local target
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
if [ $num1 -eq 1 ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
if [ $num2 -le 0 ]; then
return
fi
if [ $num2 -gt $total ]; then
return
fi
if [ $num2 -gt $static ]; then
let local _num=$num2-$static
local _sed_cmd=`echo -n \'$_num; echo p\'`
target=`eval sed -n $_sed_cmd $FREECWMP_DEVICE_ROUTES_DYNAMIC | awk '{ print $1 }'`
elif [ $num2 -le $static ]; then
let local i=$static-$num2
target=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].target 2> /dev/null`
fi
freecwmp_output "$parameter" "$target"
return
else
return
fi
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4Forwarding.{i}.DestSubnetMask" "rc" "num"
if [ $rc -eq 0 ]; then
local netmask
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
if [ $num1 -eq 1 ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
if [ $num2 -le 0 ]; then
return
fi
if [ $num2 -gt $total ]; then
return
fi
if [ $num2 -gt $static ]; then
let local _num=$num2-$static
local _sed_cmd=`echo -n \'$_num; echo p\'`
netmask=`eval sed -n $_sed_cmd $FREECWMP_DEVICE_ROUTES_DYNAMIC | awk '{ print $3 }'`
elif [ $num2 -le $static ]; then
let local i=$static-$num2
netmask=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].netmask 2> /dev/null`
fi
freecwmp_output "$parameter" "$netmask"
return
else
return
fi
fi
# TODO: Device.Routing.Router.{i}.IPv4Forwarding.{i}.ForwardingPolicy
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4Forwarding.{i}.GatewayIPAddress" "rc" "num"
if [ $rc -eq 0 ]; then
local gateway
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
if [ $num1 -eq 1 ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
if [ $num2 -le 0 ]; then
return
fi
if [ $num2 -gt $total ]; then
return
fi
if [ $num2 -gt $static ]; then
let local _num=$num2-$static
local _sed_cmd=`echo -n \'$_num; echo p\'`
gateway=`eval sed -n $_sed_cmd $FREECWMP_DEVICE_ROUTES_DYNAMIC | awk '{ print $2 }'`
elif [ $num2 -le $static ]; then
let local i=$static-$num2
gateway=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].gateway 2> /dev/null`
fi
freecwmp_output "$parameter" "$gateway"
return
else
return
fi
fi
# TODO: Device.Routing.Router.{i}.IPv4Forwarding.{i}.Interface
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4Forwarding.{i}.Origin" "rc" "num"
if [ $rc -eq 0 ]; then
local val
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
if [ $num1 -eq 1 ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
if [ $num2 -le 0 ]; then
return
fi
if [ $num2 -gt $total ]; then
return
fi
if [ $num2 -gt $static ]; then
val="Unknown"
elif [ $num2 -le $static ]; then
val="Static"
fi
freecwmp_output "$parameter" "$val"
return
else
return
fi
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Routing.Router.{i}.IPv4Forwarding.{i}.ForwardingMetric" "rc" "num"
if [ $rc -eq 0 ]; then
local metric
local num1=`echo $num | awk '{ print $1 }'`
local num2=`echo $num | awk '{ print $2 }'`
if [ $num1 -eq 1 ]; then
get_device_routing_ipv4_ordering_information "total" "active" "inactive" "static"
if [ $num2 -le 0 ]; then
return
fi
if [ $num2 -gt $total ]; then
return
fi
if [ $num2 -gt $static ]; then
let local _num=$num2-$static
local _sed_cmd=`echo -n \'$_num; echo p\'`
metric=`eval sed -n $_sed_cmd $FREECWMP_DEVICE_ROUTES_DYNAMIC | awk '{ print $5 }'`
elif [ $num2 -le $static ]; then
let local i=$static-$num2
metric=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get network.@route[$i].metric 2> /dev/null`
fi
freecwmp_output "$parameter" "$metric"
return
else
return
fi
fi
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_device_routing_name() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
get_device_routing_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_device_routing() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_device_routing_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
add_device_routing() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_device_routing() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }

View file

@ -1,141 +0,0 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_device_users() {
local parameter="$1"
case "$parameter" in
Device.Users.UserNumberOfEntries)
local val=`wc -l /etc/passwd | awk '{ print $1 }'`
freecwmp_value_output "$parameter" "$val"
return
;;
esac
local rc
local num
# TODO: Device.Users.User.{i}.Alias (alias support does not exist)
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Enable" "rc" "num"
if [ $rc -eq 0 ]; then
# TODO: this is very system dependent, for now just look at users shell
local sed_cmd=`echo -n \'$num; echo p\'`
local val=`eval sed -n $sed_cmd /etc/passwd | grep -v '/bin/false' | wc -l`
freecwmp_value_output "$parameter" "$val"
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.RemoteAccessCapable" "rc" "num"
if [ $rc -eq 0 ]; then
# TODO: this is very system dependent, for now just look at users shell
local sed_cmd=`echo -n \'$num; echo p\'`
local val=`eval sed -n $sed_cmd /etc/passwd | grep -v '/bin/false' | wc -l`
freecwmp_value_output "$parameter" "$val"
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Username" "rc" "num"
if [ $rc -eq 0 ]; then
local sed_cmd=`echo -n \'$num; echo p\'`
local val=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $1 }'`
freecwmp_value_output "$parameter" "$val"
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Password" "rc" "num"
if [ $rc -eq 0 ]; then
# if we *really* wanted to get the password we could do it like this
# local sed_cmd=`echo -n \'$num; echo p\'`
# local val=`eval sed -n $sed_cmd /etc/shadow | awk -F ':' '{ print $2 }'`
# freecwmp_value_output "$parameter" "$val"
freecwmp_value_output "$parameter" ""
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Language" "rc" "num"
if [ $rc -eq 0 ]; then
freecwmp_value_output "$parameter" ""
return
fi
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
set_device_users() {
local parameter="$1"
local value="$2"
local rc
local num
# TODO: Device.Users.User.{i}.Alias (alias support does not exist)
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Enable" "rc" "num"
if [ $rc -eq 0 ]; then
# TODO: this is very system dependent, for now just look at users shell
local val
if [ "$value" = "1" ]; then
val="/bin/ash"
else
val="/bin/false"
fi
local sed_cmd
sed_cmd=`echo -n \'$num; echo p\'`
local orig=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $7 }'`
sed_cmd=`echo -n \'$num; echo s%:$orig%:$val%\'`
eval sed -i $sed_cmd /etc/passwd
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.RemoteAccessCapable" "rc" "num"
if [ $rc -eq 0 ]; then
# TODO: this is very system dependent, for now just look at users shell
local val
if [ "$value" = "1" ]; then
val="/bin/ash"
else
val="/bin/false"
fi
local sed_cmd
sed_cmd=`echo -n \'$num; echo p\'`
local orig=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $7 }'`
sed_cmd=`echo -n \'$num; echo s%:$orig%:$val%\'`
eval sed -i $sed_cmd /etc/passwd
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Username" "rc" "num"
if [ $rc -eq 0 ]; then
local sed_cmd
sed_cmd=`echo -n \'$num; echo p\'`
local orig=`eval sed -n $sed_cmd /etc/passwd | awk -F ':' '{ print $1 }'`
sed_cmd=`echo -n \'$num; echo s%$orig:%$value:%\'`
eval sed -i $sed_cmd /etc/passwd
return
fi
freecwmp_parse_formated_parameter "$parameter" "Device.Users.User.{i}.Password" "rc" "num"
if [ $rc -eq 0 ]; then
local sed_cmd
sed_cmd=`echo -n \'$num; echo p\'`
local orig=`eval sed -n $sed_cmd /etc/shadow | awk -F ':' '{ print $2 }'`
sed_cmd=`echo -n \'$num; echo s%:$orig:%:$value:%\'`
eval sed -i $sed_cmd /etc/shadow
return
fi
# TODO: Device.Users.User.{i}.Language (why? look at the get value function for this parameter)
}
get_device_users_name() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
get_device_users_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_device_users() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_device_users_notification() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
add_device_users() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_device_users() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }

File diff suppressed because it is too large Load diff

View file

@ -2,216 +2,10 @@
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_management_server_url() {
local tmp=${FLAGS_value}
FLAGS_value=${FLAGS_TRUE}
FLAGS_value=$tmp
local val=""
local permissions=""
local parm="InternetGatewayDevice.ManagementServer.URL"
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.acs.url 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_url() {
local parm="InternetGatewayDevice.ManagementServer.URL"
local type="xsd:string"
case "$action" in
set_value)
local url=$1
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.acs.url="$url"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
freecwmp_notify "$parm" "$url" "$type"
;;
set_notification)
local val=$1
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_username() {
local val=""
local permissions=""
local parm="InternetGatewayDevice.ManagementServer.Username"
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.acs.userid 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_username() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.Username"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.acs.userid="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_password() {
local val=""
local permissions=""
local parm="InternetGatewayDevice.ManagementServer.Password"
case "$action" in
get_value)
# returned value must be empty
val=""
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_password() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.Password"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.acs.passwd="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_parameter_key() {
local val=""
local permissions=""
local parm="InternetGatewayDevice.ManagementServer.ParameterKey"
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.acs.ParameterKey 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_parameter_key() {
local parm="InternetGatewayDevice.ManagementServer.ParameterKey"
local type="xsd:string"
local val="$1"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.acs.ParameterKey="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
freecwmp_notify "$parm" "$val" "$type"
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_periodic_inform_enable() {
local val=""
local type="xsd:boolean"
local parm="InternetGatewayDevice.ManagementServer.PeriodicInformEnable"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.acs.periodic_inform_enable`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions" "$type"
}
set_management_server_periodic_inform_enable() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.PeriodicInformEnable"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.acs.periodic_inform_enable="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_periodic_inform_interval() {
local val=""
local type="xsd:unsignedInt"
local parm="InternetGatewayDevice.ManagementServer.PeriodicInformInterval"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.acs.periodic_inform_interval 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions" "$type"
}
set_management_server_periodic_inform_interval() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.PeriodicInformInterval"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.acs.periodic_inform_interval="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
get_management_server_connection_request_url() {
local val
local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestURL"
local permissions=""
case "$action" in
get_value)
if [ -z "$default_management_server_connection_request_url" ]; then
local tmp_value=${FLAGS_value}
FLAGS_value=${FLAGS_TRUE}
@ -228,113 +22,22 @@ case "$action" in
else
val=$default_management_server_connection_request_url
fi
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
echo $val
}
get_management_server_connection_request_username() {
local val=""
local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.cpe.userid 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_connection_request_username() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestUsername"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.cpe.userid="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_connection_request_password() {
local val=""
local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword"
local permissions=""
case "$action" in
get_value)
# returned value must be empty
val=""
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_connection_request_password() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.cpe.passwd="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
# TODO: InternetGatewayDevice.ManagementServer.PeriodicInformTime
get_management_server_periodic_inform_time() {
local val=""
local type="xsd:dateTime"
local parm="InternetGatewayDevice.ManagementServer.PeriodicInformTime"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.acs.periodic_inform_time`
val=`$UCI_GET cwmp.acs.periodic_inform_time`
if [ "$val" != "0" -a "$val" != "" ];then
val=`date -d @$val +"%Y-%m-%dT%H:%M:%S.000Z"`
else
val="0001-01-01T00:00:00Z"
fi
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions" "$type"
echo "$val"
}
set_management_server_periodic_inform_time() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.PeriodicInformTime"
case "$action" in
set_value)
local val="$1"
if [ "$val" != "0001-01-01T00:00:00Z" ];then
val=`echo $val|sed 's/Z//g'`
val=`echo $val|sed 's/T/ /g'`
@ -343,595 +46,39 @@ case "$action" in
else
val=0
fi
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.acs.periodic_inform_time="$val"
$UCI_SET cwmp.acs.periodic_inform_time="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_x_freecwmp_org__acs_scheme() {
local val=""
local permissions=""
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Scheme"
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.@acs[0].scheme 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_x_freecwmp_org__acs_scheme() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Scheme"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.@acs[0].scheme="$val"
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_x_freecwmp_org__acs_hostname() {
local val=""
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Hostname"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.@acs[0].hostname 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_x_freecwmp_org__acs_hostname() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Hostname"
case "$action" in
set_value)
if [ -z "$default_management_server_acs_hostname" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.@acs[0].hostname="$val"
else
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.@acs[0].hostname="$default_management_server_acs_hostname"
fi
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_x_freecwmp_org__acs_port() {
local val=""
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Port"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.@acs[0].port 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_x_freecwmp_org__acs_port() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Port"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.@acs[0].port="$val"
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_x_freecwmp_org__acs_path() {
local val=""
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Path"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.@acs[0].path 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_x_freecwmp_org__acs_path() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__ACS_Path"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.@acs[0].path="$val"
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server_x_freecwmp_org__connection_request_port() {
local val=""
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__Connection_Request_Port"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.@local[0].port 2> /dev/null`
;;
get_name)
permissions="1"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions"
}
set_management_server_x_freecwmp_org__connection_request_port() {
local val=$1
local parm="InternetGatewayDevice.ManagementServer.X_freecwmp_org__Connection_Request_Port"
case "$action" in
set_value)
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.@local[0].port="$val"
;;
set_notification)
freecwmp_set_parameter_notification "$parm" "$val"
;;
esac
}
get_management_server() {
case "$1" in
InternetGatewayDevice.)
get_management_server_url
get_management_server_username
get_management_server_password
get_management_server_periodic_inform_enable
get_management_server_periodic_inform_interval
get_management_server_periodic_inform_time
get_management_server_connection_request_url
get_management_server_connection_request_username
get_management_server_connection_request_password
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.)
get_management_server_url
get_management_server_username
get_management_server_password
get_management_server_periodic_inform_enable
get_management_server_periodic_inform_interval
get_management_server_periodic_inform_time
get_management_server_connection_request_url
get_management_server_connection_request_username
get_management_server_connection_request_password
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.URL)
get_management_server_url
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Username)
get_management_server_username
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Password)
get_management_server_password
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformEnable)
get_management_server_periodic_inform_enable
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformInterval)
get_management_server_periodic_inform_interval
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformTime)
get_management_server_periodic_inform_time
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestURL)
get_management_server_connection_request_url
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestUsername)
get_management_server_connection_request_username
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestPassword)
get_management_server_connection_request_password
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ParameterKey)
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_management_server_name() {
case "$1" in
InternetGatewayDevice.)
freecwmp_output "InternetGatewayDevice.ManagementServer." "" "0"
if [ "$2" = "0" ]; then
get_management_server_url
get_management_server_username
get_management_server_password
get_management_server_periodic_inform_enable
get_management_server_periodic_inform_interval
get_management_server_periodic_inform_time
get_management_server_connection_request_url
get_management_server_connection_request_username
get_management_server_connection_request_password
get_management_server_parameter_key
fi
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.)
freecwmp_output "InternetGatewayDevice.ManagementServer." "" "0"
get_management_server_url
get_management_server_username
get_management_server_password
get_management_server_periodic_inform_enable
get_management_server_periodic_inform_interval
get_management_server_periodic_inform_time
get_management_server_connection_request_url
get_management_server_connection_request_username
get_management_server_connection_request_password
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.URL)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_url
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Username)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_username
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Password)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_password
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformEnable)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_periodic_inform_enable
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformInterval)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_periodic_inform_interval
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformTime)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_periodic_inform_time
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestURL)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_connection_request_url
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestUsername)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_connection_request_username
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestPassword)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_connection_request_password
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ParameterKey)
if [ "$2" = "1" ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_management_server_notification() {
case "$1" in
InternetGatewayDevice.)
get_management_server_url
get_management_server_username
get_management_server_password
get_management_server_periodic_inform_enable
get_management_server_periodic_inform_interval
get_management_server_periodic_inform_time
get_management_server_connection_request_url
get_management_server_connection_request_username
get_management_server_connection_request_password
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.)
get_management_server_url
get_management_server_username
get_management_server_password
get_management_server_periodic_inform_enable
get_management_server_periodic_inform_interval
get_management_server_periodic_inform_time
get_management_server_connection_request_url
get_management_server_connection_request_username
get_management_server_connection_request_password
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.URL)
get_management_server_url
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Username)
get_management_server_username
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Password)
get_management_server_password
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformEnable)
get_management_server_periodic_inform_enable
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformInterval)
get_management_server_periodic_inform_interval
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformTime)
get_management_server_periodic_inform_time
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestURL)
get_management_server_connection_request_url
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestUsername)
get_management_server_connection_request_username
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestPassword)
get_management_server_connection_request_password
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ParameterKey)
get_management_server_parameter_key
return $FAULT_CPE_NO_FAULT
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
set_management_server() {
case "$1" in
InternetGatewayDevice.ManagementServer.URL)
set_management_server_url "$2"
local uci_name=$1
local val=$2
$UCI_SET $uci_name="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
}
get_cache_InternetGatewayDevice_ManagementServer() {
get_object_cache_generic "InternetGatewayDevice.ManagementServer." "0" "0"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.URL" "1" "$UCI_GET cwmp.acs.url" "set_management_server cwmp.acs.url \$val"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.Username" "1" "$UCI_GET cwmp.acs.userid" "set_management_server cwmp.acs.userid \$val"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.Password" "1" "" "set_management_server cwmp.acs.passwd \$val"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ParameterKey" "1" "$UCI_GET cwmp.acs.ParameterKey" "set_management_server cwmp.acs.ParameterKey \$val" "" "" "0" "1"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformEnable" "1" "$UCI_GET cwmp.acs.periodic_inform_enable" "set_management_server cwmp.acs.periodic_inform_enable \$val" "" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformInterval" "1" "$UCI_GET cwmp.acs.periodic_inform_interval" "set_management_server cwmp.acs.periodic_inform_interval \$val" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformTime" "1" "get_management_server_periodic_inform_time" "set_management_server_periodic_inform_time \$val" "" "xsd:dateTime"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestURL" "0" "get_management_server_connection_request_url" "" "" "" "" "1" "2"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" "1" "$UCI_GET cwmp.cpe.userid" "set_management_server cwmp.cpe.userid \$val"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" "1" "" "set_management_server cwmp.cpe.passwd \$val"
}
get_dynamic_InternetGatewayDevice_ManagementServer() {
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Username)
set_management_server_username "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Password)
set_management_server_password "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformEnable)
set_management_server_periodic_inform_enable "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformInterval)
set_management_server_periodic_inform_interval "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformTime)
set_management_server_periodic_inform_time "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestURL)
set_management_server_connection_request_url "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestUsername)
set_management_server_connection_request_username "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestPassword)
set_management_server_connection_request_password "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ParameterKey)
set_management_server_parameter_key "$2"
return $FAULT_CPE_NO_FAULT
;;
esac
}
add_object_InternetGatewayDevice_ManagementServer() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
set_management_server_notification() {
case "$1" in
InternetGatewayDevice.)
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.URL" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.Username" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.Password" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.PeriodicInformEnable" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.PeriodicInformInterval" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.PeriodicInformTime" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ConnectionRequestURL" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ParameterKey" "0"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.)
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.URL" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.Username" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.Password" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.PeriodicInformEnable" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.PeriodicInformInterval" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.PeriodicInformTime" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ConnectionRequestURL" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" "0"
freecwmp_set_parameter_notification "InternetGatewayDevice.ManagementServer.ParameterKey" "0"
freecwmp_set_parameter_notification "$1" "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.URL)
set_management_server_url "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Username)
set_management_server_username "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.Password)
set_management_server_password "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformEnable)
set_management_server_periodic_inform_enable "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformInterval)
set_management_server_periodic_inform_interval "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.PeriodicInformTime)
set_management_server_periodic_inform_time "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestURL)
set_management_server_connection_request_url "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestUsername)
set_management_server_connection_request_username "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ConnectionRequestPassword)
set_management_server_connection_request_password "$2"
return $FAULT_CPE_NO_FAULT
;;
InternetGatewayDevice.ManagementServer.ParameterKey)
set_management_server_parameter_key "$2"
return $FAULT_CPE_NO_FAULT
;;
esac
delete_object_InternetGatewayDevice_ManagementServer() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
check_parameter_management_server_generic() {
case "$1" in
InternetGatewayDevice.ManagementServer.UpgradesManaged)
return 0
;;
esac
return 1
}
get_management_server_generic() {
check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
freecwmp_get_parameter_value "val" "$1"
freecwmp_output "$1" "$val"
return $FAULT_CPE_NO_FAULT
}
get_management_server_generic_name() {
check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
local permissions="1"
freecwmp_output "$1" "" "$permissions"
return $FAULT_CPE_NO_FAULT
}
get_management_server_generic_notification() {
check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
local val
freecwmp_get_parameter_notification "val" "$1"
freecwmp_output "$1" "$val"
return $FAULT_CPE_NO_FAULT
}
set_management_server_generic() {
check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
freecwmp_set_parameter_value "$1" "$2"
return $FAULT_CPE_NO_FAULT
}
set_management_server_generic_notification() {
check_parameter_management_server_generic "$1" ; _tmp=$? ; if [ "$_tmp" -eq 1 ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
freecwmp_set_parameter_notification "$1" "$2"
return $FAULT_CPE_NO_FAULT
}
add_management_server() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_management_server() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
add_management_server_generic() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_management_server_generic() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }

View file

@ -1,41 +0,0 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_misc_cpu_usage() {
local val=`uptime | awk -F'average: ' '{ print $2 }' | awk -F',' '{ print $1 }' | awk -F'.' '{ print $2 }'`
freecwmp_output "Device.DeviceInfo.ProcessStatus.CPUUsage" "$val"
}
get_misc_process_number() {
local val=`ps | grep -v COMMAND | wc -l`
local type="xsd:unsignedInt"
freecwmp_output "Device.DeviceInfo.ProcessStatus.ProcessNumberOfEntries" "$val" "" "$type"
}
get_misc() {
case "$1" in
Device.DeviceInfo.ProcessStatus.CPUUsage)
get_misc_cpu_usage
return $FAULT_CPE_NO_FAULT
;;
Device.DeviceInfo.ProcessStatus.ProcessNumberOfEntries)
get_misc_process_number
return $FAULT_CPE_NO_FAULT
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_misc_name () { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
get_misc_notification () { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_misc() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
set_misc_notification () { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
add_misc() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }
delete_misc() { return $FAULT_CPE_INVALID_PARAMETER_NAME; }

23
scripts/functions/models Normal file
View file

@ -0,0 +1,23 @@
#!/bin/sh
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
#InternetGatewayDevice.
get_cache_InternetGatewayDevice() {
get_object_cache_generic "InternetGatewayDevice." "0" "0"
}
get_dynamic_InternetGatewayDevice() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
#Device.
#To be added

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,3 +0,0 @@
#!/bin/sh
# Copyright (C) 2011 Luka Perkov <freecwmp@lukaperkov.net>

View file

@ -4,7 +4,7 @@
usage()
{
echo "Usage: $0 <strength> <passphrase>"
echo "-<strength> Indicate the WEP KEY strength to generate. Should be 64 or 128"
echo "<strength> Indicate the WEP KEY strength to generate. Should be 64 or 128"
echo "<passphrase> Indicate the passphrase used to generate the WEP KEY"
echo "$0 -h display this help"
}

17
xml.c
View file

@ -729,6 +729,7 @@ int cwmp_rpc_acs_destroy_data_transfer_complete(struct session *session, struct
FREE(p->command_key);
FREE(p->start_time);
FREE(p->complete_time);
FREE(p->old_software_version);
}
FREE(rpc->extra_data);
return 0;
@ -1857,7 +1858,6 @@ int cwmp_launch_download(struct download *pdownload, struct transfer_complete **
p->fault_code = error;
}
bkp_session_insert_transfer_complete(p);
*ptransfer_complete = p;
return error;
@ -1873,6 +1873,7 @@ void *thread_cwmp_rpc_cpe_download (void *v)
struct transfer_complete *ptransfer_complete;
long int time_of_grace = 3600,timeout;
char *fault_code;
struct parameter_container *parameter_container;
thread_download_is_working = true;
while (list_download.next!=&(list_download))
@ -1914,18 +1915,29 @@ void *thread_cwmp_rpc_cpe_download (void *v)
error = cwmp_launch_download(pdownload,&ptransfer_complete);
if(error != FAULT_CPE_NO_FAULT)
{
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
cwmp_root_cause_TransferComplete (cwmp,ptransfer_complete);
bkp_session_delete_transfer_complete(ptransfer_complete);
}
else
{
external_get_action("value", DM_SOFTWARE_VERSION_PATH, NULL);
external_handle_action(cwmp_handle_getParamValues);
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if ((!parameter_container->fault_code || parameter_container->fault_code[0] != '9') &&
strcmp(parameter_container->name, DM_SOFTWARE_VERSION_PATH) == 0)
{
ptransfer_complete->old_software_version = strdup(parameter_container->data);
}
external_free_list_parameter();
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
external_apply("download", pdownload->file_type);
external_handle_action(cwmp_handle_downloadFault);
external_fetch_downloadFaultResp(&fault_code);
if(fault_code != NULL)
{
external_exit();
if(fault_code[0]=='9')
{
for(i=1;i<__FAULT_CPE_MAX;i++)
@ -1950,6 +1962,7 @@ void *thread_cwmp_rpc_cpe_download (void *v)
cwmp_root_cause_TransferComplete (cwmp,ptransfer_complete);
}
}
external_exit();
pthread_mutex_unlock (&(cwmp->mutex_session_send));
pthread_cond_signal (&(cwmp->threshold_session_send));
pthread_mutex_lock (&mutex_download);