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