summaryrefslogtreecommitdiff
path: root/libusb
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-01-29 20:04:35 +0000
committerPete Batard <pbatard@gmail.com>2010-01-29 20:04:35 +0000
commitafe70cedf774436981defb900c5eb78d13ec13d0 (patch)
tree4e93bf005247dba8f5406c25c0d49c49ada4e99b /libusb
parent47c83183c080c866c54bcf886e535ff7db907bb8 (diff)
downloadlibusb-afe70cedf774436981defb900c5eb78d13ec13d0.tar.gz
r123: reverted the use of usb_interface in core and forced interface to be undefined always on Windows
Diffstat (limited to 'libusb')
-rw-r--r--libusb/core.c2
-rw-r--r--libusb/descriptor.c10
-rw-r--r--libusb/libusb.h19
-rw-r--r--libusb/os/windows_usb.c20
4 files changed, 24 insertions, 27 deletions
diff --git a/libusb/core.c b/libusb/core.c
index 013bc77..acc8e12 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -692,7 +692,7 @@ static const struct libusb_endpoint_descriptor *find_endpoint(
{
int iface_idx;
for (iface_idx = 0; iface_idx < config->bNumInterfaces; iface_idx++) {
- const struct libusb_interface *iface = &config->usb_interface[iface_idx];
+ const struct libusb_interface *iface = &config->interface[iface_idx];
int altsetting_idx;
for (altsetting_idx = 0; altsetting_idx < iface->num_altsetting;
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index 32cd795..6cbe23c 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -315,12 +315,12 @@ err:
static void clear_configuration(struct libusb_config_descriptor *config)
{
- if (config->usb_interface) {
+ if (config->interface) {
int i;
for (i = 0; i < config->bNumInterfaces; i++)
clear_interface((struct libusb_interface *)
- config->usb_interface + i);
- free((void *) config->usb_interface);
+ config->interface + i);
+ free((void *) config->interface);
}
if (config->extra)
free((void *) config->extra);
@@ -347,8 +347,8 @@ static int parse_configuration(struct libusb_context *ctx,
tmp = config->bNumInterfaces * sizeof(struct libusb_interface);
usb_interface = malloc(tmp);
- config->usb_interface = usb_interface;
- if (!config->usb_interface)
+ config->interface = usb_interface;
+ if (!config->interface)
return LIBUSB_ERROR_NO_MEM;
memset(usb_interface, 0, tmp);
diff --git a/libusb/libusb.h b/libusb/libusb.h
index d8b17de..277f040 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -32,12 +32,17 @@
#include <time.h>
#include <limits.h>
-// Work around for existing libusb 1.0 code that might have used "interface"
-// instead of the newer "usb_interface", in libusb_config_descriptor.
-// "interface" was changed to "usb_interface" to work around macro redefinition
-// issues on Windows platforms.
-#if !defined(OS_WINDOWS) && !defined(interface)
-#define interface usb_interface
+// 'interface' might be defined as a macro on Windows, so we need to undefine
+// it so as not to break the current libusb API, because libusb_config_descriptor
+// has an 'interface' member
+// As this could still be problematic if you include windows.h after libusb.h in
+// your sources, we attempt to detect that as well.
+#if defined(OS_WINDOWS)
+#if !defined(interface) && !defined(_WINDOWS_)
+#error "Please make sure you include both windows.h and libusb.h in your source, in that order."
+#elif defined(interface)
+#undef interface
+#endif
#endif
// MSVC doesn't know ssize_t
@@ -513,7 +518,7 @@ struct libusb_config_descriptor {
/** Array of interfaces supported by this configuration. The length of
* this array is determined by the bNumInterfaces field. */
- const struct libusb_interface *usb_interface;
+ const struct libusb_interface *interface;
/** Extra descriptors. If libusb encounters unknown configuration
* descriptors, it will store them here, should you wish to parse them. */
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index d33fbc9..c425004 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -34,11 +34,6 @@
#include <inttypes.h>
#include <objbase.h> // for string to GUID conv. requires libole32.a
-/* Prevent compilation problems on Windows platforms */
-#if defined(interface)
-#undef interface
-#endif
-
#include "libusbi.h"
#include "windows_compat.h"
#include "windows_usb.h"
@@ -343,7 +338,7 @@ static void windows_assign_endpoints(struct libusb_device *dev, int iface, int a
const struct libusb_interface_descriptor *if_desc;
if (libusb_get_config_descriptor(dev, 0, &conf_desc) == LIBUSB_SUCCESS) {
- if_desc = &conf_desc->usb_interface[iface].altsetting[altsetting];
+ if_desc = &conf_desc->interface[iface].altsetting[altsetting];
safe_free(priv->usb_interface[iface].endpoint);
priv->usb_interface[iface].endpoint = malloc(if_desc->bNumEndpoints);
if (priv->usb_interface[iface].endpoint != NULL) {
@@ -1058,7 +1053,6 @@ enum libusb_hid_report_type {
}
}
if (sanitized_short[j] == 0) {
- // TODO: change this to debug?
usbi_warn(ctx, "failure to read interface number for %s. Using default value %d",
sanitized_short, interface_number);
}
@@ -2402,20 +2396,18 @@ static int winusb_abort_transfers(struct usbi_transfer *itransfer)
struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
struct windows_device_handle_priv *handle_priv = (struct windows_device_handle_priv *)transfer->dev_handle->os_priv;
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer);
HANDLE winusb_handle;
int current_interface;
CHECK_WINUSB_AVAILABLE;
- // TODO: why don't we use transfer_priv->interface_number here???
- current_interface = interface_by_endpoint(priv, handle_priv, transfer->endpoint);
- if (current_interface < 0) {
- usbi_err(ctx, "unable to match endpoint to an open interface - cancelling abort");
+ current_interface = transfer_priv->interface_number;
+ if ((current_interface < 0) || (current_interface >= USB_MAXINTERFACES)) {
+ usbi_err(ctx, "program assertion failed: invalid interface_number");
return LIBUSB_ERROR_NOT_FOUND;
}
-
- usbi_dbg("matched endpoint %02X with interface %d", transfer->endpoint, current_interface);
+ usbi_dbg("will use interface %d", current_interface);
winusb_handle = handle_priv->interface_handle[current_interface].api_handle;