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.

572 lines
10 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // sysprocs.hpp
  7. //
  8. // Abstract:
  9. // Function prototypes for tdi sample driver.
  10. //
  11. //////////////////////////////////////////////////////////////////////////
  12. //
  13. // public functions in buffer.cpp
  14. //
  15. NTSTATUS
  16. TSPostReceiveBuffer(
  17. PGENERIC_HEADER pGenericHeader,
  18. PSEND_BUFFER pSendBuffer
  19. );
  20. NTSTATUS
  21. TSFetchReceiveBuffer(
  22. PGENERIC_HEADER pGenericHeader,
  23. PRECEIVE_BUFFER pReceiveBuffer
  24. );
  25. //
  26. // public functions in connect.cpp
  27. //
  28. NTSTATUS
  29. TSConnect(
  30. PENDPOINT_OBJECT pEndpointObject,
  31. PSEND_BUFFER pSendBuffer,
  32. PIRP pIrp
  33. );
  34. NTSTATUS
  35. TSDisconnect(
  36. PENDPOINT_OBJECT pEndpointObject,
  37. PSEND_BUFFER pSendBuffer,
  38. PIRP pIrp
  39. );
  40. NTSTATUS
  41. TSListen(
  42. PENDPOINT_OBJECT pEndpointObject
  43. );
  44. NTSTATUS
  45. TSIsConnected(
  46. PENDPOINT_OBJECT pEndpointObject,
  47. PRECEIVE_BUFFER pReceiveBuffer
  48. );
  49. TDI_STATUS
  50. TSConnectHandler(
  51. PVOID TdiEventContext,
  52. LONG RemoteAddressLength,
  53. PVOID RemoteAddress,
  54. LONG UserDataLength,
  55. PVOID UserData,
  56. LONG OptionsLength,
  57. PVOID Options,
  58. CONNECTION_CONTEXT *ConnectionContext,
  59. PIRP *AcceptIrp
  60. );
  61. TDI_STATUS
  62. TSDisconnectHandler(
  63. PVOID TdiEventContext,
  64. CONNECTION_CONTEXT ConnectionContext,
  65. LONG DisconnectDataLength,
  66. PVOID DisconnectData,
  67. LONG DisconnectInformationLength,
  68. PVOID DisconnectInformation,
  69. ULONG DisconnectFlags
  70. );
  71. //
  72. // public functions in events.cpp
  73. //
  74. NTSTATUS
  75. TSSetEventHandler(
  76. PGENERIC_HEADER pGenericHeader,
  77. PSEND_BUFFER pSendBuffer,
  78. PIRP pIrp
  79. );
  80. //
  81. // public functions in open.cpp
  82. //
  83. NTSTATUS
  84. TSOpenControl(
  85. PSEND_BUFFER pSendBuffer,
  86. PRECEIVE_BUFFER pReceiveBuffer
  87. );
  88. VOID
  89. TSCloseControl(
  90. PCONTROL_CHANNEL pControlChannel
  91. );
  92. NTSTATUS
  93. TSOpenAddress(
  94. PSEND_BUFFER pSendBuffer,
  95. PRECEIVE_BUFFER pReceiveBuffer
  96. );
  97. VOID
  98. TSCloseAddress(
  99. PADDRESS_OBJECT pAddressObject
  100. );
  101. NTSTATUS
  102. TSOpenEndpoint(
  103. PSEND_BUFFER pSendBuffer,
  104. PRECEIVE_BUFFER pReceiveBuffer
  105. );
  106. VOID
  107. TSCloseEndpoint(
  108. PENDPOINT_OBJECT pEndpoint
  109. );
  110. //
  111. // public functions from recvcom.cpp
  112. //
  113. VOID
  114. TSPacketReceived(
  115. PADDRESS_OBJECT pAddressObject,
  116. PRECEIVE_DATA pReceiveData,
  117. BOOLEAN fIsExpedited
  118. );
  119. VOID
  120. TSFreePacketData(
  121. PADDRESS_OBJECT pAddressObject
  122. );
  123. //
  124. // locks down user buffer, maps to kernel space
  125. //
  126. PMDL
  127. TSMakeMdlForUserBuffer(
  128. PUCHAR pucDataBuffer,
  129. ULONG ulDataLength,
  130. LOCK_OPERATION AccessType
  131. );
  132. //
  133. // unmaps and unlocks user buffer
  134. //
  135. inline
  136. VOID
  137. TSFreeUserBuffer(PMDL pMdl)
  138. {
  139. MmUnlockPages(pMdl);
  140. IoFreeMdl(pMdl);
  141. }
  142. //
  143. // public functions in rcvdgram.cpp
  144. //
  145. NTSTATUS
  146. TSReceiveDatagram(
  147. PADDRESS_OBJECT pAddressObject,
  148. PSEND_BUFFER pSendBuffer,
  149. PRECEIVE_BUFFER pReceiveBuffer
  150. );
  151. TDI_STATUS
  152. TSRcvDatagramHandler(
  153. PVOID pvTdiEventContext,
  154. LONG lSourceAddressLength,
  155. PVOID pvSourceAddress,
  156. LONG lOptionsLength,
  157. PVOID pvOptions,
  158. ULONG ulReceiveDatagramFlags,
  159. ULONG ulBytesIndicated,
  160. ULONG ulBytesAvailable,
  161. ULONG *pulBytesTaken,
  162. PVOID pvTsdu,
  163. PIRP *pIoRequestPacket
  164. );
  165. TDI_STATUS
  166. TSChainedRcvDatagramHandler(
  167. PVOID TdiEventContext,
  168. LONG SourceAddressLength,
  169. PVOID SourceAddress,
  170. LONG OptionsLength,
  171. PVOID Options,
  172. ULONG ReceiveDatagramFlags,
  173. ULONG ReceiveDatagramLength,
  174. ULONG StartingOffset,
  175. PMDL Tsdu,
  176. PVOID TsduDescriptor
  177. );
  178. //
  179. // public functions in receive.cpp
  180. //
  181. NTSTATUS
  182. TSReceive(
  183. PENDPOINT_OBJECT pEndpointObject,
  184. PSEND_BUFFER pSendBuffer,
  185. PRECEIVE_BUFFER pReceiveBuffer
  186. );
  187. TDI_STATUS
  188. TSReceiveHandler(
  189. PVOID TdiEventContext,
  190. CONNECTION_CONTEXT ConnectionContext,
  191. ULONG ReceiveFlags,
  192. ULONG BytesIndicated,
  193. ULONG BytesAvailable,
  194. ULONG *BytesTaken,
  195. PVOID Tsdu,
  196. PIRP *IoRequestPacket
  197. );
  198. TDI_STATUS
  199. TSRcvExpeditedHandler(
  200. PVOID TdiEventContext,
  201. CONNECTION_CONTEXT ConnectionContext,
  202. ULONG ReceiveFlags,
  203. ULONG BytesIndicated,
  204. ULONG BytesAvailable,
  205. ULONG *BytesTaken,
  206. PVOID Tsdu,
  207. PIRP *IoRequestPacket
  208. );
  209. TDI_STATUS
  210. TSChainedReceiveHandler(
  211. PVOID TdiEventContext,
  212. CONNECTION_CONTEXT ConnectionContext,
  213. ULONG ReceiveFlags,
  214. ULONG ReceiveLength,
  215. ULONG StartingOffset,
  216. PMDL Tsdu,
  217. PVOID TsduDescriptor
  218. );
  219. TDI_STATUS
  220. TSChainedRcvExpeditedHandler(
  221. PVOID TdiEventContext,
  222. CONNECTION_CONTEXT ConnectionContext,
  223. ULONG ReceiveFlags,
  224. ULONG ReceiveLength,
  225. ULONG StartingOffset,
  226. PMDL Tsdu,
  227. PVOID TsduDescriptor
  228. );
  229. //
  230. // public functions in request.cpp
  231. //
  232. NTSTATUS
  233. TSIssueRequest(
  234. IN PDEVICE_CONTEXT pDeviceContext,
  235. IN PIRP pIrp,
  236. IN PIO_STACK_LOCATION pIrpSp
  237. );
  238. //
  239. // public functions in send.cpp
  240. //
  241. NTSTATUS
  242. TSSendDatagram(
  243. PADDRESS_OBJECT pAddressObject,
  244. PSEND_BUFFER pSendBuffer,
  245. PIRP pIrp
  246. );
  247. NTSTATUS
  248. TSSend(
  249. PENDPOINT_OBJECT pEndpointObject,
  250. PSEND_BUFFER pSendBuffer,
  251. PIRP pIrp
  252. );
  253. //
  254. // functions in tdipnp.cpp
  255. //
  256. VOID
  257. TSPnpBindCallback(
  258. TDI_PNP_OPCODE opcode,
  259. PUNICODE_STRING devname,
  260. PWSTR multiszstring
  261. );
  262. NTSTATUS
  263. TSPnpPowerHandler(
  264. PUNICODE_STRING devname,
  265. PNET_PNP_EVENT pnpevent,
  266. PTDI_PNP_CONTEXT Context1,
  267. PTDI_PNP_CONTEXT Context2
  268. );
  269. VOID
  270. TSPnpAddAddressCallback(
  271. PTA_ADDRESS Address,
  272. PUNICODE_STRING DeviceName,
  273. PTDI_PNP_CONTEXT Context
  274. );
  275. VOID
  276. TSPnpDelAddressCallback(
  277. PTA_ADDRESS Address,
  278. PUNICODE_STRING DeviceName,
  279. PTDI_PNP_CONTEXT Context
  280. );
  281. VOID
  282. TSGetNumDevices(
  283. PSEND_BUFFER pSendBuffer,
  284. PRECEIVE_BUFFER pReceiveBuffer
  285. );
  286. NTSTATUS
  287. TSGetDevice(
  288. PSEND_BUFFER pSendBuffer,
  289. PRECEIVE_BUFFER pReceiveBuffer
  290. );
  291. NTSTATUS
  292. TSGetAddress(
  293. PSEND_BUFFER pSendBuffer,
  294. PRECEIVE_BUFFER pReceiveBuffer
  295. );
  296. //
  297. // functions in tdiquery.cpp
  298. //
  299. NTSTATUS
  300. TSQueryInfo(
  301. PGENERIC_HEADER pGenericHeader,
  302. PSEND_BUFFER pSendBuffer,
  303. PIRP pIrp
  304. );
  305. //
  306. // functions in utils.cpp
  307. //
  308. NTSTATUS
  309. TSAllocateMemory(
  310. OUT PVOID *ppvVirtualAddress,
  311. IN ULONG ulLength,
  312. IN CONST PCHAR strFunction,
  313. IN CONST PCHAR strTitle
  314. );
  315. VOID
  316. TSFreeMemory(
  317. IN PVOID pvVirtualAddress
  318. );
  319. VOID
  320. TSScanMemoryPool(
  321. VOID
  322. );
  323. ULONG
  324. TSInsertNode(
  325. PGENERIC_HEADER pNewNode
  326. );
  327. VOID
  328. TSRemoveNode(
  329. ULONG ulTdiHandle
  330. );
  331. PIRP
  332. TSAllocateIrp(
  333. PDEVICE_OBJECT pDeviceObject,
  334. PIRP_POOL pIrpPool
  335. );
  336. VOID
  337. TSFreeIrp(
  338. PIRP pIrp,
  339. PIRP_POOL pIrpPool
  340. );
  341. VOID
  342. TSPrintTaAddress(
  343. PTA_ADDRESS ptaaddr
  344. );
  345. PIRP_POOL
  346. TSAllocateIrpPool(
  347. PDEVICE_OBJECT pDeviceObject,
  348. ULONG ulPoolSize
  349. );
  350. VOID
  351. TSFreeIrpPool(
  352. PIRP_POOL pIrpPool
  353. );
  354. PGENERIC_HEADER
  355. TSGetObjectFromHandle(
  356. ULONG ulTdiHandle,
  357. ULONG ulType
  358. );
  359. //
  360. // inline functions...
  361. //
  362. inline
  363. PRECEIVE_BUFFER
  364. TSGetReceiveBuffer(PIRP pIrp)
  365. {
  366. return (PRECEIVE_BUFFER)MmGetSystemAddressForMdl(pIrp->MdlAddress);
  367. }
  368. inline
  369. PSEND_BUFFER
  370. TSGetSendBuffer(PIRP pIrp)
  371. {
  372. return (PSEND_BUFFER)pIrp->AssociatedIrp.SystemBuffer;
  373. }
  374. inline
  375. PMDL
  376. TSAllocateBuffer(PVOID pvAddress,
  377. ULONG ulLength)
  378. {
  379. PMDL pMdl
  380. = IoAllocateMdl(pvAddress,
  381. ulLength,
  382. FALSE,
  383. FALSE,
  384. NULL);
  385. if (pMdl)
  386. {
  387. MmBuildMdlForNonPagedPool(pMdl);
  388. }
  389. return pMdl;
  390. }
  391. inline
  392. VOID
  393. TSFreeBuffer(PMDL pMdl)
  394. {
  395. IoFreeMdl(pMdl);
  396. }
  397. inline
  398. VOID
  399. TSCompleteIrp(PIRP pIrp)
  400. {
  401. PSEND_BUFFER pSendBuffer = TSGetSendBuffer(pIrp);
  402. pSendBuffer->pvLowerIrp = NULL;
  403. ((PDEVICE_CONTEXT)pSendBuffer->pvDeviceContext)->pLastCommandIrp = NULL;
  404. pIrp->IoStatus.Status = STATUS_SUCCESS;
  405. IoMarkIrpPending(pIrp);
  406. IoCompleteRequest(pIrp, IO_NETWORK_INCREMENT);
  407. }
  408. //
  409. // spinlock and timer functions, mostly stolen from ndis
  410. //
  411. inline
  412. VOID
  413. TSAllocateSpinLock(PTDI_SPIN_LOCK pTdiSpinLock)
  414. {
  415. KeInitializeSpinLock(&pTdiSpinLock->SpinLock);
  416. }
  417. #pragma warning(disable: UNREFERENCED_PARAM)
  418. inline
  419. VOID
  420. TSFreeSpinLock(PTDI_SPIN_LOCK pTdiSpinLock)
  421. {
  422. }
  423. #pragma warning(default: UNREFERENCED_PARAM)
  424. inline
  425. VOID
  426. TSAcquireSpinLock(PTDI_SPIN_LOCK pTdiSpinLock)
  427. {
  428. KeAcquireSpinLock(&pTdiSpinLock->SpinLock,
  429. &pTdiSpinLock->OldIrql);
  430. }
  431. inline
  432. VOID
  433. TSReleaseSpinLock(PTDI_SPIN_LOCK pTdiSpinLock)
  434. {
  435. KeReleaseSpinLock(&pTdiSpinLock->SpinLock,
  436. pTdiSpinLock->OldIrql);
  437. }
  438. inline
  439. VOID
  440. TSInitializeEvent(PTDI_EVENT pTdiEvent)
  441. {
  442. KeInitializeEvent(pTdiEvent,
  443. NotificationEvent,
  444. FALSE);
  445. }
  446. inline
  447. VOID
  448. TSWaitEvent(PTDI_EVENT pTdiEvent)
  449. {
  450. KeWaitForSingleObject(pTdiEvent,
  451. Executive,
  452. KernelMode,
  453. FALSE,
  454. NULL);
  455. }
  456. inline
  457. VOID
  458. TSSetEvent(PTDI_EVENT pTdiEvent)
  459. {
  460. KeSetEvent(pTdiEvent,
  461. 0,
  462. FALSE);
  463. }
  464. /////////////////////////////////////////////////////////////////////////
  465. // end of file sysprocs.hpp
  466. /////////////////////////////////////////////////////////////////////////