Blame SOURCES/open-lldp-v1.0.1-10-VDP-Support-for-OUI-infrastructure-in-vdp22.patch

ee47b4
From 7289ac24898ae74a3a47fb4e4378d1535c21adba Mon Sep 17 00:00:00 2001
ee47b4
From: padkrish <padkrish@cisco.com>
ee47b4
Date: Wed, 21 Jan 2015 03:39:47 +0000
ee47b4
Subject: [PATCH] VDP: Support for OUI infrastructure in vdp22.
ee47b4
ee47b4
This commit is a framework for supporting OUI fields
ee47b4
in VDP22. This specific patch adds helper functions
ee47b4
(functions exported by VDP to OUI code) to be called by OUI
ee47b4
specific handler code.
ee47b4
ee47b4
Signed-off-by: padkrish <padkrish@cisco.com>
ee47b4
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
ee47b4
---
ee47b4
 Makefile.am             |  2 +-
ee47b4
 include/qbg_utils.h     |  1 +
ee47b4
 include/qbg_vdp22_oui.h | 48 +++++++++++++++++++++++++++++++++++++
ee47b4
 qbg/vdp22_oui.c         | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
ee47b4
 4 files changed, 113 insertions(+), 1 deletion(-)
ee47b4
 create mode 100644 qbg/vdp22_oui.c
ee47b4
ee47b4
diff --git a/Makefile.am b/Makefile.am
ee47b4
index 403088b..f63311c 100644
ee47b4
--- a/Makefile.am
ee47b4
+++ b/Makefile.am
ee47b4
@@ -70,7 +70,7 @@ include/lldp_evb22.h lldp_evb22.c lldp_evb22_cmds.c \
ee47b4
 include/qbg22.h include/qbg_ecp22.h qbg/ecp22.c \
ee47b4
 include/qbg_vdp22.h qbg/vdp22.c qbg/vdpnl.c qbg/vdp22sm.c qbg/vdp22br.c \
ee47b4
 include/qbg_vdp22def.h qbg/vdp22_cmds.c qbg/vdp_ascii.c \
ee47b4
-include/qbg_vdp22_oui.h
ee47b4
+include/qbg_vdp22_oui.h qbg/vdp22_oui.c
ee47b4
 
ee47b4
 lib_LTLIBRARIES = liblldp_clif.la
ee47b4
 liblldp_clif_la_LDFLAGS = -version-info 1:0:0
ee47b4
diff --git a/include/qbg_utils.h b/include/qbg_utils.h
ee47b4
index 6033556..963cb87 100644
ee47b4
--- a/include/qbg_utils.h
ee47b4
+++ b/include/qbg_utils.h
ee47b4
@@ -42,4 +42,5 @@ int modules_notify(int, int, char *, void *);
ee47b4
 
ee47b4
 /* Convert VSI IDs to strings */
ee47b4
 int vdp_uuid2str(const unsigned char *, char *, size_t);
ee47b4
+int vdp_str2uuid(unsigned char *, char *, size_t);
ee47b4
 #endif
ee47b4
diff --git a/include/qbg_vdp22_oui.h b/include/qbg_vdp22_oui.h
ee47b4
index 0cce31e..79e1ff5 100644
ee47b4
--- a/include/qbg_vdp22_oui.h
ee47b4
+++ b/include/qbg_vdp22_oui.h
ee47b4
@@ -92,4 +92,52 @@ struct vdp22_oui_handler_s {
ee47b4
 	unsigned long (*oui_ptlv_size_hndlr)(void *);
ee47b4
 };
ee47b4
 
