Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
lldp.h
Go to the documentation of this file.
1
6
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
24
25#include <zephyr/net/net_if.h>
26#include <zephyr/net/net_pkt.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
33
34#define LLDP_TLV_GET_LENGTH(type_length) (type_length & BIT_MASK(9))
35#define LLDP_TLV_GET_TYPE(type_length) ((uint8_t)(type_length >> 9))
36
37/* LLDP Definitions */
38
39/* According to the spec, End of LLDPDU TLV value is constant. */
40#define NET_LLDP_END_LLDPDU_VALUE 0x0000
41
42/*
43 * For the Chassis ID TLV Value, if subtype is a MAC address then we must
44 * use values from CONFIG_NET_LLDP_CHASSIS_ID_MAC0 through
45 * CONFIG_NET_LLDP_CHASSIS_ID_MAC5. If not, we use CONFIG_NET_LLDP_CHASSIS_ID.
46 *
47 * FIXME: implement a similar scheme for subtype 5 (network address).
48 */
49#if defined(CONFIG_NET_LLDP_CHASSIS_ID_SUBTYPE)
50#if (CONFIG_NET_LLDP_CHASSIS_ID_SUBTYPE == 4)
51#define NET_LLDP_CHASSIS_ID_VALUE \
52 { \
53 CONFIG_NET_LLDP_CHASSIS_ID_MAC0, \
54 CONFIG_NET_LLDP_CHASSIS_ID_MAC1, \
55 CONFIG_NET_LLDP_CHASSIS_ID_MAC2, \
56 CONFIG_NET_LLDP_CHASSIS_ID_MAC3, \
57 CONFIG_NET_LLDP_CHASSIS_ID_MAC4, \
58 CONFIG_NET_LLDP_CHASSIS_ID_MAC5 \
59 }
60
61#define NET_LLDP_CHASSIS_ID_VALUE_LEN (6)
62#else
63#define NET_LLDP_CHASSIS_ID_VALUE CONFIG_NET_LLDP_CHASSIS_ID
64#define NET_LLDP_CHASSIS_ID_VALUE_LEN (sizeof(CONFIG_NET_LLDP_CHASSIS_ID) - 1)
65#endif
66#else
67#define NET_LLDP_CHASSIS_ID_VALUE 0
68#define NET_LLDP_CHASSIS_ID_VALUE_LEN 0
69#endif
70
71/*
72 * For the Port ID TLV Value, if subtype is a MAC address then we must
73 * use values from CONFIG_NET_LLDP_PORT_ID_MAC0 through
74 * CONFIG_NET_LLDP_PORT_ID_MAC5. If not, we use CONFIG_NET_LLDP_PORT_ID.
75 *
76 * FIXME: implement a similar scheme for subtype 4 (network address).
77 */
78#if defined(CONFIG_NET_LLDP_PORT_ID_SUBTYPE)
79#if (CONFIG_NET_LLDP_PORT_ID_SUBTYPE == 3)
80#define NET_LLDP_PORT_ID_VALUE \
81 { \
82 CONFIG_NET_LLDP_PORT_ID_MAC0, \
83 CONFIG_NET_LLDP_PORT_ID_MAC1, \
84 CONFIG_NET_LLDP_PORT_ID_MAC2, \
85 CONFIG_NET_LLDP_PORT_ID_MAC3, \
86 CONFIG_NET_LLDP_PORT_ID_MAC4, \
87 CONFIG_NET_LLDP_PORT_ID_MAC5 \
88 }
89
90#define NET_LLDP_PORT_ID_VALUE_LEN (6)
91#else
92#define NET_LLDP_PORT_ID_VALUE CONFIG_NET_LLDP_PORT_ID
93#define NET_LLDP_PORT_ID_VALUE_LEN (sizeof(CONFIG_NET_LLDP_PORT_ID) - 1)
94#endif
95#else
96#define NET_LLDP_PORT_ID_VALUE 0
97#define NET_LLDP_PORT_ID_VALUE_LEN 0
98#endif
99
100/*
101 * TLVs Length.
102 * Note that TLVs that have a subtype must have a byte added to their length.
103 */
104#define NET_LLDP_CHASSIS_ID_TLV_LEN (NET_LLDP_CHASSIS_ID_VALUE_LEN + 1)
105#define NET_LLDP_PORT_ID_TLV_LEN (NET_LLDP_PORT_ID_VALUE_LEN + 1)
106#define NET_LLDP_TTL_TLV_LEN (2)
107
108/*
109 * Time to Live value.
110 * Calculate based on section 9.2.5.22 from LLDP spec.
111 *
112 * FIXME: when the network interface is about to be ‘disabled’ TTL shall be set
113 * to zero so LLDP Rx agents can invalidate the entry related to this node.
114 */
115#if defined(CONFIG_NET_LLDP_TX_INTERVAL) && defined(CONFIG_NET_LLDP_TX_HOLD)
116#define NET_LLDP_TTL \
117 MIN((CONFIG_NET_LLDP_TX_INTERVAL * CONFIG_NET_LLDP_TX_HOLD) + 1, 65535)
118#endif
119
120
121struct net_if;
122
124
139
147 uint8_t value[NET_LLDP_CHASSIS_ID_VALUE_LEN];
148} __packed;
149
157 uint8_t value[NET_LLDP_PORT_ID_VALUE_LEN];
158} __packed;
159
167
177
186int net_lldp_config(struct net_if *iface, const struct net_lldpdu *lldpdu);
187
197int net_lldp_config_optional(struct net_if *iface, const uint8_t *tlv,
198 size_t len);
199
203void net_lldp_init(void);
204
218typedef enum net_verdict (*net_lldp_recv_cb_t)(struct net_if *iface,
219 struct net_pkt *pkt);
220
230
238#if defined(CONFIG_NET_LLDP)
239int net_lldp_set_lldpdu(struct net_if *iface);
240#else
241#define net_lldp_set_lldpdu(iface)
242#endif
243
249#if defined(CONFIG_NET_LLDP)
251#else
252#define net_lldp_unset_lldpdu(iface)
253#endif
254
255#ifdef __cplusplus
256}
257#endif
258
262
263#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:218
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:241
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:126
#define net_lldp_unset_lldpdu(iface)
Unset LLDP protocol data unit (LLDPDU) for the network interface.
Definition lldp.h:252
@ LLDP_TLV_ORG_SPECIFIC
Org specific TLVs (optional)
Definition lldp.h:137
@ LLDP_TLV_PORT_ID
Port ID (mandatory)
Definition lldp.h:129
@ LLDP_TLV_END_LLDPDU
End Of LLDPDU (optional)
Definition lldp.h:127
@ LLDP_TLV_PORT_DESC
Port Description (optional)
Definition lldp.h:131
@ LLDP_TLV_SYSTEM_CAPABILITIES
System Capability (optional)
Definition lldp.h:134
@ LLDP_TLV_MANAGEMENT_ADDR
Management Address (optional)
Definition lldp.h:135
@ LLDP_TLV_SYSTEM_DESC
System Description (optional)
Definition lldp.h:133
@ LLDP_TLV_SYSTEM_NAME
System Name (optional)
Definition lldp.h:132
@ LLDP_TLV_CHASSIS_ID
Chassis ID (mandatory)
Definition lldp.h:128
@ LLDP_TLV_TTL
Time To Live (mandatory)
Definition lldp.h:130
net_verdict
Net Verdict.
Definition net_core.h:109
Public API for network interface.
Network packet buffer descriptor API.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Network Interface structure.
Definition net_if.h:726
Chassis ID TLV, see chapter 8.5.2 in IEEE 802.1AB.
Definition lldp.h:141
uint8_t value[NET_LLDP_CHASSIS_ID_VALUE_LEN]
Chassis ID value.
Definition lldp.h:147
uint8_t subtype
ID subtype.
Definition lldp.h:145
uint16_t type_length
7 bits for type, 9 bits for length
Definition lldp.h:143
Port ID TLV, see chapter 8.5.3 in IEEE 802.1AB.
Definition lldp.h:151
uint8_t subtype
ID subtype.
Definition lldp.h:155
uint16_t type_length
7 bits for type, 9 bits for length
Definition lldp.h:153
uint8_t value[NET_LLDP_PORT_ID_VALUE_LEN]
Port ID value.
Definition lldp.h:157
Time To Live TLV, see chapter 8.5.4 in IEEE 802.1AB.
Definition lldp.h:161
uint16_t type_length
7 bits for type, 9 bits for length
Definition lldp.h:163
uint16_t ttl
Time To Live (TTL) value.
Definition lldp.h:165
LLDP Data Unit (LLDPDU) shall contain the following ordered TLVs as stated in "8.2 LLDPDU format" fro...
Definition lldp.h:172
struct net_lldp_chassis_tlv chassis_id
Mandatory Chassis TLV.
Definition lldp.h:173
struct net_lldp_port_tlv port_id
Mandatory Port TLV.
Definition lldp.h:174
struct net_lldp_time_to_live_tlv ttl
Mandatory TTL TLV.
Definition lldp.h:175
Network packet.
Definition net_pkt.h:91
struct net_if * iface
Network interface.
Definition net_pkt.h:114