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

📄 usbfx2lk_devctrl.cpp

📁 基于vc++6.0环境的cypress USB 驱动源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                status = STATUS_INVALID_PARAMETER;
                bytesReturned = 0;
                break;

            }

            if (inputBufferLength < sizeof(USBFX2_PIPE_ENUM)) {

                //
                // Let the user know how big the buffer was
                //  supposed to be
                //
                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User's input buffer is too small for this IOCTL, expecting a USBFX2_PIPE_ENUM\n"));

                status = STATUS_BUFFER_TOO_SMALL;
                bytesReturned = sizeof(USBFX2_PIPE_ENUM);
                break;

            }

            //
            // This is a METHOD_BUFFERED request
            //
            whichPipe = *(PUSBFX2_PIPE_ENUM)Irp->AssociatedIrp.SystemBuffer;

            //
            // Post the IRP off to the reset pipe code. 
            //  This request may pend while the device powers up,
            //  so just return whatever SubmitResetPipe
            //  returns to us and don't touch the IRP
            //
            status = SubmitResetPipe(devExt, Irp, whichPipe);

            OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_SELECTIVE_SUSPEND,
               ("UsbFx2LkDeviceControl: SubmitResetPipe returned "\
                                                "0x%x (%s). Exiting...\n",
                status,OsrNtStatusToString(status)));

            return status;

        }
        case IOCTL_OSRUSBFX2_GET_DEVICE_DESCRIPTOR: {

            PUSB_DEVICE_DESCRIPTOR deviceDescriptor = NULL;

            //
            // This IOCTL doesn't use an input
            //  buffer. Make sure that the caller knows that
            //  and is playing by the rules.
            //
            if (inputBufferLength) {

                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User passed an input buffer - Incorrect usage for this IOCTL\n"));

                status = STATUS_INVALID_PARAMETER;
                bytesReturned = 0;
                break;

            }

            //
            // Make sure the caller's output buffer is large enough
            //  to hold the device descriptor
            //
            if (outputBufferLength < sizeof(USB_DEVICE_DESCRIPTOR)) {

                //
                // Let the user know how big the buffer was
                //  supposed to be
                //
                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User's output buffer is too small for this IOCTL\n"));

                status = STATUS_BUFFER_TOO_SMALL;
                bytesReturned = sizeof(USB_DEVICE_DESCRIPTOR);
                break;

            }

            //
            // This is a METHOD_BUFFERED request
            //
            deviceDescriptor = (PUSB_DEVICE_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;

            //
            // Get our device's descriptor and return it to the user
            // 
            status = GetDeviceDescriptor(devExt, deviceDescriptor, &bytesReturned);

            break;
        }
        case IOCTL_OSRUSBFX2_GET_CONFIGURATION_DESCRIPTOR: {

            PUSB_CONFIGURATION_DESCRIPTOR configDescriptor = NULL;

            //
            // This IOCTL doesn't use an input
            //  buffer. Make sure that the caller knows that
            //  and is playing by the rules.
            //
            if (inputBufferLength) {

                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User passed an input buffer - Incorrect usage for this IOCTL\n"));

                status = STATUS_INVALID_PARAMETER;
                bytesReturned = 0;
                break;

            }

            //
            // Make sure the caller's output buffer is large enough
            //  to hold the configuration descriptor
            //
            if (outputBufferLength < sizeof(USB_CONFIGURATION_DESCRIPTOR)) {

                //
                // Let the user know how big the buffer was
                //  supposed to be
                //
                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User's output buffer is too small for this IOCTL\n"));

                status = STATUS_BUFFER_TOO_SMALL;
                bytesReturned = sizeof(USB_CONFIGURATION_DESCRIPTOR);
                break;

            }

            //
            // This is a METHOD_BUFFERED request
            //
            configDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;

            //
            // Get our device's configuration descriptor and return it 
            //  to the user
            // 
            status = GetConfigurationDescriptor(devExt, configDescriptor, &bytesReturned);

            break;
        }
        case IOCTL_OSRUSBFX2_GET_INTERFACE_INFORMATION: {

            PUSBD_INTERFACE_INFORMATION interfaceDescriptor = NULL;

            //
            // This IOCTL doesn't use an input
            //  buffer. Make sure that the caller knows that
            //  and is playing by the rules.
            //
            if (inputBufferLength) {

                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User passed an input buffer - Incorrect usage for this IOCTL\n"));

                status = STATUS_INVALID_PARAMETER;
                bytesReturned = 0;
                break;

            }

            //
            // Make sure the caller's output buffer is large enough
            //  to hold the configuration descriptor
            //
            if (outputBufferLength < devExt->UsbInterface->Length) {

                //
                // Let the user know how big the buffer was
                //  supposed to be
                //
                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User's output buffer is too small for this IOCTL\n"));

                status = STATUS_BUFFER_TOO_SMALL;
                bytesReturned = devExt->UsbInterface->Length;
                break;

            }

            //
            // This is a METHOD_BUFFERED request
            //
            interfaceDescriptor = (PUSBD_INTERFACE_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

            //
            // Get our device's configuration descriptor and return it 
            //  to the user
            // 
            status = GetInterfaceInformation(devExt, interfaceDescriptor, &bytesReturned);

            break;
        }
        case IOCTL_OSRUSBFX2_GET_PIPE_INFORMATION: {

            PUSBD_PIPE_INFORMATION pipeInfo = NULL;
            USBFX2_PIPE_ENUM whichPipe;

            //
            // Make sure the caller's output buffer is large enough
            //  to hold the pipe info
            //
            if (outputBufferLength < sizeof(USBD_PIPE_INFORMATION)) {

                //
                // Let the user know how big the buffer was
                //  supposed to be
                //
                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User's output buffer is too small for this IOCTL, expecting a USBD_PIPE_INFORMATION\n"));

                status = STATUS_BUFFER_TOO_SMALL;
                bytesReturned = sizeof(USBD_PIPE_INFORMATION);
                break;

            }

            if (inputBufferLength < sizeof(USBFX2_PIPE_ENUM)) {

                //
                // Let the user know how big the buffer was
                //  supposed to be
                //
                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User's input buffer is too small for this IOCTL, expecting a USBFX2_PIPE_ENUM\n"));

                status = STATUS_BUFFER_TOO_SMALL;
                bytesReturned = sizeof(USBFX2_PIPE_ENUM);
                break;

            }

            //
            // For METHOD_BUFFERED requests, the input buffer is the
            //  same as the output buffer. We need to first use the buffer
            //  as an input buffer and capture our USBFX2_PIPE_ENUM
            //
            whichPipe = *(PUSBFX2_PIPE_ENUM)Irp->AssociatedIrp.SystemBuffer;

            //
            // Now we can go ahead and use the buffer as an output buffer
            // 
            pipeInfo = (PUSBD_PIPE_INFORMATION)Irp->AssociatedIrp.SystemBuffer;

            //
            // Return information about this pipe to the user
            //
            status = GetPipeInformation(devExt, whichPipe, pipeInfo, &bytesReturned);

            break;
        }
        case IOCTL_OSRUSBFX2_GET_INTERRUPT_MESSAGE: {
  
            //
            // This IOCTL doesn't use an input
            //  buffer. Make sure that the caller knows that
            //  and is playing by the rules.
            //
            if (inputBufferLength) {

                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User passed an input buffer - Incorrect usage for this IOCTL\n"));

                status = STATUS_INVALID_PARAMETER;
                bytesReturned = 0;
                break;

            }

            //
            // Make sure the caller's output buffer is large enough
            //  to hold the configuration descriptor
            //
            if (!outputBufferLength || 
                (outputBufferLength > devExt->InterruptPipe->PipeInformation.MaximumTransferSize)) {

                //
                // Let the user know how big the buffer was
                //  supposed to be
                //
                OsrTracePrint(TRACE_LEVEL_ERROR,OSRDBG_IOCTL_INFO, 
                    ("UsbFx2LkDeviceControl: User's output buffer is too small for this IOCTL\n"));

                status = STATUS_BUFFER_TOO_SMALL;
                bytesReturned = sizeof(UCHAR);
                break;

            }

            //
            // Post the IRP off to the get interrupt data code. 
            //  This request may pend for an indefinite amount of 
            //  time, so just return whatever SubmitInterruptDataRequest
            //  returns to us and don't touch the IRP
            //
            status = SubmitInterruptDataRequest(devExt, Irp);

            OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_SELECTIVE_SUSPEND,
               ("UsbFx2LkDeviceControl: SubmitInterruptDataRequest returned "\
                                                    "0x%x (%s). Exiting...\n",
                status,OsrNtStatusToString(status)));

            return status;

        }
        default: {

            OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_IOCTL_INFO,("UsbFx2LkDeviceControl: Passing on unknown IOCTL\n"));

            //
            // The default action is to just pass the IRP
            //  down to the lower driver. Maybe HE handles it...
            //
            IoSkipCurrentIrpStackLocation(Irp);
            status = IoCallDriver(devExt->DeviceToSendIrpsTo, Irp);

            //
            // We're done with this request
            //
            OsrDecrementOutstandingIoCount(devExt,__FILE__,__LINE__);

            return status;
        }

    }

    OsrTracePrint(TRACE_LEVEL_INFORMATION,OSRDBG_IOCTL_INFO, 
        ("UsbFx2LkDeviceControl: Completing IRP: 0x%p, Status: 0x%x, BytesReturned: 0x%x\n", 
        Irp, status, bytesReturned));


    //
    // Complete the IRP appropriately
    //
    Irp->IoStatus.Status = status;
    Irp->IoStatus.Information = bytesReturned;
    IoCompleteRequest(Irp,IO_NO_INCREMENT);

    //
    // We're done with this request
    //
    OsrDecrementOutstandingIoCount(devExt,__FILE__,__LINE__);

    OsrTracePrint(TRACE_LEVEL_VERBOSE,OSRDBG_IOCTL_INFO,("UsbFx2LkDeviceControl: Exit\n"));

    return status;
}


