Hello,

here's the patch that adds support for USB transport layer via libusb to
openobex library. The patch for the obex_test application is in the next 
message. Specification for these USB OBEX interfaces is available at
http://www.usb.org/developers/devclass_docs

Devices which support this are typically post-2003 mobile phones with a
USB interface. The list of contributors to the specification includes
Ericsson, Motorola, NEC, Nokia, NTT DoCoMo and others. The only devices
which are known to work so far are my Nokia 7610 and 6630 phones, and of 
course I'd like to hear from you about other gadgets.

Please note that many phones which claim to be obex-compatible don't 
actually have a proper OBEX interface: you switch their ACM modems to OBEX 
mode instead with a special AT command. For Nokia phones the rule of thumb 
is this: if it comes with a DKU-2 cable, it has a proper OBEX interface, 
and should work with this patch. If it comes with a DKU-5 or any other 
cable, then it's using some other method and isn't compatible. The 
compatibility chart is here: 
http://www.nokia.com/nokia/0,,54698,00.html#apps

I have also added support for USB to obexftp library and application, but 
that's coming later; it works, but it's not ready for others to see yet.

To use this, you first run "obex_test -u" to get a list of USB OBEX 
interfaces on your system. Then "obex_test -u interface_number" to connect 
to one of them.

So I'd like to get your comments on the patch, and of course ultimately
have it included into openobex.

-- 
Alexander

Homepage: http://www.sensi.org/~ak/

diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/ChangeLog openobex-1.0.1-usb/ChangeLog
--- openobex-1.0.1/ChangeLog    2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/ChangeLog        2005-02-10 01:23:17.000000000 +0200
@@ -1,3 +1,7 @@
+2005-02-10 Alex Kanavin         <[EMAIL PROTECTED]>
+
+       * Support for USB transport layer and USB interface discovery
+
 2003-10-01  Marcel Holtmann  <[EMAIL PROTECTED]>
 
        * Add COPYING.LIB for LGPL stuff
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/acinclude.m4 openobex-1.0.1-usb/acinclude.m4
--- openobex-1.0.1/acinclude.m4 2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/acinclude.m4     2005-02-07 00:33:26.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.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/configure.in openobex-1.0.1-usb/configure.in
--- openobex-1.0.1/configure.in 2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-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.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/Makefile.am openobex-1.0.1-usb/src/Makefile.am
--- openobex-1.0.1/src/Makefile.am      2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/Makefile.am  2005-02-07 00:24:20.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 usb_wrap.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
Binary files openobex-1.0.1/src/btobex.o and openobex-1.0.1-usb/src/btobex.o 
differ
Binary files openobex-1.0.1/src/inobex.o and openobex-1.0.1-usb/src/inobex.o 
differ
Binary files openobex-1.0.1/src/irobex.o and openobex-1.0.1-usb/src/irobex.o 
differ
Binary files openobex-1.0.1/src/netbuf.o and openobex-1.0.1-usb/src/netbuf.o 
differ
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex.c openobex-1.0.1-usb/src/obex.c
--- openobex-1.0.1/src/obex.c   2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex.c       2005-02-10 01:29:18.000000000 +0200
@@ -50,11 +50,15 @@
 #include "obex_object.h"
 #include "obex_connect.h"
 #include "obex_client.h"
+#include "obex_const.h"
 
 #include "inobex.h"
 #ifdef HAVE_IRDA
 #include "irobex.h"
 #endif
+#ifdef HAVE_USB
+#include "usbobex.h"
+#endif
 #ifdef HAVE_BLUETOOTH
 #include "btobex.h"
 #else
@@ -69,6 +73,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 +126,39 @@
        /* Init transport */
        self->trans.type = transport;
        self->trans.connected = FALSE;
