chiark / gitweb /
treewide: correct typos and use consistent "MAC" spelling
[elogind.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 "util.h"
28 #include "lldp.h"
29 #include "list.h"
30
31 typedef struct tlv_packet tlv_packet;
32 typedef struct tlv_section tlv_section;
33
34 struct tlv_section {
35         uint16_t type;
36         uint16_t length;
37
38         uint8_t *read_pos;
39         uint8_t *data;
40
41         LIST_FIELDS(tlv_section, section);
42 };
43
44 int tlv_section_new(tlv_section **ret);
45 void tlv_section_free(tlv_section *ret);
46
47 struct tlv_packet {
48         uint16_t type;
49         uint16_t length;
50         usec_t ts;
51
52         uint8_t *container_pos;
53         uint8_t pdu[ETHER_MAX_LEN];
54
55         void *userdata;
56
57         struct ether_addr mac;
58         tlv_section *container;
59
60         LIST_HEAD(tlv_section, sections);
61 };
62
63 int tlv_packet_new(tlv_packet **ret);
64 void tlv_packet_free(tlv_packet *m);
65
66 DEFINE_TRIVIAL_CLEANUP_FUNC(tlv_packet*, tlv_packet_free);
67 #define _cleanup_tlv_packet_free_ _cleanup_(tlv_packet_freep)
68
69 int lldp_tlv_packet_open_container(tlv_packet *m, uint16_t type);
70 int lldp_tlv_packet_close_container(tlv_packet *m);
71
72 int tlv_packet_append_bytes(tlv_packet *m, const void *data, size_t data_length);
73 int tlv_packet_append_u8(tlv_packet *m, uint8_t data);
74 int tlv_packet_append_u16(tlv_packet *m, uint16_t data);
75 int tlv_packet_append_u32(tlv_packet *m, uint32_t data);
76 int tlv_packet_append_string(tlv_packet *m, char *data, uint16_t size);
77
78 int lldp_tlv_packet_enter_container(tlv_packet *m, uint16_t type);
79 int lldp_tlv_packet_exit_container(tlv_packet *m);
80
81 int tlv_packet_read_bytes(tlv_packet *m, uint8_t **data, uint16_t *data_length);
82 int tlv_packet_read_string(tlv_packet *m, char **data, uint16_t *data_length);
83 int tlv_packet_read_u8(tlv_packet *m, uint8_t *data);
84 int tlv_packet_read_u16(tlv_packet *m, uint16_t *data);
85 int tlv_packet_read_u32(tlv_packet *m, uint32_t *data);
86
87 int tlv_packet_parse_pdu(tlv_packet *t, uint16_t size);