-rw-r--r-- | gammu/emb/common/device/bluetoth/bluez.c | 29 | ||||
-rw-r--r-- | gammu/emb/common/device/devfunc.c | 12 | ||||
-rw-r--r-- | gammu/emb/common/device/irda/irda.c | 8 | ||||
-rw-r--r-- | gammu/emb/common/device/irda/irda_unx.h | 2 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_djg.c | 10 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_unx.c | 38 | ||||
-rw-r--r-- | gammu/emb/common/device/serial/ser_w32.c | 6 |
7 files changed, 79 insertions, 26 deletions
diff --git a/gammu/emb/common/device/bluetoth/bluez.c b/gammu/emb/common/device/bluetoth/bluez.c index 8a4807e..e7e8adf 100644 --- a/gammu/emb/common/device/bluetoth/bluez.c +++ b/gammu/emb/common/device/bluetoth/bluez.c @@ -1,17 +1,26 @@ -/* Based on work by Marcel Holtmann and other authors of Bluez */ +/* Based on some work from Bluez (www.bluez.org) + * (C) 2000-2001 Qualcomm Incorporated + * (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> + * (C) 2002-2004 Marcel Holtmann <marcel@holtmann.org> + * 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 + */ #include "../../gsmstate.h" #ifdef GSM_ENABLE_BLUETOOTHDEVICE #ifdef GSM_ENABLE_BLUEZ #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <errno.h> #include <string.h> #include <sys/socket.h> #include <sys/time.h> #include <unistd.h> #include <bluetooth/bluetooth.h> #include <bluetooth/rfcomm.h> @@ -68,132 +77,132 @@ struct search_context { char *svc; uuid_t group; int tree; uint32_t handle; }; static void print_service_desc(void *value, void *user) { sdp_data_t *p = (sdp_data_t *)value; int i = 0, proto = 0, *channel = (int *)user; for (; p; p = p->next, i++) { switch (p->dtd) { case SDP_UUID16: case SDP_UUID32: case SDP_UUID128: - proto = 1;//sdp_uuid_to_proto(&p->val.uuid); + proto = sdp_uuid_to_proto(&p->val.uuid); break; case SDP_UINT8: if (proto == RFCOMM_UUID) { (*channel) = p->val.uint8; return; } break; } } } void print_access_protos(value, user) { sdp_list_t *protDescSeq = (sdp_list_t *)value; int *channel = (int *)user; sdp_list_foreach(protDescSeq,print_service_desc,channel); } static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context) { sdp_session_t *sess; - sdp_list_t *attrid, *search, *seq, *next, *proto = 0; - uint32_t range = 0x0000ffff; - char str[20]; sdp_record_t *rec; + sdp_list_t *attrid, *search, *seq, *next, *proto = 0; sdp_data_t *d; bdaddr_t interface; + uint32_t range = 0x0000ffff; struct search_context subcontext; + char str[20]; int channel,channel2; bacpy(&interface,BDADDR_ANY); ba2str(bdaddr, str); smprintf(s,"%s\n", str); sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY); if (!sess) { dbgprintf("Failed to connect to SDP server on %s: %s\n", str, strerror(errno)); return ERR_UNKNOWN; } attrid = sdp_list_append(0, &range); search = sdp_list_append(0, &context->group); if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) { dbgprintf("Service Search failed: %s\n", strerror(errno)); sdp_close(sess); return ERR_UNKNOWN; } sdp_list_free(attrid, 0); sdp_list_free(search, 0); channel2 = -1; for (; seq; seq = next) { rec = (sdp_record_t *) seq->data; if (channel2 == -1) { if (!context->tree) { d = sdp_data_get(rec,SDP_ATTR_SVCNAME_PRIMARY); - if (false) { + if (sdp_get_access_protos(rec,&proto) == 0) { channel = -1; sdp_list_foreach(proto,print_access_protos,&channel); - //sdp_list_free(proto,(sdp_free_func_t)sdp_data_free); + sdp_list_free(proto,(sdp_free_func_t)sdp_data_free); } smprintf(s,"Channel %i",channel); if (d) smprintf(s," - \"%s\"",d->val.str); smprintf(s,"\n"); if (channel2 == -1 && bluetooth_checkservicename(s, d->val.str) == ERR_NONE) { channel2 = channel; } } if (sdp_get_group_id(rec,&subcontext.group) != -1) { memcpy(&subcontext, context, sizeof(struct search_context)); if (subcontext.group.value.uuid16 != context->group.value.uuid16) bluetooth_checkdevice(s,bdaddr,&subcontext); } } next = seq->next; free(seq); - //sdp_record_free(rec); + sdp_record_free(rec); } sdp_close(sess); if (channel2 != -1) return bluetooth_connect(s, channel2, str); - return ERR_UNKNOWN; + return ERR_NOTSUPPORTED; } GSM_Error bluetooth_findchannel(GSM_StateMachine *s) { inquiry_info ii[20]; uint8_t count = 0; int i; struct search_context context; GSM_Error error = ERR_NOTSUPPORTED; memset(&context, '\0', sizeof(struct search_context)); - //sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP); + sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP); if (!strcmp(s->CurrentConfig->Device,"/dev/ttyS1")) { dbgprintf("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<count;i++) { error = bluetooth_checkdevice(s,&ii[i].bdaddr,&context); if (error == ERR_NONE) return error; } return error; } diff --git a/gammu/emb/common/device/devfunc.c b/gammu/emb/common/device/devfunc.c index d31ebbf..c58a01f 100644 --- a/gammu/emb/common/device/devfunc.c +++ b/gammu/emb/common/device/devfunc.c @@ -1,16 +1,24 @@ +/* Some source from Gnokii (www.gnokii.org) + * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot + * GNU GPL version 2 or later + */ +/* Some source from Minicom (http://alioth.debian.org/projects/minicom) + * (C) 1991,1992,1993,1994,1995,1996 by Miquel van Smoorenburg + * GNU GPL version 2 + */ #include <string.h> #ifdef WIN32 # include <io.h> #else # include <errno.h> # include <signal.h> #endif #include "../gsmstate.h" #ifdef GSM_ENABLE_BLUETOOTHDEVICE #ifdef BLUETOOTH_RF_SEARCHING GSM_Error bluetooth_checkservicename(GSM_StateMachine *s, char *name) { @@ -92,33 +100,33 @@ GSM_Error lock_device(const char* port, char **lock_device) bool unlock_device(char **lock_file) { return true; } #else #define max_buf_len 128 #define lock_path "/var/lock/LCK.." /* Lock the device. Allocated string with a lock name is returned * in lock_device */ GSM_Error lock_device(const char* port, char **lock_device) { -#ifndef WIN32 +#if !defined(WIN32) && !defined(DJGPP) char *lock_file = NULL; char buffer[max_buf_len]; const char *aux; int fd, len; GSM_Error error = ERR_NONE; dbgprintf("Locking device\n"); aux = strrchr(port, '/'); /* Remove leading '/' */ if (aux) { aux++; } else { /* No / in port */ aux = port; } @@ -205,33 +213,33 @@ GSM_Error lock_device(const char* port, char **lock_device) close(fd); *lock_device = lock_file; return ERR_NONE; failed: free(lock_file); *lock_device = 0; return error; #else *lock_device = 0; return ERR_NONE; #endif } /* Removes lock and frees memory */ bool unlock_device(char **lock_file) { -#ifndef WIN32 +#if !defined(WIN32) && !defined(DJGPP) int err; if (!lock_file) { dbgprintf("Cannot unlock device\n"); return false; } err = unlink(*lock_file); free(*lock_file); *lock_file = NULL; return (err + 1); #else return true; #endif } #endif diff --git a/gammu/emb/common/device/irda/irda.c b/gammu/emb/common/device/irda/irda.c index fef50ac..e680377 100644 --- a/gammu/emb/common/device/irda/irda.c +++ b/gammu/emb/common/device/irda/irda.c @@ -1,19 +1,23 @@ /* (c) 2001-2004 by Marcin Wiacek */ -/* based on some work from Ralf Thelen and MyGnokii */ -/* based on some work from Gnokii and MSDN */ +/* based on some work from Ralf Thelen and MyGnokii (www.mwiacek.com) */ +/* based on some work from MSDN */ +/* based on some 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 + */ /* You have to include wsock32.lib library to MS VC project to compile it */ #include "../../gsmstate.h" #ifdef GSM_ENABLE_IRDADEVICE #ifndef DJGPP #ifndef WIN32 # include <stdlib.h> # include <unistd.h> # include <stdio.h> # include <fcntl.h> # include <errno.h> # include <string.h> # include <sys/time.h> diff --git a/gammu/emb/common/device/irda/irda_unx.h b/gammu/emb/common/device/irda/irda_unx.h index 8dbcb97..7a55273 100644 --- a/gammu/emb/common/device/irda/irda_unx.h +++ b/gammu/emb/common/device/irda/irda_unx.h @@ -1,17 +1,17 @@ -/* part of irda.h available in Linux kernel source */ +/* part of irda.h available in Linux kernel source (www.kernel.org) */ /********************************************************************* * * Filename: irda.h * Version: * Description: * Status: Experimental. * Author: Dag Brattli <dagb@cs.uit.no> * Created at: Mon Mar 8 14:06:12 1999 * Modified at: Sat Dec 25 16:06:42 1999 * Modified by: Dag Brattli <dagb@cs.uit.no> * * Copyright (c) 1999 Dag Brattli, All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as diff --git a/gammu/emb/common/device/serial/ser_djg.c b/gammu/emb/common/device/serial/ser_djg.c index ac9d7c8..2524187 100644 --- a/gammu/emb/common/device/serial/ser_djg.c +++ b/gammu/emb/common/device/serial/ser_djg.c @@ -1,58 +1,58 @@ #include "../../gsmstate.h" #ifdef GSM_ENABLE_SERIALDEVICE #ifdef DJGPP #include "../../gsmcomon.h" #include "ser_djg.h" static GSM_Error serial_close(GSM_StateMachine *s) { GSM_Device_SerialData *d = &s->Device.Data.Serial; - return ERR_NONE; + return ERR_NOTIMPLEMENTED; } static GSM_Error serial_open (GSM_StateMachine *s) { GSM_Device_SerialData *d = &s->Device.Data.Serial; - return ERR_NONE; + return ERR_NOTIMPLEMENTED; } static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity) { GSM_Device_SerialData *d = &s->Device.Data.Serial; - return ERR_NONE; + return ERR_NOTIMPLEMENTED; } static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) { GSM_Device_SerialData *d = &s->Device.Data.Serial; - return ERR_NONE; + return ERR_NOTIMPLEMENTED; } static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) { GSM_Device_SerialData *d = &s->Device.Data.Serial; - return ERR_NONE; + return ERR_NOTIMPLEMENTED; } static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) { GSM_Device_SerialData *d = &s->Device.Data.Serial; return 0; } static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) { GSM_Device_SerialData *d = &s->Device.Data.Serial; return 0; } diff --git a/gammu/emb/common/device/serial/ser_unx.c b/gammu/emb/common/device/serial/ser_unx.c index 2a87b11..69c7515 100644 --- a/gammu/emb/common/device/serial/ser_unx.c +++ b/gammu/emb/common/device/serial/ser_unx.c @@ -1,51 +1,75 @@ /* (c) 2002-2004 by Marcin Wiacek */ /* locking device and settings all speeds by Michal Cihar */ +/* based on some 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 + */ #include "../../gsmstate.h" #ifdef GSM_ENABLE_SERIALDEVICE #ifndef WIN32 #ifndef DJGPP #include <sys/file.h> #include <sys/time.h> #include <string.h> #include <termios.h> #include <errno.h> #include "../../gsmcomon.h" #include "ser_unx.h" +#ifndef O_NONBLOCK +# define O_NONBLOCK 0 +#endif + +#ifdef __NetBSD__ +# define FNONBLOCK O_NONBLOCK + +# define B57600 0010001 +# define B115200 0010002 +# define B230400 0010003 +# define B460800 0010004 +# define B500000 0010005 +# define B576000 0010006 +# define B921600 0010007 +# define B1000000 0010010 +# define B1152000 0010011 +# define B1500000 0010012 +# define B2000000 0010013 +# define B2500000 0010014 +# define B3000000 0010015 +# define B3500000 0010016 +# define B4000000 0010017 +#endif + static GSM_Error serial_close(GSM_StateMachine *s) { GSM_Device_SerialData *d = &s->Device.Data.Serial; /* Restores old settings */ tcsetattr(d->hPhone, TCSANOW, &d->old_settings); /* Closes device */ close(d->hPhone); return ERR_NONE; } -#ifndef O_NONBLOCK -# define O_NONBLOCK 0 -#endif - static GSM_Error serial_open (GSM_StateMachine *s) { GSM_Device_SerialData *d = &s->Device.Data.Serial; struct termios t; int i; /* O_NONBLOCK MUST is required to avoid waiting for DCD */ d->hPhone = open(s->CurrentConfig->Device, O_RDWR | O_NOCTTY | O_NONBLOCK); if (d->hPhone < 0) { i = errno; GSM_OSErrorInfo(s,"open in serial_open"); if (i == 2) return ERR_DEVICENOTEXIST; //no such file or directory if (i == 13) return ERR_DEVICENOPERMISSION; //permission denied return ERR_DEVICEOPENERROR; } @@ -164,72 +188,76 @@ static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) dbgprintf("Serial device:"); dbgprintf(" DTR is %s", flags&TIOCM_DTR?"up":"down"); dbgprintf(", RTS is %s", flags&TIOCM_RTS?"up":"down"); dbgprintf(", CAR is %s", flags&TIOCM_CAR?"up":"down"); dbgprintf(", CTS is %s\n", flags&TIOCM_CTS?"up":"down"); if (((flags&TIOCM_DTR)==TIOCM_DTR) != dtr) return ERR_DEVICEDTRRTSERROR; if (((flags&TIOCM_RTS)==TIOCM_RTS) != rts) return ERR_DEVICEDTRRTSERROR; return ERR_NONE; } static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) { GSM_Device_SerialData *d = &s->Device.Data.Serial; struct termios t; - int speed2 = B19200; + int speed2 = B19200; if (tcgetattr(d->hPhone, &t)) { GSM_OSErrorInfo(s,"tcgetattr in serial_setspeed"); return ERR_DEVICEREADERROR; } smprintf(s, "Setting speed to %d\n", speed); switch (speed) { case 50: speed2 = B50; break; case 75: speed2 = B75; break; case 110: speed2 = B110; break; case 134: speed2 = B134; break; case 150: speed2 = B150; break; case 200: speed2 = B200; break; case 300: speed2 = B300; break; case 600: speed2 = B600; break; case 1200: speed2 = B1200; break; case 1800: speed2 = B1800; break; case 2400: speed2 = B2400; break; case 4800: speed2 = B4800; break; case 9600: speed2 = B9600; break; case 19200: speed2 = B19200; break; case 38400: speed2 = B38400; break; +#ifdef B57600 case 57600: speed2 = B57600; break; case 115200: speed2 = B115200; break; case 230400: speed2 = B230400; break; case 460800: speed2 = B460800; break; +#ifdef B500000 case 500000: speed2 = B500000; break; case 576000: speed2 = B576000; break; case 921600: speed2 = B921600; break; case 1000000: speed2 = B1000000; break; case 1152000: speed2 = B1152000; break; case 1500000: speed2 = B1500000; break; case 2000000: speed2 = B2000000; break; case 2500000: speed2 = B2500000; break; case 3000000: speed2 = B3000000; break; case 3500000: speed2 = B3500000; break; case 4000000: speed2 = B4000000; break; +#endif +#endif } /* This should work on all systems because it is done according to POSIX */ cfsetispeed(&t, speed2); cfsetospeed(&t, speed2); if (tcsetattr(d->hPhone, TCSADRAIN, &t) == -1) { serial_close(s); GSM_OSErrorInfo(s,"tcsetattr in serial_setspeed"); return ERR_DEVICECHANGESPEEDERROR; } return ERR_NONE; } static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) diff --git a/gammu/emb/common/device/serial/ser_w32.c b/gammu/emb/common/device/serial/ser_w32.c index 9fa0135..7d88fc7 100644 --- a/gammu/emb/common/device/serial/ser_w32.c +++ b/gammu/emb/common/device/serial/ser_w32.c @@ -1,18 +1,22 @@ /* (c) 2002-2004 by Marcin Wiacek */ -/* based on some work from Gnokii, MSDN and others */ +/* based on some work from MSDN and others */ +/* based on some 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 + */ #include "../../gsmstate.h" #ifdef GSM_ENABLE_SERIALDEVICE #ifdef WIN32 #include <windows.h> #include <string.h> #include <stdio.h> #include <io.h> #include <memory.h> #include "../../gsmcomon.h" #include "ser_w32.h" static GSM_Error serial_close(GSM_StateMachine *s) |