Ticket #9: 600_win32_bluetooth.patch

File 600_win32_bluetooth.patch, 11.9 KB (added by hsattler, 18 months ago)
  • (a) /dev/null vs. (b) openobex-anoncvs/lib/bluez_compat.h

    a b  
     1 
     2/* Here are the defines that make it possible to 
     3 * implement bluetooth with the Bluez API 
     4 */ 
     5 
     6#ifdef HAVE_CONFIG_H 
     7#include <config.h> 
     8#endif 
     9 
     10#ifdef _WIN32 
     11/* you need the headers files from the Platform SDK */ 
     12#include <winsock2.h> 
     13#include <ws2bth.h> 
     14#define bdaddr_t    BTH_ADDR 
     15#define sockaddr_rc _SOCKADDR_BTH 
     16#define rc_family   addressFamily 
     17#define rc_bdaddr   btAddr 
     18#define rc_channel  port 
     19#define PF_BLUETOOTH   PF_BTH 
     20#define AF_BLUETOOTH   PF_BLUETOOTH 
     21#define BTPROTO_RFCOMM BTHPROTO_RFCOMM 
     22#define BDADDR_ANY     (&(BTH_ADDR){BTH_ADDR_NULL}) 
     23#define bacpy(dst,src) memcpy((dst),(src),sizeof(BTH_ADDR)) 
     24#define bacmp(a,b)     memcmp((a),(b),sizeof(BTH_ADDR)) 
     25 
     26#else /* _WIN32 */ 
     27/* Linux/FreeBSD/NetBSD case */ 
     28 
     29#if defined(HAVE_BLUETOOTH_LINUX) 
     30#include <bluetooth/bluetooth.h> 
     31#include <bluetooth/rfcomm.h> 
     32 
     33#elif defined(HAVE_BLUETOOTH_FREEBSD) 
     34#include <bluetooth.h> 
     35#define sockaddr_rc sockaddr_rfcomm 
     36#define rc_family   rfcomm_family 
     37#define rc_bdaddr   rfcomm_bdaddr 
     38#define rc_channel  rfcomm_channel 
     39 
     40#elif defined(HAVE_BLUETOOTH_NETBSD) 
     41#include <bluetooth.h> 
     42#include <netbt/rfcomm.h> 
     43#define sockaddr_rc sockaddr_bt 
     44#define rc_family   bt_family 
     45#define rc_bdaddr   bt_bdaddr 
     46#define rc_channel  bt_channel 
     47#define BDADDR_ANY  NG_HCI_BDADDR_ANY 
     48 
     49#endif /* HAVE_BLUETOOTH_* */ 
     50 
     51#endif /* _WIN32 */ 
  • openobex-anoncvs

    old new  
    4545#include <errno.h>              /* errno and EADDRNOTAVAIL */ 
    4646#include <netinet/in.h> 
    4747#include <sys/socket.h> 
    48  
    49 #ifdef HAVE_BLUETOOTH_LINUX 
    50 #include <bluetooth/bluetooth.h> 
    51 #include <bluetooth/rfcomm.h> 
    52 #endif 
    53 #ifdef HAVE_BLUETOOTH_FREEBSD 
    54 #include <bluetooth.h> 
    55 #define sockaddr_rc  sockaddr_rfcomm 
    56 #define rc_family    rfcomm_family 
    57 #define rc_bdaddr    rfcomm_bdaddr 
    58 #define rc_channel   rfcomm_channel 
    59 #endif 
    60 #ifdef HAVE_BLUETOOTH_NETBSD 
    61 #define rc_family    bt_family 
    62 #define rc_bdaddr    bt_bdaddr 
    63 #define rc_channel   bt_channel 
    64 #define sockaddr_rc  sockaddr_bt 
    65 #include <bluetooth.h> 
    66 #include <netbt/rfcomm.h> 
    67 #endif 
    68  
    6948#endif /* _WIN32 */ 
    7049 
    7150#include "obex_main.h" 
     
    7958 */ 
    8059void btobex_prepare_connect(obex_t *self, bdaddr_t *src, bdaddr_t *dst, uint8_t channel) 
    8160{ 
    82 #ifndef _WIN32 
    8361        self->trans.self.rfcomm.rc_family = AF_BLUETOOTH; 
    8462        bacpy(&self->trans.self.rfcomm.rc_bdaddr, src); 
    8563        self->trans.self.rfcomm.rc_channel = 0; 
     
    8765        self->trans.peer.rfcomm.rc_family = AF_BLUETOOTH; 
    8866        bacpy(&self->trans.peer.rfcomm.rc_bdaddr, dst); 
    8967        self->trans.peer.rfcomm.rc_channel = channel; 
    90 #endif /* _WIN32 */ 
    9168} 
    9269 
    9370/* 
     
    9875 */ 
    9976void btobex_prepare_listen(obex_t *self, bdaddr_t *src, uint8_t channel) 
    10077{ 
    101 #ifndef _WIN32 
    10278        /* Bind local service */ 
    10379        self->trans.self.rfcomm.rc_family = AF_BLUETOOTH; 
    10480        bacpy(&self->trans.self.rfcomm.rc_bdaddr, src); 
    10581        self->trans.self.rfcomm.rc_channel = channel; 
    106 #endif /* _WIN32 */ 
    10782} 
    10883 
    10984/* 
     
    11489 */ 
    11590int btobex_listen(obex_t *self) 
    11691{ 
    117 #ifndef _WIN32 
    11892        DEBUG(3, "\n"); 
    11993 
    12094        self->serverfd = obex_create_socket(self, AF_BLUETOOTH); 
     
    142116out_freesock: 
    143117        obex_delete_socket(self, self->serverfd); 
    144118        self->serverfd = INVALID_SOCKET; 
    145 #endif /* _WIN32 */ 
    146119        return -1; 
    147120} 
    148121 
     
    156129 */ 
    157130int btobex_accept(obex_t *self) 
    158131{ 
    159 #ifndef _WIN32 
    160132        socklen_t addrlen = sizeof(struct sockaddr_rc); 
    161133        //int mtu; 
    162134        //int len = sizeof(int); 
     
    170142        } 
    171143 
    172144        self->trans.mtu = OBEX_DEFAULT_MTU; 
    173 #endif /* _WIN32 */ 
    174145        return 0; 
    175146} 
    176147         
     
    183154int btobex_connect_request(obex_t *self) 
    184155{ 
    185156        int ret; 
    186 #ifndef _WIN32 
    187157        int mtu = 0; 
    188158        //int len = sizeof(int); 
    189159 
     
    220190out_freesock: 
    221191        obex_delete_socket(self, self->fd); 
    222192        self->fd = INVALID_SOCKET; 
    223 #endif /* _WIN32 */ 
    224193        return ret;      
    225194} 
    226195 
     
    233202int btobex_disconnect_request(obex_t *self) 
    234203{ 
    235204        int ret; 
    236 #ifndef _WIN32 
    237205        DEBUG(4, "\n"); 
    238206        ret = obex_delete_socket(self, self->fd); 
    239207        if(ret < 0) 
    240208                return ret; 
    241209        self->fd = INVALID_SOCKET; 
    242 #endif /* _WIN32 */ 
    243210        return ret;      
    244211} 
    245212 
     
    254221int btobex_disconnect_server(obex_t *self) 
    255222{ 
    256223        int ret; 
    257 #ifndef _WIN32 
    258224        DEBUG(4, "\n"); 
    259225        ret = obex_delete_socket(self, self->serverfd); 
    260226        self->serverfd = INVALID_SOCKET; 
    261 #endif /* _WIN32 */ 
    262227        return ret;      
    263228} 
    264229 
  • openobex-anoncvs

    old new  
    3030#ifndef BTOBEX_H 
    3131#define BTOBEX_H 
    3232 
     33#include "bluez_compat.h" 
     34 
    3335void btobex_prepare_connect(obex_t *self, bdaddr_t *src, bdaddr_t *dst, uint8_t channel); 
    3436void btobex_prepare_listen(obex_t *self, bdaddr_t *src, uint8_t channel); 
    3537int btobex_listen(obex_t *self); 
  • openobex-anoncvs

    old new  
    4343#ifdef DLL_EXPORT 
    4444#define LIB_SYMBOL __declspec(dllexport) 
    4545#endif 
     46static unsigned long wsa_init = 0; 
     47#define WSA_VER_MAJOR 2 
     48#define WSA_VER_MINOR 2 
    4649 
    4750#else /* _WIN32 */ 
    4851#include <fcntl.h> 
     
    6366#include "obex_client.h" 
    6467 
    6568#include "inobex.h" 
     69 
    6670#ifdef HAVE_IRDA 
    6771#include "irobex.h" 
    6872#endif 
     73 
    6974#ifdef HAVE_USB 
    7075#include "usbobex.h" 
    7176#endif 
     77 
    7278#ifdef HAVE_BLUETOOTH 
    7379#include "btobex.h" 
    74 #ifdef HAVE_BLUETOOTH_FREEBSD 
    75 #define BDADDR_ANY  NG_HCI_BDADDR_ANY 
    76 #endif 
    7780#else 
    7881// This is to workaround compilation without Bluetooth support. - Jean II 
    7982typedef char *bdaddr_t; 
     
    126129        obex_return_val_if_fail(eventcb != NULL, NULL); 
    127130 
    128131#ifdef _WIN32 
    129         { 
    130                 WSADATA WSAData; 
    131                 if (WSAStartup (MAKEWORD(2,0), &WSAData) != 0) { 
    132                         DEBUG(4, "WSAStartup failed\n"); 
    133                         return NULL; 
    134                 } 
    135         } 
     132        if (!wsa_init) { 
     133                WORD ver = MAKEWORD(WSA_VER_MAJOR,WSA_VER_MINOR); 
     134                WSADATA WSAData; 
     135                if (WSAStartup (ver, &WSAData) != 0) { 
     136                        DEBUG(4, "WSAStartup failed (%d)\n",WSAGetLastError()); 
     137                        return NULL; 
     138                } 
     139                if (LOBYTE(WSAData.wVersion) != WSA_VER_MAJOR || 
     140                    HIBYTE(WSAData.wVersion) != WSA_VER_MINOR) { 
     141                        DEBUG(4, "WSA version mismatch\n"); 
     142                        WSACleanup(); 
     143                        return NULL; 
     144                } 
     145        } 
     146        ++wsa_init; 
    136147#endif 
    137148 
    138149        self = malloc(sizeof(obex_t)); 
  • openobex-anoncvs

    old new  
    6464        ]) 
    6565]) 
    6666 
     67AC_DEFUN([AC_PATH_WINBT], [ 
     68        AC_CACHE_VAL(winbt_found,[ 
     69               AC_CHECK_HEADERS(ws2bth.h, winbt_found=yes, winbt_found=no, 
     70                                [ 
     71                                  #include <winsock2.h> 
     72               ]) 
     73        ]) 
     74        AC_MSG_CHECKING([for Windows Bluetooth support]) 
     75        AC_MSG_RESULT([$winbt_found]) 
     76]) 
     77 
     78 
    6779AC_DEFUN([AC_PATH_NETBSDBT], [ 
    6880        AC_CACHE_CHECK([for NetBSD Bluetooth support], netbsdbt_found, [ 
    6981                AC_TRY_COMPILE([ 
     
    8597]) 
    8698 
    8799AC_DEFUN([AC_PATH_BLUEZ], [ 
    88         PKG_CHECK_MODULES(BLUEZ, bluez, bluez_found=yes, AC_MSG_RESULT(no)) 
    89         AC_SUBST(BLUEZ_CFLAGS) 
    90         AC_SUBST(BLUEZ_LIBS) 
     100        PKG_CHECK_MODULES(BLUETOOTH, bluez, bluez_found=yes, AC_MSG_RESULT(no)) 
    91101]) 
    92102 
    93103AC_DEFUN([AC_PATH_BLUETOOTH], [ 
     
    101111        *-*-netbsd*) 
    102112                AC_PATH_NETBSDBT 
    103113                ;; 
     114        *-*-mingw32*) 
     115                AC_PATH_WINBT 
     116                ;; 
    104117        esac 
     118        AC_SUBST(BLUETOOTH_CFLAGS) 
     119        AC_SUBST(BLUETOOTH_LIBS) 
    105120]) 
    106121 
    107122AC_DEFUN([AC_PATH_USB], [ 
     
    200215                AC_DEFINE(HAVE_IRDA, 1, [Define if system supports IrDA and it's enabled]) 
    201216        fi 
    202217 
     218        if (test "${bluetooth_enable}" = "yes" && test "${winbt_found}" = "yes"); then 
     219                AC_DEFINE(HAVE_BLUETOOTH, 1, [Define if system supports Bluetooth and it's enabled]) 
     220        fi 
     221 
    203222        if (test "${bluetooth_enable}" = "yes" && test "${netbsdbt_found}" = "yes"); then 
    204223                AC_DEFINE(HAVE_BLUETOOTH, 1, [Define if system supports Bluetooth and it's enabled]) 
    205224                AC_DEFINE(HAVE_BLUETOOTH_NETBSD, 1, [Define if system supports Bluetooth stack for NetBSD]) 
  • apps/Makefile.am

    old new  
    1414        obex_test_server.c obex_test_server.h \ 
    1515        obex_test_cable.c obex_test_cable.h 
    1616 
    17 obex_test_LDADD = $(top_builddir)/lib/libopenobex.la @BLUEZ_LIBS@ libmisc.a 
     17obex_test_LDADD = $(top_builddir)/lib/libopenobex.la @BLUETOOTH_LIBS@ libmisc.a 
    1818 
    1919LDADD = $(top_builddir)/lib/libopenobex.la libmisc.a 
    2020 
    21 INCLUDES = @BLUEZ_CFLAGS@ -I$(top_builddir)/include 
     21INCLUDES = @BLUETOOTH_CFLAGS@ -I$(top_builddir)/include 
    2222endif 
    2323 
    2424MAINTAINERCLEANFILES = Makefile.in 
  • lib/obex_transport.h

    old new  
    4141#include "irda_wrap.h" 
    4242#endif /*HAVE_IRDA*/ 
    4343#ifdef HAVE_BLUETOOTH 
    44 #ifdef HAVE_BLUETOOTH_LINUX 
    45 #include <bluetooth/bluetooth.h> 
    46 #include <bluetooth/rfcomm.h> 
    47 #endif 
    48 #ifdef HAVE_BLUETOOTH_FREEBSD 
    49 #include <bluetooth.h> 
    50 #define sockaddr_rc  sockaddr_rfcomm 
    51 #endif 
    52 #ifdef HAVE_BLUETOOTH_NETBSD 
    53 #include <bluetooth.h> 
    54 #include <netbt/rfcomm.h> 
    55 #endif 
     44#include "bluez_compat.h" 
    5645#endif /*HAVE_BLUETOOTH*/ 
    5746#ifdef HAVE_USB 
    5847#include "usbobex.h" 
     
    6655#endif /*HAVE_IRDA*/ 
    6756        struct sockaddr_in6  inet6; 
    6857#ifdef HAVE_BLUETOOTH 
    69 #ifdef HAVE_BLUETOOTH_LINUX 
    7058        struct sockaddr_rc   rfcomm; 
    71 #endif 
    72 #ifdef HAVE_BLUETOOTH_NETBSD 
    73         struct sockaddr_bt   rfcomm; 
    74 #endif 
    7559#endif /*HAVE_BLUETOOTH*/ 
    7660#ifdef HAVE_USB 
    7761        struct obex_usb_intf_transport_t usb; 
  • openobex-anoncvs

    old new  
    6060typedef void* obex_object_t; 
    6161typedef void (*obex_event_t)(obex_t *handle, obex_object_t *obj, int mode, int event, int obex_cmd, int obex_rsp); 
    6262// This is to workaround compilation without Bluetooth support. - Jean II 
    63 #ifndef SOL_RFCOMM 
    64 typedef char* bdaddr_t; 
    65 #endif 
    6663 
    6764#include <openobex/obex_const.h> 
    6865 
     
    146143/* 
    147144 * Bluetooth OBEX API 
    148145 */ 
     146#ifdef SOL_RFCOMM 
     147#ifdef _WIN32 
     148#define bdaddr_t BTH_ADDR 
     149#endif 
    149150LIB_SYMBOL int BtOBEX_ServerRegister(obex_t *self, bdaddr_t *src, uint8_t channel); 
    150151LIB_SYMBOL int BtOBEX_TransportConnect(obex_t *self, bdaddr_t *src, bdaddr_t *dst, uint8_t channel); 
     152#endif 
    151153 
    152154/* 
    153155 * OBEX File API 
  • lib/obex_main.c

    old new  
    4545#include <sys/types.h> 
    4646#include <stdio.h> 
    4747 
     48#endif /* _WIN32 */ 
     49 
    4850#ifdef HAVE_BLUETOOTH 
    49 #ifdef HAVE_BLUETOOTH_LINUX 
    50 #include <bluetooth/bluetooth.h> 
    51 #endif 
    52 #ifdef HAVE_BLUETOOTH_FREEBSD 
    53 #include <bluetooth.h> 
    54 #define BTPROTO_RFCOMM  BLUETOOTH_PROTO_RFCOMM 
    55 #endif 
    56 #ifdef HAVE_BLUETOOTH_NETBSB 
    57 #include <bluetooth.h> 
    58 #endif 
     51#include "bluez_compat.h" 
    5952#endif /*HAVE_BLUETOOTH*/ 
    6053 
    61 #endif /* _WIN32 */ 
    62  
    6354#include "obex_main.h" 
    6455#include "obex_header.h" 
    6556#include "obex_server.h"