Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port" ats ats_tcp_connection1
authorshort <>
Wed, 3 Apr 2002 01:44:15 +0000 (01:44 +0000)
committershort <>
Wed, 3 Apr 2002 01:44:15 +0000 (01:44 +0000)
12 files changed:
common/cimd.c
common/device.c
common/devices/Makefile
common/devices/tcp.c [new file with mode: 0644]
common/devices/unixserial.c
gnokii/gnokii.c
gnokiid/gnokiid.c
include/devices/tcp.h [new file with mode: 0644]
include/devices/unixserial.h
include/gsm-common.h
smsd/lowlevel.c
xgnokii/xgnokii_lowlevel.c

index e213170..5784020 100644 (file)
@@ -17,6 +17,9 @@
   The various routines are prefixed by CIMD.
 
   $Log$
   The various routines are prefixed by CIMD.
 
   $Log$
+  Revision 1.1.1.2  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.1  2002/04/03 00:08:03  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.1  2002/04/03 00:08:03  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -757,7 +760,7 @@ static GSM_Error CIMD_PhoneSetup(void)
 
 static void CIMD_RX_Char(char rx_byte);
 static void CIMD_SigHandler(int status);
 
 static void CIMD_RX_Char(char rx_byte);
 static void CIMD_SigHandler(int status);
-static bool CIMD_OpenSerial(void);
+static bool CIMD_OpenSerial(GSM_ConnectionType connection);
 
 GSM_Phone phone_cimd;  /* forward declaration */
 
 
 GSM_Phone phone_cimd;  /* forward declaration */
 
@@ -780,7 +783,7 @@ int rtn;
 }
 #else
        SAFE_STRNCPY_SIZEOF(PortDevice,state->Link.PortDevice);
 }
 #else
        SAFE_STRNCPY_SIZEOF(PortDevice,state->Link.PortDevice);
-       if (!CIMD_OpenSerial())
+       if (!CIMD_OpenSerial(state->Link.ConnectionType))
                return(GE_INTERNALERROR);
 #endif
 
                return(GE_INTERNALERROR);
 #endif
 
@@ -1203,7 +1206,7 @@ static GSM_Error CIMD_Reset(GSM_Data *data, GSM_Statemachine *state)
 
 /* Called by initialisation code to open comm port in asynchronous mode. */
 
 
 /* Called by initialisation code to open comm port in asynchronous mode. */
 
