mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
self-diagnostics: Added datamodel plugin
This commit is contained in:
parent
e0e9dffee8
commit
c5bfa7332a
4 changed files with 211 additions and 11 deletions
|
|
@ -1,35 +1,30 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=self-diagnostics
|
||||
PKG_VERSION:=1.0.5
|
||||
PKG_VERSION:=1.0.6
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_LICENSE:=GPL-2.0-only
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../bbfdm/bbfdm.mk
|
||||
|
||||
define Package/self-diagnostics
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=System Report
|
||||
DEPENDS:=+@CONFIG_BUSYBOX_CONFIG_TIMEOUT +@CONFIG_BUSYBOX_CONFIG_FEATURE_FIND_PATH +@CONFIG_BUSYBOX_CONFIG_TEE \
|
||||
+@CONFIG_BUSYBOX_CONFIG_GZIP
|
||||
+@CONFIG_BUSYBOX_CONFIG_GZIP +libbbfdm-api
|
||||
MENU:=1
|
||||
endef
|
||||
|
||||
define Package/self-diagnostics/description
|
||||
Generate Self test diagnostics report
|
||||
endef
|
||||
|
||||
#define Build/Prepare
|
||||
# mkdir -p $(PKG_BUILD_DIR)
|
||||
# $(CP) ./files/* $(PKG_BUILD_DIR)/
|
||||
#endef
|
||||
|
||||
define Build/Compile
|
||||
Generate Self test diagnostics report and adds Device.SelfTestDiagnostics. datamodel object
|
||||
endef
|
||||
|
||||
define Package/self-diagnostics/install
|
||||
$(INSTALL_DIR) $(1)/etc/self-diagnostics/spec/
|
||||
$(CP) ./files/* $(1)/
|
||||
$(BBFDM_INSTALL_CORE_PLUGIN) $(PKG_BUILD_DIR)/libselftest.so $(1)
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,self-diagnostics))
|
||||
|
|
|
|||
29
self-diagnostics/src/LICENSE
Normal file
29
self-diagnostics/src/LICENSE
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2023, IOPSYS
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
21
self-diagnostics/src/Makefile
Normal file
21
self-diagnostics/src/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
LIBOUT := libselftest.so
|
||||
|
||||
LIBOBJS := selftest.o
|
||||
|
||||
PROG_CFLAGS = $(CFLAGS) -Wall -Werror -fstrict-aliasing -g
|
||||
LIB_LDFLAGS = $(LDFLAGS)
|
||||
|
||||
FPIC := -fPIC
|
||||
|
||||
.PHONY: all
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(PROG_CFLAGS) $(FPIC) -c -o $@ $<
|
||||
|
||||
all: $(LIBOUT)
|
||||
|
||||
$(LIBOUT): $(LIBOBJS)
|
||||
$(CC) $(PROG_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f *.o $(LIBOUT)
|
||||
155
self-diagnostics/src/selftest.c
Normal file
155
self-diagnostics/src/selftest.c
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* selftest.c: SelfTestDiagnostics datamodel handler
|
||||
*
|
||||
* Copyright (C) 2023-2024 IOPSYS Software Solutions AB. All rights reserved.
|
||||
*
|
||||
*
|
||||
* See LICENSE file for license related information.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "libbbfdm-api/dmcommon.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}
|
||||
};
|
||||
|
||||
DMOBJ tDeviceObjs[] = {
|
||||
{"SelfTestDiagnostics", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tSelfTestParams, NULL, BBFDM_CWMP, NULL},
|
||||
{0}
|
||||
};
|
||||
|
||||
DMLEAF tDeviceParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/
|
||||
{"SelfTestDiagnostics()", &DMASYNC, DMT_COMMAND, get_operate_args_SelfTest, operate_Device_SelfTest, BBFDM_USP},
|
||||
{0}
|
||||
};
|
||||
|
||||
DM_MAP_OBJ tDynamicObj[] = {
|
||||
/* parentobj, nextobject, parameter */
|
||||
{"Device.", tDeviceObjs, tDeviceParams},
|
||||
{0}
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue