blob: e27ad39f2bde296288c388e94d22034d9389c967 [file] [log] [blame]
Steve Frenchddfbefb2011-03-15 02:08:48 +00001/*
2 * fs/cifs/smb2pdu.h
3 *
4 * Copyright (c) International Business Machines Corp., 2009, 2010
5 * 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
83#define NUMBER_OF_SMB2_COMMANDS 0x0013
84
85/* BB FIXME - analyze following length BB */
86#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
87
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +040088#define SMB2_PROTO_NUMBER __constant_cpu_to_le32(0x424d53fe)
89
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040090/*
Steve Frenchddfbefb2011-03-15 02:08:48 +000091 * SMB2 Header Definition
92 *
93 * "MBZ" : Must be Zero
94 * "BB" : BugBug, Something to check/review/analyze later
95 * "PDU" : "Protocol Data Unit" (ie a network "frame")
96 *
97 */
Pavel Shilovsky74112862012-07-27 01:20:41 +040098
Pavel Shilovskyb2ede582012-09-04 15:49:31 +040099#define SMB2_HEADER_STRUCTURE_SIZE __constant_cpu_to_le16(64)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400100
Steve Frenchddfbefb2011-03-15 02:08:48 +0000101struct smb2_hdr {
102 __be32 smb2_buf_length; /* big endian on wire */
103 /* length is only two or three bytes - with
104 one or two byte type preceding it that MBZ */
105 __u8 ProtocolId[4]; /* 0xFE 'S' 'M' 'B' */
106 __le16 StructureSize; /* 64 */
107 __le16 CreditCharge; /* MBZ */
108 __le32 Status; /* Error from server */
109 __le16 Command;
110 __le16 CreditRequest; /* CreditResponse */
111 __le32 Flags;
112 __le32 NextCommand;
113 __u64 MessageId; /* opaque - so can stay little endian */
114 __le32 ProcessId;
115 __u32 TreeId; /* opaque - so do not make little endian */
116 __u64 SessionId; /* opaque - so do not make little endian */
117 __u8 Signature[16];
118} __packed;
119
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400120struct smb2_pdu {
121 struct smb2_hdr hdr;
122 __le16 StructureSize2; /* size of wct area (varies, request specific) */
123} __packed;
124
125/*
126 * SMB2 flag definitions
127 */
128#define SMB2_FLAGS_SERVER_TO_REDIR __constant_cpu_to_le32(0x00000001)
129#define SMB2_FLAGS_ASYNC_COMMAND __constant_cpu_to_le32(0x00000002)
130#define SMB2_FLAGS_RELATED_OPERATIONS __constant_cpu_to_le32(0x00000004)
131#define SMB2_FLAGS_SIGNED __constant_cpu_to_le32(0x00000008)
132#define SMB2_FLAGS_DFS_OPERATIONS __constant_cpu_to_le32(0x10000000)
133
134/*
135 * Definitions for SMB2 Protocol Data Units (network frames)
136 *
137 * See MS-SMB2.PDF specification for protocol details.
138 * The Naming convention is the lower case version of the SMB2
139 * command code name for the struct. Note that structures must be packed.
140 *
141 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400142
Pavel Shilovskyb2ede582012-09-04 15:49:31 +0400143#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_cpu_to_le16(9)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400144
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400145struct smb2_err_rsp {
146 struct smb2_hdr hdr;
147 __le16 StructureSize;
148 __le16 Reserved; /* MBZ */
149 __le32 ByteCount; /* even if zero, at least one byte follows */
150 __u8 ErrorData[1]; /* variable length */
151} __packed;
152
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700153#define SMB2_CLIENT_GUID_SIZE 16
154
155extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE];
156
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400157struct smb2_negotiate_req {
158 struct smb2_hdr hdr;
159 __le16 StructureSize; /* Must be 36 */
160 __le16 DialectCount;
161 __le16 SecurityMode;
162 __le16 Reserved; /* MBZ */
163 __le32 Capabilities;
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700164 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400165 __le64 ClientStartTime; /* MBZ */
Steve Frenche4aa25e2012-10-01 12:26:22 -0500166 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400167} __packed;
168
Steve Frenche4aa25e2012-10-01 12:26:22 -0500169/* Dialects */
170#define SMB20_PROT_ID 0x0202
171#define SMB21_PROT_ID 0x0210
172#define SMB30_PROT_ID 0x0300
Steve French20b6d8b2013-06-12 22:48:41 -0500173#define SMB302_PROT_ID 0x0302
Steve Frenche4aa25e2012-10-01 12:26:22 -0500174#define BAD_PROT_ID 0xFFFF
175
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400176/* SecurityMode flags */
177#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
178#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
179/* Capabilities flags */
180#define SMB2_GLOBAL_CAP_DFS 0x00000001
181#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
182#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
Steve Frenche4aa25e2012-10-01 12:26:22 -0500183#define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
184#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
185#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
186#define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
Pavel Shilovsky29e20f92012-07-13 13:58:14 +0400187/* Internal types */
188#define SMB2_NT_FIND 0x00100000
189#define SMB2_LARGE_FILES 0x00200000
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400190
191struct smb2_negotiate_rsp {
192 struct smb2_hdr hdr;
193 __le16 StructureSize; /* Must be 65 */
194 __le16 SecurityMode;
195 __le16 DialectRevision;
196 __le16 Reserved; /* MBZ */
197 __u8 ServerGUID[16];
198 __le32 Capabilities;
199 __le32 MaxTransactSize;
200 __le32 MaxReadSize;
201 __le32 MaxWriteSize;
202 __le64 SystemTime; /* MBZ */
203 __le64 ServerStartTime;
204 __le16 SecurityBufferOffset;
205 __le16 SecurityBufferLength;
206 __le32 Reserved2; /* may be any value, ignore */
207 __u8 Buffer[1]; /* variable length GSS security buffer */
208} __packed;
209
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400210struct smb2_sess_setup_req {
211 struct smb2_hdr hdr;
212 __le16 StructureSize; /* Must be 25 */
213 __u8 VcNumber;
214 __u8 SecurityMode;
215 __le32 Capabilities;
216 __le32 Channel;
217 __le16 SecurityBufferOffset;
218 __le16 SecurityBufferLength;
219 __le64 PreviousSessionId;
220 __u8 Buffer[1]; /* variable length GSS security buffer */
221} __packed;
222
223/* Currently defined SessionFlags */
224#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
225#define SMB2_SESSION_FLAG_IS_NULL 0x0002
226struct smb2_sess_setup_rsp {
227 struct smb2_hdr hdr;
228 __le16 StructureSize; /* Must be 9 */
229 __le16 SessionFlags;
230 __le16 SecurityBufferOffset;
231 __le16 SecurityBufferLength;
232 __u8 Buffer[1]; /* variable length GSS security buffer */
233} __packed;
234
235struct smb2_logoff_req {
236 struct smb2_hdr hdr;
237 __le16 StructureSize; /* Must be 4 */
238 __le16 Reserved;
239} __packed;
240
241struct smb2_logoff_rsp {
242 struct smb2_hdr hdr;
243 __le16 StructureSize; /* Must be 4 */
244 __le16 Reserved;
245} __packed;
246
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400247struct smb2_tree_connect_req {
248 struct smb2_hdr hdr;
249 __le16 StructureSize; /* Must be 9 */
250 __le16 Reserved;
251 __le16 PathOffset;
252 __le16 PathLength;
253 __u8 Buffer[1]; /* variable length */
254} __packed;
255
256struct smb2_tree_connect_rsp {
257 struct smb2_hdr hdr;
258 __le16 StructureSize; /* Must be 16 */
259 __u8 ShareType; /* see below */
260 __u8 Reserved;
261 __le32 ShareFlags; /* see below */
262 __le32 Capabilities; /* see below */
263 __le32 MaximalAccess;
264} __packed;
265
266/* Possible ShareType values */
267#define SMB2_SHARE_TYPE_DISK 0x01
268#define SMB2_SHARE_TYPE_PIPE 0x02
269#define SMB2_SHARE_TYPE_PRINT 0x03
270
271/*
272 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
273 * must be set (any of the remaining, SHI1005, flags may be set individually
274 * or in combination.
275 */
276#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
277#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
278#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
279#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
280#define SHI1005_FLAGS_DFS 0x00000001
281#define SHI1005_FLAGS_DFS_ROOT 0x00000002
282#define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
283#define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
284#define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
285#define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
286#define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
287#define SHI1005_FLAGS_ENABLE_HASH 0x00002000
288
289/* Possible share capabilities */
Steve French2b5dc282013-06-13 10:51:10 -0500290#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
291#define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
292#define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
293#define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
294#define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400295
296struct smb2_tree_disconnect_req {
297 struct smb2_hdr hdr;
298 __le16 StructureSize; /* Must be 4 */
299 __le16 Reserved;
300} __packed;
301
302struct smb2_tree_disconnect_rsp {
303 struct smb2_hdr hdr;
304 __le16 StructureSize; /* Must be 4 */
305 __le16 Reserved;
306} __packed;
307
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400308/* File Attrubutes */
309#define FILE_ATTRIBUTE_READONLY 0x00000001
310#define FILE_ATTRIBUTE_HIDDEN 0x00000002
311#define FILE_ATTRIBUTE_SYSTEM 0x00000004
312#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
313#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
314#define FILE_ATTRIBUTE_NORMAL 0x00000080
315#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
316#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
317#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
318#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
319#define FILE_ATTRIBUTE_OFFLINE 0x00001000
320#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
321#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
322
323/* Oplock levels */
324#define SMB2_OPLOCK_LEVEL_NONE 0x00
325#define SMB2_OPLOCK_LEVEL_II 0x01
326#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
327#define SMB2_OPLOCK_LEVEL_BATCH 0x09
328#define SMB2_OPLOCK_LEVEL_LEASE 0xFF
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700329/* Non-spec internal type */
330#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400331
332/* Desired Access Flags */
333#define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
334#define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
335#define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
336#define FILE_READ_EA_LE cpu_to_le32(0x00000008)
337#define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
338#define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
339#define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
340#define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
341#define FILE_DELETE_LE cpu_to_le32(0x00010000)
342#define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
343#define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
344#define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
345#define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
346#define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
347#define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
348#define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
349#define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
350#define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
351#define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
352
353/* ShareAccess Flags */
354#define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
355#define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
356#define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
357#define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
358
359/* CreateDisposition Flags */
360#define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
361#define FILE_OPEN_LE cpu_to_le32(0x00000001)
362#define FILE_CREATE_LE cpu_to_le32(0x00000002)
363#define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
364#define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
365#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
366
367/* CreateOptions Flags */
368#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
369/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
370#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
371#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
372#define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
373#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
374#define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
375#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
376#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
377#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
378#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
379#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
380#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
381#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
382#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
383#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
384#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
385#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
386#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
387
388#define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
389 | FILE_READ_ATTRIBUTES_LE)
390#define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
391 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
392#define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
393
394/* Impersonation Levels */
395#define IL_ANONYMOUS cpu_to_le32(0x00000000)
396#define IL_IDENTIFICATION cpu_to_le32(0x00000001)
397#define IL_IMPERSONATION cpu_to_le32(0x00000002)
398#define IL_DELEGATE cpu_to_le32(0x00000003)
399
400/* Create Context Values */
401#define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
402#define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
403#define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
404#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
405#define SMB2_CREATE_ALLOCATION_SIZE "AlSi"
406#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
407#define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
408#define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
409#define SMB2_CREATE_REQUEST_LEASE "RqLs"
410
411struct smb2_create_req {
412 struct smb2_hdr hdr;
413 __le16 StructureSize; /* Must be 57 */
414 __u8 SecurityFlags;
415 __u8 RequestedOplockLevel;
416 __le32 ImpersonationLevel;
417 __le64 SmbCreateFlags;
418 __le64 Reserved;
419 __le32 DesiredAccess;
420 __le32 FileAttributes;
421 __le32 ShareAccess;
422 __le32 CreateDisposition;
423 __le32 CreateOptions;
424 __le16 NameOffset;
425 __le16 NameLength;
426 __le32 CreateContextsOffset;
427 __le32 CreateContextsLength;
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700428 __u8 Buffer[8];
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400429} __packed;
430
431struct smb2_create_rsp {
432 struct smb2_hdr hdr;
433 __le16 StructureSize; /* Must be 89 */
434 __u8 OplockLevel;
435 __u8 Reserved;
436 __le32 CreateAction;
437 __le64 CreationTime;
438 __le64 LastAccessTime;
439 __le64 LastWriteTime;
440 __le64 ChangeTime;
441 __le64 AllocationSize;
442 __le64 EndofFile;
443 __le32 FileAttributes;
444 __le32 Reserved2;
445 __u64 PersistentFileId; /* opaque endianness */
446 __u64 VolatileFileId; /* opaque endianness */
447 __le32 CreateContextsOffset;
448 __le32 CreateContextsLength;
449 __u8 Buffer[1];
450} __packed;
451
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700452struct create_context {
453 __le32 Next;
454 __le16 NameOffset;
455 __le16 NameLength;
456 __le16 Reserved;
457 __le16 DataOffset;
458 __le32 DataLength;
459 __u8 Buffer[0];
460} __packed;
461
462#define SMB2_LEASE_NONE __constant_cpu_to_le32(0x00)
463#define SMB2_LEASE_READ_CACHING __constant_cpu_to_le32(0x01)
464#define SMB2_LEASE_HANDLE_CACHING __constant_cpu_to_le32(0x02)
465#define SMB2_LEASE_WRITE_CACHING __constant_cpu_to_le32(0x04)
466
467#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS __constant_cpu_to_le32(0x02)
468
469#define SMB2_LEASE_KEY_SIZE 16
470
471struct lease_context {
472 __le64 LeaseKeyLow;
473 __le64 LeaseKeyHigh;
474 __le32 LeaseState;
475 __le32 LeaseFlags;
476 __le64 LeaseDuration;
477} __packed;
478
479struct create_lease {
480 struct create_context ccontext;
481 __u8 Name[8];
482 struct lease_context lcontext;
483} __packed;
484
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400485/* Currently defined values for close flags */
486#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
487struct smb2_close_req {
488 struct smb2_hdr hdr;
489 __le16 StructureSize; /* Must be 24 */
490 __le16 Flags;
491 __le32 Reserved;
492 __u64 PersistentFileId; /* opaque endianness */
493 __u64 VolatileFileId; /* opaque endianness */
494} __packed;
495
496struct smb2_close_rsp {
497 struct smb2_hdr hdr;
498 __le16 StructureSize; /* 60 */
499 __le16 Flags;
500 __le32 Reserved;
501 __le64 CreationTime;
502 __le64 LastAccessTime;
503 __le64 LastWriteTime;
504 __le64 ChangeTime;
505 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
506 __le64 EndOfFile;
507 __le32 Attributes;
508} __packed;
509
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700510struct smb2_flush_req {
511 struct smb2_hdr hdr;
512 __le16 StructureSize; /* Must be 24 */
513 __le16 Reserved1;
514 __le32 Reserved2;
515 __u64 PersistentFileId; /* opaque endianness */
516 __u64 VolatileFileId; /* opaque endianness */
517} __packed;
518
519struct smb2_flush_rsp {
520 struct smb2_hdr hdr;
521 __le16 StructureSize;
522 __le16 Reserved;
523} __packed;
524
Steve French2b5dc282013-06-13 10:51:10 -0500525/* For read request Flags field below, following flag is defined for SMB3.02 */
526#define SMB2_READFLAG_READ_UNBUFFERED 0x01
527
528/* Channel field for read and write: exactly one of following flags can be set*/
529#define SMB2_CHANNEL_NONE 0x00000000
530#define SMB2_CHANNEL_RDMA_V1 0x00000001 /* SMB3 or later */
531#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001 /* SMB3.02 or later */
532
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700533struct smb2_read_req {
534 struct smb2_hdr hdr;
535 __le16 StructureSize; /* Must be 49 */
536 __u8 Padding; /* offset from start of SMB2 header to place read */
Steve French2b5dc282013-06-13 10:51:10 -0500537 __u8 Flags; /* MBZ unless SMB3.02 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700538 __le32 Length;
539 __le64 Offset;
540 __u64 PersistentFileId; /* opaque endianness */
541 __u64 VolatileFileId; /* opaque endianness */
542 __le32 MinimumCount;
Steve French2b5dc282013-06-13 10:51:10 -0500543 __le32 Channel; /* MBZ except for SMB3 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700544 __le32 RemainingBytes;
545 __le16 ReadChannelInfoOffset; /* Reserved MBZ */
546 __le16 ReadChannelInfoLength; /* Reserved MBZ */
547 __u8 Buffer[1];
548} __packed;
549
550struct smb2_read_rsp {
551 struct smb2_hdr hdr;
552 __le16 StructureSize; /* Must be 17 */
553 __u8 DataOffset;
554 __u8 Reserved;
555 __le32 DataLength;
556 __le32 DataRemaining;
557 __u32 Reserved2;
558 __u8 Buffer[1];
559} __packed;
560
Steve French2b5dc282013-06-13 10:51:10 -0500561/* For write request Flags field below the following flags are defined: */
562#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
563#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
Pavel Shilovsky33319142012-09-18 16:20:29 -0700564
565struct smb2_write_req {
566 struct smb2_hdr hdr;
567 __le16 StructureSize; /* Must be 49 */
568 __le16 DataOffset; /* offset from start of SMB2 header to write data */
569 __le32 Length;
570 __le64 Offset;
571 __u64 PersistentFileId; /* opaque endianness */
572 __u64 VolatileFileId; /* opaque endianness */
573 __le32 Channel; /* Reserved MBZ */
574 __le32 RemainingBytes;
575 __le16 WriteChannelInfoOffset; /* Reserved MBZ */
576 __le16 WriteChannelInfoLength; /* Reserved MBZ */
577 __le32 Flags;
578 __u8 Buffer[1];
579} __packed;
580
581struct smb2_write_rsp {
582 struct smb2_hdr hdr;
583 __le16 StructureSize; /* Must be 17 */
584 __u8 DataOffset;
585 __u8 Reserved;
586 __le32 DataLength;
587 __le32 DataRemaining;
588 __u32 Reserved2;
589 __u8 Buffer[1];
590} __packed;
591
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -0700592#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
593#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
594#define SMB2_LOCKFLAG_UNLOCK 0x0004
595#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
596
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -0700597struct smb2_lock_element {
598 __le64 Offset;
599 __le64 Length;
600 __le32 Flags;
601 __le32 Reserved;
602} __packed;
603
604struct smb2_lock_req {
605 struct smb2_hdr hdr;
606 __le16 StructureSize; /* Must be 48 */
607 __le16 LockCount;
608 __le32 Reserved;
609 __u64 PersistentFileId; /* opaque endianness */
610 __u64 VolatileFileId; /* opaque endianness */
611 /* Followed by at least one */
612 struct smb2_lock_element locks[1];
613} __packed;
614
615struct smb2_lock_rsp {
616 struct smb2_hdr hdr;
617 __le16 StructureSize; /* Must be 4 */
618 __le16 Reserved;
619} __packed;
620
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400621struct smb2_echo_req {
622 struct smb2_hdr hdr;
623 __le16 StructureSize; /* Must be 4 */
624 __u16 Reserved;
625} __packed;
626
627struct smb2_echo_rsp {
628 struct smb2_hdr hdr;
629 __le16 StructureSize; /* Must be 4 */
630 __u16 Reserved;
631} __packed;
632
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700633/* search (query_directory) Flags field */
634#define SMB2_RESTART_SCANS 0x01
635#define SMB2_RETURN_SINGLE_ENTRY 0x02
636#define SMB2_INDEX_SPECIFIED 0x04
637#define SMB2_REOPEN 0x10
638
639struct smb2_query_directory_req {
640 struct smb2_hdr hdr;
641 __le16 StructureSize; /* Must be 33 */
642 __u8 FileInformationClass;
643 __u8 Flags;
644 __le32 FileIndex;
645 __u64 PersistentFileId; /* opaque endianness */
646 __u64 VolatileFileId; /* opaque endianness */
647 __le16 FileNameOffset;
648 __le16 FileNameLength;
649 __le32 OutputBufferLength;
650 __u8 Buffer[1];
651} __packed;
652
653struct smb2_query_directory_rsp {
654 struct smb2_hdr hdr;
655 __le16 StructureSize; /* Must be 9 */
656 __le16 OutputBufferOffset;
657 __le32 OutputBufferLength;
658 __u8 Buffer[1];
659} __packed;
660
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400661/* Possible InfoType values */
662#define SMB2_O_INFO_FILE 0x01
663#define SMB2_O_INFO_FILESYSTEM 0x02
664#define SMB2_O_INFO_SECURITY 0x03
665#define SMB2_O_INFO_QUOTA 0x04
666
667struct smb2_query_info_req {
668 struct smb2_hdr hdr;
669 __le16 StructureSize; /* Must be 41 */
670 __u8 InfoType;
671 __u8 FileInfoClass;
672 __le32 OutputBufferLength;
673 __le16 InputBufferOffset;
674 __u16 Reserved;
675 __le32 InputBufferLength;
676 __le32 AdditionalInformation;
677 __le32 Flags;
678 __u64 PersistentFileId; /* opaque endianness */
679 __u64 VolatileFileId; /* opaque endianness */
680 __u8 Buffer[1];
681} __packed;
682
683struct smb2_query_info_rsp {
684 struct smb2_hdr hdr;
685 __le16 StructureSize; /* Must be 9 */
686 __le16 OutputBufferOffset;
687 __le32 OutputBufferLength;
688 __u8 Buffer[1];
689} __packed;
690
Pavel Shilovsky35143eb2012-09-18 16:20:31 -0700691struct smb2_set_info_req {
692 struct smb2_hdr hdr;
693 __le16 StructureSize; /* Must be 33 */
694 __u8 InfoType;
695 __u8 FileInfoClass;
696 __le32 BufferLength;
697 __le16 BufferOffset;
698 __u16 Reserved;
699 __le32 AdditionalInformation;
700 __u64 PersistentFileId; /* opaque endianness */
701 __u64 VolatileFileId; /* opaque endianness */
702 __u8 Buffer[1];
703} __packed;
704
705struct smb2_set_info_rsp {
706 struct smb2_hdr hdr;
707 __le16 StructureSize; /* Must be 2 */
708} __packed;
709
Pavel Shilovsky983c88a2012-09-18 16:20:33 -0700710struct smb2_oplock_break {
711 struct smb2_hdr hdr;
712 __le16 StructureSize; /* Must be 24 */
713 __u8 OplockLevel;
714 __u8 Reserved;
715 __le32 Reserved2;
716 __u64 PersistentFid;
717 __u64 VolatileFid;
718} __packed;
719
Pavel Shilovsky0822f512012-09-19 06:22:45 -0700720#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
721
722struct smb2_lease_break {
723 struct smb2_hdr hdr;
724 __le16 StructureSize; /* Must be 44 */
725 __le16 Reserved;
726 __le32 Flags;
727 __u8 LeaseKey[16];
728 __le32 CurrentLeaseState;
729 __le32 NewLeaseState;
730 __le32 BreakReason;
731 __le32 AccessMaskHint;
732 __le32 ShareMaskHint;
733} __packed;
734
735struct smb2_lease_ack {
736 struct smb2_hdr hdr;
737 __le16 StructureSize; /* Must be 36 */
738 __le16 Reserved;
739 __le32 Flags;
740 __u8 LeaseKey[16];
741 __le32 LeaseState;
742 __le64 LeaseDuration;
743} __packed;
744
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400745/*
746 * PDU infolevel structure definitions
747 * BB consider moving to a different header
748 */
749
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -0700750/* File System Information Classes */
751#define FS_VOLUME_INFORMATION 1 /* Query */
752#define FS_LABEL_INFORMATION 2 /* Set */
753#define FS_SIZE_INFORMATION 3 /* Query */
754#define FS_DEVICE_INFORMATION 4 /* Query */
755#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
756#define FS_CONTROL_INFORMATION 6 /* Query, Set */
757#define FS_FULL_SIZE_INFORMATION 7 /* Query */
758#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
759#define FS_DRIVER_PATH_INFORMATION 9 /* Query */
760
761struct smb2_fs_full_size_info {
762 __le64 TotalAllocationUnits;
763 __le64 CallerAvailableAllocationUnits;
764 __le64 ActualAvailableAllocationUnits;
765 __le32 SectorsPerAllocationUnit;
766 __le32 BytesPerSector;
767} __packed;
768
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400769/* partial list of QUERY INFO levels */
770#define FILE_DIRECTORY_INFORMATION 1
771#define FILE_FULL_DIRECTORY_INFORMATION 2
772#define FILE_BOTH_DIRECTORY_INFORMATION 3
773#define FILE_BASIC_INFORMATION 4
774#define FILE_STANDARD_INFORMATION 5
775#define FILE_INTERNAL_INFORMATION 6
776#define FILE_EA_INFORMATION 7
777#define FILE_ACCESS_INFORMATION 8
778#define FILE_NAME_INFORMATION 9
779#define FILE_RENAME_INFORMATION 10
780#define FILE_LINK_INFORMATION 11
781#define FILE_NAMES_INFORMATION 12
782#define FILE_DISPOSITION_INFORMATION 13
783#define FILE_POSITION_INFORMATION 14
784#define FILE_FULL_EA_INFORMATION 15
785#define FILE_MODE_INFORMATION 16
786#define FILE_ALIGNMENT_INFORMATION 17
787#define FILE_ALL_INFORMATION 18
788#define FILE_ALLOCATION_INFORMATION 19
789#define FILE_END_OF_FILE_INFORMATION 20
790#define FILE_ALTERNATE_NAME_INFORMATION 21
791#define FILE_STREAM_INFORMATION 22
792#define FILE_PIPE_INFORMATION 23
793#define FILE_PIPE_LOCAL_INFORMATION 24
794#define FILE_PIPE_REMOTE_INFORMATION 25
795#define FILE_MAILSLOT_QUERY_INFORMATION 26
796#define FILE_MAILSLOT_SET_INFORMATION 27
797#define FILE_COMPRESSION_INFORMATION 28
798#define FILE_OBJECT_ID_INFORMATION 29
799/* Number 30 not defined in documents */
800#define FILE_MOVE_CLUSTER_INFORMATION 31
801#define FILE_QUOTA_INFORMATION 32
802#define FILE_REPARSE_POINT_INFORMATION 33
803#define FILE_NETWORK_OPEN_INFORMATION 34
804#define FILE_ATTRIBUTE_TAG_INFORMATION 35
805#define FILE_TRACKING_INFORMATION 36
806#define FILEID_BOTH_DIRECTORY_INFORMATION 37
807#define FILEID_FULL_DIRECTORY_INFORMATION 38
808#define FILE_VALID_DATA_LENGTH_INFORMATION 39
809#define FILE_SHORT_NAME_INFORMATION 40
810#define FILE_SFIO_RESERVE_INFORMATION 44
811#define FILE_SFIO_VOLUME_INFORMATION 45
812#define FILE_HARD_LINK_INFORMATION 46
813#define FILE_NORMALIZED_NAME_INFORMATION 48
814#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
815#define FILE_STANDARD_LINK_INFORMATION 54
816
Pavel Shilovskyf0df7372012-09-18 16:20:26 -0700817struct smb2_file_internal_info {
818 __le64 IndexNumber;
819} __packed; /* level 6 Query */
820
Pavel Shilovsky35143eb2012-09-18 16:20:31 -0700821struct smb2_file_rename_info { /* encoding of request for level 10 */
822 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
823 /* 0 = fail if target already exists */
824 __u8 Reserved[7];
825 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
826 __le32 FileNameLength;
827 char FileName[0]; /* New name to be assigned */
828} __packed; /* level 10 Set */
829
Pavel Shilovsky568798c2012-09-18 16:20:31 -0700830struct smb2_file_link_info { /* encoding of request for level 11 */
831 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
832 /* 0 = fail if link already exists */
833 __u8 Reserved[7];
834 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
835 __le32 FileNameLength;
836 char FileName[0]; /* Name to be assigned to new link */
837} __packed; /* level 11 Set */
838
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400839/*
840 * This level 18, although with struct with same name is different from cifs
841 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
842 * CurrentByteOffset.
843 */
844struct smb2_file_all_info { /* data block encoding of response to level 18 */
845 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
846 __le64 LastAccessTime;
847 __le64 LastWriteTime;
848 __le64 ChangeTime;
849 __le32 Attributes;
850 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
851 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
852 __le64 EndOfFile; /* size ie offset to first free byte in file */
853 __le32 NumberOfLinks; /* hard links */
854 __u8 DeletePending;
855 __u8 Directory;
856 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
857 __le64 IndexNumber;
858 __le32 EASize;
859 __le32 AccessFlags;
860 __le64 CurrentByteOffset;
861 __le32 Mode;
862 __le32 AlignmentRequirement;
863 __le32 FileNameLength;
864 char FileName[1];
865} __packed; /* level 18 Query */
866
Pavel Shilovskyc839ff22012-09-18 16:20:32 -0700867struct smb2_file_eof_info { /* encoding of request for level 10 */
868 __le64 EndOfFile; /* new end of file value */
869} __packed; /* level 20 Set */
870
Steve Frenchddfbefb2011-03-15 02:08:48 +0000871#endif /* _SMB2PDU_H */