diff -Nur orig/gammu-1.24.91/CMakeLists.txt gammu-1.24.91/CMakeLists.txt --- orig/gammu-1.24.91/CMakeLists.txt 2009-05-22 11:54:00.000000000 +0100 +++ gammu-1.24.91/CMakeLists.txt 2009-06-12 19:29:31.000000000 +0100 @@ -270,12 +270,16 @@ set(BLUETOOTH_SEARCH TRUE) message(STATUS "Using BlueZ stack") endif (BLUEZ_FOUND) - find_package (FBSDBluetooth) - if (FBSD_BLUE_FOUND) + find_package (BSDBluetooth) + if (BSD_BLUE_FOUND) set(BLUETOOTH_FOUND ON) - set(BLUETOOTH_SEARCH FALSE) - message(STATUS "Using FreeBSD Bluetooth stack") - endif (FBSD_BLUE_FOUND) + message(STATUS "Using BSD Bluetooth stack") + check_library_exists(bluetooth sdp_service_search_attribute "" HAVE_SDP_SERVICE_SEARCH_ATTRIBUTE) + check_library_exists(bluetooth bt_devinquiry "" HAVE_BT_DEVINQUIRY) + if (HAVE_SDP_SERVICE_SEARCH_ATTRIBUTE AND HAVE_BT_DEVINQUIRY) + set(BLUETOOTH_SEARCH TRUE) + endif (HAVE_SDP_SERVICE_SEARCH_ATTRIBUTE AND HAVE_BT_DEVINQUIRY) + endif (BSD_BLUE_FOUND) find_package (OSXBluetooth) if (OSX_BLUE_FOUND) set(BLUETOOTH_FOUND ON) @@ -360,11 +364,11 @@ endif (NOT "${BLUEZ_LIBRARIES}" STREQUAL "") endif (BLUEZ_FOUND) -if (FBSD_BLUE_FOUND) - if (NOT "${FBSD_BLUE_LIBRARIES}" STREQUAL "") - set (GAMMU_LIBS "${GAMMU_LIBS} -l${FBSD_BLUE_LIBRARIES}") - endif (NOT "${FBSD_BLUE_LIBRARIES}" STREQUAL "") -endif (FBSD_BLUE_FOUND) +if (BSD_BLUE_FOUND) + if (NOT "${BSD_BLUE_LIBRARIES}" STREQUAL "") + set (GAMMU_LIBS "${GAMMU_LIBS} -l${BSD_BLUE_LIBRARIES}") + endif (NOT "${BSD_BLUE_LIBRARIES}" STREQUAL "") +endif (BSD_BLUE_FOUND) if (ICONV_FOUND) if (NOT "${ICONV_LIBRARIES}" STREQUAL "") diff -Nur orig/gammu-1.24.91/cmake/FindBSDBluetooth.cmake gammu-1.24.91/cmake/FindBSDBluetooth.cmake --- orig/gammu-1.24.91/cmake/FindBSDBluetooth.cmake 1970-01-01 01:00:00.000000000 +0100 +++ gammu-1.24.91/cmake/FindBSDBluetooth.cmake 2009-06-12 19:29:31.000000000 +0100 @@ -0,0 +1,35 @@ +# - Finds Bluetooth library on BSD +# This module defines +# BSD_BLUE_INCLUDE_DIR, where to find bluetooth.h +# BSD_BLUE_LIBRARIES, the libraries needed to use BSD Bluetooth. +# BSD_BLUE_FOUND, If false, do not try to use BSD Bluetooth. +# +# Copyright (c) 2007, Michal Cihar, +# +# vim: expandtab sw=4 ts=4 sts=4: + +if (NOT DEFINED BSD_BLUE_FOUND) + if (NOT CROSS_MINGW) + find_path(BSD_BLUE_INCLUDE_DIR NAMES bluetooth.h + PATHS + /usr/include + /usr/local/include + ) + + find_library(BSD_BLUE_LIBRARIES NAMES bluetooth + PATHS + /usr/lib + /usr/local/lib + ) + + if(BSD_BLUE_INCLUDE_DIR AND BSD_BLUE_LIBRARIES) + set(BSD_BLUE_FOUND TRUE CACHE INTERNAL "BSD Bluetooth found") + message(STATUS "Found BSD Bluetooth: ${BSD_BLUE_INCLUDE_DIR}, ${BSD_BLUE_LIBRARIES}") + else(BSD_BLUE_INCLUDE_DIR AND BSD_BLUE_LIBRARIES) + set(BSD_BLUE_FOUND FALSE CACHE INTERNAL "BSD Bluetooth found") + message(STATUS "BSD Bluetooth not found.") + endif(BSD_BLUE_INCLUDE_DIR AND BSD_BLUE_LIBRARIES) + + mark_as_advanced(BSD_BLUE_INCLUDE_DIR BSD_BLUE_LIBRARIES) + endif (NOT CROSS_MINGW) +endif (NOT DEFINED BSD_BLUE_FOUND) diff -Nur orig/gammu-1.24.91/cmake/FindFBSDBluetooth.cmake gammu-1.24.91/cmake/FindFBSDBluetooth.cmake --- orig/gammu-1.24.91/cmake/FindFBSDBluetooth.cmake 2007-09-03 03:06:48.000000000 +0100 +++ gammu-1.24.91/cmake/FindFBSDBluetooth.cmake 2009-06-12 19:29:31.000000000 +0100 @@ -1,35 +0,0 @@ -# - Finds Bluetooth library on FreeBSD -# This module defines -# FBSD_BLUE_INCLUDE_DIR, where to find bluetooth.h -# FBSD_BLUE_LIBRARIES, the libraries needed to use FreeBSD Bluetooth. -# FBSD_BLUE_FOUND, If false, do not try to use FreeBSD Bluetooth. -# -# Copyright (c) 2007, Michal Cihar, -# -# vim: expandtab sw=4 ts=4 sts=4: - -if (NOT DEFINED FBSD_BLUE_FOUND) - if (NOT CROSS_MINGW) - find_path(FBSD_BLUE_INCLUDE_DIR NAMES bluetooth.h - PATHS - /usr/include - /usr/local/include - ) - - find_library(FBSD_BLUE_LIBRARIES NAMES bluetooth - PATHS - /usr/lib - /usr/local/lib - ) - - if(FBSD_BLUE_INCLUDE_DIR AND FBSD_BLUE_LIBRARIES) - set(FBSD_BLUE_FOUND TRUE CACHE INTERNAL "FreeBSD Bluetooth found") - message(STATUS "Found FreeBSD Bluetooth: ${FBSD_BLUE_INCLUDE_DIR}, ${FBSD_BLUE_LIBRARIES}") - else(FBSD_BLUE_INCLUDE_DIR AND FBSD_BLUE_LIBRARIES) - set(FBSD_BLUE_FOUND FALSE CACHE INTERNAL "FreeBSD Bluetooth found") - message(STATUS "FreeBSD Bluetooth not found.") - endif(FBSD_BLUE_INCLUDE_DIR AND FBSD_BLUE_LIBRARIES) - - mark_as_advanced(FBSD_BLUE_INCLUDE_DIR FBSD_BLUE_LIBRARIES) - endif (NOT CROSS_MINGW) -endif (NOT DEFINED FBSD_BLUE_FOUND) diff -Nur orig/gammu-1.24.91/cmake/templates/gammu-config.h.cmake gammu-1.24.91/cmake/templates/gammu-config.h.cmake --- orig/gammu-1.24.91/cmake/templates/gammu-config.h.cmake 2009-03-17 15:01:11.000000000 +0000 +++ gammu-1.24.91/cmake/templates/gammu-config.h.cmake 2009-06-12 19:29:31.000000000 +0100 @@ -322,8 +322,8 @@ /* Do we have libusb-1.0 ? */ #cmakedefine LIBUSB_FOUND -/* Will be used FreeBSD Bluetooth stack ? */ -#cmakedefine FBSD_BLUE_FOUND +/* Will be used BSD Bluetooth stack ? */ +#cmakedefine BSD_BLUE_FOUND /* Will be used OSX Bluetooth stack ? */ #cmakedefine OSX_BLUE_FOUND diff -Nur orig/gammu-1.24.91/libgammu/CMakeLists.txt gammu-1.24.91/libgammu/CMakeLists.txt --- orig/gammu-1.24.91/libgammu/CMakeLists.txt 2009-03-18 09:16:38.000000000 +0000 +++ gammu-1.24.91/libgammu/CMakeLists.txt 2009-06-12 19:29:31.000000000 +0100 @@ -76,9 +76,9 @@ if (LIBUSB_FOUND) list (APPEND LIBRARY_SRC device/usb/usb.c) endif (LIBUSB_FOUND) -if (FBSD_BLUE_FOUND) - list (APPEND LIBRARY_SRC device/bluetoth/blue_fbsd.c) -endif (FBSD_BLUE_FOUND) +if (BSD_BLUE_FOUND) + list (APPEND LIBRARY_SRC device/bluetoth/blue_bsd.c) +endif (BSD_BLUE_FOUND) if (OSX_BLUE_FOUND) list (APPEND LIBRARY_SRC device/bluetoth/blue_osx.c) endif (OSX_BLUE_FOUND) @@ -126,10 +126,10 @@ include_directories (${LIBUSB_INCLUDE_DIR}) endif (LIBUSB_FOUND) -if (FBSD_BLUE_FOUND) - target_link_libraries (libGammu ${FBSD_BLUE_LIBRARIES}) - include_directories (${FBSD_BLUE_INCLUDE_DIR}) -endif (FBSD_BLUE_FOUND) +if (BSD_BLUE_FOUND) + target_link_libraries (libGammu ${BSD_BLUE_LIBRARIES}) + include_directories (${BSD_BLUE_INCLUDE_DIR}) +endif (BSD_BLUE_FOUND) if (OSX_BLUE_FOUND) target_link_libraries (libGammu ${OSX_BLUE_LIBS}) diff -Nur orig/gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.c gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.c --- orig/gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.c 1970-01-01 01:00:00.000000000 +0100 +++ gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.c 2009-06-12 19:29:31.000000000 +0100 @@ -0,0 +1,267 @@ +/*- + * Copyright (c) 2009 Iain Hibbert + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "../../gsmstate.h" + +#ifdef GSM_ENABLE_BLUETOOTHDEVICE +#ifdef BSD_BLUE_FOUND + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../gsmcomon.h" +#include "../devfunc.h" +#include "bluetoth.h" + +/* + * Handle FreeBSD compatibility + */ +#ifndef BTPROTO_RFCOMM +#define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM +#define BDADDR_ANY NG_HCI_BDADDR_ANY +#define sockaddr_bt sockaddr_rfcomm +#define bt_len rfcomm_len +#define bt_family rfcomm_family +#define bt_channel rfcomm_channel +#define bt_bdaddr rfcomm_bdaddr +#define bdaddr_copy(d, s) memcpy((d), (s), sizeof(bdaddr_t)) +#endif + +static GSM_Error bluetooth_open(GSM_StateMachine *s, bdaddr_t *bdaddr, int channel) +{ + GSM_Device_BlueToothData *d = &s->Device.Data.BlueTooth; + struct sockaddr_bt sa; + int fd; + + memset(&sa, 0, sizeof(sa)); + sa.bt_len = sizeof(sa); + sa.bt_family = AF_BLUETOOTH; + + smprintf(s, "Connecting to RF channel %i\n", channel); + + fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); + if (fd < 0) { + smprintf(s, "Can't create socket\n"); + return ERR_DEVICENODRIVER; + } + + bdaddr_copy(&sa.bt_bdaddr, BDADDR_ANY); + + if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { + smprintf(s, "Can't bind socket: %s\n", strerror(errno)); + close(fd); + return ERR_DEVICEOPENERROR; + } + + sa.bt_channel = channel; + bdaddr_copy(&sa.bt_bdaddr, bdaddr); + + if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) { + smprintf(s, "Can't connect to %s: %s\n", bt_ntoa(bdaddr, NULL), strerror(errno)); + close(fd); + return ERR_DEVICEOPENERROR; + } + + d->hPhone = fd; + return ERR_NONE; +} + +GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) +{ + bdaddr_t bdaddr; + struct hostent *he = NULL; + + if (!bt_aton(device, &bdaddr)) { + if ((he = bt_gethostbyname(device)) == NULL) { + smprintf(s, "%s: %s\n", device, hstrerror(h_errno)); + return ERR_UNKNOWN; + } + + bdaddr_copy(&bdaddr, (bdaddr_t *)he->h_addr); + } + + return bluetooth_open(s, &bdaddr, port); +} + +#ifdef BLUETOOTH_RF_SEARCHING + +static int bluetooth_channel(sdp_data_t *value) +{ + sdp_data_t pdl, seq; + uintmax_t channel; + + sdp_get_alt(value, value); /* strip any alt container */ + + while (sdp_get_seq(value, &pdl)) { + if (sdp_get_seq(&pdl, &seq) + && sdp_match_uuid16(&seq, SDP_UUID_PROTOCOL_L2CAP) + && sdp_get_seq(&pdl, &seq) + && sdp_match_uuid16(&seq, SDP_UUID_PROTOCOL_RFCOMM) + && sdp_get_uint(&seq, &channel) + && channel >= 1 && channel <= 30) + return channel; + } + + return -1; +} + +static char *bluetooth_service(sdp_data_t *value) +{ + char *str; + size_t len; + + if (!sdp_get_str(value, &str, &len)) + return NULL; + + return strndup(str, len); +} + +static GSM_Error bluetooth_search(GSM_StateMachine *s, bdaddr_t *bdaddr) +{ + sdp_data_t rec, rsp, ssp, value; + uint8_t buf[3]; + uint16_t attr; + sdp_session_t ss; + int ch, channel, sc, score; + char *sv; + + smprintf(s, "Searching for services on %s\n", bt_ntoa(bdaddr, NULL)); + + ss = sdp_open(NULL, bdaddr); + if (ss == NULL) { + smprintf(s, "SDP Connection failed: %s\n", strerror(errno)); + return ERR_TIMEOUT; + } + + ssp.next = buf; + ssp.end = buf + sizeof(buf); + sdp_put_uuid16(&ssp, SDP_UUID_PROTOCOL_RFCOMM); + ssp.end = ssp.next; + ssp.next = buf; + + if (!sdp_service_search_attribute(ss, &ssp, NULL, &rsp)) { + smprintf(s, "SDP Service Search Attribute failed: %s\n", strerror(errno)); + sdp_close(ss); + return ERR_UNKNOWN; + } + + channel = -1; + score = 0; + + while (sdp_get_seq(&rsp, &rec)) { + ch = -1; + sv = NULL; + + while (sdp_get_attr(&rec, &attr, &value)) { + switch (attr) { + case SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST: + ch = bluetooth_channel(&value); + break; + + case SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET: + sv = bluetooth_service(&value); + break; + + default: + break; + } + } + + if (ch != -1) { + smprintf(s, " Channel %i", ch); + if (sv != NULL) { + sc = bluetooth_checkservicename(s, sv); + smprintf(s, " - \"%s\" (score=%d)", sv, sc); + if (sc > score) { + score = sc; + channel = ch; + } + } + smprintf(s, "\n"); + } + + free(sv); + } + + sdp_close(ss); + + if (channel == -1) { + smprintf(s, "No suitable service found!\n"); + return ERR_NOTSUPPORTED; + } + + return bluetooth_open(s, bdaddr, channel); +} + +GSM_Error bluetooth_findchannel(GSM_StateMachine *s) +{ + char *device = s->CurrentConfig->Device; + bdaddr_t bdaddr; + struct hostent *he; + struct bt_devinquiry *ii; + int count, n; + + if (bt_aton(device, &bdaddr)) + return bluetooth_search(s, &bdaddr); + + if ((he = bt_gethostbyname(device)) != NULL) + return bluetooth_search(s, (bdaddr_t *)he->h_addr); + + smprintf(s, "Device \"%s\" unknown. Starting inquiry..\n", device); + + if ((count = bt_devinquiry(NULL, 10, 20, &ii)) == -1) { + smprintf(s, "Inquiry failed: %s\n", strerror(errno)); + return ERR_UNKNOWN; + } + + smprintf(s, "Found %d device%s.\n", count, (count == 1 ? "" : "s")); + + for (n = 0; n < count; n++) { + if (bluetooth_search(s, &ii[n].bdaddr) == ERR_NONE) { + free(ii); + return ERR_NONE; + } + } + + free(ii); + return ERR_UNKNOWN; +} + +#endif +#endif +#endif + +/* How should editor hadle tabs in this file? Add editor commands here. + * vim: noexpandtab sw=8 ts=8 sts=8: + */ diff -Nur orig/gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.h gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.h --- orig/gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.h 1970-01-01 01:00:00.000000000 +0100 +++ gammu-1.24.91/libgammu/device/bluetoth/blue_bsd.h 2009-06-12 19:29:31.000000000 +0100 @@ -0,0 +1 @@ +/* empty file */ diff -Nur orig/gammu-1.24.91/libgammu/device/bluetoth/blue_fbsd.c gammu-1.24.91/libgammu/device/bluetoth/blue_fbsd.c --- orig/gammu-1.24.91/libgammu/device/bluetoth/blue_fbsd.c 2009-01-02 14:10:41.000000000 +0000 +++ gammu-1.24.91/libgammu/device/bluetoth/blue_fbsd.c 2009-06-12 19:29:31.000000000 +0100 @@ -1,220 +0,0 @@ -/* Based on some work from Bluez (www.bluez.org) - * (C) 2000-2001 Qualcomm Incorporated - * (C) 2002-2003 Maxim Krasnyansky - * (C) 2002-2004 Marcel Holtmann - * GNU GPL version 2 - */ -/* based on some Marcel Holtmann work from Gnokii (www.gnokii.org) - * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot - * GNU GPL version 2 or later - */ -/* Ported to FreeBSD by Michal Cihar, based on FreeBSD port patches */ -/* Due to a problem in the source code management, the names of some of - * the authors have unfortunately been lost. We do not mean to belittle - * their efforts and hope they will contact us to see their names - * properly added to the Copyright notice above. - * Having published their contributions under the terms of the GNU - * General Public License (GPL) [version 2], the Copyright of these - * authors will remain respected by adhering to the license they chose - * to publish their code under. - */ - -#include "../../gsmstate.h" - -#ifdef GSM_ENABLE_BLUETOOTHDEVICE -#ifdef FBSD_BLUE_FOUND - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../../gsmcomon.h" -#include "../devfunc.h" -#include "bluetoth.h" - -GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) -{ - GSM_Device_BlueToothData *d = &s->Device.Data.BlueTooth; - struct sockaddr_rfcomm laddr, raddr; - bdaddr_t bdaddr; - int fd; - - memset(&laddr, 0, sizeof(laddr)); - memset(&raddr, 0, sizeof(raddr)); - - smprintf(s, "Connecting to RF channel %i\n",port); - - fd = socket(PF_BLUETOOTH, SOCK_STREAM, BLUETOOTH_PROTO_RFCOMM); - if (fd < 0) { - smprintf(s, "Can't create socket\n"); - return ERR_DEVICENODRIVER; - } - - bacpy(&laddr.rfcomm_bdaddr, NG_HCI_BDADDR_ANY); - laddr.rfcomm_family = AF_BLUETOOTH; - laddr.rfcomm_channel = 0; - - if (bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { - smprintf(s, "Can't bind socket (%d, %s)\n", errno, strerror(errno)); - close(fd); - return ERR_DEVICEOPENERROR; - } - - str2ba(device, &bdaddr); - bacpy(&raddr.rfcomm_bdaddr, &bdaddr); - raddr.rfcomm_family = AF_BLUETOOTH; - raddr.rfcomm_channel = port; - - if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) { - smprintf(s, "Can't connect (%d, %s)\n", errno, strerror(errno)); - close(fd); - return ERR_DEVICEOPENERROR; - } - - d->hPhone = fd; - return ERR_NONE; -} - -#ifdef BLUETOOTH_RF_SEARCHING -#warning This code is not ported to FreeBSD stack! - -static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, uuid_t *group) -{ - sdp_session_t *sess; - sdp_record_t *rec; - sdp_list_t *attrid, *search, *seq, *next, *proto; - sdp_data_t *d; - bdaddr_t interface; - uint32_t range = 0x0000ffff; - char str[20]; - int channel,dd; - char name[1000]; - int score, bestscore = 0; - int found = -1; - uuid_t subgroup; - - bacpy(&interface,NG_HCI_BDADDR_ANY); - - ba2str(bdaddr, str); - smprintf(s,"Device %s", str); - - /* Try to read name */ - dd = hci_open_dev(0); - if (dd < 0) return ERR_UNKNOWN; - memset(name, 0, sizeof(name)); - if (hci_read_remote_name(dd, bdaddr, sizeof(name), name, 100000) >= 0) { - smprintf(s, " (\"%s\")", name); - } - close(dd); - smprintf(s,"\n"); - - /* Connect to device */ - sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY); - if (!sess) { - smprintf(s, "Failed to connect to SDP server on %s: %s\n", str, strerror(errno)); - return ERR_TIMEOUT; - } - - /* List available channels */ - attrid = sdp_list_append(0, &range); - search = sdp_list_append(0, group); - if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) { - smprintf(s, "Service Search failed: %s\n", strerror(errno)); - sdp_close(sess); - return ERR_UNKNOWN; - } - sdp_list_free(attrid, 0); - sdp_list_free(search, 0); - - for (; seq; seq = next) { - rec = (sdp_record_t *) seq->data; - - /* Get channel info */ - if (sdp_get_access_protos(rec, &proto) == 0) { - channel = sdp_get_proto_port(proto, RFCOMM_UUID); - sdp_list_foreach(proto, (sdp_list_func_t)sdp_list_free, 0); - sdp_list_free(proto, 0); - } else { - goto next_seq; - } - smprintf(s, " Channel %i", channel); - - /* Get service name and check it */ - d = sdp_data_get(rec, SDP_ATTR_SVCNAME_PRIMARY); - if (d) { - score = bluetooth_checkservicename(s, d->val.str); - smprintf(s," - \"%s\" (score=%d)\n", d->val.str, score); - if (score > bestscore) { - found = channel; - bestscore = score; - } - } else { - smprintf(s,"\n"); - } - - /* Descent to subroups */ - memset(&subgroup, 0, sizeof(subgroup)); - if (sdp_get_group_id(rec, &subgroup) != -1) { - if (subgroup.value.uuid16 != group->value.uuid16) { - bluetooth_checkdevice(s, bdaddr, &subgroup); - } - } - -next_seq: - next = seq->next; - free(seq); - sdp_record_free(rec); - } - sdp_close(sess); - - if (found != -1) { - return bluetooth_connect(s, found, str); - } - - return ERR_NOTSUPPORTED; -} - -GSM_Error bluetooth_findchannel(GSM_StateMachine *s) -{ - inquiry_info ii[20]; - uint8_t count = 0; - int i; - GSM_Error error = ERR_TIMEOUT; - struct hci_dev_info di; - uuid_t group; - - memset(&group, 0, sizeof(group)); - /* We're looking only for rfcomm channels */ - sdp_uuid16_create(&group, RFCOMM_UUID); - - if (hci_devinfo(0, &di) < 0) return ERR_DEVICENOTWORK; - - if (strcmp(s->CurrentConfig->Device, "/dev/ttyS1") == 0) { - smprintf(s, "Searching for devices\n"); - if (sdp_general_inquiry(ii, 20, 8, &count) < 0) { - return ERR_UNKNOWN; - } - } else { - count = 1; - str2ba(s->CurrentConfig->Device,&ii[0].bdaddr); - } - for (i=0;i