net: lldp: Move LLDP structure definition to lldp
Move duplicated structure definitions to lldp subsystem from drivers. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
parent
57f5f80293
commit
fba09bffb2
6 changed files with 80 additions and 111 deletions
|
@ -32,6 +32,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <ptp_clock.h>
|
#include <ptp_clock.h>
|
||||||
#include <net/gptp.h>
|
#include <net/gptp.h>
|
||||||
|
#include <net/lldp.h>
|
||||||
|
|
||||||
#include "eth_native_posix_priv.h"
|
#include "eth_native_posix_priv.h"
|
||||||
|
|
||||||
|
@ -47,35 +48,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
#define ETH_HDR_LEN sizeof(struct net_eth_hdr)
|
#define ETH_HDR_LEN sizeof(struct net_eth_hdr)
|
||||||
#endif
|
#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 */
|
|
||||||
|
|
||||||
struct eth_context {
|
struct eth_context {
|
||||||
u8_t recv[_ETH_MTU + ETH_HDR_LEN];
|
u8_t recv[_ETH_MTU + ETH_HDR_LEN];
|
||||||
u8_t send[_ETH_MTU + ETH_HDR_LEN];
|
u8_t send[_ETH_MTU + ETH_HDR_LEN];
|
||||||
|
@ -363,7 +335,7 @@ static void eth_iface_init(struct net_if *iface)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_eth_set_lldpdu(iface, lldpdu_ptr);
|
net_lldp_set_lldpdu(iface);
|
||||||
|
|
||||||
ctx->init_done = true;
|
ctx->init_done = true;
|
||||||
|
|
||||||
|
@ -482,9 +454,9 @@ static int vlan_setup(struct device *dev, struct net_if *iface,
|
||||||
u16_t tag, bool enable)
|
u16_t tag, bool enable)
|
||||||
{
|
{
|
||||||
if (enable) {
|
if (enable) {
|
||||||
net_eth_set_lldpdu(iface, lldpdu_ptr);
|
net_lldp_set_lldpdu(iface);
|
||||||
} else {
|
} else {
|
||||||
net_eth_unset_lldpdu(iface);
|
net_lldp_unset_lldpdu(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -32,6 +32,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
#include <net/net_core.h>
|
#include <net/net_core.h>
|
||||||
#include <console/uart_pipe.h>
|
#include <console/uart_pipe.h>
|
||||||
#include <net/ethernet.h>
|
#include <net/ethernet.h>
|
||||||
|
#include <net/lldp.h>
|
||||||
|
|
||||||
#define SLIP_END 0300
|
#define SLIP_END 0300
|
||||||
#define SLIP_ESC 0333
|
#define SLIP_ESC 0333
|
||||||
|
@ -67,35 +68,6 @@ struct slip_context {
|
||||||
#endif
|
#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 */
|
|
||||||
|
|
||||||
static inline void slip_writeb(unsigned char c)
|
static inline void slip_writeb(unsigned char c)
|
||||||
{
|
{
|
||||||
u8_t buf[1] = { c };
|
u8_t buf[1] = { c };
|
||||||
|
@ -425,7 +397,7 @@ static void slip_iface_init(struct net_if *iface)
|
||||||
|
|
||||||
ethernet_init(iface);
|
ethernet_init(iface);
|
||||||
|
|
||||||
net_eth_set_lldpdu(iface, lldpdu_ptr);
|
net_lldp_set_lldpdu(iface);
|
||||||
|
|
||||||
if (slip->init_done) {
|
if (slip->init_done) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -688,43 +688,6 @@ static inline int net_eth_get_ptp_port(struct net_if *iface)
|
||||||
void net_eth_set_ptp_port(struct net_if *iface, int port);
|
void net_eth_set_ptp_port(struct net_if *iface, int port);
|
||||||
#endif /* CONFIG_NET_GPTP */
|
#endif /* CONFIG_NET_GPTP */
|
||||||
|
|
||||||
struct net_lldpdu;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set LLDP protocol data unit (LLDPDU) for the network interface.
|
|
||||||
*
|
|
||||||
* @param iface Network interface
|
|
||||||
* @param lldpdu LLDPDU pointer
|
|
||||||
*
|
|
||||||
* @return <0 if error, index in lldp array if iface is found there
|
|
||||||
*/
|
|
||||||
#if defined(CONFIG_NET_LLDP)
|
|
||||||
int net_eth_set_lldpdu(struct net_if *iface, const struct net_lldpdu *lldpdu);
|
|
||||||
#else
|
|
||||||
static inline int net_eth_set_lldpdu(struct net_if *iface,
|
|
||||||
const struct net_lldpdu *lldpdu)
|
|
||||||
{
|
|
||||||
ARG_UNUSED(iface);
|
|
||||||
ARG_UNUSED(lldpdu);
|
|
||||||
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unset LLDP protocol data unit (LLDPDU) for the network interface.
|
|
||||||
*
|
|
||||||
* @param iface Network interface
|
|
||||||
*/
|
|
||||||
#if defined(CONFIG_NET_LLDP)
|
|
||||||
void net_eth_unset_lldpdu(struct net_if *iface);
|
|
||||||
#else
|
|
||||||
static inline void net_eth_unset_lldpdu(struct net_if *iface)
|
|
||||||
{
|
|
||||||
ARG_UNUSED(iface);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define LLDP_TLV_GET_LENGTH(type_length) (type_length & BIT_MASK(9))
|
||||||
|
#define LLDP_TLV_GET_TYPE(type_length) ((u8_t)(type_length >> 9))
|
||||||
|
|
||||||
/* LLDP Definitions */
|
/* LLDP Definitions */
|
||||||
|
|
||||||
/* According to the spec, End of LLDPDU TLV value is constant. */
|
/* According to the spec, End of LLDPDU TLV value is constant. */
|
||||||
|
@ -196,6 +199,30 @@ int net_lldp_register_callback(struct net_if *iface, net_lldp_recv_cb_t cb);
|
||||||
*/
|
*/
|
||||||
enum net_verdict net_lldp_recv(struct net_if *iface, struct net_pkt *pkt);
|
enum net_verdict net_lldp_recv(struct net_if *iface, struct net_pkt *pkt);
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_LLDP)
|
||||||
|
/**
|
||||||
|
* @brief Set LLDP protocol data unit (LLDPDU) for the network interface.
|
||||||
|
*
|
||||||
|
* @param iface Network interface
|
||||||
|
*
|
||||||
|
* @return <0 if error, index in lldp array if iface is found there
|
||||||
|
*/
|
||||||
|
int net_lldp_set_lldpdu(struct net_if *iface);
|
||||||
|
#else
|
||||||
|
#define net_lldp_set_lldpdu(iface)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_LLDP)
|
||||||
|
/**
|
||||||
|
* @brief Unset LLDP protocol data unit (LLDPDU) for the network interface.
|
||||||
|
*
|
||||||
|
* @param iface Network interface
|
||||||
|
*/
|
||||||
|
void net_lldp_unset_lldpdu(struct net_if *iface);
|
||||||
|
#else
|
||||||
|
#define net_lldp_unset_lldpdu(iface)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -959,18 +959,6 @@ int net_eth_promisc_mode(struct net_if *iface, bool enable)
|
||||||
¶ms, sizeof(struct ethernet_req_params));
|
¶ms, sizeof(struct ethernet_req_params));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_LLDP)
|
|
||||||
int net_eth_set_lldpdu(struct net_if *iface, const struct net_lldpdu *lldpdu)
|
|
||||||
{
|
|
||||||
return net_lldp_config(iface, lldpdu);
|
|
||||||
}
|
|
||||||
|
|
||||||
void net_eth_unset_lldpdu(struct net_if *iface)
|
|
||||||
{
|
|
||||||
net_lldp_config(iface, NULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ethernet_init(struct net_if *iface)
|
void ethernet_init(struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct ethernet_context *ctx = net_if_l2_data(iface);
|
struct ethernet_context *ctx = net_if_l2_data(iface);
|
||||||
|
|
|
@ -307,6 +307,53 @@ int net_lldp_config(struct net_if *iface, const struct net_lldpdu *lldpdu)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int net_lldp_config_optional(struct net_if *iface, const u8_t *tlv, size_t len)
|
||||||
|
{
|
||||||
|
struct ethernet_context *ctx = net_if_l2_data(iface);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = lldp_find(ctx, iface);
|
||||||
|
if (i < 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->lldp[i].optional_du = tlv;
|
||||||
|
ctx->lldp[i].optional_len = len;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
int net_lldp_set_lldpdu(struct net_if *iface)
|
||||||
|
{
|
||||||
|
return net_lldp_config(iface, &lldpdu);
|
||||||
|
}
|
||||||
|
|
||||||
|
void net_lldp_unset_lldpdu(struct net_if *iface)
|
||||||
|
{
|
||||||
|
net_lldp_config(iface, NULL);
|
||||||
|
net_lldp_config_optional(iface, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
void net_lldp_init(void)
|
void net_lldp_init(void)
|
||||||
{
|
{
|
||||||
k_delayed_work_init(&lldp_tx_timer, lldp_tx_timeout);
|
k_delayed_work_init(&lldp_tx_timer, lldp_tx_timeout);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue