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

📄 miniport.cpp

📁 CIRRUS 公司EP93XX系列CPU的WINCE下的BSP
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//**********************************************************************

//                                                                      

// Filename: miniport.cpp

//                                                                      

// Description: Handles as much of the interface between the upper 

//              NDIS layer as possible.

//

// 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) Cirrus Logic Corporation 2001, All Rights Reserved                       

//                                                                      

//**********************************************************************

#include <windows.h>

extern "C"

{

    #include <ndis.h>

    #include <ntddndis.h>

}    

#include <linklist.h>

#include <ceddk.h>

#include "settings.h"

#include "debugzone.h"

#include "recvlist.h"

#include "sendlist.h"

#include "sirstate.h"

#include "irdahw.h"

#include "miniport.h"







//IrSIR bit mask          

//----------------------  

//NDIS_IRDA_SPEED_2400,   

//NDIS_IRDA_SPEED_9600,   

//NDIS_IRDA_SPEED_19200,  

//NDIS_IRDA_SPEED_38400,  

//NDIS_IRDA_SPEED_57600,  

//NDIS_IRDA_SPEED_115200, 

//NDIS_IRDA_SPEED_576K,   

//NDIS_IRDA_SPEED_1152K,  

//NDIS_IRDA_SPEED_4M,     







//

// Static data.

//



static const char 

v_lpszVendorDesc[] = "EP9312 Infrared Port";



static const UINT 

v_rgSupportedOids[] = 

{

    //

    // General required OIDs.

    //



    //                                     Query        Set       Bytes

    //                                   supported   supported   required

    //                                  ----------- ----------- ----------



    OID_GEN_SUPPORTED_LIST,             // Query                    Arr(4)

    OID_GEN_HARDWARE_STATUS,            // Query                    4

    OID_GEN_MEDIA_SUPPORTED,            // Query                    Arr(4)

    OID_GEN_MEDIA_IN_USE,               // Query                    Arr(4)

    OID_GEN_MAXIMUM_LOOKAHEAD,          // Query                    4

    OID_GEN_MAXIMUM_FRAME_SIZE,         // Query                    4

    OID_GEN_LINK_SPEED,                 // Query                    4

    OID_GEN_TRANSMIT_BUFFER_SPACE,      // Query                    4

    OID_GEN_RECEIVE_BUFFER_SPACE,       // Query                    4

    OID_GEN_TRANSMIT_BLOCK_SIZE,        // Query                    4

    OID_GEN_RECEIVE_BLOCK_SIZE,         // Query                    4

    OID_GEN_VENDOR_ID,                  // Query                    4

    OID_GEN_VENDOR_DESCRIPTION,         // Query                    variable

    OID_GEN_VENDOR_DRIVER_VERSION,      // Query                    2

    OID_GEN_CURRENT_PACKET_FILTER,      // Query        Set         4

    OID_GEN_CURRENT_LOOKAHEAD,          // Query        Set         4

    OID_GEN_DRIVER_VERSION,             // Query                    2

    OID_GEN_MAXIMUM_TOTAL_SIZE,         // Query                    4

    OID_GEN_PROTOCOL_OPTIONS,           //              Set         4

    OID_GEN_MAC_OPTIONS,                // Query                    4

    OID_GEN_MEDIA_CONNECT_STATUS,       // Query                    4

    OID_GEN_MAXIMUM_SEND_PACKETS,       // Query                    4

    OID_GEN_VENDOR_DRIVER_VERSION,      // Query                    4



    //

    // Required statistical OIDs.

    //



    OID_GEN_XMIT_OK,                    // Query                    4

    OID_GEN_RCV_OK,                     // Query                    4

    OID_GEN_XMIT_ERROR,                 // Query                    4

    OID_GEN_RCV_ERROR,                  // Query                    4

    OID_GEN_RCV_NO_BUFFER,              // Query                    4



    //

    // Infrared-specific OIDs.

    //



    OID_IRDA_RECEIVING,                 // Query                    4

    OID_IRDA_TURNAROUND_TIME,           // Query                    4

    OID_IRDA_SUPPORTED_SPEEDS,          // Query                    Arr(4)

    OID_IRDA_LINK_SPEED,                // Query        Set         4

    OID_IRDA_MEDIA_BUSY,                // Query        Set         4

    OID_IRDA_EXTRA_RCV_BOFS,            // Query                    4

    OID_IRDA_REACQUIRE_HW_RESOURCES,    //              Set         4

    OID_IRDA_RELEASE_HW_RESOURCES       // Query                    4

};



//

// NDIS compatibility version.

//

#define NDIS_MAJOR_VERSION 0x04

#define NDIS_MINOR_VERSION 0x00



//

// IRSIR compatibility version.

//

#define IRSIR_MAJOR_VERSION 0x01

#define IRSIR_MINOR_VERSION 0x00





//****************************************************************************

// MiniportInitialize

//****************************************************************************

//  Description:    Initializes the NIC and allocates all resources

//                  required to carry out network operations.

//

//  Arguments:

//    OpenErrorStatus - Additional error code (NDIS_STATUS_Xxx) if returning

//                      NDIS_STATUS_OPEN_FAILED.

//

//    piMedium        - Indicates to NDIS which medium type the miniport is using.

//    

//    rgMedium        - Array of NdisMediumXxx the miniport can choose to use.

//    

//    cMediums        - The number of entries in the rgMedium array.

//    

//    hNdisAdapter    - Pointer to handle identifying NDIS' miniport context.

//    

//    hConfiguration  - This is an NDIS wrapper handle context used for 

//                      configuration.

//

// Returns:

//

//    NDIS_STATUS_SUCCESS - IFF miniport is properly configured and all resources

//                          allocated.

//    NDIS_STATUS_OPEN_FAILED, otherwise with extended error code in OpenErrorStatus

//    NDIS_STATUS_UNSUPPORTED_MEDIA - Driver doesn't support mediums.

//    NDIS_STATUS_ADAPTER_NOT_FOUND - NdisOpenConfiguration failure.

//    NDIS_STATUS_RESOURCES         - Could not claim sufficient resources.                         

//

NDIS_STATUS MiniportInitialize

(

    OUT PNDIS_STATUS    OpenErrorStatus,

    OUT PUINT           piMedium,

    IN PNDIS_MEDIUM     rgMediums,

    IN UINT             uiMediumArraySize,

    IN NDIS_HANDLE      hNdisAdapter,

    IN NDIS_HANDLE      hConfiguration 

)

 {

    NDIS_STATUS     status      = NDIS_STATUS_SUCCESS;

    IRMiniport *    pMiniport   = NULL;

    DWORD           i;



    DEBUGMSG(ZONE_INIT,

             (TEXT("+MiniportInitialize(0x%.8X, 0x%.8X, 0x%.8X, %d, ")

              TEXT("0x%.8X, 0x%.8X)\r\n"),

              OpenErrorStatus,

              piMedium, 

              rgMediums,

              uiMediumArraySize,

              hNdisAdapter,

              hConfiguration)

             );             

             

    //

    // Search for the IrDA medium in the array.

    //

    for (i = 0; i < uiMediumArraySize; i++)

    {

        if (rgMediums[i] == NdisMediumIrda) { break; }

    }



    if (i < uiMediumArraySize)

    {

        *piMedium = i;

    }

    else

    {

        // IrDA not found!

        status = NDIS_STATUS_UNSUPPORTED_MEDIA;

    }

             

    //

    // Allocate memory for our IR Device.

    //             

    if(status == NDIS_STATUS_SUCCESS)

    {

        pMiniport = new IRMiniport(hNdisAdapter);

    

        if(!pMiniport)

        {

            status = NDIS_STATUS_RESOURCES;

        }

    }        

    

    //

    // Initialize the recieve list.

    //   

    if(status ==NDIS_STATUS_SUCCESS)

    {

        status = pMiniport->m_ReceivePacketList.Initialize();

    }        



    //

    // Initialize the IRDA Hardware.

    //

    if(status == NDIS_STATUS_SUCCESS)

    {

        status = pMiniport->InitializeIrdaHW();

    }

    

    if(status == NDIS_STATUS_SUCCESS)

    {

    

        //

        // NdisMSetAttributes will associate our adapter handle (pMiniport)

        // with the wrapper's adapter handle. The wrapper will then always use

        // our adapter handle when calling us. 

        // This function informs the NDIS library about significant features 

        // of the caller抯 network adapter during initialization.

        // It cannot fail.

        //

        NdisMSetAttributes

        (

            hNdisAdapter,

            (NDIS_HANDLE)pMiniport,

            FALSE ,                  // TRUE if busmaster DMA.

            NdisInterfaceInternal   // I/O Bus interface type.

        );

        

        //

        // Initialize the Critical Section.  

        // (TODO - Need to catch an exception if there is low memory)

        //

        InitializeCriticalSection(&pMiniport->m_ListCriticalSection);

    }





    //

    // Get serial port.

    //

    if(status == NDIS_STATUS_SUCCESS)

    {

        NDIS_HANDLE hConfig          = NULL;



        //

        // Get device configuration from registry.

        //

        NdisOpenConfiguration

        (

                &status,

                &hConfig,

                hConfiguration

        );



    }            



    //

    // If we fail delete the Miniport class.

    //

    if(status != NDIS_STATUS_SUCCESS && pMiniport)

    {

        delete pMiniport;

    }        

    DEBUGMSG(ZONE_INIT, (TEXT("-MiniportInitialize [0x%.8X]\r\n"), status));

    

    return (status);

}





