コード例 #1
0
ファイル: atobex.c プロジェクト: CootCraig/gammu
/**
 * \author Peter Ondraska, based on code by Marcin Wiacek and Michal Cihar
 *
 * License: Whatever the current maintainer of gammulib chooses, as long as there
 * is an easy way to obtain the source under GPL, otherwise the author's parts
 * of this function are GPL 2.0.
 */
GSM_Error ATOBEX_SetLocale(GSM_StateMachine *s, GSM_Locale *locale)
{
	/* this is not yet supported by gammu.c */
	int	format=0;
	char	req[12];
	GSM_Error error;

	if ((error = ATOBEX_SetATMode(s))!= ERR_NONE) return error;

	if (locale->DateFormat==GSM_Date_OFF) { format=0; } else
	if ((locale->DateFormat==GSM_Date_DDMMMYY)&&(locale->DateSeparator=='-')) { format=1; } else
	if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='-')) { format=2; } else
	if ((locale->DateFormat==GSM_Date_MMDDYY)&&(locale->DateSeparator=='/')) { format=3; } else
	if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='/')) { format=4; } else
	if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='.')) { format=5; } else
	if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator==0)) { format=6; } else
	if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator=='-')) { format=7; }
	else { return ERR_NOTSUPPORTED; } /* ERR_WRONGINPUT */

	sprintf(req,"AT*ESDF=%i\r",format);
	smprintf(s, "Setting date format\n");
	error = GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale);
	if (error!=ERR_NONE) return error;

	if (locale->AMPMTime) { format=2; } else { format=1; }
	sprintf(req,"AT*ESTF=%i\r",format);
	smprintf(s, "Setting time format\n");
	return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale);
}
コード例 #2
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4GetADC(int argc, char *argv[])
{
	int		i = 0;
	GSM_Error error;
	unsigned char 	GetRaw[]  = {N6110_FRAME_HEADER, 0x0F,
				     0x00,		/* Test number */
			             0x01};
	unsigned char 	GetUnit[] = {N6110_FRAME_HEADER, 0x11,
				     0x00,		/* Test number */
				     0x01};

	if (CheckDCT4Only()!=ERR_NONE) return;

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	while (1) {
		printf(" %30s ", gettext(DCT4ADC[i].name));
		GetRaw[4] = i;
		error=GSM_WaitFor (gsm, GetRaw, 6, 0x17, 4, ID_User3);
		Print_Error(error);
		GetUnit[4] 	= i;
		ADC		= DCT4ADC[i].x;
		error=GSM_WaitFor (gsm, GetUnit, 6, 0x17, 4, ID_User3);
		Print_Error(error);
		printf("%s\n", gettext(DCT4ADC[i].unit));
		i++;
		if (DCT4ADC[i].name[0] == 0x00) break;
	}
}
コード例 #3
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4ResetSecurityCode(int argc, char *argv[])
{
	unsigned int	i;
	GSM_Error error;
	unsigned char 	ResetCode[30] = {0x00,0x06,0x03,0x04,0x01,
		'1','2','3','4','5','6','7','8','9','0',	/* Old code */
		0x00,
		'1','2','3','4','5',0x00,0x00,0x00,0x00,0x00,   /* New code */
		0x00};

	if (CheckDCT4Only()!=ERR_NONE) return;

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	error=GSM_WaitFor (gsm, ResetCode, 27, 0x08, 4, ID_User2);
	if (error == ERR_UNKNOWN) {
		if (answer_yes2("Try brutal force ?")) {
			for (i=10000;i<9999999;i++) {
				printf(_("Trying %i\n"),i);
				memset(ResetCode+6,0,22);
				sprintf(ResetCode+5,"%i",i);
				sprintf(ResetCode+16,"12345");
				error=GSM_WaitFor (gsm, ResetCode, 27, 0x08, 4, ID_User2);
				if (error == ERR_NONE) break;
			}
		}
	} else Print_Error(error);
}
コード例 #4
0
ファイル: dct4.c プロジェクト: pavl00/gammu
GSM_Error DCT4Info(void)
{
	unsigned char GetBTAddress[8] = {N6110_FRAME_HEADER, 0x09, 0x19, 0x01, 0x03, 0x06};
	unsigned char GetSimlock[5] = {N6110_FRAME_HEADER, 0x12, 0x0D};
	unsigned char value[10];
	GSM_Error error;

	error = CheckDCT4Only();
	if (error != ERR_NONE) return error;

	if (GSM_IsPhoneFeatureAvailable(gsm->Phone.Data.ModelInfo, F_SERIES40_30))
		return ERR_NOTSUPPORTED;

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	if (GSM_IsPhoneFeatureAvailable(gsm->Phone.Data.ModelInfo, F_BLUETOOTH)) {
		printf(LISTFORMAT, _("Bluetooth"));

		error=GSM_WaitFor (gsm, GetBTAddress, 8, 0xD7, 4, ID_User6);
		Print_Error(error);
	}

	error=GSM_WaitFor (gsm, GetSimlock, 5, 0x53, 4, ID_User6);
	Print_Error(error);
	GetSimlock[4] = 0x0E;
	error=GSM_WaitFor (gsm, GetSimlock, 5, 0x53, 4, ID_User6);
	Print_Error(error);
	GetSimlock[3] = 0x0C;
	error=GSM_WaitFor (gsm, GetSimlock, 4, 0x53, 4, ID_User6);
	Print_Error(error);
	error=NOKIA_GetPhoneString(gsm,"\x00\x03\x02\x07\x00\x08",6,0x1b,value,ID_User6,10);
	Print_Error(error);
	printf(LISTFORMAT "%s\n", _("UEM"), value);
	return ERR_NONE;
}
コード例 #5
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4GetSecurityCode(int argc, char *argv[])
{
	GSM_Error 	error;
	unsigned char 	getlen[]={0x00, 0x08, 0x01, 0x0C,
				  0x00, 0x23, 		//ID
				  0x00, 0x00, 		//Index
				  0x00, 0x00};
	unsigned char 	readcode[]={0x00, 0x08, 0x02, 0x04,
				0x00, 0x23, 		//ID
				0x00, 0x00, 		//Index
				0x00, 0x00, 0x00, 0x00, 0x00,
				0x00, 0x00, 0x00, 0x00,
				0x00};                  //Length

	if (CheckDCT4Only()!=ERR_NONE) return;

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	SecLength = 0;
	error=GSM_WaitFor (gsm, getlen, sizeof(getlen), 0x23, 1, ID_User1);
	Print_Error(error);
	if (SecLength != 0) {
		readcode[17] = SecLength;
		error=GSM_WaitFor (gsm, readcode, sizeof(readcode), 0x23, 5, ID_User1);
		Print_Error(error);
	}
}
コード例 #6
0
ファイル: 6510cal.c プロジェクト: Bakus/gammu
/* method 3 */
static GSM_Error N6510_GetCalendarNotePos3(GSM_StateMachine *s)
{
	unsigned char req[] = {N6110_FRAME_HEADER, 0x95, 0x00};

	smprintf(s, "Getting first free calendar note location\n");
	return GSM_WaitFor (s, req, 5, 0x13, 4, ID_GetCalendarNotePos);
}
コード例 #7
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4GetPBKFeatures(int argc, char *argv[])
{
	GSM_MemoryType	MemoryType=0;
	GSM_Error error;
	unsigned char 	req[] = {N6110_FRAME_HEADER, 0x25,
				 0x05, 	// memory type
				 0x00};

	if (strcasecmp(argv[2],"DC") == 0) MemoryType=MEM_DC;
	if (strcasecmp(argv[2],"ON") == 0) MemoryType=MEM_ON;
	if (strcasecmp(argv[2],"RC") == 0) MemoryType=MEM_RC;
	if (strcasecmp(argv[2],"MC") == 0) MemoryType=MEM_MC;
	if (strcasecmp(argv[2],"ME") == 0) MemoryType=MEM_ME;
	if (strcasecmp(argv[2],"SM") == 0) MemoryType=MEM_SM;
	if (strcasecmp(argv[2],"VM") == 0) MemoryType=MEM_VM;
	if (strcasecmp(argv[2],"FD") == 0) MemoryType=MEM_FD;
	if (MemoryType==0) {
		printf(_("ERROR: unknown memory type (\"%s\")\n"),argv[2]);
		Terminate(2);
	}

	req[4] = NOKIA_GetMemoryType(gsm, MemoryType,N71_65_MEMORY_TYPES);
	if (req[4]==0xff) Terminate(3);

	GSM_Init(TRUE);

        CheckDCT4();

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	error=GSM_WaitFor (gsm, req, 6, 0x03, 4, ID_User3);
	Print_Error(error);

	GSM_Terminate();
}
コード例 #8
0
ファイル: atobex.c プロジェクト: CootCraig/gammu
/**
 * \author Peter Ondraska, based on code by Marcin Wiacek and Michal Cihar
 *
 * License: Whatever the current maintainer of gammulib chooses, as long as there
 * is an easy way to obtain the source under GPL, otherwise the author's parts
 * of this function are GPL 2.0.
 */
