blob: 1e1449ad00e897c0766664a1bd8bdd923f390401 [file] [log] [blame]
Steve Frenchddfbefb2011-03-15 02:08:48 +00001/*
2 * fs/cifs/smb2pdu.h
3 *
Steve Frenchbe7457d2013-06-19 17:41:10 -05004 * Copyright (c) International Business Machines Corp., 2009, 2013
Steve Frenchddfbefb2011-03-15 02:08:48 +00005 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
8 *
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef _SMB2PDU_H
25#define _SMB2PDU_H
26
27#include <net/sock.h>
28
29/*
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040030 * Note that, due to trying to use names similar to the protocol specifications,
31 * there are many mixed case field names in the structures below. Although
32 * this does not match typical Linux kernel style, it is necessary to be
33 * be able to match against the protocol specfication.
34 *
35 * SMB2 commands
36 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
37 * (ie no useful data other than the SMB error code itself) and are marked such.
38 * Knowing this helps avoid response buffer allocations and copy in some cases.
39 */
40
41/* List of commands in host endian */
42#define SMB2_NEGOTIATE_HE 0x0000
43#define SMB2_SESSION_SETUP_HE 0x0001
44#define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
45#define SMB2_TREE_CONNECT_HE 0x0003
46#define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
47#define SMB2_CREATE_HE 0x0005
48#define SMB2_CLOSE_HE 0x0006
49#define SMB2_FLUSH_HE 0x0007 /* trivial resp */
50#define SMB2_READ_HE 0x0008
51#define SMB2_WRITE_HE 0x0009
52#define SMB2_LOCK_HE 0x000A
53#define SMB2_IOCTL_HE 0x000B
54#define SMB2_CANCEL_HE 0x000C
55#define SMB2_ECHO_HE 0x000D
56#define SMB2_QUERY_DIRECTORY_HE 0x000E
57#define SMB2_CHANGE_NOTIFY_HE 0x000F
58#define SMB2_QUERY_INFO_HE 0x0010
59#define SMB2_SET_INFO_HE 0x0011
60#define SMB2_OPLOCK_BREAK_HE 0x0012
61
62/* The same list in little endian */
63#define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
64#define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
65#define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
66#define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
67#define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
68#define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
69#define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
70#define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
71#define SMB2_READ cpu_to_le16(SMB2_READ_HE)
72#define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
73#define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
74#define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
75#define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
76#define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
77#define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
78#define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
79#define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
80#define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
81#define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
82
Pavel Shilovsky46890ff2016-11-29 11:31:23 -080083#define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
84
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040085#define NUMBER_OF_SMB2_COMMANDS 0x0013
86
Pavel Shilovskyc5e76652017-08-24 15:16:40 -070087/* 4 len + 52 transform hdr + 64 hdr + 56 create rsp */
88#define MAX_SMB2_HDR_SIZE 0x00b0
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040089
Fabian Frederickbc09d142014-12-10 15:41:15 -080090#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
Steve French373512e2015-12-18 13:05:30 -060091#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +040092
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040093/*
Steve Frenchddfbefb2011-03-15 02:08:48 +000094 * SMB2 Header Definition
95 *
96 * "MBZ" : Must be Zero
97 * "BB" : BugBug, Something to check/review/analyze later
98 * "PDU" : "Protocol Data Unit" (ie a network "frame")
99 *
100 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400101
Fabian Frederickbc09d142014-12-10 15:41:15 -0800102#define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400103
Steve Frenchddfbefb2011-03-15 02:08:48 +0000104struct smb2_hdr {
105 __be32 smb2_buf_length; /* big endian on wire */
106 /* length is only two or three bytes - with
107 one or two byte type preceding it that MBZ */
Steve French373512e2015-12-18 13:05:30 -0600108 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
Steve Frenchddfbefb2011-03-15 02:08:48 +0000109 __le16 StructureSize; /* 64 */
110 __le16 CreditCharge; /* MBZ */
111 __le32 Status; /* Error from server */
112 __le16 Command;
113 __le16 CreditRequest; /* CreditResponse */
114 __le32 Flags;
115 __le32 NextCommand;
Sachin Prabhu9235d092014-12-09 17:37:00 +0000116 __le64 MessageId;
Steve Frenchddfbefb2011-03-15 02:08:48 +0000117 __le32 ProcessId;
118 __u32 TreeId; /* opaque - so do not make little endian */
119 __u64 SessionId; /* opaque - so do not make little endian */
120 __u8 Signature[16];
121} __packed;
122
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400123struct smb2_pdu {
124 struct smb2_hdr hdr;
125 __le16 StructureSize2; /* size of wct area (varies, request specific) */
126} __packed;
127
Steve French0cbaa532013-11-15 23:50:24 -0600128struct smb2_transform_hdr {
129 __be32 smb2_buf_length; /* big endian on wire */
130 /* length is only two or three bytes - with
131 one or two byte type preceding it that MBZ */
132 __u8 ProtocolId[4]; /* 0xFD 'S' 'M' 'B' */
133 __u8 Signature[16];
Steve French373512e2015-12-18 13:05:30 -0600134 __u8 Nonce[16];
Steve French0cbaa532013-11-15 23:50:24 -0600135 __le32 OriginalMessageSize;
136 __u16 Reserved1;
Steve French373512e2015-12-18 13:05:30 -0600137 __le16 Flags; /* EncryptionAlgorithm */
Steve French0cbaa532013-11-15 23:50:24 -0600138 __u64 SessionId;
139} __packed;
140
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400141/*
142 * SMB2 flag definitions
143 */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800144#define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
145#define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
146#define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
147#define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
148#define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400149
150/*
151 * Definitions for SMB2 Protocol Data Units (network frames)
152 *
153 * See MS-SMB2.PDF specification for protocol details.
154 * The Naming convention is the lower case version of the SMB2
155 * command code name for the struct. Note that structures must be packed.
156 *
157 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400158
Fabian Frederickbc09d142014-12-10 15:41:15 -0800159#define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400160
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400161struct smb2_err_rsp {
162 struct smb2_hdr hdr;
163 __le16 StructureSize;
164 __le16 Reserved; /* MBZ */
165 __le32 ByteCount; /* even if zero, at least one byte follows */
166 __u8 ErrorData[1]; /* variable length */
167} __packed;
168
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400169struct smb2_symlink_err_rsp {
170 __le32 SymLinkLength;
171 __le32 SymLinkErrorTag;
172 __le32 ReparseTag;
173 __le16 ReparseDataLength;
174 __le16 UnparsedPathLength;
175 __le16 SubstituteNameOffset;
176 __le16 SubstituteNameLength;
177 __le16 PrintNameOffset;
178 __le16 PrintNameLength;
179 __le32 Flags;
180 __u8 PathBuffer[0];
181} __packed;
182
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700183#define SMB2_CLIENT_GUID_SIZE 16
184
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400185struct smb2_negotiate_req {
186 struct smb2_hdr hdr;
187 __le16 StructureSize; /* Must be 36 */
188 __le16 DialectCount;
189 __le16 SecurityMode;
190 __le16 Reserved; /* MBZ */
191 __le32 Capabilities;
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700192 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
Steve French5f7fbf72014-12-17 22:52:58 -0600193 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
194 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
195 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
196 __le16 Reserved2;
Steve Frenche4aa25e2012-10-01 12:26:22 -0500197 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400198} __packed;
199
Steve Frenche4aa25e2012-10-01 12:26:22 -0500200/* Dialects */
201#define SMB20_PROT_ID 0x0202
202#define SMB21_PROT_ID 0x0210
203#define SMB30_PROT_ID 0x0300
Steve French20b6d8b2013-06-12 22:48:41 -0500204#define SMB302_PROT_ID 0x0302
Steve French5f7fbf72014-12-17 22:52:58 -0600205#define SMB311_PROT_ID 0x0311
Steve Frenche4aa25e2012-10-01 12:26:22 -0500206#define BAD_PROT_ID 0xFFFF
207
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400208/* SecurityMode flags */
209#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
210#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
211/* Capabilities flags */
212#define SMB2_GLOBAL_CAP_DFS 0x00000001
213#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
214#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
Steve Frenche4aa25e2012-10-01 12:26:22 -0500215#define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
216#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
217#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
218#define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
Pavel Shilovsky29e20f92012-07-13 13:58:14 +0400219/* Internal types */
220#define SMB2_NT_FIND 0x00100000
221#define SMB2_LARGE_FILES 0x00200000
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400222
Steve Frencheed0e172015-02-06 00:03:52 -0600223#define SMB311_SALT_SIZE 32
224/* Hash Algorithm Types */
Steve Frenchebb3a9d2015-06-18 04:49:47 -0500225#define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
Steve Frencheed0e172015-02-06 00:03:52 -0600226
227struct smb2_preauth_neg_context {
228 __le16 ContextType; /* 1 */
229 __le16 DataLength;
230 __le32 Reserved;
231 __le16 HashAlgorithmCount; /* 1 */
232 __le16 SaltLength;
233 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
234 __u8 Salt[SMB311_SALT_SIZE];
235} __packed;
236
237/* Encryption Algorithms Ciphers */
238#define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
239#define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
240
241struct smb2_encryption_neg_context {
242 __le16 ContextType; /* 2 */
243 __le16 DataLength;
244 __le32 Reserved;
Steve Frenchebb3a9d2015-06-18 04:49:47 -0500245 __le16 CipherCount; /* AES-128-GCM and AES-128-CCM */
246 __le16 Ciphers[2]; /* Ciphers[0] since only one used now */
Steve Frencheed0e172015-02-06 00:03:52 -0600247} __packed;
248
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400249struct smb2_negotiate_rsp {
250 struct smb2_hdr hdr;
251 __le16 StructureSize; /* Must be 65 */
252 __le16 SecurityMode;
253 __le16 DialectRevision;
Steve French5f7fbf72014-12-17 22:52:58 -0600254 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400255 __u8 ServerGUID[16];
256 __le32 Capabilities;
257 __le32 MaxTransactSize;
258 __le32 MaxReadSize;
259 __le32 MaxWriteSize;
260 __le64 SystemTime; /* MBZ */
261 __le64 ServerStartTime;
262 __le16 SecurityBufferOffset;
263 __le16 SecurityBufferLength;
Steve French5f7fbf72014-12-17 22:52:58 -0600264 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400265 __u8 Buffer[1]; /* variable length GSS security buffer */
266} __packed;
267
Steve Frencheed0e172015-02-06 00:03:52 -0600268/* Flags */
269#define SMB2_SESSION_REQ_FLAG_BINDING 0x01
270#define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
271
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400272struct smb2_sess_setup_req {
273 struct smb2_hdr hdr;
274 __le16 StructureSize; /* Must be 25 */
Steve Frencheed0e172015-02-06 00:03:52 -0600275 __u8 Flags;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400276 __u8 SecurityMode;
277 __le32 Capabilities;
278 __le32 Channel;
279 __le16 SecurityBufferOffset;
280 __le16 SecurityBufferLength;
Steve Frenchc2afb812016-09-20 22:56:13 -0500281 __u64 PreviousSessionId;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400282 __u8 Buffer[1]; /* variable length GSS security buffer */
283} __packed;
284
285/* Currently defined SessionFlags */
286#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
287#define SMB2_SESSION_FLAG_IS_NULL 0x0002
Steve French0cbaa532013-11-15 23:50:24 -0600288#define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400289struct smb2_sess_setup_rsp {
290 struct smb2_hdr hdr;
291 __le16 StructureSize; /* Must be 9 */
292 __le16 SessionFlags;
293 __le16 SecurityBufferOffset;
294 __le16 SecurityBufferLength;
295 __u8 Buffer[1]; /* variable length GSS security buffer */
296} __packed;
297
298struct smb2_logoff_req {
299 struct smb2_hdr hdr;
300 __le16 StructureSize; /* Must be 4 */
301 __le16 Reserved;
302} __packed;
303
304struct smb2_logoff_rsp {
305 struct smb2_hdr hdr;
306 __le16 StructureSize; /* Must be 4 */
307 __le16 Reserved;
308} __packed;
309
Steve Frencheed0e172015-02-06 00:03:52 -0600310/* Flags/Reserved for SMB3.1.1 */
311#define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
312
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400313struct smb2_tree_connect_req {
314 struct smb2_hdr hdr;
315 __le16 StructureSize; /* Must be 9 */
Steve Frencheed0e172015-02-06 00:03:52 -0600316 __le16 Reserved; /* Flags in SMB3.1.1 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400317 __le16 PathOffset;
318 __le16 PathLength;
319 __u8 Buffer[1]; /* variable length */
320} __packed;
321
322struct smb2_tree_connect_rsp {
323 struct smb2_hdr hdr;
324 __le16 StructureSize; /* Must be 16 */
325 __u8 ShareType; /* see below */
326 __u8 Reserved;
327 __le32 ShareFlags; /* see below */
328 __le32 Capabilities; /* see below */
329 __le32 MaximalAccess;
330} __packed;
331
332/* Possible ShareType values */
333#define SMB2_SHARE_TYPE_DISK 0x01
334#define SMB2_SHARE_TYPE_PIPE 0x02
335#define SMB2_SHARE_TYPE_PRINT 0x03
336
337/*
338 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
339 * must be set (any of the remaining, SHI1005, flags may be set individually
340 * or in combination.
341 */
342#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
343#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
344#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
345#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
346#define SHI1005_FLAGS_DFS 0x00000001
347#define SHI1005_FLAGS_DFS_ROOT 0x00000002
348#define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
349#define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
350#define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
351#define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
352#define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
Steve Frenchc8664732013-06-21 15:35:45 -0500353#define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
354#define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
355#define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
356#define SHI1005_FLAGS_ALL 0x0000FF33
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400357
358/* Possible share capabilities */
Steve French2b5dc282013-06-13 10:51:10 -0500359#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
360#define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
361#define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
362#define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
363#define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400364
365struct smb2_tree_disconnect_req {
366 struct smb2_hdr hdr;
367 __le16 StructureSize; /* Must be 4 */
368 __le16 Reserved;
369} __packed;
370
371struct smb2_tree_disconnect_rsp {
372 struct smb2_hdr hdr;
373 __le16 StructureSize; /* Must be 4 */
374 __le16 Reserved;
375} __packed;
376
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400377/* File Attrubutes */
378#define FILE_ATTRIBUTE_READONLY 0x00000001
379#define FILE_ATTRIBUTE_HIDDEN 0x00000002
380#define FILE_ATTRIBUTE_SYSTEM 0x00000004
381#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
382#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
383#define FILE_ATTRIBUTE_NORMAL 0x00000080
384#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
385#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
386#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
387#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
388#define FILE_ATTRIBUTE_OFFLINE 0x00001000
389#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
390#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
Steve French73322972014-09-23 19:25:42 -0500391#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
392#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400393
394/* Oplock levels */
395#define SMB2_OPLOCK_LEVEL_NONE 0x00
396#define SMB2_OPLOCK_LEVEL_II 0x01
397#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
398#define SMB2_OPLOCK_LEVEL_BATCH 0x09
399#define SMB2_OPLOCK_LEVEL_LEASE 0xFF
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700400/* Non-spec internal type */
401#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400402
403/* Desired Access Flags */
404#define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
405#define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
406#define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
407#define FILE_READ_EA_LE cpu_to_le32(0x00000008)
408#define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
409#define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
410#define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
411#define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
412#define FILE_DELETE_LE cpu_to_le32(0x00010000)
413#define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
414#define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
415#define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
416#define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
417#define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
418#define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
419#define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
420#define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
421#define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
422#define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
423
424/* ShareAccess Flags */
425#define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
426#define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
427#define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
428#define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
429
430/* CreateDisposition Flags */
431#define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
432#define FILE_OPEN_LE cpu_to_le32(0x00000001)
433#define FILE_CREATE_LE cpu_to_le32(0x00000002)
434#define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
435#define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
436#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
437
438/* CreateOptions Flags */
439#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
440/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
441#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
442#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
443#define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
444#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
445#define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
446#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
447#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
448#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
449#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
450#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
451#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
452#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
453#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
454#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
455#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
456#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
457#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
458
459#define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
460 | FILE_READ_ATTRIBUTES_LE)
461#define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
462 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
463#define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
464
465/* Impersonation Levels */
466#define IL_ANONYMOUS cpu_to_le32(0x00000000)
467#define IL_IDENTIFICATION cpu_to_le32(0x00000001)
468#define IL_IMPERSONATION cpu_to_le32(0x00000002)
469#define IL_DELEGATE cpu_to_le32(0x00000003)
470
471/* Create Context Values */
472#define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
473#define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
474#define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
475#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
Steve French12197a72014-05-14 05:29:40 -0700476#define SMB2_CREATE_ALLOCATION_SIZE "AISi"
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400477#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
478#define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
479#define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
480#define SMB2_CREATE_REQUEST_LEASE "RqLs"
Steve French12197a72014-05-14 05:29:40 -0700481#define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
482#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
483#define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
484#define SVHDX_OPEN_DEVICE_CONTEXT 0x83CE6F1AD851E0986E34401CC9BCFCE9
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400485
486struct smb2_create_req {
487 struct smb2_hdr hdr;
488 __le16 StructureSize; /* Must be 57 */
489 __u8 SecurityFlags;
490 __u8 RequestedOplockLevel;
491 __le32 ImpersonationLevel;
492 __le64 SmbCreateFlags;
493 __le64 Reserved;
494 __le32 DesiredAccess;
495 __le32 FileAttributes;
496 __le32 ShareAccess;
497 __le32 CreateDisposition;
498 __le32 CreateOptions;
499 __le16 NameOffset;
500 __le16 NameLength;
501 __le32 CreateContextsOffset;
502 __le32 CreateContextsLength;
Pavel Shilovsky59aa3712013-07-04 19:41:24 +0400503 __u8 Buffer[0];
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400504} __packed;
505
506struct smb2_create_rsp {
507 struct smb2_hdr hdr;
508 __le16 StructureSize; /* Must be 89 */
509 __u8 OplockLevel;
510 __u8 Reserved;
511 __le32 CreateAction;
512 __le64 CreationTime;
513 __le64 LastAccessTime;
514 __le64 LastWriteTime;
515 __le64 ChangeTime;
516 __le64 AllocationSize;
517 __le64 EndofFile;
518 __le32 FileAttributes;
519 __le32 Reserved2;
520 __u64 PersistentFileId; /* opaque endianness */
521 __u64 VolatileFileId; /* opaque endianness */
522 __le32 CreateContextsOffset;
523 __le32 CreateContextsLength;
524 __u8 Buffer[1];
525} __packed;
526
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700527struct create_context {
528 __le32 Next;
529 __le16 NameOffset;
530 __le16 NameLength;
531 __le16 Reserved;
532 __le16 DataOffset;
533 __le32 DataLength;
534 __u8 Buffer[0];
535} __packed;
536
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400537#define SMB2_LEASE_READ_CACHING_HE 0x01
538#define SMB2_LEASE_HANDLE_CACHING_HE 0x02
539#define SMB2_LEASE_WRITE_CACHING_HE 0x04
540
Fabian Frederickbc09d142014-12-10 15:41:15 -0800541#define SMB2_LEASE_NONE cpu_to_le32(0x00)
542#define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
543#define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
544#define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700545
Fabian Frederickbc09d142014-12-10 15:41:15 -0800546#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700547
548#define SMB2_LEASE_KEY_SIZE 16
549
550struct lease_context {
551 __le64 LeaseKeyLow;
552 __le64 LeaseKeyHigh;
553 __le32 LeaseState;
554 __le32 LeaseFlags;
555 __le64 LeaseDuration;
556} __packed;
557
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400558struct lease_context_v2 {
559 __le64 LeaseKeyLow;
560 __le64 LeaseKeyHigh;
561 __le32 LeaseState;
562 __le32 LeaseFlags;
563 __le64 LeaseDuration;
564 __le64 ParentLeaseKeyLow;
565 __le64 ParentLeaseKeyHigh;
566 __le16 Epoch;
567 __le16 Reserved;
568} __packed;
569
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700570struct create_lease {
571 struct create_context ccontext;
572 __u8 Name[8];
573 struct lease_context lcontext;
574} __packed;
575
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400576struct create_lease_v2 {
577 struct create_context ccontext;
578 __u8 Name[8];
579 struct lease_context_v2 lcontext;
580 __u8 Pad[4];
581} __packed;
582
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400583struct create_durable {
584 struct create_context ccontext;
585 __u8 Name[8];
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400586 union {
587 __u8 Reserved[16];
588 struct {
589 __u64 PersistentFileId;
590 __u64 VolatileFileId;
591 } Fid;
592 } Data;
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400593} __packed;
594
Steve Frenchb56eae42015-11-03 09:26:27 -0600595/* See MS-SMB2 2.2.13.2.11 */
596/* Flags */
597#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
598struct durable_context_v2 {
599 __le32 Timeout;
600 __le32 Flags;
601 __u64 Reserved;
602 __u8 CreateGuid[16];
603} __packed;
604
605struct create_durable_v2 {
606 struct create_context ccontext;
607 __u8 Name[8];
608 struct durable_context_v2 dcontext;
609} __packed;
610
611/* See MS-SMB2 2.2.13.2.12 */
612struct durable_reconnect_context_v2 {
613 struct {
614 __u64 PersistentFileId;
615 __u64 VolatileFileId;
616 } Fid;
617 __u8 CreateGuid[16];
618 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
619} __packed;
620
621/* See MS-SMB2 2.2.14.2.12 */
622struct durable_reconnect_context_v2_rsp {
623 __le32 Timeout;
624 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
625} __packed;
626
627struct create_durable_handle_reconnect_v2 {
628 struct create_context ccontext;
629 __u8 Name[8];
630 struct durable_reconnect_context_v2 dcontext;
631} __packed;
632
Steve French41c13582013-11-14 00:05:36 -0600633#define COPY_CHUNK_RES_KEY_SIZE 24
634struct resume_key_req {
635 char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
636 __le32 ContextLength; /* MBZ */
637 char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
638} __packed;
639
Steve Frenchbe7457d2013-06-19 17:41:10 -0500640/* this goes in the ioctl buffer when doing a copychunk request */
641struct copychunk_ioctl {
Steve French41c13582013-11-14 00:05:36 -0600642 char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
Steve Frenchbe7457d2013-06-19 17:41:10 -0500643 __le32 ChunkCount; /* we are only sending 1 */
644 __le32 Reserved;
645 /* array will only be one chunk long for us */
646 __le64 SourceOffset;
647 __le64 TargetOffset;
Steve Frenchc8664732013-06-21 15:35:45 -0500648 __le32 Length; /* how many bytes to copy */
Steve Frenchbe7457d2013-06-19 17:41:10 -0500649 __u32 Reserved2;
650} __packed;
651
Steve French31742c52014-08-17 08:38:47 -0500652/* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
653struct file_zero_data_information {
654 __le64 FileOffset;
655 __le64 BeyondFinalZero;
656} __packed;
657
Steve French41c13582013-11-14 00:05:36 -0600658struct copychunk_ioctl_rsp {
659 __le32 ChunksWritten;
660 __le32 ChunkBytesWritten;
661 __le32 TotalBytesWritten;
662} __packed;
663
Steve French9d1b0662015-06-24 02:12:19 -0500664struct fsctl_set_integrity_information_req {
665 __le16 ChecksumAlgorithm;
666 __le16 Reserved;
667 __le32 Flags;
668} __packed;
669
670struct fsctl_get_integrity_information_rsp {
671 __le16 ChecksumAlgorithm;
672 __le16 Reserved;
673 __le32 Flags;
674 __le32 ChecksumChunkSizeInBytes;
675 __le32 ClusterSizeInBytes;
676} __packed;
677
678/* Integrity ChecksumAlgorithm choices for above */
679#define CHECKSUM_TYPE_NONE 0x0000
680#define CHECKSUM_TYPE_CRC64 0x0002
Steve Frenchb3152e22015-06-24 03:17:02 -0500681#define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
Steve French9d1b0662015-06-24 02:12:19 -0500682
683/* Integrity flags for above */
684#define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
685
Steve Frenchb56eae42015-11-03 09:26:27 -0600686/* See MS-SMB2 2.2.31.3 */
687struct network_resiliency_req {
688 __le32 Timeout;
689 __le32 Reserved;
690} __packed;
691/* There is no buffer for the response ie no struct network_resiliency_rsp */
692
Steve French9d1b0662015-06-24 02:12:19 -0500693
Steve Frenchff1c0382013-11-19 23:44:46 -0600694struct validate_negotiate_info_req {
Steve French4a72daf2013-06-25 00:20:49 -0500695 __le32 Capabilities;
696 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
697 __le16 SecurityMode;
698 __le16 DialectCount;
Steve Frenchff1c0382013-11-19 23:44:46 -0600699 __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */
700} __packed;
701
702struct validate_negotiate_info_rsp {
703 __le32 Capabilities;
704 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
705 __le16 SecurityMode;
706 __le16 Dialect; /* Dialect in use for the connection */
Steve French4a72daf2013-06-25 00:20:49 -0500707} __packed;
708
709#define RSS_CAPABLE 0x00000001
710#define RDMA_CAPABLE 0x00000002
711
712struct network_interface_info_ioctl_rsp {
713 __le32 Next; /* next interface. zero if this is last one */
714 __le32 IfIndex;
715 __le32 Capability; /* RSS or RDMA Capable */
716 __le32 Reserved;
717 __le64 LinkSpeed;
718 char SockAddr_Storage[128];
719} __packed;
720
721#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
722
Steve French64a5cfa2013-10-14 15:31:32 -0500723struct compress_ioctl {
Steve Frenchc7f508a2013-10-14 15:27:32 -0500724 __le16 CompressionState; /* See cifspdu.h for possible flag values */
Steve French64a5cfa2013-10-14 15:31:32 -0500725} __packed;
726
Steve French02b16662015-06-27 21:18:36 -0700727struct duplicate_extents_to_file {
728 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
729 __u64 VolatileFileHandle;
730 __le64 SourceFileOffset;
731 __le64 TargetFileOffset;
732 __le64 ByteCount; /* Bytes to be copied */
733} __packed;
734
Steve Frenchbe7457d2013-06-19 17:41:10 -0500735struct smb2_ioctl_req {
736 struct smb2_hdr hdr;
737 __le16 StructureSize; /* Must be 57 */
738 __u16 Reserved;
739 __le32 CtlCode;
740 __u64 PersistentFileId; /* opaque endianness */
741 __u64 VolatileFileId; /* opaque endianness */
742 __le32 InputOffset;
743 __le32 InputCount;
744 __le32 MaxInputResponse;
745 __le32 OutputOffset;
746 __le32 OutputCount;
747 __le32 MaxOutputResponse;
748 __le32 Flags;
749 __u32 Reserved2;
Steve French64a5cfa2013-10-14 15:31:32 -0500750 __u8 Buffer[0];
Steve Frenchbe7457d2013-06-19 17:41:10 -0500751} __packed;
752
753struct smb2_ioctl_rsp {
754 struct smb2_hdr hdr;
755 __le16 StructureSize; /* Must be 57 */
756 __u16 Reserved;
757 __le32 CtlCode;
758 __u64 PersistentFileId; /* opaque endianness */
759 __u64 VolatileFileId; /* opaque endianness */
760 __le32 InputOffset;
761 __le32 InputCount;
762 __le32 OutputOffset;
763 __le32 OutputCount;
764 __le32 Flags;
765 __u32 Reserved2;
766 /* char * buffer[] */
767} __packed;
768
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400769/* Currently defined values for close flags */
770#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
771struct smb2_close_req {
772 struct smb2_hdr hdr;
773 __le16 StructureSize; /* Must be 24 */
774 __le16 Flags;
775 __le32 Reserved;
776 __u64 PersistentFileId; /* opaque endianness */
777 __u64 VolatileFileId; /* opaque endianness */
778} __packed;
779
780struct smb2_close_rsp {
781 struct smb2_hdr hdr;
782 __le16 StructureSize; /* 60 */
783 __le16 Flags;
784 __le32 Reserved;
785 __le64 CreationTime;
786 __le64 LastAccessTime;
787 __le64 LastWriteTime;
788 __le64 ChangeTime;
789 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
790 __le64 EndOfFile;
791 __le32 Attributes;
792} __packed;
793
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700794struct smb2_flush_req {
795 struct smb2_hdr hdr;
796 __le16 StructureSize; /* Must be 24 */
797 __le16 Reserved1;
798 __le32 Reserved2;
799 __u64 PersistentFileId; /* opaque endianness */
800 __u64 VolatileFileId; /* opaque endianness */
801} __packed;
802
803struct smb2_flush_rsp {
804 struct smb2_hdr hdr;
805 __le16 StructureSize;
806 __le16 Reserved;
807} __packed;
808
Steve French2b5dc282013-06-13 10:51:10 -0500809/* For read request Flags field below, following flag is defined for SMB3.02 */
810#define SMB2_READFLAG_READ_UNBUFFERED 0x01
811
812/* Channel field for read and write: exactly one of following flags can be set*/
813#define SMB2_CHANNEL_NONE 0x00000000
814#define SMB2_CHANNEL_RDMA_V1 0x00000001 /* SMB3 or later */
815#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001 /* SMB3.02 or later */
816
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700817struct smb2_read_req {
818 struct smb2_hdr hdr;
819 __le16 StructureSize; /* Must be 49 */
820 __u8 Padding; /* offset from start of SMB2 header to place read */
Steve French2b5dc282013-06-13 10:51:10 -0500821 __u8 Flags; /* MBZ unless SMB3.02 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700822 __le32 Length;
823 __le64 Offset;
824 __u64 PersistentFileId; /* opaque endianness */
825 __u64 VolatileFileId; /* opaque endianness */
826 __le32 MinimumCount;
Steve French2b5dc282013-06-13 10:51:10 -0500827 __le32 Channel; /* MBZ except for SMB3 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700828 __le32 RemainingBytes;
829 __le16 ReadChannelInfoOffset; /* Reserved MBZ */
830 __le16 ReadChannelInfoLength; /* Reserved MBZ */
831 __u8 Buffer[1];
832} __packed;
833
834struct smb2_read_rsp {
835 struct smb2_hdr hdr;
836 __le16 StructureSize; /* Must be 17 */
837 __u8 DataOffset;
838 __u8 Reserved;
839 __le32 DataLength;
840 __le32 DataRemaining;
841 __u32 Reserved2;
842 __u8 Buffer[1];
843} __packed;
844
Steve French2b5dc282013-06-13 10:51:10 -0500845/* For write request Flags field below the following flags are defined: */
846#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
847#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
Pavel Shilovsky33319142012-09-18 16:20:29 -0700848
849struct smb2_write_req {
850 struct smb2_hdr hdr;
851 __le16 StructureSize; /* Must be 49 */
852 __le16 DataOffset; /* offset from start of SMB2 header to write data */
853 __le32 Length;
854 __le64 Offset;
855 __u64 PersistentFileId; /* opaque endianness */
856 __u64 VolatileFileId; /* opaque endianness */
857 __le32 Channel; /* Reserved MBZ */
858 __le32 RemainingBytes;
859 __le16 WriteChannelInfoOffset; /* Reserved MBZ */
860 __le16 WriteChannelInfoLength; /* Reserved MBZ */
861 __le32 Flags;
862 __u8 Buffer[1];
863} __packed;
864
865struct smb2_write_rsp {
866 struct smb2_hdr hdr;
867 __le16 StructureSize; /* Must be 17 */
868 __u8 DataOffset;
869 __u8 Reserved;
870 __le32 DataLength;
871 __le32 DataRemaining;
872 __u32 Reserved2;
873 __u8 Buffer[1];
874} __packed;
875
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -0700876#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
877#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
878#define SMB2_LOCKFLAG_UNLOCK 0x0004
879#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
880
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -0700881struct smb2_lock_element {
882 __le64 Offset;
883 __le64 Length;
884 __le32 Flags;
885 __le32 Reserved;
886} __packed;
887
888struct smb2_lock_req {
889 struct smb2_hdr hdr;
890 __le16 StructureSize; /* Must be 48 */
891 __le16 LockCount;
892 __le32 Reserved;
893 __u64 PersistentFileId; /* opaque endianness */
894 __u64 VolatileFileId; /* opaque endianness */
895 /* Followed by at least one */
896 struct smb2_lock_element locks[1];
897} __packed;
898
899struct smb2_lock_rsp {
900 struct smb2_hdr hdr;
901 __le16 StructureSize; /* Must be 4 */
902 __le16 Reserved;
903} __packed;
904
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400905struct smb2_echo_req {
906 struct smb2_hdr hdr;
907 __le16 StructureSize; /* Must be 4 */
908 __u16 Reserved;
909} __packed;
910
911struct smb2_echo_rsp {
912 struct smb2_hdr hdr;
913 __le16 StructureSize; /* Must be 4 */
914 __u16 Reserved;
915} __packed;
916
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700917/* search (query_directory) Flags field */
918#define SMB2_RESTART_SCANS 0x01
919#define SMB2_RETURN_SINGLE_ENTRY 0x02
920#define SMB2_INDEX_SPECIFIED 0x04
921#define SMB2_REOPEN 0x10
922
923struct smb2_query_directory_req {
924 struct smb2_hdr hdr;
925 __le16 StructureSize; /* Must be 33 */
926 __u8 FileInformationClass;
927 __u8 Flags;
928 __le32 FileIndex;
929 __u64 PersistentFileId; /* opaque endianness */
930 __u64 VolatileFileId; /* opaque endianness */
931 __le16 FileNameOffset;
932 __le16 FileNameLength;
933 __le32 OutputBufferLength;
934 __u8 Buffer[1];
935} __packed;
936
937struct smb2_query_directory_rsp {
938 struct smb2_hdr hdr;
939 __le16 StructureSize; /* Must be 9 */
940 __le16 OutputBufferOffset;
941 __le32 OutputBufferLength;
942 __u8 Buffer[1];
943} __packed;
944
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400945/* Possible InfoType values */
946#define SMB2_O_INFO_FILE 0x01
947#define SMB2_O_INFO_FILESYSTEM 0x02
948#define SMB2_O_INFO_SECURITY 0x03
949#define SMB2_O_INFO_QUOTA 0x04
950
Steve French911a8df2014-10-19 19:18:05 -0500951/* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
952#define OWNER_SECINFO 0x00000001
953#define GROUP_SECINFO 0x00000002
954#define DACL_SECINFO 0x00000004
955#define SACL_SECINFO 0x00000008
956#define LABEL_SECINFO 0x00000010
957#define ATTRIBUTE_SECINFO 0x00000020
958#define SCOPE_SECINFO 0x00000040
959#define BACKUP_SECINFO 0x00010000
960#define UNPROTECTED_SACL_SECINFO 0x10000000
961#define UNPROTECTED_DACL_SECINFO 0x20000000
962#define PROTECTED_SACL_SECINFO 0x40000000
963#define PROTECTED_DACL_SECINFO 0x80000000
964
965/* Flags used for FileFullEAinfo */
966#define SL_RESTART_SCAN 0x00000001
967#define SL_RETURN_SINGLE_ENTRY 0x00000002
968#define SL_INDEX_SPECIFIED 0x00000004
969
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400970struct smb2_query_info_req {
971 struct smb2_hdr hdr;
972 __le16 StructureSize; /* Must be 41 */
973 __u8 InfoType;
974 __u8 FileInfoClass;
975 __le32 OutputBufferLength;
976 __le16 InputBufferOffset;
977 __u16 Reserved;
978 __le32 InputBufferLength;
979 __le32 AdditionalInformation;
980 __le32 Flags;
981 __u64 PersistentFileId; /* opaque endianness */
982 __u64 VolatileFileId; /* opaque endianness */
983 __u8 Buffer[1];
984} __packed;
985
986struct smb2_query_info_rsp {
987 struct smb2_hdr hdr;
988 __le16 StructureSize; /* Must be 9 */
989 __le16 OutputBufferOffset;
990 __le32 OutputBufferLength;
991 __u8 Buffer[1];
992} __packed;
993
Pavel Shilovsky35143eb2012-09-18 16:20:31 -0700994struct smb2_set_info_req {
995 struct smb2_hdr hdr;
996 __le16 StructureSize; /* Must be 33 */
997 __u8 InfoType;
998 __u8 FileInfoClass;
999 __le32 BufferLength;
1000 __le16 BufferOffset;
1001 __u16 Reserved;
1002 __le32 AdditionalInformation;
1003 __u64 PersistentFileId; /* opaque endianness */
1004 __u64 VolatileFileId; /* opaque endianness */
1005 __u8 Buffer[1];
1006} __packed;
1007
1008struct smb2_set_info_rsp {
1009 struct smb2_hdr hdr;
1010 __le16 StructureSize; /* Must be 2 */
1011} __packed;
1012
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001013struct smb2_oplock_break {
1014 struct smb2_hdr hdr;
1015 __le16 StructureSize; /* Must be 24 */
1016 __u8 OplockLevel;
1017 __u8 Reserved;
1018 __le32 Reserved2;
1019 __u64 PersistentFid;
1020 __u64 VolatileFid;
1021} __packed;
1022
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001023#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1024
1025struct smb2_lease_break {
1026 struct smb2_hdr hdr;
1027 __le16 StructureSize; /* Must be 44 */
1028 __le16 Reserved;
1029 __le32 Flags;
1030 __u8 LeaseKey[16];
1031 __le32 CurrentLeaseState;
1032 __le32 NewLeaseState;
1033 __le32 BreakReason;
1034 __le32 AccessMaskHint;
1035 __le32 ShareMaskHint;
1036} __packed;
1037
1038struct smb2_lease_ack {
1039 struct smb2_hdr hdr;
1040 __le16 StructureSize; /* Must be 36 */
1041 __le16 Reserved;
1042 __le32 Flags;
1043 __u8 LeaseKey[16];
1044 __le32 LeaseState;
1045 __le64 LeaseDuration;
1046} __packed;
1047
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001048/*
1049 * PDU infolevel structure definitions
1050 * BB consider moving to a different header
1051 */
1052
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001053/* File System Information Classes */
1054#define FS_VOLUME_INFORMATION 1 /* Query */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001055#define FS_LABEL_INFORMATION 2 /* Local only */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001056#define FS_SIZE_INFORMATION 3 /* Query */
1057#define FS_DEVICE_INFORMATION 4 /* Query */
1058#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1059#define FS_CONTROL_INFORMATION 6 /* Query, Set */
1060#define FS_FULL_SIZE_INFORMATION 7 /* Query */
1061#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001062#define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
1063#define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
1064#define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001065
1066struct smb2_fs_full_size_info {
1067 __le64 TotalAllocationUnits;
1068 __le64 CallerAvailableAllocationUnits;
1069 __le64 ActualAvailableAllocationUnits;
1070 __le32 SectorsPerAllocationUnit;
1071 __le32 BytesPerSector;
1072} __packed;
1073
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001074#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1075#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1076#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1077#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1078
1079/* sector size info struct */
1080struct smb3_fs_ss_info {
1081 __le32 LogicalBytesPerSector;
1082 __le32 PhysicalBytesPerSectorForAtomicity;
1083 __le32 PhysicalBytesPerSectorForPerf;
1084 __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
1085 __le32 Flags;
1086 __le32 ByteOffsetForSectorAlignment;
1087 __le32 ByteOffsetForPartitionAlignment;
1088} __packed;
1089
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001090/* partial list of QUERY INFO levels */
1091#define FILE_DIRECTORY_INFORMATION 1
1092#define FILE_FULL_DIRECTORY_INFORMATION 2
1093#define FILE_BOTH_DIRECTORY_INFORMATION 3
1094#define FILE_BASIC_INFORMATION 4
1095#define FILE_STANDARD_INFORMATION 5
1096#define FILE_INTERNAL_INFORMATION 6
1097#define FILE_EA_INFORMATION 7
1098#define FILE_ACCESS_INFORMATION 8
1099#define FILE_NAME_INFORMATION 9
1100#define FILE_RENAME_INFORMATION 10
1101#define FILE_LINK_INFORMATION 11
1102#define FILE_NAMES_INFORMATION 12
1103#define FILE_DISPOSITION_INFORMATION 13
1104#define FILE_POSITION_INFORMATION 14
1105#define FILE_FULL_EA_INFORMATION 15
1106#define FILE_MODE_INFORMATION 16
1107#define FILE_ALIGNMENT_INFORMATION 17
1108#define FILE_ALL_INFORMATION 18
1109#define FILE_ALLOCATION_INFORMATION 19
1110#define FILE_END_OF_FILE_INFORMATION 20
1111#define FILE_ALTERNATE_NAME_INFORMATION 21
1112#define FILE_STREAM_INFORMATION 22
1113#define FILE_PIPE_INFORMATION 23
1114#define FILE_PIPE_LOCAL_INFORMATION 24
1115#define FILE_PIPE_REMOTE_INFORMATION 25
1116#define FILE_MAILSLOT_QUERY_INFORMATION 26
1117#define FILE_MAILSLOT_SET_INFORMATION 27
1118#define FILE_COMPRESSION_INFORMATION 28
1119#define FILE_OBJECT_ID_INFORMATION 29
1120/* Number 30 not defined in documents */
1121#define FILE_MOVE_CLUSTER_INFORMATION 31
1122#define FILE_QUOTA_INFORMATION 32
1123#define FILE_REPARSE_POINT_INFORMATION 33
1124#define FILE_NETWORK_OPEN_INFORMATION 34
1125#define FILE_ATTRIBUTE_TAG_INFORMATION 35
1126#define FILE_TRACKING_INFORMATION 36
1127#define FILEID_BOTH_DIRECTORY_INFORMATION 37
1128#define FILEID_FULL_DIRECTORY_INFORMATION 38
1129#define FILE_VALID_DATA_LENGTH_INFORMATION 39
1130#define FILE_SHORT_NAME_INFORMATION 40
1131#define FILE_SFIO_RESERVE_INFORMATION 44
1132#define FILE_SFIO_VOLUME_INFORMATION 45
1133#define FILE_HARD_LINK_INFORMATION 46
1134#define FILE_NORMALIZED_NAME_INFORMATION 48
1135#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1136#define FILE_STANDARD_LINK_INFORMATION 54
1137
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001138struct smb2_file_internal_info {
1139 __le64 IndexNumber;
1140} __packed; /* level 6 Query */
1141
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001142struct smb2_file_rename_info { /* encoding of request for level 10 */
1143 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1144 /* 0 = fail if target already exists */
1145 __u8 Reserved[7];
1146 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1147 __le32 FileNameLength;
1148 char FileName[0]; /* New name to be assigned */
1149} __packed; /* level 10 Set */
1150
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001151struct smb2_file_link_info { /* encoding of request for level 11 */
1152 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1153 /* 0 = fail if link already exists */
1154 __u8 Reserved[7];
1155 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1156 __le32 FileNameLength;
1157 char FileName[0]; /* Name to be assigned to new link */
1158} __packed; /* level 11 Set */
1159
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001160/*
1161 * This level 18, although with struct with same name is different from cifs
1162 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1163 * CurrentByteOffset.
1164 */
1165struct smb2_file_all_info { /* data block encoding of response to level 18 */
1166 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1167 __le64 LastAccessTime;
1168 __le64 LastWriteTime;
1169 __le64 ChangeTime;
1170 __le32 Attributes;
1171 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1172 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1173 __le64 EndOfFile; /* size ie offset to first free byte in file */
1174 __le32 NumberOfLinks; /* hard links */
1175 __u8 DeletePending;
1176 __u8 Directory;
1177 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1178 __le64 IndexNumber;
1179 __le32 EASize;
1180 __le32 AccessFlags;
1181 __le64 CurrentByteOffset;
1182 __le32 Mode;
1183 __le32 AlignmentRequirement;
1184 __le32 FileNameLength;
1185 char FileName[1];
1186} __packed; /* level 18 Query */
1187
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001188struct smb2_file_eof_info { /* encoding of request for level 10 */
1189 __le64 EndOfFile; /* new end of file value */
1190} __packed; /* level 20 Set */
1191
Steve Frenchddfbefb2011-03-15 02:08:48 +00001192#endif /* _SMB2PDU_H */