Skip to content

Commit c2dbbf7

Browse files
finikorgnashif
authored andcommitted
samples: net: lldp: Set optional TLV system_name
Add optional TLV to LLDP DU. Signed-off-by: Andrei Emeltchenko <[email protected]>
1 parent 480f93f commit c2dbbf7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

samples/net/lldp/src/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ LOG_MODULE_REGISTER(net_lldp_sample, LOG_LEVEL_DBG);
1717
#include <net/net_if.h>
1818
#include <net/ethernet.h>
1919

20+
static struct lldp_system_name_tlv {
21+
u16_t type_length;
22+
u8_t name[4];
23+
} __packed tlv = {
24+
.name = { 't', 'e', 's', 't' },
25+
};
26+
27+
static void set_optional_tlv(struct net_if *iface)
28+
{
29+
NET_DBG("");
30+
31+
tlv.type_length = htons((LLDP_TLV_SYSTEM_NAME << 9) |
32+
((sizeof(tlv) - sizeof(u16_t)) & 0x01ff));
33+
34+
net_lldp_config_optional(iface, (u8_t *)&tlv, sizeof(tlv));
35+
}
36+
2037
/* User data for the interface callback */
2138
struct ud {
2239
struct net_if *first;
@@ -178,6 +195,7 @@ static int init_app(void)
178195
LOG_ERR("Cannot setup VLAN");
179196
}
180197

198+
set_optional_tlv(ud.first);
181199
net_lldp_register_callback(ud.first, parse_lldp);
182200

183201
return 0;

0 commit comments

Comments
 (0)