[libhid-discuss] Broken pipe error with at89c5131

Jacques Dirac jacquesdirac at gmail.com
Tue Nov 2 16:08:22 UTC 2010


Hi,

When I use hid_get_input_report() on a device (with at89c5131), I get
the 'Broken pipe' error. On the same device, hid_set_output_report is
working great.

Guess I'm messing up some addresses. Can someone help me out?
And is there some function to read the paths (to use in the
hid_..._report functions) from the hid tree?

Thanks in advance!


Best regards,
Jacques.



My code (based on test_libhid.c):

#include <hid.h>
#include <stdio.h>
#include <string.h>

bool match_serial_number(struct usb_dev_handle* usbdev, void* custom,
unsigned int len)
{
  bool ret;
  char* buffer = (char*)malloc(len);
  usb_get_string_simple(usbdev, usb_device(usbdev)->descriptor.iSerialNumber,
      buffer, len);
  ret = strncmp(buffer, (char*)custom, len) == 0;
  free(buffer);
  return ret;
}

int main(void)
{
  HIDInterface* hid;
  hid_return ret;

  HIDInterfaceMatcher matcher = { 0x188a, 0x1101, NULL, NULL, 0 };

  hid_set_debug(HID_DEBUG_ALL);
  hid_set_debug_stream(stderr);
  hid_set_usb_debug(0);

printf("> hid_init()\n");
  ret = hid_init();
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_init failed with return code %d\n", ret);
    return 1;
  }

printf("> hid_new_HIDInterface()\n");
  hid = hid_new_HIDInterface();
  if (hid == 0) {
    fprintf(stderr, "hid_new_HIDInterface() failed, out of memory?\n");
    return 1;
  }

printf("> hid_force_open(hid, 0, &matcher, 3)\n");
  ret = hid_force_open(hid, 0, &matcher, 3);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_force_open failed with return code %d\n", ret);
    return 1;
  }

printf("> hid_write_identification(stdout, hid)\n");
  ret = hid_write_identification(stdout, hid);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_write_identification failed with return code
%d\n", ret);
    return 1;
  }

printf("> hid_dump_tree(stdout, hid)\n");
  ret = hid_dump_tree(stdout, hid);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_dump_tree failed with return code %d\n", ret);
    return 1;
  }

  // Write:
  #define PATHLEN_IN 3
  #define SEND_PACKET_LEN 9 // @@@ ToDo: read from device
  int const PATH_IN[PATHLEN_IN] = { 0xffa00001, 0xffa00002, 0xffa00003 };
  char const PACKET[SEND_PACKET_LEN] = { 0x05, 0xB1, 0x01, 0x0A, 0x01, 0x00 };

printf("> hid_set_output_report(hid, PATH_IN, PATHLEN_IN_, PACKET,
SEND_PACKET_LEN)\n");
  ret = hid_set_output_report(hid, PATH_IN, PATHLEN_IN, PACKET,
SEND_PACKET_LEN);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_set_output_report failed with return code %d\n", ret);
  }

  // Read:
  #define PATHLEN_OUT 3
  #define RECV_PACKET_LEN 19 // @@@ ToDo: read from device
  int const PATH_OUT[PATHLEN_OUT] = { 0xffa00001, 0xffa00002, 0xffa00004 };
  char packet[RECV_PACKET_LEN];

printf("> hid_get_input_report(hid, PATH_OUT, PATHLEN_OUT, packet,
RECV_PACKET_LEN)\n");
  ret = hid_get_input_report(hid, PATH_OUT, PATHLEN_OUT, packet,
RECV_PACKET_LEN);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_get_input_report failed with return code %d\n", ret);
  }

  int i;
  for (i = 0; i < RECV_PACKET_LEN; i++) {
    printf("    packet[%d] = %x\n", i, packet[i]);
  }

printf("> hid_close(hid)\n");
  ret = hid_close(hid);
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_close failed with return code %d\n", ret);
    return 1;
  }

  hid_delete_HIDInterface(&hid);

  ret = hid_cleanup();
  if (ret != HID_RET_SUCCESS) {
    fprintf(stderr, "hid_cleanup failed with return code %d\n", ret);
    return 1;
  }

  return 0;
}



