Steve French | ddfbefb | 2011-03-15 02:08:48 +0000 | [diff] [blame] | 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 | |
| 29 | /* |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 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 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 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 | |
Pavel Shilovsky | 2dc7e1c | 2011-12-26 22:53:34 +0400 | [diff] [blame] | 94 | /* |
Steve French | ddfbefb | 2011-03-15 02:08:48 +0000 | [diff] [blame] | 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 | */ |
| 102 | struct 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 | |
Pavel Shilovsky | 093b2bd | 2011-06-08 15:51:07 +0400 | [diff] [blame] | 121 | struct 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 | */ |
| 143 | struct 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 | |
Pavel Shilovsky | ec2e452 | 2011-12-27 16:12:43 +0400 | [diff] [blame] | 151 | struct 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 | |
| 171 | struct 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 | |
Pavel Shilovsky | 5478f9b | 2011-12-27 16:22:00 +0400 | [diff] [blame^] | 190 | struct smb2_sess_setup_req { |
| 191 | struct smb2_hdr hdr; |
| 192 | __le16 StructureSize; /* Must be 25 */ |
| 193 | __u8 VcNumber; |
| 194 | __u8 SecurityMode; |
| 195 | __le32 Capabilities; |
| 196 | __le32 Channel; |
| 197 | __le16 SecurityBufferOffset; |
| 198 | __le16 SecurityBufferLength; |
| 199 | __le64 PreviousSessionId; |
| 200 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 201 | } __packed; |
| 202 | |
| 203 | /* Currently defined SessionFlags */ |
| 204 | #define SMB2_SESSION_FLAG_IS_GUEST 0x0001 |
| 205 | #define SMB2_SESSION_FLAG_IS_NULL 0x0002 |
| 206 | struct smb2_sess_setup_rsp { |
| 207 | struct smb2_hdr hdr; |
| 208 | __le16 StructureSize; /* Must be 9 */ |
| 209 | __le16 SessionFlags; |
| 210 | __le16 SecurityBufferOffset; |
| 211 | __le16 SecurityBufferLength; |
| 212 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 213 | } __packed; |
| 214 | |
| 215 | struct smb2_logoff_req { |
| 216 | struct smb2_hdr hdr; |
| 217 | __le16 StructureSize; /* Must be 4 */ |
| 218 | __le16 Reserved; |
| 219 | } __packed; |
| 220 | |
| 221 | struct smb2_logoff_rsp { |
| 222 | struct smb2_hdr hdr; |
| 223 | __le16 StructureSize; /* Must be 4 */ |
| 224 | __le16 Reserved; |
| 225 | } __packed; |
| 226 | |
Steve French | ddfbefb | 2011-03-15 02:08:48 +0000 | [diff] [blame] | 227 | #endif /* _SMB2PDU_H */ |