From fd60013d1a0abb1cbf3a6824f3bf676b4a7d201a Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Sat, 7 Dec 2019 13:29:43 +0100 Subject: [PATCH] Ticket refs #1365: TR-157: Device.SoftwareModules. object --- bin/Makefile.am | 4 +- dmcommon.c | 1 - dmjson.h | 5 + dmmem.c | 4 +- dmtree/tr157/softwaremodules.c | 1041 ++++++++++++++++++++++++++++++++ dmtree/tr157/softwaremodules.h | 103 ++++ dmtree/tr181/device.c | 4 +- dmtree/tr181/softwaremodules.c | 244 -------- dmtree/tr181/softwaremodules.h | 37 -- dmubus.c | 16 +- json/tr181.json | 349 ++++++++++- 11 files changed, 1490 insertions(+), 318 deletions(-) create mode 100644 dmtree/tr157/softwaremodules.c create mode 100644 dmtree/tr157/softwaremodules.h delete mode 100644 dmtree/tr181/softwaremodules.c delete mode 100644 dmtree/tr181/softwaremodules.h diff --git a/bin/Makefile.am b/bin/Makefile.am index 101e2325..c1d66dea 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -22,7 +22,6 @@ libbbfdm_la_SOURCES += \ ../dmtree/tr181/device.c \ ../dmtree/tr181/deviceinfo.c \ ../dmtree/tr181/managementserver.c \ - ../dmtree/tr181/softwaremodules.c \ ../dmtree/tr181/times.c \ ../dmtree/tr181/upnp.c \ ../dmtree/tr181/x_iopsys_eu_ice.c \ @@ -73,7 +72,8 @@ endif if BBF_TR157 libbbfdm_la_SOURCES += \ - ../dmtree/tr157/bulkdata.c + ../dmtree/tr157/bulkdata.c \ + ../dmtree/tr157/softwaremodules.c endif if BBF_TR064 diff --git a/dmcommon.c b/dmcommon.c index bea961cf..3085608c 100644 --- a/dmcommon.c +++ b/dmcommon.c @@ -1444,7 +1444,6 @@ int is_section_unnamed(char *section_name) return 1; } - void add_dmmap_list_section(struct list_head *dup_list, char* section_name, char* instance) { struct dmmap_sect *dmsect; diff --git a/dmjson.h b/dmjson.h index 86452803..ca582280 100644 --- a/dmjson.h +++ b/dmjson.h @@ -54,6 +54,11 @@ char *__dmjson_get_value_array_all(json_object *mainjobj, char *delim, int argc, #define dmjson_get_value_array_all(MAINJOBJ,DELIM,ARGC,args...) \ __dmjson_get_value_array_all(MAINJOBJ, DELIM, ARGC, ##args); +#define dmjson_foreach_obj_in_array(MAINJOBJ,ARROBJ,OBJ,INDEX,ARGC,args...) \ + for (INDEX = 0, ARROBJ = NULL, OBJ = __dmjson_select_obj_in_array_idx(MAINJOBJ, &(ARROBJ), INDEX, ARGC, ##args);\ + OBJ; \ + OBJ = __dmjson_select_obj_in_array_idx(MAINJOBJ, &(ARROBJ), ++INDEX, 0)) + #define dmjson_foreach_value_in_array(MAINJOBJ,ARROBJ,VAL,INDEX,ARGC,args...) \ for (INDEX = 0, ARROBJ = NULL, VAL = __dmjson_get_value_in_array_idx(MAINJOBJ, &(ARROBJ), NULL, INDEX, ARGC, ##args);\ VAL; \ diff --git a/dmmem.c b/dmmem.c index deed292b..f033c61a 100644 --- a/dmmem.c +++ b/dmmem.c @@ -125,7 +125,7 @@ const char *file, const char *func, int line, char **s, const char *format, ... ) { - char buf[512]; + char buf[2048]; va_list arg; int ret; va_start(arg,format); @@ -148,7 +148,7 @@ const char *file, const char *func, int line, char **s, char *obj, char *lastname ) { - char buf[512]; + char buf[2048]; int olen = strlen(obj); memcpy(buf, obj, olen); int llen = strlen(lastname) + 1; diff --git a/dmtree/tr157/softwaremodules.c b/dmtree/tr157/softwaremodules.c new file mode 100644 index 00000000..6cd52723 --- /dev/null +++ b/dmtree/tr157/softwaremodules.c @@ -0,0 +1,1041 @@ +/* + * Copyright (C) 2019 iopsys Software Solutions AB + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 + * as published by the Free Software Foundation + * + * Author: Amin Ben Ramdhane + */ + +#include "dmbbf.h" +#include "dmcommon.h" +#include "dmuci.h" +#include "dmubus.h" +#include "dmjson.h" +#include "dmentry.h" +#include "softwaremodules.h" + +/* *** Device.SoftwareModules. *** */ +DMOBJ tSoftwareModulesObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/ +{"ExecEnv", &DMREAD, NULL, NULL, NULL, browseSoftwareModulesExecEnvInst, NULL, NULL, NULL, NULL, tSoftwareModulesExecEnvParams, get_exe_cenv_linker, BBFDM_BOTH}, +{"DeploymentUnit", &DMREAD, NULL, NULL, NULL, browseSoftwareModulesDeploymentUnitInst, NULL, NULL, NULL, NULL, tSoftwareModulesDeploymentUnitParams, get_du_linker, BBFDM_BOTH}, +{"ExecutionUnit", &DMREAD, NULL, NULL, NULL, browseSoftwareModulesExecutionUnitInst, NULL, NULL, NULL, tSoftwareModulesExecutionUnitObj, tSoftwareModulesExecutionUnitParams, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tSoftwareModulesParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"ExecEnvNumberOfEntries", &DMREAD, DMT_UNINT, get_SoftwareModules_ExecEnvNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{"DeploymentUnitNumberOfEntries", &DMREAD, DMT_UNINT, get_SoftwareModules_DeploymentUnitNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{"ExecutionUnitNumberOfEntries", &DMREAD, DMT_UNINT, get_SoftwareModules_ExecutionUnitNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.SoftwareModules.ExecEnv.{i}. *** */ +DMLEAF tSoftwareModulesExecEnvParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_SoftwareModulesExecEnv_Enable, set_SoftwareModulesExecEnv_Enable, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Reset", &DMWRITE, DMT_BOOL, get_SoftwareModulesExecEnv_Reset, set_SoftwareModulesExecEnv_Reset, NULL, NULL, BBFDM_CWMP}, +{"Alias", &DMWRITE, DMT_STRING, get_SoftwareModulesExecEnv_Alias, set_SoftwareModulesExecEnv_Alias, NULL, NULL, BBFDM_BOTH}, +{"Name", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_Name, NULL, NULL, NULL, BBFDM_BOTH}, +{"Type", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_Type, NULL, NULL, NULL, BBFDM_BOTH}, +{"InitialRunLevel", &DMWRITE, DMT_UNINT, get_SoftwareModulesExecEnv_InitialRunLevel, set_SoftwareModulesExecEnv_InitialRunLevel, NULL, NULL, BBFDM_BOTH}, +{"RequestedRunLevel", &DMWRITE, DMT_INT, get_SoftwareModulesExecEnv_RequestedRunLevel, set_SoftwareModulesExecEnv_RequestedRunLevel, NULL, NULL, BBFDM_CWMP}, +{"CurrentRunLevel", &DMREAD, DMT_INT, get_SoftwareModulesExecEnv_CurrentRunLevel, NULL, NULL, NULL, BBFDM_BOTH}, +{"InitialExecutionUnitRunLevel", &DMWRITE, DMT_INT, get_SoftwareModulesExecEnv_InitialExecutionUnitRunLevel, set_SoftwareModulesExecEnv_InitialExecutionUnitRunLevel, NULL, NULL, BBFDM_BOTH}, +{"Vendor", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_Vendor, NULL, NULL, NULL, BBFDM_BOTH}, +{"Version", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_Version, NULL, NULL, NULL, BBFDM_BOTH}, +{"ParentExecEnv", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_ParentExecEnv, NULL, NULL, NULL, BBFDM_BOTH}, +{"AllocatedDiskSpace", &DMREAD, DMT_INT, get_SoftwareModulesExecEnv_AllocatedDiskSpace, NULL, NULL, NULL, BBFDM_BOTH}, +{"AvailableDiskSpace", &DMREAD, DMT_INT, get_SoftwareModulesExecEnv_AvailableDiskSpace, NULL, NULL, NULL, BBFDM_BOTH}, +{"AllocatedMemory", &DMREAD, DMT_INT, get_SoftwareModulesExecEnv_AllocatedMemory, NULL, NULL, NULL, BBFDM_BOTH}, +{"AvailableMemory", &DMREAD, DMT_INT, get_SoftwareModulesExecEnv_AvailableMemory, NULL, NULL, NULL, BBFDM_BOTH}, +{"ActiveExecutionUnits", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_ActiveExecutionUnits, NULL, NULL, NULL, BBFDM_BOTH}, +//{"ProcessorRefList", &DMREAD, DMT_STRING, get_SoftwareModulesExecEnv_ProcessorRefList, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.SoftwareModules.DeploymentUnit.{i}. *** */ +DMLEAF tSoftwareModulesDeploymentUnitParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"UUID", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_UUID, NULL, NULL, NULL, BBFDM_BOTH}, +{"DUID", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_DUID, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_SoftwareModulesDeploymentUnit_Alias, set_SoftwareModulesDeploymentUnit_Alias, NULL, NULL, BBFDM_BOTH}, +{"Name", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_Name, NULL, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"Resolved", &DMREAD, DMT_BOOL, get_SoftwareModulesDeploymentUnit_Resolved, NULL, NULL, NULL, BBFDM_BOTH}, +{"URL", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_URL, NULL, NULL, NULL, BBFDM_BOTH}, +{"Description", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_Description, NULL, NULL, NULL, BBFDM_BOTH}, +{"Vendor", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_Vendor, NULL, NULL, NULL, BBFDM_BOTH}, +{"Version", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_Version, NULL, NULL, NULL, BBFDM_BOTH}, +{"VendorLogList", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_VendorLogList, NULL, NULL, NULL, BBFDM_BOTH}, +{"VendorConfigList", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_VendorConfigList, NULL, NULL, NULL, BBFDM_BOTH}, +{"ExecutionUnitList", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_ExecutionUnitList, NULL, NULL, NULL, BBFDM_BOTH}, +{"ExecutionEnvRef", &DMREAD, DMT_STRING, get_SoftwareModulesDeploymentUnit_ExecutionEnvRef, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/* *** Device.SoftwareModules.ExecutionUnit.{i}. *** */ +DMOBJ tSoftwareModulesExecutionUnitObj[] = { +/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/ +{"Extensions", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +DMLEAF tSoftwareModulesExecutionUnitParams[] = { +/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ +{"EUID", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_EUID, NULL, NULL, NULL, BBFDM_BOTH}, +{"Alias", &DMWRITE, DMT_STRING, get_SoftwareModulesExecutionUnit_Alias, set_SoftwareModulesExecutionUnit_Alias, NULL, NULL, BBFDM_BOTH}, +{"Name", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_Name, NULL, NULL, NULL, BBFDM_BOTH}, +{"ExecEnvLabel", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_ExecEnvLabel, NULL, NULL, NULL, BBFDM_BOTH}, +{"Status", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_Status, NULL, NULL, NULL, BBFDM_BOTH}, +{"RequestedState", &DMWRITE, DMT_STRING, get_SoftwareModulesExecutionUnit_RequestedState, set_SoftwareModulesExecutionUnit_RequestedState, NULL, NULL, BBFDM_CWMP}, +{"ExecutionFaultCode", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_ExecutionFaultCode, NULL, NULL, NULL, BBFDM_BOTH}, +{"ExecutionFaultMessage", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_ExecutionFaultMessage, NULL, NULL, NULL, BBFDM_BOTH}, +{"AutoStart", &DMWRITE, DMT_BOOL, get_SoftwareModulesExecutionUnit_AutoStart, set_SoftwareModulesExecutionUnit_AutoStart, NULL, NULL, BBFDM_BOTH}, +{"RunLevel", &DMWRITE, DMT_UNINT, get_SoftwareModulesExecutionUnit_RunLevel, set_SoftwareModulesExecutionUnit_RunLevel, NULL, NULL, BBFDM_BOTH}, +{"Vendor", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_Vendor, NULL, NULL, NULL, BBFDM_BOTH}, +{"Version", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_Version, NULL, NULL, NULL, BBFDM_BOTH}, +{"Description", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_Description, NULL, NULL, NULL, BBFDM_BOTH}, +{"DiskSpaceInUse", &DMREAD, DMT_INT, get_SoftwareModulesExecutionUnit_DiskSpaceInUse, NULL, NULL, NULL, BBFDM_BOTH}, +{"MemoryInUse", &DMREAD, DMT_INT, get_SoftwareModulesExecutionUnit_MemoryInUse, NULL, NULL, NULL, BBFDM_BOTH}, +{"References", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_References, NULL, NULL, NULL, BBFDM_BOTH}, +{"AssociatedProcessList", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_AssociatedProcessList, NULL, NULL, NULL, BBFDM_BOTH}, +{"VendorLogList", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_VendorLogList, NULL, NULL, NULL, BBFDM_BOTH}, +{"VendorConfigList", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_VendorConfigList, NULL, NULL, NULL, BBFDM_BOTH}, +//{"SupportedDataModelList", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_SupportedDataModelList, NULL, NULL, NULL, BBFDM_CWMP}, +{"ExecutionEnvRef", &DMREAD, DMT_STRING, get_SoftwareModulesExecutionUnit_ExecutionEnvRef, NULL, NULL, NULL, BBFDM_BOTH}, +{0} +}; + +/************************************************************************** +* LINKER +***************************************************************************/ +int get_exe_cenv_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data) { + char *name = dmjson_get_value((json_object *)data, 1, "name"); + *linker = dmstrdup(name); + return 0; + } + *linker = ""; + return 0; +} + +int get_du_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker) +{ + if (data) { + char *name = dmjson_get_value((json_object *)data, 1, "name"); + char *environment = dmjson_get_value((json_object *)data, 1, "environment"); + dmasprintf(linker, "%s-%s", name, environment); + return 0; + } + *linker = ""; + return 0; +} + +/************************************************************* + * ENTRY METHOD +/*************************************************************/ +int browseSoftwareModulesExecEnvInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + char *idx, *idx_last = NULL; + int id = 0, j = 0; + + dmubus_call("softwaremanagement", "environment", UBUS_ARGS{}, 0, &res); + if (res) { + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "environment") { + idx = handle_update_instance(1, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)du_obj, idx) == DM_STOP) + break; + } + } + return 0; +} + +int browseSoftwareModulesDeploymentUnitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + char *idx, *idx_last = NULL, buf[5]; + int id = 0, j = 0, i, incr; + + for (i = 0;; i += 100) { + sprintf(buf, "%d", i); + dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res); + if (res) { + incr = 0; + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "deployment_unit") { + incr++; + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)du_obj, idx) == DM_STOP) + break; + } + if (incr != 100) break; + } + } + return 0; +} + +int browseSoftwareModulesExecutionUnitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + char *idx, *idx_last = NULL; + int id = 0, j = 0; + + dmubus_call("softwaremanagement", "eu_list", UBUS_ARGS{}, 0, &res); + if (res) { + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "execution_unit") { + idx = handle_update_instance(2, dmctx, &idx_last, update_instance_without_section, 1, ++id); + if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)du_obj, idx) == DM_STOP) + break; + } + } + return 0; +} + +/************************************************************* + * GET & SET PARAM +/*************************************************************/ +int get_SoftwareModules_ExecEnvNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *environment = NULL; + size_t nbre_env = 0; + + dmubus_call("softwaremanagement", "environment", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = "0"); + json_object_object_get_ex(res, "environment", &environment); + nbre_env = json_object_array_length(environment); + dmasprintf(value, "%d", nbre_env); + return 0; +} + +int get_SoftwareModules_DeploymentUnitNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *deployment_unit = NULL; + size_t nbre_du = 0, total_du = 0; + char buf[5]; + int i; + + for (i = 0;; i += 100) { + sprintf(buf, "%d", i); + dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res); + DM_ASSERT(res, *value = "0"); + json_object_object_get_ex(res, "deployment_unit", &deployment_unit); + nbre_du = json_object_array_length(deployment_unit); + total_du = total_du + nbre_du; + if (nbre_du != 100) break; + } + dmasprintf(value, "%d", total_du); + return 0; +} + +int get_SoftwareModules_ExecutionUnitNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *execution_unit = NULL; + size_t nbre_env = 0; + + dmubus_call("softwaremanagement", "eu_list", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = "0"); + json_object_object_get_ex(res, "execution_unit", &execution_unit); + nbre_env = json_object_array_length(execution_unit); + dmasprintf(value, "%d", nbre_env); + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.Enable!UBUS:softwaremanagement/environment//environment[i-1].status*/ +int get_SoftwareModulesExecEnv_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "status"); + if (strcmp(*value, "Up") == 0) + *value = "1"; + else + *value = "0"; + return 0; +} + +int set_SoftwareModulesExecEnv_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *env_name; + switch (action) { + case VALUECHECK: + break; + case VALUESET: + env_name = dmjson_get_value((json_object *)data, 1, "name"); + if (strcmp(env_name, "OpenWRT_Linux")) { + if (value) + dmcmd_no_wait("/usr/bin/lxc-start", 2, "-n", env_name); + else + dmcmd_no_wait("/usr/bin/lxc-stop", 2, "-n", env_name); + } + break; + } + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.Status!UBUS:softwaremanagement/environment//environment[i-1].status*/ +int get_SoftwareModulesExecEnv_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "status"); + return 0; +} + +int get_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +int set_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + char *env_name; + + switch (action) { + case VALUECHECK: + break; + case VALUESET: + env_name = dmjson_get_value((json_object *)data, 1, "name"); + if (strcmp(env_name, "OpenWRT_Linux") == 0) { + if (value) dmcmd_no_wait("/sbin/defaultreset", 0); + } + break; + } + return 0; +} + +int get_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *env_name, *name; + + name = dmjson_get_value((json_object *)data, 1, "name"); + uci_path_foreach_sections(bbfdm, "dmmap", "environment", s) { + dmuci_get_value_by_section_string(s, "name", &env_name); + if (strcmp(env_name, name) == 0) { + dmuci_get_value_by_section_string(s, "alias", value); + return 0; + } + } + return 0; +} + +int set_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL, *dmmap = NULL; + char *name, *v; + int found = 0; + + switch (action) { + case VALUECHECK: + break; + case VALUESET: + name = dmjson_get_value((json_object *)data, 1, "name"); + uci_path_foreach_option_eq(bbfdm, "dmmap", "environment", "name", name, s) { + dmuci_set_value_by_section_bbfdm(s, "alias", value); + found = 1; + } + if(!found) { + dmuci_add_section_bbfdm("dmmap", "environment", &dmmap, &v); + dmuci_set_value_by_section(dmmap, "name", name); + dmuci_set_value_by_section(dmmap, "alias", value); + } + break; + } + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.Name!UBUS:softwaremanagement/environment//environment[i-1].name*/ +int get_SoftwareModulesExecEnv_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "name"); + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.Type!UBUS:softwaremanagement/environment//environment[i-1].type*/ +int get_SoftwareModulesExecEnv_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "type"); + return 0; +} + +int get_SoftwareModulesExecEnv_InitialRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "-1"; + return 0; +} + +int set_SoftwareModulesExecEnv_InitialRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + break; + case VALUESET: + break; + } + return 0; +} + +int get_SoftwareModulesExecEnv_RequestedRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "-1"; + return 0; +} + +int set_SoftwareModulesExecEnv_RequestedRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + break; + case VALUESET: + break; + } + return 0; +} + +int get_SoftwareModulesExecEnv_CurrentRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "-1"; + return 0; +} + +int get_SoftwareModulesExecEnv_InitialExecutionUnitRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "-1"; + return 0; +} + +int set_SoftwareModulesExecEnv_InitialExecutionUnitRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.Vendor!UBUS:softwaremanagement/environment//environment[i-1].vendor*/ +int get_SoftwareModulesExecEnv_Vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "vendor"); + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.Version!UBUS:softwaremanagement/environment//environment[i-1].version*/ +int get_SoftwareModulesExecEnv_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "version"); + return 0; +} + +int get_SoftwareModulesExecEnv_ParentExecEnv(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *env_name = dmjson_get_value((json_object *)data, 1, "name"); + *value = ""; + if (strcmp(env_name, "OpenWRT_Linux")) { + char *linker = dmstrdup(env_name); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cSoftwareModules%cExecEnv%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) { + *value = ""; + return 0; + } + } + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.AllocatedDiskSpace!UBUS:softwaremanagement/environment//environment[i-1].allocateddiskspace*/ +int get_SoftwareModulesExecEnv_AllocatedDiskSpace(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "allocateddiskspace"); + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.AvailableDiskSpace!UBUS:softwaremanagement/environment//environment[i-1].availablediskspace*/ +int get_SoftwareModulesExecEnv_AvailableDiskSpace(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "availablediskspace"); + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.AllocatedMemory!UBUS:softwaremanagement/environment//environment[i-1].allocatedmemory*/ +int get_SoftwareModulesExecEnv_AllocatedMemory(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "allocatedmemory"); + return 0; +} + +/*#Device.SoftwareModules.ExecEnv.{i}.AvailableMemory!UBUS:softwaremanagement/environment//environment[i-1].availablememory*/ +int get_SoftwareModulesExecEnv_AvailableMemory(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "availablememory"); + return 0; +} + +int get_SoftwareModulesExecEnv_ActiveExecutionUnits(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + int id = 0, j = 0, env = 0; + char *environment, *eu_list = NULL, *eu_list_tmp = NULL; + + char *curr_env = dmjson_get_value((json_object *)data, 1, "name"); + dmubus_call("softwaremanagement", "eu_list", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "execution_unit") { + env++; + environment = dmjson_get_value(du_obj, 1, "environment"); + if (strcmp(environment, curr_env) == 0) { + if(!eu_list) { + dmasprintf(&eu_list, "%s", dm_print_path("%s%cSoftwareModules%cExecutionUnit%c%d%c", dmroot, dm_delim, dm_delim, dm_delim, env, dm_delim)); + } else { + eu_list_tmp = dmstrdup(eu_list); + dmfree(eu_list); + dmasprintf(&eu_list, "%s,%s", eu_list_tmp, dm_print_path("%s%cSoftwareModules%cExecutionUnit%c%d%c", dmroot, dm_delim, dm_delim, dm_delim, env, dm_delim)); + dmfree(eu_list_tmp); + } + } + } + if(eu_list) + *value = eu_list; + return 0; +} + +int get_SoftwareModulesExecEnv_ProcessorRefList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.UUID!UBUS:softwaremanagement/du_list//deployment_unit[i-1].uuid*/ +int get_SoftwareModulesDeploymentUnit_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "uuid"); + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.DUID!UBUS:softwaremanagement/du_list//deployment_unit[i-1].duid*/ +int get_SoftwareModulesDeploymentUnit_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "duid"); + return 0; +} + +int get_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *du_name, *du_env, *environment, *name; + + name = dmjson_get_value((json_object *)data, 1, "name"); + environment = dmjson_get_value((json_object *)data, 1, "environment"); + uci_path_foreach_sections(bbfdm, "dmmap", "deployment_unit", s) { + dmuci_get_value_by_section_string(s, "name", &du_name); + dmuci_get_value_by_section_string(s, "environment", &du_env); + if ((strcmp(du_name, name) == 0) && (strcmp(du_env, environment) == 0)) { + dmuci_get_value_by_section_string(s, "alias", value); + return 0; + } + } + return 0; +} + +int set_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL, *dmmap = NULL; + char *du_name, *du_env, *environment, *name, *v; + int found = 0; + + switch (action) { + case VALUECHECK: + break; + case VALUESET: + name = dmjson_get_value((json_object *)data, 1, "name"); + environment = dmjson_get_value((json_object *)data, 1, "environment"); + uci_path_foreach_sections(bbfdm, "dmmap", "deployment_unit", s) { + dmuci_get_value_by_section_string(s, "name", &du_name); + dmuci_get_value_by_section_string(s, "environment", &du_env); + if ((strcmp(du_name, name) == 0) && (strcmp(du_env, environment) == 0)) { + dmuci_set_value_by_section_bbfdm(s, "alias", value); + found = 1; + break; + } + } + if(!found) { + dmuci_add_section_bbfdm("dmmap", "deployment_unit", &dmmap, &v); + dmuci_set_value_by_section(dmmap, "name", name); + dmuci_set_value_by_section(dmmap, "environment", environment); + dmuci_set_value_by_section(dmmap, "alias", value); + } + break; + } + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.Name!UBUS:softwaremanagement/du_list//deployment_unit[i-1].name*/ +int get_SoftwareModulesDeploymentUnit_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "name"); + return 0; +} + +int get_SoftwareModulesDeploymentUnit_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Installed"; + return 0; +} + +int get_SoftwareModulesDeploymentUnit_Resolved(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "1"; + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.URL!UBUS:softwaremanagement/du_list//deployment_unit[i-1].url*/ +int get_SoftwareModulesDeploymentUnit_URL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "url"); + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.Description!UBUS:softwaremanagement/du_list//deployment_unit[i-1].description*/ +int get_SoftwareModulesDeploymentUnit_Description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "description"); + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.Vendor!UBUS:softwaremanagement/du_list//deployment_unit[i-1].vendor*/ +int get_SoftwareModulesDeploymentUnit_Vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "vendor"); + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.Version!UBUS:softwaremanagement/du_list//deployment_unit[i-1].version*/ +int get_SoftwareModulesDeploymentUnit_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "version"); + return 0; +} + +int get_SoftwareModulesDeploymentUnit_VendorLogList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.VendorConfigList!UBUS:softwaremanagement/du_list//deployment_unit[i-1].config*/ +int get_SoftwareModulesDeploymentUnit_VendorConfigList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *name, *vcf_instance, *config; + + *value = ""; + config = dmjson_get_value((json_object *)data, 1, "config"); + if (!strlen(config)) + return 0; + + uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) { + dmuci_get_value_by_section_string(s, "name", &name); + if (strcmp(name, config) == 0) { + dmuci_get_value_by_section_string(s, "vcf_instance", &vcf_instance); + *value = strdup(dm_print_path("%s%cDeviceInfo%cVendorConfigFile%c%s%c", dmroot, dm_delim, dm_delim, dm_delim, vcf_instance, dm_delim)); + break; + } + } + return 0; +} + +int get_SoftwareModulesDeploymentUnit_ExecutionUnitList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + char *environment, *name, *curr_environment, *curr_name; + int j = 0, env = 0; + + curr_name = dmjson_get_value((json_object *)data, 1, "name"); + curr_environment = dmjson_get_value((json_object *)data, 1, "environment"); + + dmubus_call("softwaremanagement", "eu_list", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "execution_unit") { + env++; + name = dmjson_get_value(du_obj, 1, "name"); + environment = dmjson_get_value(du_obj, 1, "environment"); + if ((strcmp(name, curr_name) == 0) && (strcmp(environment, curr_environment) == 0)) { + dmasprintf(value, "%s", dm_print_path("%s%cSoftwareModules%cExecutionUnit%c%d%c", dmroot, dm_delim, dm_delim, dm_delim, env, dm_delim)); + break; + } + } + return 0; +} + +/*#Device.SoftwareModules.DeploymentUnit.{i}.ExecutionEnvRef!UBUS:softwaremanagement/du_list//deployment_unit[i-1].environment*/ +int get_SoftwareModulesDeploymentUnit_ExecutionEnvRef(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker = dmjson_get_value((json_object *)data, 1, "environment"); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cSoftwareModules%cExecEnv%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) { + *value = ""; + return 0; + } + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.EUID!UBUS:softwaremanagement/eu_list//execution_unit[i-1].euid*/ +int get_SoftwareModulesExecutionUnit_EUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "euid"); + return 0; +} + +int get_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *eu_euid, *eu_env, *environment, *euid; + + euid = dmjson_get_value((json_object *)data, 1, "euid"); + environment = dmjson_get_value((json_object *)data, 1, "environment"); + uci_path_foreach_sections(bbfdm, "dmmap", "execution_unit", s) { + dmuci_get_value_by_section_string(s, "euid", &eu_euid); + dmuci_get_value_by_section_string(s, "environment", &eu_env); + if ((strcmp(eu_euid, euid) == 0) && (strcmp(eu_env, environment) == 0)) { + dmuci_get_value_by_section_string(s, "alias", value); + return 0; + } + } + return 0; +} + +int set_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + struct uci_section *s = NULL, *dmmap = NULL; + char *eu_euid, *eu_env, *environment, *euid, *v; + int found = 0; + + switch (action) { + case VALUECHECK: + break; + case VALUESET: + euid = dmjson_get_value((json_object *)data, 1, "euid"); + environment = dmjson_get_value((json_object *)data, 1, "environment"); + uci_path_foreach_sections(bbfdm, "dmmap", "execution_unit", s) { + dmuci_get_value_by_section_string(s, "euid", &eu_euid); + dmuci_get_value_by_section_string(s, "environment", &eu_env); + if ((strcmp(eu_euid, euid) == 0) && (strcmp(eu_env, environment) == 0)) { + dmuci_set_value_by_section_bbfdm(s, "alias", value); + found = 1; + break; + } + } + if(!found) { + dmuci_add_section_bbfdm("dmmap", "execution_unit", &dmmap, &v); + dmuci_set_value_by_section(dmmap, "euid", euid); + dmuci_set_value_by_section(dmmap, "environment", environment); + dmuci_set_value_by_section(dmmap, "alias", value); + } + break; + } + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.Name!UBUS:softwaremanagement/eu_list//execution_unit[i-1].name*/ +int get_SoftwareModulesExecutionUnit_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "name"); + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.ExecEnvLabel!UBUS:softwaremanagement/eu_list//execution_unit[i-1].euid*/ +int get_SoftwareModulesExecutionUnit_ExecEnvLabel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "euid"); + return 0; +} + +int get_SoftwareModulesExecutionUnit_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Active"; + return 0; +} + +int get_SoftwareModulesExecutionUnit_RequestedState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "Active"; + return 0; +} + +int set_SoftwareModulesExecutionUnit_RequestedState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + break; + case VALUESET: + break; + } + return 0; +} + +int get_SoftwareModulesExecutionUnit_ExecutionFaultCode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "NoFault"; + return 0; +} + +int get_SoftwareModulesExecutionUnit_ExecutionFaultMessage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +int get_SoftwareModulesExecutionUnit_AutoStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +int set_SoftwareModulesExecutionUnit_AutoStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + break; + case VALUESET: + break; + } + return 0; +} + +int get_SoftwareModulesExecutionUnit_RunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = "0"; + return 0; +} + +int set_SoftwareModulesExecutionUnit_RunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +{ + switch (action) { + case VALUECHECK: + break; + case VALUESET: + break; + } + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.Vendor!UBUS:softwaremanagement/eu_list//execution_unit[i-1].vendor*/ +int get_SoftwareModulesExecutionUnit_Vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "vendor"); + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.Version!UBUS:softwaremanagement/eu_list//execution_unit[i-1].version*/ +int get_SoftwareModulesExecutionUnit_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "version"); + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.Description!UBUS:softwaremanagement/eu_list//execution_unit[i-1].description*/ +int get_SoftwareModulesExecutionUnit_Description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "description"); + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.DiskSpaceInUse!UBUS:softwaremanagement/eu_list//execution_unit[i-1].disk_space*/ +int get_SoftwareModulesExecutionUnit_DiskSpaceInUse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "disk_space"); + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.MemoryInUse!UBUS:softwaremanagement/eu_list//execution_unit[i-1].memory_space*/ +int get_SoftwareModulesExecutionUnit_MemoryInUse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = dmjson_get_value((json_object *)data, 1, "memory_space"); + return 0; +} + +int get_SoftwareModulesExecutionUnit_References(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + char *environment, *name, *curr_environment, *curr_name, buf[5]; + int j = 0, env = 0, i, incr; + + curr_name = dmjson_get_value((json_object *)data, 1, "name"); + curr_environment = dmjson_get_value((json_object *)data, 1, "environment"); + + for (i = 0;; i += 100) { + sprintf(buf, "%d", i); + dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res); + DM_ASSERT(res, *value = ""); + if (res) { + incr = 0; + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "deployment_unit") { + incr++; + env++; + name = dmjson_get_value(du_obj, 1, "name"); + environment = dmjson_get_value(du_obj, 1, "environment"); + if ((strcmp(name, curr_name) == 0) && (strcmp(environment, curr_environment) == 0)) { + dmasprintf(value, "%s", dm_print_path("%s%cSoftwareModules%cDeploymentUnit%c%d%c", dmroot, dm_delim, dm_delim, dm_delim, env, dm_delim)); + break; + } + } + if (incr != 100) break; + } + } + return 0; +} + +int get_SoftwareModulesExecutionUnit_AssociatedProcessList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + json_object *res = NULL, *processes_obj = NULL, *arrobj = NULL; + char *euid, *pid; + int j = 0, process = 0; + + euid = dmjson_get_value((json_object *)data, 1, "euid"); + dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res); + DM_ASSERT(res, *value = ""); + dmjson_foreach_obj_in_array(res, arrobj, processes_obj, j, 1, "processes") { + process++; + pid = dmjson_get_value(processes_obj, 1, "PID"); + if (strcmp(euid, pid) == 0) { + dmasprintf(value, "%s", dm_print_path("%s%cDeviceInfo%cProcessStatus%cProcess%c%d%c", dmroot, dm_delim, dm_delim, dm_delim, dm_delim, process, dm_delim)); + break; + } + } + return 0; +} + +int get_SoftwareModulesExecutionUnit_VendorLogList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + *value = ""; + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.VendorConfigList!UBUS:softwaremanagement/eu_list//execution_unit[i-1].config*/ +int get_SoftwareModulesExecutionUnit_VendorConfigList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + struct uci_section *s = NULL; + char *name, *vcf_instance, *config; + + *value = ""; + config = dmjson_get_value((json_object *)data, 1, "config"); + if (!strlen(config)) + return 0; + + uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) { + dmuci_get_value_by_section_string(s, "name", &name); + if (strcmp(name, config) == 0) { + dmuci_get_value_by_section_string(s, "vcf_instance", &vcf_instance); + *value = strdup(dm_print_path("%s%cDeviceInfo%cVendorConfigFile%c%s%c", dmroot, dm_delim, dm_delim, dm_delim, vcf_instance, dm_delim)); + break; + } + } + return 0; +} + +int get_SoftwareModulesExecutionUnit_SupportedDataModelList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + //TODO + return 0; +} + +/*#Device.SoftwareModules.ExecutionUnit.{i}.ExecutionEnvRef!UBUS:softwaremanagement/eu_list//execution_unit[i-1].environment*/ +int get_SoftwareModulesExecutionUnit_ExecutionEnvRef(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + char *linker = dmjson_get_value((json_object *)data, 1, "environment"); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cSoftwareModules%cExecEnv%c", dmroot, dm_delim, dm_delim, dm_delim), linker, value); + if (*value == NULL) { + *value = ""; + return 0; + } + return 0; +} + +char *get_deployment_unit_reference(struct dmctx *ctx, char *package_name, char *package_env) +{ + char *linker, *value; + dmasprintf(&linker, "%s-%s", package_name, package_env); + adm_entry_get_linker_param(ctx, dm_print_path("%s%cSoftwareModules%cDeploymentUnit%c", dmroot, dm_delim, dm_delim, dm_delim), linker, &value); + return value; +} + +void get_deployment_unit_name_version(char *uuid, char **name, char **version, char **env) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + int id = 0, j = 0, i, incr; + char *cur_uuid, buf[5]; + + for (i = 0;; i += 100) { + sprintf(buf, "%d", i); + dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res); + if (res) { + incr = 0; + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "deployment_unit") { + incr++; + cur_uuid = dmjson_get_value(du_obj, 1, "uuid"); + if (strcmp(cur_uuid, uuid) == 0) { + *name = dmjson_get_value(du_obj, 1, "name"); + *version = dmjson_get_value(du_obj, 1, "version"); + *env = dmjson_get_value(du_obj, 1, "environment"); + return; + } + } + if (incr != 100) break; + } + } +} + +char *get_softwaremodules_uuid(char *url) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + int id = 0, j = 0, i, incr; + char *cur_url, *uuid = "", buf[5]; + + for (i = 0;; i += 100) { + sprintf(buf, "%d", i); + dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res); + if (res) { + incr = 0; + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "deployment_unit") { + incr++; + cur_url = dmjson_get_value(du_obj, 1, "url"); + if (strcmp(cur_url, url) == 0) { + uuid = dmjson_get_value(du_obj, 1, "uuid"); + return uuid; + } + } + if (incr != 100) break; + } + + } + return uuid; +} + +char *get_softwaremodules_url(char *uuid) +{ + json_object *res = NULL, *du_obj = NULL, *arrobj = NULL; + int id = 0, j = 0, i, incr; + char *cur_uuid, *url = "", buf[5]; + + for (i = 0;; i += 100) { + sprintf(buf, "%d", i); + dmubus_call("softwaremanagement", "du_list", UBUS_ARGS{{"index", buf, Integer}}, 1, &res); + if (res) { + incr = 0; + dmjson_foreach_obj_in_array(res, arrobj, du_obj, j, 1, "deployment_unit") { + incr++; + cur_uuid = dmjson_get_value(du_obj, 1, "uuid"); + if (strcmp(cur_uuid, uuid) == 0) { + url = dmjson_get_value(du_obj, 1, "url"); + return url; + } + } + if (incr != 100) break; + } + } + return url; +} diff --git a/dmtree/tr157/softwaremodules.h b/dmtree/tr157/softwaremodules.h new file mode 100644 index 00000000..d33f1f37 --- /dev/null +++ b/dmtree/tr157/softwaremodules.h @@ -0,0 +1,103 @@ +/* +* 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) 2019 iopsys Software Solutions AB +* Author: Amin Ben Ramdhane +*/ + +#ifndef __SOFTWAREMODULES_H +#define __SOFTWAREMODULES_H + +extern DMOBJ tSoftwareModulesObj[]; +extern DMLEAF tSoftwareModulesParams[]; +extern DMLEAF tSoftwareModulesExecEnvParams[]; +extern DMLEAF tSoftwareModulesDeploymentUnitParams[]; +extern DMOBJ tSoftwareModulesExecutionUnitObj[]; +extern DMLEAF tSoftwareModulesExecutionUnitParams[]; + +int browseSoftwareModulesExecEnvInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseSoftwareModulesDeploymentUnitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); +int browseSoftwareModulesExecutionUnitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); + +int get_SoftwareModules_ExecEnvNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModules_DeploymentUnitNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModules_ExecutionUnitNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecEnv_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecEnv_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecEnv_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecEnv_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecEnv_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_Type(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_InitialRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecEnv_InitialRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecEnv_RequestedRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecEnv_RequestedRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecEnv_CurrentRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_InitialExecutionUnitRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecEnv_InitialExecutionUnitRunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecEnv_Vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_ParentExecEnv(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_AllocatedDiskSpace(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_AvailableDiskSpace(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_AllocatedMemory(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_AvailableMemory(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_ActiveExecutionUnits(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecEnv_ProcessorRefList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_UUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesDeploymentUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesDeploymentUnit_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_Resolved(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_URL(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_Description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_Vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_VendorLogList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_VendorConfigList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_ExecutionUnitList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesDeploymentUnit_ExecutionEnvRef(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_EUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecutionUnit_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecutionUnit_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_ExecEnvLabel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_RequestedState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecutionUnit_RequestedState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecutionUnit_ExecutionFaultCode(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_ExecutionFaultMessage(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_AutoStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecutionUnit_AutoStart(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecutionUnit_RunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int set_SoftwareModulesExecutionUnit_RunLevel(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); +int get_SoftwareModulesExecutionUnit_Vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_Version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_Description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_DiskSpaceInUse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_MemoryInUse(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_References(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_AssociatedProcessList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_VendorLogList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_VendorConfigList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_SupportedDataModelList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); +int get_SoftwareModulesExecutionUnit_ExecutionEnvRef(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); + +int get_exe_cenv_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); +int get_du_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker); + +char *get_deployment_unit_reference(struct dmctx *ctx, char *package_name, char *package_env); +void get_deployment_unit_name_version(char *uuid, char **name, char **version, char **env); +char *get_softwaremodules_uuid(char *url); +char *get_softwaremodules_url(char *uuid); + +#endif //__SOFTWAREMODULES_H + diff --git a/dmtree/tr181/device.c b/dmtree/tr181/device.c index e356e584..fd7d5c2b 100644 --- a/dmtree/tr181/device.c +++ b/dmtree/tr181/device.c @@ -23,7 +23,6 @@ #include "x_iopsys_eu_logincfg.h" #include "x_iopsys_eu_power_mgmt.h" #include "x_iopsys_eu_syslog.h" -#include "softwaremodules.h" #include "xmpp.h" #include "x_iopsys_eu_owsd.h" #include "x_iopsys_eu_dropbear.h" @@ -57,6 +56,7 @@ #endif #ifdef BBF_TR157 #include "bulkdata.h" +#include "softwaremodules.h" #endif /* *** BBFDM *** */ @@ -88,7 +88,6 @@ DMOBJ tRoot_181_Obj[] = { {CUSTOM_PREFIX"LoginCfg", &DMREAD, NULL, NULL, NULL, NULL,NULL, &DMNONE, NULL, NULL, tSe_LoginCfgParam, NULL, BBFDM_BOTH}, {CUSTOM_PREFIX"PowerManagement", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE, NULL, NULL, tSe_PowerManagementParam, NULL, BBFDM_BOTH}, {CUSTOM_PREFIX"SyslogCfg", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE, NULL, NULL, tSe_SyslogCfgParam, NULL, BBFDM_BOTH}, -{"SoftwareModules", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE, NULL, tSoftwareModulesObj, NULL, NULL, BBFDM_BOTH}, {CUSTOM_PREFIX"Owsd", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE, NULL, XIopsysEuOwsdObj, XIopsysEuOwsdParams, NULL, BBFDM_BOTH}, {CUSTOM_PREFIX"Dropbear", &DMWRITE, add_dropbear_instance, delete_dropbear_instance, NULL, browseXIopsysEuDropbear, NULL, &DMNONE, NULL, NULL, X_IOPSYS_EU_DropbearParams, NULL, BBFDM_BOTH}, {CUSTOM_PREFIX"Buttons", &DMREAD, NULL, NULL, NULL, browseXIopsysEuButton, NULL, &DMNONE, NULL, NULL, X_IOPSYS_EU_ButtonParams, NULL, BBFDM_BOTH}, @@ -118,6 +117,7 @@ DMOBJ tRoot_181_Obj[] = { {"XMPP", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tXMPPObj, tXMPPParams, NULL, BBFDM_BOTH}, #ifdef BBF_TR157 {"BulkData", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tBulkDataObj, tBulkDataParams, NULL, BBFDM_BOTH}, +{"SoftwareModules", &DMREAD, NULL, NULL, NULL, NULL, NULL, &DMNONE, NULL, tSoftwareModulesObj, tSoftwareModulesParams, NULL, BBFDM_BOTH}, #endif {0} }; diff --git a/dmtree/tr181/softwaremodules.c b/dmtree/tr181/softwaremodules.c deleted file mode 100644 index f938f94a..00000000 --- a/dmtree/tr181/softwaremodules.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (C) 2019 iopsys Software Solutions AB - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 2.1 - * as published by the Free Software Foundation - * - * Author: Imen Bhiri - * Author: Feten Besbes - */ - -#include -#include -#include -#include "dmbbf.h" -#include "dmuci.h" -#include "dmubus.h" -#include "dmcommon.h" -#include "softwaremodules.h" - -/* *** Device.SoftwareModules. *** */ -DMOBJ tSoftwareModulesObj[] = { -/* OBJ, permission, addobj, delobj, checkobj, browseinstobj, forced_inform, notification, nextjsonobj, nextobj, leaf, linker, bbfdm_type*/ -{"DeploymentUnit", &DMREAD, NULL, NULL, NULL, browsesoftwaremodules_deploymentunitInst, NULL, NULL, NULL, NULL, tSoftwareModulesDeploymentUnitParams, NULL, BBFDM_BOTH}, -{0} -}; - -/* *** Device.SoftwareModules.DeploymentUnit.{i}. *** */ -DMLEAF tSoftwareModulesDeploymentUnitParams[] = { -/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/ -{"UUID", &DMREAD, DMT_STRING, get_deploymentunit_uuid, NULL, NULL, NULL, BBFDM_BOTH}, -{"Name", &DMREAD, DMT_STRING, get_deploymentunit_name, NULL, NULL, NULL, BBFDM_BOTH}, -{"Resolved", &DMREAD, DMT_BOOL, get_deploymentunit_resolved, NULL, NULL, NULL, BBFDM_BOTH}, -{"URL", &DMREAD, DMT_STRING, get_deploymentunit_url, NULL, NULL, NULL, BBFDM_BOTH}, -{"Vendor", &DMREAD, DMT_STRING, get_deploymentunit_vendor, NULL, NULL, NULL, BBFDM_BOTH}, -{"Version", &DMREAD, DMT_STRING, get_deploymentunit_version, NULL, NULL, NULL, BBFDM_BOTH}, -{"ExecutionEnvRef", &DMREAD, DMT_STRING, get_deploymentunit_execution_env_ref, NULL, NULL, NULL, BBFDM_BOTH}, -{0} -}; - -int get_deploymentunit_uuid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *softsection = (struct uci_section *)data; - - dmuci_get_value_by_section_string(softsection, "uuid", value); - - return 0; -} - -int get_deploymentunit_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *softsection = (struct uci_section *)data; - - dmuci_get_value_by_section_string(softsection, "name", value); - return 0; -} - -int get_deploymentunit_resolved(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *softsection = (struct uci_section *)data; - - dmuci_get_value_by_section_string(softsection, "resolved", value); - return 0; -} - -int get_deploymentunit_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *softsection = (struct uci_section *)data; - - dmuci_get_value_by_section_string(softsection, "url", value); - return 0; -} - -int get_deploymentunit_vendor(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *softsection = (struct uci_section *)data; - - dmuci_get_value_by_section_string(softsection, "vendor", value); - return 0; -} - -int get_deploymentunit_version(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *softsection = (struct uci_section *)data; - - dmuci_get_value_by_section_string(softsection, "version", value); - return 0; -} - -int get_deploymentunit_execution_env_ref(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - struct uci_section *softsection = (struct uci_section *)data; - - dmuci_get_value_by_section_string(softsection, "execution_env_ref", value); - return 0; -} - -char *add_softwaremodules_deploymentunit(char *uuid, char*url, char *username, char *password, char *name, char *version) -{ - char *value; - char *instance; - struct uci_section *deploymentsection = NULL; - char duname[16]; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "UUID", uuid, deploymentsection) { - DMUCI_SET_VALUE_BY_SECTION(bbfdm, deploymentsection, "URL", url); - DMUCI_SET_VALUE_BY_SECTION(bbfdm,deploymentsection, "URL", url); - DMUCI_SET_VALUE_BY_SECTION(bbfdm,deploymentsection, "Name", name); - DMUCI_SET_VALUE_BY_SECTION(bbfdm,deploymentsection, "Version", version); - DMUCI_SET_VALUE_BY_SECTION(bbfdm,deploymentsection, "username", username); - DMUCI_SET_VALUE_BY_SECTION(bbfdm,deploymentsection, "password", password); - DMUCI_SET_VALUE_BY_SECTION(bbfdm,deploymentsection, "Resolved", "1"); - dmuci_get_value_by_section_string(deploymentsection, "duinstance", &instance); - goto end; - } - instance = get_last_instance(DMMAP, "deploymentunit", "duinstance"); - if (!instance) - sprintf(duname, "du%d", 0); - else - sprintf(duname, "du%s", instance); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, NULL, "deploymentunit"); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, "UUID", uuid); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, "URL", url); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, "Name", name); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, "Version", version); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, "username", username); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, "password", password); - DMUCI_SET_VALUE(bbfdm, "dmmap", duname, "Resolved", "1"); - instance = get_last_instance(DMMAP, "deploymentunit", "duinstance"); - return instance; -end: - return instance; -} - -int update_softwaremodules_url(char *uuid, char *url) -{ - struct uci_section *s = NULL; - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "UUID", uuid, s) { - DMUCI_SET_VALUE_BY_SECTION(bbfdm, s, "URL", url); - return 1; - } - return 0; -} - -char *get_softwaremodules_uuid(char *url) -{ - char *uuid; - struct uci_section *s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "url", url, s) { - dmuci_get_value_by_section_string(s, "UUID", &uuid); - - return uuid; - } - return ""; -} - -char *get_softwaremodules_url(char *uuid) -{ - char *url; - struct uci_section *s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "uuid", uuid, s) { - dmuci_get_value_by_section_string(s, "URL", &url); - return url; - } - return ""; -} - -char *get_softwaremodules_username(char *uuid) -{ - char *url; - struct uci_section *s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "uuid", uuid, s) { - dmuci_get_value_by_section_string(s, "username", &url); - return url; - } - return ""; -} - -char *get_softwaremodules_pass(char *uuid) -{ - char *url; - struct uci_section *s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "uuid", uuid, s) { - dmuci_get_value_by_section_string(s, "password", &url); - return url; - } - return ""; -} - -char *get_softwaremodules_instance(char *uuid) -{ - char *url; - struct uci_section *s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "uuid", uuid, s) { - dmuci_get_value_by_section_string(s, "duinstance", &url); - return url; - } - return ""; -} - -char *get_softwaremodules_name(char *uuid) -{ - char *name; - struct uci_section *s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "uuid", uuid, s) { - dmuci_get_value_by_section_string(s, "Name", &name); - return name; - } - return ""; -} - -char *get_softwaremodules_version(char *uuid) -{ - char *version; - struct uci_section *s = NULL; - - uci_path_foreach_option_eq(bbfdm, "dmmap", "deploymentunit", "uuid", uuid, s) { - dmuci_get_value_by_section_string(s, "Version", &version); - return version; - } - return ""; -} - -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(bbfdm, "dmmap", "deploymentunit", s) { - idu = handle_update_instance(1, dmctx, &idu_last, update_instance_alias_bbfdm, 3, s, "duinstance", "duinstance_alias"); - if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, idu) == DM_STOP) - break; - } - return 0; -} - - diff --git a/dmtree/tr181/softwaremodules.h b/dmtree/tr181/softwaremodules.h deleted file mode 100644 index a9352a99..00000000 --- a/dmtree/tr181/softwaremodules.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2019 iopsys Software Solutions AB - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 2.1 - * as published by the Free Software Foundation - * - * Author: Imen Bhiri - */ - -#ifndef __SOFTWARE_MODULE_H -#define __SOFTWARE_MODULE_H - -extern DMOBJ tSoftwareModulesObj[]; -extern DMLEAF tSoftwareModulesDeploymentUnitParams[]; - -int browsesoftwaremodules_deploymentunitInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance); - -int update_softwaremodules_url(char *uuid, char *url); -char *get_softwaremodules_uuid(char *url); -char *get_softwaremodules_username(char *uuid); -char *get_softwaremodules_pass(char *uuid); -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); -char *get_softwaremodules_url(char *uuid); - -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/dmubus.c b/dmubus.c index c39d5d80..dab01872 100644 --- a/dmubus.c +++ b/dmubus.c @@ -162,10 +162,18 @@ static inline json_object *ubus_call_req(char *obj, char *method, struct ubus_ar sprintf(p, "{"); for (i = 0; i < u_args_size; i++) { p += strlen(p); - if (i == 0) - 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); + if (i == 0){ + if(u_args[i].type != Integer) + 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); + } + else{ + if(u_args[i].type != Integer) + 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); + } } p += strlen(p); sprintf(p, "}"); diff --git a/json/tr181.json b/json/tr181.json index 37028d8b..7b859f5b 100644 --- a/json/tr181.json +++ b/json/tr181.json @@ -2776,7 +2776,18 @@ "usp" ], "read": true, - "write": true + "write": true, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].status" + } + } + ] }, "Status": { "type": "string", @@ -2790,6 +2801,17 @@ "Up", "Error", "Disabled" + ], + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].status" + } + } ] }, "Reset": { @@ -2816,7 +2838,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].name" + } + } + ] }, "Type": { "type": "string", @@ -2825,7 +2858,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].type" + } + } + ] }, "InitialRunLevel": { "type": "unsignedInt", @@ -2884,7 +2928,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].vendor" + } + } + ] }, "Version": { "type": "string", @@ -2893,7 +2948,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].version" + } + } + ] }, "ParentExecEnv": { "type": "string", @@ -2915,7 +2981,18 @@ }, "unit": "kilobytes", "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].allocateddiskspace" + } + } + ] }, "AvailableDiskSpace": { "type": "int", @@ -2928,7 +3005,18 @@ }, "unit": "kilobytes", "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].availablediskspace" + } + } + ] }, "AllocatedMemory": { "type": "int", @@ -2941,7 +3029,18 @@ }, "unit": "kilobytes", "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].allocatedmemory" + } + } + ] }, "AvailableMemory": { "type": "int", @@ -2954,7 +3053,18 @@ }, "unit": "kilobytes", "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "environment", + "args": {}, + "key": "environment[i-1].availablememory" + } + } + ] }, "ActiveExecutionUnits": { "type": "string", @@ -2990,7 +3100,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].uuid" + } + } + ] }, "DUID": { "type": "string", @@ -2999,7 +3120,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].duid" + } + } + ] }, "Alias": { "type": "string", @@ -3017,7 +3149,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].name" + } + } + ] }, "Status": { "type": "string", @@ -3051,7 +3194,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].url" + } + } + ] }, "Description": { "type": "string", @@ -3060,7 +3214,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].description" + } + } + ] }, "Vendor": { "type": "string", @@ -3069,7 +3234,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].vendor" + } + } + ] }, "Version": { "type": "string", @@ -3078,7 +3254,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].version" + } + } + ] }, "VendorLogList": { "type": "string", @@ -3114,7 +3301,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "du_list", + "args": {}, + "key": "deployment_unit[i-1].environment" + } + } + ] } }, "Device.SoftwareModules.ExecutionUnit.{i}.": { @@ -3132,7 +3330,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].euid" + } + } + ] }, "Alias": { "type": "string", @@ -3150,7 +3359,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].name" + } + } + ] }, "ExecEnvLabel": { "type": "string", @@ -3159,7 +3379,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].name" + } + } + ] }, "Status": { "type": "string", @@ -3243,7 +3474,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].vendor" + } + } + ] }, "Version": { "type": "string", @@ -3252,7 +3494,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].version" + } + } + ] }, "Description": { "type": "string", @@ -3261,7 +3514,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].description" + } + } + ] }, "DiskSpaceInUse": { "type": "int", @@ -3274,7 +3538,18 @@ }, "unit": "kilobytes", "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].disk_space" + } + } + ] }, "MemoryInUse": { "type": "int", @@ -3287,7 +3562,18 @@ }, "unit": "kilobytes", "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].memory_space" + } + } + ] }, "References": { "type": "string", @@ -3340,7 +3626,18 @@ "usp" ], "read": true, - "write": false + "write": false, + "mapping": [ + { + "type": "ubus", + "ubus": { + "object": "softwaremanagement", + "method": "eu_list", + "args": {}, + "key": "execution_unit[i-1].environment" + } + } + ] }, "Device.SoftwareModules.ExecutionUnit.{i}.Extensions.": { "type": "object",