//****************************************************************************

// MiniportHalt

//****************************************************************************

// Deallocates resources and halts the device. Does opposite of MiniportInitialize.

// 

//

VOID  MiniportHalt(IN NDIS_HANDLE hContext )

{

    IRMiniport * pMiniport = (IRMiniport *)hContext;



    DEBUGMSG(ZONE_INIT, (TEXT("+MiniportHalt(0x%.8X)\r\n"), pMiniport));



    //

    // Free the memory if we allocated it already.

    //

    if(pMiniport)

    {

        delete pMiniport;

    }



    DEBUGMSG(ZONE_INIT, (TEXT("-MiniportHalt\r\n")));

}





//****************************************************************************

// MiniportQueryInformation

//****************************************************************************

// Queries the caps and status of the miniport.

//

// Arguments:

//

//    hContext    - Handle to miniport context. (IRMiniport *).

//    Oid         - System defined OID_Xxx.

//    lpvBuf      - Where to return Oid specific information.

//    cbBuf       - Size of lpvBuf in bytes.

//    lpcbWritten - Number of bytes written to lpvBuf.

//    lpcbNeeded  - Additional bytes required if cbBuf less than the information

//                  to write to the buffer.

//

// Returns:

//

//    NDIS_STATUS Code.

//            

//        Success - NDIS_STATUS_SUCCESS.

//                  NDIS_STATUS_PENDING:

//                    Will complete asynchronously and call 

//                    NdisMQueryInformationComplete.

//

//        Failure - NDIS_STATUS_INVALID_OID:

//                    Don't recognize the OID.

//                  NDIS_STATUS_INVALID_LENGTH:

//                    lpvBuf does not match length for OID.

//                  NDIS_STATUS_NOT_ACCEPTED:                      

//                    Failure.

//                  NDIS_STATUS_NOT_SUPPORTED:

//                    Do not support optional OID.

//                  NDIS_STATUS_RESOURCES:

//                    Failure resources allocation.    

//

NDIS_STATUS MiniportQueryInformation

(

    IN NDIS_HANDLE  hContext,

    IN NDIS_OID     Oid,

    IN PVOID        lpvBuf,

    IN ULONG        cbBuf,

    OUT PULONG      lpcbWritten,

    OUT PULONG      lpcbNeeded

)

{    



    IRMiniport *    pMiniport = (IRMiniport *)hContext;

    NDIS_STATUS     status    = NDIS_STATUS_SUCCESS;

    ULONG           cbNeeded;

//    DWORD           dwSpeedMask;



    DEBUGMSG(ZONE_QUERYINFO,

             (TEXT("+MiniportQueryInformation(0x%.8X, 0x%.8X, 0x%.8X, %d, ")

              TEXT("0x%.8X, 0x%.8X)\r\n"),

              hContext, Oid, lpvBuf, cbBuf, lpcbWritten, lpcbNeeded)

             );

    

    if ((lpcbWritten == NULL) || (lpcbNeeded == NULL)) 

    {

        return NDIS_STATUS_INVALID_ADDRESS;

    }



    //

⌨️ 快捷键说明

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