Commit in reactos/lib/hid on MAIN
hid.c+321-91.2 -> 1.3
stubs.c+1-1891.2 -> 1.3
+322-198
2 modified files
implemented a couple of Hid device functions

reactos/lib/hid
hid.c 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- hid.c	12 Jul 2004 16:04:37 -0000	1.2
+++ hid.c	9 Aug 2004 16:02:43 -0000	1.3
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: hid.c,v 1.2 2004/07/12 16:04:37 weiden Exp $
+/* $Id: hid.c,v 1.3 2004/08/09 16:02:43 weiden Exp $
  *
  * PROJECT:         ReactOS Hid User Library
  * FILE:            lib/hid/hid.c
@@ -26,6 +26,8 @@
  *      07/12/2004  Created
  */
 #include <windows.h>
+#include <ddk/hidusage.h>
+#include <ddk/hidclass.h>
 #include <ddk/hidpi.h>
 #include "internal.h"
 
@@ -59,6 +61,67 @@
 
 
 /*
+ * HidD_FlushQueue							EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_FlushQueue(IN HANDLE HidDeviceObject)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_FLUSH_QUEUE,
+                         NULL, 0,
+                         NULL, 0,
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_FreePreparsedData						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData)
+{
+  return (LocalFree((HLOCAL)PreparsedData) == NULL);
+}
+
+
+/*
+ * HidD_GetAttributes							EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetAttributes(IN HANDLE HidDeviceObject,
+                   OUT PHIDD_ATTRIBUTES Attributes)
+{
+  HID_COLLECTION_INFORMATION hci;
+  DWORD RetLen;
+  
+  if(!DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_COLLECTION_INFORMATION,
+                                       NULL, 0,
+                                       &hci, sizeof(HID_COLLECTION_INFORMATION),
+                                       &RetLen, NULL))
+  {
+    return FALSE;
+  }
+  
+  /* copy the fields */
+  Attributes->Size = sizeof(HIDD_ATTRIBUTES);
+  Attributes->VendorID = hci.VendorID;
+  Attributes->ProductID = hci.ProductID;
+  Attributes->VersionNumber = hci.VersionNumber;
+  
+  return TRUE;
+}
+
+
+/*
  * HidP_GetButtonCaps							EXPORTED
  *
  * @implemented
@@ -70,7 +133,27 @@
                    IN OUT PULONG ButtonCapsLength,
                    IN PHIDP_PREPARSED_DATA PreparsedData)
 {
-  return HidP_GetSpecificButtonCaps(ReportType, 0, 0, 0, ButtonCaps, ButtonCapsLength, PreparsedData);
+  return HidP_GetSpecificButtonCaps(ReportType, 0, 0, 0, ButtonCaps,
+                                    ButtonCapsLength, PreparsedData);
+}
+
+
+/*
+ * HidD_GetFeature							EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetFeature(IN HANDLE HidDeviceObject,
+                OUT PVOID ReportBuffer,
+                IN ULONG ReportBufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_FEATURE,
+                         NULL, 0,
+                         ReportBuffer, ReportBufferLength,
+                         &RetLen, NULL);
 }
 
 
@@ -88,6 +171,174 @@
 
 
 /*
+ * HidD_GetInputReport							EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetInputReport(IN HANDLE HidDeviceObject,
+                    IN OUT PVOID ReportBuffer,
+                    IN ULONG ReportBufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_INPUT_REPORT,
+                         NULL, 0,
+                         ReportBuffer, ReportBufferLength,
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_GetManufacturerString						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetManufacturerString(IN HANDLE HidDeviceObject,
+                           OUT PVOID Buffer,
+                           IN ULONG BufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_MANUFACTURER_STRING,
+                         NULL, 0,
+                         Buffer, BufferLength,
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_GetNumInputBuffers						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetNumInputBuffers(IN HANDLE HidDeviceObject,
+                        OUT PULONG NumberBuffers)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS,
+                         NULL, 0,
+                         NumberBuffers, sizeof(ULONG),
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_GetPhysicalDescriptor						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetPhysicalDescriptor(IN HANDLE HidDeviceObject,
+                           OUT PVOID Buffer,
+                           IN ULONG BufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_GET_PHYSICAL_DESCRIPTOR,
+                         NULL, 0,
+                         Buffer, BufferLength,
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_GetPreparsedData						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetPreparsedData(IN HANDLE HidDeviceObject,
+                      OUT PHIDP_PREPARSED_DATA *PreparsedData)
+{
+  HID_COLLECTION_INFORMATION hci;
+  DWORD RetLen;
+  BOOL Ret;
+  
+  if(PreparsedData == NULL)
+  {
+    return FALSE;
+  }
+  
+  if(!DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_COLLECTION_INFORMATION,
+                                       NULL, 0,
+                                       &hci, sizeof(HID_COLLECTION_INFORMATION),
+                                       &RetLen, NULL))
+  {
+    return FALSE;
+  }
+  
+  *PreparsedData = LocalAlloc(LHND, hci.DescriptorSize);
+  if(*PreparsedData == NULL)
+  {
+    SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+    return FALSE;
+  }
+  
+  Ret = DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_COLLECTION_DESCRIPTOR,
+                        NULL, 0,
+                        *PreparsedData, hci.DescriptorSize,
+                        &RetLen, NULL);
+
+  if(!Ret)
+  {
+    /* FIXME - Free the buffer in case we failed to get the descriptor? */
+    LocalFree((HLOCAL)*PreparsedData);
+  }
+#if 0
+  else
+  {
+    /* should we truncate the memory in case RetLen < hci.DescriptorSize? */
+  }
+#endif
+
+  return Ret;
+}
+
+
+/*
+ * HidD_GetProductString						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetProductString(IN HANDLE HidDeviceObject,
+                      OUT PVOID Buffer,
+                      IN ULONG BufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_PRODUCT_STRING,
+                         NULL, 0,
+                         Buffer, BufferLength,
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_GetSerialNumberString						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_GetSerialNumberString(IN HANDLE HidDeviceObject,
+                           OUT PVOID Buffer,
+                           IN ULONG BufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_SERIALNUMBER_STRING,
+                         NULL, 0,
+                         Buffer, BufferLength,
+                         &RetLen, NULL);
+}
+
+
+/*
  * HidP_GetValueCaps							EXPORTED
  *
  * @implemented
@@ -99,18 +350,19 @@
                   IN OUT PULONG ValueCapsLength,
                   IN PHIDP_PREPARSED_DATA PreparsedData)
 {
-  return HidP_GetSpecificValueCaps (ReportType, 0, 0, 0, ValueCaps, ValueCapsLength, PreparsedData);
+  return HidP_GetSpecificValueCaps(ReportType, 0, 0, 0, ValueCaps,
+                                   ValueCapsLength, PreparsedData);
 }
 
 
 /*
  * HidD_Hello								EXPORTED
  *
- * Undocumented easter egg function. It fills the buffer with "Hello\nI hate Jello\n"
- * and returns number of bytes filled in (lstrlen(Buffer) + 1 == 20)
+ * Undocumented easter egg function. It fills the buffer with "Hello\n"
+ * and returns number of bytes filled in (lstrlen(Buffer) + 1 == 7)
  *
  * Bugs: - doesn't check Buffer for NULL
- *       - always returns 20 even if BufferLength < 20 but doesn't produce a buffer overflow
+ *       - always returns 7 even if BufferLength < 7 but doesn't produce a buffer overflow
  *
  * @implemented
  */
@@ -119,11 +371,71 @@
 HidD_Hello(OUT PCHAR Buffer,
            IN ULONG BufferLength)
 {
-  const PCHAR const HelloString = "Hello\nI hate Jello\n";
-  ULONG StrSize = lstrlenA(HelloString) + sizeof(CHAR);
+  const PCHAR const HelloString = "Hello\n";
+  ULONG StrSize = (lstrlenA(HelloString) + 1) * sizeof(CHAR);
+  
+  if(BufferLength > 0)
+  {
+    memcpy(Buffer, HelloString, min(StrSize, BufferLength));
+  }
   
-  memcpy(Buffer, HelloString, min(StrSize, BufferLength));
   return StrSize;
 }
 
+
+/*
+ * HidD_SetFeature							EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_SetFeature(IN HANDLE HidDeviceObject,
+                IN PVOID ReportBuffer,
+                IN ULONG ReportBufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_FEATURE,
+                         ReportBuffer, ReportBufferLength,
+                         NULL, 0,
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_SetNumInputBuffers						EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_SetNumInputBuffers(IN HANDLE HidDeviceObject,
+                        IN ULONG NumberBuffers)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS,
+                         &NumberBuffers, sizeof(ULONG),
+                         NULL, 0,
+                         &RetLen, NULL);
+}
+
+
+/*
+ * HidD_SetOutputReport							EXPORTED
+ *
+ * @implemented
+ */
+HIDAPI
+BOOLEAN DDKAPI
+HidD_SetOutputReport(IN HANDLE HidDeviceObject,
+                     IN PVOID ReportBuffer,
+                     IN ULONG ReportBufferLength)
+{
+  DWORD RetLen;
+  return DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_OUTPUT_REPORT,
+                         ReportBuffer, ReportBufferLength,
+                         NULL, 0,
+                         &RetLen, NULL);
+}
+
 /* EOF */

