Package: libopenusb-dev
Version: 1.0.1-3

Hello,
I just tried to build some code against libopenusb-dev package, and as far as I can tell, that's not going to work.

(1) openusb-config reports that I should link with -lusb. But if I do that, I'm getting libusb 0.1, not openusb library, so link fails complaining that none of openusb functions were present - no openusb_init, no openusb_open_device, nothing. If I change link to use -lopenusb -lpthread -ldl, then

(2) I get binary which can be built, but openusb_init immediately fails trying to open /usr/lib/openusb_backend. Unfortunately linux.a is not being shipped at all, and I have some doubts that library supports static linux.a built by build process at all...

So I'm kind of lost. After rebuilding libopenusb with --enable-shared I was awareded with linux.so, which after being dropped to /usr/lib/openusb_backend seems to get things moving (modulo that openusb_init() causes sigsegv somewhere in libdbus, but first things first...). Is libopenusb really preferred API for new applications, as documentation suggests?

Sample code attached - it most probably does not do anything useful, but it should build, and should not crash before openusb_init() returns...

All tests were run on x86-64, with unstable updated as of 1 hour ago.
                                        Thanks,
                                                Petr


#include <openusb.h>

static struct openusb_request_handle rqIntr;
static openusb_intr_request_t rqIntrIntr;
static uint8_t buffer[8];

static int32_t
print_and_retry(openusb_request_handle_t rqh);

static void
initiate_intr_dumper(openusb_dev_handle_t dev)
{
   int32_t err;

   rqIntr.dev = dev;
   rqIntr.interface = 0;
   rqIntr.endpoint = 1;
   rqIntr.type = USB_TYPE_INTERRUPT;
   rqIntr.req.intr = &rqIntrIntr;
   rqIntr.cb = print_and_retry;
   rqIntr.arg = NULL;
   rqIntrIntr.interval = 10;
   rqIntrIntr.payload = buffer;
   rqIntrIntr.length = sizeof(buffer);
   rqIntrIntr.timeout = 0;
   rqIntrIntr.flags = 0;
   rqIntrIntr.result.status = -1234;
   rqIntrIntr.result.transferred_bytes = 0;
   rqIntrIntr.next = NULL;
   err = openusb_xfer_aio(&rqIntr);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Could not initiate INTR listening: %d\n", err);
   }
}

static int32_t
print_and_retry(openusb_request_handle_t rqh)
{
   printf("INTR transfer done, result %d, bytes %u\n",
          rqIntrIntr.result.status, rqIntrIntr.result.transferred_bytes);
   printf("RCVD: %02X %02X %02X %02X-%02X %02X %02X %02X\n",
          buffer[0], buffer[1], buffer[2], buffer[3],
          buffer[4], buffer[5], buffer[6], buffer[7]);
   initiate_intr_dumper(rqIntr.dev);
   return 0;
}

static void
abort_intr_dumper(void)
{
   int32_t err;

   err = openusb_abort(&rqIntr);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Abort failed: %d\n", err);
   }
}

int
main(int argc, char* argv[])
{
   int32_t err;
   openusb_handle_t handle;
   openusb_devid_t *devs;
   uint32_t numDevs;
   unsigned int instance = 0;
   openusb_dev_handle_t dev;
   openusb_ctrl_request_t ctrl;
   openusb_request_handle_t done;

   err = openusb_init(0, &handle);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Could not initialize USB: %d\n", err);
      return 100;
   }
   openusb_coldplug_callbacks_done(handle);
   openusb_set_default_timeout(handle, USB_TYPE_CONTROL, 1000);
   openusb_set_default_timeout(handle, USB_TYPE_INTERRUPT, 0);
   err = openusb_get_devids_by_vendor(handle, 0x187C, 0x0511, &devs, &numDevs);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Could not enumerate devices: %d\n", err);
      openusb_fini(handle);
      return 99;
   }
   if (numDevs < instance) {
      fprintf(stderr, "Could not find instace %u of fx (%u found)\n",
              instance, numDevs);
      openusb_free_devid_list(devs);
      openusb_fini(handle);
      return 98;
   }
   err = openusb_open_device(handle, devs[instance], USB_INIT_FAIL_FAST, &dev);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Could not open device: %d\n", err);
      openusb_free_devid_list(devs);
      openusb_fini(handle);
      return 97;
   }
   openusb_free_devid_list(devs);
   err = openusb_claim_interface(dev, 0, USB_INIT_FAIL_FAST);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Could not claim interface: %d\n", err);
      openusb_close_device(dev);
      openusb_fini(handle);
      return 96;
   }
   initiate_intr_dumper(dev);
   ctrl.setup.bmRequestType = 0x21;
   ctrl.setup.bRequest = 0x09;
   ctrl.setup.wValue = 0x0200;
   ctrl.setup.wIndex = 0x0000;
   ctrl.payload = "\x06\x00\x00\x00\x00\x00\x00\x00";
   ctrl.length = 8;
   ctrl.timeout = 1000;
   ctrl.flags = 0;
   ctrl.result.status = -1234;
   ctrl.result.transferred_bytes = 1234;
   ctrl.next = NULL;
   err = openusb_ctrl_xfer(dev, 0, 0, &ctrl);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Failed to execute control request: %d\n", err);
   } else {
      printf("OK, result: status: %d, tb %u\n", ctrl.result.status, ctrl.result.transferred_bytes);
   }
   sleep(1);
   err = openusb_poll(0, NULL, &done);
   if (err != OPENUSB_SUCCESS) {
      fprintf(stderr, "Poll failed: %d\n", err);
   }
   abort_intr_dumper();
   openusb_release_interface(dev, 0);
   openusb_close_device(dev);
   openusb_fini(handle);
   return 0;
}
CFLAGS := -W -Wall -O2

test: alienware.o
        $(CC) -o $@ $< -lopenusb -lpthread -ldl

alienware.o: alienware.c

clean:
        rm -f test alienware.o

Reply via email to