@@ -81,6 +81,26 @@ enum packet_type {
8181
8282enum qos_level { AT_MOST_ONCE , AT_LEAST_ONCE , EXACTLY_ONCE };
8383
84+ /*
85+ * MQTT Fixed header, according to official docs it's comprised of a single
86+ * byte carrying:
87+ * - opcode (packet type)
88+ * - dup flag
89+ * - QoS
90+ * - retain flag
91+ * It's followed by the remaining_len of the packet, encoded onto 1 to 4
92+ * bytes starting at bytes 2.
93+ *
94+ * | Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
95+ * |------------|-----------------------|--------------------------|
96+ * | Byte 1 | MQTT type 3 | dup | QoS | retain |
97+ * |------------|--------------------------------------------------|
98+ * | Byte 2 | |
99+ * | . | Remaining Length |
100+ * | . | |
101+ * | Byte 5 | |
102+ * |------------|--------------------------------------------------|
103+ */
84104union mqtt_header {
85105 u8 byte ;
86106 struct {
@@ -91,6 +111,58 @@ union mqtt_header {
91111 } bits ;
92112};
93113
114+ /*
115+ * MQTT Connect packet, contains a variable header with some connect related
116+ * flags:
117+ * - clean session flag
118+ * - will flag
119+ * - will QoS (if will flag set to true)
120+ * - will topic (if will flag set to true)
121+ * - will retain flag (if will flag set to true)
122+ * - password flag
123+ * - username flag
124+ *
125+ * It's followed by all required fields according the flags set to true.
126+ *
127+ * |------------|--------------------------------------------------|
128+ * | Byte 6 | Protocol name len MSB |
129+ * | Byte 7 | Protocol name len LSB | [UINT16]
130+ * |------------|--------------------------------------------------|
131+ * | Byte 8 | |
132+ * | . | 'M' 'Q' 'T' 'T' |
133+ * | Byte 12 | |
134+ * |------------|--------------------------------------------------|
135+ * | Byte 13 | Protocol level |
136+ * |------------|--------------------------------------------------|
137+ * | | Connect flags |
138+ * | Byte 14 |--------------------------------------------------|
139+ * | | U | P | WR | WQ | WF | CS | R |
140+ * |------------|--------------------------------------------------|
141+ * | Byte 15 | Keepalive MSB | [UINT16]
142+ * | Byte 17 | Keepalive LSB |
143+ * |------------|--------------------------------------------------|<-- Payload
144+ * | Byte 18 | Client ID length MSB | [UINT16]
145+ * | Byte 19 | Client ID length LSB |
146+ * |------------|--------------------------------------------------|
147+ * | Byte 20 | |
148+ * | . | Client ID |
149+ * | Byte N | |
150+ * |------------|--------------------------------------------------|
151+ * | Byte N+1 | Username length MSB |
152+ * | Byte N+2 | Username length LSB |
153+ * |------------|--------------------------------------------------|
154+ * | Byte N+3 | |
155+ * | . | Username |
156+ * | Byte N+M | |
157+ * |------------|--------------------------------------------------|
158+ * | Byte N+M+1 | Password length MSB |
159+ * | Byte N+M+2 | Password length LSB |
160+ * |------------|--------------------------------------------------|
161+ * | Byte N+M+3 | |
162+ * | . | Password |
163+ * | Byte N+M+K | |
164+ * |------------|--------------------------------------------------|
165+ */
94166struct mqtt_connect {
95167 union {
96168 u8 byte ;
0 commit comments