On Wed, 2 Mar 2005, Alex Kanavin wrote: > This is the second part, which adds necessary modifications to the rest of > the library.
The last part: obex_test application patch. -- Alexander Homepage: http://www.sensi.org/~ak/ diff -uNr -x INSTALL -x Makefile -x Makefile.in -x aclocal.m4 -x autom4te.cache -x config.cache -x config.h -x 'config.h*' -x config.log -x config.status -x configure -x depcomp -x install-sh -x missing -x mkinstalldirs -x '*.Po' -x CVS -x '*.o' -x stamp apps/ChangeLog apps-usb/ChangeLog --- apps/ChangeLog 2002-11-15 11:49:12.000000000 +0200 +++ apps-usb/ChangeLog 2005-02-23 22:52:22.000000000 +0200 @@ -1,3 +1,7 @@ +2005-02-23 Alex Kanavin <[EMAIL PROTECTED]> + + * Add client-side USB support and interface discovery + 2002-11-15 Marcel Holtmann <[EMAIL PROTECTED]> * Add Bluetooth server support diff -uNr -x INSTALL -x Makefile -x Makefile.in -x aclocal.m4 -x autom4te.cache -x config.cache -x config.h -x 'config.h*' -x config.log -x config.status -x configure -x depcomp -x install-sh -x missing -x mkinstalldirs -x '*.Po' -x CVS -x '*.o' -x stamp apps/acinclude.m4 apps-usb/acinclude.m4 --- apps/acinclude.m4 2002-11-01 14:19:14.000000000 +0200 +++ apps-usb/acinclude.m4 2005-01-25 01:34:27.000000000 +0200 @@ -27,3 +27,30 @@ AC_SUBST(BLUETOOTH_LIBS) AC_MSG_RESULT($am_cv_bluetooth_found) ]) + +dnl +dnl Check for USB library +dnl + +AC_DEFUN([USB_CHECK],[ + AC_MSG_CHECKING(for USB support) + + 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_CFLAGS="" + USB_LIBS="-lusb" + fi + + AC_SUBST(USB_CFLAGS) + AC_SUBST(USB_LIBS) + AC_MSG_RESULT($am_cv_usb_found) +]) diff -uNr -x INSTALL -x Makefile -x Makefile.in -x aclocal.m4 -x autom4te.cache -x config.cache -x config.h -x 'config.h*' -x config.log -x config.status -x configure -x depcomp -x install-sh -x missing -x mkinstalldirs -x '*.Po' -x CVS -x '*.o' -x stamp apps/configure.in apps-usb/configure.in --- apps/configure.in 2002-12-01 19:26:42.000000000 +0200 +++ apps-usb/configure.in 2005-01-25 01:35:58.000000000 +0200 @@ -18,5 +18,6 @@ AM_PATH_OPENOBEX(1.0.0) BLUETOOTH_CHECK +USB_CHECK AC_OUTPUT([Makefile src/Makefile]) diff -uNr -x INSTALL -x Makefile -x Makefile.in -x aclocal.m4 -x autom4te.cache -x config.cache -x config.h -x 'config.h*' -x config.log -x config.status -x configure -x depcomp -x install-sh -x missing -x mkinstalldirs -x '*.Po' -x CVS -x '*.o' -x stamp apps/src/Makefile.am apps-usb/src/Makefile.am --- apps/src/Makefile.am 2002-11-01 21:06:02.000000000 +0200 +++ apps-usb/src/Makefile.am 2005-01-25 01:35:35.000000000 +0200 @@ -17,7 +17,7 @@ obex_test_server.c obex_test_server.h \ obex_test_cable.c obex_test_cable.h -obex_test_LDADD = @OPENOBEX_LIBS@ @BLUETOOTH_LIBS@ libmisc.a +obex_test_LDADD = @OPENOBEX_LIBS@ @BLUETOOTH_LIBS@ @USB_LIBS@ libmisc.a obex_tcp_SOURCES = obex_tcp.c @@ -28,6 +28,6 @@ LDADD = @OPENOBEX_LIBS@ libmisc.a -INCLUDES = @OPENOBEX_CFLAGS@ @BLUETOOTH_CFLAGS@ +INCLUDES = @OPENOBEX_CFLAGS@ @BLUETOOTH_CFLAGS@ @USB_CFLAGS@ EXTRA_DIST = makefile.msc diff -uNr -x INSTALL -x Makefile -x Makefile.in -x aclocal.m4 -x autom4te.cache -x config.cache -x config.h -x 'config.h*' -x config.log -x config.status -x configure -x depcomp -x install-sh -x missing -x mkinstalldirs -x '*.Po' -x CVS -x '*.o' -x stamp apps/src/obex_test.c apps-usb/src/obex_test.c --- apps/src/obex_test.c 2002-11-15 23:18:29.000000000 +0200 +++ apps-usb/src/obex_test.c 2005-02-24 01:13:39.000000000 +0200 @@ -47,6 +47,10 @@ #include <bluetooth/rfcomm.h> #endif +#ifdef HAVE_USB +#include <usb.h> +#endif + #include <openobex/obex.h> #include "obex_test.h" @@ -147,7 +151,29 @@ return OBEX_TransportConnect(handle, (struct sockaddr *) &peer, sizeof(struct sockaddr_in)); } - + +// +// +// +void print_usb_intf_info(struct usb_obex_intf* interfaces) +{ + struct usb_dev_handle* usb_handle; + char manufacturer[256] = "\0"; + char product[256] = "\0"; + char interface_desc[256] = "\0"; + int i = 0; int len; + + while (interfaces != NULL) { + usb_handle = usb_open(interfaces->device); + len = usb_get_string_simple(usb_handle, interfaces->device->descriptor.iManufacturer, manufacturer, 256); + len = usb_get_string_simple(usb_handle, interfaces->device->descriptor.iProduct, product ,256); + len = usb_get_string_simple(usb_handle, interfaces->control_interface_description, interface_desc, 256); + usb_close(usb_handle); + printf("Interface %d: %s %s %s\n", i, manufacturer, product, interface_desc); + interfaces = interfaces->next; i++; + } +} + // // // @@ -155,13 +181,17 @@ { char cmd[10]; int end = 0; - int cobex = FALSE, tcpobex = FALSE, btobex = FALSE, r320 = FALSE; + int cobex = FALSE, tcpobex = FALSE, btobex = FALSE, r320 = FALSE, usbobex = FALSE; obex_t *handle; #ifdef HAVE_BLUETOOTH bdaddr_t bdaddr; uint8_t channel; #endif +#ifdef HAVE_USB + struct usb_obex_intf* usb_intf; +#endif + struct context global_context = {0,}; #ifndef _WIN32 @@ -181,7 +211,8 @@ tcpobex = TRUE; if( (argc >= 2) && (strcmp(argv[1], "-b") == 0 ) ) btobex = TRUE; - + if( (argc >= 2) && (strcmp(argv[1], "-u") == 0 ) ) + usbobex = TRUE; if(cobex) { #ifndef _WIN32 @@ -262,6 +293,45 @@ printf("Not implemented in Win32 yet.\n"); #endif // _WIN32 } + else if(usbobex) { + int intf_num; + switch (argc) { +#ifdef HAVE_USB + case 2: + printf("Using USB transport, querying available interfaces\n"); + if(! (handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0))) { + perror( "OBEX_Init failed"); + exit(0); + } + print_usb_intf_info(UsbOBEX_GetInterfaces(handle)); + printf("Use '%s -u interface_number' to run interactive OBEX test client\n", argv[0]); + OBEX_Cleanup(handle); + exit(0); + break; + case 3: + intf_num = atoi(argv[2]); + printf("Using USB transport \n"); + if(! (handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0))) { + perror( "OBEX_Init failed"); + exit(0); + } + + usb_intf = UsbOBEX_GetInterfaces(handle); + while (usb_intf != NULL && intf_num > 0) { + usb_intf = usb_intf->next; intf_num--; + } + if (usb_intf == NULL) { + printf( "Invalid interface number\n"); + exit(0); + } + + break; +#endif + default: + printf("Wrong number of arguments\n"); + exit(0); + } + } else { printf("Using IrDA transport\n"); if(! (handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0))) { @@ -321,6 +391,16 @@ printf("Transport not found! (Bluetooth)\n"); #endif } + if (usbobex) { +#ifdef HAVE_USB + if (UsbOBEX_TransportConnect(handle, usb_intf) < 0) { + printf("Transport connect error! (USB)\n"); + break; + } +#else + printf("Transport not found! (USB)\n"); +#endif + } else { if(IrOBEX_TransportConnect(handle, IR_SERVICE) < 0) { printf("Transport connect error! (IrDA)\n"); ------------------------------------------------------- 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