Vanetza
 
Loading...
Searching...
No Matches
g5_link_layer.cpp
1#include <vanetza/access/g5_link_layer.hpp>
2#include <vanetza/access/ethertype.hpp>
3#include <cstring>
4
5namespace vanetza
6{
7namespace access
8{
9
10static const ieee802::LlcSnapHeader default_llc_header { ethertype::GeoNetworking };
11
12G5LinkLayer::G5LinkLayer() :
13 llc_snap_header(default_llc_header)
14{
15}
16
17void serialize(OutputArchive& ar, const G5LinkLayer& g5)
18{
19 serialize(ar, g5.mac_header);
20 serialize(ar, g5.llc_snap_header);
21}
22
23void deserialize(InputArchive& ar, G5LinkLayer& g5)
24{
25 deserialize(ar, g5.mac_header);
26 deserialize(ar, g5.llc_snap_header);
27}
28
29bool check_fixed_fields(const G5LinkLayer& link_layer)
30{
31 static const auto default_frame_control = ieee802::dot11::FrameControl::qos_data_frame();
32 static const ieee802::dot11::QosControl default_qos_control;
33
34 // all frame control flags are fixed for now
35 static const std::uint16_t frame_control_fixed = 0xFFFF;
36
37 // EOSP + A-MSDU + TXOP limit fixed, TID (LSB part = UP) and Ack policy are variable
38 static const std::uint16_t qos_control_fixed = 0xFF98;
39
40 const ieee802::dot11::QosDataHeader& mac = link_layer.mac_header;
41 const bool frame_control_ok =
42 (mac.frame_control.raw.get() & frame_control_fixed) == (default_frame_control.raw.get() & frame_control_fixed);
43 const bool qos_control_ok =
44 (mac.qos_control.raw.get() & qos_control_fixed) == (default_qos_control.raw.get() & qos_control_fixed);
45 return frame_control_ok && qos_control_ok &&
46 mac.sequence_control.fragment_number() == 0 &&
47 mac.bssid == ieee802::dot11::bssid_wildcard &&
48 link_layer.llc_snap_header == default_llc_header;
49}
50
51namespace ieee802
52{
53namespace dot11
54{
55
56// Operation outside of a BSS, must be set to wildcard (all bits 1)
57const MacAddress bssid_wildcard = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
58
59void QosControl::user_priority(AccessCategory access_category)
60{
61 std::uint16_t tmp = raw.get();
62 tmp &= ~0x000F; // clear all TID bits
63 tmp |= static_cast<std::uint16_t>(access_category) & 0x07;
64 raw = static_cast<uint16be_t>(tmp);
65}
66
67FrameControl FrameControl::qos_data_frame()
68{
69 FrameControl frame_control;
70 frame_control.raw = host_cast<std::uint16_t>(0x8800);
71 return frame_control;
72}
73
74void serialize(OutputArchive& ar, const QosDataHeader& mac)
75{
76 serialize(ar, mac.frame_control.raw);
77 serialize(ar, mac.duration_or_id);
78 serialize(ar, mac.destination);
79 serialize(ar, mac.source);
80 serialize(ar, mac.bssid);
81 serialize(ar, mac.sequence_control.raw);
82 serialize(ar, mac.qos_control.raw);
83}
84
85void deserialize(InputArchive& ar, QosDataHeader& mac)
86{
87 deserialize(ar, mac.frame_control.raw);
88 deserialize(ar, mac.duration_or_id);
89 deserialize(ar, mac.destination);
90 deserialize(ar, mac.source);
91 deserialize(ar, mac.bssid);
92 deserialize(ar, mac.sequence_control.raw);
93 deserialize(ar, mac.qos_control.raw);
94}
95
96} // namespace dot11
97
98void serialize(OutputArchive& ar, const LlcSnapHeader& snap)
99{
100 serialize(ar, snap.dsap);
101 serialize(ar, snap.ssap);
102 serialize(ar, snap.control);
103 for (std::uint8_t byte : snap.oui) {
104 ar << byte;
105 }
106 serialize(ar, snap.protocol_id);
107}
108
109void deserialize(InputArchive& ar, LlcSnapHeader& snap)
110{
111 deserialize(ar, snap.dsap);
112 deserialize(ar, snap.ssap);
113 deserialize(ar, snap.control);
114 for (std::uint8_t& byte : snap.oui) {
115 ar >> byte;
116 }
117 deserialize(ar, snap.protocol_id);
118}
119
120bool operator==(const LlcSnapHeader& a, const LlcSnapHeader& b)
121{
122 return a.dsap == b.dsap && a.ssap == b.ssap && a.control == b.control &&
123 a.oui == b.oui && a.protocol_id == b.protocol_id;
124}
125
126bool operator!=(const LlcSnapHeader& a, const LlcSnapHeader& b)
127{
128 return !(a == b);
129}
130
131} // namespace ieee802
132
133} // namespace access
134} // namespace vanetza
AccessCategory
AccessCategory represents packet priority at link layer.
Frame Control field in IEEE 802.11 MAC header.