Imported gammu 0.90.7
[gammu.git] / gammu / gammu.c
blobead9545fe7f8bb3136153116c441f747008cb81b
2 #include <string.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <stdarg.h>
6 #include <locale.h>
7 #include <signal.h>
8 #include <ctype.h>
9 #include <wchar.h>
10 #ifdef WIN32
11 # include <windows.h>
12 # include <process.h>
13 # ifdef _MSC_VER
14 # include <sys/utime.h>
15 # else
16 # include <utime.h>
17 # endif
18 #else
19 # include <utime.h>
20 #endif
22 #include "../common/gammu.h"
23 #include "gammu.h"
24 #include "smsd/smsdcore.h"
25 #ifdef DEBUG
26 # include "sniff.h"
27 #endif
28 #ifdef GSM_ENABLE_NOKIA_DCT3
29 # include "depend/dct3.h"
30 # include "depend/dct3trac/wmx.h"
31 #endif
32 #ifdef GSM_ENABLE_NOKIA_DCT4
33 # include "depend/dct4.h"
34 #endif
35 #ifdef GSM_ENABLE_ATGEN
36 # include "depend/dsiemens.h"
37 #endif
39 #ifdef HAVE_PTHREAD
40 # include <pthread.h>
41 #endif
43 #ifdef HAVE_SYS_IOCTL_H
44 # include <sys/ioctl.h>
45 #endif
48 GSM_StateMachine s;
49 GSM_Phone_Functions *Phone;
50 static INI_Section *cfg = NULL;
52 GSM_Error error = GE_NONE;
53 static int i;
55 volatile bool bshutdown = false;
57 void interrupted(int sig)
59 signal(sig, SIG_IGN);
60 bshutdown = true;
63 int printmsg(char *format, ...)
65 va_list argp;
66 int result;
68 va_start(argp, format);
69 result = vfprintf(stdout,GetMsg(s.msg,format),argp);
70 va_end(argp);
71 return result;
74 int printmsgerr(char *format, ...)
76 va_list argp;
77 int result;
79 va_start(argp, format);
80 result = vfprintf(stderr,GetMsg(s.msg,format), argp);
81 va_end(argp);
82 return result;
85 static void PrintSecurityStatus()
87 GSM_SecurityCodeType Status;
89 error=Phone->GetSecurityStatus(&s,&Status);
90 Print_Error(error);
91 switch(Status) {
92 case GSCT_SecurityCode:
93 printmsg("Waiting for Security Code.\n");
94 break;
95 case GSCT_Pin:
96 printmsg("Waiting for PIN.\n");
97 break;
98 case GSCT_Pin2:
99 printmsg("Waiting for PIN2.\n");
100 break;
101 case GSCT_Puk:
102 printmsg("Waiting for PUK.\n");
103 break;
104 case GSCT_Puk2:
105 printmsg("Waiting for PUK2.\n");
106 break;
107 case GSCT_None:
108 printmsg("Nothing to enter.\n");
109 break;
110 default:
111 printmsg("Unknown\n");
115 void Print_Error(GSM_Error error)
117 if (error != GE_NONE) {
118 printf("%s\n",print_error(error,s.di.df,s.msg));
119 if (error == GE_SECURITYERROR) {
120 printmsg("Security status: ");
121 PrintSecurityStatus();
123 if (s.opened) GSM_TerminateConnection(&s);
124 exit (-1);
128 void GSM_Init(bool checkerror)
130 error=GSM_InitConnection(&s,3);
131 if (checkerror) Print_Error(error);
133 Phone=s.Phone.Functions;
136 void GSM_Terminate(void)
138 error=GSM_TerminateConnection(&s);
139 Print_Error(error);
142 static void GetStartStop(int *start, int *stop, int num, int argc, char *argv[])
144 *start=atoi(argv[num]);
145 if (*start==0) {
146 printmsg("ERROR: enumerate locations from 1\n");
147 exit (-1);
150 if (stop!=NULL) {
151 *stop=*start;
152 if (argc>=num+2) *stop=atoi(argv[num+1]);
153 if (*stop==0) {
154 printmsg("ERROR: enumerate locations from 1\n");
155 exit (-1);
160 static bool answer_yes(char *text)
162 int len;
163 char ans[99];
164 static bool always_answer_yes = false;
165 static bool always_answer_no = false;
167 while (1) {
168 printmsgerr("%s (yes/no/ALL/ONLY/NONE) ? ",text);
169 if (always_answer_yes) {
170 printmsgerr("YES (always)\n");
171 return true;
173 if (always_answer_no) {
174 printmsgerr("NO (always)\n");
175 return false;
177 len=GetLine(stdin, ans, 99);
178 if (len==-1) exit(-1);
179 if (!strcmp(ans, "NONE")) {
180 always_answer_no = true;
181 return false;
183 if (!strcmp(ans, "ONLY")) {
184 always_answer_no = true;
185 return true;
187 if (!strcmp(ans, "ALL")) {
188 always_answer_yes = true;
189 return true;
191 if (mystrncasecmp(ans, "yes",0)) return true;
192 if (mystrncasecmp(ans, "no" ,0)) return false;
196 #ifdef GSM_ENABLE_BEEP
197 void GSM_PhoneBeep(void)
199 error = PHONE_Beep(&s);
200 if (error != GE_NOTSUPPORTED && error != GE_NOTIMPLEMENTED) Print_Error(error);
202 #endif
204 static GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone)
206 int i;
207 bool first=true;
208 GSM_Error error;
210 /* We do not want to make it forever -
211 * press Ctrl+C to stop the monitoring mode.
213 signal(SIGINT, interrupted);
214 printmsg("If you want break, press Ctrl+C...\n");
216 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
217 if (bshutdown) break;
218 if (ringtone.NoteTone.Commands[i].Type == RING_NOTETONE) {
219 error=PHONE_RTTLPlayOneNote(&s,ringtone.NoteTone.Commands[i].Note,first);
220 if (error!=GE_NONE) return error;
221 first = false;
225 /* Disables buzzer */
226 return s.Phone.Functions->PlayTone(&s,255*255,0,false);
229 static void PlayRingtone(int argc, char *argv[])
231 GSM_Ringtone ringtone,ringtone2;
233 ringtone.Format = 0;
234 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
235 Print_Error(error);
237 error=GSM_RingtoneConvert(&ringtone2,&ringtone,RING_NOTETONE);
238 Print_Error(error);
240 GSM_Init(true);
242 error=GSM_PlayRingtone(ringtone2);
243 Print_Error(error);
245 GSM_Terminate();
248 static void Identify(int argc, char *argv[])
250 unsigned char buffer[100];
252 GSM_Init(true);
254 error=Phone->GetManufacturer(&s);
255 Print_Error(error);
256 printmsg("Manufacturer : %s\n", s.Phone.Data.Manufacturer);
257 error=Phone->GetModel(&s);
258 Print_Error(error);
259 printmsg("Model : %s (%s)\n",
260 s.Phone.Data.ModelInfo->model,
261 s.Phone.Data.Model);
263 error=Phone->GetFirmware(&s);
264 Print_Error(error);
265 printmsg("Firmware : %s",s.Phone.Data.Version);
266 error=Phone->GetPPM(&s, buffer);
267 if (error != GE_NOTSUPPORTED) {
268 if (error != GE_NOTIMPLEMENTED) Print_Error(error);
269 if (error == GE_NONE) printmsg(" %s",buffer);
271 if (s.Phone.Data.VerDate[0]!=0) printmsg(" (%s)",s.Phone.Data.VerDate);
272 printf("\n");
274 error=Phone->GetHardware(&s, buffer);
275 if (error != GE_NOTSUPPORTED) {
276 if (error != GE_NOTIMPLEMENTED) Print_Error(error);
277 if (error == GE_NONE) printmsg("Hardware : %s\n",buffer);
280 error=Phone->GetIMEI(&s);
281 if (error != GE_NOTSUPPORTED) {
282 if (error != GE_NOTIMPLEMENTED) Print_Error(error);
283 if (error == GE_NONE) printmsg("IMEI : %s\n",s.Phone.Data.IMEI);
285 error=Phone->GetOriginalIMEI(&s, buffer);
286 if (error != GE_NOTSUPPORTED && error != GE_SECURITYERROR) {
287 if (error != GE_NOTIMPLEMENTED) Print_Error(error);
288 if (error == GE_NONE) printmsg("Original IMEI : %s\n",buffer);
292 error=Phone->GetManufactureMonth(&s, buffer);
293 if (error != GE_NOTSUPPORTED && error != GE_SECURITYERROR) {
294 if (error != GE_NOTIMPLEMENTED) Print_Error(error);
295 if (error == GE_NONE) printmsg("Manufactured : %s\n",buffer);
298 error=Phone->GetProductCode(&s, buffer);
299 if (error != GE_NOTSUPPORTED) {
300 if (error != GE_NOTIMPLEMENTED) Print_Error(error);
301 if (error == GE_NONE) printmsg("Product code : %s\n",buffer);
304 error=Phone->GetSIMIMSI(&s, buffer);
305 switch (error) {
306 case GE_SECURITYERROR:
307 case GE_NOTSUPPORTED:
308 case GE_NOTIMPLEMENTED:
309 break;
310 case GE_NONE:
311 printmsg("SIM IMSI : %s\n",buffer);
312 break;
313 default:
314 Print_Error(error);
317 #ifdef GSM_ENABLE_NOKIA_DCT3
318 DCT3Info(argc, argv);
319 #endif
320 #ifdef GSM_ENABLE_NOKIA_DCT4
321 DCT4Info(argc, argv);
322 #endif
324 GSM_Terminate();
327 static void GetDateTime(int argc, char *argv[])
329 GSM_DateTime date_time;
330 GSM_Locale locale;
332 GSM_Init(true);
334 error=Phone->GetDateTime(&s, &date_time);
335 switch (error) {
336 case GE_EMPTY:
337 printmsg("Date and time not set in phone\n");
338 break;
339 case GE_NONE:
340 printmsg("Phone time is %s\n",OSDateTime(date_time,false));
341 break;
342 default:
343 Print_Error(error);
346 error=Phone->GetLocale(&s, &locale);
347 switch (error) {
348 case GE_NOTSUPPORTED:
349 case GE_NOTIMPLEMENTED:
350 break;
351 default:
352 Print_Error(error);
353 printmsg("Time format is ");
354 if (locale.AMPMTime) printmsg("12 hours\n"); else printmsg("24 hours\n");
355 printmsg("Date format is ");
356 switch (locale.DateFormat) {
357 case GSM_Date_DDMMYYYY:printmsg("DD MM YYYY");break;
358 case GSM_Date_MMDDYYYY:printmsg("MM DD YYYY");break;
359 case GSM_Date_YYYYMMDD:printmsg("YYYY MM DD");
361 printmsg(", date separator is %c\n",locale.DateSeparator);
364 GSM_Terminate();
367 static void SetDateTime(int argc, char *argv[])
369 GSM_DateTime date_time;
371 GSM_GetCurrentDateTime(&date_time);
373 GSM_Init(true);
375 error=Phone->SetDateTime(&s, &date_time);
376 Print_Error(error);
378 GSM_Terminate();
381 static void GetAlarm(int argc, char *argv[])
383 GSM_Alarm alarm;
385 GSM_Init(true);
387 alarm.Location = 1;
388 error=Phone->GetAlarm(&s, &alarm);
389 switch (error) {
390 case GE_EMPTY:
391 printmsg("Alarm not set in phone\n");
392 break;
393 case GE_NONE:
394 if (alarm.Repeating) {
395 printmsg("Date: %s\n","Every day");
396 } else {
397 printmsg("Date: %s\n",OSDate(alarm.DateTime));
399 printmsg("Time: %02d:%02d\n",alarm.DateTime.Hour, alarm.DateTime.Minute);
400 if (alarm.Text[0] != 0 || alarm.Text[1] != 0) {
401 printmsg("Text: \"%s\"\n", DecodeUnicodeConsole(alarm.Text));
403 break;
404 default:
405 Print_Error(error);
408 GSM_Terminate();
411 static void SetAlarm(int argc, char *argv[])
413 GSM_Alarm alarm;
415 alarm.DateTime.Hour = atoi(argv[2]);
416 alarm.DateTime.Minute = atoi(argv[3]);
417 alarm.DateTime.Second = 0;
418 alarm.Location = 1;
419 alarm.Repeating = true;
420 alarm.Text[0] = 0;
421 alarm.Text[1] = 0;
423 GSM_Init(true);
425 error=Phone->SetAlarm(&s, &alarm);
426 Print_Error(error);
428 GSM_Terminate();
431 GSM_Bitmap caller[5];
432 GSM_AllRingtonesInfo Info;
433 bool callerinit[5] = {false, false, false, false, false};
434 bool ringinit = false;
436 static void PrintMemoryEntry(GSM_MemoryEntry *entry)
438 GSM_Category Category;
439 bool unknown;
440 int z;
442 for (i=0;i<entry->EntriesNum;i++) {
443 unknown = false;
444 switch (entry->Entries[i].EntryType) {
445 case PBK_Date:
446 printmsg("Date and time : %s\n",OSDateTime(entry->Entries[i].Date,false));
447 continue;
448 case PBK_Category:
449 Category.Location = entry->Entries[i].Number;
450 Category.Type = Category_Phonebook;
451 error=Phone->GetCategory(&s, &Category);
452 if (error == GE_NONE) {
453 printmsg("Category : \"%s\" (%i)\n", DecodeUnicodeConsole(Category.Name), entry->Entries[i].Number);
454 } else {
455 printmsg("Category : %i\n", entry->Entries[i].Number);
457 continue;
458 case PBK_Private:
459 printmsg("Private : %s\n", entry->Entries[i].Number == 1 ? "Yes" : "No");
460 continue;
461 case PBK_Number_General : printmsg("General number "); break;
462 case PBK_Number_Mobile : printmsg("Mobile number "); break;
463 case PBK_Number_Work : printmsg("Work number "); break;
464 case PBK_Number_Fax : printmsg("Fax number "); break;
465 case PBK_Number_Home : printmsg("Home number "); break;
466 case PBK_Number_Pager : printmsg("Pager number "); break;
467 case PBK_Number_Other : printmsg("Other number "); break;
468 case PBK_Text_Note : printmsg("Text "); break;
469 case PBK_Text_Postal : printmsg("Snail address "); break;
470 case PBK_Text_Email : printmsg("Email address 1 "); break;
471 case PBK_Text_Email2 : printmsg("Email address 2 "); break;
472 case PBK_Text_URL : printmsg("URL address "); break;
473 case PBK_Text_Name : printmsg("Name "); break;
474 case PBK_Text_LastName : printmsg("Last name "); break;
475 case PBK_Text_FirstName : printmsg("First name "); break;
476 case PBK_Text_Company : printmsg("Company "); break;
477 case PBK_Text_JobTitle : printmsg("Job title "); break;
478 case PBK_Text_StreetAddress : printmsg("Street address "); break;
479 case PBK_Text_City : printmsg("City "); break;
480 case PBK_Text_State : printmsg("State "); break;
481 case PBK_Text_Zip : printmsg("Zip code "); break;
482 case PBK_Text_Country : printmsg("Country "); break;
483 case PBK_Text_Custom1 : printmsg("Custom text 1 "); break;
484 case PBK_Text_Custom2 : printmsg("Custom text 2 "); break;
485 case PBK_Text_Custom3 : printmsg("Custom text 3 "); break;
486 case PBK_Text_Custom4 : printmsg("Custom text 4 "); break;
487 case PBK_Caller_Group :
488 unknown = true;
489 if (!callerinit[entry->Entries[i].Number]) {
490 caller[entry->Entries[i].Number].Type = GSM_CallerLogo;
491 caller[entry->Entries[i].Number].Location = entry->Entries[i].Number;
492 error=Phone->GetBitmap(&s,&caller[entry->Entries[i].Number]);
493 Print_Error(error);
494 if (caller[entry->Entries[i].Number].DefaultName) {
495 NOKIA_GetDefaultCallerGroupName(&s,&caller[entry->Entries[i].Number]);
497 callerinit[entry->Entries[i].Number]=true;
499 printmsg("Caller group : \"%s\"\n",DecodeUnicodeConsole(caller[entry->Entries[i].Number].Text));
500 break;
501 case PBK_RingtoneID :
502 unknown = true;
503 if (!ringinit) {
504 error=Phone->GetRingtonesInfo(&s,&Info);
505 if (error != GE_NOTSUPPORTED) Print_Error(error);
506 if (error == GE_NONE) ringinit = true;
508 if (ringinit) {
509 for (z=0;z<Info.Number;z++) {
510 if (Info.Ringtone[z].ID == entry->Entries[i].Number) {
511 printmsg("Ringtone : \"%s\"\n",DecodeUnicodeConsole(Info.Ringtone[z].Name));
512 break;
515 } else {
516 printmsg("Ringtone ID : %i\n",entry->Entries[i].Number);
518 break;
519 case PBK_PictureID :
520 unknown = true;
521 printmsg("Picture ID : 0x%x\n",entry->Entries[i].Number);
522 break;
523 default :
524 printmsg("UNKNOWN\n");
525 unknown = true;
526 break;
528 if (!unknown) printmsg(" : \"%s\"\n", DecodeUnicodeConsole(entry->Entries[i].Text));
530 printf("\n");
533 static void GetAllMemory(int argc, char *argv[])
535 GSM_MemoryEntry Entry;
536 bool start = true;
538 signal(SIGINT, interrupted);
539 printmsgerr("If you want break, press Ctrl+C...\n");
541 Entry.MemoryType = 0;
543 if (mystrncasecmp(argv[2],"DC",0)) Entry.MemoryType=GMT_DC;
544 if (mystrncasecmp(argv[2],"ON",0)) Entry.MemoryType=GMT_ON;
545 if (mystrncasecmp(argv[2],"RC",0)) Entry.MemoryType=GMT_RC;
546 if (mystrncasecmp(argv[2],"MC",0)) Entry.MemoryType=GMT_MC;
547 if (mystrncasecmp(argv[2],"ME",0)) Entry.MemoryType=GMT_ME;
548 if (mystrncasecmp(argv[2],"SM",0)) Entry.MemoryType=GMT_SM;
549 if (mystrncasecmp(argv[2],"VM",0)) Entry.MemoryType=GMT_VM;
550 if (mystrncasecmp(argv[2],"FD",0)) Entry.MemoryType=GMT_FD;
551 if (Entry.MemoryType==0) {
552 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]);
553 exit (-1);
556 GSM_Init(true);
558 while (1) {
559 if (bshutdown) break;
560 error = Phone->GetNextMemory(&s, &Entry, start);
561 if (error == GE_EMPTY) break;
562 Print_Error(error);
563 printmsg("Memory %s, Location %i\n",argv[2],Entry.Location);
564 PrintMemoryEntry(&Entry);
565 start = false;
568 GSM_Terminate();
571 static void GetMemory(int argc, char *argv[])
573 int j, start, stop;
574 GSM_MemoryEntry entry;
576 entry.MemoryType=0;
578 if (mystrncasecmp(argv[2],"DC",0)) entry.MemoryType=GMT_DC;
579 if (mystrncasecmp(argv[2],"ON",0)) entry.MemoryType=GMT_ON;
580 if (mystrncasecmp(argv[2],"RC",0)) entry.MemoryType=GMT_RC;
581 if (mystrncasecmp(argv[2],"MC",0)) entry.MemoryType=GMT_MC;
582 if (mystrncasecmp(argv[2],"ME",0)) entry.MemoryType=GMT_ME;
583 if (mystrncasecmp(argv[2],"SM",0)) entry.MemoryType=GMT_SM;
584 if (mystrncasecmp(argv[2],"VM",0)) entry.MemoryType=GMT_VM;
585 if (mystrncasecmp(argv[2],"FD",0)) entry.MemoryType=GMT_FD;
586 if (entry.MemoryType==0) {
587 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]);
588 exit (-1);
591 GetStartStop(&start, &stop, 3, argc, argv);
593 GSM_Init(true);
595 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310")) {
596 if (s.Phone.Data.VerNum<=4.06) printmsg("WARNING: you will have null names in entries. Upgrade firmware in phone to higher than 4.06\n");
599 for (j=start;j<=stop;j++) {
600 printmsg("Memory %s, Location %i\n",argv[2],j);
602 entry.Location=j;
604 error=Phone->GetMemory(&s, &entry);
605 if (error != GE_EMPTY) Print_Error(error);
607 if (error == GE_EMPTY) {
608 printmsg("Entry is empty\n");
609 printf("\n");
610 } else {
611 PrintMemoryEntry(&entry);
615 GSM_Terminate();
618 #define MemoryLocationToString(x) ( \
619 x == GMT_ON ? "ON" : \
620 x == GMT_RC ? "RC" : \
621 x == GMT_MC ? "MC" : \
622 x == GMT_ME ? "ME" : \
623 x == GMT_SM ? "SM" : \
624 x == GMT_VM ? "VM" : \
625 x == GMT_FD ? "FD" : "XX")
627 static void SearchOneEntry(GSM_MemoryEntry *Entry, unsigned char *Text)
629 int i;
631 for (i=0;i<Entry->EntriesNum;i++) {
632 switch (Entry->Entries[i].EntryType) {
633 case PBK_Number_General :
634 case PBK_Number_Mobile :
635 case PBK_Number_Work :
636 case PBK_Number_Fax :
637 case PBK_Number_Home :
638 case PBK_Number_Pager :
639 case PBK_Number_Other :
640 case PBK_Text_Note :
641 case PBK_Text_Postal :
642 case PBK_Text_Email :
643 case PBK_Text_Email2 :
644 case PBK_Text_URL :
645 case PBK_Text_Name :
646 case PBK_Text_LastName :
647 case PBK_Text_FirstName :
648 case PBK_Text_Company :
649 case PBK_Text_JobTitle :
650 case PBK_Text_StreetAddress :
651 case PBK_Text_City :
652 case PBK_Text_State :
653 case PBK_Text_Zip :
654 case PBK_Text_Country :
655 case PBK_Text_Custom1 :
656 case PBK_Text_Custom2 :
657 case PBK_Text_Custom3 :
658 case PBK_Text_Custom4 :
659 case PBK_Caller_Group :
660 if (mystrstr(Entry->Entries[i].Text, Text) != NULL) {
661 fprintf(stderr,"\n");
662 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry->MemoryType),Entry->Location);
663 PrintMemoryEntry(Entry);
664 return;
666 break;
667 default:
668 break;
673 static void SearchOneMemory(GSM_MemoryType MemoryType, char *Title, unsigned char *Text)
675 GSM_MemoryEntry Entry;
676 GSM_MemoryStatus Status;
677 int i = 0, l = 1;
678 bool start = true;
680 Status.MemoryType = MemoryType;
681 Entry.MemoryType = MemoryType;
683 if (Phone->GetMemoryStatus(&s, &Status) == GE_NONE) {
684 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.Used+1));
685 if (Phone->GetNextMemory != NOTSUPPORTED && Phone->GetNextMemory != NOTIMPLEMENTED) {
686 while (i < Status.Used) {
687 if (bshutdown) return;
688 i++;
689 fprintf(stderr,"\r%s: %i%%", Title, (i+1)*100/(Status.Used+1));
690 error = Phone->GetNextMemory(&s, &Entry, start);
691 if (error == GE_EMPTY) break;
692 Print_Error(error);
693 SearchOneEntry(&Entry, Text);
694 start = false;
696 } else {
697 while (i < Status.Used) {
698 Entry.Location = l;
699 error = Phone->GetMemory(&s, &Entry);
700 if (error != GE_EMPTY) {
701 Print_Error(error);
702 i++;
703 SearchOneEntry(&Entry, Text);
705 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.Used+1));
706 l++;
709 fprintf(stderr,"\n");
713 static void SearchMemory(int argc, char *argv[])
715 unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1)*2];
716 int Length;
718 signal(SIGINT, interrupted);
719 printmsgerr("If you want break, press Ctrl+C...\n");
721 Length = strlen(argv[2]);
722 if (Length > GSM_PHONEBOOK_TEXT_LENGTH) {
723 printmsg("Search text too long, truncating to %d chars!\n", GSM_PHONEBOOK_TEXT_LENGTH);
724 Length = GSM_PHONEBOOK_TEXT_LENGTH;
726 EncodeUnicode(Text, argv[2], Length);
728 GSM_Init(true);
730 if (!bshutdown) SearchOneMemory(GMT_ME, "Phone phonebook", Text);
731 if (!bshutdown) SearchOneMemory(GMT_SM, "SIM phonebook", Text);
732 if (!bshutdown) SearchOneMemory(GMT_ON, "Own numbers", Text);
733 if (!bshutdown) SearchOneMemory(GMT_DC, "Dialled numbers", Text);
734 if (!bshutdown) SearchOneMemory(GMT_RC, "Received numbers", Text);
735 if (!bshutdown) SearchOneMemory(GMT_MC, "Missed numbers", Text);
736 if (!bshutdown) SearchOneMemory(GMT_FD, "Fix dialling", Text);
737 if (!bshutdown) SearchOneMemory(GMT_VM, "Voice mailbox", Text);
739 GSM_Terminate();
742 static void ListMemoryCategoryEntries(int Category)
744 GSM_MemoryEntry Entry;
745 bool start = true;
746 int j;
748 /* Category can be only for ME stored entries */
749 Entry.MemoryType = GMT_ME;
751 while (1) {
752 if (bshutdown) break;
753 error = Phone->GetNextMemory(&s, &Entry, start);
754 if (error == GE_EMPTY) break;
755 Print_Error(error);
756 for (j=0;j<Entry.EntriesNum;j++) {
757 if (Entry.Entries[j].EntryType == PBK_Category && Entry.Entries[j].Number == Category) {
758 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry.MemoryType),Entry.Location);
759 PrintMemoryEntry(&Entry);
762 start = false;
766 static void ListMemoryCategory(int argc, char *argv[])
768 GSM_Category Category;
769 GSM_CategoryStatus Status;
770 int j, count;
772 unsigned char Text[(GSM_MAX_CATEGORY_NAME_LENGTH+1)*2];
773 int Length;
774 bool Number = true;;
776 GSM_Init(true);
778 signal(SIGINT, interrupted);
779 printmsgerr("If you want break, press Ctrl+C...\n");
781 Length = strlen(argv[2]);
782 for (j = 0; j < Length; j++) {
783 if (!isdigit(argv[2][j])) {
784 Number = false;
785 break;
789 if (Number) {
790 j = atoi(argv[2]);
791 if (j > 0) {
792 ListMemoryCategoryEntries(j);
794 } else {
795 if (Length > GSM_MAX_CATEGORY_NAME_LENGTH) {
796 printmsg("Search text too long, truncating to %d chars!\n", GSM_MAX_CATEGORY_NAME_LENGTH);
797 Length = GSM_MAX_CATEGORY_NAME_LENGTH;
799 EncodeUnicode(Text, argv[2], Length);
801 Category.Type = Category_Phonebook;
802 Status.Type = Category_Phonebook;
804 if (Phone->GetCategoryStatus(&s, &Status) == GE_NONE) {
805 for (count=0,j=1;count<Status.Used;j++) {
806 Category.Location=j;
807 error=Phone->GetCategory(&s, &Category);
809 if (error != GE_EMPTY) {
810 count++;
811 if (mystrstr(Category.Name, Text) != NULL) {
812 ListMemoryCategoryEntries(j);
818 GSM_Terminate();
821 static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool displayudh)
823 switch (sms.PDU) {
824 case SMS_Status_Report:
825 printmsg("SMS status report\n");
826 printmsg("Status : ");
827 switch (sms.State) {
828 case GSM_Sent : printmsg("Sent"); break;
829 case GSM_Read : printmsg("Read"); break;
830 case GSM_UnRead : printmsg("UnRead"); break;
831 case GSM_UnSent : printmsg("UnSent"); break;
833 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
834 printmsg("Sent : %s\n",OSDateTime(sms.DateTime,true));
835 printmsg("SMSC number : \"%s\"\n",DecodeUnicodeConsole(sms.SMSC.Number));
836 printmsg("SMSC response : %s\n",OSDateTime(sms.SMSCTime,true));
837 printmsg("Delivery status : %s\n",DecodeUnicodeConsole(sms.Text));
838 printmsg("Details : ");
839 if (sms.DeliveryStatus & 0x40) {
840 if (sms.DeliveryStatus & 0x20) {
841 printmsg("Temporary error, ");
842 } else {
843 printmsg("Permanent error, ");
845 } else if (sms.DeliveryStatus & 0x20) {
846 printmsg("Temporary error, ");
848 switch (sms.DeliveryStatus) {
849 case 0x00: printmsg("SM received by the SME"); break;
850 case 0x01: printmsg("SM forwarded by the SC to the SME but the SC is unable to confirm delivery");break;
851 case 0x02: printmsg("SM replaced by the SC"); break;
852 case 0x20: printmsg("Congestion"); break;
853 case 0x21: printmsg("SME busy"); break;
854 case 0x22: printmsg("No response from SME"); break;
855 case 0x23: printmsg("Service rejected"); break;
856 case 0x24: printmsg("Quality of service not aviable"); break;
857 case 0x25: printmsg("Error in SME"); break;
858 case 0x40: printmsg("Remote procedure error"); break;
859 case 0x41: printmsg("Incompatibile destination"); break;
860 case 0x42: printmsg("Connection rejected by SME"); break;
861 case 0x43: printmsg("Not obtainable"); break;
862 case 0x44: printmsg("Quality of service not available"); break;
863 case 0x45: printmsg("No internetworking available"); break;
864 case 0x46: printmsg("SM Validity Period Expired"); break;
865 case 0x47: printmsg("SM deleted by originating SME"); break;
866 case 0x48: printmsg("SM Deleted by SC Administration"); break;
867 case 0x49: printmsg("SM does not exist"); break;
868 case 0x60: printmsg("Congestion"); break;
869 case 0x61: printmsg("SME busy"); break;
870 case 0x62: printmsg("No response from SME"); break;
871 case 0x63: printmsg("Service rejected"); break;
872 case 0x64: printmsg("Quality of service not available"); break;
873 case 0x65: printmsg("Error in SME"); break;
874 default : printmsg("Reserved/Specific to SC: %x",sms.DeliveryStatus); break;
876 printf("\n");
877 break;
878 case SMS_Deliver:
879 printmsg("SMS message\n");
880 printmsg("SMSC number : \"%s\"",DecodeUnicodeConsole(sms.SMSC.Number));
881 if (sms.ReplyViaSameSMSC) printmsg(" (set for reply)");
882 printmsg("\nSent : %s\n",OSDateTime(sms.DateTime,true));
883 /* No break. The only difference for SMS_Deliver and SMS_Submit is,
884 * that SMS_Deliver contains additional data. We wrote them and then go
885 * for data shared with SMS_Submit
887 case SMS_Submit:
888 if (sms.ReplaceMessage != 0) printmsg("SMS replacing ID : %i\n",sms.ReplaceMessage);
889 /* If we went here from "case SMS_Deliver", we don't write "SMS Message" */
890 if (sms.PDU==SMS_Submit) printmsg("SMS message\n");
891 if (sms.Name[0] != 0x00 || sms.Name[1] != 0x00) {
892 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(sms.Name));
894 if (sms.Class != -1) {
895 printmsg("Class : %i\n",sms.Class);
897 printmsg("Coding : ");
898 switch (sms.Coding) {
899 case GSM_Coding_Unicode : printmsg("Unicode\n"); break;
900 case GSM_Coding_Default : printmsg("Default GSM alphabet\n"); break;
901 case GSM_Coding_8bit : printmsg("8 bit\n"); break;
903 printmsg("Status : ");
904 switch (sms.State) {
905 case GSM_Sent : printmsg("Sent"); break;
906 case GSM_Read : printmsg("Read"); break;
907 case GSM_UnRead : printmsg("UnRead"); break;
908 case GSM_UnSent : printmsg("UnSent"); break;
910 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
911 if (sms.UDH.Type != UDH_NoUDH) {
912 printmsg("User Data Header : ");
913 switch (sms.UDH.Type) {
914 case UDH_ConcatenatedMessages : printmsg("Concatenated (linked) message"); break;
915 case UDH_ConcatenatedMessages16bit : printmsg("Concatenated (linked) message"); break;
916 case UDH_DisableVoice : printmsg("Disables voice indicator"); break;
917 case UDH_EnableVoice : printmsg("Enables voice indicator"); break;
918 case UDH_DisableFax : printmsg("Disables fax indicator"); break;
919 case UDH_EnableFax : printmsg("Enables fax indicator"); break;
920 case UDH_DisableEmail : printmsg("Disables email indicator"); break;
921 case UDH_EnableEmail : printmsg("Enables email indicator"); break;
922 case UDH_VoidSMS : printmsg("Void SMS"); break;
923 case UDH_NokiaWAP : printmsg("Nokia WAP bookmark"); break;
924 case UDH_NokiaOperatorLogoLong : printmsg("Nokia operator logo"); break;
925 case UDH_NokiaWAPLong : printmsg("Nokia WAP bookmark or WAP/MMS settings"); break;
926 case UDH_NokiaRingtone : printmsg("Nokia ringtone"); break;
927 case UDH_NokiaRingtoneLong : printmsg("Nokia ringtone"); break;
928 case UDH_NokiaOperatorLogo : printmsg("Nokia GSM operator logo"); break;
929 case UDH_NokiaCallerLogo : printmsg("Nokia caller logo"); break;
930 case UDH_NokiaProfileLong : printmsg("Nokia profile"); break;
931 case UDH_NokiaCalendarLong : printmsg("Nokia calendar note"); break;
932 case UDH_NokiaPhonebookLong : printmsg("Nokia phonebook entry"); break;
933 case UDH_UserUDH : printmsg("User UDH"); break;
934 case UDH_MMSIndicatorLong : printmsg("MMS indicator"); break;
935 case UDH_NoUDH: break;
937 if (sms.UDH.Type != UDH_NoUDH) {
938 if (sms.UDH.ID8bit != -1) printmsg(", ID (8 bit) %i",sms.UDH.ID8bit);
939 if (sms.UDH.ID16bit != -1) printmsg(", ID (16 bit) %i",sms.UDH.ID16bit);
940 if (sms.UDH.PartNumber != -1 && sms.UDH.AllParts != -1) {
941 if (displayudh) {
942 printmsg(", part %i of %i",sms.UDH.PartNumber,sms.UDH.AllParts);
943 } else {
944 printmsg(", %i parts",sms.UDH.AllParts);
948 printf("\n");
950 if (displaytext) {
951 printf("\n");
952 if (sms.Coding!=GSM_Coding_8bit) {
953 printmsg("%s\n",DecodeUnicodeConsole(sms.Text));
954 } else {
955 printmsg("8 bit SMS, cannot be displayed here\n");
958 break;
962 typedef struct {
963 GSM_MultiBitmap Bitmap;
964 GSM_Ringtone Ringtone;
965 char Buffer[5000];
966 } SMSValues;
968 static void displaymultismsinfo (GSM_MultiSMSMessage sms, bool eachsms, bool ems)
970 GSM_EncodeMultiPartSMSInfo SMSInfo;
971 SMSValues Values[MAX_MULTI_SMS];
972 bool RetVal,udhinfo=true;
973 int j;
975 for (i=0;i<MAX_MULTI_SMS;i++) {
976 SMSInfo.Entries[i].Bitmap = &Values[i].Bitmap;
977 SMSInfo.Entries[i].Ringtone = &Values[i].Ringtone;
978 SMSInfo.Entries[i].Buffer = Values[i].Buffer;
980 SMSInfo.Unknown = false;
982 /* GSM_DecodeMultiPartSMS returns if decoded SMS contenst correctly */
983 RetVal = GSM_DecodeMultiPartSMS(&SMSInfo,&sms,ems);
985 if (eachsms) {
986 if (sms.SMS[0].UDH.Type != UDH_NoUDH && sms.SMS[0].UDH.AllParts == sms.Number) udhinfo = false;
987 if (RetVal && !udhinfo) {
988 displaysinglesmsinfo(sms.SMS[0],false,false);
989 printf("\n");
990 } else {
991 for (j=0;j<sms.Number;j++) {
992 displaysinglesmsinfo(sms.SMS[j],!RetVal,udhinfo);
993 printf("\n");
996 } else {
997 for (j=0;j<sms.Number;j++) {
998 displaysinglesmsinfo(sms.SMS[j],!RetVal,true);
999 printf("\n");
1002 if (!RetVal) return;
1004 if (SMSInfo.Unknown) printmsg("Some details were ignored (unknown or not implemented in decoding functions)\n\n");
1006 for (i=0;i<SMSInfo.EntriesNum;i++) {
1007 switch (SMSInfo.Entries[i].ID) {
1008 case SMS_NokiaRingtone:
1009 printmsg("Ringtone \"%s\"\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Ringtone->Name));
1010 saverttl(stdout,SMSInfo.Entries[i].Ringtone);
1011 printf("\n");
1012 if (s.Phone.Functions->PlayTone!=NOTSUPPORTED &&
1013 s.Phone.Functions->PlayTone!=NOTIMPLEMENTED) {
1014 if (answer_yes("Do you want to play it")) GSM_PlayRingtone(*SMSInfo.Entries[i].Ringtone);
1016 break;
1017 case SMS_NokiaCallerLogo:
1018 printmsg("Caller logo\n\n");
1019 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1020 break;
1021 case SMS_NokiaOperatorLogo:
1022 printmsg("Operator logo for %s network (%s, %s)\n\n",
1023 SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode,
1024 DecodeUnicodeConsole(GSM_GetNetworkName(SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode)),
1025 DecodeUnicodeConsole(GSM_GetCountryName(SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode)));
1026 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1027 break;
1028 case SMS_NokiaScreenSaverLong:
1029 printmsg("Screen saver\n");
1030 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1031 break;
1032 case SMS_NokiaPictureImageLong:
1033 printmsg("Picture Image\n");
1034 if (UnicodeLength(SMSInfo.Entries[i].Bitmap->Bitmap[0].Text)!=0) printmsg("Text: \"%s\"\n\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Bitmap->Bitmap[0].Text));
1035 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1036 break;
1037 case SMS_NokiaProfileLong:
1038 printmsg("Profile\n");
1039 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1040 break;
1041 case SMS_ConcatenatedTextLong:
1042 case SMS_ConcatenatedAutoTextLong:
1043 case SMS_ConcatenatedTextLong16bit:
1044 case SMS_ConcatenatedAutoTextLong16bit:
1045 printmsg("%s\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Buffer));
1046 break;
1047 case SMS_EMSFixedBitmap:
1048 case SMS_EMSVariableBitmap:
1049 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1050 break;
1051 case SMS_EMSAnimation:
1052 /* Can't show animation, we show first frame */
1053 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1054 break;
1055 case SMS_EMSPredefinedSound:
1056 printmsg("\nEMS sound ID: %i\n",SMSInfo.Entries[i].Number);
1057 break;
1058 case SMS_EMSPredefinedAnimation:
1059 printmsg("\nEMS animation ID: %i\n",SMSInfo.Entries[i].Number);
1060 break;
1061 default:
1062 printf("Error\n");
1063 break;
1066 printf("\n");
1069 static void IncomingSMS(char *Device, GSM_SMSMessage sms)
1071 GSM_MultiSMSMessage SMS;
1073 printmsg("SMS message received\n");
1074 SMS.Number = 1;
1075 memcpy(&SMS.SMS[0],&sms,sizeof(GSM_SMSMessage));
1076 displaymultismsinfo(SMS,false,false);
1079 static void IncomingCB(char *Device, GSM_CBMessage CB)
1081 printmsg("CB message received\n");
1082 printmsg("Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeConsole(CB.Text));
1085 static void IncomingCall(char *Device, GSM_Call call)
1087 printmsg("Call info : ");
1088 if (call.CallIDAvailable) printmsg("ID %i, ",call.CallID);
1089 switch(call.Status) {
1090 case GN_CALL_IncomingCall : printmsg("incoming call from \"%s\"\n",DecodeUnicodeConsole(call.PhoneNumber)); break;
1091 case GN_CALL_OutgoingCall : printmsg("outgoing call to \"%s\"\n",DecodeUnicodeConsole(call.PhoneNumber)); break;
1092 case GN_CALL_CallStart : printmsg("call started\n"); break;
1093 case GN_CALL_CallEnd : printmsg("end of call (unknown side)\n"); break;
1094 case GN_CALL_CallLocalEnd : printmsg("call end from our side\n"); break;
1095 case GN_CALL_CallRemoteEnd : printmsg("call end from remote side (code %i)\n",call.StatusCode); break;
1096 case GN_CALL_CallEstablished : printmsg("call established. Waiting for answer\n"); break;
1097 case GN_CALL_CallHeld : printmsg("call held\n"); break;
1098 case GN_CALL_CallResumed : printmsg("call resumed\n"); break;
1099 case GN_CALL_CallSwitched : printmsg("call switched\n"); break;
1103 static void IncomingUSSD(char *Device, char *Buffer)
1105 printmsg("Service reply: \"%s\"\n",DecodeUnicodeConsole(Buffer));
1108 #define CHECKMEMORYSTATUS(x, m, a1, b1) { \
1109 x.MemoryType=m; \
1110 if (Phone->GetMemoryStatus(&s, &x) == GE_NONE) \
1111 printmsg("%s %03d, %s %03d\n", a1, x.Used, b1, x.Free); \
1114 static void Monitor(int argc, char *argv[])
1116 GSM_MemoryStatus MemStatus;
1117 GSM_SMSMemoryStatus SMSStatus;
1118 GSM_ToDoStatus ToDoStatus;
1119 GSM_CalendarStatus CalendarStatus;
1120 GSM_NetworkInfo NetInfo;
1121 GSM_BatteryCharge BatteryCharge;
1122 GSM_SignalQuality SignalQuality;
1123 int count = -1;
1125 if (argc >= 3) {
1126 count = atoi(argv[2]);
1127 if (count <= 0) count = -1;
1130 /* We do not want to monitor serial line forever -
1131 * press Ctrl+C to stop the monitoring mode.
1133 signal(SIGINT, interrupted);
1134 printmsgerr("If you want break, press Ctrl+C...\n");
1135 printmsg("Entering monitor mode...\n\n");
1137 GSM_Init(true);
1139 s.User.IncomingSMS = IncomingSMS;
1140 s.User.IncomingCB = IncomingCB;
1141 s.User.IncomingCall = IncomingCall;
1142 s.User.IncomingUSSD = IncomingUSSD;
1144 error=Phone->SetIncomingSMS (&s,true);
1145 printmsg("Enabling info about incoming SMS : %s\n",print_error(error,NULL,s.msg));
1146 error=Phone->SetIncomingCB (&s,true);
1147 printmsg("Enabling info about incoming CB : %s\n",print_error(error,NULL,s.msg));
1148 error=Phone->SetIncomingCall (&s,true);
1149 printmsg("Enabling info about calls : %s\n",print_error(error,NULL,s.msg));
1150 error=Phone->SetIncomingUSSD (&s,true);
1151 printmsg("Enabling info about USSD : %s\n\n",print_error(error,NULL,s.msg));
1153 /* Loop here indefinitely -
1154 * allows you to see messages from GSM code in
1155 * response to unknown messages etc.
1156 * The loops ends after pressing the Ctrl+C.
1158 while (!bshutdown && count != 0) {
1159 if (count > 0) count--;
1160 CHECKMEMORYSTATUS(MemStatus,GMT_SM,"SIM phonebook : Used","Free");
1161 CHECKMEMORYSTATUS(MemStatus,GMT_DC,"Dialled numbers : Used","Free");
1162 CHECKMEMORYSTATUS(MemStatus,GMT_RC,"Received numbers : Used","Free");
1163 CHECKMEMORYSTATUS(MemStatus,GMT_MC,"Missed numbers : Used","Free");
1164 CHECKMEMORYSTATUS(MemStatus,GMT_ON,"Own numbers : Used","Free");
1165 CHECKMEMORYSTATUS(MemStatus,GMT_ME,"Phone phonebook : Used","Free");
1166 if (Phone->GetToDoStatus(&s, &ToDoStatus) == GE_NONE) {
1167 printmsg("ToDos : Used %d\n", ToDoStatus.Used);
1169 if (Phone->GetCalendarStatus(&s, &CalendarStatus) == GE_NONE) {
1170 printmsg("Calendar : Used %d\n", CalendarStatus.Used);
1172 if (Phone->GetBatteryCharge(&s,&BatteryCharge)==GE_NONE) {
1173 if (BatteryCharge.BatteryPercent != -1) printmsg("Battery level : %i percent\n", BatteryCharge.BatteryPercent);
1174 if (BatteryCharge.ChargeState != 0) {
1175 printmsg("Charge state : ");
1176 switch (BatteryCharge.ChargeState) {
1177 case GSM_BatteryPowered:
1178 printmsg("powered from battery");
1179 break;
1180 case GSM_BatteryConnected:
1181 printmsg("battery connected, but not powered from battery");
1182 break;
1183 case GSM_BatteryNotConnected:
1184 printmsg("battery not connected");
1185 break;
1186 case GSM_PowerFault:
1187 printmsg("detected power failure");
1188 break;
1189 default:
1190 printmsg("unknown");
1191 break;
1193 printf("\n");
1196 if (Phone->GetSignalQuality(&s,&SignalQuality)==GE_NONE) {
1197 if (SignalQuality.SignalStrength != -1) printmsg("Signal strength : %i dBm\n", SignalQuality.SignalStrength);
1198 if (SignalQuality.SignalPercent != -1) printmsg("Network level : %i percent\n", SignalQuality.SignalPercent);
1199 if (SignalQuality.BitErrorRate != -1) printmsg("Bit error rate : %i percent\n", SignalQuality.BitErrorRate);
1201 if (Phone->GetSMSStatus(&s,&SMSStatus)==GE_NONE) {
1202 if (SMSStatus.SIMSize > 0) {
1203 printmsg("SIM SMS status : %i used, %i unread, %i locations\n",
1204 SMSStatus.SIMUsed,
1205 SMSStatus.SIMUnRead,
1206 SMSStatus.SIMSize);
1209 if (SMSStatus.PhoneSize > 0) {
1210 printmsg("Phone SMS status : %i used, %i unread, %i locations",
1211 SMSStatus.PhoneUsed,
1212 SMSStatus.PhoneUnRead,
1213 SMSStatus.PhoneSize);
1214 if (SMSStatus.TemplatesUsed!=0) printmsg(", %i templates", SMSStatus.TemplatesUsed);
1215 printf("\n");
1218 if (Phone->GetNetworkInfo(&s,&NetInfo)==GE_NONE) {
1219 printmsg("Network state : ");
1220 switch (NetInfo.State) {
1221 case GSM_HomeNetwork : printmsg("home network\n"); break;
1222 case GSM_RoamingNetwork : printmsg("roaming network\n"); break;
1223 case GSM_RequestingNetwork : printmsg("requesting network\n"); break;
1224 case GSM_NoNetwork : printmsg("not logged into network\n"); break;
1225 case GSM_RegistrationDenied : printmsg("registration to network denied\n"); break;
1226 case GSM_NetworkStatusUnknown : printmsg("unknown\n"); break;
1227 default : printmsg("unknown\n");
1229 if (NetInfo.State == GSM_HomeNetwork || NetInfo.State == GSM_RoamingNetwork) {
1230 printmsg("Network : %s (%s", NetInfo.NetworkCode,DecodeUnicodeConsole(GSM_GetNetworkName(NetInfo.NetworkCode)));
1231 printmsg(", %s)", DecodeUnicodeConsole(GSM_GetCountryName(NetInfo.NetworkCode)));
1232 printmsg(", LAC %s, CellID %s\n", NetInfo.LAC,NetInfo.CellID);
1233 if (NetInfo.NetworkName[0] != 0x00 || NetInfo.NetworkName[1] != 0x00) {
1234 printmsg("Name in phone : \"%s\"\n",DecodeUnicodeConsole(NetInfo.NetworkName));
1238 printf("\n");
1241 printmsg("Leaving monitor mode...\n");
1243 GSM_Terminate();
1246 static void GetSMSC(int argc, char *argv[])
1248 GSM_SMSC smsc;
1249 int start, stop;
1251 GetStartStop(&start, &stop, 2, argc, argv);
1253 GSM_Init(true);
1255 for (i=start;i<=stop;i++) {
1256 smsc.Location=i;
1258 error=Phone->GetSMSC(&s, &smsc);
1259 Print_Error(error);
1261 if (!strcmp(DecodeUnicodeConsole(smsc.Name),"")) {
1262 printmsg("%i. Set %i\n",smsc.Location, smsc.Location);
1263 } else {
1264 printmsg("%i. \"%s\"\n",smsc.Location, DecodeUnicodeConsole(smsc.Name));
1266 printmsg("Number : \"%s\"\n",DecodeUnicodeConsole(smsc.Number));
1267 printmsg("Default number : \"%s\"\n",DecodeUnicodeConsole(smsc.DefaultNumber));
1269 printmsg("Format : ");
1270 switch (smsc.Format) {
1271 case GSMF_Text : printmsg("Text"); break;
1272 case GSMF_Fax : printmsg("Fax"); break;
1273 case GSMF_Email : printmsg("Email"); break;
1274 case GSMF_Pager : printmsg("Pager"); break;
1276 printf("\n");
1278 printmsg("Validity : ");
1279 switch (smsc.Validity.Relative) {
1280 case GSMV_1_Hour : printmsg("1 hour"); break;
1281 case GSMV_6_Hours : printmsg("6 hours"); break;
1282 case GSMV_24_Hours : printmsg("24 hours"); break;
1283 case GSMV_72_Hours : printmsg("72 hours"); break;
1284 case GSMV_1_Week : printmsg("1 week"); break;
1285 case GSMV_Max_Time : printmsg("Maximum time"); break;
1286 default : printmsg("Unknown");
1288 printf("\n");
1291 GSM_Terminate();
1294 static void GetSMS(int argc, char *argv[])
1296 GSM_MultiSMSMessage sms;
1297 GSM_SMSFolders folders;
1298 int start, stop;
1300 GetStartStop(&start, &stop, 3, argc, argv);
1302 GSM_Init(true);
1304 error=Phone->GetSMSFolders(&s, &folders);
1305 Print_Error(error);
1307 for (i=start;i<=stop;i++) {
1308 sms.SMS[0].Folder = atoi(argv[2]);
1309 sms.SMS[0].Location = i;
1310 error=Phone->GetSMS(&s, &sms);
1311 switch (error) {
1312 case GE_EMPTY:
1313 printmsg("Location %i\n",sms.SMS[0].Location);
1314 printmsg("Empty\n");
1315 break;
1316 default:
1317 Print_Error(error);
1318 printmsg("Location %i, folder \"%s\"",sms.SMS[0].Location,DecodeUnicodeConsole(folders.Folder[sms.SMS[0].Folder-1].Name));
1319 switch(sms.SMS[0].Memory) {
1320 case GMT_SM: printmsg(", SIM memory"); break;
1321 case GMT_ME: printmsg(", phone memory"); break;
1322 case GMT_MT: printmsg(", phone or SIM memory"); break;
1323 default : break;
1325 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder");
1326 printf("\n");
1327 displaymultismsinfo(sms,false,false);
1331 GSM_Terminate();
1334 static void DeleteSMS(int argc, char *argv[])
1336 GSM_SMSMessage sms;
1337 int start, stop;
1339 sms.Folder=atoi(argv[2]);
1341 GetStartStop(&start, &stop, 3, argc, argv);
1343 GSM_Init(true);
1345 for (i=start;i<=stop;i++) {
1346 sms.Folder = 0;
1347 sms.Location = i;
1348 error=Phone->DeleteSMS(&s, &sms);
1349 Print_Error(error);
1351 #ifdef GSM_ENABLE_BEEP
1352 GSM_PhoneBeep();
1353 #endif
1354 GSM_Terminate();
1357 static void GetAllSMS(int argc, char *argv[])
1359 GSM_MultiSMSMessage sms;
1360 GSM_SMSFolders folders;
1361 bool start = true;
1363 GSM_Init(true);
1365 error=Phone->GetSMSFolders(&s, &folders);
1366 Print_Error(error);
1368 fprintf(stderr,"Reading: ");
1369 while (error == GE_NONE) {
1370 sms.SMS[0].Folder=0x00;
1371 error=Phone->GetNextSMS(&s, &sms, start);
1372 switch (error) {
1373 case GE_EMPTY:
1374 break;
1375 default:
1376 Print_Error(error);
1377 printmsg("Location %i, folder \"%s\"",sms.SMS[0].Location,DecodeUnicodeConsole(folders.Folder[sms.SMS[0].Folder-1].Name));
1378 switch(sms.SMS[0].Memory) {
1379 case GMT_SM: printmsg(", SIM memory"); break;
1380 case GMT_ME: printmsg(", phone memory"); break;
1381 case GMT_MT: printmsg(", phone or SIM memory"); break;
1382 default : break;
1384 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder");
1385 printf("\n");
1386 displaymultismsinfo(sms,false,false);
1388 fprintf(stderr,"*");
1389 start=false;
1391 fprintf(stderr,"\n");
1393 #ifdef GSM_ENABLE_BEEP
1394 GSM_PhoneBeep();
1395 #endif
1396 GSM_Terminate();
1399 static void GetEachSMS(int argc, char *argv[])
1401 GSM_MultiSMSMessage *GetSMS[PHONE_MAXSMSINFOLDER],*SortedSMS[PHONE_MAXSMSINFOLDER],sms;
1402 int GetSMSNumber = 0,i,j;
1403 GSM_SMSFolders folders;
1404 bool start = true, ems = true;
1406 GetSMS[0] = NULL;
1408 GSM_Init(true);
1410 error=Phone->GetSMSFolders(&s, &folders);
1411 Print_Error(error);
1413 fprintf(stderr,"Reading: ");
1414 while (error == GE_NONE) {
1415 sms.SMS[0].Folder=0x00;
1416 error=Phone->GetNextSMS(&s, &sms, start);
1417 switch (error) {
1418 case GE_EMPTY:
1419 break;
1420 default:
1421 Print_Error(error);
1422 GetSMS[GetSMSNumber] = malloc(sizeof(GSM_MultiSMSMessage));
1423 if (GetSMS[GetSMSNumber] == NULL) Print_Error(GE_MOREMEMORY);
1424 GetSMS[GetSMSNumber+1] = NULL;
1425 memcpy(GetSMS[GetSMSNumber],&sms,sizeof(GSM_MultiSMSMessage));
1426 GetSMSNumber++;
1427 if (GetSMSNumber==PHONE_MAXSMSINFOLDER) {
1428 fprintf(stderr,"SMS counter overflow\n");
1429 return;
1432 fprintf(stderr,"*");
1433 start=false;
1435 fprintf(stderr,"\n");
1437 #ifdef GSM_ENABLE_BEEP
1438 GSM_PhoneBeep();
1439 #endif
1441 GSM_Terminate();
1443 error = GSM_LinkSMS(GetSMS, SortedSMS, ems);
1444 Print_Error(error);
1446 i=0;
1447 while(SortedSMS[i] != NULL) {
1448 if (SortedSMS[i] != NULL) {
1449 for (j=0;j<SortedSMS[i]->Number;j++) {
1450 if ((j==0) || (j!=0 && SortedSMS[i]->SMS[j].Location != SortedSMS[i]->SMS[j-1].Location)) {
1451 printmsg("Location %i, folder \"%s\"",SortedSMS[i]->SMS[j].Location,DecodeUnicodeConsole(folders.Folder[SortedSMS[i]->SMS[j].Folder-1].Name));
1452 switch(SortedSMS[i]->SMS[j].Memory) {
1453 case GMT_SM: printmsg(", SIM memory"); break;
1454 case GMT_ME: printmsg(", phone memory"); break;
1455 case GMT_MT: printmsg(", phone or SIM memory"); break;
1456 default : break;
1458 if (SortedSMS[i]->SMS[j].InboxFolder) printmsg(", Inbox folder");
1459 printf("\n");
1462 displaymultismsinfo(*SortedSMS[i],true,ems);
1464 i++;
1468 static void GetSMSFolders(int argc, char *argv[])
1470 GSM_SMSFolders folders;
1472 GSM_Init(true);
1474 error=Phone->GetSMSFolders(&s,&folders);
1475 Print_Error(error);
1477 for (i=0;i<folders.Number;i++) {
1478 printmsg("%i. \"%30s\"",i+1,DecodeUnicodeConsole(folders.Folder[i].Name));
1479 switch(folders.Folder[i].Memory) {
1480 case GMT_SM: printmsg(", SIM memory"); break;
1481 case GMT_ME: printmsg(", phone memory"); break;
1482 case GMT_MT: printmsg(", phone or SIM memory"); break;
1483 default : break;
1485 if (folders.Folder[i].InboxFolder) printmsg(", Inbox folder");
1486 printf("\n");
1489 GSM_Terminate();
1492 static void GetRingtone(int argc, char *argv[])
1494 GSM_Ringtone ringtone;
1495 bool PhoneRingtone = false;
1497 if (mystrncasecmp(argv[1],"--getphoneringtone",0)) PhoneRingtone = true;
1499 GetStartStop(&ringtone.Location, NULL, 2, argc, argv);
1501 GSM_Init(true);
1503 ringtone.Format=0;
1505 error=Phone->GetRingtone(&s,&ringtone,PhoneRingtone);
1506 Print_Error(error);
1508 switch (ringtone.Format) {
1509 case RING_NOTETONE : printmsg("Smart Messaging"); break;
1510 case RING_NOKIABINARY : printmsg("Nokia binary"); break;
1511 case RING_MIDI : printmsg("Midi format"); break;
1513 printmsg(" format, ringtone \"%s\"\n",DecodeUnicodeConsole(ringtone.Name));
1515 if (argc==4) {
1516 error=GSM_SaveRingtoneFile(argv[3], &ringtone);
1517 Print_Error(error);
1520 GSM_Terminate();
1523 static void GetRingtonesList(int argc, char *argv[])
1525 GSM_AllRingtonesInfo Info;
1526 int i;
1528 GSM_Init(true);
1530 error=Phone->GetRingtonesInfo(&s,&Info);
1531 Print_Error(error);
1533 GSM_Terminate();
1535 for (i=0;i<Info.Number;i++) printmsg("%i. \"%s\"\n",i,DecodeUnicodeConsole(Info.Ringtone[i].Name));
1538 static void DialVoice(int argc, char *argv[])
1540 GSM_CallShowNumber ShowNumber = GN_CALL_Default;
1542 if (argc > 3) {
1543 if (mystrncasecmp(argv[3],"show",0)) { ShowNumber = GN_CALL_ShowNumber;
1544 } else if (mystrncasecmp(argv[3],"hide",0)) { ShowNumber = GN_CALL_HideNumber;
1545 } else {
1546 printmsg("Unknown parameter (\"%s\")\n",argv[3]);
1547 exit(-1);
1551 GSM_Init(true);
1553 error=Phone->DialVoice(&s, argv[2], ShowNumber);
1554 Print_Error(error);
1556 GSM_Terminate();
1559 static void CancelCall(int argc, char *argv[])
1561 GSM_Init(true);
1563 if (argc>2) {
1564 error=Phone->CancelCall(&s,atoi(argv[2]),false);
1565 } else {
1566 error=Phone->CancelCall(&s,0,true);
1568 Print_Error(error);
1570 GSM_Terminate();
1573 static void AnswerCall(int argc, char *argv[])
1575 GSM_Init(true);
1577 if (argc>2) {
1578 error=Phone->AnswerCall(&s,atoi(argv[2]),false);
1579 } else {
1580 error=Phone->AnswerCall(&s,0,true);
1582 Print_Error(error);
1584 GSM_Terminate();
1587 static void UnholdCall(int argc, char *argv[])
1589 GSM_Init(true);
1591 error=Phone->UnholdCall(&s,atoi(argv[2]));
1592 Print_Error(error);
1594 GSM_Terminate();
1597 static void HoldCall(int argc, char *argv[])
1599 GSM_Init(true);
1601 error=Phone->HoldCall(&s,atoi(argv[2]));
1602 Print_Error(error);
1604 GSM_Terminate();
1607 static void ConferenceCall(int argc, char *argv[])
1609 GSM_Init(true);
1611 error=Phone->ConferenceCall(&s,atoi(argv[2]));
1612 Print_Error(error);
1614 GSM_Terminate();
1617 static void SplitCall(int argc, char *argv[])
1619 GSM_Init(true);
1621 error=Phone->SplitCall(&s,atoi(argv[2]));
1622 Print_Error(error);
1624 GSM_Terminate();
1627 static void SwitchCall(int argc, char *argv[])
1629 GSM_Init(true);
1631 if (argc > 2) {
1632 error=Phone->SwitchCall(&s,atoi(argv[2]),false);
1633 } else {
1634 error=Phone->SwitchCall(&s,0,true);
1636 Print_Error(error);
1638 GSM_Terminate();
1641 static void TransferCall(int argc, char *argv[])
1643 GSM_Init(true);
1645 if (argc > 2) {
1646 error=Phone->TransferCall(&s,atoi(argv[2]),false);
1647 } else {
1648 error=Phone->TransferCall(&s,0,true);
1650 Print_Error(error);
1652 GSM_Terminate();
1655 static void AddSMSFolder(int argc, char *argv[])
1657 unsigned char buffer[200];
1659 GSM_Init(true);
1661 EncodeUnicode(buffer,argv[2],strlen(argv[2]));
1662 error=Phone->AddSMSFolder(&s,buffer);
1663 Print_Error(error);
1665 GSM_Terminate();
1668 static void Reset(int argc, char *argv[])
1670 bool hard;
1672 if (mystrncasecmp(argv[2],"SOFT",0)) { hard=false;
1673 } else if (mystrncasecmp(argv[2],"HARD",0)) { hard=true;
1674 } else {
1675 printmsg("What type of reset do you want (\"%s\") ?\n",argv[2]);
1676 exit(-1);
1679 GSM_Init(true);
1681 error=Phone->Reset(&s, hard);
1682 Print_Error(error);
1684 GSM_Terminate();
1687 static void PrintCalendar(GSM_CalendarEntry *Note)
1689 int i_age = 0,i;
1690 GSM_DateTime Alarm,DateTime;
1691 GSM_MemoryEntry entry;
1692 unsigned char *name;
1694 bool repeating = false;
1695 int repeat_dayofweek = -1;
1696 int repeat_day = -1;
1697 int repeat_weekofmonth = -1;
1698 int repeat_month = -1;
1699 int repeat_frequency = -1;
1700 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
1701 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
1704 printmsg("Location : %d\n", Note->Location);
1705 printmsg("Note type : ");
1706 switch (Note->Type) {
1707 case GCN_REMINDER : printmsg("Reminder (Date)\n"); break;
1708 case GCN_CALL : printmsg("Call\n"); break;
1709 case GCN_MEETING : printmsg("Meeting\n"); break;
1710 case GCN_BIRTHDAY : printmsg("Birthday (Anniversary)\n"); break;
1711 case GCN_MEMO : printmsg("Memo (Miscellaneous)\n"); break;
1712 case GCN_TRAVEL : printmsg("Travel\n"); break;
1713 case GCN_VACATION : printmsg("Vacation\n"); break;
1714 case GCN_ALARM : printmsg("Alarm\n"); break;
1715 case GCN_DAILY_ALARM : printmsg("Daily alarm\n"); break;
1716 case GCN_T_ATHL : printmsg("Training/Athletism\n"); break;
1717 case GCN_T_BALL : printmsg("Training/Ball Games\n"); break;
1718 case GCN_T_CYCL : printmsg("Training/Cycling\n"); break;
1719 case GCN_T_BUDO : printmsg("Training/Budo\n"); break;
1720 case GCN_T_DANC : printmsg("Training/Dance\n"); break;
1721 case GCN_T_EXTR : printmsg("Training/Extreme Sports\n"); break;
1722 case GCN_T_FOOT : printmsg("Training/Football\n"); break;
1723 case GCN_T_GOLF : printmsg("Training/Golf\n"); break;
1724 case GCN_T_GYM : printmsg("Training/Gym\n"); break;
1725 case GCN_T_HORS : printmsg("Training/Horse Races\n"); break;
1726 case GCN_T_HOCK : printmsg("Training/Hockey\n"); break;
1727 case GCN_T_RACE : printmsg("Training/Races\n"); break;
1728 case GCN_T_RUGB : printmsg("Training/Rugby\n"); break;
1729 case GCN_T_SAIL : printmsg("Training/Sailing\n"); break;
1730 case GCN_T_STRE : printmsg("Training/Street Games\n"); break;
1731 case GCN_T_SWIM : printmsg("Training/Swimming\n"); break;
1732 case GCN_T_TENN : printmsg("Training/Tennis\n"); break;
1733 case GCN_T_TRAV : printmsg("Training/Travels\n"); break;
1734 case GCN_T_WINT : printmsg("Training/Winter Games\n"); break;
1735 default : printmsg("UNKNOWN\n");
1737 Alarm.Year = 0;
1739 repeating = false;
1740 repeat_dayofweek = -1;
1741 repeat_day = -1;
1742 repeat_weekofmonth = -1;
1743 repeat_month = -1;
1744 repeat_frequency = -1;
1745 repeat_startdate.Day = 0;
1746 repeat_stopdate.Day = 0;
1748 for (i=0;i<Note->EntriesNum;i++) {
1749 switch (Note->Entries[i].EntryType) {
1750 case CAL_START_DATETIME:
1751 printmsg("Start : %s\n",OSDateTime(Note->Entries[i].Date,false));
1752 memcpy(&DateTime,&Note->Entries[i].Date,sizeof(GSM_DateTime));
1753 break;
1754 case CAL_END_DATETIME:
1755 printmsg("Stop : %s\n",OSDateTime(Note->Entries[i].Date,false));
1756 memcpy(&DateTime,&Note->Entries[i].Date,sizeof(GSM_DateTime));
1757 break;
1758 case CAL_ALARM_DATETIME:
1759 printmsg("Tone alarm : %s\n",OSDateTime(Note->Entries[i].Date,false));
1760 memcpy(&Alarm,&Note->Entries[i].Date,sizeof(GSM_DateTime));
1761 break;
1762 case CAL_SILENT_ALARM_DATETIME:
1763 printmsg("Silent alarm : %s\n",OSDateTime(Note->Entries[i].Date,false));
1764 memcpy(&Alarm,&Note->Entries[i].Date,sizeof(GSM_DateTime));
1765 break;
1766 case CAL_RECURRANCE:
1767 printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,
1768 ((Note->Entries[i].Number/24)>1) ? "s":"" );
1769 break;
1770 case CAL_TEXT:
1771 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
1772 break;
1773 case CAL_LOCATION:
1774 printmsg("Location : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
1775 break;
1776 case CAL_PHONE:
1777 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
1778 break;
1779 case CAL_PRIVATE:
1780 printmsg("Private : %s\n",Note->Entries[i].Number == 1 ? "Yes" : "No");
1781 break;
1782 case CAL_CONTACTID:
1783 entry.Location = Note->Entries[i].Number;
1784 entry.MemoryType = GMT_ME;
1785 error=Phone->GetMemory(&s, &entry);
1786 if (error == GE_NONE) {
1787 name = GSM_PhonebookGetEntryName(&entry);
1788 if (name != NULL) {
1789 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
1790 } else {
1791 printmsg("Contact ID : %d\n",Note->Entries[i].Number);
1793 } else {
1794 printmsg("Contact ID : %d\n",Note->Entries[i].Number);
1796 break;
1797 case CAL_REPEAT_DAYOFWEEK:
1798 repeat_dayofweek = Note->Entries[i].Number;
1799 repeating = true;
1800 break;
1801 case CAL_REPEAT_DAY:
1802 repeat_day = Note->Entries[i].Number;
1803 repeating = true;
1804 break;
1805 case CAL_REPEAT_WEEKOFMONTH:
1806 repeat_weekofmonth = Note->Entries[i].Number;
1807 repeating = true;
1808 break;
1809 case CAL_REPEAT_MONTH:
1810 repeat_month = Note->Entries[i].Number;
1811 repeating = true;
1812 break;
1813 case CAL_REPEAT_FREQUENCY:
1814 repeat_frequency = Note->Entries[i].Number;
1815 repeating = true;
1816 break;
1817 case CAL_REPEAT_STARTDATE:
1818 repeat_startdate = Note->Entries[i].Date;
1819 repeating = true;
1820 break;
1821 case CAL_REPEAT_STOPDATE:
1822 repeat_stopdate = Note->Entries[i].Date;
1823 repeating = true;
1824 break;
1827 if (repeating) {
1828 printmsg("Repeating : ");
1829 if ((repeat_startdate.Day == 0) && (repeat_stopdate.Day == 0)) {
1830 printmsg("Forever");
1831 } else if (repeat_startdate.Day == 0) {
1832 printmsg("Till %s", OSDate(repeat_stopdate));
1833 } else if (repeat_stopdate.Day == 0) {
1834 printmsg("Since %s", OSDate(repeat_startdate));
1835 } else {
1836 printmsg("Since %s till %s", OSDate(repeat_startdate), OSDate(repeat_stopdate));
1838 if (repeat_frequency != -1) {
1839 if (repeat_frequency == 1) {
1840 printmsg (" on each ");
1841 } else {
1842 printmsg(" on each %d. ", repeat_frequency);
1844 if (repeat_dayofweek > 0) {
1845 switch (repeat_dayofweek) {
1846 case 1 : printmsg("Monday"); break;
1847 case 2 : printmsg("Tuesday"); break;
1848 case 3 : printmsg("Wednesday"); break;
1849 case 4 : printmsg("Thursday"); break;
1850 case 5 : printmsg("Friday"); break;
1851 case 6 : printmsg("Saturday"); break;
1852 case 7 : printmsg("Sunday"); break;
1853 default: printmsg("Bad day!"); break;
1855 if (repeat_weekofmonth > 0) {
1856 printmsg(" in %d. week of ", repeat_weekofmonth);
1857 } else {
1858 printmsg(" in ");
1860 if (repeat_month > 0) {
1861 switch(repeat_month) {
1862 case 1 : printmsg("January"); break;
1863 case 2 : printmsg("February"); break;
1864 case 3 : printmsg("March"); break;
1865 case 4 : printmsg("April"); break;
1866 case 5 : printmsg("May"); break;
1867 case 6 : printmsg("June"); break;
1868 case 7 : printmsg("July"); break;
1869 case 8 : printmsg("August"); break;
1870 case 9 : printmsg("September"); break;
1871 case 10: printmsg("October"); break;
1872 case 11: printmsg("November"); break;
1873 case 12: printmsg("December"); break;
1874 default: printmsg("Bad month!"); break;
1876 } else {
1877 printmsg("each month");
1879 } else if (repeat_day > 0) {
1880 printmsg("%d. day of ", repeat_day);
1881 if (repeat_month > 0) {
1882 switch(repeat_month) {
1883 case 1 : printmsg("January"); break;
1884 case 2 : printmsg("February"); break;
1885 case 3 : printmsg("March"); break;
1886 case 4 : printmsg("April"); break;
1887 case 5 : printmsg("May"); break;
1888 case 6 : printmsg("June"); break;
1889 case 7 : printmsg("July"); break;
1890 case 8 : printmsg("August"); break;
1891 case 9 : printmsg("September"); break;
1892 case 10: printmsg("October"); break;
1893 case 11: printmsg("November"); break;
1894 case 12: printmsg("December"); break;
1895 default: printmsg("Bad month!");break;
1897 } else {
1898 printmsg("each month");
1900 } else {
1901 printmsg("day");
1904 printf("\n");
1906 if (Note->Type == GCN_BIRTHDAY) {
1907 if (Alarm.Year == 0x00) GSM_GetCurrentDateTime (&Alarm);
1908 if (DateTime.Year != 0) {
1909 i_age = Alarm.Year - DateTime.Year;
1910 if (DateTime.Month < Alarm.Month) i_age++;
1911 if (DateTime.Month == Alarm.Month &&
1912 DateTime.Day < Alarm.Day) {
1913 i_age++;
1915 printmsg("Age : %d %s\n",i_age, (i_age==1)?"year":"years");
1918 printf("\n");
1921 static void GetCalendar(int argc, char *argv[])
1923 GSM_CalendarEntry Note;
1924 int start,stop;
1926 GetStartStop(&start, &stop, 2, argc, argv);
1928 GSM_Init(true);
1930 for (i=start;i<=stop;i++) {
1931 Note.Location=i;
1932 error = Phone->GetCalendar(&s, &Note);
1933 if (error == GE_EMPTY) continue;
1934 Print_Error(error);
1935 PrintCalendar(&Note);
1938 GSM_Terminate();
1941 static void DeleteCalendar(int argc, char *argv[])
1943 GSM_CalendarEntry Note;
1944 int start,stop;
1946 GetStartStop(&start, &stop, 2, argc, argv);
1948 GSM_Init(true);
1950 for (i=start;i<=stop;i++) {
1951 Note.Location=i;
1952 error = Phone->DeleteCalendar(&s, &Note);
1953 if (error == GE_EMPTY) continue;
1954 Print_Error(error);
1955 PrintCalendar(&Note);
1958 GSM_Terminate();
1962 static void GetAllCalendar(int argc, char *argv[])
1964 GSM_CalendarEntry Note;
1965 bool refresh = true;
1967 GSM_Init(true);
1969 while (1) {
1970 error=Phone->GetNextCalendar(&s,&Note,refresh);
1971 if (error == GE_EMPTY) break;
1972 PrintCalendar(&Note);
1973 Print_Error(error);
1974 refresh=false;
1977 GSM_Terminate();
1980 static void GetCalendarSettings(int argc, char *argv[])
1982 GSM_CalendarSettings settings;
1984 GSM_Init(true);
1986 error=Phone->GetCalendarSettings(&s,&settings);
1987 Print_Error(error);
1989 if (settings.AutoDelete == 0) {
1990 printmsg("Auto deleting disabled");
1991 } else {
1992 printmsg("Auto deleting notes after %i day(s)",settings.AutoDelete);
1994 printmsg("\nWeek start on ");
1995 switch(settings.StartDay) {
1996 case 1: printmsg("Monday"); break;
1997 case 6: printmsg("Saturday"); break;
1998 case 7: printmsg("Sunday"); break;
2000 printf("\n");
2002 GSM_Terminate();
2005 static void GetWAPBookmark(int argc, char *argv[])
2007 GSM_WAPBookmark bookmark;
2008 int start,stop;
2010 GetStartStop(&start, &stop, 2, argc, argv);
2012 GSM_Init(true);
2014 for (i=start;i<=stop;i++) {
2015 bookmark.Location=i;
2016 error=Phone->GetWAPBookmark(&s,&bookmark);
2017 Print_Error(error);
2018 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(bookmark.Title));
2019 printmsg("Address : \"%s\"\n",DecodeUnicodeConsole(bookmark.Address));
2022 GSM_Terminate();
2025 static void DeleteWAPBookmark(int argc, char *argv[])
2027 GSM_WAPBookmark bookmark;
2028 int start, stop;
2030 GetStartStop(&start, &stop, 2, argc, argv);
2032 GSM_Init(true);
2034 for (i=start;i<=stop;i++) {
2035 bookmark.Location=i;
2036 error=Phone->DeleteWAPBookmark(&s, &bookmark);
2037 Print_Error(error);
2040 GSM_Terminate();
2043 static void GetGPRSPoint(int argc, char *argv[])
2045 GSM_GPRSAccessPoint point;
2046 int start,stop;
2048 GetStartStop(&start, &stop, 2, argc, argv);
2050 GSM_Init(true);
2052 for (i=start;i<=stop;i++) {
2053 point.Location=i;
2054 error=Phone->GetGPRSAccessPoint(&s,&point);
2055 if (error != GE_EMPTY) {
2056 Print_Error(error);
2057 printmsg("%i. \"%s\"",point.Location,DecodeUnicodeConsole(point.Name));
2058 } else {
2059 printmsg("%i. Access point %i",point.Location,point.Location);
2061 if (point.Active) printmsg(" (active)");
2062 if (error != GE_EMPTY) {
2063 printmsg("\nAddress : \"%s\"\n\n",DecodeUnicodeConsole(point.URL));
2064 } else {
2065 printmsg("\n\n");
2069 GSM_Terminate();
2072 static void GetBitmap(int argc, char *argv[])
2074 GSM_MultiBitmap MultiBitmap;
2075 int location=0;
2076 GSM_AllRingtonesInfo Info;
2078 if (mystrncasecmp(argv[2],"STARTUP",0)) {
2079 MultiBitmap.Bitmap[0].Type=GSM_StartupLogo;
2080 } else if (mystrncasecmp(argv[2],"CALLER",0)) {
2081 MultiBitmap.Bitmap[0].Type=GSM_CallerLogo;
2082 GetStartStop(&location, NULL, 3, argc, argv);
2083 if (location>5) {
2084 printmsg("Maximal location for caller logo can be 5\n");
2085 exit (-1);
2087 } else if (mystrncasecmp(argv[2],"PICTURE",0)) {
2088 MultiBitmap.Bitmap[0].Type=GSM_PictureImage;
2089 GetStartStop(&location, NULL, 3, argc, argv);
2090 } else if (mystrncasecmp(argv[2],"TEXT",0)) {
2091 MultiBitmap.Bitmap[0].Type=GSM_WelcomeNoteText;
2092 } else if (mystrncasecmp(argv[2],"DEALER",0)) {
2093 MultiBitmap.Bitmap[0].Type=GSM_DealerNoteText;
2094 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) {
2095 MultiBitmap.Bitmap[0].Type=GSM_OperatorLogo;
2096 } else {
2097 printmsg("What type of logo do you want to get (\"%s\") ?\n",argv[2]);
2098 exit(-1);
2100 MultiBitmap.Bitmap[0].Location=location;
2102 GSM_Init(true);
2104 error=Phone->GetBitmap(&s,&MultiBitmap.Bitmap[0]);
2105 Print_Error(error);
2107 MultiBitmap.Number = 1;
2109 error=GE_NONE;
2110 switch (MultiBitmap.Bitmap[0].Type) {
2111 case GSM_CallerLogo:
2112 if (!MultiBitmap.Bitmap[0].DefaultBitmap) GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2113 printmsg("Group name : \"%s\"",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2114 if (MultiBitmap.Bitmap[0].DefaultName) printmsg(" (default)");
2115 printf("\n");
2116 if (MultiBitmap.Bitmap[0].DefaultRingtone) {
2117 printmsg("Ringtone : default\n");
2118 } else {
2119 error = Phone->GetRingtonesInfo(&s,&Info);
2120 if (error != GE_NONE) Info.Number = 0;
2121 error = GE_NONE;
2123 printmsg("Ringtone : ");
2124 if (UnicodeLength(GSM_GetRingtoneName(&Info,MultiBitmap.Bitmap[0].Ringtone))!=0) {
2125 printmsg("\"%s\"\n",DecodeUnicodeConsole(GSM_GetRingtoneName(&Info,MultiBitmap.Bitmap[0].Ringtone)));
2126 } else {
2127 printmsg("%i\n",MultiBitmap.Bitmap[0].Ringtone);
2130 if (MultiBitmap.Bitmap[0].Enabled) {
2131 printmsg("Bitmap : enabled\n");
2132 } else {
2133 printmsg("Bitmap : disabled\n");
2135 if (argc>4 && !MultiBitmap.Bitmap[0].DefaultBitmap) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap);
2136 break;
2137 case GSM_StartupLogo:
2138 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2139 if (argc>3) error=GSM_SaveBitmapFile(argv[3],&MultiBitmap);
2140 break;
2141 case GSM_OperatorLogo:
2142 if (strcmp(MultiBitmap.Bitmap[0].NetworkCode,"000 00")!=0) {
2143 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2144 if (argc>3) error=GSM_SaveBitmapFile(argv[3],&MultiBitmap);
2145 } else {
2146 printmsg("No operator logo in phone\n");
2148 break;
2149 case GSM_PictureImage:
2150 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2151 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2152 printmsg("Sender : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Sender));
2153 if (argc>4) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap);
2154 break;
2155 case GSM_WelcomeNoteText:
2156 printmsg("Welcome note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2157 break;
2158 case GSM_DealerNoteText:
2159 printmsg("Dealer note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2160 break;
2161 default:
2162 break;
2164 Print_Error(error);
2166 GSM_Terminate();
2169 static void SetBitmap(int argc, char *argv[])
2171 GSM_Bitmap Bitmap, NewBitmap;
2172 GSM_MultiBitmap MultiBitmap;
2173 GSM_NetworkInfo NetInfo;
2174 bool init = true;
2176 if (mystrncasecmp(argv[2],"STARTUP",0)) {
2177 if (argc<4) {
2178 printmsg("More arguments required\n");
2179 exit(-1);
2181 MultiBitmap.Bitmap[0].Type=GSM_StartupLogo;
2182 MultiBitmap.Bitmap[0].Location=1;
2183 if (!strcmp(argv[3],"1")) MultiBitmap.Bitmap[0].Location = 2;
2184 if (!strcmp(argv[3],"2")) MultiBitmap.Bitmap[0].Location = 3;
2185 if (!strcmp(argv[3],"3")) MultiBitmap.Bitmap[0].Location = 4;
2186 if (MultiBitmap.Bitmap[0].Location == 1) {
2187 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap);
2188 Print_Error(error);
2190 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2191 } else if (mystrncasecmp(argv[2],"TEXT",0)) {
2192 if (argc<4) {
2193 printmsg("More arguments required\n");
2194 exit(-1);
2196 Bitmap.Type=GSM_WelcomeNoteText;
2197 EncodeUnicode(Bitmap.Text,argv[3],strlen(argv[3]));
2198 } else if (mystrncasecmp(argv[2],"DEALER",0)) {
2199 if (argc<4) {
2200 printmsg("More arguments required\n");
2201 exit(-1);
2203 Bitmap.Type=GSM_DealerNoteText;
2204 EncodeUnicode(Bitmap.Text,argv[3],strlen(argv[3]));
2205 } else if (mystrncasecmp(argv[2],"CALLER",0)) {
2206 if (argc<4) {
2207 printmsg("More arguments required\n");
2208 exit(-1);
2210 GetStartStop(&i, NULL, 3, argc, argv);
2211 if (i>5 && i!=255) {
2212 printmsg("Maximal location for caller logo can be 5\n");
2213 exit (-1);
2215 MultiBitmap.Bitmap[0].Type = GSM_CallerLogo;
2216 MultiBitmap.Bitmap[0].Location = i;
2217 if (argc>4) {
2218 error=GSM_ReadBitmapFile(argv[4],&MultiBitmap);
2219 Print_Error(error);
2221 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2222 if (i!=255) {
2223 GSM_Init(true);
2224 init = false;
2225 NewBitmap.Type = GSM_CallerLogo;
2226 NewBitmap.Location = i;
2227 error=Phone->GetBitmap(&s,&NewBitmap);
2228 Print_Error(error);
2229 Bitmap.Ringtone = NewBitmap.Ringtone;
2230 Bitmap.DefaultRingtone = NewBitmap.DefaultRingtone;
2231 CopyUnicodeString(Bitmap.Text, NewBitmap.Text);
2232 Bitmap.DefaultName = NewBitmap.DefaultName;
2234 } else if (mystrncasecmp(argv[2],"PICTURE",0)) {
2235 if (argc<5) {
2236 printmsg("More arguments required\n");
2237 exit(-1);
2239 MultiBitmap.Bitmap[0].Type = GSM_PictureImage;
2240 MultiBitmap.Bitmap[0].Location = atoi(argv[4]);
2241 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap);
2242 Print_Error(error);
2243 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2244 Bitmap.Text[0]=0;
2245 Bitmap.Text[1]=0;
2246 if (argc == 6) EncodeUnicode(Bitmap.Text,argv[5],strlen(argv[5]));
2247 Bitmap.Sender[0]=0;
2248 Bitmap.Sender[1]=0;
2249 } else if (mystrncasecmp(argv[2],"COLOUROPERATOR",0)) {
2250 Bitmap.Type = GSM_ColourOperatorLogo;
2251 strcpy(Bitmap.NetworkCode,"000 00");
2252 if (argc > 3) {
2253 Bitmap.ID = atoi(argv[3]);
2254 if (argc>4) {
2255 strncpy(Bitmap.NetworkCode,argv[4],6);
2256 } else {
2257 GSM_Init(true);
2258 init = false;
2259 error=Phone->GetNetworkInfo(&s,&NetInfo);
2260 Print_Error(error);
2261 strcpy(Bitmap.NetworkCode,NetInfo.NetworkCode);
2264 } else if (mystrncasecmp(argv[2],"COLOURSTARTUP",0)) {
2265 Bitmap.Type = GSM_ColourStartupLogo;
2266 Bitmap.Location = 0;
2267 if (argc > 3) {
2268 Bitmap.Location = 1;
2269 Bitmap.ID = atoi(argv[3]);
2271 } else if (mystrncasecmp(argv[2],"WALLPAPER",0)) {
2272 Bitmap.Type = GSM_ColourWallPaper;
2273 Bitmap.ID = 0;
2274 if (argc > 3) Bitmap.ID = atoi(argv[3]);
2275 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) {
2276 MultiBitmap.Bitmap[0].Type = GSM_OperatorLogo;
2277 MultiBitmap.Bitmap[0].Location = 1;
2278 strcpy(MultiBitmap.Bitmap[0].NetworkCode,"000 00");
2279 if (argc>3) {
2280 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap);
2281 Print_Error(error);
2282 if (argc>4) {
2283 strncpy(MultiBitmap.Bitmap[0].NetworkCode,argv[4],6);
2284 } else {
2285 GSM_Init(true);
2286 init = false;
2287 error=Phone->GetNetworkInfo(&s,&NetInfo);
2288 Print_Error(error);
2289 strcpy(MultiBitmap.Bitmap[0].NetworkCode,NetInfo.NetworkCode);
2292 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2293 } else {
2294 printmsg("What type of logo do you want to set (\"%s\") ?\n",argv[2]);
2295 exit(-1);
2298 if (init) GSM_Init(true);
2300 error=Phone->SetBitmap(&s,&Bitmap);
2301 Print_Error(error);
2303 #ifdef GSM_ENABLE_BEEP
2304 GSM_PhoneBeep();
2305 #endif
2307 GSM_Terminate();
2310 static void SetRingtone(int argc, char *argv[])
2312 GSM_Ringtone ringtone;
2313 int i,nextlong=0;
2315 ringtone.Format = 0;
2316 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
2317 Print_Error(error);
2318 ringtone.Location = 255;
2319 for (i=3;i<argc;i++) {
2320 switch (nextlong) {
2321 case 0:
2322 if (mystrncasecmp(argv[i],"-scale",0)) {
2323 ringtone.NoteTone.AllNotesScale = true;
2324 break;
2326 if (mystrncasecmp(argv[i],"-location",0)) {
2327 nextlong = 1;
2328 break;
2330 if (mystrncasecmp(argv[i],"-name",0)) {
2331 nextlong = 2;
2332 break;
2334 printmsg("Unknown parameter \"%s\"",argv[i]);
2335 exit(-1);
2336 case 1:
2337 ringtone.Location=atoi(argv[i]);
2338 nextlong = 0;
2339 break;
2340 case 2:
2341 EncodeUnicode(ringtone.Name,argv[i],strlen(argv[i]));
2342 nextlong = 0;
2343 break;
2346 if (nextlong!=0) {
2347 printmsg("Parameter missed...\n");
2348 exit(-1);
2350 if (ringtone.Location==0) {
2351 printmsg("ERROR: enumerate locations from 1\n");
2352 exit (-1);
2355 GSM_Init(true);
2356 error=Phone->SetRingtone(&s, &ringtone, &i);
2357 Print_Error(error);
2358 #ifdef GSM_ENABLE_BEEP
2359 GSM_PhoneBeep();
2360 #endif
2361 GSM_Terminate();
2364 static void DisplaySMSFrame(GSM_SMSMessage *SMS)
2366 GSM_Error error;
2367 int i, length, current = 0;
2368 unsigned char req[1000], buffer[1000], hexreq[1000];
2370 error=PHONE_EncodeSMSFrame(&s,SMS,buffer,PHONE_SMSSubmit,&length,true);
2371 if (error != GE_NONE) {
2372 printmsg("Error\n");
2373 exit(-1);
2375 #ifdef OSCAR
2376 length = length - PHONE_SMSSubmit.Text;
2378 printf("<?xml version=\"1.0\"?>\n");
2379 printf("<msgbatch batchid=\"10014\">\n");
2380 /*?*/ printf("<message id=\"235\" commit=\"ACK\" ");
2381 /*?*/ printf("prio=\"0\" rn=\"NO\" ");
2382 /*?*/ printf("type=\"MT\" ver=\"1.0\" ttl=\"100\">\n");
2384 /* Sender */
2385 printf("<from>\n");
2386 printf("<shortCodeAddress sc=\"%s\"/>\n",DecodeUnicodeString(SMS->SMSC.Number));
2387 printf("</from>\n");
2389 /* Destination */
2390 printf("<to>\n");
2391 printf("<msisdnAddress msisdn=\"%s\" />\n",DecodeUnicodeString(SMS->Number));
2392 printf("</to>\n");
2394 printf("<content type=\"SMS\">\n");
2395 /*?*/ printf("<ucp51 trn=\"10\">\n");
2397 /* SMS Text (without UDH) */
2398 for(i=SMS->UDH.Length;i<length;i++) req[i-SMS->UDH.Length]=buffer[PHONE_SMSSubmit.Text+i];
2399 EncodeHexBin(hexreq, req, length-SMS->UDH.Length);
2400 printf("<msg mt=\"TD\">%s</msg>\n",hexreq);
2402 /*?*/ printf("<mcls>1</mcls>\n");
2404 /* Length of SMS Text (without UDH) in bits */
2405 printf("<nb>%i</nb>\n",(buffer[PHONE_SMSSubmit.TPUDL]-SMS->UDH.Length)*8);
2406 printf("<xser>\n");
2408 /* UDH */
2409 printf("<dcs>1</dcs>\n");
2410 for(i=0;i<SMS->UDH.Length;i++) req[i]=buffer[PHONE_SMSSubmit.Text+i];
2411 EncodeHexBin(hexreq, req, SMS->UDH.Length);
2412 printf("<udh>%s</udh>\n",hexreq);
2414 printf("</xser>\n");
2415 printf("</ucp51>\n");
2416 printf("</content>\n");
2417 printf("</message>\n");
2418 printf("</msgbatch>\n");
2419 #else
2420 length = length - PHONE_SMSSubmit.Text;
2421 for (i=0;i<buffer[PHONE_SMSSubmit.SMSCNumber]+1;i++) {
2422 req[current++]=buffer[PHONE_SMSSubmit.SMSCNumber+i];
2424 req[current++]=buffer[PHONE_SMSSubmit.firstbyte];
2425 req[current++]=buffer[PHONE_SMSSubmit.TPMR];
2426 for (i=0;i<((buffer[PHONE_SMSSubmit.Number]+1)/2+1)+1;i++) {
2427 req[current++]=buffer[PHONE_SMSSubmit.Number+i];
2429 req[current++]=buffer[PHONE_SMSSubmit.TPPID];
2430 req[current++]=buffer[PHONE_SMSSubmit.TPDCS];
2431 req[current++]=buffer[PHONE_SMSSubmit.TPVP];
2432 req[current++]=buffer[PHONE_SMSSubmit.TPUDL];
2433 for(i=0;i<length;i++) req[current++]=buffer[PHONE_SMSSubmit.Text+i];
2434 EncodeHexBin(hexreq, req, current);
2435 printmsg("%s\n\n",hexreq);
2436 #endif
2439 #define SEND_SAVE_SMS_BUFFER_SIZE 10000
2441 static GSM_Error SMSStatus;
2443 static void SendSMSStatus (char *Device, int status)
2445 dbgprintf("Incoming SMS device: \"%s\"\n",Device);
2446 if (status==0) {
2447 printmsg("..OK\n");
2448 SMSStatus = GE_NONE;
2449 } else {
2450 printmsg("..error %i\n",status);
2451 SMSStatus = GE_UNKNOWN;
2455 static void SendSaveDisplaySMS(int argc, char *argv[])
2457 #ifdef GSM_ENABLE_BACKUP
2458 GSM_Backup Backup;
2459 #endif
2460 int i,j,z,FramesNum = 0;
2461 int Protected = 0;
2462 GSM_SMSFolders folders;
2463 GSM_MultiSMSMessage sms;
2464 GSM_Ringtone ringtone[MAX_MULTI_SMS];
2465 GSM_MultiBitmap bitmap[MAX_MULTI_SMS],bitmap2;
2466 GSM_EncodeMultiPartSMSInfo SMSInfo;
2467 GSM_NetworkInfo NetInfo;
2468 GSM_MMSIndicator MMSInfo;
2469 FILE *ReplaceFile,*f;
2470 char ReplaceBuffer2 [200],ReplaceBuffer[200];
2471 char InputBuffer [SEND_SAVE_SMS_BUFFER_SIZE/2+1];
2472 char Buffer [MAX_MULTI_SMS][SEND_SAVE_SMS_BUFFER_SIZE];
2473 char Sender [(GSM_MAX_NUMBER_LENGTH+1)*2];
2474 char Name [(GSM_MAX_NUMBER_LENGTH+1)*2];
2475 char SMSC [(GSM_MAX_NUMBER_LENGTH+1)*2];
2476 int startarg = 0;
2477 int chars_read = 0;
2478 int nextlong = 0;
2479 bool ReplyViaSameSMSC = false;
2480 int SMSCSet = 1;
2481 int MaxSMS = -1;
2482 bool EMS16Bit = false;
2484 /* Parameters required only during saving */
2485 int Folder = 1; /*Inbox by default */
2486 GSM_SMS_State State = GSM_Sent;
2488 /* Required only during sending */
2489 GSM_SMSValidity Validity;
2490 GSM_SMSC PhoneSMSC;
2491 bool DeliveryReport = false;
2493 ReplaceBuffer[0] = 0;
2494 ReplaceBuffer[1] = 0;
2495 GSM_ClearMultiPartSMSInfo(&SMSInfo);
2496 SMSInfo.ReplaceMessage = 0;
2497 SMSInfo.EntriesNum = 1;
2499 if (mystrncasecmp(argv[1],"--savesms",0)) {
2500 EncodeUnicode(Sender,"Gammu",5);
2501 Name[0] = 0;
2502 Name[1] = 0;
2503 startarg = 0;
2504 } else {
2505 EncodeUnicode(Sender,argv[3],strlen(argv[3]));
2506 startarg = 1;
2507 Validity.VPF = 0;
2510 if (mystrncasecmp(argv[2],"TEXT",0)) {
2511 chars_read = fread(InputBuffer, 1, SEND_SAVE_SMS_BUFFER_SIZE/2, stdin);
2512 if (chars_read == 0) printmsg("Warning: 0 chars read !\n");
2513 InputBuffer[chars_read] = 0x00;
2514 InputBuffer[chars_read+1] = 0x00;
2515 EncodeUnicode(Buffer[0],InputBuffer,strlen(InputBuffer));
2516 SMSInfo.Entries[0].Buffer = Buffer[0];
2517 SMSInfo.Entries[0].ID = SMS_Text;
2518 SMSInfo.UnicodeCoding = false;
2519 SMSInfo.Class = -1;
2520 startarg += 3;
2521 } else if (mystrncasecmp(argv[2],"EMS",0)) {
2522 SMSInfo.UnicodeCoding = false;
2523 SMSInfo.EntriesNum = 0;
2524 startarg += 3;
2525 } else if (mystrncasecmp(argv[2],"MMSINDICATOR",0)) {
2526 if (argc<6+startarg) {
2527 printmsg("Where is ringtone filename ?\n");
2528 exit(-1);
2530 SMSInfo.Entries[0].ID = SMS_MMSIndicatorLong;
2531 SMSInfo.Entries[0].MMSIndicator = &MMSInfo;
2532 if (mystrncasecmp(argv[1],"--savesms",0)) {
2533 EncodeUnicode(Sender,"MMS Info",8);
2535 strcpy(MMSInfo.Address, argv[3+startarg]);
2536 strcpy(MMSInfo.Title, argv[4+startarg]);
2537 strcpy(MMSInfo.Sender, argv[5+startarg]);
2538 startarg += 6;
2539 } else if (mystrncasecmp(argv[2],"RINGTONE",0)) {
2540 if (argc<4+startarg) {
2541 printmsg("Where is ringtone filename ?\n");
2542 exit(-1);
2544 ringtone[0].Format=RING_NOTETONE;
2545 error=GSM_ReadRingtoneFile(argv[3+startarg],&ringtone[0]);
2546 Print_Error(error);
2547 SMSInfo.Entries[0].ID = SMS_NokiaRingtone;
2548 SMSInfo.Entries[0].Ringtone = &ringtone[0];
2549 if (mystrncasecmp(argv[1],"--savesms",0)) {
2550 CopyUnicodeString(Sender, ringtone[0].Name);
2551 EncodeUnicode(Name,"Ringtone ",9);
2552 CopyUnicodeString(Name+9*2, ringtone[0].Name);
2554 startarg += 4;
2555 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) {
2556 if (argc<4+startarg) {
2557 printmsg("Where is logo filename ?\n");
2558 exit(-1);
2560 bitmap[0].Bitmap[0].Type=GSM_OperatorLogo;
2561 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]);
2562 Print_Error(error);
2563 strcpy(bitmap[0].Bitmap[0].NetworkCode,"000 00");
2564 SMSInfo.Entries[0].ID = SMS_NokiaOperatorLogo;
2565 SMSInfo.Entries[0].Bitmap = &bitmap[0];
2566 if (mystrncasecmp(argv[1],"--savesms",0)) {
2567 EncodeUnicode(Sender, "OpLogo",6);
2568 EncodeUnicode(Name,"OpLogo ",7);
2570 startarg += 4;
2571 } else if (mystrncasecmp(argv[2],"CALLER",0)) {
2572 if (argc<4+startarg) {
2573 printmsg("Where is logo filename ?\n");
2574 exit(-1);
2576 bitmap[0].Bitmap[0].Type=GSM_CallerLogo;
2577 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]);
2578 Print_Error(error);
2579 SMSInfo.Entries[0].ID = SMS_NokiaCallerLogo;
2580 SMSInfo.Entries[0].Bitmap = &bitmap[0];
2581 if (mystrncasecmp(argv[1],"--savesms",0)) {
2582 EncodeUnicode(Sender, "Caller",6);
2584 startarg += 4;
2585 } else if (mystrncasecmp(argv[2],"PICTURE",0)) {
2586 if (argc<4+startarg) {
2587 printmsg("Where is logo filename ?\n");
2588 exit(-1);
2590 bitmap[0].Bitmap[0].Type=GSM_PictureImage;
2591 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]);
2592 Print_Error(error);
2593 SMSInfo.Entries[0].ID = SMS_NokiaPictureImageLong;
2594 SMSInfo.Entries[0].Bitmap = &bitmap[0];
2595 SMSInfo.UnicodeCoding = false;
2596 bitmap[0].Bitmap[0].Text[0] = 0;
2597 bitmap[0].Bitmap[0].Text[1] = 0;
2598 if (mystrncasecmp(argv[1],"--savesms",0)) {
2599 EncodeUnicode(Sender, "Picture",7);
2600 EncodeUnicode(Name,"Picture Image",13);
2602 startarg += 4;
2603 #ifdef GSM_ENABLE_BACKUP
2604 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) {
2605 if (argc<5+startarg) {
2606 printmsg("Where is backup filename and location ?\n");
2607 exit(-1);
2609 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2610 Print_Error(error);
2611 i = 0;
2612 while (Backup.WAPBookmark[i]!=NULL) {
2613 if (i == atoi(argv[4+startarg])-1) break;
2614 i++;
2616 if (i != atoi(argv[4+startarg])-1) {
2617 printmsg("Bookmark not found in file\n");
2618 exit(-1);
2620 SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong;
2621 SMSInfo.Entries[0].Bookmark = Backup.WAPBookmark[i];
2622 if (mystrncasecmp(argv[1],"--savesms",0)) {
2623 EncodeUnicode(Sender, "Bookmark",8);
2624 EncodeUnicode(Name,"WAP Bookmark",12);
2626 startarg += 5;
2627 } else if (mystrncasecmp(argv[2],"WAPSETTINGS",0)) {
2628 if (argc<6+startarg) {
2629 printmsg("Where is backup filename and location ?\n");
2630 exit(-1);
2632 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2633 Print_Error(error);
2634 i = 0;
2635 while (Backup.WAPSettings[i]!=NULL) {
2636 if (i == atoi(argv[4+startarg])-1) break;
2637 i++;
2639 if (i != atoi(argv[4+startarg])-1) {
2640 printmsg("WAP settings not found in file\n");
2641 exit(-1);
2643 SMSInfo.Entries[0].Settings = NULL;
2644 for (j=0;j<Backup.WAPSettings[i]->Number;j++) {
2645 switch (Backup.WAPSettings[i]->Settings[j].Bearer) {
2646 case WAPSETTINGS_BEARER_GPRS:
2647 if (mystrncasecmp(argv[5+startarg],"GPRS",0)) {
2648 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j];
2649 break;
2651 case WAPSETTINGS_BEARER_DATA:
2652 if (mystrncasecmp(argv[5+startarg],"DATA",0)) {
2653 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j];
2654 break;
2656 default:
2657 break;
2660 if (SMSInfo.Entries[0].Settings == NULL) {
2661 printmsg("Sorry. For now there is only support for GPRS or DATA bearers end\n");
2662 exit(-1);
2664 SMSInfo.Entries[0].ID = SMS_NokiaWAPSettingsLong;
2665 if (mystrncasecmp(argv[1],"--savesms",0)) {
2666 EncodeUnicode(Sender, "Settings",8);
2667 EncodeUnicode(Name,"WAP Settings",12);
2669 startarg += 6;
2670 } else if (mystrncasecmp(argv[2],"MMSSETTINGS",0)) {
2671 if (argc<5+startarg) {
2672 printmsg("Where is backup filename and location ?\n");
2673 exit(-1);
2675 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2676 Print_Error(error);
2677 i = 0;
2678 while (Backup.MMSSettings[i]!=NULL) {
2679 if (i == atoi(argv[4+startarg])-1) break;
2680 i++;
2682 if (i != atoi(argv[4+startarg])-1) {
2683 printmsg("MMS settings not found in file\n");
2684 exit(-1);
2686 SMSInfo.Entries[0].Settings = NULL;
2687 for (j=0;j<Backup.MMSSettings[i]->Number;j++) {
2688 switch (Backup.MMSSettings[i]->Settings[j].Bearer) {
2689 case WAPSETTINGS_BEARER_GPRS:
2690 SMSInfo.Entries[0].Settings = &Backup.MMSSettings[i]->Settings[j];
2691 break;
2692 default:
2693 break;
2696 if (SMSInfo.Entries[0].Settings == NULL) {
2697 printmsg("Sorry. No GPRS bearer found in MMS settings\n");
2698 exit(-1);
2700 SMSInfo.Entries[0].ID = SMS_NokiaMMSSettingsLong;
2701 if (mystrncasecmp(argv[1],"--savesms",0)) {
2702 EncodeUnicode(Sender, "Settings",8);
2703 EncodeUnicode(Name,"MMS Settings",12);
2705 startarg += 5;
2706 } else if (mystrncasecmp(argv[2],"CALENDAR",0)) {
2707 if (argc<5+startarg) {
2708 printmsg("Where is backup filename and location ?\n");
2709 exit(-1);
2711 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2712 Print_Error(error);
2713 i = 0;
2714 while (Backup.Calendar[i]!=NULL) {
2715 if (i == atoi(argv[4+startarg])-1) break;
2716 i++;
2718 if (i != atoi(argv[4+startarg])-1) {
2719 printmsg("Calendar note not found in file\n");
2720 exit(-1);
2722 SMSInfo.Entries[0].ID = SMS_NokiaVCALENDAR10Long;
2723 SMSInfo.Entries[0].Calendar = Backup.Calendar[i];
2724 if (mystrncasecmp(argv[1],"--savesms",0)) {
2725 EncodeUnicode(Sender, "Calendar",8);
2727 startarg += 5;
2728 } else if (mystrncasecmp(argv[2],"TODO",0)) {
2729 if (argc<5+startarg) {
2730 printmsg("Where is backup filename and location ?\n");
2731 exit(-1);
2733 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2734 Print_Error(error);
2735 i = 0;
2736 while (Backup.ToDo[i]!=NULL) {
2737 if (i == atoi(argv[4+startarg])-1) break;
2738 i++;
2740 if (i != atoi(argv[4+startarg])-1) {
2741 printmsg("ToDo note not found in file\n");
2742 exit(-1);
2744 SMSInfo.Entries[0].ID = SMS_NokiaVTODOLong;
2745 SMSInfo.Entries[0].ToDo = Backup.ToDo[i];
2746 if (mystrncasecmp(argv[1],"--savesms",0)) {
2747 EncodeUnicode(Sender, "ToDo",8);
2749 startarg += 5;
2750 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) {
2751 if (argc<6+startarg) {
2752 printmsg("Where is backup filename and location and memory type ?\n");
2753 exit(-1);
2755 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2756 Print_Error(error);
2757 i = 0;
2758 if (mystrncasecmp(argv[4+startarg],"SM",0)) {
2759 while (Backup.SIMPhonebook[i]!=NULL) {
2760 if (i == atoi(argv[5+startarg])-1) break;
2761 i++;
2763 if (i != atoi(argv[5+startarg])-1) {
2764 printmsg("Phonebook entry not found in file\n");
2765 exit(-1);
2767 SMSInfo.Entries[0].Phonebook = Backup.SIMPhonebook[i];
2768 } else if (mystrncasecmp(argv[4+startarg],"ME",0)) {
2769 while (Backup.PhonePhonebook[i]!=NULL) {
2770 if (i == atoi(argv[5+startarg])-1) break;
2771 i++;
2773 if (i != atoi(argv[5+startarg])-1) {
2774 printmsg("Phonebook entry not found in file\n");
2775 exit(-1);
2777 SMSInfo.Entries[0].Phonebook = Backup.PhonePhonebook[i];
2778 } else {
2779 printmsg("Unknown memory type: \"%s\"\n",argv[4+startarg]);
2780 exit(-1);
2782 if (mystrncasecmp(argv[2],"VCARD10",0)) {
2783 SMSInfo.Entries[0].ID = SMS_VCARD10Long;
2784 } else {
2785 SMSInfo.Entries[0].ID = SMS_VCARD21Long;
2787 if (mystrncasecmp(argv[1],"--savesms",0)) {
2788 EncodeUnicode(Sender, "VCARD",5);
2789 EncodeUnicode(Name, "Phonebook entry",15);
2791 startarg += 6;
2792 #endif
2793 } else if (mystrncasecmp(argv[2],"PROFILE",0)) {
2794 SMSInfo.Entries[0].ID = SMS_NokiaProfileLong;
2795 if (mystrncasecmp(argv[1],"--savesms",0)) {
2796 EncodeUnicode(Sender, "Profile",7);
2798 startarg += 3;
2799 } else {
2800 printmsg("What format of sms (\"%s\") ?\n",argv[2]);
2801 exit(-1);
2804 for (i=startarg;i<argc;i++) {
2805 switch (nextlong) {
2806 case 0:
2807 if (mystrncasecmp(argv[1],"--savesms",0)) {
2808 if (mystrncasecmp(argv[i],"-folder",0)) {
2809 nextlong=1;
2810 continue;
2812 if (mystrncasecmp(argv[i],"-unread",0)) {
2813 State = GSM_UnRead;
2814 continue;
2816 if (mystrncasecmp(argv[i],"-read",0)) {
2817 State = GSM_Read;
2818 continue;
2820 if (mystrncasecmp(argv[i],"-unsent",0)) {
2821 State = GSM_UnSent;
2822 continue;
2824 if (mystrncasecmp(argv[i],"-sent",0)) {
2825 State = GSM_Sent;
2826 continue;
2828 if (mystrncasecmp(argv[i],"-sender",0)) {
2829 nextlong=2;
2830 continue;
2832 } else {
2833 if (mystrncasecmp(argv[i],"-report",0)) {
2834 DeliveryReport=true;
2835 continue;
2837 if (mystrncasecmp(argv[i],"-validity",0)) {
2838 nextlong=10;
2839 continue;
2842 if (mystrncasecmp(argv[i],"-smscset",0)) {
2843 nextlong=3;
2844 continue;
2846 if (mystrncasecmp(argv[i],"-smscnumber",0)) {
2847 nextlong=4;
2848 continue;
2850 if (mystrncasecmp(argv[i],"-protected",0)) {
2851 nextlong=19;
2852 continue;
2854 if (mystrncasecmp(argv[i],"-reply",0)) {
2855 ReplyViaSameSMSC=true;
2856 continue;
2858 if (mystrncasecmp(argv[i],"-maxsms",0)) {
2859 nextlong=21;
2860 continue;
2862 if (mystrncasecmp(argv[2],"RINGTONE",0)) {
2863 if (mystrncasecmp(argv[i],"-long",0)) {
2864 SMSInfo.Entries[0].ID = SMS_NokiaRingtoneLong;
2865 break;
2867 if (mystrncasecmp(argv[i],"-scale",0)) {
2868 ringtone[0].NoteTone.AllNotesScale=true;
2869 break;
2872 if (mystrncasecmp(argv[2],"TEXT",0)) {
2873 if (mystrncasecmp(argv[i],"-inputunicode",0)) {
2874 ReadUnicodeFile(Buffer[0],InputBuffer);
2875 break;
2877 if (mystrncasecmp(argv[i],"-16bit",0)) {
2878 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong16bit;
2879 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedAutoTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong16bit;
2880 break;
2882 if (mystrncasecmp(argv[i],"-flash",0)) {
2883 SMSInfo.Class = 0;
2884 break;
2886 if (mystrncasecmp(argv[i],"-len",0)) {
2887 nextlong = 5;
2888 break;
2890 if (mystrncasecmp(argv[i],"-autolen",0)) {
2891 nextlong = 5;
2892 break;
2894 if (mystrncasecmp(argv[i],"-unicode",0)) {
2895 SMSInfo.UnicodeCoding = true;
2896 break;
2898 if (mystrncasecmp(argv[i],"-enablevoice",0)) {
2899 SMSInfo.Entries[0].ID = SMS_EnableVoice;
2900 break;
2902 if (mystrncasecmp(argv[i],"-disablevoice",0)) {
2903 SMSInfo.Entries[0].ID = SMS_DisableVoice;
2904 break;
2906 if (mystrncasecmp(argv[i],"-enablefax",0)) {
2907 SMSInfo.Entries[0].ID = SMS_EnableFax;
2908 break;
2910 if (mystrncasecmp(argv[i],"-disablefax",0)) {
2911 SMSInfo.Entries[0].ID = SMS_DisableFax;
2912 break;
2914 if (mystrncasecmp(argv[i],"-enableemail",0)) {
2915 SMSInfo.Entries[0].ID = SMS_EnableEmail;
2916 break;
2918 if (mystrncasecmp(argv[i],"-disableemail",0)) {
2919 SMSInfo.Entries[0].ID = SMS_DisableEmail;
2920 break;
2922 if (mystrncasecmp(argv[i],"-voidsms",0)) {
2923 SMSInfo.Entries[0].ID = SMS_VoidSMS;
2924 break;
2926 if (mystrncasecmp(argv[i],"-replacemessages",0) &&
2927 SMSInfo.Entries[0].ID != SMS_ConcatenatedTextLong) {
2928 nextlong = 8;
2929 break;
2931 if (mystrncasecmp(argv[i],"-replacefile",0)) {
2932 nextlong = 9;
2933 continue;
2936 if (mystrncasecmp(argv[2],"PICTURE",0)) {
2937 if (mystrncasecmp(argv[i],"-text",0)) {
2938 nextlong = 6;
2939 break;
2941 if (mystrncasecmp(argv[i],"-unicode",0)) {
2942 SMSInfo.UnicodeCoding = true;
2943 break;
2945 break;
2947 if (mystrncasecmp(argv[2],"VCARD10",0)) {
2948 if (mystrncasecmp(argv[i],"-nokia",0)) {
2949 SMSInfo.Entries[0].ID = SMS_NokiaVCARD10Long;
2950 break;
2952 break;
2954 if (mystrncasecmp(argv[2],"VCARD21",0)) {
2955 if (mystrncasecmp(argv[i],"-nokia",0)) {
2956 SMSInfo.Entries[0].ID = SMS_NokiaVCARD21Long;
2957 break;
2959 break;
2961 if (mystrncasecmp(argv[2],"PROFILE",0)) {
2962 if (mystrncasecmp(argv[i],"-name",0)) {
2963 nextlong = 22;
2964 break;
2966 if (mystrncasecmp(argv[i],"-ringtone",0)) {
2967 nextlong = 23;
2968 break;
2970 if (mystrncasecmp(argv[i],"-bitmap",0)) {
2971 nextlong = 24;
2972 break;
2975 if (mystrncasecmp(argv[2],"EMS",0)) {
2976 if (mystrncasecmp(argv[i],"-unicode",0)) {
2977 SMSInfo.UnicodeCoding = true;
2978 break;
2980 if (mystrncasecmp(argv[i],"-16bit",0)) {
2981 EMS16Bit = true;
2982 break;
2984 if (mystrncasecmp(argv[i],"-format",0)) {
2985 nextlong = 20;
2986 break;
2988 if (mystrncasecmp(argv[i],"-text",0)) {
2989 nextlong = 11;
2990 break;
2992 if (mystrncasecmp(argv[i],"-unicodefiletext",0)) {
2993 nextlong = 18;
2994 break;
2996 if (mystrncasecmp(argv[i],"-defsound",0)) {
2997 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSPredefinedSound;
2998 nextlong = 12;
2999 break;
3001 if (mystrncasecmp(argv[i],"-defanimation",0)) {
3002 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSPredefinedAnimation;
3003 nextlong = 12;
3004 break;
3006 if (mystrncasecmp(argv[i],"-tone10",0)) {
3007 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound10;
3008 if (Protected != 0) {
3009 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3010 Protected --;
3012 nextlong = 14;
3013 break;
3015 if (mystrncasecmp(argv[i],"-tone10long",0)) {
3016 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound10Long;
3017 if (Protected != 0) {
3018 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3019 Protected --;
3021 nextlong = 14;
3022 break;
3024 if (mystrncasecmp(argv[i],"-tone12",0)) {
3025 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound12;
3026 if (Protected != 0) {
3027 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3028 Protected --;
3030 nextlong = 14;
3031 break;
3033 if (mystrncasecmp(argv[i],"-tone12long",0)) {
3034 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSound12Long;
3035 if (Protected != 0) {
3036 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3037 Protected --;
3039 nextlong = 14;
3040 break;
3042 if (mystrncasecmp(argv[i],"-toneSE",0)) {
3043 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSonyEricssonSound;
3044 if (Protected != 0) {
3045 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3046 Protected --;
3048 nextlong = 14;
3049 break;
3051 if (mystrncasecmp(argv[i],"-toneSElong",0)) {
3052 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSSonyEricssonSoundLong;
3053 if (Protected != 0) {
3054 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3055 Protected --;
3057 nextlong = 14;
3058 break;
3060 if (mystrncasecmp(argv[i],"-fixedbitmap",0)) {
3061 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSFixedBitmap;
3062 if (Protected != 0) {
3063 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3064 Protected --;
3066 nextlong = 15;
3067 break;
3069 if (mystrncasecmp(argv[i],"-variablebitmap",0)) {
3070 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSVariableBitmap;
3071 if (Protected != 0) {
3072 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3073 Protected --;
3075 nextlong = 15;
3076 break;
3078 if (mystrncasecmp(argv[i],"-variablebitmaplong",0)) {
3079 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSVariableBitmapLong;
3080 if (Protected != 0) {
3081 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3082 Protected --;
3084 nextlong = 15;
3085 break;
3087 if (mystrncasecmp(argv[i],"-animation",0)) {
3088 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_EMSAnimation;
3089 if (Protected != 0) {
3090 SMSInfo.Entries[SMSInfo.EntriesNum].Protected = true;
3091 Protected --;
3093 bitmap[SMSInfo.EntriesNum].Number = 0;
3094 nextlong = 16;
3095 break;
3098 if (mystrncasecmp(argv[2],"OPERATOR",0)) {
3099 if (mystrncasecmp(argv[i],"-netcode",0)) {
3100 nextlong = 7;
3101 break;
3103 if (mystrncasecmp(argv[i],"-biglogo",0)) {
3104 SMSInfo.Entries[0].ID = SMS_NokiaOperatorLogoLong;
3105 break;
3107 break;
3109 printmsg("Unknown parameter (\"%s\")\n",argv[i]);
3110 exit(-1);
3111 break;
3112 case 1: /* SMS folder - only during saving SMS */
3113 Folder = atoi(argv[i]);
3114 nextlong = 0;
3115 break;
3116 case 2: /* Sender number - only during saving SMS */
3117 EncodeUnicode(Sender,argv[i],strlen(argv[i]));
3118 nextlong = 0;
3119 break;
3120 case 3: /* SMSC set number */
3121 SMSCSet = atoi(argv[i]);
3122 nextlong = 0;
3123 break;
3124 case 4: /* Number of SMSC */
3125 EncodeUnicode(SMSC,argv[i],strlen(argv[i]));
3126 SMSCSet = 0;
3127 nextlong = 0;
3128 break;
3129 case 5: /* Length of text SMS */
3130 if (atoi(argv[i])<chars_read)
3132 Buffer[0][atoi(argv[i])*2] = 0x00;
3133 Buffer[0][atoi(argv[i])*2+1] = 0x00;
3135 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
3136 if (mystrncasecmp(argv[i-1],"-autolen",0)) SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong;
3137 nextlong = 0;
3138 break;
3139 case 6: /* Picture Images - text */
3140 EncodeUnicode(bitmap[0].Bitmap[0].Text,argv[i],strlen(argv[i]));
3141 nextlong = 0;
3142 break;
3143 case 7: /* Operator Logo - network code */
3144 strncpy(bitmap[0].Bitmap[0].NetworkCode,argv[i],7);
3145 if (!strcmp(DecodeUnicodeConsole(GSM_GetNetworkName(bitmap[0].Bitmap[0].NetworkCode)),"unknown")) {
3146 printmsg("Unknown GSM network code (\"%s\")\n",argv[i]);
3147 exit(-1);
3149 if (mystrncasecmp(argv[1],"--savesms",0)) {
3150 EncodeUnicode(Sender, "OpLogo",6);
3151 EncodeUnicode(Sender+6*2,bitmap[0].Bitmap[0].NetworkCode,3);
3152 EncodeUnicode(Sender+6*2+3*2,bitmap[0].Bitmap[0].NetworkCode+4,2);
3153 if (UnicodeLength(GSM_GetNetworkName(bitmap[0].Bitmap[0].NetworkCode))<GSM_MAX_SMS_NAME_LENGTH-7) {
3154 EncodeUnicode(Name,"OpLogo ",7);
3155 CopyUnicodeString(Name+7*2,GSM_GetNetworkName(bitmap[0].Bitmap[0].NetworkCode));
3156 } else {
3157 CopyUnicodeString(Name,Sender);
3160 nextlong = 0;
3161 break;
3162 case 8:/* Reject duplicates ID */
3163 SMSInfo.ReplaceMessage = atoi(argv[i]);
3164 if (SMSInfo.ReplaceMessage < 1 || SMSInfo.ReplaceMessage > 7) {
3165 printmsg("You have to give number between 1 and 7 (\"%s\")\n",argv[i]);
3166 exit(-1);
3168 nextlong = 0;
3169 break;
3170 case 9:/* Replace file for text SMS */
3171 ReplaceFile = fopen(argv[i], "rb");
3172 if (ReplaceFile == NULL) Print_Error(GE_CANTOPENFILE);
3173 memset(ReplaceBuffer,0,sizeof(ReplaceBuffer));
3174 fread(ReplaceBuffer,1,sizeof(ReplaceBuffer),ReplaceFile);
3175 fclose(ReplaceFile);
3176 ReadUnicodeFile(ReplaceBuffer2,ReplaceBuffer);
3177 for(j=0;j<(int)(UnicodeLength(Buffer[0]));j++) {
3178 for (z=0;z<(int)(UnicodeLength(ReplaceBuffer2)/2);z++) {
3179 if (ReplaceBuffer2[z*4] == Buffer[0][j] &&
3180 ReplaceBuffer2[z*4+1] == Buffer[0][j+1]) {
3181 Buffer[0][j] = ReplaceBuffer2[z*4+2];
3182 Buffer[0][j+1] = ReplaceBuffer2[z*4+3];
3183 break;
3187 nextlong = 0;
3188 break;
3189 case 10:
3190 Validity.VPF = GSM_RelativeFormat;
3191 if (mystrncasecmp(argv[i],"HOUR",0)) Validity.Relative = GSMV_1_Hour;
3192 else if (mystrncasecmp(argv[i],"6HOURS",0)) Validity.Relative = GSMV_6_Hours;
3193 else if (mystrncasecmp(argv[i],"DAY",0)) Validity.Relative = GSMV_24_Hours;
3194 else if (mystrncasecmp(argv[i],"3DAYS",0)) Validity.Relative = GSMV_72_Hours;
3195 else if (mystrncasecmp(argv[i],"WEEK",0)) Validity.Relative = GSMV_1_Week;
3196 else if (mystrncasecmp(argv[i],"MAX",0)) Validity.Relative = GSMV_Max_Time;
3197 else {
3198 printmsg("Unknown validity string (\"%s\")\n",argv[i]);
3199 exit(-1);
3201 nextlong = 0;
3202 break;
3203 case 11:/* EMS text from parameter */
3204 EncodeUnicode(Buffer[SMSInfo.EntriesNum],argv[i],strlen(argv[i]));
3205 dbgprintf("buffer is \"%s\"\n",DecodeUnicodeConsole(Buffer[SMSInfo.EntriesNum]));
3206 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_ConcatenatedTextLong;
3207 SMSInfo.Entries[SMSInfo.EntriesNum].Buffer = Buffer[SMSInfo.EntriesNum];
3208 SMSInfo.EntriesNum++;
3209 nextlong = 0;
3210 break;
3211 case 12:/* EMS predefined sound/animation number */
3212 SMSInfo.Entries[SMSInfo.EntriesNum].Number = atoi(argv[i]);
3213 SMSInfo.EntriesNum++;
3214 nextlong = 0;
3215 break;
3216 case 14: /* EMS ringtone - IMelody */
3217 ringtone[SMSInfo.EntriesNum].Format=RING_NOTETONE;
3218 error=GSM_ReadRingtoneFile(argv[i],&ringtone[SMSInfo.EntriesNum]);
3219 Print_Error(error);
3220 SMSInfo.Entries[SMSInfo.EntriesNum].Ringtone = &ringtone[SMSInfo.EntriesNum];
3221 SMSInfo.EntriesNum++;
3222 nextlong = 0;
3223 break;
3224 case 15:/* EMS bitmap file */
3225 bitmap[SMSInfo.EntriesNum].Bitmap[0].Type=GSM_StartupLogo;
3226 error=GSM_ReadBitmapFile(argv[i],&bitmap[SMSInfo.EntriesNum]);
3227 Print_Error(error);
3228 SMSInfo.Entries[SMSInfo.EntriesNum].Bitmap = &bitmap[SMSInfo.EntriesNum];
3229 SMSInfo.EntriesNum++;
3230 nextlong = 0;
3231 break;
3232 case 16:/* Number of frames for EMS animation */
3233 FramesNum = atoi(argv[i]);
3234 if (FramesNum < 1 || FramesNum > 4) {
3235 printmsg("You have to give number of EMS frames between 1 and 4 (\"%s\")\n",argv[i]);
3236 exit(-1);
3238 bitmap[SMSInfo.EntriesNum].Number = 0;
3239 nextlong = 17;
3240 break;
3241 case 17:/*File for EMS animation */
3242 bitmap2.Bitmap[0].Type=GSM_StartupLogo;
3243 error=GSM_ReadBitmapFile(argv[i],&bitmap2);
3244 for (j=0;j<bitmap2.Number;j++) {
3245 if (bitmap[SMSInfo.EntriesNum].Number == FramesNum) break;
3246 memcpy(&bitmap[SMSInfo.EntriesNum].Bitmap[bitmap[SMSInfo.EntriesNum].Number],&bitmap2.Bitmap[j],sizeof(GSM_Bitmap));
3247 bitmap[SMSInfo.EntriesNum].Number++;
3249 if (bitmap[SMSInfo.EntriesNum].Number == FramesNum) {
3250 SMSInfo.Entries[SMSInfo.EntriesNum].Bitmap = &bitmap[SMSInfo.EntriesNum];
3251 SMSInfo.EntriesNum++;
3252 nextlong = 0;
3254 break;
3255 case 18:/* EMS text from Unicode file */
3256 f = fopen(argv[i],"rb");
3257 if (f == NULL) {
3258 printmsg("Can't open file \"%s\"\n",argv[i]);
3259 exit(-1);
3261 z=fread(InputBuffer,1,2000,f);
3262 InputBuffer[z] = 0;
3263 InputBuffer[z+1] = 0;
3264 fclose(f);
3265 ReadUnicodeFile(Buffer[SMSInfo.EntriesNum],InputBuffer);
3266 dbgprintf("buffer is \"%s\"\n",DecodeUnicodeConsole(Buffer[SMSInfo.EntriesNum]));
3267 SMSInfo.Entries[SMSInfo.EntriesNum].ID = SMS_ConcatenatedTextLong;
3268 SMSInfo.Entries[SMSInfo.EntriesNum].Buffer = Buffer[SMSInfo.EntriesNum];
3269 SMSInfo.EntriesNum++;
3270 nextlong = 0;
3271 break;
3272 case 19:/* Number of protected items */
3273 Protected = atoi(argv[i]);
3274 nextlong = 0;
3275 break;
3276 case 20:/* Formatting text for EMS */
3277 if (SMSInfo.Entries[SMSInfo.EntriesNum-1].ID == SMS_ConcatenatedTextLong) {
3278 for(j=0;j<(int)strlen(argv[i]);j++) {
3279 switch(argv[i][j]) {
3280 case 'l': case 'L':
3281 SMSInfo.Entries[SMSInfo.EntriesNum-1].Left = true;
3282 break;
3283 case 'c': case 'C':
3284 SMSInfo.Entries[SMSInfo.EntriesNum-1].Center = true;
3285 break;
3286 case 'r': case 'R':
3287 SMSInfo.Entries[SMSInfo.EntriesNum-1].Right = true;
3288 break;
3289 case 'a': case 'A':
3290 SMSInfo.Entries[SMSInfo.EntriesNum-1].Large = true;
3291 break;
3292 case 's': case 'S':
3293 SMSInfo.Entries[SMSInfo.EntriesNum-1].Small = true;
3294 break;
3295 case 'b': case 'B':
3296 SMSInfo.Entries[SMSInfo.EntriesNum-1].Bold = true;
3297 break;
3298 case 'i': case 'I':
3299 SMSInfo.Entries[SMSInfo.EntriesNum-1].Italic = true;
3300 break;
3301 case 'u': case 'U':
3302 SMSInfo.Entries[SMSInfo.EntriesNum-1].Underlined = true;
3303 break;
3304 case 't': case 'T':
3305 SMSInfo.Entries[SMSInfo.EntriesNum-1].Strikethrough = true;
3306 break;
3307 default:
3308 printmsg("Unknown parameter \"%c\"\n",argv[i][j]);
3309 exit(-1);
3312 } else {
3313 printmsg("Last parameter wasn't text\n");
3314 exit(-1);
3316 nextlong = 0;
3317 break;
3318 case 21:/*MaxSMS*/
3319 MaxSMS = atoi(argv[i]);
3320 nextlong = 0;
3321 break;
3322 case 22:/* profile name */
3323 EncodeUnicode(Buffer[0],argv[i],strlen(argv[i]));
3324 SMSInfo.Entries[0].Buffer = Buffer[0];
3325 nextlong = 0;
3326 break;
3327 case 23:/* profile ringtone */
3328 ringtone[0].Format = RING_NOTETONE;
3329 error=GSM_ReadRingtoneFile(argv[i],&ringtone[0]);
3330 Print_Error(error);
3331 SMSInfo.Entries[0].Ringtone = &ringtone[0];
3332 nextlong = 0;
3333 break;
3334 case 24:/* profile bitmap */
3335 bitmap[0].Bitmap[0].Type = GSM_PictureImage;
3336 error=GSM_ReadBitmapFile(argv[i],&bitmap[0]);
3337 Print_Error(error);
3338 bitmap[0].Bitmap[0].Text[0] = 0;
3339 bitmap[0].Bitmap[0].Text[1] = 0;
3340 SMSInfo.Entries[0].Bitmap = &bitmap[0];
3341 nextlong = 0;
3342 break;
3345 if (nextlong!=0) {
3346 printmsg("Parameter missed...\n");
3347 exit(-1);
3350 if (mystrncasecmp(argv[2],"EMS",0) && EMS16Bit) {
3351 for (i=0;i<SMSInfo.EntriesNum;i++) {
3352 switch (SMSInfo.Entries[i].ID) {
3353 case SMS_ConcatenatedTextLong:
3354 SMSInfo.Entries[i].ID = SMS_ConcatenatedTextLong16bit;
3355 default:
3356 break;
3362 if (mystrncasecmp(argv[2],"TEXT",0)) {
3363 chars_read = UnicodeLength(Buffer[0]);
3364 if (chars_read != 0) {
3365 /* Trim \n at the end of string */
3366 if (Buffer[0][chars_read*2-1] == '\n' && Buffer[0][chars_read*2-2] == 0)
3368 Buffer[0][chars_read*2-1] = 0;
3373 if (mystrncasecmp(argv[1],"--displaysms",0)) {
3374 if (mystrncasecmp(argv[2],"OPERATOR",0)) {
3375 if (bitmap[0].Bitmap[0].Type==GSM_OperatorLogo && strcmp(bitmap[0].Bitmap[0].NetworkCode,"000 00")==0) {
3376 printmsg("No network code\n");
3377 exit(-1);
3380 } else {
3381 GSM_Init(true);
3383 if (mystrncasecmp(argv[2],"OPERATOR",0)) {
3384 if (bitmap[0].Bitmap[0].Type==GSM_OperatorLogo && strcmp(bitmap[0].Bitmap[0].NetworkCode,"000 00")==0) {
3385 error=Phone->GetNetworkInfo(&s,&NetInfo);
3386 Print_Error(error);
3387 strcpy(bitmap[0].Bitmap[0].NetworkCode,NetInfo.NetworkCode);
3388 if (mystrncasecmp(argv[1],"--savesms",0)) {
3389 EncodeUnicode(Sender, "OpLogo",6);
3390 EncodeUnicode(Sender+6*2,bitmap[0].Bitmap[0].NetworkCode,3);
3391 EncodeUnicode(Sender+6*2+3*2,bitmap[0].Bitmap[0].NetworkCode+4,2);
3392 if (UnicodeLength(GSM_GetNetworkName(bitmap[0].Bitmap[0].NetworkCode))<GSM_MAX_SMS_NAME_LENGTH-7) {
3393 EncodeUnicode(Name,"OpLogo ",7);
3394 CopyUnicodeString(Name+7*2,GSM_GetNetworkName(bitmap[0].Bitmap[0].NetworkCode));
3395 } else {
3396 CopyUnicodeString(Name,Sender);
3403 error=GSM_EncodeMultiPartSMS(&SMSInfo,&sms);
3404 Print_Error(error);
3406 for (i=0;i<SMSInfo.EntriesNum;i++) {
3407 switch (SMSInfo.Entries[i].ID) {
3408 case SMS_NokiaRingtone:
3409 case SMS_NokiaRingtoneLong:
3410 case SMS_NokiaProfileLong:
3411 case SMS_EMSSound10:
3412 case SMS_EMSSound12:
3413 case SMS_EMSSonyEricssonSound:
3414 case SMS_EMSSound10Long:
3415 case SMS_EMSSound12Long:
3416 case SMS_EMSSonyEricssonSoundLong:
3417 if (SMSInfo.Entries[i].RingtoneNotes!=SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands) {
3418 printmsg("Warning: ringtone too long. %i percent part cut\n",
3419 (SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands-SMSInfo.Entries[i].RingtoneNotes)*100/SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands);
3421 default:
3422 break;
3426 if (MaxSMS != -1 && sms.Number > MaxSMS) {
3427 printmsg("There is %i SMS packed and %i limit. Exiting\n",sms.Number,MaxSMS);
3428 if (!mystrncasecmp(argv[1],"--displaysms",0)) GSM_Terminate();
3429 exit(-1);
3432 if (mystrncasecmp(argv[1],"--displaysms",0)) {
3433 if (SMSCSet != 0) {
3434 printmsg("Use -smscnumber option to give SMSC number\n");
3435 exit(-1);
3438 for (i=0;i<sms.Number;i++) {
3439 sms.SMS[i].Location = 0;
3440 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC;
3441 sms.SMS[i].SMSC.Location = 0;
3442 sms.SMS[i].PDU = SMS_Submit;
3443 if (DeliveryReport) sms.SMS[i].PDU = SMS_Status_Report;
3444 CopyUnicodeString(sms.SMS[i].Number, Sender);
3445 CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC);
3446 if (Validity.VPF != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity));
3447 DisplaySMSFrame(&sms.SMS[i]);
3450 printmsg("\nNumber of SMS: %i\n",sms.Number);
3451 exit(sms.Number);
3453 if (mystrncasecmp(argv[1],"--savesms",0)) {
3454 error=Phone->GetSMSFolders(&s, &folders);
3455 Print_Error(error);
3457 for (i=0;i<sms.Number;i++) {
3458 printmsg("Saving SMS %i/%i\n",i+1,sms.Number);
3459 // sms.SMS[i].Location = 0;
3460 sms.SMS[i].Folder = Folder;
3461 sms.SMS[i].State = State;
3462 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC;
3463 sms.SMS[i].SMSC.Location = SMSCSet;
3464 sms.SMS[i].PDU = SMS_Deliver;
3465 CopyUnicodeString(sms.SMS[i].Number, Sender);
3466 CopyUnicodeString(sms.SMS[i].Name, Name);
3467 if (SMSCSet==0) CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC);
3468 error=Phone->AddSMS(&s, &sms.SMS[i]);
3469 Print_Error(error);
3470 printmsg("Saved in folder \"%s\", location %i\n",
3471 DecodeUnicodeConsole(folders.Folder[sms.SMS[i].Folder-1].Name),sms.SMS[i].Location);
3473 } else {
3474 if (Validity.VPF != 0 && SMSCSet != 0) {
3475 PhoneSMSC.Location = SMSCSet;
3476 error=Phone->GetSMSC(&s,&PhoneSMSC);
3477 Print_Error(error);
3478 CopyUnicodeString(SMSC,PhoneSMSC.Number);
3479 SMSCSet = 0;
3482 /* We do not want to make it forever - press Ctrl+C to stop */
3483 signal(SIGINT, interrupted);
3484 printmsgerr("If you want break, press Ctrl+C...\n");
3486 s.User.SendSMSStatus = SendSMSStatus;
3488 for (i=0;i<sms.Number;i++) {
3489 printmsg("Sending SMS %i/%i",i+1,sms.Number);
3490 sms.SMS[i].Location = 0;
3491 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC;
3492 sms.SMS[i].SMSC.Location = SMSCSet;
3493 sms.SMS[i].PDU = SMS_Submit;
3494 if (DeliveryReport) sms.SMS[i].PDU = SMS_Status_Report;
3495 CopyUnicodeString(sms.SMS[i].Number, Sender);
3496 if (SMSCSet==0) CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC);
3497 if (Validity.VPF != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity));
3498 SMSStatus = GE_TIMEOUT;
3499 error=Phone->SendSMS(&s, &sms.SMS[i]);
3500 Print_Error(error);
3501 printmsg("....waiting for network answer");
3502 while (!bshutdown) {
3503 GSM_ReadDevice(&s,true);
3504 if (SMSStatus == GE_UNKNOWN) {
3505 GSM_Terminate();
3506 exit(-1);
3508 if (SMSStatus == GE_NONE) break;
3513 GSM_Terminate();
3516 #ifdef GSM_ENABLE_BACKUP
3517 static void SaveFile(int argc, char *argv[])
3519 GSM_Backup Backup;
3520 int i,j;
3521 FILE *file;
3522 unsigned char Buffer[10000];
3523 GSM_MemoryEntry *pbk;
3525 if (mystrncasecmp(argv[2],"CALENDAR",0)) {
3526 if (argc<5) {
3527 printmsg("Where is backup filename and location ?\n");
3528 exit(-1);
3530 error=GSM_ReadBackupFile(argv[4],&Backup);
3531 Print_Error(error);
3532 i = 0;
3533 while (Backup.Calendar[i]!=NULL) {
3534 if (i == atoi(argv[5])-1) break;
3535 i++;
3537 if (i != atoi(argv[5])-1) {
3538 printmsg("Calendar note not found in file\n");
3539 exit(-1);
3541 j = 0;
3542 GSM_EncodeVCALENDAR(Buffer, &j, Backup.Calendar[i],true,Nokia_VCalendar);
3543 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) {
3544 if (argc<5) {
3545 printmsg("Where is backup filename and location ?\n");
3546 exit(-1);
3548 error=GSM_ReadBackupFile(argv[4],&Backup);
3549 Print_Error(error);
3550 i = 0;
3551 while (Backup.WAPBookmark[i]!=NULL) {
3552 if (i == atoi(argv[5])-1) break;
3553 i++;
3555 if (i != atoi(argv[5])-1) {
3556 printmsg("WAP bookmark not found in file\n");
3557 exit(-1);
3559 j = 0;
3560 GSM_EncodeURLFile(Buffer, &j, Backup.WAPBookmark[i]);
3561 } else if (mystrncasecmp(argv[2],"NOTE",0)) {
3562 if (argc<5) {
3563 printmsg("Where is backup filename and location ?\n");
3564 exit(-1);
3566 error=GSM_ReadBackupFile(argv[4],&Backup);
3567 Print_Error(error);
3568 i = 0;
3569 while (Backup.Note[i]!=NULL) {
3570 if (i == atoi(argv[5])-1) break;
3571 i++;
3573 if (i != atoi(argv[5])-1) {
3574 printmsg("Note not found in file\n");
3575 exit(-1);
3577 j = 0;
3578 GSM_EncodeVNTFile(Buffer, &j, Backup.Note[i]);
3579 } else if (mystrncasecmp(argv[2],"TODO",0)) {
3580 if (argc<5) {
3581 printmsg("Where is backup filename and location ?\n");
3582 exit(-1);
3584 error=GSM_ReadBackupFile(argv[4],&Backup);
3585 Print_Error(error);
3586 i = 0;
3587 while (Backup.ToDo[i]!=NULL) {
3588 if (i == atoi(argv[5])-1) break;
3589 i++;
3591 if (i != atoi(argv[5])-1) {
3592 printmsg("ToDo note not found in file\n");
3593 exit(-1);
3595 j = 0;
3596 GSM_EncodeVTODO(Buffer, &j, Backup.ToDo[i], true, Nokia_VToDo);
3597 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) {
3598 if (argc<6) {
3599 printmsg("Where is backup filename and location and memory type ?\n");
3600 exit(-1);
3602 error=GSM_ReadBackupFile(argv[4],&Backup);
3603 Print_Error(error);
3604 i = 0;
3605 if (mystrncasecmp(argv[5],"SM",0)) {
3606 while (Backup.SIMPhonebook[i]!=NULL) {
3607 if (i == atoi(argv[6])-1) break;
3608 i++;
3610 if (i != atoi(argv[6])-1) {
3611 printmsg("Phonebook entry not found in file\n");
3612 exit(-1);
3614 pbk = Backup.SIMPhonebook[i];
3615 } else if (mystrncasecmp(argv[5],"ME",0)) {
3616 while (Backup.PhonePhonebook[i]!=NULL) {
3617 if (i == atoi(argv[6])-1) break;
3618 i++;
3620 if (i != atoi(argv[6])-1) {
3621 printmsg("Phonebook entry not found in file\n");
3622 exit(-1);
3624 pbk = Backup.PhonePhonebook[i];
3625 } else {
3626 printmsg("Unknown memory type: \"%s\"\n",argv[5]);
3627 exit(-1);
3629 j = 0;
3630 if (mystrncasecmp(argv[2],"VCARD10",0)) {
3631 GSM_EncodeVCARD(Buffer,&j,pbk,true,Nokia_VCard10);
3632 } else {
3633 GSM_EncodeVCARD(Buffer,&j,pbk,true,Nokia_VCard21);
3635 } else {
3636 printmsg("What format of file (\"%s\") ?\n",argv[2]);
3637 exit(-1);
3640 file = fopen(argv[3],"wb");
3641 fwrite(Buffer,1,j,file);
3642 fclose(file);
3645 static void Backup(int argc, char *argv[])
3647 int i, used;
3648 GSM_MemoryStatus MemStatus;
3649 GSM_ToDoEntry ToDo;
3650 GSM_ToDoStatus ToDoStatus;
3651 GSM_MemoryEntry Pbk;
3652 GSM_CalendarEntry Note;
3653 GSM_Bitmap Bitmap;
3654 GSM_WAPBookmark Bookmark;
3655 GSM_Profile Profile;
3656 GSM_MultiWAPSettings Settings;
3657 GSM_Ringtone Ringtone;
3658 GSM_SMSC SMSC;
3659 GSM_Backup Backup;
3660 GSM_Backup_Info Info;
3661 GSM_FMStation FMStation;
3662 GSM_GPRSAccessPoint GPRSPoint;
3663 bool DoBackup;
3665 GSM_ClearBackup(&Backup);
3666 GSM_GetBackupFeatures(argv[2],&Info);
3668 /* We do not want to make it forever - press Ctrl+C to stop */
3669 signal(SIGINT, interrupted);
3670 printmsgerr("If you want break, press Ctrl+C...\n");
3672 GSM_Init(true);
3674 if (Info.UseUnicode) {
3675 Info.UseUnicode=answer_yes("Use Unicode subformat of backup file");
3677 if (Info.DateTime) {
3678 GSM_GetCurrentDateTime (&Backup.DateTime);
3679 Backup.DateTimeAvailable=true;
3681 if (Info.Model) {
3682 error=Phone->GetManufacturer(&s);
3683 Print_Error(error);
3684 sprintf(Backup.Model,"%s ",s.Phone.Data.Manufacturer);
3685 if (s.Phone.Data.ModelInfo->model[0]!=0) {
3686 strcat(Backup.Model,s.Phone.Data.ModelInfo->model);
3687 } else {
3688 strcat(Backup.Model,s.Phone.Data.Model);
3690 strcat(Backup.Model," ");
3691 strcat(Backup.Model,s.Phone.Data.Version);
3693 if (Info.IMEI) {
3694 error=Phone->GetIMEI(&s);
3695 strcpy(Backup.IMEI, s.Phone.Data.IMEI);
3696 Print_Error(error);
3698 printf("\n");
3700 DoBackup = false;
3701 if (Info.PhonePhonebook) {
3702 printmsg("Checking phone phonebook\n");
3703 MemStatus.MemoryType = GMT_ME;
3704 error=Phone->GetMemoryStatus(&s, &MemStatus);
3705 if (error==GE_NONE && MemStatus.Used != 0) {
3706 if (answer_yes(" Backup phone phonebook")) DoBackup = true;
3709 if (DoBackup) {
3710 Pbk.MemoryType = GMT_ME;
3711 i = 1;
3712 used = 0;
3713 while (used != MemStatus.Used) {
3714 Pbk.Location = i;
3715 error=Phone->GetMemory(&s, &Pbk);
3716 if (error != GE_EMPTY) {
3717 Print_Error(error);
3718 if (used < GSM_BACKUP_MAX_PHONEPHONEBOOK) {
3719 Backup.PhonePhonebook[used] = malloc(sizeof(GSM_MemoryEntry));
3720 if (Backup.PhonePhonebook[used] == NULL) Print_Error(GE_MOREMEMORY);
3721 Backup.PhonePhonebook[used+1] = NULL;
3722 } else {
3723 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PHONEPHONEBOOK");
3724 GSM_Terminate();
3725 exit(-1);
3727 *Backup.PhonePhonebook[used]=Pbk;
3728 used++;
3730 printmsgerr("%c Reading: %i percent",13,used*100/MemStatus.Used);
3731 i++;
3732 if (bshutdown) {
3733 GSM_Terminate();
3734 exit(0);
3737 printmsgerr("\n");
3739 DoBackup = false;
3740 if (Info.SIMPhonebook) {
3741 printmsg("Checking SIM phonebook\n");
3742 MemStatus.MemoryType = GMT_SM;
3743 error=Phone->GetMemoryStatus(&s, &MemStatus);
3744 if (error==GE_NONE && MemStatus.Used != 0) {
3745 if (answer_yes(" Backup SIM phonebook")) DoBackup=true;
3748 if (DoBackup) {
3749 Pbk.MemoryType = GMT_SM;
3750 i = 1;
3751 used = 0;
3752 while (used != MemStatus.Used) {
3753 Pbk.Location = i;
3754 error=Phone->GetMemory(&s, &Pbk);
3755 if (error != GE_EMPTY) {
3756 Print_Error(error);
3757 if (used < GSM_BACKUP_MAX_SIMPHONEBOOK) {
3758 Backup.SIMPhonebook[used] = malloc(sizeof(GSM_MemoryEntry));
3759 if (Backup.SIMPhonebook[used] == NULL) Print_Error(GE_MOREMEMORY);
3760 Backup.SIMPhonebook[used + 1] = NULL;
3761 } else {
3762 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SIMPHONEBOOK");
3763 GSM_Terminate();
3764 exit(-1);
3766 *Backup.SIMPhonebook[used]=Pbk;
3767 used++;
3769 printmsgerr("%c Reading: %i percent",13,used*100/MemStatus.Used);
3770 i++;
3771 if (bshutdown) {
3772 GSM_Terminate();
3773 exit(0);
3776 printmsgerr("\n");
3778 DoBackup = false;
3779 if (Info.Calendar) {
3780 printmsg("Checking calendar\n");
3781 error=Phone->GetNextCalendar(&s,&Note,true);
3782 if (error==GE_NONE) {
3783 if (answer_yes(" Backup calendar notes")) DoBackup = true;
3786 if (DoBackup) {
3787 used = 0;
3788 printmsgerr(" Reading : ");
3789 while (error == GE_NONE) {
3790 if (used < GSM_MAXCALENDARTODONOTES) {
3791 Backup.Calendar[used] = malloc(sizeof(GSM_CalendarEntry));
3792 if (Backup.Calendar[used] == NULL) Print_Error(GE_MOREMEMORY);
3793 Backup.Calendar[used+1] = NULL;
3794 } else {
3795 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES");
3796 GSM_Terminate();
3797 exit(-1);
3799 *Backup.Calendar[used]=Note;
3800 used ++;
3801 error=Phone->GetNextCalendar(&s,&Note,false);
3802 printmsgerr("*");
3803 if (bshutdown) {
3804 GSM_Terminate();
3805 exit(0);
3808 printmsgerr("\n");
3810 DoBackup = false;
3811 if (Info.ToDo) {
3812 printmsg("Checking ToDo\n");
3813 error=Phone->GetToDoStatus(&s,&ToDoStatus);
3814 if (error == GE_NONE && ToDoStatus.Used != 0) {
3815 if (answer_yes(" Backup ToDo")) DoBackup = true;
3818 if (DoBackup) {
3819 used = 0;
3820 error=Phone->GetNextToDo(&s,&ToDo,true);
3821 while (error == GE_NONE) {
3822 if (used < GSM_MAXCALENDARTODONOTES) {
3823 Backup.ToDo[used] = malloc(sizeof(GSM_ToDoEntry));
3824 if (Backup.ToDo[used] == NULL) Print_Error(GE_MOREMEMORY);
3825 Backup.ToDo[used+1] = NULL;
3826 } else {
3827 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES");
3828 GSM_Terminate();
3829 exit(-1);
3831 *Backup.ToDo[used]=ToDo;
3832 used ++;
3833 error=Phone->GetNextToDo(&s,&ToDo,false);
3834 printmsgerr("%c Reading: %i percent",13,used*100/ToDoStatus.Used);
3835 if (bshutdown) {
3836 GSM_Terminate();
3837 exit(0);
3840 printmsgerr("\n");
3842 DoBackup = false;
3843 if (Info.CallerLogos) {
3844 printmsg("Checking caller logos\n");
3845 Bitmap.Type = GSM_CallerLogo;
3846 Bitmap.Location = 1;
3847 error=Phone->GetBitmap(&s,&Bitmap);
3848 if (error == GE_NONE) {
3849 if (answer_yes(" Backup caller groups and logos")) DoBackup = true;
3852 if (DoBackup) {
3853 printmsgerr(" Reading : ");
3854 error = GE_NONE;
3855 used = 0;
3856 while (error == GE_NONE) {
3857 if (used < GSM_BACKUP_MAX_CALLER) {
3858 Backup.CallerLogos[used] = malloc(sizeof(GSM_Bitmap));
3859 if (Backup.CallerLogos[used] == NULL) Print_Error(GE_MOREMEMORY);
3860 Backup.CallerLogos[used+1] = NULL;
3861 } else {
3862 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CALLER");
3863 GSM_Terminate();
3864 exit(-1);
3866 *Backup.CallerLogos[used] = Bitmap;
3867 used ++;
3868 Bitmap.Location = used + 1;
3869 error=Phone->GetBitmap(&s,&Bitmap);
3870 printmsgerr("*");
3871 if (bshutdown) {
3872 GSM_Terminate();
3873 exit(0);
3876 printmsgerr("\n");
3878 DoBackup = false;
3879 if (Info.SMSC) {
3880 printmsg("Checking SMS profiles\n");
3881 if (answer_yes(" Backup SMS profiles")) DoBackup = true;
3883 if (DoBackup) {
3884 used = 0;
3885 printmsgerr(" Reading: ");
3886 while (true) {
3887 SMSC.Location = used + 1;
3888 error = Phone->GetSMSC(&s,&SMSC);
3889 if (error != GE_NONE) break;
3890 if (used < GSM_BACKUP_MAX_SMSC) {
3891 Backup.SMSC[used] = malloc(sizeof(GSM_SMSC));
3892 if (Backup.SMSC[used] == NULL) Print_Error(GE_MOREMEMORY);
3893 Backup.SMSC[used + 1] = NULL;
3894 } else {
3895 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMSC");
3896 GSM_Terminate();
3897 exit(-1);
3899 *Backup.SMSC[used]=SMSC;
3900 used++;
3901 printmsgerr("*");
3903 printmsgerr("\n");
3905 DoBackup = false;
3906 if (Info.StartupLogo) {
3907 printmsg("Checking startup text\n");
3908 Bitmap.Type = GSM_WelcomeNoteText;
3909 error = Phone->GetBitmap(&s,&Bitmap);
3910 if (error == GE_NONE) {
3911 if (answer_yes(" Backup startup logo/text")) DoBackup = true;
3914 if (DoBackup) {
3915 Backup.StartupLogo = malloc(sizeof(GSM_Bitmap));
3916 if (Backup.StartupLogo == NULL) Print_Error(GE_MOREMEMORY);
3917 *Backup.StartupLogo = Bitmap;
3918 if (Bitmap.Text[0]==0 && Bitmap.Text[1]==0) {
3919 Bitmap.Type = GSM_StartupLogo;
3920 error = Phone->GetBitmap(&s,&Bitmap);
3921 if (error == GE_NONE) *Backup.StartupLogo = Bitmap;
3924 DoBackup = false;
3925 if (Info.OperatorLogo) {
3926 printmsg("Checking operator logo\n");
3927 Bitmap.Type = GSM_OperatorLogo;
3928 error=Phone->GetBitmap(&s,&Bitmap);
3929 if (error == GE_NONE) {
3930 if (strcmp(Bitmap.NetworkCode,"000 00")!=0) {
3931 if (answer_yes(" Backup operator logo")) DoBackup = true;
3935 if (DoBackup) {
3936 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap));
3937 if (Backup.OperatorLogo == NULL) Print_Error(GE_MOREMEMORY);
3938 *Backup.OperatorLogo = Bitmap;
3940 DoBackup = false;
3941 if (Info.WAPBookmark) {
3942 printmsg("Checking WAP bookmarks\n");
3943 Bookmark.Location = 1;
3944 error=Phone->GetWAPBookmark(&s,&Bookmark);
3945 if (error==GE_NONE) {
3946 if (answer_yes(" Backup WAP bookmarks")) DoBackup = true;
3949 if (DoBackup) {
3950 used = 0;
3951 printmsgerr(" Reading : ");
3952 while (error == GE_NONE) {
3953 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) {
3954 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark));
3955 if (Backup.WAPBookmark[used] == NULL) Print_Error(GE_MOREMEMORY);
3956 Backup.WAPBookmark[used+1] = NULL;
3957 } else {
3958 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK");
3959 GSM_Terminate();
3960 exit(-1);
3962 *Backup.WAPBookmark[used]=Bookmark;
3963 used ++;
3964 Bookmark.Location = used+1;
3965 error=Phone->GetWAPBookmark(&s,&Bookmark);
3966 printmsgerr("*");
3967 if (bshutdown) {
3968 GSM_Terminate();
3969 exit(0);
3972 printmsgerr("\n");
3974 DoBackup = false;
3975 if (Info.WAPSettings) {
3976 printmsg("Checking WAP settings\n");
3977 Settings.Location = 1;
3978 error=Phone->GetWAPSettings(&s,&Settings);
3979 if (error==GE_NONE) {
3980 if (answer_yes(" Backup WAP settings")) DoBackup = true;
3983 if (DoBackup) {
3984 used = 0;
3985 printmsgerr(" Reading : ");
3986 while (error == GE_NONE) {
3987 if (used < GSM_BACKUP_MAX_WAPSETTINGS) {
3988 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
3989 if (Backup.WAPSettings[used] == NULL) Print_Error(GE_MOREMEMORY);
3990 Backup.WAPSettings[used+1] = NULL;
3991 } else {
3992 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS");
3993 GSM_Terminate();
3994 exit(-1);
3996 *Backup.WAPSettings[used]=Settings;
3997 used ++;
3998 Settings.Location = used+1;
3999 error=Phone->GetWAPSettings(&s,&Settings);
4000 printmsgerr("*");
4001 if (bshutdown) {
4002 GSM_Terminate();
4003 exit(0);
4006 printmsgerr("\n");
4008 DoBackup = false;
4009 if (Info.MMSSettings) {
4010 printmsg("Checking MMS settings\n");
4011 Settings.Location = 1;
4012 error=Phone->GetMMSSettings(&s,&Settings);
4013 if (error==GE_NONE) {
4014 if (answer_yes(" Backup MMS settings")) DoBackup = true;
4017 if (DoBackup) {
4018 used = 0;
4019 printmsgerr(" Reading : ");
4020 while (error == GE_NONE) {
4021 if (used < GSM_BACKUP_MAX_MMSSETTINGS) {
4022 Backup.MMSSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
4023 if (Backup.MMSSettings[used] == NULL) Print_Error(GE_MOREMEMORY);
4024 Backup.MMSSettings[used+1] = NULL;
4025 } else {
4026 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_MMSSETTINGS");
4027 GSM_Terminate();
4028 exit(-1);
4030 *Backup.MMSSettings[used]=Settings;
4031 used ++;
4032 Settings.Location = used+1;
4033 error=Phone->GetMMSSettings(&s,&Settings);
4034 printmsgerr("*");
4035 if (bshutdown) {
4036 GSM_Terminate();
4037 exit(0);
4040 printmsgerr("\n");
4042 DoBackup = false;
4043 if (Info.Ringtone) {
4044 printmsg("Checking user ringtones\n");
4045 Ringtone.Location = 1;
4046 Ringtone.Format = 0;
4047 error=Phone->GetRingtone(&s,&Ringtone,false);
4048 if (error==GE_EMPTY || error == GE_NONE) {
4049 if (answer_yes(" Backup user ringtones")) DoBackup = true;
4052 if (DoBackup) {
4053 used = 0;
4054 i = 1;
4055 printmsgerr(" Reading : ");
4056 while (error == GE_NONE || error == GE_EMPTY) {
4057 if (error == GE_NONE) {
4058 if (used < GSM_BACKUP_MAX_RINGTONES) {
4059 Backup.Ringtone[used] = malloc(sizeof(GSM_Ringtone));
4060 if (Backup.Ringtone[used] == NULL) Print_Error(GE_MOREMEMORY);
4061 Backup.Ringtone[used+1] = NULL;
4062 } else {
4063 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_RINGTONES");
4064 GSM_Terminate();
4065 exit(-1);
4067 *Backup.Ringtone[used]=Ringtone;
4068 used ++;
4070 i++;
4071 Ringtone.Location = i;
4072 Ringtone.Format = 0;
4073 error=Phone->GetRingtone(&s,&Ringtone,false);
4074 printmsgerr("*");
4075 if (bshutdown) {
4076 GSM_Terminate();
4077 exit(0);
4080 printmsgerr("\n");
4082 DoBackup = false;
4083 if (Info.Profiles) {
4084 printmsg("Checking phone profiles\n");
4085 Profile.Location = 1;
4086 error = Phone->GetProfile(&s,&Profile);
4087 if (error == GE_NONE) {
4088 if (answer_yes(" Backup phone profiles")) DoBackup = true;
4091 if (DoBackup) {
4092 used = 0;
4093 printmsgerr(" Reading: ");
4094 while (true) {
4095 Profile.Location = used + 1;
4096 error = Phone->GetProfile(&s,&Profile);
4097 if (error != GE_NONE) break;
4098 if (used < GSM_BACKUP_MAX_PROFILES) {
4099 Backup.Profiles[used] = malloc(sizeof(GSM_Profile));
4100 if (Backup.Profiles[used] == NULL) Print_Error(GE_MOREMEMORY);
4101 Backup.Profiles[used + 1] = NULL;
4102 } else {
4103 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PROFILES");
4104 GSM_Terminate();
4105 exit(-1);
4107 *Backup.Profiles[used]=Profile;
4108 used++;
4109 printmsgerr("*");
4111 printmsgerr("\n");
4113 DoBackup = false;
4114 if (Info.FMStation) {
4115 printmsg("Checking FM stations\n");
4116 FMStation.Location = 1;
4117 error = Phone->GetFMStation(&s,&FMStation);
4118 if (error == GE_NONE || error == GE_EMPTY) {
4119 if (answer_yes(" Backup phone FM stations")) DoBackup=true;
4122 if (DoBackup) {
4123 used = 0;
4124 i = 1;
4125 printmsgerr(" Reading: ");
4126 while (error == GE_NONE || error == GE_EMPTY) {
4127 error = Phone->GetFMStation(&s,&FMStation);
4128 if (error == GE_NONE) {
4129 if (used < GSM_BACKUP_MAX_FMSTATIONS) {
4130 Backup.FMStation[used] = malloc(sizeof(GSM_FMStation));
4131 if (Backup.FMStation[used] == NULL) Print_Error(GE_MOREMEMORY);
4132 Backup.FMStation[used + 1] = NULL;
4133 } else {
4134 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_FMSTATIONS");
4135 GSM_Terminate();
4136 exit(-1);
4138 *Backup.FMStation[used]=FMStation;
4139 used++;
4141 i++;
4142 FMStation.Location = i;
4143 printmsgerr("*");
4145 printmsgerr("\n");
4147 DoBackup = false;
4148 if (Info.GPRSPoint) {
4149 printmsg("Checking GPRS access points\n");
4150 GPRSPoint.Location = 1;
4151 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4152 if (error == GE_NONE || error == GE_EMPTY) {
4153 if (answer_yes(" Backup GPRS access points")) DoBackup = true;
4156 if (DoBackup) {
4157 used = 0;
4158 i = 1;
4159 printmsgerr(" Reading: ");
4160 while (error == GE_NONE || error == GE_EMPTY) {
4161 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4162 if (error == GE_NONE) {
4163 if (used < GSM_BACKUP_MAX_GPRSPOINT) {
4164 Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint));
4165 if (Backup.GPRSPoint[used] == NULL) Print_Error(GE_MOREMEMORY);
4166 Backup.GPRSPoint[used + 1] = NULL;
4167 } else {
4168 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_GPRSPOINT");
4169 GSM_Terminate();
4170 exit(-1);
4172 *Backup.GPRSPoint[used]=GPRSPoint;
4173 used++;
4175 i++;
4176 GPRSPoint.Location = i;
4177 printmsgerr("*");
4179 printmsgerr("\n");
4182 GSM_Terminate();
4184 GSM_SaveBackupFile(argv[2],&Backup, Info.UseUnicode);
4185 GSM_FreeBackup(&Backup);
4188 static void Restore(int argc, char *argv[])
4190 GSM_Backup Backup;
4191 GSM_FMStation FMStation;
4192 GSM_DateTime date_time;
4193 GSM_CalendarEntry Calendar;
4194 GSM_Bitmap Bitmap;
4195 GSM_Ringtone Ringtone;
4196 GSM_MemoryEntry Pbk;
4197 GSM_MemoryStatus MemStatus;
4198 GSM_ToDoEntry ToDo;
4199 GSM_ToDoStatus ToDoStatus;
4200 GSM_Profile Profile;
4201 GSM_MultiWAPSettings Settings;
4202 GSM_GPRSAccessPoint GPRSPoint;
4203 GSM_WAPBookmark Bookmark;
4204 int i, used, max = 0;
4205 bool Past = true;
4206 bool Found, DoRestore;
4208 error=GSM_ReadBackupFile(argv[2],&Backup);
4209 Print_Error(error);
4211 /* We do not want to make it forever - press Ctrl+C to stop */
4212 signal(SIGINT, interrupted);
4213 printmsgerr("If you want break, press Ctrl+C...\n");
4215 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
4216 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
4217 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
4219 if (Backup.MD5Calculated[0]!=0) {
4220 dbgprintf("\"%s\"\n",Backup.MD5Original);
4221 dbgprintf("\"%s\"\n",Backup.MD5Calculated);
4222 if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) {
4223 if (!answer_yes("Checksum in backup file do not match. Continue")) return;
4227 GSM_Init(true);
4229 DoRestore = false;
4230 if (Backup.PhonePhonebook[0] != NULL) {
4231 MemStatus.MemoryType = GMT_ME;
4232 error=Phone->GetMemoryStatus(&s, &MemStatus);
4233 if (error==GE_NONE) {
4234 max = 0;
4235 while (Backup.PhonePhonebook[max]!=NULL) max++;
4236 printmsgerr("%i entries in backup file\n",max);
4237 if (answer_yes("Restore phone phonebook")) DoRestore = true;
4240 if (DoRestore) {
4241 used = 0;
4242 for (i=0;i<MemStatus.Used+MemStatus.Free;i++) {
4243 Pbk.MemoryType = GMT_ME;
4244 Pbk.Location = i + 1;
4245 Pbk.EntriesNum = 0;
4246 if (used<max) {
4247 if (Backup.PhonePhonebook[used]->Location == Pbk.Location) {
4248 Pbk = *Backup.PhonePhonebook[used];
4249 used++;
4250 dbgprintf("Location %i\n",Pbk.Location);
4251 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk);
4254 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk);
4255 Print_Error(error);
4256 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.Used+MemStatus.Free));
4257 if (bshutdown) {
4258 GSM_Terminate();
4259 exit(0);
4262 printmsgerr("\n");
4265 DoRestore = false;
4266 if (Backup.SIMPhonebook[0] != NULL) {
4267 MemStatus.MemoryType = GMT_SM;
4268 error=Phone->GetMemoryStatus(&s, &MemStatus);
4269 if (error==GE_NONE) {
4270 max = 0;
4271 while (Backup.SIMPhonebook[max]!=NULL) max++;
4272 printmsgerr("%i entries in backup file\n",max);
4273 if (answer_yes("Restore SIM phonebook")) DoRestore = true;
4276 if (DoRestore) {
4277 used = 0;
4278 for (i=0;i<MemStatus.Used+MemStatus.Free;i++) {
4279 Pbk.MemoryType = GMT_SM;
4280 Pbk.Location = i + 1;
4281 Pbk.EntriesNum = 0;
4282 if (used<max) {
4283 if (Backup.SIMPhonebook[used]->Location == Pbk.Location) {
4284 Pbk = *Backup.SIMPhonebook[used];
4285 used++;
4286 dbgprintf("Location %i\n",Pbk.Location);
4287 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk);
4290 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk);
4291 Print_Error(error);
4292 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.Used+MemStatus.Free));
4293 if (bshutdown) {
4294 GSM_Terminate();
4295 exit(0);
4298 printmsgerr("\n");
4301 DoRestore = false;
4302 if (Backup.CallerLogos[0] != NULL) {
4303 Bitmap.Type = GSM_CallerLogo;
4304 Bitmap.Location = 1;
4305 error=Phone->GetBitmap(&s,&Bitmap);
4306 if (error == GE_NONE) {
4307 if (answer_yes("Restore caller groups and logos")) DoRestore = true;
4310 if (DoRestore) {
4311 max = 0;
4312 while (Backup.CallerLogos[max]!=NULL) max++;
4313 for (i=0;i<max;i++) {
4314 error=Phone->SetBitmap(&s,Backup.CallerLogos[i]);
4315 Print_Error(error);
4316 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4317 if (bshutdown) {
4318 GSM_Terminate();
4319 exit(0);
4322 printmsgerr("\n");
4325 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) {
4326 if (answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")) {
4327 GSM_GetCurrentDateTime(&date_time);
4329 error=Phone->SetDateTime(&s, &date_time);
4330 Print_Error(error);
4333 DoRestore = false;
4334 if (Backup.Calendar[0] != NULL) {
4335 /* N6110 doesn't support getting calendar status */
4336 error = Phone->GetNextCalendar(&s,&Calendar,true);
4337 if (error == GE_NONE || error == GE_INVALIDLOCATION || error == GE_EMPTY) {
4338 max = 0;
4339 while (Backup.Calendar[max] != NULL) max++;
4340 printmsgerr("%i entries in backup file\n",max);
4341 if (answer_yes("Restore calendar notes")) {
4342 Past = answer_yes("Restore notes from the past");
4343 DoRestore = true;
4347 if (DoRestore) {
4348 printmsgerr("Deleting old notes: ");
4349 error = Phone->DeleteAllCalendar(&s);
4350 if (error == GE_NOTSUPPORTED || error == GE_NOTIMPLEMENTED) {
4351 while (1) {
4352 error = Phone->GetNextCalendar(&s,&Calendar,true);
4353 if (error != GE_NONE) break;
4354 error = Phone->DeleteCalendar(&s,&Calendar);
4355 Print_Error(error);
4356 printmsgerr("*");
4358 printmsgerr("\n");
4359 } else {
4360 printmsgerr("Done\n");
4361 Print_Error(error);
4364 for (i=0;i<max;i++) {
4365 if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue;
4367 Calendar = *Backup.Calendar[i];
4368 error=Phone->AddCalendar(&s,&Calendar);
4369 Print_Error(error);
4370 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4371 if (bshutdown) {
4372 GSM_Terminate();
4373 exit(0);
4376 printmsgerr("\n");
4379 DoRestore = false;
4380 if (Backup.ToDo[0] != NULL) {
4381 error = Phone->GetToDoStatus(&s,&ToDoStatus);
4382 if (error == GE_NONE) {
4383 max = 0;
4384 while (Backup.ToDo[max]!=NULL) max++;
4385 printmsgerr("%i entries in backup file\n",max);
4387 if (answer_yes("Restore ToDo")) DoRestore = true;
4390 if (DoRestore) {
4391 ToDo = *Backup.ToDo[0];
4392 error = Phone->SetToDo(&s,&ToDo);
4394 if (DoRestore && (error == GE_NOTSUPPORTED || error == GE_NOTIMPLEMENTED)) {
4395 printmsgerr("Deleting old ToDo: ");
4396 error=Phone->DeleteAllToDo(&s);
4397 if (error == GE_NOTSUPPORTED || error == GE_NOTIMPLEMENTED) {
4398 while (1) {
4399 error = Phone->GetNextToDo(&s,&ToDo,true);
4400 if (error != GE_NONE) break;
4401 error = Phone->DeleteToDo(&s,&ToDo);
4402 Print_Error(error);
4403 printmsgerr("*");
4405 printmsgerr("\n");
4406 } else {
4407 printmsgerr("Done\n");
4408 Print_Error(error);
4411 for (i=0;i<max;i++) {
4412 ToDo = *Backup.ToDo[i];
4413 ToDo.Location = 0;
4414 error=Phone->AddToDo(&s,&ToDo);
4415 Print_Error(error);
4416 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4417 if (bshutdown) {
4418 GSM_Terminate();
4419 exit(0);
4422 printmsgerr("\n");
4423 } else if (DoRestore) {
4424 /* At first delete entries, that were deleted */
4425 used = 0;
4426 error = Phone->GetNextToDo(&s,&ToDo,true);
4427 while (error == GE_NONE) {
4428 used++;
4429 Found = false;
4430 for (i=0;i<max;i++) {
4431 if (Backup.ToDo[i]->Location == ToDo.Location) {
4432 Found = true;
4433 break;
4436 if (!Found) {
4437 error=Phone->DeleteToDo(&s,&ToDo);
4438 Print_Error(error);
4440 error = Phone->GetNextToDo(&s,&ToDo,false);
4441 printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used);
4442 if (bshutdown) {
4443 GSM_Terminate();
4444 exit(0);
4447 printmsgerr("\n");
4449 /* Now write modified/new entries */
4450 for (i=0;i<max;i++) {
4451 ToDo = *Backup.ToDo[i];
4452 error = Phone->SetToDo(&s,&ToDo);
4453 Print_Error(error);
4454 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4455 if (bshutdown) {
4456 GSM_Terminate();
4457 exit(0);
4460 printmsgerr("\n");
4463 if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) {
4464 max = 0;
4465 while (Backup.SMSC[max]!=NULL) max++;
4466 for (i=0;i<max;i++) {
4467 error=Phone->SetSMSC(&s,Backup.SMSC[i]);
4468 Print_Error(error);
4469 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4470 if (bshutdown) {
4471 GSM_Terminate();
4472 exit(0);
4475 printmsgerr("\n");
4477 if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) {
4478 error=Phone->SetBitmap(&s,Backup.StartupLogo);
4479 Print_Error(error);
4481 if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) {
4482 error=Phone->SetBitmap(&s,Backup.OperatorLogo);
4483 Print_Error(error);
4485 DoRestore = false;
4486 if (Backup.WAPBookmark[0] != NULL) {
4487 Bookmark.Location = 1;
4488 error = Phone->GetWAPBookmark(&s,&Bookmark);
4489 if (error == GE_NONE || error == GE_INVALIDLOCATION) {
4490 if (answer_yes("Restore WAP bookmarks")) DoRestore = true;
4493 if (DoRestore) {
4494 printmsgerr("Deleting old bookmarks: ");
4495 /* One thing to explain: DCT4 phones seems to have bug here.
4496 * When delete for example first bookmark, phone change
4497 * numeration for getting frame, not for deleting. So, we try to
4498 * get 1'st bookmark. Inside frame is "correct" location. We use
4499 * it later
4501 while (error==GE_NONE) {
4502 error = Phone->DeleteWAPBookmark(&s,&Bookmark);
4503 Bookmark.Location = 1;
4504 error = Phone->GetWAPBookmark(&s,&Bookmark);
4505 printmsgerr("*");
4507 printmsgerr("\n");
4508 max = 0;
4509 while (Backup.WAPBookmark[max]!=NULL) max++;
4510 for (i=0;i<max;i++) {
4511 Bookmark = *Backup.WAPBookmark[i];
4512 Bookmark.Location = 0;
4513 error=Phone->SetWAPBookmark(&s,&Bookmark);
4514 Print_Error(error);
4515 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4516 if (bshutdown) {
4517 GSM_Terminate();
4518 exit(0);
4521 printmsgerr("\n");
4523 DoRestore = false;
4524 if (Backup.WAPSettings[0] != NULL) {
4525 Settings.Location = 1;
4526 error = Phone->GetWAPSettings(&s,&Settings);
4527 if (error == GE_NONE) {
4528 if (answer_yes("Restore WAP settings")) DoRestore = true;
4531 if (DoRestore) {
4532 max = 0;
4533 while (Backup.WAPSettings[max]!=NULL) max++;
4534 for (i=0;i<max;i++) {
4535 error=Phone->SetWAPSettings(&s,Backup.WAPSettings[i]);
4536 Print_Error(error);
4537 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4538 if (bshutdown) {
4539 GSM_Terminate();
4540 exit(0);
4543 printmsgerr("\n");
4545 DoRestore = false;
4546 if (Backup.MMSSettings[0] != NULL) {
4547 Settings.Location = 1;
4548 error = Phone->GetMMSSettings(&s,&Settings);
4549 if (error == GE_NONE) {
4550 if (answer_yes("Restore MMS settings")) DoRestore = true;
4553 if (DoRestore) {
4554 max = 0;
4555 while (Backup.MMSSettings[max]!=NULL) max++;
4556 for (i=0;i<max;i++) {
4557 error=Phone->SetMMSSettings(&s,Backup.MMSSettings[i]);
4558 Print_Error(error);
4559 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4560 if (bshutdown) {
4561 GSM_Terminate();
4562 exit(0);
4565 printmsgerr("\n");
4567 DoRestore = false;
4568 if (Backup.Ringtone[0] != NULL) {
4569 Ringtone.Location = 1;
4570 Ringtone.Format = 0;
4571 error = Phone->GetRingtone(&s,&Ringtone,false);
4572 if (error == GE_NONE || error ==GE_EMPTY) {
4573 if (Phone->DeleteUserRingtones != NOTSUPPORTED) {
4574 if (answer_yes("Delete all user ringtones")) DoRestore = true;
4578 if (DoRestore) {
4579 printmsgerr("Deleting: ");
4580 error=Phone->DeleteUserRingtones(&s);
4581 Print_Error(error);
4582 printmsgerr("Done\n");
4583 DoRestore = false;
4584 if (answer_yes("Restore user ringtones")) DoRestore = true;
4586 if (DoRestore) {
4587 max = 0;
4588 while (Backup.Ringtone[max]!=NULL) max++;
4589 for (i=0;i<max;i++) {
4590 error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format);
4591 Print_Error(error);
4592 error=Phone->SetRingtone(&s,&Ringtone,&i);
4593 Print_Error(error);
4594 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4595 if (bshutdown) {
4596 GSM_Terminate();
4597 exit(0);
4600 printmsgerr("\n");
4602 DoRestore = false;
4603 if (Backup.Profiles[0] != NULL) {
4604 Profile.Location = 1;
4605 error = Phone->GetProfile(&s,&Profile);
4606 if (error == GE_NONE) {
4607 if (answer_yes("Restore profiles")) DoRestore = true;
4610 if (DoRestore) {
4611 Profile.Location= 0;
4612 max = 0;
4613 while (Backup.Profiles[max]!=NULL) max++;
4614 for (i=0;i<max;i++) {
4615 Profile = *Backup.Profiles[i];
4616 error=Phone->SetProfile(&s,&Profile);
4617 Print_Error(error);
4618 if (bshutdown) {
4619 GSM_Terminate();
4620 exit(0);
4623 printmsgerr("\n");
4625 DoRestore = false;
4626 if (Backup.FMStation[0] != NULL) {
4627 FMStation.Location = 1;
4628 error = Phone->GetFMStation(&s,&FMStation);
4629 if (error == GE_NONE || error == GE_EMPTY) {
4630 if (answer_yes("Restore FM stations")) DoRestore = true;
4633 if (DoRestore) {
4634 printmsgerr("Deleting old FM stations: ");
4635 error=Phone->ClearFMStations(&s);
4636 Print_Error(error);
4637 printmsgerr("Done\n");
4638 max = 0;
4639 while (Backup.FMStation[max]!=NULL) max++;
4640 for (i=0;i<max;i++) {
4641 FMStation = *Backup.FMStation[i];
4642 error=Phone->SetFMStation(&s,&FMStation);
4643 Print_Error(error);
4644 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4645 if (bshutdown) {
4646 GSM_Terminate();
4647 exit(0);
4650 printmsgerr("\n");
4652 DoRestore = false;
4653 if (Backup.GPRSPoint[0] != NULL) {
4654 GPRSPoint.Location = 1;
4655 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4656 if (error == GE_NONE || error == GE_EMPTY) {
4657 if (answer_yes("Restore GPRS Points")) DoRestore = true;
4660 if (DoRestore) {
4661 max = 0;
4662 while (Backup.GPRSPoint[max]!=NULL) max++;
4663 for (i=0;i<max;i++) {
4664 error=Phone->SetGPRSAccessPoint(&s,Backup.GPRSPoint[i]);
4665 Print_Error(error);
4666 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4667 if (bshutdown) {
4668 GSM_Terminate();
4669 exit(0);
4672 printmsgerr("\n");
4675 GSM_Terminate();
4678 static void AddNew(int argc, char *argv[])
4680 GSM_Backup Backup;
4681 GSM_DateTime date_time;
4682 GSM_MemoryEntry Pbk;
4683 GSM_MemoryStatus MemStatus;
4684 GSM_ToDoEntry ToDo;
4685 GSM_ToDoStatus ToDoStatus;
4686 GSM_CalendarEntry Calendar;
4687 GSM_WAPBookmark Bookmark;
4688 int i, max, j;
4690 error=GSM_ReadBackupFile(argv[2],&Backup);
4691 Print_Error(error);
4693 /* We do not want to make it forever - press Ctrl+C to stop */
4694 signal(SIGINT, interrupted);
4695 printmsgerr("If you want break, press Ctrl+C...\n");
4697 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
4698 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
4699 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
4701 GSM_Init(true);
4703 if (Backup.PhonePhonebook[0] != NULL) {
4704 MemStatus.MemoryType = GMT_ME;
4705 error=Phone->GetMemoryStatus(&s, &MemStatus);
4706 if (error==GE_NONE) {
4707 max = 0;
4708 while (Backup.PhonePhonebook[max]!=NULL) max++;
4709 printmsgerr("%i entries in backup file\n",max);
4710 if (MemStatus.Free < max) {
4711 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.Free);
4712 } else if (answer_yes("Add phone phonebook entries")) {
4713 for (i=0;i<max;i++) {
4714 Pbk = *Backup.PhonePhonebook[i];
4715 Pbk.MemoryType = GMT_ME;
4716 error=Phone->AddMemory(&s, &Pbk);
4717 Print_Error(error);
4718 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4719 if (bshutdown) {
4720 GSM_Terminate();
4721 exit(0);
4724 printmsgerr("\n");
4728 if (Backup.SIMPhonebook[0] != NULL) {
4729 MemStatus.MemoryType = GMT_SM;
4730 error=Phone->GetMemoryStatus(&s, &MemStatus);
4731 if (error==GE_NONE) {
4732 max = 0;
4733 while (Backup.SIMPhonebook[max]!=NULL) max++;
4734 printmsgerr("%i entries in backup file\n",max);
4735 if (MemStatus.Free < max) {
4736 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.Free);
4737 } else if (answer_yes("Add SIM phonebook entries")) {
4738 j = 1;
4739 for (i=0;i<max;i++) {
4740 Pbk = *Backup.SIMPhonebook[i];
4741 Pbk.MemoryType = GMT_SM;
4742 error=Phone->AddMemory(&s, &Pbk);
4743 Print_Error(error);
4744 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4745 if (bshutdown) {
4746 GSM_Terminate();
4747 exit(0);
4750 printmsgerr("\n");
4755 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) {
4756 if (answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")) {
4757 GSM_GetCurrentDateTime(&date_time);
4759 error=Phone->SetDateTime(&s, &date_time);
4760 Print_Error(error);
4763 if (Backup.Calendar[0] != NULL) {
4764 error = Phone->GetNextCalendar(&s,&Calendar,true);
4765 if (error == GE_NONE || error == GE_INVALIDLOCATION || error == GE_EMPTY) {
4766 if (answer_yes("Add calendar notes")) {
4767 max = 0;
4768 while (Backup.Calendar[max]!=NULL) max++;
4769 for (i=0;i<max;i++) {
4770 Calendar = *Backup.Calendar[i];
4771 error=Phone->AddCalendar(&s,&Calendar);
4772 Print_Error(error);
4773 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4774 if (bshutdown) {
4775 GSM_Terminate();
4776 exit(0);
4779 printmsgerr("\n");
4783 if (Backup.ToDo[0] != NULL) {
4784 ToDo.Location = 1;
4785 error=Phone->GetToDoStatus(&s,&ToDoStatus);
4786 if (error == GE_NONE) {
4787 if (answer_yes("Add ToDo")) {
4788 max = 0;
4789 while (Backup.ToDo[max]!=NULL) max++;
4790 for (i=0;i<max;i++) {
4791 ToDo = *Backup.ToDo[i];
4792 error = Phone->AddToDo(&s,&ToDo);
4793 Print_Error(error);
4794 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4795 if (bshutdown) {
4796 GSM_Terminate();
4797 exit(0);
4800 printmsgerr("\n");
4804 if (Backup.WAPBookmark[0] != NULL) {
4805 Bookmark.Location = 1;
4806 error = Phone->GetWAPBookmark(&s,&Bookmark);
4807 if (error == GE_NONE || error == GE_INVALIDLOCATION) {
4808 if (answer_yes("Add WAP bookmarks")) {
4809 max = 0;
4810 while (Backup.WAPBookmark[max]!=NULL) max++;
4811 for (i=0;i<max;i++) {
4812 Bookmark = *Backup.WAPBookmark[i];
4813 Bookmark.Location = 0;
4814 error=Phone->SetWAPBookmark(&s,&Bookmark);
4815 Print_Error(error);
4816 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4817 if (bshutdown) {
4818 GSM_Terminate();
4819 exit(0);
4822 printmsgerr("\n");
4827 GSM_Terminate();
4829 #endif
4831 static void ClearAll(int argc, char *argv[])
4833 GSM_MemoryStatus MemStatus;
4834 GSM_ToDoStatus ToDoStatus;
4835 GSM_CalendarEntry Calendar;
4836 GSM_ToDoEntry ToDo;
4837 GSM_WAPBookmark Bookmark;
4838 GSM_FMStation Station;
4839 GSM_MemoryEntry Pbk;
4840 bool DoClear;
4842 GSM_Init(true);
4844 DoClear = false;
4845 MemStatus.MemoryType = GMT_ME;
4846 error=Phone->GetMemoryStatus(&s, &MemStatus);
4847 if (error==GE_NONE && MemStatus.Used !=0) {
4848 if (answer_yes("Delete phone phonebook")) DoClear = true;
4850 if (DoClear) {
4851 error = Phone->DeleteAllMemory(&s,GMT_ME);
4852 if (error == GE_NOTSUPPORTED || error == GE_NOTIMPLEMENTED) {
4853 for (i=0;i<MemStatus.Used+MemStatus.Free;i++) {
4854 Pbk.MemoryType = GMT_ME;
4855 Pbk.Location = i + 1;
4856 Pbk.EntriesNum = 0;
4857 error=Phone->DeleteMemory(&s, &Pbk);
4858 Print_Error(error);
4859 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.Used+MemStatus.Free));
4860 if (bshutdown) {
4861 GSM_Terminate();
4862 exit(0);
4865 printmsgerr("\n");
4866 } else {
4867 printmsgerr("Done\n");
4868 Print_Error(error);
4872 DoClear = false;
4873 MemStatus.MemoryType = GMT_SM;
4874 error=Phone->GetMemoryStatus(&s, &MemStatus);
4875 if (error==GE_NONE && MemStatus.Used !=0) {
4876 if (answer_yes("Delete SIM phonebook")) DoClear = true;
4878 if (DoClear) {
4879 error = Phone->DeleteAllMemory(&s,GMT_SM);
4880 if (error == GE_NOTSUPPORTED || error == GE_NOTIMPLEMENTED) {
4881 for (i=0;i<MemStatus.Used+MemStatus.Free;i++) {
4882 Pbk.MemoryType = GMT_SM;
4883 Pbk.Location = i + 1;
4884 Pbk.EntriesNum = 0;
4885 error=Phone->DeleteMemory(&s, &Pbk);
4886 Print_Error(error);
4887 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.Used+MemStatus.Free));
4888 if (bshutdown) {
4889 GSM_Terminate();
4890 exit(0);
4893 printmsgerr("\n");
4894 } else {
4895 printmsgerr("Done\n");
4896 Print_Error(error);
4900 DoClear = false;
4901 error = Phone->GetNextCalendar(&s,&Calendar,true);
4902 if (error == GE_NONE) {
4903 if (answer_yes("Delete calendar notes")) DoClear = true;
4905 if (DoClear) {
4906 printmsgerr("Deleting: ");
4907 error=Phone->DeleteAllCalendar(&s);
4908 if (error == GE_NOTSUPPORTED || error == GE_NOTIMPLEMENTED) {
4909 while (1) {
4910 error = Phone->GetNextCalendar(&s,&Calendar,true);
4911 if (error != GE_NONE) break;
4912 error = Phone->DeleteCalendar(&s,&Calendar);
4913 Print_Error(error);
4914 printmsgerr("*");
4916 printmsgerr("\n");
4917 } else {
4918 printmsgerr("Done\n");
4919 Print_Error(error);
4923 DoClear = false;
4924 error = Phone->GetToDoStatus(&s,&ToDoStatus);
4925 if (error == GE_NONE && ToDoStatus.Used != 0) {
4926 if (answer_yes("Delete ToDo")) DoClear = true;
4928 if (DoClear) {
4929 printmsgerr("Deleting: ");
4930 error=Phone->DeleteAllToDo(&s);
4931 if (error == GE_NOTSUPPORTED || error == GE_NOTIMPLEMENTED) {
4932 while (1) {
4933 error = Phone->GetNextToDo(&s,&ToDo,true);
4934 if (error != GE_NONE) break;
4935 error = Phone->DeleteToDo(&s,&ToDo);
4936 Print_Error(error);
4937 printmsgerr("*");
4939 printmsgerr("\n");
4940 } else {
4941 printmsgerr("Done\n");
4942 Print_Error(error);
4946 Bookmark.Location = 1;
4947 error = Phone->GetWAPBookmark(&s,&Bookmark);
4948 if (error == GE_NONE || error == GE_INVALIDLOCATION) {
4949 if (answer_yes("Delete WAP bookmarks")) {
4950 printmsgerr("Deleting: ");
4951 /* One thing to explain: DCT4 phones seems to have bug here.
4952 * When delete for example first bookmark, phone change
4953 * numeration for getting frame, not for deleting. So, we try to
4954 * get 1'st bookmark. Inside frame is "correct" location. We use
4955 * it later
4957 while (error==GE_NONE) {
4958 error = Phone->DeleteWAPBookmark(&s,&Bookmark);
4959 Bookmark.Location = 1;
4960 error = Phone->GetWAPBookmark(&s,&Bookmark);
4961 printmsgerr("*");
4963 printmsgerr("\n");
4966 if (Phone->DeleteUserRingtones != NOTSUPPORTED) {
4967 if (answer_yes("Delete all user ringtones")) {
4968 printmsgerr("Deleting: ");
4969 error=Phone->DeleteUserRingtones(&s);
4970 Print_Error(error);
4971 printmsgerr("Done\n");
4974 Station.Location=i;
4975 error=Phone->GetFMStation(&s,&Station);
4976 if (error == GE_NONE || error == GE_EMPTY) {
4977 if (answer_yes("Delete all FM station")) {
4978 error=Phone->ClearFMStations(&s);
4979 Print_Error(error);
4983 GSM_Terminate();
4986 static void GetWAPMMSSettings(int argc, char *argv[])
4988 GSM_MultiWAPSettings settings;
4989 int start,stop,j;
4991 GetStartStop(&start, &stop, 2, argc, argv);
4993 GSM_Init(true);
4995 for (i=start;i<=stop;i++) {
4996 settings.Location=i;
4997 if (mystrncasecmp(argv[1],"--getwapsettings",0)) {
4998 error=Phone->GetWAPSettings(&s,&settings);
4999 } else {
5000 error=Phone->GetMMSSettings(&s,&settings);
5002 Print_Error(error);
5003 for (j=0;j<settings.Number;j++) {
5004 printmsg("%i. ",i);
5005 if (settings.Settings[j].Title[0]==0 && settings.Settings[j].Title[1]==0)
5007 printmsg("Set %i",i);
5008 } else {
5009 printmsg("%s",DecodeUnicodeConsole(settings.Settings[j].Title));
5011 if (settings.Active) printmsg(" (active)");
5012 printmsg("\nHomepage : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].HomePage));
5013 if (settings.Settings[j].IsContinuous) {
5014 printmsg("Connection type : Continuous\n");
5015 } else {
5016 printmsg("Connection type : Temporary\n");
5018 if (settings.Settings[j].IsSecurity) {
5019 printmsg("Connection security : On\n");
5020 } else {
5021 printmsg("Connection security : Off\n");
5023 switch (settings.Settings[j].Bearer) {
5024 case WAPSETTINGS_BEARER_SMS:
5025 printmsg("Bearer : SMS");
5026 if (settings.ActiveBearer == WAPSETTINGS_BEARER_SMS) printf(" (active)");
5027 printmsg("\nServer number : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].Server));
5028 printmsg("Service number : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].Service));
5029 break;
5030 case WAPSETTINGS_BEARER_DATA:
5031 printmsg("Bearer : Data (CSD)");
5032 if (settings.ActiveBearer == WAPSETTINGS_BEARER_DATA) printf(" (active)");
5033 printmsg("\nDial-up number : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].DialUp));
5034 printmsg("IP address : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].IPAddress));
5035 if (settings.Settings[j].ManualLogin) {
5036 printmsg("Login Type : Manual\n");
5037 } else {
5038 printmsg("Login Type : Automatic\n");
5040 if (settings.Settings[j].IsNormalAuthentication) {
5041 printmsg("Authentication type : Normal\n");
5042 } else {
5043 printmsg("Authentication type : Secure\n");
5045 if (settings.Settings[j].IsISDNCall) {
5046 printmsg("Data call type : ISDN\n");
5047 } else {
5048 printmsg("Data call type : Analogue\n");
5050 switch (settings.Settings[j].Speed) {
5051 case WAPSETTINGS_SPEED_9600 : printmsg("Data call speed : 9600\n"); break;
5052 case WAPSETTINGS_SPEED_14400 : printmsg("Data call speed : 14400\n"); break;
5053 case WAPSETTINGS_SPEED_AUTO : printmsg("Data call speed : Auto\n"); break;
5055 printmsg("User name : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].User));
5056 printmsg("Password : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].Password));
5057 break;
5058 case WAPSETTINGS_BEARER_USSD:
5059 printmsg("Bearer : USSD");
5060 if (settings.ActiveBearer == WAPSETTINGS_BEARER_USSD) printf(" (active)");
5061 printmsg("\nService code : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].Code));
5062 if (settings.Settings[j].IsIP) {
5063 printmsg("Address type : IP address\nIPaddress : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].Service));
5064 } else {
5065 printmsg("Address type : Service number\nService number : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].Service));
5067 break;
5068 case WAPSETTINGS_BEARER_GPRS:
5069 printmsg("Bearer : GPRS");
5070 if (settings.ActiveBearer == WAPSETTINGS_BEARER_GPRS) printf(" (active)");
5071 if (settings.Settings[j].ManualLogin) {
5072 printmsg("\nLogin Type : Manual\n");
5073 } else {
5074 printmsg("\nLogin Type : Automatic\n");
5076 if (settings.Settings[j].IsNormalAuthentication) {
5077 printmsg("Authentication type : Normal\n");
5078 } else {
5079 printmsg("Authentication type : Secure\n");
5081 printmsg("Access point : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].DialUp));
5082 printmsg("IP address : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].IPAddress));
5083 printmsg("User name : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].User));
5084 printmsg("Password : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].Password));
5086 printf("\n");
5089 GSM_Terminate();
5092 #ifdef GSM_ENABLE_BACKUP
5093 static void BackupSMS(int argc, char *argv[])
5095 GSM_SMS_Backup Backup;
5096 GSM_MultiSMSMessage sms;
5097 GSM_SMSFolders folders;
5098 bool BackupFromFolder[GSM_MAX_SMS_FOLDERS];
5099 bool start = true;
5100 bool DeleteAfter;
5101 int j, smsnum;
5102 char buffer[200];
5104 /* We ignore return code, because (when file doesn't exist) we
5105 * will create new later
5107 GSM_ReadSMSBackupFile(argv[2], &Backup);
5108 smsnum = 0;
5109 while (Backup.SMS[smsnum]!=NULL) smsnum++;
5111 GSM_Init(true);
5113 error=Phone->GetSMSFolders(&s, &folders);
5114 Print_Error(error);
5116 DeleteAfter=answer_yes("Delete each sms after backup");
5118 for (j=0;j<folders.Number;j++) {
5119 BackupFromFolder[j] = false;
5120 sprintf(buffer,"Backup sms from folder \"%s\"",DecodeUnicodeConsole(folders.Folder[j].Name));
5121 if (answer_yes(buffer)) BackupFromFolder[j] = true;
5124 while (error == GE_NONE) {
5125 sms.SMS[0].Folder=0x00;
5126 error=Phone->GetNextSMS(&s, &sms, start);
5127 switch (error) {
5128 case GE_EMPTY:
5129 break;
5130 default:
5131 Print_Error(error);
5132 for (j=0;j<sms.Number;j++) {
5133 if (BackupFromFolder[sms.SMS[j].Folder-1]) {
5134 switch (sms.SMS[j].PDU) {
5135 case SMS_Status_Report:
5136 break;
5137 case SMS_Submit:
5138 case SMS_Deliver:
5139 if (sms.SMS[j].Length == 0) break;
5140 if (smsnum < GSM_BACKUP_MAX_SMS) {
5141 Backup.SMS[smsnum] = malloc(sizeof(GSM_SMSMessage));
5142 if (Backup.SMS[smsnum] == NULL) Print_Error(GE_MOREMEMORY);
5143 Backup.SMS[smsnum+1] = NULL;
5144 } else {
5145 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMS");
5146 GSM_Terminate();
5147 exit(-1);
5149 *Backup.SMS[smsnum] = sms.SMS[j];
5150 smsnum++;
5151 break;
5156 start=false;
5159 error = GSM_SaveSMSBackupFile(argv[2],&Backup);
5160 Print_Error(error);
5162 if (DeleteAfter) {
5163 for (j=0;j<smsnum;j++) {
5164 Backup.SMS[j]->Folder = 0;
5165 error=Phone->DeleteSMS(&s, Backup.SMS[j]);
5166 Print_Error(error);
5167 printmsgerr("%cDeleting: %i percent",13,(j+1)*100/smsnum);
5171 GSM_Terminate();
5174 static void RestoreSMS(int argc, char *argv[])
5176 GSM_MultiSMSMessage SMS;
5177 GSM_SMS_Backup Backup;
5178 GSM_SMSFolders folders;
5179 int smsnum = 0;
5180 char buffer[200];
5182 error=GSM_ReadSMSBackupFile(argv[2], &Backup);
5183 Print_Error(error);
5185 GSM_Init(true);
5187 error=Phone->GetSMSFolders(&s, &folders);
5188 Print_Error(error);
5190 while (Backup.SMS[smsnum] != NULL) {
5191 SMS.Number = 1;
5192 memcpy(&SMS.SMS[0],Backup.SMS[smsnum],sizeof(GSM_SMSMessage));
5193 displaymultismsinfo(SMS,false,false);
5194 sprintf(buffer,"Restore sms to folder \"%s\"",DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder-1].Name));
5195 if (answer_yes(buffer)) {
5196 Backup.SMS[smsnum]->Location = 0;
5197 error=Phone->SetSMS(&s, Backup.SMS[smsnum]);
5198 Print_Error(error);
5200 smsnum++;
5203 GSM_Terminate();
5205 #endif
5207 static void CopyBitmap(int argc, char *argv[])
5209 GSM_MultiBitmap Bitmap;
5210 int i;
5212 Bitmap.Bitmap[0].Type = GSM_None;
5214 error=GSM_ReadBitmapFile(argv[2],&Bitmap);
5215 Print_Error(error);
5217 if (argc==3) {
5218 for (i=0;i<Bitmap.Number;i++) {
5219 switch (Bitmap.Bitmap[i].Type) {
5220 case GSM_StartupLogo : printmsg("Startup logo"); break;
5221 case GSM_OperatorLogo: printmsg("Operator logo"); break;
5222 case GSM_PictureImage: printmsg("Picture Image"); break;
5223 case GSM_CallerLogo : printmsg("Caller group logo"); break;
5224 default : break;
5226 printmsg(", width %i, height %i\n",Bitmap.Bitmap[i].Width,Bitmap.Bitmap[i].Height);
5227 GSM_PrintBitmap(stdout,&Bitmap.Bitmap[i]);
5229 } else {
5230 if (argc == 5) {
5231 for (i=0;i<Bitmap.Number;i++) {
5232 if (mystrncasecmp(argv[4],"PICTURE",0)) {
5233 Bitmap.Bitmap[i].Type = GSM_PictureImage;
5234 } else if (mystrncasecmp(argv[4],"STARTUP",0)) {
5235 Bitmap.Bitmap[i].Type = GSM_StartupLogo;
5236 } else if (mystrncasecmp(argv[4],"CALLER",0)) {
5237 Bitmap.Bitmap[i].Type = GSM_CallerLogo;
5238 } else if (mystrncasecmp(argv[4],"OPERATOR",0)) {
5239 Bitmap.Bitmap[i].Type = GSM_OperatorLogo;
5240 } else {
5241 printmsg("What format of output file logo (\"%s\") ?\n",argv[4]);
5242 exit(-1);
5246 error=GSM_SaveBitmapFile(argv[3],&Bitmap);
5247 Print_Error(error);
5251 static void NokiaComposer(int argc, char *argv[])
5253 GSM_Ringtone ringtone;
5254 bool started;
5255 int i,j;
5256 GSM_RingNote *Note;
5257 GSM_RingNoteDuration Duration;
5258 GSM_RingNoteDuration DefNoteDuration = 32; /* 32 = Duration_1_4 */
5259 unsigned int DefNoteScale = Scale_880;
5261 ringtone.Format = 0;
5262 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
5264 if (ringtone.Format != RING_NOTETONE) {
5265 printmsg("It can be RTTL ringtone only used with this option\n");
5266 exit(-1);
5269 started = false;
5270 j = 0;
5271 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
5272 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
5273 Note = &ringtone.NoteTone.Commands[i].Note;
5274 if (!started) {
5275 if (Note->Note != Note_Pause) {
5276 printmsg("Ringtone \"%s\" (tempo = %i Beats Per Minute)\n\n",DecodeUnicodeConsole(ringtone.Name),GSM_RTTLGetTempo(Note->Tempo));
5277 started = true;
5280 if (started) j++;
5283 if (j>50) printmsg("WARNING: LENGTH=%i NOTES, BUT YOU WILL ENTER ONLY FIRST 50 TONES.",j);
5285 printmsg("\n\nThis ringtone in Nokia Composer in phone should look: ");
5286 started = false;
5287 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
5288 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
5289 Note = &ringtone.NoteTone.Commands[i].Note;
5290 if (!started) {
5291 if (Note->Note != Note_Pause) started = true;
5293 if (started) {
5294 switch (Note->Duration) {
5295 case Duration_Full: printmsg("1"); break;
5296 case Duration_1_2 : printmsg("2"); break;
5297 case Duration_1_4 : printmsg("4"); break;
5298 case Duration_1_8 : printmsg("8"); break;
5299 case Duration_1_16: printmsg("16");break;
5300 case Duration_1_32: printmsg("32");break;
5302 if (Note->DurationSpec == DottedNote) printmsg(".");
5303 switch (Note->Note) {
5304 case Note_C : printmsg("c"); break;
5305 case Note_Cis : printmsg("#c"); break;
5306 case Note_D :printmsg("d"); break;
5307 case Note_Dis : printmsg("#d"); break;
5308 case Note_E : printmsg("e"); break;
5309 case Note_F : printmsg("f"); break;
5310 case Note_Fis : printmsg("#f"); break;
5311 case Note_G : printmsg("g"); break;
5312 case Note_Gis : printmsg("#g"); break;
5313 case Note_A : printmsg("a"); break;
5314 case Note_Ais : printmsg("#a"); break;
5315 case Note_H : printmsg("h"); break;
5316 case Note_Pause : printmsg("-"); break;
5318 if (Note->Note != Note_Pause) printmsg("%i",Note->Scale - 4);
5319 printmsg(" ");
5324 printmsg("\n\nTo enter it please press: ");
5325 started = false;
5326 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
5327 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
5328 Note = &ringtone.NoteTone.Commands[i].Note;
5329 if (!started) {
5330 if (Note->Note != Note_Pause) started = true;
5332 if (started) {
5333 switch (Note->Note) {
5334 case Note_C : case Note_Cis: printmsg("1");break;
5335 case Note_D : case Note_Dis: printmsg("2");break;
5336 case Note_E : printmsg("3");break;
5337 case Note_F : case Note_Fis: printmsg("4");break;
5338 case Note_G : case Note_Gis: printmsg("5");break;
5339 case Note_A : case Note_Ais: printmsg("6");break;
5340 case Note_H : printmsg("7");break;
5341 default : printmsg("0");break;
5343 if (Note->DurationSpec == DottedNote) printmsg("(longer)");
5344 switch (Note->Note) {
5345 case Note_Cis: case Note_Dis:
5346 case Note_Fis: case Note_Gis:
5347 case Note_Ais:
5348 printmsg("#");
5349 break;
5350 default :
5351 break;
5353 if (Note->Note != Note_Pause) {
5354 if ((unsigned int)Note->Scale != DefNoteScale) {
5355 while (DefNoteScale != (unsigned int)Note->Scale) {
5356 printmsg("*");
5357 DefNoteScale++;
5358 if (DefNoteScale==Scale_7040) DefNoteScale = Scale_880;
5362 Duration = 0;
5363 switch (Note->Duration) {
5364 case Duration_Full : Duration = 128; break;
5365 case Duration_1_2 : Duration = 64; break;
5366 case Duration_1_4 : Duration = 32; break;
5367 case Duration_1_8 : Duration = 16; break;
5368 case Duration_1_16 : Duration = 8; break;
5369 case Duration_1_32 : Duration = 4; break;
5370 default : dbgprintf("error\n");break;
5372 if (Duration > DefNoteDuration) {
5373 while (DefNoteDuration != Duration) {
5374 printmsg("9");
5375 DefNoteDuration = DefNoteDuration * 2;
5378 if (Duration < DefNoteDuration) {
5379 while (DefNoteDuration != Duration) {
5380 printmsg("8");
5381 DefNoteDuration = DefNoteDuration / 2;
5384 printmsg(" ");
5389 printf("\n");
5392 static void CopyRingtone(int argc, char *argv[])
5394 GSM_Ringtone ringtone, ringtone2;
5395 GSM_RingtoneFormat Format;
5397 ringtone.Format = 0;
5398 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
5399 Print_Error(error);
5401 Format = ringtone.Format;
5402 if (argc == 5) {
5403 if (mystrncasecmp(argv[4],"RTTL",0)) { Format = RING_NOTETONE;
5404 } else if (mystrncasecmp(argv[4],"BINARY",0)) { Format = RING_NOKIABINARY;
5405 } else {
5406 printmsg("What format of output ringtone file (\"%s\") ?\n",argv[4]);
5407 exit(-1);
5411 error=GSM_RingtoneConvert(&ringtone2,&ringtone,Format);
5412 Print_Error(error);
5414 error=GSM_SaveRingtoneFile(argv[3],&ringtone2);
5415 Print_Error(error);
5418 static void PressKeySequence(int argc, char *argv[])
5420 int i,Length;
5421 GSM_KeyCode KeyCode[500];
5423 error = MakeKeySequence(argv[2], KeyCode, &Length);
5424 if (error == GE_NOTSUPPORTED) {
5425 printmsg("Unknown key/function name: \"%c\"\n",argv[2][Length]);
5426 exit(-1);
5429 GSM_Init(true);
5431 for (i=0;i<Length;i++) {
5432 error=Phone->PressKey(&s, KeyCode[i], true);
5433 Print_Error(error);
5434 error=Phone->PressKey(&s, KeyCode[i], false);
5435 Print_Error(error);
5438 GSM_Terminate();
5441 static void GetAllCategories(int argc, char *argv[])
5443 GSM_Category Category;
5444 GSM_CategoryStatus Status;
5445 int j, count;
5447 if (mystrncasecmp(argv[2],"TODO",0)) {
5448 Category.Type = Category_ToDo;
5449 Status.Type = Category_ToDo;
5450 } else if (mystrncasecmp(argv[2],"PHONEBOOK",0)) {
5451 Category.Type = Category_Phonebook;
5452 Status.Type = Category_Phonebook;
5453 } else {
5454 printmsg("What type of categories do you want to get (\"%s\") ?\n",argv[2]);
5455 exit(-1);
5458 GSM_Init(true);
5460 error=Phone->GetCategoryStatus(&s, &Status);
5461 Print_Error(error);
5463 for (count=0,j=1;count<Status.Used;j++)
5465 Category.Location=j;
5466 error=Phone->GetCategory(&s, &Category);
5468 if (error != GE_EMPTY) {
5469 printmsg("Location: %i\n",j);
5471 Print_Error(error);
5473 printmsg("Name : \"%s\"\n\n",DecodeUnicodeConsole(Category.Name));
5474 count++;
5478 GSM_Terminate();
5481 static void GetCategory(int argc, char *argv[])
5483 GSM_Category Category;
5484 int start,stop,j;
5486 if (mystrncasecmp(argv[2],"TODO",0)) {
5487 Category.Type = Category_ToDo;
5488 } else if (mystrncasecmp(argv[2],"PHONEBOOK",0)) {
5489 Category.Type = Category_Phonebook;
5490 } else {
5491 printmsg("What type of categories do you want to get (\"%s\") ?\n",argv[2]);
5492 exit(-1);
5495 GetStartStop(&start, &stop, 2, argc - 1, argv + 1);
5497 GSM_Init(true);
5499 for (j=start;j<=stop;j++)
5501 printmsg("Location: %i\n",j);
5503 Category.Location=j;
5505 error=Phone->GetCategory(&s, &Category);
5506 if (error != GE_EMPTY) Print_Error(error);
5508 if (error == GE_EMPTY) {
5509 printmsg("Entry is empty\n\n");
5510 } else {
5511 printmsg("Name : \"%s\"\n\n",DecodeUnicodeConsole(Category.Name));
5515 GSM_Terminate();
5518 static void DeleteToDo(int argc, char *argv[])
5520 GSM_ToDoEntry ToDo;
5521 int i;
5522 int start,stop;
5524 GetStartStop(&start, &stop, 2, argc, argv);
5526 GSM_Init(true);
5528 for (i=start;i<=stop;i++) {
5529 ToDo.Location=i;
5530 printmsg("Location : %i\n",i);
5531 error=Phone->DeleteToDo(&s,&ToDo);
5532 if (error != GE_EMPTY) Print_Error(error);
5534 if (error == GE_EMPTY) {
5535 printmsg("Entry was empty\n");
5536 } else {
5537 printmsg("Entry was deleted\n");
5539 printf("\n");
5542 GSM_Terminate();
5545 static void PrintToDo(GSM_ToDoEntry *ToDo)
5547 int j;
5548 GSM_MemoryEntry entry;
5549 unsigned char *name;
5550 GSM_Category Category;
5552 printmsg("Location : %i\n",ToDo->Location);
5553 printmsg("Priority : ");
5554 switch (ToDo->Priority) {
5555 case GSM_Priority_Low : printmsg("Low\n"); break;
5556 case GSM_Priority_Medium : printmsg("Medium\n"); break;
5557 case GSM_Priority_High : printmsg("High\n"); break;
5558 default : printmsg("Unknown\n"); break;
5560 for (j=0;j<ToDo->EntriesNum;j++) {
5561 switch (ToDo->Entries[j].EntryType) {
5562 case TODO_END_DATETIME:
5563 printmsg("DueTime : %s\n",OSDateTime(ToDo->Entries[j].Date,false));
5564 break;
5565 case TODO_COMPLETED:
5566 printmsg("Completed : %s\n",ToDo->Entries[j].Number == 1 ? "Yes" : "No");
5567 break;
5568 case TODO_ALARM_DATETIME:
5569 printmsg("Alarm : %s\n",OSDateTime(ToDo->Entries[j].Date,false));
5570 break;
5571 case TODO_SILENT_ALARM_DATETIME:
5572 printmsg("Silent alarm : %s\n",OSDateTime(ToDo->Entries[j].Date,false));
5573 break;
5574 case TODO_TEXT:
5575 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
5576 break;
5577 case TODO_PRIVATE:
5578 printmsg("Private : %s\n",ToDo->Entries[j].Number == 1 ? "Yes" : "No");
5579 break;
5580 case TODO_CATEGORY:
5581 Category.Location = ToDo->Entries[j].Number;
5582 Category.Type = Category_ToDo;
5583 error=Phone->GetCategory(&s, &Category);
5584 if (error == GE_NONE) {
5585 printmsg("Category : \"%s\" (%i)\n", DecodeUnicodeConsole(Category.Name), ToDo->Entries[j].Number);
5586 } else {
5587 printmsg("Category : %i\n", ToDo->Entries[j].Number);
5589 break;
5590 case TODO_CONTACTID:
5591 entry.Location = ToDo->Entries[j].Number;
5592 entry.MemoryType = GMT_ME;
5593 error=Phone->GetMemory(&s, &entry);
5594 if (error == GE_NONE) {
5595 name = GSM_PhonebookGetEntryName(&entry);
5596 if (name != NULL) {
5597 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number);
5598 } else {
5599 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
5601 } else {
5602 printmsg("Contact : %d\n",ToDo->Entries[j].Number);
5604 break;
5605 case TODO_PHONE:
5606 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
5607 break;
5610 printf("\n");
5613 static void ListToDoCategoryEntries(int Category)
5615 GSM_ToDoEntry Entry;
5616 bool start = true;
5617 int j;
5619 while (1) {
5620 if (bshutdown) break;
5621 error = Phone->GetNextToDo(&s, &Entry, start);
5622 if (error == GE_EMPTY) break;
5623 Print_Error(error);
5624 for (j=0;j<Entry.EntriesNum;j++) {
5625 if (Entry.Entries[j].EntryType == TODO_CATEGORY && Entry.Entries[j].Number == Category)
5626 PrintToDo(&Entry);
5628 start = false;
5632 static void ListToDoCategory(int argc, char *argv[])
5634 GSM_Category Category;
5635 GSM_CategoryStatus Status;
5636 int j, count;
5638 unsigned char Text[(GSM_MAX_CATEGORY_NAME_LENGTH+1)*2];
5639 int Length;
5640 bool Number = true;;
5642 GSM_Init(true);
5644 signal(SIGINT, interrupted);
5645 printmsgerr("If you want break, press Ctrl+C...\n");
5647 Length = strlen(argv[2]);
5648 for (j = 0; j < Length; j++) {
5649 if (!isdigit(argv[2][j])) {
5650 Number = false;
5651 break;
5655 if (Number) {
5656 j = atoi(argv[2]);
5657 if (j > 0) {
5658 ListToDoCategoryEntries(j);
5660 } else {
5661 if (Length > GSM_MAX_CATEGORY_NAME_LENGTH) {
5662 printmsg("Search text too long, truncating to %d chars!\n", GSM_MAX_CATEGORY_NAME_LENGTH);
5663 Length = GSM_MAX_CATEGORY_NAME_LENGTH;
5665 EncodeUnicode(Text, argv[2], Length);
5667 Category.Type = Category_ToDo;
5668 Status.Type = Category_ToDo;
5670 if (Phone->GetCategoryStatus(&s, &Status) == GE_NONE) {
5671 for (count=0,j=1;count<Status.Used;j++) {
5672 Category.Location=j;
5673 error=Phone->GetCategory(&s, &Category);
5675 if (error != GE_EMPTY) {
5676 count++;
5677 if (mystrstr(Category.Name, Text) != NULL) {
5678 ListToDoCategoryEntries(j);
5684 GSM_Terminate();
5688 static void GetToDo(int argc, char *argv[])
5690 GSM_ToDoEntry ToDo;
5691 int i;
5692 int start,stop;
5694 GetStartStop(&start, &stop, 2, argc, argv);
5696 GSM_Init(true);
5698 for (i=start;i<=stop;i++) {
5699 ToDo.Location=i;
5700 error = Phone->GetToDo(&s,&ToDo);
5701 if (error == GE_EMPTY) continue;
5702 Print_Error(error);
5703 PrintToDo(&ToDo);
5706 GSM_Terminate();
5709 static void GetAllToDo(int argc, char *argv[])
5711 GSM_ToDoEntry ToDo;
5712 bool start = true;
5714 GSM_Init(true);
5716 while (1) {
5717 error = Phone->GetNextToDo(&s, &ToDo, start);
5718 if (error == GE_EMPTY) break;
5719 Print_Error(error);
5720 PrintToDo(&ToDo);
5721 start = false;
5724 GSM_Terminate();
5727 static void GetNote(int argc, char *argv[])
5729 GSM_NoteEntry Note;
5730 int start,stop;
5731 bool refresh=true;
5733 GetStartStop(&start, &stop, 2, argc, argv);
5735 GSM_Init(true);
5737 for (i=start;i<=stop;i++) {
5738 Note.Location=i;
5739 printmsg("Location : %i\n",i);
5740 error=Phone->GetNote(&s,&Note,refresh);
5741 if (error != GE_EMPTY) Print_Error(error);
5743 if (error == GE_EMPTY) {
5744 printmsg("Entry is empty\n\n");
5745 } else {
5746 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note.Text));
5747 printf("\n");
5748 refresh=false;
5752 GSM_Terminate();
5755 static void GetSecurityStatus(int argc, char *argv[])
5757 GSM_Init(true);
5759 PrintSecurityStatus();
5761 GSM_Terminate();
5764 static void EnterSecurityCode(int argc, char *argv[])
5766 GSM_SecurityCode Code;
5768 if (mystrncasecmp(argv[2],"PIN",0)) { Code.Type = GSCT_Pin;
5769 } else if (mystrncasecmp(argv[2],"PUK",0)) { Code.Type = GSCT_Puk;
5770 } else if (mystrncasecmp(argv[2],"PIN2",0)) { Code.Type = GSCT_Pin2;
5771 } else if (mystrncasecmp(argv[2],"PUK2",0)) { Code.Type = GSCT_Puk2;
5772 } else {
5773 printmsg("What security code (\"%s\") ?\n",argv[2]);
5774 exit(-1);
5777 strcpy(Code.Code,argv[3]);
5779 GSM_Init(true);
5781 error=Phone->EnterSecurityCode(&s,Code);
5782 Print_Error(error);
5784 GSM_Terminate();
5787 static void GetProfile(int argc, char *argv[])
5789 GSM_Profile Profile;
5790 int start,stop,j,k;
5791 GSM_Bitmap caller[5];
5792 bool callerinit[5],special;
5793 GSM_AllRingtonesInfo Info;
5795 GetStartStop(&start, &stop, 2, argc, argv);
5797 for (i=0;i<5;i++) callerinit[i] = false;
5799 GSM_Init(true);
5801 error=Phone->GetRingtonesInfo(&s,&Info);
5802 if (error != GE_NONE) Info.Number = 0;
5804 for (i=start;i<=stop;i++) {
5805 Profile.Location=i;
5806 error=Phone->GetProfile(&s,&Profile);
5807 Print_Error(error);
5809 printmsg("%i. \"%s\"",i,DecodeUnicodeConsole(Profile.Name));
5810 if (Profile.Active) printmsg(" (active)");
5811 if (Profile.DefaultName) printmsg(" (default name)");
5812 if (Profile.HeadSetProfile) printmsg(" (HeadSet profile)");
5813 if (Profile.CarKitProfile) printmsg(" (CarKit profile)");
5814 printf("\n");
5815 for (j=0;j<Profile.FeaturesNumber;j++) {
5816 special = false;
5817 switch (Profile.FeatureID[j]) {
5818 case Profile_MessageToneID:
5819 case Profile_RingtoneID:
5820 special = true;
5821 if (Profile.FeatureID[j] == Profile_RingtoneID) {
5822 printmsg("Ringtone ID : ");
5823 } else {
5824 printmsg("Message alert tone ID : ");
5826 if (UnicodeLength(GSM_GetRingtoneName(&Info,Profile.FeatureValue[j]))!=0) {
5827 printmsg("\"%s\"\n",DecodeUnicodeConsole(GSM_GetRingtoneName(&Info,Profile.FeatureValue[j])));
5828 } else {
5829 printmsg("%i\n",Profile.FeatureValue[j]);
5831 break;
5832 case Profile_CallerGroups:
5833 special = true;
5834 printmsg("Call alert for :");
5835 for (k=0;k<5;k++) {
5836 if (Profile.CallerGroups[k]) {
5837 if (!callerinit[k]) {
5838 caller[k].Type = GSM_CallerLogo;
5839 caller[k].Location = k + 1;
5840 error=Phone->GetBitmap(&s,&caller[k]);
5841 if (error == GE_SECURITYERROR) {
5842 NOKIA_GetDefaultCallerGroupName(&s,&caller[k]);
5843 } else {
5844 Print_Error(error);
5846 callerinit[k] = true;
5848 printmsg(" \"%s\"",DecodeUnicodeConsole(caller[k].Text));
5851 printf("\n");
5852 break;
5853 case Profile_ScreenSaverNumber:
5854 special = true;
5855 printmsg("Screen saver number : ");
5856 printmsg("%i\n",Profile.FeatureValue[j]);
5857 break;
5858 case Profile_CallAlert : printmsg("Incoming call alert : "); break;
5859 case Profile_RingtoneVolume : printmsg("Ringtone volume : "); break;
5860 case Profile_Vibration : printmsg("Vibrating alert : "); break;
5861 case Profile_MessageTone : printmsg("Message alert tone : "); break;
5862 case Profile_KeypadTone : printmsg("Keypad tones : "); break;
5863 case Profile_WarningTone : printmsg("Warning (games) tones : "); break;
5864 case Profile_ScreenSaver : printmsg("Screen saver : "); break;
5865 case Profile_ScreenSaverTime : printmsg("Screen saver timeout : "); break;
5866 case Profile_AutoAnswer : printmsg("Automatic answer : "); break;
5867 case Profile_Lights : printmsg("Lights : "); break;
5868 default:
5869 printmsg("Unknown\n");
5870 special = true;
5872 if (!special) {
5873 switch (Profile.FeatureValue[j]) {
5874 case PROFILE_VOLUME_LEVEL1 :
5875 case PROFILE_KEYPAD_LEVEL1 : printmsg("Level 1\n"); break;
5876 case PROFILE_VOLUME_LEVEL2 :
5877 case PROFILE_KEYPAD_LEVEL2 : printmsg("Level 2\n"); break;
5878 case PROFILE_VOLUME_LEVEL3 :
5879 case PROFILE_KEYPAD_LEVEL3 : printmsg("Level 3\n"); break;
5880 case PROFILE_VOLUME_LEVEL4 : printmsg("Level 4\n"); break;
5881 case PROFILE_VOLUME_LEVEL5 : printmsg("Level 5\n"); break;
5882 case PROFILE_MESSAGE_NOTONE :
5883 case PROFILE_AUTOANSWER_OFF :
5884 case PROFILE_LIGHTS_OFF :
5885 case PROFILE_SAVER_OFF :
5886 case PROFILE_WARNING_OFF :
5887 case PROFILE_CALLALERT_OFF :
5888 case PROFILE_VIBRATION_OFF :
5889 case PROFILE_KEYPAD_OFF : printmsg("Off\n"); break;
5890 case PROFILE_CALLALERT_RINGING : printmsg("Ringing\n"); break;
5891 case PROFILE_CALLALERT_BEEPONCE :
5892 case PROFILE_MESSAGE_BEEPONCE : printmsg("Beep once\n"); break;
5893 case PROFILE_CALLALERT_RINGONCE : printmsg("Ring once\n"); break;
5894 case PROFILE_CALLALERT_ASCENDING : printmsg("Ascending\n"); break;
5895 case PROFILE_CALLALERT_CALLERGROUPS : printmsg("Caller groups\n"); break;
5896 case PROFILE_MESSAGE_STANDARD : printmsg("Standard\n"); break;
5897 case PROFILE_MESSAGE_SPECIAL : printmsg("Special\n"); break;
5898 case PROFILE_MESSAGE_ASCENDING : printmsg("Ascending\n"); break;
5899 case PROFILE_MESSAGE_PERSONAL : printmsg("Personal\n"); break;
5900 case PROFILE_AUTOANSWER_ON :
5901 case PROFILE_WARNING_ON :
5902 case PROFILE_SAVER_ON :
5903 case PROFILE_VIBRATION_ON : printmsg("On\n"); break;
5904 case PROFILE_VIBRATION_FIRST : printmsg("Vibrate first\n"); break;
5905 case PROFILE_LIGHTS_AUTO : printmsg("Auto\n"); break;
5906 case PROFILE_SAVER_TIMEOUT_5SEC : printmsg("5 seconds\n"); break;
5907 case PROFILE_SAVER_TIMEOUT_20SEC : printmsg("20 seconds\n"); break;
5908 case PROFILE_SAVER_TIMEOUT_1MIN : printmsg("1 minute\n"); break;
5909 case PROFILE_SAVER_TIMEOUT_2MIN : printmsg("2 minutes\n"); break;
5910 case PROFILE_SAVER_TIMEOUT_5MIN : printmsg("5 minutes\n"); break;
5911 case PROFILE_SAVER_TIMEOUT_10MIN : printmsg("10 minutes\n"); break;
5912 default : printmsg("UNKNOWN\n");
5916 printf("\n");
5919 GSM_Terminate();
5922 static void GetSpeedDial(int argc, char *argv[])
5924 GSM_SpeedDial SpeedDial;
5925 GSM_MemoryEntry Phonebook;
5926 int start,stop,Name,Number,Group;
5928 GetStartStop(&start, &stop, 2, argc, argv);
5930 GSM_Init(true);
5932 for (i=start;i<=stop;i++) {
5933 SpeedDial.Location=i;
5934 error=Phone->GetSpeedDial(&s,&SpeedDial);
5935 printmsg("%i.",i);
5936 switch (error) {
5937 case GE_EMPTY:
5938 printmsg(" speed dial not assigned\n");
5939 break;
5940 default:
5941 Print_Error(error);
5943 Phonebook.Location = SpeedDial.MemoryLocation;
5944 Phonebook.MemoryType = SpeedDial.MemoryType;
5945 error=Phone->GetMemory(&s,&Phonebook);
5947 GSM_PhonebookFindDefaultNameNumberGroup(&Phonebook, &Name, &Number, &Group);
5949 if (Name != -1) printmsg(" Name \"%s\",",DecodeUnicodeConsole(Phonebook.Entries[Name].Text));
5950 printmsg(" Number \"%s\"",DecodeUnicodeConsole(Phonebook.Entries[SpeedDial.MemoryNumberID-1].Text));
5952 printf("\n");
5955 GSM_Terminate();
5958 static void ResetPhoneSettings(int argc, char *argv[])
5960 GSM_ResetSettingsType Type;
5962 if (mystrncasecmp(argv[2],"PHONE",0)) { Type = GSM_RESET_PHONESETTINGS;
5963 } else if (mystrncasecmp(argv[2],"UIF",0)) { Type = GSM_RESET_USERINTERFACE;
5964 } else if (mystrncasecmp(argv[2],"ALL",0)) { Type = GSM_RESET_USERINTERFACE_PHONESETTINGS;
5965 } else if (mystrncasecmp(argv[2],"DEV",0)) { Type = GSM_RESET_DEVICE;
5966 } else if (mystrncasecmp(argv[2],"FACTORY",0)) { Type = GSM_RESET_FULLFACTORY;
5967 } else {
5968 printmsg("What type of reset phone settings (\"%s\") ?\n",argv[2]);
5969 exit(-1);
5972 GSM_Init(true);
5974 error=Phone->ResetPhoneSettings(&s,Type);
5975 Print_Error(error);
5977 GSM_Terminate();
5980 #if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
5981 static void NokiaSecurityCode(int argc, char *argv[])
5983 GSM_Init(true);
5985 #ifdef GSM_ENABLE_NOKIA_DCT3
5986 DCT3GetSecurityCode(argc,argv);
5987 #endif
5988 #ifdef GSM_ENABLE_NOKIA_DCT4
5989 // DCT4ResetSecurityCode(argc, argv);
5990 DCT4GetSecurityCode(argc,argv);
5991 #endif
5993 GSM_Terminate();
5996 static void NokiaSetPhoneMenus(int argc, char *argv[])
5998 GSM_Init(true);
6000 #ifdef GSM_ENABLE_NOKIA_DCT3
6001 DCT3SetPhoneMenus (argc, argv);
6002 #endif
6003 #ifdef GSM_ENABLE_NOKIA_DCT4
6004 DCT4SetPhoneMenus (argc, argv);
6005 #endif
6007 GSM_Terminate();
6010 static void NokiaSelfTests(int argc, char *argv[])
6012 GSM_Init(true);
6014 #ifdef GSM_ENABLE_NOKIA_DCT3
6015 DCT3SelfTests(argc, argv);
6016 #endif
6017 #ifdef GSM_ENABLE_NOKIA_DCT4
6018 DCT4SelfTests(argc, argv);
6019 #endif
6021 GSM_Terminate();
6023 #endif
6025 static void DeleteAllSMS(int argc, char *argv[])
6027 GSM_MultiSMSMessage sms;
6028 GSM_SMSFolders folders;
6029 int foldernum;
6030 bool start = true;
6032 GSM_Init(true);
6034 error=Phone->GetSMSFolders(&s, &folders);
6035 Print_Error(error);
6037 GetStartStop(&foldernum, NULL, 2, argc, argv);
6038 if (foldernum > folders.Number) {
6039 printmsg("Too high folder number (max. %i)\n",folders.Number);
6040 GSM_Terminate();
6041 exit(-1);
6044 printmsg("Deleting SMS from \"%s\" folder: ",DecodeUnicodeConsole(folders.Folder[foldernum-1].Name));
6046 while (error == GE_NONE) {
6047 sms.SMS[0].Folder=0x00;
6048 error=Phone->GetNextSMS(&s, &sms, start);
6049 switch (error) {
6050 case GE_EMPTY:
6051 break;
6052 default:
6053 Print_Error(error);
6054 if (sms.SMS[0].Folder == foldernum) {
6055 sms.SMS[0].Folder=0x00;
6056 error=Phone->DeleteSMS(&s, &sms.SMS[0]);
6057 Print_Error(error);
6058 printmsg("*");
6061 start=false;
6064 printf("\n");
6066 GSM_Terminate();
6069 static void SendDTMF(int argc, char *argv[])
6071 GSM_Init(true);
6073 error=Phone->SendDTMF(&s,argv[2]);
6074 Print_Error(error);
6076 GSM_Terminate();
6079 static void GetDisplayStatus(int argc, char *argv[])
6081 GSM_DisplayFeatures Features;
6082 int i;
6084 GSM_Init(true);
6086 error=Phone->GetDisplayStatus(&s,&Features);
6087 Print_Error(error);
6089 printmsg("Current display features :\n");
6091 for (i=0;i<Features.Number;i++) {
6092 switch(Features.Feature[i]) {
6093 case GSM_CallActive : printmsg("Call active\n"); break;
6094 case GSM_UnreadSMS : printmsg("Unread SMS\n"); break;
6095 case GSM_VoiceCall : printmsg("Voice call\n"); break;
6096 case GSM_FaxCall : printmsg("Fax call\n"); break;
6097 case GSM_DataCall : printmsg("Data call\n"); break;
6098 case GSM_KeypadLocked : printmsg("Keypad locked\n"); break;
6099 case GSM_SMSMemoryFull : printmsg("SMS memory full\n");
6103 GSM_Terminate();
6106 static void SetAutoNetworkLogin(int argc, char *argv[])
6108 GSM_Init(true);
6110 error=Phone->SetAutoNetworkLogin(&s);
6111 Print_Error(error);
6113 GSM_Terminate();
6116 #ifdef DEBUG
6117 static void MakeConvertTable(int argc, char *argv[])
6119 unsigned char InputBuffer[10000], Buffer[10000];
6120 FILE *file;
6121 int size,i,j=0;
6123 file = fopen(argv[2], "rb");
6124 if (file == NULL) Print_Error(GE_CANTOPENFILE);
6125 size=fread(InputBuffer, 1, 10000-1, file);
6126 fclose(file);
6127 InputBuffer[size] = 0;
6128 InputBuffer[size+1] = 0;
6130 ReadUnicodeFile(Buffer,InputBuffer);
6132 for(i=0;i<((int)UnicodeLength(Buffer));i++) {
6133 j++;
6134 if (j==100) {
6135 printf("\"\\\n\"");
6136 j=0;
6138 printf("\\x%02x\\x%02x",Buffer[i*2],Buffer[i*2+1]);
6140 printf("\\x00\\x00");
6142 #endif
6144 static void ListNetworks(int argc, char *argv[])
6146 extern unsigned char *GSM_Networks[];
6147 int i=0;
6149 printmsg("Network Name\n");
6150 printmsg("-----------------------------------------\n");
6151 while (GSM_Networks[i*2]!=NULL) {
6152 printmsg("%-7s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]);
6153 i++;
6157 static void Version(int argc, char *argv[])
6159 // unsigned char buff[10];
6160 // int len;
6162 printmsg("[Gammu version %s built %s %s]\n\n",VERSION,__TIME__,__DATE__);
6164 #ifdef DEBUG
6165 printf("GSM_SMSMessage - %i\n",sizeof(GSM_SMSMessage));
6166 printf("GSM_SMSC - %i\n",sizeof(GSM_SMSC));
6167 printf("GSM_SMS_State - %i\n",sizeof(GSM_SMS_State));
6168 printf("GSM_UDHHeader - %i\n",sizeof(GSM_UDHHeader));
6169 printf("bool - %i\n",sizeof(bool));
6170 printf("GSM_DateTime - %i\n",sizeof(GSM_DateTime));
6171 printf("int - %i\n",sizeof(int));
6172 printf("GSM_NetworkInfo - %i\n",sizeof(GSM_NetworkInfo));
6173 #endif
6175 // len=DecodeBASE64("AXw", buff, 3);
6176 // DumpMessage(stdout, buff, len);
6179 static void GetFMStation(int argc, char *argv[])
6181 GSM_FMStation Station;
6182 int start,stop;
6184 GetStartStop(&start, &stop, 2, argc, argv);
6186 GSM_Init(true);
6188 for (i=start;i<=stop;i++) {
6189 Station.Location=i;
6190 error=Phone->GetFMStation(&s,&Station);
6191 switch (error) {
6192 case GE_EMPTY:
6193 printmsg("Entry number %i is empty\n",i);
6194 break;
6195 case GE_NONE:
6196 printmsg("Entry number %i\nStation name : \"%s\"\nFrequency : %.1f MHz\n",
6197 i,DecodeUnicodeConsole(Station.StationName),
6198 Station.Frequency);
6199 break;
6200 default:
6201 Print_Error(error);
6204 GSM_Terminate();
6207 static void GetFileSystemStatus(int argc, char *argv[])
6209 GSM_FileSystemStatus Status;
6211 GSM_Init(true);
6213 error = Phone->GetFileSystemStatus(&s,&Status);
6214 if (error != GE_NOTSUPPORTED && error != GE_NOTIMPLEMENTED) {
6215 Print_Error(error);
6216 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used);
6219 GSM_Terminate();
6222 static void GetFileSystem(int argc, char *argv[])
6224 bool Start = true;
6225 GSM_File Files;
6226 int j;
6227 GSM_FileSystemStatus Status;
6229 GSM_Init(true);
6231 while (1) {
6232 error = Phone->GetNextFileFolder(&s,&Files,Start);
6233 if (error == GE_EMPTY) break;
6234 Print_Error(error);
6236 if (strlen(Files.ID_FullName) < 5 && strlen(Files.ID_FullName) != 0) {
6237 printf("%5s.",Files.ID_FullName);
6239 if (Files.Protected) {
6240 printf("P");
6241 } else {
6242 printf(" ");
6244 if (Files.ReadOnly) {
6245 printf("R");
6246 } else {
6247 printf(" ");
6249 if (Files.Hidden) {
6250 printf("H");
6251 } else {
6252 printf(" ");
6254 if (Files.System) {
6255 printf("S");
6256 } else {
6257 printf(" ");
6259 if (argc > 2 && (mystrncasecmp(argv[2],"-flatall",0) || mystrncasecmp(argv[2],"-flat",0))) {
6260 if (!Files.Folder) {
6261 if (mystrncasecmp(argv[2],"-flatall",0)) {
6262 if (!Files.ModifiedEmpty) {
6263 printf(" %30s",OSDateTime(Files.Modified,false));
6264 } else printf(" %30c",0x20);
6265 printf(" %9i",Files.Used);
6266 printf(" ");
6267 } else printf("|-- ");
6268 } else printf("Folder ");
6269 } else {
6270 if (Files.Level != 1) {
6271 for (j=0;j<Files.Level-2;j++) printf(" | ");
6272 printf(" |-- ");
6274 if (Files.Folder) printf("Folder ");
6276 printf("\"%s\"",DecodeUnicodeConsole(Files.Name));
6277 printf("\n");
6279 Start = false;
6282 error = Phone->GetFileSystemStatus(&s,&Status);
6283 if (error != GE_NOTSUPPORTED && error != GE_NOTIMPLEMENTED) {
6284 Print_Error(error);
6285 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used);
6288 GSM_Terminate();
6291 static void GetFiles(int argc, char *argv[])
6293 GSM_File File;
6294 int i;
6295 FILE *file;
6296 bool start,newtime = false;
6297 unsigned char buffer[5000];
6298 struct utimbuf filedate;
6300 File.Buffer = NULL;
6302 GSM_Init(true);
6304 for (i=2;i<argc;i++) {
6305 if (mystrncasecmp(argv[i],"-newtime",0)) {
6306 newtime = true;
6307 continue;
6310 if (File.Buffer != NULL) {
6311 free(File.Buffer);
6312 File.Buffer = NULL;
6314 File.Used = 0;
6315 strcpy(File.ID_FullName,argv[i]);
6316 start = true;
6318 error = GE_NONE;
6319 while (error == GE_NONE) {
6320 error = Phone->GetFilePart(&s,&File);
6321 if (error == GE_NONE || error == GE_EMPTY || error == GE_WRONGCRC) {
6322 if (start) {
6323 printmsg("Getting \"%s\": ", DecodeUnicodeConsole(File.Name));
6324 start = false;
6326 if (File.Folder) {
6327 free(File.Buffer);
6328 GSM_Terminate();
6329 printmsg("it's folder. Please give only file names\n");
6330 exit(-1);
6332 printmsg("*");
6333 if (error == GE_EMPTY) break;
6334 if (error == GE_WRONGCRC) {
6335 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
6336 break;
6339 Print_Error(error);
6341 printf("\n");
6343 if (File.Used != 0) {
6344 sprintf(buffer,"%s",DecodeUnicodeConsole(File.Name));
6345 file = fopen(buffer,"wb");
6346 if (file == NULL) {
6347 sprintf(buffer,"file%s",File.ID_FullName);
6348 file = fopen(buffer,"wb");
6350 if (file == NULL) {
6351 sprintf(buffer,"file%i",i);
6352 file = fopen(buffer,"wb");
6354 printmsg(" Saving to %s\n",buffer);
6355 if (!file) Print_Error(GE_CANTOPENFILE);
6356 fwrite(File.Buffer,1,File.Used,file);
6357 fclose(file);
6358 if (!newtime && !File.ModifiedEmpty) {
6359 /* access time */
6360 filedate.actime = Fill_Time_T(File.Modified, 8);
6361 /* modification time */
6362 filedate.modtime = Fill_Time_T(File.Modified, 8);
6363 dbgprintf("Setting date of %s\n",buffer);
6364 utime(buffer,&filedate);
6369 free(File.Buffer);
6370 GSM_Terminate();
6373 static void AddFile(int argc, char *argv[])
6375 GSM_File File;
6376 int Pos = 0,i,nextlong;
6378 File.Buffer = NULL;
6379 strcpy(File.ID_FullName,argv[2]);
6380 error = GSM_ReadFile(argv[3], &File);
6381 Print_Error(error);
6382 EncodeUnicode(File.Name,argv[3],strlen(argv[3]));
6383 GSM_IdentifyFileFormat(&File);
6385 File.Protected = false;
6386 File.ReadOnly = false;
6387 File.Hidden = false;
6388 File.System = false;
6390 if (argc > 4) {
6391 nextlong = 0;
6392 for (i=4;i<argc;i++) {
6393 switch(nextlong) {
6394 case 0:
6395 if (mystrncasecmp(argv[i],"-type",0)) {
6396 nextlong = 1;
6397 continue;
6399 if (mystrncasecmp(argv[i],"-protected",0)) {
6400 File.Protected = true;
6401 continue;
6403 if (mystrncasecmp(argv[i],"-readonly",0)) {
6404 File.ReadOnly = true;
6405 continue;
6407 if (mystrncasecmp(argv[i],"-hidden",0)) {
6408 File.Hidden = true;
6409 continue;
6411 if (mystrncasecmp(argv[i],"-system",0)) {
6412 File.System = true;
6413 continue;
6415 if (mystrncasecmp(argv[i],"-newtime",0)) {
6416 File.ModifiedEmpty = true;
6417 continue;
6419 printmsg("Parameter \"%s\" unknown\n",argv[i]);
6420 exit(-1);
6421 case 1:
6422 if (mystrncasecmp(argv[i],"JAR",0)) {
6423 File.Type = GSM_File_Java_JAR;
6424 } else if (mystrncasecmp(argv[i],"JPG",0)) {
6425 File.Type = GSM_File_Image_JPG;
6426 } else if (mystrncasecmp(argv[i],"BMP",0)) {
6427 File.Type = GSM_File_Image_BMP;
6428 } else if (mystrncasecmp(argv[i],"WBMP",0)) {
6429 File.Type = GSM_File_Image_WBMP;
6430 } else if (mystrncasecmp(argv[i],"GIF",0)) {
6431 File.Type = GSM_File_Image_GIF;
6432 } else if (mystrncasecmp(argv[i],"PNG",0)) {
6433 File.Type = GSM_File_Image_PNG;
6434 } else if (mystrncasecmp(argv[i],"MIDI",0)) {
6435 File.Type = GSM_File_Ringtone_MIDI;
6436 } else {
6437 printmsg("What file type (\"%s\") ?\n",argv[i]);
6438 exit(-1);
6440 nextlong = 0;
6441 break;
6444 if (nextlong!=0) {
6445 printmsg("Parameter missed...\n");
6446 exit(-1);
6450 GSM_Init(true);
6452 error = GE_NONE;
6453 while (error == GE_NONE) {
6454 error = Phone->AddFilePart(&s,&File,&Pos);
6455 if (error != GE_EMPTY && error != GE_WRONGCRC) Print_Error(error);
6456 printmsgerr("%cWriting: %i percent",13,Pos*100/File.Used);
6458 printmsgerr("\n");
6459 if (error == GE_WRONGCRC) {
6460 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
6463 free(File.Buffer);
6464 GSM_Terminate();
6467 static void AddFolder(int argc, char *argv[])
6469 GSM_File File;
6471 strcpy(File.ID_FullName,argv[2]);
6472 EncodeUnicode(File.Name,argv[3],strlen(argv[3]));
6473 File.ReadOnly = false;
6475 GSM_Init(true);
6477 error = Phone->AddFolder(&s,&File);
6478 Print_Error(error);
6480 GSM_Terminate();
6483 struct NokiaFolderInfo {
6484 char *model;
6485 char *parameter;
6486 char *folder;
6487 char *level;
6490 static struct NokiaFolderInfo Folder[] = {
6491 /* Language indepedent in DCT4 */
6492 {"", "MMSUnreadInbox", "INBOX", "3"},
6493 {"", "MMSReadInbox", "INBOX", "3"},
6494 {"", "MMSOutbox", "OUTBOX", "3"},
6495 {"", "MMSSent", "SENT", "3"},
6496 {"", "MMSDrafts", "DRAFTS", "3"},
6497 {"", "Application", "applications", "3"},
6498 {"", "Game", "games", "3"},
6499 /* Language depedent in DCT4 */
6500 {"", "Gallery", "Pictures", "2"}, /* 3510 */
6501 {"", "Gallery", "Graphics", "3"}, /* 3510i */
6502 {"", "Gallery", "Images", "3"}, /* 6610 */
6503 {"3510", "Gallery", "", "8"},
6504 {"3510i","Gallery", "", "3"},
6505 {"5100", "Gallery", "", "3"},
6506 {"", "Tones", "Tones", "3"},
6507 {"3510i","Tones", "", "4"},
6508 {"5100", "Tones", "", "4"},
6509 /* Language indepedent in OBEX */
6510 {"obex", "MMSUnreadInbox", "", "predefMessages\\predefINBOX" },
6511 {"obex", "MMSReadInbox", "", "predefMessages\\predefINBOX" },
6512 {"obex", "MMSOutbox", "", "predefMessages\\predefOUTBOX" },
6513 {"obex", "MMSSent", "", "predefMessages\\predefSENT" },
6514 {"obex", "MMSDrafts", "", "predefMessages\\predefDRAFTS" },
6515 // {"obex", "Application, "", "predefjava\\predefapplications"},
6516 // {"obex", "Game", "", "predefjava\\predefgames" },
6517 {"obex", "Gallery", "", "predefgallery\\predefgraphics" },
6518 {"obex", "Tones", "", "predefgallery\\predeftones" },
6520 /* End of list */
6521 {"", "", "", ""}
6524 static void NokiaAddFile(int argc, char *argv[])
6526 GSM_File File, Files;
6527 FILE *file;
6528 GSM_DateTime DT,DT2;
6529 time_t t_time1,t_time2;
6530 unsigned char buffer[10000],JAR[500],Vendor[500],Name[500],Version[500],FileID[400];
6531 bool Start = true, Found = false, wasclr;
6532 bool ModEmpty = false;
6533 int i = 0, Pos, Size, Size2, nextlong;
6535 while (Folder[i].level[0] != 0) {
6536 if (mystrncasecmp(argv[2],Folder[i].parameter,0)) {
6537 Found = true;
6538 break;
6540 i++;
6542 if (!Found) {
6543 printmsg("What folder type (\"%s\") ?\n",argv[2]);
6544 exit(-1);
6547 GSM_Init(true);
6549 if (s.ConnectionType == GCT_IRDAOBEX || s.ConnectionType == GCT_BLUEOBEX) {
6550 Found = false;
6551 i = 0;
6552 while (Folder[i].level[0] != 0) {
6553 if (!strcmp("obex",Folder[i].model) &&
6554 mystrncasecmp(argv[2],Folder[i].parameter,0)) {
6555 strcpy(Files.ID_FullName,Folder[i].level);
6556 Found = true;
6557 break;
6559 i++;
6561 } else {
6562 printmsgerr("Searching for phone folder: ");
6563 while (1) {
6564 error = Phone->GetNextFileFolder(&s,&Files,Start);
6565 if (error == GE_EMPTY) break;
6566 Print_Error(error);
6568 if (Files.Folder) {
6569 dbgprintf("folder %s level %i\n",DecodeUnicodeConsole(Files.Name),Files.Level);
6570 Found = false;
6571 i = 0;
6572 while (Folder[i].level[0] != 0) {
6573 EncodeUnicode(buffer,Folder[i].folder,strlen(Folder[i].folder));
6574 if (mystrncasecmp(argv[2],Folder[i].parameter,0) &&
6575 mywstrncasecmp(Files.Name,buffer,0) &&
6576 Files.Level == atoi(Folder[i].level)) {
6577 Found = true;
6578 break;
6580 if (!strcmp(s.Phone.Data.ModelInfo->model,Folder[i].model) &&
6581 mystrncasecmp(argv[2],Folder[i].parameter,0) &&
6582 !strcmp(Files.ID_FullName,Folder[i].level)) {
6583 Found = true;
6584 break;
6586 dbgprintf("comparing \"%s\" \"%s\" \"%s\"\n",s.Phone.Data.ModelInfo->model,Files.ID_FullName,Folder[i].level);
6587 i++;
6589 if (Found) break;
6591 printmsgerr("*");
6593 Start = false;
6595 printmsgerr("\n");
6597 if (!Found) {
6598 printmsg("Folder not found. Probably function not supported !\n");
6599 GSM_Terminate();
6600 exit(-1);
6602 File.Buffer = NULL;
6603 File.Protected = false;
6604 File.ReadOnly = false;
6605 File.Hidden = false;
6606 File.System = false;
6608 if (mystrncasecmp(argv[2],"Application",0) || mystrncasecmp(argv[2],"Game",0)) {
6609 sprintf(buffer,"%s.jad",argv[3]);
6610 file = fopen(buffer,"rb");
6611 if (file == NULL) Print_Error(GE_CANTOPENFILE);
6612 fclose(file);
6613 sprintf(buffer,"%s.jar",argv[3]);
6614 file = fopen(buffer,"rb");
6615 if (file == NULL) Print_Error(GE_CANTOPENFILE);
6616 fclose(file);
6618 /* reading jar file */
6619 sprintf(buffer,"%s.jar",argv[3]);
6620 error = GSM_ReadFile(buffer, &File);
6621 Print_Error(error);
6622 Size2 = File.Used;
6624 /* reading jad file */
6625 sprintf(buffer,"%s.jad",argv[3]);
6626 error = GSM_ReadFile(buffer, &File);
6627 Print_Error(error);
6629 /* Getting values from JAD file */
6630 error = GSM_JADFindData(File, Vendor, Name, JAR, Version, &Size);
6631 if (error == GE_FILENOTSUPPORTED) {
6632 if (Vendor[0] == 0x00) {
6633 printmsgerr("No vendor info in JAD file\n");
6634 GSM_Terminate();
6635 return;
6637 if (Name[0] == 0x00) {
6638 printmsgerr("No name info in JAD file\n");
6639 GSM_Terminate();
6640 return;
6642 if (JAR[0] == 0x00) {
6643 printmsgerr("No JAR URL info in JAD file\n");
6644 GSM_Terminate();
6645 return;
6647 if (Size == -1) {
6648 printmsgerr("No JAR size info in JAD file\n");
6649 GSM_Terminate();
6650 return;
6653 if (Size != Size2) {
6654 printmsgerr("Declared JAR file size is different than real\n");
6655 GSM_Terminate();
6656 return;
6658 printmsgerr("Adding \"%s\"",Name);
6659 if (Version[0] != 0x00) printmsgerr(" version %s",Version);
6660 printmsgerr(" created by %s\n",Vendor);
6662 /* Changing all #13 or #10 to #13#10 in JAD */
6663 Pos = 0;
6664 wasclr = false;
6665 for (i=0;i<File.Used;i++) {
6666 switch (File.Buffer[i]) {
6667 case 0x0D:
6668 case 0x0A:
6669 if (!wasclr) {
6670 buffer[Pos++] = 0x0D;
6671 buffer[Pos++] = 0x0A;
6672 wasclr = true;
6673 } else wasclr = false;
6674 break;
6675 default:
6676 buffer[Pos++] = File.Buffer[i];
6677 wasclr = false;
6680 File.Buffer = realloc(File.Buffer, Pos);
6681 File.Used = Pos;
6682 memcpy(File.Buffer,buffer,Pos);
6684 /* adding folder */
6685 strcpy(buffer,Vendor);
6686 strcat(buffer,Name);
6687 EncodeUnicode(File.Name,buffer,strlen(buffer));
6688 strcpy(File.ID_FullName,Files.ID_FullName);
6689 error = Phone->AddFolder(&s,&File);
6690 Print_Error(error);
6691 strcpy(FileID,File.ID_FullName);
6693 /* adding jad file */
6694 strcpy(buffer,JAR);
6695 buffer[strlen(buffer) - 1] = 'd';
6696 EncodeUnicode(File.Name,buffer,strlen(buffer));
6697 File.Type = GSM_File_Other;
6698 File.ModifiedEmpty = true;
6699 error = GE_NONE;
6700 Pos = 0;
6701 while (error == GE_NONE) {
6702 error = Phone->AddFilePart(&s,&File,&Pos);
6703 if (error != GE_EMPTY && error != GE_WRONGCRC) Print_Error(error);
6704 printmsgerr("%cWriting JAD file: %i percent",13,Pos*100/File.Used);
6706 printmsgerr("\n");
6707 if (error == GE_WRONGCRC) {
6708 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
6711 if (argc > 4) {
6712 if (mystrncasecmp(argv[4],"-readonly",0)) File.ReadOnly = true;
6715 /* reading jar file */
6716 sprintf(buffer,"%s.jar",argv[3]);
6717 error = GSM_ReadFile(buffer, &File);
6718 Print_Error(error);
6720 /* adding jar file */
6721 strcpy(File.ID_FullName,FileID);
6722 strcpy(buffer,JAR);
6723 EncodeUnicode(File.Name,buffer,strlen(buffer));
6724 File.Type = GSM_File_Java_JAR;
6725 File.ModifiedEmpty = true;
6726 error = GE_NONE;
6727 Pos = 0;
6728 while (error == GE_NONE) {
6729 error = Phone->AddFilePart(&s,&File,&Pos);
6730 if (error != GE_EMPTY && error != GE_WRONGCRC) Print_Error(error);
6731 printmsgerr("%cWriting JAR file: %i percent",13,Pos*100/File.Used);
6733 printmsgerr("\n");
6734 if (error == GE_WRONGCRC) {
6735 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
6738 free(File.Buffer);
6739 GSM_Terminate();
6740 return;
6743 if (mystrncasecmp(argv[2],"Gallery",0) || mystrncasecmp(argv[2],"Tones",0)) {
6744 strcpy(buffer,argv[3]);
6745 if (argc > 4) {
6746 nextlong = 0;
6747 for (i=4;i<argc;i++) {
6748 switch(nextlong) {
6749 case 0:
6750 if (mystrncasecmp(argv[i],"-name",0)) {
6751 nextlong = 1;
6752 continue;
6754 if (mystrncasecmp(argv[i],"-protected",0)) {
6755 File.Protected = true;
6756 continue;
6758 if (mystrncasecmp(argv[i],"-readonly",0)) {
6759 File.ReadOnly = true;
6760 continue;
6762 if (mystrncasecmp(argv[i],"-hidden",0)) {
6763 File.Hidden = true;
6764 continue;
6766 if (mystrncasecmp(argv[i],"-system",0)) {
6767 File.System = true;
6768 continue;
6770 if (mystrncasecmp(argv[i],"-newtime",0)) {
6771 ModEmpty = true;
6772 continue;
6774 printmsg("Parameter \"%s\" unknown\n",argv[i]);
6775 exit(-1);
6776 case 1:
6777 strcpy(buffer,argv[i]);
6778 nextlong = 0;
6779 break;
6782 if (nextlong!=0) {
6783 printmsg("Parameter missed...\n");
6784 exit(-1);
6787 } else { /* MMS things */
6788 DT2.Year = 2001;
6789 DT2.Month = 12;
6790 DT2.Day = 31;
6791 DT2.Hour = 14;
6792 DT2.Minute = 00;
6793 DT2.Second = 00;
6794 t_time2 = Fill_Time_T(DT2,8);
6796 GSM_GetCurrentDateTime(&DT);
6797 t_time1 = Fill_Time_T(DT,8);
6799 sprintf(buffer,"%07X %07X ",(int)(t_time1-t_time2-40),(int)(t_time1-t_time2-40));
6800 #ifdef DEVELOP
6801 sprintf(buffer,"2A947BD 2A947DB ");
6802 #endif
6803 /* 40 = inbox "multimedia message received" message */
6804 /* 30 = outbox sending failed */
6805 if (mystrncasecmp(argv[2],"MMSUnreadInbox",0)) strcat(buffer,"43 ");
6806 else if (mystrncasecmp(argv[2],"MMSReadInbox",0)) strcat(buffer,"50 ");
6807 else if (mystrncasecmp(argv[2],"MMSOutbox",0)) strcat(buffer,"10 ");
6808 else if (mystrncasecmp(argv[2],"MMSSent",0)) strcat(buffer,"20 ");
6809 else if (mystrncasecmp(argv[2],"MMSDrafts",0)) strcat(buffer,"61 ");
6810 if (argc > 4) {
6811 if (!mystrncasecmp(argv[2],"MMSOutbox",0) &&
6812 !mystrncasecmp(argv[2],"MMSSent",0)) {
6813 sprintf(Name,"%s",argv[4]);
6814 strcat(buffer,Name);
6816 if (argc > 5) {
6817 sprintf(Name,"%zd%s/TYPE=PLMN",strlen(argv[5])+10,argv[5]);
6818 strcat(buffer,Name);
6821 ModEmpty = true;
6824 error = GSM_ReadFile(argv[3], &File);
6825 Print_Error(error);
6826 if (ModEmpty) File.ModifiedEmpty = true;
6828 strcpy(File.ID_FullName,Files.ID_FullName);
6829 EncodeUnicode(File.Name,buffer,strlen(buffer));
6830 GSM_IdentifyFileFormat(&File);
6831 #ifdef DEVELOP
6832 if (mystrncasecmp(argv[2],"Gallery",0) || mystrncasecmp(argv[2],"Tones",0)) {
6833 } else { /* MMS things */
6834 File.Type = GSM_File_MMS;
6836 #endif
6838 dbgprintf("Adding file to filesystem now\n");
6839 error = GE_NONE;
6840 Pos = 0;
6841 while (error == GE_NONE) {
6842 error = Phone->AddFilePart(&s,&File,&Pos);
6843 if (error != GE_EMPTY && error != GE_WRONGCRC) Print_Error(error);
6844 if (File.Used != 0) printmsgerr("%cWriting file: %i percent",13,Pos*100/File.Used);
6846 printmsgerr("\n");
6847 if (error == GE_WRONGCRC) {
6848 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
6851 free(File.Buffer);
6852 GSM_Terminate();
6855 static void DeleteFiles(int argc, char *argv[])
6857 int i;
6859 GSM_Init(true);
6861 for (i=2;i<argc;i++) {
6862 error = Phone->DeleteFile(&s,argv[i]);
6863 Print_Error(error);
6866 GSM_Terminate();
6869 static void SaveMMSFile(int argc, char *argv[])
6871 FILE *file;
6872 unsigned char Buffer[50000],Buffer2[20][2010];
6873 int i,nextlong = 0,len = 0;
6874 GSM_EncodeMultiPartMMSInfo Info;
6876 GSM_ClearMultiPartMMSInfo(&Info);
6878 for (i=3;i<argc;i++) {
6879 switch (nextlong) {
6880 case 0:
6881 if (mystrncasecmp(argv[i],"-subject",0)) {
6882 nextlong=1;
6883 continue;
6885 if (mystrncasecmp(argv[i],"-text",0)) {
6886 nextlong=2;
6887 continue;
6889 if (mystrncasecmp(argv[i],"-from",0)) {
6890 nextlong=3;
6891 continue;
6893 if (mystrncasecmp(argv[i],"-to",0)) {
6894 nextlong=4;
6895 continue;
6897 printmsg("Unknown parameter (\"%s\")\n",argv[i]);
6898 exit(-1);
6899 break;
6900 case 1: /* Subject */
6901 EncodeUnicode(Info.Subject,argv[i],strlen(argv[i]));
6902 nextlong = 0;
6903 break;
6904 case 2: /* Text */
6905 EncodeUnicode(Buffer2[Info.EntriesNum],argv[i],strlen(argv[i]));
6906 Info.Entries[Info.EntriesNum].ID = MMS_Text;
6907 Info.Entries[Info.EntriesNum].Buffer = Buffer2[Info.EntriesNum];
6908 Info.EntriesNum++;
6909 nextlong = 0;
6910 break;
6911 case 3: /* From */
6912 EncodeUnicode(Info.Source,argv[i],strlen(argv[i]));
6913 nextlong = 0;
6914 break;
6915 case 4: /* To */
6916 EncodeUnicode(Info.Destination,argv[i],strlen(argv[i]));
6917 nextlong = 0;
6918 break;
6921 if (nextlong!=0) {
6922 printmsg("Parameter missed...\n");
6923 exit(-1);
6926 GSM_EncodeMMSFile(&Info,Buffer,&len);
6928 file = fopen(argv[2],"wb");
6929 if (file == NULL) Print_Error(GE_CANTOPENFILE);
6930 fwrite(Buffer,1,len,file);
6931 fclose(file);
6934 static void CallDivert(int argc, char *argv[])
6936 GSM_MultiCallDivert cd;
6938 if (mystrncasecmp("get", argv[2],0)) {}
6939 else if (mystrncasecmp("set", argv[2],0)) {}
6940 else {
6941 printmsg("Unknown divert action (\"%s\")\n",argv[2]);
6942 exit(-1);
6945 if (mystrncasecmp("all" , argv[3],0)) {cd.Request.DType = GSM_CDV_AllTypes ;}
6946 else if (mystrncasecmp("busy" , argv[3],0)) {cd.Request.DType = GSM_CDV_Busy ;}
6947 else if (mystrncasecmp("noans" , argv[3],0)) {cd.Request.DType = GSM_CDV_NoAnswer ;}
6948 else if (mystrncasecmp("outofreach", argv[3],0)) {cd.Request.DType = GSM_CDV_OutOfReach;}
6949 else {
6950 printmsg("Unknown divert type (\"%s\")\n",argv[3]);
6951 exit(-1);
6954 if (mystrncasecmp("all" , argv[4],0)) {cd.Request.CType = GSM_CDV_AllCalls ;}
6955 else if (mystrncasecmp("voice", argv[4],0)) {cd.Request.CType = GSM_CDV_VoiceCalls;}
6956 else if (mystrncasecmp("fax" , argv[4],0)) {cd.Request.CType = GSM_CDV_FaxCalls ;}
6957 else if (mystrncasecmp("data" , argv[4],0)) {cd.Request.CType = GSM_CDV_DataCalls ;}
6958 else {
6959 printmsg("Unknown call type (\"%s\")\n",argv[4]);
6960 exit(-1);
6963 GSM_Init(true);
6965 if (mystrncasecmp("get", argv[2],0)) {
6966 error = Phone->GetCallDivert(&s,&cd);
6967 Print_Error(error);
6968 printmsg("Query:\n Divert type: ");
6969 } else {
6970 cd.Request.Number[0] = 0;
6971 cd.Request.Number[1] = 0;
6972 if (argc > 5) EncodeUnicode(cd.Request.Number,argv[5],strlen(argv[5]));
6974 cd.Request.Timeout = 0;
6975 if (argc > 6) cd.Request.Timeout = atoi(argv[6]);
6977 error = Phone->SetCallDivert(&s,&cd);
6978 Print_Error(error);
6979 printmsg("Changed:\n Divert type: ");
6982 switch (cd.Request.DType) {
6983 case GSM_CDV_Busy : printmsg("when busy"); break;
6984 case GSM_CDV_NoAnswer : printmsg("when not answered"); break;
6985 case GSM_CDV_OutOfReach: printmsg("when phone off or no coverage"); break;
6986 case GSM_CDV_AllTypes : printmsg("all types of diverts"); break;
6987 default : printmsg("unknown %i",cd.Request.DType); break;
6989 printmsg("\n Calls type : ");
6990 switch (cd.Request.CType) {
6991 case GSM_CDV_VoiceCalls: printmsg("voice"); break;
6992 case GSM_CDV_FaxCalls : printmsg("fax"); break;
6993 case GSM_CDV_DataCalls : printmsg("data"); break;
6994 case GSM_CDV_AllCalls : printmsg("data & fax & voice"); break;
6995 default : printmsg("unknown %i",cd.Request.CType); break;
6997 printmsg("\nResponse:");
6999 for (i=0;i<cd.Response.EntriesNum;i++) {
7000 printmsg("\n Calls type : ");
7001 switch (cd.Response.Entries[i].CType) {
7002 case GSM_CDV_VoiceCalls: printmsg("voice"); break;
7003 case GSM_CDV_FaxCalls : printmsg("fax"); break;
7004 case GSM_CDV_DataCalls : printmsg("data"); break;
7005 default : printmsg("unknown %i",cd.Response.Entries[i].CType);break;
7007 printf("\n");
7008 printmsg(" Timeout : %i seconds\n",cd.Response.Entries[i].Timeout);
7009 printmsg(" Number : %s\n",DecodeUnicodeString(cd.Response.Entries[i].Number));
7011 printf("\n");
7013 GSM_Terminate();
7016 static void CancelAllDiverts(int argc, char *argv[])
7018 GSM_Init(true);
7020 error = Phone->CancelAllDiverts(&s);
7021 Print_Error(error);
7023 GSM_Terminate();
7026 typedef struct {
7027 unsigned char Connection[50];
7028 } OneConnectionInfo;
7030 typedef struct {
7031 unsigned char Device[50];
7032 OneConnectionInfo Connections[6];
7033 GSM_StateMachine s;
7034 } OneDeviceInfo;
7036 int num;
7037 OneDeviceInfo SearchDevices[100];
7038 bool SearchOutput;
7040 void SearchPhoneThread(OneDeviceInfo *Info)
7042 int j;
7043 GSM_Error error;
7045 j = 0;
7046 while(strlen(Info->Connections[j].Connection) != 0) {
7047 memcpy(&Info->s.di,&s.di,sizeof(Debug_Info));
7048 Info->s.msg = s.msg;
7049 Info->s.ConfigNum = 1;
7050 Info->s.opened = false;
7051 Info->s.Config[0].UseGlobalDebugFile = s.Config[0].UseGlobalDebugFile;
7052 Info->s.Config[0].Localize = s.Config[0].Localize;
7053 Info->s.Config[0].Device = Info->Device;
7054 Info->s.Config[0].Connection = Info->Connections[j].Connection;
7055 Info->s.Config[0].SyncTime = "no";
7056 Info->s.Config[0].DebugFile = s.Config[0].DebugFile;
7057 Info->s.Config[0].Model[0] = 0;
7058 strcpy(Info->s.Config[0].DebugLevel,s.Config[0].DebugLevel);
7059 Info->s.Config[0].LockDevice = "no";
7060 Info->s.Config[0].StartInfo = "no";
7062 error = GSM_InitConnection(&Info->s,1);
7063 if (SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device);
7064 if (error == GE_NONE) {
7065 error=Info->s.Phone.Functions->GetManufacturer(&Info->s);
7066 if (error == GE_NONE) {
7067 error=Info->s.Phone.Functions->GetModel(&Info->s);
7068 if (error == GE_NONE) {
7069 if (!SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device);
7070 printmsg(" Manufacturer : %s\n",
7071 Info->s.Phone.Data.Manufacturer);
7072 printmsg(" Model : %s (%s)\n",
7073 Info->s.Phone.Data.ModelInfo->model,
7074 Info->s.Phone.Data.Model);
7075 } else {
7076 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg));
7078 } else {
7079 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg));
7081 } else {
7082 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg));
7084 if (error != GE_DEVICEOPENERROR) {
7085 GSM_TerminateConnection(&Info->s);
7086 dbgprintf("Closing done\n");
7088 if (error == GE_DEVICEOPENERROR || error == GE_NONE) break;
7089 j++;
7091 num--;
7094 #if defined(WIN32) || defined(HAVE_PTHREAD)
7095 #ifdef HAVE_PTHREAD
7096 pthread_t Thread[100];
7097 #endif
7099 void MakeSearchThread(int i)
7101 num++;
7102 #ifdef HAVE_PTHREAD
7103 if (pthread_create(&Thread[i],NULL,(void *)SearchPhoneThread,&SearchDevices[i])!=0) {
7104 dbgprintf("Error creating thread\n");
7106 #else
7107 if (CreateThread((LPSECURITY_ATTRIBUTES)NULL,0,
7108 (LPTHREAD_START_ROUTINE)SearchPhoneThread,&SearchDevices[i],
7109 0,NULL)==NULL) {
7110 dbgprintf("Error creating thread\n");
7112 #endif
7115 static void SearchPhone(int argc, char *argv[])
7117 int i,dev = 0, dev2 = 0;
7119 SearchOutput = false;
7120 if (argc == 3 && mystrncasecmp(argv[2], "-debug",0)) SearchOutput = true;
7122 num = 0;
7123 #ifdef WIN32
7124 # ifdef GSM_ENABLE_IRDADEVICE
7125 sprintf(SearchDevices[dev].Device,"");
7126 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet");
7127 SearchDevices[dev].Connections[1].Connection[0] = 0;
7128 dev++;
7129 # endif
7130 # ifdef GSM_ENABLE_SERIALDEVICE
7131 dev2 = dev;
7132 for(i=0;i<10;i++) {
7133 sprintf(SearchDevices[dev2].Device,"com%i:",i+1);
7134 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7135 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7136 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7137 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7138 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7139 dev2++;
7141 # endif
7142 #endif
7143 #ifdef __linux__
7144 # ifdef GSM_ENABLE_IRDADEVICE
7145 for(i=0;i<6;i++) {
7146 sprintf(SearchDevices[dev].Device,"/dev/ircomm%i",i);
7147 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet");
7148 sprintf(SearchDevices[dev].Connections[1].Connection,"at19200");
7149 SearchDevices[dev].Connections[2].Connection[0] = 0;
7150 dev++;
7152 # endif
7153 # ifdef GSM_ENABLE_SERIALDEVICE
7154 dev2 = dev;
7155 for(i=0;i<10;i++) {
7156 sprintf(SearchDevices[dev2].Device,"/dev/ttyS%i",i);
7157 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7158 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7159 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7160 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7161 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7162 dev2++;
7164 for(i=0;i<8;i++) {
7165 sprintf(SearchDevices[dev2].Device,"/dev/ttyD00%i",i);
7166 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7167 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7168 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7169 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7170 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7171 dev2++;
7173 for(i=0;i<4;i++) {
7174 sprintf(SearchDevices[dev2].Device,"/dev/usb/tts/%i",i);
7175 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7176 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7177 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7178 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7179 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7180 dev2++;
7182 # endif
7183 #endif
7184 for(i=0;i<dev;i++) MakeSearchThread(i);
7185 while (1) {if (num == 0) break;my_sleep(5);}
7186 for(i=dev;i<dev2;i++) MakeSearchThread(i);
7187 while (1) {if (num == 0) break;my_sleep(5);}
7189 #endif /*Support for threads */
7191 static void NokiaGetADC(int argc, char *argv[])
7193 GSM_Init(true);
7195 #ifdef GSM_ENABLE_NOKIA_DCT3
7196 DCT3GetADC(argc,argv);
7197 #endif
7198 #ifdef GSM_ENABLE_NOKIA_DCT4
7199 DCT4GetADC(argc, argv);
7200 #endif
7202 GSM_Terminate();
7205 static void NokiaDisplayTest(int argc, char *argv[])
7207 GSM_Init(true);
7209 #ifdef GSM_ENABLE_NOKIA_DCT3
7210 DCT3DisplayTest(argc,argv);
7211 #endif
7212 #ifdef GSM_ENABLE_NOKIA_DCT4
7213 DCT4DisplayTest(argc, argv);
7214 #endif
7216 GSM_Terminate();
7219 static void NokiaGetT9(int argc, char *argv[])
7221 GSM_Init(true);
7223 #ifdef GSM_ENABLE_NOKIA_DCT3
7224 DCT3GetT9(argc,argv);
7225 #endif
7226 #ifdef GSM_ENABLE_NOKIA_DCT4
7227 DCT4GetT9(argc, argv);
7228 #endif
7230 GSM_Terminate();
7233 static void NokiaVibraTest(int argc, char *argv[])
7235 GSM_Init(true);
7237 #ifdef GSM_ENABLE_NOKIA_DCT3
7238 DCT3VibraTest(argc,argv);
7239 #endif
7240 #ifdef GSM_ENABLE_NOKIA_DCT4
7241 DCT4VibraTest(argc, argv);
7242 #endif
7244 GSM_Terminate();
7247 static GSM_Parameters Parameters[] = {
7248 {"--identify", 0, 0, Identify, {H_Info,0}, ""},
7249 {"--version", 0, 0, Version, {H_Other,0}, ""},
7250 {"--getdisplaystatus", 0, 0, GetDisplayStatus, {H_Info,0}, ""},
7251 {"--monitor", 0, 1, Monitor, {H_Info,H_Network,H_Call,0}, "[times]"},
7252 {"--setautonetworklogin", 0, 0, SetAutoNetworkLogin, {H_Network,0}, ""},
7253 {"--listnetworks", 0, 0, ListNetworks, {H_Network,0}, ""},
7254 {"--getgprspoint", 1, 2, GetGPRSPoint, {H_Nokia,H_Network,0}, "start [stop]"},
7255 {"--addfolder", 2, 2, AddFolder, {H_Filesystem,0}, "parentfolderID name"},
7256 {"--getfilesystem", 0, 1, GetFileSystem, {H_Filesystem,0}, "[-flatall|-flat]"},
7257 {"--getfilesystemstatus", 0, 0, GetFileSystemStatus, {H_Filesystem,0}, ""},
7258 {"--getfiles", 1,40, GetFiles, {H_Filesystem,0}, ""},
7259 {"--addfile", 2, 6, AddFile, {H_Filesystem,0}, "folderID name [-type JAR|BMP|PNG|GIF|JPG|MIDI|WBMP][-readonly][-protected][-system][-hidden][-newtime]"},
7260 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0}, "MMSUnreadInbox|MMSReadInbox|MMSOutbox|MMSDrafts|MMSSent file sender title"},
7261 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0}, "Application|Game file [-readonly]"},
7262 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0}, "Gallery|Tones file [-name name][-protected][-readonly][-system][-hidden][-newtime]"},
7263 {"--deletefiles", 1,20, DeleteFiles, {H_Filesystem,0}, "fileID"},
7264 {"--playringtone", 1, 1, PlayRingtone, {H_Ringtone,0}, "file"},
7265 {"--getdatetime", 0, 0, GetDateTime, {H_DateTime,0}, ""},
7266 {"--setdatetime", 0, 0, SetDateTime, {H_DateTime,0}, ""},
7267 {"--getalarm", 0, 0, GetAlarm, {H_DateTime,0}, ""},
7268 {"--setalarm", 2, 2, SetAlarm, {H_DateTime,0}, "hour minute"},
7269 {"--resetphonesettings", 1, 1, ResetPhoneSettings, {H_Settings,0}, "PHONE|DEV|UIF|ALL|FACTORY"},
7270 {"--getmemory", 2, 3, GetMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD start [stop]"},
7271 {"--getallmemory", 1, 1, GetAllMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD"},
7272 {"--searchmemory", 1, 1, SearchMemory, {H_Memory,0}, "text"},
7273 {"--listmemorycategory", 1, 1, ListMemoryCategory, {H_Memory, H_Category,0}, "text|number"},
7274 {"--getfmstation", 1, 2, GetFMStation, {H_FM,0}, "start [stop]"},
7275 {"--getsmsc", 1, 2, GetSMSC, {H_SMS,0}, "start [stop]"},
7276 {"--getsms", 2, 3, GetSMS, {H_SMS,0}, "folder start [stop]"},
7277 {"--deletesms", 2, 3, DeleteSMS, {H_SMS,0}, "folder start [stop]"},
7278 {"--deleteallsms", 1, 1, DeleteAllSMS, {H_SMS,0}, "folder"},
7279 {"--getsmsfolders", 0, 0, GetSMSFolders, {H_SMS,0}, ""},
7280 {"--getallsms", 0, 0, GetAllSMS, {H_SMS,0}, ""},
7281 {"--geteachsms", 0, 0, GetEachSMS, {H_SMS,0}, ""},
7283 #define SMS_TEXT_OPTIONS "[-inputunicode][-16bit][-flash][-len len][-autolen len][-unicode][-enablevoice][-disablevoice][-enablefax][-disablefax][-enableemail][-disableemail][-voidsms][-replacemessages ID][-replacefile file]"
7284 #define SMS_PICTURE_OPTIONS "[-text text][-unicode]"
7285 #define SMS_PROFILE_OPTIONS "[-name name][-bitmap bitmap][-ringtone ringtone]"
7286 #define SMS_EMS_OPTIONS "[-unicode][-16bit][-format lcrasbiut][-text text][-unicodefiletext file][-defsound ID][-defanimation ID][-tone10 file][-tone10long file][-tone12 file][-tone12long file][-toneSE file][-toneSElong file][-fixedbitmap file][-variablebitmap file][-variablebitmaplong file][-animation frames file1 ...][-protected number]"
7287 #define SMS_OPERATOR_OPTIONS "[-netcode netcode][-biglogo]"
7288 #define SMS_SAVE_OPTIONS "[-folder id][-unread][-read][-unsent][-sent][-sender number]"
7289 #define SMS_SEND_OPTIONS "[-report][-validity HOUR|6HOURS|DAY|3DAYS|WEEK|MAX]"
7290 #define SMS_COMMON_OPTIONS "[-smscset number][-smscnumber number][-reply][-maxsms num]"
7292 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "TEXT " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_TEXT_OPTIONS},
7293 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7294 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS},
7295 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7296 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS},
7297 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR URL Title Sender " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7298 #ifdef GSM_ENABLE_BACKUP
7299 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7300 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS file location DATA|GPRS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7301 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7302 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7303 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7304 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Memory,0}, "VCARD10|VCARD21 file SM|ME location [-nokia]" SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7305 #endif
7306 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Settings,0}, "PROFILE " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PROFILE_OPTIONS},
7307 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "EMS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_EMS_OPTIONS},
7309 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "TEXT destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_TEXT_OPTIONS},
7310 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7311 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS},
7312 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7313 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS},
7314 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR destination URL Title Sender " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7315 #ifdef GSM_ENABLE_BACKUP
7316 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7317 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS destination file location DATA|GPRS " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7318 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7319 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7320 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7321 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Memory,0}, "VCARD10|VCARD21 destination file SM|ME location [-nokia]" SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7322 #endif
7323 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Settings,0}, "PROFILE destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS ""SMS_PROFILE_OPTIONS},
7324 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "EMS destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_EMS_OPTIONS},
7326 {"--displaysms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, ""},
7328 {"--addsmsfolder", 1, 1, AddSMSFolder, {H_SMS,0}, "name"},
7329 {"--smsd", 2, 2, SMSDaemon, {H_SMS,H_Other,0}, "FILES configfile"},
7330 {"--getringtone", 1, 2, GetRingtone, {H_Ringtone,0}, "location [file]"},
7331 {"--getphoneringtone", 1, 2, GetRingtone, {H_Ringtone,0}, "location [file]"},
7332 {"--getringtoneslist", 0, 0, GetRingtonesList, {H_Ringtone,0}, ""},
7333 {"--setringtone", 1, 6, SetRingtone, {H_Ringtone,0}, "file [-location location][-scale][-name name]"},
7334 {"--nokiacomposer", 1, 1, NokiaComposer, {H_Ringtone,H_Nokia,0}, "file"},
7335 {"--copyringtone", 2, 3, CopyRingtone, {H_Ringtone,0}, "source destination [RTTL|BINARY]"},
7336 {"--dialvoice", 1, 2, DialVoice, {H_Call,0}, "number [show|hide]"},
7337 {"--getspeeddial", 1, 2, GetSpeedDial, {H_Call,H_Memory,0}, "start [stop]"},
7338 {"--cancelcall", 0, 1, CancelCall, {H_Call,0}, "[ID]"},
7339 {"--answercall", 0, 1, AnswerCall, {H_Call,0}, "[ID]"},
7340 {"--unholdcall", 1, 1, UnholdCall, {H_Call,0}, "ID"},
7341 {"--holdcall", 1, 1, HoldCall, {H_Call,0}, "ID"},
7342 {"--conferencecall", 1, 1, ConferenceCall, {H_Call,0}, "ID"},
7343 {"--splitcall", 1, 1, SplitCall, {H_Call,0}, "ID"},
7344 {"--switchcall", 0, 1, SwitchCall, {H_Call,0}, "[ID]"},
7345 {"--transfercall", 0, 1, TransferCall, {H_Call,0}, "[ID]"},
7346 {"--divert", 3, 5, CallDivert, {H_Call,0}, "get|set all|busy|noans|outofreach all|voice|fax|data [number timeout]"},
7347 {"--canceldiverts", 0, 0, CancelAllDiverts, {H_Call,0}, ""},
7348 {"--senddtmf", 1, 1, SendDTMF, {H_Call,0}, "sequence"},
7349 {"--getcalendarsettings", 0, 0, GetCalendarSettings, {H_Calendar,H_Settings,0}, ""},
7350 {"--getalltodo", 0, 0, GetAllToDo, {H_ToDo,0}, ""},
7351 {"--listtodocategory", 1, 1, ListToDoCategory, {H_ToDo, H_Category,0}, "text|number"},
7352 {"--gettodo", 1, 2, GetToDo, {H_ToDo,0}, "start [stop]"},
7353 {"--deletetodo", 1, 2, DeleteToDo, {H_ToDo,0}, "start [stop]"},
7354 {"--getnote", 1, 2, GetNote, {H_Note,0}, "start [stop]"},
7355 {"--deletecalendar", 1, 2, DeleteCalendar, {H_Calendar,0}, "start [stop]"},
7356 {"--getallcalendar", 0, 0, GetAllCalendar, {H_Calendar,0}, ""},
7357 {"--getcalendar", 1, 2, GetCalendar, {H_Calendar,0}, "start [stop]"},
7358 {"--getcategory", 2, 3, GetCategory, {H_Category,H_ToDo,H_Memory,0}, "TODO|PHONEBOOK start [stop]"},
7359 {"--getallcategory", 1, 1, GetAllCategories, {H_Category,H_ToDo,H_Memory,0}, "TODO|PHONEBOOK"},
7360 {"--reset", 1, 1, Reset, {H_Other,0}, "SOFT|HARD"},
7361 {"--getprofile", 1, 2, GetProfile, {H_Settings,0}, "start [stop]"},
7362 {"--getsecuritystatus", 0, 0, GetSecurityStatus, {H_Info,0}, ""},
7363 {"--entersecuritycode", 2, 2, EnterSecurityCode, {H_Other,0}, "PIN|PUK|PIN2|PUK2 code"},
7364 {"--deletewapbookmark", 1, 2, DeleteWAPBookmark, {H_WAP,0}, "start [stop]"},
7365 {"--getwapbookmark", 1, 2, GetWAPBookmark, {H_WAP,0}, "start [stop]"},
7366 {"--getwapsettings", 1, 2, GetWAPMMSSettings, {H_WAP,0}, "start [stop]"},
7367 {"--getmmssettings", 1, 2, GetWAPMMSSettings, {H_MMS,0}, "start [stop]"},
7368 {"--savemmsfile", 3, 15,SaveMMSFile, {H_MMS,0}, "file [-subject text][-text text]"},
7369 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "STARTUP [file]"},
7370 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "CALLER location [file]"},
7371 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "OPERATOR [file]"},
7372 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "PICTURE location [file]"},
7373 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "TEXT"},
7374 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "DEALER"},
7375 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "STARTUP file|1|2|3"},
7376 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "COLOURSTARTUP [fileID]"},
7377 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "WALLPAPER fileID"},
7378 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "CALLER location [file]"},
7379 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "OPERATOR [file [netcode]]"},
7380 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "COLOUROPERATOR [fileID [netcode]]"},
7381 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "PICTURE file location [text]"},
7382 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "TEXT text"},
7383 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "DEALER text"},
7384 {"--copybitmap", 1, 3, CopyBitmap, {H_Logo,0}, "inputfile [outputfile [OPERATOR|PICTURE|STARTUP|CALLER]]"},
7385 {"--presskeysequence", 1, 1, PressKeySequence, {H_Other,0}, "mMnNpPuUdD+-123456789*0#gGrRwW"},
7386 #if defined(WIN32) || defined(HAVE_PTHREAD)
7387 {"--searchphone", 0, 1, SearchPhone, {H_Other,0}, "[-debug]"},
7388 #endif
7389 #ifdef GSM_ENABLE_BACKUP
7390 {"--savefile", 4, 5, SaveFile, {H_Backup,H_Calendar,0}, "CALENDAR target.vcs file location"},
7391 {"--savefile", 4, 5, SaveFile, {H_Backup,H_ToDo,0}, "TODO target.vcs file location"},
7392 {"--savefile", 4, 5, SaveFile, {H_Backup,H_Memory,0}, "VCARD10|VCARD21 target.vcf file SM|ME location"},
7393 {"--savefile", 4, 5, SaveFile, {H_Backup,H_WAP,0}, "BOOKMARK target.url file location"},
7394 {"--backup", 1, 1, Backup, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file"},
7395 {"--backupsms", 1, 1, BackupSMS, {H_Backup,H_SMS,0}, "file"},
7396 {"--restore", 1, 1, Restore, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file"},
7397 {"--addnew", 1, 1, AddNew, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file"},
7398 {"--restoresms", 1, 1, RestoreSMS, {H_Backup,H_SMS,0}, "file"},
7399 #endif
7400 {"--clearall", 0, 0, ClearAll, {H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, ""},
7401 #ifdef GSM_ENABLE_AT
7402 {"--siemenssatnetmon", 0, 0, ATSIEMENSSATNetmon, {H_Siemens,H_Network,0}, ""},
7403 {"--siemensnetmonitor", 1, 1, ATSIEMENSNetmonitor, {H_Siemens,H_Network,0}, "test"},
7404 #endif
7405 #ifdef GSM_ENABLE_NOKIA6110
7406 {"--nokiagetoperatorname", 0, 0, DCT3GetOperatorName, {H_Nokia,H_Network,0}, ""},
7407 {"--nokiasetoperatorname", 0, 2, DCT3SetOperatorName, {H_Nokia,H_Network,0}, "[networkcode name]"},
7408 {"--nokiadisplayoutput", 0, 0, DCT3DisplayOutput, {H_Nokia,0}, ""},
7409 #endif
7410 #ifdef GSM_ENABLE_NOKIA_DCT3
7411 {"--nokianetmonitor", 1, 1, DCT3netmonitor, {H_Nokia,H_Network,0}, "test"},
7412 {"--nokianetmonitor36", 0, 0, DCT3ResetTest36, {H_Nokia,0}, ""},
7413 {"--nokiadebug", 1, 2, DCT3SetDebug, {H_Nokia,H_Network,0}, "filename [[v11-22][,v33-44]...]"},
7414 #endif
7415 #ifdef GSM_ENABLE_NOKIA_DCT4
7416 {"--nokiasetvibralevel", 1, 1, DCT4SetVibraLevel, {H_Nokia,H_Other,0}, "level"},
7417 {"--nokiagetvoicerecord", 1, 1, DCT4GetVoiceRecord, {H_Nokia,H_Other,0}, "location"},
7418 {"--nokiasetlights", 2, 2, DCT4SetLight, {H_Nokia,H_Tests,0}, "keypad|display|torch on|off"},
7419 {"--nokiatuneradio", 0, 0, DCT4TuneRadio, {H_Nokia,H_FM,0}, ""},
7420 #endif
7421 #if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
7422 {"--nokiavibratest", 0, 0, NokiaVibraTest, {H_Nokia,H_Tests,0}, ""},
7423 {"--nokiagett9", 0, 0, NokiaGetT9, {H_Nokia,H_SMS,0}, ""},
7424 {"--nokiadisplaytest", 1, 1, NokiaDisplayTest, {H_Nokia,H_Tests,0}, "number"},
7425 {"--nokiagetadc", 0, 0, NokiaGetADC, {H_Nokia,H_Tests,0}, ""},
7426 {"--nokiasecuritycode", 0, 0, NokiaSecurityCode, {H_Nokia,H_Info,0}, ""},
7427 {"--nokiaselftests", 0, 0, NokiaSelfTests, {H_Nokia,H_Tests,0}, ""},
7428 {"--nokiasetphonemenus", 0, 0, NokiaSetPhoneMenus, {H_Nokia,H_Other,0}, ""},
7429 #endif
7430 #ifdef DEBUG
7431 {"--decodesniff", 2, 3, decodesniff, {H_Decode,0}, "MBUS2|IRDA file [phonemodel]"},
7432 {"--decodebinarydump", 1, 2, decodebinarydump, {H_Decode,0}, "file [phonemodel]"},
7433 {"--makeconverttable", 1, 1, MakeConvertTable, {H_Decode,0}, "file"},
7434 #endif
7435 {"", 0, 0, NULL }
7438 static HelpCategoryDescriptions HelpDescriptions[] = {
7439 {H_Call, "call", "Calls",},
7440 {H_SMS, "sms", "SMS and EMS"},
7441 {H_Memory, "memory", "Memory (phonebooks and calls)"},
7442 {H_Filesystem, "filesystem", "Filesystem"},
7443 {H_Logo, "logo", "Logo and pictures"},
7444 {H_Ringtone, "ringtone", "Ringtones"},
7445 {H_Calendar, "calendar", "Calendar notes"},
7446 {H_ToDo, "todo", "To do lists"},
7447 {H_Note, "note", "Notes"},
7448 {H_DateTime, "datetime", "Date, time and alarms"},
7449 {H_Category, "category", "Categories"},
7450 #ifdef GSM_ENABLE_BACKUP
7451 {H_Backup, "backup", "Backing up and restoring"},
7452 #endif
7453 #if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
7454 {H_Nokia, "nokia", "Nokia specific"},
7455 #endif
7456 #ifdef GSM_ENABLE_AT
7457 {H_Siemens, "siemens", "Siemens specific"},
7458 #endif
7459 {H_Network, "network", "Network"},
7460 {H_WAP, "wap", "WAP settings and bookmarks"},
7461 {H_MMS, "mms", "MMS and MMS settings"},
7462 {H_Tests, "tests", "Phone tests"},
7463 {H_FM, "fm", "FM radio"},
7464 {H_Info, "info", "Phone information"},
7465 {H_Settings, "settings", "Phone settings"},
7466 #ifdef DEBUG
7467 {H_Decode, "decode", "Dumps decoding"},
7468 #endif
7469 {H_Other, "other", "Functions that don't fit elsewhere"},
7470 {0, NULL, NULL}
7474 void HelpHeader(void)
7476 printmsg("[Gammu version %s built %s %s]\n\n",VERSION,__TIME__,__DATE__);
7479 static void HelpGeneral(void)
7481 int i=0;
7483 HelpHeader();
7485 printmsg("Usage: gammu [confign] [nothing|text|textall|binary|errors] [options]\n\n");
7486 printmsg("First parameter optionally specifies which config section to use (by default are probed all).\n");
7487 printmsg("Second parameter optionally controls debug level, next specify actions.\n\n");
7489 /* We might want to put here some most used commands */
7490 printmsg("For more details call help on specific topic (gammu --help topic), topics are:\n\n");
7492 while (HelpDescriptions[i].category != 0) {
7493 printf("%11s - %s\n", HelpDescriptions[i].option, HelpDescriptions[i].description);
7494 i++;
7496 printf("\n");
7499 static void HelpSplit(int cols, int len, unsigned char *buff)
7501 int l, len2, pos, split;
7502 bool in_opt,first=true;
7503 char *remain, spaces[50], buffer[500];
7505 if (cols == 0) {
7506 printf(" %s\n", buff);
7507 } else {
7508 printf(" ");
7509 spaces[0] = 0;
7510 len2 = strlen(buff);
7511 if (len + len2 < cols) {
7512 printf("%s\n", buff);
7513 } else {
7514 for(l = 0; l < len; l++) strcat(spaces, " ");
7516 remain = buff;
7518 while (strlen(remain) > 0) {
7519 split = 0;
7520 pos = 0;
7521 in_opt = false;
7522 if (!first) printf(spaces);
7523 while (pos < cols - len && remain[pos] != 0) {
7524 if (in_opt && remain[pos] == ']') {
7525 in_opt = false;
7526 split = pos;
7527 } else if (remain[pos] == '[') {
7528 in_opt = true;
7529 } else if (!in_opt && remain[pos] == ' ') {
7530 split = pos - 1;
7532 pos++;
7534 /* Can not be split */
7535 if (split == 0) {
7536 printf("%s\n", remain);
7537 remain += strlen(remain);
7538 } else {
7539 first = false;
7540 split++;
7541 strncpy(buffer, remain, split);
7542 buffer[split] = 0;
7543 printf("%s\n", buffer);
7544 remain += split;
7545 if (remain[0] == ' ') remain++;
7552 static void Help(int argc, char *argv[])
7554 int i = 0, j = 0, k, cols;
7555 bool disp;
7556 #ifdef TIOCGWINSZ
7557 struct winsize w;
7558 #endif
7559 #if defined(WIN32) || defined(DJGPP)
7560 #else
7561 char *columns;
7562 #endif
7564 /* Just --help */
7565 if (argc == 2) {
7566 HelpGeneral();
7567 return;
7570 if (!strcmp(argv[2],"all")) {
7571 HelpHeader();
7572 } else {
7573 while (HelpDescriptions[i].category != 0) {
7574 if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break;
7575 i++;
7577 if (HelpDescriptions[i].category == 0) {
7578 HelpGeneral();
7579 printmsg("Unknown help topic specified!\n");
7580 return;
7582 HelpHeader();
7583 printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description);
7586 #if defined(WIN32) || defined(DJGPP)
7587 cols = 80;
7588 #else
7589 cols = 0;
7590 /* If stdout is a tty, we will wrap to columns it has */
7591 if (isatty(1)) {
7592 #ifdef TIOCGWINSZ
7593 if (ioctl(2, TIOCGWINSZ, &w) == 0) {
7594 if (w.ws_col > 0) cols = w.ws_col;
7596 #endif
7597 if (cols == 0) {
7598 columns = getenv("COLUMNS");
7599 if (columns != NULL) {
7600 cols = atoi(columns);
7601 if (cols <= 0) cols = 0;
7605 if (cols == 0) {
7606 /* Fallback */
7607 cols = 80;
7610 #endif
7612 while (Parameters[j].Function != NULL) {
7613 k = 0;
7614 disp = false;
7615 if (!strcmp(argv[2],"all")) {
7616 if (j==0) disp = true;
7617 if (j!=0) {
7618 if (strcmp(Parameters[j].help,Parameters[j-1].help)) {
7619 disp = true;
7620 } else {
7621 if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) {
7622 disp = true;
7626 } else {
7627 while (Parameters[j].help_cat[k] != 0) {
7628 if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) {
7629 disp = true;
7630 break;
7632 k++;
7635 if (disp) {
7636 printf("%s", Parameters[j].parameter);
7637 if (Parameters[j].help[0] == 0) {
7638 printf("\n");
7639 } else {
7640 HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help);
7643 j++;
7647 int main(int argc, char *argv[])
7649 int z = 0,start=0,i;
7650 int only_config = -1;
7651 #if !defined(WIN32) && defined(LOCALE_PATH)
7652 char *locale, locale_file[201];
7653 #endif
7654 char *cp;
7655 bool count_failed = false;
7657 s.opened = false;
7658 s.msg = NULL;
7659 s.ConfigNum = 0;
7661 setlocale(LC_ALL, "");
7662 #ifdef DEBUG
7663 di.dl = DL_TEXTALL;
7664 di.df = stdout;
7665 #endif
7667 /* Any parameters? */
7668 if (argc == 1) {
7669 HelpGeneral();
7670 printmsg("Too few parameters!\n");
7671 exit(1);
7674 /* Help? */
7675 if (strncmp(argv[1 + start], "--help", 6) == 0) {
7676 Help(argc - start, argv + start);
7677 exit(1);
7680 /* Is first parameter numeric? If so treat it as config that should be loaded. */
7681 if (isdigit(argv[1][0])) {
7682 only_config = atoi(argv[1]);
7683 if (only_config >= 0) start++;
7684 else only_config = -1;
7687 cfg=GSM_FindGammuRC();
7688 for (i=0;i<5;i++) {
7689 if (cfg!=NULL) {
7690 cp = INI_GetValue(cfg, "gammu", "gammucoding", false);
7691 if (cp) di.coding = cp;
7693 s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false);
7694 if (s.Config[i].Localize) {
7695 s.msg=INI_ReadFile(s.Config[i].Localize, true);
7696 } else {
7697 #if !defined(WIN32) && defined(LOCALE_PATH)
7698 locale = setlocale(LC_MESSAGES, NULL);
7699 if (locale != NULL) {
7700 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
7701 LOCALE_PATH,
7702 tolower(locale[0]),
7703 tolower(locale[1]));
7704 s.msg = INI_ReadFile(locale_file, true);
7706 #endif
7710 /* Wanted user specific configuration? */
7711 if (only_config != -1) {
7712 /* Here we get only in first for loop */
7713 if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break;
7714 } else {
7715 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
7717 s.ConfigNum++;
7719 /* We want to use only one file descriptor for global and state machine debug output */
7720 s.Config[i].UseGlobalDebugFile = true;
7722 /* It makes no sense to open several debug logs... */
7723 if (i != 0) {
7724 strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel);
7725 // free(s.Config[i].DebugFile);
7726 s.Config[i].DebugFile = s.Config[0].DebugFile;
7727 } else {
7728 /* Just for first config */
7729 /* When user gave debug level on command line */
7730 if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) {
7731 /* Debug level from command line will be used with phone too */
7732 strcpy(s.Config[i].DebugLevel,argv[1 + start]);
7733 start++;
7734 } else {
7735 /* Try to set debug level from config file */
7736 GSM_SetDebugLevel(s.Config[i].DebugLevel, &di);
7738 /* If user gave debug file in gammurc, we will use it */
7739 error=GSM_SetDebugFile(s.Config[i].DebugFile, &di);
7740 Print_Error(error);
7743 /* We wanted to read just user specified configuration. */
7744 if (only_config != -1) {break;}
7747 /* Do we have enough parameters? */
7748 if (argc == 1 + start) {
7749 HelpGeneral();
7750 printmsg("Too few parameters!\n");
7751 exit(-2);
7754 /* Check used version vs. compiled */
7755 if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) {
7756 printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n",
7757 GetGammuVersion(),VERSION);
7758 exit(-1);
7761 /* Check parameters */
7762 while (Parameters[z].Function != NULL) {
7763 if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) {
7764 if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) {
7765 Parameters[z].Function(argc - start, argv + start);
7766 break;
7767 } else {
7768 count_failed = true;
7771 z++;
7774 /* Tell user when we did nothing */
7775 if (Parameters[z].Function == NULL) {
7776 HelpGeneral();
7777 if (count_failed) {
7778 printmsg("Bad parameter count!\n");
7779 } else {
7780 printmsg("Bad option!\n");
7784 /* Close debug output if opened */
7785 if (di.df!=stdout) fclose(di.df);
7787 exit(0);
7790 /* How should editor hadle tabs in this file? Add editor commands here.
7791 * vim: noexpandtab sw=8 ts=8 sts=8: