📄 request.c
字号:
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.
Module Name:
Request.c
Abstract:
This module contains Miniport function and helper routines for handling
Set & Query Information requests.
Revision History:
Notes:
--*/
#include "miniport.h"
NDIS_OID NICSupportedOids[] =
{
OID_GEN_SUPPORTED_LIST,
OID_GEN_HARDWARE_STATUS,
OID_GEN_MEDIA_SUPPORTED,
OID_GEN_MEDIA_IN_USE,
OID_GEN_MAXIMUM_LOOKAHEAD,
OID_GEN_MAXIMUM_FRAME_SIZE,
OID_GEN_LINK_SPEED,
OID_GEN_TRANSMIT_BUFFER_SPACE,
OID_GEN_RECEIVE_BUFFER_SPACE,
OID_GEN_TRANSMIT_BLOCK_SIZE,
OID_GEN_RECEIVE_BLOCK_SIZE,
OID_GEN_VENDOR_ID,
OID_GEN_VENDOR_DESCRIPTION,
OID_GEN_VENDOR_DRIVER_VERSION,
OID_GEN_CURRENT_PACKET_FILTER,
OID_GEN_CURRENT_LOOKAHEAD,
OID_GEN_DRIVER_VERSION,
OID_GEN_MAXIMUM_TOTAL_SIZE,
OID_GEN_PROTOCOL_OPTIONS,
OID_GEN_MAC_OPTIONS,
OID_GEN_MEDIA_CONNECT_STATUS,
OID_GEN_MAXIMUM_SEND_PACKETS,
OID_GEN_XMIT_OK,
OID_GEN_RCV_OK,
OID_GEN_XMIT_ERROR,
OID_GEN_RCV_ERROR,
OID_GEN_RCV_NO_BUFFER,
OID_GEN_RCV_CRC_ERROR,
OID_GEN_TRANSMIT_QUEUE_LENGTH,
OID_802_3_PERMANENT_ADDRESS,
OID_802_3_CURRENT_ADDRESS,
OID_802_3_MULTICAST_LIST,
OID_802_3_MAC_OPTIONS,
OID_802_3_MAXIMUM_LIST_SIZE,
OID_802_3_RCV_ERROR_ALIGNMENT,
OID_802_3_XMIT_ONE_COLLISION,
OID_802_3_XMIT_MORE_COLLISIONS,
OID_802_3_XMIT_DEFERRED,
OID_802_3_XMIT_MAX_COLLISIONS,
OID_802_3_RCV_OVERRUN,
OID_802_3_XMIT_UNDERRUN,
OID_802_3_XMIT_HEARTBEAT_FAILURE,
OID_802_3_XMIT_TIMES_CRS_LOST,
OID_802_3_XMIT_LATE_COLLISIONS,
OID_PNP_CAPABILITIES,
OID_PNP_SET_POWER,
OID_PNP_QUERY_POWER,
OID_PNP_ADD_WAKE_UP_PATTERN,
OID_PNP_REMOVE_WAKE_UP_PATTERN,
OID_PNP_ENABLE_WAKE_UP
};
NDIS_STATUS MPQueryInformation(
IN NDIS_HANDLE MiniportAdapterContext,
IN NDIS_OID Oid,
IN PVOID InformationBuffer,
IN ULONG InformationBufferLength,
OUT PULONG BytesWritten,
OUT PULONG BytesNeeded)
/*++
Routine Description:
Entry point called by NDIS to query for the value of the specified OID.
Arguments:
MiniportAdapterContext Pointer to the adapter structure
Oid Oid for this query
InformationBuffer Buffer for information
InformationBufferLength Size of this buffer
BytesWritten Specifies how much info is written
BytesNeeded In case the buffer is smaller than
what we need, tell them how much is needed
Return Value:
Return code from the NdisRequest below.
Notes: Read "Minimizing Miniport Driver Initialization Time" in the DDK
for more info on how to handle certain OIDs that affect the init of
a miniport.
--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PMP_ADAPTER Adapter;
NDIS_HARDWARE_STATUS HardwareStatus = NdisHardwareStatusReady;
NDIS_MEDIUM Medium = NIC_MEDIA_TYPE;
UCHAR VendorDesc[] = NIC_VENDOR_DESC;
ULONG ulInfo;
USHORT usInfo;
ULONG64 ulInfo64;
PVOID pInfo = (PVOID) &ulInfo;
ULONG ulInfoLen = sizeof(ulInfo);
DEBUGP(MP_LOUD, ("---> MPQueryInformation %s\n", DbgGetOidName(Oid)));
Adapter = (PMP_ADAPTER) MiniportAdapterContext;
// Initialize the result
*BytesWritten = 0;
*BytesNeeded = 0;
switch(Oid)
{
case OID_GEN_SUPPORTED_LIST:
//
// The OID_GEN_SUPPORTED_LIST OID specifies an array of OIDs
// for objects that the underlying driver or its NIC supports.
// Objects include general, media-specific, and implementation-
// specific objects. NDIS forwards a subset of the returned
// list to protocols that make this query. That is, NDIS filters
// any supported statistics OIDs out of the list because
// protocols never make statistics queries.
//
pInfo = (PVOID) NICSupportedOids;
ulInfoLen = sizeof(NICSupportedOids);
break;
case OID_GEN_HARDWARE_STATUS:
//
// Specify the current hardware status of the underlying NIC as
// one of the following NDIS_HARDWARE_STATUS-type values.
//
pInfo = (PVOID) &HardwareStatus;
ulInfoLen = sizeof(NDIS_HARDWARE_STATUS);
break;
case OID_GEN_MEDIA_SUPPORTED:
//
// Specify the media types that the NIC can support but not
// necessarily the media types that the NIC currently uses.
// fallthrough:
case OID_GEN_MEDIA_IN_USE:
//
// Specifiy a complete list of the media types that the NIC
// currently uses.
//
pInfo = (PVOID) &Medium;
ulInfoLen = sizeof(NDIS_MEDIUM);
break;
case OID_GEN_CURRENT_LOOKAHEAD:
case OID_GEN_MAXIMUM_LOOKAHEAD:
//
// If the miniport driver indicates received data by calling
// NdisXxxIndicateReceive, it should respond to OID_GEN_MAXIMUM_LOOKAHEAD
// with the maximum number of bytes the NIC can provide as
// lookahead data. If that value is different from the size of the
// lookahead buffer supported by bound protocols, NDIS will call
// MiniportSetInformation to set the size of the lookahead buffer
// provided by the miniport driver to the minimum of the miniport
// driver and protocol(s) values. If the driver always indicates
// up full packets with NdisMIndicateReceivePacket, it should
// set this value to the maximum total packet size, which
// excludes the header.
// Upper-layer drivers examine lookahead data to determine whether
// a packet that is associated with the lookahead data is intended
// for one or more of their clients. If the underlying driver
// supports multipacket receive indications, bound protocols are
// given full net packets on every indication. Consequently,
// this value is identical to that returned for
// OID_GEN_RECEIVE_BLOCK_SIZE.
//
if(Adapter->ulLookAhead == 0)
{
Adapter->ulLookAhead = NIC_MAX_LOOKAHEAD;
}
ulInfo = Adapter->ulLookAhead;
break;
case OID_GEN_MAXIMUM_FRAME_SIZE:
//
// Specifiy the maximum network packet size, in bytes, that the
// NIC supports excluding the header. A NIC driver that emulates
// another medium type for binding to a transport must ensure that
// the maximum frame size for a protocol-supplied net packet does
// not exceed the size limitations for the true network medium.
//
ulInfo = ETH_MAX_PACKET_SIZE - ETH_HEADER_SIZE;
break;
case OID_GEN_MAXIMUM_TOTAL_SIZE:
//
// Specify the maximum total packet length, in bytes, the NIC
// supports including the header. A protocol driver might use
// this returned length as a gauge to determine the maximum
// size packet that a NIC driver could forward to the
// protocol driver. The miniport driver must never indicate
// up to the bound protocol driver packets received over the
// network that are longer than the packet size specified by
// OID_GEN_MAXIMUM_TOTAL_SIZE.
//
case OID_GEN_TRANSMIT_BLOCK_SIZE:
//
// The OID_GEN_TRANSMIT_BLOCK_SIZE OID specifies the minimum
// number of bytes that a single net packet occupies in the
// transmit buffer space of the NIC. For example, a NIC that
// has a transmit space divided into 256-byte pieces would have
// a transmit block size of 256 bytes. To calculate the total
// transmit buffer space on such a NIC, its driver multiplies
// the number of transmit buffers on the NIC by its transmit
// block size. In our case, the transmit block size is
// identical to its maximum packet size.
case OID_GEN_RECEIVE_BLOCK_SIZE:
//
// The OID_GEN_RECEIVE_BLOCK_SIZE OID specifies the amount of
// storage, in bytes, that a single packet occupies in the receive
// buffer space of the NIC.
//
ulInfo = (ULONG) ETH_MAX_PACKET_SIZE;
break;
case OID_GEN_MAC_OPTIONS:
//
// Specify a bitmask that defines optional properties of the NIC.
// This miniport indicates receive with NdisMIndicateReceivePacket
// function. It has no MiniportTransferData function. Such a driver
// should set this NDIS_MAC_OPTION_TRANSFERS_NOT_PEND flag.
//
// NDIS_MAC_OPTION_NO_LOOPBACK tells NDIS that NIC has no internal
// loopback support so NDIS will manage loopbacks on behalf of
// this driver.
//
// NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA tells the protocol that
// our receive buffer is not on a device-specific card. If
// NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA is not set, multi-buffer
// indications are copied to a single flat buffer.
//
ulInfo = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |
NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
NDIS_MAC_OPTION_NO_LOOPBACK;
break;
case OID_GEN_LINK_SPEED:
//
// Specify the maximum speed of the NIC in kbps.
//
ulInfo = Adapter->ulLinkSpeed;
break;
case OID_GEN_TRANSMIT_BUFFER_SPACE:
//
// Specify the amount of memory, in bytes, on the NIC that
// is available for buffering transmit data. A protocol can
// use this OID as a guide for sizing the amount of transmit
// data per send.
//
ulInfo = ETH_MAX_PACKET_SIZE * Adapter->ulMaxBusySends;
break;
case OID_GEN_RECEIVE_BUFFER_SPACE:
//
// Specify the amount of memory on the NIC that is available
// for buffering receive data. A protocol driver can use this
// OID as a guide for advertising its receive window after it
// establishes sessions with remote nodes.
//
ulInfo = ETH_MAX_PACKET_SIZE * Adapter->ulMaxBusyRecvs;
break;
case OID_GEN_VENDOR_ID:
//
// Specify a three-byte IEEE-registered vendor code, followed
// by a single byte that the vendor assigns to identify a
// particular NIC. The IEEE code uniquely identifies the vendor
// and is the same as the three bytes appearing at the beginning
// of the NIC hardware address. Vendors without an IEEE-registered
// code should use the value 0xFFFFFF.
//
ulInfo = NIC_VENDOR_ID;
break;
case OID_GEN_VENDOR_DESCRIPTION:
//
// Specify a zero-terminated string describing the NIC vendor.
//
pInfo = VendorDesc;
ulInfoLen = sizeof(VendorDesc);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -