Update: orig2001_12_04_22_45 -> orig2001_12_14_20_46
[gnokii.git] / gnokii / gnokii.c
index d24ca58..120a83f 100644 (file)
   WARNING: this code is the test tool. Well, our test tool is now
   really powerful and useful :-)
 
-  $Log$
-  Revision 1.1.1.1.2.1  2001/11/27 22:48:37  short
-  Update: orig2001_11_27_05_17 -> orig2001_11_27_22_58
-
-  Revision 1.1.1.2  2001/11/27 22:01:25  short
-  :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 22:58 CET 2001
-
-  Revision 1.152  2001/11/27 12:23:11  pkot
-  Specifying SMSC number in --sendsms works again
-
-  Revision 1.151  2001/11/22 17:56:53  pkot
-  smslib update. sms sending
-
-  Revision 1.150  2001/11/20 16:22:22  pkot
-  First attempt to read Picture Messages. They should appear when you enable DEBUG. Nokia seems to break own standards. :/ (Markus Plail)
-
-  Revision 1.149  2001/11/19 16:00:15  pkot
-  Another typo
-
-  Revision 1.148  2001/11/19 13:46:43  pkot
-  reading unread SMS in 6210 from Inbox. Folder updates (Markus Plail)
-
-  Revision 1.147  2001/11/18 00:54:32  pkot
-  Bugfixes. I18n of the user responses. UDH support in libsms. Business Card UDH Type
-
-  Revision 1.146  2001/11/17 20:18:33  pkot
-  Added dau9p connection type for 6210/7110
-
-  Revision 1.145  2001/11/14 10:46:12  pkot
-  Small cleanup with __unices__
-
-  Revision 1.144  2001/11/08 16:34:19  pkot
-  Updates to work with new libsms
-
-  Revision 1.143  2001/09/14 13:30:07  pkot
-  Fixed bugs introduced during 0.3.3 merge
-
-  Revision 1.142  2001/09/14 13:02:03  pkot
-  Gnokii calendar changes from 0.3.3
-
-  Revision 1.141  2001/09/14 12:53:00  pkot
-  New preview logos.
-  Localization fixes.
-  Set valid operator on logos xgnokii screen.
-
-  Revision 1.140  2001/07/27 00:02:21  pkot
-  Generic AT support for the new structure (Manfred Jonsson)
-
-  Revision 1.139  2001/07/01 23:16:45  pkot
-  Fixed a typo in gnokii.c avoiding saving logo (Jan Havelka)
-
-  Revision 1.138  2001/06/28 00:28:45  pkot
-  Small docs updates (Pawel Kot)
-
-  Revision 1.137  2001/06/27 23:52:50  pkot
-  7110/6210 updates (Marian Jancar)
-
-  Revision 1.136  2001/06/10 23:49:49  pkot
-  Small fixes to hide compilation warnings and allow gnokii.c to compile
-
-  Revision 1.135  2001/06/10 11:42:26  machek
-  Cleanup: some formating, made Statemachine global, converted to new
-  structure w.r.t. SMS-es
-
-  Revision 1.134  2001/05/24 20:47:30  chris
-  More updating of 7110 code and some of xgnokii_lowlevel changed over.
-
-  Revision 1.133  2001/04/23 17:20:01  pkot
-  Added possibility for viewing logos (currently nol and ngg) on console (Bartek Klepacz)
-
-  Revision 1.132  2001/03/21 23:36:06  chris
-  Added the statemachine
-  This will break gnokii --identify and --monitor except for 6210/7110
-
-  Revision 1.131  2001/03/19 23:43:46  pkot
-  Solaris / BSD '#if defined' cleanup
-
-  Revision 1.130  2001/03/13 01:23:18  pkot
-  Windows updates (Manfred Jonsson)
-
-  Revision 1.129  2001/03/13 01:21:39  pkot
-  *BSD updates (Bert Driehuis)
-
-  Revision 1.128  2001/03/08 00:49:06  pkot
-  Fixed bug (introduced by me) in getmemory function. Now gnokii.c should compile
-
-  Revision 1.127  2001/03/08 00:18:13  pkot
-  Fixed writephonebook once again. Someone kick me please...
-
-  Revision 1.126  2001/03/07 21:46:12  pkot
-  Fixed writephonebook patch
-
-  Revision 1.125  2001/03/06 22:19:14  pkot
-  Cleanups and fixes in gnokii.c:
-   - reindenting
-   - fixed bug reported by Gabriele Zappi
-   - fixed small bugs introduced by Pavel Machek
-
-  Revision 1.124  2001/02/28 21:42:00  machek
-  Possibility to force overwrite in --getsms (-F). Possibility to get
-  multiple files (use --getsms -f xyzzy%d), cleanup.
-
-  Revision 1.123  2001/02/20 21:55:11  pkot
-  Small #include updates
-
-  Revision 1.122  2001/02/16 14:29:53  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.121  2001/02/06 21:15:35  chris
-  Preliminary irda support for 7110 etc.  Not well tested!
-
-  Revision 1.120  2001/02/06 08:13:32  pkot
-  One more include in gnokii.c needed
-
-  Revision 1.119  2001/02/05 12:29:37  pkot
-  Changes needed to let unicode work
-
-  Revision 1.118  2001/02/01 15:17:33  pkot
-  Fixed --identify and added Manfred's manufacturer patch
-
-  Revision 1.117  2001/01/31 23:45:27  pkot
-  --identify should work ok now
-
-  Revision 1.116  2001/01/24 20:19:55  machek
-  Do not retry identification, if it is not implemented, it is bad idea.
-
-  Revision 1.115  2001/01/22 01:25:10  hugh
-  Tweaks for 3810 series, datacalls seem to be broken so need to do
-  some more debugging...
-
-  Revision 1.114  2001/01/17 02:54:55  chris
-  More 7110 work.  Use with care! (eg it is not possible to delete phonebook entries)
-  I can now edit my phonebook in xgnokii but it is 'work in progress'.
-
-  Revision 1.113  2001/01/15 17:00:49  pkot
-  Initial keypress sequence support. Disable compilation warning
-
-  Revision 1.112  2001/01/12 14:09:13  pkot
-  More cleanups. This time mainly in the code.
-
-  Revision 1.111  2001/01/10 16:32:18  pkot
-  Documentation updates.
-  FreeBSD fix for 3810 code.
-  Added possibility for deleting SMS just after reading it in gnokii.
-  2110 code updates.
-  Many cleanups.
-
-  Revision 1.110  2001/01/08 15:11:37  pkot
-  Documentation updates.
-  Fixed some bugs and removed FIXMEs.
-  We need to move some stuff from configure.in to aclocal.m4
-
-  Revision 1.109  2000/12/29 15:39:07  pkot
-  Reverted a change in fbus-3810.c which broke compling with --enable-debug.
-  Small fixes in gnokii.c
-
-  Revision 1.108  2000/12/19 16:18:16  pkot
-  configure script updates and added shared function for configfile reading
-
-  
 */
 
 #include "misc.h"
