This commit was manufactured by cvs2svn to create tag
[gnokii.git] / gnokii / gnokii.c
index 1cbe8fe..87943ec 100644 (file)
@@ -11,8 +11,6 @@
 
 */
 
-#include "config.h"
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
 #include <ctype.h>
 #include <time.h>
 #include <sys/stat.h>
-#include <limits.h>
-#include <errno.h>
-
-#ifdef UCLINUX
-/* <getopt.h> or "getopt.h" would include insufficient getopt.h from uClinux */
-#include "../getopt/getopt.h"
-#endif /* UCLINUX */
 
 #ifndef VC6
   #if defined(__svr4__) || defined(__FreeBSD__)
 #include "gsm-common.h"
 #include "gsm-api.h"
 #include "gsm-networks.h"
-#ifndef UCLINUX
 #include "gsm-ringtones.h"
 #include "gsm-bitmaps.h"
 #include "gsm-wap.h"
 #include "gsm-sms.h"
 #include "gsm-datetime.h"
-#endif /* UCLINUX */
 #include "gsm-phonebook.h"
-#ifndef UCLINUX
 #include "gsm-calendar.h"
-#endif /* UCLINUX */
 #include "gsm-coding.h"
-#ifndef UCLINUX
 #include "newmodules/n6110.h"
-#endif
 #include "files/cfgreader.h"
-#ifndef UCLINUX
 #include "files/gsm-filetypes.h"
-#endif /* UCLINUX */
 #include "gnokii.h"
-#ifdef UCLINUX
-#include "data/virtmodem.h"
-#endif /* UCLINUX */
 
 #ifdef USE_NLS
   #include <locale.h>
 #endif
 
-static char *model;           /* Model from .gnokiirc file. */
-static char *Port;            /* Port from .gnokiirc file */
-static char *Initlength;      /* Init length from .gnokiirc file */
-static char *Connection;      /* Connection type from .gnokiirc file */
-#ifndef UCLINUX
+char *model;           /* Model from .gnokiirc file. */
+char *Port;            /* Port from .gnokiirc file */
+char *Initlength;      /* Init length from .gnokiirc file */
+char *Connection;      /* Connection type from .gnokiirc file */
 char *SynchronizeTime; /* If we set date and time from computer to phone (from .gnokiirc file) */
-#endif /* UCLINUX */
-static char *BinDir;          /* Binaries directory from .gnokiirc file - not used here yet */
+char *BinDir;          /* Binaries directory from .gnokiirc file - not used here yet */
 
-#ifndef UCLINUX
-static GSM_SMSMessage SMS[4];
-#endif /* UCLINUX */
+GSM_SMSMessage SMS[4];
   
-#ifndef UCLINUX
-
 char *GetProfileCallAlertString(int code) {
 
   switch (code) {
@@ -240,7 +214,7 @@ char *GetProfileCallerGroups(int code)
   return BufferProfileGroups;
 }
 
-static char *print_error(GSM_Error e)
+char *print_error(GSM_Error e)
 {
 
 //     case GE_DEVICEOPENFAILED:         return "Couldn't open specified serial device.";
@@ -286,10 +260,12 @@ static char *print_error(GSM_Error e)
         case GE_INVALIDBOOKMARKLOCATION:  return "Invalid or empty WAP bookmark location";
         case GE_INSIDESETTINGSMENU:       return "Inside WAP Settings menu. Please leave it and try again";
         case GE_INVALIDSETTINGSLOCATION:  return "Invalid or empty WAP settings location";
+        case GE_EMPTYSMSC:                return "Empty SMSC number. Use --smsc";
        default:                          return "Unknown error.";
        }
 }
 
+
 GSM_Error GSM_ReadRingtoneFileOnConsole(char *FileName, GSM_Ringtone *ringtone)
 {
   GSM_Error error;
@@ -478,8 +454,8 @@ int GSM_SendMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int
   int w,i;
   
   struct option options[] = {
-             { "smscno",       required_argument, NULL, '1'},
-             { "smsc",         required_argument, NULL, '2'},
+             { "smscno",       required_argument, NULL, '2'},
+             { "smsc",         required_argument, NULL, '1'},
             { "name",         required_argument, NULL, '3'},
              { "unicode",      no_argument,       NULL, '4'},
              { "profilestyle", no_argument,       NULL, '5'},
@@ -552,7 +528,7 @@ int GSM_SendMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int
     if (error == GE_SMSSENDOK) {
       fprintf(stdout, _("SMS %i/%i sent OK !\n"),w+1,MultiSMS->number);
     } else {
-      fprintf(stdout, _("SMS %i/%i, sending failed (error=%d)\n"),w+1,MultiSMS->number, error);
+      fprintf(stdout, _("SMS %i/%i, sending failed (%d, %s)\n"),w+1,MultiSMS->number, error,print_error(error));
     }
 
   }
@@ -562,7 +538,7 @@ int GSM_SendMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int
   return 0;
 }
 
-static int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[],
+int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[],
                                   bool inter, bool unicode, bool profile, bool scale) {
 
   int w,i;
@@ -570,8 +546,8 @@ static int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argn
   GSM_SMSMessage SMSold;
 
   struct option options[] = {
-             { "smscno",       required_argument, NULL, '1'},
-             { "smsc",         required_argument, NULL, '2'},
+             { "smscno",       required_argument, NULL, '2'},
+             { "smsc",         required_argument, NULL, '1'},
             { "name",         required_argument, NULL, '3'},
              { "unicode",      no_argument,       NULL, '4'},
              { "profilestyle", no_argument,       NULL, '5'},
@@ -680,7 +656,7 @@ static int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argn
     if (error == GE_NONE)
       fprintf(stdout, _("SMS %i/%i saved at location %i !\n"),w+1,MultiSMS->number,MultiSMS->SMS[w].MessageNumber);
     else
-      fprintf(stdout, _("SMS %i/%i saving failed (error=%d, location=%i)\n"), w+1, MultiSMS->number, error,MultiSMS->SMS[w].Location);
+      fprintf(stdout, _("SMS %i/%i saving failed (%d, %s, location=%i)\n"), w+1, MultiSMS->number,error,print_error(error),MultiSMS->SMS[w].Location);
   }
 
   GSM->Terminate();  
@@ -707,11 +683,9 @@ void GSM_PlayRingtoneOnConsole(GSM_Ringtone *ringtone)
   GSM->PlayTone(255*255,0);
 }
 
-#endif /* UCLINUX */
-
 /* This function shows the copyright and some informations usefull for
    debugging. */
