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