reactos/lib/hid
stubs.c 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- stubs.c	12 Jul 2004 16:04:37 -0000	1.2
+++ stubs.c	9 Aug 2004 16:02:43 -0000	1.3
@@ -1,4 +1,4 @@
-/* $Id: stubs.c,v 1.2 2004/07/12 16:04:37 weiden Exp $
+/* $Id: stubs.c,v 1.3 2004/08/09 16:02:43 weiden Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS Hid User Library
@@ -22,43 +22,6 @@
  */
 HIDAPI
 BOOLEAN DDKAPI
-HidD_FlushQueue(IN HANDLE HidDeviceObject)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_GetAttributes(IN HANDLE HidDeviceObject,
-                   OUT PHIDD_ATTRIBUTES Attributes)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
 HidD_GetConfiguration(IN HANDLE HidDeviceObject,
                       OUT PHIDD_CONFIGURATION Configuration,
                       IN ULONG ConfigurationLength)
@@ -73,20 +36,6 @@
  */
 HIDAPI
 BOOLEAN DDKAPI
-HidD_GetFeature(IN HANDLE HidDeviceObject,
-                OUT PVOID ReportBuffer,
-                IN ULONG ReportBufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
 HidD_GetIndexedString(IN HANDLE HidDeviceObject,
                       IN ULONG StringIndex,
                       OUT PVOID Buffer,
@@ -102,34 +51,6 @@
  */
 HIDAPI
 BOOLEAN DDKAPI
-HidD_GetInputReport(IN HANDLE HidDeviceObject,
-                    IN OUT PVOID ReportBuffer,
-                    IN ULONG ReportBufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_GetManufacturerString(IN HANDLE HidDeviceObject,
-                           OUT PVOID Buffer,
-                           IN ULONG BufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
 HidD_GetMsGenreDescriptor(IN HANDLE HidDeviceObject,
                           OUT PVOID Buffer,
                           IN ULONG BufferLength)
@@ -144,74 +65,6 @@
  */
 HIDAPI
 BOOLEAN DDKAPI
-HidD_GetNumInputBuffers(IN HANDLE HidDeviceObject,
-                        OUT PULONG NumberBuffers)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_GetPhysicalDescriptor(IN HANDLE HidDeviceObject,
-                           OUT PVOID Buffer,
-                           IN ULONG BufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_GetPreparsedData(IN HANDLE HidDeviceObject,
-                      OUT PHIDP_PREPARSED_DATA *PreparsedData)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_GetProductString(IN HANDLE HidDeviceObject,
-                      OUT PVOID Buffer,
-                      IN ULONG BufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_GetSerialNumberString(IN HANDLE HidDeviceObject,
-                           OUT PVOID Buffer,
-                           IN ULONG BufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
 HidD_SetConfiguration(IN HANDLE HidDeviceObject,
                       IN PHIDD_CONFIGURATION Configuration,
                       IN ULONG ConfigurationLength)
@@ -225,47 +78,6 @@
  * @unimplemented
  */
 HIDAPI
-BOOLEAN DDKAPI
-HidD_SetFeature(IN HANDLE HidDeviceObject,
-                IN PVOID ReportBuffer,
-                IN ULONG ReportBufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_SetNumInputBuffers(IN HANDLE  HidDeviceObject,
-                        OUT ULONG  NumberBuffers)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
-BOOLEAN DDKAPI
-HidD_SetOutputReport(IN HANDLE HidDeviceObject,
-                     IN PVOID ReportBuffer,
-                     IN ULONG ReportBufferLength)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
-
-/*
- * @unimplemented
- */
-HIDAPI
 NTSTATUS DDKAPI
 HidP_GetCaps(IN PHIDP_PREPARSED_DATA PreparsedData,
              OUT PHIDP_CAPS Capabilities)
CVSspam 0.2.8