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

📄 smsc100fd.c

📁 smsc公司的网络芯片smsc100fd的wince源码。
💻 C
📖 第 1 页 / 共 5 页
字号:
			break;
		case OID_GEN_SUPPORTED_LIST:
			pMoveSource = (PVOID)(Smsc100FdSupportedOids);
			ulMoveBytes = sizeof (Smsc100FdSupportedOids);
			break;
		case OID_GEN_HARDWARE_STATUS:
			HardwareStatus = NdisHardwareStatusReady;
			pMoveSource = (PVOID)(&HardwareStatus);
			ulMoveBytes = sizeof (NDIS_HARDWARE_STATUS);
			break;
		case OID_GEN_MEDIA_SUPPORTED:
		case OID_GEN_MEDIA_IN_USE:
			pMoveSource = (PVOID) (&Medium);
			ulMoveBytes = sizeof (NDIS_MEDIUM);
			break;
		case OID_GEN_MAXIMUM_LOOKAHEAD:
			ulGeneric = MAX_LOOKAHEAD;
			break;
		case OID_GEN_MAXIMUM_FRAME_SIZE:
			ulGeneric = (ULONG)(1514 - ETHER_HEADER_SIZE);
			break;
		case OID_GEN_MAXIMUM_TOTAL_SIZE:
			ulGeneric = (ULONG)(1514);
			break;
		case OID_GEN_LINK_SPEED:
			ulGeneric = (ULONG)(1000000L);
			break;
		case OID_GEN_TRANSMIT_BUFFER_SPACE:
			ulGeneric = (ULONG)2048;
			break;
		case OID_GEN_RECEIVE_BUFFER_SPACE:
			ulGeneric = (ULONG)2048;
			break;
		case OID_GEN_TRANSMIT_BLOCK_SIZE:
			ulGeneric = (ULONG)512;
			break;
		case OID_GEN_RECEIVE_BLOCK_SIZE:
			ulGeneric = (ULONG)512;
			break;
		case OID_GEN_VENDOR_ID:
			NdisMoveMemory ((PVOID)&ulGeneric, pAdapter->ucStationAddress, 3);
			ulGeneric &= 0xFFFFFF00;
			ulGeneric |= 0x01;
			pMoveSource = (PVOID)(&ulGeneric);
			ulMoveBytes = sizeof (ulGeneric);
			break;
		case OID_GEN_VENDOR_DESCRIPTION:
			pMoveSource = VendorString;
			ulMoveBytes = sizeof (VendorString);
			break;
		case OID_GEN_DRIVER_VERSION:
			usGeneric = ((USHORT)SMSC100FD_NDIS_MAJOR_VERSION << 8) | SMSC100FD_NDIS_MINOR_VERSION;
			pMoveSource = (PVOID)(&usGeneric);
			ulMoveBytes = sizeof (usGeneric);
			break;
		case OID_GEN_CURRENT_LOOKAHEAD:
			ulGeneric = (ULONG)(pAdapter->ulMaxLookAhead);
			break;
		case OID_802_3_PERMANENT_ADDRESS:
		case OID_802_3_CURRENT_ADDRESS:
			NdisMoveMemory ((PCHAR)ucGenericArray, pAdapter->ucStationAddress, ETHER_LENGTH_OF_ADDRESS);
			pMoveSource = (PVOID)ucGenericArray;
			ulMoveBytes = sizeof (pAdapter->ucStationAddress);
			break;
		case OID_802_3_MAXIMUM_LIST_SIZE:
			ulGeneric = (ULONG) DEFAULT_MULTICASTLISTMAX;
			break;
		case OID_GEN_XMIT_OK:
			ulGeneric = (UINT)(pAdapter->ulFramesXmitGood);
			break;
		case OID_GEN_RCV_OK:
			ulGeneric = (UINT)(pAdapter->ulFramesRcvGood);
			break;
		case OID_GEN_XMIT_ERROR:
			ulGeneric = (UINT)(pAdapter->ulFramesXmitBad);
			break;
		case OID_GEN_RCV_ERROR:
			ulGeneric = (UINT)(pAdapter->ulCrcErrors);
			break;
		case OID_GEN_RCV_NO_BUFFER:
			ulGeneric = (UINT)(pAdapter->ulMissedPackets);
			break;
		case OID_802_3_RCV_ERROR_ALIGNMENT:
			ulGeneric = (UINT)(pAdapter->ulFrameAlignmentErrors);
			break;
		case OID_802_3_XMIT_ONE_COLLISION:
			ulGeneric = (UINT)(pAdapter->ulFramesXmitOneCollision);
			break;
		case OID_802_3_XMIT_MORE_COLLISIONS:
			ulGeneric = (UINT)(pAdapter->ulFramesXmitManyCollisions);
			break;

