Merge tag 'linux-kselftest-fixes-5.15-rc5' of git://git.kernel.org/pub/scm/linux...
[platform/kernel/linux-rpi.git] / fs / ksmbd / smb2pdu.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *   Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
4  *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
5  */
6
7 #ifndef _SMB2PDU_H
8 #define _SMB2PDU_H
9
10 #include "ntlmssp.h"
11 #include "smbacl.h"
12
13 /*
14  * Note that, due to trying to use names similar to the protocol specifications,
15  * there are many mixed case field names in the structures below.  Although
16  * this does not match typical Linux kernel style, it is necessary to be
17  * able to match against the protocol specfication.
18  *
19  * SMB2 commands
20  * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
21  * (ie no useful data other than the SMB error code itself) and are marked such.
22  * Knowing this helps avoid response buffer allocations and copy in some cases.
23  */
24
25 /* List of commands in host endian */
26 #define SMB2_NEGOTIATE_HE       0x0000
27 #define SMB2_SESSION_SETUP_HE   0x0001
28 #define SMB2_LOGOFF_HE          0x0002 /* trivial request/resp */
29 #define SMB2_TREE_CONNECT_HE    0x0003
30 #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
31 #define SMB2_CREATE_HE          0x0005
32 #define SMB2_CLOSE_HE           0x0006
33 #define SMB2_FLUSH_HE           0x0007 /* trivial resp */
34 #define SMB2_READ_HE            0x0008
35 #define SMB2_WRITE_HE           0x0009
36 #define SMB2_LOCK_HE            0x000A
37 #define SMB2_IOCTL_HE           0x000B
38 #define SMB2_CANCEL_HE          0x000C
39 #define SMB2_ECHO_HE            0x000D
40 #define SMB2_QUERY_DIRECTORY_HE 0x000E
41 #define SMB2_CHANGE_NOTIFY_HE   0x000F
42 #define SMB2_QUERY_INFO_HE      0x0010
43 #define SMB2_SET_INFO_HE        0x0011
44 #define SMB2_OPLOCK_BREAK_HE    0x0012
45
46 /* The same list in little endian */
47 #define SMB2_NEGOTIATE          cpu_to_le16(SMB2_NEGOTIATE_HE)
48 #define SMB2_SESSION_SETUP      cpu_to_le16(SMB2_SESSION_SETUP_HE)
49 #define SMB2_LOGOFF             cpu_to_le16(SMB2_LOGOFF_HE)
50 #define SMB2_TREE_CONNECT       cpu_to_le16(SMB2_TREE_CONNECT_HE)
51 #define SMB2_TREE_DISCONNECT    cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
52 #define SMB2_CREATE             cpu_to_le16(SMB2_CREATE_HE)
53 #define SMB2_CLOSE              cpu_to_le16(SMB2_CLOSE_HE)
54 #define SMB2_FLUSH              cpu_to_le16(SMB2_FLUSH_HE)
55 #define SMB2_READ               cpu_to_le16(SMB2_READ_HE)
56 #define SMB2_WRITE              cpu_to_le16(SMB2_WRITE_HE)
57 #define SMB2_LOCK               cpu_to_le16(SMB2_LOCK_HE)
58 #define SMB2_IOCTL              cpu_to_le16(SMB2_IOCTL_HE)
59 #define SMB2_CANCEL             cpu_to_le16(SMB2_CANCEL_HE)
60 #define SMB2_ECHO               cpu_to_le16(SMB2_ECHO_HE)
61 #define SMB2_QUERY_DIRECTORY    cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
62 #define SMB2_CHANGE_NOTIFY      cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
63 #define SMB2_QUERY_INFO         cpu_to_le16(SMB2_QUERY_INFO_HE)
64 #define SMB2_SET_INFO           cpu_to_le16(SMB2_SET_INFO_HE)
65 #define SMB2_OPLOCK_BREAK       cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
66
67 /*Create Action Flags*/
68 #define FILE_SUPERSEDED                0x00000000
69 #define FILE_OPENED            0x00000001
70 #define FILE_CREATED           0x00000002
71 #define FILE_OVERWRITTEN       0x00000003
72
73 /*
74  * Size of the session key (crypto key encrypted with the password
75  */
76 #define SMB2_NTLMV2_SESSKEY_SIZE        16
77 #define SMB2_SIGNATURE_SIZE             16
78 #define SMB2_HMACSHA256_SIZE            32
79 #define SMB2_CMACAES_SIZE               16
80 #define SMB3_GCM128_CRYPTKEY_SIZE       16
81 #define SMB3_GCM256_CRYPTKEY_SIZE       32
82
83 /*
84  * Size of the smb3 encryption/decryption keys
85  */
86 #define SMB3_ENC_DEC_KEY_SIZE           32
87
88 /*
89  * Size of the smb3 signing key
90  */
91 #define SMB3_SIGN_KEY_SIZE              16
92
93 #define CIFS_CLIENT_CHALLENGE_SIZE      8
94 #define SMB_SERVER_CHALLENGE_SIZE       8
95
96 /* SMB2 Max Credits */
97 #define SMB2_MAX_CREDITS                8192
98
99 #define SMB2_CLIENT_GUID_SIZE           16
100 #define SMB2_CREATE_GUID_SIZE           16
101
102 /* Maximum buffer size value we can send with 1 credit */
103 #define SMB2_MAX_BUFFER_SIZE 65536
104
105 #define NUMBER_OF_SMB2_COMMANDS 0x0013
106
107 /* BB FIXME - analyze following length BB */
108 #define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
109
110 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe) /* 'B''M''S' */
111 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
112
113 #define SMB21_DEFAULT_IOSIZE    (1024 * 1024)
114 #define SMB3_DEFAULT_IOSIZE     (4 * 1024 * 1024)
115 #define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
116
117 /*
118  * SMB2 Header Definition
119  *
120  * "MBZ" :  Must be Zero
121  * "BB"  :  BugBug, Something to check/review/analyze later
122  * "PDU" :  "Protocol Data Unit" (ie a network "frame")
123  *
124  */
125
126 #define __SMB2_HEADER_STRUCTURE_SIZE    64
127 #define SMB2_HEADER_STRUCTURE_SIZE                              \
128         cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
129
130 struct smb2_hdr {
131         __be32 smb2_buf_length; /* big endian on wire */
132                                 /*
133                                  * length is only two or three bytes - with
134                                  * one or two byte type preceding it that MBZ
135                                  */
136         __le32 ProtocolId;      /* 0xFE 'S' 'M' 'B' */
137         __le16 StructureSize;   /* 64 */
138         __le16 CreditCharge;    /* MBZ */
139         __le32 Status;          /* Error from server */
140         __le16 Command;
141         __le16 CreditRequest;   /* CreditResponse */
142         __le32 Flags;
143         __le32 NextCommand;
144         __le64 MessageId;
145         union {
146                 struct {
147                         __le32 ProcessId;
148                         __le32  TreeId;
149                 } __packed SyncId;
150                 __le64  AsyncId;
151         } __packed Id;
152         __le64  SessionId;
153         __u8   Signature[16];
154 } __packed;
155
156 struct smb2_pdu {
157         struct smb2_hdr hdr;
158         __le16 StructureSize2; /* size of wct area (varies, request specific) */
159 } __packed;
160
161 #define SMB3_AES_CCM_NONCE 11
162 #define SMB3_AES_GCM_NONCE 12
163
164 struct smb2_transform_hdr {
165         __be32 smb2_buf_length; /* big endian on wire */
166         /*
167          * length is only two or three bytes - with
168          * one or two byte type preceding it that MBZ
169          */
170         __le32 ProtocolId;      /* 0xFD 'S' 'M' 'B' */
171         __u8   Signature[16];
172         __u8   Nonce[16];
173         __le32 OriginalMessageSize;
174         __u16  Reserved1;
175         __le16 Flags; /* EncryptionAlgorithm */
176         __le64  SessionId;
177 } __packed;
178
179 /*
180  *      SMB2 flag definitions
181  */
182 #define SMB2_FLAGS_SERVER_TO_REDIR      cpu_to_le32(0x00000001)
183 #define SMB2_FLAGS_ASYNC_COMMAND        cpu_to_le32(0x00000002)
184 #define SMB2_FLAGS_RELATED_OPERATIONS   cpu_to_le32(0x00000004)
185 #define SMB2_FLAGS_SIGNED               cpu_to_le32(0x00000008)
186 #define SMB2_FLAGS_DFS_OPERATIONS       cpu_to_le32(0x10000000)
187 #define SMB2_FLAGS_REPLAY_OPERATIONS    cpu_to_le32(0x20000000)
188
189 /*
190  *      Definitions for SMB2 Protocol Data Units (network frames)
191  *
192  *  See MS-SMB2.PDF specification for protocol details.
193  *  The Naming convention is the lower case version of the SMB2
194  *  command code name for the struct. Note that structures must be packed.
195  *
196  */
197
198 #define SMB2_ERROR_STRUCTURE_SIZE2      9
199 #define SMB2_ERROR_STRUCTURE_SIZE2_LE   cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
200
201 struct smb2_err_rsp {
202         struct smb2_hdr hdr;
203         __le16 StructureSize;
204         __u8   ErrorContextCount;
205         __u8   Reserved;
206         __le32 ByteCount;  /* even if zero, at least one byte follows */
207         __u8   ErrorData[1];  /* variable length */
208 } __packed;
209
210 struct smb2_negotiate_req {
211         struct smb2_hdr hdr;
212         __le16 StructureSize; /* Must be 36 */
213         __le16 DialectCount;
214         __le16 SecurityMode;
215         __le16 Reserved;        /* MBZ */
216         __le32 Capabilities;
217         __u8   ClientGUID[SMB2_CLIENT_GUID_SIZE];
218         /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
219         __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
220         __le16 NegotiateContextCount;  /* SMB3.1.1 only. MBZ earlier */
221         __le16 Reserved2;
222         __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
223 } __packed;
224
225 /* SecurityMode flags */
226 #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE       cpu_to_le16(0x0001)
227 #define SMB2_NEGOTIATE_SIGNING_REQUIRED         0x0002
228 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE      cpu_to_le16(0x0002)
229 /* Capabilities flags */
230 #define SMB2_GLOBAL_CAP_DFS             0x00000001
231 #define SMB2_GLOBAL_CAP_LEASING         0x00000002 /* Resp only New to SMB2.1 */
232 #define SMB2_GLOBAL_CAP_LARGE_MTU       0X00000004 /* Resp only New to SMB2.1 */
233 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL   0x00000008 /* New to SMB3 */
234 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
235 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING  0x00000020 /* New to SMB3 */
236 #define SMB2_GLOBAL_CAP_ENCRYPTION      0x00000040 /* New to SMB3 */
237 /* Internal types */
238 #define SMB2_NT_FIND                    0x00100000
239 #define SMB2_LARGE_FILES                0x00200000
240
241 #define SMB311_SALT_SIZE                        32
242 /* Hash Algorithm Types */
243 #define SMB2_PREAUTH_INTEGRITY_SHA512   cpu_to_le16(0x0001)
244
245 #define PREAUTH_HASHVALUE_SIZE          64
246
247 struct preauth_integrity_info {
248         /* PreAuth integrity Hash ID */
249         __le16                  Preauth_HashId;
250         /* PreAuth integrity Hash Value */
251         __u8                    Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
252 };
253
254 /* offset is sizeof smb2_negotiate_rsp - 4 but rounded up to 8 bytes. */
255 #ifdef CONFIG_SMB_SERVER_KERBEROS5
256 /* sizeof(struct smb2_negotiate_rsp) - 4 =
257  * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
258  */
259 #define OFFSET_OF_NEG_CONTEXT   0xe0
260 #else
261 /* sizeof(struct smb2_negotiate_rsp) - 4 =
262  * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
263  */
264 #define OFFSET_OF_NEG_CONTEXT   0xd0
265 #endif
266
267 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES     cpu_to_le16(1)
268 #define SMB2_ENCRYPTION_CAPABILITIES            cpu_to_le16(2)
269 #define SMB2_COMPRESSION_CAPABILITIES           cpu_to_le16(3)
270 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID       cpu_to_le16(5)
271 #define SMB2_SIGNING_CAPABILITIES               cpu_to_le16(8)
272 #define SMB2_POSIX_EXTENSIONS_AVAILABLE         cpu_to_le16(0x100)
273
274 struct smb2_neg_context {
275         __le16  ContextType;
276         __le16  DataLength;
277         __le32  Reserved;
278         /* Followed by array of data */
279 } __packed;
280
281 struct smb2_preauth_neg_context {
282         __le16  ContextType; /* 1 */
283         __le16  DataLength;
284         __le32  Reserved;
285         __le16  HashAlgorithmCount; /* 1 */
286         __le16  SaltLength;
287         __le16  HashAlgorithms; /* HashAlgorithms[0] since only one defined */
288         __u8    Salt[SMB311_SALT_SIZE];
289 } __packed;
290
291 /* Encryption Algorithms Ciphers */
292 #define SMB2_ENCRYPTION_AES128_CCM      cpu_to_le16(0x0001)
293 #define SMB2_ENCRYPTION_AES128_GCM      cpu_to_le16(0x0002)
294 #define SMB2_ENCRYPTION_AES256_CCM      cpu_to_le16(0x0003)
295 #define SMB2_ENCRYPTION_AES256_GCM      cpu_to_le16(0x0004)
296
297 struct smb2_encryption_neg_context {
298         __le16  ContextType; /* 2 */
299         __le16  DataLength;
300         __le32  Reserved;
301         /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
302         __le16  CipherCount; /* AES-128-GCM and AES-128-CCM by default */
303         __le16  Ciphers[];
304 } __packed;
305
306 #define SMB3_COMPRESS_NONE      cpu_to_le16(0x0000)
307 #define SMB3_COMPRESS_LZNT1     cpu_to_le16(0x0001)
308 #define SMB3_COMPRESS_LZ77      cpu_to_le16(0x0002)
309 #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
310
311 struct smb2_compression_ctx {
312         __le16  ContextType; /* 3 */
313         __le16  DataLength;
314         __le32  Reserved;
315         __le16  CompressionAlgorithmCount;
316         __u16   Padding;
317         __le32  Reserved1;
318         __le16  CompressionAlgorithms[];
319 } __packed;
320
321 #define POSIX_CTXT_DATA_LEN     16
322 struct smb2_posix_neg_context {
323         __le16  ContextType; /* 0x100 */
324         __le16  DataLength;
325         __le32  Reserved;
326         __u8    Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
327 } __packed;
328
329 struct smb2_netname_neg_context {
330         __le16  ContextType; /* 0x100 */
331         __le16  DataLength;
332         __le32  Reserved;
333         __le16  NetName[]; /* hostname of target converted to UCS-2 */
334 } __packed;
335
336 /* Signing algorithms */
337 #define SIGNING_ALG_HMAC_SHA256         cpu_to_le16(0)
338 #define SIGNING_ALG_AES_CMAC            cpu_to_le16(1)
339 #define SIGNING_ALG_AES_GMAC            cpu_to_le16(2)
340
341 struct smb2_signing_capabilities {
342         __le16  ContextType; /* 8 */
343         __le16  DataLength;
344         __le32  Reserved;
345         __le16  SigningAlgorithmCount;
346         __le16  SigningAlgorithms[];
347 } __packed;
348
349 struct smb2_negotiate_rsp {
350         struct smb2_hdr hdr;
351         __le16 StructureSize;   /* Must be 65 */
352         __le16 SecurityMode;
353         __le16 DialectRevision;
354         __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
355         __u8   ServerGUID[16];
356         __le32 Capabilities;
357         __le32 MaxTransactSize;
358         __le32 MaxReadSize;
359         __le32 MaxWriteSize;
360         __le64 SystemTime;      /* MBZ */
361         __le64 ServerStartTime;
362         __le16 SecurityBufferOffset;
363         __le16 SecurityBufferLength;
364         __le32 NegotiateContextOffset;  /* Pre:SMB3.1.1 was reserved/ignored */
365         __u8   Buffer[1];       /* variable length GSS security buffer */
366 } __packed;
367
368 /* Flags */
369 #define SMB2_SESSION_REQ_FLAG_BINDING           0x01
370 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA      0x04
371
372 #define SMB2_SESSION_EXPIRED            (0)
373 #define SMB2_SESSION_IN_PROGRESS        BIT(0)
374 #define SMB2_SESSION_VALID              BIT(1)
375
376 /* Flags */
377 #define SMB2_SESSION_REQ_FLAG_BINDING           0x01
378 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA      0x04
379
380 struct smb2_sess_setup_req {
381         struct smb2_hdr hdr;
382         __le16 StructureSize; /* Must be 25 */
383         __u8   Flags;
384         __u8   SecurityMode;
385         __le32 Capabilities;
386         __le32 Channel;
387         __le16 SecurityBufferOffset;
388         __le16 SecurityBufferLength;
389         __le64 PreviousSessionId;
390         __u8   Buffer[1];       /* variable length GSS security buffer */
391 } __packed;
392
393 /* Flags/Reserved for SMB3.1.1 */
394 #define SMB2_SHAREFLAG_CLUSTER_RECONNECT        0x0001
395
396 /* Currently defined SessionFlags */
397 #define SMB2_SESSION_FLAG_IS_GUEST_LE           cpu_to_le16(0x0001)
398 #define SMB2_SESSION_FLAG_IS_NULL_LE            cpu_to_le16(0x0002)
399 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE       cpu_to_le16(0x0004)
400 struct smb2_sess_setup_rsp {
401         struct smb2_hdr hdr;
402         __le16 StructureSize; /* Must be 9 */
403         __le16 SessionFlags;
404         __le16 SecurityBufferOffset;
405         __le16 SecurityBufferLength;
406         __u8   Buffer[1];       /* variable length GSS security buffer */
407 } __packed;
408
409 struct smb2_logoff_req {
410         struct smb2_hdr hdr;
411         __le16 StructureSize;   /* Must be 4 */
412         __le16 Reserved;
413 } __packed;
414
415 struct smb2_logoff_rsp {
416         struct smb2_hdr hdr;
417         __le16 StructureSize;   /* Must be 4 */
418         __le16 Reserved;
419 } __packed;
420
421 struct smb2_tree_connect_req {
422         struct smb2_hdr hdr;
423         __le16 StructureSize;   /* Must be 9 */
424         __le16 Reserved;        /* Flags in SMB3.1.1 */
425         __le16 PathOffset;
426         __le16 PathLength;
427         __u8   Buffer[1];       /* variable length */
428 } __packed;
429
430 struct smb2_tree_connect_rsp {
431         struct smb2_hdr hdr;
432         __le16 StructureSize;   /* Must be 16 */
433         __u8   ShareType;  /* see below */
434         __u8   Reserved;
435         __le32 ShareFlags; /* see below */
436         __le32 Capabilities; /* see below */
437         __le32 MaximalAccess;
438 } __packed;
439
440 /* Possible ShareType values */
441 #define SMB2_SHARE_TYPE_DISK    0x01
442 #define SMB2_SHARE_TYPE_PIPE    0x02
443 #define SMB2_SHARE_TYPE_PRINT   0x03
444
445 /*
446  * Possible ShareFlags - exactly one and only one of the first 4 caching flags
447  * must be set (any of the remaining, SHI1005, flags may be set individually
448  * or in combination.
449  */
450 #define SMB2_SHAREFLAG_MANUAL_CACHING                   0x00000000
451 #define SMB2_SHAREFLAG_AUTO_CACHING                     0x00000010
452 #define SMB2_SHAREFLAG_VDO_CACHING                      0x00000020
453 #define SMB2_SHAREFLAG_NO_CACHING                       0x00000030
454 #define SHI1005_FLAGS_DFS                               0x00000001
455 #define SHI1005_FLAGS_DFS_ROOT                          0x00000002
456 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS          0x00000100
457 #define SHI1005_FLAGS_FORCE_SHARED_DELETE               0x00000200
458 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING           0x00000400
459 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM       0x00000800
460 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK              0x00001000
461 #define SHI1005_FLAGS_ENABLE_HASH                       0x00002000
462
463 /* Possible share capabilities */
464 #define SMB2_SHARE_CAP_DFS      cpu_to_le32(0x00000008)
465
466 struct smb2_tree_disconnect_req {
467         struct smb2_hdr hdr;
468         __le16 StructureSize;   /* Must be 4 */
469         __le16 Reserved;
470 } __packed;
471
472 struct smb2_tree_disconnect_rsp {
473         struct smb2_hdr hdr;
474         __le16 StructureSize;   /* Must be 4 */
475         __le16 Reserved;
476 } __packed;
477
478 #define ATTR_READONLY_LE        cpu_to_le32(ATTR_READONLY)
479 #define ATTR_HIDDEN_LE          cpu_to_le32(ATTR_HIDDEN)
480 #define ATTR_SYSTEM_LE          cpu_to_le32(ATTR_SYSTEM)
481 #define ATTR_DIRECTORY_LE       cpu_to_le32(ATTR_DIRECTORY)
482 #define ATTR_ARCHIVE_LE         cpu_to_le32(ATTR_ARCHIVE)
483 #define ATTR_NORMAL_LE          cpu_to_le32(ATTR_NORMAL)
484 #define ATTR_TEMPORARY_LE       cpu_to_le32(ATTR_TEMPORARY)
485 #define ATTR_SPARSE_FILE_LE     cpu_to_le32(ATTR_SPARSE)
486 #define ATTR_REPARSE_POINT_LE   cpu_to_le32(ATTR_REPARSE)
487 #define ATTR_COMPRESSED_LE      cpu_to_le32(ATTR_COMPRESSED)
488 #define ATTR_OFFLINE_LE         cpu_to_le32(ATTR_OFFLINE)
489 #define ATTR_NOT_CONTENT_INDEXED_LE     cpu_to_le32(ATTR_NOT_CONTENT_INDEXED)
490 #define ATTR_ENCRYPTED_LE       cpu_to_le32(ATTR_ENCRYPTED)
491 #define ATTR_INTEGRITY_STREAML_LE       cpu_to_le32(0x00008000)
492 #define ATTR_NO_SCRUB_DATA_LE   cpu_to_le32(0x00020000)
493 #define ATTR_MASK_LE            cpu_to_le32(0x00007FB7)
494
495 /* Oplock levels */
496 #define SMB2_OPLOCK_LEVEL_NONE          0x00
497 #define SMB2_OPLOCK_LEVEL_II            0x01
498 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE     0x08
499 #define SMB2_OPLOCK_LEVEL_BATCH         0x09
500 #define SMB2_OPLOCK_LEVEL_LEASE         0xFF
501 /* Non-spec internal type */
502 #define SMB2_OPLOCK_LEVEL_NOCHANGE      0x99
503
504 /* Desired Access Flags */
505 #define FILE_READ_DATA_LE               cpu_to_le32(0x00000001)
506 #define FILE_LIST_DIRECTORY_LE          cpu_to_le32(0x00000001)
507 #define FILE_WRITE_DATA_LE              cpu_to_le32(0x00000002)
508 #define FILE_ADD_FILE_LE                cpu_to_le32(0x00000002)
509 #define FILE_APPEND_DATA_LE             cpu_to_le32(0x00000004)
510 #define FILE_ADD_SUBDIRECTORY_LE        cpu_to_le32(0x00000004)
511 #define FILE_READ_EA_LE                 cpu_to_le32(0x00000008)
512 #define FILE_WRITE_EA_LE                cpu_to_le32(0x00000010)
513 #define FILE_EXECUTE_LE                 cpu_to_le32(0x00000020)
514 #define FILE_TRAVERSE_LE                cpu_to_le32(0x00000020)
515 #define FILE_DELETE_CHILD_LE            cpu_to_le32(0x00000040)
516 #define FILE_READ_ATTRIBUTES_LE         cpu_to_le32(0x00000080)
517 #define FILE_WRITE_ATTRIBUTES_LE        cpu_to_le32(0x00000100)
518 #define FILE_DELETE_LE                  cpu_to_le32(0x00010000)
519 #define FILE_READ_CONTROL_LE            cpu_to_le32(0x00020000)
520 #define FILE_WRITE_DAC_LE               cpu_to_le32(0x00040000)
521 #define FILE_WRITE_OWNER_LE             cpu_to_le32(0x00080000)
522 #define FILE_SYNCHRONIZE_LE             cpu_to_le32(0x00100000)
523 #define FILE_ACCESS_SYSTEM_SECURITY_LE  cpu_to_le32(0x01000000)
524 #define FILE_MAXIMAL_ACCESS_LE          cpu_to_le32(0x02000000)
525 #define FILE_GENERIC_ALL_LE             cpu_to_le32(0x10000000)
526 #define FILE_GENERIC_EXECUTE_LE         cpu_to_le32(0x20000000)
527 #define FILE_GENERIC_WRITE_LE           cpu_to_le32(0x40000000)
528 #define FILE_GENERIC_READ_LE            cpu_to_le32(0x80000000)
529 #define DESIRED_ACCESS_MASK             cpu_to_le32(0xF21F01FF)
530
531 /* ShareAccess Flags */
532 #define FILE_SHARE_READ_LE              cpu_to_le32(0x00000001)
533 #define FILE_SHARE_WRITE_LE             cpu_to_le32(0x00000002)
534 #define FILE_SHARE_DELETE_LE            cpu_to_le32(0x00000004)
535 #define FILE_SHARE_ALL_LE               cpu_to_le32(0x00000007)
536
537 /* CreateDisposition Flags */
538 #define FILE_SUPERSEDE_LE               cpu_to_le32(0x00000000)
539 #define FILE_OPEN_LE                    cpu_to_le32(0x00000001)
540 #define FILE_CREATE_LE                  cpu_to_le32(0x00000002)
541 #define FILE_OPEN_IF_LE                 cpu_to_le32(0x00000003)
542 #define FILE_OVERWRITE_LE               cpu_to_le32(0x00000004)
543 #define FILE_OVERWRITE_IF_LE            cpu_to_le32(0x00000005)
544 #define FILE_CREATE_MASK_LE             cpu_to_le32(0x00000007)
545
546 #define FILE_READ_DESIRED_ACCESS_LE     (FILE_READ_DATA_LE |            \
547                                         FILE_READ_EA_LE |               \
548                                         FILE_GENERIC_READ_LE)
549 #define FILE_WRITE_DESIRE_ACCESS_LE     (FILE_WRITE_DATA_LE |           \
550                                         FILE_APPEND_DATA_LE |           \
551                                         FILE_WRITE_EA_LE |              \
552                                         FILE_WRITE_ATTRIBUTES_LE |      \
553                                         FILE_GENERIC_WRITE_LE)
554
555 /* Impersonation Levels */
556 #define IL_ANONYMOUS_LE         cpu_to_le32(0x00000000)
557 #define IL_IDENTIFICATION_LE    cpu_to_le32(0x00000001)
558 #define IL_IMPERSONATION_LE     cpu_to_le32(0x00000002)
559 #define IL_DELEGATE_LE          cpu_to_le32(0x00000003)
560
561 /* Create Context Values */
562 #define SMB2_CREATE_EA_BUFFER                   "ExtA" /* extended attributes */
563 #define SMB2_CREATE_SD_BUFFER                   "SecD" /* security descriptor */
564 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST      "DHnQ"
565 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT    "DHnC"
566 #define SMB2_CREATE_ALLOCATION_SIZE             "AlSi"
567 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
568 #define SMB2_CREATE_TIMEWARP_REQUEST            "TWrp"
569 #define SMB2_CREATE_QUERY_ON_DISK_ID            "QFid"
570 #define SMB2_CREATE_REQUEST_LEASE               "RqLs"
571 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2   "DH2Q"
572 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
573 #define SMB2_CREATE_APP_INSTANCE_ID     "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
574  #define SMB2_CREATE_APP_INSTANCE_VERSION       "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
575 #define SVHDX_OPEN_DEVICE_CONTEXT       0x83CE6F1AD851E0986E34401CC9BCFCE9
576 #define SMB2_CREATE_TAG_POSIX           "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
577
578 struct smb2_create_req {
579         struct smb2_hdr hdr;
580         __le16 StructureSize;   /* Must be 57 */
581         __u8   SecurityFlags;
582         __u8   RequestedOplockLevel;
583         __le32 ImpersonationLevel;
584         __le64 SmbCreateFlags;
585         __le64 Reserved;
586         __le32 DesiredAccess;
587         __le32 FileAttributes;
588         __le32 ShareAccess;
589         __le32 CreateDisposition;
590         __le32 CreateOptions;
591         __le16 NameOffset;
592         __le16 NameLength;
593         __le32 CreateContextsOffset;
594         __le32 CreateContextsLength;
595         __u8   Buffer[0];
596 } __packed;
597
598 struct smb2_create_rsp {
599         struct smb2_hdr hdr;
600         __le16 StructureSize;   /* Must be 89 */
601         __u8   OplockLevel;
602         __u8   Reserved;
603         __le32 CreateAction;
604         __le64 CreationTime;
605         __le64 LastAccessTime;
606         __le64 LastWriteTime;
607         __le64 ChangeTime;
608         __le64 AllocationSize;
609         __le64 EndofFile;
610         __le32 FileAttributes;
611         __le32 Reserved2;
612         __le64  PersistentFileId;
613         __le64  VolatileFileId;
614         __le32 CreateContextsOffset;
615         __le32 CreateContextsLength;
616         __u8   Buffer[1];
617 } __packed;
618
619 struct create_context {
620         __le32 Next;
621         __le16 NameOffset;
622         __le16 NameLength;
623         __le16 Reserved;
624         __le16 DataOffset;
625         __le32 DataLength;
626         __u8 Buffer[0];
627 } __packed;
628
629 struct create_durable_req_v2 {
630         struct create_context ccontext;
631         __u8   Name[8];
632         __le32 Timeout;
633         __le32 Flags;
634         __u8 Reserved[8];
635         __u8 CreateGuid[16];
636 } __packed;
637
638 struct create_durable_reconn_req {
639         struct create_context ccontext;
640         __u8   Name[8];
641         union {
642                 __u8  Reserved[16];
643                 struct {
644                         __le64 PersistentFileId;
645                         __le64 VolatileFileId;
646                 } Fid;
647         } Data;
648 } __packed;
649
650 struct create_durable_reconn_v2_req {
651         struct create_context ccontext;
652         __u8   Name[8];
653         struct {
654                 __le64 PersistentFileId;
655                 __le64 VolatileFileId;
656         } Fid;
657         __u8 CreateGuid[16];
658         __le32 Flags;
659 } __packed;
660
661 struct create_app_inst_id {
662         struct create_context ccontext;
663         __u8 Name[8];
664         __u8 Reserved[8];
665         __u8 AppInstanceId[16];
666 } __packed;
667
668 struct create_app_inst_id_vers {
669         struct create_context ccontext;
670         __u8 Name[8];
671         __u8 Reserved[2];
672         __u8 Padding[4];
673         __le64 AppInstanceVersionHigh;
674         __le64 AppInstanceVersionLow;
675 } __packed;
676
677 struct create_mxac_req {
678         struct create_context ccontext;
679         __u8   Name[8];
680         __le64 Timestamp;
681 } __packed;
682
683 struct create_alloc_size_req {
684         struct create_context ccontext;
685         __u8   Name[8];
686         __le64 AllocationSize;
687 } __packed;
688
689 struct create_posix {
690         struct create_context ccontext;
691         __u8    Name[16];
692         __le32  Mode;
693         __u32   Reserved;
694 } __packed;
695
696 struct create_durable_rsp {
697         struct create_context ccontext;
698         __u8   Name[8];
699         union {
700                 __u8  Reserved[8];
701                 __u64 data;
702         } Data;
703 } __packed;
704
705 struct create_durable_v2_rsp {
706         struct create_context ccontext;
707         __u8   Name[8];
708         __le32 Timeout;
709         __le32 Flags;
710 } __packed;
711
712 struct create_mxac_rsp {
713         struct create_context ccontext;
714         __u8   Name[8];
715         __le32 QueryStatus;
716         __le32 MaximalAccess;
717 } __packed;
718
719 struct create_disk_id_rsp {
720         struct create_context ccontext;
721         __u8   Name[8];
722         __le64 DiskFileId;
723         __le64 VolumeId;
724         __u8  Reserved[16];
725 } __packed;
726
727 /* equivalent of the contents of SMB3.1.1 POSIX open context response */
728 struct create_posix_rsp {
729         struct create_context ccontext;
730         __u8    Name[16];
731         __le32 nlink;
732         __le32 reparse_tag;
733         __le32 mode;
734         u8 SidBuffer[40];
735 } __packed;
736
737 #define SMB2_LEASE_NONE_LE                      cpu_to_le32(0x00)
738 #define SMB2_LEASE_READ_CACHING_LE              cpu_to_le32(0x01)
739 #define SMB2_LEASE_HANDLE_CACHING_LE            cpu_to_le32(0x02)
740 #define SMB2_LEASE_WRITE_CACHING_LE             cpu_to_le32(0x04)
741
742 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE    cpu_to_le32(0x02)
743
744 struct lease_context {
745         __le64 LeaseKeyLow;
746         __le64 LeaseKeyHigh;
747         __le32 LeaseState;
748         __le32 LeaseFlags;
749         __le64 LeaseDuration;
750 } __packed;
751
752 struct lease_context_v2 {
753         __le64 LeaseKeyLow;
754         __le64 LeaseKeyHigh;
755         __le32 LeaseState;
756         __le32 LeaseFlags;
757         __le64 LeaseDuration;
758         __le64 ParentLeaseKeyLow;
759         __le64 ParentLeaseKeyHigh;
760         __le16 Epoch;
761         __le16 Reserved;
762 } __packed;
763
764 struct create_lease {
765         struct create_context ccontext;
766         __u8   Name[8];
767         struct lease_context lcontext;
768 } __packed;
769
770 struct create_lease_v2 {
771         struct create_context ccontext;
772         __u8   Name[8];
773         struct lease_context_v2 lcontext;
774         __u8   Pad[4];
775 } __packed;
776
777 /* Currently defined values for close flags */
778 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB        cpu_to_le16(0x0001)
779 struct smb2_close_req {
780         struct smb2_hdr hdr;
781         __le16 StructureSize;   /* Must be 24 */
782         __le16 Flags;
783         __le32 Reserved;
784         __le64  PersistentFileId;
785         __le64  VolatileFileId;
786 } __packed;
787
788 struct smb2_close_rsp {
789         struct smb2_hdr hdr;
790         __le16 StructureSize; /* 60 */
791         __le16 Flags;
792         __le32 Reserved;
793         __le64 CreationTime;
794         __le64 LastAccessTime;
795         __le64 LastWriteTime;
796         __le64 ChangeTime;
797         __le64 AllocationSize;  /* Beginning of FILE_STANDARD_INFO equivalent */
798         __le64 EndOfFile;
799         __le32 Attributes;
800 } __packed;
801
802 struct smb2_flush_req {
803         struct smb2_hdr hdr;
804         __le16 StructureSize;   /* Must be 24 */
805         __le16 Reserved1;
806         __le32 Reserved2;
807         __le64  PersistentFileId;
808         __le64  VolatileFileId;
809 } __packed;
810
811 struct smb2_flush_rsp {
812         struct smb2_hdr hdr;
813         __le16 StructureSize;
814         __le16 Reserved;
815 } __packed;
816
817 struct smb2_buffer_desc_v1 {
818         __le64 offset;
819         __le32 token;
820         __le32 length;
821 } __packed;
822
823 #define SMB2_CHANNEL_NONE               cpu_to_le32(0x00000000)
824 #define SMB2_CHANNEL_RDMA_V1            cpu_to_le32(0x00000001)
825 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
826
827 struct smb2_read_req {
828         struct smb2_hdr hdr;
829         __le16 StructureSize; /* Must be 49 */
830         __u8   Padding; /* offset from start of SMB2 header to place read */
831         __u8   Reserved;
832         __le32 Length;
833         __le64 Offset;
834         __le64  PersistentFileId;
835         __le64  VolatileFileId;
836         __le32 MinimumCount;
837         __le32 Channel; /* Reserved MBZ */
838         __le32 RemainingBytes;
839         __le16 ReadChannelInfoOffset; /* Reserved MBZ */
840         __le16 ReadChannelInfoLength; /* Reserved MBZ */
841         __u8   Buffer[1];
842 } __packed;
843
844 struct smb2_read_rsp {
845         struct smb2_hdr hdr;
846         __le16 StructureSize; /* Must be 17 */
847         __u8   DataOffset;
848         __u8   Reserved;
849         __le32 DataLength;
850         __le32 DataRemaining;
851         __u32  Reserved2;
852         __u8   Buffer[1];
853 } __packed;
854
855 /* For write request Flags field below the following flag is defined: */
856 #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001
857
858 struct smb2_write_req {
859         struct smb2_hdr hdr;
860         __le16 StructureSize; /* Must be 49 */
861         __le16 DataOffset; /* offset from start of SMB2 header to write data */
862         __le32 Length;
863         __le64 Offset;
864         __le64  PersistentFileId;
865         __le64  VolatileFileId;
866         __le32 Channel; /* Reserved MBZ */
867         __le32 RemainingBytes;
868         __le16 WriteChannelInfoOffset; /* Reserved MBZ */
869         __le16 WriteChannelInfoLength; /* Reserved MBZ */
870         __le32 Flags;
871         __u8   Buffer[1];
872 } __packed;
873
874 struct smb2_write_rsp {
875         struct smb2_hdr hdr;
876         __le16 StructureSize; /* Must be 17 */
877         __u8   DataOffset;
878         __u8   Reserved;
879         __le32 DataLength;
880         __le32 DataRemaining;
881         __u32  Reserved2;
882         __u8   Buffer[1];
883 } __packed;
884
885 #define SMB2_0_IOCTL_IS_FSCTL 0x00000001
886
887 struct duplicate_extents_to_file {
888         __u64 PersistentFileHandle; /* source file handle, opaque endianness */
889         __u64 VolatileFileHandle;
890         __le64 SourceFileOffset;
891         __le64 TargetFileOffset;
892         __le64 ByteCount;  /* Bytes to be copied */
893 } __packed;
894
895 struct smb2_ioctl_req {
896         struct smb2_hdr hdr;
897         __le16 StructureSize; /* Must be 57 */
898         __le16 Reserved; /* offset from start of SMB2 header to write data */
899         __le32 CntCode;
900         __le64  PersistentFileId;
901         __le64  VolatileFileId;
902         __le32 InputOffset; /* Reserved MBZ */
903         __le32 InputCount;
904         __le32 MaxInputResponse;
905         __le32 OutputOffset;
906         __le32 OutputCount;
907         __le32 MaxOutputResponse;
908         __le32 Flags;
909         __le32 Reserved2;
910         __u8   Buffer[1];
911 } __packed;
912
913 struct smb2_ioctl_rsp {
914         struct smb2_hdr hdr;
915         __le16 StructureSize; /* Must be 49 */
916         __le16 Reserved; /* offset from start of SMB2 header to write data */
917         __le32 CntCode;
918         __le64  PersistentFileId;
919         __le64  VolatileFileId;
920         __le32 InputOffset; /* Reserved MBZ */
921         __le32 InputCount;
922         __le32 OutputOffset;
923         __le32 OutputCount;
924         __le32 Flags;
925         __le32 Reserved2;
926         __u8   Buffer[1];
927 } __packed;
928
929 struct validate_negotiate_info_req {
930         __le32 Capabilities;
931         __u8   Guid[SMB2_CLIENT_GUID_SIZE];
932         __le16 SecurityMode;
933         __le16 DialectCount;
934         __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */
935 } __packed;
936
937 struct validate_negotiate_info_rsp {
938         __le32 Capabilities;
939         __u8   Guid[SMB2_CLIENT_GUID_SIZE];
940         __le16 SecurityMode;
941         __le16 Dialect; /* Dialect in use for the connection */
942 } __packed;
943
944 struct smb_sockaddr_in {
945         __be16 Port;
946         __be32 IPv4address;
947         __u8 Reserved[8];
948 } __packed;
949
950 struct smb_sockaddr_in6 {
951         __be16 Port;
952         __be32 FlowInfo;
953         __u8 IPv6address[16];
954         __be32 ScopeId;
955 } __packed;
956
957 #define INTERNETWORK    0x0002
958 #define INTERNETWORKV6  0x0017
959
960 struct sockaddr_storage_rsp {
961         __le16 Family;
962         union {
963                 struct smb_sockaddr_in addr4;
964                 struct smb_sockaddr_in6 addr6;
965         };
966 } __packed;
967
968 #define RSS_CAPABLE     0x00000001
969 #define RDMA_CAPABLE    0x00000002
970
971 struct network_interface_info_ioctl_rsp {
972         __le32 Next; /* next interface. zero if this is last one */
973         __le32 IfIndex;
974         __le32 Capability; /* RSS or RDMA Capable */
975         __le32 Reserved;
976         __le64 LinkSpeed;
977         char    SockAddr_Storage[128];
978 } __packed;
979
980 struct file_object_buf_type1_ioctl_rsp {
981         __u8 ObjectId[16];
982         __u8 BirthVolumeId[16];
983         __u8 BirthObjectId[16];
984         __u8 DomainId[16];
985 } __packed;
986
987 struct resume_key_ioctl_rsp {
988         __le64 ResumeKey[3];
989         __le32 ContextLength;
990         __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
991 } __packed;
992
993 struct copychunk_ioctl_req {
994         __le64 ResumeKey[3];
995         __le32 ChunkCount;
996         __le32 Reserved;
997         __u8 Chunks[1]; /* array of srv_copychunk */
998 } __packed;
999
1000 struct srv_copychunk {
1001         __le64 SourceOffset;
1002         __le64 TargetOffset;
1003         __le32 Length;
1004         __le32 Reserved;
1005 } __packed;
1006
1007 struct copychunk_ioctl_rsp {
1008         __le32 ChunksWritten;
1009         __le32 ChunkBytesWritten;
1010         __le32 TotalBytesWritten;
1011 } __packed;
1012
1013 struct file_sparse {
1014         __u8    SetSparse;
1015 } __packed;
1016
1017 struct file_zero_data_information {
1018         __le64  FileOffset;
1019         __le64  BeyondFinalZero;
1020 } __packed;
1021
1022 struct file_allocated_range_buffer {
1023         __le64  file_offset;
1024         __le64  length;
1025 } __packed;
1026
1027 struct reparse_data_buffer {
1028         __le32  ReparseTag;
1029         __le16  ReparseDataLength;
1030         __u16   Reserved;
1031         __u8    DataBuffer[]; /* Variable Length */
1032 } __packed;
1033
1034 /* Completion Filter flags for Notify */
1035 #define FILE_NOTIFY_CHANGE_FILE_NAME    0x00000001
1036 #define FILE_NOTIFY_CHANGE_DIR_NAME     0x00000002
1037 #define FILE_NOTIFY_CHANGE_NAME         0x00000003
1038 #define FILE_NOTIFY_CHANGE_ATTRIBUTES   0x00000004
1039 #define FILE_NOTIFY_CHANGE_SIZE         0x00000008
1040 #define FILE_NOTIFY_CHANGE_LAST_WRITE   0x00000010
1041 #define FILE_NOTIFY_CHANGE_LAST_ACCESS  0x00000020
1042 #define FILE_NOTIFY_CHANGE_CREATION     0x00000040
1043 #define FILE_NOTIFY_CHANGE_EA           0x00000080
1044 #define FILE_NOTIFY_CHANGE_SECURITY     0x00000100
1045 #define FILE_NOTIFY_CHANGE_STREAM_NAME  0x00000200
1046 #define FILE_NOTIFY_CHANGE_STREAM_SIZE  0x00000400
1047 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1048
1049 /* Flags */
1050 #define SMB2_WATCH_TREE 0x0001
1051
1052 struct smb2_notify_req {
1053         struct smb2_hdr hdr;
1054         __le16 StructureSize; /* Must be 32 */
1055         __le16 Flags;
1056         __le32 OutputBufferLength;
1057         __le64 PersistentFileId;
1058         __le64 VolatileFileId;
1059         __u32 CompletionFileter;
1060         __u32 Reserved;
1061 } __packed;
1062
1063 struct smb2_notify_rsp {
1064         struct smb2_hdr hdr;
1065         __le16 StructureSize; /* Must be 9 */
1066         __le16 OutputBufferOffset;
1067         __le32 OutputBufferLength;
1068         __u8 Buffer[1];
1069 } __packed;
1070
1071 /* SMB2 Notify Action Flags */
1072 #define FILE_ACTION_ADDED               0x00000001
1073 #define FILE_ACTION_REMOVED             0x00000002
1074 #define FILE_ACTION_MODIFIED            0x00000003
1075 #define FILE_ACTION_RENAMED_OLD_NAME    0x00000004
1076 #define FILE_ACTION_RENAMED_NEW_NAME    0x00000005
1077 #define FILE_ACTION_ADDED_STREAM        0x00000006
1078 #define FILE_ACTION_REMOVED_STREAM      0x00000007
1079 #define FILE_ACTION_MODIFIED_STREAM     0x00000008
1080 #define FILE_ACTION_REMOVED_BY_DELETE   0x00000009
1081
1082 #define SMB2_LOCKFLAG_SHARED            0x0001
1083 #define SMB2_LOCKFLAG_EXCLUSIVE         0x0002
1084 #define SMB2_LOCKFLAG_UNLOCK            0x0004
1085 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY  0x0010
1086 #define SMB2_LOCKFLAG_MASK              0x0007
1087
1088 struct smb2_lock_element {
1089         __le64 Offset;
1090         __le64 Length;
1091         __le32 Flags;
1092         __le32 Reserved;
1093 } __packed;
1094
1095 struct smb2_lock_req {
1096         struct smb2_hdr hdr;
1097         __le16 StructureSize; /* Must be 48 */
1098         __le16 LockCount;
1099         __le32 Reserved;
1100         __le64  PersistentFileId;
1101         __le64  VolatileFileId;
1102         /* Followed by at least one */
1103         struct smb2_lock_element locks[1];
1104 } __packed;
1105
1106 struct smb2_lock_rsp {
1107         struct smb2_hdr hdr;
1108         __le16 StructureSize; /* Must be 4 */
1109         __le16 Reserved;
1110 } __packed;
1111
1112 struct smb2_echo_req {
1113         struct smb2_hdr hdr;
1114         __le16 StructureSize;   /* Must be 4 */
1115         __u16  Reserved;
1116 } __packed;
1117
1118 struct smb2_echo_rsp {
1119         struct smb2_hdr hdr;
1120         __le16 StructureSize;   /* Must be 4 */
1121         __u16  Reserved;
1122 } __packed;
1123
1124 /* search (query_directory) Flags field */
1125 #define SMB2_RESTART_SCANS              0x01
1126 #define SMB2_RETURN_SINGLE_ENTRY        0x02
1127 #define SMB2_INDEX_SPECIFIED            0x04
1128 #define SMB2_REOPEN                     0x10
1129
1130 struct smb2_query_directory_req {
1131         struct smb2_hdr hdr;
1132         __le16 StructureSize; /* Must be 33 */
1133         __u8   FileInformationClass;
1134         __u8   Flags;
1135         __le32 FileIndex;
1136         __le64  PersistentFileId;
1137         __le64  VolatileFileId;
1138         __le16 FileNameOffset;
1139         __le16 FileNameLength;
1140         __le32 OutputBufferLength;
1141         __u8   Buffer[1];
1142 } __packed;
1143
1144 struct smb2_query_directory_rsp {
1145         struct smb2_hdr hdr;
1146         __le16 StructureSize; /* Must be 9 */
1147         __le16 OutputBufferOffset;
1148         __le32 OutputBufferLength;
1149         __u8   Buffer[1];
1150 } __packed;
1151
1152 /* Possible InfoType values */
1153 #define SMB2_O_INFO_FILE        0x01
1154 #define SMB2_O_INFO_FILESYSTEM  0x02
1155 #define SMB2_O_INFO_SECURITY    0x03
1156 #define SMB2_O_INFO_QUOTA       0x04
1157
1158 /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
1159 #define OWNER_SECINFO   0x00000001
1160 #define GROUP_SECINFO   0x00000002
1161 #define DACL_SECINFO   0x00000004
1162 #define SACL_SECINFO   0x00000008
1163 #define LABEL_SECINFO   0x00000010
1164 #define ATTRIBUTE_SECINFO   0x00000020
1165 #define SCOPE_SECINFO   0x00000040
1166 #define BACKUP_SECINFO   0x00010000
1167 #define UNPROTECTED_SACL_SECINFO   0x10000000
1168 #define UNPROTECTED_DACL_SECINFO   0x20000000
1169 #define PROTECTED_SACL_SECINFO   0x40000000
1170 #define PROTECTED_DACL_SECINFO   0x80000000
1171
1172 struct smb2_query_info_req {
1173         struct smb2_hdr hdr;
1174         __le16 StructureSize; /* Must be 41 */
1175         __u8   InfoType;
1176         __u8   FileInfoClass;
1177         __le32 OutputBufferLength;
1178         __le16 InputBufferOffset;
1179         __u16  Reserved;
1180         __le32 InputBufferLength;
1181         __le32 AdditionalInformation;
1182         __le32 Flags;
1183         __le64  PersistentFileId;
1184         __le64  VolatileFileId;
1185         __u8   Buffer[1];
1186 } __packed;
1187
1188 struct smb2_query_info_rsp {
1189         struct smb2_hdr hdr;
1190         __le16 StructureSize; /* Must be 9 */
1191         __le16 OutputBufferOffset;
1192         __le32 OutputBufferLength;
1193         __u8   Buffer[1];
1194 } __packed;
1195
1196 struct smb2_set_info_req {
1197         struct smb2_hdr hdr;
1198         __le16 StructureSize; /* Must be 33 */
1199         __u8   InfoType;
1200         __u8   FileInfoClass;
1201         __le32 BufferLength;
1202         __le16 BufferOffset;
1203         __u16  Reserved;
1204         __le32 AdditionalInformation;
1205         __le64  PersistentFileId;
1206         __le64  VolatileFileId;
1207         __u8   Buffer[1];
1208 } __packed;
1209
1210 struct smb2_set_info_rsp {
1211         struct smb2_hdr hdr;
1212         __le16 StructureSize; /* Must be 2 */
1213 } __packed;
1214
1215 /* FILE Info response size */
1216 #define FILE_DIRECTORY_INFORMATION_SIZE       1
1217 #define FILE_FULL_DIRECTORY_INFORMATION_SIZE  2
1218 #define FILE_BOTH_DIRECTORY_INFORMATION_SIZE  3
1219 #define FILE_BASIC_INFORMATION_SIZE           40
1220 #define FILE_STANDARD_INFORMATION_SIZE        24
1221 #define FILE_INTERNAL_INFORMATION_SIZE        8
1222 #define FILE_EA_INFORMATION_SIZE              4
1223 #define FILE_ACCESS_INFORMATION_SIZE          4
1224 #define FILE_NAME_INFORMATION_SIZE            9
1225 #define FILE_RENAME_INFORMATION_SIZE          10
1226 #define FILE_LINK_INFORMATION_SIZE            11
1227 #define FILE_NAMES_INFORMATION_SIZE           12
1228 #define FILE_DISPOSITION_INFORMATION_SIZE     13
1229 #define FILE_POSITION_INFORMATION_SIZE        14
1230 #define FILE_FULL_EA_INFORMATION_SIZE         15
1231 #define FILE_MODE_INFORMATION_SIZE            4
1232 #define FILE_ALIGNMENT_INFORMATION_SIZE       4
1233 #define FILE_ALL_INFORMATION_SIZE             104
1234 #define FILE_ALLOCATION_INFORMATION_SIZE      19
1235 #define FILE_END_OF_FILE_INFORMATION_SIZE     20
1236 #define FILE_ALTERNATE_NAME_INFORMATION_SIZE  8
1237 #define FILE_STREAM_INFORMATION_SIZE          32
1238 #define FILE_PIPE_INFORMATION_SIZE            23
1239 #define FILE_PIPE_LOCAL_INFORMATION_SIZE      24
1240 #define FILE_PIPE_REMOTE_INFORMATION_SIZE     25
1241 #define FILE_MAILSLOT_QUERY_INFORMATION_SIZE  26
1242 #define FILE_MAILSLOT_SET_INFORMATION_SIZE    27
1243 #define FILE_COMPRESSION_INFORMATION_SIZE     16
1244 #define FILE_OBJECT_ID_INFORMATION_SIZE       29
1245 /* Number 30 not defined in documents */
1246 #define FILE_MOVE_CLUSTER_INFORMATION_SIZE    31
1247 #define FILE_QUOTA_INFORMATION_SIZE           32
1248 #define FILE_REPARSE_POINT_INFORMATION_SIZE   33
1249 #define FILE_NETWORK_OPEN_INFORMATION_SIZE    56
1250 #define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE   8
1251
1252 /* FS Info response  size */
1253 #define FS_DEVICE_INFORMATION_SIZE     8
1254 #define FS_ATTRIBUTE_INFORMATION_SIZE  16
1255 #define FS_VOLUME_INFORMATION_SIZE     24
1256 #define FS_SIZE_INFORMATION_SIZE       24
1257 #define FS_FULL_SIZE_INFORMATION_SIZE  32
1258 #define FS_SECTOR_SIZE_INFORMATION_SIZE 28
1259 #define FS_OBJECT_ID_INFORMATION_SIZE 64
1260 #define FS_CONTROL_INFORMATION_SIZE 48
1261 #define FS_POSIX_INFORMATION_SIZE 56
1262
1263 /* FS_ATTRIBUTE_File_System_Name */
1264 #define FS_TYPE_SUPPORT_SIZE   44
1265 struct fs_type_info {
1266         char            *fs_name;
1267         long            magic_number;
1268 } __packed;
1269
1270 struct smb2_oplock_break {
1271         struct smb2_hdr hdr;
1272         __le16 StructureSize; /* Must be 24 */
1273         __u8   OplockLevel;
1274         __u8   Reserved;
1275         __le32 Reserved2;
1276         __le64  PersistentFid;
1277         __le64  VolatileFid;
1278 } __packed;
1279
1280 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1281
1282 struct smb2_lease_break {
1283         struct smb2_hdr hdr;
1284         __le16 StructureSize; /* Must be 44 */
1285         __le16 Epoch;
1286         __le32 Flags;
1287         __u8   LeaseKey[16];
1288         __le32 CurrentLeaseState;
1289         __le32 NewLeaseState;
1290         __le32 BreakReason;
1291         __le32 AccessMaskHint;
1292         __le32 ShareMaskHint;
1293 } __packed;
1294
1295 struct smb2_lease_ack {
1296         struct smb2_hdr hdr;
1297         __le16 StructureSize; /* Must be 36 */
1298         __le16 Reserved;
1299         __le32 Flags;
1300         __u8   LeaseKey[16];
1301         __le32 LeaseState;
1302         __le64 LeaseDuration;
1303 } __packed;
1304
1305 /*
1306  *      PDU infolevel structure definitions
1307  *      BB consider moving to a different header
1308  */
1309
1310 /* File System Information Classes */
1311 #define FS_VOLUME_INFORMATION           1 /* Query */
1312 #define FS_LABEL_INFORMATION            2 /* Set */
1313 #define FS_SIZE_INFORMATION             3 /* Query */
1314 #define FS_DEVICE_INFORMATION           4 /* Query */
1315 #define FS_ATTRIBUTE_INFORMATION        5 /* Query */
1316 #define FS_CONTROL_INFORMATION          6 /* Query, Set */
1317 #define FS_FULL_SIZE_INFORMATION        7 /* Query */
1318 #define FS_OBJECT_ID_INFORMATION        8 /* Query, Set */
1319 #define FS_DRIVER_PATH_INFORMATION      9 /* Query */
1320 #define FS_SECTOR_SIZE_INFORMATION      11 /* SMB3 or later. Query */
1321 #define FS_POSIX_INFORMATION            100 /* SMB3.1.1 POSIX. Query */
1322
1323 struct smb2_fs_full_size_info {
1324         __le64 TotalAllocationUnits;
1325         __le64 CallerAvailableAllocationUnits;
1326         __le64 ActualAvailableAllocationUnits;
1327         __le32 SectorsPerAllocationUnit;
1328         __le32 BytesPerSector;
1329 } __packed;
1330
1331 #define SSINFO_FLAGS_ALIGNED_DEVICE             0x00000001
1332 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1333 #define SSINFO_FLAGS_NO_SEEK_PENALTY            0x00000004
1334 #define SSINFO_FLAGS_TRIM_ENABLED               0x00000008
1335
1336 /* sector size info struct */
1337 struct smb3_fs_ss_info {
1338         __le32 LogicalBytesPerSector;
1339         __le32 PhysicalBytesPerSectorForAtomicity;
1340         __le32 PhysicalBytesPerSectorForPerf;
1341         __le32 FSEffPhysicalBytesPerSectorForAtomicity;
1342         __le32 Flags;
1343         __le32 ByteOffsetForSectorAlignment;
1344         __le32 ByteOffsetForPartitionAlignment;
1345 } __packed;
1346
1347 /* File System Control Information */
1348 struct smb2_fs_control_info {
1349         __le64 FreeSpaceStartFiltering;
1350         __le64 FreeSpaceThreshold;
1351         __le64 FreeSpaceStopFiltering;
1352         __le64 DefaultQuotaThreshold;
1353         __le64 DefaultQuotaLimit;
1354         __le32 FileSystemControlFlags;
1355         __le32 Padding;
1356 } __packed;
1357
1358 /* partial list of QUERY INFO levels */
1359 #define FILE_DIRECTORY_INFORMATION      1
1360 #define FILE_FULL_DIRECTORY_INFORMATION 2
1361 #define FILE_BOTH_DIRECTORY_INFORMATION 3
1362 #define FILE_BASIC_INFORMATION          4
1363 #define FILE_STANDARD_INFORMATION       5
1364 #define FILE_INTERNAL_INFORMATION       6
1365 #define FILE_EA_INFORMATION             7
1366 #define FILE_ACCESS_INFORMATION         8
1367 #define FILE_NAME_INFORMATION           9
1368 #define FILE_RENAME_INFORMATION         10
1369 #define FILE_LINK_INFORMATION           11
1370 #define FILE_NAMES_INFORMATION          12
1371 #define FILE_DISPOSITION_INFORMATION    13
1372 #define FILE_POSITION_INFORMATION       14
1373 #define FILE_FULL_EA_INFORMATION        15
1374 #define FILE_MODE_INFORMATION           16
1375 #define FILE_ALIGNMENT_INFORMATION      17
1376 #define FILE_ALL_INFORMATION            18
1377 #define FILE_ALLOCATION_INFORMATION     19
1378 #define FILE_END_OF_FILE_INFORMATION    20
1379 #define FILE_ALTERNATE_NAME_INFORMATION 21
1380 #define FILE_STREAM_INFORMATION         22
1381 #define FILE_PIPE_INFORMATION           23
1382 #define FILE_PIPE_LOCAL_INFORMATION     24
1383 #define FILE_PIPE_REMOTE_INFORMATION    25
1384 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1385 #define FILE_MAILSLOT_SET_INFORMATION   27
1386 #define FILE_COMPRESSION_INFORMATION    28
1387 #define FILE_OBJECT_ID_INFORMATION      29
1388 /* Number 30 not defined in documents */
1389 #define FILE_MOVE_CLUSTER_INFORMATION   31
1390 #define FILE_QUOTA_INFORMATION          32
1391 #define FILE_REPARSE_POINT_INFORMATION  33
1392 #define FILE_NETWORK_OPEN_INFORMATION   34
1393 #define FILE_ATTRIBUTE_TAG_INFORMATION  35
1394 #define FILE_TRACKING_INFORMATION       36
1395 #define FILEID_BOTH_DIRECTORY_INFORMATION 37
1396 #define FILEID_FULL_DIRECTORY_INFORMATION 38
1397 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1398 #define FILE_SHORT_NAME_INFORMATION     40
1399 #define FILE_SFIO_RESERVE_INFORMATION   44
1400 #define FILE_SFIO_VOLUME_INFORMATION    45
1401 #define FILE_HARD_LINK_INFORMATION      46
1402 #define FILE_NORMALIZED_NAME_INFORMATION 48
1403 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1404 #define FILE_STANDARD_LINK_INFORMATION  54
1405
1406 #define OP_BREAK_STRUCT_SIZE_20         24
1407 #define OP_BREAK_STRUCT_SIZE_21         36
1408
1409 struct smb2_file_access_info {
1410         __le32 AccessFlags;
1411 } __packed;
1412
1413 struct smb2_file_alignment_info {
1414         __le32 AlignmentRequirement;
1415 } __packed;
1416
1417 struct smb2_file_internal_info {
1418         __le64 IndexNumber;
1419 } __packed; /* level 6 Query */
1420
1421 struct smb2_file_rename_info { /* encoding of request for level 10 */
1422         __u8   ReplaceIfExists; /* 1 = replace existing target with new */
1423                                 /* 0 = fail if target already exists */
1424         __u8   Reserved[7];
1425         __u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1426         __le32 FileNameLength;
1427         char   FileName[0];     /* New name to be assigned */
1428 } __packed; /* level 10 Set */
1429
1430 struct smb2_file_link_info { /* encoding of request for level 11 */
1431         __u8   ReplaceIfExists; /* 1 = replace existing link with new */
1432                                 /* 0 = fail if link already exists */
1433         __u8   Reserved[7];
1434         __u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1435         __le32 FileNameLength;
1436         char   FileName[0];     /* Name to be assigned to new link */
1437 } __packed; /* level 11 Set */
1438
1439 /*
1440  * This level 18, although with struct with same name is different from cifs
1441  * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1442  * CurrentByteOffset.
1443  */
1444 struct smb2_file_all_info { /* data block encoding of response to level 18 */
1445         __le64 CreationTime;    /* Beginning of FILE_BASIC_INFO equivalent */
1446         __le64 LastAccessTime;
1447         __le64 LastWriteTime;
1448         __le64 ChangeTime;
1449         __le32 Attributes;
1450         __u32  Pad1;            /* End of FILE_BASIC_INFO_INFO equivalent */
1451         __le64 AllocationSize;  /* Beginning of FILE_STANDARD_INFO equivalent */
1452         __le64 EndOfFile;       /* size ie offset to first free byte in file */
1453         __le32 NumberOfLinks;   /* hard links */
1454         __u8   DeletePending;
1455         __u8   Directory;
1456         __u16  Pad2;            /* End of FILE_STANDARD_INFO equivalent */
1457         __le64 IndexNumber;
1458         __le32 EASize;
1459         __le32 AccessFlags;
1460         __le64 CurrentByteOffset;
1461         __le32 Mode;
1462         __le32 AlignmentRequirement;
1463         __le32 FileNameLength;
1464         char   FileName[1];
1465 } __packed; /* level 18 Query */
1466
1467 struct smb2_file_basic_info { /* data block encoding of response to level 18 */
1468         __le64 CreationTime;    /* Beginning of FILE_BASIC_INFO equivalent */
1469         __le64 LastAccessTime;
1470         __le64 LastWriteTime;
1471         __le64 ChangeTime;
1472         __le32 Attributes;
1473         __u32  Pad1;            /* End of FILE_BASIC_INFO_INFO equivalent */
1474 } __packed;
1475
1476 struct smb2_file_alt_name_info {
1477         __le32 FileNameLength;
1478         char FileName[0];
1479 } __packed;
1480
1481 struct smb2_file_stream_info {
1482         __le32  NextEntryOffset;
1483         __le32  StreamNameLength;
1484         __le64 StreamSize;
1485         __le64 StreamAllocationSize;
1486         char   StreamName[0];
1487 } __packed;
1488
1489 struct smb2_file_eof_info { /* encoding of request for level 10 */
1490         __le64 EndOfFile; /* new end of file value */
1491 } __packed; /* level 20 Set */
1492
1493 struct smb2_file_ntwrk_info {
1494         __le64 CreationTime;
1495         __le64 LastAccessTime;
1496         __le64 LastWriteTime;
1497         __le64 ChangeTime;
1498         __le64 AllocationSize;
1499         __le64 EndOfFile;
1500         __le32 Attributes;
1501         __le32 Reserved;
1502 } __packed;
1503
1504 struct smb2_file_standard_info {
1505         __le64 AllocationSize;
1506         __le64 EndOfFile;
1507         __le32 NumberOfLinks;   /* hard links */
1508         __u8   DeletePending;
1509         __u8   Directory;
1510         __le16 Reserved;
1511 } __packed; /* level 18 Query */
1512
1513 struct smb2_file_ea_info {
1514         __le32 EASize;
1515 } __packed;
1516
1517 struct smb2_file_alloc_info {
1518         __le64 AllocationSize;
1519 } __packed;
1520
1521 struct smb2_file_disposition_info {
1522         __u8 DeletePending;
1523 } __packed;
1524
1525 struct smb2_file_pos_info {
1526         __le64 CurrentByteOffset;
1527 } __packed;
1528
1529 #define FILE_MODE_INFO_MASK cpu_to_le32(0x0000103e)
1530
1531 struct smb2_file_mode_info {
1532         __le32 Mode;
1533 } __packed;
1534
1535 #define COMPRESSION_FORMAT_NONE 0x0000
1536 #define COMPRESSION_FORMAT_LZNT1 0x0002
1537
1538 struct smb2_file_comp_info {
1539         __le64 CompressedFileSize;
1540         __le16 CompressionFormat;
1541         __u8 CompressionUnitShift;
1542         __u8 ChunkShift;
1543         __u8 ClusterShift;
1544         __u8 Reserved[3];
1545 } __packed;
1546
1547 struct smb2_file_attr_tag_info {
1548         __le32 FileAttributes;
1549         __le32 ReparseTag;
1550 } __packed;
1551
1552 #define SL_RESTART_SCAN 0x00000001
1553 #define SL_RETURN_SINGLE_ENTRY  0x00000002
1554 #define SL_INDEX_SPECIFIED      0x00000004
1555
1556 struct smb2_ea_info_req {
1557         __le32 NextEntryOffset;
1558         __u8   EaNameLength;
1559         char name[1];
1560 } __packed; /* level 15 Query */
1561
1562 struct smb2_ea_info {
1563         __le32 NextEntryOffset;
1564         __u8   Flags;
1565         __u8   EaNameLength;
1566         __le16 EaValueLength;
1567         char name[1];
1568         /* optionally followed by value */
1569 } __packed; /* level 15 Query */
1570
1571 struct create_ea_buf_req {
1572         struct create_context ccontext;
1573         __u8   Name[8];
1574         struct smb2_ea_info ea;
1575 } __packed;
1576
1577 struct create_sd_buf_req {
1578         struct create_context ccontext;
1579         __u8   Name[8];
1580         struct smb_ntsd ntsd;
1581 } __packed;
1582
1583 /* Find File infolevels */
1584 #define SMB_FIND_FILE_POSIX_INFO        0x064
1585
1586 /* Level 100 query info */
1587 struct smb311_posix_qinfo {
1588         __le64 CreationTime;
1589         __le64 LastAccessTime;
1590         __le64 LastWriteTime;
1591         __le64 ChangeTime;
1592         __le64 EndOfFile;
1593         __le64 AllocationSize;
1594         __le32 DosAttributes;
1595         __le64 Inode;
1596         __le32 DeviceId;
1597         __le32 Zero;
1598         /* beginning of POSIX Create Context Response */
1599         __le32 HardLinks;
1600         __le32 ReparseTag;
1601         __le32 Mode;
1602         u8     Sids[];
1603         /*
1604          * var sized owner SID
1605          * var sized group SID
1606          * le32 filenamelength
1607          * u8  filename[]
1608          */
1609 } __packed;
1610
1611 struct smb2_posix_info {
1612         __le32 NextEntryOffset;
1613         __u32 Ignored;
1614         __le64 CreationTime;
1615         __le64 LastAccessTime;
1616         __le64 LastWriteTime;
1617         __le64 ChangeTime;
1618         __le64 EndOfFile;
1619         __le64 AllocationSize;
1620         __le32 DosAttributes;
1621         __le64 Inode;
1622         __le32 DeviceId;
1623         __le32 Zero;
1624         /* beginning of POSIX Create Context Response */
1625         __le32 HardLinks;
1626         __le32 ReparseTag;
1627         __le32 Mode;
1628         u8 SidBuffer[40];
1629         __le32 name_len;
1630         u8 name[1];
1631         /*
1632          * var sized owner SID
1633          * var sized group SID
1634          * le32 filenamelength
1635          * u8  filename[]
1636          */
1637 } __packed;
1638
1639 /* functions */
1640 int init_smb2_0_server(struct ksmbd_conn *conn);
1641 void init_smb2_1_server(struct ksmbd_conn *conn);
1642 void init_smb3_0_server(struct ksmbd_conn *conn);
1643 void init_smb3_02_server(struct ksmbd_conn *conn);
1644 int init_smb3_11_server(struct ksmbd_conn *conn);
1645
1646 void init_smb2_max_read_size(unsigned int sz);
1647 void init_smb2_max_write_size(unsigned int sz);
1648 void init_smb2_max_trans_size(unsigned int sz);
1649
1650 bool is_smb2_neg_cmd(struct ksmbd_work *work);
1651 bool is_smb2_rsp(struct ksmbd_work *work);
1652
1653 u16 get_smb2_cmd_val(struct ksmbd_work *work);
1654 void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
1655 int init_smb2_rsp_hdr(struct ksmbd_work *work);
1656 int smb2_allocate_rsp_buf(struct ksmbd_work *work);
1657 bool is_chained_smb2_message(struct ksmbd_work *work);
1658 int init_smb2_neg_rsp(struct ksmbd_work *work);
1659 void smb2_set_err_rsp(struct ksmbd_work *work);
1660 int smb2_check_user_session(struct ksmbd_work *work);
1661 int smb2_get_ksmbd_tcon(struct ksmbd_work *work);
1662 bool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command);
1663 int smb2_check_sign_req(struct ksmbd_work *work);
1664 void smb2_set_sign_rsp(struct ksmbd_work *work);
1665 int smb3_check_sign_req(struct ksmbd_work *work);
1666 void smb3_set_sign_rsp(struct ksmbd_work *work);
1667 int find_matching_smb2_dialect(int start_index, __le16 *cli_dialects,
1668                                __le16 dialects_count);
1669 struct file_lock *smb_flock_init(struct file *f);
1670 int setup_async_work(struct ksmbd_work *work, void (*fn)(void **),
1671                      void **arg);
1672 void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
1673 struct channel *lookup_chann_list(struct ksmbd_session *sess,
1674                                   struct ksmbd_conn *conn);
1675 void smb3_preauth_hash_rsp(struct ksmbd_work *work);
1676 bool smb3_is_transform_hdr(void *buf);
1677 int smb3_decrypt_req(struct ksmbd_work *work);
1678 int smb3_encrypt_resp(struct ksmbd_work *work);
1679 bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);
1680 int smb2_set_rsp_credits(struct ksmbd_work *work);
1681
1682 /* smb2 misc functions */
1683 int ksmbd_smb2_check_message(struct ksmbd_work *work);
1684
1685 /* smb2 command handlers */
1686 int smb2_handle_negotiate(struct ksmbd_work *work);
1687 int smb2_negotiate_request(struct ksmbd_work *work);
1688 int smb2_sess_setup(struct ksmbd_work *work);
1689 int smb2_tree_connect(struct ksmbd_work *work);
1690 int smb2_tree_disconnect(struct ksmbd_work *work);
1691 int smb2_session_logoff(struct ksmbd_work *work);
1692 int smb2_open(struct ksmbd_work *work);
1693 int smb2_query_info(struct ksmbd_work *work);
1694 int smb2_query_dir(struct ksmbd_work *work);
1695 int smb2_close(struct ksmbd_work *work);
1696 int smb2_echo(struct ksmbd_work *work);
1697 int smb2_set_info(struct ksmbd_work *work);
1698 int smb2_read(struct ksmbd_work *work);
1699 int smb2_write(struct ksmbd_work *work);
1700 int smb2_flush(struct ksmbd_work *work);
1701 int smb2_cancel(struct ksmbd_work *work);
1702 int smb2_lock(struct ksmbd_work *work);
1703 int smb2_ioctl(struct ksmbd_work *work);
1704 int smb2_oplock_break(struct ksmbd_work *work);
1705 int smb2_notify(struct ksmbd_work *ksmbd_work);
1706
1707 #endif  /* _SMB2PDU_H */