win-pvdrivers

changeset 969:1306945ecc59 0.11.0.357

Big cleanup. Push ring code to the FDO and send requests for processing there.
author James Harper <james.harper@bendigoit.com.au>
date Sat Jan 14 23:22:29 2012 +1100 (2012-01-14)
parents 1ad5f1d3a664
children a473ca2d1eac
files xenusb/xenusb.h xenusb/xenusb_decode.c xenusb/xenusb_devurb.c xenusb/xenusb_fdo.c xenusb/xenusb_hub.c xenusb/xenusb_huburb.c
line diff
     1.1 --- a/xenusb/xenusb.h	Sat Jan 14 23:19:33 2012 +1100
     1.2 +++ b/xenusb/xenusb.h	Sat Jan 14 23:22:29 2012 +1100
     1.3 @@ -25,7 +25,11 @@ Foundation, Inc., 51 Franklin Street, Fi
     1.4  #define _XENUSB_H_
     1.5  
     1.6  #define __attribute__(arg) /* empty */
     1.7 -#define EISCONN 127
     1.8 +
     1.9 +#define ECONNRESET  104
    1.10 +#define ESHUTDOWN   108
    1.11 +#define EINPROGRESS 115
    1.12 +#define EISCONN     127
    1.13  
    1.14  #include <ntifs.h>
    1.15  #include <ntddk.h>
    1.16 @@ -97,37 +101,39 @@ Foundation, Inc., 51 Franklin Street, Fi
    1.17  #define LINUX_URB_ZERO_PACKET         0x0040  /* Finish bulk OUT with short packet */
    1.18  #define LINUX_URB_NO_INTERRUPT        0x0080  /* HINT: no non-error interrupt needed */
    1.19  
    1.20 -#define PRE_DECLARE_TYPE_TYPEDEF(x) struct _##x; typedef struct _##x x##_t
    1.21 +//#define PRE_DECLARE_TYPE_TYPEDEF(x) struct _##x; typedef struct _##x x##_t
    1.22  
    1.23 -#if 0
    1.24  struct _usbif_shadow;
    1.25  typedef struct _usbif_shadow usbif_shadow_t;
    1.26 -#endif
    1.27 -
    1.28 -PRE_DECLARE_TYPE_TYPEDEF(usbif_shadow);
    1.29  
    1.30  struct _usbif_shadow {
    1.31    uint16_t id;
    1.32 -  union
    1.33 -  {
    1.34 -    struct {
    1.35 -      WDFREQUEST request;
    1.36 -      PURB urb;
    1.37 -    };
    1.38 -    KEVENT event;
    1.39 -  };
    1.40 -  //WDFDMATRANSACTION dma_transaction;
    1.41 -  PMDL mdl;
    1.42 +  WDFREQUEST request;
    1.43 +  usbif_urb_request_t req_storage; /* used by cancel/unlink */
    1.44 +  usbif_urb_request_t *req;
    1.45 +  usbif_urb_response_t *rsp;
    1.46 +  PMDL mdl; /* can be null for requests with no data */
    1.47    ULONG total_length;
    1.48 -  /* called at DISPATCH_LEVEL */
    1.49 -  VOID (*callback)(usbif_shadow_t *);
    1.50 +  usbif_shadow_t *next; /* collect then process responses as they come off the ring */
    1.51 +};
    1.52 +
    1.53 +/* needs to be at least USB_URB_RING_SIZE number of requests available */
    1.54 +#define MAX_SHADOW_ENTRIES 64
    1.55 +#define SHADOW_ENTRIES max(MAX_SHADOW_ENTRIES, USB_URB_RING_SIZE)
    1.56 +
    1.57 +/*
    1.58 +for IOCTL_PVUSB_SUBMIT_URB, the pvusb_urb_t struct is passed as Parameters.Others.Arg1
    1.59 +req must have pipe, transfer_flags, buffer_length, and u fields filled in
    1.60 +*/
    1.61 +
    1.62 +#define IOCTL_INTERNAL_PVUSB_SUBMIT_URB CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_NEITHER, FILE_READ_DATA | FILE_WRITE_DATA)
    1.63 +
    1.64 +typedef struct _pvurb {
    1.65    usbif_urb_request_t req;
    1.66    usbif_urb_response_t rsp;
    1.67 -  usbif_shadow_t *next; /* for gathering shadows from the ring for callback */
    1.68 -};
    1.69 -
    1.70 -#define MAX_SHADOW_ENTRIES 64
    1.71 -#define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, USB_URB_RING_SIZE)
    1.72 +  PMDL mdl; /* can be null for requests with no data */
    1.73 +  ULONG total_length;
    1.74 +} pvurb_t;
    1.75  
    1.76  struct _xenusb_endpoint_t;
    1.77  struct _xenusb_interface_t;
    1.78 @@ -201,6 +207,7 @@ typedef struct {
    1.79    /* other magic numbers are (ULONG)'BStx' at offset 0x4C and (ULONG)'HUB ' somewhere in an FDO extension(?) */
    1.80    BOOLEAN XenBus_ShuttingDown;
    1.81    WDFQUEUE io_queue;
    1.82 +  WDFQUEUE pvurb_queue;
    1.83    WDFCHILDLIST child_list;
    1.84    
    1.85    WDFDEVICE root_hub_device;
    1.86 @@ -235,6 +242,7 @@ WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUS
    1.87  typedef struct {  
    1.88    WDFDEVICE wdf_device;
    1.89    WDFDEVICE wdf_device_bus_fdo;
    1.90 +  WDFIOTARGET bus_fdo_target;
    1.91    WDFQUEUE io_queue;
    1.92    WDFQUEUE urb_queue;
    1.93    ULONG device_number;
    1.94 @@ -243,7 +251,6 @@ typedef struct {
    1.95    xenusb_device_t *usb_device;
    1.96    PVOID BusCallbackContext;
    1.97    PRH_INIT_CALLBACK BusCallbackFunction;
    1.98 -
    1.99  } XENUSB_PDO_DEVICE_DATA, *PXENUSB_PDO_DEVICE_DATA;
   1.100  
   1.101  WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_PDO_DEVICE_DATA, GetXupdd)
   1.102 @@ -266,6 +273,7 @@ typedef struct {
   1.103    //xenusb_compatible_id_details_t xucid[1];
   1.104  } XENUSB_PDO_IDENTIFICATION_DESCRIPTION, *PXENUSB_PDO_IDENTIFICATION_DESCRIPTION;
   1.105  
   1.106 +/* call with ring lock held */
   1.107  static usbif_shadow_t *
   1.108  get_shadow_from_freelist(PXENUSB_DEVICE_DATA xudd)
   1.109  {
   1.110 @@ -278,6 +286,7 @@ get_shadow_from_freelist(PXENUSB_DEVICE_
   1.111    return &xudd->shadows[xudd->shadow_free_list[xudd->shadow_free]];
   1.112  }
   1.113  
   1.114 +/* call with ring lock held */
   1.115  static VOID
   1.116  put_shadow_on_freelist(PXENUSB_DEVICE_DATA xudd, usbif_shadow_t *shadow)
   1.117  {
   1.118 @@ -335,14 +344,6 @@ XenUsb_EnumeratePorts(WDFDEVICE device);
   1.119  EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB;
   1.120  EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB;
   1.121  
   1.122 -NTSTATUS
   1.123 -XenUsb_ExecuteRequest(
   1.124 -  PXENUSB_DEVICE_DATA xudd,
   1.125 -  usbif_shadow_t *shadow,
   1.126 -  PVOID transfer_buffer,
   1.127 -  PMDL transfer_buffer_mdl,
   1.128 -  ULONG transfer_buffer_length);
   1.129 -
   1.130  #define URB_DECODE_UNKNOWN     0 /* URB is unknown */
   1.131  #define URB_DECODE_COMPLETE    1 /* URB is decoded and no further work should be required */
   1.132  #define URB_DECODE_INCOMPLETE  2 /* URB is decoded but further work is required */
     2.1 --- a/xenusb/xenusb_decode.c	Sat Jan 14 23:19:33 2012 +1100
     2.2 +++ b/xenusb/xenusb_decode.c	Sat Jan 14 23:22:29 2012 +1100
     2.3 @@ -217,384 +217,6 @@ XenUsb_DecodeControlUrb(PURB urb, urb_de
     2.4      decode_data->mdl = NULL;
     2.5      retval = URB_DECODE_INCOMPLETE;
     2.6      break;
     2.7 -#if 0
     2.8 -  case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
     2.9 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n"));
    2.10 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
    2.11 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    2.12 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
    2.13 -    decode_data->setup_packet.default_pipe_setup_packet.bRequest = USB_REQUEST_GET_DESCRIPTOR;
    2.14 -    decode_data->setup_packet.default_pipe_setup_packet.wValue.LowByte = urb->UrbControlDescriptorRequest.Index;
    2.15 -    decode_data->setup_packet.default_pipe_setup_packet.wValue.HiByte = urb->UrbControlDescriptorRequest.DescriptorType;
    2.16 -    switch(urb->UrbControlDescriptorRequest.DescriptorType)
    2.17 -    {
    2.18 -    case USB_STRING_DESCRIPTOR_TYPE:
    2.19 -      decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = urb->UrbControlDescriptorRequest.LanguageId;
    2.20 -      break;
    2.21 -    default:
    2.22 -      decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = 0;
    2.23 -      break;
    2.24 -    }
    2.25 -    decode_data->setup_packet.default_pipe_setup_packet.wLength = (USHORT)urb->UrbControlDescriptorRequest.TransferBufferLength;
    2.26 -    decode_data->transfer_flags = USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK;
    2.27 -    decode_data->buffer = urb->UrbControlTransfer.TransferBuffer;
    2.28 -    decode_data->mdl = urb->UrbControlTransfer.TransferBufferMDL;
    2.29 -    decode_data->length = &urb->UrbControlTransfer.TransferBufferLength;
    2.30 -    retval = URB_DECODE_COMPLETE;
    2.31 -    break;
    2.32 -  case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
    2.33 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n"));
    2.34 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
    2.35 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    2.36 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
    2.37 -    decode_data->setup_packet.default_pipe_setup_packet.bRequest = USB_REQUEST_GET_DESCRIPTOR;
    2.38 -    decode_data->setup_packet.default_pipe_setup_packet.wValue.LowByte = urb->UrbControlDescriptorRequest.Index;
    2.39 -    decode_data->setup_packet.default_pipe_setup_packet.wValue.HiByte = urb->UrbControlDescriptorRequest.DescriptorType;
    2.40 -    switch(urb->UrbControlDescriptorRequest.DescriptorType)
    2.41 -    {
    2.42 -    case USB_STRING_DESCRIPTOR_TYPE:
    2.43 -      decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = urb->UrbControlDescriptorRequest.LanguageId;
    2.44 -      break;
    2.45 -    default:
    2.46 -      decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = 0;
    2.47 -      break;
    2.48 -    }
    2.49 -    decode_data->setup_packet.default_pipe_setup_packet.wLength = (USHORT)urb->UrbControlDescriptorRequest.TransferBufferLength;
    2.50 -    decode_data->transfer_flags = USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK;
    2.51 -    decode_data->buffer = urb->UrbControlTransfer.TransferBuffer;
    2.52 -    decode_data->mdl = urb->UrbControlTransfer.TransferBufferMDL;
    2.53 -    decode_data->length = &urb->UrbControlTransfer.TransferBufferLength;
    2.54 -    retval = URB_DECODE_COMPLETE;
    2.55 -    break;
    2.56 -  case URB_FUNCTION_CLASS_DEVICE: /* CONTROL_TRANSFER has same underlying format as FUNCTION_CLASS_XXX */
    2.57 -  case URB_FUNCTION_CLASS_OTHER:
    2.58 -  case URB_FUNCTION_CLASS_INTERFACE: /* not yet tested */
    2.59 -  //case URB_FUNCTION_GET_STATUS_FROM_DEVICE: // seems to be missing fields...
    2.60 -  case URB_FUNCTION_CONTROL_TRANSFER:
    2.61 -#if (NTDDI_VERSION >= NTDDI_VISTA)  
    2.62 -  case URB_FUNCTION_CONTROL_TRANSFER_EX:
    2.63 -#endif
    2.64 -    decode_data->buffer = urb->UrbControlTransfer.TransferBuffer;
    2.65 -    decode_data->mdl = urb->UrbControlTransfer.TransferBufferMDL;
    2.66 -    decode_data->length = &urb->UrbControlTransfer.TransferBufferLength;
    2.67 -    decode_data->transfer_flags = urb->UrbControlTransfer.TransferFlags;
    2.68 -    memcpy(decode_data->setup_packet.raw, urb->UrbControlTransfer.SetupPacket, sizeof(decode_data->setup_packet.raw));
    2.69 -    retval = URB_DECODE_COMPLETE;
    2.70 -    break;
    2.71 -  case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
    2.72 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
    2.73 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
    2.74 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    2.75 -    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
    2.76 -    decode_data->setup_packet.default_pipe_setup_packet.bRequest = USB_REQUEST_GET_STATUS;
    2.77 -    decode_data->setup_packet.default_pipe_setup_packet.wLength = 0;
    2.78 -    decode_data->setup_packet.default_pipe_setup_packet.wValue.W = 0;
    2.79 -    decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = urb->UrbControlGetStatusRequest.Index;
    2.80 -    decode_data->buffer = urb->UrbControlTransfer.TransferBuffer;
    2.81 -    decode_data->mdl = urb->UrbControlTransfer.TransferBufferMDL;
    2.82 -    decode_data->length = &urb->UrbControlTransfer.TransferBufferLength;
    2.83 -    decode_data->transfer_flags = urb->UrbControlTransfer.TransferFlags;
    2.84 -    retval = URB_DECODE_COMPLETE;
    2.85 -    break;
    2.86 -#if 0
    2.87 -  case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
    2.88 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
    2.89 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlGetStatusRequest.TransferBufferLength));
    2.90 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlGetStatusRequest.TransferBuffer));
    2.91 -    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlGetStatusRequest.TransferBufferMDL));
    2.92 -    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlGetStatusRequest.Index));
    2.93 -    if (urb->UrbControlGetStatusRequest.Index == 0)
    2.94 -    {
    2.95 -      urb->UrbControlGetStatusRequest.TransferBufferLength = 2;
    2.96 -      *(PUSHORT)urb->UrbControlGetStatusRequest.TransferBuffer = 0x0003;
    2.97 -      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
    2.98 -      WdfRequestComplete(request, STATUS_SUCCESS);
    2.99 -    }
   2.100 -    else
   2.101 -    {
   2.102 -      KdPrint((__DRIVER_NAME "     Unknown Index\n"));
   2.103 -      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   2.104 -      WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   2.105 -    }    
   2.106 -    break;
   2.107 -  case URB_FUNCTION_CLASS_DEVICE:
   2.108 -#if 1
   2.109 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_DEVICE\n"));
   2.110 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   2.111 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   2.112 -    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   2.113 -    KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   2.114 -    KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   2.115 -    KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   2.116 -    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   2.117 -#endif
   2.118 -    switch (urb->UrbControlVendorClassRequest.Request)
   2.119 -    {
   2.120 -    case USB_REQUEST_GET_DESCRIPTOR:
   2.121 -      KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_DEVICE\n"));
   2.122 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   2.123 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   2.124 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   2.125 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   2.126 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   2.127 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   2.128 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   2.129 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_DESCRIPTOR\n"));
   2.130 -      switch (urb->UrbControlVendorClassRequest.Value >> 8)
   2.131 -      {
   2.132 -      case 0x00:
   2.133 -#if 0      
   2.134 -        memcpy(urb->UrbControlVendorClassRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
   2.135 -        urb->UrbControlVendorClassRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
   2.136 -        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.137 -        WdfRequestComplete(request, STATUS_SUCCESS);
   2.138 -        break;
   2.139 -#endif
   2.140 -      case 0x29: // Hub Descriptor
   2.141 -        KdPrint((__DRIVER_NAME "       HUB_DESCRIPTOR\n"));
   2.142 -        uhd = urb->UrbControlVendorClassRequest.TransferBuffer;
   2.143 -        urb->UrbControlVendorClassRequest.TransferBufferLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
   2.144 -        uhd->bDescriptorLength = (UCHAR)urb->UrbControlVendorClassRequest.TransferBufferLength;
   2.145 -        uhd->bDescriptorType = 0x29;
   2.146 -        uhd->bNumberOfPorts = 8;
   2.147 -        uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
   2.148 -        uhd->bPowerOnToPowerGood = 1; // 2ms units
   2.149 -        uhd->bHubControlCurrent = 0;
   2.150 -        // DeviceRemovable bits (includes an extra bit at the start)
   2.151 -        uhd->bRemoveAndPowerMask[0] = 0;
   2.152 -        uhd->bRemoveAndPowerMask[1] = 0;
   2.153 -        // PortPwrCtrlMask
   2.154 -        uhd->bRemoveAndPowerMask[2] = 0xFF;
   2.155 -        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.156 -        WdfRequestComplete(request, STATUS_SUCCESS);
   2.157 -        break;
   2.158 -      default:
   2.159 -        KdPrint((__DRIVER_NAME "       Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
   2.160 -        urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   2.161 -        WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   2.162 -        break;
   2.163 -      }
   2.164 -      break;
   2.165 -    case USB_REQUEST_GET_STATUS:
   2.166 -      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   2.167 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   2.168 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   2.169 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   2.170 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   2.171 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   2.172 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   2.173 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   2.174 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_STATUS\n"));
   2.175 -      // Check that RequestTypeReservedBits == 0xA0
   2.176 -      KdPrint((__DRIVER_NAME "       GetHubStatus\n"));
   2.177 -      /* hub status */
   2.178 -      // shoud be able to get this field from somewhere else...
   2.179 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = 0x0000;
   2.180 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = 0x0000; /* no change occurred */
   2.181 -      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.182 -      WdfRequestComplete(request, STATUS_SUCCESS);
   2.183 -      break;
   2.184 -    case USB_REQUEST_CLEAR_FEATURE:
   2.185 -      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   2.186 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   2.187 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   2.188 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   2.189 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   2.190 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   2.191 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   2.192 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   2.193 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_CLEAR_FEATURE\n"));
   2.194 -      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.195 -      WdfRequestComplete(request, STATUS_SUCCESS);
   2.196 -      break;
   2.197 -    default:
   2.198 -      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   2.199 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   2.200 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   2.201 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   2.202 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   2.203 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   2.204 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   2.205 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   2.206 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   2.207 -      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   2.208 -      WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   2.209 -      break;
   2.210 -    }
   2.211 -    break;
   2.212 -  case URB_FUNCTION_CLASS_OTHER:
   2.213 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_OTHER\n"));
   2.214 -    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   2.215 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   2.216 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   2.217 -    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   2.218 -    KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   2.219 -    KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   2.220 -    KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   2.221 -    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   2.222 -    switch (urb->UrbControlVendorClassRequest.Request)
   2.223 -    {
   2.224 -    case USB_REQUEST_GET_STATUS:
   2.225 -      /* port status - 11.24.2.7.1 */
   2.226 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_STATUS\n"));
   2.227 -      KdPrint((__DRIVER_NAME "       GetHubStatus\n"));
   2.228 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status;
   2.229 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change;
   2.230 -      break;
   2.231 -    case USB_REQUEST_SET_FEATURE:
   2.232 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_SET_FEATURE\n"));
   2.233 -      KdPrint((__DRIVER_NAME "       SetPortFeature\n"));
   2.234 -      switch (urb->UrbControlVendorClassRequest.Value)
   2.235 -      {
   2.236 -      case PORT_ENABLE:
   2.237 -        KdPrint((__DRIVER_NAME "        PORT_ENABLE\n"));
   2.238 -        /* do something here */
   2.239 -        break;
   2.240 -      case PORT_RESET:
   2.241 -        KdPrint((__DRIVER_NAME "        PORT_RESET\n"));
   2.242 -        /* just fake the reset */
   2.243 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change |= (1 << C_PORT_RESET);
   2.244 -        break;
   2.245 -      default:
   2.246 -        KdPrint((__DRIVER_NAME "        Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
   2.247 -        break;
   2.248 -      }
   2.249 -      KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   2.250 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   2.251 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   2.252 -      break;
   2.253 -    case USB_REQUEST_CLEAR_FEATURE:
   2.254 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_CLEAR_FEATURE\n"));
   2.255 -      KdPrint((__DRIVER_NAME "       ClearPortFeature\n"));
   2.256 -      switch (urb->UrbControlVendorClassRequest.Value)
   2.257 -      {
   2.258 -      case C_PORT_CONNECTION:
   2.259 -        KdPrint((__DRIVER_NAME "        C_PORT_CONNECTION\n"));
   2.260 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << C_PORT_CONNECTION);
   2.261 -        break;
   2.262 -      case C_PORT_RESET:
   2.263 -        KdPrint((__DRIVER_NAME "        C_PORT_RESET\n"));
   2.264 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << C_PORT_RESET);
   2.265 -        break;
   2.266 -      default:
   2.267 -        KdPrint((__DRIVER_NAME "        Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
   2.268 -        break;
   2.269 -      }
   2.270 -      KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   2.271 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   2.272 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   2.273 -      break;
   2.274 -    default:
   2.275 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   2.276 -      break;
   2.277 -    }
   2.278 -    //urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.279 -    //WdfRequestComplete(request, STATUS_SUCCESS);
   2.280 -    urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   2.281 -    WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   2.282 -    break;
   2.283 -  case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
   2.284 -#if 1
   2.285 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
   2.286 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
   2.287 -    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
   2.288 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
   2.289 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
   2.290 -    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
   2.291 -#endif
   2.292 -    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   2.293 -    WdfSpinLockAcquire (endpoint->interrupt_lock);
   2.294 -    if (WdfIoQueueGetState(endpoint->interrupt_queue, NULL, NULL) & WdfIoQueueNoRequests)
   2.295 -    {
   2.296 -      status = WdfTimerStart(endpoint->interrupt_timer, WDF_REL_TIMEOUT_IN_MS(100));
   2.297 -    }
   2.298 -    status = WdfRequestForwardToIoQueue(request, endpoint->interrupt_queue);
   2.299 -    WdfSpinLockRelease(endpoint->interrupt_lock);
   2.300 -    break;
   2.301 -  case URB_FUNCTION_CONTROL_TRANSFER_EX:
   2.302 -    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)urb->UrbControlTransfer.SetupPacket;
   2.303 -#if 1
   2.304 -    FUNCTION_MSG("URB_FUNCTION_CONTROL_TRANSFER_EX\n");
   2.305 -    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbControlTransfer.PipeHandle);
   2.306 -    FUNCTION_MSG(" TransferFlags = %08x\n", urb->UrbControlTransfer.TransferFlags);
   2.307 -    FUNCTION_MSG(" TransferBufferLength = %d\n", urb->UrbControlTransfer.TransferBufferLength);
   2.308 -    FUNCTION_MSG(" TransferBuffer = %p\n", urb->UrbControlTransfer.TransferBuffer);
   2.309 -    FUNCTION_MSG(" TransferBufferMdl = %p\n", urb->UrbControlTransfer.TransferBufferMDL);
   2.310 -    FUNCTION_MSG(" Timeout = %p\n", urb->UrbControlTransfer.TransferBufferMDL);
   2.311 -    FUNCTION_MSG(" SetupPacket.bmRequestType = %02x\n", (ULONG)setup_packet->bmRequestType.B);
   2.312 -    FUNCTION_MSG(" SetupPacket.bRequest = %02x\n", (ULONG)setup_packet->bRequest);
   2.313 -    FUNCTION_MSG(" SetupPacket.wValue.LowByte = %02x\n", (ULONG)setup_packet->wValue.LowByte);
   2.314 -    FUNCTION_MSG(" SetupPacket.wValue.HiByte = %02x\n", (ULONG)setup_packet->wValue.HiByte);
   2.315 -    FUNCTION_MSG(" SetupPacket.wIndex.LowByte = %02x\n", (ULONG)setup_packet->wIndex.LowByte);
   2.316 -    FUNCTION_MSG(" SetupPacket.wIndex.HiByte = %02x\n", (ULONG)setup_packet->wIndex.HiByte);
   2.317 -    FUNCTION_MSG(" SetupPacket.wLength = %04x\n", (ULONG)setup_packet->wLength);
   2.318 -#endif
   2.319 -    switch(setup_packet->bRequest)
   2.320 -    {
   2.321 -    case USB_REQUEST_GET_STATUS:
   2.322 -      FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
   2.323 -      *(PUSHORT)urb->UrbControlDescriptorRequest.TransferBuffer = 0x0003;
   2.324 -      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.325 -      break;
   2.326 -    case USB_REQUEST_GET_DESCRIPTOR:
   2.327 -      // should be able to reuse this code...
   2.328 -      FUNCTION_MSG(" USB_REQUEST_GET_DESCRIPTOR\n");
   2.329 -      switch (setup_packet->wValue.HiByte)
   2.330 -      {
   2.331 -      case USB_DEVICE_DESCRIPTOR_TYPE:
   2.332 -        KdPrint((__DRIVER_NAME "      USB_DEVICE_DESCRIPTOR_TYPE\n"));
   2.333 -        memcpy(urb->UrbControlDescriptorRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
   2.334 -        urb->UrbControlDescriptorRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
   2.335 -        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.336 -        break;
   2.337 -      case USB_CONFIGURATION_DESCRIPTOR_TYPE:
   2.338 -      {
   2.339 -        xenusb_config_t *usb_config;
   2.340 -        PUCHAR ptr;
   2.341 -
   2.342 -        KdPrint((__DRIVER_NAME "      USB_CONFIGURATION_DESCRIPTOR_TYPE\n"));
   2.343 -        usb_config = usb_device->active_config;
   2.344 -        ptr = (PUCHAR)urb->UrbControlDescriptorRequest.TransferBuffer;
   2.345 -        memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
   2.346 -        ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
   2.347 -        ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
   2.348 -        if (urb->UrbControlDescriptorRequest.TransferBufferLength > 9)
   2.349 -        {
   2.350 -          for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
   2.351 -          {
   2.352 -            memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
   2.353 -            KdPrint((__DRIVER_NAME "      bInterfaceClass = %02x\n", ((PUSB_INTERFACE_DESCRIPTOR)ptr)->bInterfaceClass));
   2.354 -            ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
   2.355 -            ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
   2.356 -            for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
   2.357 -            {
   2.358 -              memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
   2.359 -              ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
   2.360 -              ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
   2.361 -            }
   2.362 -          }
   2.363 -        }
   2.364 -        urb->UrbControlDescriptorRequest.TransferBufferLength = ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength;
   2.365 -        if (urb->UrbControlDescriptorRequest.TransferBufferLength == 9)
   2.366 -          ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = 32;
   2.367 -        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   2.368 -        KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
   2.369 -        break;
   2.370 -      } 
   2.371 -      default:
   2.372 -        FUNCTION_MSG(" USB_%02x_DESCRIPTOR_TYPE\n", (ULONG)setup_packet->wValue.HiByte);
   2.373 -        break;
   2.374 -      }
   2.375 -      break;
   2.376 -    default:
   2.377 -      FUNCTION_MSG(" USB_REQUEST_%02x\n", (ULONG)setup_packet->bRequest);
   2.378 -      break;
   2.379 -    }
   2.380 -    KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
   2.381 -    WdfRequestComplete(request, STATUS_SUCCESS);
   2.382 -    break;
   2.383 -#endif
   2.384 -#endif
   2.385    case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
   2.386    case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
   2.387    case URB_FUNCTION_ABORT_PIPE:
     3.1 --- a/xenusb/xenusb_devurb.c	Sat Jan 14 23:19:33 2012 +1100
     3.2 +++ b/xenusb/xenusb_devurb.c	Sat Jan 14 23:22:29 2012 +1100
     3.3 @@ -21,123 +21,18 @@ Foundation, Inc., 51 Franklin Street, Fi
     3.4  
     3.5  #define EPROTO          71      /* Protocol error */
     3.6  
     3.7 -static VOID
     3.8 -XenUsb_UrbCallback(usbif_shadow_t *shadow)
     3.9 -{
    3.10 -  WDFQUEUE queue;
    3.11 -  WDFDEVICE device;
    3.12 -  PXENUSB_DEVICE_DATA xudd;
    3.13 -  //ULONG i;
    3.14 -
    3.15 -  FUNCTION_ENTER();
    3.16 -
    3.17 -  ASSERT(shadow->request);
    3.18 -  queue = WdfRequestGetIoQueue(shadow->request);
    3.19 -  ASSERT(queue);
    3.20 -  device = WdfIoQueueGetDevice(queue);
    3.21 -  ASSERT(device);
    3.22 -  xudd = GetXudd(device);
    3.23 -
    3.24 -  switch (shadow->urb->UrbHeader.Function)
    3.25 -  {
    3.26 -  case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
    3.27 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    3.28 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    3.29 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    3.30 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    3.31 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    3.32 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    3.33 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n"));
    3.34 -    shadow->urb->UrbControlDescriptorRequest.TransferBufferLength = shadow->total_length;
    3.35 -    break;
    3.36 -  case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
    3.37 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    3.38 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    3.39 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    3.40 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    3.41 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    3.42 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    3.43 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n"));
    3.44 -    shadow->urb->UrbControlDescriptorRequest.TransferBufferLength = shadow->total_length;
    3.45 -    break;
    3.46 -  case URB_FUNCTION_SELECT_CONFIGURATION:
    3.47 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    3.48 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    3.49 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    3.50 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    3.51 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    3.52 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    3.53 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_CONFIGURATION\n"));
    3.54 -    break;
    3.55 -  case URB_FUNCTION_SELECT_INTERFACE:
    3.56 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    3.57 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    3.58 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    3.59 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    3.60 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    3.61 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    3.62 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_INTERFACE\n"));
    3.63 -    break;
    3.64 -  case URB_FUNCTION_CLASS_INTERFACE:
    3.65 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    3.66 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    3.67 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    3.68 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    3.69 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    3.70 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    3.71 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_INTERFACE\n"));
    3.72 -    shadow->urb->UrbControlVendorClassRequest.TransferBufferLength = shadow->total_length;
    3.73 -    break;
    3.74 -  case URB_FUNCTION_CONTROL_TRANSFER:
    3.75 -  case URB_FUNCTION_CONTROL_TRANSFER_EX:
    3.76 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    3.77 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    3.78 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    3.79 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    3.80 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    3.81 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    3.82 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CONTROL_TRANSFER (_EX)\n"));
    3.83 -    shadow->urb->UrbControlTransfer.TransferBufferLength = shadow->total_length;
    3.84 -    break;
    3.85 -  case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
    3.86 -//    if (shadow->rsp.status)
    3.87 -    {
    3.88 -      KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    3.89 -      KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    3.90 -      KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    3.91 -      KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    3.92 -      KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    3.93 -      KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    3.94 -      KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
    3.95 -    }
    3.96 -    shadow->urb->UrbBulkOrInterruptTransfer.TransferBufferLength = shadow->total_length;
    3.97 -    break;
    3.98 -  case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
    3.99 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
   3.100 -    break;
   3.101 -  default:
   3.102 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
   3.103 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
   3.104 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
   3.105 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
   3.106 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
   3.107 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
   3.108 -    KdPrint((__DRIVER_NAME "     Unknown function %x\n", shadow->urb->UrbHeader.Function));
   3.109 -    break;
   3.110 -  }
   3.111 -  switch (shadow->rsp.status)
   3.112 +static USBD_STATUS
   3.113 +XenUsb_GetUsbdStatusFromPvStatus(ULONG pvstatus) {
   3.114 +  switch (pvstatus)
   3.115    {
   3.116    case 0:
   3.117 -    shadow->urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.118 -    break;
   3.119 +    return USBD_STATUS_SUCCESS;
   3.120    case -EPROTO: /*  ? */
   3.121 -    shadow->urb->UrbHeader.Status = USBD_STATUS_CRC;
   3.122 -    KdPrint((__DRIVER_NAME "     rsp status = -EPROTO\n"));
   3.123 -    break;
   3.124 +    FUNCTION_MSG("pvstatus = -EPROTO\n");
   3.125 +    return USBD_STATUS_CRC;
   3.126    case -EPIPE: /* see linux code - EPIPE is when the HCD returned a stall */
   3.127 -    shadow->urb->UrbHeader.Status = USBD_STATUS_STALL_PID;
   3.128 -    KdPrint((__DRIVER_NAME "     rsp status = -EPIPE (USBD_STATUS_STALL_PID)\n"));
   3.129 -    break;
   3.130 +    FUNCTION_MSG("pvstatus = -EPIPE (USBD_STATUS_STALL_PID)\n");
   3.131 +    return USBD_STATUS_STALL_PID;
   3.132  #if 0
   3.133    case -EOVERFLOW:
   3.134      shadow->urb->UrbHeader.Status USBD_STATUS_DATA_OVERRUN;
   3.135 @@ -146,18 +41,47 @@ XenUsb_UrbCallback(usbif_shadow_t *shado
   3.136      shadow->urb->UrbHeader.Status USBD_STATUS_ERROR_SHORT_TRANSFER;
   3.137      break;
   3.138  #endif
   3.139 +  case -ESHUTDOWN:
   3.140 +    FUNCTION_MSG("pvstatus = -USBD_STATUS_INTERNAL_HC_ERROR\n");
   3.141 +    return USBD_STATUS_INTERNAL_HC_ERROR;
   3.142    default:
   3.143 -    //shadow->urb->UrbHeader.Status = USBD_STATUS_ENDPOINT_HALTED;
   3.144 -    shadow->urb->UrbHeader.Status = USBD_STATUS_INTERNAL_HC_ERROR;
   3.145 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
   3.146 -    break;
   3.147 +    FUNCTION_MSG("pvstatus = %d\n", pvstatus);
   3.148 +    return USBD_STATUS_INTERNAL_HC_ERROR;
   3.149    }
   3.150 -  if (shadow->urb->UrbHeader.Status == USBD_STATUS_SUCCESS)
   3.151 -    WdfRequestComplete(shadow->request, STATUS_SUCCESS);
   3.152 +}
   3.153 +
   3.154 +VOID
   3.155 +XenUsb_CompletionBulkInterrupt(
   3.156 +  WDFREQUEST request,
   3.157 +  WDFIOTARGET target,
   3.158 +  PWDF_REQUEST_COMPLETION_PARAMS params,
   3.159 +  WDFCONTEXT context)
   3.160 +{
   3.161 +  PURB urb;
   3.162 +  pvurb_t *pvurb = context;
   3.163 +  WDF_REQUEST_PARAMETERS wrp;
   3.164 +
   3.165 +  UNREFERENCED_PARAMETER(target);
   3.166 +
   3.167 +  FUNCTION_ENTER();
   3.168 +
   3.169 +  WDF_REQUEST_PARAMETERS_INIT(&wrp);
   3.170 +  WdfRequestGetParameters(request, &wrp);
   3.171 +  urb = (PURB)wrp.Parameters.Others.Arg1;
   3.172 +  ASSERT(urb);
   3.173 +  KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
   3.174 +  KdPrint((__DRIVER_NAME "     rsp id = %d\n", pvurb->rsp.id));
   3.175 +  KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb->rsp.start_frame));
   3.176 +  KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb->rsp.status));
   3.177 +  KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb->rsp.actual_length));
   3.178 +  KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", pvurb->rsp.error_count));
   3.179 +  KdPrint((__DRIVER_NAME "     total_length = %d\n", pvurb->total_length));
   3.180 +  urb->UrbHeader.Status = XenUsb_GetUsbdStatusFromPvStatus(pvurb->rsp.status);
   3.181 +  urb->UrbBulkOrInterruptTransfer.TransferBufferLength = (ULONG)params->IoStatus.Information;
   3.182 +  if (urb->UrbHeader.Status == USBD_STATUS_SUCCESS)
   3.183 +    WdfRequestComplete(request, STATUS_SUCCESS);
   3.184    else
   3.185 -    WdfRequestComplete(shadow->request, STATUS_UNSUCCESSFUL);
   3.186 -  put_shadow_on_freelist(xudd, shadow);
   3.187 -
   3.188 +    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   3.189    FUNCTION_EXIT();
   3.190  }
   3.191  
   3.192 @@ -167,20 +91,22 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.193    WDFREQUEST request,
   3.194    size_t output_buffer_length,
   3.195    size_t input_buffer_length,
   3.196 -  ULONG io_control_code)
   3.197 +  ULONG io_control_code) 
   3.198  {
   3.199    NTSTATUS status;
   3.200    WDFDEVICE device = WdfIoQueueGetDevice(queue);
   3.201 -  PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   3.202 +  PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
   3.203    WDF_REQUEST_PARAMETERS wrp;
   3.204 +  WDF_MEMORY_DESCRIPTOR pvurb_descriptor;
   3.205 +  WDFMEMORY pvurb_memory;
   3.206 +  WDF_REQUEST_SEND_OPTIONS send_options;
   3.207    PURB urb;
   3.208 -  usbif_shadow_t *shadow;
   3.209 +  pvurb_t *pvurb;
   3.210 +  pvurb_t local_pvurb; /* just use stack allocated space when submitting synchronously */
   3.211    PUSB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
   3.212 -  //PMDL mdl;
   3.213    PUSBD_INTERFACE_INFORMATION interface_information;
   3.214    ULONG i, j;
   3.215    xenusb_device_t *usb_device;
   3.216 -  //PUSB_HUB_DESCRIPTOR uhd;
   3.217    xenusb_endpoint_t *endpoint;
   3.218    urb_decode_t decode_data;
   3.219    ULONG decode_retval;
   3.220 @@ -193,7 +119,7 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.221  
   3.222    ASSERT(io_control_code == IOCTL_INTERNAL_USB_SUBMIT_URB);
   3.223  
   3.224 -  status = STATUS_ACCESS_VIOLATION; //STATUS_UNSUCCESSFUL;
   3.225 +  status = STATUS_UNSUCCESSFUL;
   3.226  
   3.227    WDF_REQUEST_PARAMETERS_INIT(&wrp);
   3.228    WdfRequestGetParameters(request, &wrp);
   3.229 @@ -335,16 +261,12 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.230      {
   3.231        // ? unconfigure device here
   3.232      }
   3.233 -    shadow = get_shadow_from_freelist(xudd);
   3.234 -    shadow->request = request;
   3.235 -    shadow->urb = urb;
   3.236 -    shadow->mdl = NULL;
   3.237 -    //shadow->dma_transaction = NULL;
   3.238 -    shadow->callback = XenUsb_UrbCallback;
   3.239 -    shadow->req.id = shadow->id;
   3.240 -    shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.241 -    shadow->req.transfer_flags = 0;
   3.242 -    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
   3.243 +    pvurb = &local_pvurb; //ExAllocatePoolWithTag(NonPagedPool, sizeof(*pvurb), XENUSB_POOL_TAG);
   3.244 +    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&pvurb_descriptor, pvurb, sizeof(*pvurb));
   3.245 +    pvurb->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.246 +    pvurb->req.transfer_flags = 0;
   3.247 +    pvurb->req.buffer_length = 0;
   3.248 +    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)pvurb->req.u.ctrl;
   3.249      setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
   3.250      setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
   3.251      setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
   3.252 @@ -352,10 +274,20 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.253      setup_packet->wLength = 0;
   3.254      setup_packet->wValue.W = urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue;
   3.255      setup_packet->wIndex.W = 0;
   3.256 -    status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
   3.257 -    if (!NT_SUCCESS(status))
   3.258 -    {
   3.259 -      KdPrint((__DRIVER_NAME "     XenUsb_ExecuteRequest status = %08x\n", status));
   3.260 +    pvurb->mdl = NULL;
   3.261 +    WDF_REQUEST_SEND_OPTIONS_INIT(&send_options, WDF_REQUEST_SEND_OPTION_TIMEOUT);
   3.262 +    WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&send_options, WDF_REL_TIMEOUT_IN_SEC(10));
   3.263 +    status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, request, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
   3.264 +    FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
   3.265 +    if (!NT_SUCCESS(status)) {
   3.266 +      WdfRequestComplete(request, status);
   3.267 +    } else {
   3.268 +      FUNCTION_MSG("rsp start_frame = %d\n", pvurb->rsp.start_frame);
   3.269 +      FUNCTION_MSG("rsp status = %d\n", pvurb->rsp.status);
   3.270 +      FUNCTION_MSG("rsp actual_length = %d\n", pvurb->rsp.actual_length);
   3.271 +      FUNCTION_MSG("rsp error_count = %d\n", pvurb->rsp.error_count);
   3.272 +      urb->UrbHeader.Status = XenUsb_GetUsbdStatusFromPvStatus(pvurb->rsp.status);
   3.273 +      WdfRequestComplete(request, pvurb->rsp.status?STATUS_UNSUCCESSFUL:STATUS_SUCCESS);
   3.274      }
   3.275      break;
   3.276    case URB_FUNCTION_SELECT_INTERFACE:
   3.277 @@ -383,16 +315,12 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.278        KdPrint((__DRIVER_NAME "       PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
   3.279      }
   3.280  
   3.281 -    shadow = get_shadow_from_freelist(xudd);
   3.282 -    shadow->request = request;
   3.283 -    shadow->urb = urb;
   3.284 -    shadow->mdl = NULL;
   3.285 -    //shadow->dma_transaction = NULL;
   3.286 -    shadow->callback = XenUsb_UrbCallback;
   3.287 -    shadow->req.id = shadow->id;
   3.288 -    shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.289 -    shadow->req.transfer_flags = 0;
   3.290 -    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
   3.291 +    pvurb = &local_pvurb; //ExAllocatePoolWithTag(NonPagedPool, sizeof(*pvurb), XENUSB_POOL_TAG);
   3.292 +    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&pvurb_descriptor, pvurb, sizeof(*pvurb));
   3.293 +    pvurb->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.294 +    pvurb->req.transfer_flags = 0;
   3.295 +    pvurb->req.buffer_length = 0;
   3.296 +    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)pvurb->req.u.ctrl;
   3.297      setup_packet->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
   3.298      setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
   3.299      setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
   3.300 @@ -400,10 +328,20 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.301      setup_packet->wLength = 0;
   3.302      setup_packet->wValue.W = urb->UrbSelectInterface.Interface.AlternateSetting;
   3.303      setup_packet->wIndex.W = urb->UrbSelectInterface.Interface.InterfaceNumber;
   3.304 -    status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
   3.305 -    if (!NT_SUCCESS(status))
   3.306 -    {
   3.307 -      KdPrint((__DRIVER_NAME "     XenUsb_ExecuteRequest status = %08x\n", status));
   3.308 +    pvurb->mdl = NULL;
   3.309 +    WDF_REQUEST_SEND_OPTIONS_INIT(&send_options, WDF_REQUEST_SEND_OPTION_TIMEOUT);
   3.310 +    WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&send_options, WDF_REL_TIMEOUT_IN_SEC(10));
   3.311 +    status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, request, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
   3.312 +    FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
   3.313 +    if (!NT_SUCCESS(status)) {
   3.314 +      WdfRequestComplete(request, status);
   3.315 +    } else {
   3.316 +      FUNCTION_MSG("rsp start_frame = %d\n", pvurb->rsp.start_frame);
   3.317 +      FUNCTION_MSG("rsp status = %d\n", pvurb->rsp.status);
   3.318 +      FUNCTION_MSG("rsp actual_length = %d\n", pvurb->rsp.actual_length);
   3.319 +      FUNCTION_MSG("rsp error_count = %d\n", pvurb->rsp.error_count);
   3.320 +      urb->UrbHeader.Status = XenUsb_GetUsbdStatusFromPvStatus(pvurb->rsp.status);
   3.321 +      WdfRequestComplete(request, pvurb->rsp.status?STATUS_UNSUCCESSFUL:STATUS_SUCCESS);
   3.322      }
   3.323      break;
   3.324  #if (NTDDI_VERSION >= NTDDI_VISTA)  
   3.325 @@ -431,42 +369,65 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.326      FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
   3.327      FUNCTION_MSG("decode_data.transfer_flags = %08x\n", decode_data.transfer_flags);
   3.328      FUNCTION_MSG("*decode_data.length = %04x\n", *decode_data.length);
   3.329 -    shadow = get_shadow_from_freelist(xudd);
   3.330 -    shadow->request = request;
   3.331 -    shadow->urb = urb;
   3.332 -    shadow->callback = XenUsb_UrbCallback;
   3.333 -    shadow->req.id = shadow->id;
   3.334 -    shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.335 -    shadow->req.transfer_flags = 0; 
   3.336 +    pvurb = &local_pvurb;
   3.337 +    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&pvurb_descriptor, pvurb, sizeof(*pvurb));
   3.338 +    pvurb->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.339 +    pvurb->req.transfer_flags = 0; 
   3.340      if (!(decode_data.transfer_flags & USBD_SHORT_TRANSFER_OK))
   3.341 -      shadow->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
   3.342 +      pvurb->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
   3.343      if (decode_data.transfer_flags & (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK))
   3.344 -      shadow->req.pipe |= LINUX_PIPE_DIRECTION_IN;
   3.345 +      pvurb->req.pipe |= LINUX_PIPE_DIRECTION_IN;
   3.346      else
   3.347 -      shadow->req.pipe |= LINUX_PIPE_DIRECTION_OUT;
   3.348 -    memcpy(shadow->req.u.ctrl, decode_data.setup_packet.raw, 8);
   3.349 -    FUNCTION_MSG("req.pipe = %08x\n", shadow->req.pipe);
   3.350 -    FUNCTION_MSG("req.transfer_flags = %08x\n", shadow->req.transfer_flags);
   3.351 -    status = XenUsb_ExecuteRequest(xudd, shadow, decode_data.buffer, decode_data.mdl, *decode_data.length);
   3.352 +      pvurb->req.pipe |= LINUX_PIPE_DIRECTION_OUT;
   3.353 +    memcpy(pvurb->req.u.ctrl, decode_data.setup_packet.raw, 8);
   3.354 +    FUNCTION_MSG("req.pipe = %08x\n", pvurb->req.pipe);
   3.355 +    FUNCTION_MSG("req.transfer_flags = %08x\n", pvurb->req.transfer_flags);
   3.356 +    if (decode_data.buffer) {
   3.357 +      FUNCTION_MSG("decode_data.buffer = %p\n", decode_data.buffer);
   3.358 +      pvurb->mdl = IoAllocateMdl(decode_data.buffer, *decode_data.length, FALSE, FALSE, NULL);
   3.359 +      FUNCTION_MSG("pvurb->mdl = %p\n", pvurb->mdl);
   3.360 +      MmBuildMdlForNonPagedPool(pvurb->mdl);
   3.361 +    } else {
   3.362 +      FUNCTION_MSG("decode_data.mdl = %p\n", decode_data.mdl);
   3.363 +      pvurb->mdl = decode_data.mdl;
   3.364 +    }
   3.365 +    WDF_REQUEST_SEND_OPTIONS_INIT(&send_options, WDF_REQUEST_SEND_OPTION_TIMEOUT);
   3.366 +    WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&send_options, WDF_REL_TIMEOUT_IN_SEC(10));
   3.367 +    status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, request, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
   3.368 +    if (decode_data.buffer)
   3.369 +      IoFreeMdl(pvurb->mdl);
   3.370 +    FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
   3.371      if (!NT_SUCCESS(status)) {
   3.372 -      KdPrint((__DRIVER_NAME "     XenUsb_ExecuteRequest status = %08x\n", status));
   3.373 +      WdfRequestComplete(request, status);
   3.374 +    } else {
   3.375 +      FUNCTION_MSG("rsp start_frame = %d\n", pvurb->rsp.start_frame);
   3.376 +      FUNCTION_MSG("rsp status = %d\n", pvurb->rsp.status);
   3.377 +      FUNCTION_MSG("rsp actual_length = %d\n", pvurb->rsp.actual_length);
   3.378 +      FUNCTION_MSG("rsp error_count = %d\n", pvurb->rsp.error_count);
   3.379 +      urb->UrbHeader.Status = XenUsb_GetUsbdStatusFromPvStatus(pvurb->rsp.status);
   3.380 +      WdfRequestComplete(request, pvurb->rsp.status?STATUS_UNSUCCESSFUL:STATUS_SUCCESS);
   3.381      }
   3.382      break;
   3.383    case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
   3.384 -    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;    
   3.385 -    KdPrint((__DRIVER_NAME "      pipe_handle = %p\n", endpoint));
   3.386 -    KdPrint((__DRIVER_NAME "      pipe_value = %08x\n", endpoint->pipe_value));
   3.387 -    shadow = get_shadow_from_freelist(xudd);
   3.388 -    KdPrint((__DRIVER_NAME "      id = %d\n", shadow->id));
   3.389 -    shadow->request = request;
   3.390 -    shadow->urb = urb;
   3.391 -    shadow->callback = XenUsb_UrbCallback;
   3.392 -    shadow->req.id = shadow->id;
   3.393 -    shadow->req.pipe = endpoint->pipe_value;
   3.394 -    shadow->req.transfer_flags = 0;
   3.395 -    shadow->req.u.intr.interval = endpoint->endpoint_descriptor.bInterval; /* check this... maybe there is some overridden value that should be used? */
   3.396 +    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   3.397 +    FUNCTION_MSG("endpoint address = %02x\n", endpoint->endpoint_descriptor.bEndpointAddress);
   3.398 +    FUNCTION_MSG("endpoint interval = %02x\n", endpoint->endpoint_descriptor.bInterval);
   3.399 +    FUNCTION_MSG("pipe_direction_bit = %08x\n", endpoint->pipe_value & LINUX_PIPE_DIRECTION_IN);
   3.400 +    FUNCTION_MSG("short_ok_bit = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK);
   3.401 +    FUNCTION_MSG("flags_direction_bit = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_TRANSFER_DIRECTION_IN);
   3.402 +    FUNCTION_MSG("pipe_handle = %p\n", endpoint);
   3.403 +    FUNCTION_MSG("pipe_value = %08x\n", endpoint->pipe_value);
   3.404 +    
   3.405 +    pvurb = ExAllocatePoolWithTag(NonPagedPool, sizeof(*pvurb), XENUSB_POOL_TAG);
   3.406 +    status = WdfMemoryCreatePreallocated(WDF_NO_OBJECT_ATTRIBUTES, pvurb, sizeof(*pvurb), &pvurb_memory);
   3.407 +    ASSERT(NT_SUCCESS(status));
   3.408 +    pvurb->req.pipe = endpoint->pipe_value;
   3.409 +    pvurb->req.transfer_flags = 0; 
   3.410      if (!(urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK) && (endpoint->pipe_value & LINUX_PIPE_DIRECTION_IN))
   3.411 -      shadow->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
   3.412 +      pvurb->req.transfer_flags |= LINUX_URB_SHORT_NOT_OK;
   3.413 +    pvurb->req.u.intr.interval = endpoint->endpoint_descriptor.bInterval; /* check this... maybe there is some overridden value that should be used? */
   3.414 +    FUNCTION_MSG("req.pipe = %08x\n", pvurb->req.pipe);
   3.415 +    FUNCTION_MSG("req.transfer_flags = %08x\n", pvurb->req.transfer_flags);
   3.416      switch(endpoint->endpoint_descriptor.bmAttributes & USB_ENDPOINT_TYPE_MASK)
   3.417      {
   3.418      case USB_ENDPOINT_TYPE_BULK:
   3.419 @@ -479,32 +440,39 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.420        KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_%d\n", endpoint->endpoint_descriptor.bmAttributes));
   3.421        break;
   3.422      }
   3.423 -
   3.424 -    FUNCTION_MSG("endpoint address = %02x\n", endpoint->endpoint_descriptor.bEndpointAddress);
   3.425 -    FUNCTION_MSG("endpoint interval = %02x\n", endpoint->endpoint_descriptor.bInterval);
   3.426 -    FUNCTION_MSG("pipe_direction_bit = %08x\n", endpoint->pipe_value & LINUX_PIPE_DIRECTION_IN);
   3.427 -    FUNCTION_MSG("short_ok_bit = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_SHORT_TRANSFER_OK);
   3.428 -    FUNCTION_MSG("flags_direction_bit = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_TRANSFER_DIRECTION_IN);
   3.429 -    status = XenUsb_ExecuteRequest(xudd, shadow, urb->UrbBulkOrInterruptTransfer.TransferBuffer, urb->UrbBulkOrInterruptTransfer.TransferBufferMDL, urb->UrbBulkOrInterruptTransfer.TransferBufferLength);
   3.430 -    if (!NT_SUCCESS(status))
   3.431 -    {
   3.432 -      KdPrint((__DRIVER_NAME "     XenUsb_ExecuteRequest status = %08x\n", status));
   3.433 +    if (urb->UrbBulkOrInterruptTransfer.TransferBuffer) {
   3.434 +      pvurb->mdl = IoAllocateMdl(urb->UrbBulkOrInterruptTransfer.TransferBuffer, urb->UrbBulkOrInterruptTransfer.TransferBufferLength, FALSE, FALSE, NULL);
   3.435 +      MmBuildMdlForNonPagedPool(pvurb->mdl);
   3.436 +    } else {
   3.437 +      pvurb->mdl = urb->UrbBulkOrInterruptTransfer.TransferBufferMDL;
   3.438 +    }
   3.439 +    status = WdfIoTargetFormatRequestForInternalIoctlOthers(xupdd->bus_fdo_target, request, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, pvurb_memory, NULL, NULL, NULL, NULL, NULL);
   3.440 +    FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
   3.441 +    if (!NT_SUCCESS(status)) {
   3.442 +      if (urb->UrbBulkOrInterruptTransfer.TransferBuffer)
   3.443 +        IoFreeMdl(pvurb->mdl);
   3.444 +      WdfRequestComplete(request, status);
   3.445 +    }
   3.446 +    WdfRequestSetCompletionRoutine(request, XenUsb_CompletionBulkInterrupt, pvurb);
   3.447 +    if (!WdfRequestSend(request, xupdd->bus_fdo_target, NULL)) {
   3.448 +      FUNCTION_MSG("WdfRequestSend returned FALSE\n");
   3.449 +      if (urb->UrbBulkOrInterruptTransfer.TransferBuffer)
   3.450 +        IoFreeMdl(pvurb->mdl);
   3.451 +      WdfRequestComplete(request, WdfRequestGetStatus(request));
   3.452      }
   3.453      break;
   3.454    case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
   3.455      KdPrint((__DRIVER_NAME "     URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
   3.456      KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   3.457      /* we only clear the stall here */
   3.458 -    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;    
   3.459 -    shadow = get_shadow_from_freelist(xudd);
   3.460 -    shadow->request = request;
   3.461 -    shadow->urb = urb;
   3.462 -    shadow->mdl = NULL;
   3.463 -    shadow->callback = XenUsb_UrbCallback;
   3.464 -    shadow->req.id = shadow->id;
   3.465 -    shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.466 -    shadow->req.transfer_flags = 0;
   3.467 -    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
   3.468 +    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   3.469 +
   3.470 +    pvurb = &local_pvurb; //ExAllocatePoolWithTag(NonPagedPool, sizeof(*pvurb), XENUSB_POOL_TAG);
   3.471 +    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&pvurb_descriptor, pvurb, sizeof(*pvurb));
   3.472 +    pvurb->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   3.473 +    pvurb->req.transfer_flags = 0;
   3.474 +    pvurb->req.buffer_length = 0;
   3.475 +    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)pvurb->req.u.ctrl;
   3.476      setup_packet->bmRequestType.Recipient = BMREQUEST_TO_ENDPOINT;
   3.477      setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
   3.478      setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
   3.479 @@ -512,10 +480,20 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.480      setup_packet->wLength = 0;
   3.481      setup_packet->wValue.W = 0; /* 0 == ENDPOINT_HALT */
   3.482      setup_packet->wIndex.W = endpoint->endpoint_descriptor.bEndpointAddress;
   3.483 -    status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
   3.484 -    if (!NT_SUCCESS(status))
   3.485 -    {
   3.486 -      KdPrint((__DRIVER_NAME "     XenUsb_ExecuteRequest status = %08x\n", status));
   3.487 +    pvurb->mdl = NULL;
   3.488 +    WDF_REQUEST_SEND_OPTIONS_INIT(&send_options, WDF_REQUEST_SEND_OPTION_TIMEOUT);
   3.489 +    WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&send_options, WDF_REL_TIMEOUT_IN_SEC(10));
   3.490 +    status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, request, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
   3.491 +    FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
   3.492 +    if (!NT_SUCCESS(status)) {
   3.493 +      WdfRequestComplete(request, status);
   3.494 +    } else {
   3.495 +      FUNCTION_MSG("rsp start_frame = %d\n", pvurb->rsp.start_frame);
   3.496 +      FUNCTION_MSG("rsp status = %d\n", pvurb->rsp.status);
   3.497 +      FUNCTION_MSG("rsp actual_length = %d\n", pvurb->rsp.actual_length);
   3.498 +      FUNCTION_MSG("rsp error_count = %d\n", pvurb->rsp.error_count);
   3.499 +      urb->UrbHeader.Status = XenUsb_GetUsbdStatusFromPvStatus(pvurb->rsp.status);
   3.500 +      WdfRequestComplete(request, pvurb->rsp.status?STATUS_UNSUCCESSFUL:STATUS_SUCCESS);
   3.501      }
   3.502      break;
   3.503    case URB_FUNCTION_ABORT_PIPE:
   3.504 @@ -527,11 +505,9 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
   3.505      break;
   3.506    default:
   3.507      KdPrint((__DRIVER_NAME "     URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
   3.508 -    KdPrint((__DRIVER_NAME "     Calling WdfRequestCompletestatus with status = %08x\n", status));
   3.509      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   3.510 -    WdfRequestComplete(request, STATUS_ACCESS_VIOLATION); //STATUS_UNSUCCESSFUL);
   3.511 +    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   3.512      break;
   3.513    }
   3.514    FUNCTION_EXIT();
   3.515  }
   3.516 -
     4.1 --- a/xenusb/xenusb_fdo.c	Sat Jan 14 23:19:33 2012 +1100
     4.2 +++ b/xenusb/xenusb_fdo.c	Sat Jan 14 23:22:29 2012 +1100
     4.3 @@ -32,108 +32,11 @@ static EVT_WDF_DEVICE_QUERY_REMOVE XenUs
     4.4  static EVT_WDFDEVICE_WDM_IRP_PREPROCESS XenUsb_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE;
     4.5  static EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL XenUsb_EvtIoDeviceControl;
     4.6  static EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl;
     4.7 +static EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl_PVURB;
     4.8  static EVT_WDF_IO_QUEUE_IO_DEFAULT XenUsb_EvtIoDefault;
     4.9  //static EVT_WDF_PROGRAM_DMA XenUsb_ExecuteRequestCallback;
    4.10  
    4.11  NTSTATUS
    4.12 -XenUsb_ExecuteRequest(
    4.13 - PXENUSB_DEVICE_DATA xudd,
    4.14 - usbif_shadow_t *shadow,
    4.15 - PVOID transfer_buffer,
    4.16 - PMDL transfer_buffer_mdl,
    4.17 - ULONG transfer_buffer_length)
    4.18 -{
    4.19 -  NTSTATUS status = STATUS_SUCCESS;
    4.20 -  KIRQL old_irql;
    4.21 -  PMDL mdl;
    4.22 -  int i;
    4.23 -  int notify;
    4.24 -  ULONG remaining;
    4.25 -  USHORT offset;
    4.26 -  
    4.27 -  FUNCTION_ENTER();
    4.28 -  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
    4.29 -  
    4.30 -  KdPrint((__DRIVER_NAME "     transfer_buffer = %p\n", transfer_buffer));
    4.31 -  KdPrint((__DRIVER_NAME "     transfer_buffer_mdl = %p\n", transfer_buffer_mdl));
    4.32 -  KdPrint((__DRIVER_NAME "     transfer_buffer_length = %d\n", transfer_buffer_length));
    4.33 -  shadow->total_length = 0;
    4.34 -  if (!transfer_buffer_length)
    4.35 -  {
    4.36 -    shadow->mdl = NULL;
    4.37 -    shadow->req.nr_buffer_segs = 0;
    4.38 -    shadow->req.buffer_length = 0;
    4.39 -
    4.40 -    KeAcquireSpinLock(&xudd->urb_ring_lock, &old_irql);
    4.41 -    *RING_GET_REQUEST(&xudd->urb_ring, xudd->urb_ring.req_prod_pvt) = shadow->req;
    4.42 -    xudd->urb_ring.req_prod_pvt++;
    4.43 -    RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
    4.44 -    if (notify)
    4.45 -    {
    4.46 -      //KdPrint((__DRIVER_NAME "     Notifying\n"));
    4.47 -      xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
    4.48 -    }
    4.49 -    KeReleaseSpinLock(&xudd->urb_ring_lock, old_irql);
    4.50 -    FUNCTION_EXIT();
    4.51 -    return STATUS_SUCCESS;
    4.52 -  }
    4.53 -  ASSERT(transfer_buffer || transfer_buffer_mdl);
    4.54 -  if (transfer_buffer)
    4.55 -  {
    4.56 -    mdl = IoAllocateMdl(transfer_buffer, transfer_buffer_length, FALSE, FALSE, NULL);
    4.57 -    ASSERT(mdl);
    4.58 -    MmBuildMdlForNonPagedPool(mdl);
    4.59 -    shadow->mdl = mdl;
    4.60 -  }
    4.61 -  else
    4.62 -  {
    4.63 -    mdl = transfer_buffer_mdl;
    4.64 -    shadow->mdl = NULL;
    4.65 -  }
    4.66 -
    4.67 -  ASSERT(mdl);
    4.68 -  ASSERT(transfer_buffer_length);
    4.69 -
    4.70 -  FUNCTION_MSG("MmGetMdlVirtualAddress = %p\n", MmGetMdlVirtualAddress(mdl));
    4.71 -  FUNCTION_MSG("MmGetMdlByteCount = %d\n", MmGetMdlByteCount(mdl));
    4.72 -  FUNCTION_MSG("MmGetMdlByteOffset = %d\n", MmGetMdlByteOffset(mdl));
    4.73 -  
    4.74 -  remaining = MmGetMdlByteCount(mdl);
    4.75 -  offset = (USHORT)MmGetMdlByteOffset(mdl);
    4.76 -  shadow->req.buffer_length = (USHORT)MmGetMdlByteCount(mdl);
    4.77 -  shadow->req.nr_buffer_segs = (USHORT)ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(mdl), MmGetMdlByteCount(mdl));
    4.78 -  for (i = 0; i < shadow->req.nr_buffer_segs; i++)
    4.79 -  {
    4.80 -    shadow->req.seg[i].gref = xudd->vectors.GntTbl_GrantAccess(xudd->vectors.context, 0,
    4.81 -         (ULONG)MmGetMdlPfnArray(mdl)[i], FALSE, INVALID_GRANT_REF, (ULONG)'XUSB');
    4.82 -    shadow->req.seg[i].offset = (USHORT)offset;
    4.83 -    shadow->req.seg[i].length = (USHORT)min(remaining, PAGE_SIZE);
    4.84 -    offset = 0;
    4.85 -    remaining -= shadow->req.seg[i].length;
    4.86 -    KdPrint((__DRIVER_NAME "     seg = %d\n", i));
    4.87 -    KdPrint((__DRIVER_NAME "      gref = %d\n", shadow->req.seg[i].gref));
    4.88 -    KdPrint((__DRIVER_NAME "      offset = %d\n", shadow->req.seg[i].offset));
    4.89 -    KdPrint((__DRIVER_NAME "      length = %d\n", shadow->req.seg[i].length));
    4.90 -  }
    4.91 -  KdPrint((__DRIVER_NAME "     buffer_length = %d\n", shadow->req.buffer_length));
    4.92 -  KdPrint((__DRIVER_NAME "     nr_buffer_segs = %d\n", shadow->req.nr_buffer_segs));
    4.93 -
    4.94 -  KeAcquireSpinLock(&xudd->urb_ring_lock, &old_irql);
    4.95 -  *RING_GET_REQUEST(&xudd->urb_ring, xudd->urb_ring.req_prod_pvt) = shadow->req;
    4.96 -  xudd->urb_ring.req_prod_pvt++;
    4.97 -  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
    4.98 -  if (notify)
    4.99 -  {
   4.100 -    //KdPrint((__DRIVER_NAME "     Notifying\n"));
   4.101 -    xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
   4.102 -  }
   4.103 -  KeReleaseSpinLock(&xudd->urb_ring_lock, old_irql);
   4.104 -  
   4.105 -  FUNCTION_EXIT();
   4.106 -  return status;
   4.107 -}
   4.108 -
   4.109 -NTSTATUS
   4.110  XenUsb_EvtDeviceQueryRemove(WDFDEVICE device)
   4.111  {
   4.112    //PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   4.113 @@ -191,6 +94,7 @@ XenUsb_EvtDeviceWdmIrpPreprocessQUERY_IN
   4.114  static BOOLEAN
   4.115  XenUsb_HandleEvent(PVOID context)
   4.116  {
   4.117 +  NTSTATUS status;
   4.118    PXENUSB_DEVICE_DATA xudd = context;
   4.119    RING_IDX prod, cons;
   4.120    usbif_urb_response_t *urb_rsp;
   4.121 @@ -212,37 +116,49 @@ XenUsb_HandleEvent(PVOID context)
   4.122      for (cons = xudd->urb_ring.rsp_cons; cons != prod; cons++)
   4.123      {
   4.124        urb_rsp = RING_GET_RESPONSE(&xudd->urb_ring, cons);
   4.125 +//      FUNCTION_MSG("urb_rsp->id = %d\n", urb_rsp->id);
   4.126        shadow = &xudd->shadows[urb_rsp->id];
   4.127 -      ASSERT(shadow->callback);
   4.128 -      shadow->rsp = *urb_rsp;
   4.129 -      shadow->next = NULL;
   4.130 -      shadow->total_length += urb_rsp->actual_length;
   4.131 +//      FUNCTION_MSG("shadow = %p\n", shadow);
   4.132 +//      FUNCTION_MSG("shadow->rsp = %p\n", shadow->rsp);
   4.133 +      if (usbif_pipeunlink(shadow->req->pipe)) {
   4.134 +        FUNCTION_MSG("is a cancel request for request %p\n", shadow->request);
   4.135 +        FUNCTION_MSG("urb_ring rsp status = %d\n", urb_rsp->status);
   4.136 +        // status should be 115 == EINPROGRESS
   4.137 +        put_shadow_on_freelist(xudd, shadow);
   4.138 +        /* nothing else to do - clean up when the real request comes off the ring */
   4.139 +      } else {
   4.140 +        *shadow->rsp = *urb_rsp;
   4.141 +  //      FUNCTION_MSG("A\n");
   4.142 +        shadow->next = NULL;
   4.143 +  //      FUNCTION_MSG("B\n");
   4.144 +        shadow->total_length += urb_rsp->actual_length;
   4.145  
   4.146 -      KdPrint((__DRIVER_NAME "     urb_ring rsp id = %d\n", shadow->rsp.id));
   4.147 -      KdPrint((__DRIVER_NAME "     urb_ring rsp start_frame = %d\n", shadow->rsp.start_frame));
   4.148 -      KdPrint((__DRIVER_NAME "     urb_ring rsp status = %d\n", shadow->rsp.status));
   4.149 -      KdPrint((__DRIVER_NAME "     urb_ring rsp actual_length = %d\n", shadow->rsp.actual_length));
   4.150 -      KdPrint((__DRIVER_NAME "     urb_ring rsp error_count = %d\n", shadow->rsp.error_count));
   4.151 -      KdPrint((__DRIVER_NAME "     urb_ring total_length = %d\n", shadow->total_length));
   4.152 -
   4.153 -      if (complete_tail)
   4.154 -      {
   4.155 -        complete_tail->next = shadow;
   4.156 +        KdPrint((__DRIVER_NAME "     urb_ring rsp id = %d\n", shadow->rsp->id));
   4.157 +        KdPrint((__DRIVER_NAME "     urb_ring rsp start_frame = %d\n", shadow->rsp->start_frame));
   4.158 +        KdPrint((__DRIVER_NAME "     urb_ring rsp status = %d\n", shadow->rsp->status));
   4.159 +        KdPrint((__DRIVER_NAME "     urb_ring rsp actual_length = %d\n", shadow->rsp->actual_length));
   4.160 +        KdPrint((__DRIVER_NAME "     urb_ring rsp error_count = %d\n", shadow->rsp->error_count));
   4.161 +        KdPrint((__DRIVER_NAME "     urb_ring total_length = %d\n", shadow->total_length));
   4.162 +        
   4.163 +        status = WdfRequestUnmarkCancelable(shadow->request);
   4.164 +        if (status == STATUS_CANCELLED) {
   4.165 +          FUNCTION_MSG("Cancel was called\n");
   4.166 +        }
   4.167 +        if (complete_tail) {
   4.168 +          complete_tail->next = shadow;
   4.169 +        } else {
   4.170 +          complete_head = shadow;
   4.171 +        }
   4.172 +        complete_tail = shadow;
   4.173        }
   4.174 -      else
   4.175 -      {
   4.176 -        complete_head = shadow;
   4.177 -      }
   4.178 -      complete_tail = shadow;
   4.179 +//      FUNCTION_MSG("C\n");
   4.180      }
   4.181 +//    FUNCTION_MSG("D\n");
   4.182  
   4.183      xudd->urb_ring.rsp_cons = cons;
   4.184 -    if (cons != xudd->urb_ring.req_prod_pvt)
   4.185 -    {
   4.186 +    if (cons != xudd->urb_ring.req_prod_pvt) {
   4.187        RING_FINAL_CHECK_FOR_RESPONSES(&xudd->urb_ring, more_to_do);
   4.188 -    }
   4.189 -    else
   4.190 -    {
   4.191 +    } else {
   4.192        xudd->urb_ring.sring->rsp_event = cons + 1;
   4.193        more_to_do = FALSE;
   4.194      }
   4.195 @@ -299,32 +215,21 @@ XenUsb_HandleEvent(PVOID context)
   4.196    KeReleaseSpinLockFromDpcLevel(&xudd->conn_ring_lock);
   4.197  
   4.198    shadow = complete_head;
   4.199 -  while (shadow != NULL)
   4.200 -  {
   4.201 -    if (shadow->req.buffer_length)
   4.202 -    {
   4.203 +  while (shadow != NULL) {
   4.204 +    complete_head = shadow->next;
   4.205 +    if (shadow->req->buffer_length) {
   4.206        int i;
   4.207 -      for (i = 0; i < shadow->req.nr_buffer_segs; i++)
   4.208 -      {
   4.209 +      for (i = 0; i < shadow->req->nr_buffer_segs; i++) {
   4.210          xudd->vectors.GntTbl_EndAccess(xudd->vectors.context,
   4.211 -          shadow->req.seg[i].gref, FALSE, (ULONG)'XUSB');        
   4.212 +          shadow->req->seg[i].gref, FALSE, (ULONG)'XUSB');
   4.213        }
   4.214 -      // free grant refs
   4.215 -      if (shadow->mdl)
   4.216 -      {
   4.217 -        IoFreeMdl(shadow->mdl);
   4.218 -      }
   4.219 -      shadow->callback(shadow);
   4.220      }
   4.221 -    else
   4.222 -    {
   4.223 -      shadow->callback(shadow);
   4.224 -    }
   4.225 -    shadow = shadow->next;
   4.226 +    WdfRequestCompleteWithInformation(shadow->request, (shadow->rsp->status==ECONNRESET)?STATUS_CANCELLED:STATUS_SUCCESS, shadow->total_length); /* the WDFREQUEST is always successfull here even if the shadow->rsp has an error */
   4.227 +    put_shadow_on_freelist(xudd, shadow);
   4.228 +    shadow = complete_head;
   4.229    }
   4.230  
   4.231 -  if (port_changed)
   4.232 -  {
   4.233 +  if (port_changed) {
   4.234      PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(xudd->root_hub_device);
   4.235      XenUsbHub_ProcessHubInterruptEvent(xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]);
   4.236    }
   4.237 @@ -754,9 +659,6 @@ XenUsb_EvtIoDeviceControl(
   4.238    NTSTATUS status;
   4.239    WDFDEVICE device = WdfIoQueueGetDevice(queue);
   4.240    PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   4.241 -  //WDF_REQUEST_PARAMETERS wrp;
   4.242 -  //PURB urb;
   4.243 -  //xenusb_device_t *usb_device;
   4.244  
   4.245    UNREFERENCED_PARAMETER(queue);
   4.246    UNREFERENCED_PARAMETER(input_buffer_length);
   4.247 @@ -766,58 +668,9 @@ XenUsb_EvtIoDeviceControl(
   4.248  
   4.249    status = STATUS_BAD_INITIAL_PC;
   4.250  
   4.251 -  //WDF_REQUEST_PARAMETERS_INIT(&wrp);
   4.252 -  //WdfRequestGetParameters(request, &wrp);
   4.253 -
   4.254    // these are in api\usbioctl.h
   4.255    switch(io_control_code)
   4.256    {
   4.257 -#if 0
   4.258 -  case IOCTL_USB_GET_NODE_INFORMATION:
   4.259 -  {
   4.260 -    PUSB_NODE_INFORMATION uni;
   4.261 -    size_t length;
   4.262 -    
   4.263 -    KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_INFORMATION\n"));
   4.264 -    KdPrint((__DRIVER_NAME "      output_buffer_length = %d\n", output_buffer_length));
   4.265 -    // make sure size is >= bDescriptorLength
   4.266 -    status = WdfRequestRetrieveOutputBuffer(request, output_buffer_length, (PVOID *)&uni, &length);
   4.267 -    if (NT_SUCCESS(status))
   4.268 -    {
   4.269 -      switch(uni->NodeType)
   4.270 -      {
   4.271 -      case UsbHub:
   4.272 -        KdPrint((__DRIVER_NAME "      NodeType = UsbHub\n"));
   4.273 -        uni->u.HubInformation.HubDescriptor.bDescriptorLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask) + 3;
   4.274 -        if (output_buffer_length >= FIELD_OFFSET(USB_NODE_INFORMATION, u.HubInformation.HubDescriptor.bRemoveAndPowerMask) + 3)
   4.275 -        {
   4.276 -          uni->u.HubInformation.HubDescriptor.bDescriptorType = 0x29;
   4.277 -          uni->u.HubInformation.HubDescriptor.bNumberOfPorts = xudd->num_ports;
   4.278 -          uni->u.HubInformation.HubDescriptor.wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
   4.279 -          uni->u.HubInformation.HubDescriptor.bPowerOnToPowerGood = 1; // 2ms units
   4.280 -          uni->u.HubInformation.HubDescriptor.bHubControlCurrent = 0;
   4.281 -          // DeviceRemovable bits (includes an extra bit at the start)
   4.282 -          uni->u.HubInformation.HubDescriptor.bRemoveAndPowerMask[0] = 0;
   4.283 -          uni->u.HubInformation.HubDescriptor.bRemoveAndPowerMask[1] = 0;
   4.284 -          // PortPwrCtrlMask
   4.285 -          uni->u.HubInformation.HubDescriptor.bRemoveAndPowerMask[2] = 0xFF;
   4.286 -          uni->u.HubInformation.HubIsBusPowered = TRUE;
   4.287 -        }
   4.288 -        WdfRequestSetInformation(request, FIELD_OFFSET(USB_NODE_INFORMATION, u.HubInformation.HubDescriptor.bRemoveAndPowerMask) + 3);
   4.289 -        break;
   4.290 -      case UsbMIParent:
   4.291 -        KdPrint((__DRIVER_NAME "      NodeType = UsbMIParent\n"));
   4.292 -        status = STATUS_BAD_INITIAL_PC;
   4.293 -        break;
   4.294 -      }
   4.295 -    }
   4.296 -    else
   4.297 -    {
   4.298 -      KdPrint((__DRIVER_NAME "     WdfRequestRetrieveOutputBuffer = %08x\n", status));
   4.299 -    }    
   4.300 -    break;
   4.301 -  }
   4.302 -#endif
   4.303    case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION:
   4.304      KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n"));
   4.305      break;
   4.306 @@ -973,6 +826,139 @@ XenUsb_EvtIoDeviceControl(
   4.307    FUNCTION_EXIT();
   4.308  }
   4.309  
   4.310 +EVT_WDF_REQUEST_CANCEL XenUsb_EvtRequestCancelPvUrb;
   4.311 +
   4.312 +VOID
   4.313 +XenUsb_EvtRequestCancelPvUrb(
   4.314 +  WDFREQUEST request)
   4.315 +{
   4.316 +  WDFDEVICE device = WdfIoQueueGetDevice(WdfRequestGetIoQueue(request));
   4.317 +  PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   4.318 +  WDF_REQUEST_PARAMETERS wrp;
   4.319 +  usbif_shadow_t *shadow;
   4.320 +  pvurb_t *pvurb;
   4.321 +  KIRQL old_irql;
   4.322 +  int notify;
   4.323 +
   4.324 +  FUNCTION_ENTER();
   4.325 +  FUNCTION_MSG("cancelling request %p\n", request);
   4.326 +  
   4.327 +  WDF_REQUEST_PARAMETERS_INIT(&wrp);
   4.328 +  WdfRequestGetParameters(request, &wrp);
   4.329 +  pvurb = (pvurb_t *)wrp.Parameters.Others.Arg1;
   4.330 +  FUNCTION_MSG("pvurb = %p\n", pvurb);
   4.331 +  ASSERT(pvurb);
   4.332 +  // acquire ring lock
   4.333 +  shadow = get_shadow_from_freelist(xudd);
   4.334 +  ASSERT(shadow); /* not sure what to do if we were to run out of shadow entries */
   4.335 +  shadow->request = request;
   4.336 +  shadow->req = &shadow->req_storage;
   4.337 +  *shadow->req = pvurb->req;
   4.338 +  shadow->req->id = shadow->id;
   4.339 +  shadow->req->pipe = usbif_setunlink_pipe(shadow->req->pipe);
   4.340 +  shadow->req->u.unlink.unlink_id = pvurb->req.id;
   4.341 +  KeAcquireSpinLock(&xudd->urb_ring_lock, &old_irql);
   4.342 +  *RING_GET_REQUEST(&xudd->urb_ring, xudd->urb_ring.req_prod_pvt) = *shadow->req;
   4.343 +  xudd->urb_ring.req_prod_pvt++;
   4.344 +  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
   4.345 +  if (notify) {
   4.346 +    KdPrint((__DRIVER_NAME "     Notifying\n"));
   4.347 +    xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
   4.348 +  }
   4.349 +  KeReleaseSpinLock(&xudd->urb_ring_lock, old_irql);  
   4.350 +  
   4.351 +  FUNCTION_EXIT();
   4.352 +}
   4.353 +
   4.354 +static VOID
   4.355 +XenUsb_EvtIoInternalDeviceControl_PVURB(
   4.356 +  WDFQUEUE queue,
   4.357 +  WDFREQUEST request,
   4.358 +  size_t output_buffer_length,
   4.359 +  size_t input_buffer_length,
   4.360 +  ULONG io_control_code)
   4.361 +{
   4.362 +  NTSTATUS status;
   4.363 +  WDFDEVICE device = WdfIoQueueGetDevice(queue);
   4.364 +  PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   4.365 +  WDF_REQUEST_PARAMETERS wrp;
   4.366 +  usbif_shadow_t *shadow;
   4.367 +  pvurb_t *pvurb;
   4.368 +  KIRQL old_irql;
   4.369 +  int i;
   4.370 +  int notify;
   4.371 +  
   4.372 +  UNREFERENCED_PARAMETER(input_buffer_length);
   4.373 +  UNREFERENCED_PARAMETER(output_buffer_length);
   4.374 +  UNREFERENCED_PARAMETER(io_control_code);
   4.375 +
   4.376 +  FUNCTION_ENTER();
   4.377 +
   4.378 +  ASSERT(io_control_code == IOCTL_INTERNAL_PVUSB_SUBMIT_URB);
   4.379 +
   4.380 +  WDF_REQUEST_PARAMETERS_INIT(&wrp);
   4.381 +  WdfRequestGetParameters(request, &wrp);
   4.382 +  pvurb = (pvurb_t *)wrp.Parameters.Others.Arg1;
   4.383 +  FUNCTION_MSG("pvurb = %p\n", pvurb);
   4.384 +  ASSERT(pvurb);
   4.385 +
   4.386 +  FUNCTION_MSG("IRQL = %d\n", KeGetCurrentIrql());
   4.387 +
   4.388 +  shadow = get_shadow_from_freelist(xudd);
   4.389 +//  FUNCTION_MSG("shadow = %p\n", shadow);
   4.390 +//  FUNCTION_MSG("shadow->id = %p\n", shadow->id);
   4.391 +  ASSERT(shadow);
   4.392 +  shadow->request = request;
   4.393 +  shadow->req = &pvurb->req;
   4.394 +//  FUNCTION_MSG("shadow->req = %p\n", shadow->req);
   4.395 +  shadow->rsp = &pvurb->rsp;
   4.396 +//  FUNCTION_MSG("shadow->rsp = %p\n", shadow->rsp);
   4.397 +  shadow->req->id = shadow->id;
   4.398 +  shadow->mdl = pvurb->mdl;
   4.399 +  shadow->total_length = 0;
   4.400 +  
   4.401 +  if (!shadow->mdl) {
   4.402 +    shadow->req->nr_buffer_segs = 0;
   4.403 +    shadow->req->buffer_length = 0;
   4.404 +  } else {
   4.405 +    ULONG remaining = MmGetMdlByteCount(shadow->mdl);
   4.406 +    USHORT offset = (USHORT)MmGetMdlByteOffset(shadow->mdl);
   4.407 +    shadow->req->buffer_length = (USHORT)MmGetMdlByteCount(shadow->mdl);
   4.408 +    shadow->req->nr_buffer_segs = (USHORT)ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(shadow->mdl), MmGetMdlByteCount(shadow->mdl));
   4.409 +    for (i = 0; i < shadow->req->nr_buffer_segs; i++) {
   4.410 +      shadow->req->seg[i].gref = xudd->vectors.GntTbl_GrantAccess(xudd->vectors.context, 0,
   4.411 +           (ULONG)MmGetMdlPfnArray(shadow->mdl)[i], FALSE, INVALID_GRANT_REF, (ULONG)'XUSB');
   4.412 +      shadow->req->seg[i].offset = (USHORT)offset;
   4.413 +      shadow->req->seg[i].length = (USHORT)min((USHORT)remaining, (USHORT)PAGE_SIZE - offset);
   4.414 +      offset = 0;
   4.415 +      remaining -= shadow->req->seg[i].length;
   4.416 +      KdPrint((__DRIVER_NAME "     seg = %d\n", i));
   4.417 +      KdPrint((__DRIVER_NAME "      gref = %d\n", shadow->req->seg[i].gref));
   4.418 +      KdPrint((__DRIVER_NAME "      offset = %d\n", shadow->req->seg[i].offset));
   4.419 +      KdPrint((__DRIVER_NAME "      length = %d\n", shadow->req->seg[i].length));
   4.420 +    }
   4.421 +    KdPrint((__DRIVER_NAME "     buffer_length = %d\n", shadow->req->buffer_length));
   4.422 +    KdPrint((__DRIVER_NAME "     nr_buffer_segs = %d\n", shadow->req->nr_buffer_segs));
   4.423 +  }
   4.424 +
   4.425 +  KeAcquireSpinLock(&xudd->urb_ring_lock, &old_irql);
   4.426 +  status = WdfRequestMarkCancelableEx(request, XenUsb_EvtRequestCancelPvUrb);
   4.427 +  if (status == STATUS_CANCELLED) {
   4.428 +    FUNCTION_MSG("request already cancelled");
   4.429 +    // ...
   4.430 +  }
   4.431 +  *RING_GET_REQUEST(&xudd->urb_ring, xudd->urb_ring.req_prod_pvt) = *shadow->req;
   4.432 +  xudd->urb_ring.req_prod_pvt++;
   4.433 +  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
   4.434 +  if (notify) {
   4.435 +    KdPrint((__DRIVER_NAME "     Notifying\n"));
   4.436 +    xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
   4.437 +  }
   4.438 +  KeReleaseSpinLock(&xudd->urb_ring_lock, old_irql);  
   4.439 +  
   4.440 +  FUNCTION_EXIT();
   4.441 +}
   4.442 +
   4.443  static VOID
   4.444  XenUsb_EvtIoInternalDeviceControl(
   4.445    WDFQUEUE queue,
   4.446 @@ -981,35 +967,26 @@ XenUsb_EvtIoInternalDeviceControl(
   4.447    size_t input_buffer_length,
   4.448    ULONG io_control_code)
   4.449  {
   4.450 -  //WDFDEVICE device = WdfIoQueueGetDevice(queue);
   4.451 -  //PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   4.452 -  PURB urb;
   4.453 -  xenusb_device_t *usb_device;
   4.454 -  WDF_REQUEST_PARAMETERS wrp;
   4.455 +  WDFDEVICE device = WdfIoQueueGetDevice(queue);
   4.456 +  PXENUSB_DEVICE_DATA xudd = GetXudd(device);
   4.457 +  //WDF_REQUEST_PARAMETERS wrp;
   4.458 +  //pvusb_urb_t *urb;
   4.459  
   4.460 -  UNREFERENCED_PARAMETER(queue);
   4.461    UNREFERENCED_PARAMETER(input_buffer_length);
   4.462    UNREFERENCED_PARAMETER(output_buffer_length);
   4.463  
   4.464    FUNCTION_ENTER();
   4.465  
   4.466 -  WDF_REQUEST_PARAMETERS_INIT(&wrp);
   4.467 -  WdfRequestGetParameters(request, &wrp);
   4.468 +  //WDF_REQUEST_PARAMETERS_INIT(&wrp);
   4.469 +  //WdfRequestGetParameters(request, &wrp);
   4.470  
   4.471    switch(io_control_code)
   4.472    {
   4.473 -  case IOCTL_INTERNAL_USB_SUBMIT_URB:
   4.474 -    FUNCTION_MSG("IOCTL_INTERNAL_USB_SUBMIT_URB\n");
   4.475 -    urb = (PURB)wrp.Parameters.Others.Arg1;
   4.476 -    FUNCTION_MSG("urb = %p\n", urb);
   4.477 -    ASSERT(urb);
   4.478 -    usb_device = urb->UrbHeader.UsbdDeviceHandle;
   4.479 -    FUNCTION_MSG("usb_device = %p\n", usb_device);
   4.480 -    ASSERT(usb_device);
   4.481 -    if (usb_device == (xenusb_device_t *)((ULONG_PTR)0 - 1))
   4.482 -      WdfRequestComplete(request, STATUS_INVALID_PARAMETER);
   4.483 -    else
   4.484 -      WdfRequestForwardToIoQueue(request, usb_device->urb_queue);
   4.485 +  case IOCTL_INTERNAL_PVUSB_SUBMIT_URB:
   4.486 +    FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB\n");
   4.487 +    //urb = (pvusb_urb_t *)wrp.Parameters.Others.Arg1;
   4.488 +    //FUNCTION_MSG("urb = %p\n", urb);
   4.489 +    WdfRequestForwardToIoQueue(request, xudd->pvurb_queue);
   4.490      break;
   4.491    default:
   4.492      KdPrint((__DRIVER_NAME "     Unknown IOCTL %08x\n", io_control_code));
   4.493 @@ -1142,6 +1119,18 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   4.494        return status;
   4.495    }
   4.496  
   4.497 +  WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchParallel);
   4.498 +  queue_config.PowerManaged = FALSE; /* ? */
   4.499 +  //queue_config.EvtIoDeviceControl = XenUsb_EvtIoDeviceControl;
   4.500 +  queue_config.EvtIoInternalDeviceControl = XenUsb_EvtIoInternalDeviceControl_PVURB;
   4.501 +  //queue_config.EvtIoDefault = XenUsb_EvtIoDefault;
   4.502 +  queue_config.Settings.Parallel.NumberOfPresentedRequests = USB_URB_RING_SIZE; /* the queue controls if the ring is full */
   4.503 +  status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &xudd->pvurb_queue);
   4.504 +  if (!NT_SUCCESS(status)) {
   4.505 +      KdPrint((__DRIVER_NAME "     Error creating urb_queue 0x%x\n", status));
   4.506 +      return status;
   4.507 +  }
   4.508 +
   4.509    WDF_DEVICE_POWER_CAPABILITIES_INIT(&power_capabilities);
   4.510    power_capabilities.DeviceD1 = WdfTrue;
   4.511    power_capabilities.WakeFromD1 = WdfTrue;
   4.512 @@ -1178,4 +1167,4 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   4.513  
   4.514    FUNCTION_EXIT();
   4.515    return status;
   4.516 -}
   4.517 +}
   4.518 \ No newline at end of file
     5.1 --- a/xenusb/xenusb_hub.c	Sat Jan 14 23:19:33 2012 +1100
     5.2 +++ b/xenusb/xenusb_hub.c	Sat Jan 14 23:22:29 2012 +1100
     5.3 @@ -346,12 +346,6 @@ XenUsbHub_EvtIoInternalDeviceControl(
     5.4      FUNCTION_MSG(" NtStatus = %08x\n", usfd->NtStatus);
     5.5      FUNCTION_MSG(" UsbdStatus = %08x\n", usfd->UsbdStatus);
     5.6      FUNCTION_MSG(" ConnectStatus = %08x\n", usfd->ConnectStatus);
     5.7 -#if 0
     5.8 -    FUNCTION_MSG(" DriverData[0] = %s\n", usfd->DriverData);
     5.9 -    FUNCTION_MSG(" DriverData[0] = %S\n", usfd->DriverData);
    5.10 -    FUNCTION_MSG(" DriverData[5] = %s\n", &usfd->DriverData[5]);
    5.11 -    FUNCTION_MSG(" DriverData[5] = %S\n", &usfd->DriverData[5]);
    5.12 -#endif
    5.13      status = STATUS_SUCCESS;
    5.14      break;  
    5.15  #endif
    5.16 @@ -572,14 +566,6 @@ XenUsbHub_UBIH_CreateUsbDevice(
    5.17    return status;
    5.18  }
    5.19  
    5.20 -static VOID
    5.21 -XenUsb_SetEventCallback(usbif_shadow_t *shadow)
    5.22 -{
    5.23 -  FUNCTION_ENTER();
    5.24 -  KeSetEvent(&shadow->event, IO_NO_INCREMENT, FALSE);
    5.25 -  FUNCTION_EXIT();
    5.26 -}
    5.27 -
    5.28  static NTSTATUS
    5.29  XenUsbHub_UBIH_InitializeUsbDevice(
    5.30   PVOID BusContext,
    5.31 @@ -588,19 +574,21 @@ XenUsbHub_UBIH_InitializeUsbDevice(
    5.32    NTSTATUS status = STATUS_SUCCESS;
    5.33    WDFDEVICE device = BusContext;
    5.34    PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
    5.35 -  PXENUSB_DEVICE_DATA xudd = GetXudd(xupdd->wdf_device_bus_fdo);
    5.36 +  //PXENUSB_DEVICE_DATA xudd = GetXudd(xupdd->wdf_device_bus_fdo);
    5.37    WDF_IO_QUEUE_CONFIG queue_config;
    5.38    xenusb_device_t *usb_device = DeviceHandle;
    5.39    PUCHAR ptr;
    5.40    PVOID buf;
    5.41    PMDL mdl;
    5.42 -  usbif_shadow_t *shadow;
    5.43 +  pvurb_t pvurb; /* this can be local because it never leaves this routine */
    5.44    PUSB_DEVICE_DESCRIPTOR device_descriptor;
    5.45    PUSB_CONFIGURATION_DESCRIPTOR config_descriptor;
    5.46    PUSB_INTERFACE_DESCRIPTOR interface_descriptor;
    5.47    PUSB_ENDPOINT_DESCRIPTOR endpoint_descriptor;
    5.48    int i, j, k;
    5.49    PUSB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
    5.50 +  WDF_MEMORY_DESCRIPTOR pvurb_descriptor;
    5.51 +  WDF_REQUEST_SEND_OPTIONS send_options;
    5.52    
    5.53    FUNCTION_ENTER();
    5.54  
    5.55 @@ -617,40 +605,36 @@ XenUsbHub_UBIH_InitializeUsbDevice(
    5.56    buf = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENUSB_POOL_TAG);
    5.57    mdl = IoAllocateMdl(buf, PAGE_SIZE, FALSE, FALSE, NULL);
    5.58    MmBuildMdlForNonPagedPool(mdl);
    5.59 -  shadow = get_shadow_from_freelist(xudd);
    5.60 +
    5.61 +  WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&pvurb_descriptor, &pvurb, sizeof(pvurb));
    5.62 +  WDF_REQUEST_SEND_OPTIONS_INIT(&send_options, WDF_REQUEST_SEND_OPTION_TIMEOUT);
    5.63 +  WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&send_options, WDF_REL_TIMEOUT_IN_SEC(10));
    5.64  
    5.65    /* set the address */
    5.66 -  KeInitializeEvent(&shadow->event, NotificationEvent, FALSE);
    5.67 -  shadow->callback = XenUsb_SetEventCallback;
    5.68 -  shadow->req.id = shadow->id;
    5.69 -  shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | usb_device->port_number;
    5.70 -  shadow->req.transfer_flags = 0; 
    5.71 -  shadow->req.buffer_length = 0;
    5.72 -  setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
    5.73 +  pvurb.req.pipe = LINUX_PIPE_TYPE_CTRL | usb_device->port_number;
    5.74 +  pvurb.req.transfer_flags = 0; 
    5.75 +  pvurb.req.buffer_length = 0;
    5.76 +  setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)pvurb.req.u.ctrl;
    5.77    setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
    5.78    setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
    5.79    setup_packet->bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
    5.80    setup_packet->bRequest = USB_REQUEST_SET_ADDRESS;
    5.81    setup_packet->wValue.W = usb_device->address;
    5.82    setup_packet->wIndex.W = 0;
    5.83 -  setup_packet->wLength = shadow->req.buffer_length;
    5.84 -  status = XenUsb_ExecuteRequest(xudd, shadow, NULL, NULL, 0);
    5.85 -  //TODO: Handle failure here
    5.86 -  KeWaitForSingleObject(&shadow->event, Executive, KernelMode, FALSE, NULL);
    5.87 -  KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    5.88 -  KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    5.89 -  KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    5.90 -  KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    5.91 -  KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    5.92 +  setup_packet->wLength = pvurb.req.buffer_length;
    5.93 +  pvurb.mdl = NULL;
    5.94 +  status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, NULL, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
    5.95 +  FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
    5.96 +  FUNCTION_MSG("rsp start_frame = %d\n", pvurb.rsp.start_frame);
    5.97 +  FUNCTION_MSG("rsp status = %d\n", pvurb.rsp.status);
    5.98 +  FUNCTION_MSG("rsp actual_length = %d\n", pvurb.rsp.actual_length);
    5.99 +  FUNCTION_MSG("rsp error_count = %d\n", pvurb.rsp.error_count);
   5.100  
   5.101    /* get the device descriptor */
   5.102 -  KeInitializeEvent(&shadow->event, NotificationEvent, FALSE);
   5.103 -  shadow->callback = XenUsb_SetEventCallback;
   5.104 -  shadow->req.id = shadow->id;
   5.105 -  shadow->req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   5.106 -  shadow->req.transfer_flags = 0; 
   5.107 -  shadow->req.buffer_length = PAGE_SIZE;
   5.108 -  setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
   5.109 +  pvurb.req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   5.110 +  pvurb.req.transfer_flags = 0; 
   5.111 +  pvurb.req.buffer_length = PAGE_SIZE;
   5.112 +  setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)pvurb.req.u.ctrl;
   5.113    setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
   5.114    setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
   5.115    setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
   5.116 @@ -658,15 +642,14 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   5.117    setup_packet->wValue.LowByte = 0;
   5.118    setup_packet->wValue.HiByte = USB_DEVICE_DESCRIPTOR_TYPE; //device descriptor
   5.119    setup_packet->wIndex.W = 0;
   5.120 -  setup_packet->wLength = shadow->req.buffer_length;
   5.121 -  status = XenUsb_ExecuteRequest(xudd, shadow, NULL, mdl, PAGE_SIZE);
   5.122 -  //TODO: Handle failure here
   5.123 -  KeWaitForSingleObject(&shadow->event, Executive, KernelMode, FALSE, NULL);
   5.124 -  KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
   5.125 -  KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
   5.126 -  KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
   5.127 -  KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
   5.128 -  KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
   5.129 +  setup_packet->wLength = pvurb.req.buffer_length;
   5.130 +  pvurb.mdl = mdl;
   5.131 +  status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, NULL, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
   5.132 +  FUNCTION_MSG("IOCTL_INTERNAL_PVUSB_SUBMIT_URB status = %08x\n", status);
   5.133 +  KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb.rsp.start_frame));
   5.134 +  KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb.rsp.status));
   5.135 +  KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb.rsp.actual_length));
   5.136 +  KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", pvurb.rsp.error_count));
   5.137    ptr = buf;
   5.138    device_descriptor = (PUSB_DEVICE_DESCRIPTOR)ptr;
   5.139    KdPrint((__DRIVER_NAME "     bLength = %d\n", device_descriptor->bLength));
   5.140 @@ -687,13 +670,10 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   5.141    /* get the config descriptor */
   5.142    for (i = 0; i < device_descriptor->bNumConfigurations; i++)
   5.143    {
   5.144 -    KeInitializeEvent(&shadow->event, NotificationEvent, FALSE);
   5.145 -    shadow->callback = XenUsb_SetEventCallback;
   5.146 -    shadow->req.id = shadow->id;
   5.147 -    shadow->req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   5.148 -    shadow->req.transfer_flags = 0; 
   5.149 -    shadow->req.buffer_length = PAGE_SIZE;
   5.150 -    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
   5.151 +    pvurb.req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
   5.152 +    pvurb.req.transfer_flags = 0; 
   5.153 +    pvurb.req.buffer_length = PAGE_SIZE;
   5.154 +    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)pvurb.req.u.ctrl;
   5.155      setup_packet->bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
   5.156      setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
   5.157      setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
   5.158 @@ -701,15 +681,13 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   5.159      setup_packet->wValue.LowByte = (UCHAR)(i + 1);
   5.160      setup_packet->wValue.HiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE; //device descriptor
   5.161      setup_packet->wIndex.W = 0;
   5.162 -    setup_packet->wLength = shadow->req.buffer_length;
   5.163 -    status = XenUsb_ExecuteRequest(xudd, shadow, buf, NULL, PAGE_SIZE);
   5.164 -    //TODO: Handle failure here
   5.165 -    KeWaitForSingleObject(&shadow->event, Executive, KernelMode, FALSE, NULL);
   5.166 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
   5.167 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
   5.168 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
   5.169 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
   5.170 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
   5.171 +    setup_packet->wLength = pvurb.req.buffer_length;
   5.172 +    pvurb.mdl = mdl;
   5.173 +    status = WdfIoTargetSendInternalIoctlOthersSynchronously(xupdd->bus_fdo_target, NULL, IOCTL_INTERNAL_PVUSB_SUBMIT_URB, &pvurb_descriptor, NULL, NULL, &send_options, NULL);
   5.174 +    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", pvurb.rsp.start_frame));
   5.175 +    KdPrint((__DRIVER_NAME "     rsp status = %d\n", pvurb.rsp.status));
   5.176 +    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", pvurb.rsp.actual_length));
   5.177 +    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", pvurb.rsp.error_count));
   5.178      ptr = buf;
   5.179      config_descriptor = (PUSB_CONFIGURATION_DESCRIPTOR)ptr;
   5.180      KdPrint((__DRIVER_NAME "     Config %d\n", i));
   5.181 @@ -791,20 +769,18 @@ XenUsbHub_UBIH_InitializeUsbDevice(
   5.182        j++;
   5.183      }
   5.184    }
   5.185 +
   5.186    usb_device->active_config = usb_device->configs[0];
   5.187    usb_device->active_interface = usb_device->configs[0]->interfaces[0];
   5.188  
   5.189    WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchParallel); // should this be serial?
   5.190    queue_config.EvtIoInternalDeviceControl = XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB;
   5.191    queue_config.PowerManaged = TRUE; /* power managed queue for SUBMIT_URB */
   5.192 -  status = WdfIoQueueCreate(xupdd->wdf_device_bus_fdo, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &usb_device->urb_queue);
   5.193 +  status = WdfIoQueueCreate(device, &queue_config, WDF_NO_OBJECT_ATTRIBUTES, &usb_device->urb_queue);
   5.194    if (!NT_SUCCESS(status)) {
   5.195        KdPrint((__DRIVER_NAME "     Error creating urb_queue 0x%x\n", status));
   5.196        return status;
   5.197    }
   5.198 -
   5.199 -  put_shadow_on_freelist(xudd, shadow);
   5.200 -
   5.201    FUNCTION_EXIT();
   5.202    return status;
   5.203  }
   5.204 @@ -1947,6 +1923,7 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   5.205    WDF_PNPPOWER_EVENT_CALLBACKS child_pnp_power_callbacks;
   5.206    WDF_DEVICE_POWER_CAPABILITIES child_power_capabilities;
   5.207    WDF_IO_QUEUE_CONFIG queue_config;
   5.208 +  WDF_IO_TARGET_OPEN_PARAMS target_params;
   5.209  #if (NTDDI_VERSION >= NTDDI_VISTA)
   5.210    WDF_QUERY_INTERFACE_CONFIG interface_config;
   5.211  #if 0
   5.212 @@ -2000,6 +1977,8 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   5.213  
   5.214    WdfDeviceInitSetIoType(child_init, WdfDeviceIoDirect);
   5.215  
   5.216 +  WdfPdoInitAllowForwardingRequestToParent(child_init);
   5.217 +
   5.218    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&child_attributes, XENUSB_PDO_DEVICE_DATA);
   5.219    status = WdfDeviceCreate(&child_init, &child_attributes, &child_device);
   5.220    if (!NT_SUCCESS(status))
   5.221 @@ -2013,6 +1992,12 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   5.222    
   5.223    xupdd->wdf_device = child_device;
   5.224    xupdd->wdf_device_bus_fdo = WdfChildListGetDevice(child_list);
   5.225 +
   5.226 +  status = WdfIoTargetCreate(bus_device, WDF_NO_OBJECT_ATTRIBUTES, &xupdd->bus_fdo_target);
   5.227 +  ASSERT(NT_SUCCESS(status));
   5.228 +  WDF_IO_TARGET_OPEN_PARAMS_INIT_EXISTING_DEVICE(&target_params, WdfDeviceWdmGetDeviceObject(bus_device));
   5.229 +  status = WdfIoTargetOpen(xupdd->bus_fdo_target, &target_params);
   5.230 +  ASSERT(NT_SUCCESS(status));
   5.231    
   5.232    xupdd->usb_device = ExAllocatePoolWithTag(NonPagedPool, sizeof(xenusb_device_t), XENUSB_POOL_TAG);
   5.233    // get address from freelist...
   5.234 @@ -2068,17 +2053,6 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   5.235    xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.wMaxPacketSize = 2;
   5.236    xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->endpoint_descriptor.bInterval = 12;
   5.237    WdfSpinLockCreate(WDF_NO_OBJECT_ATTRIBUTES, &xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->lock);
   5.238 -#if 0
   5.239 -  WDF_TIMER_CONFIG_INIT(&timer_config, XenUsbHub_HubInterruptTimer);  
   5.240 -  WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&timer_attributes, pxenusb_endpoint_t);
   5.241 -  timer_attributes.ParentObject = child_device;
   5.242 -  status = WdfTimerCreate(&timer_config, &timer_attributes, &xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->interrupt_timer);
   5.243 -  if (!NT_SUCCESS(status)) {
   5.244 -      KdPrint((__DRIVER_NAME "     Error creating timer 0x%x\n", status));
   5.245 -      return status;
   5.246 -  }
   5.247 -  *GetEndpoint(xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0]->interrupt_timer) = xupdd->usb_device->configs[0]->interfaces[0]->endpoints[0];
   5.248 -#endif
   5.249  
   5.250    WDF_IO_QUEUE_CONFIG_INIT(&queue_config, WdfIoQueueDispatchParallel);
   5.251    queue_config.EvtIoInternalDeviceControl = XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB;
     6.1 --- a/xenusb/xenusb_huburb.c	Sat Jan 14 23:19:33 2012 +1100
     6.2 +++ b/xenusb/xenusb_huburb.c	Sat Jan 14 23:22:29 2012 +1100
     6.3 @@ -516,255 +516,6 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
     6.4      //FUNCTION_EXIT();
     6.5      return;
     6.6      
     6.7 -#if 0 // not using this bit
     6.8 -  case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
     6.9 -  //case URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT:
    6.10 -  //case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
    6.11 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_XXX\n"));
    6.12 -    KdPrint((__DRIVER_NAME "      Reserved = %p\n", urb->UrbControlDescriptorRequest.Reserved));
    6.13 -    KdPrint((__DRIVER_NAME "      Reserved0 = %08X\n", urb->UrbControlDescriptorRequest.Reserved0));
    6.14 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
    6.15 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlDescriptorRequest.TransferBuffer));
    6.16 -    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlDescriptorRequest.TransferBufferMDL));
    6.17 -    KdPrint((__DRIVER_NAME "      UrbLink = %p\n", urb->UrbControlDescriptorRequest.UrbLink));
    6.18 -    KdPrint((__DRIVER_NAME "      Index = %d\n", (int)urb->UrbControlDescriptorRequest.Index));
    6.19 -    KdPrint((__DRIVER_NAME "      DescriptorType = %d\n", (int)urb->UrbControlDescriptorRequest.DescriptorType));
    6.20 -    KdPrint((__DRIVER_NAME "      LanguageId = %04x\n", urb->UrbControlDescriptorRequest.LanguageId));
    6.21 -    KdPrint((__DRIVER_NAME "      Reserved2 = %04X\n", urb->UrbControlDescriptorRequest.Reserved2));
    6.22 -    switch (urb->UrbControlDescriptorRequest.DescriptorType)
    6.23 -    {
    6.24 -    case USB_DEVICE_DESCRIPTOR_TYPE:
    6.25 -      KdPrint((__DRIVER_NAME "      USB_DEVICE_DESCRIPTOR_TYPE\n"));
    6.26 -      memcpy(urb->UrbControlDescriptorRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
    6.27 -      urb->UrbControlDescriptorRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
    6.28 -      KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
    6.29 -      break;
    6.30 -    case USB_CONFIGURATION_DESCRIPTOR_TYPE:
    6.31 -    {
    6.32 -      xenusb_config_t *usb_config;
    6.33 -      PUCHAR ptr;
    6.34 -
    6.35 -      KdPrint((__DRIVER_NAME "      USB_CONFIGURATION_DESCRIPTOR_TYPE\n"));
    6.36 -      usb_config = usb_device->active_config;
    6.37 -      ptr = (PUCHAR)decode_data.buffer;
    6.38 -      memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
    6.39 -      ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
    6.40 -      ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
    6.41 -      if (urb->UrbControlDescriptorRequest.TransferBufferLength > 9)
    6.42 -      {
    6.43 -        for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
    6.44 -        {
    6.45 -          memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
    6.46 -          KdPrint((__DRIVER_NAME "      bInterfaceClass = %02x\n", ((PUSB_INTERFACE_DESCRIPTOR)ptr)->bInterfaceClass));
    6.47 -          ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
    6.48 -          ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
    6.49 -          for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
    6.50 -          {
    6.51 -            memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
    6.52 -            ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
    6.53 -            ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
    6.54 -          }
    6.55 -        }
    6.56 -      }
    6.57 -      *decode_data.length = ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength;
    6.58 -      if (*decode_data.length == 9)
    6.59 -        ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = 32;
    6.60 -      KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
    6.61 -      break;
    6.62 -    } 
    6.63 -    default:
    6.64 -      KdPrint((__DRIVER_NAME "      UNKNOWN_DESCRIPTOR_TYPE\n"));
    6.65 -      break;
    6.66 -    }
    6.67 -    urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
    6.68 -    break;
    6.69 -  case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
    6.70 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
    6.71 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlGetStatusRequest.TransferBufferLength));
    6.72 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlGetStatusRequest.TransferBuffer));
    6.73 -    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlGetStatusRequest.TransferBufferMDL));
    6.74 -    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlGetStatusRequest.Index));
    6.75 -    if (urb->UrbControlGetStatusRequest.Index == 0)
    6.76 -    {
    6.77 -      urb->UrbControlGetStatusRequest.TransferBufferLength = 2;
    6.78 -      *(PUSHORT)urb->UrbControlGetStatusRequest.TransferBuffer = 0x0003;
    6.79 -      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
    6.80 -    }
    6.81 -    else
    6.82 -    {
    6.83 -      KdPrint((__DRIVER_NAME "     Unknown Index\n"));
    6.84 -      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    6.85 -    }    
    6.86 -    break;
    6.87 -  case URB_FUNCTION_CLASS_DEVICE:
    6.88 -#if 1
    6.89 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_DEVICE\n"));
    6.90 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
    6.91 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
    6.92 -    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
    6.93 -    KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
    6.94 -    KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
    6.95 -    KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
    6.96 -    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
    6.97 -#endif
    6.98 -    switch (urb->UrbControlVendorClassRequest.Request)
    6.99 -    {
   6.100 -    case USB_REQUEST_GET_DESCRIPTOR:
   6.101 -      KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_DEVICE\n"));
   6.102 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   6.103 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   6.104 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   6.105 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   6.106 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   6.107 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   6.108 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   6.109 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_DESCRIPTOR\n"));
   6.110 -      switch (urb->UrbControlVendorClassRequest.Value >> 8)
   6.111 -      {
   6.112 -      case 0x00:
   6.113 -#if 0      
   6.114 -        memcpy(urb->UrbControlVendorClassRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
   6.115 -        urb->UrbControlVendorClassRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
   6.116 -        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   6.117 -        break;
   6.118 -#endif
   6.119 -      case 0x29: // Hub Descriptor
   6.120 -        KdPrint((__DRIVER_NAME "       HUB_DESCRIPTOR\n"));
   6.121 -        uhd = urb->UrbControlVendorClassRequest.TransferBuffer;
   6.122 -        urb->UrbControlVendorClassRequest.TransferBufferLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
   6.123 -        uhd->bDescriptorLength = (UCHAR)urb->UrbControlVendorClassRequest.TransferBufferLength;
   6.124 -        uhd->bDescriptorType = 0x29;
   6.125 -        uhd->bNumberOfPorts = xudd->num_ports;
   6.126 -        uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
   6.127 -        uhd->bPowerOnToPowerGood = 1; // 2ms units
   6.128 -        uhd->bHubControlCurrent = 0;
   6.129 -        // DeviceRemovable bits (includes an extra bit at the start)
   6.130 -        uhd->bRemoveAndPowerMask[0] = 0;
   6.131 -        uhd->bRemoveAndPowerMask[1] = 0;
   6.132 -        // PortPwrCtrlMask
   6.133 -        uhd->bRemoveAndPowerMask[2] = 0xFF;
   6.134 -        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   6.135 -        break;
   6.136 -      default:
   6.137 -        KdPrint((__DRIVER_NAME "       Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
   6.138 -        urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   6.139 -        break;
   6.140 -      }
   6.141 -      break;
   6.142 -    case USB_REQUEST_GET_STATUS:
   6.143 -      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   6.144 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   6.145 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   6.146 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   6.147 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   6.148 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   6.149 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   6.150 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   6.151 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_STATUS\n"));
   6.152 -      // Check that RequestTypeReservedBits == 0xA0
   6.153 -      KdPrint((__DRIVER_NAME "       GetHubStatus\n"));
   6.154 -      /* hub status */
   6.155 -      // shoud be able to get this field from somewhere else...
   6.156 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = 0x0000;
   6.157 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = 0x0000; /* no change occurred */
   6.158 -      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   6.159 -      break;
   6.160 -    case USB_REQUEST_CLEAR_FEATURE:
   6.161 -      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   6.162 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   6.163 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   6.164 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   6.165 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   6.166 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   6.167 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   6.168 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   6.169 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_CLEAR_FEATURE\n"));
   6.170 -      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   6.171 -      break;
   6.172 -    default:
   6.173 -      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   6.174 -      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   6.175 -      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   6.176 -      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   6.177 -      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   6.178 -      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   6.179 -      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   6.180 -      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   6.181 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   6.182 -      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   6.183 -      break;
   6.184 -    }
   6.185 -    break;
   6.186 -  case URB_FUNCTION_CLASS_OTHER:
   6.187 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_OTHER\n"));
   6.188 -    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   6.189 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   6.190 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   6.191 -    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   6.192 -    KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   6.193 -    KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   6.194 -    KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   6.195 -    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   6.196 -    switch (urb->UrbControlVendorClassRequest.Request)
   6.197 -    {
   6.198 -    case USB_REQUEST_GET_STATUS:
   6.199 -      /* port status - 11.24.2.7.1 */
   6.200 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_STATUS\n"));
   6.201 -      KdPrint((__DRIVER_NAME "       GetHubStatus\n"));
   6.202 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status;
   6.203 -      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change;
   6.204 -      break;
   6.205 -    case USB_REQUEST_SET_FEATURE:
   6.206 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_SET_FEATURE\n"));
   6.207 -      KdPrint((__DRIVER_NAME "       SetPortFeature\n"));
   6.208 -      switch (urb->UrbControlVendorClassRequest.Value)
   6.209 -      {
   6.210 -      case PORT_ENABLE:
   6.211 -        KdPrint((__DRIVER_NAME "        PORT_ENABLE\n"));
   6.212 -        /* do something here */
   6.213 -        break;
   6.214 -      case PORT_RESET:
   6.215 -        KdPrint((__DRIVER_NAME "        PORT_RESET\n"));
   6.216 -        /* just fake the reset */
   6.217 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change |= (1 << PORT_RESET);
   6.218 -        break;
   6.219 -      default:
   6.220 -        KdPrint((__DRIVER_NAME "        Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
   6.221 -        break;
   6.222 -      }
   6.223 -      KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   6.224 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   6.225 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   6.226 -      break;
   6.227 -    case USB_REQUEST_CLEAR_FEATURE:
   6.228 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_CLEAR_FEATURE\n"));
   6.229 -      KdPrint((__DRIVER_NAME "       ClearPortFeature\n"));
   6.230 -      switch (urb->UrbControlVendorClassRequest.Value)
   6.231 -      {
   6.232 -      case C_PORT_CONNECTION:
   6.233 -        KdPrint((__DRIVER_NAME "        C_PORT_CONNECTION\n"));
   6.234 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_CONNECTION);
   6.235 -        break;
   6.236 -      case C_PORT_RESET:
   6.237 -        KdPrint((__DRIVER_NAME "        C_PORT_RESET\n"));
   6.238 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_RESET);
   6.239 -        break;
   6.240 -      default:
   6.241 -        KdPrint((__DRIVER_NAME "        Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
   6.242 -        break;
   6.243 -      }
   6.244 -      KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   6.245 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   6.246 -        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   6.247 -      break;
   6.248 -    default:
   6.249 -      KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   6.250 -      break;
   6.251 -    }
   6.252 -    //urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   6.253 -    urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   6.254 -    break;
   6.255 -#endif
   6.256    default:
   6.257      FUNCTION_MSG("URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
   6.258      if (decode_retval != URB_DECODE_NOT_CONTROL)