Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

813 lines
30 KiB

  1. /*++
  2. Copyright (c) 1987-1999 Microsoft Corporation
  3. Module Name:
  4. smbcxchng.h
  5. Abstract:
  6. This is the include file that defines all constants and types for
  7. SMB exchange implementation.
  8. Notes:
  9. An exchange is the core abstarction on which the SMB connection engine and
  10. the mini RDR are implemented. It encapsulates the notion of sending an SMB to
  11. the server and receiving the associated response, i.e, exchanging an SMB and
  12. hence the name.
  13. The exchange of an SMB with the server involves the following steps ....
  14. 1) Submitting the formatted SMB buffer for transmission.
  15. 2) Processing a send complete indication which ensures that at the
  16. transport level the SMB has been sent to the server.
  17. 3) Processing the receive indication which contains all/part of the
  18. response sent by the server.
  19. 4) Copying additional data not indicated by the transport
  20. There are a number of variations on this theme. For example there are certain
  21. SMB's for which no response is expected, e.g., certain SMB's which are
  22. inherently multi part in nature, TRANSACT smb's.
  23. In addition the steps outlined above will not always happen in that order. The
  24. precise sequence of events is dictated by the underlying transport chosen and
  25. the network conditions. It is this dependency that makes the implementation
  26. of exchanges challenging.
  27. The two primary goals that the current implementation was designed for are (1)
  28. performance and (2) encapsulation of transport dependencies. Goal(1) is
  29. important because this constitutes an integral part of the code path for
  30. exchanging any packet with the server. Goal (2) is important to ensure
  31. customization of the Rdr for different transports. This encapsulation provides
  32. a convenient vehicle for isolating SMB protocol level decisions from transport
  33. level decisons as much as possible.
  34. In addition the following goals were used to guide the implementation process ...
  35. 1) The exchange implementation must be able to handle asynchronous
  36. operations and synchronous operations well. The trade offs were made in
  37. favour of asynchronous operations as and when required.
  38. 2) Sufficient infrastructure support must be provided so as to ease the
  39. implementation of different flavours of exchanges.
  40. The SMB_EXCHANGE consists of a dispatch vector with the following functions
  41. 1) Start -- to initiate the exchange
  42. 2) Receive -- to handle response indications from the server
  43. 3) CopyDataHandler -- to handle portions of the response not indicated
  44. 4) SendCompletionHandler -- to handle send complete indications from the transport.
  45. 5) QuiescentStateHandler -- to handle transitions to a quiescent state, i.e., no
  46. SMB connection engine operations are outstanding.
  47. Most kinds of exchange use the QuiescentStateHandler to finalize the
  48. operation and discard the exchange. However, certain kinds of exchanges
  49. which implement the notion of a macro exchange, i.e., exchange multiple
  50. SMB's use this to delineate different phases of the multiple exchange,
  51. e.g., ORDINARY_EXCHANGE which implements most file io operations.
  52. In addition to the dispatch vector the vanilla exchange consists of state
  53. information to record the current state of the exchange, sufficient context
  54. for resumption and context for handling SMB protocol related operations. The
  55. SMB protocol requires that each SMB sent to the server be stamped with a MID
  56. ( multiplex id. ) in order to distinguish between concurrent SMB exchanges.
  57. The connection engine provides this service.
  58. The exchange also encapsulates a SMBCE_EXCHANGE_CONTEXT instance which
  59. encapsulates all the information required for building a SMB_HEADER.
  60. --*/
  61. #ifndef _SMBXCHNG_H_
  62. #define _SMBXCHNG_H_
  63. typedef enum _SMBCE_STATE_ {
  64. SMBCE_START_IN_PROGRESS,
  65. SMBCE_STARTED,
  66. SMBCE_STOP_IN_PROGRESS,
  67. SMBCE_STOPPED
  68. } SMBCE_STATE, *PSMBCE_STATE;
  69. typedef struct _SMBCE_STARTSTOP_CONTEXT_ {
  70. SMBCE_STATE State;
  71. LONG ActiveExchanges;
  72. KEVENT StopEvent;
  73. PKEVENT pServerEntryTearDownEvent;
  74. LIST_ENTRY SessionSetupRequests;
  75. } SMBCE_STARTSTOP_CONTEXT, *PSMBCE_STARTSTOP_CONTEXT;
  76. extern SMBCE_STARTSTOP_CONTEXT SmbCeStartStopContext;
  77. //
  78. // SMB_PROTOCOL_EXCHANGE dispatch vector function prototypes ..
  79. //
  80. // the initiator or the start routine
  81. typedef
  82. NTSTATUS
  83. (*PSMB_EXCHANGE_START)(
  84. IN struct _SMB_EXCHANGE *pExchange);
  85. // The SMB receive handler
  86. typedef
  87. NTSTATUS
  88. (*PSMB_EXCHANGE_IND_RECEIVE)(
  89. IN struct _SMB_EXCHANGE *pExchange, // The exchange instance
  90. IN ULONG BytesIndicated,
  91. IN ULONG BytesAvailable,
  92. OUT ULONG *BytesTaken,
  93. IN PSMB_HEADER pSmbHeader,
  94. OUT PMDL *pDataBufferPointer, // buffer to copy unindicated data
  95. OUT PULONG pDataSize, // buffer size
  96. IN ULONG ReceiveFlags
  97. );
  98. // the SMB xmit callback
  99. typedef
  100. NTSTATUS
  101. (*PSMB_EXCHANGE_IND_SEND_CALLBACK)(
  102. IN struct _SMB_EXCHANGE *pExchange, // The exchange instance
  103. IN PMDL pDataBuffer,
  104. IN NTSTATUS SendCompletionStatus
  105. );
  106. // the copy data callback for fetching large data
  107. typedef
  108. NTSTATUS
  109. (*PSMB_EXCHANGE_IND_COPY_DATA_CALLBACK)(
  110. IN struct _SMB_EXCHANGE *pExchange, // the exchange instance
  111. IN PMDL pCopyDataBuffer, // the buffer
  112. IN ULONG CopyDataSize // amount of data copied
  113. );
  114. // the finalization routine
  115. // This particular routine has a signature that is NT specific the IRQL
  116. // parameter that is passed in and the notion of posting. This helps consolidate
  117. // the NT transport driver model of indications at DPC level in SmbCeFinalizeExchange.
  118. // On WIN95 the lease restrictive value of IRQL can be passed in.
  119. typedef
  120. NTSTATUS
  121. (*PSMB_EXCHANGE_FINALIZE)(
  122. IN OUT struct _SMB_EXCHANGE *pExchange,
  123. OUT BOOLEAN *pPostRequest);
  124. typedef
  125. NTSTATUS
  126. (*PSMB_EXCHANGE_IND_ASSOCIATED_EXCHANGES_COMPLETION)(
  127. IN OUT struct _SMB_EXCHANGE *pExchange,
  128. OUT BOOLEAN *pPostRequest);
  129. // The Exchange dispatch vector definition
  130. typedef struct _SMB_EXCHANGE_DISPATCH_VECTOR_ {
  131. PSMB_EXCHANGE_START Start;
  132. PSMB_EXCHANGE_IND_RECEIVE Receive;
  133. PSMB_EXCHANGE_IND_COPY_DATA_CALLBACK CopyDataHandler;
  134. PSMB_EXCHANGE_IND_SEND_CALLBACK SendCompletionHandler;
  135. PSMB_EXCHANGE_FINALIZE Finalize;
  136. PSMB_EXCHANGE_IND_ASSOCIATED_EXCHANGES_COMPLETION AssociatedExchangesCompletionHandler;
  137. } SMB_EXCHANGE_DISPATCH_VECTOR, *PSMB_EXCHANGE_DISPATCH_VECTOR;
  138. // An enumerated type listing the type of exchanges
  139. typedef enum _SMB_EXCHANGE_TYPE_ {
  140. CONSTRUCT_NETROOT_EXCHANGE,
  141. ORDINARY_EXCHANGE,
  142. TRANSACT_EXCHANGE,
  143. ADMIN_EXCHANGE,
  144. SENTINEL_EXCHANGE
  145. } SMB_EXCHANGE_TYPE, *PSMB_EXCHANGE_TYPE;
  146. // known exchange type dispatch vectors
  147. extern SMB_EXCHANGE_DISPATCH_VECTOR ConstructNetRootExchangeDispatch;
  148. extern SMB_EXCHANGE_DISPATCH_VECTOR OrdinaryExchangeDispatch;
  149. extern SMB_EXCHANGE_DISPATCH_VECTOR TransactExchangeDispatch;
  150. // The various states of the exchange. Each exchange transitions from
  151. // the SMBCE_EXCHANGE_INITIALIZATION_START to SMBCE_EXCHANGE_INITIATED or
  152. // SMBCE_EXCHANGE_ABORTED state.
  153. typedef enum _SMBCE_EXCHANGE_STATE_ {
  154. SMBCE_EXCHANGE_INITIALIZATION_START,
  155. SMBCE_EXCHANGE_SERVER_INITIALIZED,
  156. SMBCE_EXCHANGE_SESSION_INITIALIZED,
  157. SMBCE_EXCHANGE_NETROOT_INITIALIZED,
  158. SMBCE_EXCHANGE_INITIATED,
  159. SMBCE_EXCHANGE_ABORTED
  160. } SMBCE_EXCHANGE_STATE, *PSMBCE_EXCHANGE_STATE;
  161. // The exchange encapsulates the transport information from the clients. The
  162. // Exchange engine is sandwiched between the protocol selection engine in the
  163. // mini redirector on one side and the various transports on the other side.
  164. // The transport information encapsulates the various categories of transport
  165. // the exchange engine understands.
  166. typedef struct SMBCE_EXCHANGE_TRANSPORT_INFORMATION {
  167. union {
  168. struct {
  169. struct _SMBCE_VC *pVc;
  170. } Vcs;
  171. struct {
  172. ULONG Dummy;
  173. } Datagrams;
  174. struct {
  175. ULONG Dummy;
  176. } Hybrid;
  177. };
  178. } SMBCE_EXCHANGE_TRANSPORT_CONTEXT,
  179. *PSMBCE_EXCHANGE_TRANSPORT_CONTEXT;
  180. typedef struct _SMBCE_EXCHANGE_CONTEXT_ {
  181. PMRX_V_NET_ROOT pVNetRoot;
  182. PSMBCEDB_SERVER_ENTRY pServerEntry;
  183. PSMBCE_V_NET_ROOT_CONTEXT pVNetRootContext;
  184. SMBCE_EXCHANGE_TRANSPORT_CONTEXT TransportContext;
  185. } SMBCE_EXCHANGE_CONTEXT,*PSMBCE_EXCHANGE_CONTEXT;
  186. //
  187. // Similar to the subclassing of SMB net roots the SMB_EXCHANGE will be subclassed
  188. // further to deal with various types of SMB exchanges. SMB exchanges can be roughly
  189. // classified into the following types based on the interactions involved ...
  190. //
  191. // The SMB's that need to be exchanged need to be augmented with some admin SMB's which
  192. // are required for the maintenance of SMB's in the connection engine.
  193. #define SMBCE_EXCHANGE_MID_VALID (0x1)
  194. #define SMBCE_EXCHANGE_REUSE_MID (0x2)
  195. #define SMBCE_EXCHANGE_RETAIN_MID (SMBCE_EXCHANGE_REUSE_MID)
  196. #define SMBCE_EXCHANGE_MULTIPLE_SENDS_POSSIBLE (0x4)
  197. #define SMBCE_EXCHANGE_FINALIZED (0x8)
  198. #define SMBCE_EXCHANGE_ATTEMPT_RECONNECTS (0x10)
  199. #define SMBCE_EXCHANGE_INDEFINITE_DELAY_IN_RESPONSE (0x20)
  200. #define SMBCE_EXCHANGE_MAILSLOT_OPERATION (0x40)
  201. #define SMBCE_EXCHANGE_SESSION_CONSTRUCTOR (0x100)
  202. #define SMBCE_EXCHANGE_NETROOT_CONSTRUCTOR (0x200)
  203. #define SMBCE_EXCHANGE_NOT_FROM_POOL (0x800)
  204. #define SMBCE_EXCHANGE_TIMED_RECEIVE_OPERATION (0x1000)
  205. #define SMBCE_EXCHANGE_TIMEDOUT (0x2000)
  206. #define SMBCE_EXCHANGE_FULL_PROCESSID_SPECIFIED (0x4000)
  207. #define SMBCE_EXCHANGE_SMBCE_STOPPED (0x8000)
  208. #define SMBCE_ASSOCIATED_EXCHANGE (0x80000000)
  209. #define SMBCE_ASSOCIATED_EXCHANGES_COMPLETION_HANDLER_ACTIVATED (0x40000000)
  210. #define SMBCE_EXCHANGE_FLAGS_TO_PRESERVE (SMBCE_EXCHANGE_NOT_FROM_POOL)
  211. #define SMBCE_OPLOCK_RESPONSE_MID (0xffff)
  212. #define SMBCE_MAILSLOT_OPERATION_MID (0xffff)
  213. #define SMBCE_ECHO_PROBE_MID (0xfffe)
  214. //
  215. // The cancellation status is defined as a PVOID instead of a BOOLEAN to allow
  216. // us the use of Interlocked manipulation instructions
  217. // There are only two states SMBCE_EXCHANGE_CANCELLED, SMBCE_EXCHANGE_ACTIVE
  218. //
  219. #define SMBCE_EXCHANGE_CANCELLED (0xcccccccc)
  220. #define SMBCE_EXCHANGE_NOT_CANCELLED (0xaaaaaaaa)
  221. // The Exchange definition
  222. typedef struct _SMB_EXCHANGE {
  223. union {
  224. UCHAR Type;
  225. struct {
  226. NODE_TYPE_CODE NodeTypeCode; // node type.
  227. NODE_BYTE_SIZE NodeByteSize; // node size.
  228. LONG ReferenceCount;
  229. };
  230. };
  231. LIST_ENTRY SmbMmInUseListEntry;
  232. PRX_CONTEXT RxContext; //use of these two fields is advisory
  233. PVOID LastExecutingThread; //OE and Xact will use them
  234. union {
  235. NTSTATUS SmbStatus;
  236. PMRX_SMB_SRV_OPEN SmbSrvOpen;
  237. };
  238. NTSTATUS Status;
  239. ULONG ServerVersion;
  240. SMB_EXCHANGE_ID Id;
  241. USHORT SmbCeState;
  242. USHORT MidCookie;
  243. SMB_MPX_ID Mid;
  244. LONG CancellationStatus;
  245. ULONG SmbCeFlags;
  246. SMBCE_EXCHANGE_CONTEXT SmbCeContext;
  247. LONG SendCompletePendingOperations;
  248. LONG CopyDataPendingOperations;
  249. LONG ReceivePendingOperations;
  250. LONG LocalPendingOperations;
  251. PKEVENT pSmbCeSynchronizationEvent;
  252. LIST_ENTRY ExchangeList;
  253. LARGE_INTEGER ExpiryTime;
  254. PSMB_EXCHANGE_DISPATCH_VECTOR pDispatchVector;
  255. union {
  256. struct {
  257. struct _SMB_EXCHANGE *pMasterExchange;
  258. SINGLE_LIST_ENTRY NextAssociatedExchange;
  259. } Associated;
  260. struct {
  261. SINGLE_LIST_ENTRY AssociatedExchangesToBeFinalized;
  262. LONG PendingAssociatedExchanges;
  263. } Master;
  264. };
  265. RX_WORK_QUEUE_ITEM WorkQueueItem;
  266. ULONG ExchangeTransportInitialized;
  267. NTSTATUS SessionSetupStatus;
  268. } SMB_EXCHANGE, *PSMB_EXCHANGE;
  269. INLINE PSMBCEDB_SERVER_ENTRY
  270. SmbCeGetExchangeServerEntry(PVOID pExchange)
  271. {
  272. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  273. ASSERT(pSmbExchange->SmbCeContext.pServerEntry != NULL);
  274. return pSmbExchange->SmbCeContext.pServerEntry;
  275. }
  276. INLINE PSMBCE_SERVER
  277. SmbCeGetExchangeServer(PVOID pExchange)
  278. {
  279. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  280. return &(pSmbExchange->SmbCeContext.pServerEntry->Server);
  281. }
  282. INLINE PSMBCEDB_SESSION_ENTRY
  283. SmbCeGetExchangeSessionEntry(PVOID pExchange)
  284. {
  285. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  286. if (pSmbExchange->SmbCeContext.pVNetRootContext != NULL) {
  287. return pSmbExchange->SmbCeContext.pVNetRootContext->pSessionEntry;
  288. } else {
  289. return NULL;
  290. }
  291. }
  292. INLINE PSMBCE_SESSION
  293. SmbCeGetExchangeSession(PVOID pExchange)
  294. {
  295. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  296. if (pSmbExchange->SmbCeContext.pVNetRootContext != NULL) {
  297. return &(pSmbExchange->SmbCeContext.pVNetRootContext->pSessionEntry->Session);
  298. } else {
  299. return NULL;
  300. }
  301. }
  302. INLINE PSMBCEDB_NET_ROOT_ENTRY
  303. SmbCeGetExchangeNetRootEntry(PVOID pExchange)
  304. {
  305. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  306. if (pSmbExchange->SmbCeContext.pVNetRootContext != NULL) {
  307. return pSmbExchange->SmbCeContext.pVNetRootContext->pNetRootEntry;
  308. } else {
  309. return NULL;
  310. }
  311. }
  312. INLINE PSMBCE_NET_ROOT
  313. SmbCeGetExchangeNetRoot(PVOID pExchange)
  314. {
  315. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  316. if (pSmbExchange->SmbCeContext.pVNetRootContext != NULL) {
  317. return &(pSmbExchange->SmbCeContext.pVNetRootContext->pNetRootEntry->NetRoot);
  318. } else {
  319. return NULL;
  320. }
  321. }
  322. INLINE PMRX_V_NET_ROOT
  323. SmbCeGetExchangeVNetRoot(PVOID pExchange)
  324. {
  325. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  326. return pSmbExchange->SmbCeContext.pVNetRoot;
  327. }
  328. INLINE PSMBCE_V_NET_ROOT_CONTEXT
  329. SmbCeGetExchangeVNetRootContext(PVOID pExchange)
  330. {
  331. PSMB_EXCHANGE pSmbExchange = (PSMB_EXCHANGE)pExchange;
  332. return pSmbExchange->SmbCeContext.pVNetRootContext;
  333. }
  334. extern ULONG SmbCeTraceExchangeReferenceCount;
  335. // The following functions ( inline, macros and otherwise ) are defined
  336. // to manipulate the exchanges
  337. // The reset exchange macro provides a mechanism for forcing the exchange
  338. // instance to a well known start state. This is used by the protocol
  339. // selection engine to transceive different SMB's. A note of caution --
  340. // ensure that the conditions are O.K for initialization. There is no well
  341. // known mechanism in the exchange engine to prevent overwriting an
  342. // exchange instance while in use.
  343. #define SmbCeResetExchange(pExchange) \
  344. (pExchange)->SmbCeFlags &= ~SMBCE_EXCHANGE_FINALIZED; \
  345. (pExchange)->ReceivePendingOperations = 0; \
  346. (pExchange)->CopyDataPendingOperations = 0; \
  347. (pExchange)->SendCompletePendingOperations = 0; \
  348. (pExchange)->LocalPendingOperations = 0; \
  349. (pExchange)->Status = STATUS_SUCCESS; \
  350. (pExchange)->SmbStatus = STATUS_SUCCESS
  351. // The following macros provide a mechanism for referencing and dereferencing
  352. // the exchange. The reference count provides a mechanism for detecting
  353. // when an exchange instance can be safely discarded. The reference count
  354. // differs from the pending operations count maintained in the exchange
  355. // which are used to detect when a quiescent state is reached.
  356. #define SmbCeReferenceExchange(pExchange) \
  357. InterlockedIncrement(&(pExchange)->ReferenceCount); \
  358. if (SmbCeTraceExchangeReferenceCount) { \
  359. DbgPrint("Reference Exchange %lx Type(%ld) %s %ld %ld\n", \
  360. (pExchange), \
  361. (pExchange)->Type, \
  362. __FILE__, \
  363. __LINE__, \
  364. (pExchange)->ReferenceCount); \
  365. }
  366. #define SmbCeDereferenceExchange(pExchange) \
  367. InterlockedDecrement(&(pExchange)->ReferenceCount); \
  368. if (SmbCeTraceExchangeReferenceCount) { \
  369. DbgPrint("Dereference Exchange %lx Type(%ld) %s %ld %ld\n", \
  370. (pExchange), \
  371. (pExchange)->Type, \
  372. __FILE__, \
  373. __LINE__, \
  374. (pExchange)->ReferenceCount); \
  375. }
  376. #define SmbCeDereferenceAndDiscardExchange(pExchange) \
  377. if (InterlockedDecrement(&(pExchange)->ReferenceCount) == 0) { \
  378. SmbCeDiscardExchange(pExchange); \
  379. } \
  380. if (SmbCeTraceExchangeReferenceCount) { \
  381. DbgPrint("Dereference Exchange %lx Type(%ld) %s %ld %ld\n", \
  382. (pExchange), \
  383. (pExchange)->Type, \
  384. __FILE__, \
  385. __LINE__, \
  386. (pExchange)->ReferenceCount); \
  387. }
  388. // Macros to hide the syntactic details of dereferencing and calling a
  389. // routine in a dispatch vector. These macros are purely intended for
  390. // use in the connection engine only and is not meant for use by
  391. // other modules.
  392. #define SMB_EXCHANGE_DISPATCH(pExchange,Routine,Arguments) \
  393. (*((pExchange)->pDispatchVector->Routine))##Arguments
  394. #define SMB_EXCHANGE_POST(pExchange,Routine) \
  395. RxPostToWorkerThread(&(pExchange)->WorkItem.WorkQueueItem, \
  396. (pExchange)->pDispatchVector->Routine, \
  397. (pExchange))
  398. // The following enum type defines the result of invoking the finalization routine
  399. // on an exchange instance.
  400. typedef enum _SMBCE_EXCHANGE_STATUS_ {
  401. SmbCeExchangeAlreadyFinalized,
  402. SmbCeExchangeFinalized,
  403. SmbCeExchangeNotFinalized
  404. } SMBCE_EXCHANGE_STATUS, *PSMBCE_EXCHANGE_STATUS;
  405. // The pending operations associated with an exchange are classified into four kinds
  406. // Receive operations, Copy Data Operations, Send Complete and Local operations.
  407. // These need to be incremented under the protection of a spinlock. However they
  408. // are decremented in the absence of a spinlock ( with the respective assert ).
  409. #define SMBCE_LOCAL_OPERATION 0x1
  410. #define SMBCE_SEND_COMPLETE_OPERATION 0x2
  411. #define SMBCE_COPY_DATA_OPERATION 0x4
  412. #define SMBCE_RECEIVE_OPERATION 0x8
  413. extern NTSTATUS
  414. SmbCeIncrementPendingOperations(
  415. PSMB_EXCHANGE pExchange,
  416. ULONG PendingOperationsMask,
  417. PVOID FileName,
  418. ULONG FileLine);
  419. extern NTSTATUS
  420. SmbCeDecrementPendingOperations(
  421. PSMB_EXCHANGE pExchange,
  422. ULONG PendingOperationsMask,
  423. PVOID FileName,
  424. ULONG FileLine);
  425. extern SMBCE_EXCHANGE_STATUS
  426. SmbCeDecrementPendingOperationsAndFinalize(
  427. PSMB_EXCHANGE pExchange,
  428. ULONG PendingOperationsMask,
  429. PVOID FileName,
  430. ULONG FileLine);
  431. // the pending operations increment routines
  432. #define SmbCeIncrementPendingReceiveOperations(pExchange) \
  433. SmbCeIncrementPendingOperations(pExchange,(SMBCE_RECEIVE_OPERATION),__FILE__,__LINE__)
  434. #define SmbCeIncrementPendingSendCompleteOperations(pExchange) \
  435. SmbCeIncrementPendingOperations(pExchange,(SMBCE_SEND_COMPLETE_OPERATION),__FILE__,__LINE__)
  436. #define SmbCeIncrementPendingCopyDataOperations(pExchange) \
  437. SmbCeIncrementPendingOperations(pExchange,(SMBCE_COPY_DATA_OPERATION),__FILE__,__LINE__)
  438. #define SmbCeIncrementPendingLocalOperations(pExchange) \
  439. SmbCeIncrementPendingOperations(pExchange,(SMBCE_LOCAL_OPERATION),__FILE__,__LINE__)
  440. // The pending operations decrement routines
  441. // Note the special casing of ReceivePendingOperations since it is the only one
  442. // that can be forced by a disconnect indication. There are two variations in
  443. // the decrement macros. The first flavour is to be used when it can be
  444. // guaranteed that the decrement operation will not lead to the finalization
  445. // of the exchange and the second is to be used when we cannot ensure the criterion
  446. // for the first. The difference between the two is that it eliminates
  447. // acquisition/release of a spinlock.
  448. #define SmbCeDecrementPendingReceiveOperations(pExchange) \
  449. SmbCeDecrementPendingOperations(pExchange,(SMBCE_RECEIVE_OPERATION),__FILE__,__LINE__)
  450. #define SmbCeDecrementPendingSendCompleteOperations(pExchange) \
  451. SmbCeDecrementPendingOperations(pExchange,(SMBCE_SEND_COMPLETE_OPERATION),__FILE__,__LINE__)
  452. #define SmbCeDecrementPendingCopyDataOperations(pExchange) \
  453. SmbCeDecrementPendingOperations(pExchange,(SMBCE_COPY_DATA_OPERATION),__FILE__,__LINE__)
  454. #define SmbCeDecrementPendingLocalOperations(pExchange) \
  455. SmbCeDecrementPendingOperations(pExchange,(SMBCE_LOCAL_OPERATION),__FILE__,__LINE__)
  456. // The pending operations decrement routines
  457. #define SmbCeDecrementPendingReceiveOperationsAndFinalize(pExchange) \
  458. SmbCeDecrementPendingOperationsAndFinalize(pExchange,(SMBCE_RECEIVE_OPERATION),__FILE__,__LINE__)
  459. #define SmbCeDecrementPendingSendCompleteOperationsAndFinalize(pExchange) \
  460. SmbCeDecrementPendingOperationsAndFinalize(pExchange,(SMBCE_SEND_COMPLETE_OPERATION),__FILE__,__LINE__)
  461. #define SmbCeDecrementPendingCopyDataOperationsAndFinalize(pExchange) \
  462. SmbCeDecrementPendingOperationsAndFinalize(pExchange,(SMBCE_COPY_DATA_OPERATION),__FILE__,__LINE__)
  463. #define SmbCeDecrementPendingLocalOperationsAndFinalize(pExchange) \
  464. SmbCeDecrementPendingOperationsAndFinalize(pExchange,(SMBCE_LOCAL_OPERATION),__FILE__,__LINE__)
  465. //
  466. // This is the pid that will be used by the rdr; rdr1 used 0xcafe.
  467. // only this pid is ever sent except for nt<-->nt creates. in these cases,
  468. // we have to send the full 32bit process id for RPC.
  469. //
  470. #define MRXSMB_PROCESS_ID (0xfeff)
  471. INLINE VOID
  472. SmbCeSetFullProcessIdInHeader(
  473. PSMB_EXCHANGE pExchange,
  474. ULONG ProcessId,
  475. PNT_SMB_HEADER pNtSmbHeader)
  476. {
  477. pExchange->SmbCeFlags |= SMBCE_EXCHANGE_FULL_PROCESSID_SPECIFIED;
  478. SmbPutUshort(&pNtSmbHeader->Pid, (USHORT)((ProcessId) & 0xFFFF));
  479. SmbPutUshort(&pNtSmbHeader->PidHigh, (USHORT)((ProcessId) >> 16));
  480. }
  481. // The exchange engine API, for creation and manipulation of exchange instances
  482. // Initialization/Creation of an exchange instance
  483. extern NTSTATUS
  484. SmbCepInitializeExchange(
  485. PSMB_EXCHANGE *pExchangePointer,
  486. PRX_CONTEXT pRxContext,
  487. PSMBCEDB_SERVER_ENTRY pServerEntry,
  488. PMRX_V_NET_ROOT pVNetRoot,
  489. SMB_EXCHANGE_TYPE ExchangeType,
  490. PSMB_EXCHANGE_DISPATCH_VECTOR pDispatchVector);
  491. INLINE NTSTATUS
  492. SmbCeInitializeExchange(
  493. PSMB_EXCHANGE *pExchangePointer,
  494. PRX_CONTEXT pRxContext,
  495. PMRX_V_NET_ROOT pVNetRoot,
  496. SMB_EXCHANGE_TYPE ExchangeType,
  497. PSMB_EXCHANGE_DISPATCH_VECTOR pDispatchVector)
  498. {
  499. return SmbCepInitializeExchange(
  500. pExchangePointer,
  501. pRxContext,
  502. NULL,
  503. pVNetRoot,
  504. ExchangeType,
  505. pDispatchVector);
  506. }
  507. INLINE NTSTATUS
  508. SmbCeInitializeExchange2(
  509. PSMB_EXCHANGE *pExchangePointer,
  510. PRX_CONTEXT pRxContext,
  511. PSMBCEDB_SERVER_ENTRY pServerEntry,
  512. SMB_EXCHANGE_TYPE ExchangeType,
  513. PSMB_EXCHANGE_DISPATCH_VECTOR pDispatchVector)
  514. {
  515. return SmbCepInitializeExchange(
  516. pExchangePointer,
  517. pRxContext,
  518. pServerEntry,
  519. NULL,
  520. ExchangeType,
  521. pDispatchVector);
  522. }
  523. extern NTSTATUS
  524. SmbCeInitializeAssociatedExchange(
  525. PSMB_EXCHANGE *pAssociatedExchangePointer,
  526. PSMB_EXCHANGE pMasterExchange,
  527. SMB_EXCHANGE_TYPE Type,
  528. PSMB_EXCHANGE_DISPATCH_VECTOR pDispatchVector);
  529. // converting one type of exchange to another
  530. extern NTSTATUS
  531. SmbCeTransformExchange(
  532. PSMB_EXCHANGE pExchange,
  533. SMB_EXCHANGE_TYPE NewType,
  534. PSMB_EXCHANGE_DISPATCH_VECTOR pDispatchVector);
  535. // Initiating an exchange
  536. extern NTSTATUS
  537. SmbCeInitiateExchange(PSMB_EXCHANGE pExchange);
  538. extern NTSTATUS
  539. SmbCeInitiateAssociatedExchange(
  540. PSMB_EXCHANGE pAssociatedExchange,
  541. BOOLEAN EnableCompletionHandlerInMasterExchange);
  542. // Resuming an exchange
  543. extern NTSTATUS
  544. SmbCeResumeExchange(PSMB_EXCHANGE pExchange);
  545. // aborting an initiated exchange
  546. extern NTSTATUS
  547. SmbCeAbortExchange(PSMB_EXCHANGE pExchange);
  548. // discarding an exchnge instance
  549. extern VOID
  550. SmbCeDiscardExchange(PVOID pExchange);
  551. // In addition to providing a flexible mechanism for exchanging packets with
  552. // the server the exchange engine also provides a mechanism for building and
  553. // parsing SMB_HEADER's. This functionality is built into the connection
  554. // engine because the meta data in the headers is used to update the connection
  555. // engine database.
  556. // building SMB headers
  557. extern NTSTATUS
  558. SmbCeBuildSmbHeader(
  559. IN OUT PSMB_EXCHANGE pExchange,
  560. IN OUT PVOID pBuffer,
  561. IN ULONG BufferLength,
  562. OUT PULONG pRemainingBuffer,
  563. OUT PUCHAR pLastCommandInHeader,
  564. OUT PUCHAR *pNextCommand);
  565. // parsing SMB headers.
  566. extern NTSTATUS
  567. SmbCeParseSmbHeader(
  568. PSMB_EXCHANGE pExchange,
  569. PSMB_HEADER pSmbHeader,
  570. PGENERIC_ANDX pCommandToProcess,
  571. NTSTATUS *pSmbResponseStatus,
  572. ULONG BytesAvailable,
  573. ULONG BytesIndicated,
  574. PULONG pBytesConsumed);
  575. // The following routines are intended for use in the connection engine only.
  576. extern NTSTATUS
  577. MRxSmbInitializeSmbCe();
  578. extern NTSTATUS
  579. MRxSmbTearDownSmbCe();
  580. extern NTSTATUS
  581. SmbCePrepareExchangeForReuse(PSMB_EXCHANGE pExchange);
  582. extern PVOID
  583. SmbCeMapSendBufferToCompletionContext(
  584. PSMB_EXCHANGE pExchange,
  585. PVOID pBuffer);
  586. extern PVOID
  587. SmbCeMapSendCompletionContextToBuffer(
  588. PSMB_EXCHANGE pExchange,
  589. PVOID pContext);
  590. extern SMBCE_EXCHANGE_STATUS
  591. SmbCeFinalizeExchange(PSMB_EXCHANGE pExchange);
  592. extern VOID
  593. SmbCeFinalizeExchangeOnDisconnect(
  594. PSMB_EXCHANGE pExchange);
  595. extern NTSTATUS
  596. SmbCeReferenceServer(
  597. PSMB_EXCHANGE pExchange);
  598. extern NTSTATUS
  599. SmbCeIncrementActiveExchangeCount();
  600. extern VOID
  601. SmbCeDecrementActiveExchangeCount();
  602. extern VOID
  603. SmbCeSetExpiryTime(
  604. PSMB_EXCHANGE pExchange);
  605. extern BOOLEAN
  606. SmbCeDetectExpiredExchanges(
  607. PSMBCEDB_SERVER_ENTRY pServerEntry);
  608. extern VOID
  609. SmbCepFinalizeAssociatedExchange(
  610. PSMB_EXCHANGE pExchange);
  611. extern NTSTATUS
  612. SmbCeCancelExchange(
  613. PRX_CONTEXT pRxContext);
  614. typedef struct _SMB_CONSTRUCT_NETROOT_EXCHANGE_ {
  615. union {
  616. SMB_EXCHANGE;
  617. SMB_EXCHANGE Exchange;
  618. };
  619. SMB_TREE_ID TreeId;
  620. SMB_USER_ID UserId;
  621. BOOLEAN fUpdateDefaultSessionEntry;
  622. BOOLEAN fInitializeNetRoot;
  623. PMRX_NETROOT_CALLBACK NetRootCallback;
  624. PMDL pSmbRequestMdl;
  625. PMDL pSmbResponseMdl;
  626. PVOID pSmbActualBuffer; // Originally allocated buffer
  627. PVOID pSmbBuffer; // Start of header
  628. PMRX_CREATENETROOT_CONTEXT pCreateNetRootContext;
  629. } SMB_CONSTRUCT_NETROOT_EXCHANGE, *PSMB_CONSTRUCT_NETROOT_EXCHANGE;
  630. extern
  631. NTSTATUS
  632. GetSmbResponseNtStatus(
  633. IN PSMB_HEADER pSmbHeader,
  634. IN PSMB_EXCHANGE pExchange
  635. );
  636. #endif // _SMBXCHNG_H_