CIFS: Add capability to send SMB2 negotiate message
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / cifs / smb2pdu.h
CommitLineData
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
90#define SMB2_HEADER_SIZE __constant_le16_to_cpu(64)
91
92#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_le16_to_cpu(9)
93
ddfbefbd
SF
94/*
95 * SMB2 Header Definition
96 *
97 * "MBZ" : Must be Zero
98 * "BB" : BugBug, Something to check/review/analyze later
99 * "PDU" : "Protocol Data Unit" (ie a network "frame")
100 *
101 */
102struct smb2_hdr {
103 __be32 smb2_buf_length; /* big endian on wire */
104 /* length is only two or three bytes - with
105 one or two byte type preceding it that MBZ */
106 __u8 ProtocolId[4]; /* 0xFE 'S' 'M' 'B' */
107 __le16 StructureSize; /* 64 */
108 __le16 CreditCharge; /* MBZ */
109 __le32 Status; /* Error from server */
110 __le16 Command;
111 __le16 CreditRequest; /* CreditResponse */
112 __le32 Flags;
113 __le32 NextCommand;
114 __u64 MessageId; /* opaque - so can stay little endian */
115 __le32 ProcessId;
116 __u32 TreeId; /* opaque - so do not make little endian */
117 __u64 SessionId; /* opaque - so do not make little endian */
118 __u8 Signature[16];
119} __packed;
120
093b2bda
PS
121struct smb2_pdu {
122 struct smb2_hdr hdr;
123 __le16 StructureSize2; /* size of wct area (varies, request specific) */
124} __packed;
125
126/*
127 * SMB2 flag definitions
128 */
129#define SMB2_FLAGS_SERVER_TO_REDIR __constant_cpu_to_le32(0x00000001)
130#define SMB2_FLAGS_ASYNC_COMMAND __constant_cpu_to_le32(0x00000002)
131#define SMB2_FLAGS_RELATED_OPERATIONS __constant_cpu_to_le32(0x00000004)
132#define SMB2_FLAGS_SIGNED __constant_cpu_to_le32(0x00000008)
133#define SMB2_FLAGS_DFS_OPERATIONS __constant_cpu_to_le32(0x10000000)
134
135/*
136 * Definitions for SMB2 Protocol Data Units (network frames)
137 *
138 * See MS-SMB2.PDF specification for protocol details.
139 * The Naming convention is the lower case version of the SMB2
140 * command code name for the struct. Note that structures must be packed.
141 *
142 */
143struct smb2_err_rsp {
144 struct smb2_hdr hdr;
145 __le16 StructureSize;
146 __le16 Reserved; /* MBZ */
147 __le32 ByteCount; /* even if zero, at least one byte follows */
148 __u8 ErrorData[1]; /* variable length */
149} __packed;
150
ec2e4523
PS
151struct smb2_negotiate_req {
152 struct smb2_hdr hdr;
153 __le16 StructureSize; /* Must be 36 */
154 __le16 DialectCount;
155 __le16 SecurityMode;
156 __le16 Reserved; /* MBZ */
157 __le32 Capabilities;
158 __u8 ClientGUID[16]; /* MBZ */
159 __le64 ClientStartTime; /* MBZ */
160 __le16 Dialects[2]; /* variable length */
161} __packed;
162
163/* SecurityMode flags */
164#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
165#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
166/* Capabilities flags */
167#define SMB2_GLOBAL_CAP_DFS 0x00000001
168#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
169#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
170
171struct smb2_negotiate_rsp {
172 struct smb2_hdr hdr;
173 __le16 StructureSize; /* Must be 65 */
174 __le16 SecurityMode;
175 __le16 DialectRevision;
176 __le16 Reserved; /* MBZ */
177 __u8 ServerGUID[16];
178 __le32 Capabilities;
179 __le32 MaxTransactSize;
180 __le32 MaxReadSize;
181 __le32 MaxWriteSize;
182 __le64 SystemTime; /* MBZ */
183 __le64 ServerStartTime;
184 __le16 SecurityBufferOffset;
185 __le16 SecurityBufferLength;
186 __le32 Reserved2; /* may be any value, ignore */
187 __u8 Buffer[1]; /* variable length GSS security buffer */
188} __packed;
189
ddfbefbd 190#endif /* _SMB2PDU_H */