rendered paste bodyIndex: src/irmc_bluetooth.c
===================================================================
--- src/irmc_bluetooth.c (revision 2785)
+++ src/irmc_bluetooth.c (working copy)
@@ -1,244 +0,0 @@
-/*
- MultiSync IrMC Plugin - Synchronize IrMC (mobile) devices
- Copyright (C) 2002-2003 Bo Lincoln <lincoln@lysator.liu.se>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
- published by the Free Software Foundation;
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
- IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
- CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
- ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
- COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
- SOFTWARE IS DISCLAIMED.
-*/
-
-/*
- * $Id: irmc_bluetooth.c,v 1.21 2003/09/09 19:49:03 lincoln Exp $
- */
-#include <config.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <glib.h>
-#include <config.h>
-
-#include "irmc_obex.h"
-#include "irmc_bluetooth.h"
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/rfcomm.h>
-#include <bluetooth/hci_lib.h>
-#include <bluetooth/sdp.h>
-#include <bluetooth/sdp_lib.h>
-#include <openobex/obex.h>
-
-extern gboolean multisync_debug;
-
-int rfcomm_connect(struct bt_unit *btu, int channel) {
- struct sockaddr_rc svr_addr, my_addr;
- int s;
- bdaddr_t tmp;
-
- svr_addr.rc_family = AF_BLUETOOTH;
- bacpy(&svr_addr.rc_bdaddr, &btu->bdaddr);
- svr_addr.rc_channel = channel;
-
- my_addr.rc_family = AF_BLUETOOTH;
- my_addr.rc_channel = channel;
- bacpy(&my_addr.rc_bdaddr, BDADDR_ANY);
-
- baswap(&tmp, &btu->bdaddr);
- osync_trace(TRACE_SENSITIVE, "Trying to connect on to %s... ", batostr(&tmp));
- fflush(stdout);
- if( (s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM))==-1 ) {
- osync_trace(TRACE_INTERNAL, "Can't create socket. %s(%d)\n", strerror(errno), errno);
- return(-1);
- }
-
- if( !connect(s, (struct sockaddr *) &svr_addr, sizeof(svr_addr)) ){
- osync_trace(TRACE_INTERNAL, "OK");
- } else {
- osync_trace(TRACE_INTERNAL, "Connect failed. %s(%d)\n", strerror(errno), errno);
- close(s);
- return(-1);
- }
- return(s);
-}
-
-void plugin_init(void) {
-}
-
-
-GList *find_bt_units() {
- GList *unitlist = NULL;
- inquiry_info ii[10];
- int numfound = 0;
- if (!sdp_general_inquiry(ii, 10, 10000, (uint8_t*)&numfound)) {
- int t;
- for (t = 0; t < numfound; t++) {
- bdaddr_t tmp;
- int retries = 3;
- irmc_bt_unit *irbt = g_malloc0(sizeof(irmc_bt_unit));
- int dd = hci_open_dev(0); // Open first HCI device
- sdp_list_t *services = NULL;
- sdp_list_t *attributes = NULL;
- sdp_list_t *reclist = NULL;
-// uint16_t len = 0; // unused!
- uuid_t serviceuuid;
- uint32_t attributeid = 0x0000ffff;
-// sdp_list_t *protodescs = NULL; // unused!
- sdp_session_t *sess = NULL;
-
- g_assert(irbt);
- baswap(&tmp, &ii[t].bdaddr);
- strncpy(irbt->address, batostr(&tmp), 20);
- irbt->channel = -1;
- irbt->name[0] = 0;
- if (dd >= 0) {
- hci_read_remote_name(dd, &ii[t].bdaddr, 32, irbt->name, 10000);
- hci_close_dev(dd);
- }
-
- // Now lookup the RFCOMM channel for IrMC Sync using SDP
-
- while (retries-- > 0 &&
- !(sess = sdp_connect(BDADDR_ANY, &ii[t].bdaddr, 0)))
- sleep(1);
- if (sess) {
- sdp_uuid16_create(&serviceuuid, IRMC_SYNC_SVCLASS_ID);
- services = sdp_list_append(0, &serviceuuid);
- attributes = sdp_list_append(0, &attributeid);
-
- sdp_service_search_attr_req(sess, services,
- SDP_ATTR_REQ_RANGE,
- attributes, &reclist);
-
- sdp_list_free(services, 0);
- sdp_list_free(attributes, 0);
-
- if (reclist) {
- sdp_record_t *rec = (sdp_record_t*) reclist->data;
- sdp_list_t *access = NULL;
- sdp_get_access_protos(rec, &access);
-
- if (access) {
- irbt->channel = sdp_get_proto_port(access, RFCOMM_UUID);
- }
- }
- sdp_close(sess);
- }
-
- if (access && irbt->channel != -1) {
- unitlist = g_list_append(unitlist, irbt);
- }
-
- }
- }
- return(unitlist);
-}
-
-gint obex_connect(obex_t *handle, gpointer ud) {
- obexdata_t *userdata;
-
- userdata = (obexdata_t*) ud;
- userdata->fd = rfcomm_connect(&userdata->btu, userdata->channel);
- if (userdata->fd < 0) {
- return(-1);
- }
- fcntl(userdata->fd, F_SETFL, O_NONBLOCK);
- return(0);
-}
-
-
-gint obex_disconnect(obex_t *handle, gpointer ud) {
- obexdata_t *userdata;
-
- userdata = (obexdata_t*) ud;
- close(userdata->fd);
- return(0);
-}
-
-gint obex_listen(obex_t *handle, gpointer ud) {
- obexdata_t *userdata;
-
- userdata = (obexdata_t*) ud;
- return(0);
-}
-
-gint obex_write(obex_t *handle, gpointer ud,
- guint8 *buf, gint buflen) {
- int written = 0;
- int ret = 0;
- obexdata_t *userdata;
-
- userdata = (obexdata_t*) ud;
-
- while (ret >= 0 && written < buflen) {
- ret=write(userdata->fd,buf+written,buflen-written);
- if (ret >= 0)
- written+=ret;
- }
- return(written);
-}
-
-gint obex_handleinput(obex_t *handle, gpointer ud, gint timeout) {
- int n;
- struct timeval to;
- fd_set readfds;
- char buf[2048];
- int tot=0;
- int ret = 0;
- obexdata_t *userdata;
-
- userdata = (obexdata_t*) ud;
- n = userdata->fd + 1;
- FD_ZERO(&readfds);
- FD_SET(userdata->fd, &readfds);
- to.tv_sec = timeout;
- to.tv_usec = 0;
- while (userdata->state >= 0 &&
- (ret = select(n, &readfds, NULL, NULL, &to)) > 0) {
- if((tot = read(userdata->fd, buf, 2048)) > 0) {
- OBEX_CustomDataFeed(handle, (uint8_t *) buf, tot);
- } else {
- userdata->state = IRMC_OBEX_REQFAILED;
-// userdata->error = SYNC_MSG_CONNECTIONERROR;
- }
- to.tv_sec = timeout;
- to.tv_usec = 0;
- }
- if (userdata->state >= 0 && ret == 0) {
- userdata->state = IRMC_OBEX_REQFAILED;
-// userdata->error = SYNC_MSG_CONNECTIONERROR;
- }
- return(0);
-}
-
-void irmc_strtoba(bdaddr_t *bdaddr,char *str ) {
- baswap(bdaddr, strtoba(str));
-}
-
-char *irmc_batostr(bdaddr_t *bdaddr) {
- bdaddr_t tmp;
-
- baswap(&tmp, bdaddr);
- return(batostr(&tmp));
-}
Index: src/irmc_bluetooth.h
===================================================================
--- src/irmc_bluetooth.h (revision 2785)
+++ src/irmc_bluetooth.h (working copy)
@@ -1,17 +0,0 @@
-#ifndef IRMC_BLUETOOTH_H
-#define IRMC_BLUETOOTH_H
-
-#include <config.h>
-#include "irmc_obex.h"
-
-typedef struct {
- char address[20];
- int channel;
- char name[32];
-} irmc_bt_unit;
-
-GList *find_bt_units(void);
-int rfcomm_connect(struct bt_unit *btu, int channel);
-
-
-#endif
Index: src/irmc_sync.c
===================================================================
--- src/irmc_sync.c (revision 2785)
+++ src/irmc_sync.c (working copy)
@@ -36,7 +36,6 @@
#include <libxml/parser.h>
#include "irmc_sync.h"
-#include "irmc_bluetooth.h"
#define SYNC_OBJECT_TYPE_CALENDAR 0
#define SYNC_OBJECT_TYPE_TODO 1
Index: src/irmc_obex.c
===================================================================
--- src/irmc_obex.c (revision 2785)
+++ src/irmc_obex.c (working copy)
@@ -46,11 +46,7 @@
#endif
#include "irmc_obex.h"
#include "irmc_sync.h"
-#include "irmc_bluetooth.h"
#include "irmc_irda.h"
-#ifdef HAVE_BT_OBEX
-#include <bluetooth/bluetooth.h>
-#endif
#include <openobex/obex.h>
@@ -493,8 +489,11 @@
#endif
#endif
- memcpy(&userdata->btu, &config->btunit, sizeof(struct bt_unit));
+
+#ifdef HAVE_BLUETOOTH
+ memcpy(&userdata->bdaddr, &config->bdaddr, sizeof(bdaddr_t));
userdata->channel = config->btchannel;
+#endif
strncpy(userdata->cabledev, config->cabledev, 19);
userdata->cabletype = config->cabletype;
memcpy(&userdata->irunit, &config->irunit, sizeof(irmc_ir_unit));
@@ -508,15 +507,8 @@
switch(userdata->connectmedium) {
case MEDIUM_BLUETOOTH:
-#ifdef HAVE_BT_OBEX
if (!(handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0)))
return(0);
-#else
- if (!(handle = OBEX_Init(OBEX_TRANS_CUST, obex_event, 0)))
- return(0);
- if (bluetoothplugin)
- OBEX_RegisterCTransport(handle, &bttrans);
-#endif
break;
case MEDIUM_IR:
#ifdef HAVE_IRDA
@@ -549,14 +541,11 @@
userdata = (obexdata_t*) OBEX_GetUserData(handle);
userdata->connected = 0;
switch(userdata->connectmedium) {
+#ifdef HAVE_BLUETOOTH
case MEDIUM_BLUETOOTH:
-#ifdef HAVE_BT_OBEX
- ret=BtOBEX_TransportConnect(handle, NULL,
- &userdata->btu.bdaddr, userdata->channel);
-#else
- ret=OBEX_TransportConnect (handle, (struct sockaddr*) &addr, 0);
-#endif
+ ret=BtOBEX_TransportConnect(handle, NULL, &userdata->bdaddr, userdata->channel);
break;
+#endif
case MEDIUM_IR:
// ret = -1;
ret=OBEX_TransportConnect (handle, (struct sockaddr*) &addr, 0);
Index: src/irmc_irda.c
===================================================================
--- src/irmc_irda.c (revision 2785)
+++ src/irmc_irda.c (working copy)
@@ -43,18 +43,12 @@
#endif
#include "irmc_obex.h"
#include "irmc_sync.h"
-#include "irmc_bluetooth.h"
-#ifdef HAVE_BT_OBEX
-#include <bluetooth/bluetooth.h>
-#endif
#include <openobex/obex.h>
#define DISC_BUF_LEN sizeof(struct irda_device_list) + \
sizeof(struct irda_device_info) * (10)
-extern gboolean multisync_debug;
-
gint obex_irda_connect(obex_t *handle, gpointer ud) {
#ifdef HAVE_IRDA
struct irda_device_list *list;
Index: src/irmc_sync.h
===================================================================
--- src/irmc_sync.h (revision 2785)
+++ src/irmc_sync.h (working copy)
@@ -40,7 +40,7 @@
connect_medium connectmedium; // The connection type
// bluetooth specific
- struct bt_unit btunit; // Bluetooth address
+ btaddr_t bdaddr; // Bluetooth address
int btchannel; // Bluetooth channel
// cable specific
Index: src/irmc_obex.h
===================================================================
--- src/irmc_obex.h (revision 2785)
+++ src/irmc_obex.h (working copy)
@@ -25,21 +25,8 @@
#ifdef HAVE_BLUETOOTH
#include <bluetooth/bluetooth.h>
-#include <bluetooth/hci.h>
-#include <bluetooth/l2cap.h>
-#include <bluetooth/rfcomm.h>
+#endif
-
-struct bt_unit {
- bdaddr_t bdaddr;
-};
-#else
-struct bt_unit {
- char bdaddr;
- char bdaddr_pad[5];
-};
-#endif /* HAVE_BLUETOOTH */
-
#include <openobex/obex.h>
#include "cobex_bfb.h"
@@ -49,7 +36,9 @@
typedef struct {
int fd;
connect_medium connectmedium;
- struct bt_unit btu;
+#ifdef HAVE_BLUETOOTH
+ bdaddr_t bdaddr;
+#endif
char cabledev[20];
cable_type cabletype;
irmc_ir_unit irunit; // IR device name and serial
@@ -68,7 +57,7 @@
} obexdata_t;
-int rfcomm_connect(struct bt_unit *btu, int channel);
+//int rfcomm_connect(struct bt_unit *btu, int channel);
gboolean irmc_obex_connect(obex_t* handle, char* target, OSyncError **error);
gboolean irmc_obex_disconnect(obex_t* handle, OSyncError **error);
gboolean irmc_obex_put(obex_t* handle, char* name, char *type,
Index: src/CMakeLists.txt
===================================================================
--- src/CMakeLists.txt (revision 2786)
+++ src/CMakeLists.txt (working copy)
@@ -1,5 +1,5 @@
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/bfb ${CMAKE_CURRENT_SOURCE_DIR}
- ${OPENSYNC_INCLUDE_DIR} ${OPENOBEX_INCLUDE_DIR} ${BLUEZ_INCLUDE_DIR}
+ ${OPENSYNC_INCLUDE_DIR} ${OPENOBEX_INCLUDE_DIR}
${GLIB2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIR} )
# irmc-sync source
@@ -9,7 +9,6 @@
bfb/crc.c
irmc_sync.c
cobex_bfb.c
-irmc_bluetooth.c
irmc_irda.c
irmc_obex.c
)
Index: config.h.cmake
===================================================================
--- config.h.cmake (revision 2785)
+++ config.h.cmake (working copy)
@@ -4,9 +4,6 @@
/* Defined if Bluetooth is enabled. */
#cmakedefine HAVE_BLUETOOTH
-/* Bluetooth Obex */
-#cmakedefine HAVE_BT_OBEX
-
/* Defined if IrDA is enabled. */
#cmakedefine HAVE_IRDA