GSM_Error ATOBEX_GetLocale(GSM_StateMachine *s, GSM_Locale *locale)
{
	GSM_Error error;

	if ((error = ATOBEX_SetATMode(s))!= ERR_NONE) return error;


	s->Phone.Data.Locale = locale;

	smprintf(s, "Getting date format\n");
	error=GSM_WaitFor (s, "AT*ESDF?\r", 9, 0x00, 3, ID_GetLocale);
	if (error!=ERR_NONE) return error;

	smprintf(s, "Getting time format\n");
	return GSM_WaitFor (s, "AT*ESTF?\r", 9, 0x00, 3, ID_GetLocale);
}
コード例 #9
0
ファイル: n3320.c プロジェクト: Bakus/gammu
static GSM_Error N3320_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
{
	unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x00, 0x00};

	s->Phone.Data.DateTime=date_time;
	smprintf(s, "Getting date & time\n");
	return GSM_WaitFor (s, req, 6, 0x19, 4, ID_GetDateTime);
}
コード例 #10
0
ファイル: atobex.c プロジェクト: CootCraig/gammu
GSM_Error ATOBEX_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
{
	GSM_Error error, error2;
	int	i = 0;
	GSM_Phone_ATOBEXData	*Priv = &s->Phone.Data.Priv.ATOBEX;

	s->Phone.Data.BatteryCharge = bat;

	if ((error = ATOBEX_SetATMode(s))!= ERR_NONE) return error;

	/* Go to AT if EBCA does not work */
	if (Priv->EBCAFailed) {
		return ATGEN_GetBatteryCharge(s, bat);
	}

	/* Now try ericsson extended reporting */
	error = GSM_WaitFor (s, "AT*EBCA=1\r", 10, 0x00, 3, ID_GetBatteryCharge);
	if (error != ERR_NONE) {
		Priv->EBCAFailed = TRUE;
		/* Ty ATGEN state */
		return ATGEN_GetBatteryCharge(s, bat);
	}
	/* Wait for async phone reply */
	while (s->Phone.Data.BatteryCharge != NULL) {
		error = GSM_WaitFor (s, "AT\r", 3, 0x00, 3, ID_GetBatteryCharge);
		smprintf(s, "Loop %d, error %d\n", i, error);
		if (i == 20) break;
		if (error != ERR_NONE) {
			break;
		}
		i++;
	}
	/* Disable reading information */
	error2 = GSM_WaitFor (s, "AT*EBCA=0\r", 10, 0x00, 3, ID_GetBatteryCharge);
	if (error2 != ERR_NONE) {
		return error;
	}
	/* If something failed, do AT way */
	if (error != ERR_NONE) {
		return ATGEN_GetBatteryCharge(s, bat);
	}
	/* Did we timeout? */
	if (i == 20) return ERR_TIMEOUT;
	return error;
}
コード例 #11
0
ファイル: atobex.c プロジェクト: CootCraig/gammu
GSM_Error ATOBEX_GetFileSystemStatus(GSM_StateMachine *s, GSM_FileSystemStatus *Status)
{
	GSM_Error error;

	if ((error = ATOBEX_SetATMode(s))!= ERR_NONE) return error;

	s->Phone.Data.FileSystemStatus = Status;

	return GSM_WaitFor (s, "AT*EMEM\r", 8, 0x00, 3, ID_FileSystemStatus);
}
コード例 #12
0
ファイル: dct4.c プロジェクト: pavl00/gammu
static GSM_Error DCT4EnableVibra(GSM_StateMachine *sm, gboolean enable)
{
	/* Enables or disables vibra */
	unsigned char 	Control[6] = {N7110_FRAME_HEADER,0x0C,
		0x01,		/* 0x01 = On, 0x00 = Off */
		0x00};

	if (!enable) Control[4] = 0x00;
	return GSM_WaitFor (sm, Control, 6, 0x1C, 4, ID_User3);
}
コード例 #13
0
ファイル: 6510cal.c プロジェクト: Bakus/gammu
static GSM_Error N6510_PrivGetGenericCalendar3(GSM_StateMachine *s, int Location, GSM_Phone_RequestID ID)
{
	unsigned char req[] = {N6110_FRAME_HEADER,0x7D,0x00,0x00,0x00,0x00,
			       0x00,0x99,	/* Location */
			       0xff,0xff,0xff,0xff};

	req[8] = Location / 256;
	req[9] = Location % 256;

	return GSM_WaitFor (s, req, 14, 0x13, 4, ID);
}
コード例 #14
0
ファイル: n3320.c プロジェクト: Bakus/gammu
static GSM_Error N3320_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
{
	unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02,
			       0x00,		/* memory type */
			       0x55, 0x55, 0x55, 0x00};

	req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES);
	if (Status->MemoryType == MEM_SM) return ERR_NOTSUPPORTED;
	if (req[5]==0xff) return ERR_NOTSUPPORTED;

	s->Phone.Data.MemoryStatus=Status;
	smprintf(s, "Getting memory status\n");
	return GSM_WaitFor (s, req, 10, 0x03, 4, ID_GetMemoryStatus);
}
コード例 #15
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4SelfTests(int argc, char *argv[])
{
	int 	      j;
	GSM_Error error;
	unsigned char GetDoneST[6]    = {0x00, 0x08, 0x01, 0x04, 0x01, 0x00};
	unsigned char GetDoneST2[6]   = {0x00, 0x08, 0x02, 0x04, 0x02, 0x00};
	unsigned char GetNames[6]     = {0x00, 0x08, 0x03, 0x06, 0x03, 0x00};
	unsigned char GetStatus[6]    = {0x00, 0x08, 0x04, 0x02, 0x03, 0x00};

	unsigned char RunALL[6]       = {0x00, 0x06, 0x04, 0x00, 0x03, 0x00};

//	unsigned char GetID[6]        = {0x00, 0x08, 0x00, 0x04, 0x03, 0x00};//tests ID

	if (CheckDCT4Only()!=ERR_NONE) return;

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	if (answer_yes2("Run all tests now ?")) {
		error=GSM_WaitFor (gsm, RunALL, 6, 0x35, 4, ID_User1);
		Print_Error(error);
	}

	error=GSM_WaitFor (gsm, GetNames, 6, 0x35, 4, ID_User1);
	Print_Error(error);

	for (j=0;j<DCT4Tests.Num;j++) DCT4Tests.Tests[j].Startup = FALSE;

	error=GSM_WaitFor (gsm, GetDoneST, 6, 0x35, 4, ID_User3);
	Print_Error(error);

	error=GSM_WaitFor (gsm, GetDoneST2, 6, 0x35, 4, ID_User3);
	Print_Error(error);

	error=GSM_WaitFor (gsm, GetStatus, 6, 0x35, 4, ID_User2);
	Print_Error(error);
}
コード例 #16
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4SetPhoneMenus(int argc, char *argv[])
{
	int 		current = 10,i=0,j,z;
	unsigned char 	reqSet[200] = {
		N7110_FRAME_HEADER,0x04,0x00,0x01,0x47,0x48,0x02,
		0x00};		/* Number of changed features */
	GSM_Error error;

	if (CheckDCT4Only()!=ERR_NONE) return;

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	while (DCT4PhoneFeatures[i].Model[0] != 0x00) {
		if (!strcmp(DCT4PhoneFeatures[i].Model,gsm->Phone.Data.Model)) {
			j = 0;
			while (DCT4PhoneFeatures[i].Features[j].Name != 0x00) {
				z = 0;
				while (DCT4Features[z].Name != 0x00) {
					if (DCT4Features[z].Name == DCT4PhoneFeatures[i].Features[j].Name) {
						printf("%s : %s\n",DCT4Features[z].Text,DCT4Features[z].Values[0].Text);
						reqSet[9]++;							/* Number of features */
						reqSet[current++] = DCT4PhoneFeatures[i].Features[j].Number; 	/* Feature number */
						reqSet[current++] = DCT4Features[z].Values[0].Value;		/* Value */
						break;
					}
					z++;
				}
				j++;
			}
		}
		i++;
	}

	if (current == 10) {
		printf("%s\n", _("Sorry, but configuration matrix for this model has not yet been added. See <https://wammu.eu/support/bugs/> for information how to report it."));
		return;
	}

	reqSet[current++] = 0x00;
	reqSet[current++] = 0x00;

	error=GSM_WaitFor (gsm, reqSet, current, 0x1b, 4, ID_User1);
	Print_Error(error);
}
コード例 #17
0
ファイル: 6510cal.c プロジェクト: Bakus/gammu
/* method 3 */
GSM_Error N6510_GetCalendarInfo3(GSM_StateMachine *s, GSM_NOKIACalToDoLocations *Last, char Type)
{
	GSM_Error 	error = ERR_UNKNOWN;
	int		i;
	unsigned char   req[] = {N6110_FRAME_HEADER, 0x9E, 0xFF, 0xFF, 0x00, 0x00,
			         0x00, 0x00,	/* First location */
			         0x00};		/* 0 = calendar, 1 = ToDo in 6610 style, 2 = Notes */

	Last->Location[0] = 0x00;
	Last->Number	  = 0;

	req[10] = Type;
	if (Type == 0) {
		smprintf(s, "Getting locations for calendar method 3\n");
		error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo);
	} else if (Type == 1) {
		smprintf(s, "Getting locations for ToDo method 2\n");
		error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo);
	} else if (Type == 2) {
		smprintf(s, "Getting locations for Notes\n");
		error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetNote);
	}
	if (error != ERR_NONE && error != ERR_EMPTY) return error;

	while (1) {
		i=0;
		while (Last->Location[i] != 0x00) i++;
		smprintf(s, "i = %i last_number = %i\n",i,Last->Number);
		if (i == Last->Number) break;
		if (i != Last->Number && error == ERR_EMPTY) {
			smprintf(s, "Phone doesn't support some notes with this method. Workaround\n");
			Last->Number = i;
			break;
		}
		req[8] = Last->Location[i-1] / 256;
		req[9] = Last->Location[i-1] % 256;
		if (Type == 0) {
			smprintf(s, "Getting locations for calendar method 3\n");
			error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo);
		} else if (Type == 1) {
			smprintf(s, "Getting locations for todo method 2\n");
			error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo);
		} else if (Type == 2) {
			smprintf(s, "Getting locations for Notes\n");
			error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetNote);
		}
		if (error != ERR_NONE && error != ERR_EMPTY) return error;
	}
	return ERR_NONE;
}
コード例 #18
0
ファイル: atobex.c プロジェクト: CootCraig/gammu
/**
 * Ensures phone and Gammu protocol are switched to AT commands mode.
 */
