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