5 A Linux/Unix toolset and driver for Nokia mobile phones.
7 Released under the terms of the GNU GPL, see file COPYING for more details.
9 Mainline code for gnokii utility. Handles command line parsing and
10 reading/writing phonebook entries and other stuff.
27 /* <getopt.h> or "getopt.h" would include insufficient getopt.h from uClinux */
28 #include "../getopt/getopt.h"
32 #if defined(__svr4__) || defined(__FreeBSD__)
33 # include <strings.h> /* for bzero */
36 /* for VC6 make scripts save VERSION constant in mversion.h file */
44 #include "misc_win32.h"
47 #define DEV_CONSOLE "CON:"
54 #include <sys/types.h>
58 #define DEV_CONSOLE "/dev/tty"
62 #include "gsm-common.h"
64 #include "gsm-networks.h"
66 #include "gsm-ringtones.h"
67 #include "gsm-bitmaps.h"
70 #include "gsm-datetime.h"
72 #include "gsm-phonebook.h"
74 #include "gsm-calendar.h"
76 #include "gsm-coding.h"
78 #include "newmodules/n6110.h"
80 #include "files/cfgreader.h"
82 #include "files/gsm-filetypes.h"
86 #include "data/virtmodem.h"
93 static char *model; /* Model from .gnokiirc file. */
94 static char *Port; /* Port from .gnokiirc file */
95 static char *Initlength; /* Init length from .gnokiirc file */
96 static char *Connection; /* Connection type from .gnokiirc file */
98 char *SynchronizeTime; /* If we set date and time from computer to phone (from .gnokiirc file) */
100 static char *BinDir; /* Binaries directory from .gnokiirc file - not used here yet */
103 static GSM_SMSMessage SMS[4];
108 char *GetProfileCallAlertString(int code) {
111 case PROFILE_CALLALERT_RINGING : return "Ringing";
112 case PROFILE_CALLALERT_ASCENDING : return "Ascending";
113 case PROFILE_CALLALERT_RINGONCE : return "Ring once";
114 case PROFILE_CALLALERT_BEEPONCE : return "Beep once";
115 case PROFILE_CALLALERT_CALLERGROUPS: return "Caller groups";
116 case PROFILE_CALLALERT_OFF : return "Off";
117 default : return "Unknown";
121 char *GetProfileVolumeString(int code) {
124 case PROFILE_VOLUME_LEVEL1 : return "Level 1";
125 case PROFILE_VOLUME_LEVEL2 : return "Level 2";
126 case PROFILE_VOLUME_LEVEL3 : return "Level 3";
127 case PROFILE_VOLUME_LEVEL4 : return "Level 4";
128 case PROFILE_VOLUME_LEVEL5 : return "Level 5";
129 default : return "Unknown";
133 char *GetProfileKeypadToneString(int code) {
136 case PROFILE_KEYPAD_OFF : return "Off";
137 case PROFILE_KEYPAD_LEVEL1 : return "Level 1";
138 case PROFILE_KEYPAD_LEVEL2 : return "Level 2";
139 case PROFILE_KEYPAD_LEVEL3 : return "Level 3";
140 default : return "Unknown";
144 char *GetProfileMessageToneString(int code) {
147 case PROFILE_MESSAGE_NOTONE : return "No tone";
148 case PROFILE_MESSAGE_STANDARD : return "Standard";
149 case PROFILE_MESSAGE_SPECIAL : return "Special";
150 case PROFILE_MESSAGE_BEEPONCE : return "Beep once";
151 case PROFILE_MESSAGE_ASCENDING : return "Ascending";
152 default : return "Unknown";
156 char *GetProfileWarningToneString(int code) {
159 case PROFILE_WARNING_OFF : return "Off";
160 case PROFILE_WARNING_ON : return "On";
161 default : return "Unknown";
165 char *GetProfileOnOffString(int code) {
168 case 0x00 : return "Off";
169 case 0x01 : return "On";
170 default : return "Unknown";
174 static char *GetProfileVibrationString(int code)
177 case PROFILE_VIBRATION_OFF: return "Off";
178 case PROFILE_VIBRATION_ON: return "On";
179 case PROFILE_VIBRATION_FIRST: return "Vibrate first";
180 default: return "Unknown";
184 char BufferProfileGroups[90];
186 char *GetProfileCallerGroups(int code)
188 static char az_group_name[5][MAX_BITMAP_TEXT_LENGTH];
189 static bool enteronce=false;
193 if( code == PROFILE_CALLERGROUPS_ALL )
194 return _("All calls alert");
197 for(i=0;i<5;i++) az_group_name[i][0]='\0';
201 BufferProfileGroups[0]=0;
208 code2test=(i==0) ? 1 : 2<<(i-1);
210 if( code & code2test )
212 if (!strcmp(az_group_name[i],""))
214 if (GetModelFeature (FN_CALLERGROUPS)!=0) {
215 bitmap.type=GSM_CallerLogo;
217 strcpy(z_gtype,_("unknown"));
218 if (GSM->GetBitmap(&bitmap)==GE_NONE)
219 strcpy( az_group_name[i], bitmap.text );
221 if ((!strcmp(az_group_name[i],""))) {
223 case 0:strcpy(az_group_name[i],_("Family"));break;
224 case 1:strcpy(az_group_name[i],_("VIP"));break;
225 case 2:strcpy(az_group_name[i],_("Friends"));break;
226 case 3:strcpy(az_group_name[i],_("Colleagues"));break;
227 case 4:strcpy(az_group_name[i],_("Other"));break;
232 strcpy(z_gtype,az_group_name[i]);
234 if( strlen(BufferProfileGroups) ) strcat(BufferProfileGroups,"+");
235 strcat(BufferProfileGroups, z_gtype);
240 return BufferProfileGroups;
243 static char *print_error(GSM_Error e)
246 // case GE_DEVICEOPENFAILED: return "Couldn't open specified serial device.";
247 // case GE_UNKNOWNMODEL: return "Model specified isn't known/supported.";
248 // case GE_NOLINK: return "Couldn't establish link with phone.";
249 // case GE_TRYAGAIN: return "Try again.";
250 // case GE_INVALIDSMSLOCATION: return "Invalid SMS location.";
251 // case GE_INVALIDPHBOOKLOCATION: return "Invalid phonebook location.";
252 // case GE_INVALIDMEMORYTYPE: return "Invalid type of memory.";
253 // case GE_INVALIDSPEEDDIALLOCATION: return "Invalid speed dial location.";
254 // case GE_INVALIDCALNOTELOCATION: return "Invalid calendar note location.";
255 // case GE_INVALIDDATETIME: return "Invalid date, time or alarm specification.";
256 // case GE_EMPTYSMSLOCATION: return "SMS location is empty.";
257 // case GE_PHBOOKNAMETOOLONG: return "Phonebook name is too long.";
258 // case GE_PHBOOKNUMBERTOOLONG: return "Phonebook number is too long.";
259 // case GE_PHBOOKWRITEFAILED: return "Phonebook write failed.";
260 // case GE_SMSSENDOK: return "SMS was send correctly.";
261 // case GE_SMSSENDFAILED: return "SMS send fail.";
262 // case GE_SMSTOOLONG: return "SMS message too long.";
263 // case GE_NONEWCBRECEIVED: return "Attempt to read CB when no new CB received";
264 // case GE_INTERNALERROR: return "Problem occured internal to model specific code.";
265 // case GE_NOTSUPPORTED: return "Function not supported by the phone";
266 // case GE_BUSY: return "Command is still being executed.";
267 // case GE_USERCANCELED: return "User has cancelled the action.";
268 // case GE_UNKNOWN: return "Unknown error - well better than nothing!!";
269 // case GE_MEMORYFULL: return "Memory is full";
270 // case GE_LINEBUSY: return "Outgoing call requested reported line busy";
271 // case GE_NOCARRIER: return "No Carrier error during data call setup ?";
274 case GE_NONE: return "No error, done OK";
275 case GE_INVALIDSECURITYCODE: return "Invalid Security code.";
276 case GE_NOTIMPLEMENTED: return "Called command is not implemented for the used model. Please contact marcin-wiacek@topnet.pl, if you want to help in implementing it";
277 case GE_TIMEOUT: return "Command timed out.";
278 case GE_CANTOPENFILE: return "Can't open file with bitmap/ringtone";
279 case GE_SUBFORMATNOTSUPPORTED: return "Subformat of file not supported";
280 case GE_WRONGNUMBEROFCOLORS: return "Wrong number of colors in specified bitmap file (only 2 colors files supported)";
281 case GE_WRONGCOLORS: return "Wrong colors in bitmap file";
282 case GE_INVALIDIMAGESIZE: return "Invalid size of bitmap (in file, sms etc.)";
283 case GE_INVALIDFILEFORMAT: return "Invalid format of file";
284 case GE_TOOSHORT: return "File too short";
285 case GE_INSIDEBOOKMARKSMENU: return "Inside WAP Bookmarks menu. Please leave it and try again";
286 case GE_INVALIDBOOKMARKLOCATION: return "Invalid or empty WAP bookmark location";
287 case GE_INSIDESETTINGSMENU: return "Inside WAP Settings menu. Please leave it and try again";
288 case GE_INVALIDSETTINGSLOCATION: return "Invalid or empty WAP settings location";
289 case GE_EMPTYSMSC: return "Empty SMSC number. Use --smsc";
290 default: return "Unknown error.";
294 GSM_Error GSM_ReadRingtoneFileOnConsole(char *FileName, GSM_Ringtone *ringtone)
298 error=GSM_ReadRingtoneFile(FileName, ringtone);
301 case GE_CANTOPENFILE:
302 case GE_SUBFORMATNOTSUPPORTED:
303 fprintf(stderr, _("File \"%s\"\nError: %s\n"),FileName,print_error(error));
312 GSM_Error GSM_SaveRingtoneFileOnConsole(char *FileName, GSM_Ringtone *ringtone)
314 int confirm,confirm2;
319 /* Ask before overwriting */
320 while (stat(FileName, &buf) == 0) {
325 while (confirm < 0) {
326 fprintf(stderr, _("Saving ringtone. File \"%s\" exists. (O)verwrite, create (n)ew or (s)kip ? "),FileName);
327 GetLine(stdin, ans, 4);
328 if (!strcmp(ans, "O") || !strcmp(ans, "o")) confirm = 1;
329 if (!strcmp(ans, "N") || !strcmp(ans, "n")) confirm = 2;
330 if (!strcmp(ans, "S") || !strcmp(ans, "s")) return GE_USERCANCELED;
332 if (confirm==1) break;
334 while (confirm2 < 0) {
335 fprintf(stderr, _("Enter name of new file: "));
336 GetLine(stdin, FileName, 50);
337 if (&FileName[0]==0) return GE_USERCANCELED;
343 error=GSM_SaveRingtoneFile(FileName,ringtone);
346 case GE_CANTOPENFILE: fprintf(stderr, _("Failed to write file \"%s\"\n"),FileName);
354 GSM_Error GSM_ReadBitmapFileOnConsole(char *FileName, GSM_Bitmap *bitmap)
358 error=GSM_ReadBitmapFile(FileName, bitmap);
361 case GE_CANTOPENFILE:
362 case GE_WRONGNUMBEROFCOLORS:
364 case GE_INVALIDFILEFORMAT:
365 case GE_SUBFORMATNOTSUPPORTED:
367 case GE_INVALIDIMAGESIZE:
368 fprintf(stderr, _("File \"%s\"\nError: %s\n"),FileName,print_error(error));
377 GSM_Error GSM_SaveBitmapFileOnConsole(char *FileName, GSM_Bitmap *bitmap)
379 int confirm,confirm2;
384 /* Ask before overwriting */
385 while (stat(FileName, &buf) == 0) {
390 while (confirm < 0) {
391 fprintf(stderr, _("Saving logo. File \"%s\" exists. (O)verwrite, create (n)ew or (s)kip ? "),FileName);
392 GetLine(stdin, ans, 4);
393 if (!strcmp(ans, "O") || !strcmp(ans, "o")) confirm = 1;
394 if (!strcmp(ans, "N") || !strcmp(ans, "n")) confirm = 2;
395 if (!strcmp(ans, "S") || !strcmp(ans, "s")) return GE_USERCANCELED;
397 if (confirm==1) break;
399 while (confirm2 < 0) {
400 fprintf(stderr, _("Enter name of new file: "));
401 GetLine(stdin, FileName, 50);
402 if (&FileName[0]==0) return GE_USERCANCELED;
408 error=GSM_SaveBitmapFile(FileName,bitmap);
411 case GE_CANTOPENFILE: fprintf(stderr, _("Failed to write file \"%s\"\n"),FileName);
419 /* mode == 0 -> overwrite
421 * mode == 2 -> append
423 int GSM_SaveTextFileOnConsole(char *FileName, char *text, int mode)
425 int confirm, confirm2;
430 /* Ask before overwriting */
432 while (stat(FileName, &buf) == 0 && mode==1) {
437 while (confirm < 0) {
438 fprintf(stderr, _("File \"%s\" exists. (O)verwrite, (a)ppend, create (n)ew or (s)kip ? "),FileName);
439 GetLine(stdin, ans, 4);
440 if (!strcmp(ans, "O") || !strcmp(ans, "o")) {
444 if (!strcmp(ans, "A") || !strcmp(ans, "a")) {
448 if (!strcmp(ans, "N") || !strcmp(ans, "n")) confirm=2;
449 if (!strcmp(ans, "S") || !strcmp(ans, "s")) return -1;
453 while (confirm2 < 0) {
454 fprintf(stderr, _("Enter name of new file: "));
455 GetLine(stdin, FileName, 50);
456 if (&FileName[0]==0) return -1;
465 error=GSM_SaveTextFile(FileName, text, mode);
468 case -1: fprintf(stderr, _("Failed to write file \"%s\"\n"), FileName);
476 int GSM_SendMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[],
477 bool unicode, bool profile, bool scale) {
481 struct option options[] = {
482 { "smscno", required_argument, NULL, '2'},
483 { "smsc", required_argument, NULL, '1'},
484 { "name", required_argument, NULL, '3'},
485 { "unicode", no_argument, NULL, '4'},
486 { "profilestyle", no_argument, NULL, '5'},
487 { "scale", no_argument, NULL, '6'},
493 for (w=0;w<MultiSMS->number;w++) {
498 /* We check optional parameters from ... */
501 while ((i = getopt_long(argc, argv, "v:ds", options, NULL)) != -1) {
504 case '1': /* SMSC number */
505 MultiSMS->SMS[w].MessageCenter.No = 0;
506 strcpy(MultiSMS->SMS[w].MessageCenter.Number,optarg);
509 case '2': /* SMSC number index in phone memory */
510 MultiSMS->SMS[w].MessageCenter.No = atoi(optarg);
512 if (MultiSMS->SMS[w].MessageCenter.No < 1 || MultiSMS->SMS[w].MessageCenter.No > 5) {
513 fprintf(stderr, _("Incorrect SMSC number with \"smscno\" option (can't be <1 and >5) !\n"));
519 case '3': /* Receiver/recipient */
520 strncpy(MultiSMS->SMS[w].Destination,optarg,11); break;
522 case '4': /* Unicode */
525 case '5': /* Profile */
528 case '6': /* Scale */
531 case 'v': /* Set validaty of SMS */
532 MultiSMS->SMS[w].Validity = atoi(optarg);
535 case 'd': /* delivery report */
536 MultiSMS->SMS[w].Type=GST_DR;
539 case 's': /* Set replying via the same SMSC */
540 MultiSMS->SMS[w].ReplyViaSameSMSC = true; break;
543 fprintf(stderr,_("Unknown option number %i\n"),argc);
551 error=GSM->SendSMSMessage(&MultiSMS->SMS[w]);
553 if (error == GE_SMSSENDOK) {
554 fprintf(stdout, _("SMS %i/%i sent OK !\n"),w+1,MultiSMS->number);
556 fprintf(stdout, _("SMS %i/%i, sending failed (%d, %s)\n"),w+1,MultiSMS->number, error,print_error(error));
566 static int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[],
567 bool inter, bool unicode, bool profile, bool scale) {
571 GSM_SMSMessage SMSold;
573 struct option options[] = {
574 { "smscno", required_argument, NULL, '2'},
575 { "smsc", required_argument, NULL, '1'},
576 { "name", required_argument, NULL, '3'},
577 { "unicode", no_argument, NULL, '4'},
578 { "profilestyle", no_argument, NULL, '5'},
579 { "scale", no_argument, NULL, '6'},
591 for (w=0;w<MultiSMS->number;w++) {
596 /* We check optional parameters from ... */
599 while ((i = getopt_long(argc, argv, "risal:", options, NULL)) != -1) {
602 case '1': /* SMSC number */
603 MultiSMS->SMS[w].MessageCenter.No = 0;
604 strcpy(MultiSMS->SMS[w].MessageCenter.Number,optarg);
607 case '2': /* SMSC number index in phone memory */
608 MultiSMS->SMS[w].MessageCenter.No = atoi(optarg);
610 if (MultiSMS->SMS[w].MessageCenter.No < 1 || MultiSMS->SMS[w].MessageCenter.No > 5) {
611 fprintf(stderr, _("Incorrect SMSC number with \"smscno\" option (can't be <1 and >5) !\n"));
617 case '3': /* Receiver/recipient */
618 strncpy(MultiSMS->SMS[w].Destination,optarg,11); break;
620 case '4': /* Unicode */
623 case '5': /* Profile */
626 case '6': /* Scale */
629 case 'r': /* mark as read */
630 MultiSMS->SMS[w].Status = GSS_SENTREAD; break;
632 case 'i': /* Save into Inbox */
633 MultiSMS->SMS[w].folder = GST_INBOX; break;
635 case 's': /* Set replying via the same SMSC */
636 MultiSMS->SMS[w].ReplyViaSameSMSC = true; break;
638 case 'a': /* Ask before overwriting */
639 interactive=true;break;
641 case 'l': /* Specify location */
642 MultiSMS->SMS[0].Location = atoi(optarg); break;
645 fprintf(stderr,_("Unknown option number %i\n"),argc);
652 if (interactive && MultiSMS->SMS[0].Location!=0 && w==0) {
653 SMSold.Location=MultiSMS->SMS[0].Location;
654 error = GSM->GetSMSMessage(&SMSold);
657 fprintf(stderr, _("Message at specified location exists. "));
658 while (confirm < 0) {
659 fprintf(stderr, _("Overwrite? (yes/no) "));
660 GetLine(stdin, ans, 7);
661 if (!strcmp(ans, "yes")) confirm = 1;
662 if (!strcmp(ans, "no")) confirm = 0;
664 if (!confirm) { GSM->Terminate(); return 0; }
666 case GE_INVALIDSMSLOCATION:
667 fprintf(stderr, _("Invalid location\n"));
671 /* FIXME: Remove this fprintf when the function is thoroughly tested */
673 fprintf(stderr, _("Location %d empty. Saving\n"), SMS[w].Location);
679 error=GSM->SaveSMSMessage(&MultiSMS->SMS[w]);
681 if (error == GE_NONE)
682 fprintf(stdout, _("SMS %i/%i saved at location %i !\n"),w+1,MultiSMS->number,MultiSMS->SMS[w].MessageNumber);
684 fprintf(stdout, _("SMS %i/%i saving failed (%d, %s, location=%i)\n"), w+1, MultiSMS->number,error,print_error(error),MultiSMS->SMS[w].Location);
692 void GSM_PlayRingtoneOnConsole(GSM_Ringtone *ringtone)
699 for (i=0;i<ringtone->NrNotes;i++) {
706 GSM_PlayOneNote (ringtone->notes[i]);
708 GSM->PlayTone(255*255,0);
713 /* This function shows the copyright and some informations usefull for
715 static int version(void)
718 fprintf(stdout, _("GNOKII Version %s\n"
719 "Copyright (C) Hugh Blemings <hugh@linuxcare.com>, 1999, 2000\n"
720 "Copyright (C) Pavel JanÃk ml. <Pavel.Janik@linux.cz>, 1999, 2000\n"
721 "Built %s %s for %s on %s \n"), VERSION, __TIME__, __DATE__, model, Port);
726 /* The function usage is only informative - it prints this program's usage and
727 command-line options. */
729 static int usage(void)
732 fprintf(stdout, _(" usage: gnokii [--help] [--version]\n"
737 " gnokii --ir <command> [<command args>...]\n"
743 " gnokii --monitor [-noloop|-nl]\n"
749 " gnokii --getmemory memory_type [start [end]] [-short|-v30|-v21|-v]\n"
753 " gnokii --getmemory memory_type [start [end]] [-short]\n"
758 " gnokii --writephonebook [-i]\n"
763 " gnokii --sendphonebookentry destination memory_type location\n"
764 " [--smsc message_center_number] [--smscno message_center_index]\n"
765 " [-s] [-v n] [-d]\n"
766 " gnokii --savephonebookentry memory_type location\n"
767 " [--smsc message_center_number] [--smscno message_center_index]\n"
768 " [-r] [-i] [-s] [-a] [--name name]\n"
769 " gnokii --getvoicemailbox\n"
774 " gnokii --getspeeddial number\n"
775 " gnokii --setspeeddial number memory_type location\n\n"
780 " gnokii --getsms memory_type start [end] [-f file]\n"
781 " gnokii --getsmsstatus\n"
782 " gnokii --getsmsfolders\n"
783 " gnokii --deletesms memory_type start [end]\n"
784 " gnokii --sendsms destination [--smsc message_center_number |\n"
785 " --smscno message_center_index] [--long n] [-s] [-C n]\n"
786 " [--enablevoice|--disablevoice|--enablefax|--disablefax|\n"
787 " --enableemail|--disableemail|--void][--unicode][-v n][-d]\n"
788 " gnokii --savesms destination|\"\" [--smsc \n"
789 " message_center_number] [--smscno message_center_index]\n"
790 " [--long n] [-r] [-i] [-s][-C n][-a][-l][F n][--smsname name]\n"
791 " [--enablevoice|--disablevoice|--enablefax|--disablefax|\n"
792 " --enableemail|--disableemail|--void|--hang|--bug][--unicode]\n"
793 " gnokii --receivesms\n"
794 " gnokii --getsmsc message_center_number\n"
795 " gnokii --renamesmsc number new_name\n\n"
797 " gnokii --setdatetime [YYYY [MM [DD [HH [MM]]]]]\n"
798 " gnokii --getdatetime\n"
799 " gnokii --setalarm HH MM\n"
800 " gnokii --getalarm\n\n"
802 " gnokii --getcalendarnote { start end [-v30|-v10] | --short|-s }\n"
803 " gnokii --writecalendarnote vcardfile number\n"
804 " gnokii --deletecalendarnote index\n"
805 " gnokii --sendcalendarnote destination vcardfile number\n"
806 " [--smsc message_center_number] [--smscno message_center_index]\n"
807 " [-s] [-v n] [-d]\n"
808 " gnokii --savecalendarnote vcardfile number\n"
809 " [--smsc message_center_number] [--smscno message_center_index]\n"
810 " [-r] [-i] [-s] [-a] [--name name]\n\n"
812 " gnokii --netmonitor {reset|off|field|devel|next|nr}\n"
813 " gnokii --nm_collect screen1|-d [screen2|-d]...\n"
814 " gnokii --netmonitordata [-S file] [-I file] [-h] [-n n] [-ts n][-tm n]\n"
815 " [-fs str] [-ls str] FLD1:FLD2:FLDn:... \n"
816 " (see files netmonitordata_????_??? for details)\n\n"
818 " gnokii --bitmapconvert source destination\n"
819 " gnokii --bitmapconvert source destination op|7110op [network code]\n"
820 " gnokii --bitmapconvert source destination caller [caller group number]\n"
821 " gnokii --bitmapconvert source destination\n"
822 " startup|7110startup|6210startup\n"
823 " gnokii --bitmapconvert source destination picture\n"
824 " gnokii --showbitmap logofile\n"
825 " gnokii --sendlogo op destination logofile network_code\n"
826 " [--smsc message_center_number] [--smscno message_center_index]\n"
827 " [-s] [-v n] [-d]\n"
828 " gnokii --sendlogo picture destination logofile text\n"
829 " [--smsc message_center_number] [--smscno message_center_index]\n"
830 " [-s] [-v n] [-d] [--unicode]\n"
831 " gnokii --sendlogo screensaver destination logofile\n"
832 " [--smsc message_center_number] [--smscno message_center_index]\n"
833 " [-s] [-v n] [-d]\n"
834 " gnokii --sendlogo caller destination logofile\n"
835 " [--smsc message_center_number] [--smscno message_center_index]\n"
836 " [-s] [-v n] [-d]\n"
837 " gnokii --savelogo op logofile network_code\n"
838 " [--smsc message_center_number] [--smscno message_center_index]\n"
839 " [-r] [-i] [-s] [-a] [-l] [--name name]\n"
840 " gnokii --savelogo picture logofile text\n"
841 " [--smsc message_center_number] [--smscno message_center_index]\n"
842 " [-r] [-i] [-s] [-a] [-l] [--name name] [--unicode]\n"
843 " gnokii --savelogo screensaver logofile\n"
844 " [--smsc message_center_number] [--smscno message_center_index]\n"
845 " [-r] [-i] [-s] [-a] [-l] [--name name]\n"
846 " gnokii --savelogo caller logofile\n"
847 " [--smsc message_center_number] [--smscno message_center_index]\n"
848 " [-r] [-i] [-s] [-a] [-l] [--name name]\n"
849 " gnokii --setlogo op|7110op [logofile] [network code]\n"
850 " gnokii --setlogo startup|7110startup|6210startup [logofile]\n"
851 " gnokii --setlogo startup 1|2|3\n"
852 " gnokii --setlogo caller [logofile] [caller group number] [group name]\n"
853 " gnokii --setlogo picture [logofile] [number] [text] [sender]\n"
854 " gnokii --setlogo {dealer|text} [text]\n"
855 " gnokii --getlogo op|7110op [logofile] [network code]\n"
856 " gnokii --getlogo startup|7110startup|6210startup [logofile]\n"
857 " gnokii --getlogo caller [logofile][caller group number]\n"
858 " gnokii --getlogo picture [logofile][number]\n"
859 " gnokii --getlogo {dealer|text}\n\n"
861 " gnokii --sendringtone destination ringtonefile\n"
862 " [--smsc message_center_number] [--smscno message_center_index]\n"
863 " [-s] [-v n] [-d] [--scale] [--profilestyle]\n"
864 " gnokii --saveringtone ringtonefile\n"
865 " [--smsc message_center_number] [--smscno message_center_index]\n"
866 " [-r] [-i] [-s] [-a] [--name name] [--scale] [--profilestyle]\n"
867 " gnokii --setringtone ringtonefile [location]\n"
868 " gnokii --getringtone ringtonefile [location]\n"
869 " gnokii --ringtoneconvert source destination\n"
870 " gnokii --binringtoneconvert source destination\n"
871 " gnokii --playringtone ringtonefile\n"
872 " gnokii --composer ringtonefile\n"
873 " gnokii --allringtones\n\n"
875 " gnokii --getprofile [number]\n"
876 " gnokii --setprofile number feature value\n"
877 " gnokii --sendprofile destination profile_name ringtonefile\n"
878 " picturefile [--smsc message_center_number]\n"
879 " [--smscno message_center_index] [-s] [-v n] [-d] [--scale]\n\n"
884 " gnokii --reset [soft|hard]\n"
889 " gnokii --dialvoice number\n"
894 " gnokii --cancelcall\n"
899 " gnokii --displayoutput\n"
900 " gnokii --presskeysequence sequence\n"
901 " gnokii --backupsettings file\n"
902 " gnokii --restoresettings file\n"
903 " gnokii --getphoneprofile\n"
904 " gnokii --setphoneprofile feature value\n"
905 " gnokii --getoperatorname\n"
906 " gnokii --setoperatorname code name\n"
907 " gnokii --senddtmf string\n"
908 " gnokii --divert register|enable|query|disable|erasure\n"
909 " all|busy|noans|outofreach all|voice|fax|data\n"
910 " [number timeout]\n\n"
912 " gnokii --phonetests\n"
913 " gnokii --simlock\n"
914 " gnokii --getdisplaystatus\n"
919 " gnokii --identify\n\n"
924 " gnokii --getwapbookmark location\n"
925 " gnokii --setwapbookmark title url [location]\n"
926 " gnokii --sendwapbookmark location destination\n"
927 " [--smsc message_center_number] [--smscno message_center_index]\n"
928 " [-s] [-v n] [-d]\n"
929 " gnokii --savewapbookmark location\n"
930 " [--smsc message_center_number] [--smscno message_center_index]\n"
931 " [-r] [-i] [-s] [-a] [-l] [--name name]\n"
932 " gnokii --getwapsettings location\n"
933 " gnokii --savewapsettings location\n"
934 " [--smsc message_center_number] [--smscno message_center_index]\n"
935 " [-r] [-i] [-s] [-a] [-l] [--name name]\n"
936 " gnokii --sendwapsettings location destination\n"
937 " [--smsc message_center_number] [--smscno message_center_index]\n"
938 " [-s] [-v n] [-d]\n"
943 "\n gnokii --entersecuritycode PIN|PIN2|PUK|PUK2\n"
944 " gnokii --getsecuritycodestatus\n"
945 " gnokii --getsecuritycode PIN|PIN2|PUK|PUK2|SecurityCode\n"
946 " gnokii --geteeprom\n"
947 " gnokii --resetphonesettings\n"
953 " gnokii --sniff [port]\n"
954 " gnokii --decodefile file\n"
955 " gnokii --getbinringfromfile file name offset file2\n"
963 " gnokii --gnokiid [--debug] [<child to run> [<child args>...]]\n"
970 /* fbusinit is the generic function which waits for the FBUS link. The limit
971 is 10 seconds. After 10 seconds we quit. */
973 static void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame))
980 if (strcmp(GetMygnokiiVersion(),VERSION)!=0)
981 fprintf(stderr,_("WARNING: version of installed libmygnokii.so (%s) is different to version of gnokii (%s)\n"),GetMygnokiiVersion(),VERSION);
984 /* Initialise the code for the GSM interface. */
985 error = GSM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), rlp_handler, ""/*SynchronizeTime*/);
987 if (error != GE_NONE) {
988 fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
992 /* First (and important!) wait for GSM link to be active. We allow 10
994 while (count++ < 200 && *GSM_LinkOK == false)
997 if (*GSM_LinkOK == false) {
998 fprintf (stderr, _("Hmmm... GSM_LinkOK never went true. Quitting.\n"));
1003 /* This function checks that the argument count for a given options is withing
1004 an allowed range. */
1006 static int checkargs(int opt, struct gnokii_arg_len gals[], int argc)
1011 /* Walk through the whole array with options requiring arguments. */
1013 for(i = 0;!(gals[i].gal_min == 0 && gals[i].gal_max == 0); i++) {
1015 /* Current option. */
1017 if(gals[i].gal_opt == opt) {
1019 /* Argument count checking. */
1021 if(gals[i].gal_flags == GAL_XOR) {
1022 if(gals[i].gal_min == argc || gals[i].gal_max == argc) return 0;
1025 if(gals[i].gal_min <= argc && gals[i].gal_max >= argc) return 0;
1034 /* We do not have options without arguments in the array, so check them. */
1036 if (argc==0) return 0;
1040 static int gnokiid(int argc, char *argv[]);
1042 /* Main function - handles command line arguments, passes them to separate
1043 functions accordingly. */
1045 int main(int argc, char *argv[])
1052 /* Every option should be in this array. */
1054 static struct option long_options[] =
1057 { "help", no_argument, NULL, OPT_HELP },// Display usage.
1058 { "version", no_argument, NULL, OPT_VERSION },// Display version and build information.
1060 { "getsmsfolders", no_argument, NULL, OPT_GETSMSFOLDERS },// Gets SMS folders
1061 { "getsmsstatus", no_argument, NULL, OPT_GETSMSSTATUS },// Get SMS Folder Status
1062 #endif /* UCLINUX */
1063 { "identify", no_argument, NULL, OPT_IDENTIFY },// Identify
1065 { "pmon", no_argument, NULL, OPT_PMON },// For development purposes: run in passive monitoring mode
1066 { "foogle", no_argument, NULL, OPT_FOOGLE },// For development purposes: insert you function calls here
1067 { "getdatetime", no_argument, NULL, OPT_GETDATETIME },// Get date and time mode
1068 { "getalarm", no_argument, NULL, OPT_GETALARM },// Get alarm
1069 #endif /* UCLINUX */
1070 { "cancelcall", no_argument, NULL, OPT_CANCELCALL },// Cancel Call
1072 { "getdisplaystatus", no_argument, NULL, OPT_GETDISPLAYSTATUS },// Get display status mode
1073 { "allringtones", no_argument, NULL, OPT_ALLRINGTONES },/* Displays names of available ringtones */
1074 { "displayoutput", no_argument, NULL, OPT_DISPLAYOUTPUT },/* Show texts from phone's display */
1075 { "getphoneprofile", no_argument, NULL, OPT_GETPHONEPROFILE },/* Get/Set phone profile settings */
1076 { "getoperatorname", no_argument, NULL, OPT_GETOPERATORNAME },/* Get downloaded operator name */
1077 { "getvoicemailbox", no_argument, NULL, OPT_GETVOICEMAILBOX },/* Gets voice mailbox number */
1078 { "phonetests", no_argument, NULL, OPT_PHONETESTS },
1079 { "simlockinfo", no_argument, NULL, OPT_SIMLOCKINFO },
1080 { "receivesms", no_argument, NULL, OPT_RECEIVESMS },
1081 { "setoperatorname", optional_argument, NULL, OPT_SETOPERATORNAME },/* Set downloaded operator name */
1082 { "setdatetime", optional_argument, NULL, OPT_SETDATETIME },// Set date and time
1083 #endif /* UCLINUX */
1084 { "writephonebook", optional_argument, NULL, OPT_WRITEPHONEBOOK },// Write phonebook (memory) mode
1085 { "reset", optional_argument, NULL, OPT_RESET },// Resets the phone
1087 { "monitor", optional_argument, NULL, OPT_MONITOR },// Monitor mode
1088 { "setlogo", optional_argument, NULL, OPT_SETLOGO },// Set logo
1089 { "getprofile", optional_argument, NULL, OPT_GETPROFILE },// Show profile
1090 { "setalarm", required_argument, NULL, OPT_SETALARM },// Set alarm
1091 { "dialvoice", required_argument, NULL, OPT_DIALVOICE },// Voice call mode
1092 { "getcalendarnote", required_argument, NULL, OPT_GETCALENDARNOTE },// Get calendar note mode
1093 { "writecalendarnote", required_argument, NULL, OPT_WRITECALENDARNOTE},// Write calendar note mode
1094 { "sendcalendarnote", required_argument, NULL, OPT_SENDCALENDARNOTE },
1095 { "savecalendarnote", required_argument, NULL, OPT_SAVECALENDARNOTE },
1096 { "sendphonebookentry", required_argument, NULL, OPT_SENDPHONEBOOKENTRY},
1097 { "savephonebookentry", required_argument, NULL, OPT_SAVEPHONEBOOKENTRY},
1098 { "deletecalendarnote", required_argument, NULL, OPT_DELCALENDARNOTE },// Delete calendar note mode
1099 #endif /* UCLINUX */
1100 { "getmemory", required_argument, NULL, OPT_GETMEMORY },// Get memory mode
1101 { "getspeeddial", required_argument, NULL, OPT_GETSPEEDDIAL },// Get speed dial mode
1102 { "setspeeddial", required_argument, NULL, OPT_SETSPEEDDIAL },// Set speed dial mode
1104 { "getsms", required_argument, NULL, OPT_GETSMS },// Get SMS message mode
1105 { "deletesms", required_argument, NULL, OPT_DELETESMS },// Delete SMS message mode
1106 { "sendsms", required_argument, NULL, OPT_SENDSMS },// Send SMS message mode
1107 { "savesms", required_argument, NULL, OPT_SAVESMS },// Save SMS message mode
1108 { "sendlogo", required_argument, NULL, OPT_SENDLOGO },// Send logo as SMS message mode
1109 { "savelogo", required_argument, NULL, OPT_SAVELOGO },// Save logo on SIM
1110 { "sendringtone", required_argument, NULL, OPT_SENDRINGTONE },// Send ringtone as SMS message
1111 { "saveringtone", required_argument, NULL, OPT_SAVERINGTONE },// Saves ringtone on SIM
1112 { "setringtone", required_argument, NULL, OPT_SETRINGTONE },// Set ringtone
1113 { "getringtone", required_argument, NULL, OPT_GETRINGTONE },// Get bin/normal ringtone
1114 { "presskeysequence", required_argument, NULL, OPT_PRESSKEYSEQUENCE },/* Presses keys in phone's display */
1115 { "getsmsc", required_argument, NULL, OPT_GETSMSC },// Get SMS center number mode
1116 { "renamesmsc", required_argument, NULL, OPT_RENAMESMSC },// Rename SMSC
1117 { "netmonitor", required_argument, NULL, OPT_NETMONITOR },// NetMonitor mode
1118 { "senddtmf", required_argument, NULL, OPT_SENDDTMF },// Send DTMF sequence
1119 { "getlogo", required_argument, NULL, OPT_GETLOGO },// Get logo
1120 { "setprofile", required_argument, NULL, OPT_SETPROFILE },// Set profile feature
1121 { "sendprofile", required_argument, NULL, OPT_SENDPROFILE },// Send profile via SMS
1122 { "setphoneprofile", required_argument, NULL, OPT_SETPHONEPROFILE },/* Get/Set phone profile settings */
1123 { "restoresettings", required_argument, NULL, OPT_RESTORESETTINGS },//Restore various settings from one file
1124 { "backupsettings", required_argument, NULL, OPT_BACKUPSETTINGS },//Backup various settings to one file
1125 { "playringtone", required_argument, NULL, OPT_PLAYRINGTONE },/* Plays ringtones */
1126 { "composer", required_argument, NULL, OPT_COMPOSER },/* Shows ringtone like in Nokia Composer */
1127 { "ringtoneconvert", required_argument, NULL, OPT_RINGTONECONVERT },/* Convert ringtone files */
1128 { "binringtoneconvert", required_argument, NULL, OPT_BINRINGTONECONVERT},/* Convert binary ringtone files */
1129 { "bitmapconvert", required_argument, NULL, OPT_BITMAPCONVERT },/* Convert bitmap files */
1130 { "showbitmap", required_argument, NULL, OPT_SHOWBITMAP },
1131 { "nm_collect", required_argument, NULL, OPT_NM_COLLECT },// NetMonitor periodical data collection mode (newbiee)
1132 { "netmonitordata", required_argument, NULL, OPT_NETMONITORDATA },// NetMonitor periodical data collection mode (advanced)
1133 { "getwapbookmark", required_argument, NULL, OPT_GETWAPBOOKMARK },
1134 { "setwapbookmark", required_argument, NULL, OPT_SETWAPBOOKMARK },
1135 { "savewapbookmark", required_argument, NULL, OPT_SAVEWAPBOOKMARK },
1136 { "savewapsettings", required_argument, NULL, OPT_SAVEWAPSETTINGS },
1137 { "sendwapsettings", required_argument, NULL, OPT_SENDWAPSETTINGS },
1138 { "sendwapbookmark", required_argument, NULL, OPT_SENDWAPBOOKMARK },
1139 { "getwapsettings", required_argument, NULL, OPT_GETWAPSETTINGS },
1140 { "divert", required_argument, NULL, OPT_DIVERT },
1143 { "entersecuritycode", required_argument, NULL, OPT_ENTERSECURITYCODE },// Enter Security Code mode
1144 { "getsecuritycode", required_argument, NULL, OPT_GETSECURITYCODE },// Get Security Code
1145 { "getsecuritycodestatus",no_argument, NULL, OPT_GETSECURITYCODESTATUS},// Get Security Code status
1146 { "geteeprom", no_argument, NULL, OPT_GETEEPROM },// Gets EEPROM
1147 { "resetphonesettings", no_argument, NULL, OPT_RESETPHONESETTINGS },// Reset phone settings
1148 { "setsimlock", no_argument, NULL, OPT_SETSIMLOCK },// Sets simlock
1152 { "sniff", optional_argument, NULL, OPT_SNIFFER },// Will show datas from port
1153 { "decodefile", required_argument, NULL, OPT_DECODEFILE },//decode input file
1154 { "getbinringfromfile", required_argument, NULL, OPT_GETBINRINGFROMFILE },
1156 #endif /* UCLINUX */
1159 { "gnokiid", optional_argument, NULL, OPT_GNOKIID },// gnokiid mode
1160 #endif /* UCLINUX */
1165 /* Every command which requires arguments should have an appropriate entry
1168 struct gnokii_arg_len gals[] =
1172 { OPT_MONITOR, 0, 1, 0 },
1175 { OPT_ENTERSECURITYCODE, 1, 1, 0 },
1176 { OPT_GETSECURITYCODE, 1, 1, 0 },
1180 { OPT_SNIFFER, 0, 1, 0 },
1181 { OPT_DECODEFILE, 1, 1, 0 },
1182 { OPT_GETBINRINGFROMFILE,4, 4, 0 },
1185 { OPT_SETDATETIME, 0, 5, 0 },
1186 { OPT_BACKUPSETTINGS, 1, 1, 0 },
1187 { OPT_RESTORESETTINGS, 1, 1, 0 },
1188 { OPT_SETALARM, 2, 2, 0 },
1189 { OPT_DIALVOICE, 1, 1, 0 },
1190 { OPT_GETCALENDARNOTE, 1, 3, 0 },
1191 { OPT_WRITECALENDARNOTE, 2, 2, 0 },
1192 { OPT_SAVECALENDARNOTE, 2, 9, 0 },
1193 { OPT_SENDCALENDARNOTE, 3, 9, 0 },
1194 { OPT_SAVEPHONEBOOKENTRY,2, 9, 0 },
1195 { OPT_SENDPHONEBOOKENTRY,3, 9, 0 },
1196 { OPT_DELCALENDARNOTE, 1, 1, 0 },
1197 #endif /* UCLINUX */
1198 { OPT_GETMEMORY, 2, 4, 0 },
1199 { OPT_GETSPEEDDIAL, 1, 1, 0 },
1200 { OPT_SETSPEEDDIAL, 3, 3, 0 },
1202 { OPT_GETSMS, 2, 5, 0 },
1203 { OPT_DELETESMS, 2, 3, 0 },
1204 { OPT_SENDSMS, 1,10, 0 },
1205 { OPT_SAVESMS, 1,11, 0 },
1206 { OPT_SENDLOGO, 3, 9, 0 },
1207 { OPT_SAVELOGO, 2,10, 0 },
1208 { OPT_SENDRINGTONE, 2, 7, 0 },
1209 { OPT_SAVERINGTONE, 1, 9, 0 },
1210 { OPT_GETSMSC, 1, 1, 0 },
1211 { OPT_RENAMESMSC, 2, 2, 0 },
1212 { OPT_NETMONITOR, 1, 1, 0 },
1213 { OPT_SENDDTMF, 1, 1, 0 },
1214 { OPT_SETLOGO, 1, 5, 0 },
1215 { OPT_GETLOGO, 1, 4, 0 },
1216 { OPT_SETRINGTONE, 1, 3, 0 },
1217 { OPT_GETRINGTONE, 1, 2, 0 },
1218 { OPT_PRESSKEYSEQUENCE, 1, 1, 0 },
1219 #endif /* UCLINUX */
1220 { OPT_RESET, 0, 1, 0 },
1222 { OPT_GETPROFILE, 0, 1, 0 },
1223 { OPT_SETPROFILE, 3, 3, 0 },
1224 { OPT_SENDPROFILE, 4,10, 0 },
1225 #endif /* UCLINUX */
1226 { OPT_WRITEPHONEBOOK, 0, 1, 0 },
1228 { OPT_PLAYRINGTONE, 1, 1, 0 },
1229 { OPT_COMPOSER, 1, 1, 0 },
1230 { OPT_RINGTONECONVERT, 2, 2, 0 },
1231 { OPT_BINRINGTONECONVERT,2, 2, 0 },
1232 { OPT_BITMAPCONVERT, 2, 4, 0 },
1233 { OPT_SHOWBITMAP, 1, 1, 0 },
1234 { OPT_SETOPERATORNAME, 0, 2, 0 },
1235 { OPT_SETPHONEPROFILE, 2, 2, 0 },
1236 { OPT_NM_COLLECT, 1, MAX_NM_COLLECT, 0 },
1237 { OPT_NETMONITORDATA, 0,99, 0 },
1238 { OPT_GETWAPBOOKMARK, 1, 1, 0 },
1239 { OPT_SETWAPBOOKMARK, 2, 3, 0 },
1240 { OPT_SAVEWAPBOOKMARK, 1, 9, 0 },
1241 { OPT_SENDWAPBOOKMARK, 2, 9, 0 },
1242 { OPT_GETWAPSETTINGS, 1, 1, 0 },
1243 { OPT_SAVEWAPSETTINGS, 1, 9, 0 },
1244 { OPT_SENDWAPSETTINGS, 2, 9, 0 },
1245 { OPT_DIVERT, 3, 5, 0 },
1246 #endif /* UCLINUX */
1249 { OPT_GNOKIID, 0, INT_MAX, 0 },
1250 #endif /* UCLINUX */
1259 /* For GNU gettext */
1263 textdomain("gnokii");
1264 setlocale(LC_ALL, "pl_PL"); //here is string for Polish localisation
1266 setlocale(LC_ALL, ".852"); //Polish codepage for console, not "real" WIN CP
1271 /* Read config file */
1272 if (CFG_ReadConfig(&model, &Port, &Initlength, &Connection, &BinDir, false) < 0) {
1275 if (argc>1 && !strcmp(argv[1],"--ir")) {
1279 Connection="infrared";
1282 /* Handle command line arguments. */
1284 c = getopt_long(argc, argv, "", long_options, NULL);
1288 /* No argument given - we should display usage. */
1293 /* We have to build an array of the arguments which will be passed to the
1294 functions. Please note that every text after the --command will be
1295 passed as arguments. A syntax like gnokii --cmd1 args --cmd2 args will
1296 not work as expected; instead args --cmd2 args is passed as a
1299 if((nargv = malloc(sizeof(char *) * argc)) != NULL) {
1302 for(i = 2; i < argc; i++)
1303 nargv[i-2] = argv[i];
1304 nargv[argc-2] = NULL; /* required by gnokiid() for execv(3) */
1306 if(checkargs(c, gals, nargc)) {
1310 /* Wrong number of arguments - we should display usage. */
1316 #if defined(__svr4__)
1317 /* have to ignore SIGALARM */
1324 // First, error conditions
1326 fprintf(stderr, _("Use '%s --help' for usage informations.\n"), argv[0]);
1329 // Then, options with no arguments
1330 case OPT_HELP: rc = usage(); break;
1331 case OPT_VERSION: rc = version(); break;
1333 case OPT_MONITOR: rc = monitormode(nargc, nargv); break;
1334 case OPT_GETSMSFOLDERS: rc = getsmsfolders(); break;
1335 case OPT_GETDATETIME: rc = getdatetime(); break;
1336 case OPT_GETALARM: rc = getalarm(); break;
1337 case OPT_GETDISPLAYSTATUS: rc = getdisplaystatus(); break;
1338 case OPT_PMON: rc = pmon(); break;
1339 #endif /* UCLINUX */
1340 case OPT_WRITEPHONEBOOK: rc = writephonebook(nargc, nargv);break;
1344 case OPT_ENTERSECURITYCODE: rc = entersecuritycode(optarg); break;
1345 case OPT_GETSECURITYCODESTATUS: rc = getsecuritycodestatus(); break;
1346 case OPT_GETSECURITYCODE: rc = getsecuritycode(optarg); break;
1347 case OPT_GETEEPROM: rc = geteeprom(); break;
1348 case OPT_RESETPHONESETTINGS: rc = resetphonesettings(); break;
1349 case OPT_SETSIMLOCK: rc = setsimlock(); break;
1353 case OPT_SNIFFER: rc = sniff(nargc, nargv); break;
1354 case OPT_DECODEFILE: rc = decodefile(nargc, nargv); break;
1355 case OPT_GETBINRINGFROMFILE: rc = getbinringfromfile(nargc, nargv);break;
1358 // Now, options with arguments
1359 case OPT_SETDATETIME: rc = setdatetime(nargc, nargv); break;
1360 case OPT_SETALARM: rc = setalarm(nargv); break;
1361 case OPT_DIALVOICE: rc = dialvoice(optarg); break;
1362 #endif /* UCLINUX */
1363 case OPT_CANCELCALL: rc = cancelcall(); break;
1365 case OPT_GETCALENDARNOTE: rc = getcalendarnote(nargc, nargv);break;
1366 case OPT_DELCALENDARNOTE: rc = deletecalendarnote(optarg);break;
1367 case OPT_SAVECALENDARNOTE: rc = savecalendarnote(nargc, nargv);break;
1368 case OPT_SENDCALENDARNOTE: rc = sendcalendarnote(nargc, nargv);break;
1369 case OPT_SAVEPHONEBOOKENTRY: rc = savephonebookentry(nargc, nargv);break;
1370 case OPT_SENDPHONEBOOKENTRY: rc = sendphonebookentry(nargc, nargv);break;
1371 case OPT_WRITECALENDARNOTE: rc = writecalendarnote(nargv); break;
1372 #endif /* UCLINUX */
1373 case OPT_GETMEMORY: rc = getmemory(nargc, nargv); break;
1374 case OPT_GETSPEEDDIAL: rc = getspeeddial(optarg); break;
1375 case OPT_SETSPEEDDIAL: rc = setspeeddial(nargv); break;
1377 case OPT_GETSMS: rc = getsms(argc, argv); break;
1378 case OPT_GETSMSSTATUS: rc = getsmsstatus(argc, argv); break;
1379 case OPT_DELETESMS: rc = deletesms(nargc, nargv); break;
1380 case OPT_SENDSMS: rc = sendsms(nargc, nargv); break;
1381 case OPT_SAVESMS: rc = savesms(nargc, nargv); break;
1382 case OPT_DIVERT: rc = divert(nargc, nargv); break;
1383 case OPT_SENDLOGO: rc = sendlogo(nargc, nargv); break;
1384 case OPT_SAVELOGO: rc = savelogo(nargc, nargv); break;
1385 case OPT_GETSMSC: rc = getsmsc(optarg); break;
1386 case OPT_RENAMESMSC: rc = renamesmsc(nargc,nargv); break;
1387 case OPT_NETMONITOR: rc = netmonitor(optarg); break;
1388 #endif /* UCLINUX */
1389 case OPT_IDENTIFY: rc = identify(); break;
1391 case OPT_SETLOGO: rc = setlogo(nargc, nargv); break;
1392 case OPT_GETLOGO: rc = getlogo(nargc, nargv); break;
1393 case OPT_RECEIVESMS: rc = receivesms(nargc, nargv); break;
1394 case OPT_SETRINGTONE: rc = setringtone(nargc, nargv); break;
1395 case OPT_GETRINGTONE: rc = getringtone(nargc, nargv); break;
1396 case OPT_PRESSKEYSEQUENCE: rc = presskeysequence(nargv); break;
1397 case OPT_SENDRINGTONE: rc = sendringtone(nargc, nargv);break;
1398 case OPT_SAVERINGTONE: rc = saveringtone(nargc, nargv);break;
1399 case OPT_GETPROFILE: rc = getprofile(nargc, nargv); break;
1400 case OPT_SETPROFILE: rc = setprofile(nargc, nargv); break;
1401 case OPT_SENDPROFILE: rc = sendprofile(nargc, nargv); break;
1402 case OPT_DISPLAYOUTPUT: rc = displayoutput(); break;
1403 case OPT_RESTORESETTINGS: rc = restoresettings(nargv); break;
1404 case OPT_BACKUPSETTINGS: rc = backupsettings(nargv); break;
1405 case OPT_RINGTONECONVERT: rc = ringtoneconvert(nargc, nargv);break;
1406 case OPT_BINRINGTONECONVERT: rc = binringtoneconvert(nargc, nargv);break;
1407 case OPT_BITMAPCONVERT: rc = bitmapconvert(nargc, nargv);break;
1408 case OPT_SHOWBITMAP: rc = showbitmap(nargc, nargv); break;
1409 case OPT_PLAYRINGTONE: rc = playringtone(nargc, nargv);break;
1410 case OPT_COMPOSER: rc = composer(nargc, nargv); break;
1411 case OPT_FOOGLE: rc = foogle(nargv); break;
1412 case OPT_PHONETESTS: rc = phonetests(); break;
1413 case OPT_SIMLOCKINFO: rc = simlockinfo(); break;
1414 case OPT_SENDDTMF: rc = senddtmf(optarg); break;
1415 #endif /* UCLINUX */
1416 case OPT_RESET: rc = reset(nargc,nargv); break;
1418 case OPT_GETOPERATORNAME: rc = getoperatorname(); break;
1419 case OPT_SETOPERATORNAME: rc = setoperatorname(nargc,nargv);break;
1420 case OPT_GETWAPBOOKMARK: rc = getwapbookmark(nargc,nargv);break;
1421 case OPT_SETWAPBOOKMARK: rc = setwapbookmark(nargc,nargv);break;
1422 case OPT_SAVEWAPBOOKMARK: rc = savewapbookmark(nargc,nargv);break;
1423 case OPT_SENDWAPBOOKMARK: rc = sendwapbookmark(nargc,nargv);break;
1424 case OPT_GETWAPSETTINGS: rc = getwapsettings(nargc,nargv);break;
1425 case OPT_SAVEWAPSETTINGS: rc = savewapsettings(nargc,nargv);break;
1426 case OPT_SENDWAPSETTINGS: rc = sendwapsettings(nargc,nargv);break;
1427 case OPT_ALLRINGTONES: rc = allringtones(); break;
1428 case OPT_GETPHONEPROFILE: rc = getphoneprofile(); break;
1429 case OPT_SETPHONEPROFILE: rc = setphoneprofile(nargc,nargv);break;
1430 case OPT_GETVOICEMAILBOX: rc = getvoicemailbox(); break;
1431 case OPT_NM_COLLECT: rc = nm_collect(nargc, nargv); break;
1432 case OPT_NETMONITORDATA: rc = netmonitordata(nargc, nargv);break;
1433 #endif /* UCLINUX */
1436 case OPT_GNOKIID: rc = gnokiid(nargc, nargv); break;
1437 #endif /* UCLINUX */
1438 default: fprintf(stderr, _("Unknown option: %d\n"), c); break;
1447 fprintf(stderr, _("Wrong number of arguments\n"));
1454 /* Restores various phone settings from one file */
1455 int restoresettings(char *argv[])
1458 GSM_PhonebookEntry pbk;
1465 GSM_MemoryStatus SIMMemoryStatus = {GMT_SM, 0, 0};
1466 GSM_MemoryStatus PhoneMemoryStatus = {GMT_ME, 0, 0};
1468 if (GSM_ReadBackupFile(argv[0], &Backup)!=GE_NONE) return 1;
1472 if (Backup.SIMPhonebookUsed!=0) {
1474 while (confirm < 0) {
1475 fprintf(stderr, _("Restore SIM phonebook ? "));
1476 GetLine(stdin, ans, 99);
1477 if (!strcmp(ans, "yes")) confirm = 1;
1478 if (!strcmp(ans, "no" )) confirm = 0;
1481 if (GSM->GetMemoryStatus(&SIMMemoryStatus) != GE_NONE) {
1482 fprintf(stderr,_("Error getting memory status !\n"));
1487 while ((pos-1)!=SIMMemoryStatus.Used+SIMMemoryStatus.Free) {
1489 pbk.MemoryType=GMT_SM;
1492 pbk.SubEntriesCount = 0;
1493 if (i<Backup.SIMPhonebookUsed) {
1494 if (Backup.SIMPhonebook[i].Location==pbk.Location) {
1495 pbk=Backup.SIMPhonebook[i];
1498 // fprintf(stdout,_("Copying from backup\n"));
1503 // fprintf(stdout,_("Setting location %i\n"),pbk.Location);
1505 GSM->WritePhonebookLocation(&pbk);
1506 fprintf(stderr,_("."));
1509 fprintf(stderr,_("\n"));
1512 if (Backup.PhonePhonebookUsed!=0) {
1514 while (confirm < 0) {
1515 fprintf(stderr, _("Restore phone phonebook ? "));
1516 GetLine(stdin, ans, 99);
1517 if (!strcmp(ans, "yes")) confirm = 1;
1518 if (!strcmp(ans, "no" )) confirm = 0;
1521 if (GSM->GetMemoryStatus(&PhoneMemoryStatus) != GE_NONE) {
1522 fprintf(stderr,_("Error getting memory status !\n"));
1528 while ((pos-1)!=PhoneMemoryStatus.Used+PhoneMemoryStatus.Free) {
1530 pbk.MemoryType=GMT_ME;
1533 pbk.SubEntriesCount = 0;
1534 if (i<Backup.PhonePhonebookUsed) {
1535 if (Backup.PhonePhonebook[i].Location==pbk.Location) {
1536 pbk=Backup.PhonePhonebook[i];
1539 // fprintf(stdout,_("Copying from backup\n"));
1544 // fprintf(stdout,_("Setting location %i\n"),pbk.Location);
1546 GSM->WritePhonebookLocation(&pbk);
1547 fprintf(stderr,_("."));
1550 fprintf(stderr,_("\n"));
1553 if (Backup.CallerAvailable==true) {
1555 while (confirm < 0) {
1556 fprintf(stderr, _("Restore caller groups ? "));
1557 GetLine(stdin, ans, 99);
1558 if (!strcmp(ans, "yes")) confirm = 1;
1559 if (!strcmp(ans, "no" )) confirm = 0;
1562 for (i=0;i<5;i++) GSM->SetBitmap(&Backup.CallerGroups[i]);
1565 if (Backup.OperatorLogoAvailable==true) {
1567 while (confirm < 0) {
1568 fprintf(stderr, _("Restore operator logo ? "));
1569 GetLine(stdin, ans, 99);
1570 if (!strcmp(ans, "yes")) confirm = 1;
1571 if (!strcmp(ans, "no" )) confirm = 0;
1574 GSM->SetBitmap(&Backup.OperatorLogo);
1577 if (Backup.StartupLogoAvailable==true) {
1579 while (confirm < 0) {
1580 fprintf(stderr, _("Restore startup logo ? "));
1581 GetLine(stdin, ans, 99);
1582 if (!strcmp(ans, "yes")) confirm = 1;
1583 if (!strcmp(ans, "no" )) confirm = 0;
1586 GSM->SetBitmap(&Backup.StartupLogo);
1595 /* Backup various phone settings from one file */
1596 int backupsettings(char *argv[])
1598 GSM_PhonebookEntry PbkEntry;
1603 GSM_MemoryStatus SIMMemoryStatus = {GMT_SM, 0, 0};
1604 GSM_MemoryStatus PhoneMemoryStatus = {GMT_ME, 0, 0};
1608 fprintf(stderr,_("Backup phonebook from SIM..."));
1609 Backup.SIMPhonebookUsed=0;
1610 if (GSM->GetMemoryStatus(&SIMMemoryStatus) == GE_NONE) {
1611 Backup.SIMPhonebookSize=SIMMemoryStatus.Used+SIMMemoryStatus.Free;
1613 PbkEntry.MemoryType=GMT_SM;
1615 for (i=0;i<Backup.SIMPhonebookSize;i++)
1617 if (SIMMemoryStatus.Used==Backup.SIMPhonebookUsed) break;
1619 PbkEntry.Location=i;
1621 error=GSM->GetMemoryLocation(&PbkEntry);
1624 Backup.SIMPhonebook[Backup.SIMPhonebookUsed]=PbkEntry;
1625 Backup.SIMPhonebookUsed++;
1626 fprintf(stderr,_("."));
1632 fprintf(stderr,_("Done\n"));
1633 } else fprintf(stderr,_("ERROR\n"));
1635 fprintf(stderr,_("Backup phonebook from phone..."));
1636 Backup.PhonePhonebookUsed=0;
1637 if (GSM->GetMemoryStatus(&PhoneMemoryStatus) == GE_NONE) {
1638 Backup.PhonePhonebookSize=PhoneMemoryStatus.Used+PhoneMemoryStatus.Free;
1640 PbkEntry.MemoryType=GMT_ME;
1642 for (i=0;i<Backup.PhonePhonebookSize;i++)
1644 if (PhoneMemoryStatus.Used==Backup.PhonePhonebookUsed) break;
1646 PbkEntry.Location=i;
1648 error=GSM->GetMemoryLocation(&PbkEntry);
1651 Backup.PhonePhonebook[Backup.PhonePhonebookUsed]=PbkEntry;
1652 Backup.PhonePhonebookUsed++;
1653 fprintf(stderr,_("."));
1659 fprintf(stderr,_("Done\n"));
1660 } else fprintf(stderr,_("ERROR\n"));
1662 if( GetModelFeature (FN_CALLERGROUPS)!=0) {
1663 fprintf(stderr,_("Backup caller logos..."));
1664 Backup.CallerAvailable=true;
1666 Backup.CallerGroups[i].number=i;
1667 Backup.CallerGroups[i].type=GSM_CallerLogo;
1668 if (GSM->GetBitmap(&Backup.CallerGroups[i])!=GE_NONE) return 1;
1670 fprintf(stderr,_("Done\n"));
1671 } else Backup.CallerAvailable=false;
1673 // fprintf(stderr,_("Backup speed dials..."));
1674 Backup.SpeedAvailable=false;
1675 // for (i=0;i<8;i++) {
1676 // Backup.SpeedDials[i].Number=i+1;
1677 // if (GSM->GetSpeedDial(&Backup.SpeedDials[i])!=GE_NONE) return 1;
1679 // fprintf(stderr,_("Done\n"));
1681 fprintf(stderr,_("Backup operator logo..."));
1682 Backup.OperatorLogoAvailable=true;
1683 Backup.OperatorLogo.type=GSM_7110OperatorLogo;
1684 if (GSM->GetBitmap(&Backup.OperatorLogo)!=GE_NONE) {
1685 Backup.OperatorLogo.type=GSM_OperatorLogo;
1686 if (GSM->GetBitmap(&Backup.OperatorLogo)!=GE_NONE) {
1687 Backup.OperatorLogoAvailable=false;
1688 fprintf(stderr,_("Error\n"));
1689 } else fprintf(stderr,_("Done\n"));
1690 } else fprintf(stderr,_("Done\n"));
1692 Backup.StartupLogoAvailable=false;
1693 if( GetModelFeature (FN_STARTUP)!=0) {
1694 fprintf(stderr,_("Backup startup logo..."));
1695 Backup.StartupLogoAvailable=true;
1696 switch (GetModelFeature (FN_STARTUP)) {
1697 case F_STA62: Backup.StartupLogo.type=GSM_6210StartupLogo;break;
1698 case F_STA71: Backup.StartupLogo.type=GSM_7110StartupLogo;break;
1699 default : Backup.StartupLogo.type=GSM_StartupLogo;break;
1701 if (GSM->GetBitmap(&Backup.StartupLogo)!=GE_NONE) {
1702 Backup.StartupLogoAvailable=false;
1703 fprintf(stderr,_("Error\n"));
1704 } else fprintf(stderr,_("Done\n"));
1707 fprintf(stderr,_("Backup welcome note..."));
1708 Backup.StartupText.type=GSM_WelcomeNoteText;
1709 if (GSM->GetBitmap(&Backup.StartupText)!=GE_NONE) {
1710 fprintf(stderr,_("Error\n"));
1711 } else fprintf(stderr,_("Done\n"));
1715 GSM_SaveBackupFile(argv[0], &Backup);
1720 /* Presses keys on phone's keyboard */
1722 int presskeysequence(char *argv[])
1732 for (i=0;i<strlen(argv[0]);i++)
1738 if (key!='w' && key!='W')
1740 while (Keys[j].whatchar!=' ') {
1741 if (Keys[j].whatchar==key) {
1742 keycode=Keys[j].whatcode;
1749 fprintf(stderr,_("Unknown key: %c !\n"),key);
1754 if (GSM->PressKey(keycode,PRESSPHONEKEY)!=GE_NONE)
1756 fprintf(stderr,_("Can't press key !\n"));
1760 if (GSM->PressKey(keycode,RELEASEPHONEKEY)!=GE_NONE)
1762 fprintf(stderr,_("Can't release key !\n"));
1777 /* Send SMS messages. */
1778 int sendsms(int argc, char *argv[])
1780 GSM_MultiSMSMessage MultiSMS;
1781 char message_buffer[GSM_MAX_CONCATENATED_SMS_LENGTH];
1782 int input_len, chars_read,i,msgnum;
1784 GSM_SMSMessageType SMSType=GST_SMS;
1785 int SMSValidity= 4320; /* 4320 minutes == 72 hours */
1786 bool SMSReply=false;
1787 int SMSClass=-1,SMSCenter=1;
1788 char SMSCNumber[100];
1789 GSM_Coding_Type SMSCoding=GSM_Coding_Default;
1790 GSM_UDH SMSUDHType=GSM_NoUDH;
1792 struct option options[] = {
1793 { "smscno", required_argument, NULL, '2'},
1794 { "smsc", required_argument, NULL, '1'},
1795 { "long", required_argument, NULL, '3'},
1796 { "enablevoice", no_argument, NULL, '4'},
1797 { "disablevoice", no_argument, NULL, '5'},
1798 { "enableemail", no_argument, NULL, '6'},
1799 { "disableemail", no_argument, NULL, '7'},
1800 { "enablefax", no_argument, NULL, '8'},
1801 { "disablefax", no_argument, NULL, '9'},
1802 { "unicode", no_argument, NULL, '-'},
1803 { "void", no_argument, NULL, '+'},
1804 { "hang", no_argument, NULL, '('},
1805 { "bug", no_argument, NULL, ')'},
1809 input_len = GSM_MAX_SMS_LENGTH;
1816 while ((i = getopt_long(argc, argv, "v:dsC:", options, NULL)) != -1) {
1819 case '1': /* SMSC number */
1821 strcpy(SMSCNumber,optarg);
1824 case '2': /* SMSC number index in phone memory */
1825 SMSCenter = atoi(optarg);
1827 if (SMSCenter < 1 || SMSCenter > 5) {
1828 fprintf(stderr, _("Incorrect SMSC number with \"smscno\" option (can't be <1 and >5) !\n"));
1834 case '3': /* we send long message */
1835 SMSUDHType=GSM_ConcatenatedMessages;
1836 input_len = atoi(optarg);
1837 if (input_len > GSM_MAX_CONCATENATED_SMS_LENGTH) {
1838 fprintf(stderr, _("Input too long, max %i!\n"),GSM_MAX_CONCATENATED_SMS_LENGTH);
1843 case '4': /* SMS enables voice indicator */
1844 SMSUDHType=GSM_EnableVoice; break;
1846 case '5': /* SMS disables voice indicator */
1847 SMSUDHType=GSM_DisableVoice; break;
1849 case '6': /* SMS enables email indicator */
1850 SMSUDHType=GSM_EnableEmail; break;
1852 case '7': /* SMS disables email indicator */
1853 SMSUDHType=GSM_DisableEmail; break;
1855 case '8': /* SMS enables fax indicator */
1856 SMSUDHType=GSM_EnableFax; break;
1858 case '9': /* SMS disables fax indicator */
1859 SMSUDHType=GSM_DisableFax; break;
1861 case '-': /* SMS coding type */
1862 SMSCoding=GSM_Coding_Unicode; break;
1864 case '+': /* SMS ghost */
1865 SMSUDHType=GSM_VoidSMS; break;
1867 case '(': /* SMS hanging phone, when saved to Outbox */
1868 SMSUDHType=GSM_HangSMS; break;
1870 case ')': /* SMS showed incorrectly in phone */
1871 SMSUDHType=GSM_BugSMS; break;
1873 case 'v': /* Set validaty of SMS */
1874 SMSValidity = atoi(optarg); break;
1876 case 'd': /* delivery report */
1877 SMSType=GST_DR; break;
1879 case 's': /* Set replying via the same SMSC */
1880 SMSReply = true; break;
1882 case 'C': /* class Message */
1884 if (SMSUDHType!=GSM_NoUDH) {
1885 fprintf(stderr, _("Can't specify SMS Class with --enablevoice, --disablevoice, --enableemail, --disableemail, --enablefax, --disablefax options !\n"));
1890 case '0': SMSClass = 0; break;
1891 case '1': SMSClass = 1; break;
1892 case '2': SMSClass = 2; break;
1893 case '3': SMSClass = 3; break;
1895 fprintf(stderr, _("SMS Class (\"C\" option) can be 0, 1, 2 or 3 only !\n"));
1901 fprintf(stderr,_("Unknown option number %i\n"),argc);
1907 /* Get message text from stdin. */
1908 chars_read = fread(message_buffer, 1, input_len, stdin);
1910 if (chars_read == 0) {
1911 fprintf(stderr, _("Couldn't read from stdin!\n"));
1914 if (chars_read > input_len) {
1915 fprintf(stderr, _("Input too long!\n"));
1919 /* Null terminate. */
1920 message_buffer[chars_read] = 0x00;
1922 GSM_MakeMultiPartSMS2(&MultiSMS,message_buffer,chars_read,SMSUDHType,SMSCoding);
1923 msgnum=MultiSMS.number;
1925 switch (SMSUDHType) {
1930 case GSM_EnableVoice:
1931 case GSM_DisableVoice:
1933 case GSM_DisableFax:
1934 case GSM_EnableEmail:
1935 case GSM_DisableEmail:
1936 fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText));
1943 for (i=0;i<msgnum;i++) {
1944 strcpy(MultiSMS.SMS[i].Destination,argv[0]);
1946 MultiSMS.SMS[i].Class=SMSClass;
1947 MultiSMS.SMS[i].ReplyViaSameSMSC=SMSReply;
1948 MultiSMS.SMS[i].Type=SMSType;
1949 MultiSMS.SMS[i].Validity=SMSValidity;
1952 /* Initialise the GSM interface. */
1955 MultiSMS.number=msgnum;
1956 GSM_SendMultiPartSMSOnConsole(&MultiSMS, 0,0,NULL,false,false,false);
1961 int savesms(int argc, char *argv[])
1963 GSM_MultiSMSMessage MultiSMS;
1964 char message_buffer[GSM_MAX_CONCATENATED_SMS_LENGTH];
1965 int input_len, chars_read,i,msgnum;
1967 int SMSClass=-1,SMSCenter=1;
1969 char SMSCNumber[100];
1970 GSM_Coding_Type SMSCoding=GSM_Coding_Default;
1971 GSM_UDH SMSUDHType=GSM_NoUDH;
1972 GSM_SMSMessageStatus SMSStatus;
1974 bool SMSReply=false;
1976 bool interactive=false;
1978 struct option options[] = {
1979 { "smscno", required_argument, NULL, '2'},
1980 { "smsc", required_argument, NULL, '1'},
1981 { "long", required_argument, NULL, '3'},
1982 { "enablevoice", no_argument, NULL, '4'},
1983 { "disablevoice", no_argument, NULL, '5'},
1984 { "enableemail", no_argument, NULL, '6'},
1985 { "disableemail", no_argument, NULL, '7'},
1986 { "enablefax", no_argument, NULL, '8'},
1987 { "disablefax", no_argument, NULL, '9'},
1988 { "unicode", no_argument, NULL, '-'},
1989 { "void", no_argument, NULL, '+'},
1990 { "hang", no_argument, NULL, '('},
1991 { "bug", no_argument, NULL, ')'},
1992 { "smsname", required_argument, NULL, '/'},
1998 SMSStatus=GSS_NOTSENTREAD;
1999 SMSFolder=GST_OUTBOX;
2001 input_len = GSM_MAX_SMS_LENGTH;
2008 while ((i = getopt_long(argc, argv, "risal:C:F:", options, NULL)) != -1) {
2011 case '1': /* SMSC number */
2013 strcpy(SMSCNumber,optarg);
2016 case '2': /* SMSC number index in phone memory */
2017 SMSCenter = atoi(optarg);
2019 if (SMSCenter < 1 || SMSCenter > 5) {
2020 fprintf(stderr, _("Incorrect SMSC number with \"smscno\" option (can't be <1 and >5) !\n"));
2026 case '3': /* we send long message */
2027 SMSUDHType=GSM_ConcatenatedMessages;
2028 input_len = atoi(optarg);
2029 if (input_len > GSM_MAX_CONCATENATED_SMS_LENGTH) {
2030 fprintf(stderr, _("Input too long, max %i!\n"),GSM_MAX_CONCATENATED_SMS_LENGTH);
2035 case '4': /* SMS enables voice indicator */
2036 SMSUDHType=GSM_EnableVoice; break;
2038 case '5': /* SMS disables voice indicator */
2039 SMSUDHType=GSM_DisableVoice; break;
2041 case '6': /* SMS enables email indicator */
2042 SMSUDHType=GSM_EnableEmail; break;
2044 case '7': /* SMS disables email indicator */
2045 SMSUDHType=GSM_DisableEmail; break;
2047 case '8': /* SMS enables fax indicator */
2048 SMSUDHType=GSM_EnableFax; break;
2050 case '9': /* SMS disables fax indicator */
2051 SMSUDHType=GSM_DisableFax; break;
2053 case '-': /* SMS coding type */
2054 SMSCoding=GSM_Coding_Unicode; break;
2056 case '+': /* SMS ghost */
2057 SMSUDHType=GSM_VoidSMS; break;
2059 case '(': /* SMS hanging phone, when saved to Outbox */
2060 SMSUDHType=GSM_HangSMS; break;
2062 case ')': /* SMS showed incorrectly in phone */
2063 SMSUDHType=GSM_BugSMS; break;
2065 case 'r': /* mark as read */
2066 SMSStatus = GSS_SENTREAD; break;
2068 case 'i': /* Save into Inbox */
2069 SMSFolder = GST_INBOX; break;
2071 case 's': /* Set replying via the same SMSC */
2072 SMSReply = true; break;
2074 case 'a': /* Ask before overwriting */
2075 interactive=true;break;
2077 case 'l': /* Specify location */
2078 SMSLocation = atoi(optarg); break;
2080 case '/': /* Name */
2081 strncpy(SMSName,optarg,25);break;
2083 case 'C': /* class Message */
2085 if (SMSUDHType!=GSM_NoUDH) {
2086 fprintf(stderr, _("Can't specify SMS Class with --enablevoice, --disablevoice, --enableemail, --disableemail, --enablefax, --disablefax options !\n"));
2091 case '0': SMSClass = 0; break;
2092 case '1': SMSClass = 1; break;
2093 case '2': SMSClass = 2; break;
2094 case '3': SMSClass = 3; break;
2096 fprintf(stderr, _("SMS Class (\"C\" option) can be 0, 1, 2 or 3 only !\n"));
2101 case 'F': /* save into folder n */
2102 SMSFolder = atoi(optarg);
2106 fprintf(stderr,_("Unknown option number %i\n"),argc);
2112 /* Get message text from stdin. */
2113 chars_read = fread(message_buffer, 1, input_len, stdin);
2115 if (chars_read == 0) {
2116 fprintf(stderr, _("Couldn't read from stdin!\n"));
2119 if (chars_read > input_len) {
2120 fprintf(stderr, _("Input too long!\n"));
2124 /* Null terminate. */
2125 message_buffer[chars_read] = 0x00;
2127 GSM_MakeMultiPartSMS2(&MultiSMS,message_buffer,chars_read,SMSUDHType,SMSCoding);
2128 msgnum=MultiSMS.number;
2130 switch (SMSUDHType) {
2135 case GSM_EnableVoice:
2136 case GSM_DisableVoice:
2138 case GSM_DisableFax:
2139 case GSM_EnableEmail:
2140 case GSM_DisableEmail:
2141 fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText));
2148 for (i=0;i<msgnum;i++) {
2149 MultiSMS.SMS[i].Destination[0]=0;
2150 if (argc!=0) strcpy(MultiSMS.SMS[i].Destination,argv[0]);
2152 MultiSMS.SMS[i].Location=0;
2153 MultiSMS.SMS[i].Class=SMSClass;
2154 MultiSMS.SMS[i].MessageCenter.No=SMSCenter;
2155 strcpy(MultiSMS.SMS[i].MessageCenter.Number,SMSCNumber);
2156 MultiSMS.SMS[i].Status=SMSStatus;
2157 strcpy(MultiSMS.SMS[i].Name,SMSName);
2158 MultiSMS.SMS[i].folder=SMSFolder;
2159 MultiSMS.SMS[i].ReplyViaSameSMSC=SMSReply;
2162 MultiSMS.SMS[0].Location=SMSLocation;
2164 /* Initialise the GSM interface. */
2167 MultiSMS.number=msgnum;
2168 GSM_SaveMultiPartSMSOnConsole(&MultiSMS, 0,0,NULL,interactive,false,false,false);
2173 /* Get SMSC number */
2175 int getsmsc(char *MessageCenterNumber)
2178 GSM_MessageCenter MessageCenter;
2180 MessageCenter.No=atoi(MessageCenterNumber);
2184 if (GSM->GetSMSCenter(&MessageCenter) == GE_NONE) {
2186 fprintf(stdout, _("%d. SMS center ("),MessageCenter.No);
2188 if (!strcmp(MessageCenter.Name,""))
2189 fprintf(stdout,_("Set %d"),MessageCenter.No);
2190 else fprintf(stdout,_("%s"),MessageCenter.Name);
2192 fprintf(stdout,_(") number is "));
2194 if (!strcmp(MessageCenter.Number,"")) fprintf(stdout,_("not set\n"));
2195 else fprintf(stdout,_("%s\n"),MessageCenter.Number);
2197 fprintf(stdout,_("Default recipient number is "));
2199 if (!strcmp(MessageCenter.DefaultRecipient,""))
2200 fprintf(stdout,_("not set\n"));
2201 else fprintf(stdout,_("%s\n"),MessageCenter.DefaultRecipient);
2203 fprintf(stdout, _("Messages sent as "));
2205 switch (MessageCenter.Format) {
2206 case GSMF_Text :fprintf(stdout, _("Text"));break;
2207 case GSMF_Paging:fprintf(stdout, _("Paging"));break;
2208 case GSMF_Fax :fprintf(stdout, _("Fax"));break;
2210 case GSMF_UCI :fprintf(stdout, _("Email"));break;
2211 case GSMF_ERMES :fprintf(stdout, _("ERMES"));break;
2212 case GSMF_X400 :fprintf(stdout, _("X.400"));break;
2213 default :fprintf(stdout, _("Unknown"));
2218 fprintf(stdout, _("Message validity is "));
2220 switch (MessageCenter.Validity) {
2221 case GSMV_1_Hour :fprintf(stdout, _("1 hour"));break;
2222 case GSMV_6_Hours :fprintf(stdout, _("6 hours"));break;
2223 case GSMV_24_Hours:fprintf(stdout, _("24 hours"));break;
2224 case GSMV_72_Hours:fprintf(stdout, _("72 hours"));break;
2225 case GSMV_1_Week :fprintf(stdout, _("1 week"));break;
2226 case GSMV_Max_Time:fprintf(stdout, _("Maximum time"));break;
2227 default :fprintf(stdout, _("Unknown"));
2230 fprintf(stdout, "\n");
2234 fprintf(stdout, _("SMS center can not be found :-(\n"));
2241 /* Get SMS messages. */
2242 int getsms(int argc, char *argv[])
2245 GSM_SMSMessage message;
2246 GSM_WAPBookmark bookmark;
2247 char memory_type_string[20];
2248 int start_message, end_message, count, mode = 1;
2252 GSM_Ringtone ringtone;
2253 GSM_SMSFolders folders;
2255 int confirm = -1, i;
2258 /* Handle command line args that set type, start and end locations. */
2259 if (!GetMemoryTypeID(argv[2], &message.MemoryType))
2261 fprintf(stderr, _("Unknown memory type %s!\n"), argv[2]);
2264 GetMemoryTypeString(memory_type_string, &message.MemoryType);
2266 for (i=0;i<64;i++) filename[i]=0;
2268 start_message = atoi(argv[3]);
2272 /* [end] can be only argv[4] */
2273 if (argv[4][0] == '-') { end_message = start_message; }
2274 else { end_message = atoi(argv[4]); }
2276 /* parse all options (beginning with '-' */
2277 while ((i = getopt(argc, argv, "f:")) != -1) {
2282 fprintf(stderr, _("Saving into file \"%s\"\n"), optarg);
2284 strncpy(filename, optarg, 64);
2285 if (strlen(optarg) > 63) {
2286 fprintf(stderr, _("Filename too long - will be truncated to 63 characters.\n"));
2289 filename[strlen(optarg)] = 0;
2302 end_message = start_message;
2305 /* Initialise the code for the GSM interface. */
2309 GSM->GetSMSFolders(&folders);
2312 /* Now retrieve the requested entries. */
2314 for (count = start_message; count <= end_message; count ++) {
2316 message.Location = count;
2318 error = GSM->GetSMSMessage(&message);
2324 switch (message.Type) {
2328 /* RTH FIXME: Test that out ! */
2329 fprintf(stdout, _("%d. Delivery Report "), message.MessageNumber);
2330 switch (message.Status)
2333 if (message.folder==0) fprintf(stdout, _("(read)\n")); //GST_INBOX
2334 else fprintf(stdout, _("(sent)\n"));
2336 case GSS_NOTSENTREAD:
2337 if (message.folder==0) fprintf(stdout, _("(unread)\n")); //GST_INBOX
2338 else fprintf(stdout, _("(not sent)\n"));
2341 fprintf(stdout, _("(not known :-()\n"));
2344 fprintf(stdout, _("(template)\n"));
2347 fprintf(stdout, _("(unknown: %d)\n"),message.Status);
2351 fprintf(stdout, _("Sending date/time : %s %02d/%02d/%02d %d:%02d:%02d "), \
2352 DayOfWeek(message.Time.Year, message.Time.Month, message.Time.Day), \
2353 message.Time.Day, message.Time.Month, message.Time.Year, \
2354 message.Time.Hour, message.Time.Minute, message.Time.Second);
2356 if (message.Time.Timezone) {
2357 if (message.Time.Timezone > 0)
2358 fprintf(stdout,_("+%02d00"), message.Time.Timezone);
2360 fprintf(stdout,_("%02d00"), message.Time.Timezone);
2363 fprintf(stdout, "\n");
2365 fprintf(stdout, _("Response date/time: %s %02d/%02d/%02d %d:%02d:%02d "), \
2366 DayOfWeek(message.SMSCTime.Year, message.SMSCTime.Month, message.SMSCTime.Day), \
2367 message.SMSCTime.Day, message.SMSCTime.Month, message.SMSCTime.Year, \
2368 message.SMSCTime.Hour, message.SMSCTime.Minute, message.SMSCTime.Second);
2370 if (message.SMSCTime.Timezone) {
2371 if (message.SMSCTime.Timezone > 0)
2372 fprintf(stdout,_("+%02d00"),message.SMSCTime.Timezone);
2374 fprintf(stdout,_("%02d00"),message.SMSCTime.Timezone);
2377 fprintf(stdout, "\n");
2379 fprintf(stdout, _("Receiver: %s Msg Center: %s\n"), message.Sender, message.MessageCenter.Number);
2380 fprintf(stdout, _("Text: %s\n\n"), message.MessageText);
2385 fprintf(stdout, _("%d. %s Message "), message.MessageNumber,
2386 folders.Folder[message.folder].Name);
2388 switch (message.Status)
2391 if (message.folder==0) fprintf(stdout, _("(read)\n")); //GST_INBOX
2392 else fprintf(stdout, _("(sent)\n"));
2394 case GSS_NOTSENTREAD:
2395 if (message.folder==0) fprintf(stdout, _("(unread)\n")); //GST_INBOX
2396 else fprintf(stdout, _("(not sent)\n"));
2399 fprintf(stdout, _("(not known :-()\n"));
2402 fprintf(stdout, _("(template)\n"));
2405 fprintf(stdout, _("(unknown: %d)\n"),message.Status);
2409 /* RTH FIXME: date for other status ok ? */
2410 if (message.SMSData) {
2412 fprintf(stdout, _("Date/time: %s %02d/%02d/%02d %d:%02d:%02d "), \
2413 DayOfWeek(message.Time.Year, message.Time.Month, message.Time.Day), \
2414 message.Time.Day, message.Time.Month, message.Time.Year, \
2415 message.Time.Hour, message.Time.Minute, message.Time.Second);
2417 if (message.Time.Timezone) {
2418 if (message.Time.Timezone > 0)
2419 fprintf(stdout,_("+%02d00"),message.Time.Timezone);
2421 fprintf(stdout,_("%02d00"),message.Time.Timezone);
2424 fprintf(stdout, "\n");
2426 fprintf(stdout, _("Msg Center: %s "), message.MessageCenter.Number);
2428 if (message.ReplyViaSameSMSC)
2429 fprintf(stdout, _("(centre set for reply) "));
2432 if (strcmp(message.Sender,"")) {
2433 if (message.folder==1) { //GST_OUTBOX
2434 fprintf(stdout, _("Recipient: %s"),message.Sender);
2436 fprintf(stdout, _("Sender: %s"),message.Sender);
2440 if (strcmp(message.Sender,"") || message.folder==0)
2441 fprintf(stdout, "\n");
2443 switch (message.UDHType) {
2447 /* put bitmap into bitmap structure */
2448 switch (GSM_ReadBitmap(&message, &bitmap)) {
2449 case GE_INVALIDIMAGESIZE:
2450 fprintf(stdout,_("Image size not supported\n"));
2453 fprintf(stdout, _("GSM operator logo for %s (%s) network.\n"), bitmap.netcode, GSM_GetNetworkName(bitmap.netcode));
2455 GSM_PrintBitmap(&bitmap);
2457 if (filename[0]!=0) {
2458 GSM_SaveBitmapFileOnConsole(filename, &bitmap);
2463 fprintf(stdout,_("Error reading image\n"));
2468 if (message.folder==0) { //GST_INBOX
2469 if (!strcmp(message.Sender, "+998000005") &&
2470 !strcmp(message.MessageCenter.Number, "+886935074443") &&
2471 message.Time.Day==27 &&
2472 message.Time.Month==7 &&
2473 message.Time.Year==99 &&
2474 message.Time.Hour==0 &&
2475 message.Time.Minute==10 &&
2476 message.Time.Second==48) fprintf(stdout, _("Saved by Logo Express\n"));
2478 /* Is it changed in next versions ? Or what ? */
2479 if (!strcmp(message.Sender, "+998000002") ||
2480 !strcmp(message.Sender, "+998000003") ||
2481 !strcmp(message.Sender, "+998000004")) fprintf(stdout, _("Saved by Operator Logo Uploader by Thomas Kessler\n"));
2483 if (!strcmp(message.Sender, "+8861234567890") &&
2484 !strcmp(message.MessageCenter.Number, "+886935074443")) fprintf(stdout, _("Saved by Logo Express\n"));
2486 if (!strncmp(message.Sender, "OpLogo",6) &&
2487 strlen(message.Sender)==11)
2488 fprintf(stdout, _("Saved by gnokii\n"));
2493 case GSM_WAPBookmarkUDH:
2495 /* put bookmark into bookmark structure */
2496 switch (GSM_ReadWAPBookmark(&message, &bookmark)) {
2498 fprintf(stdout, ("WAP Bookmark\n"));
2500 fprintf(stdout,_("Address: \"%s\"\n"),bookmark.address);
2502 if (bookmark.title[0]==0)
2503 fprintf(stdout,_("Title: \"%s\"\n"),bookmark.address);
2505 fprintf(stdout,_("Title: \"%s\"\n"),bookmark.title);
2509 fprintf(stdout,_("Error reading WAP Bookmark\n"));
2514 if (!strcmp(message.Sender, "WAPBookmark"))
2515 fprintf(stdout, _("Saved by gnokii\n"));
2520 case GSM_CallerIDLogo:
2522 /* put bitmap into bitmap structure */
2523 switch (GSM_ReadBitmap(&message, &bitmap)) {
2524 case GE_INVALIDIMAGESIZE:
2525 fprintf(stdout,_("Image size not supported\n"));
2528 fprintf(stdout, ("Caller Logo\n"));
2530 GSM_PrintBitmap(&bitmap);
2532 if (filename[0]!=0) {
2533 GSM_SaveBitmapFileOnConsole(filename, &bitmap);
2538 fprintf(stdout,_("Error reading image\n"));
2543 if (message.folder==0) { //GST_INBOX
2544 if (!strcmp(message.Sender, "+998000005") &&
2545 !strcmp(message.MessageCenter.Number, "+886935074443") &&
2546 message.Time.Day==27 &&
2547 message.Time.Month==7 &&
2548 message.Time.Year==99 &&
2549 message.Time.Hour==0 &&
2550 message.Time.Minute==10 &&
2551 message.Time.Second==48) fprintf(stdout, _("Saved by Logo Express\n"));
2553 if (!strcmp(message.Sender, "+8861234567890") &&
2554 !strcmp(message.MessageCenter.Number, "+886935074443")) fprintf(stdout, _("Saved by Logo Express\n"));
2556 if (!strcmp(message.Sender, "GroupLogo"))
2557 fprintf(stdout, _("Saved by gnokii\n"));
2562 case GSM_ProfileUDH:
2563 fprintf(stdout, ("Profile SMS, part %i/%i\n"),message.UDH[11],message.UDH[10]);
2566 case GSM_WAPBookmarkUDHLong:
2567 fprintf(stdout, ("WAP Bookmark, part %i/%i\n"),message.UDH[11],message.UDH[10]);
2570 case GSM_WAPSettingsUDH:
2571 fprintf(stdout, ("WAP Settings, part %i/%i\n"),message.UDH[11],message.UDH[10]);
2574 case GSM_RingtoneUDH:
2576 /* put ringtone into ringtone structure */
2577 switch (GSM_ReadRingtone(&message, &ringtone)) {
2580 fprintf(stdout, ("Ringtone \"%s\"\n"),ringtone.name);
2582 while (confirm < 0) {
2583 fprintf(stderr, _("Do you want to play it ? (yes/no) "));
2584 GetLine(stdin, ans, 7);
2585 if (!strcmp(ans, "yes")) confirm = 1;
2586 if (!strcmp(ans, "no")) confirm = 0;
2589 if (confirm==1) GSM_PlayRingtoneOnConsole(&ringtone);
2591 if (filename[0]!=0) GSM_SaveRingtoneFileOnConsole(filename, &ringtone);
2596 fprintf(stdout,_("Gnokii can't read this ringtone - there is probably error inside\n"));
2602 case GSM_CalendarNoteUDH:
2603 fprintf(stdout, ("Calendar note SMS, part %i/%i\n"),message.UDH[11],message.UDH[10]);
2604 fprintf(stdout, _("Text:\n%s\n\n"), message.MessageText);
2605 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2608 case GSM_ConcatenatedMessages:
2609 fprintf(stdout, _("Linked (%d/%d)\nText:\n%s\n\n"),message.UDH[5],message.UDH[4], message.MessageText);
2610 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2613 case GSM_EnableVoice:
2614 fprintf(stdout, _("Enables voice indicator\nText:\n%s\n\n"), message.MessageText);
2615 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2618 case GSM_DisableVoice:
2619 fprintf(stdout, _("Disables voice indicator\nText:\n%s\n\n"), message.MessageText);
2620 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2624 fprintf(stdout, _("Enables fax indicator\nText:\n%s\n\n"), message.MessageText);
2625 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2628 case GSM_DisableFax:
2629 fprintf(stdout, _("Disables fax indicator\nText:\n%s\n\n"), message.MessageText);
2630 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2633 case GSM_EnableEmail:
2634 fprintf(stdout, _("Enables email indicator\nText:\n%s\n\n"), message.MessageText);
2635 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2638 case GSM_DisableEmail:
2639 fprintf(stdout, _("Disables email indicator\nText:\n%s\n\n"), message.MessageText);
2640 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2644 fprintf(stdout, _("Void SMS\nText:\n%s\n\n"), message.MessageText);
2645 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2649 if (message.Coding!=GSM_Coding_8bit) {
2650 fprintf(stdout, _("Text:\n%s\n\n"), message.MessageText);
2651 if (filename[0]!=0 && mode != -1) mode = GSM_SaveTextFileOnConsole(filename, message.MessageText, mode);
2653 fprintf(stdout, _("Message cannot be displayed here\n")); // like in phone :-)
2657 default: //GSM_UnknownUDH and other
2658 fprintf(stderr, _("Unknown\n"));
2664 fprintf(stdout,_("Unknown SMS type. Report it\n"));
2670 case GE_NOTIMPLEMENTED:
2672 fprintf(stderr, _("Function not implemented in %s model!\n"), model);
2676 case GE_INVALIDSMSLOCATION:
2678 fprintf(stderr, _("Invalid location: %s %d\n"), memory_type_string, count);
2682 case GE_EMPTYSMSLOCATION:
2684 fprintf(stderr, _("SMS location %s %d empty.\n"), memory_type_string, count);
2690 fprintf(stderr, _("No access to %s memory.\n"), memory_type_string);
2696 fprintf(stderr, _("GetSMS %s %d failed!(%d)\n\n"), memory_type_string, count, error);
2705 int getsmsstatus(int argc, char *argv[])
2707 GSM_SMSStatus SMSStatus;
2708 GSM_SMSFolders folders;
2714 /* Initialise the code for the GSM interface. */
2717 error = GSM->GetSMSStatus(&SMSStatus);
2718 if (error!=GE_NONE) return error;
2720 fprintf(stdout, _("SMS Messages: UnRead %d, Number %d\n"),SMSStatus.UnRead, SMSStatus.Number);
2722 error=GSM->GetSMSFolders(&folders);
2723 if (error!=GE_NONE) return error;
2725 /* For not 7110 compatible phones we have to read all SMS and prepare sms table */
2726 if( GetModelFeature (FN_SMS)!=F_SMS71 )
2730 if (j==SMSStatus.Number) break;
2732 if (GSM->GetSMSMessage(&SMS)==GE_NONE) {
2733 SMSStatus.foldertable[j].smsnum=i;
2735 /* We set such folders ID like in 7110 compatible phones */
2736 if (SMS.Status==GSS_NOTSENTREAD && SMS.folder==0) //GST_INBOX
2737 SMSStatus.foldertable[j].folder=0;
2739 switch (SMS.folder) {
2741 SMSStatus.foldertable[j].folder=GST_7110_INBOX;
2744 SMSStatus.foldertable[j].folder=GST_7110_OUTBOX;
2754 printf("0.Unread : ");
2755 for(j=0; j<SMSStatus.Number; j++)
2757 if (SMSStatus.foldertable[j].folder == 0)
2758 printf("%d ",SMSStatus.foldertable[j].smsnum);
2762 for (i=0;i<folders.number;i++) {
2763 fprintf(stdout,_("%d.%-15s: "),i+1,folders.Folder[i].Name);
2764 for(j=0; j<SMSStatus.Number; j++)
2766 if ( SMSStatus.foldertable[j].folder / 8 == i+1)
2767 printf("%d ",SMSStatus.foldertable[j].smsnum);
2777 /* Delete SMS messages. */
2778 int deletesms(int argc, char *argv[])
2781 GSM_SMSMessage message;
2782 char memory_type_string[20];
2783 int start_message, end_message, count;
2786 /* Handle command line args that set type, start and end locations. */
2787 if (!GetMemoryTypeID(argv[0], &message.MemoryType))
2789 fprintf(stderr, _("Unknown memory type %s!\n"), argv[0]);
2792 GetMemoryTypeString(memory_type_string, &message.MemoryType);
2794 start_message = atoi (argv[1]);
2795 if (argc > 2) end_message = atoi (argv[2]);
2796 else end_message = start_message;
2798 /* Initialise the code for the GSM interface. */
2802 /* Now delete the requested entries. */
2804 for (count = start_message; count <= end_message; count ++) {
2806 message.Location = count;
2808 error = GSM->DeleteSMSMessage(&message);
2810 if (error == GE_NONE)
2811 fprintf(stdout, _("Deleted SMS %s %d\n"), memory_type_string, count);
2813 if (error == GE_NOTIMPLEMENTED) {
2814 fprintf(stderr, _("Function not implemented in %s model!\n"), model);
2818 fprintf(stdout, _("DeleteSMS %s %d failed!(%d)\n\n"), memory_type_string, count, error);
2827 static volatile bool bshutdown = false;
2829 /* SIGINT signal handler. */
2831 static void interrupted(int sig)
2834 signal(sig, SIG_IGN);
2841 /* In this mode we get the code from the keyboard and send it to the mobile
2844 int entersecuritycode(char *type)
2847 GSM_SecurityCode SecurityCode;
2849 if (!strcmp(type,"PIN")) SecurityCode.Type=GSCT_Pin;
2850 else if (!strcmp(type,"PUK")) SecurityCode.Type=GSCT_Puk;
2851 else if (!strcmp(type,"PIN2"))SecurityCode.Type=GSCT_Pin2;
2852 else if (!strcmp(type,"PUK2"))SecurityCode.Type=GSCT_Puk2;
2854 // FIXME: Entering of SecurityCode does not work :-(
2855 // else if (!strcmp(type,"SecurityCode"))
2856 // SecurityCode.Type=GSCT_SecurityCode;
2859 fprintf(stdout, _("Wrong code in second parameter (allowed: PIN,PUK,PIN2,PUK2,SecurityCode)\n"));
2864 printf("Enter your code: ");
2865 gets(SecurityCode.Code);
2867 strcpy(SecurityCode.Code,getpass(_("Enter your code: ")));
2872 test = GSM->EnterSecurityCode(SecurityCode);
2874 fprintf(stdout,_("Code OK !\n"));
2876 fprintf(stderr,_("%s\n"),print_error(test));
2883 int getsecuritycodestatus(void)
2890 if (GSM->GetSecurityCodeStatus(&Status) == GE_NONE) {
2892 fprintf(stdout, _("Security code status: "));
2895 case GSCT_SecurityCode:fprintf(stdout, _("waiting for Security Code.\n"));break;
2896 case GSCT_Pin: fprintf(stdout, _("waiting for PIN.\n")); break;
2897 case GSCT_Pin2: fprintf(stdout, _("waiting for PIN2.\n")); break;
2898 case GSCT_Puk: fprintf(stdout, _("waiting for PUK.\n")); break;
2899 case GSCT_Puk2: fprintf(stdout, _("waiting for PUK2.\n")); break;
2900 case GSCT_None: fprintf(stdout, _("nothing to enter.\n")); break;
2901 default: fprintf(stdout, _("Unknown!\n"));
2910 int getsecuritycode(char *type)
2913 GSM_SecurityCode SecurityCode;
2916 if (!strcmp(type,"PIN")) SecurityCode.Type=GSCT_Pin;
2917 else if (!strcmp(type,"PUK")) SecurityCode.Type=GSCT_Puk;
2918 else if (!strcmp(type,"PIN2")) SecurityCode.Type=GSCT_Pin2;
2919 else if (!strcmp(type,"PUK2")) SecurityCode.Type=GSCT_Puk2;
2920 else if (!strcmp(type,"SecurityCode"))SecurityCode.Type=GSCT_SecurityCode;
2922 fprintf(stdout, _("Wrong code in second parameter (allowed: PIN,PUK,PIN2,PUK2,SecurityCode)\n"));
2928 error=GSM->GetSecurityCode(&SecurityCode);
2931 case GE_INVALIDSECURITYCODE:
2932 fprintf(stdout, _("Error: getting "));
2933 switch (SecurityCode.Type) {
2934 case GSCT_SecurityCode:fprintf(stdout, _("security code"));break;
2935 case GSCT_Pin :fprintf(stdout, _("PIN"));break;
2936 case GSCT_Pin2:fprintf(stdout, _("PIN2"));break;
2937 case GSCT_Puk :fprintf(stdout, _("PUK"));break;
2938 case GSCT_Puk2:fprintf(stdout, _("PUK2"));break;
2941 fprintf(stdout, _(" not allowed\n"));
2944 switch (SecurityCode.Type) {
2945 case GSCT_SecurityCode:fprintf(stdout, _("Security code"));break;
2946 case GSCT_Pin :fprintf(stdout, _("PIN"));break;
2947 case GSCT_Pin2:fprintf(stdout, _("PIN2"));break;
2948 case GSCT_Puk :fprintf(stdout, _("PUK"));break;
2949 case GSCT_Puk2:fprintf(stdout, _("PUK2"));break;
2952 fprintf(stdout, _(" is %s\n"),SecurityCode.Code);
2955 fprintf(stderr, _("%s\n"),print_error(error));
2966 /* Voice dialing mode. */
2968 int dialvoice(char *Number)
2972 if (GSM->DialVoice(Number)!=GE_NONE) fprintf(stdout,_("Error!\n"));
2979 #endif /* UCLINUX */
2982 static int cancelcall(void)
2986 if (GSM->CancelCall()!=GE_NONE) fprintf(stdout,_("Error!\n"));
2995 int savelogo(int argc, char *argv[])
2998 GSM_NetworkInfo NetworkInfo;
2999 GSM_MultiSMSMessage MultiSMS;
3001 /* Operator logos will be saved with this number */
3002 char oplogonumber[]={'O','p','L','o','g','o',
3003 '0','0','0','0','0', /* MMC+MNC */
3007 bool UnicodeText=false;
3009 /* The first argument is the type of the logo. */
3010 if (!strcmp(argv[0], "op")) {
3011 fprintf(stdout, _("Saving operator logo.\n"));
3012 } else if (!strcmp(argv[0], "caller")) {
3013 fprintf(stdout, _("Saving caller line identification logo.\n"));
3014 } else if (!strcmp(argv[0], "startup")) {
3015 fprintf(stderr, _("It isn't possible to save startup logo!\n"));
3017 } else if (!strcmp(argv[0], "7110startup")) {
3018 fprintf(stderr, _("It isn't possible to save startup logo!\n"));
3020 } else if (!strcmp(argv[0], "6210startup")) {
3021 fprintf(stderr, _("It isn't possible to save startup logo!\n"));
3023 } else if (!strcmp(argv[0], "7110op")) {
3024 fprintf(stderr, _("It isn't possible to save big operator logos!\n"));
3026 } else if (!strcmp(argv[0], "picture")) {
3027 fprintf(stderr, _("Saving picture image.\n"));
3028 } else if (!strcmp(argv[0], "screensaver")) {
3029 fprintf(stderr, _("Saving screen saver.\n"));
3031 fprintf(stderr, _("You should specify what kind of logo to save!\n"));
3035 /* The second argument is the bitmap file. */
3036 if (GSM_ReadBitmapFileOnConsole(argv[1], &bitmap)!=GE_NONE) return -1;
3038 /* Initialise the GSM interface. */
3041 /* We check optional parameters from 2'rd */
3044 if (!strcmp(argv[0], "op")) {
3045 GSM_ResizeBitmap(&bitmap,GSM_CallerLogo);
3047 /* The third argument, if present, is the Network code of the operator.
3048 * Network code is in this format: "xxx yy" */
3050 strcpy(bitmap.netcode, argv[2]);
3052 fprintf(stdout, _("Operator code: %s\n"), argv[2]);
3054 if (!strcmp(GSM_GetNetworkName(bitmap.netcode),"unknown")) {
3055 fprintf(stderr,"Sorry, gnokii doesn't know \"%s\" network !\n",bitmap.netcode);
3062 if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode,NetworkInfo.NetworkCode,7);
3064 bitmap.type=GSM_OperatorLogo;
3066 /* Put bitmap into SMS structure */
3067 GSM_SaveBitmapToSMS(&MultiSMS,&bitmap,false,false);
3069 oplogonumber[6]=bitmap.netcode[0];
3070 oplogonumber[7]=bitmap.netcode[1];
3071 oplogonumber[8]=bitmap.netcode[2];
3072 oplogonumber[9]=bitmap.netcode[4];
3073 oplogonumber[10]=bitmap.netcode[5];
3074 for(i=0;i<MultiSMS.number;i++)
3075 strcpy(MultiSMS.SMS[i].Destination,oplogonumber);
3077 if (!strcmp(argv[0], "caller")) {
3078 GSM_ResizeBitmap(&bitmap,GSM_CallerLogo);
3080 bitmap.type=GSM_CallerLogo;
3082 /* Put bitmap into SMS structure */
3083 GSM_SaveBitmapToSMS(&MultiSMS,&bitmap,false,false);
3085 for(i=0;i<MultiSMS.number;i++)
3086 strcpy(MultiSMS.SMS[i].Destination,"GroupLogo");
3088 if (!strcmp(argv[0], "screensaver")) {
3089 GSM_ResizeBitmap(&bitmap,GSM_PictureImage);
3094 if (!strcmp(argv[i],"--unicode")) UnicodeText=true;
3096 /* Put bitmap into SMS structure */
3097 GSM_SaveBitmapToSMS(&MultiSMS,&bitmap,true,UnicodeText);
3099 for(i=0;i<MultiSMS.number;i++)
3100 strcpy(MultiSMS.SMS[i].Destination,"ScreenSaver");
3102 if (!strcmp(argv[0], "picture")) {
3103 GSM_ResizeBitmap(&bitmap,GSM_PictureImage);
3106 if (!strcmp(argv[i],"--unicode")) UnicodeText=true;
3111 if (strlen(argv[2])>121) {
3112 fprintf(stdout,_("Sorry: length of text (parameter \"%s\") can be 121 chars or shorter only !\n"),argv[2]);
3115 strcpy(bitmap.text,argv[2]);
3118 /* Put bitmap into SMS structure */
3119 GSM_SaveBitmapToSMS(&MultiSMS,&bitmap,false,UnicodeText);
3121 for(i=0;i<MultiSMS.number;i++)
3122 strcpy(MultiSMS.SMS[i].Destination,"Picture");
3125 GSM_SaveMultiPartSMSOnConsole(&MultiSMS, optind,argc,argv,false,true,false,false);
3130 /* The following function allows to send logos using SMS */
3131 int sendlogo(int argc, char *argv[])
3134 GSM_NetworkInfo NetworkInfo;
3135 GSM_MultiSMSMessage MultiSMS;
3139 bool UnicodeText=false;
3140 bool ScreenSaver=false;
3142 /* The first argument is the type of the logo. */
3143 if (!strcmp(argv[0], "op")) {
3144 fprintf(stdout, _("Sending operator logo.\n"));
3145 } else if (!strcmp(argv[0], "caller")) {
3146 fprintf(stdout, _("Sending caller line identification logo.\n"));
3147 } else if (!strcmp(argv[0], "picture")) {
3148 fprintf(stdout, _("Sending picture image.\n"));
3149 } else if (!strcmp(argv[0], "screensaver")) {
3150 fprintf(stdout, _("Sending screen saver.\n"));
3151 } else if (!strcmp(argv[0], "startup")) {
3152 fprintf(stderr, _("It isn't possible to send startup logo!\n"));
3154 } else if (!strcmp(argv[0], "7110startup")) {
3155 fprintf(stderr, _("It isn't possible to send startup logo!\n"));
3157 } else if (!strcmp(argv[0], "6210startup")) {
3158 fprintf(stderr, _("It isn't possible to send startup logo!\n"));
3160 } else if (!strcmp(argv[0], "7110op")) {
3161 fprintf(stderr, _("It isn't possible to send big operator logos!\n"));
3164 fprintf(stderr, _("You should specify what kind of logo to send!\n"));
3168 /* The third argument is the bitmap file. */
3169 if (GSM_ReadBitmapFileOnConsole(argv[2], &bitmap)!=GE_NONE) return -1;
3171 /* Initialise the GSM interface. */
3176 if (!strcmp(argv[0], "op")) {
3177 GSM_ResizeBitmap(&bitmap,GSM_CallerLogo);
3179 /* The third argument, if present, is the Network code of the operator.
3180 * Network code is in this format: "xxx yy" */
3182 strcpy(bitmap.netcode, argv[3]);
3184 fprintf(stdout, _("Operator code: %s\n"), argv[3]);
3186 if (!strcmp(GSM_GetNetworkName(bitmap.netcode),"unknown")) {
3187 fprintf(stderr,"Sorry, gnokii doesn't know \"%s\" network !\n",bitmap.netcode);
3194 if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode,NetworkInfo.NetworkCode,7);
3196 bitmap.type=GSM_OperatorLogo;
3198 if (!strcmp(argv[0], "caller")) {
3199 GSM_ResizeBitmap(&bitmap,GSM_CallerLogo);
3201 bitmap.type=GSM_CallerLogo;
3203 if (!strcmp(argv[0], "screensaver")) {
3204 GSM_ResizeBitmap(&bitmap,GSM_PictureImage);
3209 if (!strcmp(argv[i],"--unicode")) UnicodeText=true;
3213 if (!strcmp(argv[0], "picture")) {
3214 GSM_ResizeBitmap(&bitmap,GSM_PictureImage);
3217 if (!strcmp(argv[i],"--unicode")) UnicodeText=true;
3222 if (strlen(argv[3])>121) {
3223 fprintf(stdout,_("Sorry: length of text (parameter \"%s\") can be 121 chars or shorter only !\n"),argv[3]);
3226 strcpy(bitmap.text,argv[3]);
3230 /* Put bitmap into SMS structure */
3231 GSM_SaveBitmapToSMS(&MultiSMS,&bitmap,ScreenSaver,UnicodeText);
3233 /* The second argument is the destination, ie the phone number of recipient. */
3234 for(i=0;i<MultiSMS.number;i++)
3235 strcpy(MultiSMS.SMS[i].Destination,argv[1]);
3237 GSM_SendMultiPartSMSOnConsole(&MultiSMS, optind,argc,argv,true,false,false);
3242 /* Getting logos. */
3244 int getlogo(int argc, char *argv[])
3250 bitmap.type=GSM_None;
3252 if (!strcmp(argv[0],"7110op"))
3253 bitmap.type=GSM_7110OperatorLogo;
3255 if (!strcmp(argv[0],"op"))
3256 bitmap.type=GSM_OperatorLogo;
3258 if (!strcmp(argv[0],"caller")) {
3259 /* There is caller group number missing in argument list. */
3262 if ((num<1)||(num>9)) num=1;
3269 bitmap.type=GSM_CallerLogo;
3272 if (!strcmp(argv[0],"picture")) {
3273 /* There is a number missing in argument list. */
3275 if (strlen(argv[2])==2) {
3276 num=(argv[2][0]-'0')*10+(argv[2][1]-'0');
3287 bitmap.type=GSM_PictureImage;
3290 if (!strcmp(argv[0],"startup"))
3291 bitmap.type=GSM_StartupLogo;
3293 if (!strcmp(argv[0],"7110startup"))
3294 bitmap.type=GSM_7110StartupLogo;
3296 if (!strcmp(argv[0],"6210startup"))
3297 bitmap.type=GSM_6210StartupLogo;
3299 if (!strcmp(argv[0],"dealer"))
3300 bitmap.type=GSM_DealerNoteText;
3302 if (!strcmp(argv[0],"text"))
3303 bitmap.type=GSM_WelcomeNoteText;
3305 if (bitmap.type!=GSM_None) {
3309 fprintf(stdout, _("Getting Logo\n"));
3311 error=GSM->GetBitmap(&bitmap);
3318 if (bitmap.type==GSM_DealerNoteText) fprintf(stdout, _("Dealer welcome note "));
3319 if (bitmap.type==GSM_WelcomeNoteText) fprintf(stdout, _("Welcome note "));
3320 if (bitmap.type==GSM_DealerNoteText || bitmap.type==GSM_WelcomeNoteText)
3322 if (bitmap.text[0]!=0)
3324 fprintf(stdout, _("currently set to \"%s\"\n"), bitmap.text);
3326 fprintf(stdout, _("currently empty\n"));
3330 if (bitmap.width!=0)
3332 if (bitmap.type==GSM_OperatorLogo || bitmap.type==GSM_7110OperatorLogo)
3334 fprintf(stdout,"Operator logo for %s (%s) network got succesfully\n",bitmap.netcode,GSM_GetNetworkName(bitmap.netcode));
3336 if (bitmap.type==GSM_StartupLogo || bitmap.type==GSM_7110StartupLogo || bitmap.type==GSM_6210StartupLogo)
3338 fprintf(stdout,"Startup logo got successfully\n");
3340 if (bitmap.type==GSM_CallerLogo)
3342 fprintf(stdout,"Caller logo got successfully\n");
3344 if (bitmap.type==GSM_PictureImage)
3346 fprintf(stdout,"Picture Image got successfully");
3347 if (strcmp(bitmap.text,""))
3348 fprintf(stdout,_(", text \"%s\""),bitmap.text);
3349 if (strcmp(bitmap.Sender,""))
3350 fprintf(stdout,_(", sender \"%s\""),bitmap.Sender);
3351 fprintf(stdout,"\n");
3355 if (GSM_SaveBitmapFileOnConsole(argv[1], &bitmap)!=GE_NONE) return(-1);
3359 fprintf(stdout,"Your phone doesn't have logo uploaded !\n");
3364 case GE_NOTIMPLEMENTED:
3365 fprintf(stderr, _("Function not implemented !\n"));
3367 case GE_NOTSUPPORTED:
3368 fprintf(stderr, _("This kind of logo is not supported !\n"));
3371 fprintf(stderr, _("Error getting logo (wrong location ?) !\n"));
3376 fprintf(stderr, _("What kind of logo do you want to get ?\n"));
3383 /* Setting logos. */
3385 int setlogo(int argc, char *argv[])
3388 GSM_Bitmap bitmap,oldbit;
3389 GSM_NetworkInfo NetworkInfo;
3400 if (!strcmp(argv[0],"text") || !strcmp(argv[0],"dealer"))
3402 if (!strcmp(argv[0],"text")) bitmap.type=GSM_WelcomeNoteText;
3403 else bitmap.type=GSM_DealerNoteText;
3404 bitmap.text[0]=0x00;
3405 if (argc>1) strncpy(bitmap.text,argv[1],255);
3408 if (!strcmp(argv[0],"op") || !strcmp(argv[0],"startup") || !strcmp(argv[0],"caller") ||
3409 !strcmp(argv[0],"7110op") || !strcmp(argv[0],"6210startup") || !strcmp(argv[0],"7110startup") ||
3410 !strcmp(argv[0],"picture"))
3414 if (!strcmp(argv[0],"startup"))
3416 bitmap.type=GSM_StartupLogo;
3419 bitmap.size=GSM_GetBitmapSize(&bitmap);
3421 if (num>=1 && num<=3) {
3424 if (GSM_ReadBitmapFileOnConsole(argv[1], &bitmap)!=GE_NONE) {
3429 GSM_ResizeBitmap(&bitmap,GSM_StartupLogo);
3432 if (GSM_ReadBitmapFileOnConsole(argv[1], &bitmap)!=GE_NONE) {
3437 if (!strcmp(argv[0],"op"))
3439 if (bitmap.type!=GSM_OperatorLogo || argc<3)
3441 if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode,NetworkInfo.NetworkCode,7);
3443 GSM_ResizeBitmap(&bitmap,GSM_OperatorLogo);
3446 strncpy(bitmap.netcode,argv[2],7);
3447 if (!strcmp(GSM_GetNetworkName(bitmap.netcode),"unknown"))
3449 fprintf(stderr,"Sorry, gnokii doesn't know \"%s\" network !\n",bitmap.netcode);
3454 if (!strcmp(argv[0],"7110op"))
3456 if (bitmap.type!=GSM_7110OperatorLogo || argc<3)
3458 if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode,NetworkInfo.NetworkCode,7);
3460 GSM_ResizeBitmap(&bitmap,GSM_7110OperatorLogo);
3463 strncpy(bitmap.netcode,argv[2],7);
3464 if (!strcmp(GSM_GetNetworkName(bitmap.netcode),"unknown"))
3466 fprintf(stderr,"Sorry, gnokii doesn't know \"%s\" network !\n",bitmap.netcode);
3471 if (!strcmp(argv[0],"picture"))
3473 GSM_ResizeBitmap(&bitmap,GSM_PictureImage);
3477 if (strlen(argv[2])==2) {
3478 num=(argv[2][0]-'0')*10+(argv[2][1]-'0');
3488 strncpy(bitmap.text,argv[3],121);
3489 strcpy(bitmap.Sender,"\0");
3491 strncpy(bitmap.Sender,argv[4],GSM_MAX_SENDER_LENGTH);
3493 if (!strcmp(argv[0],"7110startup"))
3495 GSM_ResizeBitmap(&bitmap,GSM_7110StartupLogo);
3497 if (!strcmp(argv[0],"6210startup"))
3499 GSM_ResizeBitmap(&bitmap,GSM_6210StartupLogo);
3501 if (!strcmp(argv[0],"caller"))
3503 GSM_ResizeBitmap(&bitmap,GSM_CallerLogo);
3507 if ((num<0)||(num>9)) num=0;
3513 oldbit.type=GSM_CallerLogo;
3514 oldbit.number=bitmap.number;
3515 if (GSM->GetBitmap(&oldbit)==GE_NONE)
3517 /* We have to get the old name and ringtone!! */
3518 bitmap.ringtone=oldbit.ringtone;
3519 strncpy(bitmap.text,oldbit.text,255);
3521 if (argc>3) strncpy(bitmap.text,argv[3],255);
3523 fprintf(stdout, _("Setting Logo.\n"));
3526 /* FIX ME: is it possible to permanently remove op logo ? */
3527 if (!strcmp(argv[0],"op"))
3529 bitmap.type=GSM_OperatorLogo;
3530 strncpy(bitmap.netcode,"000 00",7);
3533 bitmap.size=GSM_GetBitmapSize(&bitmap);
3534 GSM_ClearBitmap(&bitmap);
3536 if (!strcmp(argv[0],"7110op"))
3538 bitmap.type=GSM_7110OperatorLogo;
3539 strncpy(bitmap.netcode,"000 00",7);
3542 bitmap.size=GSM_GetBitmapSize(&bitmap);
3543 GSM_ClearBitmap(&bitmap);
3545 /* FIX ME: how to remove startup and group logos ? */
3546 fprintf(stdout, _("Removing Logo.\n"));
3550 fprintf(stderr, _("What kind of logo do you want to set ?\n"));
3556 while (GSM->GetModel(model) != GE_NONE)
3559 /* For Nokia 6110/6130/6150 we use different method of uploading.
3560 Phone will display menu, when received it */
3561 if (!strcmp(model,"NSE-3") || !strcmp(model,"NSK-3") || !strcmp(model,"NSM-1"))
3563 if (!strcmp(argv[0],"caller") && argc<3)
3565 if (!strcmp(argv[0],"op") && argc<3)
3569 error=GSM->SetBitmap(&bitmap);
3573 case GE_NONE: oldbit.type=bitmap.type;
3574 oldbit.number=bitmap.number;
3575 if (GSM->GetBitmap(&oldbit)==GE_NONE) {
3576 if (bitmap.type==GSM_WelcomeNoteText ||
3577 bitmap.type==GSM_DealerNoteText) {
3578 if (strcmp(bitmap.text,oldbit.text)) {
3579 fprintf(stderr, _("Error setting"));
3580 if (bitmap.type==GSM_DealerNoteText) fprintf(stderr, _(" dealer"));
3581 fprintf(stderr, _(" welcome note - "));
3583 /* I know, it looks horrible, but... */
3584 /* I set it to the short string - if it won't be set */
3585 /* it means, PIN is required. If it will be correct, previous */
3586 /* (user) text was too long */
3588 /* Without it, I could have such thing: */
3589 /* user set text to very short string (for example, "Marcin") */
3590 /* then enable phone without PIN and try to set it to the very long (too long for phone) */
3591 /* string (which start with "Marcin"). If we compare them as only length different, we could think, */
3592 /* that phone accepts strings 6 chars length only (length of "Marcin") */
3593 /* When we make it correct, we don't have this mistake */
3595 strcpy(oldbit.text,"!\0");
3596 GSM->SetBitmap(&oldbit);
3597 GSM->GetBitmap(&oldbit);
3598 if (oldbit.text[0]!='!') {
3599 fprintf(stderr, _("SIM card and PIN is required\n"));
3601 GSM->SetBitmap(&bitmap);
3602 GSM->GetBitmap(&oldbit);
3603 fprintf(stderr, _("too long, truncated to \"%s\" (length %ld)\n"),oldbit.text,(long)strlen(oldbit.text));
3608 if (bitmap.type==GSM_StartupLogo) {
3609 for (i=0;i<oldbit.size;i++) {
3610 if (oldbit.bitmap[i]!=bitmap.bitmap[i]) {
3611 fprintf(stderr, _("Error setting startup logo - SIM card and PIN is required\n"));
3619 if (ok) fprintf(stdout, _("Done.\n"));
3621 case GE_NOTIMPLEMENTED:fprintf(stderr, _("Function not implemented.\n"));
3623 case GE_NOTSUPPORTED:fprintf(stderr, _("This kind of logo is not supported.\n"));
3625 default:fprintf(stderr, _("Error (wrong location ?) !\n"));
3634 /* Calendar notes receiving. */
3636 int getcalendarnote(int argc, char *argv[])
3638 GSM_CalendarNote CalendarNote;
3639 GSM_NotesInfo NotesInfo;
3645 bool was_note=false;
3646 char z_text[MAX_CALENDAR_TEXT_LENGTH+11];
3648 /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */
3656 now=localtime(&nowh);
3658 Date.Year = now->tm_year;
3660 /* I have 100 (for 2000) Year now :-) */
3661 if (Date.Year>99 && Date.Year<1900) {
3662 Date.Year=Date.Year+1900;
3665 start=atoi(argv[0]);
3670 if (!strcmp(argv[argc-1],"-v10")) {
3673 if (!strcmp(argv[argc-1],"-v30")) {
3682 if (!strcmp(argv[argc-1],"-v10")) {
3685 if (!strcmp(argv[argc-1],"-v30")) {
3697 while (GSM->GetModel(model) != GE_NONE)
3700 if (!strcmp(argv[0],"-s") || !strcmp(argv[0],"--short"))
3702 else if (!isdigit(argv[0][0])) {
3707 error=GSM->GetCalendarNotesInfo(&NotesInfo);
3708 if ( error == GE_NONE ) {
3709 if( NotesInfo.HowMany == 0 ) {
3710 fprintf(stderr, _("Sorry! No Calendar Notes present on phone.\n"));
3711 start=0; stop=(-1); /* This for skipping next 'for' loop ;-> */
3714 fprintf(stdout, _(" CALENDAR NOTES INFO \n"));
3715 fprintf(stdout, _("---------------------\n"));
3716 fprintf(stdout, _("How Many Locations :%d\n"), NotesInfo.HowMany);
3718 /* For 6210 (NPE-3) and 7110 (NSE-5), Locations have a different behaviour */
3719 if ( GetModelFeature (FN_CALENDAR)==F_CAL71 ) {
3720 fprintf(stdout, _("Locations are :\n"));
3721 for(i=0;i<NotesInfo.HowMany;i++)
3722 fprintf(stdout, _("%4d) %4d\n"), i+1, NotesInfo.Location[i]);
3726 /* For 6210 (NPE-3) and 7110 (NSE-5), Locations have a different behaviour */
3727 if ( GetModelFeature (FN_CALENDAR)==F_CAL71 ) {
3728 fprintf(stderr, _("Can't read Notes Infos from phone.\n"));
3729 start=0; stop=(-1); /* This for skipping next 'for' loop ;-> */
3733 if (GetModelFeature (FN_CALENDAR)!=F_CAL71) {
3735 NotesInfo.HowMany=200;
3736 for (i=0;i<200;i++) {
3737 NotesInfo.Location[i]=i+1;
3741 if( vInfo && stop!=(-1) && error==GE_NONE )
3743 /* Info datas (for 7110 and comp.) */
3744 fprintf(stdout, _(" CALENDAR NOTES SUMMARY INFORMATION \n"));
3745 fprintf(stdout, _(" ==================================\n"));
3746 if (GetModelFeature (FN_CALENDAR)==F_CAL71) {
3747 fprintf(stdout, _("Calendar notes present on phone: %d\n"), NotesInfo.HowMany);
3748 fprintf(stdout, _("Locations are :\n"));
3750 fprintf(stdout, "----------------------------------------------------------------------------\n");
3751 fprintf(stdout,_(" Loc Phys Type Summary description Dt start Alarm Recurs\n") );
3752 fprintf(stdout, "----------------------------------------------------------------------------\n");
3754 for(i=0;i<NotesInfo.HowMany;i++)
3756 /* very short format ... */
3758 fprintf(stdout, _("%4d) %4d\n"), i, NotesInfo.Location[i]);
3760 CalendarNote.Location=i+1;
3761 CalendarNote.ReadNotesInfo=false;
3763 if (GSM->GetCalendarNote(&CalendarNote) == GE_NONE) {
3766 switch (CalendarNote.Type) {
3767 case GCN_REMINDER:strcpy(z_type, "REMIND"); break;
3768 case GCN_CALL: strcpy(z_type, "CALL"); break;
3769 case GCN_MEETING: strcpy(z_type, "MEETING"); break;
3770 case GCN_BIRTHDAY:strcpy(z_type, "BDAY"); break;
3771 default: strcpy(z_type, "UNKNOWN"); break;
3774 if( CalendarNote.Recurrance ) {
3775 sprintf( z_recur,"%d ", CalendarNote.Recurrance/24 );
3776 strcat( z_recur, CalendarNote.Recurrance == 1 ? "day" : "days" );
3779 strcpy( z_recur, "No" );
3783 if( CalendarNote.Type == GCN_CALL )
3784 sprintf(z_text, "\"%s\"", CalendarNote.Phone );
3786 if (CalendarNote.Text[0]!=0)
3787 sprintf(z_text, "\"%s\"", CalendarNote.Text );
3789 if(CalendarNote.Type == GCN_BIRTHDAY) {
3791 i_age = Date.Year - CalendarNote.Time.Year;
3792 sprintf(z_text, "\"%s (%d %s)\"", CalendarNote.Text,
3793 i_age, (i_age==1)?"year":"years");
3794 strcpy( z_recur, "-" );
3795 if (GetModelFeature (FN_CALENDAR)==F_CAL71)
3797 _("%4d %4d %-7.7s %-32.32s %04d-%02d-%02d %s %s\n"),
3798 i+1,NotesInfo.Location[i], z_type, z_text,
3799 CalendarNote.Time.Year,
3800 CalendarNote.Time.Month,
3801 CalendarNote.Time.Day,
3802 (CalendarNote.AlarmType==0x00) ? "Tone " : "Silent",
3806 _("%4d %4d %-7.7s %-32.32s %04d-%02d-%02d %s %s\n"),
3807 i+1,NotesInfo.Location[i], z_type, z_text,
3808 CalendarNote.Time.Year,
3809 CalendarNote.Time.Month,
3810 CalendarNote.Time.Day,
3811 (CalendarNote.Alarm.Year) ? "Yes" : "No ",
3814 if (GetModelFeature (FN_CALENDAR)==F_CAL71)
3816 _("%4d %4d %-7.7s %-32.32s %04d-%02d-%02d %s %s\n"),
3817 i+1,NotesInfo.Location[i], z_type, z_text,
3818 CalendarNote.Time.Year,
3819 CalendarNote.Time.Month,
3820 CalendarNote.Time.Day,
3821 (CalendarNote.Alarm.Year) ? "Yes" : "No ",
3825 _("%4d %4d %-7.7s %-32.32s %04d-%02d-%02d %s\n"),
3826 i+1,NotesInfo.Location[i], z_type, z_text,
3827 CalendarNote.Time.Year,
3828 CalendarNote.Time.Month,
3829 CalendarNote.Time.Day,
3830 (CalendarNote.Alarm.Year) ? "Yes" : "No ");
3832 if (GetModelFeature (FN_CALENDAR)!=F_CAL71) break;
3837 for (i=start;i<=stop;i++) {
3838 if (error==GE_NONE) {
3839 if( i>NotesInfo.HowMany ) {
3840 fprintf(stderr, _("Only %d Calendar Notes present on phone!\n"),NotesInfo.HowMany);
3844 fprintf(stderr, _("Calendar Notes location can't be zero... skipping.\n"));
3849 CalendarNote.Location=i;
3850 CalendarNote.ReadNotesInfo=false;
3852 if (GSM->GetCalendarNote(&CalendarNote) == GE_NONE) {
3856 fprintf(stdout, GSM_GetVCALENDARStart(vCalVer));
3860 fprintf(stdout, GSM_GetVCALENDARNote(&CalendarNote,vCalVer));
3862 } else { /* not vCal */
3865 fprintf(stdout, "\n");
3870 fprintf(stdout, _(" Type of the note: "));
3872 switch (CalendarNote.Type) {
3874 case GCN_REMINDER:fprintf(stdout, _("Reminder\n"));break;
3875 case GCN_CALL :fprintf(stdout, _("Call\n")); break;
3876 case GCN_MEETING :fprintf(stdout, _("Meeting\n")); break;
3877 case GCN_BIRTHDAY:fprintf(stdout, _("Birthday\n"));break;
3878 default: fprintf(stdout, _("Unknown\n"));
3882 /* For 3310: set date to 2090! */
3883 if (GetModelFeature (FN_CALENDAR)==F_CAL33) {
3884 fprintf(stdout, _(" Date: xxxx-%02d-%02d\n"), CalendarNote.Time.Month,
3885 CalendarNote.Time.Day);
3887 fprintf(stdout, _(" Date: %s %d-%02d-%02d\n"),
3888 DayOfWeek(CalendarNote.Time.Year, CalendarNote.Time.Month, CalendarNote.Time.Day),
3889 CalendarNote.Time.Year,
3890 CalendarNote.Time.Month,
3891 CalendarNote.Time.Day);
3894 fprintf(stdout, _(" Time: %02d:%02d:%02d\n"), CalendarNote.Time.Hour,
3895 CalendarNote.Time.Minute,
3896 CalendarNote.Time.Second);
3898 if (CalendarNote.Alarm.Year!=0) {
3899 fprintf(stdout, _(" Alarm date: %s %d-%02d-%02d\n"),
3900 DayOfWeek(CalendarNote.Alarm.Year, CalendarNote.Alarm.Month, CalendarNote.Alarm.Day),
3901 CalendarNote.Alarm.Year,
3902 CalendarNote.Alarm.Month,
3903 CalendarNote.Alarm.Day);
3905 fprintf(stdout, _(" Alarm time: %02d:%02d:%02d\n"), CalendarNote.Alarm.Hour,
3906 CalendarNote.Alarm.Minute,
3907 CalendarNote.Alarm.Second);
3908 if ( GetModelFeature (FN_CALENDAR)==F_CAL71 )
3909 fprintf(stdout, _(" Alarm type: %s\n"), (CalendarNote.AlarmType==0x00) ?
3910 "With Tone" : "Silent" );
3913 if ( GetModelFeature (FN_CALENDAR)==F_CAL71 && CalendarNote.Recurrance!= 0 )
3914 fprintf(stdout, " It repeat every %d day%s\n", CalendarNote.Recurrance/24,
3915 ((CalendarNote.Recurrance/24)>1) ? "s":"" );
3917 if (CalendarNote.Type == GCN_BIRTHDAY)
3920 i_age = Date.Year - CalendarNote.Time.Year;
3921 fprintf(stdout, _(" Text: %s (%d %s)\n"), CalendarNote.Text,
3922 i_age, (i_age==1)?"year":"years");
3924 if (CalendarNote.Text[0]!=0)
3925 fprintf(stdout, _(" Text: %s\n"), CalendarNote.Text);
3928 if (CalendarNote.Type == GCN_CALL)
3929 fprintf(stdout, _(" Phone: %s\n"), CalendarNote.Phone);
3932 fprintf(stderr, _("The calendar note %i can not be read\n"),i);
3936 if (was_note && vCalVer!=0) {
3937 fprintf(stdout, GSM_GetVCALENDAREnd(vCalVer));
3945 /* Writing calendar notes. */
3947 int writecalendarnote(char *argv[])
3949 GSM_CalendarNote CalendarNote;
3953 number=atoi(argv[1]);
3956 fprintf(stdout, _("Number of calendar note must be 1 or higher\n"));
3960 switch ( GSM_ReadVCalendarFile(argv[0], &CalendarNote, &number) ) {
3963 case GE_CANTOPENFILE:
3964 fprintf(stdout, _("Failed to open vCalendar file \"%s\"\n"),argv[0]);
3967 fprintf(stdout, _("Number of given calendar note is too high (max=%i)\n"),number);
3970 fprintf(stdout, _("Failed to parse vCalendar file \"%s\"\n"),argv[0]);
3976 /* Error 22=Calendar full ;-) */
3978 error=GSM->WriteCalendarNote(&CalendarNote);
3981 fprintf(stdout, _("Succesfully written!\n"));break;
3983 fprintf(stdout, _("Too long text in calendar note!\n"));break;
3985 fprintf(stdout, _("Failed to write calendar note!\n"));break;
3993 /* Calendar note deleting. */
3995 int deletecalendarnote(char *Index)
3998 GSM_CalendarNote CalendarNote;
4000 CalendarNote.Location=atoi(Index);
4004 if (GSM->DeleteCalendarNote(&CalendarNote) == GE_NONE) {
4005 fprintf(stdout, _(" Calendar note deleted.\n"));
4008 fprintf(stderr, _("The calendar note can not be deleted\n"));
4019 /* Setting the date and time. */
4021 int setdatetime(int argc, char *argv[])
4030 now=localtime(&nowh);
4032 Date.Year = now->tm_year;
4033 Date.Month = now->tm_mon+1;
4034 Date.Day = now->tm_mday;
4035 Date.Hour = now->tm_hour;
4036 Date.Minute = now->tm_min;
4037 Date.Second = now->tm_sec;
4039 if (argc>0) Date.Year = atoi (argv[0]);
4040 if (argc>1) Date.Month = atoi (argv[1]);
4041 if (argc>2) Date.Day = atoi (argv[2]);
4042 if (argc>3) Date.Hour = atoi (argv[3]);
4043 if (argc>4) Date.Minute = atoi (argv[4]);
4048 /* Well, this thing is copyrighted in U.S. This technique is known as
4049 Windowing and you can read something about it in LinuxWeekly News:
4050 http://lwn.net/1999/features/Windowing.phtml. This thing is beeing
4051 written in Czech republic and Poland where algorithms are not allowed
4055 Date.Year = Date.Year+1900;
4057 Date.Year = Date.Year+2000;
4060 /* FIXME: Error checking should be here. */
4061 GSM->SetDateTime(&Date);
4068 /* In this mode we receive the date and time from mobile phone. */
4070 int getdatetime(void) {
4072 GSM_DateTime date_time;
4076 if (GSM->GetDateTime(&date_time)==GE_NONE) {
4077 if (date_time.IsSet) {
4078 fprintf(stdout, _("Date: %s %4d/%02d/%02d\n"),
4079 DayOfWeek(date_time.Year, date_time.Month, date_time.Day),
4080 date_time.Year, date_time.Month, date_time.Day);
4081 fprintf(stdout, _("Time: %02d:%02d:%02d\n"), date_time.Hour, date_time.Minute, date_time.Second);
4083 fprintf(stdout, _("Date and time not set in phone\n"));
4086 fprintf(stdout,_("Error!\n"));
4094 /* Setting the alarm. */
4096 int setalarm(char *argv[])
4103 Date.Hour = atoi(argv[0]);
4104 Date.Minute = atoi(argv[1]);
4106 GSM->SetAlarm(1, &Date);
4113 /* Getting the alarm. */
4115 int getalarm(void) {
4117 GSM_DateTime date_time;
4121 if (GSM->GetAlarm(0, &date_time)==GE_NONE) {
4122 fprintf(stdout, _("Alarm: %s\n"), (date_time.IsSet)?"on":"off");
4123 fprintf(stdout, _("Time: %02d:%02d\n"), date_time.Hour, date_time.Minute);
4125 fprintf(stdout,_("Error!\n"));
4133 /* In monitor mode we don't do much, we just initialise the fbus code.
4134 Note that the fbus code no longer has an internal monitor mode switch,
4135 instead compile with DEBUG enabled to get all the gumpf. */
4137 int monitormode(int argc, char *argv[])
4140 float rflevel=-1, batterylevel=-1;
4141 unsigned char loop=1;
4143 GSM_PowerSource powersource=-1;
4144 GSM_RFUnits rf_units = GRF_Arbitrary;
4145 GSM_BatteryUnits batt_units = GBU_Arbitrary;
4147 GSM_NetworkInfo NetworkInfo;
4148 GSM_CBMessage CBMessage;
4150 GSM_MemoryStatus SIMMemoryStatus = {GMT_SM, 0, 0};
4151 GSM_MemoryStatus PhoneMemoryStatus = {GMT_ME, 0, 0};
4152 GSM_MemoryStatus DC_MemoryStatus = {GMT_DC, 0, 0};
4153 GSM_MemoryStatus EN_MemoryStatus = {GMT_EN, 0, 0};
4154 GSM_MemoryStatus FD_MemoryStatus = {GMT_FD, 0, 0};
4155 GSM_MemoryStatus LD_MemoryStatus = {GMT_LD, 0, 0};
4156 GSM_MemoryStatus MC_MemoryStatus = {GMT_MC, 0, 0};
4157 GSM_MemoryStatus ON_MemoryStatus = {GMT_ON, 0, 0};
4158 GSM_MemoryStatus RC_MemoryStatus = {GMT_RC, 0, 0};
4160 GSM_SMSStatus SMSStatus = {0, 0};
4164 /* evaluate for presence of "-noloop" argument in parameter */
4167 if( strcmp(argv[0],"-noloop" ) && strcmp(argv[0],"-nl" ))
4176 /* We do not want to monitor serial line forever - press Ctrl+C to stop the
4179 signal(SIGINT, interrupted);
4181 fprintf (stderr, _("Entering monitor mode...\n"));
4182 fprintf (stderr, _("Initialising GSM interface...\n"));
4184 /* Initialise the code for the GSM interface. */
4189 GSM->EnableCellBroadcast();
4191 /* Loop here indefinitely - allows you to see messages from GSM code in
4192 response to unknown messages etc. The loops ends after pressing the
4194 while (!bshutdown) {
4195 if (GSM->GetRFLevel(&rf_units, &rflevel) == GE_NONE)
4196 fprintf(stdout, _("RFLevel: %d\n"), (int)rflevel);
4198 if (GSM->GetBatteryLevel(&batt_units, &batterylevel) == GE_NONE)
4199 fprintf(stdout, _("Battery: %d\n"), (int)batterylevel);
4201 if (GSM->GetPowerSource(&powersource) == GE_NONE)
4202 fprintf(stdout, _("Power Source: %s\n"), (powersource==GPS_ACDC)?_("AC/DC"):_("battery"));
4204 if (GSM->GetMemoryStatus(&SIMMemoryStatus) == GE_NONE)
4205 fprintf(stdout, _("SIM: Used %d, Free %d\n"), SIMMemoryStatus.Used, SIMMemoryStatus.Free);
4207 if (GSM->GetMemoryStatus(&PhoneMemoryStatus) == GE_NONE)
4208 fprintf(stdout, _("Phone: Used %d, Free %d\n"), PhoneMemoryStatus.Used, PhoneMemoryStatus.Free);
4210 if (GSM->GetMemoryStatus(&DC_MemoryStatus) == GE_NONE)
4211 fprintf(stdout, _("DC: Used %d, Free %d\n"), DC_MemoryStatus.Used, DC_MemoryStatus.Free);
4213 if (GSM->GetMemoryStatus(&EN_MemoryStatus) == GE_NONE)
4214 fprintf(stdout, _("EN: Used %d, Free %d\n"), EN_MemoryStatus.Used, EN_MemoryStatus.Free);
4216 if (GSM->GetMemoryStatus(&FD_MemoryStatus) == GE_NONE)
4217 fprintf(stdout, _("FD: Used %d, Free %d\n"), FD_MemoryStatus.Used, FD_MemoryStatus.Free);
4219 if (GSM->GetMemoryStatus(&LD_MemoryStatus) == GE_NONE)
4220 fprintf(stdout, _("LD: Used %d, Free %d\n"), LD_MemoryStatus.Used, LD_MemoryStatus.Free);
4222 if (GSM->GetMemoryStatus(&MC_MemoryStatus) == GE_NONE)
4223 fprintf(stdout, _("MC: Used %d, Free %d\n"), MC_MemoryStatus.Used, MC_MemoryStatus.Free);
4225 if (GSM->GetMemoryStatus(&ON_MemoryStatus) == GE_NONE)
4226 fprintf(stdout, _("ON: Used %d, Free %d\n"), ON_MemoryStatus.Used, ON_MemoryStatus.Free);
4228 if (GSM->GetMemoryStatus(&RC_MemoryStatus) == GE_NONE)
4229 fprintf(stdout, _("RC: Used %d, Free %d\n"), RC_MemoryStatus.Used, RC_MemoryStatus.Free);
4231 if (GSM->GetSMSStatus(&SMSStatus) == GE_NONE)
4232 fprintf(stdout, _("SMS Messages: UnRead %d, Number %d\n"), SMSStatus.UnRead, SMSStatus.Number);
4234 if (GSM->GetIncomingCallNr(Number) == GE_NONE)
4235 fprintf(stdout, _("Incoming call: %s\n"), Number);
4237 if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE)
4238 fprintf(stdout, _("Network: %s (%s), LAC: %s, CellID: %s\n"), GSM_GetNetworkName (NetworkInfo.NetworkCode), GSM_GetCountryName(NetworkInfo.NetworkCode), NetworkInfo.LAC, NetworkInfo.CellID);
4240 if (GSM->ReadCellBroadcast(&CBMessage) == GE_NONE)
4241 fprintf(stdout, _("Cell broadcast received on channel %d: %s\n"), CBMessage.Channel, CBMessage.Message);
4248 if( loop ) fprintf (stderr, _("Leaving monitor mode...\n"));
4255 #endif /* UCLINUX */
4257 /* Emulation of separate gnokiid binary for uClinux */
4261 #define NICE_LEVEL (-20)
4263 static void gnokiid_SIGCHLD(int signo)
4265 fprintf (stderr, _("Child process exited, aborting...\n"));
4269 static int gnokiid(int argc, char *argv[])
4271 bool DebugMode; /* When true, run in debug mode */
4273 /* evaluate for presence of "--debug" argument in parameter */
4277 if( !strcmp(argv[0],"--debug" ))
4286 fprintf (stderr, _("Initializing gnokiid mode...\n"));
4289 if (VM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), BinDir, DebugMode, true, ""/*SynchronizeTime*/) == false)
4294 fprintf (stderr, _("Spawning gnokiid startup child process \"%s\"...\n"), *argv);
4296 signal(SIGCHLD,gnokiid_SIGCHLD);
4299 case -1: /* vfork() failure */
4300 fprintf (stderr, _("vfork() failed! (%s)\n"),strerror(errno));
4304 fprintf (stderr, _("Spawn of child process failed! (%s)\n"),strerror(errno));
4307 default: /* parent */
4314 fprintf (stderr, _("Entering gnokiid virtual modem main loop...\n"));
4316 if (nice(NICE_LEVEL))
4317 fprintf (stderr, _("WARNING: nice level change failed (by %d)\n"),NICE_LEVEL);
4326 #endif /* UCLINUX */
4330 /* Shows texts from phone's display */
4339 error=GSM->EnableDisplayOutput();
4341 if (error == GE_NONE)
4344 /* We do not want to see texts forever - press Ctrl+C to stop. */
4346 signal(SIGINT, interrupted);
4348 fprintf (stderr, _("Entering display monitoring mode...\n"));
4350 /* Loop here indefinitely - allows you to read texts from phone's
4351 display. The loops ends after pressing the Ctrl+C. */
4356 fprintf (stderr, _("Leaving display monitor mode...\n"));
4358 error=GSM->DisableDisplayOutput();
4360 fprintf (stderr, _("Error!\n"));
4362 fprintf (stderr, _("Error!\n"));
4369 /* Displays names of available ringtones */
4372 char model[64], rev[64];
4377 while (GSM->GetRevision(rev) != GE_NONE)
4380 while (GSM->GetModel(model) != GE_NONE)
4383 strncpy(rev,rev+2,5);
4385 PrepareRingingTones(model,rev);
4387 for (i=1;i<=NumberOfRingtones();i++)
4389 fprintf(stdout,_("%i. %s\n"),i,RingingToneName(0,i));
4398 /* Reads profile from phone and displays its' settings */
4400 int getprofile(int argc, char *argv[])
4405 GSM_Profile profile;
4408 /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */
4409 char model[64], rev[64];
4411 /* Initialise the code for the GSM interface. */
4416 error=GSM->GetProfile(&profile);
4418 if (error == GE_NONE)
4421 while (GSM->GetModel(model) != GE_NONE) sleep(1);
4423 while (GSM->GetRevision(rev) != GE_NONE) sleep(1);
4425 strncpy(rev,rev+2,5);
4427 PrepareRingingTones(model,rev);
4429 switch(GetModelFeature (FN_PROFILES)) {
4430 case F_PROF33:max_profiles=6;break;
4431 case F_PROF51:max_profiles=3;break;
4432 default :max_profiles=7;break;
4437 profile.Number=atoi(argv[0])-1;
4438 start=profile.Number;
4441 if (profile.Number < 0)
4443 fprintf(stderr, _("Profile number must be value from 1 to %d!\n"), max_profiles);
4448 if (profile.Number >= max_profiles)
4450 fprintf(stderr, _("This phone supports only %d profiles!\n"), max_profiles);
4464 if (profile.Number!=0) GSM->GetProfile(&profile);
4466 printf("%d. \"%s\"", (profile.Number+1), profile.Name);
4467 if (profile.DefaultName==-1) printf(" (name defined)");
4471 printf("Incoming call alert: %d\n", profile.CallAlert);
4472 printf("Ringtone ID: %d\n", profile.Ringtone);
4473 printf("Ringing volume: %d\n", profile.Volume);
4474 printf("Message alert tone: %d\n", profile.MessageTone);
4475 printf("Keypad tones: %d\n", profile.KeypadTone);
4476 printf("Warning and game tones: %d\n", profile.WarningTone);
4477 printf("Lights: %d\n", profile.Lights);
4478 printf("Vibration: %d\n", profile.Vibration);
4479 printf("Caller groups: 0x%02x\n", profile.CallerGroups);
4480 printf("Automatic answer: %d\n", profile.AutomaticAnswer);
4481 printf("Screen saver: %d\n", profile.ScreenSaver);
4485 printf("Incoming call alert: %s\n", GetProfileCallAlertString(profile.CallAlert));
4487 /* For different phones different ringtones names */
4488 if (strcmp(RingingToneName(profile.Ringtone,0),""))
4489 printf(_("Ringing tone: %s (number %d in phone menu)\n"),
4490 RingingToneName(profile.Ringtone,0), RingingToneMenu(profile.Ringtone));
4492 printf(_("Ringtone number: %d\n"), profile.Ringtone);
4494 printf(_("Ringing volume: %s\n"), GetProfileVolumeString(profile.Volume));
4496 printf(_("Message alert tone: %s\n"), GetProfileMessageToneString(profile.MessageTone));
4498 printf(_("Keypad tones: %s\n"), GetProfileKeypadToneString(profile.KeypadTone));
4500 printf(_("Warning and game tones: %s\n"), GetProfileWarningToneString(profile.WarningTone));
4502 if (GetModelFeature (FN_SCREENSAVER)!=0)
4503 printf(_("Screen saver: %s\n"), GetProfileOnOffString(profile.ScreenSaver));
4505 printf(_("Vibration: %s\n"), GetProfileVibrationString(profile.Vibration));
4507 /* It has been nice to add here reading caller group name. ;^) */
4508 if (GetModelFeature (FN_CALENDAR)==F_CAL71)
4509 printf(_("Caller groups: %s\n"),
4510 GetProfileCallerGroups(profile.CallerGroups) );
4512 /* FIXME: need make investigation for 3310 for these features. For now unknown */
4513 if (GetModelFeature (FN_PROFILES)!=F_PROF33) {
4514 /* FIXME: Light settings is only used for Car */
4515 if (profile.Number==(max_profiles-2)) printf(_("Lights: %s\n"), profile.Lights ? _("On") : _("Automatic"));
4517 /* FIXME: Automatic answer is only used for Car and Headset. */
4518 if (profile.Number>=(max_profiles-2)) printf(_("Automatic answer: %s\n"), GetProfileOnOffString(profile.AutomaticAnswer));
4526 if (error == GE_NOTIMPLEMENTED) {
4527 fprintf(stderr, _("Function not implemented in %s model!\n"), model);
4532 fprintf(stderr, _("Unspecified error\n"));
4544 /* Sets profile feature */
4546 int setprofile(int argc, char *argv[])
4549 /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */
4550 char model[64], rev[64];
4553 GSM_Profile profile;
4554 GSM_Profile profile2, profile3;
4559 /* Initialise the code for the GSM interface. */
4565 error = GSM->GetProfile(&profile);
4567 if (error == GE_NONE)
4570 while (GSM->GetModel(model) != GE_NONE) sleep(1);
4572 while (GSM->GetRevision(rev) != GE_NONE) sleep(1);
4574 strncpy(rev,rev+2,5);
4576 PrepareRingingTones(model,rev);
4578 switch(GetModelFeature (FN_PROFILES)) {
4579 case F_PROF33:max_profiles=6;break;
4580 case F_PROF51:max_profiles=3;break;
4581 default :max_profiles=7;break;
4584 profile.Number=atoi (argv[0]);
4585 profile.Number=profile.Number-1;
4587 if (profile.Number < 0)
4589 fprintf(stderr, _("Profile number must be value from 1 to %i!\n"), max_profiles);
4594 if (profile.Number >= max_profiles)
4596 fprintf(stderr, _("This phone supports only %i profiles!\n"), max_profiles);
4601 if (profile.Number!=0) GSM->GetProfile(&profile);
4606 if (strcmp(argv[1], "callalert")==0)
4608 if (strcmp(argv[2], "ringing")==0) {profile.CallAlert=PROFILE_CALLALERT_RINGING;correct_arg2=true;}
4609 if (strcmp(argv[2], "ascending")==0) {profile.CallAlert=PROFILE_CALLALERT_ASCENDING;correct_arg2=true;}
4610 if (strcmp(argv[2], "ringonce")==0) {profile.CallAlert=PROFILE_CALLALERT_RINGONCE;correct_arg2=true;}
4611 if (strcmp(argv[2], "beeponce")==0) {profile.CallAlert=PROFILE_CALLALERT_BEEPONCE;correct_arg2=true;}
4612 if (strcmp(argv[2], "groups")==0)
4614 profile.CallAlert=PROFILE_CALLALERT_CALLERGROUPS;
4616 /*Ignored by N5110*/
4617 /*FIX ME: it's ignored by N5130 and 3210 too*/
4618 if (max_profiles==3) fprintf(stdout, _("Warning: value \"groups\" for profile feature \"callalert\" will be ignored in this phone model !\n"));
4620 if (strcmp(argv[2], "off")==0 || strcmp(argv[2], "0")==0) {profile.CallAlert=PROFILE_CALLALERT_OFF;correct_arg2=true;}
4623 fprintf(stderr, _("Correct parameters for profile feature \"callalert\" are ringing|ascending|ringonce|beeponce|groups|off|0 !\n"));
4629 if (strcmp(argv[1], "volume")==0)
4631 if (strcmp(argv[2], "1")==0) {profile.Volume=PROFILE_VOLUME_LEVEL1;correct_arg2=true;}
4632 if (strcmp(argv[2], "2")==0) {profile.Volume=PROFILE_VOLUME_LEVEL2;correct_arg2=true;}
4633 if (strcmp(argv[2], "3")==0) {profile.Volume=PROFILE_VOLUME_LEVEL3;correct_arg2=true;}
4634 if (strcmp(argv[2], "4")==0) {profile.Volume=PROFILE_VOLUME_LEVEL4;correct_arg2=true;}
4635 if (strcmp(argv[2], "5")==0) {profile.Volume=PROFILE_VOLUME_LEVEL5;correct_arg2=true;}
4638 fprintf(stderr, _("Correct parameters for profile feature \"volume\" are 0|1|2|3|4|5 !\n"));
4644 if (strcmp(argv[1], "keypad")==0 || strcmp(argv[1], "keypadtone")==0)
4646 if (strcmp(argv[2], "0")==0 || strcmp(argv[2], "off")==0) {profile.KeypadTone=PROFILE_KEYPAD_OFF;correct_arg2=true;}
4647 if (strcmp(argv[2], "1")==0) {profile.KeypadTone=PROFILE_KEYPAD_LEVEL1;correct_arg2=true;}
4648 if (strcmp(argv[2], "2")==0) {profile.KeypadTone=PROFILE_KEYPAD_LEVEL2;correct_arg2=true;}
4649 if (strcmp(argv[2], "3")==0) {profile.KeypadTone=PROFILE_KEYPAD_LEVEL3;correct_arg2=true;}
4652 fprintf(stderr, _("Correct parameters for profile feature \"keypad|keypadtone\" are off|0|1|2|3 !\n"));
4658 if (strcmp(argv[1], "messagetone")==0 || strcmp(argv[1], "smstone")==0 || strcmp(argv[1], "sms")==0 || strcmp(argv[1], "message")==0)
4660 if (strcmp(argv[2], "0")==0 || strcmp(argv[2], "off")==0) {profile.MessageTone=PROFILE_MESSAGE_NOTONE;correct_arg2=true;}
4661 if (strcmp(argv[2], "standard")==0) {profile.MessageTone=PROFILE_MESSAGE_STANDARD;correct_arg2=true;}
4662 if (strcmp(argv[2], "special")==0) {profile.MessageTone=PROFILE_MESSAGE_SPECIAL;correct_arg2=true;}
4663 if (strcmp(argv[2], "beeponce")==0 || strcmp(argv[2], "once")==0) {profile.MessageTone=PROFILE_MESSAGE_BEEPONCE;correct_arg2=true;}
4664 if (strcmp(argv[2], "ascending")==0) {profile.MessageTone=PROFILE_MESSAGE_ASCENDING;correct_arg2=true;}
4667 fprintf(stderr, _("Correct parameters for profile feature \"messagetone|smstone|message|sms\" are 0|off|standard|special|beeponce|once|ascending !\n"));
4673 if (strcmp(argv[1], "warningtone")==0 || strcmp(argv[1], "warning")==0)
4675 if (strcmp(argv[2], "0")==0 || strcmp(argv[2], "off")==0) {profile.WarningTone=PROFILE_WARNING_OFF;correct_arg2=true;}
4676 if (strcmp(argv[2], "1")==0 || strcmp(argv[2], "on")==0) {profile.WarningTone=PROFILE_WARNING_ON;correct_arg2=true;}
4679 fprintf(stderr, _("Correct parameters for profile feature \"warningtone|warning\" are 0|off|1|on !\n"));
4685 if (strcmp(argv[1], "vibra")==0 || strcmp(argv[1], "vibration")==0)
4687 if (strcmp(argv[2], "0")==0 || strcmp(argv[2], "off")==0) {profile.Vibration=PROFILE_VIBRATION_OFF;correct_arg2=true;}
4688 if (strcmp(argv[2], "1")==0 || strcmp(argv[2], "on")==0) {profile.Vibration=PROFILE_VIBRATION_ON;correct_arg2=true;}
4691 fprintf(stderr, _("Correct parameters for profile feature \"vibration|vibra\" are 0|off|1|on !\n"));
4697 if (strcmp(argv[1], "lights")==0)
4699 if (strcmp(argv[2], "0")==0 || strcmp(argv[2], "off")==0) {profile.Lights=-1;correct_arg2=true;}
4700 if (strcmp(argv[2], "1")==0 || strcmp(argv[2], "on")==0) {profile.Lights=0;correct_arg2=true;}
4703 fprintf(stderr, _("Correct parameters for profile feature \"lights\" are 0|off|1|on !\n"));
4707 if (profile.Number!=(max_profiles-2))
4709 profile2.Number=max_profiles-2;
4710 if (GSM->GetProfile(&profile2)==GE_NONE)
4712 fprintf(stdout, _("Warning: \"Lights\" feature is ignored in this profile (only setting it for \"%s\" profile get some results) !\n"), profile2.Name);
4717 if (strcmp(argv[1], "answer")==0)
4719 if (strcmp(argv[2], "0")==0 || strcmp(argv[2], "off")==0) {profile.AutomaticAnswer=-1;correct_arg2=true;}
4720 if (strcmp(argv[2], "1")==0 || strcmp(argv[2], "on")==0) {profile.AutomaticAnswer=0;correct_arg2=true;}
4723 fprintf(stderr, _("Correct parameters for profile feature \"answer\" are 0|off|1|on !\n"));
4727 if (profile.Number<(max_profiles-2))
4729 profile2.Number=max_profiles-2;
4730 if (GSM->GetProfile(&profile2)==GE_NONE)
4732 profile3.Number=max_profiles-1;
4733 if (GSM->GetProfile(&profile3)==GE_NONE)
4735 fprintf(stdout, _("Warning: \"Automatic Answer\" feature is ignored in this profile (only setting it for \"%s\" and \"%s\" profiles get some results) !\n"), profile2.Name, profile3.Name);
4741 if (strcmp(argv[1], "name")==0)
4743 strcpy(profile.Name,argv[2]);
4744 /*Ignored by N5110*/
4745 /*FIX ME: it's ignored by N5130 and 3210 too*/
4746 if (max_profiles==3) fprintf(stdout, _("Warning: this phone model doesn't allow to change profile name !\n"));
4749 if (strcmp(argv[1], "ringtone")==0)
4751 profile.Ringtone=atoi(argv[2]);
4752 if (profile.Ringtone<1)
4754 /*With value 0 results are interesting in N5110, but can't be used for anything*/
4755 fprintf(stderr, _("Ringtone number must be higher than 0 !\n"));
4760 if (profile.Ringtone>NumberOfRingtones())
4762 fprintf(stderr, _("Ringtone number too high (max %i) !\n"),NumberOfRingtones());
4766 profile.Ringtone=RingingToneCode(profile.Ringtone);
4767 if (profile.Ringtone==0)
4769 fprintf(stderr, _("Warning: we don't know ringtones codes for this model ! Can you contact with gnokii authors to add it into source ?\n"));
4773 if (max_profiles==3) fprintf(stdout, _("Warning: ringtone is changed for all profiles. You must reset phone or select profile in phone againg to see result.\n"));
4777 if (strcmp(argv[1], "groups")==0)
4779 /*Ignored by N5110*/
4780 /*FIX ME: it's ignored by N5130 and 3210 too*/
4781 if (max_profiles==3) fprintf(stdout, _("Warning: this phone model doesn't allow to change caller group name !\n"));
4782 profile.CallerGroups=atoi(argv[2]);
4788 fprintf(stderr, _("Correct profile feature names are callalert|volume|keypad|keypadtone|messagetone|smstone|message|sms|warningtone|warning|vibra|vibration|lights|answer|name|groups !\n"));
4793 GSM->SetProfile(&profile);
4796 if (error == GE_NOTIMPLEMENTED) {
4797 fprintf(stderr, _("Function not implemented in %s model!\n"), model);
4802 fprintf(stderr, _("Unspecified error\n"));
4814 #endif /* UCLINUX */
4816 /* Get requested range of memory storage entries and output to stdout in
4817 easy-to-parse format */
4819 static int getmemory(int argc, char *argv[])
4822 GSM_PhonebookEntry entry;
4827 char memory_type_string[20];
4830 int i_used = 0, n_used=0;
4832 char *output_opt = NULL;
4834 char az_group_name[5][MAX_BITMAP_TEXT_LENGTH];
4835 bool formatdone=false;
4838 /* group names init */
4839 for(i=0;i<5;i++) az_group_name[i][0]='\0';
4841 /* Handle command line args that set type, start and end locations. */
4842 if (!GetMemoryTypeID(argv[0], &entry.MemoryType))
4844 fprintf(stderr, _("Unknown memory type %s!\n"), argv[0]);
4848 GetMemoryTypeString(memory_type_string, &entry.MemoryType);
4850 if (argv[argc-1][0] == '-')
4851 output_opt = argv[--argc];
4853 /* Do generic initialisation routine */
4857 while ((error = GSM->GetModel(buf)) != GE_NONE && i++ < 15)
4862 start_entry = atoi (argv[1]);
4863 end_entry = argc > 2 ? atoi( argv[2]) : start_entry;
4865 GSM_MemoryStatus stats = {entry.MemoryType, 0, 0};
4869 if (GSM->GetMemoryStatus( &stats) != GE_NONE) {
4870 fprintf( stderr, _("Error reading memory status.\n"));
4874 n_used = stats.Used;
4875 end_entry = stats.Used + stats.Free;
4879 /* Now retrieve the requested entries. */
4881 for (count = start_entry;
4882 count <= end_entry && (!do_all || i_used < n_used);
4885 entry.Location=count;
4887 error=GSM->GetMemoryLocation(&entry);
4891 if (entry.SubEntriesCount || strcmp( entry.Number, ""))
4896 if (output_opt && !strcmp( output_opt,"-v30")) {
4897 semicolon_pipe_substitution( &entry, 0 );
4898 fprintf(stdout,_("%s"),GSM_GetVCARD(&entry,30));
4901 if (output_opt && !strcmp(output_opt,"-v21")) {
4902 semicolon_pipe_substitution( &entry, 0 );
4903 fprintf(stdout,_("%s"),GSM_GetVCARD(&entry,21));
4906 if (output_opt && !strcmp(output_opt,"-v")) {
4907 semicolon_pipe_substitution( &entry, 0 );
4908 fprintf(stdout,_("%s"),GSM_GetVCARD(&entry,10));
4911 #endif /* UCLINUX */
4912 if (output_opt && !strcmp(output_opt,"-short")) {
4913 semicolon_pipe_substitution( &entry, 0 );
4914 fprintf(stdout, "%s;%s;%s;%d;%d;", entry.Name, entry.Number, memory_type_string, entry.Location, entry.Group);
4915 for( i = 0; i < entry.SubEntriesCount; i++ )
4917 if( entry.SubEntries[i].EntryType == GSM_Date )
4918 fprintf(stdout,_("%u;%u;%u;%02u.%02u.%04u;%02u:%02u:%02u;"),
4919 entry.SubEntries[i].EntryType,
4920 entry.SubEntries[i].NumberType,
4921 entry.SubEntries[i].BlockNumber,
4922 entry.SubEntries[i].data.Date.Day,
4923 entry.SubEntries[i].data.Date.Month,
4924 entry.SubEntries[i].data.Date.Year,
4925 entry.SubEntries[i].data.Date.Hour,
4926 entry.SubEntries[i].data.Date.Minute,
4927 entry.SubEntries[i].data.Date.Second );
4929 fprintf(stdout,_("%u;%u;%u;%s;"),
4930 entry.SubEntries[i].EntryType,
4931 entry.SubEntries[i].NumberType,
4932 entry.SubEntries[i].BlockNumber,
4933 entry.SubEntries[i].data.Number );
4935 fprintf(stdout,_("\n"));
4941 fprintf(stdout, "Memory %s, location %d\n",memory_type_string, entry.Location);
4943 // check if some info in subentries
4944 for( i = 0; i < entry.SubEntriesCount; i++ )
4945 if( entry.SubEntries[i].EntryType != GSM_Date &&
4946 strcmp(entry.SubEntries[i].data.Number,"") )
4949 if (strcmp(entry.Number,"") || i < entry.SubEntriesCount) {
4950 if (strcmp(entry.Name,"")) fprintf(stdout,_(" Name: %s\n"),entry.Name);
4951 if (strcmp(entry.Number,"")) fprintf(stdout,_(" Number: %s\n"),entry.Number);
4952 bitmap.type=GSM_CallerLogo;
4953 bitmap.number=entry.Group;
4954 strcpy(z_gtype,"unknown");
4955 if (entry.Group==5) strcpy(z_gtype,"No group");
4956 if (entry.Group<5 && entry.Group>=0) {
4957 if (!strcmp(az_group_name[entry.Group],"")) {
4958 if (GetModelFeature (FN_CALLERGROUPS)!=0) {
4959 if (GSM->GetBitmap(&bitmap)==GE_NONE)
4960 strcpy( az_group_name[entry.Group], bitmap.text );
4962 if ((!strcmp(az_group_name[entry.Group],""))) {
4963 switch(entry.Group) {
4964 case 0:strcpy(az_group_name[entry.Group],"Family");break;
4965 case 1:strcpy(az_group_name[entry.Group],"VIP");break;
4966 case 2:strcpy(az_group_name[entry.Group],"Friends");break;
4967 case 3:strcpy(az_group_name[entry.Group],"Colleagues");break;
4968 case 4:strcpy(az_group_name[entry.Group],"Other");break;
4973 strcpy(z_gtype,az_group_name[entry.Group]);
4975 fprintf(stdout,_(" Group: %d (%s)\n"),entry.Group+1,z_gtype);
4976 for( i = 0; i < entry.SubEntriesCount; i++ )
4978 if( entry.SubEntries[i].EntryType == GSM_Date ) {
4979 fprintf(stdout, " Date and time: %s %02u.%02u.%04u %02u:%02u:%02u\n",
4980 DayOfWeek(entry.SubEntries[i].data.Date.Year,
4981 entry.SubEntries[i].data.Date.Month,
4982 entry.SubEntries[i].data.Date.Day),
4983 entry.SubEntries[i].data.Date.Day,
4984 entry.SubEntries[i].data.Date.Month,
4985 entry.SubEntries[i].data.Date.Year,
4986 entry.SubEntries[i].data.Date.Hour,
4987 entry.SubEntries[i].data.Date.Minute,
4988 entry.SubEntries[i].data.Date.Second);
4991 if( strcmp(entry.SubEntries[i].data.Number,"") ) {
4993 switch( entry.SubEntries[i].EntryType ) {
4995 switch( entry.SubEntries[i].NumberType ) {
4996 case GSM_General: strcpy(z_etype,"General "); break;
4997 case GSM_Home: strcpy(z_etype,"Home "); break;
4998 case GSM_Mobile: strcpy(z_etype,"Mobile "); break;
4999 case GSM_Work: strcpy(z_etype,"Work "); break;
5000 case GSM_Fax: strcpy(z_etype,"Fax "); break;
5001 default: strcpy(z_etype,""); break;
5003 strcat(z_etype,"Number"); break;
5005 strcpy(z_etype,"Note"); break;
5007 strcpy(z_etype,"Postal"); break;
5009 strcpy(z_etype,"E-Mail"); break;
5011 strcpy(z_etype,"unknown data"); break;
5014 fprintf(stdout,_(" ---> Subentry: %u\n"),i+1);
5015 fprintf(stdout,_(" Entry type: %u (%s)\n"),entry.SubEntries[i].EntryType,z_etype);
5016 fprintf(stdout,_(" Number type: %u\n"),entry.SubEntries[i].NumberType);
5017 fprintf(stdout,_(" Block Number: %u\n"),entry.SubEntries[i].BlockNumber);
5019 fprintf(stdout,_(" %s: %s\n"),z_etype,entry.SubEntries[i].data.Number);
5023 if ((entry.MemoryType==GMT_DC ||
5024 entry.MemoryType==GMT_RC ||
5025 entry.MemoryType==GMT_MC) && !wasdate)
5026 fprintf(stdout,_(" Date and time not available\n"));
5028 fprintf(stdout,_(" Location empty\n"));
5031 case GE_NOTIMPLEMENTED:
5032 fprintf( stderr, _("Function not implemented in %s model!\n"), model);
5035 case GE_INVALIDMEMORYTYPE:
5036 fprintf( stderr, _("Memory type %s not supported!\n"),
5037 memory_type_string);
5041 fprintf(stdout, _("%s|%d|Bad location or other error!(%d)\n"),
5042 memory_type_string, count, error);
5051 /* Read data from stdin, parse and write to phone. The parsing is relatively
5052 crude and doesn't allow for much variation from the stipulated format. */
5054 static int writephonebook(int argc, char *args[])
5057 GSM_PhonebookEntry entry;
5059 char *memory_type_string;
5060 int line_count=0,current,i;
5063 char *Line, OLine[1024], BackLine[1024];
5066 /* Check argument */
5068 if (strcmp("-i", args[0])) {
5073 /* Initialise fbus code */
5079 /* Go through data from stdin. */
5081 while (GetLine(stdin, Line, sizeof(OLine))!=-1) {
5083 current=0;BackLine[current++]=Line[0];
5084 for (i=1;i<strlen(Line);i++) {
5085 if (Line[i-1]==';' && Line[i]==';') BackLine[current++]=' ';
5086 BackLine[current++]=Line[i];
5088 BackLine[current++]=0;
5090 strcpy(Line,BackLine);
5094 #if defined(__svr4__) || defined(__FreeBSD__)
5095 ptr=strtok(Line, ";"); if (ptr) strcpy(entry.Name, ptr);
5098 ptr=strtok(NULL, ";"); if (ptr && ptr[0]!=' ') strcpy(entry.Number, ptr);
5100 ptr=strtok(NULL, ";");
5102 ptr=strsep(&Line, ";"); if (ptr) strcpy(entry.Name, ptr);
5105 ptr=strsep(&Line, ";"); if (ptr && ptr[0]!=' ') strcpy(entry.Number, ptr);
5107 ptr=strsep(&Line, ";");
5111 fprintf(stderr, _("Format problem on line %d [%s] 1\n"), line_count, BackLine);
5116 if (!strncmp(ptr,"ME", 2))
5118 memory_type_string = "int";
5119 entry.MemoryType = GMT_ME;
5121 else if (!strncmp(ptr,"SM", 2))
5123 memory_type_string = "sim";
5124 entry.MemoryType = GMT_SM;
5128 fprintf(stderr, _("Format problem on line %d [%s] 2: %s\n"),
5129 line_count, BackLine,ptr);
5133 #if defined(__svr4__) || defined(__FreeBSD__)
5134 ptr=strtok(NULL, ";"); if (ptr) entry.Location=atoi(ptr);
5136 ptr=strtok(NULL, ";"); if (ptr) entry.Group=atoi(ptr);
5138 ptr=strsep(&Line, ";"); if (ptr) entry.Location=atoi(ptr);
5140 ptr=strsep(&Line, ";"); if (ptr) entry.Group=atoi(ptr);
5144 fprintf(stderr, _("Format problem on line %d [%s] 3\n"),
5145 line_count, BackLine);
5149 for( subentry = 0; ; subentry++ )
5151 #if defined(__svr4__) || defined(__FreeBSD__)
5152 ptr=strtok(NULL, ";");
5154 ptr=strsep(&Line, ";");
5156 if( ptr && *ptr != 0 )
5157 entry.SubEntries[subentry].EntryType=atoi(ptr);
5161 #if defined(__svr4__) || defined(__FreeBSD__)
5162 ptr=strtok(NULL, ";");
5164 ptr=strsep(&Line, ";");
5167 entry.SubEntries[subentry].NumberType=atoi(ptr);
5168 // Phone Numbers need to have a number type.
5169 if(!ptr && entry.SubEntries[subentry].EntryType == GSM_Number)
5171 fprintf(stderr, _("Missing phone number type on line %d"
5172 " entry %d [%s]\n"), line_count, subentry, BackLine);
5177 #if defined(__svr4__) || defined(__FreeBSD__)
5178 ptr=strtok(NULL, ";");
5180 ptr=strsep(&Line, ";");
5183 entry.SubEntries[subentry].BlockNumber=atoi(ptr);
5185 #if defined(__svr4__) || defined(__FreeBSD__)
5186 ptr=strtok(NULL, ";");
5188 ptr=strsep(&Line, ";");
5190 // 0x13 Date Type; it is only for Dailed Numbers, etc.
5191 // we don't store to this memories so it's an error to use it.
5192 if(!ptr || entry.SubEntries[subentry].EntryType == GSM_Date)
5194 fprintf(stderr, _("Is not a phone number on line %d entry %d [%s]\n"),
5195 line_count, subentry, BackLine);
5200 strcpy( entry.SubEntries[subentry].data.Number, ptr );
5203 entry.SubEntriesCount = subentry;
5206 /* This is to send other exports (like from 6110) to 7110 */
5207 if (!entry.SubEntriesCount) {
5208 entry.SubEntriesCount = 1;
5209 entry.SubEntries[subentry].EntryType = GSM_Number;
5210 entry.SubEntries[subentry].NumberType = GSM_General;
5211 entry.SubEntries[subentry].BlockNumber = 2;
5212 strcpy(entry.SubEntries[subentry].data.Number, entry.Number);
5218 GSM_PhonebookEntry tmp_entry;
5220 memcpy(&tmp_entry, &entry, sizeof(GSM_PhonebookEntry) );
5221 error = GSM->GetMemoryLocation(&tmp_entry);
5222 if (error == GE_NONE) {
5223 if (!tmp_entry.Empty) {
5226 FILE *input_flow; //for reading from console, even when input redir.
5228 input_flow = fopen(DEV_CONSOLE, "r");
5231 fprintf(stderr, _("Can't open \"%s\" for input !\n"),DEV_CONSOLE);
5235 fprintf(stderr, _("Location busy. "));
5236 while (confirm < 0) {
5237 fprintf(stderr, _("Overwrite? (yes/no) "));
5238 GetLine(input_flow, ans, 7);
5239 if (!strcmp(ans, "yes")) confirm = 1;
5240 else if (!strcmp(ans, "no")) confirm = 0;
5242 if (!confirm) continue;
5245 fprintf(stderr, _("Unknown error (%d)\n"), error);
5251 /* Do write and report success/failure. */
5252 semicolon_pipe_substitution( &entry, 1 );
5254 error = GSM->WritePhonebookLocation(&entry);
5256 if (error == GE_NONE)
5257 fprintf (stdout, _("Write Succeeded: memory type: %s, loc: %d, name: %s, number: %s\n"), memory_type_string, entry.Location, entry.Name, entry.Number);
5259 fprintf (stdout, _("Write FAILED(%d): memory type: %s, loc: %d, name: %s, number: %s\n"), error, memory_type_string, entry.Location, entry.Name, entry.Number);
5268 /* Getting speed dials. */
5270 static int getspeeddial(char *Number) {
5272 GSM_SpeedDial entry;
5274 GSM_PhonebookEntry pbentry;
5276 entry.Number = atoi(Number);
5280 if (GSM->GetSpeedDial(&entry)==GE_NONE) {
5281 pbentry.Location=entry.Location;
5282 if (pbentry.Location==0) pbentry.Location=entry.Number;
5283 pbentry.MemoryType=entry.MemoryType;
5285 error=GSM->GetMemoryLocation(&pbentry);
5287 if (error == GE_NONE)
5289 fprintf(stdout, _("SpeedDial nr. %d: %d:%d (%s)\n"), entry.Number, entry.MemoryType, entry.Location,pbentry.Name);
5291 fprintf(stdout, _("Error\n"));
5293 fprintf(stdout, _("Error\n"));
5301 /* Setting speed dials. */
5303 static int setspeeddial(char *argv[]) {
5305 GSM_SpeedDial entry;
5307 char *memory_type_string;
5309 /* Handle command line args that set type, start and end locations. */
5311 if (strcmp(argv[1], "ME") == 0) {
5312 entry.MemoryType = GMT_ME;
5313 memory_type_string = "ME";
5315 else if (strcmp(argv[1], "SM") == 0) {
5316 entry.MemoryType = GMT_SM;
5317 memory_type_string = "SM";
5320 fprintf(stderr, _("Unknown memory type %s!\n"), argv[1]);
5325 entry.Number = atoi(argv[0]);
5326 entry.Location = atoi(argv[2]);
5330 if (GSM->SetSpeedDial(&entry) == GE_NONE) {
5331 fprintf(stdout, _("Succesfully written!\n"));
5341 /* Getting the status of the display. */
5343 int getdisplaystatus()
5348 /* Initialise the code for the GSM interface. */
5352 if (GSM->GetDisplayStatus(&Status)==GE_NONE) {
5354 printf(_("Call in progress: %s\n"), Status & (1<<DS_Call_In_Progress)?_("on"):_("off"));
5355 printf(_("Unknown: %s\n"), Status & (1<<DS_Unknown)?_("on"):_("off"));
5356 printf(_("Unread SMS: %s\n"), Status & (1<<DS_Unread_SMS)?_("on"):_("off"));
5357 printf(_("Voice call: %s\n"), Status & (1<<DS_Voice_Call)?_("on"):_("off"));
5358 printf(_("Fax call active: %s\n"), Status & (1<<DS_Fax_Call)?_("on"):_("off"));
5359 printf(_("Data call active: %s\n"), Status & (1<<DS_Data_Call)?_("on"):_("off"));
5360 printf(_("Keyboard lock: %s\n"), Status & (1<<DS_Keyboard_Lock)?_("on"):_("off"));
5361 printf(_("SMS storage full: %s\n"), Status & (1<<DS_SMS_Storage_Full)?_("on"):_("off"));
5364 printf(_("Error\n"));
5372 int netmonitor(char *Mode)
5375 unsigned char mode=atoi(Mode);
5376 char Screen[NM_MAX_SCREEN_WIDTH];
5381 if (!strcmp(Mode,"reset")) mode=0xf0;
5382 else if (!strcmp(Mode,"off")) mode=0xf1;
5383 else if (!strcmp(Mode,"field"))mode=0xf2;
5384 else if (!strcmp(Mode,"devel"))mode=0xf3;
5385 else if (!strcmp(Mode,"next")) mode=0x00;
5388 for (i=0;i<NM_MAX_SCREEN_WIDTH;i++) Screen[i]=0;
5390 GSM->NetMonitor(mode, Screen);
5393 printf("%s\n", Screen);
5400 #endif /* UCLINUX */
5402 static int identify( void )
5404 /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */
5405 char imei[64], model[64], rev[64], manufacturer[64];
5411 while (GSM->GetIMEI(imei) != GE_NONE) sleep(1);
5413 while (GSM->GetRevision(rev) != GE_NONE) sleep(1);
5415 while (GSM->GetModel(model) != GE_NONE) sleep(1);
5418 strcpy(manufacturer, "(unknown)");
5420 GSM->GetManufacturer(manufacturer);
5423 fprintf(stdout, _("IMEI: %s\n"), imei);
5424 fprintf(stdout, _("Model: %s %s (%s)\n"), manufacturer, GetModelName (model), model);
5425 fprintf(stdout, _("Revision: %s\n"), rev);
5436 int senddtmf(char *String)
5441 if (GSM->SendDTMF(String)!=GE_NONE) fprintf(stdout,_("Error!\n"));
5448 #endif /* UCLINUX */
5450 /* Resets the phone */
5451 static int reset(int argc, char *argv[])
5454 unsigned char _type=0x03;
5459 if (!strcmp(argv[0],"soft")) _type = 0x03;
5461 /* Doesn't work with 5110 */
5462 if (!strcmp(argv[0],"hard")) _type = 0x04;
5465 fprintf(stderr, _("What kind of reset do you want (second parameter can be \"soft\" or \"hard\") ?\n"));
5481 /* This is a "convenience" function to allow quick test of new API stuff which
5482 doesn't warrant a "proper" command line function. */
5484 int foogle(char *argv[])
5486 /* Initialise the code for the GSM interface. */
5490 // Fill in what you would like to test here...
5501 /* Initialise the code for the GSM interface. */
5505 if (GSM->PhoneTests()!=GE_NONE) fprintf(stderr,_("Error\n"));
5512 /* pmon allows fbus code to run in a passive state - it doesn't worry about
5513 whether comms are established with the phone. A debugging/development
5520 GSM_ConnectionType connection=GCT_FBUS;
5522 /* Initialise the code for the GSM interface. */
5524 error = GSM_Initialise(model, Port, Initlength, connection, RLP_DisplayF96Frame, ""/*SynchronizeTime*/);
5526 if (error != GE_NONE) {
5527 fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n"));
5539 int setringtone(int argc, char *argv[])
5541 GSM_Ringtone ringtone;
5542 GSM_BinRingtone binringtone,binringtone2;
5546 int current=0; //number of packed notes or location
5551 /* If not binary ringtone */
5552 if (GSM_ReadBinRingtoneFile(argv[0],&binringtone2)!=GE_NONE) {
5553 fprintf(stdout,_("Not binary ringtone, trying RTTL\n"));
5555 if (GSM_ReadRingtoneFileOnConsole(argv[0], &ringtone)!=GE_NONE) return(-1);
5557 ringtone.location=1;
5558 if (argc>1) ringtone.location=atoi(argv[1]);
5560 ringtone.allnotesscale=false;
5562 /* Initialise the GSM interface. */
5565 while (GSM->GetModel(model) != GE_NONE)
5568 /* For Nokia 6110/6130/6150/6210 we use different method of uploading.
5569 Phone will display menu, when received it */
5570 if ( !strcmp(model,"NSE-3") || !strcmp(model,"NSK-3") ||
5571 !strcmp(model,"NSM-1") || !strcmp(model,"NPE-3") ) {
5572 if (argc==1) ringtone.location=255;
5575 error=GSM->SetRingtone(&ringtone,¤t);
5577 if (current!=ringtone.NrNotes) {
5578 if (current>FB61_MAX_RINGTONE_NOTES) {
5579 fprintf(stderr,_("Warning: due to phone limitation"));
5581 fprintf(stderr,_("Warning: ringtone was too long to be saved into frame,"));
5583 fprintf(stderr, _(" only %i first notes were packed (%i cut)\n"),current,ringtone.NrNotes-current);
5587 fprintf(stdout, _("Set succeeded!\n"));
5589 fprintf(stdout, _("Setting failed\n"));
5591 } else { /* This IS binary ringtone */
5592 fprintf(stdout,_("Binary ringtone format\n"));
5595 binringtone.frame[current++]=0x00;
5596 binringtone.frame[current++]=0x00;
5597 binringtone.frame[current++]=0x0c;
5598 binringtone.frame[current++]=0x01;
5599 binringtone.frame[current++]=0x2c;
5602 memcpy(binringtone.frame+current,argv[2],strlen(argv[2]));
5603 current=current+strlen(argv[2]);
5607 while(binringtone2.frame[i]!=0x00) {
5608 if (i==binringtone.length) break;
5613 memcpy(binringtone.frame+current,binringtone2.frame+i,binringtone2.length-i);
5614 binringtone.length=binringtone2.length-i+current;
5617 memcpy(binringtone.frame+current,binringtone2.frame,binringtone2.length);
5618 binringtone.length=binringtone2.length;
5621 binringtone.location=1;
5622 if (argc>1) binringtone.location=atoi(argv[1]);
5624 /* Initialise the GSM interface. */
5627 error=GSM->SetBinRingtone(&binringtone);
5631 fprintf(stdout, _("Set succeeded!\n"));
5633 case GE_INVALIDRINGLOCATION:
5634 fprintf(stdout, _("Invalid location %i!\n"),binringtone.location);
5636 case GE_UNKNOWNMODEL:
5637 fprintf(stdout, _("Mygnokii doesn't know format for this model!\n"));
5639 case GE_NOTIMPLEMENTED:
5640 fprintf(stdout, _("Not implemented for this model!\n"));
5643 fprintf(stdout, _("Not supported by this model!\n"));
5653 int ringtoneconvert(int argc, char *argv[])
5655 GSM_Ringtone ringtone;
5657 if (!strcmp(argv[0],argv[1]))
5659 fprintf(stderr, _("Files can't have the same names !\n"));
5663 if (GSM_ReadRingtoneFileOnConsole(argv[0], &ringtone)!=GE_NONE) return(-1);
5665 ringtone.allnotesscale=false;
5667 GSM_SaveRingtoneFileOnConsole(argv[1], &ringtone);
5672 int playringtone(int argc, char *argv[])
5674 GSM_Ringtone ringtone;
5676 GSM_BinRingtone binringtone;
5682 //{ "c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "h" };
5683 int binary_notes[12] =
5684 { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11 , 12};
5686 if (GSM_ReadBinRingtoneFile(argv[0],&binringtone)!=GE_NONE) {
5687 fprintf(stdout,_("Not binary ringtone, trying RTTL\n"));
5689 if (GSM_ReadRingtoneFileOnConsole(argv[0], &ringtone)!=GE_NONE) return(-1);
5691 /* Initialise the GSM interface. */
5694 fprintf(stdout,_("Playing \"%s\" (%i notes)\n"),ringtone.name,ringtone.NrNotes);
5696 GSM_PlayRingtoneOnConsole(&ringtone);
5700 fprintf(stdout,_("Binary ringtone format\n"));
5702 /* Initialise the GSM interface. */
5706 while (true) { //skipping name
5707 if (binringtone.frame[i]==0) break;
5713 if (binringtone.frame[i]!=j) {
5716 fprintf(stdout,_("Block in binary ringtone %i %i\n"),j,z);
5723 if (!isok && j>=114 && j<=125) {
5724 j=14*3+binary_notes[j-114];
5727 if (!isok && j>=126 && j<=137) {
5728 j=14*1+binary_notes[j-126];
5731 if (!isok && j>=138 && j<=149) {
5732 j=14*2+binary_notes[j-138];
5735 if (!isok && j>=150 && j<=161) {
5736 j=14*4+binary_notes[j-150];
5741 fprintf(stdout,_("Unknown block in binary ringtone %i %i\n"),j,z);
5744 Hz=GSM_GetFrequency(j);
5745 if (GSM->PlayTone(Hz,5)!=GE_NONE) fprintf(stdout,_("error during playing\n"));
5749 j=binringtone.frame[i];
5750 z=binringtone.frame[i+1];
5752 z=z+binringtone.frame[i+1];
5755 if (i>=binringtone.length) break;
5766 int composer(int argc, char *argv[])
5768 GSM_Ringtone ringtone;
5771 int oldnoteslen=4,nownoteslen,oldnoteslen2;
5772 int oldnotesscale=1,nownotesscale;
5773 bool firstnote=true;
5774 int DefNoteTempo=63;
5776 if (GSM_ReadRingtoneFileOnConsole(argv[0], &ringtone)!=GE_NONE) return(-1);
5778 if (ringtone.NrNotes!=0)
5779 DefNoteTempo=ringtone.notes[0].tempo;
5781 fprintf(stdout,_("Ringtone \"%s\" (tempo = %i Beats Per Minute)\n\n"),ringtone.name,GSM_GetTempo(DefNoteTempo));
5783 for (i=0;i<ringtone.NrNotes;i++) {
5784 if (DefNoteTempo!=ringtone.notes[i].tempo) {
5785 fprintf(stdout,_("WARNING: IN FACT RINGTONE HAS DIFFERENT TEMPO FOR DIFFERENT NOTES AND THAT'S WHY YOU CAN'T ENTER IT ALL IN THE COMPOSITOR\n\n"));
5790 for (i=0;i<ringtone.NrNotes;i++) {
5793 if (GSM_GetNote(ringtone.notes[i].note)!=Note_Pause)
5803 if ((ringtone.NrNotes-i)>50)
5804 fprintf(stdout,_("WARNING: LENGTH=%i, BUT YOU WILL ENTER ONLY FIRST 50 TONES. TO ENTER FULL RINGTONE MUST SEND IT (--sendringtone) OR DOWNLOAD (--setringtone)\n\n"),ringtone.NrNotes-i);
5806 fprintf(stdout,_("This ringtone in Nokia Composer in phone should look: "));
5810 for (i=0;i<ringtone.NrNotes;i++) {
5813 if (GSM_GetNote(ringtone.notes[i].note)!=Note_Pause)
5819 switch (ringtone.notes[i].duration) {
5820 case 192:fprintf(stdout,_("1."));break; //192=128*1.5
5821 case 128:fprintf(stdout,_("1"));break;
5822 case 96 :fprintf(stdout,_("2."));break; //96=64*1.5
5823 case 64 :fprintf(stdout,_("2"));break;
5824 case 48 :fprintf(stdout,_("4."));break; //48=32*1.5
5825 case 32 :fprintf(stdout,_("4"));break;
5826 case 24 :fprintf(stdout,_("8."));break; //24=16*1.5
5827 case 16 :fprintf(stdout,_("8"));break;
5828 case 12 :fprintf(stdout,_("16."));break; //12=8*1.5
5829 case 8 :fprintf(stdout,_("16"));break;
5830 case 6 :fprintf(stdout,_("32."));break; //6=4*1.5
5831 case 4 :fprintf(stdout,_("32"));break;
5836 /* What note here ? */
5837 switch (GSM_GetNote(ringtone.notes[i].note)) {
5838 case Note_C :fprintf(stdout,_("c"));break;
5839 case Note_Cis:fprintf(stdout,_("#c"));break;
5840 case Note_D :fprintf(stdout,_("d"));break;
5841 case Note_Dis:fprintf(stdout,_("#d"));break;
5842 case Note_E :fprintf(stdout,_("e"));break;
5843 case Note_F :fprintf(stdout,_("f"));break;
5844 case Note_Fis:fprintf(stdout,_("#f"));break;
5845 case Note_G :fprintf(stdout,_("g"));break;
5846 case Note_Gis:fprintf(stdout,_("#g"));break;
5847 case Note_A :fprintf(stdout,_("a"));break;
5848 case Note_Ais:fprintf(stdout,_("#a"));break;
5849 case Note_H :fprintf(stdout,_("h"));break;
5850 default :fprintf(stdout,_("-"));unknown=true;break; //Pause ?
5854 fprintf(stdout,_("%i"),ringtone.notes[i].note/14);
5856 /* And separator before next note */
5857 if (i!=ringtone.NrNotes-1)
5858 fprintf(stdout,_(" "));
5864 fprintf(stdout,_("\n\nTo enter it please press: "));
5868 for (i=0;i<ringtone.NrNotes;i++) {
5871 if (GSM_GetNote(ringtone.notes[i].note)!=Note_Pause)
5879 /* What note here ? */
5880 switch (GSM_GetNote(ringtone.notes[i].note)) {
5881 case Note_C :fprintf(stdout,_("1"));break;
5882 case Note_Cis:fprintf(stdout,_("1"));break;
5883 case Note_D :fprintf(stdout,_("2"));break;
5884 case Note_Dis:fprintf(stdout,_("2"));break;
5885 case Note_E :fprintf(stdout,_("3"));break;
5886 case Note_F :fprintf(stdout,_("4"));break;
5887 case Note_Fis:fprintf(stdout,_("4"));break;
5888 case Note_G :fprintf(stdout,_("5"));break;
5889 case Note_Gis:fprintf(stdout,_("5"));break;
5890 case Note_A :fprintf(stdout,_("6"));break;
5891 case Note_Ais:fprintf(stdout,_("6"));break;
5892 case Note_H :fprintf(stdout,_("7"));break;
5893 default :fprintf(stdout,_("0"));unknown=true;break;
5896 switch (ringtone.notes[i].duration) {
5897 case 192:fprintf(stdout,_("(longer)"));break; //192=128*1.5
5898 case 96 :fprintf(stdout,_("(longer)"));break; //96=64*1.5
5899 case 48 :fprintf(stdout,_("(longer)"));break; //48=32*1.5
5900 case 24 :fprintf(stdout,_("(longer)"));break; //24=16*1.5
5901 case 12 :fprintf(stdout,_("(longer)"));break; //12=8*1.5
5902 case 6 :fprintf(stdout,_("(longer)"));break; //6=4*1.5
5906 /* What note here ? */
5907 switch (GSM_GetNote(ringtone.notes[i].note)) {
5908 case Note_Cis:fprintf(stdout,_("#"));break;
5909 case Note_Dis:fprintf(stdout,_("#"));break;
5910 case Note_Fis:fprintf(stdout,_("#"));break;
5911 case Note_Gis:fprintf(stdout,_("#"));break;
5912 case Note_Ais:fprintf(stdout,_("#"));break;
5918 nownotesscale=ringtone.notes[i].note/14;
5920 if (nownotesscale!=oldnotesscale) {
5921 switch (nownotesscale) {
5923 switch (oldnotesscale) {
5924 case 2:fprintf(stdout,_("**"));break;
5925 case 3:fprintf(stdout,_("*"));break;
5929 switch (oldnotesscale) {
5930 case 1:fprintf(stdout,_("*"));break;
5931 case 3:fprintf(stdout,_("**"));break;
5935 switch (oldnotesscale) {
5936 case 1:fprintf(stdout,_("**"));break;
5937 case 2:fprintf(stdout,_("*"));break;
5943 oldnotesscale=nownotesscale;
5947 oldnoteslen2=oldnoteslen;
5949 switch (ringtone.notes[i].duration) {
5950 case 192:nownoteslen=1;break; //192=128*1.5
5951 case 128:nownoteslen=1;break;
5952 case 96 :nownoteslen=2;break; //96=64*1.5
5953 case 64 :nownoteslen=2;break;
5954 case 48 :nownoteslen=4;break; //48=32*1.5
5955 case 32 :nownoteslen=4;break;
5956 case 24 :nownoteslen=8;break; //24=16*1.5
5957 case 16 :nownoteslen=8;break;
5958 case 12 :nownoteslen=16;break; //12=8*1.5
5959 case 8 :nownoteslen=16;break;
5960 case 6 :nownoteslen=32;break; //6=4*1.5
5961 case 4 :nownoteslen=32;break;
5964 if (nownoteslen>oldnoteslen) {
5965 while (oldnoteslen!=nownoteslen) {
5966 fprintf(stdout,_("8"));
5967 oldnoteslen=oldnoteslen*2;
5971 if (nownoteslen<oldnoteslen) {
5972 while (oldnoteslen!=nownoteslen) {
5973 fprintf(stdout,_("9"));
5974 oldnoteslen=oldnoteslen/2;
5978 if (GSM_GetNote(ringtone.notes[i].note)==Note_Pause)
5979 oldnoteslen=oldnoteslen2;
5981 /* And separator before next note */
5982 if (i!=ringtone.NrNotes-1)
5983 fprintf(stdout,_(" "));
5988 fprintf(stdout,_("\n"));
5994 int sendringtone(int argc, char *argv[])
5996 GSM_Ringtone ringtone;
5997 GSM_MultiSMSMessage SMS;
5999 bool ProfileStyle=false; /* If we use profile style available in new Nokia models */
6001 if (GSM_ReadRingtoneFileOnConsole(argv[1], &ringtone)!=GE_NONE) return(-1);
6003 ringtone.allnotesscale=false;
6005 for (i=0;i<argc;i++) {
6006 if (!strcmp(argv[i],"--profilestyle")) ProfileStyle=true;
6007 if (!strcmp(argv[i],"--scale")) ringtone.allnotesscale=true;
6010 current=GSM_SaveRingtoneToSMS(&SMS,&ringtone,ProfileStyle);
6012 if (current!=ringtone.NrNotes) {
6013 if (current>FB61_MAX_RINGTONE_NOTES) {
6014 fprintf(stderr,_("Warning: due to phone limitation"));
6016 fprintf(stderr,_("Warning: ringtone was too long to be saved into SMS,"));
6018 fprintf(stderr, _(" only %i first notes were packed (%i cut)\n"),current,ringtone.NrNotes-current);
6021 for (i=0;i<SMS.number;i++) {
6022 strcpy(SMS.SMS[i].Destination,argv[0]);
6025 /* Initialise the GSM interface. */
6028 GSM_SendMultiPartSMSOnConsole(&SMS, 2,argc,argv,false,true,true);
6033 int saveringtone(int argc, char *argv[])
6035 GSM_Ringtone ringtone;
6036 GSM_MultiSMSMessage SMS;
6038 bool ProfileStyle=false; /* If we use profile style available in new Nokia models */
6040 if (GSM_ReadRingtoneFileOnConsole(argv[0], &ringtone)!=GE_NONE) return(-1);
6042 ringtone.allnotesscale=false;
6044 for (i=0;i<argc;i++) {
6045 if (!strcmp(argv[i],"--profilestyle")) ProfileStyle=true;
6046 if (!strcmp(argv[i],"--scale")) ringtone.allnotesscale=true;
6049 current=GSM_SaveRingtoneToSMS(&SMS,&ringtone,ProfileStyle);
6051 if (current!=ringtone.NrNotes) {
6052 if (current>FB61_MAX_RINGTONE_NOTES) {
6053 fprintf(stderr,_("Warning: due to phone limitation"));
6055 fprintf(stderr,_("Warning: ringtone was too long to be saved into SMS,"));
6057 fprintf(stderr, _(" only %i first notes were packed (%i cut)\n"),current,ringtone.NrNotes-current);
6060 for (i=0;i<SMS.number;i++) {
6061 /* Only 11 chars could be here */
6062 strncpy(SMS.SMS[i].Destination,ringtone.name,11);
6065 /* Initialise the GSM interface. */
6068 GSM_SaveMultiPartSMSOnConsole(&SMS,1,argc,argv,false,false,true,true);
6073 /* Converts logo files. */
6075 int bitmapconvert(int argc, char *argv[])
6078 GSM_NetworkInfo NetworkInfo;
6082 if (!strcmp(argv[0],argv[1]))
6084 fprintf(stderr, _("Files can't have the same names !\n"));
6088 if (GSM_ReadBitmapFileOnConsole(argv[0], &bitmap)!=GE_NONE) return(-1);
6093 if (!strcmp(argv[2],"op"))
6096 if (argc<4) doit=true;
6097 if (argc<4 && bitmap.type!=GSM_OperatorLogo) doit=true;
6101 if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode,NetworkInfo.NetworkCode,7);
6104 GSM_ResizeBitmap(&bitmap,GSM_OperatorLogo);
6107 strncpy(bitmap.netcode,argv[3],7);
6108 if (!strcmp(GSM_GetNetworkName(bitmap.netcode),"unknown"))
6110 fprintf(stderr,"Sorry, gnokii doesn't know \"%s\" network !\n",bitmap.netcode);
6116 if (!strcmp(argv[2],"7110op"))
6119 if (argc<4) doit=true;
6120 if (argc<4 && bitmap.type!=GSM_7110OperatorLogo) doit=true;
6124 if (GSM->GetNetworkInfo(&NetworkInfo) == GE_NONE) strncpy(bitmap.netcode,NetworkInfo.NetworkCode,7);
6127 GSM_ResizeBitmap(&bitmap,GSM_7110OperatorLogo);
6130 strncpy(bitmap.netcode,argv[3],7);
6131 if (!strcmp(GSM_GetNetworkName(bitmap.netcode),"unknown"))
6133 fprintf(stderr,"Sorry, gnokii doesn't know \"%s\" network !\n",bitmap.netcode);
6139 if (!strcmp(argv[2],"caller"))
6141 GSM_ResizeBitmap(&bitmap,GSM_CallerLogo);
6145 if ((num<0)||(num>9)) num=0;
6153 if (!strcmp(argv[2],"startup"))
6155 GSM_ResizeBitmap(&bitmap,GSM_StartupLogo);
6158 if (!strcmp(argv[2],"7110startup"))
6160 GSM_ResizeBitmap(&bitmap,GSM_7110StartupLogo);
6163 if (!strcmp(argv[2],"6210startup"))
6165 GSM_ResizeBitmap(&bitmap,GSM_6210StartupLogo);
6168 if (!strcmp(argv[2],"picture"))
6170 GSM_ResizeBitmap(&bitmap,GSM_PictureImage);
6175 fprintf(stderr,"Unknown type of logo: %s !\n",argv[2]);
6180 if (GSM_SaveBitmapFileOnConsole(argv[1], &bitmap)!=GE_NONE) return(-1);
6185 int getphoneprofile()
6190 /* Initialise the GSM interface. */
6194 error=GSM->GetProductProfileSetting(&PPS);
6195 if (error!=GE_NONE) {
6196 fprintf(stdout,_("Error!\n"));
6200 fprintf(stdout,_("ALS : "));
6201 if (PPS.bool_value) fprintf(stdout,_("on\n"));
6202 else fprintf(stdout,_("off\n"));
6204 PPS.Name=PPS_VibraMenu;
6205 GSM->GetProductProfileSetting(&PPS);
6206 fprintf(stdout,_("Vibra menu : "));
6207 if (PPS.bool_value) fprintf(stdout,_("on\n"));
6208 else fprintf(stdout,_("off\n"));
6210 PPS.Name=PPS_GamesMenu;
6211 GSM->GetProductProfileSetting(&PPS);
6212 fprintf(stdout,_("Games menu : "));
6213 if (PPS.bool_value) fprintf(stdout,_("on\n"));
6214 else fprintf(stdout,_("off\n"));
6216 PPS.Name=PPS_HRData;
6217 GSM->GetProductProfileSetting(&PPS);
6218 fprintf(stdout,_("HR Data : "));
6219 if (PPS.bool_value) fprintf(stdout,_("on\n"));
6220 else fprintf(stdout,_("off\n"));
6222 PPS.Name=PPS_14400Data;
6223 GSM->GetProductProfileSetting(&PPS);
6224 fprintf(stdout,_("14400 Data : "));
6225 if (PPS.bool_value) fprintf(stdout,_("on\n"));
6226 else fprintf(stdout,_("off\n"));
6228 PPS.Name=PPS_LCDContrast;
6229 GSM->GetProductProfileSetting(&PPS);
6230 fprintf(stdout,_("LCD Contrast : %i%%\n"),PPS.int_value);
6233 GSM->GetProductProfileSetting(&PPS);
6234 fprintf(stdout,_("EFR : "));
6235 switch (PPS.int_value) {
6236 case 0: fprintf(stdout,_("off\n")); break;
6237 case 1: fprintf(stdout,_("last\n")); break;
6238 case 2: fprintf(stdout,_("second\n"));break;
6239 case 3: fprintf(stdout,_("first\n")); break;
6243 GSM->GetProductProfileSetting(&PPS);
6244 fprintf(stdout,_("FR : "));
6245 switch (PPS.int_value) {
6246 case 0: fprintf(stdout,_("off\n")); break;
6247 case 1: fprintf(stdout,_("last\n")); break;
6248 case 2: fprintf(stdout,_("second\n"));break;
6249 case 3: fprintf(stdout,_("first\n")); break;
6253 GSM->GetProductProfileSetting(&PPS);
6254 fprintf(stdout,_("HR : "));
6255 switch (PPS.int_value) {
6256 case 0: fprintf(stdout,_("off\n")); break;
6257 case 1: fprintf(stdout,_("last\n")); break;
6258 case 2: fprintf(stdout,_("second\n"));break;
6259 case 3: fprintf(stdout,_("first\n")); break;
6268 int setphoneprofile(int argc, char *argv[])
6272 bool correct_arg1=false, correct_arg2=false;
6274 if (!strcmp(argv[0],"ALS")) {
6277 if (!strcmp(argv[1],"1")) {
6278 PPS.bool_value=true;
6281 if (!strcmp(argv[1],"0")) {
6282 PPS.bool_value=false;
6285 if (!correct_arg2) {
6286 fprintf(stdout,_("Settings for ALS parameter can be \"0\" or \"1\" !\n"));
6290 if (!strcmp(argv[0],"HRData")) {
6291 PPS.Name=PPS_HRData;
6293 if (!strcmp(argv[1],"1")) {
6294 PPS.bool_value=true;
6297 if (!strcmp(argv[1],"0")) {
6298 PPS.bool_value=false;
6301 if (!correct_arg2) {
6302 fprintf(stdout,_("Settings for HRData parameter can be \"0\" or \"1\" !\n"));
6306 if (!correct_arg1) {
6307 fprintf(stdout,_("First parameter can be \"ALS\" or \"HRData\" only !\n"));
6311 /* Initialise the GSM interface. */
6314 error=GSM->SetProductProfileSetting(&PPS);
6316 if (error!=GE_NONE) {
6317 fprintf(stdout,_("Error!\n"));
6330 int getoperatorname()
6333 GSM_Network network;
6335 /* Initialise the GSM interface. */
6338 if (GSM->GetOperatorName(&network)==GE_NONE)
6340 if (!strcmp(network.Name,"")) {
6341 fprintf(stdout,_("Phone doesn't have downloaded operator name\n"));
6343 fprintf(stdout,_("Phone has downloaded operator name (\"%s\") for \"%s\" (\"%s\") network\n"),
6344 network.Name,network.Code,GSM_GetNetworkName(network.Code));
6354 int setoperatorname(int argc, char *argv[])
6357 GSM_Network network;
6359 /* Initialise the GSM interface. */
6363 strncpy(network.Code,argv[0],7);
6364 strncpy(network.Name,argv[1],50);
6366 strcpy(network.Code,"000 00\0");
6367 strcpy(network.Name,"\0");
6370 if (GSM->SetOperatorName(&network)==GE_NONE) {
6371 if (GSM->GetOperatorName(&network)==GE_NONE) {
6372 if (!strcmp(network.Name,"")) {
6373 fprintf(stdout,_("Downloaded operator name is removed\n"));
6375 fprintf(stdout,_("Downloaded operator name changed for \"%s\" network (\"%s\") to \"%s\"\n"),
6376 network.Code,GSM_GetNetworkName(network.Code),network.Name);
6387 int getvoicemailbox()
6389 GSM_PhonebookEntry entry;
6391 /* Initialise the GSM interface. */
6394 if (GSM->GetVoiceMailbox(&entry)==GE_NONE) {
6395 fprintf(stdout,_("Voice mailbox number is "));
6396 if (!strcmp(entry.Number,""))
6397 fprintf(stdout,_("not set\n"));
6399 fprintf(stdout,_("\"%s\"\n"),entry.Number);
6408 ///////////////////////////////////////////////////////////////////////////////
6409 // flow diagram of netmonitordata():
6410 ///////////////////////////////////////////////////////////////////////////////
6412 // get command line argument
6416 // if specific phone model
6419 // identify-phone: (((((((( TO DO )))))))))))))
6423 // get_mon_param_info() get phone netmonitor parameters name
6424 // specifically to a 'model'
6427 // parse_check() check command line arguments
6428 // | if all OK, go on else stop.
6429 // | because we can have a input file
6430 // v containing multiple
6431 // parse_process() command lines, we process each at once
6432 // so we can exit early on errors.
6434 ///////////////////////////////////////////////////////////////////////////////
6436 // private functions, see netmonitordata()
6437 void free_nm_info(PARAM_INFO_MON *info)
6439 PARAM_INFO_MON *tmp; // pointer, iterator on info
6441 // go to end of list
6443 while (info->next != NULL)
6453 ///////////////////////////////////////////////////////////////////////////////
6454 // this func retrieve parameters info from a file
6455 // and load it in a dynamic array, NULL terminated,
6456 // if 2rd parameter is not NULL, it load also description of screen
6457 // return (PARAM_INFO_MON *start) if all is OK, else NULL
6458 ///////////////////////////////////////////////////////////////////////////////
6459 // start->->next->next->next-> ...->next->NULL
6462 // par0 par1 par2 parN
6463 ///////////////////////////////////////////////////////////////////////////////
6464 // this should be de-allocated from calling function,
6465 // also, screen_name should be deallocated from calling function
6466 ///////////////////////////////////////////////////////////////////////////////
6468 PARAM_INFO_MON *get_mon_param_info(char *f_name, char *screen_name[NM_MAX_SCREEN+1])
6470 PARAM_INFO_MON *start; // pointer to netmonitor parameters info
6471 PARAM_INFO_MON *info; // pointer, iterator on info
6472 PARAM_INFO_MON *check; // pointer, iterator on info, for check usage
6481 char tmp_mname[55]; // very larger, but if netmon bug ...
6482 int x, y, len, s, t; // x & y coord, len, screen nr, type
6485 if (screen_name != NULL)
6486 for (i = 0; i <= NM_MAX_SCREEN; i++)
6487 screen_name[i] = NULL;
6490 if ((f_info = fopen(f_name, "r")) == NULL)
6491 { fprintf(stderr, "Can' t open file parameter info: <%s>\n", f_name);
6495 if ((start = malloc(sizeof(PARAM_INFO_MON))) == NULL)
6496 { fprintf(stderr, "no mem\n");
6500 { start->next = NULL;
6504 while (fgets(buf, 256, f_info) != NULL)
6508 // Truncate from '#' at right of comments
6509 if ((tmp = strchr(param, '#')) != NULL)
6512 // Strip leading, trailing whitespace
6513 while(isspace((int) *param))
6516 while((strlen(param) > 0) && isspace((int) param[strlen(param) - 1]))
6517 param[strlen(param) - 1] = '\0';
6519 // Ignore blank lines
6520 if ((*param == '\n') || (*param == '\0'))
6525 fprintf(stderr, "%s: info line: <%s>\n", f_name, param);
6527 // check for param name
6528 if ((param_name = strtok(param, "=\t\n")) == NULL)
6531 // check if screen name
6532 if (strncmp("SCREEN", param_name, 6) == 0)
6534 // if we do not want screen names ...
6535 if (screen_name == NULL)
6538 // FIXME check for screen nr
6539 if ((tmp = strtok(NULL, ":\n")) == NULL)
6543 // FIXME: check if already defined screen
6545 if ((i <= 0) || (i > NM_MAX_SCREEN))
6547 // check for screen name
6548 if ((tmp = strtok(NULL, ":\n")) == NULL)
6551 screen_name[i] = strdup(tmp);
6557 // FIXME: check for NM_MAX_FIELDS
6559 // check for x coord
6560 if ((tmp = strtok(NULL, ":\t\n")) == NULL)
6564 // check for y coord
6565 if ((tmp = strtok(NULL, ":\t\n")) == NULL)
6570 if ((tmp = strtok(NULL, ":\t\n")) == NULL)
6575 if ((tmp = strtok(NULL, ":\t\n")) == NULL)
6579 // check for netmon manual name
6580 if ((tmp = strtok(NULL, ":\t\n")) == NULL)
6582 "%s: PARAMETER <%s> in screen <%d>, not have netmon manual reference\n",
6583 f_name, param_name, s);
6584 free_nm_info(start);
6587 strcpy(tmp_mname, tmp);
6589 // check for data type (optional)
6590 if ((tmp = strtok(NULL, ":\t\n")) != NULL)
6595 // check len, here, so we print parameter name
6598 "%s: PARAMETER <%s> in screen <%d>, has invalid data lenght\n",
6599 f_name, param_name, s);
6600 free_nm_info(start);
6604 // check if already defined same param_name
6606 while (check->next != NULL)
6607 { check = check->next;
6608 if (strcmp(param_name, check->name) == 0)
6611 "%s: PARAMETER <%s> in screen <%d> already defined as in screen <%d>\n",
6612 f_name, param_name, s, check->s_nr);
6613 free_nm_info(start);
6618 // make space, and add parameter
6619 if ((info->next = malloc(sizeof(PARAM_INFO_MON))) != NULL)
6622 info->name = strdup(param_name);
6627 info->mname = strdup(tmp_mname);
6630 info->next = NULL; // mark end
6634 fprintf(stderr, "no mem");
6635 free_nm_info(start);
6647 while (info->next != NULL)
6650 fprintf(stderr, "info name %s\n", info->name);
6656 // 2, parse the arguments and check command(s) line
6657 // command line, phone spec input, and output are complex,
6658 // so we exit printing info about error instead of std help
6659 ///////////////////////////////////////////////////////////////////////////////
6661 int parse_check(int argc, char *argv[], PARAM_INFO_MON *start, char *f_name, int line)
6670 PARAM_INFO_MON *info; // iterator on this list
6673 for (i = 0; i < argc; i++)
6674 fprintf(stderr, "argv[%d] = <%s>\n",i, argv[i]);
6684 { // should be one of the short option
6685 if (strcmp(argv[i], "-fs") == 0)
6686 { // field separator, next arg should be a string
6687 if (((i+1) < argc) && (strlen(argv[i+1]) < 10))
6689 // arg OK, do nothing
6694 "-fs: Invalid field separator in <%s> at line %d\n",
6697 fprintf(stderr, "-fs: Invalid field separator\n");
6701 else if (strcmp(argv[i], "-ls") == 0)
6702 { // line separator, next arg should be a string
6703 if (((i+1) < argc) && (strlen(argv[i+1]) < 10))
6705 // arg OK, do nothing
6710 "-ls: Invalid line separator in <%s> at line %d\n",
6713 fprintf(stderr, "-ls: Invalid line separator\n");
6717 else if (strcmp(argv[i], "-tm") == 0)
6718 { // time separator, next arg should be a millisecond (200-10000)
6722 "-tm, -ts, are mutually exclusive in <%s> at line %d\n",
6725 fprintf(stderr, "-tm, -ts, are mutually exclusive\n");
6729 if (((i+1) < argc) && (atoi(argv[i+1]) >= 200) && (atoi(argv[i+1]) <= 10000))
6732 // arg OK, do nothing
6737 "-tm: Invalid argument (200-10000 milliseconds), in <%s> at line %d\n",
6740 fprintf(stderr, "-tm: Invalid argument (200-10000 milliseconds)\n");
6744 else if (strcmp(argv[i], "-ts") == 0)
6745 { // time separator, next arg should be a seconds (1-3600)
6749 "-tm, -ts, are mutually exclusive, in <%s> at line %d\n",
6752 fprintf(stderr, "-tm, -ts, are mutually exclusive\n");
6756 if (((i+1) < argc) && (atoi(argv[i+1]) >= 1) && (atoi(argv[i+1]) <= 3600))
6759 // arg OK, do nothing
6764 "-ts: Invalid argument (1-3600 seconds) in <%s> at line %d\n",
6767 fprintf(stderr, "-ts: Invalid argument (1-3600 seconds)\n");
6771 else if (strcmp(argv[i], "-n") == 0)
6772 { // nr of data pump, before stop collection,
6773 // next arg should be a int > 0
6774 if (((i+1) < argc) && (atoi(argv[i+1]) >= 1) && (atoi(argv[i+1]) <= 99999))
6776 // arg OK, do nothing
6781 "-n: Invalid argument (1-99999 times) in <%s> at line %d\n",
6784 fprintf(stderr, "-n: Invalid argument (1-99999 times)\n");
6788 else if (strcmp(argv[i], "-h") == 0)
6789 { // we do NOT want header (default with header)
6790 // arg OK, do nothing
6792 else if (strcmp(argv[i], "-S") == 0)
6793 { // we have used use specs from a file instead of standard info,
6794 // next arg is an existing readable filename
6795 // as already parsed correctly, we skip here.
6798 else if (strcmp(argv[i], "-I") == 0)
6799 { // we have used input from a file instead of command line
6800 // next arg is an existing readable filename
6801 // as already parsed correctly, we skip here.
6807 fprintf(stderr, "Unrecognized option %s in <%s> at line %d\n",
6808 argv[i], f_name, line);
6810 fprintf(stderr, "Unrecognized option %s\n", argv[i]);
6815 { // should be required data
6816 tmp = strdup(argv[i]);
6817 p = strtok(tmp, ":\t\n");
6820 // check if there is an output format specification
6830 // we have 'minus', so, probably forget format ...
6834 "Required data <%s->, without format specifiers in <%s> at line %d\n",
6838 "Required data <%s->, without format specifiers\n", p);
6844 // we check for params
6847 while (info->next != NULL)
6850 if (strcmp(p, info->name) == 0)
6852 if (ctr > NM_MAX_FIELDS)
6856 "too much data field ... in file <%s> at line %d\n",
6859 fprintf(stderr, "too much data field ...\n");
6872 if (found_data == 0)
6876 "Required data <%s>, not found in info-mon specifications in <%s> at line %d\n",
6880 "Required data <%s>, not found in info-mon specifications\n", p);
6884 p = strtok(NULL, ":\t\n");
6886 } // end while strtok
6888 } // end else '-' (short options)
6897 fprintf(stderr, "no required data! in <%s> at line %d\n", f_name, line);
6899 fprintf(stderr, "no required data!\n");
6906 // 2, parse the arguments and process the command line
6907 // no checks are needed here, because already do in parse_check
6908 // it return a pointer to info needed for make output, or NULL if errors
6909 ///////////////////////////////////////////////////////////////////////////////
6910 OUT_INFO_MON *parse_process(int argc, char *argv[], PARAM_INFO_MON *start)
6921 PARAM_INFO_MON *info; // iterator on this list
6922 OUT_INFO_MON *out_param; // iterator on this list
6924 if ((out_param = malloc(sizeof(OUT_INFO_MON))) == NULL)
6925 { fprintf(stderr, "no mem\n");
6930 fprintf(stderr, "parse_process: argc = %d\n", argc);
6931 for (i = 0; i < argc; i++)
6932 fprintf(stderr, "argv[%d] = <%s>\n",i, argv[i]);
6935 for (i = 0; i < NM_MAX_FIELDS; i++)
6936 out_param->data[i] = NULL;
6938 strcpy(out_param->req_fs, " ");
6940 strcpy(out_param->req_ls, "\n\r");
6942 strcpy(out_param->req_ls, "\n");
6945 out_param->req_n = 0;
6946 out_param->req_header = 1;
6949 req_tm = 200; /* default wait */
6958 { // should be one of the short option
6959 if (strcmp(argv[i], "-fs") == 0)
6960 { // field separator, next arg should be a string
6961 if (((i+1) < argc) && (strlen(argv[i+1]) < 10))
6963 strcpy(out_param->req_fs, argv[i]);
6966 { fprintf(stderr, "NEVER BE:-fs: Invalid field separator\n");
6970 else if (strcmp(argv[i], "-ls") == 0)
6971 { // line separator, next arg should be a string
6972 if (((i+1) < argc) && (strlen(argv[i+1]) < 10))
6974 strcpy(out_param->req_ls, argv[i]);
6977 { fprintf(stderr, "NEVER BE:-ls: Invalid line separator\n");
6981 else if (strcmp(argv[i], "-tm") == 0)
6982 { // time separator, next arg should be a millisecond (200-10000)
6984 { fprintf(stderr, "NEVER BE:-tm, -ts, are mutually exclusive");
6988 if (((i+1) < argc) && (atoi(argv[i+1]) >= 200) && (atoi(argv[i+1]) <= 10000))
6990 req_tm = atoi(argv[i]);
6994 { fprintf(stderr, "NEVER BE:-tm: Invalid argument (200-10000 milliseconds)\n");
6998 else if (strcmp(argv[i], "-ts") == 0)
6999 { // time separator, next arg should be a seconds (1-3600)
7001 { fprintf(stderr, "NEVER BE:-tm, -ts, are mutually exclusive");
7005 if (((i+1) < argc) && (atoi(argv[i+1]) >= 1) && (atoi(argv[i+1]) <= 3600))
7007 req_ts = atoi(argv[i]);
7014 { fprintf(stderr, "NEVER BE:-ts: Invalid argument (1-3600 seconds)\n");
7018 else if (strcmp(argv[i], "-n") == 0)
7019 { // nr of data pump, before stop collection,
7020 // next arg should be a int > 0
7021 if (((i+1) < argc) && (atoi(argv[i+1]) >= 1) && (atoi(argv[i+1]) <= 99999))
7023 out_param->req_n = atoi(argv[i]);
7026 { fprintf(stderr, "NEVER BE:-n: Invalid argument (1-99999 times)\n");
7030 else if (strcmp(argv[i], "-h") == 0)
7031 { // we do NOT want header (default with header)
7032 out_param->req_header = 0;
7034 else if (strcmp(argv[i], "-S") == 0)
7035 { // we have used use specs from a file instead of standard info,
7036 // next arg is an existing readable filename
7037 // as already parsed correctly, we skip here.
7040 else if (strcmp(argv[i], "-I") == 0)
7041 { // we have used input from a file instead of command line
7042 // next arg is an existing readable filename
7043 // as already parsed correctly, we skip here.
7048 fprintf(stderr, "NEVER BE:Unrecognized option %s\n", argv[i]);
7053 { // should be required data
7054 tmp = strdup(argv[i]);
7055 p = strtok(tmp, ":\t\n");
7058 // check if there is an output format specification
7068 // we have 'minus', so, probably forget format ...
7071 "NEVER BE:Required data <%s->, without format specifiers\n", p);
7077 // we check for params
7080 while (info->next != NULL)
7083 if (strcmp(p, info->name) == 0)
7085 if (ctr > NM_MAX_FIELDS)
7087 fprintf(stderr, "NEVER BE:too much data field ...");
7090 out_param->data[ctr] = info;
7091 out_param->out_f[ctr] = *o;
7098 if (found_data == 0)
7101 "NEVER BE:Required data <%s>, not found in info-mon specifications\n", p);
7106 p = strtok(NULL, ":\t\n");
7108 } // end while strtok
7110 // here, we have an array of pointers to required data
7111 // and an array of output specifiers, from 0 to [ctr-1]
7113 } // end else '-' (short options)
7121 fprintf(stderr, "NEVER BE:no required data!\n");
7125 // now, what netmon screen we need to retrieve ?
7126 // we need somewhat were checking is faster, as our goal is lower cicle time
7128 // we can have NM_MAX_SCREEN=254 screens, so we use an array, of unsigned char,
7129 // each char contain number of needed screen, 255 is list terminator
7131 for (i = 0; i <= NM_MAX_SCREEN; i++)
7132 out_param->req_screen[i] = 255;
7136 fprintf(stderr, "Start Required data %s screen %d\n", out_param->data[ctr]->name, out_param->data[ctr]->s_nr);
7138 while (out_param->data[ctr] != NULL)
7141 fprintf(stderr, "Required data %s screen %d\n", out_param->data[ctr]->name, out_param->data[ctr]->s_nr);
7143 // check if screen already in
7146 while (out_param->req_screen[i] != 255)
7148 if (out_param->req_screen[i] == out_param->data[ctr]->s_nr)
7149 { // already load, skip
7156 if (found_data == 0)
7159 fprintf(stderr, "i = %d, out_param->req_screen[%d] = %d\n", i, i, out_param->data[ctr]->s_nr);
7161 out_param->req_screen[i] = out_param->data[ctr]->s_nr;
7170 while (out_param->req_screen[i] != 255)
7172 fprintf(stderr, "Required screen %d\n", out_param->req_screen[i]);
7178 out_param->req_wait = req_tm * 1000;
7180 out_param->req_wait = req_ts * 1000000;
7182 out_param->req_wait = req_tm * 1000;
7188 int nmd_output(OUT_INFO_MON *out_param)
7198 char Screen[NM_MAX_SCREEN_WIDTH];
7200 struct tm *date_time;
7202 if (out_param->req_header)
7204 // print phone help header
7206 while (out_param->data[d] != NULL)
7207 { len = out_param->data[d]->len;
7208 if (strlen(out_param->data[d]->name) > len)
7209 len = strlen(out_param->data[d]->name);
7210 if (strlen(out_param->data[d]->mname) > len)
7211 len = strlen(out_param->data[d]->mname);
7212 printf("%*.*s%s", len, len, out_param->data[d]->name, out_param->req_fs);
7215 printf("%s", out_param->req_ls);
7217 // print netmon manual header
7219 while (out_param->data[d] != NULL)
7220 { len = out_param->data[d]->len;
7221 if (strlen(out_param->data[d]->name) > len)
7222 len = strlen(out_param->data[d]->name);
7223 if (strlen(out_param->data[d]->mname) > len)
7224 len = strlen(out_param->data[d]->mname);
7225 printf("%*.*s%s", len, len, out_param->data[d]->mname, out_param->req_fs);
7228 printf("%s", out_param->req_ls);
7229 printf("%s", out_param->req_ls);
7235 // stop after n data punp
7238 if ((out_param->req_n) && (ctr > out_param->req_n))
7241 // datapump: for each screen, for each required data, load data info->value
7244 while(out_param->req_screen[i] != 255)
7246 if (out_param->req_screen[i] == 0)
7249 date_time = localtime(&sec);
7250 sprintf(Screen, "%02d-%02d-%04d\n%02d:%02d:%02d\n",
7252 date_time->tm_mon+1,
7253 date_time->tm_year+1900,
7258 fprintf(stderr, "%02d-%02d-%04d\n%02d:%02d:%02d\n",
7260 date_time->tm_mon+1,
7261 date_time->tm_year+1900,
7269 GSM->NetMonitor(out_param->req_screen[i], Screen);
7272 // we have one screen of data, load those required
7275 while (out_param->data[d] != NULL)
7277 if (out_param->data[d]->s_nr == out_param->req_screen[i])
7281 nr_line = out_param->data[d]->y;
7282 while ((*p) && (nr_line))
7290 fprintf(stderr, "\nthis line: %s\n\n", p);
7294 nr_chr = out_param->data[d]->x;
7295 while ((*p) && (nr_chr))
7299 // this the start of data
7301 len = out_param->data[d]->len;
7302 while ((*p) && (len))
7303 { out_param->data[d]->value[n] = *p;
7308 // pad with space if shorter than presumed
7309 while ((*p) && (len))
7310 { out_param->data[d]->value[n] = ' ';
7315 out_param->data[d]->value[n] = '\0';
7324 // print row of data
7326 while (out_param->data[d] != NULL)
7328 len = out_param->data[d]->len;
7329 if (out_param->req_header)
7330 { if (strlen(out_param->data[d]->name) > len)
7331 len = strlen(out_param->data[d]->name);
7332 if (strlen(out_param->data[d]->mname) > len)
7333 len = strlen(out_param->data[d]->mname);
7335 // FIXME check format
7336 printf("%*.*s%s", len, len, out_param->data[d]->value, out_param->req_fs);
7339 printf("%s", out_param->req_ls);
7341 usleep(out_param->req_wait);
7345 printf("%s%s", out_param->req_ls, out_param->req_ls);
7351 ///////////////////////////////////////////////////////////////////////////////
7352 int netmonitordata(int argc, char *argv[])
7354 char *loc_info = NULL; // path to --netmonitordata directory
7355 char *f_name; // absolute path of phone info-file
7356 int flag_phone_spec = 0; // flags, set if used -S option
7358 char model[20] = "phonepar"; // TO DO: PHONE AUTODETECTION
7359 // char phver[20] = "";
7361 PARAM_INFO_MON *start; // pointer to list of parsed phone params
7362 OUT_INFO_MON *out_param; // pointer to struct of output data
7364 char *f_commands = NULL; // file containings input line arguments
7365 FILE *commands; // Handle for this file
7366 char buf[1024]; // buffer
7367 char *f_argv[NM_MAX_FIELDS+30]; // space for parameters and cmdline options
7369 char *p, *tmp; // various counter, flags, tmp area ...
7376 signal(SIGINT, interrupted);
7378 // FIXME model, phone_version
7380 // before parsing phone-info-file, we check for user specified phone-info-file
7385 if (strcmp(argv[i], "-S") == 0)
7389 flag_phone_spec = 1;
7390 loc_info = strdup(argv[i+1]);
7394 { fprintf(stderr, "option -S require an argument ...\n");
7402 if (loc_info != NULL)
7403 { f_name = strdup(loc_info);
7405 else // we use standard file specification
7407 if ((tmp = getenv("INFOMONPATH")) == NULL)
7408 { loc_info = strdup(".");
7411 { loc_info = strdup(tmp);
7414 f_name = malloc(strlen(loc_info)+strlen(model)+10);
7415 sprintf(f_name, "%s/%s", loc_info, model);
7420 // fprintf(stderr, "Loc_info <%s> model <%s> version <%s>\n", loc_info, model, phver);
7421 fprintf(stderr, "Info file: <%s>\n", f_name);
7423 if ((start = get_mon_param_info(f_name, NULL)) == NULL)
7426 // option -I give us the possibility of specify a filename,
7427 // containing a "sequence" of command line args.
7428 // if you specify this option, you can use (on command line) only -S option.
7429 // other options may be specified inside the input-file.
7430 // contents of this file as the same sintax as the command line,
7431 // except it must not contain "--netmonitordata" or "-I" or "-S" options
7432 ///////////////////////////////////////////////////////////////////////
7437 if (strcmp(argv[i], "-I") == 0)
7441 if ((argc == 2) || ((argc == 4) && flag_phone_spec == 1))
7442 { f_commands = strdup(argv[i+1]);
7445 { fprintf(stderr, "option -I accept only additional -S option.\n");
7452 { fprintf(stderr, "option -I require an argument ...\n");
7460 // before all, we check all command line
7462 if (f_commands != NULL)
7465 fprintf(stderr, "netmonitordata(check): commands from <%s>\n", f_commands);
7469 // read line, make array f_argv, and counter f_argc
7470 // parse & check args, so errors are checked before real processing
7471 // (-I option here is ignored)
7472 // (-S option can be here, and it is used)
7475 if ((commands = fopen(f_commands, "r")) == NULL)
7476 { fprintf(stderr, "Can' t open file commands input :<%s>n", f_commands);
7480 // FIXME line may be be splitted
7482 while (fgets(buf, 1024, commands) != NULL)
7487 // Truncate from '#' at right of comments
7488 if ((tmp = strchr(p, '#')) != NULL)
7491 // Strip leading, trailing whitespace
7492 while(isspace((int) *p))
7495 while((strlen(p) > 0) && isspace((int) p[strlen(p) - 1]))
7496 p[strlen(p) - 1] = '\0';
7498 // Ignore blank lines
7499 if ((*p == '\n') || (*p == '\0'))
7503 fprintf(stderr, "netmonitordata(check): row <%s>\n", p);
7508 p = strtok(p, " \t");
7510 { f_argv[f_argc++] = strdup(p);
7512 fprintf(stderr, "netmonitordata(check): token <%s>\n", p);
7514 p = strtok(NULL, " \t"); // OK p, (NULL)
7516 while ((p != NULL) && (*p));
7518 // here we have f_argc, f_argv, this line is OK
7520 if (parse_check(f_argc, f_argv, start, f_commands, line) != 0)
7521 { free_nm_info(start);
7528 else // as above, but we have only command line, argv, argc.
7530 if (parse_check(argc, argv, start, NULL, 0) != 0)
7531 { free_nm_info(start);
7536 // here, all commands line are checked, and are correct
7538 if (f_commands != NULL)
7541 fprintf(stderr, "netmonitordata(process): commands from <%s>\n", f_commands);
7546 // read line, make array f_argv, and counter f_argc
7547 // parse_process argument, (-I option here is ignored)
7548 // (-S option can be here, and it is used)
7549 // (make header // these are in nmd_output();
7556 if ((commands = fopen(f_commands, "r")) == NULL)
7557 { fprintf(stderr, "Can' t open file commands input :<%s>n", f_commands);
7561 // FIXME line may be be splitted
7562 while (fgets(buf, 1024, commands) != NULL)
7566 // Truncate from '#' at right of comments
7567 if ((tmp = strchr(p, '#')) != NULL)
7570 // Strip leading, trailing whitespace
7571 while(isspace((int) *p))
7574 while((strlen(p) > 0) && isspace((int) p[strlen(p) - 1]))
7575 p[strlen(p) - 1] = '\0';
7577 // Ignore blank lines
7578 if ((*p == '\n') || (*p == '\0'))
7584 p = strtok(p, " \t");
7586 { f_argv[f_argc++] = strdup(p);
7587 p = strtok(NULL, " \t"); // OK p, (NULL)
7589 while ((p != NULL) && (*p));
7591 // here we have f_argc, f_argv, this line is OK
7593 if ((out_param = parse_process(f_argc, f_argv, start)) == NULL)
7594 { free_nm_info(start);
7595 return(-1); /* NEVER BE */
7598 // here, command line has no error ...
7600 nmd_output(out_param);
7607 else // as above, but we have only command line, argv, argc.
7609 if ((out_param = parse_process(argc, argv, start)) == NULL)
7610 { free_nm_info(start);
7611 return(-1); /* NEVER BE */
7613 nmd_output(out_param);
7622 /* I analised this source and this should be done. But when compile with VC6 */
7623 /* I have error. So, commented... MW */
7625 free_nm_info(start);
7632 // used by nm_collect()
7633 ///////////////////////////////////////////////////////////////////////////////
7634 char *rowScreen(char *s)
7638 // make Screen in one row
7650 void printtime(void)
7654 int Year; /* The complete year specification - e.g. 1999. Y2K :-) */
7655 int Month; /* January = 1 */
7660 int Timezone; /* The difference between local time and GMT */
7666 now=localtime(&nowh);
7668 Date.Year = now->tm_year;
7669 Date.Month = now->tm_mon+1;
7670 Date.Day = now->tm_mday;
7671 Date.Hour = now->tm_hour;
7672 Date.Minute = now->tm_min;
7673 Date.Second = now->tm_sec;
7675 /* I have 100 (for 2000) Year now :-) */
7676 if (Date.Year>99 && Date.Year<1900) {
7677 Date.Year=Date.Year+1900;
7680 printf("%d:%d:%d:%d:%d:%d ",Date.Day,Date.Month,Date.Year,Date.Hour,Date.Minute,Date.Second);
7684 // like netmonitor(), but print in one row, 1, 2 or 3 screen, every ~0.3 s
7685 ///////////////////////////////////////////////////////////////////////////////
7686 int nm_collect(int argc, char *argv[])
7688 int mode[MAX_NM_COLLECT];
7689 char Screen[NM_MAX_SCREEN_WIDTH];
7692 for (i=0;i<argc;i++) {
7693 argc > i ? (mode[i] = atoi(argv[i])): (mode[i] = 0);
7696 for (i=0;i<argc;i++) {
7697 if (mode[i]==0 && strcmp(argv[i],"-d")) {
7698 fprintf(stderr, "Wrong %i parameter (not number and not -d)\n",i);
7703 signal(SIGINT, interrupted);
7710 for (i=0;i<argc;i++) {
7711 if (!strcmp(argv[i],"-d")) {
7717 for (i=0;i<argc;i++) {
7720 GSM->NetMonitor(mode[i], Screen);
7721 printf("%s::", rowScreen(Screen));
7736 int sniff(int argc, char *argv[])
7738 /* base model comes from gnokiirc */
7739 strcat(model,"sniff");
7741 if (argc>0) strcpy(Port,argv[0]);
7743 /* Initialise the GSM interface. */
7746 /* Loop here indefinitely - allows you to see messages from GSM code in
7747 response to unknown messages etc. The loops ends after pressing the
7749 while (!bshutdown) {
7759 int decodefile(int argc, char *argv[])
7762 unsigned char in_buffer[255];
7766 /* base model comes from gnokiirc */
7767 strcat(model,"decode");
7769 /* Initialise the GSM interface. */
7772 printf ("open InPutFile: %s\n", argv[0]);
7773 if ( (infile = fopen( argv[0], "rb")) == NULL ) {
7774 printf ("Failed to open InPutFile: %s\n", argv[0]);
7777 while ( (nr_read = fread(in_buffer, 1, 16, infile)) > 0 ) {
7778 for (i=0; i < nr_read; i++)
7779 Protocol->StateMachine(in_buffer[i]);
7787 int getringtone(int argc, char *argv[])
7789 GSM_BinRingtone ringtone;
7791 GSM_Ringtone SMringtone;
7793 ringtone.location=1;
7794 if (argc>1) ringtone.location=atoi(argv[1]);
7796 /* Initialise the GSM interface. */
7799 error=GSM_GetPhoneRingtone(&ringtone,&SMringtone);
7801 fprintf(stdout, _("Downloaded ringtone, location %i: "),ringtone.location);
7805 fprintf(stdout, _("get succeeded!\n"));
7806 /* In 33.. we have normal "Smart Messaging" format */
7807 if (GetModelFeature (FN_RINGTONES)==F_RING_SM) {
7808 fprintf(stdout, _("Name: %s (normal format)\n"),SMringtone.name);
7809 GSM_SaveRingtoneFileOnConsole(argv[0], &SMringtone);
7811 fprintf(stdout, _("Name: %s (binary format)\n"),ringtone.name);
7812 GSM_SaveBinRingtoneFile(argv[0], &ringtone);
7817 case GE_INVALIDRINGLOCATION:
7818 fprintf(stdout, _("invalid location %i!\n"),ringtone.location);
7820 case GE_UNKNOWNMODEL:
7821 fprintf(stdout, _("mygnokii doesn't know format for this model!\n"));
7823 case GE_NOTIMPLEMENTED:
7824 fprintf(stdout, _("not implemented for this model!\n"));
7827 fprintf(stdout, _("not supported by this model!\n"));
7836 int binringtoneconvert(int argc, char *argv[])
7838 GSM_BinRingtone ringtone;
7847 //{ "c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "h" };
7848 int binary_notes[12] =
7849 { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11 , 12};
7851 if (GSM_ReadBinRingtoneFile(argv[0],&ringtone)!=GE_NONE) {
7852 fprintf(stdout,_("Failed to read %s file!\n"),argv[0]);
7856 file = fopen(argv[1], "wb");
7859 return(GE_CANTOPENFILE);
7863 if (ringtone.frame[i]==0) break;
7864 fprintf(file,_("%c"),ringtone.frame[i]);
7868 fprintf(file,_(":d=32,o=5,b=300:"));
7872 if (ringtone.frame[i]!=j) {
7879 if (!isok && j>=114 && j<=125) {
7880 j=14*3+binary_notes[j-114];
7883 if (!isok && j>=126 && j<=137) {
7884 j=14*1+binary_notes[j-126];
7887 if (!isok && j>=138 && j<=149) {
7888 j=14*2+binary_notes[j-138];
7891 if (!isok && j>=150 && j<=161) {
7892 j=14*4+binary_notes[j-150];
7897 fprintf(stdout,_("Unknown block in binary ringtone %i %i\n"),j,z);
7903 if (w>z && (w/2)<=z) {
7905 case 1:fprintf(file,_("16"));break;
7906 case 2:fprintf(file,_("8"));break;
7907 case 3:fprintf(file,_("4"));break;
7908 case 4:fprintf(file,_("2"));break;
7909 case 5:fprintf(file,_("1"));break;
7914 if (z>w) fprintf(file,_("1"));
7916 switch (GSM_GetNote(j)) {
7917 case Note_C :fprintf(file,_("c"));break;
7918 case Note_Cis:fprintf(file,_("c#"));break;
7919 case Note_D :fprintf(file,_("d"));break;
7920 case Note_Dis:fprintf(file,_("d#"));break;
7921 case Note_E :fprintf(file,_("e"));break;
7922 case Note_F :fprintf(file,_("f"));break;
7923 case Note_Fis:fprintf(file,_("f#"));break;
7924 case Note_G :fprintf(file,_("g"));break;
7925 case Note_Gis:fprintf(file,_("g#"));break;
7926 case Note_A :fprintf(file,_("a"));break;
7927 case Note_Ais:fprintf(file,_("a#"));break;
7928 case Note_H :fprintf(file,_("h"));break;
7929 default :pause=true;fprintf(file,_("p"));break; //Pause ?
7934 if (w>z && (w/2)<=z) {
7935 fprintf(file,_("."));
7939 if ((j/14)!=1 && !pause) fprintf(file,_("%i"),j/14);
7940 fprintf(file,_(","));
7943 j=ringtone.frame[i];
7944 z=ringtone.frame[i+1];
7946 z=z+ringtone.frame[i+1];
7949 if (i>=ringtone.length) break;
7958 int renamesmsc(int argc, char *argv[])
7960 GSM_MessageCenter MessageCenter;
7962 MessageCenter.No=atoi(argv[0]);
7964 /* Initialise the GSM interface. */
7967 if (GSM->GetSMSCenter(&MessageCenter) == GE_NONE) {
7968 fprintf(stdout,_("SMSC number %i get OK\n"),MessageCenter.No);
7971 fprintf(stdout,_("Error getting SMSC number %i\n"),MessageCenter.No);
7975 strncpy(MessageCenter.Name,argv[1],10);
7977 if (GSM->SetSMSCenter(&MessageCenter) == GE_NONE) {
7978 fprintf(stdout,_("SMSC number %i set OK (renamed to \"%s\")\n"),MessageCenter.No,MessageCenter.Name);
7981 fprintf(stdout,_("Error setting SMSC number %i\n"),MessageCenter.No);
7990 #endif /* UCLINUX */
7993 * Returns number of sostituited characters.
7994 * ... may be useful one day ??
7996 static int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction )
7997 /* direction = 0 : after reading phone memory (
7998 * 1 : writing phone memory
8002 register int count=0;
8003 char charfrom, charto;
8005 charfrom= (direction==0) ? ';' : '|';
8006 charto = (direction==0) ? '|' : ';';
8008 count+=str_substch(pentry->Name, charfrom, charto );
8009 count+=str_substch(pentry->Number, charfrom, charto );
8011 for( i = 0; i < pentry->SubEntriesCount; i++ )
8013 if( pentry->SubEntries[i].EntryType != GSM_Date )
8014 count+=str_substch(pentry->SubEntries[i].data.Number ,charfrom,charto);
8020 int str_substch( char *str, const char toric, const char sost )
8025 for( ct = 0; ct < strlen(str); ct++ )
8026 if( str[ct] == (unsigned char) toric )
8027 { str[ct] = sost; i_sost++; }
8034 extern GSM_Error N6110_EnableExtendedCommands (unsigned char status);
8036 /* Allows to set simlock state.
8037 With older phone (older 51xx, 61xx) can open them, with older
8038 and newer should be able to close them */
8039 /* DO NOT TRY, IF DON'T WANT, WHAT YOU DO !!!!!!!!!! */
8042 GSM_AllSimlocks siml;
8044 unsigned char closebuffer[20]=
8045 { 0x00, 0x01, 0x82, 0x01,
8046 0x00, /* which simlock */
8048 0x00, 0x00, 0x00, /* lock 1 info */
8049 0x00, 0x00, 0x00, 0x00, 0x00, /* lock 4 info */
8050 0x00, 0x00, /* lock 2 info */
8051 0x00, 0x00, /* lock 3 info */
8053 unsigned char openbuffer[10]= { 0x00, 0x01, 0x81, 0x01,
8054 0x00, /* lock number */
8055 0x10, 0x10, 0x10, 0x10, 0x10 };
8056 unsigned char openbuffer0[10]= {0x00, 0x01, 0x02, 0x03, 0x1f, 0x11, 0x01, 0x01, 0x10, 0x00 };
8058 unsigned char info[120];
8061 /* Initialise the code for the GSM interface. */
8063 if (strstr(GSM_Info->FBUSModels, "3310") == NULL)
8065 fprintf(stderr,("Not supported\n"));
8069 N6110_EnableExtendedCommands(0x02);
8071 if (GSM->SimlockInfo(&siml)!=GE_NONE) {
8072 fprintf(stderr,_("Error getting simlock info\n"));GSM->Terminate();return -1;
8074 /* Opening all locks (we must check, if we can open them) */
8075 NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer0);
8076 openbuffer[4]=1;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8077 openbuffer[4]=2;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8078 openbuffer[4]=4;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8079 openbuffer[4]=8;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8080 if (GSM->SimlockInfo(&siml)!=GE_NONE) {
8081 fprintf(stderr,_("Error getting simlock info\n"));GSM->Terminate();return -1;
8084 if (siml.simlocks[i].enabled) {
8085 fprintf(stderr,_("Can not open simlock %i\n"),i+1);GSM->Terminate();return -1;
8088 /* Making frame for closing simlocks */
8089 strcpy(info,"00101");
8091 while (j!=strlen(info)) {
8092 if (j+2<=strlen(info)) {
8093 closebuffer[i]=((info[j] & 0x0f)<<4) | (info[j+1] & 0x0f);j=j+2;
8095 closebuffer[i]=(info[j] & 0x0f) << 4;j++;
8098 strcpy(info,"0000");j=0;i=15;
8099 while (j!=strlen(info)) {
8100 if (j+2<=strlen(info)) {
8101 closebuffer[i]=((info[j] & 0x0f)<<4) | (info[j+1] & 0x0f);j=j+2;
8103 closebuffer[i]=(info[j] & 0x0f) << 4;j++;
8106 strcpy(info,"0000");j=0;i=17;
8107 while (j!=strlen(info)) {
8108 if (j+2<=strlen(info)) {
8109 closebuffer[i]=((info[j] & 0x0f)<<4) | (info[j+1] & 0x0f);j=j+2;
8111 closebuffer[i]=(info[j] & 0x0f) << 4;j++;
8114 strcpy(info,"0000000001");j=0;i=9;
8115 while (j!=strlen(info)) {
8116 if (j+2<=strlen(info)) {
8118 closebuffer[i]=closebuffer[i] | (info[j] & 0x0f);j++;
8120 closebuffer[i]=((info[j] & 0x0f)<<4) | (info[j+1] & 0x0f);j=j+2;
8123 closebuffer[i]=(info[j] & 0x0f) << 4;j++;
8126 /* Closing simlock with given values */
8127 closebuffer[4]=1+2+4+8;
8128 NULL_SendMessageSequence(50, &CurrentMagicError, 20, 0x40,closebuffer);
8129 /* Opening all locks */
8130 NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer0);
8131 openbuffer[4]=1;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8132 openbuffer[4]=2;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8133 openbuffer[4]=4;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8134 openbuffer[4]=8;NULL_SendMessageSequence(50, &CurrentMagicError, 10, 0x40,openbuffer);
8142 GSM_AllSimlocks siml;
8145 /* Initialise the code for the GSM interface. */
8148 if (GSM->SimlockInfo(&siml)!=GE_NONE) fprintf(stderr,_("Error\n"));
8150 fprintf(stdout,_("MCC + MNC : %s ("),siml.simlocks[0].data);
8151 if (siml.simlocks[0].enabled) fprintf(stdout,_("CLOSED"));
8152 else fprintf(stdout,_("opened"));
8153 if (siml.simlocks[0].factory) fprintf(stdout,_(") (factory"));
8154 else fprintf(stdout,_(") (user"));
8155 fprintf(stdout,_(") (counter %i"),siml.simlocks[0].counter);
8157 s[0]=siml.simlocks[0].data[0];
8158 s[1]=siml.simlocks[0].data[1];
8159 s[2]=siml.simlocks[0].data[2];
8161 s[4]=siml.simlocks[0].data[3];
8162 s[5]=siml.simlocks[0].data[4];
8165 if (strcmp(GSM_GetNetworkName(s),"unknown"))
8166 fprintf(stdout,_(") (network \"%s\""),GSM_GetNetworkName(s));
8168 fprintf(stdout,_(")\n"));
8170 fprintf(stdout,_("GID1 : %s ("),siml.simlocks[1].data);
8171 if (siml.simlocks[1].enabled) fprintf(stdout,_("CLOSED"));
8172 else fprintf(stdout,_("opened"));
8173 if (siml.simlocks[1].factory) fprintf(stdout,_(") (factory"));
8174 else fprintf(stdout,_(") (user"));
8175 fprintf(stdout,_(") (counter %i"),siml.simlocks[1].counter);
8176 fprintf(stdout,_(")\n"));
8178 fprintf(stdout,_("GID2 : %s ("),siml.simlocks[2].data);
8179 if (siml.simlocks[2].enabled) fprintf(stdout,_("CLOSED"));
8180 else fprintf(stdout,_("opened"));
8181 if (siml.simlocks[2].factory) fprintf(stdout,_(") (factory"));
8182 else fprintf(stdout,_(") (user"));
8183 fprintf(stdout,_(") (counter %i"),siml.simlocks[2].counter);
8184 fprintf(stdout,_(")\n"));
8186 fprintf(stdout,_("MSIN : %s ("),siml.simlocks[3].data);
8187 if (siml.simlocks[3].enabled) fprintf(stdout,_("CLOSED"));
8188 else fprintf(stdout,_("opened"));
8189 if (siml.simlocks[3].factory) fprintf(stdout,_(") (factory"));
8190 else fprintf(stdout,_(") (user"));
8191 fprintf(stdout,_(") (counter %i"),siml.simlocks[3].counter);
8192 fprintf(stdout,_(")\n"));
8199 /* Getting EEPROM from older phones */
8200 /* Tested with N5110 5.07, 6150 5.22 */
8205 unsigned char buffer[1000]={ 0x00, 0x01, 0xd4, 0x02, 0x00, 0xa0,
8206 0x00, 0x00, /* location Lo and Hi */
8207 0x10 }; /* how many bytes */
8209 strcpy(Connection,"mbus");
8210 fprintf(stderr,_("Switching connection type to MBUS\n"));
8212 strcpy(model,"5110");
8214 /* Initialise the code for the GSM interface. */
8217 if (strstr(GSM_Info->FBUSModels, "3310") == NULL)
8219 fprintf(stderr,("Not supported\n"));
8224 for (i=0;i<64;i++) {
8225 fprintf(stdout,_("%c"),0xff);
8232 if ((i/256)!=((i-1)/256)) fprintf(stderr,_("."));
8234 if (NULL_SendMessageSequence(50, &CurrentMagicError, 9, 0x40,buffer)!=GE_NONE) break;
8239 fprintf(stderr,_("\n"));
8248 GSM_SMSFolders folders;
8253 /* Initialise the code for the GSM interface. */
8258 error=GSM->GetSMSFolders(&folders);
8262 if (error!=GE_NONE && !folders.number) {
8263 fprintf(stdout,_("Error!\n"));
8267 for (i=0;i<folders.number;i++) {
8268 fprintf(stdout,_("%i. %s\n"),i+1,folders.Folder[i].Name);
8274 int resetphonesettings()
8276 /* Initialise the code for the GSM interface. */
8279 GSM->ResetPhoneSettings();
8288 /* Checked on 3310 4.02 and doesn't work.
8289 Possible reasons: SMSC has problems (possible), bug in phone firmware
8290 (very possible) or here in code.
8291 I quess, that the second is the most possible - 3310 treat only 3 SMS
8292 as linked (the most often profile needs 4 - 2 and few bytes in 3'th
8293 for screen saver, few bytes for profile name and 1 or 2 sms for ringtone).
8294 When send separate ringtone (see --sendringtone with --profilestyle)
8295 and screen saver (--sendlogo screensaver...), it's received OK.
8296 It's for checking in higher firmware. */
8297 int sendprofile(int argc, char *argv[])
8299 GSM_Ringtone ringtone;
8301 GSM_MultiSMSMessage MultiSMS;
8305 u8 MessageBuffer[140*4];
8306 u16 MessageLength=0;
8308 char profilename[10+1];
8310 if (GSM_ReadRingtoneFileOnConsole(argv[2], &ringtone)!=GE_NONE) return(-1);
8312 ringtone.allnotesscale=false;
8313 for (i=0;i<argc;i++)
8314 if (!strcmp(argv[i],"--scale")) ringtone.allnotesscale=true;
8316 /* The fourth argument is the bitmap file. */
8317 if (GSM_ReadBitmapFileOnConsole(argv[3], &bitmap)!=GE_NONE) return -1;
8319 GSM_ResizeBitmap(&bitmap,GSM_PictureImage);
8321 strncpy(profilename,argv[1],10);
8323 MessageBuffer[MessageLength++]=0x30; //SM version. Here 3.0
8325 MessageBuffer[MessageLength++]=SM30_PROFILENAME; //ID for profile name
8326 MessageBuffer[MessageLength++]=0x00; //length hi
8327 MessageBuffer[MessageLength++]=strlen(profilename);//length lo
8329 EncodeUnicode (MessageBuffer+MessageLength,profilename ,strlen(profilename));
8330 MessageLength=MessageLength+2*strlen(profilename);
8332 MessageBuffer[MessageLength++]=SM30_RINGTONE; //ID for ringtone
8334 MessageBuffer[MessageLength++]=0x01; //length hi
8335 MessageBuffer[MessageLength++]=0x00; //length lo
8337 j=SM30_MAX_RINGTONE_FRAME_LENGTH;
8338 current=GSM_PackRingtone(&ringtone, MessageBuffer+MessageLength, &j);
8339 MessageLength=MessageLength+j;
8341 if (current!=ringtone.NrNotes) {
8342 if (current>FB61_MAX_RINGTONE_NOTES) {
8343 fprintf(stderr,_("Warning: due to phone limitation"));
8345 fprintf(stderr,_("Warning: ringtone was too long to be saved into SMS,"));
8347 fprintf(stderr, _(" only %i first notes were packed (%i cut)\n"),current,ringtone.NrNotes-current);
8350 MessageBuffer[i]=(j)/256;
8351 MessageBuffer[i+1]=(j)%256;
8353 MessageBuffer[MessageLength++]=SM30_SCREENSAVER; //ID for OTA screen saver
8354 MessageBuffer[MessageLength++]=0x01; //length hi
8355 MessageBuffer[MessageLength++]=0x00; //length lo
8356 MessageBuffer[MessageLength++]=0x00;
8357 MessageBuffer[MessageLength++]=bitmap.width;
8358 MessageBuffer[MessageLength++]=bitmap.height;
8359 MessageBuffer[MessageLength++]=0x01;
8361 memcpy(MessageBuffer+MessageLength,bitmap.bitmap,bitmap.size);
8362 MessageLength=MessageLength+bitmap.size;
8364 GSM_MakeMultiPartSMS2(&MultiSMS,MessageBuffer,MessageLength, GSM_ProfileUDH, GSM_Coding_Default);
8368 /* Initialise the GSM interface. */
8371 for (i=0;i<MultiSMS.number;i++)
8372 strcpy(MultiSMS.SMS[i].Destination,argv[0]);
8374 return GSM_SaveMultiPartSMSOnConsole(&MultiSMS, optind,argc,argv,false,false,false,false);
8377 int showbitmap(int argc, char *argv[])
8381 if (GSM_ReadBitmapFileOnConsole(argv[0], &bitmap)!=GE_NONE) return(-1);
8383 GSM_PrintBitmap(&bitmap);
8388 int getwapsettings(int argc, char *argv[])
8390 GSM_WAPSettings settings;
8393 settings.location=atoi(argv[0]);
8395 /* Initialise the GSM interface. */
8398 error=GSM->GetWAPSettings(&settings);
8402 fprintf(stdout,_("%s."),argv[0]);
8403 if (!(strcmp(settings.title,""))) fprintf(stdout,_("Set %s\n"),argv[0]);
8404 else fprintf(stdout,_("%s\n"),settings.title);
8405 fprintf(stdout,_("Homepage: %s\n"),settings.homepage);
8406 if (settings.iscontinuous) fprintf(stdout,_("Connection type: continuous\n"));
8407 else fprintf(stdout,_("Connection type: temporary\n"));
8408 if (settings.issecurity) fprintf(stdout,_("Connection security: on\n"));
8409 else fprintf(stdout,_("Connection security: off\n"));
8410 switch (settings.bearer) {
8411 case WAPSETTINGS_BEARER_SMS:
8412 fprintf(stdout,_("Bearer: SMS\n"));
8413 fprintf(stdout,_("Server number: %s\n"),settings.server);
8414 fprintf(stdout,_("Service number: %s\n"),settings.service);
8416 case WAPSETTINGS_BEARER_DATA:
8417 fprintf(stdout,_("Bearer: Data (CSD)\n"));
8418 fprintf(stdout,_("Dial-up number: %s\n"),settings.dialup);
8419 fprintf(stdout,_("IP address: %s\n"),settings.ipaddress);
8420 if (settings.isnormalauthentication) fprintf(stdout,_("Authentication type: normal\n"));
8421 else fprintf(stdout,_("Authentication type: secure\n"));
8422 if (settings.isISDNcall) fprintf(stdout,_("Data call type: ISDN\n"));
8423 else fprintf(stdout,_("Data call type: analogue\n"));
8424 if (settings.isspeed14400) fprintf(stdout,_("Data call speed: 14400\n"));
8425 else fprintf(stdout,_("Data call speed: 9600\n"));
8426 fprintf(stdout,_("User name: %s\n"),settings.user);
8427 fprintf(stdout,_("Password: %s\n"),settings.password);
8429 case WAPSETTINGS_BEARER_USSD:
8430 fprintf(stdout,_("Bearer: USSD\n"));
8431 fprintf(stdout,_("Service code: %s\n"),settings.code);
8432 if (settings.isIP) fprintf(stdout,_("Address type: IP address\nIPaddress: %s\n"),settings.service);
8433 else fprintf(stdout,_("Address type: service number\nService number: %s\n"),settings.service);
8438 fprintf(stderr,_("%s\n"),print_error(error));
8447 /* Not full done now */
8448 int savewapsettings(int argc, char *argv[])
8450 GSM_WAPSettings settings;
8451 GSM_MultiSMSMessage MultiSMS;
8455 settings.location=atoi(argv[0]);
8457 /* Initialise the GSM interface. */
8460 error=GSM->GetWAPSettings(&settings);
8461 // strcpy(settings.homepage,"http://OtherSites/");
8462 // strcpy(settings.title,"Orange");
8468 /* Put settings into SMS structure */
8469 GSM_SaveWAPSettingsToSMS(&MultiSMS,&settings);
8471 for (w=0;w<MultiSMS.number;w++)
8472 strcpy(MultiSMS.SMS[w].Destination,"WAPSettings");
8474 GSM_SaveMultiPartSMSOnConsole(&MultiSMS,1,argc,argv,false,false,false,false);
8479 fprintf(stderr,_("%s\n"),print_error(error));
8487 int sendwapsettings(int argc, char *argv[])
8489 GSM_WAPSettings settings;
8490 GSM_MultiSMSMessage MultiSMS;
8494 settings.location=atoi(argv[0]);
8496 /* Initialise the GSM interface. */
8499 error=GSM->GetWAPSettings(&settings);
8500 // strcpy(settings.homepage,"http://OtherSites/");
8501 // strcpy(settings.title,"Orange");
8507 /* Put settings into SMS structure */
8508 GSM_SaveWAPSettingsToSMS(&MultiSMS,&settings);
8510 for (w=0;w<MultiSMS.number;w++)
8511 strcpy(MultiSMS.SMS[w].Destination,argv[1]);
8513 GSM_SendMultiPartSMSOnConsole(&MultiSMS, 2,argc,argv,false,false,false);
8519 fprintf(stderr,_("%s\n"),print_error(error));
8527 int getwapbookmark(int argc, char *argv[])
8529 GSM_WAPBookmark bookmark;
8532 bookmark.location=atoi(argv[0]);
8534 /* Initialise the GSM interface. */
8537 error=GSM->GetWAPBookmark(&bookmark);
8541 if (bookmark.address[0]==0) {
8542 fprintf(stdout,_("Empty bookmark location\n"));
8544 fprintf(stdout,_("Address: \"%s\"\n"),bookmark.address);
8545 if (bookmark.title[0]==0)
8546 fprintf(stdout,_("Title: \"%s\"\n"),bookmark.address);
8548 fprintf(stdout,_("Title: \"%s\"\n"),bookmark.title);
8552 fprintf(stderr,_("%s\n"),print_error(error));
8561 int setwapbookmark(int argc, char *argv[])
8563 GSM_WAPBookmark bookmark;
8566 if (argc == 3) /* if location given, use it */
8567 bookmark.location=atoi(argv[2]);
8568 else /* else use first empty location */
8569 bookmark.location=0xffff;
8571 strcpy(bookmark.title, argv[0]);
8572 strcpy(bookmark.address, argv[1]);
8574 /* Initialise the GSM interface. */
8577 error=GSM->SetWAPBookmark(&bookmark);
8581 fprintf(stdout,_("No errors\n"));
8584 fprintf(stderr,_("%s\n"),print_error(error));
8593 int savewapbookmark(int argc, char *argv[])
8595 GSM_WAPBookmark bookmark;
8596 GSM_MultiSMSMessage MultiSMS;
8600 bookmark.location=atoi(argv[0]);
8602 /* Initialise the GSM interface. */
8605 error=GSM->GetWAPBookmark(&bookmark);
8607 // strcpy(bookmark.title,"tytulagagagagagagagagagagagagagagagagagagagagagend");
8608 // strcpy(bookmark.address,"http://jajajajajajajajajajajajagagagagagagagagagagagagagagagagagagagagagpapapapapapapapapapapapapapapapapapapapapapapapapapapapapapapapap¥papapapapapapapapagagagagagagagagagagagagagagagagagagagagagagagagagadadadadadadadajdjdjdjdjdjdjdjdjdjdjdjdjdjdjdjdstp");
8614 if (bookmark.address[0]==0) {
8615 fprintf(stdout,_("Empty bookmark location\n"));
8620 /* Put bookmark into SMS structure */
8621 GSM_SaveWAPBookmarkToSMS(&MultiSMS,&bookmark);
8623 for (w=0;w<MultiSMS.number;w++)
8624 strcpy(MultiSMS.SMS[w].Destination,"WAPBookmark");
8626 GSM_SaveMultiPartSMSOnConsole(&MultiSMS, 1,argc,argv,false,false,false,false);
8631 fprintf(stderr,_("%s\n"),print_error(error));
8640 int sendwapbookmark(int argc, char *argv[])
8642 GSM_WAPBookmark bookmark;
8643 GSM_MultiSMSMessage MultiSMS;
8647 bookmark.location=atoi(argv[0]);
8649 /* Initialise the GSM interface. */
8652 error=GSM->GetWAPBookmark(&bookmark);
8657 if (bookmark.address[0]==0) {
8658 fprintf(stdout,_("Empty bookmark location\n"));
8663 /* Put bookmark into SMS structure */
8664 GSM_SaveWAPBookmarkToSMS(&MultiSMS,&bookmark);
8666 for (w=0;w<MultiSMS.number;w++)
8667 strcpy(MultiSMS.SMS[w].Destination,argv[1]);
8669 GSM_SendMultiPartSMSOnConsole(&MultiSMS, 2,argc,argv,false,false,false);
8674 fprintf(stderr,_("%s\n"),print_error(error));
8683 int savecalendarnote(int argc, char *argv[])
8685 GSM_MultiSMSMessage MultiSMS;
8687 GSM_CalendarNote CalendarNote;
8690 number=atoi(argv[1]);
8693 fprintf(stdout, _("Number of calendar note must be 1 or higher\n"));
8697 switch ( GSM_ReadVCalendarFile(argv[0], &CalendarNote, &number) ) {
8700 case GE_CANTOPENFILE:
8701 fprintf(stdout, _("Failed to open vCalendar file \"%s\"\n"),argv[0]);
8704 fprintf(stdout, _("Number of given calendar note is too high (max=%i)\n"),number);
8707 fprintf(stdout, _("Failed to parse vCalendar file \"%s\"\n"),argv[0]);
8713 /* Put note into SMS structure */
8714 GSM_SaveCalendarNoteToSMS(&MultiSMS,&CalendarNote);
8716 for (w=0;w<MultiSMS.number;w++)
8717 strcpy(MultiSMS.SMS[w].Destination,"Calendar");
8719 GSM_SaveMultiPartSMSOnConsole(&MultiSMS, 2,argc,argv,false,false,false,false);
8724 int sendcalendarnote(int argc, char *argv[])
8726 GSM_MultiSMSMessage MultiSMS;
8728 GSM_CalendarNote CalendarNote;
8731 number=atoi(argv[2]);
8734 fprintf(stdout, _("Number of calendar note must be 1 or higher\n"));
8738 switch ( GSM_ReadVCalendarFile(argv[1], &CalendarNote, &number) ) {
8741 case GE_CANTOPENFILE:
8742 fprintf(stdout, _("Failed to open vCalendar file \"%s\"\n"),argv[1]);
8745 fprintf(stdout, _("Number of given calendar note is too high (max=%i)\n"),number);
8748 fprintf(stdout, _("Failed to parse vCalendar file \"%s\"\n"),argv[1]);
8754 /* Put note into SMS structure */
8755 GSM_SaveCalendarNoteToSMS(&MultiSMS,&CalendarNote);
8757 for (w=0;w<MultiSMS.number;w++)
8758 strcpy(MultiSMS.SMS[w].Destination,argv[0]);
8760 GSM_SendMultiPartSMSOnConsole(&MultiSMS, 3,argc,argv,false,false,false);
8765 /* Example function for continuous receiving SMS */
8766 /* When phone receives SMS, it's read by mygnokii, ID number is created
8767 and SMS is saved to file. After it it's deleted
8768 Checking many errors is also done */
8769 int receivesms(int argc, char *argv[])
8773 GSM_SMSStatus SMSStatus = {0, 0};
8775 int read, location, number;
8776 unsigned char name[50],filename[400];
8777 char nowdate[12]="", nowtime[12]="";
8780 struct CFG_Header *cfg_info;
8782 /* We do not want to monitor serial line forever - press Ctrl+C to stop the
8785 signal(SIGINT, interrupted);
8787 fprintf (stderr, _("Entering monitor mode (press CTRL+C to break)...\n"));
8789 cfg_info=CFG_FindGnokiirc();
8792 if (cfg_info!=NULL) {
8793 if (CFG_Get(cfg_info, "receivesms", "path")) {
8794 strcpy(Dir,CFG_Get(cfg_info, "receivesms", "path"));
8798 fprintf(stderr,_("Path for sms files is \"%s\"\n"),Dir);
8800 fprintf (stderr, _("Initialising GSM interface..."));
8802 /* Initialise the code for the GSM interface. */
8805 fprintf (stderr, _("done\n"));
8809 /* Loop here indefinitely - allows you to see messages from GSM code in
8810 response to unknown messages etc. The loops ends after pressing the
8812 while (!bshutdown) {
8813 if (GSM->GetSMSStatus(&SMSStatus) == GE_NONE) {
8814 if (SMSStatus.Number!=0) {
8816 GetMachineDateTime(nowdate, nowtime );
8817 logfile = fopen("log", "a");
8819 fprintf(logfile, _("%s %s SMS Messages: UnRead %d, Number %d\n"),
8820 nowdate, nowtime, SMSStatus.UnRead, SMSStatus.Number);
8827 while (!bshutdown) {
8829 SMS.Location=location;
8830 if (GSM->GetSMSMessage(&SMS)==GE_NONE) {
8831 if (SMS.folder==0 || SMS.folder==0x08) { //GST_7110_INBOX
8833 GetMachineDateTime(nowdate, nowtime );
8834 logfile = fopen("log", "a");
8836 fprintf(logfile,_("%s %s SMS on location %i\n"),
8837 nowdate,nowtime,SMS.MessageNumber);
8841 number= 16*(SMS.MessageText[2] >> 4)+ (SMS.MessageText[2] & 0x0f);
8842 number=number+ 256*16*(SMS.MessageText[1] >> 4)+ 256*(SMS.MessageText[1] & 0x0f);
8843 number=number+65536*16*(SMS.MessageText[0] >> 4)+65536*(SMS.MessageText[0] & 0x0f);
8845 sprintf( name, "%07i_%02d%02d%02d_%02d%02d%02d.sms", number,
8846 SMS.Time.Year, SMS.Time.Month, SMS.Time.Day,
8847 SMS.Time.Hour, SMS.Time.Minute, SMS.Time.Second);
8849 strcpy(filename,Dir);
8850 strcat(filename,name);
8852 logfile = fopen("log", "a");
8854 fprintf(logfile,_("%s %s Name is \"%s\"\n"),nowdate,nowtime,filename);
8858 file = fopen(filename, "rb");
8860 file = fopen(filename, "wb");
8862 GetMachineDateTime(nowdate, nowtime );
8863 fprintf(stderr,_("%s %s ERROR: opening file \"%s\" failed !\n"),nowdate,nowtime,filename);
8864 logfile = fopen("log", "a");
8866 fprintf(logfile,_("%s %s ERROR: opening file \"%s\" failed !\n"),nowdate,nowtime,filename);
8870 fwrite(SMS.MessageText,1,SMS.Length,file);
8876 GetMachineDateTime(nowdate, nowtime );
8877 fprintf(stderr,_("%s %s ERROR: file \"%s\" already exist !\n"),nowdate,nowtime,filename);
8878 logfile = fopen("log", "a");
8880 fprintf(logfile,_("%s %s ERROR: file \"%s\" already exist !\n"),nowdate,nowtime,filename);
8885 SMS.Location=SMS.MessageNumber;
8886 if (GSM->DeleteSMSMessage(&SMS)!=GE_NONE) {
8887 GetMachineDateTime(nowdate, nowtime );
8888 fprintf(stderr,_("%s %s ERROR: Deleting SMS location %i failed !\n"),nowdate,nowtime,SMS.MessageNumber);
8889 logfile = fopen("log", "a");
8891 fprintf(logfile,_("%s %s ERROR: Deleting SMS location %i failed !\n"),nowdate,nowtime,SMS.MessageNumber);
8899 if (read==SMSStatus.Number) break;
8903 GetMachineDateTime(nowdate, nowtime );
8904 fprintf(stderr,_("%s %s ERROR: Can't get SMS status !\n"),nowdate,nowtime);
8905 logfile = fopen("log", "a");
8907 fprintf(logfile,_("%s %s ERROR: Can't get SMS status !\n"),nowdate,nowtime);
8915 fprintf (stderr, _("Leaving monitor mode...\n"));
8922 int divert(int argc, char *argv[])
8927 memset(&cd, 0, sizeof(GSM_CallDivert));
8929 if (!strcmp("register", argv[0])){cd.Operation = GSM_CDV_Register ;}
8930 else if (!strcmp("enable" , argv[0])){cd.Operation = GSM_CDV_Enable ;}
8931 else if (!strcmp("disable" , argv[0])){cd.Operation = GSM_CDV_Disable ;}
8932 else if (!strcmp("erasure" , argv[0])){cd.Operation = GSM_CDV_Erasure ;}
8933 else if (!strcmp("query" , argv[0])){cd.Operation = GSM_CDV_Query ;}
8939 if (!strcmp("all" , argv[1])) {cd.DType = GSM_CDV_AllTypes ;}
8940 else if (!strcmp("busy" , argv[1])) {cd.DType = GSM_CDV_Busy ;}
8941 else if (!strcmp("noans" , argv[1])) {cd.DType = GSM_CDV_NoAnswer ;}
8942 else if (!strcmp("outofreach", argv[1])) {cd.DType = GSM_CDV_OutOfReach;}
8948 if (!strcmp("all" , argv[2])) {cd.CType = GSM_CDV_AllCalls ;}
8949 else if (!strcmp("voice", argv[2])) {cd.CType = GSM_CDV_VoiceCalls;}
8950 else if (!strcmp("fax" , argv[2])) {cd.CType = GSM_CDV_FaxCalls ;}
8951 else if (!strcmp("data" , argv[2])) {cd.CType = GSM_CDV_DataCalls ;}
8957 if (argc>3) strcpy(cd.Number, argv[3]);
8959 if (argc>4) cd.Timeout = atoi(argv[4]);
8961 /* Initialise the code for the GSM interface. */
8964 error=GSM->CallDivert(&cd);
8966 if (error == GE_NONE) {
8967 switch (cd.Operation)
8970 fprintf(stdout, _("Divert type: "));
8972 case GSM_CDV_Busy :fprintf(stdout, _("when busy"));break;
8973 case GSM_CDV_NoAnswer :fprintf(stdout, _("when not answered"));break;
8974 case GSM_CDV_OutOfReach:fprintf(stdout, _("when phone off or no coverage"));break;
8975 case GSM_CDV_AllTypes :fprintf(stdout, _("all call diverts"));break; //?
8976 default: fprintf(stdout, _("unknown %i"),cd.DType);break;
8979 fprintf(stdout, _("\nCalls type : "));
8981 case GSM_CDV_VoiceCalls: fprintf(stdout, _("voice"));break;
8982 case GSM_CDV_FaxCalls : fprintf(stdout, _("fax"));break;
8983 case GSM_CDV_DataCalls : fprintf(stdout, _("data"));break;
8984 case GSM_CDV_AllCalls : fprintf(stdout, _("voice, fax & data"));break;
8985 default: fprintf(stdout, _("unknown %i"),cd.CType);break;
8987 fprintf(stdout, _("\n"));
8990 fprintf(stdout, _("Status : active\n"));
8991 fprintf(stdout, _("Timeout : %i seconds\n"),cd.Timeout);
8992 fprintf(stdout, _("Number : %s\n"),cd.Number);
8994 fprintf(stdout, _("Status : deactivated\n"));
8999 fprintf(stdout,_("Divert done\n"));
9002 fprintf(stderr,_("%s\n"),print_error(error));
9009 int savephonebookentry(int argc, char *argv[])
9011 GSM_MultiSMSMessage MultiSMS;
9012 GSM_PhonebookEntry entry;
9018 /* Handle command line args that set type, start and end locations. */
9019 if (!GetMemoryTypeID(argv[0], &entry.MemoryType))
9021 fprintf(stderr, _("Unknown memory type %s!\n"), argv[0]);
9025 entry.Location=atoi(argv[1]);
9029 error=GSM->GetMemoryLocation(&entry);
9034 /* Put entry into SMS structure */
9036 if (GetModelFeature(FN_PHONEBOOK)==F_PBK71INT) {
9037 GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,21);
9039 #endif /* UCLINUX */
9041 GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,10);
9044 for (w=0;w<MultiSMS.number;w++)
9045 strcpy(MultiSMS.SMS[w].Destination,"Phonebook");
9047 GSM_SaveMultiPartSMSOnConsole(&MultiSMS, 2,argc,argv,false,false,false,false);
9051 fprintf(stdout,_("Error\n"));break;
9057 int sendphonebookentry(int argc, char *argv[])
9059 GSM_MultiSMSMessage MultiSMS;
9060 GSM_PhonebookEntry entry;
9066 /* Handle command line args that set type, start and end locations. */
9067 if (!GetMemoryTypeID(argv[1], &entry.MemoryType))
9069 fprintf(stderr, _("Unknown memory type %s!\n"), argv[1]);
9073 entry.Location=atoi(argv[2]);
9077 error=GSM->GetMemoryLocation(&entry);
9082 /* Put entry into SMS structure */
9083 if (GetModelFeature(FN_PHONEBOOK)==F_PBK71INT) {
9084 GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,21);
9086 GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,10);
9089 for (w=0;w<MultiSMS.number;w++)
9090 strcpy(MultiSMS.SMS[w].Destination,argv[0]);
9092 GSM_SendMultiPartSMSOnConsole(&MultiSMS, 3,argc,argv,false,false,false);
9097 fprintf(stdout,_("Error\n"));break;
9104 int getbinringfromfile(int argc, char *argv[])
9109 GSM_BinRingtone binring,ringtone;
9111 fprintf(stdout,_("Offset %ld\n"),atol(argv[2]));
9113 file = fopen(argv[0], "rb");
9115 if (!file) return(GE_CANTOPENFILE);
9117 fseek(file,atol(argv[2]),0);
9119 ringtone.length=fread(ringtone.frame, 1, 900, file);
9125 if (ringtone.frame[i ]==0x00 && ringtone.frame[i+1]==0x02 &&
9126 ringtone.frame[i+2]==0xFC && ringtone.frame[i+3]==0x09) {
9131 if (i==ringtone.length-3) break;
9135 fprintf(stdout,_("Start not found\n"));
9141 if (ringtone.frame[j]==0x07 && ringtone.frame[j+1]==0x0B) {
9146 if (j==ringtone.length-2) break;
9150 fprintf(stdout,_("End not found\n"));
9155 binring.frame[binring.length++]=0x00;
9156 binring.frame[binring.length++]=0x00;
9157 binring.frame[binring.length++]=0x0C;
9158 binring.frame[binring.length++]=0x01;
9159 binring.frame[binring.length++]=0x2C;
9161 memcpy(binring.frame+binring.length,argv[1],strlen(argv[1]));
9162 binring.length=binring.length+strlen(argv[1]);
9164 binring.frame[binring.length++]=0x00;
9166 memcpy(binring.frame+binring.length,ringtone.frame+i,j-i+2);
9167 binring.length=binring.length+j-i+2;
9169 GSM_SaveBinRingtoneFile(argv[3], &binring);
9175 #endif /* UCLINUX */