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