From: <svn...@op...> - 2009-03-03 17:07:36
|
Author: bellmich Date: Tue Mar 3 18:07:33 2009 New Revision: 965 URL: http://libsyncml.opensync.org/changeset/965 Log: added automatic channel discovery for OBEX client transport on Linux - fixed inclusion of CheckFunctionExists - fixed all OBEX related option handling - added option ENABLE_BLUETOOTH_SDPLIB - added code to search for a SyncML client on a known Bluetooth device Modified: trunk/CMakeLists.txt trunk/config.h.cmake trunk/libsyncml/transports/obex_client.c Modified: trunk/CMakeLists.txt ============================================================================== --- trunk/CMakeLists.txt Mon Mar 2 16:39:57 2009 (r964) +++ trunk/CMakeLists.txt Tue Mar 3 18:07:33 2009 (r965) @@ -53,6 +53,7 @@ # find header files and type size INCLUDE( CheckTypeSize ) INCLUDE( CheckIncludeFiles ) +INCLUDE( CheckFunctionExists ) INCLUDE( Documentation ) INCLUDE( AddDocumentation ) @@ -103,7 +104,6 @@ SET ( FATAL_ERROR_GLIB2 "Cannot find correct glib version ${GLIB2_MIN_VERSION}." ) SET ( ENABLE_GLIB2_GREGEX ON ) ELSE ( NOT GLIB2_FOUND ) - INCLUDE(CheckFunctionExists) SET( CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS} ) SET( CMAKE_REQUIRED_LIBRARIES ${GLIB2_LIBRARIES} ) CHECK_FUNCTION_EXISTS( g_regex_new GLIB2_HAVE_GREGEX ) @@ -131,21 +131,33 @@ SET( ENABLE_HTTP OFF ) ENDIF(LIBSOUP2_FOUND) -OPTION( ENABLE_OBEX "enable obex transports" OFF ) -OPTION( ENABLE_OPENOBEX_TCP "enable OBEX transport via TCP (requires OpenOBEX 1.3+SVN" OFF ) IF(OPENOBEX_FOUND) - SET( ENABLE_OBEX ON ) + OPTION( ENABLE_OBEX "enable obex transports" ON ) IF(BLUEZ_FOUND) OPTION( ENABLE_BLUETOOTH "enable obex over bluetooth transports" ON ) + SET( CMAKE_REQUIRED_FLAGS ${BLUEZ_CFLAGS} ) + SET( CMAKE_REQUIRED_INCLUDES ${BLUEZ_INCLUDE_DIRS} ) + SET( CMAKE_REQUIRED_LIBRARIES ${BLUEZ_LIBRARIES} ) + CHECK_FUNCTION_EXISTS( sdp_service_search_attr_req BLUETOOTH_SDPLIB ) + IF( BLUETOOTH_SDPLIB ) + OPTION( ENABLE_BLUETOOTH_SDPLIB "enable bluetooth channel discovery" ON ) + ENDIF( BLUETOOTH_SDPLIB ) ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") OPTION( ENABLE_BLUETOOTH "enable obex over bluetooth transports" ON ) LINK_LIBRARIES(bluetooth sdp) ELSE(BLUEZ_FOUND) - SET( ENABLE_BLUETOOTH OFF ) + OPTION( ENABLE_BLUETOOTH "enable obex over bluetooth transports" OFF ) ENDIF(BLUEZ_FOUND) IF( OPENOBEX_HAVE_TCPOBEX ) - SET( ENABLE_OPENOBEX_TCP ON ) + OPTION( ENABLE_OPENOBEX_TCP "enable obex over bluetooth transports" ON ) + ELSE( OPENOBEX_HAVE_TCPOBEX ) + OPTION( ENABLE_OPENOBEX_TCP "enable OBEX transport via TCP (requires OpenOBEX 1.3+SVN)" OFF ) ENDIF( OPENOBEX_HAVE_TCPOBEX ) +ELSE(OPENOBEX_FOUND) + OPTION( ENABLE_OBEX "enable obex transports" OFF ) + OPTION( ENABLE_OPENOBEX_TCP "enable OBEX transport via TCP (requires OpenOBEX 1.3+SVN)" OFF ) + OPTION( ENABLE_BLUETOOTH "enable obex over bluetooth transports" OFF ) + OPTION( ENABLE_BLUETOOTH_SDPLIB "enable bluetooth channel discovery" OFF ) ENDIF(OPENOBEX_FOUND) IF( NOT LIBSOUP2_FOUND AND NOT OPENOBEX_FOUND ) @@ -232,7 +244,8 @@ SHOW_STATUS( ENABLE_WBXML "WAP Binary XML\t\t" LIBWBXML2_VERSION ) SHOW_STATUS( ENABLE_HTTP "http transports\t\t" LIBSOUP2_VERSION ) SHOW_STATUS( ENABLE_OBEX "obex transports\t\t" OPENOBEX_VERSION ) -SHOW_STATUS( ENABLE_BLUETOOTH "obex over bluetooth transports" ) +SHOW_STATUS( ENABLE_BLUETOOTH "obex over bluetooth transports" BLUEZ_VERSION ) +SHOW_STATUS( ENABLE_BLUETOOTH_SDPLIB "bluetooth channel discovery\t" ) SHOW_STATUS( ENABLE_OPENOBEX_TCP "obex over tcp transports\t" ) SHOW_STATUS( ENABLE_BASE64_TEST "deprecated base64 tests\t" ) SHOW_STATUS( ENABLE_GLIB2_GREGEX "glib2 GRegex support\t\t" GLIB2_VERSION ) Modified: trunk/config.h.cmake ============================================================================== --- trunk/config.h.cmake Mon Mar 2 16:39:57 2009 (r964) +++ trunk/config.h.cmake Tue Mar 3 18:07:33 2009 (r965) @@ -3,6 +3,9 @@ /* Bluetooth Transport */ #cmakedefine ENABLE_BLUETOOTH +/* Bluetooth SDP library - necessary for automatic channel discovery */ +#cmakedefine ENABLE_BLUETOOTH_SDPLIB + /* Http Transport */ #cmakedefine ENABLE_HTTP Modified: trunk/libsyncml/transports/obex_client.c ============================================================================== --- trunk/libsyncml/transports/obex_client.c Mon Mar 2 16:39:57 2009 (r964) +++ trunk/libsyncml/transports/obex_client.c Tue Mar 3 18:07:33 2009 (r965) @@ -29,6 +29,13 @@ #include "obex_client_internals.h" #include "obex_client_vendor_internals.h" +#ifdef ENABLE_BLUETOOTH_SDPLIB + +#include <bluetooth/sdp.h> +#include <bluetooth/sdp_lib.h> + +#endif + #include <fcntl.h> #include <sys/poll.h> #include <sys/stat.h> @@ -756,11 +763,13 @@ "The bluetooth address is missing."); goto error; } +#ifndef ENABLE_BLUETOOTH_SDPLIB if (!env->port) { smlErrorSet(error, SML_ERROR_GENERIC, "The bluetooth channel is missing."); goto error; } +#endif break; default: /* nothing to check here */ @@ -888,6 +897,59 @@ bdaddr_t bdaddr; str2ba(env->path, &bdaddr); +#ifdef ENABLE_BLUETOOTH_SDPLIB + if (channel == 0) { + /* FIXME: Is this code really memory leak free !? */ + + sdp_session_t *sdp_session = sdp_connect(BDADDR_ANY, &bdaddr, SDP_RETRY_IF_BUSY); + if (!sdp_session) { + smlErrorSet(&error, SML_ERROR_GENERIC, "The Bluetooth connect to search for the channel failed."); + goto error; + } + unsigned char syncml_client_uuid[] = { + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 0x00, + 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x02}; + uuid_t uuid; + uint32_t range = SDP_ATTR_PROTO_DESC_LIST; + sdp_uuid128_create(&uuid, syncml_client_uuid); + sdp_list_t *attribute = sdp_list_append(0, &range); + sdp_list_t *class = sdp_list_append(0, &uuid); + + sdp_list_t *list; + if (sdp_service_search_attr_req(sdp_session, class, SDP_ATTR_REQ_INDIVIDUAL, attribute, &list) < 0) { + sdp_close(sdp_session); + sdp_list_free(attribute, 0); + sdp_list_free(class, 0); + + smlErrorSet( + &error, SML_ERROR_GENERIC, + "The service search on the Bluetooth device failed."); + goto error; + } + sdp_list_free(attribute, 0); + sdp_list_free(class, 0); + + sdp_list_t *iterator; + for(iterator = list; iterator; iterator = iterator->next) { + sdp_record_t *item = (sdp_record_t *) iterator->data; + sdp_list_t *protos = NULL; + + sdp_get_access_protos(item, &protos); + if(protos) { + channel = sdp_get_proto_port(protos, RFCOMM_UUID); + } + sdp_record_free(item); + } + sdp_list_free(list, 0); + sdp_close(sdp_session); + sleep(1); + smlTrace(TRACE_INTERNAL, + "%s: SDP SyncML channel for %s: %d", + __func__, env->path, channel); + + } +#endif + if (GET_OBEX_RESULT(BtOBEX_TransportConnect(env->obexhandle, BDADDR_ANY, &bdaddr, channel)) < 0) { smlErrorSet(&error, SML_ERROR_GENERIC, "The Bluetooth connect failed. %s (%i).", |