Heya,

We're trying to add USB device support to gvfs[1], and realised that
openobex' current API isn't good enough to uniquely identify USB
devices.

The patch attached add support for a "path" struct member that will be
exported, and can be used by infrastructure to figure out which openobex
interface number belongs to which physical device.

The other patch exports the Path property for USB devices in
obex-data-server.

Both patches successfully tested with the updated patch about to land in
the GNOME bugzilla.

Cheers

PS: Please CC: me as I'm not subscribed to this list

[1]: http://bugzilla.gnome.org/show_bug.cgi?id=511671
diff --git a/include/openobex/obex_const.h b/include/openobex/obex_const.h
index df03a98..d526f33 100644
--- a/include/openobex/obex_const.h
+++ b/include/openobex/obex_const.h
@@ -75,6 +75,9 @@ typedef struct {
 	char *product;
 	/** Product serial number */
 	char *serial;
+	/* Triplet to identify the device uniquely,
+	   usb:<bus num>,<device num>,<interface num> */
+	char *path;
 	/** USB device configuration description */
 	char *configuration;
 	/** Control interface description */
diff --git a/lib/usbobex.c b/lib/usbobex.c
index b12131b..6e168d0 100644
--- a/lib/usbobex.c
+++ b/lib/usbobex.c
@@ -184,6 +184,7 @@ static int get_intf_string(struct usb_dev_handle *usb_handle, char **string, int
  */
 static struct obex_usb_intf_transport_t *check_intf(struct usb_device *dev,
 					int c, int i, int a,
+					char *bus, char *device,
 					struct obex_usb_intf_transport_t *current)
 {
 	struct obex_usb_intf_transport_t *next = NULL;
@@ -210,6 +211,19 @@ static struct obex_usb_intf_transport_t *check_intf(struct usb_device *dev,
 		if (err)
 			free(next);
 		else {
+			char path[200], *s, *shortdev;
+
+			/* On MacOS X we might get 002-04a9-3139-00-00 instead of 002 for the dev. */
+			shortdev = strdup (device);
+			s = strchr(shortdev, '-');
+			if (s)
+				*s='\0';
+
+			/* Create the usb: path for the device */
+			snprintf (path, sizeof(path), "usb:%s,%s,%d", bus, shortdev, dev->config[c].interface[i].altsetting[a].bInterfaceNumber);
+			free (shortdev);
+			next->path = strdup (path);
+
 			if (current)
 				current->next = next;
 			next->prev = current;
@@ -300,7 +314,7 @@ int usbobex_find_interfaces(obex_interface_t **interfaces)
 					for (a = 0; a < dev->config[c].interface[i].num_altsetting; a++) {
 						/* Check if this interface is OBEX */
 						/* and find data interface */
-						current = check_intf(dev, c, i, a, current);
+						current = check_intf(dev, c, i, a, bus->dirname, dev->filename, current);
 					}
 				}
 			}
@@ -335,6 +349,7 @@ int usbobex_find_interfaces(obex_interface_t **interfaces)
 				current->data_interface_idle_description);
 		get_intf_string(usb_handle, &intf_array[num].usb.data_interface_active,
 				current->data_interface_active_description);
+		intf_array[num].usb.path = current->path;
 		find_obex_service_descriptor(current->extra_descriptors,
 					current->extra_descriptors_len,
 					&intf_array[num].usb.service);
@@ -374,6 +389,7 @@ void usbobex_free_interfaces(int num, obex_interface_t *intf)
 		free(intf[i].usb.data_interface_idle);
 		free(intf[i].usb.data_interface_active);
 		free(intf[i].usb.service);
+		free(intf[i].usb.path);
 		free(intf[i].usb.intf);
 	}
 
diff --git a/lib/usbobex.h b/lib/usbobex.h
index efd7a38..fedc3d6 100644
--- a/lib/usbobex.h
+++ b/lib/usbobex.h
@@ -50,6 +50,7 @@ struct obex_usb_intf_transport_t {
 	int data_endpoint_write;		/* OBEX data/slave interface write endpoint */
 	usb_dev_handle *dev_control;		/* libusb handler for control interace */
 	usb_dev_handle *dev_data;		/* libusb handler for data interface */
+	char *path;				/* Path, see path in obex_usb_intf_t */
 };
 
 /* "Union Functional Descriptor" from CDC spec 5.2.3.X
Index: src/ods-manager.c
===================================================================
--- src/ods-manager.c	(revision 2477)
+++ src/ods-manager.c	(working copy)
@@ -893,6 +893,8 @@
 								g_strdup (obex_intf[interface_number].usb.data_interface_idle));
 	g_hash_table_insert (info, "DataInterfaceActive", 
 								g_strdup (obex_intf[interface_number].usb.data_interface_active));
+	g_hash_table_insert (info, "Path", 
+								g_strdup (obex_intf[interface_number].usb.path));
 	OBEX_Cleanup(handle);
 	
 	return info;
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Openobex-users mailing list
Openobex-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/openobex-users

Reply via email to