This commit was manufactured by cvs2svn to create tag orig2001_12_14_20_46
authorjankratochvil <>
Fri, 14 Dec 2001 19:49:20 +0000 (19:49 +0000)
committerjankratochvil <>
Fri, 14 Dec 2001 19:49:20 +0000 (19:49 +0000)
'orig2001_12_14_20_46'.

Sprout from ats 2001-12-14 19:49:18 UTC short ':pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Fri Dec 14 20:46 CET 2001'
Cherrypick from orig 2001-12-05 03:16:14 UTC short ':pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Dec  4 22:45 CET 2001':
    Docs/gnokii-hackers-howto
    Docs/sample/magic
    common/links/fbus-3110.c
    common/phones/ateric.c
    common/phones/atnok.c
    common/phones/atsie.c
    include/links/fbus-3110.h
    include/phones/ateric.h
    include/phones/atgen.h
    include/phones/atnok.h
    include/phones/atsie.h
Cherrypick from mygnokii 2001-11-27 22:01:30 UTC short ':pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 22:58 CET 2001':
    utils/sendsms

12 files changed:
Docs/gnokii-hackers-howto [new file with mode: 0644]
Docs/sample/magic [new file with mode: 0644]
common/links/fbus-3110.c [new file with mode: 0644]
common/phones/ateric.c [new file with mode: 0644]
common/phones/atnok.c [new file with mode: 0644]
common/phones/atsie.c [new file with mode: 0644]
include/links/fbus-3110.h [new file with mode: 0644]
include/phones/ateric.h [new file with mode: 0644]
include/phones/atgen.h [new file with mode: 0644]
include/phones/atnok.h [new file with mode: 0644]
include/phones/atsie.h [new file with mode: 0644]
utils/sendsms [new file with mode: 0644]