+       
+       self->usb_interfaces = NULL;
+       if ( transport == OBEX_TRANS_USB ) {
+#ifdef HAVE_USB
+               self->usb_interfaces = usbobex_find_interfaces();
+#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 */
+       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,16 +201,26 @@
  */
 void OBEX_Cleanup(obex_t *self)
 {
+       struct usb_obex_intf* next;     
+
        obex_return_if_fail(self != NULL);
        
        obex_transport_disconnect_request(self);
        obex_transport_disconnect_server(self);
-
+       
        if (self->tx_msg)
                g_netbuf_free(self->tx_msg);
        
        if (self->rx_msg)
                g_netbuf_free(self->rx_msg);
+
+       if ( self->trans.type == OBEX_TRANS_USB ) {
+               while (self->usb_interfaces != NULL) {
+                   next = self->usb_interfaces->next;
+                   free(self->usb_interfaces);
+                   self->usb_interfaces = next;
+               }
+       }
        
        free(self);
 }
@@ -1050,3 +1079,44 @@
        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");
+
+        if (self->object)       {
+                DEBUG(1, "We are busy.\n");
+                return -EBUSY;
+        }
+
+        obex_return_val_if_fail(self != NULL, -1);
+        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");
+
+       return self->usb_interfaces;
+}
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex.def openobex-1.0.1-usb/src/obex.def
--- openobex-1.0.1/src/obex.def 2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex.def     2005-02-07 01:05:06.000000000 +0200
@@ -10,6 +10,7 @@
 OBEX_GetFD
 OBEX_HandleInput
 OBEX_ServerRegister
+OBEX_ServerAccept
 OBEX_Request
 OBEX_CancelRequest
 OBEX_SetUserData
@@ -34,3 +35,5 @@
 BtOBEX_ServerRegister
 BtOBEX_TransportConnect
 FdOBEX_TransportSetup
+UsbOBEX_TransportConnect
+UsbOBEX_GetInterfaces
\ No newline at end of file
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex.h openobex-1.0.1-usb/src/obex.h
--- openobex-1.0.1/src/obex.h   2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex.h       2005-02-06 23:01:19.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
Binary files openobex-1.0.1/src/obex.o and openobex-1.0.1-usb/src/obex.o differ
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex.sym openobex-1.0.1-usb/src/obex.sym
--- openobex-1.0.1/src/obex.sym 2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex.sym     2005-02-07 01:05:37.000000000 +0200
@@ -9,6 +9,7 @@
 OBEX_GetFD
 OBEX_HandleInput
 OBEX_ServerRegister
+OBEX_ServerAccept
 OBEX_Request
 OBEX_CancelRequest
 OBEX_SetUserData
@@ -33,3 +34,5 @@
 BtOBEX_ServerRegister
 BtOBEX_TransportConnect
 FdOBEX_TransportSetup
+UsbOBEX_TransportConnect
+UsbOBEX_GetInterfaces
\ No newline at end of file
Binary files openobex-1.0.1/src/obex_client.o and 
openobex-1.0.1-usb/src/obex_client.o differ
Binary files openobex-1.0.1/src/obex_connect.o and 
openobex-1.0.1-usb/src/obex_connect.o differ
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex_const.h openobex-1.0.1-usb/src/obex_const.h
--- openobex-1.0.1/src/obex_const.h     2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex_const.h 2005-02-10 01:50:15.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).
Binary files openobex-1.0.1/src/obex_header.o and 
openobex-1.0.1-usb/src/obex_header.o differ
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex_main.h openobex-1.0.1-usb/src/obex_main.h
--- openobex-1.0.1/src/obex_main.h      2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex_main.h  2005-02-06 23:07:52.000000000 +0200
@@ -139,6 +139,9 @@
 
        obex_transport_t trans;         /* Transport being used */
        obex_ctrans_t ctrans;
+       
+       struct usb_obex_intf* usb_interfaces;   /* Used by USB OBEX transport*/
+       
        void * userdata;                /* For user */
 };
 
Binary files openobex-1.0.1/src/obex_main.o and 
openobex-1.0.1-usb/src/obex_main.o differ
Binary files openobex-1.0.1/src/obex_object.o and 
openobex-1.0.1-usb/src/obex_object.o differ
Binary files openobex-1.0.1/src/obex_server.o and 
openobex-1.0.1-usb/src/obex_server.o differ
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex_transport.c openobex-1.0.1-usb/src/obex_transport.c
--- openobex-1.0.1/src/obex_transport.c 2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex_transport.c     2005-02-01 20:27:08.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.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/obex_transport.h openobex-1.0.1-usb/src/obex_transport.h
--- openobex-1.0.1/src/obex_transport.h 2003-10-01 14:17:13.000000000 +0300
+++ openobex-1.0.1-usb/src/obex_transport.h     2005-01-24 03:22:50.000000000 
+0200
@@ -43,6 +43,9 @@
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/rfcomm.h>
 #endif /*HAVE_BLUETOOTH*/