The Output:

> hid_init()
 NOTICE: hid_init(): libhid 0.2.15+20060325.0.0 is being initialized.
  TRACE: hid_init(): initialising USB subsystem...
  TRACE: hid_init(): scanning for USB busses...
  TRACE: hid_init(): scanning for USB devices...
 NOTICE: hid_init(): successfully initialised HID library.
> hid_new_HIDInterface()
  TRACE: hid_new_HIDInterface(): creating a new HIDInterface instance...
> hid_force_open(hid, 0, &matcher, 3)
  TRACE: hid_force_open(): forcefully opening a device interface
according to matching criteria...
  TRACE: hid_get_usb_handle(): acquiring handle for a USB device...
  TRACE: hid_find_usb_device(): enumerating USB busses...
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 002...
  TRACE: hid_find_usb_device(): inspecting USB device 002/002[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to
USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x07ab of USB device 002/002[0]
does not match 0x188a.
  TRACE: hid_find_usb_device(): inspecting USB device 002/001[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to
USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): no match on vendor ID.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): no match on product ID.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): vendor 0x1d6b of USB device 002/001[0]
does not match 0x188a.
  TRACE: hid_find_usb_device(): enumerating USB devices on bus 001...
  TRACE: hid_find_usb_device(): inspecting USB device 001/080[0]...
  TRACE: hid_compare_usb_device(): comparing match specifications to
USB device...
  TRACE: hid_compare_usb_device(): inspecting vendor ID...
  TRACE: hid_compare_usb_device(): match on vendor ID: 0x188a.
  TRACE: hid_compare_usb_device(): inspecting product ID...
  TRACE: hid_compare_usb_device(): match on product ID: 0x1101.
  TRACE: hid_compare_usb_device(): no custom matching function supplied.
 NOTICE: hid_find_usb_device(): found a matching USB device 001/080[0].
  TRACE: hid_force_open(): claiming USB device 001/080[0].
  TRACE: hid_os_force_claim(): failed to claim USB device 001/080[0],
trying 2 more time(s)...
  TRACE: hid_os_force_claim(): detaching kernel driver from USB device
001/080[0]...
  TRACE: hid_os_force_claim(): trying again to claim USB device 001/080[0]...
 NOTICE: hid_force_open(): successfully claimed USB device 001/080[0].
  TRACE: hid_init_parser(): initialising the HID parser for USB Device
001/080[0]...
  TRACE: hid_init_parser(): allocating space for HIDData structure...
  TRACE: hid_init_parser(): successfully allocated memory for HIDData strcture.
  TRACE: hid_init_parser(): allocating space for HIDParser structure...
  TRACE: hid_init_parser(): successfully allocated memory for
HIDParser strcture.
 NOTICE: hid_init_parser(): successfully initialised the HID parser
for USB Device 001/080[0].
  TRACE: hid_prepare_hid_descriptor(): initialising the HID descriptor
for USB device 001/080[0]...
  TRACE: hid_prepare_hid_descriptor(): retrieving HID descriptor for
USB device 001/080[0]...
 NOTICE: hid_prepare_hid_descriptor(): successfully initialised HID
descriptor for USB device 001/080[0] (36 bytes).
  TRACE: hid_prepare_report_descriptor(): initialising the report
descriptor for USB device 001/080[0]...
  TRACE: hid_prepare_report_descriptor(): retrieving report descriptor
for USB device 001/080[0]...
 NOTICE: hid_prepare_report_descriptor(): successfully initialised
report descriptor for USB device 001/080[0].
  TRACE: hid_prepare_parser(): setting up the HID parser for USB