diff --git a/Docs/gnokii-hackers-howto b/Docs/gnokii-hackers-howto
new file mode 100644 (file)
index 0000000..4c1be0c
--- /dev/null
@@ -0,0 +1,193 @@
+GNOKII Hackers Guide
+--------------------
+
+
+Purpose
+-------
+
+Now that we know in some detail the workings of the protocols it makes
+sense to organise the gnokii code to fit them better.  This should mean
+that when new models come out, it is easier to get the code in place to
+support them.  It is hoped that the new structure will also work for other
+makes of phone.
+
+
+Overview:
+
+Application (gnokii/xgnoki)
+    |  DoSomething()
+(Middle-layer)
+    |  GSM->Function() 
+Gsm-api
+    |  P*_Functions()
+Phone specific code (eg nk7110.c)
+    |  SM_SendMessage(), SM_Wait(), SM_Loop()
+StateMachine
+    |  SendMessage(), Loop()
+Link specific code  (eg fbus.c)
+    |
+Hardware code
+
+
+
+Detailed operation
+------------------
+
+
+Initialisation:
+
+The gnokii application (eg gnokii, xgnokii) decides on the phone type and
+required connection method from the config file.  It then calls the
+gsm-api init code which in turn calls the init code for the correct phone.  
+This code is located in a series of files phone/*.c.  This code creates a
+GSM_State structure (which contains a GSM_Link structure) and passes this
+to the common code for the specific link (eg FBUS_Initialise, contained in
+fbus.c).  The link code fills in the GSM_Link part of state (and
+also stores state to use later).  The phone code chooses the appropriate
+link and is free to perform any phone specific init.  It then initialises
+the StateMachine by passing it the state struct and a GSM_Phone struct.
+
+
+The Link:
+
+The link serves to deal with bits of the phone protocol which are common to
+every exchange for that particular phone.
+
+The GSM_Link structure is used to contain any information about the link
+which is required by the StateMachine.  Two vital functions in the link
+are SendMessage and Loop:
+
+SendMessage(u16 messagesize, u8 messagetype, void *message)
+   is the function called by the statemachine code to send a message 'down
+   the pipe'.  The parameters are intended to be generic (though with 
+   obvious origins :-)  For example 'at' commands could be enumerated and 
+   passed as messagetype.
+
+Loop(struct timeval *timeout)
+   is a function which must be called regularly by the statemachine code
+   to enable to link code to process date from the phone.  This is due to 
+   the code now being single threaded and using select/poll.  The timeout 
+   passed can therefore be used to make this function block for a while 
+  (or not).
+
+In the loop function, the link code checks for any incoming messages from
+the phone.  Any received correctly are passed up to the statemachine code.
+
+
+The Middle Layer
+
+All common/*.c files contain the code that is general and is used by all
+of the phones. The functions within should convert the gnokii internal
+structures into the frames (without the header) that can be sent to the
+phone and understood by it. It's obvious that this layer should be phone
+independent. All the phone specific stuff should be done in the phone layer.
+In the case when phone frames are similiar but not the same, the phone layer
+can export some help structures to let be the code shared in the middle
+layer. Using the middle layer is optional. Currently almost no code does use
+it. Although it is recommended to use it to avoid the code duplication and
+to keep clean the phone drivers.
+
+
+The Phone:
+
+The phone/*.c code therefore basically contains code to package up and
+unpack information from the phone specific format to generic gnokii
+structures (eg GSM_Bitmap).  However, it is also at the top of the tree
+and contains functions called by the application.  Generally there are
+three types of exchanges that can occur.  Firstly the computer can send
+the phone a command and expect no answer (not including acks etc which 
+are dealt with by the phone code).  Secondly the computer may send a command
+and expect a response within a certain time - often containing useful 
+information.  Lastly the phone may send the computer unrequested 
+information (ring!).  Therefore the functions in the phone code need to 
+process one of these three things:
+
+1) Just sending out is easy - we simply call SM_SendMessage - which in
+turn calls the link sendmessage.
+
+2) Command and response.  There are two ways to do this.  In both cases we
+start out by sending a message via the statemachine.  Next we either a)
+wait for the reply or b) wait for some other code to process the reply.  
+My (*new improved*!!!) suggestion is that the statemachine calls phone
+functions (like parts of DispatchMessage) which process the received data
+into a generic structure tagged with the data type (one function for each
+data type).  This is returned to the statemachine.  The statemachine then
+returns this 'baggage' to the other part of the phone code which is
+waiting for it.
+
+3) Notification.  Here, as for 2) the statemachine calls some phone code,
+but the phone code merely remembers it and does not return any data.
+
+
+So, the phone file contains two types of functions.  Some are called by
+the application (via GSM_Functions) - and some by the statemachine
+(IncomingFunctions[]).  The application ones assemble a request and pass
+it on down to the statemachine.  They then block to the statemachine until
+the answer is ready.  The statemachine recieves data from the link and
+passes it up to the appropriate IncomingFunction in phone, which returns
+the answer which is finally passed back to the blocked phone function.
+
+
+The StateMachine: 
+
+This therefore has the following states:
+
+Startup
+Initialised
+MessageSent
+Waiting
+AnswerReady
+
+When SM_SendMessage is called by the phone (application code), we go to
+state MessageSent.  The message is passed on to the link, but stored
+internally as well in-case it needs to be resent.
+
+If at any point an message from the link is received this is passed onto
+the phone (incoming) code.
+
+If the phone code calls SM_WaitFor, we go to state Waiting.  Now if an
+answer comes back from the phone code (eg a received logo) we store it
+internally in the statemachine and go to state AnswerReady.
+
+When the phone code calls SM_GetAnswer, we pass up the stored answer and
+go back to Initialised.
+
+Note that all of this can, or can not be done as a seperate thread.  For
+now, we will have a SM_Loop function (which blocks for a required time and
+returns the current state) so that we can work within one thread.
+
+
+PhoneGeneric:
+
+This now contains one handy helper function which serves only to call
+SM_WaitFor, then SM_Loop repeatedly until the state goes to AnswerReady,
+and then SM_GetAnswer.  This is just to save repeating code.
+
+
+-----------------------
+
+Note that this leaves the phone code very similar to the basic layout of
+eg fbus-6110.c but removes all the:
+
+static GSM_DateTime       *CurrentAlarm;
+static GSM_Error          CurrentAlarmError;
+
+,makes everything well orderd and splits up DispatchMessage into byte
+sized chunks!
+
+-----------------------
+
+
+
+Other Notes
+-----------
+
+Within a phone/*.c or link file the functions should be made static.  It
+is therefore not necessary to use prefixes such as FB61_ but this may help
+code legibility to distiguish the major functions.
+
+
+-- 
+$Id$
+Chris Kemp
+Pawel Kot
diff --git a/Docs/sample/magic b/Docs/sample/magic
new file mode 100644 (file)
index 0000000..d1822a4
--- /dev/null
@@ -0,0 +1,14 @@
+# Add these to magic file (located in /etc or /usr/share/misc)
+# to let the file command recognize NOL and NGG files
+#
+# Pawe³ Kot <pkot@linuxnews.pl>
+# Based on the gnokii (http://www.gnokii.org/) sources
+
+# GSM Operator Logos - NOL
+0       string  NOL     GSM Operator Logo, NOL format
+>10     byte    x       (size %d x
+>12     byte    x       %d)
+# GSM Caller Icons - NGG
+0      string  NGG     GSM Caller Icon, NGG format
+>6     byte    x       (size %d x
+>8     byte    x       %d)
diff --git a/common/links/fbus-3110.c b/common/links/fbus-3110.c
new file mode 100644 (file)
index 0000000..5d8af0e
--- /dev/null
@@ -0,0 +1,396 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for Nokia mobile phones.
+
+  Copyright (C) 2000 Hugh Blemings & Pavel Janík ml.
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides an API for accessing functions via fbus. 
+  See README for more details on supported mobile phones.
+
+  The various routines are called FBUS_(whatever).
+
+  $Log$
+  Revision 1.1.1.2  2001/11/27 22:01:16  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 22:58 CET 2001
+
+  Revision 1.3  2001/11/27 12:19:01  pkot
+  Cleanup, indentation, ANSI complaint preprocesor symbols (Jan Kratochvil, me)
+
+  Revision 1.2  2001/11/09 14:25:04  pkot
+  DEBUG cleanups
+
+  Revision 1.1  2001/11/09 12:55:07  pkot
+  Forgot about fbus support for 3110. FIXME: is it really needed?
+
+
+*/
+
+/* System header files */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* Various header file */
+
+#include "config.h"
+#include "misc.h"
+#include "gsm-common.h"
+#include "gsm-ringtones.h"
+#include "gsm-networks.h"
+#include "gsm-statemachine.h"
+#include "links/utils.h"
+
+#ifndef WIN32
+#  include "device.h"
+#else
+#  include "win32/winserial.h"
+#  define device_write(a, b) WriteCommBlock(a, b)
+#  define device_read(a, b) ReadCommBlock(a, b)
+#  define sleep(x) Sleep((x) * 1000)
+#  define usleep(x) Sleep(((x) < 1000) ? 1 : ((x) / 1000))
+#endif
+
+#define __links_fbus_3110_c
+#include "links/fbus-3110.h"
+
+/* FIXME - pass device_* the link stuff?? */
+/* FIXME - win32 stuff! */
+
+
+/* Some globals */
+
+static GSM_Link *glink;
+static GSM_Statemachine *statemachine;
+static FB3110_Link flink;              /* FBUS specific stuff, internal to this file */
+
+
+/*--------------------------------------------*/
+
+bool FB3110_OpenSerial(void)
+{
+       /* Open device. */
+#ifdef WIN32
+       if (OpenConnection(glink->PortDevice, FB3110_RX_StateMachine, NULL)) {
+#else
+       if (!device_open(glink->PortDevice, false, false, false, GCT_Serial)) {
+#endif
+               perror(_("Couldn't open FBUS device"));
+               return false;
+       }
+       device_changespeed(115200);
+
+       return (true);
+}
+
+
+/* RX_State machine for receive handling.  Called once for each character
+   received from the phone. */
+
+void FB3110_RX_StateMachine(unsigned char rx_byte)
+{
+       FB3110_IncomingFrame *i = &flink.i;
+       int count;
+
+       switch (i->State) {
+
+               /* Phone is currently off.  Wait for 0x55 before
+                  restarting */
+        case FB3110_RX_Discarding:
+                if (rx_byte != 0x55)
+                       break;
+
+                /* Seen 0x55, restart at 0x04 */
+                i->State = FB3110_RX_Sync;
+
+               dprintf("restarting.\n");
+
+                /* FALLTHROUGH */
+
+               /* Messages from the phone start with an 0x04 during
+                  "normal" operation, 0x03 when in data/fax mode.  We
+                  use this to "synchronise" with the incoming data
+                  stream. */
+       case FB3110_RX_Sync:
+               if (rx_byte == 0x04 || rx_byte == 0x03) {
+                       i->FrameType = rx_byte;
+                       i->Checksum = rx_byte;
+                       i->State = FB3110_RX_GetLength;
+               }
+               break;
+
+               /* Next byte is the length of the message including
+                  the message type byte but not including the checksum. */
+        case FB3110_RX_GetLength:
+               i->FrameLength = rx_byte;
+               i->BufferCount = 0;
+               i->Checksum ^= rx_byte;
+                i->State = FB3110_RX_GetMessage;
+                break;
+
+               /* Get each byte of the message.  We deliberately
+                  get one too many bytes so we get the checksum
+                  here as well. */
+       case FB3110_RX_GetMessage:
+               i->Buffer[i->BufferCount] = rx_byte;
+               i->BufferCount++;
+
+               if (i->BufferCount > FB3110_MAX_FRAME_LENGTH) {
+                       dprintf("FBUS: Message buffer overun - resetting\n");
+                       i->State = FB3110_RX_Sync;
+                       break;
+               }
+
+               /* If this is the last byte, it's the checksum. */
+               if (i->BufferCount > i->FrameLength) {
+
+                       /* Is the checksum correct? */
+                       if (rx_byte == i->Checksum) {
+
+                               if (i->FrameType == 0x03) {
+                                       /* FIXME: modify Buffer[0] to code FAX frame types */
+                               }
+
+                               dprintf("--> %02x:%02x:", i->FrameType, i->FrameLength);
+                               for (count = 0; count < i->BufferCount; count++)
+                                       dprintf("%02hhx:", i->Buffer[count]);
+                               dprintf("\n");
+                               /* Transfer message to state machine */
+                               SM_IncomingFunction(statemachine, i->Buffer[0], i->Buffer, i->FrameLength);
+
+                               /* Send an ack */
+                               FB3110_TX_SendAck(i->Buffer, i->FrameLength);
+
+                       } else {
+                               /* Checksum didn't match so ignore. */
+                               dprintf("Bad checksum!\n");
+                       }
+                       i->State = FB3110_RX_Sync;
+               }
+               i->Checksum ^= rx_byte;
+               break;
+       }
+}
+
+
+/* This is the main loop function which must be called regularly */
+/* timeout can be used to make it 'busy' or not */
+
+GSM_Error FB3110_Loop(struct timeval *timeout)
+{
+#ifndef WIN32
+       unsigned char buffer[255];
+       int count, res;
+
+       res = device_select(timeout);
+       if (res > 0) {
+               res = device_read(buffer, 255);
+               for (count = 0; count < res; count++)
+                       FB3110_RX_StateMachine(buffer[count]);
+       } else
+               return GE_TIMEOUT;
+
+       /* This traps errors from device_read */
+       if (res > 0)
+               return GE_NONE;
+       else
+               return GE_INTERNALERROR;
+#else
+       return GE_NONE;
+#endif
+}
+
+
+
+/* Prepares the message header and sends it, prepends the
+   message start byte (0x01) and other values according
+   the value specified when called.  Calculates checksum
+   and then sends the lot down the pipe... */
+
+GSM_Error FB3110_TX_SendFrame(u8 message_length, u8 message_type, u8 sequence_byte, u8 * buffer)
+{
+
+       u8 out_buffer[FB3110_MAX_TRANSMIT_LENGTH];
+       int count, current = 0;
+       unsigned char checksum;
+
+        /* Check message isn't too long, once the necessary
+           header and trailer bytes are included. */
+       if ((message_length + 5) > FB3110_MAX_TRANSMIT_LENGTH) {
+               fprintf(stderr, _("FB3110_TX_SendFrame - message too long!\n"));
+               return (GE_INTERNALERROR);
+       }
+
+       /* Now construct the message header. */
+       out_buffer[current++] = FB3110_FRAME_ID;    /* Start of frame */
+       out_buffer[current++] = message_length + 2; /* Length */
+       out_buffer[current++] = message_type;       /* Type */
+       out_buffer[current++] = sequence_byte;      /* Sequence number */
+
+       /* Copy in data if any. */
+       if (message_length != 0) {
+               memcpy(out_buffer + current, buffer, message_length);
+               current += message_length;
+       }
+
+        /* Now calculate checksum over entire message 
+           and append to message. */
+       checksum = 0;
+       for (count = 0; count < current; count++)
+               checksum ^= out_buffer[count];
+       out_buffer[current++] = checksum;
+
+       dprintf("<-- ");
+       for (count = 0; count < current; count++)
+               dprintf("%02hhx:", out_buffer[count]);
+       dprintf("\n");
+
+       /* Send it out... */
+       if (device_write(out_buffer, current) != current)
+               return (GE_INTERNALERROR);
+
+       return (GE_NONE);
+}
+
+
+/* Main function to send an fbus message */
+
+GSM_Error FB3110_SendMessage(u16 messagesize, u8 messagetype, void *message)
+{
+       u8 seqnum;
+
+       FB3110_UpdateSequenceNumber();
+       seqnum = flink.RequestSequenceNumber;
+
+       return FB3110_TX_SendFrame(messagesize, messagetype, seqnum, message);
+}
+
+
+/* Sends the "standard" acknowledge message back to the phone in
+   response to a message it sent automatically or in response to
+   a command sent to it.  The ack. algorithm isn't 100% understood
+   at this time. */
+
+void FB3110_TX_SendAck(u8 *message, int length)
+{
+       u8 t = message[0];
+
+       switch (t) {
+       case 0x0a:
+               /* We send 0x0a messages to make a call so don't ack. */
+       case 0x0c:
+               /* We send 0x0c message to answer to incoming call 
+                  so don't ack */
+       case 0x0f:
+               /* We send 0x0f message to hang up so don't ack */
+       case 0x15:
+               /* 0x15 messages are sent by the phone in response to the
+                  init sequence sent so we don't acknowledge them! */
+       case 0x20:
+               /* We send 0x20 message to phone to send DTFM, so don't ack */
+       case 0x23:
+               /* We send 0x23 messages to phone as a header for outgoing SMS
+                  messages.  So we don't acknowledge it. */
+       case 0x24:
+               /* We send 0x24 messages to phone as a header for storing SMS
+                  messages in memory. So we don't acknowledge it. :) */
+       case 0x25:
+               /* We send 0x25 messages to phone to request an SMS message
+                  be dumped.  Thus we don't acknowledge it. */
+       case 0x26:
+               /* We send 0x26 messages to phone to delete an SMS message
+                  so it's not acknowledged. */
+       case 0x3f:
+               /* We send an 0x3f message to the phone to request a different
+                  type of status dump - this one seemingly concerned with 
+                  SMS message center details.  Phone responds with an ack to
+                  our 0x3f request then sends an 0x41 message that has the
+                  actual data in it. */
+       case 0x4a:
+               /* 0x4a message is a response to our 0x4a request, assumed to
+                  be a keepalive message of sorts.  No response required. */
+       case 0x4c:
+               /* We send 0x4c to request IMEI, Revision and Model info. */
+               break;
+       case 0x27:
+               /* 0x27 messages are a little different in that both ends of
+                  the link send them.  So, first we have to check if this
+                  is an acknowledgement or a message to be acknowledged */
+               if (length == 0x02) break;
+       default:
+               /* Standard acknowledge seems to be to return an empty message
+                  with the sequence number set to equal the sequence number
+                  sent minus 0x08. */
+               if (FB3110_TX_SendFrame(0, t, (message[1] & 0x1f) - 0x08, NULL) != GE_NONE)
+                       dprintf("Failed to acknowledge message type %02x.\n", t);
+               else
+                       dprintf("Acknowledged message type %02x.\n", t);
+       }
+}
+
+
+/* Initialise variables and start the link */
+/* newlink is actually part of state - but the link code should not anything about state */
+/* state is only passed around to allow for muliple state machines (one day...) */
+
+GSM_Error FB3110_Initialise(GSM_Link *newlink, GSM_Statemachine *state)
+{
+       unsigned char init_char = 0x55;
+       unsigned char count;
+       static int try = 0;
+
+       try++;
+       if (try > 2) return GE_DEVICEOPENFAILED;
+       /* 'Copy in' the global structures */
+       glink = newlink;
+       statemachine = state;
+
+       /* Fill in the link functions */
+       glink->Loop = &FB3110_Loop;
+       glink->SendMessage = &FB3110_SendMessage;
+
+       /* Check for a valid init length */
+       if (glink->InitLength == 0)
+               glink->InitLength = 100;
+
+       /* Start up the link */
+
+       flink.RequestSequenceNumber = 0x10;
+
+       if (!FB3110_OpenSerial()) return GE_DEVICEOPENFAILED;
+
+       /* Send init string to phone, this is a bunch of 0x55 characters. 
+          Timing is empirical. I believe that we need/can do this for any 
+          phone to get the UART synced */
+       for (count = 0; count < glink->InitLength; count++) {
+               usleep(1000);
+               device_write(&init_char, 1);
+       }
+
+       /* Init variables */
+       flink.i.State = FB3110_RX_Sync;
+
+       return GE_NONE;
+}
+
+
+/* Any command we originate must have a unique SequenceNumber.
+   Observation to date suggests that these values startx at 0x10
+   and cycle up to 0x17 before repeating again.  Perhaps more
+   accurately, the numbers cycle 0,1,2,3..7 with bit 4 of the byte
+   premanently set. */
+
+void FB3110_UpdateSequenceNumber(void)
+{
+    flink.RequestSequenceNumber++;
+
+    if (flink.RequestSequenceNumber > 0x17 || flink.RequestSequenceNumber < 0x10) {
+        flink.RequestSequenceNumber = 0x10;
+    }
+}
diff --git a/common/phones/ateric.c b/common/phones/ateric.c
new file mode 100644 (file)
index 0000000..edd48c7
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides functions specific to at commands on ericsson
+  phones. See README for more details on supported mobile phones.
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:14  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/19 13:03:18  pkot
+  nk3110.c cleanup
+
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "misc.h"
+#include "gsm-common.h"
+#include "gsm-statemachine.h"
+#include "phones/generic.h"
+#include "phones/atgen.h"
+#include "phones/ateric.h"
+#include "links/atbus.h"
+#include "links/cbus.h"
+
+
+static GSM_Error GetMemoryStatus(GSM_Data *data,  GSM_Statemachine *state)
+{
+        char req[128];
+        GSM_Error ret;
+        ret = AT_SetMemoryType(data->MemoryStatus->MemoryType,  state);
+        if (ret != GE_NONE)
+                return ret;
+        sprintf(req, "AT+CPBR=?\r\n");
+        if (SM_SendMessage(state, 11, GOP_GetMemoryStatus, req) != GE_NONE)
+                return GE_NOTREADY;
+        ret = SM_Block(state, data, GOP_GetMemoryStatus);
+        return ret;
+}
+
+
+static GSM_Error ReplyMemoryStatus(int messagetype, unsigned char *buffer, int length, GSM_Data *data)
+{
+       AT_LineBuffer buf;
+        char *pos;
+       buf.line1 = buffer;
+       buf.length= length;
+       splitlines(&buf);
+       if (buf.line1 == NULL)
+                return GE_INVALIDMEMORYTYPE;
+        if (data->MemoryStatus) {
+                if (strstr(buf.line2,"+CPBR")) {
+                        pos = strchr(buf.line2, '-');
+                        if (pos) {
+                                data->MemoryStatus->Used = atoi(++pos);
+                                data->MemoryStatus->Free = 0;
+                        } else {
+                                return GE_NOTSUPPORTED;
+                        }
+                }
+        }
+        return GE_NONE;
+} 
+
+
+void AT_InitEricsson(GSM_Statemachine *state, char *foundmodel, char *setupmodel) {
+       AT_InsertRecvFunction(GOP_GetMemoryStatus, ReplyMemoryStatus);
+       AT_InsertSendFunction(GOP_GetMemoryStatus, GetMemoryStatus);
+}
diff --git a/common/phones/atnok.c b/common/phones/atnok.c
new file mode 100644 (file)
index 0000000..150d89a
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides functions specific to at commands on nokia
+  phones. See README for more details on supported mobile phones.
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:14  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/19 13:03:18  pkot
+  nk3110.c cleanup
+
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "misc.h"
+#include "gsm-common.h"
+#include "gsm-statemachine.h"
+#include "phones/generic.h"
+#include "phones/atgen.h"
+#include "phones/atnok.h"
+#include "links/atbus.h"
+#include "links/cbus.h"
+
+
+AT_SendFunctionType writephonebook;
+
+
+static GSM_Error WritePhonebook(GSM_Data *data,  GSM_Statemachine *state)
+{
+       if (writephonebook == NULL)
+               return GE_UNKNOWN;
+       if (data->MemoryStatus->MemoryType == GMT_ME)
+               return GE_NOTSUPPORTED;
+       return (*writephonebook)(data, state);
+}
+
+
+void AT_InitNokia(GSM_Statemachine *state, char *foundmodel, char *setupmodel) {
+       /* block writing of phone memory on nokia phones other than */
+       /* 8210. if you write to the phonebook of a eg 7110 all extended */
+       /* information will be lost. */
+       if (strncasecmp("8210", foundmodel, 4))
+               writephonebook = AT_InsertSendFunction(GOP_WritePhonebook,  WritePhonebook);
+}
diff --git a/common/phones/atsie.c b/common/phones/atsie.c
new file mode 100644 (file)
index 0000000..9694b23
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides functions specific to at commands on siemens
+  phones. See README for more details on supported mobile phones.
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:14  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/19 13:03:18  pkot
+  nk3110.c cleanup
+
+*/
+
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include "misc.h"
+#include "gsm-common.h"
+#include "gsm-statemachine.h"
+#include "phones/generic.h"
+#include "phones/atgen.h"
+#include "phones/atsie.h"
+#include "links/atbus.h"
+#include "links/cbus.h"
+
+
+AT_SendFunctionType writephonebook;
+
+
+static GSM_Error WritePhonebook(GSM_Data *data,  GSM_Statemachine *state)
+{
+       GSM_PhonebookEntry newphone;
+       char *rptr, *wptr;
+
+       if (writephonebook == NULL)
+               return GE_UNKNOWN;
+       if (data->PhonebookEntry != NULL) {
+               memcpy(&newphone, data->PhonebookEntry, sizeof(GSM_PhonebookEntry));
+               rptr = data->PhonebookEntry->Name;
+               wptr = newphone.Name;
+               data->PhonebookEntry = &newphone;
+       }
+       return (*writephonebook)(data, state);
+}
+
+
+void AT_InitSiemens(GSM_Statemachine *state, char *foundmodel, char *setupmodel) {
+       /* names for s35 etc must be escaped */
+/*
+       if (foundmodel && !strncasecmp("35", foundmodel + 1, 2))
+               writephonebook = AT_InsertSendFunction(GOP_WritePhonebook, WritePhonebook);
+*/
+}
diff --git a/include/links/fbus-3110.h b/include/links/fbus-3110.h
new file mode 100644 (file)
index 0000000..a0dcdcc
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for Nokia mobile phones.
+
+  Copyright (C) 2000 Hugh Blemings & Pavel Janík ml.
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides an API for accessing functions via fbus. 
+  See README for more details on supported mobile phones.
+
+  The various routines are called FB3110_(whatever).
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:22  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/09 12:55:07  pkot
+  Forgot about fbus support for 3110. FIXME: is it really needed?
+
+
+*/
+
+#ifndef __links_fbus_3110_h
+#define __links_fbus_3110_h
+
+#include <time.h>
+#include "gsm-statemachine.h"
+
+#ifdef WIN32
+#include <sys/types.h>
+#include <sys/timeb.h>
+#endif
+
+#define FB3110_MAX_FRAME_LENGTH 256
+#define FB3110_MAX_MESSAGE_TYPES 128
+#define FB3110_MAX_TRANSMIT_LENGTH 256
+#define FB3110_MAX_CONTENT_LENGTH 120
+
+/* This byte is at the beginning of all GSM Frames sent over FBUS to Nokia
+   phones.  This may have to become a phone dependant parameter... */
+#define FB3110_FRAME_ID 0x01
+
+
+/* States for receive code. */
+
+enum FB3110_RX_States {
+       FB3110_RX_Sync,
+       FB3110_RX_Discarding,
+       FB3110_RX_GetLength,
+       FB3110_RX_GetMessage
+};
+
+
+typedef struct{
+       int Checksum;
+       int BufferCount;
+       enum FB3110_RX_States State;
+       int FrameType;
+       int FrameLength;
+       char Buffer[FB3110_MAX_FRAME_LENGTH];
+} FB3110_IncomingFrame;
+
+typedef struct {
+       u16 message_length;
+       u8 message_type;
+       u8 *buffer;
+} FB3110_OutgoingMessage;
+
+
+typedef struct{
+       FB3110_IncomingFrame i;
+       u8 RequestSequenceNumber;
+} FB3110_Link;
+
+GSM_Error FB3110_Initialise(GSM_Link *newlink, GSM_Statemachine *state);
+
+
+
+#ifdef __links_fbus_3110_c  /* Prototype functions for fbus-generic.c only */
+
+bool FB3110_OpenSerial(void);
+void FB3110_RX_StateMachine(unsigned char rx_byte);
+GSM_Error FB3110_TX_SendFrame(u8 message_length, u8 message_type, u8 sequence_byte, u8 *buffer);
+GSM_Error FB3110_SendMessage(u16 messagesize, u8 messagetype, void *message);
+void FB3110_TX_SendAck(u8 *message, int length);
+void FB3110_UpdateSequenceNumber(void);
+
+#endif   /* #ifdef __links_fbus_3110_c */
+
+#endif   /* #ifndef __links_fbus_3110_h */
diff --git a/include/phones/ateric.h b/include/phones/ateric.h
new file mode 100644 (file)
index 0000000..112d54b
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides functions specific to at commands on ericsson
+  phones. See README for more details on supported mobile phones.
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:22  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/19 13:03:18  pkot
+  nk3110.c cleanup
+
+*/
+
+void AT_InitEricsson(GSM_Statemachine *state, char* foundmodel, char* setupmodel);
diff --git a/include/phones/atgen.h b/include/phones/atgen.h
new file mode 100644 (file)
index 0000000..aeb7863
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides functions specific to generic at command compatible
+  phones. See README for more details on supported mobile phones.
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:22  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/19 13:03:18  pkot
+  nk3110.c cleanup
+
+
+*/
+
+typedef GSM_Error (*GSM_RecvFunctionType)(int type, unsigned char *buffer, int length, GSM_Data *data);
+typedef GSM_Error (*AT_SendFunctionType)(GSM_Data *data, GSM_Statemachine *s);
+
+typedef struct {
+        char *line1;
+        char *line2;
+        char *line3;
+        int length;
+} AT_LineBuffer;
+
+GSM_RecvFunctionType AT_InsertRecvFunction(int type, GSM_RecvFunctionType func);
+AT_SendFunctionType AT_InsertSendFunction(int type, AT_SendFunctionType func);
+
+GSM_Error AT_SetMemoryType(GSM_MemoryType mt, GSM_Statemachine *state);
+
+void splitlines(AT_LineBuffer *buf);
+
+char *skipcrlf(char *str);
+char *findcrlf(char *str, int test, int maxlength);
+
diff --git a/include/phones/atnok.h b/include/phones/atnok.h
new file mode 100644 (file)
index 0000000..09aba82
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides functions specific to at commands on nokia
+  phones. See README for more details on supported mobile phones.
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:22  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/19 13:03:18  pkot
+  nk3110.c cleanup
+
+*/
+
+void AT_InitNokia(GSM_Statemachine *state, char* foundmodel, char* setupmodel);
diff --git a/include/phones/atsie.h b/include/phones/atsie.h
new file mode 100644 (file)
index 0000000..96245f2
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+
+  $Id$
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for mobile phones.
+
+  Copyright 2001 Manfred Jonsson <manfred.jonsson@gmx.de>
+
+  Released under the terms of the GNU GPL, see file COPYING for more details.
+
+  This file provides functions specific to at commands on siemens
+  phones. See README for more details on supported mobile phones.
+
+  $Log$
+  Revision 1.1.1.1  2001/11/25 21:59:22  short
+  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
+
+  Revision 1.1  2001/11/19 13:03:18  pkot
+  nk3110.c cleanup
+
+*/
+
+void AT_InitSiemens(GSM_Statemachine *state, char* foundmodel, char* setupmodel);
diff --git a/utils/sendsms b/utils/sendsms
new file mode 100644 (file)
index 0000000..d38dc95
--- /dev/null
@@ -0,0 +1,458 @@
+#!/bin/bash 
+###############################################################################
+#
+#      SENDSMS   --  Script to send sms by 'gnokii'
+#   Author : Gabriele Zappi - Rimini <gzappi@inwind.it>
+#      History:
+#        feb 17, 2001         Script created (v1.0)
+###############################################################################
+# $Id$
+###############################################################################
+###############################################################################
+# PROGNAME=`basename $0`
+
+# var settings.
+
+PROGNAME=${0##*/}
+VERSION="1.02"
+GNOKII=gnokii
+PID=$$
+SMSDIR=~/tmp/sms
+TMP=~/tmp/SMStmp.$PID
+BACKTITLE="SENDSMS V$VERSION"
+AUTHOR="Gabriele Zappi - Rimini <gzappi@inwind.it>"
+
+help() {
+echo "$PROGNAME: $BACKTITLE - A gnokii interface for sending SMS."
+echo "Written by $AUTHOR"
+
+echo -e "\
+\n\
+Usage: $PROGNAME [OPTION]...\n\
+\n\
+Examples:\n\
+  $PROGNAME                 # simply run $PROGNAME in standard mode\n\
+  $PROGNAME --simulate      # Simulates. doesn't really send sms (for debug)\n\
+  echo \"Hello Beauty ;-)\" | $PROGNAME --smsset\n\
+                          # Preset \"Hello Beauty ;-)\" as SMS message.\n\
+  $PROGNAME --smsset < mymessage.txt\n\
+                          # Preset contents of file mymessage.txt \n\
+                            as SMS message.\n\
+  $PROGNAME --version       # Display version, author and quits.\n\
+\n\
+NOTE:\n\
+If you require to pickup number from phone's memory (really from SIM card),\n\
+for the first time, it anyway reads phonebook from your cellular phone. \n\
+(It may take a while... please, be patient ;-) \n\
+\n\
+Available options:\n\
+  --debug, -D            May bother with more debugging messages ;-)\n\
+                         For debugging purpose.\n\
+  --simul[ate], -S       Simulation mode. Doesn't really send SMS by phone. \n\
+                         Only simulates. For debugging purpose.\n\
+  --forcememread, -F     Forces $PROGNAME to read phonebook from SIM card,\n\
+                         and to parse the generated file in order to update\n\
+                         the numbers' list (useful only if required to pickup\n\
+                         number from the phone's memory). see NOTE.\n\
+  --skipgnokiicheck, -K  Skip the test of the presence of binary 'gnokii'.\n\
+                         (It must be somewhere in your \$PATH). It allows you\n\
+                         to try this script program, even if you don't have\n\
+                         'gnokii' already. ;)\n\
+  --smsset, --setsms     Allows you to preset a SMS message from STDIN. (pipe\n\
+                         or input redirection).\n\
+                         This message will be proposed on the 'SMS message'\n\
+                         field during the program input cycle.\n\
+  --help, -h, /h         display this help and exit\n\
+  --version, -V          output version information and exit"
+echo 
+exit 0
+}
+
+acex()
+{
+       rm -rf $TMP >/dev/null 2>&1
+       clear
+       exit $1
+}
+
+parse_stdin() {
+       # Switch initialization
+       SW_DEBUG=no
+       SW_SIMUL=no
+       SW_FORCEMREAD=no
+       SW_SKIPGNOKITST=no
+       SW_PRESETSMS=no
+       PRESETSMS=""
+
+       while [ -n "$1" ] 
+       do
+               case "$1" in 
+                       --help|-h|/h)
+                                       help
+                                       ;;
+                       --version|-V)
+                                       echo
+                                       echo "$BACKTITLE - A gnokii interface for sending SMS."
+                                       echo "Written by $AUTHOR"
+                                       echo
+                                       exit 0
+                                       ;;
+                       --simul*|-S)
+                                       SW_SIMUL=yes
+                                       ;;
+                       --debug*|-D)
+                                       SW_DEBUG=yes
+                                       SW_SIMUL=yes
+                                       ;;
+                       --forcememread|-F)
+                                       SW_FORCEMREAD=yes
+                                       ;;
+                       --skipgnokiicheck|-K)
+                                       SW_SKIPGNOKITST=yes
+                                       ;;
+                       --smsset|--msgset|--setsms)
+                                       SW_PRESETSMS=yes
+                                       # will read from stdin
+                                       echo "reading sms from stdin .."
+                                       PRESETSMS=`cat`
+                                       ;;
+                       *)
+                                       echo "$PROGNAME: Invalid parameter: "
+                                       help
+                                       ;;
+               esac
+               shift
+       done
+}
+
+sure_to_quit() {
+ dialog --backtitle "$BACKTITLE" \
+                                                                                       --yesno "Really sure to quit? " 6 50
+ if [ $? -eq 0 ]; then
+ acex 0
+ fi
+}
+
+SMS_phoneread() {
+dialog --backtitle "$BACKTITLE" --infobox "Reading phonebook by phone's SIM\n         Please wait" 4 40 
+$GNOKII --getmemory SM 1 130 > $SMSDIR/.SMlist.temp
+}
+
+SMS_choicefrommem() {
+       # read from phonebook.
+       if [ "$SW_FORCEMREAD" = "yes" ] ; then
+               readsim=1
+       elif [ -s $SMSDIR/.SMlist.sim ]; then
+               dialog --backtitle "INSERT NUMBER(s).." \
+                                        --yesno "A SIM phonebook file is already present. \
+                    Do you want to read phone memory anyway?" 8 60
+               if [ $? -eq 0 ] ; then
+                       readsim=1
+               else
+                       readsim=0
+               fi
+       else
+               readsim=1
+       fi
+
+       ERROR=0
+       if [ $readsim -eq 1 ] ; then
+               SMS_phoneread
+               if [ $? -ne 0 ] ; then
+                       dialog --backtitle "INSERT NUMBER(s).." \
+                                                --msgbox "ERROR during reading memory from your phone... \
+                       Insert manually destination number." 8 60
+                       ERROR=1
+               else
+                       mv -f $SMSDIR/.SMlist.temp $SMSDIR/.SMlist.sim
+               fi
+       fi
+
+       if [ $ERROR -eq 0 ]; then
+               # Parsing sim file...
+               if [ ! -s $SMSDIR/.SMlist.chklst -o ! -s $SMSDIR/.SMlist.choice \
+                                       -o $readsim -eq 1 ] ; then
+                       > $SMSDIR/.SMlist.menu
+                       > $SMSDIR/.SMlist.chklst
+                       > $SMSDIR/.SMlist.choice
+                       totrows=`cat $SMSDIR/.SMlist.sim | wc -l`
+                       rownow=0
+                       (while read riga
+                       do
+                               rownow=`expr $rownow + 1`
+                               perc=`expr $rownow \* 100 / $totrows`
+                               pos=`echo $riga | cut -f4 -d";"`
+                               name=`echo $riga | cut -f1 -d";"`
+                               num=`echo $riga | cut -f2 -d";"`
+                               if [ -n "$pos" -a -n "$num" ] ; then
+                                       echo -e "$pos \"$name - $num\"" >> $SMSDIR/.SMlist.menu
+                                       echo -e "$pos \"$name - $num\" off" >> $SMSDIR/.SMlist.chklst
+                                       echo "$pos;$num" >> $SMSDIR/.SMlist.choice
+                               fi
+                               echo $perc
+                       done < $SMSDIR/.SMlist.sim) | dialog \
+                                                                                                       --gauge "Parsing phonebook file..." 12 70 0
+               fi
+
+               chkok=0
+               option=0
+               while [ $chkok -eq 0 ]
+               do
+                       eval dialog --backtitle \"SENDSM CKECKLIST\" \
+                                                                       --checklist \"Check your MEMORY number\(s\).\
+                              \\nPress ESC key \for options..... \" \
+                                                                       16 60 9 \
+                                                                       `cat $SMSDIR/.SMlist.chklst` 2> $TMP/rspTEMP02
+                       option=$?
+                       if [ $option -eq 255 ] ; then
+                               dialog --backtitle "SENDSM CKECKLIST" --menu \
+                                               "Options sub-menus for Phonebook choise list:" \
+                                               10 50 4 \
+                                               "1" "Sort by Memory Pos" \
+                                               "2" "Sort by Names" \
+                                               "9" "Quit $PROGNAME" 2> $TMP/rspTEMP04
+                               if [ $? -eq 0 ]; then
+                                       sorttype=`cat $TMP/rspTEMP04`
+                                       case $sorttype in
+                                               1) sort -n $SMSDIR/.SMlist.chklst > $TMP/.SMlist.tmp
+                                                        mv -f $TMP/.SMlist.tmp $SMSDIR/.SMlist.chklst
+                                                        ;;
+                                               2) sort +1 $SMSDIR/.SMlist.chklst > $TMP/.SMlist.tmp
+                                                        mv -f $TMP/.SMlist.tmp $SMSDIR/.SMlist.chklst
+                                                        ;;
+                                               9) sure_to_quit
+                                                        ;;
+                                       esac
+                               fi
+                       else
+                               chkok=1
+                       fi
+               done
+
+               if [ $? -eq 0 ] ; then
+                       for val in `cat $TMP/rspTEMP02`
+                       do
+                               tok1=`eval echo $val`
+                               tok2=`grep "^$tok1;" $SMSDIR/.SMlist.choice`
+                               tok3=`echo $tok2 | cut -f2 -d";"`
+                               if [ -z "$NUMBERS" ] ; then
+                                       NUMBERS="$tok3"
+                               else
+                                       NUMBERS="$NUMBERS $tok3"
+                               fi
+                       done
+               fi
+       fi
+}
+
+###########################################################################
+###########################################################################
+#                               MAIN PROCEDURE                            #
+###########################################################################
+###########################################################################
+
+parse_stdin $*
+
+# This is the 'help' test...
+# if [ "$1" = "--help" -o "$1" = "/h" ] ; then
+#      help
+# fi
+
+if ! type -all "dialog" >/dev/null 2>&1 ; then
+echo
+echo "${PROGNAME}: error:"
+echo "Can't find 'dialog', i can't run without 'dialog' on your system."
+echo "You can get a compiled elf version of 'dialog' from here."
+echo "http://www.tux.org/pub/people/kent-robotti/index.html"
+echo "ftp://ftp.tux.org/pub/people/kent-robotti 'dialog-0.9a-15.elf.tar.gz'"
+echo
+exit 1
+fi
+
+if [ $SW_SKIPGNOKITST = no ] ; then
+       if ! type -all "$GNOKII" >/dev/null 2>&1 ; then
+       echo
+       echo "${PROGNAME}: error:"
+       echo "Can't find 'gnokii'. This script needs 'gnokii' in order to work."
+       echo "You can get a version of 'gnokii' from following links:"
+       echo "GNOKII: http://multivac.fatburen.org/gnokii/ , http://www.gnokii.org/"
+       echo
+       echo " Pavel Janik (who is to thank for a vast part of the 6110 development) "
+       echo "also keeps an ftp archive of some recent things."
+       echo " "
+       echo "Source code and pre-compiled binaries for gnokii are available from "
+       echo "a number of sites"
+       echo
+       echo "ftp.gnokii.org located in California, USA"
+       echo "linuxcare.com.au located in Canberra, Australia"
+       echo "multivac.fatburen.org located in Stockholm, Sweden "
+       echo
+       echo "Pre release versions are kept here, maintained by Pawel Kot"
+       echo "urtica.linuxnews.pl located in Warsaw, Poland"
+       echo
+       echo "MYGNOKII (can handle other newer Nokia models...)"
+       echo "--------"
+       echo "Marcin Wiacek -> mailto:marcin-wiacek@topnet.pl"
+       echo "http://marcin-wiacek.topnet.pl (http://www.fkn.pl/marcinw) -> netmonitor,"
+       echo "firmware, mygnokii (GSM & Nokia)"
+       echo "http://grumble.zereau.com/gnokii/ &"
+       echo "http://www.mds.mdh.se/~cel95eig/mygnokii/ -> mygnokii mirrors"
+       echo
+       exit 1
+       fi
+fi
+
+if [ ! -d ~/tmp ]; then
+mkdir ~/tmp
+chmod 755 ~/tmp
+fi
+
+if [ ! -d $SMSDIR ]; then
+mkdir -p $SMSDIR
+chmod 755 $SMSDIR
+fi
+
+if [ -d $TMP ]; then
+       rm -rf $TMP
+fi
+mkdir -p $TMP
+chmod 700 $TMP
+
+
+echo "$BACKTITLE" > $TMP/txtTEMP01
+echo >> $TMP/txtTEMP01
+echo "Written by Gabriele Zappi <gzappi@inwind.it> " >> $TMP/txtTEMP01
+echo >> $TMP/txtTEMP01
+echo "This script is a front-end to type SMS messages directly" >> $TMP/txtTEMP01
+echo "from your computer and send them using gnokii through" >> $TMP/txtTEMP01
+echo "your cellular phone connected to your computer." >> $TMP/txtTEMP01
+echo >> $TMP/txtTEMP01
+echo "Press [Enter] to continue with SENDSMS." >> $TMP/txtTEMP01
+
+dialog --backtitle "$BACKTITLE" --textbox "$TMP/txtTEMP01" 14 70 
+TURN=0
+
+while true
+do
+       echo "Please, enter in the box below, your SMS message." > $TMP/txtTEMP$$ 
+       echo "Remember that it cannot be longer than 160 chars." >> $TMP/txtTEMP$$ 
+       echo " " >> $TMP/txtTEMP$$ 
+       echo "Press [ESC] or [CANCEL] to quit the program. " >> $TMP/txtTEMP$$ 
+
+       len=999
+       if [ $TURN -eq 0 ]; then
+               if [ "$SW_PRESETSMS" = "yes" ]; then
+                       echo "$PRESETSMS" > $TMP/rspTEMP01
+               else
+                       > $TMP/rspTEMP01
+               fi
+       fi
+       while test "$len" -le 0 -o "$len" -gt 160
+       do
+               dialog --backtitle "INSERT SMS ....." \
+                                        --inputbox  "`cat $TMP/txtTEMP$$`" 10 70 "`cat $TMP/rspTEMP01`" \
+                                                                                                                                                                                                                       2> $TMP/rspTEMP01
+         if [ $? -ne 0 ] ; then
+                       sure_to_quit
+               fi
+               len=`cat $TMP/rspTEMP01 | wc -c `
+
+               if [ $len -le 0 -o $len -gt 160 ] ; then
+                       echo "Invalid SMS: It must be < 160 chars and > 0 long.." > $TMP/txtTEMP02
+                       dialog --textbox "$TMP/txtTEMP02" 6 70 
+               fi
+       done
+
+       NUMBERS=""
+       okcycle=0
+       while [ "$NUMBERS" = "" -o "$okcycle" -eq 0 ]
+       do
+               dialog --backtitle "INSERT NUMBER(s).." \
+                                        --yesno "would you like to pick up number(s) \
+                    from your phone memory" 8 60
+                                                                                                               
+
+               if [ $? -eq 0 ] ; then # Yes, gimme num from phonebook.
+                       SMS_choicefrommem
+               fi
+
+               # Manual telephone number completion or insertion.
+               echo "Please, insert/modify in the box below, the NUMBER(S)" > $TMP/txtTEMP$$ 
+               echo "where you want to send the message to. " >> $TMP/txtTEMP$$ 
+               echo "(Multiple numbers must be separated by a space.)  " >> $TMP/txtTEMP$$ 
+               echo "Press [ESC] or [CANCEL] to quit the program. " >> $TMP/txtTEMP$$ 
+               echo " " >> $TMP/txtTEMP$$ 
+               echo "OUTGOING MESSAGE: " >> $TMP/txtTEMP$$ 
+               echo -n "  "
+               cat $TMP/rspTEMP01 | cut -c1-60 >> $TMP/txtTEMP$$
+               cat $TMP/rspTEMP01 | cut -c61-120 >> $TMP/txtTEMP$$
+               cat $TMP/rspTEMP01 | cut -c121-160 >> $TMP/txtTEMP$$
+               
+               okcycle=1
+               dialog --backtitle "INSERT NUMBER(s).." \
+                                        --inputbox  "`cat $TMP/txtTEMP$$`" \
+                                        16 70 "$NUMBERS"  2> $TMP/rspTEMP03
+       
+         if [ $? -ne 0 ] ; then
+                       sure_to_quit
+                       okcycle=0
+               else
+                       NUMBERS=`cat $TMP/rspTEMP03`
+                       if [ "$NUMBERS" = "" ] ; then
+                               dialog --backtitle "INSERT NUMBER(s).." \
+                                                        --infobox "Number cannot be empty.\n     Try again.." 4 28 
+                               sleep 2
+                               okcycle=0
+                       fi
+               fi
+       done
+
+       # Last confirmation before sending messages....
+
+       okcycle=0
+       while [ $okcycle -eq 0 ]
+       do
+               echo "Ok. If you confirm the operation, the the SMS" > $TMP/txtTEMP$$ 
+               echo "is going to be sent to the selected number(s)." >> $TMP/txtTEMP$$ 
+               echo >> $TMP/txtTEMP$$ 
+               echo "Press [ESC] to quit the program. " >> $TMP/txtTEMP$$ 
+               echo "Press [CANCEL] to return to SMS input. "  >> $TMP/txtTEMP$$ 
+               dialog --backtitle "$BACKTITLE" \
+                                        --yesno "`cat $TMP/txtTEMP$$`" 9 60
+               case $? in
+                       0)
+                               okcycle=1;;
+                       1)
+                               TURN=`expr $TURN + 1`
+                               continue 2;;
+                       255)
+                               sure_to_quit ;;
+               esac                                                                            
+       done
+       TURN=`expr $TURN + 1`
+
+       for num in $NUMBERS
+       do
+               # echo "Sending sms to number $num ... "
+               dialog --backtitle "$BACKTITLE" --infobox "Sending sms to number $num ...\n         Please wait" 4 45
+               if [ "$SW_SIMUL" = "yes" ] ; then
+                       sleep 2
+               else
+                       $GNOKII --sendsms $num < $TMP/rspTEMP01 > /dev/null 2>&1
+               fi
+               if [ $? -eq 0 ] ; then
+                       dialog --backtitle "$BACKTITLE" \
+                       --infobox "Message correctly sent to number $num !" 3 55 
+               else
+                       dialog --backtitle "$BACKTITLE" \
+                       --infobox "Sent Failed to num $num! Sorry!" 3 55 
+               fi
+               sleep 2
+       done
+
+done
+
+
+acex 0
+# zap - fin qui
+