GSM_Error ATOBEX_SetATMode(GSM_StateMachine *s)
{
	GSM_Phone_ATOBEXData	*Priv = &s->Phone.Data.Priv.ATOBEX;
	GSM_Error		error;

	/* Aren't we in OBEX mode? */
	if (Priv->Mode == ATOBEX_ModeAT) return ERR_NONE;

	smprintf(s, "Terminating OBEX\n");

	/* Disconnect from OBEX service */
	error = OBEXGEN_Disconnect(s);
	if (error != ERR_NONE) return error;

	/* Terminate OBEX protocol */
	error = s->Protocol.Functions->Terminate(s);
	if (error != ERR_NONE) return error;

	/* Switch to AT protocol */
	smprintf(s, "Changing protocol to AT\n");
	s->Protocol.Functions			= &ATProtocol;
	s->Phone.Functions->ReplyFunctions	= ATGENReplyFunctions;
	Priv->Mode				= ATOBEX_ModeAT;

	/* Terminate SQWE Obex mode */
	if (Priv->HasOBEX == ATOBEX_OBEX_SQWE) {
		sleep(1);
		error = GSM_WaitFor (s, "+++", 3, 0x00, 100, ID_IncomingFrame);
		if (error != ERR_NONE) return error;
	}

	/* Give Samsung phones some time to recover from protocol switch */
	if (Priv->HasOBEX == ATOBEX_OBEX_MOBEX || Priv->HasOBEX == ATOBEX_OBEX_TSSPCSW) {
		sleep(2);
	}

	/* Initialise AT protocol */
	error = s->Protocol.Functions->Initialise(s);
	if (error != ERR_NONE) return error;

	return ERR_NONE;
}
コード例 #19
0
ファイル: n3320.c プロジェクト: Bakus/gammu
static GSM_Error N3320_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
{
	unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01,
			       0xfe, 0x10, 	/* memory type */
			       0x00, 0x00, 0x00, 0x00,
			       0x00, 0x01, 	/* location */
			       0x00, 0x00, 0x01};

	req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
	if (entry->MemoryType == MEM_SM) return ERR_NOTSUPPORTED;
	if (req[9]==0xff) return ERR_NOTSUPPORTED;

	if (entry->Location==0x00) return ERR_INVALIDLOCATION;

	req[14] = entry->Location / 256;
	req[15] = entry->Location % 256;

	s->Phone.Data.Memory=entry;
	smprintf(s, "Getting phonebook entry\n");
	return GSM_WaitFor (s, req, 19, 0x03, 4, ID_GetMemory);
}
コード例 #20
0
ファイル: n9210.c プロジェクト: AndyLavr/gammu
static GSM_Error N9210_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
{
	unsigned char OpReq[] = {N6110_FRAME_HEADER, 0x70};

	s->Phone.Data.Bitmap=Bitmap;
	switch (Bitmap->Type) {
	case GSM_OperatorLogo:
		smprintf(s, "Getting operator logo\n");
		/* This is like DCT3_GetNetworkInfo */
		return GSM_WaitFor (s, OpReq, 4, 0x0a, 4, ID_GetBitmap);
	case GSM_StartupLogo:
		smprintf(s, "Getting startup logo\n");
		return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x15);
	case GSM_WelcomeNote_Text:
		smprintf(s, "Getting welcome note\n");
		return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x02);
	default:
		break;
	}
	return ERR_NOTSUPPORTED;
}
コード例 #21
0
ファイル: nfuncold.c プロジェクト: AndyLavr/gammu
/* Note: in known phones texts of notes cut to 50 chars */
GSM_Error N71_65_GetNextCalendar2(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, int *LastCalendarYear, int *LastCalendarPos)
{
	GSM_Error		error;
	GSM_DateTime		date_time;
	unsigned char 		req[] = {N6110_FRAME_HEADER, 0x3e,
					 0xFF, 0xFE};		/* Location */

	if (start) {
		/* We have to get current year. It's NOT written in frame for
		 * Birthday
		 */
		error=s->Phone.Functions->GetDateTime(s,&date_time);
		switch (error) {
			case ERR_EMPTY:
			case ERR_NOTIMPLEMENTED:
				GSM_GetCurrentDateTime(&date_time);
				break;
			case ERR_NONE:
				break;
			default:
				return error;
		}
		*LastCalendarYear = date_time.Year;

		/* First location at all */
		req[4] = 0xFF;
		req[5] = 0xFE;
	} else {
		req[4] = *LastCalendarPos / 256;
		req[5] = *LastCalendarPos % 256;
	}
	Note->EntriesNum		= 0;
	Note->Entries[0].Date.Year 	= *LastCalendarYear;

	s->Phone.Data.Cal = Note;
	smprintf(s, "Getting calendar note method 2\n");
	error=GSM_WaitFor (s, req, 6, 0x13, 4, ID_GetCalendarNote);
	*LastCalendarPos = Note->Location;
	return error;
}
コード例 #22
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4GetT9(int argc, char *argv[])
{
	int	      i,T9Dictionary=0;
	unsigned char req[] = {N7110_FRAME_HEADER, 0x04, 0x00, 0x5B,
			       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			       0x00, 0x00,	/* Start position */
			       0x00, 0x00,
			       0x02, 0xBC};	/* How many bytes to read */
	GSM_Error error;

	if (CheckDCT4Only()!=ERR_NONE) return;

	T9File = fopen("T9", "w");
	if (T9File == NULL) return;

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	i = 0;
	while (1) {
		req[12] = i / 256;
		req[13] = i % 256;
		if (i != 0) {
			if (T9Dictionary - i < req[16]*256+req[17]) {
				req[16] = (T9Dictionary - i) / 256;
				req[17] = (T9Dictionary - i) % 256;
			}
			if (T9Dictionary - i == 0) break;
		}
		error=GSM_WaitFor (gsm, req, 18, 0x23, 4, ID_User3);
		Print_Error(error);
		if (i==0) {
			T9Dictionary = T9FullSize;
			smprintf(gsm, "T9 dictionary size is %i\n",T9Dictionary);
		}
		i+=T9Size;
	}

	fclose(T9File);
}
コード例 #23
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4SetVibraLevel(int argc, char *argv[])
{
	GSM_DateTime	Date;
	int	i,j;
	GSM_Error error;

	/* Set vibra level */
	unsigned char 	SetLevel[6] = {N7110_FRAME_HEADER,0x0E,
				       0x64,	/* Vibra power (in percent) */
				       0x00};

	GSM_Init(TRUE);

        CheckDCT4();

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	SetLevel[4] = GetInt(argv[2]);
	error=GSM_WaitFor (gsm, SetLevel, 6, 0x1C, 4, ID_User3);
	Print_Error(error);

	error=DCT4EnableVibra(gsm, TRUE);
	Print_Error(error);

	for (i=0;i<3;i++) {
		GSM_GetCurrentDateTime (&Date);
		j=Date.Second;
		while (j==Date.Second) {
			usleep(10000);
			GSM_GetCurrentDateTime(&Date);
		}
	}

	error=DCT4EnableVibra(gsm, FALSE);
	Print_Error(error);

	GSM_Terminate();
}
コード例 #24
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4PlaySavedRingtone(int argc, char *argv[])
{
	unsigned char req[] =  {N6110_FRAME_HEADER,
			      	0x01,
				0x00,0x64,	//id
				0x01,		//group
				0x01,0x00,0x00,
				0x0A,		//volume
				0x00,0x00,0x00,0x00,0x00,0x00,0x00};
	GSM_AllRingtonesInfo Info;
	GSM_Error error;
//	int i;

	GSM_Init(TRUE);

        CheckDCT4();

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	error=GSM_GetRingtonesInfo(gsm,&Info);
	Print_Error(error);

	if (GetInt(argv[2]) > Info.Number-1) {
		GSM_Terminate();
		return;
	}
	req[4] = Info.Ringtone[GetInt(argv[2])-1].ID / 256;
	req[5] = Info.Ringtone[GetInt(argv[2])-1].ID % 256;
	req[6] = Info.Ringtone[GetInt(argv[2])-1].Group;

	error=GSM_WaitFor (gsm, req, 18, 0x1F, 4, ID_User3);
	Print_Error(error);

//	for (i=0;i<Info.Number;i++) printf(_("%i. \")%s\"\n",i,DecodeUnicodeConsole(Info.Ringtone[i].Name));

	GSM_Terminate();
}
コード例 #25
0
ファイル: dct4.c プロジェクト: pavl00/gammu
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();
}
コード例 #26
0
ファイル: wmx.c プロジェクト: Romppanen/gammu
void DCT3SetDebug(int argc, char *argv[])
{
	int		x,count;
	unsigned int y;
	unsigned char 	reqDisable[] = {0x01, 0x01, 0x71};
	GSM_Error error;
//	unsigned char 	reqTest[] = {0x01, 0x01, 0x96, 0xFF, 0xFF};

	/* RPC testing packets: */

	/* RPC: Get version */
	//unsigned char 	reqTest2[] = {0x01, 0x01, 0x00, 0x03, 0x00};
	/* RPC: read I/O 0x6D mask 0xFF */
	//unsigned char 	reqTest2[] = {0x01, 0x01, 0x02, 0x01, 0x02, 0x6D, 0xFF}; /*  */
	/* RPC: write I/O 0x03 mask 0xFF value 0x31 */
	//unsigned char 	reqTest2[] = {0x01, 0x01, 0x01, 0x01, 0x07, 0x03, 0xFF, 0x31}; /* write I/O */

	/* RPC: write forged FBUS packet to MDISND */
//	unsigned char 	reqTest2[] = {0x01, 0x01, 0x16, 0x01, 0x06,
//	0x14, // R0 -- length
//	0x05, // R1 -- MDI type identifier 0x05(FBUS)
//	0x1e, 0x0c, 0x00, 0x66,
//	0x00, 0x0e, 0x01, 0x01,
//	0x66, 0x55, 0x44, 0x33,
//	0x0d, 0x01, 0x01, 0x01,
//	0x1b, 0x58, 0x01, 0x44};
//	1805 t=cb37 nr=e2 :D 05:

	/* debug enable packet */
	unsigned char reqEnable[] = {
		0x00, 0x01, 0x70,
		/* Debug bits
		   byte[bit>>3]&(1<<(7-(bit&7)))
		*/
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00 */
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 */
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
		/* Debug verbose bits
		   byte[bit>>3]&(1<<(7-(bit&7)))
		*/
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		};
	FILE *xout;

	#define ENABLE_BIT(bit,verbose) reqEnable[3 + (bit>>3)] |= 1<<(7-(bit&7)); if(verbose){reqEnable[3 + 32 + (bit>>3)] |= 1<<(7-(bit&7));}

	/* Enable some bit
	   TODO command line or GUI interface
	*/
	//ENABLE_BIT(0x18, 1);	/* Enable MDISND debugging */
	//ENABLE_BIT(0x19, 1);	/* Enable MDIRCV debugging */
	//ENABLE_BIT(0x31, 1);

	gsmdec = GSMDecoder_new();
	/* Open XML file .. needs to be argument */
	xout = fopen("out.xml", "w");
	if (xout == NULL) {
		return;
	}
	GSMDecoder_xmlout(gsmdec, xout);

	printf("Debug Trace Mode -- wumpus 2003\n");
	traces = wmx_tracestruct_load(argv[2]);
	if(traces == NULL)
		printf("Warning: could not load trace description file %s\n", argv[2]);
	printf("Activating ranges:\n");
	count = 0;
	for(x=3; x<argc; x++) {
		char 		*ptr = argv[x];
		unsigned 	from,to,verbose;

		while(*ptr) {
		 	verbose = 0;
			if(*ptr == 'v') {
				verbose = 1;
				ptr++;
			}
			to = from = strtol(ptr, &ptr, 16);
			if(*ptr == '-') {
				ptr ++;
				to = strtol(ptr, &ptr, 16);
			}
			if(*ptr != ',' && *ptr != 0) {
				printf("Invalid parameter '%s'\n", argv[x]);
				return;
			}
			if(*ptr == ',')
				ptr++;
			if(from > 0xFF) from=0xFF;
			if(to > 0xFF) to=0xFF;
			printf("  %02x-%02x verbose=%i\n",from,to,verbose);
			for(y=from; y<=to; y++) {
				ENABLE_BIT(y, verbose);
				count++;
			}
		}
	}
	if(count == 0) {
		printf("Nothing activated -- bailing out\n");
		return;
	}
	//ENABLE_BIT(0x20, 1);  /* SIM commands (literal) */
	//ENABLE_BIT(0x21, 1);  /* SIML2 commands (literal) */
	//ENABLE_BIT(0x22, 1);  /* SIM commands (literal) */
	//ENABLE_BIT(0x3B, 1);	/* PHCTRL state */

	GSM_Init(TRUE);

	/* We Need DCT3 */
	CheckDCT3();

	error=DCT3_EnableSecurity (gsm, 0x01);
	Print_Error(error);

	gsm->User.UserReplyFunctions=UserReplyFunctionsX;

	//error=GSM_WaitFor (gsm, reqTest, sizeof(reqTest), 0x40, 1, ID_DebugSwitch);

	//error=GSM_WaitFor (gsm, reqTest2, sizeof(reqTest2), 0xD1, 4, ID_RPC);

	/* Enable Debug Mode */
	error=GSM_WaitFor (gsm, reqEnable, sizeof(reqEnable), 0x40, 4, ID_DebugSwitch);

	Print_Error(error);
	signal(SIGINT, interrupt);
	printf("Press Ctrl+C to interrupt...\n");
	x=0;

	/*
	while(x<100) {
		//printf(": %02x\n",x);
		gsm->Phone.Data.RequestID	= ID_DebugTrace;
		res = gsm->Device.Functions->ReadDevice(gsm, buff, 255);
		if(res) {
			printf("%02x\n",x);
			for(y=0;y<res;y++) {
				//printf("%02x\n",x,buff[y]&0xFF);
				gsm->Protocol.Functions->StateMachine(gsm,buff[y]);
				x++;
			}
		}
	}
	*/
	;

	/* todo: wait and dump for some time */
	while (!gshutdown) {
		GSM_ReadDevice(gsm,TRUE);
		usleep(10000);
	}
	signal(SIGINT, SIG_DFL);
	printf("Disabling\n");
	error=GSM_WaitFor (gsm, reqDisable, sizeof(reqDisable), 0x40, 10, ID_DebugSwitch);
	Print_Error(error);

	GSMDecoder_free(gsmdec);
}
コード例 #27
0
ファイル: atobex.c プロジェクト: CootCraig/gammu
/**
 * Ensures phone and Gammu protocol are in OBEX mode, in IrMC service
 * if requrested.
 */
