⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmini.cpp

📁 Atheros Communications AR6001 WLAN Driver for SDIO installation Read Me March 26,2007 (based on
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
// <copyright file="cmini.cpp" company="Atheros and Microsoft">
//    Copyright (c) 2006 Microsoft Corporation.  All rights reserved.
//    Copyright (c) 2006 Atheros Corporation.  All rights reserved.
//
//    The use and distribution terms for this software are covered by the
//    Microsoft Limited Permissive License (Ms-LPL) 
//    http://www.microsoft.com/resources/sharedsource/licensingbasics/limitedpermissivelicense.mspx 
//    which can be found in the file MS-LPL.txt at the root of this distribution.
//    By using this software in any fashion, you are agreeing to be bound by
//    the terms of this license.
//
//    You must not remove this notice, or any other, from this software.
// </copyright>
// 
// <summary>
//    Windows CE Wifi Driver for AR-6000
// </summary>
//------------------------------------------------------------------------------
//==============================================================================
// NDIS Miniport class.
//
// Author(s): ="Atheros and Microsoft"
//==============================================================================

#include <windows.h>
#include <ndis.h>
#include "cmini.hpp"
#include "osapi.h"

CMiniport::CMiniport()
{
	m_MiniportAdapterHandle = NULL;

	NdisAllocateSpinLock(&m_Lock);
}

CMiniport::~CMiniport()
{
	NdisFreeSpinLock(&m_Lock);
}

NDIS_STATUS
CMiniport::Initialize(
	IN NDIS_HANDLE MiniportAdapterHandle,
	IN NDIS_HANDLE pConfigHandle)
//
//  Initialize is a required function that sets up a NIC for network I/O
//  operations, claims all hardware resources necessary to the NIC, and
//  allocates resources the driver needs to carry out network I/O operations.
//
{
	m_MiniportAdapterHandle = MiniportAdapterHandle;

	return NDIS_STATUS_SUCCESS;
}

void
CMiniport::Halt()
//
//  Halt is a required function that deallocates resources (e.g. those
//  allocated by Initialize) when the NIC is removed and halts the NIC.
//
{
}

BOOLEAN
CMiniport::CheckForHang()
//
//  CheckForHang is an optional function that reports the state of
//  the NIC or monitors the responsiveness of the underlying driver.
//
//  CheckForHang returns TRUE if the driver determines that the NIC
//  is not operating.
//
{
	// Never hangs
	return FALSE;
}

NDIS_STATUS
CMiniport::Reset(
	OUT PBOOLEAN pAddressingReset)
{
	// No hardware or data to reset
	return NDIS_STATUS_SUCCESS;
}

static const NDIS_PHYSICAL_ADDRESS g_HighestAcceptableAddress = {-1, -1};

PVOID
CMiniport::MemoryAllocate(
	IN UINT cbMemory)
//
//  Allocate a block of memory Length bytes long.
//
{
	PVOID       pMemory = NULL;
	NDIS_STATUS Status;

	Status = NdisAllocateMemory(&pMemory, cbMemory, 0, g_HighestAcceptableAddress);
    if (Status == NDIS_STATUS_FAILURE) {
	    NDIS_DEBUG_PRINTF(ATH_LOG_ERR, "AR6K: ERROR - NdisAllocateMemory for %d bytes failed error = %x\n", cbMemory, Status);
    }

	return pMemory;
}

void
CMiniport::MemoryFree(
	IN PVOID pMemory)
//
//  Free a block of memory allocated by MemoryAllocate.
//
{
	NdisFreeMemory(pMemory, 0, 0);
}

//
// Set of _GEN Oids supported for Query operations:
//
static MPOidInfo g_GenSupportedQueryOids[] =
{
	{ OID_GEN_VENDOR_DRIVER_VERSION, sizeof(ULONG) },
	{ OID_GEN_MAC_OPTIONS,           sizeof(ULONG) },
	{ OID_GEN_SUPPORTED_LIST,        0 },
	{ OID_GEN_HARDWARE_STATUS,       sizeof(NDIS_HARDWARE_STATUS) },
	{ OID_GEN_MEDIA_SUPPORTED,       sizeof(NDIS_MEDIUM) },
	{ OID_GEN_MEDIA_IN_USE,          sizeof(NDIS_MEDIUM) },
	{ OID_GEN_PHYSICAL_MEDIUM,       sizeof(NDIS_MEDIUM) },
	{ OID_GEN_MEDIA_CONNECT_STATUS,  sizeof(ULONG) },
	{ OID_GEN_MAXIMUM_LOOKAHEAD,     sizeof(ULONG) },
	{ OID_GEN_CURRENT_LOOKAHEAD,     sizeof(ULONG) },
	{ OID_GEN_MAXIMUM_FRAME_SIZE,    sizeof(ULONG) },
	{ OID_GEN_MAXIMUM_TOTAL_SIZE,    sizeof(ULONG) },
	{ OID_GEN_LINK_SPEED,            sizeof(ULONG) },
	{ OID_GEN_TRANSMIT_BUFFER_SPACE, sizeof(ULONG) },
	{ OID_GEN_RECEIVE_BUFFER_SPACE,  sizeof(ULONG) },
	{ OID_GEN_TRANSMIT_BLOCK_SIZE,   sizeof(ULONG) },
	{ OID_GEN_RECEIVE_BLOCK_SIZE,    sizeof(ULONG) },
	{ OID_GEN_VENDOR_ID,             sizeof(ULONG) },
	{ OID_GEN_VENDOR_DESCRIPTION,    0 },
	{ OID_GEN_DRIVER_VERSION,        sizeof(USHORT) },
	{ OID_GEN_CURRENT_PACKET_FILTER, sizeof(ULONG) },
	{ OID_GEN_MAXIMUM_SEND_PACKETS,  sizeof(ULONG) },
	{ OID_GEN_XMIT_OK,               sizeof(ULONG) },
	{ OID_GEN_RCV_OK,                sizeof(ULONG) },
	{ OID_GEN_XMIT_ERROR,            sizeof(ULONG) },
	{ OID_GEN_RCV_ERROR,             sizeof(ULONG) },
	{ OID_GEN_RCV_NO_BUFFER,         sizeof(ULONG) },
	{ OID_GEN_MEDIA_CAPABILITIES,    sizeof(ULONG) },
	{ OID_PNP_CAPABILITIES,          sizeof(NDIS_PNP_CAPABILITIES) },
	{ OID_PNP_QUERY_POWER,           0 },
	{ 0,                             0 }
};

//
// Set of _GEN Oids supported for Set operations:
//
static MPOidInfo g_GenSupportedSetOids[] =
{
	{ OID_GEN_CURRENT_PACKET_FILTER, sizeof(ULONG) },
	{ OID_GEN_CURRENT_LOOKAHEAD,     sizeof(ULONG) },
	{ OID_GEN_PROTOCOL_OPTIONS,      sizeof(ULONG) },
	{ OID_PNP_SET_POWER,             sizeof(NDIS_DEVICE_POWER_STATE) },
	{ 0,                             0 }
};

NDIS_STATUS
CMiniport::CheckOidRequest(
	IN     MPOidInfo               *pOidInfo,
	IN     NDIS_OID                 Oid,
	IN     ULONG                    BufferLength,
	OUT    PULONG                   BytesNeeded)
//
//  Check to see that an OID request:
//		1. Is for a supported OID, and
//		2. That the provided buffer is not smaller than the minimum required space
//
{
	NDIS_STATUS    Status = NDIS_STATUS_INVALID_OID;

	for ( ; 0 != pOidInfo->Oid; pOidInfo++)
	{
		if (Oid == pOidInfo->Oid)
		{
			// Match found
			*BytesNeeded = pOidInfo->MinBufferSize;
			if (BufferLength < pOidInfo->MinBufferSize)
			{
				// The supplied buffer is not big enough
				Status = NDIS_STATUS_BUFFER_TOO_SHORT;
			}
			else
			{
				// Oid is supported, buffer size is ok.
				Status = NDIS_STATUS_SUCCESS;
			}
			break;
		}
	}

	return Status;
}

void
CMiniport::AddOidsToList(
	IN     MPOidInfo               *pOidInfo,
	IN OUT PNDIS_OID                pCurrentList,
	IN OUT PULONG                   pCurrentListCount,
	IN OUT PULONG                   pOidSlotsAvailable,
	IN OUT PULONG                   TotalOidCount)
//
//  Add the oids from the specified MPOidInfo to the array,
//  if they don't already appear in the array.
//
{
	ULONG     CurrentListCount = *pCurrentListCount;
	PNDIS_OID pEndList = pCurrentList + CurrentListCount;

	//
	// Iterate through the set of Oids in pOidInfo
	//
	for ( ; 0 != pOidInfo->Oid; pOidInfo++)
	{
		//
		// Check to see if the Oid is already in our list
		//
		for (ULONG i = 0; i < CurrentListCount; i++)
		{
			if (pOidInfo->Oid == pCurrentList[i])
			{
				// This Oid is already in the list, skip it
				break;
			}
        }
		if (i == CurrentListCount)
		{
			// Reached the end of the list without finding the oid,
			// thus it is new and needs to be added to the list
			*TotalOidCount += 1;
			if (*pOidSlotsAvailable)
			{
				*pEndList++ = pOidInfo->Oid;
				*pOidSlotsAvailable -= 1;
			}
		}
	}

	// Set the number of OIDs now in the list
	*pCurrentListCount = pEndList - pCurrentList;
}

PNDIS_OID
CMiniport::GetSupportedOidList(
	OUT     PNDIS_OID  pOidBuffer, 
	IN  OUT PULONG     pMaxOidsToAddToBuffer,
	IN  OUT PULONG     pTotalNumberOfSupportedOids)
//
//  Add the OIDs supported by the driver to pOidBuffer, but
//  do not add more than MaxOidsToAddToBuffer.
//
//  TotalNumberOfSupportedOids is set to the number of Oids
//  that the driver supports.
//
{
	PNDIS_OID   pOidList = pOidBuffer;
	ULONG       OidListCount = 0;

	AddOidsToList(&g_GenSupportedQueryOids[0], pOidList, &OidListCount, pMaxOidsToAddToBuffer, pTotalNumberOfSupportedOids);
	AddOidsToList(&g_GenSupportedSetOids[0],   pOidList, &OidListCount, pMaxOidsToAddToBuffer, pTotalNumberOfSupportedOids);

	return pOidList + OidListCount;
}

NDIS_STATUS
CMiniport::QueryInformation(
	IN  NDIS_OID Oid, 
	OUT PVOID    Buffer, 
	IN  ULONG    cbBuffer,
	OUT PULONG   pcbWritten,
	OUT PULONG   pcbNeeded)
//
// QueryInformation is a required function that returns information
// about the capabilities and status of the driver and/or its NIC.
//
{
	NDIS_STATUS             Status = NDIS_STATUS_SUCCESS;
	ULONG                   GenericULong;
	ULONG                   GenericUShort;
	NDIS_HARDWARE_STATUS    HardwareStatus;
	NDIS_MEDIUM             Medium;
	NDIS_PHYSICAL_MEDIUM	PhysicalMedium;
	NDIS_PNP_CAPABILITIES   PnpCaps;
	PVOID                   MoveSource = (PVOID)&GenericULong;
	ULONG                   MoveBytes = sizeof(GenericULong);

	// Check that OID is supported and buffer size is reasonable.
	Status = CheckOidRequest(&g_GenSupportedQueryOids[0], Oid, cbBuffer, pcbNeeded);
	if (NDIS_STATUS_SUCCESS != Status)
		goto done;

	switch (Oid)
	{
		case OID_GEN_VENDOR_DRIVER_VERSION:		
			GenericULong = GetGenVendorDriverVersion();
			break;

		case OID_GEN_MAC_OPTIONS:
			// A bitmask that defines optional properties of the underlying driver or its NIC.
			GenericULong = GetGenMacOptions();
			break;

		case OID_GEN_SUPPORTED_LIST:
			// An array of OIDs for objects that the underlying driver or its NIC supports.
			{
				ULONG TotalNumberOfSupportedOids = 0;
				ULONG MaxOidsToAddToBuffer = cbBuffer / sizeof(NDIS_OID);
                ULONG i,j;
                NDIS_OID temp;
                NDIS_OID *pOids;

				MoveBytes = 0;
				*pcbWritten = 0;
                pOids = (NDIS_OID *)Buffer;
				// Build list of supported OIDs
				GetSupportedOidList(pOids, &MaxOidsToAddToBuffer, &TotalNumberOfSupportedOids);
				*pcbNeeded = TotalNumberOfSupportedOids * sizeof(NDIS_OID);
				if (*pcbNeeded <= cbBuffer) {
                    // Sort the list 
                    for (i=0;i<TotalNumberOfSupportedOids;i++) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -