win-pvdrivers

changeset 672:63b0eb3f9d44

Fixing bugs
author James Harper <james.harper@bendigoit.com.au>
date Wed Oct 07 14:16:01 2009 +1100 (2009-10-07)
parents 1bae3638ab55
children e5522de3be37
files xenusb/xenusb_devurb.c xenusb/xenusb_fdo.c xenusb/xenusb_hub.c
line diff
     1.1 --- a/xenusb/xenusb_devurb.c	Fri Oct 02 13:53:13 2009 +1000
     1.2 +++ b/xenusb/xenusb_devurb.c	Wed Oct 07 14:16:01 2009 +1100
     1.3 @@ -47,21 +47,18 @@ XenUsb_UrbCallback(usbif_shadow_t *shado
     1.4      KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
     1.5      KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
     1.6      KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
     1.7 -  //case URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT:
     1.8 -  //case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
     1.9 -  //case URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE:
    1.10 -  //case URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT:
    1.11 -  //case URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE:
    1.12      KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE\n"));
    1.13      shadow->urb->UrbControlDescriptorRequest.TransferBufferLength = shadow->total_length;
    1.14 -{
    1.15 -  PUCHAR addr = shadow->urb->UrbControlDescriptorRequest.TransferBuffer;
    1.16 -  int i;
    1.17 -  if (!addr)
    1.18 -    addr = MmGetSystemAddressForMdlSafe(shadow->urb->UrbControlDescriptorRequest.TransferBufferMDL, HighPagePriority);
    1.19 -  for (i = 0; i < min(shadow->urb->UrbControlDescriptorRequest.TransferBufferLength, 16); i++)
    1.20 -    KdPrint((__DRIVER_NAME "      UrbControlDescriptorRequest[%02x] = %02x '%c'\n", i, addr[i], (addr[i] < 32)?' ':addr[i]));
    1.21 -}
    1.22 +    break;
    1.23 +  case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
    1.24 +    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    1.25 +    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    1.26 +    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    1.27 +    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    1.28 +    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    1.29 +    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    1.30 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n"));
    1.31 +    shadow->urb->UrbControlDescriptorRequest.TransferBufferLength = shadow->total_length;
    1.32      break;
    1.33    case URB_FUNCTION_SELECT_CONFIGURATION:
    1.34      KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    1.35 @@ -92,15 +89,16 @@ XenUsb_UrbCallback(usbif_shadow_t *shado
    1.36      shadow->urb->UrbControlVendorClassRequest.TransferBufferLength = shadow->total_length;
    1.37      break;
    1.38    case URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:
    1.39 -#if 0
    1.40 -    KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    1.41 -    KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    1.42 -    KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    1.43 -    KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    1.44 -    KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    1.45 -    KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    1.46 -    KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
    1.47 -#endif
    1.48 +    if (shadow->rsp.status)
    1.49 +    {
    1.50 +      KdPrint((__DRIVER_NAME "     rsp id = %d\n", shadow->rsp.id));
    1.51 +      KdPrint((__DRIVER_NAME "     rsp start_frame = %d\n", shadow->rsp.start_frame));
    1.52 +      KdPrint((__DRIVER_NAME "     rsp status = %d\n", shadow->rsp.status));
    1.53 +      KdPrint((__DRIVER_NAME "     rsp actual_length = %d\n", shadow->rsp.actual_length));
    1.54 +      KdPrint((__DRIVER_NAME "     rsp error_count = %d\n", shadow->rsp.error_count));
    1.55 +      KdPrint((__DRIVER_NAME "     total_length = %d\n", shadow->total_length));
    1.56 +      KdPrint((__DRIVER_NAME "     URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER\n"));
    1.57 +    }
    1.58      shadow->urb->UrbBulkOrInterruptTransfer.TransferBufferLength = shadow->total_length;
    1.59      break;
    1.60    default:
    1.61 @@ -364,15 +362,6 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    1.62      KdPrint((__DRIVER_NAME "      Index = %d\n", (int)urb->UrbControlDescriptorRequest.Index));
    1.63      KdPrint((__DRIVER_NAME "      DescriptorType = %d\n", (int)urb->UrbControlDescriptorRequest.DescriptorType));
    1.64      KdPrint((__DRIVER_NAME "      LanguageId = %04x\n", urb->UrbControlDescriptorRequest.LanguageId));
    1.65 -#if 0
    1.66 -{
    1.67 -  PUCHAR addr = urb->UrbControlDescriptorRequest.TransferBuffer;
    1.68 -  if (!addr)
    1.69 -    addr = MmGetSystemAddressForMdlSafe(urb->UrbControlDescriptorRequest.TransferBufferMDL, HighPagePriority);
    1.70 -  for (i = 0; i < min(urb->UrbControlDescriptorRequest.TransferBufferLength, 16); i++)
    1.71 -    KdPrint((__DRIVER_NAME "      UrbControlDescriptorRequest[%02x] = %02x\n", i, addr[i]));
    1.72 -}
    1.73 -#endif
    1.74      shadow = get_shadow_from_freelist(xudd);
    1.75      shadow->request = request;
    1.76      shadow->urb = urb;
    1.77 @@ -403,6 +392,44 @@ XenUsb_EvtIoInternalDeviceControl_DEVICE
    1.78        KdPrint((__DRIVER_NAME "     XenUsb_ExecuteRequest status = %08x\n", status));
    1.79      }
    1.80      break;
    1.81 +  case URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE:
    1.82 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE\n"));
    1.83 +    KdPrint((__DRIVER_NAME "      TransferBufferLength = %d\n", urb->UrbControlDescriptorRequest.TransferBufferLength));
    1.84 +    KdPrint((__DRIVER_NAME "      TransferBuffer = %p\n", urb->UrbControlDescriptorRequest.TransferBuffer));
    1.85 +    KdPrint((__DRIVER_NAME "      TransferBufferMDL = %p\n", urb->UrbControlDescriptorRequest.TransferBufferMDL));
    1.86 +    KdPrint((__DRIVER_NAME "      Index = %d\n", (int)urb->UrbControlDescriptorRequest.Index));
    1.87 +    KdPrint((__DRIVER_NAME "      DescriptorType = %d\n", (int)urb->UrbControlDescriptorRequest.DescriptorType));
    1.88 +    KdPrint((__DRIVER_NAME "      LanguageId = %04x\n", urb->UrbControlDescriptorRequest.LanguageId));
    1.89 +    shadow = get_shadow_from_freelist(xudd);
    1.90 +    shadow->request = request;
    1.91 +    shadow->urb = urb;
    1.92 +    shadow->callback = XenUsb_UrbCallback;
    1.93 +    shadow->req.id = shadow->id;
    1.94 +    shadow->req.pipe = LINUX_PIPE_DIRECTION_IN | LINUX_PIPE_TYPE_CTRL | (usb_device->address << 8) | usb_device->port_number;
    1.95 +    shadow->req.transfer_flags = 0; 
    1.96 +    setup_packet = (PUSB_DEFAULT_PIPE_SETUP_PACKET)shadow->req.u.ctrl;
    1.97 +    setup_packet->bmRequestType.Recipient = BMREQUEST_TO_INTERFACE;
    1.98 +    setup_packet->bmRequestType.Type = BMREQUEST_STANDARD;
    1.99 +    setup_packet->bmRequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
   1.100 +    setup_packet->bRequest = USB_REQUEST_GET_DESCRIPTOR;
   1.101 +    setup_packet->wValue.LowByte = urb->UrbControlDescriptorRequest.Index;
   1.102 +    setup_packet->wValue.HiByte = urb->UrbControlDescriptorRequest.DescriptorType;
   1.103 +    switch(urb->UrbControlDescriptorRequest.DescriptorType)
   1.104 +    {
   1.105 +    case USB_STRING_DESCRIPTOR_TYPE:
   1.106 +      setup_packet->wIndex.W = urb->UrbControlDescriptorRequest.LanguageId;
   1.107 +      break;
   1.108 +    default:
   1.109 +      setup_packet->wIndex.W = 0;
   1.110 +      break;
   1.111 +    }
   1.112 +    setup_packet->wLength = (USHORT)urb->UrbControlDescriptorRequest.TransferBufferLength;
   1.113 +    status = XenUsb_ExecuteRequest(xudd, shadow, urb->UrbControlDescriptorRequest.TransferBuffer, urb->UrbControlDescriptorRequest.TransferBufferMDL, urb->UrbControlDescriptorRequest.TransferBufferLength);
   1.114 +    if (!NT_SUCCESS(status))
   1.115 +    {
   1.116 +      KdPrint((__DRIVER_NAME "     XenUsb_ExecuteRequest status = %08x\n", status));
   1.117 +    }
   1.118 +    break;
   1.119    case URB_FUNCTION_CLASS_INTERFACE:
   1.120      KdPrint((__DRIVER_NAME "     URB_FUNCTION_CLASS_INTERFACE\n"));
   1.121      KdPrint((__DRIVER_NAME "      TransferFlags  = %08x\n", urb->UrbControlVendorClassRequest.TransferFlags));
   1.122 @@ -725,7 +752,7 @@ URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 
   1.123        //KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_BULK\n"));
   1.124        break;
   1.125      case USB_ENDPOINT_TYPE_INTERRUPT:
   1.126 -      //KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_INTERRUPT\n"));
   1.127 +      KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_INTERRUPT\n"));
   1.128        break;
   1.129      default:
   1.130        KdPrint((__DRIVER_NAME "      USB_ENDPOINT_TYPE_%d\n", endpoint->endpoint_descriptor.bmAttributes));
   1.131 @@ -745,6 +772,10 @@ URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 
   1.132      WdfRequestComplete(request, STATUS_SUCCESS);
   1.133      break;
   1.134  #endif
   1.135 +  case URB_FUNCTION_ABORT_PIPE:
   1.136 +    KdPrint((__DRIVER_NAME "     URB_FUNCTION_ABORT_PIPE\n"));
   1.137 +    KdPrint((__DRIVER_NAME "      PipeHandle = %p\n", urb->UrbPipeRequest.PipeHandle));
   1.138 +    break;
   1.139    default:
   1.140      KdPrint((__DRIVER_NAME "     URB_FUNCTION_%04x\n", urb->UrbHeader.Function));
   1.141      KdPrint((__DRIVER_NAME "     Calling WdfRequestCompletestatus with status = %08x\n", status));
     2.1 --- a/xenusb/xenusb_fdo.c	Fri Oct 02 13:53:13 2009 +1000
     2.2 +++ b/xenusb/xenusb_fdo.c	Wed Oct 07 14:16:01 2009 +1100
     2.3 @@ -942,6 +942,7 @@ XenUsb_EvtIoDeviceControl(
     2.4    {
     2.5      PUSB_HCD_DRIVERKEY_NAME uhdn;
     2.6      size_t length;
     2.7 +    ULONG required_length = 0;
     2.8      
     2.9      KdPrint((__DRIVER_NAME "     IOCTL_USB_GET_ROOT_HUB_NAME\n"));
    2.10      KdPrint((__DRIVER_NAME "      output_buffer_length = %d\n", output_buffer_length));
    2.11 @@ -965,8 +966,9 @@ XenUsb_EvtIoDeviceControl(
    2.12            /* remove leading \??\ from name */
    2.13            symbolic_link.Buffer += 4;
    2.14            symbolic_link.Length -= 4 * sizeof(WCHAR);
    2.15 -          uhdn->ActualLength = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + symbolic_link.Length + sizeof(WCHAR);
    2.16 -          if (output_buffer_length >= FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + symbolic_link.Length + sizeof(WCHAR))
    2.17 +          required_length = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + symbolic_link.Length + sizeof(WCHAR);
    2.18 +          uhdn->ActualLength = required_length;
    2.19 +          if (output_buffer_length >= required_length)
    2.20            {
    2.21              memcpy(uhdn->DriverKeyName, symbolic_link.Buffer, symbolic_link.Length);
    2.22              uhdn->DriverKeyName[symbolic_link.Length / 2] = 0;
    2.23 @@ -984,7 +986,7 @@ XenUsb_EvtIoDeviceControl(
    2.24        }
    2.25        KdPrint((__DRIVER_NAME "      uhdn->ActualLength = %d\n", uhdn->ActualLength));
    2.26        KdPrint((__DRIVER_NAME "      uhdn->DriverKeyName = %S\n", uhdn->DriverKeyName));
    2.27 -      WdfRequestSetInformation(request, uhdn->ActualLength);
    2.28 +      WdfRequestSetInformation(request, required_length);
    2.29      }
    2.30      break;
    2.31    }
    2.32 @@ -992,6 +994,7 @@ XenUsb_EvtIoDeviceControl(
    2.33    {
    2.34      PUSB_HCD_DRIVERKEY_NAME uhdn;
    2.35      size_t length;
    2.36 +    ULONG required_length = 0;
    2.37      
    2.38      KdPrint((__DRIVER_NAME "     IOCTL_GET_HCD_DRIVERKEY_NAME\n"));
    2.39      KdPrint((__DRIVER_NAME "      output_buffer_length = %d\n", output_buffer_length));
    2.40 @@ -1005,13 +1008,16 @@ XenUsb_EvtIoDeviceControl(
    2.41        {
    2.42          ULONG key_length;
    2.43          status = WdfDeviceQueryProperty(device, DevicePropertyDriverKeyName, 0, NULL, &key_length);
    2.44 +        KdPrint((__DRIVER_NAME "      key_length = %d\n", key_length));
    2.45          status = STATUS_SUCCESS;
    2.46 -        uhdn->ActualLength = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + key_length;
    2.47 -        if (output_buffer_length >= uhdn->ActualLength)
    2.48 +        required_length = FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + key_length;
    2.49 +        uhdn->ActualLength = required_length;
    2.50 +        if (output_buffer_length >= required_length)
    2.51          {
    2.52            status = WdfDeviceQueryProperty(device, DevicePropertyDriverKeyName, 
    2.53 -            uhdn->ActualLength - FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName), uhdn->DriverKeyName,
    2.54 +            required_length - FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName), uhdn->DriverKeyName,
    2.55              &key_length);
    2.56 +          KdPrint((__DRIVER_NAME "      wcslen(%S) = %d\n", uhdn->DriverKeyName, wcslen(uhdn->DriverKeyName)));
    2.57          }
    2.58          else
    2.59          {
    2.60 @@ -1024,7 +1030,7 @@ XenUsb_EvtIoDeviceControl(
    2.61        }
    2.62        KdPrint((__DRIVER_NAME "      uhdn->ActualLength = %d\n", uhdn->ActualLength));
    2.63        KdPrint((__DRIVER_NAME "      uhdn->DriverKeyName = %S\n", uhdn->DriverKeyName));
    2.64 -      WdfRequestSetInformation(request, uhdn->ActualLength);
    2.65 +      WdfRequestSetInformation(request, required_length);
    2.66      }
    2.67      break;
    2.68    }
     3.1 --- a/xenusb/xenusb_hub.c	Fri Oct 02 13:53:13 2009 +1000
     3.2 +++ b/xenusb/xenusb_hub.c	Wed Oct 07 14:16:01 2009 +1100
     3.3 @@ -803,6 +803,7 @@ XenUsbHub_UBIH_QueryDeviceInformation(
     3.4    required_size = (ULONG)FIELD_OFFSET(USB_DEVICE_INFORMATION_0, PipeList[usb_device->active_interface->interface_descriptor.bNumEndpoints]);
     3.5    KdPrint((__DRIVER_NAME "     required_size = %d\n", required_size));
     3.6    *LengthOfDataReturned = required_size;
     3.7 +  udi->ActualLength = required_size;
     3.8    if (DeviceInformationBufferLength < required_size)
     3.9    {
    3.10      KdPrint((__DRIVER_NAME "     STATUS_BUFFER_TOO_SMALL\n"));
    3.11 @@ -815,7 +816,6 @@ XenUsbHub_UBIH_QueryDeviceInformation(
    3.12      FUNCTION_EXIT();
    3.13      return STATUS_NOT_SUPPORTED;
    3.14    }
    3.15 -  udi->ActualLength = required_size;
    3.16    udi->PortNumber = 1;
    3.17    memcpy(&udi->DeviceDescriptor, &usb_device->device_descriptor, sizeof(USB_DEVICE_DESCRIPTOR));
    3.18    udi->CurrentConfigurationValue = usb_device->active_config->config_descriptor.bConfigurationValue;