[smb3] move more common protocol header definitions to smbfs_common
[linux-block.git] / fs / smbfs_common / smb2pdu.h
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 #ifndef _COMMON_SMB2PDU_H
3 #define _COMMON_SMB2PDU_H
4
5 /*
6  * Note that, due to trying to use names similar to the protocol specifications,
7  * there are many mixed case field names in the structures below.  Although
8  * this does not match typical Linux kernel style, it is necessary to be
9  * able to match against the protocol specfication.
10  *
11  * SMB2 commands
12  * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
13  * (ie no useful data other than the SMB error code itself) and are marked such.
14  * Knowing this helps avoid response buffer allocations and copy in some cases.
15  */
16
17 /* List of commands in host endian */
18 #define SMB2_NEGOTIATE_HE       0x0000
19 #define SMB2_SESSION_SETUP_HE   0x0001
20 #define SMB2_LOGOFF_HE          0x0002 /* trivial request/resp */
21 #define SMB2_TREE_CONNECT_HE    0x0003
22 #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
23 #define SMB2_CREATE_HE          0x0005
24 #define SMB2_CLOSE_HE           0x0006
25 #define SMB2_FLUSH_HE           0x0007 /* trivial resp */
26 #define SMB2_READ_HE            0x0008
27 #define SMB2_WRITE_HE           0x0009
28 #define SMB2_LOCK_HE            0x000A
29 #define SMB2_IOCTL_HE           0x000B
30 #define SMB2_CANCEL_HE          0x000C
31 #define SMB2_ECHO_HE            0x000D
32 #define SMB2_QUERY_DIRECTORY_HE 0x000E
33 #define SMB2_CHANGE_NOTIFY_HE   0x000F
34 #define SMB2_QUERY_INFO_HE      0x0010
35 #define SMB2_SET_INFO_HE        0x0011
36 #define SMB2_OPLOCK_BREAK_HE    0x0012
37
38 /* The same list in little endian */
39 #define SMB2_NEGOTIATE          cpu_to_le16(SMB2_NEGOTIATE_HE)
40 #define SMB2_SESSION_SETUP      cpu_to_le16(SMB2_SESSION_SETUP_HE)
41 #define SMB2_LOGOFF             cpu_to_le16(SMB2_LOGOFF_HE)
42 #define SMB2_TREE_CONNECT       cpu_to_le16(SMB2_TREE_CONNECT_HE)
43 #define SMB2_TREE_DISCONNECT    cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
44 #define SMB2_CREATE             cpu_to_le16(SMB2_CREATE_HE)
45 #define SMB2_CLOSE              cpu_to_le16(SMB2_CLOSE_HE)
46 #define SMB2_FLUSH              cpu_to_le16(SMB2_FLUSH_HE)
47 #define SMB2_READ               cpu_to_le16(SMB2_READ_HE)
48 #define SMB2_WRITE              cpu_to_le16(SMB2_WRITE_HE)
49 #define SMB2_LOCK               cpu_to_le16(SMB2_LOCK_HE)
50 #define SMB2_IOCTL              cpu_to_le16(SMB2_IOCTL_HE)
51 #define SMB2_CANCEL             cpu_to_le16(SMB2_CANCEL_HE)
52 #define SMB2_ECHO               cpu_to_le16(SMB2_ECHO_HE)
53 #define SMB2_QUERY_DIRECTORY    cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
54 #define SMB2_CHANGE_NOTIFY      cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
55 #define SMB2_QUERY_INFO         cpu_to_le16(SMB2_QUERY_INFO_HE)
56 #define SMB2_SET_INFO           cpu_to_le16(SMB2_SET_INFO_HE)
57 #define SMB2_OPLOCK_BREAK       cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
58
59 #define SMB2_INTERNAL_CMD       cpu_to_le16(0xFFFF)
60
61 #define NUMBER_OF_SMB2_COMMANDS 0x0013
62
63 /*
64  * SMB2 Header Definition
65  *
66  * "MBZ" :  Must be Zero
67  * "BB"  :  BugBug, Something to check/review/analyze later
68  * "PDU" :  "Protocol Data Unit" (ie a network "frame")
69  *
70  */
71
72 #define __SMB2_HEADER_STRUCTURE_SIZE    64
73 #define SMB2_HEADER_STRUCTURE_SIZE                              \
74         cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
75
76 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
77 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
78 #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
79
80 /*
81  *      SMB2 flag definitions
82  */
83 #define SMB2_FLAGS_SERVER_TO_REDIR      cpu_to_le32(0x00000001)
84 #define SMB2_FLAGS_ASYNC_COMMAND        cpu_to_le32(0x00000002)
85 #define SMB2_FLAGS_RELATED_OPERATIONS   cpu_to_le32(0x00000004)
86 #define SMB2_FLAGS_SIGNED               cpu_to_le32(0x00000008)
87 #define SMB2_FLAGS_PRIORITY_MASK        cpu_to_le32(0x00000070) /* SMB3.1.1 */
88 #define SMB2_FLAGS_DFS_OPERATIONS       cpu_to_le32(0x10000000)
89 #define SMB2_FLAGS_REPLAY_OPERATION     cpu_to_le32(0x20000000) /* SMB3 & up */
90
91 /* See MS-SMB2 section 2.2.1 */
92 struct smb2_hdr {
93         __le32 ProtocolId;      /* 0xFE 'S' 'M' 'B' */
94         __le16 StructureSize;   /* 64 */
95         __le16 CreditCharge;    /* MBZ */
96         __le32 Status;          /* Error from server */
97         __le16 Command;
98         __le16 CreditRequest;   /* CreditResponse */
99         __le32 Flags;
100         __le32 NextCommand;
101         __le64 MessageId;
102         union {
103                 struct {
104                         __le32 ProcessId;
105                         __le32  TreeId;
106                 } __packed SyncId;
107                 __le64  AsyncId;
108         } __packed Id;
109         __le64  SessionId;
110         __u8   Signature[16];
111 } __packed;
112
113 struct smb2_pdu {
114         struct smb2_hdr hdr;
115         __le16 StructureSize2; /* size of wct area (varies, request specific) */
116 } __packed;
117
118 #define SMB2_ERROR_STRUCTURE_SIZE2      9
119 #define SMB2_ERROR_STRUCTURE_SIZE2_LE   cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
120
121 struct smb2_err_rsp {
122         struct smb2_hdr hdr;
123         __le16 StructureSize;
124         __u8   ErrorContextCount;
125         __u8   Reserved;
126         __le32 ByteCount;  /* even if zero, at least one byte follows */
127         __u8   ErrorData[1];  /* variable length */
128 } __packed;
129
130 #define SMB3_AES_CCM_NONCE 11
131 #define SMB3_AES_GCM_NONCE 12
132
133 /* Transform flags (for 3.0 dialect this flag indicates CCM */
134 #define TRANSFORM_FLAG_ENCRYPTED        0x0001
135 struct smb2_transform_hdr {
136         __le32 ProtocolId;      /* 0xFD 'S' 'M' 'B' */
137         __u8   Signature[16];
138         __u8   Nonce[16];
139         __le32 OriginalMessageSize;
140         __u16  Reserved1;
141         __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
142         __le64  SessionId;
143 } __packed;
144
145
146 /* See MS-SMB2 2.2.42 */
147 struct smb2_compression_transform_hdr_unchained {
148         __le32 ProtocolId;      /* 0xFC 'S' 'M' 'B' */
149         __le32 OriginalCompressedSegmentSize;
150         __le16 CompressionAlgorithm;
151         __le16 Flags;
152         __le16 Length; /* if chained it is length, else offset */
153 } __packed;
154
155 /* See MS-SMB2 2.2.42.1 */
156 #define SMB2_COMPRESSION_FLAG_NONE      0x0000
157 #define SMB2_COMPRESSION_FLAG_CHAINED   0x0001
158
159 struct compression_payload_header {
160         __le16  CompressionAlgorithm;
161         __le16  Flags;
162         __le32  Length; /* length of compressed playload including field below if present */
163         /* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */
164 } __packed;
165
166 /* See MS-SMB2 2.2.42.2 */
167 struct smb2_compression_transform_hdr_chained {
168         __le32 ProtocolId;      /* 0xFC 'S' 'M' 'B' */
169         __le32 OriginalCompressedSegmentSize;
170         /* struct compression_payload_header[] */
171 } __packed;
172
173 /* See MS-SMB2 2.2.42.2.2 */
174 struct compression_pattern_payload_v1 {
175         __le16  Pattern;
176         __le16  Reserved1;
177         __le16  Reserved2;
178         __le32  Repetitions;
179 } __packed;
180
181 /* See MS-SMB2 section 2.2.9.2 */
182 /* Context Types */
183 #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
184 #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
185
186 struct tree_connect_contexts {
187         __le16 ContextType;
188         __le16 DataLength;
189         __le32 Reserved;
190         __u8   Data[];
191 } __packed;
192
193 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
194 struct smb3_blob_data {
195         __le16 BlobSize;
196         __u8   BlobData[];
197 } __packed;
198
199 /* Valid values for Attr */
200 #define SE_GROUP_MANDATORY              0x00000001
201 #define SE_GROUP_ENABLED_BY_DEFAULT     0x00000002
202 #define SE_GROUP_ENABLED                0x00000004
203 #define SE_GROUP_OWNER                  0x00000008
204 #define SE_GROUP_USE_FOR_DENY_ONLY      0x00000010
205 #define SE_GROUP_INTEGRITY              0x00000020
206 #define SE_GROUP_INTEGRITY_ENABLED      0x00000040
207 #define SE_GROUP_RESOURCE               0x20000000
208 #define SE_GROUP_LOGON_ID               0xC0000000
209
210 /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
211
212 struct sid_array_data {
213         __le16 SidAttrCount;
214         /* SidAttrList - array of sid_attr_data structs */
215 } __packed;
216
217 struct luid_attr_data {
218
219 } __packed;
220
221 /*
222  * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
223  * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
224  */
225
226 struct privilege_array_data {
227         __le16 PrivilegeCount;
228         /* array of privilege_data structs */
229 } __packed;
230
231 struct remoted_identity_tcon_context {
232         __le16 TicketType; /* must be 0x0001 */
233         __le16 TicketSize; /* total size of this struct */
234         __le16 User; /* offset to SID_ATTR_DATA struct with user info */
235         __le16 UserName; /* offset to null terminated Unicode username string */
236         __le16 Domain; /* offset to null terminated Unicode domain name */
237         __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
238         __le16 RestrictedGroups; /* similar to above */
239         __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
240         __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
241         __le16 Owner; /* offset to BLOB_DATA struct */
242         __le16 DefaultDacl; /* offset to BLOB_DATA struct */
243         __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
244         __le16 UserClaims; /* offset to BLOB_DATA struct */
245         __le16 DeviceClaims; /* offset to BLOB_DATA struct */
246         __u8   TicketInfo[]; /* variable length buf - remoted identity data */
247 } __packed;
248
249 struct smb2_tree_connect_req_extension {
250         __le32 TreeConnectContextOffset;
251         __le16 TreeConnectContextCount;
252         __u8  Reserved[10];
253         __u8  PathName[]; /* variable sized array */
254         /* followed by array of TreeConnectContexts */
255 } __packed;
256
257 /* Flags/Reserved for SMB3.1.1 */
258 #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
259 #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
260 #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
261
262 struct smb2_tree_connect_req {
263         struct smb2_hdr hdr;
264         __le16 StructureSize;   /* Must be 9 */
265         __le16 Flags;           /* Flags in SMB3.1.1 */
266         __le16 PathOffset;
267         __le16 PathLength;
268         __u8   Buffer[1];       /* variable length */
269 } __packed;
270
271 /* Possible ShareType values */
272 #define SMB2_SHARE_TYPE_DISK    0x01
273 #define SMB2_SHARE_TYPE_PIPE    0x02
274 #define SMB2_SHARE_TYPE_PRINT   0x03
275
276 /*
277  * Possible ShareFlags - exactly one and only one of the first 4 caching flags
278  * must be set (any of the remaining, SHI1005, flags may be set individually
279  * or in combination.
280  */
281 #define SMB2_SHAREFLAG_MANUAL_CACHING                   0x00000000
282 #define SMB2_SHAREFLAG_AUTO_CACHING                     0x00000010
283 #define SMB2_SHAREFLAG_VDO_CACHING                      0x00000020
284 #define SMB2_SHAREFLAG_NO_CACHING                       0x00000030
285 #define SHI1005_FLAGS_DFS                               0x00000001
286 #define SHI1005_FLAGS_DFS_ROOT                          0x00000002
287 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS          0x00000100
288 #define SHI1005_FLAGS_FORCE_SHARED_DELETE               0x00000200
289 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING           0x00000400
290 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM       0x00000800
291 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK              0x00001000
292 #define SHI1005_FLAGS_ENABLE_HASH_V1                    0x00002000
293 #define SHI1005_FLAGS_ENABLE_HASH_V2                    0x00004000
294 #define SHI1005_FLAGS_ENCRYPT_DATA                      0x00008000
295 #define SMB2_SHAREFLAG_IDENTITY_REMOTING                0x00040000 /* 3.1.1 */
296 #define SMB2_SHAREFLAG_COMPRESS_DATA                    0x00100000 /* 3.1.1 */
297 #define SHI1005_FLAGS_ALL                               0x0014FF33
298
299 /* Possible share capabilities */
300 #define SMB2_SHARE_CAP_DFS      cpu_to_le32(0x00000008) /* all dialects */
301 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
302 #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
303 #define SMB2_SHARE_CAP_CLUSTER  cpu_to_le32(0x00000040) /* 3.0 */
304 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
305 #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
306
307 struct smb2_tree_connect_rsp {
308         struct smb2_hdr hdr;
309         __le16 StructureSize;   /* Must be 16 */
310         __u8   ShareType;       /* see below */
311         __u8   Reserved;
312         __le32 ShareFlags;      /* see below */
313         __le32 Capabilities;    /* see below */
314         __le32 MaximalAccess;
315 } __packed;
316
317 struct smb2_tree_disconnect_req {
318         struct smb2_hdr hdr;
319         __le16 StructureSize;   /* Must be 4 */
320         __le16 Reserved;
321 } __packed;
322
323 struct smb2_tree_disconnect_rsp {
324         struct smb2_hdr hdr;
325         __le16 StructureSize;   /* Must be 4 */
326         __le16 Reserved;
327 } __packed;
328
329
330 /*
331  * SMB2_NEGOTIATE_PROTOCOL  See MS-SMB2 section 2.2.3
332  */
333 /* SecurityMode flags */
334 #define SMB2_NEGOTIATE_SIGNING_ENABLED     0x0001
335 #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE  cpu_to_le16(0x0001)
336 #define SMB2_NEGOTIATE_SIGNING_REQUIRED    0x0002
337 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
338 #define SMB2_SEC_MODE_FLAGS_ALL            0x0003
339
340 /* Capabilities flags */
341 #define SMB2_GLOBAL_CAP_DFS             0x00000001
342 #define SMB2_GLOBAL_CAP_LEASING         0x00000002 /* Resp only New to SMB2.1 */
343 #define SMB2_GLOBAL_CAP_LARGE_MTU       0X00000004 /* Resp only New to SMB2.1 */
344 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL   0x00000008 /* New to SMB3 */
345 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
346 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING  0x00000020 /* New to SMB3 */
347 #define SMB2_GLOBAL_CAP_ENCRYPTION      0x00000040 /* New to SMB3 */
348 /* Internal types */
349 #define SMB2_NT_FIND                    0x00100000
350 #define SMB2_LARGE_FILES                0x00200000
351
352 #define SMB2_CLIENT_GUID_SIZE           16
353 #define SMB2_CREATE_GUID_SIZE           16
354
355 /* Dialects */
356 #define SMB10_PROT_ID  0x0000 /* local only, not sent on wire w/CIFS negprot */
357 #define SMB20_PROT_ID  0x0202
358 #define SMB21_PROT_ID  0x0210
359 #define SMB2X_PROT_ID  0x02FF
360 #define SMB30_PROT_ID  0x0300
361 #define SMB302_PROT_ID 0x0302
362 #define SMB311_PROT_ID 0x0311
363 #define BAD_PROT_ID    0xFFFF
364
365 #define SMB311_SALT_SIZE                        32
366 /* Hash Algorithm Types */
367 #define SMB2_PREAUTH_INTEGRITY_SHA512   cpu_to_le16(0x0001)
368 #define SMB2_PREAUTH_HASH_SIZE 64
369
370 /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
371 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES     cpu_to_le16(1)
372 #define SMB2_ENCRYPTION_CAPABILITIES            cpu_to_le16(2)
373 #define SMB2_COMPRESSION_CAPABILITIES           cpu_to_le16(3)
374 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID       cpu_to_le16(5)
375 #define SMB2_TRANSPORT_CAPABILITIES             cpu_to_le16(6)
376 #define SMB2_RDMA_TRANSFORM_CAPABILITIES        cpu_to_le16(7)
377 #define SMB2_SIGNING_CAPABILITIES               cpu_to_le16(8)
378 #define SMB2_POSIX_EXTENSIONS_AVAILABLE         cpu_to_le16(0x100)
379
380 struct smb2_neg_context {
381         __le16  ContextType;
382         __le16  DataLength;
383         __le32  Reserved;
384         /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
385 } __packed;
386
387 /*
388  * SaltLength that the server send can be zero, so the only three required
389  * fields (all __le16) end up six bytes total, so the minimum context data len
390  * in the response is six bytes which accounts for
391  *
392  *      HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
393  */
394 #define MIN_PREAUTH_CTXT_DATA_LEN 6
395
396 struct smb2_preauth_neg_context {
397         __le16  ContextType; /* 1 */
398         __le16  DataLength;
399         __le32  Reserved;
400         __le16  HashAlgorithmCount; /* 1 */
401         __le16  SaltLength;
402         __le16  HashAlgorithms; /* HashAlgorithms[0] since only one defined */
403         __u8    Salt[SMB311_SALT_SIZE];
404 } __packed;
405
406 /* Encryption Algorithms Ciphers */
407 #define SMB2_ENCRYPTION_AES128_CCM      cpu_to_le16(0x0001)
408 #define SMB2_ENCRYPTION_AES128_GCM      cpu_to_le16(0x0002)
409 #define SMB2_ENCRYPTION_AES256_CCM      cpu_to_le16(0x0003)
410 #define SMB2_ENCRYPTION_AES256_GCM      cpu_to_le16(0x0004)
411
412 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
413 #define MIN_ENCRYPT_CTXT_DATA_LEN       4
414 struct smb2_encryption_neg_context {
415         __le16  ContextType; /* 2 */
416         __le16  DataLength;
417         __le32  Reserved;
418         /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
419         __le16  CipherCount; /* AES128-GCM and AES128-CCM by default */
420         __le16  Ciphers[];
421 } __packed;
422
423 /* See MS-SMB2 2.2.3.1.3 */
424 #define SMB3_COMPRESS_NONE      cpu_to_le16(0x0000)
425 #define SMB3_COMPRESS_LZNT1     cpu_to_le16(0x0001)
426 #define SMB3_COMPRESS_LZ77      cpu_to_le16(0x0002)
427 #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
428 /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
429 #define SMB3_COMPRESS_PATTERN   cpu_to_le16(0x0004) /* Pattern_V1 */
430
431 /* Compression Flags */
432 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE         cpu_to_le32(0x00000000)
433 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED      cpu_to_le32(0x00000001)
434
435 struct smb2_compression_capabilities_context {
436         __le16  ContextType; /* 3 */
437         __le16  DataLength;
438         __le32  Reserved;
439         __le16  CompressionAlgorithmCount;
440         __le16  Padding;
441         __le32  Flags;
442         __le16  CompressionAlgorithms[3];
443         __u16   Pad;  /* Some servers require pad to DataLen multiple of 8 */
444         /* Check if pad needed */
445 } __packed;
446
447 /*
448  * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
449  * Its struct simply contains NetName, an array of Unicode characters
450  */
451 struct smb2_netname_neg_context {
452         __le16  ContextType; /* 5 */
453         __le16  DataLength;
454         __le32  Reserved;
455         __le16  NetName[]; /* hostname of target converted to UCS-2 */
456 } __packed;
457
458 /*
459  * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
460  * and 2.2.4.1.5
461  */
462
463 /* Flags */
464 #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY    0x00000001
465
466 struct smb2_transport_capabilities_context {
467         __le16  ContextType; /* 6 */
468         __le16  DataLength;
469         __u32   Reserved;
470         __le32  Flags;
471         __u32   Pad;
472 } __packed;
473
474 /*
475  * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
476  * and 2.2.4.1.6
477  */
478
479 /* RDMA Transform IDs */
480 #define SMB2_RDMA_TRANSFORM_NONE        0x0000
481 #define SMB2_RDMA_TRANSFORM_ENCRYPTION  0x0001
482 #define SMB2_RDMA_TRANSFORM_SIGNING     0x0002
483
484 struct smb2_rdma_transform_capabilities_context {
485         __le16  ContextType; /* 7 */
486         __le16  DataLength;
487         __u32   Reserved;
488         __le16  TransformCount;
489         __u16   Reserved1;
490         __u32   Reserved2;
491         __le16  RDMATransformIds[];
492 } __packed;
493
494 /*
495  * For signing capabilities context see MS-SMB2 2.2.3.1.7
496  * and 2.2.4.1.7
497  */
498
499 /* Signing algorithms */
500 #define SIGNING_ALG_HMAC_SHA256    0
501 #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
502 #define SIGNING_ALG_AES_CMAC       1
503 #define SIGNING_ALG_AES_CMAC_LE    cpu_to_le16(1)
504 #define SIGNING_ALG_AES_GMAC       2
505 #define SIGNING_ALG_AES_GMAC_LE    cpu_to_le16(2)
506
507 struct smb2_signing_capabilities {
508         __le16  ContextType; /* 8 */
509         __le16  DataLength;
510         __le32  Reserved;
511         __le16  SigningAlgorithmCount;
512         __le16  SigningAlgorithms[];
513         /*  Followed by padding to 8 byte boundary (required by some servers) */
514 } __packed;
515
516 #define POSIX_CTXT_DATA_LEN     16
517 struct smb2_posix_neg_context {
518         __le16  ContextType; /* 0x100 */
519         __le16  DataLength;
520         __le32  Reserved;
521         __u8    Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
522 } __packed;
523
524 struct smb2_negotiate_req {
525         struct smb2_hdr hdr;
526         __le16 StructureSize; /* Must be 36 */
527         __le16 DialectCount;
528         __le16 SecurityMode;
529         __le16 Reserved;        /* MBZ */
530         __le32 Capabilities;
531         __u8   ClientGUID[SMB2_CLIENT_GUID_SIZE];
532         /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
533         __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
534         __le16 NegotiateContextCount;  /* SMB3.1.1 only. MBZ earlier */
535         __le16 Reserved2;
536         __le16 Dialects[];
537 } __packed;
538
539 struct smb2_negotiate_rsp {
540         struct smb2_hdr hdr;
541         __le16 StructureSize;   /* Must be 65 */
542         __le16 SecurityMode;
543         __le16 DialectRevision;
544         __le16 NegotiateContextCount;   /* Prior to SMB3.1.1 was Reserved & MBZ */
545         __u8   ServerGUID[16];
546         __le32 Capabilities;
547         __le32 MaxTransactSize;
548         __le32 MaxReadSize;
549         __le32 MaxWriteSize;
550         __le64 SystemTime;      /* MBZ */
551         __le64 ServerStartTime;
552         __le16 SecurityBufferOffset;
553         __le16 SecurityBufferLength;
554         __le32 NegotiateContextOffset;  /* Pre:SMB3.1.1 was reserved/ignored */
555         __u8   Buffer[1];       /* variable length GSS security buffer */
556 } __packed;
557
558
559 /*
560  * SMB2_SESSION_SETUP  See MS-SMB2 section 2.2.5
561  */
562 /* Flags */
563 #define SMB2_SESSION_REQ_FLAG_BINDING           0x01
564 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA      0x04
565
566 struct smb2_sess_setup_req {
567         struct smb2_hdr hdr;
568         __le16 StructureSize; /* Must be 25 */
569         __u8   Flags;
570         __u8   SecurityMode;
571         __le32 Capabilities;
572         __le32 Channel;
573         __le16 SecurityBufferOffset;
574         __le16 SecurityBufferLength;
575         __le64 PreviousSessionId;
576         __u8   Buffer[1];       /* variable length GSS security buffer */
577 } __packed;
578
579 /* Currently defined SessionFlags */
580 #define SMB2_SESSION_FLAG_IS_GUEST        0x0001
581 #define SMB2_SESSION_FLAG_IS_GUEST_LE     cpu_to_le16(0x0001)
582 #define SMB2_SESSION_FLAG_IS_NULL         0x0002
583 #define SMB2_SESSION_FLAG_IS_NULL_LE      cpu_to_le16(0x0002)
584 #define SMB2_SESSION_FLAG_ENCRYPT_DATA    0x0004
585 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
586
587 struct smb2_sess_setup_rsp {
588         struct smb2_hdr hdr;
589         __le16 StructureSize; /* Must be 9 */
590         __le16 SessionFlags;
591         __le16 SecurityBufferOffset;
592         __le16 SecurityBufferLength;
593         __u8   Buffer[1];       /* variable length GSS security buffer */
594 } __packed;
595
596
597 /*
598  * SMB2_LOGOFF  See MS-SMB2 section 2.2.7
599  */
600 struct smb2_logoff_req {
601         struct smb2_hdr hdr;
602         __le16 StructureSize;   /* Must be 4 */
603         __le16 Reserved;
604 } __packed;
605
606 struct smb2_logoff_rsp {
607         struct smb2_hdr hdr;
608         __le16 StructureSize;   /* Must be 4 */
609         __le16 Reserved;
610 } __packed;
611
612
613 /*
614  * SMB2_CLOSE  See MS-SMB2 section 2.2.15
615  */
616 /* Currently defined values for close flags */
617 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB        cpu_to_le16(0x0001)
618 struct smb2_close_req {
619         struct smb2_hdr hdr;
620         __le16 StructureSize;   /* Must be 24 */
621         __le16 Flags;
622         __le32 Reserved;
623         __u64  PersistentFileId; /* opaque endianness */
624         __u64  VolatileFileId; /* opaque endianness */
625 } __packed;
626
627 /*
628  * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
629  */
630 #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
631
632 struct smb2_close_rsp {
633         struct smb2_hdr hdr;
634         __le16 StructureSize; /* 60 */
635         __le16 Flags;
636         __le32 Reserved;
637         __le64 CreationTime;
638         __le64 LastAccessTime;
639         __le64 LastWriteTime;
640         __le64 ChangeTime;
641         __le64 AllocationSize;  /* Beginning of FILE_STANDARD_INFO equivalent */
642         __le64 EndOfFile;
643         __le32 Attributes;
644 } __packed;
645
646
647 /*
648  * SMB2_READ  See MS-SMB2 section 2.2.19
649  */
650 /* For read request Flags field below, following flag is defined for SMB3.02 */
651 #define SMB2_READFLAG_READ_UNBUFFERED   0x01
652 #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
653
654 /* Channel field for read and write: exactly one of following flags can be set*/
655 #define SMB2_CHANNEL_NONE               cpu_to_le32(0x00000000)
656 #define SMB2_CHANNEL_RDMA_V1            cpu_to_le32(0x00000001)
657 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
658 #define SMB2_CHANNEL_RDMA_TRANSFORM     cpu_to_le32(0x00000003)
659
660 /* SMB2 read request without RFC1001 length at the beginning */
661 struct smb2_read_req {
662         struct smb2_hdr hdr;
663         __le16 StructureSize; /* Must be 49 */
664         __u8   Padding; /* offset from start of SMB2 header to place read */
665         __u8   Flags; /* MBZ unless SMB3.02 or later */
666         __le32 Length;
667         __le64 Offset;
668         __u64  PersistentFileId;
669         __u64  VolatileFileId;
670         __le32 MinimumCount;
671         __le32 Channel; /* MBZ except for SMB3 or later */
672         __le32 RemainingBytes;
673         __le16 ReadChannelInfoOffset;
674         __le16 ReadChannelInfoLength;
675         __u8   Buffer[1];
676 } __packed;
677
678 /* Read flags */
679 #define SMB2_READFLAG_RESPONSE_NONE            cpu_to_le32(0x00000000)
680 #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM  cpu_to_le32(0x00000001)
681
682 struct smb2_read_rsp {
683         struct smb2_hdr hdr;
684         __le16 StructureSize; /* Must be 17 */
685         __u8   DataOffset;
686         __u8   Reserved;
687         __le32 DataLength;
688         __le32 DataRemaining;
689         __le32 Flags;
690         __u8   Buffer[1];
691 } __packed;
692
693
694 /*
695  * SMB2_WRITE  See MS-SMB2 section 2.2.21
696  */
697 /* For write request Flags field below the following flags are defined: */
698 #define SMB2_WRITEFLAG_WRITE_THROUGH    0x00000001      /* SMB2.1 or later */
699 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002      /* SMB3.02 or later */
700
701 struct smb2_write_req {
702         struct smb2_hdr hdr;
703         __le16 StructureSize; /* Must be 49 */
704         __le16 DataOffset; /* offset from start of SMB2 header to write data */
705         __le32 Length;
706         __le64 Offset;
707         __u64  PersistentFileId; /* opaque endianness */
708         __u64  VolatileFileId; /* opaque endianness */
709         __le32 Channel; /* MBZ unless SMB3.02 or later */
710         __le32 RemainingBytes;
711         __le16 WriteChannelInfoOffset;
712         __le16 WriteChannelInfoLength;
713         __le32 Flags;
714         __u8   Buffer[1];
715 } __packed;
716
717 struct smb2_write_rsp {
718         struct smb2_hdr hdr;
719         __le16 StructureSize; /* Must be 17 */
720         __u8   DataOffset;
721         __u8   Reserved;
722         __le32 DataLength;
723         __le32 DataRemaining;
724         __u32  Reserved2;
725         __u8   Buffer[1];
726 } __packed;
727
728
729 /*
730  * SMB2_FLUSH  See MS-SMB2 section 2.2.17
731  */
732 struct smb2_flush_req {
733         struct smb2_hdr hdr;
734         __le16 StructureSize;   /* Must be 24 */
735         __le16 Reserved1;
736         __le32 Reserved2;
737         __u64  PersistentFileId;
738         __u64  VolatileFileId;
739 } __packed;
740
741 struct smb2_flush_rsp {
742         struct smb2_hdr hdr;
743         __le16 StructureSize;
744         __le16 Reserved;
745 } __packed;
746
747
748 /*
749  * SMB2_NOTIFY  See MS-SMB2 section 2.2.35
750  */
751 /* notify flags */
752 #define SMB2_WATCH_TREE                 0x0001
753
754 /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
755 #define FILE_NOTIFY_CHANGE_FILE_NAME            0x00000001
756 #define FILE_NOTIFY_CHANGE_DIR_NAME             0x00000002
757 #define FILE_NOTIFY_CHANGE_ATTRIBUTES           0x00000004
758 #define FILE_NOTIFY_CHANGE_SIZE                 0x00000008
759 #define FILE_NOTIFY_CHANGE_LAST_WRITE           0x00000010
760 #define FILE_NOTIFY_CHANGE_LAST_ACCESS          0x00000020
761 #define FILE_NOTIFY_CHANGE_CREATION             0x00000040
762 #define FILE_NOTIFY_CHANGE_EA                   0x00000080
763 #define FILE_NOTIFY_CHANGE_SECURITY             0x00000100
764 #define FILE_NOTIFY_CHANGE_STREAM_NAME          0x00000200
765 #define FILE_NOTIFY_CHANGE_STREAM_SIZE          0x00000400
766 #define FILE_NOTIFY_CHANGE_STREAM_WRITE         0x00000800
767
768 /* SMB2 Notify Action Flags */
769 #define FILE_ACTION_ADDED                       0x00000001
770 #define FILE_ACTION_REMOVED                     0x00000002
771 #define FILE_ACTION_MODIFIED                    0x00000003
772 #define FILE_ACTION_RENAMED_OLD_NAME            0x00000004
773 #define FILE_ACTION_RENAMED_NEW_NAME            0x00000005
774 #define FILE_ACTION_ADDED_STREAM                0x00000006
775 #define FILE_ACTION_REMOVED_STREAM              0x00000007
776 #define FILE_ACTION_MODIFIED_STREAM             0x00000008
777 #define FILE_ACTION_REMOVED_BY_DELETE           0x00000009
778
779 struct smb2_change_notify_req {
780         struct smb2_hdr hdr;
781         __le16  StructureSize;
782         __le16  Flags;
783         __le32  OutputBufferLength;
784         __u64   PersistentFileId; /* opaque endianness */
785         __u64   VolatileFileId; /* opaque endianness */
786         __le32  CompletionFilter;
787         __u32   Reserved;
788 } __packed;
789
790 struct smb2_change_notify_rsp {
791         struct smb2_hdr hdr;
792         __le16  StructureSize;  /* Must be 9 */
793         __le16  OutputBufferOffset;
794         __le32  OutputBufferLength;
795         __u8    Buffer[1]; /* array of file notify structs */
796 } __packed;
797
798
799 /*
800  * SMB2_CREATE  See MS-SMB2 section 2.2.13
801  */
802 /* Oplock levels */
803 #define SMB2_OPLOCK_LEVEL_NONE          0x00
804 #define SMB2_OPLOCK_LEVEL_II            0x01
805 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE     0x08
806 #define SMB2_OPLOCK_LEVEL_BATCH         0x09
807 #define SMB2_OPLOCK_LEVEL_LEASE         0xFF
808 /* Non-spec internal type */
809 #define SMB2_OPLOCK_LEVEL_NOCHANGE      0x99
810
811 /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
812 #define IL_ANONYMOUS            cpu_to_le32(0x00000000)
813 #define IL_IDENTIFICATION       cpu_to_le32(0x00000001)
814 #define IL_IMPERSONATION        cpu_to_le32(0x00000002)
815 #define IL_DELEGATE             cpu_to_le32(0x00000003)
816
817 /* File Attrubutes */
818 #define FILE_ATTRIBUTE_READONLY                 0x00000001
819 #define FILE_ATTRIBUTE_HIDDEN                   0x00000002
820 #define FILE_ATTRIBUTE_SYSTEM                   0x00000004
821 #define FILE_ATTRIBUTE_DIRECTORY                0x00000010
822 #define FILE_ATTRIBUTE_ARCHIVE                  0x00000020
823 #define FILE_ATTRIBUTE_NORMAL                   0x00000080
824 #define FILE_ATTRIBUTE_TEMPORARY                0x00000100
825 #define FILE_ATTRIBUTE_SPARSE_FILE              0x00000200
826 #define FILE_ATTRIBUTE_REPARSE_POINT            0x00000400
827 #define FILE_ATTRIBUTE_COMPRESSED               0x00000800
828 #define FILE_ATTRIBUTE_OFFLINE                  0x00001000
829 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED      0x00002000
830 #define FILE_ATTRIBUTE_ENCRYPTED                0x00004000
831 #define FILE_ATTRIBUTE_INTEGRITY_STREAM         0x00008000
832 #define FILE_ATTRIBUTE_NO_SCRUB_DATA            0x00020000
833 #define FILE_ATTRIBUTE__MASK                    0x00007FB7
834
835 #define FILE_ATTRIBUTE_READONLY_LE              cpu_to_le32(0x00000001)
836 #define FILE_ATTRIBUTE_HIDDEN_LE                cpu_to_le32(0x00000002)
837 #define FILE_ATTRIBUTE_SYSTEM_LE                cpu_to_le32(0x00000004)
838 #define FILE_ATTRIBUTE_DIRECTORY_LE             cpu_to_le32(0x00000010)
839 #define FILE_ATTRIBUTE_ARCHIVE_LE               cpu_to_le32(0x00000020)
840 #define FILE_ATTRIBUTE_NORMAL_LE                cpu_to_le32(0x00000080)
841 #define FILE_ATTRIBUTE_TEMPORARY_LE             cpu_to_le32(0x00000100)
842 #define FILE_ATTRIBUTE_SPARSE_FILE_LE           cpu_to_le32(0x00000200)
843 #define FILE_ATTRIBUTE_REPARSE_POINT_LE         cpu_to_le32(0x00000400)
844 #define FILE_ATTRIBUTE_COMPRESSED_LE            cpu_to_le32(0x00000800)
845 #define FILE_ATTRIBUTE_OFFLINE_LE               cpu_to_le32(0x00001000)
846 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE   cpu_to_le32(0x00002000)
847 #define FILE_ATTRIBUTE_ENCRYPTED_LE             cpu_to_le32(0x00004000)
848 #define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE      cpu_to_le32(0x00008000)
849 #define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE         cpu_to_le32(0x00020000)
850 #define FILE_ATTRIBUTE_MASK_LE                  cpu_to_le32(0x00007FB7)
851
852 /* Desired Access Flags */
853 #define FILE_READ_DATA_LE               cpu_to_le32(0x00000001)
854 #define FILE_LIST_DIRECTORY_LE          cpu_to_le32(0x00000001)
855 #define FILE_WRITE_DATA_LE              cpu_to_le32(0x00000002)
856 #define FILE_APPEND_DATA_LE             cpu_to_le32(0x00000004)
857 #define FILE_ADD_SUBDIRECTORY_LE        cpu_to_le32(0x00000004)
858 #define FILE_READ_EA_LE                 cpu_to_le32(0x00000008)
859 #define FILE_WRITE_EA_LE                cpu_to_le32(0x00000010)
860 #define FILE_EXECUTE_LE                 cpu_to_le32(0x00000020)
861 #define FILE_DELETE_CHILD_LE            cpu_to_le32(0x00000040)
862 #define FILE_READ_ATTRIBUTES_LE         cpu_to_le32(0x00000080)
863 #define FILE_WRITE_ATTRIBUTES_LE        cpu_to_le32(0x00000100)
864 #define FILE_DELETE_LE                  cpu_to_le32(0x00010000)
865 #define FILE_READ_CONTROL_LE            cpu_to_le32(0x00020000)
866 #define FILE_WRITE_DAC_LE               cpu_to_le32(0x00040000)
867 #define FILE_WRITE_OWNER_LE             cpu_to_le32(0x00080000)
868 #define FILE_SYNCHRONIZE_LE             cpu_to_le32(0x00100000)
869 #define FILE_ACCESS_SYSTEM_SECURITY_LE  cpu_to_le32(0x01000000)
870 #define FILE_MAXIMAL_ACCESS_LE          cpu_to_le32(0x02000000)
871 #define FILE_GENERIC_ALL_LE             cpu_to_le32(0x10000000)
872 #define FILE_GENERIC_EXECUTE_LE         cpu_to_le32(0x20000000)
873 #define FILE_GENERIC_WRITE_LE           cpu_to_le32(0x40000000)
874 #define FILE_GENERIC_READ_LE            cpu_to_le32(0x80000000)
875 #define DESIRED_ACCESS_MASK             cpu_to_le32(0xF21F01FF)
876
877
878 #define FILE_READ_DESIRED_ACCESS_LE     (FILE_READ_DATA_LE        |     \
879                                          FILE_READ_EA_LE          |     \
880                                          FILE_GENERIC_READ_LE)
881 #define FILE_WRITE_DESIRE_ACCESS_LE     (FILE_WRITE_DATA_LE       |     \
882                                          FILE_APPEND_DATA_LE      |     \
883                                          FILE_WRITE_EA_LE         |     \
884                                          FILE_WRITE_ATTRIBUTES_LE |     \
885                                          FILE_GENERIC_WRITE_LE)
886
887 /* ShareAccess Flags */
888 #define FILE_SHARE_READ_LE              cpu_to_le32(0x00000001)
889 #define FILE_SHARE_WRITE_LE             cpu_to_le32(0x00000002)
890 #define FILE_SHARE_DELETE_LE            cpu_to_le32(0x00000004)
891 #define FILE_SHARE_ALL_LE               cpu_to_le32(0x00000007)
892
893 /* CreateDisposition Flags */
894 #define FILE_SUPERSEDE_LE               cpu_to_le32(0x00000000)
895 #define FILE_OPEN_LE                    cpu_to_le32(0x00000001)
896 #define FILE_CREATE_LE                  cpu_to_le32(0x00000002)
897 #define FILE_OPEN_IF_LE                 cpu_to_le32(0x00000003)
898 #define FILE_OVERWRITE_LE               cpu_to_le32(0x00000004)
899 #define FILE_OVERWRITE_IF_LE            cpu_to_le32(0x00000005)
900 #define FILE_CREATE_MASK_LE             cpu_to_le32(0x00000007)
901
902 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \
903                         | FILE_READ_ATTRIBUTES)
904 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
905                         | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
906 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
907
908 /* CreateOptions Flags */
909 #define FILE_DIRECTORY_FILE_LE          cpu_to_le32(0x00000001)
910 /* same as #define CREATE_NOT_FILE_LE   cpu_to_le32(0x00000001) */
911 #define FILE_WRITE_THROUGH_LE           cpu_to_le32(0x00000002)
912 #define FILE_SEQUENTIAL_ONLY_LE         cpu_to_le32(0x00000004)
913 #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
914 #define FILE_NON_DIRECTORY_FILE_LE      cpu_to_le32(0x00000040)
915 #define FILE_COMPLETE_IF_OPLOCKED_LE    cpu_to_le32(0x00000100)
916 #define FILE_NO_EA_KNOWLEDGE_LE         cpu_to_le32(0x00000200)
917 #define FILE_RANDOM_ACCESS_LE           cpu_to_le32(0x00000800)
918 #define FILE_DELETE_ON_CLOSE_LE         cpu_to_le32(0x00001000)
919 #define FILE_OPEN_BY_FILE_ID_LE         cpu_to_le32(0x00002000)
920 #define FILE_OPEN_FOR_BACKUP_INTENT_LE  cpu_to_le32(0x00004000)
921 #define FILE_NO_COMPRESSION_LE          cpu_to_le32(0x00008000)
922 #define FILE_OPEN_REPARSE_POINT_LE      cpu_to_le32(0x00200000)
923 #define FILE_OPEN_NO_RECALL_LE          cpu_to_le32(0x00400000)
924 #define CREATE_OPTIONS_MASK_LE          cpu_to_le32(0x00FFFFFF)
925
926 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
927                         | FILE_READ_ATTRIBUTES_LE)
928 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
929                         | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
930 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
931
932 /* Create Context Values */
933 #define SMB2_CREATE_EA_BUFFER                   "ExtA" /* extended attributes */
934 #define SMB2_CREATE_SD_BUFFER                   "SecD" /* security descriptor */
935 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST      "DHnQ"
936 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT    "DHnC"
937 #define SMB2_CREATE_ALLOCATION_SIZE             "AISi"
938 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
939 #define SMB2_CREATE_TIMEWARP_REQUEST            "TWrp"
940 #define SMB2_CREATE_QUERY_ON_DISK_ID            "QFid"
941 #define SMB2_CREATE_REQUEST_LEASE               "RqLs"
942 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2   "DH2Q"
943 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
944 #define SMB2_CREATE_TAG_POSIX          "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
945
946 /* Flag (SMB3 open response) values */
947 #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
948
949 struct create_context {
950         __le32 Next;
951         __le16 NameOffset;
952         __le16 NameLength;
953         __le16 Reserved;
954         __le16 DataOffset;
955         __le32 DataLength;
956         __u8 Buffer[];
957 } __packed;
958
959 struct smb2_create_req {
960         struct smb2_hdr hdr;
961         __le16 StructureSize;   /* Must be 57 */
962         __u8   SecurityFlags;
963         __u8   RequestedOplockLevel;
964         __le32 ImpersonationLevel;
965         __le64 SmbCreateFlags;
966         __le64 Reserved;
967         __le32 DesiredAccess;
968         __le32 FileAttributes;
969         __le32 ShareAccess;
970         __le32 CreateDisposition;
971         __le32 CreateOptions;
972         __le16 NameOffset;
973         __le16 NameLength;
974         __le32 CreateContextsOffset;
975         __le32 CreateContextsLength;
976         __u8   Buffer[];
977 } __packed;
978
979 struct smb2_create_rsp {
980         struct smb2_hdr hdr;
981         __le16 StructureSize;   /* Must be 89 */
982         __u8   OplockLevel;
983         __u8   Flags;  /* 0x01 if reparse point */
984         __le32 CreateAction;
985         __le64 CreationTime;
986         __le64 LastAccessTime;
987         __le64 LastWriteTime;
988         __le64 ChangeTime;
989         __le64 AllocationSize;
990         __le64 EndofFile;
991         __le32 FileAttributes;
992         __le32 Reserved2;
993         __u64  PersistentFileId;
994         __u64  VolatileFileId;
995         __le32 CreateContextsOffset;
996         __le32 CreateContextsLength;
997         __u8   Buffer[1];
998 } __packed;
999
1000 #define SMB2_LEASE_NONE_LE                      cpu_to_le32(0x00)
1001 #define SMB2_LEASE_READ_CACHING_LE              cpu_to_le32(0x01)
1002 #define SMB2_LEASE_HANDLE_CACHING_LE            cpu_to_le32(0x02)
1003 #define SMB2_LEASE_WRITE_CACHING_LE             cpu_to_le32(0x04)
1004
1005 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE    cpu_to_le32(0x02)
1006
1007 #define SMB2_LEASE_KEY_SIZE                     16
1008
1009 struct lease_context {
1010         __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1011         __le32 LeaseState;
1012         __le32 LeaseFlags;
1013         __le64 LeaseDuration;
1014 } __packed;
1015
1016 struct lease_context_v2 {
1017         __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1018         __le32 LeaseState;
1019         __le32 LeaseFlags;
1020         __le64 LeaseDuration;
1021         __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
1022         __le16 Epoch;
1023         __le16 Reserved;
1024 } __packed;
1025
1026 struct create_lease {
1027         struct create_context ccontext;
1028         __u8   Name[8];
1029         struct lease_context lcontext;
1030 } __packed;
1031
1032 struct create_lease_v2 {
1033         struct create_context ccontext;
1034         __u8   Name[8];
1035         struct lease_context_v2 lcontext;
1036         __u8   Pad[4];
1037 } __packed;
1038
1039 /* Possible InfoType values */
1040 #define SMB2_O_INFO_FILE        0x01
1041 #define SMB2_O_INFO_FILESYSTEM  0x02
1042 #define SMB2_O_INFO_SECURITY    0x03
1043 #define SMB2_O_INFO_QUOTA       0x04
1044
1045 /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */
1046
1047 /* Security info type additionalinfo flags. */
1048 #define OWNER_SECINFO   0x00000001
1049 #define GROUP_SECINFO   0x00000002
1050 #define DACL_SECINFO   0x00000004
1051 #define SACL_SECINFO   0x00000008
1052 #define LABEL_SECINFO   0x00000010
1053 #define ATTRIBUTE_SECINFO   0x00000020
1054 #define SCOPE_SECINFO   0x00000040
1055 #define BACKUP_SECINFO   0x00010000
1056 #define UNPROTECTED_SACL_SECINFO   0x10000000
1057 #define UNPROTECTED_DACL_SECINFO   0x20000000
1058 #define PROTECTED_SACL_SECINFO   0x40000000
1059 #define PROTECTED_DACL_SECINFO   0x80000000
1060
1061 /* Flags used for FileFullEAinfo */
1062 #define SL_RESTART_SCAN         0x00000001
1063 #define SL_RETURN_SINGLE_ENTRY  0x00000002
1064 #define SL_INDEX_SPECIFIED      0x00000004
1065
1066 struct smb2_query_info_req {
1067         struct smb2_hdr hdr;
1068         __le16 StructureSize; /* Must be 41 */
1069         __u8   InfoType;
1070         __u8   FileInfoClass;
1071         __le32 OutputBufferLength;
1072         __le16 InputBufferOffset;
1073         __u16  Reserved;
1074         __le32 InputBufferLength;
1075         __le32 AdditionalInformation;
1076         __le32 Flags;
1077         __u64  PersistentFileId;
1078         __u64  VolatileFileId;
1079         __u8   Buffer[1];
1080 } __packed;
1081
1082 struct smb2_query_info_rsp {
1083         struct smb2_hdr hdr;
1084         __le16 StructureSize; /* Must be 9 */
1085         __le16 OutputBufferOffset;
1086         __le32 OutputBufferLength;
1087         __u8   Buffer[1];
1088 } __packed;
1089
1090 #endif                          /* _COMMON_SMB2PDU_H */