#ifdef UNDER_CE
     //
     // These are mandatory OIDs that must be provided by the 
     // driver even if they are not supported.
     //
    
     case OID_GEN_MEDIA_CONNECT_STATUS:
        ulGeneric = NdisMediaStateConnected;
        break;
        
     case OID_GEN_MAXIMUM_SEND_PACKETS:
        ulGeneric = 1;
        break;
        
     case OID_GEN_VENDOR_DRIVER_VERSION:
        ulGeneric = 1;
        break;
#endif
		default:
			StatusToReturn = NDIS_STATUS_INVALID_OID;
			break;
		}
    if (StatusToReturn == NDIS_STATUS_SUCCESS)
		{
        if (ulMoveBytes > ulInformationBufferLength)
			{
			//
			// Not enough room in InformationBuffer. Punt
			//
			*pulBytesNeeded = ulMoveBytes;
			StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
			}
		else
			{
			//
			// Store the result.
			//
			NdisMoveMemory (pInformationBuffer, pMoveSource, ulMoveBytes);
			(*pulBytesWritten) += ulMoveBytes;
			}
	    }

    DEBUGMSG (ZONE_FUNCTION, (TEXT ("-SMSC100FD: QueryInformation\r\n")));
    return (StatusToReturn);
	}

/*
 * Description:
 *	The Smsc100FdSetInformation handles a setting configurations values all OIDs.
 *
 * Arguments:
 *	hMiniportAdapterContext - A pointer to the adapter.
 *	Oid - The NDIS_OID to process.
 *	pInformationBuffer - A pointer to the data.
 *	ulInformationBufferLength - The length of the data.
 *	pulBytesRead - A pointer to the number of bytes read from the InformationBuffer.
 *	pulBytesNeeded - If there is not data in the information buffer then this will contain the number
 *				  of bytes needed to complete the request.
 *
 * Return Value:
 *	The status of the operation.
 *
 */