@@ -301,29 +137,30 @@ char *GetProfileVibrationString(int code)
        }
 }
 
+void short_version(void)
+{
+       fprintf(stderr, _("GNOKII Version %s\n"), VERSION);
+}
+
 /* This function shows the copyright and some informations usefull for
    debugging. */
-
-int version(void)
+void version(void)
 {
-       fprintf(stdout, _("GNOKII Version %s\n"
-                         "Copyright (C) Hugh Blemings <hugh@blemings.org>, 1999, 2000\n"
+       fprintf(stderr, _("Copyright (C) Hugh Blemings <hugh@blemings.org>, 1999, 2000\n"
                          "Copyright (C) Pavel Janík ml. <Pavel.Janik@suse.cz>, 1999, 2000\n"
                          "Copyright (C) Pavel Machek <pavel@ucw.cz>, 2001\n"
                          "Copyright (C) Pawe³ Kot <pkot@linuxnews.pl>, 2001\n"
                          "gnokii is free software, covered by the GNU General Public License, and you are\n"
                          "welcome to change it and/or distribute copies of it under certain conditions.\n"
                          "There is absolutely no warranty for gnokii.  See GPL for details.\n"
-                         "Built %s %s for %s on %s \n"), VERSION, __TIME__, __DATE__, model, Port);
-       return 0;
+                         "Built %s %s for %s on %s \n"), __TIME__, __DATE__, model, Port);
 }
 
 /* The function usage is only informative - it prints this program's usage and
    command-line options. */
