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.

1136 lines
30 KiB

  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Copyright (c) 1996, 1997 Microsoft Corporation
  5. //
  6. //
  7. // Module Name:
  8. // test.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. #include <forward.h>
  25. #include <memory.h>
  26. //Per ndis.h resetting this flag uses ntddk.Avoids header conflicts.
  27. //ntddk is used here for ProbeForRead and ProbeForWrite functions.
  28. #if defined(BINARY_COMPATIBLE)
  29. #undef BINARY_COMPATIBLE
  30. #define BINARY_COMPATIBLE 0
  31. #endif
  32. #include <ndis.h>
  33. #if defined(BINARY_COMPATIBLE)
  34. #undef BINARY_COMPATIBLE
  35. #define BINARY_COMPATIBLE 1
  36. #endif
  37. #include <link.h>
  38. #include <ipsink.h>
  39. #include "device.h"
  40. #include "main.h"
  41. #include "NdisApi.h"
  42. #include "frame.h"
  43. #include "mem.h"
  44. #include "adapter.h"
  45. //////////////////////////////////////////////////////////
  46. //
  47. // Global vars
  48. //
  49. PDRIVER_OBJECT pGlobalDriverObject = NULL;
  50. extern ULONG ulGlobalInstance;
  51. extern UCHAR achGlobalVendorDescription [];
  52. //////////////////////////////////////////////////////////
  53. //
  54. // List of supported OID for this driver.
  55. //
  56. //
  57. static UINT SupportedOids[] = {
  58. //
  59. // Required General OIDs
  60. //
  61. OID_GEN_SUPPORTED_LIST,
  62. OID_GEN_HARDWARE_STATUS,
  63. OID_GEN_MEDIA_CAPABILITIES,
  64. OID_GEN_MEDIA_SUPPORTED,
  65. OID_GEN_MEDIA_IN_USE,
  66. OID_GEN_MAXIMUM_LOOKAHEAD,
  67. OID_GEN_MAXIMUM_FRAME_SIZE,
  68. OID_GEN_LINK_SPEED,
  69. OID_GEN_TRANSMIT_BUFFER_SPACE,
  70. OID_GEN_RECEIVE_BUFFER_SPACE,
  71. OID_GEN_TRANSMIT_BLOCK_SIZE,
  72. OID_GEN_RECEIVE_BLOCK_SIZE,
  73. OID_GEN_VENDOR_ID,
  74. OID_GEN_VENDOR_DESCRIPTION,
  75. OID_GEN_CURRENT_PACKET_FILTER,
  76. OID_GEN_CURRENT_LOOKAHEAD,
  77. OID_GEN_DRIVER_VERSION,
  78. OID_GEN_MAXIMUM_TOTAL_SIZE,
  79. OID_GEN_MAC_OPTIONS,
  80. OID_GEN_MEDIA_CONNECT_STATUS,
  81. OID_GEN_MAXIMUM_SEND_PACKETS,
  82. OID_GEN_VENDOR_DRIVER_VERSION,
  83. OID_GEN_TRANSPORT_HEADER_OFFSET,
  84. //
  85. // Required General Statistics
  86. //
  87. OID_GEN_XMIT_OK,
  88. OID_GEN_RCV_OK,
  89. OID_GEN_XMIT_ERROR,
  90. OID_GEN_RCV_ERROR,
  91. OID_GEN_RCV_NO_BUFFER,
  92. //
  93. // Optional General Statistics
  94. //
  95. OID_GEN_DIRECTED_BYTES_XMIT,
  96. OID_GEN_DIRECTED_FRAMES_XMIT,
  97. OID_GEN_MULTICAST_BYTES_XMIT,
  98. OID_GEN_MULTICAST_FRAMES_XMIT,
  99. OID_GEN_BROADCAST_BYTES_XMIT,
  100. OID_GEN_BROADCAST_FRAMES_XMIT,
  101. OID_GEN_DIRECTED_BYTES_RCV,
  102. OID_GEN_DIRECTED_FRAMES_RCV,
  103. OID_GEN_MULTICAST_BYTES_RCV,
  104. OID_GEN_MULTICAST_FRAMES_RCV,
  105. OID_GEN_BROADCAST_BYTES_RCV,
  106. OID_GEN_BROADCAST_FRAMES_RCV,
  107. OID_GEN_RCV_CRC_ERROR,
  108. OID_GEN_TRANSMIT_QUEUE_LENGTH,
  109. //
  110. // Required 802.3 OIDs
  111. //
  112. OID_802_3_PERMANENT_ADDRESS,
  113. OID_802_3_CURRENT_ADDRESS,
  114. OID_802_3_MULTICAST_LIST,
  115. OID_802_3_MAXIMUM_LIST_SIZE,
  116. OID_802_3_MAC_OPTIONS,
  117. OID_802_3_RCV_ERROR_ALIGNMENT,
  118. OID_802_3_XMIT_ONE_COLLISION,
  119. OID_802_3_XMIT_MORE_COLLISIONS,
  120. };
  121. //////////////////////////////////////////////////////////
  122. //
  123. //$BUGBUG - Fix Permanent Ethernet Address
  124. //
  125. //
  126. UCHAR rgchPermanentAddress[ETHERNET_ADDRESS_LENGTH] =
  127. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  128. //$BUGBUG - Fix Ethernet Station Address
  129. UCHAR rgchStationAddress[ETHERNET_ADDRESS_LENGTH] =
  130. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  131. NTSTATUS
  132. ntInitializeDriverObject(
  133. PDRIVER_OBJECT *ppDriverObject
  134. );
  135. VOID
  136. vSetDriverDispatchTable(
  137. PDRIVER_OBJECT pDriverObject
  138. );
  139. VOID
  140. vUnload(
  141. IN PDRIVER_OBJECT pDriverObject
  142. )
  143. {
  144. return;
  145. }
  146. //////////////////////////////////////////////////////////////////////////////
  147. NTSTATUS
  148. NdisDriverInitialize (
  149. IN PDRIVER_OBJECT DriverObject,
  150. IN PUNICODE_STRING RegistryPath,
  151. IN PNDIS_HANDLE pNdishWrapper
  152. )
  153. //////////////////////////////////////////////////////////////////////////////
  154. {
  155. NTSTATUS ntStatus = STATUS_SUCCESS;
  156. NDIS_STATUS nsResult = NDIS_STATUS_SUCCESS;
  157. //
  158. // NDIS data
  159. //
  160. NDIS_MINIPORT_CHARACTERISTICS ndisMiniChar = {0};
  161. NDIS_HANDLE ndishWrapper = {0};
  162. TEST_DEBUG (TEST_DBG_TRACE, ("NdisDriverInitialize Called\n"));
  163. //
  164. // Initialize Driver Object.
  165. // NOTE: The value of pDriverObject may change.
  166. //
  167. #ifdef WIN9X
  168. ntStatus = ntInitializeDriverObject(&DriverObject);
  169. if (ntStatus != STATUS_SUCCESS)
  170. {
  171. goto ret;
  172. }
  173. #endif
  174. //////////////////////////////////////////////////////
  175. //
  176. // Initialize the NDIS wrapper.
  177. //
  178. NdisMInitializeWrapper (&ndishWrapper,
  179. DriverObject,
  180. RegistryPath,
  181. NULL);
  182. //////////////////////////////////////////////////////
  183. //
  184. // Initialize the Miniport Dispatch Table
  185. //
  186. ndisMiniChar.MajorNdisVersion = 4;
  187. ndisMiniChar.MinorNdisVersion = 0;
  188. #ifdef NDIS30
  189. ndisMiniChar.Flags = 0;
  190. #endif // NDIS30
  191. ndisMiniChar.HaltHandler = NdisIPHalt;
  192. ndisMiniChar.InitializeHandler = NdisIPInitialize;
  193. ndisMiniChar.QueryInformationHandler = NdisIPQueryInformation;
  194. ndisMiniChar.ResetHandler = NdisIPReset;
  195. ndisMiniChar.SendHandler = NdisIPSend;
  196. ndisMiniChar.SetInformationHandler = NdisIPSetInformation;
  197. ndisMiniChar.ReturnPacketHandler = NdisIPReturnPacket;
  198. //
  199. // Register the miniport driver
  200. //
  201. nsResult = NdisMRegisterMiniport (ndishWrapper, &ndisMiniChar, sizeof(ndisMiniChar));
  202. if (nsResult != NDIS_STATUS_SUCCESS)
  203. {
  204. ntStatus = STATUS_UNSUCCESSFUL;
  205. goto ret;
  206. }
  207. *pNdishWrapper = ndishWrapper;
  208. #ifdef WIN9X
  209. vSetDriverDispatchTable (DriverObject);
  210. #endif
  211. ret:
  212. TEST_DEBUG (TEST_DBG_TRACE, ("NdisDriverInitialize Called, ntStatus = %08X\n", ntStatus));
  213. return ntStatus;
  214. }
  215. ///////////////////////////////////////////////////////////////////////////////////
  216. extern
  217. NDIS_STATUS
  218. NdisIPInitialize(
  219. OUT PNDIS_STATUS pnsOpenResult,
  220. OUT PUINT puiSelectedMedium,
  221. IN PNDIS_MEDIUM pNdisMediumArray,
  222. IN UINT ucNdispNdisMediumArrayEntries,
  223. IN NDIS_HANDLE ndishAdapterContext,
  224. IN NDIS_HANDLE ndishWrapperConfiguration
  225. )
  226. ///////////////////////////////////////////////////////////////////////////////////
  227. {
  228. NDIS_STATUS nsResult = NDIS_STATUS_SUCCESS;
  229. NDIS_HANDLE ndishConfiguration = NULL;
  230. PADAPTER pAdapter = NULL;
  231. UINT uTemp = 0;
  232. TEST_DEBUG (TEST_DBG_TRACE, ("NdisInitialize handler called\n"));
  233. //
  234. // Search for the medium type (DSS) in the given array.
  235. //
  236. for ( uTemp = 0; uTemp < ucNdispNdisMediumArrayEntries; uTemp++)
  237. {
  238. if (pNdisMediumArray[uTemp] == NdisMedium802_3)
  239. {
  240. break;
  241. }
  242. }
  243. if (uTemp == ucNdispNdisMediumArrayEntries)
  244. {
  245. return NDIS_STATUS_UNSUPPORTED_MEDIA;
  246. }
  247. ASSERT(puiSelectedMedium);
  248. if(puiSelectedMedium==NULL)
  249. {
  250. return NDIS_STATUS_FAILURE;
  251. }
  252. *puiSelectedMedium = uTemp;
  253. nsResult = CreateAdapter (&pAdapter, global_ndishWrapper, ndishAdapterContext);
  254. if (nsResult != NDIS_STATUS_SUCCESS)
  255. {
  256. return nsResult;
  257. }
  258. //
  259. // Initialize the information used to do indicates with
  260. //
  261. Adapter_IndicateReset (pAdapter);
  262. TEST_DEBUG (TEST_DBG_TRACE, ("NdisInitialize Handler Completed, nsResult = %08x\n", nsResult));
  263. return nsResult;
  264. }
  265. //////////////////////////////////////////////////////////////////////////////
  266. // Removes an adapter that was previously initialized.
  267. //
  268. extern
  269. VOID
  270. NdisIPHalt(
  271. IN NDIS_HANDLE ndishAdapter
  272. )
  273. //////////////////////////////////////////////////////////////////////////////
  274. {
  275. PADAPTER pAdapter = (PADAPTER) ndishAdapter;
  276. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPHalt Handler Called\n"));
  277. #ifndef WIN9X
  278. //
  279. // Deregister our device interface. This should shut down the link to the
  280. // streaming component.
  281. //
  282. NdisMDeregisterDevice(pAdapter->ndisDeviceHandle);
  283. #endif
  284. //
  285. // Signal the Streaming component that we're halting.
  286. //
  287. if (pAdapter)
  288. {
  289. if (pAdapter->pFilter)
  290. {
  291. if (pAdapter->pFilter->lpVTable->IndicateStatus)
  292. {
  293. pAdapter->pFilter->lpVTable->IndicateStatus (pAdapter->pFilter, IPSINK_EVENT_SHUTDOWN);
  294. //
  295. // Release the filter reference
  296. //
  297. pAdapter->pFilter->lpVTable->Release (pAdapter->pFilter);
  298. //
  299. // Release the frame pool
  300. //
  301. pAdapter->pFramePool->lpVTable->Release (pAdapter->pFramePool);
  302. }
  303. }
  304. }
  305. //
  306. // Release the adapter
  307. //
  308. pAdapter->lpVTable->Release (pAdapter);
  309. return;
  310. }
  311. //////////////////////////////////////////////////////////////////////////////////////
  312. // The TestReset request, instructs the Miniport to issue
  313. // a hardware reset to the network adapter. The driver also
  314. // resets its software state. See the description of NdisMReset
  315. // for a detailed description of this request.
  316. //
  317. NDIS_STATUS
  318. NdisIPReset(
  319. OUT PBOOLEAN pfAddressingReset,
  320. IN NDIS_HANDLE ndishAdapter
  321. )
  322. //////////////////////////////////////////////////////////////////////////////////////
  323. {
  324. NDIS_STATUS nsResult = NDIS_STATUS_SUCCESS;
  325. PADAPTER pAdapter = (PADAPTER) ndishAdapter;
  326. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPRest Handler Called\n"));
  327. nsResult = NDIS_STATUS_NOT_RESETTABLE;
  328. return nsResult;
  329. }
  330. //////////////////////////////////////////////////////////////////////////////////////
  331. NDIS_STATUS
  332. NdisIPQueryInformation (
  333. NDIS_HANDLE ndishAdapter,
  334. NDIS_OID ndisOid,
  335. PVOID pvInformationBuffer,
  336. ULONG dwcbInformationBuffer,
  337. PULONG pdwBytesWritten,
  338. PULONG pdwBytesNeeded
  339. )
  340. //////////////////////////////////////////////////////////////////////////////////////
  341. {
  342. NDIS_STATUS nsResult = NDIS_STATUS_SUCCESS;
  343. PADAPTER pAdapter = (PADAPTER) ndishAdapter;
  344. ULONG ulcbWritten = 0;
  345. ULONG ulcbNeeded = 0;
  346. //
  347. // These variables hold the result of queries on General OIDS.
  348. //
  349. NDIS_HARDWARE_STATUS ndisHardwareStatus = NdisHardwareStatusReady;
  350. NDIS_MEDIUM ndisMedium = NdisMedium802_3;
  351. ULONG dwGeneric = 0;
  352. USHORT wGeneric = 0;
  353. UINT ucbToMove = 0;
  354. PUCHAR pbMoveSource = NULL;
  355. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPQuery Handler Called, ndsOid: %08X\n", ndisOid));
  356. if (!pAdapter || !pdwBytesWritten || !pdwBytesNeeded)
  357. {
  358. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPQuery Handler Complete, nsResult: NDIS_STATUS_INVALID_DATA,\n"));
  359. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPQuery Handler pAdapter: %08X pdwBytesWritten: %08X pdwBytesNeeded: %08X\n",
  360. pAdapter, pdwBytesWritten, pdwBytesNeeded));
  361. return (NDIS_STATUS_INVALID_DATA);
  362. }
  363. //
  364. // Process OID's
  365. //
  366. pbMoveSource = (PUCHAR) (&dwGeneric);
  367. ulcbWritten = sizeof(ULONG);
  368. NdisAcquireSpinLock(&pAdapter->ndisSpinLock);
  369. switch (ndisOid)
  370. {
  371. case OID_GEN_MEDIA_CAPABILITIES:
  372. dwGeneric = NDIS_MEDIA_CAP_RECEIVE;
  373. break;
  374. case OID_GEN_MAC_OPTIONS:
  375. dwGeneric = (ULONG) ( NDIS_MAC_OPTION_TRANSFERS_NOT_PEND
  376. | NDIS_MAC_OPTION_RECEIVE_SERIALIZED
  377. | NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA
  378. | NDIS_MAC_OPTION_NO_LOOPBACK);
  379. break;
  380. case OID_GEN_SUPPORTED_LIST:
  381. pbMoveSource = (PUCHAR) (SupportedOids);
  382. ulcbWritten = sizeof(SupportedOids);
  383. break;
  384. case OID_GEN_MEDIA_SUPPORTED:
  385. case OID_GEN_MEDIA_IN_USE:
  386. pbMoveSource = (PUCHAR) (&ndisMedium);
  387. ulcbWritten = sizeof(NDIS_MEDIUM);
  388. break;
  389. case OID_GEN_MAXIMUM_LOOKAHEAD:
  390. dwGeneric = BDA_802_3_MAX_LOOKAHEAD;
  391. break;
  392. case OID_GEN_MAXIMUM_SEND_PACKETS:
  393. dwGeneric = 1;
  394. break;
  395. case OID_GEN_MAXIMUM_FRAME_SIZE:
  396. dwGeneric = BDA_802_3_MAX_LOOKAHEAD;
  397. break;
  398. case OID_GEN_MAXIMUM_TOTAL_SIZE:
  399. dwGeneric = (ULONG)(BDA_802_3_MAX_PACKET);
  400. break;
  401. case OID_GEN_TRANSMIT_BUFFER_SPACE:
  402. dwGeneric = (ULONG)(BDA_802_3_MAX_PACKET);
  403. break;
  404. case OID_GEN_TRANSMIT_BLOCK_SIZE:
  405. dwGeneric = BDA_802_3_MAX_LOOKAHEAD;
  406. break;
  407. case OID_GEN_RECEIVE_BLOCK_SIZE:
  408. dwGeneric = BDA_802_3_MAX_LOOKAHEAD;
  409. break;
  410. case OID_GEN_CURRENT_LOOKAHEAD:
  411. dwGeneric = BDA_802_3_MAX_LOOKAHEAD;
  412. break;
  413. case OID_GEN_CURRENT_PACKET_FILTER:
  414. dwGeneric = (ULONG) pAdapter->ulPacketFilter;
  415. break;
  416. case OID_GEN_XMIT_OK:
  417. dwGeneric = pAdapter->stats.ulOID_GEN_XMIT_OK;
  418. break;
  419. case OID_GEN_RCV_OK:
  420. dwGeneric = pAdapter->stats.ulOID_GEN_RCV_OK;
  421. break;
  422. case OID_GEN_XMIT_ERROR:
  423. dwGeneric = pAdapter->stats.ulOID_GEN_XMIT_ERROR;
  424. break;
  425. case OID_GEN_RCV_ERROR:
  426. dwGeneric = pAdapter->stats.ulOID_GEN_RCV_ERROR;
  427. break;
  428. case OID_GEN_RCV_NO_BUFFER:
  429. dwGeneric = pAdapter->stats.ulOID_GEN_RCV_NO_BUFFER;
  430. break;
  431. case OID_GEN_DIRECTED_BYTES_XMIT:
  432. dwGeneric = pAdapter->stats.ulOID_GEN_DIRECTED_BYTES_XMIT;
  433. break;
  434. case OID_GEN_DIRECTED_FRAMES_XMIT:
  435. dwGeneric = pAdapter->stats.ulOID_GEN_DIRECTED_FRAMES_XMIT;
  436. break;
  437. case OID_GEN_MULTICAST_BYTES_XMIT:
  438. dwGeneric = pAdapter->stats.ulOID_GEN_MULTICAST_BYTES_XMIT;
  439. break;
  440. case OID_GEN_MULTICAST_FRAMES_XMIT:
  441. dwGeneric = pAdapter->stats.ulOID_GEN_MULTICAST_FRAMES_XMIT;
  442. break;
  443. case OID_GEN_BROADCAST_BYTES_XMIT:
  444. dwGeneric = pAdapter->stats.ulOID_GEN_BROADCAST_BYTES_XMIT;
  445. break;
  446. case OID_GEN_BROADCAST_FRAMES_XMIT:
  447. dwGeneric = pAdapter->stats.ulOID_GEN_BROADCAST_FRAMES_XMIT;
  448. break;
  449. case OID_GEN_DIRECTED_BYTES_RCV:
  450. dwGeneric = pAdapter->stats.ulOID_GEN_DIRECTED_BYTES_RCV;
  451. break;
  452. case OID_GEN_DIRECTED_FRAMES_RCV:
  453. dwGeneric = pAdapter->stats.ulOID_GEN_DIRECTED_FRAMES_RCV;
  454. break;
  455. case OID_GEN_MULTICAST_BYTES_RCV:
  456. dwGeneric = pAdapter->stats.ulOID_GEN_MULTICAST_BYTES_RCV;
  457. break;
  458. case OID_GEN_MULTICAST_FRAMES_RCV:
  459. dwGeneric = pAdapter->stats.ulOID_GEN_MULTICAST_FRAMES_RCV;
  460. break;
  461. case OID_GEN_BROADCAST_BYTES_RCV:
  462. dwGeneric = pAdapter->stats.ulOID_GEN_BROADCAST_BYTES_RCV;
  463. break;
  464. case OID_GEN_BROADCAST_FRAMES_RCV:
  465. dwGeneric = pAdapter->stats.ulOID_GEN_BROADCAST_FRAMES_RCV;
  466. break;
  467. case OID_GEN_RCV_CRC_ERROR:
  468. dwGeneric = pAdapter->stats.ulOID_GEN_RCV_CRC_ERROR;
  469. break;
  470. case OID_GEN_TRANSMIT_QUEUE_LENGTH:
  471. dwGeneric = pAdapter->stats.ulOID_GEN_TRANSMIT_QUEUE_LENGTH;
  472. break;
  473. case OID_802_3_RCV_ERROR_ALIGNMENT:
  474. dwGeneric = 0;
  475. break;
  476. case OID_802_3_XMIT_ONE_COLLISION:
  477. dwGeneric = 0;
  478. break;
  479. case OID_802_3_XMIT_MORE_COLLISIONS:
  480. dwGeneric = 0;
  481. break;
  482. case OID_802_3_PERMANENT_ADDRESS:
  483. pbMoveSource = (PVOID)(rgchPermanentAddress);
  484. ulcbWritten = sizeof(rgchPermanentAddress);
  485. break;
  486. case OID_802_3_CURRENT_ADDRESS:
  487. pbMoveSource = (PVOID)(rgchStationAddress);
  488. ulcbWritten = sizeof(rgchStationAddress);
  489. break;
  490. case OID_802_3_MAXIMUM_LIST_SIZE:
  491. dwGeneric = MULTICAST_LIST_SIZE;
  492. break;
  493. case OID_GEN_HARDWARE_STATUS:
  494. ndisHardwareStatus = NdisHardwareStatusReady;
  495. pbMoveSource = (PUCHAR)(&ndisHardwareStatus);
  496. ulcbWritten = sizeof(NDIS_HARDWARE_STATUS);
  497. break;
  498. case OID_GEN_LINK_SPEED:
  499. dwGeneric = (ULONG)(300000);
  500. break;
  501. case OID_GEN_RECEIVE_BUFFER_SPACE:
  502. dwGeneric = BDA_802_3_MAX_PACKET * 20;
  503. break;
  504. case OID_GEN_DRIVER_VERSION:
  505. dwGeneric = ((USHORT) 4 << 8) | 0;
  506. pbMoveSource = (PVOID)(&dwGeneric);
  507. ulcbWritten = sizeof(dwGeneric);
  508. break;
  509. case OID_GEN_VENDOR_ID:
  510. wGeneric = (USHORT) 0xDDDD; // BOGUS ID
  511. pbMoveSource = (PVOID)(&wGeneric);
  512. ulcbWritten = sizeof(wGeneric);
  513. break;
  514. case OID_GEN_VENDOR_DESCRIPTION:
  515. pbMoveSource = (PVOID) pAdapter->pVendorDescription;
  516. ulcbWritten = MyStrLen (pAdapter->pVendorDescription);
  517. break;
  518. case OID_GEN_VENDOR_DRIVER_VERSION:
  519. dwGeneric = 0x0401;
  520. pbMoveSource = (PVOID)(&dwGeneric);
  521. ulcbWritten = sizeof(dwGeneric);
  522. break;
  523. case OID_GEN_MEDIA_CONNECT_STATUS:
  524. dwGeneric = NdisMediaStateConnected;
  525. break;
  526. case OID_802_3_MAC_OPTIONS:
  527. dwGeneric = 0;
  528. break;
  529. case OID_PNP_CAPABILITIES:
  530. dwGeneric = 0;
  531. break;
  532. case OID_802_3_MULTICAST_LIST:
  533. pbMoveSource = (PVOID)(pAdapter->multicastList[0]);
  534. ulcbWritten = pAdapter->ulcbMulticastListEntries;
  535. break;
  536. case OID_PNP_QUERY_POWER:
  537. nsResult = NDIS_STATUS_SUCCESS;
  538. ulcbWritten = 0;
  539. break;
  540. case OID_TCP_TASK_OFFLOAD:
  541. case OID_TCP_TASK_IPSEC_ADD_SA:
  542. case OID_TCP_TASK_IPSEC_DELETE_SA:
  543. case OID_TCP_SAN_SUPPORT:
  544. case OID_FFP_SUPPORT:
  545. case OID_FFP_FLUSH:
  546. case OID_FFP_CONTROL:
  547. case OID_FFP_PARAMS:
  548. case OID_FFP_DATA:
  549. case OID_FFP_DRIVER_STATS:
  550. case OID_FFP_ADAPTER_STATS:
  551. case OID_PNP_WAKE_UP_OK:
  552. case OID_PNP_WAKE_UP_ERROR:
  553. nsResult = NDIS_STATUS_NOT_SUPPORTED;
  554. break;
  555. default:
  556. //
  557. nsResult = NDIS_STATUS_INVALID_OID;
  558. break;
  559. }
  560. //
  561. // First take care of the case where the size of the output buffer is
  562. // zero, or the pointer to the buffer is NULL
  563. //
  564. if (nsResult == NDIS_STATUS_SUCCESS)
  565. {
  566. ulcbNeeded = ulcbWritten;
  567. if (ulcbWritten > dwcbInformationBuffer)
  568. {
  569. //
  570. // There isn't enough room in InformationBuffer.
  571. // Don't move any of the info.
  572. //
  573. ulcbWritten = 0;
  574. nsResult = NDIS_STATUS_INVALID_LENGTH;
  575. }
  576. else if (ulcbNeeded && (pvInformationBuffer == NULL))
  577. {
  578. ulcbWritten = 0;
  579. nsResult = NDIS_STATUS_INVALID_LENGTH;
  580. }
  581. else if (ulcbNeeded)
  582. {
  583. //
  584. // Move the requested information into the info buffer.
  585. //
  586. NdisMoveMemory (pvInformationBuffer, pbMoveSource, ulcbWritten);
  587. }
  588. }
  589. //Release SpinLock
  590. NdisReleaseSpinLock(&pAdapter->ndisSpinLock);
  591. if (nsResult == NDIS_STATUS_SUCCESS)
  592. {
  593. //
  594. // A status of success always indicates 0 bytes needed.
  595. //
  596. *pdwBytesWritten = ulcbWritten;
  597. *pdwBytesNeeded = 0;
  598. }
  599. else if (nsResult == NDIS_STATUS_INVALID_LENGTH)
  600. {
  601. //
  602. // For us a failure status always indicates 0 bytes read.
  603. //
  604. *pdwBytesWritten = 0;
  605. *pdwBytesNeeded = ulcbNeeded;
  606. }
  607. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPQuery Handler Complete, nsResult: %08X\n", nsResult));
  608. return nsResult;
  609. }
  610. ////////////////////////////////////////////////////////////////////////
  611. extern
  612. NDIS_STATUS
  613. NdisIPSetInformation (
  614. NDIS_HANDLE ndishAdapterContext,
  615. NDIS_OID ndisOid,
  616. PVOID pvInformationBuffer,
  617. ULONG dwcbInformationBuffer,
  618. PULONG pdwBytesRead,
  619. PULONG pdwBytesNeeded
  620. )
  621. ////////////////////////////////////////////////////////////////////////
  622. {
  623. ULONG ulcbNeeded = 0;
  624. NDIS_STATUS nsResult = NDIS_STATUS_SUCCESS;
  625. PADAPTER pAdapter = (PADAPTER) ndishAdapterContext;
  626. #ifdef PFP
  627. ASSERT (pAdapter != NULL);
  628. ASSERT (pvInformationBuffer != NULL);
  629. ASSERT (pdwBytesRead != NULL);
  630. ASSERT (pdwBytesNeeded != NULL);
  631. #endif
  632. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPSetInfo Handler Called, ndsOid: %08X\n", ndisOid));
  633. if (!pAdapter || !pvInformationBuffer || !pdwBytesRead || !pdwBytesNeeded)
  634. {
  635. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPSetInfo Handler returns Invalid data\n"));
  636. return (NDIS_STATUS_INVALID_DATA);
  637. }
  638. NdisAcquireSpinLock(&pAdapter->ndisSpinLock);
  639. switch (ndisOid)
  640. {
  641. case OID_GEN_CURRENT_PACKET_FILTER:
  642. {
  643. pAdapter->ulPacketFilter = * ((PULONG) pvInformationBuffer);
  644. *pdwBytesRead = 4;
  645. }
  646. break;
  647. case OID_GEN_CURRENT_LOOKAHEAD:
  648. if (dwcbInformationBuffer != 4)
  649. {
  650. nsResult = NDIS_STATUS_INVALID_LENGTH;
  651. *pdwBytesRead = 0;
  652. break;
  653. }
  654. //
  655. // Current Lookahead is not set this way so just ignore the
  656. // data.
  657. //
  658. *pdwBytesRead = 4;
  659. break;
  660. case OID_802_3_MULTICAST_LIST:
  661. // If our current multicast address buffer isn't big
  662. // enough, then free it.
  663. //
  664. if (dwcbInformationBuffer > sizeof (pAdapter->multicastList))
  665. {
  666. nsResult = NDIS_STATUS_RESOURCES;
  667. break;
  668. }
  669. // Copy the Multicast List.
  670. //
  671. RtlCopyMemory (pAdapter->multicastList,
  672. pvInformationBuffer,
  673. dwcbInformationBuffer
  674. );
  675. pAdapter->ulcbMulticastListEntries = dwcbInformationBuffer;
  676. //
  677. // Now we send the multicast list to the stream component so
  678. // it can get passed on to the net provider filter
  679. //
  680. if (pAdapter)
  681. {
  682. if (pAdapter->pFilter)
  683. {
  684. if (pAdapter->pFilter->lpVTable->SetMulticastList)
  685. {
  686. pAdapter->pFilter->lpVTable->SetMulticastList (
  687. pAdapter->pFilter,
  688. pAdapter->multicastList,
  689. pAdapter->ulcbMulticastListEntries
  690. );
  691. }
  692. }
  693. }
  694. break;
  695. case OID_802_3_PERMANENT_ADDRESS:
  696. if (dwcbInformationBuffer > ETHERNET_ADDRESS_LENGTH)
  697. {
  698. nsResult = NDIS_STATUS_RESOURCES;
  699. break;
  700. }
  701. RtlCopyMemory (rgchPermanentAddress,
  702. pvInformationBuffer,
  703. dwcbInformationBuffer
  704. );
  705. break;
  706. case OID_802_3_CURRENT_ADDRESS:
  707. if (dwcbInformationBuffer > ETHERNET_ADDRESS_LENGTH)
  708. {
  709. nsResult = NDIS_STATUS_RESOURCES;
  710. break;
  711. }
  712. RtlCopyMemory (rgchStationAddress,
  713. pvInformationBuffer,
  714. dwcbInformationBuffer
  715. );
  716. break;
  717. case OID_PNP_SET_POWER:
  718. nsResult = NDIS_STATUS_SUCCESS;
  719. ulcbNeeded = 0;
  720. break;
  721. default:
  722. nsResult = NDIS_STATUS_INVALID_OID;
  723. *pdwBytesRead = 0;
  724. ulcbNeeded = 0;
  725. break;
  726. }
  727. NdisReleaseSpinLock(&pAdapter->ndisSpinLock);
  728. if (nsResult == NDIS_STATUS_SUCCESS)
  729. {
  730. //
  731. // A status of success always indicates 0 bytes needed.
  732. //
  733. *pdwBytesRead = dwcbInformationBuffer;
  734. *pdwBytesNeeded = 0;
  735. }
  736. else
  737. {
  738. //
  739. // A failure status always indicates 0 bytes read.
  740. //
  741. *pdwBytesRead = 0;
  742. *pdwBytesNeeded = ulcbNeeded;
  743. }
  744. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPSetInfo Handler Complete, nsResult: %08X\n", nsResult));
  745. return nsResult;
  746. }
  747. //////////////////////////////////////////////////////////////////////////////////////
  748. VOID
  749. NdisIPReturnPacket(
  750. IN NDIS_HANDLE ndishAdapterContext,
  751. IN PNDIS_PACKET pNdisPacket
  752. )
  753. //////////////////////////////////////////////////////////////////////////////////////
  754. {
  755. PFRAME pFrame = NULL;
  756. ULONG ulMediaSpecificInfoSize;
  757. PIPSINK_MEDIA_SPECIFIC_INFORAMTION pMediaSpecificInfo;
  758. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPReturnPacket Handler Called\n"));
  759. NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO (pNdisPacket,&pMediaSpecificInfo,&ulMediaSpecificInfoSize);
  760. //
  761. // Make sure we free up any frames
  762. //
  763. if (pMediaSpecificInfo)
  764. {
  765. pFrame = (PFRAME) pMediaSpecificInfo->pFrame;
  766. ASSERT(pFrame);
  767. }
  768. //
  769. // NDIS is through with the packet so we need to free it
  770. // here.
  771. //
  772. NdisFreePacket (pNdisPacket);
  773. //
  774. // Put Frame back on available queue.
  775. //
  776. if (pFrame)
  777. {
  778. //
  779. // Release this frame since we're done using it
  780. //
  781. pFrame->lpVTable->Release (pFrame);
  782. //
  783. // Store the frame back on the available queue
  784. //
  785. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPReturnPacket: Putting frame %08X back on Available Queue\n", pFrame));
  786. PutFrame (pFrame->pFramePool, &pFrame->pFramePool->leAvailableQueue, pFrame);
  787. }
  788. return;
  789. }
  790. //////////////////////////////////////////////////////////////////////////////
  791. NDIS_STATUS
  792. NdisIPSend(
  793. IN NDIS_HANDLE ndishAdapterContext,
  794. IN PNDIS_PACKET Packet,
  795. IN UINT Flags
  796. )
  797. //////////////////////////////////////////////////////////////////////////////
  798. {
  799. PADAPTER pAdapter = (PADAPTER) ndishAdapterContext;
  800. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPSend Handler Called\n"));
  801. NdisAcquireSpinLock(&pAdapter->ndisSpinLock);
  802. pAdapter->stats.ulOID_GEN_XMIT_ERROR += 1;
  803. NdisReleaseSpinLock(&pAdapter->ndisSpinLock);
  804. return NDIS_STATUS_FAILURE;
  805. }
  806. //////////////////////////////////////////////////////////////////////////////
  807. extern VOID
  808. NdisIPShutdown(
  809. IN PVOID ShutdownContext
  810. )
  811. //////////////////////////////////////////////////////////////////////////////
  812. {
  813. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIPShutdown Handler Called\n"));
  814. //BREAK(0x10);
  815. }
  816. //////////////////////////////////////////////////////////////////////////////
  817. NTSTATUS
  818. RegisterDevice(
  819. IN PVOID NdisWrapperHandle,
  820. IN UNICODE_STRING *DeviceName,
  821. IN UNICODE_STRING *SymbolicName,
  822. IN PDRIVER_DISPATCH pDispatchTable[],
  823. OUT PDEVICE_OBJECT *pDeviceObject,
  824. OUT PVOID *NdisDeviceHandle
  825. )
  826. //////////////////////////////////////////////////////////////////////////////
  827. {
  828. NDIS_STATUS status;
  829. status = NdisMRegisterDevice ((NDIS_HANDLE) NdisWrapperHandle,
  830. DeviceName,
  831. SymbolicName,
  832. pDispatchTable,
  833. pDeviceObject,
  834. (NDIS_HANDLE *) NdisDeviceHandle);
  835. return (NTSTATUS) status;
  836. }
  837. //////////////////////////////////////////////////////////////////////////////
  838. NTSTATUS
  839. StreamIndicateEvent (
  840. IN PVOID pvEvent
  841. )
  842. //////////////////////////////////////////////////////////////////////////////
  843. {
  844. NTSTATUS ntStatus = STATUS_SUCCESS;
  845. //ntStatus = StreamIPIndicateEvent (pvEvent);
  846. return ntStatus;
  847. }
  848. //////////////////////////////////////////////////////////////////////////////
  849. NTSTATUS
  850. IndicateCallbackHandler (
  851. IN NDIS_HANDLE ndishMiniport,
  852. IN PINDICATE_CONTEXT pIndicateContext
  853. )
  854. //////////////////////////////////////////////////////////////////////////////
  855. {
  856. PFRAME pFrame = NULL;
  857. PVOID pvData = NULL;
  858. ULONG ulcbData = 0L;
  859. NTSTATUS ntStatus = STATUS_SUCCESS;
  860. PADAPTER pAdapter;
  861. pAdapter = pIndicateContext->pAdapter;
  862. //
  863. // Take the source data and stuff the data into a FRAME object
  864. //
  865. while ((pFrame = GetFrame (pAdapter->pFramePool, &pAdapter->pFramePool->leIndicateQueue)) != NULL)
  866. {
  867. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIP: Getting Frame (%08X) from Indicate Queue\n", pFrame));
  868. //
  869. // Indicate the NDIS packet
  870. //
  871. ntStatus = IndicateFrame (pFrame, pFrame->ulcbData);
  872. }
  873. if (pFrame == NULL)
  874. {
  875. TEST_DEBUG (TEST_DBG_TRACE, ("NdisIP: No more frames on Indicate Queue\n", pFrame));
  876. }
  877. //
  878. // Free up the context area. NOTE: this is alloc'ed in the indicate handler
  879. //
  880. FreeMemory (pIndicateContext, sizeof (INDICATE_CONTEXT));
  881. return ntStatus;
  882. }
  883.