Beispiel #1
0
/**
 * @name gammu_create:
 */
gammu_state_t *gammu_create(const char *config_path) {

  gammu_state_t *s = allocate(sizeof(*s));

  INI_Section *ini;
  GSM_InitLocales(NULL);

  if ((s->err = GSM_FindGammuRC(&ini, config_path)) != ERR_NONE) {
    goto cleanup;
  }

  s->sm = GSM_AllocStateMachine();
  GSM_Config *cfg = GSM_GetConfig(s->sm, 0);

  if ((s->err = GSM_ReadConfig(ini, cfg, 0)) != ERR_NONE) {
    goto cleanup_state;
  }

  INI_Free(ini);
  GSM_SetConfigNum(s->sm, 1);

  if ((s->err = GSM_InitConnection(s->sm, 1)) != ERR_NONE) {
    goto cleanup_state;
  }

  /* Success */
  return s;

  cleanup_state:
    GSM_FreeStateMachine(s->sm);
  
  cleanup:
    free(s);
    return NULL;
}
Beispiel #2
0
void single_check(const char *device, const char *connection, const char *model, GSM_Error expected)
{
	GSM_Config *smcfg;
	GSM_Error error;
	GSM_Debug_Info *debug_info;

	/* Allocates state machine */
	s = GSM_AllocStateMachine();
	test_result(s != NULL);

	debug_info = GSM_GetDebug(s);
	GSM_SetDebugGlobal(TRUE, debug_info);

	smcfg = GSM_GetConfig(s, 0);
	strcpy(smcfg->Model, model);
	smcfg->Device = strdup(device);
	smcfg->UseGlobalDebugFile = TRUE;
	smcfg->Connection = strdup(connection);
	smcfg->PhoneFeatures[0] = F_PBK_ENCODENUMBER;
	smcfg->PhoneFeatures[1] = 0;
	GSM_SetConfigNum(s, 1);

	error = GSM_InitConnection(s, 1);
	test_result(error == expected);

	/* Free state machine */
	GSM_FreeStateMachine(s);
}
Beispiel #3
0
/* Handler for SMS send reply */
void send_sms_callback (GSM_StateMachine *sm, int status, int MessageReference, void * user_data)
{
	printf("Sent SMS on device: \"%s\"\n", GSM_GetConfig(sm, -1)->Device);
	if (status==0) {
		printf("..OK");
		sms_send_status = ERR_NONE;
	} else {
		printf("..error %i", status);
		sms_send_status = ERR_UNKNOWN;
	}
	printf(", message reference=%d\n", MessageReference);
}
Beispiel #4
0
void Restore(int argc, char *argv[])
{
	GSM_Error error;
	GSM_Backup		Backup;
	GSM_FMStation		FMStation;
	GSM_DateTime 		date_time;
	GSM_CalendarEntry	Calendar;
	GSM_Bitmap		Bitmap;
	GSM_Ringtone		Ringtone;
	GSM_MemoryEntry		Pbk;
	GSM_MemoryStatus	MemStatus;
	GSM_ToDoEntry		ToDo;
	GSM_ToDoStatus		ToDoStatus;
	GSM_NoteEntry		Note;
	GSM_Profile		Profile;
	GSM_MultiWAPSettings	Settings;
	GSM_GPRSAccessPoint	GPRSPoint;
	GSM_WAPBookmark		Bookmark;
	int			i, j, used, max = 0;
	gboolean			Past = TRUE, First;
	gboolean			Found, DoRestore;

	error = GSM_ReadBackupFile(argv[2],&Backup,GSM_GuessBackupFormat(argv[2], FALSE));
	Print_Error(error);

	signal(SIGINT, interrupt);
	fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));

	if (Backup.DateTimeAvailable) 	fprintf(stderr, LISTFORMAT "%s\n", _("Time of backup"),OSDateTime(Backup.DateTime,FALSE));
	if (Backup.Model[0]!=0) 	fprintf(stderr, LISTFORMAT "%s\n", _("Phone"),Backup.Model);
	if (Backup.IMEI[0]!=0) 		fprintf(stderr, LISTFORMAT "%s\n", _("IMEI"),Backup.IMEI);
	if (Backup.Creator[0]!=0) 	fprintf(stderr, LISTFORMAT "%s\n", _("File created by"),Backup.Creator);

	if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE;

	if (Backup.MD5Calculated[0]!=0) {
		if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) {
			if (!answer_yes(_("Checksum in backup file do not match (original: %s, new: %s). Continue?"), Backup.MD5Original, Backup.MD5Calculated)) return;
		}
	}

	GSM_Init(TRUE);

	printf("%s\n", _("Please note that restoring data will cause existing data in phone to be deleted."));
	printf("%s\n", _("Use addnew command if you just want to add some entries to your phone."));

	DoRestore = FALSE;
	if (Backup.CallerLogos[0] != NULL) {
		Bitmap.Type 	= GSM_CallerGroupLogo;
		Bitmap.Location = 1;
		error=GSM_GetBitmap(gsm,&Bitmap);
		if (error == ERR_NONE) {
			if (answer_yes("%s", _("Restore phone caller groups and logos?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		max = 0;
		while (Backup.CallerLogos[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			error=GSM_SetBitmap(gsm,Backup.CallerLogos[i]);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}

	DoRestore = FALSE;
	if (Backup.PhonePhonebook[0] != NULL) {
		max = 0;
		while (Backup.PhonePhonebook[max]!=NULL) max++;
		MemStatus.MemoryType = MEM_ME;
		error=GSM_GetMemoryStatus(gsm, &MemStatus);
		/* Some phones do not support status, try reading some entry */
		if (error != ERR_NONE) {
			Pbk.Location = 1;
			Pbk.MemoryType = MEM_ME;
			error = GSM_GetMemory(gsm, &Pbk);
			MemStatus.MemoryUsed = max;
			MemStatus.MemoryFree = max;
		}
		if (error == ERR_NONE || error == ERR_EMPTY) {
			fprintf(stderr, _("%i entries in backup file\n"),max);
			if (answer_yes("%s", _("Restore phone phonebook?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		used = 0;
		for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
			Pbk.MemoryType 	= MEM_ME;
			Pbk.Location	= i + 1;
			Pbk.EntriesNum	= 0;
			if (used<max && Backup.PhonePhonebook[used]->Location == Pbk.Location) {
				Pbk = *Backup.PhonePhonebook[used];
				used++;
				if (Pbk.EntriesNum != 0) error=GSM_SetMemory(gsm, &Pbk);
				if (error == ERR_PERMISSION && GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_6230iCALLER)) {
					error=GSM_DeleteMemory(gsm, &Pbk);
					Print_Error(error);
					error=GSM_SetMemory(gsm, &Pbk);
				}
				if (error == ERR_MEMORY && GSM_IsPhoneFeatureAvailable(GSM_GetModelInfo(gsm), F_6230iCALLER)) {
					printf_err("%s\n", _("Probably caller group is missing from your backup, add it and use --restore again."));
					GSM_Terminate();
					Terminate(2);
				}
				if (Pbk.EntriesNum != 0 && error==ERR_NONE) {
					First = TRUE;
					for (j=0;j<Pbk.EntriesNum;j++) {
			 			if (Pbk.Entries[j].AddError == ERR_NONE) continue;
						if (First) {
							printf("\r");
							printf(_("Location %d"), Pbk.Location);
							printf("%20s\n    ", " ");
							First = FALSE;
						}
						PrintMemorySubEntry(&Pbk.Entries[j], gsm);
						printf("    %s\n", GSM_ErrorString(Pbk.Entries[j].AddError));
					}
				}
			}
			if (Pbk.EntriesNum == 0) {
				/* Delete only when there was some content in phone */
				if (MemStatus.MemoryUsed > 0) {
					error = GSM_DeleteMemory(gsm, &Pbk);
					if (error != ERR_EMPTY && error != ERR_NONE) {
						Print_Error(error);
					}
				}
			}
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
					(i + 1) * 100 / (MemStatus.MemoryUsed + MemStatus.MemoryFree)
					);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}

	DoRestore = FALSE;
	if (Backup.SIMPhonebook[0] != NULL) {
		MemStatus.MemoryType = MEM_SM;
		error=GSM_GetMemoryStatus(gsm, &MemStatus);
		if (error==ERR_NONE) {
			max = 0;
			while (Backup.SIMPhonebook[max]!=NULL) max++;
			fprintf(stderr, _("%i entries in backup file\n"),max);
			if (answer_yes("%s", _("Restore SIM phonebook?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		used = 0;
		for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
			Pbk.MemoryType 	= MEM_SM;
			Pbk.Location	= i + 1;
			Pbk.EntriesNum	= 0;
			if (used<max && Backup.SIMPhonebook[used]->Location == Pbk.Location) {
				Pbk = *Backup.SIMPhonebook[used];
				used++;
				if (Pbk.EntriesNum != 0) {
					error=GSM_SetMemory(gsm, &Pbk);
					if (error==ERR_NONE) {
						First = TRUE;
						for (j=0;j<Pbk.EntriesNum;j++) {
					 		if (Pbk.Entries[j].AddError == ERR_NONE) continue;
							if (First) {
								printf("\r");
								printf(_("Location %d"), Pbk.Location);
								printf("%20s\n    ", " ");
								First = FALSE;
							}
							PrintMemorySubEntry(&Pbk.Entries[j], gsm);
							printf("    %s\n",GSM_ErrorString(Pbk.Entries[j].AddError));
						}
					}
				}
			}
			if (Pbk.EntriesNum == 0) error=GSM_DeleteMemory(gsm, &Pbk);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / (MemStatus.MemoryUsed + MemStatus.MemoryFree));
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}

	if (GSM_GetConfig(gsm, -1)->SyncTime == FALSE) {
		if (answer_yes("%s", _("Do you want to set phone date/time? (NOTE: in some phones it's required to correctly restore calendar notes and other items)"))) {
			GSM_GetCurrentDateTime(&date_time);

			error=GSM_SetDateTime(gsm, &date_time);
			Print_Error(error);
		}
	}
	DoRestore = FALSE;
	if (Backup.Calendar[0] != NULL) {
		Calendar.Location = 0;
		/* N6110 doesn't support getting calendar status */
		error = GSM_GetNextCalendar(gsm,&Calendar,TRUE);
		if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) {
			max = 0;
			while (Backup.Calendar[max] != NULL) max++;
			fprintf(stderr, _("%i entries in backup file\n"),max);
			if (answer_yes("%s", _("Restore phone calendar notes?"))) {
				Past    = answer_yes("   %s", _("Restore notes from the past?"));
				DoRestore = TRUE;
			}
		}
	}
	if (DoRestore) {
		fprintf(stderr, "%s ", _("Deleting old notes:"));
		error = GSM_DeleteAllCalendar(gsm);
		if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
 			while (1) {
				error = GSM_GetNextCalendar(gsm,&Calendar,TRUE);
				if (error != ERR_NONE) break;
				error = GSM_DeleteCalendar(gsm,&Calendar);
 				Print_Error(error);
				fprintf(stderr, "*");
			}
			fprintf(stderr, "\n");
		} else {
			fprintf(stderr, "%s\n", _("Done"));
			Print_Error(error);
		}

		for (i=0;i<max;i++) {
			if (!Past && GSM_IsCalendarNoteFromThePast(Backup.Calendar[i])) continue;

			Calendar = *Backup.Calendar[i];
			error=GSM_AddCalendar(gsm,&Calendar);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}

	DoRestore = FALSE;
	if (Backup.ToDo[0] != NULL) {
		error = GSM_GetToDoStatus(gsm,&ToDoStatus);
		if (error == ERR_NONE) {
			max = 0;
			while (Backup.ToDo[max]!=NULL) max++;
			fprintf(stderr, _("%i entries in backup file\n"),max);

			if (answer_yes("%s", _("Restore phone todo?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		ToDo  = *Backup.ToDo[0];
		error = GSM_SetToDo(gsm,&ToDo);
	}
	if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) {
		fprintf(stderr, "%s ", _("Deleting old todos:"));
		error=GSM_DeleteAllToDo(gsm);
		if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
			while (1) {
				error = GSM_GetNextToDo(gsm,&ToDo,TRUE);
				if (error != ERR_NONE) break;
				error = GSM_DeleteToDo(gsm,&ToDo);
 				Print_Error(error);
				fprintf(stderr, "*");
			}
			fprintf(stderr, "\n");
		} else {
			fprintf(stderr, "%s\n", _("Done"));
			Print_Error(error);
		}

		for (i=0;i<max;i++) {
			ToDo 		= *Backup.ToDo[i];
			ToDo.Location 	= 0;
			error=GSM_AddToDo(gsm,&ToDo);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	} else if (DoRestore) {
		/* At first delete entries, that were deleted */
		used  = 0;
		error = GSM_GetNextToDo(gsm,&ToDo,TRUE);
		while (error == ERR_NONE) {
			used++;
			Found = FALSE;
			for (i=0;i<max;i++) {
				if (Backup.ToDo[i]->Location == ToDo.Location) {
					Found = TRUE;
					break;
				}
			}
			if (!Found) {
				error=GSM_DeleteToDo(gsm,&ToDo);
				Print_Error(error);
			}
			error = GSM_GetNextToDo(gsm,&ToDo,FALSE);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				used * 100 / ToDoStatus.Used);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");

		/* Now write modified/new entries */
		for (i=0;i<max;i++) {
			ToDo  = *Backup.ToDo[i];
			error = GSM_SetToDo(gsm,&ToDo);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
 	}

	DoRestore = FALSE;
	if (Backup.Note[0] != NULL) {
		error = GSM_GetNotesStatus(gsm,&ToDoStatus);
		if (error == ERR_NONE) {
			max = 0;
			while (Backup.Note[max]!=NULL) max++;
			fprintf(stderr, _("%i entries in backup file\n"),max);

			if (answer_yes("%s", _("Restore phone notes?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		fprintf(stderr, "%s ", _("Deleting old notes:"));
		while (1) {
			error = GSM_GetNextNote(gsm,&Note,TRUE);
			if (error != ERR_NONE) break;
			error = GSM_DeleteNote(gsm,&Note);
 			Print_Error(error);
			fprintf(stderr, "*");
		}
		fprintf(stderr, "\n");

		for (i=0;i<max;i++) {
			Note 		= *Backup.Note[i];
			Note.Location 	= 0;
			error=GSM_AddNote(gsm,&Note);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}

	if (Backup.SMSC[0] != NULL && answer_yes("%s", _("Restore SIM SMSC profiles?"))) {
		max = 0;
		while (Backup.SMSC[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			error=GSM_SetSMSC(gsm,Backup.SMSC[i]);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}
	if (Backup.StartupLogo != NULL && answer_yes("%s", _("Restore phone startup logo/text?"))) {
		error=GSM_SetBitmap(gsm,Backup.StartupLogo);
		Print_Error(error);
	}
	if (Backup.OperatorLogo != NULL && answer_yes("%s", _("Restore phone operator logo?"))) {
		error=GSM_SetBitmap(gsm,Backup.OperatorLogo);
		Print_Error(error);
	}
	DoRestore = FALSE;
	if (Backup.WAPBookmark[0] != NULL) {
		Bookmark.Location = 1;
		error = GSM_GetWAPBookmark(gsm,&Bookmark);
		if (error == ERR_NONE || error == ERR_INVALIDLOCATION) {
			if (answer_yes("%s", _("Restore phone WAP bookmarks?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		fprintf(stderr, "%s ", _("Deleting old bookmarks:"));
		/* One thing to explain: DCT4 phones seems to have bug here.
		 * When delete for example first bookmark, phone change
		 * numeration for getting frame, not for deleting. So, we try to
		 * get 1'st bookmark. Inside frame is "correct" location. We use
		 * it later
		 */
		while (error==ERR_NONE) {
			error = GSM_DeleteWAPBookmark(gsm,&Bookmark);
			Bookmark.Location = 1;
			error = GSM_GetWAPBookmark(gsm,&Bookmark);
			fprintf(stderr, "*");
		}
		fprintf(stderr, "\n");
		max = 0;
		while (Backup.WAPBookmark[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			Bookmark 	  = *Backup.WAPBookmark[i];
			Bookmark.Location = 0;
			error=GSM_SetWAPBookmark(gsm,&Bookmark);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}
	DoRestore = FALSE;
	if (Backup.WAPSettings[0] != NULL) {
		Settings.Location = 1;
		error = GSM_GetWAPSettings(gsm,&Settings);
		if (error == ERR_NONE) {
			if (answer_yes("%s", _("Restore phone WAP settings?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		max = 0;
		while (Backup.WAPSettings[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			error=GSM_SetWAPSettings(gsm,Backup.WAPSettings[i]);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}
	DoRestore = FALSE;
	if (Backup.MMSSettings[0] != NULL) {
		Settings.Location = 1;
		error = GSM_GetMMSSettings(gsm,&Settings);
		if (error == ERR_NONE) {
			if (answer_yes("%s", _("Restore phone MMS settings?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		max = 0;
		while (Backup.MMSSettings[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			error=GSM_SetMMSSettings(gsm,Backup.MMSSettings[i]);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}
	DoRestore = FALSE;
	if (Backup.Ringtone[0] != NULL) {
		Ringtone.Location 	= 1;
		Ringtone.Format		= 0;
		error = GSM_GetRingtone(gsm,&Ringtone,FALSE);
		if (error == ERR_NONE || error ==ERR_EMPTY) {
			if (answer_yes("%s", _("Delete all phone user ringtones?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		fprintf(stderr, LISTFORMAT, _("Deleting"));
		error=GSM_DeleteUserRingtones(gsm);
		Print_Error(error);
		fprintf(stderr, "%s\n", _("Done"));
		DoRestore = FALSE;
		if (answer_yes("%s", _("Restore user ringtones?"))) DoRestore = TRUE;
	}
	if (DoRestore) {
		max = 0;
		while (Backup.Ringtone[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format);
			Print_Error(error);
			error=GSM_SetRingtone(gsm,&Ringtone,&i);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}
	DoRestore = FALSE;
	if (Backup.Profiles[0] != NULL) {
		Profile.Location = 1;
		error = GSM_GetProfile(gsm,&Profile);
		if (error == ERR_NONE) {
			if (answer_yes("%s", _("Restore phone profiles?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		Profile.Location= 0;
		max = 0;
		while (Backup.Profiles[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			Profile	= *Backup.Profiles[i];
			error=GSM_SetProfile(gsm,&Profile);
			Print_Error(error);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}
	DoRestore = FALSE;
	if (Backup.FMStation[0] != NULL) {
		FMStation.Location = 1;
		error = GSM_GetFMStation(gsm,&FMStation);
		if (error == ERR_NONE || error == ERR_EMPTY) {
			if (answer_yes("%s", _("Restore phone FM radio stations?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		fprintf(stderr, "%s ", _("Deleting old FM stations:"));
		error=GSM_ClearFMStations(gsm);
		Print_Error(error);
		fprintf(stderr, "%s\n", _("Done"));
		max = 0;
		while (Backup.FMStation[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			FMStation = *Backup.FMStation[i];
			error=GSM_SetFMStation(gsm,&FMStation);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}
	DoRestore = FALSE;
	if (Backup.GPRSPoint[0] != NULL) {
		GPRSPoint.Location = 1;
		error = GSM_GetGPRSAccessPoint(gsm,&GPRSPoint);
		if (error == ERR_NONE || error == ERR_EMPTY) {
			if (answer_yes("%s", _("Restore phone GPRS Points?"))) DoRestore = TRUE;
		}
	}
	if (DoRestore) {
		max = 0;
		while (Backup.GPRSPoint[max]!=NULL) max++;
		for (i=0;i<max;i++) {
			error=GSM_SetGPRSAccessPoint(gsm,Backup.GPRSPoint[i]);
			Print_Error(error);
			fprintf(stderr, "\r");
			fprintf(stderr, "%s ", _("Writing:"));
			fprintf(stderr, _("%i percent"),
				(i + 1) * 100 / max);
			if (gshutdown) {
				GSM_Terminate();
				Terminate(4);
			}
		}
		fprintf(stderr, "\n");
	}

	GSM_FreeBackup(&Backup);
	GSM_Terminate();
}
Beispiel #5
0
void AddNew(int argc, char *argv[])
{
	GSM_Error error;
	GSM_Backup		Backup;
	GSM_DateTime 		date_time;
	GSM_MemoryEntry		Pbk;
	GSM_MemoryStatus	MemStatus;
	GSM_ToDoEntry		ToDo;
	GSM_ToDoStatus		ToDoStatus;
	GSM_NoteEntry		Note;
	GSM_CalendarEntry	Calendar;
	GSM_WAPBookmark		Bookmark;
	GSM_MemoryType		MemoryType = 0;
	int			i, max;

	error=GSM_ReadBackupFile(argv[2],&Backup,GSM_GuessBackupFormat(argv[2], FALSE));
	if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);

	if (Backup.DateTimeAvailable) {
		fprintf(stderr, LISTFORMAT "%s\n", _("Time of backup"),OSDateTime(Backup.DateTime,FALSE));
	}
	if (Backup.Model[0]!=0) {
		fprintf(stderr, LISTFORMAT "%s\n", _("Phone"),Backup.Model);
	}
	if (Backup.IMEI[0]!=0) {
		fprintf(stderr, LISTFORMAT "%s\n", _("IMEI"),Backup.IMEI);
	}

	for (i = 3; i < argc; i++) {
		if (strcasecmp(argv[i],"-yes") == 0) {
			always_answer_yes = TRUE;
		} else if (strcasecmp(argv[i],"-memory") == 0 && i + 1 < argc) {
			i++;
			MemoryType = GSM_StringToMemoryType(argv[i]);
			if (MemoryType == 0) {
				printf_err(_("Unknown memory type (\"%s\")\n"),argv[i]);
				Terminate(2);
			}
		} else {
			printf_err(_("Unknown parameter (\"%s\")\n"), argv[i]);
			Terminate(2);
		}
	}

	signal(SIGINT, interrupt);
	fprintf(stderr, "%s\n", _("Press Ctrl+C to break..."));


	GSM_Init(TRUE);

	if (Backup.PhonePhonebook[0] != NULL) {
		MemStatus.MemoryType = (MemoryType == 0 ? MEM_ME : MemoryType);
		error=GSM_GetMemoryStatus(gsm, &MemStatus);
		/* Some phones do not support status, try reading some entry */
		if (error != ERR_NONE) {
			Pbk.Location = 1;
			Pbk.MemoryType = MEM_ME;
			error = GSM_GetMemory(gsm, &Pbk);
			MemStatus.MemoryFree = 9999999;
		}
		if (error == ERR_NONE || error == ERR_EMPTY) {
			max = 0;
			while (Backup.PhonePhonebook[max] != NULL) {
				max++;
			}
			fprintf(stderr, _("%i entries in backup file\n"), max);
			if (MemStatus.MemoryFree < max) {
				fprintf(stderr, _("Memory has only %i free locations.Exiting\n"), MemStatus.MemoryFree);
			} else if (answer_yes("%s", _("Add phone phonebook entries?"))) {
				for (i = 0; i < max; i++) {
					Pbk 		= *Backup.PhonePhonebook[i];
					Pbk.MemoryType 	= (MemoryType == 0 ? MEM_ME : MemoryType);
					error=GSM_AddMemory(gsm, &Pbk);
					Print_Error(error);
					fprintf(stderr, "\r");
					fprintf(stderr, "%s ", _("Writing:"));
					fprintf(stderr, _("%i percent"),
						(i + 1) * 100 / max);
					if (gshutdown) {
						GSM_Terminate();
						Terminate(4);
					}
				}
				fprintf(stderr, "\n");
			}
		}
	}
	if (Backup.SIMPhonebook[0] != NULL) {
		MemStatus.MemoryType = (MemoryType == 0 ? MEM_SM : MemoryType);
		error=GSM_GetMemoryStatus(gsm, &MemStatus);
		if (error==ERR_NONE) {
			max = 0;
			while (Backup.SIMPhonebook[max]!=NULL) max++;
			fprintf(stderr, _("%i entries in backup file\n"),max);
			if (MemStatus.MemoryFree < max) {
				fprintf(stderr, _("Memory has only %i free locations.Exiting\n"),MemStatus.MemoryFree);
			} else if (answer_yes("%s", _("Add SIM phonebook entries?"))) {
				for (i=0;i<max;i++) {
					Pbk 		= *Backup.SIMPhonebook[i];
					Pbk.MemoryType 	= (MemoryType == 0 ? MEM_SM : MemoryType);
					error=GSM_AddMemory(gsm, &Pbk);
					Print_Error(error);
					fprintf(stderr, "\r");
					fprintf(stderr, "%s ", _("Writing:"));
					fprintf(stderr, _("%i percent"),
						(i + 1) * 100 / max);
					if (gshutdown) {
						GSM_Terminate();
						Terminate(4);
					}
				}
				fprintf(stderr, "\n");
			}
		}
	}

	if (GSM_GetConfig(gsm, -1)->SyncTime == FALSE) {
		if (answer_yes("%s", _("Do you want to set phone date/time? (NOTE: in some phones it's required to correctly restore calendar notes and other items)"))) {
			GSM_GetCurrentDateTime(&date_time);

			error=GSM_SetDateTime(gsm, &date_time);
			Print_Error(error);
		}
	}
	if (Backup.Calendar[0] != NULL) {
		Calendar.Location = 1;
		error = GSM_GetNextCalendar(gsm,&Calendar,TRUE);
		if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) {
			if (answer_yes("%s", _("Add phone calendar notes?"))) {
				max = 0;
				while (Backup.Calendar[max]!=NULL) max++;
				for (i=0;i<max;i++) {
					Calendar = *Backup.Calendar[i];
					error=GSM_AddCalendar(gsm,&Calendar);
					Print_Error(error);
					fprintf(stderr, "\r");
					fprintf(stderr, "%s ", _("Writing:"));
					fprintf(stderr, _("%i percent"),
						(i + 1) * 100 / max);
					if (gshutdown) {
						GSM_Terminate();
						Terminate(4);
					}
				}
				fprintf(stderr, "\n");
			}
		}
	}
	if (Backup.ToDo[0] != NULL) {
		ToDo.Location = 1;
		error=GSM_GetToDoStatus(gsm,&ToDoStatus);
		if (error == ERR_NONE) {
			if (answer_yes("%s", _("Add phone ToDo?"))) {
				max = 0;
				while (Backup.ToDo[max]!=NULL) max++;
				for (i=0;i<max;i++) {
					ToDo  = *Backup.ToDo[i];
					error = GSM_AddToDo(gsm,&ToDo);
					Print_Error(error);
					fprintf(stderr, "\r");
					fprintf(stderr, "%s ", _("Writing:"));
					fprintf(stderr, _("%i percent"),
						(i + 1) * 100 / max);
					if (gshutdown) {
						GSM_Terminate();
						Terminate(4);
					}
				}
				fprintf(stderr, "\n");
			}
		}
	}
	if (Backup.Note[0] != NULL) {
		Note.Location = 1;
		if (answer_yes("%s", _("Add notes to phone?"))) {
			max = 0;
			while (Backup.Note[max]!=NULL) max++;
			for (i=0;i<max;i++) {
				Note  = *Backup.Note[i];
				error = GSM_AddNote(gsm,&Note);
				Print_Error(error);
				fprintf(stderr, "\r");
				fprintf(stderr, "%s ", _("Writing:"));
				fprintf(stderr, _("%i percent"),
					(i + 1) * 100 / max);
				if (gshutdown) {
					GSM_Terminate();
					Terminate(4);
				}
			}
			fprintf(stderr, "\n");
		}
	}
	if (Backup.WAPBookmark[0] != NULL) {
		Bookmark.Location = 1;
		error = GSM_GetWAPBookmark(gsm,&Bookmark);
		if (error == ERR_NONE || error == ERR_INVALIDLOCATION) {
			if (answer_yes("%s", _("Add phone WAP bookmarks?"))) {
				max = 0;
				while (Backup.WAPBookmark[max]!=NULL) max++;
				for (i=0;i<max;i++) {
					Bookmark 	  = *Backup.WAPBookmark[i];
					Bookmark.Location = 0;
					error=GSM_SetWAPBookmark(gsm,&Bookmark);
					Print_Error(error);
					fprintf(stderr, "\r");
					fprintf(stderr, "%s ", _("Writing:"));
					fprintf(stderr, _("%i percent"),
						(i + 1) * 100 / max);
					if (gshutdown) {
						GSM_Terminate();
						Terminate(4);
					}
				}
				fprintf(stderr, "\n");
			}
		}
	}

	GSM_FreeBackup(&Backup);
	GSM_Terminate();
}
Beispiel #6
0
THREAD_RETURN SearchPhoneThread(void * arg)
{
	int j;
	OneDeviceInfo *Info = arg;
	GSM_Error error;
	GSM_StateMachine *search_gsm;
	GSM_Config *smcfg;
	GSM_Config *globalcfg;

	/* Iterate over all connections */
	for (j = 0; strlen(Info->Connections[j].Connection) != 0; j++) {

		/* Allocate state machine */
		search_gsm = GSM_AllocStateMachine();
		if (search_gsm == NULL)
			return THREAD_RETURN_VAL;

		/* Get configuration pointers */
		smcfg = GSM_GetConfig(search_gsm, 0);
		globalcfg = GSM_GetConfig(gsm, 0);

		/* We share some configuration with global one */
		smcfg->UseGlobalDebugFile = globalcfg->UseGlobalDebugFile;
		smcfg->DebugFile = strdup(globalcfg->DebugFile);
		strcpy(smcfg->DebugLevel, globalcfg->DebugLevel);

		/* Configure the tested state machine */
		smcfg->Device = strdup(Info->Device);
		smcfg->Connection = strdup(Info->Connections[j].Connection);
		smcfg->SyncTime = FALSE;
		smcfg->Model[0] = 0;
		smcfg->LockDevice = FALSE;
		smcfg->StartInfo = FALSE;

		/* We have only one configured connection */
		GSM_SetConfigNum(search_gsm, 1);

		/* Let's connect */
		error = GSM_InitConnection(search_gsm, 1);

		printf(_("Connection \"%s\" on device \"%s\"\n"),
		       Info->Connections[j].Connection, Info->Device);

		/* Did we succeed? Show info */
		if (error == ERR_NONE) {
			SearchPrintPhoneInfo(search_gsm);
		} else {
			SearchPrintf("\t%s\n", GSM_ErrorString(error));
		}

		if (error != ERR_DEVICEOPENERROR) {
			GSM_TerminateConnection(search_gsm);
		}

		if (error == ERR_DEVICEOPENERROR)
			break;

		/* Free allocated buffer */
		GSM_FreeStateMachine(search_gsm);
	}
	return THREAD_RETURN_VAL;
}