Beispiel #1
0
GSM_Error DUMMY_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, int *Size)
{
	char *path, *name, *pos;
	GSM_Error error;

	*Handle = 0;

	path = DUMMY_GetFSFilePath(s, File->ID_FullName);

	error = GSM_ReadFile(path, File);
	*Size = File->Used;

	name = strrchr(path, '/');
	if (name == NULL) name = path;
	else name++;
	EncodeUnicode(File->Name, name, strlen(name));
	pos = path;
	while (*pos != 0 && (pos = strchr(pos + 1, '/')) != NULL) File->Level++;

	free(path);
	path=NULL;

	if (error == ERR_NONE) return ERR_EMPTY;
	return error;
}
Beispiel #2
0
GSM_Error DUMMY_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
{
	switch (bookmark->Location) {
		case 1:
			EncodeUnicode(bookmark->Address, "http://blog.cihar.com/", 22);
			EncodeUnicode(bookmark->Title, "Michals weblog", 14);
			return ERR_NONE;
		case 2:
			EncodeUnicode(bookmark->Address, "http://wammu.eu/", 16);
			EncodeUnicode(bookmark->Title, "Wammu website", 13);
			return ERR_NONE;
		default:
			return ERR_EMPTY;

	}
}
Beispiel #3
0
static gboolean ReadLDIFText(const char *Buffer, const char *Start, char *Value)
{
	unsigned char 	Buffer2[1000],buff[200];
	int 		i;

	Value[0] = 0x00;

	strcpy(buff,Start);
	strcat(buff,":: ");
	if (!strncmp(Buffer,buff,strlen(buff))) {
		i = DecodeBASE64(Buffer+strlen(Start)+3, Buffer2, strlen(Buffer)-(strlen(Start)+3));
		dbgprintf(NULL, "Text after DecodeBASE64 is \"%s\"\n",Buffer2);
		DecodeUTF8(Value, Buffer2, i);
		dbgprintf(NULL, "Text after DecodeUTF8 is \"%s\"\n",DecodeUnicodeString(Value));
		return TRUE;
	}
	strcpy(buff,Start);
	strcat(buff,": ");
	if (!strncmp(Buffer,buff,strlen(buff))) {
		EncodeUnicode(Value,Buffer+strlen(Start)+2,strlen(Buffer)-(strlen(Start)+2));
		dbgprintf(NULL, "Text after EncodeUnicode is \"%s\"\n",DecodeUnicodeString(Value));
		return TRUE;
	}
	return FALSE;
}
Beispiel #4
0
GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap)
{
	FILE		*file;
	unsigned char	buffer[300];
	GSM_Error	error = ERR_FILENOTSUPPORTED;
	char	*file_only_name;
	size_t len;

	file = fopen(FileName, "rb");
	if (file == NULL) return ERR_CANTOPENFILE;

	file_only_name = strrchr(FileName, '/');
	if (file_only_name == NULL) {
		file_only_name = strrchr(FileName, '\\');
	} else {
		file_only_name++;
	}
	if (file_only_name == NULL) {
		file_only_name = FileName;
	} else {
		file_only_name++;
	}
	len = strlen(file_only_name);
	if (len > GSM_BITMAP_TEXT_LENGTH) {
		fclose(file);
		return ERR_MOREMEMORY;
	}

	EncodeUnicode(bitmap->Bitmap[0].Name, file_only_name, len);

	/* Read the header of the file. */
	if (fread(buffer, 1, 9, file) != 9) {
		fclose(file);
		return ERR_FILENOTSUPPORTED;
	}
	rewind(file);

	bitmap->Bitmap[0].DefaultBitmap = FALSE;

	/* Attempt to identify filetype */
	if (memcmp(buffer, "BM",2)==0) {
		error = loadbmp(file,bitmap);
	} else if (buffer[0] == 0x00 && buffer[1] == 0x00) {
		error = loadwbmp(file,bitmap);
	} else if (memcmp(buffer, "NLM",3)==0) {
		error = loadnlm(file,bitmap);
	} else if (memcmp(buffer, "NOL",3)==0) {
		error = loadnolngg(file,bitmap,TRUE);
	} else if (memcmp(buffer, "NGG",3)==0) {
		error = loadnolngg(file,bitmap,FALSE);
	} else if (memcmp(buffer, "FORM",4)==0) {
		error = loadnsl(file,bitmap);
	} else if (memcmp(buffer, "GIF",3)==0) {
		error = loadgif(file,bitmap);
	}
	fclose(file);
	return error;
}
Beispiel #5
0
GSM_Error DUMMY_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
{
	strcpy(netinfo->CID, "FACE");
	strcpy(netinfo->PacketCID, "DEAD");
	strcpy(netinfo->NetworkCode, "999 99");
	netinfo->State = GSM_HomeNetwork;
	strcpy(netinfo->LAC, "B00B");
	strcpy(netinfo->PacketLAC, "BEEF");
	netinfo->PacketState = GSM_HomeNetwork;
	EncodeUnicode(netinfo->NetworkName, "GammuT3l", 8);
	netinfo->GPRS = GSM_GPRS_Attached;

	return ERR_NONE;
}
Beispiel #6
0
GSM_Error DUMMY_DialService(GSM_StateMachine *s, char *number)
{
	GSM_Phone_DUMMYData	*Priv = &s->Phone.Data.Priv.DUMMY;
	GSM_USSDMessage ussd;
	char ussd_text[GSM_MAX_USSD_LENGTH + 1];
	size_t len;


	fprintf(Priv->log_file, "Dialling service %s\n", number);

	if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD != NULL) {
		ussd.Status = USSD_NoActionNeeded;
		len = snprintf(ussd_text, GSM_MAX_USSD_LENGTH, "Reply for %s", number);
		EncodeUnicode(ussd.Text, ussd_text, len);

		/* Notify application */
		s->User.IncomingUSSD(s, &ussd, s->User.IncomingUSSDUserData);
	}

	return ERR_NONE;
}
Beispiel #7
0
GSM_Error DUMMY_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
{
	PHONE_GetSMSFolders(s,folders);
	folders->Number = 5;

	CopyUnicodeString(folders->Folder[2].Name,folders->Folder[0].Name);
	folders->Folder[2].InboxFolder = folders->Folder[0].InboxFolder;
	folders->Folder[2].OutboxFolder = folders->Folder[0].OutboxFolder;
	folders->Folder[2].Memory = MEM_ME;

	CopyUnicodeString(folders->Folder[3].Name,folders->Folder[1].Name);
	folders->Folder[3].InboxFolder = folders->Folder[1].InboxFolder;
	folders->Folder[3].OutboxFolder = folders->Folder[1].OutboxFolder;
	folders->Folder[3].Memory = MEM_ME;

	EncodeUnicode(folders->Folder[4].Name,_("Templates"),strlen(_("Templates")));
	folders->Folder[4].InboxFolder = FALSE;
	folders->Folder[4].OutboxFolder = FALSE;
	folders->Folder[4].Memory = MEM_ME;
	return ERR_NONE;
}
Beispiel #8
0
void DCT4MakeCameraShoot(int argc, char *argv[])
{
	unsigned char SetCamera[] = {N6110_FRAME_HEADER, 0x09, 0x01, 0x02};
	unsigned char CameraON[] = {N6110_FRAME_HEADER, 0x02, 0x01, 0x00, 0x00, 0x00 , 0x00, 0x00};
	unsigned char CameraON2[] = {N6110_FRAME_HEADER, 0xF0, 0x02, 0x00};
	unsigned char MakeShot[200] = {N6110_FRAME_HEADER, 0x06, 0x01, 0x06,
		0x01, 0x00, 0x00, 0x02, 0x00, 0x04, 0x32, 0x00, 0x01,
		0x1D, 		//length of rest
		0x00, 0x00, 0x00, 0x01,
		0x00, 0x02,	//master folder id
		0x00, 0x14}; 	//length
	unsigned char CameraOFF[] = {N6110_FRAME_HEADER, 0x04, 0x01, 0x00};
	GSM_Error error;

	GSM_Init(TRUE);

        CheckDCT4();

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	error=GSM_WaitFor (gsm, SetCamera, 6, 0x61, 4, ID_User3);
	Print_Error(error);
	error=GSM_WaitFor (gsm, CameraON, 10, 0x61, 4, ID_User3);
	Print_Error(error);
	error=GSM_WaitFor (gsm, CameraON2, 6, 0x61, 4, ID_User3);
	Print_Error(error);
	EncodeUnicode(MakeShot+24,"GammuShot",9);
	MakeShot[15] = 9+9*2;
	MakeShot[23] = 9*2;
	error=GSM_WaitFor (gsm, MakeShot, 24+MakeShot[23], 0x61, 4, ID_User3);
	Print_Error(error);
	error=GSM_WaitFor (gsm, SetCamera, 6, 0x61, 4, ID_User3);
	Print_Error(error);
	error=GSM_WaitFor (gsm, CameraOFF, 6, 0x61, 4, ID_User3);
	Print_Error(error);

	GSM_Terminate();
}
Beispiel #9
0
/* Find one multi SMS to sending and return it (or return ERR_EMPTY)
 * There is also set ID for SMS
 * File extension convention:
 * OUTxxxxx.txt : normal text SMS
 * Options appended to the extension applying to this SMS only:
 * d: delivery report requested
 * f: flash SMS
 * b: WAP bookmark as name,URL
 * e.g. OUTG20040620_193810_123_+4512345678_xpq.txtdf
 * is a flash text SMS requesting delivery reports
 */
