-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqtt_structs.h
203 lines (190 loc) · 6.38 KB
/
mqtt_structs.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <stdint.h>
enum mqttControlPacketTypes {
CONNECT = 1,
CONNACK = 2,
PUBLISH = 3,
SUBSCRIBE = 8,
SUBACK = 9,
UNSUBSCRIBE = 10,
UNSUBACK = 11,
PINGREQ = 12,
PINGRESP = 13,
DISCONNECT = 14
};
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
} mqttFixedHeaderTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
uint8_t mqttVariableHeaderProtocolNameMSB; // byte 1
uint8_t mqttVariableHeaderProtocolNameLSB; // byte 2
uint8_t mqttVariableHeaderProtocolNameChar0; // byte 3
uint8_t mqttVariableHeaderProtocolNameChar1; // byte 4
uint8_t mqttVariableHeaderProtocolNameChar2; // byte 5
uint8_t mqttVariableHeaderProtocolNameChar3; // byte 6
uint8_t mqttVariableHeaderProtocolLevel; // byte 7
union {
uint8_t mqttVariableHeaderConnectFlags; // byte 8
struct {
unsigned mqttVariableHeaderConnectFlagsReserved : 1;
unsigned mqttVariableHeaderConnectFlagsCleanSession : 1;
unsigned mqttVariableHeaderConnectFlagsWillFlag : 1;
unsigned mqttVariableHeaderConnectFlagsWillQoS : 2;
unsigned mqttVariableHeaderConnectFlagsWillRetain : 1;
unsigned mqttVariableHeaderConnectFlagsPassword : 1;
unsigned mqttVariableHeaderConnectFlagsUsername : 1;
} mqttVariableHeaderConnectFlagsBits;
};
uint8_t mqttVariableHeaderKeepAliveMSB; // byte 9
uint8_t mqttVariableHeaderKeepAliveLSB; // byte 10
uint8_t clientIdMSB;
uint8_t clientIdLSB;
uint8_t clientIdChar0;
uint8_t clientIdChar1;
uint8_t clientIdChar2;
} mqttControlPacketConnectTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
uint8_t mqttVariableHeaderConnectackFlags; // byte 1
uint8_t mqttVariableHeaderConnectackReturncode; // byte 2
} mqttControlPacketConnectackTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
uint8_t mqttVariableHeaderTopicNameMSB; // byte 1
uint8_t mqttVariableHeaderTopicNameLSB; // byte 2
uint8_t mqttVariableHeaderTopicNameChar0; // byte 3
uint8_t mqttVariableHeaderTopicNameChar1; // byte 4
uint8_t mqttVariableHeaderTopicNameChar2; // byte 5
uint8_t mqttVariableHeaderPayloadChar0; // byte 6
uint8_t mqttVariableHeaderPayloadChar1; // byte 7
uint8_t mqttVariableHeaderPayloadChar2; // byte 8
uint8_t mqttVariableHeaderPayloadChar3; // byte 9
uint8_t mqttVariableHeaderPayloadChar4; // byte 10
uint8_t mqttVariableHeaderPayloadChar5; // byte 11
uint8_t mqttVariableHeaderPayloadChar6; // byte 12
uint8_t mqttVariableHeaderPayloadChar7; // byte 13
} mqttControlPacketPublishTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
uint8_t mqttVariableHeaderPacketIdentifierMSB; // byte 1
uint8_t mqttVariableHeaderPacketIdentifierLSB; // byte 2
uint8_t mqttVariableHeaderTopicFilterMSB; // byte 3
uint8_t mqttVariableHeaderTopicFilterLSB; // byte 4
uint8_t mqttVariableHeaderTopicFilterChar0; // byte 5
uint8_t mqttVariableHeaderTopicFilterChar1; // byte 6
uint8_t mqttVariableHeaderTopicFilterChar2; // byte 7
uint8_t mqttVariableHeaderTopicFilterQos; // byte 8
} mqttControlPacketSubscribeTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
uint8_t mqttVariableHeaderPacketIdentifierMSB; // byte 1
uint8_t mqttVariableHeaderPacketIdentifierLSB; // byte 2
union {
uint8_t mqttVariableHeaderSubackReturncode; // byte 3
struct {
unsigned success : 2;
unsigned reserved : 5;
unsigned failed : 1;
} mqttVariableHeaderSubackReturncodeBits;
};
} mqttControlPacketSubackTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
uint8_t mqttVariableHeaderPacketIdentifierMSB; // byte 1
uint8_t mqttVariableHeaderPacketIdentifierLSB; // byte 2
uint8_t mqttVariableHeaderTopicFilterMSB; // byte 3
uint8_t mqttVariableHeaderTopicFilterLSB; // byte 4
uint8_t mqttVariableHeaderTopicFilterChar0; // byte 5
uint8_t mqttVariableHeaderTopicFilterChar1; // byte 6
uint8_t mqttVariableHeaderTopicFilterChar2; // byte 7
} mqttControlPacketUnsubscribeTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
uint8_t mqttVariableHeaderPacketIdentifierMSB; // byte 1
uint8_t mqttVariableHeaderPacketIdentifierLSB; // byte 2
} mqttControlPacketUnsubackTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
} mqttControlPacketDisconnectTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
} mqttControlPacketPingreqTpl;
typedef struct {
union {
uint8_t mqttFixedHeaderByte1;
struct {
unsigned mqttControlPacketFlags : 4;
unsigned mqttControlPacketType : 4;
} mqttFixedHeaderByte1Bits;
};
uint8_t mqttFixedHeaderRemainingLength;
} mqttControlPacketPingrespTpl;