From fcbfefd1dd389589e9998bed8390cb8f5cefd0a8 Mon Sep 17 00:00:00 2001 From: Imen Bhiri Date: Mon, 7 Sep 2015 10:39:30 +0100 Subject: [PATCH] Code review and update deviceinfo --- dm/dmtree/deviceinfo.c | 61 ++++++++++++++++++++++++------------------ dm/dmtree/deviceinfo.h | 21 --------------- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/dm/dmtree/deviceinfo.c b/dm/dmtree/deviceinfo.c index 1d04a40..b0f276c 100644 --- a/dm/dmtree/deviceinfo.c +++ b/dm/dmtree/deviceinfo.c @@ -51,9 +51,13 @@ not_found: char *get_deviceid_productclass() { - char *v; + char *v, *tmp, *val; + char delimiter[] = "_"; + db_get_value_string("hw", "board", "iopVersion", &v); - return v; + tmp = dmstrdup(v);// MEM WILL BE FREED IN DMMEMCLEAN + val = cut_fx(tmp, delimiter, 1); + return val; } @@ -66,9 +70,13 @@ char *get_deviceid_serialnumber() char *get_softwareversion() { - char *v; + char *v, *tmp, *val; + char delimiter[] = "_"; + db_get_value_string("hw", "board", "iopVersion", &v); - return v; + tmp = dmstrdup(v);// MEM WILL BE FREED IN DMMEMCLEAN + val = cut_fx(tmp, delimiter, 2); + return val; } int get_device_manufacturer(char *refparam, struct dmctx *ctx, char **value) @@ -165,9 +173,7 @@ int get_device_devicelog(char *refparam, struct dmctx *ctx, char **value) int get_device_specversion(char *refparam, struct dmctx *ctx, char **value) { - TRACE(); dmuci_get_option_value_string("cwmp", "cpe", "specversion", value); - TRACE(); if ((*value)[0] == '\0') { *value = "1.0"; } @@ -184,11 +190,12 @@ int set_device_provisioningcode(char *refparam, struct dmctx *ctx, int action, c { bool b; switch (action) { - VALUECHECK: + case VALUECHECK: return 0; - VALUESET: + case VALUESET: dmuci_set_value("cwmp", "cpe", "provisioning_code", value); - } + return 0; + } return 0; } @@ -217,19 +224,21 @@ int get_catv_enabled(char *refparam, struct dmctx *ctx, char **value) int set_device_catvenabled(char *refparam, struct dmctx *ctx, int action, char *value) { - static bool b; - char *stat = ""; + bool b; + char *stat; switch (action) { - VALUECHECK: + case VALUECHECK: if (string_to_bool(value, &b)) return FAULT_9007; return 0; - VALUESET: + case VALUESET: + string_to_bool(value, &b); if (b) stat = "on"; else stat = "off"; dmuci_set_value("catv", "catv", "enable", stat); + return 0; } return 0; } @@ -238,19 +247,19 @@ 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, "", 1, 0, UNDEF, NULL); - DMPARAM("ManufacturerOUI", ctx, "0", get_device_manufactureroui, NULL, "", 1, 0, UNDEF, NULL); - DMPARAM("ModelName", ctx, "0", get_device_routermodel, NULL, "", 1, 0, UNDEF, NULL); - DMPARAM("ProductClass", ctx, "0", get_device_productclass, NULL, "xsd:boolean", 1, 0, UNDEF, NULL); - DMPARAM("SerialNumber", ctx, "0", get_device_serialnumber, NULL, "", 1, 0, UNDEF, NULL); - DMPARAM("HardwareVersion", ctx, "0", get_device_hardwareversion, NULL, "xsd:boolean", 1, 0, UNDEF, NULL); - DMPARAM("SoftwareVersion", ctx, "0", get_device_softwareversion, NULL, "xsd:boolean", 1, 0, UNDEF, NULL); - DMPARAM("UpTime", ctx, "0", get_device_info_uptime, NULL, "", 1, 0, UNDEF, NULL); - DMPARAM("DeviceLog", ctx, "0", get_device_devicelog, NULL, "", 1, 0, UNDEF, NULL); - DMPARAM("SpecVersion", ctx, "0", get_device_specversion, NULL, "", 1, 0, UNDEF, NULL); - DMPARAM("ProvisioningCode", ctx, "1", get_device_provisioningcode, set_device_provisioningcode, "", 1, 0, UNDEF, NULL); - DMPARAM("X_INTENO_SE_BaseMacAddr", ctx, "0", get_base_mac_addr, NULL, "", 1, 0, UNDEF, NULL); - DMPARAM("X_INTENO_SE_CATVEnabled", ctx, "1", get_catv_enabled, set_device_catvenabled, "", 1, 0, UNDEF, 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, "xsd:boolean", 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, "xsd:boolean", 1, 1, UNDEF, NULL); + DMPARAM("SoftwareVersion", ctx, "0", get_device_softwareversion, NULL, "xsd:boolean", 1, 0, 2, NULL); + DMPARAM("UpTime", ctx, "0", get_device_info_uptime, NULL, NULL, 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_CATVEnabled", ctx, "1", get_catv_enabled, set_device_catvenabled, NULL, 0, 1, UNDEF, NULL); return 0; } return FAULT_9005; diff --git a/dm/dmtree/deviceinfo.h b/dm/dmtree/deviceinfo.h index c44f919..b847738 100644 --- a/dm/dmtree/deviceinfo.h +++ b/dm/dmtree/deviceinfo.h @@ -17,27 +17,6 @@ #define BASE_MAC_ADDR "/proc/nvram/BaseMacAddr" #define UPTIME "/proc/uptime" -char *get_deviceid_manufacturer(); -char *get_deviceid_manufactureroui(); -char *get_deviceid_productclass(); -char *get_deviceid_serialnumber(); -char *get_softwareversion(); -int get_spec_version(char *refparam, struct dmctx *ctx, char **value); -int get_device_manufacturer(char *refparam, struct dmctx *ctx, char **value); -int get_device_manufactureroui(char *refparam, struct dmctx *ctx, char **value); -int get_device_routermodel(char *refparam, struct dmctx *ctx, char **value); -int get_device_productclass(char *refparam, struct dmctx *ctx, char **value); -int get_device_serialnumber(char *refparam, struct dmctx *ctx, char **value); -int get_device_hardwareversion(char *refparam, struct dmctx *ctx, char **value); -int get_device_softwareversion(char *refparam, struct dmctx *ctx, char **value); -int get_device_info_uptime(char *refparam, struct dmctx *ctx, char **value); -int get_device_devicelog (char *refparam, struct dmctx *ctx, char **value); -int get_device_specversion(char *refparam, struct dmctx *ctx, char **value); -int get_device_provisioningcode(char *refparam, struct dmctx *ctx, char **value); -int set_device_provisioningcode(char *refparam, struct dmctx *ctx, int action, char *value); -int get_base_mac_addr(char *refparam, struct dmctx *ctx, char **value); -int get_catv_enabled(char *refparam, struct dmctx *ctx, char **value); -int set_device_catvenabled(char *refparam, struct dmctx *ctx, int action, char *value); int entry_method_root_DeviceInfo(struct dmctx *ctx); #endif