static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage * sms, GSM_SMSDConfig * Config, char *ID)
{
	GSM_MultiPartSMSInfo SMSInfo;
	GSM_WAPBookmark Bookmark;
	char FileName[100], FullName[400];
	unsigned char Buffer[(GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS + 1) * 2];
	unsigned char Buffer2[(GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS + 1) * 2];
	FILE *File;
	int i, len, phlen;
	char *pos1, *pos2, *options = NULL;
	gboolean backup = FALSE;
#ifdef GSM_ENABLE_BACKUP
	GSM_SMS_Backup smsbackup;
	GSM_Error error;
#endif
#ifdef WIN32
	struct _finddata_t c_file;
	intptr_t hFile;

	strcpy(FullName, Config->outboxpath);
	strcat(FullName, "OUT*.txt*");
	hFile = _findfirst(FullName, &c_file);
	if (hFile == -1) {
		strcpy(FullName, Config->outboxpath);
		strcat(FullName, "OUT*.smsbackup*");
		hFile = _findfirst(FullName, &c_file);
		backup = TRUE;
	}
	if (hFile == -1) {
		return ERR_EMPTY;
	} else {
		strcpy(FileName, c_file.name);
	}
	_findclose(hFile);
#elif defined(HAVE_DIRBROWSING)
	struct dirent **namelist = NULL;
	int cur_file, num_files;
	char *pos;

	strcpy(FullName, Config->outboxpath);

	FullName[strlen(Config->outboxpath) - 1] = '\0';

	num_files = scandir(FullName, &namelist, 0, alphasort);

	for (cur_file = 0; cur_file < num_files; cur_file++) {
		/* Hidden file or current/parent directory */
		if (namelist[cur_file]->d_name[0] == '.') {
			continue;
		}
		/* We care only about files starting with out */
		if (strncasecmp(namelist[cur_file]->d_name, "out", 3) != 0) {
			continue;
		}
		/* Check extension */
		pos = strrchr(namelist[cur_file]->d_name, '.');
		if (pos == NULL) {
			continue;
		}
		if (strncasecmp(pos, ".txt", 4) == 0) {
			/* We have found text file */
			backup = FALSE;
			break;
		}
		if (strncasecmp(pos, ".smsbackup", 10) == 0) {
			/* We have found a SMS backup file */
			backup = TRUE;
			break;
		}
	}
	/* Remember file name */
	if (cur_file < num_files) {
		strcpy(FileName, namelist[cur_file]->d_name);
	}
	/* Free scandir result */
	for (i = 0; i < num_files; i++) {
		free(namelist[i]);
	}
	free(namelist);
	namelist = NULL;
	/* Did we actually find something? */
	if (cur_file >= num_files) {
		return ERR_EMPTY;
	}
#else
	return ERR_NOTSUPPORTED;
#endif
	strcpy(FullName, Config->outboxpath);
	strcat(FullName, FileName);

	if (backup) {
#ifdef GSM_ENABLE_BACKUP
		/* Remember ID */
		strcpy(ID, FileName);
		/* Load backup */
		GSM_ClearSMSBackup(&smsbackup);
		error = GSM_ReadSMSBackupFile(FullName, &smsbackup);
		if (error != ERR_NONE) {
			return error;
		}
		/* Copy it to our message */
		sms->Number = 0;
		for (i = 0; smsbackup.SMS[i] != NULL; i++) {
			sms->SMS[sms->Number++] = *smsbackup.SMS[i];
		}
		/* Free memory */
		GSM_FreeSMSBackup(&smsbackup);

		/* Set delivery report flag */
		if (sms->SMS[0].PDU == SMS_Status_Report) {
			Config->currdeliveryreport = 1;
		} else {
			Config->currdeliveryreport = -1;
		}

#else
		SMSD_Log(DEBUG_ERROR, Config, "SMS backup loading disabled at compile time!");
		return ERR_DISABLED;

#endif
	} else {
		options = strrchr(FileName, '.') + 4;

		File = fopen(FullName, "rb");
		if (File == NULL) {
			return ERR_CANTOPENFILE;
		}
		len = fread(Buffer, 1, sizeof(Buffer) - 2, File);
		fclose(File);

		if ((len < 2) || (len >= 2 && ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) && (Buffer[0] != 0xFE || Buffer[1] != 0xFF)))) {
			if (len > GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS)
				len = GSM_MAX_SMS_LENGTH * GSM_MAX_MULTI_SMS;
			EncodeUnicode(Buffer2, Buffer, len);
			len = len * 2;
			memmove(Buffer, Buffer2, len);
			Buffer[len] = 0;
			Buffer[len + 1] = 0;
		} else {
			Buffer[len] = 0;
			Buffer[len + 1] = 0;
			/* Possibly convert byte order */
			ReadUnicodeFile(Buffer2, Buffer);
		}

		GSM_ClearMultiPartSMSInfo(&SMSInfo);
		sms->Number = 0;

		SMSInfo.ReplaceMessage = 0;
		SMSInfo.Entries[0].Buffer = Buffer2;
		SMSInfo.Class = -1;
		SMSInfo.EntriesNum = 1;
		Config->currdeliveryreport = -1;
		if (strchr(options, 'd'))
			Config->currdeliveryreport = 1;
		if (strchr(options, 'f'))
			SMSInfo.Class = 0;	/* flash SMS */

		if (strcasecmp(Config->transmitformat, "unicode") == 0) {
			SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
			SMSInfo.UnicodeCoding = TRUE;
		} else if (strcasecmp(Config->transmitformat, "7bit") == 0) {
			SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
			SMSInfo.UnicodeCoding = FALSE;
		} else {
			/* auto */
			SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong;
		}

		if (strchr(options, 'b')) {	// WAP bookmark as title,URL
			SMSInfo.Entries[0].Buffer = NULL;
			SMSInfo.Entries[0].Bookmark = &Bookmark;
			SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong;
			SMSInfo.Entries[0].Bookmark->Location = 0;
			pos2 = mywstrstr(Buffer2, "\0,");
			if (pos2 == NULL) {
				pos2 = Buffer2;
			} else {
				*pos2 = '\0';
				pos2++;
				*pos2 = '\0';
				pos2++;	// replace comma by zero
			}

			len = UnicodeLength(Buffer2);
			if (len > 50) {
				len = 50;
			}
			memmove(&SMSInfo.Entries[0].Bookmark->Title, Buffer2, len * 2);
			pos1 = &SMSInfo.Entries[0].Bookmark->Title[0] + len * 2;
			*pos1 = '\0';
			pos1++;
			*pos1 = '\0';

			len = UnicodeLength(pos2);
			if (len > 255) {
				len = 255;
			}
			memmove(&SMSInfo.Entries[0].Bookmark->Address, pos2, len * 2);
			pos1 = &SMSInfo.Entries[0].Bookmark->Address[0] + len * 2;
			*pos1 = '\0';
			pos1++;
			*pos1 = '\0';
		}

		GSM_EncodeMultiPartSMS(GSM_GetDebug(Config->gsm), &SMSInfo, sms);

		strcpy(ID, FileName);
		pos1 = FileName;
		for (i = 1; i <= 3 && pos1 != NULL; i++) {
			pos1 = strchr(++pos1, '_');
		}
		if (pos1 != NULL) {
			/* OUT<priority><date>_<time>_<serialno>_<phone number>_<anything>.txt */
			pos2 = strchr(++pos1, '_');
			if (pos2 != NULL) {
				phlen = strlen(pos1) - strlen(pos2);
			} else {
				/* something wrong */
				return ERR_UNKNOWN;
			}
		} else if (i == 2) {
			/* OUTxxxxxxx.txt or OUTxxxxxxx */
			pos1 = &FileName[3];
			pos2 = strchr(pos1, '.');
			if (pos2 == NULL) {
				phlen = strlen(pos1);
			} else {
				phlen = strlen(pos1) - strlen(pos2);
			}
		} else if (i == 4) {
			/* OUT<priority>_<phone number>_<serialno>.txt */
			pos1 = strchr(FileName, '_');
			pos2 = strchr(++pos1, '_');
			phlen = strlen(pos1) - strlen(pos2);
		} else {
			/* something wrong */
			return ERR_UNKNOWN;
		}

		for (len = 0; len < sms->Number; len++) {
			EncodeUnicode(sms->SMS[len].Number, pos1, phlen);
		}
	}

	if (sms->Number != 0) {
		DecodeUnicode(sms->SMS[0].Number, Buffer);
		if (options != NULL && strchr(options, 'b')) {	// WAP bookmark as title,URL
			SMSD_Log(DEBUG_NOTICE, Config, "Found %i sms to \"%s\" with bookmark \"%s\" cod %i lgt %i udh: t %i l %i dlr: %i fls: %i",
				 sms->Number,
				 Buffer,
				 DecodeUnicodeString(SMSInfo.Entries[0].Bookmark->Address),
				 sms->SMS[0].Coding, sms->SMS[0].Length, sms->SMS[0].UDH.Type, sms->SMS[0].UDH.Length, Config->currdeliveryreport, SMSInfo.Class);
		} else {
			SMSD_Log(DEBUG_NOTICE, Config, "Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i dlr: %i fls: %i",
				 sms->Number,
				 Buffer,
				 DecodeUnicodeString(sms->SMS[0].Text),
				 sms->SMS[0].Coding, sms->SMS[0].Length, sms->SMS[0].UDH.Type, sms->SMS[0].UDH.Length, Config->currdeliveryreport, sms->SMS[0].Class);
		}
	} else {
		SMSD_Log(DEBUG_NOTICE, Config, "error: SMS-count = 0");
	}

	return ERR_NONE;
}
Beispiel #10
0
void NokiaAddPlayLists2(unsigned char *ID,unsigned char *Name,unsigned char *IDFolder)
{
	GSM_Error error;
	gboolean 			Start = TRUE, Available = FALSE;
	GSM_File	 	Files,Files2,Files3;
	int 			j,NamesPos2=0;
	size_t i, NamesPos = 0;
	unsigned char		Buffer[20],Buffer2[500];
	unsigned char		*Names,*Names2,*Pointer;
	PlayListEntry		*First,*Entry=NULL,*Prev;

	First = NULL; Names=NULL; Names2=NULL;

	CopyUnicodeString(Files.ID_FullName,ID);

	printf(_("Checking %s\n"),DecodeUnicodeString(Name));
	/* looking into folder content (searching for mp3 and similiar) */
	while (1) {
		error = GSM_GetFolderListing(gsm,&Files,Start);
		if (error == ERR_FOLDERPART) {
			printf("%s\n", _("  Only part handled!"));
			break;
		}
		if (error == ERR_EMPTY) break;
		if (error == ERR_FILENOTEXIST) return;
	    	Print_Error(error);

		if (!Files.Folder) {
			if (strcasestr(DecodeUnicodeConsole(Files.Name),".mp3")!=NULL ||
			    strcasestr(DecodeUnicodeConsole(Files.Name),".aac")!=NULL) {
				if (First==NULL) {
					First = malloc(sizeof(PlayListEntry));
					Entry = First;
				} else {
					Entry->Next = malloc(sizeof(PlayListEntry));
					Entry = Entry->Next;
				}
				Entry->Next = NULL;
				Entry->Name = malloc(strlen(DecodeUnicodeString(Files.ID_FullName))+1);
				sprintf(Entry->Name,"%s",DecodeUnicodeString(Files.ID_FullName));
				/* converting Gammu drives to phone drives */
				if (Entry->Name[0]=='a' || Entry->Name[0]=='A') {
					Entry->Name[0]='b';
				} else if (Entry->Name[0]=='d' || Entry->Name[0]=='D') {
					Entry->Name[0]='a';
				}

				Entry->NameUP = malloc(strlen(DecodeUnicodeString(Files.ID_FullName))+1);
				for (i = 0; i < strlen(DecodeUnicodeString(Files.ID_FullName)) + 1; i++) {
					Entry->NameUP[i] = tolower(Entry->Name[i]);
				}
			}
		} else {
			Names = (unsigned char *)realloc(Names,NamesPos+UnicodeLength(Files.ID_FullName)*2+2);
			CopyUnicodeString(Names+NamesPos,Files.ID_FullName);
			NamesPos+=UnicodeLength(Files.ID_FullName)*2+2;

			Names2 = (unsigned char *)realloc(Names2,NamesPos2+UnicodeLength(Files.Name)*2+2);
			CopyUnicodeString(Names2+NamesPos2,Files.Name);
			NamesPos2+=UnicodeLength(Files.Name)*2+2;
		}

		Start = FALSE;
	}
	if (First!=NULL) {
		/* sorting songs names */
		Entry=First;
		while (Entry->Next!=NULL) {
			if (strcmp(Entry->NameUP,Entry->Next->NameUP)>0) {
				Pointer=Entry->Next->Name;
				Entry->Next->Name = Entry->Name;
				Entry->Name = Pointer;

				Pointer=Entry->Next->NameUP;
				Entry->Next->NameUP = Entry->NameUP;
				Entry->NameUP = Pointer;

				Entry=First;
				continue;
			}
			Entry=Entry->Next;
		}
		/* we checking, if file already exist.if yes, we look for another... */
		i 		= 0;
		Files3.Buffer 	= NULL;
		while (1) {
			CopyUnicodeString(Files3.ID_FullName,IDFolder);
	        	CopyUnicodeString(Buffer2,Name);
			if (i!=0) {
				sprintf(Buffer, "%ld", (long)i);
		        	EncodeUnicode(Buffer2+UnicodeLength(Buffer2)*2,Buffer,strlen(Buffer));
			}
	        	EncodeUnicode(Buffer2+UnicodeLength(Buffer2)*2,".m3u",4);

			Start = TRUE;
			Available = FALSE;
			while (1) {
				error = GSM_GetFolderListing(gsm,&Files3,Start);
				if (error == ERR_FOLDERPART) {
					printf("%s\n", _("  Problem with adding playlist"));
					break;
				}
				if (error == ERR_EMPTY) break;
			    	Print_Error(error);

				if (!Files3.Folder) {
					if (mywstrncasecmp(Buffer2,Files3.Name,-1)) {
						Available = TRUE;
						break;
					}
				}
				Start = FALSE;
			}
			if (!Available) break;
			i++;
		}

		/* preparing new playlist file date */
		Files2.System	 = FALSE;
		Files2.Folder 	 = FALSE;
		Files2.ReadOnly	 = FALSE;
		Files2.Hidden	 = FALSE;
		Files2.Protected = FALSE;
		Files2.ModifiedEmpty = FALSE;
		GSM_GetCurrentDateTime (&Files2.Modified);
		CopyUnicodeString(Files2.ID_FullName,IDFolder);
	        CopyUnicodeString(Files2.Name,Buffer2);

		/* preparing new playlist file content */
		Files2.Buffer=NULL;
		Files2.Buffer = (unsigned char *)realloc(Files2.Buffer,10);
		sprintf(Files2.Buffer,"#EXTM3U%c%c",13,10);
		Files2.Used = 9;
		Entry=First;
		while (Entry!=NULL) {
			Files2.Buffer = (unsigned char *)realloc(Files2.Buffer,Files2.Used+strlen(Entry->Name)+2+1);
			sprintf(Files2.Buffer+Files2.Used,"%s%c%c",Entry->Name,13,10);
			Files2.Used+=strlen(Entry->Name)+2;
			Entry=Entry->Next;
		}
		Files2.Used	 -= 2;
		for (i=0;i<Files2.Used;i++) {
			if (Files2.Buffer[i]=='/') Files2.Buffer[i]='\\';
		}

		/* adding new playlist file */
		sprintf(Buffer2, _("Writing file %s:"), DecodeUnicodeString(Files2.Name));
		AddOneFile(&Files2, Buffer2, FALSE);

		/* cleaning buffers */
		free(Files2.Buffer);
		Files2.Buffer=NULL;
		while (Entry!=NULL) {
			Entry=First;
			Prev=NULL;
			while (Entry->Next!=NULL) {
				Prev=Entry;
				Entry=Entry->Next;
			}
			free(Entry->Name);
			free(Entry->NameUP);
			free(Entry);
			Entry=NULL;
			if (Prev!=NULL) Prev->Next = NULL;
		}
	}

	/* going into subfolders */
	if (NamesPos != 0) {
		i = 0; j = 0;
		while (i != NamesPos) {
			NokiaAddPlayLists2(Names+i,Names2+j,IDFolder);
			i+=UnicodeLength(Names+i)*2+2;
			j+=UnicodeLength(Names2+j)*2+2;
		}
	}
	free(Names);
	free(Names2);
}
Beispiel #11
0
/**
 * Initialises dummy module.
 */
