author | zautrix <zautrix> | 2004-08-07 17:24:40 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-07 17:24:40 (UTC) |
commit | 88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22 (patch) (side-by-side diff) | |
tree | 6331418973714243beb674abc87692277b83869d /gammu/emb/common/device/irda | |
parent | ef8a09ce74ad3f0a51484d03fdf009bd5b3677bf (diff) | |
download | kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.zip kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.gz kdepimpi-88b0d33b8b0b1f6ae320cfc863ca6a47fa8fec22.tar.bz2 |
Initial revision
-rw-r--r-- | gammu/emb/common/device/irda/irda.c | 187 | ||||
-rw-r--r-- | gammu/emb/common/device/irda/irda.h | 22 | ||||
-rw-r--r-- | gammu/emb/common/device/irda/irda_unx.h | 61 | ||||
-rw-r--r-- | gammu/emb/common/device/irda/irda_w32.h | 35 |
4 files changed, 305 insertions, 0 deletions
diff --git a/gammu/emb/common/device/irda/irda.c b/gammu/emb/common/device/irda/irda.c new file mode 100644 index 0000000..fef50ac --- a/dev/null +++ b/gammu/emb/common/device/irda/irda.c @@ -0,0 +1,187 @@ +/* (c) 2001-2004 by Marcin Wiacek */ +/* based on some work from Ralf Thelen and MyGnokii */ +/* based on some work from Gnokii and MSDN */ + +/* 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> +# include <sys/poll.h> +# include <sys/socket.h> +# include <sys/ioctl.h> +#else +# include <windows.h> +# include <io.h> +#endif + +#include "../../gsmcomon.h" +#include "../devfunc.h" +#include "irda.h" + +static bool irda_discover_device(GSM_StateMachine *state) +{ + GSM_Device_IrdaData *d = &state->Device.Data.Irda; + struct irda_device_list *list; + unsigned char *buf; + unsigned int sec; + int s, z, len, fd, i; + GSM_DateTime Date; + bool founddevice = false; +#ifdef WIN32 + int index; +#endif + + fd = socket(AF_IRDA, SOCK_STREAM, 0); + + /* can handle maximally 10 devices during discovering */ + len = sizeof(struct irda_device_list) + sizeof(struct irda_device_info) * 10; + buf = malloc(len); + list = (struct irda_device_list *)buf; + + /* Trying to find device during 2 seconds */ + for (z=0;z<2;z++) { + GSM_GetCurrentDateTime (&Date); + sec = Date.Second; + while (sec==Date.Second) { + s = len; + memset(buf, 0, s); + + if (getsockopt(fd, SOL_IRLMP, IRLMP_ENUMDEVICES, buf, &s) == 0) { + for (i = 0; i < (int)list->numDevice; i++) { + dbgprintf("Irda: found device \"%s\" (address %x) - ",list->Device[i].irdaDeviceName,list->Device[i].irdaDeviceID); + if (strcmp(GetModelData(NULL,NULL,list->Device[i].irdaDeviceName)->number,"") != 0) { + founddevice = true; + /* Model AUTO */ + if (state->CurrentConfig->Model[0]==0) strcpy(state->Phone.Data.Model,GetModelData(NULL,NULL,list->Device[i].irdaDeviceName)->number); + state->Phone.Data.ModelInfo = GetModelData(NULL,state->Phone.Data.Model,NULL); + } + if (founddevice) { + dbgprintf("correct\n"); +#ifdef WIN32 + for(index=0; index <= 3; index++) + d->peer.irdaDeviceID[index] = list->Device[i].irdaDeviceID[index]; +#else + d->peer.irdaDeviceID = list->Device[i].irdaDeviceID; +#endif + break; + } + dbgprintf("\n"); + } + } + if (founddevice) break; + my_sleep(10); + GSM_GetCurrentDateTime(&Date); + } + if (founddevice) break; + } + free(buf); + close(fd); + + return founddevice; +} + +static GSM_Error irda_open (GSM_StateMachine *s) +{ + GSM_Device_IrdaData *d = &s->Device.Data.Irda; + int fd = -1; +#ifdef WIN32 + int Enable9WireMode = 1; + WSADATA wsaData; + + WSAStartup(MAKEWORD(1,1), &wsaData); +#else + if (s->ConnectionType == GCT_IRDAAT) return ERR_SOURCENOTAVAILABLE; +#endif + + /* discovering devices */ + if (irda_discover_device(s)==false) return ERR_TIMEOUT; + + /* Creating socket */ + fd = socket(AF_IRDA, SOCK_STREAM, 0); + + d->peer.irdaAddressFamily = AF_IRDA; +#ifndef WIN32 + d->peer.sir_lsap_sel = LSAP_ANY; +#endif + switch (s->ConnectionType) { + case GCT_IRDAAT: + strcpy(d->peer.irdaServiceName, "IrDA:IrCOMM"); + +#ifdef WIN32 + if (setsockopt(fd, SOL_IRLMP, IRLMP_9WIRE_MODE, (const char *) &Enable9WireMode, + sizeof(int))==SOCKET_ERROR) return ERR_UNKNOWN; +#endif + break; + case GCT_IRDAPHONET: + strcpy(d->peer.irdaServiceName, "Nokia:PhoNet"); + break; + case GCT_IRDAOBEX: + /* IrDA:OBEX not supported by N3650 */ +// strcpy(d->peer.irdaServiceName, "IrDA:OBEX"); + + strcpy(d->peer.irdaServiceName, "OBEX"); + + /* Alternative server is "OBEX:IrXfer" */ + break; + default: + return ERR_UNKNOWN; + } + + /* Connecting to service */ + if (connect(fd, (struct sockaddr *)&d->peer, sizeof(d->peer))) { + dbgprintf("Can't connect to service %s\n",d->peer.irdaServiceName); + close(fd); + return ERR_NOTSUPPORTED; + } + + d->hPhone=fd; + + return ERR_NONE; +} + +static int irda_read(GSM_StateMachine *s, void *buf, size_t nbytes) +{ + return socket_read(s, buf, nbytes, s->Device.Data.Irda.hPhone); +} + +#ifdef WIN32 +static int irda_write(GSM_StateMachine *s, unsigned char *buf, size_t nbytes) +#else +static int irda_write(GSM_StateMachine *s, void *buf, size_t nbytes) +#endif +{ + return socket_write(s, buf, nbytes, s->Device.Data.Irda.hPhone); +} + +static GSM_Error irda_close(GSM_StateMachine *s) +{ + return socket_close(s, s->Device.Data.Irda.hPhone); +} + +GSM_Device_Functions IrdaDevice = { + irda_open, + irda_close, + NONEFUNCTION, + NONEFUNCTION, + NONEFUNCTION, + irda_read, + irda_write +}; + +#endif +#endif + +/* How should editor hadle tabs in this file? Add editor commands here. + * vim: noexpandtab sw=8 ts=8 sts=8: + */ diff --git a/gammu/emb/common/device/irda/irda.h b/gammu/emb/common/device/irda/irda.h new file mode 100644 index 0000000..455e6af --- a/dev/null +++ b/gammu/emb/common/device/irda/irda.h @@ -0,0 +1,22 @@ + +#ifndef DJGPP +#ifndef unixirda_h +#define unixirda_h + +#ifndef WIN32 +# include "irda_unx.h" +#else +# include "irda_w32.h" +#endif + +typedef struct { + int hPhone; + struct sockaddr_irda peer; +} GSM_Device_IrdaData; + +#endif +#endif + +/* How should editor hadle tabs in this file? Add editor commands here. + * vim: noexpandtab sw=8 ts=8 sts=8: + */ diff --git a/gammu/emb/common/device/irda/irda_unx.h b/gammu/emb/common/device/irda/irda_unx.h new file mode 100644 index 0000000..8dbcb97 --- a/dev/null +++ b/gammu/emb/common/device/irda/irda_unx.h @@ -0,0 +1,61 @@ +/* part of irda.h available in Linux kernel source */ + +/********************************************************************* + * + * 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 + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Neither Dag Brattli nor University of Tromsų admit liability nor + * provide warranty for any of this software. This material is + * provided "AS-IS" and at no charge. + * + ********************************************************************/ + +#ifndef __irda_unx_h +#define __irda_unx_h + +#include <sys/types.h> +#include <sys/socket.h> + +#define SOL_IRLMP 266 /* Same as SOL_IRDA for now */ +#define IRLMP_ENUMDEVICES 1 /* Return discovery log */ +#define LSAP_ANY 0xff + +struct sockaddr_irda { + sa_family_t irdaAddressFamily; /* AF_IRDA */ + u_int8_t sir_lsap_sel; /* LSAP selector */ + u_int32_t irdaDeviceID; /* Device address */ + char irdaServiceName[25]; /* Usually <service>:IrDA:TinyTP */ +}; + +struct irda_device_info { + u_int32_t saddr; /* Address of local interface */ + u_int32_t irdaDeviceID; /* Address of remote device */ + char irdaDeviceName[22]; /* Description */ + u_int8_t charset; /* Charset used for description */ + u_int8_t hints[2]; /* Hint bits */ +}; + +struct irda_device_list { + u_int32_t numDevice; + struct irda_device_info Device[1]; +}; + +#endif + +/* How should editor hadle tabs in this file? Add editor commands here. + * vim: noexpandtab sw=8 ts=8 sts=8: + */ diff --git a/gammu/emb/common/device/irda/irda_w32.h b/gammu/emb/common/device/irda/irda_w32.h new file mode 100644 index 0000000..daffa37 --- a/dev/null +++ b/gammu/emb/common/device/irda/irda_w32.h @@ -0,0 +1,35 @@ + +/* MS Platform SDK */ + +#ifndef __irda_w32_h +#define __irda_w32_h + +#define AF_IRDA 26 +#define SOL_IRLMP 0x00FF +#define IRLMP_ENUMDEVICES 0x00000010 +#define IRLMP_9WIRE_MODE 0x00000016 + +struct sockaddr_irda { + unsigned short irdaAddressFamily; + unsigned char irdaDeviceID[4]; + char irdaServiceName[25]; +}; + +struct irda_device_info { + unsigned char irdaDeviceID[4]; + char irdaDeviceName[22]; + unsigned char irdaDeviceHints1; + unsigned char irdaDeviceHints2; + unsigned char irdaCharSet; +}; + +struct irda_device_list { + ULONG numDevice; + struct irda_device_info Device[1]; +}; + +#endif + +/* How should editor hadle tabs in this file? Add editor commands here. + * vim: noexpandtab sw=8 ts=8 sts=8: + */ |