Moved SelfTestDiagnostics

This commit is contained in:
Suvendhu Hansa 2024-05-23 16:24:16 +05:30 committed by Vivek Kumar Dutta
parent 01214297eb
commit 6dfb163f0a
5 changed files with 9 additions and 164 deletions

View file

@ -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_IGMP. | mcastmngr | https://dev.iopsys.eu/hal/mcastmngr.git |
| Device.X_IOPSYS_EU_MLD. | 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.PacketCaptureDiagnostics. | PacketCaptureDiagnostics | https://dev.iopsys.eu/bbf/packet-capture-diagnostics.git |
| Device.SelfTestDiagnostics. | SelfTestDiagnostics | https://dev.iopsys.eu/feed/iopsys.git |

View file

@ -25,7 +25,6 @@
#include "routeradvertisement.h" #include "routeradvertisement.h"
#include "gatewayinfo.h" #include "gatewayinfo.h"
#include "mqtt.h" #include "mqtt.h"
#include "selftest.h"
/************************************************************* /*************************************************************
* GET & SET PARAM * GET & SET PARAM
@ -88,7 +87,6 @@ DMOBJ tDeviceObj[] = {
{"Services", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, BBFDM_BOTH, NULL}, {"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}, {"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}, {"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} {0}
}; };
@ -98,7 +96,6 @@ DMLEAF tDeviceParams[] = {
{"RootDataModelVersion", &DMREAD, DMT_STRING, get_Device_RootDataModelVersion, NULL, BBFDM_BOTH}, {"RootDataModelVersion", &DMREAD, DMT_STRING, get_Device_RootDataModelVersion, NULL, BBFDM_BOTH},
{"Reboot()", &DMSYNC, DMT_COMMAND, NULL, operate_Device_Reboot, BBFDM_USP}, {"Reboot()", &DMSYNC, DMT_COMMAND, NULL, operate_Device_Reboot, BBFDM_USP},
{"FactoryReset()", &DMSYNC, DMT_COMMAND, NULL, operate_Device_FactoryReset, 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}, //{"Boot!", &DMREAD, DMT_EVENT, NULL, NULL, BBFDM_USP},
{0} {0}
}; };

View file

@ -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 <suvendhu.hansa@iopsys.eu>
*
*/
#include <sys/stat.h>
#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}
};

View file

@ -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 <suvendhu.hansa@iopsys.eu>
*/
#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

View file

@ -79,6 +79,14 @@
"ponmngr/files/etc/ponmngr/xpon.json" "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", "repo": "https://dev.iopsys.eu/lcm/swmodd.git",
"proto": "git", "proto": "git",