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