///////////////////////////////////////////////////////////////////////////////
//
// IoctlToString
//
//  Takes the IOCTL passed in and tries to match it up with
//   one of our supported IOCTLs. If there's a match, returns
//   a string to be used for debugging purposes.
//
//
//  INPUTS:
//
//      Ioctl  -  An IOCTL value
//
//  OUTPUTS:
//
//      None
//
//  RETURNS:
//
//      A string containing the manifest oonstant name of the
//      IOCTL if there is one. "Unknown" otherwiese
//
//  IRQL:
//
//      IRQL == Any
//
//  CONTEXT:
//
//      Any
//
//  NOTES:
//
///////////////////////////////////////////////////////////////////////////////
LPCSTR IoctlToString(ULONG Ioctl) 
{
    switch (Ioctl) {

        case IOCTL_OSRUSBFX2_GET_BAR_GRAPH_DISPLAY:
            return "IOCTL_OSRUSBFX2_GET_BAR_GRAPH_DISPLAY";

        case IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY:
            return "IOCTL_OSRUSBFX2_SET_BAR_GRAPH_DISPLAY";

        case IOCTL_OSRUSBFX2_READ_SWITCHES:
            return "IOCTL_OSRUSBFX2_READ_SWITCHES";

        case IOCTL_OSRUSBFX2_RESET_PIPE:
            return "IOCTL_OSRUSBFX2_RESET_PIPE";

        case IOCTL_OSRUSBFX2_GET_DEVICE_DESCRIPTOR:
            return "IOCTL_OSRUSBFX2_GET_DEVICE_DESCRIPTOR";

        case IOCTL_OSRUSBFX2_GET_CONFIGURATION_DESCRIPTOR:
            return "IOCTL_OSRUSBFX2_GET_CONFIGURATION_DESCRIPTOR";

        case IOCTL_OSRUSBFX2_GET_PIPE_INFORMATION:
            return "IOCTL_OSRUSBFX2_GET_PIPE_INFORMATION";

        case IOCTL_OSRUSBFX2_GET_7_SEGMENT_DISPLAY:
            return "IOCTL_OSRUSBFX2_GET_7_SEGMENT_DISPLAY";

        case IOCTL_OSRUSBFX2_SET_7_SEGMENT_DISPLAY:
            return "IOCTL_OSRUSBFX2_SET_7_SEGMENT_DISPLAY";

        case IOCTL_OSRUSBFX2_GET_INTERFACE_INFORMATION:
            return "IOCTL_OSRUSBFX2_GET_INTERFACE_INFORMATION";

        case IOCTL_OSRUSBFX2_GET_INTERRUPT_MESSAGE:
            return "IOCTL_OSRUSBFX2_GET_INTERRUPT_MESSAGE";

        default:
            break;
    }

    return "Unknown IOCTL";
}



⌨️ 快捷键说明

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