Source code of Windows XP (NT5)
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.

319 lines
7.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Copyright (c) 1996, 1997 Microsoft Corporation
  5. //
  6. //
  7. // Module Name:
  8. // ipstream.c
  9. //
  10. // Abstract:
  11. //
  12. // This file is a test to find out if dual binding to NDIS and KS works
  13. //
  14. // Author:
  15. //
  16. // P Porzuczek
  17. //
  18. // Environment:
  19. //
  20. // Revision History:
  21. //
  22. //
  23. //////////////////////////////////////////////////////////////////////////////
  24. #ifndef DWORD
  25. #define DWORD ULONG
  26. #endif
  27. #include <forward.h>
  28. #include <strmini.h>
  29. #include <link.h>
  30. #include <ipsink.h>
  31. #include "ipmedia.h"
  32. #include "main.h"
  33. //////////////////////////////////////////////////////////////////////////////
  34. VOID
  35. CloseLink (
  36. PLINK pLink
  37. )
  38. //////////////////////////////////////////////////////////////////////////////
  39. {
  40. PDEVICE_OBJECT pDeviceObject = NULL;
  41. PFILE_OBJECT pFileObject = NULL;
  42. HANDLE hFileHandle = 0;
  43. KIRQL Irql;
  44. // Validate the parameter
  45. //
  46. ASSERT( pLink);
  47. if (!pLink)
  48. {
  49. return;
  50. }
  51. // Swap our new objects into the NdisLink.
  52. //
  53. KeAcquireSpinLock( &pLink->spinLock, &Irql);
  54. if (pLink->flags & LINK_ESTABLISHED)
  55. {
  56. pDeviceObject = pLink->pDeviceObject;
  57. pLink->pDeviceObject = NULL;
  58. pFileObject = pLink->pFileObject;
  59. pLink->pFileObject = NULL;
  60. pLink->flags &= ~LINK_ESTABLISHED;
  61. }
  62. KeReleaseSpinLock( &pLink->spinLock, Irql);
  63. //
  64. // DeReference the private interface handles.
  65. //
  66. if (pDeviceObject)
  67. {
  68. ObDereferenceObject(pDeviceObject);
  69. pDeviceObject = NULL;
  70. }
  71. if (pFileObject)
  72. {
  73. ObDereferenceObject(pFileObject);
  74. pFileObject = NULL;
  75. }
  76. }
  77. //////////////////////////////////////////////////////////////////////////////
  78. PLINK
  79. OpenLink (
  80. PLINK pLink,
  81. UNICODE_STRING DriverName
  82. )
  83. //////////////////////////////////////////////////////////////////////////////
  84. {
  85. NTSTATUS ntStatus = STATUS_SUCCESS;
  86. PWSTR pwstr = (PWSTR)NULL;
  87. UNICODE_STRING uni = {0};
  88. OBJECT_ATTRIBUTES objAttrib = {0};
  89. IO_STATUS_BLOCK IoStatusBlock = {0};
  90. PDEVICE_OBJECT pDeviceObject = NULL;
  91. PFILE_OBJECT pFileObject = NULL;
  92. HANDLE hFileHandle = 0;
  93. KIRQL Irql;
  94. if (pLink->flags & LINK_ESTABLISHED)
  95. {
  96. goto err;
  97. }
  98. //
  99. // Set the link_established flag. This will be cleared if the call fails.
  100. //
  101. #ifndef WIN9X
  102. //
  103. // Look up the interface for NDISIP. This gets the full path used by
  104. // swenum to find and open NdisIp.sys.
  105. //
  106. ntStatus = IoGetDeviceInterfaces( (GUID *) &IID_IBDA_BDANetInterface,
  107. NULL,
  108. 0,
  109. &pwstr);
  110. if (ntStatus != STATUS_SUCCESS || pwstr == NULL)
  111. {
  112. goto err;
  113. }
  114. //
  115. // Initialize a Unicode string to the NDIS driver's Software Enum Path/Name.
  116. //
  117. RtlInitUnicodeString( &uni, pwstr);
  118. //
  119. // Open Ndisip.sys via swenum.
  120. //
  121. InitializeObjectAttributes( &objAttrib,
  122. &uni,
  123. OBJ_CASE_INSENSITIVE,
  124. NULL,
  125. NULL);
  126. ntStatus = ZwCreateFile( &hFileHandle,
  127. FILE_WRITE_DATA|FILE_READ_ATTRIBUTES,
  128. &objAttrib,
  129. &IoStatusBlock,
  130. 0,
  131. FILE_ATTRIBUTE_NORMAL,
  132. FILE_SHARE_WRITE|FILE_SHARE_READ,
  133. FILE_OPEN_IF,
  134. 0,
  135. NULL,
  136. 0);
  137. if (ntStatus != STATUS_SUCCESS)
  138. {
  139. goto err;
  140. }
  141. #endif
  142. //
  143. // Now get get handles to the Ndisip.sys/streamip.sys private
  144. // data interface.
  145. //
  146. ntStatus = IoGetDeviceObjectPointer (
  147. &DriverName,
  148. FILE_READ_ATTRIBUTES,
  149. &pFileObject,
  150. &pDeviceObject);
  151. if (ntStatus != STATUS_SUCCESS)
  152. {
  153. goto err;
  154. }
  155. ObReferenceObject(pDeviceObject);
  156. ObReferenceObject(pFileObject);
  157. // Swap our new objects into the NdisLink.
  158. //
  159. KeAcquireSpinLock( &pLink->spinLock, &Irql);
  160. pLink->flags |= LINK_ESTABLISHED;
  161. // Exchange our new device object reference for the one currently used.
  162. //
  163. {
  164. PDEVICE_OBJECT pDeviceObjectT;
  165. pDeviceObjectT = pLink->pDeviceObject;
  166. pLink->pDeviceObject = pDeviceObject;
  167. pDeviceObject = pDeviceObjectT;
  168. }
  169. // Exchange our new file object reference for the one currently used.
  170. //
  171. {
  172. PFILE_OBJECT pFileObjectT;
  173. pFileObjectT = pLink->pFileObject;
  174. pLink->pFileObject = pFileObject;
  175. pFileObject = pFileObjectT;
  176. }
  177. KeReleaseSpinLock( &pLink->spinLock, Irql);
  178. err:
  179. // Clean up temp string allocation.
  180. //
  181. if(pwstr)
  182. {
  183. ExFreePool(pwstr);
  184. pwstr = NULL;
  185. }
  186. // DeReference any leaked objects.
  187. //
  188. // These objects are leaked only if two or more calls to
  189. // OpenLink collide or if an open failed in this routine.
  190. //
  191. if (pDeviceObject)
  192. {
  193. ObDereferenceObject( pDeviceObject);
  194. pDeviceObject = NULL;
  195. }
  196. if (pFileObject)
  197. {
  198. ObDereferenceObject( pFileObject);
  199. pFileObject = NULL;
  200. }
  201. if(hFileHandle)
  202. {
  203. ZwClose( hFileHandle);
  204. hFileHandle = 0;
  205. }
  206. return (pLink->flags & LINK_ESTABLISHED) ? pLink : NULL;
  207. }
  208. //////////////////////////////////////////////////////////////////////////////
  209. NTSTATUS
  210. SendIOCTL (
  211. PLINK pLink,
  212. ULONG ulIoctl,
  213. PVOID pData,
  214. ULONG ulcbData
  215. )
  216. //////////////////////////////////////////////////////////////////////////////
  217. {
  218. PIRP pIrp = NULL;
  219. NTSTATUS ntStatus = STATUS_SUCCESS;
  220. IO_STATUS_BLOCK IoStatusBlock = {0};
  221. //
  222. // Create a control request block
  223. //
  224. pIrp = IoBuildDeviceIoControlRequest(
  225. ulIoctl,
  226. pLink->pDeviceObject,
  227. pData,
  228. ulcbData,
  229. 0, // Optional output buffer
  230. 0, // Optional output buffer length
  231. TRUE, // InternalDeviceIoControl == TRUE
  232. NULL, // Optional Event
  233. &IoStatusBlock);
  234. if (pIrp != NULL)
  235. {
  236. PIO_STACK_LOCATION pNextStackLocation;
  237. pNextStackLocation = IoGetNextIrpStackLocation(pIrp);
  238. if (pNextStackLocation)
  239. {
  240. pNextStackLocation->FileObject = pLink->pFileObject;
  241. IoStatusBlock.Status = STATUS_SUCCESS;
  242. //
  243. // Feed the NDIS mini-driver
  244. //
  245. ntStatus = IoCallDriver( pLink->pDeviceObject, pIrp);
  246. if (ntStatus != STATUS_SUCCESS ||
  247. IoStatusBlock.Status != STATUS_SUCCESS)
  248. {
  249. ntStatus = STATUS_UNSUCCESSFUL;
  250. }
  251. }
  252. else
  253. {
  254. ntStatus = STATUS_UNSUCCESSFUL;
  255. }
  256. }
  257. else
  258. {
  259. ntStatus = STATUS_UNSUCCESSFUL;
  260. }
  261. return ntStatus;
  262. }