Skip to main content

smb_server_proto_smb2/
consts.rs

1//! SMB2/3 shared constants.
2
3/// Signing enabled but not required.
4pub const SIGNING_ENABLED: u16 = 0x0001;
5/// Signing required.
6pub const SIGNING_REQUIRED: u16 = 0x0002;
7/// DFS support capability.
8pub const CAP_DFS: u32 = 0x0000_0001;
9/// Large MTU capability.
10pub const CAP_LARGE_MTU: u32 = 0x0000_0004;
11
12/// Byte offsets and sizes of the 64-byte SMB2 packet header ([MS-SMB2] §2.2.1.2).
13pub mod hdr {
14    /// Total SMB2 packet header length.
15    pub const LEN: usize = 64;
16    /// ProtocolId (`\xFESMB`) offset.
17    pub const PROTOCOL_ID: usize = 0;
18    /// StructureSize offset (the value is always 64).
19    pub const STRUCTURE_SIZE: usize = 4;
20    /// CreditCharge offset.
21    pub const CREDIT_CHARGE: usize = 6;
22    /// Status / ChannelSequence offset.
23    pub const STATUS: usize = 8;
24    /// Command offset.
25    pub const COMMAND: usize = 12;
26    /// CreditRequest / CreditResponse offset.
27    pub const CREDIT: usize = 14;
28    /// Flags offset.
29    pub const FLAGS: usize = 16;
30    /// NextCommand offset (compound chaining).
31    pub const NEXT_COMMAND: usize = 20;
32    /// MessageId offset.
33    pub const MESSAGE_ID: usize = 24;
34    /// AsyncId offset in async mode (overlaps Reserved + TreeId).
35    pub const ASYNC_ID: usize = 32;
36    /// TreeId offset in sync mode.
37    pub const TREE_ID: usize = 36;
38    /// SessionId offset.
39    pub const SESSION_ID: usize = 40;
40    /// Signature offset.
41    pub const SIGNATURE: usize = 48;
42    /// Signature length.
43    pub const SIGNATURE_LEN: usize = 16;
44    /// Compound requests/responses are 8-byte aligned ([MS-SMB2] §3.3.4.1).
45    pub const ALIGN: usize = 8;
46}
47
48/// SMB2 header `Flags` bits ([MS-SMB2] §2.2.1.2).
49pub mod hdr_flags {
50    /// SMB2_FLAGS_SERVER_TO_REDIR — response, not request.
51    pub const SERVER_TO_REDIR: u32 = 0x0000_0001;
52    /// SMB2_FLAGS_ASYNC_COMMAND — the header carries an AsyncId.
53    pub const ASYNC_COMMAND: u32 = 0x0000_0002;
54    /// SMB2_FLAGS_RELATED_OPERATIONS — compound request shares the prior FileId.
55    pub const RELATED_OPERATIONS: u32 = 0x0000_0004;
56    /// SMB2_FLAGS_SIGNED — the PDU carries a signature.
57    pub const SIGNED: u32 = 0x0000_0008;
58    /// SMB2_FLAGS_REPLAY_OPERATION — the request is a replay ([MS-SMB2] §2.2.1.2).
59    pub const REPLAY_OPERATION: u32 = 0x2000_0000;
60}
61
62/// AEAD parameters for SMB3 transform (encrypted) messages ([MS-SMB2] §3.1.4.3).
63pub mod aead {
64    /// AES-128-GCM nonce length.
65    pub const GCM_NONCE_LEN: usize = 12;
66    /// AES-128-CCM nonce length.
67    pub const CCM_NONCE_LEN: usize = 11;
68    /// AEAD authentication tag length (lands in the transform Signature field).
69    pub const TAG_LEN: usize = 16;
70    /// Key length for the AES-128 cipher variants ([MS-SMB2] §2.2.3.1.2).
71    pub const AES128_KEY_LEN: usize = 16;
72    /// Key length for the AES-256 cipher variants ([MS-SMB2] §2.2.3.1.2).
73    pub const AES256_KEY_LEN: usize = 32;
74}
75
76/// ChannelSequence replay-window half-range: the maximum forward distance
77/// (mod 2^16) still accepted as "newer" before it is treated as a replay
78/// ([MS-SMB2] §3.3.5.2.10).
79pub const CHANNEL_SEQUENCE_WINDOW: u16 = 0x7FFF;