+#ifdef HAVE_USB
+#include "usb_wrap.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 {
@@ -76,7 +82,7 @@
 int obex_transport_read(obex_t *self, int count, uint8_t *buf, int buflen);
 
 
-#endif OBEX_TRANSPORT_H
+#endif //OBEX_TRANSPORT_H
 
 
 
Binary files openobex-1.0.1/src/obex_transport.o and 
openobex-1.0.1-usb/src/obex_transport.o differ
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/usb_wrap.h openobex-1.0.1-usb/src/usb_wrap.h
--- openobex-1.0.1/src/usb_wrap.h       1970-01-01 02:00:00.000000000 +0200
+++ openobex-1.0.1-usb/src/usb_wrap.h   2005-01-24 03:46:38.000000000 +0200
@@ -0,0 +1,12 @@
+#ifndef USB_WRAP_H
+#define USB_WRAP_H
+
+#include <usb.h>
+
+struct addr_usb {
+       struct usb_obex_intf* interface;
+       usb_dev_handle* dev_control;
+       usb_dev_handle* dev_data;
+};
+
+#endif /* USB_WRAP_H */
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/usbobex.c openobex-1.0.1-usb/src/usbobex.c
--- openobex-1.0.1/src/usbobex.c        1970-01-01 02:00:00.000000000 +0200
+++ openobex-1.0.1-usb/src/usbobex.c    2005-02-10 02:07:03.000000000 +0200
@@ -0,0 +1,320 @@
+/*************************************<********************************
+ *                
+ * Filename:      usbobex.c
+ * Version:       0.1
+ * Description:   USB OBEX, USB transport for OBEX
+ * Status:        Experimental.
+ * Author:        Alex Kanavin <[EMAIL PROTECTED]>
+ * 
+ *     Copyright (c) 2005 Alex Kanavin, All Rights Reserved.
+ *
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation; either
+ *     version 2 of the License, or (at your option) any later version.
+ *
+ *     This library is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *     Lesser General Public License for more details.
+ *
+ *     You should have received a copy of the GNU Lesser General Public
+ *     License along with this library; if not, write to the Free Software
+ *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
+ *     MA  02111-1307  USA
+ *     
+ ********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_USB
+
+/* Linux case */
+
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>             /* perror */
+#include <errno.h>             /* errno and EADDRNOTAVAIL */
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+#include <usb.h>
+
+#include <obex_main.h>
+#include <usbobex.h>
+
+
+/*
+ * Function usbobex_prepare_connect (self, interface)
+ *
+ *    Prepare for USB OBEX connect
+ *
+ */
+void usbobex_prepare_connect(obex_t *self, struct usb_obex_intf *intf)
+{
+#ifndef _WIN32
+       self->trans.self.usb.interface = intf;
+#endif /* _WIN32 */
+}
+
+/*
+ * Function usbobex_find_interfaces ()
+ *
+ *    Find available USBOBEX interfaces on the system
+ */
+struct usb_obex_intf* usbobex_find_interfaces()
+{
+       struct usb_bus *busses;
+       struct usb_obex_intf *current, *next;
+       current = NULL; next = NULL;
+
+       usb_init();
+       usb_find_busses();
+       usb_find_devices();
+
+       busses = usb_get_busses();
+
+       struct usb_bus *bus;
+       int c, i, a;
+    
+       for (bus = busses; bus; bus = bus->next) {
+               struct usb_device *dev;
+    
+               for (dev = bus->devices; dev; dev = dev->next) {
+                       /* Loop through all of the configurations */
+                       for (c = 0; c < dev->descriptor.bNumConfigurations; 
c++) {
+                               /* Loop through all of the interfaces */
+                               for (i = 0; i < dev->config[c].bNumInterfaces; 
i++) {
+                                       /* Loop through all of the alternate 
settings */
+                                       for (a = 0; a < 
dev->config[c].interface[i].num_altsetting; a++) {
+                                               /* Check if this interface is 
OBEX */
+                                               if 
((dev->config[c].interface[i].altsetting[a].bInterfaceClass == USB_CDC_CLASS) 
+                                                   && 
(dev->config[c].interface[i].altsetting[a].bInterfaceSubClass == 
USB_CDC_OBEX_SUBCLASS)) { 
+                                                       /* Find the data 
interface */
+ 
+                                                       unsigned char *buffer = 
dev->config[c].interface[i].altsetting[a].extra;
+                                                       int buflen = 
dev->config[c].interface[i].altsetting[a].extralen;
+
+                                                       next = 
malloc(sizeof(struct usb_obex_intf));
+                                                       if (next == NULL)
+                                                               continue;
+                                                       next->device = dev;
+                                                        next->configuration = 
dev->config[c].bConfigurationValue;
+                                                        
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;
+
+                                                       int err = 
find_obex_data_interface(buffer, buflen, dev->config[c], next);
+                                                       if (err)
+                                                               free(next);
+                                                       else {
+                                                               if (current)
+                                                                       
current->next = next;
+                                                               next->prev = 
current;
+                                                               next->next = 
NULL;
+                                                               current = next;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       while (current && current->prev)
+               current = current->prev;
+       return current;
+}
+
+/*
+ * Helper function to usbobex_find_interfaces 
+ */
+int find_obex_data_interface(unsigned char* buffer, int buflen, struct 
usb_config_descriptor config, struct usb_obex_intf* intf)
+{
+       struct cdc_union_desc* union_header = NULL;
+
+        if (!buffer) {
+                DEBUG(2,"Weird descriptor references");
+                return -EINVAL;
+        }
+        while (buflen > 0) {
+                if (buffer [1] != USB_DT_CS_INTERFACE) {
+                        DEBUG(2,"skipping garbage");
+                        goto next_desc;
+                }
+                switch (buffer [2]) {
+                        case CDC_UNION_TYPE: /* we've found it */
+                                if (union_header) {
+                                        DEBUG(2,"More than one union 
descriptor, skiping ...");
+                                        goto next_desc;
+                                }
+                                union_header = (struct cdc_union_desc *)buffer;
+                                break;
+                        case CDC_OBEX_TYPE: /* maybe check version */
+                        case CDC_HEADER_TYPE:
+                                break; /* for now we ignore it */
+                        default:
+                                DEBUG(2, "Ignoring extra header, type %d, 
length %d", buffer[2], buffer[0]);
+                                break;
+                        }
+next_desc:
+                buflen -= buffer[0];
+                buffer += buffer[0];
+        }
+        if (!union_header) {
+                DEBUG(2,"No union descriptor, giving up\n");
+                return -ENODEV;
+        }
+       /* Found the slave interface, now find active/idle settings and 
endpoints */
+       intf->data_interface = union_header->bSlaveInterface0;
+       int c, i, a;
+       struct usb_endpoint_descriptor *ep0, *ep1;
+       int found_active = 0;
+       int found_idle = 0;
+       struct usb_bus* bus;
+
+       /* Loop through all of the interfaces */
+       for (i = 0; i < config.bNumInterfaces; i++) {
+               /* Loop through all of the alternate settings */
+               for (a = 0; a < config.interface[i].num_altsetting; a++) {
+                       /* Check if this interface is OBEX data interface*/
+                       if (config.interface[i].altsetting[a].bInterfaceNumber 
== intf->data_interface) {
+                               if 
(config.interface[i].altsetting[a].bNumEndpoints == 2) {
+                                       ep0 = 
config.interface[i].altsetting[a].endpoint;
+                                       ep1 = 
config.interface[i].altsetting[a].endpoint + 1;
+                                       if ((ep0->bEndpointAddress & 
USB_ENDPOINT_IN) && ((ep0->bmAttributes & USB_ENDPOINT_TYPE_MASK) == 
USB_ENDPOINT_TYPE_BULK) && !(ep1->bEndpointAddress & USB_ENDPOINT_IN) && 
((ep1->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK)) {
+                                               found_active = 1;
+                                               intf->data_active_setting = 
config.interface[i].altsetting[a].bAlternateSetting;
+                                               
intf->data_interface_active_description =  
config.interface[i].altsetting[a].iInterface;
+                                               intf->data_endpoint_read = 
ep0->bEndpointAddress;
+                                               intf->data_endpoint_write = 
ep1->bEndpointAddress;
+                                       }
+                                       if (!(ep0->bEndpointAddress & 
USB_ENDPOINT_IN) &&((ep0->bmAttributes & USB_ENDPOINT_TYPE_MASK) == 
USB_ENDPOINT_TYPE_BULK) && (ep1->bEndpointAddress & USB_ENDPOINT_IN) 
&&((ep1->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK)) {
+                                               found_active = 1;
+                                               intf->data_active_setting = 
config.interface[i].altsetting[a].bAlternateSetting;
+                                               
intf->data_interface_active_description =  
config.interface[i].altsetting[a].iInterface;
+                                               intf->data_endpoint_read = 
ep1->bEndpointAddress;
+                                               intf->data_endpoint_write = 
ep0->bEndpointAddress;
+                                       }
+                               }
+                               if 
(config.interface[i].altsetting[a].bNumEndpoints == 0) {
+                                       found_idle = 1;
+                                       intf->data_idle_setting = 
config.interface[i].altsetting[a].bAlternateSetting;
+                                       intf->data_interface_idle_description = 
config.interface[i].altsetting[a].iInterface;
+                               }
+                       }
+               }
+       }
+
+        if (!found_idle) {
+                DEBUG(2,"No idle setting\n");
+                return -ENODEV;
+        }
+        if (!found_active) {
+                DEBUG(2,"No active setting\n");
+                return -ENODEV;
+        }
+
+       return 0;
+}
+       
+/*
+ * Function usbobex_connect_request (self)
+ *
+ *    Open the USB connection
+ *
+ */
+int usbobex_connect_request(obex_t *self)
+{
+       int ret;
+#ifndef _WIN32
+       int mtu = 0;
+       //int len = sizeof(int);
+
+       DEBUG(4, "\n");
+
+       self->trans.self.usb.dev_control = 
usb_open(self->trans.self.usb.interface->device);
+       self->trans.self.usb.dev_data = 
usb_open(self->trans.self.usb.interface->device);
+
+        ret = usb_claim_interface(self->trans.self.usb.dev_control, 
self->trans.self.usb.interface->control_interface);
+        if(ret < 0) {
+                DEBUG(4, "Can't claim control interface %d", ret);
+                return ret;
+        }
+
+        ret = usb_claim_interface(self->trans.self.usb.dev_data, 
self->trans.self.usb.interface->data_interface);
+        if(ret < 0) {
+                DEBUG(4, "Can't claim data interface %d", ret);
+               usb_release_interface(self->trans.self.usb.dev_control, 
self->trans.self.usb.interface->control_interface);
+                return ret;
+        }
+
+       ret = usb_set_configuration(self->trans.self.usb.dev_control, 
self->trans.self.usb.interface->configuration);
+        if(ret < 0) {
+               DEBUG(4, "Can't set configuration %d", ret);
+               goto err;
+       }
+       
+        ret = usb_set_altinterface(self->trans.self.usb.dev_control, 
self->trans.self.usb.interface->control_setting);
+        if(ret < 0) {
+                DEBUG(4, "Can't set control setting %d", ret);
+                goto err;
+        }
+
+       ret = usb_set_altinterface(self->trans.self.usb.dev_data, 
self->trans.self.usb.interface->data_active_setting);
+        if(ret < 0) {
+                DEBUG(4, "Can't set data active setting %d", ret);
+                goto err;
+        }
+
+       mtu = OBEX_DEFAULT_MTU_USB;
+       self->trans.mtu = mtu;
+
+       DEBUG(2, "transport mtu=%d\n", mtu);
+
+       return 1;
+
+err:
+       usb_release_interface(self->trans.self.usb.dev_data, 
self->trans.self.usb.interface->data_interface);   
+       usb_release_interface(self->trans.self.usb.dev_control, 
self->trans.self.usb.interface->control_interface);
+       return ret;
+
+#endif /* _WIN32 */
+}
+
+/*
+ * Function usbobex_link_disconnect_request (self)
+ *
+ *    Shutdown the USB link
+ *
+ */
+int usbobex_disconnect_request(obex_t *self)
+{
+       int ret;
+#ifndef _WIN32
+       DEBUG(4, "\n");
+       if (!self->trans.self.usb.interface)
+               return 0;
+       ret = usb_set_altinterface(self->trans.self.usb.dev_data, 
self->trans.self.usb.interface->data_idle_setting);;
+       if(ret < 0)
+               DEBUG(4, "Can't set data idle setting %d", ret);
+        ret = usb_release_interface(self->trans.self.usb.dev_data, 
self->trans.self.usb.interface->data_interface);
+        if(ret < 0) 
+                DEBUG(4, "Can't release data interface %d", ret);
+        ret = usb_release_interface(self->trans.self.usb.dev_control, 
self->trans.self.usb.interface->control_interface);
+        if(ret < 0) 
+                DEBUG(4, "Can't release control interface %d", ret);
+       ret = usb_close(self->trans.self.usb.dev_data);
+        if(ret < 0)
+                DEBUG(4, "Can't close data interface %d", ret);
+        ret = usb_close(self->trans.self.usb.dev_control);
+        if(ret < 0)
+                DEBUG(4, "Can't close control interface %d", ret);
+
+#endif /* _WIN32 */
+       return ret;     
+}
+
+
+#endif /* HAVE_BLUETOOTH */
diff -uNr -x configure -x aclocal.m4 -x autom4te.cache -x config.h -x 
config.h.in -x config.log -x config.status -x depcomp -x doc -x INSTALL -x 
install-sh -x libtool -x m4macros -x Makefile -x Makefile.in -x missing -x 
mkinstalldirs -x '*.lo' -x '*.Plo' -x '*.la*' -x .libs -x stamp-h1 
openobex-1.0.1/src/usbobex.h openobex-1.0.1-usb/src/usbobex.h
--- openobex-1.0.1/src/usbobex.h        1970-01-01 02:00:00.000000000 +0200
+++ openobex-1.0.1-usb/src/usbobex.h    2005-02-10 01:55:54.000000000 +0200
@@ -0,0 +1,66 @@
+/*********************************************************************
+ *                
+ * Filename:      usbobex.h
+ * Version:       
+ * Description:   
+ * Status:        Experimental.
+ * Author:        Alex Kanavin <[EMAIL PROTECTED]>
+ * 
+ *     Copyright (c) 2005 Alex Kanavin, All Rights Reserved.
+ *     
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation; either
+ *     version 2 of the License, or (at your option) any later version.
+ *
+ *     This library is distributed in the hope that it will be useful,
+ *     but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *     Lesser General Public License for more details.
+ *
+ *     You should have received a copy of the GNU Lesser General Public
+ *     License along with this library; if not, write to the Free Software
+ *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
+ *     MA  02111-1307  USA
+ *     
+ ********************************************************************/
+
+#ifndef USBOBEX_H
+#define USBOBEX_H
+
+#include "obex_const.h"
+
+/* "Union Functional Descriptor" from CDC spec 5.2.3.X
+ * used to find data/slave OBEX interface */
+struct cdc_union_desc {
+        u_int8_t      bLength;
+        u_int8_t      bDescriptorType;
+        u_int8_t      bDescriptorSubType;
+
+        u_int8_t      bMasterInterface0;
+        u_int8_t      bSlaveInterface0;
+} __attribute__ ((packed));
+
+/* CDC class and subclass types */
+#define USB_CDC_CLASS                  0x02
+#define USB_CDC_OBEX_SUBCLASS          0x0b
+
+/* class and subclass specific descriptor types */
+#define CDC_HEADER_TYPE                 0x00
+#define CDC_CALL_MANAGEMENT_TYPE        0x01
+#define CDC_AC_MANAGEMENT_TYPE          0x02
+#define CDC_UNION_TYPE                  0x06
+#define CDC_COUNTRY_TYPE                0x07
+#define CDC_OBEX_TYPE                  0x15
+
+/* Interface descriptor */
+#define USB_DT_CS_INTERFACE             0x24
+#define CDC_DATA_INTERFACE_TYPE        0x0a
+
+
+void usbobex_prepare_connect(obex_t *self, struct usb_obex_intf* intf);
+int usbobex_connect_request(obex_t *self);
+int usbobex_disconnect_request(obex_t *self);
+struct usb_obex_intf* usbobex_find_interfaces();
+int find_obex_data_interface(unsigned char* buffer, int buflen, struct 
usb_config_descriptor config, struct usb_obex_intf* intf);
+#endif
Binary files openobex-1.0.1/src/usbobex.o and openobex-1.0.1-usb/src/usbobex.o 
differ





-------------------------------------------------------
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
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to