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
//! MQTT control packet support.
//!
//! This module provides packet-layer construction and decoding for cleartext
//! MQTT 3.1.1 and 5.0 control packets on TCP port [`MQTT_PORT`]. The [`Mqtt`]
//! layer follows the same builder and decode model as the rest of `crafter`:
//! fields left unset are filled during `compile()`, while fields set explicitly
//! are preserved so malformed packets can still be built intentionally.
//!
//! Decode determines a CONNECT packet's version from its protocol level. Other
//! MQTT control packets do not carry a version marker, so the registry path uses
//! MQTT 3.1.1 as the default for non-CONNECT packets. Use
//! [`Mqtt::decode_payload_with_default_version`] to decode standalone payloads
//! with a different default, for example MQTT 5.0 property-bearing CONNACK or
//! SUBACK packets.
//!
//! MQTT-over-TLS on [`MQTT_TLS_PORT`] is treated as TLS-wrapped traffic rather
//! than cleartext MQTT, so TCP payloads on that port are preserved as raw bytes.
//!
//! MQTT codepoints are copied from `.agents/docs/mqtt-codepoints.md`, which is
//! the source of truth derived from `.agents/docs/mqtt-manifest.md`.
//!
//! ```rust
//! use crafter::prelude::*;
//! use std::net::Ipv4Addr;
//!
//! # fn main() -> crafter::Result<()> {
//! let packet = Ipv4::new()
//! .src(Ipv4Addr::new(192, 0, 2, 10))
//! .dst(Ipv4Addr::new(198, 51, 100, 20))
//! / Tcp::new()
//! .sport(49_194)
//! .dport(MQTT_PORT)
//! .seq(0x0102_0304)
//! .ack(0x0506_0708)
//! .ack_segment()
//! / Mqtt::connect()
//! .client_id("crafter-client")
//! .keep_alive(30)
//! .clean_session(true);
//!
//! let compiled = packet.compile()?;
//! let decoded = Packet::decode_from_l3(NetworkLayer::Ipv4, compiled.as_bytes())?;
//! let mqtt = decoded.layer::<Mqtt>().expect("MQTT layer");
//! assert_eq!(mqtt.packet_type(), MqttControlPacketType::Connect);
//! assert_eq!(mqtt.client_id_value(), Some("crafter-client"));
//! # Ok(())
//! # }
//! ```
pub
pub use *;
pub use MqttControlPacketType;
pub use ;
pub use ;