]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/lldp-tlv.h
tty-ask-password: Split out password sending
[thirdparty/systemd.git] / src / libsystemd-network / lldp-tlv.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4 This file is part of systemd.
5
6 Copyright (C) 2014 Tom Gundersen
7 Copyright (C) 2014 Susant Sahani
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #pragma once
24
25 #include <net/ethernet.h>
26
27 #include "sd-lldp.h"
28
29 #include "list.h"
30 #include "lldp.h"
31 #include "util.h"
32
33 typedef struct sd_lldp_packet tlv_packet;
34 typedef struct sd_lldp_section tlv_section;
35
36 #define LLDP_OUI_LEN 3
37
38 struct sd_lldp_section {
39 uint16_t type;
40 uint16_t length;
41 uint8_t *oui;
42 uint8_t subtype;
43
44 uint8_t *read_pos;
45 uint8_t *data;
46
47 LIST_FIELDS(tlv_section, section);
48 };
49
50 #define LLDP_MAC_NEAREST_BRIDGE (uint8_t[]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e }
51 #define LLDP_MAC_NEAREST_NON_TPMR_BRIDGE (uint8_t[]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 }
52 #define LLDP_MAC_NEAREST_CUSTOMER_BRIDGE (uint8_t[]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 }
53
54 int tlv_section_new(tlv_section **ret);
55 void tlv_section_free(tlv_section *ret);
56
57 struct sd_lldp_packet {
58 unsigned n_ref;
59
60 uint16_t type;
61 uint16_t length;
62 usec_t ts;
63
64 uint8_t *container_pos;
65 uint8_t pdu[ETHER_MAX_LEN];
66
67 void *userdata;
68
69 struct ether_addr mac;
70 tlv_section *container;
71
72 LIST_HEAD(tlv_section, sections);
73 };
74
75 int tlv_packet_new(tlv_packet **ret);
76
77 int lldp_tlv_packet_open_container(tlv_packet *m, uint16_t type);
78 int lldp_tlv_packet_close_container(tlv_packet *m);
79
80 int tlv_packet_append_bytes(tlv_packet *m, const void *data, size_t data_length);
81 int tlv_packet_append_u8(tlv_packet *m, uint8_t data);
82 int tlv_packet_append_u16(tlv_packet *m, uint16_t data);
83 int tlv_packet_append_u32(tlv_packet *m, uint32_t data);
84 int tlv_packet_append_string(tlv_packet *m, char *data, uint16_t size);
85
86 int lldp_tlv_packet_enter_container(tlv_packet *m, uint16_t type);
87 int lldp_tlv_packet_enter_container_oui(tlv_packet *m, const uint8_t *oui, uint8_t subtype);
88 int lldp_tlv_packet_exit_container(tlv_packet *m);
89
90 int tlv_packet_read_bytes(tlv_packet *m, uint8_t **data, uint16_t *data_length);
91 int tlv_packet_read_string(tlv_packet *m, char **data, uint16_t *data_length);
92 int tlv_packet_read_u8(tlv_packet *m, uint8_t *data);
93 int tlv_packet_read_u16(tlv_packet *m, uint16_t *data);
94 int tlv_packet_read_u32(tlv_packet *m, uint32_t *data);
95
96 int tlv_packet_parse_pdu(tlv_packet *t, uint16_t size);