-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.h
148 lines (135 loc) · 3.68 KB
/
messages.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef __MESSAGES_H
#define __MESSAGES_H
#include <assert.h>
#include <cinttypes>
#include <string>
enum class message_type_t : uint32_t {
/**
* @brief To register a station of interest (i.e. this process will begin monitoring and collect link metrics if that STA is seen.)
*
*/
MSG_REGISTER_STA = 0x01,
/**
* @brief Unregister a station. Stop collecting metrics for this station. Pre-collected metrics, if any, will be lost.
*
*/
MSG_UNREGISTER_STA = 0x02,
/**
* @brief Get the link metric statistics for a station.
*
*/
MSG_GET_STA_STATS = 0x04,
/**
* @brief Get the link metric statistics for this station, but with the RSSI being a weighted mean average with more recent measurement weighed more.
*
*/
MSG_GET_STA_WMI_STATS = 0x08,
/**
* @brief Check if a given STA has disassociated from a BSS.
* The STA MAC included in the message header is the station of interest.
*/
MSG_GET_DISASSOCIATED_STATIONS = 0x40,
};
enum class error_code_t : uint32_t {
/**
* @brief No error! Good to go.
*
*
*/
ERROR_OK = 0x00,
/**
* @brief The station that was request to act upon is not known to this Agent.
*
*/
ERROR_STA_NOT_KNOWN = 0x01,
/**
* @brief Client fed us a malformed message.
*
*/
ERROR_BAD_MESSAGE = 0x02,
};
enum class bandwidth_t : uint8_t {
/**
* @brief Unknown bandwidth -- default value
*
*/
BANDWIDTH_UNKNOWN = 0,
/**
* @brief 20 mHz BW
*
*/
BANDWIDTH_20MHZ = 20,
/**
* @brief 40 mHz BW
*
*/
BANDWIDTH_40MHZ = 40,
/**
* @brief 80 mHz BW
*
*/
BANDWIDTH_80MHZ = 80,
/**
* @brief 160 mHz BW
*
*/
BANDWIDTH_160MHZ = 160,
/**
* @brief 80+80 mHz BW
*
*/
BANDWIDTH_80_80 = 161,
};
/**
* @brief Convert an error_code_t to a string literal
*
* @param err_code the error_code_t of interest
* @return std::string the string representation of 'err_code'
*/
extern std::string error_code_to_string(const error_code_t &err_code);
/**
* @brief Convert a message_type_t enum to a string literal
*
* @param mt the message_type_t of interest
* @return std::string the string representation of 'mt'
*/
extern std::string message_type_to_string(const message_type_t &mt);
struct message_request_header {
message_type_t message_type;
uint8_t mac[6];
uint32_t checksum;
} __attribute__((packed));
struct message_response_header {
error_code_t error_code;
} __attribute__((packed));
struct request {
message_request_header header;
} __attribute__((packed));
struct response {
message_response_header response;
} __attribute__((packed));
struct sta_lm : public response {
int8_t rssi;
int16_t channel_number;
uint8_t bandwidth;
uint64_t timestamp;
} __attribute__((packed));
struct sta_wma_lm : public response {
int8_t rssi;
int16_t channel_number;
uint8_t bandwidth;
uint64_t timestamp;
int8_t wma_rssi;
} __attribute__((packed));
struct sta_diassoc_query : public request {};
struct sta_disassoc_response : public response {
uint8_t disassociated;
uint8_t bssid[6];
} __attribute__((packed));
static_assert(sizeof(sta_lm) == 16, "sta_lm struct should be 15 bytes (one byte for RSSI, 1 for "
"bandwidth, 2 for channel number, 8 for timestamp)");
static_assert(
sizeof(message_request_header) == 14,
"message_header should be 14 bytes (uint32_t message_type, int8_t mac[6], uint32_t checksum");
static_assert(sizeof(sta_wma_lm) == 17, "struct sta_wma_lm should be 17 bytes long");
#endif // __MESSAGES_H