-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmqtt.fdesc
378 lines (257 loc) · 8.27 KB
/
mqtt.fdesc
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# Generic dissector for MQTT based on MQTT V3.1 Protocol Specification
# http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html
#
# Johann ANGELI (02/2014)
enum4 MQTTMessageType {
Reserved_0 0
CONNECT 1
CONNACK 2
PUBLISH 3
PUBACK 4
PUBREC 5
PUBREL 6
PUBCOMP 7
SUBSCRIBE 8
SUBACK 9
UNSUBSCRIBE 10
UNSUBACK 11
PINGREQ 12
PINGRESP 13
DISCONNECT 14
Reserved_15 15
}
enum8 MQTTConnectReturnCode {
connection_accepted 0
connection_refused_unacceptable_protocol_version 1
connection_refused_identifier_rejected 2
connection_refused_server_unavailable 3
connection_refused_bad_username_or_password 4
connection_refused_not_authorized 5
#Todo : Manage reserved values
#From 6 to 255 : reserved for future use
}
enum2 MQTTQoS {
at_most_once 0
at_least_once 1
exactly_once 2
reserved 3
}
struct MQTTFixedHeader
{
byte_order big_endian;
MQTTMessageType message_type;
bool1 dup;
MQTTQoS qos;
bool1 retain;
hide var uint32 message_length = 1;
hide var uint8 multiplier = 1;
hide var uint32 value = 0;
do
{
hide uint8 length;
set value = value + (length & 127) * multiplier;
set multiplier = multiplier * 128;
set message_length = message_length + 1;
} while ( (length & 128) !=0 );
var uint32 remaining_length = value;
set message_length = message_length + remaining_length;
}
struct MQTTConnectFlags {
bool1 username;
bool1 password;
bool1 will_retain;
MQTTQoS will_qos;
bool1 will;
bool1 clean_session;
uint1 reserved;
}
struct MQTTSubscribeQoS {
hide uint6 reserved;
MQTTQoS qos;
}
struct MQTTSubScribeTopic {
hide uint16 topic_name_length;
string(topic_name_length) topic_name;
hide uint6 reserved;
MQTTQoS requested_qos;
}
###############################################################################
# Messages Types
###############################################################################
# Reserved 0
# Reserved message for futur use
struct MQTTMessageReserved0 {
MQTTFixedHeader fixed_header;
# Variable header and payload (if any)
raw(fixed_header.remaining_length) content_of_message;
}
# CONNECT
# Message with variable header
# Message with payload
struct MQTTMessageConnect {
MQTTFixedHeader fixed_header;
# Variable header
hide uint16 protocol_name_length;
string(protocol_name_length) protocol_name;
uint8 protocol_version_number;
MQTTConnectFlags connect_flags;
uint16 keep_alive_timer;
# Payload
hide uint16 client_id_length;
string(client_id_length) client_id;
if (connect_flags.will == 1) {
hide uint16 will_topic_length;
string(will_topic_length) will_topic;
hide uint16 will_message_length;
string(will_message_length) will_message;
}
if (connect_flags.username == 1) {
#Todo : verify the way the username can be null
hide uint16 username_length;
string(username_length) username;
}
if (connect_flags.password == 1) {
#Todo : verify the way the password can be null
hide uint16 password_length;
string(password_length) password;
}
}
# CONNACK
# Message with variable header
# Message without payload
struct MQTTMessageConnack {
MQTTFixedHeader fixed_header;
# Variable header
uint8 topic_name_compression_response;
MQTTConnectReturnCode connect_return_code;
}
# PUBLISH
# Message with variable header
# Message with payload
struct MQTTMessagePublish {
MQTTFixedHeader fixed_header;
# Variable header
hide uint16 topic_length;
string(topic_length) topic;
hide var uint8 variable_header_length = topic_length + 2;
if (fixed_header.qos == 1 || fixed_header.qos == 2 ) {
uint16 message_id;
set variable_header_length = variable_header_length + 2;
}
# Payload
raw(fixed_header.remaining_length - variable_header_length) payload;
}
# PUBACK
# Message with variable header
# Message without payload
struct MQTTMessagePuback {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
}
# PUBREC
# Message with variable header
# Message without payload
struct MQTTMessagePubrec {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
}
# PUBREL
# Message with variable header
# Message without payload
struct MQTTMessagePubrel {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
}
# PUBCOMP
# Message with variable header
# Message without payload
struct MQTTMessagePubcomp {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
}
# SUBSCRIBE
# Message with variable header
# Message with payload
struct MQTTMessageSubscribe {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
# Payload
MQTTSubScribeTopic[+] topics;
}
# SUBACK
# Message with variable header
# Message with payload
struct MQTTMessageSuback {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
# Payload
MQTTSubscribeQoS[+] granted_qos;
}
# UNSUBSCRIBE
# Message with variable header
# Message without payload
struct MQTTMessageUnsubscribe {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
}
# UNSUBACK
# Message with variable header
# Message without payload
struct MQTTMessageUnsuback {
MQTTFixedHeader fixed_header;
# Variable header
uint16 message_id;
}
# PINGREQ
# Message without variable header
# Message without payload
struct MQTTMessagePingreq {
MQTTFixedHeader fixed_header;
}
# PINGRESP
# Message without variable header
# Message without payload
struct MQTTMessagePingresp {
MQTTFixedHeader fixed_header;
}
# DISCONNECT
# Message without variable header
# Message without payload
struct MQTTMessageDisconnect {
MQTTFixedHeader fixed_header;
}
# Reserved 15
# Reserved message for futur use
struct MQTTMessageReserved15 {
MQTTFixedHeader fixed_header;
# Variable header and payload (if any)
raw(fixed_header.remaining_length) content_of_message;
}
switch MQTTMessageSwitch MQTTMessageType {
case MQTTMessageType::Reserved_0 : MQTTMessageReserved0 "";
case MQTTMessageType::CONNECT : MQTTMessageConnect "";
case MQTTMessageType::CONNACK : MQTTMessageConnack "";
case MQTTMessageType::PUBLISH : MQTTMessagePublish "";
case MQTTMessageType::PUBACK : MQTTMessagePuback "";
case MQTTMessageType::PUBREC : MQTTMessagePubrec "";
case MQTTMessageType::PUBREL : MQTTMessagePubrel "";
case MQTTMessageType::PUBCOMP : MQTTMessagePubcomp "";
case MQTTMessageType::SUBSCRIBE : MQTTMessageSubscribe "";
case MQTTMessageType::SUBACK : MQTTMessageSuback "";
case MQTTMessageType::UNSUBSCRIBE : MQTTMessageUnsubscribe "";
case MQTTMessageType::UNSUBACK : MQTTMessageUnsuback "";
case MQTTMessageType::PINGREQ : MQTTMessagePingreq "";
case MQTTMessageType::PINGRESP : MQTTMessagePingresp "";
case MQTTMessageType::DISCONNECT : MQTTMessageDisconnect "";
case MQTTMessageType::Reserved_15 : MQTTMessageReserved15 "";
default :
MQTTFixedHeader fixed_header;
raw(fixed_header.remaining_length) content_of_message;
}