X-Git-Url: http://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=common%2Fdevices%2Funixirda.c;h=31beb660a54aed6ed5b9acb96739ef41cdb33ffc;hp=cfbf39addd0c95afeab5b9e64b5fa8841832253b;hb=49dd905279a8e62936e3713510ab0fd738e20ecb;hpb=2f2703c9133032c12671ca5c77ae626b8fb178d4 diff --git a/common/devices/unixirda.c b/common/devices/unixirda.c index cfbf39a..31beb66 100644 --- a/common/devices/unixirda.c +++ b/common/devices/unixirda.c @@ -1,10 +1,14 @@ /* * $Id$ * + * * 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) 2000-2001 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 @@ -19,22 +23,45 @@ * License along with this library; if not, write to the Free * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * $Log$ + * Revision 1.1.1.3 2002/04/03 00:08:06 short + * Found in "gnokii-working" directory, some November-patches version + * + * Revision 1.7 2001/11/08 16:49:19 pkot + * Cleanups + * + * Revision 1.6 2001/08/17 00:18:12 pkot + * Removed recv() from IrDA initializing procedure (many people) + * + * Revision 1.5 2001/06/27 23:52:48 pkot + * 7110/6210 updates (Marian Jancar) + * + * Revision 1.4 2001/06/20 21:27:34 pkot + * IrDA patch (Marian Jancar) + * + * Revision 1.3 2001/02/21 19:57:04 chris + * More fiddling with the directory layout + * + * Revision 1.2 2001/02/20 21:55:10 pkot + * Small #include updates + * + * Revision 1.1 2001/02/16 14:29:52 chris + * Restructure of common/. Fixed a problem in fbus-phonet.c + * Lots of dprintfs for Marcin + * Any size xpm can now be loaded (eg for 7110 startup logos) + * nk7110 code detects 7110/6210 and alters startup logo size to suit + * Moved Marcin's extended phonebook code into gnokii.c + * + * Revision 1.2 2001/02/06 21:15:35 chris + * Preliminary irda support for 7110 etc. Not well tested! + * + * Revision 1.1 2001/02/03 23:56:17 chris + * Start of work on irda support (now we just need fbus-irda.c!) + * Proper unicode support in 7110 code (from pkot) + * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "devices/unixirda.h" -#include "devices/linuxirda.h" - #ifndef AF_IRDA #define AF_IRDA 23 @@ -45,10 +72,7 @@ #define DISCOVERY_SLEEP 0.4 static char *phone[] = { - "Nokia 5210", - "Nokia 6210", "Nokia 6250", "Nokia 6310", - "Nokia 7110", - "Nokia 8210", "Nokia 8310", "Nokia 8850" + "Nokia 7110", "Nokia 6210" }; double d_time(void) @@ -77,17 +101,18 @@ double d_sleep(double s) return time; } -static int irda_discover_device(int fd) +static int irda_discover_device(void) { struct irda_device_list *list; struct irda_device_info *dev; unsigned char *buf; - int s, len, i, j; - int daddr = -1; + int s, len, i, j, daddr = -1, fd; double t1, t2; int phones = sizeof(phone) / sizeof(*phone); + fd = socket(AF_IRDA, SOCK_STREAM, 0); + len = sizeof(*list) + sizeof(*dev) * 10; // 10 = max devices in discover buf = malloc(len); list = (struct irda_device_list *)buf; @@ -104,15 +129,11 @@ static int irda_discover_device(int fd) for (j = 0; (j < phones) && (daddr == -1); j++) { if (strncmp(dev[i].info, phone[j], INFO_LEN) == 0) { daddr = dev[i].daddr; -#ifdef DEBUG - fprintf(stdout,_("%s\t%x\n"), dev[i].info, dev[i].daddr); -#endif + dprintf("%s\t%x\n", dev[i].info, dev[i].daddr); } } if (daddr == -1) { -#ifdef DEBUG - fprintf(stdout,_("unknown: %s\t%x\n"), dev[i].info, dev[i].daddr); -#endif + dprintf("unknown: %s\t%x\n", dev[i].info, dev[i].daddr); } } } @@ -126,6 +147,7 @@ static int irda_discover_device(int fd) } while ((t2 - t1 < DISCOVERY_TIMEOUT) && (daddr == -1)); free(buf); + close(fd); return daddr; } @@ -134,44 +156,24 @@ int irda_open(void) { struct sockaddr_irda peer; int fd = -1, daddr; - int pgrp; + daddr = irda_discover_device(); /* discover the devices */ - fd = socket(AF_IRDA, SOCK_STREAM, 0); /* Create socket */ - if (fd == -1) { - perror("socket"); - exit(1); - } - - /* discover the devices */ - daddr = irda_discover_device(fd); - if (daddr == -1) { - printf("irda_discover: no nokia devices found"); - exit(1); - } - - /* Arrange for the current process to receive - SIGIO when the state of the socket changes. */ - pgrp = getpid(); - if (fcntl (fd, F_SETOWN, pgrp) < 0) - perror("F_SETOWN"); - - /* Set the socket state for Asynchronous */ - if (fcntl (fd, F_SETFL, FASYNC) < 0) { - perror("fcntl"); - exit(1); - } - - peer.sir_family = AF_IRDA; - peer.sir_lsap_sel = LSAP_ANY; - peer.sir_addr = daddr; - strcpy(peer.sir_name, "Nokia:PhoNet"); + if (daddr != -1) { + fd = socket(AF_IRDA, SOCK_STREAM, 0); /* Create socket */ + peer.sir_family = AF_IRDA; + peer.sir_lsap_sel = LSAP_ANY; + peer.sir_addr = daddr; + strcpy(peer.sir_name, "Nokia:PhoNet"); - if (connect(fd, (struct sockaddr *)&peer, sizeof(peer))) { /* Connect to service "Nokia:PhoNet" */ - perror("connect"); - close(fd); - fd = -1; + if (connect(fd, (struct sockaddr *)&peer, sizeof(peer))) { /* Connect to service "Nokia:PhoNet" */ + perror("connect"); + close(fd); + fd = -1; +/* } else { FIXME: It does not work in most cases. Why? Or why it should work? + recv(fd, NULL, 0, 0); call recv first to make select work correctly */ } + } return fd; } @@ -184,20 +186,7 @@ int irda_close(int fd) int irda_write(int __fd, __const __ptr_t __bytes, int __size) { - int actual,ret; - - actual = 0; - - do { - if ((ret = send(__fd, __bytes, __size - actual, 0)) < 0) - return(actual); - - actual += ret; - __bytes += ret; - - } while (actual < __size); - - return (actual); + return (send(__fd, __bytes, __size, 0)); } int irda_read(int __fd, __ptr_t __bytes, int __size)