-
 int usage(void)
 {
-       fprintf(stdout, _("   usage: gnokii [--help|--monitor|--version]\n"
+       fprintf(stderr, _("   usage: gnokii [--help|--monitor|--version]\n"
                          "          gnokii --getmemory memory_type start [end]\n"
                          "          gnokii --writephonebook [-i]\n"
                          "          gnokii --getspeeddial number\n"
@@ -363,9 +200,14 @@ int usage(void)
                          "          gnokii --getprofile [number]\n"
                          "          gnokii --displayoutput\n"
                          "          gnokii --keysequence\n"
-               ));
+                         "          gnokii --divert {--op|-o} {register|enable|query|disable|erasure}\n"
+                         "                 {--type|-t} {all|busy|noans|outofreach|notavail}\n"
+                         "                 {--call|-c} {all|voice|fax|data}\n"
+                         "                 [{--timeout|-m} time_in_seconds]\n"
+                         "                 [{--number|-n} number]\n"
+                       ));
 #ifdef SECURITY
-       fprintf(stdout, _(
+       fprintf(stderr, _(
                "          gnokii --entersecuritycode PIN|PIN2|PUK|PUK2\n"
                "          gnokii --getsecuritycodestatus\n"
                ));
@@ -387,7 +229,7 @@ void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 
        GSM_DataClear(&data);
 
-       if (!strcasecmp(Connection, "dau9p"))    connection = GCT_DAU9P;
+       if (!strcasecmp(Connection, "dau9p"))    connection = GCT_DAU9P; /* Use only with 6210/7110 for faster connection with such cable */
        if (!strcasecmp(Connection, "infrared")) connection = GCT_Infrared;
        if (!strcasecmp(Connection, "irda"))     connection = GCT_Irda;
 
@@ -454,18 +296,18 @@ int main(int argc, char *argv[])
        static struct option long_options[] =
        {
                /* FIXME: these comments are nice, but they would be more usefull as docs for the user */
-               // Display usage.
+               /* Display usage. */
                { "help",               no_argument,       NULL, OPT_HELP },
 
-               // Display version and build information.
+               /* Display version and build information. */
                { "version",            no_argument,       NULL, OPT_VERSION },
 
-               // Monitor mode
+               /* Monitor mode */
                { "monitor",            no_argument,       NULL, OPT_MONITOR },
 
 #ifdef SECURITY
 
-               // Enter Security Code mode
+               /* Enter Security Code mode */
                { "entersecuritycode",  required_argument, NULL, OPT_ENTERSECURITYCODE },
 
                // Get Security Code status
@@ -568,7 +410,10 @@ int main(int argc, char *argv[])
 
                // Simulate pressing the keys
                { "keysequence",        no_argument,       NULL, OPT_KEYPRESS },
-    
+
+               /* Divert calls */
+               { "divert",             required_argument, NULL, OPT_DIVERT },
+
                // For development purposes: insert you function calls here
                { "foogle",             no_argument,       NULL, OPT_FOOGLE },
 
@@ -611,6 +456,7 @@ int main(int argc, char *argv[])
                { OPT_RESET,             0, 1, 0 },
                { OPT_GETPROFILE,        0, 1, 0 },
                { OPT_WRITEPHONEBOOK,    0, 1, 0 },
+               { OPT_DIVERT,            6, 10, 0 },
 
                { 0, 0, 0, 0 },
        };
@@ -628,22 +474,26 @@ int main(int argc, char *argv[])
                exit(-1);
        }
 
+       /* Introduce yourself */
+       short_version();
+
        /* Handle command line arguments. */
        c = getopt_long(argc, argv, "", long_options, NULL);
        if (c == -1)            /* No argument given - we should display usage. */
                usage();
 
        switch(c) {
-       // First, error conditions
+       /* First, error conditions */
        case '?':
        case ':':
                fprintf(stderr, _("Use '%s --help' for usage informations.\n"), argv[0]);
                exit(0);
-       // Then, options with no arguments
+       /* Then, options with no arguments */
        case OPT_HELP:
                usage();
        case OPT_VERSION:
-               return version();
+               version();
+               exit(0);
        }
        
        /* We have to build an array of the arguments which will be passed to the
@@ -695,7 +545,7 @@ int main(int argc, char *argv[])
                case OPT_WRITEPHONEBOOK:
                        rc = writephonebook(nargc, nargv);
                        break;
-               // Now, options with arguments
+               /* Now, options with arguments */
                case OPT_SETDATETIME:
                        rc = setdatetime(nargc, nargv);
                        break;
@@ -771,17 +621,20 @@ int main(int argc, char *argv[])
                case OPT_KEYPRESS:
                        rc = presskeysequence();
                        break;
-#ifndef WIN32
-               case OPT_FOOGLE:
-                       rc = foogle(nargv);
-                       break;
-#endif
                case OPT_SENDDTMF:
                        rc = senddtmf(optarg);
                        break;
                case OPT_RESET:
                        rc = reset(optarg);
                        break;
+               case OPT_DIVERT:
+                       rc = divert(argc, argv);
+                       break;
+#ifndef WIN32
+               case OPT_FOOGLE:
+                       rc = foogle(nargv);
+                       break;
+#endif
                default:
                        fprintf(stderr, _("Unknown option: %d\n"), c);
                        break;
@@ -836,6 +689,7 @@ int sendsms(int argc, char *argv[])
        SMS.Validity.VPF = SMS_RelativeFormat;
        SMS.Validity.u.Relative = 4320; /* 4320 minutes == 72 hours */
        SMS.UDH_No = 0;
+       SMS.Report = false;
 
        strcpy(SMS.RemoteNumber.number, argv[0]);
        if (SMS.RemoteNumber.number[0] == '+') SMS.RemoteNumber.type = SMS_International;
@@ -868,7 +722,7 @@ int sendsms(int argc, char *argv[])
                        }
                        break;
                case 'r': /* request for delivery report */
-                       SMS.Type = SMS_Delivery_Report;
+                       SMS.Report = true;
                        break;
                case 'C': /* class Message */
                        switch (*optarg) {
@@ -992,17 +846,17 @@ int savesms(int argc, char *argv[])
                                if (!strcmp(ans, _("yes"))) confirm = 1;
                                else if (!strcmp(ans, _("no"))) confirm = 0;
                        }  
-                       if (!confirm) { GSM->Terminate(); return 0; }
+                       if (!confirm) {
+                               if (GSM && GSM->Terminate) GSM->Terminate();
+                               return 0;
+                       }
                        else break;
                case GE_INVALIDSMSLOCATION:
                        fprintf(stderr, _("Invalid location\n"));
-                       GSM->Terminate();
+                       if (GSM && GSM->Terminate) GSM->Terminate();
                        return -1;
                default:
-/* FIXME: Remove this fprintf when the function is thoroughly tested */
-#ifdef DEBUG
-                       fprintf(stderr, _("Location %d empty. Saving\n"), SMS.Number);
-#endif
+                       dprintf("Location %d empty. Saving\n", SMS.Number);
                        break;
                }
        }
@@ -1031,7 +885,7 @@ int savesms(int argc, char *argv[])
                fprintf(stdout, _("Saving failed (error=%d)\n"), error);
        }
        sleep(10);
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -1044,7 +898,7 @@ int getsmsc(char *MessageCenterNumber)
        GSM_Error               error;
        
        memset(&MessageCenter, 0, sizeof(MessageCenter));
-       MessageCenter.No=atoi(MessageCenterNumber);
+       MessageCenter.No = atoi(MessageCenterNumber);
        
        if (GSM && GSM->GetSMSCenter && GSM->Terminate) {
                error = GSM->GetSMSCenter(&MessageCenter);
@@ -1171,7 +1025,7 @@ int getsms(int argc, char *argv[])
                                mode = 0;
                        case 'f':
                                if (optarg) {
-                                       dprintf("Saving into %s\n", optarg);
+                                       fprintf(stderr, _("Saving into %s\n"), optarg);
                                        strncpy(filename, optarg, 64);
                                        if (strlen(optarg) > 63) {
                                                fprintf(stderr, _("Filename too long - will be truncated to 63 characters.\n"));
@@ -1259,8 +1113,8 @@ int getsms(int argc, char *argv[])
                                switch (message.UDH[0].Type) {
                                case SMS_OpLogo:
                                        fprintf(stdout, _("GSM operator logo for %s (%s) network.\n"), bitmap.netcode, GSM_GetNetworkName(bitmap.netcode));
-                                       if (!strcmp(message.RemoteNumber.number, "+998000005") && !strcmp(message.MessageCenter.Number, "+886935074443")) dprintf(_("Saved by Logo Express\n"));
-                                       if (!strcmp(message.RemoteNumber.number, "+998000002") || !strcmp(message.RemoteNumber.number, "+998000003")) dprintf(_("Saved by Operator Logo Uploader by Thomas Kessler\n"));
+                                       if (!strcmp(message.RemoteNumber.number, "+998000005") && !strcmp(message.MessageCenter.Number, "+886935074443")) fprintf(stdout, _("Saved by Logo Express\n"));
+                                       if (!strcmp(message.RemoteNumber.number, "+998000002") || !strcmp(message.RemoteNumber.number, "+998000003")) fprintf(stdout, _("Saved by Operator Logo Uploader by Thomas Kessler\n"));
                                        offset = 3;
                                case SMS_CallerIDLogo:
                                        fprintf(stdout, ("Logo:\n"));
@@ -1271,7 +1125,7 @@ int getsms(int argc, char *argv[])
                                                error = GE_NONE;
                                                if ((stat(filename, &buf) == 0)) {
                                                        fprintf(stdout, _("File %s exists.\n"), filename);
-                                                       fprintf(stderr, _("Overwrite? (yes/no) "));
+                                                       fprintf(stdout, _("Overwrite? (yes/no) "));
                                                        GetLine(stdin, ans, 4);
                                                        if (!strcmp(ans, _("yes"))) {
                                                                error = GSM_SaveBitmapFile(filename, &bitmap);
@@ -1364,14 +1218,14 @@ int deletesms(int argc, char *argv[])
                else {
                        if (error == GE_NOTIMPLEMENTED) {
                                fprintf(stderr, _("Function not implemented in %s model!\n"), model);
-                               GSM->Terminate();
+                               if (GSM && GSM->Terminate) GSM->Terminate();
                                return -1;      
                        }
                        fprintf(stdout, _("DeleteSMS %s %d failed!(%d)\n\n"), memory_type_string, count, error);
                }
        }
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -1394,17 +1248,18 @@ int entersecuritycode(char *type)
        GSM_Error test;
        GSM_SecurityCode SecurityCode;
 
-       if (!strcmp(type,"PIN"))
-               SecurityCode.Type=GSCT_Pin;
-       else if (!strcmp(type,"PUK"))
-               SecurityCode.Type=GSCT_Puk;
-       else if (!strcmp(type,"PIN2"))
-               SecurityCode.Type=GSCT_Pin2;
-       else if (!strcmp(type,"PUK2"))
-               SecurityCode.Type=GSCT_Puk2;
-       // FIXME: Entering of SecurityCode does not work :-(
-       //  else if (!strcmp(type,"SecurityCode"))
-       //    SecurityCode.Type=GSCT_SecurityCode;
+       if (!strcmp(type, "PIN"))
+               SecurityCode.Type = GSCT_Pin;
+       else if (!strcmp(type, "PUK"))
+               SecurityCode.Type = GSCT_Puk;
+       else if (!strcmp(type, "PIN2"))
+               SecurityCode.Type = GSCT_Pin2;
+       else if (!strcmp(type, "PUK2"))
+               SecurityCode.Type = GSCT_Puk2;
+       /* FIXME: Entering of SecurityCode does not work :-(
+       else if (!strcmp(type, "SecurityCode"))
+               SecurityCode.Type = GSCT_SecurityCode;
+       */
        else
                usage();
 
@@ -1412,10 +1267,10 @@ int entersecuritycode(char *type)
        printf("Enter your code: ");
        gets(SecurityCode.Code);
 #else
-       strcpy(SecurityCode.Code,getpass(_("Enter your code: ")));
+       strcpy(SecurityCode.Code, getpass(_("Enter your code: ")));
 #endif
 
-       test = GSM->EnterSecurityCode(SecurityCode);
+       if (GSM && GSM->EnterSecurityCode) test = GSM->EnterSecurityCode(SecurityCode);
        if (test == GE_INVALIDSECURITYCODE)
                fprintf(stdout, _("Error: invalid code.\n"));
        else if (test == GE_NONE)
@@ -1425,7 +1280,7 @@ int entersecuritycode(char *type)
        else
                fprintf(stdout, _("Other error.\n"));
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -1434,7 +1289,7 @@ int getsecuritycodestatus(void)
 {
        int Status;
 
-       if (GSM->GetSecurityCodeStatus(&Status) == GE_NONE) {
+       if (GSM && GSM->GetSecurityCodeStatus && GSM->GetSecurityCodeStatus(&Status) == GE_NONE) {
 
                fprintf(stdout, _("Security code status: "));
 
@@ -1463,7 +1318,7 @@ int getsecuritycodestatus(void)
                }
        }
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -1474,9 +1329,9 @@ int getsecuritycodestatus(void)
 /* Voice dialing mode. */
 int dialvoice(char *Number)
 {
-       GSM->DialVoice(Number);
+       if (GSM && GSM->DialVoice) GSM->DialVoice(Number);
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -1594,9 +1449,9 @@ GSM_Error SaveBitmapFileOnConsole(char *FileName, GSM_Bitmap *bitmap)
                while (!confirm) {
                        fprintf(stderr, _("Saving logo. File \"%s\" exists. (O)verwrite, create (n)ew or (s)kip ? "), FileName);
                        GetLine(stdin, ans, 4);
-                       if (!strcmp(ans, "O") || !strcmp(ans, "o")) confirm = 1;
-                       if (!strcmp(ans, "N") || !strcmp(ans, "n")) confirm = 2;
-                       if (!strcmp(ans, "S") || !strcmp(ans, "s")) return GE_USERCANCELED;
+                       if (!strcmp(ans, _("O")) || !strcmp(ans, _("o"))) confirm = 1;
+                       if (!strcmp(ans, _("N")) || !strcmp(ans, _("n"))) confirm = 2;
+                       if (!strcmp(ans, _("S")) || !strcmp(ans, _("s"))) return GE_USERCANCELED;
                }  
                if (confirm == 1) break;
                if (confirm == 2) {
@@ -1785,13 +1640,13 @@ int setlogo(int argc, char *argv[])
                if (!strcmp(argv[0], "op") || !strcmp(argv[0], "startup") || !strcmp(argv[0], "caller")) {
                        if (argc > 1) {
                                if (ReadBitmapFileOnConsole(argv[1], &bitmap) != GE_NONE) {
-                                       GSM->Terminate();
+                                       if (GSM && GSM->Terminate) GSM->Terminate();
                                        return(-1);
                                }
 
                                if (!strcmp(argv[0], "op")) {
                                        if (bitmap.type != GSM_OperatorLogo || argc < 3) {
-                                               if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode, NetworkInfo.NetworkCode, 7);
+                                               if (GSM && GSM->GetNetworkInfo && GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode, NetworkInfo.NetworkCode, 7);
                                        }
                                        GSM_ResizeBitmap(&bitmap, GSM_OperatorLogo, GSM_Info);
                                        if (argc == 3) {
@@ -1815,7 +1670,7 @@ int setlogo(int argc, char *argv[])
                                        }
                                        oldbit.type = GSM_CallerLogo;
                                        oldbit.number = bitmap.number;
-                                       if (GSM->GetBitmap(&oldbit) == GE_NONE) {
+                                       if (GSM && GSM->GetBitmap && GSM->GetBitmap(&oldbit) == GE_NONE) {
                                                /* We have to get the old name and ringtone!! */
                                                bitmap.ringtone = oldbit.ringtone;
                                                strncpy(bitmap.text, oldbit.text, 255);
@@ -1839,18 +1694,18 @@ int setlogo(int argc, char *argv[])
                        }  
                } else {
                        fprintf(stderr, _("What kind of logo do you want to set ?\n"));
-                       GSM->Terminate();
+                       if (GSM && GSM->Terminate) GSM->Terminate();
                        return -1;
                }
        }
     
-       error=GSM->SetBitmap(&bitmap);
+       if (GSM && GSM->SetBitmap) error = GSM->SetBitmap(&bitmap);
   
        switch (error) {
        case GE_NONE:
                oldbit.type = bitmap.type;
                oldbit.number = bitmap.number;
-               if (GSM->GetBitmap(&oldbit) == GE_NONE) {
+               if (GSM && GSM->GetBitmap && GSM->GetBitmap(&oldbit) == GE_NONE) {
                        if (bitmap.type == GSM_WelcomeNoteText ||
                            bitmap.type == GSM_DealerNoteText) {
                                if (strcmp(bitmap.text, oldbit.text)) {
@@ -1871,13 +1726,13 @@ int setlogo(int argc, char *argv[])
                                        /* When we make it correct, we don't have this mistake */
                        
                                        strcpy(oldbit.text, "!\0");
-                                       GSM->SetBitmap(&oldbit);
-                                       GSM->GetBitmap(&oldbit);
+                                       if (GSM && GSM->SetBitmap) GSM->SetBitmap(&oldbit);
+                                       if (GSM && GSM->GetBitmap) GSM->GetBitmap(&oldbit);
                                        if (oldbit.text[0]!='!') {
                                                fprintf(stderr, _("SIM card and PIN is required\n"));
                                        } else {
-                                               GSM->SetBitmap(&bitmap);
-                                               GSM->GetBitmap(&oldbit);
+                                               if (GSM && GSM->SetBitmap) GSM->SetBitmap(&bitmap);
+                                               if (GSM && GSM->GetBitmap) GSM->GetBitmap(&oldbit);
                                                fprintf(stderr, _("too long, truncated to \"%s\" (length %i)\n"),oldbit.text,strlen(oldbit.text));
                                        }
                                        ok = false;
@@ -1907,7 +1762,7 @@ int setlogo(int argc, char *argv[])
                break;
        }
   
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -2056,7 +1911,7 @@ int getcalendarnote(int argc, char *argv[])
                }
        }
        
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return error;
 }
 
@@ -2071,12 +1926,12 @@ int writecalendarnote(char *argv[])
        }
 
         /* Error 22=Calendar full ;-) */
-       if ((GSM->WriteCalendarNote(&CalendarNote)) == GE_NONE)
+       if (GSM && GSM->WriteCalendarNote && GSM->WriteCalendarNote(&CalendarNote) == GE_NONE)
                fprintf(stdout, _("Succesfully written!\n"));
        else
                fprintf(stdout, _("Failed to write calendar note!\n"));
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -2094,7 +1949,7 @@ int deletecalendarnote(int argc, char *argv[])
 
                CalendarNote.Location = i;
 
-               if (GSM->DeleteCalendarNote(&CalendarNote) == GE_NONE) {
+               if (GSM && GSM->DeleteCalendarNote && GSM->DeleteCalendarNote(&CalendarNote) == GE_NONE) {
                        fprintf(stdout, _("   Calendar note deleted.\n"));
                } else {
                        fprintf(stderr, _("The calendar note can not be deleted\n"));
@@ -2102,7 +1957,7 @@ int deletecalendarnote(int argc, char *argv[])
 
        }
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -2145,15 +2000,16 @@ int setdatetime(int argc, char *argv[])
        }
 
        /* FIXME: Error checking should be here. */
-       GSM->SetDateTime(&Date);
+       if (GSM && GSM->SetDateTime) GSM->SetDateTime(&Date);
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
 
 /* In this mode we receive the date and time from mobile phone. */
-int getdatetime(void) {
+int getdatetime(void)
+{
        GSM_Data        data;
        GSM_DateTime    date_time;
        GSM_Error       error;
@@ -2192,9 +2048,9 @@ int setalarm(char *argv[])
        Date.Hour = atoi(argv[0]);
        Date.Minute = atoi(argv[1]);
 
-       GSM->SetAlarm(1, &Date);
+       if (GSM && GSM->SetAlarm) GSM->SetAlarm(1, &Date);
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -2275,55 +2131,55 @@ int monitormode(void)
        /* Loop here indefinitely - allows you to see messages from GSM code in
           response to unknown messages etc. The loops ends after pressing the
           Ctrl+C. */
-       data.RFUnits=&rf_units;
-       data.RFLevel=&rflevel;
-       data.BatteryUnits=&batt_units;
-       data.BatteryLevel=&batterylevel;
+       data.RFUnits = &rf_units;
+       data.RFLevel = &rflevel;
+       data.BatteryUnits = &batt_units;
+       data.BatteryLevel = &batterylevel;
 
        while (!bshutdown) {
-               if (SM_Functions(GOP_GetRFLevel,&data,sm) == GE_NONE)
+               if (SM_Functions(GOP_GetRFLevel, &data, sm) == GE_NONE)
                        fprintf(stdout, _("RFLevel: %d\n"), (int)rflevel);
 
-               if (SM_Functions(GOP_GetBatteryLevel,&data,sm) == GE_NONE)
+               if (SM_Functions(GOP_GetBatteryLevel, &data, sm) == GE_NONE)
                        fprintf(stdout, _("Battery: %d\n"), (int)batterylevel);
 
 //             if (GSM->GetPowerSource(&powersource) == GE_NONE)
 //                     fprintf(stdout, _("Power Source: %s\n"), (powersource==GPS_ACDC)?_("AC/DC"):_("battery"));
 
-               data.MemoryStatus=&SIMMemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &SIMMemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("SIM: Used %d, Free %d\n"), SIMMemoryStatus.Used, SIMMemoryStatus.Free);
 
-               data.MemoryStatus=&PhoneMemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &PhoneMemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("Phone: Used %d, Free %d\n"), PhoneMemoryStatus.Used, PhoneMemoryStatus.Free);
 
-               data.MemoryStatus=&DC_MemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &DC_MemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("DC: Used %d, Free %d\n"), DC_MemoryStatus.Used, DC_MemoryStatus.Free);
 
-               data.MemoryStatus=&EN_MemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &EN_MemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("EN: Used %d, Free %d\n"), EN_MemoryStatus.Used, EN_MemoryStatus.Free);
 
-               data.MemoryStatus=&FD_MemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &FD_MemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("FD: Used %d, Free %d\n"), FD_MemoryStatus.Used, FD_MemoryStatus.Free);
 
-               data.MemoryStatus=&LD_MemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &LD_MemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("LD: Used %d, Free %d\n"), LD_MemoryStatus.Used, LD_MemoryStatus.Free);
 
-               data.MemoryStatus=&MC_MemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &MC_MemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("MC: Used %d, Free %d\n"), MC_MemoryStatus.Used, MC_MemoryStatus.Free);
 
-               data.MemoryStatus=&ON_MemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &ON_MemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("ON: Used %d, Free %d\n"), ON_MemoryStatus.Used, ON_MemoryStatus.Free);
 
-               data.MemoryStatus=&RC_MemoryStatus;
-               if (SM_Functions(GOP_GetMemoryStatus,&data,sm) == GE_NONE)
+               data.MemoryStatus = &RC_MemoryStatus;
+               if (SM_Functions(GOP_GetMemoryStatus, &data, sm) == GE_NONE)
                        fprintf(stdout, _("RC: Used %d, Free %d\n"), RC_MemoryStatus.Used, RC_MemoryStatus.Free);
 
 //             if (GSM->GetSMSStatus(&SMSStatus) == GE_NONE)
@@ -2341,9 +2197,7 @@ int monitormode(void)
                sleep(1);
        }
 
-       fprintf (stderr, _("Leaving monitor mode...\n"));
-
-       //GSM->Terminate();
+       fprintf(stderr, _("Leaving monitor mode...\n"));
 
        return 0;
 }
@@ -2362,7 +2216,7 @@ static GSM_Error PrettyOutputFn(char *Display, char *Indicators)
 }
 
 #if 0
-// Uncomment it if used
+/* Uncomment it if used */
 static GSM_Error OutputFn(char *Display, char *Indicators)
 {
        if (Display)
@@ -2415,7 +2269,7 @@ int displayoutput(void)
                        memset(&buf[0], 0, 102);
                        while (read(0, buf, 100) > 0) {
                                fprintf(stderr, "handling keys (%d).\n", strlen(buf));
-                               if (GSM->HandleString(buf) != GE_NONE)
+                               if (GSM && GSM->HandleString && GSM->HandleString(buf) != GE_NONE)
                                        fprintf(stdout, _("Key press simulation failed.\n"));
                                memset(buf, 0, 102);
                        }
@@ -2432,7 +2286,7 @@ int displayoutput(void)
        } else
                fprintf (stderr, _("Error!\n"));
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
 
@@ -2448,18 +2302,18 @@ int getprofile(int argc, char *argv[])
        char model[64];
 
        profile.Number = 0;
-       error = GSM->GetProfile(&profile);
+       if (GSM && GSM->GetProfile) error = GSM->GetProfile(&profile);
 
        if (error == GE_NONE) {
   
-               while (GSM->GetModel(model) != GE_NONE)
+               while (GSM && GSM->GetModel && GSM->GetModel(model) != GE_NONE)
                        sleep(1);
 
                max_profiles = 7; /* This is correct for 6110 (at least my). How do we get
                                     the number of profiles? */
 
-               /*For N5110*/
-               /*FIX ME: It should be set to 3 for N5130 and 3210 too*/
+               /* For N5110 */
+               /* FIXME: It should be set to 3 for N5130 and 3210 too */
                if (!strcmp(model, "NSE-1"))
                        max_profiles = 3;
 
@@ -2470,13 +2324,13 @@ int getprofile(int argc, char *argv[])
 
                        if (profile.Number < 0) {
                                fprintf(stderr, _("Profile number must be value from 1 to %d!\n"), max_profiles);
-                               GSM->Terminate();
+                               if (GSM && GSM->Terminate) GSM->Terminate();
                                return -1;
                        }
 
                        if (profile.Number >= max_profiles) {
                                fprintf(stderr, _("This phone supports only %d profiles!\n"), max_profiles);
-                               GSM->Terminate();
+                               if (GSM && GSM->Terminate) GSM->Terminate();
                                return -1;
                        }
                } else {
@@ -2489,7 +2343,7 @@ int getprofile(int argc, char *argv[])
                        profile.Number = i;
 
                        if (profile.Number != 0)
-                               GSM->GetProfile(&profile);
+                               if (GSM && GSM->GetProfile) GSM->GetProfile(&profile);
 
                        fprintf(stdout, "%d. \"%s\"\n", profile.Number + 1, profile.Name);
                        if (profile.DefaultName == -1) fprintf(stdout, _(" (name defined)\n"));
@@ -2529,16 +2383,16 @@ int getprofile(int argc, char *argv[])
        } else {
                if (error == GE_NOTIMPLEMENTED) {
                        fprintf(stderr, _("Function not implemented in %s model!\n"), model);
-                       GSM->Terminate();
+                       if (GSM && GSM->Terminate) GSM->Terminate();
                        return -1;
                } else {
                        fprintf(stderr, _("Unspecified error\n"));
-                       GSM->Terminate();
+                       if (GSM && GSM->Terminate) GSM->Terminate();
                        return -1;
                }
        }
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
 
@@ -2571,8 +2425,8 @@ int getmemory(int argc, char *argv[])
 
                entry.Location = count;
 
-               data.PhonebookEntry=&entry;
-               error=SM_Functions(GOP_ReadPhonebook,&data,sm);
+               data.PhonebookEntry = &entry;
+               error = SM_Functions(GOP_ReadPhonebook, &data, sm);
 
                if (error == GE_NONE) {
                        fprintf(stdout, "%s;%s;%s;%d;%d\n", entry.Name, entry.Number, memory_type_string, entry.Location, entry.Group);
@@ -2716,7 +2570,7 @@ int writephonebook(int argc, char *args[])
                        GSM_PhonebookEntry aux;
 
                        aux.Location = entry.Location;
-                       error = GSM->GetMemoryLocation(&aux);
+                       if (GSM && GSM->GetMemoryLocation) error = GSM->GetMemoryLocation(&aux);
                        
                        if (error == GE_NONE) {
                                if (!aux.Empty) {
@@ -2734,13 +2588,13 @@ int writephonebook(int argc, char *args[])
                                }
                        } else {
                                fprintf(stderr, _("Unknown error (%d)\n"), error);
-                               GSM->Terminate();
+                               if (GSM && GSM->Terminate) GSM->Terminate();
                                return 0;
                        }
                }
 
                /* Do write and report success/failure. */
-               error = GSM->WritePhonebookLocation(&entry);
+               if (GSM && GSM->WritePhonebookLocation) error = GSM->WritePhonebookLocation(&entry);
 
                if (error == GE_NONE)
                        fprintf (stdout, _("Write Succeeded: memory type: %s, loc: %d, name: %s, number: %s\n"), memory_type_string, entry.Location, entry.Name, entry.Number);
@@ -2749,7 +2603,7 @@ int writephonebook(int argc, char *args[])
 
        }
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
 