-static int version(void)
+int version(void)
 {
 
   fprintf(stdout, _("GNOKII Version %s\n"
@@ -725,32 +699,12 @@ static int version(void)
 /* The function usage is only informative - it prints this program's usage and
    command-line options. */
 
-static int usage(void)
+int usage(void)
 {
 
-  fprintf(stdout, _("   usage: gnokii [--help] [--version]\n"
-  ));
-#ifndef UCLINUX
-"          gnokii --monitor [-noloop|-nl]\n"
-  ));
-#endif /* UCLINUX */
-
-#ifndef UCLINUX
-  fprintf(stdout, _(
+  fprintf(stdout, _("   usage: gnokii [--help|--monitor [-noloop|-nl]|--version]\n"
 "          gnokii --getmemory memory_type [start [end]] [-short|-v30|-v21|-v]\n"
-  ));
-#else /* UCLINUX */
-  fprintf(stdout, _(
-"          gnokii --getmemory memory_type [start [end]] [-short]\n"
-  ));
-#endif /* UCLINUX */
-
-  fprintf(stdout, _(
 "          gnokii --writephonebook [-i]\n"
-  ));
-
-#ifndef UCLINUX
-  fprintf(stdout, _(
 "          gnokii --sendphonebookentry destination memory_type location\n"
 "                 [--smsc message_center_number] [--smscno message_center_index]\n"
 "                 [-s] [-v n] [-d]\n"
@@ -758,16 +712,9 @@ static int usage(void)
 "                 [--smsc message_center_number] [--smscno message_center_index]\n"
 "                 [-r] [-i] [-s] [-a] [--name name]\n"
 "          gnokii --getvoicemailbox\n"
-  ));
-#endif /* UCLINUX */
-
-  fprintf(stdout, _(
 "          gnokii --getspeeddial number\n"
 "          gnokii --setspeeddial number memory_type location\n\n"
-  ));
 
-#ifndef UCLINUX
-  fprintf(stdout, _(
 "          gnokii --getsms memory_type start [end] [-f file]\n"
 "          gnokii --getsmsstatus\n"
 "          gnokii --getsmsfolders\n"
@@ -868,25 +815,10 @@ static int usage(void)
 "          gnokii --sendprofile destination profile_name ringtonefile\n"
 "                 picturefile [--smsc message_center_number]\n"
 "                 [--smscno message_center_index] [-s] [-v n] [-d] [--scale]\n\n"
-  ));
-#endif /* UCLINUX */
 
-  fprintf(stdout, _(
 "          gnokii --reset [soft|hard]\n"
-  ));
-
-#ifndef UCLINUX
-  fprintf(stdout, _(
 "          gnokii --dialvoice number\n"
-  ));
-#endif /* UCLINUX */
-
-  fprintf(stdout, _(
 "          gnokii --cancelcall\n"
-  ));
-
-#ifndef UCLINUX
-  fprintf(stdout, _(
 "          gnokii --displayoutput\n"
 "          gnokii --presskeysequence sequence\n"
 "          gnokii --backupsettings file\n"
@@ -903,15 +835,8 @@ static int usage(void)
 "          gnokii --phonetests\n"
 "          gnokii --simlock\n"
 "          gnokii --getdisplaystatus\n"
-  ));
-#endif /* UCLINUX */
-
-  fprintf(stdout, _(
 "          gnokii --identify\n\n"
-  ));
 
-#ifndef UCLINUX
-  fprintf(stdout, _(
 "          gnokii --getwapbookmark location\n"
 "          gnokii --setwapbookmark title url [location]\n"
 "          gnokii --sendwapbookmark location destination\n"
@@ -943,14 +868,7 @@ static int usage(void)
   fprintf(stdout, _(
 "          gnokii --sniff [port]\n"
 "          gnokii --decodefile file\n"
-  ));
-#endif
-
-#endif /* UCLINUX */
-
-#ifdef UCLINUX
-  fprintf(stdout, _(
-"          gnokii --gnokiid [--debug] [<child to run> [<child args>...]]\n"
+"          gnokii --getbinringfromfile file name offset file2\n"
   ));
 #endif
 
@@ -960,7 +878,7 @@ static int usage(void)
 /* fbusinit is the generic function which waits for the FBUS link. The limit
    is 10 seconds. After 10 seconds we quit. */
 
-static void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
+void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 {
 
   int count=0;
@@ -972,7 +890,7 @@ static void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 #endif
 
   /* Initialise the code for the GSM interface. */     
-  error = GSM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), rlp_handler, ""/*SynchronizeTime*/);
+  error = GSM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), rlp_handler, SynchronizeTime);
 
   if (error != GE_NONE) {
     fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
@@ -993,7 +911,7 @@ static void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
 /* This function checks that the argument count for a given options is withing
    an allowed range. */
 
-static int checkargs(int opt, struct gnokii_arg_len gals[], int argc)
+int checkargs(int opt, struct gnokii_arg_len gals[], int argc)
 {
 
   int i;
@@ -1027,8 +945,6 @@ static int checkargs(int opt, struct gnokii_arg_len gals[], int argc)
           else return 1;
 }
 
-static int gnokiid(int argc, char *argv[]);
-
 /* Main function - handles command line arguments, passes them to separate
    functions accordingly. */
 
@@ -1046,19 +962,14 @@ int main(int argc, char *argv[])
 
     { "help",               no_argument,       NULL, OPT_HELP             },// Display usage.
     { "version",            no_argument,       NULL, OPT_VERSION          },// Display version and build information.
-#ifndef UCLINUX
     { "getsmsfolders",      no_argument,       NULL, OPT_GETSMSFOLDERS    },// Gets SMS folders
     { "getsmsstatus",       no_argument,       NULL, OPT_GETSMSSTATUS     },// Get SMS Folder Status
-#endif /* UCLINUX */
     { "identify",           no_argument,       NULL, OPT_IDENTIFY         },// Identify
-#ifndef UCLINUX
     { "pmon",               no_argument,       NULL, OPT_PMON             },// For development purposes: run in passive monitoring mode
     { "foogle",             no_argument,       NULL, OPT_FOOGLE           },// For development purposes: insert you function calls here
     { "getdatetime",        no_argument,       NULL, OPT_GETDATETIME      },// Get date and time mode    
     { "getalarm",           no_argument,       NULL, OPT_GETALARM         },// Get alarm    
-#endif /* UCLINUX */
     { "cancelcall",         no_argument,       NULL, OPT_CANCELCALL       },// Cancel Call    
-#ifndef UCLINUX
     { "getdisplaystatus",   no_argument,       NULL, OPT_GETDISPLAYSTATUS },// Get display status mode    
     { "allringtones",       no_argument,       NULL, OPT_ALLRINGTONES     },/* Displays names of available ringtones */    
     { "displayoutput",      no_argument,       NULL, OPT_DISPLAYOUTPUT    },/* Show texts from phone's display */
@@ -1070,10 +981,8 @@ int main(int argc, char *argv[])
     { "receivesms",         no_argument,       NULL, OPT_RECEIVESMS       },    
     { "setoperatorname",    optional_argument, NULL, OPT_SETOPERATORNAME  },/* Set downloaded operator name */    
     { "setdatetime",        optional_argument, NULL, OPT_SETDATETIME      },// Set date and time    
-#endif /* UCLINUX */
     { "writephonebook",     optional_argument, NULL, OPT_WRITEPHONEBOOK   },// Write phonebook (memory) mode
     { "reset",              optional_argument, NULL, OPT_RESET            },// Resets the phone
-#ifndef UCLINUX
     { "monitor",            optional_argument, NULL, OPT_MONITOR          },// Monitor mode
     { "setlogo",            optional_argument, NULL, OPT_SETLOGO          },// Set logo
     { "getprofile",         optional_argument, NULL, OPT_GETPROFILE       },// Show profile
@@ -1086,11 +995,9 @@ int main(int argc, char *argv[])
     { "sendphonebookentry", required_argument, NULL, OPT_SENDPHONEBOOKENTRY},
     { "savephonebookentry", required_argument, NULL, OPT_SAVEPHONEBOOKENTRY},
     { "deletecalendarnote", required_argument, NULL, OPT_DELCALENDARNOTE  },// Delete calendar note mode    
-#endif /* UCLINUX */
     { "getmemory",          required_argument, NULL, OPT_GETMEMORY        },// Get memory mode
     { "getspeeddial",       required_argument, NULL, OPT_GETSPEEDDIAL     },// Get speed dial mode
     { "setspeeddial",       required_argument, NULL, OPT_SETSPEEDDIAL     },// Set speed dial mode
-#ifndef UCLINUX
     { "getsms",             required_argument, NULL, OPT_GETSMS           },// Get SMS message mode
     { "deletesms",          required_argument, NULL, OPT_DELETESMS        },// Delete SMS message mode
     { "sendsms",            required_argument, NULL, OPT_SENDSMS          },// Send SMS message mode
@@ -1141,12 +1048,8 @@ int main(int argc, char *argv[])
 #ifdef DEBUG
     { "sniff",              optional_argument, NULL, OPT_SNIFFER    },// Will show datas from port
     { "decodefile",         required_argument, NULL, OPT_DECODEFILE },//decode input file
+    { "getbinringfromfile", required_argument, NULL, OPT_GETBINRINGFROMFILE },
 #endif
-#endif /* UCLINUX */
-
-#ifdef UCLINUX
-    { "gnokiid",            optional_argument, NULL, OPT_GNOKIID          },// gnokiid mode
-#endif /* UCLINUX */
 
     { 0, 0, 0, 0},
   };
@@ -1157,7 +1060,6 @@ int main(int argc, char *argv[])
   struct gnokii_arg_len gals[] =
   {
 
-#ifndef UCLINUX
     { OPT_MONITOR,           0, 1, 0 },
 
 #ifdef SECURITY
@@ -1168,6 +1070,7 @@ int main(int argc, char *argv[])
 #ifdef DEBUG
     { OPT_SNIFFER,           0, 1, 0 },
     { OPT_DECODEFILE,        1, 1, 0 },
+    { OPT_GETBINRINGFROMFILE,4, 4, 0 },
 #endif
 
     { OPT_SETDATETIME,       0, 5, 0 },
@@ -1182,11 +1085,9 @@ int main(int argc, char *argv[])
     { OPT_SAVEPHONEBOOKENTRY,2, 9, 0 },
     { OPT_SENDPHONEBOOKENTRY,3, 9, 0 },
     { OPT_DELCALENDARNOTE,   1, 1, 0 },
-#endif /* UCLINUX */
     { OPT_GETMEMORY,         2, 4, 0 },
     { OPT_GETSPEEDDIAL,      1, 1, 0 },
     { OPT_SETSPEEDDIAL,      3, 3, 0 },
-#ifndef UCLINUX
     { OPT_GETSMS,            2, 5, 0 },
     { OPT_DELETESMS,         2, 3, 0 },
     { OPT_SENDSMS,           1,10, 0 },
@@ -1204,15 +1105,11 @@ int main(int argc, char *argv[])
     { OPT_SETRINGTONE,       1, 3, 0 },
     { OPT_GETRINGTONE,       1, 2, 0 },
     { OPT_PRESSKEYSEQUENCE,  1, 1, 0 },
-#endif /* UCLINUX */
     { OPT_RESET,             0, 1, 0 },
-#ifndef UCLINUX
     { OPT_GETPROFILE,        0, 1, 0 },
     { OPT_SETPROFILE,        3, 3, 0 },
     { OPT_SENDPROFILE,       4,10, 0 },
-#endif /* UCLINUX */
     { OPT_WRITEPHONEBOOK,    0, 1, 0 },
-#ifndef UCLINUX
     { OPT_PLAYRINGTONE,      1, 1, 0 },
     { OPT_COMPOSER,          1, 1, 0 },
     { OPT_RINGTONECONVERT,   2, 2, 0 },
@@ -1231,17 +1128,10 @@ int main(int argc, char *argv[])
     { OPT_SAVEWAPSETTINGS,   1, 9, 0 },
     { OPT_SENDWAPSETTINGS,   2, 9, 0 },
     { OPT_DIVERT,            3, 5, 0 },    
-#endif /* UCLINUX */
-
-#ifdef UCLINUX
-    { OPT_GNOKIID,           0, INT_MAX, 0 },
-#endif /* UCLINUX */
 
     { 0, 0, 0, 0 },
   };
 
-  LIVE;
-
   opterr = 0;
 
   /* For GNU gettext */
@@ -1257,7 +1147,7 @@ int main(int argc, char *argv[])
 #endif
 
     /* Read config file */
-    if (CFG_ReadConfig(&model, &Port, &Initlength, &Connection, &BinDir, false) < 0) {
+    if (CFG_ReadConfig(&model, &Port, &Initlength, &Connection, &BinDir, &SynchronizeTime,false) < 0) {
        exit(-1);
     }
 
@@ -1282,7 +1172,6 @@ int main(int argc, char *argv[])
 
     for(i = 2; i < argc; i++)
       nargv[i-2] = argv[i];
-               nargv[argc-2] = NULL;   /* required by gnokiid() for execv(3) */
        
     if(checkargs(c, gals, nargc)) {
 
@@ -1310,17 +1199,14 @@ int main(int argc, char *argv[])
     // Then, options with no arguments
     case OPT_HELP:                  rc = usage();                   break;
     case OPT_VERSION:               rc = version();                 break;
-#ifndef UCLINUX
     case OPT_MONITOR:               rc = monitormode(nargc, nargv); break;
     case OPT_GETSMSFOLDERS:         rc = getsmsfolders();           break;
     case OPT_GETDATETIME:           rc = getdatetime();             break;
     case OPT_GETALARM:              rc = getalarm();                break;
     case OPT_GETDISPLAYSTATUS:      rc = getdisplaystatus();        break;
     case OPT_PMON:                  rc = pmon();                    break;
-#endif /* UCLINUX */
     case OPT_WRITEPHONEBOOK:        rc = writephonebook(nargc, nargv);break;
 
-#ifndef UCLINUX
 #ifdef SECURITY
     case OPT_ENTERSECURITYCODE:     rc = entersecuritycode(optarg); break;
     case OPT_GETSECURITYCODESTATUS: rc = getsecuritycodestatus();   break;
@@ -1333,15 +1219,14 @@ int main(int argc, char *argv[])
 #ifdef DEBUG
     case OPT_SNIFFER:               rc = sniff(nargc, nargv);       break;
     case OPT_DECODEFILE:            rc = decodefile(nargc, nargv);  break;
+    case OPT_GETBINRINGFROMFILE:    rc = getbinringfromfile(nargc, nargv);break;
 #endif                                 
        
     // Now, options with arguments
     case OPT_SETDATETIME:           rc = setdatetime(nargc, nargv); break;
     case OPT_SETALARM:              rc = setalarm(nargv);           break;
     case OPT_DIALVOICE:             rc = dialvoice(optarg);         break;
-#endif /* UCLINUX */
     case OPT_CANCELCALL:            rc = cancelcall();              break;
-#ifndef UCLINUX
     case OPT_GETCALENDARNOTE:       rc = getcalendarnote(nargc, nargv);break;
     case OPT_DELCALENDARNOTE:       rc = deletecalendarnote(optarg);break;
     case OPT_SAVECALENDARNOTE:      rc = savecalendarnote(nargc, nargv);break;
@@ -1349,11 +1234,9 @@ int main(int argc, char *argv[])
     case OPT_SAVEPHONEBOOKENTRY:    rc = savephonebookentry(nargc, nargv);break;
     case OPT_SENDPHONEBOOKENTRY:    rc = sendphonebookentry(nargc, nargv);break;
     case OPT_WRITECALENDARNOTE:     rc = writecalendarnote(nargv);  break;
-#endif /* UCLINUX */
     case OPT_GETMEMORY:             rc = getmemory(nargc, nargv);   break;
     case OPT_GETSPEEDDIAL:          rc = getspeeddial(optarg);      break;
     case OPT_SETSPEEDDIAL:          rc = setspeeddial(nargv);       break;
-#ifndef UCLINUX
     case OPT_GETSMS:                rc = getsms(argc, argv);        break;
     case OPT_GETSMSSTATUS:          rc = getsmsstatus(argc, argv);  break;
     case OPT_DELETESMS:             rc = deletesms(nargc, nargv);   break;
@@ -1365,9 +1248,7 @@ int main(int argc, char *argv[])
     case OPT_GETSMSC:               rc = getsmsc(optarg);           break;
     case OPT_RENAMESMSC:            rc = renamesmsc(nargc,nargv);   break;
     case OPT_NETMONITOR:            rc = netmonitor(optarg);        break;
-#endif /* UCLINUX */
     case OPT_IDENTIFY:              rc = identify();                break;
-#ifndef UCLINUX
     case OPT_SETLOGO:               rc = setlogo(nargc, nargv);     break;
     case OPT_GETLOGO:               rc = getlogo(nargc, nargv);     break;
     case OPT_RECEIVESMS:            rc = receivesms(nargc, nargv);  break;
@@ -1392,9 +1273,7 @@ int main(int argc, char *argv[])
     case OPT_PHONETESTS:            rc = phonetests();              break;
     case OPT_SIMLOCKINFO:           rc = simlockinfo();             break;
     case OPT_SENDDTMF:              rc = senddtmf(optarg);          break;
-#endif /* UCLINUX */
     case OPT_RESET:                 rc = reset(nargc,nargv);        break;
-#ifndef UCLINUX
     case OPT_GETOPERATORNAME:       rc = getoperatorname();         break;
     case OPT_SETOPERATORNAME:       rc = setoperatorname(nargc,nargv);break;
     case OPT_GETWAPBOOKMARK:        rc = getwapbookmark(nargc,nargv);break;
@@ -1410,11 +1289,7 @@ int main(int argc, char *argv[])
     case OPT_GETVOICEMAILBOX:       rc = getvoicemailbox();         break;
     case OPT_NM_COLLECT:            rc = nm_collect(nargc, nargv);  break;
     case OPT_NETMONITORDATA:        rc = netmonitordata(nargc, nargv);break;
-#endif /* UCLINUX */
 
-#ifdef UCLINUX
-    case OPT_GNOKIID:               rc = gnokiid(nargc, nargv);     break;
-#endif /* UCLINUX */
     default:         fprintf(stderr, _("Unknown option: %d\n"), c); break;
 
     }
@@ -1429,12 +1304,144 @@ int main(int argc, char *argv[])
   exit(-1);
 }
 
-#ifndef UCLINUX
-
 /* Restores various phone settings from one file */
 int restoresettings(char *argv[])
 {
-  fprintf(stdout,_("Work in progress. Not usefull now. Sorry\n"));
+  GSM_Backup Backup;
+  GSM_PhonebookEntry pbk;
+
+  int confirm;
+  char ans[4];
+
+  int i,pos;
+
+  GSM_MemoryStatus SIMMemoryStatus = {GMT_SM, 0, 0};
+  GSM_MemoryStatus PhoneMemoryStatus = {GMT_ME, 0, 0};
+
+  if (GSM_ReadBackupFile(argv[0], &Backup)!=GE_NONE) return 1;
+
+  fbusinit(NULL);
+
+  if (Backup.SIMPhonebookUsed!=0) {
+    confirm=-1;    
+    while (confirm < 0) {
+      fprintf(stderr, _("Restore SIM phonebook ? "));
+      GetLine(stdin, ans, 99);
+      if (!strcmp(ans, "yes")) confirm = 1;
+      if (!strcmp(ans, "no" )) confirm = 0;
+    }
+    if (confirm==1) {
+      if (GSM->GetMemoryStatus(&SIMMemoryStatus) != GE_NONE) {
+        fprintf(stderr,_("Error getting memory status !\n"));
+        GSM->Terminate();
+      }
+      i=0;pos=1;
+
+      while ((pos-1)!=SIMMemoryStatus.Used+SIMMemoryStatus.Free) {
+        pbk.Location=pos;
+        pbk.MemoryType=GMT_SM;
+        pbk.Name[0]=0;
+        pbk.Number[0]=0;
+        pbk.SubEntriesCount = 0;
+        if (i<Backup.SIMPhonebookUsed) {
+          if (Backup.SIMPhonebook[i].Location==pbk.Location) {
+            pbk=Backup.SIMPhonebook[i];
+            i++;
+//#ifdef DEBUG
+//            fprintf(stdout,_("Copying from backup\n"));
+//#endif
+          }
+        }
+//#ifdef DEBUG
+//        fprintf(stdout,_("Setting location %i\n"),pbk.Location);
+//#endif
+        GSM->WritePhonebookLocation(&pbk);
+       fprintf(stderr,_("."));
+        pos++;
+      }
+      fprintf(stderr,_("\n"));
+    }
+  }
+  if (Backup.PhonePhonebookUsed!=0) {
+    confirm=-1;    
+    while (confirm < 0) {
+      fprintf(stderr, _("Restore phone phonebook ? "));
+      GetLine(stdin, ans, 99);
+      if (!strcmp(ans, "yes")) confirm = 1;
+      if (!strcmp(ans, "no" )) confirm = 0;
+    }
+    if (confirm==1) {
+      if (GSM->GetMemoryStatus(&PhoneMemoryStatus) != GE_NONE) {
+        fprintf(stderr,_("Error getting memory status !\n"));
+        GSM->Terminate();
+      }
+
+      i=0;pos=1;
+
+      while ((pos-1)!=PhoneMemoryStatus.Used+PhoneMemoryStatus.Free) {
+        pbk.Location=pos;
+        pbk.MemoryType=GMT_ME;
+        pbk.Name[0]=0;
+        pbk.Number[0]=0;
+        pbk.SubEntriesCount = 0;
+        if (i<Backup.PhonePhonebookUsed) {
+          if (Backup.PhonePhonebook[i].Location==pbk.Location) {
+            pbk=Backup.PhonePhonebook[i];
+            i++;
+//#ifdef DEBUG
+//            fprintf(stdout,_("Copying from backup\n"));
+//#endif
+          }
+        }
+//#ifdef DEBUG
+//        fprintf(stdout,_("Setting location %i\n"),pbk.Location);
+//#endif
+        GSM->WritePhonebookLocation(&pbk);
+       fprintf(stderr,_("."));
+        pos++;
+      }
+      fprintf(stderr,_("\n"));
+    }
+  }
+  if (Backup.CallerAvailable==true) {
+    confirm=-1;    
+    while (confirm < 0) {
+      fprintf(stderr, _("Restore caller groups ? "));
+      GetLine(stdin, ans, 99);
+      if (!strcmp(ans, "yes")) confirm = 1;
+      if (!strcmp(ans, "no" )) confirm = 0;
+    }
+    if (confirm==1) {
+      for (i=0;i<5;i++) GSM->SetBitmap(&Backup.CallerGroups[i]);
+    }
+  }
+  if (Backup.OperatorLogoAvailable==true) {
+    confirm=-1;    
+    while (confirm < 0) {
+      fprintf(stderr, _("Restore operator logo ? "));
+      GetLine(stdin, ans, 99);
+      if (!strcmp(ans, "yes")) confirm = 1;
+      if (!strcmp(ans, "no" )) confirm = 0;
+    }
+    if (confirm==1) {
+      GSM->SetBitmap(&Backup.OperatorLogo);
+    }
+  }
+  if (Backup.StartupLogoAvailable==true) {
+    confirm=-1;    
+    while (confirm < 0) {
+      fprintf(stderr, _("Restore startup logo ? "));
+      GetLine(stdin, ans, 99);
+      if (!strcmp(ans, "yes")) confirm = 1;
+      if (!strcmp(ans, "no" )) confirm = 0;
+    }
+    if (confirm==1) {
+      GSM->SetBitmap(&Backup.StartupLogo);
+    }
+  }
+
+  GSM->Terminate();
+
   return 0;
 }
 
@@ -1453,7 +1460,7 @@ int backupsettings(char *argv[])
 
   fprintf(stderr,_("Backup phonebook from SIM..."));
   Backup.SIMPhonebookUsed=0;
-  if (GSM->GetMemoryStatus(&SIMMemoryStatus) == GE_NONE) {//FIXME
+  if (GSM->GetMemoryStatus(&SIMMemoryStatus) == GE_NONE) {
     Backup.SIMPhonebookSize=SIMMemoryStatus.Used+SIMMemoryStatus.Free;
 
     PbkEntry.MemoryType=GMT_SM;
@@ -1528,11 +1535,10 @@ int backupsettings(char *argv[])
   Backup.OperatorLogoAvailable=true;
   Backup.OperatorLogo.type=GSM_7110OperatorLogo;
   if (GSM->GetBitmap(&Backup.OperatorLogo)!=GE_NONE) {
-    Backup.OperatorLogoAvailable=true;
     Backup.OperatorLogo.type=GSM_OperatorLogo;
     if (GSM->GetBitmap(&Backup.OperatorLogo)!=GE_NONE) {
       Backup.OperatorLogoAvailable=false;
-      fprintf(stderr,_("Error\n"));
+     fprintf(stderr,_("Error\n"));
     } else fprintf(stderr,_("Done\n"));
   } else fprintf(stderr,_("Done\n"));
 
@@ -1574,9 +1580,6 @@ int presskeysequence(char *argv[])
   
   sleep(1);
 
-  /* We need to make sure that the init is finished to avoid interrupted */
-  /* multiframe packets... */
-
   fbusinit(NULL);
   
   for (i=0;i<strlen(argv[0]);i++)
@@ -1640,8 +1643,8 @@ int sendsms(int argc, char *argv[])
   GSM_UDH SMSUDHType=GSM_NoUDH;
 
   struct option options[] = {
-             { "smscno",       required_argument, NULL, '1'},
-             { "smsc",         required_argument, NULL, '2'},
+             { "smscno",       required_argument, NULL, '2'},
+             { "smsc",         required_argument, NULL, '1'},
              { "long",        required_argument, NULL, '3'},
              { "enablevoice",  no_argument,       NULL, '4'},
             { "disablevoice", no_argument,       NULL, '5'},
@@ -1783,7 +1786,7 @@ int sendsms(int argc, char *argv[])
     case GSM_DisableFax:
     case GSM_EnableEmail:
     case GSM_DisableEmail:
-      fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText));
+      fprintf(stdout,_("Warning: saving %i chars\n"),strlen(MultiSMS.SMS[0].MessageText));
       msgnum=1;
       break;
     default:
@@ -1826,8 +1829,8 @@ int savesms(int argc, char *argv[])
   bool interactive=false;
 
   struct option options[] = {
-             { "smscno",       required_argument, NULL, '1'},
-             { "smsc",         required_argument, NULL, '2'},
+             { "smscno",       required_argument, NULL, '2'},
+             { "smsc",         required_argument, NULL, '1'},
              { "long",        required_argument, NULL, '3'},
              { "enablevoice",  no_argument,       NULL, '4'},
             { "disablevoice", no_argument,       NULL, '5'},
@@ -1988,7 +1991,7 @@ int savesms(int argc, char *argv[])
     case GSM_DisableFax:
     case GSM_EnableEmail:
     case GSM_DisableEmail:
-      fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText));
+      fprintf(stdout,_("Warning: saving %i chars\n"),strlen(MultiSMS.SMS[0].MessageText));
       msgnum=1;
       break;
     default:
@@ -2120,11 +2123,8 @@ int getsms(int argc, char *argv[])
      int i;
      
      /* [end] can be only argv[4] */
-     if (argv[4][0] == '-') {
-        end_message = start_message;
-     } else {
-        end_message = atoi(argv[4]);
-     }
+     if (argv[4][0] == '-') { end_message = start_message; }
+                       else { end_message = atoi(argv[4]); }
 
      /* parse all options (beginning with '-' */
      while ((i = getopt(argc, argv, "f:")) != -1) {
@@ -2183,16 +2183,12 @@ int getsms(int argc, char *argv[])
           switch (message.Status)
           {
            case  GSS_SENTREAD:
-                if (message.folder==0) //GST_INBOX
-                 fprintf(stdout, _("(read)\n"));
-                else
-                 fprintf(stdout, _("(sent)\n"));
+                if (message.folder==0) fprintf(stdout, _("(read)\n")); //GST_INBOX
+                                  else fprintf(stdout, _("(sent)\n"));
                break;
            case  GSS_NOTSENTREAD:
-                if (message.folder==0) //GST_INBOX
-                 fprintf(stdout, _("(unread)\n"));
-                else
-                 fprintf(stdout, _("(not sent)\n"));
+                if (message.folder==0) fprintf(stdout, _("(unread)\n")); //GST_INBOX
+                                  else fprintf(stdout, _("(not sent)\n"));
                break;
            case  GSS_UNKNOWN:
                fprintf(stdout, _("(not known :-()\n"));
@@ -2245,16 +2241,12 @@ int getsms(int argc, char *argv[])
          switch (message.Status)
            {
            case  GSS_SENTREAD:
-                if (message.folder==0) //GST_INBOX
-                 fprintf(stdout, _("(read)\n"));
-                else
-                 fprintf(stdout, _("(sent)\n"));
+                if (message.folder==0) fprintf(stdout, _("(read)\n")); //GST_INBOX
+                                  else fprintf(stdout, _("(sent)\n"));
                break;
            case  GSS_NOTSENTREAD:
-                if (message.folder==0) //GST_INBOX
-                 fprintf(stdout, _("(unread)\n"));
-                else
-                 fprintf(stdout, _("(not sent)\n"));
+                if (message.folder==0) fprintf(stdout, _("(unread)\n")); //GST_INBOX
+                                  else fprintf(stdout, _("(not sent)\n"));
                break;
             case  GSS_UNKNOWN:
                 fprintf(stdout, _("(not known :-()\n"));
@@ -2837,10 +2829,8 @@ int dialvoice(char *Number)
   return 0;
 }
 
-#endif /* UCLINUX */
-
 /* Cancel a call */
-static int cancelcall(void)
+int cancelcall(void)
 {
   fbusinit(NULL);
 
@@ -2851,8 +2841,6 @@ static int cancelcall(void)
   return 0;
 }
 
-#ifndef UCLINUX
-
 int savelogo(int argc, char *argv[])
 {
   GSM_Bitmap bitmap;
@@ -3277,7 +3265,7 @@ int setlogo(int argc, char *argv[])
           bitmap.type=GSM_StartupLogo;
           bitmap.width=84;
           bitmap.height=48;
-         bitmap.size=bitmap.width*bitmap.height/8;
+         bitmap.size=GSM_GetBitmapSize(&bitmap);
           num=argv[1][0]-'0';
           if (num>=1 && num<=3) {
            bitmap.number=num;
@@ -3391,7 +3379,7 @@ int setlogo(int argc, char *argv[])
          strncpy(bitmap.netcode,"000 00",7);
          bitmap.width=72;
          bitmap.height=14;
-         bitmap.size=bitmap.width*bitmap.height/8;
+         bitmap.size=GSM_GetBitmapSize(&bitmap);
          GSM_ClearBitmap(&bitmap);
        }
         if (!strcmp(argv[0],"7110op"))
@@ -3400,7 +3388,7 @@ int setlogo(int argc, char *argv[])
          strncpy(bitmap.netcode,"000 00",7);
          bitmap.width=78;
          bitmap.height=21;
-          bitmap.size=(bitmap.width*bitmap.height + 7)/8;
+          bitmap.size=GSM_GetBitmapSize(&bitmap);
          GSM_ClearBitmap(&bitmap);
        }
        /* FIX ME: how to remove startup and group logos ? */
@@ -3461,7 +3449,7 @@ int setlogo(int argc, char *argv[])
                        } else {
                          GSM->SetBitmap(&bitmap);
                          GSM->GetBitmap(&oldbit);
-                         fprintf(stderr, _("too long, truncated to \"%s\" (length %ld)\n"),oldbit.text,(long)strlen(oldbit.text));
+                         fprintf(stderr, _("too long, truncated to \"%s\" (length %i)\n"),oldbit.text,strlen(oldbit.text));
                        }
                         ok=false;
                      }
@@ -4113,89 +4101,6 @@ int monitormode(int argc, char *argv[])
   return 0;
 }
 
-#endif /* UCLINUX */
-
-/* Emulation of separate gnokiid binary for uClinux */
-
-#ifdef UCLINUX
-
-#define NICE_LEVEL (-20)
-
-static void gnokiid_SIGCHLD(int signo)
-{
-       fprintf (stderr, _("Child process exited, aborting...\n"));
-       exit(2);
-}
-
-static int gnokiid(int argc, char *argv[])
-{
-       bool    DebugMode;  /* When true, run in debug mode */
-       char    *Model;   /* Model from .gnokiirc file. */
-       char    *Port;    /* Port from .gnokiirc file */
-       char    *Initlength;  /* Init length from .gnokiirc file */
-       char    *Connection;  /* Connection type from .gnokiirc file */
-       char    *BinDir;  /* Directory of the mgnokiidev command */
-
-       /* evaluate for presence of "--debug" argument in parameter */
-       DebugMode = false;
-       if(argc>0)
-       {
-               if( !strcmp(argv[0],"--debug" ))
-               {
-                       DebugMode = true;
-                       argv++;
-                       argc--;
-               }
-       }
-
-#ifdef DEBUG
-  fprintf (stderr, _("Initializing gnokiid mode...\n"));
-#endif
-
-       if (CFG_ReadConfig(&Model, &Port, &Initlength, &Connection, &BinDir, true) < 0)
-               return(-1);
-
-  if (VM_Initialise(Model, Port, Initlength, GCT_FBUS, BinDir, DebugMode, true, ""/*SynchronizeTime*/) == false)
-               return (-1);
-
-       if (argc>0) {
-#ifdef DEBUG
-               fprintf (stderr, _("Spawning gnokiid startup child process \"%s\"...\n"), *argv);
-#endif
-               signal(SIGCHLD,gnokiid_SIGCHLD);
-               errno=0;
-               switch (vfork()) {
-                       case -1: /* vfork() failure */
-                               fprintf (stderr, _("vfork() failed! (%s)\n"),strerror(errno));
-                               return -1;
-                       case 0: /* child */
-                               execv(*argv,argv);
-                               fprintf (stderr, _("Spawn of child process failed! (%s)\n"),strerror(errno));
-                               _exit(9);
-                               break;
-                       default: /* parent */
-                               /* PASSTHRU */
-                               break;
-                       }
-               }
-
-#ifdef DEBUG
-  fprintf (stderr, _("Entering gnokiid virtual modem main loop...\n"));
-#endif
-       if (nice(NICE_LEVEL))
-               fprintf (stderr, _("WARNING: nice level change failed (by %d)\n"),NICE_LEVEL);
-
-       VM_ThreadLoop();
-
-       VM_Terminate();
-
-  return 0;
-}
-
-#endif /* UCLINUX */
-
-#ifndef UCLINUX
-
 /* Shows texts from phone's display */
 
 int displayoutput()
@@ -4680,12 +4585,10 @@ int setprofile(int argc, char *argv[])
 
 }
 
-#endif /* UCLINUX */
-
 /* Get requested range of memory storage entries and output to stdout in
    easy-to-parse format */
 
-static int getmemory(int argc, char *argv[])
+int getmemory(int argc, char *argv[])
 {
 
   GSM_PhonebookEntry entry;
@@ -4713,7 +4616,6 @@ static int getmemory(int argc, char *argv[])
     fprintf(stderr, _("Unknown memory type %s!\n"), argv[0]);
     return (-1);
   }
-
   GetMemoryTypeString(memory_type_string, &entry.MemoryType);
 
   if (argv[argc-1][0] == '-')
@@ -4761,7 +4663,6 @@ static int getmemory(int argc, char *argv[])
        i_used++;
       else if (do_all)
        break;
-#ifndef UCLINUX
       if (output_opt && !strcmp( output_opt,"-v30")) {
        semicolon_pipe_substitution( &entry, 0 );
         fprintf(stdout,_("%s"),GSM_GetVCARD(&entry,30));
@@ -4777,7 +4678,6 @@ static int getmemory(int argc, char *argv[])
         fprintf(stdout,_("%s"),GSM_GetVCARD(&entry,10));
        formatdone=true;
       } 
-#endif /* UCLINUX */
       if (output_opt && !strcmp(output_opt,"-short")) {
         semicolon_pipe_substitution( &entry, 0 );
         fprintf(stdout, "%s;%s;%s;%d;%d;", entry.Name, entry.Number, memory_type_string, entry.Location, entry.Group);
@@ -4920,7 +4820,7 @@ static int getmemory(int argc, char *argv[])
 /* Read data from stdin, parse and write to phone.  The parsing is relatively
    crude and doesn't allow for much variation from the stipulated format. */
 
-static int writephonebook(int argc, char *args[])
+int writephonebook(int argc, char *args[])
 {
 
   GSM_PhonebookEntry entry;
@@ -5136,7 +5036,7 @@ static int writephonebook(int argc, char *args[])
 
 /* Getting speed dials. */
 
-static int getspeeddial(char *Number) {
+int getspeeddial(char *Number) {
 
   GSM_SpeedDial entry;
   GSM_Error error;
@@ -5169,7 +5069,7 @@ static int getspeeddial(char *Number) {
 
 /* Setting speed dials. */
 
-static int setspeeddial(char *argv[]) {
+int setspeeddial(char *argv[]) {
 
   GSM_SpeedDial entry;
 
@@ -5205,8 +5105,6 @@ static int setspeeddial(char *argv[]) {
   return 0;
 }
 
-#ifndef UCLINUX
-
 /* Getting the status of the display. */
 
 int getdisplaystatus()
@@ -5266,42 +5164,29 @@ int netmonitor(char *Mode)
   return 0;
 }
 
-#endif /* UCLINUX */
-
-static int identify( void )
+int identify( void )
 {
   /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */
   char imei[64], model[64], rev[64], manufacturer[64];
 
-  LIVE;
   fbusinit(NULL);
 
-  LIVE;
   while (GSM->GetIMEI(imei)    != GE_NONE) sleep(1);
-  LIVE;
   while (GSM->GetRevision(rev) != GE_NONE) sleep(1);
-  LIVE;
   while (GSM->GetModel(model)  != GE_NONE) sleep(1);
-  LIVE;
 
   strcpy(manufacturer, "(unknown)");
-  LIVE;
   GSM->GetManufacturer(manufacturer);
-  LIVE;
 
   fprintf(stdout, _("IMEI:     %s\n"), imei);
   fprintf(stdout, _("Model:    %s %s (%s)\n"), manufacturer, GetModelName (model), model);
   fprintf(stdout, _("Revision: %s\n"), rev);
 
-  LIVE;
   GSM->Terminate();
-  LIVE;
 
   return 0;
 }
 
-#ifndef UCLINUX
-
 int senddtmf(char *String)
 {
 
@@ -5314,10 +5199,8 @@ int senddtmf(char *String)
   return 0;
 }
 
-#endif /* UCLINUX */
-
 /* Resets the phone */
-static int reset(int argc, char *argv[])
+int reset(int argc, char *argv[])
 {
 
   unsigned char _type=0x03;
@@ -5345,8 +5228,6 @@ static int reset(int argc, char *argv[])
   return 0;
 }
 
-#ifndef UCLINUX
-
 /* This is a "convenience" function to allow quick test of new API stuff which
    doesn't warrant a "proper" command line function. */
 
@@ -5390,7 +5271,7 @@ int pmon()
 
   /* Initialise the code for the GSM interface. */     
 
-  error = GSM_Initialise(model, Port, Initlength, connection, RLP_DisplayF96Frame, ""/*SynchronizeTime*/);
+  error = GSM_Initialise(model, Port, Initlength, connection, RLP_DisplayF96Frame, SynchronizeTime);
 
   if (error != GE_NONE) {
     fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
@@ -7659,53 +7540,34 @@ int getringtone(int argc, char *argv[])
   GSM_Error error;
   GSM_Ringtone SMringtone;
 
-  int i;
-  
-  char model[64];
-
-  FILE *file;
-
   ringtone.location=1;
   if (argc>1) ringtone.location=atoi(argv[1]);
 
   /* Initialise the GSM interface. */
   fbusinit(NULL);
 
-  error=GSM->GetBinRingtone(&ringtone);
-
-  while (GSM->GetModel(model)  != GE_NONE)
-    sleep(1);
-
-  GSM->Terminate();
+  error=GSM_GetPhoneRingtone(&ringtone,&SMringtone);
 
   fprintf(stdout, _("Downloaded ringtone, location %i: "),ringtone.location);
   
   switch (error) {
     case GE_NONE:
       fprintf(stdout, _("get succeeded!\n"));
-      fprintf(stdout, _("Name: %s (binary format)\n"),ringtone.name);
+      /* In 33.. we have normal "Smart Messaging" format */
+      if (GetModelFeature (FN_RINGTONES)==F_RING_SM) {
+        fprintf(stdout, _("Name: %s (normal format)\n"),SMringtone.name);
+        GSM_SaveRingtoneFileOnConsole(argv[0], &SMringtone);   
+      } else {
+        fprintf(stdout, _("Name: %s (binary format)\n"),ringtone.name);
+        GSM_SaveBinRingtoneFile(argv[0], &ringtone);
+      }
+      GSM->Terminate();
+      return 0;
       break;
     case GE_INVALIDRINGLOCATION:
       fprintf(stdout, _("invalid location %i!\n"),ringtone.location);
       break;
     case GE_UNKNOWNMODEL:
-    
-      /* In 3310 we have normal "Smart Messaging" format */
-      if (GetModelFeature (FN_RINGTONES)==F_RING_SM) {
-      
-        i=7;
-       if (ringtone.frame[9]==0x4a && ringtone.frame[10]==0x3a) i=8;
-       ringtone.frame[i]=0x02;
-       
-        GSM_UnPackRingtone(&SMringtone, ringtone.frame+i, ringtone.length-i);
-
-        fprintf(stdout, _("Name: %s (normal format)\n"),SMringtone.name);
-
-        GSM_SaveRingtoneFileOnConsole(argv[0], &SMringtone);
-       
-       return 0;
-      }
-
       fprintf(stdout, _("mygnokii doesn't know format for this model!\n"));
       break;
     case GE_NOTIMPLEMENTED:
@@ -7715,21 +7577,10 @@ int getringtone(int argc, char *argv[])
       fprintf(stdout, _("not supported by this model!\n"));
       break;
   }
-  
-  if (error!=GE_NONE)
-    return(-1);
-  
-  file = fopen(argv[0], "wb");
-      
-  if (!file)
-    return(GE_CANTOPENFILE);
 
-  fwrite(ringtone.frame, 1, ringtone.length, file);    
-  
-  fclose(file);
+  GSM->Terminate();
   
-  return 0;
-
+  return(-1);
 }
 
 int binringtoneconvert(int argc, char *argv[])
@@ -7801,32 +7652,32 @@ int binringtoneconvert(int argc, char *argv[])
            w=w*2;
            if (w>z && (w/2)<=z) {
              switch (m) {
-               case 1:fprintf(file,_("16"));break;
-               case 2:fprintf(file,_("8"));break;
-               case 3:fprintf(file,_("4"));break;
-               case 4:fprintf(file,_("2"));break;
-               case 5:fprintf(file,_("1"));break;
+               case 1:fprintf(file,_("16"));break;\r
+               case 2:fprintf(file,_("8"));break;\r
+               case 3:fprintf(file,_("4"));break;\r
+               case 4:fprintf(file,_("2"));break;\r
+               case 5:fprintf(file,_("1"));break;\r
              }
              break;
            }
          }
          if (z>w) fprintf(file,_("1"));
          pause=false;
-          switch (GSM_GetNote(j)) {
-            case Note_C  :fprintf(file,_("c"));break;
-            case Note_Cis:fprintf(file,_("c#"));break;
-            case Note_D  :fprintf(file,_("d"));break;
-            case Note_Dis:fprintf(file,_("d#"));break;
-            case Note_E  :fprintf(file,_("e"));break;
-            case Note_F  :fprintf(file,_("f"));break;
-            case Note_Fis:fprintf(file,_("f#"));break;
-            case Note_G  :fprintf(file,_("g"));break;
-            case Note_Gis:fprintf(file,_("g#"));break;
-            case Note_A  :fprintf(file,_("a"));break;
-            case Note_Ais:fprintf(file,_("a#"));break;
-            case Note_H  :fprintf(file,_("h"));break;
-            default      :pause=true;fprintf(file,_("p"));break; //Pause ?
-          }
+          switch (GSM_GetNote(j)) {\r
+            case Note_C  :fprintf(file,_("c"));break;\r
+            case Note_Cis:fprintf(file,_("c#"));break;\r
+            case Note_D  :fprintf(file,_("d"));break;\r
+            case Note_Dis:fprintf(file,_("d#"));break;\r
+            case Note_E  :fprintf(file,_("e"));break;\r
+            case Note_F  :fprintf(file,_("f"));break;\r
+            case Note_Fis:fprintf(file,_("f#"));break;\r
+            case Note_G  :fprintf(file,_("g"));break;\r
+            case Note_Gis:fprintf(file,_("g#"));break;\r
+            case Note_A  :fprintf(file,_("a"));break;\r
+            case Note_Ais:fprintf(file,_("a#"));break;\r
+            case Note_H  :fprintf(file,_("h"));break;\r
+            default      :pause=true;fprintf(file,_("p"));break; //Pause ?\r
+          }\r
          w=deflen*1.5;
          for (m=0;m<6;m++) {
            w=w*2;
@@ -7886,13 +7737,11 @@ int renamesmsc(int argc, char *argv[])
   return 0;
 }
 
-#endif /* UCLINUX */
-
 /*
  * Returns number of sostituited characters.
  * ... may be useful one day ??
  */
-static int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction )
+int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction )
        /* direction = 0 : after reading phone memory (
         *             1 : writing phone memory
         */
@@ -7928,10 +7777,6 @@ int str_substch( char *str, const char toric, const char sost )
        return( i_sost );
 }                                                                               
 
-#ifndef UCLINUX
-
-extern GSM_Error N6110_EnableExtendedCommands (unsigned char status);
-
 /* Allows to set simlock state.
    With older phone (older 51xx, 61xx) can open them, with older
    and newer should be able to close them */
@@ -7971,11 +7816,11 @@ int setsimlock()
     fprintf(stderr,_("Error getting simlock info\n"));GSM->Terminate();return -1;
   }
   /* Opening all locks (we must check, if we can open them) */
-  NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer0);
-  openbuffer[4]=1;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=2;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=4;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=8;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer0);
+  openbuffer[4]=1;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=2;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=4;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=8;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
   if (GSM->SimlockInfo(&siml)!=GE_NONE) {
     fprintf(stderr,_("Error getting simlock info\n"));GSM->Terminate();return -1;
   }