GSM_Error ATOBEX_SetOBEXMode(GSM_StateMachine *s, OBEX_Service service)
{
	GSM_Phone_ATOBEXData	*Priv = &s->Phone.Data.Priv.ATOBEX;
	GSM_Error		error;

	/* Is OBEX mode supported? */
	if (Priv->HasOBEX == ATOBEX_OBEX_None) {
		return ERR_NOTSUPPORTED;
	}

	/* Are we already in OBEX mode? */
	if (Priv->Mode == ATOBEX_ModeOBEX) {
		/* We can not safely switch service, we need to disconnect instead */
		if (s->Phone.Data.Priv.OBEXGEN.Service == service) {
			return ERR_NONE;
		} else {
			error = ATOBEX_SetATMode(s);
		}
		if (error != ERR_NONE) return error;
	}

	smprintf(s, "Changing to OBEX mode\n");

	/* Switch phone to OBEX */
	error = ERR_NOTSUPPORTED;
	switch (Priv->HasOBEX) {
		case ATOBEX_OBEX_CPROT0:
			/* 3GPP TS 27.007 standard */
			error = GSM_WaitFor (s, "AT+CPROT=0\r", 11, 0x00, 100, ID_SetOBEX);
			break;
		case ATOBEX_OBEX_EOBEX:
			/* Sony-Ericsson extension */
			error = GSM_WaitFor (s, "AT*EOBEX\r", 9, 0x00, 100, ID_SetOBEX);
			break;
		case ATOBEX_OBEX_MODE22:
			/* Motorola extension */
			error = GSM_WaitFor (s, "AT+MODE=22\r", 11, 0x00, 20, ID_SetOBEX);
			break;
		case ATOBEX_OBEX_XLNK:
			/* Sharp extension */
			error = GSM_WaitFor (s, "AT+XLNK\r", 8, 0x00, 20, ID_SetOBEX);
			break;
		case ATOBEX_OBEX_SQWE:
			/* Siemens extension */
			error = GSM_WaitFor (s, "AT^SQWE=3\r", 10, 0x00, 20, ID_SetOBEX);
			break;
		case ATOBEX_OBEX_MOBEX:
			/* Samsung extension */
			error = GSM_WaitFor (s, "AT+SYNCML=MOBEXSTART\r", 21, 0x00, 20, ID_SetOBEX);
			break;
		case ATOBEX_OBEX_TSSPCSW:
			/* Samsung extension */
			error = GSM_WaitFor (s, "AT$TSSPCSW=1\r", 13, 0x00, 20, ID_SetOBEX);
			break;
		case ATOBEX_OBEX_None:
			break;
	}
	if (error != ERR_NONE) return error;

	/* Tell OBEX module it has no service selected */
	s->Phone.Data.Priv.OBEXGEN.Service = 0;

	smprintf(s, "Changing protocol to OBEX\n");

	/* Stop AT protocol */
	error = s->Protocol.Functions->Terminate(s);
	if (error != ERR_NONE) return error;

	/* Need some sleep before starting talk in OBEX */
	sleep(1);

	/* Switch to OBEX protocol and initialise it */
	s->Protocol.Functions = &OBEXProtocol;
	s->Phone.Functions->ReplyFunctions	= OBEXGENReplyFunctions;

	/* Initialise protocol */
	error = s->Protocol.Functions->Initialise(s);
	if (error != ERR_NONE) {
		/* Revert back to AT */
		s->Protocol.Functions = &ATProtocol;
		return error;
	}

	/* Remember our state */
	Priv->Mode				= ATOBEX_ModeOBEX;

	/* Choose appropriate connection type (we need different for filesystem and for IrMC) */
	smprintf(s, "Setting service %d\n", service);
	error = OBEXGEN_Connect(s, service);
	if (error != ERR_NONE) return error;

	return ERR_NONE;
}
コード例 #28
0
ファイル: atobex.c プロジェクト: CootCraig/gammu
/**
 * Initialises Sony-Ericsson module internals and calls AT module init.
 */
