Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
25#ifdef __cplusplus
26extern "C" {
27#endif
28
31#define LLDP_TLV_GET_LENGTH(type_length) (type_length & BIT_MASK(9))
32#define LLDP_TLV_GET_TYPE(type_length) ((uint8_t)(type_length >> 9))
33
34/* LLDP Definitions */
35
36/* According to the spec, End of LLDPDU TLV value is constant. */
37#define NET_LLDP_END_LLDPDU_VALUE 0x0000
38
39/*
40 * For the Chassis ID TLV Value, if subtype is a MAC address then we must
41 * use values from CONFIG_NET_LLDP_CHASSIS_ID_MAC0 through
42 * CONFIG_NET_LLDP_CHASSIS_ID_MAC5. If not, we use CONFIG_NET_LLDP_CHASSIS_ID.
43 *
44 * FIXME: implement a similar scheme for subtype 5 (network address).
45 */
46#if defined(CONFIG_NET_LLDP_CHASSIS_ID_SUBTYPE)
47#if (CONFIG_NET_LLDP_CHASSIS_ID_SUBTYPE == 4)
48#define NET_LLDP_CHASSIS_ID_VALUE \
49 { \
50 CONFIG_NET_LLDP_CHASSIS_ID_MAC0, \
51 CONFIG_NET_LLDP_CHASSIS_ID_MAC1, \
52 CONFIG_NET_LLDP_CHASSIS_ID_MAC2, \
53 CONFIG_NET_LLDP_CHASSIS_ID_MAC3, \
54 CONFIG_NET_LLDP_CHASSIS_ID_MAC4, \
55 CONFIG_NET_LLDP_CHASSIS_ID_MAC5 \
56 }
57
58#define NET_LLDP_CHASSIS_ID_VALUE_LEN (6)
59#else
60#define NET_LLDP_CHASSIS_ID_VALUE CONFIG_NET_LLDP_CHASSIS_ID
61#define NET_LLDP_CHASSIS_ID_VALUE_LEN (sizeof(CONFIG_NET_LLDP_CHASSIS_ID) - 1)
62#endif
63#else
64#define NET_LLDP_CHASSIS_ID_VALUE 0
65#define NET_LLDP_CHASSIS_ID_VALUE_LEN 0
66#endif
67
68/*
69 * For the Port ID TLV Value, if subtype is a MAC address then we must
70 * use values from CONFIG_NET_LLDP_PORT_ID_MAC0 through
71 * CONFIG_NET_LLDP_PORT_ID_MAC5. If not, we use CONFIG_NET_LLDP_PORT_ID.
72 *
73 * FIXME: implement a similar scheme for subtype 4 (network address).
74 */
75#if defined(CONFIG_NET_LLDP_PORT_ID_SUBTYPE)
76#if (CONFIG_NET_LLDP_PORT_ID_SUBTYPE == 3)
77#define NET_LLDP_PORT_ID_VALUE \
78 { \
79 CONFIG_NET_LLDP_PORT_ID_MAC0, \
80 CONFIG_NET_LLDP_PORT_ID_MAC1, \
81 CONFIG_NET_LLDP_PORT_ID_MAC2, \
82 CONFIG_NET_LLDP_PORT_ID_MAC3, \
83 CONFIG_NET_LLDP_PORT_ID_MAC4, \
84 CONFIG_NET_LLDP_PORT_ID_MAC5 \
85 }
86
87#define NET_LLDP_PORT_ID_VALUE_LEN (6)
88#else
89#define NET_LLDP_PORT_ID_VALUE CONFIG_NET_LLDP_PORT_ID
90#define NET_LLDP_PORT_ID_VALUE_LEN (sizeof(CONFIG_NET_LLDP_PORT_ID) - 1)
91#endif
92#else
93#define NET_LLDP_PORT_ID_VALUE 0
94#define NET_LLDP_PORT_ID_VALUE_LEN 0
95#endif
96
97/*
98 * TLVs Length.
99 * Note that TLVs that have a subtype must have a byte added to their length.
100 */
101#define NET_LLDP_CHASSIS_ID_TLV_LEN (NET_LLDP_CHASSIS_ID_VALUE_LEN + 1)
102#define NET_LLDP_PORT_ID_TLV_LEN (NET_LLDP_PORT_ID_VALUE_LEN + 1)
103#define NET_LLDP_TTL_TLV_LEN (2)
104
105/*
106 * Time to Live value.
107 * Calculate based on section 9.2.5.22 from LLDP spec.
108 *
109 * FIXME: when the network interface is about to be ‘disabled’ TTL shall be set
110 * to zero so LLDP Rx agents can invalidate the entry related to this node.
111 */
112#if defined(CONFIG_NET_LLDP_TX_INTERVAL) && defined(CONFIG_NET_LLDP_TX_HOLD)
113#define NET_LLDP_TTL \
114 MIN((CONFIG_NET_LLDP_TX_INTERVAL * CONFIG_NET_LLDP_TX_HOLD) + 1, 65535)
115#endif
116
117
118struct net_if;
119
136
144 uint8_t value[NET_LLDP_CHASSIS_ID_VALUE_LEN];
145} __packed;
146
154 uint8_t value[NET_LLDP_PORT_ID_VALUE_LEN];
155} __packed;
156
164
174
183int net_lldp_config(struct net_if *iface, const struct net_lldpdu *lldpdu);
184
194int net_lldp_config_optional(struct net_if *iface, const uint8_t *tlv,
195 size_t len);
196
200void net_lldp_init(void);
201
215typedef enum net_verdict (*net_lldp_recv_cb_t)(struct net_if *iface,
216 struct net_pkt *pkt);
217
227
236enum net_verdict net_lldp_recv(struct net_if *iface, struct net_pkt *pkt);
237
245#if defined(CONFIG_NET_LLDP)
246int net_lldp_set_lldpdu(struct net_if *iface);
247#else
248#define net_lldp_set_lldpdu(iface)
249#endif
250
256#if defined(CONFIG_NET_LLDP)
258#else
259#define net_lldp_unset_lldpdu(iface)
260#endif
261
262#ifdef __cplusplus
263}
264#endif
265
270#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:215
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:248
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
TLV Types.
Definition lldp.h:123
#define net_lldp_unset_lldpdu(iface)
Unset LLDP protocol data unit (LLDPDU) for the network interface.
Definition lldp.h:259
enum net_verdict net_lldp_recv(struct net_if *iface, struct net_pkt *pkt)
Parse LLDP packet.
@ LLDP_TLV_ORG_SPECIFIC
Org specific TLVs (optional)
Definition lldp.h:134
@ LLDP_TLV_PORT_ID
Port ID (mandatory)
Definition lldp.h:126
@ LLDP_TLV_END_LLDPDU
End Of LLDPDU (optional)
Definition lldp.h:124
@ LLDP_TLV_PORT_DESC
Port Description (optional)
Definition lldp.h:128
@ LLDP_TLV_SYSTEM_CAPABILITIES
System Capability (optional)
Definition lldp.h:131
@ LLDP_TLV_MANAGEMENT_ADDR
Management Address (optional)
Definition lldp.h:132
@ LLDP_TLV_SYSTEM_DESC
System Description (optional)
Definition lldp.h:130
@ LLDP_TLV_SYSTEM_NAME
System Name (optional)
Definition lldp.h:129
@ LLDP_TLV_CHASSIS_ID
Chassis ID (mandatory)
Definition lldp.h:125
@ LLDP_TLV_TTL
Time To Live (mandatory)
Definition lldp.h:127
net_verdict
Net Verdict.
Definition net_core.h:102
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Network Interface structure.
Definition net_if.h:692
Chassis ID TLV, see chapter 8.5.2 in IEEE 802.1AB.
Definition lldp.h:138
uint8_t value[NET_LLDP_CHASSIS_ID_VALUE_LEN]
Chassis ID value.
Definition lldp.h:144
uint8_t subtype
ID subtype.
Definition lldp.h:142
uint16_t type_length
7 bits for type, 9 bits for length
Definition lldp.h:140
Port ID TLV, see chapter 8.5.3 in IEEE 802.1AB.
Definition lldp.h:148
uint8_t subtype
ID subtype.
Definition lldp.h:152
uint16_t type_length
7 bits for type, 9 bits for length
Definition lldp.h:150
uint8_t value[NET_LLDP_PORT_ID_VALUE_LEN]
Port ID value.
Definition lldp.h:154
Time To Live TLV, see chapter 8.5.4 in IEEE 802.1AB.
Definition lldp.h:158
uint16_t type_length
7 bits for type, 9 bits for length
Definition lldp.h:160
uint16_t ttl
Time To Live (TTL) value.
Definition lldp.h:162
LLDP Data Unit (LLDPDU) shall contain the following ordered TLVs as stated in "8.2 LLDPDU format" fro...
Definition lldp.h:169
struct net_lldp_chassis_tlv chassis_id
Mandatory Chassis TLV.
Definition lldp.h:170
struct net_lldp_port_tlv port_id
Mandatory Port TLV.
Definition lldp.h:171
struct net_lldp_time_to_live_tlv ttl
Mandatory TTL TLV.
Definition lldp.h:172
Network packet.
Definition net_pkt.h:91
struct net_if * iface
Network interface.
Definition net_pkt.h:114