xref: /linux/fs/smb/common/smb2pdu.h (revision 6234f50105fbb0fffe878b6b493325d67822e43b)
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 #ifndef _COMMON_SMB2PDU_H
3 #define _COMMON_SMB2PDU_H
4 
5 #include <linux/types.h>
6 #include <linux/build_bug.h>
7 
8 /*
9  * Note that, due to trying to use names similar to the protocol specifications,
10  * there are many mixed case field names in the structures below.  Although
11  * this does not match typical Linux kernel style, it is necessary to be
12  * able to match against the protocol specification.
13  *
14  * SMB2 commands
15  * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
16  * (ie no useful data other than the SMB error code itself) and are marked such.
17  * Knowing this helps avoid response buffer allocations and copy in some cases.
18  */
19 
20 /* List of commands in host endian */
21 #define SMB2_NEGOTIATE_HE	0x0000
22 #define SMB2_SESSION_SETUP_HE	0x0001
23 #define SMB2_LOGOFF_HE		0x0002 /* trivial request/resp */
24 #define SMB2_TREE_CONNECT_HE	0x0003
25 #define SMB2_TREE_DISCONNECT_HE	0x0004 /* trivial req/resp */
26 #define SMB2_CREATE_HE		0x0005
27 #define SMB2_CLOSE_HE		0x0006
28 #define SMB2_FLUSH_HE		0x0007 /* trivial resp */
29 #define SMB2_READ_HE		0x0008
30 #define SMB2_WRITE_HE		0x0009
31 #define SMB2_LOCK_HE		0x000A
32 #define SMB2_IOCTL_HE		0x000B
33 #define SMB2_CANCEL_HE		0x000C
34 #define SMB2_ECHO_HE		0x000D
35 #define SMB2_QUERY_DIRECTORY_HE	0x000E
36 #define SMB2_CHANGE_NOTIFY_HE	0x000F
37 #define SMB2_QUERY_INFO_HE	0x0010
38 #define SMB2_SET_INFO_HE	0x0011
39 #define SMB2_OPLOCK_BREAK_HE	0x0012
40 #define SMB2_SERVER_TO_CLIENT_NOTIFICATION 0x0013
41 
42 /* The same list in little endian */
43 #define SMB2_NEGOTIATE		cpu_to_le16(SMB2_NEGOTIATE_HE)
44 #define SMB2_SESSION_SETUP	cpu_to_le16(SMB2_SESSION_SETUP_HE)
45 #define SMB2_LOGOFF		cpu_to_le16(SMB2_LOGOFF_HE)
46 #define SMB2_TREE_CONNECT	cpu_to_le16(SMB2_TREE_CONNECT_HE)
47 #define SMB2_TREE_DISCONNECT	cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
48 #define SMB2_CREATE		cpu_to_le16(SMB2_CREATE_HE)
49 #define SMB2_CLOSE		cpu_to_le16(SMB2_CLOSE_HE)
50 #define SMB2_FLUSH		cpu_to_le16(SMB2_FLUSH_HE)
51 #define SMB2_READ		cpu_to_le16(SMB2_READ_HE)
52 #define SMB2_WRITE		cpu_to_le16(SMB2_WRITE_HE)
53 #define SMB2_LOCK		cpu_to_le16(SMB2_LOCK_HE)
54 #define SMB2_IOCTL		cpu_to_le16(SMB2_IOCTL_HE)
55 #define SMB2_CANCEL		cpu_to_le16(SMB2_CANCEL_HE)
56 #define SMB2_ECHO		cpu_to_le16(SMB2_ECHO_HE)
57 #define SMB2_QUERY_DIRECTORY	cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
58 #define SMB2_CHANGE_NOTIFY	cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
59 #define SMB2_QUERY_INFO		cpu_to_le16(SMB2_QUERY_INFO_HE)
60 #define SMB2_SET_INFO		cpu_to_le16(SMB2_SET_INFO_HE)
61 #define SMB2_OPLOCK_BREAK	cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
62 
63 #define SMB2_INTERNAL_CMD	cpu_to_le16(0xFFFF)
64 
65 #define NUMBER_OF_SMB2_COMMANDS	0x0013
66 
67 /*
68  * Size of the session key (crypto key encrypted with the password
69  */
70 #define SMB2_NTLMV2_SESSKEY_SIZE	16
71 #define SMB2_SIGNATURE_SIZE		16
72 #define SMB2_HMACSHA256_SIZE		32
73 #define SMB2_CMACAES_SIZE		16
74 #define SMB3_GCM128_CRYPTKEY_SIZE	16
75 #define SMB3_GCM256_CRYPTKEY_SIZE	32
76 
77 /*
78  * Size of the smb3 encryption/decryption keys
79  * This size is big enough to store any cipher key types.
80  */
81 #define SMB3_ENC_DEC_KEY_SIZE		32
82 
83 /*
84  * Size of the smb3 signing key
85  */
86 #define SMB3_SIGN_KEY_SIZE		16
87 
88 #define CIFS_CLIENT_CHALLENGE_SIZE	8
89 
90 /* Maximum buffer size value we can send with 1 credit */
91 #define SMB2_MAX_BUFFER_SIZE 65536
92 
93 /*
94  * The default wsize is 1M for SMB2 (and for some CIFS cases).
95  * find_get_pages seems to return a maximum of 256
96  * pages in a single call. With PAGE_SIZE == 4k, this means we can
97  * fill a single wsize request with a single call.
98  */
99 #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
100 
101 /* According to MS-SMB2 specification The minimum recommended value is 65536.*/
102 #define CIFS_MIN_DEFAULT_IOSIZE (65536)
103 
104 /*
105  * SMB2 Header Definition
106  *
107  * "MBZ" :  Must be Zero
108  * "BB"  :  BugBug, Something to check/review/analyze later
109  * "PDU" :  "Protocol Data Unit" (ie a network "frame")
110  *
111  */
112 
113 #define __SMB2_HEADER_STRUCTURE_SIZE	64
114 #define SMB2_HEADER_STRUCTURE_SIZE				\
115 	cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
116 
117 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
118 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
119 #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
120 
121 /*
122  *	SMB2 flag definitions
123  */
124 #define SMB2_FLAGS_SERVER_TO_REDIR	cpu_to_le32(0x00000001)
125 #define SMB2_FLAGS_ASYNC_COMMAND	cpu_to_le32(0x00000002)
126 #define SMB2_FLAGS_RELATED_OPERATIONS	cpu_to_le32(0x00000004)
127 #define SMB2_FLAGS_SIGNED		cpu_to_le32(0x00000008)
128 #define SMB2_FLAGS_PRIORITY_MASK	cpu_to_le32(0x00000070) /* SMB3.1.1 */
129 #define SMB2_FLAGS_DFS_OPERATIONS	cpu_to_le32(0x10000000)
130 #define SMB2_FLAGS_REPLAY_OPERATION	cpu_to_le32(0x20000000) /* SMB3 & up */
131 
132 /*
133  *	Definitions for SMB2 Protocol Data Units (network frames)
134  *
135  *  See MS-SMB2.PDF specification for protocol details.
136  *  The Naming convention is the lower case version of the SMB2
137  *  command code name for the struct. Note that structures must be packed.
138  *
139  */
140 
141 /* See MS-SMB2 section 2.2.1 */
142 struct smb2_hdr {
143 	__le32 ProtocolId;	/* 0xFE 'S' 'M' 'B' */
144 	__le16 StructureSize;	/* 64 */
145 	__le16 CreditCharge;	/* MBZ */
146 	__le32 Status;		/* Error from server */
147 	__le16 Command;
148 	__le16 CreditRequest;	/* CreditResponse */
149 	__le32 Flags;
150 	__le32 NextCommand;
151 	__le64 MessageId;
152 	union {
153 		struct {
154 			__le32 ProcessId;
155 			__le32  TreeId;
156 		} __packed SyncId;
157 		__le64  AsyncId;
158 	} __packed Id;
159 	__le64  SessionId;
160 	__u8   Signature[16];
161 } __packed;
162 
163 struct smb3_hdr_req {
164 	__le32 ProtocolId;	/* 0xFE 'S' 'M' 'B' */
165 	__le16 StructureSize;	/* 64 */
166 	__le16 CreditCharge;	/* MBZ */
167 	__le16 ChannelSequence; /* See MS-SMB2 3.2.4.1 and 3.2.7.1 */
168 	__le16 Reserved;
169 	__le16 Command;
170 	__le16 CreditRequest;	/* CreditResponse */
171 	__le32 Flags;
172 	__le32 NextCommand;
173 	__le64 MessageId;
174 	union {
175 		struct {
176 			__le32 ProcessId;
177 			__le32  TreeId;
178 		} __packed SyncId;
179 		__le64  AsyncId;
180 	} __packed Id;
181 	__le64  SessionId;
182 	__u8   Signature[16];
183 } __packed;
184 
185 struct smb2_pdu {
186 	struct smb2_hdr hdr;
187 	__le16 StructureSize2; /* size of wct area (varies, request specific) */
188 } __packed;
189 
190 #define SMB2_ERROR_STRUCTURE_SIZE2	9
191 #define SMB2_ERROR_STRUCTURE_SIZE2_LE	cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
192 
193 struct smb2_err_rsp {
194 	struct smb2_hdr hdr;
195 	__le16 StructureSize;
196 	__u8   ErrorContextCount;
197 	__u8   Reserved;
198 	__le32 ByteCount;  /* even if zero, at least one byte follows */
199 	__u8   ErrorData[];  /* variable length */
200 } __packed;
201 
202 #define SMB3_AES_CCM_NONCE 11
203 #define SMB3_AES_GCM_NONCE 12
204 
205 /* Transform flags (for 3.0 dialect this flag indicates CCM */
206 #define TRANSFORM_FLAG_ENCRYPTED	0x0001
207 struct smb2_transform_hdr {
208 	__le32 ProtocolId;	/* 0xFD 'S' 'M' 'B' */
209 	__u8   Signature[16];
210 	__u8   Nonce[16];
211 	__le32 OriginalMessageSize;
212 	__u16  Reserved1;
213 	__le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
214 	__le64  SessionId;
215 } __packed;
216 
217 /*
218  * These are simplified versions from the spec, as we don't need a fully fledged
219  * form of both unchained and chained structs.
220  *
221  * For chained payloads, only the first 8 bytes belong to the transform header.
222  * CompressionAlgorithm, Flags and Offset below overlay the first chained
223  * payload header, where Offset represents Length.
224  *
225  * See MS-SMB2 2.2.42 for more details.
226  */
227 #define SMB2_COMPRESSION_FLAG_NONE	0x0000
228 #define SMB2_COMPRESSION_FLAG_CHAINED	0x0001
229 
230 struct smb2_compression_hdr {
231 	__le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
232 	__le32 OriginalCompressedSegmentSize;
233 	__le16 CompressionAlgorithm;
234 	__le16 Flags;
235 	__le32 Offset; /* this is the size of the uncompressed SMB2 header below */
236 	/* uncompressed SMB2 header (READ or WRITE) goes here */
237 	/* compressed data goes here */
238 } __packed;
239 
240 /*
241  * ... OTOH, set compression payload header to always have OriginalPayloadSize
242  * as it's easier to pass the struct size minus sizeof(OriginalPayloadSize)
243  * than to juggle around the header/data memory.
244  */
245 struct smb2_compression_payload_hdr {
246 	__le16	CompressionAlgorithm;
247 	__le16	Flags;
248 	__le32	Length; /* length of compressed playload including field below if present */
249 	__le32 OriginalPayloadSize; /* accounted when LZNT1, LZ77, LZ77+Huffman */
250 } __packed;
251 
252 struct smb2_compression_pattern_v1 {
253 	__u8	Pattern;
254 	__u8	Reserved1;
255 	__le16	Reserved2;
256 	__le32	Repetitions;
257 } __packed;
258 
259 /* See MS-SMB2 section 2.2.9.2 */
260 /* Context Types */
261 #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
262 #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
263 
264 struct tree_connect_contexts {
265 	__le16 ContextType;
266 	__le16 DataLength;
267 	__le32 Reserved;
268 	__u8   Data[];
269 } __packed;
270 
271 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
272 struct smb3_blob_data {
273 	__le16 BlobSize;
274 	__u8   BlobData[];
275 } __packed;
276 
277 /* Valid values for Attr */
278 #define SE_GROUP_MANDATORY		0x00000001
279 #define SE_GROUP_ENABLED_BY_DEFAULT	0x00000002
280 #define SE_GROUP_ENABLED		0x00000004
281 #define SE_GROUP_OWNER			0x00000008
282 #define SE_GROUP_USE_FOR_DENY_ONLY	0x00000010
283 #define SE_GROUP_INTEGRITY		0x00000020
284 #define SE_GROUP_INTEGRITY_ENABLED	0x00000040
285 #define SE_GROUP_RESOURCE		0x20000000
286 #define SE_GROUP_LOGON_ID		0xC0000000
287 
288 struct sid_array_data {
289 	__le16 SidAttrCount;
290 	/* SidAttrList - array of sid_attr_data structs */
291 } __packed;
292 
293 /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
294 struct sid_attr_data {
295 	__le16 BlobSize;
296 	__u8 BlobData[];
297 	/* __le32 Attr */
298 } __packed;
299 
300 /*
301  * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
302  * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
303  */
304 
305 struct privilege_array_data {
306 	__le16 PrivilegeCount;
307 	/* array of privilege_data structs */
308 } __packed;
309 
310 struct remoted_identity_tcon_context {
311 	__le16 TicketType; /* must be 0x0001 */
312 	__le16 TicketSize; /* total size of this struct */
313 	__le16 User; /* offset to SID_ATTR_DATA struct with user info */
314 	__le16 UserName; /* offset to null terminated Unicode username string */
315 	__le16 Domain; /* offset to null terminated Unicode domain name */
316 	__le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
317 	__le16 RestrictedGroups; /* similar to above */
318 	__le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
319 	__le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
320 	__le16 Owner; /* offset to BLOB_DATA struct */
321 	__le16 DefaultDacl; /* offset to BLOB_DATA struct */
322 	__le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
323 	__le16 UserClaims; /* offset to BLOB_DATA struct */
324 	__le16 DeviceClaims; /* offset to BLOB_DATA struct */
325 	__u8   TicketInfo[]; /* variable length buf - remoted identity data */
326 } __packed;
327 
328 struct smb2_tree_connect_req_extension {
329 	__le32 TreeConnectContextOffset;
330 	__le16 TreeConnectContextCount;
331 	__u8  Reserved[10];
332 	__u8  PathName[]; /* variable sized array */
333 	/* followed by array of TreeConnectContexts */
334 } __packed;
335 
336 /* Flags/Reserved for SMB3.1.1 */
337 #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
338 #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
339 #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
340 
341 struct smb2_tree_connect_req {
342 	struct smb2_hdr hdr;
343 	__le16 StructureSize;	/* Must be 9 */
344 	__le16 Flags;		/* Flags in SMB3.1.1 */
345 	__le16 PathOffset;
346 	__le16 PathLength;
347 	__u8   Buffer[];	/* variable length */
348 } __packed;
349 
350 /* Possible ShareType values */
351 #define SMB2_SHARE_TYPE_DISK	0x01
352 #define SMB2_SHARE_TYPE_PIPE	0x02
353 #define	SMB2_SHARE_TYPE_PRINT	0x03
354 
355 /*
356  * Possible ShareFlags - exactly one and only one of the first 4 caching flags
357  * must be set (any of the remaining, SHI1005, flags may be set individually
358  * or in combination.
359  */
360 #define SMB2_SHAREFLAG_MANUAL_CACHING			0x00000000
361 #define SMB2_SHAREFLAG_AUTO_CACHING			0x00000010
362 #define SMB2_SHAREFLAG_VDO_CACHING			0x00000020
363 #define SMB2_SHAREFLAG_NO_CACHING			0x00000030
364 #define SHI1005_FLAGS_DFS				0x00000001
365 #define SHI1005_FLAGS_DFS_ROOT				0x00000002
366 #define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS		0x00000100
367 #define SMB2_SHAREFLAG_FORCE_SHARED_DELETE		0x00000200
368 #define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING		0x00000400
369 #define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM	0x00000800
370 #define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK		0x00001000
371 #define SMB2_SHAREFLAG_ENABLE_HASH_V1			0x00002000
372 #define SMB2_SHAREFLAG_ENABLE_HASH_V2			0x00004000
373 #define SHI1005_FLAGS_ENCRYPT_DATA			0x00008000
374 #define SMB2_SHAREFLAG_IDENTITY_REMOTING		0x00040000 /* 3.1.1 */
375 #define SMB2_SHAREFLAG_COMPRESS_DATA			0x00100000 /* 3.1.1 */
376 #define SMB2_SHAREFLAG_ISOLATED_TRANSPORT		0x00200000
377 #define SHI1005_FLAGS_ALL				0x0034FF33
378 
379 /* Possible share capabilities */
380 #define SMB2_SHARE_CAP_DFS	cpu_to_le32(0x00000008) /* all dialects */
381 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
382 #define SMB2_SHARE_CAP_SCALEOUT	cpu_to_le32(0x00000020) /* 3.0 */
383 #define SMB2_SHARE_CAP_CLUSTER	cpu_to_le32(0x00000040) /* 3.0 */
384 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
385 #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
386 
387 struct smb2_tree_connect_rsp {
388 	struct smb2_hdr hdr;
389 	__le16 StructureSize;	/* Must be 16 */
390 	__u8   ShareType;	/* see below */
391 	__u8   Reserved;
392 	__le32 ShareFlags;	/* see below */
393 	__le32 Capabilities;	/* see below */
394 	__le32 MaximalAccess;
395 } __packed;
396 
397 struct smb2_tree_disconnect_req {
398 	struct smb2_hdr hdr;
399 	__le16 StructureSize;	/* Must be 4 */
400 	__le16 Reserved;
401 } __packed;
402 
403 struct smb2_tree_disconnect_rsp {
404 	struct smb2_hdr hdr;
405 	__le16 StructureSize;	/* Must be 4 */
406 	__le16 Reserved;
407 } __packed;
408 
409 
410 /*
411  * SMB2_NEGOTIATE_PROTOCOL  See MS-SMB2 section 2.2.3
412  */
413 /* SecurityMode flags */
414 #define	SMB2_NEGOTIATE_SIGNING_ENABLED     0x0001
415 #define	SMB2_NEGOTIATE_SIGNING_ENABLED_LE  cpu_to_le16(0x0001)
416 #define SMB2_NEGOTIATE_SIGNING_REQUIRED	   0x0002
417 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
418 #define SMB2_SEC_MODE_FLAGS_ALL            0x0003
419 
420 /* Capabilities flags */
421 #define SMB2_GLOBAL_CAP_DFS		0x00000001
422 #define SMB2_GLOBAL_CAP_LEASING		0x00000002 /* Resp only New to SMB2.1 */
423 #define SMB2_GLOBAL_CAP_LARGE_MTU	0x00000004 /* Resp only New to SMB2.1 */
424 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL	0x00000008 /* New to SMB3 */
425 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
426 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING  0x00000020 /* New to SMB3 */
427 #define SMB2_GLOBAL_CAP_ENCRYPTION	0x00000040 /* New to SMB3 */
428 #define SMB2_GLOBAL_CAP_NOTIFICATIONS	0x00000080 /* New to SMB3.1.1 */
429 /* Internal types */
430 #define SMB2_NT_FIND			0x00100000
431 #define SMB2_LARGE_FILES		0x00200000
432 
433 #define SMB2_CLIENT_GUID_SIZE		16
434 #define SMB2_CREATE_GUID_SIZE		16
435 
436 /* Dialects */
437 #define SMB10_PROT_ID  0x0000 /* local only, not sent on wire w/CIFS negprot */
438 #define SMB20_PROT_ID  0x0202
439 #define SMB21_PROT_ID  0x0210
440 #define SMB2X_PROT_ID  0x02FF
441 #define SMB30_PROT_ID  0x0300
442 #define SMB302_PROT_ID 0x0302
443 #define SMB311_PROT_ID 0x0311
444 #define BAD_PROT_ID    0xFFFF
445 
446 #define SMB311_SALT_SIZE			32
447 /* Hash Algorithm Types */
448 #define SMB2_PREAUTH_INTEGRITY_SHA512	cpu_to_le16(0x0001)
449 #define SMB2_PREAUTH_HASH_SIZE 64
450 
451 /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
452 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES	cpu_to_le16(1)
453 #define SMB2_ENCRYPTION_CAPABILITIES		cpu_to_le16(2)
454 #define SMB2_COMPRESSION_CAPABILITIES		cpu_to_le16(3)
455 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID	cpu_to_le16(5)
456 #define SMB2_TRANSPORT_CAPABILITIES		cpu_to_le16(6)
457 #define SMB2_RDMA_TRANSFORM_CAPABILITIES	cpu_to_le16(7)
458 #define SMB2_SIGNING_CAPABILITIES		cpu_to_le16(8)
459 #define SMB2_POSIX_EXTENSIONS_AVAILABLE		cpu_to_le16(0x100)
460 
461 struct smb2_neg_context {
462 	__le16	ContextType;
463 	__le16	DataLength;
464 	__le32	Reserved;
465 	/* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
466 } __packed;
467 
468 /*
469  * SaltLength that the server send can be zero, so the only three required
470  * fields (all __le16) end up six bytes total, so the minimum context data len
471  * in the response is six bytes which accounts for
472  *
473  *      HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
474  */
475 #define MIN_PREAUTH_CTXT_DATA_LEN 6
476 
477 struct smb2_preauth_neg_context {
478 	__le16	ContextType; /* 1 */
479 	__le16	DataLength;
480 	__le32	Reserved;
481 	__le16	HashAlgorithmCount; /* 1 */
482 	__le16	SaltLength;
483 	__le16	HashAlgorithms; /* HashAlgorithms[0] since only one defined */
484 	__u8	Salt[SMB311_SALT_SIZE];
485 } __packed;
486 
487 /* Encryption Algorithms Ciphers */
488 #define SMB2_ENCRYPTION_AES128_CCM	cpu_to_le16(0x0001)
489 #define SMB2_ENCRYPTION_AES128_GCM	cpu_to_le16(0x0002)
490 #define SMB2_ENCRYPTION_AES256_CCM      cpu_to_le16(0x0003)
491 #define SMB2_ENCRYPTION_AES256_GCM      cpu_to_le16(0x0004)
492 
493 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
494 #define MIN_ENCRYPT_CTXT_DATA_LEN	4
495 struct smb2_encryption_neg_context {
496 	__le16	ContextType; /* 2 */
497 	__le16	DataLength;
498 	__le32	Reserved;
499 	/* CipherCount usually 2, but can be 3 when AES256-GCM enabled */
500 	__le16	CipherCount; /* AES128-GCM and AES128-CCM by default */
501 	__le16	Ciphers[];
502 } __packed;
503 
504 /* See MS-SMB2 2.2.3.1.3 */
505 #define SMB3_COMPRESS_NONE	cpu_to_le16(0x0000)
506 #define SMB3_COMPRESS_LZNT1	cpu_to_le16(0x0001)
507 #define SMB3_COMPRESS_LZ77	cpu_to_le16(0x0002)
508 #define SMB3_COMPRESS_LZ77_HUFF	cpu_to_le16(0x0003)
509 /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
510 #define SMB3_COMPRESS_PATTERN	cpu_to_le16(0x0004) /* Pattern_V1 */
511 #define SMB3_COMPRESS_LZ4	cpu_to_le16(0x0005)
512 /* Account for NONE for easier array indexing */
513 #define SMB3_COMPRESS_MAX_ALGS	6
514 
515 /* Compression Flags */
516 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE		cpu_to_le32(0x00000000)
517 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED	cpu_to_le32(0x00000001)
518 
519 struct smb2_compression_capabilities_context {
520 	__le16	ContextType; /* 3 */
521 	__le16  DataLength;
522 	__le32	Reserved;
523 	__le16	CompressionAlgorithmCount;
524 	__le16	Padding;
525 	__le32	Flags;
526 	__le16	CompressionAlgorithms[4];
527 } __packed;
528 
529 /*
530  * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
531  * Its struct simply contains NetName, an array of Unicode characters
532  */
533 struct smb2_netname_neg_context {
534 	__le16	ContextType; /* 5 */
535 	__le16	DataLength;
536 	__le32	Reserved;
537 	__le16	NetName[]; /* hostname of target converted to UCS-2 */
538 } __packed;
539 
540 /*
541  * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
542  * and 2.2.4.1.5
543  */
544 
545 /* Flags */
546 #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY	0x00000001
547 
548 struct smb2_transport_capabilities_context {
549 	__le16	ContextType; /* 6 */
550 	__le16  DataLength;
551 	__u32	Reserved;
552 	__le32	Flags;
553 	__u32	Pad;
554 } __packed;
555 
556 /*
557  * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
558  * and 2.2.4.1.6
559  */
560 
561 /* RDMA Transform IDs */
562 #define SMB2_RDMA_TRANSFORM_NONE	0x0000
563 #define SMB2_RDMA_TRANSFORM_ENCRYPTION	0x0001
564 #define SMB2_RDMA_TRANSFORM_SIGNING	0x0002
565 
566 struct smb2_rdma_transform_capabilities_context {
567 	__le16	ContextType; /* 7 */
568 	__le16  DataLength;
569 	__u32	Reserved;
570 	__le16	TransformCount;
571 	__u16	Reserved1;
572 	__u32	Reserved2;
573 	__le16	RDMATransformIds[];
574 } __packed;
575 
576 /*
577  * For signing capabilities context see MS-SMB2 2.2.3.1.7
578  * and 2.2.4.1.7
579  */
580 
581 /* Signing algorithms */
582 #define SIGNING_ALG_HMAC_SHA256    0
583 #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
584 #define SIGNING_ALG_AES_CMAC       1
585 #define SIGNING_ALG_AES_CMAC_LE    cpu_to_le16(1)
586 #define SIGNING_ALG_AES_GMAC       2
587 #define SIGNING_ALG_AES_GMAC_LE    cpu_to_le16(2)
588 
589 struct smb2_signing_capabilities {
590 	__le16	ContextType; /* 8 */
591 	__le16	DataLength;
592 	__le32	Reserved;
593 	__le16	SigningAlgorithmCount;
594 	__le16	SigningAlgorithms[];
595 	/*  Followed by padding to 8 byte boundary (required by some servers) */
596 } __packed;
597 
598 #define POSIX_CTXT_DATA_LEN	16
599 struct smb2_posix_neg_context {
600 	__le16	ContextType; /* 0x100 */
601 	__le16	DataLength;
602 	__le32	Reserved;
603 	__u8	Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
604 } __packed;
605 
606 struct smb2_negotiate_req {
607 	struct smb2_hdr hdr;
608 	__le16 StructureSize; /* Must be 36 */
609 	__le16 DialectCount;
610 	__le16 SecurityMode;
611 	__le16 Reserved;	/* MBZ */
612 	__le32 Capabilities;
613 	__u8   ClientGUID[SMB2_CLIENT_GUID_SIZE];
614 	/* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
615 	__le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
616 	__le16 NegotiateContextCount;  /* SMB3.1.1 only. MBZ earlier */
617 	__le16 Reserved2;
618 	__le16 Dialects[];
619 } __packed;
620 
621 struct smb2_negotiate_rsp {
622 	struct smb2_hdr hdr;
623 	__le16 StructureSize;	/* Must be 65 */
624 	__le16 SecurityMode;
625 	__le16 DialectRevision;
626 	__le16 NegotiateContextCount;	/* Prior to SMB3.1.1 was Reserved & MBZ */
627 	__u8   ServerGUID[16];
628 	__le32 Capabilities;
629 	__le32 MaxTransactSize;
630 	__le32 MaxReadSize;
631 	__le32 MaxWriteSize;
632 	__le64 SystemTime;	/* MBZ */
633 	__le64 ServerStartTime;
634 	__le16 SecurityBufferOffset;
635 	__le16 SecurityBufferLength;
636 	__le32 NegotiateContextOffset;	/* Pre:SMB3.1.1 was reserved/ignored */
637 	__u8   Buffer[];	/* variable length GSS security buffer */
638 } __packed;
639 
640 
641 /*
642  * SMB2_SESSION_SETUP  See MS-SMB2 section 2.2.5
643  */
644 /* Flags */
645 #define SMB2_SESSION_REQ_FLAG_BINDING		0x01
646 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA	0x04
647 
648 struct smb2_sess_setup_req {
649 	struct smb2_hdr hdr;
650 	__le16 StructureSize; /* Must be 25 */
651 	__u8   Flags;
652 	__u8   SecurityMode;
653 	__le32 Capabilities;
654 	__le32 Channel;
655 	__le16 SecurityBufferOffset;
656 	__le16 SecurityBufferLength;
657 	__le64 PreviousSessionId;
658 	__u8   Buffer[];	/* variable length GSS security buffer */
659 } __packed;
660 
661 /* Currently defined SessionFlags */
662 #define SMB2_SESSION_FLAG_IS_GUEST        0x0001
663 #define SMB2_SESSION_FLAG_IS_GUEST_LE     cpu_to_le16(0x0001)
664 #define SMB2_SESSION_FLAG_IS_NULL         0x0002
665 #define SMB2_SESSION_FLAG_IS_NULL_LE      cpu_to_le16(0x0002)
666 #define SMB2_SESSION_FLAG_ENCRYPT_DATA    0x0004
667 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
668 
669 struct smb2_sess_setup_rsp {
670 	struct smb2_hdr hdr;
671 	__le16 StructureSize; /* Must be 9 */
672 	__le16 SessionFlags;
673 	__le16 SecurityBufferOffset;
674 	__le16 SecurityBufferLength;
675 	__u8   Buffer[];	/* variable length GSS security buffer */
676 } __packed;
677 
678 
679 /*
680  * SMB2_LOGOFF  See MS-SMB2 section 2.2.7
681  */
682 struct smb2_logoff_req {
683 	struct smb2_hdr hdr;
684 	__le16 StructureSize;	/* Must be 4 */
685 	__le16 Reserved;
686 } __packed;
687 
688 struct smb2_logoff_rsp {
689 	struct smb2_hdr hdr;
690 	__le16 StructureSize;	/* Must be 4 */
691 	__le16 Reserved;
692 } __packed;
693 
694 
695 /*
696  * SMB2_CLOSE  See MS-SMB2 section 2.2.15
697  */
698 /* Currently defined values for close flags */
699 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB	cpu_to_le16(0x0001)
700 struct smb2_close_req {
701 	struct smb2_hdr hdr;
702 	__le16 StructureSize;	/* Must be 24 */
703 	__le16 Flags;
704 	__le32 Reserved;
705 	__u64  PersistentFileId; /* opaque endianness */
706 	__u64  VolatileFileId; /* opaque endianness */
707 } __packed;
708 
709 /*
710  * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
711  */
712 #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
713 
714 struct smb2_close_rsp {
715 	struct smb2_hdr hdr;
716 	__le16 StructureSize; /* 60 */
717 	__le16 Flags;
718 	__le32 Reserved;
719 	struct_group_attr(network_open_info, __packed,
720 		__le64 CreationTime;
721 		__le64 LastAccessTime;
722 		__le64 LastWriteTime;
723 		__le64 ChangeTime;
724 		/* Beginning of FILE_STANDARD_INFO equivalent */
725 		__le64 AllocationSize;
726 		__le64 EndOfFile;
727 		__le32 Attributes;
728 	);
729 } __packed;
730 
731 
732 /*
733  * SMB2_READ  See MS-SMB2 section 2.2.19
734  */
735 /* For read request Flags field below, following flag is defined for SMB3.02 */
736 #define SMB2_READFLAG_READ_UNBUFFERED	0x01
737 #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
738 
739 /* Channel field for read and write: exactly one of following flags can be set*/
740 #define SMB2_CHANNEL_NONE               cpu_to_le32(0x00000000)
741 #define SMB2_CHANNEL_RDMA_V1            cpu_to_le32(0x00000001)
742 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
743 #define SMB2_CHANNEL_RDMA_TRANSFORM     cpu_to_le32(0x00000003)
744 
745 /* SMB2 read request without RFC1001 length at the beginning */
746 struct smb2_read_req {
747 	struct smb2_hdr hdr;
748 	__le16 StructureSize; /* Must be 49 */
749 	__u8   Padding; /* offset from start of SMB2 header to place read */
750 	__u8   Flags; /* MBZ unless SMB3.02 or later */
751 	__le32 Length;
752 	__le64 Offset;
753 	__u64  PersistentFileId;
754 	__u64  VolatileFileId;
755 	__le32 MinimumCount;
756 	__le32 Channel; /* MBZ except for SMB3 or later */
757 	__le32 RemainingBytes;
758 	__le16 ReadChannelInfoOffset;
759 	__le16 ReadChannelInfoLength;
760 	__u8   Buffer[];
761 } __packed;
762 
763 /* Read flags */
764 #define SMB2_READFLAG_RESPONSE_NONE            cpu_to_le32(0x00000000)
765 #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM  cpu_to_le32(0x00000001)
766 
767 struct smb2_read_rsp {
768 	struct smb2_hdr hdr;
769 	__le16 StructureSize; /* Must be 17 */
770 	__u8   DataOffset;
771 	__u8   Reserved;
772 	__le32 DataLength;
773 	__le32 DataRemaining;
774 	__le32 Flags;
775 	__u8   Buffer[];
776 } __packed;
777 
778 
779 /*
780  * SMB2_WRITE  See MS-SMB2 section 2.2.21
781  */
782 /* For write request Flags field below the following flags are defined: */
783 #define SMB2_WRITEFLAG_WRITE_THROUGH	0x00000001	/* SMB2.1 or later */
784 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED	0x00000002	/* SMB3.02 or later */
785 
786 struct smb2_write_req {
787 	struct smb2_hdr hdr;
788 	__le16 StructureSize; /* Must be 49 */
789 	__le16 DataOffset; /* offset from start of SMB2 header to write data */
790 	__le32 Length;
791 	__le64 Offset;
792 	__u64  PersistentFileId; /* opaque endianness */
793 	__u64  VolatileFileId; /* opaque endianness */
794 	__le32 Channel; /* MBZ unless SMB3.02 or later */
795 	__le32 RemainingBytes;
796 	__le16 WriteChannelInfoOffset;
797 	__le16 WriteChannelInfoLength;
798 	__le32 Flags;
799 	__u8   Buffer[];
800 } __packed;
801 
802 struct smb2_write_rsp {
803 	struct smb2_hdr hdr;
804 	__le16 StructureSize; /* Must be 17 */
805 	__u8   DataOffset;
806 	__u8   Reserved;
807 	__le32 DataLength;
808 	__le32 DataRemaining;
809 	__u32  Reserved2;
810 	__u8   Buffer[];
811 } __packed;
812 
813 
814 /*
815  * SMB2_FLUSH  See MS-SMB2 section 2.2.17
816  */
817 struct smb2_flush_req {
818 	struct smb2_hdr hdr;
819 	__le16 StructureSize;	/* Must be 24 */
820 	__le16 Reserved1;
821 	__le32 Reserved2;
822 	__u64  PersistentFileId;
823 	__u64  VolatileFileId;
824 } __packed;
825 
826 struct smb2_flush_rsp {
827 	struct smb2_hdr hdr;
828 	__le16 StructureSize;
829 	__le16 Reserved;
830 } __packed;
831 
832 #define SMB2_LOCKFLAG_SHARED		0x0001
833 #define SMB2_LOCKFLAG_EXCLUSIVE		0x0002
834 #define SMB2_LOCKFLAG_UNLOCK		0x0004
835 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY	0x0010
836 #define SMB2_LOCKFLAG_MASK		0x0007
837 
838 struct smb2_lock_element {
839 	__le64 Offset;
840 	__le64 Length;
841 	__le32 Flags;
842 	__le32 Reserved;
843 } __packed;
844 
845 struct smb2_lock_req {
846 	struct smb2_hdr hdr;
847 	__le16 StructureSize; /* Must be 48 */
848 	__le16 LockCount;
849 	/*
850 	 * The least significant four bits are the index, the other 28 bits are
851 	 * the lock sequence number (0 to 64). See MS-SMB2 2.2.26
852 	 */
853 	__le32 LockSequenceNumber;
854 	__u64  PersistentFileId;
855 	__u64  VolatileFileId;
856 	/* Followed by at least one */
857 	union {
858 		struct smb2_lock_element lock;
859 		DECLARE_FLEX_ARRAY(struct smb2_lock_element, locks);
860 	};
861 } __packed;
862 
863 struct smb2_lock_rsp {
864 	struct smb2_hdr hdr;
865 	__le16 StructureSize; /* Must be 4 */
866 	__le16 Reserved;
867 } __packed;
868 
869 struct smb2_echo_req {
870 	struct smb2_hdr hdr;
871 	__le16 StructureSize;	/* Must be 4 */
872 	__u16  Reserved;
873 } __packed;
874 
875 struct smb2_echo_rsp {
876 	struct smb2_hdr hdr;
877 	__le16 StructureSize;	/* Must be 4 */
878 	__u16  Reserved;
879 } __packed;
880 
881 /*
882  * Valid FileInformation classes for query directory
883  *
884  * Note that these are a subset of the (file) QUERY_INFO levels defined
885  * later in this file (but since QUERY_DIRECTORY uses equivalent numbers
886  * we do not redefine them here)
887  *
888  * FileDirectoryInfomation		0x01
889  * FileFullDirectoryInformation		0x02
890  * FileIdFullDirectoryInformation	0x26
891  * FileBothDirectoryInformation		0x03
892  * FileIdBothDirectoryInformation	0x25
893  * FileNamesInformation			0x0C
894  * FileIdExtdDirectoryInformation	0x3C
895  */
896 
897 /* search (query_directory) Flags field */
898 #define SMB2_RESTART_SCANS		0x01
899 #define SMB2_RETURN_SINGLE_ENTRY	0x02
900 #define SMB2_INDEX_SPECIFIED		0x04
901 #define SMB2_REOPEN			0x10
902 
903 struct smb2_query_directory_req {
904 	struct smb2_hdr hdr;
905 	__le16 StructureSize; /* Must be 33 */
906 	__u8   FileInformationClass;
907 	__u8   Flags;
908 	__le32 FileIndex;
909 	__u64  PersistentFileId;
910 	__u64  VolatileFileId;
911 	__le16 FileNameOffset;
912 	__le16 FileNameLength;
913 	__le32 OutputBufferLength;
914 	__u8   Buffer[];
915 } __packed;
916 
917 struct smb2_query_directory_rsp {
918 	struct smb2_hdr hdr;
919 	__le16 StructureSize; /* Must be 9 */
920 	__le16 OutputBufferOffset;
921 	__le32 OutputBufferLength;
922 	__u8   Buffer[];
923 } __packed;
924 
925 /* DeviceType Flags */
926 #define FILE_DEVICE_CD_ROM              0x00000002
927 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM  0x00000003
928 #define FILE_DEVICE_DFS                 0x00000006
929 #define FILE_DEVICE_DISK                0x00000007
930 #define FILE_DEVICE_DISK_FILE_SYSTEM    0x00000008
931 #define FILE_DEVICE_FILE_SYSTEM         0x00000009
932 #define FILE_DEVICE_NAMED_PIPE          0x00000011
933 #define FILE_DEVICE_NETWORK             0x00000012
934 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
935 #define FILE_DEVICE_NULL                0x00000015
936 #define FILE_DEVICE_PARALLEL_PORT       0x00000016
937 #define FILE_DEVICE_PRINTER             0x00000018
938 #define FILE_DEVICE_SERIAL_PORT         0x0000001b
939 #define FILE_DEVICE_STREAMS             0x0000001e
940 #define FILE_DEVICE_TAPE                0x0000001f
941 #define FILE_DEVICE_TAPE_FILE_SYSTEM    0x00000020
942 #define FILE_DEVICE_VIRTUAL_DISK        0x00000024
943 #define FILE_DEVICE_NETWORK_REDIRECTOR  0x00000028
944 
945 /* Device Characteristics */
946 #define FILE_REMOVABLE_MEDIA			0x00000001
947 #define FILE_READ_ONLY_DEVICE			0x00000002
948 #define FILE_FLOPPY_DISKETTE			0x00000004
949 #define FILE_WRITE_ONCE_MEDIA			0x00000008
950 #define FILE_REMOTE_DEVICE			0x00000010
951 #define FILE_DEVICE_IS_MOUNTED			0x00000020
952 #define FILE_VIRTUAL_VOLUME			0x00000040
953 #define FILE_DEVICE_SECURE_OPEN			0x00000100
954 #define FILE_CHARACTERISTIC_TS_DEVICE		0x00001000
955 #define FILE_CHARACTERISTIC_WEBDAV_DEVICE	0x00002000
956 #define FILE_PORTABLE_DEVICE			0x00004000
957 #define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000
958 
959 /*
960  * Maximum number of iovs we need for a set-info request.
961  * The largest one is rename/hardlink
962  * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
963  * [1] : path
964  * [2] : compound padding
965  */
966 #define SMB2_SET_INFO_IOV_SIZE 3
967 
968 struct smb2_set_info_req {
969 	struct smb2_hdr hdr;
970 	__le16 StructureSize; /* Must be 33 */
971 	__u8   InfoType;
972 	__u8   FileInfoClass;
973 	__le32 BufferLength;
974 	__le16 BufferOffset;
975 	__u16  Reserved;
976 	__le32 AdditionalInformation;
977 	__u64  PersistentFileId;
978 	__u64  VolatileFileId;
979 	__u8   Buffer[];
980 } __packed;
981 
982 struct smb2_set_info_rsp {
983 	struct smb2_hdr hdr;
984 	__le16 StructureSize; /* Must be 2 */
985 } __packed;
986 
987 /*
988  * SMB2_NOTIFY  See MS-SMB2 section 2.2.35
989  */
990 /* notify flags */
991 #define SMB2_WATCH_TREE			0x0001
992 
993 /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
994 #define FILE_NOTIFY_CHANGE_FILE_NAME		0x00000001
995 #define FILE_NOTIFY_CHANGE_DIR_NAME		0x00000002
996 #define FILE_NOTIFY_CHANGE_NAME			0x00000003
997 #define FILE_NOTIFY_CHANGE_ATTRIBUTES		0x00000004
998 #define FILE_NOTIFY_CHANGE_SIZE			0x00000008
999 #define FILE_NOTIFY_CHANGE_LAST_WRITE		0x00000010
1000 #define FILE_NOTIFY_CHANGE_LAST_ACCESS		0x00000020
1001 #define FILE_NOTIFY_CHANGE_CREATION		0x00000040
1002 #define FILE_NOTIFY_CHANGE_EA			0x00000080
1003 #define FILE_NOTIFY_CHANGE_SECURITY		0x00000100
1004 #define FILE_NOTIFY_CHANGE_STREAM_NAME		0x00000200
1005 #define FILE_NOTIFY_CHANGE_STREAM_SIZE		0x00000400
1006 #define FILE_NOTIFY_CHANGE_STREAM_WRITE		0x00000800
1007 
1008 /* See MS-SMB2 2.2.35 */
1009 struct smb2_change_notify_req {
1010 	struct smb2_hdr hdr;
1011 	__le16	StructureSize;
1012 	__le16	Flags;
1013 	__le32	OutputBufferLength;
1014 	__u64	PersistentFileId; /* opaque endianness */
1015 	__u64	VolatileFileId; /* opaque endianness */
1016 	__le32	CompletionFilter;
1017 	__u32	Reserved;
1018 } __packed;
1019 
1020 /* See MS-SMB2 2.2.36 */
1021 struct smb2_change_notify_rsp {
1022 	struct smb2_hdr hdr;
1023 	__le16	StructureSize;  /* Must be 9 */
1024 	__le16	OutputBufferOffset;
1025 	__le32	OutputBufferLength;
1026 	__u8	Buffer[]; /* array of file notify structs */
1027 } __packed;
1028 
1029 /*
1030  * SMB2_SERVER_TO_CLIENT_NOTIFICATION: See MS-SMB2 section 2.2.44
1031  */
1032 
1033 #define SMB2_NOTIFY_SESSION_CLOSED	0x0000
1034 
1035 struct smb2_server_client_notification {
1036 	struct smb2_hdr hdr;
1037 	__le16	StructureSize;
1038 	__u16	Reserved; /* MBZ */
1039 	__le32	NotificationType;
1040 	__u8	NotificationBuffer[4]; /* MBZ */
1041 } __packed;
1042 
1043 /*
1044  * SMB2_CREATE  See MS-SMB2 section 2.2.13
1045  */
1046 /* Oplock levels */
1047 #define SMB2_OPLOCK_LEVEL_NONE		0x00
1048 #define SMB2_OPLOCK_LEVEL_II		0x01
1049 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE	0x08
1050 #define SMB2_OPLOCK_LEVEL_BATCH		0x09
1051 #define SMB2_OPLOCK_LEVEL_LEASE		0xFF
1052 /* Non-spec internal type */
1053 #define SMB2_OPLOCK_LEVEL_NOCHANGE	0x99
1054 
1055 /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
1056 #define IL_ANONYMOUS		cpu_to_le32(0x00000000)
1057 #define IL_IDENTIFICATION	cpu_to_le32(0x00000001)
1058 #define IL_IMPERSONATION	cpu_to_le32(0x00000002)
1059 #define IL_DELEGATE		cpu_to_le32(0x00000003)
1060 
1061 /* Desired Access Flags */
1062 #define FILE_READ_DATA_LE		cpu_to_le32(0x00000001)
1063 #define FILE_LIST_DIRECTORY_LE		cpu_to_le32(0x00000001)
1064 #define FILE_WRITE_DATA_LE		cpu_to_le32(0x00000002)
1065 #define FILE_APPEND_DATA_LE		cpu_to_le32(0x00000004)
1066 #define FILE_ADD_SUBDIRECTORY_LE	cpu_to_le32(0x00000004)
1067 #define FILE_READ_EA_LE			cpu_to_le32(0x00000008)
1068 #define FILE_WRITE_EA_LE		cpu_to_le32(0x00000010)
1069 #define FILE_EXECUTE_LE			cpu_to_le32(0x00000020)
1070 #define FILE_DELETE_CHILD_LE		cpu_to_le32(0x00000040)
1071 #define FILE_READ_ATTRIBUTES_LE		cpu_to_le32(0x00000080)
1072 #define FILE_WRITE_ATTRIBUTES_LE	cpu_to_le32(0x00000100)
1073 #define FILE_DELETE_LE			cpu_to_le32(0x00010000)
1074 #define FILE_READ_CONTROL_LE		cpu_to_le32(0x00020000)
1075 #define FILE_WRITE_DAC_LE		cpu_to_le32(0x00040000)
1076 #define FILE_WRITE_OWNER_LE		cpu_to_le32(0x00080000)
1077 #define FILE_SYNCHRONIZE_LE		cpu_to_le32(0x00100000)
1078 #define FILE_ACCESS_SYSTEM_SECURITY_LE	cpu_to_le32(0x01000000)
1079 #define FILE_MAXIMAL_ACCESS_LE		cpu_to_le32(0x02000000)
1080 #define FILE_GENERIC_ALL_LE		cpu_to_le32(0x10000000)
1081 #define FILE_GENERIC_EXECUTE_LE		cpu_to_le32(0x20000000)
1082 #define FILE_GENERIC_WRITE_LE		cpu_to_le32(0x40000000)
1083 #define FILE_GENERIC_READ_LE		cpu_to_le32(0x80000000)
1084 #define DESIRED_ACCESS_MASK             cpu_to_le32(0xF21F01FF)
1085 
1086 
1087 #define FILE_READ_DESIRED_ACCESS_LE     (FILE_READ_DATA_LE        |	\
1088 					 FILE_READ_EA_LE          |     \
1089 					 FILE_GENERIC_READ_LE)
1090 #define FILE_WRITE_DESIRE_ACCESS_LE     (FILE_WRITE_DATA_LE       |	\
1091 					 FILE_APPEND_DATA_LE      |	\
1092 					 FILE_WRITE_EA_LE         |	\
1093 					 FILE_WRITE_ATTRIBUTES_LE |	\
1094 					 FILE_GENERIC_WRITE_LE)
1095 
1096 /* ShareAccess Flags */
1097 #define FILE_SHARE_READ_LE		cpu_to_le32(0x00000001)
1098 #define FILE_SHARE_WRITE_LE		cpu_to_le32(0x00000002)
1099 #define FILE_SHARE_DELETE_LE		cpu_to_le32(0x00000004)
1100 #define FILE_SHARE_ALL_LE		cpu_to_le32(0x00000007)
1101 
1102 /* CreateDisposition Flags */
1103 #define FILE_SUPERSEDE_LE		cpu_to_le32(0x00000000)
1104 #define FILE_OPEN_LE			cpu_to_le32(0x00000001)
1105 #define FILE_CREATE_LE			cpu_to_le32(0x00000002)
1106 #define	FILE_OPEN_IF_LE			cpu_to_le32(0x00000003)
1107 #define FILE_OVERWRITE_LE		cpu_to_le32(0x00000004)
1108 #define FILE_OVERWRITE_IF_LE		cpu_to_le32(0x00000005)
1109 #define FILE_CREATE_MASK_LE             cpu_to_le32(0x00000007)
1110 
1111 /* CreateOptions Flags */
1112 #define FILE_DIRECTORY_FILE_LE		cpu_to_le32(0x00000001)
1113 /* same as #define CREATE_NOT_FILE_LE	cpu_to_le32(0x00000001) */
1114 #define FILE_WRITE_THROUGH_LE		cpu_to_le32(0x00000002)
1115 #define FILE_SEQUENTIAL_ONLY_LE		cpu_to_le32(0x00000004)
1116 #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
1117 /* FILE_SYNCHRONOUS_IO_ALERT_LE		cpu_to_le32(0x00000010) should be zero, ignored */
1118 /* FILE_SYNCHRONOUS_IO_NONALERT		cpu_to_le32(0x00000020) should be zero, ignored */
1119 #define FILE_NON_DIRECTORY_FILE_LE	cpu_to_le32(0x00000040)
1120 #define FILE_COMPLETE_IF_OPLOCKED_LE	cpu_to_le32(0x00000100)
1121 #define FILE_NO_EA_KNOWLEDGE_LE		cpu_to_le32(0x00000200)
1122 /* FILE_OPEN_REMOTE_INSTANCE		cpu_to_le32(0x00000400) should be zero, ignored */
1123 #define FILE_RANDOM_ACCESS_LE		cpu_to_le32(0x00000800)
1124 #define FILE_DELETE_ON_CLOSE_LE		cpu_to_le32(0x00001000) /* MBZ */
1125 #define FILE_OPEN_BY_FILE_ID_LE		cpu_to_le32(0x00002000)
1126 #define FILE_OPEN_FOR_BACKUP_INTENT_LE	cpu_to_le32(0x00004000)
1127 #define FILE_NO_COMPRESSION_LE		cpu_to_le32(0x00008000)
1128 /* FILE_OPEN_REQUIRING_OPLOCK		cpu_to_le32(0x00010000) should be zero, ignored */
1129 /* FILE_DISALLOW_EXCLUSIVE		cpu_to_le32(0x00020000) should be zero, ignored */
1130 /* FILE_RESERVE_OPFILTER		cpu_to_le32(0x00100000) MBZ */
1131 #define FILE_OPEN_REPARSE_POINT_LE	cpu_to_le32(0x00200000)
1132 #define FILE_OPEN_NO_RECALL_LE		cpu_to_le32(0x00400000)
1133 /* #define FILE_OPEN_FOR_FREE_SPACE_QUERY cpu_to_le32(0x00800000) should be zero, ignored */
1134 #define CREATE_OPTIONS_MASK_LE          cpu_to_le32(0x00FFFFFF)
1135 
1136 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
1137 			| FILE_READ_ATTRIBUTES_LE)
1138 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
1139 			| FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
1140 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
1141 
1142 /* Create Context Values */
1143 #define SMB2_CREATE_EA_BUFFER			"ExtA" /* extended attributes */
1144 #define SMB2_CREATE_SD_BUFFER			"SecD" /* security descriptor */
1145 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST	"DHnQ"
1146 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT	"DHnC"
1147 #define SMB2_CREATE_ALLOCATION_SIZE		"AlSi"
1148 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
1149 #define SMB2_CREATE_TIMEWARP_REQUEST		"TWrp"
1150 #define SMB2_CREATE_QUERY_ON_DISK_ID		"QFid"
1151 #define SMB2_CREATE_REQUEST_LEASE		"RqLs"
1152 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2	"DH2Q"
1153 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2	"DH2C"
1154 #define SMB2_CREATE_TAG_POSIX		"\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
1155 #define SMB2_CREATE_APP_INSTANCE_ID	"\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
1156 #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
1157 #define SVHDX_OPEN_DEVICE_CONTEXT	"\x9C\xCB\xCF\x9E\x04\xC1\xE6\x43\x98\x0E\x15\x8D\xA1\xF6\xEC\x83"
1158 #define SMB2_CREATE_TAG_AAPL			"AAPL"
1159 
1160 /* Flag (SMB3 open response) values */
1161 #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
1162 
1163 struct create_context {
1164 	/* New members must be added within the struct_group() macro below. */
1165 	__struct_group(create_context_hdr, hdr, __packed,
1166 		__le32 Next;
1167 		__le16 NameOffset;
1168 		__le16 NameLength;
1169 		__le16 Reserved;
1170 		__le16 DataOffset;
1171 		__le32 DataLength;
1172 	);
1173 	__u8 Buffer[];
1174 } __packed;
1175 static_assert(offsetof(struct create_context, Buffer) == sizeof(struct create_context_hdr),
1176 	      "struct member likely outside of __struct_group()");
1177 
1178 struct smb2_create_req {
1179 	struct smb2_hdr hdr;
1180 	__le16 StructureSize;	/* Must be 57 */
1181 	__u8   SecurityFlags;
1182 	__u8   RequestedOplockLevel;
1183 	__le32 ImpersonationLevel;
1184 	__le64 SmbCreateFlags;
1185 	__le64 Reserved;
1186 	__le32 DesiredAccess;
1187 	__le32 FileAttributes;
1188 	__le32 ShareAccess;
1189 	__le32 CreateDisposition;
1190 	__le32 CreateOptions;
1191 	__le16 NameOffset;
1192 	__le16 NameLength;
1193 	__le32 CreateContextsOffset;
1194 	__le32 CreateContextsLength;
1195 	__u8   Buffer[];
1196 } __packed;
1197 
1198 struct smb2_create_rsp {
1199 	struct smb2_hdr hdr;
1200 	__le16 StructureSize;	/* Must be 89 */
1201 	__u8   OplockLevel;
1202 	__u8   Flags;  /* 0x01 if reparse point */
1203 	__le32 CreateAction;
1204 	__le64 CreationTime;
1205 	__le64 LastAccessTime;
1206 	__le64 LastWriteTime;
1207 	__le64 ChangeTime;
1208 	__le64 AllocationSize;
1209 	__le64 EndofFile;
1210 	__le32 FileAttributes;
1211 	__le32 Reserved2;
1212 	__u64  PersistentFileId;
1213 	__u64  VolatileFileId;
1214 	__le32 CreateContextsOffset;
1215 	__le32 CreateContextsLength;
1216 	__u8   Buffer[];
1217 } __packed;
1218 
1219 struct create_posix {
1220 	struct create_context_hdr ccontext;
1221 	__u8    Name[16];
1222 	__le32  Mode;
1223 	__u32   Reserved;
1224 } __packed;
1225 
1226 /* See MS-SMB2 2.2.13.2.3 and MS-SMB2 2.2.13.2.4 */
1227 typedef struct {
1228 	struct create_context_hdr ccontext;
1229 	__u8   Name[8];
1230 	union {
1231 		__u8  Reserved[16];
1232 		struct {
1233 			__u64 PersistentFileId;
1234 			__u64 VolatileFileId;
1235 		} Fid;
1236 	} Data;
1237 } __packed create_durable_req_t, create_durable_reconn_t;
1238 
1239 /* See MS-SMB2 2.2.13.2.5 */
1240 struct create_mxac_req {
1241 	struct create_context_hdr ccontext;
1242 	__u8   Name[8];
1243 	__le64 Timestamp;
1244 } __packed;
1245 
1246 /*
1247  * Flags
1248  * See MS-SMB2 2.2.13.2.11
1249  *     MS-SMB2 2.2.13.2.12
1250  *     MS-SMB2 2.2.14.2.12
1251  */
1252 #define SMB2_DHANDLE_FLAG_PERSISTENT	0x00000002
1253 
1254 /* See MS-SMB2 2.2.13.2.11 */
1255 struct durable_context_v2_req {
1256 	__le32 Timeout;
1257 	__le32 Flags; /* see SMB2_DHANDLE_FLAG_PERSISTENT */
1258 	__u64 Reserved;
1259 	__u8 CreateGuid[16];
1260 } __packed;
1261 
1262 struct create_durable_req_v2 {
1263 	struct create_context_hdr ccontext;
1264 	__u8   Name[8];
1265 	struct durable_context_v2_req dcontext;
1266 } __packed;
1267 
1268 /* See MS-SMB2 2.2.13.2.12 */
1269 struct durable_reconnect_context_v2 {
1270 	struct {
1271 		__u64 PersistentFileId;
1272 		__u64 VolatileFileId;
1273 	} Fid;
1274 	__u8 CreateGuid[16];
1275 	__le32 Flags; /* see SMB2_DHANDLE_FLAG_PERSISTENT */
1276 } __packed;
1277 
1278 struct create_durable_handle_reconnect_v2 {
1279 	struct create_context_hdr ccontext;
1280 	__u8   Name[8];
1281 	struct durable_reconnect_context_v2 dcontext;
1282 	__u8 Pad[4];
1283 } __packed;
1284 
1285 /* See MS-SMB2 2.2.14.2.12 */
1286 struct durable_context_v2_rsp {
1287 	__le32 Timeout;
1288 	__le32 Flags; /* see SMB2_DHANDLE_FLAG_PERSISTENT */
1289 } __packed;
1290 
1291 struct create_durable_rsp_v2 {
1292 	struct create_context_hdr ccontext;
1293 	__u8   Name[8];
1294 	struct durable_context_v2_rsp dcontext;
1295 } __packed;
1296 
1297 /* See MS-SMB2 2.2.14.2.5 */
1298 struct create_mxac_rsp {
1299 	struct create_context_hdr ccontext;
1300 	__u8   Name[8];
1301 	__le32 QueryStatus;
1302 	__le32 MaximalAccess;
1303 } __packed;
1304 
1305 #define SMB2_LEASE_NONE_LE			cpu_to_le32(0x00)
1306 #define SMB2_LEASE_READ_CACHING_LE		cpu_to_le32(0x01)
1307 #define SMB2_LEASE_HANDLE_CACHING_LE		cpu_to_le32(0x02)
1308 #define SMB2_LEASE_WRITE_CACHING_LE		cpu_to_le32(0x04)
1309 
1310 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE	cpu_to_le32(0x02)
1311 #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE	cpu_to_le32(0x04)
1312 
1313 #define SMB2_LEASE_KEY_SIZE			16
1314 
1315 /* See MS-SMB2 2.2.13.2.8 */
1316 struct lease_context {
1317 	__u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1318 	__le32 LeaseState;
1319 	__le32 LeaseFlags;
1320 	__le64 LeaseDuration;
1321 } __packed;
1322 
1323 /* See MS-SMB2 2.2.13.2.10 */
1324 struct lease_context_v2 {
1325 	__u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1326 	__le32 LeaseState;
1327 	__le32 LeaseFlags;
1328 	__le64 LeaseDuration;
1329 	__u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
1330 	__le16 Epoch;
1331 	__le16 Reserved;
1332 } __packed;
1333 
1334 struct create_lease {
1335 	struct create_context_hdr ccontext;
1336 	__u8   Name[8];
1337 	struct lease_context lcontext;
1338 } __packed;
1339 
1340 struct create_lease_v2 {
1341 	struct create_context_hdr ccontext;
1342 	__u8   Name[8];
1343 	struct lease_context_v2 lcontext;
1344 	__u8   Pad[4];
1345 } __packed;
1346 
1347 /* See MS-SMB2 2.2.14.2.9 */
1348 struct create_disk_id_rsp {
1349 	struct create_context_hdr ccontext;
1350 	__u8   Name[8];
1351 	__le64 DiskFileId;
1352 	__le64 VolumeId;
1353 	__u8  Reserved[16];
1354 } __packed;
1355 
1356 /* See MS-SMB2 2.2.13.2.13 */
1357 struct create_app_inst_id {
1358 	struct create_context_hdr ccontext;
1359 	__u8 Name[16];
1360 	__le32 StructureSize; /* Must be 20 */
1361 	__u16 Reserved;
1362 	__u8 AppInstanceId[16];
1363 } __packed;
1364 
1365 /* See MS-SMB2 2.2.13.2.15 */
1366 struct create_app_inst_id_vers {
1367 	struct create_context_hdr ccontext;
1368 	__u8 Name[16];
1369 	__le32 StructureSize; /* Must be 24 */
1370 	__u16 Reserved;
1371 	__u32 Padding;
1372 	__le64 AppInstanceVersionHigh;
1373 	__le64 AppInstanceVersionLow;
1374 } __packed;
1375 
1376 /* See MS-SMB2 2.2.31 and 2.2.32 */
1377 struct smb2_ioctl_req {
1378 	struct smb2_hdr hdr;
1379 	__le16 StructureSize; /* Must be 57 */
1380 	__le16 Reserved; /* offset from start of SMB2 header to write data */
1381 	__le32 CtlCode;
1382 	__u64  PersistentFileId;
1383 	__u64  VolatileFileId;
1384 	__le32 InputOffset; /* Reserved MBZ */
1385 	__le32 InputCount;
1386 	__le32 MaxInputResponse;
1387 	__le32 OutputOffset;
1388 	__le32 OutputCount;
1389 	__le32 MaxOutputResponse;
1390 	__le32 Flags;
1391 	__le32 Reserved2;
1392 	__u8   Buffer[];
1393 } __packed;
1394 
1395 /* See MS-SMB2 2.2.31.1.1 */
1396 struct srv_copychunk {
1397 	__le64 SourceOffset;
1398 	__le64 TargetOffset;
1399 	__le32 Length;
1400 	__le32 Reserved;
1401 } __packed;
1402 
1403 #define COPY_CHUNK_RES_KEY_SIZE	24
1404 
1405 /* See MS-SMB2 2.2.31.1 */
1406 /* this goes in the ioctl buffer when doing a copychunk request */
1407 struct copychunk_ioctl_req {
1408 	union {
1409 		char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
1410 		__le64 SourceKeyU64[3];
1411 	};
1412 	__le32 ChunkCount;
1413 	__le32 Reserved;
1414 	struct srv_copychunk Chunks[] __counted_by_le(ChunkCount);
1415 } __packed;
1416 
1417 /* See MS-SMB2 2.2.32.1 */
1418 struct copychunk_ioctl_rsp {
1419 	__le32 ChunksWritten;
1420 	__le32 ChunkBytesWritten;
1421 	__le32 TotalBytesWritten;
1422 } __packed;
1423 
1424 /* See MS-SMB2 2.2.32.3 */
1425 struct resume_key_ioctl_rsp {
1426 	union {
1427 		char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
1428 		__u64 ResumeKeyU64[3];
1429 	};
1430 	__le32	ContextLength;	/* MBZ */
1431 	char	Context[];	/* ignored, Windows sets to 4 bytes of zero */
1432 } __packed;
1433 
1434 struct smb2_ioctl_rsp {
1435 	struct smb2_hdr hdr;
1436 	__le16 StructureSize; /* Must be 49 */
1437 	__le16 Reserved;
1438 	__le32 CtlCode;
1439 	__u64  PersistentFileId;
1440 	__u64  VolatileFileId;
1441 	__le32 InputOffset; /* Reserved MBZ */
1442 	__le32 InputCount;
1443 	__le32 OutputOffset;
1444 	__le32 OutputCount;
1445 	__le32 Flags;
1446 	__le32 Reserved2;
1447 	__u8   Buffer[];
1448 } __packed;
1449 
1450 /* See MS-SMB2 2.2.32.5.1.1 */
1451 struct smb_sockaddr_in {
1452 	__be16 Port;
1453 	__be32 IPv4Address;
1454 	__u8   Reserved[8];
1455 } __packed;
1456 
1457 /* See MS-SMB2 2.2.32.5.1.2 */
1458 struct smb_sockaddr_in6 {
1459 	__be16 Port;
1460 	__be32 FlowInfo;
1461 	__u8   IPv6Address[16];
1462 	__be32 ScopeId;
1463 } __packed;
1464 
1465 /* See MS-SMB2 2.2.32.5 and MS-SMB2 2.2.32.5.1 */
1466 #define RSS_CAPABLE	cpu_to_le32(0x00000001)
1467 #define RDMA_CAPABLE	cpu_to_le32(0x00000002)
1468 #define INTERNETWORK	cpu_to_le16(0x0002)
1469 #define INTERNETWORKV6	cpu_to_le16(0x0017)
1470 struct network_interface_info_ioctl_rsp {
1471 	__le32 Next; /* next interface. zero if this is last one */
1472 	__le32 IfIndex;
1473 	__le32 Capability; /* RSS or RDMA Capable */
1474 	__le32 Reserved;
1475 	__le64 LinkSpeed;
1476 	union {
1477 		char	SockAddr_Storage[128];
1478 		struct {
1479 			__le16 Family;
1480 			__u8 Buffer[126];
1481 		};
1482 	};
1483 } __packed;
1484 
1485 /* Integrity ChecksumAlgorithm choices for above */
1486 #define	CHECKSUM_TYPE_NONE	0x0000
1487 #define	CHECKSUM_TYPE_CRC64	0x0002
1488 #define	CHECKSUM_TYPE_UNCHANGED	0xFFFF	/* set only */
1489 
1490 /* Integrity flags for above */
1491 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF	0x00000001
1492 
1493 struct validate_negotiate_info_req {
1494 	__le32 Capabilities;
1495 	__u8   Guid[SMB2_CLIENT_GUID_SIZE];
1496 	__le16 SecurityMode;
1497 	__le16 DialectCount;
1498 	__le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
1499 } __packed;
1500 
1501 struct validate_negotiate_info_rsp {
1502 	__le32 Capabilities;
1503 	__u8   Guid[SMB2_CLIENT_GUID_SIZE];
1504 	__le16 SecurityMode;
1505 	__le16 Dialect; /* Dialect in use for the connection */
1506 } __packed;
1507 
1508 
1509 /* Possible InfoType values */
1510 #define SMB2_O_INFO_FILE	0x01
1511 #define SMB2_O_INFO_FILESYSTEM	0x02
1512 #define SMB2_O_INFO_SECURITY	0x03
1513 #define SMB2_O_INFO_QUOTA	0x04
1514 
1515 /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */
1516 
1517 /* List of QUERY INFO levels (those also valid for QUERY_DIR are noted below */
1518 #define FILE_DIRECTORY_INFORMATION	1	/* also for QUERY_DIR */
1519 #define FILE_FULL_DIRECTORY_INFORMATION 2	/* also for QUERY_DIR */
1520 #define FILE_BOTH_DIRECTORY_INFORMATION 3	/* also for QUERY_DIR */
1521 #define FILE_BASIC_INFORMATION		4
1522 #define FILE_STANDARD_INFORMATION	5
1523 #define FILE_INTERNAL_INFORMATION	6
1524 #define FILE_EA_INFORMATION	        7
1525 #define FILE_ACCESS_INFORMATION		8
1526 #define FILE_NAME_INFORMATION		9
1527 #define FILE_RENAME_INFORMATION		10
1528 #define FILE_LINK_INFORMATION		11
1529 #define FILE_NAMES_INFORMATION		12	/* also for QUERY_DIR */
1530 #define FILE_DISPOSITION_INFORMATION	13
1531 #define FILE_POSITION_INFORMATION	14
1532 #define FILE_FULL_EA_INFORMATION	15
1533 #define FILE_MODE_INFORMATION		16
1534 #define FILE_ALIGNMENT_INFORMATION	17
1535 #define FILE_ALL_INFORMATION		18
1536 #define FILE_ALLOCATION_INFORMATION	19
1537 #define FILE_END_OF_FILE_INFORMATION	20
1538 #define FILE_ALTERNATE_NAME_INFORMATION 21
1539 #define FILE_STREAM_INFORMATION		22
1540 #define FILE_PIPE_INFORMATION		23
1541 #define FILE_PIPE_LOCAL_INFORMATION	24
1542 #define FILE_PIPE_REMOTE_INFORMATION	25
1543 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1544 #define FILE_MAILSLOT_SET_INFORMATION	27
1545 #define FILE_COMPRESSION_INFORMATION	28
1546 #define FILE_OBJECT_ID_INFORMATION	29
1547 /* Number 30 not defined in documents */
1548 #define FILE_MOVE_CLUSTER_INFORMATION	31
1549 #define FILE_QUOTA_INFORMATION		32
1550 #define FILE_REPARSE_POINT_INFORMATION	33
1551 #define FILE_NETWORK_OPEN_INFORMATION	34
1552 #define FILE_ATTRIBUTE_TAG_INFORMATION	35
1553 #define FILE_TRACKING_INFORMATION	36
1554 #define FILEID_BOTH_DIRECTORY_INFORMATION 37	/* also for QUERY_DIR */
1555 #define FILEID_FULL_DIRECTORY_INFORMATION 38	/* also for QUERY_DIR */
1556 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1557 #define FILE_SHORT_NAME_INFORMATION	40
1558 #define FILE_SFIO_RESERVE_INFORMATION	44
1559 #define FILE_SFIO_VOLUME_INFORMATION	45
1560 #define FILE_HARD_LINK_INFORMATION	46
1561 #define FILE_NORMALIZED_NAME_INFORMATION 48
1562 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1563 #define FILE_STANDARD_LINK_INFORMATION	54
1564 #define FILE_ID_INFORMATION		59
1565 #define FILE_ID_EXTD_DIRECTORY_INFORMATION 60	/* also for QUERY_DIR */
1566 #define FileId64ExtdDirectoryInformation 78	/* also for QUERY_DIR */
1567 #define FileId64ExtdBothDirectoryInformation 79 /* also for QUERY_DIR */
1568 #define FileIdAllExtdDirectoryInformation 80	/* also for QUERY_DIR */
1569 #define FileIdAllExtdBothDirectoryInformation 81 /* also for QUERY_DIR */
1570 /* Used for Query Info and Find File POSIX Info for SMB3.1.1 and SMB1 */
1571 #define SMB_FIND_FILE_POSIX_INFO	0x064
1572 
1573 /* Security info type additionalinfo flags. */
1574 #define OWNER_SECINFO   0x00000001
1575 #define GROUP_SECINFO   0x00000002
1576 #define DACL_SECINFO   0x00000004
1577 #define SACL_SECINFO   0x00000008
1578 #define LABEL_SECINFO   0x00000010
1579 #define ATTRIBUTE_SECINFO   0x00000020
1580 #define SCOPE_SECINFO   0x00000040
1581 #define BACKUP_SECINFO   0x00010000
1582 #define UNPROTECTED_SACL_SECINFO   0x10000000
1583 #define UNPROTECTED_DACL_SECINFO   0x20000000
1584 #define PROTECTED_SACL_SECINFO   0x40000000
1585 #define PROTECTED_DACL_SECINFO   0x80000000
1586 
1587 /* Flags used for FileFullEAinfo */
1588 #define SL_RESTART_SCAN		0x00000001
1589 #define SL_RETURN_SINGLE_ENTRY	0x00000002
1590 #define SL_INDEX_SPECIFIED	0x00000004
1591 
1592 struct smb2_query_info_req {
1593 	struct smb2_hdr hdr;
1594 	__le16 StructureSize; /* Must be 41 */
1595 	__u8   InfoType;
1596 	__u8   FileInfoClass;
1597 	__le32 OutputBufferLength;
1598 	__le16 InputBufferOffset;
1599 	__u16  Reserved;
1600 	__le32 InputBufferLength;
1601 	__le32 AdditionalInformation;
1602 	__le32 Flags;
1603 	__u64  PersistentFileId;
1604 	__u64  VolatileFileId;
1605 	__u8   Buffer[];
1606 } __packed;
1607 
1608 struct smb2_query_info_rsp {
1609 	struct smb2_hdr hdr;
1610 	__le16 StructureSize; /* Must be 9 */
1611 	__le16 OutputBufferOffset;
1612 	__le32 OutputBufferLength;
1613 	__u8   Buffer[];
1614 } __packed;
1615 
1616 /* Level 100 query info */
1617 struct smb311_posix_qinfo {
1618 	__le64 CreationTime;
1619 	__le64 LastAccessTime;
1620 	__le64 LastWriteTime;
1621 	__le64 ChangeTime;
1622 	__le64 EndOfFile;
1623 	__le64 AllocationSize;
1624 	__le32 DosAttributes;
1625 	__le64 Inode;
1626 	__le32 DeviceId;
1627 	__le32 Zero;
1628 	/* beginning of POSIX Create Context Response */
1629 	__le32 HardLinks;
1630 	__le32 ReparseTag;
1631 	__le32 Mode;
1632 	u8     Sids[];
1633 	/*
1634 	 * var sized owner SID
1635 	 * var sized group SID
1636 	 * le32 filenamelength
1637 	 * u8  filename[]
1638 	 */
1639 } __packed;
1640 
1641 /* See MS-SMB2 2.2.23 through 2.2.25 */
1642 struct smb2_oplock_break {
1643 	struct smb2_hdr hdr;
1644 	__le16 StructureSize; /* Must be 24 */
1645 	__u8   OplockLevel;
1646 	__u8   Reserved;
1647 	__le32 Reserved2;
1648 	__u64  PersistentFid;
1649 	__u64  VolatileFid;
1650 } __packed;
1651 
1652 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1653 
1654 struct smb2_lease_break {
1655 	struct smb2_hdr hdr;
1656 	__le16 StructureSize; /* Must be 44 */
1657 	__le16 Epoch;
1658 	__le32 Flags;
1659 	__u8   LeaseKey[16];
1660 	__le32 CurrentLeaseState;
1661 	__le32 NewLeaseState;
1662 	__le32 BreakReason;
1663 	__le32 AccessMaskHint;
1664 	__le32 ShareMaskHint;
1665 } __packed;
1666 
1667 struct smb2_lease_ack {
1668 	struct smb2_hdr hdr;
1669 	__le16 StructureSize; /* Must be 36 */
1670 	__le16 Reserved;
1671 	__le32 Flags;
1672 	__u8   LeaseKey[16];
1673 	__le32 LeaseState;
1674 	__le64 LeaseDuration;
1675 } __packed;
1676 
1677 #define OP_BREAK_STRUCT_SIZE_20		24
1678 #define OP_BREAK_STRUCT_SIZE_21		36
1679 
1680 /*
1681  * See MS-SMB2 2.2.13.1.1
1682  *     MS-SMB 2.2.1.4.1
1683  * These are the file access permission bits defined in CIFS for the
1684  * NTCreateAndX as well as the level 0x107
1685  * TRANS2_QUERY_PATH_INFORMATION API.  The level 0x107, SMB_QUERY_FILE_ALL_INFO
1686  * responds with the AccessFlags.
1687  * The AccessFlags specifies the access permissions a caller has to the
1688  * file and can have any suitable combination of the following values:
1689  */
1690 #define FILE_READ_DATA        0x00000001  /* Data can be read from the file   */
1691 					  /* or directory child entries can   */
1692 					  /* be listed together with the      */
1693 					  /* associated child attributes      */
1694 					  /* (so the FILE_READ_ATTRIBUTES on  */
1695 					  /* the child entry is not needed)   */
1696 #define FILE_WRITE_DATA       0x00000002  /* Data can be written to the file  */
1697 					  /* or new file can be created in    */
1698 					  /* the directory                    */
1699 #define FILE_APPEND_DATA      0x00000004  /* Data can be appended to the file */
1700 					  /* (for non-local files over SMB it */
1701 					  /* is same as FILE_WRITE_DATA)      */
1702 					  /* or new subdirectory can be       */
1703 					  /* created in the directory         */
1704 #define FILE_READ_EA          0x00000008  /* Extended attributes associated   */
1705 					  /* with the file can be read        */
1706 #define FILE_WRITE_EA         0x00000010  /* Extended attributes associated   */
1707 					  /* with the file can be written     */
1708 #define FILE_EXECUTE          0x00000020  /*Data can be read into memory from */
1709 					  /* the file using system paging I/O */
1710 					  /* for executing the file / script  */
1711 					  /* or right to traverse directory   */
1712 					  /* (but by default all users have   */
1713 					  /* directory bypass traverse        */
1714 					  /* privilege and do not need this   */
1715 					  /* permission on directories at all)*/
1716 #define FILE_DELETE_CHILD     0x00000040  /* Child entry can be deleted from  */
1717 					  /* the directory (so the DELETE on  */
1718 					  /* the child entry is not needed)   */
1719 #define FILE_READ_ATTRIBUTES  0x00000080  /* Attributes associated with the   */
1720 					  /* file or directory can be read    */
1721 #define FILE_WRITE_ATTRIBUTES 0x00000100  /* Attributes associated with the   */
1722 					  /* file or directory can be written */
1723 #define DELETE                0x00010000  /* The file or dir can be deleted   */
1724 #define READ_CONTROL          0x00020000  /* The discretionary access control */
1725 					  /* list and ownership associated    */
1726 					  /* with the file or dir can be read */
1727 #define WRITE_DAC             0x00040000  /* The discretionary access control */
1728 					  /* list associated with the file or */
1729 					  /* directory can be written         */
1730 #define WRITE_OWNER           0x00080000  /* Ownership information associated */
1731 					  /* with the file/dir can be written */
1732 #define SYNCHRONIZE           0x00100000  /* The file handle can waited on to */
1733 					  /* synchronize with the completion  */
1734 					  /* of an input/output request       */
1735 #define SYSTEM_SECURITY       0x01000000  /* The system access control list   */
1736 					  /* associated with the file or      */
1737 					  /* directory can be read or written */
1738 					  /* (cannot be in DACL, can in SACL) */
1739 #define MAXIMUM_ALLOWED       0x02000000  /* Maximal subset of GENERIC_ALL    */
1740 					  /* permissions which can be granted */
1741 					  /* (cannot be in DACL nor SACL)     */
1742 #define GENERIC_ALL           0x10000000  /* Same as: GENERIC_EXECUTE |       */
1743 					  /*          GENERIC_WRITE |         */
1744 					  /*          GENERIC_READ |          */
1745 					  /*          FILE_DELETE_CHILD |     */
1746 					  /*          DELETE |                */
1747 					  /*          WRITE_DAC |             */
1748 					  /*          WRITE_OWNER             */
1749 					  /* So GENERIC_ALL contains all bits */
1750 					  /* mentioned above except these two */
1751 					  /* SYSTEM_SECURITY  MAXIMUM_ALLOWED */
1752 #define GENERIC_EXECUTE       0x20000000  /* Same as: FILE_EXECUTE |          */
1753 					  /*          FILE_READ_ATTRIBUTES |  */
1754 					  /*          READ_CONTROL |          */
1755 					  /*          SYNCHRONIZE             */
1756 #define GENERIC_WRITE         0x40000000  /* Same as: FILE_WRITE_DATA |       */
1757 					  /*          FILE_APPEND_DATA |      */
1758 					  /*          FILE_WRITE_EA |         */
1759 					  /*          FILE_WRITE_ATTRIBUTES | */
1760 					  /*          READ_CONTROL |          */
1761 					  /*          SYNCHRONIZE             */
1762 #define GENERIC_READ          0x80000000  /* Same as: FILE_READ_DATA |        */
1763 					  /*          FILE_READ_EA |          */
1764 					  /*          FILE_READ_ATTRIBUTES |  */
1765 					  /*          READ_CONTROL |          */
1766 					  /*          SYNCHRONIZE             */
1767 
1768 /* Combinations of file access permission bits */
1769 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES)
1770 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
1771 			| FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
1772 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
1773 #define SET_FILE_EXEC_RIGHTS (FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE \
1774 				| FILE_READ_ATTRIBUTES \
1775 				| FILE_WRITE_ATTRIBUTES \
1776 				| DELETE | READ_CONTROL | WRITE_DAC \
1777 				| WRITE_OWNER | SYNCHRONIZE)
1778 #define SET_MINIMUM_RIGHTS (FILE_READ_EA | FILE_READ_ATTRIBUTES \
1779 				| READ_CONTROL | SYNCHRONIZE)
1780 
1781 #endif				/* _COMMON_SMB2PDU_H */
1782