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

📄 request.c

📁 HomePNA的Usb网卡驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
                size in such a way that it will not transform 
                a protocol-supplied net packet of this size 
                to a net packet too large for the true network medium.

*/
                *(UINT *)InformationBuffer =  MAX_PACKET_SIZE;

                break;

            case OID_GEN_MAXIMUM_TOTAL_SIZE:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_MAXIMUM_TOTAL_SIZE)\n"));

/*
                The maximum total packet length, in bytes, 
                the device supports, including the header. 
                This value is medium-dependent. The returned 
                length specifies the largest packet a protocol 
                driver can pass to NdisSend or NdisSendPackets.

                For a binding emulating another media type,
                the device driver must define the maximum total 
                packet length in such a way that it will not 
                transform a protocol-supplied net packet of 
                this size to a net packet too large for the true network medium.

*/
                *(UINT *)InformationBuffer =MAX_PACKET_SIZE+2;

                break;

            case OID_GEN_VENDOR_ID:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_VENDOR_ID)\n"));

                // we get this from our config descriptor
                *(UINT *)InformationBuffer = device->IdVendor;

                break;

            case OID_GEN_VENDOR_DESCRIPTION:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_VENDOR_DESCRIPTION)\n"));

                // BUGBUG? should we ask for class-specific string?
                NdisMoveMemory(
                            InformationBuffer,
                            (PVOID)vendorDesc,
                            sizeof(vendorDesc)
                            );

                break;

            case OID_GEN_LINK_SPEED:
                DEBUGONCE(DBG_FUNC, ("MiniportQueryInformation(OID_GEN_LINK_SPEED)\n"));

                //
                // Return MAXIMUM POSSIBLE speed for this device in units
                // of 100 bits/sec.
                //

                *(UINT *)InformationBuffer = 1000000;

                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_LINK_SPEED)  %d\n",*(UINT *)InformationBuffer));


                break;



            case OID_GEN_CURRENT_PACKET_FILTER:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_CURRENT_PACKET_FILTER)\n"));

                *(UINT *)InformationBuffer = NDIS_PACKET_TYPE_PROMISCUOUS;

                break;


            case OID_GEN_DRIVER_VERSION:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_DRIVER_VERSION)\n"));

                *(USHORT *)InformationBuffer = ((NDIS_MAJOR_VERSION << 8) |
                                                 NDIS_MINOR_VERSION);

                break;


            case OID_GEN_PROTOCOL_OPTIONS:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_PROTOCOL_OPTIONS)\n"));

                DEBUGMSG(DBG_ERR, ("This is a set-only OID\n"));
                *BytesWritten = 0;
                status = NDIS_STATUS_NOT_SUPPORTED;

                break;

            case OID_GEN_MAC_OPTIONS:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_MAC_OPTIONS)\n"));

                *(UINT *)InformationBuffer =   
                    NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |
                    NDIS_MAC_OPTION_TRANSFERS_NOT_PEND;  

                break;

            case OID_GEN_MEDIA_CONNECT_STATUS:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_MEDIA_CONNECT_STATUS)\n"));

                //
                // Since we are not physically connected to a LAN, we
                // cannot determine whether or not we are connected;
                // so always indicate that we are.
                //

                *(UINT *)InformationBuffer = NdisMediaStateConnected;

                break;

            case OID_GEN_MAXIMUM_SEND_PACKETS:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_MAXIMUM_SEND_PACKETS)\n"));

                //The maximum number of send packets the
                //MiniportSendPackets function can accept. 
                //If a larger packet array is given to MiniportSendPackets, 
                //it will return some packets in the array to NDIS for resubmission later. 
                //If the underlying driver has only a MiniportSend function, it should return one
                //for this query. This is our case 

                *(UINT *)InformationBuffer = 1;

                break;

            case OID_GEN_VENDOR_DRIVER_VERSION:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_VENDOR_DRIVER_VERSION)\n"));

                *(UINT *)InformationBuffer =
                                            ((NDIS_MAJOR_VERSION << 16) |
                                              NDIS_MINOR_VERSION);

                break;

            //
            // Required statistical OIDs.
            //

            case OID_GEN_XMIT_OK:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_XMIT_OK)\n"));

                *(UINT *)InformationBuffer =
                                (UINT)device->packetsSent;

                break;

            case OID_GEN_RCV_OK:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_RCV_OK)\n"));

                *(UINT *)InformationBuffer =
                                (UINT)device->packetsReceived;

                break;

            case OID_GEN_XMIT_ERROR:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_XMIT_ERROR)\n"));

                *(UINT *)InformationBuffer =
                                (UINT)device->packetsSentDropped;

                break;

            case OID_GEN_RCV_ERROR:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_RCV_ERROR)\n"));

                *(UINT *)InformationBuffer =
                                (UINT)device->packetsReceivedDropped;

                break;

            case OID_GEN_RCV_NO_BUFFER:
                DEBUGONCE(DBG_FUNC, ("    MiniportQueryInformation(OID_GEN_RCV_NO_BUFFER)\n"));

                *(UINT *)InformationBuffer =
                                (UINT)device->packetsReceivedOverflow;

                break;


            // PNP OIDs
            case OID_PNP_CAPABILITIES:
                DEBUGONCE(DBG_WARN, ("USB: OID_PNP_CAPABILITIES OID %x BufLen:%d\n", Oid, InformationBufferLength));

                NdisZeroMemory( // say all pnp caps are unspecified
                            InformationBuffer,
                            sizeof(NDIS_PNP_CAPABILITIES)
                            );


                break;


            default:
                DEBUGMSG(DBG_FUNC, ("    MiniportQueryInformation(%d=0x%x), invalid OID\n", Oid, Oid));

                status = NDIS_STATUS_NOT_SUPPORTED; 

                break;
        }
    }
    else
    {
        *BytesNeeded = infoSizeNeeded - InformationBufferLength;
        *BytesWritten = 0;
        status = NDIS_STATUS_INVALID_LENGTH;
    }