@@ -2810,11 +2664,11 @@ int setspeeddial(char *argv[])
        entry.Number = atoi(argv[0]);
        entry.Location = atoi(argv[2]);
 
-       if (GSM->SetSpeedDial(&entry) == GE_NONE) {
+       if (GSM && GSM->SetSpeedDial && GSM->SetSpeedDial(&entry) == GE_NONE) {
                fprintf(stdout, _("Succesfully written!\n"));
        }
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
 
@@ -2823,7 +2677,7 @@ int getdisplaystatus(void)
 { 
        int Status;
 
-       GSM->GetDisplayStatus(&Status);
+       if (GSM && GSM->GetDisplayStatus) GSM->GetDisplayStatus(&Status);
 
        fprintf(stdout, _("Call in progress: %s\n"), Status & (1<<DS_Call_In_Progress)?_("on"):_("off"));
        fprintf(stdout, _("Unknown: %s\n"),          Status & (1<<DS_Unknown)?_("on"):_("off"));
@@ -2834,7 +2688,7 @@ int getdisplaystatus(void)
        fprintf(stdout, _("Keyboard lock: %s\n"),    Status & (1<<DS_Keyboard_Lock)?_("on"):_("off"));
        fprintf(stdout, _("SMS storage full: %s\n"), Status & (1<<DS_SMS_Storage_Full)?_("on"):_("off"));
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
 
@@ -2855,12 +2709,12 @@ int netmonitor(char *Mode)
                mode = 0x00;
 
        memset(&Screen, 0, 50);
-       GSM->NetMonitor(mode, Screen);
+       if (GSM && GSM->NetMonitor) GSM->NetMonitor(mode, Screen);
 
        if (Screen)
                fprintf(stdout, "%s\n", Screen);
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
 
@@ -2870,10 +2724,10 @@ int identify(void)
        char imei[64], model[64], rev[64], manufacturer[64];
        GSM_Statemachine *sm = &State;
 
-       data.Manufacturer=manufacturer;
-       data.Model=model;
-       data.Revision=rev;
-       data.Imei=imei;
+       data.Manufacturer = manufacturer;
+       data.Model = model;
+       data.Revision = rev;
+       data.Imei = imei;
 
        /* Retrying is bad idea: what if function is simply not implemented?
           Anyway let's wait 2 seconds for the right packet from the phone. */
@@ -2891,15 +2745,13 @@ int identify(void)
        fprintf(stdout, _("Model:    %s\n"), model);
        fprintf(stdout, _("Revision: %s\n"), rev);
 
-       //GSM->Terminate();
-
        return 0;
 }
 
 int senddtmf(char *String)
 {
-       GSM->SendDTMF(String);
-       GSM->Terminate();
+       if (GSM && GSM->SendDTMF) GSM->SendDTMF(String);
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
 
@@ -2920,8 +2772,8 @@ int reset( char *type)
                        }
        }
 
