smb2pdu.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  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. /* 4 len + 52 transform hdr + 64 hdr + 56 create rsp */
  80. #define MAX_SMB2_HDR_SIZE 0x00b0
  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. /* Flag (SMB3 open response) values */
  545. #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
  546. /*
  547. * Maximum number of iovs we need for an open/create request.
  548. * [0] : struct smb2_create_req
  549. * [1] : path
  550. * [2] : lease context
  551. * [3] : durable context
  552. * [4] : posix context
  553. * [5] : time warp context
  554. * [6] : compound padding
  555. */
  556. #define SMB2_CREATE_IOV_SIZE 7
  557. struct smb2_create_req {
  558. struct smb2_sync_hdr sync_hdr;
  559. __le16 StructureSize; /* Must be 57 */
  560. __u8 SecurityFlags;
  561. __u8 RequestedOplockLevel;
  562. __le32 ImpersonationLevel;
  563. __le64 SmbCreateFlags;
  564. __le64 Reserved;
  565. __le32 DesiredAccess;
  566. __le32 FileAttributes;
  567. __le32 ShareAccess;
  568. __le32 CreateDisposition;
  569. __le32 CreateOptions;
  570. __le16 NameOffset;
  571. __le16 NameLength;
  572. __le32 CreateContextsOffset;
  573. __le32 CreateContextsLength;
  574. __u8 Buffer[0];
  575. } __packed;
  576. struct smb2_create_rsp {
  577. struct smb2_sync_hdr sync_hdr;
  578. __le16 StructureSize; /* Must be 89 */
  579. __u8 OplockLevel;
  580. __u8 Flag; /* 0x01 if reparse point */
  581. __le32 CreateAction;
  582. __le64 CreationTime;
  583. __le64 LastAccessTime;
  584. __le64 LastWriteTime;
  585. __le64 ChangeTime;
  586. __le64 AllocationSize;
  587. __le64 EndofFile;
  588. __le32 FileAttributes;
  589. __le32 Reserved2;
  590. __u64 PersistentFileId; /* opaque endianness */
  591. __u64 VolatileFileId; /* opaque endianness */
  592. __le32 CreateContextsOffset;
  593. __le32 CreateContextsLength;
  594. __u8 Buffer[1];
  595. } __packed;
  596. struct create_context {
  597. __le32 Next;
  598. __le16 NameOffset;
  599. __le16 NameLength;
  600. __le16 Reserved;
  601. __le16 DataOffset;
  602. __le32 DataLength;
  603. __u8 Buffer[0];
  604. } __packed;
  605. #define SMB2_LEASE_READ_CACHING_HE 0x01
  606. #define SMB2_LEASE_HANDLE_CACHING_HE 0x02
  607. #define SMB2_LEASE_WRITE_CACHING_HE 0x04
  608. #define SMB2_LEASE_NONE cpu_to_le32(0x00)
  609. #define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
  610. #define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
  611. #define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
  612. #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
  613. #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
  614. #define SMB2_LEASE_KEY_SIZE 16
  615. struct lease_context {
  616. u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  617. __le32 LeaseState;
  618. __le32 LeaseFlags;
  619. __le64 LeaseDuration;
  620. } __packed;
  621. struct lease_context_v2 {
  622. u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  623. __le32 LeaseState;
  624. __le32 LeaseFlags;
  625. __le64 LeaseDuration;
  626. __le64 ParentLeaseKeyLow;
  627. __le64 ParentLeaseKeyHigh;
  628. __le16 Epoch;
  629. __le16 Reserved;
  630. } __packed;
  631. struct create_lease {
  632. struct create_context ccontext;
  633. __u8 Name[8];
  634. struct lease_context lcontext;
  635. } __packed;
  636. struct create_lease_v2 {
  637. struct create_context ccontext;
  638. __u8 Name[8];
  639. struct lease_context_v2 lcontext;
  640. __u8 Pad[4];
  641. } __packed;
  642. struct create_durable {
  643. struct create_context ccontext;
  644. __u8 Name[8];
  645. union {
  646. __u8 Reserved[16];
  647. struct {
  648. __u64 PersistentFileId;
  649. __u64 VolatileFileId;
  650. } Fid;
  651. } Data;
  652. } __packed;
  653. struct create_posix {
  654. struct create_context ccontext;
  655. __u8 Name[16];
  656. __le32 Mode;
  657. __u32 Reserved;
  658. } __packed;
  659. /* See MS-SMB2 2.2.13.2.11 */
  660. /* Flags */
  661. #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
  662. struct durable_context_v2 {
  663. __le32 Timeout;
  664. __le32 Flags;
  665. __u64 Reserved;
  666. __u8 CreateGuid[16];
  667. } __packed;
  668. struct create_durable_v2 {
  669. struct create_context ccontext;
  670. __u8 Name[8];
  671. struct durable_context_v2 dcontext;
  672. } __packed;
  673. /* See MS-SMB2 2.2.13.2.12 */
  674. struct durable_reconnect_context_v2 {
  675. struct {
  676. __u64 PersistentFileId;
  677. __u64 VolatileFileId;
  678. } Fid;
  679. __u8 CreateGuid[16];
  680. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  681. } __packed;
  682. /* See MS-SMB2 2.2.14.2.12 */
  683. struct durable_reconnect_context_v2_rsp {
  684. __le32 Timeout;
  685. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  686. } __packed;
  687. struct create_durable_handle_reconnect_v2 {
  688. struct create_context ccontext;
  689. __u8 Name[8];
  690. struct durable_reconnect_context_v2 dcontext;
  691. } __packed;
  692. /* See MS-SMB2 2.2.13.2.5 */
  693. struct crt_twarp_ctxt {
  694. struct create_context ccontext;
  695. __u8 Name[8];
  696. __le64 Timestamp;
  697. } __packed;
  698. #define COPY_CHUNK_RES_KEY_SIZE 24
  699. struct resume_key_req {
  700. char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
  701. __le32 ContextLength; /* MBZ */
  702. char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
  703. } __packed;
  704. /* this goes in the ioctl buffer when doing a copychunk request */
  705. struct copychunk_ioctl {
  706. char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
  707. __le32 ChunkCount; /* we are only sending 1 */
  708. __le32 Reserved;
  709. /* array will only be one chunk long for us */
  710. __le64 SourceOffset;
  711. __le64 TargetOffset;
  712. __le32 Length; /* how many bytes to copy */
  713. __u32 Reserved2;
  714. } __packed;
  715. /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
  716. struct file_zero_data_information {
  717. __le64 FileOffset;
  718. __le64 BeyondFinalZero;
  719. } __packed;
  720. struct copychunk_ioctl_rsp {
  721. __le32 ChunksWritten;
  722. __le32 ChunkBytesWritten;
  723. __le32 TotalBytesWritten;
  724. } __packed;
  725. struct fsctl_set_integrity_information_req {
  726. __le16 ChecksumAlgorithm;
  727. __le16 Reserved;
  728. __le32 Flags;
  729. } __packed;
  730. struct fsctl_get_integrity_information_rsp {
  731. __le16 ChecksumAlgorithm;
  732. __le16 Reserved;
  733. __le32 Flags;
  734. __le32 ChecksumChunkSizeInBytes;
  735. __le32 ClusterSizeInBytes;
  736. } __packed;
  737. /* Integrity ChecksumAlgorithm choices for above */
  738. #define CHECKSUM_TYPE_NONE 0x0000
  739. #define CHECKSUM_TYPE_CRC64 0x0002
  740. #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
  741. /* Integrity flags for above */
  742. #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
  743. /* Reparse structures - see MS-FSCC 2.1.2 */
  744. /* struct fsctl_reparse_info_req is empty, only response structs (see below) */
  745. struct reparse_data_buffer {
  746. __le32 ReparseTag;
  747. __le16 ReparseDataLength;
  748. __u16 Reserved;
  749. __u8 DataBuffer[0]; /* Variable Length */
  750. } __packed;
  751. struct reparse_guid_data_buffer {
  752. __le32 ReparseTag;
  753. __le16 ReparseDataLength;
  754. __u16 Reserved;
  755. __u8 ReparseGuid[16];
  756. __u8 DataBuffer[0]; /* Variable Length */
  757. } __packed;
  758. struct reparse_mount_point_data_buffer {
  759. __le32 ReparseTag;
  760. __le16 ReparseDataLength;
  761. __u16 Reserved;
  762. __le16 SubstituteNameOffset;
  763. __le16 SubstituteNameLength;
  764. __le16 PrintNameOffset;
  765. __le16 PrintNameLength;
  766. __u8 PathBuffer[0]; /* Variable Length */
  767. } __packed;
  768. /* See MS-FSCC 2.1.2.4 and cifspdu.h for struct reparse_symlink_data */
  769. /* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
  770. /* See MS-DFSC 2.2.2 */
  771. struct fsctl_get_dfs_referral_req {
  772. __le16 MaxReferralLevel;
  773. __u8 RequestFileName[];
  774. } __packed;
  775. /* DFS response is struct get_dfs_refer_rsp */
  776. /* See MS-SMB2 2.2.31.3 */
  777. struct network_resiliency_req {
  778. __le32 Timeout;
  779. __le32 Reserved;
  780. } __packed;
  781. /* There is no buffer for the response ie no struct network_resiliency_rsp */
  782. struct validate_negotiate_info_req {
  783. __le32 Capabilities;
  784. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  785. __le16 SecurityMode;
  786. __le16 DialectCount;
  787. __le16 Dialects[3]; /* BB expand this if autonegotiate > 3 dialects */
  788. } __packed;
  789. struct validate_negotiate_info_rsp {
  790. __le32 Capabilities;
  791. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  792. __le16 SecurityMode;
  793. __le16 Dialect; /* Dialect in use for the connection */
  794. } __packed;
  795. #define RSS_CAPABLE cpu_to_le32(0x00000001)
  796. #define RDMA_CAPABLE cpu_to_le32(0x00000002)
  797. #define INTERNETWORK cpu_to_le16(0x0002)
  798. #define INTERNETWORKV6 cpu_to_le16(0x0017)
  799. struct network_interface_info_ioctl_rsp {
  800. __le32 Next; /* next interface. zero if this is last one */
  801. __le32 IfIndex;
  802. __le32 Capability; /* RSS or RDMA Capable */
  803. __le32 Reserved;
  804. __le64 LinkSpeed;
  805. __le16 Family;
  806. __u8 Buffer[126];
  807. } __packed;
  808. struct iface_info_ipv4 {
  809. __be16 Port;
  810. __be32 IPv4Address;
  811. __be64 Reserved;
  812. } __packed;
  813. struct iface_info_ipv6 {
  814. __be16 Port;
  815. __be32 FlowInfo;
  816. __u8 IPv6Address[16];
  817. __be32 ScopeId;
  818. } __packed;
  819. #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
  820. struct compress_ioctl {
  821. __le16 CompressionState; /* See cifspdu.h for possible flag values */
  822. } __packed;
  823. struct duplicate_extents_to_file {
  824. __u64 PersistentFileHandle; /* source file handle, opaque endianness */
  825. __u64 VolatileFileHandle;
  826. __le64 SourceFileOffset;
  827. __le64 TargetFileOffset;
  828. __le64 ByteCount; /* Bytes to be copied */
  829. } __packed;
  830. struct smb2_ioctl_req {
  831. struct smb2_sync_hdr sync_hdr;
  832. __le16 StructureSize; /* Must be 57 */
  833. __u16 Reserved;
  834. __le32 CtlCode;
  835. __u64 PersistentFileId; /* opaque endianness */
  836. __u64 VolatileFileId; /* opaque endianness */
  837. __le32 InputOffset;
  838. __le32 InputCount;
  839. __le32 MaxInputResponse;
  840. __le32 OutputOffset;
  841. __le32 OutputCount;
  842. __le32 MaxOutputResponse;
  843. __le32 Flags;
  844. __u32 Reserved2;
  845. __u8 Buffer[0];
  846. } __packed;
  847. struct smb2_ioctl_rsp {
  848. struct smb2_sync_hdr sync_hdr;
  849. __le16 StructureSize; /* Must be 57 */
  850. __u16 Reserved;
  851. __le32 CtlCode;
  852. __u64 PersistentFileId; /* opaque endianness */
  853. __u64 VolatileFileId; /* opaque endianness */
  854. __le32 InputOffset;
  855. __le32 InputCount;
  856. __le32 OutputOffset;
  857. __le32 OutputCount;
  858. __le32 Flags;
  859. __u32 Reserved2;
  860. /* char * buffer[] */
  861. } __packed;
  862. /* Currently defined values for close flags */
  863. #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
  864. struct smb2_close_req {
  865. struct smb2_sync_hdr sync_hdr;
  866. __le16 StructureSize; /* Must be 24 */
  867. __le16 Flags;
  868. __le32 Reserved;
  869. __u64 PersistentFileId; /* opaque endianness */
  870. __u64 VolatileFileId; /* opaque endianness */
  871. } __packed;
  872. struct smb2_close_rsp {
  873. struct smb2_sync_hdr sync_hdr;
  874. __le16 StructureSize; /* 60 */
  875. __le16 Flags;
  876. __le32 Reserved;
  877. __le64 CreationTime;
  878. __le64 LastAccessTime;
  879. __le64 LastWriteTime;
  880. __le64 ChangeTime;
  881. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  882. __le64 EndOfFile;
  883. __le32 Attributes;
  884. } __packed;
  885. struct smb2_flush_req {
  886. struct smb2_sync_hdr sync_hdr;
  887. __le16 StructureSize; /* Must be 24 */
  888. __le16 Reserved1;
  889. __le32 Reserved2;
  890. __u64 PersistentFileId; /* opaque endianness */
  891. __u64 VolatileFileId; /* opaque endianness */
  892. } __packed;
  893. struct smb2_flush_rsp {
  894. struct smb2_sync_hdr sync_hdr;
  895. __le16 StructureSize;
  896. __le16 Reserved;
  897. } __packed;
  898. /* For read request Flags field below, following flag is defined for SMB3.02 */
  899. #define SMB2_READFLAG_READ_UNBUFFERED 0x01
  900. /* Channel field for read and write: exactly one of following flags can be set*/
  901. #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
  902. #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
  903. #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
  904. /* SMB2 read request without RFC1001 length at the beginning */
  905. struct smb2_read_plain_req {
  906. struct smb2_sync_hdr sync_hdr;
  907. __le16 StructureSize; /* Must be 49 */
  908. __u8 Padding; /* offset from start of SMB2 header to place read */
  909. __u8 Flags; /* MBZ unless SMB3.02 or later */
  910. __le32 Length;
  911. __le64 Offset;
  912. __u64 PersistentFileId; /* opaque endianness */
  913. __u64 VolatileFileId; /* opaque endianness */
  914. __le32 MinimumCount;
  915. __le32 Channel; /* MBZ except for SMB3 or later */
  916. __le32 RemainingBytes;
  917. __le16 ReadChannelInfoOffset;
  918. __le16 ReadChannelInfoLength;
  919. __u8 Buffer[1];
  920. } __packed;
  921. struct smb2_read_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. /* For write request Flags field below the following flags are defined: */
  932. #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
  933. #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
  934. struct smb2_write_req {
  935. struct smb2_sync_hdr sync_hdr;
  936. __le16 StructureSize; /* Must be 49 */
  937. __le16 DataOffset; /* offset from start of SMB2 header to write data */
  938. __le32 Length;
  939. __le64 Offset;
  940. __u64 PersistentFileId; /* opaque endianness */
  941. __u64 VolatileFileId; /* opaque endianness */
  942. __le32 Channel; /* Reserved MBZ */
  943. __le32 RemainingBytes;
  944. __le16 WriteChannelInfoOffset;
  945. __le16 WriteChannelInfoLength;
  946. __le32 Flags;
  947. __u8 Buffer[1];
  948. } __packed;
  949. struct smb2_write_rsp {
  950. struct smb2_sync_hdr sync_hdr;
  951. __le16 StructureSize; /* Must be 17 */
  952. __u8 DataOffset;
  953. __u8 Reserved;
  954. __le32 DataLength;
  955. __le32 DataRemaining;
  956. __u32 Reserved2;
  957. __u8 Buffer[1];
  958. } __packed;
  959. #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
  960. #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
  961. #define SMB2_LOCKFLAG_UNLOCK 0x0004
  962. #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
  963. struct smb2_lock_element {
  964. __le64 Offset;
  965. __le64 Length;
  966. __le32 Flags;
  967. __le32 Reserved;
  968. } __packed;
  969. struct smb2_lock_req {
  970. struct smb2_sync_hdr sync_hdr;
  971. __le16 StructureSize; /* Must be 48 */
  972. __le16 LockCount;
  973. __le32 Reserved;
  974. __u64 PersistentFileId; /* opaque endianness */
  975. __u64 VolatileFileId; /* opaque endianness */
  976. /* Followed by at least one */
  977. struct smb2_lock_element locks[1];
  978. } __packed;
  979. struct smb2_lock_rsp {
  980. struct smb2_sync_hdr sync_hdr;
  981. __le16 StructureSize; /* Must be 4 */
  982. __le16 Reserved;
  983. } __packed;
  984. struct smb2_echo_req {
  985. struct smb2_sync_hdr sync_hdr;
  986. __le16 StructureSize; /* Must be 4 */
  987. __u16 Reserved;
  988. } __packed;
  989. struct smb2_echo_rsp {
  990. struct smb2_sync_hdr sync_hdr;
  991. __le16 StructureSize; /* Must be 4 */
  992. __u16 Reserved;
  993. } __packed;
  994. /* search (query_directory) Flags field */
  995. #define SMB2_RESTART_SCANS 0x01
  996. #define SMB2_RETURN_SINGLE_ENTRY 0x02
  997. #define SMB2_INDEX_SPECIFIED 0x04
  998. #define SMB2_REOPEN 0x10
  999. struct smb2_query_directory_req {
  1000. struct smb2_sync_hdr sync_hdr;
  1001. __le16 StructureSize; /* Must be 33 */
  1002. __u8 FileInformationClass;
  1003. __u8 Flags;
  1004. __le32 FileIndex;
  1005. __u64 PersistentFileId; /* opaque endianness */
  1006. __u64 VolatileFileId; /* opaque endianness */
  1007. __le16 FileNameOffset;
  1008. __le16 FileNameLength;
  1009. __le32 OutputBufferLength;
  1010. __u8 Buffer[1];
  1011. } __packed;
  1012. struct smb2_query_directory_rsp {
  1013. struct smb2_sync_hdr sync_hdr;
  1014. __le16 StructureSize; /* Must be 9 */
  1015. __le16 OutputBufferOffset;
  1016. __le32 OutputBufferLength;
  1017. __u8 Buffer[1];
  1018. } __packed;
  1019. /* Possible InfoType values */
  1020. #define SMB2_O_INFO_FILE 0x01
  1021. #define SMB2_O_INFO_FILESYSTEM 0x02
  1022. #define SMB2_O_INFO_SECURITY 0x03
  1023. #define SMB2_O_INFO_QUOTA 0x04
  1024. /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
  1025. #define OWNER_SECINFO 0x00000001
  1026. #define GROUP_SECINFO 0x00000002
  1027. #define DACL_SECINFO 0x00000004
  1028. #define SACL_SECINFO 0x00000008
  1029. #define LABEL_SECINFO 0x00000010
  1030. #define ATTRIBUTE_SECINFO 0x00000020
  1031. #define SCOPE_SECINFO 0x00000040
  1032. #define BACKUP_SECINFO 0x00010000
  1033. #define UNPROTECTED_SACL_SECINFO 0x10000000
  1034. #define UNPROTECTED_DACL_SECINFO 0x20000000
  1035. #define PROTECTED_SACL_SECINFO 0x40000000
  1036. #define PROTECTED_DACL_SECINFO 0x80000000
  1037. /* Flags used for FileFullEAinfo */
  1038. #define SL_RESTART_SCAN 0x00000001
  1039. #define SL_RETURN_SINGLE_ENTRY 0x00000002
  1040. #define SL_INDEX_SPECIFIED 0x00000004
  1041. struct smb2_query_info_req {
  1042. struct smb2_sync_hdr sync_hdr;
  1043. __le16 StructureSize; /* Must be 41 */
  1044. __u8 InfoType;
  1045. __u8 FileInfoClass;
  1046. __le32 OutputBufferLength;
  1047. __le16 InputBufferOffset;
  1048. __u16 Reserved;
  1049. __le32 InputBufferLength;
  1050. __le32 AdditionalInformation;
  1051. __le32 Flags;
  1052. __u64 PersistentFileId; /* opaque endianness */
  1053. __u64 VolatileFileId; /* opaque endianness */
  1054. __u8 Buffer[1];
  1055. } __packed;
  1056. struct smb2_query_info_rsp {
  1057. struct smb2_sync_hdr sync_hdr;
  1058. __le16 StructureSize; /* Must be 9 */
  1059. __le16 OutputBufferOffset;
  1060. __le32 OutputBufferLength;
  1061. __u8 Buffer[1];
  1062. } __packed;
  1063. /*
  1064. * Maximum number of iovs we need for a set-info request.
  1065. * The largest one is rename/hardlink
  1066. * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
  1067. * [1] : path
  1068. * [2] : compound padding
  1069. */
  1070. #define SMB2_SET_INFO_IOV_SIZE 3
  1071. struct smb2_set_info_req {
  1072. struct smb2_sync_hdr sync_hdr;
  1073. __le16 StructureSize; /* Must be 33 */
  1074. __u8 InfoType;
  1075. __u8 FileInfoClass;
  1076. __le32 BufferLength;
  1077. __le16 BufferOffset;
  1078. __u16 Reserved;
  1079. __le32 AdditionalInformation;
  1080. __u64 PersistentFileId; /* opaque endianness */
  1081. __u64 VolatileFileId; /* opaque endianness */
  1082. __u8 Buffer[1];
  1083. } __packed;
  1084. struct smb2_set_info_rsp {
  1085. struct smb2_sync_hdr sync_hdr;
  1086. __le16 StructureSize; /* Must be 2 */
  1087. } __packed;
  1088. struct smb2_oplock_break {
  1089. struct smb2_sync_hdr sync_hdr;
  1090. __le16 StructureSize; /* Must be 24 */
  1091. __u8 OplockLevel;
  1092. __u8 Reserved;
  1093. __le32 Reserved2;
  1094. __u64 PersistentFid;
  1095. __u64 VolatileFid;
  1096. } __packed;
  1097. #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
  1098. struct smb2_lease_break {
  1099. struct smb2_sync_hdr sync_hdr;
  1100. __le16 StructureSize; /* Must be 44 */
  1101. __le16 Reserved;
  1102. __le32 Flags;
  1103. __u8 LeaseKey[16];
  1104. __le32 CurrentLeaseState;
  1105. __le32 NewLeaseState;
  1106. __le32 BreakReason;
  1107. __le32 AccessMaskHint;
  1108. __le32 ShareMaskHint;
  1109. } __packed;
  1110. struct smb2_lease_ack {
  1111. struct smb2_sync_hdr sync_hdr;
  1112. __le16 StructureSize; /* Must be 36 */
  1113. __le16 Reserved;
  1114. __le32 Flags;
  1115. __u8 LeaseKey[16];
  1116. __le32 LeaseState;
  1117. __le64 LeaseDuration;
  1118. } __packed;
  1119. /*
  1120. * PDU infolevel structure definitions
  1121. * BB consider moving to a different header
  1122. */
  1123. /* File System Information Classes */
  1124. #define FS_VOLUME_INFORMATION 1 /* Query */
  1125. #define FS_LABEL_INFORMATION 2 /* Local only */
  1126. #define FS_SIZE_INFORMATION 3 /* Query */
  1127. #define FS_DEVICE_INFORMATION 4 /* Query */
  1128. #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
  1129. #define FS_CONTROL_INFORMATION 6 /* Query, Set */
  1130. #define FS_FULL_SIZE_INFORMATION 7 /* Query */
  1131. #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
  1132. #define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
  1133. #define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
  1134. #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
  1135. #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
  1136. struct smb2_fs_full_size_info {
  1137. __le64 TotalAllocationUnits;
  1138. __le64 CallerAvailableAllocationUnits;
  1139. __le64 ActualAvailableAllocationUnits;
  1140. __le32 SectorsPerAllocationUnit;
  1141. __le32 BytesPerSector;
  1142. } __packed;
  1143. #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
  1144. #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
  1145. #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
  1146. #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
  1147. /* sector size info struct */
  1148. struct smb3_fs_ss_info {
  1149. __le32 LogicalBytesPerSector;
  1150. __le32 PhysicalBytesPerSectorForAtomicity;
  1151. __le32 PhysicalBytesPerSectorForPerf;
  1152. __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
  1153. __le32 Flags;
  1154. __le32 ByteOffsetForSectorAlignment;
  1155. __le32 ByteOffsetForPartitionAlignment;
  1156. } __packed;
  1157. /* volume info struct - see MS-FSCC 2.5.9 */
  1158. #define MAX_VOL_LABEL_LEN 32
  1159. struct smb3_fs_vol_info {
  1160. __le64 VolumeCreationTime;
  1161. __u32 VolumeSerialNumber;
  1162. __le32 VolumeLabelLength; /* includes trailing null */
  1163. __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
  1164. __u8 Reserved;
  1165. __u8 VolumeLabel[0]; /* variable len */
  1166. } __packed;
  1167. /* partial list of QUERY INFO levels */
  1168. #define FILE_DIRECTORY_INFORMATION 1
  1169. #define FILE_FULL_DIRECTORY_INFORMATION 2
  1170. #define FILE_BOTH_DIRECTORY_INFORMATION 3
  1171. #define FILE_BASIC_INFORMATION 4
  1172. #define FILE_STANDARD_INFORMATION 5
  1173. #define FILE_INTERNAL_INFORMATION 6
  1174. #define FILE_EA_INFORMATION 7
  1175. #define FILE_ACCESS_INFORMATION 8
  1176. #define FILE_NAME_INFORMATION 9
  1177. #define FILE_RENAME_INFORMATION 10
  1178. #define FILE_LINK_INFORMATION 11
  1179. #define FILE_NAMES_INFORMATION 12
  1180. #define FILE_DISPOSITION_INFORMATION 13
  1181. #define FILE_POSITION_INFORMATION 14
  1182. #define FILE_FULL_EA_INFORMATION 15
  1183. #define FILE_MODE_INFORMATION 16
  1184. #define FILE_ALIGNMENT_INFORMATION 17
  1185. #define FILE_ALL_INFORMATION 18
  1186. #define FILE_ALLOCATION_INFORMATION 19
  1187. #define FILE_END_OF_FILE_INFORMATION 20
  1188. #define FILE_ALTERNATE_NAME_INFORMATION 21
  1189. #define FILE_STREAM_INFORMATION 22
  1190. #define FILE_PIPE_INFORMATION 23
  1191. #define FILE_PIPE_LOCAL_INFORMATION 24
  1192. #define FILE_PIPE_REMOTE_INFORMATION 25
  1193. #define FILE_MAILSLOT_QUERY_INFORMATION 26
  1194. #define FILE_MAILSLOT_SET_INFORMATION 27
  1195. #define FILE_COMPRESSION_INFORMATION 28
  1196. #define FILE_OBJECT_ID_INFORMATION 29
  1197. /* Number 30 not defined in documents */
  1198. #define FILE_MOVE_CLUSTER_INFORMATION 31
  1199. #define FILE_QUOTA_INFORMATION 32
  1200. #define FILE_REPARSE_POINT_INFORMATION 33
  1201. #define FILE_NETWORK_OPEN_INFORMATION 34
  1202. #define FILE_ATTRIBUTE_TAG_INFORMATION 35
  1203. #define FILE_TRACKING_INFORMATION 36
  1204. #define FILEID_BOTH_DIRECTORY_INFORMATION 37
  1205. #define FILEID_FULL_DIRECTORY_INFORMATION 38
  1206. #define FILE_VALID_DATA_LENGTH_INFORMATION 39
  1207. #define FILE_SHORT_NAME_INFORMATION 40
  1208. #define FILE_SFIO_RESERVE_INFORMATION 44
  1209. #define FILE_SFIO_VOLUME_INFORMATION 45
  1210. #define FILE_HARD_LINK_INFORMATION 46
  1211. #define FILE_NORMALIZED_NAME_INFORMATION 48
  1212. #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
  1213. #define FILE_STANDARD_LINK_INFORMATION 54
  1214. struct smb2_file_internal_info {
  1215. __le64 IndexNumber;
  1216. } __packed; /* level 6 Query */
  1217. struct smb2_file_rename_info { /* encoding of request for level 10 */
  1218. __u8 ReplaceIfExists; /* 1 = replace existing target with new */
  1219. /* 0 = fail if target already exists */
  1220. __u8 Reserved[7];
  1221. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1222. __le32 FileNameLength;
  1223. char FileName[0]; /* New name to be assigned */
  1224. } __packed; /* level 10 Set */
  1225. struct smb2_file_link_info { /* encoding of request for level 11 */
  1226. __u8 ReplaceIfExists; /* 1 = replace existing link with new */
  1227. /* 0 = fail if link already exists */
  1228. __u8 Reserved[7];
  1229. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1230. __le32 FileNameLength;
  1231. char FileName[0]; /* Name to be assigned to new link */
  1232. } __packed; /* level 11 Set */
  1233. #define SMB2_MIN_EA_BUF 2048
  1234. #define SMB2_MAX_EA_BUF 65536
  1235. struct smb2_file_full_ea_info { /* encoding of response for level 15 */
  1236. __le32 next_entry_offset;
  1237. __u8 flags;
  1238. __u8 ea_name_length;
  1239. __le16 ea_value_length;
  1240. char ea_data[0]; /* \0 terminated name plus value */
  1241. } __packed; /* level 15 Set */
  1242. /*
  1243. * This level 18, although with struct with same name is different from cifs
  1244. * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
  1245. * CurrentByteOffset.
  1246. */
  1247. struct smb2_file_all_info { /* data block encoding of response to level 18 */
  1248. __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
  1249. __le64 LastAccessTime;
  1250. __le64 LastWriteTime;
  1251. __le64 ChangeTime;
  1252. __le32 Attributes;
  1253. __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
  1254. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  1255. __le64 EndOfFile; /* size ie offset to first free byte in file */
  1256. __le32 NumberOfLinks; /* hard links */
  1257. __u8 DeletePending;
  1258. __u8 Directory;
  1259. __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
  1260. __le64 IndexNumber;
  1261. __le32 EASize;
  1262. __le32 AccessFlags;
  1263. __le64 CurrentByteOffset;
  1264. __le32 Mode;
  1265. __le32 AlignmentRequirement;
  1266. __le32 FileNameLength;
  1267. char FileName[1];
  1268. } __packed; /* level 18 Query */
  1269. struct smb2_file_eof_info { /* encoding of request for level 10 */
  1270. __le64 EndOfFile; /* new end of file value */
  1271. } __packed; /* level 20 Set */
  1272. extern char smb2_padding[7];
  1273. #endif /* _SMB2PDU_H */