[USBCCGP]
authorThomas Faber <thomas.faber@reactos.org>
Mon, 28 May 2012 10:15:58 +0000 (10:15 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Mon, 28 May 2012 10:15:58 +0000 (10:15 +0000)
- Fix hardware/compatible id generation (still abusing UNICODE_STRING though)
- Do not touch unsupported IRP_MN_QUERY_ID requests

svn path=/trunk/; revision=56666

reactos/drivers/usb/usbccgp/function.c
reactos/drivers/usb/usbccgp/misc.c
reactos/drivers/usb/usbccgp/pdo.c

index 2c2f8c9..d5a8acf 100644 (file)
@@ -386,9 +386,9 @@ USBCCGP_InitFunctionDescriptor(
                                                                          FDODeviceExtension->DeviceDescriptor->idProduct,
                                                                          FDODeviceExtension->DeviceDescriptor->bcdDevice,
                                                                          Descriptor->bFirstInterface) + 1;
-    Index = swprintf(&Buffer[Index], L"USB\\VID_%04x&PID_%04x&MI_%02x", FDODeviceExtension->DeviceDescriptor->idVendor,
-                                                                        FDODeviceExtension->DeviceDescriptor->idProduct,
-                                                                        Descriptor->bFirstInterface) + 1;
+    Index += swprintf(&Buffer[Index], L"USB\\VID_%04x&PID_%04x&MI_%02x", FDODeviceExtension->DeviceDescriptor->idVendor,
+                                                                         FDODeviceExtension->DeviceDescriptor->idProduct,
+                                                                         Descriptor->bFirstInterface) + 1;
 
     // allocate result buffer
     DescriptionBuffer = AllocateItem(NonPagedPool, (Index + 1) * sizeof(WCHAR));
@@ -401,7 +401,7 @@ USBCCGP_InitFunctionDescriptor(
     }
 
     // copy description
-    RtlCopyMemory(DescriptionBuffer, Buffer, Index * sizeof(WCHAR));
+    RtlCopyMemory(DescriptionBuffer, Buffer, (Index + 1) * sizeof(WCHAR));
     FunctionDescriptor->HardwareId.Buffer = DescriptionBuffer;
     FunctionDescriptor->HardwareId.Length = Index * sizeof(WCHAR);
     FunctionDescriptor->HardwareId.MaximumLength = (Index + 1) * sizeof(WCHAR);
@@ -411,8 +411,8 @@ USBCCGP_InitFunctionDescriptor(
     // now init the compatible id
     //
     Index = swprintf(Buffer, L"USB\\Class_%02x&SubClass_%02x&Prot_%02x", Descriptor->bFunctionClass, Descriptor->bFunctionSubClass, Descriptor->bFunctionProtocol) + 1;
-    Index = swprintf(&Buffer[Index], L"USB\\Class_%04x&SubClass_%04x",  Descriptor->bFunctionClass, Descriptor->bFunctionSubClass) + 1;
-    Index = swprintf(&Buffer[Index], L"USB\\Class_%04x", Descriptor->bFunctionClass) + 1;
+    Index += swprintf(&Buffer[Index], L"USB\\Class_%02x&SubClass_%02x",  Descriptor->bFunctionClass, Descriptor->bFunctionSubClass) + 1;
+    Index += swprintf(&Buffer[Index], L"USB\\Class_%02x", Descriptor->bFunctionClass) + 1;
 
     // allocate result buffer
     DescriptionBuffer = AllocateItem(NonPagedPool, (Index + 1) * sizeof(WCHAR));
@@ -425,7 +425,7 @@ USBCCGP_InitFunctionDescriptor(
     }
 
     // copy description
-    RtlCopyMemory(DescriptionBuffer, Buffer, Index * sizeof(WCHAR));
+    RtlCopyMemory(DescriptionBuffer, Buffer, (Index + 1) * sizeof(WCHAR));
     FunctionDescriptor->CompatibleId.Buffer = DescriptionBuffer;
     FunctionDescriptor->CompatibleId.Length = Index * sizeof(WCHAR);
     FunctionDescriptor->CompatibleId.MaximumLength = (Index + 1) * sizeof(WCHAR);
@@ -566,7 +566,7 @@ USBCCG_InitIdsWithInterfaceDescriptor(
     }
 
     // copy description
-    RtlCopyMemory(DescriptionBuffer, Buffer, Index * sizeof(WCHAR));
+    RtlCopyMemory(DescriptionBuffer, Buffer, (Index + 1) * sizeof(WCHAR));
     FunctionDescriptor->HardwareId.Buffer = DescriptionBuffer;
     FunctionDescriptor->HardwareId.Length = Index * sizeof(WCHAR);
     FunctionDescriptor->HardwareId.MaximumLength = (Index + 1) * sizeof(WCHAR);
@@ -589,7 +589,7 @@ USBCCG_InitIdsWithInterfaceDescriptor(
     }
 
     // copy description
-    RtlCopyMemory(DescriptionBuffer, Buffer, Index * sizeof(WCHAR));
+    RtlCopyMemory(DescriptionBuffer, Buffer, (Index + 1) * sizeof(WCHAR));
     FunctionDescriptor->CompatibleId.Buffer = DescriptionBuffer;
     FunctionDescriptor->CompatibleId.Length = Index * sizeof(WCHAR);
     FunctionDescriptor->CompatibleId.MaximumLength = (Index + 1) * sizeof(WCHAR);
index d2fdee0..fe788e7 100644 (file)
@@ -166,8 +166,8 @@ DumpFunctionDescriptor(
     {
         DPRINT1("Function %lu\n", Index);
         DPRINT1("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
-        DPRINT1("HardwareId %wZ\n", &FunctionDescriptor[Index].HardwareId);
-        DPRINT1("CompatibleId %wZ\n", &FunctionDescriptor[Index].CompatibleId);
+        DPRINT1("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
+        DPRINT1("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
         DPRINT1("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
         DPRINT1("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);
 
index 034536a..de23ccc 100644 (file)
@@ -272,6 +272,13 @@ USBCCGP_PdoHandleQueryId(
         //
         DeviceString = &PDODeviceExtension->FunctionDescriptor->CompatibleId;
     }
+    else
+    {
+        //
+        // unsupported query
+        //
+        return Irp->IoStatus.Status;
+    }
 
     //
     // sanity check
@@ -294,6 +301,7 @@ USBCCGP_PdoHandleQueryId(
     // copy buffer
     //
     RtlCopyMemory(Buffer, DeviceString->Buffer, DeviceString->Length);
+    Buffer[DeviceString->Length / sizeof(WCHAR)] = UNICODE_NULL;
     Irp->IoStatus.Information = (ULONG_PTR)Buffer;
 
     return STATUS_SUCCESS;