[prev in list] [next in list] [prev in thread] [next in thread]
List: libusb-devel
Subject: [Libusb-devel] Patches
From: Earl Levine <elevine () gmail ! com>
Date: 2010-01-29 18:06:48
Message-ID: 25ddf9391001291006u5b464fcfo1581c93f821869a4 () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Attached are a couple of patches I needed for my unusual application and
device:
libusb-1-bigendian.diff : Patch for libusb. I found this patch was
necessary to get my application working on big-endian platforms.
libusb-compat-0.1.2-reinit.diff : Patch for libusb-compat-0.1.2. Maybe not
useful for anyone else, I don't know. Sorry, it's a little messy, it's
actually two patches in one:
1. Allow calling usb_init() more than once
2. Find out from usb_find_devices() how many devices were removed since the
last call (alters the API)
[Attachment #5 (text/html)]
Attached are a couple of patches I needed for my unusual application and de=
vice:<br><br>libusb-1-bigendian.diff : Patch for libusb.=A0 I found this pa=
tch was necessary to get my application working on big-endian platforms.<br=
>
<br>libusb-compat-0.1.2-reinit.diff : Patch for libusb-compat-0.1.2.=A0 May=
be not useful for anyone else, I don't know.=A0 Sorry, it's a littl=
e messy, it's actually two patches in one:<br>1. Allow calling usb_init=
() more than once<br>
2. Find out from usb_find_devices() how many devices were removed since the=
last call (alters the API)<br><br>
--001636c931cacdbd70047e517fd5--
["libusb-1-bigendian.diff" (application/octet-stream)]
--- libusb-1.0.2-orig/libusb/sync.c 2009-05-29 08:21:11.000000000 -0700
+++ libusb-1.0.2/libusb/sync.c 2009-09-29 02:16:57.000000000 -0700
@@ -81,7 +81,7 @@
if (!transfer)
return LIBUSB_ERROR_NO_MEM;
- buffer = malloc(LIBUSB_CONTROL_SETUP_SIZE + wLength);
+ buffer = malloc(LIBUSB_CONTROL_SETUP_SIZE + libusb_cpu_to_le16(wLength));
if (!buffer) {
libusb_free_transfer(transfer);
return LIBUSB_ERROR_NO_MEM;
@@ -90,7 +90,7 @@
libusb_fill_control_setup(buffer, bmRequestType, bRequest, wValue, wIndex,
wLength);
if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
- memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, wLength);
+ memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, libusb_cpu_to_le16(wLength));
libusb_fill_control_transfer(transfer, dev_handle, buffer,
ctrl_transfer_cb, &completed, timeout);
["libusb-compat-0.1.2-reinit.diff" (application/octet-stream)]
diff -aur libusb-compat-0.1.2-bug2808161-fix/libusb/core.c libusb-compat-0.1.2/libusb/core.c
--- libusb-compat-0.1.2-bug2808161-fix/libusb/core.c 2009-07-06 04:16:42.000000000 -0700
+++ libusb-compat-0.1.2/libusb/core.c 2009-07-06 04:21:48.000000000 -0700
@@ -136,11 +136,22 @@
fprintf(stream, "\n");
}
+void free_usbbusses(void);
+
API_EXPORTED void usb_init(void)
{
int r;
usbi_dbg("");
+ if(ctx) {
+ /* clean up the static usb_busses */
+ free_usbbusses();
+ free(usb_busses);
+ usb_busses = NULL;
+ /* exit libusb-1.0 properly */
+ libusb_exit(ctx);
+ ctx = NULL;
+ }
if (!ctx) {
r = libusb_init(&ctx);
if (r < 0) {
@@ -237,6 +248,28 @@
return -ENOMEM;
}
+static void free_device(struct usb_device *dev);
+
+void free_usbbusses(void) {
+ /* Delete all the busses in the static list usb_busses */
+ struct usb_bus *bus = usb_busses;
+ while (bus) {
+ /* free all the devices on this bus */
+ struct usb_device *dev = bus->devices;
+ while (dev) {
+ struct usb_device *tdev = dev->next;
+ LIST_DEL(bus->devices, dev);
+ free_device(dev);
+ dev = tdev;
+ }
+
+ struct usb_bus *tbus = bus->next;
+ LIST_DEL(usb_busses, bus);
+ free(bus);
+ bus = tbus;
+ }
+}
+
API_EXPORTED int usb_find_busses(void)
{
struct usb_bus *new_busses = NULL;
@@ -562,7 +595,7 @@
free(dev);
}
-API_EXPORTED int usb_find_devices(void)
+API_EXPORTED int usb_find_devices(int *pDevicesRemoved)
{
struct usb_bus *bus;
libusb_device **dev_list;
@@ -579,6 +612,10 @@
dev_list_len = libusb_get_device_list(ctx, &dev_list);
if (dev_list_len < 0)
return compat_err(dev_list_len);
+
+ if(pDevicesRemoved) {
+ *pDevicesRemoved = 0;
+ }
for (bus = usb_busses; bus; bus = bus->next) {
struct usb_device *new_devices = NULL;
@@ -615,6 +652,9 @@
LIST_DEL(bus->devices, dev);
free_device(dev);
changes++;
+ if(pDevicesRemoved) {
+ *pDevicesRemoved = *pDevicesRemoved + 1;
+ }
}
dev = tdev;
diff -aur libusb-compat-0.1.2-bug2808161-fix/libusb/usb.h libusb-compat-0.1.2/libusb/usb.h
--- libusb-compat-0.1.2-bug2808161-fix/libusb/usb.h 2009-07-06 04:15:43.000000000 -0700
+++ libusb-compat-0.1.2/libusb/usb.h 2009-07-06 03:01:05.000000000 -0700
@@ -327,7 +327,7 @@
void usb_init(void);
void usb_set_debug(int level);
int usb_find_busses(void);
-int usb_find_devices(void);
+int usb_find_devices(int *pDevicesRemoved);
struct usb_device *usb_device(usb_dev_handle *dev);
struct usb_bus *usb_get_busses(void);
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Libusb-devel mailing list
Libusb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic