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