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

📄 request.c

📁 网络驱动开发
💻 C
📖 第 1 页 / 共 4 页
字号:
            *BytesRead = InformationBufferLength;
                             
            Status = NICSetPacketFilter(
                            Adapter,
                            *((PULONG)InformationBuffer));
            
            if(!Adapter->Promiscuous) {
                bForwardRequest = TRUE;
            }
            break;

        case OID_GEN_CURRENT_LOOKAHEAD:
            //
            // A protocol driver can set a suggested value for the number
            // of bytes to be used in its binding; however, the underlying
            // NIC driver is never required to limit its indications to 
            // the value set.
            //            
            if(InformationBufferLength != sizeof(ULONG)){
                *BytesNeeded = sizeof(ULONG);
                Status = NDIS_STATUS_INVALID_LENGTH;
                break;
            }                
                
            Adapter->ulLookAhead = *(PULONG)InformationBuffer;                

            *BytesRead = sizeof(ULONG);
            Status = NDIS_STATUS_SUCCESS;
            bForwardRequest = FALSE;            
            
            break;

        case OID_PNP_SET_POWER:
            //
            // This OID notifies a miniport driver that its NIC will be 
            // transitioning to the device power state specified in the 
            // InformationBuffer. The miniport driver must always return 
            // NDIS_STATUS_SUCCESS to an OID_PNP_SET_POWER request. An 
            // OID_PNP_SET_POWER request may or may not be preceded by an 
            // OID_PNP_QUERY_POWER request.
            //
            if (InformationBufferLength != sizeof(NDIS_DEVICE_POWER_STATE ))
            {
                Status = NDIS_STATUS_INVALID_LENGTH;
                break;
            }                   
            *BytesRead = sizeof(NDIS_DEVICE_POWER_STATE);
            Status = NDIS_STATUS_SUCCESS; 
            bForwardRequest = TRUE;            
            break;

        case OID_PNP_ADD_WAKE_UP_PATTERN:
            //
            // This OID is sent by a protocol driver to a miniport driver to 
            // specify a wake-up pattern. The wake-up pattern, along with its mask, 
            // is described by an NDIS_PM_PACKET_PATTERN structure.
            //
            pPmPattern = (PNDIS_PM_PACKET_PATTERN) InformationBuffer;
            if (InformationBufferLength < sizeof(NDIS_PM_PACKET_PATTERN))
            {
                Status = NDIS_STATUS_BUFFER_TOO_SHORT;
                
                *BytesNeeded = sizeof(NDIS_PM_PACKET_PATTERN);
                break;
            }
            if (InformationBufferLength < pPmPattern->PatternOffset + pPmPattern->PatternSize)
            {
                Status = NDIS_STATUS_BUFFER_TOO_SHORT;
                
                *BytesNeeded = pPmPattern->PatternOffset + pPmPattern->PatternSize;
                break;
            }        
            *BytesRead = pPmPattern->PatternOffset + pPmPattern->PatternSize;
            Status = NDIS_STATUS_SUCCESS;
            bForwardRequest = TRUE;            
            break;
    
        case OID_PNP_REMOVE_WAKE_UP_PATTERN:
            //
            // This OID requests the miniport driver to delete a wake-up pattern 
            // that it previously received in an OID_PNP_ADD_WAKE_UP_PATTERN request.
            // The wake-up pattern, along with its mask, is described by an 
            // NDIS_PM_PACKET_PATTERN structure. 
            //
            pPmPattern = (PNDIS_PM_PACKET_PATTERN) InformationBuffer;
            if (InformationBufferLength < sizeof(NDIS_PM_PACKET_PATTERN))
            {
                Status = NDIS_STATUS_BUFFER_TOO_SHORT;
                
                *BytesNeeded = sizeof(NDIS_PM_PACKET_PATTERN);
                break;
            }
            if (InformationBufferLength < pPmPattern->PatternOffset + pPmPattern->PatternSize)
            {
                Status = NDIS_STATUS_BUFFER_TOO_SHORT;
                
                *BytesNeeded = pPmPattern->PatternOffset + pPmPattern->PatternSize;
                break;
            }            
            *BytesRead = pPmPattern->PatternOffset + pPmPattern->PatternSize;
            Status = NDIS_STATUS_SUCCESS;
            bForwardRequest = TRUE;
            
            break;

        case OID_PNP_ENABLE_WAKE_UP:
            //
            // This OID specifies which wake-up capabilities a miniport 
            // driver should enable in its NIC. Before the miniport
            // transitions to a low-power state (that is, before NDIS 
            // sends the miniport driver an OID_PNP_SET_POWER request), 
            // NDIS sends the miniport an OID_PNP_ENABLE_WAKE_UP request to
            // enable the appropriate wake-up capabilities. 
            //
            DEBUGP(MP_INFO, ("--> OID_PNP_ENABLE_WAKE_UP\n"));                        
            if(InformationBufferLength != sizeof(ULONG))
            {
                *BytesNeeded = sizeof(ULONG);
                Status = NDIS_STATUS_INVALID_LENGTH;
                break;
            }
            *BytesRead = sizeof(ULONG);                         
            Status = NDIS_STATUS_SUCCESS; 
            bForwardRequest = TRUE;
            break;

        default:
            Status = NDIS_STATUS_INVALID_OID;
            break;

    }
    
    if(Status == NDIS_STATUS_SUCCESS && bForwardRequest && 
        MP_IS_READY(Adapter) && InformationBufferLength){
        
        Status = NICForwardRequest(Adapter,
                            NdisRequestSetInformation,
                            Oid,
                            InformationBuffer,
                            InformationBufferLength,
                            BytesRead,
                            BytesNeeded
                            );
        ASSERT(Status == NDIS_STATUS_SUCCESS);
        Status = NDIS_STATUS_PENDING;
    }

    DEBUGP(MP_VERY_LOUD, ("<-- MPSetInformation Status = 0x%08x\n", Status));
    
    return(Status);
}