done:

    if (  NDIS_STATUS_PENDING != status  ) {

        // zero-out the time so check for hang handler knows nothing pending

        device->LastQueryTime.QuadPart = 0;
        device->fQuerypending            = FALSE;
    }

    DEBUGMSG(DBG_FUNC, ("-MiniportQueryInformation\n"));

    return status;
}

/*****************************************************************************
*
*  Function:   MiniportSetInformation
*
*  Synopsis:   MiniportSetInformation allows other layers of the network software
*              (e.g., a transport driver) to control the miniport driver
*              by changing information that the miniport driver maintains
*              in its OIDs, such as the packet filters or multicast addresses.
*
*  Arguments:  MiniportAdapterContext  - miniport context area (PUSB_DEVICE)
*              Oid                     - system defined OID_Xxx
*              InformationBuffer       - buffer containing data for the set Oid
*              InformationBufferLength - specifies size of InformationBuffer
*              BytesRead               - bytes read from InformationBuffer
*              BytesNeeded             - addition bytes required if
*                                        InformationBufferLength is less than
*                                        what the Oid requires to read
*
*  Returns:    NDIS_STATUS_SUCCESS       - success
*              NDIS_STATUS_PENDING       - will complete asynchronously and
*                                          call NdisMSetInformationComplete
*              NDIS_STATUS_INVALID_OID   - don't recognize the Oid
*              NDIS_STATUS_INVALID_LENGTH- InformationBufferLength does not
*                                          match length for the Oid
*              NDIS_STATUS_INVALID_DATA  - supplied data was invalid for the
*                                          given Oid
*              NDIS_STATUS_NOT_ACCEPTED  - failure
*              NDIS_STATUS_NOT_SUPPORTED - do not support an optional Oid
*              NDIS_STATUS_RESOURCES     - failed allocation of resources
*
*  Notes:
*
*
*****************************************************************************/