GSM_Error ATOBEX_Initialise(GSM_StateMachine *s)
{
	GSM_Phone_ATOBEXData	*Priv = &s->Phone.Data.Priv.ATOBEX;
	GSM_Phone_ATGENData	*PrivAT = &s->Phone.Data.Priv.ATGEN;
	GSM_Error		error;

	Priv->Mode				= ATOBEX_ModeAT;
	Priv->EBCAFailed = FALSE;

	/* We might receive incoming event */
	s->Phone.Data.BatteryCharge = NULL;

	/* Init OBEX module also */
	error = OBEXGEN_InitialiseVars(s);
	if (error != ERR_NONE) return error;

	/* This can be filled in by AT module init */
	Priv->HasOBEX = ATOBEX_OBEX_None;
	Priv->DataService = OBEX_None;

	/* Init AT module */
	/* This also enables ATOBEX_OBEX_CPROT0 if available */
	error = ATGEN_Initialise(s);
	if (error != ERR_NONE) return error;

	/* Does phone have support for AT+MODE=22 switching? */
	if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_MODE22)) {
		Priv->HasOBEX = ATOBEX_OBEX_MODE22;
		Priv->DataService = OBEX_IRMC;
	} else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_XLNK)) {
		Priv->HasOBEX = ATOBEX_OBEX_XLNK;
		Priv->DataService = OBEX_IRMC;
	} else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SQWE)) {
		Priv->HasOBEX = ATOBEX_OBEX_SQWE;
		Priv->DataService = OBEX_IRMC;
	} else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CPROT)) {
		Priv->HasOBEX = ATOBEX_OBEX_CPROT0;
		Priv->DataService = OBEX_IRMC;
	} else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_MOBEX)) {
		Priv->HasOBEX = ATOBEX_OBEX_MOBEX;
		Priv->DataService = OBEX_m_OBEX;
	} else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TSSPCSW)) {
		Priv->HasOBEX = ATOBEX_OBEX_TSSPCSW;
		Priv->DataService = OBEX_m_OBEX;
	} else {
		if (PrivAT->Mode) {
			smprintf(s, "Guessed mode style switching\n");
			Priv->HasOBEX = ATOBEX_OBEX_MODE22;
			Priv->DataService = OBEX_IRMC;
		}
	}

	/* Do we have OBEX capability? */
	if (Priv->HasOBEX == ATOBEX_OBEX_None) {
		error = GSM_WaitFor (s, "AT*EOBEX=?\r", 11, 0x00, 4, ID_SetOBEX);
		if (error == ERR_NONE) {
			Priv->HasOBEX = ATOBEX_OBEX_EOBEX;
			Priv->DataService = OBEX_IRMC;
		}
	}

	return ERR_NONE;
}
コード例 #29
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4TuneRadio(int argc, char *argv[])
{
	double		Freq, diff;
	GSM_Error error;
 	GSM_FMStation 	FMStation[50],FMStat;
	int		i, j, num;
	gboolean		found;

	unsigned char Enable[]     = {N6110_FRAME_HEADER, 0x00, 0x00, 0x00};
	unsigned char Disable[]    = {N6110_FRAME_HEADER, 0x01, 0x0E, 0x00};
//	unsigned char SetVolume[]  = {N6110_FRAME_HEADER, 0x14,
//				      0x00,	/* Volume level */
//				      0x00};
//	unsigned char MuteUnMute[] = {N6110_FRAME_HEADER, 0x0F,
//				      0x0C,	/* 0x0B = mute, 0x0C = unmute */
//				      0x00};
	unsigned char SetFreq[]	   = {N6110_FRAME_HEADER, 0x08,
				      0x08, 0x14, 0x00, 0x01,
				      0x9A, 0x28};  /* Frequency */
//	unsigned char Find1[]	   = {N6110_FRAME_HEADER, 0x08,
//				      0x04, 0x14, 0x00, 0x00, 0x00, 0x00};
	unsigned char Find2[]	   = {N6110_FRAME_HEADER, 0x08,
				      0x05, 0x14, 0x00, 0x00, 0x00, 0x00};
//	unsigned char SetStereo[]  = {N6110_FRAME_HEADER, 0x19,
//				      0x0A, 0x00, 0x15};
//	unsigned char SetMono[]    = {N6110_FRAME_HEADER, 0x19,
//				      0x09, 0x00, 0x96};

	GSM_Init(TRUE);

        CheckDCT4();

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	FMStat.Location = 1;
	error = GSM_GetFMStation(gsm,&FMStat);
	if (error != ERR_NONE && error != ERR_EMPTY) {
		printf("%s\n", _("Phone seems not to support radio"));
		GSM_Terminate();
		Terminate(3);
	}

	error=GSM_WaitFor (gsm, Enable, 6, 0x3E, 4, ID_User3);
	if (error == ERR_PERMISSION) {
		printf("%s\n", _("Please connect headset. Required as antenna"));
		GSM_Terminate();
		Terminate(3);
	}
	Print_Error(error);

	num=0;
	for (i=88;i<108;i++) {
		fprintf(stderr,"%cSearching: %i percent",13,(i-88)*100/(108-88));
		Freq = i;
		N6510_EncodeFMFrequency(Freq, SetFreq+8);
		error=GSM_WaitFor (gsm, SetFreq, 10, 0x3E, 4, ID_User3);
		Print_Error(error);

		error=GSM_WaitFor (gsm, Find2, 10, 0x3E, 4, ID_User3);
		Print_Error(error);
		found = FALSE;
		for (j=0;j<num;j++) {
			if (FMStation[j].Frequency > RadioFreq) {
				diff = FMStation[j].Frequency - RadioFreq;
			} else {
				diff = RadioFreq - FMStation[j].Frequency;
			}
			if (diff <= 0.2) {
				smprintf(gsm, "diff is %f\n",diff);
				found = TRUE;
				break;
			}
		}
		if (!found) {
			smprintf(gsm, "Adding %f, num %i\n",RadioFreq,num);
			FMStation[num].Frequency = RadioFreq;
			CopyUnicodeString(FMStation[num].StationName,RadioName);
			num++;
		}
	}
	fprintf(stderr,"%cSearching: %i percent",13,100);
	fprintf(stderr,"\n\n");

	i=0;
	while(1) {
		if (i==num || i==num-1) break;
		if (FMStation[i].Frequency > FMStation[i+1].Frequency) {
			memcpy(&FMStat,&FMStation[i],sizeof(GSM_FMStation));
			memcpy(&FMStation[i],&FMStation[i+1],sizeof(GSM_FMStation));
			memcpy(&FMStation[i+1],&FMStat,sizeof(GSM_FMStation));
			i = 0;
			continue;
		}
		i++;
	}
	for (i=0;i<num;i++) {
		fprintf(stderr,"%02i.",i+1);
		if (FMStation[i].Frequency < 100) fprintf(stderr," ");
		fprintf(stderr,"%.1f MHz - \"%s\" \n",
			FMStation[i].Frequency,
			DecodeUnicodeString(FMStation[i].StationName));
	}

	if (answer_yes2("Do you want to save found stations")) {
		fprintf(stderr,"Deleting old FM stations: ");
		error=GSM_ClearFMStations(gsm);
		Print_Error(error);
		fprintf(stderr,"Done\n");
		for (i=0;i<num;i++) {
			FMStation[i].Location = i+1;
			error=GSM_SetFMStation(gsm,&FMStation[i]);
			Print_Error(error);
			fprintf(stderr,"%cWriting: %i percent",13,(i+1)*100/num);
		}
		fprintf(stderr,"\n");
	}

	error=GSM_WaitFor (gsm, Disable, 6, 0x3E, 4, ID_User3);
	Print_Error(error);

	GSM_Terminate();
}
コード例 #30
0
ファイル: dct4.c プロジェクト: pavl00/gammu
void DCT4GetVoiceRecord(int argc, char *argv[])
{
	/* Voice records names */
	unsigned char 	ReqNames[200] = {
		N7110_FRAME_HEADER,
		0x30,0x01,0x55,0x00,0x00,0xFF,0xFF,0x01,0x01,0x55,0x55};
	/* Voice record token */
	unsigned char 	ReqToken[200] = {
		N7110_FRAME_HEADER,0x0C,0x00,0x44,0x00,
		0x00,		/* Location: 0, 1, ... */
		0x55,0x55};
	/* Voice record part */
	unsigned char 	ReqGet[200] = {
		N7110_FRAME_HEADER,0x04,0x00,0x44,
		0x00,0x00,	/* Location: 0, 1, ...  */
		0x55,0x55,0x00,

		0x00,0x00,	/* Part Location	*/
		0x00,0x00,0x00,

		0x04,		/* ???			*/

		0x00};		/* Token		*/

	/* WAV file headers */
	unsigned char 	WAV_Header[] = {
			'R','I','F','F',
			0x00,0x00,0x00,0x00,	/* Length */
			'W','A','V','E'};
	unsigned char 	FMT_Header[] = {'f','m','t',' ',
			0x14,0x00,0x00,0x00,0x31,0x00,0x01,0x00,0x40,0x1f,
			0x00,0x00,0x59,0x06,0x00,0x00,0x41,0x00,0x00,0x00,
			0x02,0x00,0x40,0x01,'f', 'a', 'c', 't', 0x04,0x00,
			0x00,0x00,
			0x00,0x73,0x00,0x00};	/* Seems to be some length */
	unsigned char 	DATA_Header[] = {
			'd','a','t','a',
			0x00,0x00,0x00,0x00};	/* Length */

	long		wavfilesize=0;
	unsigned char	FileName[100], Buffer[10000], Token;
	size_t 	Location, size=0, CurrentLocation = 0, TokenLocation;
	int		i;
	FILE		*WAVFile;
	GSM_Error error;

	Location = GetInt(argv[2]);
	if (Location == 0x00) {
		printf("%s\n", _("Please enumerate locations from 1"));
		return;
	}
	Location--;

	GSM_Init(TRUE);

        CheckDCT4();

	gsm->User.UserReplyFunctions=UserReplyFunctions4;

	gsm->Phone.Data.VoiceRecord 	= &Location;
	gsm->Phone.Data.PhoneString 	= FileName;
	smprintf(gsm, "Getting voice record name\n");
	error=GSM_WaitFor (gsm, ReqNames, 14, 0x4A, 4, ID_User4);
	Print_Error(error);

	gsm->Phone.Data.PhoneString 	= Buffer;
	ReqToken[7] 			= Location;
	smprintf(gsm, "Getting voice record token\n");
	error=GSM_WaitFor (gsm, ReqToken, 10, 0x23, 4, ID_User4);
	Print_Error(error);
	TokenLocation 			= Buffer[0] * 256 + Buffer[1];
	Token				= Buffer[2];

	WAVFile = fopen(FileName, "wb");
	if (WAVFile == NULL) {
		goto failnofile;
	}

	chk_fwrite(&WAV_Header,	1, sizeof(WAV_Header),	WAVFile);
	chk_fwrite(&FMT_Header,	1, sizeof(FMT_Header),	WAVFile);
	chk_fwrite(&DATA_Header,	1, sizeof(DATA_Header),	WAVFile);

	gsm->Phone.Data.VoiceRecord 	= &size;
	gsm->Phone.Data.PhoneString 	= Buffer;
	ReqGet[7]			= Location;
	fprintf(stderr,"Getting voice record and saving to \"%s\": ",FileName);
	while (1) {
		smprintf(gsm, "Getting next part of voice record\n");
		fprintf(stderr,".");
		error=GSM_WaitFor (gsm, ReqGet, 18, 0x23, 4, ID_User4);
		if (error == ERR_NONE) {
			wavfilesize += size;
			chk_fwrite(Buffer,1,size,WAVFile);
		}
		if (error == ERR_EMPTY) break;
		Print_Error(error);
		CurrentLocation += 4;
		ReqGet[11] = CurrentLocation / 256;
		ReqGet[12] = CurrentLocation % 256;
		if (CurrentLocation+4 > TokenLocation) break;
	}
	smprintf(gsm, "Getting first part in last sequence of voice record\n");
	for (i=255;i>=0;i--) {
		ReqGet[16] = i;
		ReqGet[17] = Token;
		fprintf(stderr,".");
		error=GSM_WaitFor (gsm, ReqGet, 18, 0x23, 4, ID_User4);
		if (error == ERR_NONE) {
			wavfilesize += size;
			chk_fwrite(Buffer,1,size,WAVFile);
			break;
		}
		if (error != ERR_EMPTY) Print_Error(error);
	}
	while (1) {
		smprintf(gsm, "Getting next part of last sequence in voice record\n");
		CurrentLocation += 4;
		ReqGet[11] = CurrentLocation / 256;
		ReqGet[12] = CurrentLocation % 256;
		fprintf(stderr,".");
		error=GSM_WaitFor (gsm, ReqGet, 18, 0x23, 4, ID_User4);
		if (error == ERR_NONE) {
			wavfilesize += size;
			chk_fwrite(Buffer,1,size,WAVFile);
		}
		if (error == ERR_EMPTY) break;
		Print_Error(error);
	}
	fprintf(stderr,"\n");

	wavfilesize 	+= sizeof(WAV_Header) + sizeof(FMT_Header) + sizeof(DATA_Header);
	WAV_Header[4] 	= (unsigned char)(wavfilesize % 256);
	WAV_Header[5] 	= (unsigned char)(wavfilesize / 256);
	WAV_Header[6] 	= (unsigned char)(wavfilesize / (256*256));
	WAV_Header[7] 	= (unsigned char)(wavfilesize / (256*256*256));

	/* FIXME */
	FMT_Header[36]	= (unsigned char)(((wavfilesize - 238) * 5 ) % 256);
	FMT_Header[37]	= (unsigned char)(((wavfilesize - 238) * 5 ) / 256);
	FMT_Header[38]	= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256));
	FMT_Header[39]	= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256*256));

	wavfilesize 	= wavfilesize - 54 - 6;
	DATA_Header[4] 	= (unsigned char)(wavfilesize % 256);
	DATA_Header[5] 	= (unsigned char)(wavfilesize / 256);
	DATA_Header[6] 	= (unsigned char)(wavfilesize / (256*256));
	DATA_Header[7] 	= (unsigned char)(wavfilesize / (256*256*256));

	fseek( WAVFile, 0, SEEK_SET);
	chk_fwrite(&WAV_Header,	1, sizeof(WAV_Header),	WAVFile);
	chk_fwrite(&FMT_Header,	1, sizeof(FMT_Header),	WAVFile);
	chk_fwrite(&DATA_Header,	1, sizeof(DATA_Header),	WAVFile);

fail:
	fclose(WAVFile);
failnofile:
	GSM_Terminate();
}