smb2pdu.h 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. /*
  2. * fs/cifs/smb2pdu.h
  3. *
  4. * Copyright (c) International Business Machines Corp., 2009, 2013
  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. #ifndef _SMB2PDU_H
  24. #define _SMB2PDU_H
  25. #include <net/sock.h>
  26. /*
  27. * Note that, due to trying to use names similar to the protocol specifications,
  28. * there are many mixed case field names in the structures below. Although
  29. * this does not match typical Linux kernel style, it is necessary to be
  30. * be able to match against the protocol specfication.
  31. *
  32. * SMB2 commands
  33. * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
  34. * (ie no useful data other than the SMB error code itself) and are marked such.
  35. * Knowing this helps avoid response buffer allocations and copy in some cases.
  36. */
  37. /* List of commands in host endian */
  38. #define SMB2_NEGOTIATE_HE 0x0000
  39. #define SMB2_SESSION_SETUP_HE 0x0001
  40. #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
  41. #define SMB2_TREE_CONNECT_HE 0x0003
  42. #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
  43. #define SMB2_CREATE_HE 0x0005
  44. #define SMB2_CLOSE_HE 0x0006
  45. #define SMB2_FLUSH_HE 0x0007 /* trivial resp */
  46. #define SMB2_READ_HE 0x0008
  47. #define SMB2_WRITE_HE 0x0009
  48. #define SMB2_LOCK_HE 0x000A
  49. #define SMB2_IOCTL_HE 0x000B
  50. #define SMB2_CANCEL_HE 0x000C
  51. #define SMB2_ECHO_HE 0x000D
  52. #define SMB2_QUERY_DIRECTORY_HE 0x000E
  53. #define SMB2_CHANGE_NOTIFY_HE 0x000F
  54. #define SMB2_QUERY_INFO_HE 0x0010
  55. #define SMB2_SET_INFO_HE 0x0011
  56. #define SMB2_OPLOCK_BREAK_HE 0x0012
  57. /* The same list in little endian */
  58. #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
  59. #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
  60. #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
  61. #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
  62. #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
  63. #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
  64. #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
  65. #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
  66. #define SMB2_READ cpu_to_le16(SMB2_READ_HE)
  67. #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
  68. #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
  69. #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
  70. #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
  71. #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
  72. #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
  73. #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
  74. #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
  75. #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
  76. #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
  77. #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
  78. #define NUMBER_OF_SMB2_COMMANDS 0x0013
  79. /* 52 transform hdr + 64 hdr + 88 create rsp */
  80. #define MAX_SMB2_HDR_SIZE 204
  81. #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
  82. #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
  83. /*
  84. * SMB2 Header Definition
  85. *
  86. * "MBZ" : Must be Zero
  87. * "BB" : BugBug, Something to check/review/analyze later
  88. * "PDU" : "Protocol Data Unit" (ie a network "frame")
  89. *
  90. */
  91. #define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
  92. struct smb2_sync_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. __le32 ProcessId;
  103. __u32 TreeId; /* opaque - so do not make little endian */
  104. __u64 SessionId; /* opaque - so do not make little endian */
  105. __u8 Signature[16];
  106. } __packed;
  107. struct smb2_sync_pdu {
  108. struct smb2_sync_hdr sync_hdr;
  109. __le16 StructureSize2; /* size of wct area (varies, request specific) */
  110. } __packed;
  111. #define SMB3_AES128CMM_NONCE 11
  112. #define SMB3_AES128GCM_NONCE 12
  113. struct smb2_transform_hdr {
  114. __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
  115. __u8 Signature[16];
  116. __u8 Nonce[16];
  117. __le32 OriginalMessageSize;
  118. __u16 Reserved1;
  119. __le16 Flags; /* EncryptionAlgorithm */
  120. __u64 SessionId;
  121. } __packed;
  122. /*
  123. * SMB2 flag definitions
  124. */
  125. #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
  126. #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
  127. #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
  128. #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
  129. #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
  130. /*
  131. * Definitions for SMB2 Protocol Data Units (network frames)
  132. *
  133. * See MS-SMB2.PDF specification for protocol details.
  134. * The Naming convention is the lower case version of the SMB2
  135. * command code name for the struct. Note that structures must be packed.
  136. *
  137. */
  138. #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
  139. #define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
  140. struct smb2_err_rsp {
  141. struct smb2_sync_hdr sync_hdr;
  142. __le16 StructureSize;
  143. __le16 Reserved; /* MBZ */
  144. __le32 ByteCount; /* even if zero, at least one byte follows */
  145. __u8 ErrorData[1]; /* variable length */
  146. } __packed;
  147. struct smb2_symlink_err_rsp {
  148. __le32 SymLinkLength;
  149. __le32 SymLinkErrorTag;
  150. __le32 ReparseTag;
  151. __le16 ReparseDataLength;
  152. __le16 UnparsedPathLength;
  153. __le16 SubstituteNameOffset;
  154. __le16 SubstituteNameLength;
  155. __le16 PrintNameOffset;
  156. __le16 PrintNameLength;
  157. __le32 Flags;
  158. __u8 PathBuffer[0];
  159. } __packed;
  160. /* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
  161. struct smb2_error_context_rsp {
  162. __le32 ErrorDataLength;
  163. __le32 ErrorId;
  164. __u8 ErrorContextData; /* ErrorDataLength long array */
  165. } __packed;
  166. /* Defines for Type field below (see MS-SMB2 2.2.2.2.2.1) */
  167. #define MOVE_DST_IPADDR_V4 cpu_to_le32(0x00000001)
  168. #define MOVE_DST_IPADDR_V6 cpu_to_le32(0x00000002)
  169. struct move_dst_ipaddr {
  170. __le32 Type;
  171. __u32 Reserved;
  172. __u8 address[16]; /* IPv4 followed by 12 bytes rsvd or IPv6 address */
  173. } __packed;
  174. struct share_redirect_error_context_rsp {
  175. __le32 StructureSize;
  176. __le32 NotificationType;
  177. __le32 ResourceNameOffset;
  178. __le32 ResourceNameLength;
  179. __le16 Flags;
  180. __le16 TargetType;
  181. __le32 IPAddrCount;
  182. struct move_dst_ipaddr IpAddrMoveList[0];
  183. /* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
  184. } __packed;
  185. #define SMB2_CLIENT_GUID_SIZE 16
  186. struct smb2_negotiate_req {
  187. struct smb2_sync_hdr sync_hdr;
  188. __le16 StructureSize; /* Must be 36 */
  189. __le16 DialectCount;
  190. __le16 SecurityMode;
  191. __le16 Reserved; /* MBZ */
  192. __le32 Capabilities;
  193. __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
  194. /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
  195. __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
  196. __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
  197. __le16 Reserved2;
  198. __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
  199. } __packed;
  200. /* Dialects */
  201. #define SMB20_PROT_ID 0x0202
  202. #define SMB21_PROT_ID 0x0210
  203. #define SMB30_PROT_ID 0x0300
  204. #define SMB302_PROT_ID 0x0302
  205. #define SMB311_PROT_ID 0x0311
  206. #define BAD_PROT_ID 0xFFFF
  207. /* SecurityMode flags */
  208. #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
  209. #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
  210. #define SMB2_SEC_MODE_FLAGS_ALL 0x0003
  211. /* Capabilities flags */
  212. #define SMB2_GLOBAL_CAP_DFS 0x00000001
  213. #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
  214. #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
  215. #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
  216. #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
  217. #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
  218. #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
  219. /* Internal types */
  220. #define SMB2_NT_FIND 0x00100000
  221. #define SMB2_LARGE_FILES 0x00200000
  222. struct smb2_neg_context {
  223. __le16 ContextType;
  224. __le16 DataLength;
  225. __le32 Reserved;
  226. /* Followed by array of data */
  227. } __packed;
  228. #define SMB311_SALT_SIZE 32
  229. /* Hash Algorithm Types */
  230. #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
  231. #define SMB2_PREAUTH_HASH_SIZE 64
  232. #define MIN_PREAUTH_CTXT_DATA_LEN (SMB311_SALT_SIZE + 6)
  233. struct smb2_preauth_neg_context {
  234. __le16 ContextType; /* 1 */
  235. __le16 DataLength;
  236. __le32 Reserved;
  237. __le16 HashAlgorithmCount; /* 1 */
  238. __le16 SaltLength;
  239. __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
  240. __u8 Salt[SMB311_SALT_SIZE];
  241. } __packed;
  242. /* Encryption Algorithms Ciphers */
  243. #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
  244. #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
  245. /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
  246. #define MIN_ENCRYPT_CTXT_DATA_LEN 4
  247. struct smb2_encryption_neg_context {
  248. __le16 ContextType; /* 2 */
  249. __le16 DataLength;
  250. __le32 Reserved;
  251. __le16 CipherCount; /* AES-128-GCM and AES-128-CCM */
  252. __le16 Ciphers[1]; /* Ciphers[0] since only one used now */
  253. } __packed;
  254. #define POSIX_CTXT_DATA_LEN 8
  255. struct smb2_posix_neg_context {
  256. __le16 ContextType; /* 0x100 */
  257. __le16 DataLength;
  258. __le32 Reserved;
  259. __le64 Reserved1; /* In case needed for future (eg version or caps) */
  260. } __packed;
  261. struct smb2_negotiate_rsp {
  262. struct smb2_sync_hdr sync_hdr;
  263. __le16 StructureSize; /* Must be 65 */
  264. __le16 SecurityMode;
  265. __le16 DialectRevision;
  266. __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
  267. __u8 ServerGUID[16];
  268. __le32 Capabilities;
  269. __le32 MaxTransactSize;
  270. __le32 MaxReadSize;
  271. __le32 MaxWriteSize;
  272. __le64 SystemTime; /* MBZ */
  273. __le64 ServerStartTime;
  274. __le16 SecurityBufferOffset;
  275. __le16 SecurityBufferLength;
  276. __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
  277. __u8 Buffer[1]; /* variable length GSS security buffer */
  278. } __packed;
  279. /* Flags */
  280. #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
  281. #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
  282. struct smb2_sess_setup_req {
  283. struct smb2_sync_hdr sync_hdr;
  284. __le16 StructureSize; /* Must be 25 */
  285. __u8 Flags;
  286. __u8 SecurityMode;
  287. __le32 Capabilities;
  288. __le32 Channel;
  289. __le16 SecurityBufferOffset;
  290. __le16 SecurityBufferLength;
  291. __u64 PreviousSessionId;
  292. __u8 Buffer[1]; /* variable length GSS security buffer */
  293. } __packed;
  294. /* Currently defined SessionFlags */
  295. #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
  296. #define SMB2_SESSION_FLAG_IS_NULL 0x0002
  297. #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
  298. struct smb2_sess_setup_rsp {
  299. struct smb2_sync_hdr sync_hdr;
  300. __le16 StructureSize; /* Must be 9 */
  301. __le16 SessionFlags;
  302. __le16 SecurityBufferOffset;
  303. __le16 SecurityBufferLength;
  304. __u8 Buffer[1]; /* variable length GSS security buffer */
  305. } __packed;
  306. struct smb2_logoff_req {
  307. struct smb2_sync_hdr sync_hdr;
  308. __le16 StructureSize; /* Must be 4 */
  309. __le16 Reserved;
  310. } __packed;
  311. struct smb2_logoff_rsp {
  312. struct smb2_sync_hdr sync_hdr;
  313. __le16 StructureSize; /* Must be 4 */
  314. __le16 Reserved;
  315. } __packed;
  316. /* Flags/Reserved for SMB3.1.1 */
  317. #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
  318. #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
  319. #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
  320. struct smb2_tree_connect_req {
  321. struct smb2_sync_hdr sync_hdr;
  322. __le16 StructureSize; /* Must be 9 */
  323. __le16 Reserved; /* Flags in SMB3.1.1 */
  324. __le16 PathOffset;
  325. __le16 PathLength;
  326. __u8 Buffer[1]; /* variable length */
  327. } __packed;
  328. /* See MS-SMB2 section 2.2.9.2 */
  329. /* Context Types */
  330. #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
  331. #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
  332. struct tree_connect_contexts {
  333. __le16 ContextType;
  334. __le16 DataLength;
  335. __le32 Reserved;
  336. __u8 Data[0];
  337. } __packed;
  338. /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
  339. struct smb3_blob_data {
  340. __le16 BlobSize;
  341. __u8 BlobData[0];
  342. } __packed;
  343. /* Valid values for Attr */
  344. #define SE_GROUP_MANDATORY 0x00000001
  345. #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
  346. #define SE_GROUP_ENABLED 0x00000004
  347. #define SE_GROUP_OWNER 0x00000008
  348. #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
  349. #define SE_GROUP_INTEGRITY 0x00000020
  350. #define SE_GROUP_INTEGRITY_ENABLED 0x00000040
  351. #define SE_GROUP_RESOURCE 0x20000000
  352. #define SE_GROUP_LOGON_ID 0xC0000000
  353. /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
  354. struct sid_array_data {
  355. __le16 SidAttrCount;
  356. /* SidAttrList - array of sid_attr_data structs */
  357. } __packed;
  358. struct luid_attr_data {
  359. } __packed;
  360. /*
  361. * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
  362. * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
  363. */
  364. struct privilege_array_data {
  365. __le16 PrivilegeCount;
  366. /* array of privilege_data structs */
  367. } __packed;
  368. struct remoted_identity_tcon_context {
  369. __le16 TicketType; /* must be 0x0001 */
  370. __le16 TicketSize; /* total size of this struct */
  371. __le16 User; /* offset to SID_ATTR_DATA struct with user info */
  372. __le16 UserName; /* offset to null terminated Unicode username string */
  373. __le16 Domain; /* offset to null terminated Unicode domain name */
  374. __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
  375. __le16 RestrictedGroups; /* similar to above */
  376. __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
  377. __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
  378. __le16 Owner; /* offset to BLOB_DATA struct */
  379. __le16 DefaultDacl; /* offset to BLOB_DATA struct */
  380. __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
  381. __le16 UserClaims; /* offset to BLOB_DATA struct */
  382. __le16 DeviceClaims; /* offset to BLOB_DATA struct */
  383. __u8 TicketInfo[0]; /* variable length buf - remoted identity data */
  384. } __packed;
  385. struct smb2_tree_connect_req_extension {
  386. __le32 TreeConnectContextOffset;
  387. __le16 TreeConnectContextCount;
  388. __u8 Reserved[10];
  389. __u8 PathName[0]; /* variable sized array */
  390. /* followed by array of TreeConnectContexts */
  391. } __packed;
  392. struct smb2_tree_connect_rsp {
  393. struct smb2_sync_hdr sync_hdr;
  394. __le16 StructureSize; /* Must be 16 */
  395. __u8 ShareType; /* see below */
  396. __u8 Reserved;
  397. __le32 ShareFlags; /* see below */
  398. __le32 Capabilities; /* see below */
  399. __le32 MaximalAccess;
  400. } __packed;
  401. /* Possible ShareType values */
  402. #define SMB2_SHARE_TYPE_DISK 0x01
  403. #define SMB2_SHARE_TYPE_PIPE 0x02
  404. #define SMB2_SHARE_TYPE_PRINT 0x03
  405. /*
  406. * Possible ShareFlags - exactly one and only one of the first 4 caching flags
  407. * must be set (any of the remaining, SHI1005, flags may be set individually
  408. * or in combination.
  409. */
  410. #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
  411. #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
  412. #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
  413. #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
  414. #define SHI1005_FLAGS_DFS 0x00000001
  415. #define SHI1005_FLAGS_DFS_ROOT 0x00000002
  416. #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
  417. #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
  418. #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
  419. #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
  420. #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
  421. #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
  422. #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
  423. #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
  424. #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
  425. #define SHI1005_FLAGS_ALL 0x0004FF33
  426. /* Possible share capabilities */
  427. #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
  428. #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
  429. #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
  430. #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
  431. #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
  432. #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
  433. struct smb2_tree_disconnect_req {
  434. struct smb2_sync_hdr sync_hdr;
  435. __le16 StructureSize; /* Must be 4 */
  436. __le16 Reserved;
  437. } __packed;
  438. struct smb2_tree_disconnect_rsp {
  439. struct smb2_sync_hdr sync_hdr;
  440. __le16 StructureSize; /* Must be 4 */
  441. __le16 Reserved;
  442. } __packed;
  443. /* File Attrubutes */
  444. #define FILE_ATTRIBUTE_READONLY 0x00000001
  445. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  446. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  447. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  448. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  449. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  450. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  451. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  452. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  453. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  454. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  455. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  456. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  457. #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
  458. #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
  459. /* Oplock levels */
  460. #define SMB2_OPLOCK_LEVEL_NONE 0x00
  461. #define SMB2_OPLOCK_LEVEL_II 0x01
  462. #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
  463. #define SMB2_OPLOCK_LEVEL_BATCH 0x09
  464. #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
  465. /* Non-spec internal type */
  466. #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
  467. /* Desired Access Flags */
  468. #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
  469. #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
  470. #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
  471. #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
  472. #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
  473. #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
  474. #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
  475. #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
  476. #define FILE_DELETE_LE cpu_to_le32(0x00010000)
  477. #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
  478. #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
  479. #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
  480. #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
  481. #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
  482. #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
  483. #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
  484. #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
  485. #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
  486. #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
  487. /* ShareAccess Flags */
  488. #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
  489. #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
  490. #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
  491. #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
  492. /* CreateDisposition Flags */
  493. #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
  494. #define FILE_OPEN_LE cpu_to_le32(0x00000001)
  495. #define FILE_CREATE_LE cpu_to_le32(0x00000002)
  496. #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
  497. #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
  498. #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
  499. /* CreateOptions Flags */
  500. #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
  501. /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
  502. #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
  503. #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
  504. #define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
  505. #define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
  506. #define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
  507. #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
  508. #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
  509. #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
  510. #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
  511. #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
  512. #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
  513. #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
  514. #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
  515. #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
  516. #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
  517. #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
  518. #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
  519. #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
  520. | FILE_READ_ATTRIBUTES_LE)
  521. #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
  522. | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
  523. #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
  524. /* Impersonation Levels */
  525. #define IL_ANONYMOUS cpu_to_le32(0x00000000)
  526. #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
  527. #define IL_IMPERSONATION cpu_to_le32(0x00000002)
  528. #define IL_DELEGATE cpu_to_le32(0x00000003)
  529. /* Create Context Values */
  530. #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
  531. #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
  532. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
  533. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
  534. #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
  535. #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
  536. #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
  537. #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
  538. #define SMB2_CREATE_REQUEST_LEASE "RqLs"
  539. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
  540. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
  541. #define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
  542. #define SVHDX_OPEN_DEVICE_CONTEX 0x9CCBCF9E04C1E643980E158DA1F6EC83
  543. #define SMB2_CREATE_TAG_POSIX 0x93AD25509CB411E7B42383DE968BCD7C
  544. /*
  545. * Maximum number of iovs we need for an open/create request.
  546. * [0] : struct smb2_create_req
  547. * [1] : path
  548. * [2] : lease context
  549. * [3] : durable context
  550. * [4] : posix context
  551. * [5] : time warp context
  552. * [6] : compound padding
  553. */
  554. #define SMB2_CREATE_IOV_SIZE 7
  555. struct smb2_create_req {
  556. struct smb2_sync_hdr sync_hdr;
  557. __le16 StructureSize; /* Must be 57 */
  558. __u8 SecurityFlags;
  559. __u8 RequestedOplockLevel;
  560. __le32 ImpersonationLevel;
  561. __le64 SmbCreateFlags;
  562. __le64 Reserved;
  563. __le32 DesiredAccess;
  564. __le32 FileAttributes;
  565. __le32 ShareAccess;
  566. __le32 CreateDisposition;
  567. __le32 CreateOptions;
  568. __le16 NameOffset;
  569. __le16 NameLength;
  570. __le32 CreateContextsOffset;
  571. __le32 CreateContextsLength;
  572. __u8 Buffer[0];
  573. } __packed;
  574. struct smb2_create_rsp {
  575. struct smb2_sync_hdr sync_hdr;
  576. __le16 StructureSize; /* Must be 89 */
  577. __u8 OplockLevel;
  578. __u8 Reserved;
  579. __le32 CreateAction;
  580. __le64 CreationTime;
  581. __le64 LastAccessTime;
  582. __le64 LastWriteTime;
  583. __le64 ChangeTime;
  584. __le64 AllocationSize;
  585. __le64 EndofFile;
  586. __le32 FileAttributes;
  587. __le32 Reserved2;
  588. __u64 PersistentFileId; /* opaque endianness */
  589. __u64 VolatileFileId; /* opaque endianness */
  590. __le32 CreateContextsOffset;
  591. __le32 CreateContextsLength;
  592. __u8 Buffer[1];
  593. } __packed;
  594. struct create_context {
  595. __le32 Next;
  596. __le16 NameOffset;
  597. __le16 NameLength;
  598. __le16 Reserved;
  599. __le16 DataOffset;
  600. __le32 DataLength;
  601. __u8 Buffer[0];
  602. } __packed;
  603. #define SMB2_LEASE_READ_CACHING_HE 0x01
  604. #define SMB2_LEASE_HANDLE_CACHING_HE 0x02
  605. #define SMB2_LEASE_WRITE_CACHING_HE 0x04
  606. #define SMB2_LEASE_NONE cpu_to_le32(0x00)
  607. #define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
  608. #define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
  609. #define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
  610. #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
  611. #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
  612. #define SMB2_LEASE_KEY_SIZE 16
  613. struct lease_context {
  614. u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  615. __le32 LeaseState;
  616. __le32 LeaseFlags;
  617. __le64 LeaseDuration;
  618. } __packed;
  619. struct lease_context_v2 {
  620. u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  621. __le32 LeaseState;
  622. __le32 LeaseFlags;
  623. __le64 LeaseDuration;
  624. __le64 ParentLeaseKeyLow;
  625. __le64 ParentLeaseKeyHigh;
  626. __le16 Epoch;
  627. __le16 Reserved;
  628. } __packed;
  629. struct create_lease {
  630. struct create_context ccontext;
  631. __u8 Name[8];
  632. struct lease_context lcontext;
  633. } __packed;
  634. struct create_lease_v2 {
  635. struct create_context ccontext;
  636. __u8 Name[8];
  637. struct lease_context_v2 lcontext;
  638. __u8 Pad[4];
  639. } __packed;
  640. struct create_durable {
  641. struct create_context ccontext;
  642. __u8 Name[8];
  643. union {
  644. __u8 Reserved[16];
  645. struct {
  646. __u64 PersistentFileId;
  647. __u64 VolatileFileId;
  648. } Fid;
  649. } Data;
  650. } __packed;
  651. struct create_posix {
  652. struct create_context ccontext;
  653. __u8 Name[16];
  654. __le32 Mode;
  655. __u32 Reserved;
  656. } __packed;
  657. /* See MS-SMB2 2.2.13.2.11 */
  658. /* Flags */
  659. #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
  660. struct durable_context_v2 {
  661. __le32 Timeout;
  662. __le32 Flags;
  663. __u64 Reserved;
  664. __u8 CreateGuid[16];
  665. } __packed;
  666. struct create_durable_v2 {
  667. struct create_context ccontext;
  668. __u8 Name[8];
  669. struct durable_context_v2 dcontext;
  670. } __packed;
  671. /* See MS-SMB2 2.2.13.2.12 */
  672. struct durable_reconnect_context_v2 {
  673. struct {
  674. __u64 PersistentFileId;
  675. __u64 VolatileFileId;
  676. } Fid;
  677. __u8 CreateGuid[16];
  678. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  679. } __packed;
  680. /* See MS-SMB2 2.2.14.2.12 */
  681. struct durable_reconnect_context_v2_rsp {
  682. __le32 Timeout;
  683. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  684. } __packed;
  685. struct create_durable_handle_reconnect_v2 {
  686. struct create_context ccontext;
  687. __u8 Name[8];
  688. struct durable_reconnect_context_v2 dcontext;
  689. __u8 Pad[4];
  690. } __packed;
  691. /* See MS-SMB2 2.2.13.2.5 */
  692. struct crt_twarp_ctxt {
  693. struct create_context ccontext;
  694. __u8 Name[8];
  695. __le64 Timestamp;
  696. } __packed;
  697. #define COPY_CHUNK_RES_KEY_SIZE 24
  698. struct resume_key_req {
  699. char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
  700. __le32 ContextLength; /* MBZ */
  701. char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
  702. } __packed;
  703. /* this goes in the ioctl buffer when doing a copychunk request */
  704. struct copychunk_ioctl {
  705. char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
  706. __le32 ChunkCount; /* we are only sending 1 */
  707. __le32 Reserved;
  708. /* array will only be one chunk long for us */
  709. __le64 SourceOffset;
  710. __le64 TargetOffset;
  711. __le32 Length; /* how many bytes to copy */
  712. __u32 Reserved2;
  713. } __packed;
  714. /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
  715. struct file_zero_data_information {
  716. __le64 FileOffset;
  717. __le64 BeyondFinalZero;
  718. } __packed;
  719. struct copychunk_ioctl_rsp {
  720. __le32 ChunksWritten;
  721. __le32 ChunkBytesWritten;
  722. __le32 TotalBytesWritten;
  723. } __packed;
  724. struct fsctl_set_integrity_information_req {
  725. __le16 ChecksumAlgorithm;
  726. __le16 Reserved;
  727. __le32 Flags;
  728. } __packed;
  729. struct fsctl_get_integrity_information_rsp {
  730. __le16 ChecksumAlgorithm;
  731. __le16 Reserved;
  732. __le32 Flags;
  733. __le32 ChecksumChunkSizeInBytes;
  734. __le32 ClusterSizeInBytes;
  735. } __packed;
  736. /* Integrity ChecksumAlgorithm choices for above */
  737. #define CHECKSUM_TYPE_NONE 0x0000
  738. #define CHECKSUM_TYPE_CRC64 0x0002
  739. #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
  740. /* Integrity flags for above */
  741. #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
  742. /* See MS-DFSC 2.2.2 */
  743. struct fsctl_get_dfs_referral_req {
  744. __le16 MaxReferralLevel;
  745. __u8 RequestFileName[];
  746. } __packed;
  747. /* DFS response is struct get_dfs_refer_rsp */
  748. /* See MS-SMB2 2.2.31.3 */
  749. struct network_resiliency_req {
  750. __le32 Timeout;
  751. __le32 Reserved;
  752. } __packed;
  753. /* There is no buffer for the response ie no struct network_resiliency_rsp */
  754. struct validate_negotiate_info_req {
  755. __le32 Capabilities;
  756. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  757. __le16 SecurityMode;
  758. __le16 DialectCount;
  759. __le16 Dialects[3]; /* BB expand this if autonegotiate > 3 dialects */
  760. } __packed;
  761. struct validate_negotiate_info_rsp {
  762. __le32 Capabilities;
  763. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  764. __le16 SecurityMode;
  765. __le16 Dialect; /* Dialect in use for the connection */
  766. } __packed;
  767. #define RSS_CAPABLE cpu_to_le32(0x00000001)
  768. #define RDMA_CAPABLE cpu_to_le32(0x00000002)
  769. #define INTERNETWORK cpu_to_le16(0x0002)
  770. #define INTERNETWORKV6 cpu_to_le16(0x0017)
  771. struct network_interface_info_ioctl_rsp {
  772. __le32 Next; /* next interface. zero if this is last one */
  773. __le32 IfIndex;
  774. __le32 Capability; /* RSS or RDMA Capable */
  775. __le32 Reserved;
  776. __le64 LinkSpeed;
  777. __le16 Family;
  778. __u8 Buffer[126];
  779. } __packed;
  780. struct iface_info_ipv4 {
  781. __be16 Port;
  782. __be32 IPv4Address;
  783. __be64 Reserved;
  784. } __packed;
  785. struct iface_info_ipv6 {
  786. __be16 Port;
  787. __be32 FlowInfo;
  788. __u8 IPv6Address[16];
  789. __be32 ScopeId;
  790. } __packed;
  791. #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
  792. struct compress_ioctl {
  793. __le16 CompressionState; /* See cifspdu.h for possible flag values */
  794. } __packed;
  795. struct duplicate_extents_to_file {
  796. __u64 PersistentFileHandle; /* source file handle, opaque endianness */
  797. __u64 VolatileFileHandle;
  798. __le64 SourceFileOffset;
  799. __le64 TargetFileOffset;
  800. __le64 ByteCount; /* Bytes to be copied */
  801. } __packed;
  802. struct smb2_ioctl_req {
  803. struct smb2_sync_hdr sync_hdr;
  804. __le16 StructureSize; /* Must be 57 */
  805. __u16 Reserved;
  806. __le32 CtlCode;
  807. __u64 PersistentFileId; /* opaque endianness */
  808. __u64 VolatileFileId; /* opaque endianness */
  809. __le32 InputOffset;
  810. __le32 InputCount;
  811. __le32 MaxInputResponse;
  812. __le32 OutputOffset;
  813. __le32 OutputCount;
  814. __le32 MaxOutputResponse;
  815. __le32 Flags;
  816. __u32 Reserved2;
  817. __u8 Buffer[0];
  818. } __packed;
  819. struct smb2_ioctl_rsp {
  820. struct smb2_sync_hdr sync_hdr;
  821. __le16 StructureSize; /* Must be 57 */
  822. __u16 Reserved;
  823. __le32 CtlCode;
  824. __u64 PersistentFileId; /* opaque endianness */
  825. __u64 VolatileFileId; /* opaque endianness */
  826. __le32 InputOffset;
  827. __le32 InputCount;
  828. __le32 OutputOffset;
  829. __le32 OutputCount;
  830. __le32 Flags;
  831. __u32 Reserved2;
  832. /* char * buffer[] */
  833. } __packed;
  834. /* Currently defined values for close flags */
  835. #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
  836. struct smb2_close_req {
  837. struct smb2_sync_hdr sync_hdr;
  838. __le16 StructureSize; /* Must be 24 */
  839. __le16 Flags;
  840. __le32 Reserved;
  841. __u64 PersistentFileId; /* opaque endianness */
  842. __u64 VolatileFileId; /* opaque endianness */
  843. } __packed;
  844. struct smb2_close_rsp {
  845. struct smb2_sync_hdr sync_hdr;
  846. __le16 StructureSize; /* 60 */
  847. __le16 Flags;
  848. __le32 Reserved;
  849. __le64 CreationTime;
  850. __le64 LastAccessTime;
  851. __le64 LastWriteTime;
  852. __le64 ChangeTime;
  853. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  854. __le64 EndOfFile;
  855. __le32 Attributes;
  856. } __packed;
  857. struct smb2_flush_req {
  858. struct smb2_sync_hdr sync_hdr;
  859. __le16 StructureSize; /* Must be 24 */
  860. __le16 Reserved1;
  861. __le32 Reserved2;
  862. __u64 PersistentFileId; /* opaque endianness */
  863. __u64 VolatileFileId; /* opaque endianness */
  864. } __packed;
  865. struct smb2_flush_rsp {
  866. struct smb2_sync_hdr sync_hdr;
  867. __le16 StructureSize;
  868. __le16 Reserved;
  869. } __packed;
  870. /* For read request Flags field below, following flag is defined for SMB3.02 */
  871. #define SMB2_READFLAG_READ_UNBUFFERED 0x01
  872. /* Channel field for read and write: exactly one of following flags can be set*/
  873. #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
  874. #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
  875. #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
  876. /* SMB2 read request without RFC1001 length at the beginning */
  877. struct smb2_read_plain_req {
  878. struct smb2_sync_hdr sync_hdr;
  879. __le16 StructureSize; /* Must be 49 */
  880. __u8 Padding; /* offset from start of SMB2 header to place read */
  881. __u8 Flags; /* MBZ unless SMB3.02 or later */
  882. __le32 Length;
  883. __le64 Offset;
  884. __u64 PersistentFileId; /* opaque endianness */
  885. __u64 VolatileFileId; /* opaque endianness */
  886. __le32 MinimumCount;
  887. __le32 Channel; /* MBZ except for SMB3 or later */
  888. __le32 RemainingBytes;
  889. __le16 ReadChannelInfoOffset;
  890. __le16 ReadChannelInfoLength;
  891. __u8 Buffer[1];
  892. } __packed;
  893. struct smb2_read_rsp {
  894. struct smb2_sync_hdr sync_hdr;
  895. __le16 StructureSize; /* Must be 17 */
  896. __u8 DataOffset;
  897. __u8 Reserved;
  898. __le32 DataLength;
  899. __le32 DataRemaining;
  900. __u32 Reserved2;
  901. __u8 Buffer[1];
  902. } __packed;
  903. /* For write request Flags field below the following flags are defined: */
  904. #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
  905. #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
  906. struct smb2_write_req {
  907. struct smb2_sync_hdr sync_hdr;
  908. __le16 StructureSize; /* Must be 49 */
  909. __le16 DataOffset; /* offset from start of SMB2 header to write data */
  910. __le32 Length;
  911. __le64 Offset;
  912. __u64 PersistentFileId; /* opaque endianness */
  913. __u64 VolatileFileId; /* opaque endianness */
  914. __le32 Channel; /* Reserved MBZ */
  915. __le32 RemainingBytes;
  916. __le16 WriteChannelInfoOffset;
  917. __le16 WriteChannelInfoLength;
  918. __le32 Flags;
  919. __u8 Buffer[1];
  920. } __packed;
  921. struct smb2_write_rsp {
  922. struct smb2_sync_hdr sync_hdr;
  923. __le16 StructureSize; /* Must be 17 */
  924. __u8 DataOffset;
  925. __u8 Reserved;
  926. __le32 DataLength;
  927. __le32 DataRemaining;
  928. __u32 Reserved2;
  929. __u8 Buffer[1];
  930. } __packed;
  931. #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
  932. #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
  933. #define SMB2_LOCKFLAG_UNLOCK 0x0004
  934. #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
  935. struct smb2_lock_element {
  936. __le64 Offset;
  937. __le64 Length;
  938. __le32 Flags;
  939. __le32 Reserved;
  940. } __packed;
  941. struct smb2_lock_req {
  942. struct smb2_sync_hdr sync_hdr;
  943. __le16 StructureSize; /* Must be 48 */
  944. __le16 LockCount;
  945. __le32 Reserved;
  946. __u64 PersistentFileId; /* opaque endianness */
  947. __u64 VolatileFileId; /* opaque endianness */
  948. /* Followed by at least one */
  949. struct smb2_lock_element locks[1];
  950. } __packed;
  951. struct smb2_lock_rsp {
  952. struct smb2_sync_hdr sync_hdr;
  953. __le16 StructureSize; /* Must be 4 */
  954. __le16 Reserved;
  955. } __packed;
  956. struct smb2_echo_req {
  957. struct smb2_sync_hdr sync_hdr;
  958. __le16 StructureSize; /* Must be 4 */
  959. __u16 Reserved;
  960. } __packed;
  961. struct smb2_echo_rsp {
  962. struct smb2_sync_hdr sync_hdr;
  963. __le16 StructureSize; /* Must be 4 */
  964. __u16 Reserved;
  965. } __packed;
  966. /* search (query_directory) Flags field */
  967. #define SMB2_RESTART_SCANS 0x01
  968. #define SMB2_RETURN_SINGLE_ENTRY 0x02
  969. #define SMB2_INDEX_SPECIFIED 0x04
  970. #define SMB2_REOPEN 0x10
  971. struct smb2_query_directory_req {
  972. struct smb2_sync_hdr sync_hdr;
  973. __le16 StructureSize; /* Must be 33 */
  974. __u8 FileInformationClass;
  975. __u8 Flags;
  976. __le32 FileIndex;
  977. __u64 PersistentFileId; /* opaque endianness */
  978. __u64 VolatileFileId; /* opaque endianness */
  979. __le16 FileNameOffset;
  980. __le16 FileNameLength;
  981. __le32 OutputBufferLength;
  982. __u8 Buffer[1];
  983. } __packed;
  984. struct smb2_query_directory_rsp {
  985. struct smb2_sync_hdr sync_hdr;
  986. __le16 StructureSize; /* Must be 9 */
  987. __le16 OutputBufferOffset;
  988. __le32 OutputBufferLength;
  989. __u8 Buffer[1];
  990. } __packed;
  991. /* Possible InfoType values */
  992. #define SMB2_O_INFO_FILE 0x01
  993. #define SMB2_O_INFO_FILESYSTEM 0x02
  994. #define SMB2_O_INFO_SECURITY 0x03
  995. #define SMB2_O_INFO_QUOTA 0x04
  996. /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
  997. #define OWNER_SECINFO 0x00000001
  998. #define GROUP_SECINFO 0x00000002
  999. #define DACL_SECINFO 0x00000004
  1000. #define SACL_SECINFO 0x00000008
  1001. #define LABEL_SECINFO 0x00000010
  1002. #define ATTRIBUTE_SECINFO 0x00000020
  1003. #define SCOPE_SECINFO 0x00000040
  1004. #define BACKUP_SECINFO 0x00010000
  1005. #define UNPROTECTED_SACL_SECINFO 0x10000000
  1006. #define UNPROTECTED_DACL_SECINFO 0x20000000
  1007. #define PROTECTED_SACL_SECINFO 0x40000000
  1008. #define PROTECTED_DACL_SECINFO 0x80000000
  1009. /* Flags used for FileFullEAinfo */
  1010. #define SL_RESTART_SCAN 0x00000001
  1011. #define SL_RETURN_SINGLE_ENTRY 0x00000002
  1012. #define SL_INDEX_SPECIFIED 0x00000004
  1013. struct smb2_query_info_req {
  1014. struct smb2_sync_hdr sync_hdr;
  1015. __le16 StructureSize; /* Must be 41 */
  1016. __u8 InfoType;
  1017. __u8 FileInfoClass;
  1018. __le32 OutputBufferLength;
  1019. __le16 InputBufferOffset;
  1020. __u16 Reserved;
  1021. __le32 InputBufferLength;
  1022. __le32 AdditionalInformation;
  1023. __le32 Flags;
  1024. __u64 PersistentFileId; /* opaque endianness */
  1025. __u64 VolatileFileId; /* opaque endianness */
  1026. __u8 Buffer[1];
  1027. } __packed;
  1028. struct smb2_query_info_rsp {
  1029. struct smb2_sync_hdr sync_hdr;
  1030. __le16 StructureSize; /* Must be 9 */
  1031. __le16 OutputBufferOffset;
  1032. __le32 OutputBufferLength;
  1033. __u8 Buffer[1];
  1034. } __packed;
  1035. struct smb2_set_info_req {
  1036. struct smb2_sync_hdr sync_hdr;
  1037. __le16 StructureSize; /* Must be 33 */
  1038. __u8 InfoType;
  1039. __u8 FileInfoClass;
  1040. __le32 BufferLength;
  1041. __le16 BufferOffset;
  1042. __u16 Reserved;
  1043. __le32 AdditionalInformation;
  1044. __u64 PersistentFileId; /* opaque endianness */
  1045. __u64 VolatileFileId; /* opaque endianness */
  1046. __u8 Buffer[1];
  1047. } __packed;
  1048. struct smb2_set_info_rsp {
  1049. struct smb2_sync_hdr sync_hdr;
  1050. __le16 StructureSize; /* Must be 2 */
  1051. } __packed;
  1052. struct smb2_oplock_break {
  1053. struct smb2_sync_hdr sync_hdr;
  1054. __le16 StructureSize; /* Must be 24 */
  1055. __u8 OplockLevel;
  1056. __u8 Reserved;
  1057. __le32 Reserved2;
  1058. __u64 PersistentFid;
  1059. __u64 VolatileFid;
  1060. } __packed;
  1061. #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
  1062. struct smb2_lease_break {
  1063. struct smb2_sync_hdr sync_hdr;
  1064. __le16 StructureSize; /* Must be 44 */
  1065. __le16 Reserved;
  1066. __le32 Flags;
  1067. __u8 LeaseKey[16];
  1068. __le32 CurrentLeaseState;
  1069. __le32 NewLeaseState;
  1070. __le32 BreakReason;
  1071. __le32 AccessMaskHint;
  1072. __le32 ShareMaskHint;
  1073. } __packed;
  1074. struct smb2_lease_ack {
  1075. struct smb2_sync_hdr sync_hdr;
  1076. __le16 StructureSize; /* Must be 36 */
  1077. __le16 Reserved;
  1078. __le32 Flags;
  1079. __u8 LeaseKey[16];
  1080. __le32 LeaseState;
  1081. __le64 LeaseDuration;
  1082. } __packed;
  1083. /*
  1084. * PDU infolevel structure definitions
  1085. * BB consider moving to a different header
  1086. */
  1087. /* File System Information Classes */
  1088. #define FS_VOLUME_INFORMATION 1 /* Query */
  1089. #define FS_LABEL_INFORMATION 2 /* Local only */
  1090. #define FS_SIZE_INFORMATION 3 /* Query */
  1091. #define FS_DEVICE_INFORMATION 4 /* Query */
  1092. #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
  1093. #define FS_CONTROL_INFORMATION 6 /* Query, Set */
  1094. #define FS_FULL_SIZE_INFORMATION 7 /* Query */
  1095. #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
  1096. #define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
  1097. #define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
  1098. #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
  1099. #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
  1100. struct smb2_fs_full_size_info {
  1101. __le64 TotalAllocationUnits;
  1102. __le64 CallerAvailableAllocationUnits;
  1103. __le64 ActualAvailableAllocationUnits;
  1104. __le32 SectorsPerAllocationUnit;
  1105. __le32 BytesPerSector;
  1106. } __packed;
  1107. #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
  1108. #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
  1109. #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
  1110. #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
  1111. /* sector size info struct */
  1112. struct smb3_fs_ss_info {
  1113. __le32 LogicalBytesPerSector;
  1114. __le32 PhysicalBytesPerSectorForAtomicity;
  1115. __le32 PhysicalBytesPerSectorForPerf;
  1116. __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
  1117. __le32 Flags;
  1118. __le32 ByteOffsetForSectorAlignment;
  1119. __le32 ByteOffsetForPartitionAlignment;
  1120. } __packed;
  1121. /* volume info struct - see MS-FSCC 2.5.9 */
  1122. #define MAX_VOL_LABEL_LEN 32
  1123. struct smb3_fs_vol_info {
  1124. __le64 VolumeCreationTime;
  1125. __u32 VolumeSerialNumber;
  1126. __le32 VolumeLabelLength; /* includes trailing null */
  1127. __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
  1128. __u8 Reserved;
  1129. __u8 VolumeLabel[0]; /* variable len */
  1130. } __packed;
  1131. /* partial list of QUERY INFO levels */
  1132. #define FILE_DIRECTORY_INFORMATION 1
  1133. #define FILE_FULL_DIRECTORY_INFORMATION 2
  1134. #define FILE_BOTH_DIRECTORY_INFORMATION 3
  1135. #define FILE_BASIC_INFORMATION 4
  1136. #define FILE_STANDARD_INFORMATION 5
  1137. #define FILE_INTERNAL_INFORMATION 6
  1138. #define FILE_EA_INFORMATION 7
  1139. #define FILE_ACCESS_INFORMATION 8
  1140. #define FILE_NAME_INFORMATION 9
  1141. #define FILE_RENAME_INFORMATION 10
  1142. #define FILE_LINK_INFORMATION 11
  1143. #define FILE_NAMES_INFORMATION 12
  1144. #define FILE_DISPOSITION_INFORMATION 13
  1145. #define FILE_POSITION_INFORMATION 14
  1146. #define FILE_FULL_EA_INFORMATION 15
  1147. #define FILE_MODE_INFORMATION 16
  1148. #define FILE_ALIGNMENT_INFORMATION 17
  1149. #define FILE_ALL_INFORMATION 18
  1150. #define FILE_ALLOCATION_INFORMATION 19
  1151. #define FILE_END_OF_FILE_INFORMATION 20
  1152. #define FILE_ALTERNATE_NAME_INFORMATION 21
  1153. #define FILE_STREAM_INFORMATION 22
  1154. #define FILE_PIPE_INFORMATION 23
  1155. #define FILE_PIPE_LOCAL_INFORMATION 24
  1156. #define FILE_PIPE_REMOTE_INFORMATION 25
  1157. #define FILE_MAILSLOT_QUERY_INFORMATION 26
  1158. #define FILE_MAILSLOT_SET_INFORMATION 27
  1159. #define FILE_COMPRESSION_INFORMATION 28
  1160. #define FILE_OBJECT_ID_INFORMATION 29
  1161. /* Number 30 not defined in documents */
  1162. #define FILE_MOVE_CLUSTER_INFORMATION 31
  1163. #define FILE_QUOTA_INFORMATION 32
  1164. #define FILE_REPARSE_POINT_INFORMATION 33
  1165. #define FILE_NETWORK_OPEN_INFORMATION 34
  1166. #define FILE_ATTRIBUTE_TAG_INFORMATION 35
  1167. #define FILE_TRACKING_INFORMATION 36
  1168. #define FILEID_BOTH_DIRECTORY_INFORMATION 37
  1169. #define FILEID_FULL_DIRECTORY_INFORMATION 38
  1170. #define FILE_VALID_DATA_LENGTH_INFORMATION 39
  1171. #define FILE_SHORT_NAME_INFORMATION 40
  1172. #define FILE_SFIO_RESERVE_INFORMATION 44
  1173. #define FILE_SFIO_VOLUME_INFORMATION 45
  1174. #define FILE_HARD_LINK_INFORMATION 46
  1175. #define FILE_NORMALIZED_NAME_INFORMATION 48
  1176. #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
  1177. #define FILE_STANDARD_LINK_INFORMATION 54
  1178. struct smb2_file_internal_info {
  1179. __le64 IndexNumber;
  1180. } __packed; /* level 6 Query */
  1181. struct smb2_file_rename_info { /* encoding of request for level 10 */
  1182. __u8 ReplaceIfExists; /* 1 = replace existing target with new */
  1183. /* 0 = fail if target already exists */
  1184. __u8 Reserved[7];
  1185. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1186. __le32 FileNameLength;
  1187. char FileName[0]; /* New name to be assigned */
  1188. } __packed; /* level 10 Set */
  1189. struct smb2_file_link_info { /* encoding of request for level 11 */
  1190. __u8 ReplaceIfExists; /* 1 = replace existing link with new */
  1191. /* 0 = fail if link already exists */
  1192. __u8 Reserved[7];
  1193. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1194. __le32 FileNameLength;
  1195. char FileName[0]; /* Name to be assigned to new link */
  1196. } __packed; /* level 11 Set */
  1197. #define SMB2_MIN_EA_BUF 2048
  1198. #define SMB2_MAX_EA_BUF 65536
  1199. struct smb2_file_full_ea_info { /* encoding of response for level 15 */
  1200. __le32 next_entry_offset;
  1201. __u8 flags;
  1202. __u8 ea_name_length;
  1203. __le16 ea_value_length;
  1204. char ea_data[0]; /* \0 terminated name plus value */
  1205. } __packed; /* level 15 Set */
  1206. /*
  1207. * This level 18, although with struct with same name is different from cifs
  1208. * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
  1209. * CurrentByteOffset.
  1210. */
  1211. struct smb2_file_all_info { /* data block encoding of response to level 18 */
  1212. __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
  1213. __le64 LastAccessTime;
  1214. __le64 LastWriteTime;
  1215. __le64 ChangeTime;
  1216. __le32 Attributes;
  1217. __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
  1218. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  1219. __le64 EndOfFile; /* size ie offset to first free byte in file */
  1220. __le32 NumberOfLinks; /* hard links */
  1221. __u8 DeletePending;
  1222. __u8 Directory;
  1223. __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
  1224. __le64 IndexNumber;
  1225. __le32 EASize;
  1226. __le32 AccessFlags;
  1227. __le64 CurrentByteOffset;
  1228. __le32 Mode;
  1229. __le32 AlignmentRequirement;
  1230. __le32 FileNameLength;
  1231. char FileName[1];
  1232. } __packed; /* level 18 Query */
  1233. struct smb2_file_eof_info { /* encoding of request for level 10 */
  1234. __le64 EndOfFile; /* new end of file value */
  1235. } __packed; /* level 20 Set */
  1236. extern char smb2_padding[7];
  1237. #endif /* _SMB2PDU_H */