Vanetza
 
Loading...
Searching...
No Matches
indication_context.hpp
1#ifndef INDICATION_CONTEXT_HPP_UWOD2BSQ
2#define INDICATION_CONTEXT_HPP_UWOD2BSQ
3
4#include <vanetza/geonet/data_indication.hpp>
5#include <vanetza/geonet/link_layer.hpp>
6#include <vanetza/geonet/packet.hpp>
7#include <vanetza/geonet/parser.hpp>
8#include <vanetza/geonet/pdu.hpp>
9#include <vanetza/geonet/variant_pdu.hpp>
10#include <vanetza/security/secured_message.hpp>
11#include <boost/optional/optional.hpp>
12
13namespace vanetza
14{
15namespace geonet
16{
17
18/**
19 * IndicationContext is used for parsing incoming packets.
20 * For each indication (packet reception) a new context should be created.
21 */
23{
24public:
25 using UpPacketPtr = std::unique_ptr<UpPacket>;
26 using SecuredMessage = security::SecuredMessage;
28
29 // parser commands
30 virtual const BasicHeader* parse_basic() = 0;
31 virtual const CommonHeader* parse_common() = 0;
32 virtual const SecuredMessage* parse_secured() = 0;
33 virtual boost::optional<HeaderConstRefVariant> parse_extended(HeaderType) = 0;
34
35 // access to data structures related to indication
36 virtual const VariantPdu& pdu() const = 0;
37 virtual VariantPdu& pdu() = 0;
38 virtual const LinkLayer& link_layer() const = 0;
39 virtual DataIndication& service_primitive() = 0;
40
41 /**
42 * Finish usage of IndicationContext and release owned packet
43 * \return owned packet
44 */
45 virtual UpPacketPtr finish() = 0;
46
47 virtual ~IndicationContext() = default;
48};
49
50
51/**
52 * IndicationContextBasic represents the first phase of packet reception,
53 * i.e. it is the context for unsecured headers
54 */
56{
57public:
58 IndicationContextBasic(const LinkLayer& ll) : m_link_layer(ll) {}
59 const LinkLayer& link_layer() const override { return m_link_layer; }
60 DataIndication& service_primitive() override { return m_service_primitive; }
61 VariantPdu& pdu() override { return m_pdu; }
62 const VariantPdu& pdu() const override { return m_pdu; }
63
64protected:
65 LinkLayer m_link_layer;
66 DataIndication m_service_primitive;
67 VariantPdu m_pdu;
68};
69
71{
72public:
74 const BasicHeader* parse_basic() override;
75 const CommonHeader* parse_common() override;
76 const SecuredMessage* parse_secured() override;
77 boost::optional<HeaderConstRefVariant> parse_extended(HeaderType) override;
78 UpPacketPtr finish() override;
79
80private:
81 UpPacketPtr m_packet;
82 CohesivePacket& m_cohesive_packet;
83 Parser m_parser;
84};
85
87{
88public:
89 IndicationContextCast(UpPacketPtr, ChunkPacket&, const LinkLayer&);
90 const BasicHeader* parse_basic() override;
91 const CommonHeader* parse_common() override;
92 const SecuredMessage* parse_secured() override;
93 boost::optional<HeaderConstRefVariant> parse_extended(HeaderType) override;
94 UpPacketPtr finish() override;
95
96private:
97 UpPacketPtr m_packet;
98};
99
100
101/**
102 * IndicationContextSecured is used for the (optional) second phase of packet reception,
103 * i.e. handling the payload contained in a secured message's payload
104 */
106{
107public:
108 IndicationContextSecured(IndicationContextBasic& parent) : m_parent(parent) {}
109 const LinkLayer& link_layer() const override { return m_parent.link_layer(); }
110 DataIndication& service_primitive() override { return m_parent.service_primitive(); }
111 VariantPdu& pdu() override { return m_parent.pdu(); }
112 const VariantPdu& pdu() const override { return m_parent.pdu(); }
113 const BasicHeader* parse_basic() override { return nullptr; }
114 const SecuredMessage* parse_secured() override { return nullptr; }
115
116protected:
117 IndicationContextBasic& m_parent;
118};
119
121{
122public:
124 const CommonHeader* parse_common() override;
125 boost::optional<HeaderConstRefVariant> parse_extended(HeaderType) override;
126 UpPacketPtr finish() override;
127
128private:
129 CohesivePacket& m_packet;
130 Parser m_parser;
131};
132
134{
135public:
137 const CommonHeader* parse_common() override;
138 boost::optional<HeaderConstRefVariant> parse_extended(HeaderType) override;
139 UpPacketPtr finish() override;
140
141private:
142 UpPacketPtr m_packet;
143};
144
145} // namespace geonet
146} // namespace vanetza
147
148#endif /* INDICATION_CONTEXT_HPP_UWOD2BSQ */
149
ChunckPacket is a packet consisting of several memory chunks.
virtual UpPacketPtr finish()=0
BasicHeader specified in ETSI EN 302 636-4-1 v1.2.1, section 8.6.