ULONG 
NICGetMediaConnectStatus(
    PMP_ADAPTER Adapter
    )
/*++
Routine Description:
    This routine will query the hardware and return      
    the media status.

Arguments:
    IN PMP_ADAPTER Adapter - pointer to adapter block
   
Return Value:
    NdisMediaStateDisconnected or
    NdisMediaStateConnected
    
--*/
{
    if(MP_TEST_FLAG(Adapter, fMP_DISCONNECTED))
    {
        return(NdisMediaStateDisconnected);
    }
    else
    {
        return(NdisMediaStateConnected);
    }
}

NDIS_STATUS 
NICSetPacketFilter(
    IN PMP_ADAPTER Adapter,
    IN ULONG PacketFilter)
/*++
Routine Description:
    This routine will set up the adapter so that it accepts packets 
    that match the specified packet filter.  The only filter bits   
    that can truly be toggled are for broadcast and promiscuous     

Arguments:
    IN PMP_ADAPTER Adapter - pointer to adapter block
    IN ULONG PacketFilter - the new packet filter 
    
Return Value:
    NDIS_STATUS_SUCCESS
    NDIS_STATUS_NOT_SUPPORTED
    
--*/

{
    NDIS_STATUS      Status = NDIS_STATUS_SUCCESS;
    
    DEBUGP(MP_TRACE, ("--> NICSetPacketFilter\n"));
    
    // any bits not supported?
    if(PacketFilter & ~NIC_SUPPORTED_FILTERS)
    {
        return(NDIS_STATUS_NOT_SUPPORTED);
    }
    
    // any filtering changes?
    if(PacketFilter != Adapter->PacketFilter)
    {   
        //
        // Change the filtering modes on hardware
        // TODO 
                
                
        // Save the new packet filter value                                                               
        Adapter->PacketFilter = PacketFilter;
    }

    DEBUGP(MP_TRACE, ("<-- NICSetPacketFilter\n"));
    
    return(Status);
}


NDIS_STATUS 
NICSetMulticastList(
    IN PMP_ADAPTER              Adapter,
    IN PVOID                    InformationBuffer,
    IN ULONG                    InformationBufferLength,
    OUT PULONG                  pBytesRead,
    OUT PULONG                  pBytesNeeded
    )
/*++
Routine Description:
    This routine will set up the adapter for a specified multicast
    address list.                                                 
    
Arguments:
    IN PMP_ADAPTER Adapter - Pointer to adapter block
    InformationBuffer       - Buffer for information
    InformationBufferLength   Size of this buffer
    pBytesRead                Specifies how much info is read
    BytesNeeded               In case the buffer is smaller than 
    
Return Value:

    NDIS_STATUS
    
--*/
{
    NDIS_STATUS            Status = NDIS_STATUS_SUCCESS;
    ULONG                  index;

    DEBUGP(MP_TRACE, ("--> NICSetMulticastList\n"));
    
    //
    // Initialize.
    //
    *pBytesNeeded = 0;
    *pBytesRead = InformationBufferLength;

    do
    {
        if (InformationBufferLength % ETH_LENGTH_OF_ADDRESS)
        {
            Status = NDIS_STATUS_INVALID_LENGTH;
            break;
        }

        if (InformationBufferLength > (NIC_MAX_MCAST_LIST * ETH_LENGTH_OF_ADDRESS))
        {
            Status = NDIS_STATUS_MULTICAST_FULL;
            *pBytesNeeded = NIC_MAX_MCAST_LIST * ETH_LENGTH_OF_ADDRESS;
            break;
        }

        //
        // Protect the list update with a lock if it can be updated by
        // another thread simultaneously.
        //

        NdisZeroMemory(Adapter->MCList,
                       NIC_MAX_MCAST_LIST * ETH_LENGTH_OF_ADDRESS);
        
        NdisMoveMemory(Adapter->MCList,
                       InformationBuffer,
                       InformationBufferLength);
        
        Adapter->ulMCListSize =    InformationBufferLength / ETH_LENGTH_OF_ADDRESS;
        
#if DBG
        // display the multicast list
        for(index = 0; index < Adapter->ulMCListSize; index++)
        {
            DEBUGP(MP_VERY_LOUD, ("MC(%d) = %02x-%02x-%02x-%02x-%02x-%02x\n", 
                index,
                Adapter->MCList[index][0],
                Adapter->MCList[index][1],
                Adapter->MCList[index][2],
                Adapter->MCList[index][3],
                Adapter->MCList[index][4],
                Adapter->MCList[index][5]));
        }
#endif        
    }
    while (FALSE);    

    //
    // Program the hardware to add suport for these muticast addresses
    // 

    DEBUGP(MP_TRACE, ("<-- NICSetMulticastList\n"));
    
    return(Status);

}

NDIS_STATUS
    NICForwardRequest(
    IN PMP_ADAPTER                  Adapter,
    IN NDIS_REQUEST_TYPE            RequestType,
    IN NDIS_OID                     Oid,
    IN PVOID                        InformationBuffer,
    IN ULONG                        InformationBufferLength,
    OUT PULONG                      BytesReadOrWritten,
    OUT PULONG                      BytesNeeded
    )
/*++

Routine Description:

    Utility routine that forwards an NDIS request made on a Adapter to the
    lower binding. Since at most a single request can be pended on a Adapter,
    we use the pre-allocated request structure embedded in the Adapter struct.

Arguments:


Return Value:

⌨️ 快捷键说明

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