-static bool CIMD_OpenSerial(void)
+static bool CIMD_OpenSerial(GSM_ConnectionType connection)
 {
        int result;
   
 {
        int result;
   
@@ -1221,7 +1224,7 @@ static bool CIMD_OpenSerial(void)
 
        /* Open device. */
 
 
        /* Open device. */
 
-       result = device_open(PortDevice, false/*with_odd_parity*/, true/*with_async*/, -1/*with_hw_handshake*/, GCT_Serial);
+       result = device_open(PortDevice, false/*with_odd_parity*/, true/*with_async*/, -1/*with_hw_handshake*/, connection);
 
        if (!result) {
                perror(_("Couldn't open CIMD device"));
 
        if (!result) {
                perror(_("Couldn't open CIMD device"));
index dee2fe2..ad8ef2c 100644 (file)
@@ -11,6 +11,9 @@
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
+  Revision 1.1.1.2  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.1  2001/11/25 21:58:58  short
   :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
 
   Revision 1.1.1.1  2001/11/25 21:58:58  short
   :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
 
@@ -41,6 +44,7 @@
 #include "devices/unixserial.h"
 #include "devices/unixirda.h"
 #include "devices/tekram.h"
 #include "devices/unixserial.h"
 #include "devices/unixirda.h"
 #include "devices/tekram.h"
+#include "devices/tcp.h"
 #include "device.h"
 
 /*
 #include "device.h"
 
 /*
@@ -74,6 +78,9 @@ int device_open(__const char *__file, int __with_odd_parity, int __with_async, i
   case GCT_Irda:
     device_portfd = irda_open();
     break;
   case GCT_Irda:
     device_portfd = irda_open();
     break;
+  case GCT_TCP:
+    device_portfd = tcp_opendevice(__file, __with_async);
+    break;
   default:
     break;
   }
   default:
     break;
   }
@@ -93,6 +100,9 @@ void device_close(void)
   case GCT_Irda:
     irda_close(device_portfd);
     break;
   case GCT_Irda:
     irda_close(device_portfd);
     break;
+  case GCT_TCP:
+    tcp_close(device_portfd);
+    break;
   default:
     break;
   }
   default:
     break;
   }
@@ -113,6 +123,8 @@ void device_setdtrrts(int __dtr, int __rts)
     break;
   case GCT_Irda:
     break;
     break;
   case GCT_Irda:
     break;
+  case GCT_TCP:
+    break;
   default:
     break;
   }
   default:
     break;
   }
@@ -130,6 +142,8 @@ void device_changespeed(int __speed)
     break;
   case GCT_Irda:
     break;
     break;
   case GCT_Irda:
     break;
+  case GCT_TCP:
+    break;
   default:
     break;
   }
   default:
     break;
   }
@@ -148,6 +162,9 @@ size_t device_read(__ptr_t __buf, size_t __nbytes)
   case GCT_Irda:
     return irda_read(device_portfd, __buf, __nbytes);
     break;
   case GCT_Irda:
     return irda_read(device_portfd, __buf, __nbytes);
     break;
+  case GCT_TCP:
+    return tcp_read(device_portfd, __buf, __nbytes);
+    break;
   default:
     break;
   }
   default:
     break;
   }
@@ -167,6 +184,9 @@ size_t device_write(__const __ptr_t __buf, size_t __n)
   case GCT_Irda:
     return irda_write(device_portfd, __buf, __n);
     break;
   case GCT_Irda:
     return irda_write(device_portfd, __buf, __n);
     break;
+  case GCT_TCP:
+    return tcp_write(device_portfd, __buf, __n);
+    break;
   default:
     break;
   }
   default:
     break;
   }
@@ -186,6 +206,9 @@ int device_select(struct timeval *timeout)
   case GCT_Irda:
     return irda_select(device_portfd, timeout);
     break;
   case GCT_Irda:
     return irda_select(device_portfd, timeout);
     break;
+  case GCT_TCP:
+    return tcp_select(device_portfd, timeout);
+    break;
   default:
     break;
   }
   default:
     break;
   }
index aefedc8..ae54cd1 100644 (file)
@@ -23,7 +23,8 @@ ifdef WIN32
        OBJS += $(TOPDIR)/win32/winserial.o
 else
        OBJS += unixserial.o \
        OBJS += $(TOPDIR)/win32/winserial.o
 else
        OBJS += unixserial.o \
-               unixirda.o
+               unixirda.o \
+               tcp.o
 endif
 
 all: DEVICES.o
 endif
 
 all: DEVICES.o
diff --git a/common/devices/tcp.c b/common/devices/tcp.c
new file mode 100644 (file)
index 0000000..ea4918e
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+  
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for Nokia mobile phones.
+
+  Copyright (C) 2002 Jan Kratochvil
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+*/
+
+#include "misc.h"
+#include "cfgreader.h"
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#if __unices__
+#  include <sys/file.h>
+#endif
+
+#include <termios.h>
+#include "devices/tcp.h"
+#include "devices/unixserial.h"
+
+#ifdef HAVE_SYS_IOCTL_COMPAT_H
+  #include <sys/ioctl_compat.h>
+#endif
+
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+#ifndef O_NONBLOCK
+  #define O_NONBLOCK  0
+#endif
+
+/* Open the serial port and store the settings. */
+
+int tcp_open(__const char *__file) {
+
+  int __fd;
+  int i;
+  struct sockaddr_in addr;
+  static bool atexit_registered=false;
+  char *filedup,*portstr,*end;
+  unsigned long portul;
+  struct hostent *hostent;
+
+  if (!atexit_registered) {
+    memset(serial_close_all_openfds,-1,sizeof(serial_close_all_openfds));
+#if 0  /* Disabled for now as atexit() functions are then called multiple times for pthreads! */
+    signal(SIGINT,unixserial_interrupted);
+#endif
+    atexit(serial_close_all);
+    atexit_registered=true;
+    }
+
+  __fd = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
+  if (__fd == -1) {
+    perror("Gnokii tcp_open: socket()");
+    return (-1);
+  }
+  if (!(filedup=strdup(__file))) {
+fail_close:
+    close(__fd);
+    return (-1);
+  }
+  if (!(portstr=strchr(filedup,':'))) {
+    fprintf(stderr,"Gnokii tcp_open: colon (':') not found in connect strings \"%s\"!\n",filedup);
+fail_free:
+    free(filedup);
+    goto fail_close;
+  }
+  *portstr++='\0';
+  portul=strtoul(portstr,&end,0);
+  if ((end && *end) || portul>=0x10000) {
+    fprintf(stderr,"Gnokii tcp_open: Port string \"%s\" not valid for IPv4 connection!\n",portstr);
+    goto fail_free;
+  }
+  if (!(hostent=gethostbyname(filedup))) {
+    fprintf(stderr,"Gnokii tcp_open: Unknown host \"%s\"!\n",filedup);
+    goto fail_free;
+  }
+  if (hostent->h_addrtype!=AF_INET || hostent->h_length!=sizeof(addr.sin_addr) || !hostent->h_addr_list[0]) {
+    fprintf(stderr,"Gnokii tcp_open: Address resolve for host \"%s\" not compatible!\n",filedup);
+    goto fail_free;
+  }
+  free(filedup);
+  
+  addr.sin_family=AF_INET;
+  addr.sin_port=htons(portul);
+  memcpy(&addr.sin_addr,hostent->h_addr_list[0],sizeof(addr.sin_addr));
+
+  if (connect(__fd,(struct sockaddr *)&addr,sizeof(addr))) {
+    perror("Gnokii tcp_open: connect()");
+    goto fail_close;
+  }
+
+  for (i=0;i<ARRAY_LEN(serial_close_all_openfds);i++)
+    if (serial_close_all_openfds[i]==-1 || serial_close_all_openfds[i]==__fd) {
+      serial_close_all_openfds[i]=__fd;
+      break;
+      }
+
+  return __fd;
+}
+
+int tcp_close(int __fd) {
+  int i;
+
+  for (i=0;i<ARRAY_LEN(serial_close_all_openfds);i++)
+    if (serial_close_all_openfds[i]==__fd)
+      serial_close_all_openfds[i]=-1;          /* fd closed */
+
+  /* handle config file disconnect_script:
+   */
+  if (-1 == device_script(__fd,"disconnect_script"))
+    fprintf(stderr,"Gnokii tcp_close: disconnect_script\n");
+
+  return (close(__fd));
+}
+
+/* Open a device with standard options.
+ * Use value (-1) for "__with_hw_handshake" if its specification is required from the user
+ */
+int tcp_opendevice(__const char *__file, int __with_async) {
+
+  int fd;
+  int retcode;
+
+  /* Open device */
+
+  fd = tcp_open(__file);
+
+  if (fd < 0) 
+    return fd;
+
+  /* handle config file connect_script:
+   */
+  if (-1 == device_script(fd,"connect_script")) {
+    fprintf(stderr,"Gnokii tcp_opendevice: connect_script\n");
+    tcp_close(fd);
+    return(-1);
+  }
+
+  /* Allow process/thread to receive SIGIO */
+
+#if !(__unices__)
+  retcode = fcntl(fd, F_SETOWN, getpid());
+  if (retcode == -1){
+    perror("Gnokii tcp_opendevice: fnctl(F_SETOWN)");
+    tcp_close(fd);
+    return(-1);
+  }
+#endif
+
+  /* Make filedescriptor asynchronous. */
+
+  /* We need to supply FNONBLOCK (or O_NONBLOCK) again as it would get reset
+   * by F_SETFL as a side-effect!
+   */
+  retcode=fcntl(fd, F_SETFL, (__with_async ? FASYNC : 0) | FNONBLOCK);
+  if (retcode == -1){
+    perror("Gnokii tcp_opendevice: fnctl(F_SETFL)");
+    tcp_close(fd);
+    return(-1);
+  }
+  
+  return fd;
+}
+
+int tcp_select(int fd, struct timeval *timeout) {
+
+  return serial_select(fd, timeout);
+}
+
+
+/* Read from serial device. */
+
+size_t tcp_read(int __fd, __ptr_t __buf, size_t __nbytes) {
+
+  return (read(__fd, __buf, __nbytes));
+}
+
+/* Write to serial device. */
+
+size_t tcp_write(int __fd, __const __ptr_t __buf, size_t __n) {
+
+       return(write(__fd, __buf, __n));
+}
index 9594d89..80b4b7a 100644 (file)
@@ -11,6 +11,9 @@
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
+  Revision 1.1.1.6  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.5  2002/04/03 00:08:07  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.5  2002/04/03 00:08:07  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -113,7 +116,7 @@ static void device_script_cfgfunc(const char *section,const char *key,const char
   setenv(key,value,1/*overwrite*/);    /* errors ignored */
 }
 
   setenv(key,value,1/*overwrite*/);    /* errors ignored */
 }
 
-static int device_script(int fd, const char *section)
+int device_script(int fd, const char *section)
 {
 pid_t pid;
 const char *scriptname = CFG_Get(CFG_Info, "global", section);
 {
 pid_t pid;
 const char *scriptname = CFG_Get(CFG_Info, "global", section);
@@ -159,7 +162,7 @@ int status;
 int serial_close_all_openfds[0x10];    /* -1 when entry not used, fd otherwise */
 int serial_close(int __fd);
 
 int serial_close_all_openfds[0x10];    /* -1 when entry not used, fd otherwise */
 int serial_close(int __fd);
 
-static void serial_close_all(void)
+void serial_close_all(void)
 {
   int i;
 
 {
   int i;
 
@@ -169,7 +172,7 @@ static void serial_close_all(void)
       serial_close(serial_close_all_openfds[i]);
 }
 
       serial_close(serial_close_all_openfds[i]);
 }
 
-static void unixserial_interrupted(int signo)
+void unixserial_interrupted(int signo)
 {
        exit(EXIT_FAILURE);
        /* NOTREACHED */
 {
        exit(EXIT_FAILURE);
        /* NOTREACHED */
index 472f4e5..b7f0850 100644 (file)
@@ -19,6 +19,9 @@
   really powerful and useful :-)
 
   $Log$
   really powerful and useful :-)
 
   $Log$
+  Revision 1.1.1.12  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.11  2002/04/03 00:08:17  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.11  2002/04/03 00:08:17  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -362,6 +365,7 @@ void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 
        if (!strcmp(Connection, "infrared")) connection=GCT_Infrared;
        if (!strcmp(Connection, "irda"))     connection=GCT_Irda;
 
        if (!strcmp(Connection, "infrared")) connection=GCT_Infrared;
        if (!strcmp(Connection, "irda"))     connection=GCT_Irda;
+       if (!strcmp(Connection, "tcp"))      connection=GCT_TCP;
 
        /* Initialise the code for the GSM interface. */     
 
 
        /* Initialise the code for the GSM interface. */     
 
index e0b8f16..26cb16f 100644 (file)
@@ -14,6 +14,9 @@
   various daemon functions.
 
   $Log$
   various daemon functions.
 
   $Log$
+  Revision 1.1.1.4  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.3  2002/04/03 00:08:17  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.3  2002/04/03 00:08:17  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -123,6 +126,10 @@ int main(int argc, char *argv[])
                 connection=GCT_Infrared;
         }
 
                 connection=GCT_Infrared;
         }
 
+        if (!strcmp(Connection, "tcp")) {
+                connection=GCT_TCP;
+        }
+
         TerminateThread=false;
 
         if (VM_Initialise(Model, Port, Initlength, connection, BinDir, DebugMode, true) == false) {
         TerminateThread=false;
 
         if (VM_Initialise(Model, Port, Initlength, connection, BinDir, DebugMode, true) == false) {
diff --git a/include/devices/tcp.h b/include/devices/tcp.h
new file mode 100644 (file)
index 0000000..0786ae4
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for Nokia mobile phones.
+
+  Copyright (C) 2002 Jan Kratochvil
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+*/
+
+#ifndef __devices_tcp_h
+#define __devices_tcp_h
+
+#ifdef WIN32
+  #include <stddef.h>
+  /* FIXME: this should be solved in config.h in 0.4.0 */
+  #define __const const
+  typedef void * __ptr_t;
+#else
+  #include <unistd.h>
+#endif /* WIN32 */
+
+#include "misc.h"
+
+int tcp_open(__const char *__file);
+int tcp_close(int __fd);
+
+int tcp_opendevice(__const char *__file, int __with_async);
+
+size_t tcp_read(int __fd, __ptr_t __buf, size_t __nbytes);
+size_t tcp_write(int __fd, __const __ptr_t __buf, size_t __n);
+
+int tcp_select(int fd, struct timeval *timeout);
+
+#endif  /* __devices_tcp_h */
index 9dca33b..0f95914 100644 (file)
@@ -11,6 +11,9 @@
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
+  Revision 1.1.1.5  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.4  2002/04/03 00:08:20  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.4  2002/04/03 00:08:20  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -50,6 +53,11 @@ size_t serial_write(int __fd, __const __ptr_t __buf, size_t __n);
 
 int serial_select(int fd, struct timeval *timeout);
 
 
 int serial_select(int fd, struct timeval *timeout);
 
+extern int serial_close_all_openfds[0x10];
+extern void serial_close_all(void);
+extern int device_script(int fd, const char *section);
+extern void unixserial_interrupted(int signo);
+
 #endif  /* __devices_unixserial_h */
 
 
 #endif  /* __devices_unixserial_h */
 
 
index cca004b..8fbca92 100644 (file)
@@ -14,6 +14,9 @@
   handset.
 
   $Log$
   handset.
 
   $Log$
+  Revision 1.1.1.10  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.9  2002/04/03 00:08:19  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.9  2002/04/03 00:08:19  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -44,7 +47,8 @@ typedef enum {
   GCT_Serial,   /* Serial connection. */
   GCT_Infrared, /* Infrared connection. */
   GCT_Tekram,   /* Tekram Ir-Dongle */
   GCT_Serial,   /* Serial connection. */
   GCT_Infrared, /* Infrared connection. */
   GCT_Tekram,   /* Tekram Ir-Dongle */
-  GCT_Irda
+  GCT_Irda,
+  GCT_TCP,      /* TCP network connection */
 } GSM_ConnectionType;
 
 /* Maximum length of device name for serial port */
 } GSM_ConnectionType;
 
 /* Maximum length of device name for serial port */
index ea36182..d5191d2 100644 (file)
@@ -11,6 +11,9 @@
   $Id$
   
   $Log$
   $Id$
   
   $Log$
+  Revision 1.1.1.4  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.3  2002/04/03 00:08:22  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.3  2002/04/03 00:08:22  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -137,6 +140,8 @@ static GSM_Error fbusinit(bool enable_monitoring)
 
   if (!strcmp(smsdConfig.connection, "infrared"))
     connection = GCT_Infrared;
 
   if (!strcmp(smsdConfig.connection, "infrared"))
     connection = GCT_Infrared;
+  if (!strcmp(smsdConfig.connection, "tcp"))
+    connection = GCT_TCP;
 
   /* Initialise the code for the GSM interface. */     
 
 
   /* Initialise the code for the GSM interface. */     
 
index 528a433..73b0b50 100644 (file)
@@ -11,6 +11,9 @@
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
   $Log$
+  Revision 1.1.1.5  2002/04/03 01:44:15  short
+  Implemented connection type "tcp" (GCT_TCP), use <hostname>:<port> as "port"
+
   Revision 1.1.1.4  2002/04/03 00:08:33  short
   Found in "gnokii-working" directory, some November-patches version
 
   Revision 1.1.1.4  2002/04/03 00:08:33  short
   Found in "gnokii-working" directory, some November-patches version
 
@@ -200,6 +203,9 @@ static GSM_Error fbusinit(bool enable_monitoring)
   if (!strcmp(xgnokiiConfig.connection, "irda"))
     connection = GCT_Irda;
 
   if (!strcmp(xgnokiiConfig.connection, "irda"))
     connection = GCT_Irda;
 
+  if (!strcmp(xgnokiiConfig.connection, "tcp"))
+    connection = GCT_TCP;
+
   /* Initialise the code for the GSM interface. */     
 
   if (error == GE_NOLINK)
   /* Initialise the code for the GSM interface. */     
 
   if (error == GE_NOLINK)