NDIS_STATUS
Smsc100FdSetInformation (IN NDIS_HANDLE hMiniportAdapterContext, IN NDIS_OID Oid, IN PVOID pInformationBuffer, IN ULONG ulInformationBufferLength, OUT PULONG pulBytesRead, OUT PULONG pulBytesNeeded)
	{
	//
	// Pointer to the adapter structure.
	//
	PSMSC100FD_ADAPTER pAdapter = (PSMSC100FD_ADAPTER)(hMiniportAdapterContext);

	//
	// General Algorithm:
	//
	//     Verify length
	//     Switch(Request)
	//        Process Request
	//
	ULONG ulBytesLeft = ulInformationBufferLength;
	PUCHAR pucInfoBuffer = (PUCHAR)(pInformationBuffer);
	//
	// Variables for holding the new values to be used.
	//
	ULONG ulLookAhead;
	ULONG ulPacketFilter;
	//
	// Status of the operation.
	//
	NDIS_STATUS StatusToReturn = NDIS_STATUS_SUCCESS;

	DEBUGMSG (ZONE_INIT | ZONE_FUNCTION, (TEXT ("+SMSC100FD: SetInformation[0x%x]\r\n"), Oid));

	switch (Oid)
		{
		case OID_802_3_MULTICAST_LIST:
			//
			// Verify length
			//
			if ((ulInformationBufferLength % ETHER_LENGTH_OF_ADDRESS) != 0)
				{
				StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
				*pulBytesRead = 0;
				*pulBytesNeeded = 0;
				break;
				}
			//
			// Set the new list on the adapter.
			//
			NdisMoveMemory(
				pAdapter->ucAddresses,
				pInformationBuffer,
				min(sizeof(pAdapter->ucAddresses), ulInformationBufferLength)
				);
			//
			//  If we are currently receiving all multicast or
			//  we are in promsicuous mode then we DO NOT call this, or
			//  it will reset the settings.
			//
			if (!(pAdapter->ulPacketFilter & (NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_PROMISCUOUS)))
				StatusToReturn = DispatchSetMulticastAddressList (pAdapter);
			else
				StatusToReturn = NDIS_STATUS_SUCCESS; // The list of multicast addresses is kept by the wrapper.
			break;
		case OID_GEN_CURRENT_PACKET_FILTER:
			//
			// Verify length
			//
			if (ulInformationBufferLength != 4)
				{
				StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
				*pulBytesRead = 0;
				*pulBytesNeeded = 0;
				break;
				}
			NdisMoveMemory (&ulPacketFilter, pucInfoBuffer, 4);
			//
			// Verify bits
			//
			if (ulPacketFilter & (NDIS_PACKET_TYPE_SOURCE_ROUTING | NDIS_PACKET_TYPE_SMT | NDIS_PACKET_TYPE_MAC_FRAME | NDIS_PACKET_TYPE_FUNCTIONAL | NDIS_PACKET_TYPE_ALL_FUNCTIONAL | NDIS_PACKET_TYPE_GROUP))
				{
	            StatusToReturn = NDIS_STATUS_NOT_SUPPORTED;
				*pulBytesRead = 4;
				*pulBytesNeeded = 0;
				break;
				}
			//
			// Set the new value on the adapter.
			//
			pAdapter->ulPacketFilter = ulPacketFilter;
			StatusToReturn = DispatchSetPacketFilter (pAdapter);
			break;
		case OID_GEN_CURRENT_LOOKAHEAD:
			//
			// Verify length
			//
			if (ulInformationBufferLength != 4)
				{
				StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
				*pulBytesRead = 0;
				*pulBytesNeeded = 0;
				break;
				}
			//
			// Store the new value.
			//
			NdisMoveMemory (&ulLookAhead, pucInfoBuffer, 4);
			if (ulLookAhead <= MAX_LOOKAHEAD)
				pAdapter->ulMaxLookAhead = ulLookAhead;
			else
				StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
			break;
		default:
			StatusToReturn = NDIS_STATUS_INVALID_OID;
			*pulBytesRead = 0;
			*pulBytesNeeded = 0;
			break;
		}
	if (StatusToReturn == NDIS_STATUS_SUCCESS)
		{
        *pulBytesRead = ulBytesLeft;
        *pulBytesNeeded = 0;
	    }
	RETAILMSG (1, (TEXT ("-SMSC100FD: SetInformation\r\n")));
    return (StatusToReturn);
	}

/*
 * Description:
 *	Sets the appropriate bits in the adapter filters and modifies
 *	the card Receive Configuration Register if needed.
 *
 * Arguments:
 *	pAdapter - Pointer to the adapter structure.
 *
 * Return Value:
 *	The status of the operation.
 *
 *	Notes:
 *		To receive all multicast packets the multicast
 *		registers on the card must be filled with 1's. To be
 *		promiscuous that must be done as well as setting the
 *		promiscuous physical flag in the RCR. This must be done
 *		as long as ANY protocol bound to this adapter has their
 *		filter set accordingly.
 *
 */
