From 6dfb163f0ae2d35024120d5f149d186c701f33ba Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Thu, 23 May 2024 16:24:16 +0530 Subject: [PATCH] Moved SelfTestDiagnostics --- README.md | 1 + libbbfdm/dmtree/tr181/device.c | 3 - libbbfdm/dmtree/tr181/selftest.c | 140 ------------------------------- libbbfdm/dmtree/tr181/selftest.h | 21 ----- tools/tools_input.json | 8 ++ 5 files changed, 9 insertions(+), 164 deletions(-) delete mode 100644 libbbfdm/dmtree/tr181/selftest.c delete mode 100644 libbbfdm/dmtree/tr181/selftest.h diff --git a/README.md b/README.md index 59223bf8..3959f0f9 100644 --- a/README.md +++ b/README.md @@ -118,3 +118,4 @@ All supported tools are presented in this file[BBFDM Tools](./tools/README.md) | Device.X_IOPSYS_EU_IGMP. | mcastmngr | https://dev.iopsys.eu/hal/mcastmngr.git | | Device.X_IOPSYS_EU_MLD. | mcastmngr | https://dev.iopsys.eu/hal/mcastmngr.git | | Device.PacketCaptureDiagnostics. | PacketCaptureDiagnostics | https://dev.iopsys.eu/bbf/packet-capture-diagnostics.git | +| Device.SelfTestDiagnostics. | SelfTestDiagnostics | https://dev.iopsys.eu/feed/iopsys.git | diff --git a/libbbfdm/dmtree/tr181/device.c b/libbbfdm/dmtree/tr181/device.c index cf7af368..56849175 100644 --- a/libbbfdm/dmtree/tr181/device.c +++ b/libbbfdm/dmtree/tr181/device.c @@ -25,7 +25,6 @@ #include "routeradvertisement.h" #include "gatewayinfo.h" #include "mqtt.h" -#include "selftest.h" /************************************************************* * GET & SET PARAM @@ -88,7 +87,6 @@ DMOBJ tDeviceObj[] = { {"Services", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, BBFDM_BOTH, NULL}, {"GatewayInfo", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tGatewayInfoParams, NULL, BBFDM_CWMP, NULL}, {"MQTT", &DMREAD, NULL, NULL, "file:/etc/config/mosquitto", NULL, NULL, NULL, tMQTTObj, tMQTTParams, NULL, BBFDM_BOTH, NULL}, -{"SelfTestDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tSelfTestParams, NULL, BBFDM_CWMP, NULL}, {0} }; @@ -98,7 +96,6 @@ DMLEAF tDeviceParams[] = { {"RootDataModelVersion", &DMREAD, DMT_STRING, get_Device_RootDataModelVersion, NULL, BBFDM_BOTH}, {"Reboot()", &DMSYNC, DMT_COMMAND, NULL, operate_Device_Reboot, BBFDM_USP}, {"FactoryReset()", &DMSYNC, DMT_COMMAND, NULL, operate_Device_FactoryReset, BBFDM_USP}, -{"SelfTestDiagnostics()", &DMASYNC, DMT_COMMAND, get_operate_args_SelfTest, operate_Device_SelfTest, BBFDM_USP}, //{"Boot!", &DMREAD, DMT_EVENT, NULL, NULL, BBFDM_USP}, {0} }; diff --git a/libbbfdm/dmtree/tr181/selftest.c b/libbbfdm/dmtree/tr181/selftest.c deleted file mode 100644 index 88f395d5..00000000 --- a/libbbfdm/dmtree/tr181/selftest.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2023 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: Suvendhu Hansa - * - */ - -#include - -#include "selftest.h" - -#define DIAG_BIN "/usr/sbin/self-diagnostics" - -static char *get_selftest_log_instance(struct dmctx *ctx) -{ - char *file_name = NULL; - char *path = NULL; - - struct uci_section *s = get_origin_section_from_config("system", "system", "self_test_log"); - if (s == NULL) - goto err; - - dmuci_get_value_by_section_string(s, "log_file", &file_name); - if (DM_STRLEN(file_name) == 0) - goto err; - - _bbfdm_get_references(ctx, "Device.DeviceInfo.VendorLogFile.", "Name", file_name, &path); - -err: - return path ? path : dmstrdup(""); -} - -/************************************************************* -* OPERATE COMMAND -**************************************************************/ -static operation_args device_self_test_args = { - .out = (const char *[]) { - "Status", - "Results", - NULL - } -}; - -int get_operate_args_SelfTest(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = (char *)&device_self_test_args; - return 0; -} - -int operate_Device_SelfTest(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - char cmd[512] = {0}; - char output[512] = {0}; - - snprintf(cmd, sizeof(cmd), "sh %s", DIAG_BIN); - - if (run_cmd(cmd, output, sizeof(output)) != 0) - goto err; - - // truncate the new line char from end - remove_new_line(output); - - if (!file_exists(output)) - goto err; - - /* Add in vendor log */ - struct uci_section *s = get_origin_section_from_config("system", "system", "self_test_log"); - if (s == NULL) { - dmuci_add_section("system", "system", &s); - dmuci_rename_section_by_section(s, "self_test_log"); - } - - dmuci_set_value_by_section(s, "log_file", output); - dmuci_commit_package("system"); - - /* Get self test log instance */ - char *result = get_selftest_log_instance(ctx); - - add_list_parameter(ctx, dmstrdup("Status"), dmstrdup("Complete"), DMT_TYPE[DMT_STRING], NULL); - add_list_parameter(ctx, dmstrdup("Results"), result, DMT_TYPE[DMT_STRING], NULL); - - if (ctx->dm_type != BBFDM_USP) { - diagnostics_set_option("selftest", "DiagnosticState", "Complete"); - dmuci_commit_package_bbfdm(DMMAP_DIAGNOSTIGS); - } - - return 0; - -err: - add_list_parameter(ctx, dmstrdup("Status"), dmstrdup("Error_Internal"), DMT_TYPE[DMT_STRING], NULL); - if (ctx->dm_type != BBFDM_USP) { - diagnostics_set_option("selftest", "DiagnosticState", "Error"); - dmuci_commit_package_bbfdm(DMMAP_DIAGNOSTIGS); - } - - return USP_FAULT_COMMAND_FAILURE; -} - -/************************************************************* -* GET & SET PARAM -**************************************************************/ -static int get_SelfTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = diagnostics_get_option_fallback_def("selftest", "DiagnosticState", "None"); - return 0; -} - -static int set_SelfTest_DiagnosticsState(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (bbfdm_validate_string(ctx, value, -1, -1, DiagnosticsState, NULL)) - return FAULT_9007; - break; - case VALUESET: - if (DM_LSTRCMP(value, "Requested") == 0) - diagnostics_set_option("selftest", "DiagnosticState", value); - } - return 0; -} - -static int get_SelfTest_Results(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - *value = get_selftest_log_instance(ctx); - return 0; -} - -/********************************************************************************************************************************** -* OBJ & LEAF DEFINITION -***********************************************************************************************************************************/ -DMLEAF tSelfTestParams[] = { -/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/ -{"DiagnosticsState", &DMWRITE, DMT_STRING, get_SelfTest_DiagnosticsState, set_SelfTest_DiagnosticsState, BBFDM_CWMP}, -{"Results", &DMREAD, DMT_STRING, get_SelfTest_Results, NULL, BBFDM_CWMP}, -{0} -}; diff --git a/libbbfdm/dmtree/tr181/selftest.h b/libbbfdm/dmtree/tr181/selftest.h deleted file mode 100644 index fb07c70e..00000000 --- a/libbbfdm/dmtree/tr181/selftest.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2023 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: Suvendhu Hansa - */ - -#ifndef __SELFTEST_H -#define __SELFTEST_H - -#include "libbbfdm-api/dmcommon.h" - -extern DMLEAF tSelfTestParams[]; - -int get_operate_args_SelfTest(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value); -int operate_Device_SelfTest(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action); -#endif - diff --git a/tools/tools_input.json b/tools/tools_input.json index b9901be1..50f86025 100644 --- a/tools/tools_input.json +++ b/tools/tools_input.json @@ -79,6 +79,14 @@ "ponmngr/files/etc/ponmngr/xpon.json" ] }, + { + "repo": "https://dev.iopsys.eu/feed/iopsys.git", + "proto": "git", + "version": "devel", + "dm_files": [ + "self-diagnostics/src/selftest.c" + ] + }, { "repo": "https://dev.iopsys.eu/lcm/swmodd.git", "proto": "git",