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.

930 lines
33 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. PURPOSE.
  7. Module Name:
  8. Request.c
  9. Abstract:
  10. This module contains Miniport function and helper routines for handling
  11. Set & Query Information requests.
  12. Revision History:
  13. Notes:
  14. --*/
  15. #include "miniport.h"
  16. NDIS_OID NICSupportedOids[] =
  17. {
  18. OID_GEN_SUPPORTED_LIST,
  19. OID_GEN_HARDWARE_STATUS,
  20. OID_GEN_MEDIA_SUPPORTED,
  21. OID_GEN_MEDIA_IN_USE,
  22. OID_GEN_MAXIMUM_LOOKAHEAD,
  23. OID_GEN_MAXIMUM_FRAME_SIZE,
  24. OID_GEN_LINK_SPEED,
  25. OID_GEN_TRANSMIT_BUFFER_SPACE,
  26. OID_GEN_RECEIVE_BUFFER_SPACE,
  27. OID_GEN_TRANSMIT_BLOCK_SIZE,
  28. OID_GEN_RECEIVE_BLOCK_SIZE,
  29. OID_GEN_VENDOR_ID,
  30. OID_GEN_VENDOR_DESCRIPTION,
  31. OID_GEN_VENDOR_DRIVER_VERSION,
  32. OID_GEN_CURRENT_PACKET_FILTER,
  33. OID_GEN_CURRENT_LOOKAHEAD,
  34. OID_GEN_DRIVER_VERSION,
  35. OID_GEN_MAXIMUM_TOTAL_SIZE,
  36. OID_GEN_PROTOCOL_OPTIONS,
  37. OID_GEN_MAC_OPTIONS,
  38. OID_GEN_MEDIA_CONNECT_STATUS,
  39. OID_GEN_MAXIMUM_SEND_PACKETS,
  40. OID_GEN_XMIT_OK,
  41. OID_GEN_RCV_OK,
  42. OID_GEN_XMIT_ERROR,
  43. OID_GEN_RCV_ERROR,
  44. OID_GEN_RCV_NO_BUFFER,
  45. OID_GEN_RCV_CRC_ERROR,
  46. OID_GEN_TRANSMIT_QUEUE_LENGTH,
  47. OID_802_3_PERMANENT_ADDRESS,
  48. OID_802_3_CURRENT_ADDRESS,
  49. OID_802_3_MULTICAST_LIST,
  50. OID_802_3_MAC_OPTIONS,
  51. OID_802_3_MAXIMUM_LIST_SIZE,
  52. OID_802_3_RCV_ERROR_ALIGNMENT,
  53. OID_802_3_XMIT_ONE_COLLISION,
  54. OID_802_3_XMIT_MORE_COLLISIONS,
  55. OID_802_3_XMIT_DEFERRED,
  56. OID_802_3_XMIT_MAX_COLLISIONS,
  57. OID_802_3_RCV_OVERRUN,
  58. OID_802_3_XMIT_UNDERRUN,
  59. OID_802_3_XMIT_HEARTBEAT_FAILURE,
  60. OID_802_3_XMIT_TIMES_CRS_LOST,
  61. OID_802_3_XMIT_LATE_COLLISIONS,
  62. OID_PNP_CAPABILITIES,
  63. OID_PNP_SET_POWER,
  64. OID_PNP_QUERY_POWER,
  65. OID_PNP_ADD_WAKE_UP_PATTERN,
  66. OID_PNP_REMOVE_WAKE_UP_PATTERN,
  67. OID_PNP_ENABLE_WAKE_UP
  68. };
  69. NDIS_STATUS MPQueryInformation(
  70. IN NDIS_HANDLE MiniportAdapterContext,
  71. IN NDIS_OID Oid,
  72. IN PVOID InformationBuffer,
  73. IN ULONG InformationBufferLength,
  74. OUT PULONG BytesWritten,
  75. OUT PULONG BytesNeeded)
  76. /*++
  77. Routine Description:
  78. Entry point called by NDIS to query for the value of the specified OID.
  79. Arguments:
  80. MiniportAdapterContext Pointer to the adapter structure
  81. Oid Oid for this query
  82. InformationBuffer Buffer for information
  83. InformationBufferLength Size of this buffer
  84. BytesWritten Specifies how much info is written
  85. BytesNeeded In case the buffer is smaller than
  86. what we need, tell them how much is needed
  87. Return Value:
  88. Return code from the NdisRequest below.
  89. Notes: Read "Minimizing Miniport Driver Initialization Time" in the DDK
  90. for more info on how to handle certain OIDs that affect the init of
  91. a miniport.
  92. --*/
  93. {
  94. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  95. PMP_ADAPTER Adapter;
  96. NDIS_HARDWARE_STATUS HardwareStatus = NdisHardwareStatusReady;
  97. NDIS_MEDIUM Medium = NIC_MEDIA_TYPE;
  98. UCHAR VendorDesc[] = NIC_VENDOR_DESC;
  99. ULONG ulInfo;
  100. USHORT usInfo;
  101. ULONG64 ulInfo64;
  102. PVOID pInfo = (PVOID) &ulInfo;
  103. ULONG ulInfoLen = sizeof(ulInfo);
  104. DEBUGP(MP_LOUD, ("---> MPQueryInformation %s\n", DbgGetOidName(Oid)));
  105. Adapter = (PMP_ADAPTER) MiniportAdapterContext;
  106. // Initialize the result
  107. *BytesWritten = 0;
  108. *BytesNeeded = 0;
  109. switch(Oid)
  110. {
  111. case OID_GEN_SUPPORTED_LIST:
  112. //
  113. // The OID_GEN_SUPPORTED_LIST OID specifies an array of OIDs
  114. // for objects that the underlying driver or its NIC supports.
  115. // Objects include general, media-specific, and implementation-
  116. // specific objects. NDIS forwards a subset of the returned
  117. // list to protocols that make this query. That is, NDIS filters
  118. // any supported statistics OIDs out of the list because
  119. // protocols never make statistics queries.
  120. //
  121. pInfo = (PVOID) NICSupportedOids;
  122. ulInfoLen = sizeof(NICSupportedOids);
  123. break;
  124. case OID_GEN_HARDWARE_STATUS:
  125. //
  126. // Specify the current hardware status of the underlying NIC as
  127. // one of the following NDIS_HARDWARE_STATUS-type values.
  128. //
  129. pInfo = (PVOID) &HardwareStatus;
  130. ulInfoLen = sizeof(NDIS_HARDWARE_STATUS);
  131. break;
  132. case OID_GEN_MEDIA_SUPPORTED:
  133. //
  134. // Specify the media types that the NIC can support but not
  135. // necessarily the media types that the NIC currently uses.
  136. // fallthrough:
  137. case OID_GEN_MEDIA_IN_USE:
  138. //
  139. // Specifiy a complete list of the media types that the NIC
  140. // currently uses.
  141. //
  142. pInfo = (PVOID) &Medium;
  143. ulInfoLen = sizeof(NDIS_MEDIUM);
  144. break;
  145. case OID_GEN_CURRENT_LOOKAHEAD:
  146. case OID_GEN_MAXIMUM_LOOKAHEAD:
  147. //
  148. // If the miniport driver indicates received data by calling
  149. // NdisXxxIndicateReceive, it should respond to OID_GEN_MAXIMUM_LOOKAHEAD
  150. // with the maximum number of bytes the NIC can provide as
  151. // lookahead data. If that value is different from the size of the
  152. // lookahead buffer supported by bound protocols, NDIS will call
  153. // MiniportSetInformation to set the size of the lookahead buffer
  154. // provided by the miniport driver to the minimum of the miniport
  155. // driver and protocol(s) values. If the driver always indicates
  156. // up full packets with NdisMIndicateReceivePacket, it should
  157. // set this value to the maximum total packet size, which
  158. // excludes the header.
  159. // Upper-layer drivers examine lookahead data to determine whether
  160. // a packet that is associated with the lookahead data is intended
  161. // for one or more of their clients. If the underlying driver
  162. // supports multipacket receive indications, bound protocols are
  163. // given full net packets on every indication. Consequently,
  164. // this value is identical to that returned for
  165. // OID_GEN_RECEIVE_BLOCK_SIZE.
  166. //
  167. if(Adapter->ulLookAhead == 0)
  168. {
  169. Adapter->ulLookAhead = NIC_MAX_LOOKAHEAD;
  170. }
  171. ulInfo = Adapter->ulLookAhead;
  172. break;
  173. case OID_GEN_MAXIMUM_FRAME_SIZE:
  174. //
  175. // Specifiy the maximum network packet size, in bytes, that the
  176. // NIC supports excluding the header. A NIC driver that emulates
  177. // another medium type for binding to a transport must ensure that
  178. // the maximum frame size for a protocol-supplied net packet does
  179. // not exceed the size limitations for the true network medium.
  180. //
  181. ulInfo = ETH_MAX_PACKET_SIZE - ETH_HEADER_SIZE;
  182. break;
  183. case OID_GEN_MAXIMUM_TOTAL_SIZE:
  184. //
  185. // Specify the maximum total packet length, in bytes, the NIC
  186. // supports including the header. A protocol driver might use
  187. // this returned length as a gauge to determine the maximum
  188. // size packet that a NIC driver could forward to the
  189. // protocol driver. The miniport driver must never indicate
  190. // up to the bound protocol driver packets received over the
  191. // network that are longer than the packet size specified by
  192. // OID_GEN_MAXIMUM_TOTAL_SIZE.
  193. //
  194. case OID_GEN_TRANSMIT_BLOCK_SIZE:
  195. //
  196. // The OID_GEN_TRANSMIT_BLOCK_SIZE OID specifies the minimum
  197. // number of bytes that a single net packet occupies in the
  198. // transmit buffer space of the NIC. For example, a NIC that
  199. // has a transmit space divided into 256-byte pieces would have
  200. // a transmit block size of 256 bytes. To calculate the total
  201. // transmit buffer space on such a NIC, its driver multiplies
  202. // the number of transmit buffers on the NIC by its transmit
  203. // block size. In our case, the transmit block size is
  204. // identical to its maximum packet size.
  205. case OID_GEN_RECEIVE_BLOCK_SIZE:
  206. //
  207. // The OID_GEN_RECEIVE_BLOCK_SIZE OID specifies the amount of
  208. // storage, in bytes, that a single packet occupies in the receive
  209. // buffer space of the NIC.
  210. //
  211. ulInfo = (ULONG) ETH_MAX_PACKET_SIZE;
  212. break;
  213. case OID_GEN_MAC_OPTIONS:
  214. //
  215. // Specify a bitmask that defines optional properties of the NIC.
  216. // This miniport indicates receive with NdisMIndicateReceivePacket
  217. // function. It has no MiniportTransferData function. Such a driver
  218. // should set this NDIS_MAC_OPTION_TRANSFERS_NOT_PEND flag.
  219. //
  220. // NDIS_MAC_OPTION_NO_LOOPBACK tells NDIS that NIC has no internal
  221. // loopback support so NDIS will manage loopbacks on behalf of
  222. // this driver.
  223. //
  224. // NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA tells the protocol that
  225. // our receive buffer is not on a device-specific card. If
  226. // NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA is not set, multi-buffer
  227. // indications are copied to a single flat buffer.
  228. //
  229. ulInfo = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |
  230. NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
  231. NDIS_MAC_OPTION_NO_LOOPBACK;
  232. break;
  233. case OID_GEN_LINK_SPEED:
  234. //
  235. // Specify the maximum speed of the NIC in kbps.
  236. //
  237. ulInfo = Adapter->ulLinkSpeed;
  238. break;
  239. case OID_GEN_TRANSMIT_BUFFER_SPACE:
  240. //
  241. // Specify the amount of memory, in bytes, on the NIC that
  242. // is available for buffering transmit data. A protocol can
  243. // use this OID as a guide for sizing the amount of transmit
  244. // data per send.
  245. //
  246. ulInfo = ETH_MAX_PACKET_SIZE * Adapter->ulMaxBusySends;
  247. break;
  248. case OID_GEN_RECEIVE_BUFFER_SPACE:
  249. //
  250. // Specify the amount of memory on the NIC that is available
  251. // for buffering receive data. A protocol driver can use this
  252. // OID as a guide for advertising its receive window after it
  253. // establishes sessions with remote nodes.
  254. //
  255. ulInfo = ETH_MAX_PACKET_SIZE * Adapter->ulMaxBusyRecvs;
  256. break;
  257. case OID_GEN_VENDOR_ID:
  258. //
  259. // Specify a three-byte IEEE-registered vendor code, followed
  260. // by a single byte that the vendor assigns to identify a
  261. // particular NIC. The IEEE code uniquely identifies the vendor
  262. // and is the same as the three bytes appearing at the beginning
  263. // of the NIC hardware address. Vendors without an IEEE-registered
  264. // code should use the value 0xFFFFFF.
  265. //
  266. ulInfo = NIC_VENDOR_ID;
  267. break;
  268. case OID_GEN_VENDOR_DESCRIPTION:
  269. //
  270. // Specify a zero-terminated string describing the NIC vendor.
  271. //
  272. pInfo = VendorDesc;
  273. ulInfoLen = sizeof(VendorDesc);
  274. break;
  275. case OID_GEN_VENDOR_DRIVER_VERSION:
  276. //
  277. // Specify the vendor-assigned version number of the NIC driver.
  278. // The low-order half of the return value specifies the minor
  279. // version; the high-order half specifies the major version.
  280. //
  281. ulInfo = NIC_VENDOR_DRIVER_VERSION;
  282. break;
  283. case OID_GEN_DRIVER_VERSION:
  284. //
  285. // Specify the NDIS version in use by the NIC driver. The high
  286. // byte is the major version number; the low byte is the minor
  287. // version number.
  288. //
  289. usInfo = (USHORT) (MP_NDIS_MAJOR_VERSION<<8) + MP_NDIS_MINOR_VERSION;
  290. pInfo = (PVOID) &usInfo;
  291. ulInfoLen = sizeof(USHORT);
  292. break;
  293. case OID_GEN_MAXIMUM_SEND_PACKETS:
  294. //
  295. // If a miniport driver registers a MiniportSendPackets function,
  296. // MiniportQueryInformation will be called with the
  297. // OID_GEN_MAXIMUM_SEND_PACKETS request. The miniport driver must
  298. // respond with the maximum number of packets it is prepared to
  299. // handle on a single send request. The miniport driver should
  300. // pick a maximum that minimizes the number of packets that it
  301. // has to queue internally because it has no resources
  302. // (its device is full). A miniport driver for a bus-master DMA
  303. // NIC should attempt to pick a value that keeps its NIC filled
  304. // under anticipated loads.
  305. //
  306. ulInfo = NIC_MAX_SEND_PKTS;
  307. break;
  308. case OID_GEN_MEDIA_CONNECT_STATUS:
  309. //
  310. // Return the connection status of the NIC on the network as one
  311. // of the following system-defined values: NdisMediaStateConnected
  312. // or NdisMediaStateDisconnected.
  313. //
  314. ulInfo = NICGetMediaConnectStatus(Adapter);
  315. break;
  316. case OID_GEN_CURRENT_PACKET_FILTER:
  317. //
  318. // Specifiy the types of net packets such as directed, broadcast
  319. // multicast, for which a protocol receives indications from a
  320. // NIC driver. After NIC is initialized, a protocol driver
  321. // can send a set OID_GEN_CURRENT_PACKET_FILTER to a non-zero value,
  322. // thereby enabling the miniport driver to indicate receive packets
  323. // to that protocol.
  324. //
  325. ulInfo = Adapter->PacketFilter;
  326. break;
  327. case OID_PNP_CAPABILITIES:
  328. //
  329. // Return the wake-up capabilities of its NIC. If you return
  330. // NDIS_STATUS_NOT_SUPPORTED, NDIS considers the miniport driver
  331. // to be not Power management aware and doesn't send any power
  332. // or wake-up related queries such as
  333. // OID_PNP_SET_POWER, OID_PNP_QUERY_POWER,
  334. // OID_PNP_ADD_WAKE_UP_PATTERN, OID_PNP_REMOVE_WAKE_UP_PATTERN,
  335. // OID_PNP_ENABLE_WAKE_UP.
  336. //
  337. Status = NDIS_STATUS_NOT_SUPPORTED;
  338. break;
  339. //
  340. // Following 4 OIDs are for querying Ethernet Operational
  341. // Characteristics.
  342. //
  343. case OID_802_3_PERMANENT_ADDRESS:
  344. //
  345. // Return the MAC address of the NIC burnt in the hardware.
  346. //
  347. pInfo = Adapter->PermanentAddress;
  348. ulInfoLen = ETH_LENGTH_OF_ADDRESS;
  349. break;
  350. case OID_802_3_CURRENT_ADDRESS:
  351. //
  352. // Return the MAC address the NIC is currently programmed to
  353. // use. Note that this address could be different from the
  354. // permananent address as the user can override using
  355. // registry. Read NdisReadNetworkAddress doc for more info.
  356. //
  357. pInfo = Adapter->CurrentAddress;
  358. ulInfoLen = ETH_LENGTH_OF_ADDRESS;
  359. break;
  360. case OID_802_3_MAXIMUM_LIST_SIZE:
  361. //
  362. // The maximum number of multicast addresses the NIC driver
  363. // can manage. This list is global for all protocols bound
  364. // to (or above) the NIC. Consequently, a protocol can receive
  365. // NDIS_STATUS_MULTICAST_FULL from the NIC driver when
  366. // attempting to set the multicast address list, even if
  367. // the number of elements in the given list is less than
  368. // the number originally returned for this query.
  369. //
  370. ulInfo = NIC_MAX_MCAST_LIST;
  371. break;
  372. case OID_802_3_MAC_OPTIONS:
  373. //
  374. // A protocol can use this OID to determine features supported
  375. // by the underlying driver such as NDIS_802_3_MAC_OPTION_PRIORITY.
  376. // Return zero indicating that it supports no options.
  377. //
  378. ulInfo = 0;
  379. break;
  380. //
  381. // Following list consists of both general and Ethernet
  382. // specific statistical OIDs.
  383. //
  384. case OID_GEN_XMIT_OK:
  385. ulInfo64 = Adapter->GoodTransmits;
  386. pInfo = &ulInfo64;
  387. if (InformationBufferLength >= sizeof(ULONG64) ||
  388. InformationBufferLength == 0)
  389. {
  390. ulInfoLen = sizeof(ULONG64);
  391. }
  392. else
  393. {
  394. ulInfoLen = sizeof(ULONG);
  395. }
  396. break;
  397. case OID_GEN_RCV_OK:
  398. ulInfo64 = Adapter->GoodReceives;
  399. pInfo = &ulInfo64;
  400. if (InformationBufferLength >= sizeof(ULONG64) ||
  401. InformationBufferLength == 0)
  402. {
  403. ulInfoLen = sizeof(ULONG64);
  404. }
  405. else
  406. {
  407. ulInfoLen = sizeof(ULONG);
  408. }
  409. break;
  410. case OID_GEN_XMIT_ERROR:
  411. ulInfo = Adapter->TxAbortExcessCollisions +
  412. Adapter->TxDmaUnderrun +
  413. Adapter->TxLostCRS +
  414. Adapter->TxLateCollisions+
  415. Adapter->TransmitFailuresOther;
  416. break;
  417. case OID_GEN_RCV_ERROR:
  418. ulInfo = Adapter->RcvCrcErrors +
  419. Adapter->RcvAlignmentErrors +
  420. Adapter->RcvResourceErrors +
  421. Adapter->RcvDmaOverrunErrors +
  422. Adapter->RcvRuntErrors;
  423. break;
  424. case OID_GEN_RCV_NO_BUFFER:
  425. ulInfo = Adapter->RcvResourceErrors;
  426. break;
  427. case OID_GEN_RCV_CRC_ERROR:
  428. ulInfo = Adapter->RcvCrcErrors;
  429. break;
  430. case OID_GEN_TRANSMIT_QUEUE_LENGTH:
  431. ulInfo = Adapter->RegNumTcb;
  432. break;
  433. case OID_802_3_RCV_ERROR_ALIGNMENT:
  434. ulInfo = Adapter->RcvAlignmentErrors;
  435. break;
  436. case OID_802_3_XMIT_ONE_COLLISION:
  437. ulInfo = Adapter->OneRetry;
  438. break;
  439. case OID_802_3_XMIT_MORE_COLLISIONS:
  440. ulInfo = Adapter->MoreThanOneRetry;
  441. break;
  442. case OID_802_3_XMIT_DEFERRED:
  443. ulInfo = Adapter->TxOKButDeferred;
  444. break;
  445. case OID_802_3_XMIT_MAX_COLLISIONS:
  446. ulInfo = Adapter->TxAbortExcessCollisions;
  447. break;
  448. case OID_802_3_RCV_OVERRUN:
  449. ulInfo = Adapter->RcvDmaOverrunErrors;
  450. break;
  451. case OID_802_3_XMIT_UNDERRUN:
  452. ulInfo = Adapter->TxDmaUnderrun;
  453. break;
  454. case OID_802_3_XMIT_HEARTBEAT_FAILURE:
  455. ulInfo = Adapter->TxLostCRS;
  456. break;
  457. case OID_802_3_XMIT_TIMES_CRS_LOST:
  458. ulInfo = Adapter->TxLostCRS;
  459. break;
  460. case OID_802_3_XMIT_LATE_COLLISIONS:
  461. ulInfo = Adapter->TxLateCollisions;
  462. break;
  463. default:
  464. Status = NDIS_STATUS_NOT_SUPPORTED;
  465. break;
  466. }
  467. if(Status == NDIS_STATUS_SUCCESS)
  468. {
  469. if(ulInfoLen <= InformationBufferLength)
  470. {
  471. // Copy result into InformationBuffer
  472. *BytesWritten = ulInfoLen;
  473. if(ulInfoLen)
  474. {
  475. NdisMoveMemory(InformationBuffer, pInfo, ulInfoLen);
  476. }
  477. }
  478. else
  479. {
  480. // too short
  481. *BytesNeeded = ulInfoLen;
  482. Status = NDIS_STATUS_BUFFER_TOO_SHORT;
  483. }
  484. }
  485. DEBUGP(MP_LOUD, ("<--- MPQueryInformation Status = 0x%08x\n", Status));
  486. return(Status);
  487. }
  488. NDIS_STATUS MPSetInformation(
  489. IN NDIS_HANDLE MiniportAdapterContext,
  490. IN NDIS_OID Oid,
  491. IN PVOID InformationBuffer,
  492. IN ULONG InformationBufferLength,
  493. OUT PULONG BytesRead,
  494. OUT PULONG BytesNeeded)
  495. /*++
  496. Routine Description:
  497. This is the handler for an OID set operation.
  498. Arguments:
  499. MiniportAdapterContext Pointer to the adapter structure
  500. Oid Oid for this query
  501. InformationBuffer Buffer for information
  502. InformationBufferLength Size of this buffer
  503. BytesRead Specifies how much info is read
  504. BytesNeeded In case the buffer is smaller than what
  505. we need, tell them how much is needed
  506. Return Value:
  507. Return code from the NdisRequest below.
  508. --*/
  509. {
  510. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  511. PMP_ADAPTER Adapter = (PMP_ADAPTER) MiniportAdapterContext;
  512. DEBUGP(MP_LOUD, ("---> MPSetInformation %s\n", DbgGetOidName(Oid)));
  513. *BytesRead = 0;
  514. *BytesNeeded = 0;
  515. switch(Oid)
  516. {
  517. case OID_802_3_MULTICAST_LIST:
  518. //
  519. // Set the multicast address list on the NIC for packet reception.
  520. // The NIC driver can set a limit on the number of multicast
  521. // addresses bound protocol drivers can enable simultaneously.
  522. // NDIS returns NDIS_STATUS_MULTICAST_FULL if a protocol driver
  523. // exceeds this limit or if it specifies an invalid multicast
  524. // address.
  525. //
  526. Status = NICSetMulticastList(
  527. Adapter,
  528. InformationBuffer,
  529. InformationBufferLength,
  530. BytesRead,
  531. BytesNeeded);
  532. break;
  533. case OID_GEN_CURRENT_PACKET_FILTER:
  534. //
  535. // Program the hardware to indicate the packets
  536. // of certain filter types.
  537. //
  538. if(InformationBufferLength != sizeof(ULONG))
  539. {
  540. *BytesNeeded = sizeof(ULONG);
  541. Status = NDIS_STATUS_INVALID_LENGTH;
  542. break;
  543. }
  544. *BytesRead = InformationBufferLength;
  545. Status = NICSetPacketFilter(
  546. Adapter,
  547. *((PULONG)InformationBuffer));
  548. break;
  549. case OID_GEN_CURRENT_LOOKAHEAD:
  550. //
  551. // A protocol driver can set a suggested value for the number
  552. // of bytes to be used in its binding; however, the underlying
  553. // NIC driver is never required to limit its indications to
  554. // the value set.
  555. //
  556. if(InformationBufferLength != sizeof(ULONG)){
  557. *BytesNeeded = sizeof(ULONG);
  558. Status = NDIS_STATUS_INVALID_LENGTH;
  559. break;
  560. }
  561. Adapter->ulLookAhead = *(PULONG)InformationBuffer;
  562. *BytesRead = sizeof(ULONG);
  563. Status = NDIS_STATUS_SUCCESS;
  564. break;
  565. default:
  566. Status = NDIS_STATUS_INVALID_OID;
  567. break;
  568. }
  569. if(Status == NDIS_STATUS_SUCCESS)
  570. {
  571. *BytesRead = InformationBufferLength;
  572. }
  573. DEBUGP(MP_LOUD, ("<-- MPSetInformation Status = 0x%08x\n", Status));
  574. return(Status);
  575. }
  576. ULONG NICGetMediaConnectStatus(
  577. PMP_ADAPTER Adapter
  578. )
  579. /*++
  580. Routine Description:
  581. This routine will query the hardware and return
  582. the media status.
  583. Arguments:
  584. IN PMP_ADAPTER Adapter - pointer to adapter block
  585. Return Value:
  586. NdisMediaStateDisconnected or
  587. NdisMediaStateConnected
  588. --*/
  589. {
  590. if(MP_TEST_FLAG(Adapter, fMP_DISCONNECTED))
  591. {
  592. return(NdisMediaStateDisconnected);
  593. }
  594. else
  595. {
  596. return(NdisMediaStateConnected);
  597. }
  598. }
  599. NDIS_STATUS NICSetPacketFilter(
  600. IN PMP_ADAPTER Adapter,
  601. IN ULONG PacketFilter)
  602. /*++
  603. Routine Description:
  604. This routine will set up the adapter so that it accepts packets
  605. that match the specified packet filter. The only filter bits
  606. that can truly be toggled are for broadcast and promiscuous
  607. Arguments:
  608. IN PMP_ADAPTER Adapter - pointer to adapter block
  609. IN ULONG PacketFilter - the new packet filter
  610. Return Value:
  611. NDIS_STATUS_SUCCESS
  612. NDIS_STATUS_NOT_SUPPORTED
  613. --*/
  614. {
  615. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  616. DEBUGP(MP_TRACE, ("--> NICSetPacketFilter\n"));
  617. // any bits not supported?
  618. if(PacketFilter & ~NIC_SUPPORTED_FILTERS)
  619. {
  620. return(NDIS_STATUS_NOT_SUPPORTED);
  621. }
  622. // any filtering changes?
  623. if(PacketFilter != Adapter->PacketFilter)
  624. {
  625. //
  626. // Change the filtering modes on hardware
  627. // TODO
  628. // Save the new packet filter value
  629. Adapter->PacketFilter = PacketFilter;
  630. }
  631. DEBUGP(MP_TRACE, ("<-- NICSetPacketFilter\n"));
  632. return(Status);
  633. }
  634. NDIS_STATUS NICSetMulticastList(
  635. IN PMP_ADAPTER Adapter,
  636. IN PVOID InformationBuffer,
  637. IN ULONG InformationBufferLength,
  638. OUT PULONG pBytesRead,
  639. OUT PULONG pBytesNeeded
  640. )
  641. /*++
  642. Routine Description:
  643. This routine will set up the adapter for a specified multicast
  644. address list.
  645. Arguments:
  646. IN PMP_ADAPTER Adapter - Pointer to adapter block
  647. InformationBuffer - Buffer for information
  648. InformationBufferLength Size of this buffer
  649. pBytesRead Specifies how much info is read
  650. BytesNeeded In case the buffer is smaller than
  651. what we need, tell them how much is needed
  652. Return Value:
  653. NDIS_STATUS
  654. --*/
  655. {
  656. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  657. ULONG index;
  658. DEBUGP(MP_TRACE, ("--> NICSetMulticastList\n"));
  659. //
  660. // Initialize.
  661. //
  662. *pBytesNeeded = ETH_LENGTH_OF_ADDRESS;
  663. *pBytesRead = InformationBufferLength;
  664. do
  665. {
  666. if (InformationBufferLength % ETH_LENGTH_OF_ADDRESS)
  667. {
  668. Status = NDIS_STATUS_INVALID_LENGTH;
  669. break;
  670. }
  671. if (InformationBufferLength > (NIC_MAX_MCAST_LIST * ETH_LENGTH_OF_ADDRESS))
  672. {
  673. Status = NDIS_STATUS_MULTICAST_FULL;
  674. *pBytesNeeded = NIC_MAX_MCAST_LIST * ETH_LENGTH_OF_ADDRESS;
  675. break;
  676. }
  677. //
  678. // Protect the list update with a lock if it can be updated by
  679. // another thread simultaneously.
  680. //
  681. NdisZeroMemory(Adapter->MCList,
  682. NIC_MAX_MCAST_LIST * ETH_LENGTH_OF_ADDRESS);
  683. NdisMoveMemory(Adapter->MCList,
  684. InformationBuffer,
  685. InformationBufferLength);
  686. Adapter->ulMCListSize = InformationBufferLength / ETH_LENGTH_OF_ADDRESS;
  687. #if DBG
  688. // display the multicast list
  689. for(index = 0; index < Adapter->ulMCListSize; index++)
  690. {
  691. DEBUGP(MP_LOUD, ("MC(%d) = %02x-%02x-%02x-%02x-%02x-%02x\n",
  692. index,
  693. Adapter->MCList[index][0],
  694. Adapter->MCList[index][1],
  695. Adapter->MCList[index][2],
  696. Adapter->MCList[index][3],
  697. Adapter->MCList[index][4],
  698. Adapter->MCList[index][5]));
  699. }
  700. #endif
  701. }
  702. while (FALSE);
  703. //
  704. // Program the hardware to add suport for these muticast addresses
  705. //
  706. DEBUGP(MP_TRACE, ("<-- NICSetMulticastList\n"));
  707. return(Status);
  708. }
  709. PUCHAR DbgGetOidName(ULONG oid)
  710. {
  711. PCHAR oidName;
  712. switch (oid){
  713. #undef MAKECASE
  714. #define MAKECASE(oidx) case oidx: oidName = #oidx; break;
  715. MAKECASE(OID_GEN_SUPPORTED_LIST)
  716. MAKECASE(OID_GEN_HARDWARE_STATUS)
  717. MAKECASE(OID_GEN_MEDIA_SUPPORTED)
  718. MAKECASE(OID_GEN_MEDIA_IN_USE)
  719. MAKECASE(OID_GEN_MAXIMUM_LOOKAHEAD)
  720. MAKECASE(OID_GEN_MAXIMUM_FRAME_SIZE)
  721. MAKECASE(OID_GEN_LINK_SPEED)
  722. MAKECASE(OID_GEN_TRANSMIT_BUFFER_SPACE)
  723. MAKECASE(OID_GEN_RECEIVE_BUFFER_SPACE)
  724. MAKECASE(OID_GEN_TRANSMIT_BLOCK_SIZE)
  725. MAKECASE(OID_GEN_RECEIVE_BLOCK_SIZE)
  726. MAKECASE(OID_GEN_VENDOR_ID)
  727. MAKECASE(OID_GEN_VENDOR_DESCRIPTION)
  728. MAKECASE(OID_GEN_CURRENT_PACKET_FILTER)
  729. MAKECASE(OID_GEN_CURRENT_LOOKAHEAD)
  730. MAKECASE(OID_GEN_DRIVER_VERSION)
  731. MAKECASE(OID_GEN_MAXIMUM_TOTAL_SIZE)
  732. MAKECASE(OID_GEN_PROTOCOL_OPTIONS)
  733. MAKECASE(OID_GEN_MAC_OPTIONS)
  734. MAKECASE(OID_GEN_MEDIA_CONNECT_STATUS)
  735. MAKECASE(OID_GEN_MAXIMUM_SEND_PACKETS)
  736. MAKECASE(OID_GEN_VENDOR_DRIVER_VERSION)
  737. MAKECASE(OID_GEN_SUPPORTED_GUIDS)
  738. MAKECASE(OID_GEN_NETWORK_LAYER_ADDRESSES)
  739. MAKECASE(OID_GEN_TRANSPORT_HEADER_OFFSET)
  740. MAKECASE(OID_GEN_MEDIA_CAPABILITIES)
  741. MAKECASE(OID_GEN_PHYSICAL_MEDIUM)
  742. MAKECASE(OID_GEN_XMIT_OK)
  743. MAKECASE(OID_GEN_RCV_OK)
  744. MAKECASE(OID_GEN_XMIT_ERROR)
  745. MAKECASE(OID_GEN_RCV_ERROR)
  746. MAKECASE(OID_GEN_RCV_NO_BUFFER)
  747. MAKECASE(OID_GEN_DIRECTED_BYTES_XMIT)
  748. MAKECASE(OID_GEN_DIRECTED_FRAMES_XMIT)
  749. MAKECASE(OID_GEN_MULTICAST_BYTES_XMIT)
  750. MAKECASE(OID_GEN_MULTICAST_FRAMES_XMIT)
  751. MAKECASE(OID_GEN_BROADCAST_BYTES_XMIT)
  752. MAKECASE(OID_GEN_BROADCAST_FRAMES_XMIT)
  753. MAKECASE(OID_GEN_DIRECTED_BYTES_RCV)
  754. MAKECASE(OID_GEN_DIRECTED_FRAMES_RCV)
  755. MAKECASE(OID_GEN_MULTICAST_BYTES_RCV)
  756. MAKECASE(OID_GEN_MULTICAST_FRAMES_RCV)
  757. MAKECASE(OID_GEN_BROADCAST_BYTES_RCV)
  758. MAKECASE(OID_GEN_BROADCAST_FRAMES_RCV)
  759. MAKECASE(OID_GEN_RCV_CRC_ERROR)
  760. MAKECASE(OID_GEN_TRANSMIT_QUEUE_LENGTH)
  761. MAKECASE(OID_GEN_GET_TIME_CAPS)
  762. MAKECASE(OID_GEN_GET_NETCARD_TIME)
  763. MAKECASE(OID_GEN_NETCARD_LOAD)
  764. MAKECASE(OID_GEN_DEVICE_PROFILE)
  765. MAKECASE(OID_GEN_INIT_TIME_MS)
  766. MAKECASE(OID_GEN_RESET_COUNTS)
  767. MAKECASE(OID_GEN_MEDIA_SENSE_COUNTS)
  768. MAKECASE(OID_PNP_CAPABILITIES)
  769. MAKECASE(OID_PNP_SET_POWER)
  770. MAKECASE(OID_PNP_QUERY_POWER)
  771. MAKECASE(OID_PNP_ADD_WAKE_UP_PATTERN)
  772. MAKECASE(OID_PNP_REMOVE_WAKE_UP_PATTERN)
  773. MAKECASE(OID_PNP_ENABLE_WAKE_UP)
  774. MAKECASE(OID_802_3_PERMANENT_ADDRESS)
  775. MAKECASE(OID_802_3_CURRENT_ADDRESS)
  776. MAKECASE(OID_802_3_MULTICAST_LIST)
  777. MAKECASE(OID_802_3_MAXIMUM_LIST_SIZE)
  778. MAKECASE(OID_802_3_MAC_OPTIONS)
  779. MAKECASE(OID_802_3_RCV_ERROR_ALIGNMENT)
  780. MAKECASE(OID_802_3_XMIT_ONE_COLLISION)
  781. MAKECASE(OID_802_3_XMIT_MORE_COLLISIONS)
  782. MAKECASE(OID_802_3_XMIT_DEFERRED)
  783. MAKECASE(OID_802_3_XMIT_MAX_COLLISIONS)
  784. MAKECASE(OID_802_3_RCV_OVERRUN)
  785. MAKECASE(OID_802_3_XMIT_UNDERRUN)
  786. MAKECASE(OID_802_3_XMIT_HEARTBEAT_FAILURE)
  787. MAKECASE(OID_802_3_XMIT_TIMES_CRS_LOST)
  788. MAKECASE(OID_802_3_XMIT_LATE_COLLISIONS)
  789. default:
  790. oidName = "<** UNKNOWN OID **>";
  791. break;
  792. }
  793. return oidName;
  794. }