ee47b4
+unsigned char vdp22_oui_get_vsi22_fmt(void *);
ee47b4
+unsigned char *vdp22_oui_get_vsi22_len(void *, unsigned char *);
ee47b4
+int oui_vdp_str2uuid(unsigned char *, char *, size_t);
ee47b4
+bool oui_vdp_hndlr_init(struct vdp22_oui_handler_s *);
ee47b4
+int oui_vdp_hexstr2bin(const char *hex, unsigned char *buf, size_t len);
ee47b4
+
ee47b4
+static inline size_t oui_append_1o(unsigned char *cp, const unsigned char data)
ee47b4
+{
ee47b4
+	*cp = data;
ee47b4
+	return 1;
ee47b4
+}
ee47b4
+
ee47b4
+static inline size_t oui_append_2o(unsigned char *cp, const unsigned short data)
ee47b4
+{
ee47b4
+	*cp = (data >> 8) & 0xff;
ee47b4
+	*(cp + 1) = data & 0xff;
ee47b4
+	return 2;
ee47b4
+}
ee47b4
+
ee47b4
+static inline size_t oui_append_3o(unsigned char *cp, const unsigned long data)
ee47b4
+{
ee47b4
+	*cp = (data >> 16) & 0xff;
ee47b4
+	*(cp + 1) = (data >> 8) & 0xff;
ee47b4
+	*(cp + 2) = data & 0xff;
ee47b4
+	return 3;
ee47b4
+}
ee47b4
+static inline size_t oui_append_4o(unsigned char *cp, const unsigned long data)
ee47b4
+{
ee47b4
+	*cp = (data >> 24) & 0xff;
ee47b4
+	*(cp + 1) = (data >> 16) & 0xff;
ee47b4
+	*(cp + 2) = (data >> 8) & 0xff;
ee47b4
+	*(cp + 3) = data & 0xff;
ee47b4
+	return 4;
ee47b4
+}
ee47b4
+
ee47b4
+static inline size_t oui_append_nb(unsigned char *cp, const unsigned char *data,
ee47b4
+				   const size_t nlen)
ee47b4
+{
ee47b4
+	memcpy(cp, data, nlen);
ee47b4
+	return nlen;
ee47b4
+}
ee47b4
+
ee47b4
+static inline unsigned short oui_get_tlv_head(unsigned short type,
ee47b4
+					      unsigned short len)
ee47b4
+{
ee47b4
+	return (type & 0x7f) << 9 | (len & 0x1ff);
ee47b4
+}
ee47b4
+
ee47b4
 #endif /* __VDP22_OUI_H__ */
ee47b4
diff --git a/qbg/vdp22_oui.c b/qbg/vdp22_oui.c
ee47b4
new file mode 100644
ee47b4
index 0000000..3a2d0cc
ee47b4
--- /dev/null
ee47b4
+++ b/qbg/vdp22_oui.c
ee47b4
@@ -0,0 +1,63 @@
ee47b4
+/*******************************************************************************
ee47b4
+
ee47b4
+  Implementation of OUI Functionality for VDP2.2
ee47b4
+  This file contains the exported functions from VDP to the OUI handlers file.
ee47b4
+  Copyright (c) 2012-2014 by Cisco Systems, Inc.
ee47b4
+
ee47b4
+  Author(s): Padmanabhan Krishnan <padkrish at cisco dot com>
ee47b4
+
ee47b4
+  This program is free software; you can redistribute it and/or modify it
ee47b4
+  under the terms and conditions of the GNU General Public License,
ee47b4
+  version 2, as published by the Free Software Foundation.
ee47b4
+
ee47b4
+  This program is distributed in the hope it will be useful, but WITHOUT
ee47b4
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ee47b4
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
ee47b4
+  more details.
ee47b4
+
ee47b4
+  You should have received a copy of the GNU General Public License along with
ee47b4
+  this program; if not, write to the Free Software Foundation, Inc.,
ee47b4
+  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
ee47b4
+
ee47b4
+  The full GNU General Public License is included in this distribution in
ee47b4
+  the file called "COPYING".
ee47b4
+*******************************************************************************/
ee47b4
+
ee47b4
+#include <stdio.h>
ee47b4
+#include <stdlib.h>
ee47b4
+#include <string.h>
ee47b4
+#include <errno.h>
ee47b4
+#include <ctype.h>
ee47b4
+#include "messages.h"
ee47b4
+#include "lldp_util.h"
ee47b4
+#include "qbg_vdp22.h"
ee47b4
+#include "qbg_utils.h"
ee47b4
+#include "qbg_vdp22_oui.h"
ee47b4
+
ee47b4
+unsigned char vdp22_oui_get_vsi22_fmt(void *vsi_data)
ee47b4
+{
ee47b4
+	if (vsi_data != NULL)
ee47b4
+		return ((struct vsi22 *)(vsi_data))->vsi_fmt;
ee47b4
+	LLDPAD_ERR("%s: NULL Arg\n", __func__);
ee47b4
+	return 0;
ee47b4
+}
ee47b4
+
ee47b4
+unsigned char *vdp22_oui_get_vsi22_len(void *vsi_data, unsigned char *len)
ee47b4
+{
ee47b4
+	if ((vsi_data != NULL) && (len != NULL)) {
ee47b4
+		*len = VDP22_IDSZ;
ee47b4
+		return ((struct vsi22 *)(vsi_data))->vsi;
ee47b4
+	}
ee47b4
+	LLDPAD_ERR("%s: NULL Arg\n", __func__);
ee47b4
+	return NULL;
ee47b4
+}
ee47b4
+
ee47b4
+int oui_vdp_str2uuid(unsigned char *to, char *buffer, size_t max)
ee47b4
+{
ee47b4
+	return vdp_str2uuid(to, buffer, max);
ee47b4
+}
ee47b4
+
ee47b4
+int oui_vdp_hexstr2bin(const char *hex, unsigned char *buf, size_t len)
ee47b4
+{
ee47b4
+	return hexstr2bin(hex, buf, len);
ee47b4
+}
ee47b4
-- 
ee47b4
2.1.0
ee47b4