On Wed, 2 Mar 2005, Alex Kanavin wrote: > So here's the new version of the patch, first the part that adds usbobex.c > and .h.
This is the second part, which adds necessary modifications to the rest of the library. -- Alexander Homepage: http://www.sensi.org/~ak/ diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/ChangeLog lib-usb/ChangeLog --- lib/ChangeLog 2004-03-06 14:00:27.000000000 +0200 +++ lib-usb/ChangeLog 2005-02-23 22:52:06.000000000 +0200 @@ -1,3 +1,7 @@ +2005-02-23 Alex Kanavin <[EMAIL PROTECTED]> + + * Support for USB transport layer and USB interface discovery + 2004-03-06 Christian W. Zuckschwerdt <[EMAIL PROTECTED]> * Portability fixes, mainly replacing stdint.h with inttypes.h diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/acinclude.m4 lib-usb/acinclude.m4 --- lib/acinclude.m4 2002-10-16 01:39:02.000000000 +0300 +++ lib-usb/acinclude.m4 2005-02-23 22:36:07.000000000 +0200 @@ -54,3 +54,31 @@ AC_DEFUN([BLUETOOTH_CHECK], [ BLUETOOTH_HOOK([],failure) ]) + + +dnl +dnl USB_HOOK (script-if-usb-found, failflag) +dnl +dnl if failflag is "failure" it aborts if obex is not found. +dnl + +AC_DEFUN([USB_HOOK],[ + AC_CACHE_CHECK([for USB support],am_cv_usb_found,[ + + AC_TRY_COMPILE([#include <usb.h>], + [struct usb_dev_handle *dev;], + am_cv_usb_found=yes, + am_cv_usb_found=no)]) + + if test $am_cv_usb_found = yes; then + AC_DEFINE(HAVE_USB,1,[Define if system supports USB]) + USB_LIBS="-lusb" + fi + AC_SUBST(USB_LIBS) + ]) + +]) + +AC_DEFUN([USB_CHECK], [ + USB_HOOK([],failure) +]) diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/configure.in lib-usb/configure.in --- lib/configure.in 2003-10-01 14:15:52.000000000 +0300 +++ lib-usb/configure.in 2005-01-24 01:49:11.000000000 +0200 @@ -39,6 +39,7 @@ IRDA_CHECK BLUETOOTH_CHECK +USB_CHECK dnl Configure debug facilities AC_ARG_WITH(debug,[ --with-debug=level Debug level], diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/Makefile.am lib-usb/src/Makefile.am --- lib/src/Makefile.am 2002-10-28 23:51:18.000000000 +0200 +++ lib-usb/src/Makefile.am 2005-02-20 17:45:29.000000000 +0200 @@ -22,7 +22,8 @@ inobex.c inobex.h \ btobex.c btobex.h \ netbuf.c netbuf.h \ - irda.h irda_wrap.h + irda.h irda_wrap.h \ + usbobex.c usbobex.h libopenobex_la_LDFLAGS = \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ @@ -32,4 +33,6 @@ INCLUDES = -I$(top_srcdir)/src +libopenobex_la_LIBADD = @USB_LIBS@ + EXTRA_DIST = obex.sym obex.def makefile.msc win32compat.c windeps.dep diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/obex.c lib-usb/src/obex.c --- lib/src/obex.c 2004-01-30 21:44:30.000000000 +0200 +++ lib-usb/src/obex.c 2005-02-23 22:39:04.000000000 +0200 @@ -55,6 +55,9 @@ #ifdef HAVE_IRDA #include "irobex.h" #endif +#ifdef HAVE_USB +#include "usbobex.h" +#endif #ifdef HAVE_BLUETOOTH #include "btobex.h" #else @@ -69,6 +72,7 @@ * %OBEX_TRANS_INET : Use regular TCP/IP socket * %OBEX_TRANS_CUSTOM : Use user provided transport * %OBEX_TRANS_BLUETOOTH: Use regular Bluetooth RFCOMM socket (need the BlueZ stack) + * %OBEX_TRANS_USB: Use USB transport (libusb needed) * If you use %OBEX_TRANS_CUSTOM you must register your own * transport with OBEX_RegisterCTransport() * @eventcb: Function pointer to your event callback. @@ -121,25 +125,40 @@ /* Init transport */ self->trans.type = transport; self->trans.connected = FALSE; + if (transport == OBEX_TRANS_USB) { +#ifdef HAVE_USB + self->trans.usb_interfaces = usbobex_find_interfaces(); +#else + self->trans.usb_interfaces = NULL; +#endif + } + + + /* Safe values. + * Both self->mtu_rx and self->mtu_tx_max can be increased by app + * self->mtu_tx will be whatever the other end sneds us - Jean II */ + /* Set MTU to the maximum, if using USB transport - Alex Kanavin */ + if (transport == OBEX_TRANS_USB) { + self->mtu_rx = OBEX_DEFAULT_MTU_USB; + self->mtu_tx = OBEX_MINIMUM_MTU; + self->mtu_tx_max = OBEX_DEFAULT_MTU_USB; + } else { + self->mtu_rx = OBEX_DEFAULT_MTU; + self->mtu_tx = OBEX_MINIMUM_MTU; + self->mtu_tx_max = OBEX_DEFAULT_MTU; + } /* Allocate message buffers */ /* It's safe to allocate them smaller than OBEX_MAXIMUM_MTU * because netbuf will realloc data as needed. - Jean II */ - self->rx_msg = g_netbuf_new(OBEX_DEFAULT_MTU); + self->rx_msg = g_netbuf_new(self->mtu_rx); if (self->rx_msg == NULL) goto out_err; - self->tx_msg = g_netbuf_new(OBEX_DEFAULT_MTU); + self->tx_msg = g_netbuf_new(self->mtu_tx_max); if (self->tx_msg == NULL) goto out_err; - /* Safe values. - * Both self->mtu_rx and self->mtu_tx_max can be increased by app - * self->mtu_tx will be whatever the other end sneds us - Jean II */ - self->mtu_rx = OBEX_DEFAULT_MTU; - self->mtu_tx = OBEX_MINIMUM_MTU; - self->mtu_tx_max = OBEX_DEFAULT_MTU; - #ifndef _WIN32 /* Ignore SIGPIPE. Otherwise send() will raise it and the app will quit */ signal(SIGPIPE, SIG_IGN); @@ -182,6 +201,10 @@ */ void OBEX_Cleanup(obex_t *self) { +#ifdef HAVE_USB + struct usb_obex_intf* next; +#endif + obex_return_if_fail(self != NULL); obex_transport_disconnect_request(self); @@ -192,6 +215,16 @@ if (self->rx_msg) g_netbuf_free(self->rx_msg); + + if (self->trans.type == OBEX_TRANS_USB) { +#ifdef HAVE_USB + while (self->trans.usb_interfaces != NULL) { + next = self->trans.usb_interfaces->next; + free(self->trans.usb_interfaces); + self->trans.usb_interfaces = next; + } +#endif + } free(self); } @@ -1054,3 +1087,49 @@ return obex_transport_connect_request(self); } +/** + * UsbOBEX_TransportConnect - Connect USB transport + * @self: OBEX handle + * @interface: USB interface to connect to + * + * An easier connect function to use for USB (USB OBEX) only. + */ +int UsbOBEX_TransportConnect(obex_t *self, struct usb_obex_intf* interface) +{ + DEBUG(4, "\n"); + + obex_return_val_if_fail(self != NULL, -1); + + if (self->object) { + DEBUG(1, "We are busy.\n"); + return -EBUSY; + } + + obex_return_val_if_fail(interface != NULL, -1); + obex_return_val_if_fail(interface->device != NULL, -1); + +#ifdef HAVE_USB + usbobex_prepare_connect(self, interface); + return obex_transport_connect_request(self); +#else + return -ESOCKTNOSUPPORT; +#endif /* HAVE_USB */ +} + +/** + * UsbOBEX_GetInterfaces - Get a list of USB OBEX interfaces on the system + * @self: OBEX handle + * @interfaces: A list of USB OBEX interfaces + * + * Gets a list of USB OBEX interfaces, or NULL if there are none. + */ +struct usb_obex_intf* UsbOBEX_GetInterfaces(obex_t *self) +{ + DEBUG(4, "\n"); + +#ifdef HAVE_USB + return self->trans.usb_interfaces; +#else + return NULL; +#endif +} diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/obex.def lib-usb/src/obex.def --- lib/src/obex.def 2004-01-30 21:25:45.000000000 +0200 +++ lib-usb/src/obex.def 2005-02-20 17:06:19.000000000 +0200 @@ -38,3 +38,5 @@ BtOBEX_ServerRegister BtOBEX_TransportConnect FdOBEX_TransportSetup +UsbOBEX_TransportConnect +UsbOBEX_GetInterfaces diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/obex.h lib-usb/src/obex.h --- lib/src/obex.h 2004-03-06 13:32:56.000000000 +0200 +++ lib-usb/src/obex.h 2005-02-20 17:16:31.000000000 +0200 @@ -134,4 +134,10 @@ */ int FdOBEX_TransportSetup(obex_t *self, int rfd, int wfd, int mtu); +/* + * OBEX USB API + */ + struct usb_obex_intf* UsbOBEX_GetInterfaces(obex_t *self); + int UsbOBEX_TransportConnect(obex_t *self, struct usb_obex_intf* interface); + #endif diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/obex.sym lib-usb/src/obex.sym --- lib/src/obex.sym 2004-01-30 21:25:45.000000000 +0200 +++ lib-usb/src/obex.sym 2005-02-20 17:06:55.000000000 +0200 @@ -37,3 +37,5 @@ BtOBEX_ServerRegister BtOBEX_TransportConnect FdOBEX_TransportSetup +UsbOBEX_TransportConnect +UsbOBEX_GetInterfaces diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/obex_const.h lib-usb/src/obex_const.h --- lib/src/obex_const.h 2004-03-06 13:32:56.000000000 +0200 +++ lib-usb/src/obex_const.h 2005-02-23 22:50:25.000000000 +0200 @@ -47,6 +47,31 @@ void * customdata; } obex_ctrans_t; +struct usb_obex_intf; + +/* Structure that contains information about a USB OBEX interface + * present on the system */ +struct usb_obex_intf { + struct usb_obex_intf *prev, *next; /* Next and previous interfaces in the list */ + struct usb_device *device; /* USB device that has the interface */ + int configuration; /* Device configuration */ + int control_interface; /* OBEX master interface */ + int control_interface_description; /* OBEX master interface string descriptor number + * If non-zero, use usb_get_string_simple() from + * libusb to retrieve human-readable description + */ + int control_setting; /* OBEX master interface setting */ + 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 + * in idle setting */ + int data_active_setting; /* OBEX data/slave active setting */ + int data_interface_active_description; /* OBEX data/slave interface string descriptor number + * in active setting */ + int data_endpoint_read; /* OBEX data/slave interface read endpoint */ + int data_endpoint_write; /* OBEX data/slave interface write endpoint */ +}; + #define OBEX_CLIENT 0 #define OBEX_SERVER 1 @@ -81,6 +106,7 @@ #define OBEX_TRANS_CUSTOM 3 #define OBEX_TRANS_BLUETOOTH 4 #define OBEX_TRANS_FD 5 +#define OBEX_TRANS_USB 6 /* Standard headers */ #define OBEX_HDR_COUNT 0xc0 /* Number of objects (used by connect) */ @@ -133,6 +159,7 @@ #define OBEX_DEFAULT_MTU 1024 #define OBEX_MINIMUM_MTU 255 #define OBEX_MAXIMUM_MTU 32768 +#define OBEX_DEFAULT_MTU_USB 0xffff /* In theory max MTU is (64k-1), but that's quite big. */ /* Optimum MTU for various transport (optimum for throughput). diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/obex_transport.c lib-usb/src/obex_transport.c --- lib/src/obex_transport.c 2002-11-22 21:06:12.000000000 +0200 +++ lib-usb/src/obex_transport.c 2005-02-23 22:40:27.000000000 +0200 @@ -43,6 +43,9 @@ #ifdef HAVE_BLUETOOTH #include "btobex.h" #endif /*HAVE_BLUETOOTH*/ +#ifdef HAVE_USB +#include "usbobex.h" +#endif /*HAVE_USB*/ #include "obex_transport.h" @@ -64,6 +67,9 @@ ret = -1; } } + else if (self->trans.type == OBEX_TRANS_USB) { + ret = obex_data_indication(self, NULL, 0); + } else { struct timeval time; fd_set fdset; @@ -205,7 +211,11 @@ if (self->fd >= 0 && self->writefd >= 0) ret = 0; break; - +#ifdef HAVE_USB + case OBEX_TRANS_USB: + ret = usbobex_connect_request(self); + break; +#endif /*HAVE_USB*/ default: DEBUG(4, "Transport not implemented!\n"); break; @@ -250,6 +260,11 @@ /* no real disconnect on a file */ self->fd = self->writefd = -1; break; +#ifdef HAVE_USB + case OBEX_TRANS_USB: + usbobex_disconnect_request(self); + break; +#endif /*HAVE_USB*/ default: DEBUG(4, "Transport not implemented!\n"); break; @@ -289,7 +304,8 @@ break; #endif /*HAVE_BLUETOOTH*/ case OBEX_TRANS_FD: - /* no real listen on the file */ + case OBEX_TRANS_USB: + /* no real listen on the file or USB */ ret = 0; break; default: @@ -330,7 +346,8 @@ break; #endif /*HAVE_BLUETOOTH*/ case OBEX_TRANS_FD: - /* no real server on a file */; + case OBEX_TRANS_USB: + /* no real server on a file or USB */; break; default: DEBUG(4, "Transport not implemented!\n"); @@ -389,6 +406,16 @@ case OBEX_TRANS_FD: actual = do_write(self->writefd, msg, self->trans.mtu); break; +#ifdef HAVE_USB + case OBEX_TRANS_USB: + if (self->trans.connected != TRUE) + break; + DEBUG(4, "Endpoint %d\n", self->trans.self.usb.interface->data_endpoint_write); + actual = usb_bulk_write(self->trans.self.usb.dev_data, + self->trans.self.usb.interface->data_endpoint_write, + msg->data, msg->len, 10*1000); + break; +#endif /*HAVE_USB*/ case OBEX_TRANS_CUSTOM: DEBUG(4, "Custom write\n"); if(self->ctrans.write) @@ -427,6 +454,16 @@ case OBEX_TRANS_FD: actual = read(self->fd, msg->tail, max); break; +#ifdef HAVE_USB + case OBEX_TRANS_USB: + if (self->trans.connected != TRUE) + break; + DEBUG(4, "Endpoint %d\n", self->trans.self.usb.interface->data_endpoint_read); + actual = usb_bulk_read(self->trans.self.usb.dev_data, + self->trans.self.usb.interface->data_endpoint_read, + msg->tail, self->mtu_rx, 10*1000); + break; +#endif /*HAVE_USB*/ case OBEX_TRANS_CUSTOM: if(buflen > max) { memcpy(msg->tail, buf, max); diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x 'config.*' -x depcomp -x doc -x INSTALL -x install-sh -x libtool -x ltmain.sh -x m4macros -x Makefile -x Makefile.in -x missing -x mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x 'stamp*' -x CVS -x '*.o' -x openobex-config lib/src/obex_transport.h lib-usb/src/obex_transport.h --- lib/src/obex_transport.h 2004-03-05 11:48:49.000000000 +0200 +++ lib-usb/src/obex_transport.h 2005-02-23 22:40:57.000000000 +0200 @@ -43,6 +43,9 @@ #include <bluetooth/bluetooth.h> #include <bluetooth/rfcomm.h> #endif /*HAVE_BLUETOOTH*/ +#ifdef HAVE_USB +#include "usbobex.h" +#endif /*HAVE_USB*/ #include "obex_main.h" @@ -54,6 +57,9 @@ #ifdef HAVE_BLUETOOTH struct sockaddr_rc rfcomm; #endif /*HAVE_BLUETOOTH*/ +#ifdef HAVE_USB + struct addr_usb usb; +#endif /*HAVE_USB*/ } saddr_t; typedef struct obex_transport { @@ -62,6 +68,7 @@ unsigned int mtu; /* Tx MTU of the link */ saddr_t self; /* Source address */ saddr_t peer; /* Destination address */ + struct usb_obex_intf* usb_interfaces; /* Used by USB OBEX transport*/ } obex_transport_t; ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ linux-usb-devel@lists.sourceforge.net To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel