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 SMB3_AES_CCM_NONCE 11
119 #define SMB3_AES_GCM_NONCE 12
121 /* Transform flags (for 3.0 dialect this flag indicates CCM */
122 #define TRANSFORM_FLAG_ENCRYPTED 0x0001
123 struct smb2_transform_hdr {
124 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
127 __le32 OriginalMessageSize;
129 __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
134 /* See MS-SMB2 2.2.42 */
135 struct smb2_compression_transform_hdr_unchained {
136 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
137 __le32 OriginalCompressedSegmentSize;
138 __le16 CompressionAlgorithm;
140 __le16 Length; /* if chained it is length, else offset */
143 /* See MS-SMB2 2.2.42.1 */
144 #define SMB2_COMPRESSION_FLAG_NONE 0x0000
145 #define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
147 struct compression_payload_header {
148 __le16 CompressionAlgorithm;
150 __le32 Length; /* length of compressed playload including field below if present */
151 /* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */
154 /* See MS-SMB2 2.2.42.2 */
155 struct smb2_compression_transform_hdr_chained {
156 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
157 __le32 OriginalCompressedSegmentSize;
158 /* struct compression_payload_header[] */
161 /* See MS-SMB2 2.2.42.2.2 */
162 struct compression_pattern_payload_v1 {
169 /* See MS-SMB2 section 2.2.9.2 */
171 #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
172 #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
174 struct tree_connect_contexts {
181 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
182 struct smb3_blob_data {
187 /* Valid values for Attr */
188 #define SE_GROUP_MANDATORY 0x00000001
189 #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
190 #define SE_GROUP_ENABLED 0x00000004
191 #define SE_GROUP_OWNER 0x00000008
192 #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
193 #define SE_GROUP_INTEGRITY 0x00000020
194 #define SE_GROUP_INTEGRITY_ENABLED 0x00000040
195 #define SE_GROUP_RESOURCE 0x20000000
196 #define SE_GROUP_LOGON_ID 0xC0000000
198 /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
200 struct sid_array_data {
202 /* SidAttrList - array of sid_attr_data structs */
205 struct luid_attr_data {
210 * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
211 * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
214 struct privilege_array_data {
215 __le16 PrivilegeCount;
216 /* array of privilege_data structs */
219 struct remoted_identity_tcon_context {
220 __le16 TicketType; /* must be 0x0001 */
221 __le16 TicketSize; /* total size of this struct */
222 __le16 User; /* offset to SID_ATTR_DATA struct with user info */
223 __le16 UserName; /* offset to null terminated Unicode username string */
224 __le16 Domain; /* offset to null terminated Unicode domain name */
225 __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
226 __le16 RestrictedGroups; /* similar to above */
227 __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
228 __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
229 __le16 Owner; /* offset to BLOB_DATA struct */
230 __le16 DefaultDacl; /* offset to BLOB_DATA struct */
231 __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
232 __le16 UserClaims; /* offset to BLOB_DATA struct */
233 __le16 DeviceClaims; /* offset to BLOB_DATA struct */
234 __u8 TicketInfo[]; /* variable length buf - remoted identity data */
237 struct smb2_tree_connect_req_extension {
238 __le32 TreeConnectContextOffset;
239 __le16 TreeConnectContextCount;
241 __u8 PathName[]; /* variable sized array */
242 /* followed by array of TreeConnectContexts */
245 /* Flags/Reserved for SMB3.1.1 */
246 #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
247 #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
248 #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
250 struct smb2_tree_connect_req {
252 __le16 StructureSize; /* Must be 9 */
253 __le16 Flags; /* Flags in SMB3.1.1 */
256 __u8 Buffer[1]; /* variable length */
259 /* Possible ShareType values */
260 #define SMB2_SHARE_TYPE_DISK 0x01
261 #define SMB2_SHARE_TYPE_PIPE 0x02
262 #define SMB2_SHARE_TYPE_PRINT 0x03
265 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
266 * must be set (any of the remaining, SHI1005, flags may be set individually
269 #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
270 #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
271 #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
272 #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
273 #define SHI1005_FLAGS_DFS 0x00000001
274 #define SHI1005_FLAGS_DFS_ROOT 0x00000002
275 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
276 #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
277 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
278 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
279 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
280 #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
281 #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
282 #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
283 #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
284 #define SMB2_SHAREFLAG_COMPRESS_DATA 0x00100000 /* 3.1.1 */
285 #define SHI1005_FLAGS_ALL 0x0014FF33
287 /* Possible share capabilities */
288 #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
289 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
290 #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
291 #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
292 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
293 #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
295 struct smb2_tree_connect_rsp {
297 __le16 StructureSize; /* Must be 16 */
298 __u8 ShareType; /* see below */
300 __le32 ShareFlags; /* see below */
301 __le32 Capabilities; /* see below */
302 __le32 MaximalAccess;
305 struct smb2_tree_disconnect_req {
307 __le16 StructureSize; /* Must be 4 */
311 struct smb2_tree_disconnect_rsp {
313 __le16 StructureSize; /* Must be 4 */
319 * SMB2_NEGOTIATE_PROTOCOL See MS-SMB2 section 2.2.3
321 /* SecurityMode flags */
322 #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
323 #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
324 #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
325 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
326 #define SMB2_SEC_MODE_FLAGS_ALL 0x0003
328 /* Capabilities flags */
329 #define SMB2_GLOBAL_CAP_DFS 0x00000001
330 #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
331 #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
332 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
333 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
334 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
335 #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
337 #define SMB2_NT_FIND 0x00100000
338 #define SMB2_LARGE_FILES 0x00200000
340 #define SMB2_CLIENT_GUID_SIZE 16
341 #define SMB2_CREATE_GUID_SIZE 16
344 #define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */
345 #define SMB20_PROT_ID 0x0202
346 #define SMB21_PROT_ID 0x0210
347 #define SMB2X_PROT_ID 0x02FF
348 #define SMB30_PROT_ID 0x0300
349 #define SMB302_PROT_ID 0x0302
350 #define SMB311_PROT_ID 0x0311
351 #define BAD_PROT_ID 0xFFFF
353 #define SMB311_SALT_SIZE 32
354 /* Hash Algorithm Types */
355 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
356 #define SMB2_PREAUTH_HASH_SIZE 64
358 /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
359 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
360 #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
361 #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
362 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
363 #define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
364 #define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
365 #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
366 #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
368 struct smb2_neg_context {
372 /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
376 * SaltLength that the server send can be zero, so the only three required
377 * fields (all __le16) end up six bytes total, so the minimum context data len
378 * in the response is six bytes which accounts for
380 * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
382 #define MIN_PREAUTH_CTXT_DATA_LEN 6
384 struct smb2_preauth_neg_context {
385 __le16 ContextType; /* 1 */
388 __le16 HashAlgorithmCount; /* 1 */
390 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
391 __u8 Salt[SMB311_SALT_SIZE];
394 /* Encryption Algorithms Ciphers */
395 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
396 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
397 #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
398 #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
400 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
401 #define MIN_ENCRYPT_CTXT_DATA_LEN 4
402 struct smb2_encryption_neg_context {
403 __le16 ContextType; /* 2 */
406 /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
407 __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
411 /* See MS-SMB2 2.2.3.1.3 */
412 #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
413 #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
414 #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
415 #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
416 /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
417 #define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */
419 /* Compression Flags */
420 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000)
421 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)
423 struct smb2_compression_capabilities_context {
424 __le16 ContextType; /* 3 */
427 __le16 CompressionAlgorithmCount;
430 __le16 CompressionAlgorithms[3];
431 __u16 Pad; /* Some servers require pad to DataLen multiple of 8 */
432 /* Check if pad needed */
436 * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
437 * Its struct simply contains NetName, an array of Unicode characters
439 struct smb2_netname_neg_context {
440 __le16 ContextType; /* 5 */
443 __le16 NetName[]; /* hostname of target converted to UCS-2 */
447 * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
452 #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY 0x00000001
454 struct smb2_transport_capabilities_context {
455 __le16 ContextType; /* 6 */
463 * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
467 /* RDMA Transform IDs */
468 #define SMB2_RDMA_TRANSFORM_NONE 0x0000
469 #define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
470 #define SMB2_RDMA_TRANSFORM_SIGNING 0x0002
472 struct smb2_rdma_transform_capabilities_context {
473 __le16 ContextType; /* 7 */
476 __le16 TransformCount;
479 __le16 RDMATransformIds[];
483 * For signing capabilities context see MS-SMB2 2.2.3.1.7
487 /* Signing algorithms */
488 #define SIGNING_ALG_HMAC_SHA256 0
489 #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
490 #define SIGNING_ALG_AES_CMAC 1
491 #define SIGNING_ALG_AES_CMAC_LE cpu_to_le16(1)
492 #define SIGNING_ALG_AES_GMAC 2
493 #define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2)
495 struct smb2_signing_capabilities {
496 __le16 ContextType; /* 8 */
499 __le16 SigningAlgorithmCount;
500 __le16 SigningAlgorithms[];
501 /* Followed by padding to 8 byte boundary (required by some servers) */
504 #define POSIX_CTXT_DATA_LEN 16
505 struct smb2_posix_neg_context {
506 __le16 ContextType; /* 0x100 */
509 __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
512 struct smb2_negotiate_req {
514 __le16 StructureSize; /* Must be 36 */
517 __le16 Reserved; /* MBZ */
519 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
520 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
521 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
522 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
527 struct smb2_negotiate_rsp {
529 __le16 StructureSize; /* Must be 65 */
531 __le16 DialectRevision;
532 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
535 __le32 MaxTransactSize;
538 __le64 SystemTime; /* MBZ */
539 __le64 ServerStartTime;
540 __le16 SecurityBufferOffset;
541 __le16 SecurityBufferLength;
542 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
543 __u8 Buffer[1]; /* variable length GSS security buffer */
548 * SMB2_SESSION_SETUP See MS-SMB2 section 2.2.5
551 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
552 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
554 struct smb2_sess_setup_req {
556 __le16 StructureSize; /* Must be 25 */
561 __le16 SecurityBufferOffset;
562 __le16 SecurityBufferLength;
563 __le64 PreviousSessionId;
564 __u8 Buffer[1]; /* variable length GSS security buffer */
567 /* Currently defined SessionFlags */
568 #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
569 #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001)
570 #define SMB2_SESSION_FLAG_IS_NULL 0x0002
571 #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002)
572 #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
573 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
575 struct smb2_sess_setup_rsp {
577 __le16 StructureSize; /* Must be 9 */
579 __le16 SecurityBufferOffset;
580 __le16 SecurityBufferLength;
581 __u8 Buffer[1]; /* variable length GSS security buffer */
586 * SMB2_LOGOFF See MS-SMB2 section 2.2.7
588 struct smb2_logoff_req {
590 __le16 StructureSize; /* Must be 4 */
594 struct smb2_logoff_rsp {
596 __le16 StructureSize; /* Must be 4 */
602 * SMB2_CLOSE See MS-SMB2 section 2.2.15
604 /* Currently defined values for close flags */
605 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
606 struct smb2_close_req {
608 __le16 StructureSize; /* Must be 24 */
611 __le64 PersistentFileId; /* opaque endianness */
612 __le64 VolatileFileId; /* opaque endianness */
616 * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
618 #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
620 struct smb2_close_rsp {
622 __le16 StructureSize; /* 60 */
626 __le64 LastAccessTime;
627 __le64 LastWriteTime;
629 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
636 * SMB2_READ See MS-SMB2 section 2.2.19
638 /* For read request Flags field below, following flag is defined for SMB3.02 */
639 #define SMB2_READFLAG_READ_UNBUFFERED 0x01
640 #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
642 /* Channel field for read and write: exactly one of following flags can be set*/
643 #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
644 #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001)
645 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
646 #define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003)
648 /* SMB2 read request without RFC1001 length at the beginning */
649 struct smb2_read_req {
651 __le16 StructureSize; /* Must be 49 */
652 __u8 Padding; /* offset from start of SMB2 header to place read */
653 __u8 Flags; /* MBZ unless SMB3.02 or later */
656 __le64 PersistentFileId;
657 __le64 VolatileFileId;
659 __le32 Channel; /* MBZ except for SMB3 or later */
660 __le32 RemainingBytes;
661 __le16 ReadChannelInfoOffset;
662 __le16 ReadChannelInfoLength;
667 #define SMB2_READFLAG_RESPONSE_NONE cpu_to_le32(0x00000000)
668 #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM cpu_to_le32(0x00000001)
670 struct smb2_read_rsp {
672 __le16 StructureSize; /* Must be 17 */
676 __le32 DataRemaining;
683 * SMB2_WRITE See MS-SMB2 section 2.2.21
685 /* For write request Flags field below the following flags are defined: */
686 #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
687 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
689 struct smb2_write_req {
691 __le16 StructureSize; /* Must be 49 */
692 __le16 DataOffset; /* offset from start of SMB2 header to write data */
695 __le64 PersistentFileId; /* opaque endianness */
696 __le64 VolatileFileId; /* opaque endianness */
697 __le32 Channel; /* MBZ unless SMB3.02 or later */
698 __le32 RemainingBytes;
699 __le16 WriteChannelInfoOffset;
700 __le16 WriteChannelInfoLength;
705 struct smb2_write_rsp {
707 __le16 StructureSize; /* Must be 17 */
711 __le32 DataRemaining;
718 * SMB2_FLUSH See MS-SMB2 section 2.2.17
720 struct smb2_flush_req {
722 __le16 StructureSize; /* Must be 24 */
725 __le64 PersistentFileId;
726 __le64 VolatileFileId;
729 struct smb2_flush_rsp {
731 __le16 StructureSize;
737 * SMB2_NOTIFY See MS-SMB2 section 2.2.35
740 #define SMB2_WATCH_TREE 0x0001
742 /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
743 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
744 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
745 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
746 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
747 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
748 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
749 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
750 #define FILE_NOTIFY_CHANGE_EA 0x00000080
751 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
752 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
753 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
754 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
756 /* SMB2 Notify Action Flags */
757 #define FILE_ACTION_ADDED 0x00000001
758 #define FILE_ACTION_REMOVED 0x00000002
759 #define FILE_ACTION_MODIFIED 0x00000003
760 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
761 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
762 #define FILE_ACTION_ADDED_STREAM 0x00000006
763 #define FILE_ACTION_REMOVED_STREAM 0x00000007
764 #define FILE_ACTION_MODIFIED_STREAM 0x00000008
765 #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
767 struct smb2_change_notify_req {
769 __le16 StructureSize;
771 __le32 OutputBufferLength;
772 __le64 PersistentFileId; /* opaque endianness */
773 __le64 VolatileFileId; /* opaque endianness */
774 __le32 CompletionFilter;
778 struct smb2_change_notify_rsp {
780 __le16 StructureSize; /* Must be 9 */
781 __le16 OutputBufferOffset;
782 __le32 OutputBufferLength;
783 __u8 Buffer[1]; /* array of file notify structs */
788 * SMB2_CREATE See MS-SMB2 section 2.2.13
791 #define SMB2_OPLOCK_LEVEL_NONE 0x00
792 #define SMB2_OPLOCK_LEVEL_II 0x01
793 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
794 #define SMB2_OPLOCK_LEVEL_BATCH 0x09
795 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
796 /* Non-spec internal type */
797 #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
799 /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
800 #define IL_ANONYMOUS cpu_to_le32(0x00000000)
801 #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
802 #define IL_IMPERSONATION cpu_to_le32(0x00000002)
803 #define IL_DELEGATE cpu_to_le32(0x00000003)
805 /* File Attrubutes */
806 #define FILE_ATTRIBUTE_READONLY 0x00000001
807 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
808 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
809 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
810 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
811 #define FILE_ATTRIBUTE_NORMAL 0x00000080
812 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
813 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
814 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
815 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
816 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
817 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
818 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
819 #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
820 #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
821 #define FILE_ATTRIBUTE__MASK 0x00007FB7
823 #define FILE_ATTRIBUTE_READONLY_LE cpu_to_le32(0x00000001)
824 #define FILE_ATTRIBUTE_HIDDEN_LE cpu_to_le32(0x00000002)
825 #define FILE_ATTRIBUTE_SYSTEM_LE cpu_to_le32(0x00000004)
826 #define FILE_ATTRIBUTE_DIRECTORY_LE cpu_to_le32(0x00000010)
827 #define FILE_ATTRIBUTE_ARCHIVE_LE cpu_to_le32(0x00000020)
828 #define FILE_ATTRIBUTE_NORMAL_LE cpu_to_le32(0x00000080)
829 #define FILE_ATTRIBUTE_TEMPORARY_LE cpu_to_le32(0x00000100)
830 #define FILE_ATTRIBUTE_SPARSE_FILE_LE cpu_to_le32(0x00000200)
831 #define FILE_ATTRIBUTE_REPARSE_POINT_LE cpu_to_le32(0x00000400)
832 #define FILE_ATTRIBUTE_COMPRESSED_LE cpu_to_le32(0x00000800)
833 #define FILE_ATTRIBUTE_OFFLINE_LE cpu_to_le32(0x00001000)
834 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE cpu_to_le32(0x00002000)
835 #define FILE_ATTRIBUTE_ENCRYPTED_LE cpu_to_le32(0x00004000)
836 #define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE cpu_to_le32(0x00008000)
837 #define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000)
838 #define FILE_ATTRIBUTE_MASK_LE cpu_to_le32(0x00007FB7)
840 /* Desired Access Flags */
841 #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
842 #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001)
843 #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
844 #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
845 #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004)
846 #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
847 #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
848 #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
849 #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040)
850 #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
851 #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
852 #define FILE_DELETE_LE cpu_to_le32(0x00010000)
853 #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
854 #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
855 #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
856 #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
857 #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
858 #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
859 #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
860 #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
861 #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
862 #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
863 #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF)
866 #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \
868 FILE_GENERIC_READ_LE)
869 #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \
870 FILE_APPEND_DATA_LE | \
872 FILE_WRITE_ATTRIBUTES_LE | \
873 FILE_GENERIC_WRITE_LE)
875 /* ShareAccess Flags */
876 #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
877 #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
878 #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
879 #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
881 /* CreateDisposition Flags */
882 #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
883 #define FILE_OPEN_LE cpu_to_le32(0x00000001)
884 #define FILE_CREATE_LE cpu_to_le32(0x00000002)
885 #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
886 #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
887 #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
888 #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
890 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \
891 | FILE_READ_ATTRIBUTES)
892 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
893 | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
894 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
896 /* CreateOptions Flags */
897 #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
898 /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
899 #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
900 #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
901 #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
902 #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
903 #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
904 #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
905 #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
906 #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
907 #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
908 #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
909 #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
910 #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
911 #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
912 #define CREATE_OPTIONS_MASK_LE cpu_to_le32(0x00FFFFFF)
914 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
915 | FILE_READ_ATTRIBUTES_LE)
916 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
917 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
918 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
920 /* Create Context Values */
921 #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
922 #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
923 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
924 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
925 #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
926 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
927 #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
928 #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
929 #define SMB2_CREATE_REQUEST_LEASE "RqLs"
930 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
931 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
932 #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
934 /* Flag (SMB3 open response) values */
935 #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
937 struct create_context {
947 struct smb2_create_req {
949 __le16 StructureSize; /* Must be 57 */
951 __u8 RequestedOplockLevel;
952 __le32 ImpersonationLevel;
953 __le64 SmbCreateFlags;
955 __le32 DesiredAccess;
956 __le32 FileAttributes;
958 __le32 CreateDisposition;
959 __le32 CreateOptions;
962 __le32 CreateContextsOffset;
963 __le32 CreateContextsLength;
967 struct smb2_create_rsp {
969 __le16 StructureSize; /* Must be 89 */
971 __u8 Flags; /* 0x01 if reparse point */
974 __le64 LastAccessTime;
975 __le64 LastWriteTime;
977 __le64 AllocationSize;
979 __le32 FileAttributes;
981 __le64 PersistentFileId;
982 __le64 VolatileFileId;
983 __le32 CreateContextsOffset;
984 __le32 CreateContextsLength;
989 #endif /* _COMMON_SMB2PDU_H */