[LIBUSB][USBCCGP][USBEHCI]
authorThomas Faber <thomas.faber@reactos.org>
Mon, 28 May 2012 10:34:45 +0000 (10:34 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Mon, 28 May 2012 10:34:45 +0000 (10:34 +0000)
- Return the actual number of bytes copied for configuration descriptor requests
- Fix MSVC warnings and NULL vs 0 vs FALSE issues

svn path=/trunk/; revision=56667

reactos/drivers/usb/usbccgp/pdo.c
reactos/drivers/usb/usbehci/usb_request.cpp
reactos/lib/drivers/libusb/hub_controller.cpp
reactos/lib/drivers/libusb/usb_device.cpp

index de23ccc..747b83b 100644 (file)
@@ -473,6 +473,7 @@ USBCCGP_BuildConfigurationDescriptor(
     PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
     PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
     ULONG TotalSize, Index;
+    ULONG Size;
     PURB Urb;
     PVOID Buffer;
     PUCHAR BufferPtr;
@@ -640,7 +641,7 @@ USBCCGP_BuildConfigurationDescriptor(
     // modify configuration descriptor
     //
     ConfigurationDescriptor = Buffer;
-    ConfigurationDescriptor->wTotalLength = TotalSize;
+    ConfigurationDescriptor->wTotalLength = (USHORT)TotalSize;
     ConfigurationDescriptor->bNumInterfaces = PDODeviceExtension->FunctionDescriptor->NumberOfInterfaces;
 
     //
@@ -652,12 +653,13 @@ USBCCGP_BuildConfigurationDescriptor(
     //
     // copy descriptor
     //
-    RtlCopyMemory(Urb->UrbControlDescriptorRequest.TransferBuffer, Buffer, min(TotalSize, Urb->UrbControlDescriptorRequest.TransferBufferLength));
+    Size = min(TotalSize, Urb->UrbControlDescriptorRequest.TransferBufferLength);
+    RtlCopyMemory(Urb->UrbControlDescriptorRequest.TransferBuffer, Buffer, Size);
 
     //
     // store final size
     //
-    Urb->UrbControlDescriptorRequest.TransferBufferLength = TotalSize;
+    Urb->UrbControlDescriptorRequest.TransferBufferLength = Size;
 
     //
     // free buffer
@@ -846,7 +848,7 @@ USBCCGP_PDOSelectConfiguration(
             //
             // now prepare interface urb
             //
-            UsbBuildSelectInterfaceRequest(NewUrb, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceInformation->NumberOfPipes), PDODeviceExtension->ConfigurationHandle, InterfaceInformation->InterfaceNumber, InterfaceInformation->AlternateSetting);
+            UsbBuildSelectInterfaceRequest(NewUrb, (USHORT)GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceInformation->NumberOfPipes), PDODeviceExtension->ConfigurationHandle, InterfaceInformation->InterfaceNumber, InterfaceInformation->AlternateSetting);
 
             //
             // now select the interface
index 1f180fb..ba12783 100644 (file)
@@ -538,7 +538,7 @@ CUSBRequest::InternalGetTransferType()
         // initialized with setup packet, must be a control transfer
         //
         TransferType = USB_ENDPOINT_TYPE_CONTROL;
-        ASSERT(m_EndpointDescriptor == FALSE);
+        ASSERT(m_EndpointDescriptor == NULL);
     }
 
     //
index 6a96048..b412282 100644 (file)
@@ -1293,7 +1293,6 @@ CHubController::HandleClassDevice(
             // generate setup packet
             //
             CtrlSetup.bRequest = USB_REQUEST_GET_STATUS;
-            CtrlSetup.wValue.LowByte = Urb->UrbControlVendorClassRequest.Index;
             CtrlSetup.wValue.W = Urb->UrbControlVendorClassRequest.Value;
             CtrlSetup.wIndex.W = Urb->UrbControlVendorClassRequest.Index;
             CtrlSetup.wLength = (USHORT)Urb->UrbControlGetStatusRequest.TransferBufferLength;
@@ -1410,7 +1409,7 @@ CHubController::HandleClassDevice(
             CtrlSetup.bRequest = Urb->UrbControlVendorClassRequest.Request;
             CtrlSetup.wValue.W = Urb->UrbControlVendorClassRequest.Value;
             CtrlSetup.wIndex.W = Urb->UrbControlVendorClassRequest.Index;
-            CtrlSetup.wLength = Urb->UrbControlVendorClassRequest.TransferBufferLength;
+            CtrlSetup.wLength = (USHORT)Urb->UrbControlVendorClassRequest.TransferBufferLength;
 
             if (Urb->UrbControlVendorClassRequest.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
             {
@@ -1758,7 +1757,7 @@ CHubController::HandleClassEndpoint(
     CtrlSetup.bRequest = Urb->UrbControlVendorClassRequest.Request;
     CtrlSetup.wValue.W = Urb->UrbControlVendorClassRequest.Value;
     CtrlSetup.wIndex.W = Urb->UrbControlVendorClassRequest.Index;
-    CtrlSetup.wLength = Urb->UrbControlVendorClassRequest.TransferBufferLength;
+    CtrlSetup.wLength = (USHORT)Urb->UrbControlVendorClassRequest.TransferBufferLength;
 
     if (Urb->UrbControlVendorClassRequest.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
     {
@@ -1830,7 +1829,7 @@ CHubController::HandleVendorDevice(
     CtrlSetup.bRequest = Urb->UrbControlVendorClassRequest.Request;
     CtrlSetup.wValue.W = Urb->UrbControlVendorClassRequest.Value;
     CtrlSetup.wIndex.W = Urb->UrbControlVendorClassRequest.Index;
-    CtrlSetup.wLength = Urb->UrbControlVendorClassRequest.TransferBufferLength;
+    CtrlSetup.wLength = (USHORT)Urb->UrbControlVendorClassRequest.TransferBufferLength;
 
     if (Urb->UrbControlVendorClassRequest.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
     {
@@ -2096,7 +2095,7 @@ CHubController::HandleClassInterface(
     CtrlSetup.bRequest = Urb->UrbControlVendorClassRequest.Request;
     CtrlSetup.wValue.W = Urb->UrbControlVendorClassRequest.Value;
     CtrlSetup.wIndex.W = Urb->UrbControlVendorClassRequest.Index;
-    CtrlSetup.wLength = Urb->UrbControlVendorClassRequest.TransferBufferLength;
+    CtrlSetup.wLength = (USHORT)Urb->UrbControlVendorClassRequest.TransferBufferLength;
 
     if (Urb->UrbControlVendorClassRequest.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
     {
index 2dc0fa6..df750c7 100644 (file)
@@ -323,7 +323,7 @@ CUSBDevice::SetDeviceAddress(
     CtrlSetup->wValue.W = DeviceAddress;
 
     // set device address
-    Status = CommitSetupPacket(CtrlSetup, 0, 0, 0);
+    Status = CommitSetupPacket(CtrlSetup, NULL, 0, NULL);
 
     // free setup packet
     ExFreePoolWithTag(CtrlSetup, TAG_USBLIB);
@@ -640,7 +640,7 @@ CUSBDevice::CreateDeviceDescriptor()
     //
     // commit setup packet
     //
-    Status = CommitSetupPacket(&CtrlSetup, 0, sizeof(USB_DEVICE_DESCRIPTOR), Mdl);
+    Status = CommitSetupPacket(&CtrlSetup, NULL, sizeof(USB_DEVICE_DESCRIPTOR), Mdl);
 
     //
     // now free the mdl
@@ -713,7 +713,7 @@ CUSBDevice::GetConfigurationDescriptor(
     //
     // commit packet
     //
-    Status = CommitSetupPacket(&CtrlSetup, 0, BufferSize, Mdl);
+    Status = CommitSetupPacket(&CtrlSetup, NULL, BufferSize, Mdl);
 
     //
     // free mdl
@@ -809,6 +809,8 @@ CUSBDevice::GetConfigurationDescriptors(
     IN ULONG BufferLength,
     OUT PULONG OutBufferLength)
 {
+    ULONG Length;
+
     // sanity check
     ASSERT(BufferLength >= sizeof(USB_CONFIGURATION_DESCRIPTOR));
     ASSERT(ConfigDescriptorBuffer);
@@ -821,8 +823,9 @@ CUSBDevice::GetConfigurationDescriptors(
     PC_ASSERT(m_DeviceDescriptor.bNumConfigurations == 1);
 
     // copy configuration descriptor
-    RtlCopyMemory(ConfigDescriptorBuffer, m_ConfigurationDescriptors[0].ConfigurationDescriptor, min(m_ConfigurationDescriptors[0].ConfigurationDescriptor->wTotalLength, BufferLength));
-    *OutBufferLength = m_ConfigurationDescriptors[0].ConfigurationDescriptor->wTotalLength;
+    Length = min(m_ConfigurationDescriptors[0].ConfigurationDescriptor->wTotalLength, BufferLength);
+    RtlCopyMemory(ConfigDescriptorBuffer, m_ConfigurationDescriptors[0].ConfigurationDescriptor, Length);
+    *OutBufferLength = Length;
 }
 
 //----------------------------------------------------------------------------------------
@@ -904,7 +907,7 @@ CUSBDevice::SubmitSetupPacket(
     //
     // commit setup packet
     //
-    Status = CommitSetupPacket(SetupPacket, 0, BufferLength, Mdl);
+    Status = CommitSetupPacket(SetupPacket, NULL, BufferLength, Mdl);
 
     if (Mdl != NULL)
     {
@@ -1055,7 +1058,7 @@ CUSBDevice::SelectConfiguration(
     CtrlSetup.wValue.W = bConfigurationValue;
 
     // select configuration
-    Status = CommitSetupPacket(&CtrlSetup, 0, 0, 0);
+    Status = CommitSetupPacket(&CtrlSetup, NULL, 0, NULL);
 
     if (!ConfigurationDescriptor)
     {
@@ -1174,7 +1177,7 @@ CUSBDevice::SelectInterface(
     CtrlSetup.bmRequestType.B = 0x01;
 
     // issue request
-    Status = CommitSetupPacket(&CtrlSetup, 0, 0, 0);
+    Status = CommitSetupPacket(&CtrlSetup, NULL, 0, NULL);
 
     // informal debug print
     DPRINT1("CUSBDevice::SelectInterface AlternateSetting %x InterfaceNumber %x Status %x\n", InterfaceInfo->AlternateSetting, InterfaceInfo->InterfaceNumber, Status);