NDIS_STATUS
MiniportSetInformation(
            IN  NDIS_HANDLE MiniportAdapterContext,
            IN  NDIS_OID    Oid,
            IN  PVOID       InformationBuffer,
            IN  ULONG       InformationBufferLength,
            OUT PULONG      BytesRead,
            OUT PULONG      BytesNeeded
            )
{
    NDIS_STATUS status;
    PUSB_DEVICE device;
    NTSTATUS ntStatus;

    int i;

    DEBUGMSG(DBG_FUNC, ("+MiniportSetInformation\n"));


    status   = NDIS_STATUS_SUCCESS;
    device = CONTEXT_TO_DEV(MiniportAdapterContext);

    ASSERT( NULL != device ); 
    ASSERT( NULL != BytesRead );
    ASSERT( NULL != BytesNeeded );


    NdisGetCurrentSystemTime( &device->LastSetTime ); //used by check for hang handler
    device->fSetpending = TRUE;

    if ( NULL == InformationBuffer ) { // Should be impossible but it happened on an MP system!

        DEBUGMSG(DBG_ERR, ("    MiniportSetInformation() NULL info buffer passed!,InformationBufferLength = dec %d\n",InformationBufferLength));
        status = NDIS_STATUS_NOT_ACCEPTED;
        *BytesNeeded =0;
        *BytesRead = 0;
        goto done;
 
    }

    if (InformationBufferLength >= sizeof(UINT))
    {
        //
        //  Set default results.
        //

        UINT info = 0;
        
        if ( NULL != InformationBuffer ) {
            info = *(UINT *)InformationBuffer;
        }


        *BytesRead = sizeof(UINT);
        *BytesNeeded = 0;

        switch (Oid)
        {
            //
            //  Generic OIDs.
            //

            case OID_GEN_CURRENT_PACKET_FILTER:
                DEBUGONCE(DBG_FUNC, ("    MiniportSetInformation(OID_GEN_CURRENT_PACKET_FILTER, %xh)\n", info));

                //
                // We ignore the packet filter itself.
                //
                // Note:  The protocol may use a NULL filter, in which case
                //        we will not get this OID; so don't wait on
                //        OID_GEN_CURRENT_PACKET_FILTER to start receiving
                //        frames.
                //

                device->fGotFilterIndication = TRUE;

                break;

            case OID_GEN_CURRENT_LOOKAHEAD:
                DEBUGONCE(DBG_FUNC, ("    MiniportSetInformation(OID_GEN_CURRENT_LOOKAHEAD, %xh)\n", info));

                //
                // We always indicate entire receive frames all at once,
                // so just ignore this.
                //

                break;

            case OID_GEN_PROTOCOL_OPTIONS:
                DEBUGONCE(DBG_FUNC, ("    MiniportSetInformation(OID_GEN_PROTOCOL_OPTIONS, %xh)\n", info));

                //
                // Ignore.
                //

                break;


            default:
                DEBUGMSG(DBG_ERR, ("    MiniportSetInformation(OID=%d=0x%x, value=%xh) - invalid OID\n", Oid, Oid, info));

                *BytesRead = 0;
                *BytesNeeded = 0;
                status = NDIS_STATUS_INVALID_OID;

                break;
        }
    }
    else
    {
        //
        // The given data buffer is not large enough for the information
        // to set.
        //

        *BytesRead = 0;
        *BytesNeeded = sizeof(UINT);
        status = NDIS_STATUS_INVALID_LENGTH;
    }

done:

    if (  NDIS_STATUS_PENDING != status  ) {

        // zero-out the time so check for hang handler knows nothing pending

        device->LastSetTime.QuadPart = 0;
        device->fSetpending            = FALSE;
    }

    DEBUGMSG(DBG_FUNC, ("-MiniportSetInformation\n"));

    return status;
}


⌨️ 快捷键说明

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