diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b530b9c90e7636dfe7d1557020c29d894f76d08d --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +/src/*.so +/src/*.o +/*.xml +/*.log +/result +*.swp +*.swo +*.gcda +*.gcno +*.gcov +*.o +*.so +*.tar +docs/index.md diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..86a55dae2fa30e5d1ef0b9bf37c3886c67297cda --- /dev/null +++ b/src/Makefile @@ -0,0 +1,15 @@ +LIBGWINFO = libgwinfo.so +LIBGWOBJS = gatewayinfo.o + +LIB_CFLAGS = $(CFLAGS) -Wall -Werror -fPIC + +%.o: %.c + $(CC) $(LIB_CFLAGS) -c -o $@ $< + +all: $(LIBGWINFO) + +$(LIBGWINFO): $(LIBGWOBJS) + $(CC) -shared -o $@ $^ $(LDFLAGS) + +clean: + rm -rf *.o $(LIBGWINFO) diff --git a/src/gatewayinfo.c b/src/gatewayinfo.c new file mode 100644 index 0000000000000000000000000000000000000000..299763db5a3a289bafc559f1aa3fedc1b0783043 --- /dev/null +++ b/src/gatewayinfo.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2025 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 "libbbfdm-api/legacy/dmcommon.h" + +static int get_manufacturer_oui(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string_varstate("gwinfo", "gatewayinfo", "oui", value); + if (*value[0] == '\0') { + db_get_value_string("device", "deviceinfo", "ManufacturerOUI", value); + } + + return 0; +} + +static int get_product_class(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string_varstate("gwinfo", "gatewayinfo", "class", value); + if (*value[0] == '\0') { + db_get_value_string("device", "deviceinfo", "ProductClass", value); + } + + return 0; +} + +static int get_serial_number(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string_varstate("gwinfo", "gatewayinfo", "serial", value); + if (*value[0] == '\0') { + db_get_value_string("device", "deviceinfo", "SerialNumber", value); + } + + return 0; +} + +static int get_gateway_proto(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string_varstate("gwinfo", "gatewayinfo", "proto", value); + return 0; +} + +static int get_endpoint_id(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string_varstate("gwinfo", "gatewayinfo", "endpoint", value); + return 0; +} + +static int get_mac_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +{ + dmuci_get_option_value_string_varstate("gwinfo", "gatewayinfo", "hwaddr", value); + return 0; +} + +/********************************************************************************************************************************** +* OBJ & PARAM DEFINITION +***********************************************************************************************************************************/ +/* *** Device.GatewayInfo. *** */ +DMLEAF tGatewayInfoParams[] = { +/* PARAM, permission, type, getvalue, setvalue, bbfdm_type, version*/ +{"ManufacturerOUI", &DMREAD, DMT_STRING, get_manufacturer_oui, NULL, BBFDM_BOTH}, +{"ProductClass", &DMREAD, DMT_STRING, get_product_class, NULL, BBFDM_BOTH}, +{"SerialNumber", &DMREAD, DMT_STRING, get_serial_number, NULL, BBFDM_BOTH}, +{"ManagementProtocol", &DMREAD, DMT_STRING, get_gateway_proto, NULL, BBFDM_USP}, +{"EndpointID", &DMREAD, DMT_STRING, get_endpoint_id, NULL, BBFDM_USP}, +{"MACAddress", &DMREAD, DMT_STRING, get_mac_address, NULL, BBFDM_USP}, +{0} +}; + +DMOBJ tDeviceObjs[] = { +/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/ +{"GatewayInfo", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tGatewayInfoParams, NULL, BBFDM_BOTH}, +{0} +}; + +DM_MAP_OBJ tDynamicObj[] = { +/* parentobj, nextobject, parameter */ +{"Device.", tDeviceObjs, NULL}, +{0} +};