@@ -8024,13 +7869,13 @@ int setsimlock()
   }  
   /* Closing simlock with given values */
   closebuffer[4]=1+2+4+8;
-  NULL_SendMessageSequence(50, &CurrentMagicError, 20, 0x40,closebuffer);  
+  NULL_SendMessageSequence\r(50, &CurrentMagicError, 20, 0x40,closebuffer);  
   /* Opening all locks */
-  NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer0);
-  openbuffer[4]=1;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=2;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=4;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
-  openbuffer[4]=8;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer0);
+  openbuffer[4]=1;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=2;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=4;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
+  openbuffer[4]=8;NULL_SendMessageSequence\r(50, &CurrentMagicError, 10, 0x40,openbuffer);
   GSM->Reset(0x03);
   GSM->Terminate();
   return 0;
@@ -8130,7 +7975,7 @@ int geteeprom()
     
     if ((i/256)!=((i-1)/256)) fprintf(stderr,_("."));
     
-    if (NULL_SendMessageSequence(50, &CurrentMagicError, 9, 0x40,buffer)!=GE_NONE)       break;
+    if (NULL_SendMessageSequence(50, &CurrentMagicError, 9, 0x40,buffer)!=GE_NONE)\r      break;
 
     i=i+0x10;
   }
@@ -8931,12 +8776,9 @@ int savephonebookentry(int argc, char *argv[])
     case GE_NONE:
 
       /* Put entry into SMS structure */
-#ifndef UCLINUX
-      if (GetModelFeature(FN_PHONEBOOK)==F_PBK71) {
+      if (GetModelFeature(FN_PHONEBOOK)==F_PBK71INT) {
         GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,21);
-      } else
-#endif /* UCLINUX */
-                               {
+      } else {
         GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,10);
       }
 
@@ -8979,7 +8821,7 @@ int sendphonebookentry(int argc, char *argv[])
     case GE_NONE:
 
       /* Put entry into SMS structure */
-      if (GetModelFeature(FN_PHONEBOOK)==F_PBK71) {
+      if (GetModelFeature(FN_PHONEBOOK)==F_PBK71INT) {
         GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,21);
       } else {
         GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,10);
@@ -8999,4 +8841,74 @@ int sendphonebookentry(int argc, char *argv[])
   return 0;
 }
 
-#endif /* UCLINUX */
+#ifdef DEBUG
+int getbinringfromfile(int argc, char *argv[])
+{
+  FILE *file;
+  int i,j;
+  bool found;
+  GSM_BinRingtone binring,ringtone;
+
+  fprintf(stdout,_("Offset %ld\n"),atol(argv[2]));
+
+  file = fopen(argv[0], "rb");
+
+  if (!file) return(GE_CANTOPENFILE);
+
+  fseek(file,atol(argv[2]),0);
+  
+  ringtone.length=fread(ringtone.frame, 1, 900, file);
+
+  fclose(file);
+
+  i=0;found=false;
+  while (true) {
+    if (ringtone.frame[i  ]==0x00 && ringtone.frame[i+1]==0x02 && 
+        ringtone.frame[i+2]==0xFC && ringtone.frame[i+3]==0x09) {
+      found=true;
+      break;
+    }
+    i++;
+    if (i==ringtone.length-3) break;
+  }
+
+  if (!found) {
+    fprintf(stdout,_("Start not found\n"));
+    return (-1);
+  }
+
+  j=0;found=false;
+  while (true) {
+    if (ringtone.frame[j]==0x07 && ringtone.frame[j+1]==0x0B) {
+      found=true;
+      break;
+    }
+    j++;
+    if (j==ringtone.length-2) break;
+  }
+
+  if (!found) {
+    fprintf(stdout,_("End not found\n"));
+    return (-1);
+  }
+
+  binring.length=0;
+  binring.frame[binring.length++]=0x00;
+  binring.frame[binring.length++]=0x00;
+  binring.frame[binring.length++]=0x0C;
+  binring.frame[binring.length++]=0x01;
+  binring.frame[binring.length++]=0x2C;
+  
+  memcpy(binring.frame+binring.length,argv[1],strlen(argv[1]));
+  binring.length=binring.length+strlen(argv[1]);
+
+  binring.frame[binring.length++]=0x00;
+
+  memcpy(binring.frame+binring.length,ringtone.frame+i,j-i+2);
+  binring.length=binring.length+j-i+2;
+
+  GSM_SaveBinRingtoneFile(argv[3], &binring); 
+
+  return GE_NONE;
+}
+#endif