ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

hid.c
Go to the documentation of this file.
00001 /*
00002  * ReactOS Hid User Library
00003  * Copyright (C) 2004-2005 ReactOS Team
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 /* $Id: hid.c 55555 2012-02-12 04:59:51Z cgutman $
00020  *
00021  * PROJECT:         ReactOS Hid User Library
00022  * FILE:            lib/hid/hid.c
00023  * PURPOSE:         ReactOS Hid User Library
00024  * PROGRAMMER:      Thomas Weidenmueller <w3seek@reactos.com>
00025  *
00026  * UPDATE HISTORY:
00027  *      07/12/2004  Created
00028  */
00029 #include <precomp.h>
00030 
00031 HINSTANCE hDllInstance;
00032 
00033 /* device interface GUID for HIDClass devices */
00034 const GUID HidClassGuid = {0x4D1E55B2, 0xF16F, 0x11CF, {0x88,0xCB,0x00,0x11,0x11,0x00,0x00,0x30}};
00035 
00036 BOOL WINAPI
00037 DllMain(HINSTANCE hinstDLL,
00038         DWORD dwReason,
00039         LPVOID lpvReserved)
00040 {
00041   switch(dwReason)
00042   {
00043     case DLL_PROCESS_ATTACH:
00044       hDllInstance = hinstDLL;
00045       break;
00046 
00047     case DLL_THREAD_ATTACH:
00048       break;
00049 
00050     case DLL_THREAD_DETACH:
00051       break;
00052 
00053     case DLL_PROCESS_DETACH:
00054       break;
00055   }
00056   return TRUE;
00057 }
00058 
00059 
00060 /*
00061  * HidD_FlushQueue                          EXPORTED
00062  *
00063  * @implemented
00064  */
00065 HIDAPI
00066 BOOLEAN WINAPI
00067 HidD_FlushQueue(IN HANDLE HidDeviceObject)
00068 {
00069   DWORD RetLen;
00070   return DeviceIoControl(HidDeviceObject, IOCTL_HID_FLUSH_QUEUE,
00071                          NULL, 0,
00072                          NULL, 0,
00073                          &RetLen, NULL) != 0;
00074 }
00075 
00076 
00077 /*
00078  * HidD_FreePreparsedData                       EXPORTED
00079  *
00080  * @implemented
00081  */
00082 HIDAPI
00083 BOOLEAN WINAPI
00084 HidD_FreePreparsedData(IN PHIDP_PREPARSED_DATA PreparsedData)
00085 {
00086   return (LocalFree((HLOCAL)PreparsedData) == NULL);
00087 }
00088 
00089 
00090 /*
00091  * HidD_GetAttributes                           EXPORTED
00092  *
00093  * @implemented
00094  */
00095 HIDAPI
00096 BOOLEAN WINAPI
00097 HidD_GetAttributes(IN HANDLE HidDeviceObject,
00098                    OUT PHIDD_ATTRIBUTES Attributes)
00099 {
00100   HID_COLLECTION_INFORMATION hci;
00101   DWORD RetLen;
00102 
00103   if(!DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_COLLECTION_INFORMATION,
00104                                        NULL, 0,
00105                                        &hci, sizeof(HID_COLLECTION_INFORMATION),
00106                                        &RetLen, NULL))
00107   {
00108     return FALSE;
00109   }
00110 
00111   /* copy the fields */
00112   Attributes->Size = sizeof(HIDD_ATTRIBUTES);
00113   Attributes->VendorID = hci.VendorID;
00114   Attributes->ProductID = hci.ProductID;
00115   Attributes->VersionNumber = hci.VersionNumber;
00116 
00117   return TRUE;
00118 }
00119 
00120 
00121 /*
00122  * HidP_GetButtonCaps                           EXPORTED
00123  *
00124  * @implemented
00125  */
00126 HIDAPI
00127 NTSTATUS WINAPI
00128 HidP_GetButtonCaps(IN HIDP_REPORT_TYPE ReportType,
00129                    OUT PHIDP_BUTTON_CAPS ButtonCaps,
00130                    IN OUT PULONG ButtonCapsLength,
00131                    IN PHIDP_PREPARSED_DATA PreparsedData)
00132 {
00133   return HidP_GetSpecificButtonCaps(ReportType, 0, 0, 0, ButtonCaps,
00134                                     ButtonCapsLength, PreparsedData);
00135 }
00136 
00137 
00138 /*
00139  * HidD_GetFeature                          EXPORTED
00140  *
00141  * @implemented
00142  */
00143 HIDAPI
00144 BOOLEAN WINAPI
00145 HidD_GetFeature(IN HANDLE HidDeviceObject,
00146                 OUT PVOID ReportBuffer,
00147                 IN ULONG ReportBufferLength)
00148 {
00149   DWORD RetLen;
00150   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_FEATURE,
00151                          NULL, 0,
00152                          ReportBuffer, ReportBufferLength,
00153                          &RetLen, NULL) != 0;
00154 }
00155 
00156 
00157 /*
00158  * HidD_GetHidGuid                          EXPORTED
00159  *
00160  * @implemented
00161  */
00162 HIDAPI
00163 VOID WINAPI
00164 HidD_GetHidGuid(OUT LPGUID HidGuid)
00165 {
00166   *HidGuid = HidClassGuid;
00167 }
00168 
00169 
00170 /*
00171  * HidD_GetInputReport                          EXPORTED
00172  *
00173  * @implemented
00174  */
00175 HIDAPI
00176 BOOLEAN WINAPI
00177 HidD_GetInputReport(IN HANDLE HidDeviceObject,
00178                     IN OUT PVOID ReportBuffer,
00179                     IN ULONG ReportBufferLength)
00180 {
00181   DWORD RetLen;
00182   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_INPUT_REPORT,
00183                          NULL, 0,
00184                          ReportBuffer, ReportBufferLength,
00185                          &RetLen, NULL) != 0;
00186 }
00187 
00188 
00189 /*
00190  * HidD_GetManufacturerString                       EXPORTED
00191  *
00192  * @implemented
00193  */
00194 HIDAPI
00195 BOOLEAN WINAPI
00196 HidD_GetManufacturerString(IN HANDLE HidDeviceObject,
00197                            OUT PVOID Buffer,
00198                            IN ULONG BufferLength)
00199 {
00200   DWORD RetLen;
00201   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_MANUFACTURER_STRING,
00202                          NULL, 0,
00203                          Buffer, BufferLength,
00204                          &RetLen, NULL) != 0;
00205 }
00206 
00207 
00208 /*
00209  * HidD_GetNumInputBuffers                      EXPORTED
00210  *
00211  * @implemented
00212  */
00213 HIDAPI
00214 BOOLEAN WINAPI
00215 HidD_GetNumInputBuffers(IN HANDLE HidDeviceObject,
00216                         OUT PULONG NumberBuffers)
00217 {
00218   DWORD RetLen;
00219   return DeviceIoControl(HidDeviceObject, IOCTL_GET_NUM_DEVICE_INPUT_BUFFERS,
00220                          NULL, 0,
00221                          NumberBuffers, sizeof(ULONG),
00222                          &RetLen, NULL) != 0;
00223 }
00224 
00225 
00226 /*
00227  * HidD_GetPhysicalDescriptor                       EXPORTED
00228  *
00229  * @implemented
00230  */
00231 HIDAPI
00232 BOOLEAN WINAPI
00233 HidD_GetPhysicalDescriptor(IN HANDLE HidDeviceObject,
00234                            OUT PVOID Buffer,
00235                            IN ULONG BufferLength)
00236 {
00237   DWORD RetLen;
00238   return DeviceIoControl(HidDeviceObject, IOCTL_GET_PHYSICAL_DESCRIPTOR,
00239                          NULL, 0,
00240                          Buffer, BufferLength,
00241                          &RetLen, NULL) != 0;
00242 }
00243 
00244 
00245 /*
00246  * HidD_GetPreparsedData                        EXPORTED
00247  *
00248  * @implemented
00249  */
00250 HIDAPI
00251 BOOLEAN WINAPI
00252 HidD_GetPreparsedData(IN HANDLE HidDeviceObject,
00253                       OUT PHIDP_PREPARSED_DATA *PreparsedData)
00254 {
00255   HID_COLLECTION_INFORMATION hci;
00256   DWORD RetLen;
00257   BOOLEAN Ret;
00258 
00259   if(PreparsedData == NULL)
00260   {
00261     return FALSE;
00262   }
00263 
00264   if(!DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_COLLECTION_INFORMATION,
00265                                        NULL, 0,
00266                                        &hci, sizeof(HID_COLLECTION_INFORMATION),
00267                                        &RetLen, NULL))
00268   {
00269     return FALSE;
00270   }
00271 
00272   *PreparsedData = LocalAlloc(LHND, hci.DescriptorSize);
00273   if(*PreparsedData == NULL)
00274   {
00275     SetLastError(ERROR_NOT_ENOUGH_MEMORY);
00276     return FALSE;
00277   }
00278 
00279   Ret = DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_COLLECTION_DESCRIPTOR,
00280                         NULL, 0,
00281                         *PreparsedData, hci.DescriptorSize,
00282                         &RetLen, NULL) != 0;
00283 
00284   if(!Ret)
00285   {
00286     /* FIXME - Free the buffer in case we failed to get the descriptor? */
00287     LocalFree((HLOCAL)*PreparsedData);
00288   }
00289 #if 0
00290   else
00291   {
00292     /* should we truncate the memory in case RetLen < hci.DescriptorSize? */
00293   }
00294 #endif
00295 
00296   return Ret;
00297 }
00298 
00299 
00300 /*
00301  * HidD_GetProductString                        EXPORTED
00302  *
00303  * @implemented
00304  */
00305 HIDAPI
00306 BOOLEAN WINAPI
00307 HidD_GetProductString(IN HANDLE HidDeviceObject,
00308                       OUT PVOID Buffer,
00309                       IN ULONG BufferLength)
00310 {
00311   DWORD RetLen;
00312   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_PRODUCT_STRING,
00313                          NULL, 0,
00314                          Buffer, BufferLength,
00315                          &RetLen, NULL) != 0;
00316 }
00317 
00318 
00319 /*
00320  * HidD_GetSerialNumberString                       EXPORTED
00321  *
00322  * @implemented
00323  */
00324 HIDAPI
00325 BOOLEAN WINAPI
00326 HidD_GetSerialNumberString(IN HANDLE HidDeviceObject,
00327                            OUT PVOID Buffer,
00328                            IN ULONG BufferLength)
00329 {
00330   DWORD RetLen;
00331   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_SERIALNUMBER_STRING,
00332                          NULL, 0,
00333                          Buffer, BufferLength,
00334                          &RetLen, NULL) != 0;
00335 }
00336 
00337 
00338 /*
00339  * HidP_GetValueCaps                            EXPORTED
00340  *
00341  * @implemented
00342  */
00343 HIDAPI
00344 NTSTATUS WINAPI
00345 HidP_GetValueCaps(IN HIDP_REPORT_TYPE ReportType,
00346                   OUT PHIDP_VALUE_CAPS ValueCaps,
00347                   IN OUT PULONG ValueCapsLength,
00348                   IN PHIDP_PREPARSED_DATA PreparsedData)
00349 {
00350   return HidP_GetSpecificValueCaps(ReportType, 0, 0, 0, ValueCaps,
00351                                    ValueCapsLength, PreparsedData);
00352 }
00353 
00354 
00355 /*
00356  * HidD_Hello                               EXPORTED
00357  *
00358  * Undocumented easter egg function. It fills the buffer with "Hello\n"
00359  * and returns number of bytes filled in (lstrlen(Buffer) + 1 == 7)
00360  *
00361  * Bugs: - doesn't check Buffer for NULL
00362  *       - always returns 7 even if BufferLength < 7 but doesn't produce a buffer overflow
00363  *
00364  * @implemented
00365  */
00366 HIDAPI
00367 ULONG WINAPI
00368 HidD_Hello(OUT PCHAR Buffer,
00369            IN ULONG BufferLength)
00370 {
00371   const CHAR HelloString[] = "Hello\n";
00372 
00373   if(BufferLength > 0)
00374   {
00375     memcpy(Buffer, HelloString, min(sizeof(HelloString), BufferLength));
00376   }
00377 
00378   return sizeof(HelloString);
00379 }
00380 
00381 
00382 /*
00383  * HidD_SetFeature                          EXPORTED
00384  *
00385  * @implemented
00386  */
00387 HIDAPI
00388 BOOLEAN WINAPI
00389 HidD_SetFeature(IN HANDLE HidDeviceObject,
00390                 IN PVOID ReportBuffer,
00391                 IN ULONG ReportBufferLength)
00392 {
00393   DWORD RetLen;
00394   return DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_FEATURE,
00395                          ReportBuffer, ReportBufferLength,
00396                          NULL, 0,
00397                          &RetLen, NULL) != 0;
00398 }
00399 
00400 
00401 /*
00402  * HidD_SetNumInputBuffers                      EXPORTED
00403  *
00404  * @implemented
00405  */
00406 HIDAPI
00407 BOOLEAN WINAPI
00408 HidD_SetNumInputBuffers(IN HANDLE HidDeviceObject,
00409                         IN ULONG NumberBuffers)
00410 {
00411   DWORD RetLen;
00412   return DeviceIoControl(HidDeviceObject, IOCTL_SET_NUM_DEVICE_INPUT_BUFFERS,
00413                          &NumberBuffers, sizeof(ULONG),
00414                          NULL, 0,
00415                          &RetLen, NULL) != 0;
00416 }
00417 
00418 
00419 /*
00420  * HidD_SetOutputReport                         EXPORTED
00421  *
00422  * @implemented
00423  */
00424 HIDAPI
00425 BOOLEAN WINAPI
00426 HidD_SetOutputReport(IN HANDLE HidDeviceObject,
00427                      IN PVOID ReportBuffer,
00428                      IN ULONG ReportBufferLength)
00429 {
00430   DWORD RetLen;
00431   return DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_OUTPUT_REPORT,
00432                          ReportBuffer, ReportBufferLength,
00433                          NULL, 0,
00434                          &RetLen, NULL) != 0;
00435 }
00436 
00437 /*
00438  * HidD_GetIndexedString                            EXPORTED
00439  *
00440  * @implemented
00441  */
00442 HIDAPI
00443 BOOLEAN WINAPI
00444 HidD_GetIndexedString(IN HANDLE HidDeviceObject,
00445                       IN ULONG StringIndex,
00446                       OUT PVOID Buffer,
00447                       IN ULONG BufferLength)
00448 {
00449   DWORD RetLen;
00450   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_INDEXED_STRING,
00451                          &StringIndex, sizeof(ULONG),
00452                          Buffer, BufferLength,
00453                          &RetLen, NULL) != 0;
00454 }
00455 
00456 /*
00457  * HidD_GetMsGenreDescriptor                            EXPORTED
00458  *
00459  * @implemented
00460  */
00461 HIDAPI
00462 BOOLEAN WINAPI
00463 HidD_GetMsGenreDescriptor(IN HANDLE HidDeviceObject,
00464                           OUT PVOID Buffer,
00465                           IN ULONG BufferLength)
00466 {
00467   DWORD RetLen;
00468   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_MS_GENRE_DESCRIPTOR,
00469                          0, 0,
00470                          Buffer, BufferLength,
00471                          &RetLen, NULL) != 0;
00472 }
00473 
00474 /*
00475  * HidD_GetConfiguration                            EXPORTED
00476  *
00477  * @implemented
00478  */
00479 HIDAPI
00480 BOOLEAN WINAPI
00481 HidD_GetConfiguration(IN HANDLE HidDeviceObject,
00482                       OUT PHIDD_CONFIGURATION Configuration,
00483                       IN ULONG ConfigurationLength)
00484 {
00485 
00486   // magic cookie
00487   Configuration->cookie = (PVOID)HidD_GetConfiguration;
00488 
00489   return DeviceIoControl(HidDeviceObject, IOCTL_HID_GET_DRIVER_CONFIG,
00490                          0, 0,
00491                          &Configuration->size, ConfigurationLength - sizeof(ULONG),
00492                          (PULONG)&Configuration->cookie, NULL) != 0;
00493 }
00494 
00495 /*
00496  * HidD_SetConfiguration                            EXPORTED
00497  *
00498  * @implemented
00499  */
00500 HIDAPI
00501 BOOLEAN WINAPI
00502 HidD_SetConfiguration(IN HANDLE HidDeviceObject,
00503                       IN PHIDD_CONFIGURATION Configuration,
00504                       IN ULONG ConfigurationLength)
00505 {
00506     BOOLEAN Ret = FALSE;
00507 
00508     if (Configuration->cookie == (PVOID)HidD_GetConfiguration)
00509     {
00510         Ret = DeviceIoControl(HidDeviceObject, IOCTL_HID_SET_DRIVER_CONFIG,
00511                               0, 0,
00512                               (PVOID)&Configuration->size, ConfigurationLength - sizeof(ULONG),
00513                               (PULONG)&Configuration->cookie, NULL) != 0;
00514     }
00515     else
00516     {
00517         SetLastError(ERROR_INVALID_PARAMETER);
00518     }
00519 
00520     return Ret;
00521 }
00522 
00523 /*
00524  * HidP_GetUsagesEx                         EXPORTED
00525  *
00526  * @implemented
00527  */
00528 HIDAPI
00529 NTSTATUS WINAPI
00530 HidP_GetUsagesEx(IN HIDP_REPORT_TYPE ReportType,
00531                  IN USHORT LinkCollection,
00532                  OUT PUSAGE_AND_PAGE ButtonList,
00533                  IN OUT ULONG *UsageLength,
00534                  IN PHIDP_PREPARSED_DATA PreparsedData,
00535                  IN PCHAR Report,
00536                  IN ULONG ReportLength)
00537 {
00538     return HidP_GetUsages(ReportType, ButtonList->UsagePage, LinkCollection, &ButtonList->Usage, UsageLength, PreparsedData, Report, ReportLength);
00539 }
00540 
00541 
00542 /* EOF */

Generated on Sun May 27 2012 04:23:52 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.