Add hotplug support to the Linux backend.

There are two ways to configure hotplug support for Linux: udev, and netlink. It
is strongly recommened that udev support is used on systems that utilize udev.
We reenforce this recommendation by defaulting to --with-udev=yes at configure
time. To enable netlink support run configure with --with-udev=no. If udev
support is enabled all device enumeration is done with udev.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Bump LIBUSBX_API_VERSION for new hotplug API

And document the minimum version under which hotplug is supported

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: allow control messages on devices we can not exclusively open

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: dpriv->device will never be NULL for a valid device. remove unnecessary code that handled this case

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin/libusb_reset: reenumerate device if the device descriptor or any configuration descriptor has changed

Some background: the Linux kernel causes a device to be reenumeration when
reset if the device's descriptors have changed. Darwin does not provide
this feature but instead provides a call to force the reenumeration of
a device. This behavior is required to support the firmware update
protocol used by some devices.

This patch updates darwin_reset to check if either the device or
configuration descriptors have changed. If they have darwin_reset will
ask the OS to reenumerate the device and return LIBUSB_ERROR_NOT_FOUND
or LIBUSB_SUCCESS accordingly.

Fixes #169

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: add support for the LIBUSB_TRANSFER_ADD_ZERO_PACKET transfer flag.

The zero-length packet is sent by the async event thread if all the following
conditions are met:

1) The packet size is not a multiple of maxPacketSize, and
2) the transfer completed successfully.

References #6.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: don't assume an interval of 1 or high/super speed

This patch updates submit_iso_transfer to use the bInterval value of the
endpoint and the speed of the device to determine the last frame of the
transaction.

Fixes: #165
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
core: release the context device list when the context is deleted.

This commit fixes a memory leak in the context list patch. Devices need
to be unref'd when the context is deleted. This can happen if either 1)
the backend init fails, or 2) the context is destroyed by libusb_exit().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: fix memory leaks in the darwin backend.

There were two memory leaks in the darwin backend:
 - A CFString allocated by IORegistryEntryCreateCFProperty in darwin_get_interface()
   was not released.
 - The runloop is retained by darwin_open() but was not release by darwin_close().

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: clean up old code

For some time only one type of completion message has been in use in the darwin
backend. The commit cleans up this code. This commit also removes some code
that has never done anything useful. If a pipe has an error it probably means
the device was closed so there is nothing to do.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: return LIBUSB_ERROR_NOT_FOUND when reading the active config descriptor when the device is not configured.

fixes #172

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Core: use C99 flexible array member when possible

Fix clang warning by using C99 flexible array member instead of zero
length array gcc extension

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Add some editor meta-comments for proper tab usage

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Add INSTALL_WIN.txt eol=crlf to .gitattributes

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
examples: Only check for HAVE_SIGACTION once in Makefile.am

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Misc fixes

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Add hotplugtest to msvc project files
darwin: clean up extraneous includes

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
darwin: fix topology

The parent device should always already be in the context when a
device is processed. Use the parent device's location to find the
parent dev.

Note: we might want to replicate the notion of a locationID in the
core. If done right the parent dev could be determined in the core.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>