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); } }
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; }
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; } }
int main(int argc, char **argv) { int fd, rc; char *filename; char buf[BUFSIZE]; if (argc != 2) { Print("Usage: %s <filename>\n", argv[0]); Exit(1); } filename = argv[1]; fd = Open(filename, O_READ); if (fd < 0) Print_Error("Could not open file", fd); for (;;) { int len = Read(fd, buf, BUFSIZE); if (len == 0) break; /* EOF */ else if (len < 0) Print_Error("Read error", len); else { int i; for (i = 0; i < len; ++i) Put_Char(buf[i]); } } rc = Close(fd); if (rc < 0) Print_Error("Could not close file", rc); return 0; }
void RestoreSMS(int argc, char *argv[]) { GSM_Error error; GSM_MultiSMSMessage *SMS; GSM_SMS_Backup *Backup; GSM_SMSFolders folders; int smsnum = 0; gboolean restore8bit; SMS = malloc(sizeof(GSM_MultiSMSMessage)); if (SMS == NULL) { return; } Backup = malloc(sizeof(GSM_SMS_Backup)); if (Backup == NULL) { free(SMS); return; } if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE; error = GSM_ReadSMSBackupFile(argv[2], Backup); Print_Error(error); restore8bit = answer_yes("%s", _("Do you want to restore binary SMS?")); GSM_Init(TRUE); error = GSM_GetSMSFolders(gsm, &folders); Print_Error(error); while (Backup->SMS[smsnum] != NULL) { if (restore8bit || Backup->SMS[smsnum]->Coding != SMS_Coding_8bit) { SMS->Number = 1; memcpy(&(SMS->SMS[0]), Backup->SMS[smsnum], sizeof(GSM_SMSMessage)); DisplayMultiSMSInfo(SMS, FALSE, FALSE, NULL, gsm); if (answer_yes(_("Restore %03i sms to folder \"%s\"%s?"), smsnum + 1, DecodeUnicodeConsole(folders.Folder[Backup->SMS[smsnum]->Folder - 1].Name), folders.Folder[Backup->SMS[smsnum]->Folder - 1].Memory == MEM_SM ? _(" (SIM)") : "")) { smprintf(gsm, _("saving %i SMS\n"),smsnum); error = GSM_AddSMS(gsm, Backup->SMS[smsnum]); Print_Error(error); } } smsnum++; } /* We don't need this anymore */ GSM_FreeSMSBackup(Backup); free(Backup); free(SMS); GSM_Terminate(); }
void AddSMS(int argc, char *argv[]) { GSM_Error error; GSM_MultiSMSMessage *SMS; GSM_SMS_Backup *Backup; int smsnum = 0; int folder; if (argc == 5 && strcasecmp(argv[4],"-yes") == 0) always_answer_yes = TRUE; SMS = malloc(sizeof(GSM_MultiSMSMessage)); if (SMS == NULL) { return; } Backup = malloc(sizeof(GSM_SMS_Backup)); if (Backup == NULL) { free(SMS); return; } folder = GetInt(argv[2]); error = GSM_ReadSMSBackupFile(argv[3], Backup); Print_Error(error); GSM_Init(TRUE); while (Backup->SMS[smsnum] != NULL) { Backup->SMS[smsnum]->Folder = folder; Backup->SMS[smsnum]->SMSC.Location = 1; SMS->Number = 1; SMS->SMS[0] = *(Backup->SMS[smsnum]); DisplayMultiSMSInfo(SMS, FALSE, FALSE, NULL, gsm); if (answer_yes("%s", _("Restore message?"))) { error=GSM_AddSMS(gsm, Backup->SMS[smsnum]); Print_Error(error); } smsnum++; } /* We don't need this anymore */ GSM_FreeSMSBackup(Backup); free(Backup); free(SMS); GSM_Terminate(); }
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(); }
void DCT4SetLight(int argc, char *argv[]) { int i; N6510_PHONE_LIGHTS type; gboolean enable; GSM_Error error; if (strcasecmp(argv[2],"display") == 0) { type = N6510_LIGHT_DISPLAY; } else if (strcasecmp(argv[2],"keypad") == 0) { type = N6510_LIGHT_KEYPAD; } else if (strcasecmp(argv[2],"torch") == 0) { type = N6510_LIGHT_TORCH; } else { printf(_("What lights should I enable (\"%s\") ?\n"),argv[2]); Terminate(2); } if (strcasecmp(argv[3],"on") == 0) { enable = TRUE; } else if (strcasecmp(argv[3],"off") == 0) { enable = FALSE; } else { printf(_("What should I do (\"%s\") ?\n"),argv[3]); Terminate(2); } for (i=0;i<gsm->ConfigNum;i++) { gsm->Config[i].StartInfo = FALSE; } GSM_Init(TRUE); CheckDCT4(); error=N6510_SetLight(gsm, type, enable); Print_Error(error); GSM_Terminate(); }
/*************************************************************************************************** * Main section * ***************************************************************************************************/ void main(void) { error = 0; uint8 cntr; // Initialize system speed, communication interfaces and RF radio module exit_code = System_Init(); Print_Error(exit_code); while (1) { payload_length = 0; // Construct the packet TxPacket[payload_length++] = 0x01; TxPacket[payload_length++] = 0x02; TxPacket[payload_length++] = 0x03; // Send data over radio exit_code = Radio_Tx(TxPacket, payload_length, ADDR_REMOTE); // Print out packet that was sent UART_Send_Data("\r\nSending:"); for (cntr = 0; cntr < payload_length; cntr++) { UART0_Send_ByteToChar(&TxPacket[cntr]); } // Add some delay (around 1sec) __delay_cycles(5000000*SYSTEM_SPEED_MHZ); } } /* END: main */
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); }
int main(int argc, char **argv) { int fd; if (argc != 2) { Print("Usage: touch <filename>\n"); Exit(1); } fd = Open(argv[1], O_CREATE|O_WRITE); if (fd < 0) Print_Error("Could not open file", fd); if (Close(fd) < 0) Print_Error("Could not close file", fd); return 0; }
void CheckDCT4(void) { GSM_Error error; error = CheckDCT4Only(); switch (error) { case ERR_NOTSUPPORTED: Print_Error(ERR_NOTSUPPORTED); break; case ERR_OTHERCONNECTIONREQUIRED: printf("%s\n", _("Can't do it with current phone protocol")); Print_Error(ERR_NOTSUPPORTED); break; default: break; } }
void DCT4VibraTest(int argc, char *argv[]) { unsigned char ans[200]; GSM_Error error; if (CheckDCT4Only()!=ERR_NONE) return; gsm->User.UserReplyFunctions=UserReplyFunctions4; error=DCT4EnableVibra(gsm, TRUE); Print_Error(error); printf("%s\n", _("Press any key to continue...")); GetLine(stdin, ans, 99); error=DCT4EnableVibra(gsm, FALSE); Print_Error(error); }
inline void send_data_to_server(){ if(timer_counter == 10){ payload_length = 0; // Clear Tx packet buffer cntr = 0; for (cntr=RF_BUFFER_SIZE; cntr > 0; cntr--) TxPacket[cntr] = 0; // Construct the packet // This is the place where you can put your own data to send TxPacket[payload_length++] = PKT_CTRL | PKT_CTRL_REQUEST; //TxPacket[payload_length++] = PKT_TYPE_VOLTAGE; TxPacket[payload_length++] = 68; // Setting packet type as 'D' TxPacket[payload_length++] = water_high_byte; TxPacket[payload_length++] = water_low_byte; TxPacket[payload_length++] = water_temperature; // Print out all data that we are goind to send // Payload length includes Control packet and does not take into account // packet encryption nor source, destination adress bytes. Only actual payload that // you have defined above /*UART_Send_Data("\r\nPayload length:\t"); UART0_Send_ByteToChar(&payload_length); UART_Send_Data("\r\nDestination address: "); UART0_Send_ByteToChar(&addr_remote); UART_Send_Data("\r\nMessage: "); for (cntr = 1; cntr < payload_length; cntr++) { UART0_Send_ByteToChar(&TxPacket[cntr]); } */ /* NWK level data sending */ Print_Error(Radio_Send_Data(TxPacket, payload_length, addr_remote, PAYLOAD_ENC_OFF, PCKT_ACK_ON)); // reset water data water_high_byte = 0; water_low_byte = 0; //UART_Send_Data("\r\nERR: "); //UART0_Send_ByteToChar((uint8 *)exit_code); exit_code = 0; //UART_Send_Data("\r\n"); // Insert new line to separate packets // Add some delay (around 2sec) //__delay_cycles(5000000*SYSTEM_SPEED_MHZ); } }
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(); }
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(); }
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); }
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); }
/*************************************************************************************************** * Main section * ***************************************************************************************************/ void main(void) { // Initialize system Print_Error(System_Init()); WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer /* Start : CPU clock configuration */ if (CALBC1_1MHZ==0xFF) // If calibration constant erased { while(1); // do not load, trap CPU } DCOCTL = 0; // Select lowest DCOx and MODx settings BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz DCOCTL = CALDCO_1MHZ; /* End : CPU clock configuration */ /* Start : data pin configuration */ P1IE |= DATA_PIN; // DATA_PIN interrupt enabled // P1IES |= DATA_PIN; // DATA_PIN HI to LOW edge P1IFG &= ~DATA_PIN; // DATA_PIN IFG cleared /* End : data pin configuration */ /* Start : Timer interrupt configuration */ TACCTL0 = CCIE; // TACCR0 interrupt enabled TACCR0 = 32768; // Interrupt every one second ( TACTL = TASSEL_1 + ID_0 + MC_1; // Set the timer A to ACLK, divide clock cycle by 1, Up mode /* End : Timer interrupt configuration */ __enable_interrupt(); // Enabling interrupt __bis_SR_register(LPM0 + GIE); // LPM0 with interrupts enabled } /* END: main */
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); }
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(); }
void NokiaComposer(int argc UNUSED, char *argv[]) { GSM_Error error; GSM_Ringtone ringtone; gboolean started; int i,j; GSM_RingNote *Note; GSM_RingNoteDuration Duration; GSM_RingNoteDuration DefNoteDuration = 32; /* 32 = Duration_1_4 */ unsigned int DefNoteScale = Scale_880; ringtone.Format = 0; error=GSM_ReadRingtoneFile(argv[2],&ringtone); Print_Error(error); if (ringtone.Format != RING_NOTETONE) { printf("%s\n", _("It can be RTTL ringtone only used with this option")); Terminate(2); } started = FALSE; j = 0; for (i=0;i<ringtone.NoteTone.NrCommands;i++) { if (ringtone.NoteTone.Commands[i].Type == RING_Note) { Note = &ringtone.NoteTone.Commands[i].Note; if (!started) { if (Note->Note != Note_Pause) { printf(_("Ringtone \"%s\" (tempo = %i Beats Per Minute)"),DecodeUnicodeConsole(ringtone.Name),GSM_RTTLGetTempo(Note->Tempo)); printf("\n\n"); started = TRUE; } } if (started) j++; } } if (j>50) { printf_warn(_("length=%i notes, but you will enter only first 50 tones."), j); } printf("\n\n%s ", _("This ringtone in Nokia Composer in phone should look:")); started = FALSE; for (i=0;i<ringtone.NoteTone.NrCommands;i++) { if (ringtone.NoteTone.Commands[i].Type == RING_Note) { Note = &ringtone.NoteTone.Commands[i].Note; if (!started) { if (Note->Note != Note_Pause) started = TRUE; } if (started) { switch (Note->Duration) { case Duration_Full: printf("1"); break; case Duration_1_2 : printf("2"); break; case Duration_1_4 : printf("4"); break; case Duration_1_8 : printf("8"); break; case Duration_1_16: printf("16");break; case Duration_1_32: printf("32");break; } if (Note->DurationSpec == DottedNote) printf("."); switch (Note->Note) { case Note_C : printf("c"); break; case Note_Cis : printf("#c"); break; case Note_D :printf("d"); break; case Note_Dis : printf("#d"); break; case Note_E : printf("e"); break; case Note_F : printf("f"); break; case Note_Fis : printf("#f"); break; case Note_G : printf("g"); break; case Note_Gis : printf("#g"); break; case Note_A : printf("a"); break; case Note_Ais : printf("#a"); break; case Note_H : printf("h"); break; case Note_Pause : printf("-"); break; } if (Note->Note != Note_Pause) printf("%i",Note->Scale - 4); printf(" "); } } } printf("\n\n%s ", _("To enter it please press:")); started = FALSE; for (i=0;i<ringtone.NoteTone.NrCommands;i++) { if (ringtone.NoteTone.Commands[i].Type == RING_Note) { Note = &ringtone.NoteTone.Commands[i].Note; if (!started) { if (Note->Note != Note_Pause) started = TRUE; } if (started) { switch (Note->Note) { case Note_C : case Note_Cis: printf("1");break; case Note_D : case Note_Dis: printf("2");break; case Note_E : printf("3");break; case Note_F : case Note_Fis: printf("4");break; case Note_G : case Note_Gis: printf("5");break; case Note_A : case Note_Ais: printf("6");break; case Note_H : printf("7");break; default : printf("0");break; } if (Note->DurationSpec == DottedNote) printf("%s", _("(longer)")); switch (Note->Note) { case Note_Cis: case Note_Dis: case Note_Fis: case Note_Gis: case Note_Ais: printf("#"); break; default : break; } if (Note->Note != Note_Pause) { if ((unsigned int)Note->Scale != DefNoteScale) { while (DefNoteScale != (unsigned int)Note->Scale) { printf("*"); DefNoteScale++; if (DefNoteScale==Scale_7040) DefNoteScale = Scale_880; } } } Duration = 0; switch (Note->Duration) { case Duration_Full : Duration = 128; break; case Duration_1_2 : Duration = 64; break; case Duration_1_4 : Duration = 32; break; case Duration_1_8 : Duration = 16; break; case Duration_1_16 : Duration = 8; break; case Duration_1_32 : Duration = 4; break; default : fprintf(stderr, "error\n");break; } if (Duration > DefNoteDuration) { while (DefNoteDuration != Duration) { printf("9"); DefNoteDuration = DefNoteDuration * 2; } } if (Duration < DefNoteDuration) { while (DefNoteDuration != Duration) { printf("8"); DefNoteDuration = DefNoteDuration / 2; } } printf(" "); } } } printf("\n"); fflush(stdout); }
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); }
void SaveFile(int argc, char *argv[]) { GSM_Error error; GSM_Backup Backup; int i; size_t data_size = 0; FILE *file; unsigned char Buffer[100000]; GSM_MemoryEntry *pbk; long int location; if (strcasecmp(argv[2],"CALENDAR") == 0) { if (argc < 5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error = GSM_ReadBackupFile(argv[4], &Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error != ERR_NOTIMPLEMENTED) { Print_Error(error); } i = 0; while (Backup.Calendar[i] != NULL) { if (i == location) break; i++; } if (i != location || Backup.Calendar[i] == NULL) { printf("%s\n", _("Calendar note not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeVCALENDAR(Buffer, sizeof(Buffer), &data_size, Backup.Calendar[i],TRUE,Nokia_VCalendar); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"BOOKMARK") == 0) { if (argc < 5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error = GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error != ERR_NOTIMPLEMENTED) { Print_Error(error); } i = 0; while (Backup.WAPBookmark[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.WAPBookmark[i] == NULL) { printf("%s\n", _("WAP bookmark not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeURLFile(Buffer, &data_size, Backup.WAPBookmark[i]); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"NOTE") == 0) { if (argc<5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.Note[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.Note[i] == NULL) { printf("%s\n", _("Note not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeVNTFile(Buffer, sizeof(Buffer), &data_size, Backup.Note[i]); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"TODO") == 0) { if (argc<5) { printf("%s\n", _("Where is backup filename and location?")); Terminate(2); } location = GetInt(argv[5]) - 1; error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; while (Backup.ToDo[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.ToDo[i] == NULL) { printf("%s\n", _("Todo note not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } error = GSM_EncodeVTODO(Buffer, sizeof(Buffer), &data_size, Backup.ToDo[i], TRUE, Nokia_VToDo); GSM_FreeBackup(&Backup); Print_Error(error); } else if (strcasecmp(argv[2],"VCARD10") == 0 || strcasecmp(argv[2],"VCARD21") == 0) { if (argc<6) { printf("%s\n", _("Where is backup filename and location and memory type?")); Terminate(2); } location = GetInt(argv[6]) - 1; error=GSM_ReadBackupFile(argv[4],&Backup,GSM_GuessBackupFormat(argv[4], FALSE)); if (error!=ERR_NOTIMPLEMENTED) Print_Error(error); i = 0; if (strcasecmp(argv[5],"SM") == 0) { while (Backup.SIMPhonebook[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.SIMPhonebook[i] == NULL) { printf("%s\n", _("Phonebook entry not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } pbk = Backup.SIMPhonebook[i]; } else if (strcasecmp(argv[5],"ME") == 0) { while (Backup.PhonePhonebook[i]!=NULL) { if (i == location) break; i++; } if (i != location || Backup.PhonePhonebook[i] == NULL) { printf("%s\n", _("Phonebook entry not found in file")); GSM_FreeBackup(&Backup); Terminate(2); } pbk = Backup.PhonePhonebook[i]; } else { printf(_("Unknown memory type: \"%s\"\n"),argv[5]); GSM_FreeBackup(&Backup); Terminate(2); } if (strcasecmp(argv[2],"VCARD10") == 0) { error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard10); GSM_FreeBackup(&Backup); Print_Error(error); } else { error = GSM_EncodeVCARD(GSM_GetDebug(gsm), Buffer, sizeof(Buffer), &data_size, pbk, TRUE, Nokia_VCard21); GSM_FreeBackup(&Backup); Print_Error(error); } } else { printf(_("Unknown backup format: \"%s\"\n"), argv[2]); Terminate(2); } file = fopen(argv[3],"wb"); if (file == NULL) { printf_err("%s", _("Error while opening file for writing!\n")); Terminate(3); } if (data_size != fwrite(Buffer,1,data_size,file)) { printf_err("%s", _("Error while writing file!\n")); } if (fclose(file) != 0) { printf_err("%s", _("Error while closing file!\n")); } }
void BackupSMS(int argc UNUSED, char *argv[]) { GSM_Error error; GSM_SMS_Backup *Backup; GSM_MultiSMSMessage *sms; GSM_SMSFolders folders; gboolean BackupFromFolder[GSM_MAX_SMS_FOLDERS]; gboolean start = TRUE; gboolean DeleteAfter = FALSE, askdelete = TRUE; int j, smsnum = 0; sms = malloc(sizeof(GSM_MultiSMSMessage)); if (sms == NULL) { return; } Backup = malloc(sizeof(GSM_SMS_Backup)); if (Backup == NULL) { free(sms); return; } if (argc == 4) { if (strcasecmp(argv[3],"-yes") == 0) { always_answer_yes = TRUE; } if (strcasecmp(argv[3],"-all") == 0) { always_answer_yes = TRUE; askdelete = FALSE; DeleteAfter = FALSE; } } GSM_Init(TRUE); Backup->SMS[0] = NULL; sms->SMS[0].Location = 0; sms->Number = 0; error=GSM_GetSMSFolders(gsm, &folders); Print_Error(error); if (askdelete) { DeleteAfter = answer_yes("%s", _("Delete each sms after backup?")); } for (j=0;j<folders.Number;j++) { BackupFromFolder[j] = FALSE; if (answer_yes(_("Backup sms from folder \"%s\"%s?"), DecodeUnicodeConsole(folders.Folder[j].Name), folders.Folder[j].Memory == MEM_SM ? _(" (SIM)") : "" )) BackupFromFolder[j] = TRUE; } while (error == ERR_NONE) { sms->SMS[0].Folder=0x00; error=GSM_GetNextSMS(gsm, sms, start); switch (error) { case ERR_EMPTY: break; default: Print_Error(error); for (j=0;j<sms->Number;j++) { if (BackupFromFolder[sms->SMS[j].Folder-1]) { switch (sms->SMS[j].PDU) { case SMS_Status_Report: break; case SMS_Submit: case SMS_Deliver: if (sms->SMS[j].Length == 0) break; if (smsnum < GSM_BACKUP_MAX_SMS) { Backup->SMS[smsnum] = malloc(sizeof(GSM_SMSMessage)); if (Backup->SMS[smsnum] == NULL) Print_Error(ERR_MOREMEMORY); Backup->SMS[smsnum + 1] = NULL; } else { printf(_(" Increase %s\n") , "GSM_BACKUP_MAX_SMS"); GSM_Terminate(); Terminate(1); } *(Backup->SMS[smsnum]) = sms->SMS[j]; smsnum++; break; } } } } start=FALSE; } error = GSM_AddSMSBackupFile(argv[2], Backup); Print_Error(error); if (DeleteAfter) { for (j=0;j<smsnum;j++) { Backup->SMS[j]->Folder = 0; error=GSM_DeleteSMS(gsm, Backup->SMS[j]); Print_Error(error); fprintf(stderr, "\r"); fprintf(stderr, "%s ", _("Deleting:")); fprintf(stderr, _("%i percent"), (j + 1) * 100 / smsnum); } } GSM_FreeSMSBackup(Backup); free(Backup); free(sms); GSM_Terminate(); }
void DoBackup(int argc, char *argv[]) { GSM_Error error = ERR_NONE; int i, used; GSM_ToDoEntry ToDo; GSM_ToDoStatus ToDoStatus; GSM_CalendarEntry Calendar; GSM_Bitmap Bitmap; GSM_WAPBookmark Bookmark; GSM_Profile Profile; GSM_MultiWAPSettings Settings; GSM_SyncMLSettings SyncML; GSM_ChatSettings Chat; GSM_Ringtone Ringtone; GSM_SMSC SMSC; GSM_Backup Backup; GSM_NoteEntry Note; GSM_Backup_Info Info; GSM_FMStation FMStation; GSM_GPRSAccessPoint GPRSPoint; gboolean DoBackupPart; char buffer[GSM_MAX_INFO_LENGTH]; if (argc == 4 && strcasecmp(argv[3],"-yes") == 0) always_answer_yes = TRUE; GSM_ClearBackup(&Backup); GSM_GetBackupFormatFeatures(GSM_GuessBackupFormat(argv[2], FALSE),&Info); sprintf(Backup.Creator,"Gammu %s",VERSION); if (strlen(GetOS()) != 0) { strcat(Backup.Creator+strlen(Backup.Creator),", "); strcat(Backup.Creator+strlen(Backup.Creator),GetOS()); } if (strlen(GetCompiler()) != 0) { strcat(Backup.Creator+strlen(Backup.Creator),", "); strcat(Backup.Creator+strlen(Backup.Creator),GetCompiler()); } signal(SIGINT, interrupt); fprintf(stderr, "%s\n", _("Press Ctrl+C to break...")); GSM_Init(TRUE); if (Info.UseUnicode) { Info.UseUnicode=answer_yes("%s", _("Use Unicode subformat of backup file?")); } if (Info.DateTime) { GSM_GetCurrentDateTime (&Backup.DateTime); Backup.DateTimeAvailable=TRUE; } if (Info.Model) { error=GSM_GetManufacturer(gsm, Backup.Model); Print_Error(error); strcat(Backup.Model," "); error=GSM_GetModel(gsm, buffer); strcat(Backup.Model, buffer); if (GSM_GetModelInfo(gsm)->model[0]!=0) { strcat(Backup.Model," ("); strcat(Backup.Model,GSM_GetModelInfo(gsm)->model); strcat(Backup.Model,")"); } strcat(Backup.Model," "); error=GSM_GetFirmware(gsm, buffer, NULL, NULL); strcat(Backup.Model,buffer); } if (Info.IMEI) { error=GSM_GetIMEI(gsm, Backup.IMEI); if (error != ERR_NOTSUPPORTED) { Print_Error(error); } else { Backup.IMEI[0] = 0; } } printf("\n"); if (Info.PhonePhonebook) { printf("%s\n", _("Checking phone phonebook")); ReadPhonebook(Backup.PhonePhonebook, MEM_ME, _("Backup phone phonebook?"), GSM_BACKUP_MAX_PHONEPHONEBOOK); } if (Info.SIMPhonebook) { printf("%s\n", _("Checking SIM phonebook")); ReadPhonebook(Backup.SIMPhonebook, MEM_SM, _("Backup SIM phonebook?"), GSM_BACKUP_MAX_SIMPHONEBOOK); } DoBackupPart = FALSE; if (Info.Calendar) { printf("%s\n", _("Checking phone calendar")); Calendar.Location = 0; error=GSM_GetNextCalendar(gsm,&Calendar,TRUE); if (error==ERR_NONE) { if (answer_yes(" %s", _("Backup phone calendar notes?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); while (error == ERR_NONE) { if (used < GSM_MAXCALENDARTODONOTES) { Backup.Calendar[used] = malloc(sizeof(GSM_CalendarEntry)); if (Backup.Calendar[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.Calendar[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_MAXCALENDARTODONOTES"); printf("\n"); break; } *Backup.Calendar[used]=Calendar; used ++; error=GSM_GetNextCalendar(gsm,&Calendar,FALSE); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.ToDo) { printf("%s\n", _("Checking phone todos")); error=GSM_GetToDoStatus(gsm,&ToDoStatus); if (error == ERR_NONE && ToDoStatus.Used != 0) { if (answer_yes(" %s", _("Backup phone todos?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; ToDo.Location = 0; error=GSM_GetNextToDo(gsm,&ToDo,TRUE); while (error == ERR_NONE) { if (used < GSM_MAXCALENDARTODONOTES) { Backup.ToDo[used] = malloc(sizeof(GSM_ToDoEntry)); if (Backup.ToDo[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.ToDo[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_MAXCALENDARTODONOTES"); printf("\n"); break; } *Backup.ToDo[used]=ToDo; used ++; error=GSM_GetNextToDo(gsm,&ToDo,FALSE); fprintf(stderr, "\r "); fprintf(stderr, "%s ", _("Reading:")); fprintf(stderr, _("%i percent"), used * 100 / ToDoStatus.Used); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); } DoBackupPart = FALSE; if (Info.Note) { printf("%s\n", _("Checking phone notes")); Note.Location = 0; error=GSM_GetNextNote(gsm,&Note,TRUE); if (error==ERR_NONE) { if (answer_yes(" %s", _("Backup phone notes?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); while (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_NOTE) { Backup.Note[used] = malloc(sizeof(GSM_NoteEntry)); if (Backup.Note[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.Note[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_NOTE"); printf("\n"); break; } *Backup.Note[used]=Note; used ++; error=GSM_GetNextNote(gsm,&Note,FALSE); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.CallerLogos) { printf("%s\n", _("Checking phone caller logos")); Bitmap.Type = GSM_CallerGroupLogo; Bitmap.Location = 1; error=GSM_GetBitmap(gsm,&Bitmap); if (error == ERR_NONE) { if (answer_yes(" %s", _("Backup phone caller groups and logos?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; used = 0; while (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_CALLER) { Backup.CallerLogos[used] = malloc(sizeof(GSM_Bitmap)); if (Backup.CallerLogos[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.CallerLogos[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_CALLER"); printf("\n"); break; } *Backup.CallerLogos[used] = Bitmap; used ++; Bitmap.Location = used + 1; error=GSM_GetBitmap(gsm,&Bitmap); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.SMSC) { printf("%s\n", _("Checking SIM SMS profiles")); if (answer_yes(" %s", _("Backup SIM SMS profiles?"))) DoBackupPart = TRUE; } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); while (TRUE) { SMSC.Location = used + 1; error = GSM_GetSMSC(gsm,&SMSC); if (error != ERR_NONE) break; if (used < GSM_BACKUP_MAX_SMSC) { Backup.SMSC[used] = malloc(sizeof(GSM_SMSC)); if (Backup.SMSC[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.SMSC[used + 1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_SMSC"); printf("\n"); break; } *Backup.SMSC[used]=SMSC; used++; fprintf(stderr, "*"); } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.StartupLogo) { printf("%s\n", _("Checking phone startup text")); Bitmap.Type = GSM_WelcomeNote_Text; error = GSM_GetBitmap(gsm,&Bitmap); if (error == ERR_NONE) { if (answer_yes(" %s", _("Backup phone startup logo/text?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { Backup.StartupLogo = malloc(sizeof(GSM_Bitmap)); if (Backup.StartupLogo == NULL) Print_Error(ERR_MOREMEMORY); *Backup.StartupLogo = Bitmap; if (Bitmap.Text[0]==0 && Bitmap.Text[1]==0) { Bitmap.Type = GSM_StartupLogo; error = GSM_GetBitmap(gsm,&Bitmap); if (error == ERR_NONE) *Backup.StartupLogo = Bitmap; } } DoBackupPart = FALSE; if (Info.OperatorLogo) { printf("%s\n", _("Checking phone operator logo")); Bitmap.Type = GSM_OperatorLogo; error=GSM_GetBitmap(gsm,&Bitmap); if (error == ERR_NONE) { if (strcmp(Bitmap.NetworkCode,"000 00")!=0) { if (answer_yes(" %s", _("Backup phone operator logo?"))) DoBackupPart = TRUE; } } } if (DoBackupPart) { Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap)); if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY); *Backup.OperatorLogo = Bitmap; } DoBackupPart = FALSE; if (Info.WAPBookmark) { printf("%s\n", _("Checking phone WAP bookmarks")); Bookmark.Location = 1; error=GSM_GetWAPBookmark(gsm,&Bookmark); if (error==ERR_NONE) { if (answer_yes(" %s", _("Backup phone WAP bookmarks?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; while (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_WAPBOOKMARK) { Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark)); if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.WAPBookmark[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_WAPBOOKMARK"); printf("\n"); break; } *Backup.WAPBookmark[used]=Bookmark; used ++; Bookmark.Location = used+1; error=GSM_GetWAPBookmark(gsm,&Bookmark); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.WAPSettings) { printf("%s\n", _("Checking phone WAP settings")); Settings.Location = 1; error=GSM_GetWAPSettings(gsm,&Settings); if (error==ERR_NONE) { if (answer_yes(" %s", _("Backup phone WAP settings?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; while (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_WAPSETTINGS) { Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.WAPSettings[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_WAPSETTINGS"); printf("\n"); break; } *Backup.WAPSettings[used]=Settings; used ++; Settings.Location = used+1; error=GSM_GetWAPSettings(gsm,&Settings); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.MMSSettings) { printf("%s\n", _("Checking phone MMS settings")); Settings.Location = 1; error=GSM_GetMMSSettings(gsm,&Settings); if (error==ERR_NONE) { if (answer_yes(" %s", _("Backup phone MMS settings?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; while (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_MMSSETTINGS) { Backup.MMSSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); if (Backup.MMSSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.MMSSettings[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_MMSSETTINGS"); printf("\n"); break; } *Backup.MMSSettings[used]=Settings; used ++; Settings.Location = used+1; error=GSM_GetMMSSettings(gsm,&Settings); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.ChatSettings) { printf("%s\n", _("Checking phone Chat settings")); Chat.Location = 1; error=GSM_GetChatSettings(gsm,&Chat); if (error==ERR_NONE) { if (answer_yes(" %s", _("Backup phone Chat settings?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; while (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_CHATSETTINGS) { Backup.ChatSettings[used] = malloc(sizeof(GSM_ChatSettings)); if (Backup.ChatSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.ChatSettings[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_CHATSETTINGS"); printf("\n"); break; } *Backup.ChatSettings[used]=Chat; used ++; Chat.Location = used+1; error=GSM_GetChatSettings(gsm,&Chat); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.SyncMLSettings) { printf("%s\n", _("Checking phone SyncML settings")); SyncML.Location = 1; error=GSM_GetSyncMLSettings(gsm,&SyncML); if (error==ERR_NONE) { if (answer_yes(" %s", _("Backup phone SyncML settings?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); while (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_SYNCMLSETTINGS) { Backup.SyncMLSettings[used] = malloc(sizeof(GSM_SyncMLSettings)); if (Backup.SyncMLSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.SyncMLSettings[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_SYNCMLSETTINGS"); printf("\n"); break; } *Backup.SyncMLSettings[used]=SyncML; used ++; SyncML.Location = used+1; error=GSM_GetSyncMLSettings(gsm,&SyncML); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.Ringtone) { printf("%s\n", _("Checking phone user ringtones")); Ringtone.Location = 1; Ringtone.Format = 0; error=GSM_GetRingtone(gsm,&Ringtone,FALSE); if (error==ERR_EMPTY || error == ERR_NONE) { if (answer_yes(" %s", _("Backup phone user ringtones?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; i = 1; fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; while (error == ERR_NONE || error == ERR_EMPTY) { if (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_RINGTONES) { Backup.Ringtone[used] = malloc(sizeof(GSM_Ringtone)); if (Backup.Ringtone[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.Ringtone[used+1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_RINGTONES"); printf("\n"); break; } *Backup.Ringtone[used]=Ringtone; used ++; } i++; Ringtone.Location = i; Ringtone.Format = 0; error=GSM_GetRingtone(gsm,&Ringtone,FALSE); fprintf(stderr, "*"); if (gshutdown) { GSM_Terminate(); Terminate(4); } } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.Profiles) { printf("%s\n", _("Checking phone profiles")); Profile.Location = 1; error = GSM_GetProfile(gsm,&Profile); if (error == ERR_NONE) { if (answer_yes(" %s", _("Backup phone profiles?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; fprintf(stderr, LISTFORMAT, _("Reading")); while (TRUE) { Profile.Location = used + 1; error = GSM_GetProfile(gsm,&Profile); if (error != ERR_NONE) break; if (used < GSM_BACKUP_MAX_PROFILES) { Backup.Profiles[used] = malloc(sizeof(GSM_Profile)); if (Backup.Profiles[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.Profiles[used + 1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_PROFILES"); printf("\n"); break; } *Backup.Profiles[used]=Profile; used++; fprintf(stderr, "*"); } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.FMStation) { printf("%s\n", _("Checking phone FM radio stations")); FMStation.Location = 1; error = GSM_GetFMStation(gsm,&FMStation); if (error == ERR_NONE || error == ERR_EMPTY) { if (answer_yes(" %s", _("Backup phone FM radio stations?"))) DoBackupPart=TRUE; } } if (DoBackupPart) { used = 0; i = 1; fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; while (error == ERR_NONE || error == ERR_EMPTY) { error = GSM_GetFMStation(gsm,&FMStation); if (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_FMSTATIONS) { Backup.FMStation[used] = malloc(sizeof(GSM_FMStation)); if (Backup.FMStation[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.FMStation[used + 1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_FMSTATIONS"); printf("\n"); break; } *Backup.FMStation[used]=FMStation; used++; } i++; FMStation.Location = i; fprintf(stderr, "*"); } fprintf(stderr, "\n"); fflush(stderr); } DoBackupPart = FALSE; if (Info.GPRSPoint) { printf("%s\n", _("Checking phone GPRS access points")); GPRSPoint.Location = 1; error = GSM_GetGPRSAccessPoint(gsm,&GPRSPoint); if (error == ERR_NONE || error == ERR_EMPTY) { if (answer_yes(" %s", _("Backup phone GPRS access points?"))) DoBackupPart = TRUE; } } if (DoBackupPart) { used = 0; i = 1; fprintf(stderr, LISTFORMAT, _("Reading")); error = ERR_NONE; while (error == ERR_NONE || error == ERR_EMPTY) { error = GSM_GetGPRSAccessPoint(gsm,&GPRSPoint); if (error == ERR_NONE) { if (used < GSM_BACKUP_MAX_GPRSPOINT) { Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint)); if (Backup.GPRSPoint[used] == NULL) Print_Error(ERR_MOREMEMORY); Backup.GPRSPoint[used + 1] = NULL; } else { printf("\n "); printf(_("Only part of data saved, please increase %s.") , "GSM_BACKUP_MAX_GPRSPOINT"); printf("\n"); break; } *Backup.GPRSPoint[used]=GPRSPoint; used++; } i++; GPRSPoint.Location = i; fprintf(stderr, "*"); } fprintf(stderr, "\n"); fflush(stderr); } GSM_Terminate(); GSM_SaveBackupFile(argv[2], &Backup, GSM_GuessBackupFormat(argv[2], Info.UseUnicode)); GSM_FreeBackup(&Backup); }
/*************************************************************************************************** * Main section * ***************************************************************************************************/ void main(void) { WDTCTL = WDTPW | WDTHOLD; if(CALBC1_1MHZ==0xFF) { while(1); } DCOCTL = 0; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; // LED_DIR = (LED_0 ); //LEDs are set as output // LED_OUT &= ~(LED_0 ); //LEDs are turned off P1SEL |= BIT1 + BIT2; //Enable module function on pin P1SEL2 |= BIT1 + BIT2; //Select second module; P1.1 = RXD, P1.2=TXD UCA0CTL1 |= UCSSEL_2; // Set clock source SMCLK UCA0BR0 = 104; // 1MHz 9600 (N=BRCLK/baudrate) UCA0BR1 = 0; // 1MHz 9600 UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** IE2 |= UCA0RXIE; //enable RX interrupt __enable_interrupt(); // uint8 cntr = 0; // Initialize system Print_Error(System_Init()); while (1) { if (process == 1) { request = compareArrays(data_transmit_buffer, data_memory_buffer, data_slots); // request = critical_request(model_output); process = 0; } if (request == 1) { payload_length = 0; // Construct the packet // This is the place where you can put your own data to send TxPacket[payload_length++] = PKT_CTRL | PKT_CTRL_REQUEST; TxPacket[payload_length++] = 'S'; TxPacket[payload_length++] = data_transmit_buffer[0]; TxPacket[payload_length++] = data_transmit_buffer[1]; TxPacket[payload_length++] = data_transmit_buffer[2]; TxPacket[payload_length++] = data_transmit_buffer[3]; TxPacket[payload_length++] = data_transmit_buffer[4]; TxPacket[payload_length++] = data_transmit_buffer[5]; // Send data over RF and get the exit code to check for errors exit_code = Radio_Send_Data(TxPacket, payload_length, ADDR_REMOTE, PAYLOAD_ENC_OFF, PCKT_ACK_ON); // Add some delay (around 2sec) __delay_cycles(5000000*SYSTEM_SPEED_MHZ); request = 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(); }
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(); }
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(); }