win-pvdrivers

changeset 929:3aa213de2a31

Updates to try and make xenusb work under 2008R2. This probably breaks the compile for XP. Very noisy and still doesn't work.
author James Harper <james.harper@bendigoit.com.au>
date Tue Jun 07 22:37:56 2011 +1000 (2011-06-07)
parents 047bcd81cdc0
children 95579023dfe9
files xenusb/sources 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/sources	Sat Jun 04 17:39:58 2011 +1000
     1.2 +++ b/xenusb/sources	Tue Jun 07 22:37:56 2011 +1000
     1.3 @@ -4,4 +4,4 @@ TARGETTYPE=DRIVER
     1.4  KMDF_VERSION_MAJOR=1
     1.5  NTTARGETFILES=$(NTTARGETFILES) $(OBJ_PATH)\$(O)\$(TARGETNAME).inf
     1.6  TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\wdmsec.lib $(DDK_LIB_PATH)\Rtlver.lib $(DDK_LIB_PATH)\..\..\wlh\*\aux_klib.lib
     1.7 -SOURCES=xenusb.rc xenusb.c xenusb_fdo.c xenusb_hub.c xenusb_huburb.c xenusb_devurb.c
     1.8 +SOURCES=xenusb.rc xenusb.c xenusb_fdo.c xenusb_hub.c xenusb_huburb.c xenusb_devurb.c xenusb_decode.c
     2.1 --- a/xenusb/xenusb.h	Sat Jun 04 17:39:58 2011 +1000
     2.2 +++ b/xenusb/xenusb.h	Tue Jun 07 22:37:56 2011 +1000
     2.3 @@ -97,10 +97,14 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  #define LINUX_URB_ZERO_PACKET         0x0040  /* Finish bulk OUT with short packet */
     2.5  #define LINUX_URB_NO_INTERRUPT        0x0080  /* HINT: no non-error interrupt needed */
     2.6  
     2.7 +#define PRE_DECLARE_TYPE_TYPEDEF(x) struct _##x; typedef struct _##x x##_t
     2.8  
     2.9 -
    2.10 +#if 0
    2.11  struct _usbif_shadow;
    2.12  typedef struct _usbif_shadow usbif_shadow_t;
    2.13 +#endif
    2.14 +
    2.15 +PRE_DECLARE_TYPE_TYPEDEF(usbif_shadow);
    2.16  
    2.17  struct _usbif_shadow {
    2.18    uint16_t id;
    2.19 @@ -112,7 +116,7 @@ struct _usbif_shadow {
    2.20      };
    2.21      KEVENT event;
    2.22    };
    2.23 -  WDFDMATRANSACTION dma_transaction;
    2.24 +  //WDFDMATRANSACTION dma_transaction;
    2.25    PMDL mdl;
    2.26    ULONG total_length;
    2.27    /* called at DISPATCH_LEVEL */
    2.28 @@ -186,7 +190,7 @@ typedef struct
    2.29  typedef struct {  
    2.30    BOOLEAN XenBus_ShuttingDown;
    2.31    WDFQUEUE io_queue;
    2.32 -  WDFDMAENABLER dma_enabler;
    2.33 +  //WDFDMAENABLER dma_enabler;
    2.34    
    2.35    WDFCHILDLIST child_list;
    2.36    
    2.37 @@ -329,5 +333,22 @@ XenUsb_ExecuteRequest(
    2.38    PVOID transfer_buffer,
    2.39    PMDL transfer_buffer_mdl,
    2.40    ULONG transfer_buffer_length);
    2.41 - 
    2.42 +
    2.43 +#define URB_DECODE_UNKNOWN     0 /* URB is unknown */
    2.44 +#define URB_DECODE_COMPLETE    1 /* URB is decoded and no further work should be required */
    2.45 +#define URB_DECODE_INCOMPLETE  2 /* URB is decoded but further work is required */
    2.46 +#define URB_DECODE_NOT_CONTROL 3 /* URB is known but not a control packet */
    2.47 +
    2.48 +typedef struct {
    2.49 +  PULONG length;
    2.50 +  PVOID buffer;
    2.51 +  union {
    2.52 +    USB_DEFAULT_PIPE_SETUP_PACKET default_pipe_setup_packet;
    2.53 +    UCHAR raw[8];
    2.54 +  } setup_packet;
    2.55 +} urb_decode_t;
    2.56 +
    2.57 +ULONG
    2.58 +XenUsb_DecodeControlUrb(PURB urb, urb_decode_t *decode_data);
    2.59 +  
    2.60  #endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xenusb/xenusb_decode.c	Tue Jun 07 22:37:56 2011 +1000
     3.3 @@ -0,0 +1,398 @@
     3.4 +/*
     3.5 +PV Drivers for Windows Xen HVM Domains
     3.6 +Copyright (C) 2007 James Harper
     3.7 +
     3.8 +This program is free software; you can redistribute it and/or
     3.9 +modify it under the terms of the GNU General Public License
    3.10 +as published by the Free Software Foundation; either version 2
    3.11 +of the License, or (at your option) any later version.
    3.12 +
    3.13 +This program is distributed in the hope that it will be useful,
    3.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.16 +GNU General Public License for more details.
    3.17 +
    3.18 +You should have received a copy of the GNU General Public License
    3.19 +along with this program; if not, write to the Free Software
    3.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    3.21 +*/
    3.22 +
    3.23 +#include "xenusb.h"
    3.24 +
    3.25 +/*
    3.26 +decode all the funky URB_Xxx functions into a basic 8 byte SetupPacket
    3.27 +*/
    3.28 +ULONG
    3.29 +XenUsb_DecodeControlUrb(PURB urb, urb_decode_t *decode_data)
    3.30 +{
    3.31 +  ULONG retval;
    3.32 +  
    3.33 +  FUNCTION_ENTER();
    3.34 +  switch(urb->UrbHeader.Function)
    3.35 +  {
    3.36 +  case URB_FUNCTION_SELECT_CONFIGURATION:
    3.37 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_CONFIGURATION\n"));
    3.38 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
    3.39 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    3.40 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
    3.41 +    decode_data->setup_packet.default_pipe_setup_packet.bRequest = USB_REQUEST_SET_CONFIGURATION;
    3.42 +    decode_data->setup_packet.default_pipe_setup_packet.wLength = 0;
    3.43 +    decode_data->setup_packet.default_pipe_setup_packet.wValue.W = urb->UrbSelectConfiguration.ConfigurationDescriptor->bConfigurationValue;
    3.44 +    decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = 0;
    3.45 +    decode_data->buffer = NULL;
    3.46 +    retval = URB_DECODE_INCOMPLETE;
    3.47 +    break;
    3.48 +  case URB_FUNCTION_SELECT_INTERFACE:
    3.49 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_INTERFACE\n"));
    3.50 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
    3.51 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    3.52 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
    3.53 +    decode_data->setup_packet.default_pipe_setup_packet.bRequest = USB_REQUEST_SET_INTERFACE;
    3.54 +    decode_data->setup_packet.default_pipe_setup_packet.wLength = 0;
    3.55 +    decode_data->setup_packet.default_pipe_setup_packet.wValue.W = urb->UrbSelectInterface.Interface.AlternateSetting;
    3.56 +    decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = urb->UrbSelectInterface.Interface.InterfaceNumber;
    3.57 +    decode_data->buffer = NULL;
    3.58 +    retval = URB_DECODE_INCOMPLETE;
    3.59 +    break;
    3.60 +  case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
    3.61 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n"));
    3.62 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Recipient = BMREQUEST_TO_DEVICE;
    3.63 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Type = BMREQUEST_STANDARD;
    3.64 +    decode_data->setup_packet.default_pipe_setup_packet.bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
    3.65 +    decode_data->setup_packet.default_pipe_setup_packet.bRequest = USB_REQUEST_GET_DESCRIPTOR;
    3.66 +    decode_data->setup_packet.default_pipe_setup_packet.wValue.LowByte = urb->UrbControlDescriptorRequest.Index;
    3.67 +    decode_data->setup_packet.default_pipe_setup_packet.wValue.HiByte = urb->UrbControlDescriptorRequest.DescriptorType;
    3.68 +    switch(urb->UrbControlDescriptorRequest.DescriptorType)
    3.69 +    {
    3.70 +    case USB_STRING_DESCRIPTOR_TYPE:
    3.71 +      decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = urb->UrbControlDescriptorRequest.LanguageId;
    3.72 +      break;
    3.73 +    default:
    3.74 +      decode_data->setup_packet.default_pipe_setup_packet.wIndex.W = 0;
    3.75 +      break;
    3.76 +    }
    3.77 +    decode_data->setup_packet.default_pipe_setup_packet.wLength = (USHORT)urb->UrbControlDescriptorRequest.TransferBufferLength;
    3.78 +    decode_data->buffer = urb->UrbControlTransfer.TransferBuffer;
    3.79 +    decode_data->length = &urb->UrbControlTransfer.TransferBufferLength;
    3.80 +    retval = URB_DECODE_COMPLETE;
    3.81 +    break;
    3.82 +  case URB_FUNCTION_CONTROL_TRANSFER:
    3.83 +  case URB_FUNCTION_CONTROL_TRANSFER_EX:
    3.84 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CONTROL_TRANSFER\n"));
    3.85 +    decode_data->buffer = urb->UrbControlTransfer.TransferBuffer;
    3.86 +    decode_data->length = &urb->UrbControlTransfer.TransferBufferLength;
    3.87 +    memcpy(decode_data->setup_packet.raw, urb->UrbControlTransfer.SetupPacket, sizeof(decode_data->setup_packet.raw));
    3.88 +    retval = URB_DECODE_COMPLETE;
    3.89 +    break;
    3.90 +#if 0
    3.91 +  case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
    3.92 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
    3.93 +    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlGetStatusRequest.TransferBufferLength));
    3.94 +    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlGetStatusRequest.TransferBuffer));
    3.95 +    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlGetStatusRequest.TransferBufferMDL));
    3.96 +    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlGetStatusRequest.Index));
    3.97 +    if (urb->UrbControlGetStatusRequest.Index == 0)
    3.98 +    {
    3.99 +      urb->UrbControlGetStatusRequest.TransferBufferLength = 2;
   3.100 +      *(PUSHORT)urb->UrbControlGetStatusRequest.TransferBuffer = 0x0003;
   3.101 +      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.102 +      WdfRequestComplete(request, STATUS_SUCCESS);
   3.103 +    }
   3.104 +    else
   3.105 +    {
   3.106 +      KdPrint((__DRIVER_NAME "     Unknown Index\n"));
   3.107 +      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   3.108 +      WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   3.109 +    }    
   3.110 +    break;
   3.111 +  case URB_FUNCTION_CLASS_DEVICE:
   3.112 +#if 1
   3.113 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_DEVICE\n"));
   3.114 +    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   3.115 +    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   3.116 +    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   3.117 +    KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   3.118 +    KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   3.119 +    KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   3.120 +    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   3.121 +#endif
   3.122 +    switch (urb->UrbControlVendorClassRequest.Request)
   3.123 +    {
   3.124 +    case USB_REQUEST_GET_DESCRIPTOR:
   3.125 +      KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_DEVICE\n"));
   3.126 +      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   3.127 +      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   3.128 +      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   3.129 +      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   3.130 +      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   3.131 +      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   3.132 +      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   3.133 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_DESCRIPTOR\n"));
   3.134 +      switch (urb->UrbControlVendorClassRequest.Value >> 8)
   3.135 +      {
   3.136 +      case 0x00:
   3.137 +#if 0      
   3.138 +        memcpy(urb->UrbControlVendorClassRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
   3.139 +        urb->UrbControlVendorClassRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
   3.140 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.141 +        WdfRequestComplete(request, STATUS_SUCCESS);
   3.142 +        break;
   3.143 +#endif
   3.144 +      case 0x29: // Hub Descriptor
   3.145 +        KdPrint((__DRIVER_NAME "       HUB_DESCRIPTOR\n"));
   3.146 +        uhd = urb->UrbControlVendorClassRequest.TransferBuffer;
   3.147 +        urb->UrbControlVendorClassRequest.TransferBufferLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
   3.148 +        uhd->bDescriptorLength = (UCHAR)urb->UrbControlVendorClassRequest.TransferBufferLength;
   3.149 +        uhd->bDescriptorType = 0x29;
   3.150 +        uhd->bNumberOfPorts = 8;
   3.151 +        uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
   3.152 +        uhd->bPowerOnToPowerGood = 1; // 2ms units
   3.153 +        uhd->bHubControlCurrent = 0;
   3.154 +        // DeviceRemovable bits (includes an extra bit at the start)
   3.155 +        uhd->bRemoveAndPowerMask[0] = 0;
   3.156 +        uhd->bRemoveAndPowerMask[1] = 0;
   3.157 +        // PortPwrCtrlMask
   3.158 +        uhd->bRemoveAndPowerMask[2] = 0xFF;
   3.159 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.160 +        WdfRequestComplete(request, STATUS_SUCCESS);
   3.161 +        break;
   3.162 +      default:
   3.163 +        KdPrint((__DRIVER_NAME "       Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
   3.164 +        urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   3.165 +        WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   3.166 +        break;
   3.167 +      }
   3.168 +      break;
   3.169 +    case USB_REQUEST_GET_STATUS:
   3.170 +      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   3.171 +      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   3.172 +      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   3.173 +      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   3.174 +      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   3.175 +      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   3.176 +      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   3.177 +      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   3.178 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_STATUS\n"));
   3.179 +      // Check that RequestTypeReservedBits == 0xA0
   3.180 +      KdPrint((__DRIVER_NAME "       GetHubStatus\n"));
   3.181 +      /* hub status */
   3.182 +      // shoud be able to get this field from somewhere else...
   3.183 +      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = 0x0000;
   3.184 +      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = 0x0000; /* no change occurred */
   3.185 +      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.186 +      WdfRequestComplete(request, STATUS_SUCCESS);
   3.187 +      break;
   3.188 +    case USB_REQUEST_CLEAR_FEATURE:
   3.189 +      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   3.190 +      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   3.191 +      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   3.192 +      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   3.193 +      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   3.194 +      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   3.195 +      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   3.196 +      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   3.197 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_CLEAR_FEATURE\n"));
   3.198 +      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.199 +      WdfRequestComplete(request, STATUS_SUCCESS);
   3.200 +      break;
   3.201 +    default:
   3.202 +      KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   3.203 +      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   3.204 +      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   3.205 +      KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   3.206 +      KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   3.207 +      KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   3.208 +      KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   3.209 +      KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   3.210 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   3.211 +      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   3.212 +      WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   3.213 +      break;
   3.214 +    }
   3.215 +    break;
   3.216 +  case URB_FUNCTION_CLASS_OTHER:
   3.217 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_OTHER\n"));
   3.218 +    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   3.219 +    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   3.220 +    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   3.221 +    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbControlVendorClassRequest.TransferBufferMDL));
   3.222 +    KdPrint((__DRIVER_NAME "      RequestTypeReservedBits = %02x\n", urb->UrbControlVendorClassRequest.RequestTypeReservedBits));
   3.223 +    KdPrint((__DRIVER_NAME "      Request = %02x\n", urb->UrbControlVendorClassRequest.Request));
   3.224 +    KdPrint((__DRIVER_NAME "      Value = %04x\n", urb->UrbControlVendorClassRequest.Value));
   3.225 +    KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   3.226 +    switch (urb->UrbControlVendorClassRequest.Request)
   3.227 +    {
   3.228 +    case USB_REQUEST_GET_STATUS:
   3.229 +      /* port status - 11.24.2.7.1 */
   3.230 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_GET_STATUS\n"));
   3.231 +      KdPrint((__DRIVER_NAME "       GetHubStatus\n"));
   3.232 +      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status;
   3.233 +      ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change;
   3.234 +      break;
   3.235 +    case USB_REQUEST_SET_FEATURE:
   3.236 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_SET_FEATURE\n"));
   3.237 +      KdPrint((__DRIVER_NAME "       SetPortFeature\n"));
   3.238 +      switch (urb->UrbControlVendorClassRequest.Value)
   3.239 +      {
   3.240 +      case PORT_ENABLE:
   3.241 +        KdPrint((__DRIVER_NAME "        PORT_ENABLE\n"));
   3.242 +        /* do something here */
   3.243 +        break;
   3.244 +      case PORT_RESET:
   3.245 +        KdPrint((__DRIVER_NAME "        PORT_RESET\n"));
   3.246 +        /* just fake the reset */
   3.247 +        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change |= (1 << PORT_RESET);
   3.248 +        break;
   3.249 +      default:
   3.250 +        KdPrint((__DRIVER_NAME "        Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
   3.251 +        break;
   3.252 +      }
   3.253 +      KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   3.254 +        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   3.255 +        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   3.256 +      break;
   3.257 +    case USB_REQUEST_CLEAR_FEATURE:
   3.258 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_CLEAR_FEATURE\n"));
   3.259 +      KdPrint((__DRIVER_NAME "       ClearPortFeature\n"));
   3.260 +      switch (urb->UrbControlVendorClassRequest.Value)
   3.261 +      {
   3.262 +      case C_PORT_CONNECTION:
   3.263 +        KdPrint((__DRIVER_NAME "        C_PORT_CONNECTION\n"));
   3.264 +        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_CONNECTION);
   3.265 +        break;
   3.266 +      case C_PORT_RESET:
   3.267 +        KdPrint((__DRIVER_NAME "        C_PORT_RESET\n"));
   3.268 +        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change &= ~(1 << PORT_RESET);
   3.269 +        break;
   3.270 +      default:
   3.271 +        KdPrint((__DRIVER_NAME "        Unknown Value %04X\n", urb->UrbControlVendorClassRequest.Value));
   3.272 +        break;
   3.273 +      }
   3.274 +      KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   3.275 +        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   3.276 +        xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   3.277 +      break;
   3.278 +    default:
   3.279 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   3.280 +      break;
   3.281 +    }
   3.282 +    //urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.283 +    //WdfRequestComplete(request, STATUS_SUCCESS);
   3.284 +    urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   3.285 +    WdfRequestComplete(request, STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL);
   3.286 +    break;
   3.287 +  case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
   3.288 +#if 1
   3.289 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
   3.290 +    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
   3.291 +    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
   3.292 +    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
   3.293 +    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
   3.294 +    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
   3.295 +#endif
   3.296 +    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   3.297 +    WdfSpinLockAcquire (endpoint->interrupt_lock);
   3.298 +    if (WdfIoQueueGetState(endpoint->interrupt_queue, NULL, NULL) & WdfIoQueueNoRequests)
   3.299 +    {
   3.300 +      status = WdfTimerStart(endpoint->interrupt_timer, WDF_REL_TIMEOUT_IN_MS(100));
   3.301 +    }
   3.302 +    status = WdfRequestForwardToIoQueue(request, endpoint->interrupt_queue);
   3.303 +    WdfSpinLockRelease(endpoint->interrupt_lock);
   3.304 +    break;
   3.305 +  case URB_FUNCTION_CONTROL_TRANSFER_EX:
   3.306 +    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)urb->UrbControlTransfer.SetupPacket;
   3.307 +#if 1
   3.308 +    FUNCTION_MSG("URB_FUNCTION_CONTROL_TRANSFER_EX\n");
   3.309 +    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbControlTransfer.PipeHandle);
   3.310 +    FUNCTION_MSG(" TransferFlags = %08x\n", urb->UrbControlTransfer.TransferFlags);
   3.311 +    FUNCTION_MSG(" TransferBufferLength = %d\n", urb->UrbControlTransfer.TransferBufferLength);
   3.312 +    FUNCTION_MSG(" TransferBuffer = %p\n", urb->UrbControlTransfer.TransferBuffer);
   3.313 +    FUNCTION_MSG(" TransferBufferMdl = %p\n", urb->UrbControlTransfer.TransferBufferMDL);
   3.314 +    FUNCTION_MSG(" Timeout = %p\n", urb->UrbControlTransfer.TransferBufferMDL);
   3.315 +    FUNCTION_MSG(" SetupPacket.bmRequestType = %02x\n", (ULONG)setup_packet->bmRequestType.B);
   3.316 +    FUNCTION_MSG(" SetupPacket.bRequest = %02x\n", (ULONG)setup_packet->bRequest);
   3.317 +    FUNCTION_MSG(" SetupPacket.wValue.LowByte = %02x\n", (ULONG)setup_packet->wValue.LowByte);
   3.318 +    FUNCTION_MSG(" SetupPacket.wValue.HiByte = %02x\n", (ULONG)setup_packet->wValue.HiByte);
   3.319 +    FUNCTION_MSG(" SetupPacket.wIndex.LowByte = %02x\n", (ULONG)setup_packet->wIndex.LowByte);
   3.320 +    FUNCTION_MSG(" SetupPacket.wIndex.HiByte = %02x\n", (ULONG)setup_packet->wIndex.HiByte);
   3.321 +    FUNCTION_MSG(" SetupPacket.wLength = %04x\n", (ULONG)setup_packet->wLength);
   3.322 +#endif
   3.323 +    switch(setup_packet->bRequest)
   3.324 +    {
   3.325 +    case USB_REQUEST_GET_STATUS:
   3.326 +      FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
   3.327 +      *(PUSHORT)urb->UrbControlDescriptorRequest.TransferBuffer = 0x0003;
   3.328 +      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.329 +      break;
   3.330 +    case USB_REQUEST_GET_DESCRIPTOR:
   3.331 +      // should be able to reuse this code...
   3.332 +      FUNCTION_MSG(" USB_REQUEST_GET_DESCRIPTOR\n");
   3.333 +      switch (setup_packet->wValue.HiByte)
   3.334 +      {
   3.335 +      case USB_DEVICE_DESCRIPTOR_TYPE:
   3.336 +        KdPrint((__DRIVER_NAME "      USB_DEVICE_DESCRIPTOR_TYPE\n"));
   3.337 +        memcpy(urb->UrbControlDescriptorRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
   3.338 +        urb->UrbControlDescriptorRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
   3.339 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.340 +        break;
   3.341 +      case USB_CONFIGURATION_DESCRIPTOR_TYPE:
   3.342 +      {
   3.343 +        xenusb_config_t *usb_config;
   3.344 +        PUCHAR ptr;
   3.345 +
   3.346 +        KdPrint((__DRIVER_NAME "      USB_CONFIGURATION_DESCRIPTOR_TYPE\n"));
   3.347 +        usb_config = usb_device->active_config;
   3.348 +        ptr = (PUCHAR)urb->UrbControlDescriptorRequest.TransferBuffer;
   3.349 +        memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
   3.350 +        ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
   3.351 +        ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
   3.352 +        if (urb->UrbControlDescriptorRequest.TransferBufferLength > 9)
   3.353 +        {
   3.354 +          for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
   3.355 +          {
   3.356 +            memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
   3.357 +            KdPrint((__DRIVER_NAME "      bInterfaceClass = %02x\n", ((PUSB_INTERFACE_DESCRIPTOR)ptr)->bInterfaceClass));
   3.358 +            ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
   3.359 +            ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
   3.360 +            for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
   3.361 +            {
   3.362 +              memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
   3.363 +              ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
   3.364 +              ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
   3.365 +            }
   3.366 +          }
   3.367 +        }
   3.368 +        urb->UrbControlDescriptorRequest.TransferBufferLength = ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength;
   3.369 +        if (urb->UrbControlDescriptorRequest.TransferBufferLength == 9)
   3.370 +          ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = 32;
   3.371 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   3.372 +        KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
   3.373 +        break;
   3.374 +      } 
   3.375 +      default:
   3.376 +        FUNCTION_MSG(" USB_%02x_DESCRIPTOR_TYPE\n", (ULONG)setup_packet->wValue.HiByte);
   3.377 +        break;
   3.378 +      }
   3.379 +      break;
   3.380 +    default:
   3.381 +      FUNCTION_MSG(" USB_REQUEST_%02x\n", (ULONG)setup_packet->bRequest);
   3.382 +      break;
   3.383 +    }
   3.384 +    KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
   3.385 +    WdfRequestComplete(request, STATUS_SUCCESS);
   3.386 +    break;
   3.387 +#endif
   3.388 +  case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
   3.389 +  case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
   3.390 +    FUNCTION_MSG("NOT_CONTROL URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
   3.391 +    retval = URB_DECODE_NOT_CONTROL;
   3.392 +    break;
   3.393 +  default:
   3.394 +    FUNCTION_MSG("URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
   3.395 +    retval = URB_DECODE_UNKNOWN;
   3.396 +    break;
   3.397 +  }
   3.398 +  FUNCTION_EXIT();
   3.399 +  return retval;
   3.400 +}
   3.401 +
     4.1 --- a/xenusb/xenusb_devurb.c	Sat Jun 04 17:39:58 2011 +1000
     4.2 +++ b/xenusb/xenusb_devurb.c	Tue Jun 07 22:37:56 2011 +1000
     4.3 @@ -169,11 +169,11 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
     4.4    UNREFERENCED_PARAMETER(output_buffer_length);
     4.5    UNREFERENCED_PARAMETER(io_control_code);
     4.6  
     4.7 -  //FUNCTION_ENTER();
     4.8 +  FUNCTION_ENTER();
     4.9  
    4.10    ASSERT(io_control_code == IOCTL_INTERNAL_USB_SUBMIT_URB);
    4.11  
    4.12 -  status = STATUS_UNSUCCESSFUL;
    4.13 +  status = STATUS_ACCESS_VIOLATION; //STATUS_UNSUCCESSFUL;
    4.14  
    4.15    WDF_REQUEST_PARAMETERS_INIT(&wrp);
    4.16    WdfRequestGetParameters(request, &wrp);
    4.17 @@ -288,7 +288,7 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    4.18      shadow->request = request;
    4.19      shadow->urb = urb;
    4.20      shadow->mdl = NULL;
    4.21 -    shadow->dma_transaction = NULL;
    4.22 +    //shadow->dma_transaction = NULL;
    4.23      shadow->callback = XenUsb_UrbCallback;
    4.24      shadow->req.id = shadow->id;
    4.25      shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
    4.26 @@ -336,7 +336,7 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    4.27      shadow->request = request;
    4.28      shadow->urb = urb;
    4.29      shadow->mdl = NULL;
    4.30 -    shadow->dma_transaction = NULL;
    4.31 +    //shadow->dma_transaction = NULL;
    4.32      shadow->callback = XenUsb_UrbCallback;
    4.33      shadow->req.id = shadow->id;
    4.34      shadow->req.pipe = LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
    4.35 @@ -492,7 +492,7 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    4.36      {
    4.37        KdPrint((__DRIVER_NAME "     Unknown Index\n"));
    4.38        urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    4.39 -      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    4.40 +      WdfRequestComplete(request, STATUS_ACCESS_VIOLATION); //STATUS_UNSUCCESSFUL);
    4.41      }    
    4.42      break;
    4.43    case URB_FUNCTION_CLASS_DEVICE:
    4.44 @@ -549,7 +549,7 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    4.45        default:
    4.46          KdPrint((__DRIVER_NAME "       Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
    4.47          urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    4.48 -        WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    4.49 +        WdfRequestComplete(request, STATUS_ACCESS_VIOLATION); //STATUS_UNSUCCESSFUL);
    4.50          break;
    4.51        }
    4.52        break;
    4.53 @@ -596,7 +596,7 @@ URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 
    4.54        KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
    4.55        KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
    4.56        urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    4.57 -      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    4.58 +      WdfRequestComplete(request, STATUS_ACCESS_VIOLATION); //STATUS_UNSUCCESSFUL);
    4.59        break;
    4.60      }
    4.61  #if 0
    4.62 @@ -781,9 +781,9 @@ URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 
    4.63      KdPrint((__DRIVER_NAME "     URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
    4.64      KdPrint((__DRIVER_NAME "     Calling WdfRequestCompletestatus with status = %08x\n", status));
    4.65      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    4.66 -    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    4.67 +    WdfRequestComplete(request, STATUS_ACCESS_VIOLATION); //STATUS_UNSUCCESSFUL);
    4.68      break;
    4.69    }
    4.70 -  //FUNCTION_EXIT();
    4.71 +  FUNCTION_EXIT();
    4.72  }
    4.73  
     5.1 --- a/xenusb/xenusb_fdo.c	Sat Jun 04 17:39:58 2011 +1000
     5.2 +++ b/xenusb/xenusb_fdo.c	Tue Jun 07 22:37:56 2011 +1000
     5.3 @@ -17,6 +17,8 @@ along with this program; if not, write t
     5.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     5.5  */
     5.6  
     5.7 +// STATUS_UNSUCCESSFUL -> STATUS_BAD_INITIAL_PC 
     5.8 +
     5.9  #include "xenusb.h"
    5.10  
    5.11  /* Not really necessary but keeps PREfast happy */
    5.12 @@ -31,54 +33,7 @@ static EVT_WDFDEVICE_WDM_IRP_PREPROCESS 
    5.13  static EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL XenUsb_EvtIoDeviceControl;
    5.14  static EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl;
    5.15  static EVT_WDF_IO_QUEUE_IO_DEFAULT XenUsb_EvtIoDefault;
    5.16 -static EVT_WDF_PROGRAM_DMA XenUsb_ExecuteRequestCallback;
    5.17 -
    5.18 -static BOOLEAN
    5.19 -XenUsb_ExecuteRequestCallback(
    5.20 -  WDFDMATRANSACTION dma_transaction,
    5.21 -  WDFDEVICE device,
    5.22 -  PVOID context,
    5.23 -  WDF_DMA_DIRECTION direction,
    5.24 -  PSCATTER_GATHER_LIST sg_list)
    5.25 -{
    5.26 -  usbif_shadow_t *shadow = context;
    5.27 -  PXENUSB_DEVICE_DATA xudd = GetXudd(device);
    5.28 -  ULONG i;
    5.29 -  int notify;
    5.30 -  KIRQL old_irql;
    5.31 -
    5.32 -  UNREFERENCED_PARAMETER(direction);
    5.33 -  UNREFERENCED_PARAMETER(dma_transaction);
    5.34 -
    5.35 -  //FUNCTION_ENTER();
    5.36 -
    5.37 -  shadow->req.buffer_length = 0;
    5.38 -  for (i = 0; i < sg_list->NumberOfElements; i++)
    5.39 -  {
    5.40 -    shadow->req.seg[i].gref = (grant_ref_t)(sg_list->Elements->Address.QuadPart >> PAGE_SHIFT);
    5.41 -    shadow->req.seg[i].offset = (USHORT)sg_list->Elements->Address.LowPart & (PAGE_SIZE - 1);
    5.42 -    shadow->req.seg[i].length = (USHORT)sg_list->Elements->Length;
    5.43 -    shadow->req.buffer_length = shadow->req.buffer_length + (USHORT)sg_list->Elements->Length;
    5.44 -  }
    5.45 -  shadow->req.nr_buffer_segs = (USHORT)sg_list->NumberOfElements;
    5.46 -  //KdPrint((__DRIVER_NAME "     buffer_length = %d\n", shadow->req.buffer_length));
    5.47 -  //KdPrint((__DRIVER_NAME "     nr_buffer_segs = %d\n", shadow->req.nr_buffer_segs));
    5.48 -
    5.49 -  KeAcquireSpinLock(&xudd->urb_ring_lock, &old_irql);
    5.50 -  *RING_GET_REQUEST(&xudd->urb_ring, xudd->urb_ring.req_prod_pvt) = shadow->req;
    5.51 -  xudd->urb_ring.req_prod_pvt++;
    5.52 -  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
    5.53 -  if (notify)
    5.54 -  {
    5.55 -    //KdPrint((__DRIVER_NAME "     Notifying\n"));
    5.56 -    xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
    5.57 -  }
    5.58 -  KeReleaseSpinLock(&xudd->urb_ring_lock, old_irql);
    5.59 -
    5.60 -  //FUNCTION_EXIT();
    5.61 -  
    5.62 -  return TRUE;
    5.63 -}
    5.64 +//static EVT_WDF_PROGRAM_DMA XenUsb_ExecuteRequestCallback;
    5.65  
    5.66  NTSTATUS
    5.67  XenUsb_ExecuteRequest(
    5.68 @@ -88,10 +43,13 @@ XenUsb_ExecuteRequest(
    5.69   PMDL transfer_buffer_mdl,
    5.70   ULONG transfer_buffer_length)
    5.71  {
    5.72 -  NTSTATUS status;
    5.73 +  NTSTATUS status = STATUS_SUCCESS;
    5.74    KIRQL old_irql;
    5.75    PMDL mdl;
    5.76 +  int i;
    5.77    int notify;
    5.78 +  ULONG remaining;
    5.79 +  USHORT offset;
    5.80    
    5.81    //FUNCTION_ENTER();
    5.82    
    5.83 @@ -100,7 +58,6 @@ XenUsb_ExecuteRequest(
    5.84    if (!transfer_buffer_length)
    5.85    {
    5.86      shadow->mdl = NULL;
    5.87 -    shadow->dma_transaction = NULL;
    5.88      shadow->req.nr_buffer_segs = 0;
    5.89      shadow->req.buffer_length = 0;
    5.90  
    5.91 @@ -127,74 +84,40 @@ XenUsb_ExecuteRequest(
    5.92    }
    5.93    else
    5.94    {
    5.95 -    if (!MmGetMdlVirtualAddress(transfer_buffer_mdl))
    5.96 -    {
    5.97 -      /* WdfDmaTransactionInitialize has a bug where it crashes on VirtualAddress == 0 */
    5.98 -      PVOID addr = MmGetSystemAddressForMdlSafe(transfer_buffer_mdl, LowPagePriority);
    5.99 -      //KdPrint((__DRIVER_NAME "     Mapping MDL with NULL VA to work around bug in WdfDmaTransactionInitialize\n"));
   5.100 -      if (!addr)
   5.101 -      {
   5.102 -        KdPrint((__DRIVER_NAME "     Could not map MDL\n"));
   5.103 -        return STATUS_INSUFFICIENT_RESOURCES;
   5.104 -      }
   5.105 -      mdl = IoAllocateMdl(addr, transfer_buffer_length, FALSE, FALSE, NULL);
   5.106 -      ASSERT(mdl);
   5.107 -      MmBuildMdlForNonPagedPool(mdl);
   5.108 -      shadow->mdl = mdl;
   5.109 -    }
   5.110 -    else
   5.111 -    {
   5.112 -      mdl = transfer_buffer_mdl;
   5.113 -      shadow->mdl = NULL;
   5.114 -    }
   5.115 -  }
   5.116 -  status = WdfDmaTransactionCreate(xudd->dma_enabler, WDF_NO_OBJECT_ATTRIBUTES, &shadow->dma_transaction);
   5.117 -  if (!NT_SUCCESS(status))
   5.118 -  {
   5.119 -    KdPrint((__DRIVER_NAME "     WdfDmaTransactionCreate status = %08x\n", status));
   5.120 -    if (shadow->mdl)
   5.121 -    {
   5.122 -      IoFreeMdl(shadow->mdl);
   5.123 -    }
   5.124 -    FUNCTION_EXIT();
   5.125 -    return status;
   5.126 +    mdl = transfer_buffer_mdl;
   5.127 +    shadow->mdl = NULL;
   5.128    }
   5.129  
   5.130 -  ASSERT(shadow->dma_transaction);  
   5.131    ASSERT(mdl);
   5.132    ASSERT(transfer_buffer_length);
   5.133  
   5.134 -  status = WdfDmaTransactionInitialize(
   5.135 -    shadow->dma_transaction,
   5.136 -    XenUsb_ExecuteRequestCallback,
   5.137 -    (shadow->req.pipe & LINUX_PIPE_DIRECTION_IN)?WdfDmaDirectionReadFromDevice:WdfDmaDirectionWriteToDevice,
   5.138 -    mdl,
   5.139 -    MmGetMdlVirtualAddress(mdl),
   5.140 -    transfer_buffer_length);
   5.141 -  if (!NT_SUCCESS(status))
   5.142 +  remaining = MmGetMdlByteCount(mdl);
   5.143 +  offset = (USHORT)MmGetMdlByteOffset(mdl);
   5.144 +  shadow->req.buffer_length = (USHORT)MmGetMdlByteCount(mdl);
   5.145 +  shadow->req.nr_buffer_segs = (USHORT)ADDRESS_AND_SIZE_TO_SPAN_PAGES(MmGetMdlVirtualAddress(mdl), MmGetMdlByteCount(mdl));
   5.146 +  for (i = 0; i < shadow->req.nr_buffer_segs; i++)
   5.147    {
   5.148 -    KdPrint((__DRIVER_NAME "     WdfDmaTransactionInitialize status = %08x\n", status));
   5.149 -    WdfObjectDelete(shadow->dma_transaction);
   5.150 -    if (shadow->mdl)
   5.151 -    {
   5.152 -      IoFreeMdl(shadow->mdl);
   5.153 -    }
   5.154 -    //FUNCTION_EXIT();
   5.155 -    return status;
   5.156 +    shadow->req.seg[i].gref = xudd->vectors.GntTbl_GrantAccess(xudd->vectors.context, 0,
   5.157 +         (ULONG)MmGetMdlPfnArray(mdl)[i], FALSE, INVALID_GRANT_REF, (ULONG)'XUSB');
   5.158 +    shadow->req.seg[i].offset = (USHORT)offset;
   5.159 +    shadow->req.seg[i].length = (USHORT)min(remaining, PAGE_SIZE);
   5.160 +    offset = 0;
   5.161 +    remaining -= shadow->req.seg[i].length;
   5.162    }
   5.163 -  WdfDmaTransactionSetMaximumLength(shadow->dma_transaction, (USBIF_MAX_SEGMENTS_PER_REQUEST - 1) * PAGE_SIZE);
   5.164 -  status = WdfDmaTransactionExecute(shadow->dma_transaction, shadow);
   5.165 -  if (!NT_SUCCESS(status))
   5.166 +  //KdPrint((__DRIVER_NAME "     buffer_length = %d\n", shadow->req.buffer_length));
   5.167 +  //KdPrint((__DRIVER_NAME "     nr_buffer_segs = %d\n", shadow->req.nr_buffer_segs));
   5.168 +
   5.169 +  KeAcquireSpinLock(&xudd->urb_ring_lock, &old_irql);
   5.170 +  *RING_GET_REQUEST(&xudd->urb_ring, xudd->urb_ring.req_prod_pvt) = shadow->req;
   5.171 +  xudd->urb_ring.req_prod_pvt++;
   5.172 +  RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&xudd->urb_ring, notify);
   5.173 +  if (notify)
   5.174    {
   5.175 -    KdPrint((__DRIVER_NAME "     WdfDmaTransactionExecute status = %08x\n", status));
   5.176 -    WdfObjectDelete(shadow->dma_transaction);
   5.177 -    if (shadow->mdl)
   5.178 -    {
   5.179 -      IoFreeMdl(shadow->mdl);
   5.180 -    }
   5.181 -    //FUNCTION_EXIT();
   5.182 -    return status;
   5.183 +    //KdPrint((__DRIVER_NAME "     Notifying\n"));
   5.184 +    xudd->vectors.EvtChn_Notify(xudd->vectors.context, xudd->event_channel);
   5.185    }
   5.186 +  KeReleaseSpinLock(&xudd->urb_ring_lock, old_irql);
   5.187 +  
   5.188    //FUNCTION_EXIT();
   5.189    return status;
   5.190  }
   5.191 @@ -225,6 +148,8 @@ XenUsb_EvtDeviceWdmIrpPreprocessQUERY_IN
   5.192      KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_GUID\n"));
   5.193    else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_USBDI_GUID, sizeof(GUID)) == 0)
   5.194      KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_USBDI_GUID\n"));
   5.195 +  else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &GUID_TRANSLATOR_INTERFACE_STANDARD, sizeof(GUID)) == 0)
   5.196 +    KdPrint((__DRIVER_NAME "     GUID_TRANSLATOR_INTERFACE_STANDARD\n"));
   5.197    else
   5.198      KdPrint((__DRIVER_NAME "     GUID = %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
   5.199        stack->Parameters.QueryInterface.InterfaceType->Data1,
   5.200 @@ -365,33 +290,20 @@ XenUsb_HandleEvent(PVOID context)
   5.201    shadow = complete_head;
   5.202    while (shadow != NULL)
   5.203    {
   5.204 -    if (shadow->dma_transaction)
   5.205 +    if (shadow->req.buffer_length)
   5.206      {
   5.207 -      NTSTATUS status;
   5.208 -      BOOLEAN dma_complete;
   5.209 -      if (shadow->rsp.status != 0 || shadow->rsp.actual_length != shadow->req.buffer_length)
   5.210 +      int i;
   5.211 +      for (i = 0; i < shadow->req.nr_buffer_segs; i++)
   5.212        {
   5.213 -        WdfDmaTransactionDmaCompletedFinal(shadow->dma_transaction, shadow->total_length, &status);
   5.214 -        WdfObjectDelete(shadow->dma_transaction);
   5.215 -        if (shadow->mdl)
   5.216 -        {
   5.217 -          IoFreeMdl(shadow->mdl);
   5.218 -        }
   5.219 -        shadow->callback(shadow);
   5.220 +        xudd->vectors.GntTbl_EndAccess(xudd->vectors.context,
   5.221 +          shadow->req.seg[i].gref, FALSE, (ULONG)'XUSB');        
   5.222        }
   5.223 -      else
   5.224 +      // free grant refs
   5.225 +      if (shadow->mdl)
   5.226        {
   5.227 -        dma_complete = WdfDmaTransactionDmaCompleted(shadow->dma_transaction, &status);
   5.228 -        if (dma_complete)
   5.229 -        {
   5.230 -          WdfObjectDelete(shadow->dma_transaction);
   5.231 -          if (shadow->mdl)
   5.232 -          {
   5.233 -            IoFreeMdl(shadow->mdl);
   5.234 -          }
   5.235 -          shadow->callback(shadow);
   5.236 -        }
   5.237 +        IoFreeMdl(shadow->mdl);
   5.238        }
   5.239 +      shadow->callback(shadow);
   5.240      }
   5.241      else
   5.242      {
   5.243 @@ -431,7 +343,7 @@ XenUsb_StartXenbusInit(PXENUSB_DEVICE_DA
   5.244          KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
   5.245            ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
   5.246          KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   5.247 -        return STATUS_UNSUCCESSFUL;
   5.248 +        return STATUS_BAD_INITIAL_PC;
   5.249        }
   5.250        else
   5.251          memcpy(&xudd->vectors, value, sizeof(XENPCI_VECTORS));
   5.252 @@ -501,7 +413,7 @@ XenUsb_CompleteXenbusInit(PXENUSB_DEVICE
   5.253    {
   5.254      KdPrint((__DRIVER_NAME "     Missing settings\n"));
   5.255      KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   5.256 -    return STATUS_UNSUCCESSFUL;
   5.257 +    return STATUS_BAD_INITIAL_PC;
   5.258    }
   5.259    
   5.260    xudd->shadow_free = 0;
   5.261 @@ -875,7 +787,7 @@ XenUsb_EvtIoDeviceControl(
   5.262  
   5.263    FUNCTION_ENTER();
   5.264  
   5.265 -  status = STATUS_UNSUCCESSFUL;
   5.266 +  status = STATUS_BAD_INITIAL_PC;
   5.267  
   5.268    //WDF_REQUEST_PARAMETERS_INIT(&wrp);
   5.269    //WdfRequestGetParameters(request, &wrp);
   5.270 @@ -918,7 +830,7 @@ XenUsb_EvtIoDeviceControl(
   5.271          break;
   5.272        case UsbMIParent:
   5.273          KdPrint((__DRIVER_NAME "      NodeType = UsbMIParent\n"));
   5.274 -        status = STATUS_UNSUCCESSFUL;
   5.275 +        status = STATUS_BAD_INITIAL_PC;
   5.276          break;
   5.277        }
   5.278      }
   5.279 @@ -1087,7 +999,7 @@ XenUsb_EvtIoInternalDeviceControl(
   5.280    UNREFERENCED_PARAMETER(input_buffer_length);
   5.281    UNREFERENCED_PARAMETER(output_buffer_length);
   5.282  
   5.283 -  //FUNCTION_ENTER();
   5.284 +  FUNCTION_ENTER();
   5.285  
   5.286    WDF_REQUEST_PARAMETERS_INIT(&wrp);
   5.287    WdfRequestGetParameters(request, &wrp);
   5.288 @@ -1106,7 +1018,7 @@ XenUsb_EvtIoInternalDeviceControl(
   5.289      WdfRequestComplete(request, WdfRequestGetStatus(request));
   5.290      break;
   5.291    }
   5.292 -  //FUNCTION_EXIT();
   5.293 +  FUNCTION_EXIT();
   5.294  }
   5.295  
   5.296  static VOID
   5.297 @@ -1121,7 +1033,7 @@ XenUsb_EvtIoDefault(
   5.298  
   5.299    UNREFERENCED_PARAMETER(queue);
   5.300  
   5.301 -  status = STATUS_UNSUCCESSFUL;
   5.302 +  status = STATUS_BAD_INITIAL_PC;
   5.303  
   5.304    WDF_REQUEST_PARAMETERS_INIT(&parameters);
   5.305    WdfRequestGetParameters(request, &parameters);
   5.306 @@ -1168,7 +1080,6 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   5.307    WDF_PNPPOWER_EVENT_CALLBACKS pnp_power_callbacks;
   5.308    WDF_DEVICE_POWER_CAPABILITIES power_capabilities;
   5.309    WDF_IO_QUEUE_CONFIG queue_config;
   5.310 -  WDF_DMA_ENABLER_CONFIG dma_config;
   5.311    UCHAR pnp_minor_functions[] = { IRP_MN_QUERY_INTERFACE };
   5.312    
   5.313    UNREFERENCED_PARAMETER(driver);
   5.314 @@ -1218,16 +1129,8 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   5.315  
   5.316    KeInitializeSpinLock(&xudd->urb_ring_lock);
   5.317    
   5.318 -  WdfDeviceSetAlignmentRequirement(device, 0);
   5.319 -  WDF_DMA_ENABLER_CONFIG_INIT(&dma_config, WdfDmaProfileScatterGather64Duplex, PAGE_SIZE);
   5.320 -  status = WdfDmaEnablerCreate(device, &dma_config, WDF_NO_OBJECT_ATTRIBUTES, &xudd->dma_enabler);
   5.321 -  if (!NT_SUCCESS(status))
   5.322 -  {
   5.323 -    KdPrint(("Error creating DMA enabler %08x\n", status));
   5.324 -    return status;
   5.325 -  }
   5.326 -
   5.327    WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queue_config, WdfIoQueueDispatchParallel);
   5.328 +  queue_config.PowerManaged = FALSE; /* ? */
   5.329    queue_config.EvtIoDeviceControl = XenUsb_EvtIoDeviceControl;
   5.330    queue_config.EvtIoInternalDeviceControl = XenUsb_EvtIoInternalDeviceControl;
   5.331    queue_config.EvtIoDefault = XenUsb_EvtIoDefault;
   5.332 @@ -1241,7 +1144,7 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   5.333    power_capabilities.DeviceD1 = WdfTrue;
   5.334    power_capabilities.WakeFromD1 = WdfTrue;
   5.335    power_capabilities.DeviceWake = PowerDeviceD1;
   5.336 -  power_capabilities.DeviceState[PowerSystemWorking]   = PowerDeviceD1;
   5.337 +  power_capabilities.DeviceState[PowerSystemWorking]   = PowerDeviceD0;
   5.338    power_capabilities.DeviceState[PowerSystemSleeping1] = PowerDeviceD1;
   5.339    power_capabilities.DeviceState[PowerSystemSleeping2] = PowerDeviceD2;
   5.340    power_capabilities.DeviceState[PowerSystemSleeping3] = PowerDeviceD2;
   5.341 @@ -1262,8 +1165,6 @@ XenUsb_EvtDriverDeviceAdd(WDFDRIVER driv
   5.342    if (!NT_SUCCESS(status))
   5.343      return status;
   5.344  
   5.345 -  //status = WdfDeviceOpenRegistryKey(device, 
   5.346 -  
   5.347    FUNCTION_EXIT();
   5.348    return status;
   5.349  }
     6.1 --- a/xenusb/xenusb_hub.c	Sat Jun 04 17:39:58 2011 +1000
     6.2 +++ b/xenusb/xenusb_hub.c	Tue Jun 07 22:37:56 2011 +1000
     6.3 @@ -17,8 +17,19 @@ along with this program; if not, write t
     6.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     6.5  */
     6.6  
     6.7 +// STATUS_UNSUCCESSUFL -> STATUS_BAD_INITIAL_STACK 
     6.8 +
     6.9  #include "xenusb.h"
    6.10  #include <stdlib.h>
    6.11 +#include <usbioctl.h>
    6.12 +
    6.13 +typedef struct _USB_START_FAILDATA {
    6.14 +  ULONG LengthInBytes;
    6.15 +  NTSTATUS NtStatus;
    6.16 +  USBD_STATUS UsbdStatus;
    6.17 +  ULONG ConnectStatus;
    6.18 +  UCHAR DriverData[4];
    6.19 +} USB_START_FAILDATA, *PUSB_START_FAILDATA;
    6.20  
    6.21  #pragma warning(disable: 4127) // conditional expression is constant
    6.22  
    6.23 @@ -48,6 +59,50 @@ static USB_BUSIFFN_ROOTHUB_INIT_NOTIFY X
    6.24  static USB_BUSIFFN_FLUSH_TRANSFERS XenUsbHub_UBIH_FlushTransfers;
    6.25  static USB_BUSIFFN_SET_DEVHANDLE_DATA XenUsbHub_UBIH_SetDeviceHandleData;
    6.26  
    6.27 +static NTSTATUS
    6.28 +XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE(WDFDEVICE device, PIRP irp)
    6.29 +{
    6.30 +  PIO_STACK_LOCATION stack;
    6.31 + 
    6.32 +  FUNCTION_ENTER();
    6.33 + 
    6.34 +  stack = IoGetCurrentIrpStackLocation(irp);
    6.35 +
    6.36 +  if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_GUID, sizeof(GUID)) == 0)
    6.37 +    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_GUID\n"));
    6.38 +  else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_USBDI_GUID, sizeof(GUID)) == 0)
    6.39 +    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_USBDI_GUID\n"));
    6.40 +  else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &GUID_TRANSLATOR_INTERFACE_STANDARD, sizeof(GUID)) == 0)
    6.41 +    KdPrint((__DRIVER_NAME "     GUID_TRANSLATOR_INTERFACE_STANDARD\n"));
    6.42 +  else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_MINIDUMP_GUID, sizeof(GUID)) == 0)
    6.43 +    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_MINIDUMP_GUID\n"));
    6.44 +  else if (memcmp(stack->Parameters.QueryInterface.InterfaceType, &USB_BUS_INTERFACE_HUB_SS_GUID, sizeof(GUID)) == 0)
    6.45 +    KdPrint((__DRIVER_NAME "     USB_BUS_INTERFACE_HUB_SS_GUID\n"));
    6.46 +  else
    6.47 +    KdPrint((__DRIVER_NAME "     GUID = %08X-%04X-%04X-%04X-%02X%02X%02X%02X%02X%02X\n",
    6.48 +      stack->Parameters.QueryInterface.InterfaceType->Data1,
    6.49 +      stack->Parameters.QueryInterface.InterfaceType->Data2,
    6.50 +      stack->Parameters.QueryInterface.InterfaceType->Data3,
    6.51 +      (stack->Parameters.QueryInterface.InterfaceType->Data4[0] << 8) |
    6.52 +       stack->Parameters.QueryInterface.InterfaceType->Data4[1],
    6.53 +      stack->Parameters.QueryInterface.InterfaceType->Data4[2],
    6.54 +      stack->Parameters.QueryInterface.InterfaceType->Data4[3],
    6.55 +      stack->Parameters.QueryInterface.InterfaceType->Data4[4],
    6.56 +      stack->Parameters.QueryInterface.InterfaceType->Data4[5],
    6.57 +      stack->Parameters.QueryInterface.InterfaceType->Data4[6],
    6.58 +      stack->Parameters.QueryInterface.InterfaceType->Data4[7]));
    6.59 +
    6.60 +  KdPrint((__DRIVER_NAME "     Size = %d\n", stack->Parameters.QueryInterface.Size));
    6.61 +  KdPrint((__DRIVER_NAME "     Version = %d\n", stack->Parameters.QueryInterface.Version));
    6.62 +  KdPrint((__DRIVER_NAME "     Interface = %p\n", stack->Parameters.QueryInterface.Interface));
    6.63 +
    6.64 +  IoSkipCurrentIrpStackLocation(irp);
    6.65 +  
    6.66 +  FUNCTION_EXIT();
    6.67 +
    6.68 +  return WdfDeviceWdmDispatchPreprocessedIrp(device, irp);
    6.69 +}
    6.70 +
    6.71  static VOID
    6.72  XenUsbHub_EvtIoDefault(
    6.73    WDFQUEUE queue,
    6.74 @@ -60,7 +115,7 @@ XenUsbHub_EvtIoDefault(
    6.75  
    6.76    UNREFERENCED_PARAMETER(queue);
    6.77  
    6.78 -  status = STATUS_UNSUCCESSFUL;
    6.79 +  status = STATUS_BAD_INITIAL_STACK;
    6.80  
    6.81    WDF_REQUEST_PARAMETERS_INIT(&parameters);
    6.82    WdfRequestGetParameters(request, &parameters);
    6.83 @@ -90,6 +145,7 @@ XenUsbHub_EvtIoDefault(
    6.84      KdPrint((__DRIVER_NAME "     Unknown type %x\n", parameters.Type));
    6.85      break;
    6.86    }
    6.87 +  FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
    6.88    WdfRequestComplete(request, status);  
    6.89  
    6.90    FUNCTION_EXIT();
    6.91 @@ -107,6 +163,7 @@ XenUsbHub_BusIrpCompletionRoutine(
    6.92  
    6.93    FUNCTION_ENTER();
    6.94  
    6.95 +  FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
    6.96    WdfRequestCompleteWithInformation(request, irp->IoStatus.Status, irp->IoStatus.Information);
    6.97    IoFreeIrp(irp);
    6.98  
    6.99 @@ -184,7 +241,7 @@ XenUsbHub_EvtIoDeviceControl(
   6.100      KdPrint((__DRIVER_NAME "     Unknown IOCTL %08x\n", io_control_code));
   6.101      break;
   6.102    }
   6.103 -  KdPrint((__DRIVER_NAME "     Calling WdfRequestComplete with status = %08x\n", status));
   6.104 +  FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n");
   6.105    WdfRequestComplete(request, status);
   6.106  
   6.107    FUNCTION_EXIT();
   6.108 @@ -203,12 +260,15 @@ XenUsbHub_EvtIoInternalDeviceControl(
   6.109    PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
   6.110    WDF_REQUEST_PARAMETERS wrp;
   6.111    PURB urb;
   6.112 +  PUSB_START_FAILDATA usfd;
   6.113 +  PHUB_DEVICE_CONFIG_INFO hdci;
   6.114 +  PUSB_TOPOLOGY_ADDRESS uta;
   6.115    xenusb_device_t *usb_device;
   6.116  
   6.117    UNREFERENCED_PARAMETER(input_buffer_length);
   6.118    UNREFERENCED_PARAMETER(output_buffer_length);
   6.119  
   6.120 -  //FUNCTION_ENTER();
   6.121 +  FUNCTION_ENTER();
   6.122  
   6.123    status = STATUS_UNSUCCESSFUL;
   6.124  
   6.125 @@ -260,6 +320,7 @@ XenUsbHub_EvtIoInternalDeviceControl(
   6.126      KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION\n"));
   6.127      break;
   6.128    case IOCTL_INTERNAL_USB_SUBMIT_URB:
   6.129 +    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_SUBMIT_URB\n"));
   6.130      urb = (PURB)wrp.Parameters.Others.Arg1;
   6.131      ASSERT(urb);
   6.132      usb_device = urb->UrbHeader.UsbdDeviceHandle;
   6.133 @@ -268,19 +329,69 @@ XenUsbHub_EvtIoInternalDeviceControl(
   6.134      WdfRequestForwardToIoQueue(request, usb_device->urb_queue);
   6.135      return;
   6.136    case IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE:
   6.137 -    KdPrint((__DRIVER_NAME "     IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE (returning %p)\n", xupdd->usb_device));
   6.138 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE (returning %p)\n", xupdd->usb_device);
   6.139      *(PVOID *)wrp.Parameters.Others.Arg1 = xupdd->usb_device;
   6.140      status = STATUS_SUCCESS;
   6.141      break;
   6.142 +  case IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE_EX: /* incomplete probably */
   6.143 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE_EX (returning %p)\n", xupdd->usb_device);
   6.144 +    *(PVOID *)wrp.Parameters.Others.Arg1 = xupdd->usb_device;
   6.145 +    *(ULONG_PTR *)wrp.Parameters.Others.Arg2 = (ULONG_PTR)0x123456789ABCDEF;
   6.146 +    status = STATUS_SUCCESS;
   6.147 +    break;
   6.148 +  case IOCTL_INTERNAL_USB_GET_TOPOLOGY_ADDRESS:
   6.149 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_TOPOLOGY_ADDRESS\n");
   6.150 +    uta = (PUSB_TOPOLOGY_ADDRESS)wrp.Parameters.Others.Arg1;
   6.151 +    uta->PciBusNumber = 0;
   6.152 +    uta->PciDeviceNumber = 0;
   6.153 +    uta->PciFunctionNumber = 0;
   6.154 +    uta->RootHubPortNumber = 0;
   6.155 +    uta->HubPortNumber[1] = 0;
   6.156 +    uta->HubPortNumber[2] = 0;
   6.157 +    uta->HubPortNumber[3] = 0;
   6.158 +    uta->HubPortNumber[4] = 0;
   6.159 +    status = STATUS_SUCCESS;
   6.160 +    break;
   6.161 +  case IOCTL_INTERNAL_USB_GET_DEVICE_CONFIG_INFO:
   6.162 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_GET_DEVICE_CONFIG_INFO\n");
   6.163 +    hdci = (PHUB_DEVICE_CONFIG_INFO)wrp.Parameters.Others.Arg1;
   6.164 +    hdci->Version = 1;
   6.165 +    hdci->Length = 192;
   6.166 +    hdci->HubFlags.ul = 0;
   6.167 +    hdci->HubFlags.HubIsHighSpeedCapable = 1;
   6.168 +    hdci->HubFlags.HubIsHighSpeed = 1;
   6.169 +    hdci->HubFlags.HubIsMultiTtCapable = 0;
   6.170 +    hdci->HubFlags.HubIsMultiTt = 0;
   6.171 +    hdci->HubFlags.HubIsRoot = 1;
   6.172 +    hdci->HubFlags.HubIsArmedWakeOnConnect = 1;
   6.173 +    hdci->HubFlags.HubIsBusPowered = 1;
   6.174 +    //hdci->HardwareIds = ?;
   6.175 +    //hdci->CompatibleIds = ?;
   6.176 +    //hdci->DeviceDescription = ?;
   6.177 +    status = STATUS_SUCCESS;
   6.178 +    break;
   6.179 +  case IOCTL_INTERNAL_USB_RECORD_FAILURE:
   6.180 +    FUNCTION_MSG("IOCTL_INTERNAL_USB_RECORD_FAILURE\n");
   6.181 +    usfd = (PUSB_START_FAILDATA)wrp.Parameters.Others.Arg1;
   6.182 +    FUNCTION_MSG(" LengthInBytes = %d\n", usfd->LengthInBytes);
   6.183 +    FUNCTION_MSG(" NtStatus = %08x\n", usfd->NtStatus);
   6.184 +    FUNCTION_MSG(" UsbdStatus = %08x\n", usfd->UsbdStatus);
   6.185 +    FUNCTION_MSG(" ConnectStatus = %08x\n", usfd->ConnectStatus);
   6.186 +    FUNCTION_MSG(" DriverData[0] = %s\n", usfd->DriverData);
   6.187 +    FUNCTION_MSG(" DriverData[0] = %S\n", usfd->DriverData);
   6.188 +    FUNCTION_MSG(" DriverData[5] = %s\n", &usfd->DriverData[5]);
   6.189 +    FUNCTION_MSG(" DriverData[5] = %S\n", &usfd->DriverData[5]);
   6.190 +    status = STATUS_SUCCESS;
   6.191 +    break;  
   6.192    default:
   6.193 -    KdPrint((__DRIVER_NAME "     Unknown IOCTL %08x\n", io_control_code));
   6.194 +    FUNCTION_MSG("Unknown IOCTL %08x\n", io_control_code);
   6.195      break;
   6.196    }  
   6.197  
   6.198 -  KdPrint((__DRIVER_NAME "     Calling WdfRequestComplete with status = %08x\n", status));
   6.199 +  FUNCTION_MSG("Calling WdfRequestComplete with status = %08x\n", status);
   6.200    WdfRequestComplete(request, status);
   6.201  
   6.202 -  //FUNCTION_EXIT();
   6.203 +  FUNCTION_EXIT();
   6.204  }
   6.205  
   6.206  static NTSTATUS
   6.207 @@ -779,7 +890,7 @@ XenUsbHub_UBIH_RestoreUsbDevice(
   6.208    PUSB_DEVICE_HANDLE OldDeviceHandle,
   6.209    PUSB_DEVICE_HANDLE NewDeviceHandle)
   6.210  {
   6.211 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.212 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.213  
   6.214    UNREFERENCED_PARAMETER(BusContext);
   6.215    UNREFERENCED_PARAMETER(OldDeviceHandle);
   6.216 @@ -796,7 +907,7 @@ XenUsbHub_UBIH_GetPortHackFlags(
   6.217   PVOID BusContext,
   6.218   PULONG HackFlags)
   6.219  {
   6.220 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.221 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.222  
   6.223    UNREFERENCED_PARAMETER(BusContext);
   6.224    UNREFERENCED_PARAMETER(HackFlags);
   6.225 @@ -869,7 +980,7 @@ XenUsbHub_UBIH_GetControllerInformation 
   6.226    ULONG ControllerInformationBufferLength,
   6.227    PULONG LengthOfDataReturned)
   6.228  {
   6.229 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.230 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.231    PUSB_CONTROLLER_INFORMATION_0 uci = ControllerInformationBuffer;
   6.232    //WDFDEVICE device = BusContext;
   6.233    //xenusb_device_t *usb_device = DeviceHandle;
   6.234 @@ -909,7 +1020,7 @@ XenUsbHub_UBIH_ControllerSelectiveSuspen
   6.235    PVOID BusContext,
   6.236    BOOLEAN Enable)
   6.237  {
   6.238 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.239 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.240  
   6.241    UNREFERENCED_PARAMETER(BusContext);
   6.242    UNREFERENCED_PARAMETER(Enable);
   6.243 @@ -1074,13 +1185,284 @@ XenUsbHub_UBIH_SetDeviceHandleData(
   6.244  }
   6.245  
   6.246  static NTSTATUS
   6.247 +XenUsbHub_UBIH_CreateUsbDeviceEx(
   6.248 +  PVOID BusContext,
   6.249 +  PUSB_DEVICE_HANDLE *DeviceHandle,
   6.250 +  PUSB_DEVICE_HANDLE *HubDeviceHandle,
   6.251 +  USHORT PortStatus,
   6.252 +  USHORT PortNumber,
   6.253 +  PUSB_CD_ERROR_INFORMATION CdErrorInfo,
   6.254 +  USHORT TtPortNumber)
   6.255 +{
   6.256 +  NTSTATUS status = STATUS_SUCCESS;
   6.257 +  
   6.258 +  UNREFERENCED_PARAMETER(CdErrorInfo);  
   6.259 +  UNREFERENCED_PARAMETER(TtPortNumber);
   6.260 +  
   6.261 +  FUNCTION_ENTER();
   6.262 +
   6.263 +  status = XenUsbHub_UBIH_CreateUsbDevice(BusContext, DeviceHandle, HubDeviceHandle, PortStatus, PortNumber);
   6.264 +  
   6.265 +  KdPrint((__DRIVER_NAME "     CdErrorInfo = %p\n", CdErrorInfo));
   6.266 +  KdPrint((__DRIVER_NAME "     TtPortNumber = %d\n", TtPortNumber));
   6.267 +  
   6.268 +  FUNCTION_EXIT();
   6.269 +  return status;
   6.270 +}
   6.271 +
   6.272 +static NTSTATUS
   6.273 +XenUsbHub_UBIH_InitializeUsbDeviceEx(
   6.274 + PVOID BusContext,
   6.275 + PUSB_DEVICE_HANDLE DeviceHandle,
   6.276 + PUSB_ID_ERROR_INFORMATION IdErrInfo)
   6.277 +{
   6.278 +  NTSTATUS status;
   6.279 +  FUNCTION_ENTER();
   6.280 +  FUNCTION_MSG("IdErrInfo->Version = %d\n", IdErrInfo->Version);
   6.281 +  FUNCTION_MSG("IdErrInfo->PathError = %d\n", IdErrInfo->PathError);
   6.282 +  FUNCTION_MSG("IdErrInfo->Arg1 = %08x\n", IdErrInfo->Arg1);
   6.283 +  FUNCTION_MSG("IdErrInfo->UsbAddress = %d\n", IdErrInfo->UsbAddress);
   6.284 +  FUNCTION_MSG("IdErrInfo->NtStatus = %08x\n", IdErrInfo->NtStatus);
   6.285 +  FUNCTION_MSG("IdErrInfo->UsbdStatus = %08x\n", IdErrInfo->UsbdStatus);
   6.286 +  FUNCTION_MSG("IdErrInfo->XtraInfo = %s\n", IdErrInfo->XtraInfo);
   6.287 +  status = XenUsbHub_UBIH_InitializeUsbDevice(BusContext, DeviceHandle);
   6.288 +  FUNCTION_EXIT();
   6.289 +  return status;
   6.290 +}
   6.291 +
   6.292 +static BOOLEAN
   6.293 +XenUsbHub_UBIH_HubIsRoot(
   6.294 +  PVOID BusContext,
   6.295 +  PVOID DeviceObject)
   6.296 +{
   6.297 +  UNREFERENCED_PARAMETER(BusContext);
   6.298 +  UNREFERENCED_PARAMETER(DeviceObject);
   6.299 +  
   6.300 +  FUNCTION_ENTER();
   6.301 +  FUNCTION_EXIT();
   6.302 +  return TRUE;
   6.303 +}
   6.304 +
   6.305 +static VOID
   6.306 +XenUsbHub_UBIH_AcquireBusSemaphore(
   6.307 +  PVOID BusContext)
   6.308 +{
   6.309 +  UNREFERENCED_PARAMETER(BusContext);
   6.310 +  FUNCTION_ENTER();
   6.311 +  FUNCTION_EXIT();
   6.312 +  return;
   6.313 +}
   6.314 +
   6.315 +static VOID
   6.316 +XenUsbHub_UBIH_ReleaseBusSemaphore(
   6.317 +  PVOID BusContext)
   6.318 +{
   6.319 +  UNREFERENCED_PARAMETER(BusContext);
   6.320 +  FUNCTION_ENTER();
   6.321 +  FUNCTION_EXIT();
   6.322 +  return;
   6.323 +}
   6.324 +
   6.325 +static ULONG
   6.326 +XenUsbHub_UBIH_CaculatePipeBandwidth(
   6.327 +  PVOID BusContext,
   6.328 +  PUSBD_PIPE_INFORMATION PipeInfo,
   6.329 +  USB_DEVICE_SPEED DeviceSpeed)
   6.330 +{
   6.331 +  UNREFERENCED_PARAMETER(BusContext);
   6.332 +  FUNCTION_ENTER();
   6.333 +  FUNCTION_EXIT();
   6.334 +  return (ULONG)-1;
   6.335 +}
   6.336 +
   6.337 +static VOID
   6.338 +XenUsbHub_UBIH_SetBusSystemWakeMode(
   6.339 +  PVOID BusContext,
   6.340 +  ULONG Mode)
   6.341 +{
   6.342 +  UNREFERENCED_PARAMETER(BusContext);
   6.343 +  FUNCTION_ENTER();
   6.344 +  FUNCTION_EXIT();
   6.345 +  return;
   6.346 +}
   6.347 +
   6.348 +static VOID
   6.349 +XenUsbHub_UBIH_SetDeviceFlag(
   6.350 +  PVOID BusContext,
   6.351 +  GUID *DeviceFlagGuid,
   6.352 +  PVOID ValueData,
   6.353 +  ULONG ValueLength)
   6.354 +{
   6.355 +  UNREFERENCED_PARAMETER(BusContext);
   6.356 +  FUNCTION_ENTER();
   6.357 +  FUNCTION_EXIT();
   6.358 +  return;
   6.359 +}
   6.360 +
   6.361 +static NTSTATUS
   6.362 +XenUsbHub_UBIH_HubTestPoint(
   6.363 +  PVOID bus_context,
   6.364 +  PVOID device_handle,
   6.365 +  ULONG op_code,
   6.366 +  PVOID test_data)
   6.367 +{
   6.368 +  UNREFERENCED_PARAMETER(bus_context);
   6.369 +  FUNCTION_ENTER();
   6.370 +  FUNCTION_MSG("device_handle = %p\n", device_handle);
   6.371 +  FUNCTION_MSG("op_code = %p\n", op_code);
   6.372 +  FUNCTION_MSG("test_data = %p\n", test_data);
   6.373 +  FUNCTION_EXIT();
   6.374 +  return STATUS_SUCCESS;
   6.375 +}
   6.376 +
   6.377 +static NTSTATUS
   6.378 +XenUsbHub_UBIH_GetDevicePerformanceInfo(
   6.379 +  PVOID BusContext,
   6.380 +  PUSB_DEVICE_HANDLE DeviceHandle,
   6.381 +  PVOID DeviceInformationBuffer,
   6.382 +  ULONG DeviceInformationBufferLength,
   6.383 +  PULONG LengthOfDataCopied)
   6.384 +{
   6.385 +  UNREFERENCED_PARAMETER(BusContext);
   6.386 +  FUNCTION_ENTER();
   6.387 +  FUNCTION_EXIT();
   6.388 +  return STATUS_BAD_INITIAL_STACK;
   6.389 +}
   6.390 +
   6.391 +static NTSTATUS
   6.392 +XenUsbHub_UBIH_WaitAsyncPowerUp(
   6.393 +  PVOID BusContext)
   6.394 +{
   6.395 +  UNREFERENCED_PARAMETER(BusContext);
   6.396 +  FUNCTION_ENTER();
   6.397 +  FUNCTION_EXIT();
   6.398 +  return STATUS_BAD_INITIAL_STACK;
   6.399 +}
   6.400 +
   6.401 +static NTSTATUS
   6.402 +XenUsbHub_UBIH_GetDeviceAddress(
   6.403 +  PVOID BusContext,
   6.404 +  PUSB_DEVICE_HANDLE DeviceHandle,
   6.405 +  PUSHORT DeviceAddress)
   6.406 +{
   6.407 +  UNREFERENCED_PARAMETER(BusContext);
   6.408 +  FUNCTION_ENTER();
   6.409 +  FUNCTION_EXIT();
   6.410 +  return STATUS_BAD_INITIAL_STACK;
   6.411 +}
   6.412 +
   6.413 +static NTSTATUS
   6.414 +XenUsbHub_UBIH_RefDeviceHandle(
   6.415 +  PVOID BusContext,
   6.416 +  PUSB_DEVICE_HANDLE DeviceHandle,
   6.417 +  PVOID Object,
   6.418 +  ULONG Tag)
   6.419 +{
   6.420 +  UNREFERENCED_PARAMETER(BusContext);
   6.421 +  FUNCTION_ENTER();
   6.422 +  FUNCTION_EXIT();
   6.423 +  return STATUS_BAD_INITIAL_STACK;
   6.424 +}
   6.425 +
   6.426 +static NTSTATUS
   6.427 +XenUsbHub_UBIH_DerefDeviceHandle(
   6.428 +  PVOID BusContext,
   6.429 +  PUSB_DEVICE_HANDLE DeviceHandle,
   6.430 +  PVOID Object,
   6.431 +  ULONG Tag)
   6.432 +{
   6.433 +  UNREFERENCED_PARAMETER(BusContext);
   6.434 +  FUNCTION_ENTER();
   6.435 +  FUNCTION_MSG("This should do something\n");
   6.436 +  FUNCTION_EXIT();
   6.437 +  return STATUS_SUCCESS;
   6.438 +}
   6.439 +
   6.440 +static ULONG
   6.441 +XenUsbHub_UBIH_SetDeviceHandleIdleReadyState(
   6.442 +  PVOID BusContext,
   6.443 +  PUSB_DEVICE_HANDLE DeviceHandle,
   6.444 +  ULONG NewIdleReadyState)
   6.445 +{
   6.446 +  UNREFERENCED_PARAMETER(BusContext);
   6.447 +  FUNCTION_ENTER();
   6.448 +  FUNCTION_EXIT();
   6.449 +  return (ULONG)-1;
   6.450 +}
   6.451 +
   6.452 +static NTSTATUS
   6.453 +XenUsbHub_UBIH_CreateUsbDeviceV7(
   6.454 +    PVOID BusContext,
   6.455 +    PUSB_DEVICE_HANDLE *NewDeviceHandle,
   6.456 +    PUSB_DEVICE_HANDLE HsHubDeviceHandle,
   6.457 +    USHORT PortStatus,
   6.458 +    PUSB_PORT_PATH PortPath,
   6.459 +    PUSB_CD_ERROR_INFORMATION CdErrorInfo,
   6.460 +    USHORT TtPortNumber,
   6.461 +    PDEVICE_OBJECT PdoDeviceObject,
   6.462 +    PUNICODE_STRING PhysicalDeviceObjectName)
   6.463 +{
   6.464 +  UNREFERENCED_PARAMETER(BusContext);
   6.465 +  FUNCTION_ENTER();
   6.466 +  FUNCTION_EXIT();
   6.467 +  return STATUS_BAD_INITIAL_STACK;
   6.468 +}
   6.469 +
   6.470 +static NTSTATUS
   6.471 +XenUsbHub_UBIH_GetContainerIdForPort(
   6.472 +  PVOID BusContext,
   6.473 +  USHORT PortNumber,
   6.474 +  LPGUID ContainerId)
   6.475 +{
   6.476 +  UNREFERENCED_PARAMETER(BusContext);
   6.477 +  FUNCTION_ENTER();
   6.478 +  FUNCTION_EXIT();
   6.479 +  return STATUS_BAD_INITIAL_STACK;
   6.480 +}
   6.481 +
   6.482 +static NTSTATUS
   6.483 +XenUsbHub_UBIH_SetContainerIdForPort(
   6.484 +  PVOID BusContext,
   6.485 +  USHORT PortNumber,
   6.486 +  LPGUID ContainerId)
   6.487 +{
   6.488 +  UNREFERENCED_PARAMETER(BusContext);
   6.489 +  FUNCTION_ENTER();
   6.490 +  FUNCTION_EXIT();
   6.491 +  return STATUS_BAD_INITIAL_STACK;
   6.492 +}
   6.493 +
   6.494 +static NTSTATUS
   6.495 +XenUsbHub_UBIH_AbortAllDevicePipes(
   6.496 +  PVOID BusContext,
   6.497 +  PUSB_DEVICE_HANDLE DeviceHandle)
   6.498 +{
   6.499 +  UNREFERENCED_PARAMETER(BusContext);
   6.500 +  FUNCTION_ENTER();
   6.501 +  FUNCTION_EXIT();
   6.502 +  return STATUS_BAD_INITIAL_STACK;
   6.503 +}
   6.504 +
   6.505 +static VOID
   6.506 +XenUsbHub_UBIH_SetDeviceErrataFlag(
   6.507 +  PVOID BusContext,
   6.508 +  PUSB_DEVICE_HANDLE DeviceHandle,
   6.509 +  ULONG DeviceErrataFlag)
   6.510 +{
   6.511 +  UNREFERENCED_PARAMETER(BusContext);
   6.512 +  FUNCTION_ENTER();
   6.513 +  FUNCTION_EXIT();
   6.514 +  return;
   6.515 +}  
   6.516 +
   6.517 +static NTSTATUS
   6.518  XenUsbHub_UBIU_GetUSBDIVersion(
   6.519    PVOID BusContext,
   6.520    PUSBD_VERSION_INFORMATION VersionInformation,
   6.521    PULONG HcdCapabilities
   6.522    )
   6.523  {
   6.524 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.525 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.526  
   6.527    UNREFERENCED_PARAMETER(BusContext);
   6.528    UNREFERENCED_PARAMETER(VersionInformation);
   6.529 @@ -1098,7 +1480,7 @@ XenUsbHub_UBIU_QueryBusTime(
   6.530    PULONG CurrentFrame
   6.531    )
   6.532  {
   6.533 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.534 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.535  
   6.536    UNREFERENCED_PARAMETER(BusContext);
   6.537    UNREFERENCED_PARAMETER(CurrentFrame);
   6.538 @@ -1115,7 +1497,7 @@ XenUsbHub_UBIU_SubmitIsoOutUrb(
   6.539    PURB Urb
   6.540    )
   6.541  {
   6.542 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.543 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.544  
   6.545    UNREFERENCED_PARAMETER(BusContext);
   6.546    UNREFERENCED_PARAMETER(Urb);
   6.547 @@ -1134,7 +1516,7 @@ XenUsbHub_UBIU_QueryBusInformation(
   6.548    PULONG BusInformationBufferLength,
   6.549    PULONG BusInformationActualLength)
   6.550  {
   6.551 -  NTSTATUS status = STATUS_UNSUCCESSFUL;
   6.552 +  NTSTATUS status = STATUS_BAD_INITIAL_STACK;
   6.553  
   6.554    UNREFERENCED_PARAMETER(BusContext);
   6.555    UNREFERENCED_PARAMETER(Level);
   6.556 @@ -1186,6 +1568,55 @@ XenUsbHub_UBIU_EnumLogEntry(
   6.557    return status;
   6.558  }
   6.559  
   6.560 +static NTSTATUS
   6.561 +XenUsbHub_UBIU_QueryBusTimeEx(
   6.562 +  PVOID BusContext,
   6.563 +  PULONG HighSpeedFrameCounter)
   6.564 +{
   6.565 +  UNREFERENCED_PARAMETER(BusContext);
   6.566 +  UNREFERENCED_PARAMETER(HighSpeedFrameCounter);
   6.567 +  FUNCTION_ENTER();
   6.568 +  FUNCTION_EXIT();
   6.569 +  return STATUS_BAD_INITIAL_STACK;
   6.570 +}
   6.571 +
   6.572 +static NTSTATUS
   6.573 +XenUsbHub_UBIU_QueryControllerType(
   6.574 +  PVOID BusContext,
   6.575 +  PULONG HcdiOptionFlags,
   6.576 +  PUSHORT PciVendorId,
   6.577 +  PUSHORT PciDeviceId,
   6.578 +  PUCHAR PciClass,
   6.579 +  PUCHAR PciSubClass,
   6.580 +  PUCHAR PciRevisionId,
   6.581 +  PUCHAR PciProgIf)
   6.582 +{
   6.583 +  UNREFERENCED_PARAMETER(BusContext);
   6.584 +  FUNCTION_ENTER();
   6.585 +  FUNCTION_EXIT();
   6.586 +  return STATUS_BAD_INITIAL_STACK;
   6.587 +}
   6.588 +
   6.589 +static NTSTATUS
   6.590 +XenUsbHub_UBIHSS_SuspendHub(
   6.591 +  PVOID BusContext)
   6.592 +{
   6.593 +  UNREFERENCED_PARAMETER(BusContext);
   6.594 +  FUNCTION_ENTER();
   6.595 +  FUNCTION_EXIT();
   6.596 +  return STATUS_BAD_INITIAL_STACK;
   6.597 +}
   6.598 +
   6.599 +static NTSTATUS
   6.600 +XenUsbHub_UBIHSS_ResumeHub(
   6.601 +  PVOID BusContext)
   6.602 +{
   6.603 +  UNREFERENCED_PARAMETER(BusContext);
   6.604 +  FUNCTION_ENTER();
   6.605 +  FUNCTION_EXIT();
   6.606 +  return STATUS_BAD_INITIAL_STACK;
   6.607 +}
   6.608 +
   6.609  #if 0
   6.610  VOID
   6.611  XenUsb_EnumeratePorts(WDFDEVICE device)
   6.612 @@ -1250,7 +1681,7 @@ XenUsbHub_HubInterruptTimer(WDFTIMER tim
   6.613    PURB urb;
   6.614    ULONG i;
   6.615    
   6.616 -  //FUNCTION_ENTER();
   6.617 +  FUNCTION_ENTER();
   6.618    WdfSpinLockAcquire(endpoint->interrupt_lock);
   6.619    status = WdfIoQueueRetrieveNextRequest(endpoint->interrupt_queue, &request);
   6.620    if (status == STATUS_NO_MORE_ENTRIES)
   6.621 @@ -1300,9 +1731,9 @@ XenUsbHub_HubInterruptTimer(WDFTIMER tim
   6.622      KdPrint((__DRIVER_NAME "      Direction mismatch\n"));
   6.623      urb->UrbHeader.Status = USBD_STATUS_INVALID_PARAMETER;
   6.624      WdfSpinLockRelease(endpoint->interrupt_lock);
   6.625 -    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   6.626 +    WdfRequestComplete(request, STATUS_BAD_INITIAL_STACK);
   6.627    }
   6.628 -  //FUNCTION_EXIT();
   6.629 +  FUNCTION_EXIT();
   6.630    return;
   6.631  }
   6.632  
   6.633 @@ -1325,10 +1756,18 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   6.634    WDF_DEVICE_POWER_CAPABILITIES child_power_capabilities;
   6.635    WDF_IO_QUEUE_CONFIG queue_config;
   6.636    WDF_QUERY_INTERFACE_CONFIG interface_config;
   6.637 -  USB_BUS_INTERFACE_HUB_V5 ubih;
   6.638 -  USB_BUS_INTERFACE_USBDI_V2 ubiu;
   6.639 +  union {
   6.640 +    USB_BUS_INTERFACE_HUB_V5 ubih5; /* support version 5 */
   6.641 +    USB_BUS_INTERFACE_HUB_V7 ubih7; /* support versions 6,  and 7 - base definition changed */
   6.642 +  } ubih;
   6.643 +  union {
   6.644 +    USB_BUS_INTERFACE_USBDI_V2 ubiu2;
   6.645 +    USB_BUS_INTERFACE_USBDI_V3 ubiu3;
   6.646 +  } ubiu;
   6.647 +  USB_BUS_INTERFACE_HUB_SELECTIVE_SUSPEND ubihss;
   6.648    WDF_TIMER_CONFIG timer_config;
   6.649    WDF_OBJECT_ATTRIBUTES timer_attributes;
   6.650 +  UCHAR pnp_minor_functions[] = { IRP_MN_QUERY_INTERFACE };
   6.651  
   6.652    UNREFERENCED_PARAMETER(xudd);
   6.653    
   6.654 @@ -1337,6 +1776,13 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   6.655    //KdPrint((__DRIVER_NAME "     device = %d, port = %d, vendor_id = %04x, product_id = %04x\n",
   6.656  
   6.657    WdfDeviceInitSetDeviceType(child_init, FILE_DEVICE_UNKNOWN);
   6.658 +
   6.659 +  status = WdfDeviceInitAssignWdmIrpPreprocessCallback(child_init, XenUsbHub_EvtDeviceWdmIrpPreprocessQUERY_INTERFACE,
   6.660 +    IRP_MJ_PNP, pnp_minor_functions, ARRAY_SIZE(pnp_minor_functions));
   6.661 +  if (!NT_SUCCESS(status))
   6.662 +  {
   6.663 +    return status;
   6.664 +  }
   6.665    
   6.666    WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&child_pnp_power_callbacks);
   6.667    child_pnp_power_callbacks.EvtDeviceD0Entry = XenUsbHub_EvtDeviceD0Entry;
   6.668 @@ -1495,7 +1941,7 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   6.669    child_power_capabilities.DeviceD1 = WdfTrue;
   6.670    child_power_capabilities.WakeFromD1 = WdfTrue;
   6.671    child_power_capabilities.DeviceWake = PowerDeviceD1;
   6.672 -  child_power_capabilities.DeviceState[PowerSystemWorking]   = PowerDeviceD1;
   6.673 +  child_power_capabilities.DeviceState[PowerSystemWorking]   = PowerDeviceD0;
   6.674    child_power_capabilities.DeviceState[PowerSystemSleeping1] = PowerDeviceD1;
   6.675    child_power_capabilities.DeviceState[PowerSystemSleeping2] = PowerDeviceD2;
   6.676    child_power_capabilities.DeviceState[PowerSystemSleeping3] = PowerDeviceD2;
   6.677 @@ -1503,48 +1949,118 @@ XenUsb_EvtChildListCreateDevice(WDFCHILD
   6.678    child_power_capabilities.DeviceState[PowerSystemShutdown]  = PowerDeviceD3;
   6.679    WdfDeviceSetPowerCapabilities(child_device, &child_power_capabilities);  
   6.680  
   6.681 -  ubih.BusContext = child_device;
   6.682 -  ubih.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
   6.683 -  ubih.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
   6.684 -  ubih.CreateUsbDevice = XenUsbHub_UBIH_CreateUsbDevice;
   6.685 -  ubih.InitializeUsbDevice = XenUsbHub_UBIH_InitializeUsbDevice;
   6.686 -  ubih.GetUsbDescriptors = XenUsbHub_UBIH_GetUsbDescriptors;
   6.687 -  ubih.RemoveUsbDevice = XenUsbHub_UBIH_RemoveUsbDevice;
   6.688 -  ubih.RestoreUsbDevice = XenUsbHub_UBIH_RestoreUsbDevice;
   6.689 -  ubih.GetPortHackFlags = XenUsbHub_UBIH_GetPortHackFlags;
   6.690 -  ubih.QueryDeviceInformation = XenUsbHub_UBIH_QueryDeviceInformation;
   6.691 -  ubih.GetControllerInformation = XenUsbHub_UBIH_GetControllerInformation;
   6.692 -  ubih.ControllerSelectiveSuspend = XenUsbHub_UBIH_ControllerSelectiveSuspend;
   6.693 -  ubih.GetExtendedHubInformation = XenUsbHub_UBIH_GetExtendedHubInformation;
   6.694 -  ubih.GetRootHubSymbolicName = XenUsbHub_UBIH_GetRootHubSymbolicName;
   6.695 -  ubih.GetDeviceBusContext = XenUsbHub_UBIH_GetDeviceBusContext;
   6.696 -  ubih.Initialize20Hub = XenUsbHub_UBIH_Initialize20Hub;
   6.697 -  ubih.RootHubInitNotification = XenUsbHub_UBIH_RootHubInitNotification;
   6.698 -  ubih.FlushTransfers = XenUsbHub_UBIH_FlushTransfers;
   6.699 -  ubih.SetDeviceHandleData = XenUsbHub_UBIH_SetDeviceHandleData;
   6.700 -  ubih.Size = sizeof(USB_BUS_INTERFACE_HUB_V5);
   6.701 -  ubih.Version = USB_BUSIF_HUB_VERSION_5;
   6.702 +  ubih.ubih7.Size = sizeof(USB_BUS_INTERFACE_HUB_V7);
   6.703 +  ubih.ubih7.Version = USB_BUSIF_HUB_VERSION_7;
   6.704 +  ubih.ubih7.BusContext = child_device;
   6.705 +  ubih.ubih7.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
   6.706 +  ubih.ubih7.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
   6.707 +  ubih.ubih7.CreateUsbDevice = XenUsbHub_UBIH_CreateUsbDeviceEx;
   6.708 +  ubih.ubih7.InitializeUsbDevice = XenUsbHub_UBIH_InitializeUsbDeviceEx;
   6.709 +  ubih.ubih7.GetUsbDescriptors = XenUsbHub_UBIH_GetUsbDescriptors;
   6.710 +  ubih.ubih7.RemoveUsbDevice = XenUsbHub_UBIH_RemoveUsbDevice;
   6.711 +  ubih.ubih7.RestoreUsbDevice = XenUsbHub_UBIH_RestoreUsbDevice;
   6.712 +  ubih.ubih7.GetPortHackFlags = XenUsbHub_UBIH_GetPortHackFlags;
   6.713 +  ubih.ubih7.QueryDeviceInformation = XenUsbHub_UBIH_QueryDeviceInformation;
   6.714 +  ubih.ubih7.GetControllerInformation = XenUsbHub_UBIH_GetControllerInformation;
   6.715 +  ubih.ubih7.ControllerSelectiveSuspend = XenUsbHub_UBIH_ControllerSelectiveSuspend;
   6.716 +  ubih.ubih7.GetExtendedHubInformation = XenUsbHub_UBIH_GetExtendedHubInformation;
   6.717 +  ubih.ubih7.GetRootHubSymbolicName = XenUsbHub_UBIH_GetRootHubSymbolicName;
   6.718 +  ubih.ubih7.GetDeviceBusContext = XenUsbHub_UBIH_GetDeviceBusContext;
   6.719 +  ubih.ubih7.Initialize20Hub = XenUsbHub_UBIH_Initialize20Hub;
   6.720 +  ubih.ubih7.RootHubInitNotification = XenUsbHub_UBIH_RootHubInitNotification;
   6.721 +  ubih.ubih7.FlushTransfers = XenUsbHub_UBIH_FlushTransfers;
   6.722 +  ubih.ubih7.SetDeviceHandleData = XenUsbHub_UBIH_SetDeviceHandleData;
   6.723 +  ubih.ubih7.CreateUsbDevice = XenUsbHub_UBIH_CreateUsbDeviceEx;
   6.724 +  ubih.ubih7.InitializeUsbDevice = XenUsbHub_UBIH_InitializeUsbDeviceEx;
   6.725 +  ubih.ubih7.HubIsRoot = XenUsbHub_UBIH_HubIsRoot;
   6.726 +  ubih.ubih7.AcquireBusSemaphore = XenUsbHub_UBIH_AcquireBusSemaphore;
   6.727 +  ubih.ubih7.ReleaseBusSemaphore = XenUsbHub_UBIH_ReleaseBusSemaphore;
   6.728 +  ubih.ubih7.CaculatePipeBandwidth = XenUsbHub_UBIH_CaculatePipeBandwidth;
   6.729 +  ubih.ubih7.SetBusSystemWakeMode = XenUsbHub_UBIH_SetBusSystemWakeMode;
   6.730 +  ubih.ubih7.SetDeviceFlag = XenUsbHub_UBIH_SetDeviceFlag;
   6.731 +  ubih.ubih7.HubTestPoint = XenUsbHub_UBIH_HubTestPoint;
   6.732 +  ubih.ubih7.GetDevicePerformanceInfo = XenUsbHub_UBIH_GetDevicePerformanceInfo;
   6.733 +  ubih.ubih7.WaitAsyncPowerUp = XenUsbHub_UBIH_WaitAsyncPowerUp;
   6.734 +  ubih.ubih7.GetDeviceAddress = XenUsbHub_UBIH_GetDeviceAddress;
   6.735 +  ubih.ubih7.RefDeviceHandle = XenUsbHub_UBIH_RefDeviceHandle;
   6.736 +  ubih.ubih7.DerefDeviceHandle = XenUsbHub_UBIH_DerefDeviceHandle;
   6.737 +  ubih.ubih7.SetDeviceHandleIdleReadyState = XenUsbHub_UBIH_SetDeviceHandleIdleReadyState;
   6.738 +  ubih.ubih7.HubIsRoot = XenUsbHub_UBIH_HubIsRoot;
   6.739 +  ubih.ubih7.AcquireBusSemaphore = XenUsbHub_UBIH_AcquireBusSemaphore;
   6.740 +  ubih.ubih7.ReleaseBusSemaphore = XenUsbHub_UBIH_ReleaseBusSemaphore;
   6.741 +  ubih.ubih7.CaculatePipeBandwidth = XenUsbHub_UBIH_CaculatePipeBandwidth;
   6.742 +  ubih.ubih7.SetBusSystemWakeMode = XenUsbHub_UBIH_SetBusSystemWakeMode;
   6.743 +  ubih.ubih7.SetDeviceFlag = XenUsbHub_UBIH_SetDeviceFlag;
   6.744 +  ubih.ubih7.HubTestPoint = XenUsbHub_UBIH_HubTestPoint;
   6.745 +  ubih.ubih7.GetDevicePerformanceInfo = XenUsbHub_UBIH_GetDevicePerformanceInfo;
   6.746 +  ubih.ubih7.WaitAsyncPowerUp = XenUsbHub_UBIH_WaitAsyncPowerUp;
   6.747 +  ubih.ubih7.GetDeviceAddress = XenUsbHub_UBIH_GetDeviceAddress;
   6.748 +  ubih.ubih7.RefDeviceHandle = XenUsbHub_UBIH_RefDeviceHandle;
   6.749 +  ubih.ubih7.DerefDeviceHandle = XenUsbHub_UBIH_DerefDeviceHandle;
   6.750 +  ubih.ubih7.SetDeviceHandleIdleReadyState = XenUsbHub_UBIH_SetDeviceHandleIdleReadyState;
   6.751 +  ubih.ubih7.CreateUsbDeviceV7 = XenUsbHub_UBIH_CreateUsbDeviceV7;
   6.752 +  ubih.ubih7.GetContainerIdForPort = XenUsbHub_UBIH_GetContainerIdForPort;
   6.753 +  ubih.ubih7.SetContainerIdForPort = XenUsbHub_UBIH_SetContainerIdForPort;
   6.754 +  ubih.ubih7.AbortAllDevicePipes = XenUsbHub_UBIH_AbortAllDevicePipes;
   6.755 +  ubih.ubih7.SetDeviceErrataFlag = XenUsbHub_UBIH_SetDeviceErrataFlag;  
   6.756    WDF_QUERY_INTERFACE_CONFIG_INIT(&interface_config, (PINTERFACE)&ubih, &USB_BUS_INTERFACE_HUB_GUID, NULL);
   6.757    status = WdfDeviceAddQueryInterface(child_device, &interface_config);
   6.758    if (!NT_SUCCESS(status))
   6.759      return status;
   6.760  
   6.761 -  ubiu.BusContext = child_device;
   6.762 -  ubiu.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
   6.763 -  ubiu.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
   6.764 -  ubiu.GetUSBDIVersion = XenUsbHub_UBIU_GetUSBDIVersion;
   6.765 -  ubiu.QueryBusTime = XenUsbHub_UBIU_QueryBusTime;
   6.766 -  ubiu.SubmitIsoOutUrb = XenUsbHub_UBIU_SubmitIsoOutUrb;
   6.767 -  ubiu.QueryBusInformation = XenUsbHub_UBIU_QueryBusInformation;
   6.768 -  ubiu.IsDeviceHighSpeed = XenUsbHub_UBIU_IsDeviceHighSpeed;
   6.769 -  ubiu.EnumLogEntry  = XenUsbHub_UBIU_EnumLogEntry;
   6.770 -  ubiu.Size = sizeof(USB_BUS_INTERFACE_USBDI_V2);
   6.771 -  ubiu.Version = USB_BUSIF_HUB_VERSION_2;
   6.772 +  ubih.ubih7.Size = sizeof(USB_BUS_INTERFACE_HUB_V6);
   6.773 +  ubih.ubih7.Version = USB_BUSIF_HUB_VERSION_6;
   6.774 +  WDF_QUERY_INTERFACE_CONFIG_INIT(&interface_config, (PINTERFACE)&ubih, &USB_BUS_INTERFACE_HUB_GUID, NULL);
   6.775 +  status = WdfDeviceAddQueryInterface(child_device, &interface_config);
   6.776 +  if (!NT_SUCCESS(status))
   6.777 +    return status;
   6.778 +
   6.779 +  ubih.ubih5.Size = sizeof(USB_BUS_INTERFACE_HUB_V5);
   6.780 +  ubih.ubih5.Version = USB_BUSIF_HUB_VERSION_5;
   6.781 +  ubih.ubih5.CreateUsbDevice = XenUsbHub_UBIH_CreateUsbDevice;
   6.782 +  ubih.ubih5.InitializeUsbDevice = XenUsbHub_UBIH_InitializeUsbDevice;
   6.783 +  WDF_QUERY_INTERFACE_CONFIG_INIT(&interface_config, (PINTERFACE)&ubih, &USB_BUS_INTERFACE_HUB_GUID, NULL);
   6.784 +  status = WdfDeviceAddQueryInterface(child_device, &interface_config);
   6.785 +  if (!NT_SUCCESS(status))
   6.786 +    return status;
   6.787 +
   6.788 +  ubiu.ubiu3.Size = sizeof(USB_BUS_INTERFACE_USBDI_V3);
   6.789 +  ubiu.ubiu3.Version = USB_BUSIF_HUB_VERSION_3;
   6.790 +  ubiu.ubiu2.BusContext = child_device;
   6.791 +  ubiu.ubiu2.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
   6.792 +  ubiu.ubiu2.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
   6.793 +  ubiu.ubiu2.GetUSBDIVersion = XenUsbHub_UBIU_GetUSBDIVersion;
   6.794 +  ubiu.ubiu2.QueryBusTime = XenUsbHub_UBIU_QueryBusTime;
   6.795 +  ubiu.ubiu2.SubmitIsoOutUrb = XenUsbHub_UBIU_SubmitIsoOutUrb;
   6.796 +  ubiu.ubiu2.QueryBusInformation = XenUsbHub_UBIU_QueryBusInformation;
   6.797 +  ubiu.ubiu2.IsDeviceHighSpeed = XenUsbHub_UBIU_IsDeviceHighSpeed;
   6.798 +  ubiu.ubiu2.EnumLogEntry  = XenUsbHub_UBIU_EnumLogEntry;
   6.799 +  ubiu.ubiu3.QueryBusTimeEx = XenUsbHub_UBIU_QueryBusTimeEx;
   6.800 +  ubiu.ubiu3.QueryControllerType = XenUsbHub_UBIU_QueryControllerType;
   6.801    WDF_QUERY_INTERFACE_CONFIG_INIT(&interface_config, (PINTERFACE)&ubiu, &USB_BUS_INTERFACE_USBDI_GUID, NULL);
   6.802    status = WdfDeviceAddQueryInterface(child_device, &interface_config);
   6.803    if (!NT_SUCCESS(status))
   6.804      return status;
   6.805 -  
   6.806 +
   6.807 +  ubiu.ubiu2.Size = sizeof(USB_BUS_INTERFACE_USBDI_V2);
   6.808 +  ubiu.ubiu2.Version = USB_BUSIF_HUB_VERSION_2;
   6.809 +  WDF_QUERY_INTERFACE_CONFIG_INIT(&interface_config, (PINTERFACE)&ubiu, &USB_BUS_INTERFACE_USBDI_GUID, NULL);
   6.810 +  status = WdfDeviceAddQueryInterface(child_device, &interface_config);
   6.811 +  if (!NT_SUCCESS(status))
   6.812 +  return status;
   6.813 +
   6.814 +  ubihss.BusContext = child_device;
   6.815 +  ubihss.Size = sizeof(USB_BUS_INTERFACE_HUB_SELECTIVE_SUSPEND);
   6.816 +  ubihss.Version = USB_BUSIF_HUB_SS_VERSION_0;
   6.817 +  ubihss.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
   6.818 +  ubihss.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
   6.819 +  ubihss.SuspendHub = XenUsbHub_UBIHSS_SuspendHub;
   6.820 +  ubihss.ResumeHub = XenUsbHub_UBIHSS_ResumeHub;
   6.821 +  WDF_QUERY_INTERFACE_CONFIG_INIT(&interface_config, (PINTERFACE)&ubiu, &USB_BUS_INTERFACE_HUB_SS_GUID, NULL);
   6.822 +  status = WdfDeviceAddQueryInterface(child_device, &interface_config);
   6.823 +  if (!NT_SUCCESS(status))
   6.824 +  return status;
   6.825 +
   6.826    status = WdfDeviceCreateDeviceInterface(child_device, &GUID_DEVINTERFACE_USB_HUB, NULL);
   6.827    if (!NT_SUCCESS(status))
   6.828      return status;
     7.1 --- a/xenusb/xenusb_huburb.c	Sat Jun 04 17:39:58 2011 +1000
     7.2 +++ b/xenusb/xenusb_huburb.c	Tue Jun 07 22:37:56 2011 +1000
     7.3 @@ -27,7 +27,7 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
     7.4    size_t input_buffer_length,
     7.5    ULONG io_control_code)
     7.6  {
     7.7 -  NTSTATUS status;
     7.8 +  //NTSTATUS status;
     7.9    WDFDEVICE device = WdfIoQueueGetDevice(queue);
    7.10    PXENUSB_PDO_DEVICE_DATA xupdd = GetXupdd(device);
    7.11    PXENUSB_DEVICE_DATA xudd = GetXudd(xupdd->wdf_device_bus_fdo);
    7.12 @@ -36,25 +36,25 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
    7.13    PUSBD_INTERFACE_INFORMATION interface_information;
    7.14    ULONG i, j;
    7.15    xenusb_device_t *usb_device;
    7.16 -  PUSB_HUB_DESCRIPTOR uhd;
    7.17    xenusb_endpoint_t *endpoint;
    7.18 +  //USB_DEFAULT_PIPE_SETUP_PACKET setup_packet;
    7.19 +  urb_decode_t decode_data;
    7.20 +  ULONG decode_retval;
    7.21  
    7.22    UNREFERENCED_PARAMETER(input_buffer_length);
    7.23    UNREFERENCED_PARAMETER(output_buffer_length);
    7.24    UNREFERENCED_PARAMETER(io_control_code);
    7.25  
    7.26 -  //FUNCTION_ENTER();
    7.27 +  FUNCTION_ENTER();
    7.28  
    7.29    ASSERT(io_control_code == IOCTL_INTERNAL_USB_SUBMIT_URB);
    7.30  
    7.31 -  status = STATUS_UNSUCCESSFUL;
    7.32 -
    7.33    WDF_REQUEST_PARAMETERS_INIT(&wrp);
    7.34    WdfRequestGetParameters(request, &wrp);
    7.35  
    7.36    urb = (PURB)wrp.Parameters.Others.Arg1;
    7.37    ASSERT(urb);
    7.38 -#if 0
    7.39 +#if 1
    7.40    KdPrint((__DRIVER_NAME "     urb = %p\n", urb));
    7.41    KdPrint((__DRIVER_NAME "      Length = %d\n", urb->UrbHeader.Length));
    7.42    KdPrint((__DRIVER_NAME "      Function = %d\n", urb->UrbHeader.Function));
    7.43 @@ -67,6 +67,34 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
    7.44    if (!usb_device)
    7.45      usb_device = xupdd->usb_device;
    7.46  
    7.47 +  decode_retval = XenUsb_DecodeControlUrb(urb, &decode_data);
    7.48 +  if (decode_retval == URB_DECODE_UNKNOWN)
    7.49 +  {
    7.50 +    FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL); //STATUS_UNSUCCESSFUL));
    7.51 +    urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    7.52 +    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    7.53 +    FUNCTION_EXIT();
    7.54 +    return;
    7.55 +  }
    7.56 +
    7.57 +  urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    7.58 +  
    7.59 +  if (decode_retval != URB_DECODE_NOT_CONTROL)
    7.60 +  {
    7.61 +    FUNCTION_MSG("bmRequestType = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.B);
    7.62 +    FUNCTION_MSG(" Recipient = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient);
    7.63 +    FUNCTION_MSG(" Type = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type);
    7.64 +    FUNCTION_MSG(" Dir = %x\n", decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Dir);
    7.65 +    FUNCTION_MSG("bRequest = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.bRequest);
    7.66 +    FUNCTION_MSG("wValue = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W);
    7.67 +    FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.LowByte);
    7.68 +    FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
    7.69 +    FUNCTION_MSG("wIndex = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex);
    7.70 +    FUNCTION_MSG(" Low = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte);
    7.71 +    FUNCTION_MSG(" High = %02x\n", decode_data.setup_packet.default_pipe_setup_packet.wIndex.HiByte);
    7.72 +    FUNCTION_MSG("wLength = %04x\n", decode_data.setup_packet.default_pipe_setup_packet.wLength);
    7.73 +  }
    7.74 +  
    7.75    switch(urb->UrbHeader.Function)
    7.76    {
    7.77    case URB_FUNCTION_SELECT_CONFIGURATION:
    7.78 @@ -126,7 +154,6 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
    7.79        }
    7.80      }
    7.81      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
    7.82 -    WdfRequestComplete(request, STATUS_SUCCESS);
    7.83      break;
    7.84    case URB_FUNCTION_SELECT_INTERFACE:
    7.85      KdPrint((__DRIVER_NAME "     URB_FUNCTION_SELECT_INTERFACE\n"));
    7.86 @@ -153,8 +180,180 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
    7.87        KdPrint((__DRIVER_NAME "       PipeFlags = %08x\n", interface_information->Pipes[i].PipeFlags));
    7.88      }
    7.89      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
    7.90 -    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
    7.91      break;
    7.92 +  case URB_FUNCTION_CONTROL_TRANSFER_EX:
    7.93 +#if 0
    7.94 +    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)urb->UrbControlTransfer.SetupPacket;
    7.95 +    FUNCTION_MSG("URB_FUNCTION_CONTROL_TRANSFER_EX\n");
    7.96 +    FUNCTION_MSG(" PipeHandle = %p\n", urb->UrbControlTransfer.PipeHandle);
    7.97 +    FUNCTION_MSG(" TransferFlags = %08x\n", urb->UrbControlTransfer.TransferFlags);
    7.98 +    FUNCTION_MSG(" TransferBufferLength = %d\n", urb->UrbControlTransfer.TransferBufferLength);
    7.99 +    FUNCTION_MSG(" TransferBuffer = %p\n", urb->UrbControlTransfer.TransferBuffer);
   7.100 +    FUNCTION_MSG(" TransferBufferMdl = %p\n", urb->UrbControlTransfer.TransferBufferMDL);
   7.101 +    FUNCTION_MSG(" Timeout = %p\n", urb->UrbControlTransfer.TransferBufferMDL);
   7.102 +#endif
   7.103 +    switch(decode_data.setup_packet.default_pipe_setup_packet.bRequest)
   7.104 +    {
   7.105 +    case USB_REQUEST_GET_STATUS:
   7.106 +      // switch device, interface, endpoint
   7.107 +      FUNCTION_MSG(" USB_REQUEST_GET_STATUS\n");
   7.108 +      switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
   7.109 +      {
   7.110 +      case 0: /* Standard */
   7.111 +        KdPrint((__DRIVER_NAME "       Device Status\n"));
   7.112 +        *(PUSHORT)urb->UrbControlDescriptorRequest.TransferBuffer = 0x0003;
   7.113 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.114 +        break;
   7.115 +      case 1: /* Class */
   7.116 +        KdPrint((__DRIVER_NAME "       Port Status\n"));
   7.117 +        ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status;
   7.118 +        ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change;
   7.119 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.120 +      }
   7.121 +      break;
   7.122 +    case USB_REQUEST_GET_DESCRIPTOR:
   7.123 +      FUNCTION_MSG(" USB_REQUEST_GET_DESCRIPTOR\n");
   7.124 +      switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte)
   7.125 +      {
   7.126 +      case USB_DEVICE_DESCRIPTOR_TYPE:
   7.127 +        FUNCTION_MSG(" USB_DEVICE_DESCRIPTOR_TYPE\n");
   7.128 +        memcpy(urb->UrbControlDescriptorRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
   7.129 +        urb->UrbControlDescriptorRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
   7.130 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.131 +        break;
   7.132 +      case USB_CONFIGURATION_DESCRIPTOR_TYPE:
   7.133 +      {
   7.134 +        xenusb_config_t *usb_config;
   7.135 +        PUCHAR ptr;
   7.136 +
   7.137 +        FUNCTION_MSG(" USB_CONFIGURATION_DESCRIPTOR_TYPE\n");
   7.138 +        usb_config = usb_device->active_config;
   7.139 +        ptr = (PUCHAR)decode_data.buffer;
   7.140 +        memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
   7.141 +        ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
   7.142 +        ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
   7.143 +        if (*decode_data.length > 9)
   7.144 +        {
   7.145 +          for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
   7.146 +          {
   7.147 +            memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
   7.148 +            ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
   7.149 +            ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
   7.150 +            for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
   7.151 +            {
   7.152 +              memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
   7.153 +              ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
   7.154 +              ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
   7.155 +            }
   7.156 +          }
   7.157 +        }
   7.158 +        *decode_data.length = ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength;
   7.159 +        //if (urb->UrbControlDescriptorRequest.TransferBufferLength == 9)
   7.160 +        //  ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = 32;
   7.161 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.162 +        break;
   7.163 +      } 
   7.164 +      case 0x29: // Hub Descriptor
   7.165 +      {
   7.166 +        PUSB_HUB_DESCRIPTOR uhd;
   7.167 +        
   7.168 +        FUNCTION_MSG(" USB_HUB_DESCRIPTOR_TYPE\n");
   7.169 +        uhd = urb->UrbControlVendorClassRequest.TransferBuffer;
   7.170 +        urb->UrbControlVendorClassRequest.TransferBufferLength = FIELD_OFFSET(USB_HUB_DESCRIPTOR, bRemoveAndPowerMask[0]) + 2 + 1;
   7.171 +        uhd->bDescriptorLength = (UCHAR)urb->UrbControlVendorClassRequest.TransferBufferLength;
   7.172 +        uhd->bDescriptorType = 0x29;
   7.173 +        uhd->bNumberOfPorts = 8;
   7.174 +        uhd->wHubCharacteristics = 0x0012; // no power switching no overcurrent protection
   7.175 +        uhd->bPowerOnToPowerGood = 1; // 2ms units
   7.176 +        uhd->bHubControlCurrent = 0;
   7.177 +        // DeviceRemovable bits (includes an extra bit at the start)
   7.178 +        uhd->bRemoveAndPowerMask[0] = 0;
   7.179 +        uhd->bRemoveAndPowerMask[1] = 0;
   7.180 +        // PortPwrCtrlMask
   7.181 +        uhd->bRemoveAndPowerMask[2] = 0xFF;
   7.182 +        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.183 +        break;
   7.184 +      }
   7.185 +      default:
   7.186 +        FUNCTION_MSG(" USB_%02x_DESCRIPTOR_TYPE\n", (ULONG)decode_data.setup_packet.default_pipe_setup_packet.wValue.HiByte);
   7.187 +        break;
   7.188 +      }
   7.189 +      break;
   7.190 +    case USB_REQUEST_SET_FEATURE:
   7.191 +      KdPrint((__DRIVER_NAME "      USB_REQUEST_SET_FEATURE\n"));
   7.192 +      KdPrint((__DRIVER_NAME "       SetPortFeature\n"));
   7.193 +      switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Type)
   7.194 +      {
   7.195 +      case 0: /* Standard */
   7.196 +        KdPrint((__DRIVER_NAME "       Standard\n"));
   7.197 +        break;
   7.198 +      case 1: /* Class */
   7.199 +        KdPrint((__DRIVER_NAME "       Class\n"));
   7.200 +        switch (decode_data.setup_packet.default_pipe_setup_packet.bmRequestType.Recipient)
   7.201 +        {
   7.202 +        case BMREQUEST_TO_OTHER:
   7.203 +          switch (decode_data.setup_packet.default_pipe_setup_packet.wValue.W)
   7.204 +          {
   7.205 +          case PORT_ENABLE:
   7.206 +            KdPrint((__DRIVER_NAME "        PORT_ENABLE (NOOP)\n"));
   7.207 +            /* do something here */
   7.208 +            urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.209 +            break;
   7.210 +          case PORT_RESET:
   7.211 +            KdPrint((__DRIVER_NAME "        PORT_RESET\n"));
   7.212 +            /* just fake the reset */
   7.213 +            xudd->ports[decode_data.setup_packet.default_pipe_setup_packet.wIndex.LowByte - 1].port_change |= (1 << PORT_RESET);
   7.214 +            urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.215 +            break;
   7.216 +          case PORT_POWER:
   7.217 +            KdPrint((__DRIVER_NAME "        PORT_POWER (NOOP)\n"));
   7.218 +            /* do something here */
   7.219 +            urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.220 +            break;
   7.221 +          default:
   7.222 +            KdPrint((__DRIVER_NAME "        PORT_%04X\n", decode_data.setup_packet.default_pipe_setup_packet.wValue.W));
   7.223 +            break;
   7.224 +          }
   7.225 +          KdPrint((__DRIVER_NAME "        status = %04x, change = %04x\n",
   7.226 +            xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_status,
   7.227 +            xudd->ports[urb->UrbControlVendorClassRequest.Index - 1].port_change));
   7.228 +          break;
   7.229 +        }
   7.230 +        break;
   7.231 +      }
   7.232 +      break;
   7.233 +    default:
   7.234 +      FUNCTION_MSG(" USB_REQUEST_%02x\n", (ULONG)decode_data.setup_packet.default_pipe_setup_packet.bRequest);
   7.235 +      KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
   7.236 +      break;
   7.237 +    }
   7.238 +    break;
   7.239 +  case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
   7.240 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
   7.241 +    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   7.242 +    urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.243 +    break;
   7.244 +  case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
   7.245 +#if 1
   7.246 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
   7.247 +    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
   7.248 +    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
   7.249 +    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
   7.250 +    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
   7.251 +    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
   7.252 +#endif
   7.253 +    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   7.254 +    WdfSpinLockAcquire(endpoint->interrupt_lock);
   7.255 +    if (WdfIoQueueGetState(endpoint->interrupt_queue, NULL, NULL) & WdfIoQueueNoRequests)
   7.256 +    {
   7.257 +      WdfTimerStart(endpoint->interrupt_timer, WDF_REL_TIMEOUT_IN_MS(100));
   7.258 +    }
   7.259 +    WdfRequestForwardToIoQueue(request, endpoint->interrupt_queue);
   7.260 +    WdfSpinLockRelease(endpoint->interrupt_lock);
   7.261 +    FUNCTION_EXIT();
   7.262 +    return;
   7.263 +    
   7.264 +#if 0 // not using this bit
   7.265    case URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE:
   7.266    //case URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT:
   7.267    //case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
   7.268 @@ -184,10 +383,10 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.269  
   7.270        KdPrint((__DRIVER_NAME "      USB_CONFIGURATION_DESCRIPTOR_TYPE\n"));
   7.271        usb_config = usb_device->active_config;
   7.272 -      ptr = (PUCHAR)urb->UrbControlDescriptorRequest.TransferBuffer;
   7.273 +      ptr = (PUCHAR)decode_data.buffer;
   7.274        memcpy(ptr, &usb_config->config_descriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
   7.275        ptr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
   7.276 -      ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
   7.277 +      ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = sizeof(USB_CONFIGURATION_DESCRIPTOR);
   7.278        if (urb->UrbControlDescriptorRequest.TransferBufferLength > 9)
   7.279        {
   7.280          for (i = 0; i < usb_config->config_descriptor.bNumInterfaces; i++)
   7.281 @@ -195,18 +394,18 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.282            memcpy(ptr, &usb_config->interfaces[i]->interface_descriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
   7.283            KdPrint((__DRIVER_NAME "      bInterfaceClass = %02x\n", ((PUSB_INTERFACE_DESCRIPTOR)ptr)->bInterfaceClass));
   7.284            ptr += sizeof(USB_INTERFACE_DESCRIPTOR);
   7.285 -          ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
   7.286 +          ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_INTERFACE_DESCRIPTOR);
   7.287            for (j = 0; j < usb_config->interfaces[i]->interface_descriptor.bNumEndpoints; j++)
   7.288            {
   7.289              memcpy(ptr, &usb_config->interfaces[i]->endpoints[j]->endpoint_descriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
   7.290              ptr += sizeof(USB_ENDPOINT_DESCRIPTOR);
   7.291 -            ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
   7.292 +            ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength += sizeof(USB_ENDPOINT_DESCRIPTOR);
   7.293            }
   7.294          }
   7.295        }
   7.296 -      urb->UrbControlDescriptorRequest.TransferBufferLength = ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength;
   7.297 -      if (urb->UrbControlDescriptorRequest.TransferBufferLength == 9)
   7.298 -        ((PUSB_CONFIGURATION_DESCRIPTOR)urb->UrbControlDescriptorRequest.TransferBuffer)->wTotalLength = 32;
   7.299 +      *decode_data.length = ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength;
   7.300 +      if (*decode_data.length == 9)
   7.301 +        ((PUSB_CONFIGURATION_DESCRIPTOR)decode_data.buffer)->wTotalLength = 32;
   7.302        KdPrint((__DRIVER_NAME "      TransferBufferLength returned = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
   7.303        break;
   7.304      } 
   7.305 @@ -215,7 +414,6 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.306        break;
   7.307      }
   7.308      urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.309 -    WdfRequestComplete(request, STATUS_SUCCESS);
   7.310      break;
   7.311    case URB_FUNCTION_GET_STATUS_FROM_DEVICE:
   7.312      KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_STATUS_FROM_DEVICE\n"));
   7.313 @@ -228,17 +426,15 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.314        urb->UrbControlGetStatusRequest.TransferBufferLength = 2;
   7.315        *(PUSHORT)urb->UrbControlGetStatusRequest.TransferBuffer = 0x0003;
   7.316        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.317 -      WdfRequestComplete(request, STATUS_SUCCESS);
   7.318      }
   7.319      else
   7.320      {
   7.321        KdPrint((__DRIVER_NAME "     Unknown Index\n"));
   7.322        urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   7.323 -      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   7.324      }    
   7.325      break;
   7.326    case URB_FUNCTION_CLASS_DEVICE:
   7.327 -#if 0
   7.328 +#if 1
   7.329      KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_DEVICE\n"));
   7.330      KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlVendorClassRequest.TransferBufferLength));
   7.331      KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlVendorClassRequest.TransferBuffer));
   7.332 @@ -267,7 +463,6 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.333          memcpy(urb->UrbControlVendorClassRequest.TransferBuffer, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
   7.334          urb->UrbControlVendorClassRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
   7.335          urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.336 -        WdfRequestComplete(request, STATUS_SUCCESS);
   7.337          break;
   7.338  #endif
   7.339        case 0x29: // Hub Descriptor
   7.340 @@ -286,12 +481,10 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.341          // PortPwrCtrlMask
   7.342          uhd->bRemoveAndPowerMask[2] = 0xFF;
   7.343          urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.344 -        WdfRequestComplete(request, STATUS_SUCCESS);
   7.345          break;
   7.346        default:
   7.347          KdPrint((__DRIVER_NAME "       Unknown Value %02x\n", urb->UrbControlVendorClassRequest.Value >> 8));
   7.348          urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   7.349 -        WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   7.350          break;
   7.351        }
   7.352        break;
   7.353 @@ -312,7 +505,6 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.354        ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[0] = 0x0000;
   7.355        ((PUSHORT)urb->UrbControlVendorClassRequest.TransferBuffer)[1] = 0x0000; /* no change occurred */
   7.356        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.357 -      WdfRequestComplete(request, STATUS_SUCCESS);
   7.358        break;
   7.359      case USB_REQUEST_CLEAR_FEATURE:
   7.360        KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   7.361 @@ -325,7 +517,6 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.362        KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   7.363        KdPrint((__DRIVER_NAME "      USB_REQUEST_CLEAR_FEATURE\n"));
   7.364        urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.365 -      WdfRequestComplete(request, STATUS_SUCCESS);
   7.366        break;
   7.367      default:
   7.368        KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   7.369 @@ -338,7 +529,6 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.370        KdPrint((__DRIVER_NAME "      Index = %04x\n", urb->UrbControlVendorClassRequest.Index));
   7.371        KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   7.372        urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   7.373 -      WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   7.374        break;
   7.375      }
   7.376      break;
   7.377 @@ -408,43 +598,25 @@ XenUsb_EvtIoInternalDeviceControl_ROOTHU
   7.378        KdPrint((__DRIVER_NAME "      USB_REQUEST_%02x\n", urb->UrbControlVendorClassRequest.Request));
   7.379        break;
   7.380      }
   7.381 -    urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.382 -    WdfRequestComplete(request, STATUS_SUCCESS);
   7.383 -    //urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   7.384 -    //WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   7.385 +    //urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.386 +    urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   7.387      break;
   7.388 -  case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER: /* 11.12.4 */
   7.389 -#if 0
   7.390 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
   7.391 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbBulkOrInterruptTransfer.PipeHandle));
   7.392 -    KdPrint((__DRIVER_NAME "      TransferFlags = %08x\n", urb->UrbBulkOrInterruptTransfer.TransferFlags));
   7.393 -    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbBulkOrInterruptTransfer.TransferBufferLength));
   7.394 -    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBuffer));
   7.395 -    KdPrint((__DRIVER_NAME "      TransferBufferMdl = %p\n", urb->UrbBulkOrInterruptTransfer.TransferBufferMDL));
   7.396  #endif
   7.397 -    endpoint = urb->UrbBulkOrInterruptTransfer.PipeHandle;
   7.398 -    WdfSpinLockAcquire (endpoint->interrupt_lock);
   7.399 -    if (WdfIoQueueGetState(endpoint->interrupt_queue, NULL, NULL) & WdfIoQueueNoRequests)
   7.400 -    {
   7.401 -      status = WdfTimerStart(endpoint->interrupt_timer, WDF_REL_TIMEOUT_IN_MS(100));
   7.402 -    }
   7.403 -    status = WdfRequestForwardToIoQueue(request, endpoint->interrupt_queue);
   7.404 -    WdfSpinLockRelease(endpoint->interrupt_lock);
   7.405 -    break;
   7.406 -  case URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL:
   7.407 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL\n"));
   7.408 -    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   7.409 -    urb->UrbHeader.Status = USBD_STATUS_SUCCESS;
   7.410 -    WdfRequestComplete(request, STATUS_SUCCESS);
   7.411 -    break;
   7.412    default:
   7.413 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
   7.414 -    KdPrint((__DRIVER_NAME "     Calling WdfRequestCompletestatus with status = %08x\n", status));
   7.415 +    FUNCTION_MSG("URB_FUNCTION_%04x\n", urb->UrbHeader.Function);
   7.416      urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
   7.417 -    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   7.418      break;
   7.419    }
   7.420 -
   7.421 -  //FUNCTION_EXIT();
   7.422 +  if (urb->UrbHeader.Status == USBD_STATUS_SUCCESS)
   7.423 +  {
   7.424 +    FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_SUCCESS);
   7.425 +    WdfRequestComplete(request, STATUS_SUCCESS);
   7.426 +  }
   7.427 +  else
   7.428 +  {
   7.429 +    FUNCTION_MSG("Calling WdfRequestCompletestatus with status = %08x\n", STATUS_UNSUCCESSFUL);
   7.430 +    WdfRequestComplete(request, STATUS_UNSUCCESSFUL);
   7.431 +  }
   7.432 +  FUNCTION_EXIT();
   7.433  }
   7.434