8 #include "../../phone/nokia/nfunc.h" 9 #include "../../misc/coding/coding.h" 10 #include "../gsmlogo.h" 11 #include "../gsmmisc.h" 12 #include "../../debug.h" 14 #include "../../gsmphones.h" 16 #ifdef GSM_ENABLE_BACKUP 21 #define chk_fwrite(data, size, count, file) \ 22 if (fwrite(data, size, count, file) != count) goto fail; 58 req[4]=(count-12)%256;
59 req[5]=(count-12)/256;
69 size_t count = 12, textlen;
82 req[count++] = textlen;
91 if (bitmap->
BitmapEnabled) req[count++] = 0x01;
else req[count++] = 0x00;
102 req[4]=(count-12)%256;
103 req[5]=(count-12)/256;
115 size_t count = 16, blocks;
133 req[4]=(count-12)%256;
134 req[5]=(count-12)/256;
135 req[8]=req[12] = entry->
Location & 0xff;
136 req[9]=req[13] = (entry->
Location >> 8);
147 GSM_Error SaveLMB(
const char *FileName, GSM_Backup *backup)
151 char LMBHeader[] = {
'L',
'M',
'B',
' '};
164 file = fopen(FileName,
"wb");
168 chk_fwrite(LMBHeader, 1,
sizeof(LMBHeader), file);
170 if (backup->PhonePhonebook[0]!=NULL) {
172 PBKHeader[12] = (
unsigned char)(500 % 256);
173 PBKHeader[13] = 500 / 256;
174 chk_fwrite(PBKHeader, 1,
sizeof(PBKHeader), file);
176 while (backup->PhonePhonebook[i]!=NULL) {
177 error = SaveLMBPBKEntry(file, backup->PhonePhonebook[i]);
185 if (backup->SIMPhonebook[0]!=NULL) {
187 PBKHeader[12] = (
unsigned char)(250 % 256);
188 PBKHeader[13] = 250 / 256;
189 PBKHeader[14] = 0x16;
190 chk_fwrite(PBKHeader, 1,
sizeof(PBKHeader), file);
192 while (backup->SIMPhonebook[i]!=NULL) {
193 error = SaveLMBPBKEntry(file, backup->SIMPhonebook[i]);
202 while (backup->CallerLogos[i]!=NULL) {
203 error = SaveLMBCallerEntry(file, backup->CallerLogos[i]);
210 if (backup->StartupLogo!=NULL) {
211 error = SaveLMBStartupEntry(file, backup->StartupLogo);
225 static GSM_Error LoadLMBCallerEntry(
unsigned char *buffer
UNUSED,
unsigned char *buffer2, GSM_Backup *backup)
231 dbgprintf(NULL,
"Number %i, name \"", buffer2[0]+1);
232 for (num=0;num<buffer2[1];num++)
dbgprintf(NULL,
"%c", buffer2[num+2]);
234 dbgprintf(NULL,
"Ringtone ID=%i\n", buffer2[num+2]);
235 if (buffer2[num+3]==1) {
250 if (bitmap.
Text[0] == 0x00 && bitmap.
Text[1] == 0x00) {
269 while (backup->CallerLogos[num] != NULL) num++;
270 if (num < GSM_BACKUP_MAX_CALLER) {
273 backup->CallerLogos[num + 1] = NULL;
275 dbgprintf(NULL,
"Increase GSM_BACKUP_MAX_CALLER\n");
278 *backup->CallerLogos[num] = bitmap;
283 static GSM_Error LoadLMBStartupEntry(
unsigned char *buffer UNUSED,
unsigned char *buffer2, GSM_Backup *backup)
292 for (i=0;i<buffer2[0];i++) {
293 switch (buffer2[j++]) {
295 dbgprintf(NULL,
"Block 1 - startup logo\n");
298 backup->StartupLogo->Location = 1;
299 backup->StartupLogo->BitmapHeight = buffer2[j++];
300 backup->StartupLogo->BitmapWidth = buffer2[j++];
302 switch (backup->StartupLogo->BitmapHeight) {
315 dbgprintf(NULL,
"Block 2 - welcome note \"");
316 for (z=0;z<buffer2[j];z++)
dbgprintf(NULL,
"%c",buffer2[j+z+1]);
319 if (backup->StartupLogo == NULL) {
323 EncodeUnicode(backup->StartupLogo->Text,buffer2+j,buffer2[j]);
328 dbgprintf(NULL,
"Unknown block %02x\n",buffer2[j]);
335 static GSM_Error LoadLMBPbkEntry(
unsigned char *buffer,
unsigned char *buffer2, GSM_Backup *backup)
360 pbk.
Location = buffer2[0] + buffer2[1] * 256;
368 pbk.
Location=buffer2[0]+256*buffer2[1];
372 while (backup->PhonePhonebook[num] != NULL) num++;
373 if (num < GSM_BACKUP_MAX_PHONEPHONEBOOK) {
375 if (backup->PhonePhonebook[num] == NULL) {
379 backup->PhonePhonebook[num + 1] = NULL;
382 dbgprintf(NULL,
"Increase GSM_BACKUP_MAX_PHONEPHONEBOOK\n");
385 *backup->PhonePhonebook[num] = pbk;
387 while (backup->SIMPhonebook[num] != NULL) num++;
388 if (num < GSM_BACKUP_MAX_SIMPHONEBOOK) {
390 if (backup->SIMPhonebook[num] == NULL) {
394 backup->SIMPhonebook[num + 1] = NULL;
396 dbgprintf(NULL,
"Increase GSM_BACKUP_MAX_SIMPHONEBOOK\n");
400 *backup->SIMPhonebook[num] = pbk;
406 GSM_Error LoadLMB(
const char *FileName, GSM_Backup *backup)
411 unsigned char buffer[12], buffer2[1000];
416 file = fopen(FileName,
"rb");
420 if (fread(buffer, 1, 4, file) != 4) {
426 while (fread(buffer, 1, 12, file) == 12) {
430 for (i=0;i<4;i++) {
dbgprintf(NULL,
"%c",buffer[i]);}
432 if (memcmp(buffer,
"PBK ",4)==0) {
dbgprintf(NULL,
"Phonebook");
433 }
else if (memcmp(buffer,
"PBE2",4)==0) {
dbgprintf(NULL,
"Phonebook entry");
434 }
else if (memcmp(buffer,
"CGR ",4)==0) {
dbgprintf(NULL,
"Caller group");
435 }
else if (memcmp(buffer,
"SPD ",4)==0) {
dbgprintf(NULL,
"Speed dial");
436 }
else if (memcmp(buffer,
"OLG ",4)==0) {
dbgprintf(NULL,
"Operator logo");
437 }
else if (memcmp(buffer,
"WEL ",4)==0) {
dbgprintf(NULL,
"Startup logo and welcome text");
438 }
else {
dbgprintf(NULL,
"unknown - ignored");
440 dbgprintf(NULL,
") - length %i\n", buffer[4]+buffer[5]*256);
443 blocksize = buffer[4] + buffer[5] * 256;
444 if (blocksize >
sizeof(buffer2)) {
445 dbgprintf(NULL,
"Too big block size!\n");
449 if (fread(buffer2, 1, blocksize, file) != blocksize) {
455 if (memcmp(buffer,
"PBK ",4)==0) {
456 dbgprintf(NULL,
"Size of phonebook %i, type %i ",(buffer2[0]+buffer2[1]*256),buffer[8]);
458 case 2 :
dbgprintf(NULL,
"(internal)");
break;
459 case 3 :
dbgprintf(NULL,
"(sim)") ;
break;
460 default:
dbgprintf(NULL,
"(unknown)") ;
break;
462 dbgprintf(NULL,
", length of each position - %i\n",buffer2[2]);
465 if (memcmp(buffer,
"PBE2",4)==0) {
466 error = LoadLMBPbkEntry(buffer,buffer2,backup);
472 if (memcmp(buffer,
"CGR ",4)==0) {
473 error = LoadLMBCallerEntry(buffer, buffer2, backup);
479 if (memcmp(buffer,
"WEL ",4)==0) {
480 error = LoadLMBStartupEntry(buffer, buffer2, backup);
char * DecodeUnicodeString(const unsigned char *src)
size_t PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, size_t Width, size_t Height)
GSM_StateMachine * GSM_AllocStateMachine(void)
GSM_MemoryType MemoryType
gboolean FileSystemRingtone
void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
size_t UnicodeLength(const unsigned char *str)
void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
#define chk_fwrite(data, size, count, file)
GSM_PhoneModel * ModelInfo
void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, size_t *Length)
void GSM_PrintBitmap(FILE *file, GSM_Bitmap *bitmap)
GSM_Debug_Info GSM_global_debug
GSM_PhoneModel * GetModelData(GSM_StateMachine *s, const char *model, const char *number, const char *irdamodel)
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, GSM_MemoryEntry *entry, GSM_Bitmap *bitmap, GSM_SpeedDial *speed, unsigned char *MessageBuffer, int MessageLength, gboolean DayMonthReverse)
void GSM_ClearBitmap(GSM_Bitmap *bmp)
size_t N71_65_EncodePhonebookFrame(GSM_StateMachine *s, unsigned char *req, GSM_MemoryEntry *entry, size_t *block2, gboolean DCT4, gboolean VoiceTag)
unsigned char Text[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
void GSM_FreeStateMachine(GSM_StateMachine *s)