NDIS_STATUS
DispatchSetPacketFilter (IN PSMSC100FD_ADAPTER pAdapter)
	{
    RETAILMSG (1, (TEXT ("+SMSC100FD: DispatchSetPacketFilter\r\n")));
    if (pAdapter->ulPacketFilter & (NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_PROMISCUOUS))
		NdisMSynchronizeWithInterrupt (&(pAdapter)->Interrupt, SyncCardSetAllMulticast, (PVOID)(pAdapter));  // Fills it with 1's
	else
		DispatchSetMulticastAddressList (pAdapter); // No longer need "all multicast".
    //
    // The multicast bit in the RCR should be on if ANY protocol wants
    // multicast/all multicast packets (or is promiscuous).
    //
    if (pAdapter->ulPacketFilter & (NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_MULTICAST | NDIS_PACKET_TYPE_PROMISCUOUS))
		pAdapter->usNicReceiveConfig |= RCR_ALMUL;
	else
		pAdapter->usNicReceiveConfig &= ~RCR_ALMUL;
	//
	// The promiscuous physical bit in the RCR should be on if ANY
	// protocol wants to be promiscuous.
	//
	if (pAdapter->ulPacketFilter & NDIS_PACKET_TYPE_PROMISCUOUS)
		pAdapter->usNicReceiveConfig |= RCR_PROMISC;
	else
		pAdapter->usNicReceiveConfig &= ~RCR_PROMISC;
	NdisMSynchronizeWithInterrupt (&(pAdapter)->Interrupt, SyncCardSetReceiveConfig, (PVOID)(pAdapter));
    DEBUGMSG (ZONE_FUNCTION, (TEXT ("-SMSC100FD: DispatchSetPacketFilter\r\n")));
    return (NDIS_STATUS_SUCCESS);
	}

/*
 * Description:
 *	Sets the multicast list for this adapter.
 *
 * Arguments:
 *	pAdapter - Pointer to the adapter structure.
 *
 * Return Value:
 *	The status of the operation.
 *
 */
NDIS_STATUS
DispatchSetMulticastAddressList (IN PSMSC100FD_ADAPTER pAdapter)
	{
	//
	// Update the local copy of the SMSC100FD multicast regs and copy them to the SNSC100FD
	//
	DEBUGMSG (ZONE_FUNCTION, (TEXT ("+SMSC100FD: DispatchSetMulticastAddressList\r\n")));
	CardFillMulticastRegs (pAdapter);
    NdisMSynchronizeWithInterrupt (&(pAdapter)->Interrupt, SyncCardCopyMulticastRegs, (PVOID)(pAdapter));
	DEBUGMSG (ZONE_FUNCTION, (TEXT ("-SMSC100FD: DispatchSetMulticastAddressList\r\n")));
	return (NDIS_STATUS_SUCCESS);
	}

/*
 * Description:
 *	This is the primary initialization routine for the SMSC100FD driver.
 *	It is simply responsible for the intializing the wrapper and registering
 *	the Miniport driver. It then calls a system and architecture specific
 *  routine that will initialize and register each adapter.
 *
 * Arguments:
 *	DriverObject - Pointer to driver object created by the system.
 *	RegistryPath - Path to the parameters for this driver in the registry.
 *
 * Return Value:
 *	The status of the operation.
 *
 */
NTSTATUS
DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
	{
	HKEY hKey;			// Handle for the registry key
    NDIS_MINIPORT_CHARACTERISTICS Characteristics;	// Characteristics table for this driver.
    NDIS_STATUS Status;	// Ndis function call result

    DEBUGMSG (ZONE_INIT | ZONE_FUNCTION, (TEXT ("+SMSC100FD:DriverEntry for %s\r\n"), RegistryPath->Buffer));
//	NKDbgPrintfW (L"+SMSC100FD: DriverEntry for %s\r\n", RegistryPath->Buffer);
    //
    // Initialize the wrapper.
    //
    NdisMInitializeWrapper (&gSmsc100FdMiniportBlock.NdisWrapperHandle, DriverObject, RegistryPath, NULL);

	if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, (LPCTSTR)RegistryPath->Buffer, 0, KEY_ALL_ACCESS, &hKey))
		{
		DEBUGMSG (ZONE_INIT | ZONE_ERROR, (TEXT ("!SMSC100FD:DriverEntry: Failed to open HKEY_LOCAL_MACHINE key.\r\n")));
    	return (STATUS_UNSUCCESSFUL);
		}
	//
	// Read any registry settings (currently nonthing to read)
	//
	RegCloseKey (hKey);

    //
    // Save the global information about this driver.

⌨️ 快捷键说明

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