?? request.c
字號(hào):
/*++
Copyright (c) 1999 Microsoft Corporation
Module Name:
request.c | usb NDIS Miniport Driver
Abstract:
Query and Set information handlers
Environment:
kernel mode only
Notes:
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.
Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
Revision History:
--*/
#define BINARY_COMPATIBLE 1 // for win9x compatibility with ndis.h
#define DOBREAKS // enable debug breaks
#include <ndis.h>
#include <ntddndis.h> // defines OID's
#include "debug.h"
#include "common.h"
#include "USBNDIS.h"
//
// These are the OIDs we support
//
UINT supportedOIDs[] =
{
//
// General required OIDs.
//
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_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_VENDOR_DRIVER_VERSION,
//
// Required statistical OIDs.
//
OID_GEN_XMIT_OK,
OID_GEN_RCV_OK,
OID_GEN_XMIT_ERROR,
OID_GEN_RCV_ERROR,
OID_GEN_RCV_NO_BUFFER,
OID_PNP_CAPABILITIES/*,
OID_PNP_SET_POWER,
OID_PNP_QUERY_POWER,
OID_PNP_ENABLE_WAKE_UP
OID_PNP_ADD_WAKE_UP_PATTERN
OID_PNP_REMOVE_WAKE_UP_PATTERN
OID_PNP_WAKE_UP_PATTERN_LIST
OID_PNP_WAKE_UP_OK
OID_PNP_WAKE_UP_ERROR */
};
//
// PnP and PM OIDs
//
#define OID_PNP_CAPABILITIES 0xFD010100
#define OID_PNP_SET_POWER 0xFD010101
#define OID_PNP_QUERY_POWER 0xFD010102
#define OID_PNP_ADD_WAKE_UP_PATTERN 0xFD010103
#define OID_PNP_REMOVE_WAKE_UP_PATTERN 0xFD010104
#define OID_PNP_WAKE_UP_PATTERN_LIST 0xFD010105
#define OID_PNP_ENABLE_WAKE_UP 0xFD010106
//
// PnP/PM Statistics (Optional).
//
#define OID_PNP_WAKE_UP_OK 0xFD020200
#define OID_PNP_WAKE_UP_ERROR 0xFD020201
/*****************************************************************************
*
* Function: MiniportQueryInformation
*
* Synopsis: Queries the capabilities and status of the miniport driver.
*
* Arguments: MiniportAdapterContext - miniport context area (PUSB_DEVICE)
* Oid - system defined OID_Xxx
* InformationBuffer - where to return Oid specific info
* InformationBufferLength - specifies size of InformationBuffer
* BytesWritten - bytes written to InformationBuffer
* BytesNeeded - addition bytes required if
* InformationBufferLength is less than
* what the Oid requires to write
*
* Returns: NDIS_STATUS_SUCCESS - success
* NDIS_STATUS_PENDING - will complete asynchronously and
* call NdisMQueryInformationComplete
* NDIS_STATUS_INVALID_OID - don't recognize the Oid
* NDIS_STATUS_INVALID_LENGTH- InformationBufferLength does not
* match length for the Oid
* NDIS_STATUS_NOT_ACCEPTED - failure
* NDIS_STATUS_NOT_SUPPORTED - do not support an optional Oid
* NDIS_STATUS_RESOURCES - failed allocation of resources
*
* Notes:
* See list of Supported OIDs at the top of this module in the supportedOIDs[] array
*
*
*****************************************************************************/
NDIS_STATUS
MiniportQueryInformation(
IN NDIS_HANDLE MiniportAdapterContext,
IN NDIS_OID Oid,
IN PVOID InformationBuffer,
IN ULONG InformationBufferLength,
OUT PULONG BytesWritten,
OUT PULONG BytesNeeded
)
{
PUSB_DEVICE device;
NDIS_STATUS status;
UINT speeds;
UINT i;
UINT infoSizeNeeded;
UINT *infoPtr;
ULONG OidCategory = Oid & 0xFF000000;
BOOLEAN fBusy;
static char vendorDesc[] = "Usb Infrared Port";
DEBUGMSG(DBG_FUNC, ("+MiniportQueryInformation\n"));
device = CONTEXT_TO_DEV(MiniportAdapterContext);
ASSERT( NULL != device );
ASSERT( NULL != BytesWritten );
ASSERT( NULL != BytesNeeded );
status = NDIS_STATUS_SUCCESS;
NdisGetCurrentSystemTime( &device->LastQueryTime ); //used by check for hang handler
device->fQuerypending = TRUE;
//DUMP_STATS_SEC( device, 180 ); // dump statistics every n seconds if debugging
if ( NULL == InformationBuffer && InformationBufferLength > 0 ) { // Should be impossible but it happened on an MP system!
DEBUGMSG(DBG_ERR, (" MiniportQueryInformation() NULL info buffer passed!,InformationBufferLength = dec %d\n",InformationBufferLength));
status = NDIS_STATUS_NOT_ACCEPTED;
*BytesNeeded =0;
*BytesWritten = 0;
goto done;
}
//
// Figure out buffer size needed.
// Most OIDs just return a single UINT, but there are exceptions.
//
switch (Oid)
{
case OID_GEN_SUPPORTED_LIST:
infoSizeNeeded = sizeof(supportedOIDs);
break;
case OID_PNP_CAPABILITIES:
infoSizeNeeded = sizeof(NDIS_PNP_CAPABILITIES);
break;
case OID_GEN_DRIVER_VERSION:
infoSizeNeeded = sizeof(USHORT);
break;
case OID_GEN_VENDOR_DESCRIPTION:
infoSizeNeeded = sizeof(vendorDesc);
break;
default:
infoSizeNeeded = sizeof(UINT);
break;
}
//
// If the protocol provided a large enough buffer, we can go ahead
// and complete the query.
//
if (InformationBufferLength >= infoSizeNeeded)
{
//
// Set default results.
//
*BytesWritten = infoSizeNeeded;
*BytesNeeded = 0;
switch (Oid)
{
//
// Generic OIDs.
//
case OID_GEN_SUPPORTED_LIST:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_SUPPORTED_LIST)\n"));
/*
Specifies an array of OIDs for objects that the underlying
driver or its device supports. Objects include general, media-specific,
and implementation-specific objects.
The underlying driver should order the OID list it returns
in increasing numeric order. 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 since protocols
never make statistics queries subsequentlly.
*/
NdisMoveMemory(
InformationBuffer,
(PVOID)supportedOIDs,
sizeof(supportedOIDs)
);
break;
case OID_GEN_HARDWARE_STATUS:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_HARDWARE_STATUS)\n"));
//
// If we can be called with a context, then we are
// initialized and ready.
//
*(UINT *)InformationBuffer = NdisHardwareStatusReady;
break;
case OID_GEN_MEDIA_SUPPORTED:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_MEDIA_SUPPORTED)\n"));
*(UINT *)InformationBuffer = NdisMedium802_3;
break;
case OID_GEN_MEDIA_IN_USE:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_MEDIA_IN_USE)\n"));
*(UINT *)InformationBuffer = NdisMedium802_3;
break;
case OID_GEN_TRANSMIT_BUFFER_SPACE:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_TRANSMIT_BUFFER_SPACE)\n"));
/*
The amount of memory, in bytes, on the device available
for buffering transmit data.
*/
*(UINT *)InformationBuffer = MAX_PACKET_SIZE+2;
break;
case OID_GEN_RECEIVE_BUFFER_SPACE:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_RECEIVE_BUFFER_SPACE)\n"));
/*
The amount of memory on the device available
for buffering receive data.
*/
*(UINT *)InformationBuffer = MAX_PACKET_SIZE+4;
break;
case OID_GEN_TRANSMIT_BLOCK_SIZE:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_TRANSMIT_BLOCK_SIZE)\n"));
/*
The minimum number of bytes that a single net packet
occupies in the transmit buffer space of the device.
For example, on some devices the transmit space is
divided into 256-byte pieces so such a device's
transmit block size would be 256. To calculate
the total transmit buffer space on such a device,
its driver multiplies the number of transmit
buffers on the device by its transmit block size.
For other devices, the transmit block size is
identical to its maximum packet size.
*/
*(UINT *)InformationBuffer = MAX_PACKET_SIZE+2;
break;
case OID_GEN_RECEIVE_BLOCK_SIZE:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_RECEIVE_BLOCK_SIZE)\n"));
/*
The amount of storage, in bytes, that a single packet
occupies in the receive buffer space of the device
*/
*(UINT *)InformationBuffer = MAX_PACKET_SIZE+4;
break;
case OID_GEN_MAXIMUM_LOOKAHEAD:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_MAXIMUM_LOOKAHEAD)\n"));
/*
The maximum number of bytes the device can always provide as lookahead data.
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.
*/
*(UINT *)InformationBuffer = MAX_PACKET_SIZE+4;
break;
case OID_GEN_CURRENT_LOOKAHEAD:
DEBUGONCE(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_CURRENT_LOOKAHEAD)\n"));
/*
The number of bytes of received packet data,
excluding the header, that will be indicated
to the protocol driver. For a query,
NDIS returns the largest lookahead size from
among all the bindings. A protocol driver can
set a suggested value for the number of bytes
to be used in its binding; however,
the underlying device driver is never required
to limit its indications to the value set.
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.
*/
*(UINT *)InformationBuffer = MAX_PACKET_SIZE+4;
break;
case OID_GEN_MAXIMUM_FRAME_SIZE:
DEBUGMSG(DBG_FUNC, (" MiniportQueryInformation(OID_GEN_MAXIMUM_FRAME_SIZE)\n"));
/*
The maximum network packet size in bytes
the device supports, not including a header.
For a binding emulating another medium type,
the device driver must define the maximum frame
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -