PERFORCE change 164376 for review
Sylvestre Gallon
syl at FreeBSD.org
Sun Jun 14 20:30:16 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=164376
Change 164376 by syl at syl_atuin on 2009/06/14 20:29:47
Add debug for libusb10.c and libusb10_desc.c.
Affected files ...
.. //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test1/test1.c#3 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#10 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#33 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.h#6 edit
.. //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#15 edit
Differences ...
==== //depot/projects/soc2009/syl_usb/libusb-tests/descriptors/test1/test1.c#3 (text+ko) ====
@@ -26,6 +26,7 @@
fprintf(stderr, "libusb_init failed\n");
return (EXIT_FAILURE);
}
+ printf("debug %i\n", ctx->debug);
if ((ret = libusb_get_device_list(ctx, &devs_list)) < 0) {
fprintf(stderr,"libusb_get_device_list failed with 0x%x error code\n",
@@ -33,6 +34,7 @@
return (EXIT_FAILURE);
}
+ perror("toto\n");
if (ret == 0) {
fprintf(stderr, "No device match or lack of permissions.\n");
return (EXIT_SUCCESS);
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb.h#10 (text+ko) ====
@@ -176,6 +176,10 @@
LIBUSB_TRANSFER_FREE_TRANSFER = 1 << 2,
};
+enum libusb_debug_level {
+ LIBUSB_DEBUG_FUNCTION=1,
+};
+
/* libusb structures */
typedef void (*libusb_pollfd_added_cb) (int fd, short events, void *user_data);
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.c#33 (text+ko) ====
@@ -111,7 +111,7 @@
}
pthread_mutex_lock(&default_context_lock);
- if (!usbi_default_context) {
+ if (usbi_default_context == NULL) {
usbi_default_context = ctx;
}
pthread_mutex_unlock(&default_context_lock);
@@ -127,6 +127,7 @@
{
GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_exit enter");
usb_remove_pollfd(ctx, ctx->ctrl_pipe[0]);
close(ctx->ctrl_pipe[0]);
close(ctx->ctrl_pipe[1]);
@@ -138,6 +139,7 @@
pthread_mutex_unlock(&default_context_lock);
free(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_exit leave");
}
/* Device handling and initialisation. */
@@ -152,6 +154,8 @@
int i;
GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_list enter");
+
usb_backend = libusb20_be_alloc_default();
if (usb_backend == NULL)
return (-1);
@@ -203,6 +207,7 @@
(*list)[i] = NULL;
libusb20_be_free(usb_backend);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_list leave");
return (i);
}
@@ -214,6 +219,10 @@
libusb_free_device_list(libusb_device **list, int unref_devices)
{
int i;
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_device_list enter");
if (list == NULL)
return ;
@@ -223,21 +232,34 @@
libusb_unref_device(list[i]);
}
free(list);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_device_list leave");
}
uint8_t
libusb_get_bus_number(libusb_device * dev)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_bus_number enter");
+
if (dev == NULL)
return (LIBUSB_ERROR_NO_DEVICE);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_bus_number leave");
return (dev->bus_number);
}
uint8_t
libusb_get_device_address(libusb_device * dev)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_address enter");
+
if (dev == NULL)
return (LIBUSB_ERROR_NO_DEVICE);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_address leave");
return (dev->device_address);
}
@@ -248,8 +270,12 @@
struct libusb_interface *pinf;
struct libusb_interface_descriptor *pdinf;
struct libusb_endpoint_descriptor *pdend;
+ libusb_context *ctx;
int i, j, k, ret;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_max_packet_size enter");
+
if (dev == NULL)
return (LIBUSB_ERROR_NO_DEVICE);
@@ -273,12 +299,18 @@
out:
libusb_free_config_descriptor(pdconf);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_max_packet_size leave");
return (ret);
}
libusb_device *
libusb_ref_device(libusb_device * dev)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_ref_device enter");
+
if (dev == NULL)
return (NULL);
@@ -286,12 +318,18 @@
dev->refcnt++;
pthread_mutex_unlock(&dev->lock);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_ref_device leave");
return (dev);
}
void
libusb_unref_device(libusb_device * dev)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_unref_device enter");
+
if (dev == NULL)
return;
@@ -307,6 +345,7 @@
libusb20_dev_free(dev->os_priv);
free(dev);
}
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_unref_device leave");
}
int
@@ -318,6 +357,9 @@
unsigned char dummy;
int err;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open enter");
+
dummy = 1;
if (devh == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -369,6 +411,7 @@
pthread_mutex_unlock(&ctx->pollfd_modify_lock);
libusb_unlock_events(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open leave");
return (0);
}
@@ -382,6 +425,9 @@
struct LIBUSB20_DEVICE_DESC_DECODED *pdesc;
int i, j;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open_device_width_vid_pid enter");
+
devh = NULL;
if ((i = libusb_get_device_list(ctx, &devs)) < 0)
@@ -397,6 +443,7 @@
}
libusb_free_device_list(devs, 1);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open_device_width_vid_pid leave");
return (devh);
}
@@ -414,6 +461,9 @@
ctx = devh->dev->ctx;
pdev = devh->os_priv;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_close enter");
+
pthread_mutex_lock(&ctx->pollfd_modify_lock);
ctx->pollfd_modify++;
pthread_mutex_unlock(&ctx->pollfd_modify_lock);
@@ -452,26 +502,39 @@
pthread_mutex_unlock(&ctx->pollfd_modify_lock);
libusb_unlock_events(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_close leave");
}
libusb_device *
libusb_get_device(libusb_device_handle * devh)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device enter");
+
if (devh == NULL)
return (NULL);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device leave");
return (devh->dev);
}
int
libusb_get_configuration(libusb_device_handle * devh, int *config)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_configuration enter");
+
if (devh == NULL || config == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
*config = libusb20_dev_get_config_index((struct libusb20_device *)
devh->dev->os_priv);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_configuration leave");
return (0);
}
@@ -483,7 +546,11 @@
libusb_set_configuration(libusb_device_handle * devh, int configuration)
{
struct libusb20_device *pdev;
+ libusb_context *ctx;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_set_configuration enter");
+
if (devh == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -491,14 +558,19 @@
libusb20_dev_set_alt_index(pdev, libusb20_dev_get_config_index(pdev),
configuration);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_set_configuration leave");
return (0);
}
int
libusb_claim_interface(libusb_device_handle * dev, int interface_number)
{
+ libusb_context *ctx;
int ret = 0;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_claim_interface enter");
+
if (dev == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -513,14 +585,19 @@
dev->claimed_interfaces |= (1 << interface_number);
pthread_mutex_unlock(&(dev->lock));
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_claim_interface leave");
return (ret);
}
int
libusb_release_interface(libusb_device_handle * dev, int interface_number)
{
+ libusb_context *ctx;
int ret;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_release_interface enter");
+
ret = 0;
if (dev == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -536,6 +613,7 @@
dev->claimed_interfaces &= ~(1 << interface_number);
pthread_mutex_unlock(&(dev->lock));
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_release_interface leave");
return (ret);
}
@@ -543,8 +621,12 @@
libusb_set_interface_alt_setting(libusb_device_handle * dev,
int interface_number, int alternate_setting)
{
+ libusb_context *ctx;
int ret;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_set_interface_alt_setting enter");
+
if (dev == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -562,6 +644,7 @@
alternate_setting) != 0)
return (LIBUSB_ERROR_OTHER);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_set_interface_alt_setting leave");
return (0);
}
@@ -569,8 +652,12 @@
libusb_clear_halt(libusb_device_handle * devh, unsigned char endpoint)
{
struct libusb20_transfer *xfer;
+ libusb_context *ctx;
int ret;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_clear_halt enter");
+
GET_XFER(xfer, endpoint, devh->os_priv);
pthread_mutex_lock(&libusb20_lock);
@@ -584,25 +671,39 @@
if (ret == 0) /* check if we have open the device */
libusb20_tr_close(xfer);
pthread_mutex_unlock(&libusb20_lock);
+
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_clear_halt leave");
return (0);
}
int
libusb_reset_device(libusb_device_handle * dev)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_reset_device enter");
+
if (dev == NULL)
return (LIBUSB20_ERROR_INVALID_PARAM);
libusb20_dev_reset(dev->os_priv);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_reset_device leave");
return (0);
}
int
libusb_kernel_driver_active(libusb_device_handle * devh, int interface)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_kernel_driver_active enter");
+
if (devh == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_kernel_driver_active leave");
return (libusb20_dev_kernel_driver_active(devh->os_priv, interface));
}
@@ -610,6 +711,10 @@
libusb_detach_kernel_driver(libusb_device_handle * devh, int interface)
{
struct libusb20_device *pdev;
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_detach_kernel_driver enter");
if (devh == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -617,6 +722,8 @@
pdev = (struct libusb20_device *)devh->dev->os_priv;
if (libusb20_dev_detach_kernel_driver(pdev, interface) == LIBUSB20_ERROR_OTHER)
return (LIBUSB_ERROR_OTHER);
+
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_detach_kernel_driver leave");
return (0);
}
@@ -627,8 +734,15 @@
int
libusb_attach_kernel_driver(libusb_device_handle * devh, int interface)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_attach_kernel_driver enter");
+
if (devh == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
+
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_attach_kernel_driver leave");
return (0);
}
@@ -639,8 +753,12 @@
{
struct libusb_transfer *xfer;
struct usb_transfer *bxfer;
+ libusb_context *ctx;
int len;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_alloc_transfer enter");
+
len = sizeof(struct libusb_transfer) +
sizeof(struct usb_transfer) +
(iso_packets * sizeof(libusb_iso_packet_descriptor));
@@ -654,6 +772,8 @@
xfer = (struct libusb_transfer *) ((uint8_t *)bxfer +
sizeof(struct usb_transfer));
+
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_alloc_transfer leave");
return (xfer);
}
@@ -661,7 +781,11 @@
libusb_free_transfer(struct libusb_transfer *xfer)
{
struct usb_transfer *bxfer;
+ libusb_context *ctx;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_transfer enter");
+
if (xfer == NULL)
return ;
@@ -674,6 +798,7 @@
free(xfer->user_data);
free(bxfer);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_transfer leave");
return;
}
@@ -719,10 +844,10 @@
if (usb_xfer->num_iso_packets > iso_packets)
usb_xfer->num_iso_packets = iso_packets;
for (i = 0 ; i < usb_xfer->num_iso_packets ; i++) {
- libusb20_tr_setup_isoc(usb_xfer,
+ libusb20_tr_setup_isoc(xfer,
usb_xfer->buffer, usb_xfer->length, i);
}
- libusb20_tr_set_total_frames(i);
+ libusb20_tr_set_total_frames(xfer, i);
break ;
case LIBUSB_TRANSFER_TYPE_BULK:
libusb20_tr_setup_bulk(xfer, usb_xfer->buffer,
@@ -865,6 +990,8 @@
ctx = xfer->dev_handle->dev->ctx;
pdev = xfer->dev_handle->os_priv;
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_submit_transfer enter");
+
usb_backend = (struct usb_transfer *) ((uint8_t *)xfer -
sizeof(struct usb_transfer));
usb_backend->transferred = 0;
@@ -950,12 +1077,18 @@
pthread_mutex_unlock(&libusb20_lock);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_submit_transfer leave");
return (0);
}
int
libusb_cancel_transfer(struct libusb_transfer *xfer)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer enter");
+
if (xfer == NULL)
return (LIBUSB_ERROR_NO_MEM);
@@ -964,6 +1097,7 @@
libusb20_tr_close(xfer->os_priv);
pthread_mutex_unlock(&libusb20_lock);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer leave");
return (0);
}
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10.h#6 (text+ko) ====
@@ -83,6 +83,20 @@
#define MAX(a,b) (((a)>(b))?(a):(b))
#define USB_TIMED_OUT (1<<0)
+static inline void
+dprintf(libusb_context *ctx, int debug, char *str)
+{
+ switch (ctx->debug) {
+ case LIBUSB_DEBUG_FUNCTION:
+ printf("LIBUSB FUNCTION : %s\n", str);
+ break ;
+ default:
+ printf("LIBUSB UNKNOW DEBUG\n");
+ break ;
+ }
+ return ;
+}
+
struct usb_pollfd {
struct libusb_pollfd pollfd;
struct list_head list;
==== //depot/projects/soc2009/syl_usb/src/lib/libusb/libusb10_desc.c#15 (text+ko) ====
@@ -32,6 +32,7 @@
#include "libusb20_desc.h"
#include "libusb20_int.h"
#include "libusb.h"
+#include "libusb10.h"
/* USB descriptors */
@@ -41,6 +42,10 @@
{
struct LIBUSB20_DEVICE_DESC_DECODED *pdesc;
struct libusb20_device *pdev;
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_descriptor enter");
if ((dev == NULL) || (desc == NULL))
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -63,6 +68,7 @@
desc->iSerialNumber = pdesc->iSerialNumber;
desc->bNumConfigurations = pdesc->bNumConfigurations;
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_descriptor leave");
return (0);
}
@@ -71,11 +77,16 @@
struct libusb_config_descriptor **config)
{
struct libusb20_device *pdev;
+ libusb_context *ctx;
uint8_t idx;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_active_config_descriptor enter");
+
pdev = dev->os_priv;
idx = libusb20_dev_get_config_index(pdev);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_active_config_descriptor leave");
return (libusb_get_config_descriptor(dev, idx, config));
}
@@ -93,9 +104,13 @@
struct libusb20_endpoint *pend;
libusb_interface_descriptor *ifd;
libusb_endpoint_descriptor *endd;
+ libusb_context *ctx;
uint8_t nif, nend, nalt, i, j, k;
uint32_t if_idx, endp_idx;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor enter");
+
if (dev == NULL || config == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -206,6 +221,7 @@
}
free(pconf);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor leave");
return (0);
}
@@ -216,8 +232,11 @@
struct LIBUSB20_DEVICE_DESC_DECODED *pdesc;
struct libusb20_device *pdev;
struct libusb20_config *pconf;
+ libusb_context *ctx;
int i;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor_by_value enter");
if (dev == NULL || config == NULL)
return (LIBUSB_ERROR_INVALID_PARAM);
@@ -234,13 +253,20 @@
free(pconf);
}
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor_by_value leave");
return (LIBUSB_ERROR_NOT_FOUND);
}
void
libusb_free_config_descriptor(struct libusb_config_descriptor *config)
{
+ libusb_context *ctx;
+
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_config_descriptor enter");
+
free(config);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_config_descriptor leave");
}
int
@@ -248,14 +274,20 @@
uint8_t desc_index, unsigned char *data, int length)
{
struct libusb20_device *pdev;
+ libusb_context *ctx;
int ret;
+ GET_CONTEXT(ctx);
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_string_descriptor_ascii enter");
+
if (dev == NULL || data == NULL)
return (LIBUSB20_ERROR_INVALID_PARAM);
pdev = dev->os_priv;
+ dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_string_descriptor_ascii leave");
if (libusb20_dev_req_string_simple_sync(pdev, desc_index,
data, length) == 0)
return (strlen(data));
+
return (LIBUSB_ERROR_OTHER);
}
More information about the p4-projects
mailing list