1 /*
2  *   fs/cifs/smb2pdu.h
3  *
4  *   Copyright (c) International Business Machines  Corp., 2009, 2013
5  *                 Etersoft, 2012
6  *   Author(s): Steve French (sfrench@us.ibm.com)
7  *              Pavel Shilovsky (pshilovsky@samba.org) 2012
8  *
9  *   This library is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU Lesser General Public License as published
11  *   by the Free Software Foundation; either version 2.1 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This library is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
17  *   the GNU Lesser General Public License for more details.
18  *
19  *   You should have received a copy of the GNU Lesser General Public License
20  *   along with this library; if not, write to the Free Software
21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23 
24 #ifndef _SMB2PDU_H
25 #define _SMB2PDU_H
26 
27 #include <net/sock.h>
28 
29 /*
30  * Note that, due to trying to use names similar to the protocol specifications,
31  * there are many mixed case field names in the structures below.  Although
32  * this does not match typical Linux kernel style, it is necessary to be
33  * be able to match against the protocol specfication.
34  *
35  * SMB2 commands
36  * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
37  * (ie no useful data other than the SMB error code itself) and are marked such.
38  * Knowing this helps avoid response buffer allocations and copy in some cases.
39  */
40 
41 /* List of commands in host endian */
42 #define SMB2_NEGOTIATE_HE	0x0000
43 #define SMB2_SESSION_SETUP_HE	0x0001
44 #define SMB2_LOGOFF_HE		0x0002 /* trivial request/resp */
45 #define SMB2_TREE_CONNECT_HE	0x0003
46 #define SMB2_TREE_DISCONNECT_HE	0x0004 /* trivial req/resp */
47 #define SMB2_CREATE_HE		0x0005
48 #define SMB2_CLOSE_HE		0x0006
49 #define SMB2_FLUSH_HE		0x0007 /* trivial resp */
50 #define SMB2_READ_HE		0x0008
51 #define SMB2_WRITE_HE		0x0009
52 #define SMB2_LOCK_HE		0x000A
53 #define SMB2_IOCTL_HE		0x000B
54 #define SMB2_CANCEL_HE		0x000C
55 #define SMB2_ECHO_HE		0x000D
56 #define SMB2_QUERY_DIRECTORY_HE	0x000E
57 #define SMB2_CHANGE_NOTIFY_HE	0x000F
58 #define SMB2_QUERY_INFO_HE	0x0010
59 #define SMB2_SET_INFO_HE	0x0011
60 #define SMB2_OPLOCK_BREAK_HE	0x0012
61 
62 /* The same list in little endian */
63 #define SMB2_NEGOTIATE		cpu_to_le16(SMB2_NEGOTIATE_HE)
64 #define SMB2_SESSION_SETUP	cpu_to_le16(SMB2_SESSION_SETUP_HE)
65 #define SMB2_LOGOFF		cpu_to_le16(SMB2_LOGOFF_HE)
66 #define SMB2_TREE_CONNECT	cpu_to_le16(SMB2_TREE_CONNECT_HE)
67 #define SMB2_TREE_DISCONNECT	cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
68 #define SMB2_CREATE		cpu_to_le16(SMB2_CREATE_HE)
69 #define SMB2_CLOSE		cpu_to_le16(SMB2_CLOSE_HE)
70 #define SMB2_FLUSH		cpu_to_le16(SMB2_FLUSH_HE)
71 #define SMB2_READ		cpu_to_le16(SMB2_READ_HE)
72 #define SMB2_WRITE		cpu_to_le16(SMB2_WRITE_HE)
73 #define SMB2_LOCK		cpu_to_le16(SMB2_LOCK_HE)
74 #define SMB2_IOCTL		cpu_to_le16(SMB2_IOCTL_HE)
75 #define SMB2_CANCEL		cpu_to_le16(SMB2_CANCEL_HE)
76 #define SMB2_ECHO		cpu_to_le16(SMB2_ECHO_HE)
77 #define SMB2_QUERY_DIRECTORY	cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
78 #define SMB2_CHANGE_NOTIFY	cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
79 #define SMB2_QUERY_INFO		cpu_to_le16(SMB2_QUERY_INFO_HE)
80 #define SMB2_SET_INFO		cpu_to_le16(SMB2_SET_INFO_HE)
81 #define SMB2_OPLOCK_BREAK	cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
82 
83 #define SMB2_INTERNAL_CMD	cpu_to_le16(0xFFFF)
84 
85 #define NUMBER_OF_SMB2_COMMANDS	0x0013
86 
87 /* 4 len + 52 transform hdr + 64 hdr + 56 create rsp */
88 #define MAX_SMB2_HDR_SIZE 0x00b0
89 
90 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
91 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
92 
93 /*
94  * SMB2 Header Definition
95  *
96  * "MBZ" :  Must be Zero
97  * "BB"  :  BugBug, Something to check/review/analyze later
98  * "PDU" :  "Protocol Data Unit" (ie a network "frame")
99  *
100  */
101 
102 #define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
103 
104 struct smb2_sync_hdr {
105 	__le32 ProtocolId;	/* 0xFE 'S' 'M' 'B' */
106 	__le16 StructureSize;	/* 64 */
107 	__le16 CreditCharge;	/* MBZ */
108 	__le32 Status;		/* Error from server */
109 	__le16 Command;
110 	__le16 CreditRequest;  /* CreditResponse */
111 	__le32 Flags;
112 	__le32 NextCommand;
113 	__le64 MessageId;
114 	__le32 ProcessId;
115 	__u32  TreeId;		/* opaque - so do not make little endian */
116 	__u64  SessionId;	/* opaque - so do not make little endian */
117 	__u8   Signature[16];
118 } __packed;
119 
120 struct smb2_sync_pdu {
121 	struct smb2_sync_hdr sync_hdr;
122 	__le16 StructureSize2; /* size of wct area (varies, request specific) */
123 } __packed;
124 
125 #define SMB3_AES128CMM_NONCE 11
126 #define SMB3_AES128GCM_NONCE 12
127 
128 struct smb2_transform_hdr {
129 	__le32 ProtocolId;	/* 0xFD 'S' 'M' 'B' */
130 	__u8   Signature[16];
131 	__u8   Nonce[16];
132 	__le32 OriginalMessageSize;
133 	__u16  Reserved1;
134 	__le16 Flags; /* EncryptionAlgorithm */
135 	__u64  SessionId;
136 } __packed;
137 
138 /*
139  *	SMB2 flag definitions
140  */
141 #define SMB2_FLAGS_SERVER_TO_REDIR	cpu_to_le32(0x00000001)
142 #define SMB2_FLAGS_ASYNC_COMMAND	cpu_to_le32(0x00000002)
143 #define SMB2_FLAGS_RELATED_OPERATIONS	cpu_to_le32(0x00000004)
144 #define SMB2_FLAGS_SIGNED		cpu_to_le32(0x00000008)
145 #define SMB2_FLAGS_DFS_OPERATIONS	cpu_to_le32(0x10000000)
146 
147 /*
148  *	Definitions for SMB2 Protocol Data Units (network frames)
149  *
150  *  See MS-SMB2.PDF specification for protocol details.
151  *  The Naming convention is the lower case version of the SMB2
152  *  command code name for the struct. Note that structures must be packed.
153  *
154  */
155 
156 #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
157 
158 #define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
159 
160 struct smb2_err_rsp {
161 	struct smb2_sync_hdr sync_hdr;
162 	__le16 StructureSize;
163 	__le16 Reserved; /* MBZ */
164 	__le32 ByteCount;  /* even if zero, at least one byte follows */
165 	__u8   ErrorData[1];  /* variable length */
166 } __packed;
167 
168 struct smb2_symlink_err_rsp {
169 	__le32 SymLinkLength;
170 	__le32 SymLinkErrorTag;
171 	__le32 ReparseTag;
172 	__le16 ReparseDataLength;
173 	__le16 UnparsedPathLength;
174 	__le16 SubstituteNameOffset;
175 	__le16 SubstituteNameLength;
176 	__le16 PrintNameOffset;
177 	__le16 PrintNameLength;
178 	__le32 Flags;
179 	__u8  PathBuffer[0];
180 } __packed;
181 
182 /* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
183 struct smb2_error_context_rsp {
184 	__le32 ErrorDataLength;
185 	__le32 ErrorId;
186 	__u8  ErrorContextData; /* ErrorDataLength long array */
187 } __packed;
188 
189 /* Defines for Type field below (see MS-SMB2 2.2.2.2.2.1) */
190 #define MOVE_DST_IPADDR_V4	cpu_to_le32(0x00000001)
191 #define MOVE_DST_IPADDR_V6	cpu_to_le32(0x00000002)
192 
193 struct move_dst_ipaddr {
194 	__le32 Type;
195 	__u32  Reserved;
196 	__u8   address[16]; /* IPv4 followed by 12 bytes rsvd or IPv6 address */
197 } __packed;
198 
199 struct share_redirect_error_context_rsp {
200 	__le32 StructureSize;
201 	__le32 NotificationType;
202 	__le32 ResourceNameOffset;
203 	__le32 ResourceNameLength;
204 	__le16 Flags;
205 	__le16 TargetType;
206 	__le32 IPAddrCount;
207 	struct move_dst_ipaddr IpAddrMoveList[0];
208 	/* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
209 } __packed;
210 
211 #define SMB2_CLIENT_GUID_SIZE 16
212 
213 struct smb2_negotiate_req {
214 	struct smb2_sync_hdr sync_hdr;
215 	__le16 StructureSize; /* Must be 36 */
216 	__le16 DialectCount;
217 	__le16 SecurityMode;
218 	__le16 Reserved;	/* MBZ */
219 	__le32 Capabilities;
220 	__u8   ClientGUID[SMB2_CLIENT_GUID_SIZE];
221 	/* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
222 	__le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
223 	__le16 NegotiateContextCount;  /* SMB3.1.1 only. MBZ earlier */
224 	__le16 Reserved2;
225 	__le16 Dialects[1]; /* One dialect (vers=) at a time for now */
226 } __packed;
227 
228 /* Dialects */
229 #define SMB20_PROT_ID 0x0202
230 #define SMB21_PROT_ID 0x0210
231 #define SMB30_PROT_ID 0x0300
232 #define SMB302_PROT_ID 0x0302
233 #define SMB311_PROT_ID 0x0311
234 #define BAD_PROT_ID   0xFFFF
235 
236 /* SecurityMode flags */
237 #define	SMB2_NEGOTIATE_SIGNING_ENABLED	0x0001
238 #define SMB2_NEGOTIATE_SIGNING_REQUIRED	0x0002
239 #define SMB2_SEC_MODE_FLAGS_ALL		0x0003
240 
241 /* Capabilities flags */
242 #define SMB2_GLOBAL_CAP_DFS		0x00000001
243 #define SMB2_GLOBAL_CAP_LEASING		0x00000002 /* Resp only New to SMB2.1 */
244 #define SMB2_GLOBAL_CAP_LARGE_MTU	0X00000004 /* Resp only New to SMB2.1 */
245 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL	0x00000008 /* New to SMB3 */
246 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
247 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING  0x00000020 /* New to SMB3 */
248 #define SMB2_GLOBAL_CAP_ENCRYPTION	0x00000040 /* New to SMB3 */
249 /* Internal types */
250 #define SMB2_NT_FIND			0x00100000
251 #define SMB2_LARGE_FILES		0x00200000
252 
253 struct smb2_neg_context {
254 	__le16	ContextType;
255 	__le16	DataLength;
256 	__le32	Reserved;
257 	/* Followed by array of data */
258 } __packed;
259 
260 #define SMB311_SALT_SIZE			32
261 /* Hash Algorithm Types */
262 #define SMB2_PREAUTH_INTEGRITY_SHA512	cpu_to_le16(0x0001)
263 #define SMB2_PREAUTH_HASH_SIZE 64
264 
265 #define MIN_PREAUTH_CTXT_DATA_LEN	(SMB311_SALT_SIZE + 6)
266 struct smb2_preauth_neg_context {
267 	__le16	ContextType; /* 1 */
268 	__le16	DataLength;
269 	__le32	Reserved;
270 	__le16	HashAlgorithmCount; /* 1 */
271 	__le16	SaltLength;
272 	__le16	HashAlgorithms; /* HashAlgorithms[0] since only one defined */
273 	__u8	Salt[SMB311_SALT_SIZE];
274 } __packed;
275 
276 /* Encryption Algorithms Ciphers */
277 #define SMB2_ENCRYPTION_AES128_CCM	cpu_to_le16(0x0001)
278 #define SMB2_ENCRYPTION_AES128_GCM	cpu_to_le16(0x0002)
279 
280 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
281 #define MIN_ENCRYPT_CTXT_DATA_LEN	4
282 struct smb2_encryption_neg_context {
283 	__le16	ContextType; /* 2 */
284 	__le16	DataLength;
285 	__le32	Reserved;
286 	__le16	CipherCount; /* AES-128-GCM and AES-128-CCM */
287 	__le16	Ciphers[1]; /* Ciphers[0] since only one used now */
288 } __packed;
289 
290 #define POSIX_CTXT_DATA_LEN	8
291 struct smb2_posix_neg_context {
292 	__le16	ContextType; /* 0x100 */
293 	__le16	DataLength;
294 	__le32	Reserved;
295 	__le64	Reserved1; /* In case needed for future (eg version or caps) */
296 } __packed;
297 
298 struct smb2_negotiate_rsp {
299 	struct smb2_sync_hdr sync_hdr;
300 	__le16 StructureSize;	/* Must be 65 */
301 	__le16 SecurityMode;
302 	__le16 DialectRevision;
303 	__le16 NegotiateContextCount;	/* Prior to SMB3.1.1 was Reserved & MBZ */
304 	__u8   ServerGUID[16];
305 	__le32 Capabilities;
306 	__le32 MaxTransactSize;
307 	__le32 MaxReadSize;
308 	__le32 MaxWriteSize;
309 	__le64 SystemTime;	/* MBZ */
310 	__le64 ServerStartTime;
311 	__le16 SecurityBufferOffset;
312 	__le16 SecurityBufferLength;
313 	__le32 NegotiateContextOffset;	/* Pre:SMB3.1.1 was reserved/ignored */
314 	__u8   Buffer[1];	/* variable length GSS security buffer */
315 } __packed;
316 
317 /* Flags */
318 #define SMB2_SESSION_REQ_FLAG_BINDING		0x01
319 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA	0x04
320 
321 struct smb2_sess_setup_req {
322 	struct smb2_sync_hdr sync_hdr;
323 	__le16 StructureSize; /* Must be 25 */
324 	__u8   Flags;
325 	__u8   SecurityMode;
326 	__le32 Capabilities;
327 	__le32 Channel;
328 	__le16 SecurityBufferOffset;
329 	__le16 SecurityBufferLength;
330 	__u64 PreviousSessionId;
331 	__u8   Buffer[1];	/* variable length GSS security buffer */
332 } __packed;
333 
334 /* Currently defined SessionFlags */
335 #define SMB2_SESSION_FLAG_IS_GUEST	0x0001
336 #define SMB2_SESSION_FLAG_IS_NULL	0x0002
337 #define SMB2_SESSION_FLAG_ENCRYPT_DATA	0x0004
338 struct smb2_sess_setup_rsp {
339 	struct smb2_sync_hdr sync_hdr;
340 	__le16 StructureSize; /* Must be 9 */
341 	__le16 SessionFlags;
342 	__le16 SecurityBufferOffset;
343 	__le16 SecurityBufferLength;
344 	__u8   Buffer[1];	/* variable length GSS security buffer */
345 } __packed;
346 
347 struct smb2_logoff_req {
348 	struct smb2_sync_hdr sync_hdr;
349 	__le16 StructureSize;	/* Must be 4 */
350 	__le16 Reserved;
351 } __packed;
352 
353 struct smb2_logoff_rsp {
354 	struct smb2_sync_hdr sync_hdr;
355 	__le16 StructureSize;	/* Must be 4 */
356 	__le16 Reserved;
357 } __packed;
358 
359 /* Flags/Reserved for SMB3.1.1 */
360 #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
361 #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
362 #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
363 
364 struct smb2_tree_connect_req {
365 	struct smb2_sync_hdr sync_hdr;
366 	__le16 StructureSize;	/* Must be 9 */
367 	__le16 Reserved; /* Flags in SMB3.1.1 */
368 	__le16 PathOffset;
369 	__le16 PathLength;
370 	__u8   Buffer[1];	/* variable length */
371 } __packed;
372 
373 /* See MS-SMB2 section 2.2.9.2 */
374 /* Context Types */
375 #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
376 #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
377 
378 struct tree_connect_contexts {
379 	__le16 ContextType;
380 	__le16 DataLength;
381 	__le32 Reserved;
382 	__u8   Data[0];
383 } __packed;
384 
385 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
386 struct smb3_blob_data {
387 	__le16 BlobSize;
388 	__u8   BlobData[0];
389 } __packed;
390 
391 /* Valid values for Attr */
392 #define SE_GROUP_MANDATORY		0x00000001
393 #define SE_GROUP_ENABLED_BY_DEFAULT	0x00000002
394 #define SE_GROUP_ENABLED		0x00000004
395 #define SE_GROUP_OWNER			0x00000008
396 #define SE_GROUP_USE_FOR_DENY_ONLY	0x00000010
397 #define SE_GROUP_INTEGRITY		0x00000020
398 #define SE_GROUP_INTEGRITY_ENABLED	0x00000040
399 #define SE_GROUP_RESOURCE		0x20000000
400 #define SE_GROUP_LOGON_ID		0xC0000000
401 
402 /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
403 
404 struct sid_array_data {
405 	__le16 SidAttrCount;
406 	/* SidAttrList - array of sid_attr_data structs */
407 } __packed;
408 
409 struct luid_attr_data {
410 
411 } __packed;
412 
413 /*
414  * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
415  * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
416  */
417 
418 struct privilege_array_data {
419 	__le16 PrivilegeCount;
420 	/* array of privilege_data structs */
421 } __packed;
422 
423 struct remoted_identity_tcon_context {
424 	__le16 TicketType; /* must be 0x0001 */
425 	__le16 TicketSize; /* total size of this struct */
426 	__le16 User; /* offset to SID_ATTR_DATA struct with user info */
427 	__le16 UserName; /* offset to null terminated Unicode username string */
428 	__le16 Domain; /* offset to null terminated Unicode domain name */
429 	__le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
430 	__le16 RestrictedGroups; /* similar to above */
431 	__le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
432 	__le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
433 	__le16 Owner; /* offset to BLOB_DATA struct */
434 	__le16 DefaultDacl; /* offset to BLOB_DATA struct */
435 	__le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
436 	__le16 UserClaims; /* offset to BLOB_DATA struct */
437 	__le16 DeviceClaims; /* offset to BLOB_DATA struct */
438 	__u8   TicketInfo[0]; /* variable length buf - remoted identity data */
439 } __packed;
440 
441 struct smb2_tree_connect_req_extension {
442 	__le32 TreeConnectContextOffset;
443 	__le16 TreeConnectContextCount;
444 	__u8  Reserved[10];
445 	__u8  PathName[0]; /* variable sized array */
446 	/* followed by array of TreeConnectContexts */
447 } __packed;
448 
449 struct smb2_tree_connect_rsp {
450 	struct smb2_sync_hdr sync_hdr;
451 	__le16 StructureSize;	/* Must be 16 */
452 	__u8   ShareType;  /* see below */
453 	__u8   Reserved;
454 	__le32 ShareFlags; /* see below */
455 	__le32 Capabilities; /* see below */
456 	__le32 MaximalAccess;
457 } __packed;
458 
459 /* Possible ShareType values */
460 #define SMB2_SHARE_TYPE_DISK	0x01
461 #define SMB2_SHARE_TYPE_PIPE	0x02
462 #define	SMB2_SHARE_TYPE_PRINT	0x03
463 
464 /*
465  * Possible ShareFlags - exactly one and only one of the first 4 caching flags
466  * must be set (any of the remaining, SHI1005, flags may be set individually
467  * or in combination.
468  */
469 #define SMB2_SHAREFLAG_MANUAL_CACHING			0x00000000
470 #define SMB2_SHAREFLAG_AUTO_CACHING			0x00000010
471 #define SMB2_SHAREFLAG_VDO_CACHING			0x00000020
472 #define SMB2_SHAREFLAG_NO_CACHING			0x00000030
473 #define SHI1005_FLAGS_DFS				0x00000001
474 #define SHI1005_FLAGS_DFS_ROOT				0x00000002
475 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS		0x00000100
476 #define SHI1005_FLAGS_FORCE_SHARED_DELETE		0x00000200
477 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING		0x00000400
478 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM	0x00000800
479 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK		0x00001000
480 #define SHI1005_FLAGS_ENABLE_HASH_V1			0x00002000
481 #define SHI1005_FLAGS_ENABLE_HASH_V2			0x00004000
482 #define SHI1005_FLAGS_ENCRYPT_DATA			0x00008000
483 #define SMB2_SHAREFLAG_IDENTITY_REMOTING		0x00040000 /* 3.1.1 */
484 #define SHI1005_FLAGS_ALL				0x0004FF33
485 
486 /* Possible share capabilities */
487 #define SMB2_SHARE_CAP_DFS	cpu_to_le32(0x00000008) /* all dialects */
488 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
489 #define SMB2_SHARE_CAP_SCALEOUT	cpu_to_le32(0x00000020) /* 3.0 */
490 #define SMB2_SHARE_CAP_CLUSTER	cpu_to_le32(0x00000040) /* 3.0 */
491 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
492 #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
493 
494 struct smb2_tree_disconnect_req {
495 	struct smb2_sync_hdr sync_hdr;
496 	__le16 StructureSize;	/* Must be 4 */
497 	__le16 Reserved;
498 } __packed;
499 
500 struct smb2_tree_disconnect_rsp {
501 	struct smb2_sync_hdr sync_hdr;
502 	__le16 StructureSize;	/* Must be 4 */
503 	__le16 Reserved;
504 } __packed;
505 
506 /* File Attrubutes */
507 #define FILE_ATTRIBUTE_READONLY			0x00000001
508 #define FILE_ATTRIBUTE_HIDDEN			0x00000002
509 #define FILE_ATTRIBUTE_SYSTEM			0x00000004
510 #define FILE_ATTRIBUTE_DIRECTORY		0x00000010
511 #define FILE_ATTRIBUTE_ARCHIVE			0x00000020
512 #define FILE_ATTRIBUTE_NORMAL			0x00000080
513 #define FILE_ATTRIBUTE_TEMPORARY		0x00000100
514 #define FILE_ATTRIBUTE_SPARSE_FILE		0x00000200
515 #define FILE_ATTRIBUTE_REPARSE_POINT		0x00000400
516 #define FILE_ATTRIBUTE_COMPRESSED		0x00000800
517 #define FILE_ATTRIBUTE_OFFLINE			0x00001000
518 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	0x00002000
519 #define FILE_ATTRIBUTE_ENCRYPTED		0x00004000
520 #define FILE_ATTRIBUTE_INTEGRITY_STREAM		0x00008000
521 #define FILE_ATTRIBUTE_NO_SCRUB_DATA		0x00020000
522 
523 /* Oplock levels */
524 #define SMB2_OPLOCK_LEVEL_NONE		0x00
525 #define SMB2_OPLOCK_LEVEL_II		0x01
526 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE	0x08
527 #define SMB2_OPLOCK_LEVEL_BATCH		0x09
528 #define SMB2_OPLOCK_LEVEL_LEASE		0xFF
529 /* Non-spec internal type */
530 #define SMB2_OPLOCK_LEVEL_NOCHANGE	0x99
531 
532 /* Desired Access Flags */
533 #define FILE_READ_DATA_LE		cpu_to_le32(0x00000001)
534 #define FILE_WRITE_DATA_LE		cpu_to_le32(0x00000002)
535 #define FILE_APPEND_DATA_LE		cpu_to_le32(0x00000004)
536 #define FILE_READ_EA_LE			cpu_to_le32(0x00000008)
537 #define FILE_WRITE_EA_LE		cpu_to_le32(0x00000010)
538 #define FILE_EXECUTE_LE			cpu_to_le32(0x00000020)
539 #define FILE_READ_ATTRIBUTES_LE		cpu_to_le32(0x00000080)
540 #define FILE_WRITE_ATTRIBUTES_LE	cpu_to_le32(0x00000100)
541 #define FILE_DELETE_LE			cpu_to_le32(0x00010000)
542 #define FILE_READ_CONTROL_LE		cpu_to_le32(0x00020000)
543 #define FILE_WRITE_DAC_LE		cpu_to_le32(0x00040000)
544 #define FILE_WRITE_OWNER_LE		cpu_to_le32(0x00080000)
545 #define FILE_SYNCHRONIZE_LE		cpu_to_le32(0x00100000)
546 #define FILE_ACCESS_SYSTEM_SECURITY_LE	cpu_to_le32(0x01000000)
547 #define FILE_MAXIMAL_ACCESS_LE		cpu_to_le32(0x02000000)
548 #define FILE_GENERIC_ALL_LE		cpu_to_le32(0x10000000)
549 #define FILE_GENERIC_EXECUTE_LE		cpu_to_le32(0x20000000)
550 #define FILE_GENERIC_WRITE_LE		cpu_to_le32(0x40000000)
551 #define FILE_GENERIC_READ_LE		cpu_to_le32(0x80000000)
552 
553 /* ShareAccess Flags */
554 #define FILE_SHARE_READ_LE		cpu_to_le32(0x00000001)
555 #define FILE_SHARE_WRITE_LE		cpu_to_le32(0x00000002)
556 #define FILE_SHARE_DELETE_LE		cpu_to_le32(0x00000004)
557 #define FILE_SHARE_ALL_LE		cpu_to_le32(0x00000007)
558 
559 /* CreateDisposition Flags */
560 #define FILE_SUPERSEDE_LE		cpu_to_le32(0x00000000)
561 #define FILE_OPEN_LE			cpu_to_le32(0x00000001)
562 #define FILE_CREATE_LE			cpu_to_le32(0x00000002)
563 #define	FILE_OPEN_IF_LE			cpu_to_le32(0x00000003)
564 #define FILE_OVERWRITE_LE		cpu_to_le32(0x00000004)
565 #define FILE_OVERWRITE_IF_LE		cpu_to_le32(0x00000005)
566 
567 /* CreateOptions Flags */
568 #define FILE_DIRECTORY_FILE_LE		cpu_to_le32(0x00000001)
569 /* same as #define CREATE_NOT_FILE_LE	cpu_to_le32(0x00000001) */
570 #define FILE_WRITE_THROUGH_LE		cpu_to_le32(0x00000002)
571 #define FILE_SEQUENTIAL_ONLY_LE		cpu_to_le32(0x00000004)
572 #define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
573 #define FILE_SYNCHRONOUS_IO_ALERT_LE	cpu_to_le32(0x00000010)
574 #define FILE_SYNCHRONOUS_IO_NON_ALERT_LE	cpu_to_le32(0x00000020)
575 #define FILE_NON_DIRECTORY_FILE_LE	cpu_to_le32(0x00000040)
576 #define FILE_COMPLETE_IF_OPLOCKED_LE	cpu_to_le32(0x00000100)
577 #define FILE_NO_EA_KNOWLEDGE_LE		cpu_to_le32(0x00000200)
578 #define FILE_RANDOM_ACCESS_LE		cpu_to_le32(0x00000800)
579 #define FILE_DELETE_ON_CLOSE_LE		cpu_to_le32(0x00001000)
580 #define FILE_OPEN_BY_FILE_ID_LE		cpu_to_le32(0x00002000)
581 #define FILE_OPEN_FOR_BACKUP_INTENT_LE	cpu_to_le32(0x00004000)
582 #define FILE_NO_COMPRESSION_LE		cpu_to_le32(0x00008000)
583 #define FILE_RESERVE_OPFILTER_LE	cpu_to_le32(0x00100000)
584 #define FILE_OPEN_REPARSE_POINT_LE	cpu_to_le32(0x00200000)
585 #define FILE_OPEN_NO_RECALL_LE		cpu_to_le32(0x00400000)
586 #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
587 
588 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
589 			| FILE_READ_ATTRIBUTES_LE)
590 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
591 			| FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
592 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
593 
594 /* Impersonation Levels */
595 #define IL_ANONYMOUS		cpu_to_le32(0x00000000)
596 #define IL_IDENTIFICATION	cpu_to_le32(0x00000001)
597 #define IL_IMPERSONATION	cpu_to_le32(0x00000002)
598 #define IL_DELEGATE		cpu_to_le32(0x00000003)
599 
600 /* Create Context Values */
601 #define SMB2_CREATE_EA_BUFFER			"ExtA" /* extended attributes */
602 #define SMB2_CREATE_SD_BUFFER			"SecD" /* security descriptor */
603 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST	"DHnQ"
604 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT	"DHnC"
605 #define SMB2_CREATE_ALLOCATION_SIZE		"AISi"
606 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
607 #define SMB2_CREATE_TIMEWARP_REQUEST		"TWrp"
608 #define SMB2_CREATE_QUERY_ON_DISK_ID		"QFid"
609 #define SMB2_CREATE_REQUEST_LEASE		"RqLs"
610 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2	"DH2Q"
611 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2	"DH2C"
612 #define SMB2_CREATE_APP_INSTANCE_ID	0x45BCA66AEFA7F74A9008FA462E144D74
613 #define SVHDX_OPEN_DEVICE_CONTEX	0x9CCBCF9E04C1E643980E158DA1F6EC83
614 #define SMB2_CREATE_TAG_POSIX		0x93AD25509CB411E7B42383DE968BCD7C
615 
616 
617 /*
618  * Maximum number of iovs we need for an open/create request.
619  * [0] : struct smb2_create_req
620  * [1] : path
621  * [2] : lease context
622  * [3] : durable context
623  * [4] : posix context
624  * [5] : time warp context
625  * [6] : compound padding
626  */
627 #define SMB2_CREATE_IOV_SIZE 7
628 
629 struct smb2_create_req {
630 	struct smb2_sync_hdr sync_hdr;
631 	__le16 StructureSize;	/* Must be 57 */
632 	__u8   SecurityFlags;
633 	__u8   RequestedOplockLevel;
634 	__le32 ImpersonationLevel;
635 	__le64 SmbCreateFlags;
636 	__le64 Reserved;
637 	__le32 DesiredAccess;
638 	__le32 FileAttributes;
639 	__le32 ShareAccess;
640 	__le32 CreateDisposition;
641 	__le32 CreateOptions;
642 	__le16 NameOffset;
643 	__le16 NameLength;
644 	__le32 CreateContextsOffset;
645 	__le32 CreateContextsLength;
646 	__u8   Buffer[0];
647 } __packed;
648 
649 struct smb2_create_rsp {
650 	struct smb2_sync_hdr sync_hdr;
651 	__le16 StructureSize;	/* Must be 89 */
652 	__u8   OplockLevel;
653 	__u8   Reserved;
654 	__le32 CreateAction;
655 	__le64 CreationTime;
656 	__le64 LastAccessTime;
657 	__le64 LastWriteTime;
658 	__le64 ChangeTime;
659 	__le64 AllocationSize;
660 	__le64 EndofFile;
661 	__le32 FileAttributes;
662 	__le32 Reserved2;
663 	__u64  PersistentFileId; /* opaque endianness */
664 	__u64  VolatileFileId; /* opaque endianness */
665 	__le32 CreateContextsOffset;
666 	__le32 CreateContextsLength;
667 	__u8   Buffer[1];
668 } __packed;
669 
670 struct create_context {
671 	__le32 Next;
672 	__le16 NameOffset;
673 	__le16 NameLength;
674 	__le16 Reserved;
675 	__le16 DataOffset;
676 	__le32 DataLength;
677 	__u8 Buffer[0];
678 } __packed;
679 
680 #define SMB2_LEASE_READ_CACHING_HE	0x01
681 #define SMB2_LEASE_HANDLE_CACHING_HE	0x02
682 #define SMB2_LEASE_WRITE_CACHING_HE	0x04
683 
684 #define SMB2_LEASE_NONE			cpu_to_le32(0x00)
685 #define SMB2_LEASE_READ_CACHING		cpu_to_le32(0x01)
686 #define SMB2_LEASE_HANDLE_CACHING	cpu_to_le32(0x02)
687 #define SMB2_LEASE_WRITE_CACHING	cpu_to_le32(0x04)
688 
689 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
690 #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
691 
692 #define SMB2_LEASE_KEY_SIZE 16
693 
694 struct lease_context {
695 	u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
696 	__le32 LeaseState;
697 	__le32 LeaseFlags;
698 	__le64 LeaseDuration;
699 } __packed;
700 
701 struct lease_context_v2 {
702 	u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
703 	__le32 LeaseState;
704 	__le32 LeaseFlags;
705 	__le64 LeaseDuration;
706 	__le64 ParentLeaseKeyLow;
707 	__le64 ParentLeaseKeyHigh;
708 	__le16 Epoch;
709 	__le16 Reserved;
710 } __packed;
711 
712 struct create_lease {
713 	struct create_context ccontext;
714 	__u8   Name[8];
715 	struct lease_context lcontext;
716 } __packed;
717 
718 struct create_lease_v2 {
719 	struct create_context ccontext;
720 	__u8   Name[8];
721 	struct lease_context_v2 lcontext;
722 	__u8   Pad[4];
723 } __packed;
724 
725 struct create_durable {
726 	struct create_context ccontext;
727 	__u8   Name[8];
728 	union {
729 		__u8  Reserved[16];
730 		struct {
731 			__u64 PersistentFileId;
732 			__u64 VolatileFileId;
733 		} Fid;
734 	} Data;
735 } __packed;
736 
737 struct create_posix {
738 	struct create_context ccontext;
739 	__u8	Name[16];
740 	__le32  Mode;
741 	__u32	Reserved;
742 } __packed;
743 
744 /* See MS-SMB2 2.2.13.2.11 */
745 /* Flags */
746 #define SMB2_DHANDLE_FLAG_PERSISTENT	0x00000002
747 struct durable_context_v2 {
748 	__le32 Timeout;
749 	__le32 Flags;
750 	__u64 Reserved;
751 	__u8 CreateGuid[16];
752 } __packed;
753 
754 struct create_durable_v2 {
755 	struct create_context ccontext;
756 	__u8   Name[8];
757 	struct durable_context_v2 dcontext;
758 } __packed;
759 
760 /* See MS-SMB2 2.2.13.2.12 */
761 struct durable_reconnect_context_v2 {
762 	struct {
763 		__u64 PersistentFileId;
764 		__u64 VolatileFileId;
765 	} Fid;
766 	__u8 CreateGuid[16];
767 	__le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
768 } __packed;
769 
770 /* See MS-SMB2 2.2.14.2.12 */
771 struct durable_reconnect_context_v2_rsp {
772 	__le32 Timeout;
773 	__le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
774 } __packed;
775 
776 struct create_durable_handle_reconnect_v2 {
777 	struct create_context ccontext;
778 	__u8   Name[8];
779 	struct durable_reconnect_context_v2 dcontext;
780 } __packed;
781 
782 /* See MS-SMB2 2.2.13.2.5 */
783 struct crt_twarp_ctxt {
784 	struct create_context ccontext;
785 	__u8	Name[8];
786 	__le64	Timestamp;
787 
788 } __packed;
789 
790 #define COPY_CHUNK_RES_KEY_SIZE	24
791 struct resume_key_req {
792 	char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
793 	__le32	ContextLength;	/* MBZ */
794 	char	Context[0];	/* ignored, Windows sets to 4 bytes of zero */
795 } __packed;
796 
797 /* this goes in the ioctl buffer when doing a copychunk request */
798 struct copychunk_ioctl {
799 	char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
800 	__le32 ChunkCount; /* we are only sending 1 */
801 	__le32 Reserved;
802 	/* array will only be one chunk long for us */
803 	__le64 SourceOffset;
804 	__le64 TargetOffset;
805 	__le32 Length; /* how many bytes to copy */
806 	__u32 Reserved2;
807 } __packed;
808 
809 /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
810 struct file_zero_data_information {
811 	__le64	FileOffset;
812 	__le64	BeyondFinalZero;
813 } __packed;
814 
815 struct copychunk_ioctl_rsp {
816 	__le32 ChunksWritten;
817 	__le32 ChunkBytesWritten;
818 	__le32 TotalBytesWritten;
819 } __packed;
820 
821 struct fsctl_set_integrity_information_req {
822 	__le16	ChecksumAlgorithm;
823 	__le16	Reserved;
824 	__le32	Flags;
825 } __packed;
826 
827 struct fsctl_get_integrity_information_rsp {
828 	__le16	ChecksumAlgorithm;
829 	__le16	Reserved;
830 	__le32	Flags;
831 	__le32	ChecksumChunkSizeInBytes;
832 	__le32	ClusterSizeInBytes;
833 } __packed;
834 
835 /* Integrity ChecksumAlgorithm choices for above */
836 #define	CHECKSUM_TYPE_NONE	0x0000
837 #define	CHECKSUM_TYPE_CRC64	0x0002
838 #define CHECKSUM_TYPE_UNCHANGED	0xFFFF	/* set only */
839 
840 /* Integrity flags for above */
841 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF	0x00000001
842 
843 /* See MS-DFSC 2.2.2 */
844 struct fsctl_get_dfs_referral_req {
845 	__le16 MaxReferralLevel;
846 	__u8 RequestFileName[];
847 } __packed;
848 
849 /* DFS response is struct get_dfs_refer_rsp */
850 
851 /* See MS-SMB2 2.2.31.3 */
852 struct network_resiliency_req {
853 	__le32 Timeout;
854 	__le32 Reserved;
855 } __packed;
856 /* There is no buffer for the response ie no struct network_resiliency_rsp */
857 
858 
859 struct validate_negotiate_info_req {
860 	__le32 Capabilities;
861 	__u8   Guid[SMB2_CLIENT_GUID_SIZE];
862 	__le16 SecurityMode;
863 	__le16 DialectCount;
864 	__le16 Dialects[3]; /* BB expand this if autonegotiate > 3 dialects */
865 } __packed;
866 
867 struct validate_negotiate_info_rsp {
868 	__le32 Capabilities;
869 	__u8   Guid[SMB2_CLIENT_GUID_SIZE];
870 	__le16 SecurityMode;
871 	__le16 Dialect; /* Dialect in use for the connection */
872 } __packed;
873 
874 #define RSS_CAPABLE	cpu_to_le32(0x00000001)
875 #define RDMA_CAPABLE	cpu_to_le32(0x00000002)
876 
877 #define INTERNETWORK	cpu_to_le16(0x0002)
878 #define INTERNETWORKV6	cpu_to_le16(0x0017)
879 
880 struct network_interface_info_ioctl_rsp {
881 	__le32 Next; /* next interface. zero if this is last one */
882 	__le32 IfIndex;
883 	__le32 Capability; /* RSS or RDMA Capable */
884 	__le32 Reserved;
885 	__le64 LinkSpeed;
886 	__le16 Family;
887 	__u8 Buffer[126];
888 } __packed;
889 
890 struct iface_info_ipv4 {
891 	__be16 Port;
892 	__be32 IPv4Address;
893 	__be64 Reserved;
894 } __packed;
895 
896 struct iface_info_ipv6 {
897 	__be16 Port;
898 	__be32 FlowInfo;
899 	__u8   IPv6Address[16];
900 	__be32 ScopeId;
901 } __packed;
902 
903 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
904 
905 struct compress_ioctl {
906 	__le16 CompressionState; /* See cifspdu.h for possible flag values */
907 } __packed;
908 
909 struct duplicate_extents_to_file {
910 	__u64 PersistentFileHandle; /* source file handle, opaque endianness */
911 	__u64 VolatileFileHandle;
912 	__le64 SourceFileOffset;
913 	__le64 TargetFileOffset;
914 	__le64 ByteCount;  /* Bytes to be copied */
915 } __packed;
916 
917 struct smb2_ioctl_req {
918 	struct smb2_sync_hdr sync_hdr;
919 	__le16 StructureSize;	/* Must be 57 */
920 	__u16 Reserved;
921 	__le32 CtlCode;
922 	__u64  PersistentFileId; /* opaque endianness */
923 	__u64  VolatileFileId; /* opaque endianness */
924 	__le32 InputOffset;
925 	__le32 InputCount;
926 	__le32 MaxInputResponse;
927 	__le32 OutputOffset;
928 	__le32 OutputCount;
929 	__le32 MaxOutputResponse;
930 	__le32 Flags;
931 	__u32  Reserved2;
932 	__u8   Buffer[0];
933 } __packed;
934 
935 struct smb2_ioctl_rsp {
936 	struct smb2_sync_hdr sync_hdr;
937 	__le16 StructureSize;	/* Must be 57 */
938 	__u16 Reserved;
939 	__le32 CtlCode;
940 	__u64  PersistentFileId; /* opaque endianness */
941 	__u64  VolatileFileId; /* opaque endianness */
942 	__le32 InputOffset;
943 	__le32 InputCount;
944 	__le32 OutputOffset;
945 	__le32 OutputCount;
946 	__le32 Flags;
947 	__u32  Reserved2;
948 	/* char * buffer[] */
949 } __packed;
950 
951 /* Currently defined values for close flags */
952 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB	cpu_to_le16(0x0001)
953 struct smb2_close_req {
954 	struct smb2_sync_hdr sync_hdr;
955 	__le16 StructureSize;	/* Must be 24 */
956 	__le16 Flags;
957 	__le32 Reserved;
958 	__u64  PersistentFileId; /* opaque endianness */
959 	__u64  VolatileFileId; /* opaque endianness */
960 } __packed;
961 
962 struct smb2_close_rsp {
963 	struct smb2_sync_hdr sync_hdr;
964 	__le16 StructureSize; /* 60 */
965 	__le16 Flags;
966 	__le32 Reserved;
967 	__le64 CreationTime;
968 	__le64 LastAccessTime;
969 	__le64 LastWriteTime;
970 	__le64 ChangeTime;
971 	__le64 AllocationSize;	/* Beginning of FILE_STANDARD_INFO equivalent */
972 	__le64 EndOfFile;
973 	__le32 Attributes;
974 } __packed;
975 
976 struct smb2_flush_req {
977 	struct smb2_sync_hdr sync_hdr;
978 	__le16 StructureSize;	/* Must be 24 */
979 	__le16 Reserved1;
980 	__le32 Reserved2;
981 	__u64  PersistentFileId; /* opaque endianness */
982 	__u64  VolatileFileId; /* opaque endianness */
983 } __packed;
984 
985 struct smb2_flush_rsp {
986 	struct smb2_sync_hdr sync_hdr;
987 	__le16 StructureSize;
988 	__le16 Reserved;
989 } __packed;
990 
991 /* For read request Flags field below, following flag is defined for SMB3.02 */
992 #define SMB2_READFLAG_READ_UNBUFFERED	0x01
993 
994 /* Channel field for read and write: exactly one of following flags can be set*/
995 #define SMB2_CHANNEL_NONE	cpu_to_le32(0x00000000)
996 #define SMB2_CHANNEL_RDMA_V1	cpu_to_le32(0x00000001) /* SMB3 or later */
997 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
998 
999 /* SMB2 read request without RFC1001 length at the beginning */
1000 struct smb2_read_plain_req {
1001 	struct smb2_sync_hdr sync_hdr;
1002 	__le16 StructureSize; /* Must be 49 */
1003 	__u8   Padding; /* offset from start of SMB2 header to place read */
1004 	__u8   Flags; /* MBZ unless SMB3.02 or later */
1005 	__le32 Length;
1006 	__le64 Offset;
1007 	__u64  PersistentFileId; /* opaque endianness */
1008 	__u64  VolatileFileId; /* opaque endianness */
1009 	__le32 MinimumCount;
1010 	__le32 Channel; /* MBZ except for SMB3 or later */
1011 	__le32 RemainingBytes;
1012 	__le16 ReadChannelInfoOffset;
1013 	__le16 ReadChannelInfoLength;
1014 	__u8   Buffer[1];
1015 } __packed;
1016 
1017 struct smb2_read_rsp {
1018 	struct smb2_sync_hdr sync_hdr;
1019 	__le16 StructureSize; /* Must be 17 */
1020 	__u8   DataOffset;
1021 	__u8   Reserved;
1022 	__le32 DataLength;
1023 	__le32 DataRemaining;
1024 	__u32  Reserved2;
1025 	__u8   Buffer[1];
1026 } __packed;
1027 
1028 /* For write request Flags field below the following flags are defined: */
1029 #define SMB2_WRITEFLAG_WRITE_THROUGH	0x00000001	/* SMB2.1 or later */
1030 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED	0x00000002	/* SMB3.02 or later */
1031 
1032 struct smb2_write_req {
1033 	struct smb2_sync_hdr sync_hdr;
1034 	__le16 StructureSize; /* Must be 49 */
1035 	__le16 DataOffset; /* offset from start of SMB2 header to write data */
1036 	__le32 Length;
1037 	__le64 Offset;
1038 	__u64  PersistentFileId; /* opaque endianness */
1039 	__u64  VolatileFileId; /* opaque endianness */
1040 	__le32 Channel; /* Reserved MBZ */
1041 	__le32 RemainingBytes;
1042 	__le16 WriteChannelInfoOffset;
1043 	__le16 WriteChannelInfoLength;
1044 	__le32 Flags;
1045 	__u8   Buffer[1];
1046 } __packed;
1047 
1048 struct smb2_write_rsp {
1049 	struct smb2_sync_hdr sync_hdr;
1050 	__le16 StructureSize; /* Must be 17 */
1051 	__u8   DataOffset;
1052 	__u8   Reserved;
1053 	__le32 DataLength;
1054 	__le32 DataRemaining;
1055 	__u32  Reserved2;
1056 	__u8   Buffer[1];
1057 } __packed;
1058 
1059 #define SMB2_LOCKFLAG_SHARED_LOCK	0x0001
1060 #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK	0x0002
1061 #define SMB2_LOCKFLAG_UNLOCK		0x0004
1062 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY	0x0010
1063 
1064 struct smb2_lock_element {
1065 	__le64 Offset;
1066 	__le64 Length;
1067 	__le32 Flags;
1068 	__le32 Reserved;
1069 } __packed;
1070 
1071 struct smb2_lock_req {
1072 	struct smb2_sync_hdr sync_hdr;
1073 	__le16 StructureSize; /* Must be 48 */
1074 	__le16 LockCount;
1075 	__le32 Reserved;
1076 	__u64  PersistentFileId; /* opaque endianness */
1077 	__u64  VolatileFileId; /* opaque endianness */
1078 	/* Followed by at least one */
1079 	struct smb2_lock_element locks[1];
1080 } __packed;
1081 
1082 struct smb2_lock_rsp {
1083 	struct smb2_sync_hdr sync_hdr;
1084 	__le16 StructureSize; /* Must be 4 */
1085 	__le16 Reserved;
1086 } __packed;
1087 
1088 struct smb2_echo_req {
1089 	struct smb2_sync_hdr sync_hdr;
1090 	__le16 StructureSize;	/* Must be 4 */
1091 	__u16  Reserved;
1092 } __packed;
1093 
1094 struct smb2_echo_rsp {
1095 	struct smb2_sync_hdr sync_hdr;
1096 	__le16 StructureSize;	/* Must be 4 */
1097 	__u16  Reserved;
1098 } __packed;
1099 
1100 /* search (query_directory) Flags field */
1101 #define SMB2_RESTART_SCANS		0x01
1102 #define SMB2_RETURN_SINGLE_ENTRY	0x02
1103 #define SMB2_INDEX_SPECIFIED		0x04
1104 #define SMB2_REOPEN			0x10
1105 
1106 struct smb2_query_directory_req {
1107 	struct smb2_sync_hdr sync_hdr;
1108 	__le16 StructureSize; /* Must be 33 */
1109 	__u8   FileInformationClass;
1110 	__u8   Flags;
1111 	__le32 FileIndex;
1112 	__u64  PersistentFileId; /* opaque endianness */
1113 	__u64  VolatileFileId; /* opaque endianness */
1114 	__le16 FileNameOffset;
1115 	__le16 FileNameLength;
1116 	__le32 OutputBufferLength;
1117 	__u8   Buffer[1];
1118 } __packed;
1119 
1120 struct smb2_query_directory_rsp {
1121 	struct smb2_sync_hdr sync_hdr;
1122 	__le16 StructureSize; /* Must be 9 */
1123 	__le16 OutputBufferOffset;
1124 	__le32 OutputBufferLength;
1125 	__u8   Buffer[1];
1126 } __packed;
1127 
1128 /* Possible InfoType values */
1129 #define SMB2_O_INFO_FILE	0x01
1130 #define SMB2_O_INFO_FILESYSTEM	0x02
1131 #define SMB2_O_INFO_SECURITY	0x03
1132 #define SMB2_O_INFO_QUOTA	0x04
1133 
1134 /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
1135 #define OWNER_SECINFO   0x00000001
1136 #define GROUP_SECINFO   0x00000002
1137 #define DACL_SECINFO   0x00000004
1138 #define SACL_SECINFO   0x00000008
1139 #define LABEL_SECINFO   0x00000010
1140 #define ATTRIBUTE_SECINFO   0x00000020
1141 #define SCOPE_SECINFO   0x00000040
1142 #define BACKUP_SECINFO   0x00010000
1143 #define UNPROTECTED_SACL_SECINFO   0x10000000
1144 #define UNPROTECTED_DACL_SECINFO   0x20000000
1145 #define PROTECTED_SACL_SECINFO   0x40000000
1146 #define PROTECTED_DACL_SECINFO   0x80000000
1147 
1148 /* Flags used for FileFullEAinfo */
1149 #define SL_RESTART_SCAN		0x00000001
1150 #define SL_RETURN_SINGLE_ENTRY	0x00000002
1151 #define SL_INDEX_SPECIFIED	0x00000004
1152 
1153 struct smb2_query_info_req {
1154 	struct smb2_sync_hdr sync_hdr;
1155 	__le16 StructureSize; /* Must be 41 */
1156 	__u8   InfoType;
1157 	__u8   FileInfoClass;
1158 	__le32 OutputBufferLength;
1159 	__le16 InputBufferOffset;
1160 	__u16  Reserved;
1161 	__le32 InputBufferLength;
1162 	__le32 AdditionalInformation;
1163 	__le32 Flags;
1164 	__u64  PersistentFileId; /* opaque endianness */
1165 	__u64  VolatileFileId; /* opaque endianness */
1166 	__u8   Buffer[1];
1167 } __packed;
1168 
1169 struct smb2_query_info_rsp {
1170 	struct smb2_sync_hdr sync_hdr;
1171 	__le16 StructureSize; /* Must be 9 */
1172 	__le16 OutputBufferOffset;
1173 	__le32 OutputBufferLength;
1174 	__u8   Buffer[1];
1175 } __packed;
1176 
1177 struct smb2_set_info_req {
1178 	struct smb2_sync_hdr sync_hdr;
1179 	__le16 StructureSize; /* Must be 33 */
1180 	__u8   InfoType;
1181 	__u8   FileInfoClass;
1182 	__le32 BufferLength;
1183 	__le16 BufferOffset;
1184 	__u16  Reserved;
1185 	__le32 AdditionalInformation;
1186 	__u64  PersistentFileId; /* opaque endianness */
1187 	__u64  VolatileFileId; /* opaque endianness */
1188 	__u8   Buffer[1];
1189 } __packed;
1190 
1191 struct smb2_set_info_rsp {
1192 	struct smb2_sync_hdr sync_hdr;
1193 	__le16 StructureSize; /* Must be 2 */
1194 } __packed;
1195 
1196 struct smb2_oplock_break {
1197 	struct smb2_sync_hdr sync_hdr;
1198 	__le16 StructureSize; /* Must be 24 */
1199 	__u8   OplockLevel;
1200 	__u8   Reserved;
1201 	__le32 Reserved2;
1202 	__u64  PersistentFid;
1203 	__u64  VolatileFid;
1204 } __packed;
1205 
1206 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1207 
1208 struct smb2_lease_break {
1209 	struct smb2_sync_hdr sync_hdr;
1210 	__le16 StructureSize; /* Must be 44 */
1211 	__le16 Reserved;
1212 	__le32 Flags;
1213 	__u8   LeaseKey[16];
1214 	__le32 CurrentLeaseState;
1215 	__le32 NewLeaseState;
1216 	__le32 BreakReason;
1217 	__le32 AccessMaskHint;
1218 	__le32 ShareMaskHint;
1219 } __packed;
1220 
1221 struct smb2_lease_ack {
1222 	struct smb2_sync_hdr sync_hdr;
1223 	__le16 StructureSize; /* Must be 36 */
1224 	__le16 Reserved;
1225 	__le32 Flags;
1226 	__u8   LeaseKey[16];
1227 	__le32 LeaseState;
1228 	__le64 LeaseDuration;
1229 } __packed;
1230 
1231 /*
1232  *	PDU infolevel structure definitions
1233  *	BB consider moving to a different header
1234  */
1235 
1236 /* File System Information Classes */
1237 #define FS_VOLUME_INFORMATION		1 /* Query */
1238 #define FS_LABEL_INFORMATION		2 /* Local only */
1239 #define FS_SIZE_INFORMATION		3 /* Query */
1240 #define FS_DEVICE_INFORMATION		4 /* Query */
1241 #define FS_ATTRIBUTE_INFORMATION	5 /* Query */
1242 #define FS_CONTROL_INFORMATION		6 /* Query, Set */
1243 #define FS_FULL_SIZE_INFORMATION	7 /* Query */
1244 #define FS_OBJECT_ID_INFORMATION	8 /* Query, Set */
1245 #define FS_DRIVER_PATH_INFORMATION	9 /* Local only */
1246 #define FS_VOLUME_FLAGS_INFORMATION	10 /* Local only */
1247 #define FS_SECTOR_SIZE_INFORMATION	11 /* SMB3 or later. Query */
1248 #define FS_POSIX_INFORMATION		100 /* SMB3.1.1 POSIX. Query */
1249 
1250 struct smb2_fs_full_size_info {
1251 	__le64 TotalAllocationUnits;
1252 	__le64 CallerAvailableAllocationUnits;
1253 	__le64 ActualAvailableAllocationUnits;
1254 	__le32 SectorsPerAllocationUnit;
1255 	__le32 BytesPerSector;
1256 } __packed;
1257 
1258 #define SSINFO_FLAGS_ALIGNED_DEVICE		0x00000001
1259 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1260 #define SSINFO_FLAGS_NO_SEEK_PENALTY		0x00000004
1261 #define SSINFO_FLAGS_TRIM_ENABLED		0x00000008
1262 
1263 /* sector size info struct */
1264 struct smb3_fs_ss_info {
1265 	__le32 LogicalBytesPerSector;
1266 	__le32 PhysicalBytesPerSectorForAtomicity;
1267 	__le32 PhysicalBytesPerSectorForPerf;
1268 	__le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
1269 	__le32 Flags;
1270 	__le32 ByteOffsetForSectorAlignment;
1271 	__le32 ByteOffsetForPartitionAlignment;
1272 } __packed;
1273 
1274 /* volume info struct - see MS-FSCC 2.5.9 */
1275 #define MAX_VOL_LABEL_LEN	32
1276 struct smb3_fs_vol_info {
1277 	__le64	VolumeCreationTime;
1278 	__u32	VolumeSerialNumber;
1279 	__le32	VolumeLabelLength; /* includes trailing null */
1280 	__u8	SupportsObjects; /* True if eg like NTFS, supports objects */
1281 	__u8	Reserved;
1282 	__u8	VolumeLabel[0]; /* variable len */
1283 } __packed;
1284 
1285 /* partial list of QUERY INFO levels */
1286 #define FILE_DIRECTORY_INFORMATION	1
1287 #define FILE_FULL_DIRECTORY_INFORMATION 2
1288 #define FILE_BOTH_DIRECTORY_INFORMATION 3
1289 #define FILE_BASIC_INFORMATION		4
1290 #define FILE_STANDARD_INFORMATION	5
1291 #define FILE_INTERNAL_INFORMATION	6
1292 #define FILE_EA_INFORMATION	        7
1293 #define FILE_ACCESS_INFORMATION		8
1294 #define FILE_NAME_INFORMATION		9
1295 #define FILE_RENAME_INFORMATION		10
1296 #define FILE_LINK_INFORMATION		11
1297 #define FILE_NAMES_INFORMATION		12
1298 #define FILE_DISPOSITION_INFORMATION	13
1299 #define FILE_POSITION_INFORMATION	14
1300 #define FILE_FULL_EA_INFORMATION	15
1301 #define FILE_MODE_INFORMATION		16
1302 #define FILE_ALIGNMENT_INFORMATION	17
1303 #define FILE_ALL_INFORMATION		18
1304 #define FILE_ALLOCATION_INFORMATION	19
1305 #define FILE_END_OF_FILE_INFORMATION	20
1306 #define FILE_ALTERNATE_NAME_INFORMATION 21
1307 #define FILE_STREAM_INFORMATION		22
1308 #define FILE_PIPE_INFORMATION		23
1309 #define FILE_PIPE_LOCAL_INFORMATION	24
1310 #define FILE_PIPE_REMOTE_INFORMATION	25
1311 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1312 #define FILE_MAILSLOT_SET_INFORMATION	27
1313 #define FILE_COMPRESSION_INFORMATION	28
1314 #define FILE_OBJECT_ID_INFORMATION	29
1315 /* Number 30 not defined in documents */
1316 #define FILE_MOVE_CLUSTER_INFORMATION	31
1317 #define FILE_QUOTA_INFORMATION		32
1318 #define FILE_REPARSE_POINT_INFORMATION	33
1319 #define FILE_NETWORK_OPEN_INFORMATION	34
1320 #define FILE_ATTRIBUTE_TAG_INFORMATION	35
1321 #define FILE_TRACKING_INFORMATION	36
1322 #define FILEID_BOTH_DIRECTORY_INFORMATION 37
1323 #define FILEID_FULL_DIRECTORY_INFORMATION 38
1324 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1325 #define FILE_SHORT_NAME_INFORMATION	40
1326 #define FILE_SFIO_RESERVE_INFORMATION	44
1327 #define FILE_SFIO_VOLUME_INFORMATION	45
1328 #define FILE_HARD_LINK_INFORMATION	46
1329 #define FILE_NORMALIZED_NAME_INFORMATION 48
1330 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1331 #define FILE_STANDARD_LINK_INFORMATION	54
1332 
1333 struct smb2_file_internal_info {
1334 	__le64 IndexNumber;
1335 } __packed; /* level 6 Query */
1336 
1337 struct smb2_file_rename_info { /* encoding of request for level 10 */
1338 	__u8   ReplaceIfExists; /* 1 = replace existing target with new */
1339 				/* 0 = fail if target already exists */
1340 	__u8   Reserved[7];
1341 	__u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1342 	__le32 FileNameLength;
1343 	char   FileName[0];     /* New name to be assigned */
1344 } __packed; /* level 10 Set */
1345 
1346 struct smb2_file_link_info { /* encoding of request for level 11 */
1347 	__u8   ReplaceIfExists; /* 1 = replace existing link with new */
1348 				/* 0 = fail if link already exists */
1349 	__u8   Reserved[7];
1350 	__u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1351 	__le32 FileNameLength;
1352 	char   FileName[0];     /* Name to be assigned to new link */
1353 } __packed; /* level 11 Set */
1354 
1355 #define SMB2_MIN_EA_BUF  2048
1356 #define SMB2_MAX_EA_BUF 65536
1357 
1358 struct smb2_file_full_ea_info { /* encoding of response for level 15 */
1359 	__le32 next_entry_offset;
1360 	__u8   flags;
1361 	__u8   ea_name_length;
1362 	__le16 ea_value_length;
1363 	char   ea_data[0]; /* \0 terminated name plus value */
1364 } __packed; /* level 15 Set */
1365 
1366 /*
1367  * This level 18, although with struct with same name is different from cifs
1368  * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1369  * CurrentByteOffset.
1370  */
1371 struct smb2_file_all_info { /* data block encoding of response to level 18 */
1372 	__le64 CreationTime;	/* Beginning of FILE_BASIC_INFO equivalent */
1373 	__le64 LastAccessTime;
1374 	__le64 LastWriteTime;
1375 	__le64 ChangeTime;
1376 	__le32 Attributes;
1377 	__u32  Pad1;		/* End of FILE_BASIC_INFO_INFO equivalent */
1378 	__le64 AllocationSize;	/* Beginning of FILE_STANDARD_INFO equivalent */
1379 	__le64 EndOfFile;	/* size ie offset to first free byte in file */
1380 	__le32 NumberOfLinks;	/* hard links */
1381 	__u8   DeletePending;
1382 	__u8   Directory;
1383 	__u16  Pad2;		/* End of FILE_STANDARD_INFO equivalent */
1384 	__le64 IndexNumber;
1385 	__le32 EASize;
1386 	__le32 AccessFlags;
1387 	__le64 CurrentByteOffset;
1388 	__le32 Mode;
1389 	__le32 AlignmentRequirement;
1390 	__le32 FileNameLength;
1391 	char   FileName[1];
1392 } __packed; /* level 18 Query */
1393 
1394 struct smb2_file_eof_info { /* encoding of request for level 10 */
1395 	__le64 EndOfFile; /* new end of file value */
1396 } __packed; /* level 20 Set */
1397 
1398 extern char smb2_padding[7];
1399 
1400 #endif				/* _SMB2PDU_H */
1401