hid_presentation.c

Go to the documentation of this file.
00001 #define HID_INTERNAL
00002 
00003 #include <hid.h>
00004 #include <hid_helpers.h>
00005 
00006 #include <debug.h>
00007 #include <assert.h>
00008 
00009 hid_return hid_write_identification(FILE* const out,
00010     HIDInterface const* const hidif)
00011 {
00012   if (!hid_is_opened(hidif)) {
00013     ERROR("cannot write identification of unopened HIDinterface.");
00014     return HID_RET_DEVICE_NOT_OPENED;
00015   }
00016 
00017   if (!out) {
00018     ERROR("cannot write HIDinterface identification of USB device %s "
00019         "to NULL output stream.", hidif->id);
00020     return HID_RET_INVALID_PARAMETER;
00021   }
00022   
00023   int len;
00024   unsigned short const BUFLEN = 256;
00025   char buffer[BUFLEN];
00026   
00027   fprintf(out, "device identification of HIDInterface %s:\n", hidif->id);
00028   fprintf(out, "  dev_handle:    0x%08lx\n", (unsigned long)hidif->dev_handle);
00029   fprintf(out, "  device:        0x%08lx\n", (unsigned long)hidif->device);
00030   fprintf(out, "  location:      %s/%s\n",
00031       hidif->device->bus->dirname, hidif->device->filename);
00032 
00033   if (hidif->device->descriptor.iManufacturer) {
00034     len = usb_get_string_simple(hidif->dev_handle,
00035         hidif->device->descriptor.iManufacturer, buffer, BUFLEN);
00036 
00037     if (len > 0)
00038       fprintf(out, "  manufacturer:  %s\n", buffer);
00039     else
00040       fprintf(out, "(unable to fetch manufacturer string)\n");
00041   }
00042   
00043   if (hidif->device->descriptor.iProduct) {
00044     len = usb_get_string_simple(hidif->dev_handle,
00045         hidif->device->descriptor.iProduct, buffer, BUFLEN);
00046 
00047     if (len > 0)
00048       fprintf(out, "  product:       %s\n", buffer);
00049     else
00050       fprintf(out, "(unable to fetch product string)\n");
00051   }
00052   
00053   if (hidif->device->descriptor.iSerialNumber) {
00054     len = usb_get_string_simple(hidif->dev_handle,
00055         hidif->device->descriptor.iSerialNumber, buffer, BUFLEN);
00056 
00057     if (len > 0)
00058       fprintf(out, "  serial number: %s\n", buffer);
00059     else
00060       fprintf(out, "(unable to fetch product string)\n");
00061   }
00062   
00063   return HID_RET_SUCCESS;
00064 }
00065 
00066 hid_return hid_dump_tree(FILE* const out, HIDInterface* const hidif)
00067 {
00068   if (!hid_is_opened(hidif)) {
00069     ERROR("cannot dump tree of unopened HIDinterface.");
00070     return HID_RET_DEVICE_NOT_OPENED;
00071   }
00072 
00073   if (!out) {
00074     ERROR("cannot dump HIDinterface tree of USB device %s to NULL output stream.",
00075         hidif->id);
00076     return HID_RET_INVALID_PARAMETER;
00077   }
00078   
00079   hid_reset_parser(hidif);
00080   
00081   TRACE("iterating the parse tree for USB device %s...", hidif->id);
00082       
00083   unsigned int i = 0;
00084 
00085   fprintf(out, "parse tree of HIDInterface %s:\n", hidif->id);
00086 
00087   while (HIDParse(hidif->hid_parser, hidif->hid_data)) {
00088     fprintf(out, "  path: ");
00089     for (i = 0; i < hidif->hid_data->Path.Size; ++i) {
00090       fprintf(out, "0x%08x", (hidif->hid_data->Path.Node[i].UPage << 16)
00091           | hidif->hid_data->Path.Node[i].Usage);
00092       if ((signed)i < hidif->hid_data->Path.Size - 1) fputc('.', out);
00093     }
00094     fprintf(out, "; type: 0x%02x\n", hidif->hid_data->Type);
00095   }
00096 
00097   hid_reset_parser(hidif);
00098 
00099   return HID_RET_SUCCESS;
00100 }
00101 
00102 const char *hid_strerror(hid_return ret)
00103 {
00104   switch(ret) {
00105     case HID_RET_SUCCESS:
00106       return "libhid: success";
00107     case HID_RET_INVALID_PARAMETER:
00108       return "libhid: invalid parameter";
00109     case HID_RET_NOT_INITIALISED:
00110       return "libhid: not initialized; call hid_init() first";
00111     case HID_RET_ALREADY_INITIALISED:
00112       return "libhid: hid_init() already called";
00113     case HID_RET_FAIL_FIND_BUSSES:
00114       return "libhid: failed to find any USB busses";
00115     case HID_RET_FAIL_FIND_DEVICES:
00116       return "libhid: failed to find any USB devices";
00117     case HID_RET_FAIL_OPEN_DEVICE:
00118       return "libhid: failed to open device";
00119     case HID_RET_DEVICE_NOT_FOUND:
00120       return "libhid: device not found";
00121     case HID_RET_DEVICE_NOT_OPENED:
00122       return "libhid: device not yet opened";
00123     case HID_RET_DEVICE_ALREADY_OPENED:
00124       return "libhid: device already opened";
00125     case HID_RET_FAIL_CLOSE_DEVICE:
00126       return "libhid: could not close device";
00127     case HID_RET_FAIL_CLAIM_IFACE:
00128       return "libhid: failed to claim interface; is another driver using it?";
00129     case HID_RET_FAIL_DETACH_DRIVER:
00130       return "libhid: failed to detach kernel driver";
00131     case HID_RET_NOT_HID_DEVICE:
00132       return "libhid: not recognized as a HID device";
00133     case HID_RET_HID_DESC_SHORT:
00134       return "libhid: HID interface descriptor too short";
00135     case HID_RET_REPORT_DESC_SHORT:
00136       return "libhid: HID report descriptor too short";
00137     case HID_RET_REPORT_DESC_LONG:
00138       return "libhid: HID report descriptor too long";
00139     case HID_RET_FAIL_ALLOC:
00140       return "libhid: failed to allocate memory";
00141     case HID_RET_OUT_OF_SPACE:
00142       return "libhid: no space left in buffer";
00143     case HID_RET_FAIL_SET_REPORT:
00144       return "libhid: failed to set report";
00145     case HID_RET_FAIL_GET_REPORT:
00146       return "libhid: failed to get report";
00147     case HID_RET_FAIL_INT_READ:
00148       return "libhid: interrupt read failed";
00149     case HID_RET_NOT_FOUND:
00150       return "libhid: not found";
00151     case HID_RET_TIMEOUT:
00152       return "libhid: timeout";
00153   }
00154   return "libhid: unknown error";
00155 }
00156 
00157 /* COPYRIGHT --
00158  *
00159  * This file is part of libhid, a user-space HID access library.
00160  * libhid is (c) 2003-2005
00161  *   Martin F. Krafft <libhid@pobox.madduck.net>
00162  *   Charles Lepple <clepple@ghz.cc>
00163  *   Arnaud Quette <arnaud.quette@free.fr> && <arnaud.quette@mgeups.com>
00164  * and distributed under the terms of the GNU General Public License.
00165  * See the file ./COPYING in the source distribution for more information.
00166  *
00167  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
00168  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
00169  * OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00170  */

Generated on Sun Mar 30 15:28:24 2008 for libhid by  doxygen 1.5.1