device 001/080[0]...
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
001/080[0]...
  TRACE: hid_prepare_parser(): dumping the raw report descriptor
  TRACE: hid_prepare_parser(): 0x000: 0x06 0xa0 0xff 0x09 0x01 0xa1 0x01 0x09
  TRACE: hid_prepare_parser(): 0x008: 0x02 0x09 0x03 0x15 0x00 0x26 0xff 0x00
  TRACE: hid_prepare_parser(): 0x010: 0x75 0x08 0x95 0x13 0x81 0x02 0x09 0x04
  TRACE: hid_prepare_parser(): 0x018: 0x15 0x00 0x26 0xff 0x00 0x75 0x08 0x95
  TRACE: hid_prepare_parser(): 0x020: 0x09 0x91 0x02 0xc0
  TRACE: hid_prepare_parser(): parsing the HID tree of USB device 001/080[0]...
 NOTICE: hid_prepare_parser(): successfully set up the HID parser for
USB device 001/080[0].
 NOTICE: hid_force_open(): successfully opened USB device 001/080[0].
> hid_write_identification(stdout, hid)
device identification of HIDInterface 001/080[0]:
  dev_handle:    0x0919d0b8
  device:        0x091a3208
  location:      001/080
  manufacturer:  EATON
  product:       EATON Communication Interface
  serial number: 0004553538
> hid_dump_tree(stdout, hid)
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
001/080[0]...
  TRACE: hid_dump_tree(): iterating the parse tree for USB device 001/080[0]...
parse tree of HIDInterface 001/080[0]:
  path: 0xffa00001.0xffa00002; type: 0x80
  path: 0xffa00001.0xffa00003; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0x00000000; type: 0x80
  path: 0xffa00001.0xffa00004; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  path: 0xffa00001.0x00000000; type: 0x90
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
001/080[0]...
> hid_set_output_report(hid, PATH_IN, PATHLEN_IN_, PACKET, SEND_PACKET_LEN)
  TRACE: hid_set_output_report(): looking up report ID...
  TRACE: hid_prepare_parse_path(): preparing search path of depth 3
for parse tree of USB device 001/080[0]...
  TRACE: hid_prepare_parse_path(): search path prepared for parse tree
of USB device 001/080[0].
 NOTICE: hid_find_object(): found requested item.
  TRACE: hid_set_output_report(): sending report ID 0x00 (length: 9)
to USB device 001/080[0]...
 NOTICE: hid_set_output_report(): successfully sent report to USB
device 001/080[0].
> hid_get_input_report(hid, PATH_OUT, PATHLEN_OUT, packet, RECV_PACKET_LEN)
  TRACE: hid_get_input_report(): looking up report ID...
  TRACE: hid_prepare_parse_path(): preparing search path of depth 3
for parse tree of USB device 001/080[0]...
  TRACE: hid_prepare_parse_path(): search path prepared for parse tree
of USB device 001/080[0].
 NOTICE: hid_find_object(): found requested item.
  TRACE: hid_get_input_report(): retrieving report ID 0x00 (length:
19) from USB device 001/080[0]...
WARNING: hid_get_input_report(): failed to retrieve report from USB
device 001/080[0]:error sending control message: Broken pipe.
hid_get_input_report failed with return code 20
    packet[0] = 0
    packet[1] = 0
    packet[2] = 0
    packet[3] = 4c
    packet[4] = ffffffaa
    packet[5] = ffffffdc
    packet[6] = ffffffbf
    packet[7] = 7e
    packet[8] = ffffffa1
    packet[9] = 69
    packet[10] = ffffffb7
    packet[11] = fffffff4
    packet[12] = ffffff9f
    packet[13] = 76
    packet[14] = ffffffb7
    packet[15] = ffffffc0
    packet[16] = ffffffa2
    packet[17] = 4
    packet[18] = 8
> hid_close(hid)
  TRACE: hid_close(): closing USB device 001/080[0]...
  TRACE: hid_close(): closing handle of USB device 001/080[0]...
 NOTICE: hid_close(): successfully closed USB device 001/080[0].
  TRACE: hid_reset_parser(): resetting the HID parser for USB device
001/080[0]...
  TRACE: hid_close(): freeing memory allocated for HID parser...
  TRACE: hid_close(): resetting HIDInterface...
 NOTICE: hid_cleanup(): successfully deinitialised HID library.



More information about the libhid-discuss mailing list