diff --git a/backupSession.c b/backupSession.c index 7b7c824..8bb961c 100644 --- a/backupSession.c +++ b/backupSession.c @@ -663,7 +663,7 @@ void bkp_session_insert_du_state_change_complete(struct du_state_change_complete struct opresult *p; list_for_each_entry(p, &(pdu_state_change_complete->list_opresult), list) { n = bkp_session_insert(b,"opresult",NULL); - sprintf(resolved,"%b",p->resolved); + sprintf(resolved,"%d",p->resolved); sprintf(fault_code,"%d",p->fault); bkp_session_insert(n,"uuid",p->uuid); bkp_session_insert(n,"du_ref",p->du_ref); diff --git a/bin/Makefile.am b/bin/Makefile.am index e2baba1..5078429 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -1,23 +1,10 @@ -bin_PROGRAMS = icwmpd -CWMP_VERSION = 3.0 +CWMP_VERSION = 3.0.0 +LIB_DATAMODEL_VERSION = 3:0:0 -icwmpd_SOURCES = \ - ../backupSession.c \ - ../config.c \ - ../cwmp.c \ - ../diagnostic.c \ - ../digestauth.c \ - ../event.c \ - ../external.c \ - ../http.c \ - ../jshn.c \ - ../log.c \ +lib_LTLIBRARIES = libdatamodel.la + +libdatamodel_la_SOURCES = \ ../md5.c \ - ../netlink.c \ - ../time.c \ - ../ubus.c \ - ../xml.c \ - ../zlib.c \ ../dm/dmcwmp.c \ ../dm/dmentry.c \ ../dm/dmmem.c \ @@ -28,29 +15,23 @@ icwmpd_SOURCES = \ ../dm/wepkey.c \ ../dm/dmtree/common/deviceinfo.c \ ../dm/dmtree/common/managementserver.c \ - ../dm/dmtree/common/root.c \ + ../dm/dmtree/common/softwaremodules.c \ ../dm/dmtree/common/times.c \ ../dm/dmtree/common/upnp.c \ - ../dm/dmtree/common/voice_services.c \ - ../dm/dmtree/common/x_inteno_se_ice.c \ - ../dm/dmtree/common/x_inteno_se_igmp.c \ + ../dm/dmtree/common/voice_services.c \ + ../dm/dmtree/common/x_inteno_se_ice.c \ + ../dm/dmtree/common/x_inteno_se_igmp.c \ ../dm/dmtree/common/x_inteno_se_ipacccfg.c \ ../dm/dmtree/common/x_inteno_se_logincfg.c \ ../dm/dmtree/common/x_inteno_se_power_mgmt.c \ - ../dm/dmtree/common/softwaremodules.c \ - ../dm/dmtree/common/x_inteno_se_owsd.c \ + ../dm/dmtree/common/x_inteno_syslog.c \ ../dm/dmtree/common/x_inteno_se_dropbear.c \ + ../dm/dmtree/common/x_inteno_se_owsd.c \ ../dm/dmtree/common/x_inteno_se_buttons.c \ - ../dm/dmtree/common/x_inteno_syslog.c - -if XMPP_ENABLE -icwmpd_SOURCES += \ - ../dm/dmtree/common/xmpp.c \ - ../xmpp_cr.c -endif + ../dm/dmtree/common/root.c if DATAMODEL_TR098 -icwmpd_SOURCES += \ +libdatamodel_la_SOURCES += \ ../dm/dmtree/tr098/lan_interfaces.c \ ../dm/dmtree/tr098/landevice.c \ ../dm/dmtree/tr098/layer_2_bridging.c \ @@ -63,7 +44,7 @@ icwmpd_SOURCES += \ ../dm/dmtree/tr098/layer_3_forwarding.c endif if DATAMODEL_TR181 -icwmpd_SOURCES += \ +libdatamodel_la_SOURCES += \ ../dm/dmtree/tr181/wifi.c \ ../dm/dmtree/tr181/ethernet.c \ ../dm/dmtree/tr181/wan.c \ @@ -75,6 +56,74 @@ icwmpd_SOURCES += \ ../dm/dmtree/tr181/nat.c \ ../dm/dmtree/tr181/routing.c endif + +if UPNP_TR064 +libdatamodel_la_SOURCES += \ + ../dm/dmtree/upnp/upnp_deviceinfo.c \ + ../dm/dmtree/upnp/upnp_configuration.c \ + ../dm/dmtree/upnp/upnp_monitoring.c \ + ../dm/dmtree/upnp/upnp_common.c +endif + +libdatamodel_la_CFLAGS = \ + $(AM_CFLAGS) \ + $(LIBUCI_CFLAGS) \ + $(LIBUBOX_CFLAGS) \ + $(LIBUBUS_CFLAGS) + +libdatamodel_la_LDFLAGS = \ + $(AM_LDFLAGS) \ + $(LIBUCI_LDFLAGS) \ + $(LIBUBOX_LDFLAGS) \ + $(LIBUBUS_LDFLAGS) \ + -share \ + -version-info $(LIB_DATAMODEL_VERSION) + +libdatamodel_la_LIBADD = \ + $(AM_LIBS) \ + $(LIBUCI_LIBS) \ + $(LIBUBOX_LIBS) \ + $(LIBUBUS_LIBS) \ + $(LIBJSON_LIBS) \ + $(LBLOBMSG_LIBS) + +libdatamodel_la_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" +libdatamodel_la_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" + +libdatamodel_la_CFLAGS+=-I../inc/ +libdatamodel_la_CFLAGS+=-I../dm/ +libdatamodel_la_CFLAGS+=-I../dm/dmtree/ +libdatamodel_la_CFLAGS+=-I../dm/dmtree/common +libdatamodel_la_CFLAGS+=-I../dm/dmtree/tr098 +libdatamodel_la_CFLAGS+=-I../dm/dmtree/tr181 +libdatamodel_la_CFLAGS+=-I../dm/dmtree/upnp + +bin_PROGRAMS = icwmpd + +icwmpd_SOURCES = \ + ../backupSession.c \ + ../config.c \ + ../cwmp.c \ + ../digestauth.c \ + ../event.c \ + ../external.c \ + ../http.c \ + ../jshn.c \ + ../log.c \ + ../md5.c \ + ../netlink.c \ + ../time.c \ + ../ubus.c \ + ../xml.c \ + ../diagnostic.c \ + ../zlib.c + +if XMPP_ENABLE +icwmpd_SOURCES += \ + ../dm/dmtree/common/xmpp.c \ + ../xmpp_cr.c +endif + icwmpd_CFLAGS = \ $(AM_CFLAGS) \ $(LIBUCI_CFLAGS) \ @@ -103,12 +152,14 @@ icwmpd_LDADD = \ $(LIBTRACE_LIBS) \ $(LIBZSTREAM_LIBS) \ $(LIBPTHREAD_LIBS) \ + $(LIBSTROPHE_LIBS) \ $(LCRYPTO_LIBS) \ $(LSSL_LIBS) \ $(LIBJSON_LIBS) \ $(LBLOBMSG_LIBS) \ $(LIBZ_LIBS) \ - $(LIBM_LIBS) + $(LIBM_LIBS) \ + -ldatamodel icwmpd_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" icwmpd_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\" @@ -121,3 +172,4 @@ icwmpd_CFLAGS+=-I../dm/dmtree/ icwmpd_CFLAGS+=-I../dm/dmtree/common icwmpd_CFLAGS+=-I../dm/dmtree/tr098 icwmpd_CFLAGS+=-I../dm/dmtree/tr181 +icwmpd_CFLAGS+=-I../dm/dmtree/upnp diff --git a/config.c b/config.c index 0885a4b..2ce0324 100644 --- a/config.c +++ b/config.c @@ -20,12 +20,14 @@ #include #include #include +#include #include "cwmp.h" #include "backupSession.h" #include "xml.h" #include "log.h" #include "dmentry.h" #include "deviceinfo.h" +#include "config.h" typedef enum uci_config_action { CMD_SET, @@ -34,16 +36,47 @@ typedef enum uci_config_action { CMD_DEL, } uci_config_action; -void show_help() +struct option long_options[] = { + {"boot-event", no_argument, NULL, 'b'}, + {"get-rpc-methods", no_argument, NULL, 'g'}, + {"command-input", no_argument, NULL, 'c'}, + {"shell-cli", required_argument, NULL, 'm'}, + {"alias-based-addressing", no_argument, NULL, 'a'}, + {"instance-mode-number", no_argument, NULL, 'N'}, + {"instance-mode-alias", no_argument, NULL, 'A'}, + {"upnp", no_argument, NULL, 'U'}, + {"user-acl", required_argument, NULL, 'u'}, + {"amendment", required_argument, NULL, 'M'}, + {"time-tracking", no_argument, NULL, 't'}, + {"evaluating-test", no_argument, NULL, 'E'}, + {"file", required_argument, NULL, 'f'}, + {"wep", required_argument, NULL, 'w'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {NULL, 0, NULL, 0} +}; + +static void show_help(void) { - fprintf(stdout, "\nUsage: icwmpd [option]\n"); - fprintf(stdout, "-b: this option should be added only in the load phase\n"); - fprintf(stdout, "-m: execute data model commands\n"); - fprintf(stdout, "-w: generate wep keys\n"); - fprintf(stdout, "-g: send GetRPCMethods to ACS\n"); - fprintf(stdout, "-v: show the application version\n"); - fprintf(stdout, "-h: show this help\n\n"); + printf("Usage: icwmpd [OPTIONS]\n"); + printf(" -b, --boot-event (CWMP daemon) Start CWMP with BOOT event\n"); + printf(" -g, --get-rpc-methods (CWMP daemon) Start CWMP with GetRPCMethods request to ACS\n"); + printf(" -c, --command-input (DataModel CLI) Execute data model rpc(s) with commands input\n"); + printf(" -m, --shell-cli (DataModel CLI) Execute data model RPC command directly from shell.\n"); + printf(" -a, --alias-based-addressing (DataModel CLI) Alias based addressing supported\n"); + printf(" -N, --instance-mode-number (DataModel CLI) Instance mode is Number (Enabled by default)\n"); + printf(" -A, --instance-mode-alias (DataModel CLI) Instance mode is Alias\n"); + printf(" -M, --amendment (DataModel CLI) Amendment version (Default amendment version is 2)\n"); + printf(" -U, --upnp (DataModel CLI) Use UPNP data model paths\n"); + printf(" -u, --user-acl (DataModel CLI) user access level. Default: superadmin\n"); + printf(" -t, --time-tracking (DataModel CLI) Tracking time of RPC commands\n"); + printf(" -E, --evaluating-test (DataModel CLI) Evaluating test format\n"); + printf(" -f, --file (DataModel CLI) Execute data model rpc(s) from file\n"); + printf(" -w, --wep (WEP KEY GEN) Generate wep keys\n"); + printf(" -h, --help Display this help text\n"); + printf(" -v, --version Display the version\n"); } + void show_version() { #ifndef CWMP_REVISION @@ -385,84 +418,6 @@ static void uppercase ( char *sPtr ) } } -int get_amd_version_config() -{ - int error; - int a = 0; - char *value = NULL; - struct cwmp *cwmp = &cwmp_main; - if((error = uci_get_value(UCI_CPE_AMD_VERSION ,&value)) == CWMP_OK) - { - cwmp->conf.amd_version = DEFAULT_AMD_VERSION; - if(value != NULL) - { - a = atoi(value) ; - if ( a >= 1 ) { - cwmp->conf.amd_version = a; - } - free(value); - value = NULL; - } - cwmp->conf.supported_amd_version = cwmp->conf.amd_version; - } - else - { - return error; - } - return CWMP_OK; -} - -int get_session_timeout_config() -{ - int error; - int a = 0; - char *value = NULL; - struct cwmp *cwmp = &cwmp_main; - if((error = uci_get_value(UCI_CPE_SESSION_TIMEOUT ,&value)) == CWMP_OK) - { - cwmp->conf.session_timeout = DEFAULT_SESSION_TIMEOUT; - if(value != NULL) - { - a = atoi(value) ; - if ( a >= 1 ) { - cwmp->conf.session_timeout = a; - } - free(value); - value = NULL; - } - } - else - { - return error; - } - return CWMP_OK; -} - -int get_instance_mode_config() -{ - int error; - char *value = NULL; - struct cwmp *cwmp = &cwmp_main; - if((error = uci_get_value(UCI_CPE_INSTANCE_MODE ,&value)) == CWMP_OK) - { - cwmp->conf.instance_mode = DEFAULT_INSTANCE_MODE; - if(value != NULL) - { - if ( 0 == strcmp(value, "InstanceNumber") ) { - cwmp->conf.instance_mode = INSTANCE_MODE_NUMBER; - } else { - cwmp->conf.instance_mode = INSTANCE_MODE_ALIAS; - } - free(value); - value = NULL; - } - } - else - { - return error; - } - return CWMP_OK; -} int get_global_config(struct config *conf) { int error, error2, error3; @@ -970,6 +925,84 @@ int get_global_config(struct config *conf) return CWMP_OK; } +int get_amd_version_config() +{ + int error; + int a = 0; + char *value = NULL; + struct cwmp *cwmp = &cwmp_main; + if((error = uci_get_value(UCI_CPE_AMD_VERSION ,&value)) == CWMP_OK) + { + cwmp->conf.amd_version = DEFAULT_AMD_VERSION; + if(value != NULL) + { + a = atoi(value) ; + if ( a >= 1 ) { + cwmp->conf.amd_version = a; + } + free(value); + value = NULL; + } + cwmp->conf.supported_amd_version = cwmp->conf.amd_version; + } + else + { + return error; + } + return CWMP_OK; +} + +int get_session_timeout_config() +{ + int error; + int a = 0; + char *value = NULL; + struct cwmp *cwmp = &cwmp_main; + if((error = uci_get_value(UCI_CPE_SESSION_TIMEOUT ,&value)) == CWMP_OK) + { + cwmp->conf.session_timeout = DEFAULT_SESSION_TIMEOUT; + if(value != NULL) + { + a = atoi(value) ; + if ( a >= 1 ) { + cwmp->conf.session_timeout = a; + } + free(value); + value = NULL; + } + } + else + { + return error; + } + return CWMP_OK; +} + +int get_instance_mode_config() +{ + int error; + char *value = NULL; + struct cwmp *cwmp = &cwmp_main; + if((error = uci_get_value(UCI_CPE_INSTANCE_MODE ,&value)) == CWMP_OK) + { + cwmp->conf.instance_mode = DEFAULT_INSTANCE_MODE; + if(value != NULL) + { + if ( 0 == strcmp(value, "InstanceNumber") ) { + cwmp->conf.instance_mode = INSTANCE_MODE_NUMBER; + } else { + cwmp->conf.instance_mode = INSTANCE_MODE_ALIAS; + } + free(value); + value = NULL; + } + } + else + { + return error; + } + return CWMP_OK; +} int get_lwn_config(struct config *conf) { int error; @@ -1022,42 +1055,151 @@ int get_lwn_config(struct config *conf) } return CWMP_OK; } + int global_env_init (int argc, char** argv, struct env *env) { - int i,error=0; + unsigned char command_input = 0; + unsigned char from_shell = 0; + unsigned int dmaliassupport = 0; + unsigned int dminstancemode =INSTANCE_MODE_NUMBER; + unsigned int dmamendment = AMD_2; + unsigned int dmtype = DM_CWMP; + struct dmctx dmctx = {0}; - for (i=1;iboot = CWMP_START_BOOT; - break; - case 'g': - env->periodic = CWMP_START_PERIODIC; - break; - case 'm': - dm_entry_cli(argc, argv); - exit(EXIT_SUCCESS); - break; - case 'w': - wepkey_cli(argc, argv); - exit(EXIT_SUCCESS); - break; - case 'v': - show_version(); - exit(EXIT_SUCCESS); - break; - case 'h': - show_help(); - exit(EXIT_SUCCESS); - break; - } - } + char *file = NULL; + char *upnpuser; + char *next; + char *m_argv[64]; + int m_argc; + int c, option_index = 0, iv, idx; - return CWMP_OK; + while ((c = getopt_long(argc, argv, "bgcaNAUtEhvm:u:M:f:w:", long_options, &option_index)) != -1) { + + switch (c) + { + case 'b': + env->boot = CWMP_START_BOOT; + break; + + case 'g': + env->periodic = CWMP_START_PERIODIC; + break; + + case 'c': + command_input = 1; + break; + + case 'a': + dmaliassupport = 1; + break; + + case 'A': + dminstancemode = INSTANCE_MODE_ALIAS; + break; + + case 'M': + iv = atoi(optarg); + if (iv > 0) + dmamendment = (unsigned int)(iv & 0xFF); + break; + + case 'm': + from_shell = 1; + idx = optind - 1; + m_argc = 2; + while(idx < argc) { + next = argv[idx]; + idx++; + if(next[0] != '-') { + m_argv[m_argc++] = next; + } + else + break; + if (m_argc > 63) { + printf("Too many arguments!\n"); + exit(1); + } + } + optind = idx - 1; + break; + + case 'U': + dmtype = DM_UPNP; + break; + + case 'u': + upnpuser = optarg; + if (strcmp(upnpuser, "public") == 0) { + upnp_in_user_mask = DM_PUBLIC_MASK; + } + else if (strcmp(upnpuser, "basic") == 0) { + upnp_in_user_mask = DM_BASIC_MASK; + } + else if (strcmp(upnpuser, "xxxadmin") == 0) { + upnp_in_user_mask = DM_XXXADMIN_MASK; + } + else if (strcmp(upnpuser, "superadmin") == 0) { + upnp_in_user_mask = DM_SUPERADMIN_MASK; + } + break; + + case 'w': + m_argc = 2; + idx = optind - 1; + while(idx < argc) { + next = argv[idx]; + idx++; + if(next[0] != '-') { + m_argv[m_argc++] = next; + } + else + break; + if (m_argc > 2) { + printf("Too many arguments!\n"); + exit(1); + } + } + optind = idx - 1; + wepkey_cli(m_argc, m_argv); + exit(0); + break; + + case 't': + dmcli_timetrack = 1; + break; + + case 'E': + dmcli_timetrack = 1; + dmcli_evaluatetest = 1; + break; + + case 'f': + file = optarg; + break; + + case 'h': + show_help(); + exit(0); + + case 'v': + show_version(); + exit(0); + } + } + + if (from_shell) { + if (!dmaliassupport) + dminstancemode =INSTANCE_MODE_NUMBER; + dm_execute_cli_shell(m_argc, (char**)m_argv, dmtype, dmamendment, dminstancemode); + exit (0); + } + else if (command_input) { + if (!dmaliassupport) + dminstancemode =INSTANCE_MODE_NUMBER; + dm_execute_cli_command(file, dmtype, dmamendment, dminstancemode); + exit (0); + } + return CWMP_OK; } int global_conf_init (struct config *conf) @@ -1088,13 +1230,13 @@ int save_acs_bkp_config(struct cwmp *cwmp) int cwmp_get_deviceid(struct cwmp *cwmp) { struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); cwmp->deviceid.manufacturer = strdup(get_deviceid_manufacturer()); //TODO free cwmp->deviceid.serialnumber = strdup(get_deviceid_serialnumber()); cwmp->deviceid.productclass = strdup(get_deviceid_productclass()); cwmp->deviceid.oui = strdup(get_deviceid_manufactureroui()); cwmp->deviceid.softwareversion = strdup(get_softwareversion()); - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); return CWMP_OK; } @@ -1112,7 +1254,7 @@ int cwmp_get_xmpp_param(struct cwmp *cwmp) { { char *enable; asprintf(&instance, "%d", conf->xmpp_connection_id); - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); char *tmp; asprintf(&tmp, "%s", get_xmpp_server_enable(instance)); //tmp = ; @@ -1140,7 +1282,7 @@ int cwmp_get_xmpp_param(struct cwmp *cwmp) { cwmp->xmpp_param.retry_max_interval = atoi((const char *)get_xmpp_connect_retry_max_interval(instance)); cwmp->xmpp_param.retry_max_interval = (cwmp->xmpp_param.retry_max_interval) ? cwmp->xmpp_param.retry_max_interval : DEFAULT_RETRY_MAX_INTERVAL; } - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); check_xmpp_config(cwmp); } else @@ -1188,13 +1330,12 @@ int cwmp_init(int argc, char** argv,struct cwmp *cwmp) { return error; } - dm_global_init(); cwmp_get_deviceid(cwmp); #ifdef XMPP_ENABLE if (conf->xmpp_enable && conf->xmpp_connection_id > 0) cwmp_get_xmpp_param(cwmp); #endif - dm_entry_load_enabled_notify(); + dm_entry_load_enabled_notify(DM_CWMP, cwmp->conf.amd_version, cwmp->conf.instance_mode); return CWMP_OK; } @@ -1213,6 +1354,6 @@ int cwmp_config_reload(struct cwmp *cwmp) if (conf->xmpp_enable && conf->xmpp_connection_id != 0) cwmp_get_xmpp_param(cwmp); #endif - dm_entry_load_enabled_notify(); + dm_entry_load_enabled_notify(DM_CWMP, cwmp->conf.amd_version, cwmp->conf.instance_mode); return CWMP_OK; } diff --git a/configure.ac b/configure.ac index 7b70f9d..7568b8a 100644 --- a/configure.ac +++ b/configure.ac @@ -10,6 +10,12 @@ AC_ARG_ENABLE(acs, [AS_HELP_STRING([--enable-acs], [specify which ACS is going to be used; there are some optimizations available for HDM and Fusion ACS (default --enable-acs=multi]))],, [AC_DEFINE(ACS_MULTI)]) +AC_ARG_ENABLE(upnptr064, [AS_HELP_STRING([--enable-upnptr064], [enable tr064 upnp feature])], AC_DEFINE(UPNP_TR064),) +AM_CONDITIONAL([UPNP_TR064],[test "x$enable_upnptr064" = "xyes"]) + +AC_ARG_ENABLE(xmpp, [AS_HELP_STRING([--enable-xmpp], [enable xmpp feature])], AC_DEFINE(XMPP_ENABLE),) +AM_CONDITIONAL([XMPP_ENABLE],[test "x$enable_xmpp" = "xyes"]) + AS_IF([test "x$enable_acs" = "xhdm"], [AC_DEFINE(ACS_HDM)]) AS_IF([test "x$enable_acs" = "xfusion"], [AC_DEFINE(ACS_FUSION)]) AS_IF([test "x$enable_acs" = "xmulti"], [AC_DEFINE(ACS_MULTI)]) @@ -32,19 +38,20 @@ AC_ARG_ENABLE(debug, [AS_HELP_STRING([--enable-debug], [enable debugging message AC_ARG_ENABLE(devel, [AS_HELP_STRING([--enable-devel], [enable development messages])], AC_DEFINE(WITH_DEV_DEBUG),) AC_ARG_ENABLE(dummy_mode, [AS_HELP_STRING([--enable-dummy-mode], [enable dummy mode])], AC_DEFINE(DUMMY_MODE),) -AC_ARG_ENABLE(xmpp, [AS_HELP_STRING([--enable-xmpp], - [enable xmpp; (default --enable-xmpp=disable]))],,) - -AM_CONDITIONAL([XMPP_DISABLE], [test "x$enable_xmpp" = "xdisable" ]) -AM_CONDITIONAL([XMPP_ENABLE], [test "x$enable_xmpp" = "xenable" ]) # checks for programs AC_PROG_CC AM_PROG_CC_C_O +LT_INIT +AC_ENABLE_SHARED # checks for libraries LIBPTHREAD_LIBS='-lpthread' AC_SUBST([LIBPTHREAD_LIBS]) +# checks for libraries +LIBSTROPHE_LIBS='-lstrophe' +AC_SUBST([LIBSTROPHE_LIBS]) + LIBZ_LIBS='-lz' AC_SUBST([LIBZ_LIBS]) @@ -112,13 +119,6 @@ AM_COND_IF([DATAMODEL_TR181], [ AC_DEFINE(DATAMODEL_TR181) ]) -AM_COND_IF([XMPP_DISABLE], [ - AC_DEFINE(XMPP_DISABLE) -]) - -AM_COND_IF([XMPP_ENABLE], [ - AC_DEFINE(XMPP_ENABLE) -]) AM_COND_IF([HTTP_CURL], [ AC_DEFINE(HTTP_CURL) PKG_CHECK_MODULES(LIBCURL, [libcurl]) diff --git a/cwmp.c b/cwmp.c index b8493ac..2dcc3d2 100644 --- a/cwmp.c +++ b/cwmp.c @@ -26,53 +26,27 @@ #include "ubus.h" #include "diagnostic.h" #include "xmpp_cr.h" +#include "config.h" #ifdef XMPP_ENABLE -#include +#include "/home/piva/projects/inteno-tr064/iop-cc/staging_dir/target-mips_mips32_uClibc-0.9.33.2/usr/include/strophe.h" #endif #include struct cwmp cwmp_main = {0}; -int ip_version = 4; -LIST_HEAD(list_execute_end_session); - -int dm_add_end_session(void(*function)(int a, void *d), int action, void *data) +int cwmp_dm_ctx_init(struct cwmp *cwmp, struct dmctx *ctx) { - struct execute_end_session *execute_end_session; - - execute_end_session = calloc (1,sizeof(struct execute_end_session)); - if (execute_end_session == NULL) - { - return -1; - } - execute_end_session->action = action; - execute_end_session->data = data; - execute_end_session->function = function; - list_add_tail (&(execute_end_session->list), &(list_execute_end_session)); - + if(cwmp->conf.supported_amd_version == 0) + get_amd_version_config(); + get_instance_mode_config(); + dm_ctx_init(ctx, DM_CWMP, cwmp->conf.amd_version, cwmp->conf.instance_mode); return 0; } -int cwmp_free_dm_end_session(struct execute_end_session *execute_end_session) +int cwmp_dm_ctx_clean(struct cwmp *cwmp, struct dmctx *ctx) { - if(execute_end_session != NULL) - { - if(execute_end_session->data != NULL) - { - FREE(execute_end_session->data); - } - FREE(execute_end_session); - } -} - -int apply_end_session() -{ - struct execute_end_session *p, *q; - list_for_each_entry_safe(p, q, &(list_execute_end_session), list) { - p->function(p->action, p->data); - list_del(&(p->list)); - cwmp_free_dm_end_session(p); - } + dm_ctx_clean(ctx); + return 0; } int cwmp_get_int_event_code(char *code) @@ -216,7 +190,6 @@ void cwmp_schedule_session (struct cwmp *cwmp) cwmp->session_status.last_start_time = time(NULL); cwmp->session_status.last_status = SESSION_RUNNING; cwmp->session_status.next_retry = 0; - dm_global_init(); CWMP_LOG (INFO,"Start session"); error = cwmp_schedule_rpc (cwmp,session); CWMP_LOG (INFO,"End session"); @@ -471,12 +444,6 @@ int cwmp_move_session_to_session_queue (struct cwmp *cwmp, struct session *sessi return CWMP_OK; } -void cwmp_set_end_session (unsigned int end_session_flag) -{ - if (cwmp_main.session_send) - cwmp_main.session_send->end_session |= end_session_flag; -} - int cwmp_session_destructor (struct cwmp *cwmp, struct session *session) { struct rpc *rpc; @@ -532,7 +499,7 @@ int run_session_end_func (struct session *session) { apply_end_session(); - if (session->end_session & END_SESSION_EXTERNAL_ACTION) + if (end_session_flag & END_SESSION_EXTERNAL_ACTION) { CWMP_LOG (INFO,"Executing external commands: end session request"); external_init(); @@ -540,7 +507,7 @@ int run_session_end_func (struct session *session) external_exit(); } - if (session->end_session & END_SESSION_FACTORY_RESET) + if (end_session_flag & END_SESSION_FACTORY_RESET) { CWMP_LOG (INFO,"Executing factory reset: end session request"); external_init(); @@ -549,24 +516,24 @@ int run_session_end_func (struct session *session) exit(EXIT_SUCCESS); } - if (session->end_session & END_SESSION_IPPING_DIAGNOSTIC) + if (end_session_flag & END_SESSION_IPPING_DIAGNOSTIC) { CWMP_LOG (INFO,"Executing ippingdiagnostic: end session request"); cwmp_ip_ping_diagnostic(); } - if (session->end_session & END_SESSION_DOWNLOAD_DIAGNOSTIC) + if (end_session_flag & END_SESSION_DOWNLOAD_DIAGNOSTIC) { CWMP_LOG (INFO,"Executing download diagnostic: end session request"); cwmp_start_diagnostic(DOWNLOAD_DIAGNOSTIC); } - if (session->end_session & END_SESSION_UPLOAD_DIAGNOSTIC) + if (end_session_flag & END_SESSION_UPLOAD_DIAGNOSTIC) { CWMP_LOG (INFO,"Executing upload diagnostic: end session request"); cwmp_start_diagnostic(UPLOAD_DIAGNOSTIC); } - if (session->end_session & END_SESSION_REBOOT) + if (end_session_flag & END_SESSION_REBOOT) { CWMP_LOG (INFO,"Executing Reboot: end session request"); external_init(); @@ -575,14 +542,14 @@ int run_session_end_func (struct session *session) exit(EXIT_SUCCESS); } - if (session->end_session & END_SESSION_RELOAD) + if (end_session_flag & END_SESSION_RELOAD) { CWMP_LOG (INFO,"Config reload: end session request"); cwmp_apply_acs_changes(); } - if (session->end_session & END_SESSION_X_FACTORY_RESET_SOFT) + if (end_session_flag & END_SESSION_X_FACTORY_RESET_SOFT) { CWMP_LOG (INFO,"Executing factory reset soft: end session request"); external_init(); @@ -593,7 +560,7 @@ int run_session_end_func (struct session *session) dm_entry_restart_services(); - session->end_session = 0; + end_session_flag = 0; return CWMP_OK; } diff --git a/diagnostic.c b/diagnostic.c index cc7c2e0..0486738 100644 --- a/diagnostic.c +++ b/diagnostic.c @@ -21,6 +21,7 @@ #include "dmcommon.h" #include "ubus.h" #include "diagnostic.h" +#include "config.h" #include #include #include diff --git a/dm/dmcommon.c b/dm/dmcommon.c index 94c514f..0cc5398 100644 --- a/dm/dmcommon.c +++ b/dm/dmcommon.c @@ -21,13 +21,23 @@ #include #include #include -#include +#include #include "dmcwmp.h" #include "dmuci.h" #include "dmubus.h" #include "dmcommon.h" #include "dmjson.h" +char *array_notifcation_char[__MAX_notification] = { + [notification_none] = "0", + [notification_passive] = "1", + [notification_active] = "2", + [notification_passive_lw] = "3", + [notification_ppassive_passive_lw] = "4", + [notification_aactive_lw] = "5", + [notification_passive_active_lw] = "6", +}; + int set_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char *option, char *value) { struct uci_list *v; @@ -89,6 +99,7 @@ int update_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char } return 0; } + void compress_spaces(char *str) { char *dst = str; @@ -114,6 +125,58 @@ char *cut_fx(char *str, char *delimiter, int occurence) return pch; } +unsigned char dmisnumeric(char *nbr) +{ + if (*nbr == '\0') + return 0; + while (*nbr <= '9' && *nbr >= '0') { + nbr++; + } + return ((*nbr) ? 0 : 1); +} + +/* int strstructered(char *str1, char *str2) + * Return: + * STRUCTERED_SAME: if str1 is same of str2 (with # match any number) + * STRUCTERED_PART: if str2 is part of str1 (with # match any number) + * STRUCTERED_NULL: if str2 is not part of str1 (with # match any number) + * + */ +int strstructered(char *str1, char *str2) +{ + char buf[16]; + int i = 0; + for (; *str1 && *str2; str1++, str2++) { + if (*str1 == *str2) + continue; + if (*str2 == '#') { + i = 0; + do { + buf[i++] = *str1; + } while (*(str1+1) && *(str1+1) != dm_delim && str1++); + buf[i] = '\0'; + if (dmisnumeric(buf)) + continue; + } + else if (*str1 == '#') { + i = 0; + do { + buf[i++] = *str2; + } while (*(str2+1) && *(str2+1) != dm_delim && str2++); + buf[i] = '\0'; + if (dmisnumeric(buf)) + continue; + } + return STRUCTERED_NULL; + } + if (*str1 == '\0' && *str2 == '\0') + return STRUCTERED_SAME; + else if (*str2 == '\0') + return STRUCTERED_PART; + return STRUCTERED_NULL; +} + + pid_t get_pid(char *pname) { DIR* dir; @@ -782,3 +845,57 @@ int check_ifname_is_vlan(char *ifname) return 1; return 0; } + +int dmcommon_check_notification_value(char *value) +{ + int i; + for (i = 0; i< __MAX_notification; i++) { + if (strcmp(value, array_notifcation_char[i]) == 0) + return 0; + } + return -1; +} + +char *print_bin(unsigned int n, char *buf, int sep) +{ + int i = 0, j; + for (j = 0; j < 32; j++) { + if (j % sep == 0) + buf[i++] = ' '; + buf[i++] = (n & (1<iface = strtok_r(line, " \t", &spch); + + pch = strtok_r(NULL, " \t", &spch); + hex_to_ip(pch, proute->destination); + pch = strtok_r(NULL, " \t", &spch); + hex_to_ip(pch, proute->gateway); + proute->flags = strtok_r(NULL, " \t", &spch); + proute->refcnt = strtok_r(NULL, " \t", &spch); + proute->use = strtok_r(NULL, " \t", &spch); + proute->metric = strtok_r(NULL, " \t", &spch); + pch = strtok_r(NULL, " \t", &spch); + hex_to_ip(pch, proute->mask); + proute->mtu = strtok_r(NULL, " \t", &spch); + proute->window = strtok_r(NULL, " \t", &spch); + proute->irtt = strtok_r(NULL, " \t\n\r", &spch); +} + +void hex_to_ip(char *address, char *ret) +{ + int i; + int ip[4] = {0}; + sscanf(address, "%2x%2x%2x%2x", &(ip[0]), &(ip[1]), &(ip[2]), &(ip[3])); + if (htonl(13) == 13) { + sprintf(ret, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + } else { + sprintf(ret, "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); + } +} diff --git a/dm/dmcommon.h b/dm/dmcommon.h index 4960b60..3375ab6 100644 --- a/dm/dmcommon.h +++ b/dm/dmcommon.h @@ -18,6 +18,8 @@ #include "dmcwmp.h" #define NVRAM_FILE "/proc/nvram/WpaKey" #define MAX_DHCP_LEASES 256 +#define MAX_PROC_ROUTING 256 +#define ROUTING_FILE "/proc/net/route" #define ARP_FILE "/proc/net/arp" #define DMMAP "dmmap" #define DHCPSTATICADDRESS_DISABLED_CHADDR "00:00:00:00:00:01" @@ -54,6 +56,54 @@ do { \ if (mpp) close (mpp); \ } while (0) +#define IPPING_STOP DMCMD("/bin/sh", 2, FUNCTION_PATH, "stop"); +#define FUNCTION_PATH "/usr/share/icwmp/functions/ipping_launch" +#define DOWNLOAD_DIAGNOSTIC_PATH "/usr/share/icwmp/functions/download_launch" +#define DOWNLOAD_DUMP_FILE "/tmp/download_dump" +#define DOWNLOAD_DIAGNOSTIC_STOP DMCMD("/bin/sh", 2, DOWNLOAD_DIAGNOSTIC_PATH, "stop"); +#define UPLOAD_DIAGNOSTIC_PATH "/usr/share/icwmp/functions/upload_launch" +#define UPLOAD_DUMP_FILE "/tmp/upload_dump" +#define UPLOAD_DIAGNOSTIC_STOP DMCMD("/bin/sh", 2, UPLOAD_DIAGNOSTIC_PATH, "stop"); + +enum notification_enum { + notification_none, + notification_passive, + notification_active, + notification_passive_lw, + notification_ppassive_passive_lw, + notification_aactive_lw, + notification_passive_active_lw, + __MAX_notification +}; + +enum strstructered_enum { + STRUCTERED_SAME, + STRUCTERED_PART, + STRUCTERED_NULL +}; + +struct proc_routing { + char *iface; + char *flags; + char *refcnt; + char *use; + char *metric; + char *mtu; + char *window; + char *irtt; + char destination[16]; + char gateway[16]; + char mask[16]; +}; + +struct routingfwdargs +{ + char *permission; + struct uci_section *routefwdsection; + struct proc_routing *proute; + int type; +}; + void compress_spaces(char *str); char *cut_fx(char *str, char *delimiter, int occurence); pid_t get_pid(char *pname); @@ -88,5 +138,8 @@ int max_array(int a[], int size); int check_ifname_is_vlan(char *ifname); int set_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char *option, char *value); int update_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char *option, char * new_option, char *value); - +void parse_proc_route_line(char *line, struct proc_routing *proute); +int strstructered(char *str1, char *str2); +int dmcommon_check_notification_value(char *value); +void hex_to_ip(char *address, char *ret); #endif diff --git a/dm/dmcwmp.c b/dm/dmcwmp.c index 5f0ba34..ce81a4a 100644 --- a/dm/dmcwmp.c +++ b/dm/dmcwmp.c @@ -7,11 +7,13 @@ * */ +#include +#include #include -#include "cwmp.h" +#include #include "dmuci.h" #include "dmcwmp.h" -#include "xml.h" +#include "dmmem.h" #include "root.h" #include "times.h" #include "upnp.h" @@ -45,57 +47,90 @@ #include "routing.h" #include "nat.h" #include "xmpp.h" -#include "x_inteno_se_owsd.h" -#include "downloaddiagnostic.h" -#include "uploaddiagnostic.h" -#include "x_inteno_se_dropbear.h" -#include "x_inteno_se_buttons.h" -#include "deviceconfig.h" +#include "dmcwmp.h" -static char *get_parameter_notification (struct dmctx *ctx, char *param); +static char *get_parameter_notification(struct dmctx *ctx, char *param); static int remove_parameter_notification(char *param); -static int set_parameter_notification(struct dmctx *ctx, char *param, char *value); -static int check_param_prefix (struct dmctx *ctx); -static int check_obj_is_nl1(char *refparam, char *inparam, int ndot); -static int get_value_obj(DMOBJECT_API_ARGS); -static int get_value_inparam_isobj_check_obj(DMOBJECT_API_ARGS); -static int get_value_inparam_isparam_check_obj(DMOBJECT_API_ARGS); -static int get_value_param(DMPARAM_API_ARGS); -static int get_value_inparam_isparam_check_param(DMPARAM_API_ARGS); -static int get_value_inparam_isobj_check_param(DMPARAM_API_ARGS); -static int get_name_obj(DMOBJECT_API_ARGS); -static int get_name_inparam_isparam_check_obj(DMOBJECT_API_ARGS); -static int get_name_inparam_isobj_check_obj(DMOBJECT_API_ARGS); -static int get_name_emptyin_nl1_obj(DMOBJECT_API_ARGS); -static int get_name_param(DMPARAM_API_ARGS); -static int get_name_inparam_isparam_check_param(DMPARAM_API_ARGS); -static int get_name_inparam_isobj_check_param(DMPARAM_API_ARGS); -static int get_name_emptyin_nl1_param(DMPARAM_API_ARGS); -static int get_notification_obj(DMOBJECT_API_ARGS); -static int get_notification_inparam_isparam_check_obj(DMOBJECT_API_ARGS); -static int get_notification_inparam_isobj_check_obj(DMOBJECT_API_ARGS); -static int get_notification_param(DMPARAM_API_ARGS); -static int get_notification_inparam_isparam_check_param(DMPARAM_API_ARGS); -static int get_notification_inparam_isobj_check_param(DMPARAM_API_ARGS); -static int inform_check_obj(DMOBJECT_API_ARGS); -static int inform_check_param(DMPARAM_API_ARGS); -static int add_object_obj(DMOBJECT_API_ARGS); -static int add_object_param(DMPARAM_API_ARGS); -static int delete_object_obj(DMOBJECT_API_ARGS); -static int delete_object_param(DMPARAM_API_ARGS); -static int set_value_check_obj(DMOBJECT_API_ARGS); -static int set_value_check_param(DMPARAM_API_ARGS); -static int set_notification_check_obj(DMOBJECT_API_ARGS); -static int set_notification_check_param(DMPARAM_API_ARGS); -static int enabled_notify_check_obj(DMOBJECT_API_ARGS); -static int enabled_notify_check_param(DMPARAM_API_ARGS); -static int get_linker_check_obj(DMOBJECT_API_ARGS); -static int get_linker_check_param(DMPARAM_API_ARGS); -static int get_linker_value_check_obj(DMOBJECT_API_ARGS); -static int get_linker_value_check_param(DMPARAM_API_ARGS); +static int set_parameter_notification(struct dmctx *ctx, char *param,char *value); +static int get_value_obj(DMOBJECT_ARGS); +static int get_value_param(DMPARAM_ARGS); +static int mobj_get_value_in_param(DMOBJECT_ARGS); +static int mparam_get_value_in_param(DMPARAM_ARGS); +static int mparam_get_name(DMPARAM_ARGS); +static int mobj_get_name(DMOBJECT_ARGS); +static int mparam_get_name_in_param(DMPARAM_ARGS); +static int mobj_get_name_in_param(DMOBJECT_ARGS); +static int mparam_get_name_in_obj(DMPARAM_ARGS); +static int mobj_get_name_in_obj(DMOBJECT_ARGS); +static int inform_check_obj(DMOBJECT_ARGS); +static int inform_check_param(DMPARAM_ARGS); +static int mparam_add_object(DMPARAM_ARGS); +static int mobj_add_object(DMOBJECT_ARGS); +static int delete_object_obj(DMOBJECT_ARGS); +static int delete_object_param(DMPARAM_ARGS); +static int mobj_set_value(DMOBJECT_ARGS); +static int mparam_set_value(DMPARAM_ARGS); +static int mobj_get_notification_in_param(DMOBJECT_ARGS); +static int mobj_get_notification(DMOBJECT_ARGS); +static int mparam_get_notification(DMPARAM_ARGS); +static int mparam_get_notification_in_param(DMPARAM_ARGS); +static int mparam_set_notification_in_obj(DMPARAM_ARGS); +static int mobj_set_notification_in_param(DMOBJECT_ARGS); +static int mparam_set_notification_in_param(DMPARAM_ARGS); +static int mobj_set_notification_in_obj(DMOBJECT_ARGS); +#ifdef UPNP_TR064 +static int mparam_upnp_get_instances(DMPARAM_ARGS); +static int mobj_upnp_get_instances(DMOBJECT_ARGS); +static int mparam_upnp_structured_get_value_in_param(DMPARAM_ARGS); +static int mparam_upnp_get_supportedparams(DMPARAM_ARGS); +static int mparam_upnp_set_attributes(DMPARAM_ARGS); +static int mobj_upnp_set_attributes(DMOBJECT_ARGS); +static int mobj_upnp_get_supportedparams(DMOBJECT_ARGS); +static int mparam_upnp_get_attributes(DMPARAM_ARGS); +static int mobj_upnp_get_attributes(DMOBJECT_ARGS); +static int upnp_get_value_obj(DMOBJECT_ARGS); +static int upnp_get_value_param(DMPARAM_ARGS); +static int mobj_upnp_get_value_in_param(DMOBJECT_ARGS); +static int mparam_upnp_get_value_in_param(DMPARAM_ARGS); +static int mobj_upnp_set_value(DMOBJECT_ARGS); +static int mparam_upnp_set_value(DMPARAM_ARGS); +static int upnp_delete_instance_param(DMPARAM_ARGS); +static int upnp_delete_instance_obj(DMOBJECT_ARGS); +static int mparam_upnp_add_instance(DMPARAM_ARGS); +static int mobj_upnp_add_instance(DMOBJECT_ARGS); +static int mparam_upnp_get_acldata(DMPARAM_ARGS); +static int mobj_upnp_get_acldata(DMOBJECT_ARGS); +static int mparam_upnp_get_instance_numbers(DMPARAM_ARGS); +static int mobj_upnp_get_instance_numbers(DMOBJECT_ARGS); +static int enabled_tracked_param_check_obj(DMOBJECT_ARGS); +static int enabled_tracked_param_check_param(DMPARAM_ARGS); +#endif +static int enabled_notify_check_obj(DMOBJECT_ARGS); +static int enabled_notify_check_param(DMPARAM_ARGS); +static int get_linker_check_obj(DMOBJECT_ARGS); +static int get_linker_check_param(DMPARAM_ARGS); +static int get_linker_value_check_obj(DMOBJECT_ARGS); +static int get_linker_value_check_param(DMPARAM_ARGS); + LIST_HEAD(list_enabled_notify); LIST_HEAD(list_enabled_lw_notify); +#ifdef UPNP_TR064 +LIST_HEAD(list_upnp_enabled_onevent); +LIST_HEAD(list_upnp_enabled_onalarm); +LIST_HEAD(list_upnp_enabled_version); +LIST_HEAD(list_upnp_changed_onevent); +LIST_HEAD(list_upnp_changed_onalarm); +LIST_HEAD(list_upnp_changed_version); +#endif + +LIST_HEAD(list_execute_end_session); +int end_session_flag = 0; +int ip_version = 4; +char dm_delim = DMDELIM_CWMP; +char DMROOT[64] = DMROOT_CWMP; +unsigned int upnp_in_user_mask = DM_SUPERADMIN_MASK; + struct notification notifications[] = { [0] = {"0", "disabled"}, @@ -107,64 +142,261 @@ struct notification notifications[] = { [6] = {"6", "passive_active_lw"} }; -struct prefix_method prefix_methods[] = { - { DMROOT, 1, NULL, 1, &entry_method_root }, - { DMROOT"DeviceInfo.", 1, NULL, 1, &entry_method_root_DeviceInfo }, - { DMROOT"ManagementServer.", 1, NULL, 1, &entry_method_root_ManagementServer }, -#ifdef DATAMODEL_TR098 - { DMROOT"LANDevice.", 1, NULL, 0, &entry_method_root_LANDevice }, - { DMROOT"LANInterfaces.", 1, NULL, 0, &entry_method_root_InternetGatewayDevice_LANInterfaces }, - { DMROOT"WANDevice.", 1, NULL, 1, &entry_method_root_WANDevice }, - { DMROOT"Layer2Bridging.", 1, NULL, 0, &entry_method_root_Layer2Bridging }, - { DMROOT"X_INTENO_SE_Wifi.", 1, NULL, 0, &entry_method_root_SE_Wifi }, - { DMROOT"Layer3Forwarding.", 1, NULL, 0, &entry_method_root_layer3_forwarding }, - { DMROOT"IPPingDiagnostics.", 1, NULL, 0, &entry_method_root_IPPingDiagnostics }, - { DMROOT"DownloadDiagnostics.", 1, NULL, 0, &entry_method_root_Download_Diagnostics }, - { DMROOT"UploadDiagnostics.", 1, NULL, 0, &entry_method_root_Upload_Diagnostics }, - { DMROOT"DeviceConfig.", 1, NULL, 0, &entry_method_root_device_config }, -#endif - { DMROOT"Services.", 1, dm_service_enable_set, 0, &entry_method_root_Service }, - { DMROOT"UPnP.", 1, NULL, 0, &entry_method_root_upnp }, - { DMROOT"Time.", 1, NULL, 0, &entry_method_root_Time }, - { DMROOT"X_INTENO_SE_IGMP.", 1, NULL, 0, &entry_method_root_X_INTENO_SE_IGMP }, - { DMROOT"X_INTENO_SE_ICE.", 1, NULL, 0, &entry_method_root_X_INTENO_SE_Ice }, - { DMROOT"X_INTENO_SE_IpAccCfg.", 1, NULL, 0, &entry_method_root_X_INTENO_SE_IpAccCfg }, - { DMROOT"X_INTENO_SE_LoginCfg.", 1, NULL, 0, &entry_method_root_X_INTENO_SE_LOGIN_CFG }, - { DMROOT"X_INTENO_SE_PowerManagement.", 1, dm_powermgmt_enable_set, 0, &entry_method_root_X_INTENO_SE_PowerManagement }, - { DMROOT"X_INTENO_SE_SyslogCfg.", 1, NULL, 0, &entry_method_root_syslog }, - { DMROOT"SoftwareModules.", 1, NULL, 0, &entry_method_root_software_modules }, - { DMROOT"X_INTENO_SE_Owsd.", 1, NULL, 0, &entry_method_root_X_INTENO_SE_OWSD }, - { DMROOT"X_INTENO_SE_Dropbear.", 1, NULL, 0, &entry_method_root_X_INTENO_SE_DROPBEAR }, - { DMROOT"X_INTENO_SE_Buttons.", 1, NULL, 0, &entry_method_root_X_INTENO_SE_BUTTONS }, -#ifdef XMPP_ENABLE - { DMROOT"XMPP.", 1, NULL, 0, &entry_method_root_xmpp }, -#endif -#ifdef DATAMODEL_TR181 - { DMROOT"Wifi.", 1, NULL, 0, &entry_method_root_Wifi }, - { DMROOT"Ethernet.", 1, NULL, 0, &entry_method_root_Ethernet }, - { DMROOT"DSL.", 1, NULL, 0, &entry_method_root_wan_dsl }, - { DMROOT"ATM.", 1, NULL, 0, &entry_method_root_wan_atm }, - { DMROOT"PTM.", 1, NULL, 0, &entry_method_root_wan_ptm }, - { DMROOT"Bridging.", 1, NULL, 0, &entry_method_root_bridging }, - { DMROOT"Hosts.", 1, NULL, 0, &entry_method_root_hosts }, - { DMROOT"DHCPv4.", 1, NULL, 0, &entry_method_root_dhcp }, - { DMROOT"IP.", 1, NULL, 0, &entry_method_root_ip }, - { DMROOT"PPP.", 1, NULL, 0, &entry_method_root_ppp }, - { DMROOT"Routing.", 1, NULL, 0, &entry_method_root_routing }, - { DMROOT"NAT.", 1, NULL, 0, &entry_method_root_nat }, -#endif +struct dm_acl dm_acl[] = { + [0] = {DM_PUBLIC_LIST, "public_list"}, + [1] = {DM_PUBLIC_READ, "public_read"}, + [2] = {DM_PUBLIC_WRITE, "public_write"}, + [3] = {DM_BASIC_LIST, "basic_list"}, + [4] = {DM_BASIC_READ, "basic_read"}, + [5] = {DM_BASIC_WRITE, "basic_write"}, + [6] = {DM_XXXADMIN_LIST, "xxxadmin_list"}, + [7] = {DM_XXXADMIN_READ, "xxxadmin_read"}, + [8] = {DM_XXXADMIN_WRITE, "xxxadmin_write"}, }; -int dm_entry_set_prefix_methods_enable(void) +char *DMT_TYPE[] = { +[DMT_STRING] = "xsd:string", +[DMT_UNINT] = "xsd:unsignedInt", +[DMT_INT] = "xsd:int", +[DMT_LONG] = "xsd:long", +[DMT_BOOL] = "xsd:boolean", +[DMT_TIME] = "xsd:dateTime", +[DMT_HEXBIN] = "xsd:hexbin", +}; + +#ifdef UPNP_TR064 +unsigned int UPNP_DMT_TYPE[] = { +[DMT_STRING] = NODE_DATA_ATTRIBUTE_TYPESTRING, +[DMT_UNINT] = NODE_DATA_ATTRIBUTE_TYPEINT, +[DMT_INT] = NODE_DATA_ATTRIBUTE_TYPEINT, +[DMT_LONG] = NODE_DATA_ATTRIBUTE_TYPELONG, +[DMT_BOOL] = NODE_DATA_ATTRIBUTE_TYPEBOOL, +[DMT_TIME] = NODE_DATA_ATTRIBUTE_TYPEDATETIME, +[DMT_HEXBIN] = NODE_DATA_ATTRIBUTE_TYPEBIN, +}; +#endif + +struct dm_permession_s DMREAD = {"0", NULL}; +struct dm_permession_s DMWRITE = {"1", NULL}; +struct dm_forced_inform_s DMFINFRM = {1, NULL}; +struct dm_notif_s DMNONE = { "0", NULL }; +struct dm_notif_s DMPASSIVE = { "1", NULL }; +struct dm_notif_s DMACTIVE = { "2", NULL }; + +int plugin_obj_match(DMOBJECT_ARGS) { - unsigned int i = 0; - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (prefix_methods[i].set_enable) { - prefix_methods[i].enable = prefix_methods[i].set_enable(); + if (node->matched) + return 0; + if (!dmctx->inparam_isparam && strstr(node->current_object, dmctx->in_param) == node->current_object) { + node->matched++; + dmctx->findparam = 1; + return 0; + } + if (strstr(dmctx->in_param, node->current_object) == dmctx->in_param) { + return 0; + } + return FAULT_9005; +} + +int plugin_leaf_match(DMOBJECT_ARGS) +{ + char *str; + if (node->matched) + return 0; + if (!dmctx->inparam_isparam) + return FAULT_9005; + str = dmctx->in_param + strlen(node->current_object); + if (!strchr(str, dm_delim)) + return 0; + return FAULT_9005; +} + +int plugin_obj_forcedinform_match(DMOBJECT_ARGS) +{ + unsigned char fi; + if (forced_inform) { + if (forced_inform->get_forced_inform) + fi = forced_inform->get_forced_inform(node->current_object, dmctx, data, instance); + else + fi = forced_inform->val; + if (fi) + return 0; + } + return FAULT_9005; +} + +int plugin_leaf_onlyobj_match(DMOBJECT_ARGS) +{ + return FAULT_9005; +} + +int plugin_obj_nextlevel_match(DMOBJECT_ARGS) +{ + if (node->matched > 1) + return FAULT_9005; + if (node->matched) { + node->matched++; + return 0; + } + if (!dmctx->inparam_isparam && strstr(node->current_object, dmctx->in_param) == node->current_object) { + node->matched++; + dmctx->findparam = 1; + return 0; + } + if (strstr(dmctx->in_param, node->current_object) == dmctx->in_param) { + return 0; + } + return FAULT_9005; +} + +int plugin_leaf_nextlevel_match(DMOBJECT_ARGS) +{ + char *str; + if (node->matched > 1) + return FAULT_9005; + if (node->matched) + return 0; + if (!dmctx->inparam_isparam) + return FAULT_9005; + str = dmctx->in_param + strlen(node->current_object); + if (!strchr(str, dm_delim)) + return 0; + return FAULT_9005; +} + +int dm_browse_leaf(struct dmctx *dmctx, DMNODE *parent_node, DMLEAF *leaf, void *data, char *instance) +{ + int err = 0; + if (!leaf) + return 0; + + for (; leaf->parameter; leaf++) { + err = dmctx->method_param(dmctx, parent_node, leaf->parameter, leaf->permission, leaf->type, leaf->getvalue, leaf->setvalue, leaf->forced_inform, leaf->notification, data, instance); + if (dmctx->stop) + return err; + } + return err; +} + +int dm_browse(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, void *data, char *instance) +{ + int err = 0; + if (!entryobj) + return 0; + char *parent_obj = parent_node->current_object; + for (; entryobj->obj; entryobj++) { + DMNODE node = {0}; + node.obj = entryobj; + node.parent = parent_node; + node.instance_level = parent_node->instance_level; + node.matched = parent_node->matched; + dmasprintf(&(node.current_object), "%s%s%c", parent_obj, entryobj->obj, dm_delim); + if (dmctx->checkobj) { + err = dmctx->checkobj(dmctx, &node, entryobj->permission, entryobj->addobj, entryobj->delobj, entryobj->forced_inform, entryobj->notification, entryobj->get_linker, data, instance); + if (err) + continue; + } + err = dmctx->method_obj(dmctx, &node, entryobj->permission, entryobj->addobj, entryobj->delobj, entryobj->forced_inform, entryobj->notification, entryobj->get_linker, data, instance); + if (dmctx->stop) + return err; + if (entryobj->checkobj && ((entryobj->checkobj)(dmctx, data) == false) ){ + continue; + } + if (entryobj->browseinstobj) { + if (dmctx->instance_wildchar) { + dm_link_inst_obj(dmctx, &node, data, dmctx->instance_wildchar); + continue; + } + else { + entryobj->browseinstobj(dmctx, &node, data, instance); + err = dmctx->faultcode; + if (dmctx->stop) + return err; + continue; + } + } + if (entryobj->leaf) { + if (dmctx->checkleaf) { + err = dmctx->checkleaf(dmctx, &node, entryobj->permission, entryobj->addobj, entryobj->delobj, entryobj->forced_inform, entryobj->notification, entryobj->get_linker, data, instance); + if (!err) { + err = dm_browse_leaf(dmctx, &node, entryobj->leaf, data, instance); + if (dmctx->stop) + return err; + } + } else { + err = dm_browse_leaf(dmctx, &node, entryobj->leaf, data, instance); + if (dmctx->stop) + return err; + } + } + if (entryobj->nextobj) { + err = dm_browse(dmctx, &node, entryobj->nextobj, data, instance); + if (dmctx->stop) + return err; } } - return 0; + return err; } + +int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance) +{ + int err = 0; + char *parent_obj; + DMOBJ *prevobj = parent_node->obj; + DMOBJ *nextobj = prevobj->nextobj; + DMLEAF *nextleaf = prevobj->leaf; + + DMNODE node = {0}; + node.obj = prevobj; + node.parent = parent_node; + node.instance_level = parent_node->instance_level + 1; + node.is_instanceobj = 1; + node.matched = parent_node->matched; + + parent_obj = parent_node->current_object; + if (instance == NULL) + return -1; + dmasprintf(&node.current_object, "%s%s%c", parent_obj, instance, dm_delim); + if (dmctx->checkobj) { + err = dmctx->checkobj(dmctx, &node, prevobj->permission, prevobj->addobj, prevobj->delobj, prevobj->forced_inform, prevobj->notification, prevobj->get_linker, data, instance); + if (err) + return err; + } + err = dmctx->method_obj(dmctx, &node, prevobj->permission, prevobj->addobj, prevobj->delobj, prevobj->forced_inform, prevobj->notification, prevobj->get_linker, data, instance); + if (dmctx->stop) + return err; + if (nextleaf) { + if (dmctx->checkleaf) { + err = dmctx->checkleaf(dmctx, &node, prevobj->permission, prevobj->addobj, prevobj->delobj, prevobj->forced_inform, prevobj->notification, prevobj->get_linker, data, instance); + if (!err) { + err = dm_browse_leaf(dmctx, &node, nextleaf, data, instance); + if (dmctx->stop) + return err; + } + } else { + err = dm_browse_leaf(dmctx, &node, nextleaf, data, instance); + if (dmctx->stop) + return err; + } + } + if (nextobj) { + err = dm_browse(dmctx, &node, nextobj, data, instance); + if (dmctx->stop) + return err; + } + return err; +} + +int rootcmp(char *inparam, char *rootobj) +{ + int cmp = -1; + char buf[32]; + sprintf(buf, "%s%c", rootobj, dm_delim); + cmp = strcmp(inparam, buf); + return cmp; +} + +//END// /*************************** * update instance & alias ***************************/ @@ -178,9 +410,8 @@ char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **last_ unsigned int alias_resister = 0, max, action; void *argv[argc]; - va_start(arg,argc); - for (i=0; ilist_parameter) { + list_for_each(ilist, &ctx->list_parameter) + { dm_parameter = list_entry(ilist, struct dm_parameter, list); int cmp = strcmp(dm_parameter->name, param_name); if (cmp == 0) { return; - } else if (cmp>0) { + } else if (cmp > 0) { break; } } @@ -374,6 +607,8 @@ void add_list_paramameter(struct dmctx *ctx, char *param_name, char *param_data, dm_parameter->name = param_name; dm_parameter->data = param_data ? param_data : ""; //allocate memory in function dm_parameter->type = param_type; + dm_parameter->version = param_version; + dm_parameter->flags = flags; } void del_list_parameter(struct dm_parameter *dm_parameter) @@ -392,13 +627,14 @@ void free_all_list_parameter(struct dmctx *ctx) } } -void add_set_list_tmp(struct dmctx *ctx, char *param, char *value) +void add_set_list_tmp(struct dmctx *ctx, char *param, char *value, unsigned int flags) { struct set_tmp *set_tmp; set_tmp = dmcalloc(1, sizeof(struct set_tmp)); list_add_tail(&set_tmp->list, &ctx->set_list_tmp); set_tmp->name = dmstrdup(param); - set_tmp->value = dmstrdup(value); + set_tmp->value = value ? dmstrdup(value) : NULL; + set_tmp->flags = flags; } void del_set_list_tmp(struct set_tmp *set_tmp) @@ -445,63 +681,28 @@ void free_all_list_fault_param(struct dmctx *ctx) } } -int update_param_instance_alias(struct dmctx *ctx, char *param, char **new_param) -{ - char *pch, *spch, *p; - char buf[512]; - int i = 0, j = 0; - - char *dup = dmstrdup(param); - p = buf; - for (pch = strtok_r(dup, ".", &spch); pch != NULL; pch = strtok_r(NULL, ".", &spch)) { - if (isdigit(pch[0])) { - dmstrappendchr(p, '.'); - dmstrappendstr(p, pch); - i++; - } else if (pch[0]== '[') { - dmstrappendchr(p, '.'); - dmstrappendstr(p, ctx->inst_buf[i]); - i++; - } else { - if(j > 0) { - dmstrappendchr(p, '.'); - dmstrappendstr(p, pch); - } - if(j == 0) { - dmstrappendstr(p, pch); - j++; - } - } - } - if (param[strlen(param)-1] == '.') - dmstrappendchr(p, '.'); - dmstrappendend(p); - *new_param = dmstrdup(buf); - dmfree(dup); - return 0; -} - -void add_list_enabled_notify(char *param, char *notification, char *value) +void add_list_enabled_notify(struct dmctx *dmctx, char *param, char *notification, char *value) { struct dm_enabled_notify *dm_enabled_notify; - dm_enabled_notify = calloc(1, sizeof(struct param_fault)); // Should be calloc and not dmcalloc + dm_enabled_notify = calloc(1, sizeof(struct dm_enabled_notify)); // Should be calloc and not dmcalloc list_add_tail(&dm_enabled_notify->list, &list_enabled_notify); dm_enabled_notify->name = strdup(param); // Should be strdup and not dmstrdup dm_enabled_notify->value = value ? strdup(value) : strdup(""); // Should be strdup and not dmstrdup - dm_enabled_notify->notification = strdup(notification); // Should be strdup and not dmstrdup + dm_enabled_notify->notification = strdup(notification); // Should be strdup and not dmstrdup } -void add_list_enabled_lwnotify(char *param, char *notification, char *value) +void add_list_enabled_lwnotify(struct dmctx *dmctx, char *param, char *notification, char *value) { struct dm_enabled_notify *dm_enabled_notify; - dm_enabled_notify = calloc(1, sizeof(struct param_fault)); // Should be calloc and not dmcalloc + dm_enabled_notify = calloc(1, sizeof(struct dm_enabled_notify)); // Should be calloc and not dmcalloc list_add_tail(&dm_enabled_notify->list, &list_enabled_lw_notify); dm_enabled_notify->name = strdup(param); // Should be strdup and not dmstrdup dm_enabled_notify->value = value ? strdup(value) : strdup(""); // Should be strdup and not dmstrdup dm_enabled_notify->notification = strdup(notification); // Should be strdup and not dmstrdup } + void del_list_enabled_notify(struct dm_enabled_notify *dm_enabled_notify) { list_del(&dm_enabled_notify->list); // Should be free and not dmfree @@ -545,7 +746,45 @@ void dm_update_enabled_notify_byname(char *name, char *new_value) } } -static char *get_parameter_notification (struct dmctx *ctx, char *param) +int update_param_instance_alias(struct dmctx *ctx, char *param, char **new_param) +{ + char *pch, *spch, *p; + char buf[512]; + int i = 0, j = 0; + char pat[2] = {0}; + + char *dup = dmstrdup(param); + *pat = dm_delim; + p = buf; + for (pch = strtok_r(dup, pat, &spch); pch != NULL; pch = strtok_r(NULL, pat, &spch)) { + if (isdigit(pch[0])) { + dmstrappendchr(p, dm_delim); + dmstrappendstr(p, pch); + i++; + } else if (pch[0]== '[') { + dmstrappendchr(p, dm_delim); + dmstrappendstr(p, ctx->inst_buf[i]); + i++; + } else { + if (j > 0) { + dmstrappendchr(p, dm_delim); + dmstrappendstr(p, pch); + } + if (j == 0) { + dmstrappendstr(p, pch); + j++; + } + } + } + if (param[strlen(param) - 1] == dm_delim) + dmstrappendchr(p, dm_delim); + dmstrappendend(p); + *new_param = dmstrdup(buf); + dmfree(dup); + return 0; +} + +static char *get_parameter_notification(struct dmctx *ctx, char *param) { int i, maxlen = 0, len; struct uci_list *list_notif; @@ -564,7 +803,7 @@ static char *get_parameter_notification (struct dmctx *ctx, char *param) return notification; } len = strlen(pch); - if (pch[len-1] == '.') { + if (pch[len-1] == dm_delim) { if (strstr(new_param, pch)) { if (len > maxlen ) { @@ -580,7 +819,6 @@ static char *get_parameter_notification (struct dmctx *ctx, char *param) return notification; } - static int remove_parameter_notification(char *param) { int i; @@ -588,7 +826,7 @@ static int remove_parameter_notification(char *param) struct uci_element *e, *tmp; char *pch; for (i = (ARRAY_SIZE(notifications) - 1); i >= 0; i--) { - if (param[strlen(param)-1] == '.') { + if (param[strlen(param)-1] == dm_delim) { dmuci_get_option_value_list("cwmp", "@notifications[0]", notifications[i].type, &list_notif); if (list_notif) { uci_foreach_element_safe(list_notif, e, tmp) { @@ -619,7 +857,7 @@ static int set_parameter_notification(struct dmctx *ctx, char *param, char *valu } notification = get_parameter_notification(ctx, new_param); - if (strcmp(notification, value) == 0) { + if (strcmp(notification, value) == 0) { goto end; } if (strcmp(value, "1") == 0) { @@ -644,7 +882,7 @@ static int set_parameter_notification(struct dmctx *ctx, char *param, char *valu uci_foreach_element(list_notif, e) { pch = e->name; len = strlen(pch); - if (pch[len-1] == '.' && strstr(new_param, pch)) { + if (pch[len-1] == dm_delim && strstr(new_param, pch)) { dmuci_add_list_value("cwmp", "@notifications[0]", "disabled", new_param); goto end; } @@ -660,33 +898,6 @@ end: return 0; } -static int check_param_prefix (struct dmctx *ctx) -{ - unsigned int i; - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (strcmp(ctx->in_param, prefix_methods[i].prefix_name) == 0) { - return 0; - } - } - return -1; -} - -static int check_obj_is_nl1(char *refparam, char *inparam, int ndot) -{ - unsigned int len, i; - len = strlen(refparam); - for (i = len; i > 0; i--) { - if (refparam[i-1] == '.') { - if (--ndot == 0) - break; - } - } - //i++; - if (strlen(inparam) == i) - return 0; - return -1; -} - int string_to_bool(char *v, bool *b) { if (v[0] == '1' && v[1] == '\0') { @@ -712,689 +923,2056 @@ int string_to_bool(char *v, bool *b) /* ********** * get value * **********/ -int dm_entry_get_value(struct dmctx *ctx) +int dm_entry_get_value(struct dmctx *dmctx) { - unsigned int i; - ctx->faultcode = FAULT_9005; + int i; + int err = 0; + unsigned char findparam_check = 0; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = {.current_object = ""}; - if (ctx->in_param[0] == '\0' || check_param_prefix(ctx) == 0) { - ctx->method_obj=&get_value_obj; - ctx->method_param=&get_value_param; - ctx->faultcode = 0; - } else if (ctx->in_param[strlen(ctx->in_param)-1] == '.') { - ctx->method_obj=&get_value_inparam_isobj_check_obj; - ctx->method_param=&get_value_inparam_isobj_check_param; + if (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, root->obj) == 0) { + dmctx->inparam_isparam = 0; + dmctx->method_obj = get_value_obj; + dmctx->method_param = get_value_param; + dmctx->checkobj = NULL; + dmctx->checkleaf = NULL; + dmctx->findparam = 1; + dmctx->stop = 0; + findparam_check = 1; + } else if (dmctx->in_param[strlen(dmctx->in_param) - 1] == dm_delim) { + dmctx->inparam_isparam = 0; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = get_value_obj; + dmctx->method_param = get_value_param; + findparam_check = 1; } else { - ctx->method_obj=&get_value_inparam_isparam_check_obj; - ctx->method_param=&get_value_inparam_isparam_check_param; + dmctx->inparam_isparam = 1; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_get_value_in_param; + dmctx->method_param = mparam_get_value_in_param; } - - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop) - return ret; - } - - return ctx->faultcode; -} - -static int get_value_obj(DMOBJECT_API_ARGS) -{ - return 0; -} - -static int get_value_inparam_isobj_check_obj(DMOBJECT_API_ARGS) -{ - if (strstr(ctx->current_obj, ctx->in_param)) { - ctx->faultcode = 0; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (findparam_check && dmctx->findparam) return 0; - } - return FAULT_9005; + else + return err; } -static int get_value_inparam_isparam_check_obj(DMOBJECT_API_ARGS) +static int get_value_obj(DMOBJECT_ARGS) { - return FAULT_9005; -} - -static int get_value_param(DMPARAM_API_ARGS) -{ - char *full_param; - char *value = NULL; - - dmastrcat(&full_param, ctx->current_obj, lastname); - (get_cmd)(full_param, ctx, &value); - add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string"); return 0; } -static int get_value_inparam_isparam_check_param(DMPARAM_API_ARGS) +static int get_value_param(DMPARAM_ARGS) { char *full_param; - char *value = NULL; + char *value = ""; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (strcmp(ctx->in_param, full_param) != 0) { + dmastrcat(&full_param, node->current_object, lastname); + (get_cmd)(full_param, dmctx, data, instance, &value); + add_list_paramameter(dmctx, full_param, value, DMT_TYPE[type], NULL, 0); + return 0; +} + +static int mobj_get_value_in_param(DMOBJECT_ARGS) +{ + return 0; +} +static int mparam_get_value_in_param(DMPARAM_ARGS) +{ + char *full_param; + char *value = ""; + + dmastrcat(&full_param, node->current_object, lastname); + if (strcmp(dmctx->in_param, full_param) != 0) { dmfree(full_param); return FAULT_9005; } - - (get_cmd)(full_param, ctx, &value); - add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string"); - ctx->stop = true; + + (get_cmd)(full_param, dmctx, data, instance, &value); + add_list_paramameter(dmctx, full_param, value, DMT_TYPE[type], NULL, 0); + dmctx->stop = true; return 0; } -static int get_value_inparam_isobj_check_param(DMPARAM_API_ARGS) -{ - char *full_param; - char *value = NULL; - - dmastrcat(&full_param, ctx->current_obj, lastname); - if (strstr(full_param, ctx->in_param)) { - (get_cmd)(full_param, ctx, &value); - add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string"); - ctx->faultcode = 0; - return 0; - } - dmfree(full_param); - return FAULT_9005; -} - /* ********** * get name * **********/ int dm_entry_get_name(struct dmctx *ctx) { - unsigned int i; - ctx->faultcode = FAULT_9005; - if (ctx->in_param[0] == '\0' && ctx->nextlevel == 1) { - ctx->method_obj=&get_name_emptyin_nl1_obj; - ctx->method_param=&get_name_emptyin_nl1_param; - entry_method_root(ctx); - return 0; - } - if ( ctx->in_param[0] == '\0' || check_param_prefix(ctx) == 0) { - if (ctx->nextlevel == 0) { - ctx->method_obj=&get_name_obj; - ctx->method_param=&get_name_param; - ctx->faultcode = 0; - } else { - ctx->method_obj=&get_name_inparam_isobj_check_obj; - ctx->method_param=&get_name_inparam_isobj_check_param; - } - } else if (ctx->in_param[strlen(ctx->in_param)-1] == '.') { - ctx->method_obj=&get_name_inparam_isobj_check_obj; - ctx->method_param=&get_name_inparam_isobj_check_param; + DMOBJ *root = ctx->dm_entryobj; + DMNODE node = {.current_object = ""}; + unsigned char findparam_check = 0; + int err; + if (ctx->nextlevel == 0 && (ctx->in_param[0] == '\0' || rootcmp(ctx->in_param, root->obj) == 0)) { + ctx->inparam_isparam = 0; + ctx->findparam = 1; + ctx->stop = 0; + ctx->checkobj = NULL; + ctx->checkleaf = NULL; + ctx->method_obj = mobj_get_name; + ctx->method_param = mparam_get_name; + } else if (ctx->nextlevel && (ctx->in_param[0] == '\0')) { + ctx->inparam_isparam = 0; + ctx->findparam = 1; + ctx->stop = 0; + ctx->checkobj = plugin_obj_nextlevel_match; + ctx->checkleaf = plugin_leaf_nextlevel_match; + ctx->method_obj = mobj_get_name; + ctx->method_param = mparam_get_name; + ctx->in_param = root->obj; + node.matched = 1; + findparam_check = 1; + } else if (*(ctx->in_param + strlen(ctx->in_param) - 1) == dm_delim) { + ctx->inparam_isparam = 0; + ctx->findparam = 0; + ctx->stop = 0; + ctx->method_obj = mobj_get_name_in_obj; + ctx->method_param = mparam_get_name_in_obj; + ctx->checkobj = (ctx->nextlevel) ? plugin_obj_nextlevel_match : plugin_obj_match; + ctx->checkleaf = (ctx->nextlevel) ? plugin_leaf_nextlevel_match : plugin_leaf_match; + findparam_check = 1; } else { - ctx->method_obj=&get_name_inparam_isparam_check_obj; - ctx->method_param=&get_name_inparam_isparam_check_param; + ctx->inparam_isparam = 1; + ctx->findparam = 0; + ctx->stop = 0; + ctx->checkobj = plugin_obj_match; + ctx->checkleaf = plugin_leaf_match; + ctx->method_obj = mobj_get_name_in_param; + ctx->method_param = mparam_get_name_in_param; } - - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop == 1) - return ret; - } - return ctx->faultcode; -} - -static int get_name_obj(DMOBJECT_API_ARGS) -{ - char *obj = dmstrdup(ctx->current_obj); - char *p = permission; - add_list_paramameter(ctx, obj, p, NULL); - return 0; -} - -static int get_name_inparam_isparam_check_obj(DMOBJECT_API_ARGS) -{ - return FAULT_9005; -} - -static int get_name_inparam_isobj_check_obj(DMOBJECT_API_ARGS) -{ - if (strstr(ctx->current_obj, ctx->in_param)) { - ctx->faultcode = 0; - if (ctx->nextlevel == 0 || check_obj_is_nl1(ctx->current_obj, ctx->in_param, 2) == 0 ) { - char *obj = dmstrdup(ctx->current_obj); - char *p = permission; - add_list_paramameter(ctx, obj, p, NULL); - return 0; - } + err = dm_browse(ctx, &node, root, NULL, NULL); + if (findparam_check && ctx->findparam) return 0; - } - return FAULT_9005; + else + return err; } -static int get_name_emptyin_nl1_obj(DMOBJECT_API_ARGS) +static int mparam_get_name(DMPARAM_ARGS) { - char *obj = dmstrdup(ctx->current_obj); - char *p = permission; - add_list_paramameter(ctx, obj, p, NULL); + char *refparam; + char *perm = permission->val; + dmastrcat(&refparam, node->current_object, lastname); + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + add_list_paramameter(dmctx, refparam, perm, NULL, NULL, 0); return 0; } -static int get_name_param(DMPARAM_API_ARGS) +static int mobj_get_name(DMOBJECT_ARGS) { - char *full_param; - char *p = permission; - dmastrcat(&full_param, ctx->current_obj, lastname); - add_list_paramameter(ctx, full_param, p, NULL); + char *refparam; + char *perm = permission->val; + refparam = node->current_object; + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + add_list_paramameter(dmctx, refparam, perm, NULL, NULL, 0); return 0; } -static int get_name_inparam_isparam_check_param(DMPARAM_API_ARGS) +static int mparam_get_name_in_param(DMPARAM_ARGS) { - char *full_param; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (strcmp(full_param, ctx->in_param) != 0) { - dmfree(full_param); + char *refparam; + char *perm = permission->val; + dmastrcat(&refparam, node->current_object, lastname); + if (strcmp(refparam, dmctx->in_param) != 0) { + dmfree(refparam); return FAULT_9005; } - if (ctx->nextlevel == 1) { - dmfree(full_param); - ctx->stop = 1; + dmctx->stop = 1; + if (dmctx->nextlevel == 1) { + dmfree(refparam); return FAULT_9003; } - char *p = permission; - add_list_paramameter(ctx, full_param, p, NULL); - ctx->stop = 1; + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + add_list_paramameter(dmctx, refparam, perm, NULL, NULL, 0); return 0; } -static int get_name_inparam_isobj_check_param(DMPARAM_API_ARGS) +static int mobj_get_name_in_param(DMOBJECT_ARGS) { - char *full_param; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (strstr(full_param, ctx->in_param)) { - ctx->faultcode = 0; - if (ctx->nextlevel == 0 || check_obj_is_nl1(full_param, ctx->in_param, 1) == 0 ) { - char *p = permission; - add_list_paramameter(ctx, full_param, p, NULL); - return 0; - } - dmfree(full_param); - return 0; //TODO check the return value here! - } - dmfree(full_param); - return FAULT_9005; + return 0; } -static int get_name_emptyin_nl1_param(DMPARAM_API_ARGS) +static int mparam_get_name_in_obj(DMPARAM_ARGS) { + char *refparam; + char *perm = permission->val; + + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + dmastrcat(&refparam, node->current_object, lastname); + add_list_paramameter(dmctx, refparam, perm, NULL, NULL, 0); + return 0; +} + +static int mobj_get_name_in_obj(DMOBJECT_ARGS) +{ + char *refparam; + char *perm = permission->val; + + if (!node->matched) { + return FAULT_9005; + } + + if (dmctx->nextlevel && strcmp(node->current_object, dmctx->in_param) == 0) + return 0; + + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + refparam = node->current_object; + add_list_paramameter(dmctx, refparam, perm, NULL, NULL, 0); return 0; } /* ******************** * get notification * ********************/ -int dm_entry_get_notification(struct dmctx *ctx) +int dm_entry_get_notification(struct dmctx *dmctx) { - unsigned int i; - ctx->faultcode = FAULT_9005; - - if (ctx->in_param[0] == '\0' || check_param_prefix(ctx) == 0) { - ctx->method_obj=&get_notification_obj; - ctx->method_param=&get_notification_param; - ctx->faultcode = 0; - } else if ( ctx->in_param[strlen(ctx->in_param)-1] == '.') { - ctx->method_obj=&get_notification_inparam_isobj_check_obj; - ctx->method_param=&get_notification_inparam_isobj_check_param; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + unsigned char findparam_check = 0; + int err; + + if (dmctx->in_param[0] == '\0' + || rootcmp(dmctx->in_param, root->obj) == 0) { + dmctx->inparam_isparam = 0; + dmctx->findparam = 1; + dmctx->stop = 0; + dmctx->checkobj = NULL; + dmctx->checkleaf = NULL; + dmctx->method_obj = mobj_get_notification; + dmctx->method_param = mparam_get_notification; + findparam_check = 1; + } else if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) == dm_delim) { + dmctx->inparam_isparam = 0; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_get_notification; + dmctx->method_param = mparam_get_notification; + findparam_check = 1; } else { - ctx->method_obj=&get_notification_inparam_isparam_check_obj; - ctx->method_param=&get_notification_inparam_isparam_check_param; - } - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop == 1) - return ret; + dmctx->inparam_isparam = 1; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_get_notification_in_param; + dmctx->method_param = mparam_get_notification_in_param; } - return ctx->faultcode; -} - -static int get_notification_obj(DMOBJECT_API_ARGS) -{ - return 0; -} - -static int get_notification_inparam_isparam_check_obj(DMOBJECT_API_ARGS) -{ - return FAULT_9005; -} - -static int get_notification_inparam_isobj_check_obj(DMOBJECT_API_ARGS) -{ - if (strstr(ctx->current_obj, ctx->in_param)) { - ctx->faultcode = 0; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (findparam_check && dmctx->findparam) return 0; - } - return FAULT_9005; + else + return err; } -static int get_notification_param(DMPARAM_API_ARGS) +static int mparam_get_notification(DMPARAM_ARGS) { - char *full_param; - char *notification; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (forced_notify == UNDEF) { - notification = get_parameter_notification(ctx, full_param); + char *value; + char *refparam; + + dmastrcat(&refparam, node->current_object, lastname); + + if (notification == NULL) { + value = get_parameter_notification(dmctx, refparam); } else { - notification = notifications[forced_notify].value; + value = notification->val; + if (notification->get_notif) + value = notification->get_notif(refparam, dmctx, data, instance); } - add_list_paramameter(ctx, full_param, notification, NULL); + add_list_paramameter(dmctx, refparam, value, NULL, NULL, 0); return 0; } -static int get_notification_inparam_isparam_check_param(DMPARAM_API_ARGS) +static int mobj_get_notification(DMOBJECT_ARGS) { - char *full_param; - char *notification; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (strcmp(full_param, ctx->in_param) != 0) { - dmfree(full_param); + return 0; +} + +static int mparam_get_notification_in_param(DMPARAM_ARGS) +{ + char *value = NULL; + char *refparam; + + dmastrcat(&refparam, node->current_object, lastname); + if (strcmp(refparam, dmctx->in_param) != 0) { + dmfree(refparam); return FAULT_9005; } - if (forced_notify == UNDEF) { - notification = get_parameter_notification(ctx, full_param); + if (notification == NULL) { + value = get_parameter_notification(dmctx, refparam); } else { - notification = notifications[forced_notify].value; + value = notification->val; + if (notification->get_notif) + value = notification->get_notif(refparam, dmctx, data, instance); } - add_list_paramameter(ctx, full_param, notification, NULL); - ctx->stop = true; + add_list_paramameter(dmctx, refparam, value, NULL, NULL, 0); + dmctx->stop = 1; return 0; } -static int get_notification_inparam_isobj_check_param(DMPARAM_API_ARGS) +static int mobj_get_notification_in_param(DMOBJECT_ARGS) { - char *full_param; - char *notification; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (strstr(full_param, ctx->in_param)) { - if (forced_notify == UNDEF) { - notification = get_parameter_notification(ctx, full_param); - } else { - notification = notifications[forced_notify].value; - } - add_list_paramameter(ctx, full_param, notification, NULL); - ctx->faultcode = 0; - return 0; - } - dmfree(full_param); - return FAULT_9005; + return 0; } /*************** -* inform -***************/ -int dm_entry_inform(struct dmctx *ctx) + * inform + ***************/ +int dm_entry_inform(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = {.current_object = ""}; + int err; + + dmctx->inparam_isparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_forcedinform_match; + dmctx->checkleaf = NULL; + dmctx->method_obj = &inform_check_obj; + dmctx->method_param = &inform_check_param; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return err; + else + return FAULT_9005; +} + +static int inform_check_obj(DMOBJECT_ARGS) { - unsigned int i; - ctx->method_obj = &inform_check_obj; - ctx->method_param = &inform_check_param; - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - if (prefix_methods[i].forced_inform) - prefix_methods[i].method(ctx); - } return 0; } -static int inform_check_obj(DMOBJECT_API_ARGS) +static int inform_check_param(DMPARAM_ARGS) { - return FAULT_9005; -} - -static int inform_check_param(DMPARAM_API_ARGS) -{ - if (!forced_inform) - return FAULT_9005; + char *value = ""; char *full_param; - char *value = NULL; - dmastrcat(&full_param, ctx->current_obj, lastname); - (get_cmd)(full_param, ctx, &value); - add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string"); + unsigned char fi; + + if (!forced_inform) + return FAULT_9005; + + if (forced_inform->get_forced_inform) + fi = forced_inform->get_forced_inform(node->current_object, dmctx, data, + instance); + else + fi = forced_inform->val; + + if (!fi) + return FAULT_9005; + + dmastrcat(&full_param, node->current_object, lastname); + (get_cmd)(full_param, dmctx, data, instance, &value); + add_list_paramameter(dmctx, full_param, value, DMT_TYPE[type], NULL, 0); return 0; } /* ************** * add object * **************/ -int dm_entry_add_object(struct dmctx *ctx) +int dm_entry_add_object(struct dmctx *dmctx) { - unsigned int i; - if (ctx->tree) + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + int err; + + if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' + || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim)) return FAULT_9005; - ctx->method_obj=&add_object_obj; - ctx->method_param=&add_object_param; - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop) - return ret; - } + + dmctx->inparam_isparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_onlyobj_match; + dmctx->method_obj = mobj_add_object; + dmctx->method_param = mparam_add_object; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return err; + else + return FAULT_9005; +} + +static int mparam_add_object(DMPARAM_ARGS) +{ return FAULT_9005; } -static int add_object_obj(DMOBJECT_API_ARGS) +static int mobj_add_object(DMOBJECT_ARGS) { - char *instance; - if (strcmp(ctx->current_obj, ctx->in_param) != 0) + char *addinst; + char newparam[256]; + char *refparam = node->current_object; + char *perm = permission->val; + char *objinst; + + if (strcmp(refparam, dmctx->in_param) != 0) return FAULT_9005; - ctx->stop = true; - if (addobj == NULL) - return FAULT_9005; + dmctx->stop = 1; + if (node->is_instanceobj) + return FAULT_9005; + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); - int fault = (addobj)(ctx, &instance); + if (perm[0] == '0' || addobj == NULL) + return FAULT_9005; + + int fault = (addobj)(refparam, dmctx, data, &instance); if (fault) return fault; - - ctx->addobj_instance = instance; - char *objinst; - dmasprintf(&objinst, "%s%s.", ctx->current_obj, instance); - set_parameter_notification(ctx, objinst, "0"); + dmctx->addobj_instance = instance; + dmasprintf(&objinst, "%s%s%c", node->current_object, instance, dm_delim); + set_parameter_notification(dmctx, objinst, "0"); dmfree(objinst); return 0; } - -static int add_object_param(DMPARAM_API_ARGS) -{ - return FAULT_9005; -} - - /* ************** +/* ************** * del object * **************/ -int dm_entry_delete_object(struct dmctx *ctx) +int dm_entry_delete_object(struct dmctx *dmctx) { - unsigned int i; - if (ctx->tree == 1) + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + int err; + + if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' + || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim)) + return FAULT_9005; + + dmctx->inparam_isparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_onlyobj_match; + dmctx->method_obj = delete_object_obj; + dmctx->method_param = delete_object_param; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return err; + else return FAULT_9005; - ctx->method_obj=&delete_object_obj; - ctx->method_param=&delete_object_param; - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop) - return ret; - } - return FAULT_9005; } -static int delete_object_obj(DMOBJECT_API_ARGS) +static int delete_object_obj(DMOBJECT_ARGS) { - if (strcmp(ctx->current_obj, ctx->in_param) != 0) + char *refparam = node->current_object; + char *perm = permission->val; + unsigned char del_action = DEL_INST; + if (strcmp(refparam, dmctx->in_param) != 0) return FAULT_9005; - ctx->stop = true; - if (delobj == NULL) + dmctx->stop = 1; + + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + if (perm[0] == '0' || delobj == NULL) return FAULT_9005; - int fault = (delobj)(ctx); + if (!node->is_instanceobj) + del_action = DEL_ALL; + int fault = (delobj)(refparam, dmctx, data, instance, del_action); return fault; } -static int delete_object_param(DMPARAM_API_ARGS) +static int delete_object_param(DMPARAM_ARGS) { - return FAULT_9005; + return FAULT_9005; } - - /* ************** +/* ************** * set value * **************/ -int dm_entry_set_value(struct dmctx *ctx) +int dm_entry_set_value(struct dmctx *dmctx) { - unsigned int i; - if (ctx->in_param[0] == '\0' || ctx->in_param[strlen(ctx->in_param)-1] == '.' ) { + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + int err; + + if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' + || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) == dm_delim)) + return FAULT_9005; + + dmctx->inparam_isparam = 1; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_set_value; + dmctx->method_param = mparam_set_value; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return err; + else return FAULT_9005; - } else { - ctx->method_obj=&set_value_check_obj; - ctx->method_param=&set_value_check_param; - } - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop) - return ret; - } - return FAULT_9005; -} - -static int set_value_check_obj(DMOBJECT_API_ARGS) -{ - return FAULT_9005; } -static int set_value_check_param(DMPARAM_API_ARGS) +static int mobj_set_value(DMOBJECT_ARGS) { - char *full_param; - char *v; - dmastrcat(&full_param, ctx->current_obj, lastname); + return FAULT_9005; +} - if (strcmp(ctx->in_param, full_param) != 0) { - dmfree(full_param); +static int mparam_set_value(DMPARAM_ARGS) +{ + int err; + char *refparam; + char *perm; + char *v = ""; + + dmastrcat(&refparam, node->current_object, lastname); + if (strcmp(refparam, dmctx->in_param) != 0) { + dmfree(refparam); return FAULT_9005; - } + } + dmctx->stop = 1; - ctx->stop = true; + if (dmctx->setaction == VALUECHECK) { + perm = permission->val; + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); - if (ctx->setaction == VALUECHECK) { - if (permission[0] != '1' || set_cmd == NULL) { - dmfree(full_param); + if (perm[0] == '0' || !set_cmd) { + dmfree(refparam); return FAULT_9008; } - - int fault = (set_cmd)(full_param, ctx, VALUECHECK, ctx->in_value); + int fault = (set_cmd)(refparam, dmctx, data, instance, dmctx->in_value, VALUECHECK); if (fault) { - dmfree(full_param); + dmfree(refparam); return fault; } - - add_set_list_tmp(ctx, ctx->in_param, ctx->in_value); + add_set_list_tmp(dmctx, dmctx->in_param, dmctx->in_value, 0); } - else if (ctx->setaction == VALUESET) { - (set_cmd)(full_param, ctx, VALUESET, ctx->in_value); - //(get_cmd)(full_param, ctx, &v); - dm_update_enabled_notify_byname(full_param, ctx->in_value); + else if (dmctx->setaction == VALUESET) { + (set_cmd)(refparam, dmctx, data, instance, dmctx->in_value, VALUESET); + //(get_cmd)(refparam, dmctx, data, instance, &v); + dm_update_enabled_notify_byname(refparam, dmctx->in_value); } - - dmfree(full_param); + dmfree(refparam); return 0; } - /* **************** +/* **************** * set notification * ****************/ -int dm_entry_set_notification(struct dmctx *ctx) +int dm_entry_set_notification(struct dmctx *dmctx) { - unsigned int i; - if (ctx->in_param[0] == '\0') { + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + unsigned char findparam_check = 0; + int err; + + if (dmcommon_check_notification_value(dmctx->in_notification) < 0) + return FAULT_9003; + + if (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, root->obj) == 0) { return FAULT_9009; + } else if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) == dm_delim) { + dmctx->inparam_isparam = 0; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_set_notification_in_obj; + dmctx->method_param = mparam_set_notification_in_obj; } else { - ctx->method_obj=&set_notification_check_obj; - ctx->method_param=&set_notification_check_param; + dmctx->inparam_isparam = 1; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_set_notification_in_param; + dmctx->method_param = mparam_set_notification_in_param; } - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop) - return ret; - } - return FAULT_9005; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return err; + else + return FAULT_9005; } -static int set_notification_check_obj(DMOBJECT_API_ARGS) +/* SET Notification*/ + +static int mparam_set_notification_in_obj(DMPARAM_ARGS) { - if (strcmp(ctx->in_param, ctx->current_obj) != 0) + return FAULT_9005; +} + +static int mobj_set_notification_in_obj(DMOBJECT_ARGS) +{ + int err; + char *refparam; + char *perm; + char tparam[256]; + + refparam = node->current_object; + if (strcmp(refparam, dmctx->in_param) != 0) { return FAULT_9005; - - ctx->stop = true; - - if (ctx->setaction == VALUECHECK) { - if (!notif_permission) + } + dmctx->stop = 1; + if (!dmctx->notification_change) { + return 0; + } + if (dmctx->setaction == VALUECHECK) { + if (notification) return FAULT_9009; - add_set_list_tmp(ctx, ctx->in_param, ctx->in_notification); + add_set_list_tmp(dmctx, dmctx->in_param, dmctx->in_notification, 0); } - else if (ctx->setaction == VALUESET) { - set_parameter_notification(ctx, ctx->in_param, ctx->in_notification); + else if (dmctx->setaction == VALUESET) { + set_parameter_notification(dmctx, dmctx->in_param, dmctx->in_notification); cwmp_set_end_session(END_SESSION_RELOAD); } return 0; } -static int set_notification_check_param(DMPARAM_API_ARGS) +static int mparam_set_notification_in_param(DMPARAM_ARGS) { - char *full_param; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (strcmp(ctx->in_param, full_param) != 0) { - dmfree(full_param); + int err; + char *refparam; + char tparam[256]; + + dmastrcat(&refparam, node->current_object, lastname); + if (strcmp(refparam, dmctx->in_param) != 0) { + dmfree(refparam); return FAULT_9005; } - ctx->stop = true; - if (ctx->setaction == VALUECHECK) { - if (!notif_permission) { - dmfree(full_param); + dmctx->stop = 1; + if (!dmctx->notification_change) { + return 0; + } + if (dmctx->setaction == VALUECHECK) { + if (notification) { + dmfree(refparam); return FAULT_9009; } - add_set_list_tmp(ctx, ctx->in_param, ctx->in_notification); - } else if (ctx->setaction == VALUESET) { - set_parameter_notification(ctx, ctx->in_param, ctx->in_notification); + add_set_list_tmp(dmctx, dmctx->in_param, dmctx->in_notification, 0); + } else if (dmctx->setaction == VALUESET) { + set_parameter_notification(dmctx, dmctx->in_param, dmctx->in_notification); cwmp_set_end_session(END_SESSION_RELOAD); } - - dmfree(full_param); + dmfree(refparam); return 0; } +static int mobj_set_notification_in_param(DMOBJECT_ARGS) +{ + return FAULT_9005; +} + /********************* * load enabled notify ********************/ -int dm_entry_enabled_notify(struct dmctx *ctx) +int dm_entry_enabled_notify(struct dmctx *dmctx) { - unsigned int i; - ctx->method_obj = &enabled_notify_check_obj; - ctx->method_param = &enabled_notify_check_param; - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - prefix_methods[i].method(ctx); - } - return 0; + int err; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + //unsigned char findparam_check = 0; + + dmctx->method_obj = enabled_notify_check_obj; + dmctx->method_param = enabled_notify_check_param; + dmctx->checkobj = NULL ; + dmctx->checkleaf = NULL; + err = dm_browse(dmctx, &node, root, NULL, NULL); + return err; + } -static int enabled_notify_check_obj(DMOBJECT_API_ARGS) +static int enabled_notify_check_obj(DMOBJECT_ARGS) { return FAULT_9005; } - -static int enabled_notify_check_param(DMPARAM_API_ARGS) +// TO check +static int enabled_notify_check_param(DMPARAM_ARGS) { - char *full_param; - char *value = NULL; - char *notification; + char *refparam; + char *value = ""; + char *notif; - dmastrcat(&full_param, ctx->current_obj, lastname); - if (forced_notify == UNDEF) { - notification = get_parameter_notification(ctx, full_param); + dmastrcat(&refparam, node->current_object, lastname); + + if (notification == NULL) { + notif = get_parameter_notification(dmctx, refparam); } else { - notification = notifications[forced_notify].value; + notif = notification->val; + if (notification->get_notif) + notif = notification->get_notif(refparam, dmctx, data, instance); } - if (notification[0] == '0') { - dmfree(full_param); + if (notif[0] == '0') { + dmfree(refparam); return 0; } - - (get_cmd)(full_param, ctx, &value); - if (notification[0] == '1' || notification[0] == '2' || notification[0] == '4' || notification[0] == '6') - add_list_enabled_notify(full_param, notification, value); - if (notification[0] >= '3') { - add_list_enabled_lwnotify(full_param, notification, value); + (get_cmd)(refparam, dmctx, data, instance, &value); + if (notif[0] == '1' || notif[0] == '2' + || notif[0] == '4' || notif[0] == '6') + add_list_enabled_notify(dmctx, refparam, notif, value); + if (notif[0] >= '3') { + add_list_enabled_lwnotify(dmctx, refparam, notif, value); } - dmfree(full_param); + dmfree(refparam); return 0; } /****************** * get linker param *****************/ -int dm_entry_get_linker(struct dmctx *ctx) +int dm_entry_get_linker(struct dmctx *dmctx) { - unsigned int i; - ctx->method_obj = &get_linker_check_obj; - ctx->method_param = &get_linker_check_param; - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop) - return ret; - } - return 0; + int err; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + + dmctx->method_obj = get_linker_check_obj; + dmctx->method_param = get_linker_check_param; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_onlyobj_match; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return err; + else + return FAULT_9005; } -static int get_linker_check_obj(DMOBJECT_API_ARGS) +static int get_linker_check_obj(DMOBJECT_ARGS) { - if (linker && strcmp(linker, ctx->linker) == 0) { - ctx->linker_param = dmstrdup(ctx->current_obj); - ctx->stop = true; + char *link_val = ""; + + if (!get_linker) { + return FAULT_9005; + } + if (node->obj->browseinstobj && !node->is_instanceobj) { + return FAULT_9005; + } + get_linker(node->current_object, dmctx, data, instance, &link_val); + if (dmctx->linker[0] == '\0') { + return FAULT_9005; + } + if (link_val && link_val[0] != '\0' && strcmp(link_val, dmctx->linker) == 0) { + dmctx->linker_param = dmstrdup(node->current_object); + dmctx->stop = true; return 0; } return FAULT_9005; } -static int get_linker_check_param(DMPARAM_API_ARGS) +static int get_linker_check_param(DMPARAM_ARGS) { - if (linker && strcmp(linker, ctx->linker) == 0) { - dmastrcat(&(ctx->linker_param), ctx->current_obj, lastname); - ctx->stop = true; - return 0; - } return FAULT_9005; } /****************** * get linker value *****************/ -int dm_entry_get_linker_value(struct dmctx *ctx) +int dm_entry_get_linker_value(struct dmctx *dmctx) { - unsigned int i; - ctx->method_obj = &get_linker_value_check_obj; - ctx->method_param = &get_linker_value_check_param; - dmentry_instance_lookup_inparam(ctx); - for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) { - if (!prefix_methods[i].enable) continue; - int ret = prefix_methods[i].method(ctx); - if (ctx->stop) - return ret; + int err ; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + + dmctx->method_obj = get_linker_value_check_obj; + dmctx->method_param = get_linker_value_check_param; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmentry_instance_lookup_inparam(dmctx); + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return err; + else + return FAULT_9005; +} + +static int get_linker_value_check_obj(DMOBJECT_ARGS) +{ + char *link_val; + if (!get_linker) + return FAULT_9005; + + if (strcmp(node->current_object, dmctx->in_param) == 0) { + get_linker(node->current_object, dmctx, data, instance, &link_val); + dmctx->linker = dmstrdup(link_val); + dmctx->stop = true; + return 0; + } + return FAULT_9005; +} + +static int get_linker_value_check_param(DMPARAM_ARGS) +{ + return FAULT_9005; +} + +#ifdef UPNP_TR064 +/* ****************** + * UPNP entries + * ******************/ + +int upnp_map_cwmp_fault(int cwmp_fault) +{ + switch (cwmp_fault) { + case FAULT_9005: + return FAULT_UPNP_703; + case FAULT_9003: + return FAULT_UPNP_701; + case FAULT_9007: + return FAULT_UPNP_705; + case FAULT_9008: + return FAULT_UPNP_706; + } + if (cwmp_fault > __FAULT_UPNP_MAX) + return FAULT_UPNP_701; + return cwmp_fault; +} + +int plugin_upnp_structured_obj_match(DMOBJECT_ARGS) +{ + if (node->matched) + return 0; + if (!dmctx->inparam_isparam && strstructered(node->current_object, dmctx->in_param) == STRUCTERED_SAME) { + node->matched++; + dmctx->findparam = 1; + return 0; + } + if (strstructered(dmctx->in_param, node->current_object) == STRUCTERED_PART) { + return 0; + } + return FAULT_UPNP_703; +} + +int plugin_upnp_leaf_match(DMOBJECT_ARGS) +{ + char *str; + if (node->matched) + return 0; + if (!dmctx->inparam_isparam) + return FAULT_UPNP_703; + str = dmctx->in_param + strlen(node->current_object); + if (!strchr(str, dm_delim)) + return 0; + return FAULT_UPNP_703; +} + +static int plugin_upnp_obj_depth_match(DMOBJECT_ARGS) +{ + if (node->matched) { + node->matched++; + } + else if (strcmp(node->current_object, dmctx->in_param) == 0) { + node->matched++; + dmctx->findparam = 1; + } + else if (strstr(dmctx->in_param, node->current_object) == dmctx->in_param) { + return 0; + } + if (dmctx->depth == 0 || dmctx->depth >= (node->matched - 1)) + return 0; + return FAULT_UPNP_703; +} + +int plugin_upnp_leaf_depth_match(DMOBJECT_ARGS) +{ + char *str; + if (!node->matched) { + if (!dmctx->inparam_isparam) { + return FAULT_UPNP_703; + } + else { + str = dmctx->in_param + strlen(node->current_object); + if (strchr(str, dm_delim)) + return FAULT_UPNP_703; + } + } + if (dmctx->depth == 0) + return 0; + if (dmctx->depth >= node->matched) + return 0; + return FAULT_UPNP_703; +} + +static int plugin_upnp_skip_leafs(DMOBJECT_ARGS) +{ + return FAULT_UPNP_703; +} + +static int upnp_get_parameter_onchange(struct dmctx *ctx, char *param, char *onchange) +{ + struct uci_list *list_onchange; + char *pch; + struct uci_element *e; + dmuci_get_option_value_list(UPNP_CFG, "@notifications[0]", onchange, &list_onchange); + if (list_onchange) { + uci_foreach_element(list_onchange, e) { + pch = e->name; + if (strcmp(pch, param) == 0) { + return 1; + } + } } return 0; } -static int get_linker_value_check_obj(DMOBJECT_API_ARGS) +static int upnp_set_parameter_onchange(struct dmctx *ctx, char *param, char *onchange, unsigned int value) { - if (linker && strcmp(ctx->current_obj, ctx->in_param) == 0) { - ctx->linker = dmstrdup(linker); - ctx->stop = true; - return 0; + char *tmp; + struct uci_section *s; + + dmuci_get_section_type(UPNP_CFG, "@notifications[0]", &tmp); + if (!tmp || tmp[0] == '\0') { + dmuci_add_section(UPNP_CFG, "notifications", &s, &tmp); } - return FAULT_9005; + + dmuci_del_list_value(UPNP_CFG, "@notifications[0]",onchange, param); + if (value) { + dmuci_add_list_value(UPNP_CFG, "@notifications[0]", onchange, param); + } + return 0; } -static int get_linker_value_check_param(DMPARAM_API_ARGS) +void add_list_upnp_param_track(struct dmctx *dmctx, struct list_head *pchead, char *param, char *key, char *value, unsigned int isobj) +{ + struct dm_upnp_enabled_track *dm_upnp_enabled_track; + + dm_upnp_enabled_track = calloc(1, sizeof(struct dm_upnp_enabled_track)); // Should be calloc and not dmcalloc + list_add_tail(&dm_upnp_enabled_track->list, pchead); + dm_upnp_enabled_track->name = strdup(param); // Should be strdup and not dmstrdup + dm_upnp_enabled_track->value = value ? strdup(value) : strdup(""); // Should be strdup and not dmstrdup + dm_upnp_enabled_track->key = key ? strdup(key) : NULL; // Should be strdup and not dmstrdup + dm_upnp_enabled_track->isobj = isobj; +} + +void del_list_upnp_param_track(struct dm_upnp_enabled_track *dm_upnp_enabled_track) +{ + list_del(&dm_upnp_enabled_track->list); // Should be free and not dmfree + free(dm_upnp_enabled_track->name); + free(dm_upnp_enabled_track->value); + free(dm_upnp_enabled_track->key); + free(dm_upnp_enabled_track); +} + +void free_all_list_upnp_param_track(struct list_head *pchead) +{ + struct dm_upnp_enabled_track *dm_upnp_enabled_track; + while (pchead->next != pchead) { + dm_upnp_enabled_track = list_entry(pchead->next, struct dm_upnp_enabled_track, list); + del_list_upnp_param_track(dm_upnp_enabled_track); + } +} + +int get_parameter_version(struct dmctx *ctx, char *param, char **version, struct uci_section **rs) +{ + int found = 0; + struct uci_list *list_struc; + struct uci_section *s = NULL; + char *pch; + unsigned int acl = 0, f; + struct uci_element *e; + + *version = NULL; + *rs = NULL; + + uci_foreach_option_eq(UPNP_CFG, "parameter_version", "parameter", param, s) { + break; + } + if (s != NULL) { + *rs = s; + dmuci_get_value_by_section_string(s, "version", version); + if (**version == '\0') + *version = "0"; + return 1; + } + else { + dmuci_get_option_value_list(UPNP_CFG, "@parameter_version_structured[0]", "paramater", &list_struc); + if (list_struc) { + uci_foreach_element(list_struc, e) { + pch = e->name; + if (strstructered(pch, param) == STRUCTERED_SAME) { + *version = "0"; + return 1; + } + } + } + } + return 0; +} + +unsigned int get_parameter_acl(struct dmctx *ctx, char *param) +{ + int i, maxlen = 0, len; + struct uci_list *list_acl; + char *pch; + unsigned int acl = 0, f; + struct uci_element *e; + + for (i = (ARRAY_SIZE(dm_acl) - 1); i >= 0; i--) { + dmuci_get_option_value_list(UPNP_CFG, "@acl_factorized[0]", dm_acl[i].user_access, &list_acl); + if (list_acl) { + f = 0; + maxlen = 0; + uci_foreach_element(list_acl, e) { + pch = e->name; + if (strstructered(pch, param) == STRUCTERED_SAME) { + f = dm_acl[i].flag; + break; + } + len = strlen(pch); + if (pch[len-1] == dm_delim) { + if (strstructered(param, pch) == STRUCTERED_PART) { + if (len > maxlen ) + { + f = dm_acl[i].flag; + maxlen = len; + } + } + } + } + acl |= f; + } + } + return acl; +} + +unsigned int dm_upnp_check_acl_list(struct dmctx *dmctx, char *param) +{ + unsigned int flag; + unsigned int mask = DM_LIST_MASK | DM_READ_MASK | DM_WRITE_MASK; + flag = get_parameter_acl(dmctx, param); + if (flag & mask & dmctx->user_mask) + return flag; + return 0; +} + +unsigned int dm_upnp_check_acl_read(struct dmctx *dmctx, char *param) +{ + unsigned int flag; + unsigned int mask = DM_READ_MASK | DM_WRITE_MASK; + flag = get_parameter_acl(dmctx, param); + if (flag & mask & dmctx->user_mask) + return flag; + return 0; +} + +unsigned int dm_upnp_check_acl_write(struct dmctx *dmctx, char *param) +{ + unsigned int flag; + unsigned int mask = DM_WRITE_MASK; + flag = get_parameter_acl(dmctx, param); + if (flag & mask & dmctx->user_mask) + return flag; + return 0; +} + +int dm_entry_upnp_update_attribute_values_update(struct dmctx *dmctx) +{ + char *v, *tmp, buf[32]; + struct uci_section *s; + int version; + time_t time_value; + + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "attribute_values_version", &v); + version = atoi(v); + version++; + + dmuci_get_section_type(UPNP_CFG, "@dm[0]", &tmp); + if (!tmp || tmp[0] == '\0') { + dmuci_add_section(UPNP_CFG, "dm", &s, &tmp); + } + sprintf(buf, "%d", version); + dmuci_set_value(UPNP_CFG, "@dm[0]", "attribute_values_version", buf); + sprintf(buf, "%ld", time(NULL)); + dmuci_set_value(UPNP_CFG, "@dm[0]", "attribute_values_epochtime", buf); + + return 0; +} + +/* ****************** + * UPNP get instances + * ******************/ + +int dm_entry_upnp_get_instances(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = {.current_object = ""}; + int err; + char buf[4] = {0}; + buf[0] = dm_delim; + + if (*(dmctx->in_param) == '\0') + dmctx->in_param = buf; + + if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim) + return FAULT_UPNP_701; + + dmctx->inparam_isparam = 0; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_upnp_obj_depth_match; + dmctx->checkleaf = plugin_upnp_skip_leafs; + dmctx->method_obj = mobj_upnp_get_instances; + dmctx->method_param = mparam_upnp_get_instances; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int mparam_upnp_get_instances(DMPARAM_ARGS) +{ + return 0; +} + +static int mobj_upnp_get_instances(DMOBJECT_ARGS) { char *refparam; - dmastrcat(&refparam, ctx->current_obj, lastname); - if (linker && strcmp(refparam, ctx->in_param) == 0) { - ctx->linker = dmstrdup(linker); - ctx->stop = true; - return 0; + refparam = node->current_object; + if (!node->is_instanceobj || !node->matched) + return FAULT_UPNP_703; + if (!dm_upnp_check_acl_read(dmctx, refparam)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; } - return FAULT_9005; + add_list_paramameter(dmctx, refparam, NULL, NULL, NULL, 0); + return 0; } +/* ***************************** + * UPNP get supported parameters + * *****************************/ + +int dm_entry_upnp_get_supported_parameters(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = {.current_object = ""}; + int err; + + char buf[4] = {0}; + buf[0] = dm_delim; + + if (*(dmctx->in_param) == '\0') + dmctx->in_param = buf; + + if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim) + dmctx->inparam_isparam = 1; + else + dmctx->inparam_isparam = 0; + dmctx->instance_wildchar = "#"; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_upnp_obj_depth_match; + dmctx->checkleaf = plugin_upnp_leaf_depth_match; + dmctx->method_obj = mobj_upnp_get_supportedparams; + dmctx->method_param = mparam_upnp_get_supportedparams; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int mparam_upnp_get_supportedparams(DMPARAM_ARGS) +{ + char *refparam; + dmastrcat(&refparam, node->current_object, lastname); + if (dmctx->inparam_isparam) { + if (strcmp(refparam, dmctx->in_param) == 0) { + if (!dm_upnp_check_acl_list(dmctx, refparam)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + dmctx->findparam = 1; + add_list_paramameter(dmctx, refparam, NULL, NULL, NULL, 0); + return 0; + } + } + else { + if (!dm_upnp_check_acl_list(dmctx, refparam)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + add_list_paramameter(dmctx, refparam, NULL, NULL, NULL, 0); + return 0; + } + return FAULT_UPNP_703; +} + +static int mobj_upnp_get_supportedparams(DMOBJECT_ARGS) +{ + char *refparam; + if (node->matched <= 1) + return FAULT_UPNP_703; + if (dmctx->depth == (node->matched - 1)) { + if (node->obj->browseinstobj && !node->is_instanceobj) + dmastrcat(&refparam, node->current_object, "#/"); + else + refparam = node->current_object; + if (!dm_upnp_check_acl_list(dmctx, refparam)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + add_list_paramameter(dmctx, refparam, NULL, NULL, NULL, 0); + return 0; + } + return FAULT_UPNP_703; +} + +/* ************************ + * UPNP get selected values + * ************************/ + +int dm_entry_upnp_get_selected_values(struct dmctx *dmctx) +{ + int i; + int err = 0; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = {.current_object = ""}; + + if (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, root->obj) == 0) { + dmctx->inparam_isparam = 0; + dmctx->method_obj = get_value_obj; + dmctx->method_param = get_value_param; + dmctx->checkobj = NULL; + dmctx->checkleaf = NULL; + dmctx->findparam = 1; + dmctx->stop = 0; + } else if (dmctx->in_param[strlen(dmctx->in_param) - 1] == dm_delim) { + dmctx->inparam_isparam = 0; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_upnp_structured_obj_match; + dmctx->checkleaf = plugin_upnp_leaf_match; + dmctx->method_obj = get_value_obj; + dmctx->method_param = get_value_param; + } else { + dmctx->inparam_isparam = 1; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_upnp_structured_obj_match; + dmctx->checkleaf = plugin_upnp_leaf_match; + dmctx->method_obj = mobj_get_value_in_param; + dmctx->method_param = mparam_upnp_structured_get_value_in_param; + } + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int mparam_upnp_structured_get_value_in_param(DMPARAM_ARGS) +{ + char *full_param; + char *value = ""; + + dmastrcat(&full_param, node->current_object, lastname); + if (strstructered(dmctx->in_param, full_param) == STRUCTERED_NULL) { + dmfree(full_param); + return FAULT_UPNP_703; + } + if (!dm_upnp_check_acl_read(dmctx, full_param)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + dmctx->findparam = 1; + (get_cmd)(full_param, dmctx, data, instance, &value); + add_list_paramameter(dmctx, full_param, value, DMT_TYPE[type], NULL, 0); + return 0; +} + +/* *************** + * UPNP get values + * ***************/ + +int dm_entry_upnp_get_values(struct dmctx *dmctx) +{ + int i; + int err = 0; + unsigned char findparam_check = 0; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = {.current_object = ""}; + + if (dmctx->in_param[0] == '\0' || rootcmp(dmctx->in_param, root->obj) == 0) { + dmctx->inparam_isparam = 0; + dmctx->method_obj = upnp_get_value_obj; + dmctx->method_param = upnp_get_value_param; + dmctx->checkobj = NULL; + dmctx->checkleaf = NULL; + dmctx->findparam = 1; + dmctx->stop = 0; + findparam_check = 1; + } else if (dmctx->in_param[strlen(dmctx->in_param) - 1] == dm_delim) { + dmctx->inparam_isparam = 0; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = upnp_get_value_obj; + dmctx->method_param = upnp_get_value_param; + findparam_check = 1; + } else { + dmctx->inparam_isparam = 1; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_upnp_get_value_in_param; + dmctx->method_param = mparam_upnp_get_value_in_param; + } + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (findparam_check && dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int upnp_get_value_obj(DMOBJECT_ARGS) +{ + return 0; +} + +static int upnp_get_value_param(DMPARAM_ARGS) +{ + char *full_param; + char *value = ""; + + dmastrcat(&full_param, node->current_object, lastname); + if (!dm_upnp_check_acl_read(dmctx, full_param)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + (get_cmd)(full_param, dmctx, data, instance, &value); + add_list_paramameter(dmctx, full_param, value, NULL, NULL, 0); + return 0; +} + +static int mobj_upnp_get_value_in_param(DMOBJECT_ARGS) +{ + return 0; +} +static int mparam_upnp_get_value_in_param(DMPARAM_ARGS) +{ + char *full_param; + char *value = ""; + + dmastrcat(&full_param, node->current_object, lastname); + if (strcmp(dmctx->in_param, full_param) != 0) { + dmfree(full_param); + return FAULT_UPNP_703; + } + + if (!dm_upnp_check_acl_read(dmctx, full_param)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + (get_cmd)(full_param, dmctx, data, instance, &value); + add_list_paramameter(dmctx, full_param, value, NULL, NULL, 0); + dmctx->stop = 1; + return 0; +} + +/* *************** + * UPNP set values + * ***************/ + +int dm_entry_upnp_set_values(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + int err; + + if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' + || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) == dm_delim)) + return FAULT_UPNP_703; + + dmctx->inparam_isparam = 1; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_upnp_set_value; + dmctx->method_param = mparam_upnp_set_value; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return (upnp_map_cwmp_fault(err)); + else + return FAULT_UPNP_703; +} + +static int mobj_upnp_set_value(DMOBJECT_ARGS) +{ + return FAULT_UPNP_703; +} + +static int mparam_upnp_set_value(DMPARAM_ARGS) +{ + int err; + char *refparam; + char *perm; + char *v = ""; + + dmastrcat(&refparam, node->current_object, lastname); + if (strcmp(refparam, dmctx->in_param) != 0) { + dmfree(refparam); + return FAULT_UPNP_703; + } + dmctx->stop = 1; + + if (dmctx->setaction == VALUECHECK) { + perm = permission->val; + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + if (perm[0] == '0' || !set_cmd) { + dmfree(refparam); + return FAULT_UPNP_706; + } + if (!dm_upnp_check_acl_write(dmctx, refparam)) { + dmctx->findparam = 0; + return FAULT_UPNP_706; + } + int fault = (set_cmd)(refparam, dmctx, data, instance, dmctx->in_value, VALUECHECK); + if (fault) { + dmfree(refparam); + return fault; + } + add_set_list_tmp(dmctx, dmctx->in_param, dmctx->in_value, 0); + } + else if (dmctx->setaction == VALUESET) { + (set_cmd)(refparam, dmctx, data, instance, dmctx->in_value, VALUESET); + (get_cmd)(refparam, dmctx, data, instance, &v); + dm_update_enabled_notify_byname(refparam, v); + } + dmfree(refparam); + return 0; +} + +/* ******************** + * UPNP delete instance + * *******************/ + +int dm_entry_upnp_delete_instance(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + int err; + + if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' + || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim)) + return FAULT_UPNP_703; + + dmctx->inparam_isparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_onlyobj_match; + dmctx->method_obj = upnp_delete_instance_obj; + dmctx->method_param = upnp_delete_instance_param; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return (upnp_map_cwmp_fault(err)); + else + return FAULT_UPNP_703; +} + +static int upnp_delete_instance_obj(DMOBJECT_ARGS) +{ + char *refparam = node->current_object; + char *perm = permission->val; + unsigned char del_action = DEL_INST; + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + dmctx->stop = 1; + + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + if (perm[0] == '0' || delobj == NULL) + return FAULT_UPNP_706; + + if (!dm_upnp_check_acl_write(dmctx, refparam)) { + dmctx->findparam = 0; + return FAULT_UPNP_706; + } + + if (!node->is_instanceobj) + del_action = DEL_ALL; + int fault = (delobj)(refparam, dmctx, data, instance, del_action); + return fault; +} + +static int upnp_delete_instance_param(DMPARAM_ARGS) +{ + return FAULT_UPNP_703; +} + +/* ******************** + * UPNP add instance + * *******************/ + +int dm_entry_upnp_add_instance(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + int err; + + if (dmctx->in_param == NULL || dmctx->in_param[0] == '\0' + || (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim)) + return FAULT_UPNP_703; + + dmctx->inparam_isparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_onlyobj_match; + dmctx->method_obj = mobj_upnp_add_instance; + dmctx->method_param = mparam_upnp_add_instance; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->stop) + return (upnp_map_cwmp_fault(err)); + else + return FAULT_UPNP_703; +} + +static int mparam_upnp_add_instance(DMPARAM_ARGS) +{ + return FAULT_UPNP_703; +} + +static int mobj_upnp_add_instance(DMOBJECT_ARGS) +{ + char *addinst; + char newparam[256]; + char *refparam = node->current_object; + char *perm = permission->val; + char *objinst; + + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + dmctx->stop = 1; + if (node->is_instanceobj) + return FAULT_UPNP_703; + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + if (perm[0] == '0' || addobj == NULL) + return FAULT_UPNP_706; + + if (!dm_upnp_check_acl_write(dmctx, refparam)) { + dmctx->findparam = 0; + return FAULT_UPNP_706; + } + + int fault = (addobj)(refparam, dmctx, data, &instance); + if (fault) + return fault; + dmctx->addobj_instance = instance; + dmasprintf(&objinst, "%s%s%c", node->current_object, instance, dm_delim); + set_parameter_notification(dmctx, objinst, "0"); + dmfree(objinst); + return 0; +} + +/* ******************** + * UPNP get attributes + * ********************/ +int dm_entry_upnp_get_attributes(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + unsigned char findparam_check = 0; + int err; + char buf[4] = {0}; + buf[0] = dm_delim; + + if (*(dmctx->in_param) == '\0') + dmctx->in_param = buf; + + if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim) + dmctx->inparam_isparam = 1; + else + dmctx->inparam_isparam = 0; + + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_upnp_get_attributes; + dmctx->method_param = mparam_upnp_get_attributes; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int mparam_upnp_get_attributes(DMPARAM_ARGS) +{ + char *refparam; + unsigned int flags = 0; + char *perm = permission->val; + char *version = NULL; + struct uci_section *s = NULL; + + dmastrcat(&refparam, node->current_object, lastname); + + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + if (!dm_upnp_check_acl_read(dmctx, refparam)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + + dmctx->stop = 1; + + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + perm = (*perm == '1') ? "readWrite" : "readOnly"; + + if (upnp_get_parameter_onchange(dmctx, refparam, "alarmchange")) + flags |= DM_PARAM_ALARAM_ON_CHANGE; + if (upnp_get_parameter_onchange(dmctx, refparam, "eventchange")) + flags |= DM_PARAM_EVENT_ON_CHANGE; + get_parameter_version(dmctx, refparam, &version, &s); + flags |= UPNP_DMT_TYPE[type]; + + add_list_paramameter(dmctx, refparam, perm, NULL, version, flags); + return 0; +} + +static int mobj_upnp_get_attributes(DMOBJECT_ARGS) +{ + char *refparam; + unsigned int flags = 0; + char *perm = permission->val; + char *version = NULL; + char *type; + struct uci_section *s = NULL; + + refparam = node->current_object; + + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + if (!dm_upnp_check_acl_read(dmctx, refparam)) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + + dmctx->stop = 1; + + if (permission->get_permission != NULL) + perm = permission->get_permission(refparam, dmctx, data, instance); + + perm = (*perm == '1') ? "readWrite" : "readOnly"; + + if (!node->is_instanceobj && upnp_get_parameter_onchange(dmctx, refparam, "eventchange")) + flags |= DM_PARAM_EVENT_ON_CHANGE; + + get_parameter_version(dmctx, refparam, &version, &s); + + if (node->is_instanceobj) + flags |= (NODE_DATA_ATTRIBUTE_INSTANCE | NODE_DATA_ATTRIBUTE_TYPEPTR); + else if (node->obj->browseinstobj) + flags |= (NODE_DATA_ATTRIBUTE_MULTIINSTANCE | NODE_DATA_ATTRIBUTE_TYPEPTR); + + add_list_paramameter(dmctx, refparam, perm, NULL, version, flags); + + return 0; +} + +/* ******************** + * UPNP set attributes + * ********************/ +int dm_entry_upnp_set_attributes(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + unsigned char findparam_check = 0; + int err; + char buf[4] = {0}; + buf[0] = dm_delim; + + if (*(dmctx->in_param) == '\0') + dmctx->in_param = buf; + + if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim) + dmctx->inparam_isparam = 1; + else + dmctx->inparam_isparam = 0; + + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_upnp_set_attributes; + dmctx->method_param = mparam_upnp_set_attributes; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int mparam_upnp_set_attributes(DMPARAM_ARGS) +{ + char *refparam; + unsigned int flags = 0; + char *perm = permission->val; + + dmastrcat(&refparam, node->current_object, lastname); + + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + dmctx->stop = 1; + if (dmctx->setaction == VALUECHECK) { + if (!dm_upnp_check_acl_write(dmctx, refparam)) { + dmctx->findparam = 0; + return FAULT_UPNP_706; + } + add_set_list_tmp(dmctx, dmctx->in_param, NULL, dmctx->dmparam_flags); + } + else { + upnp_set_parameter_onchange(dmctx, refparam, "alarmchange", dmctx->dmparam_flags & DM_PARAM_ALARAM_ON_CHANGE); + upnp_set_parameter_onchange(dmctx, refparam, "eventchange", dmctx->dmparam_flags & DM_PARAM_EVENT_ON_CHANGE); + dm_entry_upnp_update_attribute_values_update(dmctx); + } + return 0; +} + +static int mobj_upnp_set_attributes(DMOBJECT_ARGS) +{ + char *refparam; + unsigned int flags = 0; + char *perm = permission->val; + + refparam = node->current_object; + + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + dmctx->stop = 1; + + if (dmctx->setaction == VALUECHECK) { + if (!dm_upnp_check_acl_write(dmctx, refparam)) { + dmctx->findparam = 0; + return FAULT_UPNP_706; + } + add_set_list_tmp(dmctx, dmctx->in_param, NULL, dmctx->dmparam_flags); + } + else { + if (!node->is_instanceobj) { + upnp_set_parameter_onchange(dmctx, refparam, "eventchange", dmctx->dmparam_flags & DM_PARAM_EVENT_ON_CHANGE); + dm_entry_upnp_update_attribute_values_update(dmctx); + } + } + return 0; +} + +/* ******************* + * UPNP get ACL data + * ******************/ + +int dm_entry_upnp_get_acl_data(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + unsigned char findparam_check = 0; + int err; + char buf[4] = {0}; + buf[0] = dm_delim; + + if (*(dmctx->in_param) == '\0') + dmctx->in_param = buf; + + if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim) + dmctx->inparam_isparam = 1; + else + dmctx->inparam_isparam = 0; + + if (strchr(dmctx->in_param, '#')) + dmctx->instance_wildchar = "#"; + else + dmctx->instance_wildchar = NULL; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_obj_match; + dmctx->checkleaf = plugin_leaf_match; + dmctx->method_obj = mobj_upnp_get_acldata; + dmctx->method_param = mparam_upnp_get_acldata; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int mparam_upnp_get_acldata(DMPARAM_ARGS) +{ + char *refparam; + unsigned int flags = 0; + char *perm = permission->val; + + dmastrcat(&refparam, node->current_object, lastname); + + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + flags = dm_upnp_check_acl_list(dmctx, refparam); + if (!flags) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + + dmctx->stop = 1; + + add_list_paramameter(dmctx, refparam, NULL, NULL, NULL, flags); + return 0; +} + +static int mobj_upnp_get_acldata(DMOBJECT_ARGS) +{ + char *refparam; + unsigned int flags = 0; + char *perm = permission->val; + + refparam = node->current_object; + + if (strcmp(refparam, dmctx->in_param) != 0) + return FAULT_UPNP_703; + + flags = dm_upnp_check_acl_list(dmctx, refparam); + if (!flags) { + dmctx->findparam = 0; + dmctx->stop = 1; + return FAULT_UPNP_703; + } + + dmctx->stop = 1; + flags |= DM_FACTORIZED; + + add_list_paramameter(dmctx, refparam, NULL, NULL, NULL, flags); + return 0; +} + +/* ************************** + * UPNP get instance numbers + * *************************/ + +char *dm_entry_get_all_instance_numbers(struct dmctx *pctx, char *param) +{ + static char instbuf[256]; + struct dmctx dmctx = {0}; + + dm_ctx_init_sub(&dmctx, pctx->dm_type, pctx->amd_version, pctx->instance_mode); + dmctx.in_param = param; + dmctx.depth = 1; + dm_entry_upnp_get_instance_numbers(&dmctx); + strcpy(instbuf, dmctx.all_instances); + dm_ctx_clean_sub(&dmctx); + return instbuf; +} + +int dm_entry_upnp_get_instance_numbers(struct dmctx *dmctx) +{ + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = {.current_object = ""}; + int err; + char buf[4] = {0}; + buf[0] = dm_delim; + + if (*(dmctx->in_param) == '\0') + dmctx->in_param = buf; + + if (*(dmctx->in_param + strlen(dmctx->in_param) - 1) != dm_delim) + return FAULT_UPNP_701; + + dmctx->inparam_isparam = 0; + dmctx->findparam = 0; + dmctx->stop = 0; + dmctx->checkobj = plugin_upnp_obj_depth_match; + dmctx->checkleaf = plugin_upnp_skip_leafs; + dmctx->method_obj = mobj_upnp_get_instance_numbers; + dmctx->method_param = mparam_upnp_get_instance_numbers; + err = dm_browse(dmctx, &node, root, NULL, NULL); + if (dmctx->findparam) + return 0; + else + return (upnp_map_cwmp_fault(err)); +} + +static int mparam_upnp_get_instance_numbers(DMPARAM_ARGS) +{ + return 0; +} + +static int mobj_upnp_get_instance_numbers(DMOBJECT_ARGS) +{ + char *refparam; + refparam = node->current_object; + if (!node->is_instanceobj || !node->matched) + return FAULT_UPNP_703; + if (*(dmctx->all_instances)) { + strcat(dmctx->all_instances, ","); + } + strcat(dmctx->all_instances, instance); + return 0; +} + +/************************************ + * upnp load tracked parameter values + ***********************************/ +int dm_entry_upnp_tracked_parameters(struct dmctx *dmctx) +{ + int err; + DMOBJ *root = dmctx->dm_entryobj; + DMNODE node = { .current_object = "" }; + + dmctx->method_obj = enabled_tracked_param_check_obj; + dmctx->method_param = enabled_tracked_param_check_param; + dmctx->checkobj = NULL ; + dmctx->checkleaf = NULL; + err = dm_browse(dmctx, &node, root, NULL, NULL); + return err; +} + +static int enabled_tracked_param_check_obj(DMOBJECT_ARGS) +{ + char *refparam; + char *all_instances; + char *version = "0"; + struct uci_section *s; + int isevnt, isversion; + + refparam = node->current_object; + if (!node->obj->browseinstobj || node->is_instanceobj) + return FAULT_UPNP_703; + + isevnt = upnp_get_parameter_onchange(dmctx, refparam, "eventchange"); + isversion = get_parameter_version(dmctx, refparam, &version, &s); + if (isevnt || isversion) + all_instances = dm_entry_get_all_instance_numbers(dmctx, refparam); + + if (isevnt) { + add_list_upnp_param_track(dmctx, &list_upnp_enabled_onevent, refparam, "1", all_instances, 1); + } + if (isversion) { + add_list_upnp_param_track(dmctx, &list_upnp_enabled_version, refparam, (s ? section_name(s) : NULL), all_instances, 1); + } + return 0; +} + +static int enabled_tracked_param_check_param(DMPARAM_ARGS) +{ + char *refparam; + char *value = ""; + char *version = "0"; + struct uci_section *s; + int isalrm, isevnt, isversion; + + dmastrcat(&refparam, node->current_object, lastname); + isalrm = upnp_get_parameter_onchange(dmctx, refparam, "alarmchange"); + isevnt = upnp_get_parameter_onchange(dmctx, refparam, "eventchange"); + isversion = get_parameter_version(dmctx, refparam, &version, &s); + + if (isalrm || isevnt || isversion) + (get_cmd)(refparam, dmctx, data, instance, &value); + if (isalrm) { + add_list_upnp_param_track(dmctx, &list_upnp_enabled_onalarm, refparam, "1", value, 0); + } + if (isevnt) { + add_list_upnp_param_track(dmctx, &list_upnp_enabled_onevent, refparam, "1", value, 0); + } + if (isversion) { + add_list_upnp_param_track(dmctx, &list_upnp_enabled_version, refparam, (s ? section_name(s) : NULL), value, 0); + } + + dmfree(refparam); + return 0; +} +#endif + +/********************/ + +int dm_add_end_session(struct dmctx *ctx, void(*function)(struct execute_end_session *), int action, void *data) +{ + struct execute_end_session *execute_end_session; + + execute_end_session = calloc (1,sizeof(struct execute_end_session)); + if (execute_end_session == NULL) + { + return -1; + } + execute_end_session->action = action; + execute_end_session->data = data; + execute_end_session->function = function; + execute_end_session->amd_version = ctx->amd_version; + execute_end_session->instance_mode = ctx->instance_mode; + execute_end_session->dm_type = ctx->dm_type; + list_add_tail (&(execute_end_session->list), &(list_execute_end_session)); + + return 0; +} + +int cwmp_free_dm_end_session(struct execute_end_session *execute_end_session) +{ + if(execute_end_session != NULL) + { + FREE(execute_end_session); + } + return 0; +} + +int apply_end_session() +{ + struct execute_end_session *p, *q; + list_for_each_entry_safe(p, q, &(list_execute_end_session), list) { + p->function(p); + list_del(&(p->list)); + cwmp_free_dm_end_session(p); + } + return 0; +} + +void cwmp_set_end_session (unsigned int flag) +{ + end_session_flag |= flag; +} + +char *dm_print_path(char *fpath, ...) +{ + static char pathbuf[512] = ""; + va_list vl; + + va_start(vl, fpath); + vsprintf(pathbuf, fpath, vl); + va_end(vl); + return pathbuf; +} diff --git a/dm/dmcwmp.h b/dm/dmcwmp.h index 774d2c5..1b9200b 100644 --- a/dm/dmcwmp.h +++ b/dm/dmcwmp.h @@ -21,85 +21,139 @@ #include "dmmem.h" #ifdef DATAMODEL_TR098 -#define DMROOT "InternetGatewayDevice." +#define DMROOT_CWMP "InternetGatewayDevice" #endif #ifdef DATAMODEL_TR181 -#define DMROOT "Device." +#define DMROOT_CWMP "Device" #endif + +#ifdef UPNP_TR064 +#define DMROOT_UPNP "" + +#define DMDELIM_UPNP '/' +#endif + +#define DMDELIM_CWMP '.' + +#define DM_PROMPT "icwmp>" + +#ifdef UPNP_TR064 +#define UPNP_CFG "tr064" +#endif + #ifdef UNDEF #undef UNDEF #endif - #define UNDEF -1 #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #endif -#define IF_MATCH(ctx, prefix, ...) \ - (ctx)->match = (ctx)->tree; \ - if (!(ctx)->tree) { \ - sprintf((ctx)->current_obj, prefix, ##__VA_ARGS__); \ - if (strstr((ctx)->in_param, (ctx)->current_obj) || \ - (strstr((ctx)->current_obj, (ctx)->in_param) && \ - (ctx)->in_param[strlen((ctx)->in_param)-1] == '.')) { \ - (ctx)->match = true; \ - } \ - } \ - if ((ctx)->match) +#ifndef FREE +#define FREE(x) do { free(x); x = NULL; } while (0) +#endif -#define IF_MATCH_ROOT(ctx) \ - (ctx)->match = (ctx)->tree; \ - if (!(ctx)->tree) { \ - if (strstr((ctx)->in_param, DMROOT) && \ - !strchr(((ctx)->in_param + sizeof(DMROOT) - 1), '.')) { \ - (ctx)->match = true; \ - } \ - } \ - if ((ctx)->match) +extern struct dm_permession_s DMREAD; +extern struct dm_permession_s DMWRITE; +extern struct dm_forced_inform_s DMFINFRM; -#define DMOBJECT(name, ctx, permission, notif_permission, addobj, delobj, linker, ...) { \ - sprintf((ctx)->current_obj, name, ##__VA_ARGS__); \ - int error = ctx->method_obj(ctx, permission, notif_permission, addobj, delobj, linker); \ - if ((ctx)->stop) return error; \ -} +extern struct dm_notif_s DMNONE; +extern struct dm_notif_s DMACTIVE; +extern struct dm_notif_s DMPASSIVE; -#define DMPARAM(lastname, ctx, permission, get_cmd, set_cmd, type, forced_inform, notif_permission, forced_notify, linker) { \ - int error = ctx->method_param(lastname, ctx, permission, get_cmd, set_cmd, type, forced_inform, notif_permission, forced_notify, linker); \ - if ((ctx)->stop) return error; \ -} - -#define SUBENTRY(f, ctx, ...) { \ - int error = f(ctx, ## __VA_ARGS__); \ - if ((ctx)->stop) return error; \ -} - -#define DMPARAM_API_ARGS \ +#define DMPARAM_ARGS \ + struct dmctx *dmctx, \ + struct dmnode *node, \ char *lastname, \ - struct dmctx *ctx, \ - char *permission, \ - int (*get_cmd)(char *refparam, struct dmctx *ctx, char **value), \ - int (*set_cmd)(char *refparam, struct dmctx *ctx, int action, char *value), \ - char *type, \ - bool forced_inform, \ - bool notif_permission, \ - int forced_notify, \ - char *linker + struct dm_permession_s *permission, \ + int type, \ + int (*get_cmd)(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value), \ + int (*set_cmd)(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action), \ + struct dm_forced_inform_s *forced_inform, \ + struct dm_notif_s *notification, \ + void *data, \ + char *instance -#define DMOBJECT_API_ARGS \ - struct dmctx *ctx, \ - char *permission, \ - bool notif_permission, \ - int (*addobj)(struct dmctx *ctx, char **instance), \ - int (*delobj)(struct dmctx *ctx), \ - char *linker +#define DMOBJECT_ARGS \ + struct dmctx *dmctx, \ + struct dmnode *node, \ + struct dm_permession_s *permission, \ + int (*addobj)(char *refparam, struct dmctx *ctx, void *data, char **instance), \ + int (*delobj)(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action), \ + struct dm_forced_inform_s *forced_inform, \ + struct dm_notif_s *notification, \ + int (*get_linker)(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker), \ + void *data, \ + char *instance #define TAILLE_MAX 1024 - + +struct dm_forced_inform_s; +struct dm_permession_s; +struct dm_parameter; +struct dm_leaf_s; +struct dm_obj_s; +struct dmnode; +struct dmctx; +struct dm_notif_s; + +struct dm_permession_s { + char *val; + char *(*get_permission)(char *refparam, struct dmctx *dmctx, void *data, char *instance); +}; + +struct dm_forced_inform_s { + unsigned char val; + unsigned char (*get_forced_inform)(char *refparam, struct dmctx *dmctx, void *data, char *instance); +}; + +struct dm_notif_s { + char *val; + char *(*get_notif)(char *refparam, struct dmctx *dmctx, void *data, char *instance); +}; + +typedef struct dm_leaf_s { + /* PARAM, permission, type, getvalue, setvalue, forced_inform, notification(7)*/ + char *parameter; + struct dm_permession_s *permission; + int type; + int (*getvalue)(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + int (*setvalue)(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + struct dm_forced_inform_s *forced_inform; + struct dm_notif_s *notification; +} DMLEAF; + +typedef struct dm_obj_s { + /* OBJ, permission, addobj, delobj, browseinstobj, forced_inform, notification, nextobj, leaf, linker(10)*/ + char *obj; + struct dm_permession_s *permission; + int (*addobj)(char *refparam, struct dmctx *ctx, void *data, char **instance); + int (*delobj)(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + bool (*checkobj)(struct dmctx *dmctx, void *data); + int (*browseinstobj)(struct dmctx *dmctx, struct dmnode *node, void *data, char *instance); + struct dm_forced_inform_s *forced_inform; + struct dm_notif_s *notification; + struct dm_obj_s *nextobj; + struct dm_leaf_s *leaf; + int (*get_linker)(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +} DMOBJ; + +#ifdef UPNP_TR064 +typedef struct dm_upnp_supported_dm_s { + char *location; + char *uri; + char *url; + char *description; + char *source_location; +} UPNP_SUPPORTED_DM; +#endif + struct set_tmp { struct list_head list; char *name; char *value; + unsigned int flags; }; struct param_fault { @@ -115,41 +169,72 @@ struct dm_enabled_notify { char *value; }; +#ifdef UPNP_TR064 +struct dm_upnp_enabled_track { + struct list_head list; + char *name; + char *key; + char *value; + unsigned int isobj; +}; +#endif + struct dm_parameter { struct list_head list; char *name; char *data; char *type; + char *version; + unsigned int flags; }; struct dmctx { bool stop; - bool tree; bool match; - int (*method_param)(DMPARAM_API_ARGS); - int (*method_obj)(DMOBJECT_API_ARGS); - void *args; + int (*method_param)(DMPARAM_ARGS); + int (*method_obj)(DMOBJECT_ARGS); + int (*checkobj)(DMOBJECT_ARGS); + int (*checkleaf)(DMOBJECT_ARGS); struct list_head list_parameter; struct list_head set_list_tmp; struct list_head list_fault_param; + DMOBJ *dm_entryobj; bool nextlevel; + int depth; int faultcode; int setaction; char *in_param; - char *in_notification; + char *in_notification; + bool notification_change; char *in_value; char *addobj_instance; char *linker; char *linker_param; + unsigned int dmparam_flags; unsigned int alias_register; unsigned int nbrof_instance; unsigned int amd_version; unsigned int instance_mode; - char current_obj[512]; + unsigned int dm_type; + unsigned int user_mask; + unsigned char inparam_isparam; + unsigned char findparam; + char all_instances[512]; char *inst_buf[16]; + char *instance_wildchar; }; + +typedef struct dmnode { + DMOBJ *obj; + struct dmnode *parent; + char *current_object; + unsigned char instance_level; + unsigned char matched; + unsigned char is_instanceobj; +} DMNODE; + struct prefix_method { const char *prefix_name; bool enable; @@ -163,11 +248,30 @@ struct notification { char *type; }; +struct dm_acl { + unsigned int flag; + char *user_access; +}; + +typedef struct execute_end_session { + struct list_head list; + int action; + unsigned int dm_type; + unsigned int amd_version; + unsigned int instance_mode; + void *data; + void (*function)(struct execute_end_session *); +} execute_end_session; + enum set_value_action { VALUECHECK, VALUESET }; +enum del_action_enum { + DEL_INST, + DEL_ALL +}; enum { CMD_GET_VALUE, CMD_GET_NAME, @@ -177,9 +281,35 @@ enum { CMD_ADD_OBJECT, CMD_DEL_OBJECT, CMD_INFORM, +#ifdef UPNP_TR064 + CMD_UPNP_GET_SUPPORTED_PARAMETERS, + CMD_UPNP_GET_INSTANCES, + CMD_UPNP_GET_SELECTED_VALUES, + CMD_UPNP_GET_VALUES, + CMD_UPNP_SET_VALUES, + CMD_UPNP_GET_ATTRIBUTES, + CMD_UPNP_SET_ATTRIBUTES, + CMD_UPNP_DEL_INSTANCE, + CMD_UPNP_ADD_INSTANCE, + CMD_UPNP_GET_ACLDATA, + CMD_UPNP_INIT_STATE_VARIABLES, + CMD_UPNP_LOAD_ENABLED_PARAMETRS_TRACK, + CMD_UPNP_GET_CONFIGURATION_UPDATE, + CMD_UPNP_GET_CURRENT_CONFIGURATION_VERSION, + CMD_UPNP_GET_SUPPORTED_DATA_MODEL_UPDATE, + CMD_UPNP_GET_SUPPORTED_PARAMETERS_UPDATE, + CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE, + CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM, + CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT, + CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION, + CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM, + CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT, + CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION, +#endif + CMD_EXTERNAL_COMMAND }; -enum fault_code { +enum fault_code_enum { FAULT_9000 = 9000,// Method not supported FAULT_9001,// Request denied FAULT_9002,// Internal error @@ -216,6 +346,21 @@ enum fault_code { __FAULT_MAX }; +#ifdef UPNP_TR064 +enum upnp_fault_code_enum { + FAULT_UPNP_606 = 606,// Action not authorized + FAULT_UPNP_701 = 701,// Invalid Argument Syntax + FAULT_UPNP_702,//Invalid XML Argument + FAULT_UPNP_703,// No Such Name + FAULT_UPNP_704,// Invalid Value Type + FAULT_UPNP_705,// Invalid Value + FAULT_UPNP_706,// Read Only Violation + FAULT_UPNP_707,// Multiple Set + FAULT_UPNP_708,// Resource Temporarily Unavailable + __FAULT_UPNP_MAX +}; +#endif + enum { INSTANCE_UPDATE_NUMBER, INSTANCE_UPDATE_ALIAS @@ -226,19 +371,111 @@ enum instance_mode { INSTANCE_MODE_ALIAS }; +enum end_session_enum { + END_SESSION_REBOOT = 1, + END_SESSION_EXTERNAL_ACTION = 1<<1, + END_SESSION_RELOAD = 1<<2, + END_SESSION_FACTORY_RESET = 1<<3, + END_SESSION_IPPING_DIAGNOSTIC = 1<<4, + END_SESSION_DOWNLOAD_DIAGNOSTIC = 1<<5, + END_SESSION_UPLOAD_DIAGNOSTIC = 1<<6, + END_SESSION_X_FACTORY_RESET_SOFT = 1<<7 +}; + +enum dm_browse_enum { + DM_ERROR = -1, + DM_OK = 0, + DM_STOP = 1 +}; + +enum dmt_type_enum { + DMT_STRING, + DMT_UNINT, + DMT_INT, + DMT_LONG, + DMT_BOOL, + DMT_TIME, + DMT_HEXBIN, +}; + +enum amd_version_enum{ + AMD_1 = 1, + AMD_2, + AMD_3, + AMD_4, + AMD_5, +}; + +enum dm_type_enum{ + DM_CWMP, + DM_UPNP, +}; + +enum dm_param_flags_enum{ + /* UPNP OnChange flags flags */ + DM_PARAM_ALARAM_ON_CHANGE = 1 << 0, + DM_PARAM_EVENT_ON_CHANGE = 1 << 1, + /* UPNP type flags */ + NODE_DATA_ATTRIBUTE_INSTANCE = 0x0010, + NODE_DATA_ATTRIBUTE_MULTIINSTANCE = 0x0020, + NODE_DATA_ATTRIBUTE_TYPESTRING = 0x0100, + NODE_DATA_ATTRIBUTE_TYPEINT = 0x0200, + NODE_DATA_ATTRIBUTE_TYPELONG = 0x0400, + NODE_DATA_ATTRIBUTE_TYPEBOOL = 0x0800, + NODE_DATA_ATTRIBUTE_TYPEDATETIME = 0x1000, + NODE_DATA_ATTRIBUTE_TYPEBASE64 = 0x2000, + NODE_DATA_ATTRIBUTE_TYPEBIN = 0x4000, + NODE_DATA_ATTRIBUTE_TYPEPTR = 0x8000, + NODE_DATA_ATTRIBUTE_TYPEMASK = 0x0000FF00, + /*ACLRoles*/ + DM_PUBLIC_LIST = 1 << 0, + DM_PUBLIC_READ = 1 << 1, + DM_PUBLIC_WRITE = 1 << 2, + DM_PUBLIC_MASK = DM_PUBLIC_LIST|DM_PUBLIC_READ|DM_PUBLIC_WRITE, + DM_BASIC_LIST = 1 << 3, + DM_BASIC_READ = 1 << 4, + DM_BASIC_WRITE = 1 << 5, + DM_BASIC_MASK = DM_PUBLIC_MASK|DM_BASIC_LIST|DM_BASIC_READ|DM_BASIC_WRITE, + DM_XXXADMIN_LIST = 1 << 6, + DM_XXXADMIN_READ = 1 << 7, + DM_XXXADMIN_WRITE = 1 << 8, + DM_XXXADMIN_MASK = DM_BASIC_MASK|DM_XXXADMIN_LIST|DM_XXXADMIN_READ|DM_XXXADMIN_WRITE, + DM_SUPERADMIN_MASK = DM_XXXADMIN_MASK | (1 << 9), + DM_LIST_MASK = DM_PUBLIC_LIST|DM_BASIC_LIST|DM_XXXADMIN_LIST, + DM_READ_MASK = DM_PUBLIC_READ|DM_BASIC_READ|DM_XXXADMIN_READ, + DM_WRITE_MASK = DM_PUBLIC_WRITE|DM_BASIC_WRITE|DM_XXXADMIN_WRITE, + DM_FACTORIZED = 1 << 31 +}; + extern struct list_head list_enabled_notify; extern struct list_head list_enabled_lw_notify; +extern struct list_head list_execute_end_session; + +#ifdef UPNP_TR064 +extern struct list_head list_upnp_enabled_onevent; +extern struct list_head list_upnp_enabled_onalarm; +extern struct list_head list_upnp_enabled_version; +extern struct list_head list_upnp_changed_onevent; +extern struct list_head list_upnp_changed_onalarm; +extern struct list_head list_upnp_changed_version; +#endif + +extern int end_session_flag; +extern int ip_version; +extern char dm_delim; +extern char DMROOT[64]; +extern unsigned int upnp_in_user_mask; char *update_instance(struct uci_section *s, char *last_inst, char *inst_opt); char *update_instance_icwmpd(struct uci_section *s, char *last_inst, char *inst_opt); char *update_instance_alias_icwmpd(int action, char **last_inst , void *argv[]); char *update_instance_alias(int action, char **last_inst , void *argv[]); char *update_instance_without_section(int action, char **last_inst, void *argv[]); -int get_empty(char *refparam, struct dmctx *args, char **value); -void add_list_paramameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type); +int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +void add_list_paramameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type, char *param_version, unsigned int flags); void del_list_parameter(struct dm_parameter *dm_parameter); void free_all_list_parameter(struct dmctx *ctx); -void add_set_list_tmp(struct dmctx *ctx, char *param, char *value); +void add_set_list_tmp(struct dmctx *ctx, char *param, char *value, unsigned int flags); void del_set_list_tmp(struct set_tmp *set_tmp); void free_all_set_list_tmp(struct dmctx *ctx); void add_list_fault_param(struct dmctx *ctx, char *param, int fault); @@ -253,19 +490,52 @@ int dm_entry_add_object(struct dmctx *ctx); int dm_entry_delete_object(struct dmctx *ctx); int dm_entry_set_value(struct dmctx *ctx); int dm_entry_set_notification(struct dmctx *ctx); -int dm_entry_set_prefix_methods_enable(void); int dm_entry_enabled_notify(struct dmctx *ctx); int dm_entry_get_linker(struct dmctx *ctx); int dm_entry_get_linker_value(struct dmctx *ctx); +#ifdef UPNP_TR064 +int dm_entry_upnp_get_instances(struct dmctx *ctx); +int dm_entry_upnp_get_selected_values(struct dmctx *dmctx); +int dm_entry_upnp_get_values(struct dmctx *dmctx); +int dm_entry_upnp_set_values(struct dmctx *dmctx); +int dm_entry_upnp_get_attributes(struct dmctx *dmctx); +int upnp_state_variables_init(struct dmctx *dmctx); +int dm_entry_upnp_tracked_parameters(struct dmctx *dmctx); +int dm_entry_upnp_get_instance_numbers(struct dmctx *dmctx); +char *dm_entry_get_all_instance_numbers(struct dmctx *pctx, char *param); void free_all_list_enabled_notify(); +void free_all_list_upnp_param_track(struct list_head *head); +#endif void dm_update_enabled_notify(struct dm_enabled_notify *p, char *new_value); void dm_update_enabled_notify_byname(char *name, char *new_value); char *get_last_instance(char *package, char *section, char *opt_inst); char *get_last_instance_icwmpd(char *package, char *section, char *opt_inst); char *get_last_instance_lev2(char *package, char *section, char *opt_inst, char *opt_check, char *value_check); char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **last_inst, char * (*up_instance)(int action, char **last_inst, void *argv[]), int argc, ...); - +int dm_add_end_session(struct dmctx *ctx, void(*function)(struct execute_end_session *), int action, void *data); +int apply_end_session(); +void cwmp_set_end_session (unsigned int flag); +char *dm_print_path(char *fpath, ...); +#ifdef UPNP_TR064 +void dm_upnp_apply_config(void); +void add_list_upnp_param_track(struct dmctx *dmctx, struct list_head *pchead, char *param, char *key, char *value, unsigned int isobj); +int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance); +int dm_entry_upnp_get_supported_parameters(struct dmctx *dmctx); +int dm_entry_upnp_set_attributes(struct dmctx *dmctx); +int dm_entry_upnp_delete_instance(struct dmctx *dmctx); +int dm_entry_upnp_get_acl_data(struct dmctx *dmctx); void free_all_list_enabled_lwnotify(); +int dm_entry_upnp_add_instance(struct dmctx *dmctx); +#endif + +static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance) +{ + dmctx->faultcode = dm_link_inst_obj(dmctx, parent_node, data, instance); + if (dmctx->stop) + return DM_STOP; + return DM_OK; +} + #ifndef TRACE #define TRACE_TYPE 0 static inline void trace_empty_func() @@ -274,9 +544,11 @@ static inline void trace_empty_func() #if TRACE_TYPE == 2 #define TRACE(MESSAGE,args...) do { \ const char *A[] = {MESSAGE}; \ - printf("TRACE: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\ + fprintf(stderr, "TRACE: %s %s %d ",__FUNCTION__,__FILE__,__LINE__); \ if(sizeof(A) > 0) \ - printf(*A,##args); \ + fprintf(stderr, *A,##args); \ + fprintf(stderr, "\n"); \ + fflush(stderr); \ } while(0) #elif TRACE_TYPE == 1 #define TRACE(MESSAGE, ...) printf(MESSAGE, ## __VA_ARGS__) @@ -285,8 +557,6 @@ static inline void trace_empty_func() #endif #endif - - #ifndef DETECT_CRASH #define DETECT_CRASH(MESSAGE,args...) { \ const char *A[] = {MESSAGE}; \ diff --git a/dm/dmentry.c b/dm/dmentry.c index 332d4ac..66db8c0 100644 --- a/dm/dmentry.c +++ b/dm/dmentry.c @@ -15,21 +15,59 @@ #include "dmubus.h" #include "dmuci.h" #include "dmentry.h" +#include "root.h" #include "cwmp.h" #include "log.h" #include "wepkey.h" +#include +#include LIST_HEAD(head_package_change); +unsigned char dmcli_timetrack = 0; +unsigned char dmcli_evaluatetest = 0; -int dm_global_init(void) +static void print_dm_help(void) { - dm_entry_set_prefix_methods_enable(); - return 0; + printf("Usage:\n"); + printf(" get_value [param]\n"); + printf(" set_value [ ] .... [ ]\n"); + printf(" get_name \n"); + printf(" get_notification [param]\n"); + printf(" set_notification [ ] ....[ ]\n"); + printf(" add_obj \n"); + printf(" del_obj \n"); + printf(" inform\n"); +#ifdef UPNP_TR064 + printf(" upnp_get_values [param]\n"); + printf(" upnp_get_selected_values [param]\n"); + printf(" upnp_get_instances \n"); + printf(" upnp_get_supported_parameters \n"); + printf(" upnp_set_values [ ] .... [ ]\n"); + printf(" upnp_get_attributes \n"); + printf(" upnp_set_attributes .... [ \n"); + printf(" upnp_add_instance [ ] [ ] .... [ ]\n"); + printf(" upnp_delete_instance \n"); + printf(" upnp_get_acldata \n"); + printf(" upnp_init_state_variables\n"); + printf(" upnp_get_supported_parameters_update\n"); + printf(" upnp_get_supported_datamodel_update\n"); + printf(" upnp_get_configuration_update\n"); + printf(" upnp_get_current_configuration_version\n"); + printf(" upnp_get_attribute_values_update\n"); + printf(" upnp_load_enabled_parametrs_track\n"); + printf(" upnp_get_enabled_parametrs_alarm\n"); + printf(" upnp_get_enabled_parametrs_event\n"); + printf(" upnp_get_enabled_parametrs_version\n"); + printf(" upnp_check_changed_parametrs_alarm\n"); + printf(" upnp_check_changed_parametrs_event\n"); + printf(" upnp_check_changed_parametrs_version\n"); +#endif + printf(" external_command [arg 1] [arg 2] ... [arg N]\n"); + printf(" exit\n"); } -static int dm_ctx_init_custom(struct dmctx *ctx, int custom) +static int dm_ctx_init_custom(struct dmctx *ctx, unsigned int dm_type, unsigned int amd_version, unsigned int instance_mode, int custom) { - struct cwmp *cwmp = &cwmp_main; if (custom == CTX_INIT_ALL) { memset(&dmubus_ctx, 0, sizeof(struct dmubus_ctx)); INIT_LIST_HEAD(&dmubus_ctx.obj_head); @@ -40,11 +78,26 @@ static int dm_ctx_init_custom(struct dmctx *ctx, int custom) INIT_LIST_HEAD(&ctx->list_parameter); INIT_LIST_HEAD(&ctx->set_list_tmp); INIT_LIST_HEAD(&ctx->list_fault_param); - if(cwmp->conf.supported_amd_version == 0) - get_amd_version_config(); - get_instance_mode_config(); - ctx->amd_version = cwmp->conf.amd_version; - ctx->instance_mode = cwmp->conf.instance_mode; + ctx->amd_version = amd_version; + ctx->instance_mode = instance_mode; + ctx->dm_type = dm_type; +#ifdef UPNP_TR064 + if (dm_type == DM_UPNP) { + strcpy(DMROOT, DMROOT_UPNP); + dm_delim = DMDELIM_UPNP; + ctx->dm_entryobj = tEntryObjUPNP; + ctx->user_mask = upnp_in_user_mask; + } + else { + strcpy(DMROOT, DMROOT_CWMP); + dm_delim = DMDELIM_CWMP; + ctx->dm_entryobj = tEntryObj; + } +#else + strcpy(DMROOT, DMROOT_CWMP); + dm_delim = DMDELIM_CWMP; + ctx->dm_entryobj = tEntryObj; +#endif return 0; } @@ -66,9 +119,9 @@ static int dm_ctx_clean_custom(struct dmctx *ctx, int custom) return 0; } -int dm_ctx_init(struct dmctx *ctx) +int dm_ctx_init(struct dmctx *ctx, unsigned int dm_type, unsigned int amd_version, unsigned int instance_mode) { - dm_ctx_init_custom(ctx, CTX_INIT_ALL); + dm_ctx_init_custom(ctx, dm_type, amd_version, instance_mode, CTX_INIT_ALL); return 0; } @@ -78,9 +131,9 @@ int dm_ctx_clean(struct dmctx *ctx) return 0; } -int dm_ctx_init_sub(struct dmctx *ctx) +int dm_ctx_init_sub(struct dmctx *ctx, unsigned int dm_type, unsigned int amd_version, unsigned int instance_mode) { - dm_ctx_init_custom(ctx, CTX_INIT_SUB); + dm_ctx_init_custom(ctx, dm_type, amd_version, instance_mode, CTX_INIT_SUB); return 0; } @@ -95,7 +148,9 @@ void dmentry_instance_lookup_inparam(struct dmctx *ctx) char *pch, *spch, *in_param; in_param = dmstrdup(ctx->in_param); int i = 0; - for (pch = strtok_r(in_param, ".", &spch); pch != NULL; pch = strtok_r(NULL, ".", &spch)) { + char pat[2] = {0}; + *pat = dm_delim; + for (pch = strtok_r(in_param, pat, &spch); pch != NULL; pch = strtok_r(NULL, pat, &spch)) { if (pch[0]== '[') { ctx->alias_register |= (1 << i); i++; @@ -111,27 +166,22 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, { int fault = 0; bool setnotif = true; + bool alarm = false, event = false; + int err, err2; if (!inparam) inparam = ""; ctx->in_param = inparam; dmentry_instance_lookup_inparam(ctx); - if (ctx->in_param[0] == '\0' || strcmp(ctx->in_param, DMROOT) == 0) { - ctx->tree = true; - } else { - ctx->tree = false; - } ctx->stop = false; switch(cmd) { case CMD_GET_VALUE: - CWMP_LOG(DEBUG,"Get Value Param : %s\n",ctx->in_param); - if (ctx->in_param[0] == '.' && strlen(ctx->in_param) == 1) + if (ctx->dm_type == DM_CWMP && ctx->in_param[0] == dm_delim && strlen(ctx->in_param) == 1) fault = FAULT_9005; else fault = dm_entry_get_value(ctx); break; case CMD_GET_NAME: - CWMP_LOG(DEBUG,"Get Name Param : %s Level %s\n",ctx->in_param, arg1); - if (ctx->in_param[0] == '.' && strlen(ctx->in_param) == 1) + if (ctx->dm_type == DM_CWMP && ctx->in_param[0] == dm_delim && strlen(ctx->in_param) == 1) fault = FAULT_9005; else if (arg1 && string_to_bool(arg1, &ctx->nextlevel) == 0){ fault = dm_entry_get_name(ctx); @@ -140,8 +190,7 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, } break; case CMD_GET_NOTIFICATION: - CWMP_LOG(DEBUG,"Get Notification Param : %s \n",ctx->in_param); - if (ctx->in_param[0] == '.' && strlen(ctx->in_param) == 1) + if (ctx->dm_type == DM_CWMP && ctx->in_param[0] == dm_delim && strlen(ctx->in_param) == 1) fault = FAULT_9005; else fault = dm_entry_get_notification(ctx); @@ -149,15 +198,14 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, case CMD_SET_VALUE: ctx->in_value = arg1 ? arg1 : ""; ctx->setaction = VALUECHECK; - CWMP_LOG(DEBUG,"Set Value Param: %s Value: %s\n",ctx->in_param, ctx->in_value); fault = dm_entry_set_value(ctx); if (fault) add_list_fault_param(ctx, ctx->in_param, fault); break; case CMD_SET_NOTIFICATION: if (arg2) - string_to_bool(arg2, &setnotif); - if (setnotif && arg1 && + err = string_to_bool(arg2, &setnotif); + if (!err && arg1 && (strcmp(arg1, "0") == 0 || strcmp(arg1, "1") == 0 || strcmp(arg1, "2") == 0 || @@ -167,6 +215,7 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, strcmp(arg1, "6") == 0)) { ctx->in_notification = arg1; ctx->setaction = VALUECHECK; + ctx->notification_change = setnotif; fault = dm_entry_set_notification(ctx); } else { fault = FAULT_9003; @@ -176,7 +225,6 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, dm_entry_inform(ctx); break; case CMD_ADD_OBJECT: - CWMP_LOG(DEBUG,"Object To Add: %s \n",ctx->in_param); fault = dm_entry_add_object(ctx); if (!fault) { dmuci_set_value("cwmp", "acs", "ParameterKey", arg1 ? arg1 : ""); @@ -184,13 +232,65 @@ int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, } break; case CMD_DEL_OBJECT: - CWMP_LOG(DEBUG,"Object To Del: %s \n",ctx->in_param); fault = dm_entry_delete_object(ctx); if (!fault) { dmuci_set_value("cwmp", "acs", "ParameterKey", arg1 ? arg1 : ""); dmuci_change_packages(&head_package_change); } break; +#ifdef UPNP_TR064 + case CMD_UPNP_GET_SUPPORTED_PARAMETERS: + ctx->depth = atoi(arg1); + fault = dm_entry_upnp_get_supported_parameters(ctx); + break; + case CMD_UPNP_GET_VALUES: + fault = dm_entry_upnp_get_values(ctx); + break; + case CMD_UPNP_GET_SELECTED_VALUES: + fault = dm_entry_upnp_get_selected_values(ctx); + break; + case CMD_UPNP_GET_INSTANCES: + ctx->depth = atoi(arg1); + fault = dm_entry_upnp_get_instances(ctx); + break; + case CMD_UPNP_SET_VALUES: + ctx->in_value = arg1 ? arg1 : ""; + ctx->setaction = VALUECHECK; + fault = dm_entry_upnp_set_values(ctx); + break; + case CMD_UPNP_SET_ATTRIBUTES: + if (arg1) + err = string_to_bool(arg1, &event); + if (arg2) + err2 = string_to_bool(arg2, &alarm); + if (!err && !err2) { + ctx->dmparam_flags |= (event) ? DM_PARAM_EVENT_ON_CHANGE : 0; + ctx->dmparam_flags |= (alarm) ? DM_PARAM_ALARAM_ON_CHANGE : 0; + ctx->setaction = VALUECHECK; + fault = dm_entry_upnp_set_attributes(ctx); + } else { + fault = FAULT_9003; + } + break; + case CMD_UPNP_GET_ATTRIBUTES: + fault = dm_entry_upnp_get_attributes(ctx); + break; + case CMD_UPNP_DEL_INSTANCE: + fault = dm_entry_upnp_delete_instance(ctx); + if (!fault) { + dmuci_change_packages(&head_package_change); + } + break; + case CMD_UPNP_ADD_INSTANCE: + fault = dm_entry_upnp_add_instance(ctx); + if (!fault) { + dmuci_change_packages(&head_package_change); + } + break; + case CMD_UPNP_GET_ACLDATA: + fault = dm_entry_upnp_get_acl_data(ctx); + break; +#endif } dmuci_commit(); return fault; @@ -204,7 +304,6 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2) switch(cmd) { case CMD_SET_VALUE: ctx->setaction = VALUESET; - ctx->tree = false; list_for_each_entry_safe(n, p, &ctx->set_list_tmp, list) { ctx->in_param = n->name; ctx->in_value = n->value ? n->value : ""; @@ -225,7 +324,6 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2) break; case CMD_SET_NOTIFICATION: ctx->setaction = VALUESET; - ctx->tree = false; list_for_each_entry_safe(n, p, &ctx->set_list_tmp, list) { ctx->in_param = n->name; ctx->in_notification = n->value ? n->value : "0"; @@ -241,17 +339,52 @@ int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2) } free_all_set_list_tmp(ctx); break; +#ifdef UPNP_TR064 + case CMD_UPNP_SET_VALUES: + ctx->setaction = VALUESET; + list_for_each_entry_safe(n, p, &ctx->set_list_tmp, list) { + ctx->in_param = n->name; + ctx->in_value = n->value ? n->value : ""; + ctx->stop = false; + fault = dm_entry_upnp_set_values(ctx); + if (fault) break; + } + if (fault) { + //Should not happen + dmuci_revert(); + } else { + dmuci_change_packages(&head_package_change); + dmuci_commit(); + } + break; + case CMD_UPNP_SET_ATTRIBUTES: + ctx->setaction = VALUESET; + list_for_each_entry_safe(n, p, &ctx->set_list_tmp, list) { + ctx->in_param = n->name; + ctx->dmparam_flags = n->flags; + ctx->stop = false; + fault = dm_entry_upnp_set_attributes(ctx); + if (fault) break; + } + if (fault) { + //Should not happen + dmuci_revert(); + } else { + dmuci_commit(); + } + free_all_set_list_tmp(ctx); + break; +#endif } return fault; } -int dm_entry_load_enabled_notify() +int dm_entry_load_enabled_notify(unsigned int dm_type, unsigned int amd_version, int instance_mode) { struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + dm_ctx_init(&dmctx, dm_type, amd_version, instance_mode); dmctx.in_param = ""; - dmctx.tree = true; free_all_list_enabled_lwnotify(); free_all_list_enabled_notify(); @@ -261,29 +394,21 @@ int dm_entry_load_enabled_notify() return 0; } -int adm_entry_get_linker_param(char *param, char *linker, char **value) +int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, char **value) { struct dmctx dmctx = {0}; - dm_ctx_init_sub(&dmctx); + dm_ctx_init_sub(&dmctx, ctx->dm_type, ctx->amd_version, ctx->instance_mode); dmctx.in_param = param ? param : ""; dmctx.linker = linker; - - if (dmctx.in_param[0] == '\0') { - dmctx.tree = true; - } else { - dmctx.tree = false; - } - dm_entry_get_linker(&dmctx); *value = dmctx.linker_param; - dm_ctx_clean_sub(&dmctx); return 0; } -int adm_entry_get_linker_value(char *param, char **value) +int adm_entry_get_linker_value(struct dmctx *ctx, char *param, char **value) { struct dmctx dmctx = {0}; *value = NULL; @@ -292,9 +417,8 @@ int adm_entry_get_linker_value(char *param, char **value) return 0; } - dm_ctx_init_sub(&dmctx); + dm_ctx_init_sub(&dmctx, ctx->dm_type, ctx->amd_version, ctx->instance_mode); dmctx.in_param = param; - dmctx.tree = false; dm_entry_get_linker_value(&dmctx); *value = dmctx.linker; @@ -303,7 +427,331 @@ int adm_entry_get_linker_value(char *param, char **value) return 0; } -int dm_entry_restart_services() +#ifdef UPNP_TR064 +/**************************************** + * upnp load tracked on change parameters + ****************************************/ + +int dm_entry_upnp_load_tracked_parameters(struct dmctx *dmctx) +{ + + dmctx->in_param = ""; + + free_all_list_upnp_param_track(&list_upnp_enabled_onevent); + free_all_list_upnp_param_track(&list_upnp_enabled_onalarm); + free_all_list_upnp_param_track(&list_upnp_enabled_version); + dm_entry_upnp_tracked_parameters(dmctx); + + return 0; +} + +/********************************************* + * upnp check on change params (event & alarm) + *********************************************/ + +void dm_upnp_update_enabled_track_value(struct dm_upnp_enabled_track *p, char *new_value) +{ + free(p->value); // Should be free and not dmfree + p->value = strdup(new_value); +} + +void dm_upnp_update_enabled_track_key(struct dm_upnp_enabled_track *p, char *key) +{ + free(p->key); // Should be free and not dmfree + p->key = strdup(key); +} + +int dm_entry_upnp_check_onchange_param(struct dmctx *pctx, struct list_head *enabled_head, struct list_head *changed_head) +{ + struct dmctx dmctx = {0}; + struct dm_upnp_enabled_track *p; + struct dm_parameter *dm_parameter; + int fault; + int ischange = 0; + char *all_instances; + + list_for_each_entry(p, enabled_head, list) { + dm_ctx_init_sub(&dmctx, pctx->dm_type, pctx->amd_version, pctx->instance_mode); + dmctx.user_mask = DM_SUPERADMIN_MASK; + if (p->isobj) { + all_instances = dm_entry_get_all_instance_numbers(&dmctx, p->name); + if (all_instances && strcmp(all_instances, p->value) != 0) { + dm_upnp_update_enabled_track_value(p, all_instances); + add_list_upnp_param_track(&dmctx, changed_head, p->name, "1", all_instances, 1); + ischange = 1; + } + } + else { + fault = dm_entry_param_method(&dmctx, CMD_UPNP_GET_VALUES, p->name, NULL, NULL); + if (!fault && dmctx.list_parameter.next != &dmctx.list_parameter) { + dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list); + if (strcmp(dm_parameter->data, p->value) != 0) { + dm_upnp_update_enabled_track_value(p, dm_parameter->data); + add_list_upnp_param_track(&dmctx, changed_head, p->name, "1", dm_parameter->data, 0); + ischange = 1; + } + } + free_all_list_parameter(&dmctx); + } + dm_ctx_clean_sub(&dmctx); + memset(&dmctx, 0, sizeof(struct dmctx)); + } + return ischange; +} + +int dm_entry_upnp_check_alarmonchange_param(struct dmctx *dmctx) +{ + int r; + r = dm_entry_upnp_check_onchange_param(dmctx, &list_upnp_enabled_onalarm, &list_upnp_changed_onalarm); + return r; +} + +int dm_entry_upnp_check_eventonchange_param(struct dmctx *dmctx) +{ + int r; + r = dm_entry_upnp_check_onchange_param(dmctx, &list_upnp_enabled_onevent, &list_upnp_changed_onevent); + return r; +} + +/************************************* + * upnp check on change version params + *************************************/ + +int dm_entry_upnp_update_version_configuration(struct dmctx *dmctx) +{ + char *v, *tmp, buf[32]; + struct uci_section *s; + int version; + + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "current_configuration_version", &v); + version = atoi(v); + version++; + + dmuci_get_section_type(UPNP_CFG, "@dm[0]", &tmp); + if (!tmp || tmp[0] == '\0') { + dmuci_add_section(UPNP_CFG, "dm", &s, &tmp); + } + sprintf(buf, "%d", version); + dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_version", buf); + sprintf(buf, "%ld", time(NULL)); + dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_epochtime", buf); + + return version; +} + +int dm_entry_upnp_check_versiononchange_param(struct dmctx *pctx) +{ + struct dmctx dmctx = {0}; + struct dm_upnp_enabled_track *p; + struct dm_parameter *dm_parameter; + int version, fault; + int ischange; + char *all_instances; + + list_for_each_entry(p, &list_upnp_enabled_version, list) { + ischange = 0; + dm_ctx_init_sub(&dmctx, pctx->dm_type, pctx->amd_version, pctx->instance_mode); + dmctx.user_mask = DM_SUPERADMIN_MASK; + if (p->isobj) { + all_instances = dm_entry_get_all_instance_numbers(&dmctx, p->name); + if (strcmp(all_instances, p->value) != 0) { + dm_upnp_update_enabled_track_value(p, all_instances); + add_list_upnp_param_track(&dmctx, &list_upnp_changed_version, p->name, "1", all_instances, 1); + ischange = 1; + } + } + else { + fault = dm_entry_param_method(&dmctx, CMD_UPNP_GET_VALUES, p->name, NULL, NULL); + if (!fault && dmctx.list_parameter.next != &dmctx.list_parameter) { + dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list); + if (strcmp(dm_parameter->data, p->value) != 0) { + dm_upnp_update_enabled_track_value(p, dm_parameter->data); + add_list_upnp_param_track(&dmctx, &list_upnp_changed_version, p->name, p->key, dm_parameter->data, 0); + ischange = 1; + } + } + free_all_list_parameter(&dmctx); + } + if (ischange) + { + char buf[32]; + char *tmp; + struct uci_section *s = NULL; + version = dm_entry_upnp_update_version_configuration(&dmctx); + sprintf(buf, "%d", version); + if (p->key) { + dmuci_set_value(UPNP_CFG, p->key, "version", buf); + } + else { + dmuci_add_section(UPNP_CFG, "parameter_version", &s, &tmp); + if (s != NULL) { + dmuci_set_value_by_section(s, "version", buf); + dmuci_set_value_by_section(s, "parameter", p->name); + dm_upnp_update_enabled_track_key(p, section_name(s)); + } + } + dmuci_commit(); + } + dm_ctx_clean_sub(&dmctx); + memset(&dmctx, 0, sizeof(struct dmctx)); + } + return ischange; +} + +/* ************************* + * UPNP init state variables + * ************************/ +int upnp_state_variables_init(struct dmctx *dmctx) +{ + char *v, *tmp; + struct uci_section *s; + char buf[32]; + int n; + + dmuci_get_section_type(UPNP_CFG, "@dm[0]", &tmp); + if (!tmp || tmp[0] == '\0') { + dmuci_add_section(UPNP_CFG, "dm", &s, &tmp); + } + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "supported_datamodel_version", &v); + n = atoi(v); + if (n != UPNP_SUPPORTED_DATAMODEL_VERSION) { + sprintf(buf, "%d", UPNP_SUPPORTED_DATAMODEL_VERSION); + dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_datamodel_version", buf); + sprintf(buf, "%ld", time(NULL)); + dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_datamodel_epochtime", buf); + } + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "supported_parameters_version", &v); + n = atoi(v); + if (n != UPNP_SUPPORTED_PARAMETERS_VERSION) { + sprintf(buf, "%d", UPNP_SUPPORTED_PARAMETERS_VERSION); + dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_parameters_version", buf); + sprintf(buf, "%ld", time(NULL)); + dmuci_set_value(UPNP_CFG, "@dm[0]", "supported_parameters_epochtime", buf); + } + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "current_configuration_version", &v); + if (*v == '\0') { + dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_version", "0"); + sprintf(buf, "%ld", time(NULL)); + dmuci_set_value(UPNP_CFG, "@dm[0]", "current_configuration_epochtime", buf); + } + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "attribute_values_version", &v); + if (*v == '\0') { + dmuci_set_value(UPNP_CFG, "@dm[0]", "attribute_values_version", "0"); + sprintf(buf, "%ld", time(NULL)); + dmuci_set_value(UPNP_CFG, "@dm[0]", "attribute_values_epochtime", buf); + } + + dmuci_commit(); + return 0; +} + +/* ************************************ + * UPNP get supported parameters update + * ***********************************/ + +int dm_entry_upnp_get_supported_parameters_update(struct dmctx *dmctx, char **value) +{ + static char csv[128] = ""; + char *v; + time_t time_value; + + *value = csv; + + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "supported_parameters_epochtime", &v); + if (v[0] != '0' && v[0] != '\0') { + time_value = atoi(v); + char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; + strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value)); + sprintf(csv, "%d,%s", UPNP_SUPPORTED_PARAMETERS_VERSION, s_now); + } + + return 0; +} + +/* ************************************ + * UPNP get supported_datamodel update + * ***********************************/ + +int dm_entry_upnp_get_supported_datamodel_update(struct dmctx *dmctx, char **value) +{ + static char csv[128] = ""; + char *v; + time_t time_value; + + *value = csv; + + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "supported_datamodel_epochtime", &v); + if (v[0] != '0' && v[0] != '\0') { + time_value = atoi(v); + char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; + strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value)); + sprintf(csv, "%d,%s", UPNP_SUPPORTED_DATAMODEL_VERSION, s_now); + } + + return 0; +} + +/* ******************************** + * UPNP get attribute values update + * ********************************/ + +int dm_entry_upnp_get_attribute_values_update(struct dmctx *dmctx, char **value) +{ + static char csv[128] = ""; + char *v, *s; + time_t time_value; + + *value = csv; + + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "attribute_values_epochtime", &v); + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "attribute_values_version", &s); + if (v[0] != '0' && v[0] != '\0' && s[0] != '\0') { + time_value = atoi(v); + char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; + strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value)); + sprintf(csv, "%s,%s", s, s_now); + } + + return 0; +} + +/* ******************************** + * UPNP get configuration update + * ********************************/ + +int dm_entry_upnp_get_configuration_update(struct dmctx *dmctx, char **value) +{ + static char csv[128] = ""; + char *v, *s; + time_t time_value; + + *value = csv; + + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "current_configuration_epochtime", &v); + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "current_configuration_version", &s); + if (v[0] != '\0' && s[0] != '\0') { + time_value = atoi(v); + char s_now[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; + strftime(s_now, sizeof s_now, "%Y-%m-%dT%H:%M:%S.000Z", localtime(&time_value)); + sprintf(csv, "%s,%s", s, s_now); + } + + return 0; +} + +/* ************************************** + * UPNP get current configuration version + * *************************************/ + +int dm_entry_upnp_get_current_configuration_version(struct dmctx *dmctx, char **value) +{ + dmuci_get_option_value_string(UPNP_CFG, "@dm[0]", "current_configuration_version", value); + return 0; +} +#endif +/************************/ + +int dm_entry_restart_services(void) { struct package_change *pc; @@ -316,9 +764,51 @@ int dm_entry_restart_services() return 0; } +#ifdef UPNP_TR064 +int dm_entry_upnp_restart_services(void) +{ + struct package_change *pc; + + list_for_each_entry(pc, &head_package_change, list) { + dmubus_call_set("uci", "commit", UBUS_ARGS{{"config", pc->package}}, 1); + } + free_all_list_package_change(&head_package_change); + + return 0; +} + +void dm_upnp_apply_config(void) +{ + apply_end_session(); + dm_entry_upnp_restart_services(); +} + +int cli_output_dm_upnp_variable_state(struct dmctx *dmctx, int cmd, char *variable) +{ + switch (cmd) { + case CMD_UPNP_GET_CONFIGURATION_UPDATE: + fprintf (stdout, "{ \"ConfigurationUpdate\": \"%s\"}\n", variable); + break; + case CMD_UPNP_GET_CURRENT_CONFIGURATION_VERSION: + fprintf (stdout, "{ \"CurrentConfigurationVersion\": \"%s\"}\n", variable); + break; + case CMD_UPNP_GET_SUPPORTED_DATA_MODEL_UPDATE: + fprintf (stdout, "{ \"SupportedDataModelsUpdate\": \"%s\"}\n", variable); + break; + case CMD_UPNP_GET_SUPPORTED_PARAMETERS_UPDATE: + fprintf (stdout, "{ \"SupportedParametersUpdate\": \"%s\"}\n", variable); + break; + case CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE: + fprintf (stdout, "{ \"AttributeValuesUpdate\": \"%s\"}\n", variable); + break; + } + return 0; +} +#endif int cli_output_dm_result(struct dmctx *dmctx, int fault, int cmd, int out) { + struct dm_parameter *n; if (!out) return 0; if (dmctx->list_fault_param.next != &dmctx->list_fault_param) { @@ -333,56 +823,294 @@ int cli_output_dm_result(struct dmctx *dmctx, int fault, int cmd, int out) goto end; } - if (cmd == CMD_ADD_OBJECT) { + switch (cmd) { + case CMD_ADD_OBJECT: if (dmctx->addobj_instance) { fprintf (stdout, "{ \"status\": \"1\", \"instance\": \"%s\" }\n", dmctx->addobj_instance); - goto end; } else { fprintf (stdout, "{ \"fault\": \"%d\" }\n", FAULT_9002); - goto end; } - } - - if (cmd == CMD_DEL_OBJECT || cmd == CMD_SET_VALUE) { + break; +#ifdef UPNP_TR064 + case CMD_UPNP_ADD_INSTANCE: + if (dmctx->addobj_instance) { + fprintf (stdout, "{ \"status\": \"ChangesApplied\", \"instance_path\": \"%s%s%c\" }\n", dmctx->in_param, dmctx->addobj_instance, dm_delim); + } else { + fprintf (stdout, "{ \"fault\": \"%d\" }\n", FAULT_UPNP_701); + } + break; +#endif + case CMD_DEL_OBJECT: + case CMD_SET_VALUE: fprintf (stdout, "{ \"status\": \"1\" }\n"); - goto end; - } + break; - if (cmd == CMD_SET_NOTIFICATION) { + case CMD_SET_NOTIFICATION: fprintf (stdout, "{ \"status\": \"0\" }\n"); - goto end; - } + break; - struct dm_parameter *n; - if (cmd == CMD_GET_NAME) { +#ifdef UPNP_TR064 + case CMD_UPNP_SET_ATTRIBUTES: + case CMD_UPNP_SET_VALUES: + case CMD_UPNP_DEL_INSTANCE: + fprintf (stdout, "{ \"status\": \"ChangesApplied\" }\n"); + break; +#endif + + case CMD_GET_NAME: list_for_each_entry(n, &dmctx->list_parameter, list) { fprintf (stdout, "{ \"parameter\": \"%s\", \"writable\": \"%s\" }\n", n->name, n->data); } - } - else if (cmd == CMD_GET_NOTIFICATION) { + break; + case CMD_GET_NOTIFICATION: list_for_each_entry(n, &dmctx->list_parameter, list) { fprintf (stdout, "{ \"parameter\": \"%s\", \"notification\": \"%s\" }\n", n->name, n->data); } - } - else if (cmd == CMD_GET_VALUE || cmd == CMD_INFORM) { + break; + case CMD_GET_VALUE: + case CMD_INFORM: list_for_each_entry(n, &dmctx->list_parameter, list) { fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"type\": \"%s\" }\n", n->name, n->data, n->type); } + break; + +#ifdef UPNP_TR064 + case CMD_UPNP_GET_VALUES: + case CMD_UPNP_GET_SELECTED_VALUES: + list_for_each_entry(n, &dmctx->list_parameter, list) { + fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\" }\n", n->name, n->data); + } + break; + case CMD_UPNP_GET_ATTRIBUTES: + list_for_each_entry(n, &dmctx->list_parameter, list) { + char alrm[32] = "", evnt[32] = "", btype[16], bversion[32] = "", *stype = NULL; + if (n->flags & DM_PARAM_ALARAM_ON_CHANGE) + strcpy(alrm, ", \"alarmOnChange\": \"1\""); + if (n->flags & DM_PARAM_EVENT_ON_CHANGE) + strcpy(evnt, ", \"eventOnChange\": \"1\""); + if (n->version) + sprintf(bversion, ", \"version\": \"%s\"", n->version); + switch (n->flags & NODE_DATA_ATTRIBUTE_TYPEMASK) { + case NODE_DATA_ATTRIBUTE_TYPEINT: + stype = "int"; + break; + case NODE_DATA_ATTRIBUTE_TYPESTRING: + stype = "string"; + break; + case NODE_DATA_ATTRIBUTE_TYPELONG: + stype = "long"; + break; + case NODE_DATA_ATTRIBUTE_TYPEBOOL: + stype = "boolean"; + break; + case NODE_DATA_ATTRIBUTE_TYPEDATETIME: + stype = "dateTime"; + break; + case NODE_DATA_ATTRIBUTE_TYPEPTR: + if (n->flags & NODE_DATA_ATTRIBUTE_INSTANCE) + stype = "Instance"; + else if (n->flags & NODE_DATA_ATTRIBUTE_MULTIINSTANCE) + stype = "MultiInstance"; + break; + } + if (stype) + sprintf(btype, ", \"type\": \"%s\"", stype); + fprintf (stdout, "{ \"parameter\": \"%s\", \"access\": \"%s\"%s%s%s%s}\n", n->name, n->data, btype, evnt, alrm, bversion); + } + break; + case CMD_UPNP_GET_INSTANCES: + case CMD_UPNP_GET_SUPPORTED_PARAMETERS: + list_for_each_entry(n, &dmctx->list_parameter, list) { + fprintf (stdout, "{ \"parameter\": \"%s\"}\n", n->name); + } + break; + case CMD_UPNP_GET_ACLDATA: + list_for_each_entry(n, &dmctx->list_parameter, list) { + char blist[64] = ""; + char bread[64] = ""; + char bwrite[64] = ""; + char bfac[32] = ""; + if (n->flags & DM_PUBLIC_LIST) { + strcat(blist, "Public "); + } + if (n->flags & DM_BASIC_LIST) { + strcat(blist, "Basic "); + } + if (n->flags & DM_XXXADMIN_LIST) { + strcat(blist, "xxxAdmin "); + } + if (*blist) + blist[strlen(blist) - 1] = '\0'; + if (n->flags & DM_PUBLIC_READ) { + strcat(bread, "Public "); + } + if (n->flags & DM_BASIC_READ) { + strcat(bread, "Basic "); + } + if (n->flags & DM_XXXADMIN_READ) { + strcat(bread, "xxxAdmin "); + } + if (*bread) + bread[strlen(bread) - 1] = '\0'; + if (n->flags & DM_PUBLIC_WRITE) { + strcat(bwrite, "Public "); + } + if (n->flags & DM_BASIC_WRITE) { + strcat(bwrite, "Basic "); + } + if (n->flags & DM_XXXADMIN_WRITE) { + strcat(bwrite, "xxxAdmin "); + } + if (*bwrite) + bwrite[strlen(bwrite) - 1] = '\0'; + if (n->flags & DM_FACTORIZED) + sprintf(bfac, ", \"factorized\": \"1\""); + fprintf (stdout, "{ \"ACLDataPath\": \"%s\", \"List\": \"%s\", \"Read\": \"%s\", \"Write\": \"%s\"%s }\n", n->name, blist, bread, bwrite, bfac); + } + break; + case CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM: + { + struct dm_upnp_enabled_track *p; + list_for_each_entry(p, &list_upnp_enabled_onalarm, list) { + fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"key\": \"%s\"}\n", p->name, p->value, p->key ? p->key : ""); + } + } + break; + case CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT: + { + struct dm_upnp_enabled_track *p; + list_for_each_entry(p, &list_upnp_enabled_onevent, list) { + fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"key\": \"%s\"}\n", p->name, p->value, p->key ? p->key : ""); + } + } + break; + case CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION: + { + struct dm_upnp_enabled_track *p; + list_for_each_entry(p, &list_upnp_enabled_version, list) { + fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"key\": \"%s\"}\n", p->name, p->value, p->key ? p->key : ""); + } + } + break; + case CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM: + { + struct dm_upnp_enabled_track *p; + list_for_each_entry(p, &list_upnp_changed_onalarm, list) { + fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"key\": \"%s\"}\n", p->name, p->value, p->key ? p->key : ""); + } + } + break; + case CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT: + { + struct dm_upnp_enabled_track *p; + list_for_each_entry(p, &list_upnp_changed_onevent, list) { + fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"key\": \"%s\"}\n", p->name, p->value, p->key ? p->key : ""); + } + } + break; + case CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION: + { + struct dm_upnp_enabled_track *p; + list_for_each_entry(p, &list_upnp_changed_version, list) { + fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"key\": \"%s\"}\n", p->name, p->value, p->key ? p->key : ""); + } + } + break; +#endif } end: return 0; } -void dm_entry_cli(int argc, char** argv) +static char *parse_arg_r(char *pch, char **last) +{ + if (pch == NULL) { + pch = *last; + } + + if (pch == NULL) { + return NULL; + } + + for(; *pch != '\0'; pch++) + { + if(*pch == ' ' || *pch == '\t') + continue; + if (*pch == '"') + { + char *s = strchr(++pch, '"'); + if(s) { + *s = '\0'; + *last = s + 1; + return pch; + } + else { + *last = NULL; + return NULL; + } + } + else + { + char *s = strchr(pch, ' '); + if(s) { + *s = '\0'; + *last = s + 1; + } + else { + s = strchr(pch, '\t'); + if(s) { + *s = '\0'; + *last = s + 1; + } + else { + *last = NULL; + } + } + + return pch; + } + } + *last = NULL; + return NULL; +} + +static int dmentry_external_cmd(char **argv) +{ + int pid; + + if ((pid = fork()) == -1) + return -1; + + if (pid == 0) { + /* child */ + execvp(argv[0], argv); + exit(ESRCH); + + } else if (pid < 0) + return -1; + + int status; + while (wait(&status) != pid); + + return 0; +} + +void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode) { struct dmctx cli_dmctx = {0}; - int output = 1; + int output = 1, dmrpc; char *param, *next_level, *parameter_key, *value, *cmd; int fault = 0, status = -1; bool set_fault = false; + long ms; // Milliseconds + time_t s; // Seconds + struct timespec tstart, tend; + unsigned char apply_services = 0; - dm_global_init(); - dm_ctx_init(&cli_dmctx); + if (dmcli_timetrack) + clock_gettime(CLOCK_REALTIME, &tstart); + + dm_ctx_init(&cli_dmctx, dmtype, amd_version, instance_mode); if (argc < 4) goto invalid_arguments; @@ -392,7 +1120,8 @@ void dm_entry_cli(int argc, char** argv) /* GET NAME */ if (strcmp(cmd, "get_name") == 0) { if (argc < 6) goto invalid_arguments; - param =argv[4]; + dmrpc = CMD_GET_NAME; + param = argv[4]; next_level =argv[5]; fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NAME, param, next_level, NULL); cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NAME, output); @@ -400,20 +1129,23 @@ void dm_entry_cli(int argc, char** argv) /* GET VALUE */ else if (strcmp(cmd, "get_value") == 0) { if (argc < 5) goto invalid_arguments; - param =argv[4]; + dmrpc = CMD_GET_VALUE; + param = argv[4]; fault = dm_entry_param_method(&cli_dmctx, CMD_GET_VALUE, param, NULL, NULL); cli_output_dm_result(&cli_dmctx, fault, CMD_GET_VALUE, output); } /* GET NOTIFICATION */ else if (strcmp(cmd, "get_notification") == 0) { if (argc < 5) goto invalid_arguments; - param =argv[4]; + dmrpc = CMD_GET_NOTIFICATION; + param = argv[4]; fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NOTIFICATION, param, NULL, NULL); cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NOTIFICATION, output); } /* SET VALUE */ else if (strcmp(cmd, "set_value") == 0) { if (argc < 7 || (argc % 2) == 0) goto invalid_arguments; + dmrpc = CMD_SET_VALUE; int i; for (i = 5; i < argc; i+=2) { param = argv[i]; @@ -430,6 +1162,7 @@ void dm_entry_cli(int argc, char** argv) /* SET NOTIFICATION */ else if (strcmp(cmd, "set_notification") == 0) { if (argc < 6 || (argc % 2) != 0) goto invalid_arguments; + dmrpc = CMD_SET_NOTIFICATION; int i; for (i = 4; i < argc; i+=2) { param = argv[i]; @@ -445,6 +1178,7 @@ void dm_entry_cli(int argc, char** argv) /* ADD OBJECT */ else if (strcmp(cmd, "add_object") == 0) { if (argc < 6) goto invalid_arguments; + dmrpc = CMD_ADD_OBJECT; param =argv[5]; parameter_key =argv[4]; fault = dm_entry_param_method(&cli_dmctx, CMD_ADD_OBJECT, param, parameter_key, NULL); @@ -452,6 +1186,7 @@ void dm_entry_cli(int argc, char** argv) } /* DEL OBJECT */ else if (strcmp(cmd, "delete_object") == 0) { + dmrpc = CMD_DEL_OBJECT; if (argc < 6) goto invalid_arguments; param =argv[5]; parameter_key =argv[4]; @@ -460,13 +1195,238 @@ void dm_entry_cli(int argc, char** argv) } /* INFORM */ else if (strcmp(cmd, "inform") == 0) { + dmrpc = CMD_INFORM; fault = dm_entry_param_method(&cli_dmctx, CMD_INFORM, "", NULL, NULL); cli_output_dm_result(&cli_dmctx, fault, CMD_INFORM, output); } +#ifdef UPNP_TR064 + /* UPNP GET VALUES */ + else if (strcmp(cmd, "upnp_get_values") == 0) { + if (argc < 5) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_VALUES; + param = argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_VALUES, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_VALUES, output); + } + /* UPNP GET SELECTED VALUES */ + else if (strcmp(cmd, "upnp_get_selected_values") == 0) { + if (argc < 5) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_SELECTED_VALUES; + param = argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_SELECTED_VALUES, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_SELECTED_VALUES, output); + } + /* UPNP GET INSTANCES */ + else if (strcmp(cmd, "upnp_get_instances") == 0) { + if (argc < 6) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_INSTANCES; + param = argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_INSTANCES, param, argv[5], NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_INSTANCES, output); + } + /* UPNP GET SUPPORTED PARAMETERS */ + else if (strcmp(cmd, "upnp_get_supported_parameters") == 0) { + if (argc < 6) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_SUPPORTED_PARAMETERS; + param = argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_SUPPORTED_PARAMETERS, param, argv[5], NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_SUPPORTED_PARAMETERS, output); + } + /* UPNP SET VALUE */ + else if (strcmp(cmd, "upnp_set_values") == 0) { + if (argc < 6 || (argc % 2) == 1) goto invalid_arguments; + dmrpc = CMD_UPNP_SET_VALUES; + int i; + for (i = 4; i < argc; i+=2) { + param = argv[i]; + value = argv[i+1]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_SET_VALUES, param, value, NULL); + if (fault) break; + } + if (!fault) { + apply_services = 1; + fault = dm_entry_apply(&cli_dmctx, CMD_UPNP_SET_VALUES, NULL, NULL); + } + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_SET_VALUES, output); + } + /* UPNP DEL INSTANCE */ + else if (strcmp(cmd, "upnp_delete_instance") == 0) { + if (argc < 5) goto invalid_arguments; + dmrpc = CMD_UPNP_DEL_INSTANCE; + param =argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_DEL_INSTANCE, param, NULL, NULL); + if (!fault) + apply_services = 1; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_DEL_INSTANCE, output); + } + /* UPNP ADD INSTANCE */ + else if (strcmp(cmd, "upnp_add_instance") == 0) { + char buf[256]; + dmrpc = CMD_UPNP_ADD_INSTANCE; + int i; + if (argc < 5 || (argc % 2) == 0) goto invalid_arguments; + param = argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_ADD_INSTANCE, param, NULL, NULL); + if (!fault && cli_dmctx.addobj_instance) { + struct dmctx set_dmctx = {0}; + apply_services = 1; + if (argc >= 6) { + dm_ctx_init_sub(&set_dmctx, dmtype, amd_version, instance_mode); + for (i = 5; i < argc; i+=2) { + sprintf(buf, "%s%s%c%s", param, cli_dmctx.addobj_instance, dm_delim, argv[i]); // concatenate obj path + instance + sub param + value = argv[i+1]; + dm_entry_param_method(&set_dmctx, CMD_UPNP_SET_VALUES, buf, value, NULL); + } + dm_entry_apply(&set_dmctx, CMD_UPNP_SET_VALUES, NULL, NULL); + dm_ctx_clean_sub(&set_dmctx); + } + } + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_ADD_INSTANCE, output); + } + /* UPNP GET ATTRIBUTES */ + else if (strcmp(cmd, "upnp_get_attributes") == 0) { + if (argc < 5) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_ATTRIBUTES; + param = argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_ATTRIBUTES, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ATTRIBUTES, output); + } + /* UPNP SET ATTRIBUTES */ + else if (strcmp(cmd, "upnp_set_attributes") == 0) { + if (argc < 7 || (argc % 3) != 1) goto invalid_arguments; + dmrpc = CMD_UPNP_SET_ATTRIBUTES; + int i; + for (i = 4; i < argc; i+=3) { + param = argv[i]; + char *evnt = argv[i+1]; + char *alrm = argv[i+2]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_SET_ATTRIBUTES, param, evnt, alrm); + if (fault) break; + } + if(!fault) { + fault = dm_entry_apply(&cli_dmctx, CMD_UPNP_SET_ATTRIBUTES, NULL, NULL); + } + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_SET_ATTRIBUTES, output); + } + /* UPNP GET ACLDATA */ + else if (strcmp(cmd, "upnp_get_acldata") == 0) { + if (argc < 5) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_ACLDATA; + param = argv[4]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_ACLDATA, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ACLDATA, output); + } + else if (strcmp(cmd, "upnp_init_state_variables") == 0) { + dmrpc = CMD_UPNP_INIT_STATE_VARIABLES; + upnp_state_variables_init(&cli_dmctx); + } + else if (strcmp(cmd, "upnp_get_supported_parameters_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_SUPPORTED_PARAMETERS_UPDATE; + dm_entry_upnp_get_supported_parameters_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_SUPPORTED_PARAMETERS_UPDATE, var); + } + else if (strcmp(cmd, "upnp_get_supported_datamodel_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_SUPPORTED_DATA_MODEL_UPDATE; + dm_entry_upnp_get_supported_datamodel_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_SUPPORTED_DATA_MODEL_UPDATE, var); + } + else if (strcmp(cmd, "upnp_get_configuration_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_CONFIGURATION_UPDATE; + dm_entry_upnp_get_configuration_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_CONFIGURATION_UPDATE, var); + } + else if (strcmp(cmd, "upnp_get_current_configuration_version") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_CURRENT_CONFIGURATION_VERSION; + dm_entry_upnp_get_current_configuration_version(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_CURRENT_CONFIGURATION_VERSION, var); + } + else if (strcmp(cmd, "upnp_get_attribute_values_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE; + dm_entry_upnp_get_attribute_values_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE, var); + } + else if (strcmp(cmd, "upnp_load_enabled_parametrs_track") == 0) { + char *var; + dmrpc = CMD_UPNP_LOAD_ENABLED_PARAMETRS_TRACK; + dm_entry_upnp_load_tracked_parameters(&cli_dmctx); + } + else if (strcmp(cmd, "upnp_get_enabled_parametrs_alarm") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM, output); + } + else if (strcmp(cmd, "upnp_get_enabled_parametrs_event") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT, output); + } + else if (strcmp(cmd, "upnp_get_enabled_parametrs_version") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION, output); + } + else if (strcmp(cmd, "upnp_check_changed_parametrs_alarm") == 0) { + char *var; + dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM; + dm_entry_upnp_check_alarmonchange_param(&cli_dmctx); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM, output); + } + else if (strcmp(cmd, "upnp_check_changed_parametrs_event") == 0) { + char *var; + dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT; + dm_entry_upnp_check_eventonchange_param(&cli_dmctx); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT, output); + } + else if (strcmp(cmd, "upnp_check_changed_parametrs_version") == 0) { + char *var; + dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION; + dm_entry_upnp_check_versiononchange_param(&cli_dmctx); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION, output); + } +#endif else { goto invalid_arguments; } + dm_ctx_clean(&cli_dmctx); + if (apply_services) { + dm_upnp_apply_config(); + } + + if (!fault) { + int ualarm, uversion, uevent; +#ifdef UPNP_TR064 + switch (dmrpc) { + case CMD_UPNP_SET_VALUES: + case CMD_UPNP_DEL_INSTANCE: + case CMD_UPNP_ADD_INSTANCE: + DM_ENTRY_UPNP_CHECK_CHANGES(ualarm, uevent, uversion); + break; + case CMD_UPNP_SET_ATTRIBUTES: + DM_ENTRY_UPNP_LOAD_TRACKED_PARAMETERS(); + break; + } +#endif + } + + if (dmcli_timetrack) { + clock_gettime(CLOCK_REALTIME, &tend); + s = tend.tv_sec - tstart.tv_sec; + ms = (tend.tv_nsec - tstart.tv_nsec) / 1.0e6; // Convert nanoseconds to milliseconds + if (ms < 0) { + ms = 1000 + ms; + s--; + } + fprintf(stdout, "-----------------------------\n"); + fprintf(stdout, "End: %ld s : %ld ms\n", (long)s, ms); + fprintf(stdout, "-----------------------------\n"); + fflush(stdout); + } return; invalid_arguments: @@ -474,6 +1434,445 @@ invalid_arguments: fprintf(stdout, "Invalid arguments!\n");; } +int dmentry_cli(int argc, char *argv[], unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode) +{ + struct dmctx cli_dmctx = {0}; + int fault = 0, set_fault = 0; + int i, dmrpc; + char *param; + char *value; + char *parameter_key; + char *notifset; + unsigned char apply_services = 0; + + if (argc < 3) { + fprintf(stderr, "Wrong arguments!\n"); + return -1; + } + + dm_ctx_init(&cli_dmctx, dmtype, amd_version, instance_mode); + if (strcmp(argv[2], "get_value") == 0) { + char *param = ""; + dmrpc = CMD_GET_VALUE; + if (argc >= 4) + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_GET_VALUE, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_GET_VALUE, 1); + } + else if (strcmp(argv[2], "get_name") == 0) { + if (argc < 5) + goto invalid_arguments; + dmrpc = CMD_GET_NAME; + fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NAME, argv[3], argv[4], NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NAME, 1); + } + else if (strcmp(argv[2], "get_notification") == 0) { + char *param = ""; + dmrpc = CMD_GET_NOTIFICATION; + if (argc >= 4) + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NOTIFICATION, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NOTIFICATION, 1); + } + else if (strcmp(argv[2], "set_value") == 0) { + if (argc < 6 || (argc % 2) != 0) + goto invalid_arguments; + + dmrpc = CMD_SET_VALUE; + for (i = 4; i < argc; i+=2) { + param = argv[i]; + value = argv[i+1]; + fault = dm_entry_param_method(&cli_dmctx, CMD_SET_VALUE, param, value, NULL); + if (fault) set_fault = true; + } + parameter_key = argv[3]; + if (!set_fault) { + fault = dm_entry_apply(&cli_dmctx, CMD_SET_VALUE, parameter_key, NULL); + } + cli_output_dm_result(&cli_dmctx, fault, CMD_SET_VALUE, 1); + } + else if (strcmp(argv[2], "set_notification") == 0) { + if (argc < 6 || (argc % 3) != 0) + goto invalid_arguments; + dmrpc = CMD_SET_NOTIFICATION; + for (i=3; i= 4) + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_VALUES, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_VALUES, 1); + } + else if (strcmp(argv[2], "upnp_get_selected_values") == 0) { + char *param = ""; + dmrpc = CMD_UPNP_GET_SELECTED_VALUES; + if (argc >= 4) + param = argv[3]; + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_SELECTED_VALUES, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_SELECTED_VALUES, 1); + } + else if (strcmp(argv[2], "upnp_get_supported_parameters") == 0) { + if (argc < 5) + goto invalid_arguments; + dmrpc = CMD_UPNP_GET_SUPPORTED_PARAMETERS; + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_SUPPORTED_PARAMETERS, param, argv[4], NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_SUPPORTED_PARAMETERS, 1); + } + else if (strcmp(argv[2], "upnp_get_instances") == 0) { + if (argc < 5) + goto invalid_arguments; + dmrpc = CMD_UPNP_GET_INSTANCES; + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_INSTANCES, param, argv[4], NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_INSTANCES, 1); + } + else if (strcmp(argv[2], "upnp_set_values") == 0) { + if (argc < 5 || (argc % 2) == 0) + goto invalid_arguments; + + dmrpc = CMD_UPNP_SET_VALUES; + for (i = 3; i < argc; i+=2) { + param = argv[i]; + value = argv[i+1]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_SET_VALUES, param, value, NULL); + if (fault) break; + } + if (!fault) { + apply_services = 1; + fault = dm_entry_apply(&cli_dmctx, CMD_UPNP_SET_VALUES, parameter_key, NULL); + } + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_SET_VALUES, 1); + } + else if (strcmp(argv[2], "upnp_get_attributes") == 0) { + if (argc < 4) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_ATTRIBUTES; + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_ATTRIBUTES, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ATTRIBUTES, 1); + } + else if (strcmp(argv[2], "upnp_set_attributes") == 0) { + if (argc < 6 || (argc % 3) != 0) goto invalid_arguments; + dmrpc = CMD_UPNP_SET_ATTRIBUTES; + int i; + for (i = 3; i < argc; i+=3) { + param = argv[i]; + char *evnt = argv[i+1]; + char *alrm = argv[i+2]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_SET_ATTRIBUTES, param, evnt, alrm); + if (fault) break; + } + if(!fault) { + fault = dm_entry_apply(&cli_dmctx, CMD_UPNP_SET_ATTRIBUTES, NULL, NULL); + } + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_SET_ATTRIBUTES, 1); + } + else if (strcmp(argv[2], "upnp_add_instance") == 0) { + char buf[256]; + int i; + if (argc < 4 || (argc % 2) != 0) + goto invalid_arguments; + dmrpc = CMD_UPNP_ADD_INSTANCE; + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_ADD_INSTANCE, param, NULL, NULL); + if (!fault && cli_dmctx.addobj_instance) { + struct dmctx set_dmctx = {0}; + apply_services = 1; + if (argc >= 5) { + dm_ctx_init_sub(&set_dmctx, dmtype, amd_version, instance_mode); + for (i = 4; i < argc; i+=2) { + sprintf(buf, "%s%s%c%s", param, cli_dmctx.addobj_instance, dm_delim, argv[i]); // concatenate obj path + instance + sub param + value = argv[i+1]; + dm_entry_param_method(&set_dmctx, CMD_UPNP_SET_VALUES, buf, value, NULL); + } + dm_entry_apply(&set_dmctx, CMD_UPNP_SET_VALUES, NULL, NULL); + dm_ctx_clean_sub(&set_dmctx); + } + } + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_ADD_INSTANCE, 1); + } + else if (strcmp(argv[2], "upnp_delete_instance") == 0) { + if (argc < 4) + goto invalid_arguments; + dmrpc = CMD_UPNP_DEL_INSTANCE; + param =argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_DEL_INSTANCE, param, NULL, NULL); + if (!fault) + apply_services = 1; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_DEL_INSTANCE, 1); + } + else if (strcmp(argv[2], "upnp_get_acldata") == 0) { + if (argc < 4) goto invalid_arguments; + dmrpc = CMD_UPNP_GET_ACLDATA; + param = argv[3]; + fault = dm_entry_param_method(&cli_dmctx, CMD_UPNP_GET_ACLDATA, param, NULL, NULL); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ACLDATA, 1); + } + else if (strcmp(argv[2], "upnp_init_state_variables") == 0) { + dmrpc = CMD_UPNP_INIT_STATE_VARIABLES; + upnp_state_variables_init(&cli_dmctx); + } + else if (strcmp(argv[2], "upnp_get_supported_parameters_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_SUPPORTED_PARAMETERS_UPDATE; + dm_entry_upnp_get_supported_parameters_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_SUPPORTED_PARAMETERS_UPDATE, var); + } + else if (strcmp(argv[2], "upnp_get_supported_datamodel_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_SUPPORTED_DATA_MODEL_UPDATE; + dm_entry_upnp_get_supported_datamodel_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_SUPPORTED_DATA_MODEL_UPDATE, var); + } + else if (strcmp(argv[2], "upnp_get_configuration_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_CONFIGURATION_UPDATE; + dm_entry_upnp_get_configuration_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_CONFIGURATION_UPDATE, var); + } + else if (strcmp(argv[2], "upnp_get_current_configuration_version") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_CURRENT_CONFIGURATION_VERSION; + dm_entry_upnp_get_current_configuration_version(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_CURRENT_CONFIGURATION_VERSION, var); + } + else if (strcmp(argv[2], "upnp_get_attribute_values_update") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE; + dm_entry_upnp_get_attribute_values_update(&cli_dmctx, &var); + cli_output_dm_upnp_variable_state(&cli_dmctx, CMD_UPNP_GET_ATTRIBUTE_VALUES_UPDATE, var); + } + else if (strcmp(argv[2], "upnp_load_enabled_parametrs_track") == 0) { + char *var; + dmrpc = CMD_UPNP_LOAD_ENABLED_PARAMETRS_TRACK; + dm_entry_upnp_load_tracked_parameters(&cli_dmctx); + } + else if (strcmp(argv[2], "upnp_get_enabled_parametrs_alarm") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_ALARM, 1); + } + else if (strcmp(argv[2], "upnp_get_enabled_parametrs_event") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_EVENT, 1); + } + else if (strcmp(argv[2], "upnp_get_enabled_parametrs_version") == 0) { + char *var; + dmrpc = CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION; + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_GET_ENABLED_PARAMETRS_VERSION, 1); + } + else if (strcmp(argv[2], "upnp_check_changed_parametrs_alarm") == 0) { + char *var; + dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM; + dm_entry_upnp_check_alarmonchange_param(&cli_dmctx); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_ALARM, 1); + } + else if (strcmp(argv[2], "upnp_check_changed_parametrs_event") == 0) { + char *var; + dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT; + dm_entry_upnp_check_eventonchange_param(&cli_dmctx); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_EVENT, 1); + } + else if (strcmp(argv[2], "upnp_check_changed_parametrs_version") == 0) { + char *var; + dmrpc = CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION; + dm_entry_upnp_check_versiononchange_param(&cli_dmctx); + cli_output_dm_result(&cli_dmctx, fault, CMD_UPNP_CHECK_CHANGED_PARAMETRS_VERSION, 1); + } +#endif + else { + goto invalid_arguments; + } + + dm_ctx_clean(&cli_dmctx); + if (apply_services) { + dm_upnp_apply_config(); + } + + if (!fault) { + int ualarm, uversion, uevent; +#ifdef UPNP_TR064 + switch (dmrpc) { + case CMD_UPNP_SET_VALUES: + case CMD_UPNP_DEL_INSTANCE: + case CMD_UPNP_ADD_INSTANCE: + DM_ENTRY_UPNP_CHECK_CHANGES(ualarm, uevent, uversion); + break; + case CMD_UPNP_SET_ATTRIBUTES: + DM_ENTRY_UPNP_LOAD_TRACKED_PARAMETERS(); + break; + } +#endif + } + + return 0; + +invalid_arguments: + dm_ctx_clean(&cli_dmctx); + fprintf(stdout, "Invalid arguments!\n"); + return -1; +} + +void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode) +{ + FILE *fp; + char *argv[64]; + char buf[2048], dbuf[2048]; + char *pch, *pchr; + int argc, len, i=0; + long ms; // Milliseconds + time_t s; // Seconds + struct timespec tstart, tend; + + if (file) { + fp = fopen(file, "r"); + if (fp == NULL) { + fprintf(stderr, "ERROR: Wrong file!\n"); + fflush(stderr); + return; + } + } + else { + fp = stdin; + } + + printf("%s", DM_PROMPT" "); fflush(stdout); + + while (fgets (buf , 2048 , fp) != NULL) { + if (dmcli_evaluatetest) + argc = 1; + else + argc = 2; + + len = strlen(buf); + if (len>0 && buf[len-1] == '\n') { + buf[len-1] = '\0'; + } + if (strcasecmp(buf, "exit") == 0) { + if (file) { + fprintf(stdout, "%s\n", buf); + fflush(stdout); + } + return; + } + if (strcasecmp(buf, "help") == 0) { + if (file) { + fprintf(stdout, "%s\n", buf); + fflush(stdout); + } + print_dm_help(); + printf(DM_PROMPT" "); fflush(stdout); + continue; + } + + i++; + + strcpy(dbuf, buf); + for (pch = parse_arg_r(buf, &pchr); pch != NULL; pch = parse_arg_r(NULL, &pchr)) { + if(argc < 3 && (pch[0] == '#' || pch[0] == '\0')) + break; + if (*pch == '"') + pch++; + len = strlen(pch); + if (len>0 && pch[len-1] == '"') + pch[len-1] = '\0'; + argv[argc++] = pch; + } + if (file) { + if (!pch || pch[0] != '#') { + fprintf(stdout, "%s\n", dbuf); + fflush(stdout); + } + else { + fprintf(stdout, "\n"); + fflush(stdout); + } + } + if (argc>2) { + char testref[32] = ""; + if (dmcli_evaluatetest) + sprintf(testref, "Ref: %s - ", argv[1]); + if (dmcli_timetrack || dmcli_evaluatetest) { + fprintf(stdout, "-----------------------------\n"); + fprintf(stdout, "[%s%04d] %s\n", testref, i, dbuf); + fprintf(stdout, "-----------------------------\n"); + fflush(stdout); + clock_gettime(CLOCK_REALTIME, &tstart); + } + if (dmentry_cli(argc, argv, dmtype, amd_version, instance_mode) == 0) { + if (dmcli_timetrack || dmcli_evaluatetest) { + clock_gettime(CLOCK_REALTIME, &tend); + s = tend.tv_sec - tstart.tv_sec; + ms = (tend.tv_nsec - tstart.tv_nsec) / 1.0e6; // Convert nanoseconds to milliseconds + if (ms < 0) { + ms = 1000 + ms; + s--; + } + fprintf(stdout, "-----------------------------\n"); + fprintf(stdout, "%sEnd: %ld s : %ld ms\n", testref, (long)s, ms); + fprintf(stdout, "-----------------------------\n"); + fflush(stdout); + } + } + else { + fprintf(stdout, "Type help for help\n"); + fflush(stdout); + } + } + printf(DM_PROMPT" "); fflush(stdout); + } + if (file) { + fclose(fp); + fprintf(stdout, "\n"); + fflush(stdout); + } +} + int cli_output_wepkey64(char strk64[4][11]) { fprintf(stdout, "%s\n%s\n%s\n%s\n", strk64[0], strk64[1], strk64[2], strk64[3]); @@ -514,3 +1913,4 @@ void wepkey_cli(int argc, char** argv) invalid_arguments: fprintf(stdout, "Invalid arguments!\n");; } + diff --git a/dm/dmentry.h b/dm/dmentry.h index 0444825..0812a38 100644 --- a/dm/dmentry.h +++ b/dm/dmentry.h @@ -3,24 +3,74 @@ #include "dmcwmp.h" extern struct list_head head_package_change; +extern unsigned char dmcli_timetrack; +extern unsigned char dmcli_evaluatetest; enum ctx_init_enum { CTX_INIT_ALL, CTX_INIT_SUB }; -int dm_global_init(void); -int dm_ctx_init(struct dmctx *ctx); -int dm_ctx_init_sub(struct dmctx *ctx); +int dm_ctx_init(struct dmctx *ctx, unsigned int dm_type, unsigned int amd_version, unsigned int instance_mode); +int dm_ctx_init_sub(struct dmctx *ctx, unsigned int dm_type, unsigned int amd_version, unsigned int instance_mode); int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, char *arg2); int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2); -int dm_entry_load_enabled_notify(); -int adm_entry_get_linker_param(char *param, char *linker, char **value); -int adm_entry_get_linker_value(char *param, char **value); -int dm_entry_restart_services(); +int dm_entry_load_enabled_notify(unsigned int dm_type, unsigned int amd_version, int instance_mode); +int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, char **value); +int adm_entry_get_linker_value(struct dmctx *ctx, char *param, char **value); +int dm_entry_restart_services(void); +#ifdef UPNP_TR064 +int dm_entry_upnp_restart_services(void); +void dm_upnp_apply_config(void); +int dm_entry_upnp_check_alarmonchange_param(struct dmctx *dmctx); +int dm_entry_upnp_check_eventonchange_param(struct dmctx *dmctx); +int dm_entry_upnp_check_versiononchange_param(struct dmctx *pctx); +int dm_entry_upnp_load_tracked_parameters(struct dmctx *dmctx); +int dm_entry_upnp_get_supported_parameters_update(struct dmctx *dmctx, char **value); +int dm_entry_upnp_get_supported_datamodel_update(struct dmctx *dmctx, char **value); +int dm_entry_upnp_get_attribute_values_update(struct dmctx *dmctx, char **value); +int dm_entry_upnp_get_configuration_update(struct dmctx *dmctx, char **value); +int dm_entry_upnp_get_current_configuration_version(struct dmctx *dmctx, char **value); +#endif + int dm_ctx_clean(struct dmctx *ctx); int dm_ctx_clean_sub(struct dmctx *ctx); -void dm_entry_cli(int argc, char** argv); +void dm_execute_cli_shell(int argc, char** argv, unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode); +void dm_execute_cli_command(char *file, unsigned int dmtype, unsigned int amd_version, unsigned int instance_mode); void wepkey_cli(int argc, char** argv); void dmentry_instance_lookup_inparam(struct dmctx *ctx); + +#ifdef UPNP_TR064 +#define DM_ENTRY_UPNP_CHECK_CHANGES(ALARM, EVENT, VERSION) \ + do { \ + struct dmctx dmctx_chg = {0}; \ + dm_ctx_init(&dmctx_chg, DM_UPNP, AMD_2, INSTANCE_MODE_NUMBER); \ + ALARM = dm_entry_upnp_check_alarmonchange_param(&dmctx_chg); \ + dm_ctx_clean(&dmctx_chg); \ + memset(&dmctx_chg, 0, sizeof(struct dmctx)); \ + dm_ctx_init(&dmctx_chg, DM_UPNP, AMD_2, INSTANCE_MODE_NUMBER); \ + EVENT = dm_entry_upnp_check_eventonchange_param(&dmctx_chg); \ + dm_ctx_clean(&dmctx_chg); \ + memset(&dmctx_chg, 0, sizeof(struct dmctx)); \ + dm_ctx_init(&dmctx_chg, DM_UPNP, AMD_2, INSTANCE_MODE_NUMBER); \ + VERSION = dm_entry_upnp_check_versiononchange_param(&dmctx_chg); \ + dm_ctx_clean(&dmctx_chg); \ + } while(0) + +#define DM_ENTRY_UPNP_FREE_ALL_CHECK_CHANGES() \ + do { \ + free_all_list_upnp_param_track(&list_upnp_changed_onevent); \ + free_all_list_upnp_param_track(&list_upnp_changed_onalarm); \ + free_all_list_upnp_param_track(&list_upnp_changed_version); \ + } while(0) + +#define DM_ENTRY_UPNP_LOAD_TRACKED_PARAMETERS() \ + do { \ + struct dmctx dmctx_trk = {0}; \ + dm_ctx_init(&dmctx_trk, DM_UPNP, AMD_2, INSTANCE_MODE_NUMBER); \ + dm_entry_upnp_load_tracked_parameters(&dmctx_trk); \ + dm_ctx_clean(&dmctx_trk); \ + } while(0) +#endif + #endif diff --git a/dm/dmmem.h b/dm/dmmem.h index 732e8dd..2312e8c 100644 --- a/dm/dmmem.h +++ b/dm/dmmem.h @@ -60,7 +60,7 @@ const char *file, const char *func, int line, #endif /*WITH_MEMTRACK*/ const char *s ); -//inline void dmfree(void *m); + void dmcleanmem(); #endif /*WITH_MEMLEACKSEC*/ int __dmasprintf diff --git a/dm/dmtree/common/deviceinfo.c b/dm/dmtree/common/deviceinfo.c index 9fd4067..4287f50 100644 --- a/dm/dmtree/common/deviceinfo.c +++ b/dm/dmtree/common/deviceinfo.c @@ -22,18 +22,59 @@ #include "deviceinfo.h" #include "dmjson.h" -inline int entry_method_device_info_vcf(struct dmctx *ctx); -inline int entry_method_device_info_vcf_instance(struct dmctx *ctx, char *ivcf); -struct dev_vcf cur_dev_vcf = {0}; +/*** DeviceInfo. ***/ +DMOBJ tDeviceInfoObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"X_INTENO_SE_CATV", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tCatTvParams, NULL}, +{"VendorConfigFile", &DMREAD, NULL, NULL, NULL, browseVcfInst, NULL, NULL, NULL, tVcfParams, NULL}, +{0} +}; -inline int init_args_vcf(struct dmctx *ctx, struct uci_section *s) -{ - struct dev_vcf *args = &cur_dev_vcf; - ctx->args = (void *)args; - args->vcf_sec = s; - return 0; -} +DMLEAF tDeviceInfoParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification, linker*/ +{"Manufacturer", &DMREAD, DMT_STRING, get_device_manufacturer, NULL, &DMFINFRM, NULL}, +{"ManufacturerOUI", &DMREAD, DMT_STRING, get_device_manufactureroui, NULL, &DMFINFRM, NULL}, +{"ModelName", &DMREAD, DMT_STRING, get_device_routermodel, NULL, &DMFINFRM, NULL}, +{"ProductClass", &DMREAD, DMT_STRING, get_device_productclass, NULL, &DMFINFRM, NULL}, +{"SerialNumber", &DMREAD, DMT_STRING, get_device_serialnumber, NULL, &DMFINFRM, NULL}, +{"HardwareVersion", &DMREAD, DMT_STRING, get_device_hardwareversion, NULL, &DMFINFRM, NULL}, +{"SoftwareVersion", &DMREAD, DMT_STRING, get_device_softwareversion, NULL, &DMFINFRM, &DMACTIVE}, +{"UpTime", &DMREAD, DMT_UNINT, get_device_info_uptime, NULL, NULL, NULL}, +{"DeviceLog", &DMREAD, DMT_STRING, get_device_devicelog, NULL, NULL, NULL}, +{"SpecVersion", &DMREAD, DMT_STRING, get_device_specversion, NULL, &DMFINFRM, NULL}, +{"ProvisioningCode", &DMWRITE, DMT_STRING, get_device_provisioningcode, set_device_provisioningcode, &DMFINFRM, &DMACTIVE}, +{"X_INTENO_SE_BaseMacAddr", &DMREAD, DMT_STRING, get_base_mac_addr, NULL, NULL, NULL}, +{"X_INTENO_SE_CATVEnabled", &DMWRITE, DMT_STRING, get_catv_enabled, set_device_catvenabled, NULL, NULL}, +{"X_INTENO_SE_MemoryBank", &DMWRITE, DMT_STRING, get_device_memory_bank, set_device_memory_bank, NULL, NULL}, +{0} +}; +/*** DeviceInfo.X_INTENO_SE_CATV. ***/ +DMLEAF tCatTvParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Enabled", &DMWRITE, DMT_STRING, get_catv_enabled, set_device_catvenabled, NULL, NULL}, +{"OpticalInputLevel", &DMREAD, DMT_STRING, get_catv_optical_input_level, NULL, NULL, NULL}, +{"RFOutputLevel", &DMREAD, DMT_STRING, get_catv_rf_output_level, NULL, NULL, NULL}, +{"Temperature", &DMREAD, DMT_STRING, get_catv_temperature, NULL, NULL, NULL}, +{"Voltage", &DMREAD, DMT_STRING, get_catv_voltage, NULL, NULL, NULL}, +{0} +}; + +/*** DeviceInfo.VendorConfigFile.{i}. ***/ +DMLEAF tVcfParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_vcf_alias, set_vcf_alias, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_vcf_name, NULL, NULL, NULL}, +{"Version", &DMREAD, DMT_STRING, get_vcf_version, NULL, NULL, NULL}, +{"Date", &DMREAD, DMT_TIME, get_vcf_date, NULL, NULL, NULL}, +{"Description", &DMREAD, DMT_STRING, get_vcf_desc, NULL, NULL, NULL}, +{"UseForBackupRestore", &DMREAD, DMT_BOOL, get_vcf_backup_restore, NULL, NULL, NULL}, +{0} +}; + +/* + *DeviceInfo. functions + */ char *get_deviceid_manufacturer() { char *v; @@ -49,18 +90,18 @@ char *get_deviceid_manufactureroui() json_object *res; FILE *nvrammac=NULL; char macreadfile[18]={0}; - + dmuci_get_option_value_string("cwmp", "cpe", "override_oui", &v); if (v[0] == '\0') { - dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); + dmubus_call("router.system", "info", UBUS_ARGS{{}}, 0, &res); if(!(res)){ db_get_value_string("hw", "board", "BaseMacAddr", &mac); if(!mac || strlen(mac)==0 ){ if ((nvrammac = fopen("/proc/nvram/BaseMacAddr", "r")) == NULL) - { + { mac = NULL; - } + } else{ fscanf(nvrammac,"%[^\n]", macreadfile); macreadfile[17]='\0'; @@ -74,6 +115,7 @@ char *get_deviceid_manufactureroui() } else mac = dm_ubus_get_value(res, 2, "system", "basemac"); + if(mac) { size_t ln = strlen(mac); @@ -122,49 +164,49 @@ char *get_softwareversion() return val; } -int get_device_manufacturer(char *refparam, struct dmctx *ctx, char **value) +int get_device_manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = get_deviceid_manufacturer(); return 0; } -int get_device_manufactureroui(char *refparam, struct dmctx *ctx, char **value) +int get_device_manufactureroui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = get_deviceid_manufactureroui(); return 0; } -int get_device_productclass(char *refparam, struct dmctx *ctx, char **value) +int get_device_productclass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = get_deviceid_productclass(); return 0; } -int get_device_serialnumber(char *refparam, struct dmctx *ctx, char **value) +int get_device_serialnumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = get_deviceid_serialnumber(); return 0; } -int get_device_softwareversion(char *refparam, struct dmctx *ctx, char **value) +int get_device_softwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = get_softwareversion(); return 0; } -int get_device_hardwareversion(char *refparam, struct dmctx *ctx, char **value) +int get_device_hardwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { db_get_value_string("hw", "board", "hardwareVersion", value); return 0; } -int get_device_routermodel(char *refparam, struct dmctx *ctx, char **value) +int get_device_routermodel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { db_get_value_string("hw", "board", "routerModel", value); return 0; } -int get_device_info_uptime(char *refparam, struct dmctx *ctx, char **value) +int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { FILE* fp = NULL; char *pch, *spch; @@ -182,7 +224,7 @@ int get_device_info_uptime(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_device_devicelog(char *refparam, struct dmctx *ctx, char **value) +int get_device_devicelog(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; int i = 0, nbrlines = 4; @@ -199,6 +241,7 @@ int get_device_devicelog(char *refparam, struct dmctx *ctx, char **value) if(msg == NULL) msg = p; i++; if (i == nbrlines) { + *(p-1) = '\0'; break; } } @@ -214,19 +257,19 @@ int get_device_devicelog(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_device_specversion(char *refparam, struct dmctx *ctx, char **value) +int get_device_specversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1.0"; return 0; } -int get_device_provisioningcode(char *refparam, struct dmctx *ctx, char **value) +int get_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "cpe", "provisioning_code", value); return 0; } -int set_device_provisioningcode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; switch (action) { @@ -240,7 +283,7 @@ int set_device_provisioningcode(char *refparam, struct dmctx *ctx, int action, c } -int get_base_mac_addr(char *refparam, struct dmctx *ctx, char **value) +int get_base_mac_addr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; @@ -250,7 +293,7 @@ int get_base_mac_addr(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_device_memory_bank(char *refparam, struct dmctx *ctx, char **value) +int get_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; @@ -260,7 +303,7 @@ int get_device_memory_bank(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_device_memory_bank(char *refparam, struct dmctx *ctx, int action, char *value) +int set_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -271,7 +314,7 @@ int set_device_memory_bank(char *refparam, struct dmctx *ctx, int action, char * } return 0; } -int get_catv_enabled(char *refparam, struct dmctx *ctx, char **value) +int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *catv; dmuci_get_option_value_string("catv", "catv", "enable", &catv); @@ -283,7 +326,7 @@ int get_catv_enabled(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_device_catvenabled(char *refparam, struct dmctx *ctx, int action, char *value) +int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *stat; @@ -304,7 +347,7 @@ int set_device_catvenabled(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, char **value) +int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *str; @@ -316,7 +359,7 @@ int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, char **value return 0; } -int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, char **value) +int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *str; @@ -328,7 +371,7 @@ int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_catv_temperature(char *refparam, struct dmctx *ctx, char **value) +int get_catv_temperature(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *str; @@ -340,7 +383,7 @@ int get_catv_temperature(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_catv_voltage(char *refparam, struct dmctx *ctx, char **value) +int get_catv_voltage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *str; @@ -352,27 +395,30 @@ int get_catv_voltage(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_vcf_name(char *refparam, struct dmctx *ctx, char **value) +int get_vcf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dev_vcf.vcf_sec, "name", value); + struct uci_section *vcf_sec = (struct uci_section *)data; + dmuci_get_value_by_section_string(vcf_sec, "name", value); return 0; } -int get_vcf_version(char *refparam, struct dmctx *ctx, char **value) +int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dev_vcf.vcf_sec, "version", value); + struct uci_section *vcf_sec = (struct uci_section *)data; + dmuci_get_value_by_section_string(vcf_sec, "version", value); return 0; } -int get_vcf_date(char *refparam, struct dmctx *ctx, char **value) +int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { DIR *dir; struct dirent *d_file; struct stat attr; char path[128]; char date[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"]; + struct uci_section *vcf_sec = (struct uci_section *)data; *value = ""; - dmuci_get_value_by_section_string(cur_dev_vcf.vcf_sec, "name", value); + dmuci_get_value_by_section_string(vcf_sec, "name", value); if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) { while ((d_file = readdir (dir)) != NULL) { if(strcmp(*value, d_file->d_name) == 0) { @@ -382,69 +428,53 @@ int get_vcf_date(char *refparam, struct dmctx *ctx, char **value) *value = dmstrdup(date); } } - closedir (dir); + closedir (dir); } return 0; } -int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, char **value) +int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dev_vcf.vcf_sec, "backup_restore", value); + struct uci_section *vcf_sec = (struct uci_section *)data; + dmuci_get_value_by_section_string(vcf_sec, "backup_restore", value); return 0; } -int get_vcf_desc(char *refparam, struct dmctx *ctx, char **value) +int get_vcf_desc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dev_vcf.vcf_sec, "description", value); + struct uci_section *vcf_sec = (struct uci_section *)data; + dmuci_get_value_by_section_string(vcf_sec, "description", value); return 0; } -int get_vcf_alias(char *refparam, struct dmctx *ctx, char **value) +int get_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dev_vcf.vcf_sec, "vcf_alias", value); + struct uci_section *vcf_sec = (struct uci_section *)data; + dmuci_get_value_by_section_string(vcf_sec, "vcf_alias", value); return 0; } -int lookup_vcf_name(char *instance, char **value) { +int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *vcf_sec = (struct uci_section *)data; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(vcf_sec, "vcf_alias", value); + return 0; + } + return 0; +} + +int lookup_vcf_name(char *instance, char **value) +{ struct uci_section *s = NULL; uci_path_foreach_option_eq(icwmpd, DMMAP, "vcf", "vcf_instance", instance, s) { dmuci_get_value_by_section_string(s, "name", value); } return 0; } -/************************************************************* - * ENTRY METHOD -/*************************************************************/ -int entry_method_root_DeviceInfo(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"DeviceInfo.") { - DMOBJECT(DMROOT"DeviceInfo.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("Manufacturer", ctx, "0", get_device_manufacturer, NULL, NULL, 1, 1, UNDEF, NULL); - DMPARAM("ManufacturerOUI", ctx, "0", get_device_manufactureroui, NULL, NULL, 1, 1, UNDEF, NULL); - DMPARAM("ModelName", ctx, "0", get_device_routermodel, NULL, NULL, 1, 1, UNDEF, NULL); - DMPARAM("ProductClass", ctx, "0", get_device_productclass, NULL, NULL, 1, 1, UNDEF, NULL); - DMPARAM("SerialNumber", ctx, "0", get_device_serialnumber, NULL, NULL, 1, 1, UNDEF, NULL); - DMPARAM("HardwareVersion", ctx, "0", get_device_hardwareversion, NULL, NULL, 1, 1, UNDEF, NULL); - DMPARAM("SoftwareVersion", ctx, "0", get_device_softwareversion, NULL, NULL, 1, 0, 2, NULL); - DMPARAM("UpTime", ctx, "0", get_device_info_uptime, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DeviceLog", ctx, "0", get_device_devicelog, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SpecVersion", ctx, "0", get_device_specversion, NULL, NULL, 1, 1, UNDEF, NULL); - DMPARAM("ProvisioningCode", ctx, "1", get_device_provisioningcode, set_device_provisioningcode, NULL, 1, 0, 2, NULL); - DMPARAM("X_INTENO_SE_BaseMacAddr", ctx, "0", get_base_mac_addr, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_MemoryBank", ctx, "1", get_device_memory_bank, set_device_memory_bank, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_CATVEnabled", ctx, "1", get_catv_enabled, set_device_catvenabled, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"DeviceInfo.X_INTENO_SE_CATV.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("Enabled", ctx, "1", get_catv_enabled, set_device_catvenabled, NULL, 0, 1, UNDEF, NULL); - DMPARAM("OpticalInputLevel", ctx, "0", get_catv_optical_input_level, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RFOutputLevel", ctx, "0", get_catv_rf_output_level, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Temperature", ctx, "0", get_catv_temperature, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Voltage", ctx, "0", get_catv_voltage, NULL, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"DeviceInfo.VendorConfigFile.", ctx, "0", 0, NULL, NULL, NULL); - SUBENTRY(entry_method_device_info_vcf, ctx); - return 0; - } - return FAULT_9005; -} int check_file_dir(char *name) { @@ -457,12 +487,13 @@ int check_file_dir(char *name) return 1; } } - closedir(dir); + closedir(dir); } return 0; } -inline int entry_method_device_info_vcf(struct dmctx *ctx) + +int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *vcf = NULL, *vcf_last = NULL, *name; struct uci_section *s = NULL, *del_sec = NULL; @@ -487,26 +518,11 @@ inline int entry_method_device_info_vcf(struct dmctx *ctx) del_sec = s; continue; } - init_args_vcf(ctx, s); - vcf = handle_update_instance(1, ctx, &vcf_last, update_instance_alias_icwmpd, 3, s, "vcf_instance", "vcf_alias"); - SUBENTRY(entry_method_device_info_vcf_instance, ctx, vcf); + vcf = handle_update_instance(1, dmctx, &vcf_last, update_instance_alias_icwmpd, 3, s, "vcf_instance", "vcf_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, vcf) == DM_STOP) + break; } if(del_sec) DMUCI_DELETE_BY_SECTION(icwmpd, del_sec, NULL, NULL); return 0; } - -inline int entry_method_device_info_vcf_instance(struct dmctx *ctx, char *ivcf) -{ - IF_MATCH(ctx, DMROOT"DeviceInfo.VendorConfigFile.%s.", ivcf) { - DMOBJECT(DMROOT"DeviceInfo.VendorConfigFile.%s.", ctx, "0", 1, NULL, NULL, NULL, ivcf); - DMPARAM("Alias", ctx, "0", get_vcf_alias, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_vcf_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Version", ctx, "0", get_vcf_version, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Date", ctx, "0", get_vcf_date, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("Description", ctx, "0", get_vcf_desc, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("UseForBackupRestore", ctx, "0", get_vcf_backup_restore, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/deviceinfo.h b/dm/dmtree/common/deviceinfo.h index c748435..bafa773 100644 --- a/dm/dmtree/common/deviceinfo.h +++ b/dm/dmtree/common/deviceinfo.h @@ -16,17 +16,49 @@ #define UPTIME "/proc/uptime" #define DEFAULT_CONFIG_DIR "/etc/config/" +extern DMLEAF tDeviceInfoParams[]; +extern DMLEAF tCatTvParams[]; +extern DMLEAF tVcfParams[]; +extern DMOBJ tDeviceInfoObj[]; char *get_deviceid_manufacturer(); char *get_deviceid_manufactureroui(); char *get_deviceid_productclass(); char *get_deviceid_serialnumber(); char *get_softwareversion(); -int entry_method_root_DeviceInfo(struct dmctx *ctx); int lookup_vcf_name(char *instance, char **value); +int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_device_manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_manufactureroui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_routermodel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_productclass(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_serialnumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_hardwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_softwareversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_info_uptime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_devicelog(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_specversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_base_mac_addr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_catv_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_catv_optical_input_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_catv_rf_output_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_catv_temperature(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_catv_voltage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vcf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vcf_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vcf_desc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vcf_backup_restore(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_device_memory_bank(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_device_catvenabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -struct dev_vcf -{ - struct uci_section *vcf_sec; -}; #endif diff --git a/dm/dmtree/common/managementserver.c b/dm/dmtree/common/managementserver.c index 3e40b28..c9397dd 100644 --- a/dm/dmtree/common/managementserver.c +++ b/dm/dmtree/common/managementserver.c @@ -13,15 +13,40 @@ #include #include #include "cwmp.h" -#include "ubus.h" +#include "dmmem.h" #include "dmcwmp.h" #include "dmuci.h" #include "dmubus.h" #include "dmcommon.h" #include "managementserver.h" -#include "xml.h" -int get_management_server_url(char *refparam, struct dmctx *ctx, char **value) +/*** ManagementServer. ***/ +DMLEAF tManagementServerParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, linker*/ +{"URL", &DMWRITE, DMT_STRING, get_management_server_url, set_management_server_url, NULL, NULL}, +{"Username", &DMWRITE, DMT_STRING, get_management_server_username, set_management_server_username, NULL, NULL}, +{"Password", &DMWRITE, DMT_STRING, get_empty, set_management_server_passwd, NULL, NULL}, +{"ParameterKey", &DMREAD, DMT_STRING, get_management_server_key, NULL, &DMFINFRM, &DMNONE}, +{"PeriodicInformEnable", &DMWRITE, DMT_BOOL, get_management_server_periodic_inform_enable, set_management_server_periodic_inform_enable, NULL, NULL}, +{"PeriodicInformInterval", &DMWRITE, DMT_UNINT, get_management_server_periodic_inform_interval, set_management_server_periodic_inform_interval, NULL, NULL}, +{"PeriodicInformTime", &DMWRITE, DMT_TIME, get_management_server_periodic_inform_time, set_management_server_periodic_inform_time, NULL, NULL}, +{"ConnectionRequestURL", &DMREAD, DMT_STRING, get_management_server_connection_request_url, NULL, &DMFINFRM, &DMACTIVE}, +{"ConnectionRequestUsername", &DMWRITE, DMT_STRING, get_management_server_connection_request_username, set_management_server_connection_request_username, NULL, NULL}, +{"ConnectionRequestPassword", &DMWRITE, DMT_STRING, get_empty, set_management_server_connection_request_passwd, NULL, NULL}, +{"HTTPCompressionSupported", &DMREAD, DMT_STRING, get_management_server_http_compression_supportted, NULL, NULL, NULL}, +{"HTTPCompression", &DMWRITE, DMT_STRING, get_management_server_http_compression, set_management_server_http_compression, NULL, NULL}, +{"LightweightNotificationProtocolsSupported", &DMREAD, DMT_STRING, get_lwn_protocol_supported, NULL, NULL, NULL}, +{"LightweightNotificationProtocolsUsed", &DMWRITE, DMT_STRING, get_lwn_protocol_used, set_lwn_protocol_used, NULL, NULL}, +{"UDPLightweightNotificationHost", &DMWRITE, DMT_STRING, get_lwn_host, set_lwn_host, NULL, NULL}, +{"UDPLightweightNotificationPort", &DMWRITE, DMT_STRING, get_lwn_port, set_lwn_port, NULL, NULL}, +{"CWMPRetryMinimumWaitInterval", &DMWRITE, DMT_UNINT, get_management_server_retry_min_wait_interval, set_management_server_retry_min_wait_interval, NULL, NULL}, +{"CWMPRetryIntervalMultiplier", &DMWRITE, DMT_UNINT, get_management_server_retry_interval_multiplier, set_management_server_retry_interval_multiplier, NULL, NULL}, +{"AliasBasedAddressing", &DMREAD, DMT_BOOL, get_alias_based_addressing, NULL, &DMFINFRM, NULL}, +{"InstanceMode", &DMWRITE, DMT_STRING, get_instance_mode, set_instance_mode, NULL, NULL}, +{0} +}; + +int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int i = 1; char *dhcp = NULL, *pch = NULL, *spch = NULL; @@ -66,10 +91,10 @@ int get_management_server_url(char *refparam, struct dmctx *ctx, char **value) *value = url; else *value = dmstrdup(DEFAULT_ACSURL); - return 0; + return 0; } -int set_management_server_url(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -83,13 +108,13 @@ int set_management_server_url(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_management_server_username(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "acs", "userid", value); return 0; } -int set_management_server_username(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -102,7 +127,7 @@ int set_management_server_username(char *refparam, struct dmctx *ctx, int action return 0; } -int set_management_server_passwd(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -115,19 +140,19 @@ int set_management_server_passwd(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_management_server_key(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "acs", "ParameterKey", value); return 0; } -int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_enable", value); return 0; } -int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -148,13 +173,13 @@ int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *c return 0; } -int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_interval", value); return 0; } -int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -167,7 +192,7 @@ int set_management_server_periodic_inform_interval(char *refparam, struct dmctx return 0; } -int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { time_t time_value; @@ -184,7 +209,7 @@ int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx return 0; } -int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct tm tm; char *p, buf[16]; @@ -203,7 +228,7 @@ int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx return 0; } -int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *ip, *port, *iface; @@ -219,13 +244,13 @@ int get_management_server_connection_request_url(char *refparam, struct dmctx *c return 0; } -int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "cpe", "userid", value); return 0; } -int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -238,7 +263,7 @@ int set_management_server_connection_request_username(char *refparam, struct dmc return 0; } -int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -251,13 +276,13 @@ int set_management_server_connection_request_passwd(char *refparam, struct dmctx return 0; } -int get_lwn_protocol_supported(char *refparam, struct dmctx *ctx, char **value) +int get_lwn_protocol_supported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "UDP"; return 0; } -int get_lwn_protocol_used(char *refparam, struct dmctx *ctx, char **value) +int get_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { bool b; char *tmp; @@ -271,7 +296,7 @@ int get_lwn_protocol_used(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -290,13 +315,13 @@ int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, int action, char *v return 0; } -int get_lwn_host(char *refparam, struct dmctx *ctx, char **value) +int get_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "lwn", "hostname", value); return 0; } -int set_lwn_host(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -309,13 +334,13 @@ int set_lwn_host(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_lwn_port(char *refparam, struct dmctx *ctx, char **value) +int get_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "lwn", "port", value); return 0; } -int set_lwn_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -328,19 +353,19 @@ int set_lwn_port(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_management_server_http_compression_supportted(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_http_compression_supportted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "GZIP,Deflate"; return 0; } -int get_management_server_http_compression(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "acs", "compression", value); return 0; } -int set_management_server_http_compression(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -356,13 +381,13 @@ int set_management_server_http_compression(char *refparam, struct dmctx *ctx, in return 0; } -int get_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "acs", "retry_min_wait_interval", value); return 0; } -int set_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int a; switch (action) { @@ -380,13 +405,13 @@ int set_management_server_retry_min_wait_interval(char *refparam, struct dmctx * return 0; } -int get_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, char **value) +int get_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "acs", "retry_interval_multiplier", value); return 0; } -int set_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, int action, char *value) +int set_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int a; switch (action) { @@ -404,7 +429,7 @@ int set_management_server_retry_interval_multiplier(char *refparam, struct dmctx return 0; } -int get_alias_based_addressing(char *refparam, struct dmctx *ctx, char **value) +int get_alias_based_addressing(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "cpe", "amd_version", value); if((*value)[0] == '\0'|| atoi(*value) <= AMD_4) { @@ -416,13 +441,13 @@ int get_alias_based_addressing(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_instance_mode(char *refparam, struct dmctx *ctx, char **value) +int get_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("cwmp", "cpe", "instance_mode", value); return 0; } -int set_instance_mode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -438,32 +463,4 @@ int set_instance_mode(char *refparam, struct dmctx *ctx, int action, char *value return 0; } -int entry_method_root_ManagementServer(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"ManagementServer.") { - DMOBJECT(DMROOT"ManagementServer.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("URL", ctx, "1", get_management_server_url, set_management_server_url, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Username", ctx, "1", get_management_server_username, set_management_server_username, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Password", ctx, "1", get_empty, set_management_server_passwd, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ParameterKey", ctx, "0", get_management_server_key, NULL, NULL, 1, 0, 0, NULL); - DMPARAM("PeriodicInformEnable", ctx, "1", get_management_server_periodic_inform_enable, set_management_server_periodic_inform_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("PeriodicInformInterval", ctx, "1", get_management_server_periodic_inform_interval, set_management_server_periodic_inform_interval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PeriodicInformTime", ctx, "1", get_management_server_periodic_inform_time, set_management_server_periodic_inform_time, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("ConnectionRequestURL", ctx, "0", get_management_server_connection_request_url, NULL, NULL, 1, 0, 2, NULL); - DMPARAM("ConnectionRequestUsername", ctx, "1", get_management_server_connection_request_username, set_management_server_connection_request_username, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ConnectionRequestPassword", ctx, "1", get_empty, set_management_server_connection_request_passwd, NULL, 0, 1, UNDEF, NULL); - DMPARAM("HTTPCompressionSupported", ctx, "0", get_management_server_http_compression_supportted, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("HTTPCompression", ctx, "1", get_management_server_http_compression, set_management_server_http_compression, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LightweightNotificationProtocolsSupported", ctx, "0", get_lwn_protocol_supported, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LightweightNotificationProtocolsUsed", ctx, "1", get_lwn_protocol_used, set_lwn_protocol_used, NULL, 0, 1, UNDEF, NULL); - DMPARAM("UDPLightweightNotificationHost", ctx, "1", get_lwn_host, set_lwn_host, NULL, 0, 1, UNDEF, NULL); - DMPARAM("UDPLightweightNotificationPort", ctx, "1", get_lwn_port, set_lwn_port, NULL, 0, 1, UNDEF, NULL); - DMPARAM("CWMPRetryMinimumWaitInterval", ctx, "1", get_management_server_retry_min_wait_interval, set_management_server_retry_min_wait_interval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("CWMPRetryIntervalMultiplier", ctx, "1", get_management_server_retry_interval_multiplier, set_management_server_retry_interval_multiplier, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("AliasBasedAddressing", ctx, "0", get_alias_based_addressing, NULL, "xsd:boolean", 1, 1, UNDEF, NULL); - DMPARAM("InstanceMode", ctx, "1", get_instance_mode, set_instance_mode, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/managementserver.h b/dm/dmtree/common/managementserver.h index 36f20d4..066c822 100644 --- a/dm/dmtree/common/managementserver.h +++ b/dm/dmtree/common/managementserver.h @@ -10,6 +10,44 @@ */ #ifndef __MANAGEMENT_SERVER_H #define __MANAGEMENT_SERVER_H +#include "dmcwmp.h" +extern DMLEAF tManagementServerParams[]; -int entry_method_root_ManagementServer(struct dmctx *ctx); -#endif \ No newline at end of file +int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_http_compression_supportted(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lwn_protocol_supported(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_alias_based_addressing(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_http_compression(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lwn_protocol_used(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lwn_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lwn_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_retry_min_wait_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_management_server_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_instance_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/common/root.c b/dm/dmtree/common/root.c index f0cbada..5b2e237 100644 --- a/dm/dmtree/common/root.c +++ b/dm/dmtree/common/root.c @@ -4,23 +4,239 @@ * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * Copyright (C) 2015 Inteno Broadband Technology AB - * Author MOHAMED Kallel - * Author Imen Bhiri - * Author Feten Besbes - * + * Copyright (C) 2012-2016 PIVA SOFTWARE (www.pivasoftware.com) + * Author: Imen Bhiri + * Author: Anis Ellouze */ #include "dmuci.h" #include "dmcwmp.h" #include "root.h" +#include "deviceinfo.h" +#include "managementserver.h" +#include "times.h" +#include "upnp.h" +#include "voice_services.h" +#include "x_inteno_se_ice.h" +#include "x_inteno_se_igmp.h" +#include "x_inteno_se_ipacccfg.h" +#include "x_inteno_se_logincfg.h" +#include "x_inteno_se_power_mgmt.h" +#include "x_inteno_syslog.h" +#include "softwaremodules.h" +#include "xmpp.h" +#include "x_inteno_se_owsd.h" +#include "x_inteno_se_dropbear.h" +#include "x_inteno_se_buttons.h" +#ifdef UPNP_TR064 +#include "upnp_deviceinfo.h" +#include "upnp_configuration.h" +#include "upnp_monitoring.h" +#endif -int entry_method_root(struct dmctx *ctx) -{ - char *val = NULL; - IF_MATCH_ROOT(ctx) { - DMOBJECT(DMROOT, ctx, "0", 0, NULL, NULL, NULL); - return 0; - } - return FAULT_9005; -} +#ifdef DATAMODEL_TR181 +#include "ip.h" +#include "ethernet.h" +#include "bridging.h" +#include "wifi.h" +#include "wan.h" +#include "dhcp.h" +#include "hosts.h" +#include "nat.h" +#include "ppp.h" +#include "routing.h" +#endif +#ifdef DATAMODEL_TR098 +#include "landevice.h" +#include "wandevice.h" +#include "ippingdiagnostics.h" +#include "lan_interfaces.h" +#include "layer_3_forwarding.h" +#include "x_inteno_se_wifi.h" +#include "layer_2_bridging.h" +#include "downloaddiagnostic.h" +#include "uploaddiagnostic.h" +#include "deviceconfig.h" +#endif + +/* *** CWMP *** */ +DMOBJ tEntryObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, NOTIFICATION, nextobj, leaf, linker*/ +{(char *)&DMROOT, &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE, tRootObj, NULL, NULL}, +{0} +}; + +DMOBJ tRootObj[] = { +/* OBJ permission, addobj, delobj, browseinstobj, finform, nextobj, leaf, notification, linker*/ +{"DeviceInfo", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tDeviceInfoObj, tDeviceInfoParams, NULL}, +{"ManagementServer", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tManagementServerParams, NULL}, +{"Time", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tTimeParams, NULL}, +{"UPnP", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,tUPnPObj, NULL, NULL}, +{"Services", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,tServiceObj, NULL, NULL}, +{"X_INTENO_SE_ICE", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_IceParam, NULL}, +{"X_INTENO_SE_IGMP", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_IgmpParam, NULL}, +{"X_INTENO_SE_IpAccCfg", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,tSe_IpAccObj, NULL, NULL}, +{"X_INTENO_SE_LoginCfg", &DMREAD, NULL, NULL, NULL, NULL,NULL, &DMNONE,NULL, tSe_LoginCfgParam, NULL}, +{"X_INTENO_SE_PowerManagement", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_PowerManagementParam, NULL}, +{"X_INTENO_SE_SyslogCfg", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_SyslogCfgParam, NULL}, +{"SoftwareModules", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,tSoftwareModulesObj, NULL, NULL}, +{"X_INTENO_SE_Owsd", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,XIntenoSeOwsdObj, XIntenoSeOwsdParams, NULL}, +{"X_INTENO_SE_Dropbear", &DMWRITE, add_dropbear_instance, delete_dropbear_instance, NULL, browseXIntenoDropbear, NULL, &DMNONE, NULL, X_INTENO_SE_DropbearParams, NULL}, +{"X_INTENO_SE_Buttons", &DMREAD, NULL, NULL, NULL, browseXIntenoButton, NULL, &DMNONE, NULL, X_INTENO_SE_ButtonParams, NULL}, +#ifdef DATAMODEL_TR098 +{"LANDevice", &DMREAD, NULL, NULL, NULL, browselandeviceInst, &DMFINFRM, &DMNONE,tLANDeviceObj, tLANDeviceParam, NULL}, +{"WANDevice", &DMREAD, NULL, NULL, NULL, browsewandeviceInst, &DMFINFRM, &DMWANConnectionDevicenotif,tWANDeviceObj, tWANDeviceParam, NULL}, +{"LANInterfaces", &DMREAD, NULL, NULL, check_laninterfaces, NULL, &DMFINFRM, &DMNONE,tLANInterfacesObj, tLANInterfacesParam, NULL}, +{"IPPingDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tIPPingDiagnosticsParam, NULL}, +{"Layer3Forwarding", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tLayer3ForwardingObj, tLayer3ForwardingParam, NULL}, +{"Layer2Bridging", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tLayer2BridgingObj, NULL, NULL}, +{"X_INTENO_SE_Wifi", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tsewifiObj, tsewifiParam, NULL}, +{"DownloadDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tDownloadDiagnosticsParam, NULL}, +{"UploadDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tUploadDiagnosticsParam, NULL}, +{"DeviceConfig", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tDeviceConfigParam, NULL}, +#endif +#ifdef XMPP_ENABLE +{"XMPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL,tXMPPObj, tXMPPParams, NULL}, +#endif +#ifdef DATAMODEL_TR181 +{"Bridging",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tBridgingObj, NULL, NULL}, +{"WiFi",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tWifiObj, tWifiParams, NULL}, +{"IP",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tIPObj, NULL, NULL}, +{"Ethernet", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tEthernetObj, NULL, NULL}, +{"DSL",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDslObj, NULL, NULL}, +{"ATM",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tAtmObj, NULL, NULL}, +{"PTM", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tPtmObj, NULL, NULL}, +{"DHCPv4", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDhcpv4Obj, NULL, NULL}, +{"Hosts", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, thostsObj, thostsParam, NULL}, +{"NAT", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tnatObj, NULL, NULL}, +{"PPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tpppObj, NULL, NULL}, +{"Routing", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tRoutingObj, tRoutingParam, NULL}, +#endif +{0} +}; + +/*** UPNP ***/ +#ifdef UPNP_TR064 +DMOBJ tEntryObjUPNP[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, NOTIFICATION, nextobj, leaf, linker*/ +{(char *)&DMROOT, &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE, tRootObjUPNP, NULL, NULL}, +{0} +}; + +DMOBJ tRootObjUPNP[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, NOTIFICATION, nextobj, leaf, linker*/ +{"BBF", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE, tRootObjUPNPBBF, NULL, NULL}, +{"UPnP", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE, tRootObjUPNPDMROOT, NULL, NULL}, +{0} +}; + +DMOBJ tRootObjUPNPDMROOT[] = { +{"DM", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE, tRootObjUPNPDM, NULL, NULL}, +{0} +}; + +DMOBJ tRootObjUPNPDM[] = { +{"DeviceInfo", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,upnpDeviceInfoObj, upnpDeviceInfoParams, NULL}, +{"Configuration", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,upnpConfigurationObj, NULL, NULL}, +{"Monitoring", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,upnpMonitoringObj, upnpMonitoringParams, NULL}, +{0} +}; + +DMOBJ tRootObjUPNPBBF[] = { +/* OBJ permission, addobj, delobj, browseinstobj, finform, nextobj, leaf, notification, linker*/ +{"DeviceInfo", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tDeviceInfoObj, tDeviceInfoParams, NULL}, +{"ManagementServer", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tManagementServerParams, NULL}, +{"Time", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tTimeParams, NULL}, +{"UPnP", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,tUPnPObj, NULL, NULL}, +{"VoiceService", &DMREAD, NULL, NULL, NULL, browseVoiceServiceInst, NULL, NULL, tVoiceServiceObj, tVoiceServiceParam, NULL}, +{"X_INTENO_SE_ICE", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_IceParam, NULL}, +{"X_INTENO_SE_IGMP", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_IgmpParam, NULL}, +{"X_INTENO_SE_IpAccCfg", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,tSe_IpAccObj, NULL, NULL}, +{"X_INTENO_SE_LoginCfg", &DMREAD, NULL, NULL, NULL, NULL,NULL, &DMNONE,NULL, tSe_LoginCfgParam, NULL}, +{"X_INTENO_SE_PowerManagement", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_PowerManagementParam, NULL}, +{"X_INTENO_SE_SyslogCfg", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,NULL, tSe_SyslogCfgParam, NULL}, +{"SoftwareModules", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,tSoftwareModulesObj, NULL, NULL}, +{"X_INTENO_SE_Owsd", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE,XIntenoSeOwsdObj, XIntenoSeOwsdParams, NULL}, +{"X_INTENO_SE_Dropbear", &DMWRITE, add_dropbear_instance, delete_dropbear_instance, NULL, browseXIntenoDropbear, NULL, &DMNONE, NULL, X_INTENO_SE_DropbearParams, NULL}, +{"X_INTENO_SE_Buttons", &DMREAD, NULL, NULL, NULL, browseXIntenoButton, NULL, &DMNONE, NULL, X_INTENO_SE_ButtonParams, NULL}, +#ifdef DATAMODEL_TR098 +{"LANDevice", &DMREAD, NULL, NULL, NULL, browselandeviceInst, &DMFINFRM, &DMNONE,tLANDeviceObj, tLANDeviceParam, NULL}, +{"WANDevice", &DMREAD, NULL, NULL, NULL, browsewandeviceInst, &DMFINFRM, &DMWANConnectionDevicenotif,tWANDeviceObj, tWANDeviceParam, NULL}, +{"LANInterfaces", &DMREAD, NULL, NULL, check_laninterfaces, NULL, &DMFINFRM, &DMNONE,tLANInterfacesObj, tLANInterfacesParam, NULL}, +{"IPPingDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tIPPingDiagnosticsParam, NULL}, +{"Layer3Forwarding", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tLayer3ForwardingObj, tLayer3ForwardingParam, NULL}, +{"Layer2Bridging", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tLayer2BridgingObj, NULL, NULL}, +{"X_INTENO_SE_Wifi", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,tsewifiObj, NULL, NULL}, +{"DownloadDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tDownloadDiagnosticsParam, NULL}, +{"UploadDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, &DMFINFRM, &DMNONE,NULL, tUploadDiagnosticsParam, NULL}, +#endif +#ifdef XMPP_ENABLE +{"XMPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL,tXMPPObj, tXMPPParams, NULL}, +#endif +#ifdef DATAMODEL_TR181 +{"Bridging",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tBridgingObj, NULL, NULL}, +{"WiFi",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tWifiObj, NULL, NULL}, +{"IP",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tIPObj, NULL, NULL}, +{"Ethernet", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tEthernetObj, NULL, NULL}, +{"DSL",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDslObj, NULL, NULL}, +{"ATM",&DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tAtmObj, NULL, NULL}, +{"PTM", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tPtmObj, NULL, NULL}, +{"DHCPv4", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDhcpv4Obj, NULL, NULL}, +{"Hosts", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, thostsObj, thostsParam, NULL}, +{"NAT", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tnatObj, NULL, NULL}, +{"PPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tpppObj, NULL, NULL}, +{"Routing", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tRoutingObj, tRoutingParam, NULL}, +#endif +{0} +}; + +UPNP_SUPPORTED_DM tUPNPSupportedDM[] = { +{"/UPnP/DM/DeviceInfo/", "urn:UPnP:Parent Device:1:ConfigurationManagement:2", DMROOT_URL, "UPnP DeviceInfo from "DMROOT_DESC, ""}, +{"/UPnP/DM/Configuration/", "urn:UPnP:Parent Device:1:ConfigurationManagement:2", DMROOT_URL, "Configuration from "DMROOT_DESC, ""}, +{"/UPnP/DM/Monitoring/", "urn:UPnP:Parent Device:1:ConfigurationManagement:2", DMROOT_URL, "Monitoring from "DMROOT_DESC, ""}, +{"/BBF/DeviceInfo/", DMROOT_URI, DMROOT_URL, "DeviceInfo from "DMROOT_DESC, ""}, +{"/BBF/ManagementServer/", DMROOT_URI, DMROOT_URL, "ManagementServer from "DMROOT_DESC, ""}, +{"/BBF/Time/", DMROOT_URI, DMROOT_URL, "Time from "DMROOT_DESC, ""}, +{"/BBF/UPnP/", DMROOT_URI, DMROOT_URL, "UPnP from "DMROOT_DESC, ""}, +{"/BBF/VoiceService/", "urn:broadband-forum-org:wt-104-2-0-0", "https://www.broadband-forum.org/cwmp/tr-104-2-0-0.html", "TR-104 Voice:2 Service Object definition", ""}, +{"/BBF/X_INTENO_SE_ICE/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for ICE", ""}, +{"/BBF/X_INTENO_SE_IGMP/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for ICE", ""}, +{"/BBF/X_INTENO_SE_IpAccCfg/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for IGMP", ""}, +{"/BBF/X_INTENO_SE_LoginCfg/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for LoginCfg", ""}, +{"/BBF/X_INTENO_SE_PowerManagement/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for PowerManagement", ""}, +{"/BBF/X_INTENO_SE_SyslogCfg/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for SyslogCfg", ""}, +{"/BBF/SoftwareModules/", DMROOT_URI, DMROOT_URL, "SoftwareModules from "DMROOT_DESC, ""}, +{"/BBF/X_INTENO_SE_Owsd/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for Owsd", ""}, +{"/BBF/X_INTENO_SE_Dropbear/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for Dropbear", ""}, +{"/BBF/X_INTENO_SE_Buttons/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for Buttons", ""}, +#ifdef DATAMODEL_TR098 +{"/BBF/LANDevice/", DMROOT_URI, DMROOT_URL, "LANDevice from "DMROOT_DESC, ""}, +{"/BBF/WANDevice/", DMROOT_URI, DMROOT_URL, "WANDevice from "DMROOT_DESC, ""}, +{"/BBF/LANInterfaces/", DMROOT_URI, DMROOT_URL, "LANInterfaces from "DMROOT_DESC, ""}, +{"/BBF/IPPingDiagnostics/", DMROOT_URI, DMROOT_URL, "IPPingDiagnostics from "DMROOT_DESC, ""}, +{"/BBF/Layer3Forwarding/", DMROOT_URI, DMROOT_URL, "Layer3Forwarding from "DMROOT_DESC, ""}, +{"/BBF/Layer2Bridging/", DMROOT_URI, DMROOT_URL, "Layer2Bridging from "DMROOT_DESC, ""}, +{"/BBF/X_INTENO_SE_Wifi/", "urn:intenogroup-com:na", "https://www.intenogroup.com/", "Inteno extension for WiFi", ""}, +{"/BBF/DownloadDiagnostics/", DMROOT_URI, DMROOT_URL, "DownloadDiagnostics from "DMROOT_DESC, ""}, +{"/BBF/UploadDiagnostics/", DMROOT_URI, DMROOT_URL, "UploadDiagnostics from "DMROOT_DESC, ""}, +#endif +#ifdef XMPP_ENABLE +{"/BBF/XMPP/", DMROOT_URI, DMROOT_URL, "XMPP from "DMROOT_DESC, ""}, +#endif +#ifdef DATAMODEL_TR181 +{"/BBF/Bridging/", DMROOT_URI, DMROOT_URL, "Bridging from "DMROOT_DESC, ""}, +{"/BBF/WiFi/", DMROOT_URI, DMROOT_URL, "WiFi from "DMROOT_DESC, ""}, +{"/BBF/IP/", DMROOT_URI, DMROOT_URL, "IP from "DMROOT_DESC, ""}, +{"/BBF/Ethernet/", DMROOT_URI, DMROOT_URL, "Ethernet from "DMROOT_DESC, ""}, +{"/BBF/DSL/", DMROOT_URI, DMROOT_URL, "DSL from "DMROOT_DESC, ""}, +{"/BBF/ATM/", DMROOT_URI, DMROOT_URL, "ATM from "DMROOT_DESC, ""}, +{"/BBF/PTM/", DMROOT_URI, DMROOT_URL, "PTM from "DMROOT_DESC, ""}, +{"/BBF/DHCPv4/", DMROOT_URI, DMROOT_URL, "DHCPv4 from "DMROOT_DESC, ""}, +{"/BBF/Hosts/", DMROOT_URI, DMROOT_URL, "Hosts from "DMROOT_DESC, ""}, +{"/BBF/NAT/", DMROOT_URI, DMROOT_URL, "NAT from "DMROOT_DESC, ""}, +{"/BBF/PPP/", DMROOT_URI, DMROOT_URL, "PPP from "DMROOT_DESC, ""}, +{"/BBF/Routing/", DMROOT_URI, DMROOT_URL, "Routing from "DMROOT_DESC, ""}, +#endif +{0} +}; +#endif diff --git a/dm/dmtree/common/root.h b/dm/dmtree/common/root.h index 741a259..2e22bc3 100644 --- a/dm/dmtree/common/root.h +++ b/dm/dmtree/common/root.h @@ -13,6 +13,33 @@ #ifndef __ROOT_H #define __ROOT_H + #include "dmcwmp.h" -int entry_method_root(struct dmctx *ctx); + +extern DMOBJ tEntryObj[]; +extern DMOBJ tRootObj[]; + +#ifdef UPNP_TR064 +extern DMOBJ tEntryObjUPNP[]; +extern DMOBJ tRootObjUPNP[]; +extern DMOBJ tRootObjUPNPDMROOT[]; +extern DMOBJ tRootObjUPNPDM[]; +extern DMOBJ tRootObjUPNPBBF[]; +extern UPNP_SUPPORTED_DM tUPNPSupportedDM[]; + +#define UPNP_SUPPORTED_PARAMETERS_VERSION 1 //Should be incremented each time the Parameters are updated +#define UPNP_SUPPORTED_DATAMODEL_VERSION 1 //Should be incremented each time the tUPNPSupportedDM array is updated +#endif + +#ifdef DATAMODEL_TR098 +#define DMROOT_URI "urn:broadband-forum-org:tr-098-1-8-0" +#define DMROOT_URL "https://www.broadband-forum.org/cwmp/tr-098-1-8-0.html" +#define DMROOT_DESC "TR-098 InternetGatewayDevice:1 Root Object definition" +#endif +#ifdef DATAMODEL_TR181 +#define DMROOT_URI "urn:broadband-forum-org:tr-181-2-11-0" +#define DMROOT_URL "https://www.broadband-forum.org/cwmp/tr-181-2-11-0.html" +#define DMROOT_DESC "TR-181 Device:2 Root Object definition" +#endif + #endif diff --git a/dm/dmtree/common/softwaremodules.c b/dm/dmtree/common/softwaremodules.c index 7efb089..ad81181 100644 --- a/dm/dmtree/common/softwaremodules.c +++ b/dm/dmtree/common/softwaremodules.c @@ -12,80 +12,87 @@ #include #include #include -#include "cwmp.h" -#include "diagnostic.h" -#include "ubus.h" #include "dmcwmp.h" #include "dmuci.h" #include "dmubus.h" #include "dmcommon.h" #include "softwaremodules.h" -struct software_module cur_software_module = {0}; -inline int entry_softwaremodules_deploymentunit_instance(struct dmctx *ctx, char *idu); -inline int init_args_du_entry(struct dmctx *ctx, struct uci_section *s) + +/*** SoftwareModules. ***/ +DMOBJ tSoftwareModulesObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"DeploymentUnit", &DMREAD, NULL, NULL, NULL, browsesoftwaremodules_deploymentunitInst, NULL, NULL, NULL, tDeploymentUnitParams, NULL}, +{0} +}; + +DMLEAF tDeploymentUnitParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"UUID", &DMREAD, DMT_STRING, get_deploymentunit_uuid, NULL, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_deploymentunit_name, NULL, NULL, NULL}, +{"Resolved", &DMREAD, DMT_BOOL, get_deploymentunit_resolved, NULL, NULL, NULL}, +{"URL", &DMREAD, DMT_STRING, get_deploymentunit_url, NULL, NULL, NULL}, +{"Vendor", &DMREAD, DMT_STRING, get_deploymentunit_vendor, NULL, NULL, NULL}, +{"Version", &DMREAD, DMT_STRING, get_deploymentunit_version, NULL, NULL, NULL}, +{"ExecutionEnvRef", &DMREAD, DMT_STRING, get_deploymentunit_execution_env_ref, NULL, NULL, NULL}, +{0} +}; + +int get_deploymentunit_uuid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct software_module *args = &cur_software_module; - ctx->args = (void *)args; - args->softsection = s; - return 0; -} + struct uci_section *softsection = (struct uci_section *)data; -int get_deploymentunit_uuid(char *refparam, struct dmctx *ctx, char **value) -{ - struct software_module *softawreargs = (struct software_module *)ctx->args; - - dmuci_get_value_by_section_string(softawreargs->softsection, "uuid", value); + dmuci_get_value_by_section_string(softsection, "uuid", value); return 0; } -int get_deploymentunit_name(char *refparam, struct dmctx *ctx, char **value) +int get_deploymentunit_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct software_module *softawreargs = (struct software_module *)ctx->args; + struct uci_section *softsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(softawreargs->softsection, "name", value); + dmuci_get_value_by_section_string(softsection, "name", value); return 0; } -int get_deploymentunit_resolved(char *refparam, struct dmctx *ctx, char **value) +int get_deploymentunit_resolved(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct software_module *softawreargs = (struct software_module *)ctx->args; + struct uci_section *softsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(softawreargs->softsection, "resolved", value); + dmuci_get_value_by_section_string(softsection, "resolved", value); return 0; } -int get_deploymentunit_url(char *refparam, struct dmctx *ctx, char **value) +int get_deploymentunit_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct software_module *softawreargs = (struct software_module *)ctx->args; + struct uci_section *softsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(softawreargs->softsection, "url", value); + dmuci_get_value_by_section_string(softsection, "url", value); return 0; } -int get_deploymentunit_vendor(char *refparam, struct dmctx *ctx, char **value) +int get_deploymentunit_vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct software_module *softawreargs = (struct software_module *)ctx->args; + struct uci_section *softsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(softawreargs->softsection, "vendor", value); + dmuci_get_value_by_section_string(softsection, "vendor", value); return 0; } -int get_deploymentunit_version(char *refparam, struct dmctx *ctx, char **value) +int get_deploymentunit_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct software_module *softawreargs = (struct software_module *)ctx->args; + struct uci_section *softsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(softawreargs->softsection, "version", value); + dmuci_get_value_by_section_string(softsection, "version", value); return 0; } -int get_deploymentunit_execution_env_ref(char *refparam, struct dmctx *ctx, char **value) +int get_deploymentunit_execution_env_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct software_module *softawreargs = (struct software_module *)ctx->args; + struct uci_section *softsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(softawreargs->softsection, "execution_env_ref", value); + dmuci_get_value_by_section_string(softsection, "execution_env_ref", value); return 0; } @@ -222,44 +229,21 @@ char *get_softwaremodules_version(char *uuid) return ""; } -inline int entry_softwaremodules_deploymentunit(struct dmctx *ctx) + + + +int browsesoftwaremodules_deploymentunitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *idu = NULL, *idu_last = NULL; char *permission = "1"; struct uci_section *s = NULL; uci_path_foreach_sections(icwmpd, "dmmap", "deploymentunit", s) { - init_args_du_entry(ctx, s); - idu = handle_update_instance(1, ctx, &idu_last, update_instance_alias_icwmpd, 3, s, "duinstance", "duinstance_alias"); - SUBENTRY(entry_softwaremodules_deploymentunit_instance, ctx, idu); + idu = handle_update_instance(1, dmctx, &idu_last, update_instance_alias_icwmpd, 3, s, "duinstance", "duinstance_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, idu) == DM_STOP) + break; } return 0; } -inline int entry_softwaremodules_deploymentunit_instance(struct dmctx *ctx, char *idu) -{ - IF_MATCH(ctx, DMROOT"SoftwareModules.DeploymentUnit.%s.", idu) { - DMOBJECT(DMROOT"SoftwareModules.DeploymentUnit.%s.", ctx, "0", 1, NULL, NULL, NULL, idu); - DMPARAM("UUID", ctx, "0", get_deploymentunit_uuid, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_deploymentunit_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Resolved", ctx, "0", get_deploymentunit_resolved, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("URL", ctx, "0", get_deploymentunit_url, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Vendor", ctx, "0", get_deploymentunit_vendor, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Version", ctx, "0", get_deploymentunit_version, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExecutionEnvRef", ctx, "0", get_deploymentunit_execution_env_ref, NULL, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -int entry_method_root_software_modules(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"SoftwareModules.") { - DMOBJECT(DMROOT"SoftwareModules.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"SoftwareModules.DeploymentUnit.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_softwaremodules_deploymentunit, ctx); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/softwaremodules.h b/dm/dmtree/common/softwaremodules.h index cb8b6f0..19f996f 100644 --- a/dm/dmtree/common/softwaremodules.h +++ b/dm/dmtree/common/softwaremodules.h @@ -10,12 +10,7 @@ #ifndef __SOFTWARE_MODULE_H #define __SOFTWARE_MODULE_H -struct software_module -{ - struct uci_section *softsection; -}; int update_softwaremodules_url(char *uuid, char *url); -char *get_softwaremodules_url(char *uuid); char *get_softwaremodules_uuid(char *url); char *get_softwaremodules_username(char *uuid); char *get_softwaremodules_pass(char *uuid); @@ -23,5 +18,17 @@ char *get_softwaremodules_instance(char *uuid); char *get_softwaremodules_version(char *uuid); char *add_softwaremodules_deploymentunit(char *uuid, char*url, char *username, char *password, char *name, char *version); char *get_softwaremodules_name(char *uuid); -int entry_method_root_software_modules(struct dmctx *ctx); +char *get_softwaremodules_url(char *uuid); +extern DMLEAF tDeploymentUnitParams[]; +extern DMOBJ tSoftwareModulesObj[]; + +int browsesoftwaremodules_deploymentunitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int get_deploymentunit_uuid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_deploymentunit_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_deploymentunit_resolved(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_deploymentunit_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_deploymentunit_vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_deploymentunit_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_deploymentunit_execution_env_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + #endif diff --git a/dm/dmtree/common/times.c b/dm/dmtree/common/times.c index bd99a7c..babe6c1 100644 --- a/dm/dmtree/common/times.c +++ b/dm/dmtree/common/times.c @@ -17,7 +17,19 @@ #include "times.h" #include "dmcommon.h" -int get_time_enable(char *refparam, struct dmctx *ctx, char **value) + +/*** Time. ***/ +DMLEAF tTimeParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification, linker*/ +{"Enable", &DMWRITE, DMT_BOOL, get_time_enable, set_time_enable, NULL, NULL}, +{"NTPServer1", &DMWRITE, DMT_STRING, get_time_ntpserver1, set_time_ntpserver1, NULL, NULL}, +{"NTPServer2", &DMWRITE, DMT_STRING, get_time_ntpserver2, set_time_ntpserver2, NULL, NULL}, +{"NTPServer3", &DMWRITE, DMT_STRING, get_time_ntpserver3, set_time_ntpserver3, NULL, NULL}, +{"NTPServer4", &DMWRITE, DMT_STRING, get_time_ntpserver4, set_time_ntpserver4, NULL, NULL}, +{"NTPServer5", &DMWRITE, DMT_STRING, get_time_ntpserver5, set_time_ntpserver5, NULL, NULL}, +{0} +}; +int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *path = "/etc/rc.d/*sysntpd"; @@ -28,7 +40,7 @@ int get_time_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_time_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; int check; @@ -90,27 +102,27 @@ int get_time_ntpserver(char *refparam, struct dmctx *ctx, char **value, int inde return 0; } -int get_time_ntpserver1(char *refparam, struct dmctx *ctx, char **value) +int get_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 1); } -int get_time_ntpserver2(char *refparam, struct dmctx *ctx, char **value) +int get_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 2); } -int get_time_ntpserver3(char *refparam, struct dmctx *ctx, char **value) +int get_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 3); } -int get_time_ntpserver4(char *refparam, struct dmctx *ctx, char **value) +int get_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 4); } -int get_time_ntpserver5(char *refparam, struct dmctx *ctx, char **value) +int get_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { return get_time_ntpserver(refparam, ctx, value, 5); } @@ -161,42 +173,28 @@ int set_time_ntpserver(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int set_time_ntpserver1(char *refparam, struct dmctx *ctx, int action, char *value) +int set_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 1); } -int set_time_ntpserver2(char *refparam, struct dmctx *ctx, int action, char *value) +int set_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 2); } -int set_time_ntpserver3(char *refparam, struct dmctx *ctx, int action, char *value) +int set_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 3); } -int set_time_ntpserver4(char *refparam, struct dmctx *ctx, int action, char *value) +int set_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 4); } -int set_time_ntpserver5(char *refparam, struct dmctx *ctx, int action, char *value) +int set_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { return set_time_ntpserver(refparam, ctx, action, value, 5); } -int entry_method_root_Time(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Time.") { - DMOBJECT(DMROOT"Time.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("Enable", ctx, "1", get_time_enable, set_time_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("NTPServer1", ctx, "1", get_time_ntpserver1, set_time_ntpserver1, NULL, 0, 1, UNDEF, NULL); - DMPARAM("NTPServer2", ctx, "1", get_time_ntpserver2, set_time_ntpserver2, NULL, 0, 1, UNDEF, NULL); - DMPARAM("NTPServer3", ctx, "1", get_time_ntpserver3, set_time_ntpserver3, NULL, 0, 1, UNDEF, NULL); - DMPARAM("NTPServer4", ctx, "1", get_time_ntpserver4, set_time_ntpserver4, NULL, 0, 1, UNDEF, NULL); - DMPARAM("NTPServer5", ctx, "1", get_time_ntpserver5, set_time_ntpserver5, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/times.h b/dm/dmtree/common/times.h index 6ae764a..1a12870 100644 --- a/dm/dmtree/common/times.h +++ b/dm/dmtree/common/times.h @@ -1,6 +1,20 @@ #ifndef __TIMES_H #define __TIMES_H -int entry_method_root_Time(struct dmctx *ctx); +extern DMLEAF tTimeParams[]; -#endif \ No newline at end of file +int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_time_ntpserver1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_time_ntpserver2(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_time_ntpserver3(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_time_ntpserver4(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/common/upnp.c b/dm/dmtree/common/upnp.c index 980b20e..f40ecef 100644 --- a/dm/dmtree/common/upnp.c +++ b/dm/dmtree/common/upnp.c @@ -18,7 +18,21 @@ #include "dmcommon.h" #include "upnp.h" -int get_upnp_enable(char *refparam, struct dmctx *ctx, char **value) +/*** UPnP. ***/ +DMOBJ tUPnPObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Device", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tUPnPDeviceParams, NULL}, +{0} +}; + +DMLEAF tUPnPDeviceParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Enable", &DMWRITE, DMT_BOOL, get_upnp_enable, set_upnp_enable, NULL, NULL}, +{"X_INTENO_SE_Status", &DMREAD, DMT_STRING, get_upnp_status, NULL, NULL, NULL}, +{0} +}; + +int get_upnp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("upnpd","config","enabled", value); if ((*value)[0] == '\0') { @@ -27,7 +41,7 @@ int get_upnp_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_upnp_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_upnp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; int check; @@ -47,7 +61,7 @@ int set_upnp_enable(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_upnp_status(char *refparam, struct dmctx *ctx, char **value) +int get_upnp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { pid_t pid = get_pid("miniupnpd"); @@ -59,15 +73,3 @@ int get_upnp_status(char *refparam, struct dmctx *ctx, char **value) } return 0; } - -int entry_method_root_upnp(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"UPnP.") { - DMOBJECT(DMROOT"UPnP.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"UPnP.Device.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("Enable", ctx, "1", get_upnp_enable, set_upnp_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_Status", ctx, "0", get_upnp_status, NULL, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/upnp.h b/dm/dmtree/common/upnp.h index c22caa9..bd8a7ea 100644 --- a/dm/dmtree/common/upnp.h +++ b/dm/dmtree/common/upnp.h @@ -1,6 +1,12 @@ #ifndef __UPNP_H #define __UPNP_H -int entry_method_root_upnp(struct dmctx *ctx); +extern DMLEAF tUPnPDeviceParams[]; +extern DMOBJ tUPnPObj[]; -#endif \ No newline at end of file +int get_upnp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_upnp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_upnp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/common/voice_services.c b/dm/dmtree/common/voice_services.c index 36b56b2..88ee8e3 100644 --- a/dm/dmtree/common/voice_services.c +++ b/dm/dmtree/common/voice_services.c @@ -19,12 +19,256 @@ #include "voice_services.h" #include "dmjson.h" +/*** DMROOT.Services. ****/ +DMOBJ tServiceObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"VoiceService", &DMREAD, NULL, NULL, NULL, browseVoiceServiceInst, NULL, NULL, tVoiceServiceObj, tVoiceServiceParam, NULL}, +{0} +}; + +/*** VoiceService.{i}. ****/ +DMOBJ tVoiceServiceObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +//{"Capabilities", &DMREAD, NULL, NULL, NULL, NULL, NULL, tCapabilitiesParams, NULL}, +{"Capabilities", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tCapabilitiesObj, tCapabilitiesParams, NULL}, +{"VoiceProfile", &DMWRITE, add_profile_object, delete_profile_object, NULL, browseProfileInst, NULL, NULL, tProfileObj, tProfileParam, NULL}, +{0} +}; + +DMLEAF tVoiceServiceParam[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_service_alias, set_service_alias, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.Capabilities. ****/ +DMOBJ tCapabilitiesObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"SIP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tSIPParams, NULL}, +{"Codecs", &DMREAD, NULL, NULL, NULL, browseCodecsInst, NULL, NULL, NULL, tCodecsParams, NULL}, +{0} +}; + +DMLEAF tCapabilitiesParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"MaxProfileCount", &DMREAD, DMT_UNINT, get_max_profile_count, NULL, NULL, NULL}, +{"MaxLineCount", &DMREAD, DMT_UNINT, get_max_line_count, NULL, NULL, NULL}, +{"MaxSessionsPerLine", &DMREAD, DMT_UNINT, get_true_value, NULL, NULL, NULL}, +{"MaxSessionCount", &DMREAD, DMT_UNINT, get_max_session_count, NULL, NULL, NULL}, +{"SignalingProtocols", &DMREAD, DMT_STRING, get_signal_protocols, NULL, NULL, NULL}, +{"Regions", &DMREAD, DMT_STRING, get_regions, NULL, NULL, NULL}, +{"RTCP", &DMREAD, DMT_BOOL, get_true_value, NULL, NULL, NULL}, +{"SRTP", &DMREAD, DMT_BOOL, get_true_value, NULL, NULL, NULL}, +{"RTPRedundancy", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"PSTNSoftSwitchOver", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"FaxT38", &DMREAD, DMT_BOOL, get_true_value, NULL, NULL, NULL}, +{"FaxPassThrough", &DMREAD, DMT_BOOL, get_true_value, NULL, NULL, NULL}, +{"ModemPassThrough", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"ToneGeneration", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"ToneDescriptionsEditable", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"PatternBasedToneGeneration", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"FileBasedToneGeneration", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"ToneFileFormats", &DMREAD, DMT_STRING, get_empty, NULL, NULL, NULL}, +{"RingGeneration", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"RingDescriptionsEditable", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"PatternBasedRingGeneration", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"RingPatternEditable", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"FileBasedRingGeneration", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"RingFileFormats", &DMREAD, DMT_STRING, get_empty, NULL, NULL, NULL}, +{"DigitMap", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"NumberingPlan", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"ButtonMap", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"VoicePortTests", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.Capabilities.SIP. ****/ +DMLEAF tSIPParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Role", &DMREAD, DMT_STRING, get_sip_role, NULL, NULL, NULL}, +{"Extensions", &DMREAD, DMT_STRING, get_sip_extension, NULL, NULL, NULL}, +{"Transports", &DMREAD, DMT_STRING, get_sip_transport, NULL, NULL, NULL}, +{"URISchemes", &DMREAD, DMT_STRING, get_empty, NULL, NULL, NULL}, +{"EventSubscription", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"ResponseMap", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"TLSAuthenticationProtocols", &DMREAD, DMT_STRING, get_sip_tls_auth_protocols, NULL, NULL, NULL}, +{"TLSEncryptionProtocols", &DMREAD, DMT_STRING, get_sip_tls_enc_protocols, NULL, NULL, NULL}, +{"TLSKeyExchangeProtocols", &DMREAD, DMT_STRING, get_sip_tls_key_protocols, NULL, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.Capabilities.Codecs.{i}. ****/ +DMLEAF tCodecsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_cap_codec_alias, set_cap_codec_alias, NULL, NULL}, +{"EntryID", &DMREAD, DMT_UNINT, get_entry_id, NULL, NULL, NULL}, +{"Codec", &DMREAD, DMT_STRING, get_capabilities_sip_codec, NULL, NULL, NULL}, +{"BitRate", &DMREAD, DMT_UNINT, get_capabilities_sip_bitrate, NULL, NULL, NULL}, +{"PacketizationPeriod", &DMREAD, DMT_STRING, get_capabilities_sip_pperiod, NULL, NULL, NULL}, +{"SilenceSuppression", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}. ****/ +DMOBJ tProfileObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"SIP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tProfileSIPParams, NULL}, +{"ServiceProviderInfo", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tServiceProviderInfoParams, NULL}, +{"FaxT38", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tFaxT38Params, NULL}, +{"RTP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tRTPObj, tRTPParams, NULL}, +{"Line", &DMWRITE, add_line_object, delete_line_object, NULL, browseLineInst, NULL, NULL, tLineObj, tLineParams, NULL}, +{0} +}; + +DMLEAF tProfileParam[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_voice_profile_alias, set_voice_profile_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_STRING, get_voice_profile_enable, set_voice_profile_enable, NULL, NULL}, +{"Reset", &DMWRITE, DMT_BOOL, get_false_value, set_voice_profile_reset, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_voice_profile_name, NULL, NULL, NULL}, +{"SignalingProtocol", &DMWRITE, DMT_STRING, get_voice_profile_signalprotocol, set_voice_profile_signaling_protocol, NULL, NULL}, +{"MaxSessions", &DMREAD, DMT_UNINT, get_voice_profile_max_sessions, NULL, NULL, NULL}, +{"NumberOfLines", &DMREAD, DMT_UNINT, get_voice_profile_number_of_lines, NULL, NULL, NULL}, +{"DTMFMethod", &DMWRITE, DMT_STRING, get_voice_profile_sip_dtmfmethod, set_voice_profile_sip_dtmfmethod, NULL, NULL}, +{"Region", &DMWRITE, DMT_STRING, get_sip_profile_region, set_sip_profile_region, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.SIP. ***/ +DMLEAF tProfileSIPParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"ProxyServer", &DMWRITE, DMT_STRING, get_voice_profile_sip_proxyserver, set_voice_profile_sip_proxyserver, NULL, NULL}, +{"ProxyServerPort", &DMWRITE, DMT_UNINT, get_empty, set_sip_proxy_server_port, NULL, NULL}, +{"ProxyServerTransport", &DMWRITE, DMT_STRING, get_sip_proxy_server_transport, set_sip_proxy_server_transport, NULL, NULL}, +{"RegistrarServer", &DMWRITE, DMT_STRING, get_voice_profile_sip_registerserver, set_voice_profile_sip_registerserver, NULL, NULL}, +{"RegistrarServerPort", &DMWRITE, DMT_UNINT, get_voice_profile_sip_registerserverport, set_voice_profile_sip_registerserverport, NULL, NULL}, +{"RegistrarServerTransport", &DMWRITE, DMT_STRING, get_sip_registrar_server_transport, set_sip_registrar_server_transport, NULL, NULL}, +{"UserAgentDomain", &DMWRITE, DMT_STRING, get_sip_user_agent_domain, set_sip_user_agent_domain, NULL, NULL}, +{"UserAgentPort", &DMWRITE, DMT_UNINT, get_sip_user_agent_port, set_sip_user_agent_port, NULL, NULL}, +{"UserAgentTransport", &DMWRITE, DMT_STRING, get_sip_user_agent_transport, set_sip_user_agent_transport, NULL, NULL}, +{"OutboundProxy", &DMWRITE, DMT_STRING, get_sip_outbound_proxy, set_sip_outbound_proxy, NULL, NULL}, +{"OutboundProxyPort", &DMWRITE, DMT_UNINT, get_sip_outbound_proxy_port, set_sip_outbound_proxy_port, NULL, NULL}, +{"RegistrationPeriod", &DMWRITE, DMT_UNINT, get_sip_registration_period, set_sip_registration_period, NULL, NULL}, +{"ReInviteExpires", &DMWRITE, DMT_UNINT, get_sip_re_invite_expires, set_sip_re_invite_expires, NULL, NULL}, +{"RegisterExpires", &DMWRITE, DMT_UNINT, get_sip_re_invite_expires, set_sip_re_invite_expires, NULL, NULL}, +{"RegisterRetryInterval", &DMWRITE, DMT_UNINT, get_sip_re_invite_expires, set_sip_re_invite_expires, NULL, NULL}, +{"X_002207_CallLines", &DMWRITE, DMT_STRING, get_sip_x_002207_call_lines, set_sip_x_002207_call_lines, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.ServiceProviderInfo. ***/ +DMLEAF tServiceProviderInfoParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Name", &DMWRITE, DMT_STRING, get_voice_service_serviceproviderinfo_name, set_voice_service_serviceproviderinfo_name, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.FaxT38. ***/ +DMLEAF tFaxT38Params[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Enable", &DMWRITE, DMT_BOOL, get_sip_fax_t38_enable, set_sip_fax_t38_enable, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.RTP. ***/ +DMOBJ tRTPObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"RTCP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tRTCPParams, NULL}, +{"SRTP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tSRTPParam, NULL}, +{0} +}; + +DMLEAF tRTPParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"LocalPortMin", &DMWRITE, DMT_UNINT, get_voice_service_vp_rtp_portmin, set_voice_service_vp_rtp_portmin, NULL, NULL}, +{"LocalPortMax", &DMWRITE, DMT_UNINT, get_voice_service_vp_rtp_portmax, set_voice_profile_rtp_localportmax, NULL, NULL}, +{"DSCPMark", &DMWRITE, DMT_UNINT, get_voice_service_vp_rtp_dscp, set_voice_service_vp_rtp_dscp, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.RTP.RTCP. ***/ +DMLEAF tRTCPParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Enable", &DMREAD, DMT_BOOL, get_voice_service_vp_rtp_rtcp_enable, NULL, NULL, NULL}, +{"TxRepeatInterval", &DMWRITE, DMT_UNINT, get_voice_service_vp_rtp_rtcp_txrepeatinterval, set_voice_service_vp_rtp_rtcp_txrepeatinterval, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.RTP.SRTP. ***/ +DMLEAF tSRTPParam[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Enable", &DMWRITE, DMT_BOOL, get_voice_service_vp_rtp_srtp_enable, set_voice_service_vp_rtp_srtp_enable, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.Line.{i}. ***/ +DMOBJ tLineObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"VoiceProcessing", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tVoiceProcessingParams, NULL}, +{"CallingFeatures", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tCallingFeaturesParams, NULL}, +{"SIP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tLineSIPParams, NULL}, +{"Codec", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tLineCodecObj, NULL, NULL}, +{0} +}; + +DMLEAF tLineParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_line_alias, set_line_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_STRING, get_voice_profile_line_enable, set_voice_profile_line_enable, NULL, NULL}, +{"DirectoryNumber", &DMWRITE, DMT_STRING, get_line_directory_number, set_line_directory_number, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_voice_profile_line_status, set_line_alias, NULL, NULL}, +{"CallState", &DMREAD, DMT_STRING, get_voice_profile_line_callstate, set_line_alias, NULL, NULL}, +{"X_002207_LineProfile", &DMWRITE, DMT_STRING, get_line_x_002207_line_profile, set_line_x_002207_line_profile, NULL, NULL}, +{"X_002207_BRCMLine", &DMWRITE, DMT_STRING, get_line_x_002207_brcm_line, set_line_x_002207_brcm_line, NULL, NULL}, +{"X_INTENO_SE_Confort_Noise_Enable", &DMWRITE, DMT_BOOL, get_line_confort_noise_enable, set_line_confort_noise_enable, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.Line.{i}.VoiceProcessing. ***/ +DMLEAF tVoiceProcessingParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"EchoCancellationEnable", &DMWRITE, DMT_BOOL, get_line_voice_processing_cancellation_enable, set_line_voice_processing_cancellation_enable, NULL, NULL}, +{0} +}; +/*** VoiceService.{i}.VoiceProfile.{i}.Line.{i}.CallingFeatures. ***/ +DMLEAF tCallingFeaturesParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"CallerIDName", &DMWRITE, DMT_STRING, get_line_calling_features_caller_id_name, set_line_calling_features_caller_id_name, NULL, NULL}, +{"CallWaitingEnable", &DMWRITE, DMT_BOOL, get_line_calling_features_callwaiting, set_line_calling_features_callwaiting, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.Line.{i}.SIP. ***/ +DMLEAF tLineSIPParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"AuthUserName", &DMWRITE, DMT_STRING, get_line_sip_auth_username, set_line_sip_auth_username, NULL, NULL}, +{"AuthPassword", &DMWRITE, DMT_STRING, get_empty, set_line_sip_auth_password, NULL, NULL}, +{"URI", &DMWRITE, DMT_STRING, get_line_sip_uri, set_line_sip_uri, NULL, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.Line.{i}.Codec. ***/ +DMOBJ tLineCodecObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"List", &DMREAD, NULL, NULL, NULL, browseLineCodecListInst, NULL, NULL, NULL, tLineCodecListParams, NULL}, +{0} +}; + +/*** VoiceService.{i}.VoiceProfile.{i}.Line.{i}.Codec.List.{i}. ***/ +DMLEAF tLineCodecListParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_line_codec_list_alias, set_line_codec_list_alias, NULL, NULL}, +{"EntryID", &DMREAD, DMT_UNINT, get_codec_entry_id, NULL, NULL, NULL}, +{"Codec", &DMREAD, DMT_STRING, capabilities_sip_codecs_get_codec, NULL, NULL, NULL}, +{"BitRate", &DMREAD, DMT_UNINT, capabilities_sip_codecs_get_bitrate, NULL, NULL, NULL}, +{"PacketizationPeriod", &DMWRITE, DMT_STRING, get_capabilities_sip_codecs_pperiod, set_line_codec_list_packetization, NULL, NULL}, +{"SilenceSuppression", &DMREAD, DMT_BOOL, get_false_value, NULL, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_line_codec_list_enable, set_line_codec_list_enable, NULL, NULL}, +{"Priority", &DMWRITE, DMT_UNINT, get_line_codec_list_priority, set_line_codec_list_priority, NULL, NULL}, +{0} +}; + #define MAX_ALLOWED_SIP_CODECS 20 -struct service_args cur_service_args = {0}; -struct codec_args cur_codec_args = {0}; -struct sip_args cur_sip_args = {0}; -struct brcm_args cur_brcm_args = {0}; -struct line_codec_args cur_line_codec_args = {0}; int available_sip_codecs = 0; struct allow_sip_codec allowed_sip_codecs[MAX_ALLOWED_SIP_CODECS]; char *codec_option_array[5] = {"codec0", "codec1", "codec2", "codec3", "codec4"}; @@ -101,20 +345,6 @@ struct rtp_tos list_rtp_tos[] = { {"CS7", "224"} }; -inline int entry_voice_service_capabilities_codecs(struct dmctx *ctx, char *ivoice); -inline int entry_services_voice_service_voiceprofile(struct dmctx *ctx, char *ivoice); -inline int entry_services_voice_service_line(struct dmctx *ctx, char *ivoice, char *profile_num); -inline int entry_services_voice_service_line_codec_list(struct dmctx *ctx, char *ivoice, char *profile_num, char *line_num); -int entry_method_root_Service_sub(struct dmctx *ctx, char *ivoice); -inline int entry_method_Service(struct dmctx *ctx); -inline int init_allowed_sip_codecs(); -int get_voice_service_max_line(); -inline int entry_services_voice_service_line_codec_list_instance(struct dmctx *ctx, char *ivoice, char *profile_num, char *line_num, char *codec_num); -inline int entry_services_voice_service_line_codec_list_instance(struct dmctx *ctx, char *ivoice, char *profile_num, char *line_num, char *codec_num); -inline int entry_services_voice_service_line_instance(struct dmctx *ctx, char *ivoice, char *profile_num, char *line_num); -inline int entry_services_voice_service_voiceprofile_instance (struct dmctx *ctx, char *ivoice, char *profile_num); -inline int entry_voice_service_capabilities_codecs_instance(struct dmctx *ctx, char *ivoice, char *id); - ///////////////////////////////INIT ARGS////////////////// void wait_voice_service_up(void) { @@ -127,11 +357,11 @@ void wait_voice_service_up(void) } } -inline int init_allowed_sip_codecs() +static inline int init_allowed_sip_codecs() { json_object *res = NULL; char id[8], priority[24], ptime[24]; - unsigned int i; + int i; available_sip_codecs = 0; dmubus_call("asterisk", "codecs", UBUS_ARGS{}, 0, &res); if(res) { @@ -155,27 +385,15 @@ inline int init_allowed_sip_codecs() return 0; } -inline int init_service_args(struct dmctx *ctx, struct uci_section *section) +int init_sip_args(struct sip_args *args, struct uci_section *section, char *profile_num) { - struct service_args *args = &cur_service_args; - ctx->args = (void *)args; - args->service_section = section; - return 0; -} - -inline int init_sip_args(struct dmctx *ctx, struct uci_section *section, char *profile_num) -{ - struct sip_args *args = &cur_sip_args; - ctx->args = (void *)args; args->sip_section = section; args->profile_num = profile_num; return 0; } -inline int init_codec_args(struct dmctx *ctx, char *cdc, char *id, int enumid, struct uci_section *s) +int init_codec_args(struct codec_args *args, char *cdc, char *id, int enumid, struct uci_section *s) { - struct codec_args *args = &cur_codec_args; - ctx->args = (void *)args; args->cdc = dmstrdup(cdc); args->id = dmstrdup(id); args->enumid = enumid; @@ -183,10 +401,15 @@ inline int init_codec_args(struct dmctx *ctx, char *cdc, char *id, int enumid, return 0; } -inline int init_line_code_args(struct dmctx *ctx, int i, struct uci_section *s, struct uci_section *codec_sec) +int fini_codec_args(struct codec_args *args) +{ + dmfree(args->cdc); + dmfree(args->id); + return 0; +} + +int init_line_code_args(struct line_codec_args *args, int i, struct uci_section *s, struct uci_section *codec_sec) { - struct line_codec_args *args = &cur_line_codec_args; - ctx->args = (void *)args; args->cdc = allowed_sip_codecs[i].allowed_cdc; args->id = allowed_sip_codecs[i].id; args->sip_section = s; @@ -197,10 +420,8 @@ inline int init_line_code_args(struct dmctx *ctx, int i, struct uci_section *s, return 0; } -inline int init_brcm_args(struct dmctx *ctx, struct uci_section *section, struct uci_section *section2, char *instance) +int init_brcm_args(struct brcm_args *args, struct uci_section *section, struct uci_section *section2, char *instance) { - struct brcm_args *args = &cur_brcm_args; - ctx->args = (void *)args; args->brcm_section = section; args->sip_section = section2; args->profile_num = instance; @@ -223,7 +444,7 @@ int get_cfg_sipidx(void) return (max + 1); } -int add_profile_object(struct dmctx *ctx, char **instancepara) +int add_profile_object(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char sname[8]; char account[16]; @@ -268,33 +489,33 @@ int delete_associated_line_instances(char *sip_id) return 0; } -int delete_profile_object(struct dmctx *ctx) -{ - struct sip_args *sipargs = (struct sip_args *)(ctx->args); - - delete_associated_line_instances(section_name(sipargs->sip_section)); - dmuci_delete_by_section(sipargs->sip_section, NULL, NULL); - - return 0; -} - -int delete_profile_object_all(struct dmctx *ctx) +int delete_profile_object(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; struct uci_section *s, *ss = NULL; + struct sip_args *sipargs = (struct sip_args *)data; - uci_foreach_sections("voice_client", "sip_service_provider", s) { - if (found != 0) { - delete_associated_line_instances(section_name(ss)); - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; + switch (del_action) { + case DEL_INST: + delete_associated_line_instances(section_name(sipargs->sip_section)); + dmuci_delete_by_section(sipargs->sip_section, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("voice_client", "sip_service_provider", s) { + if (found != 0) { + delete_associated_line_instances(section_name(ss)); + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + delete_associated_line_instances(section_name(ss)); + dmuci_delete_by_section(ss, NULL, NULL); + } + break; } - if (ss != NULL) { - delete_associated_line_instances(section_name(ss)); - dmuci_delete_by_section(ss, NULL, NULL); - } + return 0; } @@ -390,14 +611,14 @@ int add_line(struct uci_section *s, char *s_name) return 0; } -int add_line_object(struct dmctx *ctx, char **instancepara) +int add_line_object(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { int i; char *value; char instance[4]; char call_lines[16] = {0}; struct uci_section *s = NULL; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; int last_instance; i = get_line_max_instance(&s); if (i == 0) @@ -447,71 +668,74 @@ int delete_line(struct uci_section *line_section, struct uci_section *sip_sectio return 0; } -int delete_line_object_all(struct dmctx *ctx) +int delete_line_object(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; char *s_name; struct uci_section *s; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); - s_name = section_name(sipargs->sip_section); + struct sip_args *sipargs; + struct brcm_args *bargs; //profile_num must be added to brcm_args - uci_foreach_option_eq("voice_client", "brcm_line", "sip_account", s_name, s) { - delete_line(s, sipargs->sip_section); + switch (del_action) { + case DEL_INST: + bargs = (struct brcm_args *)data; + delete_line(bargs->brcm_section, bargs->sip_section); + break; + case DEL_ALL: + sipargs = (struct sip_args *)data; + s_name = section_name(sipargs->sip_section); + uci_foreach_option_eq("voice_client", "brcm_line", "sip_account", s_name, s) { + delete_line(s, sipargs->sip_section); + } + break; } - return 0; -} -int delete_line_object(struct dmctx *ctx) -{ - struct brcm_args *bargs = (struct brcm_args *)(ctx->args); //profile_num must be added to brcm_args - - delete_line(bargs->brcm_section, bargs->sip_section); return 0; } /**************************Function for root entry *************************/ -int get_max_profile_count(char *refparam, struct dmctx *ctx, char **value) +int get_max_profile_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "8"; return 0; } -int get_max_line_count(char *refparam, struct dmctx *ctx, char **value) +int get_max_line_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "6"; return 0; } -int get_max_session_per_line(char *refparam, struct dmctx *ctx, char **value) +int get_max_session_per_line(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int get_max_session_count(char *refparam, struct dmctx *ctx, char **value) +int get_max_session_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "6"; return 0; } -int get_signal_protocols(char *refparam, struct dmctx *ctx, char **value) +int get_signal_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "SIP"; return 0; } -int get_regions(char *refparam, struct dmctx *ctx, char **value) +int get_regions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "AU, BE, BR, CL, CN, CZ, DK, FI, FR, DE, HU, IN, IT, JP, NL, NZ, US, ES, SE, CH, NO, TW, GB, AE, ET, T5"; return 0; } -int get_true_value(char *refparam, struct dmctx *ctx, char **value) +int get_true_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int get_false_value(char *refparam, struct dmctx *ctx, char **value) +int get_false_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0"; return 0; @@ -519,53 +743,53 @@ int get_false_value(char *refparam, struct dmctx *ctx, char **value) /*******************end root ***************************/ /**************SIP CAPABILITIES ************************/ -int get_sip_role (char *refparam, struct dmctx *ctx, char **value) +int get_sip_role (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "BackToBackUserAgents"; return 0; } -int get_sip_extension(char *refparam, struct dmctx *ctx, char **value) +int get_sip_extension(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH"; return 0; } -int get_sip_transport(char *refparam, struct dmctx *ctx, char **value) +int get_sip_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "UDP, TCP, TLS"; return 0; } -int get_sip_tls_auth_protocols(char *refparam, struct dmctx *ctx, char **value) +int get_sip_tls_auth_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "MD5"; return 0; } -int get_sip_tls_enc_protocols(char *refparam, struct dmctx *ctx, char **value) +int get_sip_tls_enc_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "RC4, RC2, DES, 3DES"; return 0; } -int get_sip_tls_key_protocols(char *refparam, struct dmctx *ctx, char **value) +int get_sip_tls_key_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "RSA, DSS"; return 0; } /*******************Capabilities.Codecs.***********************************/ -int get_entry_id(char *refparam, struct dmctx *ctx, char **value) +int get_entry_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct codec_args *codecs = (struct codec_args *)(ctx->args); - *value = codecs->id; + struct codec_args *codecs = (struct codec_args *)data; + *value = dmstrdup(codecs->id); return 0; } -int get_capabilities_sip_codec(char *refparam, struct dmctx *ctx, char **value) +int get_capabilities_sip_codec(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; - struct codec_args *cdcargs = (struct codec_args *)(ctx->args); + int i; + struct codec_args *cdcargs = (struct codec_args *)data; bool sep = false; for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) { if(capabilities_sip_codecs[i].enumid == cdcargs->enumid) { @@ -576,10 +800,10 @@ int get_capabilities_sip_codec(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_capabilities_sip_bitrate(char *refparam, struct dmctx *ctx, char **value) +int get_capabilities_sip_bitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; - struct codec_args *cdcargs = (struct codec_args *)(ctx->args); + int i; + struct codec_args *cdcargs = (struct codec_args *)data; for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) { if(capabilities_sip_codecs[i].enumid == cdcargs->enumid) { *value = capabilities_sip_codecs[i].c3; @@ -589,10 +813,10 @@ int get_capabilities_sip_bitrate(char *refparam, struct dmctx *ctx, char **value return 0; } -int get_capabilities_sip_pperiod(char *refparam, struct dmctx *ctx, char **value) +int get_capabilities_sip_pperiod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; - struct codec_args *cdcargs = (struct codec_args *)(ctx->args); + int i; + struct codec_args *cdcargs = (struct codec_args *)data; for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) { if(capabilities_sip_codecs[i].enumid == cdcargs->enumid) { *value = capabilities_sip_codecs[i].c4; @@ -623,10 +847,10 @@ int get_voice_service_max_line() return num; } -int get_voice_profile_enable(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; - struct sip_args *sipargs = &cur_sip_args; // This function is used for line enable and sip profile enable + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "enabled", &tmp); @@ -637,9 +861,9 @@ int get_voice_profile_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_voice_profile_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = &cur_sip_args; // This function is used for line enable and sip profile enable + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: return 0; @@ -653,7 +877,7 @@ int set_voice_profile_enable(char *refparam, struct dmctx *ctx, int action, char return 0; } -int set_voice_profile_reset(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -665,7 +889,7 @@ int set_voice_profile_reset(char *refparam, struct dmctx *ctx, int action, char case VALUESET: string_to_bool(value, &b); if(b) { - dmubus_call_set("uci", "commit", UBUS_ARGS{{"config", "voice_client", String}}, 1); + dmubus_call_set("uci", "commit", UBUS_ARGS{{"config", "voice_client"}}, 1); return 0; } return 0; @@ -673,20 +897,20 @@ int set_voice_profile_reset(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_voice_profile_name(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "name", value); return 0; } -int get_voice_profile_signalprotocol(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_signalprotocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "SIP"; return 0; } -int set_voice_profile_signaling_protocol(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_signaling_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -696,7 +920,7 @@ int set_voice_profile_signaling_protocol(char *refparam, struct dmctx *ctx, int } return 0; } -int get_voice_profile_max_sessions(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_max_sessions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *sub_channel = NULL, *num_lines = NULL; @@ -708,12 +932,12 @@ int get_voice_profile_max_sessions(char *refparam, struct dmctx *ctx, char **val return 0; } -int get_voice_profile_number_of_lines(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_number_of_lines(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int num = 0; json_object *res, *jobj; struct uci_section *b_section = NULL; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; *value = "0"; dmubus_call("asterisk", "status", UBUS_ARGS{}, 0, &res); @@ -728,16 +952,14 @@ int get_voice_profile_number_of_lines(char *refparam, struct dmctx *ctx, char ** return 0; } -int get_voice_profile_sip_proxyserver(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_sip_proxyserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("voice_client", "SIP", "sip_proxy", value); return 0; } -int set_voice_profile_sip_proxyserver(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_sip_proxyserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); - switch (action) { case VALUECHECK: return 0; @@ -748,7 +970,7 @@ int set_voice_profile_sip_proxyserver(char *refparam, struct dmctx *ctx, int act return 0; } -int set_sip_proxy_server_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_proxy_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -760,17 +982,17 @@ int set_sip_proxy_server_port(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_sip_proxy_server_transport(char *refparam, struct dmctx *ctx, char **value) +int get_sip_proxy_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "transport", value); return 0; } -int set_sip_proxy_server_transport(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_proxy_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -782,17 +1004,17 @@ int set_sip_proxy_server_transport(char *refparam, struct dmctx *ctx, int action return 0; } -int get_voice_profile_sip_registerserver(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_sip_registerserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "host", value); return 0; } -int set_voice_profile_sip_registerserver(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_sip_registerserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -804,17 +1026,17 @@ int set_voice_profile_sip_registerserver(char *refparam, struct dmctx *ctx, int return 0; } -int get_voice_profile_sip_registerserverport(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_sip_registerserverport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "port", value); return 0; } -int set_voice_profile_sip_registerserverport(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_sip_registerserverport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -826,17 +1048,17 @@ int set_voice_profile_sip_registerserverport(char *refparam, struct dmctx *ctx, return 0; } -int get_sip_registrar_server_transport(char *refparam, struct dmctx *ctx, char **value) +int get_sip_registrar_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "transport", value); return 0; } -int set_sip_registrar_server_transport(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_registrar_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -848,17 +1070,17 @@ int set_sip_registrar_server_transport(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_sip_user_agent_domain(char *refparam, struct dmctx *ctx, char **value) +int get_sip_user_agent_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "domain", value); return 0; } -int set_sip_user_agent_domain(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_user_agent_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -870,13 +1092,13 @@ int set_sip_user_agent_domain(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_sip_user_agent_port(char *refparam, struct dmctx *ctx, char **value) +int get_sip_user_agent_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("voice_client", "SIP", "bindport", value); return 0; } -int set_sip_user_agent_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_user_agent_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -888,11 +1110,11 @@ int set_sip_user_agent_port(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_sip_user_agent_transport(char *refparam, struct dmctx *ctx, char **value) +int get_sip_user_agent_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { //dmubus_call("asterisk.sip", "dump", UBUS_ARGS{}, 0, &res); char *tmp; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "transport", &tmp); if (tmp[0] == '\0') @@ -902,7 +1124,7 @@ int get_sip_user_agent_transport(char *refparam, struct dmctx *ctx, char **value return 0; } -int set_sip_user_agent_transport(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_user_agent_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -914,17 +1136,17 @@ int set_sip_user_agent_transport(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_sip_outbound_proxy(char *refparam, struct dmctx *ctx, char **value) +int get_sip_outbound_proxy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "outboundproxy", value); return 0; } -int set_sip_outbound_proxy(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_outbound_proxy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -936,17 +1158,17 @@ int set_sip_outbound_proxy(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_sip_outbound_proxy_port(char *refparam, struct dmctx *ctx, char **value) +int get_sip_outbound_proxy_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "outboundproxyport", value); return 0; } -int set_sip_outbound_proxy_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_outbound_proxy_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: return 0; @@ -958,13 +1180,13 @@ int set_sip_outbound_proxy_port(char *refparam, struct dmctx *ctx, int action, c } -int get_sip_registration_period(char *refparam, struct dmctx *ctx, char **value) +int get_sip_registration_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("voice_client", "SIP", "defaultexpiry", value); return 0; } -int set_sip_registration_period(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_registration_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -977,13 +1199,13 @@ int set_sip_registration_period(char *refparam, struct dmctx *ctx, int action, c } -int get_sip_re_invite_expires(char *refparam, struct dmctx *ctx, char **value) +int get_sip_re_invite_expires(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("voice_client", "SIP", "registertimeout", value); return 0; } -int set_sip_re_invite_expires(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_re_invite_expires(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; switch (action) { @@ -997,17 +1219,17 @@ int set_sip_re_invite_expires(char *refparam, struct dmctx *ctx, int action, cha } -int get_sip_x_002207_call_lines(char *refparam, struct dmctx *ctx, char **value) +int get_sip_x_002207_call_lines(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "call_lines", value); return 0; } -int set_sip_x_002207_call_lines(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_x_002207_call_lines(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -1018,7 +1240,7 @@ int set_sip_x_002207_call_lines(char *refparam, struct dmctx *ctx, int action, c } } -int get_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; @@ -1034,10 +1256,8 @@ int get_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, char ** return 0; } -int set_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); - switch (action) { case VALUECHECK: return 0; @@ -1053,9 +1273,9 @@ int set_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_sip_profile_region(char *refparam, struct dmctx *ctx, char **value) +int get_sip_profile_region(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; + int i; dmuci_get_option_value_string("voice_client", "BRCM", "country", value); for (i = 0; i < ARRAY_SIZE(capabilities_regions); i++) { @@ -1067,10 +1287,9 @@ int get_sip_profile_region(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_sip_profile_region(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_profile_region(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - unsigned int i; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + int i; switch (action) { case VALUECHECK: @@ -1087,9 +1306,9 @@ int set_sip_profile_region(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx, char **value) +int get_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "provider_name", value); if(value[0] == '\0') @@ -1097,9 +1316,9 @@ int get_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx return 0; } -int set_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -1111,17 +1330,17 @@ int set_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx return 0; } -int get_sip_fax_t38_enable(char *refparam, struct dmctx *ctx, char **value) +int get_sip_fax_t38_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "is_fax", value); return 0; } -int set_sip_fax_t38_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_sip_fax_t38_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -1141,7 +1360,7 @@ int set_sip_fax_t38_enable(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, char **value) +int get_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; @@ -1153,10 +1372,9 @@ int get_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, char ** return 0; } -int set_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); switch (action) { case VALUECHECK: @@ -1168,7 +1386,7 @@ int set_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_voice_service_vp_rtp_portmax(char *refparam, struct dmctx *ctx, char **value) +int get_voice_service_vp_rtp_portmax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; @@ -1180,9 +1398,8 @@ int get_voice_service_vp_rtp_portmax(char *refparam, struct dmctx *ctx, char ** return 0; } -int set_voice_profile_rtp_localportmax(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_rtp_localportmax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); switch (action) { case VALUECHECK: @@ -1194,9 +1411,9 @@ int set_voice_profile_rtp_localportmax(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, char **value) +int get_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; + int i; char *tmp; *value = "0"; @@ -1210,10 +1427,9 @@ int get_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, char **val return 0; } -int set_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - unsigned int i; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + int i; switch (action) { case VALUECHECK: @@ -1230,7 +1446,7 @@ int set_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_voice_service_vp_rtp_rtcp_enable(char *refparam, struct dmctx *ctx, char **value) +int get_voice_service_vp_rtp_rtcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { pid_t pid; @@ -1242,7 +1458,7 @@ int get_voice_service_vp_rtp_rtcp_enable(char *refparam, struct dmctx *ctx, cha return 0; } -int get_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx *ctx, char **value) +int get_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; @@ -1254,10 +1470,8 @@ int get_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx return 0; } -int set_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sip_args *sipargs = (struct sip_args *)(ctx->args); - switch (action) { case VALUECHECK: return 0; @@ -1268,10 +1482,10 @@ int set_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx return 0; } -int get_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, char **value) +int get_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; dmuci_get_value_by_section_string(sipargs->sip_section, "encryption", &tmp); if(strcasecmp(tmp, "yes") == 0) @@ -1281,10 +1495,10 @@ int get_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, cha return 0; } -int set_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: @@ -1303,17 +1517,47 @@ int set_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, int } /*******************LINE **********************************/ -int get_line_directory_number(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_line_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + char *tmp; + struct brcm_args *brcmargs = (struct brcm_args *)data; + + dmuci_get_value_by_section_string(brcmargs->sip_section, "enabled", &tmp); + + if(strcmp(tmp, "0") == 0) + *value = "Disabled"; + else + *value = "Enabled"; + return 0; +} + +int set_voice_profile_line_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct brcm_args *brcmargs = (struct brcm_args *)data; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if(strcmp(value, "Enabled") == 0) + dmuci_set_value_by_section(brcmargs->sip_section, "enabled", "1"); + else + dmuci_set_value_by_section(brcmargs->sip_section, "enabled", "0"); + return 0; + } + return 0; +} + +int get_line_directory_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct brcm_args *brcmargs = (struct brcm_args *)data; dmuci_get_value_by_section_string(brcmargs->brcm_section, "extension", value); return 0; } -int set_line_directory_number(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_directory_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1325,12 +1569,12 @@ int set_line_directory_number(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_voice_profile_line_status(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_line_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status, *sip_name, *q; json_object *res; char buf[64]; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; *value = "Disabled"; sip_name = section_name(brcmargs->sip_section); q = buf; @@ -1358,10 +1602,10 @@ int get_voice_profile_line_status(char *refparam, struct dmctx *ctx, char **val return 0; } -int get_voice_profile_line_callstate(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_line_callstate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp, *line_name; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; line_name = section_name(brcmargs->brcm_section); dmuci_get_varstate_string("chan_brcm", line_name, "subchannel_0", &tmp); @@ -1380,20 +1624,20 @@ int get_voice_profile_line_callstate(char *refparam, struct dmctx *ctx, char **v return 0; } -int get_line_x_002207_line_profile(char *refparam, struct dmctx *ctx, char **value) +int get_line_x_002207_line_profile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; *value = brcmargs->profile_num; return 0; } -int set_line_x_002207_line_profile(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_x_002207_line_profile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char call_lines[32]; char *str; struct uci_section *sip_s; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1424,22 +1668,22 @@ int set_line_x_002207_line_profile(char *refparam, struct dmctx *ctx, int action return 0; } -int get_line_x_002207_brcm_line(char *refparam, struct dmctx *ctx, char **value) +int get_line_x_002207_brcm_line(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *line_name; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; line_name = section_name(brcmargs->brcm_section); *value = dmstrdup(line_name + sizeof("brcm") - 1); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } -int set_line_x_002207_brcm_line(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_x_002207_brcm_line(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int error; char bname[8], *stype = NULL, *sipaccount = NULL; char *lineinstance = NULL; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1466,18 +1710,18 @@ int set_line_x_002207_brcm_line(char *refparam, struct dmctx *ctx, int action, c return 0; } -int get_line_confort_noise_enable(char *refparam, struct dmctx *ctx, char **value) +int get_line_confort_noise_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; dmuci_get_value_by_section_string(brcmargs->brcm_section, "noise", value); return 0; } -int set_line_confort_noise_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_confort_noise_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1495,19 +1739,19 @@ int set_line_confort_noise_enable(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_line_voice_processing_cancellation_enable(char *refparam, struct dmctx *ctx, char **value) +int get_line_voice_processing_cancellation_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; dmuci_get_value_by_section_string(brcmargs->brcm_section, "echo_cancel", value); return 0; } -int set_line_voice_processing_cancellation_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_voice_processing_cancellation_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1525,17 +1769,18 @@ int set_line_voice_processing_cancellation_enable(char *refparam, struct dmctx * return 0; } -int get_line_calling_features_caller_id_name(char *refparam, struct dmctx *ctx, char **value) + +int get_line_calling_features_caller_id_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; dmuci_get_value_by_section_string(brcmargs->sip_section, "displayname", value); return 0; } -int set_line_calling_features_caller_id_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_calling_features_caller_id_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1547,9 +1792,9 @@ int set_line_calling_features_caller_id_name(char *refparam, struct dmctx *ctx, return 0; } -int get_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, char **value) +int get_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; dmuci_get_value_by_section_string(brcmargs->brcm_section, "callwaiting", value); if((*value)[0] == '\0') @@ -1557,10 +1802,10 @@ int get_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, ch return 0; } -int set_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1578,17 +1823,17 @@ int set_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, int return 0; } -int get_line_sip_auth_username(char *refparam, struct dmctx *ctx, char **value) +int get_line_sip_auth_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; dmuci_get_value_by_section_string(brcmargs->sip_section, "authuser", value); return 0; } -int set_line_sip_auth_username(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_sip_auth_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1600,9 +1845,9 @@ int set_line_sip_auth_username(char *refparam, struct dmctx *ctx, int action, ch return 0; } -int set_line_sip_auth_password(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_sip_auth_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1614,10 +1859,10 @@ int set_line_sip_auth_password(char *refparam, struct dmctx *ctx, int action, ch return 0; } -int get_line_sip_uri(char *refparam, struct dmctx *ctx, char **value) +int get_line_sip_uri(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *domain = NULL, *user = NULL; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; dmuci_get_value_by_section_string(brcmargs->sip_section, "domain", &domain); dmuci_get_value_by_section_string(brcmargs->sip_section, "user", &user); @@ -1628,10 +1873,10 @@ int get_line_sip_uri(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_line_sip_uri(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_sip_uri(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch, *spch, *str1; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)data; switch (action) { case VALUECHECK: @@ -1661,9 +1906,7 @@ int codec_compare(const void *s1, const void *s2) void codec_priority_sort(struct uci_section *sip_section, char *new_codec) { - unsigned int j; - - int k = 0, h = 0, size = ARRAY_SIZE(codec_option_array); + int j, k = 0, h = 0, size = ARRAY_SIZE(codec_option_array); char *ucodec, *coption, *poption; bool found; struct codec sipcodec[ARRAY_SIZE(codec_option_array)+1] = {0}; @@ -1712,8 +1955,7 @@ void codec_priority_sort(struct uci_section *sip_section, char *new_codec) void codec_priority_update(struct uci_section *sip_section) { bool found; - int i; - unsigned int j; + int i, j; char *priority = NULL; char *codec; char pid[4] = "1"; @@ -1737,18 +1979,18 @@ void codec_priority_update(struct uci_section *sip_section) codec_priority_sort(sip_section, NULL); } -int get_codec_entry_id(char *refparam, struct dmctx *ctx, char **value) +int get_codec_entry_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; *value = line_codecargs->id; return 0; } -int capabilities_sip_codecs_get_codec(char *refparam, struct dmctx *ctx, char **value) +int capabilities_sip_codecs_get_codec(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + int i; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) { if(capabilities_sip_codecs[i].enumid == line_codecargs->enumid) { @@ -1759,10 +2001,10 @@ int capabilities_sip_codecs_get_codec(char *refparam, struct dmctx *ctx, char ** return 0; } -int capabilities_sip_codecs_get_bitrate(char *refparam, struct dmctx *ctx, char **value) +int capabilities_sip_codecs_get_bitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + int i; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; for (i = 0; i < ARRAY_SIZE(capabilities_sip_codecs); i++) { if(capabilities_sip_codecs[i].enumid == line_codecargs->enumid) { @@ -1773,10 +2015,10 @@ int capabilities_sip_codecs_get_bitrate(char *refparam, struct dmctx *ctx, char return 0; } -int get_capabilities_sip_codecs_pperiod(char *refparam, struct dmctx *ctx, char **value) +int get_capabilities_sip_codecs_pperiod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + int i; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; dmuci_get_value_by_section_string(line_codecargs->sip_section, line_codecargs->ptime_cdc, value); if ((*value)[0] != '\0') return 0; @@ -1789,11 +2031,11 @@ int get_capabilities_sip_codecs_pperiod(char *refparam, struct dmctx *ctx, char return 0; } -int get_line_codec_list_enable(char *refparam, struct dmctx *ctx, char **value) +int get_line_codec_list_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - unsigned int i; + int i; char *val; - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; for (i =0; i < ARRAY_SIZE(codec_option_array); i++) { dmuci_get_value_by_section_string(line_codecargs->sip_section, codec_option_array[i], &val); @@ -1806,16 +2048,16 @@ int get_line_codec_list_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_line_codec_list_priority(char *refparam, struct dmctx *ctx, char **value) +int get_line_codec_list_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; dmuci_get_value_by_section_string(line_codecargs->sip_section, line_codecargs->priority_cdc, value); return 0; } -int set_line_codec_list_packetization(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_codec_list_packetization(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; switch (action) { case VALUECHECK: @@ -1827,12 +2069,12 @@ int set_line_codec_list_packetization(char *refparam, struct dmctx *ctx, int act return 0; } -int set_line_codec_list_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_codec_list_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - unsigned int j; + int j; char *codec; - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; int error = string_to_bool(value, &b); switch (action) { @@ -1863,11 +2105,11 @@ int set_line_codec_list_enable(char *refparam, struct dmctx *ctx, int action, ch return 0; } -int set_line_codec_list_priority(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_codec_list_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - unsigned int i; + int i; char *val; - struct line_codec_args *line_codecargs = (struct line_codec_args *)ctx->args; + struct line_codec_args *line_codecargs = (struct line_codec_args *)data; switch (action) { case VALUECHECK: @@ -1919,349 +2161,195 @@ void codec_update_id() } } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_service_alias(char *refparam, struct dmctx *ctx, char **value) +int get_service_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_service_args.service_section, "vsalias", value); + struct uci_section *service_section = (struct uci_section *)data; + dmuci_get_value_by_section_string(service_section, "vsalias", value); return 0; } -int set_service_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_service_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *service_section = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_service_args.service_section, "vsalias", value); + dmuci_set_value_by_section(service_section, "vsalias", value); return 0; } return 0; } -int get_cap_codec_alias(char *refparam, struct dmctx *ctx, char **value) +int get_cap_codec_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_codec_args.codec_section, "codecalias", value); + struct codec_args *cur_codec_args = (struct codec_args *)data; + dmuci_get_value_by_section_string(cur_codec_args->codec_section, "codecalias", value); return 0; } -int set_cap_codec_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_cap_codec_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct codec_args *cur_codec_args = (struct codec_args *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_codec_args.codec_section, "codecalias", value); + dmuci_set_value_by_section(cur_codec_args->codec_section, "codecalias", value); return 0; } return 0; } -int get_voice_profile_alias(char *refparam, struct dmctx *ctx, char **value) +int get_voice_profile_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_sip_args.sip_section, "profilealias", value); + struct sip_args *sipargs = (struct sip_args *)data; + dmuci_get_value_by_section_string(sipargs->sip_section, "profilealias", value); return 0; } -int set_voice_profile_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_voice_profile_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct sip_args *sipargs = (struct sip_args *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_sip_args.sip_section, "profilealias", value); + dmuci_set_value_by_section(sipargs->sip_section, "profilealias", value); return 0; } return 0; } -int get_line_alias(char *refparam, struct dmctx *ctx, char **value) +int get_line_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_brcm_args.brcm_section, "linealias", value); + struct brcm_args *brcmarg = (struct brcm_args *)data; + dmuci_get_value_by_section_string(brcmarg->brcm_section, "linealias", value); return 0; } -int set_line_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct brcm_args *brcmarg = (struct brcm_args *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_brcm_args.brcm_section, "linealias", value); + dmuci_set_value_by_section(brcmarg->brcm_section, "linealias", value); return 0; } return 0; } -int get_line_codec_list_alias(char *refparam, struct dmctx *ctx, char **value) +int get_line_codec_list_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_line_codec_args.codec_sec, "codecalias", value); + dmuci_get_value_by_section_string(((struct line_codec_args *)data)->codec_sec, "codecalias", value); return 0; } -int set_line_codec_list_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_line_codec_list_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_line_codec_args.codec_sec, "codecalias", value); + dmuci_set_value_by_section(((struct line_codec_args *)data)->codec_sec, "codecalias", value); return 0; } return 0; } /////////////////////////////////////// -/////////////SUB ENTRIES/////////////// -int entry_method_root_Service(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Services.") { - DMOBJECT(DMROOT"Services.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"Services.VoiceService.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_method_Service, ctx); - return 0; - } - return FAULT_9005; -} -inline int entry_method_Service(struct dmctx *ctx) +int browseVoiceServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *vs = NULL, *vs_last = NULL; update_section_list(DMMAP,"voice_service", NULL, 1, NULL, NULL, NULL, NULL, NULL); uci_path_foreach_sections(icwmpd, "dmmap", "voice_service", s) { - init_service_args(ctx, s); - vs = handle_update_instance(1, ctx, &vs_last, update_instance_alias_icwmpd, 3, s, "vsinstance", "vsalias"); - SUBENTRY(entry_method_root_Service_sub, ctx, vs); + vs = handle_update_instance(1, dmctx, &vs_last, update_instance_alias_icwmpd, 3, s, "vsinstance", "vsalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, vs) == DM_STOP) + break; } return 0; } -inline int entry_voice_service_capabilities_codecs(struct dmctx *ctx, char *ivoice) +int browseCodecsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int i = 0; char *id, *id_last = NULL; struct uci_section *code_sec; + struct codec_args curr_codec_args = {0}; init_allowed_sip_codecs(); codec_update_id(); uci_path_foreach_sections(icwmpd, "dmmap", "codec_id", code_sec) { - init_codec_args(ctx, allowed_sip_codecs[i].allowed_cdc, allowed_sip_codecs[i].id, allowed_sip_codecs[i].enumid, code_sec); - id = handle_update_instance(2, ctx, &id_last, update_instance_alias_icwmpd, 3, code_sec, "codecinstance", "codecalias"); - SUBENTRY(entry_voice_service_capabilities_codecs_instance, ctx, ivoice, id); + init_codec_args(&curr_codec_args, allowed_sip_codecs[i].allowed_cdc, allowed_sip_codecs[i].id, allowed_sip_codecs[i].enumid, code_sec); + id = handle_update_instance(2, dmctx, &id_last, update_instance_alias_icwmpd, 3, code_sec, "codecinstance", "codecalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_codec_args, id) == DM_STOP) { + fini_codec_args(&curr_codec_args); + break; + } + fini_codec_args(&curr_codec_args); + i++; } return 0; } -inline int entry_services_voice_service_voiceprofile(struct dmctx *ctx, char *ivoice) +int browseProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *sip_section; char *profile_num = NULL, *profile_num_last = NULL; + struct sip_args curr_sip_args = {0}; wait_voice_service_up(); uci_foreach_sections("voice_client", "sip_service_provider", sip_section) { - profile_num = handle_update_instance(2, ctx, &profile_num_last, update_instance_alias, 3, sip_section, "profileinstance", "profilealias"); - init_sip_args(ctx, sip_section, profile_num_last); - SUBENTRY(entry_services_voice_service_voiceprofile_instance, ctx, ivoice, profile_num); + profile_num = handle_update_instance(2, dmctx, &profile_num_last, update_instance_alias, 3, sip_section, "profileinstance", "profilealias"); + init_sip_args(&curr_sip_args, sip_section, profile_num_last); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_sip_args, profile_num) == DM_STOP) + break; } return 0; } -inline int entry_services_voice_service_line(struct dmctx *ctx, char *ivoice, char *profile_num) +int browseLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int maxLine, line_id = 0; char *line_num = NULL, *last_inst = NULL; struct uci_section *b_section = NULL; json_object *res, *jobj; - struct sip_args *sipargs = (struct sip_args *)(ctx->args); + struct sip_args *sipargs = (struct sip_args *)prev_data; + struct brcm_args curr_brcm_args = {0}; maxLine = get_voice_service_max_line(); uci_foreach_option_eq("voice_client", "brcm_line", "sip_account", section_name(sipargs->sip_section), b_section) { line_id = atoi(section_name(b_section) + sizeof("brcm") - 1); if ( line_id >= maxLine ) continue; - line_num = handle_update_instance(3, ctx, &last_inst, update_vp_line_instance_alias, 2, b_section, section_name(sipargs->sip_section)); - init_brcm_args(ctx, b_section, sipargs->sip_section, profile_num); - SUBENTRY(entry_services_voice_service_line_instance, ctx, ivoice, profile_num, line_num); + line_num = handle_update_instance(3, dmctx, &last_inst, update_vp_line_instance_alias, 2, b_section, section_name(sipargs->sip_section)); + init_brcm_args(&curr_brcm_args, b_section, sipargs->sip_section, sipargs->profile_num); //check difference between sipargs->profile_num and profile_num + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_brcm_args, line_num) == DM_STOP) + break; } return 0; } -inline int entry_services_voice_service_line_codec_list(struct dmctx *ctx, char *ivoice, char *profile_num, char *line_num) +int browseLineCodecListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int i = 0; char *id = NULL , *id_last = NULL; - struct brcm_args *brcmargs = (struct brcm_args *)(ctx->args); + struct brcm_args *brcmargs = (struct brcm_args *)prev_data; struct uci_section *code_sec = NULL; + struct line_codec_args curr_line_codec_args = {0}; codec_update_id(); codec_priority_update(brcmargs->sip_section); uci_path_foreach_sections(icwmpd, "dmmap", "codec_id", code_sec) { - init_line_code_args(ctx, i, brcmargs->sip_section, code_sec); - id = handle_update_instance(4, ctx, &id_last, update_instance_alias_icwmpd, 3, code_sec, "codecinstance", "codecalias"); - SUBENTRY(entry_services_voice_service_line_codec_list_instance, ctx, ivoice, profile_num, line_num, id); + init_line_code_args(&curr_line_codec_args, i, brcmargs->sip_section, code_sec); + id = handle_update_instance(4, dmctx, &id_last, update_instance_alias_icwmpd, 3, code_sec, "codecinstance", "codecalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_line_codec_args, id) == DM_STOP) + break; i++; } return 0; } -////////////////////////////////////// -int entry_method_root_Service_sub(struct dmctx *ctx, char *ivoice) -{ - IF_MATCH(ctx, DMROOT"Services.VoiceService.%s.", ivoice) { - DMOBJECT(DMROOT"Services.VoiceService.%s.", ctx, "0", 1, NULL, NULL, NULL, ivoice); - DMPARAM("Alias", ctx, "1", get_service_alias, set_service_alias, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.Capabilities.", ctx, "0", 1, NULL, NULL, NULL, ivoice); - DMPARAM("MaxProfileCount", ctx, "0", get_max_profile_count, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaxLineCount", ctx, "0", get_max_line_count, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaxSessionsPerLine", ctx, "0", get_true_value, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaxSessionCount", ctx, "0", get_max_session_count, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("SignalingProtocols", ctx, "0", get_signal_protocols, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Regions", ctx, "0", get_regions, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RTCP", ctx, "0", get_true_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("SRTP", ctx, "0", get_true_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("RTPRedundancy", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("PSTNSoftSwitchOver", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("FaxT38", ctx, "0", get_true_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("FaxPassThrough", ctx, "0", get_true_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ModemPassThrough", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ToneGeneration", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ToneDescriptionsEditable", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("PatternBasedToneGeneration", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("FileBasedToneGeneration", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ToneFileFormats", ctx, "0", get_empty, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RingGeneration", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("RingDescriptionsEditable", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("PatternBasedRingGeneration", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("RingPatternEditable", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("FileBasedRingGeneration", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("RingFileFormats", ctx, "0", get_empty, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DigitMap", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("NumberingPlan", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ButtonMap", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("VoicePortTests", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.Capabilities.SIP.", ctx, "0", 0, NULL, NULL, NULL, ivoice); - DMPARAM("Role", ctx, "0", get_sip_role, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Extensions", ctx, "0", get_sip_extension, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Transports", ctx, "0", get_sip_transport, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("URISchemes", ctx, "0", get_empty, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("EventSubscription", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ResponseMap", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("TLSAuthenticationProtocols", ctx, "0", get_sip_tls_auth_protocols, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("TLSEncryptionProtocols", ctx, "0", get_sip_tls_enc_protocols, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("TLSKeyExchangeProtocols", ctx, "0", get_sip_tls_key_protocols, NULL, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.Capabilities.Codecs.", ctx, "0", 1, NULL, NULL, NULL, ivoice); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.", ctx, "1", 1, add_profile_object, delete_profile_object_all, NULL, ivoice); - SUBENTRY(entry_voice_service_capabilities_codecs, ctx, ivoice); - SUBENTRY(entry_services_voice_service_voiceprofile, ctx, ivoice); - return 0; - } - return FAULT_9005; -} -inline int entry_voice_service_capabilities_codecs_instance(struct dmctx *ctx, char *ivoice, char *id) -{ - IF_MATCH(ctx, DMROOT"Services.VoiceService.%s.Capabilities.Codecs.%s.", ivoice, id) { - DMOBJECT(DMROOT"Services.VoiceService.%s.Capabilities.Codecs.%s.", ctx, "0", 1, NULL, NULL, NULL, ivoice, id); - DMPARAM("Alias", ctx, "1", get_cap_codec_alias, set_cap_codec_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("EntryID", ctx, "0", get_entry_id, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Codec", ctx, "0", get_capabilities_sip_codec, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BitRate", ctx, "0", get_capabilities_sip_bitrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketizationPeriod", ctx, "0", get_capabilities_sip_pperiod, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SilenceSuppression", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_services_voice_service_voiceprofile_instance (struct dmctx *ctx, char *ivoice, char *profile_num) -{ - IF_MATCH(ctx, DMROOT"Services.VoiceService.%s.VoiceProfile.%s.", ivoice, profile_num) { - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.", ctx, "1", 1, NULL, delete_profile_object, NULL, ivoice, profile_num); - DMPARAM("Alias", ctx, "1", get_voice_profile_alias, set_voice_profile_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_voice_profile_enable, set_voice_profile_enable, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Reset", ctx, "1", get_false_value, set_voice_profile_reset, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_voice_profile_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SignalingProtocol", ctx, "1" ,get_voice_profile_signalprotocol, set_voice_profile_signaling_protocol, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxSessions", ctx, "0" ,get_voice_profile_max_sessions, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("NumberOfLines", ctx, "0" ,get_voice_profile_number_of_lines, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DTMFMethod", ctx, "1", get_voice_profile_sip_dtmfmethod, set_voice_profile_sip_dtmfmethod, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Region", ctx, "1", get_sip_profile_region, set_sip_profile_region, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.SIP.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num); - DMPARAM("ProxyServer", ctx, "1" ,get_voice_profile_sip_proxyserver, set_voice_profile_sip_proxyserver, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ProxyServerPort", ctx, "1" ,get_empty, set_sip_proxy_server_port, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ProxyServerTransport", ctx, "1" ,get_sip_proxy_server_transport, set_sip_proxy_server_transport, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RegistrarServer", ctx, "1" ,get_voice_profile_sip_registerserver, set_voice_profile_sip_registerserver, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RegistrarServerPort", ctx, "1" ,get_voice_profile_sip_registerserverport, set_voice_profile_sip_registerserverport, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RegistrarServerTransport", ctx, "1" ,get_sip_registrar_server_transport, set_sip_registrar_server_transport, NULL, 0, 1, UNDEF, NULL); - DMPARAM("UserAgentDomain", ctx, "1", get_sip_user_agent_domain, set_sip_user_agent_domain, NULL, 0, 1, UNDEF, NULL); - DMPARAM("UserAgentPort", ctx, "1", get_sip_user_agent_port, set_sip_user_agent_port, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("UserAgentTransport", ctx, "1", get_sip_user_agent_transport, set_sip_user_agent_transport, NULL, 0, 1, UNDEF, NULL); - DMPARAM("OutboundProxy", ctx, "1", get_sip_outbound_proxy, set_sip_outbound_proxy, NULL, 0, 1, UNDEF, NULL); - DMPARAM("OutboundProxyPort", ctx, "1", get_sip_outbound_proxy_port, set_sip_outbound_proxy_port, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RegistrationPeriod", ctx, "1", get_sip_registration_period, set_sip_registration_period, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ReInviteExpires", ctx, "1", get_sip_re_invite_expires, set_sip_re_invite_expires, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RegisterExpires", ctx, "1", get_sip_re_invite_expires, set_sip_re_invite_expires, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RegisterRetryInterval", ctx, "1",get_sip_re_invite_expires, set_sip_re_invite_expires, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("X_002207_CallLines", ctx, "1", get_sip_x_002207_call_lines, set_sip_x_002207_call_lines, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.ServiceProviderInfo.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num); - DMPARAM("Name", ctx, "1", get_voice_service_serviceproviderinfo_name, set_voice_service_serviceproviderinfo_name, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.FaxT38.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num); - DMPARAM("Enable", ctx, "1", get_sip_fax_t38_enable, set_sip_fax_t38_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.RTP.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num); - DMPARAM("LocalPortMin", ctx, "1", get_voice_service_vp_rtp_portmin, set_voice_service_vp_rtp_portmin, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("LocalPortMax", ctx, "1", get_voice_service_vp_rtp_portmax, set_voice_profile_rtp_localportmax, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DSCPMark", ctx, "1", get_voice_service_vp_rtp_dscp, set_voice_service_vp_rtp_dscp, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.RTP.RTCP.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num); - DMPARAM("Enable", ctx, "0", get_voice_service_vp_rtp_rtcp_enable, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("TxRepeatInterval", ctx, "1", get_voice_service_vp_rtp_rtcp_txrepeatinterval, set_voice_service_vp_rtp_rtcp_txrepeatinterval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.RTP.SRTP.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num); - DMPARAM("Enable", ctx, "1", get_voice_service_vp_rtp_srtp_enable, set_voice_service_vp_rtp_srtp_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.", ctx, "1", 1, add_line_object, delete_line_object_all, NULL, ivoice, profile_num); - SUBENTRY(entry_services_voice_service_line, ctx, ivoice, profile_num); - return 0; - } - return FAULT_9005; -} - -inline int entry_services_voice_service_line_instance(struct dmctx *ctx, char *ivoice, char *profile_num, char *line_num) -{ - IF_MATCH(ctx, DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.", ivoice, profile_num, line_num) { - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.", ctx, "1", 1, NULL, delete_line_object, NULL, ivoice, profile_num, line_num); - DMPARAM("Alias", ctx, "1", get_line_alias, set_line_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_voice_profile_enable, set_voice_profile_enable, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DirectoryNumber", ctx, "1", get_line_directory_number, set_line_directory_number, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_voice_profile_line_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("CallState", ctx, "0", get_voice_profile_line_callstate, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_002207_LineProfile", ctx, "1", get_line_x_002207_line_profile, set_line_x_002207_line_profile, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_002207_BRCMLine", ctx, "1", get_line_x_002207_brcm_line, set_line_x_002207_brcm_line, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_Confort_Noise_Enable", ctx, "1", get_line_confort_noise_enable, set_line_confort_noise_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.VoiceProcessing.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num, line_num); - DMPARAM("EchoCancellationEnable", ctx, "1", get_line_voice_processing_cancellation_enable, set_line_voice_processing_cancellation_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.CallingFeatures.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num, line_num); - DMPARAM("CallerIDName", ctx, "1", get_line_calling_features_caller_id_name, set_line_calling_features_caller_id_name, NULL, 0, 1, UNDEF, NULL); - DMPARAM("CallWaitingEnable", ctx, "1", get_line_calling_features_callwaiting, set_line_calling_features_callwaiting, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.SIP.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num, line_num); - DMPARAM("AuthUserName", ctx, "1", get_line_sip_auth_username, set_line_sip_auth_username, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AuthPassword", ctx, "1", get_empty, set_line_sip_auth_password, NULL, 0, 1, UNDEF, NULL); - DMPARAM("URI" , ctx, "1", get_line_sip_uri, set_line_sip_uri, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.codec.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num, line_num); - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.codec.List.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num, line_num); - SUBENTRY(entry_services_voice_service_line_codec_list, ctx, ivoice, profile_num, line_num); - return 0; - } - return FAULT_9005; -} - -inline int entry_services_voice_service_line_codec_list_instance(struct dmctx *ctx, char *ivoice, char *profile_num, char *line_num, char *codec_num) -{ - IF_MATCH(ctx, DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.Codec.List.%s.", ivoice, profile_num, line_num, codec_num) { - DMOBJECT(DMROOT"Services.VoiceService.%s.VoiceProfile.%s.Line.%s.Codec.List.%s.", ctx, "0", 1, NULL, NULL, NULL, ivoice, profile_num, line_num, codec_num); - DMPARAM("Alias", ctx, "1", get_line_codec_list_alias, set_line_codec_list_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("EntryID", ctx, "0", get_codec_entry_id, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Codec", ctx, "0", capabilities_sip_codecs_get_codec, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BitRate", ctx, "0", capabilities_sip_codecs_get_bitrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketizationPeriod", ctx, "1", get_capabilities_sip_codecs_pperiod, set_line_codec_list_packetization, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SilenceSuppression", ctx, "0", get_false_value, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_line_codec_list_enable, set_line_codec_list_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Priority", ctx, "1", get_line_codec_list_priority, set_line_codec_list_priority, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/voice_services.h b/dm/dmtree/common/voice_services.h index f2aae53..29051ed 100644 --- a/dm/dmtree/common/voice_services.h +++ b/dm/dmtree/common/voice_services.h @@ -13,6 +13,30 @@ #ifndef __VOICE_H #define __VOICE_H +extern DMOBJ tServiceObj[]; +extern DMOBJ tVoiceServiceObj[]; +extern DMLEAF tVoiceServiceParam[]; +extern DMLEAF tCapabilitiesParams[]; +extern DMOBJ tCapabilitiesObj[]; +extern DMLEAF tSIPParams[]; +extern DMLEAF tCodecsParams[] ; +extern DMOBJ tProfileObj[] ; +extern DMLEAF tProfileSIPParams[]; +extern DMLEAF tServiceProviderInfoParams[]; +extern DMLEAF tProfileParam[]; +extern DMOBJ tLineObj[]; +extern DMOBJ tLineCodecObj[]; +extern DMLEAF tLineCodecListParams[]; +extern DMLEAF tLineSIPParams[]; +extern DMLEAF tVoiceProcessingParams[]; +extern DMLEAF tCallingFeaturesParams[]; +extern DMLEAF tLineParams[]; +extern DMLEAF tRTPParams[]; +extern DMOBJ tRTPObj[]; +extern DMLEAF tSRTPParam[]; +extern DMLEAF tRTCPParams[]; +extern DMLEAF tFaxT38Params[]; + /*Args of get_voice_service_capabilities_codecs_generic*/ struct codec_args { @@ -85,11 +109,6 @@ struct codec char *priority; }; -struct service_args -{ - struct uci_section *service_section; -}; - enum enum_cap_sip_codecs { SIP_CODEC_G723, SIP_CODEC_GSM, @@ -112,6 +131,132 @@ enum enum_cap_sip_codecs { SIP_CODEC_TESTLAW }; -int entry_method_root_Service(struct dmctx *ctx); bool dm_service_enable_set(void); +int browseVoiceServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseCodecsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseLineCodecListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_profile_object(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_profile_object(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_line_object(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_line_object(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +int get_service_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_max_profile_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_max_line_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_true_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_max_session_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_signal_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_regions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_false_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_role(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_extension(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_tls_auth_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_tls_enc_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_tls_key_protocols(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_cap_codec_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_entry_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_capabilities_sip_codec(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_capabilities_sip_bitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_capabilities_sip_pperiod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_signalprotocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_max_sessions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_number_of_lines(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_profile_region(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_sip_proxyserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_proxy_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_sip_registerserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_sip_registerserverport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_registrar_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_user_agent_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_user_agent_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_user_agent_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_outbound_proxy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_outbound_proxy_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_registration_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_re_invite_expires(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_x_002207_call_lines(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_sip_fax_t38_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_service_vp_rtp_portmax(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_service_vp_rtp_rtcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_line_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_line_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_voice_profile_line_callstate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_x_002207_line_profile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_x_002207_brcm_line(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_confort_noise_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_voice_processing_cancellation_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_calling_features_caller_id_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_sip_auth_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_sip_uri(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_codec_list_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_codec_entry_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int capabilities_sip_codecs_get_codec(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int capabilities_sip_codecs_get_bitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_capabilities_sip_codecs_pperiod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_codec_list_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_codec_list_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_directory_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_service_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_cap_codec_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_signaling_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_sip_dtmfmethod(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_sip_proxyserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_proxy_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_proxy_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_sip_registerserver(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_sip_registerserverport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_registrar_server_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_user_agent_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_user_agent_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_user_agent_transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_outbound_proxy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_outbound_proxy_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_registration_period(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_re_invite_expires(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_x_002207_call_lines(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_service_serviceproviderinfo_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_fax_t38_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_service_vp_rtp_portmin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_rtp_localportmax(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_service_vp_rtp_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_service_vp_rtp_rtcp_txrepeatinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_service_vp_rtp_srtp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_voice_profile_line_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_directory_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_x_002207_line_profile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_x_002207_brcm_line(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_confort_noise_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_calling_features_caller_id_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_voice_processing_cancellation_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_calling_features_callwaiting(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_sip_auth_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_sip_auth_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_sip_uri(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_codec_list_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_codec_list_packetization(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_codec_list_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_line_codec_list_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_sip_profile_region(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_voice_service_max_line(); + #endif diff --git a/dm/dmtree/common/x_inteno_se_buttons.c b/dm/dmtree/common/x_inteno_se_buttons.c index 53bc28b..287c9c8 100644 --- a/dm/dmtree/common/x_inteno_se_buttons.c +++ b/dm/dmtree/common/x_inteno_se_buttons.c @@ -18,15 +18,29 @@ #include "dmcommon.h" #include "x_inteno_se_buttons.h" -struct button_args cur_button_args = {0}; -inline int entry_xinteno_button_instance(struct dmctx *ctx, char *ibutton); -inline int entry_xinteno_buttons(struct dmctx *ctx); +/*** DMROOT.X_INTENO_SE_Buttons.{i}. ****/ +DMLEAF X_INTENO_SE_ButtonParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_x_inteno_button_alias, set_x_inteno_button_alias, NULL, NULL}, +{"button", &DMREAD, DMT_STRING, get_x_inteno_button_name, NULL, NULL, NULL}, +{"hotplug", &DMREAD, DMT_STRING, get_x_inteno_button_hotplug, NULL, NULL, NULL}, +{"hotplug_long", &DMREAD, DMT_STRING, get_x_inteno_button_hotplug_long, NULL, NULL, NULL}, +{"minpress", &DMWRITE, DMT_UNINT, get_x_inteno_button_minpress, set_x_inteno_button_minpress, NULL, NULL}, +{"longpress", &DMWRITE, DMT_UNINT, get_x_inteno_button_longpress, set_x_inteno_button_longpress, NULL, NULL}, +{"enable", &DMWRITE, DMT_BOOL, get_x_inteno_button_enable, set_x_inteno_button_enable, NULL, NULL}, +{0} +}; -inline int init_args_button(struct dmctx *ctx, struct uci_section *s) +int browseXIntenoButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct button_args *args = &cur_button_args; - ctx->args = (void *)args; - args->button_section = s; + char *ibutton = NULL, *ibutton_last = NULL; + struct uci_section *s = NULL; + + uci_foreach_sections("buttons", "button", s) { + ibutton = handle_update_instance(1, dmctx, &ibutton_last, update_instance_alias, 3, s, "buttoninstance", "buttonalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, ibutton) == DM_STOP) + break; + } return 0; } @@ -34,11 +48,11 @@ inline int init_args_button(struct dmctx *ctx, struct uci_section *s) **** function related to button **** **************************************************************************************/ -int get_x_inteno_button_name(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_button_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_list *val; - dmuci_get_value_by_section_list(cur_button_args.button_section, "button", &val); + dmuci_get_value_by_section_list((struct uci_section *)data, "button", &val); if (val) *value = dmuci_list_to_string(val, " "); else @@ -46,67 +60,67 @@ int get_x_inteno_button_name(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_x_inteno_button_hotplug(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_button_hotplug(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_button_args.button_section, "hotplug", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "hotplug", value); return 0; } -int get_x_inteno_button_hotplug_long(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_button_hotplug_long(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_button_args.button_section, "hotplug_long", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "hotplug_long", value); return 0; } -int get_x_inteno_button_minpress(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_button_args.button_section, "minpress", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "minpress", value); return 0; } -int set_x_inteno_button_minpress(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_button_args.button_section, "minpress", value); + dmuci_set_value_by_section((struct uci_section *)data, "minpress", value); return 0; } return 0; } -int get_x_inteno_button_longpress(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_button_args.button_section, "longpress", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "longpress", value); return 0; } -int set_x_inteno_button_longpress(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_button_args.button_section, "longpress", value); + dmuci_set_value_by_section((struct uci_section *)data, "longpress", value); return 0; } return 0; } -int get_x_inteno_button_enable(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_button_args.button_section, "enable", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); if ((*value)[0] == '\0') { *value = "1"; } return 0; } -int set_x_inteno_button_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -118,72 +132,31 @@ int set_x_inteno_button_enable(char *refparam, struct dmctx *ctx, int action, ch case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_button_args.button_section, "enable", ""); + dmuci_set_value_by_section((struct uci_section *)data, "enable", ""); else - dmuci_set_value_by_section(cur_button_args.button_section, "enable", "0"); + dmuci_set_value_by_section((struct uci_section *)data, "enable", "0"); return 0; } return 0; } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_inteno_button_alias(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_button_args.button_section, "buttonalias", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "buttonalias", value); return 0; } -int set_x_inteno_button_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_button_args.button_section, "buttonalias", value); + dmuci_set_value_by_section((struct uci_section *)data, "buttonalias", value); return 0; } return 0; } -/////////////SUB ENTRIES/////////////// -inline int entry_xinteno_buttons(struct dmctx *ctx) -{ - char *ibutton = NULL, *ibutton_last = NULL; - struct uci_section *s = NULL; - - uci_foreach_sections("buttons", "button", s) { - init_args_button(ctx, s); - ibutton = handle_update_instance(1, ctx, &ibutton_last, update_instance_alias, 3, s, "buttoninstance", "buttonalias"); - SUBENTRY(entry_xinteno_button_instance, ctx, ibutton); - } - return 0; -} - -////////////////////////////////////// - -int entry_method_root_X_INTENO_SE_BUTTONS(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Buttons.") { - DMOBJECT(DMROOT"X_INTENO_SE_Buttons.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_xinteno_buttons, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_xinteno_button_instance(struct dmctx *ctx, char *ibutton) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Buttons.%s.", ibutton) { - DMOBJECT(DMROOT"X_INTENO_SE_Buttons.%s.", ctx, "0", 1, NULL, NULL, NULL, ibutton); - DMPARAM("Alias", ctx, "1", get_x_inteno_button_alias, set_x_inteno_button_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("button", ctx, "0", get_x_inteno_button_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("hotplug", ctx, "0", get_x_inteno_button_hotplug, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("hotplug_long", ctx, "0", get_x_inteno_button_hotplug_long, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("minpress", ctx, "1", get_x_inteno_button_minpress, set_x_inteno_button_minpress, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("longpress", ctx, "1", get_x_inteno_button_longpress, set_x_inteno_button_longpress, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("enable", ctx, "1", get_x_inteno_button_enable, set_x_inteno_button_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/x_inteno_se_buttons.h b/dm/dmtree/common/x_inteno_se_buttons.h index 04cded3..be6d06d 100644 --- a/dm/dmtree/common/x_inteno_se_buttons.h +++ b/dm/dmtree/common/x_inteno_se_buttons.h @@ -1,10 +1,18 @@ #ifndef __SE_BUTTONS_H #define __SE_BUTTONS_H -struct button_args -{ - struct uci_section *button_section; -}; +extern DMLEAF X_INTENO_SE_ButtonParams[]; +int browseXIntenoButton(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int get_x_inteno_button_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_button_hotplug(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_button_hotplug_long(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_button_minpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_button_longpress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_button_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_button_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int entry_method_root_X_INTENO_SE_BUTTONS(struct dmctx *ctx); #endif diff --git a/dm/dmtree/common/x_inteno_se_dropbear.c b/dm/dmtree/common/x_inteno_se_dropbear.c index 2e6c602..c85177a 100644 --- a/dm/dmtree/common/x_inteno_se_dropbear.c +++ b/dm/dmtree/common/x_inteno_se_dropbear.c @@ -18,15 +18,35 @@ #include "dmcommon.h" #include "x_inteno_se_dropbear.h" -inline int entry_xinteno_dropbear_instance(struct dmctx *ctx, char *idropbear); -inline int entry_xinteno_dropbear(struct dmctx *ctx); -struct dropbear_args cur_dropbear_args = {0}; +/*** DMROOT.X_INTENO_SE_Dropbear.{i}. ****/ +DMLEAF X_INTENO_SE_DropbearParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_x_inteno_dropbear_alias, set_x_inteno_dropbear_alias, NULL, NULL}, +{"PasswordAuth", &DMWRITE, DMT_BOOL, get_x_inteno_dropbear_password_auth, set_x_inteno_dropbear_password_auth, NULL, NULL}, +{"RootPasswordAuth", &DMWRITE, DMT_BOOL, get_x_inteno_dropbear_root_password_auth, set_x_inteno_dropbear_root_password_auth, NULL, NULL}, +{"Port", &DMWRITE, DMT_UNINT, get_x_inteno_dropbear_port, set_x_inteno_dropbear_port, NULL, NULL}, +{"RootLogin", &DMWRITE, DMT_BOOL, get_x_inteno_dropbear_root_login, set_x_inteno_dropbear_root_login, NULL, NULL}, +{"GatewayPorts", &DMWRITE, DMT_BOOL, get_x_inteno_dropbear_gateway_ports, set_x_inteno_dropbear_gateway_ports, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_x_inteno_dropbear_interface, set_x_inteno_dropbear_interface, NULL, NULL}, +{"rsakeyfile", &DMWRITE, DMT_STRING, get_x_inteno_dropbear_rsakeyfile, set_x_inteno_dropbear_rsakeyfile, NULL, NULL}, +{"dsskeyfile", &DMWRITE, DMT_STRING, get_x_inteno_dropbear_dsskeyfile, set_x_inteno_dropbear_dsskeyfile, NULL, NULL}, +{"SSHKeepAlive", &DMWRITE, DMT_UNINT, get_x_inteno_dropbear_ssh_keepalive, set_x_inteno_dropbear_ssh_keepalive, NULL, NULL}, +{"IdleTimeout", &DMWRITE, DMT_UNINT, get_x_inteno_dropbear_idle_timeout, set_x_inteno_dropbear_idle_timeout, NULL, NULL}, +{"verbose", &DMWRITE, DMT_BOOL, get_x_inteno_dropbear_gateway_ports, set_x_inteno_dropbear_gateway_ports, NULL, NULL}, +{"BannerFile", &DMWRITE, DMT_STRING, get_x_inteno_dropbear_interface, set_x_inteno_dropbear_interface, NULL, NULL}, +{0} +}; -inline int init_args_dropbear(struct dmctx *ctx, struct uci_section *s) +int browseXIntenoDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct dropbear_args *args = &cur_dropbear_args; - ctx->args = (void *)args; - args->dropbear_section = s; + char *idropbear = NULL, *idropbear_last = NULL; + struct uci_section *s = NULL; + + uci_foreach_sections("dropbear", "dropbear", s) { + idropbear = handle_update_instance(1, dmctx, &idropbear_last, update_instance_alias, 3, s, "dropbearinstance", "dropbearalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, idropbear) == DM_STOP) + break; + } return 0; } @@ -35,9 +55,9 @@ inline int init_args_dropbear(struct dmctx *ctx, struct uci_section *s) **************************************************************************************/ -int get_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "PasswordAuth", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "PasswordAuth", value); if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1') { *value = "1"; } @@ -46,7 +66,7 @@ int get_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, char return 0; } -int set_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -58,17 +78,17 @@ int set_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, int a case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "PasswordAuth", "1"); + dmuci_set_value_by_section((struct uci_section *)data, "PasswordAuth", "1"); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "PasswordAuth", "0"); + dmuci_set_value_by_section((struct uci_section *)data, "PasswordAuth", "0"); return 0; } return 0; } -int get_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "RootPasswordAuth", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "RootPasswordAuth", value); if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1') { *value = "1"; } @@ -77,7 +97,7 @@ int get_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, return 0; } -int set_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -89,24 +109,24 @@ int set_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "RootPasswordAuth", "1"); + dmuci_set_value_by_section((struct uci_section *)data, "RootPasswordAuth", "1"); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "RootPasswordAuth", "0"); + dmuci_set_value_by_section((struct uci_section *)data, "RootPasswordAuth", "0"); return 0; } return 0; } -int get_x_inteno_dropbear_port(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "Port", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "Port", value); if ((*value)[0] == '\0') { *value = "22"; } return 0; } -int set_x_inteno_dropbear_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -114,17 +134,17 @@ int set_x_inteno_dropbear_port(char *refparam, struct dmctx *ctx, int action, ch return 0; case VALUESET: if (value[0] == '\0') - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "Port", "22"); + dmuci_set_value_by_section((struct uci_section *)data, "Port", "22"); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "Port", value); + dmuci_set_value_by_section((struct uci_section *)data, "Port", value); return 0; } return 0; } -int get_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "RootLogin", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "RootLogin", value); if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1' ) { *value = "1"; } @@ -133,7 +153,7 @@ int get_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -145,17 +165,17 @@ int set_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, int acti case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "RootLogin", "1"); + dmuci_set_value_by_section((struct uci_section *)data, "RootLogin", "1"); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "RootLogin", "0"); + dmuci_set_value_by_section((struct uci_section *)data, "RootLogin", "0"); return 0; } return 0; } -int get_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "verbose", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "verbose", value); if ((*value)[0] == '\0' || (*value)[0] == '0' ) { *value = "0"; } @@ -164,7 +184,7 @@ int get_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, char **valu return 0; } -int set_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -176,18 +196,18 @@ int set_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, int action, case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "verbose", "1"); + dmuci_set_value_by_section((struct uci_section *)data, "verbose", "1"); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "verbose", "0"); + dmuci_set_value_by_section((struct uci_section *)data, "verbose", "0"); return 0; } return 0; } -int get_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "GatewayPorts", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "GatewayPorts", value); if ((*value)[0] == '\0' || (*value)[0] == '0' ) { *value = "0"; } @@ -196,7 +216,7 @@ int get_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, char return 0; } -int set_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -208,81 +228,81 @@ int set_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, int a case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "GatewayPorts", "1"); + dmuci_set_value_by_section((struct uci_section *)data, "GatewayPorts", "1"); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "GatewayPorts", ""); + dmuci_set_value_by_section((struct uci_section *)data, "GatewayPorts", ""); return 0; } return 0; } -int get_x_inteno_dropbear_interface(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "Interface", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "Interface", value); return 0; } -int set_x_inteno_dropbear_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "Interface", value); + dmuci_set_value_by_section((struct uci_section *)data, "Interface", value); return 0; } return 0; } -int get_x_inteno_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "rsakeyfile", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "rsakeyfile", value); return 0; } -int set_x_inteno_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "rsakeyfile", value); + dmuci_set_value_by_section((struct uci_section *)data, "rsakeyfile", value); return 0; } return 0; } -int get_x_inteno_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "dsskeyfile", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "dsskeyfile", value); return 0; } -int set_x_inteno_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "dsskeyfile", value); + dmuci_set_value_by_section((struct uci_section *)data, "dsskeyfile", value); return 0; } return 0; } -int get_x_inteno_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "SSHKeepAlive", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "SSHKeepAlive", value); if ((*value)[0] == '\0') { *value = "300"; } return 0; } -int set_x_inteno_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -290,24 +310,24 @@ int set_x_inteno_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, int a return 0; case VALUESET: if (strcmp(value, "300") == 0) - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "SSHKeepAlive", ""); + dmuci_set_value_by_section((struct uci_section *)data, "SSHKeepAlive", ""); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "SSHKeepAlive", value); + dmuci_set_value_by_section((struct uci_section *)data, "SSHKeepAlive", value); return 0; } return 0; } -int get_x_inteno_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "IdleTimeout", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "IdleTimeout", value); if ((*value)[0] == '\0') { *value = "300"; } return 0; } -int set_x_inteno_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { @@ -315,28 +335,28 @@ int set_x_inteno_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, int ac return 0; case VALUESET: if (value[0] == '0') - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "IdleTimeout", ""); + dmuci_set_value_by_section((struct uci_section *)data, "IdleTimeout", ""); else - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "IdleTimeout", value); + dmuci_set_value_by_section((struct uci_section *)data, "IdleTimeout", value); return 0; } return 0; } -int get_x_inteno_dropbear_banner_file(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "BannerFile", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "BannerFile", value); return 0; } -int set_x_inteno_dropbear_banner_file(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "BannerFile", value); + dmuci_set_value_by_section((struct uci_section *)data, "BannerFile", value); return 0; } return 0; @@ -344,26 +364,26 @@ int set_x_inteno_dropbear_banner_file(char *refparam, struct dmctx *ctx, int act ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_inteno_dropbear_alias(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dropbear_args.dropbear_section, "dropbearalias", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "dropbearalias", value); return 0; } -int set_x_inteno_dropbear_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dropbear_args.dropbear_section, "dropbearalias", value); + dmuci_set_value_by_section((struct uci_section *)data, "dropbearalias", value); return 0; } return 0; } /***** ADD DEL OBJ *******/ -int add_dropbear_instance(struct dmctx *ctx, char **instancepara) +int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char *instance; @@ -381,75 +401,26 @@ int add_dropbear_instance(struct dmctx *ctx, char **instancepara) return 0; } -int delete_dropbear_all(struct dmctx *ctx) +int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL; struct uci_section *ss = NULL; int found = 0; - - uci_foreach_sections("dropbear", "dropbear", s) { + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section((struct uci_section *)data, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("dropbear", "dropbear", s) { if (found != 0) dmuci_delete_by_section(ss, NULL, NULL); ss = s; found++; - } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - return 0; -} - - -int delete_dropbear_instance(struct dmctx *ctx) -{ - dmuci_delete_by_section(cur_dropbear_args.dropbear_section, NULL, NULL); - return 0; -} -/////////////SUB ENTRIES/////////////// -inline int entry_xinteno_dropbear(struct dmctx *ctx) -{ - char *idropbear = NULL, *idropbear_last = NULL; - struct uci_section *s = NULL; - - uci_foreach_sections("dropbear", "dropbear", s) { - init_args_dropbear(ctx, s); - idropbear = handle_update_instance(1, ctx, &idropbear_last, update_instance_alias, 3, s, "dropbearinstance", "dropbearalias"); - SUBENTRY(entry_xinteno_dropbear_instance, ctx, idropbear); - } - return 0; -} - -////////////////////////////////////// - -int entry_method_root_X_INTENO_SE_DROPBEAR(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Dropbear.") { - DMOBJECT(DMROOT"X_INTENO_SE_Dropbear.", ctx, "1", 1, add_dropbear_instance, delete_dropbear_all, NULL); - SUBENTRY(entry_xinteno_dropbear, ctx); + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); return 0; } - return FAULT_9005; -} - -inline int entry_xinteno_dropbear_instance(struct dmctx *ctx, char *idropbear) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Dropbear.%s.", idropbear) { - DMOBJECT(DMROOT"X_INTENO_SE_Dropbear.%s.", ctx, "1", 1, NULL, delete_dropbear_instance, NULL, idropbear); - DMPARAM("Alias", ctx, "1", get_x_inteno_dropbear_alias, set_x_inteno_dropbear_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("PasswordAuth", ctx, "1", get_x_inteno_dropbear_password_auth, set_x_inteno_dropbear_password_auth, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("RootPasswordAuth", ctx, "1", get_x_inteno_dropbear_root_password_auth, set_x_inteno_dropbear_root_password_auth, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Port", ctx, "1", get_x_inteno_dropbear_port, set_x_inteno_dropbear_port, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RootLogin", ctx, "1", get_x_inteno_dropbear_root_login, set_x_inteno_dropbear_root_login, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("GatewayPorts", ctx, "1", get_x_inteno_dropbear_gateway_ports, set_x_inteno_dropbear_gateway_ports, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Interface", ctx, "1", get_x_inteno_dropbear_interface, set_x_inteno_dropbear_interface, NULL, 0, 1, UNDEF, NULL); - DMPARAM("rsakeyfile", ctx, "1", get_x_inteno_dropbear_rsakeyfile, set_x_inteno_dropbear_rsakeyfile, NULL, 0, 1, UNDEF, NULL); - DMPARAM("dsskeyfile", ctx, "1", get_x_inteno_dropbear_dsskeyfile, set_x_inteno_dropbear_dsskeyfile, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SSHKeepAlive", ctx, "1", get_x_inteno_dropbear_ssh_keepalive, set_x_inteno_dropbear_ssh_keepalive, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("IdleTimeout", ctx, "1", get_x_inteno_dropbear_idle_timeout, set_x_inteno_dropbear_idle_timeout, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - //DMPARAM("enable", ctx, "1", get_x_inteno_dropbear_enable, set_x_inteno_dropbear_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("verbose", ctx, "1", get_x_inteno_dropbear_verbose, set_x_inteno_dropbear_verbose, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("BannerFile", ctx, "1", get_x_inteno_dropbear_banner_file, set_x_inteno_dropbear_banner_file, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; + return 0; } diff --git a/dm/dmtree/common/x_inteno_se_dropbear.h b/dm/dmtree/common/x_inteno_se_dropbear.h index 82af030..b69074c 100644 --- a/dm/dmtree/common/x_inteno_se_dropbear.h +++ b/dm/dmtree/common/x_inteno_se_dropbear.h @@ -1,10 +1,35 @@ #ifndef __SE_DROPBEAR_H #define __SE_DROPBEAR_H -struct dropbear_args -{ - struct uci_section *dropbear_section; -}; +extern DMLEAF X_INTENO_SE_DropbearParams[]; +int browseXIntenoDropbear(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int get_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); -int entry_method_root_X_INTENO_SE_DROPBEAR(struct dmctx *ctx); #endif diff --git a/dm/dmtree/common/x_inteno_se_ice.c b/dm/dmtree/common/x_inteno_se_ice.c index 120978f..ed61a57 100644 --- a/dm/dmtree/common/x_inteno_se_ice.c +++ b/dm/dmtree/common/x_inteno_se_ice.c @@ -18,7 +18,14 @@ #include "dmcommon.h" #include "x_inteno_se_ice.h" -int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, char **value) +/*** DMROOT.X_INTENO_SE_ICE. ***/ +DMLEAF tSe_IceParam[] = { + {"Enable", &DMWRITE, DMT_BOOL, get_ice_cloud_enable, set_ice_cloud_enable, NULL, NULL}, + {"Server", &DMWRITE, DMT_STRING, get_ice_cloud_server, set_ice_cloud_server, NULL, NULL}, + {0} +}; + +int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { bool b; dmuci_get_option_value_string("ice", "cloud", "enabled", value); @@ -31,7 +38,7 @@ int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -50,13 +57,13 @@ int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, int action, char *va } } -int get_ice_cloud_server(char *refparam, struct dmctx *ctx, char **value) +int get_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("ice", "cloud", "server", value); return 0; } -int set_ice_cloud_server(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -69,14 +76,3 @@ int set_ice_cloud_server(char *refparam, struct dmctx *ctx, int action, char *va } return 0; } - -int entry_method_root_X_INTENO_SE_Ice(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_ICE.") { - DMOBJECT(DMROOT"X_INTENO_SE_ICE.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("Enable", ctx, "1", get_ice_cloud_enable, set_ice_cloud_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Server", ctx, "1", get_ice_cloud_server, set_ice_cloud_server, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/x_inteno_se_ice.h b/dm/dmtree/common/x_inteno_se_ice.h index df9b9f1..a06e955 100644 --- a/dm/dmtree/common/x_inteno_se_ice.h +++ b/dm/dmtree/common/x_inteno_se_ice.h @@ -1,6 +1,12 @@ #ifndef __SE_ICE_H #define __SE_ICE_H -int entry_method_root_X_INTENO_SE_Ice(struct dmctx *ctx); +extern DMLEAF tSe_IceParam[]; -#endif \ No newline at end of file +int get_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_ice_cloud_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ice_cloud_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/common/x_inteno_se_igmp.c b/dm/dmtree/common/x_inteno_se_igmp.c index ed5fc24..07100bb 100644 --- a/dm/dmtree/common/x_inteno_se_igmp.c +++ b/dm/dmtree/common/x_inteno_se_igmp.c @@ -19,13 +19,13 @@ #include "x_inteno_se_igmp.h" -int get_igmp_dscp_mark(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_dscp_mark", value); return 0; } -int set_igmp_dscp_mark(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_dscp_mark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -37,7 +37,7 @@ int set_igmp_dscp_mark(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *p; dmuci_get_option_value_string("mcpd", "mcpd", "igmp_proxy_interfaces", value); @@ -49,7 +49,7 @@ int get_igmp_proxy_interface(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int i; char *p; @@ -73,13 +73,13 @@ int set_igmp_proxy_interface(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_igmp_default_version(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_default_version", value); return 0; } -int set_igmp_default_version(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_default_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -91,13 +91,13 @@ int set_igmp_default_version(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_igmp_query_interval(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_query_interval", value); return 0; } -int set_igmp_query_interval(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_query_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -109,13 +109,13 @@ int set_igmp_query_interval(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_igmp_query_response_interval(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_query_response_interval", value); return 0; } -int set_igmp_query_response_interval(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_query_response_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -127,13 +127,13 @@ int set_igmp_query_response_interval(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_last_member_query_interval", value); return 0; } -int set_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -145,13 +145,13 @@ int set_igmp_last_member_queryinterval(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_igmp_robustness_value(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_robustness_value", value); return 0; } -int set_igmp_robustness_value(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_robustness_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -163,7 +163,7 @@ int set_igmp_robustness_value(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_igmp_multicast_enable(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_lan_to_lan_multicast", value); if ((*value)[0] == '\0') { @@ -172,7 +172,7 @@ int get_igmp_multicast_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_igmp_multicast_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_multicast_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -192,7 +192,7 @@ int set_igmp_multicast_enable(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_fast_leave", value); if ((*value)[0] == '\0') { @@ -201,7 +201,7 @@ int get_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -221,7 +221,7 @@ int set_igmp_fastleave_enable(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_join_immediate", value); if ((*value)[0] == '\0') { @@ -230,7 +230,7 @@ int get_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, char **valu return 0; } -int set_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -250,7 +250,7 @@ int set_igmp_joinimmediate_enable(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_igmp_proxy_enable(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_proxy_enable", value); if ((*value)[0] == '\0') { @@ -259,7 +259,7 @@ int get_igmp_proxy_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_igmp_proxy_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_proxy_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -279,13 +279,13 @@ int set_igmp_proxy_enable(char *refparam, struct dmctx *ctx, int action, char *v return 0; } -int get_igmp_maxgroup(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_max_groups", value); return 0; } -int set_igmp_maxgroup(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_maxgroup(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -297,13 +297,13 @@ int set_igmp_maxgroup(char *refparam, struct dmctx *ctx, int action, char *value return 0; } -int get_igmp_maxsources(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_max_sources", value); return 0; } -int set_igmp_maxsources(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_maxsources(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -315,13 +315,13 @@ int set_igmp_maxsources(char *refparam, struct dmctx *ctx, int action, char *val return 0; } -int get_igmp_maxmembers(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_max_members", value); return 0; } -int set_igmp_maxmembers(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_maxmembers(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -333,13 +333,13 @@ int set_igmp_maxmembers(char *refparam, struct dmctx *ctx, int action, char *val return 0; } -int get_igmp_snooping_mode(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("mcpd", "mcpd", "igmp_snooping_enable", value); return 0; } -int set_igmp_snooping_mode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_snooping_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -351,7 +351,7 @@ int set_igmp_snooping_mode(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, char **value) +int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *p; @@ -365,7 +365,7 @@ int get_igmp_snooping_interface(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int i; char *p; @@ -389,27 +389,22 @@ int set_igmp_snooping_interface(char *refparam, struct dmctx *ctx, int action, c return 0; } -int entry_method_root_X_INTENO_SE_IGMP(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_IGMP.") { - DMOBJECT(DMROOT"X_INTENO_SE_IGMP.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("DifferentiateService", ctx, "1", get_igmp_dscp_mark, set_igmp_dscp_mark, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ProxyInterface", ctx, "1", get_igmp_proxy_interface, set_igmp_proxy_interface, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DefaultVersion", ctx, "1", get_igmp_default_version, set_igmp_default_version, NULL, 0, 1, UNDEF, NULL); - DMPARAM("QueryInterval", ctx, "1", get_igmp_query_interval, set_igmp_query_interval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("QueryResponseInterval", ctx, "1", get_igmp_query_response_interval, set_igmp_query_response_interval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("LastMemberQueryInterval", ctx, "1", get_igmp_last_member_queryinterval, set_igmp_last_member_queryinterval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RobustnessValue", ctx, "1", get_igmp_robustness_value, set_igmp_robustness_value, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("LanToLanMulticastEnable", ctx, "1", get_igmp_multicast_enable, set_igmp_multicast_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("MaxGroup", ctx, "1", get_igmp_maxgroup, set_igmp_maxgroup, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaxSources", ctx, "1", get_igmp_maxsources, set_igmp_maxsources, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaxMembers", ctx, "1", get_igmp_maxmembers, set_igmp_maxmembers, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("FastLeaveEnable", ctx, "1", get_igmp_fastleave_enable, set_igmp_fastleave_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("JoinImmediateEnable", ctx, "1", get_igmp_joinimmediate_enable, set_igmp_joinimmediate_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ProxyEnable", ctx, "1", get_igmp_proxy_enable, set_igmp_proxy_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("SnoopingMode", ctx, "1", get_igmp_snooping_mode, set_igmp_snooping_mode, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SnoopingInterfaces", ctx, "1", get_igmp_snooping_interface, set_igmp_snooping_interface, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} +DMLEAF tSe_IgmpParam[] = { +{"DifferentiateService", &DMWRITE, DMT_STRING, get_igmp_dscp_mark, set_igmp_dscp_mark, NULL, NULL}, +{"ProxyInterface", &DMWRITE, DMT_STRING, get_igmp_proxy_interface, set_igmp_proxy_interface, NULL, NULL}, +{"DefaultVersion", &DMWRITE, DMT_STRING, get_igmp_default_version, set_igmp_default_version, NULL, NULL}, +{"QueryInterval", &DMWRITE, DMT_UNINT, get_igmp_query_interval, set_igmp_query_interval, NULL, NULL}, +{"QueryResponseInterval", &DMWRITE, DMT_UNINT, get_igmp_query_response_interval, set_igmp_query_response_interval, NULL, NULL}, +{"LastMemberQueryInterval", &DMWRITE, DMT_UNINT, get_igmp_last_member_queryinterval, set_igmp_last_member_queryinterval, NULL, NULL}, +{"RobustnessValue", &DMWRITE, DMT_INT, get_igmp_robustness_value, set_igmp_robustness_value, NULL, NULL}, +{"LanToLanMulticastEnable", &DMWRITE, DMT_BOOL, get_igmp_multicast_enable, set_igmp_multicast_enable, NULL, NULL}, +{"MaxGroup", &DMWRITE, DMT_UNINT, get_igmp_maxgroup, set_igmp_maxgroup, NULL, NULL}, +{"MaxSources", &DMWRITE, DMT_UNINT, get_igmp_maxsources, set_igmp_maxsources, NULL, NULL}, +{"MaxMembers", &DMWRITE, DMT_UNINT, get_igmp_maxmembers, set_igmp_maxmembers, NULL, NULL}, +{"FastLeaveEnable", &DMWRITE, DMT_BOOL, get_igmp_fastleave_enable, set_igmp_fastleave_enable, NULL, NULL}, +{"JoinImmediateEnable", &DMWRITE, DMT_BOOL, get_igmp_joinimmediate_enable, set_igmp_joinimmediate_enable, NULL, NULL}, +{"ProxyEnable", &DMWRITE, DMT_BOOL, get_igmp_proxy_enable, set_igmp_proxy_enable, NULL, NULL}, +{"SnoopingMode", &DMWRITE, DMT_STRING, get_igmp_snooping_mode, set_igmp_snooping_mode, NULL, NULL}, +{"SnoopingInterfaces", &DMWRITE, DMT_STRING, get_igmp_snooping_interface, set_igmp_snooping_interface, NULL, NULL}, +{0} +}; diff --git a/dm/dmtree/common/x_inteno_se_igmp.h b/dm/dmtree/common/x_inteno_se_igmp.h index 7970813..e962e9f 100644 --- a/dm/dmtree/common/x_inteno_se_igmp.h +++ b/dm/dmtree/common/x_inteno_se_igmp.h @@ -1,6 +1,6 @@ #ifndef __SE_IGMP_H #define __SE_IGMP_H -int entry_method_root_X_INTENO_SE_IGMP(struct dmctx *ctx); +extern DMLEAF tSe_IgmpParam[]; #endif \ No newline at end of file diff --git a/dm/dmtree/common/x_inteno_se_ipacccfg.c b/dm/dmtree/common/x_inteno_se_ipacccfg.c index ff59ffc..e966b50 100644 --- a/dm/dmtree/common/x_inteno_se_ipacccfg.c +++ b/dm/dmtree/common/x_inteno_se_ipacccfg.c @@ -18,49 +18,65 @@ #include "dmcommon.h" #include "x_inteno_se_ipacccfg.h" -struct ipaccargs cur_ipaccargs = {0}; -struct pforwardrgs cur_pforwardrgs = {0}; +/*** DMROOT.X_INTENO_SE_IpAccCfg. ***/ +DMOBJ tSe_IpAccObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"X_INTENO_SE_IpAccListCfgObj", &DMWRITE, add_ipacccfg_rule, delete_ipacccfg_rule, NULL, browseAccListInst, NULL, NULL, NULL, tSe_IpAccCfgParam, NULL}, +{"X_INTENO_SE_PortForwarding", &DMWRITE, add_ipacccfg_port_forwarding, delete_ipacccfg_port_forwarding, NULL, browseport_forwardingInst, NULL, NULL, NULL, tSe_PortForwardingParam, NULL}, +{0} +}; + +DMLEAF tSe_PortForwardingParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_port_forwarding_alias, set_port_forwarding_alias, NULL, NULL}, +{"Name", &DMWRITE, DMT_STRING, get_port_forwarding_name, set_port_forwarding_name, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_port_forwarding_enable, set_port_forwarding_enable, NULL, NULL}, +{"EnalbeNatLoopback", &DMWRITE, DMT_BOOL, get_port_forwarding_loopback, set_port_forwarding_loopback, NULL, NULL}, +{"Protocol", &DMWRITE, DMT_STRING, get_port_forwarding_protocol, set_port_forwarding_protocol, NULL, NULL}, +{"ExternalZone", &DMWRITE, DMT_STRING, get_port_forwarding_external_zone, set_port_forwarding_external_zone, NULL, NULL}, +{"InternalZone", &DMWRITE, DMT_STRING, get_port_forwarding_internal_zone, set_port_forwarding_internal_zone, NULL, NULL}, +{"ExternalPort", &DMWRITE, DMT_STRING, get_port_forwarding_external_port, set_port_forwarding_external_port, NULL, NULL}, +{"InternalPort", &DMWRITE, DMT_STRING, get_port_forwarding_internal_port, set_port_forwarding_internal_port, NULL, NULL}, +{"SourcePort", &DMWRITE, DMT_STRING, get_port_forwarding_source_port, set_port_forwarding_source_port, NULL, NULL}, +{"InternalIpAddress", &DMWRITE, DMT_STRING, get_port_forwarding_internal_ipaddress, set_port_forwarding_internal_ipaddress, NULL, NULL}, +{"ExternalIpAddress", &DMWRITE, DMT_STRING, get_port_forwarding_external_ipaddress, set_port_forwarding_external_ipaddress, NULL, NULL}, +{"SourceIpAddress", &DMWRITE, DMT_STRING, get_port_forwarding_source_ipaddress, set_port_forwarding_source_ipaddress, NULL, NULL}, +{"SourceMacAddress", &DMWRITE, DMT_STRING, get_port_forwarding_src_mac, set_port_forwarding_src_mac, NULL, NULL}, +{0} +}; + +DMLEAF tSe_IpAccCfgParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_x_inteno_cfgobj_address_alias, set_x_inteno_cfgobj_address_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_x_bcm_com_ip_acc_list_cfgobj_enable, set_x_bcm_com_ip_acc_list_cfgobj_enable, NULL, NULL}, +{"IPVersion", &DMWRITE, DMT_STRING, get_x_bcm_com_ip_acc_list_cfgobj_ipversion, set_x_bcm_com_ip_acc_list_cfgobj_ipversion, NULL, NULL}, +{"Protocol", &DMWRITE, DMT_STRING, get_x_bcm_com_ip_acc_list_cfgobj_protocol, set_x_bcm_com_ip_acc_list_cfgobj_protocol, NULL, NULL}, +{"FilterName", &DMWRITE, DMT_STRING, get_x_bcm_com_ip_acc_list_cfgobj_name, set_x_bcm_com_ip_acc_list_cfgobj_name, NULL, NULL}, +{"AccAddressAndNetMask", &DMWRITE, DMT_STRING, get_x_inteno_cfgobj_address_netmask, set_x_inteno_cfgobj_address_netmask, NULL, NULL}, +{"AccPort", &DMWRITE, DMT_STRING, get_x_bcm_com_ip_acc_list_cfgobj_acc_port, set_x_bcm_com_ip_acc_list_cfgobj_acc_port, NULL, NULL}, +{0} +}; -inline int entry_xinteno_ipacccfg_listcfgobj(struct dmctx *ctx); -inline int entry_xinteno_ipacccfg_portforwarding(struct dmctx *ctx); -inline int entry_xinteno_ipacccfg_portforwarding_instance(struct dmctx *ctx, char *iforward); -inline int entry_xinteno_ipacccfg_listcfgobj_instance(struct dmctx *ctx, char *irule); -inline int init_args_ipacc(struct dmctx *ctx, struct uci_section *s) -{ - struct ipaccargs *args = &cur_ipaccargs; - ctx->args = (void *)args; - args->ipaccsection = s; - return 0; -} -inline int init_args_pforward(struct dmctx *ctx, struct uci_section *s) -{ - struct pforwardrgs *args = &cur_pforwardrgs; - ctx->args = (void *)args; - args->forwardsection = s; - return 0; -} /************************************************************************************* **** function related to get_object_ip_acc_list_cfgobj **** **************************************************************************************/ -int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, char **value) +int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(accargs->ipaccsection, "enabled", value); + dmuci_get_value_by_section_string(ipaccsection, "enabled", value); if ((*value)[0] == '\0') { *value = "1"; } return 0; } -int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; int check; - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -75,86 +91,86 @@ int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, i else { value = "0"; } - dmuci_set_value_by_section(accargs->ipaccsection, "enabled", value); + dmuci_set_value_by_section(ipaccsection, "enabled", value); return 0; } return 0; } -int get_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, char **value) +int get_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(accargs->ipaccsection, "family", value); + dmuci_get_value_by_section_string(ipaccsection, "family", value); return 0; } -int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(accargs->ipaccsection, "family", value); + dmuci_set_value_by_section(ipaccsection, "family", value); return 0; } return 0; } -int get_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, char **value) +int get_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(accargs->ipaccsection, "proto", value); + dmuci_get_value_by_section_string(ipaccsection, "proto", value); return 0; } -int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(accargs->ipaccsection, "proto", value); + dmuci_set_value_by_section(ipaccsection, "proto", value); return 0; } return 0; } -int get_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, char **value) +int get_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(accargs->ipaccsection, "name", value); + dmuci_get_value_by_section_string(ipaccsection, "name", value); return 0; } -int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(accargs->ipaccsection, "name", value); + dmuci_set_value_by_section(ipaccsection, "name", value); return 0; } return 0; } -int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_list *val; struct uci_element *e = NULL; - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; struct uci_list *list = NULL; - dmuci_get_value_by_section_list(accargs->ipaccsection, "src_ip", &val); + dmuci_get_value_by_section_list(ipaccsection, "src_ip", &val); if (val) { *value = dmuci_list_to_string(val, ","); } @@ -167,20 +183,20 @@ int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, char return 0; } -int set_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch, *spch, *val; - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_delete_by_section(accargs->ipaccsection, "src_ip", ""); + dmuci_delete_by_section(ipaccsection, "src_ip", ""); val = dmstrdup(value); pch = strtok_r(val, " ,", &spch); while (pch != NULL) { - dmuci_add_list_value_by_section(accargs->ipaccsection, "src_ip", pch); + dmuci_add_list_value_by_section(ipaccsection, "src_ip", pch); pch = strtok_r(NULL, " ,", &spch); } dmfree(val); @@ -189,23 +205,23 @@ int set_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, int a return 0; } -int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, char **value) +int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(accargs->ipaccsection, "dest_port", value); + dmuci_get_value_by_section_string(ipaccsection, "dest_port", value); return 0; } -int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; + struct uci_section *ipaccsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(accargs->ipaccsection, "dest_port", value); + dmuci_set_value_by_section(ipaccsection, "dest_port", value); return 0; } return 0; @@ -217,41 +233,41 @@ int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, **** function related to get_cache_object_port_forwarding **** **************************************************************************************/ -int get_port_forwarding_name(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "name", value); + dmuci_get_value_by_section_string(forwardsection, "name", value); return 0; } -int set_port_forwarding_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(forwardargs->forwardsection, "name", value); + dmuci_set_value_by_section(forwardsection, "name", value); return 0; } return 0; } -int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "enabled", value); + dmuci_get_value_by_section_string(forwardsection, "enabled", value); return 0; } -int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; int check; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -261,29 +277,29 @@ int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, int action, ch case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(forwardargs->forwardsection, "enabled", "1"); + dmuci_set_value_by_section(forwardsection, "enabled", "1"); else - dmuci_set_value_by_section(forwardargs->forwardsection, "enabled", "0"); + dmuci_set_value_by_section(forwardsection, "enabled", "0"); return 0; } return 0; } -int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "reflection", value); + dmuci_get_value_by_section_string(forwardsection, "reflection", value); if((*value)[0] == '\0') { *value = "1"; } return 0; } -int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -293,121 +309,121 @@ int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, int action, case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(forwardargs->forwardsection, "reflection", "1"); + dmuci_set_value_by_section(forwardsection, "reflection", "1"); else - dmuci_set_value_by_section(forwardargs->forwardsection, "reflection", "0"); + dmuci_set_value_by_section(forwardsection, "reflection", "0"); return 0; } return 0; } -int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "proto", value); + dmuci_get_value_by_section_string(forwardsection, "proto", value); return 0; } -int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(forwardargs->forwardsection, "proto", value); + dmuci_set_value_by_section(forwardsection, "proto", value); return 0; } return 0; } -int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "src", value); + dmuci_get_value_by_section_string(forwardsection, "src", value); return 0; } -int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(forwardargs->forwardsection, "src", value); + dmuci_set_value_by_section(forwardsection, "src", value); return 0; } return 0; } -int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "dest", value); + dmuci_get_value_by_section_string(forwardsection, "dest", value); return 0; } -int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(forwardargs->forwardsection, "dest", value); + dmuci_set_value_by_section(forwardsection, "dest", value); return 0; } return 0; } -int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_dport", value); + dmuci_get_value_by_section_string(forwardsection, "src_dport", value); return 0; } -int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(forwardargs->forwardsection, "src_dport", value); + dmuci_set_value_by_section(forwardsection, "src_dport", value); return 0; } return 0; } -int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "dest_port", value); + dmuci_get_value_by_section_string(forwardsection, "dest_port", value); if ((*value)[0] == '\0') { *value = "any"; } return 0; } -int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -416,27 +432,27 @@ int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, int act if (strcasecmp(value, "any") == 0) { value = ""; } - dmuci_set_value_by_section(forwardargs->forwardsection, "dest_port", value); + dmuci_set_value_by_section(forwardsection, "dest_port", value); return 0; } return 0; } -int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_port", value); + dmuci_get_value_by_section_string(forwardsection, "src_port", value); if ((*value)[0] == '\0') { *value = "any"; } return 0; } -int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -445,50 +461,50 @@ int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, int actio if (strcasecmp(value, "any") == 0) { value = ""; } - dmuci_set_value_by_section(forwardargs->forwardsection, "src_port", value); + dmuci_set_value_by_section(forwardsection, "src_port", value); return 0; } return 0; } -int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "dest_ip", value); + dmuci_get_value_by_section_string(forwardsection, "dest_ip", value); return 0; } -int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(forwardargs->forwardsection, "dest_ip", value); + dmuci_set_value_by_section(forwardsection, "dest_ip", value); return 0; } return 0; } -int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(forwardargs->forwardsection, "src_dip", value); + dmuci_get_value_by_section_string(forwardsection, "src_dip", value); if ((*value)[0] == '\0') { *value = "any"; } return 0; } -int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -497,19 +513,19 @@ int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, in if (strcasecmp(value, "any") == 0) { value = ""; } - dmuci_set_value_by_section(forwardargs->forwardsection, "src_dip", value); + dmuci_set_value_by_section(forwardsection, "src_dip", value); return 0; } return 0; } -int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_list *val; struct uci_element *e = NULL; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_list(forwardargs->forwardsection, "src_ip", &val); + dmuci_get_value_by_section_list(forwardsection, "src_ip", &val); if (val) { *value = dmuci_list_to_string(val, ","); } @@ -522,24 +538,24 @@ int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, char return 0; } -int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch, *val, *spch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: if (strcasecmp(value, "any") == 0) { - dmuci_delete_by_section(forwardargs->forwardsection, "src_ip", ""); + dmuci_delete_by_section(forwardsection, "src_ip", ""); } else { - dmuci_delete_by_section(forwardargs->forwardsection, "src_ip", ""); + dmuci_delete_by_section(forwardsection, "src_ip", ""); val = dmstrdup(value); pch = strtok_r(val, " ,", &spch); while (pch != NULL) { - dmuci_add_list_value_by_section(forwardargs->forwardsection, "src_ip", pch); + dmuci_add_list_value_by_section(forwardsection, "src_ip", pch); pch = strtok_r(NULL, " ,", &spch); } dmfree(val); @@ -549,30 +565,30 @@ int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, int return 0; } -int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_list *list = NULL; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; - dmuci_get_value_by_section_list(forwardargs->forwardsection, "src_mac", &list); + dmuci_get_value_by_section_list(forwardsection, "src_mac", &list); *value = dmuci_list_to_string(list, " "); return 0; } -int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch, *spch; - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_delete_by_section(forwardargs->forwardsection, "src_mac", NULL); + dmuci_delete_by_section(forwardsection, "src_mac", NULL); value = dmstrdup(value); pch = strtok_r(value, " ", &spch); while (pch != NULL) { - dmuci_add_list_value_by_section(forwardargs->forwardsection, "src_mac", pch); + dmuci_add_list_value_by_section(forwardsection, "src_mac", pch); pch = strtok_r(NULL, " ", &spch); } dmfree(value); @@ -582,49 +598,7 @@ int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, int action, c } /***** ADD DEL OBJ *******/ -int add_ipacccfg_port_forwarding(struct dmctx *ctx, char **instancepara) -{ - char *value; - char *instance; - struct uci_section *redirect = NULL; - - instance = get_last_instance_lev2("firewall", "redirect", "forwardinstance", "target", "DNAT"); - dmuci_add_section("firewall", "redirect", &redirect, &value); - dmuci_set_value_by_section(redirect, "enabled", "0"); - dmuci_set_value_by_section(redirect, "target", "DNAT"); - dmuci_set_value_by_section(redirect, "proto", "tcp udp"); - *instancepara = update_instance(redirect, instance, "forwardinstance"); - return 0; -} - - -int delete_ipacccfg_port_forwarding_all(struct dmctx *ctx) -{ - struct uci_section *s = NULL; - struct uci_section *ss = NULL; - int found = 0; - - uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { - if (found != 0) - dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; - } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - return 0; -} - - -int delete_ipacccfg_port_forwarding_instance(struct dmctx *ctx) -{ - struct pforwardrgs *forwardargs = (struct pforwardrgs *)ctx->args; - - dmuci_delete_by_section(forwardargs->forwardsection, NULL, NULL); - return 0; -} - -int add_ipacccfg_rule(struct dmctx *ctx, char **instancepara) +int add_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char *instance; @@ -644,143 +618,136 @@ int add_ipacccfg_rule(struct dmctx *ctx, char **instancepara) return 0; } -int delete_ipacccfg_rule_all(struct dmctx *ctx) +int delete_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL; struct uci_section *ss = NULL; int found = 0; - - uci_foreach_sections("firewall", "rule", s) { - if (found != 0) - dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; + struct uci_section *ipaccsection = (struct uci_section *)data; + + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(ipaccsection, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("firewall", "rule", s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + break; } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); return 0; } -int delete_ipacccfg_rule_instance(struct dmctx *ctx) -{ - struct ipaccargs *accargs = (struct ipaccargs *)ctx->args; +int add_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *value; + char *instance; + struct uci_section *redirect = NULL; + + instance = get_last_instance_lev2("firewall", "redirect", "forwardinstance", "target", "DNAT"); + dmuci_add_section("firewall", "redirect", &redirect, &value); + dmuci_set_value_by_section(redirect, "enabled", "0"); + dmuci_set_value_by_section(redirect, "target", "DNAT"); + dmuci_set_value_by_section(redirect, "proto", "tcp udp"); + *instancepara = update_instance(redirect, instance, "forwardinstance"); + return 0; +} - dmuci_delete_by_section(accargs->ipaccsection, NULL, NULL); + +int delete_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + int found = 0; + struct pforwardrgs *forwardargs; + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + struct uci_section *forwardsection = (struct uci_section *)data; + + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(forwardsection, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + break; + } return 0; } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_inteno_cfgobj_address_alias(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ipaccargs.ipaccsection, "frulealias", value); + struct uci_section *ipaccsection = (struct uci_section *)data; + dmuci_get_value_by_section_string(ipaccsection, "frulealias", value); return 0; } -int set_x_inteno_cfgobj_address_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *ipaccsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ipaccargs.ipaccsection, "frulealias", value); + dmuci_set_value_by_section(ipaccsection, "frulealias", value); return 0; } return 0; } -int get_port_forwarding_alias(char *refparam, struct dmctx *ctx, char **value) +int get_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_pforwardrgs.forwardsection, "forwardalias", value); + struct uci_section *forwardsection = (struct uci_section *)data; + dmuci_get_value_by_section_string(forwardsection, "forwardalias", value); return 0; } -int set_port_forwarding_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *forwardsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_pforwardrgs.forwardsection, "forwardalias", value); + dmuci_set_value_by_section(forwardsection, "forwardalias", value); return 0; } return 0; } -/////////////SUB ENTRIES/////////////// -inline int entry_xinteno_ipacccfg_listcfgobj(struct dmctx *ctx) +int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *irule = NULL, *irule_last = NULL; struct uci_section *s = NULL; uci_foreach_sections("firewall", "rule", s) { - init_args_ipacc(ctx, s); - irule = handle_update_instance(1, ctx, &irule_last, update_instance_alias, 3, s, "fruleinstance", "frulealias"); - SUBENTRY(entry_xinteno_ipacccfg_listcfgobj_instance, ctx, irule); + irule = handle_update_instance(1, dmctx, &irule_last, update_instance_alias, 3, s, "fruleinstance", "frulealias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, irule) == DM_STOP) + break; } return 0; } -inline int entry_xinteno_ipacccfg_portforwarding(struct dmctx *ctx) +int browseport_forwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *iforward = NULL, *iforward_last = NULL; struct uci_section *s = NULL; uci_foreach_option_eq("firewall", "redirect", "target", "DNAT", s) { - init_args_pforward(ctx, s); - iforward = handle_update_instance(1, ctx, &iforward_last, update_instance_alias, 3, s, "forwardinstance", "forwardalias"); - SUBENTRY(entry_xinteno_ipacccfg_portforwarding_instance, ctx, iforward); + iforward = handle_update_instance(1, dmctx, &iforward_last, update_instance_alias, 3, s, "forwardinstance", "forwardalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, iforward) == DM_STOP) + break; } return 0; } -////////////////////////////////////// -int entry_method_root_X_INTENO_SE_IpAccCfg(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_IpAccCfg.") { - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.", ctx, "1", 1, add_ipacccfg_rule, delete_ipacccfg_rule_all, NULL); - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.", ctx, "1", 1, add_ipacccfg_port_forwarding, delete_ipacccfg_port_forwarding_all, NULL); - SUBENTRY(entry_xinteno_ipacccfg_listcfgobj, ctx); - SUBENTRY(entry_xinteno_ipacccfg_portforwarding, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_xinteno_ipacccfg_listcfgobj_instance(struct dmctx *ctx, char *irule) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.%s.", irule) { - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.%s.", ctx, "1", 1, NULL, delete_ipacccfg_rule_instance, NULL, irule); - DMPARAM("Alias", ctx, "1", get_x_inteno_cfgobj_address_alias, set_x_inteno_cfgobj_address_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_x_bcm_com_ip_acc_list_cfgobj_enable, set_x_bcm_com_ip_acc_list_cfgobj_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("IPVersion", ctx, "1", get_x_bcm_com_ip_acc_list_cfgobj_ipversion, set_x_bcm_com_ip_acc_list_cfgobj_ipversion, "xsd:string", 0, 1, UNDEF, NULL); - DMPARAM("Protocol", ctx, "1", get_x_bcm_com_ip_acc_list_cfgobj_protocol, set_x_bcm_com_ip_acc_list_cfgobj_protocol, "xsd:string", 0, 1, UNDEF, NULL); - DMPARAM("FilterName", ctx, "1", get_x_bcm_com_ip_acc_list_cfgobj_name, set_x_bcm_com_ip_acc_list_cfgobj_name, "xsd:string", 0, 1, UNDEF, NULL); - DMPARAM("AccAddressAndNetMask", ctx, "1", get_x_inteno_cfgobj_address_netmask, set_x_inteno_cfgobj_address_netmask, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AccPort", ctx, "1", get_x_bcm_com_ip_acc_list_cfgobj_acc_port, set_x_bcm_com_ip_acc_list_cfgobj_acc_port, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_xinteno_ipacccfg_portforwarding_instance(struct dmctx *ctx, char *iforward) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", iforward) { - DMOBJECT(DMROOT"X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.%s.", ctx, "0", 1, NULL, delete_ipacccfg_port_forwarding_instance, NULL, iforward); - DMPARAM("Alias", ctx, "1", get_port_forwarding_alias, set_port_forwarding_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "1", get_port_forwarding_name, set_port_forwarding_name, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_port_forwarding_enable, set_port_forwarding_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("EnalbeNatLoopback", ctx, "1", get_port_forwarding_loopback, set_port_forwarding_loopback, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Protocol", ctx, "1", get_port_forwarding_protocol, set_port_forwarding_protocol, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalZone", ctx, "1", get_port_forwarding_external_zone, set_port_forwarding_external_zone, NULL, 0, 1, UNDEF, NULL); - DMPARAM("InternalZone", ctx, "1", get_port_forwarding_internal_zone, set_port_forwarding_internal_zone, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalPort", ctx, "1", get_port_forwarding_external_port, set_port_forwarding_external_port, NULL, 0, 1, UNDEF, NULL); - DMPARAM("InternalPort", ctx, "1", get_port_forwarding_internal_port, set_port_forwarding_internal_port, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourcePort", ctx, "1", get_port_forwarding_source_port, set_port_forwarding_source_port, NULL, 0, 1, UNDEF, NULL); - DMPARAM("InternalIpAddress", ctx, "1", get_port_forwarding_internal_ipaddress, set_port_forwarding_internal_ipaddress, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalIpAddress", ctx, "1", get_port_forwarding_external_ipaddress, set_port_forwarding_external_ipaddress, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceIpAddress", ctx, "1", get_port_forwarding_source_ipaddress, set_port_forwarding_source_ipaddress, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceMacAddress", ctx, "1", get_port_forwarding_src_mac, set_port_forwarding_src_mac, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/x_inteno_se_ipacccfg.h b/dm/dmtree/common/x_inteno_se_ipacccfg.h index f7edfc3..d6452de 100644 --- a/dm/dmtree/common/x_inteno_se_ipacccfg.h +++ b/dm/dmtree/common/x_inteno_se_ipacccfg.h @@ -1,15 +1,61 @@ #ifndef __SE_IPACCCFG_H #define __SE_IPACCCFG_H -struct ipaccargs -{ - struct uci_section *ipaccsection; -}; +extern DMOBJ tSe_IpAccObj[]; +extern DMLEAF tSe_IpAccCfgParam[]; +extern DMLEAF tSe_PortForwardingParam[]; -struct pforwardrgs -{ - struct uci_section *forwardsection; -}; +int browseport_forwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseAccListInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int entry_method_root_X_INTENO_SE_IpAccCfg(struct dmctx *ctx); -#endif \ No newline at end of file +int add_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_ipacccfg_port_forwarding(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +int add_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_ipacccfg_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +int get_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_port_forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_loopback(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_external_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_internal_zone(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_source_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_internal_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_external_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_source_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_forwarding_src_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_inteno_cfgobj_address_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_com_ip_acc_list_cfgobj_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_com_ip_acc_list_cfgobj_ipversion(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_com_ip_acc_list_cfgobj_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_com_ip_acc_list_cfgobj_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_inteno_cfgobj_address_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_com_ip_acc_list_cfgobj_acc_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/common/x_inteno_se_logincfg.c b/dm/dmtree/common/x_inteno_se_logincfg.c index 49c0523..7cca379 100644 --- a/dm/dmtree/common/x_inteno_se_logincfg.c +++ b/dm/dmtree/common/x_inteno_se_logincfg.c @@ -16,6 +16,15 @@ #include "dmcommon.h" #include "x_inteno_se_logincfg.h" + +DMLEAF tSe_LoginCfgParam[] = { +{"AdminPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_admin_password, NULL, NULL}, +{"SupportPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_support_password, NULL, NULL}, +{"UserPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_user_password, NULL, NULL}, +{"RootPassword", &DMWRITE, DMT_STRING, get_empty, set_x_bcm_root_password, NULL, NULL}, +{0} +}; + int set_x_bcm_password(char *refparam, struct dmctx *ctx, int action, char *value, char *user_type) { switch (action) { @@ -28,39 +37,26 @@ int set_x_bcm_password(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int set_x_bcm_admin_password(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_admin_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "admin"); return 0; } -int set_x_bcm_support_password(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_support_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "support"); return 0; } -int set_x_bcm_user_password(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "user"); return 0; } -int set_x_bcm_root_password(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_bcm_root_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { set_x_bcm_password(refparam, ctx, action, value, "root"); return 0; } - -int entry_method_root_X_INTENO_SE_LOGIN_CFG(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_LoginCfg.") { - DMOBJECT(DMROOT"X_INTENO_SE_LoginCfg.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("AdminPassword", ctx, "1", get_empty, set_x_bcm_admin_password, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SupportPassword", ctx, "1", get_empty, set_x_bcm_support_password, NULL, 0, 1, UNDEF, NULL); - DMPARAM("UserPassword", ctx, "1", get_empty, set_x_bcm_user_password, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RootPassword", ctx, "1", get_empty, set_x_bcm_root_password, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} \ No newline at end of file diff --git a/dm/dmtree/common/x_inteno_se_logincfg.h b/dm/dmtree/common/x_inteno_se_logincfg.h index dae3748..02682c0 100644 --- a/dm/dmtree/common/x_inteno_se_logincfg.h +++ b/dm/dmtree/common/x_inteno_se_logincfg.h @@ -1,6 +1,11 @@ #ifndef __SE_LOGINCFG_H #define __SE_LOGINCFG_H -int entry_method_root_X_INTENO_SE_LOGIN_CFG(struct dmctx *ctx); +extern DMLEAF tSe_LoginCfgParam[]; -#endif \ No newline at end of file +int set_x_bcm_admin_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_support_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_user_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_bcm_root_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/common/x_inteno_se_owsd.c b/dm/dmtree/common/x_inteno_se_owsd.c index 2a8da6c..9ebfc65 100644 --- a/dm/dmtree/common/x_inteno_se_owsd.c +++ b/dm/dmtree/common/x_inteno_se_owsd.c @@ -19,28 +19,54 @@ #include "dmentry.h" #include "x_inteno_se_owsd.h" -struct owsd_listenargs cur_owsd_listenargs = {0}; -inline int entry_xinteno_owsd_listenobj_instance(struct dmctx *ctx, char *iowsd_listen); -inline int entry_xinteno_owsd_listenobj(struct dmctx *ctx); +DMLEAF XIntenoSeOwsdParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"Socket", &DMWRITE, DMT_STRING, get_x_inteno_owsd_global_sock, set_x_inteno_owsd_global_sock, NULL, NULL}, +{"Redirect", &DMWRITE, DMT_STRING, get_x_inteno_owsd_global_redirect, set_x_inteno_owsd_global_redirect, NULL, NULL}, +{0} +}; -inline int init_args_owsd_listen(struct dmctx *ctx, struct uci_section *s) +DMOBJ XIntenoSeOwsdObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf*/ +{"X_INTENO_SE_ListenObj", &DMWRITE, add_owsd_listen, delete_owsd_listen_instance, NULL, browseXIntenoOwsdListenObj, NULL, NULL, NULL, X_INTENO_SE_ListenObjParams, NULL}, +{0} +}; + +DMLEAF X_INTENO_SE_ListenObjParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_x_inteno_owsd_listenobj_alias, set_x_inteno_owsd_listenobj_alias, NULL, NULL}, +{"Port", &DMWRITE, DMT_UNINT, get_x_inteno_owsd_listenobj_port, set_x_inteno_owsd_listenobj_alias, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_x_inteno_owsd_listenobj_interface, set_x_inteno_owsd_listenobj_interface, NULL, NULL}, +{"Ipv6", &DMWRITE, DMT_BOOL, get_x_inteno_owsd_listenobj_ipv6_enable, set_x_inteno_owsd_listenobj_ipv6_enable, NULL, NULL}, +{"Whitelist_interface", &DMWRITE, DMT_BOOL, get_x_inteno_owsd_listenobj_whitelist_interface, set_x_inteno_owsd_listenobj_whitelist_interface, NULL, NULL}, +{"Whitelist_dhcp", &DMWRITE, DMT_BOOL, get_x_inteno_owsd_listenobj_whitelist_dhcp, set_x_inteno_owsd_listenobj_whitelist_dhcp, NULL, NULL}, +{"Origin", &DMWRITE, DMT_STRING, get_x_inteno_owsd_listenobj_origin, set_x_inteno_owsd_listenobj_origin, NULL, NULL}, +{0} +}; + +int browseXIntenoOwsdListenObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - struct owsd_listenargs *args = &cur_owsd_listenargs; - ctx->args = (void *)args; - args->owsd_listensection = s; + char *iowsd_listen = NULL, *iowsd_listen_last = NULL; + struct uci_section *s = NULL; + + uci_foreach_sections("owsd", "owsd-listen", s) { + iowsd_listen = handle_update_instance(1, dmctx, &iowsd_listen_last, update_instance_alias, 3, s, "olisteninstance", "olistenalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, iowsd_listen) == DM_STOP) + break; + } return 0; } /************************************************************************************* **** function related to owsd_origin **** **************************************************************************************/ -int get_x_inteno_owsd_global_sock(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd", "global", "sock", value); return 0; } -int set_x_inteno_owsd_global_sock(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -52,13 +78,13 @@ int set_x_inteno_owsd_global_sock(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_x_inteno_owsd_global_redirect(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("owsd", "global", "redirect", value); return 0; } -int set_x_inteno_owsd_global_redirect(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -74,39 +100,42 @@ int set_x_inteno_owsd_global_redirect(char *refparam, struct dmctx *ctx, int act **** function related to owsd_listenobj **** **************************************************************************************/ -int get_x_inteno_owsd_listenobj_port(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_owsd_listenargs.owsd_listensection, "port", value); + struct uci_section *owsd_listensection = (struct uci_section *)data; + dmuci_get_value_by_section_string(owsd_listensection, "port", value); if ((*value)[0] == '\0') { *value = ""; } return 0; } -int set_x_inteno_owsd_listenobj_port(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *owsd_listensection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "port", value); + dmuci_set_value_by_section(owsd_listensection, "port", value); return 0; } return 0; } -int get_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface, *linker; + struct uci_section *owsd_listensection = (struct uci_section *)data; - dmuci_get_value_by_section_string(cur_owsd_listenargs.owsd_listensection, "interface", &iface); + dmuci_get_value_by_section_string(owsd_listensection, "interface", &iface); #ifdef DATAMODEL_TR098 if (iface[0] != '\0') { dmastrcat(&linker, "linker_interface:", iface); - adm_entry_get_linker_param(DMROOT"WANDevice.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWANDevice%c", DMROOT, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) { - adm_entry_get_linker_param(DMROOT"LANDevice.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cLANDevice%c", DMROOT, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; } @@ -115,7 +144,7 @@ int get_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, cha #endif #ifdef DATAMODEL_TR181 if (iface[0] != '\0') { - adm_entry_get_linker_param(DMROOT"IP.Interface.", iface, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), iface, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; } @@ -123,21 +152,22 @@ int get_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, cha return 0; } -int set_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int check; char *linker, *iface; + struct uci_section *owsd_listensection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); + adm_entry_get_linker_value(ctx, value, &linker); if (linker) { #ifdef DATAMODEL_TR098 iface = linker + sizeof("linker_interface:") - 1; #endif - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "interface", iface); + dmuci_set_value_by_section(owsd_listensection, "interface", iface); dmfree(linker); } return 0; @@ -145,10 +175,11 @@ int set_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, int return 0; } -int get_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct uci_section *owsd_listensection = (struct uci_section *)data; - dmuci_get_value_by_section_string(cur_owsd_listenargs.owsd_listensection, "ipv6", value); + dmuci_get_value_by_section_string(owsd_listensection, "ipv6", value); if ((*value)[0] != '\0' && (*value)[0] == 'o' && (*value)[1] == 'n' ) { *value = "1"; } @@ -157,9 +188,10 @@ int get_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, c return 0; } -int set_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; + struct uci_section *owsd_listensection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -169,26 +201,28 @@ int set_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, i case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "ipv6", "on"); + dmuci_set_value_by_section(owsd_listensection, "ipv6", "on"); else - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "ipv6", "off"); + dmuci_set_value_by_section(owsd_listensection, "ipv6", "off"); return 0; } return 0; } -int get_x_inteno_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_owsd_listenargs.owsd_listensection, "whitelist_interface_as_origin", value); + struct uci_section *owsd_listensection = (struct uci_section *)data; + dmuci_get_value_by_section_string(owsd_listensection, "whitelist_interface_as_origin", value); if ((*value)[0] == '\0' ) { *value = "0"; } return 0; } -int set_x_inteno_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; + struct uci_section *owsd_listensection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -198,26 +232,28 @@ int set_x_inteno_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "whitelist_interface_as_origin", "1"); + dmuci_set_value_by_section(owsd_listensection, "whitelist_interface_as_origin", "1"); else - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "whitelist_interface_as_origin", "0"); + dmuci_set_value_by_section(owsd_listensection, "whitelist_interface_as_origin", "0"); return 0; } return 0; } -int get_x_inteno_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_owsd_listenargs.owsd_listensection, "whitelist_dhcp_domains", value); + struct uci_section *owsd_listensection = (struct uci_section *)data; + dmuci_get_value_by_section_string(owsd_listensection, "whitelist_dhcp_domains", value); if ((*value)[0] == '\0') { *value = "0"; } return 0; } -int set_x_inteno_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; + struct uci_section *owsd_listensection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -227,19 +263,20 @@ int set_x_inteno_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx case VALUESET: string_to_bool(value, &b); if(b) - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "whitelist_dhcp_domains", "1"); + dmuci_set_value_by_section(owsd_listensection, "whitelist_dhcp_domains", "1"); else - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "whitelist_dhcp_domains", "0"); + dmuci_set_value_by_section(owsd_listensection, "whitelist_dhcp_domains", "0"); return 0; } return 0; } -int get_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_list *val; + struct uci_section *owsd_listensection = (struct uci_section *)data; - dmuci_get_value_by_section_list(cur_owsd_listenargs.owsd_listensection, "origin", &val); + dmuci_get_value_by_section_list(owsd_listensection, "origin", &val); if (val) *value = dmuci_list_to_string(val, " "); else @@ -247,18 +284,19 @@ int get_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, char * return 0; } -int set_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch, *spch; + struct uci_section *owsd_listensection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_delete_by_section(cur_owsd_listenargs.owsd_listensection, "origin", NULL); + dmuci_delete_by_section(owsd_listensection, "origin", NULL); value = dmstrdup(value); pch = strtok_r(value, " ", &spch); while (pch != NULL) { - dmuci_add_list_value_by_section(cur_owsd_listenargs.owsd_listensection, "origin", pch); + dmuci_add_list_value_by_section(owsd_listensection, "origin", pch); pch = strtok_r(NULL, " ", &spch); } dmfree(value); @@ -268,26 +306,28 @@ int set_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, int ac } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_x_inteno_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_owsd_listenargs.owsd_listensection, "olistenalias", value); + struct uci_section *owsd_listensection = (struct uci_section *)data; + dmuci_get_value_by_section_string(owsd_listensection, "olistenalias", value); return 0; } -int set_x_inteno_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *owsd_listensection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_owsd_listenargs.owsd_listensection, "olistenalias", value); + dmuci_set_value_by_section(owsd_listensection, "olistenalias", value); return 0; } return 0; } /***** ADD DEL OBJ *******/ -int add_owsd_listen(struct dmctx *ctx, char **instancepara) +int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char *instance; @@ -303,71 +343,26 @@ int add_owsd_listen(struct dmctx *ctx, char **instancepara) return 0; } -int delete_owsd_listen_all(struct dmctx *ctx) +int delete_owsd_listen_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL; struct uci_section *ss = NULL; + struct uci_section *owsd_listensection = (struct uci_section *)data; int found = 0; - - uci_foreach_sections("owsd", "owsd-listen", s) { - if (found != 0) - dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; - } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - return 0; -} - - -int delete_owsd_listen_instance(struct dmctx *ctx) -{ - dmuci_delete_by_section(cur_owsd_listenargs.owsd_listensection, NULL, NULL); - return 0; -} -/////////////SUB ENTRIES/////////////// -inline int entry_xinteno_owsd_listenobj(struct dmctx *ctx) -{ - char *iowsd_listen = NULL, *iowsd_listen_last = NULL; - struct uci_section *s = NULL; - - uci_foreach_sections("owsd", "owsd-listen", s) { - init_args_owsd_listen(ctx, s); - iowsd_listen = handle_update_instance(1, ctx, &iowsd_listen_last, update_instance_alias, 3, s, "olisteninstance", "olistenalias"); - SUBENTRY(entry_xinteno_owsd_listenobj_instance, ctx, iowsd_listen); + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(owsd_listensection, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("owsd", "owsd-listen", s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + return 0; } return 0; } - -////////////////////////////////////// - -int entry_method_root_X_INTENO_SE_OWSD(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Owsd.") { - DMOBJECT(DMROOT"X_INTENO_SE_Owsd.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("Socket", ctx, "1", get_x_inteno_owsd_global_sock, set_x_inteno_owsd_global_sock, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Redirect", ctx, "1", get_x_inteno_owsd_global_redirect, set_x_inteno_owsd_global_redirect, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"X_INTENO_SE_Owsd.X_INTENO_SE_ListenObj.", ctx, "1", 1, add_owsd_listen, delete_owsd_listen_all, NULL); - SUBENTRY(entry_xinteno_owsd_listenobj, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_xinteno_owsd_listenobj_instance(struct dmctx *ctx, char *iowsd_listen) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Owsd.X_INTENO_SE_ListenObj.%s.", iowsd_listen) { - DMOBJECT(DMROOT"X_INTENO_SE_Owsd.X_INTENO_SE_ListenObj.%s.", ctx, "1", 1, NULL, delete_owsd_listen_instance, NULL, iowsd_listen); - DMPARAM("Alias", ctx, "1", get_x_inteno_owsd_listenobj_alias, set_x_inteno_owsd_listenobj_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Port", ctx, "1", get_x_inteno_owsd_listenobj_port, set_x_inteno_owsd_listenobj_port, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Interface", ctx, "1", get_x_inteno_owsd_listenobj_interface, set_x_inteno_owsd_listenobj_interface, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Ipv6", ctx, "1", get_x_inteno_owsd_listenobj_ipv6_enable, set_x_inteno_owsd_listenobj_ipv6_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Whitelist_interface", ctx, "1", get_x_inteno_owsd_listenobj_whitelist_interface, set_x_inteno_owsd_listenobj_whitelist_interface, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Whitelist_dhcp", ctx, "1", get_x_inteno_owsd_listenobj_whitelist_dhcp, set_x_inteno_owsd_listenobj_whitelist_dhcp, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Origin", ctx, "1", get_x_inteno_owsd_listenobj_origin, set_x_inteno_owsd_listenobj_origin, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - diff --git a/dm/dmtree/common/x_inteno_se_owsd.h b/dm/dmtree/common/x_inteno_se_owsd.h index a23a411..0021165 100644 --- a/dm/dmtree/common/x_inteno_se_owsd.h +++ b/dm/dmtree/common/x_inteno_se_owsd.h @@ -1,10 +1,32 @@ #ifndef __SE_OWSD_H #define __SE_OWSD_H -struct owsd_listenargs -{ - struct uci_section *owsd_listensection; -}; +int browseXIntenoOwsdListenObj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_x_inteno_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_global_sock(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_global_redirect(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_listenobj_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_listenobj_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_listenobj_ipv6_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_listenobj_whitelist_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_listenobj_whitelist_dhcp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_listenobj_origin(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_x_inteno_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_x_inteno_owsd_listenobj_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int add_owsd_listen(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_owsd_listen_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +extern DMLEAF XIntenoSeOwsdParams[]; +extern DMOBJ XIntenoSeOwsdObj[]; +extern DMLEAF X_INTENO_SE_ListenObjParams[]; -int entry_method_root_X_INTENO_SE_OWSD(struct dmctx *ctx); #endif diff --git a/dm/dmtree/common/x_inteno_se_power_mgmt.c b/dm/dmtree/common/x_inteno_se_power_mgmt.c index 3988846..1325b07 100644 --- a/dm/dmtree/common/x_inteno_se_power_mgmt.c +++ b/dm/dmtree/common/x_inteno_se_power_mgmt.c @@ -15,20 +15,30 @@ #include "dmcwmp.h" #include "dmuci.h" #include "dmcommon.h" +#include "x_inteno_se_power_mgmt.h" -int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, char **value) +/*** DMROOT.X_INTENO_SE_PowerManagement. ***/ +DMLEAF tSe_PowerManagementParam[] = { +{"EthernetAutoPowerDownEnable", &DMWRITE, DMT_BOOL, get_pwr_mgmt_value_ethapd, set_power_mgmt_param_ethapd, NULL, NULL}, +{"EnergyEfficientEthernetEnable", &DMWRITE, DMT_BOOL, get_pwr_mgmt_value_eee, set_power_mgmt_param_eee, NULL, NULL}, +{"NumberOfEthernetInterfacesPoweredUp", &DMREAD, DMT_UNINT, get_pwr_nbr_interfaces_up, NULL, NULL, NULL}, +{"NumberOfEthernetInterfacesPoweredDown", &DMREAD, DMT_UNINT, get_pwr_nbr_interfaces_down, NULL, NULL, NULL}, +{0} +}; + +int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("power_mgmt", "power_mgmt", "ethapd", value); return 0; } -int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, char **value) +int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("power_mgmt", "power_mgmt", "eee", value); return 0; } -int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, char **value) +int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char buf[256]; int pp, r; @@ -44,7 +54,7 @@ int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, char **value) +int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char buf[256]; int pp, r; @@ -60,7 +70,7 @@ int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, int action, char *value) +int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -80,7 +90,7 @@ int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, int action, c return 0; } -int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, int action, char *value) +int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -109,15 +119,3 @@ bool dm_powermgmt_enable_set(void) return false; } } -int entry_method_root_X_INTENO_SE_PowerManagement(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_PowerManagement.") { - DMOBJECT(DMROOT"X_INTENO_SE_PowerManagement.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("EthernetAutoPowerDownEnable", ctx, "1", get_pwr_mgmt_value_ethapd, set_power_mgmt_param_ethapd, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("EnergyEfficientEthernetEnable", ctx, "1", get_pwr_mgmt_value_eee, set_power_mgmt_param_eee, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("NumberOfEthernetInterfacesPoweredUp", ctx, "0", get_pwr_nbr_interfaces_up, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("NumberOfEthernetInterfacesPoweredDown", ctx, "0", get_pwr_nbr_interfaces_down, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/x_inteno_se_power_mgmt.h b/dm/dmtree/common/x_inteno_se_power_mgmt.h index 4d625df..d3c7e5b 100644 --- a/dm/dmtree/common/x_inteno_se_power_mgmt.h +++ b/dm/dmtree/common/x_inteno_se_power_mgmt.h @@ -12,6 +12,14 @@ #ifndef __POWER_MGMT_H #define __POWER_MGMT_H +extern DMLEAF tSe_PowerManagementParam[]; bool dm_powermgmt_enable_set(void); -int entry_method_root_X_INTENO_SE_PowerManagement(struct dmctx *ctx); -#endif \ No newline at end of file + +int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +#endif diff --git a/dm/dmtree/common/x_inteno_syslog.c b/dm/dmtree/common/x_inteno_syslog.c index c9fb1f9..63317e4 100644 --- a/dm/dmtree/common/x_inteno_syslog.c +++ b/dm/dmtree/common/x_inteno_syslog.c @@ -18,13 +18,20 @@ #include "dmcommon.h" #include "x_inteno_syslog.h" -int get_server_ip_address(char *refparam, struct dmctx *ctx, char **value) +DMLEAF tSe_SyslogCfgParam[] = { +{"ServerIPAddress", &DMWRITE, DMT_STRING, get_server_ip_address, set_server_ip_address, NULL, NULL}, +{"ServerPortNumber", &DMWRITE, DMT_UNINT, get_server_port_number, set_server_port_number, NULL, NULL}, +{"RemoteLogLevel", &DMWRITE, DMT_UNINT, get_remote_log_level, set_remote_log_level, NULL, NULL}, +{0} +}; + +int get_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("system", "@system[0]", "log_ip", value); return 0; } -int set_server_ip_address(char *refparam, struct dmctx *ctx, int action, char *value) +int set_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -36,7 +43,7 @@ int set_server_ip_address(char *refparam, struct dmctx *ctx, int action, char *v return 0; } -int get_server_port_number(char *refparam, struct dmctx *ctx, char **value) +int get_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; dmuci_get_option_value_string("system", "@system[0]", "log_port", &tmp); @@ -47,7 +54,7 @@ int get_server_port_number(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_server_port_number(char *refparam, struct dmctx *ctx, int action, char *value) +int set_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -59,7 +66,7 @@ int set_server_port_number(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_remote_log_level(char *refparam, struct dmctx *ctx, char **value) +int get_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; dmuci_get_option_value_string("system", "@system[0]", "conloglevel", &tmp); @@ -70,7 +77,7 @@ int get_remote_log_level(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_remote_log_level(char *refparam, struct dmctx *ctx, int action, char *value) +int set_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -81,15 +88,3 @@ int set_remote_log_level(char *refparam, struct dmctx *ctx, int action, char *va } return 0; } - -int entry_method_root_syslog(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_SyslogCfg.") { - DMOBJECT(DMROOT"X_INTENO_SE_SyslogCfg.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("ServerIPAddress", ctx, "1", get_server_ip_address, set_server_ip_address, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ServerPortNumber", ctx, "1", get_server_port_number, set_server_port_number, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RemoteLogLevel", ctx, "1", get_remote_log_level, set_remote_log_level, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} \ No newline at end of file diff --git a/dm/dmtree/common/x_inteno_syslog.h b/dm/dmtree/common/x_inteno_syslog.h index 2a10868..6be2256 100644 --- a/dm/dmtree/common/x_inteno_syslog.h +++ b/dm/dmtree/common/x_inteno_syslog.h @@ -1,6 +1,14 @@ #ifndef __SE_SYSLOG_H #define __SE_SYSLOG_H -int entry_method_root_syslog(struct dmctx *ctx); +extern DMLEAF tSe_SyslogCfgParam[]; -#endif \ No newline at end of file +int get_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_server_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_server_port_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_remote_log_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/common/xmpp.c b/dm/dmtree/common/xmpp.c index b7cc97c..5e34b21 100644 --- a/dm/dmtree/common/xmpp.c +++ b/dm/dmtree/common/xmpp.c @@ -17,16 +17,36 @@ #include "dmcommon.h" #include "xmpp.h" -struct connectionargs cur_connectionargs = {0}; -inline int entry_xmpp_connection_instance(struct dmctx *ctx, char *iconnection); +/*** XMPP.Connection. ***/ +DMOBJ tXMPPObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Connection", &DMWRITE, add_xmpp_connection, delete_xmpp_connection, NULL, browsexmpp_connectionInst, NULL, NULL, NULL, tConnectionParams, get_xmpp_connection_linker}, +{0} +}; + +DMLEAF tXMPPParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"ConnectionNumberOfEntries", &DMREAD, DMT_UNINT, get_xmpp_connection_nbr_entry, NULL, NULL, NULL}, +{0} +}; + +DMLEAF tConnectionParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Enable", &DMWRITE, DMT_BOOL, get_connection_enable, set_connection_enable, NULL, NULL}, +//{"Username", &DMWRITE, DMT_STRING, get_xmpp_connection_username, set_xmpp_connection_username, NULL, NULL}, +{"Password", &DMWRITE, DMT_STRING, get_xmpp_connection_password, set_xmpp_connection_password, NULL, NULL}, +{"Domain", &DMWRITE, DMT_STRING, get_xmpp_connection_domain, set_xmpp_connection_domain, NULL, NULL}, +{"Resource", &DMWRITE, DMT_STRING, get_xmpp_connection_resource, set_xmpp_connection_resource, NULL, NULL}, +{"ServerConnectAlgorithm", &DMWRITE, DMT_STRING, get_xmpp_connection_server_connect_algorithm, set_xmpp_connection_server_connect_algorithm, NULL, NULL}, +{"KeepAliveInterval", &DMWRITE, DMT_LONG, get_xmpp_connection_keepalive_interval, set_xmpp_connection_keepalive_interval, NULL, NULL}, +{"ServerConnectAttempts", &DMWRITE, DMT_UNINT, get_xmpp_connection_server_attempts, set_xmpp_connection_server_attempts, NULL, NULL}, +{"ServerRetryInitialInterval", &DMWRITE, DMT_UNINT, get_xmpp_connection_retry_initial_interval, set_xmpp_connection_retry_initial_interval, NULL, NULL}, +{"ServerRetryIntervalMultiplier", &DMWRITE, DMT_UNINT, get_xmpp_connection_retry_interval_multiplier, set_xmpp_connection_retry_interval_multiplier, NULL, NULL}, +{"ServerRetryMaxInterval", &DMWRITE, DMT_UNINT, get_xmpp_connection_retry_max_interval, set_xmpp_connection_retry_max_interval, NULL, NULL}, +{"UseTLS", &DMWRITE, DMT_BOOL, get_xmpp_connection_server_usetls, set_xmpp_connection_server_usetls, NULL, NULL}, +{0} +}; -inline int init_args_connection_entry(struct dmctx *ctx, struct uci_section *s) -{ - struct connectionargs *args = &cur_connectionargs; - ctx->args = (void *)args; - args->connsection = s; - return 0; -} char *get_xmpp_server_enable(char *instance) { @@ -148,7 +168,7 @@ char *get_xmpp_connect_retry_max_interval(char *instance) return v; } -int add_xmpp_connection(struct dmctx *ctx, char **instancepara) +int add_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { struct uci_section *s; char *value, *name; @@ -158,33 +178,34 @@ int add_xmpp_connection(struct dmctx *ctx, char **instancepara) return 0; } -int delete_xmpp_connection_all() +int delete_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; struct uci_section *s, *ss = NULL; + struct connectionargs *connargs; + struct uci_section *connsection = (struct uci_section *)data; - uci_foreach_sections("cwmp", "xmpp_connection", s) { - if (found != 0) { - dmuci_delete_by_section(ss, NULL, NULL); - } - ss = s; - found++; + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(connsection, NULL, NULL); + return 0; + case DEL_ALL: + uci_foreach_sections("cwmp", "xmpp_connection", s) { + if (found != 0) { + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) { + dmuci_delete_by_section(ss, NULL, NULL); + } + return 0; } - if (ss != NULL) { - dmuci_delete_by_section(ss, NULL, NULL); - } return 0; } -int delete_xmpp_connection(struct dmctx *ctx) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_delete_by_section(connargs->connsection, NULL, NULL); - return 0; -} - -int get_xmpp_connection_nbr_entry(char *refparam, struct dmctx *ctx, char **value) +int get_xmpp_connection_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s; int cnt = 0; @@ -196,311 +217,294 @@ int get_xmpp_connection_nbr_entry(char *refparam, struct dmctx *ctx, char **valu return 0; } -inline int entry_xmpp_connection(struct dmctx *ctx) +int get_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "enable", value); + return 0; +} + +int set_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "enable", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "password", value); + return 0; +} + +int set_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "password", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "password", value); + return 0; +} + +int set_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "password", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "resource", value); + return 0; +} + +int set_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "resource", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "serveralgorithm", value); + return 0; +} + +int set_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "serveralgorithm", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "interval", value); + return 0; +} + +int set_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "interval", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "attempt", value); + return 0; +} + +int set_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "attempt", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "initial_retry_interval", value); + return 0; +} + +int set_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "initial_retry_interval", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "retry_interval_multiplier", value); + return 0; +} + +int set_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "retry_interval_multiplier", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "retry_max_interval", value); + return 0; +} + +int set_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "retry_max_interval", value); + return 0; + } + return 0; +} + +int get_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *connsection = (struct uci_section *)data; + + dmuci_get_value_by_section_string(connsection, "usetls", value); + return 0; +} + +int set_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *connsection = (struct uci_section *)data; + bool b; + + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value_by_section(connsection, "usetls", value); + return 0; + } + return 0; +} + +/************************************************************************** +* LINKER +***************************************************************************/ +int get_xmpp_connection_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + char *conn_instance; + struct uci_section *connsection = (struct uci_section *)data; + + if (connsection) + { + dmuci_get_value_by_section_string(connsection, "connection_instance", &conn_instance); + dmasprintf(linker,"xmppc:%s", conn_instance); + return 0; + } + else + *linker = ""; + return 0; +} + +/************************************************************* + * ENTRY METHOD +/*************************************************************/ + +int browsexmpp_connectionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *iconnection = NULL, *iconnection_last = NULL;; struct uci_section *s = NULL; uci_foreach_sections("cwmp", "xmpp_connection", s) { - init_args_connection_entry(ctx, s); - iconnection = handle_update_instance(1, ctx, &iconnection_last, update_instance_alias, 3, s, "connection_instance", "connection_instance_alias"); - SUBENTRY(entry_xmpp_connection_instance, ctx, iconnection); - } -} - -int get_connection_enable(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "enable", value); - return 0; -} - -int set_connection_enable(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "enable", value); - return 0; + iconnection = handle_update_instance(1, dmctx, &iconnection_last, update_instance_alias, 3, s, "connection_instance", "connection_instance_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, iconnection) == DM_STOP) + break; } return 0; } - -int get_xmpp_connection_password(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "password", value); - return 0; -} - -int set_xmpp_connection_password(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "password", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_domain(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "password", value); - return 0; -} - -int set_xmpp_connection_domain(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "password", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_resource(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "resource", value); - return 0; -} - -int set_xmpp_connection_resource(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "resource", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "serveralgorithm", value); - return 0; -} - -int set_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "serveralgorithm", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "interval", value); - return 0; -} - -int set_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "interval", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "attempt", value); - return 0; -} - -int set_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "attempt", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "initial_retry_interval", value); - return 0; -} - -int set_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "initial_retry_interval", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "retry_interval_multiplier", value); - return 0; -} - -int set_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "retry_interval_multiplier", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "retry_max_interval", value); - return 0; -} - -int set_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "retry_max_interval", value); - return 0; - } - return 0; -} - -int get_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, char **value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - - dmuci_get_value_by_section_string(connargs->connsection, "usetls", value); - return 0; -} - -int set_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, int action, char *value) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - bool b; - - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value_by_section(connargs->connsection, "usetls", value); - return 0; - } - return 0; -} - -inline int entry_xmpp_connection_instance(struct dmctx *ctx, char *iconnection) -{ - struct connectionargs *connargs = (struct connectionargs *)ctx->args; - char linker[32] = "xmppc:"; - char *conn_instance; - dmuci_get_value_by_section_string(connargs->connsection, "connection_instance", &conn_instance); - strcat(linker, conn_instance); - - IF_MATCH(ctx, DMROOT"XMPP.Connection.%s.", iconnection) { - DMOBJECT(DMROOT"XMPP.Connection.%s.", ctx, "0", 1, NULL, delete_xmpp_connection, linker, iconnection); - DMPARAM("Enable", ctx, "1", get_connection_enable, set_connection_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - //DMPARAM("Username", ctx, "1", get_xmpp_connection_username, set_xmpp_connection_username, NULL, 0, 1, UNDEF, NULL); //TO CHECK - DMPARAM("Password", ctx, "1", get_xmpp_connection_password, set_xmpp_connection_password, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Domain", ctx, "1", get_xmpp_connection_domain, set_xmpp_connection_domain, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Resource", ctx, "1", get_xmpp_connection_resource, set_xmpp_connection_resource, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ServerConnectAlgorithm", ctx, "1", get_xmpp_connection_server_connect_algorithm, set_xmpp_connection_server_connect_algorithm, NULL, 0, 1, UNDEF, NULL); - DMPARAM("KeepAliveInterval", ctx, "1", get_xmpp_connection_keepalive_interval, set_xmpp_connection_keepalive_interval, "xsd:long", 0, 1, UNDEF, NULL); - DMPARAM("ServerConnectAttempts", ctx, "1", get_xmpp_connection_server_attempts, set_xmpp_connection_server_attempts, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ServerRetryInitialInterval", ctx, "1", get_xmpp_connection_retry_initial_interval, set_xmpp_connection_retry_initial_interval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ServerRetryIntervalMultiplier", ctx, "1", get_xmpp_connection_retry_interval_multiplier, set_xmpp_connection_retry_interval_multiplier, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ServerRetryMaxInterval", ctx, "1", get_xmpp_connection_retry_max_interval, set_xmpp_connection_retry_max_interval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("UseTLS", ctx, "1", get_xmpp_connection_server_usetls, set_xmpp_connection_server_usetls, "xsd:boolean", 0, 1, UNDEF, NULL); //TO CHECK - //SUBENTRY(entry_xmpp_connection_server, ctx, iconnection); - return 0; - } - return FAULT_9005; -} - -int entry_method_root_xmpp(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"XMPP.") { - DMOBJECT(DMROOT"XMPP.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("ConnectionNumberOfEntries", ctx, "0", get_xmpp_connection_nbr_entry, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"XMPP.Connection.", ctx, "0", 1, add_xmpp_connection, delete_xmpp_connection_all, NULL); - SUBENTRY(entry_xmpp_connection, ctx); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/common/xmpp.h b/dm/dmtree/common/xmpp.h index 019c976..1db4db1 100644 --- a/dm/dmtree/common/xmpp.h +++ b/dm/dmtree/common/xmpp.h @@ -1,10 +1,14 @@ #ifndef __XMPP_H #define __XMPP_H -struct connectionargs -{ - struct uci_section *connsection; -}; +extern DMOBJ tXMPPObj[]; +extern DMLEAF tXMPPParams[]; +extern DMLEAF tConnectionParams[]; + +int browsexmpp_connectionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_xmpp_connection(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); char *get_xmpp_server_enable(char *instance); char *get_xmpp_username(char *instance); @@ -16,5 +20,33 @@ char *get_xmpp_connect_attempts(char *instance); char *get_xmpp_connect_initial_retry_interval(char *instance); char *get_xmpp_connect_retry_interval_multiplier(char *instance); char *get_xmpp_connect_retry_max_interval(char *instance); -int entry_method_root_xmpp(struct dmctx *ctx); + +int get_xmpp_connection_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + + +int set_connection_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_resource(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_server_connect_algorithm(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_keepalive_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_server_attempts(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_retry_initial_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_retry_interval_multiplier(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_retry_max_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_xmpp_connection_server_usetls(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_xmpp_connection_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif diff --git a/dm/dmtree/tr098/deviceconfig.c b/dm/dmtree/tr098/deviceconfig.c index eaca19f..ac6e841 100644 --- a/dm/dmtree/tr098/deviceconfig.c +++ b/dm/dmtree/tr098/deviceconfig.c @@ -1,81 +1,75 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * Copyright (C) 2015 Inteno Broadband Technology AB - * Author Imen Bhiri - * - */ - -#include -#include -#include -#include "dmuci.h" -#include "dmubus.h" -#include "dmcwmp.h" -#include "dmcommon.h" -#include "deviceconfig.h" - -#define BACKUP_CONFIG_FILE "/etc/backup" -#define RESTORE_FUNCTION_PATH "/usr/share/icwmp/functions/conf_backup" -////////////////////////SET AND GET ALIAS///////////////////////////////// - -int get_config_file(char *refparam, struct dmctx *ctx, char **value) -{ - long length; - FILE * f = NULL; - char *pch = NULL, *spch = NULL; - char * buffer = 0; - int first = 1; - - - dmcmd("/bin/sh", 2, RESTORE_FUNCTION_PATH, "export_conf"); - - f = fopen (BACKUP_CONFIG_FILE, "rb"); - if (f) - { - fseek(f, 0, SEEK_END); - length = ftell(f); - fseek(f, 0, SEEK_SET); - buffer = dmmalloc(length); - if (buffer) - { - fread(buffer, 1, length, f); - } - fclose(f); - } - if (buffer) - { - *value = dmstrdup(buffer); - dmfree(buffer); - } - return 0; -} - -int set_config_file(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmcmd("/bin/sh", 2, RESTORE_FUNCTION_PATH, "import_conf"); - return 0; - } - return 0; -} - -////////////////////////////////////// - -int entry_method_root_device_config(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"DeviceConfig.") { - DMOBJECT(DMROOT"DeviceConfig.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("ConfigFile", ctx, "1", get_config_file, set_config_file, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - - +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Copyright (C) 2015 Inteno Broadband Technology AB + * Author Imen Bhiri + * + */ + +#include +#include +#include +#include "dmuci.h" +#include "dmubus.h" +#include "dmcwmp.h" +#include "dmcommon.h" +#include "deviceconfig.h" + +#define BACKUP_CONFIG_FILE "/etc/backup" +#define RESTORE_FUNCTION_PATH "/usr/share/icwmp/functions/conf_backup" +////////////////////////SET AND GET ALIAS///////////////////////////////// + +/*** DMROOT.DownloadDiagnostics. ***/ +DMLEAF tDeviceConfigParam[] = { +{"ConfigFile", &DMWRITE, DMT_STRING, get_config_file, set_config_file, NULL, NULL}, +{0} +}; + +int get_config_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + long length; + FILE * f = NULL; + char *pch = NULL, *spch = NULL; + char * buffer = 0; + int first = 1; + + + dmcmd("/bin/sh", 2, RESTORE_FUNCTION_PATH, "export_conf"); + + f = fopen (BACKUP_CONFIG_FILE, "rb"); + if (f) + { + fseek(f, 0, SEEK_END); + length = ftell(f); + fseek(f, 0, SEEK_SET); + buffer = dmmalloc(length); + if (buffer) + { + fread(buffer, 1, length, f); + } + fclose(f); + } + if (buffer) + { + *value = dmstrdup(buffer); + dmfree(buffer); + } + return 0; +} + +int set_config_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmcmd("/bin/sh", 2, RESTORE_FUNCTION_PATH, "import_conf"); + return 0; + } + return 0; +} + + diff --git a/dm/dmtree/tr098/deviceconfig.h b/dm/dmtree/tr098/deviceconfig.h index 2141afc..7c82396 100644 --- a/dm/dmtree/tr098/deviceconfig.h +++ b/dm/dmtree/tr098/deviceconfig.h @@ -1,6 +1,8 @@ -#ifndef __SE_CONFIG_FILE_H -#define __SE_CONFIG_FILE_H - -int entry_method_root_device_config(struct dmctx *ctx); - -#endif +#ifndef __SE_CONFIG_FILE_H +#define __SE_CONFIG_FILE_H + +extern DMLEAF tDeviceConfigParam[]; +int get_config_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_config_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/tr098/downloaddiagnostic.c b/dm/dmtree/tr098/downloaddiagnostic.c index a380459..fc7368b 100644 --- a/dm/dmtree/tr098/downloaddiagnostic.c +++ b/dm/dmtree/tr098/downloaddiagnostic.c @@ -4,7 +4,7 @@ * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com) + * Copyright (C) 2012-2016 PIVA SOFTWARE (www.pivasoftware.com) * Author: Imen Bhiri * Author: Feten Besbes */ @@ -12,15 +12,29 @@ #include #include #include -#include "cwmp.h" -#include "diagnostic.h" -#include "ubus.h" #include "dmcwmp.h" #include "dmuci.h" #include "dmubus.h" #include "dmcommon.h" #include "downloaddiagnostic.h" +/*** DMROOT.DownloadDiagnostics. ***/ +DMLEAF tDownloadDiagnosticsParam[] = { +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_download_diagnostics_state, set_download_diagnostics_state, NULL, NULL}, +{"DownloadURL", &DMWRITE, DMT_STRING, get_download_diagnostics_url, set_download_diagnostics_url, NULL, NULL}, +{"EthernetPriority", &DMWRITE, DMT_UNINT, get_download_diagnostics_ethernet_priority,set_download_diagnostics_ethernet_priority, NULL, NULL}, +{"ROMTime", &DMREAD, DMT_TIME, get_download_diagnostic_romtime, NULL, NULL, NULL}, +{"BOMTime", &DMREAD, DMT_TIME, get_download_diagnostic_bomtime, NULL, NULL, NULL}, +{"EOMTime", &DMREAD, DMT_TIME, get_download_diagnostic_eomtime, NULL, NULL, NULL}, +{"TestBytesReceived", &DMREAD, DMT_UNINT, get_download_diagnostic_testbytes, NULL, NULL, NULL}, +{"TotalBytesReceived", &DMREAD, DMT_UNINT, get_download_diagnostic_totalbytes, NULL, NULL, NULL}, +{"TCPOpenRequestTime", &DMREAD, DMT_TIME, get_download_diagnostic_tcp_open_request_time, NULL, NULL, NULL}, +{"TCPOpenResponseTime", &DMREAD, DMT_TIME, get_download_diagnostic_tcp_open_response_time, NULL, NULL, NULL}, +//{"DSCP", &DMWRITE, DMT_UNINT, get_download_diagnostics_dscp, set_download_diagnostics_dscp, NULL, NULL}, +//{"Interface", &DMWRITE, DMT_UNINT, get_download_diagnostics_interface, set_download_diagnostics_interface, NULL, NULL}, +{0} +}; + static inline char *download_diagnostic_get(char *option, char *def) { char *tmp; @@ -30,13 +44,13 @@ static inline char *download_diagnostic_get(char *option, char *def) else return tmp; } -int get_download_diagnostics_state(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = download_diagnostic_get("DiagnosticState", "None"); return 0; } -int set_download_diagnostics_state(char *refparam, struct dmctx *ctx, int action, char *value) +int set_download_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -59,13 +73,13 @@ int set_download_diagnostics_state(char *refparam, struct dmctx *ctx, int action return 0; } -int get_download_diagnostics_interface(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "interface", value); return 0; } -int set_download_diagnostics_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_download_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -74,7 +88,7 @@ int set_download_diagnostics_interface(char *refparam, struct dmctx *ctx, int ac return 0; case VALUESET: DOWNLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); @@ -85,14 +99,14 @@ int set_download_diagnostics_interface(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_download_diagnostics_url(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "url", value); return 0; } -int set_download_diagnostics_url(char *refparam, struct dmctx *ctx, int action, char *value) +int set_download_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -101,7 +115,7 @@ int set_download_diagnostics_url(char *refparam, struct dmctx *ctx, int action, return 0; case VALUESET: DOWNLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); @@ -112,13 +126,13 @@ int set_download_diagnostics_url(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; return 0; } -int set_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, int action, char *value) +int set_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -128,7 +142,7 @@ int set_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx return 0; case VALUESET: DOWNLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "downloaddiagnostic", &curr_section, &tmp); @@ -139,7 +153,7 @@ int set_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx return 0; } -int get_download_diagnostic_romtime(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostic_romtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "ROMtime", value); @@ -148,7 +162,7 @@ int get_download_diagnostic_romtime(char *refparam, struct dmctx *ctx, char **va return 0; } -int get_download_diagnostic_bomtime(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostic_bomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "BOMtime", value); @@ -157,7 +171,7 @@ int get_download_diagnostic_bomtime(char *refparam, struct dmctx *ctx, char **va return 0; } -int get_download_diagnostic_eomtime(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostic_eomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "EOMtime", value); @@ -166,7 +180,7 @@ int get_download_diagnostic_eomtime(char *refparam, struct dmctx *ctx, char **va return 0; } -int get_download_diagnostic_testbytes(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostic_testbytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "TestBytesReceived", value); @@ -175,7 +189,7 @@ int get_download_diagnostic_testbytes(char *refparam, struct dmctx *ctx, char ** return 0; } -int get_download_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "TotalBytesReceived", value); @@ -184,7 +198,7 @@ int get_download_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, char * return 0; } -int get_download_diagnostic_tcp_open_request_time(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostic_tcp_open_request_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "TCPOpenRequestTime", value); @@ -193,7 +207,7 @@ int get_download_diagnostic_tcp_open_request_time(char *refparam, struct dmctx * return 0; } -int get_download_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_download_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@downloaddiagnostic[0]", "TCPOpenResponseTime", value); @@ -201,26 +215,3 @@ int get_download_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *value = "0"; return 0; } - - - -int entry_method_root_Download_Diagnostics(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"DownloadDiagnostics.") { - DMOBJECT(DMROOT"DownloadDiagnostics.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("DiagnosticsState", ctx, "1", get_download_diagnostics_state, set_download_diagnostics_state, NULL, 0, 1, UNDEF, NULL); - //DMPARAM("Interface", ctx, "1", get_download_diagnostics_interface, set_download_diagnostics_interface, NULL, 0, 1, UNDEF, NULL); //TODO - DMPARAM("DownloadURL", ctx, "1", get_download_diagnostics_url, set_download_diagnostics_url, NULL, 0, 1, UNDEF, NULL); - //DMPARAM("DSCP", ctx, "1", get_download_diagnostics_dscp, set_download_diagnostics_dscp, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPriority", ctx, "1", get_download_diagnostics_ethernet_priority, set_download_diagnostics_ethernet_priority, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ROMTime", ctx, "0", get_download_diagnostic_romtime, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("BOMTime", ctx, "0", get_download_diagnostic_bomtime, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("EOMTime", ctx, "0", get_download_diagnostic_eomtime, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("TestBytesReceived", ctx, "0", get_download_diagnostic_testbytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("TotalBytesReceived", ctx, "0", get_download_diagnostic_totalbytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("TCPOpenRequestTime", ctx, "0", get_download_diagnostic_tcp_open_request_time, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("TCPOpenResponseTime", ctx, "0", get_download_diagnostic_tcp_open_response_time, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr098/downloaddiagnostic.h b/dm/dmtree/tr098/downloaddiagnostic.h index fa932aa..630fe04 100644 --- a/dm/dmtree/tr098/downloaddiagnostic.h +++ b/dm/dmtree/tr098/downloaddiagnostic.h @@ -4,12 +4,29 @@ * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com) + * Copyright (C) 2012-2016 PIVA SOFTWARE (www.pivasoftware.com) * Author: Imen Bhiri + * Author: Anis Ellouze */ #ifndef __DOWNLOAD_DIAGNOSTIC_H #define __DOWNLOAD_DIAGNOSTIC_H -int entry_method_root_Download_Diagnostics(struct dmctx *ctx); +static inline char *download_diagnostic_get(char *option, char *def); +int get_download_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_download_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_download_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_download_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_download_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_download_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_download_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_download_diagnostic_romtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_download_diagnostic_bomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_download_diagnostic_eomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_download_diagnostic_testbytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_download_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_download_diagnostic_tcp_open_request_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_download_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +extern DMLEAF tDownloadDiagnosticsParam[]; #endif diff --git a/dm/dmtree/tr098/ippingdiagnostics.c b/dm/dmtree/tr098/ippingdiagnostics.c index e561c1c..29b62c5 100644 --- a/dm/dmtree/tr098/ippingdiagnostics.c +++ b/dm/dmtree/tr098/ippingdiagnostics.c @@ -12,15 +12,29 @@ #include #include #include -#include "cwmp.h" -#include "diagnostic.h" -#include "ubus.h" #include "dmcwmp.h" #include "dmuci.h" #include "dmubus.h" #include "dmcommon.h" #include "ippingdiagnostics.h" +/*** IPPingDiagnostics. ***/ +DMLEAF tIPPingDiagnosticsParam[] = { +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_ipping_diagnostics_state, set_ipping_diagnostics_state, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_ipping_interface, set_ipping_interface, NULL, NULL}, +{"Host", &DMWRITE, DMT_STRING, get_ipping_host, set_ipping_host, NULL, NULL}, +{"NumberOfRepetitions", &DMWRITE, DMT_UNINT, get_ipping_repetition_number, set_ipping_repetition_number, NULL, NULL}, +{"Timeout", &DMWRITE, DMT_UNINT, get_ipping_timeout, set_ipping_timeout, NULL, NULL}, +{"DataBlockSize", &DMWRITE, DMT_UNINT, get_ipping_block_size, set_ipping_block_size, NULL, NULL}, +//{"DSCP", &DMWRITE, DMT_UNINT, get_ipping_dscp, set_ipping_dscp, NULL, NULL}, +{"SuccessCount", &DMREAD, DMT_UNINT, get_ipping_success_count, NULL, NULL, NULL}, +{"FailureCount", &DMREAD, DMT_UNINT, get_ipping_failure_count, NULL, NULL, NULL}, +{"AverageResponseTime", &DMREAD, DMT_UNINT, get_ipping_average_response_time, NULL, NULL, NULL}, +{"MinimumResponseTime", &DMREAD, DMT_UNINT, get_ipping_min_response_time, NULL, NULL, NULL}, +{"MaximumResponseTime", &DMREAD, DMT_UNINT, get_ipping_max_response_time, NULL, NULL, NULL}, +{0} +}; + static inline char *ipping_get(char *option, char *def) { char *tmp; @@ -30,13 +44,13 @@ static inline char *ipping_get(char *option, char *def) else return tmp; } -int get_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("DiagnosticState", "None"); return 0; } -int set_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -46,7 +60,7 @@ int set_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, int action, case VALUESET: if (strcmp(value, "Requested") == 0) { IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); @@ -59,13 +73,13 @@ int set_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_ipping_interface(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@ippingdiagnostic[0]", "interface", value); return 0; } -int set_ipping_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -74,7 +88,7 @@ int set_ipping_interface(char *refparam, struct dmctx *ctx, int action, char *va return 0; case VALUESET: //IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); @@ -85,14 +99,14 @@ int set_ipping_interface(char *refparam, struct dmctx *ctx, int action, char *va return 0; } -int get_ipping_host(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@ippingdiagnostic[0]", "Host", value); return 0; } -int set_ipping_host(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -101,7 +115,7 @@ int set_ipping_host(char *refparam, struct dmctx *ctx, int action, char *value) return 0; case VALUESET: IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); @@ -112,13 +126,13 @@ int set_ipping_host(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_ipping_repetition_number(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("NumberOfRepetitions", "3"); return 0; } -int set_ipping_repetition_number(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -128,7 +142,7 @@ int set_ipping_repetition_number(char *refparam, struct dmctx *ctx, int action, return 0; case VALUESET: IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); @@ -139,14 +153,14 @@ int set_ipping_repetition_number(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_ipping_timeout(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("Timeout", "1000"); return 0; } -int set_ipping_timeout(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *curr_section = NULL; char *tmp; @@ -156,7 +170,7 @@ int set_ipping_timeout(char *refparam, struct dmctx *ctx, int action, char *valu return 0; case VALUESET: IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); @@ -167,14 +181,14 @@ int set_ipping_timeout(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int get_ipping_block_size(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("DataBlockSize", "64"); return 0; } -int set_ipping_block_size(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -183,7 +197,7 @@ int set_ipping_block_size(char *refparam, struct dmctx *ctx, int action, char *v return 0; case VALUESET: IPPING_STOP - curr_section = dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "ippingdiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "ippingdiagnostic", &curr_section, &tmp); @@ -193,57 +207,37 @@ int set_ipping_block_size(char *refparam, struct dmctx *ctx, int action, char *v return 0; } -int get_ipping_success_count(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("SuccessCount", "0"); return 0; } -int get_ipping_failure_count(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_failure_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("FailureCount", "0"); return 0; } -int get_ipping_average_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_average_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("AverageResponseTime", "0"); return 0; } -int get_ipping_min_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_min_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("MinimumResponseTime", "0"); return 0; } -int get_ipping_max_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_ipping_max_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("MaximumResponseTime", "0"); return 0; } -int entry_method_root_IPPingDiagnostics(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"IPPingDiagnostics.") { - DMOBJECT(DMROOT"IPPingDiagnostics.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("DiagnosticsState", ctx, "1", get_ipping_diagnostics_state, set_ipping_diagnostics_state, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Interface", ctx, "1", get_ipping_interface, set_ipping_interface, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Host", ctx, "1", get_ipping_host, set_ipping_host, NULL, 0, 1, UNDEF, NULL); - DMPARAM("NumberOfRepetitions", ctx, "1", get_ipping_repetition_number, set_ipping_repetition_number, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Timeout", ctx, "1", get_ipping_timeout, set_ipping_timeout, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DataBlockSize", ctx, "1", get_ipping_block_size, set_ipping_block_size, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - //DMPARAM("DSCP", ctx, "1", get_ipping_dscp, set_ipping_dscp, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("SuccessCount", ctx, "0", get_ipping_success_count, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("FailureCount", ctx, "0", get_ipping_failure_count, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("AverageResponseTime", ctx, "0", get_ipping_average_response_time, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MinimumResponseTime", ctx, "0", get_ipping_min_response_time, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaximumResponseTime", ctx, "0", get_ipping_max_response_time, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} \ No newline at end of file diff --git a/dm/dmtree/tr098/ippingdiagnostics.h b/dm/dmtree/tr098/ippingdiagnostics.h index c9c349c..5ddffcd 100644 --- a/dm/dmtree/tr098/ippingdiagnostics.h +++ b/dm/dmtree/tr098/ippingdiagnostics.h @@ -10,7 +10,27 @@ #ifndef __IPPING_DIAGNOSTIC_H #define __IPPING_DIAGNOSTIC_H -extern struct ip_ping_diagnostic ipping_diagnostic; -int entry_method_root_IPPingDiagnostics(struct dmctx *ctx); +extern DMLEAF tIPPingDiagnosticsParam[]; -#endif \ No newline at end of file +int get_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_failure_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_average_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_min_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipping_max_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_ipping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipping_dscp(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/tr098/lan_interfaces.c b/dm/dmtree/tr098/lan_interfaces.c index 5153df2..5aea3d7 100644 --- a/dm/dmtree/tr098/lan_interfaces.c +++ b/dm/dmtree/tr098/lan_interfaces.c @@ -16,31 +16,47 @@ #include "dmcommon.h" #include "lan_interfaces.h" -struct linterfargs cur_linterfargs = {0}; -struct wifaceargs cur_wifaceargs = {0}; -static inline void laninterface_lookup(char *eths[], int *size); -int entry_laninterface_lan(struct dmctx *ctx); -int entry_laninterface_wlan(struct dmctx *ctx); -inline int entry_laninterface_wlan_instance(struct dmctx *ctx, char *wli); -inline int entry_laninterface_lan_instance(struct dmctx *ctx, char *li); +struct ethrnet_ifaces_s ethrnet_ifaces_g = {0}; +void laninterface_lookup(char *eths[], int *size); + +/*** LANInterfaces. ***/ +DMOBJ tLANInterfacesObj[] = { +{"LANEthernetInterfaceConfig", &DMREAD, NULL, NULL, NULL, browselaninterface_lanInst, NULL, NULL, NULL, tlaninterface_lanParam, NULL}, +{"WLANConfiguration", &DMREAD, NULL, NULL, NULL, browselaninterface_wlanInst, NULL, NULL, NULL, tlaninterface_wlanParam, NULL}, +{0} +}; + +DMLEAF tLANInterfacesParam[] = { +{"LANEthernetInterfaceNumberOfEntries", &DMREAD, DMT_UNINT, get_lan_ethernet_interface_number, NULL, NULL, NULL}, +{"LANWLANConfigurationNumberOfEntries", &DMREAD, DMT_UNINT, get_lan_wlan_configuration_number, NULL, NULL, NULL}, +{0} +}; + +/*** LANInterfaces.LANEthernetInterfaceConfig. ***/ +DMLEAF tlaninterface_lanParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_lan_eth_int_alias, set_lan_eth_int_alias, NULL, NULL}, +{"X_INTENO_COM_EthName", &DMREAD, DMT_STRING, get_eth_name, NULL, NULL, NULL}, +{0} +}; + +/*** LANInterfaces.WLANConfiguration. ***/ +DMLEAF tlaninterface_wlanParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wlan_conf_alias, set_wlan_conf_alias, NULL, NULL}, +{0} +}; + + //////////////////////INIT ARGS//////////////////////////////// -static inline int init_lan_interface_args(char *lif, struct uci_section *port_sec) +int init_lan_interface_args(struct linterfargs *args, char *lif, struct uci_section *port_sec) { - cur_linterfargs.linterf = lif; - cur_linterfargs.port_sec = port_sec; + args->linterf = lif; + args->port_sec = port_sec; return 0; } -static inline int init_wifi_iface_args(struct uci_section *s) +int get_lan_ethernet_interface_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - cur_wifaceargs.wiface_sec = s; - return 0; -} - -int get_lan_ethernet_interface_number(char *refparam, struct dmctx *ctx, char **value) -{ - struct linterfargs *lifargs = (struct linterfargs *)ctx->args; - dmasprintf(value, "%d", lifargs->eths_size);// MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(value, "%d", ethrnet_ifaces_g.eths_size);// MEM WILL BE FREED IN DMMEMCLEAN return 0; } @@ -56,7 +72,7 @@ static inline int lan_wlan_configuration_number() return cnt; } -int get_lan_wlan_configuration_number(char *refparam, struct dmctx *ctx, char **value) +int get_lan_wlan_configuration_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int cnt = lan_wlan_configuration_number(); @@ -64,21 +80,23 @@ int get_lan_wlan_configuration_number(char *refparam, struct dmctx *ctx, char ** return 0; } -int get_eth_name(char *refparam, struct dmctx *ctx, char **value) +int get_eth_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct linterfargs *lifargs = (struct linterfargs *)ctx->args; + struct linterfargs *lifargs = (struct linterfargs *)data; *value = lifargs->linterf; return 0; } -static inline void laninterface_lookup(char *eths[], int *size) +void laninterface_lookup(char *eths[], int *size) { static char eths_buf[64]; char *phy_itf; char *savepch; int n = 0; + if (*size) + return; db_get_value_string("hw", "board", "ethernetLanPorts", &phy_itf); strcpy(eths_buf, phy_itf); eths[n] = strtok_r(eths_buf, " ", &savepch); @@ -88,107 +106,84 @@ static inline void laninterface_lookup(char *eths[], int *size) *size = n; } -void init_laninterface_lan(struct dmctx *ctx) +inline void init_laninterface_lan(struct dmctx *ctx, void *data) { - struct linterfargs *args = &cur_linterfargs; - ctx->args = (void *)args; - laninterface_lookup(args->eths, &(args->eths_size)); + laninterface_lookup(ethrnet_ifaces_g.eths, &(ethrnet_ifaces_g.eths_size)); } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_lan_eth_int_alias(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_linterfargs.port_sec, "lanportalias", value); + struct linterfargs *args = (struct linterfargs *)data; + dmuci_get_value_by_section_string(args->port_sec, "lanportalias", value); return 0; } -int set_lan_eth_int_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_eth_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct linterfargs *args = (struct linterfargs *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_linterfargs.port_sec, "lanportalias", value); + dmuci_set_value_by_section(args->port_sec, "lanportalias", value); return 0; } return 0; } -int get_wlan_conf_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_conf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wifaceargs.wiface_sec, "wifacealias", value); + struct uci_section *wiface_sec = (struct uci_section *)data; + dmuci_get_value_by_section_string(wiface_sec, "wifacealias", value); return 0; } -int set_wlan_conf_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_conf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *wiface_sec = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wifaceargs.wiface_sec, "wifacealias", value); + dmuci_set_value_by_section(wiface_sec, "wifacealias", value); return 0; } return 0; } /////////////SUB ENTRIES/////////////// -int entry_laninterface_lan(struct dmctx *ctx) +bool check_laninterfaces(struct dmctx *dmctx, void *data) +{ + init_laninterface_lan(dmctx, data); + return true; +} + +int browselaninterface_lanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *ei, *ei_last = NULL; int i = 0; - struct linterfargs *args = &cur_linterfargs; - ctx->args = (void *)args; + struct linterfargs curr_linterfargs = {0}; + struct linterfargs *args = &curr_linterfargs; struct uci_section *s = NULL; - laninterface_lookup(args->eths, &(args->eths_size)); - update_section_list(DMMAP,"lan_port", NULL, args->eths_size, NULL, NULL, NULL, NULL, NULL); + update_section_list(DMMAP,"lan_port", NULL, ethrnet_ifaces_g.eths_size, NULL, NULL, NULL, NULL, NULL); uci_path_foreach_sections(icwmpd, "dmmap", "lan_port", s) { - init_lan_interface_args(args->eths[i++], s); - ei = handle_update_instance(1, ctx, &ei_last, update_instance_alias_icwmpd, 3, s, "lanportinstance", "lanportalias"); - SUBENTRY(entry_laninterface_lan_instance, ctx, ei); + init_lan_interface_args(args, ethrnet_ifaces_g.eths[i++], s); + ei = handle_update_instance(1, dmctx, &ei_last, update_instance_alias_icwmpd, 3, s, "lanportinstance", "lanportalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)args, ei) == DM_STOP) + break; } return 0; } -int entry_laninterface_wlan(struct dmctx *ctx) +int browselaninterface_wlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *wi, *wi_last = NULL; uci_foreach_sections("wireless", "wifi-iface", s) { - init_wifi_iface_args(s); - wi = handle_update_instance(1, ctx, &wi_last, update_instance_alias, 3, s, "wifaceinstance", "wifacealias"); - SUBENTRY(entry_laninterface_wlan_instance, ctx, wi); + wi = handle_update_instance(1, dmctx, &wi_last, update_instance_alias, 3, s, "wifaceinstance", "wifacealias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, wi) == DM_STOP) + break; } return 0; } -//////////////////////////////////////// -int entry_method_root_InternetGatewayDevice_LANInterfaces(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"LANInterfaces.") { - init_laninterface_lan(ctx); - DMOBJECT(DMROOT"LANInterfaces.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("LANEthernetInterfaceNumberOfEntries", ctx, "0", get_lan_ethernet_interface_number, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("LANWLANConfigurationNumberOfEntries", ctx, "0", get_lan_wlan_configuration_number, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANInterfaces.LANEthernetInterfaceConfig.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"LANInterfaces.WLANConfiguration.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_laninterface_lan, ctx); - SUBENTRY(entry_laninterface_wlan, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_laninterface_lan_instance(struct dmctx *ctx, char *li) -{ - DMOBJECT(DMROOT"LANInterfaces.LANEthernetInterfaceConfig.%s.", ctx, "0", 1, NULL, NULL, NULL, li); - DMPARAM("Alias", ctx, "1", get_lan_eth_int_alias, set_lan_eth_int_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_COM_EthName", ctx, "0", get_eth_name, NULL, NULL, 0, 1, UNDEF, NULL); - return 0; -} - -inline int entry_laninterface_wlan_instance(struct dmctx *ctx, char *wli) -{ - DMOBJECT(DMROOT"LANInterfaces.WLANConfiguration.%s.", ctx, "0", 1, NULL, NULL, NULL, wli); - DMPARAM("Alias", ctx, "1", get_wlan_conf_alias, set_wlan_conf_alias, NULL, 0, 1, UNDEF, NULL); - return 0; -} \ No newline at end of file diff --git a/dm/dmtree/tr098/lan_interfaces.h b/dm/dmtree/tr098/lan_interfaces.h index deb4e3a..084b502 100644 --- a/dm/dmtree/tr098/lan_interfaces.h +++ b/dm/dmtree/tr098/lan_interfaces.h @@ -4,16 +4,31 @@ struct linterfargs { char *linterf; - char *eths[16]; - int eths_size; struct uci_section *port_sec; }; -struct wifaceargs +struct ethrnet_ifaces_s { - struct uci_section *wiface_sec; + char *eths[16]; + int eths_size; }; -int entry_method_root_InternetGatewayDevice_LANInterfaces(struct dmctx *ctx); +bool check_laninterfaces(struct dmctx *dmctx, void *data); +extern DMLEAF tlaninterface_lanParam[]; +extern DMLEAF tlaninterface_wlanParam[]; +extern DMLEAF tLANInterfacesParam[]; +extern DMOBJ tLANInterfacesObj[]; -#endif \ No newline at end of file +int browselaninterface_lanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browselaninterface_wlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_lan_eth_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_conf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_ethernet_interface_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_wlan_configuration_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_lan_eth_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_conf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +#endif diff --git a/dm/dmtree/tr098/landevice.c b/dm/dmtree/tr098/landevice.c index ccd2b8f..b3801cc 100644 --- a/dm/dmtree/tr098/landevice.c +++ b/dm/dmtree/tr098/landevice.c @@ -29,80 +29,226 @@ #define MAX_PROC_ARP 256 #define DHCP_LEASE_FILE "/var/dhcp.leases" -inline int entry_landevice_sub_instance(struct dmctx *ctx, struct uci_section *landevice_section, char *idev); -inline int entry_landevice_ipinterface_instance (struct dmctx *ctx, char *idev, char *ilan); -inline int entry_landevice_dhcpstaticaddress_instance(struct dmctx *ctx, char *idev, char *idhcp); -inline int entry_landevice_wlanconfiguration_instance(struct dmctx *ctx, char *idev,char *iwlan); -inline int entry_landevice_wlanconfiguration_presharedkey_instance(struct dmctx *ctx, char *idev, char *iwlan, char *ipk); -inline int entry_landevice_wlanconfiguration_associateddevice(struct dmctx *ctx, char *idev, char *iwlan); -inline int entry_landevice_wlanconfiguration_associateddevice_instance(struct dmctx *ctx, char *idev, char *iwlan, char *idx); -inline int entry_landevice_lanethernetinterfaceconfig_instance(struct dmctx *ctx, char *idev, char *ieth); -inline int entry_landevice_host_instance(struct dmctx *ctx, char *idev, char *idx); -inline int entry_landevice_wlanconfiguration_wepkey_instance(struct dmctx *ctx, char *idev, char *iwlan, char *iwep); -inline int entry_landevice_dhcpconditionalservingpool_option_instance(struct dmctx *ctx, char * idev, char *icondpool, char *idx); -inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *ctx, char * idev, char *icondpool); -inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool(struct dmctx *ctx, char *idev); +/*** LANDevice.{i}. ***/ +DMLEAF tLANDeviceParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_lan_dev_alias, set_lan_dev_alias, NULL, NULL}, +{0} +}; -struct ldlanargs cur_lanargs = {0}; -struct ldipargs cur_ipargs = {0}; -struct lddhcpargs cur_dhcpargs = {0}; -struct ldwlanargs cur_wlanargs = {0}; -struct ldethargs cur_ethargs = {0}; -struct wlan_psk cur_pskargs = {0}; -struct wlan_wep cur_wepargs = {0}; -struct wl_clientargs cur_wl_clientargs = {0}; -struct clientargs cur_clientargs = {0}; -struct dhcppoolargs cur_dhcppoolargs = {0}; -struct dhcppooloptionargs cur_dhcppooloptionargs = {0}; +DMOBJ tLANDeviceObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"LANHostConfigManagement", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tLanhost_Config_ManagementObj, tLanhost_Config_ManagementParam, NULL}, +{"Hosts", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tlandevice_hostObj, tlandevice_hostsParam, NULL}, +{"LANEthernetInterfaceConfig", &DMREAD, NULL, NULL, NULL, browselanethernetinterfaceconfigInst, NULL, NULL, tlanethernetinterfaceconfigObj, tlanethernetinterfaceconfigParam, NULL}, +{"WLANConfiguration", &DMWRITE, add_landevice_wlanconfiguration, delete_landevice_wlanconfiguration, NULL, browseWlanConfigurationInst, NULL, NULL, tWlanConfigurationObj, tWlanConfigurationParam, NULL}, +{0} +}; -inline int init_ldargs_lan(struct dmctx *ctx, struct uci_section *s, char *iwan) +/*** LANDevice.{i}.LANHostConfigManagement. ***/ +DMOBJ tLanhost_Config_ManagementObj[] = { +{"IPInterface", &DMREAD, NULL, NULL, NULL, browseIPInterfaceInst, NULL, NULL, NULL, tIPInterfaceParam, get_linker_lanhost_interface}, +{"DHCPStaticAddress", &DMWRITE, add_landevice_dhcpstaticaddress, delete_landevice_dhcpstaticaddress, NULL, browseDhcp_static_addressInst, NULL, NULL, NULL, tDHCPStaticAddressParam, NULL}, +{"DHCPConditionalServingPool", &DMWRITE, add_dhcp_conditional_serving_pool, delete_dhcp_conditional_serving_pool, NULL, browselandevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance, NULL, NULL, tDHCPConditionalServingPoolobj, tDHCPConditionalServingPoolParam, NULL}, +{0} +}; + +DMLEAF tLanhost_Config_ManagementParam[] = { +{"DNSServers", &DMWRITE, DMT_STRING, get_lan_dns, set_lan_dns, NULL, NULL}, +{"DHCPServerConfigurable", &DMWRITE, DMT_BOOL, get_lan_dhcp_server_configurable, set_lan_dhcp_server_configurable, NULL, NULL}, +{"DHCPServerEnable", &DMWRITE, DMT_BOOL, get_lan_dhcp_server_enable, set_lan_dhcp_server_enable, NULL, NULL}, +{"MinAddress", &DMWRITE, DMT_STRING, get_lan_dhcp_interval_address_start, set_lan_dhcp_address_start, NULL, NULL}, +{"MaxAddress", &DMWRITE, DMT_STRING, get_lan_dhcp_interval_address_end, set_lan_dhcp_address_end, NULL, NULL}, +{"ReservedAddresses", &DMWRITE, DMT_STRING, get_lan_dhcp_reserved_addresses, set_lan_dhcp_reserved_addresses, NULL, NULL}, +{"SubnetMask", &DMWRITE, DMT_STRING, get_lan_dhcp_subnetmask, set_lan_dhcp_subnetmask, NULL, NULL}, +{"IPRouters", &DMWRITE, DMT_STRING, get_lan_dhcp_iprouters, set_lan_dhcp_iprouters, NULL, NULL}, +{"DHCPLeaseTime", &DMWRITE, DMT_STRING, get_lan_dhcp_leasetime, set_lan_dhcp_leasetime, NULL, NULL}, +{"DomainName", &DMWRITE, DMT_STRING, get_lan_dhcp_domainname, set_lan_dhcp_domainname, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.LANHostConfigManagement.IPInterface.{i}. ***/ +DMLEAF tIPInterfaceParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_lan_ip_int_alias, set_lan_ip_int_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_interface_enable_ipinterface, set_interface_enable_ipinterface, NULL, NULL}, +{"X_BROADCOM_COM_FirewallEnabled", &DMWRITE, DMT_BOOL, get_interface_firewall_enabled_ipinterface, set_interface_firewall_enabled_ipinterface, NULL, NULL}, +{"IPInterfaceIPAddress", &DMWRITE, DMT_STRING, get_interface_ipaddress, set_interface_ipaddress, NULL, NULL}, +{"IPInterfaceSubnetMask", &DMWRITE, DMT_STRING, get_interface_subnetmask, set_interface_subnetmask, NULL, NULL}, +{"IPInterfaceAddressingType", &DMWRITE, DMT_STRING, get_interface_addressingtype, set_interface_addressingtype, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.LANHostConfigManagement.DHCPStaticAddress.{i}. ***/ +DMLEAF tDHCPStaticAddressParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_dhcp_alias, set_dhcp_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_dhcpstaticaddress_enable, set_dhcpstaticaddress_enable, NULL, NULL}, +{"Chaddr", &DMWRITE, DMT_STRING, get_dhcpstaticaddress_chaddr, set_dhcpstaticaddress_chaddr, NULL, NULL}, +{"Yiaddr", &DMWRITE, DMT_STRING, get_dhcpstaticaddress_yiaddr, set_dhcpstaticaddress_yiaddr, NULL, NULL}, +{0} +}; + + +/*** LANDevice.{i}.Hosts. ***/ +DMOBJ tlandevice_hostObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Host", &DMREAD, NULL, NULL, NULL, browselandevice_hostInst, NULL, NULL, NULL, tlandevice_hostParam, NULL}, +{0} +}; + +DMLEAF tlandevice_hostsParam[] = { +{"HostNumberOfEntries", &DMREAD, DMT_UNINT, get_lan_host_nbr_entries, NULL, NULL, &DMNONE}, +{0} +}; + +/*** LANDevice.{i}.DHCPConditionalServingPool. ***/ +DMOBJ tDHCPConditionalServingPoolobj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"DHCPOption", &DMWRITE, add_dhcp_serving_pool_option, delete_dhcp_serving_pool_option, NULL, browseentry_landevice_dhcpconditionalservingpool_option_instance, NULL, NULL, NULL, tDHCPOptionParam, NULL}, +{0} +}; + +DMLEAF tDHCPConditionalServingPoolParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_dhcp_conditional_servingpool_alias, set_dhcp_conditional_servingpool_alias, NULL, &DMNONE}, +{"Enable", &DMWRITE, DMT_BOOL, get_dhcp_conditional_servingpool_enable, set_dhcp_conditionalservingpool_enable, NULL, &DMNONE}, +{"VendorClassID", &DMWRITE, DMT_STRING, get_dhcp_conditional_servingpool_vendorclassid, set_dhcp_conditional_servingpool_vendorclassid, NULL, &DMNONE}, +{"X_INTENO_COM_Networkid", &DMWRITE, DMT_STRING, get_dhcp_conditional_servingpool_network_id, set_dhcp_conditional_servingpool_network_id, NULL, &DMNONE}, +{0} +}; + +DMLEAF tDHCPOptionParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_dhcp_servingpool_alias, set_dhcp_servingpool_alias, NULL, &DMNONE}, +{"Tag", &DMWRITE, DMT_BOOL, get_dhcp_servingpool_tag, set_dhcp_servingpool_tag, NULL, &DMNONE}, +{"Value", &DMWRITE, DMT_UNINT, get_dhcp_servingpool_value, set_dhcp_servingpool_value, NULL, &DMNONE}, +{0} +}; + +/*** LANDevice.{i}.Hosts.Host.{i}. ***/ +DMLEAF tlandevice_hostParam[] = { +{"IPAddress", &DMREAD, DMT_STRING, get_lan_host_ipaddress, NULL, NULL, &DMNONE}, +{"HostName", &DMREAD, DMT_STRING, get_lan_host_hostname, NULL, NULL, &DMNONE}, +{"Active", &DMREAD, DMT_BOOL, get_lan_host_active, NULL, NULL, &DMNONE}, +{"MACAddress", &DMREAD, DMT_STRING, get_lan_host_macaddress, NULL, NULL, &DMNONE}, +{"InterfaceType", &DMREAD, DMT_STRING, get_lan_host_interfacetype, NULL, NULL, &DMNONE}, +{"AddressSource", &DMREAD, DMT_STRING, get_lan_host_addresssource, NULL, NULL, &DMNONE}, +{"LeaseTimeRemaining", &DMREAD, DMT_STRING, get_lan_host_leasetimeremaining, NULL, NULL, &DMNONE}, +{0} +}; + +/*** LANDevice.{i}.LANEthernetInterfaceConfig.{i}. ***/ +DMOBJ tlanethernetinterfaceconfigObj[] = { +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tlanethernetinterfaceStatsParam, NULL}, +{0} +}; + +DMLEAF tlanethernetinterfaceconfigParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_lan_eth_alias, set_lan_eth_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_lan_eth_iface_cfg_enable, set_lan_eth_iface_cfg_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_lan_eth_iface_cfg_status, NULL, NULL, NULL}, +{"MaxBitRate", &DMWRITE, DMT_STRING, get_lan_eth_iface_cfg_maxbitrate, set_lan_eth_iface_cfg_maxbitrate, NULL, NULL}, +{"DuplexMode", &DMWRITE, DMT_STRING, get_lan_eth_iface_cfg_duplexmode, set_lan_eth_iface_cfg_duplexmode, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.LANEthernetInterfaceConfig.{i}.Stats. ***/ +DMLEAF tlanethernetinterfaceStatsParam[] = { +{"BytesSent", &DMREAD, DMT_UNINT, get_lan_eth_iface_cfg_stats_tx_bytes, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_lan_eth_iface_cfg_stats_rx_bytes, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_lan_eth_iface_cfg_stats_tx_packets, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_lan_eth_iface_cfg_stats_rx_packets, NULL, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.WLANConfiguration.{i}. ***/ +DMOBJ tWlanConfigurationObj[] = { +{"WPS", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWPSParam, NULL}, +{"WEPKey", &DMREAD, NULL, NULL, NULL, browseWepKeyInst, NULL, NULL, NULL, tWepKeyParam, NULL}, +{"PreSharedKey", &DMREAD, NULL, NULL, NULL, browsepresharedkeyInst, NULL, NULL, NULL, tpresharedkeyParam, NULL}, +{"AssociatedDevice", &DMREAD, NULL, NULL, NULL, browseassociateddeviceInst, NULL, NULL, NULL, tassociateddeviceParam, NULL}, +{0} +}; + +DMLEAF tWlanConfigurationParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wlan_alias, set_wlan_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_wlan_enable, set_wlan_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_wlan_status, NULL, NULL, NULL}, +{"BSSID", &DMREAD, DMT_STRING, get_wlan_bssid, NULL, NULL, NULL}, +{"MaxBitRate", &DMWRITE, DMT_STRING, get_wlan_max_bit_rate, set_wlan_max_bit_rate, NULL, NULL}, +{"Channel", &DMWRITE, DMT_UNINT, get_wlan_channel, set_wlan_channel, NULL, NULL}, +{"AutoChannelEnable", &DMWRITE, DMT_BOOL, get_wlan_auto_channel_enable, set_wlan_auto_channel_enable, NULL, NULL}, +{"SSID", &DMWRITE, DMT_STRING, get_wlan_ssid, set_wlan_ssid, NULL, NULL}, +{"BeaconType", &DMWRITE, DMT_STRING, get_wlan_beacon_type, set_wlan_beacon_type, NULL, NULL}, +{"MACAddressControlEnabled", &DMWRITE, DMT_BOOL, get_wlan_mac_control_enable, set_wlan_mac_control_enable, NULL, NULL}, +{"PossibleChannels", &DMREAD, DMT_STRING, get_wlan_possible_channels, NULL, NULL, NULL}, +{"Standard", &DMWRITE, DMT_STRING, get_wlan_standard, set_wlan_standard, NULL, NULL}, +{"WEPKeyIndex", &DMWRITE, DMT_UNINT, get_wlan_wep_key_index, set_wlan_wep_key_index, NULL, NULL}, +{"KeyPassphrase", &DMWRITE, DMT_STRING, get_empty, set_wlan_key_passphrase, NULL, NULL}, +{"WEPEncryptionLevel", &DMREAD, DMT_STRING, get_wlan_wep_encryption_level, NULL, NULL, NULL}, +{"BasicEncryptionModes", &DMWRITE, DMT_STRING, get_wlan_basic_encryption_modes, set_wlan_basic_encryption_modes, NULL, NULL}, +{"BasicAuthenticationMode", &DMWRITE, DMT_STRING, get_wlan_basic_authentication_mode, set_wlan_basic_authentication_mode, NULL, NULL}, +{"WPAEncryptionModes", &DMWRITE, DMT_STRING, get_wlan_wpa_encryption_modes, set_wlan_wpa_encryption_modes, NULL, NULL}, +{"WPAAuthenticationMode", &DMWRITE, DMT_STRING, get_wlan_wpa_authentication_mode, set_wlan_wpa_authentication_mode, NULL, NULL}, +{"IEEE11iEncryptionModes", &DMWRITE, DMT_STRING, get_wlan_ieee_11i_encryption_modes, set_wlan_ieee_11i_encryption_modes, NULL, NULL}, +{"IEEE11iAuthenticationMode", &DMWRITE, DMT_STRING, get_wlan_ieee_11i_authentication_mode, set_wlan_ieee_11i_authentication_mode, NULL, NULL}, +{"RadioEnabled", &DMWRITE, DMT_BOOL, get_wlan_radio_enabled, set_wlan_radio_enabled, NULL, NULL}, +{"DeviceOperationMode", &DMWRITE, DMT_STRING, get_wlan_device_operation_mode, set_wlan_device_operation_mode, NULL, NULL}, +{"AuthenticationServiceMode", &DMWRITE, DMT_STRING, get_wlan_authentication_service_mode, set_wlan_authentication_service_mode, NULL, NULL}, +{"TotalAssociations", &DMREAD, DMT_UNINT, get_wlan_total_associations, NULL, NULL, NULL}, +{"ChannelsInUse", &DMWRITE, DMT_STRING, get_wlan_channel, set_wlan_channel, NULL, NULL}, +{"TotalBytesSent", &DMREAD, DMT_UNINT, get_wlan_devstatus_statistics_tx_bytes, NULL, NULL, NULL}, +{"TotalBytesReceived", &DMREAD, DMT_UNINT, get_wlan_devstatus_statistics_rx_bytes, NULL, NULL, NULL}, +{"TotalPacketsSent", &DMREAD, DMT_UNINT, get_wlan_devstatus_statistics_tx_packets, NULL, NULL, NULL}, +{"TotalPacketsReceived", &DMREAD, DMT_UNINT, get_wlan_devstatus_statistics_rx_packets, NULL, NULL, NULL}, +{"SSIDAdvertisementEnabled", &DMWRITE, DMT_BOOL, get_wlan_ssid_advertisement_enable, set_wlan_ssid_advertisement_enable, NULL, NULL}, +{"WMMEnable", &DMWRITE, DMT_BOOL, get_wmm_enabled, set_wmm_enabled, NULL, NULL}, +{"X_INTENO_SE_ChannelMode", &DMWRITE, DMT_STRING, get_x_inteno_se_channelmode, set_x_inteno_se_channelmode, NULL, NULL}, +{"X_INTENO_SE_SupportedStandards", &DMREAD, DMT_STRING, get_x_inteno_se_supported_standard, NULL, NULL, NULL}, +{"X_INTENO_SE_OperatingChannelBandwidth", &DMWRITE, DMT_STRING, get_x_inteno_se_operating_channel_bandwidth, set_x_inteno_se_operating_channel_bandwidth, NULL, NULL}, +{"X_INTENO_SE_MaxSSID", &DMWRITE, DMT_STRING, get_x_inteno_se_maxssid, set_x_inteno_se_maxssid, NULL, NULL}, +{"X_INTENO_SE_ScanTimer", &DMWRITE, DMT_STRING, get_x_inteno_se_scantimer, set_x_inteno_se_scantimer, NULL, NULL}, +{"X_INTENO_SE_Frequency", &DMWRITE, DMT_STRING, get_x_inteno_se_frequency, set_x_inteno_se_frequency, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.WLANConfiguration.{i}.WPS. ***/ +DMLEAF tWPSParam[] = { +{"Enable", &DMWRITE, DMT_BOOL, get_wlan_wps_enable, set_wlan_wps_enable, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.WLANConfiguration.{i}.WEPKey.{i}. ***/ +DMLEAF tWepKeyParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wlan_wep_alias, set_wlan_wep_alias, NULL, NULL}, +{"WEPKey", &DMWRITE, DMT_STRING, get_empty, set_wlan_wep_key1, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.WLANConfiguration.{i}.PreSharedKey.{i}. ***/ +DMLEAF tpresharedkeyParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wlan_psk_alias, set_wlan_psk_alias, NULL, NULL}, +{"PreSharedKey", &DMWRITE, DMT_STRING, get_empty, set_wlan_pre_shared_key, NULL, NULL}, +{"KeyPassphrase", &DMWRITE, DMT_STRING, get_empty, set_wlan_preshared_key_passphrase, NULL, NULL}, +{"AssociatedDeviceMACAddress", &DMREAD, DMT_STRING, get_wlan_psk_assoc_MACAddress, NULL, NULL, NULL}, +{0} +}; + +/*** LANDevice.{i}.WLANConfiguration.{i}.AssociatedDevice.{i}. ***/ +DMLEAF tassociateddeviceParam[] = { +{"AssociatedDeviceMACAddress", &DMREAD, DMT_STRING, get_wlan_associated_macaddress, NULL, NULL, &DMNONE}, +{"AssociatedDeviceIPAddress", &DMREAD, DMT_STRING, get_wlan_associated_ipddress, NULL, NULL, &DMNONE}, +{"AssociatedDeviceAuthenticationState", &DMREAD, DMT_BOOL, get_wlan_associated_authenticationstate, NULL, NULL, &DMNONE}, +{0} +}; + +inline int init_ldargs_lan(struct ldlanargs *args, struct uci_section *s, char *iwan) { - struct ldlanargs *args = &cur_lanargs; - ctx->args = (void *)args; args->ldlansection = s; args->ldinstance = iwan; return 0; } -inline int init_ldargs_ip(struct dmctx *ctx, struct uci_section *s) -{ - struct ldipargs *args = &cur_ipargs; - ctx->args = (void *)args; - args->ldipsection = s; - return 0; -} - -inline int init_ldargs_dhcp(struct dmctx *ctx, struct uci_section *s) -{ - struct lddhcpargs *args = &cur_dhcpargs; - ctx->args = (void *)args; - args->lddhcpsection = s; - return 0; -} - -inline int init_args_dhcp_conditional_servingpool_entry(struct dmctx *ctx, struct uci_section *s) -{ - struct dhcppoolargs *args = &cur_dhcppoolargs; - ctx->args = (void *)args; - args->dhcppoolsection = s; - return 0; -} - -inline int init_args_pool_option(struct dmctx *ctx, struct uci_section *s, struct uci_section *ss) -{ - struct dhcppooloptionargs *args = &cur_dhcppooloptionargs; - ctx->args = (void *)args; - args->dhcppooloptionsection = s; - args->dhcppoolsection = ss; - return 0; -} - -inline int init_ldargs_wlan(struct dmctx *ctx, struct uci_section *wifisection, int wlctl_num, +inline int init_ldargs_wlan(struct ldwlanargs *args, struct uci_section *wifisection, int wlctl_num, struct uci_section *device_section, char *wunit, char *wiface, json_object *res, int pki) { - struct ldwlanargs *args = &cur_wlanargs; - ctx->args = (void *)args; args->lwlansection = wifisection; args->device_section = device_section; args->res = res; @@ -113,58 +259,41 @@ inline int init_ldargs_wlan(struct dmctx *ctx, struct uci_section *wifisection, return 0; } -inline int init_ldargs_eth_cfg(struct dmctx *ctx, char *eth, struct uci_section *eth_section) +inline int init_ldargs_eth_cfg(struct ldethargs *args, char *eth, struct uci_section *eth_section) { - struct ldethargs *args = &cur_ethargs; - ctx->args = (void *)args; args->eth = eth; args->lan_ethsection = eth_section; return 0; } -inline int init_client_args(struct dmctx *ctx, json_object *clients, char *lan_name) +inline int init_client_args(struct clientargs *args, json_object *clients, char *lan_name) { - struct clientargs *args = &cur_clientargs; - ctx->args = (void *)args; args->client = clients; args->lan_name = lan_name; return 0; } -inline int init_wl_client_args(struct dmctx *ctx, char *value, char *wiface) +inline int init_wl_client_args(struct wl_clientargs *args, char *value, char *wiface) { - struct wl_clientargs *args = &cur_wl_clientargs; - ctx->args = (void *)args; args->mac = value; args->wiface = wiface; - return 0; } -inline int init_wlan_psk_args(struct dmctx *ctx, struct uci_section *s) +inline int init_args_pool_option(struct dhcppooloptionargs *args, struct uci_section *s, struct uci_section *ss) { - struct wlan_psk *args = &cur_pskargs; - ctx->args = (void *)args; - args->wlanpsk = s; + args->dhcppooloptionsection = s; + args->dhcppoolsection = ss; return 0; } - -inline int init_wlan_wep_args(struct dmctx *ctx, struct uci_section *s) -{ - struct wlan_wep *args = &cur_wepargs; - ctx->args = (void *)args; - args->wlanwep = s; - return 0; -} - -void update_dhcp_conf_start(int i, void *data) +void update_dhcp_conf_start(struct execute_end_session *ees) { json_object *res, *jobj; struct dmctx dmctx = {0}; - struct dhcp_param *dhcp_param = (struct dhcp_param *)(data); + struct dhcp_param *dhcp_param = (struct dhcp_param *)(ees->data); char *mask, *start, *dhcp_name, *ipaddr, buf[16]; - dm_ctx_init(&dmctx); + dm_ctx_init(&dmctx, ees->dm_type, ees->amd_version, ees->instance_mode); dmuci_get_option_value_string("network", dhcp_param->interface, "ipaddr", &ipaddr); if (ipaddr[0] == '\0') { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcp_param->interface, String}}, 1, &res); @@ -197,17 +326,18 @@ void update_dhcp_conf_start(int i, void *data) end: FREE(dhcp_param->state_sec); FREE(dhcp_param->interface); + FREE(dhcp_param); return; } -void update_dhcp_conf_end(int i, void *data) +void update_dhcp_conf_end(struct execute_end_session *ees) { json_object *res, *jobj; char *ipaddr, *mask, *start, *dhcp_name, *limit, buf[16], buf_start[16] = ""; - struct dhcp_param *dhcp_param = (struct dhcp_param *)(data); + struct dhcp_param *dhcp_param = (struct dhcp_param *)(ees->data); struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + dm_ctx_init(&dmctx, ees->dm_type, ees->amd_version, ees->instance_mode); dmuci_get_option_value_string("network", dhcp_param->interface, "ipaddr", &ipaddr); if (ipaddr[0] == '\0') { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcp_param->interface, String}}, 1, &res); @@ -251,8 +381,10 @@ void update_dhcp_conf_end(int i, void *data) end: FREE(dhcp_param->state_sec); FREE(dhcp_param->interface); + FREE(dhcp_param); return; } + int get_dhcp_option_last_inst(struct uci_section *ss) { char *drinst = NULL, *tmp; @@ -275,14 +407,15 @@ char *dhcp_option_update_instance_alias_icwmpd(int action, char **last_inst, voi char buf[8] = {0}; struct uci_section *s = (struct uci_section *) argv[0]; - char *inst_opt = (char *) argv[1]; - char *alias_opt = (char *) argv[2]; - bool *find_max = (bool *) argv[3]; + struct uci_section *ss = (struct uci_section *) argv[1]; + char *inst_opt = (char *) argv[2]; + char *alias_opt = (char *) argv[3]; + bool *find_max = (bool *) argv[4]; dmuci_get_value_by_section_string(s, inst_opt, &instance); if (instance[0] == '\0') { if (*find_max) { - int m = get_dhcp_option_last_inst(s); + int m = get_dhcp_option_last_inst(ss); sprintf(buf, "%d", m+1); *find_max = false; } @@ -306,84 +439,78 @@ char *dhcp_option_update_instance_alias_icwmpd(int action, char **last_inst, voi } return instance; } + /*******************ADD-DEL OBJECT*********************/ -int add_dhcp_serving_pool_option(struct dmctx *ctx, char **instancepara) +int add_dhcp_serving_pool_option(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char val[64]; char *value, *instance, *tmp; struct uci_section *s = NULL; - struct dhcppoolargs *poolargs = (struct dhcppoolargs *)ctx->args; + struct uci_section *poolargs = (struct uci_section *)data; - instance = get_last_instance(DMMAP, section_name(poolargs->dhcppoolsection), "optioninst"); - DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), &s, &value); + instance = get_last_instance(DMMAP, section_name(poolargs), "optioninst"); + DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(poolargs), &s, &value); DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "dhcp_option", "0"); *instancepara = update_instance_icwmpd(s, instance, "optioninst"); sprintf(val, "vendorclass%s", *instancepara); DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "value", val); sprintf(val, "0,vendorclass%s", *instancepara); - dmuci_add_list_value_by_section( poolargs->dhcppoolsection, "dhcp_option", val); + dmuci_add_list_value_by_section( poolargs, "dhcp_option", val); return 0; } -int delete_dhcp_serving_pool_option_all(struct dmctx *ctx) +int delete_dhcp_serving_pool_option(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct dhcppoolargs *poolargs = (struct dhcppoolargs *)ctx->args; - char *value; - char *instance; + char *value, *tag, *bufopt; struct uci_list *val; - struct uci_section *dmmap_s = NULL; + struct uci_section *dmmap_s = NULL, *dhcp_sec; struct uci_section *dmmap_ss = NULL; struct uci_element *e = NULL, *tmp; int dmmap = 0; - uci_path_foreach_sections(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), dmmap_s) - { - if (dmmap) - DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); - dmmap_ss = dmmap_s; - dmmap++; - } - if (dmmap_ss != NULL) - DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); - dmuci_get_value_by_section_list(poolargs->dhcppoolsection, "dhcp_option", &val); - if (val) { - uci_foreach_element_safe(val, e, tmp) - { - dmuci_del_list_value_by_section(poolargs->dhcppoolsection, "dhcp_option", tmp->name); //TODO test it - } - } - return 0; -} + struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)data; -int delete_dhcp_serving_pool_option(struct dmctx *ctx) -{ - int dmmap = 0; - char *value, *tag, *instance, *bufopt; - struct uci_list *val; - struct uci_section *dmmap_s = NULL; - struct uci_section *dmmap_ss = NULL; - struct uci_element *e = NULL, *tmp; - struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args; - - dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "dhcp_option", &tag); - dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "value", &value); - dmasprintf(&bufopt, "%s,%s", tag, value); - dmuci_get_value_by_section_list(pooloptionargs->dhcppoolsection, "dhcp_option", &val); - if (val) { - uci_foreach_element_safe(val, e, tmp) - { - if (strcmp(tmp->name, bufopt) == 0) { - dmuci_del_list_value_by_section(pooloptionargs->dhcppoolsection, "dhcp_option", tmp->name); //TODO test it - break; + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "dhcp_option", &tag); + dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "value", &value); + dmasprintf(&bufopt, "%s,%s", tag, value); + dmuci_get_value_by_section_list(pooloptionargs->dhcppoolsection, "dhcp_option", &val); + if (val) { + uci_foreach_element_safe(val, e, tmp) + { + if (strcmp(tmp->name, bufopt) == 0) { + dmuci_del_list_value_by_section(pooloptionargs->dhcppoolsection, "dhcp_option", tmp->name); //TODO test it + break; + } + } + } + dmfree(bufopt); + DMUCI_DELETE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, NULL, NULL); + return 0; + case DEL_ALL: + dhcp_sec = (struct uci_section *)data; + uci_path_foreach_sections(icwmpd, "dmmap", section_name(dhcp_sec), dmmap_s) + { + if (dmmap) + DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); + dmmap_ss = dmmap_s; + dmmap++; + } + if (dmmap_ss != NULL) + DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); + dmuci_get_value_by_section_list(dhcp_sec, "dhcp_option", &val); + if (val) { + uci_foreach_element_safe(val, e, tmp) + { + dmuci_del_list_value_by_section(dhcp_sec, "dhcp_option", tmp->name); //TODO test it + } } } - } - dmfree(bufopt); - DMUCI_DELETE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, NULL, NULL); - return 0; + return 0; } -int add_dhcp_conditional_serving_pool(struct dmctx *ctx, char **instancepara) +int add_dhcp_conditional_serving_pool(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char *instance; @@ -396,77 +523,73 @@ int add_dhcp_conditional_serving_pool(struct dmctx *ctx, char **instancepara) return 0; } -int delete_dhcp_conditional_serving_pool_all(struct dmctx *ctx) +int delete_dhcp_conditional_serving_pool(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - int found = 0; + struct uci_section *poolargs = (struct uci_section *)data; int dmmap = 0; - char *lan_name; + int found = 0; struct uci_section *s = NULL; struct uci_section *ss = NULL; struct uci_section *dmmap_s = NULL; struct uci_section *dmmap_ss = NULL; - uci_foreach_sections("dhcp", "vendorclass", s) { - if (found != 0) - { - uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), dmmap_s) + switch (del_action) { + case DEL_INST: + uci_path_foreach_sections(icwmpd, "dmmap", section_name(poolargs), dmmap_s) { - if (dmmap != 0) + if (dmmap) DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); dmmap_ss = dmmap_s; dmmap++; } if (dmmap_ss != NULL) DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); - dmmap = 0; - dmmap_ss = NULL; - dmuci_delete_by_section(ss, NULL, NULL); + dmuci_delete_by_section(poolargs, NULL, NULL); + return 0; + case DEL_ALL: + uci_foreach_sections("dhcp", "vendorclass", s) { + if (found != 0) + { + uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), dmmap_s) + { + if (dmmap != 0) + DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); + dmmap_ss = dmmap_s; + dmmap++; + } + if (dmmap_ss != NULL) + DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); + dmmap = 0; + dmmap_ss = NULL; + dmuci_delete_by_section(ss, NULL, NULL); + } + ss = s; + found++; + } + if (ss != NULL) + { + uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), dmmap_s) + { + if (dmmap != 0) + DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); + dmmap_ss = dmmap_s; + dmmap++; + } + if (dmmap_ss != NULL) + DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); + dmuci_delete_by_section(ss, NULL, NULL); + } + return 0; } - ss = s; - found++; - } - if (ss != NULL) - { - uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), dmmap_s) - { - if (dmmap != 0) - DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); - dmmap_ss = dmmap_s; - dmmap++; - } - if (dmmap_ss != NULL) - DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); - dmuci_delete_by_section(ss, NULL, NULL); - } return 0; } -int delete_dhcp_conditional_serving_pool(struct dmctx *ctx) -{ - struct dhcppoolargs *poolargs = (struct dhcppoolargs *)ctx->args; - int dmmap = 0; - struct uci_section *dmmap_s = NULL; - struct uci_section *dmmap_ss = NULL; - - - uci_path_foreach_sections(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), dmmap_s) - { - if (dmmap) - DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); - dmmap_ss = dmmap_s; - dmmap++; - } - if (dmmap_ss != NULL) - DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL); - dmuci_delete_by_section(poolargs->dhcppoolsection, NULL, NULL); - return 0; -} -int add_landevice_dhcpstaticaddress(struct dmctx *ctx, char **instancepara) +int add_landevice_dhcpstaticaddress(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char *instance; struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); instance = get_last_instance_lev2("dhcp", "host", "ldhcpinstance", "interface", lan_name); @@ -477,42 +600,44 @@ int add_landevice_dhcpstaticaddress(struct dmctx *ctx, char **instancepara) return 0; } -int delete_landevice_dhcpstaticaddress_all(struct dmctx *ctx) +int delete_landevice_dhcpstaticaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; char *lan_name; struct uci_section *s = NULL; struct uci_section *ss = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs; + struct uci_section *lddhcpsection; - lan_name = section_name(lanargs->ldlansection); - uci_foreach_option_eq("dhcp", "host", "interface", lan_name, s) { - if (found != 0) - dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; + switch (del_action) { + case DEL_INST: + lddhcpsection = (struct uci_section *)data; + dmuci_delete_by_section(lddhcpsection, NULL, NULL); + return 0; + case DEL_ALL: + lanargs = (struct ldlanargs *)data; + lan_name = section_name(lanargs->ldlansection); + uci_foreach_option_eq("dhcp", "host", "interface", lan_name, s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + return 0; } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - return 0; -} - -int delete_landevice_dhcpstaticaddress(struct dmctx *ctx) -{ - struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; - - dmuci_delete_by_section(dhcpargs->lddhcpsection, NULL, NULL); return 0; } -int add_landevice_wlanconfiguration(struct dmctx *ctx, char **instancepara) +int add_landevice_wlanconfiguration(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char ssid[16] = {0}; char *instance; struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); instance = get_last_instance_lev2("wireless", "wifi-iface", "lwlaninstance", "network", lan_name); @@ -528,31 +653,33 @@ int add_landevice_wlanconfiguration(struct dmctx *ctx, char **instancepara) return 0; } -int delete_landevice_wlanconfiguration_all(struct dmctx *ctx) +int delete_landevice_wlanconfiguration(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; char *lan_name; struct uci_section *s = NULL; struct uci_section *ss = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs; + struct ldwlanargs *wlanargs; - lan_name = section_name(lanargs->ldlansection); - uci_foreach_option_eq("wireless", "wifi-iface", "network", lan_name, s) { - if (found != 0) + switch (del_action) { + case DEL_INST: + wlanargs = (struct ldwlanargs *)data; + dmuci_delete_by_section(wlanargs->lwlansection, NULL, NULL); + return 0; + case DEL_ALL: + lanargs = (struct ldlanargs *)data; + lan_name = section_name(lanargs->ldlansection); + uci_foreach_option_eq("wireless", "wifi-iface", "network", lan_name, s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; + return 0; } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - return 0; -} - -int delete_landevice_wlanconfiguration(struct dmctx *ctx) -{ - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; - - dmuci_delete_by_section(wlanargs->lwlansection, NULL, NULL); return 0; } /******************************************************/ @@ -560,11 +687,11 @@ int delete_landevice_wlanconfiguration(struct dmctx *ctx) **** **** function related to landevice_lanhostconfigmanagement **** **** ***************************************************************************/ -int get_lan_dns(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dns(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; int len; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name, String}}, 1, &res); @@ -584,9 +711,9 @@ int get_lan_dns(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_lan_dns(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dns(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *dup, *p; switch (action) { @@ -608,10 +735,10 @@ int set_lan_dns(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; uci_foreach_option_eq("dhcp", "dhcp", "interface", section_name(lanargs->ldlansection), s) { *value = "1"; @@ -621,11 +748,11 @@ int get_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); switch (action) { @@ -653,10 +780,10 @@ int set_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { @@ -671,11 +798,11 @@ int get_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); switch (action) { @@ -702,11 +829,11 @@ enum enum_lanip_interval_address { LANIP_INTERVAL_END }; -int get_lan_dhcp_interval_address(struct dmctx *ctx, char **value, int option) +int get_lan_dhcp_interval_address(struct dmctx *ctx, void *data, char **value, int option) { json_object *res, *jobj; char *ipaddr = "" , *mask = "", *start , *limit; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); struct uci_section *s = NULL; char bufipstart[16], bufipend[16]; @@ -762,10 +889,10 @@ end: return 0; } -int get_lan_dhcp_interval_address_start(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_interval_address_start(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *s_name, *tmp; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); dmasprintf(&s_name, "@%s[0]", lan_name); @@ -776,14 +903,14 @@ int get_lan_dhcp_interval_address_start(char *refparam, struct dmctx *ctx, char *value = tmp; return 0; } - int ret = get_lan_dhcp_interval_address(ctx, value, LANIP_INTERVAL_START); + int ret = get_lan_dhcp_interval_address(ctx, data, value, LANIP_INTERVAL_START); return ret; } -int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *s_name, *tmp; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); dmasprintf(&s_name, "@%s[0]", lan_name); @@ -794,21 +921,21 @@ int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, char ** *value = tmp; return 0; } - int ret = get_lan_dhcp_interval_address(ctx, value, LANIP_INTERVAL_END); + int ret = get_lan_dhcp_interval_address(ctx, data, value, LANIP_INTERVAL_END); return ret; } -int set_lan_dhcp_address_start(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_address_start(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { json_object *res; char *ipaddr = "", *mask = "", *start , *limit, buf[16]; char *s_name = "", *tmp, *dhcp_name = NULL; struct uci_section *s = NULL; struct uci_section *curr_section = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); struct dhcp_param *dhcp_param_1; - + switch (action) { case VALUECHECK: return 0; @@ -819,7 +946,7 @@ int set_lan_dhcp_address_start(char *refparam, struct dmctx *ctx, int action, ch } if (!s) return 0; dmasprintf(&s_name, "@%s[0]", lan_name); - curr_section = dmuci_walk_state_section("cwmp", lan_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", lan_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", lan_name, &curr_section, &tmp); @@ -830,24 +957,24 @@ int set_lan_dhcp_address_start(char *refparam, struct dmctx *ctx, int action, ch dhcp_param_1 = calloc(1, sizeof(struct dhcp_param)); dhcp_param_1->interface = strdup(lan_name); dhcp_param_1->state_sec = strdup((curr_section)->e.name); - dm_add_end_session(&update_dhcp_conf_start, 0, (void*)(dhcp_param_1)); + dm_add_end_session(ctx, &update_dhcp_conf_start, 0, (void*)(dhcp_param_1)); return 0; } return 0; } -int set_lan_dhcp_address_end(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_address_end(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int i_val; json_object *res; char *ipaddr = "", *mask = "", *start, buf[16], *tmp, *s_name = NULL; struct uci_section *s = NULL; struct uci_section *curr_section = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); char *dhcp_name = NULL; struct dhcp_param *dhcp_param; - + switch (action) { case VALUECHECK: return 0; @@ -860,35 +987,35 @@ int set_lan_dhcp_address_end(char *refparam, struct dmctx *ctx, int action, char if (!s) return 0; dmasprintf(&s_name, "@%s[0]", lan_name); - curr_section = dmuci_walk_state_section("cwmp", lan_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", lan_name, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", lan_name, &curr_section, &tmp); - } + } dmuci_set_varstate_value("cwmp", s_name, "limit", value); dmuci_set_varstate_value("cwmp", s_name, "dhcp_sec", dhcp_name); dmfree(s_name); dhcp_param = calloc(1, sizeof(struct dhcp_param)); dhcp_param->interface = strdup(lan_name); dhcp_param->state_sec = strdup((curr_section)->e.name); - dm_add_end_session(&update_dhcp_conf_end, 0, (void*)(dhcp_param)); + dm_add_end_session(ctx, &update_dhcp_conf_end, 0, (void*)(dhcp_param)); return 0; } return 0; } -int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char val[512] = {0}, *p; struct uci_section *s = NULL; char *min, *max, *ip, *s_n_ip; unsigned int n_min, n_max, n_ip; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); *value = ""; - get_lan_dhcp_interval_address(ctx, &min, LANIP_INTERVAL_START); - get_lan_dhcp_interval_address(ctx, &max, LANIP_INTERVAL_END); + get_lan_dhcp_interval_address(ctx, data, &min, LANIP_INTERVAL_START); + get_lan_dhcp_interval_address(ctx, data, &max, LANIP_INTERVAL_END); if (min[0] == '\0' || max[0] == '\0') return 0; n_min = inet_network(min); @@ -910,22 +1037,22 @@ int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **va return 0; } -int set_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL; struct uci_section *dhcp_section = NULL; char *min, *max, *ip, *val, *local_value; char *pch, *spch; unsigned int n_min, n_max, n_ip; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); switch (action) { case VALUECHECK: return 0; case VALUESET: - get_lan_dhcp_interval_address(ctx, &min, LANIP_INTERVAL_START); - get_lan_dhcp_interval_address(ctx, &max, LANIP_INTERVAL_END); + get_lan_dhcp_interval_address(ctx, data, &min, LANIP_INTERVAL_START); + get_lan_dhcp_interval_address(ctx, data, &max, LANIP_INTERVAL_END); n_min = inet_network(min); n_max = inet_network(max); local_value = dmstrdup(value); @@ -958,9 +1085,9 @@ int set_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int actio return 0; } -int get_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); char *mask; json_object *res, *jobj; @@ -986,10 +1113,10 @@ int get_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); switch (action) { @@ -1005,9 +1132,9 @@ int set_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; dmuci_get_value_by_section_string(lanargs->ldlansection, "gateway", value); if ((*value)[0] == '\0') { @@ -1016,9 +1143,9 @@ int get_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; switch (action) { case VALUECHECK: @@ -1030,12 +1157,12 @@ int set_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int len, mtime = 0; char *ltime = "", *pch, *spch, *ltime_ini, *tmp, *tmp_ini; struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) { @@ -1099,11 +1226,11 @@ int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL; char buf[32]; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); switch (action) { @@ -1121,13 +1248,13 @@ int set_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *result, *str; struct uci_list *val; struct uci_element *e = NULL; struct uci_section *s = NULL; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); *value = ""; @@ -1146,15 +1273,15 @@ int get_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *result, *dn, *pch; struct uci_list *val; struct uci_section *s = NULL; struct uci_element *e = NULL, *tmp; char *option = "dhcp_option", buf[64]; - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); + struct ldlanargs *lanargs = (struct ldlanargs *)data; + char *lan_name = section_name(lanargs->ldlansection); switch (action) { case VALUECHECK: @@ -1180,12 +1307,12 @@ end: return 0; } -int get_lan_host_nbr_entries(char *refparam, struct dmctx *ctx, char **value) +int get_lan_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int entries = 0; char *network; json_object *res; - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; + struct ldlanargs *lanargs = (struct ldlanargs *)data; char *lan_name = section_name(lanargs->ldlansection); dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res); @@ -1205,44 +1332,40 @@ int get_lan_host_nbr_entries(char *refparam, struct dmctx *ctx, char **value) **** function related to landevice_lanhostconfigmanagement_ipinterface **** ***************************************************************************/ -int get_interface_enable_ipinterface(char *refparam, struct dmctx *ctx, char **value) +int get_interface_enable_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); + char *lan_name = section_name(((struct uci_section *)data)); return get_interface_enable_ubus(lan_name, refparam, ctx, value); } -int set_interface_enable_ipinterface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_interface_enable_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); + char *lan_name = section_name(((struct uci_section *)data)); return set_interface_enable_ubus(lan_name, refparam, ctx, action, value); } -int get_interface_firewall_enabled_ipinterface(char *refparam, struct dmctx *ctx, char **value) +int get_interface_firewall_enabled_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); + char *lan_name = section_name(((struct uci_section *)data)); return get_interface_firewall_enabled(lan_name, refparam, ctx, value); } -int set_interface_firewall_enabled_ipinterface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_interface_firewall_enabled_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); + char *lan_name = section_name(((struct uci_section *)data)); return set_interface_firewall_enabled(lan_name, refparam, ctx, action, value); } -int get_interface_ipaddress(char *refparam, struct dmctx *ctx, char **value) +int get_interface_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *proto; json_object *res, *jobj; - struct ldipargs *ipargs = (struct ldipargs *)ctx->args;//TO CHECK - char *lan_name = section_name(ipargs->ldipsection); + struct uci_section *ldipsection = (struct uci_section *)data; + char *lan_name = section_name(ldipsection); - dmuci_get_value_by_section_string(ipargs->ldipsection, "proto", &proto); + dmuci_get_value_by_section_string(ldipsection, "proto", &proto); if (strcmp(proto, "static") == 0) - dmuci_get_value_by_section_string(ipargs->ldipsection, "ipaddr", value); + dmuci_get_value_by_section_string(ldipsection, "ipaddr", value); else { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -1252,35 +1375,35 @@ int get_interface_ipaddress(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_interface_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value) +int set_interface_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; - char *lan_name = section_name(ipargs->ldipsection); - + struct uci_section *ldipsection = (struct uci_section *)data; + char *lan_name = section_name(ldipsection); + switch (action) { case VALUECHECK: return 0; case VALUESET: if (value[0] == '\0') return 0; - dmuci_set_value_by_section(ipargs->ldipsection, "ipaddr", value); + dmuci_set_value_by_section(ldipsection, "ipaddr", value); return 0; } return 0; } -int get_interface_subnetmask(char *refparam, struct dmctx *ctx, char **value) +int get_interface_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; + struct uci_section *ldipsection = (struct uci_section *)data; char *proto; char *val = NULL; json_object *res, *jobj; char *tmp; - char *lan_name = section_name(ipargs->ldipsection); + char *lan_name = section_name(ldipsection); - dmuci_get_value_by_section_string(ipargs->ldipsection, "proto", &proto); + dmuci_get_value_by_section_string(ldipsection, "proto", &proto); if (strcmp(proto, "static") == 0) - dmuci_get_value_by_section_string(ipargs->ldipsection, "netmask", value); + dmuci_get_value_by_section_string(ldipsection, "netmask", value); else { dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -1292,9 +1415,9 @@ int get_interface_subnetmask(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_interface_subnetmask(char *refparam, struct dmctx *ctx, int action, char *value) +int set_interface_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; + struct uci_section *ldipsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -1302,18 +1425,18 @@ int set_interface_subnetmask(char *refparam, struct dmctx *ctx, int action, char case VALUESET: if (value[0] == '\0') return 0; - dmuci_set_value_by_section(ipargs->ldipsection, "netmask", value); + dmuci_set_value_by_section(ldipsection, "netmask", value); return 0; } return 0; } -int get_interface_addressingtype (char *refparam, struct dmctx *ctx, char **value) +int get_interface_addressingtype (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; + struct uci_section *ldipsection = (struct uci_section *)data; *value = ""; - dmuci_get_value_by_section_string(ipargs->ldipsection, "proto", value); + dmuci_get_value_by_section_string(ldipsection, "proto", value); if (strcmp(*value, "static") == 0) *value = "Static"; else if (strcmp(*value, "dhcp") == 0) @@ -1321,18 +1444,18 @@ int get_interface_addressingtype (char *refparam, struct dmctx *ctx, char **valu return 0; } -int set_interface_addressingtype(char *refparam, struct dmctx *ctx, int action, char *value) +int set_interface_addressingtype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldipargs *ipargs = (struct ldipargs *)ctx->args; + struct uci_section *ldipsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: if (strcmp(value, "Static") == 0) - dmuci_set_value_by_section(ipargs->ldipsection, "proto", "static"); + dmuci_set_value_by_section(ldipsection, "proto", "static"); else if (strcmp(value, "DHCP") == 0) - dmuci_set_value_by_section(ipargs->ldipsection, "proto", "dhcp"); + dmuci_set_value_by_section(ldipsection, "proto", "dhcp"); return 0; } return 0; @@ -1342,12 +1465,12 @@ int set_interface_addressingtype(char *refparam, struct dmctx *ctx, int action, **** function related to get_landevice_lanhostconfigmanagement_dhcpstaticaddress **** **************************************************************************************/ -int get_dhcpstaticaddress_enable (char *refparam, struct dmctx *ctx, char **value) +int get_dhcpstaticaddress_enable (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *mac; - struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; + struct uci_section *lddhcpsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &mac); + dmuci_get_value_by_section_string(lddhcpsection, "mac", &mac); if (strcmp (mac, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) *value = "0"; else @@ -1355,11 +1478,11 @@ int get_dhcpstaticaddress_enable (char *refparam, struct dmctx *ctx, char **valu return 0; } -int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *chaddr; bool b; - struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; + struct uci_section *lddhcpsection = (struct uci_section *)data; switch (action) { case VALUECHECK: @@ -1368,12 +1491,12 @@ int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, int action, return 0; case VALUESET: string_to_bool(value, &b); - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &chaddr); + dmuci_get_value_by_section_string(lddhcpsection, "mac", &chaddr); if (b) { if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) { char *orig_chaddr; - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac_orig", &orig_chaddr); - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac", orig_chaddr); + dmuci_get_value_by_section_string(lddhcpsection, "mac_orig", &orig_chaddr); + dmuci_set_value_by_section(lddhcpsection, "mac", orig_chaddr); } else { return 0; } @@ -1382,9 +1505,9 @@ int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, int action, return 0; else { char *orig_chaddr; - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &orig_chaddr); - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac_orig", orig_chaddr); - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); + dmuci_get_value_by_section_string(lddhcpsection, "mac", &orig_chaddr); + dmuci_set_value_by_section(lddhcpsection, "mac_orig", orig_chaddr); + dmuci_set_value_by_section(lddhcpsection, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); } } return 0; @@ -1392,55 +1515,55 @@ int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, char **value) +int get_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *chaddr; - struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; + struct uci_section *lddhcpsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &chaddr); + dmuci_get_value_by_section_string(lddhcpsection, "mac", &chaddr); if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac_orig", value); + dmuci_get_value_by_section_string(lddhcpsection, "mac_orig", value); else *value = chaddr; return 0; } -int set_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *chaddr; - struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; + struct uci_section *lddhcpsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "mac", &chaddr); + dmuci_get_value_by_section_string(lddhcpsection, "mac", &chaddr); if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac_orig", value); + dmuci_set_value_by_section(lddhcpsection, "mac_orig", value); else - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "mac", value); + dmuci_set_value_by_section(lddhcpsection, "mac", value); return 0; } return 0; } -int get_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, char **value) +int get_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; + struct uci_section *lddhcpsection = (struct uci_section *)data; - dmuci_get_value_by_section_string(dhcpargs->lddhcpsection, "ip", value); + dmuci_get_value_by_section_string(lddhcpsection, "ip", value); return 0; } -int set_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct lddhcpargs *dhcpargs = (struct lddhcpargs *)ctx->args; + struct uci_section *lddhcpsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(dhcpargs->lddhcpsection, "ip", value); + dmuci_set_value_by_section(lddhcpsection, "ip", value); return 0; } return 0; @@ -1452,10 +1575,10 @@ int set_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, int action, **** function related to get_landevice_ethernet_interface_config **** **************************************************************************************/ -int get_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", ethargs->eth, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -1463,10 +1586,10 @@ int get_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, char **value return 0; } -int set_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; switch (action) { case VALUECHECK: @@ -1486,12 +1609,12 @@ int set_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_lan_eth_iface_cfg_status(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; bool b; - get_lan_eth_iface_cfg_enable(refparam, ctx, value); + get_lan_eth_iface_cfg_enable(refparam, ctx, data, instance, value); string_to_bool(*value, &b); if (b) *value = "Up"; @@ -1500,12 +1623,13 @@ int get_lan_eth_iface_cfg_status(char *refparam, struct dmctx *ctx, char **value return 0; } -int get_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *pch, *spch, *v; int len; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; struct uci_section *s; + *value = ""; uci_foreach_option_eq("ports", "ethport", "ifname", ethargs->eth, s) { @@ -1526,12 +1650,12 @@ int get_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *val = NULL; char *duplex; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; - struct uci_section *s, *sec = NULL; + struct ldethargs *ethargs = (struct ldethargs *)data; + struct uci_section *s, *sec; switch (action) { case VALUECHECK: @@ -1566,10 +1690,10 @@ int set_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp = ""; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; struct uci_section *s; uci_foreach_option_eq("ports", "ethport", "ifname", ethargs->eth, s) { @@ -1592,11 +1716,11 @@ int get_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *m, *spch, *rate, *val = NULL; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; - struct uci_section *s, *sec = NULL; + struct ldethargs *ethargs = (struct ldethargs *)data; + struct uci_section *s, *sec; switch (action) { case VALUECHECK: @@ -1634,10 +1758,10 @@ int set_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_lan_eth_iface_cfg_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", ethargs->eth, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -1645,10 +1769,10 @@ int get_lan_eth_iface_cfg_stats_tx_bytes(char *refparam, struct dmctx *ctx, char return 0; } -int get_lan_eth_iface_cfg_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", ethargs->eth, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -1656,10 +1780,10 @@ int get_lan_eth_iface_cfg_stats_rx_bytes(char *refparam, struct dmctx *ctx, char return 0; } -int get_lan_eth_iface_cfg_stats_tx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", ethargs->eth, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -1667,10 +1791,10 @@ int get_lan_eth_iface_cfg_stats_tx_packets(char *refparam, struct dmctx *ctx, ch return 0; } -int get_lan_eth_iface_cfg_stats_rx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_iface_cfg_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; + struct ldethargs *ethargs = (struct ldethargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", ethargs->eth, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -1715,47 +1839,47 @@ char *get_interface_type(char *mac, char *ndev) return "Ethernet"; } -int get_lan_host_ipaddress(char *refparam, struct dmctx *ctx, char **value) { - struct clientargs *clienlargs = (struct clientargs *)ctx->args; +int get_lan_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct clientargs *clienlargs = (struct clientargs *)data; *value = dm_ubus_get_value(clienlargs->client, 1, "ipaddr"); return 0; } -int get_lan_host_hostname(char *refparam, struct dmctx *ctx, char **value) { - struct clientargs *clienlargs = (struct clientargs *)ctx->args; +int get_lan_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct clientargs *clienlargs = (struct clientargs *)data; *value = dm_ubus_get_value(clienlargs->client, 1, "hostname"); return 0; } -int get_lan_host_active(char *refparam, struct dmctx *ctx, char **value) { - struct clientargs *clienlargs = (struct clientargs *)ctx->args; +int get_lan_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct clientargs *clienlargs = (struct clientargs *)data; *value = dm_ubus_get_value(clienlargs->client, 1, "connected"); return 0; } -int get_lan_host_macaddress(char *refparam, struct dmctx *ctx, char **value) { - struct clientargs *clienlargs = (struct clientargs *)ctx->args; +int get_lan_host_macaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct clientargs *clienlargs = (struct clientargs *)data; *value = dm_ubus_get_value(clienlargs->client, 1, "macaddr"); return 0; } -int get_lan_host_interfacetype(char *refparam, struct dmctx *ctx, char **value) +int get_lan_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *mac; - struct clientargs *clienlargs = (struct clientargs *)ctx->args; + struct clientargs *clienlargs = (struct clientargs *)data; mac = dm_ubus_get_value(clienlargs->client, 1, "macaddr"); *value = get_interface_type(mac, clienlargs->lan_name); return 0; } -int get_lan_host_addresssource(char *refparam, struct dmctx *ctx, char **value) { +int get_lan_host_addresssource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *dhcp; - struct clientargs *clienlargs = (struct clientargs *)ctx->args; + struct clientargs *clienlargs = (struct clientargs *)data; dhcp = dm_ubus_get_value(clienlargs->client, 1, "dhcp"); if (strcasecmp(dhcp, "true") == 0) @@ -1765,14 +1889,14 @@ int get_lan_host_addresssource(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_lan_host_leasetimeremaining(char *refparam, struct dmctx *ctx, char **value) +int get_lan_host_leasetimeremaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char buf[80], *dhcp; FILE *fp; char line[MAX_DHCP_LEASES]; struct tm ts; char *leasetime, *mac_f, *mac, *line1; - struct clientargs *clientlargs = (struct clientargs *)ctx->args; + struct clientargs *clientlargs = (struct clientargs *)data; char delimiter[] = " \t"; dhcp = dm_ubus_get_value(clientlargs->client, 1, "dhcp"); @@ -1810,11 +1934,11 @@ int get_lan_host_leasetimeremaining(char *refparam, struct dmctx *ctx, char **va /************************************************************************************** **** **** ****function related to get_landevice_wlanconfiguration_generic **** ******** ***************************************************************************************/ -int get_wlan_enable(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int i; char *val; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "disabled", &val); if (val[0] == '1') @@ -1824,10 +1948,10 @@ int get_wlan_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: if (string_to_bool(value, &b)) @@ -1844,38 +1968,38 @@ int set_wlan_enable(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_wlan_status (char *refparam, struct dmctx *ctx, char **value) +int get_wlan_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "disabled", &tmp); if (tmp[0] == '0' || tmp[0] == '\0') *value = "Up"; else if (tmp[0] == '1') - *value = "Disabled"; + *value = "Disabled"; return 0; } -int get_wlan_bssid(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; DM_ASSERT(wlanargs->res, *value = ""); *value = dmjson_get_value(wlanargs->res, 1, "bssid"); return 0; } -int get_wlan_max_bit_rate (char *refparam, struct dmctx *ctx, char **value) +int get_wlan_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "hwmode", value); return 0; } -int set_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -1886,9 +2010,9 @@ int set_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, int action, char *v return 0; } -int get_wlan_channel(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "channel", value); if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') { @@ -1898,9 +2022,9 @@ int get_wlan_channel(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_channel(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -1911,9 +2035,9 @@ int set_wlan_channel(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "channel", value); if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') *value = "1"; @@ -1922,10 +2046,10 @@ int get_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, char **value return 0; } -int set_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -1948,16 +2072,16 @@ int set_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_wlan_ssid(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "ssid", value); return 0; } -int set_wlan_ssid(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -1969,9 +2093,9 @@ int set_wlan_ssid(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_wlan_beacon_type(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_beacon_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", value); if (strcmp(*value, "none") == 0) @@ -1987,9 +2111,9 @@ int get_wlan_beacon_type(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_beacon_type(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_beacon_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *) ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; char *encryption, *option; char strk64[4][11]; @@ -2064,9 +2188,9 @@ int set_wlan_beacon_type(char *refparam, struct dmctx *ctx, int action, char *va return 0; } -int get_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; char *macfilter; dmuci_get_value_by_section_string(wlanargs->lwlansection, "macfilter", &macfilter); if (macfilter[0] != '0') @@ -2076,10 +2200,10 @@ int get_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: if (string_to_bool(value, &b)) @@ -2097,9 +2221,9 @@ int set_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, int action, c return 0; } -int get_wlan_standard(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "hwmode", value); if (strcmp(*value, "11b") == 0) *value = "b"; @@ -2112,9 +2236,9 @@ int get_wlan_standard(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_standard(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -2133,10 +2257,10 @@ int set_wlan_standard(char *refparam, struct dmctx *ctx, int action, char *value return 0; } -int get_wlan_possible_channels(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res, *jobj; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; *value = ""; dmubus_call("router.wireless", "radios", UBUS_ARGS{}, 0, &res); @@ -2145,9 +2269,9 @@ int get_wlan_possible_channels(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wlan_wep_key_index(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_wep_key_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; char *encryption; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(encryption, "wep-shared") == 0) @@ -2157,11 +2281,11 @@ int get_wlan_wep_key_index(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_wep_key_index(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_wep_key_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *option, *encryption; char strk64[4][11]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2187,31 +2311,11 @@ int set_wlan_wep_key_index(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int set_wlan_pre_shared_key(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); - if (!strstr(encryption, "psk")) { - reset_wlan(wlanargs->lwlansection); - dmuci_set_value_by_section(wlanargs->lwlansection, "gtk_rekey", "3600"); - dmuci_set_value_by_section(wlanargs->lwlansection, "encryption", "psk"); - } - dmuci_set_value_by_section(wlanargs->lwlansection, "key", value); - return 0; - } - return 0; -} - -int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *option, *encryption; char strk64[4][11]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -2229,22 +2333,22 @@ int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, int action, char } else if (strcmp(encryption, "none") == 0) return 0; else - return set_wlan_pre_shared_key(refparam, ctx, action, value); + return set_wlan_pre_shared_key(refparam, ctx, data, instance, value, action); return 0; } return 0; } -int get_wlan_wep_encryption_level(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_wep_encryption_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "40-bit, 104-bit"; return 0; } -int get_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "wep-open") == 0) @@ -2254,12 +2358,12 @@ int get_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, char **va return 0; } -int set_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *option, *encryption; char strk64[4][11]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2289,10 +2393,10 @@ int set_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, int actio return 0; } -int get_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(encryption, "wep-shared") == 0) @@ -2302,11 +2406,11 @@ int get_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, char * return 0; } -int set_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *encryption, *option; char strk64[4][11]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -2335,10 +2439,10 @@ int set_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; *value = ""; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); @@ -2351,10 +2455,10 @@ int get_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, char **valu return 0; } -int set_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -2395,10 +2499,10 @@ int set_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); *value = ""; if (strcmp(encryption, "psk") == 0 || strncmp(encryption, "psk+", 4) == 0 || strncmp(encryption, "mixed-psk", 9) == 0) @@ -2408,10 +2512,10 @@ int get_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2442,10 +2546,10 @@ int set_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); *value = ""; @@ -2458,11 +2562,11 @@ int get_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, char * return 0; } -int set_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2507,10 +2611,10 @@ int set_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); *value = ""; if (strcmp(encryption, "psk2") == 0 || strncmp(encryption, "psk2+", 5) == 0 || strncmp(encryption, "mixed-psk", 9) == 0 ) @@ -2520,10 +2624,10 @@ int get_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, cha return 0; } -int set_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2555,10 +2659,10 @@ int set_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, int return 0; } -int get_wlan_radio_enabled(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_radio_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "disabled", &tmp); if (tmp[0] == '0' || tmp[0] == '\0') @@ -2568,11 +2672,11 @@ int get_wlan_radio_enabled(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_radio_enabled(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_radio_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *wunit, buf[8]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: if (string_to_bool(value, &b)) @@ -2589,9 +2693,9 @@ int set_wlan_radio_enabled(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "mode", value); if (strcmp(*value, "ap") == 0) @@ -2601,9 +2705,9 @@ int get_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, char **val return 0; } -int set_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -2615,10 +2719,10 @@ int set_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, int action return 0; } -int get_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0) @@ -2628,10 +2732,10 @@ int get_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, char return 0; } -int set_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *encryption; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2656,12 +2760,12 @@ int set_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, int return 0; } -int get_wlan_total_associations(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int i = 0; json_object *res; char *wunit, buf[8]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", wlanargs->wiface, String}}, 1, &res); DM_ASSERT(res, *value = "0"); @@ -2673,9 +2777,9 @@ int get_wlan_total_associations(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wlan_devstatus_statistics_tx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_devstatus_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wlanargs->wiface, String}}, 1, &res); @@ -2684,10 +2788,10 @@ int get_wlan_devstatus_statistics_tx_bytes(char *refparam, struct dmctx *ctx, ch return 0; } -int get_wlan_devstatus_statistics_rx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_devstatus_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wlanargs->wiface, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -2695,10 +2799,10 @@ int get_wlan_devstatus_statistics_rx_bytes(char *refparam, struct dmctx *ctx, ch return 0; } -int get_wlan_devstatus_statistics_tx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_devstatus_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wlanargs->wiface, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -2706,11 +2810,11 @@ int get_wlan_devstatus_statistics_tx_packets(char *refparam, struct dmctx *ctx, return 0; } -int get_wlan_devstatus_statistics_rx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_devstatus_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *val = NULL; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wlanargs->wiface, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -2718,10 +2822,10 @@ int get_wlan_devstatus_statistics_rx_packets(char *refparam, struct dmctx *ctx, return 0; } -int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *hidden; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "hidden", &hidden); if (hidden[0] == '1' && hidden[1] == '\0') *value = "0"; @@ -2730,10 +2834,10 @@ int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, char * return 0; } -int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2752,10 +2856,10 @@ int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_wlan_wps_enable(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_wps_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *wps_pbc; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "wps_pbc", &wps_pbc); if (wps_pbc[0] == '1' && wps_pbc[1] == '\0') *value = "1"; @@ -2764,10 +2868,10 @@ int get_wlan_wps_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wlan_wps_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_wps_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2785,9 +2889,9 @@ int set_wlan_wps_enable(char *refparam, struct dmctx *ctx, int action, char *val return 0; } -int get_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "channel", value); if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') *value = "Auto"; @@ -2796,10 +2900,10 @@ int get_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *channel; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2819,10 +2923,10 @@ int set_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, int action, c return 0; } -int get_x_inteno_se_supported_standard(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_se_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *freq; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; DM_ASSERT(wlanargs->res, *value = "b, g, n, gst, lrs"); freq = dmjson_get_value(wlanargs->res, 1, "frequency"); @@ -2833,25 +2937,25 @@ int get_x_inteno_se_supported_standard(char *refparam, struct dmctx *ctx, char * return 0; } -int get_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *bandwith; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->device_section, "bandwidth", value); - if (value[0] == '\0') + if (*value[0] == '\0') { - DM_ASSERT(wlanargs->res, *value =""); + DM_ASSERT(wlanargs->res, *value = ""); bandwith = dmjson_get_value(wlanargs->res, 1, "bandwidth"); - dmastrcat(value, bandwith, "MHz"); // MEM WILL BE FREED IN DMMEMCLEAN } + dmastrcat(value, *value, "MHz"); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } -int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *pch, *spch, *dup; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2866,17 +2970,17 @@ int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ct return 0; } -int get_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; dmuci_get_value_by_section_string(wlanargs->lwlansection, "bss_max", value); return 0; } -int set_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -2889,58 +2993,58 @@ int set_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, int action, char return 0; } -int set_wlan_wep_key(char *refparam, struct dmctx *ctx, int action, char *value, char *key_index) +int set_wlan_wep_key(char *refparam, struct dmctx *ctx, void *data, char *instance, int action, char *value, char *key_index) { char *encryption, *option; char strk64[4][11]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct wlan_wep *wepargs = (struct wlan_wep *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); + dmuci_get_value_by_section_string(wepargs->lwlansection, "encryption", &encryption); if (strcmp(encryption, "wep-shared") != 0 && strcmp(encryption, "wep-open") != 0) { - reset_wlan(wlanargs->lwlansection); - dmuci_set_value_by_section(wlanargs->lwlansection, "encryption", "wep-open"); + reset_wlan(wepargs->lwlansection); + dmuci_set_value_by_section(wepargs->lwlansection, "encryption", "wep-open"); wepkey64("Inteno", strk64); int i = 0; while (i < 4) { dmasprintf(&option, "key%d", i + 1); - dmuci_set_value_by_section(wlanargs->lwlansection, option, strk64[i]); + dmuci_set_value_by_section(wepargs->lwlansection, option, strk64[i]); dmfree(option); i++; } - dmuci_set_value_by_section(wlanargs->lwlansection, "key", "1"); + dmuci_set_value_by_section(wepargs->lwlansection, "key", "1"); } - dmuci_set_value_by_section(wlanargs->lwlansection, key_index, value); + dmuci_set_value_by_section(wepargs->lwlansection, key_index, value); return 0; } return 0; } -int set_wlan_wep_key1(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_wep_key1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char buf[8]; - sprintf(buf, "key%d", cur_wepargs.key_index); - return set_wlan_wep_key(refparam, ctx, action, value, buf); + sprintf(buf, "key%d", ((struct wlan_wep *)data)->key_index); + return set_wlan_wep_key(refparam, ctx, data, instance, action, value, buf); } /****************************************************************************************/ -int get_wlan_associated_macaddress(char *refparam, struct dmctx *ctx, char **value) { - struct wl_clientargs *clientwlargs = (struct wl_clientargs *)ctx->args; +int get_wlan_associated_macaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct wl_clientargs *clientwlargs = (struct wl_clientargs *)data; *value = dmstrdup(clientwlargs->mac); return 0; } -int get_wlan_associated_ipddress(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_associated_ipddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { FILE *fp; char *ip, *mac, *line1; char delimiter[] = " \t"; char line[MAX_PROC_ARP]; - struct wl_clientargs *clientwlargs = (struct wl_clientargs *)ctx->args; + struct wl_clientargs *clientwlargs = (struct wl_clientargs *)data; fp = fopen(ARP_FILE, "r"); if ( fp != NULL) @@ -2964,8 +3068,8 @@ int get_wlan_associated_ipddress(char *refparam, struct dmctx *ctx, char **value return 0; } -int get_wlan_associated_authenticationstate(char *refparam, struct dmctx *ctx, char **value) { - struct wl_clientargs *clientwlargs = (struct wl_clientargs *)ctx->args; +int get_wlan_associated_authenticationstate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { + struct wl_clientargs *clientwlargs = (struct wl_clientargs *)data; char buf[256]; int pp, r; *value = "0"; @@ -2982,17 +3086,65 @@ int get_wlan_associated_authenticationstate(char *refparam, struct dmctx *ctx, c return 0; } -int get_wlan_psk_assoc_MACAddress(char *refparam, struct dmctx *ctx, char **value) +int set_wlan_pre_shared_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + struct wlan_psk *pskargs = (struct wlan_psk *)data; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(pskargs->lwlansection, "encryption", &encryption); + if (!strstr(encryption, "psk")) { + reset_wlan(pskargs->lwlansection); + dmuci_set_value_by_section(pskargs->lwlansection, "gtk_rekey", "3600"); + dmuci_set_value_by_section(pskargs->lwlansection, "encryption", "psk"); + } + dmuci_set_value_by_section(pskargs->lwlansection, "key", value); + return 0; + } + return 0; +} + +int set_wlan_preshared_key_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *option, *encryption; + char strk64[4][11]; + struct wlan_psk *pskargs = (struct wlan_psk *)data; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(pskargs->lwlansection, "encryption", &encryption); + if (strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "wep-open") == 0) { + wepkey64("Inteno", strk64); + int i = 0; + while (i < 4) { + dmasprintf(&option, "key%d", i + 1); + dmuci_set_value_by_section(pskargs->lwlansection, option, strk64[i]); + dmfree(option); + i++; + } + } else if (strcmp(encryption, "none") == 0) + return 0; + else + return set_wlan_pre_shared_key(refparam, ctx, data, instance, value, action); + return 0; + } + return 0; +} + +int get_wlan_psk_assoc_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *wunit, *encryption, buf[8]; char sta_pki[8]; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct wlan_psk *pskargs = (struct wlan_psk *)data; - dmuci_get_value_by_section_string(wlanargs->lwlansection, "encryption", &encryption); + dmuci_get_value_by_section_string(pskargs->lwlansection, "encryption", &encryption); if (strstr(encryption, "psk")) { - sprintf(sta_pki, "sta-%d", wlanargs->pki); - dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", wlanargs->wiface, String}}, 1, &res); + sprintf(sta_pki, "sta-%d", pskargs->pki); + dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", pskargs->wiface}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, sta_pki, "macaddr"); return 0; @@ -3001,17 +3153,17 @@ int get_wlan_psk_assoc_MACAddress(char *refparam, struct dmctx *ctx, char **valu return 0; } -int get_x_inteno_se_scantimer(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_se_scantimer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; *value = "0"; dmuci_get_value_by_section_string(wlanargs->device_section, "scantimer", value); return 0; } -int set_x_inteno_se_scantimer(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_se_scantimer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -3023,9 +3175,9 @@ int set_x_inteno_se_scantimer(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_wmm_enabled(char *refparam, struct dmctx *ctx, char **value) +int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; bool b; dmuci_get_value_by_section_string(wlanargs->device_section, "wmm", value); @@ -3038,10 +3190,10 @@ int get_wmm_enabled(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, char **value) +int get_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *freq; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; DM_ASSERT(wlanargs->res, *value = ""); freq = dmjson_get_value(wlanargs->res, 1, "frequency"); @@ -3049,12 +3201,12 @@ int get_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, int action, char *value) +int set_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *freq = NULL; json_object *res = NULL; struct uci_section *s = NULL; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; switch (action) { case VALUECHECK: @@ -3086,15 +3238,16 @@ int set_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, int action, cha } return 0; } -int set_wmm_enabled(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)data; bool b; switch (action) { case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; + break; case VALUESET: string_to_bool(value, &b); if (b) { @@ -3130,157 +3283,162 @@ void lan_eth_update_section_option_list (char *name, char *sec_name, char *wan_e dmfree(ifname); } /////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_lan_dev_alias(char *refparam, struct dmctx *ctx, char **value) +int get_lan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_lanargs.ldlansection, "ldalias", value); + dmuci_get_value_by_section_string(((struct ldlanargs *)data)->ldlansection, "ldalias", value); return 0; } -int set_lan_dev_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_lanargs.ldlansection, "ldalias", value); + dmuci_set_value_by_section(((struct ldlanargs *)data)->ldlansection, "ldalias", value); return 0; } return 0; } -int get_lan_ip_int_alias(char *refparam, struct dmctx *ctx, char **value) +int get_lan_ip_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ipargs.ldipsection, "lipalias", value); + struct uci_section *ldipsection = (struct uci_section *)data; + dmuci_get_value_by_section_string(ldipsection, "lipalias", value); return 0; } -int set_lan_ip_int_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_ip_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *ldipsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ipargs.ldipsection, "lipalias", value); + dmuci_set_value_by_section(ldipsection, "lipalias", value); return 0; } return 0; } -int get_dhcp_alias(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dhcpargs.lddhcpsection, "ldhcpalias", value); + struct uci_section *lddhcpsection = (struct uci_section *)data; + dmuci_get_value_by_section_string(lddhcpsection, "ldhcpalias", value); return 0; } -int set_dhcp_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { + struct uci_section *lddhcpsection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dhcpargs.lddhcpsection, "ldhcpalias", value); + dmuci_set_value_by_section(lddhcpsection, "ldhcpalias", value); return 0; } return 0; } -int get_wlan_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wlanargs.lwlansection, "lwlanalias", value); + dmuci_get_value_by_section_string(((struct ldwlanargs *)data)->lwlansection, "lwlanalias", value); return 0; } -int set_wlan_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wlanargs.lwlansection, "lwlanalias", value); + dmuci_set_value_by_section(((struct ldwlanargs *)data)->lwlansection, "lwlanalias", value); return 0; } return 0; } -int get_wlan_psk_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_psk_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_pskargs.wlanpsk, "pskalias", value); + dmuci_get_value_by_section_string(((struct wlan_psk *)data)->wlanpsk, "pskalias", value); return 0; } -int set_wlan_psk_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_psk_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_pskargs.wlanpsk, "pskalias", value); + dmuci_set_value_by_section(((struct wlan_psk *)data)->wlanpsk, "pskalias", value); return 0; } return 0; } -int get_wlan_wep_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wlan_wep_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wepargs.wlanwep, "wepalias", value); + dmuci_get_value_by_section_string(((struct wlan_wep *)data)->wlanwep, "wepalias", value); return 0; } -int set_wlan_wep_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wlan_wep_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wepargs.wlanwep, "wepalias", value); + dmuci_set_value_by_section(((struct wlan_wep *)data)->wlanwep, "wepalias", value); return 0; } return 0; } -int get_lan_eth_alias(char *refparam, struct dmctx *ctx, char **value) +int get_lan_eth_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ethargs.lan_ethsection, "ethalias", value); + dmuci_get_value_by_section_string(((struct ldethargs *)data)->lan_ethsection, "ethalias", value); return 0; } -int set_lan_eth_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_lan_eth_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ethargs.lan_ethsection, "ethalias", value); + dmuci_set_value_by_section(((struct ldethargs *)data)->lan_ethsection, "ethalias", value); return 0; } return 0; } -int get_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, char **value) + +int get_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dhcppoolargs.dhcppoolsection, "poulalias", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "poulalias", value); return 0; } -int set_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dhcppoolargs.dhcppoolsection, "poulalias", value); + dmuci_set_value_by_section((struct uci_section *)data, "poulalias", value); return 0; } return 0; } -int get_dhcp_conditional_servingpool_enable(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_conditional_servingpool_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dhcppoolargs.dhcppoolsection, "enable", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "enable", value); return 0; } -int set_dhcp_conditionalservingpool_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_conditionalservingpool_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -3292,63 +3450,63 @@ int set_dhcp_conditionalservingpool_enable(char *refparam, struct dmctx *ctx, in case VALUESET: string_to_bool(value, &b); if (b) { - dmuci_set_value_by_section(cur_dhcppoolargs.dhcppoolsection, "enable", ""); + dmuci_set_value_by_section((struct uci_section *)data, "enable", ""); } else { - dmuci_set_value_by_section(cur_dhcppoolargs.dhcppoolsection, "enable", "0"); + dmuci_set_value_by_section((struct uci_section *)data, "enable", "0"); } return 0; } return 0; } -int get_dhcp_conditional_servingpool_vendorclassid(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_conditional_servingpool_vendorclassid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dhcppoolargs.dhcppoolsection, "vendorclass", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "vendorclass", value); return 0; } -int set_dhcp_conditional_servingpool_vendorclassid(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_conditional_servingpool_vendorclassid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dhcppoolargs.dhcppoolsection, "vendorclass", value); + dmuci_set_value_by_section((struct uci_section *)data, "vendorclass", value); return 0; } return 0; } -int get_dhcp_conditional_servingpool_network_id(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_conditional_servingpool_network_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dhcppoolargs.dhcppoolsection, "networkid", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "networkid", value); return 0; } -int set_dhcp_conditional_servingpool_network_id(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_conditional_servingpool_network_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dhcppoolargs.dhcppoolsection, "networkid", value); + dmuci_set_value_by_section((struct uci_section *)data, "networkid", value); return 0; } return 0; } -int get_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args; + struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)data; dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "optionalias", value); return 0; } -int set_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args; + struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)data; switch (action) { case VALUECHECK: @@ -3361,19 +3519,19 @@ int set_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, int action, ch } -int get_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args; + struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)data; dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "dhcp_option", value); return 0; } -int set_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp = NULL; char *option_tmp = NULL; - struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args; + struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)data; switch (action) { case VALUECHECK: @@ -3388,19 +3546,19 @@ int set_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args; + struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)data; dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "value", value); return 0; } -int set_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; - struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args; + struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)data; switch (action) { case VALUECHECK: @@ -3414,134 +3572,90 @@ int set_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, int action, ch } return 0; } -/////////////SUB ENTRIES/////////////// -inline int entry_landevice_sub(struct dmctx *ctx) +/************************************************************************** +* LINKER +***************************************************************************/ + +int get_linker_lanhost_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + + struct uci_section *ldipsection = (struct uci_section *)data; + if(ldipsection) { + dmasprintf(linker,"linker_interface:%s", section_name(ldipsection)); + return 0; + } + *linker = ""; + return 0; +} + + + +int browselandeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *idev = NULL, *idev_last = NULL; + struct ldlanargs curr_lanargs = {0}; uci_foreach_filter_func("network", "interface", NULL, &filter_lan_device_interface, s) { - idev = handle_update_instance(1, ctx, &idev_last, update_instance_alias, 3, s, "ldinstance", "ldalias"); - init_ldargs_lan(ctx, s, idev); - SUBENTRY(entry_landevice_sub_instance, ctx, s, idev); + idev = handle_update_instance(1, dmctx, &idev_last, update_instance_alias, 3, s, "ldinstance", "ldalias"); + init_ldargs_lan(&curr_lanargs, s, idev); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_lanargs, idev) == DM_STOP) + break; } return 0; } -inline int entry_landevice_ipinterface_and_dhcpstaticaddress(struct dmctx *ctx, struct uci_section *landevice_section, char *idev) +int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *ss = NULL; struct uci_section *sss = NULL; char *ilan = NULL, *ilan_last = NULL; char *idhcp = NULL, *idhcp_last = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)prev_data; - uci_foreach_filter_func("network", "interface", landevice_section, filter_lan_ip_interface, ss) { - ilan = handle_update_instance(2, ctx, &ilan_last, update_instance_alias, 3, ss, "lipinstance", "lipalias"); - init_ldargs_ip(ctx, ss); - SUBENTRY(entry_landevice_ipinterface_instance, ctx, idev, ilan); - uci_foreach_option_cont("dhcp", "host", "interface", section_name(ss), sss) { - idhcp = handle_update_instance(2, ctx, &idhcp_last, update_instance_alias, 3, sss, "ldhcpinstance", "ldhcpalias"); - init_ldargs_dhcp(ctx, sss); - SUBENTRY(entry_landevice_dhcpstaticaddress_instance, ctx, idev, idhcp); - } + uci_foreach_filter_func("network", "interface", lanargs->ldlansection, filter_lan_ip_interface, ss) { + ilan = handle_update_instance(2, dmctx, &ilan_last, update_instance_alias, 3, ss, "lipinstance", "lipalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ss, ilan) == DM_STOP) + break; + /*SUBENTRY(entry_landevice_ipinterface_instance, ctx, idev, ilan); + uci_foreach_option_cont("dhcp", "host", "interface", section_name(ss), sss) { + idhcp = handle_update_instance(2, ctx, &idhcp_last, update_instance_alias, 3, sss, "ldhcpinstance", "ldhcpalias"); + init_ldargs_dhcp(ctx, sss); + SUBENTRY(entry_landevice_dhcpstaticaddress_instance, ctx, idev, idhcp); + }*/ } return 0; } -inline int entry_landevice_wlanconfiguration(struct dmctx *ctx, struct uci_section *landevice_section, char *idev) +int browseDhcp_static_addressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *ss = NULL; struct uci_section *sss = NULL; - json_object *res; - char *iwlan = NULL, *iwlan_last = NULL; - char *network , *wiface, buf[8]; + char *ilan = NULL, *ilan_last = NULL; + char *idhcp = NULL, *idhcp_last = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)prev_data; - iwlan = get_last_instance_lev2("wireless", "wifi-iface", "lwlaninstance", "network", section_name(landevice_section)); - uci_foreach_sections("wireless", "wifi-device", ss) { - int wlctl_num=0; - uci_foreach_option_eq("wireless", "wifi-iface", "device", section_name(ss), sss) { - dmuci_get_value_by_section_string(sss, "network", &network); - if (strcmp(network, section_name(landevice_section)) != 0) - continue; - iwlan = handle_update_instance(2, ctx, &iwlan_last, update_instance_alias, 3, sss, "lwlaninstance", "lwlanalias"); - wiface = section_name(ss); - if (wlctl_num != 0) { - sprintf(buf, "%s.%d", wiface, wlctl_num); - wiface = buf; - } - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wiface, String}}, 1, &res); - init_ldargs_wlan(ctx, sss, wlctl_num, ss, section_name(ss), wiface, res, 0); - wlctl_num++; - SUBENTRY(entry_landevice_wlanconfiguration_instance, ctx, idev, iwlan); + uci_foreach_filter_func("network", "interface", lanargs->ldlansection, filter_lan_ip_interface, ss) { + ilan = handle_update_instance(2, dmctx, &ilan_last, update_instance_alias, 3, ss, "lipinstance", "lipalias"); + uci_foreach_option_cont("dhcp", "host", "interface", section_name(ss), sss) { + idhcp = handle_update_instance(2, dmctx, &idhcp_last, update_instance_alias, 3, sss, "ldhcpinstance", "ldhcpalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)sss, idhcp) == DM_STOP) + goto end; } } +end: return 0; } -inline int entry_landevice_wlanconfiguration_wepkey(struct dmctx *ctx, char *idev, char *iwlan) -{ - int i = 0; - char *iwep = NULL, *iwep_last = NULL; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; - struct uci_section *s = NULL; - - update_section_list(DMMAP,"wlan-wepkey", "wlan", 4, section_name(wlanargs->lwlansection), NULL, NULL, NULL, NULL); - uci_path_foreach_option_eq(icwmpd, "dmmap", "wlan-wepkey", "wlan", section_name(wlanargs->lwlansection), s) { - //init_wlan_wep_args(ctx, s); - cur_wepargs.wlanwep = s; - cur_wepargs.key_index = ++i; - iwep = handle_update_instance(3, ctx, &iwep_last, update_instance_alias_icwmpd, 3, s, "wepinstance", "wepalias"); - SUBENTRY(entry_landevice_wlanconfiguration_wepkey_instance, ctx, idev, iwlan, iwep); - } - return 0; -} - -inline int entry_landevice_wlanconfiguration_presharedkey(struct dmctx *ctx, char *idev, char *iwlan) -{ - char *ipk = NULL, *ipk_last = NULL ; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; - struct uci_section *s = NULL; - - wlanargs->pki = 0; - //update section list of wlan-psk before update instance - update_section_list(DMMAP,"wlan-psk", "wlan", 10, section_name(wlanargs->lwlansection), NULL, NULL, NULL, NULL); - uci_path_foreach_option_eq(icwmpd, "dmmap", "wlan-psk", "wlan", section_name(wlanargs->lwlansection), s) { - wlanargs->pki++; - //init_wlan_psk_args(ctx, s); - cur_pskargs.wlanpsk = s; - ipk = handle_update_instance(3, ctx, &ipk_last, update_instance_alias_icwmpd, 3, s, "pskinstance", "pskalias"); - SUBENTRY(entry_landevice_wlanconfiguration_presharedkey_instance, ctx, idev, iwlan, ipk); //"$wunit" "$wlctl_num" "$uci_num" are not needed - } - return 0; -} - -inline int entry_landevice_wlanconfiguration_associateddevice(struct dmctx *ctx, char *idev, char *iwlan) -{ - int id = 0; - json_object *res, *wl_client_obj; - char *idx, *idx_last = NULL; - struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args; - - dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", wlanargs->wiface, String}}, 1, &res); - if (res) { - char *value; - json_object_object_foreach(res, key, wl_client_obj) { - idx = handle_update_instance(3, ctx, &idx_last, update_instance_without_section, 1, ++id); - value = dmjson_get_value(wl_client_obj, 1, "macaddr"); - init_wl_client_args(ctx, value, wlanargs->wiface); - SUBENTRY(entry_landevice_wlanconfiguration_associateddevice_instance, ctx, idev, iwlan, idx); - } - } - return 0; -} - -inline int entry_landevice_lanethernetinterfaceconfig(struct dmctx *ctx, struct uci_section *landevice_section, char *idev) +int browselanethernetinterfaceconfigInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int i = 0; char *pch, *spch; char *ifname, *wan_eth, *baseifname; char *ieth = NULL, *ieth_last = NULL; struct uci_section *s = NULL; + struct ldlanargs *lanargs = (struct ldlanargs *)prev_data; + struct ldethargs curr_ethargs = {0}; + #ifdef EX400 uci_foreach_option_eq("ports", "ethport", "name", "WAN", s) { dmuci_get_value_by_section_string(s, "ifname", &wan_eth); @@ -3549,327 +3663,202 @@ inline int entry_landevice_lanethernetinterfaceconfig(struct dmctx *ctx, struct #else dmuci_get_option_value_string("layer2_interface_ethernet", "ethernet_interface", "baseifname", &wan_eth); #endif - dmuci_get_value_by_section_string(landevice_section, "ifname", &ifname); - lan_eth_update_section_option_list(ifname, section_name(landevice_section), wan_eth); - uci_path_foreach_option_eq(icwmpd, "dmmap", "lan_eth", "network", section_name(landevice_section), s) { + dmuci_get_value_by_section_string(lanargs->ldlansection, "ifname", &ifname); + lan_eth_update_section_option_list(ifname, section_name(lanargs->ldlansection), wan_eth); + uci_path_foreach_option_eq(icwmpd, "dmmap", "lan_eth", "network", section_name(lanargs->ldlansection), s) { dmuci_get_value_by_section_string(s, "ifname", &baseifname); - init_ldargs_eth_cfg(ctx, baseifname, s); - ieth = handle_update_instance(2, ctx, &ieth_last, update_instance_alias_icwmpd, 3, s, "ethinstance", "ethalias"); - SUBENTRY(entry_landevice_lanethernetinterfaceconfig_instance, ctx, idev, ieth); + init_ldargs_eth_cfg(&curr_ethargs, baseifname, s); + ieth = handle_update_instance(2, dmctx, &ieth_last, update_instance_alias_icwmpd, 3, s, "ethinstance", "ethalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ethargs, ieth) == DM_STOP) + break; } return 0; } -inline int entry_landevice_host(struct dmctx *ctx, struct uci_section *landevice_section, char *idev) +int browseWlanConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *ss = NULL; + struct uci_section *sss = NULL; + json_object *res; + char *iwlan = NULL, *iwlan_last = NULL; + char *network , *wiface, buf[8], *lan_sec; + struct ldlanargs *lanargs = (struct ldlanargs *)prev_data; + struct ldwlanargs curr_wlanargs = {0}; + + lan_sec = section_name(lanargs->ldlansection); + iwlan = get_last_instance_lev2("wireless", "wifi-iface", "lwlaninstance", "network", lan_sec); + uci_foreach_sections("wireless", "wifi-device", ss) { + int wlctl_num=0; + uci_foreach_option_eq("wireless", "wifi-iface", "device", section_name(ss), sss) { + dmuci_get_value_by_section_string(sss, "network", &network); + if (strcmp(network, lan_sec) != 0) + continue; + iwlan = handle_update_instance(2, dmctx, &iwlan_last, update_instance_alias, 3, sss, "lwlaninstance", "lwlanalias"); + wiface = section_name(ss); + if (wlctl_num != 0) { + sprintf(buf, "%s.%d", wiface, wlctl_num); + wiface = buf; + } + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wiface, String}}, 1, &res); + init_ldargs_wlan(&curr_wlanargs, sss, wlctl_num, ss, section_name(ss), wiface, res, 0); + wlctl_num++; + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wlanargs, iwlan) == DM_STOP) + goto end; + } + } +end: + return 0; +} + +int browseWepKeyInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + int i = 0; + char *iwep = NULL, *iwep_last = NULL; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)prev_data; + struct uci_section *s = NULL; + struct wlan_wep curr_wepargs = {0}; + + update_section_list(DMMAP,"wlan-wepkey", "wlan", 4, section_name(wlanargs->lwlansection), NULL, NULL, NULL, NULL); + uci_path_foreach_option_eq(icwmpd, "dmmap", "wlan-wepkey", "wlan", section_name(wlanargs->lwlansection), s) { + curr_wepargs.wlanwep = s; + curr_wepargs.key_index = ++i; + curr_wepargs.lwlansection = wlanargs->lwlansection; + iwep = handle_update_instance(3, dmctx, &iwep_last, update_instance_alias_icwmpd, 3, s, "wepinstance", "wepalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wepargs, iwep) == DM_STOP) + break; + } + return 0; +} + +int browsepresharedkeyInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *ipk = NULL, *ipk_last = NULL ; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)prev_data; + struct uci_section *s = NULL; + struct wlan_psk curr_pskargs = {0}; + + curr_pskargs.pki = 0; + //update section list of wlan-psk before update instance + update_section_list(DMMAP,"wlan-psk", "wlan", 10, section_name(wlanargs->lwlansection), NULL, NULL, NULL, NULL); + uci_path_foreach_option_eq(icwmpd, "dmmap", "wlan-psk", "wlan", section_name(wlanargs->lwlansection), s) { + curr_pskargs.pki++; + curr_pskargs.wlanpsk = s; + curr_pskargs.lwlansection = wlanargs->lwlansection; + curr_pskargs.wiface = wlanargs->wiface; + ipk = handle_update_instance(3, dmctx, &ipk_last, update_instance_alias_icwmpd, 3, s, "pskinstance", "pskalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_pskargs, ipk) == DM_STOP) + break; + } + return 0; +} + +int browseassociateddeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + int id = 0; + json_object *res, *wl_client_obj; + char *idx, *idx_last = NULL; + struct ldwlanargs *wlanargs = (struct ldwlanargs *)prev_data; + struct wl_clientargs curr_wl_clientargs = {0}; + + dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", wlanargs->wiface, String}}, 1, &res); + if (res) { + char *value; + json_object_object_foreach(res, key, wl_client_obj) { + idx = handle_update_instance(3, dmctx, &idx_last, update_instance_without_section, 1, ++id); + value = dmjson_get_value(wl_client_obj, 1, "macaddr"); + init_wl_client_args(&curr_wl_clientargs, value, wlanargs->wiface); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wl_clientargs, idx) == DM_STOP) + break; + } + } + return 0; +} + +int browselandevice_hostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - //HOST DYNAMIC json_object *res, *client_obj; char *network; char *idx, *idx_last = NULL; int id = 0; + struct ldlanargs *lanargs = (struct ldlanargs *)prev_data; + struct clientargs curr_clientargs = {0}; + dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res); if (res) { json_object_object_foreach(res, key, client_obj) { network = dmjson_get_value(client_obj, 1, "network"); - if (strcmp(network, section_name(landevice_section)) == 0) { - init_client_args(ctx, client_obj, section_name(landevice_section)); - idx = handle_update_instance(2, ctx, &idx_last, update_instance_without_section, 1, ++id); - SUBENTRY(entry_landevice_host_instance, ctx, idev, idx); + if (strcmp(network, section_name(lanargs->ldlansection)) == 0) { + init_client_args(&curr_clientargs, client_obj, section_name(lanargs->ldlansection)); + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_clientargs, idx) == DM_STOP) + break; } } } return 0; } -inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool(struct dmctx *ctx, char *idev) + +int browselandevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *icondpool = NULL, *icondpool_last = NULL; uci_foreach_sections("dhcp", "vendorclass", s) { - init_args_dhcp_conditional_servingpool_entry(ctx, s); - icondpool = handle_update_instance(1, ctx, &icondpool_last, update_instance_alias, 3, s, "poulinstance", "poulalias"); - SUBENTRY(entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance, ctx, idev, icondpool); + icondpool = handle_update_instance(1, dmctx, &icondpool_last, update_instance_alias, 3, s, "poulinstance", "poulalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, icondpool) == DM_STOP) + break; } return 0; } -inline int entry_landevice_dhcpconditionalservingpool_option(struct dmctx *ctx, char *idev, char *icondpool) +int browseentry_landevice_dhcpconditionalservingpool_option_instance(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int id = 0; - char *idx = NULL, *pch, *spch, *name, *value; - char *idx_last = NULL; - struct uci_list *val; - struct uci_element *e = NULL, *tmp; - struct uci_section *ss = NULL; - struct dhcppoolargs *poolargs = (struct dhcppoolargs *)ctx->args; - bool find_max = true; - char *tt; + char *idx = NULL, *pch, *spch, *name, *value; + char *idx_last = NULL; + struct uci_list *val; + struct uci_element *e = NULL, *tmp; + struct uci_section *ss = NULL; + bool find_max = true; + char *tt; + struct dhcppooloptionargs cur_dhcp_option = {0}; + int found = 0; - int found = 0; - dmuci_get_value_by_section_list(poolargs->dhcppoolsection, "dhcp_option", &val); - if (val) { - uci_foreach_element_safe(val, e, tmp) - { - tt = dmstrdup(tmp->name); - pch = strtok_r(tt, ",", &spch); - found = 0; - uci_path_foreach_option_eq(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), "dhcp_option", pch, ss) + dmuci_get_value_by_section_list((struct uci_section *)prev_data, "dhcp_option", &val); + if (val) { + uci_foreach_element_safe(val, e, tmp) { - dmuci_get_value_by_section_string(ss, "value", &value); - if (strcmp(spch, value) == 0) + tt = dmstrdup(tmp->name); + pch = strtok_r(tt, ",", &spch); + found = 0; + uci_path_foreach_option_eq(icwmpd, "dmmap", section_name((struct uci_section *)prev_data), "dhcp_option", pch, ss) { - dmuci_get_value_by_section_string(ss, "optioninst", &idx); - found = 1; + dmuci_get_value_by_section_string(ss, "value", &value); + if (strcmp(spch, value) == 0) { + dmuci_get_value_by_section_string(ss, "optioninst", &idx); + found = 1; + } + else + continue; + init_args_pool_option(&cur_dhcp_option, ss, (struct uci_section *)prev_data); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dhcp_option, idx) == DM_STOP) { + dmfree(tt); + break; + } + } + if (!found) + { + DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name((struct uci_section *)prev_data), &ss, &name); + DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "dhcp_option", pch); + DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "value", spch); + init_args_pool_option(&cur_dhcp_option, ss, (struct uci_section *)prev_data); + idx = handle_update_instance(1, dmctx, &idx_last, dhcp_option_update_instance_alias_icwmpd, 5, ss, (struct uci_section *)prev_data, "optioninst", "optionalias", &find_max); + DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "optioninst", idx); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dhcp_option, idx) == DM_STOP) { + dmfree(tt); + break; + } } - else - continue; - init_args_pool_option(ctx, ss, poolargs->dhcppoolsection); - SUBENTRY(entry_landevice_dhcpconditionalservingpool_option_instance, ctx, idev, icondpool, idx); - dmfree(tt); - break; - } - if (!found) - { - DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), &ss, &name); - DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "dhcp_option", pch); - DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "value", spch); - init_args_pool_option(ctx, ss, poolargs->dhcppoolsection); - idx = handle_update_instance(1, ctx, &idx_last, dhcp_option_update_instance_alias_icwmpd, 4, ss, "optioninst", "optionalias", &find_max); - DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "optioninst", idx); - SUBENTRY(entry_landevice_dhcpconditionalservingpool_option_instance, ctx, idev, icondpool, idx); - dmfree(tt); } } - } -} -/////////////////////////////////////// -/*************************************/ -int entry_method_root_LANDevice(struct dmctx *ctx) -{ - //struct ldlanargs *(ctx->args) = (struct ldlanargs *)(ctx->args); //TO CHECK - IF_MATCH(ctx, DMROOT"LANDevice.") { - DMOBJECT(DMROOT"LANDevice.", ctx, "0", 0, NULL, NULL, NULL); - SUBENTRY(entry_landevice_sub, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_sub_instance(struct dmctx *ctx, struct uci_section *landevice_section, char *idev) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.", idev) { - DMOBJECT(DMROOT"LANDevice.%s.", ctx, "0", 0, NULL, NULL, NULL, idev); - DMPARAM("Alias", ctx, "1", get_lan_dev_alias, set_lan_dev_alias, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.", ctx, "0", 1, NULL, NULL, NULL, idev); - DMPARAM("DNSServers", ctx, "1", get_lan_dns, set_lan_dns, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DHCPServerConfigurable", ctx, "1", get_lan_dhcp_server_configurable, set_lan_dhcp_server_configurable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("DHCPServerEnable", ctx, "1", get_lan_dhcp_server_enable, set_lan_dhcp_server_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("MinAddress", ctx, "1", get_lan_dhcp_interval_address_start, set_lan_dhcp_address_start, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxAddress", ctx, "1", get_lan_dhcp_interval_address_end, set_lan_dhcp_address_end, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ReservedAddresses", ctx, "1", get_lan_dhcp_reserved_addresses, set_lan_dhcp_reserved_addresses, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SubnetMask", ctx, "1", get_lan_dhcp_subnetmask, set_lan_dhcp_subnetmask, NULL, 0, 1, UNDEF, NULL); - DMPARAM("IPRouters", ctx, "1", get_lan_dhcp_iprouters, set_lan_dhcp_iprouters, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DHCPLeaseTime", ctx, "1", get_lan_dhcp_leasetime, set_lan_dhcp_leasetime, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DomainName", ctx, "1", get_lan_dhcp_domainname, set_lan_dhcp_domainname, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANDevice.%s.Hosts.", ctx, "0", 0, NULL, NULL, NULL, idev); - DMPARAM("HostNumberOfEntries", ctx, "0", get_lan_host_nbr_entries, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANDevice.%s.Hosts.Host.", ctx, "0", 0, NULL, NULL, NULL, idev); - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.IPInterface.", ctx, "0", 1, NULL, NULL, NULL, idev); - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.", ctx, "1", 1, add_dhcp_conditional_serving_pool, delete_dhcp_conditional_serving_pool_all, NULL, idev); - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPStaticAddress.", ctx, "1", 1, add_landevice_dhcpstaticaddress, delete_landevice_dhcpstaticaddress_all, NULL, idev); - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.", ctx, "1", 0, add_landevice_wlanconfiguration, delete_landevice_wlanconfiguration_all, NULL, idev); - DMOBJECT(DMROOT"LANDevice.%s.LANEthernetInterfaceConfig.", ctx, "0", 1, NULL, NULL, NULL, idev);/* TO CHECK */ - SUBENTRY(entry_landevice_ipinterface_and_dhcpstaticaddress, ctx, landevice_section, idev); - SUBENTRY(entry_landevice_wlanconfiguration, ctx, landevice_section, idev); - SUBENTRY(entry_landevice_lanethernetinterfaceconfig, ctx, landevice_section, idev); - SUBENTRY(entry_landevice_host, ctx, landevice_section, idev); - SUBENTRY(entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool, ctx, idev); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *ctx, char * idev, char *icondpool) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.", idev, icondpool) { - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.", ctx, "1", 1, NULL, delete_dhcp_conditional_serving_pool, NULL, idev, icondpool); - DMPARAM("Alias", ctx, "1", get_dhcp_conditional_servingpool_alias, set_dhcp_conditional_servingpool_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_dhcp_conditional_servingpool_enable, set_dhcp_conditionalservingpool_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("VendorClassID", ctx, "1", get_dhcp_conditional_servingpool_vendorclassid, set_dhcp_conditional_servingpool_vendorclassid, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_COM_Networkid", ctx, "1", get_dhcp_conditional_servingpool_network_id, set_dhcp_conditional_servingpool_network_id, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.DHCPOption.", ctx, "1", 0, add_dhcp_serving_pool_option, delete_dhcp_serving_pool_option_all, NULL, idev, icondpool); - SUBENTRY(entry_landevice_dhcpconditionalservingpool_option, ctx, idev, icondpool); - - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_dhcpconditionalservingpool_option_instance(struct dmctx *ctx, char * idev, char *icondpool, char *idx) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.DHCPOption.%s.", idev, icondpool, idx) { - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.DHCPOption.%s.", ctx, "1", 1, NULL, delete_dhcp_serving_pool_option, NULL, idev, icondpool, idx); - DMPARAM("Alias", ctx, "1", get_dhcp_servingpool_alias, set_dhcp_servingpool_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Tag", ctx, "1", get_dhcp_servingpool_tag, set_dhcp_servingpool_tag, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Value", ctx, "1", get_dhcp_servingpool_value, set_dhcp_servingpool_value, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_ipinterface_instance (struct dmctx *ctx, char *idev, char *ilan) //TODO CAN WE USE TYPE VOID -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.LANHostConfigManagement.IPInterface.%s.", idev, ilan) { - struct ldipargs *ipargs = (struct ldipargs *)(ctx->args); - char *linker; - dmastrcat(&linker, "linker_interface:", section_name(ipargs->ldipsection)); - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.IPInterface.%s.", ctx, "0", 1, NULL, NULL, linker, idev, ilan); - DMPARAM("Alias", ctx, "1", get_lan_ip_int_alias, set_lan_ip_int_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_interface_enable_ipinterface, set_interface_enable_ipinterface, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("X_BROADCOM_COM_FirewallEnabled", ctx, "1", get_interface_firewall_enabled_ipinterface, set_interface_firewall_enabled_ipinterface, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("IPInterfaceIPAddress", ctx, "1", get_interface_ipaddress, set_interface_ipaddress, NULL, 0, 1, UNDEF, NULL); - DMPARAM("IPInterfaceSubnetMask", ctx, "1", get_interface_subnetmask, set_interface_subnetmask, NULL, 0, 1, UNDEF, NULL); - DMPARAM("IPInterfaceAddressingType", ctx, "1", get_interface_addressingtype, set_interface_addressingtype, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_dhcpstaticaddress_instance(struct dmctx *ctx, char *idev, char *idhcp) //TODO CAN WE USE TYPE VOID -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPStaticAddress.%s.", idev, idhcp) { - DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPStaticAddress.%s.", ctx, "1", 1, NULL, delete_landevice_dhcpstaticaddress, NULL, idev, idhcp); - DMPARAM("Alias", ctx, "1", get_dhcp_alias, set_dhcp_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_dhcpstaticaddress_enable, set_dhcpstaticaddress_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Chaddr", ctx, "1", get_dhcpstaticaddress_chaddr, set_dhcpstaticaddress_chaddr, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Yiaddr", ctx, "1", get_dhcpstaticaddress_yiaddr, set_dhcpstaticaddress_yiaddr, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_wlanconfiguration_instance(struct dmctx *ctx, char *idev,char *iwlan) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.WLANConfiguration.%s.", idev, iwlan) { - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.", ctx, "1", 0, NULL, delete_landevice_wlanconfiguration, NULL, idev, iwlan); - DMPARAM("Alias", ctx, "1", get_wlan_alias, set_wlan_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_wlan_enable, set_wlan_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_wlan_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BSSID", ctx, "0", get_wlan_bssid, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxBitRate", ctx, "1", get_wlan_max_bit_rate, set_wlan_max_bit_rate, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Channel", ctx, "1", get_wlan_channel, set_wlan_channel, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("AutoChannelEnable", ctx, "1", get_wlan_auto_channel_enable, set_wlan_auto_channel_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("SSID", ctx, "1", get_wlan_ssid, set_wlan_ssid, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BeaconType", ctx, "1", get_wlan_beacon_type, set_wlan_beacon_type, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MACAddressControlEnabled", ctx, "1", get_wlan_mac_control_enable, set_wlan_mac_control_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("PossibleChannels", ctx, "0", get_wlan_possible_channels, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Standard", ctx, "1", get_wlan_standard, set_wlan_standard, NULL, 0, 1, UNDEF, NULL); - DMPARAM("WEPKeyIndex", ctx, "1", get_wlan_wep_key_index, set_wlan_wep_key_index, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("KeyPassphrase", ctx, "1", get_empty, set_wlan_key_passphrase, NULL, 0, 1, UNDEF, NULL); - DMPARAM("WEPEncryptionLevel", ctx, "0", get_wlan_wep_encryption_level, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BasicEncryptionModes", ctx, "1", get_wlan_basic_encryption_modes, set_wlan_basic_encryption_modes, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BasicAuthenticationMode", ctx, "1", get_wlan_basic_authentication_mode, set_wlan_basic_authentication_mode, NULL, 0, 1, UNDEF, NULL); - DMPARAM("WPAEncryptionModes", ctx, "1", get_wlan_wpa_encryption_modes, set_wlan_wpa_encryption_modes, NULL, 0, 1, UNDEF, NULL); - DMPARAM("WPAAuthenticationMode", ctx, "1", get_wlan_wpa_authentication_mode, set_wlan_wpa_authentication_mode, NULL, 0, 1, UNDEF, NULL); - DMPARAM("IEEE11iEncryptionModes", ctx, "1", get_wlan_ieee_11i_encryption_modes, set_wlan_ieee_11i_encryption_modes, NULL, 0, 1, UNDEF, NULL); - DMPARAM("IEEE11iAuthenticationMode", ctx, "1", get_wlan_ieee_11i_authentication_mode, set_wlan_ieee_11i_authentication_mode, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RadioEnabled", ctx, "1", get_wlan_radio_enabled, set_wlan_radio_enabled, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("DeviceOperationMode", ctx, "1", get_wlan_device_operation_mode, set_wlan_device_operation_mode, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AuthenticationServiceMode", ctx, "1", get_wlan_authentication_service_mode, set_wlan_authentication_service_mode, NULL, 0, 1, UNDEF, NULL); - DMPARAM("TotalAssociations", ctx, "0", get_wlan_total_associations, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ChannelsInUse", ctx, "1", get_wlan_channel, set_wlan_channel, NULL, 0, 1, UNDEF, NULL); - DMPARAM("TotalBytesSent", ctx, "0", get_wlan_devstatus_statistics_tx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("TotalBytesReceived", ctx, "0", get_wlan_devstatus_statistics_rx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("TotalPacketsSent", ctx, "0", get_wlan_devstatus_statistics_tx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("TotalPacketsReceived", ctx, "0", get_wlan_devstatus_statistics_rx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("SSIDAdvertisementEnabled", ctx, "1", get_wlan_ssid_advertisement_enable, set_wlan_ssid_advertisement_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("WMMEnable", ctx, "1", get_wmm_enabled, set_wmm_enabled, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_ChannelMode", ctx, "1", get_x_inteno_se_channelmode, set_x_inteno_se_channelmode, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_SupportedStandards", ctx, "0", get_x_inteno_se_supported_standard, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_OperatingChannelBandwidth", ctx, "1", get_x_inteno_se_operating_channel_bandwidth, set_x_inteno_se_operating_channel_bandwidth, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_MaxSSID", ctx, "1", get_x_inteno_se_maxssid, set_x_inteno_se_maxssid, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_ScanTimer", ctx, "1", get_x_inteno_se_scantimer, set_x_inteno_se_scantimer, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_Frequency", ctx, "1", get_x_inteno_se_frequency, set_x_inteno_se_frequency, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WPS.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); //Check if we can move it - DMPARAM("Enable", ctx, "1", get_wlan_wps_enable, set_wlan_wps_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.PreSharedKey.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan); - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.AssociatedDevice.", ctx, "0", 0, NULL, NULL, NULL, idev, iwlan); - SUBENTRY(entry_landevice_wlanconfiguration_wepkey, ctx, idev, iwlan); - SUBENTRY(entry_landevice_wlanconfiguration_presharedkey, ctx, idev, iwlan); - SUBENTRY(entry_landevice_wlanconfiguration_associateddevice, ctx, idev, iwlan); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_wlanconfiguration_presharedkey_instance(struct dmctx *ctx, char *idev, char *iwlan, char *ipk) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.WLANConfiguration.%s.PreSharedKey.%s.", idev, iwlan, ipk) { - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.PreSharedKey.%s.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan, ipk); - DMPARAM("Alias", ctx, "1", get_wlan_psk_alias, set_wlan_psk_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("PreSharedKey", ctx, "1", get_empty, set_wlan_pre_shared_key, NULL, 0, 1, UNDEF, NULL); - DMPARAM("KeyPassphrase", ctx, "1", get_empty, set_wlan_key_passphrase, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AssociatedDeviceMACAddress", ctx, "0", get_wlan_psk_assoc_MACAddress, NULL, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_wlanconfiguration_associateddevice_instance(struct dmctx *ctx, char *idev, char *iwlan, char *idx) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.WLANConfiguration.%s.AssociatedDevice.%s.", idev, iwlan, idx) { - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.AssociatedDevice.%s.", ctx, "0", 0, NULL, NULL, NULL, idev, iwlan, idx); - DMPARAM("AssociatedDeviceMACAddress", ctx, "0", get_wlan_associated_macaddress, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("AssociatedDeviceIPAddress", ctx, "0", get_wlan_associated_ipddress, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("AssociatedDeviceAuthenticationState", ctx, "0", get_wlan_associated_authenticationstate, NULL, "xsd:boolean", 0, 0, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_lanethernetinterfaceconfig_instance(struct dmctx *ctx, char *idev, char *ieth) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.LANEthernetInterfaceConfig.%s.", idev, ieth) { - DMOBJECT(DMROOT"LANDevice.%s.LANEthernetInterfaceConfig.%s.", ctx, "0", 1, NULL, NULL, NULL, idev, ieth); - DMPARAM("Alias", ctx, "1", get_lan_eth_alias, set_lan_eth_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_lan_eth_iface_cfg_enable, set_lan_eth_iface_cfg_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_lan_eth_iface_cfg_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxBitRate", ctx, "1", get_lan_eth_iface_cfg_maxbitrate, set_lan_eth_iface_cfg_maxbitrate, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DuplexMode", ctx, "1", get_lan_eth_iface_cfg_duplexmode, set_lan_eth_iface_cfg_duplexmode, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"LANDevice.%s.LANEthernetInterfaceConfig.%s.Stats.", ctx, "0", 1, NULL, NULL, NULL, idev, ieth); - DMPARAM("BytesSent", ctx, "0", get_lan_eth_iface_cfg_stats_tx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_lan_eth_iface_cfg_stats_rx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_lan_eth_iface_cfg_stats_tx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_lan_eth_iface_cfg_stats_rx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_host_instance(struct dmctx *ctx, char *idev, char *idx) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.Hosts.Host.%s.", idev, idx) { - DMOBJECT(DMROOT"LANDevice.%s.Hosts.Host.%s.", ctx, "0", 0, NULL, NULL, NULL, idev, idx); - DMPARAM("IPAddress", ctx, "0", get_lan_host_ipaddress, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("HostName", ctx, "0", get_lan_host_hostname, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("Active", ctx, "0", get_lan_host_active, NULL, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("MACAddress", ctx, "0", get_lan_host_macaddress, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("InterfaceType", ctx, "0", get_lan_host_interfacetype, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("AddressSource", ctx, "0", get_lan_host_addresssource, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("LeaseTimeRemaining", ctx, "0", get_lan_host_leasetimeremaining, NULL, NULL, 0, 0, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_landevice_wlanconfiguration_wepkey_instance(struct dmctx *ctx, char *idev, char *iwlan, char *iwep) -{ - IF_MATCH(ctx, DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.%s.", idev, iwlan, iwep) { - DMOBJECT(DMROOT"LANDevice.%s.WLANConfiguration.%s.WEPKey.%s.", ctx, "0", 1, NULL, NULL, NULL, idev, iwlan, iwep); - DMPARAM("Alias", ctx, "1", get_wlan_wep_alias, set_wlan_wep_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("WEPKey", ctx, "1", get_empty, set_wlan_wep_key1, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; } diff --git a/dm/dmtree/tr098/landevice.h b/dm/dmtree/tr098/landevice.h index 2de7da4..c99584a 100644 --- a/dm/dmtree/tr098/landevice.h +++ b/dm/dmtree/tr098/landevice.h @@ -15,6 +15,28 @@ #include #define NVRAM_FILE "/proc/nvram/WpaKey" +extern DMLEAF tLanhost_Config_ManagementParam[]; +extern DMLEAF tDHCPStaticAddressParam[]; +extern DMLEAF tIPInterfaceParam[]; +extern DMLEAF tlanethernetinterfaceconfigParam[]; +extern DMOBJ tLanhost_Config_ManagementObj[]; +extern DMLEAF tWlanConfigurationParam[]; +extern DMLEAF tWPSParam[]; +extern DMLEAF tWepKeyParam[]; +extern DMLEAF tpresharedkeyParam[]; +extern DMLEAF tassociateddeviceParam[]; +extern DMOBJ tWlanConfigurationObj[]; +extern DMOBJ tLANDeviceinstObj[]; +extern DMOBJ tLANDeviceObj[]; +extern DMOBJ tlanethernetinterfaceconfigObj[]; +extern DMLEAF tlanethernetinterfaceStatsParam[]; +extern DMLEAF tLANDeviceParam[]; +extern DMLEAF tlandevice_hostParam[]; +extern DMOBJ tlandevice_hostObj[]; +extern DMLEAF tlandevice_hostsParam[]; +extern DMOBJ tDHCPConditionalServingPoolobj[]; +extern DMLEAF tDHCPConditionalServingPoolParam[]; +extern DMLEAF tDHCPOptionParam[]; struct wl_clientargs { char *mac; @@ -33,27 +55,6 @@ struct ldlanargs char *ldinstance; }; -struct ldipargs -{ - struct uci_section *ldipsection; -}; - -struct lddhcpargs -{ - struct uci_section *lddhcpsection; -}; - -struct dhcppoolargs -{ - struct uci_section *dhcppoolsection; -}; - -struct dhcppooloptionargs -{ - struct uci_section *dhcppooloptionsection; - struct uci_section *dhcppoolsection; -}; - struct ldwlanargs { struct uci_section *lwlansection; @@ -74,11 +75,15 @@ struct ldethargs struct wlan_psk { struct uci_section *wlanpsk; + struct uci_section *lwlansection; + char *wiface; + int pki; }; struct wlan_wep { struct uci_section *wlanwep; + struct uci_section *lwlansection; unsigned int key_index; }; @@ -88,5 +93,188 @@ typedef struct dhcp_param char *state_sec; }dhcp_param; -int entry_method_root_LANDevice(struct dmctx *ctx); +struct dhcppooloptionargs +{ + struct uci_section *dhcppooloptionsection; + struct uci_section *dhcppoolsection; +}; + +int browselandeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseDhcp_static_addressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browselanethernetinterfaceconfigInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseWlanConfigurationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseWepKeyInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browsepresharedkeyInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseassociateddeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browselandevice_hostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseentry_landevice_dhcpconditionalservingpool_option_instance(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browselandevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_landevice_wlanconfiguration(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_landevice_wlanconfiguration(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_landevice_dhcpstaticaddress(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_landevice_dhcpstaticaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_dhcp_conditional_serving_pool(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_dhcp_conditional_serving_pool(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_dhcp_serving_pool_option(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_dhcp_serving_pool_option(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +int get_lan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dns(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_interval_address_start(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_ip_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_enable_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_firewall_enabled_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_addressingtype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_conditional_servingpool_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_conditional_servingpool_vendorclassid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_conditional_servingpool_network_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_macaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_addresssource(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_host_leasetimeremaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_lan_eth_iface_cfg_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_beacon_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_wep_key_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_wep_encryption_level(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_radio_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_devstatus_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_devstatus_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_devstatus_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_devstatus_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_se_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_se_scantimer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_wps_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_wep_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_psk_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_psk_assoc_MACAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_associated_macaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_associated_ipddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_associated_authenticationstate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_linker_lanhost_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_lan_dns(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_address_start(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_address_end(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_ip_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_enable_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_firewall_enabled_ipinterface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_addressingtype(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_conditionalservingpool_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_conditional_servingpool_vendorclassid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_conditional_servingpool_network_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_eth_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_beacon_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_wep_key_index(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_radio_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_inteno_se_scantimer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_x_inteno_se_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_wps_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_wep_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_wep_key1(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_psk_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_pre_shared_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_preshared_key_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_lan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + #endif diff --git a/dm/dmtree/tr098/layer_2_bridging.c b/dm/dmtree/tr098/layer_2_bridging.c index fa070bd..97d844c 100644 --- a/dm/dmtree/tr098/layer_2_bridging.c +++ b/dm/dmtree/tr098/layer_2_bridging.c @@ -19,37 +19,8 @@ #include "dmjson.h" #include "layer_2_bridging.h" -inline int entry_layer2_availableinterface_instance(struct dmctx *ctx, char *int_instance); -inline int entry_layer2_marking_instance(struct dmctx *ctx, char *marking_br_instance); -inline int entry_layer2_bridge_instance(struct dmctx *ctx, char *bridge_instance, char *bridge_instance_last); -inline int entry_layer2_bridge_vlan(struct dmctx *ctx, char *bridge_instance, char *bridge_instance_last); -inline int entry_layer2_bridge_vlan_instance(struct dmctx *ctx,char *bridge_instance, char *vlan_instance); -int set_marking_bridge_key_sub(char *refparam, struct dmctx *ctx, char *value); -int set_marking_interface_key_sub(char *refparam, struct dmctx *ctx, char *value); -int set_bridge_vlan_enable_sub(char *refparam, struct dmctx *ctx, bool b); -int set_bridge_vlan_vid_sub(struct uci_section *vb, char *value); -int set_bridge_vlanid_sub(char *refparam, struct dmctx *ctx, char *value); -void remove_config_interfaces(char *baseifname, char *bridge_key, struct uci_section *bridge_s, char *mbi); - -struct wan_interface -{ - char *instance; - char *name; - char *package; - char *section; -}; - -struct args_layer2 -{ - struct uci_section *layer2section; - struct uci_section *layer2sectionlev2; - char *bridge_instance; - char *availableinterface_instance; - char *interface_type; - char *oface; -}; const char *vlan_ifname[3] = {"eth","atm", "ptm"}; - +char *wan_baseifname = NULL; #ifndef EX400 struct wan_interface wan_interface_tab[3] = { {"1", "ethernet", "layer2_interface_ethernet", "ethernet_interface"}, @@ -58,15 +29,231 @@ struct wan_interface wan_interface_tab[3] = { }; #endif -struct args_layer2 cur_args = {0}; -char *wan_baseifname = NULL; +/************************************************************* +* LAYER2-DM OBJ & PARAM +/************************************************************/ -inline void init_args_layer2(struct dmctx *ctx, struct uci_section *s, struct uci_section *ss, +/*** Layer2Bridging. ***/ +DMOBJ tLayer2BridgingObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"AvailableInterface", &DMREAD, NULL, NULL, NULL, browselayer2_availableinterfaceInst, NULL, NULL, NULL, tavailableinterfaceParam, NULL}, +{"Marking", &DMWRITE, add_layer2bridging_marking, delete_layer2bridging_marking, NULL, browselayer2_markingInst, NULL, NULL, NULL, tlayer2_markingParam, NULL}, +{"Bridge", &DMWRITE, add_layer2bridging_bridge, delete_layer2bridging_bridge, NULL, browselayer2_bridgeInst, NULL, NULL, tlayer2_bridgeObj, tlayer2_bridgeParam, NULL}, +{0} +}; + +/*** Layer2Bridging.AvailableInterface.{i}. ***/ +DMLEAF tavailableinterfaceParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_avai_int_alias, set_avai_int_alias, NULL, NULL}, +{"AvailableInterfaceKey", &DMREAD, DMT_UNINT, get_available_interface_key, NULL, NULL, &DMNONE}, +{"InterfaceReference", &DMREAD, DMT_STRING, get_interface_reference, NULL, NULL, &DMNONE}, +{"InterfaceType", &DMREAD, DMT_STRING, get_interfaces_type, NULL, NULL, &DMNONE}, +{0} +}; + +/*** Layer2Bridging.Marking.{i}. ***/ +DMLEAF tlayer2_markingParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_marking_alias, set_marking_alias, NULL, NULL}, +{"MarkingBridgeReference", &DMWRITE, DMT_INT, get_marking_bridge_reference, set_marking_bridge_key, NULL, NULL}, +{"MarkingInterface", &DMWRITE, DMT_STRING, get_marking_interface_key, set_marking_interface_key, NULL, NULL}, +{0} +}; + +/*** Layer2Bridging.Bridge.{i}. ***/ +DMOBJ tlayer2_bridgeObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"VLAN", &DMWRITE, add_layer2bridging_bridge_vlan, delete_layer2bridging_bridge_vlan, NULL, browsebridge_vlanInst, NULL, NULL, NULL, tbridge_vlanParam, NULL}, +{0} +}; + +DMLEAF tlayer2_bridgeParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_bridge_alias, set_bridge_alias, NULL, NULL}, +{"BridgeEnable", &DMWRITE, DMT_BOOL, get_bridge_status, set_bridge_status, NULL, NULL}, +{"BridgeKey", &DMREAD, DMT_UNINT, get_bridge_key, NULL, NULL, NULL}, +{"BridgeName", &DMWRITE, DMT_STRING, get_bridge_name, set_bridge_name, NULL, NULL}, +{"VLANID", &DMWRITE, DMT_UNINT, get_bridge_vlanid, set_bridge_vlanid, NULL, NULL}, +{"X_INTENO_COM_AssociatedInterfaces", &DMWRITE, DMT_STRING, get_associated_interfaces, set_associated_interfaces, NULL, NULL}, +{0} +}; + +/*** Layer2Bridging.Bridge.{i}.VLAN.{i}. ***/ +DMLEAF tbridge_vlanParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_brvlan_alias, set_brvlan_alias, NULL, NULL}, +{"VLANEnable", &DMWRITE, DMT_BOOL, get_bridge_vlan_enable, set_bridge_vlan_enable, NULL, NULL}, +{"VLANName", &DMWRITE, DMT_STRING, get_bridge_vlan_name, set_bridge_vlan_name, NULL, NULL}, +{"VLANID", &DMWRITE, DMT_UNINT, get_bridge_vlan_vid, set_bridge_vlan_vid, NULL, NULL}, +{0} +}; + + +int browselayer2_availableinterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + int i = 0; + char *oface, *phy_interface, *ch_ptr, *saveptr, *waninstance = NULL, *phy_interface_dup = NULL; + char *base_ifname, *available_inst = NULL; + struct uci_section *wifi_s , *wan_s, *ai_s; + char *instance_last = NULL; + struct args_layer2 curr_args = {0}; +#ifndef EX400 + for (i=0; i<3; i++) { + uci_foreach_sections(wan_interface_tab[i].package, wan_interface_tab[i].section, wan_s) { + waninstance = update_instance(wan_s, waninstance, "waninstance"); + dmasprintf(&oface, "%s%cWANDevice%c%s%cWANConnectionDevice%c%s%c", DMROOT, dm_delim, dm_delim, wan_interface_tab[i].instance, dm_delim, dm_delim, waninstance, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN + dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); + ai_s = update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); + init_args_layer2(&curr_args, ai_s, NULL, instance_last, NULL, "WANInterface", oface); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_args, available_inst) == DM_STOP) + goto end; + } + } +#else + uci_foreach_sections("ports", "ethport", wan_s) { + if(!strcmp(wan_s->e.name, "WAN")){ + waninstance = update_instance(wan_s, waninstance, "waninstance"); + dmasprintf(&oface, DMROOT_CWMP"WANDevice.1.WANConnectionDevice.%s.", waninstance); // MEM WILL BE FREED IN DMMEMCLEAN + dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); + ai_s = update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); + init_args_layer2(&curr_args, ai_s, NULL, instance_last, NULL, "WANInterface", oface); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_args, available_inst) == DM_STOP) + goto end; + } + } +#endif + db_get_value_string("hw", "board", "ethernetLanPorts", &phy_interface); + phy_interface_dup = dmstrdup(phy_interface); + i = 0; + for (ch_ptr = strtok_r(phy_interface_dup, " ", &saveptr); ch_ptr; ch_ptr = strtok_r(NULL, " ", &saveptr)) + { + dmasprintf(&oface, "%s%cLANInterfaces%cLANEthernetInterfaceConfig%c%d%c", DMROOT, dm_delim, dm_delim, dm_delim, ++i, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN + ai_s = update_availableinterface_list(dmctx, ch_ptr, &available_inst, &instance_last); + init_args_layer2(&curr_args, ai_s, NULL, instance_last, NULL, "LANInterface", oface); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_args, available_inst) == DM_STOP) + goto end; + } + i = 0; + uci_foreach_sections("wireless", "wifi-iface", wifi_s) { + dmasprintf(&oface, "%s%cLANInterfaces%cWLANConfiguration%c%d%c", DMROOT, dm_delim, dm_delim, dm_delim, ++i, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN + ai_s = update_availableinterface_list(dmctx, section_name(wifi_s), &available_inst, &instance_last); + init_args_layer2(&curr_args, ai_s, NULL, instance_last, NULL, "LANInterface", oface); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_args, available_inst) == DM_STOP) + goto end; + } +end: + dmfree(phy_interface_dup); + return 0; +} + +int browselayer2_bridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *bridge_instance = NULL, *bridge_instance_last = NULL; + struct uci_section *bridge_s; + struct args_layer2 curr_args = {0}; +#ifdef EX400 + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); +#else + dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", &wan_baseifname); +#endif + uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { + bridge_instance = handle_update_instance(1, dmctx, &bridge_instance_last, update_instance_alias, 3, bridge_s, "bridge_instance", "bridge_alias"); + init_args_layer2(&curr_args, bridge_s, NULL, NULL, bridge_instance_last, NULL, NULL); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_args, bridge_instance) == DM_STOP) + break; + } + return 0; +} + +int browselayer2_markingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *marking_instance = NULL, *marking_instance_last = NULL; + struct uci_section *marking_s = NULL; + struct args_layer2 curr_args = {0}; + + synchronize_availableinterfaceInst(dmctx); + synchrinize_layer2_bridgeInst(dmctx); + uci_path_foreach_sections(icwmpd, "dmmap", "marking-bridge", marking_s) { + marking_instance = handle_update_instance(1, dmctx, &marking_instance_last, update_instance_alias, 3, marking_s, "marking_instance", "marking_alias"); + init_args_layer2(&curr_args, marking_s, NULL, NULL, NULL, NULL, NULL); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_args, marking_instance) == DM_STOP) + break; + } + return 0; +} + +int browsebridge_vlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *ss = NULL; + char *vlan_instance = NULL, *vlan_instance_last = NULL; + struct args_layer2 *curr_args = (struct args_layer2 *)prev_data; + + update_bridge_all_vlan_config_bybridge(dmctx, curr_args); + uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", curr_args->bridge_instance, ss) { + vlan_instance = handle_update_instance(2, dmctx, &vlan_instance_last, update_instance_alias, 3, ss, "vlan_instance", "vlan_alias"); + init_args_layer2_vlan(curr_args, ss); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_args, vlan_instance) == DM_STOP) + break; + } + return 0; +} + +int synchronize_availableinterfaceInst(struct dmctx *dmctx) +{ + int i = 0; + char *oface, *phy_interface, *ch_ptr, *saveptr, *waninstance = NULL, *phy_interface_dup = NULL; + char *base_ifname, *available_inst = NULL; + struct uci_section *wifi_s , *wan_s, *ai_s; + char *instance_last = NULL; +#ifndef EX400 + for (i=0; i<3; i++) { + uci_foreach_sections(wan_interface_tab[i].package, wan_interface_tab[i].section, wan_s) { + waninstance = update_instance(wan_s, waninstance, "waninstance"); + dmasprintf(&oface, "%s%cWANDevice%c%s%cWANConnectionDevice%c%s%c", DMROOT, dm_delim, dm_delim, wan_interface_tab[i].instance, dm_delim, dm_delim, waninstance, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN + dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); + update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); + } + } +#else + uci_foreach_sections("ports", "ethport", wan_s) { + if(!strcmp(wan_s->e.name, "WAN")){ + waninstance = update_instance(wan_s, waninstance, "waninstance"); + dmasprintf(&oface, DMROOT_CWMP"WANDevice.1.WANConnectionDevice.%s.", waninstance); // MEM WILL BE FREED IN DMMEMCLEAN + dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); + update_availableinterface_list(dmctx, base_ifname, &available_inst, &instance_last); + } + } +#endif + db_get_value_string("hw", "board", "ethernetLanPorts", &phy_interface); + phy_interface_dup = dmstrdup(phy_interface); + i = 0; + for (ch_ptr = strtok_r(phy_interface_dup, " ", &saveptr); ch_ptr != NULL; ch_ptr = strtok_r(NULL, " ", &saveptr)) + { + dmasprintf(&oface, "%s%cLANInterfaces%cLANEthernetInterfaceConfig%c%d%c", DMROOT, dm_delim, dm_delim, dm_delim, ++i, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN + update_availableinterface_list(dmctx, ch_ptr, &available_inst, &instance_last); + } + i = 0; + uci_foreach_sections("wireless", "wifi-iface", wifi_s) { + dmasprintf(&oface, "%s%cLANInterfaces%cWLANConfiguration%c%d%c", DMROOT, dm_delim, dm_delim, dm_delim, ++i, dm_delim); // MEM WILL BE FREED IN DMMEMCLEAN + update_availableinterface_list(dmctx, section_name(wifi_s), &available_inst, &instance_last); + } + dmfree(phy_interface_dup); + return 0; +} + +int synchrinize_layer2_bridgeInst(struct dmctx *dmctx) +{ + char *ifname = "", *bridge_instance = ""; + struct uci_section *bridge_s = NULL; + uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { + handle_update_instance(1, dmctx, &bridge_instance, update_instance_alias, 3, bridge_s, "bridge_instance", "bridge_alias"); + dmuci_get_value_by_section_string(bridge_s, "ifname", &ifname); + update_markinginterface_list(bridge_s, bridge_instance, ifname); + } + return 0; +} + +void init_args_layer2(struct args_layer2 *args, struct uci_section *s, struct uci_section *ss, char *availableinterface_instance, char *bridge_instance, char *interface_type, char *oface) { - struct args_layer2 *args = &cur_args; - ctx->args = (void *)args; args->layer2section = s; args->layer2sectionlev2 = ss; args->interface_type = interface_type; @@ -75,10 +262,8 @@ inline void init_args_layer2(struct dmctx *ctx, struct uci_section *s, struct uc args->bridge_instance = bridge_instance; } -inline void init_args_layer2_vlan(struct dmctx *ctx, struct uci_section *ss) +void init_args_layer2_vlan(struct args_layer2 *args, struct uci_section *ss) { - struct args_layer2 *args = &cur_args; - ctx->args = (void *)args; args->layer2sectionlev2 = ss; } @@ -119,25 +304,25 @@ int update_bridge_vlan_config(char *vid, char *bridge_key) return 0; } -int update_bridge_all_vlan_config_bybridge(struct dmctx *ctx) +int update_bridge_all_vlan_config_bybridge(struct dmctx *ctx, struct args_layer2 *curr_args) { - char *ifname, *pch, *spch, *vid; + char *ifname, *ifname_tmp, *pch, *spch, *vid; struct uci_section *s, *ss; - dmuci_get_value_by_section_string(cur_args.layer2section, "ifname", &ifname); - ifname = dmstrdup(ifname); - for (pch = strtok_r(ifname, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { + dmuci_get_value_by_section_string(curr_args->layer2section, "ifname", &ifname); + ifname_tmp = dmstrdup(ifname); + for (pch = strtok_r(ifname_tmp, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { if (strncmp(pch, wan_baseifname, 4) == 0 || strncmp(pch, "ptm", 3) == 0 || strncmp(pch, "atm", 3) == 0) { uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "ifname", pch, s) { vid = strchr(pch, '.') + 1; - update_bridge_vlan_config(vid, cur_args.bridge_instance); + update_bridge_vlan_config(vid, curr_args->bridge_instance); break; } } } - dmfree(ifname); + dmfree(ifname_tmp); return 0; } @@ -219,9 +404,9 @@ void update_add_vlan_to_bridge_interface(char *bridge_key, struct uci_section *d } } -int get_marking_bridge_reference(char *refparam, struct dmctx *ctx, char **value) +int get_marking_bridge_reference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; dmuci_get_value_by_section_string(args->layer2section, "bridgekey", value); return 0; } @@ -234,16 +419,15 @@ void get_baseifname_from_ifname(char *ifname, char *baseifname) *baseifname = '\0'; } -void update_markinginterface_list(struct uci_section *interface_section, char *bridge_key) +void update_markinginterface_list(struct uci_section *interface_section, char *bridge_key, char *ifname) { - char *ifname, *dupifname, *ifname_element, *bridgekey, *instance; + char *dupifname, *ifname_element, *bridgekey, *instance; char *add_value, *interfacekey="", *spch; struct uci_section *marking_section, *new_marking_section, *wireless_section; struct uci_section *ciface; bool found; char baseifname[8]; - dmuci_get_value_by_section_string(interface_section, "ifname", &ifname); dupifname = dmstrdup(ifname); ifname_element = strtok_r(dupifname, " ", &spch); while (ifname_element != NULL) { @@ -305,7 +489,7 @@ nextifname: } //set_marking_bridgekey -int set_marking_bridge_key(char *refparam, struct dmctx *ctx, int action, char *value) +int set_marking_bridge_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -313,18 +497,18 @@ int set_marking_bridge_key(char *refparam, struct dmctx *ctx, int action, char * case VALUESET: if (value[0] == '\0') return 0; - set_marking_bridge_key_sub(refparam, ctx, value); + set_marking_bridge_key_sub(refparam, ctx, data, instance, value); return 0; } return 0; } -int set_marking_bridge_key_sub(char *refparam, struct dmctx *ctx, char *value) +int set_marking_bridge_key_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value) { char *old_bridge_key, *baseifname, *ifname, *vid, *enable, *bridgekey, *p; char new_ifname[128]; struct uci_section *s, *ss; - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; char iface[16]; bool found; @@ -412,15 +596,15 @@ int set_marking_bridge_key_sub(char *refparam, struct dmctx *ctx, char *value) return 0; } -int get_marking_interface_key(char *refparam, struct dmctx *ctx, char **value) +int get_marking_interface_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; dmuci_get_value_by_section_string(args->layer2section, "interfacekey", value); return 0; } //set_marking_interfacekey -int set_marking_interface_key(char *refparam, struct dmctx *ctx, int action, char *value) +int set_marking_interface_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -428,19 +612,19 @@ int set_marking_interface_key(char *refparam, struct dmctx *ctx, int action, cha case VALUESET: if (value[0] == '\0') return 0; - set_marking_interface_key_sub(refparam, ctx, value); + set_marking_interface_key_sub(refparam, ctx, data, instance, value); return 0; } return 0; } -int set_marking_interface_key_sub(char *refparam, struct dmctx *ctx, char *value) +int set_marking_interface_key_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value) { char *vid, *ifname, *baseifname, *bkey, *p, *enable; char new_ifname[128]; - char *obifname, *instance; + char *obifname, *instce; struct uci_section *s = NULL, *ss = NULL, *ab, *mb, *sbridge = NULL; - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; mb = args->layer2section; uci_path_foreach_option_eq(icwmpd, "dmmap", "available-bridge", "key", value, ab) { @@ -455,9 +639,9 @@ int set_marking_interface_key_sub(char *refparam, struct dmctx *ctx, char *value } if (sbridge) { dmuci_get_value_by_section_string(mb, "baseifname", &obifname); - dmuci_get_value_by_section_string(mb, "marking_instance", &instance); + dmuci_get_value_by_section_string(mb, "marking_instance", &instce); if (obifname[0] != '\0') { - remove_config_interfaces(obifname, bkey, sbridge, instance); + remove_config_interfaces(obifname, bkey, sbridge, instce); } } } @@ -513,15 +697,14 @@ int set_marking_interface_key_sub(char *refparam, struct dmctx *ctx, char *value return 0; } -int get_bridge_vlan_enable(char *refparam,struct dmctx *ctx, char **value) +int get_bridge_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; dmuci_get_value_by_section_string(args->layer2sectionlev2, "enable", value); return 0; } -//set_bridgevlan_enable -int set_bridge_vlan_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bridge_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; int error = string_to_bool(value, &b); @@ -531,18 +714,18 @@ int set_bridge_vlan_enable(char *refparam, struct dmctx *ctx, int action, char * return FAULT_9007; return 0; case VALUESET: - set_bridge_vlan_enable_sub(refparam, ctx, b); + set_bridge_vlan_enable_sub(refparam, ctx, data, instance, b); return 0; } return 0; } -int set_bridge_vlan_enable_sub(char *refparam, struct dmctx *ctx, bool b) +int set_bridge_vlan_enable_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, bool b) { char *value, *vid, *bkey, *cval; struct uci_section *vb; bool bcval; - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; vb = args->layer2sectionlev2; dmuci_get_value_by_section_string(vb, "vid", &vid); @@ -563,36 +746,35 @@ int set_bridge_vlan_enable_sub(char *refparam, struct dmctx *ctx, bool b) return 0; } -int get_bridge_vlan_name(char *refparam, struct dmctx *ctx, char **value) +int get_bridge_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; dmuci_get_value_by_section_string(args->layer2sectionlev2, "name", value); return 0; } -int set_bridge_vlan_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bridge_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct args_layer2 *args; switch (action) { case VALUECHECK: return 0; case VALUESET: - args = (struct args_layer2 *)ctx->args; + args = (struct args_layer2 *)data; DMUCI_SET_VALUE_BY_SECTION(icwmpd, args->layer2sectionlev2, "name", value); return 0; } return 0; } -int get_bridge_vlan_vid(char *refparam, struct dmctx *ctx, char **value) +int get_bridge_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; dmuci_get_value_by_section_string(args->layer2sectionlev2, "vid", value); return 0; } -//set_bridgevlan_vid -int set_bridge_vlan_vid(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bridge_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *vb; struct args_layer2 *args; @@ -601,7 +783,7 @@ int set_bridge_vlan_vid(char *refparam, struct dmctx *ctx, int action, char *val case VALUECHECK: return 0; case VALUESET: - args = (struct args_layer2 *)ctx->args; + args = (struct args_layer2 *)data; vb = args->layer2sectionlev2; set_bridge_vlan_vid_sub(vb, value); return 0; @@ -629,20 +811,20 @@ int set_bridge_vlan_vid_sub(struct uci_section *vb, char *value) return 0; } -int get_bridge_status(char *refparam, struct dmctx *ctx, char **value) +int get_bridge_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(args->layer2section), String}}, 1, &res); DM_ASSERT(res, *value = "0"); *value = dmjson_get_value(res, 1, "up"); return 0; } -int set_bridge_status(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bridge_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; int error = string_to_bool(value, &b); switch (action) { @@ -662,39 +844,39 @@ int set_bridge_status(char *refparam, struct dmctx *ctx, int action, char *value return 0; } -int get_bridge_key(char *refparam, struct dmctx *ctx, char **value) +int get_bridge_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; *value = args->bridge_instance; return 0; } -int get_bridge_name(char *refparam, struct dmctx *ctx, char **value) +int get_bridge_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; *value = dmstrdup(section_name(args->layer2section)); return 0; } -int set_bridge_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bridge_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct args_layer2 *args; switch (action) { case VALUECHECK: return 0; case VALUESET: - args = (struct args_layer2 *)ctx->args; + args = (struct args_layer2 *)data; dmuci_rename_section_by_section(args->layer2section, value); return 0; } return 0; } -int get_bridge_vlanid(char *refparam, struct dmctx *ctx, char **value) +int get_bridge_vlanid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *bridge_instance; struct uci_section *s = NULL; - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; *value = ""; uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", args->bridge_instance, s) @@ -705,38 +887,38 @@ int get_bridge_vlanid(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_bridge_vlanid(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bridge_vlanid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; struct uci_section *vb; switch(action) { case VALUECHECK: return 0; case VALUESET: - args = (struct args_layer2 *)ctx->args; + args = (struct args_layer2 *)data; vb = args->layer2section; - set_bridge_vlanid_sub(refparam, ctx, value); + set_bridge_vlanid_sub(refparam, ctx, data, instance, value); return 0; } return 0; } -int set_bridge_vlanid_sub(char *refparam, struct dmctx *ctx, char *value) +int set_bridge_vlanid_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value) { - char *add_value, *name, *instance; + char *add_value, *name, *instce; struct uci_section *s = NULL, *vb;; - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", args->bridge_instance, s) { break; } if (s == NULL) { - instance = get_last_instance_lev2(DMMAP, "vlan_bridge", "vlan_instance", "bridgekey", args->bridge_instance); + instce = get_last_instance_lev2(DMMAP, "vlan_bridge", "vlan_instance", "bridgekey", args->bridge_instance); DMUCI_ADD_SECTION(icwmpd, "dmmap", "vlan_bridge", &vb, &add_value); - instance = update_instance_icwmpd(vb, instance, "vlan_instance"); - dmasprintf(&name, "vlan_%s.%s", args->bridge_instance, instance); + instce = update_instance_icwmpd(vb, instce, "vlan_instance"); + dmasprintf(&name, "vlan_%s.%s", args->bridge_instance, instce); DMUCI_SET_VALUE_BY_SECTION(icwmpd, vb, "bridgekey", args->bridge_instance); DMUCI_SET_VALUE_BY_SECTION(icwmpd, vb, "name", name); DMUCI_SET_VALUE_BY_SECTION(icwmpd, vb, "enable", "0"); @@ -749,44 +931,44 @@ int set_bridge_vlanid_sub(char *refparam, struct dmctx *ctx, char *value) return 0; } -int get_associated_interfaces(char *refparam, struct dmctx *ctx, char **value) +int get_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; dmuci_get_value_by_section_string(args->layer2section, "ifname", value); return 0; } -int set_associated_interfaces(char *refparam, struct dmctx *ctx, int action, char *value) +int set_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct args_layer2 *args; switch (action) { case VALUECHECK: return 0; case VALUESET: - args = (struct args_layer2 *)ctx->args; + args = (struct args_layer2 *)data; dmuci_set_value_by_section(args->layer2section, "ifname", value); return 0; } return 0; } -int get_available_interface_key(char *refparam, struct dmctx *ctx, char **value) +int get_available_interface_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; *value = args->availableinterface_instance; return 0; } -int get_interface_reference(char *refparam, struct dmctx *ctx, char **value) +int get_interface_reference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; *value = args->oface; return 0; } -int get_interfaces_type(char *refparam, struct dmctx *ctx, char **value) +int get_interfaces_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; + struct args_layer2 *args = (struct args_layer2 *)data; *value = args->interface_type; return 0; } @@ -812,7 +994,7 @@ struct uci_section *update_availableinterface_list(struct dmctx *ctx, char *ifac * ADD DELETE OBJECT /*************************************************************/ -int add_layer2bridging_bridge(struct dmctx *ctx, char **instance) +int add_layer2bridging_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance) { char *last_instance; char bridge_name[16], ib[8]; @@ -830,46 +1012,44 @@ int add_layer2bridging_bridge(struct dmctx *ctx, char **instance) return 0; } -int delete_layer2bridging_bridge(struct dmctx *ctx) +int delete_layer2bridging_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct args_layer2 *args_bridge = (struct args_layer2 *)ctx->args; - char *bridge_instance; - struct uci_section *vlan_s = NULL, *prev_s = NULL; - dmuci_get_value_by_section_string(args_bridge->layer2section, "bridge_instance", &bridge_instance); - dmuci_set_value_by_section(args_bridge->layer2section, "type", ""); - dmuci_set_value_by_section(args_bridge->layer2section, "bridge_instance", ""); - uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", bridge_instance, vlan_s) { - if (prev_s) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - prev_s = vlan_s; - } - if (prev_s) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - return 0; -} - -int delete_layer2bridging_bridge_all(struct dmctx *ctx) -{ - struct args_layer2 *args_bridge = (struct args_layer2 *)ctx->args; + struct args_layer2 *args_bridge = (struct args_layer2 *)data; struct uci_section *bridge_s, *vlan_s, *prev_s = NULL; - char *bridgekey = NULL; + char *bridgekey = NULL, *bridge_instance; - uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { - dmuci_set_value_by_section(bridge_s, "type", ""); - dmuci_set_value_by_section(bridge_s, "bridge_instance", ""); + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(args_bridge->layer2section, "bridge_instance", &bridge_instance); + dmuci_set_value_by_section(args_bridge->layer2section, "type", ""); + dmuci_set_value_by_section(args_bridge->layer2section, "bridge_instance", ""); + uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", bridge_instance, vlan_s) { + if (prev_s) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + prev_s = vlan_s; + } + if (prev_s) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + return 0; + case DEL_ALL: + uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { + dmuci_set_value_by_section(bridge_s, "type", ""); + dmuci_set_value_by_section(bridge_s, "bridge_instance", ""); + } + uci_path_foreach_sections(icwmpd, "dmmap", "vlan_bridge", vlan_s) { + if(prev_s != NULL && bridgekey[0] != '\0') + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + prev_s = vlan_s; + dmuci_get_value_by_section_string(vlan_s, "bridgekey", &bridgekey); + } + if(prev_s != NULL && bridgekey[0] != '\0') + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + return 0; } - uci_path_foreach_sections(icwmpd, "dmmap", "vlan_bridge", vlan_s) { - if(prev_s != NULL && bridgekey[0] != '\0') - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - prev_s = vlan_s; - dmuci_get_value_by_section_string(vlan_s, "bridgekey", &bridgekey); - } - if(prev_s != NULL && bridgekey[0] != '\0') - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); return 0; } -int add_layer2bridging_marking(struct dmctx *ctx, char **instance) +int add_layer2bridging_marking(char *refparam, struct dmctx *ctx, void *data, char **instance) { char *last_instance; char *value; @@ -928,54 +1108,53 @@ void remove_config_interfaces(char *baseifname, char *bridge_key, struct uci_sec } } -int delete_layer2bridging_marking(struct dmctx *ctx) -{ - struct args_layer2 *args_bridge = (struct args_layer2 *)ctx->args; - char *b_key, *bifname, *m_instance; - struct uci_section *bridge_s; - - dmuci_get_value_by_section_string(args_bridge->layer2section, "bridgekey", &b_key); - dmuci_get_value_by_section_string(args_bridge->layer2section, "baseifname", &bifname); - dmuci_get_value_by_section_string(args_bridge->layer2section, "marking_instance", &m_instance); - dmuci_delete_by_section(args_bridge->layer2section, NULL, NULL); - if(b_key[0] == '\0') - return 0; - uci_foreach_option_eq("network", "interface", "bridge_instance", b_key, bridge_s) { - remove_config_interfaces(bifname, b_key, bridge_s, m_instance); - break; - } - return 0; -} - -int delete_layer2bridging_marking_all(struct dmctx *ctx) +int delete_layer2bridging_marking(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *mark_s, *prev_s = NULL; char *bifname, *b_key, *m_instance; struct uci_section *bridge_s; + struct args_layer2 *args_bridge; - uci_path_foreach_sections(icwmpd, "dmmap", "marking-bridge", mark_s) { - dmuci_get_value_by_section_string(mark_s, "bridgekey", &b_key); - dmuci_get_value_by_section_string(mark_s, "baseifname", &bifname); - dmuci_get_value_by_section_string(mark_s, "marking_instance", &m_instance); - if (prev_s != NULL) { - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - } - prev_s = mark_s; - if (b_key[0] == '\0') - continue; - uci_foreach_option_eq("network", "interface", "bridge_instance", b_key, bridge_s) { - remove_config_interfaces(bifname, b_key, bridge_s, m_instance); + switch (del_action) { + case DEL_INST: + args_bridge = (struct args_layer2 *)data; + dmuci_get_value_by_section_string(args_bridge->layer2section, "bridgekey", &b_key); + dmuci_get_value_by_section_string(args_bridge->layer2section, "baseifname", &bifname); + dmuci_get_value_by_section_string(args_bridge->layer2section, "marking_instance", &m_instance); + dmuci_delete_by_section(args_bridge->layer2section, NULL, NULL); + if(b_key[0] == '\0') + return 0; + uci_foreach_option_eq("network", "interface", "bridge_instance", b_key, bridge_s) { + remove_config_interfaces(bifname, b_key, bridge_s, m_instance); + break; + } + break; + case DEL_ALL: + uci_path_foreach_sections(icwmpd, "dmmap", "marking-bridge", mark_s) { + dmuci_get_value_by_section_string(mark_s, "bridgekey", &b_key); + dmuci_get_value_by_section_string(mark_s, "baseifname", &bifname); + dmuci_get_value_by_section_string(mark_s, "marking_instance", &m_instance); + if (prev_s != NULL) { + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + } + prev_s = mark_s; + if (b_key[0] == '\0') + continue; + uci_foreach_option_eq("network", "interface", "bridge_instance", b_key, bridge_s) { + remove_config_interfaces(bifname, b_key, bridge_s, m_instance); + break; + } + } + if(prev_s != NULL) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); break; - } } - if(prev_s != NULL) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); return 0; } -int add_layer2bridging_bridge_vlan(struct dmctx *ctx, char **instance) +int add_layer2bridging_bridge_vlan(char *refparam, struct dmctx *ctx, void *data, char **instance) { - struct args_layer2 *args_bridge = (struct args_layer2 *)ctx->args; + struct args_layer2 *args_bridge = (struct args_layer2 *)data; char *value, *last_instance ; struct uci_section *vlan_s; char buf[16]; @@ -995,283 +1174,107 @@ int add_layer2bridging_bridge_vlan(struct dmctx *ctx, char **instance) return 0; } -int delete_layer2bridging_bridge_vlan(struct dmctx *ctx) +int delete_layer2bridging_bridge_vlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct args_layer2 *args_bridge = (struct args_layer2 *)ctx->args; char *vid, *ifname; char new_ifname[128]; - - dmuci_get_value_by_section_string(args_bridge->layer2sectionlev2, "vid", &vid); - dmuci_get_value_by_section_string(args_bridge->layer2section, "ifname", &ifname); - remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); - dmuci_set_value_by_section(args_bridge->layer2section, "ifname", new_ifname); - DMUCI_DELETE_BY_SECTION(icwmpd, args_bridge->layer2sectionlev2, NULL, NULL); - return 0; -} - -int delete_layer2bridging_bridge_vlan_all(struct dmctx *ctx) -{ - struct args_layer2 *args_bridge = (struct args_layer2 *)ctx->args; - char *vid, *ifname; struct uci_section *vlan_s, *prev_s = NULL ; - char new_ifname[128]; + struct args_layer2 *args_bridge = (struct args_layer2 *)data; - uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", args_bridge->bridge_instance, vlan_s) { - dmuci_get_value_by_section_string(vlan_s, "vid", &vid); - dmuci_get_value_by_section_string(args_bridge->layer2section, "ifname", &ifname); - remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); - dmuci_set_value_by_section(args_bridge->layer2section, "ifname", new_ifname); - if (prev_s != NULL) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - prev_s = vlan_s; + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(args_bridge->layer2sectionlev2, "vid", &vid); + dmuci_get_value_by_section_string(args_bridge->layer2section, "ifname", &ifname); + remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); + dmuci_set_value_by_section(args_bridge->layer2section, "ifname", new_ifname); + DMUCI_DELETE_BY_SECTION(icwmpd, args_bridge->layer2sectionlev2, NULL, NULL); + break; + case DEL_ALL: + uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", args_bridge->bridge_instance, vlan_s) { + dmuci_get_value_by_section_string(vlan_s, "vid", &vid); + dmuci_get_value_by_section_string(args_bridge->layer2section, "ifname", &ifname); + remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); + dmuci_set_value_by_section(args_bridge->layer2section, "ifname", new_ifname); + if (prev_s != NULL) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + prev_s = vlan_s; + } + if (prev_s != NULL) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + break; } - if (prev_s != NULL) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); return 0; } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_avai_int_alias(char *refparam, struct dmctx *ctx, char **value) +int get_avai_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_args.layer2section, "avbralias", value); + dmuci_get_value_by_section_string(((struct args_layer2 *)data)->layer2section, "avbralias", value); return 0; } -int set_avai_int_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_avai_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_args.layer2section, "avbralias", value); + dmuci_set_value_by_section(((struct args_layer2 *)data)->layer2section, "avbralias", value); return 0; } return 0; } -int get_marking_alias(char *refparam, struct dmctx *ctx, char **value) +int get_marking_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_args.layer2section, "marking_alias", value); + dmuci_get_value_by_section_string(((struct args_layer2 *)data)->layer2section, "marking_alias", value); return 0; } -int set_marking_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_marking_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_args.layer2section, "marking_alias", value); + dmuci_set_value_by_section(((struct args_layer2 *)data)->layer2section, "marking_alias", value); return 0; } return 0; } -int get_bridge_alias(char *refparam, struct dmctx *ctx, char **value) +int get_bridge_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_args.layer2section, "bridge_alias", value); + dmuci_get_value_by_section_string(((struct args_layer2 *)data)->layer2section, "bridge_alias", value); return 0; } -int set_bridge_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bridge_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_args.layer2section, "bridge_alias", value); + dmuci_set_value_by_section(((struct args_layer2 *)data)->layer2section, "bridge_alias", value); return 0; } return 0; } -int get_brvlan_alias(char *refparam, struct dmctx *ctx, char **value) +int get_brvlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_args.layer2section, "vlan_alias", value); + dmuci_get_value_by_section_string(((struct args_layer2 *)data)->layer2section, "vlan_alias", value); return 0; } -int set_brvlan_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_brvlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_args.layer2section, "vlan_alias", value); + dmuci_set_value_by_section(((struct args_layer2 *)data)->layer2section, "vlan_alias", value); return 0; } return 0; } -/************************************************************* - * SUB ENTRIES -/*************************************************************/ - -inline int entry_layer2_availableinterface(struct dmctx *ctx) -{ - int i = 0; - char *oface, *phy_interface, *ch_ptr, *saveptr, *waninstance = NULL; - char *base_ifname, *available_inst = NULL; - struct uci_section *wifi_s , *wan_s, *ai_s; - char *instance_last = NULL; -#ifndef EX400 - for (i=0; i<3; i++) { - uci_foreach_sections(wan_interface_tab[i].package, wan_interface_tab[i].section, wan_s) { - waninstance = update_instance(wan_s, waninstance, "waninstance"); - dmasprintf(&oface, DMROOT"WANDevice.%s.WANConnectionDevice.%s.", wan_interface_tab[i].instance, waninstance); // MEM WILL BE FREED IN DMMEMCLEAN - dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); - ai_s = update_availableinterface_list(ctx, base_ifname, &available_inst, &instance_last); - init_args_layer2(ctx, ai_s, NULL, instance_last, NULL, "WANInterface", oface); - SUBENTRY(entry_layer2_availableinterface_instance, ctx, available_inst); - } - } -#else - uci_foreach_sections("ports", "ethport", wan_s) { - if(!strcmp(wan_s->e.name, "WAN")){ - waninstance = update_instance(wan_s, waninstance, "waninstance"); - dmasprintf(&oface, DMROOT"WANDevice.1.WANConnectionDevice.%s.", waninstance); // MEM WILL BE FREED IN DMMEMCLEAN - dmuci_get_value_by_section_string(wan_s, "baseifname", &base_ifname); - ai_s = update_availableinterface_list(ctx, base_ifname, &available_inst, &instance_last); - init_args_layer2(ctx, ai_s, NULL, instance_last, NULL, "WANInterface", oface); - SUBENTRY(entry_layer2_availableinterface_instance, ctx, available_inst); - } - } -#endif - db_get_value_string("hw", "board", "ethernetLanPorts", &phy_interface); - ch_ptr = strtok_r(phy_interface, " ", &saveptr); - i = 0; - while (ch_ptr != NULL) - { - dmasprintf(&oface, DMROOT"LANInterfaces.LANEthernetInterfaceConfig.%d.", ++i); // MEM WILL BE FREED IN DMMEMCLEAN - ai_s = update_availableinterface_list(ctx, ch_ptr, &available_inst, &instance_last); - init_args_layer2(ctx, ai_s, NULL, instance_last, NULL, "LANInterface", oface); - SUBENTRY(entry_layer2_availableinterface_instance, ctx, available_inst); - ch_ptr = strtok_r(NULL, " ", &saveptr); - } - i = 0; - uci_foreach_sections("wireless", "wifi-iface", wifi_s) { - dmasprintf(&oface, DMROOT"LANInterfaces.WLANConfiguration.%d.", ++i); // MEM WILL BE FREED IN DMMEMCLEAN - ai_s = update_availableinterface_list(ctx, section_name(wifi_s), &available_inst, &instance_last); - init_args_layer2(ctx, ai_s, NULL, instance_last, NULL, "LANInterface", oface); - SUBENTRY(entry_layer2_availableinterface_instance, ctx, available_inst); - } - return 0; -} - -inline int entry_layer2_bridge(struct dmctx *ctx) -{ - char *bridge_instance = NULL, *bridge_instance_last = NULL; - struct uci_section *bridge_s; - - uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { - bridge_instance = handle_update_instance(1, ctx, &bridge_instance_last, update_instance_alias, 3, bridge_s, "bridge_instance", "bridge_alias"); - update_markinginterface_list(bridge_s, bridge_instance_last); - init_args_layer2(ctx, bridge_s, NULL, NULL, bridge_instance_last, NULL, NULL); - SUBENTRY(entry_layer2_bridge_instance, ctx, bridge_instance, bridge_instance_last); - } - return 0; -} - -inline int entry_layer2_marking(struct dmctx *ctx) -{ - char *marking_instance = NULL, *marking_instance_last = NULL; - struct uci_section *marking_s = NULL; - - uci_path_foreach_sections(icwmpd, "dmmap", "marking-bridge", marking_s) { - marking_instance = handle_update_instance(1, ctx, &marking_instance_last, update_instance_alias_icwmpd, 3, marking_s, "marking_instance", "marking_alias"); - init_args_layer2(ctx, marking_s, NULL, NULL, NULL, NULL, NULL); - SUBENTRY(entry_layer2_marking_instance, ctx, marking_instance); - } - return 0; -} - -inline int entry_layer2_bridge_vlan(struct dmctx *ctx, char *bridge_instance, char *bridge_instance_last) -{ - struct uci_section *ss = NULL; - char *vlan_instance = NULL, *vlan_instance_last = NULL; - - update_bridge_all_vlan_config_bybridge(ctx); - uci_path_foreach_option_eq(icwmpd, "dmmap", "vlan_bridge", "bridgekey", bridge_instance_last, ss) { - vlan_instance = handle_update_instance(2, ctx, &vlan_instance_last, update_instance_alias_icwmpd, 3, ss, "vlan_instance", "vlan_alias"); - init_args_layer2_vlan(ctx, ss); - SUBENTRY(entry_layer2_bridge_vlan_instance, ctx, bridge_instance, vlan_instance); - } - return 0; -} -/************************************************************* -* LAYER2-DM OBJ & PARAM -/ * ***********************************************************/ - -int entry_method_root_Layer2Bridging(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Layer2Bridging.") { -#ifdef EX400 - dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); -#else - dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", &wan_baseifname); -#endif - DMOBJECT(DMROOT"Layer2Bridging.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"Layer2Bridging.AvailableInterface.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"Layer2Bridging.Marking.", ctx, "1", 1, add_layer2bridging_marking, delete_layer2bridging_marking_all, NULL); - DMOBJECT(DMROOT"Layer2Bridging.Bridge.", ctx, "1", 1, add_layer2bridging_bridge, delete_layer2bridging_bridge_all, NULL); - SUBENTRY(entry_layer2_availableinterface, ctx); - SUBENTRY(entry_layer2_bridge, ctx); - SUBENTRY(entry_layer2_marking, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_layer2_availableinterface_instance(struct dmctx *ctx, char *int_instance) -{ - IF_MATCH(ctx, DMROOT"Layer2Bridging.AvailableInterface.%s.", int_instance) { - DMOBJECT(DMROOT"Layer2Bridging.AvailableInterface.%s.", ctx, "0", 0, NULL, NULL, NULL, int_instance); - DMPARAM("Alias", ctx, "1", get_avai_int_alias, set_avai_int_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AvailableInterfaceKey", ctx, "0", get_available_interface_key, NULL, "xsd:unsignedInt", 0, 0, 0, NULL); - DMPARAM("InterfaceReference", ctx, "0", get_interface_reference, NULL, NULL, 0, 0, 0, NULL); - DMPARAM("InterfaceType", ctx, "0", get_interfaces_type, NULL, NULL, 0, 0, 0, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_layer2_marking_instance(struct dmctx *ctx, char *marking_br_instance) -{ - IF_MATCH(ctx, DMROOT"Layer2Bridging.Marking.%s.", marking_br_instance) { - DMOBJECT(DMROOT"Layer2Bridging.Marking.%s.", ctx, "1", 1, NULL, delete_layer2bridging_marking, NULL, marking_br_instance); - DMPARAM("Alias", ctx, "1", get_marking_alias, set_marking_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MarkingBridgeReference", ctx, "1", get_marking_bridge_reference, set_marking_bridge_key, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("MarkingInterface", ctx, "1", get_marking_interface_key, set_marking_interface_key, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_layer2_bridge_instance(struct dmctx *ctx, char *bridge_instance, char *bridge_instance_last) -{ - IF_MATCH(ctx, DMROOT"Layer2Bridging.Bridge.%s.", bridge_instance) { - DMOBJECT(DMROOT"Layer2Bridging.Bridge.%s.", ctx, "1", 1, NULL, delete_layer2bridging_bridge, NULL, bridge_instance); - DMPARAM("Alias", ctx, "1", get_bridge_alias, set_bridge_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BridgeEnable", ctx, "1", get_bridge_status, set_bridge_status, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("BridgeKey", ctx, "0", get_bridge_key, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BridgeName", ctx, "1", get_bridge_name, set_bridge_name, NULL, 0, 1, UNDEF, NULL); - DMPARAM("VLANID", ctx, "1", get_bridge_vlanid, set_bridge_vlanid, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_COM_AssociatedInterfaces", ctx, "1", get_associated_interfaces, set_associated_interfaces, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Layer2Bridging.Bridge.%s.VLAN.", ctx, "1", 1, add_layer2bridging_bridge_vlan, delete_layer2bridging_bridge_vlan_all, NULL, bridge_instance); - SUBENTRY(entry_layer2_bridge_vlan, ctx, bridge_instance, bridge_instance_last); - return 0; - } - return FAULT_9005; -} - -inline int entry_layer2_bridge_vlan_instance(struct dmctx *ctx,char *bridge_instance, char *vlan_instance) -{ - IF_MATCH(ctx, DMROOT"Layer2Bridging.Bridge.%s.VLAN.%s.", bridge_instance, vlan_instance) { - DMOBJECT(DMROOT"Layer2Bridging.Bridge.%s.VLAN.%s.", ctx, "1", 1, NULL, delete_layer2bridging_bridge_vlan, NULL, bridge_instance, vlan_instance); - DMPARAM("Alias", ctx, "1", get_brvlan_alias, set_brvlan_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("VLANEnable", ctx, "1", get_bridge_vlan_enable, set_bridge_vlan_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("VLANName", ctx, "1", get_bridge_vlan_name, set_bridge_vlan_name, NULL, 0, 1, UNDEF, NULL); - DMPARAM("VLANID", ctx, "1", get_bridge_vlan_vid, set_bridge_vlan_vid, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr098/layer_2_bridging.h b/dm/dmtree/tr098/layer_2_bridging.h index 4249b54..8dc82a6 100644 --- a/dm/dmtree/tr098/layer_2_bridging.h +++ b/dm/dmtree/tr098/layer_2_bridging.h @@ -12,6 +12,90 @@ #ifndef __Layer_2_bridging_H #define __Layer_2_bridging_H -int entry_method_root_Layer2Bridging(struct dmctx *ctx); +extern DMOBJ tLayer2BridgingObj[]; +extern DMOBJ tlayer2_bridgeObj[]; +extern DMLEAF tbridge_vlanParam[]; +extern DMLEAF tlayer2_bridgeParam[]; +extern DMLEAF tlayer2_markingParam[]; +extern DMLEAF tavailableinterfaceParam[]; +struct wan_interface +{ + char *instance; + char *name; + char *package; + char *section; +}; + +struct args_layer2 +{ + struct uci_section *layer2section; + struct uci_section *layer2sectionlev2; + char *bridge_instance; + char *availableinterface_instance; + char *interface_type; + char *oface; +}; + +int browselayer2_availableinterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browselayer2_bridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browselayer2_markingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browsebridge_vlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int set_marking_bridge_key_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value); +int set_marking_interface_key_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value); +int set_bridge_vlan_enable_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, bool b); +int set_bridge_vlanid_sub(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value); +void remove_config_interfaces(char *baseifname, char *bridge_key, struct uci_section *bridge_s, char *mbi); +int synchrinize_layer2_bridgeInst(struct dmctx *dmctx); +int synchronize_availableinterfaceInst(struct dmctx *dmctx); +void init_args_layer2(struct args_layer2 *args, struct uci_section *s, struct uci_section *ss, + char *availableinterface_instance, char *bridge_instance, + char *interface_type, char *oface); +void init_args_layer2_vlan(struct args_layer2 *args, struct uci_section *ss); +struct uci_section *update_availableinterface_list(struct dmctx *ctx, char *iface, char **instance, char **instance_last); +void update_markinginterface_list(struct uci_section *interface_section, char *bridge_key, char *ifname); +int add_layer2bridging_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance); +int delete_layer2bridging_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_layer2bridging_marking(char *refparam, struct dmctx *ctx, void *data, char **instance); +int delete_layer2bridging_marking(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_layer2bridging_bridge_vlan(char *refparam, struct dmctx *ctx, void *data, char **instance); +int delete_layer2bridging_bridge_vlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int get_avai_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_avai_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_marking_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_marking_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bridge_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bridge_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bridge_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bridge_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bridge_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bridge_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_bridge_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bridge_vlanid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_vlanid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_available_interface_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_reference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interfaces_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +char *layer2_get_last_section_instance(char *package, char *section, char *opt_inst); +int update_bridge_vlan_config(char *vid, char *bridge_key); +int update_bridge_all_vlan_config_bybridge(struct dmctx *ctx, struct args_layer2 *curr_args); +void update_add_vlan_interfaces(char *bridge_key, char *vid); +void update_add_vlan_to_bridge_interface(char *bridge_key, struct uci_section *dmmap_s); +int get_marking_bridge_reference(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +void get_baseifname_from_ifname(char *ifname, char *baseifname); +int set_marking_bridge_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_marking_interface_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_marking_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_brvlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_brvlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_marking_interface_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bridge_vlan_vid_sub(struct uci_section *vb, char *value); #endif diff --git a/dm/dmtree/tr098/layer_3_forwarding.c b/dm/dmtree/tr098/layer_3_forwarding.c index 0dc7d28..12bcbf1 100644 --- a/dm/dmtree/tr098/layer_3_forwarding.c +++ b/dm/dmtree/tr098/layer_3_forwarding.c @@ -20,19 +20,40 @@ #include "dmjson.h" #include "layer_3_forwarding.h" -enum enum_route_type { - ROUTE_STATIC, - ROUTE_DYNAMIC, - ROUTE_DISABLED + +/*** Layer3Forwarding. ***/ +DMOBJ tLayer3ForwardingObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Forwarding", &DMREAD, NULL, NULL, NULL, browseForwardingInst, NULL, NULL, NULL, tForwardingInstParam, NULL}, +{0} }; -struct routefwdargs cur_routefwdargs = {0}; +DMLEAF tLayer3ForwardingParam[] = { +{"DefaultConnectionService", &DMWRITE, DMT_STRING, get_layer3_def_conn_serv, set_layer3_def_conn_serv, NULL, NULL}, +{"ForwardNumberOfEntries", &DMREAD, DMT_UNINT, get_layer3_nbr_entry, NULL, NULL, NULL}, +{0} +}; -inline int entry_layer3_forwarding_instance(struct dmctx *ctx, char *iroute, char *permission); -inline int init_args_rentry(struct dmctx *ctx, struct uci_section *s, char *permission, struct proc_route *proute, int type) +/*** Layer3Forwarding.Forwarding.{i}. ***/ +DMLEAF tForwardingInstParam[] = { +{"Enable", &DMForwarding_perm, DMT_BOOL, get_layer3_enable, set_layer3_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_layer3_status, NULL, NULL, NULL}, +{"Alias", &DMWRITE, DMT_STRING, get_layer3_alias, set_layer3_alias, NULL, NULL}, +{"Type", &DMREAD, DMT_STRING, get_layer3_type, NULL, NULL, NULL}, +{"DestIPAddress", &DMForwarding_perm, DMT_STRING, get_layer3_destip, set_layer3_destip, NULL, NULL}, +{"DestSubnetMask", &DMForwarding_perm, DMT_STRING, get_layer3_destmask, set_layer3_destmask, NULL, NULL}, +{"SourceIPAddress", &DMREAD, DMT_STRING, get_layer3_src_address, NULL, NULL, NULL}, +{"SourceSubnetMask", &DMREAD, DMT_STRING, get_layer3_src_mask, NULL, NULL, NULL}, +{"GatewayIPAddress", &DMForwarding_perm, DMT_STRING, get_layer3_gatewayip, set_layer3_gatewayip, NULL, NULL}, +{"Interface", &DMForwarding_perm, DMT_STRING, get_layer3_interface_linker_parameter, set_layer3_interface_linker_parameter, NULL, NULL}, +{"ForwardingMetric", &DMForwarding_perm, DMT_STRING, get_layer3_metric, set_layer3_metric, NULL, NULL}, +{"MTU", &DMForwarding_perm, DMT_STRING, get_layer3_mtu, set_layer3_mtu, NULL, NULL}, +{0} +}; + + +inline int init_args_rentry(struct routingfwdargs *args, struct uci_section *s, char *permission, struct proc_routing *proute, int type) { - struct routefwdargs *args = &cur_routefwdargs; - ctx->args = (void *)args; args->permission = permission; args->routefwdsection = s; args->proute = proute; @@ -52,39 +73,7 @@ void ip_to_hex(char *address, char *ret) //TODO Move to the common.c sprintf(ret, "%02X%02X%02X%02X", ip[0], ip[1], ip[2], ip[3]); } -void hex_to_ip(char *address, char *ret) //TODO Move to the common.c -{ - int i; - int ip[4] = {0}; - sscanf(address, "%2x%2x%2x%2x", &(ip[0]), &(ip[1]), &(ip[2]), &(ip[3])); - if (htonl(13) == 13) { - sprintf(ret, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); - } else { - sprintf(ret, "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); - } -} - -void parse_proc_route_line(char *line, struct proc_route *proute) -{ - char *pch, *spch; - proute->iface = strtok_r(line, " \t", &spch); - - pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->destination); - pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->gateway); - proute->flags = strtok_r(NULL, " \t", &spch); - proute->refcnt = strtok_r(NULL, " \t", &spch); - proute->use = strtok_r(NULL, " \t", &spch); - proute->metric = strtok_r(NULL, " \t", &spch); - pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->mask); - proute->mtu = strtok_r(NULL, " \t", &spch); - proute->window = strtok_r(NULL, " \t", &spch); - proute->irtt = strtok_r(NULL, " \t\n\r", &spch); -} - -bool is_proute_static(struct proc_route *proute) +bool is_proute_static(struct proc_routing *proute) { char *mask; struct uci_section *s; @@ -104,8 +93,8 @@ bool is_proute_static(struct proc_route *proute) bool is_cfg_route_active(struct uci_section *s) { FILE *fp; - char line[MAX_PROC_ROUTE]; - struct proc_route proute; + char line[MAX_PROC_ROUTING]; + struct proc_routing proute; char *dest, *mask; dmuci_get_value_by_section_string(s, "target", &dest); @@ -114,8 +103,8 @@ bool is_cfg_route_active(struct uci_section *s) fp = fopen(ROUTE_FILE, "r"); if ( fp != NULL) { - fgets(line, MAX_PROC_ROUTE, fp); - while (fgets(line, MAX_PROC_ROUTE, fp) != NULL ) + fgets(line, MAX_PROC_ROUTING, fp); + while (fgets(line, MAX_PROC_ROUTING, fp) != NULL ) { if (line[0] == '\n') continue; @@ -138,8 +127,8 @@ int get_forwarding_last_inst() struct uci_section *s; int cnt = 0; FILE *fp; - char line[MAX_PROC_ROUTE]; - struct proc_route proute; + char line[MAX_PROC_ROUTING]; + struct proc_routing proute; uci_foreach_sections("network", "route", s) { dmuci_get_value_by_section_string(s, "routeinstance", &tmp); @@ -242,7 +231,7 @@ char *forwarding_update_instance_alias_icwmpd(int action, char **last_inst, void return instance; } -struct uci_section *update_route_dynamic_section(struct proc_route *proute) +struct uci_section *update_route_dynamic_section(struct proc_routing *proute) { struct uci_section *s = NULL; char *name, *mask; @@ -259,9 +248,9 @@ struct uci_section *update_route_dynamic_section(struct proc_route *proute) return s; } -int get_layer3_enable(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection == NULL) { *value = "1"; @@ -275,11 +264,11 @@ int get_layer3_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_layer3_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *pch; - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -303,9 +292,9 @@ int set_layer3_enable(char *refparam, struct dmctx *ctx, int action, char *value return 0; } -int get_layer3_status(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection == NULL) { *value = "Enabled"; @@ -322,26 +311,26 @@ int get_layer3_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_layer3_type(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *netmask; - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "netmask", value); } else { - struct proc_route *proute = routeargs->proute; + struct proc_routing *proute = routeargs->proute; *value = proute->mask; } *value = (strcmp(*value, "255.255.255.255") == 0 || (*value)[0] == '\0') ? "Host" : "Network"; return 0; } -int get_layer3_destip(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "target", value); @@ -350,15 +339,15 @@ int get_layer3_destip(char *refparam, struct dmctx *ctx, char **value) } } else { - struct proc_route *proute = routeargs->proute; + struct proc_routing *proute = routeargs->proute; *value = dmstrdup(proute->destination); // MEM WILL BE FREED IN DMMEMCLEAN } return 0; } -int set_layer3_destip(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -370,9 +359,9 @@ int set_layer3_destip(char *refparam, struct dmctx *ctx, int action, char *value return 0; } -int get_layer3_destmask(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "netmask", value); @@ -381,15 +370,15 @@ int get_layer3_destmask(char *refparam, struct dmctx *ctx, char **value) } } else { - struct proc_route *proute = routeargs->proute; + struct proc_routing *proute = routeargs->proute; *value = dmstrdup(proute->mask); // MEM WILL BE FREED IN DMMEMCLEAN } return 0; } -int set_layer3_destmask(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -401,21 +390,21 @@ int set_layer3_destmask(char *refparam, struct dmctx *ctx, int action, char *val return 0; } -int get_layer3_src_address(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_src_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0.0.0.0"; return 0; } -int get_layer3_src_mask(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_src_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0.0.0.0"; return 0; } -int get_layer3_gatewayip(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "gateway", value); @@ -424,15 +413,15 @@ int get_layer3_gatewayip(char *refparam, struct dmctx *ctx, char **value) } } else { - struct proc_route *proute = routeargs->proute; + struct proc_routing *proute = routeargs->proute; *value = dmstrdup(proute->gateway); // MEM WILL BE FREED IN DMMEMCLEAN } return 0; } -int set_layer3_gatewayip(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -444,20 +433,19 @@ int set_layer3_gatewayip(char *refparam, struct dmctx *ctx, int action, char *va return 0; } -char *get_layer3_interface(struct dmctx *ctx) +char *get_layer3_interface(struct dmctx *ctx, struct routingfwdargs *routeargs) { json_object *res; char *val, *bval, *ifname, *device; char *name; struct uci_section *ss; - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "interface", &val); return val; } else { - struct proc_route *proute = routeargs->proute; + struct proc_routing *proute = routeargs->proute; bval = proute->iface; val = bval; if (!strstr(bval, "br-")) { @@ -480,16 +468,17 @@ char *get_layer3_interface(struct dmctx *ctx) return ""; } -int get_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface, *linker; + *value = ""; - iface = get_layer3_interface(ctx); + iface = get_layer3_interface(ctx, (struct routingfwdargs *)data); if (iface[0] != '\0') { dmastrcat(&linker, "linker_interface:", iface); - adm_entry_get_linker_param(DMROOT"WANDevice.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWANDevice%c", DMROOT, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) { - adm_entry_get_linker_param(DMROOT"LANDevice.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cLANDevice%c", DMROOT, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; } @@ -498,16 +487,16 @@ int get_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, cha return 0; } -int set_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker, *iface; - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); + adm_entry_get_linker_value(ctx, value, &linker); if (linker) { iface = linker + sizeof("linker_interface:") - 1; dmuci_set_value_by_section(routeargs->routefwdsection, "interface", iface); @@ -518,16 +507,16 @@ int set_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, int return 0; } -int get_layer3_metric(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *name; - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "metric", value); } else { - struct proc_route *proute = routeargs->proute; + struct proc_routing *proute = routeargs->proute; *value = dmstrdup(proute->metric); // MEM WILL BE FREED IN DMMEMCLEAN } if ((*value)[0] == '\0') { @@ -536,9 +525,9 @@ int get_layer3_metric(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_layer3_metric(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -550,15 +539,15 @@ int set_layer3_metric(char *refparam, struct dmctx *ctx, int action, char *value return 0; } -int get_layer3_mtu(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_mtu(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "mtu", value); } else { - struct proc_route *proute = routeargs->proute; + struct proc_routing *proute = routeargs->proute; *value = dmstrdup(proute->mtu); // MEM WILL BE FREED IN DMMEMCLEAN } if ((*value)[0] == '\0') { @@ -567,9 +556,9 @@ int get_layer3_mtu(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_layer3_mtu(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_mtu(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routefwdargs *routeargs = (struct routefwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -582,14 +571,14 @@ int set_layer3_mtu(char *refparam, struct dmctx *ctx, int action, char *value) } -int get_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface, *linker; dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &iface); if (iface[0] != '\0') { - dmastrcat(&linker, "linker_interface:", iface); - adm_entry_get_linker_param(DMROOT"WANDevice.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(&linker, "linker_interface:%s", iface); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWANDevice%c", DMROOT, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) { *value = ""; } @@ -597,7 +586,7 @@ int get_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, char **value) } return 0; } -int set_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int i; char *linker, *iface; @@ -606,7 +595,7 @@ int set_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, int action, char case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); + adm_entry_get_linker_value(ctx, value, &linker); if (linker) { iface = linker + sizeof("linker_interface:") - 1; dmuci_set_value("cwmp", "cpe", "default_wan_interface", iface); @@ -617,13 +606,13 @@ int set_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_layer3_nbr_entry(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s; int cnt = 0; FILE *fp; - char line[MAX_PROC_ROUTE]; - struct proc_route proute; + char line[MAX_PROC_ROUTING]; + struct proc_routing proute; uci_foreach_sections("network", "route", s) { cnt++; @@ -634,8 +623,8 @@ int get_layer3_nbr_entry(char *refparam, struct dmctx *ctx, char **value) fp = fopen(ROUTE_FILE, "r"); if ( fp != NULL) { - fgets(line, MAX_PROC_ROUTE, fp); - while (fgets(line, MAX_PROC_ROUTE, fp) != NULL ) + fgets(line, MAX_PROC_ROUTING, fp); + while (fgets(line, MAX_PROC_ROUTING, fp) != NULL ) { if (line[0] == '\n') continue; @@ -650,49 +639,60 @@ int get_layer3_nbr_entry(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_layer3_alias(char *refparam, struct dmctx *ctx, char **value) +int get_layer3_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; - if (cur_routefwdargs.routefwdsection) dmuci_get_value_by_section_string(cur_routefwdargs.routefwdsection, "routealias", value); + if (((struct routingfwdargs *)data)->routefwdsection) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "routealias", value); return 0; } -int set_layer3_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_layer3_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - if (cur_routefwdargs.routefwdsection) dmuci_set_value_by_section(cur_routefwdargs.routefwdsection, "routealias", value); + if (((struct routingfwdargs *)data)->routefwdsection) dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "routealias", value); return 0; } return 0; } /////////////SUB ENTRIES/////////////// -inline int entry_layer3_forwarding(struct dmctx *ctx) +struct dm_permession_s DMForwarding_perm = {"0", &get_forwording_perm}; + +char *get_forwording_perm(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + return ((struct routingfwdargs *)data)->permission; +} + +int browseForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *iroute = NULL, *iroute_last = NULL; char *permission = "1"; struct uci_section *s = NULL, *ss = NULL; FILE* fp = NULL; - char line[MAX_PROC_ROUTE]; - struct proc_route proute; + char line[MAX_PROC_ROUTING]; + struct proc_routing proute; bool find_max = true; + struct routingfwdargs curr_routefwdargs = {0}; + uci_foreach_sections("network", "route", s) { - init_args_rentry(ctx, s, "1", NULL, ROUTE_STATIC); - iroute = handle_update_instance(1, ctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); - SUBENTRY(entry_layer3_forwarding_instance, ctx, iroute, permission); + init_args_rentry(&curr_routefwdargs, s, "1", NULL, ROUTE_STATIC); + iroute = handle_update_instance(1, dmctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, iroute) == DM_STOP) + goto end; } uci_foreach_sections("network", "route_disabled", s) { - init_args_rentry(ctx, s, "1", NULL, ROUTE_DISABLED); - iroute = handle_update_instance(1, ctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); - SUBENTRY(entry_layer3_forwarding_instance, ctx, iroute, permission); + init_args_rentry(&curr_routefwdargs, s, "1", NULL, ROUTE_DISABLED); + iroute = handle_update_instance(1, dmctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, iroute) == DM_STOP) + goto end; } fp = fopen(ROUTE_FILE, "r"); if ( fp != NULL) { - fgets(line, MAX_PROC_ROUTE, fp); - while (fgets(line, MAX_PROC_ROUTE, fp) != NULL ) + fgets(line, MAX_PROC_ROUTING, fp); + while (fgets(line, MAX_PROC_ROUTING, fp) != NULL ) { if (line[0] == '\n') continue; @@ -700,46 +700,13 @@ inline int entry_layer3_forwarding(struct dmctx *ctx) if (is_proute_static(&proute)) continue; ss = update_route_dynamic_section(&proute); - init_args_rentry(ctx, ss, "0", &proute, ROUTE_DYNAMIC); - iroute = handle_update_instance(1, ctx, &iroute_last, forwarding_update_instance_alias_icwmpd, 4, ss, "routeinstance", "routealias", &find_max); - SUBENTRY(entry_layer3_forwarding_instance, ctx, iroute, "0"); + init_args_rentry(&curr_routefwdargs, ss, "0", &proute, ROUTE_DYNAMIC); + iroute = handle_update_instance(1, dmctx, &iroute_last, forwarding_update_instance_alias_icwmpd, 4, ss, "routeinstance", "routealias", &find_max); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, iroute) == DM_STOP) + goto end; } fclose(fp) ; } +end: return 0; } -////////////////////////////////////// - -int entry_method_root_layer3_forwarding(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Layer3Forwarding.") { - DMOBJECT(DMROOT"Layer3Forwarding.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"Layer3Forwarding.Forwarding.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("DefaultConnectionService", ctx, "1", get_layer3_def_conn_serv, set_layer3_def_conn_serv, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ForwardNumberOfEntries", ctx, "0", get_layer3_nbr_entry, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - SUBENTRY(entry_layer3_forwarding, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_layer3_forwarding_instance(struct dmctx *ctx, char *iroute, char *permission) -{ - IF_MATCH(ctx, DMROOT"Layer3Forwarding.Forwarding.%s.", iroute) { - DMOBJECT(DMROOT"Layer3Forwarding.Forwarding.%s.", ctx, "0", 1, NULL, NULL, NULL, iroute); - DMPARAM("Enable", ctx, permission, get_layer3_enable, set_layer3_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_layer3_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Alias", ctx, "1", get_layer3_alias, set_layer3_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Type", ctx, "0", get_layer3_type, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DestIPAddress", ctx, permission, get_layer3_destip, set_layer3_destip, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DestSubnetMask", ctx, permission, get_layer3_destmask, set_layer3_destmask, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceIPAddress", ctx, "0", get_layer3_src_address, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceSubnetMask", ctx, "0", get_layer3_src_mask, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("GatewayIPAddress", ctx, permission, get_layer3_gatewayip, set_layer3_gatewayip, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Interface", ctx, permission, get_layer3_interface_linker_parameter, set_layer3_interface_linker_parameter, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ForwardingMetric", ctx, permission, get_layer3_metric, set_layer3_metric, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MTU", ctx, permission, get_layer3_mtu, set_layer3_mtu, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr098/layer_3_forwarding.h b/dm/dmtree/tr098/layer_3_forwarding.h index e36fab4..f097432 100644 --- a/dm/dmtree/tr098/layer_3_forwarding.h +++ b/dm/dmtree/tr098/layer_3_forwarding.h @@ -2,29 +2,45 @@ #define __LAYER3_FORWORDING_H #define ROUTE_FILE "/proc/net/route" -#define MAX_PROC_ROUTE 256 -struct proc_route { - char *iface; - char *flags; - char *refcnt; - char *use; - char *metric; - char *mtu; - char *window; - char *irtt; - char destination[16]; - char gateway[16]; - char mask[16]; +enum enum_route_type { + ROUTE_STATIC, + ROUTE_DYNAMIC, + ROUTE_DISABLED }; -struct routefwdargs -{ - char *permission; - struct uci_section *routefwdsection; - struct proc_route *proute; - int type; -}; +extern struct dm_permession_s DMForwarding_perm; + +extern DMLEAF tForwardingInstParam[]; +extern DMOBJ tLayer3ForwardingObj[]; +extern DMLEAF tLayer3ForwardingParam[]; + +int browseForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +char *get_forwording_perm(char *refparam, struct dmctx *dmctx, void *data, char *instance); + +int get_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_src_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_src_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_layer3_mtu(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_layer3_def_conn_serv(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_mtu(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_layer3_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int entry_method_root_layer3_forwarding(struct dmctx *ctx); #endif diff --git a/dm/dmtree/tr098/uploaddiagnostic.c b/dm/dmtree/tr098/uploaddiagnostic.c index c0f569d..20c9ced 100644 --- a/dm/dmtree/tr098/uploaddiagnostic.c +++ b/dm/dmtree/tr098/uploaddiagnostic.c @@ -4,23 +4,37 @@ * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com) + * Copyright (C) 2012-2016 PIVA SOFTWARE (www.pivasoftware.com) * Author: Imen Bhiri - * Author: Feten Besbes + * Author: Anis Ellouze */ #include #include #include -#include "cwmp.h" -#include "diagnostic.h" -#include "ubus.h" #include "dmcwmp.h" #include "dmuci.h" #include "dmubus.h" #include "dmcommon.h" #include "uploaddiagnostic.h" + +DMLEAF tUploadDiagnosticsParam[] = { +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_upload_diagnostics_state, set_upload_diagnostics_state, NULL, NULL}, +{"UploadURL", &DMWRITE, DMT_STRING, get_upload_diagnostics_url, set_upload_diagnostics_url, NULL, NULL}, +{"TestFileLength", &DMWRITE, DMT_UNINT, get_upload_diagnostic_test_file_length, set_upload_diagnostic_test_file_length, NULL, NULL}, +{"EthernetPriority", &DMWRITE, DMT_UNINT, get_upload_diagnostics_ethernet_priority, set_upload_diagnostics_ethernet_priority, NULL, NULL}, +{"ROMTime", &DMREAD, DMT_TIME, get_upload_diagnostic_romtime, NULL, NULL, NULL}, +{"BOMTime", &DMREAD, DMT_TIME, get_upload_diagnostic_bomtime, NULL, NULL, NULL}, +{"EOMTime", &DMREAD, DMT_TIME, get_upload_diagnostic_eomtime, NULL, NULL, NULL}, +{"TotalBytesSent", &DMREAD, DMT_UNINT, get_upload_diagnostic_totalbytes, NULL, NULL, NULL}, +{"TCPOpenRequestTime", &DMREAD, DMT_TIME, get_upload_diagnostic_tcp_open_request_time, NULL, NULL, NULL}, +{"TCPOpenResponseTime", &DMREAD, DMT_TIME, get_upload_diagnostic_tcp_open_response_time, NULL, NULL, NULL}, +//{"DSCP", &DMWRITE, DMT_UNINT, get_upload_diagnostics_dscp, set_upload_diagnostics_dscp, NULL, NULL}, +//{"Interface", &DMWRITE, DMT_UNINT, get_upload_diagnostics_interface, set_upload_diagnostics_interface, NULL, NULL}, +{0} +}; + static inline char *upload_diagnostic_get(char *option, char *def) { char *tmp; @@ -30,13 +44,13 @@ static inline char *upload_diagnostic_get(char *option, char *def) else return tmp; } -int get_upload_diagnostics_state(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = upload_diagnostic_get("DiagnosticState", "None"); return 0; } -int set_upload_diagnostics_state(char *refparam, struct dmctx *ctx, int action, char *value) +int set_upload_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -46,7 +60,7 @@ int set_upload_diagnostics_state(char *refparam, struct dmctx *ctx, int action, case VALUESET: if (strcmp(value, "Requested") == 0) { UPLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "downloaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); @@ -59,13 +73,13 @@ int set_upload_diagnostics_state(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "interface", value); return 0; } -int set_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -74,7 +88,7 @@ int set_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, int acti return 0; case VALUESET: UPLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); @@ -85,14 +99,14 @@ int set_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_upload_diagnostics_url(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "url", value); return 0; } -int set_upload_diagnostics_url(char *refparam, struct dmctx *ctx, int action, char *value) +int set_upload_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -101,7 +115,7 @@ int set_upload_diagnostics_url(char *refparam, struct dmctx *ctx, int action, ch return 0; case VALUESET: UPLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); @@ -112,13 +126,13 @@ int set_upload_diagnostics_url(char *refparam, struct dmctx *ctx, int action, ch return 0; } -int get_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; return 0; } -int set_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, int action, char *value) +int set_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -128,7 +142,7 @@ int set_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, return 0; case VALUESET: UPLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); @@ -139,7 +153,7 @@ int set_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, return 0; } -int get_upload_diagnostic_romtime(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostic_romtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "ROMtime", value); @@ -148,7 +162,7 @@ int get_upload_diagnostic_romtime(char *refparam, struct dmctx *ctx, char **valu return 0; } -int get_upload_diagnostic_bomtime(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostic_bomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "BOMtime", value); @@ -157,7 +171,7 @@ int get_upload_diagnostic_bomtime(char *refparam, struct dmctx *ctx, char **valu return 0; } -int get_upload_diagnostic_eomtime(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostic_eomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "EOMtime", value); @@ -166,7 +180,7 @@ int get_upload_diagnostic_eomtime(char *refparam, struct dmctx *ctx, char **valu return 0; } -int get_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "TestFileLength", value); @@ -175,7 +189,7 @@ int get_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, ch return 0; } -int set_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, int action, char *value) +int set_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -185,7 +199,7 @@ int set_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, in return 0; case VALUESET: UPLOAD_DIAGNOSTIC_STOP - curr_section = dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); + curr_section = (struct uci_section *)dmuci_walk_state_section("cwmp", "uploaddiagnostic", NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); if(!curr_section) { dmuci_add_state_section("cwmp", "uploaddiagnostic", &curr_section, &tmp); @@ -196,7 +210,7 @@ int set_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, in return 0; } -int get_upload_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "TotalBytesSent", value); @@ -205,7 +219,7 @@ int get_upload_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, char **v return 0; } -int get_upload_diagnostic_tcp_open_request_time(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostic_tcp_open_request_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "TCPOpenRequestTime", value); @@ -214,7 +228,7 @@ int get_upload_diagnostic_tcp_open_request_time(char *refparam, struct dmctx *ct return 0; } -int get_upload_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_upload_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@uploaddiagnostic[0]", "TCPOpenResponseTime", value); @@ -223,23 +237,3 @@ int get_upload_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *c return 0; } -int entry_method_root_Upload_Diagnostics(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"UploadDiagnostics.") { - DMOBJECT(DMROOT"UploadDiagnostics.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("DiagnosticsState", ctx, "1", get_upload_diagnostics_state, set_upload_diagnostics_state, NULL, 0, 1, UNDEF, NULL); - //DMPARAM("Interface", ctx, "1", get_upload_diagnostics_interface, set_upload_diagnostics_interface, NULL, 0, 1, UNDEF, NULL); //TODO - DMPARAM("UploadURL", ctx, "1", get_upload_diagnostics_url, set_upload_diagnostics_url, NULL, 0, 1, UNDEF, NULL); - DMPARAM("TestFileLength", ctx, "1", get_upload_diagnostic_test_file_length, set_upload_diagnostic_test_file_length, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - //DMPARAM("DSCP", ctx, "1", get_upload_diagnostics_dscp, set_upload_diagnostics_dscp, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPriority", ctx, "1", get_upload_diagnostics_ethernet_priority, set_upload_diagnostics_ethernet_priority, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("ROMTime", ctx, "0", get_upload_diagnostic_romtime, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("BOMTime", ctx, "0", get_upload_diagnostic_bomtime, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("EOMTime", ctx, "0", get_upload_diagnostic_eomtime, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("TotalBytesSent", ctx, "0", get_upload_diagnostic_totalbytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("TCPOpenRequestTime", ctx, "0", get_upload_diagnostic_tcp_open_request_time, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - DMPARAM("TCPOpenResponseTime", ctx, "0", get_upload_diagnostic_tcp_open_response_time, NULL, "xsd:dateTime", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr098/uploaddiagnostic.h b/dm/dmtree/tr098/uploaddiagnostic.h index 598f628..e2ccc23 100644 --- a/dm/dmtree/tr098/uploaddiagnostic.h +++ b/dm/dmtree/tr098/uploaddiagnostic.h @@ -10,6 +10,23 @@ #ifndef __UPLOAD_DIAGNOSTIC_H #define __UPLOAD_DIAGNOSTIC_H -int entry_method_root_Upload_Diagnostics(struct dmctx *ctx); +extern DMLEAF tUploadDiagnosticsParam[]; +static inline char *upload_diagnostic_get(char *option, char *def); +int get_upload_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_upload_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_upload_diagnostics_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_upload_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_upload_diagnostics_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_upload_diagnostics_ethernet_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_upload_diagnostic_romtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_upload_diagnostic_bomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_upload_diagnostic_eomtime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_upload_diagnostic_test_file_length(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_upload_diagnostic_totalbytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_upload_diagnostic_tcp_open_request_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_upload_diagnostic_tcp_open_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); #endif diff --git a/dm/dmtree/tr098/wandevice.c b/dm/dmtree/tr098/wandevice.c index 8f5c5b3..125d927 100644 --- a/dm/dmtree/tr098/wandevice.c +++ b/dm/dmtree/tr098/wandevice.c @@ -24,9 +24,158 @@ #define WAN_INST_ATM 2 #define WAN_INST_PTM 3 -inline int entry_wandevice_sub_instance(struct dmctx *ctx, char *dev, int i, char *cwritable, bool notif_permission); -inline int entry_wandevice_wanconnectiondevice_instance(struct dmctx *ctx, char *idev, int i, char *iwan, char *fwan, char *cwritable, bool notif_permission, bool ipn_perm, bool pppn_perm); -inline int entry_wandevice_wanprotocolconnection_instance(struct dmctx *ctx, char *idev, char *iwan, char *iconp, int proto, bool notif_permission, bool forced_inform_eip, int forced_notify); + +/*** WANDevice.{i}. ***/ +DMOBJ tWANDeviceObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +//dynamic +{"WANConnectionDevice", &DMWANConnectionDevice, add_wan_wanconnectiondevice, delete_wan_wanconnectiondevice, NULL, browsewanconnectiondeviceInst, &DMFINFRM, &DMWANConnectionDevicenotif, tWANConnectionDeviceObj, tWANConnectionDeviceParam, NULL}, +{"WANCommonInterfaceConfig", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWANCommonInterfaceConfigParam, NULL}, +#ifndef EX400 +{"WANDSLInterfaceConfig", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWANDSLInterfaceConfigParam, NULL}, +#endif +{"WANEthernetInterfaceConfig", &DMREAD, NULL, NULL, check_wan_is_ethernet, NULL, NULL, NULL, tWANEthernetInterfaceConfigObj, tWANEthernetInterfaceConfigParam, NULL}, +{0} +}; + +DMLEAF tWANDeviceParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wan_dev_alias, set_wan_dev_alias, NULL, NULL}, +{0} +}; + +/*** WANDevice.{i}.WANConnectionDevice.{i}. ***/ +DMOBJ tWANConnectionDeviceObj[] = { +{"WANIPConnection", &DMWRITE, add_wan_wanipconnection, delete_wan_wanipconnectiondevice, NULL, browsewanprotocolconnectionipInst, &DMFINFRM, &DMWANConnectionDevicenotif, tWANConnectionObj, tWANIPConnectionParam, get_protocol_connection_linker}, +{"WANPPPConnection", &DMWRITE, add_wan_wanpppconnection, delete_wan_wanpppconnectiondevice, NULL, browsewanprotocolconnectionpppInst, &DMFINFRM, &DMWANConnectionDevicenotif, tWANConnectionObj, tWANPPPConnectionParam, get_protocol_connection_linker}, +//Depend on wandev type +#ifndef EX400 +{"WANDSLLinkConfig", &DMREAD, NULL, NULL, check_wan_is_atm, NULL, NULL, NULL, NULL, tWANDSLLinkConfigParam, NULL}, +#endif +{0} +}; + +DMLEAF tWANConnectionDeviceParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wan_con_dev_alias, set_wan_con_dev_alias, NULL, NULL}, +{0} +}; + +/*** WANDevice.{i}.WANConnectionDevice.{i}.WANIPConnection.{i}. ***/ +/*** WANDevice.{i}.WANConnectionDevice.{i}.WANPPPConnection.{i}. ***/ +DMOBJ tWANConnectionObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +//dynamic +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWANConnectionStatsParam, NULL}, +{"X_INTENO_COM_VLAN", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWANConnection_VLANParam, NULL}, +{0} +}; + +DMLEAF tWANIPConnectionParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wan_ip_con_alias, set_wan_ip_con_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_interface_enable_wanproto, set_interface_enable_wanproto, NULL, NULL}, +{"ConnectionStatus", &DMREAD, DMT_STRING, get_wan_device_mng_status, NULL, NULL, NULL}, +{"ExternalIPAddress", &DMREAD, DMT_STRING, get_wan_device_mng_interface_ip, NULL, &DMWANConnectionProtocolinform, &DMWANConnectionDevicenotif}, //TO CHECK +{"MACAddress", &DMREAD, DMT_STRING, get_wan_device_mng_interface_mac, NULL, NULL, NULL}, +{"ConnectionType", &DMWRITE, DMT_STRING, get_wan_ip_link_connection_connection_type, set_wan_ip_link_connection_connection_type, NULL, NULL}, +{"AddressingType", &DMWRITE, DMT_STRING, get_wan_ip_link_connection_addressing_type, set_wan_ip_link_connection_addressing_type, NULL, NULL}, +{"NATEnabled", &DMWRITE, DMT_BOOL, get_wan_ip_link_connection_nat_enabled, set_wan_ip_link_connection_nat_enabled, NULL, NULL}, +{"X_BROADCOM_COM_FirewallEnabled", &DMWRITE, DMT_BOOL, get_interface_firewall_enabled_wanproto, set_interface_firewall_enabled_wanproto, NULL, NULL}, +{"X_BROADCOM_COM_IGMPEnabled", &DMWRITE, DMT_BOOL, get_wan_ip_link_connection_igmp_enabled, set_wan_ip_link_connection_igmp_enabled, NULL, NULL}, +{"DNSEnabled", &DMWRITE, DMT_BOOL, get_wan_ip_link_connection_dns_enabled, set_wan_ip_link_connection_dns_enabled, NULL, NULL}, +{"DNSOverrideAllowed", &DMREAD, DMT_STRING, get_empty, NULL, NULL, NULL}, +{"Name", &DMWRITE, DMT_STRING, get_wan_ip_link_connection_name, set_wan_ip_link_connection_connection_name, NULL, NULL}, +{0} +}; + +DMLEAF tWANPPPConnectionParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_wan_ppp_con_alias, set_wan_ppp_con_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_interface_enable_wanproto, set_interface_enable_wanproto, NULL, NULL}, +{"ConnectionStatus", &DMREAD, DMT_STRING, get_wan_device_ppp_status, NULL, NULL, NULL}, +//{"ExternalIPAddress", &DMREAD, DMT_STRING, get_wan_device_ppp_interface_ip, NULL, &DMWANConnectionProtocolinform, NULL}, //TO CHECK +{"MACAddress", &DMREAD, DMT_STRING, get_wan_device_mng_interface_mac, NULL, NULL, NULL}, +{"Username", &DMWRITE, DMT_STRING, get_wan_device_ppp_username, set_wan_device_username, NULL, NULL}, +{"Password", &DMWRITE, DMT_STRING, get_empty, set_wan_device_password, NULL, NULL}, +{"Name", &DMWRITE, DMT_STRING, get_wan_ip_link_connection_name, set_wan_ip_link_connection_connection_name, NULL, NULL}, +{0} +}; + +/*** WANDevice.{i}.WANConnectionDevice.{i}.WANIPConnection.{i}.Stats. ***/ +/*** WANDevice.{i}.WANConnectionDevice.{i}.WANPPPConnection.{i}.Stats. ***/ +DMLEAF tWANConnectionStatsParam[] = { +{"EthernetBytesReceived", &DMREAD, DMT_UNINT, get_wan_link_connection_eth_bytes_received, NULL, NULL, NULL}, +{"EthernetBytesSent", &DMREAD, DMT_UNINT, get_wan_link_connection_eth_bytes_sent, NULL, NULL, NULL}, +{"EthernetPacketsReceived", &DMREAD, DMT_UNINT, get_wan_link_connection_eth_pack_received, NULL, NULL, NULL}, +{"EthernetPacketsSent", &DMREAD, DMT_UNINT, get_wan_link_connection_eth_pack_sent, NULL, NULL, NULL}, +{0} +}; + +/*** WANDevice.{i}.WANConnectionDevice.{i}.WANIPConnection.{i}.X_INTENO_COM_VLAN. ***/ +/*** WANDevice.{i}.WANConnectionDevice.{i}.WANPPPConnection.{i}.X_INTENO_COM_VLAN. ***/ +DMLEAF tWANConnection_VLANParam[] = { +{"VLANID", &DMWRITE, DMT_UNINT, get_wan_ip_link_connection_vid, set_wan_ip_link_connection_vid, NULL, NULL}, +{"VLANPriority", &DMWRITE, DMT_UNINT, get_wan_ip_link_connection_vpriority, set_wan_ip_link_connection_vpriority, NULL, NULL}, +{"Layer2Interface", &DMWRITE, DMT_STRING, get_wan_ip_link_connection_layer2_interface, set_wan_ip_link_connection_layer2_interface, NULL, NULL}, +{0} +}; + +/*** WANDevice.{i}.WANConnectionDevice.{i}.WANDSLLinkConfig. ***/ +DMLEAF tWANDSLLinkConfigParam[] = { +#ifndef EX400 +{"Enable", &DMREAD, DMT_BOOL, get_wan_dsl_link_config_enable, NULL, NULL, NULL}, +{"DestinationAddress", &DMWRITE, DMT_STRING, get_wan_dsl_link_config_destination_address, set_wan_dsl_link_config_destination_address, NULL, NULL}, +{"ATMEncapsulation", &DMWRITE, DMT_STRING, get_wan_dsl_link_config_atm_encapsulation, set_wan_dsl_link_config_atm_encapsulation, NULL, NULL}, +#endif +{0} +}; + +/*** WANDevice.{i}.WANCommonInterfaceConfig. ***/ +DMLEAF tWANCommonInterfaceConfigParam[] = { +{"WANAccessType", &DMREAD, DMT_STRING, get_wan_device_wan_access_type, NULL, NULL, NULL}, +{0} +}; + +/*** WANDevice.{i}.WANDSLInterfaceConfig. ***/ +DMLEAF tWANDSLInterfaceConfigParam[] = { +#ifndef EX400 +{"Status", &DMREAD, DMT_STRING, get_wan_device_wan_dsl_interface_config_status, NULL, NULL, NULL}, +{"ModulationType", &DMREAD, DMT_STRING, get_wan_device_wan_dsl_interface_config_modulation_type, NULL, NULL, NULL}, +{"DataPath", &DMREAD, DMT_STRING, get_wan_device_dsl_datapath, NULL, NULL, NULL}, +{"DownstreamCurrRate", &DMREAD, DMT_UNINT, get_wan_device_dsl_downstreamcurrrate, NULL, NULL, NULL}, +{"DownstreamMaxRate", &DMREAD, DMT_UNINT, get_wan_device_dsl_downstreammaxrate, NULL, NULL, NULL}, +{"DownstreamAttenuation", &DMREAD, DMT_INT, get_wan_device_dsl_downstreamattenuation, NULL, NULL, NULL}, +{"DownstreamNoiseMargin", &DMREAD, DMT_INT, get_wan_device_dsl_downstreamnoisemargin, NULL, NULL, NULL}, +{"UpstreamCurrRate", &DMREAD, DMT_UNINT, get_wan_device_dsl_upstreamcurrrate, NULL, NULL, NULL}, +{"UpstreamMaxRate", &DMREAD, DMT_UNINT, get_wan_device_dsl_upstreammaxrate, NULL, NULL, NULL}, +{"UpstreamAttenuation", &DMREAD, DMT_INT, get_wan_device_dsl_upstreamattenuation, NULL, NULL, NULL}, +{"UpstreamNoiseMargin", &DMREAD, DMT_INT, get_wan_device_dsl_upstreamnoisemargin, NULL, NULL, NULL}, +{"X_INTENO_SE_AnnexMEnable", &DMWRITE, DMT_BOOL, get_annexm_status, set_annexm_enable, NULL, NULL}, +#endif +{0} +}; + +/*** WANDevice.{i}.WANEthernetInterfaceConfig. ***/ +DMOBJ tWANEthernetInterfaceConfigObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +//dynamic +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWANEthernetInterfaceConfigStatsParam, NULL}, +{0} +}; + +DMLEAF tWANEthernetInterfaceConfigParam[] = { +{"Enable", &DMWRITE, DMT_BOOL, get_wan_eth_intf_enable, set_wan_eth_intf_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_wan_eth_intf_status, NULL, NULL, NULL}, +{"MACAddress", &DMREAD, DMT_STRING, get_wan_eth_intf_mac, NULL, NULL, NULL}, +{0} +}; + +/*** WANDevice.{i}.WANEthernetInterfaceConfig.Stats. ***/ +DMLEAF tWANEthernetInterfaceConfigStatsParam[] = { +{"BytesSent", &DMREAD, DMT_UNINT, get_wan_eth_intf_stats_tx_bytes, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_wan_eth_intf_stats_rx_bytes, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_wan_eth_intf_stats_tx_packets, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_wan_eth_intf_stats_rx_packets, NULL, NULL, NULL}, +{0} +}; + enum WAN_TYPE_CONNECTION { WAN_IP_CONNECTION, @@ -72,34 +221,38 @@ static char *default_wan_ifname; static int default_wan_proto; static char *eth_wan = NULL; -struct wanargs cur_wanargs = {0}; -struct wancdevargs cur_wancdevargs = {0}; -struct wancprotoargs cur_wancprotoargs = {0}; +/************************************************************************** +* LINKER +***************************************************************************/ -inline int init_wanargs(struct dmctx *ctx, int wan_instance, char *fdev, struct uci_section *s) +int get_protocol_connection_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + + if (data && ((struct wanargs *)data)->wancprotosection) + { + dmasprintf(linker, "linker_interface:%s", section_name(((struct wanargs *)data)->wancprotosection)); + return 0; + } + *linker = ""; + return 0; +} + +inline int init_wanargs(struct wanargs *args, int wan_instance, char *fdev, struct uci_section *s) { - struct wanargs *args = &cur_wanargs; - ctx->args = (void *)args; args->instance = wan_instance; args->fdev = fdev; args->wandevsection = s; return 0; } -inline int init_wancprotoargs(struct dmctx *ctx, struct uci_section *s) +inline int init_wancprotoargs(struct wanargs *args, struct uci_section *s) { - struct wancprotoargs *args = &cur_wancprotoargs; - ctx->args = (void *)args; args->wancprotosection = s; return 0; } -inline int init_wancdevargs(struct dmctx *ctx, struct uci_section *s, int index, char *fwan, char *iwan, char *wan_ifname) +inline int init_wancdevargs(struct wanargs *args, struct uci_section *s, char *fwan, char *iwan, char *wan_ifname) { - struct wancdevargs *args = &cur_wancdevargs; - ctx->args = (void *)args; - args->wandevsection = s; - args->index = index; + args->wancdsection = s; args->fwan = fwan; args->iwan = iwan; args->wan_ifname = wan_ifname; @@ -127,10 +280,9 @@ inline int add_wvlan(char *baseifname, char *ifname, char *vid, char *prioprity, return 0; } -void set_bridge_layer2(struct dmctx *ctx, char *bridge) +void set_bridge_layer2(struct dmctx *ctx, char *bridge, struct wanargs *wandcprotoargs) { - char *wifname, *dup, *pch, *spch, *ifname; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + char *wifname, *dup, *pch, *spch; struct uci_section *s; dmuci_get_value_by_section_string(wandcprotoargs->wancprotosection, "ifname", &wifname); @@ -160,10 +312,15 @@ void set_bridge_layer2(struct dmctx *ctx, char *bridge) #endif else if (strstr(pch, eth_wan)) { #ifdef EX400 + uci_foreach_option_eq("network", "interface", "ifname", pch, s) { + dmuci_set_value_by_section(s, "bridge", bridge); + + fprintf(stdout, "bridge = %s\n", bridge); } + #else uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "ifname", pch, s) { @@ -279,7 +436,7 @@ char *get_last_instance_proto(char *package, char *section, char *opt_inst, char return instance; } -int add_wan_wanconnectiondevice(struct dmctx *ctx, char **instancepara) +int add_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { #ifndef EX400 int iwan, idx; @@ -288,7 +445,7 @@ int add_wan_wanconnectiondevice(struct dmctx *ctx, char **instancepara) char ifname[16] = {0}; char buf[16] = {0}; struct uci_section *s = NULL; - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; if (wandargs->instance == WAN_INST_ATM) { idx = get_cfg_layer2idx("layer2_interface_adsl", "atm_bridge", "baseifname", sizeof("atm")-1); @@ -322,63 +479,61 @@ int add_wan_wanconnectiondevice(struct dmctx *ctx, char **instancepara) } return FAULT_9005; #else + return FAULT_9008; #endif } -int delete_wan_wanconnectiondevice_all(struct dmctx *ctx) +int delete_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { #ifndef EX400 struct uci_section *s = NULL; struct uci_section *ss = NULL; - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs; + struct wanargs *wandcdevargs; - uci_foreach_option_cont(wan_devices[wandargs->instance - 1].cdev, wan_devices[wandargs->instance - 1].stype, "baseifname", wandargs->fdev, s) { - if (ss) - dmuci_delete_by_section(ss, NULL, NULL); - ss = s; + switch (del_action) { + case DEL_INST: + wandcdevargs = (struct wanargs *)data; + dmuci_delete_by_section(wandcdevargs->wancdsection, NULL, NULL); + uci_foreach_option_cont("network", "interface", "ifname", wandcdevargs->fwan, s) { + if (ss) + wan_remove_dev_interface(ss, wandcdevargs->fwan); + ss = s; + } + if (ss != NULL) + wan_remove_dev_interface(ss, wandcdevargs->fwan); + return 0; + case DEL_ALL: + wandargs = (struct wanargs *)data; + uci_foreach_option_cont(wan_devices[wandargs->instance - 1].cdev, wan_devices[wandargs->instance - 1].stype, "baseifname", wandargs->fdev, s) { + if (ss) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + + ss = NULL; + uci_foreach_option_cont("network", "interface", "ifname", wandargs->fdev, s) { + if (ss) + wan_remove_dev_interface(ss, wandargs->fdev); + ss = s; + } + if (ss != NULL) + wan_remove_dev_interface(ss, wandargs->fdev); + return 0; } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - - ss = NULL; - uci_foreach_option_cont("network", "interface", "ifname", wandargs->fdev, s) { - if (ss) - wan_remove_dev_interface(ss, wandargs->fdev); - ss = s; - } - if (ss != NULL) - wan_remove_dev_interface(ss, wandargs->fdev); return 0; #else + return FAULT_9008; #endif } -int delete_wan_wanconnectiondevice(struct dmctx *ctx) +int add_wan_wanipconnection(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { -#ifndef EX400 - struct uci_section *s = NULL; - struct uci_section *ss = NULL; - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; - - dmuci_delete_by_section(wandcdevargs->wandevsection, NULL, NULL); - uci_foreach_option_cont("network", "interface", "ifname", wandcdevargs->fwan, s) { - if (ss) - wan_remove_dev_interface(ss, wandcdevargs->fwan); - ss = s; - } - if (ss != NULL) - wan_remove_dev_interface(ss, wandcdevargs->fwan); - return 0; -#else - return FAULT_9008; -#endif -} - -int add_wan_wanipconnection(struct dmctx *ctx, char **instancepara) -{ - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + struct wanargs *wandcdevargs = (struct wanargs *)data; char sname[16] = {0}; char ifname[8] = {0}; char *instance; @@ -386,9 +541,11 @@ int add_wan_wanipconnection(struct dmctx *ctx, char **instancepara) instance = get_last_instance_proto("network", "interface", "conipinstance", "ifname", wandcdevargs->fwan, "proto", WAN_PROTO_IP); dmasprintf(instancepara, "%d", instance ? atoi(instance) + 1 : 1); //MEM WILL BE FREED IN DMMEMCLEAN #ifdef EX400 + sprintf(sname,"wan_1_%s_%d_%s", wandcdevargs->iwan, WAN_IP_CONNECTION, *instancepara); + #else - sprintf(sname,"wan_%s_%s_%d_%s", wan_devices[wandcdevargs->index].instance, wandcdevargs->iwan, WAN_IP_CONNECTION, *instancepara); + sprintf(sname,"wan_%s_%s_%d_%s", wan_devices[wandcdevargs->instance].instance, wandcdevargs->iwan, WAN_IP_CONNECTION, *instancepara); #endif sprintf(ifname, "%s.1", wandcdevargs->fwan); dmuci_set_value("network", sname, NULL, "interface"); @@ -398,59 +555,50 @@ int add_wan_wanipconnection(struct dmctx *ctx, char **instancepara) return 0; } -int delete_wan_wanipconnectiondevice_all(struct dmctx *ctx) +int delete_wan_wanipconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { char *ifname, *iproto; struct uci_section *s = NULL; struct uci_section *ss = NULL; - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + struct wanargs *wandcdevargs = (struct wanargs *)data; - dmuci_get_value_by_section_string(wandcdevargs->wandevsection, "ifname", &ifname); - uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { - dmuci_get_value_by_section_string(s, "proto", &iproto); - if (strcmp(iproto, "dhcp") == 0 || strcmp(iproto, "static") == 0) { - if (ss) + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(wandcdevargs->wancprotosection, NULL, NULL); + return 0; + case DEL_ALL: + dmuci_get_value_by_section_string(wandcdevargs->wancdsection, "ifname", &ifname); + uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { + dmuci_get_value_by_section_string(s, "proto", &iproto); + if (strcmp(iproto, "dhcp") == 0 || strcmp(iproto, "static") == 0) { + if (ss) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + } + } + if (ss != NULL) dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - } + return 0; } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); return 0; } -int delete_wan_wanipconnectiondevice(struct dmctx *ctx) +int add_wan_wanpppconnection(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; - - dmuci_delete_by_section(wandcdevargs->wandevsection, NULL, NULL); - return 0; -} - -int delete_wan_wanpppconnectiondevice(struct dmctx *ctx) -{ - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; - - dmuci_delete_by_section(wandcdevargs->wandevsection, NULL, NULL); - return 0; -} - -int add_wan_wanpppconnection(struct dmctx *ctx, char **instancepara) -{ - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + struct wanargs *wandcdevargs = (struct wanargs *)data; char sname[16] = {0}; char ifname[8] = {0}; char *instance; instance = get_last_instance_proto("network", "interface", "conpppinstance", "ifname", wandcdevargs->fwan, "proto", WAN_PROTO_PPP); dmasprintf(instancepara, "%d", instance ? atoi(instance) + 1 : 1); - #ifdef EX400 - sprintf(sname,"wan_1_%s_%d_%s", wandcdevargs->iwan, WANPPPConnection, *instancepara); -#else - sprintf(sname,"wan_%s_%s_%d_%s", wan_devices[wandcdevargs->index].instance, wandcdevargs->iwan, WANPPPConnection, *instancepara); -#endif + sprintf(sname,"wan_1_%s_%d_%s", wandcdevargs->iwan, WANPPPConnection, *instancepara); + +#else + sprintf(sname,"wan_%s_%s_%d_%s", wan_devices[wandcdevargs->instance].instance, wandcdevargs->iwan, WANPPPConnection, *instancepara); +#endif sprintf(ifname, "%s.1", wandcdevargs->fwan); dmuci_set_value("network", sname, NULL, "interface"); dmuci_set_value("network", sname, "ifname", ifname); @@ -459,25 +607,32 @@ int add_wan_wanpppconnection(struct dmctx *ctx, char **instancepara) return 0; } -int delete_wan_wanpppconnectiondevice_all(struct dmctx *ctx) +int delete_wan_wanpppconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; char *ifname, *iproto; struct uci_section *s = NULL; struct uci_section *ss = NULL; - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + struct wanargs *wandcdevargs = (struct wanargs *)data; - dmuci_get_value_by_section_string(wandcdevargs->wandevsection, "ifname", &ifname); - uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { - dmuci_get_value_by_section_string(s, "proto", &iproto); - if (strstr(iproto, "ppp")) { //CHECK IF WE CAN OPTIMISE AND IF iproto can be pppoa - if (ss) - dmuci_delete_by_section(ss, NULL, NULL); - ss = s; + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(wandcdevargs->wancprotosection, NULL, NULL); + return 0; + case DEL_ALL: + dmuci_get_value_by_section_string(wandcdevargs->wancdsection, "ifname", &ifname); + uci_foreach_option_eq("network", "interface", "ifname", ifname, s) { + dmuci_get_value_by_section_string(s, "proto", &iproto); + if (strstr(iproto, "ppp")) { //CHECK IF WE CAN OPTIMISE AND IF iproto can be pppoa + if (ss) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + } + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + return 0; } - } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); return 0; } /********************/ @@ -507,9 +662,9 @@ int get_wan_device_wan_dsl_traffic() return dsl; } -int get_wan_device_wan_access_type(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_wan_access_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; switch(wandargs->instance) { case WAN_INST_ETH: *value = "Ethernet"; @@ -525,9 +680,9 @@ int get_wan_device_wan_access_type(char *refparam, struct dmctx *ctx, char **val return 0; } -int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *status; int dsl; json_object *res; @@ -562,9 +717,9 @@ end: return 0; } -int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *mode; int dsl; json_object *res = NULL; @@ -600,9 +755,9 @@ int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, stru return 0; } -int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char buf[512], *val = "", *pch, *spch, *pch2, *spch2, *dup; int dsl, pp, r; *value = "None"; @@ -645,9 +800,9 @@ int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *rate_down; int dsl; json_object *res = NULL; @@ -680,9 +835,9 @@ int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, cha return 0; } -int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *max_down; int dsl; json_object *res = NULL; @@ -714,9 +869,9 @@ int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, char return 0; } -int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *attn_down_x100; int dsl; json_object *res = NULL; @@ -740,9 +895,9 @@ int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, return 0; } -int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *snr_down_x100; int dsl; json_object *res; @@ -766,9 +921,9 @@ int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, return 0; } -int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *rate_up; int dsl; json_object *res = NULL; @@ -798,9 +953,9 @@ int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, char return 0; } -int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *max_up; int dsl; json_object *res = NULL; @@ -830,9 +985,9 @@ int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, char * return 0; } -int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *attn_up_x100; int dsl; json_object *res = NULL; @@ -856,9 +1011,9 @@ int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, ch return 0; } -int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; char *snr_up_x100; int dsl; json_object *res; @@ -887,10 +1042,11 @@ int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, ch return 0; } -int get_annexm_status(char *refparam, struct dmctx *ctx, char **value) +int get_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val = "0"; - struct wanargs *wandargs = (struct wanargs *)ctx->args; + *value = "0"; + struct wanargs *wandargs = (struct wanargs *)data; if (wandargs->instance == WAN_INST_ATM) { dmuci_get_option_value_string("layer2_interface", "capabilities", "AnnexM", &val); @@ -904,11 +1060,11 @@ int get_annexm_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_annexm_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_annexm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; switch (action) { case VALUECHECK: @@ -931,11 +1087,11 @@ int set_annexm_enable(char *refparam, struct dmctx *ctx, int action, char *value } //TO CHECK IF NO VALUE RETURNE BY UBUS CMD -int get_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, char **value) +int get_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val; bool b; - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wandargs->fdev, String}}, 1, &res); @@ -951,14 +1107,14 @@ int get_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s; json_object *res; char *enable, *type, *device, json_name[32]; bool b; bool enable_b; - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; switch (action) { case VALUECHECK: @@ -1007,9 +1163,9 @@ end: return 0; } -int get_wan_eth_intf_status(char *refparam, struct dmctx *ctx, char **value) +int get_wan_eth_intf_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; json_object *res; bool b; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wandargs->fdev, String}}, 1, &res); @@ -1025,9 +1181,9 @@ int get_wan_eth_intf_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wan_eth_intf_mac(char *refparam, struct dmctx *ctx, char **value) +int get_wan_eth_intf_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wandargs->fdev, String}}, 1, &res); DM_ASSERT(res, *value = "00:00:00:00:00:00"); @@ -1038,9 +1194,9 @@ int get_wan_eth_intf_mac(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wan_eth_intf_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_wan_eth_intf_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wandargs->fdev, String}}, 1, &res); @@ -1052,9 +1208,9 @@ int get_wan_eth_intf_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **va return 0; } -int get_wan_eth_intf_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_wan_eth_intf_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wandargs->fdev, String}}, 1, &res); @@ -1066,9 +1222,9 @@ int get_wan_eth_intf_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **va return 0; } -int get_wan_eth_intf_stats_tx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_wan_eth_intf_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wandargs->fdev, String}}, 1, &res); @@ -1080,9 +1236,9 @@ int get_wan_eth_intf_stats_tx_packets(char *refparam, struct dmctx *ctx, char ** return 0; } -int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wanargs *wandargs = (struct wanargs *)ctx->args; + struct wanargs *wandargs = (struct wanargs *)data; json_object *res; dmubus_call("network.device", "status", UBUS_ARGS{{"name", wandargs->fdev, String}}, 1, &res); @@ -1098,15 +1254,15 @@ int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, char ** **** **** function related to get_wandevice_wanconnectiondevice_parameters **** **** ***************************************************************************/ -int get_wan_dsl_link_config_enable(char *refparam, struct dmctx *ctx, char **value) +int get_wan_dsl_link_config_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int get_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, char **value) +int get_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + struct wanargs *wandcdevargs = (struct wanargs *)data; char *vpi, *vci; struct uci_section *s; @@ -1119,11 +1275,11 @@ int get_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ct return 0; } -int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *vpi = NULL, *vci = NULL, *spch, *val; struct uci_section *s; - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + struct wanargs *wandcdevargs = (struct wanargs *)data; switch (action) { case VALUECHECK: @@ -1151,9 +1307,9 @@ int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ct return 0; } -int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, char **value) +int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + struct wanargs *wandcdevargs = (struct wanargs *)data; struct uci_section *s; char *type, *encapsulation, *encaptype; *value = ""; @@ -1181,13 +1337,12 @@ int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, return 0; } -int set_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int i; struct uci_section *s; - char *type, *pch; - char *encapsulation = NULL, *encaptype = NULL; - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; + char *type, *encapsulation, *encaptype, *pch; + struct wanargs *wandcdevargs = (struct wanargs *)data; switch (action) { case VALUECHECK: @@ -1230,35 +1385,35 @@ int set_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, **** **** function related to get_wandevice_wanprotoclconnection_parameters **** **** ***************************************************************************/ -int get_interface_enable_wanproto(char *refparam, struct dmctx *ctx, char **value) +int get_interface_enable_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *intf = section_name(wandcprotoargs->wancprotosection); return get_interface_enable_ubus(intf, refparam, ctx, value); } -int set_interface_enable_wanproto(char *refparam, struct dmctx *ctx, int action, char *value) +int set_interface_enable_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *intf = section_name(wandcprotoargs->wancprotosection); return set_interface_enable_ubus(intf, refparam, ctx, action, value); } -int get_interface_firewall_enabled_wanproto(char *refparam, struct dmctx *ctx, char **value) +int get_interface_firewall_enabled_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *intf = section_name(wandcprotoargs->wancprotosection); return get_interface_firewall_enabled(intf, refparam, ctx, value); } -int set_interface_firewall_enabled_wanproto(char *refparam, struct dmctx *ctx, int action, char *value) +int set_interface_firewall_enabled_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *intf = section_name(wandcprotoargs->wancprotosection); return set_interface_firewall_enabled(intf, refparam, ctx, action, value); } //THE same as get_wan_device_ppp_status WHY DO WE CREATE A SEPARATED FUNCTION -int get_wan_device_mng_status(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_mng_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res = NULL, *jobj = NULL; char *pending = NULL; @@ -1266,7 +1421,7 @@ int get_wan_device_mng_status(char *refparam, struct dmctx *ctx, char **value) char *status = NULL; char *uptime = NULL; bool b = false; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", intf, String}}, 1, &res); @@ -1291,20 +1446,20 @@ int get_wan_device_mng_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wan_device_mng_interface_ip(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_mng_interface_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *intf; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); network_get_ipaddr(value, intf); return 0; } -int get_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *type; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *)ctx->args; + struct wanargs *wandcprotoargs = (struct wanargs *)data; dmuci_get_value_by_section_string(wandcprotoargs->wancprotosection, "type", &type); if (strcmp(type, "bridge") == 0 || strcmp(type, "alias") == 0) @@ -1314,10 +1469,10 @@ int get_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx return 0; } -int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *type = ""; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; switch (action) { case VALUECHECK: @@ -1329,7 +1484,7 @@ int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx return 0; else { type = "bridge"; - set_bridge_layer2(ctx, "1"); + set_bridge_layer2(ctx, "1", wandcprotoargs); } } else if (strcmp(value, "IP_Routed") == 0) { @@ -1337,7 +1492,7 @@ int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx return 0; else { if (strcmp(type, "bridge") == 0) - set_bridge_layer2(ctx, ""); + set_bridge_layer2(ctx, "", wandcprotoargs); type = "anywan"; } } @@ -1349,10 +1504,10 @@ int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx return 0; } -int get_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *proto; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; dmuci_get_value_by_section_string(wandcprotoargs->wancprotosection, "proto", &proto); if (strcmp(proto, "dhcp") == 0) @@ -1364,10 +1519,10 @@ int get_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx return 0; } -int set_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; switch (action) { case VALUECHECK: @@ -1385,11 +1540,11 @@ int set_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx return 0; } -int get_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *intf, *masq, *network; struct uci_section *s = NULL; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); uci_foreach_sections("firewall", "zone", s) { @@ -1406,13 +1561,13 @@ int get_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, ch return 0; } -int set_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *intf; int found = 0; struct uci_section *s = NULL; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); switch (action) { @@ -1480,13 +1635,13 @@ int get_wan_igmp_rule_idx(char *iface, struct uci_section **rule, struct uci_sec return 0; } -int get_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *intf, *enable = "0"; struct uci_section *rule = NULL; struct uci_section *zone = NULL; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); get_wan_igmp_rule_idx(intf, &rule, &zone, &enable); @@ -1494,14 +1649,14 @@ int get_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, c return 0; } -int set_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; int found = 0; char *val, *intf, *enable, *zname, buf[32]; struct uci_section *rule = NULL; struct uci_section *zone = NULL; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); switch (action) { @@ -1535,9 +1690,9 @@ int set_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, i return 0; } -int get_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; dmuci_get_value_by_section_string(wandcprotoargs->wancprotosection, "peerdns", value); if ((*value)[0] == '\0') { @@ -1546,11 +1701,11 @@ int get_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, ch return 0; } -int set_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *intf; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); switch (action) { @@ -1569,7 +1724,7 @@ int set_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, in } } -int get_wan_device_ppp_status(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *intf; char *status = NULL; @@ -1577,7 +1732,7 @@ int get_wan_device_ppp_status(char *refparam, struct dmctx *ctx, char **value) char *pending = NULL; json_object *res = NULL, *jobj = NULL; bool bstatus = false, bpend = false; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", intf, String}}, 1, &res); @@ -1602,21 +1757,21 @@ int get_wan_device_ppp_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wan_device_ppp_interface_ip(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_ppp_interface_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *intf, *val; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; intf = section_name(wandcprotoargs->wancprotosection); network_get_ipaddr(value, intf); return 0; } -int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *intf, *device; json_object *res, *jobj; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; *value = ""; intf = section_name(wandcprotoargs->wancprotosection); @@ -1634,17 +1789,17 @@ int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, char **v return 0; } -int get_wan_device_ppp_username(char *refparam, struct dmctx *ctx, char **value) +int get_wan_device_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *intf; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; dmuci_get_value_by_section_string(wandcprotoargs->wancprotosection, "username", value); return 0; } -int set_wan_device_username(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_device_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; switch (action) { case VALUECHECK: return 0; @@ -1655,9 +1810,9 @@ int set_wan_device_username(char *refparam, struct dmctx *ctx, int action, char return 0; } -int set_wan_device_password(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_device_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; switch (action) { case VALUECHECK: @@ -1669,21 +1824,21 @@ int set_wan_device_password(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_wan_ip_link_connection_name(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancprotoargs *args = (struct wancprotoargs *)ctx->args; + struct wanargs *args = (struct wanargs *)data; *value = dmstrdup(section_name(args->wancprotosection)); return 0; } -int set_wan_ip_link_connection_connection_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_connection_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct wancprotoargs *args; + struct wanargs *args; switch (action) { case VALUECHECK: return 0; case VALUESET: - args = (struct wancprotoargs *)ctx->args; + args = (struct wanargs *)data; dmuci_rename_section_by_section(args->wancprotosection, value); return 0; } @@ -1729,9 +1884,9 @@ int get_layer2_interface(char *wan_name, char **ifname) return 0; } -int get_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *wan_name = section_name(wandcprotoargs->wancprotosection); struct uci_section *ss = NULL; char *ifname; @@ -1750,10 +1905,10 @@ int get_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, char **val return 0; } -int set_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *ss = NULL, *w_vlan, *s_last = NULL; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *add_value, *ifname, *vid, *prio; char *wan_name = section_name(wandcprotoargs->wancprotosection); bool found = false; @@ -1846,9 +2001,9 @@ int set_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, int action } return 0; } -int get_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *wan_name = section_name(wandcprotoargs->wancprotosection); struct uci_section *ss = NULL; char *ifname; @@ -1869,11 +2024,11 @@ int get_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, char return 0; } -int set_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *ifname; struct uci_section *ss = NULL; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *wan_name = section_name(wandcprotoargs->wancprotosection); switch (action) { @@ -1897,9 +2052,9 @@ int set_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, int return 0; } -int get_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *wan_name = section_name(wandcprotoargs->wancprotosection); struct uci_section *ss = NULL; char *ifname, *p; @@ -1920,11 +2075,11 @@ int get_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ct return 0; } -int set_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *ifname, *add_value; struct uci_section *ss = NULL, *w_vlan, *s_last; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *wandcprotoargs = (struct wanargs *)data; char *wan_name = section_name(wandcprotoargs->wancprotosection); char *p, *q, *wifname, *baseifname = NULL, *vid = NULL, *prio = NULL; char r_new_wifname[128]; @@ -1995,17 +2150,18 @@ int set_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ct return 0; } -inline int ubus_get_wan_stats(json_object *res, char **value, char *stat_mod) +inline int ubus_get_wan_stats(json_object *res, char **value, char *stat_mod, struct wanargs *wanargs) { char *proto; json_object *res1; char *device_name; - dmuci_get_option_value_string("network", section_name(cur_wancprotoargs.wancprotosection), "proto", &proto); + + dmuci_get_option_value_string("network", section_name(wanargs->wancprotosection), "proto", &proto); if (strcmp(proto, "dhcp") == 0 || strcmp(proto, "pppoe") == 0) { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface",section_name(cur_wancprotoargs.wancprotosection)}, String}, 1, &res1); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface",section_name(wanargs->wancprotosection)}, String}, 1, &res1); device_name = dmjson_get_value(res1, 1, "device"); - dmubus_call("network.device", "status", UBUS_ARGS{{"name",device_name, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", device_name, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", stat_mod); return 0; @@ -2014,109 +2170,159 @@ inline int ubus_get_wan_stats(json_object *res, char **value, char *stat_mod) return 0; } -int get_wan_link_connection_eth_bytes_received(char *refparam, struct dmctx *ctx, char **value) +int get_wan_link_connection_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res = NULL; - ubus_get_wan_stats(res, value, "rx_bytes"); + json_object *res; + ubus_get_wan_stats(res, value, "rx_bytes", (struct wanargs *)data); return 0; } -int get_wan_link_connection_eth_bytes_sent(char *refparam, struct dmctx *ctx, char **value) +int get_wan_link_connection_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res = NULL; - ubus_get_wan_stats(res, value, "tx_bytes"); + json_object *res; + ubus_get_wan_stats(res, value, "tx_bytes", (struct wanargs *)data); return 0; } -int get_wan_link_connection_eth_pack_received(char *refparam, struct dmctx *ctx, char **value) +int get_wan_link_connection_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res = NULL; - ubus_get_wan_stats(res, value, "rx_packets"); + json_object *res; + ubus_get_wan_stats(res, value, "rx_packets", (struct wanargs *)data); return 0; } -int get_wan_link_connection_eth_pack_sent(char *refparam, struct dmctx *ctx, char **value) +int get_wan_link_connection_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - json_object *res = NULL; - ubus_get_wan_stats(res, value, "tx_packets"); + json_object *res; + ubus_get_wan_stats(res, value, "tx_packets", (struct wanargs *)data); return 0; } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_wan_dev_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wanargs.wandevsection, "wan_dev_alias", value); + dmuci_get_value_by_section_string(((struct wanargs *)data)->wandevsection, "wan_dev_alias", value); return 0; } -int set_wan_dev_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wanargs.wandevsection, "wan_dev_alias", value); + dmuci_set_value_by_section(((struct wanargs *)data)->wandevsection, "wan_dev_alias", value); return 0; } return 0; } -int get_wan_con_dev_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wan_con_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wancdevargs.wandevsection, "wanalias", value); + dmuci_get_value_by_section_string(((struct wanargs *)data)->wancdsection, "wanalias", value); return 0; } -int set_wan_con_dev_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_con_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wancdevargs.wandevsection, "wanalias", value); + dmuci_set_value_by_section(((struct wanargs *)data)->wancdsection, "wanalias", value); return 0; } return 0; } -int get_wan_ip_con_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ip_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wancprotoargs.wancprotosection, "conipalias", value); + dmuci_get_value_by_section_string(((struct wanargs *)data)->wancprotosection, "conipalias", value); return 0; } -int set_wan_ip_con_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ip_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wancprotoargs.wancprotosection, "conipalias", value); + dmuci_set_value_by_section(((struct wanargs *)data)->wancprotosection, "conipalias", value); return 0; } return 0; } -int get_wan_ppp_con_alias(char *refparam, struct dmctx *ctx, char **value) +int get_wan_ppp_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wancprotoargs.wancprotosection, "conpppalias", value); + dmuci_get_value_by_section_string(((struct wanargs *)data)->wancprotosection, "conpppalias", value); return 0; } -int set_wan_ppp_con_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wan_ppp_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wancprotoargs.wancprotosection, "conpppalias", value); + dmuci_set_value_by_section(((struct wanargs *)data)->wancprotosection, "conpppalias", value); return 0; } return 0; } /////////////SUB ENTRIES/////////////// -int entry_wandevice_sub(struct dmctx *ctx) +/*************************************************/ + +char *get_wan_connection_device_perm(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + + int tmp = WAN_IDX_ETH + 1; + if (((struct wanargs *)data)->instance == tmp ) + return "0"; + else + return "1"; +} + +unsigned char get_wan_protocol_connection_forced_inform(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + return 1; + struct wanargs *wancprotoarg = (struct wanargs *)data; + if (strcmp(section_name(wancprotoarg->wancprotosection), default_wan) == 0) + return 1; + return 0; +} + +bool check_wan_is_ethernet(struct dmctx *dmctx, void *data) +{ + struct wanargs *wanargs = (struct wanargs *)data; + if(wanargs->instance == WAN_IDX_ETH + 1) + return true; + else + return false; +} + +bool check_wan_is_atm(struct dmctx *dmctx, void *data) +{ + struct wanargs *wanargs = (struct wanargs *)data; + if(wanargs->instance == WAN_IDX_ATM + 1) + return true; + else + return false; +} + +char *get_wan_connection_device_notif(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + struct wanargs *wancprotoarg = (struct wanargs *)data; + if (strcmp(section_name(wancprotoarg->wancprotosection), default_wan) == 0) + return "2"; + return "0"; +} + + + + +int browsewandeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { int i = 0; bool notif_permission; @@ -2124,36 +2330,41 @@ int entry_wandevice_sub(struct dmctx *ctx) char *defwanproto; struct uci_section *s = NULL; char *dev, *dev_last= NULL; + struct wanargs curr_wanargs = {0}; + dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &default_wan); dmuci_get_option_value_string("network", default_wan, "ifname", &default_wan_ifname); dmuci_get_option_value_string("network", default_wan, "proto", &defwanproto); - #ifdef EX400 + dmuci_get_option_value_string("ports", "WAN", "ifname", ð_wan); + #else dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", ð_wan); wan_devices[WAN_IDX_ETH].fdev = eth_wan; #endif - if (strstr(defwanproto, "ppp")) default_wan_proto = WAN_PROTO_PPP; else if (strcmp(defwanproto, "dhcp") == 0 || strcmp(defwanproto, "static") == 0) default_wan_proto = WAN_PROTO_IP; else default_wan_proto = WAN_PROTO_NIL; - update_section_list(DMMAP,"wan_dev", NULL, 3, NULL, NULL, NULL, NULL, NULL); - uci_path_foreach_sections(icwmpd, "dmmap", "wan_dev", s) { + update_section_list(DMMAP,"wan_dev", NULL, 3, NULL, NULL, NULL, NULL, NULL); + uci_path_foreach_sections(icwmpd, "dmmap", "wan_dev", s) { #ifdef EX400 + if(i==WAN_IDX_ETH){ - init_wanargs(ctx, i+1, eth_wan, s); + + init_wanargs(&curr_wanargs, i+1, eth_wan, s); if (strstr(default_wan_ifname, eth_wan)) notif_permission = false; else notif_permission = true; + } #else - init_wanargs(ctx, i+1, wan_devices[i].fdev, s); + init_wanargs(&curr_wanargs, i+1, wan_devices[i].fdev, s); if (strstr(default_wan_ifname, wan_devices[i].fdev)) notif_permission = false; @@ -2161,25 +2372,30 @@ int entry_wandevice_sub(struct dmctx *ctx) notif_permission = true; #endif - if (i == WAN_IDX_ETH) cwritable = "0"; #ifndef EX400 else cwritable = "1"; #endif - - dev = handle_update_instance(1, ctx, &dev_last, update_instance_alias_icwmpd, 3, s, "wan_dev_instance", "wan_dev_alias"); + dev = handle_update_instance(1, dmctx, &dev_last, update_instance_alias_icwmpd, 3, s, "wan_dev_instance", "wan_dev_alias"); #ifdef EX400 - if(i==WAN_IDX_ETH) SUBENTRY(entry_wandevice_sub_instance, ctx, dev, i++, cwritable, notif_permission); + if(i==WAN_IDX_ETH){ + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wanargs, dev) == DM_STOP) + break; + + } #else - SUBENTRY(entry_wandevice_sub_instance, ctx, dev, i++, cwritable, notif_permission); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wanargs, dev) == DM_STOP) + break; #endif + i++; } return 0; } -int entry_wandevice_wanconnectiondevice(struct dmctx *ctx, char *dev, int i, char *cwritable) +int browsewanconnectiondeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *fwan; @@ -2189,21 +2405,38 @@ int entry_wandevice_wanconnectiondevice(struct dmctx *ctx, char *dev, int i, cha bool ipn_perm = true; bool pppn_perm = true; bool notif_permission = true; + int i; + struct wanargs *curr_wanargs = (struct wanargs *)prev_data; + + i = curr_wanargs->instance - 1; #ifdef EX400 + if (i==0){ uci_foreach_sections("ports", "ethport", s) { + if(!strcmp(s->e.name, "WAN")){ + dmuci_get_value_by_section_string(s, "ifname", &fwan); + dmuci_get_option_value_string("network", "wan", "ifname", &wan_ifname); + if (strstr(default_wan_ifname, fwan)) { + notif_permission = false; + if (default_wan_proto == WAN_PROTO_IP) ipn_perm = false; else if (default_wan_proto == WAN_PROTO_PPP) pppn_perm = false; + } - iwan = handle_update_instance(2, ctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); - init_wancdevargs(ctx, s, i, fwan, iwan_last, wan_ifname); - SUBENTRY(entry_wandevice_wanconnectiondevice_instance, ctx, dev, i, iwan, fwan, cwritable, notif_permission, ipn_perm, pppn_perm); + iwan = handle_update_instance(2, dmctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); + + init_wancdevargs(curr_wanargs, s, fwan, iwan_last, wan_ifname); + + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iwan) == DM_STOP){ + break; + } + } } } @@ -2218,16 +2451,16 @@ int entry_wandevice_wanconnectiondevice(struct dmctx *ctx, char *dev, int i, cha if (default_wan_proto == WAN_PROTO_IP) ipn_perm = false; else if (default_wan_proto == WAN_PROTO_PPP) pppn_perm = false; } - iwan = handle_update_instance(2, ctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); - init_wancdevargs(ctx, s, i, fwan, iwan_last, wan_ifname); - SUBENTRY(entry_wandevice_wanconnectiondevice_instance, ctx, dev, i, iwan, fwan, cwritable, notif_permission, ipn_perm, pppn_perm); + iwan = handle_update_instance(2, dmctx, &iwan_last, update_instance_alias, 3, s, "waninstance", "wanalias"); + init_wancdevargs(curr_wanargs, s, fwan, iwan_last, wan_ifname); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iwan) == DM_STOP) + break; } #endif - return 0; } -int entry_wandevice_wanprotocolconnection(struct dmctx *ctx, char *idev, char *iwan, char *fwan) +int browsewanprotocolconnectionipInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *ss = NULL; char *pack, *stype, *p, *iconp_ip_last = NULL, *iconp_ppp_last = NULL; @@ -2236,7 +2469,7 @@ int entry_wandevice_wanprotocolconnection(struct dmctx *ctx, char *idev, char *i bool notif_permission = true; bool forced_inform_eip = false; int forced_notify = UNDEF; - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); + struct wanargs *curr_wanargs = (struct wanargs *)prev_data; char *lan_name; char *wan_interface; @@ -2258,10 +2491,69 @@ int entry_wandevice_wanprotocolconnection(struct dmctx *ctx, char *idev, char *i if(freq[0]=='5') dmasprintf(&wan_interface, "%s", s->e.name); } }else{ - dmasprintf(&wan_interface, "%s", fwan); + dmasprintf(&wan_interface, "%s", curr_wanargs->fwan); } }else{ - dmasprintf(&wan_interface, "%s", fwan); + dmasprintf(&wan_interface, "%s", curr_wanargs->fwan); + } + + uci_foreach_option_cont("network", "interface", "ifname", wan_interface, ss) { + dmuci_get_value_by_section_string(ss, "proto", &p); + lan_name = section_name(ss); + if (strcmp(p, "dhcp") == 0 || strcmp(p, "static") == 0) + proto = WAN_PROTO_IP; + else + return 0; + if (strcmp(lan_name, default_wan) == 0) { + forced_inform_eip = true; + forced_notify = 2; + notif_permission = false; + } + if (check_multiwan_interface(ss, curr_wanargs->fwan) != 0) + continue; + init_wancprotoargs(curr_wanargs, ss); + iconp = handle_update_instance(3, dmctx, &iconp_ip_last, update_instance_alias, 3, ss, "conipinstance", "conipalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iconp) == DM_STOP) + break; + } + return 0; +} + +int browsewanprotocolconnectionpppInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + struct uci_section *ss = NULL; + char *pack, *stype, *p, *iconp_ip_last = NULL, *iconp_ppp_last = NULL; + char *iconp = NULL, *iconp_nil = NULL; + int proto; + bool notif_permission = true; + bool forced_inform_eip = false; + int forced_notify = UNDEF; + struct wanargs *curr_wanargs = (struct wanargs *)prev_data; + char *lan_name; + + char *wan_interface; + char* containsrepeater= NULL; + int repeatindex; + struct uci_section *s = NULL; + char *freq, **value; + json_object *res; + char *isrepeater; + dmuci_get_option_value_string("netmode", "setup", "curmode", &isrepeater); + containsrepeater = strstr(isrepeater, "repeater"); + if(containsrepeater){ + repeatindex = (int)(containsrepeater - isrepeater); + if(repeatindex == 0){ + uci_foreach_sections("wireless", "wifi-device", s) { + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", s->e.name, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + freq = dmjson_get_value(res, 1, "frequency"); + if(freq[0]=='5') dmasprintf(&wan_interface, "%s", s->e.name); + } + }else{ + dmasprintf(&wan_interface, "%s", curr_wanargs->fwan); + } + }else{ + dmasprintf(&wan_interface, "%s", curr_wanargs->fwan); } uci_foreach_option_cont("network", "interface", "ifname", wan_interface, ss) { @@ -2269,160 +2561,23 @@ int entry_wandevice_wanprotocolconnection(struct dmctx *ctx, char *idev, char *i lan_name = section_name(ss); if (strstr(p, "ppp")) proto = WAN_PROTO_PPP; - else if (strcmp(p, "dhcp") == 0 || strcmp(p, "static") == 0) - proto = WAN_PROTO_IP; else - proto = WAN_PROTO_NIL; + return 0; if (strcmp(lan_name, default_wan) == 0) { forced_inform_eip = true; forced_notify = 2; notif_permission = false; } - if (check_multiwan_interface(ss, fwan) != 0) + if (check_multiwan_interface(ss, curr_wanargs->fwan) != 0) continue; - init_wancprotoargs(ctx, ss); - if (proto == WAN_PROTO_IP) { - iconp = handle_update_instance(3, ctx, &iconp_ip_last, update_instance_alias, 3, ss, "conipinstance", "conipalias"); - } - else if (proto == WAN_PROTO_PPP) { - iconp = handle_update_instance(3, ctx, &iconp_ppp_last, update_instance_alias, 3, ss, "conpppinstance", "conpppalias"); - } - SUBENTRY(entry_wandevice_wanprotocolconnection_instance, ctx, idev, iwan, iconp, proto, - notif_permission, forced_inform_eip, forced_notify); + init_wancprotoargs(curr_wanargs, ss); + iconp = handle_update_instance(3, dmctx, &iconp_ppp_last, update_instance_alias, 3, ss, "conpppinstance", "conpppalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)curr_wanargs, iconp) == DM_STOP) + break; } return 0; } -/*************************************************/ -int entry_method_root_WANDevice(struct dmctx *ctx) -{ - dmuci_get_option_value_string("cwmp", "cpe", "default_wan_interface", &default_wan); - IF_MATCH(ctx, DMROOT"WANDevice.") { - DMOBJECT(DMROOT"WANDevice.", ctx, "0", 0, NULL, NULL, NULL); - SUBENTRY(entry_wandevice_sub, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_wandevice_sub_instance(struct dmctx *ctx, char *dev, int i, char *cwritable, bool notif_permission) -{ - IF_MATCH(ctx, DMROOT"WANDevice.%s.", dev) { - DMOBJECT(DMROOT"WANDevice.%s.", ctx, "0", notif_permission, NULL, NULL, NULL, dev); - DMPARAM("Alias", ctx, "1", get_wan_dev_alias, set_wan_dev_alias, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.", ctx, cwritable, notif_permission, add_wan_wanconnectiondevice, delete_wan_wanconnectiondevice_all, NULL, dev); - DMOBJECT(DMROOT"WANDevice.%s.WANCommonInterfaceConfig.", ctx, "0", 1, NULL, NULL, NULL, dev); - DMPARAM("WANAccessType", ctx, "0", get_wan_device_wan_access_type, NULL, NULL, 0, 1, UNDEF, NULL); -#ifndef EX400 - DMOBJECT(DMROOT"WANDevice.%s.WANDSLInterfaceConfig.", ctx, "0", 1, NULL, NULL, NULL, dev); - DMPARAM("Status", ctx, "0", get_wan_device_wan_dsl_interface_config_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ModulationType", ctx, "0", get_wan_device_wan_dsl_interface_config_modulation_type, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DataPath", ctx, "0", get_wan_device_dsl_datapath, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DownstreamCurrRate", ctx, "0", get_wan_device_dsl_downstreamcurrrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DownstreamMaxRate", ctx, "0", get_wan_device_dsl_downstreammaxrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DownstreamAttenuation", ctx, "0", get_wan_device_dsl_downstreamattenuation, NULL, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("DownstreamNoiseMargin", ctx, "0", get_wan_device_dsl_downstreamnoisemargin, NULL, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamCurrRate", ctx, "0", get_wan_device_dsl_upstreamcurrrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamMaxRate", ctx, "0", get_wan_device_dsl_upstreammaxrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamAttenuation", ctx, "0", get_wan_device_dsl_upstreamattenuation, NULL, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamNoiseMargin", ctx, "0", get_wan_device_dsl_upstreamnoisemargin, NULL, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_AnnexMEnable", ctx, "1", get_annexm_status, set_annexm_enable, "xsd:boolean", 0, 1, UNDEF, NULL); -#endif - if( i == WAN_IDX_ETH ) { - DMOBJECT(DMROOT"WANDevice.%s.WANEthernetInterfaceConfig.", ctx, "0", 1, NULL, NULL, NULL, dev); - DMPARAM("Enable", ctx, "1", get_wan_eth_intf_enable, set_wan_eth_intf_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_wan_eth_intf_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MACAddress", ctx, "0", get_wan_eth_intf_mac, NULL, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WANDevice.%s.WANEthernetInterfaceConfig.Stats.", ctx, "0", 1, NULL, NULL, NULL, dev); - DMPARAM("BytesSent", ctx, "0", get_wan_eth_intf_stats_tx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_wan_eth_intf_stats_rx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_wan_eth_intf_stats_tx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_wan_eth_intf_stats_rx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - } - SUBENTRY(entry_wandevice_wanconnectiondevice, ctx, dev, i, cwritable); - return 0; - } - return FAULT_9005; -} - -inline int entry_wandevice_wanconnectiondevice_instance(struct dmctx *ctx, char *idev, int i, char *iwan, char *fwan, char *cwritable, bool notif_permission, bool ipn_perm, bool pppn_perm) -{ - IF_MATCH(ctx, DMROOT"WANDevice.%s.WANConnectionDevice.%s.", idev, iwan) { - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.", ctx, cwritable, notif_permission, NULL, delete_wan_wanconnectiondevice, NULL, idev, iwan); - DMPARAM("Alias", ctx, "1", get_wan_con_dev_alias, set_wan_con_dev_alias, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.", ctx, "1", ipn_perm, add_wan_wanipconnection, delete_wan_wanipconnectiondevice_all, NULL, idev, iwan); - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.", ctx, "1", pppn_perm, add_wan_wanpppconnection, delete_wan_wanpppconnectiondevice_all, NULL, idev, iwan); -#ifndef EX400 - if (i == WAN_IDX_ATM) { - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANDSLLinkConfig.", ctx, "0", 1, NULL, NULL, NULL, idev, iwan); - DMPARAM("Enable", ctx, "0", get_wan_dsl_link_config_enable, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("DestinationAddress", ctx, "1", get_wan_dsl_link_config_destination_address, set_wan_dsl_link_config_destination_address, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ATMEncapsulation", ctx, "1", get_wan_dsl_link_config_atm_encapsulation, set_wan_dsl_link_config_atm_encapsulation, NULL, 0, 1, UNDEF, NULL); - } -#endif - SUBENTRY(entry_wandevice_wanprotocolconnection, ctx, idev, iwan, fwan); - return 0; - } - return FAULT_9005; -} - -inline int entry_wandevice_wanprotocolconnection_instance(struct dmctx *ctx, char *idev, char *iwan, char *iconp, int proto, - bool notif_permission, bool forced_inform_eip, int forced_notify) -{ - struct wancprotoargs *wandcprotoargs = (struct wancprotoargs *) (ctx->args); - char *linker; - dmastrcat(&linker, "linker_interface:", section_name(wandcprotoargs->wancprotosection)); - if (proto == WAN_PROTO_IP) { - IF_MATCH(ctx, DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.", idev, iwan, iconp) { - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.", ctx, "1", notif_permission, NULL, delete_wan_wanipconnectiondevice, linker, idev, iwan, iconp); - DMPARAM("Alias", ctx, "1", get_wan_ip_con_alias, set_wan_ip_con_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_interface_enable_wanproto, set_interface_enable_wanproto, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ConnectionStatus", ctx, "0", get_wan_device_mng_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalIPAddress", ctx, "0", get_wan_device_mng_interface_ip, NULL, NULL, forced_inform_eip, notif_permission, forced_notify, NULL); - DMPARAM("MACAddress", ctx, "0", get_wan_device_mng_interface_mac, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ConnectionType", ctx, "1", get_wan_ip_link_connection_connection_type, set_wan_ip_link_connection_connection_type, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AddressingType", ctx, "1", get_wan_ip_link_connection_addressing_type, set_wan_ip_link_connection_addressing_type, NULL, 0, 1, UNDEF, NULL); - DMPARAM("NATEnabled", ctx, "1", get_wan_ip_link_connection_nat_enabled, set_wan_ip_link_connection_nat_enabled, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("X_BROADCOM_COM_FirewallEnabled", ctx, "1", get_interface_firewall_enabled_wanproto, set_interface_firewall_enabled_wanproto, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("X_BROADCOM_COM_IGMPEnabled", ctx, "1", get_wan_ip_link_connection_igmp_enabled, set_wan_ip_link_connection_igmp_enabled, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("DNSEnabled", ctx, "1", get_wan_ip_link_connection_dns_enabled, set_wan_ip_link_connection_dns_enabled, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("DNSOverrideAllowed", ctx, "0", get_empty, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "1", get_wan_ip_link_connection_name, set_wan_ip_link_connection_connection_name, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.X_INTENO_COM_VLAN.", ctx, "1", 1, NULL, NULL, NULL, idev, iwan, iconp); - DMPARAM("VLANID", ctx, "1", get_wan_ip_link_connection_vid, set_wan_ip_link_connection_vid, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("VLANPriority", ctx, "1", get_wan_ip_link_connection_vpriority, set_wan_ip_link_connection_vpriority, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Layer2Interface", ctx, "1", get_wan_ip_link_connection_layer2_interface, set_wan_ip_link_connection_layer2_interface, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANIPConnection.%s.Stats.", ctx, "1", 1, NULL, NULL, NULL, idev, iwan, iconp); - DMPARAM("EthernetBytesReceived", ctx, "0", get_wan_link_connection_eth_bytes_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetBytesSent", ctx, "0", get_wan_link_connection_eth_bytes_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPacketsReceived", ctx, "0", get_wan_link_connection_eth_pack_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPacketsSent", ctx, "0", get_wan_link_connection_eth_pack_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - } - else if (proto == WAN_PROTO_PPP) { - IF_MATCH(ctx, DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.%s.", idev, iwan, iconp) { - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.%s.", ctx, "1", notif_permission, NULL, delete_wan_wanpppconnectiondevice, linker, idev, iwan, iconp); - DMPARAM("Alias", ctx, "1", get_wan_ppp_con_alias, set_wan_ppp_con_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_interface_enable_wanproto, set_interface_enable_wanproto, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("ConnectionStatus", ctx, "0", get_wan_device_ppp_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ExternalIPAddress", ctx, "0", get_wan_device_ppp_interface_ip, NULL, NULL, forced_inform_eip, notif_permission, forced_notify, NULL); - DMPARAM("MACAddress", ctx, "0", get_wan_device_mng_interface_mac, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Username", ctx, "1", get_wan_device_ppp_username, set_wan_device_username, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Password", ctx, "1", get_empty, set_wan_device_password, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "1", get_wan_ip_link_connection_name, set_wan_ip_link_connection_connection_name, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.%s.X_INTENO_COM_VLAN.", ctx, "1", 1, NULL, NULL, NULL, idev, iwan, iconp); - DMPARAM("VLANID", ctx, "1", get_wan_ip_link_connection_vid, set_wan_ip_link_connection_vid, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("VLANPriority", ctx, "1", get_wan_ip_link_connection_vpriority, set_wan_ip_link_connection_vpriority, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Layer2Interface", ctx, "1", get_wan_ip_link_connection_layer2_interface, set_wan_ip_link_connection_layer2_interface, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WANDevice.%s.WANConnectionDevice.%s.WANPPPConnection.%s.Stats.", ctx, "1", 1, NULL, NULL, NULL, idev, iwan, iconp); - DMPARAM("EthernetBytesReceived", ctx, "0", get_wan_link_connection_eth_bytes_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetBytesSent", ctx, "0", get_wan_link_connection_eth_bytes_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPacketsReceived", ctx, "0", get_wan_link_connection_eth_pack_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPacketsSent", ctx, "0", get_wan_link_connection_eth_pack_sent,NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - } - return FAULT_9005; -} - +struct dm_permession_s DMWANConnectionDevice = {"0", &get_wan_connection_device_perm}; +struct dm_notif_s DMWANConnectionDevicenotif = {NULL, &get_wan_connection_device_notif}; +struct dm_forced_inform_s DMWANConnectionProtocolinform = {1, get_wan_protocol_connection_forced_inform}; diff --git a/dm/dmtree/tr098/wandevice.h b/dm/dmtree/tr098/wandevice.h index 07cc254..cd9d453 100644 --- a/dm/dmtree/tr098/wandevice.h +++ b/dm/dmtree/tr098/wandevice.h @@ -14,27 +14,130 @@ #include #include - -struct wancprotoargs -{ - struct uci_section *wancprotosection; - struct uci_ptr *ptr; -}; - -struct wancdevargs -{ - struct uci_section *wandevsection; - int index; - char *fwan; - char *iwan; - char *wan_ifname; -}; - struct wanargs { +/* WANDevice */ struct uci_section *wandevsection; int instance; char *fdev; +/* WANConnectionDevice */ + struct uci_section *wancdsection; + char *fwan; + char *iwan; + char *wan_ifname; +/* WAN###Connection */ + struct uci_section *wancprotosection; }; -int entry_method_root_WANDevice(struct dmctx *ctx); + +extern struct dm_permession_s DMWANConnectionDevice; +extern struct dm_notif_s DMWANConnectionDevicenotif; +extern struct dm_forced_inform_s DMWANConnectionProtocolinform; + +extern struct dm_notif_s DMWANConnectionDevicenotif; +extern DMOBJ tWANDeviceObj[]; +extern DMLEAF tWANDeviceParam[]; +extern DMOBJ tWANConnectionDeviceObj[]; +extern DMLEAF tWANConnectionDeviceParam[]; +extern DMOBJ tWANConnectionObj[]; +extern DMLEAF tWANIPConnectionParam[]; +extern DMLEAF tWANPPPConnectionParam[]; +extern DMLEAF tWANConnectionStatsParam[]; +extern DMLEAF tWANConnection_VLANParam[]; +extern DMLEAF tWANDSLLinkConfigParam[]; +extern DMLEAF tWANCommonInterfaceConfigParam[]; +extern DMLEAF tWANDSLInterfaceConfigParam[]; +extern DMOBJ tWANEthernetInterfaceConfigObj[]; +extern DMLEAF tWANEthernetInterfaceConfigParam[]; +extern DMLEAF tWANEthernetInterfaceConfigStatsParam[]; + +int browsewandeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +unsigned char get_wan_protocol_connection_forced_inform(char *refparam, struct dmctx *dmctx, void *data, char *instance); +int browsewanconnectiondeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browsewanprotocolconnectionipInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browsewanprotocolconnectionpppInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_wan_wanconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_wan_wanipconnection(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_wan_wanipconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_wan_wanpppconnection(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_wan_wanpppconnectiondevice(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +bool check_wan_is_ethernet(struct dmctx *dmctx, void *data); +bool check_wan_is_atm(struct dmctx *dmctx, void *data); + +int get_wan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_con_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_enable_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_mng_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_mng_interface_ip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_firewall_enabled_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ppp_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_interface_enable_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_link_connection_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_link_connection_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_link_connection_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_link_connection_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_dsl_link_config_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_wan_access_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_eth_intf_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_eth_intf_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_eth_intf_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_eth_intf_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_eth_intf_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_protocol_connection_linker(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_wan_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_con_dev_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_enable_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_firewall_enabled_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_connection_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ppp_con_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_interface_enable_wanproto(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_device_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_device_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_vpriority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_ip_link_connection_layer2_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_annexm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + #endif diff --git a/dm/dmtree/tr098/x_inteno_se_wifi.c b/dm/dmtree/tr098/x_inteno_se_wifi.c index bf2a843..2a8c2a8 100644 --- a/dm/dmtree/tr098/x_inteno_se_wifi.c +++ b/dm/dmtree/tr098/x_inteno_se_wifi.c @@ -19,25 +19,37 @@ #include "x_inteno_se_wifi.h" #include "dmjson.h" -struct sewifiargs cur_wifiargs = {0}; +/*** X_INTENO_SE_Wifi. ***/ +DMLEAF tsewifiParam[] = { +{"Bandsteering_Enable", &DMWRITE, DMT_BOOL, get_bandsteering_enable, set_bandsteering_enable, NULL, NULL}, +{"Bandsteering_Rssi_Threshold", &DMWRITE, DMT_BOOL, get_bandsteering_rssi_threshold, set_bandsteering_rssi_threshold, NULL, NULL}, +{"Bandsteering_Policy", &DMWRITE, DMT_BOOL, get_bandsteering_policy, set_bandsteering_policy, NULL, NULL}, +{"Bandsteering_Bw_Util", &DMWRITE, DMT_BOOL, get_bandsteering_bw_util, set_bandsteering_bw_util, NULL, NULL}, +{0} +}; -inline int entry_sewifi_radio(struct dmctx *ctx); -inline int entry_sewifi_radio_instance(struct dmctx *ctx, char *wnum); -inline int init_se_wifi(struct dmctx *ctx, struct uci_section *s) -{ - struct sewifiargs *args = &cur_wifiargs; - ctx->args = (void *)args; - args->sewifisection = s; - return 0; -} +DMOBJ tsewifiObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Radio", &DMREAD, NULL, NULL, NULL, browsesewifiradioInst, NULL, NULL, NULL, tsewifiradioParam, NULL}, +{0} +}; -int get_bandsteering_enable(char *refparam, struct dmctx *ctx, char **value) +/*** X_INTENO_SE_Wifi.Radio.{i}. ***/ +DMLEAF tsewifiradioParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_radio_alias, set_radio_alias, NULL, NULL}, +{"Frequency", &DMREAD, DMT_STRING, get_wifi_frequency, NULL, NULL, NULL}, +{"MaxAssociations", &DMWRITE, DMT_STRING, get_wifi_maxassoc, set_wifi_maxassoc, NULL, NULL}, +{"DFSEnable", &DMWRITE, DMT_BOOL, get_wifi_dfsenable, set_wifi_dfsenable, NULL, NULL}, +{0} +}; + +int get_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("wireless", "bandsteering", "enabled", value); return 0; } -int set_bandsteering_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -59,74 +71,74 @@ int set_bandsteering_enable(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_bandsteering_rssi_threshold(char *refparam, struct dmctx *ctx, char **value) +int get_bandsteering_rssi_threshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_option_value_string("wireless", "bandsteering", "rssi_threshold", value); - return 0; + dmuci_get_option_value_string("wireless", "bandsteering", "rssi_threshold", value); + return 0; } -int set_bandsteering_rssi_threshold(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bandsteering_rssi_threshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - switch (action) { - case VALUECHECK: - if (value == NULL) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("wireless", "bandsteering", "rssi_threshold", value); - return 0; - } - return 0; + switch (action) { + case VALUECHECK: + if (value == NULL) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("wireless", "bandsteering", "rssi_threshold", value); + return 0; + } + return 0; } -int get_bandsteering_policy(char *refparam, struct dmctx *ctx, char **value) +int get_bandsteering_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_option_value_string("wireless", "bandsteering", "policy", value); - return 0; + dmuci_get_option_value_string("wireless", "bandsteering", "policy", value); + return 0; } -int set_bandsteering_policy(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bandsteering_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - switch (action) { - case VALUECHECK: - if (value == NULL) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("wireless", "bandsteering", "policy", value); - return 0; - } - return 0; + switch (action) { + case VALUECHECK: + if (value == NULL) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("wireless", "bandsteering", "policy", value); + return 0; + } + return 0; } -int get_bandsteering_bw_util(char *refparam, struct dmctx *ctx, char **value) +int get_bandsteering_bw_util(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_option_value_string("wireless", "bandsteering", "bw_util", value); - return 0; + dmuci_get_option_value_string("wireless", "bandsteering", "bw_util", value); + return 0; } -int set_bandsteering_bw_util(char *refparam, struct dmctx *ctx, int action, char *value) +int set_bandsteering_bw_util(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - bool b; + bool b; - switch (action) { - case VALUECHECK: - if (value==NULL) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_set_value("wireless", "bandsteering", "bw_util", value); - return 0; - } - return 0; + switch (action) { + case VALUECHECK: + if (value==NULL) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_set_value("wireless", "bandsteering", "bw_util", value); + return 0; + } + return 0; } -int get_wifi_frequency(char *refparam, struct dmctx *ctx, char **value) +int get_wifi_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *freq; json_object *res; - struct sewifiargs *wifiargs = (struct sewifiargs *)ctx->args; - char *wlan_name = section_name(wifiargs->sewifisection); + struct uci_section *sewifisection = (struct uci_section *)data; + char *wlan_name = section_name(sewifisection); dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -135,50 +147,50 @@ int get_wifi_frequency(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_wifi_maxassoc(char *refparam, struct dmctx *ctx, char **value) +int get_wifi_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct sewifiargs *wifiargs = (struct sewifiargs *)ctx->args; + struct uci_section *sewifisection = (struct uci_section *)data; - dmuci_get_value_by_section_string(wifiargs->sewifisection, "maxassoc", value); + dmuci_get_value_by_section_string(sewifisection, "maxassoc", value); return 0; } -int set_wifi_maxassoc(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wifi_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct sewifiargs *wifiargs = (struct sewifiargs *)ctx->args; + struct uci_section *sewifisection = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(wifiargs->sewifisection, "maxassoc", value); + dmuci_set_value_by_section(sewifisection, "maxassoc", value); return 0; } return 0; } -int get_wifi_dfsenable(char *refparam, struct dmctx *ctx, char **value) +int get_wifi_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val; - struct sewifiargs *wifiargs = (struct sewifiargs *)ctx->args; - char *wlan_name = section_name(wifiargs->sewifisection); + struct uci_section *sewifisection = (struct uci_section *)data; + char *wlan_name = section_name(sewifisection); *value = ""; - dmuci_get_value_by_section_string(wifiargs->sewifisection, "band", &val); + dmuci_get_value_by_section_string(sewifisection, "band", &val); if (val[0] == 'a') { - dmuci_get_value_by_section_string(wifiargs->sewifisection, "dfsc", value); + dmuci_get_value_by_section_string(sewifisection, "dfsc", value); if ((*value)[0] == '\0') *value = "0"; } return 0; } -int set_wifi_dfsenable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wifi_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *val; - struct sewifiargs *wifiargs = (struct sewifiargs *)ctx->args; - char *wlan_name = section_name(wifiargs->sewifisection); + struct uci_section *sewifisection = (struct uci_section *)data; + char *wlan_name = section_name(sewifisection); switch (action) { case VALUECHECK: @@ -186,13 +198,13 @@ int set_wifi_dfsenable(char *refparam, struct dmctx *ctx, int action, char *valu return FAULT_9007; return 0; case VALUESET: - dmuci_get_value_by_section_string(wifiargs->sewifisection, "band", &val); + dmuci_get_value_by_section_string(sewifisection, "band", &val); if (val[0] == 'a') { string_to_bool(value, &b); if (b) - dmuci_set_value_by_section(wifiargs->sewifisection, "dfsc", "1"); + dmuci_set_value_by_section(sewifisection, "dfsc", "1"); else - dmuci_set_value_by_section(wifiargs->sewifisection, "dfsc", "0"); + dmuci_set_value_by_section(sewifisection, "dfsc", "0"); } return 0; } @@ -200,61 +212,34 @@ int set_wifi_dfsenable(char *refparam, struct dmctx *ctx, int action, char *valu } ////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_radio_alias(char *refparam, struct dmctx *ctx, char **value) +int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_wifiargs.sewifisection, "radioalias", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "radioalias", value); return 0; } -int set_radio_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_wifiargs.sewifisection, "radioalias", value); + dmuci_set_value_by_section((struct uci_section *)data, "radioalias", value); return 0; } return 0; } -/////////////SUB ENTRIES/////////////// -inline int entry_sewifi_radio(struct dmctx *ctx) + + +int browsesewifiradioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *wnum_last = NULL; struct uci_section *s = NULL; uci_foreach_sections("wireless", "wifi-device", s) { - init_se_wifi(ctx, s); - wnum = handle_update_instance(1, ctx, &wnum_last, update_instance_alias, 3, s, "radioinstance", "radioalias"); - SUBENTRY(entry_sewifi_radio_instance, ctx, wnum); + wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, s, "radioinstance", "radioalias"); + //SUBENTRY(entry_sewifi_radio_instance, ctx, wnum); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, wnum) == DM_STOP) + break; } return 0; } -////////////////////////////////////// - -int entry_method_root_SE_Wifi(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Wifi.") { - DMOBJECT(DMROOT"X_INTENO_SE_Wifi.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("Bandsteering_Enable", ctx, "1", get_bandsteering_enable, set_bandsteering_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Bandsteering_Rssi_Threshold", ctx, "1", get_bandsteering_rssi_threshold, set_bandsteering_rssi_threshold, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Bandsteering_Policy", ctx, "1", get_bandsteering_policy, set_bandsteering_policy, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Bandsteering_Bw_Util", ctx, "1", get_bandsteering_bw_util, set_bandsteering_bw_util, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"X_INTENO_SE_Wifi.Radio.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_sewifi_radio, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_sewifi_radio_instance(struct dmctx *ctx, char *wnum) -{ - IF_MATCH(ctx, DMROOT"X_INTENO_SE_Wifi.Radio.%s.", wnum) { - DMOBJECT(DMROOT"X_INTENO_SE_Wifi.Radio.%s.", ctx, "0", 1, NULL, NULL, NULL, wnum); - DMPARAM("Alias", ctx, "1", get_radio_alias, set_radio_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Frequency", ctx, "0", get_wifi_frequency, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxAssociations", ctx, "1", get_wifi_maxassoc, set_wifi_maxassoc, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DFSEnable", ctx, "1", get_wifi_dfsenable, set_wifi_dfsenable, "xsd:boolean", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr098/x_inteno_se_wifi.h b/dm/dmtree/tr098/x_inteno_se_wifi.h index 84c9e9a..c0e72be 100644 --- a/dm/dmtree/tr098/x_inteno_se_wifi.h +++ b/dm/dmtree/tr098/x_inteno_se_wifi.h @@ -1,11 +1,28 @@ #ifndef __SE_WIFI_H #define __SE_WIFI_H -struct sewifiargs -{ - struct uci_section *sewifisection; -}; +extern DMLEAF tsewifiradioParam[]; +extern DMLEAF tsewifiParam[]; +extern DMOBJ tsewifiObj[]; -int entry_method_root_SE_Wifi(struct dmctx *ctx); +int get_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bandsteering_rssi_threshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bandsteering_rssi_threshold(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bandsteering_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bandsteering_policy(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_bandsteering_bw_util(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_bandsteering_bw_util(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int browsesewifiradioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wifi_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wifi_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wifi_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wifi_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wifi_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dm/dmtree/tr181/bridging.c b/dm/dmtree/tr181/bridging.c index 23f4493..82dfdc3 100644 --- a/dm/dmtree/tr181/bridging.c +++ b/dm/dmtree/tr181/bridging.c @@ -17,38 +17,128 @@ #include "bridging.h" #include "dmjson.h" -struct bridging_args cur_bridging_args = {0}; -struct bridging_port_args cur_bridging_port_args = {0}; -struct bridging_vlan_args cur_bridging_vlan_args = {0}; char *wan_baseifname = NULL; + +/*** Bridging. ***/ +DMOBJ tBridgingObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Bridge", &DMWRITE, add_bridge, delete_bridge, NULL, browseBridgeInst, NULL, NULL, tDridgingBridgeObj, tDridgingBridgeParams, NULL}, +{0} +}; + +/*** Bridging.Bridge.{i}. ***/ +DMOBJ tDridgingBridgeObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"VLAN", &DMWRITE, add_br_vlan, delete_br_vlan, NULL, browseBridgeVlanInst, NULL, NULL, NULL, tBridgeVlanParams, get_linker_br_vlan}, +{"Port", &DMWRITE, add_br_port, delete_br_port, NULL, browseBridgePortInst, NULL, NULL, tBridgePortObj, tBridgePortParams, get_linker_br_port}, +{"VLANPort", &DMWRITE, NULL, NULL, NULL, browseBridgeVlanPortInst, NULL, NULL, NULL, tBridgeVlanPortParams, NULL}, +{0} +}; + +DMLEAF tDridgingBridgeParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_br_alias, set_br_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_br_enable, set_br_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_br_status, NULL, NULL, NULL}, +{"X_INTENO_COM_AssociatedInterfaces", &DMWRITE, DMT_STRING, get_br_associated_interfaces, set_br_associated_interfaces, NULL, NULL}, +{0} +}; + +/*** Bridging.Bridge.{i}.VLAN.{i}. ***/ +DMLEAF tBridgeVlanParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING,get_br_vlan_alias, set_br_vlan_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_br_vlan_enable, set_br_vlan_enable, NULL, NULL}, +{"Name", &DMWRITE, DMT_STRING, get_br_vlan_name, set_br_vlan_name, NULL, NULL}, +{"VLANID", &DMWRITE, DMT_STRING,get_br_vlan_vid, set_br_vlan_vid, NULL, NULL}, +{"X_INTENO_SE_VLANPriority", &DMWRITE, DMT_STRING, get_br_vlan_priority, set_br_vlan_priority, NULL, NULL}, +{0} +}; + +/*** Bridging.Bridge.{i}.Port.{i}. ***/ +DMOBJ tBridgePortObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Stats", &DMWRITE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tBridgePortStatParams, NULL}, +{0} +}; + +DMLEAF tBridgePortParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_br_port_alias, set_br_port_alias, NULL, NULL}, +{"Enable", &DMREAD, DMT_BOOL, get_br_port_enable, NULL, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_br_port_status, NULL, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_br_port_name, NULL, NULL, NULL}, +{"LowerLayers", &DMWRITE, DMT_STRING, get_port_lower_layer, set_port_lower_layer, NULL, NULL}, +{"ManagementPort", &DMREAD, DMT_STRING, get_br_port_management, NULL, NULL, NULL}, +{0} +}; + +/*** Bridging.Bridge.{i}.Port.{i}.Stats. ***/ +DMLEAF tBridgePortStatParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification, linker*/ +{"BytesSent", &DMREAD, DMT_UNINT, get_br_port_stats_tx_bytes, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_br_port_stats_rx_bytes, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_br_port_stats_tx_packets, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_br_port_stats_rx_packets, NULL, NULL, NULL}, +{0} +}; + +/*** Bridging.Bridge.{i}.VLANPort.{i}. ***/ +DMLEAF tBridgeVlanPortParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMREAD, DMT_STRING, get_br_vlan_alias, NULL, NULL, NULL}, +{"Enable", &DMREAD, DMT_BOOL, get_br_vlan_enable, NULL, NULL, NULL}, +{"VLAN", &DMREAD, DMT_STRING, get_vlan_port_vlan_ref, NULL, NULL, NULL}, +{"Port", &DMWRITE, DMT_STRING, get_vlan_port_port_ref, set_vlan_port_port_ref, NULL, NULL}, +{0} +}; + /************************************************************************** -* INIT +* LINKER ***************************************************************************/ -inline int init_bridging_args(struct dmctx *ctx, struct uci_section *s, char *key) -{ - struct bridging_args *args = &cur_bridging_args; - ctx->args = (void *)args; - args->bridge_sec = s; - args->br_key = key; +int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if(((struct bridging_port_args *)data)->bridge_port_sec) { + dmasprintf(linker,"%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname); + return 0; + } + *linker = ""; return 0; } -inline int init_bridging_port_args(struct dmctx *ctx, struct uci_section *s, bool vlan, char *ifname) +int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if(((struct bridging_vlan_args *)data)->vlan_port) { + dmasprintf(linker,"vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst); + return 0; + } + *linker = ""; + return 0; +} +/************************************************************************** +* INIT +***************************************************************************/ +inline int init_bridging_args(struct bridging_args *args, struct uci_section *s, char *last_instance, char *ifname, char *br_instance) +{ + args->bridge_sec = s; + args->br_key = last_instance; + args->ifname = ifname; + args->br_inst = br_instance; + return 0; +} + +inline int init_bridging_port_args(struct bridging_port_args *args, struct uci_section *s, struct uci_section *bs, bool vlan, char *ifname) { - struct bridging_port_args *args = &cur_bridging_port_args; - ctx->args = (void *)args; args->bridge_port_sec = s; + args->bridge_sec = bs; args->vlan = vlan; args->ifname = ifname; return 0; } -inline int init_bridging_vlan_args(struct dmctx *ctx, struct uci_section *s, char *vlan_port, char *br_inst) +inline int init_bridging_vlan_args(struct bridging_vlan_args *args, struct uci_section *s, struct uci_section *bs, char *vlan_port, char *br_inst) { - struct bridging_vlan_args *args = &cur_bridging_vlan_args; - ctx->args = (void *)args; args->bridge_vlan_sec = s; + args->bridge_sec = bs; args->vlan_port = vlan_port; args->br_inst = br_inst; return 0; @@ -322,21 +412,21 @@ int update_port_parameters(char *linker, char *br_key, char *br_pt_inst, char *m *SET & GET BRIDGING PARAMETERS ***************************************************************************/ -int get_br_enable(char *refparam, struct dmctx *ctx, char **value) +int get_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *br_name; - dmastrcat(&br_name, "br-", section_name(cur_bridging_args.bridge_sec)); + dmastrcat(&br_name, "br-", section_name(((struct bridging_args *)data)->bridge_sec)); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", br_name, String}}, 1, &res); DM_ASSERT(res, *value = "false"); *value = dmjson_get_value(res, 1, "up"); return 0; } -int get_br_status(char *refparam, struct dmctx *ctx, char **value) +int get_br_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(cur_bridging_args.bridge_sec), String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1, &res); DM_ASSERT(res, *value = "Disabled"); *value = dmjson_get_value(res, 1, "up"); if(strcmp(*value,"true") == 0) @@ -344,7 +434,7 @@ int get_br_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_br_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; int error = string_to_bool(value, &b); @@ -355,39 +445,38 @@ int set_br_enable(char *refparam, struct dmctx *ctx, int action, char *value) return 0; case VALUESET: if (b) { - dmubus_call_set("network.interface", "up", UBUS_ARGS{{"interface", section_name(cur_bridging_args.bridge_sec), String}}, 1); + dmubus_call_set("network.interface", "up", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1); } else { - dmubus_call_set("network.interface", "down", UBUS_ARGS{{"interface", section_name(cur_bridging_args.bridge_sec), String}}, 1); + dmubus_call_set("network.interface", "down", UBUS_ARGS{{"interface", section_name(((struct bridging_args *)data)->bridge_sec), String}}, 1); } return 0; } return 0; } -int get_br_associated_interfaces(char *refparam, struct dmctx *ctx, char **value) +int get_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct args_layer2 *args = (struct args_layer2 *)ctx->args; - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", value); + dmuci_get_value_by_section_string(((struct bridging_args *)data)->bridge_sec, "ifname", value); return 0; } -int set_br_associated_interfaces(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", value); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", value); return 0; } return 0; } -int get_br_port_status(char *refparam, struct dmctx *ctx, char **value) +int get_br_port_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "ifname", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", value); dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", *value, String}}, 1, &res); DM_ASSERT(res, *value = "Down"); *value = dmjson_get_value(res, 1, "up"); @@ -396,19 +485,19 @@ int get_br_port_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_br_port_name(char *refparam, struct dmctx *ctx, char **value) +int get_br_port_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "name", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "name", value); return 0; } -int get_br_port_management(char *refparam,struct dmctx *ctx, char **value) +int get_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "mg_port", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", value); return 0; } -int get_br_port_enable(char *refparam,struct dmctx *ctx, char **value) +int get_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "true"; return 0; @@ -418,57 +507,54 @@ int get_br_port_enable(char *refparam,struct dmctx *ctx, char **value) /************************************************************************** * GET STAT ***************************************************************************/ -int get_br_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_br_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "ifname", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", value); dmubus_call("network.device", "status", UBUS_ARGS{{"name", *value, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "tx_bytes"); return 0; } -int get_br_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_br_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "ifname", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", value); dmubus_call("network.device", "status", UBUS_ARGS{{"name", *value, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "rx_bytes"); return 0; } -int get_br_port_stats_tx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_br_port_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "ifname", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", value); dmubus_call("network.device", "status", UBUS_ARGS{{"name", *value, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "tx_packets"); return 0; } -int get_br_port_stats_rx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_br_port_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - struct ldethargs *ethargs = (struct ldethargs *)ctx->args; - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "ifname", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", value); dmubus_call("network.device", "status", UBUS_ARGS{{"name", *value, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "rx_packets"); return 0; } -int get_br_vlan_enable(char *refparam,struct dmctx *ctx, char **value) +int get_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "false"; char *tmp; - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "penable", &tmp); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "penable", &tmp); if (tmp[0] == '0' || tmp[0] == '\0') *value = "false"; else if (tmp[0] == '1') @@ -476,7 +562,7 @@ int get_br_vlan_enable(char *refparam,struct dmctx *ctx, char **value) return 0; } -int set_br_vlan_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *vlan_ifname, *br_ifname, *vid, *p; @@ -490,17 +576,17 @@ int set_br_vlan_enable(char *refparam, struct dmctx *ctx, int action, char *valu case VALUESET: string_to_bool(value, &b); if (b) - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "penable", "1"); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "penable", "1"); else { - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "penable", "0"); - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "bridge_port_instance", ""); - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "bridge_port_alias", ""); - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "br_port_linker", ""); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "penable", "0"); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "bridge_port_instance", ""); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "bridge_port_alias", ""); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", ""); } - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "ifname", &vlan_ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", &vlan_ifname); if (vlan_ifname[0] == '\0') return 0; - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &br_ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", &br_ifname); if (b) { //add vlan ifname to br ifname list p = new_ifname; @@ -510,47 +596,47 @@ int set_br_vlan_enable(char *refparam, struct dmctx *ctx, int action, char *valu } dmstrappendstr(p, vlan_ifname); dmstrappendend(p); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", new_ifname); - sprintf(pr_linker,"%s+%s", section_name(cur_bridging_vlan_args.bridge_vlan_sec), vlan_ifname); - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "br_port_linker", pr_linker); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", new_ifname); + sprintf(pr_linker,"%s+%s", section_name(((struct bridging_vlan_args *)data)->bridge_vlan_sec), vlan_ifname); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", pr_linker); } else { //delete vlan ifname from br ifname list remove_interface_from_ifname(vlan_ifname, br_ifname, new_ifname); //remove_vid_interfaces_from_ifname(vid, br_ifname, new_ifname); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", new_ifname); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", new_ifname); } return 0; } return 0; } -int get_br_vlan_name(char *refparam,struct dmctx *ctx, char **value) +int get_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0"; - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "name", value); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "name", value); return 0; } -int set_br_vlan_name(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "name", value); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "name", value); return 0; } return 0; } -int get_br_vlan_vid(char *refparam,struct dmctx *ctx, char **value) +int get_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0"; - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "vlan8021q", value); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021q", value); return 0; } -int set_br_vlan_vid(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *ifname, *p, *vifname, *linker, *n_ifname; char buf[256]; @@ -560,15 +646,15 @@ int set_br_vlan_vid(char *refparam, struct dmctx *ctx, int action, char *value) case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "vlan8021q", value); - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "ifname", &vifname); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021q", value); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", &vifname); if (vifname[0] != '\0') { strncpy(tmp, vifname, 5); tmp[5] = '\0'; strcat(tmp, value);// concat new vid - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "ifname", tmp); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", tmp); //update br ifname - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", &ifname); remove_interface_from_ifname(vifname, ifname, buf); p = buf; if (buf[0] != '\0') { @@ -577,27 +663,27 @@ int set_br_vlan_vid(char *refparam, struct dmctx *ctx, int action, char *value) } dmstrappendstr(p, tmp); dmstrappendend(p); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", buf); - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "br_port_linker", &linker); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", buf); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", &linker); strcpy(buf,linker); p = strchr(buf, '+') + 1; dmstrappendstr(p, tmp); dmstrappendend(p); - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "br_port_linker", buf); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", buf); } return 0; } return 0; } -int get_br_vlan_priority(char *refparam,struct dmctx *ctx, char **value) +int get_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0"; - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "vlan8021p", value); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021p", value); return 0; } -int set_br_vlan_priority(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *ifname, *p, *vifname, *linker, *n_ifname; char buf[256]; @@ -607,7 +693,7 @@ int set_br_vlan_priority(char *refparam, struct dmctx *ctx, int action, char *va case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "vlan8021p", value); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021p", value); return 0; } return 0; @@ -616,55 +702,55 @@ int set_br_vlan_priority(char *refparam, struct dmctx *ctx, int action, char *va * GET SET ALIAS /*************************************************************/ -int get_br_alias(char *refparam, struct dmctx *ctx, char **value) +int get_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "bridge_alias", value); + dmuci_get_value_by_section_string(((struct bridging_args *)data)->bridge_sec, "bridge_alias", value); return 0; } -int set_br_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "bridge_alias", value); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "bridge_alias", value); return 0; } return 0; } -int get_br_port_alias(char *refparam, struct dmctx *ctx, char **value) +int get_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "bridge_port_alias", value); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_port_alias", value); return 0; } -int set_br_port_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_bridging_port_args.bridge_port_sec, "bridge_port_alias", value); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_port_alias", value); return 0; } return 0; } -int get_br_vlan_alias(char *refparam, struct dmctx *ctx, char **value) +int get_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "bridge_vlan_alias", value); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "bridge_vlan_alias", value); return 0; } -int set_br_vlan_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "bridge_vlan_alias", value); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "bridge_vlan_alias", value); return 0; } return 0; @@ -673,7 +759,7 @@ int set_br_vlan_alias(char *refparam, struct dmctx *ctx, int action, char *value * ADD DELETE OBJECT /*************************************************************/ -int add_bridge(struct dmctx *ctx, char **instance) +int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance) { char *last_inst; char bridge_name[16], ib[8]; @@ -692,59 +778,64 @@ int add_bridge(struct dmctx *ctx, char **instance) return 0; } -int delete_bridge(struct dmctx *ctx) +int delete_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL, *prev_s = NULL; - - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "type", ""); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "bridge_instance", ""); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ip_int_instance", ""); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ipv4_instance", ""); - uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", cur_bridging_args.br_key, s) { - if (prev_s) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - prev_s = s; - } - if (prev_s) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - reset_br_port( cur_bridging_args.br_key); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", ""); - return 0; -} - -int delete_bridge_all(struct dmctx *ctx) -{ - struct uci_section *bridge_s, *vlan_s, *prev_s = NULL; + struct uci_section *bridge_s, *vlan_s; char *bridgekey = NULL; - uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { - dmuci_set_value_by_section(bridge_s, "type", ""); - dmuci_set_value_by_section(bridge_s, "bridge_instance", ""); + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "type", ""); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "bridge_instance", ""); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ip_int_instance", ""); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ipv4_instance", ""); + uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", ((struct bridging_args *)data)->br_key, s) { + if (prev_s) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + prev_s = s; + } + if (prev_s) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + reset_br_port( ((struct bridging_args *)data)->br_key); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", ""); + break; + case DEL_ALL: + uci_foreach_option_eq("network", "interface", "type", "bridge", bridge_s) { + dmuci_set_value_by_section(bridge_s, "type", ""); + dmuci_set_value_by_section(bridge_s, "bridge_instance", ""); + dmuci_set_value_by_section(bridge_s, "ip_int_instance", ""); + dmuci_set_value_by_section(bridge_s, "ipv4_instance", ""); + dmuci_get_value_by_section_string(bridge_s, "bridge_instance", &bridgekey); + uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", bridgekey, s) { + if (prev_s) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + prev_s = s; + } + if (prev_s) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + reset_br_port(bridgekey); + dmuci_set_value_by_section(bridge_s, "ifname", ""); + } + + break; } - uci_foreach_sections("layer2_interface_vlan", "vlan_interface", vlan_s) { - if(prev_s != NULL && bridgekey[0] != '\0') - dmuci_delete_by_section(prev_s, NULL, NULL); - prev_s = vlan_s; - dmuci_get_value_by_section_string(vlan_s, "bridge_key", &bridgekey); - } - if(prev_s != NULL && bridgekey[0] != '\0') - dmuci_delete_by_section(prev_s, NULL, NULL); return 0; } -int add_br_vlan(struct dmctx *ctx, char **instance) +int add_br_vlan(char *refparam, struct dmctx *ctx, void *data, char **instance) { char *value, *last_instance, *ifname; struct uci_section *vlan_s; char buf[16]; char *v_name = buf; - last_instance = get_last_instance_lev2("layer2_interface_vlan", "vlan_interface", "bridge_vlan_instance", "bridge_key", cur_bridging_args.br_key); + last_instance = get_last_instance_lev2("layer2_interface_vlan", "vlan_interface", "bridge_vlan_instance", "bridge_key", ((struct bridging_args *)data)->br_key); dmuci_add_section("layer2_interface_vlan", "vlan_interface", &vlan_s, &value); - dmuci_set_value_by_section(vlan_s, "bridge_key", cur_bridging_args.br_key); + dmuci_set_value_by_section(vlan_s, "bridge_key", ((struct bridging_args *)data)->br_key); *instance = update_instance(vlan_s, last_instance, "bridge_vlan_instance"); dmstrappendstr(v_name, "vlan_"); - dmstrappendstr(v_name, cur_bridging_args.br_key); + dmstrappendstr(v_name, ((struct bridging_args *)data)->br_key); dmstrappendchr(v_name, '.'); dmstrappendstr(v_name, *instance); dmstrappendend(v_name); @@ -753,99 +844,96 @@ int add_br_vlan(struct dmctx *ctx, char **instance) return 0; } -int delete_br_vlan(struct dmctx *ctx) +int delete_br_vlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { char *vid, *ifname; char new_ifname[128]; - - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &ifname); - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "vlan8021q", &vid); - if(ifname[0] != '\0' && vid[0] != '\0'){ - remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", new_ifname); - } - dmuci_delete_by_section(cur_bridging_vlan_args.bridge_vlan_sec, NULL, NULL); - return 0; -} - -int delete_br_vlan_all(struct dmctx *ctx) -{ - char *vid, *ifname; struct uci_section *vlan_s, *prev_s = NULL ; - char new_ifname[128]; - uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "bridge_key", cur_bridging_args.br_key, vlan_s) { - dmuci_get_value_by_section_string(vlan_s, "vlan8021q", &vid); - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &ifname); + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", &ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021q", &vid); if(ifname[0] != '\0' && vid[0] != '\0'){ remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", new_ifname); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", new_ifname); + } + dmuci_delete_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "bridge_key", ((struct bridging_args *)data)->br_key, vlan_s) { + dmuci_get_value_by_section_string(vlan_s, "vlan8021q", &vid); + dmuci_get_value_by_section_string(((struct bridging_args *)data)->bridge_sec, "ifname", &ifname); + if(ifname[0] != '\0' && vid[0] != '\0'){ + remove_vid_interfaces_from_ifname(vid, ifname, new_ifname); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", new_ifname); + } + if (prev_s != NULL) + dmuci_delete_by_section(prev_s, NULL, NULL); + prev_s = vlan_s; } if (prev_s != NULL) dmuci_delete_by_section(prev_s, NULL, NULL); - prev_s = vlan_s; + break; } - if (prev_s != NULL) - dmuci_delete_by_section(prev_s, NULL, NULL); return 0; } -int add_br_port(struct dmctx *ctx, char **instance) +int add_br_port(char *refparam, struct dmctx *ctx, void *data, char **instance) { char *value; struct uci_section *br_port_s; char buf[16]; - int m = get_br_port_last_inst(cur_bridging_args.br_key); + int m = get_br_port_last_inst(((struct bridging_args *)data)->br_key); dmasprintf(instance, "%d", m+1); DMUCI_ADD_SECTION(icwmpd, "dmmap", "bridge_port", &br_port_s, &value); - dmuci_set_value_by_section(br_port_s, "bridge_key", cur_bridging_args.br_key); + dmuci_set_value_by_section(br_port_s, "bridge_key", ((struct bridging_args *)data)->br_key); dmuci_set_value_by_section(br_port_s, "bridge_port_instance", *instance); dmuci_set_value_by_section(br_port_s, "mg_port", "false"); return 0; } -int delete_br_port(struct dmctx *ctx) +int delete_br_port(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { char *iface, *ifname, *linker; char new_ifname[128]; struct uci_section *vlan_s; - - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &ifname); - if(ifname[0] != '\0'){ - remove_interface_from_ifname(cur_bridging_port_args.ifname, ifname, new_ifname); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", new_ifname); - dmuci_set_value_by_section(cur_bridging_port_args.bridge_port_sec, "bridge_port_instance", ""); - dmuci_set_value_by_section(cur_bridging_port_args.bridge_port_sec, "bridge_port_alias", ""); - dmuci_set_value_by_section(cur_bridging_port_args.bridge_port_sec, "bridge_key", ""); - dmuci_set_value_by_section(cur_bridging_port_args.bridge_port_sec, "penable", "0"); - return 0; - } - dmasprintf(&linker, "%s+%s", section_name(cur_bridging_port_args.bridge_port_sec), cur_bridging_port_args.ifname); - uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "br_port_linker", linker, vlan_s) { - dmuci_set_value_by_section(vlan_s, "br_port_linker", ""); - } - DMUCI_DELETE_BY_SECTION(icwmpd, cur_bridging_port_args.bridge_port_sec, NULL, NULL);//del port from dmmap - dmfree(linker); - return 0; -} - - -int delete_br_port_all(struct dmctx *ctx) -{ struct uci_section *s = NULL, *prev_s = NULL; - uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", cur_bridging_args.br_key, s) { + + switch (del_action) { + case DEL_INST: + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); + if(ifname[0] != '\0'){ + remove_interface_from_ifname(((struct bridging_port_args *)data)->ifname, ifname, new_ifname); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_sec, "ifname", new_ifname); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_port_instance", ""); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_port_alias", ""); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_key", ""); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_port_sec, "penable", "0"); + return 0; + } + dmasprintf(&linker, "%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname); + uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "br_port_linker", linker, vlan_s) { + dmuci_set_value_by_section(vlan_s, "br_port_linker", ""); + } + DMUCI_DELETE_BY_SECTION(icwmpd, ((struct bridging_port_args *)data)->bridge_port_sec, NULL, NULL);//del port from dmmap + dmfree(linker); + break; + case DEL_ALL: + uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", ((struct bridging_args *)data)->br_key, s) { + if (prev_s) + DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); + prev_s = s; + } if (prev_s) DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - prev_s = s; + reset_br_port(((struct bridging_args *)data)->br_key); + dmuci_set_value_by_section(((struct bridging_args *)data)->bridge_sec, "ifname", ""); // TO CHECK + break; } - if (prev_s) - DMUCI_DELETE_BY_SECTION(icwmpd, prev_s, NULL, NULL); - reset_br_port(cur_bridging_args.br_key); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", ""); // TO CHECK return 0; } - /************************************************************* * LOWER LAYER /*************************************************************/ @@ -889,7 +977,7 @@ int check_port_with_ifname (char * ifname, struct uci_section **ss) return 0; } -int get_port_lower_layer(char *refparam, struct dmctx *ctx, char **value) +int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker = ""; char *mg_port, *pch, *spch, *ifname, *ifname_dup, *p; @@ -898,15 +986,15 @@ int get_port_lower_layer(char *refparam, struct dmctx *ctx, char **value) struct uci_section *s = NULL; char lbuf[512]; - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "mg_port", &mg_port); - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &ifname); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", &mg_port); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); if (ifname[0] != '\0' && strcmp(mg_port, "true") == 0) { ifname_dup = dmstrdup(ifname); p = lbuf; for (pch = strtok_r(ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { check_port_with_ifname(pch, &s); sprintf(plinker, "%s+%s", section_name(s), pch); - adm_entry_get_linker_param(DMROOT"Bridging.Bridge.", plinker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", DMROOT, dm_delim, dm_delim, dm_delim), plinker, value); if (*value == NULL) *value = ""; dmstrappendstr(p, *value); @@ -917,28 +1005,28 @@ int get_port_lower_layer(char *refparam, struct dmctx *ctx, char **value) *value = dmstrdup(lbuf); return 0; } else { - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "ifname", &linker); - if(cur_bridging_port_args.vlan) { + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "ifname", &linker); + if(((struct bridging_port_args *)data)->vlan) { strncpy(buf, linker, 5); buf[5] = '\0'; strcat(buf, "1"); linker = buf; } } - adm_entry_get_linker_param(DMROOT"Ethernet.Interface.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) - adm_entry_get_linker_param(DMROOT"WiFi.SSID.", linker, value); + adm_entry_get_linker_param(ctx,dm_print_path("%s%cWiFi%cSSID%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) - adm_entry_get_linker_param(DMROOT"ATM.Link.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cATM%cLink%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) - adm_entry_get_linker_param(DMROOT"PTM.Link.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPTM%cLink%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) *value = ""; return 0; } -int set_port_lower_layer(char *refparam, struct dmctx *ctx, int action, char *value) +int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker, *iface, *ifname, *p, *br_key, *br_pt_inst = "", *mg_port = "false", *br_port_ifname, *vid = NULL; char new_ifname[256]; @@ -947,30 +1035,30 @@ int set_port_lower_layer(char *refparam, struct dmctx *ctx, int action, char *va struct uci_section *s; switch (action) { case VALUECHECK: - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "mg_port", &mg_port); - adm_entry_get_linker_value(value, &linker); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", &mg_port); + adm_entry_get_linker_value(ctx, value, &linker); if (strcmp(mg_port, "false") && linker && check_ifname_exist_in_br_ifname_list(linker)) return FAULT_9001; return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); + adm_entry_get_linker_value(ctx, value, &linker); //check ifname(linker) doesn't exit in bridges if (linker && !check_ifname_exist_in_br_ifname_list(linker)) { //save param of current port and copy it to new port - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "bridge_key", &br_key); - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "bridge_port_instance", &br_pt_inst); - dmuci_get_value_by_section_string(cur_bridging_port_args.bridge_port_sec, "mg_port", &mg_port); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_key", &br_key); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "bridge_port_instance", &br_pt_inst); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_port_sec, "mg_port", &mg_port); //remove old port (ifname) from bridge - if (cur_bridging_port_args.ifname[0] != 0 && strcmp(cur_bridging_port_args.ifname, linker) != 0) { - delete_br_port(ctx); + if (((struct bridging_port_args *)data)->ifname[0] != 0 && strcmp(((struct bridging_port_args *)data)->ifname, linker) != 0) { + delete_br_port(NULL, ctx, data, instance, DEL_INST); } // check if the current port is already linked with VLAN - sprintf(pr_linker,"%s+%s", section_name(cur_bridging_port_args.bridge_port_sec), cur_bridging_port_args.ifname); + sprintf(pr_linker,"%s+%s", section_name(((struct bridging_port_args *)data)->bridge_port_sec), ((struct bridging_port_args *)data)->ifname); uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "br_port_linker", pr_linker, s) { dmuci_get_value_by_section_string(s, "vlan8021q", &vid); break; } - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &ifname); + dmuci_get_value_by_section_string(((struct bridging_port_args *)data)->bridge_sec, "ifname", &ifname); p = new_ifname; if (ifname[0] != '\0') { dmstrappendstr(p, ifname); @@ -993,39 +1081,39 @@ int set_port_lower_layer(char *refparam, struct dmctx *ctx, int action, char *va dmstrappendstr(p, linker); dmstrappendend(p); } - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", new_ifname); + dmuci_set_value_by_section(((struct bridging_port_args *)data)->bridge_sec, "ifname", new_ifname); //remove old br_port param to the new one update_port_parameters(linker, br_key, br_pt_inst, mg_port); - if(cur_bridging_port_args.ifname[0] == '\0') - DMUCI_DELETE_BY_SECTION(icwmpd, cur_bridging_port_args.bridge_port_sec, NULL, NULL);// delete dmmap section after remove br_port_instance to adequate config + if(((struct bridging_port_args *)data)->ifname[0] == '\0') + DMUCI_DELETE_BY_SECTION(icwmpd,((struct bridging_port_args *)data)->bridge_port_sec, NULL, NULL);// delete dmmap section after remove br_port_instance to adequate config } return 0; } } -int get_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, char **value) +int get_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char linker[8]; char *name; - dmasprintf(&name,DMROOT"Bridging.Bridge.%s.",cur_bridging_args.br_key); - sprintf(linker,"vlan%s_%s", cur_bridging_vlan_args.vlan_port, cur_bridging_args.br_key); - adm_entry_get_linker_param(DMROOT"Bridging.Bridge.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + dmasprintf(&name,"%s%cBridging%cBridge%c%s%c", DMROOT, dm_delim, dm_delim, dm_delim, ((struct bridging_vlan_args *)data)->br_inst, dm_delim); + sprintf(linker,"vlan%s_%s", ((struct bridging_vlan_args *)data)->vlan_port, ((struct bridging_vlan_args *)data)->br_inst); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; return 0; } -int get_vlan_port_port_ref(char *refparam, struct dmctx *ctx, char **value) +int get_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "br_port_linker", &linker); - adm_entry_get_linker_param(DMROOT"Bridging.Bridge.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", &linker); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; return 0; } -int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, int action, char *value) +int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker = NULL, *vid, *enable, *vifname, tmp[8], *pch, *p, *br_ifname; char new_ifname[16]; @@ -1034,14 +1122,14 @@ int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, int action, char * case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); + adm_entry_get_linker_value(ctx, value, &linker); if (!linker) { - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "br_port_linker", ""); - set_br_vlan_enable(refparam, ctx, action, "false"); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", ""); + set_br_vlan_enable(refparam, ctx, data, instance, "false", action); return 0; } - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "br_port_linker", linker); - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "vlan8021q", &vid); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "br_port_linker", linker); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "vlan8021q", &vid); pch = strchr(linker, '+') + 1; if (pch[0] == '\0') { dmfree(linker); @@ -1051,24 +1139,24 @@ int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, int action, char * if (strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, wan_baseifname)) { strncpy(tmp, pch, 4); tmp[4] ='\0'; - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "baseifname", tmp); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "baseifname", tmp); } } else { if (strstr(pch, "atm") || strstr(pch, "ptm") || strstr(pch, wan_baseifname)) { p = new_ifname; strncpy(tmp, pch, 4); tmp[4] ='\0'; - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "baseifname", tmp); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "baseifname", tmp); dmstrappendstr(p, tmp); dmstrappendchr(p, '.'); dmstrappendstr(p, vid); dmstrappendend(p); - dmuci_set_value_by_section(cur_bridging_vlan_args.bridge_vlan_sec, "ifname", new_ifname); - dmuci_get_value_by_section_string(cur_bridging_vlan_args.bridge_vlan_sec, "penable", &enable);///TO CHECK + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "ifname", new_ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_vlan_sec, "penable", &enable);///TO CHECK // add to bridge ifname if enable = 1 if (enable[0] == '1') { vifname = dmstrdup(new_ifname); - dmuci_get_value_by_section_string(cur_bridging_args.bridge_sec, "ifname", &br_ifname); + dmuci_get_value_by_section_string(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", &br_ifname); p = new_ifname; if (br_ifname[0] != '\0') { dmstrappendstr(p, br_ifname); @@ -1076,7 +1164,7 @@ int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, int action, char * } dmstrappendstr(p, vifname); dmstrappendend(p); - dmuci_set_value_by_section(cur_bridging_args.bridge_sec, "ifname", new_ifname); + dmuci_set_value_by_section(((struct bridging_vlan_args *)data)->bridge_sec, "ifname", new_ifname); dmfree(vifname); } } @@ -1089,195 +1177,163 @@ int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, int action, char * /************************************************************* * ENTRY METHOD /*************************************************************/ -int entry_method_root_bridging(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Bridging.") { - DMOBJECT(DMROOT"Bridging.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"Bridging.Bridge.", ctx, "1", 0, add_bridge, delete_bridge_all, NULL); - SUBENTRY(entry_bridging_sub, ctx); - return 0; - } - return FAULT_9005; -} -inline int entry_bridging_sub(struct dmctx *ctx) + +int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *br_s = NULL; char *br_inst = NULL, *br_inst_last = NULL, *ifname; + struct bridging_args curr_bridging_args = {0}; #ifdef EX400 - dmuci_get_option_value_string("layer2_interface_ethernet", "WAN", "baseifname", &wan_baseifname); + dmuci_get_option_value_string("ports", "WAN", "ifname", &wan_baseifname); #else dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", &wan_baseifname); #endif uci_foreach_option_eq("network", "interface", "type", "bridge", br_s) { - br_inst = handle_update_instance(1, ctx, &br_inst_last, update_instance_alias, 3, br_s, "bridge_instance", "bridge_alias"); - init_bridging_args(ctx, br_s, br_inst_last); + br_inst = handle_update_instance(1, dmctx, &br_inst_last, update_instance_alias, 3, br_s, "bridge_instance", "bridge_alias"); dmuci_get_value_by_section_string(br_s, "ifname", &ifname); - SUBENTRY(entry_bridge_instance, ctx, br_inst, br_inst_last); - SUBENTRY(entry_bridge_vlan_instance_sub, ctx, br_inst, br_inst_last); - SUBENTRY(entry_bridge_port_sub, ctx, ifname, br_inst, br_inst_last); + init_bridging_args(&curr_bridging_args, br_s, br_inst_last, ifname, br_inst); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_args, br_inst) == DM_STOP) + break; } return 0; } -inline int entry_bridge_instance(struct dmctx *ctx, char *dev) -{ - IF_MATCH(ctx, DMROOT"Bridging.Bridge.%s.", dev) { - DMOBJECT(DMROOT"Bridging.Bridge.%s.", ctx, "1", NULL, NULL, delete_bridge, NULL, dev); - DMPARAM("Alias", ctx, "1", get_br_alias, set_br_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_br_status, set_br_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_br_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_COM_AssociatedInterfaces", ctx, "1", get_br_associated_interfaces, set_br_associated_interfaces, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Bridging.Bridge.%s.VLAN.", ctx, "1", NULL, add_br_vlan, delete_br_vlan_all, NULL, dev); - DMOBJECT(DMROOT"Bridging.Bridge.%s.Port.", ctx, "1", NULL, add_br_port, delete_br_port_all, NULL, dev); // TODO ADD DEL OBJ - DMOBJECT(DMROOT"Bridging.Bridge.%s.VLANPort.", ctx, "0", NULL, NULL, NULL, NULL, dev); - return 0; - } - return FAULT_9005; -} - -inline int entry_bridge_port_sub(struct dmctx *ctx, char *ifname, char *idev, char *last_br_inst) +int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *eth_s = NULL, *atm_s = NULL, *ptm_s = NULL, *wl_s = NULL, *vlan_s = NULL, *w_eth_s = NULL, *m_port = NULL, *new_port = NULL; char *port = NULL, *port_last = NULL, *vlan = NULL, *vlan_last = NULL; - char *ifname_dup, *pch, *spch, *vid; + char *ifname_dup = NULL, *pch, *spch, *vid; bool find_max = true; + struct bridging_port_args curr_bridging_port_args = {0}; - update_section_list(DMMAP,"bridge_port", "bridge_key", 1, last_br_inst, "mg_port", "true", "bridge_port_instance", "1"); - uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", last_br_inst, new_port) { - init_bridging_port_args(ctx, new_port, false, ""); - port = handle_update_instance(2, ctx, &port_last, br_port_update_instance_alias_icwmpd, 5, new_port, "bridge_port_instance", "bridge_port_alias", &find_max, last_br_inst); - SUBENTRY(entry_bridge_port_instance, ctx, idev, port); + update_section_list(DMMAP,"bridge_port", "bridge_key", 1, ((struct bridging_args *)prev_data)->br_key, "mg_port", "true", "bridge_port_instance", "1"); + uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", ((struct bridging_args *)prev_data)->br_key, new_port) { + init_bridging_port_args(&curr_bridging_port_args, new_port, ((struct bridging_args *)prev_data)->bridge_sec, false, ""); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias_icwmpd, 5, new_port, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; } - if (ifname[0] == '\0') + if (((struct bridging_args *)prev_data)->ifname[0] == '\0') return 0; - ifname_dup = dmstrdup(ifname); + ifname_dup = dmstrdup(((struct bridging_args *)prev_data)->ifname); for (pch = strtok_r(ifname_dup, " ", &spch); pch != NULL; pch = strtok_r(NULL, " ", &spch)) { - uci_foreach_option_eq("ports", "ethport", "ifname", pch, eth_s) { - dmuci_set_value_by_section(eth_s, "bridge_key", last_br_inst); - dmuci_set_value_by_section(eth_s, "mg_port", "false"); - dmuci_set_value_by_section(eth_s, "penable", "1"); - init_bridging_port_args(ctx, eth_s, false, pch); - port = handle_update_instance(2, ctx, &port_last, br_port_update_instance_alias, 5, eth_s, "bridge_port_instance", "bridge_port_alias", &find_max, last_br_inst); - SUBENTRY(entry_bridge_port_instance, ctx, idev, port); - break; + bool found = false; + if(!found) { + uci_foreach_option_eq("ports", "ethport", "ifname", pch, eth_s) { + dmuci_set_value_by_section(eth_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); + dmuci_set_value_by_section(eth_s, "mg_port", "false"); + dmuci_set_value_by_section(eth_s, "penable", "1"); + init_bridging_port_args(&curr_bridging_port_args, eth_s, ((struct bridging_args *)prev_data)->bridge_sec, false, pch); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, eth_s, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + found = true ; + break; + } } #ifndef EX400 - uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "ifname", pch, atm_s) { - dmuci_set_value_by_section(atm_s, "bridge_key", last_br_inst); - dmuci_set_value_by_section(atm_s, "mg_port", "false"); - dmuci_set_value_by_section(atm_s, "penable", "1"); - init_bridging_port_args(ctx, atm_s, false, pch); - port = handle_update_instance(2, ctx, &port_last, br_port_update_instance_alias, 5, atm_s, "bridge_port_instance", "bridge_port_alias", &find_max, last_br_inst); - SUBENTRY(entry_bridge_port_instance, ctx, idev, port); - break; + if(!found) { + uci_foreach_option_eq("layer2_interface_adsl", "atm_bridge", "ifname", pch, atm_s) { + dmuci_set_value_by_section(atm_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); + dmuci_set_value_by_section(atm_s, "mg_port", "false"); + dmuci_set_value_by_section(atm_s, "penable", "1"); + init_bridging_port_args(&curr_bridging_port_args, atm_s, ((struct bridging_args *)prev_data)->bridge_sec, false, pch); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, atm_s, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + found = true ; + break; + } } - uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "ifname", pch, ptm_s) { - dmuci_set_value_by_section(ptm_s, "bridge_key", last_br_inst); - dmuci_set_value_by_section(ptm_s, "mg_port", "false"); - dmuci_set_value_by_section(ptm_s, "penable", "1"); - init_bridging_port_args(ctx, ptm_s, false, pch); - port = handle_update_instance(2, ctx, &port_last, br_port_update_instance_alias, 5, ptm_s, "bridge_port_instance", "bridge_port_alias", &find_max, last_br_inst); - SUBENTRY(entry_bridge_port_instance, ctx, idev, port); - break; + if(!found) { + uci_foreach_option_eq("layer2_interface_vdsl", "vdsl_interface", "ifname", pch, ptm_s) { + dmuci_set_value_by_section(ptm_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); + dmuci_set_value_by_section(ptm_s, "mg_port", "false"); + dmuci_set_value_by_section(ptm_s, "penable", "1"); + init_bridging_port_args(&curr_bridging_port_args, ptm_s, ((struct bridging_args *)prev_data)->bridge_sec, false, pch); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, ptm_s, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + found = true ; + break; + } } - uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "ifname", pch, w_eth_s) { + if(!found) { + uci_foreach_option_eq("layer2_interface_ethernet", "ethernet_interface", "ifname", pch, w_eth_s) { #else - uci_foreach_option_eq("network", "interface", "ifname", pch, w_eth_s) { + uci_foreach_option_eq("network", "interface", "ifname", pch, w_eth_s) { #endif - dmuci_set_value_by_section(w_eth_s, "bridge_key", last_br_inst); - dmuci_set_value_by_section(w_eth_s, "mg_port", "false"); - dmuci_set_value_by_section(w_eth_s, "penable", "1"); - init_bridging_port_args(ctx, w_eth_s, false, pch); - port = handle_update_instance(2, ctx, &port_last, br_port_update_instance_alias, 5, w_eth_s, "bridge_port_instance", "bridge_port_alias", &find_max, last_br_inst); - SUBENTRY(entry_bridge_port_instance, ctx, idev, port); - break; + dmuci_set_value_by_section(w_eth_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); + dmuci_set_value_by_section(w_eth_s, "mg_port", "false"); + dmuci_set_value_by_section(w_eth_s, "penable", "1"); + init_bridging_port_args(&curr_bridging_port_args, w_eth_s, ((struct bridging_args *)prev_data)->bridge_sec, false, pch); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, w_eth_s, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + found = true ; + break; + } } - uci_foreach_option_eq("wireless", "wifi-iface", "ifname", pch, wl_s) { - dmuci_set_value_by_section(wl_s, "bridge_key", last_br_inst); - dmuci_set_value_by_section(wl_s, "mg_port", "false"); - dmuci_set_value_by_section(wl_s, "penable", "1"); - init_bridging_port_args(ctx, wl_s, false, pch); - port = handle_update_instance(2, ctx, &port_last, br_port_update_instance_alias, 5, wl_s, "bridge_port_instance", "bridge_port_alias", &find_max, last_br_inst); - SUBENTRY(entry_bridge_port_instance, ctx, idev, port); - break; + if(!found) { + uci_foreach_option_eq("wireless", "wifi-iface", "ifname", pch, wl_s) { + dmuci_set_value_by_section(wl_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); + dmuci_set_value_by_section(wl_s, "mg_port", "false"); + dmuci_set_value_by_section(wl_s, "penable", "1"); + init_bridging_port_args(&curr_bridging_port_args, wl_s, ((struct bridging_args *)prev_data)->bridge_sec, false, pch); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, wl_s, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + found = true ; + break; + } } - uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "ifname", pch, vlan_s) { - dmuci_set_value_by_section(vlan_s, "bridge_key", last_br_inst); - dmuci_set_value_by_section(vlan_s, "mg_port", "false"); - dmuci_set_value_by_section(vlan_s, "penable", "1"); - init_bridging_port_args(ctx, vlan_s, true, pch); - port = handle_update_instance(2, ctx, &port_last, br_port_update_instance_alias, 5, vlan_s, "bridge_port_instance", "bridge_port_alias", &find_max, last_br_inst); - SUBENTRY(entry_bridge_port_instance, ctx, idev, port); - break; + if(!found) { + uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "ifname", pch, vlan_s) { + dmuci_set_value_by_section(vlan_s, "bridge_key", ((struct bridging_args *)prev_data)->br_key); + dmuci_set_value_by_section(vlan_s, "mg_port", "false"); + dmuci_set_value_by_section(vlan_s, "penable", "1"); + init_bridging_port_args(&curr_bridging_port_args, vlan_s, ((struct bridging_args *)prev_data)->bridge_sec, true, pch); + port = handle_update_instance(2, dmctx, &port_last, br_port_update_instance_alias, 5, vlan_s, "bridge_port_instance", "bridge_port_alias", &find_max, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_port_args, port) == DM_STOP) + goto end; + break; + } } } +end: dmfree(ifname_dup); return 0; } -inline int entry_bridge_vlan_instance_sub(struct dmctx *ctx, char *idev, char *last_br_inst) + +int browseBridgeVlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *vlan_s = NULL; char *vlan = NULL, *vlan_last = NULL; char *type, *ipv4 ; + struct bridging_vlan_args curr_bridging_vlan_args = {0}; - uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "bridge_key", last_br_inst, vlan_s) { - vlan = handle_update_instance(2, ctx, &vlan_last, update_instance_alias, 3, vlan_s, "bridge_vlan_instance", "bridge_vlan_alias"); - init_bridging_vlan_args(ctx, vlan_s, vlan_last, last_br_inst); - SUBENTRY(entry_bridge_vlan_instance, ctx, idev, vlan); - SUBENTRY(entry_bridge_vlan_port_instance, ctx, idev, vlan); + uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "bridge_key", ((struct bridging_args *)prev_data)->br_key, vlan_s) { + vlan = handle_update_instance(2, dmctx, &vlan_last, update_instance_alias, 3, vlan_s, "bridge_vlan_instance", "bridge_vlan_alias"); + init_bridging_vlan_args(&curr_bridging_vlan_args, vlan_s, ((struct bridging_args *)prev_data)->bridge_sec, vlan_last, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_vlan_args, vlan) == DM_STOP) + break; } return 0; } -inline int entry_bridge_port_instance(struct dmctx *ctx, char *br, char *port) +int browseBridgeVlanPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - IF_MATCH(ctx, DMROOT"Bridging.Bridge.%s.Port.%s.", br, port) { - char linker[32]; - sprintf(linker,"%s+%s", section_name(cur_bridging_port_args.bridge_port_sec), cur_bridging_port_args.ifname); - DMOBJECT(DMROOT"Bridging.Bridge.%s.Port.%s.", ctx, "1", NULL, NULL, delete_br_port, linker, br, port); - DMPARAM("Alias", ctx, "1", get_br_port_alias, set_br_port_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "0", get_br_port_enable, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_br_port_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_br_port_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LowerLayers", ctx, "1", get_port_lower_layer, set_port_lower_layer, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ManagementPort", ctx, "0", get_br_port_management, NULL, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Bridging.Bridge.%s.Port.%s.Stats.", ctx, "0", 1, NULL, NULL, NULL, br, port); - DMPARAM("BytesSent", ctx, "0", get_br_port_stats_tx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_br_port_stats_rx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_br_port_stats_tx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_br_port_stats_rx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} + struct uci_section *vlan_s = NULL; + char *vlan = NULL, *vlan_last = NULL; + char *type, *ipv4 ; + struct bridging_vlan_args curr_bridging_vlan_args = {0}; -inline int entry_bridge_vlan_instance(struct dmctx *ctx, char *br, char *vlan) -{ - IF_MATCH(ctx, DMROOT"Bridging.Bridge.%s.VLAN.%s.", br, vlan) { - char linker[64]; - sprintf(linker,"vlan%s_%s", cur_bridging_vlan_args.vlan_port, cur_bridging_vlan_args.br_inst); - DMOBJECT(DMROOT"Bridging.Bridge.%s.VLAN.%s.", ctx, "1", NULL, NULL, delete_br_vlan, linker, br, vlan); - DMPARAM("Alias", ctx, "1", get_br_vlan_alias, set_br_vlan_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_br_vlan_enable, set_br_vlan_enable, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "1", get_br_vlan_name, set_br_vlan_name, NULL, 0, 1, UNDEF, NULL); - DMPARAM("VLANID", ctx, "1", get_br_vlan_vid, set_br_vlan_vid, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_VLANPriority", ctx, "1", get_br_vlan_priority, set_br_vlan_priority, NULL, 0, 1, UNDEF, NULL); - return 0; + uci_foreach_option_eq("layer2_interface_vlan", "vlan_interface", "bridge_key", ((struct bridging_args *)prev_data)->br_key, vlan_s) { + vlan = handle_update_instance(2, dmctx, &vlan_last, update_instance_alias, 3, vlan_s, "bridge_vlan_instance", "bridge_vlan_alias"); + init_bridging_vlan_args(&curr_bridging_vlan_args, vlan_s, ((struct bridging_args *)prev_data)->bridge_sec, vlan_last, ((struct bridging_args *)prev_data)->br_key); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridging_vlan_args, vlan) == DM_STOP) + break; } - return FAULT_9005; -} - - -inline int entry_bridge_vlan_port_instance(struct dmctx *ctx, char *br, char *vlan_port) -{ - IF_MATCH(ctx, DMROOT"Bridging.Bridge.%s.VLANPort.%s.", br, vlan_port) { - DMOBJECT(DMROOT"Bridging.Bridge.%s.VLANPort.%s.", ctx, "0", NULL, NULL, NULL, NULL, br, vlan_port); - DMPARAM("Alias", ctx, "0", get_br_vlan_alias, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "0", get_br_vlan_enable, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("VLAN", ctx, "0", get_vlan_port_vlan_ref, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Port", ctx, "1", get_vlan_port_port_ref, set_vlan_port_port_ref, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; + return 0; } diff --git a/dm/dmtree/tr181/bridging.h b/dm/dmtree/tr181/bridging.h index 5f22be9..91cf4bd 100644 --- a/dm/dmtree/tr181/bridging.h +++ b/dm/dmtree/tr181/bridging.h @@ -16,11 +16,14 @@ struct bridging_args { struct uci_section *bridge_sec; char *br_key; + char *ifname; + char *br_inst; }; struct bridging_port_args { struct uci_section *bridge_port_sec; + struct uci_section *bridge_sec; bool vlan; char *ifname; }; @@ -28,12 +31,71 @@ struct bridging_port_args struct bridging_vlan_args { struct uci_section *bridge_vlan_sec; + struct uci_section *bridge_sec; char *vlan_port; char *br_inst; char *ifname; }; #define BUF_SIZE 7 -int entry_method_root_bridging(struct dmctx *ctx); +extern DMOBJ tBridgingObj[]; +extern DMOBJ tDridgingBridgeObj[]; +extern DMLEAF tDridgingBridgeParams[]; +extern DMLEAF tBridgeVlanParams[]; +extern DMLEAF tBridgePortParams[]; +extern DMLEAF tBridgeVlanPortParams[]; +extern DMOBJ tBridgePortObj[]; +extern DMLEAF tBridgePortStatParams[]; +int browseBridgeVlanPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseBridgeVlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_bridge(char *refparam, struct dmctx *ctx, void *data, char **instance); +int delete_bridge(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_br_vlan(char *refparam, struct dmctx *ctx, void *data, char **instance); +int delete_br_vlan(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_br_port(char *refparam, struct dmctx *ctx, void *data, char **instance); +int delete_br_port(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + + +int get_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_management(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_port_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vlan_port_vlan_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_br_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_associated_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_vlan_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_vlan_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_vlan_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_vlan_vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_vlan_priority(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_br_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_port_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_vlan_port_port_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int get_linker_br_port(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +int get_linker_br_vlan(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif diff --git a/dm/dmtree/tr181/dhcp.c b/dm/dmtree/tr181/dhcp.c index e8392c5..06f4379 100644 --- a/dm/dmtree/tr181/dhcp.c +++ b/dm/dmtree/tr181/dhcp.c @@ -17,43 +17,101 @@ #include "dmcwmp.h" #include "dmcommon.h" #include "dhcp.h" - #include "dmjson.h" #define DELIMITOR "," -struct dhcp_args cur_dhcp_args = {0}; -struct client_args cur_dhcp_client_args = {0}; -struct dhcp_static_args cur_dhcp_staticargs = {0}; +/*** DHCPv4. ***/ +DMOBJ tDhcpv4Obj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Server", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDhcpv4ServerObj, NULL, NULL}, +{0} +}; + +/*** DHCPv4.Server. ***/ +DMOBJ tDhcpv4ServerObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Pool", &DMWRITE, add_dhcp_server, delete_dhcp_server, NULL, browseDhcpInst, NULL, NULL, tDhcpServerPoolObj, tDhcpServerPoolParams, NULL}, +{0} +}; + + +/*** DHCPv4.Server.Pool.{i}. ***/ +DMOBJ tDhcpServerPoolObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"StaticAddress", &DMWRITE, add_dhcp_staticaddress, delete_dhcp_staticaddress, NULL, browseDhcpStaticInst, NULL, NULL, NULL, tDhcpServerPoolAddressParams, NULL}, +{"Client", &DMREAD, NULL, NULL, NULL, browseDhcpClientInst, NULL, NULL, NULL, tDhcpServerPoolClientParams, get_dhcp_client_linker}, +{0} +}; + +DMLEAF tDhcpServerPoolParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"DNSServers", &DMWRITE, DMT_STRING, get_dns_server, set_dns_server, NULL, NULL}, +{"X_INTENO_SE_DHCPServerConfigurable", &DMWRITE, DMT_BOOL, get_dhcp_configurable, set_dhcp_configurable, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_dhcp_enable, set_dhcp_enable, NULL, NULL}, +{"MinAddress", &DMWRITE, DMT_STRING, get_dhcp_interval_address_min, set_dhcp_address_min, NULL, NULL}, +{"MaxAddress", &DMWRITE, DMT_STRING,get_dhcp_interval_address_max, set_dhcp_address_max, NULL, NULL}, +{"ReservedAddresses", &DMWRITE, DMT_STRING, get_dhcp_reserved_addresses, set_dhcp_reserved_addresses, NULL, NULL}, +{"SubnetMask", &DMWRITE, DMT_STRING,get_dhcp_subnetmask, set_dhcp_subnetmask, NULL, NULL}, +{"IPRouters", &DMWRITE, DMT_STRING, get_dhcp_iprouters, set_dhcp_iprouters, NULL, NULL}, +{"LeaseTime", &DMWRITE, DMT_STRING, get_dhcp_leasetime, set_dhcp_leasetime, NULL, NULL}, +{"DomainName", &DMWRITE, DMT_STRING, get_dhcp_domainname, set_dhcp_domainname, NULL, NULL}, +{"Interface", &DMWRITE, DMT_STRING, get_dhcp_interface, set_dhcp_interface_linker_parameter, NULL, NULL}, +{0} +}; + +/*** DHCPv4.Server.Pool.{i}.StaticAddress.{i}. ***/ +DMLEAF tDhcpServerPoolAddressParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_dhcp_static_alias, set_dhcp_static_alias, NULL, NULL}, +{"Chaddr", &DMWRITE, DMT_STRING, get_dhcp_staticaddress_chaddr, set_dhcp_staticaddress_chaddr, NULL, NULL}, +{"Yiaddr", &DMWRITE, DMT_STRING, get_dhcp_staticaddress_yiaddr, set_dhcp_staticaddress_yiaddr, NULL, NULL}, +{0} +}; + +/*** DHCPv4.Server.Pool.{i}.Client.{i}. ***/ +DMLEAF tDhcpServerPoolClientParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Chaddr", &DMREAD, DMT_STRING, get_dhcp_client_chaddr, NULL, NULL, NULL}, +{0} +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +int get_dhcp_client_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if (((struct client_args *)data)->key) { + *linker = ((struct client_args *)data)->key; + return 0; + } else { + *linker = ""; + return 0; + } +} /************************************************************* * INIT /*************************************************************/ -inline int init_dhcp_args(struct dmctx *ctx, struct uci_section *s, char *interface) +inline int init_dhcp_args(struct dhcp_args *args, struct uci_section *s, char *interface) { - struct dhcp_args *args = &cur_dhcp_args; - ctx->args = (void *)args; args->interface = interface; args->dhcp_sec = s; return 0; } -inline int init_args_dhcp_host(struct dmctx *ctx, struct uci_section *s) +inline int init_args_dhcp_host(struct dhcp_static_args *args, struct uci_section *s) { - struct dhcp_static_args *args = &cur_dhcp_staticargs; - ctx->args = (void *)args; args->dhcpsection = s; return 0; } -inline int init_dhcp_client_args(struct dmctx *ctx, json_object *client) +inline int init_dhcp_client_args(struct client_args *args, json_object *client, char *key) { - struct client_args *args = &cur_dhcp_client_args; - ctx->args = (void *)args; args->client = client; + args->key = key; return 0; } /*******************ADD-DEL OBJECT*********************/ -int add_dhcp_server(struct dmctx *ctx, char **instancepara) +int add_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char *instance; @@ -68,86 +126,87 @@ int add_dhcp_server(struct dmctx *ctx, char **instancepara) return 0; } -int delete_dhcp_server(struct dmctx *ctx) -{ - dmuci_delete_by_section(cur_dhcp_args.dhcp_sec, NULL, NULL); - return 0; -} - -int delete_dhcp_server_all(struct dmctx *ctx) +int delete_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; char *lan_name; struct uci_section *s = NULL; struct uci_section *ss = NULL; - uci_foreach_sections("dhcp", "dhcp", s) { - if (found != 0) + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(((struct dhcp_args *)data)->dhcp_sec, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("dhcp", "dhcp", s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; + break; } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - return 0; + return 0; } -int add_dhcp_staticaddress(struct dmctx *ctx, char **instancepara) +int add_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *value; char *instance; struct uci_section *s = NULL; - instance = get_last_instance_lev2("dhcp", "host", "ldhcpinstance", "interface", cur_dhcp_args.interface); + instance = get_last_instance_lev2("dhcp", "host", "ldhcpinstance", "interface", ((struct dhcp_args *)data)->interface); dmuci_add_section("dhcp", "host", &s, &value); dmuci_set_value_by_section(s, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); - dmuci_set_value_by_section(s, "interface", cur_dhcp_args.interface); + dmuci_set_value_by_section(s, "interface", ((struct dhcp_args *)data)->interface); *instancepara = update_instance(s, instance, "ldhcpinstance"); return 0; } -int delete_dhcp_staticaddress_all(struct dmctx *ctx) +int delete_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; char *lan_name; struct uci_section *s = NULL; struct uci_section *ss = NULL; - - uci_foreach_option_eq("dhcp", "host", "interface", cur_dhcp_args.interface, s) { - if (found != 0) - dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; - } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); - return 0; -} - -int delete_dhcp_staticaddress(struct dmctx *ctx) -{ - struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)ctx->args; + struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)data; - dmuci_delete_by_section(dhcpargs->dhcpsection, NULL, NULL); + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(dhcpargs->dhcpsection, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_option_eq("dhcp", "host", "interface", ((struct dhcp_args *)data)->interface, s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) + dmuci_delete_by_section(ss, NULL, NULL); + break; + } return 0; } /************************************************************* * GET & SET PARAM /*************************************************************/ -int get_dns_server(char *refparam, struct dmctx *ctx, char **value) +int get_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; int len; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); if(res) { *value = dmjson_get_value_array_all(res, DELIMITOR, 1, "dns-server"); - } + } else *value = ""; if ((*value)[0] == '\0') { - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "dns", value); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "dns", value); *value = dmstrdup(*value); // MEM WILL BE FREED IN DMMEMCLEAN char *p = *value; while (*p) { @@ -160,7 +219,7 @@ int get_dns_server(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_dns_server(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *dup, *p; @@ -176,18 +235,18 @@ int set_dns_server(char *refparam, struct dmctx *ctx, int action, char *value) else p++; } - dmuci_set_value("network", cur_dhcp_args.interface, "dns", dup); + dmuci_set_value("network", ((struct dhcp_args *)data)->interface, "dns", dup); dmfree(dup); return 0; } return 0; } -int get_dhcp_configurable(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { *value = "1"; return 0; } @@ -195,7 +254,7 @@ int get_dhcp_configurable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_dhcp_configurable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; struct uci_section *s = NULL; @@ -207,29 +266,29 @@ int set_dhcp_configurable(char *refparam, struct dmctx *ctx, int action, char *v return 0; case VALUESET: string_to_bool(value, &b); - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { if (!b) { dmuci_delete_by_section(s, NULL, NULL); } break; } if (s == NULL && b) { - dmuci_set_value("dhcp",cur_dhcp_args.interface, NULL, "dhcp"); - dmuci_set_value("dhcp", cur_dhcp_args.interface, "interface", cur_dhcp_args.interface); - dmuci_set_value("dhcp", cur_dhcp_args.interface, "start", "100"); - dmuci_set_value("dhcp", cur_dhcp_args.interface, "limit", "150"); - dmuci_set_value("dhcp", cur_dhcp_args.interface, "leasetime", "12h"); + dmuci_set_value("dhcp",((struct dhcp_args *)data)->interface, NULL, "dhcp"); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "interface", ((struct dhcp_args *)data)->interface); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "start", "100"); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "limit", "150"); + dmuci_set_value("dhcp", ((struct dhcp_args *)data)->interface, "leasetime", "12h"); } return 0; } return 0; } -int get_dhcp_enable(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s = NULL; - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_get_value_by_section_string(s, "ignore", value); if ((*value)[0] == '\0') *value = "1"; @@ -241,7 +300,7 @@ int get_dhcp_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_dhcp_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; struct uci_section *s = NULL; @@ -253,7 +312,7 @@ int set_dhcp_enable(char *refparam, struct dmctx *ctx, int action, char *value) return 0; case VALUESET: string_to_bool(value, &b); - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { if (b) dmuci_set_value_by_section(s, "ignore", ""); else @@ -270,7 +329,7 @@ enum enum_lanip_interval_address { LANIP_INTERVAL_END }; -int get_dhcp_interval_address(struct dmctx *ctx, char **value, int option) +int get_dhcp_interval_address(struct dmctx *ctx, void *data, char *instance, char **value, int option) { json_object *res, *jobj; char *ipaddr = "" , *mask = "", *start , *limit; @@ -279,7 +338,7 @@ int get_dhcp_interval_address(struct dmctx *ctx, char **value, int option) *value = ""; - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_get_value_by_section_string(s, "start", &start); if (option == LANIP_INTERVAL_END) dmuci_get_value_by_section_string(s, "limit", &limit); @@ -288,9 +347,9 @@ int get_dhcp_interval_address(struct dmctx *ctx, char **value, int option) if (s == NULL) { return 0; } - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "ipaddr", &ipaddr); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); if (ipaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); if (res) { jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); @@ -300,9 +359,9 @@ int get_dhcp_interval_address(struct dmctx *ctx, char **value, int option) if (ipaddr[0] == '\0') { return 0; } - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "netmask", &mask); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); if (res) { jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); mask = dmjson_get_value(jobj, 1, "mask"); @@ -325,19 +384,19 @@ int get_dhcp_interval_address(struct dmctx *ctx, char **value, int option) } return 0; } -int get_dhcp_interval_address_min(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_interval_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - get_dhcp_interval_address(ctx, value, LANIP_INTERVAL_START); + get_dhcp_interval_address(ctx, data, instance, value, LANIP_INTERVAL_START); return 0; } -int get_dhcp_interval_address_max(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_interval_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - get_dhcp_interval_address(ctx, value, LANIP_INTERVAL_END); + get_dhcp_interval_address(ctx, data, instance, value, LANIP_INTERVAL_END); return 0; } -int set_dhcp_address_min(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { json_object *res, *jobj; char *ipaddr = "", *mask = "", *start , *limit, buf[16]; @@ -347,9 +406,9 @@ int set_dhcp_address_min(char *refparam, struct dmctx *ctx, int action, char *va case VALUECHECK: return 0; case VALUESET: - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "ipaddr", &ipaddr); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); if (ipaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); if (res) { jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); ipaddr = dmjson_get_value(jobj, 1, "address"); @@ -358,9 +417,9 @@ int set_dhcp_address_min(char *refparam, struct dmctx *ctx, int action, char *va if (ipaddr[0] == '\0') return 0; - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "netmask", &mask); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); if (res) { jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); mask = dmjson_get_value(jobj, 1, "mask"); @@ -373,7 +432,7 @@ int set_dhcp_address_min(char *refparam, struct dmctx *ctx, int action, char *va mask = "255.255.255.0"; ipcalc_rev_start(ipaddr, mask, value, buf); - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_set_value_by_section(s, "start", buf); break; } @@ -383,7 +442,7 @@ int set_dhcp_address_min(char *refparam, struct dmctx *ctx, int action, char *va return 0; } -int set_dhcp_address_max(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int i_val; json_object *res, *jobj; @@ -394,15 +453,15 @@ int set_dhcp_address_max(char *refparam, struct dmctx *ctx, int action, char *va case VALUECHECK: return 0; case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_get_value_by_section_string(s, "start", &start); break; } if (!s) return 0; - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "ipaddr", &ipaddr); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", &ipaddr); if (ipaddr[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); if (res) { jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); ipaddr = dmjson_get_value(jobj, 1, "address"); } @@ -410,9 +469,9 @@ int set_dhcp_address_max(char *refparam, struct dmctx *ctx, int action, char *va if (ipaddr[0] == '\0') return 0; - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "netmask", &mask); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", &mask); if (mask[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); if (res) { jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); mask = dmjson_get_value(jobj, 1, "mask"); @@ -432,7 +491,7 @@ int set_dhcp_address_max(char *refparam, struct dmctx *ctx, int action, char *va } -int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char val[512] = {0}, *p; struct uci_section *s = NULL; @@ -440,8 +499,8 @@ int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **value) unsigned int n_min, n_max, n_ip; *value = ""; - get_dhcp_interval_address(ctx, &min, LANIP_INTERVAL_START); - get_dhcp_interval_address(ctx, &max, LANIP_INTERVAL_END); + get_dhcp_interval_address(ctx, data, instance, &min, LANIP_INTERVAL_START); + get_dhcp_interval_address(ctx, data, instance, &max, LANIP_INTERVAL_END); if (min[0] == '\0' || max[0] == '\0') return 0; n_min = inet_network(min); @@ -463,7 +522,7 @@ int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL; struct uci_section *dhcp_section = NULL; @@ -475,8 +534,8 @@ int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int action, c case VALUECHECK: return 0; case VALUESET: - get_dhcp_interval_address(ctx, &min, LANIP_INTERVAL_START); - get_dhcp_interval_address(ctx, &max, LANIP_INTERVAL_END); + get_dhcp_interval_address(ctx, data, instance, &min, LANIP_INTERVAL_START); + get_dhcp_interval_address(ctx, data, instance, &max, LANIP_INTERVAL_END); n_min = inet_network(min); n_max = inet_network(max); local_value = dmstrdup(value); @@ -493,7 +552,7 @@ int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int action, c else { dmuci_add_section("dhcp", "host", &dhcp_section, &val); dmuci_set_value_by_section(dhcp_section, "mac", DHCPSTATICADDRESS_DISABLED_CHADDR); - dmuci_set_value_by_section(dhcp_section, "interface", cur_dhcp_args.interface); + dmuci_set_value_by_section(dhcp_section, "interface", ((struct dhcp_args *)data)->interface); dmuci_set_value_by_section(dhcp_section, "ip", pch); } } @@ -509,7 +568,7 @@ int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int action, c return 0; } -int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *mask; json_object *res, *jobj; @@ -517,14 +576,14 @@ int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value) char *val; *value = ""; - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_get_value_by_section_string(s, "netmask", value); break; } if (s == NULL || (*value)[0] == '\0') - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "netmask", value); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "netmask", value); if ((*value)[0] == '\0') { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", ((struct dhcp_args *)data)->interface, String}}, 1, &res); DM_ASSERT(res, *value = ""); jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address"); mask = dmjson_get_value(jobj, 1, "mask"); @@ -535,7 +594,7 @@ int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL; @@ -543,7 +602,7 @@ int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, int action, char *val case VALUECHECK: return 0; case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_set_value_by_section(s, "netmask", value); return 0; } @@ -552,36 +611,35 @@ int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, int action, char *val return 0; } -int get_dhcp_iprouters(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "gateway", value); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "gateway", value); if ((*value)[0] == '\0') { - dmuci_get_option_value_string("network", cur_dhcp_args.interface, "ipaddr", value); + dmuci_get_option_value_string("network", ((struct dhcp_args *)data)->interface, "ipaddr", value); } return 0; } -int set_dhcp_iprouters(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value("network", cur_dhcp_args.interface, "gateway", value); + dmuci_set_value("network", ((struct dhcp_args *)data)->interface, "gateway", value); return 0; } return 0; } -int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int len, mtime = 0; char *ltime = "", *pch, *spch, *ltime_ini, *tmp, *tmp_ini; struct uci_section *s = NULL; - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_get_value_by_section_string(s, "leasetime", <ime); break; } @@ -642,7 +700,7 @@ int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { struct uci_section *s = NULL; char buf[32]; @@ -651,7 +709,7 @@ int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, int action, char *valu case VALUECHECK: return 0; case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { int val = atoi(value); sprintf(buf, "%ds", val); dmuci_set_value_by_section(s, "leasetime", buf); @@ -662,18 +720,18 @@ int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, int action, char *valu return 0; } -int get_dhcp_interface(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; - linker = dmstrdup(cur_dhcp_args.interface); - adm_entry_get_linker_param(DMROOT"IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + linker = dmstrdup(((struct dhcp_args *)data)->interface); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; dmfree(linker); return 0; } -int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker; @@ -681,9 +739,9 @@ int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, int a case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); + adm_entry_get_linker_value(ctx, value, &linker); if (linker) { - dmuci_set_value_by_section(cur_dhcp_args.dhcp_sec, "interface", linker); + dmuci_set_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "interface", linker); dmfree(linker); } return 0; @@ -691,7 +749,7 @@ int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, int a return 0; } -int get_dhcp_domainname(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *result, *str; struct uci_list *val; @@ -699,12 +757,12 @@ int get_dhcp_domainname(char *refparam, struct dmctx *ctx, char **value) struct uci_section *s = NULL; *value = ""; - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_get_value_by_section_list(s, "dhcp_option", &val); if (val) { uci_foreach_element(val, e) { - if (str = strstr(e->name, "15,")) { + if ((str = strstr(e->name, "15,"))) { *value = dmstrdup(str + sizeof("15,") - 1); //MEM WILL BE FREED IN DMMEMCLEAN return 0; } @@ -714,7 +772,7 @@ int get_dhcp_domainname(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_dhcp_domainname(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *result, *dn, *pch; struct uci_list *val; @@ -726,7 +784,7 @@ int set_dhcp_domainname(char *refparam, struct dmctx *ctx, int action, char *val case VALUECHECK: return 0; case VALUESET: - uci_foreach_option_eq("dhcp", "dhcp", "interface", cur_dhcp_args.interface, s) { + uci_foreach_option_eq("dhcp", "dhcp", "interface", ((struct dhcp_args *)data)->interface, s) { dmuci_get_value_by_section_list(s, option, &val); if (val) { uci_foreach_element_safe(val, e, tmp) @@ -742,32 +800,32 @@ int set_dhcp_domainname(char *refparam, struct dmctx *ctx, int action, char *val } end: sprintf(buf, "15,%s", value); - dmuci_add_list_value_by_section(cur_dhcp_args.dhcp_sec, "dhcp_option", buf); + dmuci_add_list_value_by_section(((struct dhcp_args *)data)->dhcp_sec, "dhcp_option", buf); return 0; } -int get_dhcp_static_alias(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dhcp_staticargs.dhcpsection, "ldhcpalias", value); + dmuci_get_value_by_section_string(((struct dhcp_static_args *)data)->dhcpsection, "ldhcpalias", value); return 0; } -int set_dhcp_static_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dhcp_staticargs.dhcpsection, "ldhcpalias", value); + dmuci_set_value_by_section(((struct dhcp_static_args *)data)->dhcpsection, "ldhcpalias", value); return 0; } return 0; } -int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *chaddr; - struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)ctx->args; + struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)data; dmuci_get_value_by_section_string(dhcpargs->dhcpsection, "mac", &chaddr); if (strcmp(chaddr, DHCPSTATICADDRESS_DISABLED_CHADDR) == 0) @@ -777,10 +835,10 @@ int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, char **valu return 0; } -int set_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *chaddr; - struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)ctx->args; + struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)data; switch (action) { case VALUECHECK: @@ -796,17 +854,17 @@ int set_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)ctx->args; + struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)data; dmuci_get_value_by_section_string(dhcpargs->dhcpsection, "ip", value); return 0; } -int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)ctx->args; + struct dhcp_static_args *dhcpargs = (struct dhcp_static_args *)data; switch (action) { case VALUECHECK: @@ -818,96 +876,55 @@ int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, char **value) +int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value(cur_dhcp_client_args.client, 1, "macaddr"); + *value = dmjson_get_value(((struct client_args *)data)->client, 1, "macaddr"); return 0; } /************************************************************* * ENTRY METHOD /*************************************************************/ -int entry_method_root_dhcp(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"DHCPv4.") { - DMOBJECT(DMROOT"DHCPv4.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"DHCPv4.Server.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"DHCPv4.Server.Pool.", ctx, "0", 1, add_dhcp_server, delete_dhcp_server_all, NULL); - SUBENTRY(entry_dhcp, ctx); - return 0; - } - return FAULT_9005; -} -inline int entry_dhcp(struct dmctx *ctx) +int browseDhcpInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s; char *interface, *idhcp = NULL, *idhcp_last = NULL; + struct dhcp_args curr_dhcp_args = {0}; uci_foreach_sections("dhcp","dhcp", s) { dmuci_get_value_by_section_string(s, "interface", &interface); - init_dhcp_args(ctx, s, interface); - idhcp = handle_update_instance(1, ctx, &idhcp_last, update_instance_alias, 3, s, "dhcp_instance", "dhcp_alias"); - SUBENTRY(entry_dhcp_instance, ctx, interface, idhcp); + init_dhcp_args(&curr_dhcp_args, s, interface); + idhcp = handle_update_instance(1, dmctx, &idhcp_last, update_instance_alias, 3, s, "dhcp_instance", "dhcp_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_args, idhcp) == DM_STOP) + break; } - return 0; } -inline int entry_dhcp_instance(struct dmctx *ctx, char *interface, char *int_num) -{ - IF_MATCH(ctx, DMROOT"DHCPv4.Server.Pool.%s.", int_num) { - DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.", ctx, "0", NULL, NULL, delete_dhcp_server, NULL, int_num); - DMPARAM("DNSServers", ctx, "1", get_dns_server, set_dns_server, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_DHCPServerConfigurable", ctx, "1", get_dhcp_configurable, set_dhcp_configurable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_dhcp_enable, set_dhcp_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("MinAddress", ctx, "1", get_dhcp_interval_address_min, set_dhcp_address_min, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxAddress", ctx, "1", get_dhcp_interval_address_max, set_dhcp_address_max, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ReservedAddresses", ctx, "1", get_dhcp_reserved_addresses, set_dhcp_reserved_addresses, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SubnetMask", ctx, "1", get_dhcp_subnetmask, set_dhcp_subnetmask, NULL, 0, 1, UNDEF, NULL); - DMPARAM("IPRouters", ctx, "1", get_dhcp_iprouters, set_dhcp_iprouters, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LeaseTime", ctx, "1", get_dhcp_leasetime, set_dhcp_leasetime, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DomainName", ctx, "1", get_dhcp_domainname, set_dhcp_domainname, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Interface", ctx, "1", get_dhcp_interface, set_dhcp_interface_linker_parameter, NULL, 0, 1, UNDEF, NULL); // refer to IP.Interface - DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.StaticAddress.", ctx, "0", NULL, add_dhcp_staticaddress, delete_dhcp_staticaddress_all, NULL, int_num); //TODO - SUBENTRY(entry_dhcp_static_address, ctx, interface, int_num); - DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.Client.", ctx, "0", NULL, NULL, NULL, NULL, int_num); //TODO - SUBENTRY(entry_dhcp_client, ctx, interface, int_num); - return 0; - } - return FAULT_9005; -} - - -inline int entry_dhcp_static_address(struct dmctx *ctx, char *interface, char *idev) +int browseDhcpStaticInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *sss = NULL; char *idhcp = NULL, *idhcp_last = NULL; - uci_foreach_option_cont("dhcp", "host", "interface", interface, sss) { - idhcp = handle_update_instance(2, ctx, &idhcp_last, update_instance_alias, 3, sss, "ldhcpinstance", "ldhcpalias"); - init_args_dhcp_host(ctx, sss); - SUBENTRY(entry_dhcp_static_address_instance, ctx, idev, idhcp); + struct dhcp_static_args curr_dhcp_staticargs = {0}; + + uci_foreach_option_cont("dhcp", "host", "interface", ((struct dhcp_args *)prev_data)->interface, sss) { + idhcp = handle_update_instance(2, dmctx, &idhcp_last, update_instance_alias, 3, sss, "ldhcpinstance", "ldhcpalias"); + init_args_dhcp_host(&curr_dhcp_staticargs, sss); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_staticargs, idhcp) == DM_STOP) + break; } + return 0; } -inline int entry_dhcp_static_address_instance(struct dmctx *ctx, char *int_num, char *st_address) -{ - IF_MATCH(ctx, DMROOT"DHCPv4.Server.Pool.%s.StaticAddress.%s.", int_num, st_address) { - DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.StaticAddress.%s.", ctx, "1", NULL, NULL, delete_dhcp_staticaddress, NULL, int_num, st_address); - DMPARAM("Alias", ctx, "1", get_dhcp_static_alias, set_dhcp_static_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Chaddr", ctx, "1", get_dhcp_staticaddress_chaddr, set_dhcp_staticaddress_chaddr, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Yiaddr", ctx, "1", get_dhcp_staticaddress_yiaddr, set_dhcp_staticaddress_yiaddr, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_dhcp_client(struct dmctx *ctx, char *interface, char *idev ) +int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *sss = NULL; char *idx = NULL, *idx_last = NULL; json_object *res = NULL, *client_obj = NULL; char *dhcp, *network; int id = 0; + struct client_args curr_dhcp_client_args = {0}; + dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res); if (res) { json_object_object_foreach(res, key, client_obj) { @@ -915,11 +932,12 @@ inline int entry_dhcp_client(struct dmctx *ctx, char *interface, char *idev ) if(strcmp(dhcp, "true") == 0) { network = dmjson_get_value(client_obj, 1, "network"); - if(strcmp(network, interface) == 0) + if(strcmp(network, ((struct dhcp_args *)prev_data)->interface) == 0) { - init_dhcp_client_args(ctx, client_obj); - idx = handle_update_instance(2, ctx, &idx_last, update_instance_without_section, 1, ++id); - SUBENTRY(entry_dhcp_client_instance, ctx, idev, idx, key); + init_dhcp_client_args(&curr_dhcp_client_args, client_obj, key); + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_client_args, idx) == DM_STOP) + break; } } } @@ -927,15 +945,3 @@ inline int entry_dhcp_client(struct dmctx *ctx, char *interface, char *idev ) return 0; } -inline int entry_dhcp_client_instance(struct dmctx *ctx, char *int_num, char *idx, char *key) -{ - char linker[32] = "linker_dhcp:"; - strcat(linker, key); - IF_MATCH(ctx, DMROOT"DHCPv4.Server.Pool.%s.Client.%s.", int_num, idx) { - DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.Client.%s.", ctx, "1", NULL, NULL, NULL, linker, int_num, idx); - DMPARAM("Chaddr", ctx, "0", get_dhcp_client_chaddr, NULL, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - diff --git a/dm/dmtree/tr181/dhcp.h b/dm/dmtree/tr181/dhcp.h index e6877f6..2e69b87 100644 --- a/dm/dmtree/tr181/dhcp.h +++ b/dm/dmtree/tr181/dhcp.h @@ -11,6 +11,8 @@ #ifndef __DHCP_H #define __DHCP_H +#include + struct dhcp_args { struct uci_section *dhcp_sec; @@ -25,8 +27,56 @@ struct dhcp_static_args struct client_args { json_object *client; + char *key; }; -int entry_method_root_dhcp(struct dmctx *ctx); +extern DMOBJ tDhcpv4Obj[]; +extern DMOBJ tDhcpv4ServerObj[]; +extern DMOBJ tDhcpServerPoolObj[]; +extern DMLEAF tDhcpServerPoolParams[]; +extern DMLEAF tDhcpServerPoolAddressParams[]; +extern DMLEAF tDhcpServerPoolClientParams[]; + +int browseDhcpInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseDhcpStaticInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseDhcpClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_dhcp_server(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_dhcp_staticaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +int get_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_interval_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_interval_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_dns_server(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_configurable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_address_min(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_address_max(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_subnetmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_iprouters(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_domainname(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_static_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_staticaddress_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int get_dhcp_client_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif diff --git a/dm/dmtree/tr181/ethernet.c b/dm/dmtree/tr181/ethernet.c index 64214c9..3e9be12 100644 --- a/dm/dmtree/tr181/ethernet.c +++ b/dm/dmtree/tr181/ethernet.c @@ -19,46 +19,98 @@ #include "ethernet.h" #include "dmjson.h" -struct eth_port_args cur_eth_port_args = {0}; char *wan_ifname = NULL; -inline int init_eth_port(struct dmctx *ctx, struct uci_section *s, char *ifname) +/*** Ethernet. ***/ +DMOBJ tEthernetObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf, linker*/ +{"Interface", &DMREAD, NULL, NULL, NULL, browseEthIfaceInst, NULL, NULL, tEthernetStatObj, tEthernetParams, get_linker_val}, +{0} +}; + + +DMLEAF tEthernetParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"Alias", &DMWRITE, DMT_STRING, get_eth_port_alias, set_eth_port_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_eth_port_enable, set_eth_port_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_eth_port_status, NULL, NULL, NULL}, +{"MaxBitRate", &DMWRITE, DMT_STRING, get_eth_port_maxbitrate, set_eth_port_maxbitrate, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_eth_port_name, NULL, NULL, NULL}, +{"MACAddress", &DMREAD, DMT_STRING, get_eth_port_mac_address, NULL, NULL, NULL}, +{"DuplexMode", &DMWRITE, DMT_STRING, get_eth_port_duplexmode, set_eth_port_duplexmode, NULL, NULL}, +{0} +}; + +/*** Ethernet.Stats. ***/ +DMOBJ tEthernetStatObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf, linker*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tEthernetStatParams, NULL}, +{0} +}; + +DMLEAF tEthernetStatParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"BytesSent", &DMREAD, DMT_UNINT, get_eth_port_stats_tx_bytes, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_eth_port_stats_rx_bytes, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_eth_port_stats_tx_packets, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_eth_port_stats_rx_packets, NULL, NULL, NULL}, +{0} +}; + + +/************************************************************************** +* LINKER +***************************************************************************/ +int get_linker_val(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if (((struct eth_port_args *)data)->ifname) { + *linker = ((struct eth_port_args *)data)->ifname; + return 0; + } else { + *linker = ""; + return 0; + } +} +/************************************************************************** +* INIT +***************************************************************************/ +inline int init_eth_port(struct eth_port_args *args, struct uci_section *s, char *ifname) { - struct eth_port_args *args = &cur_eth_port_args; - ctx->args = (void *)args; args->eth_port_sec = s; args->ifname = ifname; return 0; } - -///////////////////SET & GET ALIAS//////////////////////////////////// -int get_eth_port_alias(char *refparam, struct dmctx *ctx, char **value) +/************************************************************************** +* SET & GET ALIAS +***************************************************************************/ +int get_eth_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_eth_port_args.eth_port_sec, "eth_port_alias", value); + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "eth_port_alias", value); return 0; } -int set_eth_port_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_eth_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_eth_port_args.eth_port_sec, "eth_port_alias", value); + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "eth_port_alias", value); return 0; } return 0; } -//////////////////////////GET & SET ETH PARAM////////////////: -int get_eth_port_enable(char *refparam, struct dmctx *ctx, char **value) +/************************************************************************** +* GET & SET ETH PARAM +***************************************************************************/ +int get_eth_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; char *ifname; - if (strstr(cur_eth_port_args.ifname, wan_ifname)) { + if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) { ifname = dmstrdup(wan_ifname); } else - ifname = dmstrdup(cur_eth_port_args.ifname); + ifname = dmstrdup(((struct eth_port_args *)data)->ifname); dmubus_call("network.device", "status", UBUS_ARGS{{"name", ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -67,7 +119,7 @@ int get_eth_port_enable(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_eth_port_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_eth_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *ifname; @@ -79,10 +131,10 @@ int set_eth_port_enable(char *refparam, struct dmctx *ctx, int action, char *val return 0; case VALUESET: string_to_bool(value, &b); - if (strstr(cur_eth_port_args.ifname, wan_ifname)) { + if (strstr(((struct eth_port_args *)data)->ifname, wan_ifname)) { ifname = dmstrdup(wan_ifname); } else - ifname = dmstrdup(cur_eth_port_args.ifname); + ifname = dmstrdup(((struct eth_port_args *)data)->ifname); if (b) { DMCMD("ethctl", 3, ifname, "phy-power", "up"); //TODO wait ubus command @@ -96,11 +148,11 @@ int set_eth_port_enable(char *refparam, struct dmctx *ctx, int action, char *val return 0; } -int get_eth_port_status(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { bool b; - get_eth_port_enable(refparam, ctx, value); + get_eth_port_enable(refparam, ctx, data, instance, value); string_to_bool(*value, &b); if (b) *value = "Up"; @@ -109,11 +161,11 @@ int get_eth_port_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *pch, *spch, *v; - dmuci_get_value_by_section_string(cur_eth_port_args.eth_port_sec, "speed", value); + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", value); if ((*value)[0] == '\0' || strcmp(*value, "disabled") == 0 ) return 0; else { @@ -128,7 +180,7 @@ int get_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, int action, char *value) +int set_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *val = "", *p = ""; char *duplex; @@ -138,18 +190,18 @@ int set_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, int action, char return 0; case VALUESET: if (strcasecmp(value, "disabled") == 0 ) { - dmuci_set_value_by_section(cur_eth_port_args.eth_port_sec, "speed", "disabled"); + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "disabled"); } else if (strcasecmp(value, "auto") == 0 || strcmp(value, "-1") == 0) { - dmuci_set_value_by_section(cur_eth_port_args.eth_port_sec, "speed", "auto"); + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto"); } else { - dmuci_get_value_by_section_string(cur_eth_port_args.eth_port_sec, "speed", &duplex); + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &duplex); if (strcmp(duplex, "auto") == 0 || strcmp(duplex, "disabled") == 0) p = "FDAUTO"; else { p = strchr(duplex, 'F') ? strchr(duplex, 'F') : strchr(duplex, 'H'); } if (p) dmastrcat(&val, value, p); - dmuci_set_value_by_section(cur_eth_port_args.eth_port_sec, "speed", val); + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val); dmfree(val); } return 0; @@ -157,27 +209,27 @@ int set_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_eth_port_name(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_eth_port_args.eth_port_sec, "name", value); + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value); return 0; } -int get_eth_port_mac_address(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_mac_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_eth_port_args.ifname, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 1, "macaddr"); return 0; } -int get_eth_port_duplexmode(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *tmp, *name; - dmuci_get_value_by_section_string(cur_eth_port_args.eth_port_sec, "speed", value); + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", value); if (*value[0] == '\0') { *value = ""; } else if (strcmp(*value, "auto") == 0) { @@ -193,7 +245,7 @@ int get_eth_port_duplexmode(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_eth_port_duplexmode(char *refparam, struct dmctx *ctx, int action, char *value) +int set_eth_port_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *m, *spch, *rate, *val = NULL; @@ -202,10 +254,10 @@ int set_eth_port_duplexmode(char *refparam, struct dmctx *ctx, int action, char return 0; case VALUESET: if (strcasecmp(value, "auto") == 0) { - dmuci_set_value_by_section(cur_eth_port_args.eth_port_sec, "speed", "auto"); + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", "auto"); return 0; } - dmuci_get_value_by_section_string(cur_eth_port_args.eth_port_sec, "speed", &m); + dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", &m); m = dmstrdup(m); rate = m; if (strcmp(rate, "auto") == 0) @@ -221,7 +273,7 @@ int set_eth_port_duplexmode(char *refparam, struct dmctx *ctx, int action, char dmfree(m); return 0; } - dmuci_set_value_by_section(cur_eth_port_args.eth_port_sec, "speed", val); + dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", val); dmfree(m); dmfree(val); return 0; @@ -229,62 +281,55 @@ int set_eth_port_duplexmode(char *refparam, struct dmctx *ctx, int action, char return 0; } -int get_eth_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_eth_port_args.ifname, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "tx_bytes"); return 0; } -int get_eth_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_eth_port_args.ifname, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "rx_bytes"); return 0; } -int get_eth_port_stats_tx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_eth_port_args.ifname, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "tx_packets"); return 0; } -int get_eth_port_stats_rx_packets(char *refparam, struct dmctx *ctx, char **value) +int get_eth_port_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_eth_port_args.ifname, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct eth_port_args *)data)->ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", "rx_packets"); return 0; } -/////////////////////ENTRY METHOD ////////////////////////// -int entry_method_root_Ethernet(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Ethernet.") { - DMOBJECT(DMROOT"Ethernet.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"Ethernet.Interface.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_method_eth_interface, ctx); - return 0; - } - return FAULT_9005; -} +/************************************************************* + * ENTRY METHOD +/*************************************************************/ -inline int entry_method_eth_interface(struct dmctx *ctx) +int browseEthIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *int_num = NULL, *int_num_last = NULL, *ifname; struct uci_section *ss = NULL; + struct eth_port_args curr_eth_port_args = {0}; #ifndef EX400 dmuci_get_option_value_string("layer2_interface_ethernet", "Wan", "baseifname", &wan_ifname); #else @@ -295,30 +340,11 @@ inline int entry_method_eth_interface(struct dmctx *ctx) if (strcmp(ifname, wan_ifname) == 0) { dmasprintf(&ifname, "%s.1", ifname); } - init_eth_port(ctx, ss, ifname); - int_num = handle_update_instance(1, ctx, &int_num_last, update_instance_alias, 3, ss, "eth_port_instance", "eth_port_alias"); - SUBENTRY(entry_eth_interface_instance, ctx, int_num); + init_eth_port(&curr_eth_port_args, ss, ifname); + int_num = handle_update_instance(1, dmctx, &int_num_last, update_instance_alias, 3, ss, "eth_port_instance", "eth_port_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_port_args, int_num) == DM_STOP) + break; } return 0; } -inline int entry_eth_interface_instance(struct dmctx *ctx, char *int_num) -{ - IF_MATCH(ctx, DMROOT"Ethernet.Interface.%s.", int_num) { - DMOBJECT(DMROOT"Ethernet.Interface.%s.", ctx, "0", 1, NULL, NULL, cur_eth_port_args.ifname, int_num); - DMPARAM("Alias", ctx, "1", get_eth_port_alias, set_eth_port_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_eth_port_enable, set_eth_port_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_eth_port_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxBitRate", ctx, "1", get_eth_port_maxbitrate, set_eth_port_maxbitrate, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_eth_port_name, NULL, NULL, 0, 1, UNDEF, NULL); //TO CHECK R/W - DMPARAM("MACAddress", ctx, "0", get_eth_port_mac_address, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DuplexMode", ctx, "1", get_eth_port_duplexmode, set_eth_port_duplexmode, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Ethernet.Interface.%s.Stats.", ctx, "0", 1, NULL, NULL, NULL, int_num); - DMPARAM("BytesSent", ctx, "0", get_eth_port_stats_tx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_eth_port_stats_rx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_eth_port_stats_tx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_eth_port_stats_rx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr181/ethernet.h b/dm/dmtree/tr181/ethernet.h index d3e57a7..6fb1907 100644 --- a/dm/dmtree/tr181/ethernet.h +++ b/dm/dmtree/tr181/ethernet.h @@ -16,8 +16,29 @@ struct eth_port_args struct uci_section *eth_port_sec; char *ifname; }; +extern DMOBJ tEthernetObj[]; +extern DMOBJ tEthernetStatObj[]; +extern DMLEAF tEthernetParams[]; +extern DMLEAF tEthernetStatParams[]; +int browseEthIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_eth_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_mac_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_stats_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_stats_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_stats_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_eth_port_stats_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_eth_port_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_eth_port_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_eth_port_maxbitrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_eth_port_duplexmode(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -int entry_method_root_Ethernet(struct dmctx *ctx); - +int get_linker_val(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif diff --git a/dm/dmtree/tr181/hosts.c b/dm/dmtree/tr181/hosts.c index 3124007..4d43693 100644 --- a/dm/dmtree/tr181/hosts.c +++ b/dm/dmtree/tr181/hosts.c @@ -19,15 +19,38 @@ #include "hosts.h" #include "dmjson.h" -struct host_args cur_host_args = {0}; +/*** Hosts. ***/ + +DMOBJ thostsObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Host", &DMREAD, NULL, NULL, NULL, browsehostInst, NULL, NULL, NULL, thostParam, NULL}, +{0} +}; + +DMLEAF thostsParam[] = { +{"HostNumberOfEntries", &DMREAD, DMT_UNINT, get_host_nbr_entries, NULL, NULL, NULL}, +{0} +}; + +/*** Hosts.Host ***/ +DMLEAF thostParam[] = { +{"IPAddress", &DMREAD, DMT_STRING, get_host_ipaddress, NULL, NULL, &DMNONE}, +{"HostName", &DMREAD, DMT_STRING, get_host_hostname, NULL, NULL, &DMNONE}, +{"Active", &DMREAD, DMT_BOOL, get_host_active, NULL, NULL, &DMNONE}, +{"PhysAddress", &DMREAD, DMT_STRING, get_host_phy_address, NULL, NULL, &DMNONE}, +{"X_INTENO_SE_InterfaceType", &DMREAD, DMT_STRING, get_host_interfacetype, NULL, NULL, &DMNONE}, +{"AddressSource", &DMREAD, DMT_STRING, get_host_address_source, NULL, NULL, &DMNONE}, +{"LeaseTimeRemaining", &DMREAD, DMT_STRING, get_host_leasetime_remaining, NULL, NULL, &DMNONE}, +{"DHCPClient", &DMREAD, DMT_STRING, get_host_dhcp_client, NULL, NULL, NULL}, +{0} +}; + /************************************************************* * INIT /*************************************************************/ -inline int init_host_args(struct dmctx *ctx, json_object *clients, char *key) +inline int init_host_args(struct host_args *args, json_object *clients, char *key) { - struct host_args *args = &cur_host_args; - ctx->args = (void *)args; args->client = clients; args->key = key; return 0; @@ -35,34 +58,34 @@ inline int init_host_args(struct dmctx *ctx, json_object *clients, char *key) /************************************************************* * GET & SET PARAM /*************************************************************/ -int get_host_ipaddress(char *refparam, struct dmctx *ctx, char **value) +int get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value(cur_host_args.client, 1, "ipaddr"); + *value = dmjson_get_value(((struct host_args *)data)->client, 1, "ipaddr"); return 0; } -int get_host_hostname(char *refparam, struct dmctx *ctx, char **value) +int get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value(cur_host_args.client, 1, "hostname"); + *value = dmjson_get_value(((struct host_args *)data)->client, 1, "hostname"); return 0; } -int get_host_active(char *refparam, struct dmctx *ctx, char **value) +int get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value(cur_host_args.client, 1, "connected"); + *value = dmjson_get_value(((struct host_args *)data)->client, 1, "connected"); return 0; } -int get_host_phy_address(char *refparam, struct dmctx *ctx, char **value) +int get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmjson_get_value(cur_host_args.client, 1, "macaddr"); + *value = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr"); return 0; } -int get_host_address_source(char *refparam, struct dmctx *ctx, char **value) { +int get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *dhcp; - dhcp = dmjson_get_value(cur_host_args.client, 1, "dhcp"); + dhcp = dmjson_get_value(((struct host_args *)data)->client, 1, "dhcp"); if (strcasecmp(dhcp, "true") == 0) *value = "DHCP"; else @@ -70,7 +93,7 @@ int get_host_address_source(char *refparam, struct dmctx *ctx, char **value) { return 0; } -int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, char **value) +int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char buf[80], *dhcp; FILE *fp; @@ -79,12 +102,13 @@ int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, char **value char *leasetime, *mac_f, *mac, *line1; char delimiter[] = " \t"; - dhcp = dmjson_get_value(cur_host_args.client, 1, "dhcp"); + dhcp = dmjson_get_value(((struct host_args *)data)->client, 1, "dhcp"); if (strcmp(dhcp, "false") == 0) { *value = "0"; } else { - mac = dmjson_get_value(cur_host_args.client, 1, "macaddr"); + mac = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr"); + // fp = fopen(ARP_FILE, "r"); if ( fp != NULL) { @@ -111,11 +135,11 @@ int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, char **value return 0; } -int get_host_dhcp_client(char *refparam, struct dmctx *ctx, char **value) +int get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface, *linker; - dmastrcat(&linker, "linker_dhcp:", cur_host_args.key); - adm_entry_get_linker_param(DMROOT"DHCPv4.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + dmastrcat(&linker, "linker_dhcp:", ((struct host_args *)data)->key); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cDHCPv4%c", DMROOT, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) { *value = ""; } @@ -147,7 +171,7 @@ char *get_interface_type(char *mac, char *ndev) dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", p, String}}, 1, &res); if(res) { json_object_object_foreach(res, key, val) { - value = dmjson_get_value(res, 1, "macaddr"); + value = dmjson_get_value(val, 1, "macaddr"); if (strcasecmp(value, mac) == 0) return "802.11"; } @@ -159,17 +183,17 @@ char *get_interface_type(char *mac, char *ndev) return "Ethernet"; } -int get_host_interfacetype(char *refparam, struct dmctx *ctx, char **value) +int get_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *mac, *network; - mac = dmjson_get_value(cur_host_args.client, 1, "macaddr"); - network = dmjson_get_value(cur_host_args.client, 1, "network"); + mac = dmjson_get_value(((struct host_args *)data)->client, 1, "macaddr"); + network = dmjson_get_value(((struct host_args *)data)->client, 1, "network"); *value = get_interface_type(mac, network); return 0; } -int get_host_nbr_entries(char *refparam, struct dmctx *ctx, char **value) +int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { int entries = 0; json_object *res; @@ -182,50 +206,26 @@ int get_host_nbr_entries(char *refparam, struct dmctx *ctx, char **value) dmasprintf(value, "%d", entries); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } + /************************************************************* * ENTRY METHOD /*************************************************************/ -int entry_method_root_hosts(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Hosts.") { - DMOBJECT(DMROOT"Hosts.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("HostNumberOfEntries", ctx, "0", get_host_nbr_entries, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"Hosts.Host.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_host, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_host(struct dmctx *ctx) +int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { json_object *res, *client_obj; char *idx, *idx_last = NULL; int id = 0; + struct host_args curr_host_args = {0}; + dmubus_call("router.network", "clients", UBUS_ARGS{}, 0, &res); if (res) { json_object_object_foreach(res, key, client_obj) { - init_host_args(ctx, client_obj, key); - idx = handle_update_instance(2, ctx, &idx_last, update_instance_without_section, 1, ++id); - SUBENTRY(entry_host_instance, ctx, idx); + init_host_args(&curr_host_args, client_obj, key); + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_host_args, idx) == DM_STOP) + break; } } return 0; } -inline int entry_host_instance(struct dmctx *ctx, char *int_num) -{ - IF_MATCH(ctx, DMROOT"Hosts.Host.%s.", int_num) { - DMOBJECT(DMROOT"Hosts.Host.%s.", ctx, "0", NULL, NULL, NULL, NULL, int_num); - DMPARAM("IPAddress", ctx, "0", get_host_ipaddress, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("HostName", ctx, "0", get_host_hostname, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("Active", ctx, "0", get_host_active, NULL, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("PhysAddress", ctx, "0", get_host_phy_address, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("X_INTENO_SE_InterfaceType", ctx, "0", get_host_interfacetype, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("AddressSource", ctx, "0", get_host_address_source, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("LeaseTimeRemaining", ctx, "0", get_host_leasetime_remaining, NULL, NULL, 0, 0, UNDEF, NULL); - DMPARAM("DHCPClient", ctx, "0", get_host_dhcp_client, NULL, NULL, 0, 1, UNDEF, NULL); //TO CHECK R/W - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr181/hosts.h b/dm/dmtree/tr181/hosts.h index 07ba0a3..03edb82 100644 --- a/dm/dmtree/tr181/hosts.h +++ b/dm/dmtree/tr181/hosts.h @@ -17,6 +17,20 @@ struct host_args char *key; }; -int entry_method_root_hosts(struct dmctx *ctx); +extern DMLEAF thostsParam[]; +extern DMLEAF thostParam[]; +extern DMOBJ thostsObj[]; + +int browsehostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_host_nbr_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_ipaddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_hostname(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_active(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_phy_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_interfacetype(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_address_source(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_leasetime_remaining(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_host_dhcp_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); #endif diff --git a/dm/dmtree/tr181/ip.c b/dm/dmtree/tr181/ip.c index 611b86c..87ffe77 100644 --- a/dm/dmtree/tr181/ip.c +++ b/dm/dmtree/tr181/ip.c @@ -12,38 +12,105 @@ #include #include #include -#include "cwmp.h" #include "dmuci.h" #include "dmubus.h" #include "dmcwmp.h" #include "dmcommon.h" #include "ip.h" #include "diagnostic.h" - #include "dmjson.h" -struct ip_args cur_ip_args = {0}; -struct ipv4_args cur_ipv4_args = {0}; +struct dm_forced_inform_s IPv4INFRM = {0, get_ipv4_finform}; +struct dm_forced_inform_s IPv6INFRM = {0, get_ipv6_finform}; + +/* *** Device.IP. *** */ +DMOBJ tIPObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Interface", &DMWRITE, add_ip_interface, delete_ip_interface, NULL, browseIPIfaceInst, NULL, NULL, tInterfaceObj, tIPintParams, get_linker_ip_interface}, +{"Diagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tDiagnosticObj, NULL, NULL}, +{0} +}; + +DMLEAF tIPintParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Enable", &DMWRITE, DMT_BOOL, get_ip_interface_enable, set_ip_interface_enable, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_ip_interface_name, NULL, NULL, NULL}, +{"LowerLayers", &DMWRITE, DMT_STRING, get_ip_int_lower_layer, set_ip_int_lower_layer, NULL, NULL}, +{0} +}; +/* *** Device.IP.Interface. *** */ +DMOBJ tInterfaceObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf*/ +{"IPv4Address", &DMWRITE, add_ipv4, delete_ipv4, NULL, browseIfaceIPv4Inst, NULL, NULL, NULL, tIPv4Params, NULL}, +{"IPv6Address", &DMWRITE, add_ipv6, delete_ipv6, NULL, browseIfaceIPv6Inst, NULL, NULL, NULL, tIPv6Params, NULL}, +{0} +}; + +DMOBJ tDiagnosticObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf*/ +{"IPPingDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tIpPingDiagParams, NULL}, +{0} +}; +/* *** Device.IP.Interface.{i}.IPv4Address.{i}. *** */ +DMLEAF tIPv4Params[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform*/ +{"Alias", &DMWRITE, DMT_STRING, get_ipv4_alias, set_ipv4_alias, &IPv4INFRM, NULL}, +{"Enable", &DMREAD, DMT_BOOL, get_ip_enable, NULL, &IPv4INFRM, NULL}, +{"X_BROADCOM_COM_FirewallEnabled", &DMWRITE, DMT_BOOL, get_firewall_enabled, set_firewall_enabled, &IPv4INFRM, NULL}, +{"IPAddress", &DMWRITE, DMT_STRING, get_ipv4_address, set_ipv4_address, &IPv4INFRM, NULL}, +{"SubnetMask", &DMWRITE, DMT_STRING, get_ipv4_netmask, set_ipv4_netmask, &IPv4INFRM, NULL}, +{"AddressingType", &DMWRITE, DMT_STRING, get_ipv4_addressing_type, set_ipv4_addressing_type, &IPv4INFRM, NULL}, +{0} +}; + + +/* *** Device.IP.Interface.{i}.IPv6Address.{i}. *** */ +DMLEAF tIPv6Params[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform*/ +{"Alias", &DMWRITE, DMT_STRING, get_ipv6_alias, set_ipv6_alias, &IPv6INFRM, NULL}, +{"Enable", &DMREAD, DMT_BOOL, get_ip_enable, NULL, &IPv6INFRM, NULL}, +{"IPAddress", &DMWRITE, DMT_STRING, get_ipv6_address, set_ipv6_address, &IPv6INFRM, NULL}, +{"Origin", &DMWRITE, DMT_STRING, get_ipv6_addressing_type, set_ipv6_addressing_type, &IPv6INFRM, NULL}, +{0} +}; + +DMLEAF tIpPingDiagParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification , linker*/ +{"DiagnosticsState", &DMWRITE, DMT_STRING, get_ip_ping_diagnostics_state, set_ip_ping_diagnostics_state, NULL, NULL}, +{"Interface", &DMWRITE, DMT_BOOL, get_ip_ping_interface, set_ip_ping_interface, NULL, NULL}, +{"Host", &DMWRITE, DMT_STRING, get_ip_ping_host, set_ip_ping_host, NULL, NULL}, +{"NumberOfRepetitions", &DMWRITE, DMT_UNINT, get_ip_ping_repetition_number, set_ip_ping_repetition_number, NULL, NULL}, +{"Timeout", &DMWRITE, DMT_UNINT, get_ip_ping_timeout, set_ip_ping_timeout, NULL, NULL}, +{"DataBlockSize", &DMWRITE, DMT_UNINT, get_ip_ping_block_size, set_ip_ping_block_size, NULL, NULL}, +{"SuccessCount", &DMREAD, DMT_UNINT, get_ip_ping_success_count, NULL, NULL}, +{"FailureCount", &DMREAD, DMT_UNINT, get_ip_ping_failure_count, set_ipv6_addressing_type, NULL, NULL}, +{"AverageResponseTime", &DMREAD, DMT_UNINT, get_ip_ping_average_response_time, NULL, NULL, NULL}, +{"MinimumResponseTime", &DMREAD, DMT_UNINT, get_ip_ping_min_response_time, NULL, NULL, NULL}, +{"MaximumResponseTime", &DMREAD, DMT_UNINT, get_ip_ping_max_response_time, NULL, NULL, NULL}, +{0} +}; + +unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + return 1; + //TODO +} +unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + return 1; + //TODO +} /************************************************************* * INIT /*************************************************************/ -inline int init_ip_args(struct dmctx *ctx, struct uci_section *s) +inline int init_ip_args(struct ip_args *args, struct uci_section *s, char *ip_4address, char *ip_6address) { - struct ip_args *args = &cur_ip_args; - ctx->args = (void *)args; args->ip_sec = s; - return 0; -} - -inline int init_ipv4_args(struct dmctx *ctx, struct uci_section *s, char *ip_address, char *ip_6address) -{ - struct ipv4_args *args = &cur_ipv4_args; - ctx->args = (void *)args; - args->ipv4_sec = s; - args->ip_address = ip_address; + args->ip_4address = ip_4address; args->ip_6address = ip_6address; return 0; } + /************************************************************* * GET & SET PARAM /*************************************************************/ @@ -57,18 +124,19 @@ static inline char *ipping_get(char *option, char *def) return tmp; } -int get_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("DiagnosticState", "None"); return 0; } -int set_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; + switch (action) { - case VALUECHECK: + case VALUECHECK: return 0; case VALUESET: if (strcmp(value, "Requested") == 0) { @@ -86,16 +154,17 @@ int set_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_ip_ping_interface(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@ippingdiagnostic[0]", "interface", value); return 0; } -int set_ip_ping_interface(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; + switch (action) { case VALUECHECK: return 0; @@ -112,17 +181,18 @@ int set_ip_ping_interface(char *refparam, struct dmctx *ctx, int action, char *v return 0; } -int get_ip_ping_host(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_varstate_string("cwmp", "@ippingdiagnostic[0]", "Host", value); return 0; } -int set_ip_ping_host(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; + switch (action) { case VALUECHECK: return 0; @@ -139,13 +209,13 @@ int set_ip_ping_host(char *refparam, struct dmctx *ctx, int action, char *value) return 0; } -int get_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("NumberOfRepetitions", "3"); return 0; } -int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -166,14 +236,14 @@ int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, int action, return 0; } -int get_ip_ping_timeout(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("Timeout", "1000"); return 0; } -int set_ip_ping_timeout(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; @@ -194,17 +264,18 @@ int set_ip_ping_timeout(char *refparam, struct dmctx *ctx, int action, char *val return 0; } -int get_ip_ping_block_size(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("DataBlockSize", "64"); return 0; } -int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *tmp; struct uci_section *curr_section = NULL; + switch (action) { case VALUECHECK: return 0; @@ -220,34 +291,34 @@ int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, int action, char * return 0; } -int get_ip_ping_success_count(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("SuccessCount", "0"); return 0; } -int get_ip_ping_failure_count(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_failure_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("FailureCount", "0"); return 0; } -int get_ip_ping_average_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_average_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("AverageResponseTime", "0"); return 0; } -int get_ip_ping_min_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_min_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("MinimumResponseTime", "0"); return 0; } -int get_ip_ping_max_response_time(char *refparam, struct dmctx *ctx, char **value) +int get_ip_ping_max_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ipping_get("MaximumResponseTime", "0"); @@ -255,84 +326,84 @@ int get_ip_ping_max_response_time(char *refparam, struct dmctx *ctx, char **valu } -int get_ip_interface_enable(char *refparam, struct dmctx *ctx, char **value) +int get_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *lan_name = section_name(cur_ip_args.ip_sec); + char *lan_name = section_name(((struct ip_args *)data)->ip_sec); get_interface_enable_ubus(lan_name, refparam, ctx, value); return 0; } -int set_ip_interface_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - char *lan_name = section_name(cur_ip_args.ip_sec); + char *lan_name = section_name(((struct ip_args *)data)->ip_sec); set_interface_enable_ubus(lan_name, refparam, ctx, action, value); return 0; } -int get_ip_interface_name(char *refparam, struct dmctx *ctx, char **value) +int get_ip_interface_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmstrdup(section_name(cur_ip_args.ip_sec)); + *value = dmstrdup(section_name(((struct ip_args *)data)->ip_sec)); return 0; } -int get_firewall_enabled(char *refparam, struct dmctx *ctx, char **value) +int get_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - get_interface_firewall_enabled(section_name(cur_ip_args.ip_sec), refparam, ctx, value); + get_interface_firewall_enabled(section_name(((struct ip_args *)data)->ip_sec), refparam, ctx, value); return 0; } -int set_firewall_enabled(char *refparam, struct dmctx *ctx, int action, char *value) +int set_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - set_interface_firewall_enabled(section_name(cur_ip_args.ip_sec), refparam, ctx, action, value); + set_interface_firewall_enabled(section_name(((struct ip_args *)data)->ip_sec), refparam, ctx, action, value); return 0; } -int get_ipv4_address(char *refparam, struct dmctx *ctx, char **value) +int get_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = cur_ipv4_args.ip_address; + *value = ((struct ip_args *)data)->ip_4address; return 0; } -int set_ipv4_address(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ipaddr", value); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", value); return 0; } return 0; } -int get_ipv4_netmask(char *refparam, struct dmctx *ctx, char **value) +int get_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "netmask", value); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "netmask", value); return 0; } -int set_ipv4_netmask(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "netmask", value); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "netmask", value); return 0; } return 0; } -int get_ipv4_addressing_type (char *refparam, struct dmctx *ctx, char **value) +int get_ipv4_addressing_type (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "proto", value); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", value); if (strcmp(*value, "static") == 0) *value = "Static"; else if (strcmp(*value, "dhcp") == 0) @@ -342,7 +413,7 @@ int get_ipv4_addressing_type (char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_ipv4_addressing_type(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; switch (action) { @@ -350,21 +421,21 @@ int set_ipv4_addressing_type(char *refparam, struct dmctx *ctx, int action, char return 0; case VALUESET: if(strcasecmp(value, "static") == 0) { - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "proto", "static"); - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ipaddr", "0.0.0.0"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", "0.0.0.0"); } if(strcasecmp(value, "dhcp") == 0) { - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "proto", "dhcp"); - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ipaddr", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "dhcp"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", ""); } return 0; } return 0; } -int get_ipv6_addressing_type (char *refparam, struct dmctx *ctx, char **value) +int get_ipv6_addressing_type (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "proto", value); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", value); if (strcmp(*value, "static") == 0) *value = "Static"; else if (strcmp(*value, "dhcpv6") == 0) @@ -374,7 +445,7 @@ int get_ipv6_addressing_type (char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_ipv6_addressing_type(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipv6_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; switch (action) { @@ -382,18 +453,18 @@ int set_ipv6_addressing_type(char *refparam, struct dmctx *ctx, int action, char return 0; case VALUESET: if(strcasecmp(value, "static") == 0) { - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "proto", "static"); - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ip6addr", "0.0.0.0"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", "0.0.0.0"); } if(strcasecmp(value, "dhcpv6") == 0) { - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "proto", "dhcpv6"); - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ip6addr", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "dhcpv6"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", ""); } return 0; } return 0; } -int get_ip_int_lower_layer(char *refparam, struct dmctx *ctx, char **value) +int get_ip_int_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *wifname, *wtype, *br_inst, *mg, *device, *proto; struct uci_section *port; @@ -401,22 +472,22 @@ int get_ip_int_lower_layer(char *refparam, struct dmctx *ctx, char **value) char buf[8]; char linker[64] = ""; - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "type", &wtype); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "type", &wtype); if (strcmp(wtype, "bridge") == 0) { - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "bridge_instance", &br_inst); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "bridge_instance", &br_inst); uci_path_foreach_option_eq(icwmpd, "dmmap", "bridge_port", "bridge_key", br_inst, port) { dmuci_get_value_by_section_string(port, "mg_port", &mg); if (strcmp(mg, "true") == 0) sprintf(linker, "%s+", section_name(port)); - adm_entry_get_linker_param(DMROOT"Bridging.Bridge.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cBridging%cBridge%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) *value = ""; return 0; } } else if (wtype[0] == '\0' || strcmp(wtype, "anywan") == 0) { - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(cur_ip_args.ip_sec), String}}, 1, &res); - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "ifname", &wifname); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct ip_args *)data)->ip_sec), String}}, 1, &res); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ifname", &wifname); strcpy (linker, wifname); if (res) { device = dmjson_get_value(res, 1, "device"); @@ -427,87 +498,88 @@ int get_ip_int_lower_layer(char *refparam, struct dmctx *ctx, char **value) strcpy(linker, buf); } } - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); if (strstr(proto, "ppp")) { - sprintf(linker, "%s", section_name(cur_ip_args.ip_sec)); + sprintf(linker, "%s", section_name(((struct ip_args *)data)->ip_sec)); } } - adm_entry_get_linker_param(DMROOT"ATM.Link.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cATM%cLink%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) - adm_entry_get_linker_param(DMROOT"PTM.Link.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPTM%cLink%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) - adm_entry_get_linker_param(DMROOT"Ethernet.Interface.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) - adm_entry_get_linker_param(DMROOT"WiFi.SSID.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) - adm_entry_get_linker_param(DMROOT"PPP.Interface.", linker, value); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPPP%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); if (*value == NULL) *value = ""; return 0; } -int set_ip_int_lower_layer(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_int_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker, *pch, *spch, *dup, *b_key, *proto, *ipaddr, *ip_inst, *ipv4_inst, *p, *type; char sec[16]; + char pat[32] = ""; struct uci_section *s; switch (action) { case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); - p = strstr(value, ".Port."); - if (linker && p && strcmp(p, ".Port.1.") == 0) + adm_entry_get_linker_value(ctx, value, &linker); + sprintf(pat, "%cPort%c1%c", dm_delim, dm_delim, dm_delim); + if (linker && strstr(value, pat)) { strncpy(sec, linker, strlen(linker) - 1); sec[strlen(linker) - 1] = '\0'; DMUCI_GET_OPTION_VALUE_STRING(icwmpd, "dmmap", sec, "bridge_key", &b_key); - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "proto", &proto); - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "ipaddr", &ipaddr); - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "ip_int_instance", &ip_inst); - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "ipv4_instance", &ipv4_inst); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipaddr", &ipaddr); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ip_int_instance", &ip_inst); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv4_instance", &ipv4_inst); uci_foreach_option_eq("network", "interface", "bridge_instance", b_key, s) { dmuci_set_value_by_section(s, "proto", proto); dmuci_set_value_by_section(s, "ipaddr", ipaddr); dmuci_set_value_by_section(s, "ip_int_instance", ip_inst); dmuci_set_value_by_section(s, "ipv4_instance", ipv4_inst); - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "type", &type); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "type", &type); if (strcmp (type, "bridge")) - dmuci_delete_by_section(cur_ip_args.ip_sec, NULL, NULL); + dmuci_delete_by_section(((struct ip_args *)data)->ip_sec, NULL, NULL); } return 0; } if (linker) - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ifname", linker); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ifname", linker); return 0; } return 0; } -int get_ipv6_address(char *refparam, struct dmctx *ctx, char **value) +int get_ipv6_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = cur_ipv4_args.ip_6address; + *value = ((struct ip_args *)data)->ip_6address; return 0; } -int set_ipv6_address(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipv6_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ip6addr", value); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", value); return 0; } return 0; } -int get_ip_enable(char *refparam, struct dmctx *ctx, char **value) +int get_ip_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "true"; return 0; @@ -515,61 +587,61 @@ int get_ip_enable(char *refparam, struct dmctx *ctx, char **value) /************************************************************* * GET & SET ALIAS /*************************************************************/ -int get_ip_int_alias(char *refparam, struct dmctx *ctx, char **value) +int get_ip_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "ip_int_alias", value); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ip_int_alias", value); return 0; } -int set_ip_int_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ip_int_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ip_int_alias", value); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip_int_alias", value); return 0; } return 0; } -int get_ipv4_alias(char *refparam, struct dmctx *ctx, char **value) +int get_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "ipv4_alias", value); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv4_alias", value); return 0; } -int set_ipv4_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ipv4_alias", value); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv4_alias", value); return 0; } return 0; } -int get_ipv6_alias(char *refparam, struct dmctx *ctx, char **value) +int get_ipv6_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "ipv6_alias", value); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv6_alias", value); return 0; } -int set_ipv6_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ipv6_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *proto; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(cur_ipv4_args.ipv4_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "proto", &proto); if(strcmp(proto, "static") == 0) - dmuci_set_value_by_section(cur_ipv4_args.ipv4_sec, "ipv6_alias", value); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv6_alias", value); return 0; } return 0; @@ -592,7 +664,7 @@ char *get_last_instance_cond(char *package, char *section, char *opt_inst, char return inst; } -int add_ip_interface(struct dmctx *ctx, char **instance) +int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **instance) { char *last_inst; char ip_name[32], ib[8]; @@ -609,86 +681,106 @@ int add_ip_interface(struct dmctx *ctx, char **instance) return 0; } -int delete_ip_interface(struct dmctx *ctx) +int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - dmuci_set_value_by_section(cur_ip_args.ip_sec, "proto", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "type", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "bridge_instance", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ip_int_instance", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipv4_instance", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipv6_instance", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ifname", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipaddr", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ip6addr", ""); - return 0; -} - -int add_ipv4(struct dmctx *ctx, char **instancepara) -{ - char *instance; - - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "ipv4_instance", &instance); - *instancepara = update_instance(cur_ip_args.ip_sec, instance, "ipv4_instance"); - if(instance[0] == '\0') { - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipv4_instance", *instancepara); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipaddr", "0.0.0.0"); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "proto", "static"); + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "type", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "bridge_instance", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip_int_instance", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv4_instance", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv6_instance", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ifname", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", ""); + break; + case DEL_ALL: + return FAULT_9005; } return 0; } -int delete_ipv4(struct dmctx *ctx) -{ - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipaddr", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipv4_instance", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "proto", ""); - return 0; -} - -int add_ipv6(struct dmctx *ctx, char **instancepara) +int add_ipv4(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { char *instance; - dmuci_get_value_by_section_string(cur_ip_args.ip_sec, "ipv6_instance", &instance); - *instancepara = update_instance(cur_ip_args.ip_sec, instance, "ipv6_instance"); + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv4_instance", &instance); + *instancepara = update_instance(((struct ip_args *)data)->ip_sec, instance, "ipv4_instance"); if(instance[0] == '\0') { - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipv6_instance", *instancepara); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ip6addr", "::"); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "proto", "static"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv4_instance", *instancepara); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", "0.0.0.0"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static"); } return 0; } -int delete_ipv6(struct dmctx *ctx) +int delete_ipv4(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ip6addr", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "ipv6_instance", ""); - dmuci_set_value_by_section(cur_ip_args.ip_sec, "proto", ""); + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipaddr", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv4_instance", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); + break; + case DEL_ALL: + return FAULT_9005; + } return 0; } +int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara) +{ + char *instance; + + dmuci_get_value_by_section_string(((struct ip_args *)data)->ip_sec, "ipv6_instance", &instance); + *instancepara = update_instance(((struct ip_args *)data)->ip_sec, instance, "ipv6_instance"); + if(instance[0] == '\0') { + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv6_instance", *instancepara); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", "::"); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", "static"); + } + return 0; +} + +int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + switch (del_action) { + case DEL_INST: + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ip6addr", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "ipv6_instance", ""); + dmuci_set_value_by_section(((struct ip_args *)data)->ip_sec, "proto", ""); + break; + case DEL_ALL: + return FAULT_9005; + } + return 0; +} + +/************************************************************************** +* LINKER +***************************************************************************/ +int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + + if(((struct ip_args *)data)->ip_sec) { + dmasprintf(linker,"%s", section_name(((struct ip_args *)data)->ip_sec)); + return 0; + } else { + *linker = ""; + return 0; + } +} /************************************************************* * ENTRY METHOD /*************************************************************/ -int entry_method_root_ip(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"IP.") { - DMOBJECT(DMROOT"IP.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"IP.Interface.", ctx, "1", 1, add_ip_interface, NULL, NULL); - DMOBJECT(DMROOT"IP.Diagnostics.", ctx, "0", 0, NULL, NULL, NULL); - SUBENTRY(entry_ip_interface, ctx); - SUBENTRY(entry_ip_ping_diagnostic, ctx); - return 0; - } - return FAULT_9005; -} -inline int entry_ip_interface(struct dmctx *ctx) +int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *net_sec = NULL; char *ip_int = NULL, *ip_int_last = NULL; char *type, *ipv4addr = "", *ipv6addr = "", *proto, *inst; json_object *res, *jobj; + struct ip_args curr_ip_args = {0}; uci_foreach_sections("network", "interface", net_sec) { dmuci_get_value_by_section_string(net_sec, "type", &type); @@ -717,108 +809,38 @@ inline int entry_ip_interface(struct dmctx *ctx) if (ipv4addr[0] == '\0' && ipv6addr[0] == '\0' && strcmp(proto, "dhcp") != 0 && strcmp(proto, "dhcpv6") != 0 && strcmp(inst, "") == 0) { continue; } - init_ip_args(ctx, net_sec); - ip_int = handle_update_instance(1, ctx, &ip_int_last, update_instance_alias, 3, net_sec, "ip_int_instance", "ip_int_alias"); - SUBENTRY(entry_ip_interface_instance, ctx, ip_int); - SUBENTRY(entry_ip_address, ctx, net_sec, ipv4addr, ipv6addr, ip_int); + init_ip_args(&curr_ip_args, net_sec, ipv4addr, ipv6addr); + ip_int = handle_update_instance(1, dmctx, &ip_int_last, update_instance_alias, 3, net_sec, "ip_int_instance", "ip_int_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ip_args, ip_int) == DM_STOP) + break; } return 0; } -inline int entry_ip_address(struct dmctx *ctx, struct uci_section *net_sec, char *ipv4addr, char *ipv6addr,char *ip_int) +int browseIfaceIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *ip_sec = NULL; char *type, *ifname, *ipv4, *ipv6, *ipv4_inst = NULL, *ipv6_inst = NULL,*ipv4_inst_last = NULL, *ipv6_inst_last = NULL ; - init_ipv4_args(ctx, net_sec, ipv4addr, ipv6addr); - if(ipv4addr[0] != '\0') { - ipv4_inst = handle_update_instance(2, ctx, &ipv4_inst_last, update_instance_alias, 3, net_sec, "ipv4_instance", "ipv4_alias"); - SUBENTRY(entry_ipv4_address_instance, ctx, ip_int, ipv4_inst); - } - if (ipv6addr[0] != '\0') { - ipv6_inst = handle_update_instance(2, ctx, &ipv6_inst_last, update_instance_alias, 3, net_sec, "ipv6_instance", "ipv6_alias"); - SUBENTRY(entry_ipv6_address_instance, ctx, ip_int, ipv6_inst); - } - dmasprintf(&ifname, "br-%s", section_name(net_sec)); - uci_foreach_option_eq("network", "interface", "ifname", ifname, ip_sec) { - dmuci_get_value_by_section_string(ip_sec, "ipaddr", &ipv4); - dmuci_get_value_by_section_string(ip_sec, "ip6addr", &ipv6); - if(ipv4[0] != '\0') { - init_ipv4_args(ctx, ip_sec, ipv4, ipv6); - ipv4_inst = handle_update_instance(2, ctx, &ipv4_inst_last, update_instance_alias, 3, ip_sec, "ipv4_instance", "ipv4_alias"); - SUBENTRY(entry_ipv4_address_instance, ctx, ip_int, ipv4_inst); - } - if(ipv6[0] != '\0') { - init_ipv4_args(ctx, ip_sec, ipv4, ipv6); - ipv6_inst = handle_update_instance(2, ctx, &ipv6_inst_last, update_instance_alias, 3, ip_sec, "ipv6_instance", "ipv6_alias"); - SUBENTRY(entry_ipv6_address_instance, ctx, ip_int, ipv6_inst); - } + if(((struct ip_args *)prev_data)->ip_4address[0] != '\0') { + ipv4_inst = handle_update_instance(2, dmctx, &ipv4_inst_last, update_instance_alias, 3, ((struct ip_args *)prev_data)->ip_sec, "ipv4_instance", "ipv4_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, ipv4_inst) == DM_STOP) + goto end; } +end: return 0; } -inline int entry_ip_interface_instance(struct dmctx *ctx, char *int_num) +int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - IF_MATCH(ctx, DMROOT"IP.Interface.%s.", int_num) { - char linker[32] = ""; - strcat(linker, section_name(cur_ip_args.ip_sec)); - DMOBJECT(DMROOT"IP.Interface.%s.", ctx, "1", 1, NULL, delete_ip_interface, linker, int_num); - DMPARAM("Alias", ctx, "1", get_ip_int_alias, set_ip_int_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_ip_interface_enable, set_ip_interface_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_ip_interface_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LowerLayers", ctx, "1", get_ip_int_lower_layer, set_ip_int_lower_layer, NULL, 0, 1, UNDEF, NULL);//TODO - DMOBJECT(DMROOT"IP.Interface.%s.IPv4Address.", ctx, "1", 1, add_ipv4, NULL, NULL, int_num); - DMOBJECT(DMROOT"IP.Interface.%s.IPv6Address.", ctx, "1", 1, add_ipv6, NULL, NULL, int_num); - return 0; - } - return FAULT_9005; -} + struct uci_section *ip_sec = NULL; + char *type, *ifname, *ipv4, *ipv6, *ipv4_inst = NULL, *ipv6_inst = NULL,*ipv4_inst_last = NULL, *ipv6_inst_last = NULL ; -inline int entry_ipv4_address_instance(struct dmctx *ctx, char *int_num, char *ip_inst) -{ - IF_MATCH(ctx, DMROOT"IP.Interface.%s.IPv4Address.%s.", int_num, ip_inst) { - DMOBJECT(DMROOT"IP.Interface.%s.IPv4Address.%s.", ctx, "1", 1, NULL, delete_ipv4, NULL, int_num, ip_inst); - DMPARAM("Alias", ctx, "1", get_ipv4_alias, set_ipv4_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "0", get_ip_enable, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("X_BROADCOM_COM_FirewallEnabled", ctx, "1", get_firewall_enabled, set_firewall_enabled, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("IPAddress", ctx, "1", get_ipv4_address, set_ipv4_address, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SubnetMask", ctx, "1", get_ipv4_netmask, set_ipv4_netmask, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AddressingType", ctx, "1", get_ipv4_addressing_type, set_ipv4_addressing_type, NULL, 0, 1, UNDEF, NULL); - return 0; + if (((struct ip_args *)prev_data)->ip_6address[0] != '\0') { + ipv6_inst = handle_update_instance(2, dmctx, &ipv6_inst_last, update_instance_alias, 3, ((struct ip_args *)prev_data)->ip_sec, "ipv6_instance", "ipv6_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, prev_data, ipv6_inst) == DM_STOP) + goto end; } - return FAULT_9005; -} - -inline int entry_ipv6_address_instance(struct dmctx *ctx, char *int_num, char *ip_inst) -{ - IF_MATCH(ctx, DMROOT"IP.Interface.%s.IPv6Address.%s.", int_num, ip_inst) { - DMOBJECT(DMROOT"IP.Interface.%s.IPv6Address.%s.", ctx, "1", 1, NULL, delete_ipv6, NULL, int_num, ip_inst); - DMPARAM("Alias", ctx, "1", get_ipv6_alias, set_ipv6_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "0", get_ip_enable, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("IPAddress", ctx, "1", get_ipv6_address, set_ipv6_address, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Origin", ctx, "1", get_ipv6_addressing_type, set_ipv6_addressing_type, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_ip_ping_diagnostic(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"IP.Diagnostics.IPPingDiagnostics.") { - DMOBJECT(DMROOT"IP.Diagnostics.IPPingDiagnostics.", ctx, "0", 0, NULL, NULL, NULL); - DMPARAM("DiagnosticsState", ctx, "1", get_ip_ping_diagnostics_state, set_ip_ping_diagnostics_state, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Interface", ctx, "1", get_ip_ping_interface, set_ip_ping_interface, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Host", ctx, "1", get_ip_ping_host, set_ip_ping_host, NULL, 0, 1, UNDEF, NULL); - DMPARAM("NumberOfRepetitions", ctx, "1", get_ip_ping_repetition_number, set_ip_ping_repetition_number, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("Timeout", ctx, "1", get_ip_ping_timeout, set_ip_ping_timeout, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DataBlockSize", ctx, "1", get_ip_ping_block_size, set_ip_ping_block_size, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - //DMPARAM("DSCP", ctx, "1", get_ipping_dscp, set_ipping_dscp, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("SuccessCount", ctx, "0", get_ip_ping_success_count, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("FailureCount", ctx, "0", get_ip_ping_failure_count, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("AverageResponseTime", ctx, "0", get_ip_ping_average_response_time, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MinimumResponseTime", ctx, "0", get_ip_ping_min_response_time, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaximumResponseTime", ctx, "0", get_ip_ping_max_response_time, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; +end: + return 0; } diff --git a/dm/dmtree/tr181/ip.h b/dm/dmtree/tr181/ip.h index 2905ac6..c47f0ba 100644 --- a/dm/dmtree/tr181/ip.h +++ b/dm/dmtree/tr181/ip.h @@ -15,16 +15,73 @@ extern struct ip_ping_diagnostic ipping_diagnostic; struct ip_args { struct uci_section *ip_sec; -}; - -struct ipv4_args -{ - struct uci_section *ipv4_sec; - char *ip_address; + char *ip_4address; char *ip_6address; }; +extern DMOBJ tIPObj[]; +extern DMOBJ tInterfaceObj[]; +extern DMLEAF tIPv4Params[]; +extern DMLEAF tIPv6Params[]; +extern DMLEAF tIPintParams[]; +extern DMLEAF tIpPingDiagParams[]; +extern DMOBJ tDiagnosticObj[]; +unsigned char get_ipv4_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance); +unsigned char get_ipv6_finform(char *refparam, struct dmctx *dmctx, void *data, char *instance); +int browseIPIfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseIfaceIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseIfaceIPv6Inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int entry_method_root_ip(struct dmctx *ctx); +int add_ip_interface(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_ip_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_ipv4(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_ipv4(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_ipv6(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_ipv6(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int get_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_interface_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_int_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipv6_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipv6_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ipv6_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_success_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_failure_count(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_average_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_min_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ip_ping_max_response_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_ip_int_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_int_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv4_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_firewall_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv4_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv4_netmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv4_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv6_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv6_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv6_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_diagnostics_state(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_repetition_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_ping_block_size(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ipv6_addressing_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ip_interface_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int get_linker_ip_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif diff --git a/dm/dmtree/tr181/nat.c b/dm/dmtree/tr181/nat.c index 97b555d..2f842e2 100644 --- a/dm/dmtree/tr181/nat.c +++ b/dm/dmtree/tr181/nat.c @@ -18,72 +18,59 @@ #include "dmcommon.h" #include "nat.h" -struct nat_args -{ - struct uci_section *int_sec; +/*** NAT. ***/ +DMOBJ tnatObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"InterfaceSetting", &DMREAD, NULL, NULL, NULL, browseInterfaceSettingInst, NULL, NULL, NULL, tInterfaceSettingParam, NULL}, +{0} }; -struct nat_args cur_nat_args = {0}; +/*** NAT.InterfaceSetting. ***/ +DMLEAF tInterfaceSettingParam[] = { +{"Enable", &DMREAD, DMT_BOOL, get_nat_enable, NULL, NULL, &DMNONE}, +{"Alias", &DMWRITE, DMT_STRING, get_nat_alias, set_nat_alias, NULL, &DMNONE}, +{"Interface", &DMREAD, DMT_STRING, get_nat_interface, NULL, NULL, &DMNONE}, +{0} +}; -inline int init_nat_args(struct dmctx *ctx, struct uci_section *int_sec) -{ - struct nat_args *args = &cur_nat_args; - ctx->args = (void *)args; - args->int_sec = int_sec; - return 0; -} -int get_nat_enable(char *refparam, struct dmctx *ctx, char **value) +int get_nat_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "1"; return 0; } -int get_nat_alias(char *refparam, struct dmctx *ctx, char **value) +int get_nat_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct nat_args *natargs = (struct nat_args *)ctx->args; - dmuci_get_value_by_section_string(natargs->int_sec, "natalias", value); + struct uci_section *int_sec = (struct uci_section *)data; + dmuci_get_value_by_section_string(int_sec, "natalias", value); return 0; } -int set_nat_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_nat_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct nat_args *natargs = (struct nat_args *)ctx->args; + struct uci_section *int_sec = (struct uci_section *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(natargs->int_sec, "natalias", value); + dmuci_set_value_by_section(int_sec, "natalias", value); return 0; } return 0; } -int get_nat_interface(char *refparam, struct dmctx *ctx, char **value) +int get_nat_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; - linker = dmstrdup(section_name(cur_nat_args.int_sec)); - adm_entry_get_linker_param(DMROOT"IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + linker = dmstrdup(section_name(((struct uci_section *)data))); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; dmfree(linker); return 0; } -/************************************************************* - * ENTRY METHOD -/*************************************************************/ -int entry_method_root_nat(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"NAT.") { - DMOBJECT(DMROOT"NAT.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"NAT.InterfaceSetting.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_nat, ctx); - return 0; - } - return FAULT_9005; -} - int get_nat_last_inst() { char *rinst = "0", *tmp; @@ -142,7 +129,12 @@ char *nat_update_instance_alias(int action, char **last_inst, void *argv[]) return instance; } -inline int entry_nat(struct dmctx *ctx) + +/************************************************************* + * ENTRY METHOD +/*************************************************************/ + +int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *net_sec = NULL, *s = NULL; char *nat = NULL; @@ -153,26 +145,14 @@ inline int entry_nat(struct dmctx *ctx) uci_foreach_list_cont("firewall", "zone", "network", section_name(net_sec), s) { dmuci_get_value_by_section_string(s, "masq", &nat); if(nat[0] == '1') { - nati = handle_update_instance(1, ctx, &nati_last, nat_update_instance_alias, 4, net_sec, "natinstance", "natalias", &find_max); - init_nat_args(ctx, net_sec); - SUBENTRY(entry_nat_instance, ctx, nati); + nati = handle_update_instance(1, dmctx, &nati_last, nat_update_instance_alias, 4, net_sec, "natinstance", "natalias", &find_max); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)net_sec, nati) == DM_STOP) + goto end; break; - } + } } - } + } +end: return 0; } - -inline int entry_nat_instance(struct dmctx *ctx, char *int_num) -{ - IF_MATCH(ctx, DMROOT"NAT.InterfaceSetting.%s.", int_num) { - DMOBJECT(DMROOT"NAT.InterfaceSetting.%s.", ctx, "0", NULL, NULL, NULL, NULL, int_num); - DMPARAM("Enable", ctx, "0", get_nat_enable, NULL, "xsd:boolean", 0, 0, UNDEF, NULL); - DMPARAM("Alias", ctx, "1", get_nat_alias, set_nat_alias, NULL, 0, 0, UNDEF, NULL); - DMPARAM("Interface", ctx, "0", get_nat_interface, NULL, NULL, 0, 0, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - diff --git a/dm/dmtree/tr181/nat.h b/dm/dmtree/tr181/nat.h index 911b1c6..3b35d45 100644 --- a/dm/dmtree/tr181/nat.h +++ b/dm/dmtree/tr181/nat.h @@ -11,6 +11,15 @@ #ifndef __NAT_H #define __NAT_H -int entry_method_root_nat(struct dmctx *ctx); +extern DMLEAF tInterfaceSettingParam[]; +extern DMOBJ tnatObj[]; + +int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_nat_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_nat_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_nat_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_nat_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dm/dmtree/tr181/ppp.c b/dm/dmtree/tr181/ppp.c index a9e7816..e2b3759 100644 --- a/dm/dmtree/tr181/ppp.c +++ b/dm/dmtree/tr181/ppp.c @@ -19,36 +19,60 @@ #include "dmcommon.h" #include "ppp.h" -struct ppp_args cur_ppp_args = {0}; +/*** PPP. ***/ +DMOBJ tpppObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Interface", &DMREAD, NULL, NULL, NULL, browseInterfaceInst, NULL, NULL, tpppInterfaceObj, tpppInterfaceParam, get_linker_ppp_interface}, +{0} +}; + +/*** PPP.Interface. ***/ +DMOBJ tpppInterfaceObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tStatsParam, NULL}, +{0} +}; + +DMLEAF tpppInterfaceParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_ppp_alias, set_ppp_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_ppp_enable, set_ppp_enable, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_ppp_name, NULL, NULL, NULL}, +{"LowerLayers", &DMWRITE, DMT_STRING, get_ppp_lower_layer, set_ppp_lower_layer, NULL, NULL}, +{"ConnectionStatus", &DMREAD, DMT_STRING, get_ppp_status, NULL, NULL, NULL}, +{"Username", &DMWRITE, DMT_STRING, get_ppp_username, set_ppp_username, NULL, NULL}, +{"Password", &DMWRITE, DMT_STRING, get_empty, set_ppp_password, NULL, NULL}, +{0} +}; + +/*** PPP.Interface.Stats. ***/ +DMLEAF tStatsParam[] = { +{"EthernetBytesReceived", &DMREAD, DMT_UNINT, get_ppp_eth_bytes_received, NULL, NULL, NULL}, +{"EthernetBytesSent", &DMWRITE, DMT_UNINT, get_ppp_eth_bytes_sent, NULL, NULL, NULL}, +{"EthernetPacketsReceived", &DMREAD, DMT_UNINT, get_ppp_eth_pack_received, NULL, NULL, NULL}, +{"EthernetPacketsSent", &DMREAD, DMT_UNINT, get_ppp_eth_pack_sent, NULL, NULL, NULL}, +{0} +}; + + -/************************************************************* - * INIT -/*************************************************************/ -inline int init_ppp_args(struct dmctx *ctx, struct uci_section *s) -{ - struct ppp_args *args = &cur_ppp_args; - ctx->args = (void *)args; - args->ppp_sec = s; - return 0; -} /************************************************************* * GET SET ALIAS /*************************************************************/ -int get_ppp_alias(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ppp_args.ppp_sec, "ppp_int_alias", value); + dmuci_get_value_by_section_string(((struct uci_section *)data), "ppp_int_alias", value); return 0; } -int set_ppp_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ppp_args.ppp_sec, "ppp_int_alias", value); + dmuci_set_value_by_section(((struct uci_section *)data), "ppp_int_alias", value); return 0; } return 0; @@ -58,23 +82,23 @@ int set_ppp_alias(char *refparam, struct dmctx *ctx, int action, char *value) * GET & SET PARAMETERS ***************************************************************************/ -int get_ppp_enable(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - return get_interface_enable_ubus(section_name(cur_ppp_args.ppp_sec), refparam, ctx, value); + return get_interface_enable_ubus(section_name(((struct uci_section *)data)), refparam, ctx, value); } -int set_ppp_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - return set_interface_enable_ubus(section_name(cur_ppp_args.ppp_sec), refparam, ctx, action, value); + return set_interface_enable_ubus(section_name(((struct uci_section *)data)), refparam, ctx, action, value); } -int get_ppp_name(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmstrdup(section_name(cur_ppp_args.ppp_sec)); + *value = dmstrdup(section_name(((struct uci_section *)data))); return 0; } -int get_ppp_status(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status = NULL; char *uptime = NULL; @@ -82,7 +106,7 @@ int get_ppp_status(char *refparam, struct dmctx *ctx, char **value) json_object *res = NULL, *jobj = NULL; bool bstatus = false, bpend = false; - dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(cur_ppp_args.ppp_sec), String}}, 1, &res); + dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res); DM_ASSERT(res, *value = ""); jobj = dmjson_get_obj(res, 1, "up"); if(jobj) @@ -104,41 +128,41 @@ int get_ppp_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_ppp_username(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ppp_args.ppp_sec, "username", value); + dmuci_get_value_by_section_string(((struct uci_section *)data), "username", value); return 0; } -int set_ppp_username(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ppp_args.ppp_sec, "username", value); + dmuci_set_value_by_section(((struct uci_section *)data), "username", value); return 0; } return 0; } -int set_ppp_password(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ppp_args.ppp_sec, "password", value); + dmuci_set_value_by_section(((struct uci_section *)data), "password", value); return 0; } return 0; } -inline int ubus_get_wan_stats(json_object *res, char **value, char *stat_mod) +inline int ubus_get_wan_stats(void *data, char *instance, json_object *res, char **value, char *stat_mod) { char *ifname, *proto; - dmuci_get_value_by_section_string(cur_ppp_args.ppp_sec, "ifname", &ifname); - dmuci_get_value_by_section_string(cur_ppp_args.ppp_sec, "proto", &proto); + dmuci_get_value_by_section_string(((struct uci_section *)data), "ifname", &ifname); + dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto); if (strcmp(proto, "pppoe") == 0) { dmubus_call("network.device", "status", UBUS_ARGS{{"name", ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); @@ -147,78 +171,83 @@ inline int ubus_get_wan_stats(json_object *res, char **value, char *stat_mod) return 0; } -int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_get_wan_stats(res, value, "rx_bytes"); + ubus_get_wan_stats(data, instance, res, value, "rx_bytes"); return 0; } -int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_get_wan_stats(res, value, "tx_bytes"); + ubus_get_wan_stats(data, instance, res, value, "tx_bytes"); return 0; } -int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_get_wan_stats(res, value, "rx_packets"); + ubus_get_wan_stats(data, instance, res, value, "rx_packets"); return 0; } -int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_get_wan_stats(res, value, "tx_packets"); + ubus_get_wan_stats(data, instance, res, value, "tx_packets"); return 0; } -int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, char **value) +int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker; - dmuci_get_value_by_section_string(cur_ppp_args.ppp_sec, "ifname", &linker); - adm_entry_get_linker_param(DMROOT"ATM.Link.", linker, value); - if (*value == NULL) - adm_entry_get_linker_param(DMROOT"PTM.Link.", linker, value); - if (*value == NULL) - adm_entry_get_linker_param(DMROOT"Ethernet.Interface.", linker, value); - if (*value == NULL) - adm_entry_get_linker_param(DMROOT"WiFi.SSID.", linker, value); + dmuci_get_value_by_section_string(((struct uci_section *)data), "ifname", &linker); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cATM%cLink%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cPTM%cLink%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); + } + if (*value == NULL) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cEthernet%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); + } + if (*value == NULL) { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); + } if (*value == NULL) *value = ""; return 0; } -int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker; switch (action) { case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); - dmuci_set_value_by_section(cur_ppp_args.ppp_sec, "ifname", linker); + adm_entry_get_linker_value(ctx, value, &linker); + dmuci_set_value_by_section(((struct uci_section *)data), "ifname", linker); return 0; } return 0; } +/************************************************************************** +* LINKER +***************************************************************************/ +int get_linker_ppp_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + + if(((struct uci_section *)data)) { + dmasprintf(linker,"%s", section_name(((struct uci_section *)data))); + return 0; + } + *linker = ""; + return 0; +} + /************************************************************* * ENTRY METHOD /*************************************************************/ -int entry_method_root_ppp(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"PPP.") { - DMOBJECT(DMROOT"PPP.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"PPP.Interface.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_ppp_interface, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_ppp_interface(struct dmctx *ctx) +int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *net_sec = NULL; char *ppp_int = NULL, *ppp_int_last = NULL; @@ -228,32 +257,11 @@ inline int entry_ppp_interface(struct dmctx *ctx) dmuci_get_value_by_section_string(net_sec, "proto", &proto); if (!strstr(proto, "ppp")) continue; - init_ppp_args(ctx, net_sec); - ppp_int = handle_update_instance(1, ctx, &ppp_int_last, update_instance_alias, 3, net_sec, "ppp_int_instance", "ppp_int_alias"); - SUBENTRY(entry_ppp_interface_instance, ctx, ppp_int); + ppp_int = handle_update_instance(1, dmctx, &ppp_int_last, update_instance_alias, 3, net_sec, "ppp_int_instance", "ppp_int_alias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)net_sec, ppp_int) == DM_STOP) + break; } return 0; } -inline int entry_ppp_interface_instance(struct dmctx *ctx, char *int_num) -{ - IF_MATCH(ctx, DMROOT"PPP.Interface.%s.", int_num) { - char linker[32] = ""; - strcat(linker, section_name(cur_ppp_args.ppp_sec)); - DMOBJECT(DMROOT"PPP.Interface.%s.", ctx, "0", 1, NULL, NULL, linker, int_num); - DMPARAM("Alias", ctx, "1", get_ppp_alias, set_ppp_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_ppp_enable, set_ppp_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_ppp_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LowerLayers", ctx, "1", get_ppp_lower_layer, set_ppp_lower_layer, NULL, 0, 1, UNDEF, NULL);//TODO - DMPARAM("ConnectionStatus", ctx, "0", get_ppp_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Username", ctx, "1", get_ppp_username, set_ppp_username, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Password", ctx, "1", get_empty, set_ppp_password, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"PPP.Interface.%s.Stats.", ctx, "0", 1, NULL, NULL, NULL, int_num); - DMPARAM("EthernetBytesReceived", ctx, "0", get_ppp_eth_bytes_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetBytesSent", ctx, "0", get_ppp_eth_bytes_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPacketsReceived", ctx, "0", get_ppp_eth_pack_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("EthernetPacketsSent", ctx, "0", get_ppp_eth_pack_sent,NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} + diff --git a/dm/dmtree/tr181/ppp.h b/dm/dmtree/tr181/ppp.h index dddf6fb..854c9cf 100644 --- a/dm/dmtree/tr181/ppp.h +++ b/dm/dmtree/tr181/ppp.h @@ -11,11 +11,29 @@ #ifndef __PPP_H #define __PPP_H -struct ppp_args -{ - struct uci_section *ppp_sec; -}; +extern DMLEAF tpppInterfaceParam[]; +extern DMLEAF tStatsParam[]; +extern DMOBJ tpppInterfaceObj[]; +extern DMOBJ tpppObj[]; -int entry_method_root_ppp(struct dmctx *ctx); +int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int get_linker_ppp_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif diff --git a/dm/dmtree/tr181/routing.c b/dm/dmtree/tr181/routing.c index 235ced4..7a8ba3b 100644 --- a/dm/dmtree/tr181/routing.c +++ b/dm/dmtree/tr181/routing.c @@ -24,14 +24,50 @@ enum enum_route_type { ROUTE_DISABLED }; -struct routingfwdargs cur_routefwdargs = {0}; -struct router_args cur_router_args = {0}; +/*** Routing. ***/ +DMOBJ tRoutingObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Router", &DMREAD, NULL, NULL, NULL, browseRouterInst, NULL, NULL, tRouterObj, tRouterInstParam, NULL}, +{0} +}; -inline int entry_router_ipv4forwarding_instance(struct dmctx *ctx, char *irouter, char *iroute, char *permission); -inline int init_args_ipv4forward(struct dmctx *ctx, struct uci_section *s, char *permission, struct proc_routing *proute, int type) +DMLEAF tRoutingParam[] = { +{"RouterNumberOfEntries", &DMREAD, DMT_UNINT, get_router_nbr_entry, NULL, NULL, NULL}, +{0} +}; + +/*** Routing.Router. ***/ +DMOBJ tRouterObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"IPv4Forwarding", &DMREAD, NULL, NULL, NULL, browseIPv4ForwardingInst, NULL, NULL, NULL, tIPv4ForwardingParam, NULL}, +{0} +}; +DMLEAF tRouterInstParam[] = { +{"Alias", &DMWRITE, DMT_STRING, get_router_alias, set_router_alias, NULL, NULL}, +{0} +}; + +/*** Routing.Router.IPv4Forwarding. ***/ +DMLEAF tIPv4ForwardingParam[] = { +{"Enable", &DMRouting, DMT_BOOL, get_router_ipv4forwarding_enable, set_router_ipv4forwarding_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_router_ipv4forwarding_status, NULL, NULL, NULL}, +{"Alias", &DMWRITE, DMT_STRING, get_router_ipv4forwarding_alias, set_router_ipv4forwarding_alias, NULL, NULL}, +{"DestIPAddress", &DMRouting, DMT_STRING, get_router_ipv4forwarding_destip, set_router_ipv4forwarding_destip, NULL, NULL}, +{"DestSubnetMask", &DMRouting, DMT_STRING, get_router_ipv4forwarding_destmask, set_router_ipv4forwarding_destmask, NULL, NULL}, +{"SourceIPAddress", &DMREAD, DMT_STRING, get_router_ipv4forwarding_src_address, NULL, NULL, NULL}, +{"SourceSubnetMask", &DMREAD, DMT_STRING, get_router_ipv4forwarding_src_mask, NULL, NULL, NULL}, +{"GatewayIPAddress", &DMRouting, DMT_STRING, get_router_ipv4forwarding_gatewayip, set_router_ipv4forwarding_gatewayip, NULL, NULL}, +{"Interface", &DMRouting, DMT_STRING, get_router_ipv4forwarding_interface_linker_parameter, set_router_ipv4forwarding_interface_linker_parameter, NULL, NULL}, +{"ForwardingMetric", &DMRouting, DMT_STRING, get_router_ipv4forwarding_metric, set_router_ipv4forwarding_metric, NULL, NULL}, +{0} +}; + + +/******************************** + * inti function + ********************************/ +inline int init_args_ipv4forward(struct routingfwdargs *args, struct uci_section *s, char *permission, struct proc_routing *proute, int type) { - struct routingfwdargs *args = &cur_routefwdargs; - ctx->args = (void *)args; args->permission = permission; args->routefwdsection = s; args->proute = proute; @@ -39,13 +75,6 @@ inline int init_args_ipv4forward(struct dmctx *ctx, struct uci_section *s, char return 0; } -inline int init_router_args(struct dmctx *ctx, struct uci_section *section) -{ - struct router_args *args = &cur_router_args; - ctx->args = (void *)args; - args->router_section = section; - return 0; -} /************************************************************************************* **** function related to get_object_router_ipv4forwarding **** **************************************************************************************/ @@ -58,38 +87,6 @@ void ip_to_hex(char *address, char *ret) //TODO Move to the common.c sprintf(ret, "%02X%02X%02X%02X", ip[0], ip[1], ip[2], ip[3]); } -void hex_to_ip(char *address, char *ret) //TODO Move to the common.c -{ - int i; - int ip[4] = {0}; - sscanf(address, "%2x%2x%2x%2x", &(ip[0]), &(ip[1]), &(ip[2]), &(ip[3])); - if (htonl(13) == 13) { - sprintf(ret, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); - } else { - sprintf(ret, "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); - } -} - -void parse_proc_route_line(char *line, struct proc_routing *proute) -{ - char *pch, *spch; - proute->iface = strtok_r(line, " \t", &spch); - - pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->destination); - pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->gateway); - proute->flags = strtok_r(NULL, " \t", &spch); - proute->refcnt = strtok_r(NULL, " \t", &spch); - proute->use = strtok_r(NULL, " \t", &spch); - proute->metric = strtok_r(NULL, " \t", &spch); - pch = strtok_r(NULL, " \t", &spch); - hex_to_ip(pch, proute->mask); - proute->mtu = strtok_r(NULL, " \t", &spch); - proute->window = strtok_r(NULL, " \t", &spch); - proute->irtt = strtok_r(NULL, " \t\n\r", &spch); -} - bool is_proute_static(struct proc_routing *proute) { char *mask; @@ -228,9 +225,9 @@ struct uci_section *update_route_dynamic_section(struct proc_routing *proute) return s; } -int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection == NULL) { *value = "1"; @@ -244,11 +241,11 @@ int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; char *pch; - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -272,9 +269,9 @@ int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection == NULL) { *value = "Enabled"; @@ -291,9 +288,9 @@ int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, char **v return 0; } -int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "target", value); @@ -308,9 +305,9 @@ int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -322,9 +319,9 @@ int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "netmask", value); @@ -339,9 +336,9 @@ int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, char * return 0; } -int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -353,21 +350,21 @@ int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, int ac return 0; } -int get_router_ipv4forwarding_src_address(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_src_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0.0.0.0"; return 0; } -int get_router_ipv4forwarding_src_mask(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_src_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "0.0.0.0"; return 0; } -int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "gateway", value); @@ -382,9 +379,9 @@ int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, char return 0; } -int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -396,13 +393,13 @@ int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, int a return 0; } -char *get_router_ipv4forwarding_interface(struct dmctx *ctx) +char *get_router_ipv4forwarding_interface(struct dmctx *ctx, void *data, char *instance) { json_object *res; char *val, *bval, *ifname, *device; char *name; struct uci_section *ss; - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "interface", &val); @@ -432,14 +429,14 @@ char *get_router_ipv4forwarding_interface(struct dmctx *ctx) return ""; } -int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *iface, *linker; - iface = get_router_ipv4forwarding_interface(ctx); + iface = get_router_ipv4forwarding_interface(ctx, data, instance); if (iface[0] != '\0') { dmasprintf(&linker, "%s", iface); - adm_entry_get_linker_param(DMROOT"IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cIP%cInterface%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; dmfree(linker); @@ -447,16 +444,16 @@ int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct return 0; } -int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *linker; - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: return 0; case VALUESET: - adm_entry_get_linker_value(value, &linker); + adm_entry_get_linker_value(ctx, value, &linker); if (linker) { dmuci_set_value_by_section(routeargs->routefwdsection, "interface", linker); dmfree(linker); @@ -466,10 +463,10 @@ int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct return 0; } -int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *name; - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; if (routeargs->routefwdsection != NULL) { dmuci_get_value_by_section_string(routeargs->routefwdsection, "metric", value); @@ -484,9 +481,9 @@ int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, char **v return 0; } -int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { - struct routingfwdargs *routeargs = (struct routingfwdargs *)ctx->args; + struct routingfwdargs *routeargs = (struct routingfwdargs *)data; switch (action) { case VALUECHECK: @@ -498,7 +495,7 @@ int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, int acti return 0; } -int get_router_nbr_entry(char *refparam, struct dmctx *ctx, char **value) +int get_router_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { struct uci_section *s; int cnt = 0; @@ -535,48 +532,56 @@ int get_router_nbr_entry(char *refparam, struct dmctx *ctx, char **value) * SET AND GET ALIAS FOR ROUTER OBJ /*************************************************************/ -int get_router_alias(char *refparam, struct dmctx *ctx, char **value) +int get_router_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_router_args.router_section, "router_alias", value); + dmuci_get_value_by_section_string((struct uci_section *)data, "router_alias", value); return 0; } -int set_router_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_router_args.router_section, "router_alias", value); + dmuci_set_value_by_section((struct uci_section *)data, "router_alias", value); return 0; } return 0; } -int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, char **value) +int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; - if (cur_routefwdargs.routefwdsection) dmuci_get_value_by_section_string(cur_routefwdargs.routefwdsection, "routealias", value); + if (((struct routingfwdargs *)data)->routefwdsection) dmuci_get_value_by_section_string(((struct routingfwdargs *)data)->routefwdsection, "routealias", value); return 0; } -int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - if (cur_routefwdargs.routefwdsection) dmuci_set_value_by_section(cur_routefwdargs.routefwdsection, "routealias", value); + if (((struct routingfwdargs *)data)->routefwdsection) dmuci_set_value_by_section(((struct routingfwdargs *)data)->routefwdsection, "routealias", value); return 0; } return 0; } +char *get_routing_perm(char *refparam, struct dmctx *dmctx, void *data, char *instance) +{ + return ((struct routingfwdargs *)data)->permission; +} + +struct dm_permession_s DMRouting = {"0", &get_routing_perm}; + + /************************************************************* * SUB ENTRIES /*************************************************************/ -inline int entry_router_ipv4forwarding(struct dmctx *ctx, char *irouter) +int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *iroute = NULL, *iroute_last = NULL; char *permission = "1"; @@ -585,15 +590,19 @@ inline int entry_router_ipv4forwarding(struct dmctx *ctx, char *irouter) char line[MAX_PROC_ROUTING]; struct proc_routing proute = {0}; bool find_max = true; + struct routingfwdargs curr_routefwdargs = {0}; + uci_foreach_sections("network", "route", s) { - init_args_ipv4forward(ctx, s, "1", NULL, ROUTE_STATIC); - iroute = handle_update_instance(1, ctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); - SUBENTRY(entry_router_ipv4forwarding_instance, ctx, irouter, iroute, permission); + init_args_ipv4forward(&curr_routefwdargs, s, "1", NULL, ROUTE_STATIC); + iroute = handle_update_instance(1, dmctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, iroute) == DM_STOP) + goto end; } uci_foreach_sections("network", "route_disabled", s) { - init_args_ipv4forward(ctx, s, "1", NULL, ROUTE_DISABLED); - iroute = handle_update_instance(1, ctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); - SUBENTRY(entry_router_ipv4forwarding_instance, ctx, irouter, iroute, permission); + init_args_ipv4forward(&curr_routefwdargs, s, "1", NULL, ROUTE_DISABLED); + iroute = handle_update_instance(1, dmctx, &iroute_last, forwarding_update_instance_alias, 4, s, "routeinstance", "routealias", &find_max); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, iroute) == DM_STOP) + goto end; } fp = fopen(ROUTING_FILE, "r"); if ( fp != NULL) @@ -607,72 +616,27 @@ inline int entry_router_ipv4forwarding(struct dmctx *ctx, char *irouter) if (is_proute_static(&proute)) continue; ss = update_route_dynamic_section(&proute); - init_args_ipv4forward(ctx, ss, "0", &proute, ROUTE_DYNAMIC); - iroute = handle_update_instance(1, ctx, &iroute_last, forwarding_update_instance_alias, 4, ss, "routeinstance", "routealias", &find_max); - SUBENTRY(entry_router_ipv4forwarding_instance, ctx, irouter, iroute, "0"); + init_args_ipv4forward(&curr_routefwdargs, ss, "0", &proute, ROUTE_DYNAMIC); + iroute = handle_update_instance(1, dmctx, &iroute_last, forwarding_update_instance_alias, 4, ss, "routeinstance", "routealias", &find_max); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, iroute) == DM_STOP) + goto end; } fclose(fp) ; } +end: return 0; } -inline int entry_method_router(struct dmctx *ctx) +int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { struct uci_section *s = NULL; char *r = NULL, *r_last = NULL; update_section_list(DMMAP,"router", NULL, 1, NULL, NULL, NULL, NULL, NULL); uci_path_foreach_sections(icwmpd, "dmmap", "router", s) { - init_router_args(ctx, s); - r = handle_update_instance(1, ctx, &r_last, update_instance_alias_icwmpd, 3, s, "router_instance", "router_alias"); - SUBENTRY(entry_method_root_router_sub, ctx, r); - return 0; - } - return FAULT_9005; -} - -inline int entry_router_ipv4forwarding_instance(struct dmctx *ctx, char *irouter, char *iroute, char *permission) -{ - IF_MATCH(ctx, DMROOT"Routing.Router.%s.IPv4Forwarding.%s.", irouter, iroute) { - DMOBJECT(DMROOT"Routing.Router.%s.IPv4Forwarding.%s.", ctx, "0", 1, NULL, NULL, NULL, irouter, iroute); - DMPARAM("Enable", ctx, permission, get_router_ipv4forwarding_enable, set_router_ipv4forwarding_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_router_ipv4forwarding_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Alias", ctx, "1", get_router_ipv4forwarding_alias, set_router_ipv4forwarding_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DestIPAddress", ctx, permission, get_router_ipv4forwarding_destip, set_router_ipv4forwarding_destip, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DestSubnetMask", ctx, permission, get_router_ipv4forwarding_destmask, set_router_ipv4forwarding_destmask, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceIPAddress", ctx, "0", get_router_ipv4forwarding_src_address, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SourceSubnetMask", ctx, "0", get_router_ipv4forwarding_src_mask, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("GatewayIPAddress", ctx, permission, get_router_ipv4forwarding_gatewayip, set_router_ipv4forwarding_gatewayip, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Interface", ctx, permission, get_router_ipv4forwarding_interface_linker_parameter, set_router_ipv4forwarding_interface_linker_parameter, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ForwardingMetric", ctx, permission, get_router_ipv4forwarding_metric, set_router_ipv4forwarding_metric, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -int entry_method_root_routing(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"Routing.") { - DMOBJECT(DMROOT"Routing.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"Routing.Router.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("RouterNumberOfEntries", ctx, "0", get_router_nbr_entry, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - SUBENTRY(entry_method_router, ctx); - return 0; - } - return FAULT_9005; -} - -int entry_method_root_router_sub(struct dmctx *ctx, char *irouter) -{ - IF_MATCH(ctx, DMROOT"Routing.Router.%s.", irouter) { - DMOBJECT(DMROOT"Routing.Router.%s.", ctx, "0", 1, NULL, NULL, NULL, irouter); - DMPARAM("Alias", ctx, "1", get_router_alias, set_router_alias, NULL, 0, 1, UNDEF, NULL); //TODO - DMOBJECT(DMROOT"Routing.Router.%s.IPv4Forwarding.", ctx, "0", 1, NULL, NULL, NULL, irouter); - SUBENTRY(entry_router_ipv4forwarding, ctx, irouter); + r = handle_update_instance(1, dmctx, &r_last, update_instance_alias_icwmpd, 3, s, "router_instance", "router_alias"); + DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, r); + break; } return 0; } - - - - diff --git a/dm/dmtree/tr181/routing.h b/dm/dmtree/tr181/routing.h index fd7a5b1..f011de1 100644 --- a/dm/dmtree/tr181/routing.h +++ b/dm/dmtree/tr181/routing.h @@ -1,35 +1,37 @@ #ifndef __ROUTING_H #define __ROUTING_H -#define ROUTING_FILE "/proc/net/route" -#define MAX_PROC_ROUTING 256 -struct proc_routing { - char *iface; - char *flags; - char *refcnt; - char *use; - char *metric; - char *mtu; - char *window; - char *irtt; - char destination[16]; - char gateway[16]; - char mask[16]; -}; +extern struct dm_permession_s DMRouting; -struct routingfwdargs -{ - char *permission; - struct uci_section *routefwdsection; - struct proc_routing *proute; - int type; -}; +extern DMLEAF tRouterInstParam[]; +extern DMLEAF tIPv4ForwardingParam[]; +extern DMOBJ tRoutingObj[]; +extern DMLEAF tRoutingParam[]; +extern DMOBJ tRouterObj[]; -struct router_args -{ - struct uci_section *router_section; -}; +int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); -int entry_method_root_routing(struct dmctx *ctx); +int get_router_nbr_entry(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_src_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_src_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_router_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_router_ipv4forwarding_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_router_ipv4forwarding_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_router_ipv4forwarding_destip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_router_ipv4forwarding_destmask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_router_ipv4forwarding_gatewayip(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_router_ipv4forwarding_interface_linker_parameter(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_router_ipv4forwarding_metric(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_router_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dm/dmtree/tr181/wan.c b/dm/dmtree/tr181/wan.c index 5018e69..a8fa784 100644 --- a/dm/dmtree/tr181/wan.c +++ b/dm/dmtree/tr181/wan.c @@ -17,33 +17,177 @@ #include "wan.h" #include "dmjson.h" -struct dsl_line_args cur_dsl_line_args = {0}; -struct dsl_channel_args cur_dsl_channel_args = {0}; -struct atm_args cur_atm_args = {0}; -struct ptm_args cur_ptm_args = {0}; +/*** DSL. ***/ +DMOBJ tDslObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Line", &DMREAD, NULL, NULL, NULL, browseDslLineInst, NULL, NULL, NULL, tDslLineParams, get_dsl_line_linker}, +{"Channel", &DMREAD, NULL, NULL, NULL, browseDslChannelInst, NULL, NULL, NULL, tDslChanelParams, get_dsl_channel_linker}, +{0} +}; -inline int init_dsl_link(struct dmctx *ctx, struct uci_section *s, char *type) +/*** ATM. ***/ +DMOBJ tAtmObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Link", &DMWRITE, add_atm_link, delete_atm_link, NULL, browseAtmLinkInst, NULL, NULL, tAtmLinkStatsObj, tAtmLineParams, get_atm_linker}, +{0} +}; + +/*** PTM. ***/ +DMOBJ tPtmObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Link", &DMWRITE, add_ptm_link, delete_ptm_link, NULL, browsePtmLinkInst, NULL, NULL, tPtmLinkStatsObj, tPtmLineParams, get_ptm_linker}, +{0} +}; + +/*** DSL.Line ***/ +DMLEAF tDslLineParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_dsl_link_alias, set_dsl_link_alias, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_line_name, NULL, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_dsl_status, NULL, NULL, NULL}, +{"LinkStatus", &DMREAD, DMT_STRING,get_dsl_link_status, NULL, NULL, NULL}, +{"StandardsSupported", &DMREAD, DMT_STRING, get_dsl_link_supported_standard, NULL, NULL, NULL}, +{"StandardUsed", &DMREAD, DMT_STRING, get_dsl_link_standard_inuse, NULL, NULL, NULL}, +{"AllowedProfiles", &DMREAD, DMT_STRING, get_vdsl_link_supported_profile, NULL, NULL, NULL}, +{"CurrentProfile", &DMREAD, DMT_STRING, get_vdsl_link_profile_inuse, NULL, NULL, NULL}, +{"DownstreamMaxBitRate", &DMREAD, DMT_UNINT, get_dsl_link_downstreammaxrate, NULL, NULL, NULL}, +{"DownstreamAttenuation", &DMREAD, DMT_INT, get_dsl_link_downstreamattenuation, NULL, NULL, NULL}, +{"DownstreamNoiseMargin", &DMREAD, DMT_INT, get_dsl_link_downstreamnoisemargin, NULL, NULL, NULL}, +{"UpstreamMaxBitRate", &DMREAD, DMT_UNINT, get_dsl_link_upstreammaxrate, NULL, NULL, NULL}, +{"UpstreamAttenuation", &DMREAD, DMT_INT, get_dsl_link_upstreamattenuation, NULL, NULL, NULL}, +{"UpstreamNoiseMargin", &DMREAD, DMT_INT, get_dsl_link_upstreamnoisemargin, NULL, NULL, NULL}, +{0} +}; + +/*** DSL.Channel ***/ +DMLEAF tDslChanelParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_channel_alias, set_channel_alias, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_dsl_status, NULL, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_line_name, NULL, NULL, NULL}, +{"LowerLayers", &DMREAD, DMT_STRING, get_channel_lower_layer, NULL, NULL, NULL}, +{"DownstreamCurrRate", &DMREAD, DMT_UNINT, get_dsl_channel_downstreamcurrrate, NULL, NULL, NULL}, +{"UpstreamCurrRate", &DMREAD, DMT_UNINT, get_dsl_channel_upstreamcurrrate, NULL, NULL, NULL}, +{"X_INTENO_SE_AnnexMEnable", &DMWRITE, DMT_BOOL, get_channel_annexm_status, set_channel_annexm_status, NULL, NULL}, +{"LinkEncapsulationSupported", &DMREAD, DMT_STRING, get_channel_supported_encap, NULL, NULL, NULL}, +{"LinkEncapsulationUsed", &DMREAD, DMT_STRING, get_empty, NULL, NULL, NULL}, +{0} +}; + +/*** ATM.Link. ***/ + +DMOBJ tAtmLinkStatsObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tAtmLinkStatsParams, NULL}, +{0} +}; + +DMLEAF tAtmLineParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_atm_alias, set_atm_alias, NULL, NULL}, +{"Enable", &DMREAD, DMT_BOOL, get_atm_enable, NULL, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_atm_link_name, NULL, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_atm_enable, NULL, NULL, NULL}, +{"LowerLayers", &DMREAD, DMT_STRING, get_atm_lower_layer, NULL, NULL, NULL}, +{"LinkType", &DMWRITE, DMT_STRING, get_atm_link_type, set_atm_link_type, NULL, NULL}, +{"DestinationAddress", &DMWRITE, DMT_STRING, get_atm_destination_address, set_atm_destination_address, NULL, NULL}, +{"Encapsulation", &DMWRITE, DMT_STRING, get_atm_encapsulation, set_atm_encapsulation, NULL, NULL}, +{0} +}; + +/*** ATM.Link.Stats. ***/ +DMLEAF tAtmLinkStatsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"BytesSent", &DMREAD, DMT_UNINT, get_atm_stats_bytes_sent, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_atm_stats_bytes_received, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_atm_stats_pack_sent, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_atm_stats_pack_received, NULL, NULL, NULL}, +{0} +}; + +/*** PTM.Link. ***/ +DMOBJ tPtmLinkStatsObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf, linker*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tPtmLinkStatsParams, NULL}, +{0} +}; + +DMLEAF tPtmLineParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_ptm_alias, set_ptm_alias, NULL, NULL}, +{"Enable", &DMREAD, DMT_BOOL, get_ptm_enable, NULL, NULL, NULL}, +{"Name", &DMREAD, DMT_STRING, get_ptm_link_name, NULL, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_ptm_enable, NULL, NULL, NULL}, +{"LowerLayers", &DMREAD, DMT_STRING, get_ptm_lower_layer, NULL, NULL, NULL}, +{0} +}; + +/*** PTM.Link.Stats. ***/ +DMLEAF tPtmLinkStatsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"BytesSent", &DMREAD, DMT_UNINT, get_ptm_stats_bytes_sent, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_ptm_stats_bytes_received, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_ptm_stats_pack_sent, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_ptm_stats_pack_received, NULL, NULL, NULL}, +{0} +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if (((struct atm_args *)data)->ifname) { + *linker = ((struct atm_args *)data)->ifname; + return 0; + } + *linker = "" ; + return 0; +} + +int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if (((struct ptm_args *)data)->ifname){ + *linker = ((struct ptm_args *)data)->ifname; + return 0; + } + *linker = "" ; + return 0; +} +int get_dsl_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if (((struct dsl_line_args *)data)->type) { + *linker = ((struct dsl_line_args *)data)->type; + return 0; + } + *linker = "" ; + return 0; +} + +int get_dsl_channel_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if (((struct dsl_line_args *)data)->type){ + *linker = ((struct dsl_line_args *)data)->type; + return 0; + } + *linker = "" ; + return 0; +} +/************************************************************************** +* INIT +***************************************************************************/ +inline int init_dsl_link(struct dsl_line_args *args, struct uci_section *s, char *type) { - struct dsl_line_args *args = &cur_dsl_line_args; - ctx->args = (void *)args; args->line_sec = s; args->type = type; return 0; } -inline int init_atm_link(struct dmctx *ctx, struct uci_section *s, char *ifname) +inline int init_atm_link(struct atm_args *args, struct uci_section *s, char *ifname) { - struct atm_args *args = &cur_atm_args; - ctx->args = (void *)args; args->atm_sec = s; args->ifname = ifname; return 0; } -inline int init_ptm_link(struct dmctx *ctx, struct uci_section *s, char *ifname) +inline int init_ptm_link(struct ptm_args *args, struct uci_section *s, char *ifname) { - struct ptm_args *args = &cur_ptm_args; - ctx->args = (void *)args; args->ptm_sec = s; args->ifname = ifname; return 0; @@ -53,13 +197,13 @@ inline int init_ptm_link(struct dmctx *ctx, struct uci_section *s, char *ifname) * SET & GET DSL LINK PARAMETERS ***************************************************************************/ -int get_dsl_status(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status; json_object *res; *value = "Down"; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if(strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = ""); status = dmjson_get_value(res, 2, "dslstats", "status"); @@ -71,13 +215,13 @@ int get_dsl_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_dsl_link_status(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *status; json_object *res; *value = "NoSignal"; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if(strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = ""); status = dmjson_get_value(res, 2, "dslstats", "status"); @@ -95,34 +239,36 @@ int get_dsl_link_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int get_dsl_link_supported_standard(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "G.992.1_Annex_A, G.992.2, T1.413, G.992.3_Annex_A, G.992.3_Annex_L, G.992.5_Annex_A, G.992.5_Annex_M"; return 0; } -int get_dsl_link_standard_inuse(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_standard_inuse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *mode; json_object *res = NULL; - - dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - mode = dmjson_get_value(res, 2, "dslstats", "mode"); - if (strcmp(mode, "G.Dmt") == 0) - *value = "G.992.1_Annex_A"; // TO CHECK - else if (strcmp(mode, "G.lite") == 0) - *value = "G.992.2"; - else if (strcmp(mode, "T1.413") == 0) - *value = "T1.413"; - else if (strcmp(mode, "ADSL2") == 0) - *value = "G.992.3_Annex_A"; - else if (strcmp(mode, "AnnexL") == 0) - *value = "G.992.3_Annex_L"; - else if (strcmp(mode, "ADSL2+") == 0) - *value = "G.992.5_Annex_A"; - else - *value = mode; + *value = ""; + if(strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0) { + dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + mode = dmjson_get_value(res, 2, "dslstats", "mode"); + if (strcmp(mode, "G.Dmt") == 0) + *value = "G.992.1_Annex_A"; // TO CHECK + else if (strcmp(mode, "G.lite") == 0) + *value = "G.992.2"; + else if (strcmp(mode, "T1.413") == 0) + *value = "T1.413"; + else if (strcmp(mode, "ADSL2") == 0) + *value = "G.992.3_Annex_A"; + else if (strcmp(mode, "AnnexL") == 0) + *value = "G.992.3_Annex_L"; + else if (strcmp(mode, "ADSL2+") == 0) + *value = "G.992.5_Annex_A"; + else + *value = mode; + } return 0; } @@ -138,32 +284,34 @@ int check_dsl_link_type() return 1; return 0; } -int get_vdsl_link_supported_profile(char *refparam, struct dmctx *ctx, char **value) +int get_vdsl_link_supported_profile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "8a, 8b, 8c, 8d, 12a, 12b, 17a, 17b, 30a"; return 0; } -int get_vdsl_link_profile_inuse(char *refparam, struct dmctx *ctx, char **value) +int get_vdsl_link_profile_inuse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *mode; json_object *res = NULL; - - dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); - DM_ASSERT(res, *value = ""); - mode = dmjson_get_value(res, 2, "dslstats", "mode"); - *value = mode; + *value = ""; + if (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0) { + dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + mode = dmjson_get_value(res, 2, "dslstats", "mode"); + *value = mode; + } return 0; } -int get_dsl_link_downstreammaxrate(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_downstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *max_down; json_object *res = NULL; json_object *sub_obj = NULL; json_object *sub_obj_2 = NULL; *value = ""; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); sub_obj = dmjson_get_obj(res, 1, "dslstats"); @@ -181,12 +329,12 @@ int get_dsl_link_downstreammaxrate(char *refparam, struct dmctx *ctx, char **val return 0; } -int get_dsl_link_downstreamattenuation(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_downstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *attn_down_x100; json_object *res = NULL; *value = ""; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); attn_down_x100 = dmjson_get_value(res, 2, "dslstats", "attn_down_x100"); @@ -198,12 +346,12 @@ int get_dsl_link_downstreamattenuation(char *refparam, struct dmctx *ctx, char * return 0; } -int get_dsl_link_downstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_downstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *snr_down_x100; json_object *res; *value = ""; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); snr_down_x100 = dmjson_get_value(res, 2, "dslstats", "snr_down_x100"); @@ -215,14 +363,14 @@ int get_dsl_link_downstreamnoisemargin(char *refparam, struct dmctx *ctx, char * return 0; } -int get_dsl_link_upstreammaxrate(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_upstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *max_up; json_object *res = NULL; json_object *sub_obj = NULL; json_object *sub_obj_2 = NULL; *value = ""; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); sub_obj = dmjson_get_obj(res, 1, "dslstats"); @@ -238,12 +386,12 @@ int get_dsl_link_upstreammaxrate(char *refparam, struct dmctx *ctx, char **value return 0; } -int get_dsl_link_upstreamattenuation(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_upstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *attn_up_x100; json_object *res = NULL; *value = ""; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); attn_up_x100 = dmjson_get_value(res, 2, "dslstats", "attn_up_x100"); @@ -255,12 +403,12 @@ int get_dsl_link_upstreamattenuation(char *refparam, struct dmctx *ctx, char **v return 0; } -int get_dsl_link_upstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_upstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *snr_up_x100; json_object *res; *value = ""; - if(strcmp(cur_dsl_line_args.type, "adsl") == 0 && check_dsl_link_type() == 1 || strcmp(cur_dsl_line_args.type, "vdsl") == 0 && check_dsl_link_type() == 0) { + if((strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0 && check_dsl_link_type() == 1) || (strcmp(((struct dsl_line_args *)data)->type, "vdsl") == 0 && check_dsl_link_type() == 0)) { dmubus_call("router.dsl", "stats", UBUS_ARGS{}, 0, &res); DM_ASSERT(res, *value = "0"); snr_up_x100 = dmjson_get_value(res, 2, "dslstats", "snr_up_x100"); @@ -275,15 +423,15 @@ int get_dsl_link_upstreamnoisemargin(char *refparam, struct dmctx *ctx, char **v return 0; } -int get_channel_lower_layer(char *refparam, struct dmctx *ctx, char **value) +int get_channel_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - adm_entry_get_linker_param(DMROOT"DSL.Line.", cur_dsl_line_args.type, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cLine%c", DMROOT, dm_delim, dm_delim, dm_delim), ((struct dsl_line_args *)data)->type, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; return 0; } -int get_dsl_channel_downstreamcurrrate(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_channel_downstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *rate_down; json_object *res = NULL; @@ -306,7 +454,7 @@ int get_dsl_channel_downstreamcurrrate(char *refparam, struct dmctx *ctx, char * return 0; } -int get_dsl_channel_upstreamcurrrate(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_channel_upstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *rate_up; json_object *res = NULL; @@ -327,11 +475,11 @@ int get_dsl_channel_upstreamcurrrate(char *refparam, struct dmctx *ctx, char **v return 0; } -int get_channel_annexm_status(char *refparam, struct dmctx *ctx, char **value) +int get_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *val = "0"; *value = ""; - if (strcmp(cur_dsl_line_args.type, "adsl") == 0) { + if (strcmp(((struct dsl_line_args *)data)->type, "adsl") == 0) { dmuci_get_option_value_string("layer2_interface", "capabilities", "AnnexM", &val); if (val[0] != '\0') { if (strcasecmp(val, "enabled") == 0) { @@ -343,12 +491,10 @@ int get_channel_annexm_status(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_channel_annexm_status(char *refparam, struct dmctx *ctx, int action, char *value) +int set_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; - struct wanargs *wandargs = (struct wanargs *)ctx->args; - switch (action) { case VALUECHECK: if (string_to_bool(value, &b)) @@ -366,28 +512,27 @@ int set_channel_annexm_status(char *refparam, struct dmctx *ctx, int action, cha return 0; } -int get_channel_supported_encap(char *refparam, struct dmctx *ctx, char **value) +int get_channel_supported_encap(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "G.992.3_Annex_K_ATM, G.992.3_Annex_K_PTM, G.993.2_Annex_K_ATM, G.993.2_Annex_K_PTM, G.994.1"; return 0; } -int get_atm_destination_address(char *refparam, struct dmctx *ctx, char **value) +int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *vpi, *vci; - dmuci_get_value_by_section_string(cur_atm_args.atm_sec, "vpi", &vpi); - dmuci_get_value_by_section_string(cur_atm_args.atm_sec, "vci", &vci); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "vpi", &vpi); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "vci", &vci); dmasprintf(value, "PVC: %s/%s", vpi, vci); // MEM WILL BE FREED IN DMMEMCLEAN return 0; } -int set_atm_destination_address(char *refparam, struct dmctx *ctx, int action, char *value) +int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { char *vpi = NULL, *vci = NULL, *spch, *val; struct uci_section *s; - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; switch (action) { case VALUECHECK: @@ -403,8 +548,8 @@ int set_atm_destination_address(char *refparam, struct dmctx *ctx, int action, c vci = strtok_r(NULL, "/", &spch); } if (vpi && vci) { - dmuci_set_value_by_section(cur_atm_args.atm_sec, "vpi", vpi); - dmuci_set_value_by_section(cur_atm_args.atm_sec, "vci", vci); + dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "vpi", vpi); + dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "vci", vci); } dmfree(val); break; @@ -413,23 +558,23 @@ int set_atm_destination_address(char *refparam, struct dmctx *ctx, int action, c return 0; } -int get_atm_link_name(char *refparam, struct dmctx *ctx, char **value) +int get_atm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_atm_args.atm_sec, "name", value); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "name", value); return 0; } -int get_ptm_link_name(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ptm_args.ptm_sec, "name", value); + dmuci_get_value_by_section_string(((struct ptm_args *)data)->ptm_sec, "name", value); return 0; } -int get_atm_encapsulation(char *refparam, struct dmctx *ctx, char **value) +int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *type, *encapsulation; - dmuci_get_value_by_section_string(cur_atm_args.atm_sec,"link_type", &type); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec,"link_type", &type); if (strcmp(type, "EoA") == 0 ) { type = "encapseoa"; } else if (strcmp(type, "PPPoA") == 0) { @@ -437,7 +582,7 @@ int get_atm_encapsulation(char *refparam, struct dmctx *ctx, char **value) } else if (strcmp(type, "IPoA") == 0) { type = "encapsipoa"; } - dmuci_get_value_by_section_string(cur_atm_args.atm_sec, type, &encapsulation); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, type, &encapsulation); if (strstr(encapsulation, "vcmux")) { *value = "VCMUX"; } @@ -449,18 +594,17 @@ int get_atm_encapsulation(char *refparam, struct dmctx *ctx, char **value) return 0; } -int set_atm_encapsulation(char *refparam, struct dmctx *ctx, int action, char *value) +int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { int i; struct uci_section *s; char *type, *encapsulation, *encaptype, *pch; - struct wancdevargs *wandcdevargs = (struct wancdevargs *)ctx->args; switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_get_value_by_section_string(cur_atm_args.atm_sec, "link_type", &type); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "link_type", &type); int enc; if (strstr(value, "VCMUX")) { enc = 1; @@ -485,138 +629,138 @@ int set_atm_encapsulation(char *refparam, struct dmctx *ctx, int action, char *v else return 0; - dmuci_set_value_by_section(cur_atm_args.atm_sec, encaptype, encapsulation); + dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, encaptype, encapsulation); return 0; } return 0; } -int get_atm_link_type(char *refparam, struct dmctx *ctx, char **value) +int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = ""; - dmuci_get_value_by_section_string(cur_atm_args.atm_sec, "link_type", value); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "link_type", value); return 0; } -int set_atm_link_type(char *refparam, struct dmctx *ctx, int action, char *value) +int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_atm_args.atm_sec, "link_type", value); + dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "link_type", value); return 0; } return 0; } -int get_atm_lower_layer(char *refparam, struct dmctx *ctx, char **value) +int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker = "adsl"; - adm_entry_get_linker_param(DMROOT"DSL.Channel.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cChannel%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; return 0; } -int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { char *linker = "vdsl"; - adm_entry_get_linker_param(DMROOT"DSL.Channel.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + adm_entry_get_linker_param(ctx, dm_print_path("%s%cDSL%cChannel%c", DMROOT, dm_delim, dm_delim, dm_delim), linker, value); // MEM WILL BE FREED IN DMMEMCLEAN if (*value == NULL) *value = ""; return 0; } -inline int ubus_atm_stats(json_object *res, char **value, char *stat_mod) +inline int ubus_atm_stats(json_object *res, char **value, char *stat_mod, void *data) { - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_atm_args.ifname, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct atm_args *)data)->ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", stat_mod); return 0; } -int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, char **value) +int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_atm_stats(res, value, "rx_bytes"); + ubus_atm_stats(res, value, "rx_bytes", data); return 0; } -int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, char **value) +int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_atm_stats(res, value, "tx_bytes"); + ubus_atm_stats(res, value, "tx_bytes", data); return 0; } -int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, char **value) +int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_atm_stats(res, value, "rx_packets"); + ubus_atm_stats(res, value, "rx_packets", data); return 0; } -int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, char **value) +int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_atm_stats(res, value, "tx_packets"); + ubus_atm_stats(res, value, "tx_packets", data); return 0; } -inline int ubus_ptm_stats(json_object *res, char **value, char *stat_mod) +inline int ubus_ptm_stats(json_object *res, char **value, char *stat_mod, void *data) { - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_ptm_args.ifname, String}}, 1, &res); + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct ptm_args *)data)->ifname, String}}, 1, &res); DM_ASSERT(res, *value = ""); *value = dmjson_get_value(res, 2, "statistics", stat_mod); return 0; } -int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_ptm_stats(res, value, "rx_bytes"); + ubus_ptm_stats(res, value, "rx_bytes", data); return 0; } -int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_ptm_stats(res, value, "tx_bytes"); + ubus_ptm_stats(res, value, "tx_bytes", data); return 0; } -int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_ptm_stats(res, value, "rx_packets"); + ubus_ptm_stats(res, value, "rx_packets", data); return 0; } -int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { json_object *res; - ubus_ptm_stats(res, value, "tx_packets"); + ubus_ptm_stats(res, value, "tx_packets", data); return 0; } -int get_line_name(char *refparam, struct dmctx *ctx, char **value) +int get_line_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = dmstrdup(cur_dsl_line_args.type); + *value = dmstrdup(((struct dsl_line_args *)data)->type); return 0; } -int get_atm_enable(char *refparam, struct dmctx *ctx, char **value) +int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "true"; return 0; } -int get_ptm_enable(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = "true"; return 0; @@ -624,7 +768,7 @@ int get_ptm_enable(char *refparam, struct dmctx *ctx, char **value) /************************************************************* * ADD OBJ /*************************************************************/ -int add_atm_link(struct dmctx *ctx, char **instancepara) +int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { int idx; char *value; @@ -650,7 +794,7 @@ int add_atm_link(struct dmctx *ctx, char **instancepara) return 0; } -int add_ptm_link(struct dmctx *ctx, char **instancepara) +int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara) { int idx; char *value; @@ -672,7 +816,7 @@ int add_ptm_link(struct dmctx *ctx, char **instancepara) return 0; } -int delete_atm_link_all(struct dmctx *ctx) +int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { struct uci_section *s = NULL; struct uci_section *ss = NULL; @@ -680,8 +824,84 @@ int delete_atm_link_all(struct dmctx *ctx) struct uci_section *ns = NULL; struct uci_section *nss = NULL; char *ifname; - uci_foreach_sections("layer2_interface_adsl", "atm_bridge", s) { - if (ss){ + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(((struct atm_args *)data)->atm_sec, NULL, NULL); + uci_foreach_option_cont("network", "interface", "ifname", ((struct atm_args *)data)->ifname, s) { + if (ss) + wan_remove_dev_interface(ss, ((struct atm_args *)data)->ifname); + ss = s; + } + if (ss != NULL) + wan_remove_dev_interface(ss, ((struct atm_args *)data)->ifname); + break; + case DEL_ALL: + uci_foreach_sections("layer2_interface_adsl", "atm_bridge", s) { + if (ss){ + dmuci_get_value_by_section_string(ss, "ifname", &ifname); + dmuci_delete_by_section(ss, NULL, NULL); + uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { + if (nss) + wan_remove_dev_interface(nss, ifname); + nss = ns; + } + if (nss != NULL) + wan_remove_dev_interface(nss, ifname); + } + ss = s; + } + if (ss != NULL) { + dmuci_get_value_by_section_string(ss, "ifname", &ifname); + dmuci_delete_by_section(ss, NULL, NULL); + uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { + if (nss) + wan_remove_dev_interface(nss, ifname); + nss = ns; + } + if (nss != NULL) + wan_remove_dev_interface(nss, ifname); + } + break; + } + return 0; +} + +int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) +{ + char *ifname; + struct uci_section *s = NULL; + struct uci_section *ss = NULL; + + struct uci_section *ns = NULL; + struct uci_section *nss = NULL; + + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(((struct ptm_args *)data)->ptm_sec, NULL, NULL); + uci_foreach_option_cont("network", "interface", "ifname", ((struct ptm_args *)data)->ifname, s) { + if (ss) + wan_remove_dev_interface(ss, ((struct ptm_args *)data)->ifname); + ss = s; + } + if (ss != NULL) + wan_remove_dev_interface(ss, ((struct ptm_args *)data)->ifname); + break; + case DEL_ALL: + uci_foreach_sections("layer2_interface_vdsl", "vdsl_interface", s) { + if (ss){ + dmuci_get_value_by_section_string(ss, "ifname", &ifname); + dmuci_delete_by_section(ss, NULL, NULL); + uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { + if (nss) + wan_remove_dev_interface(nss, ifname); + nss = ns; + } + if (nss != NULL) + wan_remove_dev_interface(nss, ifname); + } + ss = s; + } + if (ss != NULL) { dmuci_get_value_by_section_string(ss, "ifname", &ifname); dmuci_delete_by_section(ss, NULL, NULL); uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { @@ -692,330 +912,147 @@ int delete_atm_link_all(struct dmctx *ctx) if (nss != NULL) wan_remove_dev_interface(nss, ifname); } - ss = s; + break; } - if (ss != NULL) { - dmuci_get_value_by_section_string(ss, "ifname", &ifname); - dmuci_delete_by_section(ss, NULL, NULL); - - uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { - if (nss) - wan_remove_dev_interface(nss, ifname); - nss = ns; - } - if (nss != NULL) - wan_remove_dev_interface(nss, ifname); - } return 0; -} - -int delete_atm_link(struct dmctx *ctx) -{ - struct uci_section *s = NULL; - struct uci_section *ss = NULL; - struct uci_section *ns = NULL; - struct uci_section *nss = NULL; - char *ifname; - - dmuci_delete_by_section(cur_atm_args.atm_sec, NULL, NULL); - uci_foreach_option_cont("network", "interface", "ifname", cur_atm_args.ifname, s) { - if (ss) - wan_remove_dev_interface(ss, cur_atm_args.ifname); - ss = s; - } - if (ss != NULL) - wan_remove_dev_interface(ss, cur_atm_args.ifname); - return 0; -} - -int delete_ptm_link_all(struct dmctx *ctx) -{ - struct uci_section *s = NULL; - struct uci_section *ss = NULL; - struct uci_section *ns = NULL; - struct uci_section *nss = NULL; - char *ifname; - - uci_foreach_sections("layer2_interface_vdsl", "vdsl_interface", s) { - if (ss){ - dmuci_get_value_by_section_string(ss, "ifname", &ifname); - dmuci_delete_by_section(ss, NULL, NULL); - uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { - if (nss) - wan_remove_dev_interface(nss, ifname); - nss = ns; - } - if (nss != NULL) - wan_remove_dev_interface(nss, ifname); - } - ss = s; - } - if (ss != NULL) { - dmuci_get_value_by_section_string(ss, "ifname", &ifname); - dmuci_delete_by_section(ss, NULL, NULL); - - uci_foreach_option_cont("network", "interface", "ifname", ifname, ns) { - if (nss) - wan_remove_dev_interface(nss, ifname); - nss = ns; - } - if (nss != NULL) - wan_remove_dev_interface(nss, ifname); - } - return 0; -} - -int delete_ptm_link(struct dmctx *ctx) -{ - struct uci_section *s = NULL; - struct uci_section *ss = NULL; - - dmuci_delete_by_section(cur_ptm_args.ptm_sec, NULL, NULL); - uci_foreach_option_cont("network", "interface", "ifname", cur_ptm_args.ifname, s) { - if (ss) - wan_remove_dev_interface(ss, cur_ptm_args.ifname); - ss = s; - } - if (ss != NULL) - wan_remove_dev_interface(ss, cur_ptm_args.ifname); return 0; } /************************************************************* * SET AND GET ALIAS /*************************************************************/ -int get_dsl_link_alias(char *refparam, struct dmctx *ctx, char **value) +int get_dsl_link_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dsl_line_args.line_sec, "dsllinkalias", value); + dmuci_get_value_by_section_string(((struct dsl_line_args *)data)->line_sec, "dsllinkalias", value); return 0; } -int set_dsl_link_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_dsl_link_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dsl_line_args.line_sec, "dsllinkalias", value); + dmuci_set_value_by_section(((struct dsl_line_args *)data)->line_sec, "dsllinkalias", value); return 0; } return 0; } -int get_channel_alias(char *refparam, struct dmctx *ctx, char **value) +int get_channel_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_dsl_line_args.line_sec, "channelalias", value); + dmuci_get_value_by_section_string(((struct dsl_line_args *)data)->line_sec, "channelalias", value); return 0; } -int set_channel_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_channel_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_dsl_line_args.line_sec, "channelalias", value); + dmuci_set_value_by_section(((struct dsl_line_args *)data)->line_sec, "channelalias", value); return 0; } return 0; } -int get_atm_alias(char *refparam, struct dmctx *ctx, char **value) +int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_atm_args.atm_sec, "atmlinkalias", value); + dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "atmlinkalias", value); return 0; } -int set_atm_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_atm_args.atm_sec, "atmlinkalias", value); + dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "atmlinkalias", value); return 0; } return 0; } -int get_ptm_alias(char *refparam, struct dmctx *ctx, char **value) +int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string(cur_ptm_args.ptm_sec, "ptmlinkalias", value); + dmuci_get_value_by_section_string(((struct ptm_args *)data)->ptm_sec, "ptmlinkalias", value); return 0; } -int set_ptm_alias(char *refparam, struct dmctx *ctx, int action, char *value) +int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: return 0; case VALUESET: - dmuci_set_value_by_section(cur_ptm_args.ptm_sec, "ptmlinkalias", value); + dmuci_set_value_by_section(((struct ptm_args *)data)->ptm_sec, "ptmlinkalias", value); return 0; } return 0; } + /************************************************************* - * SUB ENTRIES + * ENTRY METHOD /*************************************************************/ -int entry_method_root_wan_dsl(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"DSL.") { - DMOBJECT(DMROOT"DSL.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"DSL.Line.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"DSL.Channel.", ctx, "0", 0, NULL, NULL, NULL); - SUBENTRY(entry_dsl_link, ctx); - return 0; - } - return FAULT_9005; -} -int entry_method_root_wan_atm(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"ATM.") { - DMOBJECT(DMROOT"ATM.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"ATM.Link.", ctx, "0", 0, add_atm_link, delete_atm_link_all, NULL); - SUBENTRY(entry_atm_link, ctx); - return 0; - } - return FAULT_9005; -} - -int entry_method_root_wan_ptm(struct dmctx *ctx) -{ - IF_MATCH(ctx, DMROOT"PTM.") { - DMOBJECT(DMROOT"PTM.", ctx, "0", 0, NULL, NULL, NULL); - DMOBJECT(DMROOT"PTM.Link.", ctx, "0", 0, add_ptm_link, delete_ptm_link_all, NULL); - SUBENTRY(entry_ptm_link, ctx); - return 0; - } - return FAULT_9005; -} - -inline int entry_dsl_link(struct dmctx *ctx) +int browseDslLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *wnum_last = NULL, *channel_last = NULL, *type; struct uci_section *s = NULL; + struct dsl_line_args curr_dsl_line_args = {0}; + uci_foreach_sections("layer2_interface", "dsltype", s) { - init_dsl_link(ctx, s, section_name(s)); - wnum = handle_update_instance(1, ctx, &wnum_last, update_instance_alias, 3, s, "dsllinkinstance", "dsllinkalias"); - SUBENTRY(entry_dsl_line_instance, ctx, wnum); - wnum = handle_update_instance(1, ctx, &channel_last, update_instance_alias, 3, s, "channelinstance", "channelalias"); - SUBENTRY(entry_dsl_channel_instance, ctx, wnum); + init_dsl_link(&curr_dsl_line_args, s, section_name(s)); + wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, s, "dsllinkinstance", "dsllinkalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dsl_line_args, wnum) == DM_STOP) + break; } return 0; } -inline int entry_atm_link(struct dmctx *ctx) +int browseDslChannelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + char *wnum = NULL, *wnum_last = NULL, *channel_last = NULL, *type; + struct uci_section *s = NULL; + struct dsl_line_args curr_dsl_line_args = {0}; + + uci_foreach_sections("layer2_interface", "dsltype", s) { + init_dsl_link(&curr_dsl_line_args, s, section_name(s)); + wnum = handle_update_instance(1, dmctx, &channel_last, update_instance_alias, 3, s, "channelinstance", "channelalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dsl_line_args, wnum) == DM_STOP) + break; + } + return 0; +} + +int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *wnum_last = NULL, *channel_last = NULL, *ifname; struct uci_section *s = NULL; + struct atm_args curr_atm_args = {0}; + uci_foreach_sections("layer2_interface_adsl", "atm_bridge", s) { dmuci_get_value_by_section_string(s, "ifname", &ifname); - init_atm_link(ctx, s, ifname); - wnum = handle_update_instance(1, ctx, &channel_last, update_instance_alias, 3, s, "atmlinkinstance", "atmlinkalias"); - SUBENTRY(entry_atm_link_instance, ctx, wnum); + init_atm_link(&curr_atm_args, s, ifname); + wnum = handle_update_instance(1, dmctx, &channel_last, update_instance_alias, 3, s, "atmlinkinstance", "atmlinkalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_atm_args, wnum) == DM_STOP) + break; } return 0; } -inline int entry_ptm_link(struct dmctx *ctx) +int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *wnum_last = NULL, *channel_last = NULL, *ifname; struct uci_section *s = NULL; + struct ptm_args curr_ptm_args = {0}; + uci_foreach_sections("layer2_interface_vdsl", "vdsl_interface", s) { dmuci_get_value_by_section_string(s, "ifname", &ifname); - init_ptm_link(ctx, s, ifname); - wnum = handle_update_instance(1, ctx, &channel_last, update_instance_alias, 3, s, "ptmlinkinstance", "ptmlinkalias"); //finish here - SUBENTRY(entry_ptm_link_instance, ctx, wnum); + init_ptm_link(&curr_ptm_args, s, ifname); + wnum = handle_update_instance(1, dmctx, &channel_last, update_instance_alias, 3, s, "ptmlinkinstance", "ptmlinkalias"); //finish here + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ptm_args, wnum) == DM_STOP) + break; } return 0; } -inline int entry_dsl_line_instance(struct dmctx *ctx, char *dev) -{ - IF_MATCH(ctx, DMROOT"DSL.Line.%s.", dev) { - char linker[8]; - strcpy(linker, cur_dsl_line_args.type); - DMOBJECT(DMROOT"DSL.Line.%s.", ctx, "0", NULL, NULL, NULL, linker, dev); - DMPARAM("Alias", ctx, "1", get_dsl_link_alias, set_dsl_link_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_line_name, NULL, NULL, 0, 1, UNDEF, NULL); - if (strcmp(cur_dsl_line_args.type, "adsl") == 0) { - DMPARAM("Status", ctx, "0", get_dsl_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LinkStatus", ctx, "0", get_dsl_link_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("StandardsSupported", ctx, "0", get_dsl_link_supported_standard, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("StandardUsed", ctx, "0", get_dsl_link_standard_inuse, NULL, NULL, 0, 1, UNDEF, NULL); - } else if (strcmp(cur_dsl_line_args.type, "vdsl") == 0) { - DMPARAM("Status", ctx, "0", get_dsl_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LinkStatus", ctx, "0", get_dsl_link_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("AllowedProfiles", ctx, "0", get_vdsl_link_supported_profile, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("CurrentProfile", ctx, "0", get_vdsl_link_profile_inuse, NULL, NULL, 0, 1, UNDEF, NULL); - } - DMPARAM("DownstreamMaxBitRate", ctx, "0", get_dsl_link_downstreammaxrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("DownstreamAttenuation", ctx, "0", get_dsl_link_downstreamattenuation, NULL, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("DownstreamNoiseMargin", ctx, "0", get_dsl_link_downstreamnoisemargin, NULL, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamMaxBitRate", ctx, "0", get_dsl_link_upstreammaxrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamAttenuation", ctx, "0", get_dsl_link_upstreamattenuation, NULL, "xsd:int", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamNoiseMargin", ctx, "0", get_dsl_link_upstreamnoisemargin, NULL, "xsd:int", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_dsl_channel_instance(struct dmctx *ctx, char *dev) -{ - IF_MATCH(ctx, DMROOT"DSL.Channel.%s.", dev) { - char linker[8]; - strcpy(linker, cur_dsl_line_args.type); - DMOBJECT(DMROOT"DSL.Channel.%s.", ctx, "0", NULL, NULL, NULL, linker, dev); - DMPARAM("Alias", ctx, "1", get_channel_alias, set_channel_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_dsl_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_line_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LowerLayers", ctx, "0", get_channel_lower_layer, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DownstreamCurrRate", ctx, "0", get_dsl_channel_downstreamcurrrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("UpstreamCurrRate", ctx, "0", get_dsl_channel_upstreamcurrrate, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_AnnexMEnable", ctx, "1", get_channel_annexm_status, set_channel_annexm_status, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("LinkEncapsulationSupported", ctx, "0", get_channel_supported_encap, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LinkEncapsulationUsed", ctx, "0", get_empty, NULL, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_atm_link_instance(struct dmctx *ctx, char *idev) -{ - IF_MATCH(ctx, DMROOT"ATM.Link.%s.", idev) { - DMOBJECT(DMROOT"ATM.Link.%s.", ctx, "1", NULL, NULL, delete_atm_link, cur_atm_args.ifname, idev); - DMPARAM("Alias", ctx, "1", get_atm_alias, set_atm_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "0", get_atm_enable, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_atm_link_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_atm_enable, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LowerLayers", ctx, "0", get_atm_lower_layer, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LinkType", ctx, "1", get_atm_link_type, set_atm_link_type, NULL, 0, 1, UNDEF, NULL); - DMPARAM("DestinationAddress", ctx, "1", get_atm_destination_address, set_atm_destination_address, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Encapsulation", ctx, "1", get_atm_encapsulation, set_atm_encapsulation, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"ATM.Link.%s.Stats.", ctx, "1", 1, NULL, NULL, NULL, idev); - DMPARAM("BytesSent", ctx, "0", get_atm_stats_bytes_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_atm_stats_bytes_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_atm_stats_pack_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_atm_stats_pack_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_ptm_link_instance(struct dmctx *ctx, char *idev) -{ - IF_MATCH(ctx, DMROOT"PTM.Link.%s.", idev) { - DMOBJECT(DMROOT"PTM.Link.%s.", ctx, "1", NULL, NULL, delete_ptm_link, cur_ptm_args.ifname, idev); - DMPARAM("Alias", ctx, "1", get_ptm_alias, set_ptm_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "0", get_ptm_enable, NULL, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "0", get_ptm_link_name, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_ptm_enable, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LowerLayers", ctx, "0", get_ptm_lower_layer, NULL, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"PTM.Link.%s.Stats.", ctx, "1", 1, NULL, NULL, NULL, idev); - DMPARAM("BytesSent", ctx, "0", get_ptm_stats_bytes_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_ptm_stats_bytes_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_ptm_stats_pack_sent, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_ptm_stats_pack_received, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} diff --git a/dm/dmtree/tr181/wan.h b/dm/dmtree/tr181/wan.h index cba689e..77c15a4 100644 --- a/dm/dmtree/tr181/wan.h +++ b/dm/dmtree/tr181/wan.h @@ -18,11 +18,6 @@ struct dsl_line_args char *type; }; -struct dsl_channel_args -{ - struct uci_section *chanel_sec; -}; - struct atm_args { struct uci_section *atm_sec; @@ -33,8 +28,80 @@ struct ptm_args struct uci_section *ptm_sec; char *ifname; }; -int entry_method_root_wan_dsl(struct dmctx *ctx); -int entry_method_root_wan_ptm(struct dmctx *ctx); -int entry_method_root_wan_atm(struct dmctx *ctx); +extern DMOBJ tDslObj[]; +extern DMOBJ tAtmObj[]; +extern DMOBJ tPtmObj[]; +extern DMOBJ tAtmLinkStatsObj[]; +extern DMOBJ tPtmLinkStatsObj[]; +extern DMLEAF tDslLineParams[]; +extern DMLEAF tDslChanelParams[] ; +extern DMLEAF tAtmLineParams[]; +extern DMLEAF tAtmLinkStatsParams[] ; +extern DMLEAF tPtmLinkStatsParams[]; +extern DMLEAF tPtmLineParams[]; + +int browseDslLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseDslChannelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); + +int get_dsl_link_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_line_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_standard_inuse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vdsl_link_supported_profile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_vdsl_link_profile_inuse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_downstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_downstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_downstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_upstreammaxrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_upstreamattenuation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_link_upstreamnoisemargin(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_channel_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_channel_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_channel_downstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_dsl_channel_upstreamcurrrate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_channel_supported_encap(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_atm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_stats_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_stats_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ptm_stats_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_dsl_link_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_channel_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_channel_annexm_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int get_dsl_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +int get_dsl_channel_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); #endif diff --git a/dm/dmtree/tr181/wifi.c b/dm/dmtree/tr181/wifi.c index d50935f..b8a5659 100644 --- a/dm/dmtree/tr181/wifi.c +++ b/dm/dmtree/tr181/wifi.c @@ -17,967 +17,182 @@ #include "dmcwmp.h" #include "dmcommon.h" #include "wifi.h" - #include "dmjson.h" #define DELIMITOR "," -struct wifi_radio_args cur_wifi_radio_args = {0}; -struct wifi_ssid_args cur_wifi_ssid_args = {0}; -inline int entry_wifi_radio(struct dmctx *ctx); +/*** WiFi. ***/ +DMOBJ tWifiObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Radio", &DMWRITE, NULL, NULL, NULL, browseWifiRadioInst, NULL, NULL, tWifiRadioStatsObj, tWifiRadioParams, get_linker_Wifi_Radio}, +{"SSID", &DMWRITE, add_wifi_ssid, delete_wifi_ssid, NULL, browseWifiSsidInst, NULL, NULL, tWifiSsidStatsObj, tWifiSsidParams, get_linker_Wifi_Ssid}, +{"AccessPoint", &DMREAD, NULL, NULL, NULL, browseWifiAccessPointInst, NULL, NULL, tAcessPointSecurityObj, tWifiAcessPointParams, NULL}, +{0} +}; -inline int init_wifi_radio(struct dmctx *ctx, struct uci_section *s) +DMLEAF tWifiParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"X_INTENO_SE_Bandsteering_Enable", &DMWRITE, DMT_BOOL, get_wifi_bandsteering_enable, set_wifi_bandsteering_enable, NULL, NULL}, +{0} +}; + +/*** WiFi.Radio. ***/ +DMOBJ tWifiRadioStatsObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWifiRadioStatsParams, NULL}, +{0} +}; + +DMLEAF tWifiRadioParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_radio_alias, set_radio_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_radio_enable, set_radio_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_radio_status, NULL, NULL, NULL}, +{"MaxBitRate", &DMWRITE, DMT_STRING,get_radio_max_bit_rate, set_radio_max_bit_rate, NULL, NULL}, +{"OperatingFrequencyBand", &DMREAD, DMT_STRING, get_radio_frequency, NULL, NULL, NULL}, +{"SupportedFrequencyBands", &DMREAD, DMT_STRING, get_radio_supported_frequency_bands, NULL, NULL, NULL}, +{"OperatingChannelBandwidth", &DMWRITE, DMT_STRING, get_radio_operating_channel_bandwidth, set_radio_operating_channel_bandwidth, NULL, NULL}, +{"X_INTENO_SE_MaxAssociations", &DMWRITE, DMT_STRING, get_radio_maxassoc, set_radio_maxassoc, NULL, NULL}, +{"X_INTENO_SE_DFSEnable", &DMWRITE, DMT_BOOL, get_radio_dfsenable, set_radio_dfsenable, NULL, NULL}, +{"SupportedStandards", &DMREAD, DMT_STRING, get_radio_supported_standard, NULL, NULL, NULL}, +{"OperatingStandards", &DMWRITE, DMT_STRING, get_radio_operating_standard, set_radio_operating_standard, NULL, NULL}, +{"ChannelsInUse", &DMREAD, DMT_STRING, get_radio_channel, NULL, NULL, NULL}, +{"Channel", &DMWRITE, DMT_UNINT, get_radio_channel, set_radio_channel, NULL, NULL}, +{"AutoChannelEnable", &DMWRITE, DMT_BOOL, get_radio_auto_channel_enable, set_radio_auto_channel_enable, NULL, NULL}, +{"PossibleChannels", &DMREAD, DMT_STRING, get_radio_possible_channels, NULL, NULL, NULL}, +{0} +}; + +/*** WiFi.Radio.Stats. ***/ +DMLEAF tWifiRadioStatsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"BytesSent", &DMREAD, DMT_UNINT, get_radio_statistics_tx_bytes, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_radio_statistics_rx_bytes, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_radio_statistics_tx_packets, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_radio_statistics_rx_packets, NULL, NULL, NULL}, +{0} +}; + +/*** WiFi.SSID. ***/ +DMOBJ tWifiSsidStatsObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, nextobj, leaf*/ +{"Stats", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWifiSsidStatsParams, NULL}, +{0} +}; + + +DMLEAF tWifiSsidParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_ssid_alias, set_ssid_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_wifi_enable, set_wifi_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_wifi_status, NULL, NULL, NULL}, +{"SSID", &DMWRITE, DMT_STRING, get_wlan_ssid, set_wlan_ssid, NULL, NULL}, +{"Name", &DMWRITE, DMT_STRING, get_wlan_ssid, set_wlan_ssid, NULL, NULL}, +{"LowerLayers", &DMWRITE, DMT_STRING, get_ssid_lower_layer, set_ssid_lower_layer, NULL, NULL}, +{"BSSID", &DMREAD, DMT_STRING, get_wlan_bssid, NULL, NULL, NULL}, +{0} +}; + +/*** WiFi.SSID.Stats. ***/ +DMLEAF tWifiSsidStatsParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, NOTIFICATION, linker*/ +{"BytesSent", &DMREAD, DMT_UNINT, get_ssid_statistics_tx_bytes, NULL, NULL, NULL}, +{"BytesReceived", &DMREAD, DMT_UNINT, get_ssid_statistics_rx_bytes, NULL, NULL, NULL}, +{"PacketsSent", &DMREAD, DMT_UNINT, get_ssid_statistics_tx_packets, NULL, NULL, NULL}, +{"PacketsReceived", &DMREAD, DMT_UNINT, get_ssid_statistics_rx_packets, NULL, NULL, NULL}, +{0} +}; + +/*** WiFi.AccessPoint. ***/ + +DMOBJ tAcessPointSecurityObj[] = { +/* OBJ, permission, addobj, delobj, browseinstobj, finform, notification, nextobj, leaf*/ +{"Security", &DMWRITE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tWifiAcessPointSecurityParams, NULL}, +{0} +}; + +DMLEAF tWifiAcessPointParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"Alias", &DMWRITE, DMT_STRING, get_access_point_alias, set_access_point_alias, NULL, NULL}, +{"Enable", &DMWRITE, DMT_BOOL, get_wifi_enable, set_wifi_enable, NULL, NULL}, +{"Status", &DMREAD, DMT_STRING, get_wifi_status, NULL, NULL, NULL}, +{"SSIDReference", &DMREAD, DMT_STRING, get_ap_ssid_ref, NULL, NULL, NULL}, +{"SSIDAdvertisementEnabled", &DMWRITE, DMT_BOOL, get_wlan_ssid_advertisement_enable, set_wlan_ssid_advertisement_enable, NULL, NULL}, +{"WMMEnable", &DMWRITE, DMT_BOOL, get_wmm_enabled, set_wmm_enabled, NULL, NULL}, +{"AssociatedDeviceNumberOfEntries", &DMREAD, DMT_UNINT, get_access_point_total_associations, NULL, NULL, NULL}, +{"MaxAssociatedDevices", &DMWRITE, DMT_UNINT, get_access_point_maxassoc, set_access_point_maxassoc, NULL, NULL}, +{"MACAddressControlEnabled", &DMWRITE, DMT_BOOL, get_access_point_control_enable, set_access_point_control_enable, NULL, NULL}, +{0} +}; + +/*** WiFi.AccessPoint.Security. ***/ +DMLEAF tWifiAcessPointSecurityParams[] = { +/* PARAM, permission, type, getvlue, setvalue, forced_inform, notification*/ +{"ModesSupported", &DMREAD, DMT_STRING, get_access_point_security_supported_modes, NULL, NULL, NULL}, +{"ModeEnabled", &DMWRITE, DMT_STRING ,get_access_point_security_modes, set_access_point_security_modes, NULL, NULL}, +{"WEPKey", &DMWRITE, DMT_STRING, get_empty, set_access_point_security_wepkey, NULL, NULL}, +{"PreSharedKey", &DMWRITE, DMT_STRING, get_empty, set_access_point_security_shared_key, NULL, NULL}, +{"KeyPassphrase", &DMWRITE, DMT_STRING, get_empty, set_access_point_security_passphrase, NULL, NULL}, +{"RekeyingInterval", &DMWRITE, DMT_UNINT, get_access_point_security_rekey_interval, set_access_point_security_rekey_interval, NULL, NULL}, +{"RadiusServerIPAddr", &DMWRITE, DMT_STRING, get_access_point_security_radius_ip_address, set_access_point_security_radius_ip_address, NULL, NULL}, +{"RadiusServerPort", &DMWRITE, DMT_UNINT, get_access_point_security_radius_server_port, set_access_point_security_radius_server_port, NULL, NULL}, +{"RadiusSecret", &DMWRITE, DMT_STRING,get_empty, set_access_point_security_radius_secret, NULL, NULL}, +{0} +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +int get_linker_Wifi_Radio(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if(((struct wifi_radio_args *)data)->wifi_radio_sec) { + *linker = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + return 0; + } + *linker = ""; + return 0; +} + +int get_linker_Wifi_Ssid(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) { + if(((struct wifi_ssid_args *)data)->ifname) { + *linker = ((struct wifi_ssid_args *)data)->ifname; + return 0; + } + *linker = ""; + return 0; +} +/************************************************************************** +* INIT +***************************************************************************/ +inline int init_wifi_radio(struct wifi_radio_args *args, struct uci_section *s) { - struct wifi_radio_args *args = &cur_wifi_radio_args; - ctx->args = (void *)args; args->wifi_radio_sec = s; return 0; } -inline int init_wifi_ssid(struct dmctx *ctx, struct uci_section *s, char *wiface, char *linker) +inline int init_wifi_ssid(struct wifi_ssid_args *args, struct uci_section *s, char *wiface, char *linker) { - struct wifi_ssid_args *args = &cur_wifi_ssid_args; args->wifi_ssid_sec = s; args->ifname = wiface; args->linker = linker; return 0; } -int get_wifi_enable(char *refparam, struct dmctx *ctx, char **value) +inline int init_wifi_acp(struct wifi_acp_args *args, struct uci_section *s, char *wiface) { - int i; - char *val; - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "disabled", &val); - if (val[0] == '0') - *value = "1"; - else - *value = "0"; + args->wifi_acp_sec = s; + args->ifname = wiface; return 0; } -int set_wifi_enable(char *refparam, struct dmctx *ctx, int action, char *value) -{ - bool b; - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if (b) - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "disabled", "0"); - else - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "disabled", "1"); - return 0; - } - return 0; -} - -int get_wifi_status (char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "disabled", value); - if ((*value)[0] == '\0' || (*value)[0] == '0') - *value = "Up"; - else - *value = "Down"; - return 0; -} - -int get_wlan_ssid(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "ssid", value); - return 0; -} - -int set_wlan_ssid(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "ssid", value); - return 0; - } - return 0; -} - -int get_wlan_bssid(char *refparam, struct dmctx *ctx, char **value) -{ - char *wlan_name; - json_object *res; - - wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "bssid"); - return 0; -} - -int get_radio_enable(char *refparam, struct dmctx *ctx, char **value) -{ - int i; - char *val; - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "disabled", &val); - - if (val[0] == '1') - *value = "0"; - else - *value = "1"; - return 0; -} - -int set_radio_enable(char *refparam, struct dmctx *ctx, int action, char *value) -{ - bool b; - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if (b) - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "disabled", "0"); - else - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "disabled", "1"); - return 0; - } - return 0; -} - -int get_radio_status (char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "disabled", value); - if ((*value)[0] == '1') - *value = "Down"; - else - *value = "Up"; - return 0; -} -int get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "hwmode", value); - return 0; -} - -int set_radio_max_bit_rate(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "hwmode", value); - return 0; - } - return 0; -} -int get_radio_frequency(char *refparam, struct dmctx *ctx, char **value) -{ - char *freq; - json_object *res; - char *wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - freq = dmjson_get_value(res, 1, "frequency"); - if(strcmp(freq, "2") == 0 ) { - dmastrcat(value, freq, ".4GHz"); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; - } - dmastrcat(value, freq, "GHz"); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int get_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, char **value) -{ - char *bandwith; - json_object *res; - char *wlan_name; - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "bandwidth", value); - if (value[0] == '\0') - { - wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - bandwith = dmjson_get_value(res, 1, "bandwidth"); - dmastrcat(value, bandwith, "MHz"); // MEM WILL BE FREED IN DMMEMCLEAN - } - return 0; -} - -int set_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *pch, *spch, *dup; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dup = dmstrdup(value); - pch = strtok_r(dup, "Mm", &spch); - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "bandwidth", pch); - dmfree(dup); - return 0; - } - return 0; -} - -int get_radio_maxassoc(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "maxassoc", value); - return 0; -} - -int set_radio_maxassoc(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "maxassoc", value); - return 0; - } - return 0; -} - -int get_radio_dfsenable(char *refparam, struct dmctx *ctx, char **value) -{ - char *val; - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "band", &val); - if (val[0] == 'a') { - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "dfsc", value); - if ((*value)[0] == '\0') - *value = "0"; - } - return 0; -} - -int set_radio_dfsenable(char *refparam, struct dmctx *ctx, int action, char *value) -{ - bool b; - char *val; - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "band", &val); - if (val[0] == 'a') { - string_to_bool(value, &b); - if (b) - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "dfsc", "1"); - else - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "dfsc", "0"); - } - return 0; - } - return 0; -} - -int get_radio_supported_standard(char *refparam, struct dmctx *ctx, char **value) -{ - char *freq, *wlan_name; - json_object *res; - wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); - DM_ASSERT(res, *value = "b, g, n"); - freq = dmjson_get_value(res, 1, "frequency"); - if (strcmp(freq, "5") == 0) - *value = "a, n, ac"; - else - *value = "b, g, n"; - return 0; -} - -int get_radio_operating_standard(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "hwmode", value); - if (strcmp(*value, "11b") == 0) - *value = "b"; - else if (strcmp(*value, "11bg") == 0) - *value = "b,g"; - else if (strcmp(*value, "11g") == 0 || strcmp(*value, "11gst") == 0 || strcmp(*value, "11lrs") == 0) - *value = "g"; - else if (strcmp(*value, "11n") == 0 || strcmp(*value, "auto") == 0) - *value = "n"; - else if (strcmp(*value, "11ac") == 0) - *value = "ac"; - return 0; -} - -int set_radio_operating_standard(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *freq, *wlan_name; - json_object *res; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); - freq = dmjson_get_value(res, 1, "frequency"); - if (strcmp(freq, "5") == 0) { - if (strcmp(value, "n") == 0) - value = "11n"; - else if (strcmp(value, "ac") == 0) - value = "11ac"; - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "hwmode", value); - } else { - if (strcmp(value, "b") == 0) - value = "11b"; - else if (strcmp(value, "b,g") == 0 || strcmp(value, "g,b") == 0) - value = "11bg"; - else if (strcmp(value, "g") == 0) - value = "11g"; - else if (strcmp(value, "n") == 0) - value = "11n"; - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "hwmode", value); - } - return 0; - } - return 0; -} - -int get_radio_possible_channels(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - char *wlan_name; - - *value = ""; - wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "radios", UBUS_ARGS{}, 0, &res); - if(res) - *value = dmjson_get_value_array_all(res, DELIMITOR, 2, wlan_name, "channels"); - return 0; -} - -int get_radio_channel(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - char *wlan_name; - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "channel", value); - if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') { - wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 1, "channel"); - } - return 0; -} - -int set_radio_channel(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "channel", value); - return 0; - } - return 0; -} - -int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "channel", value); - if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, int action, char *value) -{ - bool b; - json_object *res; - char *wlan_name; - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if (b) - value = "auto"; - else { - wlan_name = section_name(cur_wifi_radio_args.wifi_radio_sec); - dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); - if(res == NULL) - return 0; - else - value = dmjson_get_value(res, 1, "channel"); - } - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "channel", value); - return 0; - } - return 0; -} -//////////////////////GET STAT///////////////////////////////////// -int get_radio_statistics_tx_bytes(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - - dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(cur_wifi_radio_args.wifi_radio_sec), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "tx_bytes"); - return 0; -} - -int get_radio_statistics_rx_bytes(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(cur_wifi_radio_args.wifi_radio_sec), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "rx_bytes"); - return 0; -} - -int get_radio_statistics_tx_packets(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(cur_wifi_radio_args.wifi_radio_sec), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "tx_packets"); - return 0; -} - -int get_radio_statistics_rx_packets(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(cur_wifi_radio_args.wifi_radio_sec), String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "rx_packets"); - return 0; -} -//////////////////////GET STAT///////////////////////////////////// -int get_ssid_statistics_tx_bytes(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_wifi_ssid_args.ifname, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "tx_bytes"); - return 0; -} - -int get_ssid_statistics_rx_bytes(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_wifi_ssid_args.ifname, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "rx_bytes"); - return 0; -} - -int get_ssid_statistics_tx_packets(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_wifi_ssid_args.ifname, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "tx_packets"); - return 0; -} - -int get_ssid_statistics_rx_packets(char *refparam, struct dmctx *ctx, char **value) -{ - json_object *res; - dmubus_call("network.device", "status", UBUS_ARGS{{"name", cur_wifi_ssid_args.ifname, String}}, 1, &res); - DM_ASSERT(res, *value = ""); - *value = dmjson_get_value(res, 2, "statistics", "rx_packets"); - return 0; -} - -int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, char **value) -{ - char *hidden; - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "hidden", &hidden); - if (hidden[0] == '1' && hidden[1] == '\0') - *value = "0"; - else - *value = "1"; - return 0; -} - -int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, int action, char *value) -{ - bool b; - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if (b) - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "hidden", ""); - else - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "hidden", "1"); - return 0; - - } - return 0; -} - -int get_wmm_enabled(char *refparam, struct dmctx *ctx, char **value) -{ - bool b; - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "device", value); - dmuci_get_option_value_string("wireless", *value, "wmm", value); - string_to_bool(*value, &b); - if (b) - *value = "Enabled"; - else - *value = "Disabled"; - - return 0; -} - -int set_wmm_enabled(char *refparam, struct dmctx *ctx, int action, char *value) -{ - bool b; - char *device; - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - case VALUESET: - string_to_bool(value, &b); - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "device", &device); - if (b) { - dmuci_set_value("wireless", device, "wmm", "1"); - dmuci_set_value("wireless", device, "wmm_noack", "1"); - dmuci_set_value("wireless", device, "wmm_apsd", "1"); - } - else { - dmuci_set_value("wireless", device, "wmm", "0"); - dmuci_set_value("wireless", device, "wmm_noack", ""); - dmuci_set_value("wireless", device, "wmm_apsd", ""); - } - return 0; - } - return 0; -} - -int get_access_point_total_associations(char *refparam, struct dmctx *ctx, char **value) -{ - int i = 0; - json_object *res; - char *wunit, buf[8]; - dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", cur_wifi_ssid_args.ifname, String}}, 1, &res); - DM_ASSERT(res, *value = "0"); - json_object_object_foreach(res, key, val) { - if (strstr(key, "sta-")) - i++; - } - dmasprintf(value, "%d", i); // MEM WILL BE FREED IN DMMEMCLEAN - return 0; -} - -int get_access_point_maxassoc(char *refparam, struct dmctx *ctx, char **value) -{ - char *device; - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "device", &device); - dmuci_get_option_value_string("wireless", device, "maxassoc", value); - return 0; -} - -int set_access_point_maxassoc(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *device; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "device", &device); - dmuci_set_value("wireless", device, "maxassoc", value); - return 0; - } - return 0; -} - -int get_access_point_control_enable(char *refparam, struct dmctx *ctx, char **value) -{ - char *macfilter; - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "macfilter", &macfilter); - if (macfilter[0] != '0') - *value = "1"; - else - *value = "0"; - return 0; -} - -int set_access_point_control_enable(char *refparam, struct dmctx *ctx, int action, char *value) -{ - bool b; - switch (action) { - case VALUECHECK: - if (string_to_bool(value, &b)) - return FAULT_9007; - return 0; - case VALUESET: - string_to_bool(value, &b); - if (b) - value = "2"; - else - value = "0"; - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "macfilter", value); - return 0; - } - return 0; -} - -int get_access_point_security_supported_modes(char *refparam, struct dmctx *ctx, char **value) -{ - *value = "None, WEP-64, WEP-128, WPA-Personal, WPA2-Personal, WPA-WPA2-Personal, WPA-Enterprise, WPA2-Enterprise, WPA-WPA2-Enterprise"; - return 0; -} - -int get_access_point_security_modes(char *refparam, struct dmctx *ctx, char **value) -{ - char *encryption, *cipher; - - *value = ""; - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "cipher", &cipher); - if (strcmp(encryption, "none") == 0) - *value = "None"; - else if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0) - *value = "WEP-64"; - else if (strcmp(encryption, "psk") == 0) - *value = "WPA-Personal"; - else if (strcmp(encryption, "wpa") == 0) - *value = "WPA-Enterprise"; - else if (strcmp(encryption, "psk2") == 0 && strcmp(cipher, "ccmp") == 0) - *value = "WPA2-Personal"; - else if (strcmp(encryption, "wpa2") == 0) - *value = "WPA2-Enterprise"; - else if (strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "tkip+ccmp") == 0) - *value = "WPA-WPA2-Personal"; - else if (strcmp(encryption, "mixed-wpa") == 0) - *value = "WPA-WPA2-Enterprise"; - return 0; -} - -int set_access_point_security_modes(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *option, *gnw; - char strk64[4][11]; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - //dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(value, "None") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "none"); - } - else if (strcmp(value, "WEP-64") == 0 || strcmp(value, "WEP-128") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "wep-open"); - wepkey64("Inteno", strk64); - int i = 0; - while (i < 4) { - dmasprintf(&option, "key%d", i + 1); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, option, strk64[i]); - dmfree(option); - i++; - } - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "key", "1"); - } - else if (strcmp(value, "WPA-Personal") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "psk"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "key", gnw); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "cipher", "tkip"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "gtk_rekey", "3600"); - dmfree(gnw); - } - else if (strcmp(value, "WPA-Enterprise") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "wpa"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_server", ""); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_port", "1812"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_secret", ""); - } - else if (strcmp(value, "WPA2-Personal") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "psk2"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "key", gnw); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "cipher", "ccmp"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "gtk_rekey", "3600"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "wps_pbc", "1"); - dmfree(gnw); - } - else if (strcmp(value, "WPA2-Enterprise") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "wpa2"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_server", ""); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_port", "1812"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_secret", ""); - } - else if (strcmp(value, "WPA-WPA2-Personal") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - gnw = get_nvram_wpakey(); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "mixed-psk"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "key", gnw); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "cipher", "tkip+ccmp"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "gtk_rekey", "3600"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "wps_pbc", "1"); - dmfree(gnw); - } - else if (strcmp(value, "WPA-WPA2-Enterprise") == 0) { - reset_wlan(cur_wifi_ssid_args.wifi_ssid_sec); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", "mixed-wpa"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_server", ""); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_port", "1812"); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_secret", ""); - } - return 0; - } - return 0; -} - -int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *key_index, *encryption; - char buf[8]; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 ) { - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "key", &key_index); - sprintf(buf,"key%s", key_index); - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, buf, value); - } - return 0; - } - return 0; -} - -int set_access_point_security_shared_key(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *encryption; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "key", value); - } - return 0; - } - return 0; -} - -int set_access_point_security_passphrase(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *encryption; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { - set_access_point_security_shared_key(refparam, ctx, action, value); - } - return 0; - } - return 0; -} - -int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "gtk_rekey", value); - return 0; -} - -int set_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *key_index, *encryption; - char buf[8]; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "none") == 0) - return 0; - else { - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "gtk_rekey", value); - } - return 0; - } - return 0; -} - -int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "radius_server", value); - return 0; -} - -int set_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *key_index, *encryption; - char buf[8]; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0) - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_server", value); - return 0; - } - return 0; -} - -int get_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "radius_port", value); - return 0; -} - -int set_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *key_index, *encryption; - char buf[8]; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0) - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_port", value); - return 0; - } - return 0; -} - -int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *key_index, *encryption; - char buf[8]; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "encryption", &encryption); - if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0) - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "radius_secret", value); - return 0; - } - return 0; -} - -int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, char **value) -{ - *value = "2.4GHz, 5GHz"; - return 0; -} - -////////////////////////SET AND GET ALIAS///////////////////////////////// -int get_radio_alias(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_radio_args.wifi_radio_sec, "radioalias", value); - return 0; -} - -int set_radio_alias(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(cur_wifi_radio_args.wifi_radio_sec, "radioalias", value); - return 0; - } - return 0; -} - -int get_ssid_alias(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "ssidalias", value); - return 0; -} - -int set_ssid_alias(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "ssidalias", value); - return 0; - } - return 0; -} -int get_access_point_alias(char *refparam, struct dmctx *ctx, char **value) -{ - dmuci_get_value_by_section_string(cur_wifi_ssid_args.wifi_ssid_sec, "accesspointalias", value); - return 0; -} - -int set_access_point_alias(char *refparam, struct dmctx *ctx, int action, char *value) -{ - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "accesspointalias", value); - return 0; - } - return 0; -} -////////////////////////////////GET & SET LOWER LAYER////////////////////////// -int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, char **value) -{ - if (cur_wifi_ssid_args.linker[0] != '\0') { - adm_entry_get_linker_param(DMROOT"WiFi.Radio.", cur_wifi_ssid_args.linker, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - } - return 0; -} - -int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, int action, char *value) -{ - char *linker; - switch (action) { - case VALUECHECK: - return 0; - case VALUESET: - adm_entry_get_linker_value(value, &linker); - if (linker) { - dmuci_set_value_by_section(cur_wifi_ssid_args.wifi_ssid_sec, "device", linker); - dmfree(linker); - } - return 0; - } - return 0; -} - -int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, char **value) -{ - - adm_entry_get_linker_param(DMROOT"WiFi.SSID.", cur_wifi_ssid_args.ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN - if (*value == NULL) - *value = ""; - return 0; -} - -int get_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, char **value) +/************************************************************************** +* SET & GET VALUE +***************************************************************************/ +int get_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_option_value_string("wireless", "bandsteering", "enabled", value); return 0; } -int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, int action, char *value) +int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { bool b; @@ -998,174 +213,1041 @@ int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, int action, } return 0; } -////////////////ADD DEL OBJ////////////////////////// -int add_wifi_ssid(struct dmctx *ctx, char **new_instance) + +int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + int i; + char *val; + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", &val); + if (val[0] == '0') + *value = "1"; + else + *value = "0"; + return 0; +} + +int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", "0"); + else + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", "1"); + return 0; + } + return 0; +} + +int get_wifi_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "disabled", value); + if ((*value)[0] == '\0' || (*value)[0] == '0') + *value = "Up"; + else + *value = "Down"; + return 0; +} + +int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssid", value); + return 0; +} + +int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssid", value); + return 0; + } + return 0; +} + +int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *wlan_name; + json_object *res; + + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", &wlan_name); + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "bssid"); + return 0; +} + +int get_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + int i; + char *val; + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", &val); + + if (val[0] == '1') + *value = "0"; + else + *value = "1"; + return 0; +} + +int set_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", "0"); + else + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", "1"); + return 0; + } + return 0; +} + +int get_radio_status (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "disabled", value); + if ((*value)[0] == '1') + *value = "Down"; + else + *value = "Up"; + return 0; +} +int get_radio_max_bit_rate (char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + return 0; +} + +int set_radio_max_bit_rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + return 0; + } + return 0; +} +int get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *freq; + json_object *res; + char *wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + freq = dmjson_get_value(res, 1, "frequency"); + if(strcmp(freq, "2") == 0 ) { + dmastrcat(value, freq, ".4GHz"); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; + } + dmastrcat(value, freq, "GHz"); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +int get_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *bandwith; + json_object *res; + char *wlan_name; + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", value); + if (value[0] == '\0') + { + wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + bandwith = dmjson_get_value(res, 1, "bandwidth"); + dmastrcat(value, bandwith, "MHz"); // MEM WILL BE FREED IN DMMEMCLEAN + } + return 0; +} + +int set_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *pch, *spch, *dup; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dup = dmstrdup(value); + pch = strtok_r(dup, "Mm", &spch); + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "bandwidth", pch); + dmfree(dup); + return 0; + } + return 0; +} + +int get_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); + return 0; +} + +int set_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "maxassoc", value); + return 0; + } + return 0; +} + +int get_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *val; + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "band", &val); + if (val[0] == 'a') { + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "dfsc", value); + if ((*value)[0] == '\0') + *value = "0"; + } + return 0; +} + +int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *val; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "band", &val); + if (val[0] == 'a') { + string_to_bool(value, &b); + if (b) + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "dfsc", "1"); + else + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "dfsc", "0"); + } + return 0; + } + return 0; +} + +int get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *freq, *wlan_name; + json_object *res; + wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); + DM_ASSERT(res, *value = "b, g, n"); + freq = dmjson_get_value(res, 1, "frequency"); + if (strcmp(freq, "5") == 0) + *value = "a, n, ac"; + else + *value = "b, g, n"; + return 0; +} + +int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + if (strcmp(*value, "11b") == 0) + *value = "b"; + else if (strcmp(*value, "11bg") == 0) + *value = "b,g"; + else if (strcmp(*value, "11g") == 0 || strcmp(*value, "11gst") == 0 || strcmp(*value, "11lrs") == 0) + *value = "g"; + else if (strcmp(*value, "11n") == 0 || strcmp(*value, "auto") == 0) + *value = "n"; + else if (strcmp(*value, "11ac") == 0) + *value = "ac"; + return 0; +} + +int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *freq, *wlan_name; + json_object *res; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); + freq = dmjson_get_value(res, 1, "frequency"); + if (strcmp(freq, "5") == 0) { + if (strcmp(value, "n") == 0) + value = "11n"; + else if (strcmp(value, "ac") == 0) + value = "11ac"; + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + } else { + if (strcmp(value, "b") == 0) + value = "11b"; + else if (strcmp(value, "b,g") == 0 || strcmp(value, "g,b") == 0) + value = "11bg"; + else if (strcmp(value, "g") == 0) + value = "11g"; + else if (strcmp(value, "n") == 0) + value = "11n"; + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "hwmode", value); + } + return 0; + } + return 0; +} + +int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *wlan_name; + + *value = ""; + wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + dmubus_call("router.wireless", "radios", UBUS_ARGS{}, 0, &res); + if(res) + *value = dmjson_get_value_array_all(res, DELIMITOR, 2, wlan_name, "channels"); + return 0; +} + +int get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + char *wlan_name; + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') { + wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 1, "channel"); + } + return 0; +} + +int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + return 0; + } + return 0; +} + +int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + if (strcmp(*value, "auto") == 0 || (*value)[0] == '\0') + *value = "1"; + else + *value = "0"; + return 0; +} + +int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + json_object *res; + char *wlan_name; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + value = "auto"; + else { + wlan_name = section_name(((struct wifi_radio_args *)data)->wifi_radio_sec); + dmubus_call("router.wireless", "status", UBUS_ARGS{{"vif", wlan_name, String}}, 1, &res); + if(res == NULL) + return 0; + else + value = dmjson_get_value(res, 1, "channel"); + } + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "channel", value); + return 0; + } + return 0; +} + +/************************************************************* + * GET STAT +/*************************************************************/ +int get_radio_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + + dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "tx_bytes"); + return 0; +} + +int get_radio_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "rx_bytes"); + return 0; +} + +int get_radio_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "tx_packets"); + return 0; +} + +int get_radio_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", section_name(((struct wifi_radio_args *)data)->wifi_radio_sec), String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "rx_packets"); + return 0; +} + +int get_ssid_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "tx_bytes"); + return 0; +} + +int get_ssid_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "rx_bytes"); + return 0; +} + +int get_ssid_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "tx_packets"); + return 0; +} + +int get_ssid_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res; + dmubus_call("network.device", "status", UBUS_ARGS{{"name", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = ""); + *value = dmjson_get_value(res, 2, "statistics", "rx_packets"); + return 0; +} + +/************************************************************************** +* SET & GET VALUE +***************************************************************************/ +int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *hidden; + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", &hidden); + if (hidden[0] == '1' && hidden[1] == '\0') + *value = "0"; + else + *value = "1"; + return 0; +} + +int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", ""); + else + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "hidden", "1"); + return 0; + + } + return 0; +} + +int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + bool b; + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", value); + dmuci_get_option_value_string("wireless", *value, "wmm", value); + string_to_bool(*value, &b); + if (b) + *value = "Enabled"; + else + *value = "Disabled"; + + return 0; +} + +int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + char *device; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); + if (b) { + dmuci_set_value("wireless", device, "wmm", "1"); + dmuci_set_value("wireless", device, "wmm_noack", "1"); + dmuci_set_value("wireless", device, "wmm_apsd", "1"); + } + else { + dmuci_set_value("wireless", device, "wmm", "0"); + dmuci_set_value("wireless", device, "wmm_noack", ""); + dmuci_set_value("wireless", device, "wmm_apsd", ""); + } + return 0; + } + return 0; +} + +int get_access_point_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + int i = 0; + json_object *res; + char *wunit, buf[8]; + dmubus_call("router.wireless", "stas", UBUS_ARGS{{"vif", ((struct wifi_ssid_args *)data)->ifname, String}}, 1, &res); + DM_ASSERT(res, *value = "0"); + json_object_object_foreach(res, key, val) { + if (strstr(key, "sta-")) + i++; + } + dmasprintf(value, "%d", i); // MEM WILL BE FREED IN DMMEMCLEAN + return 0; +} + +int get_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *device; + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", &device); + dmuci_get_option_value_string("wireless", device, "maxassoc", value); + return 0; +} + +int set_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *device; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "device", &device); + dmuci_set_value("wireless", device, "maxassoc", value); + return 0; + } + return 0; +} + +int get_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *macfilter; + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "macfilter", &macfilter); + if (macfilter[0] != '0') + *value = "1"; + else + *value = "0"; + return 0; +} + +int set_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + bool b; + switch (action) { + case VALUECHECK: + if (string_to_bool(value, &b)) + return FAULT_9007; + return 0; + case VALUESET: + string_to_bool(value, &b); + if (b) + value = "2"; + else + value = "0"; + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "macfilter", value); + return 0; + } + return 0; +} + +int get_access_point_security_supported_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "None, WEP-64, WEP-128, WPA-Personal, WPA2-Personal, WPA-WPA2-Personal, WPA-Enterprise, WPA2-Enterprise, WPA-WPA2-Enterprise"; + return 0; +} + +int get_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *encryption, *cipher; + + *value = ""; + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", &cipher); + if (strcmp(encryption, "none") == 0) + *value = "None"; + else if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0) + *value = "WEP-64"; + else if (strcmp(encryption, "psk") == 0) + *value = "WPA-Personal"; + else if (strcmp(encryption, "wpa") == 0) + *value = "WPA-Enterprise"; + else if (strcmp(encryption, "psk2") == 0 && strcmp(cipher, "ccmp") == 0) + *value = "WPA2-Personal"; + else if (strcmp(encryption, "wpa2") == 0) + *value = "WPA2-Enterprise"; + else if (strcmp(encryption, "mixed-psk") == 0 && strcmp(cipher, "tkip+ccmp") == 0) + *value = "WPA-WPA2-Personal"; + else if (strcmp(encryption, "mixed-wpa") == 0) + *value = "WPA-WPA2-Enterprise"; + return 0; +} + +int set_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *option, *gnw; + char strk64[4][11]; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + if (strcmp(value, "None") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "none"); + } + else if (strcmp(value, "WEP-64") == 0 || strcmp(value, "WEP-128") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wep-open"); + wepkey64("Inteno", strk64); + int i = 0; + while (i < 4) { + dmasprintf(&option, "key%d", i + 1); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, option, strk64[i]); + dmfree(option); + i++; + } + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", "1"); + } + else if (strcmp(value, "WPA-Personal") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "psk"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "tkip"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); + dmfree(gnw); + } + else if (strcmp(value, "WPA-Enterprise") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); + } + else if (strcmp(value, "WPA2-Personal") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "psk2"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "ccmp"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps_pbc", "1"); + dmfree(gnw); + } + else if (strcmp(value, "WPA2-Enterprise") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "wpa2"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); + } + else if (strcmp(value, "WPA-WPA2-Personal") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + gnw = get_nvram_wpakey(); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "mixed-psk"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", gnw); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "cipher", "tkip+ccmp"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", "3600"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "wps_pbc", "1"); + dmfree(gnw); + } + else if (strcmp(value, "WPA-WPA2-Enterprise") == 0) { + reset_wlan(((struct wifi_acp_args *)data)->wifi_acp_sec); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", "mixed-wpa"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", ""); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", "1812"); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", ""); + } + return 0; + } + return 0; +} + +int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *key_index, *encryption; + char buf[8]; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 ) { + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", &key_index); + sprintf(buf,"key%s", key_index); + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, buf, value); + } + return 0; + } + return 0; +} + +int set_access_point_security_shared_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "key", value); + } + return 0; + } + return 0; +} + +int set_access_point_security_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *encryption; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "psk") == 0 || strcmp(encryption, "psk2") == 0 || strcmp(encryption, "mixed-psk") == 0 ) { + set_access_point_security_shared_key(refparam, ctx, data, instance, value, action); + } + return 0; + } + return 0; +} + +int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", value); + return 0; +} + +int set_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *key_index, *encryption; + char buf[8]; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wep-open") == 0 || strcmp(encryption, "wep-shared") == 0 || strcmp(encryption, "none") == 0) + return 0; + else { + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "gtk_rekey", value); + } + return 0; + } + return 0; +} + +int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", value); + return 0; +} + +int set_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *key_index, *encryption; + char buf[8]; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0) + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_server", value); + return 0; + } + return 0; +} + +int get_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", value); + return 0; +} + +int set_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *key_index, *encryption; + char buf[8]; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0) + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_port", value); + return 0; + } + return 0; +} + +int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *key_index, *encryption; + char buf[8]; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "encryption", &encryption); + if (strcmp(encryption, "wpa") == 0 || strcmp(encryption, "wpa2") == 0 || strcmp(encryption, "mixed-wpa") == 0) + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "radius_secret", value); + return 0; + } + return 0; +} + +int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "2.4GHz, 5GHz"; + return 0; +} +/************************************************************************** +* SET AND GET ALIAS +***************************************************************************/ + +int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_radio_args *)data)->wifi_radio_sec, "radioalias", value); + return 0; +} + +int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_radio_args *)data)->wifi_radio_sec, "radioalias", value); + return 0; + } + return 0; +} + +int get_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssidalias", value); + return 0; +} + +int set_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "ssidalias", value); + return 0; + } + return 0; +} +int get_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_value_by_section_string(((struct wifi_acp_args *)data)->wifi_acp_sec, "accesspointalias", value); + return 0; +} + +int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + dmuci_set_value_by_section(((struct wifi_acp_args *)data)->wifi_acp_sec, "accesspointalias", value); + return 0; + } + return 0; +} +/************************************************************* + * GET & SET LOWER LAYER +/*************************************************************/ +int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + if (((struct wifi_ssid_args *)data)->linker[0] != '\0') { + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cRadio%c", DMROOT, dm_delim, dm_delim, dm_delim), ((struct wifi_ssid_args *)data)->linker, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + } + return 0; +} + +int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *linker; + switch (action) { + case VALUECHECK: + return 0; + case VALUESET: + adm_entry_get_linker_value(ctx, value, &linker); + if (linker) { + dmuci_set_value_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, "device", linker); + dmfree(linker); + } + return 0; + } + return 0; +} + +int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + adm_entry_get_linker_param(ctx, dm_print_path("%s%cWiFi%cSSID%c", DMROOT, dm_delim, dm_delim, dm_delim), ((struct wifi_acp_args *)data)->ifname, value); // MEM WILL BE FREED IN DMMEMCLEAN + if (*value == NULL) + *value = ""; + return 0; +} + +/************************************************************* + * ADD DEL OBJ +/*************************************************************/ +int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instance) { char *value; char ssid[16] = {0}; - char *instance; + char *inst; struct uci_section *s = NULL; - instance = get_last_instance("wireless", "wifi-iface", "ssidinstance"); - sprintf(ssid, "Inteno_%d", instance ? (atoi(instance)+1) : 1); + inst = get_last_instance("wireless", "wifi-iface", "ssidinstance"); + sprintf(ssid, "Inteno_%d", inst ? (atoi(inst)+1) : 1); dmuci_add_section("wireless", "wifi-iface", &s, &value); dmuci_set_value_by_section(s, "device", "wl0"); dmuci_set_value_by_section(s, "encryption", "none"); dmuci_set_value_by_section(s, "macfilter", "0"); dmuci_set_value_by_section(s, "mode", "ap"); dmuci_set_value_by_section(s, "ssid", ssid); - *new_instance = update_instance(s, instance, "ssidinstance"); + *instance = update_instance(s, inst, "ssidinstance"); return 0; } -int delete_wifi_ssid_all(struct dmctx *ctx) +int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { int found = 0; char *lan_name; struct uci_section *s = NULL; struct uci_section *ss = NULL; - - uci_foreach_sections("wireless", "wifi-iface", s) { - if (found != 0) + switch (del_action) { + case DEL_INST: + dmuci_delete_by_section(((struct wifi_ssid_args *)data)->wifi_ssid_sec, NULL, NULL); + break; + case DEL_ALL: + uci_foreach_sections("wireless", "wifi-iface", s) { + if (found != 0) + dmuci_delete_by_section(ss, NULL, NULL); + ss = s; + found++; + } + if (ss != NULL) dmuci_delete_by_section(ss, NULL, NULL); - ss = s; - found++; + return 0; } - if (ss != NULL) - dmuci_delete_by_section(ss, NULL, NULL); return 0; } +/************************************************************* + * ENTRY METHOD +/*************************************************************/ -int delete_wifi_ssid(struct dmctx *ctx) -{ - dmuci_delete_by_section(cur_wifi_ssid_args.wifi_ssid_sec, NULL, NULL); - return 0; -} -/////////////SUB ENTRIES/////////////// -inline int entry_wifi_radio(struct dmctx *ctx) +int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *wnum_last = NULL; char buf[12]; struct uci_section *s = NULL; + struct wifi_radio_args curr_wifi_radio_args = {0}; uci_foreach_sections("wireless", "wifi-device", s) { - init_wifi_radio(ctx, s); - wnum = handle_update_instance(1, ctx, &wnum_last, update_instance_alias, 3, s, "radioinstance", "radioalias"); - SUBENTRY(entry_wifi_radio_instance, ctx, wnum); + init_wifi_radio(&curr_wifi_radio_args, s); + wnum = handle_update_instance(1, dmctx, &wnum_last, update_instance_alias, 3, s, "radioinstance", "radioalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_radio_args, wnum) == DM_STOP) + break; } return 0; } -inline int entry_wifi_ssid(struct dmctx *ctx) +int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { char *wnum = NULL, *ssid_last = NULL, *ifname, *acpt_last = NULL, *linker; struct uci_section *ss = NULL; json_object *res; + struct wifi_ssid_args curr_wifi_ssid_args = {0}; uci_foreach_sections("wireless", "wifi-iface", ss) { dmuci_get_value_by_section_string(ss, "ifname", &ifname); dmuci_get_value_by_section_string(ss, "device", &linker); - init_wifi_ssid(ctx, ss, ifname, linker); - wnum = handle_update_instance(1, ctx, &ssid_last, update_instance_alias, 3, ss, "ssidinstance", "ssidalias"); - SUBENTRY(entry_wifi_ssid_instance, ctx, wnum); - wnum = handle_update_instance(1, ctx, &acpt_last, update_instance_alias, 3, ss, "accesspointinstance", "accesspointalias"); - SUBENTRY(entry_wifi_access_point_instance, ctx, wnum); + init_wifi_ssid(&curr_wifi_ssid_args, ss, ifname, linker); + wnum = handle_update_instance(1, dmctx, &ssid_last, update_instance_alias, 3, ss, "ssidinstance", "ssidalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_ssid_args, wnum) == DM_STOP) + break; } return 0; } -///////////////////WIFI ENTRY/////////////////// -int entry_method_root_Wifi(struct dmctx *ctx) +int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) { - IF_MATCH(ctx, DMROOT"WiFi.") { - DMOBJECT(DMROOT"WiFi.", ctx, "0", 1, NULL, NULL, NULL); - DMPARAM("X_INTENO_SE_Bandsteering_Enable", ctx, "1", get_wifi_bandsteering_enable, set_wifi_bandsteering_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WiFi.Radio.", ctx, "0", 1, NULL, NULL, NULL); - DMOBJECT(DMROOT"WiFi.SSID.", ctx, "1", 1, add_wifi_ssid, delete_wifi_ssid_all, NULL); - DMOBJECT(DMROOT"WiFi.AccessPoint.", ctx, "0", 1, NULL, NULL, NULL); - SUBENTRY(entry_wifi_radio, ctx); - SUBENTRY(entry_wifi_ssid, ctx); - return 0; - } - return FAULT_9005; -} + char *wnum = NULL, *ssid_last = NULL, *ifname, *acpt_last = NULL; + struct uci_section *ss = NULL; + json_object *res; + struct wifi_acp_args curr_wifi_acp_args = {0}; -inline int entry_wifi_radio_instance(struct dmctx *ctx, char *wnum) -{ - IF_MATCH(ctx, DMROOT"WiFi.Radio.%s.", wnum) { - char linker[32] = ""; - strcat(linker, section_name(cur_wifi_radio_args.wifi_radio_sec)); - DMOBJECT(DMROOT"WiFi.Radio.%s.", ctx, "0", 1, NULL, NULL, linker, wnum); - DMPARAM("Alias", ctx, "1", get_radio_alias, set_radio_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_radio_enable, set_radio_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_radio_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("MaxBitRate", ctx, "1", get_radio_max_bit_rate, set_radio_max_bit_rate, NULL, 0, 1, UNDEF, NULL); - DMPARAM("OperatingFrequencyBand", ctx, "0", get_radio_frequency, NULL, NULL, 0, 1, UNDEF, NULL); //TO CHECK R/W - DMPARAM("SupportedFrequencyBands", ctx, "0", get_radio_supported_frequency_bands, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("OperatingChannelBandwidth", ctx, "1", get_radio_operating_channel_bandwidth, set_radio_operating_channel_bandwidth, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_MaxAssociations", ctx, "1", get_radio_maxassoc, set_radio_maxassoc, NULL, 0, 1, UNDEF, NULL); - DMPARAM("X_INTENO_SE_DFSEnable", ctx, "1", get_radio_dfsenable, set_radio_dfsenable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("SupportedStandards", ctx, "0", get_radio_supported_standard, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("OperatingStandards", ctx, "1", get_radio_operating_standard, set_radio_operating_standard, NULL, 0, 1, UNDEF, NULL); - DMPARAM("PossibleChannels", ctx, "0", get_radio_possible_channels, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ChannelsInUse", ctx, "0", get_radio_channel, NULL, NULL, 0, 1, UNDEF, NULL); /// TO CHECK - DMPARAM("Channel", ctx, "1", get_radio_channel, set_radio_channel, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("AutoChannelEnable", ctx, "1", get_radio_auto_channel_enable, set_radio_auto_channel_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WiFi.Radio.%s.Stats.", ctx, "0", 1, NULL, NULL, NULL, wnum); - DMPARAM("BytesSent", ctx, "0", get_radio_statistics_tx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_radio_statistics_rx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_radio_statistics_tx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_radio_statistics_rx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; + uci_foreach_sections("wireless", "wifi-iface", ss) { + dmuci_get_value_by_section_string(ss, "ifname", &ifname); + init_wifi_acp(&curr_wifi_acp_args, ss, ifname); + wnum = handle_update_instance(1, dmctx, &acpt_last, update_instance_alias, 3, ss, "accesspointinstance", "accesspointalias"); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_wifi_acp_args, wnum) == DM_STOP) + break; } - return FAULT_9005; -} - -inline int entry_wifi_ssid_instance(struct dmctx *ctx, char *wnum) -{ - IF_MATCH(ctx, DMROOT"WiFi.SSID.%s.", wnum) { - DMOBJECT(DMROOT"WiFi.SSID.%s.", ctx, "1", 1, NULL, delete_wifi_ssid, cur_wifi_ssid_args.ifname, wnum); - DMPARAM("Alias", ctx, "1", get_ssid_alias, set_ssid_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_wifi_enable, set_wifi_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_wifi_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SSID", ctx, "1", get_wlan_ssid, set_wlan_ssid, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Name", ctx, "1", get_wlan_ssid, set_wlan_ssid, NULL, 0, 1, UNDEF, NULL); - DMPARAM("LowerLayers", ctx, "1", get_ssid_lower_layer, set_ssid_lower_layer, NULL, 0, 1, UNDEF, NULL); - DMPARAM("BSSID", ctx, "0", get_wlan_bssid, NULL, NULL, 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WiFi.SSID.%s.Stats.", ctx, "0", 1, NULL, NULL, NULL, wnum); - DMPARAM("BytesSent", ctx, "0", get_ssid_statistics_tx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("BytesReceived", ctx, "0", get_ssid_statistics_rx_bytes, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsSent", ctx, "0", get_ssid_statistics_tx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("PacketsReceived", ctx, "0", get_ssid_statistics_rx_packets, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; -} - -inline int entry_wifi_access_point_instance(struct dmctx *ctx, char *wnum) -{ - IF_MATCH(ctx, DMROOT"WiFi.AccessPoint.%s.", wnum) { - DMOBJECT(DMROOT"WiFi.AccessPoint.%s.", ctx, "0", 1, NULL, NULL, NULL, wnum); - DMPARAM("Alias", ctx, "1", get_access_point_alias, set_access_point_alias, NULL, 0, 1, UNDEF, NULL); - DMPARAM("Enable", ctx, "1", get_wifi_enable, set_wifi_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("Status", ctx, "0", get_wifi_status, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SSIDReference", ctx, "0", get_ap_ssid_ref, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("SSIDAdvertisementEnabled", ctx, "1", get_wlan_ssid_advertisement_enable, set_wlan_ssid_advertisement_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("WMMEnable", ctx, "1", get_wmm_enabled, set_wmm_enabled, "xsd:boolean", 0, 1, UNDEF, NULL); - DMPARAM("AssociatedDeviceNumberOfEntries", ctx, "0", get_access_point_total_associations, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MaxAssociatedDevices", ctx, "1", get_access_point_maxassoc, set_access_point_maxassoc, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("MACAddressControlEnabled", ctx, "1", get_access_point_control_enable, set_access_point_control_enable, "xsd:boolean", 0, 1, UNDEF, NULL); - DMOBJECT(DMROOT"WiFi.AccessPoint.%s.Security.", ctx, "0", 1, NULL, NULL, NULL, wnum); - DMPARAM("ModesSupported", ctx, "0", get_access_point_security_supported_modes, NULL, NULL, 0, 1, UNDEF, NULL); - DMPARAM("ModeEnabled", ctx, "1", get_access_point_security_modes, set_access_point_security_modes, NULL, 0, 1, UNDEF, NULL); - DMPARAM("WEPKey", ctx, "1", get_empty, set_access_point_security_wepkey, NULL, 0, 1, UNDEF, NULL); - DMPARAM("PreSharedKey", ctx, "1", get_empty, set_access_point_security_shared_key, NULL, 0, 1, UNDEF, NULL); - DMPARAM("KeyPassphrase", ctx, "1", get_empty, set_access_point_security_passphrase, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RekeyingInterval", ctx, "1", get_access_point_security_rekey_interval, set_access_point_security_rekey_interval, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RadiusServerIPAddr", ctx, "1", get_access_point_security_radius_ip_address, set_access_point_security_radius_ip_address, NULL, 0, 1, UNDEF, NULL); - DMPARAM("RadiusServerPort", ctx, "1", get_access_point_security_radius_server_port, set_access_point_security_radius_server_port, "xsd:unsignedInt", 0, 1, UNDEF, NULL); - DMPARAM("RadiusSecret", ctx, "1", get_empty, set_access_point_security_radius_secret, NULL, 0, 1, UNDEF, NULL); - return 0; - } - return FAULT_9005; + return 0; } diff --git a/dm/dmtree/tr181/wifi.h b/dm/dmtree/tr181/wifi.h index 275ad50..8c5b23e 100644 --- a/dm/dmtree/tr181/wifi.h +++ b/dm/dmtree/tr181/wifi.h @@ -22,6 +22,103 @@ struct wifi_ssid_args char *ifname; char *linker; }; -int entry_method_root_Wifi(struct dmctx *ctx); +struct wifi_acp_args +{ + struct uci_section *wifi_acp_sec; + char *ifname; +}; +extern DMOBJ tWifiObj[]; +extern DMLEAF tWifiParams[]; +extern DMOBJ tWifiRadioStatsObj[]; +extern DMOBJ tAcessPointSecurityObj[]; +extern DMOBJ tWifiSsidStatsObj[]; +extern DMLEAF tWifiAcessPointParams[]; +extern DMLEAF tWifiSsidParams[]; +extern DMLEAF tWifiRadioParams[]; +extern DMLEAF tWifiAcessPointSecurityParams[]; +extern DMLEAF tWifiRadioStatsParams[]; +extern DMLEAF tWifiSsidStatsParams[]; + +int browseWifiSsidInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseWifiAccessPointInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseWifiRadioInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int add_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char **instancepara); +int delete_wifi_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action); +int get_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_wifi_bandsteering_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); + +int get_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_max_bit_rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_frequency(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_supported_frequency_bands(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_supported_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_possible_channels(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_radio_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wifi_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_bssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ssid_statistics_tx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ssid_statistics_rx_bytes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ssid_statistics_tx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ssid_statistics_rx_packets(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wifi_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_ap_ssid_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_total_associations(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_security_supported_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_linker_Wifi_Radio(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_linker_Wifi_Ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int set_radio_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_max_bit_rate(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_dfsenable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_operating_standard(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_channel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_radio_auto_channel_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ssid_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_ssid(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_ssid_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wifi_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_maxassoc(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_control_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_modes(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_wepkey(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_shared_key(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_passphrase(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_rekey_interval(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_radius_ip_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_radius_server_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_access_point_security_radius_secret(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int set_wmm_enabled(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); #endif diff --git a/dm/dmubus.c b/dm/dmubus.c index 2cce18c..a9262b0 100644 --- a/dm/dmubus.c +++ b/dm/dmubus.c @@ -26,7 +26,7 @@ #define UBUS_BUFFEER_SIZE 1024 * 8 struct dmubus_ctx dmubus_ctx; -#if 0 +#if DM_USE_LIBUBUS struct ubus_context *ubus_ctx; static int timeout = 1000; @@ -66,7 +66,7 @@ static inline int ubus_arg_cmp(struct ubus_arg *src_args, int src_size, struct u return 0; } -#if 0 +#if DM_USE_LIBUBUS static void receive_call_result_data(struct ubus_request *req, int type, struct blob_attr *msg) { if (!msg) @@ -87,6 +87,7 @@ static void receive_call_result_data(struct ubus_request *req, int type, struct int dmubus_call_set(char *obj, char *method, struct ubus_arg u_args[], int u_args_size) { +#if !DM_USE_LIBUBUS char bufargs[256], *p; int i, r; p = bufargs; @@ -95,12 +96,8 @@ int dmubus_call_set(char *obj, char *method, struct ubus_arg u_args[], int u_arg sprintf(p, "{"); for (i = 0; i < u_args_size; i++) { p += strlen(p); - if (i == 0 && u_args[i].type == 1) - sprintf(p, "\"%s\": %s", u_args[i].key, u_args[i].val); - else if (i == 0 && u_args[i].type == 0) + if (i == 0) sprintf(p, "\"%s\": \"%s\"", u_args[i].key, u_args[i].val); - else if (i != 0 && u_args[i].type == 1) - sprintf(p, ", \"%s\": %s", u_args[i].key, u_args[i].val); else sprintf(p, ", \"%s\": \"%s\"", u_args[i].key, u_args[i].val); } @@ -112,10 +109,40 @@ int dmubus_call_set(char *obj, char *method, struct ubus_arg u_args[], int u_arg DMCMD("ubus", 6, "-S", "-t", "1", "call", obj, method); //TODO wait to fix uloop ubus freeze } return 0; +#else + struct blob_buf b = {0}; + uint32_t id; + int ret; + json_res = NULL; + + ubus_ctx = ubus_connect(ubus_socket); + if (!ubus_ctx) + return 0; + + blob_buf_init(&b, 0); + int i=0; + for (i = 0; i < u_args_size; i++) { + if (!dmblobmsg_json_object_from_uargs(&b, u_args[i].key, u_args[i].val)) + goto end_error; + } + ret = ubus_lookup_id(ubus_ctx, obj, &id); + ubus_invoke(ubus_ctx, id, method, b.head, receive_call_result_data, NULL, timeout); + blob_buf_free(&b); + if (json_res != NULL) { + json_object_put(json_res); + json_res = NULL; + } + return 0; + +end_error: + blob_buf_free(&b); + return NULL; +#endif } static inline json_object *ubus_call_req(char *obj, char *method, struct ubus_arg u_args[], int u_args_size) { +#if !DM_USE_LIBUBUS json_object *res = NULL; char bufres[UBUS_BUFFEER_SIZE], bufargs[256], *p; int i, pp = 0, r; @@ -150,7 +177,7 @@ static inline json_object *ubus_call_req(char *obj, char *method, struct ubus_ar } return res; -#if 0 +#else struct blob_buf b = {0}; uint32_t id; int ret; @@ -278,4 +305,3 @@ void dmubus_ctx_free(struct dmubus_ctx *ctx) dmfree(i); } } - diff --git a/event.c b/event.c index 787f080..40cea1b 100644 --- a/event.c +++ b/event.c @@ -26,6 +26,7 @@ #include "dmcwmp.h" #include "dmentry.h" #include "deviceinfo.h" +#include "config.h" LIST_HEAD(list_value_change); LIST_HEAD(list_lw_value_change); @@ -296,9 +297,9 @@ void cwmp_add_notification(void) cwmp->count_handle_notify = 0; pthread_mutex_unlock(&(cwmp->mutex_handle_notify)); - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); list_for_each_entry(p, &list_enabled_notify, list) { - dm_ctx_init_sub(&dmctx); + dm_ctx_init_sub(&dmctx, DM_CWMP, cwmp_main.conf.amd_version, cwmp_main.conf.instance_mode); initiate = true; fault = dm_entry_param_method(&dmctx, CMD_GET_VALUE, p->name, NULL, NULL); if (!fault && dmctx.list_parameter.next != &dmctx.list_parameter) { @@ -317,7 +318,7 @@ void cwmp_add_notification(void) //dm_ctx_init(&dmctx); list_for_each_entry(p, &list_enabled_lw_notify, list) { if (!initiate || i != 0) - dm_ctx_init_sub(&dmctx); + dm_ctx_init_sub(&dmctx, DM_CWMP, cwmp_main.conf.amd_version, cwmp_main.conf.instance_mode); i++; if (!conf->lw_notification_enable) break; @@ -334,7 +335,7 @@ void cwmp_add_notification(void) } dm_ctx_clean_sub(&dmctx); } - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); if (lw_isactive) { cwmp_lwnotification(); } @@ -441,6 +442,7 @@ int cwmp_root_cause_event_bootstrap (struct cwmp *cwmp) int error,cmp=0; struct event_container *event_container; struct session *session; + char buf[64] = ""; error = cwmp_load_saved_session(cwmp, &acsurl, ACS); @@ -484,8 +486,9 @@ int cwmp_root_cause_event_bootstrap (struct cwmp *cwmp) pthread_mutex_unlock (&(cwmp->mutex_session_queue)); return CWMP_MEM_ERR; } + sprintf(buf, "%sManagementServer.URL", DMROOT); add_dm_parameter_tolist(&(event_container->head_dm_parameter), - DMROOT"ManagementServer.URL", NULL, NULL); + buf, NULL, NULL); cwmp_save_event_container (cwmp,event_container); save_acs_bkp_config(cwmp); cwmp_scheduleInform_remove_all(); diff --git a/external.c b/external.c index 1d133d3..8dd1f67 100644 --- a/external.c +++ b/external.c @@ -31,6 +31,7 @@ #include "cwmp.h" #include "xml.h" #include "log.h" +#include "dmcwmp.h" #include static int pid; @@ -118,7 +119,7 @@ static void external_read_pipe_input(int (*external_handler)(char *msg)) value = c; } else { if (!value) continue; - if (strcmp(value, "icwmp>")==0) { + if (strcmp(value, DM_PROMPT)==0) { FREE(value); break; } diff --git a/http.c b/http.c index de4e57f..c0e0a8e 100644 --- a/http.c +++ b/http.c @@ -25,6 +25,7 @@ #include "cwmp.h" #include "log.h" #include "xml.h" +#include "config.h" #include #include @@ -256,25 +257,25 @@ http_send_message(struct cwmp *cwmp, char *msg_out, int msg_out_len,char **msg_i if (!strlen(*msg_in)) FREE(*msg_in); - curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip); - if (ip && ip[0] != '\0') { - if (!ip_acs || strcmp(ip_acs, ip) != 0) { - FREE(ip_acs); - ip_acs = strdup(ip); - if (cwmp->conf.ipv6_enable) { + curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ip); + if (ip && ip[0] != '\0') { + if (!ip_acs || strcmp(ip_acs, ip) != 0) { + FREE(ip_acs); + ip_acs = strdup(ip); + if (cwmp->conf.ipv6_enable) { tmp = inet_pton(AF_INET, ip, buf); - if (tmp == 1) - tmp = 0; - else - tmp = inet_pton(AF_INET6, ip, buf); - } - external_init(); - external_simple("allow_cr_ip", ip_acs, tmp); - external_exit(); - } - } + if (tmp == 1) + tmp = 0; + else + tmp = inet_pton(AF_INET6, ip, buf); + } + external_init(); + external_simple("allow_cr_ip", ip_acs, tmp); + external_exit(); + } + } - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); if(http_code == 204) { CWMP_LOG (INFO,"Receive HTTP 204 No Content"); @@ -348,165 +349,165 @@ error: void http_success_cr() { - struct event_container *event_container; - CWMP_LOG(INFO,"Connection Request thread: add connection request event in the queue"); - pthread_mutex_lock (&(cwmp_main.mutex_session_queue)); - event_container = cwmp_add_event_container (&cwmp_main, EVENT_IDX_6CONNECTION_REQUEST, ""); - pthread_mutex_unlock (&(cwmp_main.mutex_session_queue)); - pthread_cond_signal(&(cwmp_main.threshold_session_send)); + struct event_container *event_container; + CWMP_LOG(INFO,"Connection Request thread: add connection request event in the queue"); + pthread_mutex_lock (&(cwmp_main.mutex_session_queue)); + event_container = cwmp_add_event_container (&cwmp_main, EVENT_IDX_6CONNECTION_REQUEST, ""); + pthread_mutex_unlock (&(cwmp_main.mutex_session_queue)); + pthread_cond_signal(&(cwmp_main.threshold_session_send)); } static void http_cr_new_client(int client, bool service_available) { - FILE *fp; - char buffer[BUFSIZ]; - int8_t auth_status = 0; + FILE *fp; + char buffer[BUFSIZ]; + int8_t auth_status = 0; - fp = fdopen(client, "r+"); + fp = fdopen(client, "r+"); - while (fgets(buffer, sizeof(buffer), fp)) { - if (!strncasecmp(buffer, "Authorization: Digest ", strlen("Authorization: Digest "))) { - char *username = cwmp_main.conf.cpe_userid; - char *password = cwmp_main.conf.cpe_passwd; + while (fgets(buffer, sizeof(buffer), fp)) { + if (!strncasecmp(buffer, "Authorization: Digest ", strlen("Authorization: Digest "))) { + char *username = cwmp_main.conf.cpe_userid; + char *password = cwmp_main.conf.cpe_passwd; - if (!username || !password) { - // if we dont have username or password configured proceed with connecting to ACS - service_available = false; - goto http_end; - } + if (!username || !password) { + // if we dont have username or password configured proceed with connecting to ACS + service_available = false; + goto http_end; + } - if (http_digest_auth_check("GET", "/", buffer + strlen("Authorization: Digest "), REALM, username, password, 300) == MHD_YES) - auth_status = 1; - else - auth_status = 0; - } + if (http_digest_auth_check("GET", "/", buffer + strlen("Authorization: Digest "), REALM, username, password, 300) == MHD_YES) + auth_status = 1; + else + auth_status = 0; + } - if (buffer[0] == '\r' || buffer[0] == '\n') { - /* end of http request (empty line) */ - goto http_end; - } - } - if(!service_available) { - goto http_end; - } - goto http_done; + if (buffer[0] == '\r' || buffer[0] == '\n') { + /* end of http request (empty line) */ + goto http_end; + } + } + if(!service_available) { + goto http_end; + } + goto http_done; -http_end: - if (!service_available) { - CWMP_LOG (INFO,"Receive Connection Request: Return 503 Service Unavailable"); - fputs("HTTP/1.1 503 Service Unavailable\r\n", fp); - fputs("Connection: close\r\n", fp); - fputs("Content-Length: 0\r\n", fp); - } else if (auth_status) { - CWMP_LOG (INFO,"Receive Connection Request: success authentication"); - fputs("HTTP/1.1 200 OK\r\n", fp); - fputs("Connection: close\r\n", fp); - fputs("Content-Length: 0\r\n", fp); - http_success_cr(); - } else { - CWMP_LOG (INFO,"Receive Connection Request: Return 401 Unauthorized"); - fputs("HTTP/1.1 401 Unauthorized\r\n", fp); - fputs("Connection: close\r\n", fp); - http_digest_auth_fail_response(fp, "GET", "/", REALM, OPAQUE); - fputs("\r\n", fp); - } - fputs("\r\n", fp); + http_end: + if (!service_available) { + CWMP_LOG (INFO,"Receive Connection Request: Return 503 Service Unavailable"); + fputs("HTTP/1.1 503 Service Unavailable\r\n", fp); + fputs("Connection: close\r\n", fp); + fputs("Content-Length: 0\r\n", fp); + } else if (auth_status) { + CWMP_LOG (INFO,"Receive Connection Request: success authentication"); + fputs("HTTP/1.1 200 OK\r\n", fp); + fputs("Connection: close\r\n", fp); + fputs("Content-Length: 0\r\n", fp); + http_success_cr(); + } else { + CWMP_LOG (INFO,"Receive Connection Request: Return 401 Unauthorized"); + fputs("HTTP/1.1 401 Unauthorized\r\n", fp); + fputs("Connection: close\r\n", fp); + http_digest_auth_fail_response(fp, "GET", "/", REALM, OPAQUE); + fputs("\r\n", fp); + } + fputs("\r\n", fp); -http_done: - fclose(fp); + http_done: + fclose(fp); } void http_server_init(void) { - struct sockaddr_in6 server = {0}; - unsigned short cr_port; + struct sockaddr_in6 server = {0}; + unsigned short cr_port; - for(;;) { - cr_port = (unsigned short) (cwmp_main.conf.connection_request_port); - unsigned short i = (DEFAULT_CONNECTION_REQUEST_PORT == cr_port)? 1 : 0; - //Create socket - cwmp_main.cr_socket_desc = socket(AF_INET6 , SOCK_STREAM , 0); - if (cwmp_main.cr_socket_desc == -1) - { - CWMP_LOG (ERROR,"Could not open server socket for Connection Requests, Error no is : %d, Error description is : %s", errno, strerror(errno)); - sleep(1); - continue; - } + for(;;) { + cr_port = (unsigned short) (cwmp_main.conf.connection_request_port); + unsigned short i = (DEFAULT_CONNECTION_REQUEST_PORT == cr_port)? 1 : 0; + //Create socket + cwmp_main.cr_socket_desc = socket(AF_INET6 , SOCK_STREAM , 0); + if (cwmp_main.cr_socket_desc == -1) + { + CWMP_LOG (ERROR,"Could not open server socket for Connection Requests, Error no is : %d, Error description is : %s", errno, strerror(errno)); + sleep(1); + continue; + } - fcntl(cwmp_main.cr_socket_desc, F_SETFD, fcntl(cwmp_main.cr_socket_desc, F_GETFD) | FD_CLOEXEC); + fcntl(cwmp_main.cr_socket_desc, F_SETFD, fcntl(cwmp_main.cr_socket_desc, F_GETFD) | FD_CLOEXEC); - int reusaddr = 1; - if (setsockopt(cwmp_main.cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0) - { - CWMP_LOG (WARNING,"setsockopt(SO_REUSEADDR) failed"); - } + int reusaddr = 1; + if (setsockopt(cwmp_main.cr_socket_desc, SOL_SOCKET, SO_REUSEADDR, &reusaddr, sizeof(int)) < 0) + { + CWMP_LOG (WARNING,"setsockopt(SO_REUSEADDR) failed"); + } - //Prepare the sockaddr_in structure - server.sin6_family = AF_INET6; - server.sin6_addr=in6addr_any; + //Prepare the sockaddr_in structure + server.sin6_family = AF_INET6; + server.sin6_addr=in6addr_any; - for(;;i++) { - server.sin6_port = htons(cr_port); - //Bind - if( bind(cwmp_main.cr_socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0) - { - //print the error message - CWMP_LOG (ERROR,"Could not bind server socket on the port %d, Error no is : %d, Error description is : %s", cr_port, errno, strerror(errno)); - cr_port = DEFAULT_CONNECTION_REQUEST_PORT + i; - CWMP_LOG (INFO,"Trying to use another connection request port: %d", cr_port); - continue; - } - break; - } - break; - } - char buf[64]; - sprintf(buf,UCI_CPE_PORT_PATH"=%d", cr_port); - uci_set_state_value(buf); - connection_request_port_value_change(&cwmp_main, cr_port); - CWMP_LOG (INFO,"Connection Request server initiated with the port: %d", cr_port); + for(;;i++) { + server.sin6_port = htons(cr_port); + //Bind + if( bind(cwmp_main.cr_socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0) + { + //print the error message + CWMP_LOG (ERROR,"Could not bind server socket on the port %d, Error no is : %d, Error description is : %s", cr_port, errno, strerror(errno)); + cr_port = DEFAULT_CONNECTION_REQUEST_PORT + i; + CWMP_LOG (INFO,"Trying to use another connection request port: %d", cr_port); + continue; + } + break; + } + break; + } + char buf[64]; + sprintf(buf,UCI_CPE_PORT_PATH"=%d", cr_port); + uci_set_state_value(buf); + connection_request_port_value_change(&cwmp_main, cr_port); + CWMP_LOG (INFO,"Connection Request server initiated with the port: %d", cr_port); } void http_server_listen(void) { - int client_sock , c; - static int cr_request = 0; - static time_t restrict_start_time = 0; - time_t current_time; - bool service_available; - struct sockaddr_in6 client; + int client_sock , c; + static int cr_request = 0; + static time_t restrict_start_time = 0; + time_t current_time; + bool service_available; + struct sockaddr_in6 client; - //Listen - listen(cwmp_main.cr_socket_desc , 3); + //Listen + listen(cwmp_main.cr_socket_desc , 3); - //Accept and incoming connection - c = sizeof(struct sockaddr_in); - while( (client_sock = accept(cwmp_main.cr_socket_desc, (struct sockaddr *)&client, (socklen_t*)&c)) ) - { - current_time = time(NULL); - service_available = true; - if ((restrict_start_time==0) || - ((current_time-restrict_start_time) > CONNECTION_REQUEST_RESTRICT_PERIOD)) - { - restrict_start_time = current_time; - cr_request = 1; - } - else - { - cr_request++; - if (cr_request > CONNECTION_REQUEST_RESTRICT_REQUEST) - { - restrict_start_time = current_time; - service_available = false; - } - } - http_cr_new_client(client_sock, service_available); - close(client_sock); - } + //Accept and incoming connection + c = sizeof(struct sockaddr_in); + while( (client_sock = accept(cwmp_main.cr_socket_desc, (struct sockaddr *)&client, (socklen_t*)&c)) ) + { + current_time = time(NULL); + service_available = true; + if ((restrict_start_time==0) || + ((current_time-restrict_start_time) > CONNECTION_REQUEST_RESTRICT_PERIOD)) + { + restrict_start_time = current_time; + cr_request = 1; + } + else + { + cr_request++; + if (cr_request > CONNECTION_REQUEST_RESTRICT_REQUEST) + { + restrict_start_time = current_time; + service_available = false; + } + } + http_cr_new_client(client_sock, service_available); + close(client_sock); + } - if (client_sock < 0) - { - CWMP_LOG(ERROR,"Could not accept connections for Connection Requests!"); - return; - } + if (client_sock < 0) + { + CWMP_LOG(ERROR,"Could not accept connections for Connection Requests!"); + return; + } } diff --git a/inc/cwmp.h b/inc/cwmp.h index c8fc60e..8638151 100644 --- a/inc/cwmp.h +++ b/inc/cwmp.h @@ -19,6 +19,7 @@ #include #include #include +#include "dmcwmp.h" #ifdef XMPP_ENABLE #include #endif @@ -92,17 +93,6 @@ enum action RESTART, }; -enum end_session { - END_SESSION_REBOOT = 1, - END_SESSION_EXTERNAL_ACTION = 1<<1, - END_SESSION_RELOAD = 1<<2, - END_SESSION_FACTORY_RESET = 1<<3, - END_SESSION_IPPING_DIAGNOSTIC = 1<<4, - END_SESSION_DOWNLOAD_DIAGNOSTIC = 1<<5, - END_SESSION_UPLOAD_DIAGNOSTIC = 1<<6, - END_SESSION_X_FACTORY_RESET_SOFT = 1<<7 -}; - enum cwmp_start { CWMP_START_BOOT = 1, CWMP_START_PERIODIC = 2 @@ -307,7 +297,6 @@ typedef struct session { mxml_node_t *body_in; bool hold_request; bool digest_auth; - unsigned int end_session; int fault_code; int error; } session; @@ -319,18 +308,12 @@ typedef struct rpc { struct list_head *list_set_value_fault; } rpc; -typedef struct execute_end_session { - struct list_head list; - int action; - void *data; - void (*function)(int, void*); -} execute_end_session; - extern int ip_version; #define ARRAYSIZEOF(a) (sizeof(a) / sizeof((a)[0])) +#ifndef FREE #define FREE(x) do { free(x); x = NULL; } while (0) +#endif -extern struct list_head list_execute_end_session; extern struct cwmp cwmp_main; extern const struct EVENT_CONST_STRUCT EVENT_CONST [__EVENT_IDX_MAX]; extern struct list_head list_lw_value_change; @@ -338,13 +321,6 @@ extern struct list_head list_value_change; extern pthread_mutex_t mutex_value_change; int cwmp_config_reload(struct cwmp *cwmp); -int cwmp_move_session_to_session_send (struct cwmp *cwmp, struct session *session); -int cwmp_schedule_rpc (struct cwmp *cwmp, struct session *session); -int run_session_end_func (struct session *session); -int cwmp_move_session_to_session_queue (struct cwmp *cwmp, struct session *session); -int cwmp_session_destructor (struct cwmp *cwmp, struct session *session); -int dm_add_end_session(void(*function)(int a, void *d), int action, void *data); -int apply_end_session(); struct rpc *cwmp_add_session_rpc_cpe (struct session *session, int type); struct session *cwmp_add_queue_session (struct cwmp *cwmp); struct rpc *cwmp_add_session_rpc_acs (struct session *session, int type); @@ -355,24 +331,22 @@ void cwmp_save_event_container (struct cwmp *cwmp,struct event_container *event_ void *thread_event_periodic (void *v); void cwmp_add_notification(void); int netlink_init(void); -int netlink_init_v6(void); char * mix_get_time(void); char * mix_get_time_of(time_t t_time); void *thread_exit_program (void *v); void connection_request_ip_value_change(struct cwmp *cwmp, int version); void connection_request_port_value_change(struct cwmp *cwmp, int port); void add_dm_parameter_tolist(struct list_head *head, char *param_name, char *param_data, char *param_type); -void cwmp_set_end_session (unsigned int end_session_flag); void *thread_handle_notify(void *v); int zlib_compress (char *message, unsigned char **zmsg, int *zlen, int type); int cwmp_get_int_event_code(char *code); -int cwmp_apply_acs_changes (); +int cwmp_dm_ctx_init(struct cwmp *cwmp, struct dmctx *ctx); +int cwmp_dm_ctx_clean(struct cwmp *cwmp, struct dmctx *ctx); +int cwmp_apply_acs_changes(); +int cwmp_move_session_to_session_send (struct cwmp *cwmp, struct session *session); +int cwmp_schedule_rpc (struct cwmp *cwmp, struct session *session); +int run_session_end_func (struct session *session); +int cwmp_move_session_to_session_queue (struct cwmp *cwmp, struct session *session); +int cwmp_session_destructor (struct cwmp *cwmp, struct session *session); int cwmp_init(int argc, char** argv,struct cwmp *cwmp); -int cwmp_config_reload(struct cwmp *cwmp); -int uci_get_value(char *cmd,char **value); -int uci_set_state_value(char *cmd); -int uci_get_state_value(char *cmd,char **value); -int save_acs_bkp_config(struct cwmp *cwmp); -int get_instance_mode_config(); -int get_amd_version_config(); #endif /* _CWMP_H__ */ diff --git a/inc/diagnostic.h b/inc/diagnostic.h index 42feeaa..08f61fc 100644 --- a/inc/diagnostic.h +++ b/inc/diagnostic.h @@ -10,14 +10,6 @@ #ifndef __DIAGNOSTIC__H #define __DIAGNOSTIC__H -#define FUNCTION_PATH "/usr/share/icwmp/functions/ipping_launch" -#define DOWNLOAD_DIAGNOSTIC_PATH "/usr/share/icwmp/functions/download_launch" -#define DOWNLOAD_DUMP_FILE "/tmp/download_dump" -#define IPPING_STOP DMCMD("/bin/sh", 2, FUNCTION_PATH, "stop"); -#define DOWNLOAD_DIAGNOSTIC_STOP DMCMD("/bin/sh", 2, DOWNLOAD_DIAGNOSTIC_PATH, "stop"); -#define UPLOAD_DIAGNOSTIC_PATH "/usr/share/icwmp/functions/upload_launch" -#define UPLOAD_DUMP_FILE "/tmp/upload_dump" -#define UPLOAD_DIAGNOSTIC_STOP DMCMD("/bin/sh", 2, UPLOAD_DIAGNOSTIC_PATH, "stop"); #define default_date_format "AAAA-MM-JJTHH:MM:SS.000000Z" #define default_date_size sizeof(default_date_format) + 1 #define FTP_SIZE_RESPONSE "213" diff --git a/inc/log.h b/inc/log.h index 221a818..720192d 100644 --- a/inc/log.h +++ b/inc/log.h @@ -68,9 +68,11 @@ static inline void trace_empty_func() #if TRACE_TYPE == 2 #define TRACE(MESSAGE,args...) do { \ const char *A[] = {MESSAGE}; \ - printf("TRACE: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\ + fprintf(stderr, "TRACE: %s %s %d ",__FUNCTION__,__FILE__,__LINE__); \ if(sizeof(A) > 0) \ - printf(*A,##args); \ + fprintf(stderr, *A,##args); \ + fprintf(stderr, "\n"); \ + fflush(stderr); \ } while(0) #elif TRACE_TYPE == 1 #define TRACE(MESSAGE, ...) printf(MESSAGE, ## __VA_ARGS__) diff --git a/inc/xml.h b/inc/xml.h index 42cded8..f61dabe 100644 --- a/inc/xml.h +++ b/inc/xml.h @@ -50,8 +50,8 @@ enum rpc_cpe_methods_idx { RPC_CPE_SCHEDULE_DOWNLOAD, RPC_CPE_CHANGE_DU_STATE, RPC_CPE_CANCEL_TRANSFER, - RPC_CPE_FAULT, RPC_CPE_X_FACTORY_RESET_SOFT, + RPC_CPE_FAULT, __RPC_CPE_MAX }; @@ -114,13 +114,6 @@ enum { FAULT_CPE_TYPE_SERVER }; -enum { - AMD_1 = 1, - AMD_2, - AMD_3, - AMD_4, - AMD_5, -}; struct rpc_cpe_method { const char *name; int (*handler)(struct session *session, struct rpc *rpc); diff --git a/netlink.c b/netlink.c index 39e88e9..deac82c 100644 --- a/netlink.c +++ b/netlink.c @@ -32,6 +32,7 @@ #include "cwmp.h" #include "http.h" #include "log.h" +#include "config.h" static void netlink_new_msg(struct uloop_fd *ufd, unsigned events); static void netlink_new_msg_v6(struct uloop_fd *ufd, unsigned events); diff --git a/scripts/icwmp.sh b/scripts/icwmp.sh index 7324072..f9c0561 100644 --- a/scripts/icwmp.sh +++ b/scripts/icwmp.sh @@ -365,7 +365,7 @@ handle_action() { if [ "$action" = "factory_reset_soft" ]; then /sbin/defaultreset -s wifi fw_redirect fw_parental passwd_user ice fi - + if [ "$action" = "reboot" ]; then sync reboot diff --git a/ubus.c b/ubus.c index b1163ea..e91270c 100644 --- a/ubus.c +++ b/ubus.c @@ -21,6 +21,7 @@ #include "log.h" #include "wepkey.h" #include "dmentry.h" +#include "netlink.h" static struct ubus_context *ctx = NULL; static struct blob_buf b; @@ -32,8 +33,6 @@ static const char *arr_session_status[] = { [SESSION_SUCCESS] = "success", }; -static const struct blobmsg_policy notify_policy[] = {}; - static int cwmp_handle_notify(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -102,7 +101,6 @@ cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj, } else { pthread_mutex_lock (&(cwmp_main.mutex_session_queue)); - dm_global_init(); cwmp_apply_acs_changes(); pthread_mutex_unlock (&(cwmp_main.mutex_session_queue)); blobmsg_add_u32(&b, "status", 0); @@ -183,9 +181,6 @@ static inline time_t get_session_status_next_time() { return ntime; } -static const struct blobmsg_policy status_policy[] = { -}; - static int cwmp_handle_status(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -304,9 +299,9 @@ cwmp_handle_inform(struct ubus_context *ctx, struct ubus_object *obj, } static const struct ubus_method freecwmp_methods[] = { - UBUS_METHOD("notify", cwmp_handle_notify, notify_policy), + UBUS_METHOD_NOARG("notify", cwmp_handle_notify), UBUS_METHOD("command", cwmp_handle_command, command_policy), - UBUS_METHOD("status", cwmp_handle_status, status_policy), + UBUS_METHOD_NOARG("status", cwmp_handle_status), UBUS_METHOD("inform", cwmp_handle_inform, inform_policy), }; @@ -330,8 +325,8 @@ ubus_init(struct cwmp *cwmp) } if (cwmp->conf.ipv6_enable) { - if (netlink_init_v6()) { - CWMP_LOG(ERROR,"netlink initialization failed"); + if (netlink_init_v6()) { + CWMP_LOG(ERROR,"netlink initialization failed"); } } ctx = ubus_connect(cwmp->conf.ubus_socket); diff --git a/xml.c b/xml.c index 9b9a828..68eb59f 100644 --- a/xml.c +++ b/xml.c @@ -631,7 +631,7 @@ int xml_prepare_lwnotification_message(char **msg_out) b = mxmlFindElement(tree, tree, "CN", NULL, NULL, MXML_DESCEND); if (!b) goto error; - c = calculate_lwnotification_cnonce(); + c = (char*)calculate_lwnotification_cnonce(); b = mxmlNewText(b, 0,c); free(c); if (!b) goto error; @@ -695,7 +695,7 @@ int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *sess struct list_head *ilist,*jlist; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); if (session==NULL || this==NULL) { @@ -797,11 +797,11 @@ int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *sess free(c); session->tree_out = tree; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); return -1; } @@ -1120,7 +1120,7 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); b = session->body_in; n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", @@ -1198,17 +1198,17 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc FREE(c); #endif - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; fault: if (cwmp_create_fault_message(session, rpc, fault_code)) goto error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return -1; } @@ -1226,7 +1226,7 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND); @@ -1306,17 +1306,17 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc FREE(c); #endif - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; fault: if (cwmp_create_fault_message(session, rpc, fault_code)) goto error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return -1; } @@ -1333,7 +1333,7 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); b = session->body_in; n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", @@ -1415,17 +1415,17 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct FREE(c); #endif - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; fault: if (cwmp_create_fault_message(session, rpc, fault_code)) goto error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return -1; } @@ -1460,7 +1460,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc int fault_code = FAULT_CPE_INTERNAL_ERROR; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); b = mxmlFindElement(session->body_in, session->body_in, "ParameterList", NULL, NULL, MXML_DESCEND); if(!b) { @@ -1554,18 +1554,18 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc if (!b) goto fault; success: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; fault: rpc->list_set_value_fault = &dmctx.list_fault_param; if (cwmp_create_fault_message(session, rpc, fault_code)) goto error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return -1; } @@ -1580,7 +1580,7 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct int fault_code = FAULT_CPE_INTERNAL_ERROR; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); /* handle cwmp:SetParameterAttributes */ if (asprintf(&c, "%s:%s", ns.cwmp, "SetParameterAttributes") == -1) @@ -1658,17 +1658,17 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct if (!b) goto fault; end_success: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; fault: if (cwmp_create_fault_message(session, rpc, fault_code)) goto error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return -1; } @@ -1686,7 +1686,7 @@ int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc) int fault_code = FAULT_CPE_INTERNAL_ERROR; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); b = session->body_in; while (b) { @@ -1737,17 +1737,17 @@ int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc) if (!b) goto fault; success: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; fault: if (cwmp_create_fault_message(session, rpc, fault_code)) goto error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return -1; } @@ -1764,7 +1764,7 @@ int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc) int fault_code = FAULT_CPE_INTERNAL_ERROR; struct dmctx dmctx = {0}; - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); b = session->body_in; while (b) { @@ -1809,17 +1809,17 @@ int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc) if (!b) goto fault; success: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; fault: if (cwmp_create_fault_message(session, rpc, fault_code)) goto error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return 0; error: - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); return -1; } @@ -1907,6 +1907,10 @@ error: return -1; } +/* + * [RPC CPE]: X_FactoryResetSoft + */ + int cwmp_handle_rpc_cpe_x_factory_reset_soft(struct session *session, struct rpc *rpc){ mxml_node_t *b; @@ -2389,13 +2393,13 @@ int cwmp_launch_upload(struct upload *pupload, struct transfer_complete **ptrans bkp_session_delete_upload(pupload); bkp_session_save(); - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(&cwmp_main, &dmctx); if (pupload->file_type[0] == '3' && pupload->f_instance && isdigit(pupload->f_instance[0])) { lookup_vcf_name(pupload->f_instance, &name); } external_upload(pupload->url, pupload->file_type, pupload->username, pupload->password, name); - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(&cwmp_main, &dmctx); external_handle_action(cwmp_handle_uploadFault); external_fetch_uploadFaultResp(&fault_code); @@ -2727,14 +2731,14 @@ void *thread_cwmp_rpc_cpe_schedule_download (void *v) pthread_mutex_unlock(&(cwmp->mutex_session_send)); pthread_cond_signal(&(cwmp->threshold_session_send)); } - else + else { cwmp_add_apply_schedule_download(current_download, ptransfer_complete->start_time); } } pthread_mutex_lock (&mutex_schedule_download); bkp_session_delete_schedule_download(current_download); - bkp_session_save(); + bkp_session_save(); list_del(&(current_download->list)); cwmp_free_schedule_download_request(current_download); pthread_mutex_unlock (&mutex_schedule_download); @@ -3129,11 +3133,11 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) free(fault_code); if( error == FAULT_CPE_NO_FAULT) { - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); du_instance = strdup(add_softwaremodules_deploymentunit(p->uuid, p->url, p->username, p->password, package_name, package_version)); dmuci_commit(); - dm_ctx_clean(&dmctx); - sprintf(du_ref,DMROOT"SoftwareModules.%s.", du_instance); + cwmp_dm_ctx_clean(cwmp, &dmctx); + sprintf(du_ref,"%sSoftwareModules.%s.", DMROOT, du_instance); res->uuid = strdup(p->uuid); res->du_ref = strdup(du_ref); res->current_state = strdup("Installed"); @@ -3154,12 +3158,12 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) } break; case DU_UNINSTALL: - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); cur_name = strdup(get_softwaremodules_name(p->uuid)); if (!cur_name || cur_name[0] == '\0') { error = FAULT_CPE_UNKNOWN_DEPLOYMENT_UNIT; res->fault = error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); break; } if((p->version)[0] == '\0') { @@ -3171,15 +3175,15 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) error = cwmp_launch_uninstall_du_state(cur_name, &res); else { error = FAULT_CPE_UNKNOWN_DEPLOYMENT_UNIT; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); break; } } if( error == FAULT_CPE_NO_FAULT) { - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); du_instance = get_softwaremodules_instance(p->uuid); - sprintf(du_ref,DMROOT"SoftwareModules.%s.", du_instance); + sprintf(du_ref,"%sSoftwareModules.%s.", DMROOT, du_instance); res->uuid = strdup(p->uuid); res->du_ref = strdup(du_ref); FREE(du_instance); @@ -3189,13 +3193,13 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) operation_endTime = mix_get_time(); res->complete_time = strdup(operation_endTime); res->fault = error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); } else { res->uuid = strdup(p->uuid); du_instance = get_softwaremodules_instance(p->uuid); - sprintf(du_ref,DMROOT"SoftwareModules.%s.", du_instance); + sprintf(du_ref,"%sSoftwareModules.%s.", DMROOT, du_instance); res->du_ref = strdup(du_ref); FREE(du_instance); res->version = strdup(p->version); @@ -3204,46 +3208,46 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) operation_endTime = mix_get_time(); //TO CHECK res->complete_time = strdup(operation_endTime); res->fault = error; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); } break; case DU_UPDATE: if ((p->url)[0] != '\0' && (p->uuid)[0] != '\0') { - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); uuid = update_softwaremodules_url(p->uuid, p->url); if(uuid == 0) { error = FAULT_CPE_UNKNOWN_DEPLOYMENT_UNIT; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); break; } cur_instance = strdup(get_softwaremodules_instance(p->uuid)); dmuci_commit(); - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); } else if ((p->url)[0] != '\0' && (p->uuid)[0] == '\0') { - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); cur_uuid = get_softwaremodules_uuid(p->url); if (!cur_uuid || cur_uuid[0] == '\0') { error = FAULT_CPE_UNKNOWN_DEPLOYMENT_UNIT; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); break; } cur_instance = strdup(get_softwaremodules_instance(p->uuid)); } else if ((p->url)[0] == '\0' && (p->uuid)[0] != '\0') { - dm_ctx_init(&dmctx); + cwmp_dm_ctx_init(cwmp, &dmctx); cur_url = strdup(get_softwaremodules_url(p->uuid)); if (cur_url == NULL || cur_url[0] == '\0') { error = FAULT_CPE_UNKNOWN_DEPLOYMENT_UNIT; - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); break; } cur_user = strdup(get_softwaremodules_username(p->uuid)); cur_pass = strdup(get_softwaremodules_pass(p->uuid)); - dm_ctx_clean(&dmctx); + cwmp_dm_ctx_clean(cwmp, &dmctx); } error = cwmp_launch_update_du_state_download((cur_url && cur_url[0]!='\0' )?cur_url:p->url, p->username, p->password, &res); if(error != FAULT_CPE_NO_FAULT) @@ -3254,7 +3258,7 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) } else res->uuid = strdup(p->uuid); - sprintf(du_ref,DMROOT"SoftwareModules.%s.", du_instance); + sprintf(du_ref,"%sSoftwareModules.%s.", DMROOT, du_instance); res->du_ref = strdup(du_ref); FREE(du_instance); res->current_state = strdup("Installed"); @@ -3271,7 +3275,7 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) } else res->uuid = strdup(p->uuid); - sprintf(du_ref,DMROOT"SoftwareModules.%s.", du_instance); + sprintf(du_ref,"%sSoftwareModules.%s.", DMROOT, du_instance); res->du_ref = strdup(du_ref); FREE(du_instance); res->current_state = strdup("Failed"); @@ -3300,7 +3304,7 @@ void *thread_cwmp_rpc_cpe_change_du_state (void *v) } } free(fault_code); - sprintf(du_ref,DMROOT"SoftwareModules.%s.", du_instance); + sprintf(du_ref,"%sSoftwareModules.%s.", DMROOT, du_instance); if (p->uuid == NULL || (p->uuid)[0] == '\0') { res->uuid = strdup(cur_url); FREE(cur_url); diff --git a/xmpp_cr.c b/xmpp_cr.c index cd1cf1e..dacd7b5 100644 --- a/xmpp_cr.c +++ b/xmpp_cr.c @@ -17,7 +17,9 @@ #include "http.h" #include "xmpp_cr.h" #include - +#ifdef XMPP_ENABLE +#include "/home/piva/projects/inteno-tr064/iop-cc/staging_dir/target-mips_mips32_uClibc-0.9.33.2/usr/include/strophe.h" +#endif int ping_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) {