From 1ccba3a4af878471de80d5827d305bb975a1e55b Mon Sep 17 00:00:00 2001
From: Anjan Chanda <anjan.chanda@iopsys.eu>
Date: Fri, 4 Aug 2023 12:49:57 +0200
Subject: [PATCH] simplify EASYMESH_VENDOR_EXT_OUI definition and usage

Pass -DEASYMESH_VENDOR_EXT_OUI=0xAABBCC during build to override the
default vendor OUI with the passed value. Here, AABBCC are hex
characters representing the three octets of vendor OUI.
---
 src/cmdu_validate.c | 11 ++++++++++-
 src/cntlr.h         |  5 +++--
 src/cntlr_map.c     | 11 ++++++++++-
 src/config.c        | 10 +++++++++-
 4 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/cmdu_validate.c b/src/cmdu_validate.c
index a14080e1..e3161a3f 100644
--- a/src/cmdu_validate.c
+++ b/src/cmdu_validate.c
@@ -1043,8 +1043,17 @@ bool validate_channel_scan_report(struct cmdu_buff *cmdu, struct tlv *tv_tsp[][1
 #ifdef EASYMESH_VENDOR_EXT
 static int validate_topology_response_vext(struct tlv *tv[16])
 {
+	const uint8_t vendor_oui[4] = {0};
+	uint32_t oui = 0;
 	int num = 0;
 
+
+	BUF_PUT_BE24(vendor_oui, EASYMESH_VENDOR_EXT_OUI_DEFAULT);
+#ifdef EASYMESH_VENDOR_EXT_OUI
+	oui = EASYMESH_VENDOR_EXT_OUI;
+	BUF_PUT_BE24(vendor_oui, oui);
+#endif
+
 	while (num < 16 && tv[num]) {
 		uint16_t tlv_len = 0;
 		struct tlv_vendor_bbss *tlv;
@@ -1063,7 +1072,7 @@ static int validate_topology_response_vext(struct tlv *tv[16])
 		if (offset + 3 > tlv_len)
 			return -1;
 
-		memcpy(oui2, EASYMESH_VENDOR_EXT_OUI, 3);
+		memcpy(oui2, vendor_oui, 3);
 		oui2[2]++;
 		if (memcmp(tlv->oui, oui2, 3)) {
 			num++;
diff --git a/src/cntlr.h b/src/cntlr.h
index 2e1a4324..5dbcfd38 100644
--- a/src/cntlr.h
+++ b/src/cntlr.h
@@ -31,8 +31,9 @@
 #include "steer.h"
 #include "allmac.h"
 
-#ifndef EASYMESH_VENDOR_EXT_OUI
-#define EASYMESH_VENDOR_EXT_OUI         (uint8_t *)"\x00\x11\x22"
+
+#ifndef EASYMESH_VENDOR_EXT_OUI_DEFAULT
+#define EASYMESH_VENDOR_EXT_OUI_DEFAULT		0xB456FA  /* IOPSYS OUI */
 #endif
 
 extern const char *ubus_socket;
diff --git a/src/cntlr_map.c b/src/cntlr_map.c
index 4d6decc8..a69c0752 100644
--- a/src/cntlr_map.c
+++ b/src/cntlr_map.c
@@ -237,8 +237,17 @@ int handle_topology_query(void *cntlr, struct cmdu_buff *cmdu, struct node *n)
 #ifdef EASYMESH_VENDOR_EXT
 static int topology_response_vext(struct controller *c, struct node *n, struct tlv *tv[16])
 {
+	const uint8_t vendor_oui[4] = {0};
+	uint32_t oui = 0;
 	int num = 0;
 
+
+	BUF_PUT_BE24(vendor_oui, EASYMESH_VENDOR_EXT_OUI_DEFAULT);
+#ifdef EASYMESH_VENDOR_EXT_OUI
+	oui = EASYMESH_VENDOR_EXT_OUI;
+	BUF_PUT_BE24(vendor_oui, oui);
+#endif
+
 	/* vendor tlv containing backhaul interfaces only */
 	while (num < 16 && tv[num]) {
 		struct tlv_vendor_bbss *tlv;
@@ -250,7 +259,7 @@ static int topology_response_vext(struct controller *c, struct node *n, struct t
 			return -1;
 
 		/* oui (3 bytes) */
-		memcpy(oui2, EASYMESH_VENDOR_EXT_OUI, 3);
+		memcpy(oui2, vendor_oui, 3);
 		oui2[2]++;
 
 		if (memcmp(tlv->oui, oui2, 3)) {
diff --git a/src/config.c b/src/config.c
index 1b0d7234..af87ed6e 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1185,10 +1185,18 @@ static int cntlr_config_get_credentials(struct controller_config *c,
 		uint8_t offset = 0;
 		uint8_t attr = 0x4c;
 		uint8_t attr_len = 0x01;
+		const uint8_t vendor_oui[4] = {0};
+		uint32_t oui = 0;
 
+
+		BUF_PUT_BE24(vendor_oui, EASYMESH_VENDOR_EXT_OUI_DEFAULT);
+#ifdef EASYMESH_VENDOR_EXT_OUI
+		oui = EASYMESH_VENDOR_EXT_OUI;
+		BUF_PUT_BE24(vendor_oui, oui);
+#endif
 		ext = &cred->ven_ies[0];
 
-		memcpy(ext->oui, EASYMESH_VENDOR_EXT_OUI, 3);
+		memcpy(ext->oui, vendor_oui, 3);
 		ext->len = 3;
 		ext->payload = calloc(1, ext->len);
 		if (!ext->payload)
-- 
GitLab