Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
lldp.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2017 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_LLDP_H_
14#define ZEPHYR_INCLUDE_NET_LLDP_H_
15
23#ifdef __cplusplus
24extern "C" {
25#endif
26
29#define LLDP_TLV_GET_LENGTH(type_length) (type_length & BIT_MASK(9))
30#define LLDP_TLV_GET_TYPE(type_length) ((uint8_t)(type_length >> 9))
31
32/* LLDP Definitions */
33
34/* According to the spec, End of LLDPDU TLV value is constant. */
35#define NET_LLDP_END_LLDPDU_VALUE 0x0000
36
37/*
38 * For the Chassis ID TLV Value, if subtype is a MAC address then we must
39 * use values from CONFIG_NET_LLDP_CHASSIS_ID_MAC0 through
40 * CONFIG_NET_LLDP_CHASSIS_ID_MAC5. If not, we use CONFIG_NET_LLDP_CHASSIS_ID.
41 *
42 * FIXME: implement a similar scheme for subtype 5 (network address).
43 */
44#if defined(CONFIG_NET_LLDP_CHASSIS_ID_SUBTYPE)
45#if (CONFIG_NET_LLDP_CHASSIS_ID_SUBTYPE == 4)
46#define NET_LLDP_CHASSIS_ID_VALUE \
47 { \
48 CONFIG_NET_LLDP_CHASSIS_ID_MAC0, \
49 CONFIG_NET_LLDP_CHASSIS_ID_MAC1, \
50 CONFIG_NET_LLDP_CHASSIS_ID_MAC2, \
51 CONFIG_NET_LLDP_CHASSIS_ID_MAC3, \
52 CONFIG_NET_LLDP_CHASSIS_ID_MAC4, \
53 CONFIG_NET_LLDP_CHASSIS_ID_MAC5 \
54 }
55
56#define NET_LLDP_CHASSIS_ID_VALUE_LEN (6)
57#else
58#define NET_LLDP_CHASSIS_ID_VALUE CONFIG_NET_LLDP_CHASSIS_ID
59#define NET_LLDP_CHASSIS_ID_VALUE_LEN (sizeof(CONFIG_NET_LLDP_CHASSIS_ID) - 1)
60#endif
61#else
62#define NET_LLDP_CHASSIS_ID_VALUE 0
63#define NET_LLDP_CHASSIS_ID_VALUE_LEN 0
64#endif
65
66/*
67 * For the Port ID TLV Value, if subtype is a MAC address then we must
68 * use values from CONFIG_NET_LLDP_PORT_ID_MAC0 through
69 * CONFIG_NET_LLDP_PORT_ID_MAC5. If not, we use CONFIG_NET_LLDP_PORT_ID.
70 *
71 * FIXME: implement a similar scheme for subtype 4 (network address).
72 */
73#if defined(CONFIG_NET_LLDP_PORT_ID_SUBTYPE)
74#if (CONFIG_NET_LLDP_PORT_ID_SUBTYPE == 3)
75#define NET_LLDP_PORT_ID_VALUE \
76 { \
77 CONFIG_NET_LLDP_PORT_ID_MAC0, \
78 CONFIG_NET_LLDP_PORT_ID_MAC1, \
79 CONFIG_NET_LLDP_PORT_ID_MAC2, \
80 CONFIG_NET_LLDP_PORT_ID_MAC3, \
81 CONFIG_NET_LLDP_PORT_ID_MAC4, \
82 CONFIG_NET_LLDP_PORT_ID_MAC5 \
83 }
84
85#define NET_LLDP_PORT_ID_VALUE_LEN (6)
86#else
87#define NET_LLDP_PORT_ID_VALUE CONFIG_NET_LLDP_PORT_ID
88#define NET_LLDP_PORT_ID_VALUE_LEN (sizeof(CONFIG_NET_LLDP_PORT_ID) - 1)
89#endif
90#else
91#define NET_LLDP_PORT_ID_VALUE 0
92#define NET_LLDP_PORT_ID_VALUE_LEN 0
93#endif
94
95/*
96 * TLVs Length.
97 * Note that TLVs that have a subtype must have a byte added to their length.
98 */
99#define NET_LLDP_CHASSIS_ID_TLV_LEN (NET_LLDP_CHASSIS_ID_VALUE_LEN + 1)
100#define NET_LLDP_PORT_ID_TLV_LEN (NET_LLDP_PORT_ID_VALUE_LEN + 1)
101#define NET_LLDP_TTL_TLV_LEN (2)
102
103/*
104 * Time to Live value.
105 * Calculate based on section 9.2.5.22 from LLDP spec.
106 *
107 * FIXME: when the network interface is about to be ‘disabled’ TTL shall be set
108 * to zero so LLDP Rx agents can invalidate the entry related to this node.
109 */
110#if defined(CONFIG_NET_LLDP_TX_INTERVAL) && defined(CONFIG_NET_LLDP_TX_HOLD)
111#define NET_LLDP_TTL \
112 MIN((CONFIG_NET_LLDP_TX_INTERVAL * CONFIG_NET_LLDP_TX_HOLD) + 1, 65535)
113#endif
114
115
116struct net_if;
117
131 /* Types 9 - 126 are reserved. */
133};
134
142 uint8_t value[NET_LLDP_CHASSIS_ID_VALUE_LEN];
143} __packed;
144
152 uint8_t value[NET_LLDP_PORT_ID_VALUE_LEN];
153} __packed;
154
161} __packed;
162
171} __packed;
172
181int net_lldp_config(struct net_if *iface, const struct net_lldpdu *lldpdu);
182
192int net_lldp_config_optional(struct net_if *iface, const uint8_t *tlv,
193 size_t len);
194
198void net_lldp_init(void);
199
213typedef enum net_verdict (*net_lldp_recv_cb_t)(struct net_if *iface,
214 struct net_pkt *pkt);
215
225
234enum net_verdict net_lldp_recv(struct net_if *iface, struct net_pkt *pkt);
235
243#if defined(CONFIG_NET_LLDP)
244int net_lldp_set_lldpdu(struct net_if *iface);
245#else
246#define net_lldp_set_lldpdu(iface)
247#endif
248
254#if defined(CONFIG_NET_LLDP)
256#else
257#define net_lldp_unset_lldpdu(iface)
258#endif
259
260#ifdef __cplusplus
261}
262#endif
263
268#endif /* ZEPHYR_INCLUDE_NET_LLDP_H_ */
int net_lldp_config(struct net_if *iface, const struct net_lldpdu *lldpdu)
Set the LLDP data unit for a network interface.
enum net_verdict(* net_lldp_recv_cb_t)(struct net_if *iface, struct net_pkt *pkt)
LLDP Receive packet callback.
Definition: lldp.h:213
void net_lldp_init(void)
Initialize LLDP engine.
int net_lldp_register_callback(struct net_if *iface, net_lldp_recv_cb_t cb)
Register LLDP Rx callback function.
#define net_lldp_set_lldpdu(iface)
Set LLDP protocol data unit (LLDPDU) for the network interface.
Definition: lldp.h:246
int net_lldp_config_optional(struct net_if *iface, const uint8_t *tlv, size_t len)
Set the Optional LLDP TLVs for a network interface.
net_lldp_tlv_type
Definition: lldp.h:121
#define net_lldp_unset_lldpdu(iface)
Unset LLDP protocol data unit (LLDPDU) for the network interface.
Definition: lldp.h:257
enum net_verdict net_lldp_recv(struct net_if *iface, struct net_pkt *pkt)
Parse LLDP packet.
@ LLDP_TLV_ORG_SPECIFIC
Definition: lldp.h:132
@ LLDP_TLV_PORT_ID
Definition: lldp.h:124
@ LLDP_TLV_END_LLDPDU
Definition: lldp.h:122
@ LLDP_TLV_PORT_DESC
Definition: lldp.h:126
@ LLDP_TLV_SYSTEM_CAPABILITIES
Definition: lldp.h:129
@ LLDP_TLV_MANAGEMENT_ADDR
Definition: lldp.h:130
@ LLDP_TLV_SYSTEM_DESC
Definition: lldp.h:128
@ LLDP_TLV_SYSTEM_NAME
Definition: lldp.h:127
@ LLDP_TLV_CHASSIS_ID
Definition: lldp.h:123
@ LLDP_TLV_TTL
Definition: lldp.h:125
net_verdict
Net Verdict.
Definition: net_core.h:97
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Network Interface structure.
Definition: net_if.h:468
Definition: lldp.h:136
uint8_t value[NET_LLDP_CHASSIS_ID_VALUE_LEN]
Definition: lldp.h:142
uint8_t subtype
Definition: lldp.h:140
uint16_t type_length
Definition: lldp.h:138
Definition: lldp.h:146
uint8_t subtype
Definition: lldp.h:150
uint16_t type_length
Definition: lldp.h:148
uint8_t value[NET_LLDP_PORT_ID_VALUE_LEN]
Definition: lldp.h:152
Definition: lldp.h:156
uint16_t type_length
Definition: lldp.h:158
uint16_t ttl
Definition: lldp.h:160
Definition: lldp.h:167
struct net_lldp_chassis_tlv chassis_id
Definition: lldp.h:168
struct net_lldp_port_tlv port_id
Definition: lldp.h:169
struct net_lldp_time_to_live_tlv ttl
Definition: lldp.h:170
Network packet.
Definition: net_pkt.h:62
struct net_if * iface
Definition: net_pkt.h:85