Vanetza
 
Loading...
Searching...
No Matches
cam_ssp.hpp
1#ifndef CAM_SSP_HPP_GGBE8KES
2#define CAM_SSP_HPP_GGBE8KES
3
4#include <vanetza/common/byte_buffer.hpp>
5#include <cstdint>
6#include <set>
7#include <string>
8
9namespace vanetza
10{
11namespace security
12{
13
14/**
15 * CAM permission bits
16 *
17 * These bitmasks describe CA station roles, e.g. emergency vehicles.
18 * Some CAM data containers are linked to these roles. Misuse is opposed by checking CAM SSPs.
19 *
20 * \see EN 302 637-2 V1.3.2, Table 4
21 */
22enum class CamPermission : uint16_t
23{
24 // first octet
25 CEN_DSRC_Tolling_Zone = 0x80,
26 Public_Transport = 0x40,
27 Special_Transport = 0x20,
28 Dangerous_Goods = 0x10,
29 Roadwork = 0x08,
30 Rescue = 0x04,
31 Emergency = 0x02,
32 Safety_Car = 0x01,
33
34 // second octet
35 Closed_Lanes = 0x8000,
36 Request_For_Right_Of_Way = 0x4000,
37 Request_For_Free_Crossing_At_Traffic_Light = 0x2000,
38 No_Passing = 0x1000,
39 No_Passing_For_Trucks = 0x0800,
40 Speed_Limit = 0x0400,
41 // 0x0200 and 0x0100 are reserved for future usage
42};
43
44/**
45 * Set of CAM permissions, i.e. Service Specific Permissions
46 *
47 * \see EN 302 637-2 V1.3.2, section 6.2.2.2
48 */
50{
51public:
53 CamPermissions(CamPermission);
54 CamPermissions(const std::initializer_list<CamPermission>&);
55
56 // check for permission
57 bool has(CamPermission) const;
58 bool has(const std::initializer_list<CamPermission>&) const;
59 bool has(const CamPermissions&) const;
60 bool none() const;
61
62 /**
63 * Get set of all included permissions
64 * \return permission set
65 */
66 std::set<CamPermission> permissions() const;
67
68 // permission manipulation (with chaining)
69 CamPermissions& add(CamPermission);
70 CamPermissions& remove(CamPermission);
71
72 // serialization helpers
73 ByteBuffer encode() const;
74 static CamPermissions decode(const ByteBuffer&);
75
76private:
77 using value_type = std::underlying_type<CamPermission>::type;
78 value_type m_bits;
79};
80
81/**
82 * Get string representation of CAM permission flag
83 * \param cp CAM permission flag
84 * \return string representation (empty for unknown flags)
85 */
86std::string stringify(CamPermission);
87
88} // namespace security
89} // namespace vanetza
90
91#endif /* CAM_SSP_HPP_GGBE8KES */
92
std::set< CamPermission > permissions() const
Definition: cam_ssp.cpp:48