1 /* SPDX-License-Identifier: LGPL-2.1 */
2 #ifndef _COMMON_SMB2PDU_H
3 #define _COMMON_SMB2PDU_H
6 * Note that, due to trying to use names similar to the protocol specifications,
7 * there are many mixed case field names in the structures below. Although
8 * this does not match typical Linux kernel style, it is necessary to be
9 * able to match against the protocol specfication.
12 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
13 * (ie no useful data other than the SMB error code itself) and are marked such.
14 * Knowing this helps avoid response buffer allocations and copy in some cases.
17 /* List of commands in host endian */
18 #define SMB2_NEGOTIATE_HE 0x0000
19 #define SMB2_SESSION_SETUP_HE 0x0001
20 #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
21 #define SMB2_TREE_CONNECT_HE 0x0003
22 #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
23 #define SMB2_CREATE_HE 0x0005
24 #define SMB2_CLOSE_HE 0x0006
25 #define SMB2_FLUSH_HE 0x0007 /* trivial resp */
26 #define SMB2_READ_HE 0x0008
27 #define SMB2_WRITE_HE 0x0009
28 #define SMB2_LOCK_HE 0x000A
29 #define SMB2_IOCTL_HE 0x000B
30 #define SMB2_CANCEL_HE 0x000C
31 #define SMB2_ECHO_HE 0x000D
32 #define SMB2_QUERY_DIRECTORY_HE 0x000E
33 #define SMB2_CHANGE_NOTIFY_HE 0x000F
34 #define SMB2_QUERY_INFO_HE 0x0010
35 #define SMB2_SET_INFO_HE 0x0011
36 #define SMB2_OPLOCK_BREAK_HE 0x0012
38 /* The same list in little endian */
39 #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
40 #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
41 #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
42 #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
43 #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
44 #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
45 #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
46 #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
47 #define SMB2_READ cpu_to_le16(SMB2_READ_HE)
48 #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
49 #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
50 #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
51 #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
52 #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
53 #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
54 #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
55 #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
56 #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
57 #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
59 #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
61 #define NUMBER_OF_SMB2_COMMANDS 0x0013
64 * SMB2 Header Definition
66 * "MBZ" : Must be Zero
67 * "BB" : BugBug, Something to check/review/analyze later
68 * "PDU" : "Protocol Data Unit" (ie a network "frame")
72 #define __SMB2_HEADER_STRUCTURE_SIZE 64
73 #define SMB2_HEADER_STRUCTURE_SIZE \
74 cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
76 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
77 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
78 #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
81 * SMB2 flag definitions
83 #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
84 #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
85 #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
86 #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
87 #define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */
88 #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
89 #define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */
91 /* See MS-SMB2 section 2.2.1 */
93 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
94 __le16 StructureSize; /* 64 */
95 __le16 CreditCharge; /* MBZ */
96 __le32 Status; /* Error from server */
98 __le16 CreditRequest; /* CreditResponse */
115 __le16 StructureSize2; /* size of wct area (varies, request specific) */
118 #define SMB2_ERROR_STRUCTURE_SIZE2 9
119 #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
121 struct smb2_err_rsp {
123 __le16 StructureSize;
124 __u8 ErrorContextCount;
126 __le32 ByteCount; /* even if zero, at least one byte follows */
127 __u8 ErrorData[1]; /* variable length */
130 #define SMB3_AES_CCM_NONCE 11
131 #define SMB3_AES_GCM_NONCE 12
133 /* Transform flags (for 3.0 dialect this flag indicates CCM */
134 #define TRANSFORM_FLAG_ENCRYPTED 0x0001
135 struct smb2_transform_hdr {
136 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
139 __le32 OriginalMessageSize;
141 __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
146 /* See MS-SMB2 2.2.42 */
147 struct smb2_compression_transform_hdr_unchained {
148 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
149 __le32 OriginalCompressedSegmentSize;
150 __le16 CompressionAlgorithm;
152 __le16 Length; /* if chained it is length, else offset */
155 /* See MS-SMB2 2.2.42.1 */
156 #define SMB2_COMPRESSION_FLAG_NONE 0x0000
157 #define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
159 struct compression_payload_header {
160 __le16 CompressionAlgorithm;
162 __le32 Length; /* length of compressed playload including field below if present */
163 /* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */
166 /* See MS-SMB2 2.2.42.2 */
167 struct smb2_compression_transform_hdr_chained {
168 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
169 __le32 OriginalCompressedSegmentSize;
170 /* struct compression_payload_header[] */
173 /* See MS-SMB2 2.2.42.2.2 */
174 struct compression_pattern_payload_v1 {
181 /* See MS-SMB2 section 2.2.9.2 */
183 #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
184 #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
186 struct tree_connect_contexts {
193 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
194 struct smb3_blob_data {
199 /* Valid values for Attr */
200 #define SE_GROUP_MANDATORY 0x00000001
201 #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
202 #define SE_GROUP_ENABLED 0x00000004
203 #define SE_GROUP_OWNER 0x00000008
204 #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
205 #define SE_GROUP_INTEGRITY 0x00000020
206 #define SE_GROUP_INTEGRITY_ENABLED 0x00000040
207 #define SE_GROUP_RESOURCE 0x20000000
208 #define SE_GROUP_LOGON_ID 0xC0000000
210 /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
212 struct sid_array_data {
214 /* SidAttrList - array of sid_attr_data structs */
217 struct luid_attr_data {
222 * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
223 * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
226 struct privilege_array_data {
227 __le16 PrivilegeCount;
228 /* array of privilege_data structs */
231 struct remoted_identity_tcon_context {
232 __le16 TicketType; /* must be 0x0001 */
233 __le16 TicketSize; /* total size of this struct */
234 __le16 User; /* offset to SID_ATTR_DATA struct with user info */
235 __le16 UserName; /* offset to null terminated Unicode username string */
236 __le16 Domain; /* offset to null terminated Unicode domain name */
237 __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
238 __le16 RestrictedGroups; /* similar to above */
239 __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
240 __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
241 __le16 Owner; /* offset to BLOB_DATA struct */
242 __le16 DefaultDacl; /* offset to BLOB_DATA struct */
243 __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
244 __le16 UserClaims; /* offset to BLOB_DATA struct */
245 __le16 DeviceClaims; /* offset to BLOB_DATA struct */
246 __u8 TicketInfo[]; /* variable length buf - remoted identity data */
249 struct smb2_tree_connect_req_extension {
250 __le32 TreeConnectContextOffset;
251 __le16 TreeConnectContextCount;
253 __u8 PathName[]; /* variable sized array */
254 /* followed by array of TreeConnectContexts */
257 /* Flags/Reserved for SMB3.1.1 */
258 #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
259 #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
260 #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
262 struct smb2_tree_connect_req {
264 __le16 StructureSize; /* Must be 9 */
265 __le16 Flags; /* Flags in SMB3.1.1 */
268 __u8 Buffer[1]; /* variable length */
271 /* Possible ShareType values */
272 #define SMB2_SHARE_TYPE_DISK 0x01
273 #define SMB2_SHARE_TYPE_PIPE 0x02
274 #define SMB2_SHARE_TYPE_PRINT 0x03
277 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
278 * must be set (any of the remaining, SHI1005, flags may be set individually
281 #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
282 #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
283 #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
284 #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
285 #define SHI1005_FLAGS_DFS 0x00000001
286 #define SHI1005_FLAGS_DFS_ROOT 0x00000002
287 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
288 #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
289 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
290 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
291 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
292 #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
293 #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
294 #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
295 #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
296 #define SMB2_SHAREFLAG_COMPRESS_DATA 0x00100000 /* 3.1.1 */
297 #define SHI1005_FLAGS_ALL 0x0014FF33
299 /* Possible share capabilities */
300 #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
301 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
302 #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
303 #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
304 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
305 #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
307 struct smb2_tree_connect_rsp {
309 __le16 StructureSize; /* Must be 16 */
310 __u8 ShareType; /* see below */
312 __le32 ShareFlags; /* see below */
313 __le32 Capabilities; /* see below */
314 __le32 MaximalAccess;
317 struct smb2_tree_disconnect_req {
319 __le16 StructureSize; /* Must be 4 */
323 struct smb2_tree_disconnect_rsp {
325 __le16 StructureSize; /* Must be 4 */
331 * SMB2_NEGOTIATE_PROTOCOL See MS-SMB2 section 2.2.3
333 /* SecurityMode flags */
334 #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
335 #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
336 #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
337 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
338 #define SMB2_SEC_MODE_FLAGS_ALL 0x0003
340 /* Capabilities flags */
341 #define SMB2_GLOBAL_CAP_DFS 0x00000001
342 #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
343 #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
344 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
345 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
346 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
347 #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
349 #define SMB2_NT_FIND 0x00100000
350 #define SMB2_LARGE_FILES 0x00200000
352 #define SMB2_CLIENT_GUID_SIZE 16
353 #define SMB2_CREATE_GUID_SIZE 16
356 #define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */
357 #define SMB20_PROT_ID 0x0202
358 #define SMB21_PROT_ID 0x0210
359 #define SMB2X_PROT_ID 0x02FF
360 #define SMB30_PROT_ID 0x0300
361 #define SMB302_PROT_ID 0x0302
362 #define SMB311_PROT_ID 0x0311
363 #define BAD_PROT_ID 0xFFFF
365 #define SMB311_SALT_SIZE 32
366 /* Hash Algorithm Types */
367 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
368 #define SMB2_PREAUTH_HASH_SIZE 64
370 /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
371 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
372 #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
373 #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
374 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
375 #define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
376 #define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
377 #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
378 #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
380 struct smb2_neg_context {
384 /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
388 * SaltLength that the server send can be zero, so the only three required
389 * fields (all __le16) end up six bytes total, so the minimum context data len
390 * in the response is six bytes which accounts for
392 * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
394 #define MIN_PREAUTH_CTXT_DATA_LEN 6
396 struct smb2_preauth_neg_context {
397 __le16 ContextType; /* 1 */
400 __le16 HashAlgorithmCount; /* 1 */
402 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
403 __u8 Salt[SMB311_SALT_SIZE];
406 /* Encryption Algorithms Ciphers */
407 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
408 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
409 #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
410 #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
412 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
413 #define MIN_ENCRYPT_CTXT_DATA_LEN 4
414 struct smb2_encryption_neg_context {
415 __le16 ContextType; /* 2 */
418 /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
419 __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
423 /* See MS-SMB2 2.2.3.1.3 */
424 #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
425 #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
426 #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
427 #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
428 /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
429 #define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */
431 /* Compression Flags */
432 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000)
433 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)
435 struct smb2_compression_capabilities_context {
436 __le16 ContextType; /* 3 */
439 __le16 CompressionAlgorithmCount;
442 __le16 CompressionAlgorithms[3];
443 __u16 Pad; /* Some servers require pad to DataLen multiple of 8 */
444 /* Check if pad needed */
448 * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
449 * Its struct simply contains NetName, an array of Unicode characters
451 struct smb2_netname_neg_context {
452 __le16 ContextType; /* 5 */
455 __le16 NetName[]; /* hostname of target converted to UCS-2 */
459 * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
464 #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY 0x00000001
466 struct smb2_transport_capabilities_context {
467 __le16 ContextType; /* 6 */
475 * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
479 /* RDMA Transform IDs */
480 #define SMB2_RDMA_TRANSFORM_NONE 0x0000
481 #define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
482 #define SMB2_RDMA_TRANSFORM_SIGNING 0x0002
484 struct smb2_rdma_transform_capabilities_context {
485 __le16 ContextType; /* 7 */
488 __le16 TransformCount;
491 __le16 RDMATransformIds[];
495 * For signing capabilities context see MS-SMB2 2.2.3.1.7
499 /* Signing algorithms */
500 #define SIGNING_ALG_HMAC_SHA256 0
501 #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
502 #define SIGNING_ALG_AES_CMAC 1
503 #define SIGNING_ALG_AES_CMAC_LE cpu_to_le16(1)
504 #define SIGNING_ALG_AES_GMAC 2
505 #define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2)
507 struct smb2_signing_capabilities {
508 __le16 ContextType; /* 8 */
511 __le16 SigningAlgorithmCount;
512 __le16 SigningAlgorithms[];
513 /* Followed by padding to 8 byte boundary (required by some servers) */
516 #define POSIX_CTXT_DATA_LEN 16
517 struct smb2_posix_neg_context {
518 __le16 ContextType; /* 0x100 */
521 __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
524 struct smb2_negotiate_req {
526 __le16 StructureSize; /* Must be 36 */
529 __le16 Reserved; /* MBZ */
531 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
532 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
533 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
534 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
539 struct smb2_negotiate_rsp {
541 __le16 StructureSize; /* Must be 65 */
543 __le16 DialectRevision;
544 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
547 __le32 MaxTransactSize;
550 __le64 SystemTime; /* MBZ */
551 __le64 ServerStartTime;
552 __le16 SecurityBufferOffset;
553 __le16 SecurityBufferLength;
554 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
555 __u8 Buffer[1]; /* variable length GSS security buffer */
560 * SMB2_SESSION_SETUP See MS-SMB2 section 2.2.5
563 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
564 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
566 struct smb2_sess_setup_req {
568 __le16 StructureSize; /* Must be 25 */
573 __le16 SecurityBufferOffset;
574 __le16 SecurityBufferLength;
575 __le64 PreviousSessionId;
576 __u8 Buffer[1]; /* variable length GSS security buffer */
579 /* Currently defined SessionFlags */
580 #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
581 #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001)
582 #define SMB2_SESSION_FLAG_IS_NULL 0x0002
583 #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002)
584 #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
585 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
587 struct smb2_sess_setup_rsp {
589 __le16 StructureSize; /* Must be 9 */
591 __le16 SecurityBufferOffset;
592 __le16 SecurityBufferLength;
593 __u8 Buffer[1]; /* variable length GSS security buffer */
598 * SMB2_LOGOFF See MS-SMB2 section 2.2.7
600 struct smb2_logoff_req {
602 __le16 StructureSize; /* Must be 4 */
606 struct smb2_logoff_rsp {
608 __le16 StructureSize; /* Must be 4 */
614 * SMB2_CLOSE See MS-SMB2 section 2.2.15
616 /* Currently defined values for close flags */
617 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
618 struct smb2_close_req {
620 __le16 StructureSize; /* Must be 24 */
623 __u64 PersistentFileId; /* opaque endianness */
624 __u64 VolatileFileId; /* opaque endianness */
628 * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
630 #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
632 struct smb2_close_rsp {
634 __le16 StructureSize; /* 60 */
638 __le64 LastAccessTime;
639 __le64 LastWriteTime;
641 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
648 * SMB2_READ See MS-SMB2 section 2.2.19
650 /* For read request Flags field below, following flag is defined for SMB3.02 */
651 #define SMB2_READFLAG_READ_UNBUFFERED 0x01
652 #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
654 /* Channel field for read and write: exactly one of following flags can be set*/
655 #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
656 #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001)
657 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
658 #define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003)
660 /* SMB2 read request without RFC1001 length at the beginning */
661 struct smb2_read_req {
663 __le16 StructureSize; /* Must be 49 */
664 __u8 Padding; /* offset from start of SMB2 header to place read */
665 __u8 Flags; /* MBZ unless SMB3.02 or later */
668 __u64 PersistentFileId;
669 __u64 VolatileFileId;
671 __le32 Channel; /* MBZ except for SMB3 or later */
672 __le32 RemainingBytes;
673 __le16 ReadChannelInfoOffset;
674 __le16 ReadChannelInfoLength;
679 #define SMB2_READFLAG_RESPONSE_NONE cpu_to_le32(0x00000000)
680 #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM cpu_to_le32(0x00000001)
682 struct smb2_read_rsp {
684 __le16 StructureSize; /* Must be 17 */
688 __le32 DataRemaining;
695 * SMB2_WRITE See MS-SMB2 section 2.2.21
697 /* For write request Flags field below the following flags are defined: */
698 #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
699 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
701 struct smb2_write_req {
703 __le16 StructureSize; /* Must be 49 */
704 __le16 DataOffset; /* offset from start of SMB2 header to write data */
707 __u64 PersistentFileId; /* opaque endianness */
708 __u64 VolatileFileId; /* opaque endianness */
709 __le32 Channel; /* MBZ unless SMB3.02 or later */
710 __le32 RemainingBytes;
711 __le16 WriteChannelInfoOffset;
712 __le16 WriteChannelInfoLength;
717 struct smb2_write_rsp {
719 __le16 StructureSize; /* Must be 17 */
723 __le32 DataRemaining;
730 * SMB2_FLUSH See MS-SMB2 section 2.2.17
732 struct smb2_flush_req {
734 __le16 StructureSize; /* Must be 24 */
737 __u64 PersistentFileId;
738 __u64 VolatileFileId;
741 struct smb2_flush_rsp {
743 __le16 StructureSize;
749 * SMB2_NOTIFY See MS-SMB2 section 2.2.35
752 #define SMB2_WATCH_TREE 0x0001
754 /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
755 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
756 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
757 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
758 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
759 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
760 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
761 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
762 #define FILE_NOTIFY_CHANGE_EA 0x00000080
763 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
764 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
765 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
766 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
768 /* SMB2 Notify Action Flags */
769 #define FILE_ACTION_ADDED 0x00000001
770 #define FILE_ACTION_REMOVED 0x00000002
771 #define FILE_ACTION_MODIFIED 0x00000003
772 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
773 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
774 #define FILE_ACTION_ADDED_STREAM 0x00000006
775 #define FILE_ACTION_REMOVED_STREAM 0x00000007
776 #define FILE_ACTION_MODIFIED_STREAM 0x00000008
777 #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
779 struct smb2_change_notify_req {
781 __le16 StructureSize;
783 __le32 OutputBufferLength;
784 __u64 PersistentFileId; /* opaque endianness */
785 __u64 VolatileFileId; /* opaque endianness */
786 __le32 CompletionFilter;
790 struct smb2_change_notify_rsp {
792 __le16 StructureSize; /* Must be 9 */
793 __le16 OutputBufferOffset;
794 __le32 OutputBufferLength;
795 __u8 Buffer[1]; /* array of file notify structs */
800 * SMB2_CREATE See MS-SMB2 section 2.2.13
803 #define SMB2_OPLOCK_LEVEL_NONE 0x00
804 #define SMB2_OPLOCK_LEVEL_II 0x01
805 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
806 #define SMB2_OPLOCK_LEVEL_BATCH 0x09
807 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
808 /* Non-spec internal type */
809 #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
811 /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
812 #define IL_ANONYMOUS cpu_to_le32(0x00000000)
813 #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
814 #define IL_IMPERSONATION cpu_to_le32(0x00000002)
815 #define IL_DELEGATE cpu_to_le32(0x00000003)
817 /* File Attrubutes */
818 #define FILE_ATTRIBUTE_READONLY 0x00000001
819 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
820 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
821 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
822 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
823 #define FILE_ATTRIBUTE_NORMAL 0x00000080
824 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
825 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
826 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
827 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
828 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
829 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
830 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
831 #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
832 #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
833 #define FILE_ATTRIBUTE__MASK 0x00007FB7
835 #define FILE_ATTRIBUTE_READONLY_LE cpu_to_le32(0x00000001)
836 #define FILE_ATTRIBUTE_HIDDEN_LE cpu_to_le32(0x00000002)
837 #define FILE_ATTRIBUTE_SYSTEM_LE cpu_to_le32(0x00000004)
838 #define FILE_ATTRIBUTE_DIRECTORY_LE cpu_to_le32(0x00000010)
839 #define FILE_ATTRIBUTE_ARCHIVE_LE cpu_to_le32(0x00000020)
840 #define FILE_ATTRIBUTE_NORMAL_LE cpu_to_le32(0x00000080)
841 #define FILE_ATTRIBUTE_TEMPORARY_LE cpu_to_le32(0x00000100)
842 #define FILE_ATTRIBUTE_SPARSE_FILE_LE cpu_to_le32(0x00000200)
843 #define FILE_ATTRIBUTE_REPARSE_POINT_LE cpu_to_le32(0x00000400)
844 #define FILE_ATTRIBUTE_COMPRESSED_LE cpu_to_le32(0x00000800)
845 #define FILE_ATTRIBUTE_OFFLINE_LE cpu_to_le32(0x00001000)
846 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE cpu_to_le32(0x00002000)
847 #define FILE_ATTRIBUTE_ENCRYPTED_LE cpu_to_le32(0x00004000)
848 #define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE cpu_to_le32(0x00008000)
849 #define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000)
850 #define FILE_ATTRIBUTE_MASK_LE cpu_to_le32(0x00007FB7)
852 /* Desired Access Flags */
853 #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
854 #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001)
855 #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
856 #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
857 #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004)
858 #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
859 #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
860 #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
861 #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040)
862 #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
863 #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
864 #define FILE_DELETE_LE cpu_to_le32(0x00010000)
865 #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
866 #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
867 #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
868 #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
869 #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
870 #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
871 #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
872 #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
873 #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
874 #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
875 #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF)
878 #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \
880 FILE_GENERIC_READ_LE)
881 #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \
882 FILE_APPEND_DATA_LE | \
884 FILE_WRITE_ATTRIBUTES_LE | \
885 FILE_GENERIC_WRITE_LE)
887 /* ShareAccess Flags */
888 #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
889 #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
890 #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
891 #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
893 /* CreateDisposition Flags */
894 #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
895 #define FILE_OPEN_LE cpu_to_le32(0x00000001)
896 #define FILE_CREATE_LE cpu_to_le32(0x00000002)
897 #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
898 #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
899 #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
900 #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
902 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \
903 | FILE_READ_ATTRIBUTES)
904 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
905 | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
906 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
908 /* CreateOptions Flags */
909 #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
910 /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
911 #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
912 #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
913 #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
914 #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
915 #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
916 #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
917 #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
918 #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
919 #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
920 #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
921 #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
922 #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
923 #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
924 #define CREATE_OPTIONS_MASK_LE cpu_to_le32(0x00FFFFFF)
926 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
927 | FILE_READ_ATTRIBUTES_LE)
928 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
929 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
930 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
932 /* Create Context Values */
933 #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
934 #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
935 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
936 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
937 #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
938 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
939 #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
940 #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
941 #define SMB2_CREATE_REQUEST_LEASE "RqLs"
942 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
943 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
944 #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
946 /* Flag (SMB3 open response) values */
947 #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
949 struct create_context {
959 struct smb2_create_req {
961 __le16 StructureSize; /* Must be 57 */
963 __u8 RequestedOplockLevel;
964 __le32 ImpersonationLevel;
965 __le64 SmbCreateFlags;
967 __le32 DesiredAccess;
968 __le32 FileAttributes;
970 __le32 CreateDisposition;
971 __le32 CreateOptions;
974 __le32 CreateContextsOffset;
975 __le32 CreateContextsLength;
979 struct smb2_create_rsp {
981 __le16 StructureSize; /* Must be 89 */
983 __u8 Flags; /* 0x01 if reparse point */
986 __le64 LastAccessTime;
987 __le64 LastWriteTime;
989 __le64 AllocationSize;
991 __le32 FileAttributes;
993 __u64 PersistentFileId;
994 __u64 VolatileFileId;
995 __le32 CreateContextsOffset;
996 __le32 CreateContextsLength;
1000 #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
1001 #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
1002 #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
1003 #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
1005 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
1007 #define SMB2_LEASE_KEY_SIZE 16
1009 struct lease_context {
1010 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1013 __le64 LeaseDuration;
1016 struct lease_context_v2 {
1017 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1020 __le64 LeaseDuration;
1021 __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
1026 struct create_lease {
1027 struct create_context ccontext;
1029 struct lease_context lcontext;
1032 struct create_lease_v2 {
1033 struct create_context ccontext;
1035 struct lease_context_v2 lcontext;
1039 /* Possible InfoType values */
1040 #define SMB2_O_INFO_FILE 0x01
1041 #define SMB2_O_INFO_FILESYSTEM 0x02
1042 #define SMB2_O_INFO_SECURITY 0x03
1043 #define SMB2_O_INFO_QUOTA 0x04
1045 /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */
1047 /* Security info type additionalinfo flags. */
1048 #define OWNER_SECINFO 0x00000001
1049 #define GROUP_SECINFO 0x00000002
1050 #define DACL_SECINFO 0x00000004
1051 #define SACL_SECINFO 0x00000008
1052 #define LABEL_SECINFO 0x00000010
1053 #define ATTRIBUTE_SECINFO 0x00000020
1054 #define SCOPE_SECINFO 0x00000040
1055 #define BACKUP_SECINFO 0x00010000
1056 #define UNPROTECTED_SACL_SECINFO 0x10000000
1057 #define UNPROTECTED_DACL_SECINFO 0x20000000
1058 #define PROTECTED_SACL_SECINFO 0x40000000
1059 #define PROTECTED_DACL_SECINFO 0x80000000
1061 /* Flags used for FileFullEAinfo */
1062 #define SL_RESTART_SCAN 0x00000001
1063 #define SL_RETURN_SINGLE_ENTRY 0x00000002
1064 #define SL_INDEX_SPECIFIED 0x00000004
1066 struct smb2_query_info_req {
1067 struct smb2_hdr hdr;
1068 __le16 StructureSize; /* Must be 41 */
1071 __le32 OutputBufferLength;
1072 __le16 InputBufferOffset;
1074 __le32 InputBufferLength;
1075 __le32 AdditionalInformation;
1077 __u64 PersistentFileId;
1078 __u64 VolatileFileId;
1082 struct smb2_query_info_rsp {
1083 struct smb2_hdr hdr;
1084 __le16 StructureSize; /* Must be 9 */
1085 __le16 OutputBufferOffset;
1086 __le32 OutputBufferLength;
1090 #endif /* _COMMON_SMB2PDU_H */