From 7927fd146ec6c87ae73838e562e8cb528209e7c3 Mon Sep 17 00:00:00 2001
From: Rohit Topno <r.topno@gxgroup.eu>
Date: Mon, 10 Jun 2024 13:52:56 +0530
Subject: [PATCH] qosmngr: add tr-181 vendor extension for VLAN ID translation

---
 bbf_plugin/Makefile         |  9 +++++--
 bbf_plugin/qos_bbf_vendor.c | 48 +++++++++++++++++++++++++++++++++++++
 bbf_plugin/qos_bbf_vendor.h | 20 ++++++++++++++++
 3 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 bbf_plugin/qos_bbf_vendor.c
 create mode 100644 bbf_plugin/qos_bbf_vendor.h

diff --git a/bbf_plugin/Makefile b/bbf_plugin/Makefile
index e844578..e170fd1 100644
--- a/bbf_plugin/Makefile
+++ b/bbf_plugin/Makefile
@@ -1,6 +1,8 @@
 LIB_QOS_BBF := libqos_bbf.so
+LIB_QOS_BBF_VENDOR := libqos_vendor_bbf.so
 
 OBJS  := qos_bbf.o
+OBJS_VENDOR  := qos_bbf_vendor.o
 
 LIB_CFLAGS = $(CFLAGS) -Wall -Werror
 LIB_LDFLAGS = $(LDFLAGS)
@@ -11,11 +13,14 @@ FPIC := -fPIC
 %.o: %.c
 	$(CC) $(LIB_CFLAGS) $(FPIC) -c -o $@ $<
 
-all: $(LIB_QOS_BBF)
+all: $(LIB_QOS_BBF) $(LIB_QOS_BBF_VENDOR)
 
 $(LIB_QOS_BBF): $(OBJS)
 	$(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^
 
+$(LIB_QOS_BBF_VENDOR): $(OBJS_VENDOR)
+	$(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) -shared -o $@ $^
+
 clean:
-	rm -f *.o $(LIB_QOS_BBF)
+	rm -f *.o $(LIB_QOS_BBF) $(LIB_QOS_BBF_VENDOR)
 
diff --git a/bbf_plugin/qos_bbf_vendor.c b/bbf_plugin/qos_bbf_vendor.c
new file mode 100644
index 0000000..07c41e1
--- /dev/null
+++ b/bbf_plugin/qos_bbf_vendor.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2024 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: Rohit Topno <r.topno@gxgroup.eu>
+ */
+
+#include "qos_bbf_vendor.h"
+
+/*************************************************************
+ * GET & SET PARAM
+*************************************************************/
+static int get_QoSClassification_VLANIDMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
+{
+	*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "vid_mark", "-1");
+	return 0;
+}
+
+static int set_QoSClassification_VLANIDMark(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
+{
+	switch (action)	{
+	case VALUECHECK:
+		if (bbfdm_validate_int(ctx, value, RANGE_ARGS{{"-1",NULL}}, 1))
+			return FAULT_9007;
+		break;
+	case VALUESET:
+		dmuci_set_value_by_section(((struct dm_data *)data)->config_section, "vid_mark", value);
+		break;
+	}
+	return 0;
+}
+
+/* ********** DynamicObj ********** */
+DM_MAP_OBJ tDynamicObj[] = {
+/* parentobj, nextobject, parameter */
+{"Device.QoS.Classification.{i}.", NULL, tQoSClassificationParams},
+{0}
+};
+
+/* *** Device.QoS.Classification.{i}. *** */
+DMLEAF tQoSClassificationParams[] = {
+/* PARAM, permission, type, getvalue, setvalue, bbfdm_type */
+{BBF_VENDOR_PREFIX"VLANIDMark", &DMWRITE, DMT_UNINT, get_QoSClassification_VLANIDMark, set_QoSClassification_VLANIDMark, BBFDM_BOTH},
+{0}
+};
diff --git a/bbf_plugin/qos_bbf_vendor.h b/bbf_plugin/qos_bbf_vendor.h
new file mode 100644
index 0000000..b5eecf4
--- /dev/null
+++ b/bbf_plugin/qos_bbf_vendor.h
@@ -0,0 +1,20 @@
+
+/*
+ * Copyright (C) 2024 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: Rohit Topno <r.topno@gxgroup.eu>
+ *
+ */
+
+#ifndef __IOPSYS_QOS_H
+#define __IOPSYS_QOS_H
+
+#include "libbbfdm-api/dmcommon.h"
+
+extern DMLEAF tQoSClassificationParams[];
+
+#endif //__IOPSYS_QOS_H
-- 
GitLab