-       GSM->Reset(_type);
-       GSM->Terminate();
+       if (GSM && GSM->Reset) GSM->Reset(_type);
+       if (GSM && GSM->Terminate) GSM->Terminate();
 
        return 0;
 }
@@ -2931,7 +2783,6 @@ int reset( char *type)
    tool. */
 int pmon(void)
 { 
-
        GSM_Error error;
        GSM_ConnectionType connection=GCT_Serial;
        GSM_Statemachine sm;
@@ -2961,16 +2812,15 @@ int sendringtone(int argc, char *argv[])
                return(-1);
        }  
 
-       error = GSM->SendRingtone(&ringtone,argv[1]);
+       if (GSM && GSM->SendRingtone) error = GSM->SendRingtone(&ringtone,argv[1]);
 
        if (error == GE_NONE) 
                fprintf(stdout, _("Send succeeded!\n"));
        else
                fprintf(stdout, _("SMS Send failed (error=%d)\n"), error);
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
-
 }
 
 
@@ -2984,16 +2834,15 @@ int setringtone(int argc, char *argv[])
                return(-1);
        }  
 
-       error = GSM->SetRingtone(&ringtone);
+       if (GSM && GSM->SetRingtone) error = GSM->SetRingtone(&ringtone);
 
        if (error == GE_NONE) 
                fprintf(stdout, _("Send succeeded!\n"));
        else
                fprintf(stdout, _("Send failed\n"));
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
-
 }
 
 int presskeysequence(void)
