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

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