From: Hendrik Sattler <p...@hendrik-sattler.de> Change obex_test so that only the compiled-in parts are visible. Prepare the bluetooth part for addition of L2CAP usage. --- apps/obex_test/obex_test.c | 135 ++++++++++++++++++++++++++------------------ 1 files changed, 80 insertions(+), 55 deletions(-)
diff --git a/apps/obex_test/obex_test.c b/apps/obex_test/obex_test.c index 0373241..93838f8 100644 --- a/apps/obex_test/obex_test.c +++ b/apps/obex_test/obex_test.c @@ -27,6 +27,11 @@ #include "../lib/bluez_compat.h" #ifdef _WIN32 bdaddr_t bluez_compat_bdaddr_any = { BTH_ADDR_NULL }; +int str2ba(const char *str, bdaddr_t *ba) { + //TODO + *ba = *BDADDR_ANY; + return 0; +} #endif #endif @@ -155,41 +160,49 @@ int main (int argc, char *argv[]) { char cmd[10]; int num, end = 0; - int cobex = FALSE, tcpobex = FALSE, btobex = FALSE, r320 = FALSE, usbobex = FALSE; - obex_t *handle; + int tcpobex = FALSE; + obex_t *handle = NULL; + struct context global_context = {0,}; + #ifdef HAVE_BLUETOOTH + int btobex = FALSE bdaddr_t bdaddr; uint8_t channel = 0; #endif - #ifdef HAVE_USB + int usbobex = FALSE; obex_interface_t *obex_intf = NULL; #endif - - struct context global_context = {0,}; - #ifndef _WIN32 - + int cobex = FALSE, r320 = FALSE; char *port; obex_ctrans_t custfunc; +#endif if( (argc == 2) && (strcmp(argv[1], "-h") == 0 ) ) { printf( "Usage: obex_test [options]\n" "\n" "Options:\n" - " -s [tty] Use cable transport (Sony-Ericsson phones/DCU-11 cable)\n" - " -r [tty] Use cable transport for R320\n" - " -i Use IP/TCP transport\n" - " -b [addr] [chan] Use bluetooth transport\n" - " -u [interface] Use USB transport\n" - " -h Print this help message\n" +#ifndef _WIN32 + " -s [tty] Use cable transport (Sony-Ericsson phones/DCU-11 cable)\n" + " -r [tty] Use cable transport for R320\n" +#endif +#ifdef HAVE_BLUETOOTH + " -b [addr] [chan] Use bluetooth RFCOMM transport\n" +#endif +#ifdef HAVE_USB + " -u [interface] Use USB transport\n" +#endif + " -i Use IP/TCP transport\n" + " -h Print this help message\n" "\n" "If no transport is selected, IrDA is used.\n" ); return 0; } +#ifndef _WIN32 if( (argc == 2 || argc ==3) && (strcmp(argv[1], "-s") == 0 ) ) cobex = TRUE; if( (argc == 2 || argc ==3) && (strcmp(argv[1], "-r") == 0 ) ) { @@ -197,16 +210,19 @@ int main (int argc, char *argv[]) r320 = TRUE; } #endif - - if( (argc == 2) && (strcmp(argv[1], "-i") == 0 ) ) - tcpobex = TRUE; +#ifdef HAVE_BLUETOOTH if( (argc >= 2) && (strcmp(argv[1], "-b") == 0 ) ) btobex = TRUE; +#endif +#ifdef HAVE_USB if( (argc >= 2) && (strcmp(argv[1], "-u") == 0 ) ) usbobex = TRUE; +#endif + if( (argc == 2) && (strcmp(argv[1], "-i") == 0 ) ) + tcpobex = TRUE; - if(cobex) { #ifndef _WIN32 + if(cobex) { if(argc == 3) port = argv[2]; else @@ -224,7 +240,8 @@ int main (int argc, char *argv[]) return -1; } - if(! (handle = OBEX_Init(OBEX_TRANS_CUSTOM, obex_event, 0))) { + handle = OBEX_Init(OBEX_TRANS_CUSTOM, obex_event, 0); + if(!handle) { perror( "OBEX_Init failed"); return -1; } @@ -238,66 +255,66 @@ int main (int argc, char *argv[]) if(OBEX_RegisterCTransport(handle, &custfunc) < 0) { printf("Custom transport callback-registration failed\n"); } -#else - printf("Not implemented in Win32 yet.\n"); + } else #endif // _WIN32 - } - else if(tcpobex) { - printf("Using TCP transport\n"); - if(! (handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0))) { - perror( "OBEX_Init failed"); - exit(0); - } - } - else if(btobex) { -#ifndef _WIN32 - switch (argc) { #ifdef HAVE_BLUETOOTH + if(btobex) { + const char *channel_arg = NULL; + switch (argc) { case 4: str2ba(argv[2], &bdaddr); - channel = atoi(argv[3]); + channel_arg = argv[3]; break; case 3: str2ba(argv[2], &bdaddr); if (bacmp(&bdaddr, BDADDR_ANY) == 0) - channel = atoi(argv[2]); - else - channel = BT_CHANNEL; + channel_arg = argv[2]; break; case 2: bacpy(&bdaddr, BDADDR_ANY); - channel = BT_CHANNEL; break; -#endif default: printf("Wrong number of arguments\n"); exit(0); } - printf("Using Bluetooth RFCOMM transport\n"); - if(! (handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0))) { + switch (btobex) { + case TRUE: + printf("Using Bluetooth RFCOMM transport\n"); + handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0); + if (channel_arg) + channel = (atoi(channel_arg) & 0xFF); + else + channel = BT_CHANNEL; + break; + } + + if(!handle) { perror( "OBEX_Init failed"); exit(0); } -#else - printf("Not implemented in Win32 yet.\n"); -#endif // _WIN32 - } - else if(usbobex) { + } else +#endif + #ifdef HAVE_USB + if(usbobex) { int i, interfaces_number, intf_num; switch (argc) { case 2: - printf("Using USB transport, querying available interfaces\n"); - if(! (handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0))) { + printf("Using USB transport, " + "querying available interfaces\n"); + handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0); + if(!handle) { perror( "OBEX_Init failed"); exit(0); } interfaces_number = OBEX_EnumerateInterfaces(handle); for (i=0; i < interfaces_number; i++) { obex_intf = OBEX_GetInterfaceByIndex(handle, i); - printf("Interface %d: idVendor: %#x, idProduct: %#x, bus %d, dev %d, intf %d, %s %s %s\n", i, + printf("Interface %d: idVendor: %#x, " + "idProduct: %#x, bus %d, dev %d, " + "intf %d, %s %s %s\n", i, obex_intf->usb.idVendor, obex_intf->usb.idProduct, obex_intf->usb.bus_number, @@ -307,14 +324,16 @@ int main (int argc, char *argv[]) obex_intf->usb.product, obex_intf->usb.control_interface); } - printf("Use '%s -u interface_number' to run interactive OBEX test client\n", argv[0]); + 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))) { + handle = OBEX_Init(OBEX_TRANS_USB, obex_event, 0); + if(!handle) { perror( "OBEX_Init failed"); exit(0); } @@ -331,14 +350,20 @@ int main (int argc, char *argv[]) printf("Wrong number of arguments\n"); exit(0); } -#else - printf("Not compiled with USB support\n"); - exit(0); + } else #endif - } - else { + + if(tcpobex) { + printf("Using TCP transport\n"); + if(! (handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0))) { + perror( "OBEX_Init failed"); + exit(0); + } + + } else { printf("Using IrDA transport\n"); - if(! (handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0))) { + handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0); + if(!handle) { perror( "OBEX_Init failed"); exit(0); } -- 1.7.4.1 ------------------------------------------------------------------------------ Forrester Wave Report - Recovery time is now measured in hours and minutes not days. Key insights are discussed in the 2010 Forrester Wave Report as part of an in-depth evaluation of disaster recovery service providers. Forrester found the best-in-class provider in terms of services and vision. Read this report now! http://p.sf.net/sfu/ibm-webcastpromo _______________________________________________ Openobex-users mailing list Openobex-users@lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/openobex-users