Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 1 | /* SPDX-License-Identifier: LGPL-2.1 */ |
| 2 | #ifndef _COMMON_SMB2PDU_H |
| 3 | #define _COMMON_SMB2PDU_H |
| 4 | |
| 5 | /* |
| 6 | * Note that, due to trying to use names similar to the protocol specifications, |
| 7 | * there are many mixed case field names in the structures below. Although |
| 8 | * this does not match typical Linux kernel style, it is necessary to be |
| 9 | * able to match against the protocol specfication. |
| 10 | * |
| 11 | * SMB2 commands |
| 12 | * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses |
| 13 | * (ie no useful data other than the SMB error code itself) and are marked such. |
| 14 | * Knowing this helps avoid response buffer allocations and copy in some cases. |
| 15 | */ |
| 16 | |
| 17 | /* List of commands in host endian */ |
| 18 | #define SMB2_NEGOTIATE_HE 0x0000 |
| 19 | #define SMB2_SESSION_SETUP_HE 0x0001 |
| 20 | #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */ |
| 21 | #define SMB2_TREE_CONNECT_HE 0x0003 |
| 22 | #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */ |
| 23 | #define SMB2_CREATE_HE 0x0005 |
| 24 | #define SMB2_CLOSE_HE 0x0006 |
| 25 | #define SMB2_FLUSH_HE 0x0007 /* trivial resp */ |
| 26 | #define SMB2_READ_HE 0x0008 |
| 27 | #define SMB2_WRITE_HE 0x0009 |
| 28 | #define SMB2_LOCK_HE 0x000A |
| 29 | #define SMB2_IOCTL_HE 0x000B |
| 30 | #define SMB2_CANCEL_HE 0x000C |
| 31 | #define SMB2_ECHO_HE 0x000D |
| 32 | #define SMB2_QUERY_DIRECTORY_HE 0x000E |
| 33 | #define SMB2_CHANGE_NOTIFY_HE 0x000F |
| 34 | #define SMB2_QUERY_INFO_HE 0x0010 |
| 35 | #define SMB2_SET_INFO_HE 0x0011 |
| 36 | #define SMB2_OPLOCK_BREAK_HE 0x0012 |
| 37 | |
| 38 | /* The same list in little endian */ |
| 39 | #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE) |
| 40 | #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE) |
| 41 | #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE) |
| 42 | #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE) |
| 43 | #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE) |
| 44 | #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE) |
| 45 | #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE) |
| 46 | #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE) |
| 47 | #define SMB2_READ cpu_to_le16(SMB2_READ_HE) |
| 48 | #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE) |
| 49 | #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE) |
| 50 | #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE) |
| 51 | #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE) |
| 52 | #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE) |
| 53 | #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE) |
| 54 | #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE) |
| 55 | #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE) |
| 56 | #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE) |
| 57 | #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE) |
| 58 | |
| 59 | #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF) |
| 60 | |
| 61 | #define NUMBER_OF_SMB2_COMMANDS 0x0013 |
| 62 | |
| 63 | /* |
| 64 | * SMB2 Header Definition |
| 65 | * |
| 66 | * "MBZ" : Must be Zero |
| 67 | * "BB" : BugBug, Something to check/review/analyze later |
| 68 | * "PDU" : "Protocol Data Unit" (ie a network "frame") |
| 69 | * |
| 70 | */ |
| 71 | |
| 72 | #define __SMB2_HEADER_STRUCTURE_SIZE 64 |
| 73 | #define SMB2_HEADER_STRUCTURE_SIZE \ |
| 74 | cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE) |
| 75 | |
| 76 | #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe) |
| 77 | #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd) |
| 78 | #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc) |
| 79 | |
| 80 | /* |
| 81 | * SMB2 flag definitions |
| 82 | */ |
| 83 | #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001) |
| 84 | #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002) |
| 85 | #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004) |
| 86 | #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008) |
| 87 | #define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */ |
| 88 | #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000) |
| 89 | #define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */ |
| 90 | |
| 91 | /* See MS-SMB2 section 2.2.1 */ |
| 92 | struct smb2_hdr { |
| 93 | __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */ |
| 94 | __le16 StructureSize; /* 64 */ |
| 95 | __le16 CreditCharge; /* MBZ */ |
| 96 | __le32 Status; /* Error from server */ |
| 97 | __le16 Command; |
| 98 | __le16 CreditRequest; /* CreditResponse */ |
| 99 | __le32 Flags; |
| 100 | __le32 NextCommand; |
| 101 | __le64 MessageId; |
| 102 | union { |
| 103 | struct { |
| 104 | __le32 ProcessId; |
| 105 | __le32 TreeId; |
| 106 | } __packed SyncId; |
| 107 | __le64 AsyncId; |
| 108 | } __packed Id; |
| 109 | __le64 SessionId; |
| 110 | __u8 Signature[16]; |
| 111 | } __packed; |
| 112 | |
| 113 | struct smb2_pdu { |
| 114 | struct smb2_hdr hdr; |
| 115 | __le16 StructureSize2; /* size of wct area (varies, request specific) */ |
| 116 | } __packed; |
| 117 | |
| 118 | #define SMB3_AES_CCM_NONCE 11 |
| 119 | #define SMB3_AES_GCM_NONCE 12 |
| 120 | |
| 121 | /* Transform flags (for 3.0 dialect this flag indicates CCM */ |
| 122 | #define TRANSFORM_FLAG_ENCRYPTED 0x0001 |
| 123 | struct smb2_transform_hdr { |
| 124 | __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */ |
| 125 | __u8 Signature[16]; |
| 126 | __u8 Nonce[16]; |
| 127 | __le32 OriginalMessageSize; |
| 128 | __u16 Reserved1; |
| 129 | __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */ |
| 130 | __le64 SessionId; |
| 131 | } __packed; |
| 132 | |
| 133 | |
| 134 | /* See MS-SMB2 2.2.42 */ |
| 135 | struct smb2_compression_transform_hdr_unchained { |
| 136 | __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */ |
| 137 | __le32 OriginalCompressedSegmentSize; |
| 138 | __le16 CompressionAlgorithm; |
| 139 | __le16 Flags; |
| 140 | __le16 Length; /* if chained it is length, else offset */ |
| 141 | } __packed; |
| 142 | |
| 143 | /* See MS-SMB2 2.2.42.1 */ |
| 144 | #define SMB2_COMPRESSION_FLAG_NONE 0x0000 |
| 145 | #define SMB2_COMPRESSION_FLAG_CHAINED 0x0001 |
| 146 | |
| 147 | struct compression_payload_header { |
| 148 | __le16 CompressionAlgorithm; |
| 149 | __le16 Flags; |
| 150 | __le32 Length; /* length of compressed playload including field below if present */ |
| 151 | /* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */ |
| 152 | } __packed; |
| 153 | |
| 154 | /* See MS-SMB2 2.2.42.2 */ |
| 155 | struct smb2_compression_transform_hdr_chained { |
| 156 | __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */ |
| 157 | __le32 OriginalCompressedSegmentSize; |
| 158 | /* struct compression_payload_header[] */ |
| 159 | } __packed; |
| 160 | |
| 161 | /* See MS-SMB2 2.2.42.2.2 */ |
| 162 | struct compression_pattern_payload_v1 { |
| 163 | __le16 Pattern; |
| 164 | __le16 Reserved1; |
| 165 | __le16 Reserved2; |
| 166 | __le32 Repetitions; |
| 167 | } __packed; |
| 168 | |
| 169 | /* See MS-SMB2 section 2.2.9.2 */ |
| 170 | /* Context Types */ |
| 171 | #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000 |
| 172 | #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001) |
| 173 | |
| 174 | struct tree_connect_contexts { |
| 175 | __le16 ContextType; |
| 176 | __le16 DataLength; |
| 177 | __le32 Reserved; |
| 178 | __u8 Data[]; |
| 179 | } __packed; |
| 180 | |
| 181 | /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */ |
| 182 | struct smb3_blob_data { |
| 183 | __le16 BlobSize; |
| 184 | __u8 BlobData[]; |
| 185 | } __packed; |
| 186 | |
| 187 | /* Valid values for Attr */ |
| 188 | #define SE_GROUP_MANDATORY 0x00000001 |
| 189 | #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002 |
| 190 | #define SE_GROUP_ENABLED 0x00000004 |
| 191 | #define SE_GROUP_OWNER 0x00000008 |
| 192 | #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010 |
| 193 | #define SE_GROUP_INTEGRITY 0x00000020 |
| 194 | #define SE_GROUP_INTEGRITY_ENABLED 0x00000040 |
| 195 | #define SE_GROUP_RESOURCE 0x20000000 |
| 196 | #define SE_GROUP_LOGON_ID 0xC0000000 |
| 197 | |
| 198 | /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */ |
| 199 | |
| 200 | struct sid_array_data { |
| 201 | __le16 SidAttrCount; |
| 202 | /* SidAttrList - array of sid_attr_data structs */ |
| 203 | } __packed; |
| 204 | |
| 205 | struct luid_attr_data { |
| 206 | |
| 207 | } __packed; |
| 208 | |
| 209 | /* |
| 210 | * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5 |
| 211 | * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA |
| 212 | */ |
| 213 | |
| 214 | struct privilege_array_data { |
| 215 | __le16 PrivilegeCount; |
| 216 | /* array of privilege_data structs */ |
| 217 | } __packed; |
| 218 | |
| 219 | struct remoted_identity_tcon_context { |
| 220 | __le16 TicketType; /* must be 0x0001 */ |
| 221 | __le16 TicketSize; /* total size of this struct */ |
| 222 | __le16 User; /* offset to SID_ATTR_DATA struct with user info */ |
| 223 | __le16 UserName; /* offset to null terminated Unicode username string */ |
| 224 | __le16 Domain; /* offset to null terminated Unicode domain name */ |
| 225 | __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */ |
| 226 | __le16 RestrictedGroups; /* similar to above */ |
| 227 | __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */ |
| 228 | __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */ |
| 229 | __le16 Owner; /* offset to BLOB_DATA struct */ |
| 230 | __le16 DefaultDacl; /* offset to BLOB_DATA struct */ |
| 231 | __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */ |
| 232 | __le16 UserClaims; /* offset to BLOB_DATA struct */ |
| 233 | __le16 DeviceClaims; /* offset to BLOB_DATA struct */ |
| 234 | __u8 TicketInfo[]; /* variable length buf - remoted identity data */ |
| 235 | } __packed; |
| 236 | |
| 237 | struct smb2_tree_connect_req_extension { |
| 238 | __le32 TreeConnectContextOffset; |
| 239 | __le16 TreeConnectContextCount; |
| 240 | __u8 Reserved[10]; |
| 241 | __u8 PathName[]; /* variable sized array */ |
| 242 | /* followed by array of TreeConnectContexts */ |
| 243 | } __packed; |
| 244 | |
| 245 | /* Flags/Reserved for SMB3.1.1 */ |
| 246 | #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001) |
| 247 | #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002) |
| 248 | #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004) |
| 249 | |
| 250 | struct smb2_tree_connect_req { |
| 251 | struct smb2_hdr hdr; |
| 252 | __le16 StructureSize; /* Must be 9 */ |
| 253 | __le16 Flags; /* Flags in SMB3.1.1 */ |
| 254 | __le16 PathOffset; |
| 255 | __le16 PathLength; |
| 256 | __u8 Buffer[1]; /* variable length */ |
| 257 | } __packed; |
| 258 | |
| 259 | /* Possible ShareType values */ |
| 260 | #define SMB2_SHARE_TYPE_DISK 0x01 |
| 261 | #define SMB2_SHARE_TYPE_PIPE 0x02 |
| 262 | #define SMB2_SHARE_TYPE_PRINT 0x03 |
| 263 | |
| 264 | /* |
| 265 | * Possible ShareFlags - exactly one and only one of the first 4 caching flags |
| 266 | * must be set (any of the remaining, SHI1005, flags may be set individually |
| 267 | * or in combination. |
| 268 | */ |
| 269 | #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000 |
| 270 | #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010 |
| 271 | #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020 |
| 272 | #define SMB2_SHAREFLAG_NO_CACHING 0x00000030 |
| 273 | #define SHI1005_FLAGS_DFS 0x00000001 |
| 274 | #define SHI1005_FLAGS_DFS_ROOT 0x00000002 |
| 275 | #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100 |
| 276 | #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200 |
| 277 | #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400 |
| 278 | #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800 |
| 279 | #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000 |
| 280 | #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000 |
| 281 | #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000 |
| 282 | #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000 |
| 283 | #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */ |
| 284 | #define SMB2_SHAREFLAG_COMPRESS_DATA 0x00100000 /* 3.1.1 */ |
| 285 | #define SHI1005_FLAGS_ALL 0x0014FF33 |
| 286 | |
| 287 | /* Possible share capabilities */ |
| 288 | #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */ |
| 289 | #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */ |
| 290 | #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */ |
| 291 | #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */ |
| 292 | #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */ |
| 293 | #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */ |
| 294 | |
| 295 | struct smb2_tree_connect_rsp { |
| 296 | struct smb2_hdr hdr; |
| 297 | __le16 StructureSize; /* Must be 16 */ |
| 298 | __u8 ShareType; /* see below */ |
| 299 | __u8 Reserved; |
| 300 | __le32 ShareFlags; /* see below */ |
| 301 | __le32 Capabilities; /* see below */ |
| 302 | __le32 MaximalAccess; |
| 303 | } __packed; |
| 304 | |
| 305 | struct smb2_tree_disconnect_req { |
| 306 | struct smb2_hdr hdr; |
| 307 | __le16 StructureSize; /* Must be 4 */ |
| 308 | __le16 Reserved; |
| 309 | } __packed; |
| 310 | |
| 311 | struct smb2_tree_disconnect_rsp { |
| 312 | struct smb2_hdr hdr; |
| 313 | __le16 StructureSize; /* Must be 4 */ |
| 314 | __le16 Reserved; |
| 315 | } __packed; |
| 316 | |
| 317 | |
Ronnie Sahlberg | fc0b384 | 2021-09-08 12:10:13 +1000 | [diff] [blame] | 318 | /* |
| 319 | * SMB2_NEGOTIATE_PROTOCOL See MS-SMB2 section 2.2.3 |
| 320 | */ |
| 321 | /* SecurityMode flags */ |
| 322 | #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001 |
| 323 | #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001) |
| 324 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002 |
| 325 | #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002) |
| 326 | #define SMB2_SEC_MODE_FLAGS_ALL 0x0003 |
| 327 | |
| 328 | /* Capabilities flags */ |
| 329 | #define SMB2_GLOBAL_CAP_DFS 0x00000001 |
| 330 | #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */ |
| 331 | #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */ |
| 332 | #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */ |
| 333 | #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */ |
| 334 | #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */ |
| 335 | #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */ |
| 336 | /* Internal types */ |
| 337 | #define SMB2_NT_FIND 0x00100000 |
| 338 | #define SMB2_LARGE_FILES 0x00200000 |
| 339 | |
| 340 | #define SMB2_CLIENT_GUID_SIZE 16 |
| 341 | #define SMB2_CREATE_GUID_SIZE 16 |
| 342 | |
| 343 | /* Dialects */ |
| 344 | #define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */ |
| 345 | #define SMB20_PROT_ID 0x0202 |
| 346 | #define SMB21_PROT_ID 0x0210 |
| 347 | #define SMB2X_PROT_ID 0x02FF |
| 348 | #define SMB30_PROT_ID 0x0300 |
| 349 | #define SMB302_PROT_ID 0x0302 |
| 350 | #define SMB311_PROT_ID 0x0311 |
| 351 | #define BAD_PROT_ID 0xFFFF |
| 352 | |
| 353 | #define SMB311_SALT_SIZE 32 |
| 354 | /* Hash Algorithm Types */ |
| 355 | #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001) |
| 356 | #define SMB2_PREAUTH_HASH_SIZE 64 |
| 357 | |
| 358 | /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */ |
| 359 | #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1) |
| 360 | #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2) |
| 361 | #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3) |
| 362 | #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5) |
| 363 | #define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6) |
| 364 | #define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7) |
| 365 | #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8) |
| 366 | #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100) |
| 367 | |
| 368 | struct smb2_neg_context { |
| 369 | __le16 ContextType; |
| 370 | __le16 DataLength; |
| 371 | __le32 Reserved; |
| 372 | /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */ |
| 373 | } __packed; |
| 374 | |
| 375 | /* |
| 376 | * SaltLength that the server send can be zero, so the only three required |
| 377 | * fields (all __le16) end up six bytes total, so the minimum context data len |
| 378 | * in the response is six bytes which accounts for |
| 379 | * |
| 380 | * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm. |
| 381 | */ |
| 382 | #define MIN_PREAUTH_CTXT_DATA_LEN 6 |
| 383 | |
| 384 | struct smb2_preauth_neg_context { |
| 385 | __le16 ContextType; /* 1 */ |
| 386 | __le16 DataLength; |
| 387 | __le32 Reserved; |
| 388 | __le16 HashAlgorithmCount; /* 1 */ |
| 389 | __le16 SaltLength; |
| 390 | __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */ |
| 391 | __u8 Salt[SMB311_SALT_SIZE]; |
| 392 | } __packed; |
| 393 | |
| 394 | /* Encryption Algorithms Ciphers */ |
| 395 | #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001) |
| 396 | #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002) |
| 397 | #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003) |
| 398 | #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004) |
| 399 | |
| 400 | /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */ |
| 401 | #define MIN_ENCRYPT_CTXT_DATA_LEN 4 |
| 402 | struct smb2_encryption_neg_context { |
| 403 | __le16 ContextType; /* 2 */ |
| 404 | __le16 DataLength; |
| 405 | __le32 Reserved; |
| 406 | /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */ |
| 407 | __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */ |
| 408 | __le16 Ciphers[]; |
| 409 | } __packed; |
| 410 | |
| 411 | /* See MS-SMB2 2.2.3.1.3 */ |
| 412 | #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000) |
| 413 | #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001) |
| 414 | #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002) |
| 415 | #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003) |
| 416 | /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */ |
| 417 | #define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */ |
| 418 | |
| 419 | /* Compression Flags */ |
| 420 | #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000) |
| 421 | #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001) |
| 422 | |
| 423 | struct smb2_compression_capabilities_context { |
| 424 | __le16 ContextType; /* 3 */ |
| 425 | __le16 DataLength; |
| 426 | __le32 Reserved; |
| 427 | __le16 CompressionAlgorithmCount; |
| 428 | __le16 Padding; |
| 429 | __le32 Flags; |
| 430 | __le16 CompressionAlgorithms[3]; |
| 431 | __u16 Pad; /* Some servers require pad to DataLen multiple of 8 */ |
| 432 | /* Check if pad needed */ |
| 433 | } __packed; |
| 434 | |
| 435 | /* |
| 436 | * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4. |
| 437 | * Its struct simply contains NetName, an array of Unicode characters |
| 438 | */ |
| 439 | struct smb2_netname_neg_context { |
| 440 | __le16 ContextType; /* 5 */ |
| 441 | __le16 DataLength; |
| 442 | __le32 Reserved; |
| 443 | __le16 NetName[]; /* hostname of target converted to UCS-2 */ |
| 444 | } __packed; |
| 445 | |
| 446 | /* |
| 447 | * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5 |
| 448 | * and 2.2.4.1.5 |
| 449 | */ |
| 450 | |
| 451 | /* Flags */ |
| 452 | #define SMB2_ACCEPT_TRANSFORM_LEVEL_SECURITY 0x00000001 |
| 453 | |
| 454 | struct smb2_transport_capabilities_context { |
| 455 | __le16 ContextType; /* 6 */ |
| 456 | __le16 DataLength; |
| 457 | __u32 Reserved; |
| 458 | __le32 Flags; |
| 459 | __u32 Pad; |
| 460 | } __packed; |
| 461 | |
| 462 | /* |
| 463 | * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6 |
| 464 | * and 2.2.4.1.6 |
| 465 | */ |
| 466 | |
| 467 | /* RDMA Transform IDs */ |
| 468 | #define SMB2_RDMA_TRANSFORM_NONE 0x0000 |
| 469 | #define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001 |
| 470 | #define SMB2_RDMA_TRANSFORM_SIGNING 0x0002 |
| 471 | |
| 472 | struct smb2_rdma_transform_capabilities_context { |
| 473 | __le16 ContextType; /* 7 */ |
| 474 | __le16 DataLength; |
| 475 | __u32 Reserved; |
| 476 | __le16 TransformCount; |
| 477 | __u16 Reserved1; |
| 478 | __u32 Reserved2; |
| 479 | __le16 RDMATransformIds[]; |
| 480 | } __packed; |
| 481 | |
| 482 | /* |
| 483 | * For signing capabilities context see MS-SMB2 2.2.3.1.7 |
| 484 | * and 2.2.4.1.7 |
| 485 | */ |
| 486 | |
| 487 | /* Signing algorithms */ |
| 488 | #define SIGNING_ALG_HMAC_SHA256 0 |
| 489 | #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0) |
| 490 | #define SIGNING_ALG_AES_CMAC 1 |
| 491 | #define SIGNING_ALG_AES_CMAC_LE cpu_to_le16(1) |
| 492 | #define SIGNING_ALG_AES_GMAC 2 |
| 493 | #define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2) |
| 494 | |
| 495 | struct smb2_signing_capabilities { |
| 496 | __le16 ContextType; /* 8 */ |
| 497 | __le16 DataLength; |
| 498 | __le32 Reserved; |
| 499 | __le16 SigningAlgorithmCount; |
| 500 | __le16 SigningAlgorithms[]; |
| 501 | /* Followed by padding to 8 byte boundary (required by some servers) */ |
| 502 | } __packed; |
| 503 | |
| 504 | #define POSIX_CTXT_DATA_LEN 16 |
| 505 | struct smb2_posix_neg_context { |
| 506 | __le16 ContextType; /* 0x100 */ |
| 507 | __le16 DataLength; |
| 508 | __le32 Reserved; |
| 509 | __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */ |
| 510 | } __packed; |
| 511 | |
| 512 | struct smb2_negotiate_req { |
| 513 | struct smb2_hdr hdr; |
| 514 | __le16 StructureSize; /* Must be 36 */ |
| 515 | __le16 DialectCount; |
| 516 | __le16 SecurityMode; |
| 517 | __le16 Reserved; /* MBZ */ |
| 518 | __le32 Capabilities; |
| 519 | __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE]; |
| 520 | /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */ |
| 521 | __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */ |
| 522 | __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */ |
| 523 | __le16 Reserved2; |
| 524 | __le16 Dialects[]; |
| 525 | } __packed; |
| 526 | |
| 527 | struct smb2_negotiate_rsp { |
| 528 | struct smb2_hdr hdr; |
| 529 | __le16 StructureSize; /* Must be 65 */ |
| 530 | __le16 SecurityMode; |
| 531 | __le16 DialectRevision; |
| 532 | __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */ |
| 533 | __u8 ServerGUID[16]; |
| 534 | __le32 Capabilities; |
| 535 | __le32 MaxTransactSize; |
| 536 | __le32 MaxReadSize; |
| 537 | __le32 MaxWriteSize; |
| 538 | __le64 SystemTime; /* MBZ */ |
| 539 | __le64 ServerStartTime; |
| 540 | __le16 SecurityBufferOffset; |
| 541 | __le16 SecurityBufferLength; |
| 542 | __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */ |
| 543 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 544 | } __packed; |
| 545 | |
| 546 | |
Ronnie Sahlberg | d8d9de5 | 2021-09-08 12:10:14 +1000 | [diff] [blame^] | 547 | /* |
| 548 | * SMB2_SESSION_SETUP See MS-SMB2 section 2.2.5 |
| 549 | */ |
| 550 | /* Flags */ |
| 551 | #define SMB2_SESSION_REQ_FLAG_BINDING 0x01 |
| 552 | #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04 |
| 553 | |
| 554 | struct smb2_sess_setup_req { |
| 555 | struct smb2_hdr hdr; |
| 556 | __le16 StructureSize; /* Must be 25 */ |
| 557 | __u8 Flags; |
| 558 | __u8 SecurityMode; |
| 559 | __le32 Capabilities; |
| 560 | __le32 Channel; |
| 561 | __le16 SecurityBufferOffset; |
| 562 | __le16 SecurityBufferLength; |
| 563 | __le64 PreviousSessionId; |
| 564 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 565 | } __packed; |
| 566 | |
| 567 | /* Currently defined SessionFlags */ |
| 568 | #define SMB2_SESSION_FLAG_IS_GUEST 0x0001 |
| 569 | #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001) |
| 570 | #define SMB2_SESSION_FLAG_IS_NULL 0x0002 |
| 571 | #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002) |
| 572 | #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004 |
| 573 | #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004) |
| 574 | |
| 575 | struct smb2_sess_setup_rsp { |
| 576 | struct smb2_hdr hdr; |
| 577 | __le16 StructureSize; /* Must be 9 */ |
| 578 | __le16 SessionFlags; |
| 579 | __le16 SecurityBufferOffset; |
| 580 | __le16 SecurityBufferLength; |
| 581 | __u8 Buffer[1]; /* variable length GSS security buffer */ |
| 582 | } __packed; |
| 583 | |
| 584 | |
| 585 | /* |
| 586 | * SMB2_LOGOFF See MS-SMB2 section 2.2.7 |
| 587 | */ |
| 588 | struct smb2_logoff_req { |
| 589 | struct smb2_hdr hdr; |
| 590 | __le16 StructureSize; /* Must be 4 */ |
| 591 | __le16 Reserved; |
| 592 | } __packed; |
| 593 | |
| 594 | struct smb2_logoff_rsp { |
| 595 | struct smb2_hdr hdr; |
| 596 | __le16 StructureSize; /* Must be 4 */ |
| 597 | __le16 Reserved; |
| 598 | } __packed; |
| 599 | |
| 600 | |
| 601 | /* |
| 602 | * SMB2_CLOSE See MS-SMB2 section 2.2.15 |
| 603 | */ |
| 604 | /* Currently defined values for close flags */ |
| 605 | #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001) |
| 606 | struct smb2_close_req { |
| 607 | struct smb2_hdr hdr; |
| 608 | __le16 StructureSize; /* Must be 24 */ |
| 609 | __le16 Flags; |
| 610 | __le32 Reserved; |
| 611 | __le64 PersistentFileId; /* opaque endianness */ |
| 612 | __le64 VolatileFileId; /* opaque endianness */ |
| 613 | } __packed; |
| 614 | |
| 615 | /* |
| 616 | * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data) |
| 617 | */ |
| 618 | #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124 |
| 619 | |
| 620 | struct smb2_close_rsp { |
| 621 | struct smb2_hdr hdr; |
| 622 | __le16 StructureSize; /* 60 */ |
| 623 | __le16 Flags; |
| 624 | __le32 Reserved; |
| 625 | __le64 CreationTime; |
| 626 | __le64 LastAccessTime; |
| 627 | __le64 LastWriteTime; |
| 628 | __le64 ChangeTime; |
| 629 | __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */ |
| 630 | __le64 EndOfFile; |
| 631 | __le32 Attributes; |
| 632 | } __packed; |
| 633 | |
| 634 | |
| 635 | /* |
| 636 | * SMB2_READ See MS-SMB2 section 2.2.19 |
| 637 | */ |
| 638 | /* For read request Flags field below, following flag is defined for SMB3.02 */ |
| 639 | #define SMB2_READFLAG_READ_UNBUFFERED 0x01 |
| 640 | #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */ |
| 641 | |
| 642 | /* Channel field for read and write: exactly one of following flags can be set*/ |
| 643 | #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000) |
| 644 | #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) |
| 645 | #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) |
| 646 | #define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003) |
| 647 | |
| 648 | /* SMB2 read request without RFC1001 length at the beginning */ |
| 649 | struct smb2_read_req { |
| 650 | struct smb2_hdr hdr; |
| 651 | __le16 StructureSize; /* Must be 49 */ |
| 652 | __u8 Padding; /* offset from start of SMB2 header to place read */ |
| 653 | __u8 Flags; /* MBZ unless SMB3.02 or later */ |
| 654 | __le32 Length; |
| 655 | __le64 Offset; |
| 656 | __le64 PersistentFileId; |
| 657 | __le64 VolatileFileId; |
| 658 | __le32 MinimumCount; |
| 659 | __le32 Channel; /* MBZ except for SMB3 or later */ |
| 660 | __le32 RemainingBytes; |
| 661 | __le16 ReadChannelInfoOffset; |
| 662 | __le16 ReadChannelInfoLength; |
| 663 | __u8 Buffer[1]; |
| 664 | } __packed; |
| 665 | |
| 666 | /* Read flags */ |
| 667 | #define SMB2_READFLAG_RESPONSE_NONE cpu_to_le32(0x00000000) |
| 668 | #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM cpu_to_le32(0x00000001) |
| 669 | |
| 670 | struct smb2_read_rsp { |
| 671 | struct smb2_hdr hdr; |
| 672 | __le16 StructureSize; /* Must be 17 */ |
| 673 | __u8 DataOffset; |
| 674 | __u8 Reserved; |
| 675 | __le32 DataLength; |
| 676 | __le32 DataRemaining; |
| 677 | __le32 Flags; |
| 678 | __u8 Buffer[1]; |
| 679 | } __packed; |
| 680 | |
| 681 | |
| 682 | /* |
| 683 | * SMB2_WRITE See MS-SMB2 section 2.2.21 |
| 684 | */ |
| 685 | /* For write request Flags field below the following flags are defined: */ |
| 686 | #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */ |
| 687 | #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */ |
| 688 | |
| 689 | struct smb2_write_req { |
| 690 | struct smb2_hdr hdr; |
| 691 | __le16 StructureSize; /* Must be 49 */ |
| 692 | __le16 DataOffset; /* offset from start of SMB2 header to write data */ |
| 693 | __le32 Length; |
| 694 | __le64 Offset; |
| 695 | __le64 PersistentFileId; /* opaque endianness */ |
| 696 | __le64 VolatileFileId; /* opaque endianness */ |
| 697 | __le32 Channel; /* MBZ unless SMB3.02 or later */ |
| 698 | __le32 RemainingBytes; |
| 699 | __le16 WriteChannelInfoOffset; |
| 700 | __le16 WriteChannelInfoLength; |
| 701 | __le32 Flags; |
| 702 | __u8 Buffer[1]; |
| 703 | } __packed; |
| 704 | |
| 705 | struct smb2_write_rsp { |
| 706 | struct smb2_hdr hdr; |
| 707 | __le16 StructureSize; /* Must be 17 */ |
| 708 | __u8 DataOffset; |
| 709 | __u8 Reserved; |
| 710 | __le32 DataLength; |
| 711 | __le32 DataRemaining; |
| 712 | __u32 Reserved2; |
| 713 | __u8 Buffer[1]; |
| 714 | } __packed; |
| 715 | |
| 716 | |
| 717 | /* |
| 718 | * SMB2_FLUSH See MS-SMB2 section 2.2.17 |
| 719 | */ |
| 720 | struct smb2_flush_req { |
| 721 | struct smb2_hdr hdr; |
| 722 | __le16 StructureSize; /* Must be 24 */ |
| 723 | __le16 Reserved1; |
| 724 | __le32 Reserved2; |
| 725 | __le64 PersistentFileId; |
| 726 | __le64 VolatileFileId; |
| 727 | } __packed; |
| 728 | |
| 729 | struct smb2_flush_rsp { |
| 730 | struct smb2_hdr hdr; |
| 731 | __le16 StructureSize; |
| 732 | __le16 Reserved; |
| 733 | } __packed; |
| 734 | |
| 735 | |
| 736 | /* |
| 737 | * SMB2_NOTIFY See MS-SMB2 section 2.2.35 |
| 738 | */ |
| 739 | /* notify flags */ |
| 740 | #define SMB2_WATCH_TREE 0x0001 |
| 741 | |
| 742 | /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */ |
| 743 | #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 |
| 744 | #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 |
| 745 | #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004 |
| 746 | #define FILE_NOTIFY_CHANGE_SIZE 0x00000008 |
| 747 | #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010 |
| 748 | #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020 |
| 749 | #define FILE_NOTIFY_CHANGE_CREATION 0x00000040 |
| 750 | #define FILE_NOTIFY_CHANGE_EA 0x00000080 |
| 751 | #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100 |
| 752 | #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200 |
| 753 | #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400 |
| 754 | #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800 |
| 755 | |
| 756 | /* SMB2 Notify Action Flags */ |
| 757 | #define FILE_ACTION_ADDED 0x00000001 |
| 758 | #define FILE_ACTION_REMOVED 0x00000002 |
| 759 | #define FILE_ACTION_MODIFIED 0x00000003 |
| 760 | #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004 |
| 761 | #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005 |
| 762 | #define FILE_ACTION_ADDED_STREAM 0x00000006 |
| 763 | #define FILE_ACTION_REMOVED_STREAM 0x00000007 |
| 764 | #define FILE_ACTION_MODIFIED_STREAM 0x00000008 |
| 765 | #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009 |
| 766 | |
| 767 | struct smb2_change_notify_req { |
| 768 | struct smb2_hdr hdr; |
| 769 | __le16 StructureSize; |
| 770 | __le16 Flags; |
| 771 | __le32 OutputBufferLength; |
| 772 | __le64 PersistentFileId; /* opaque endianness */ |
| 773 | __le64 VolatileFileId; /* opaque endianness */ |
| 774 | __le32 CompletionFilter; |
| 775 | __u32 Reserved; |
| 776 | } __packed; |
| 777 | |
| 778 | struct smb2_change_notify_rsp { |
| 779 | struct smb2_hdr hdr; |
| 780 | __le16 StructureSize; /* Must be 9 */ |
| 781 | __le16 OutputBufferOffset; |
| 782 | __le32 OutputBufferLength; |
| 783 | __u8 Buffer[1]; /* array of file notify structs */ |
| 784 | } __packed; |
| 785 | |
| 786 | |
| 787 | |
Ronnie Sahlberg | 0d35e38 | 2021-11-05 08:39:01 +0900 | [diff] [blame] | 788 | #endif /* _COMMON_SMB2PDU_H */ |