@@ -3005,23 +2854,124 @@ int presskeysequence(void)
        memset(&buf[0], 0, 102);
        while (read(0, buf, 100) > 0) {
                fprintf(stderr, "handling keys (%d).\n", strlen(buf));
-               if (GSM->HandleString(buf) != GE_NONE)
+               if (GSM && GSM->HandleString && GSM->HandleString(buf) != GE_NONE)
                        fprintf(stdout, _("Key press simulation failed.\n"));
                memset(buf, 0, 102);
        }
 
-       GSM->Terminate();
+       if (GSM && GSM->Terminate) GSM->Terminate();
        return 0;
 }
+
+/* Options for --divert:
+   --op, -o [register|enable|query|disable|erasure]  REQ
+   --type, -t [all|busy|noans|outofreach|notavail]   REQ
+   --call, -c [all|voice|fax|data]                   REQ
+   --timeout, m time_in_seconds                      OPT
+   --number, -n number                               OPT
+ */
+int divert(int argc, char **argv)
+{
+       int opt;
+       GSM_CallDivert cd;
+       GSM_Statemachine *sm = &State;
+       GSM_Data data;
+       GSM_Error error;
+       struct option options[] = {
+               { "op",      required_argument, NULL, 'o'},
+               { "type",    required_argument, NULL, 't'},
+               { "call",    required_argument, NULL, 'c'},
+               { "number",  required_argument, NULL, 'n'},
+               { "timeout", required_argument, NULL, 'm'},
+               { NULL,      0,                 NULL, 0}
+       };
+
+       optarg = NULL;
+       optind = 0;
+
+       /* Skip --divert */
+       argc--; argv++;
+
+       memset(&cd, 0, sizeof(GSM_CallDivert));
+
+       while ((opt = getopt_long(argc, argv, "o:t:n:c:m:", options, NULL)) != -1) {
+               switch (opt) {
+               case 'o':
+                       if (!strcmp("register", optarg)) {
+                               cd.Operation = GSM_CDV_Register;
+                       } else if (!strcmp("enable", optarg)) {
+                               cd.Operation = GSM_CDV_Enable;
+                       } else if (!strcmp("disable", optarg)) {
+                               cd.Operation = GSM_CDV_Disable;
+                       } else if (!strcmp("erasure", optarg)) {
+                               cd.Operation = GSM_CDV_Erasure;
+                       } else if (!strcmp("query", optarg)) {
+                               cd.Operation = GSM_CDV_Query;
+                       } else {
+                               usage();
+                               exit(-1);
+                       }
+                       break;
+               case 't':
+                       if (!strcmp("all", optarg)) {
+                               cd.DType = GSM_CDV_AllTypes;
+                       } else if (!strcmp("busy", optarg)) {
+                               cd.DType = GSM_CDV_Busy;
+                       } else if (!strcmp("noans", optarg)) {
+                               cd.DType = GSM_CDV_NoAnswer;
+                       } else if (!strcmp("outofreach", optarg)) {
+                               cd.DType = GSM_CDV_OutOfReach;
+                       } else if (!strcmp("notavail", optarg)) {
+                               cd.DType = GSM_CDV_NotAvailable;
+                       } else {
+                               usage();
+                               exit(-1);
+                       }
+                       break;
+               case 'c':
+                       if (!strcmp("all", optarg)) {
+                               cd.CType = GSM_CDV_AllCalls;
+                       } else if (!strcmp("voice", optarg)) {
+                               cd.CType = GSM_CDV_VoiceCalls;
+                       } else if (!strcmp("fax", optarg)) {
+                               cd.CType = GSM_CDV_FaxCalls;
+                       } else if (!strcmp("data", optarg)) {
+                               cd.CType = GSM_CDV_DataCalls;
+                       } else {
+                               usage();
+                               exit(-1);
+                       }
+                       break;
+               case 'm':
+                       cd.Timeout = atoi(optarg);
+                       break;
+               case 'n':
+                       strcpy(cd.Number.number, optarg);
+                       if (cd.Number.number[0] == '+') cd.Number.type = SMS_International;
+                       else cd.Number.type = SMS_Unknown;
+                       break;
+               default:
+                       usage();
+                       exit(-1);
+               }
+       }
+       data.CallDivert = &cd;
+       error = SM_Functions(GOP_CallDivert, &data, sm);
+
+       if (error == GE_NONE) {
+               fprintf(stderr, "Divert succeeded.\n");
+       } else {
+               fprintf(stderr, "%s\n", print_error(error));
+       }
+       return 0;
+}
+
 /* This is a "convenience" function to allow quick test of new API stuff which
    doesn't warrant a "proper" command line function. */
 #ifndef WIN32
 int foogle(char *argv[])
 {
-       /* Initialise the code for the GSM interface. */     
-       fbusinit(NULL);
-       // Fill in what you would like to test here...
+       /* Fill in what you would like to test here... */
        return 0;
 }
 #endif