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

📄 mavioctl.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 5 页
字号:

//****************************************************************************
//
// Handles the "get descriptor" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorGetDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
                           PUCHAR buffer, MavUsb_GetDescriptorParams *pIn,
                           MavUsb_GetDescriptorResult *pOut, PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the "get_descriptor" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulIndex,
                                        USB_Vendor_GetDescriptor, 0,
                                        (USHORT)pIn->ulDescriptor, buffer, 8);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 8)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];

            //
            // Get the length of the descriptor value.
            //
            pOut->ulLength = ((ULONG *)buffer)[1];

            //
            // Read the value of the descriptor.
            //
            if(*result && pOut->ulLength)
            {
                ntStatus = MavUsb_BulkXfer(DeviceObject, pOut->pcValue,
                                           pOut->ulLength, TRUE);
            }
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "set descriptor" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorSetDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
                           PUCHAR buffer, MavUsb_SetDescriptorParams *pIn,
                           PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the new descriptor value.
    //
    ntStatus = MavUsb_BulkXfer(DeviceObject, pIn->pcValue, pIn->ulLength,
                               FALSE);
    if(!NT_SUCCESS(ntStatus))
    {
        return(ntStatus);
    }

    //
    // Send the "set_descriptor" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulIndex,
                                        USB_Vendor_SetDescriptor,
                                        (USHORT)pIn->ulLength,
                                        (USHORT)pIn->ulDescriptor, buffer, 4);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "num drives" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorNumDrives(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
                       PUCHAR buffer, MavUsb_NumDrivesResult *pOut,
                       PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the "num_drives" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0,
                                        USB_Vendor_NumDrives, 0, 0, buffer, 8);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 8)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];

            //
            // Get the number of drives.
            //
            pOut->ulNumDrives = ((ULONG *)buffer)[1];
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "open" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorOpen(IN PDEVICE_OBJECT DeviceObject, IN PURB urb, PUCHAR buffer,
                  MavUsb_OpenParams *pIn, PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the file name.
    //
    ntStatus = MavUsb_BulkXfer(DeviceObject, (char *)pIn->pusFileName, 256,
                               FALSE);
    if(!NT_SUCCESS(ntStatus))
    {
        return(ntStatus);
    }

    //
    // Send the "open" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulDriveNum,
                                        USB_Vendor_Open, (USHORT)pIn->ulFlags,
                                        0, buffer, 4);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "create" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorCreate(IN PDEVICE_OBJECT DeviceObject, IN PURB urb, PUCHAR buffer,
                    MavUsb_CreateParams *pIn, PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the file name.
    //
    ntStatus = MavUsb_BulkXfer(DeviceObject, (char *)pIn->pusFileName, 256,
                               FALSE);
    if(!NT_SUCCESS(ntStatus))
    {
        return(ntStatus);
    }

    //
    // Send the "create" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, pIn->ulDriveNum,
                                        USB_Vendor_Create,
                                        (USHORT)(pIn->ulLength & 0xffff),
                                        (USHORT)(pIn->ulLength >> 16), buffer,
                                        4);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "seek" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorSeek(IN PDEVICE_OBJECT DeviceObject, IN PURB urb, PUCHAR buffer,
                  MavUsb_SeekParams *pIn, PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the "seek" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0, USB_Vendor_Seek,
                                        (USHORT)(pIn->ulPosition & 0xffff),
                                        (USHORT)(pIn->ulPosition >> 16),
                                        buffer, 4);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 4)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "tell" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorTell(IN PDEVICE_OBJECT DeviceObject, IN PURB urb, PUCHAR buffer,
                  MavUsb_TellResult *pOut, PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the "tell" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0, USB_Vendor_Tell,
                                        0, 0, buffer, 8);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 8)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];

            //
            // Get the current file pointer.
            //
            pOut->ulPosition = ((ULONG *)buffer)[1];
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "length" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorLength(IN PDEVICE_OBJECT DeviceObject, IN PURB urb, PUCHAR buffer,
                    MavUsb_LengthResult *pOut, PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the "length" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0,
                                        USB_Vendor_Length, 0, 0, buffer, 8);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))
    {
        //
        // Make sure that the correct amount of data was returned.
        //
        if(urb->UrbControlVendorClassRequest.TransferBufferLength != 8)
        {
            //
            // The wrong amount of data was returned, so return a device error.
            //
            ntStatus = STATUS_DEVICE_DATA_ERROR;
        }
        else
        {
            //
            // Get the return code.
            //
            *result = ((ULONG *)buffer)[0];

            //
            // Get the file length.
            //
            pOut->ulLength = ((ULONG *)buffer)[1];
        }
    }

    //
    // Return the result.
    //
    return(ntStatus);
}

//****************************************************************************
//
// Handles the "get date" request IOCTL.
//
//****************************************************************************
NTSTATUS
MavUsb_VendorGetDate(IN PDEVICE_OBJECT DeviceObject, IN PURB urb,
                     PUCHAR buffer, MavUsb_GetDateResult *pOut, PULONG result)
{
    NTSTATUS ntStatus;

    //
    // Send the "get date" vendor request.
    //
    ntStatus = MavUsb_SendVendorCommand(DeviceObject, urb, 0,
                                        USB_Vendor_GetDate, 0, 0, buffer, 8);

    //
    // If the vendor packet was sent successfully, then return the result.
    //
    if(NT_SUCCESS(ntStatus))

⌨️ 快捷键说明

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