
// ===================================================================
//        Testdrv.h
//        Header file for the Test USB Device Driver;
//        Kernel & user mode
//
// ===================================================================

#ifdef DRIVER

#define Test_NAME_MAX  64

//modes
#define Test_MODE_USE_POOL    0
#define Test_MODE_USE_MDL     1

//options
#define Test_OPT_NONE         0


// This is an unused structure in this driver, but is provided here
// so when you extend the driver to deal with USB pipes, you may wish
// to use this structure as an example or model.

typedef struct _Test_PIPE {
    ULONG Mode;
    ULONG Option;
    ULONG Param1;
    ULONG Param2;
    PUSBD_PIPE_INFORMATION PipeInfo;
} Test_PIPE, *PTest_PIPE;

// The interface number on this device that this driver expects to use
// This would be in the bInterfaceNumber field of the Interface Descriptor, hence
// this device driver would need to know this value.

#define SAMPLE_INTERFACE_NBR 0x00

// This driver supports only interface
#define MAX_INTERFACE 0x01


// A structure representing the instance information associated with
// this particular device.

typedef struct _DEVICE_EXTENSION {

    // physical device object
    PDEVICE_OBJECT PhysicalDeviceObject;        

    // Device object we call when submitting Urbs/Irps to the USB stack
    PDEVICE_OBJECT              StackDeviceObject;              

    // Indicates that we have recieved a STOP message
    BOOLEAN Stopped;

        // Indicates the device needs to be cleaned up (ie., some configuration
        // has occurred and needs to be torn down).
        BOOLEAN NeedCleanup;

    // configuration handle for the configuration the
    // device is currently in
    USBD_CONFIGURATION_HANDLE ConfigurationHandle;

    // ptr to the USB device descriptor
    // for this device
    PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;

    // we support up one interface
    PUSBD_INTERFACE_INFORMATION Interface;

    // Name buffer for our named Functional device object link
    WCHAR DeviceLinkNameBuffer[Test_NAME_MAX];

        UCHAR pad[3];

} DEVICE_EXTENSION, *PDEVICE_EXTENSION;


#if DBG

#define Test_KdPrint(_x_) DbgPrint("Test.SYS: "); \
                             DbgPrint _x_ ;
#define TRAP() DbgBreakPoint()
#else
#define Test_KdPrint(_x_)
#define TRAP()
#endif

#ifndef max
#define max(a,b)            (((a) > (b)) ? (a) : (b))
#endif

NTSTATUS
Test_Dispatch(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp
    );

VOID
Test_Unload(
    IN PDRIVER_OBJECT DriverObject
    );

NTSTATUS
Test_StartDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
Test_StopDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
Test_RemoveDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
Test_CallUSBD(
    IN PDEVICE_OBJECT DeviceObject,
    IN PURB Urb
    );

NTSTATUS
Test_PnPAddDevice(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT PhysicalDeviceObject
    );

NTSTATUS
Test_CreateDeviceObject(
    IN PDRIVER_OBJECT DriverObject,
    IN PDEVICE_OBJECT *DeviceObject,
    LONG Instance
    );

NTSTATUS
Test_ConfigureDevice(
    IN  PDEVICE_OBJECT DeviceObject
    );

NTSTATUS
Test_Write(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
Test_Create(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
Test_Close(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
Test_Read(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
Test_ProcessIOCTL(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

NTSTATUS
Test_SelectInterfaces(
    IN PDEVICE_OBJECT DeviceObject,
    IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
    IN PUSBD_INTERFACE_INFORMATION Interface
    );

VOID
Test_Cleanup(
    PDEVICE_OBJECT DeviceObject
    );

ULONG
Test_GetDeviceDescriptor(
    IN PDEVICE_OBJECT DeviceObject,
    PVOID             pvOutputBuffer
    );

ULONG
Test_GetConfigDescriptor(
    IN PDEVICE_OBJECT DeviceObject,
    PVOID             pvOutputBuffer,
    ULONG             ulLength
    );

#endif      //DRIVER section


// ===================================================================
//
// IRP IOCTL Definitions
//
// User mode applications wishing to send IOCTLs to a kernel mode driver
// must use this file to set up the correct type of IOCTL code permissions.
//
// Note: this file depends on the file DEVIOCTL.H which contains the macro
// definition for "CTL_CODE" below.  Include that file before  you include
// this one in your source code.
//
// ===================================================================

#define Test_IOCTL_INDEX  0x0800

#define IRP_Test_GET_PIPE_INFO     CTL_CODE(FILE_DEVICE_UNKNOWN,  \
                                                   Test_IOCTL_INDEX+0,\
                                                   METHOD_BUFFERED,  \
                                                   FILE_ANY_ACCESS)

#define IRP_Test_GET_DEVICE_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,  \
                                                   Test_IOCTL_INDEX+1,\
                                                   METHOD_BUFFERED,  \
                                                   FILE_ANY_ACCESS)

#define IRP_Test_GET_CONFIGURATION_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,  \
                                                   Test_IOCTL_INDEX+2,\
                                                   METHOD_BUFFERED,  \
                                                   FILE_ANY_ACCESS)


#define IRP_TEST_GETONE                       CTL_CODE(FILE_DEVICE_UNKNOWN,  \
                                                   Test_IOCTL_INDEX+5,\
                                                   METHOD_BUFFERED,  \
                                                   FILE_ANY_ACCESS)

#define IRP_TEST_GETTWO                       CTL_CODE(FILE_DEVICE_UNKNOWN,  \
                                                   Test_IOCTL_INDEX+6,\
                                                   METHOD_BUFFERED,  \
                                                   FILE_ANY_ACCESS)

#define IRP_TEST_SETONE                       CTL_CODE(FILE_DEVICE_UNKNOWN,  \
                                                   Test_IOCTL_INDEX+7,\
                                                   METHOD_BUFFERED,  \
                                                   FILE_ANY_ACCESS)

#define IRP_TEST_SETTWO                       CTL_CODE(FILE_DEVICE_UNKNOWN,  \
                                                   Test_IOCTL_INDEX+8,\
                                                   METHOD_BUFFERED,  \
                                                   FILE_ANY_ACCESS)


