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