Vanetza
Loading...
Searching...
No Matches
g5_link_layer.hpp
1#ifndef G5_LINK_LAYER_HPP_CESAPUOW
2#define G5_LINK_LAYER_HPP_CESAPUOW
3
4#include <array>
5#include <cstdint>
6#include <vanetza/access/access_category.hpp>
7#include <vanetza/common/bit_number.hpp>
8#include <vanetza/common/byte_order.hpp>
9#include <vanetza/common/serialization.hpp>
10#include <vanetza/net/mac_address.hpp>
11
12namespace vanetza
13{
14namespace access
15{
16namespace ieee802
17{
18namespace dot11
19{
20
21/**
22 * \brief QoS Control field in IEEE 802.11 MAC header.
23 */
25{
26 vanetza::uint16be_t raw { 0 };
27
28 /**
29 * Set user priority by access category
30 * \param ac map this AccessCategory to user priority
31 */
32 void user_priority(AccessCategory ac);
33};
34
35/**
36 * \brief Frame Control field in IEEE 802.11 MAC header
37 */
39{
40 vanetza::uint16be_t raw { 0 };
41
42 using Protocol = BitNumber<std::uint16_t, 2>; /**< represents protocol version */
43 using Type = BitNumber<std::uint16_t, 2>;
44 using SubType = BitNumber<std::uint16_t, 4>;
45
46 Protocol protocol() const { return Protocol(raw.get()); }
47 Type type() const { return Type(raw.get() >> 2); }
48 SubType sub_type() const { return SubType(raw.get() >> 4); }
49 bool to_ds() const { return raw.get() & 0x0100; }
50 bool from_ds() const { return raw.get() & 0x0200; }
51 bool more_fragments() const { return raw.get() & 0x0400; }
52 bool retry() const { return raw.get() & 0x0800; }
53
54 /**
55 * Create frame control for QoS data frame without any flags
56 * \return FrameControl field for QoS data frame
57 **/
58 static FrameControl qos_data_frame();
59};
60
61/**
62 * \brief Sequence Control field in IEEE 802.11 MAC header
63 */
65{
66 vanetza::uint16be_t raw { 0 };
67
68 using SequenceNumber = BitNumber<std::uint16_t, 12>;
69 using FragmentNumber = BitNumber<std::uint16_t, 4>;
70
71 SequenceNumber sequence_number() const
72 {
73 return SequenceNumber(raw.get() >> 4);
74 }
75
76 FragmentNumber fragment_number() const
77 {
78 return FragmentNumber(raw.get());
79 }
80};
81
82/** MAC address representing the BSSID wildcard (all bits set) */
83extern const MacAddress bssid_wildcard;
84
85/**
86 * \brief MAC header of QoS data frames
87 */
89{
91 uint16be_t duration_or_id;
92 MacAddress destination;
93 MacAddress source;
94 MacAddress bssid = bssid_wildcard;
95 SequenceControl sequence_control;
96 QosControl qos_control;
97
98 /** length of serialized QoSDataHeader in bytes */
99 static constexpr std::size_t length_bytes = 26;
100};
101
102/** length of frame check sequence in bytes */
103static constexpr std::size_t fcs_length_bytes = 4;
104
105void serialize(OutputArchive&, const QosDataHeader&);
106void deserialize(InputArchive&, QosDataHeader&);
107
108} // namespace dot11
109
110/**
111 * \brief Logical Link Control header with SNAP extension
112 */
113struct LlcSnapHeader
114{
115 std::uint8_t dsap = 0xAA;
116 std::uint8_t ssap = 0xAA;
117 std::uint8_t control = 0x03;
118 std::array<std::uint8_t, 3> oui = {{ 0x00, 0x00, 0x00 }};
119 uint16be_t protocol_id;
120
121 LlcSnapHeader(uint16be_t protocol_id) : protocol_id(protocol_id) {}
122
123 static constexpr std::size_t length_bytes = 8;
124};
125
126bool operator==(const LlcSnapHeader&, const LlcSnapHeader&);
127bool operator!=(const LlcSnapHeader&, const LlcSnapHeader&);
128
129void serialize(OutputArchive&, const LlcSnapHeader&);
130void deserialize(InputArchive&, LlcSnapHeader&);
131
132} // namespace ieee802
133
134/**
135 * \brief Link layer header used by ITS-G5 stations
136 */
137struct G5LinkLayer
138{
140 ieee802::LlcSnapHeader llc_snap_header;
141
142 G5LinkLayer();
143
144 static constexpr std::size_t length_bytes =
146 ieee802::LlcSnapHeader::length_bytes;
147};
148
149void serialize(OutputArchive&, const G5LinkLayer&);
150void deserialize(InputArchive&, G5LinkLayer&);
151
152/**
153 * \brief Check whether some link layer header fields contain their expected values.
154 * For most explicitly initialized link layer header fields, their (default) value is expected in received frames.
155 *
156 * \param link_layer G5LinkLayer to check
157 * \return whether all fields are set as expected
158 */
159bool check_fixed_fields(const G5LinkLayer& link_layer);
160
161} // namespace access
162} // namespace vanetza
163
164#endif /* G5_LINK_LAYER_HPP_CESAPUOW */
Link layer header used by ITS-G5 stations.
Logical Link Control header with SNAP extension.
Frame Control field in IEEE 802.11 MAC header.
QoS Control field in IEEE 802.11 MAC header.
Sequence Control field in IEEE 802.11 MAC header.