From 34ff437b53a5a3f06bef89b843b33aec43472535 Mon Sep 17 00:00:00 2001 From: Jesus Sanchez-Palencia Date: Wed, 5 Apr 2017 18:01:39 -0700 Subject: [PATCH] drivers: slip: Add LLDP support Enable LLDP TX support on the slip ethernet driver. Now when CONFIG_NET_LLDP is enabled, one can easily verify on a sniffer (i.e. wireshark) that LLDP frames are being sent at the configured interval with all mandatory TLVs enabled. Signed-off-by: Jesus Sanchez-Palencia --- drivers/net/slip.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/net/slip.c b/drivers/net/slip.c index 97ae03cdd5e..6419c819864 100644 --- a/drivers/net/slip.c +++ b/drivers/net/slip.c @@ -22,10 +22,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -63,6 +65,35 @@ struct slip_context { #endif }; +#if defined(CONFIG_NET_LLDP) +static const struct net_lldpdu lldpdu = { + .chassis_id = { + .type_length = htons((LLDP_TLV_CHASSIS_ID << 9) | + NET_LLDP_CHASSIS_ID_TLV_LEN), + .subtype = CONFIG_NET_LLDP_CHASSIS_ID_SUBTYPE, + .value = NET_LLDP_CHASSIS_ID_VALUE + }, + .port_id = { + .type_length = htons((LLDP_TLV_PORT_ID << 9) | + NET_LLDP_PORT_ID_TLV_LEN), + .subtype = CONFIG_NET_LLDP_PORT_ID_SUBTYPE, + .value = NET_LLDP_PORT_ID_VALUE + }, + .ttl = { + .type_length = htons((LLDP_TLV_TTL << 9) | + NET_LLDP_TTL_TLV_LEN), + .ttl = htons(NET_LLDP_TTL) + }, +#if defined(CONFIG_NET_LLDP_END_LLDPDU_TLV_ENABLED) + .end_lldpdu_tlv = NET_LLDP_END_LLDPDU_VALUE +#endif /* CONFIG_NET_LLDP_END_LLDPDU_TLV_ENABLED */ +}; + +#define lldpdu_ptr (&lldpdu) +#else +#define lldpdu_ptr NULL +#endif /* CONFIG_NET_LLDP */ + #if SYS_LOG_LEVEL >= SYS_LOG_LEVEL_DEBUG #if defined(CONFIG_SYS_LOG_SHOW_COLOR) #define COLOR_OFF "\x1B[0m" @@ -479,11 +510,14 @@ static void slip_iface_init(struct net_if *iface) ethernet_init(iface); + net_eth_set_lldpdu(iface, lldpdu_ptr); + if (slip->init_done) { return; } ll_addr = slip_get_mac(slip); + slip->init_done = true; slip->iface = iface; @@ -512,7 +546,11 @@ static enum ethernet_hw_caps eth_capabilities(struct device *dev) { ARG_UNUSED(dev); - return ETHERNET_HW_VLAN; + return ETHERNET_HW_VLAN +#if defined(CONFIG_NET_LLDP) + | ETHERNET_LLDP +#endif + ; } #if defined(CONFIG_SLIP_TAP) && defined(CONFIG_NET_L2_ETHERNET)