Commit | Line | Data |
---|---|---|
ddfbefbd SF |
1 | /* |
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 | ||
2dc7e1c0 PS |
29 | /* |
30 | * 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 | ||
093b2bda PS |
88 | #define SMB2_PROTO_NUMBER __constant_cpu_to_le32(0x424d53fe) |
89 | ||
ddfbefbd SF |
90 | /* |
91 | * 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 | */ | |
74112860 | 98 | |
b2ede58e | 99 | #define SMB2_HEADER_STRUCTURE_SIZE __constant_cpu_to_le16(64) |
74112860 | 100 | |
ddfbefbd SF |
101 | struct 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 | ||
093b2bda PS |
120 | struct 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 | */ | |
74112860 | 142 | |
b2ede58e | 143 | #define SMB2_ERROR_STRUCTURE_SIZE2 __constant_cpu_to_le16(9) |
74112860 | 144 | |
093b2bda PS |
145 | struct 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 | ||
ec2e4523 PS |
153 | struct smb2_negotiate_req { |
154 | struct smb2_hdr hdr; | |
155 | __le16 StructureSize; /* Must be 36 */ | |
156 | __le16 DialectCount; | |
157 | __le16 SecurityMode; | |
158 | __le16 Reserved; /* MBZ */ | |
159 | __le32 Capabilities; | |
160 | __u8 ClientGUID[16]; /* MBZ */ | |
161 | __le64 ClientStartTime; /* MBZ */ | |
162 | __le16 Dialects[2]; /* variable length */ | |
163 | } __packed; | |
164 | ||
165 | /* SecurityMode flags */ | |
166 | #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001 | |
167 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 | |
168 | /* Capabilities flags */ | |
169 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 | |
170 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ | |
171 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */ | |
29e20f9c PS |
172 | /* Internal types */ |
173 | #define SMB2_NT_FIND 0x00100000 | |
174 | #define SMB2_LARGE_FILES 0x00200000 | |
ec2e4523 PS |
175 | |
176 | struct smb2_negotiate_rsp { | |
177 | struct smb2_hdr hdr; | |
178 | __le16 StructureSize; /* Must be 65 */ | |
179 | __le16 SecurityMode; | |
180 | __le16 DialectRevision; | |
181 | __le16 Reserved; /* MBZ */ | |
182 | __u8 ServerGUID[16]; | |
183 | __le32 Capabilities; | |
184 | __le32 MaxTransactSize; | |
185 | __le32 MaxReadSize; | |
186 | __le32 MaxWriteSize; | |
187 | __le64 SystemTime; /* MBZ */ | |
188 | __le64 ServerStartTime; | |
189 | __le16 SecurityBufferOffset; | |
190 | __le16 SecurityBufferLength; | |
191 | __le32 Reserved2; /* may be any value, ignore */ | |
192 | __u8 Buffer[1]; /* variable length GSS security buffer */ | |
193 | } __packed; | |
194 | ||
5478f9ba PS |
195 | struct smb2_sess_setup_req { |
196 | struct smb2_hdr hdr; | |
197 | __le16 StructureSize; /* Must be 25 */ | |
198 | __u8 VcNumber; | |
199 | __u8 SecurityMode; | |
200 | __le32 Capabilities; | |
201 | __le32 Channel; | |
202 | __le16 SecurityBufferOffset; | |
203 | __le16 SecurityBufferLength; | |
204 | __le64 PreviousSessionId; | |
205 | __u8 Buffer[1]; /* variable length GSS security buffer */ | |
206 | } __packed; | |
207 | ||
208 | /* Currently defined SessionFlags */ | |
209 | #define SMB2_SESSION_FLAG_IS_GUEST 0x0001 | |
210 | #define SMB2_SESSION_FLAG_IS_NULL 0x0002 | |
211 | struct smb2_sess_setup_rsp { | |
212 | struct smb2_hdr hdr; | |
213 | __le16 StructureSize; /* Must be 9 */ | |
214 | __le16 SessionFlags; | |
215 | __le16 SecurityBufferOffset; | |
216 | __le16 SecurityBufferLength; | |
217 | __u8 Buffer[1]; /* variable length GSS security buffer */ | |
218 | } __packed; | |
219 | ||
220 | struct smb2_logoff_req { | |
221 | struct smb2_hdr hdr; | |
222 | __le16 StructureSize; /* Must be 4 */ | |
223 | __le16 Reserved; | |
224 | } __packed; | |
225 | ||
226 | struct smb2_logoff_rsp { | |
227 | struct smb2_hdr hdr; | |
228 | __le16 StructureSize; /* Must be 4 */ | |
229 | __le16 Reserved; | |
230 | } __packed; | |
231 | ||
faaf946a PS |
232 | struct smb2_tree_connect_req { |
233 | struct smb2_hdr hdr; | |
234 | __le16 StructureSize; /* Must be 9 */ | |
235 | __le16 Reserved; | |
236 | __le16 PathOffset; | |
237 | __le16 PathLength; | |
238 | __u8 Buffer[1]; /* variable length */ | |
239 | } __packed; | |
240 | ||
241 | struct smb2_tree_connect_rsp { | |
242 | struct smb2_hdr hdr; | |
243 | __le16 StructureSize; /* Must be 16 */ | |
244 | __u8 ShareType; /* see below */ | |
245 | __u8 Reserved; | |
246 | __le32 ShareFlags; /* see below */ | |
247 | __le32 Capabilities; /* see below */ | |
248 | __le32 MaximalAccess; | |
249 | } __packed; | |
250 | ||
251 | /* Possible ShareType values */ | |
252 | #define SMB2_SHARE_TYPE_DISK 0x01 | |
253 | #define SMB2_SHARE_TYPE_PIPE 0x02 | |
254 | #define SMB2_SHARE_TYPE_PRINT 0x03 | |
255 | ||
256 | /* | |
257 | * Possible ShareFlags - exactly one and only one of the first 4 caching flags | |
258 | * must be set (any of the remaining, SHI1005, flags may be set individually | |
259 | * or in combination. | |
260 | */ | |
261 | #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000 | |
262 | #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010 | |
263 | #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020 | |
264 | #define SMB2_SHAREFLAG_NO_CACHING 0x00000030 | |
265 | #define SHI1005_FLAGS_DFS 0x00000001 | |
266 | #define SHI1005_FLAGS_DFS_ROOT 0x00000002 | |
267 | #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100 | |
268 | #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200 | |
269 | #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400 | |
270 | #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800 | |
271 | #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000 | |
272 | #define SHI1005_FLAGS_ENABLE_HASH 0x00002000 | |
273 | ||
274 | /* Possible share capabilities */ | |
275 | #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) | |
276 | ||
277 | struct smb2_tree_disconnect_req { | |
278 | struct smb2_hdr hdr; | |
279 | __le16 StructureSize; /* Must be 4 */ | |
280 | __le16 Reserved; | |
281 | } __packed; | |
282 | ||
283 | struct smb2_tree_disconnect_rsp { | |
284 | struct smb2_hdr hdr; | |
285 | __le16 StructureSize; /* Must be 4 */ | |
286 | __le16 Reserved; | |
287 | } __packed; | |
288 | ||
2503a0db PS |
289 | /* File Attrubutes */ |
290 | #define FILE_ATTRIBUTE_READONLY 0x00000001 | |
291 | #define FILE_ATTRIBUTE_HIDDEN 0x00000002 | |
292 | #define FILE_ATTRIBUTE_SYSTEM 0x00000004 | |
293 | #define FILE_ATTRIBUTE_DIRECTORY 0x00000010 | |
294 | #define FILE_ATTRIBUTE_ARCHIVE 0x00000020 | |
295 | #define FILE_ATTRIBUTE_NORMAL 0x00000080 | |
296 | #define FILE_ATTRIBUTE_TEMPORARY 0x00000100 | |
297 | #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 | |
298 | #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 | |
299 | #define FILE_ATTRIBUTE_COMPRESSED 0x00000800 | |
300 | #define FILE_ATTRIBUTE_OFFLINE 0x00001000 | |
301 | #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 | |
302 | #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 | |
303 | ||
304 | /* Oplock levels */ | |
305 | #define SMB2_OPLOCK_LEVEL_NONE 0x00 | |
306 | #define SMB2_OPLOCK_LEVEL_II 0x01 | |
307 | #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08 | |
308 | #define SMB2_OPLOCK_LEVEL_BATCH 0x09 | |
309 | #define SMB2_OPLOCK_LEVEL_LEASE 0xFF | |
310 | ||
311 | /* Desired Access Flags */ | |
312 | #define FILE_READ_DATA_LE cpu_to_le32(0x00000001) | |
313 | #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002) | |
314 | #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004) | |
315 | #define FILE_READ_EA_LE cpu_to_le32(0x00000008) | |
316 | #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010) | |
317 | #define FILE_EXECUTE_LE cpu_to_le32(0x00000020) | |
318 | #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080) | |
319 | #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100) | |
320 | #define FILE_DELETE_LE cpu_to_le32(0x00010000) | |
321 | #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000) | |
322 | #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000) | |
323 | #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000) | |
324 | #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000) | |
325 | #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000) | |
326 | #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000) | |
327 | #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000) | |
328 | #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000) | |
329 | #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000) | |
330 | #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000) | |
331 | ||
332 | /* ShareAccess Flags */ | |
333 | #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001) | |
334 | #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002) | |
335 | #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004) | |
336 | #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007) | |
337 | ||
338 | /* CreateDisposition Flags */ | |
339 | #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000) | |
340 | #define FILE_OPEN_LE cpu_to_le32(0x00000001) | |
341 | #define FILE_CREATE_LE cpu_to_le32(0x00000002) | |
342 | #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003) | |
343 | #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004) | |
344 | #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005) | |
345 | ||
346 | /* CreateOptions Flags */ | |
347 | #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001) | |
348 | /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */ | |
349 | #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002) | |
350 | #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004) | |
351 | #define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008) | |
352 | #define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010) | |
353 | #define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020) | |
354 | #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040) | |
355 | #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100) | |
356 | #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200) | |
357 | #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800) | |
358 | #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000) | |
359 | #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000) | |
360 | #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000) | |
361 | #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000) | |
362 | #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000) | |
363 | #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000) | |
364 | #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000) | |
365 | #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000) | |
366 | ||
367 | #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \ | |
368 | | FILE_READ_ATTRIBUTES_LE) | |
369 | #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \ | |
370 | | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE) | |
371 | #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE) | |
372 | ||
373 | /* Impersonation Levels */ | |
374 | #define IL_ANONYMOUS cpu_to_le32(0x00000000) | |
375 | #define IL_IDENTIFICATION cpu_to_le32(0x00000001) | |
376 | #define IL_IMPERSONATION cpu_to_le32(0x00000002) | |
377 | #define IL_DELEGATE cpu_to_le32(0x00000003) | |
378 | ||
379 | /* Create Context Values */ | |
380 | #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */ | |
381 | #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */ | |
382 | #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ" | |
383 | #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC" | |
384 | #define SMB2_CREATE_ALLOCATION_SIZE "AlSi" | |
385 | #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc" | |
386 | #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp" | |
387 | #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid" | |
388 | #define SMB2_CREATE_REQUEST_LEASE "RqLs" | |
389 | ||
390 | struct smb2_create_req { | |
391 | struct smb2_hdr hdr; | |
392 | __le16 StructureSize; /* Must be 57 */ | |
393 | __u8 SecurityFlags; | |
394 | __u8 RequestedOplockLevel; | |
395 | __le32 ImpersonationLevel; | |
396 | __le64 SmbCreateFlags; | |
397 | __le64 Reserved; | |
398 | __le32 DesiredAccess; | |
399 | __le32 FileAttributes; | |
400 | __le32 ShareAccess; | |
401 | __le32 CreateDisposition; | |
402 | __le32 CreateOptions; | |
403 | __le16 NameOffset; | |
404 | __le16 NameLength; | |
405 | __le32 CreateContextsOffset; | |
406 | __le32 CreateContextsLength; | |
407 | __u8 Buffer[1]; | |
408 | } __packed; | |
409 | ||
410 | struct smb2_create_rsp { | |
411 | struct smb2_hdr hdr; | |
412 | __le16 StructureSize; /* Must be 89 */ | |
413 | __u8 OplockLevel; | |
414 | __u8 Reserved; | |
415 | __le32 CreateAction; | |
416 | __le64 CreationTime; | |
417 | __le64 LastAccessTime; | |
418 | __le64 LastWriteTime; | |
419 | __le64 ChangeTime; | |
420 | __le64 AllocationSize; | |
421 | __le64 EndofFile; | |
422 | __le32 FileAttributes; | |
423 | __le32 Reserved2; | |
424 | __u64 PersistentFileId; /* opaque endianness */ | |
425 | __u64 VolatileFileId; /* opaque endianness */ | |
426 | __le32 CreateContextsOffset; | |
427 | __le32 CreateContextsLength; | |
428 | __u8 Buffer[1]; | |
429 | } __packed; | |
430 | ||
431 | /* Currently defined values for close flags */ | |
432 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) | |
433 | struct smb2_close_req { | |
434 | struct smb2_hdr hdr; | |
435 | __le16 StructureSize; /* Must be 24 */ | |
436 | __le16 Flags; | |
437 | __le32 Reserved; | |
438 | __u64 PersistentFileId; /* opaque endianness */ | |
439 | __u64 VolatileFileId; /* opaque endianness */ | |
440 | } __packed; | |
441 | ||
442 | struct smb2_close_rsp { | |
443 | struct smb2_hdr hdr; | |
444 | __le16 StructureSize; /* 60 */ | |
445 | __le16 Flags; | |
446 | __le32 Reserved; | |
447 | __le64 CreationTime; | |
448 | __le64 LastAccessTime; | |
449 | __le64 LastWriteTime; | |
450 | __le64 ChangeTime; | |
451 | __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */ | |
452 | __le64 EndOfFile; | |
453 | __le32 Attributes; | |
454 | } __packed; | |
455 | ||
7a5cfb19 PS |
456 | struct smb2_flush_req { |
457 | struct smb2_hdr hdr; | |
458 | __le16 StructureSize; /* Must be 24 */ | |
459 | __le16 Reserved1; | |
460 | __le32 Reserved2; | |
461 | __u64 PersistentFileId; /* opaque endianness */ | |
462 | __u64 VolatileFileId; /* opaque endianness */ | |
463 | } __packed; | |
464 | ||
465 | struct smb2_flush_rsp { | |
466 | struct smb2_hdr hdr; | |
467 | __le16 StructureSize; | |
468 | __le16 Reserved; | |
469 | } __packed; | |
470 | ||
09a4707e PS |
471 | struct smb2_read_req { |
472 | struct smb2_hdr hdr; | |
473 | __le16 StructureSize; /* Must be 49 */ | |
474 | __u8 Padding; /* offset from start of SMB2 header to place read */ | |
475 | __u8 Reserved; | |
476 | __le32 Length; | |
477 | __le64 Offset; | |
478 | __u64 PersistentFileId; /* opaque endianness */ | |
479 | __u64 VolatileFileId; /* opaque endianness */ | |
480 | __le32 MinimumCount; | |
481 | __le32 Channel; /* Reserved MBZ */ | |
482 | __le32 RemainingBytes; | |
483 | __le16 ReadChannelInfoOffset; /* Reserved MBZ */ | |
484 | __le16 ReadChannelInfoLength; /* Reserved MBZ */ | |
485 | __u8 Buffer[1]; | |
486 | } __packed; | |
487 | ||
488 | struct smb2_read_rsp { | |
489 | struct smb2_hdr hdr; | |
490 | __le16 StructureSize; /* Must be 17 */ | |
491 | __u8 DataOffset; | |
33319141 PS |
492 | __u8 Reserved; |
493 | __le32 DataLength; | |
494 | __le32 DataRemaining; | |
495 | __u32 Reserved2; | |
496 | __u8 Buffer[1]; | |
497 | } __packed; | |
498 | ||
499 | /* For write request Flags field below the following flag is defined: */ | |
500 | #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 | |
501 | ||
502 | struct smb2_write_req { | |
503 | struct smb2_hdr hdr; | |
504 | __le16 StructureSize; /* Must be 49 */ | |
505 | __le16 DataOffset; /* offset from start of SMB2 header to write data */ | |
506 | __le32 Length; | |
507 | __le64 Offset; | |
508 | __u64 PersistentFileId; /* opaque endianness */ | |
509 | __u64 VolatileFileId; /* opaque endianness */ | |
510 | __le32 Channel; /* Reserved MBZ */ | |
511 | __le32 RemainingBytes; | |
512 | __le16 WriteChannelInfoOffset; /* Reserved MBZ */ | |
513 | __le16 WriteChannelInfoLength; /* Reserved MBZ */ | |
514 | __le32 Flags; | |
515 | __u8 Buffer[1]; | |
516 | } __packed; | |
517 | ||
518 | struct smb2_write_rsp { | |
519 | struct smb2_hdr hdr; | |
520 | __le16 StructureSize; /* Must be 17 */ | |
521 | __u8 DataOffset; | |
09a4707e PS |
522 | __u8 Reserved; |
523 | __le32 DataLength; | |
524 | __le32 DataRemaining; | |
525 | __u32 Reserved2; | |
526 | __u8 Buffer[1]; | |
527 | } __packed; | |
528 | ||
027e8eec PS |
529 | #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001 |
530 | #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002 | |
531 | #define SMB2_LOCKFLAG_UNLOCK 0x0004 | |
532 | #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010 | |
533 | ||
f7ba7fe6 PS |
534 | struct smb2_lock_element { |
535 | __le64 Offset; | |
536 | __le64 Length; | |
537 | __le32 Flags; | |
538 | __le32 Reserved; | |
539 | } __packed; | |
540 | ||
541 | struct smb2_lock_req { | |
542 | struct smb2_hdr hdr; | |
543 | __le16 StructureSize; /* Must be 48 */ | |
544 | __le16 LockCount; | |
545 | __le32 Reserved; | |
546 | __u64 PersistentFileId; /* opaque endianness */ | |
547 | __u64 VolatileFileId; /* opaque endianness */ | |
548 | /* Followed by at least one */ | |
549 | struct smb2_lock_element locks[1]; | |
550 | } __packed; | |
551 | ||
552 | struct smb2_lock_rsp { | |
553 | struct smb2_hdr hdr; | |
554 | __le16 StructureSize; /* Must be 4 */ | |
555 | __le16 Reserved; | |
556 | } __packed; | |
557 | ||
9094fad1 PS |
558 | struct smb2_echo_req { |
559 | struct smb2_hdr hdr; | |
560 | __le16 StructureSize; /* Must be 4 */ | |
561 | __u16 Reserved; | |
562 | } __packed; | |
563 | ||
564 | struct smb2_echo_rsp { | |
565 | struct smb2_hdr hdr; | |
566 | __le16 StructureSize; /* Must be 4 */ | |
567 | __u16 Reserved; | |
568 | } __packed; | |
569 | ||
d324f08d PS |
570 | /* search (query_directory) Flags field */ |
571 | #define SMB2_RESTART_SCANS 0x01 | |
572 | #define SMB2_RETURN_SINGLE_ENTRY 0x02 | |
573 | #define SMB2_INDEX_SPECIFIED 0x04 | |
574 | #define SMB2_REOPEN 0x10 | |
575 | ||
576 | struct smb2_query_directory_req { | |
577 | struct smb2_hdr hdr; | |
578 | __le16 StructureSize; /* Must be 33 */ | |
579 | __u8 FileInformationClass; | |
580 | __u8 Flags; | |
581 | __le32 FileIndex; | |
582 | __u64 PersistentFileId; /* opaque endianness */ | |
583 | __u64 VolatileFileId; /* opaque endianness */ | |
584 | __le16 FileNameOffset; | |
585 | __le16 FileNameLength; | |
586 | __le32 OutputBufferLength; | |
587 | __u8 Buffer[1]; | |
588 | } __packed; | |
589 | ||
590 | struct smb2_query_directory_rsp { | |
591 | struct smb2_hdr hdr; | |
592 | __le16 StructureSize; /* Must be 9 */ | |
593 | __le16 OutputBufferOffset; | |
594 | __le32 OutputBufferLength; | |
595 | __u8 Buffer[1]; | |
596 | } __packed; | |
597 | ||
be4cb9e3 PS |
598 | /* Possible InfoType values */ |
599 | #define SMB2_O_INFO_FILE 0x01 | |
600 | #define SMB2_O_INFO_FILESYSTEM 0x02 | |
601 | #define SMB2_O_INFO_SECURITY 0x03 | |
602 | #define SMB2_O_INFO_QUOTA 0x04 | |
603 | ||
604 | struct smb2_query_info_req { | |
605 | struct smb2_hdr hdr; | |
606 | __le16 StructureSize; /* Must be 41 */ | |
607 | __u8 InfoType; | |
608 | __u8 FileInfoClass; | |
609 | __le32 OutputBufferLength; | |
610 | __le16 InputBufferOffset; | |
611 | __u16 Reserved; | |
612 | __le32 InputBufferLength; | |
613 | __le32 AdditionalInformation; | |
614 | __le32 Flags; | |
615 | __u64 PersistentFileId; /* opaque endianness */ | |
616 | __u64 VolatileFileId; /* opaque endianness */ | |
617 | __u8 Buffer[1]; | |
618 | } __packed; | |
619 | ||
620 | struct smb2_query_info_rsp { | |
621 | struct smb2_hdr hdr; | |
622 | __le16 StructureSize; /* Must be 9 */ | |
623 | __le16 OutputBufferOffset; | |
624 | __le32 OutputBufferLength; | |
625 | __u8 Buffer[1]; | |
626 | } __packed; | |
627 | ||
35143eb5 PS |
628 | struct smb2_set_info_req { |
629 | struct smb2_hdr hdr; | |
630 | __le16 StructureSize; /* Must be 33 */ | |
631 | __u8 InfoType; | |
632 | __u8 FileInfoClass; | |
633 | __le32 BufferLength; | |
634 | __le16 BufferOffset; | |
635 | __u16 Reserved; | |
636 | __le32 AdditionalInformation; | |
637 | __u64 PersistentFileId; /* opaque endianness */ | |
638 | __u64 VolatileFileId; /* opaque endianness */ | |
639 | __u8 Buffer[1]; | |
640 | } __packed; | |
641 | ||
642 | struct smb2_set_info_rsp { | |
643 | struct smb2_hdr hdr; | |
644 | __le16 StructureSize; /* Must be 2 */ | |
645 | } __packed; | |
646 | ||
983c88a4 PS |
647 | struct smb2_oplock_break { |
648 | struct smb2_hdr hdr; | |
649 | __le16 StructureSize; /* Must be 24 */ | |
650 | __u8 OplockLevel; | |
651 | __u8 Reserved; | |
652 | __le32 Reserved2; | |
653 | __u64 PersistentFid; | |
654 | __u64 VolatileFid; | |
655 | } __packed; | |
656 | ||
be4cb9e3 PS |
657 | /* |
658 | * PDU infolevel structure definitions | |
659 | * BB consider moving to a different header | |
660 | */ | |
661 | ||
6fc05c25 PS |
662 | /* File System Information Classes */ |
663 | #define FS_VOLUME_INFORMATION 1 /* Query */ | |
664 | #define FS_LABEL_INFORMATION 2 /* Set */ | |
665 | #define FS_SIZE_INFORMATION 3 /* Query */ | |
666 | #define FS_DEVICE_INFORMATION 4 /* Query */ | |
667 | #define FS_ATTRIBUTE_INFORMATION 5 /* Query */ | |
668 | #define FS_CONTROL_INFORMATION 6 /* Query, Set */ | |
669 | #define FS_FULL_SIZE_INFORMATION 7 /* Query */ | |
670 | #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */ | |
671 | #define FS_DRIVER_PATH_INFORMATION 9 /* Query */ | |
672 | ||
673 | struct smb2_fs_full_size_info { | |
674 | __le64 TotalAllocationUnits; | |
675 | __le64 CallerAvailableAllocationUnits; | |
676 | __le64 ActualAvailableAllocationUnits; | |
677 | __le32 SectorsPerAllocationUnit; | |
678 | __le32 BytesPerSector; | |
679 | } __packed; | |
680 | ||
be4cb9e3 PS |
681 | /* partial list of QUERY INFO levels */ |
682 | #define FILE_DIRECTORY_INFORMATION 1 | |
683 | #define FILE_FULL_DIRECTORY_INFORMATION 2 | |
684 | #define FILE_BOTH_DIRECTORY_INFORMATION 3 | |
685 | #define FILE_BASIC_INFORMATION 4 | |
686 | #define FILE_STANDARD_INFORMATION 5 | |
687 | #define FILE_INTERNAL_INFORMATION 6 | |
688 | #define FILE_EA_INFORMATION 7 | |
689 | #define FILE_ACCESS_INFORMATION 8 | |
690 | #define FILE_NAME_INFORMATION 9 | |
691 | #define FILE_RENAME_INFORMATION 10 | |
692 | #define FILE_LINK_INFORMATION 11 | |
693 | #define FILE_NAMES_INFORMATION 12 | |
694 | #define FILE_DISPOSITION_INFORMATION 13 | |
695 | #define FILE_POSITION_INFORMATION 14 | |
696 | #define FILE_FULL_EA_INFORMATION 15 | |
697 | #define FILE_MODE_INFORMATION 16 | |
698 | #define FILE_ALIGNMENT_INFORMATION 17 | |
699 | #define FILE_ALL_INFORMATION 18 | |
700 | #define FILE_ALLOCATION_INFORMATION 19 | |
701 | #define FILE_END_OF_FILE_INFORMATION 20 | |
702 | #define FILE_ALTERNATE_NAME_INFORMATION 21 | |
703 | #define FILE_STREAM_INFORMATION 22 | |
704 | #define FILE_PIPE_INFORMATION 23 | |
705 | #define FILE_PIPE_LOCAL_INFORMATION 24 | |
706 | #define FILE_PIPE_REMOTE_INFORMATION 25 | |
707 | #define FILE_MAILSLOT_QUERY_INFORMATION 26 | |
708 | #define FILE_MAILSLOT_SET_INFORMATION 27 | |
709 | #define FILE_COMPRESSION_INFORMATION 28 | |
710 | #define FILE_OBJECT_ID_INFORMATION 29 | |
711 | /* Number 30 not defined in documents */ | |
712 | #define FILE_MOVE_CLUSTER_INFORMATION 31 | |
713 | #define FILE_QUOTA_INFORMATION 32 | |
714 | #define FILE_REPARSE_POINT_INFORMATION 33 | |
715 | #define FILE_NETWORK_OPEN_INFORMATION 34 | |
716 | #define FILE_ATTRIBUTE_TAG_INFORMATION 35 | |
717 | #define FILE_TRACKING_INFORMATION 36 | |
718 | #define FILEID_BOTH_DIRECTORY_INFORMATION 37 | |
719 | #define FILEID_FULL_DIRECTORY_INFORMATION 38 | |
720 | #define FILE_VALID_DATA_LENGTH_INFORMATION 39 | |
721 | #define FILE_SHORT_NAME_INFORMATION 40 | |
722 | #define FILE_SFIO_RESERVE_INFORMATION 44 | |
723 | #define FILE_SFIO_VOLUME_INFORMATION 45 | |
724 | #define FILE_HARD_LINK_INFORMATION 46 | |
725 | #define FILE_NORMALIZED_NAME_INFORMATION 48 | |
726 | #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50 | |
727 | #define FILE_STANDARD_LINK_INFORMATION 54 | |
728 | ||
f0df737e PS |
729 | struct smb2_file_internal_info { |
730 | __le64 IndexNumber; | |
731 | } __packed; /* level 6 Query */ | |
732 | ||
35143eb5 PS |
733 | struct smb2_file_rename_info { /* encoding of request for level 10 */ |
734 | __u8 ReplaceIfExists; /* 1 = replace existing target with new */ | |
735 | /* 0 = fail if target already exists */ | |
736 | __u8 Reserved[7]; | |
737 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ | |
738 | __le32 FileNameLength; | |
739 | char FileName[0]; /* New name to be assigned */ | |
740 | } __packed; /* level 10 Set */ | |
741 | ||
568798cc PS |
742 | struct smb2_file_link_info { /* encoding of request for level 11 */ |
743 | __u8 ReplaceIfExists; /* 1 = replace existing link with new */ | |
744 | /* 0 = fail if link already exists */ | |
745 | __u8 Reserved[7]; | |
746 | __u64 RootDirectory; /* MBZ for network operations (why says spec?) */ | |
747 | __le32 FileNameLength; | |
748 | char FileName[0]; /* Name to be assigned to new link */ | |
749 | } __packed; /* level 11 Set */ | |
750 | ||
be4cb9e3 PS |
751 | /* |
752 | * This level 18, although with struct with same name is different from cifs | |
753 | * level 0x107. Level 0x107 has an extra u64 between AccessFlags and | |
754 | * CurrentByteOffset. | |
755 | */ | |
756 | struct smb2_file_all_info { /* data block encoding of response to level 18 */ | |
757 | __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */ | |
758 | __le64 LastAccessTime; | |
759 | __le64 LastWriteTime; | |
760 | __le64 ChangeTime; | |
761 | __le32 Attributes; | |
762 | __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */ | |
763 | __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */ | |
764 | __le64 EndOfFile; /* size ie offset to first free byte in file */ | |
765 | __le32 NumberOfLinks; /* hard links */ | |
766 | __u8 DeletePending; | |
767 | __u8 Directory; | |
768 | __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */ | |
769 | __le64 IndexNumber; | |
770 | __le32 EASize; | |
771 | __le32 AccessFlags; | |
772 | __le64 CurrentByteOffset; | |
773 | __le32 Mode; | |
774 | __le32 AlignmentRequirement; | |
775 | __le32 FileNameLength; | |
776 | char FileName[1]; | |
777 | } __packed; /* level 18 Query */ | |
778 | ||
c839ff24 PS |
779 | struct smb2_file_eof_info { /* encoding of request for level 10 */ |
780 | __le64 EndOfFile; /* new end of file value */ | |
781 | } __packed; /* level 20 Set */ | |
782 | ||
ddfbefbd | 783 | #endif /* _SMB2PDU_H */ |