--- include/openobex/obex_const.h | 18 +++++++++++++ lib/Makefile.am | 2 +- lib/usbobex.c | 54 +++++++++++++++++++++++++++++++++++++++++ lib/usbobex.h | 9 +++++++ 4 files changed, 82 insertions(+), 1 deletions(-)
diff --git a/include/openobex/obex_const.h b/include/openobex/obex_const.h index ea29195..df03a98 100644 --- a/include/openobex/obex_const.h +++ b/include/openobex/obex_const.h @@ -51,6 +51,22 @@ typedef struct { void * customdata; } obex_ctrans_t; +/** USB-specific OBEX service information + * provided by optional Service Identification Functional Descriptor + * (CDC WMC specification section 6.5.2.5) + */ +typedef struct { + /** Role bit mask: bit 0 is set if client, unset if server */ + uint8_t role; + /** Service UUID */ + uint8_t uuid[16]; + /** Service version */ + uint16_t version; + /** Set if the service provides/expects + * an OBEX Default Server (spec section 6.5.2.5.2) */ + int is_default_uuid; +} obex_usb_intf_service_t; + /** USB-specific OBEX interface information */ typedef struct { /** Manufacturer, e.g. Nokia */ @@ -67,6 +83,8 @@ typedef struct { char *data_interface_idle; /** Active data interface description, typically empty */ char *data_interface_active; + /** Service information descriptor, may be NULL if absent */ + obex_usb_intf_service_t *service; /** Internal information for the transport layer in the library */ struct obex_usb_intf_transport_t *intf; } obex_usb_intf_t; diff --git a/lib/Makefile.am b/lib/Makefile.am index c8f2309..f45e7da 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -22,7 +22,7 @@ libopenobex_la_CFLAGS = @CFLAG_VISIBILITY@ libopenobex_la_LDFLAGS = \ -no-undefined \ - -version-info 5:1:4 \ + -version-info 6:0:0 \ -export-symbols $(top_srcdir)/lib/obex.sym libopenobex_la_LIBADD = @USB_LIBS@ @EXTRA_LIBS@ diff --git a/lib/usbobex.c b/lib/usbobex.c index b067bac..b12131b 100644 --- a/lib/usbobex.c +++ b/lib/usbobex.c @@ -124,6 +124,7 @@ static int find_obex_data_interface(unsigned char *buffer, int buflen, struct us union_header = (struct cdc_union_desc *)buffer; break; case CDC_OBEX_TYPE: /* maybe check version */ + case CDC_OBEX_SERVICE_ID_TYPE: /* This one is handled later */ case CDC_HEADER_TYPE: break; /* for now we ignore it */ default: @@ -202,6 +203,8 @@ static struct obex_usb_intf_transport_t *check_intf(struct usb_device *dev, next->control_interface = dev->config[c].interface[i].altsetting[a].bInterfaceNumber; next->control_interface_description = dev->config[c].interface[i].altsetting[a].iInterface; next->control_setting = dev->config[c].interface[i].altsetting[a].bAlternateSetting; + next->extra_descriptors = buffer; + next->extra_descriptors_len = buflen; err = find_obex_data_interface(buffer, buflen, dev->config[c], next); if (err) @@ -219,6 +222,53 @@ static struct obex_usb_intf_transport_t *check_intf(struct usb_device *dev, } /* + * Helper function to usbobex_find_interfaces + */ +static void find_obex_service_descriptor(unsigned char *buffer, int buflen, obex_usb_intf_service_t **service) +{ + if (!buffer) { + DEBUG(2, "Weird descriptor references"); + return ; + } + while (buflen > 0) { + if (buffer[1] != USB_DT_CS_INTERFACE) { + DEBUG(2, "skipping garbage"); + goto next_desc; + } + switch (buffer[2]) { + case CDC_OBEX_SERVICE_ID_TYPE: /* we've found it */ + if (buflen < 22) /* Check descriptor size */ + DEBUG(2, "Invalid service id descriptor"); + else if (*service == NULL) { + *service = malloc(sizeof(obex_usb_intf_service_t)); + if (*service != NULL) { + const uint8_t default_uuid[16] = WMC_DEFAULT_OBEX_SERVER_UUID; + (*service)->role = buffer[3]; + memcpy((*service)->uuid, buffer+4, 16); + (*service)->version = (buffer[20]<<8)|(buffer[21]); + if (memcmp((*service)->uuid, default_uuid, 16) == 0 ) + (*service)->is_default_uuid = 1; + else + (*service)->is_default_uuid = 0; + } + } + break; + case CDC_OBEX_TYPE: /* maybe check version */ + case CDC_UNION_TYPE: + case CDC_HEADER_TYPE: + break; + default: + DEBUG(2, "Ignoring extra header, type %d, length %d", buffer[2], buffer[0]); + break; + } +next_desc: + buflen -= buffer[0]; + buffer += buffer[0]; + } +} + + +/* * Function usbobex_find_interfaces () * * Find available USBOBEX interfaces on the system @@ -285,6 +335,9 @@ 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); + find_obex_service_descriptor(current->extra_descriptors, + current->extra_descriptors_len, + &intf_array[num].usb.service); usb_close(usb_handle); current = current->next; num++; } @@ -320,6 +373,7 @@ void usbobex_free_interfaces(int num, obex_interface_t *intf) free(intf[i].usb.control_interface); free(intf[i].usb.data_interface_idle); free(intf[i].usb.data_interface_active); + free(intf[i].usb.service); free(intf[i].usb.intf); } diff --git a/lib/usbobex.h b/lib/usbobex.h index d0e1dfe..efd7a38 100644 --- a/lib/usbobex.h +++ b/lib/usbobex.h @@ -37,6 +37,8 @@ struct obex_usb_intf_transport_t { * If non-zero, use usb_get_string_simple() from * libusb to retrieve human-readable description */ + unsigned char *extra_descriptors; /* Extra master interface descriptors */ + int extra_descriptors_len; /* Length of extra descriptors */ int data_interface; /* OBEX data/slave interface */ int data_idle_setting; /* OBEX data/slave idle setting */ int data_interface_idle_description; /* OBEX data/slave interface string descriptor number @@ -74,11 +76,18 @@ struct cdc_union_desc { #define CDC_UNION_TYPE 0x06 #define CDC_COUNTRY_TYPE 0x07 #define CDC_OBEX_TYPE 0x15 +#define CDC_OBEX_SERVICE_ID_TYPE 0x19 /* Interface descriptor */ #define USB_DT_CS_INTERFACE 0x24 #define CDC_DATA_INTERFACE_TYPE 0x0a +#define WMC_DEFAULT_OBEX_SERVER_UUID \ +{ 0x02, 0xae, 0xb3, 0x20, \ +0xf6, 0x49, 0x11, 0xda, \ +0x97, 0x4d, 0x08, 0x00, \ +0x20, 0x0c, 0x9a, 0x66 } + #define USB_MAX_STRING_SIZE 256 #define USB_OBEX_TIMEOUT 10000 /* 10 seconds */ -- 1.6.0.6 ------------------------------------------------------------------------------ Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com _______________________________________________ Openobex-users mailing list Openobex-users@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/openobex-users