GSM_Error DUMMY_Initialise(GSM_StateMachine *s)
{
	GSM_Phone_DUMMYData	*Priv = &s->Phone.Data.Priv.DUMMY;
	char *log_file, *path;
	const char * const paths[] = {
		"fs",
		"fs/incoming",
		"sms",
		"sms/1",
		"sms/2",
		"sms/3",
		"sms/4",
		"sms/5",
		"pbk",
		"pbk/ME",
		"pbk/SM",
		"pbk/MC",
		"pbk/RC",
		"pbk/DC",
		"note",
		"todo",
		"calendar",
		"alarm",
	};
	size_t i;

	Priv->devlen = strlen(s->CurrentConfig->Device);

	log_file = DUMMY_GetFilePath(s, "operations.log");

	smprintf(s, "Log file %s\n", log_file);

	/* Create some directories we might need */
	for (i = 0; i < sizeof(paths) / sizeof(char *); i++) {
		path = DUMMY_GetFilePath(s, paths[i]);
		if (MKDIR(path) != 0 && errno != EEXIST) {
			smprintf(s, "Failed to create directory: %s\n", path);
			free(path);
			free(log_file);
			return ERR_DEVICENOPERMISSION;
		}
		free(path);
	}

	for (i = 0; i <= DUMMY_MAX_FS_DEPTH; i++) {
		Priv->dir[i] = NULL;
	}
	Priv->fs_depth = 0;
	Priv->log_file = fopen(log_file, "w");
	free(log_file);
	log_file=NULL;

	if (Priv->log_file == NULL) {
		i = errno;
		GSM_OSErrorInfo(s, "Failed to open log");
		if (i == ENOENT) return ERR_DEVICENOTEXIST;		/* no such file or directory */
		if (i == EACCES) return ERR_DEVICENOPERMISSION;	/* permission denied */
		return ERR_DEVICEOPENERROR;
	}

	strcpy(s->Phone.Data.IMEI, "999999999999999");
	strcpy(s->Phone.Data.Manufacturer, "Gammu");
	strcpy(s->Phone.Data.Model, "Dummy");
	strcpy(s->Phone.Data.Version, GAMMU_VERSION);
	strcpy(s->Phone.Data.VerDate, "20150101");

	EncodeUnicode(Priv->SMSC.Number, "123456", 6);
	EncodeUnicode(Priv->SMSC.Name, "Default", 7);
	Priv->SMSC.Validity.Format = SMS_Validity_NotAvailable;
	Priv->SMSC.Validity.Relative = SMS_VALID_Max_Time;
	Priv->SMSC.DefaultNumber[0] = 0;
	Priv->SMSC.DefaultNumber[1] = 0;
	Priv->SMSC.Format = SMS_FORMAT_Text;
	Priv->SMSC.Location = 1;

	s->Phone.Data.VerNum = GAMMU_VERSION_NUM;

	Priv->locale.AMPMTime = FALSE;
	Priv->locale.DateFormat = GSM_Date_DDMMYYYY;
	Priv->locale.DateSeparator = '.';

	Priv->diverts.EntriesNum = 5;

	Priv->diverts.Entries[0].DivertType = GSM_DIVERT_Busy;
	Priv->diverts.Entries[0].CallType = GSM_DIVERT_VoiceCalls;
	Priv->diverts.Entries[0].Timeout = 10;
	EncodeUnicode(Priv->diverts.Entries[0].Number, "", 0);

	Priv->diverts.Entries[1].DivertType = GSM_DIVERT_NoAnswer;
	Priv->diverts.Entries[1].CallType = GSM_DIVERT_FaxCalls;
	Priv->diverts.Entries[1].Timeout = 20;
	EncodeUnicode(Priv->diverts.Entries[1].Number, "123", 3);

	Priv->diverts.Entries[2].DivertType = GSM_DIVERT_OutOfReach;
	Priv->diverts.Entries[2].CallType = GSM_DIVERT_DataCalls;
	Priv->diverts.Entries[2].Timeout = 30;
	EncodeUnicode(Priv->diverts.Entries[2].Number, "123", 3);

	Priv->diverts.Entries[3].DivertType = GSM_DIVERT_NoAnswer;
	Priv->diverts.Entries[3].CallType = GSM_DIVERT_VoiceCalls;
	Priv->diverts.Entries[3].Timeout = 40;
	EncodeUnicode(Priv->diverts.Entries[3].Number, "123", 3);

	Priv->diverts.Entries[4].DivertType = GSM_DIVERT_AllTypes;
	Priv->diverts.Entries[4].CallType = GSM_DIVERT_AllCalls;
	Priv->diverts.Entries[4].Timeout = 0;
	EncodeUnicode(Priv->diverts.Entries[4].Number, "", 0);

	return ERR_NONE;
}
Beispiel #12
0
GSM_Error DUMMY_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean start)
{
	GSM_Phone_DUMMYData	*Priv = &s->Phone.Data.Priv.DUMMY;
	char *path;
	struct dirent *dp;
	struct stat sb;
	int i;

	if (start) {
		for (i = 0; i < DUMMY_MAX_FS_DEPTH; i++) {
			if (Priv->dir[i] != NULL) {
				closedir(Priv->dir[i]);
				Priv->dir[i] = NULL;
			}
		}
		path = DUMMY_GetFilePath(s, "fs");
		strcpy(Priv->dirnames[0], path);
		Priv->dir[0] = opendir(path);
		free(path);
		path=NULL;

		if (Priv->dir[0] == NULL) {
			return DUMMY_Error(s, "opendir failed");
		}
		Priv->fs_depth = 0;
	}

read_next_entry:
	dp = readdir(Priv->dir[Priv->fs_depth]);

	if (dp == NULL) {
		closedir(Priv->dir[Priv->fs_depth]);
		Priv->dir[Priv->fs_depth] = NULL;
		if (Priv->fs_depth == 0) return ERR_EMPTY;
		Priv->fs_depth--;
		goto read_next_entry;
	}

	if (strcmp(dp->d_name, "..") == 0 || strcmp(dp->d_name, ".") == 0)
		goto read_next_entry;

	/* Stat file */
	path = DUMMY_GetFSPath(s, dp->d_name, Priv->fs_depth);
	if (stat(path, &sb) < 0) {
		free(path);
		path=NULL;
		return DUMMY_Error(s, "stat failed");
	}

	/* Fill file structure */
	File->Used = 0;
	EncodeUnicode(File->Name, dp->d_name, strlen(dp->d_name));
	File->Folder = FALSE;
	File->Level = Priv->fs_depth + 1;
	File->Type = GSM_File_Other; /* @todo TODO we should somehow detect this? */
	/* We need to skip device prefix and /fs/ prefix */
	EncodeUnicode(File->ID_FullName, path + Priv->devlen + 4, strlen(path + Priv->devlen + 4));
	File->Buffer = NULL;
	Fill_GSM_DateTime(&(File->Modified), sb.st_mtime);
	File->ModifiedEmpty = FALSE;
	File->Protected = FALSE;
	File->Hidden = FALSE;
	File->System = FALSE;
	File->ReadOnly = FALSE; /* @todo TODO get this from permissions? */

	/* Open nested directory for next loop if needed */
	if (S_ISDIR(sb.st_mode)) {
		File->Folder = TRUE;
		if (Priv->fs_depth == DUMMY_MAX_FS_DEPTH - 1) {
			smprintf(s, "We hit DUMMY_MAX_FS_DEPTH limit!\n");
			free(path);
			path=NULL;
			return ERR_MOREMEMORY;
		}
		Priv->fs_depth++;
		Priv->dir[Priv->fs_depth] = opendir(path);
		if (Priv->dir[Priv->fs_depth] == NULL) {
			free(path);
			path=NULL;
			return DUMMY_Error(s, "nested opendir failed");
		}
		strcpy(Priv->dirnames[Priv->fs_depth], path);
	}
	free(path);
	path=NULL;
	return ERR_NONE;
}
Beispiel #13
0
GSM_Error DUMMY_SendFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos, int *Handle)
{
	EncodeUnicode(File->ID_FullName, "incoming/", 9);
	return DUMMY_AddFilePart(s, File, Pos, Handle);
}
Beispiel #14
0
static void cgi_process_each(GSM_StateMachine *s, GSM_SMSMessage*sms) {
	int child_in[2];
	int child_out[2];
	int pid;
	int ret;
	int offset;
	int status;

	child_in[0] = child_in[1] = child_out[0] = child_out[1] = -1; /* invalid fd */

	DecodeUnicode(sms->Text, buffer);
	smprintf(s, CGI_ENGINE "<< [%s]\n", buffer);

	/* ----------------------------------------------------- now open the pipes */
	if (pipe(child_in)) {
		smprintf(s, CGI_ENGINE "Unable to open to pipe: %s\n", strerror(errno));
		goto error;
	}
	if (pipe(child_out)) {
		smprintf(s, CGI_ENGINE "Unable to open from pipe: %s\n", strerror(errno));
		goto error;
	}

	/* ------------------------- Block SIGHUP during the fork - prevents a race */
	//sigfillset(&signal_set);
	//pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
	//signal(SIGCHLD, cgi_child_end);


	/* ----------------------------------------------------------- fork the cgi */
	pid = fork();
	if(pid < 0) {
		smprintf(s, CGI_ENGINE "Could not fork: %s\n", strerror(errno));
		// pthread_sigmask(SIG_SETMASK, &old_set, NULL);
		goto error;
	}
	if(!pid) {
		/* -------------------------------------------------- child process */
		/* ------------------------------------ move stdout to child_out[1] */
		close(STDOUT_FILENO);
		dup2(child_out[1], STDOUT_FILENO);
		close(child_out[1]);
		close(child_out[0]);                       /* close unused read end */
		/* -------------------------------------- move stdin to child_in[0] */
		close(STDIN_FILENO);
		dup2(child_in[0], STDIN_FILENO);
		close(child_in[0]);
		close(child_in[1]);                       /* close unused write end */
		cgi_child(s);
	}
	/* --------------------------------------------------------- parent process */
	close(child_out[1]);                              /* close unused write end */
	close(child_in[0]);                                /* close unused read end */
	smprintf(s, CGI_ENGINE "Launched CGI script\n");

	/* ----------------------------------------------------------- send headers */
	DecodeUnicode(sms->Number, buffer2);
	cgi_write_header(s, child_in[1], "SMS_FROM", buffer2);
	DecodeUnicode(sms->Name, buffer2);
	cgi_write_header(s, child_in[1], "SMS_NAME", buffer2);
	cgi_write_header(s, child_in[1], "SMS_TIME", OSDate(sms->DateTime));

	/* -------------------------------------------- End headers with empty line */
	cgi_write_helper(s, child_in[1], "\r\n", sizeof("\r\n") - 1);

	/* ----------------------------------------------- now we write the command */
	cgi_write_helper(s, child_in[1], buffer, strlen(buffer));

	close(child_in[1]);                                             /* send EOF */

	/* ------------------------------------------------------------ now we read */
	smprintf(s, CGI_ENGINE ">>======== CGI Response ==========\n");
	buffer[0] = '\0';
	offset = 0;
	while((ret = read(child_out[0], buffer + offset, 1)) > 0) {
		offset += ret;
		*(buffer+offset) = '\0';
	}
	smprintf(s, CGI_ENGINE "%s", buffer);
	smprintf(s, "\n>>================================\n");

	do {
		/* ------------------------------------------------- wait for child to exit */
		if((ret = waitpid(pid, &status, WNOHANG)) == -1) {
			smprintf(s, CGI_ENGINE " waitpid failed :(\n");
			goto error;
		}
		if(!ret) {
			smprintf(s, CGI_ENGINE " Child is not dead yet ..\n");
		}
		if(!WIFEXITED(status)) {
			if(WIFSIGNALED(status)) {
				smprintf(s, CGI_ENGINE "killed by signal %d\n", WTERMSIG(status));
			} else if (WIFSTOPPED(status)) {
				smprintf(s, CGI_ENGINE "stopped by signal %d\n", WSTOPSIG(status));
			} else if (WIFCONTINUED(status)) {
				smprintf(s, CGI_ENGINE "continued\n");
			}
		}
	} while(!WIFEXITED(status) && !WIFSIGNALED(status));
	smprintf(s, CGI_ENGINE " Child process exited\n");

	if(buffer[0] != '\0') {
		/* ----------------------------------------------- prepare response */
		memset(&smsSendBuffer, 0, sizeof(smsSendBuffer));   /* reset memory */
		GSM_SetDefaultSMSData(&smsSendBuffer);
		smsSendBuffer.Location = 1;
		smsSendBuffer.Class = 1;
		smsSendBuffer.PDU = SMS_Submit;
		smsSendBuffer.Coding = SMS_Coding_Default_No_Compression;
		CopyUnicodeString(smsSendBuffer.Number, sms->Number);
		EncodeUnicode(smsSendBuffer.Text, buffer, strlen(buffer));
		/* -------------------------------------------------- send response */
		error = GSM_SendSMS(s, &smsSendBuffer);
	}

	error:
		close(child_in[0]);
		close(child_in[1]);
		close(child_out[0]);
		close(child_out[1]);

	GSM_DeleteSMS(s, sms);
	return;
}
Beispiel #15
0
GSM_Error GSM_DecodeSMSStatusReportData(GSM_Debug_Info *di, GSM_SMSMessage *SMS, int TP_ST)
{
	SMS->DeliveryStatus 	= TP_ST;
	SMS->Coding 		= SMS_Coding_Unicode_No_Compression;

	if (TP_ST < 0x03) {
		EncodeUnicode(SMS->Text,"Delivered",9);
		SMS->Length = 9;
	} else if (TP_ST & 0x40) {
		EncodeUnicode(SMS->Text,"Failed",6);
		SMS->Length = 6;
	} else if (TP_ST & 0x20) {
		EncodeUnicode(SMS->Text,"Pending",7);
		SMS->Length = 7;
	} else {
		EncodeUnicode(SMS->Text,"Unknown",7);
		SMS->Length = 7;
	}

#ifdef DEBUG
	/* See GSM 03.40 section 9.2.3.15 (TP-Status) */
	if (TP_ST & 0x40) {
		if (TP_ST & 0x20) {
			/* 0x60, 0x61, ... */
			smfprintf(di, "Temporary error, SC is not making any more transfer attempts\n");
		} else {
			/* 0x40, 0x41, ... */
     			smfprintf(di, "Permanent error, SC is not making any more transfer attempts\n");
		}
    	} else if (TP_ST & 0x20) {
		/* 0x20, 0x21, ... */
		smfprintf(di, "Temporary error, SC still trying to transfer SM\n");
	}
	switch (TP_ST) {
	case 0x00: smfprintf(di, "SM received by the SME");					break;
	case 0x01: smfprintf(di, "SM forwarded by the SC to the SME but the SC is unable to confirm delivery");break;
	case 0x02: smfprintf(di, "SM replaced by the SC");					break;
	case 0x20: smfprintf(di, "Congestion");						break;
	case 0x21: smfprintf(di, "SME busy");						break;
	case 0x22: smfprintf(di, "No response from SME");					break;
	case 0x23: smfprintf(di, "Service rejected");					break;
	case 0x24: smfprintf(di, "Quality of service not available");			break;
	case 0x25: smfprintf(di, "Error in SME");						break;
        case 0x40: smfprintf(di, "Remote procedure error");					break;
        case 0x41: smfprintf(di, "Incompatibile destination");				break;
        case 0x42: smfprintf(di, "Connection rejected by SME");				break;
        case 0x43: smfprintf(di, "Not obtainable");						break;
        case 0x44: smfprintf(di, "Quality of service not available");			break;
        case 0x45: smfprintf(di, "No internetworking available");				break;
        case 0x46: smfprintf(di, "SM Validity Period Expired");				break;
        case 0x47: smfprintf(di, "SM deleted by originating SME");				break;
        case 0x48: smfprintf(di, "SM Deleted by SC Administration");			break;
        case 0x49: smfprintf(di, "SM does not exist");					break;
        case 0x60: smfprintf(di, "Congestion");						break;
        case 0x61: smfprintf(di, "SME busy");						break;
        case 0x62: smfprintf(di, "No response from SME");					break;
        case 0x63: smfprintf(di, "Service rejected");					break;
        case 0x64: smfprintf(di, "Quality of service not available");			break;
        case 0x65: smfprintf(di, "Error in SME");						break;
        default  : smfprintf(di, "Reserved/Specific to SC: %x",TP_ST);	break;
	}
	smfprintf(di, "\n");
#endif

	return ERR_NONE;
}