diff -urN gnokii/common/devices/Makefile gnokii-mh/common/devices/Makefile --- gnokii/common/devices/Makefile Sat Aug 24 11:50:24 2002 +++ gnokii-mh/common/devices/Makefile Sat Aug 24 11:35:45 2002 @@ -24,6 +24,7 @@ else OBJS += unixserial.o \ unixirda.o \ + unixbluetooth.o \ tcp.o endif diff -urN gnokii/common/devices/unixbluetooth.c gnokii-mh/common/devices/unixbluetooth.c --- gnokii/common/devices/unixbluetooth.c Thu Jan 1 01:00:00 1970 +++ gnokii-mh/common/devices/unixbluetooth.c Sat Aug 24 11:54:04 2002 @@ -0,0 +1,94 @@ +/* + * + * $Id: unixbluetooth.c,v 1.16 2002/08/05 20:37:26 pkot Exp $ + * + * G N O K I I + * + * A Linux/Unix toolset and driver for Nokia mobile phones. + * + * Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml. + * Copyright (C) 2002 Marcel Holtmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "devices/unixbluetooth.h" + +static char *phone[] = { + "Nokia 6210", + "Nokia 6310", + "Nokia 6310i", + "Nokia 7650", + "Nokia 8910" +}; + +int bluetooth_open(bdaddr_t *bdaddr, int channel) +{ + struct sockaddr_rc laddr, raddr; + int fd; + + if ((fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) { + perror("Can't create socket"); + return -1; + } + + laddr.rc_family = AF_BLUETOOTH; + bacpy(&laddr.rc_bdaddr, BDADDR_ANY); + laddr.rc_channel = 0; + + if (bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { + perror("Can't bind socket"); + close(fd); + return -1; + } + + raddr.rc_family = AF_BLUETOOTH; + bacpy(&raddr.rc_bdaddr, bdaddr); + raddr.rc_channel = htobs(channel); + + if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) { + perror("Can't connect"); + close(fd); + return -1; + } + + return fd; +} + +int bluetooth_close(int fd) +{ + return (close(fd)); +} + +int bluetooth_write(int fd, const __ptr_t bytes, int size) +{ + return (write(fd, bytes, size)); +} + +int bluetooth_read(int fd, __ptr_t bytes, int size) +{ + return (read(fd, bytes, size)); +} + +int bluetooth_select(int fd, struct timeval *timeout) +{ + fd_set readfds; + + FD_ZERO(&readfds); + FD_SET(fd, &readfds); + + return (select(fd + 1, &readfds, NULL, NULL, timeout)); +} diff -urN gnokii/include/devices/unixbluetooth.h gnokii-mh/include/devices/unixbluetooth.h --- gnokii/include/devices/unixbluetooth.h Thu Jan 1 01:00:00 1970 +++ gnokii-mh/include/devices/unixbluetooth.h Sat Aug 24 11:14:56 2002 @@ -0,0 +1,51 @@ +/* + * + * $Id: unixbluetooth.h,v 1.6 2002/03/28 21:37:49 pkot Exp $ + * + * G N O K I I + * + * A Linux/Unix toolset and driver for Nokia mobile phones. + * + * Copyright (C) 1999, 2000 Hugh Blemings & Pavel Janík ml. + * Copyright (C) 2002 Marcel Holtmann + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef __unix_bluetooth_h_ +#define __unix_bluetooth_h_ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "misc.h" + +int bluetooth_open(bdaddr_t *bdaddr, int channel); +int bluetooth_close(int fd); +int bluetooth_write(int fd, const __ptr_t bytes, int size); +int bluetooth_read(int fd, __ptr_t bytes, int size); +int bluetooth_select(int fd, struct timeval *timeout); + +#endif