Gammu internals  1.38.0
nfunc.c File Reference
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <gammu-nokia.h>
#include "../../gsmstate.h"
#include "../../gsmphones.h"
#include "../../misc/coding/coding.h"
#include "../../misc/locales.h"
#include "../../service/gsmnet.h"
#include "../../service/gsmlogo.h"
#include "../../service/gsmcal.h"
#include "../pfunc.h"
#include "nfunc.h"
Include dependency graph for nfunc.c:

Go to the source code of this file.

Functions

size_t N71_65_PackPBKBlock (GSM_StateMachine *s, int id, size_t size, int no, unsigned char *buf, unsigned char *block)
 
size_t N71_65_EncodePhonebookFrame (GSM_StateMachine *s, unsigned char *req, GSM_MemoryEntry *entry, size_t *block2, gboolean DCT4, gboolean VoiceTag)
 
static gboolean N71_65_PB_CopyString (GSM_StateMachine *s, GSM_MemoryEntry *entry, const unsigned char *src, unsigned char length)
 
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 NOKIA_GetDefaultCallerGroupName (GSM_Bitmap *Bitmap)
 
void NOKIA_DecodeDateTime (GSM_StateMachine *s, unsigned char *buffer, GSM_DateTime *datetime, gboolean seconds, gboolean DayMonthReverse)
 
void NOKIA_EncodeDateTime (GSM_StateMachine *s UNUSED, unsigned char *buffer, GSM_DateTime *datetime)
 

Variables

unsigned char N71_65_MEMORY_TYPES []
 

Function Documentation

§ N71_65_DecodePhonebook()

GSM_Error N71_65_DecodePhonebook ( GSM_StateMachine s,
GSM_MemoryEntry entry,
GSM_Bitmap bitmap,
GSM_SpeedDial speed,
unsigned char *  MessageBuffer,
int  MessageLength,
gboolean  DayMonthReverse 
)

Decodes nokia phonebook.

Bug:
Type casting MemoryType to int is ugly.

Definition at line 364 of file nfunc.c.

References GSM_SubMemoryEntry::AddError, GSM_Bitmap::BitmapEnabled, GSM_SubMemoryEntry::CallLength, CheckDate(), CopyUnicodeString(), GSM_Phone::Data, GSM_SubMemoryEntry::Date, DecodeUnicodeString(), GSM_Bitmap::DefaultBitmap, GSM_Bitmap::DefaultName, GSM_Bitmap::DefaultRingtone, _GSM_StateMachine::di, _GSM_Debug_Info::dl, DL_TEXTALL, DL_TEXTALLDATE, DumpMessage(), EncodeUnicode(), GSM_MemoryEntry::Entries, GSM_MemoryEntry::EntriesNum, GSM_SubMemoryEntry::EntryType, ERR_EMPTY, ERR_MOREMEMORY, ERR_NONE, ERR_UNKNOWNRESPONSE, F_6230iCALLER, FALSE, GSM_Bitmap::FileSystemPicture, GSM_Bitmap::FileSystemRingtone, GSM_GetDI(), GSM_IsPhoneFeatureAvailable(), GSM_NokiaCallerLogo, GSM_PHONEBOOK_ENTRIES, GSM_PHONEBOOK_TEXT_LENGTH, GSM_SubMemoryEntry::Location, MEM6510_CG2, MEM7110_CG, MEM7110_SP, MEM_ME, MEM_SM, GSM_SpeedDial::MemoryLocation, GSM_SpeedDial::MemoryNumberID, GSM_MemoryEntry::MemoryType, GSM_SpeedDial::MemoryType, GSM_Phone_Data::ModelInfo, N2630_PBK_FAVMESSAGING, N3600_PBK_UNKNOWN1, N6303_PBK_UNKNOWN1, N6303_PBK_UNKNOWN2, N6510_PBK_GROUP2_ID, N6510_PBK_PICTURE_ID, N6510_PBK_PUSHTOTALK_ID, N6510_PBK_RINGTONEFILE_ID, N6510_PBK_SMSLIST_ID, N6510_PBK_UNKNOWN2, N6510_PBK_UNKNOWN3, N6510_PBK_UNKNOWN4, N6510_PBK_UNKNOWN5, N6510_PBK_URL, N6510_PBK_USER_ID, N6510_PBK_VOICETAG_ID, N7110_PBK_DATETIME, N7110_PBK_EMAIL, N7110_PBK_GROUP, N7110_PBK_GROUPLOGO, N7110_PBK_LOGOON, N7110_PBK_MISSED, N7110_PBK_NAME, N7110_PBK_NOTE, N7110_PBK_NUMBER, N7110_PBK_NUMBER_FAX, N7110_PBK_NUMBER_GENERAL, N7110_PBK_NUMBER_HOME, N7110_PBK_NUMBER_MOBILE, N7110_PBK_NUMBER_WORK, N7110_PBK_POSTAL, N7110_PBK_RINGTONE_ID, N7110_PBK_SIM_SPEEDDIAL, N7110_PBK_SPEEDDIAL, N7110_PBK_UNKNOWN2, N7110_PBK_UNKNOWN3, N71_65_PB_CopyString(), NOKIA_DecodeDateTime(), GSM_SubMemoryEntry::Number, PBK_Caller_Group, PBK_CallLength, PBK_Date, PBK_Location_Home, PBK_Location_Unknown, PBK_Location_Work, PBK_Number_Fax, PBK_Number_General, PBK_Number_Messaging, PBK_Number_Mobile, PBK_PictureID, PBK_PushToTalkID, PBK_RingtoneID, PBK_Text_City, PBK_Text_Company, PBK_Text_Country, PBK_Text_Custom1, PBK_Text_Email, PBK_Text_FirstName, PBK_Text_FormalName, PBK_Text_JobTitle, PBK_Text_LastName, PBK_Text_Name, PBK_Text_NickName, PBK_Text_Note, PBK_Text_Postal, PBK_Text_State, PBK_Text_StreetAddress, PBK_Text_URL, PBK_Text_UserID, _GSM_StateMachine::Phone, PHONE_DecodeBitmap(), GSM_Bitmap::PictureID, GSM_Bitmap::RingtoneID, S4030_PBK_BIRTHDAY, S4030_PBK_CALLLENGTH, S4030_PBK_COMPANY, S4030_PBK_FIRSTNAME, S4030_PBK_FORMALNAME, S4030_PBK_JOBTITLE, S4030_PBK_LASTNAME, S4030_PBK_NICKNAME, S4030_PBK_POSTAL, S4030_PBK_POSTAL_CITY, S4030_PBK_POSTAL_COUNTRY, S4030_PBK_POSTAL_EXTADDRESS, S4030_PBK_POSTAL_POSTAL, S4030_PBK_POSTAL_STATE, S4030_PBK_POSTAL_STREET, smprintf(), GSM_SubMemoryEntry::SMSList, GSM_Bitmap::Text, GSM_SubMemoryEntry::Text, TRUE, and GSM_SubMemoryEntry::VoiceTag.

371 {
372  unsigned char *Block;
373  int length = 0, i, bs = 0;
374  GSM_EntryType Type;
376  gboolean found=FALSE;
377  gboolean foundbb5add=FALSE;
378  gboolean missed_call = FALSE;
379  int favorite_messaging_numbers[10];
380  size_t used_favorite_messaging_numbers = 0;
381 
382  entry->EntriesNum = 0;
383 
384  if ((int)entry->MemoryType==MEM7110_CG) {
385  bitmap->Text[0] = 0x00;
386  bitmap->Text[1] = 0x00;
387  bitmap->DefaultBitmap = TRUE;
388  bitmap->DefaultRingtone = TRUE;
389  bitmap->FileSystemPicture = FALSE;
390  }
392  bitmap->DefaultName = FALSE;
393  bitmap->DefaultBitmap = TRUE;
394  bitmap->DefaultRingtone = TRUE;
395  bitmap->FileSystemPicture = FALSE;
396  }
397 
398  Block = &MessageBuffer[0];
399  while (TRUE) {
400  entry->Entries[entry->EntriesNum].AddError = ERR_NONE;
401  entry->Entries[entry->EntriesNum].SMSList[0] = 0;
402  entry->Entries[entry->EntriesNum].VoiceTag = 0;
403  if (bs != 0) {
404  length = length + bs;
405  /* bb5 */
406  if (length >= MessageLength-1) break;
407  Block = &Block[bs];
408  }
409  bs = 256*Block[2]+Block[3];
410  if (bs == 0) break;
411 #ifdef DEBUG
412  smprintf(s, "Phonebook entry block 0x%02x - length %i\n",
413  Block[0], bs-6);
414  if (GSM_GetDI(s)->dl == DL_TEXTALL || GSM_GetDI(s)->dl == DL_TEXTALLDATE)
415  DumpMessage(&s->di, Block+0, bs-1);
416 #endif
417  if (entry->EntriesNum==GSM_PHONEBOOK_ENTRIES) {
418  smprintf(s, "Too many entries\n");
419  return ERR_UNKNOWNRESPONSE;
420  }
421 
422  Type = 0;
423  if (Block[0] == S4030_PBK_FIRSTNAME) {
424  Type = PBK_Text_FirstName; smprintf(s,"First name ");
425  }
426  if (Block[0] == S4030_PBK_LASTNAME) {
427  Type = PBK_Text_LastName; smprintf(s,"Last name ");
428  }
429  if (Type != 0) {
430  found=TRUE;
431  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
432  return ERR_UNKNOWNRESPONSE;
433  entry->Entries[entry->EntriesNum].EntryType=Type;
435  entry->EntriesNum ++;
436  }
437  }
438 
439  Block = &MessageBuffer[0];
440  bs=0;
441  length=0;
442  while (TRUE) {
443  entry->Entries[entry->EntriesNum].AddError = ERR_NONE;
444  entry->Entries[entry->EntriesNum].SMSList[0] = 0;
445  entry->Entries[entry->EntriesNum].VoiceTag = 0;
446  if (bs != 0) {
447  length = length + bs;
448  if (length >= MessageLength-1) break;
449  Block = &Block[bs];
450  }
451  bs = 256*Block[2]+Block[3];
452  smprintf(s, "Phonebook entry block 0x%02x - length %i\n",
453  Block[0], bs-6);
454  if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXTALLDATE) {
455  DumpMessage(&s->di, Block+0, bs-1);
456  }
457  if (entry->EntriesNum >= GSM_PHONEBOOK_ENTRIES) {
458  smprintf(s, "Too many entries\n");
459  return ERR_MOREMEMORY;
460  }
461 
462  Type = 0;
463  if (Block[0] == N7110_PBK_NAME) {
464  if (found) continue;
465  Type = PBK_Text_Name; smprintf(s,"Name ");
466  }
467  if (Block[0] == S4030_PBK_FIRSTNAME) continue;
468  if (Block[0] == S4030_PBK_LASTNAME) continue;
469  if (Block[0] == N7110_PBK_EMAIL) {
470  Type = PBK_Text_Email; smprintf(s,"Email ");
471  }
472  if (Block[0] == N7110_PBK_POSTAL) {
473  Type = PBK_Text_Postal; smprintf(s,"Postal ");
474  }
475  if (Block[0] == N7110_PBK_NOTE) {
476  Type = PBK_Text_Note; smprintf(s,"Text note ");
477  }
478  if (Block[0] == N6510_PBK_URL) {
479  Type = PBK_Text_URL; smprintf(s,"URL ");
480  }
481  if (Block[0] == N6510_PBK_USER_ID) {
482  Type = PBK_Text_UserID; smprintf(s,"User ID:");
483  }
484  if (Type != 0) {
485  if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) {
486  smprintf(s, "Too long text\n");
487  return ERR_UNKNOWNRESPONSE;
488  }
489  /* No text? */
490  if (Block[5] < 2) {
491  entry->Entries[entry->EntriesNum].Text[0] = 0;
492  entry->Entries[entry->EntriesNum].Text[1] = 0;
493  } else {
494  memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]);
495  /* Zero terminate the string */
496  entry->Entries[entry->EntriesNum].Text[Block[5]] = 0;
497  entry->Entries[entry->EntriesNum].Text[Block[5] + 1] = 0;
498  }
499  entry->Entries[entry->EntriesNum].EntryType=Type;
501  smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
502  if (Block[0] == N7110_PBK_NAME) {
503  if ((int)entry->MemoryType == MEM7110_CG || (int)entry->MemoryType == MEM6510_CG2) {
504  /* No text? */
505  if (Block[5] < 2) {
506  bitmap->Text[0] = 0;
507  bitmap->Text[1] = 0;
508  } else {
509  memcpy(bitmap->Text,Block+6,Block[5]);
510  }
511  }
512  }
513  entry->EntriesNum ++;
514  continue;
515  }
516  if (Block[0] == N7110_PBK_DATETIME) {
517  entry->Entries[entry->EntriesNum].EntryType=PBK_Date;
519  NOKIA_DecodeDateTime(s, Block+6, &entry->Entries[entry->EntriesNum].Date, TRUE, DayMonthReverse);
520  if (CheckDate(&entry->Entries[entry->EntriesNum].Date) &&
521  CheckDate(&entry->Entries[entry->EntriesNum].Date)) {
522  entry->EntriesNum ++;
523  } else {
524  smprintf(s, "Datetime seems to be invalid, ignoring!\n");
525  }
526  continue;
527  }
528  if (Block[0] == N6510_PBK_PICTURE_ID) {
529  if ((int)entry->MemoryType==MEM6510_CG2) {
530  bitmap->FileSystemPicture = TRUE;
531  smprintf(s, "Picture ID \"%i\"\n",Block[10]*256+Block[11]);
532  bitmap->PictureID = Block[10]*256+Block[11];
533  } else {
534  entry->Entries[entry->EntriesNum].EntryType=PBK_PictureID;
536  smprintf(s, "Picture ID \"%i\"\n",Block[10]*256+Block[11]);
537  entry->Entries[entry->EntriesNum].Number=Block[10]*256+Block[11];
538  entry->EntriesNum ++;
539  }
540  continue;
541  }
542  if (Block[0] == N7110_PBK_NUMBER) {
543  if (Block[5] == 0x00) {
544  Type = PBK_Number_General; smprintf(s,"General number ");
545  }
546  /* Not assigned dialed number */
547  if (Block[5] == 0x01) {
548  Type = PBK_Number_General; smprintf(s,"General number ");
549  }
550  if (Block[5] == 0x0B) {
551  Type = PBK_Number_General; smprintf(s,"General number ");
552  }
553  /* In many firmwares 0x55 visible after using
554  * Save from Call Register menu and saving number
555  * to existing phonebook entry */
556  if (Block[5] == 0x55) {
557  Type = PBK_Number_General; smprintf(s,"General number ");
558  }
559  /* Yet another unknown General number */
560  if (Block[5] == 0x08) {
561  Type = PBK_Number_General; smprintf(s,"General number ");
562  }
563  if (Block[5] == N7110_PBK_NUMBER_GENERAL) {
564  Type = PBK_Number_General; smprintf(s,"General number ");
565  }
566  if (Block[5] == N7110_PBK_NUMBER_WORK) {
567  Type = PBK_Number_General; Location = PBK_Location_Work; smprintf(s,"Work number ");
568  }
569  if (Block[5] == N7110_PBK_NUMBER_FAX) {
570  Type = PBK_Number_Fax; smprintf(s,"Fax number ");
571  }
572  if (Block[5] == N7110_PBK_NUMBER_MOBILE) {
573  Type = PBK_Number_Mobile; smprintf(s,"Mobile number ");
574  }
575  if (Block[5] == N7110_PBK_NUMBER_HOME) {
576  Type = PBK_Number_General; Location = PBK_Location_Home; smprintf(s,"Home number ");
577  }
578  if (Type == 0x00) {
579  smprintf(s, "Unknown number type %02x\n",Block[5]);
580  return ERR_UNKNOWNRESPONSE;
581  }
582  entry->Entries[entry->EntriesNum].EntryType=Type;
583  entry->Entries[entry->EntriesNum].Location = Location;
584  if (! N71_65_PB_CopyString(s, entry, Block+10, Block[9]))
585  return ERR_UNKNOWNRESPONSE;
586  /* DCT3 phones like 6210 */
587  entry->Entries[entry->EntriesNum].VoiceTag = Block[7];
588 #ifdef DEBUG
589  if (entry->Entries[entry->EntriesNum].VoiceTag != 0) smprintf(s, "Voice tag %i assigned\n",Block[7]);
590 #endif
591  entry->Entries[entry->EntriesNum].SMSList[0] = 0;
592  entry->EntriesNum ++;
593  continue;
594  }
595  /* to checking */
596  if (Block[0] == S4030_PBK_CALLLENGTH) {
597  entry->Entries[entry->EntriesNum].CallLength = Block[9]*256*256+Block[10]*256+Block[11];
600  entry->EntriesNum ++;
601  continue;
602  }
603  if (Block[0] == S4030_PBK_POSTAL) {
604  if (Block[5] == S4030_PBK_POSTAL_EXTADDRESS) {
605  Type = PBK_Text_Custom1; smprintf(s,"Address extension ? ");
606  }
607  if (Block[5] == S4030_PBK_POSTAL_STREET) {
608  Type = PBK_Text_StreetAddress; smprintf(s,"Street ");
609  }
610  if (Block[5] == S4030_PBK_POSTAL_CITY) {
611  Type = PBK_Text_City; smprintf(s,"City ");
612  }
613  if (Block[5] == S4030_PBK_POSTAL_STATE) {
614  Type = PBK_Text_State; smprintf(s,"State ");
615  }
616  if (Block[5] == S4030_PBK_POSTAL_POSTAL) {
617  Type = PBK_Text_Postal; smprintf(s,"Postal ");
618  }
619  if (Block[5] == S4030_PBK_POSTAL_COUNTRY) {
620  Type = PBK_Text_Country; smprintf(s,"Country ");
621  }
622  if ((Type == 0x00) && (Block[7]>0)) {
623  smprintf(s, "Found new bb5 style address\n");
624  foundbb5add=TRUE;
625  continue;
626  }
627  if (Type == 0x00) {
628  smprintf(s, "Unknown address type %02x\n",Block[5]);
629  return ERR_UNKNOWNRESPONSE;
630  }
631  entry->Entries[entry->EntriesNum].EntryType=Type;
633  if (! N71_65_PB_CopyString(s, entry, Block+10, Block[9]))
634  return ERR_UNKNOWNRESPONSE;
635  entry->EntriesNum ++;
636  continue;
637  }
638 
639 
640  if ((Block[0] == S4030_PBK_POSTAL_EXTADDRESS) && (foundbb5add==TRUE)) {
641  Type = PBK_Text_Custom1; smprintf(s,"Address extension ? ");
642  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
643  return ERR_UNKNOWNRESPONSE;
644  entry->Entries[entry->EntriesNum].EntryType=Type;
646  entry->EntriesNum ++;
647  continue;
648  }
649  if ((Block[0] == S4030_PBK_POSTAL_STREET) && (foundbb5add==TRUE)) {
650  Type = PBK_Text_StreetAddress; smprintf(s,"Street ");
651  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
652  return ERR_UNKNOWNRESPONSE;
653  entry->Entries[entry->EntriesNum].EntryType=Type;
655  entry->EntriesNum ++;
656  continue;
657  }
658  if ((Block[0] == S4030_PBK_POSTAL_CITY) && (foundbb5add==TRUE)) {
659  Type = PBK_Text_City; smprintf(s,"City ");
660  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
661  return ERR_UNKNOWNRESPONSE;
662  entry->Entries[entry->EntriesNum].EntryType=Type;
664  entry->EntriesNum ++;
665  continue;
666  }
667  if ((Block[0] == S4030_PBK_POSTAL_STATE) && (foundbb5add==TRUE)) {
668  Type = PBK_Text_State; smprintf(s,"State ");
669  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
670  return ERR_UNKNOWNRESPONSE;
671  entry->Entries[entry->EntriesNum].EntryType=Type;
673  entry->EntriesNum ++;
674  continue;
675  }
676  if ((Block[0] == S4030_PBK_POSTAL_POSTAL) && (foundbb5add==TRUE)) {
677  Type = PBK_Text_Postal; smprintf(s,"Postal ");
678  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
679  return ERR_UNKNOWNRESPONSE;
680  entry->Entries[entry->EntriesNum].EntryType=Type;
682  entry->EntriesNum ++;
683  continue;
684  }
685  if ((Block[0] == S4030_PBK_POSTAL_COUNTRY) && (foundbb5add==TRUE)) {
686  Type = PBK_Text_Country; smprintf(s,"Country ");
687  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
688  return ERR_UNKNOWNRESPONSE;
689  entry->Entries[entry->EntriesNum].EntryType=Type;
691  entry->EntriesNum ++;
692  continue;
693  }
694  if (Block[0] == S4030_PBK_FORMALNAME) {
695  Type = PBK_Text_FormalName; smprintf(s,"FormalName ");
696  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
697  return ERR_UNKNOWNRESPONSE;
698  entry->Entries[entry->EntriesNum].EntryType=Type;
700  entry->EntriesNum ++;
701  continue;
702  }
703  if (Block[0] == S4030_PBK_JOBTITLE) {
704  Type = PBK_Text_JobTitle; smprintf(s,"JobTitle ");
705  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
706  return ERR_UNKNOWNRESPONSE;
707  entry->Entries[entry->EntriesNum].EntryType=Type;
709  entry->EntriesNum ++;
710  continue;
711  }
712  if (Block[0] == S4030_PBK_COMPANY) {
713  Type = PBK_Text_Company; smprintf(s,"Company ");
714  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
715  return ERR_UNKNOWNRESPONSE;
716  entry->Entries[entry->EntriesNum].EntryType=Type;
718  entry->EntriesNum ++;
719  continue;
720  }
721  if (Block[0] == S4030_PBK_NICKNAME) {
722  Type = PBK_Text_NickName; smprintf(s,"NickName ");
723  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
724  return ERR_UNKNOWNRESPONSE;
725  entry->Entries[entry->EntriesNum].EntryType=Type;
727  entry->EntriesNum ++;
728  continue;
729  }
730  if (Block[0] == S4030_PBK_BIRTHDAY) {
731  entry->Entries[entry->EntriesNum].EntryType=PBK_Date;
733  NOKIA_DecodeDateTime(s, Block+6, &entry->Entries[entry->EntriesNum].Date, FALSE, DayMonthReverse);
734  entry->EntriesNum ++;
735  continue;
736  }
737 
738 
739  if (Block[0] == N7110_PBK_RINGTONE_ID) {
740  if ((int)entry->MemoryType==MEM7110_CG) {
741  bitmap->RingtoneID=Block[5];
742  if (Block[5] == 0x00) bitmap->RingtoneID=Block[7];
743  smprintf(s, "Ringtone ID : %i\n",bitmap->RingtoneID);
744  bitmap->DefaultRingtone = FALSE;
745  bitmap->FileSystemRingtone = FALSE;
746  } else {
749  smprintf(s, "Ringtone ID \"%i\"\n",Block[7]);
750  entry->Entries[entry->EntriesNum].Number=Block[7];
751  entry->EntriesNum ++;
752  }
753  continue;
754  }
755  if (Block[0] == N7110_PBK_LOGOON) {
756  if ((int)entry->MemoryType==MEM7110_CG) {
757  bitmap->BitmapEnabled=(Block[5]==0x00 ? FALSE : TRUE);
758  smprintf(s, "Logo : %s\n", bitmap->BitmapEnabled==TRUE ? "enabled":"disabled");
759  } else {
760  return ERR_UNKNOWNRESPONSE;
761  }
762  continue;
763  }
764  if (Block[0] == N7110_PBK_GROUPLOGO) {
765  if ((int)entry->MemoryType==MEM7110_CG) {
766  smprintf(s, "Caller logo\n");
767  PHONE_DecodeBitmap(GSM_NokiaCallerLogo, Block+10, bitmap);
768  bitmap->DefaultBitmap = FALSE;
769  } else {
770  return ERR_UNKNOWNRESPONSE;
771  }
772  continue;
773  }
774  if (Block[0] == N7110_PBK_GROUP) {
777  smprintf(s, "Caller group \"%i\"\n",Block[5]);
778  entry->Entries[entry->EntriesNum].Number=Block[5];
779  if (Block[5]!=0) entry->EntriesNum ++;
780  continue;
781  }
782  if (Block[0] == N6510_PBK_VOICETAG_ID) {
783  smprintf(s, "Entry %i has voice tag %i\n",Block[5]-1,Block[7]);
784  entry->Entries[entry->EntriesNum].VoiceTag = Block[7];
785  continue;
786  }
787 
788  /* 6210 5.56, SIM speed dials or ME with 1 number */
789  if (Block[0] == N7110_PBK_SIM_SPEEDDIAL) {
790  if ((int)entry->MemoryType==MEM7110_SP) {
791 #ifdef DEBUG
792  smprintf(s, "location %i\n",(Block[6]*256+Block[7]));
793 #endif
794  speed->MemoryType = MEM_ME;
795  if (Block[8] == 0x06) speed->MemoryType = MEM_SM;
796  speed->MemoryLocation = (Block[6]*256+Block[7]);
797  speed->MemoryNumberID = 2;
798  } else {
799  return ERR_UNKNOWNRESPONSE;
800  }
801  continue;
802  }
803 
804  if (Block[0] == N7110_PBK_SPEEDDIAL) {
805  if ((int)entry->MemoryType==MEM7110_SP) {
806 #ifdef DEBUG
807  switch (Block[12]) {
808  case 0x05: smprintf(s, "ME\n"); break;
809  case 0x06: smprintf(s, "SM\n"); break;
810  default : smprintf(s, "%02x\n",Block[12]);
811  }
812  smprintf(s, "location %i, number %i in location\n",
813  (Block[6]*256+Block[7])-1,Block[14]);
814 #endif
815  switch (Block[12]) {
816  case 0x05: speed->MemoryType = MEM_ME; break;
817  case 0x06: speed->MemoryType = MEM_SM; break;
818  }
819  speed->MemoryLocation = (Block[6]*256+Block[7])-1;
820  speed->MemoryNumberID = Block[14];
821  } else {
822  return ERR_UNKNOWNRESPONSE;
823  }
824  continue;
825  }
826  if (Block[0] == N6510_PBK_RINGTONEFILE_ID) {
827  smprintf(s, "Ringtone ID with possibility of using filesystem\n");
828  if ((int)entry->MemoryType==MEM7110_CG) {
829  if (Block[9] == 0x01) {
830  smprintf(s, "Filesystem ringtone ID: %02x\n",Block[10]*256+Block[11]);
831  bitmap->FileSystemRingtone = TRUE;
832  } else {
833  smprintf(s, "Internal ringtone ID: %02x\n",Block[10]*256+Block[11]);
834  bitmap->FileSystemRingtone = FALSE;
835  }
836  bitmap->RingtoneID = Block[10]*256+Block[11];
837  bitmap->DefaultRingtone = FALSE;
838  } else if ((int)entry->MemoryType==MEM6510_CG2) {
839  /* FIXME */
840  smprintf(s, "Internal ringtone ID: %02x\n",Block[10]*256+Block[11]);
841  bitmap->FileSystemRingtone = FALSE;
842  bitmap->RingtoneID = Block[10]*256+Block[11];
843  bitmap->DefaultRingtone = FALSE;
844  } else {
845  /* series 40 3.0 */
846  smprintf(s, "Filesystem ringtone ID: %02x\n",Block[10]*256+Block[11]);
849  entry->Entries[entry->EntriesNum].Number=Block[10]*256+Block[11];
850  entry->EntriesNum ++;
851  }
852  continue;
853  }
854  if (Block[0] == N6510_PBK_SMSLIST_ID) {
855  smprintf(s, "Entry %i is assigned to SMS list %i\n",Block[5]-1,Block[9]);
856  i = 0;
857  while(entry->Entries[Block[5]-1].SMSList[i] != 0) i++;
858  entry->Entries[Block[5]-1].SMSList[i+1] = 0;
859  entry->Entries[Block[5]-1].SMSList[i] = Block[9];
860  continue;
861  }
862  if (Block[0] == N7110_PBK_MISSED) {
863  missed_call = TRUE;
864  smprintf(s,"Unknown entry type 0x%02x data length %d\n", Block[0], bs-6);
865  continue;
866  }
867  if (Block[0] == N7110_PBK_UNKNOWN2
868  || Block[0] == N7110_PBK_UNKNOWN3
869  || Block[0] == N3600_PBK_UNKNOWN1
870  || Block[0] == N6303_PBK_UNKNOWN1
871  || Block[0] == N6303_PBK_UNKNOWN2) {
872  smprintf(s,"Unknown entry type 0x%02x data length %d\n", Block[0], bs-6);
873  continue;
874  }
875  if (Block[0] == N6510_PBK_UNKNOWN2) {
876  smprintf(s,"Unknown entry - probably ID for conversation list\n");
877  continue;
878  }
879  if (Block[0] == N6510_PBK_UNKNOWN3) {
880  smprintf(s,"Unknown entry - probably ID for Instant Messaging service list\n");
881  continue;
882  }
883  if (Block[0] == N6510_PBK_UNKNOWN4) {
884  smprintf(s,"Unknown entry - probably ID for presence list\n");
885  continue;
886  }
887  if (Block[0] == N6510_PBK_PUSHTOTALK_ID) {
888  smprintf(s,"SIP Address (Push to Talk address)\n");
889  if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
890  return ERR_UNKNOWNRESPONSE;
893  entry->EntriesNum ++;
894  continue;
895  }
896  if (Block[0] == N6510_PBK_UNKNOWN5) {
897  smprintf(s,"Unknown entry\n");
898  continue;
899  }
900  if (Block[0] == N6510_PBK_GROUP2_ID) {
901  smprintf(s,"Group ID (6230i or later)\n");
902 
905  smprintf(s, "Caller group \"%i\"\n",Block[7]);
906  entry->Entries[entry->EntriesNum].Number=Block[7];
907  entry->EntriesNum ++;
908  continue;
909  }
910  if (Block[0] == N2630_PBK_FAVMESSAGING) {
911  if (used_favorite_messaging_numbers >= sizeof(favorite_messaging_numbers) / sizeof(int)) {
912  smprintf(s, "Too many favorite messaging numbers!\n");
913  return ERR_MOREMEMORY;
914  }
915  favorite_messaging_numbers[used_favorite_messaging_numbers] = (int)Block[5];
916  used_favorite_messaging_numbers++;
917 
918  continue;
919  }
920  smprintf(s, "ERROR: unknown pbk entry 0x%02x\n",Block[0]);
921  return ERR_UNKNOWNRESPONSE;
922  }
923 
924  if (entry->EntriesNum == 0) {
925  if (missed_call) {
926  smprintf(s, "Empty entry with missed call reference, adding blank number!\n");
929  EncodeUnicode(entry->Entries[entry->EntriesNum].Text, "", 0);
930  } else {
931  return ERR_EMPTY;
932  }
933  }
934 
935  /* Process favorite messaging numbers */
936  for (i = 0; i < (int)used_favorite_messaging_numbers; i++) {
937  if (entry->EntriesNum >= GSM_PHONEBOOK_ENTRIES) {
938  smprintf(s, "Too many entries\n");
939  return ERR_MOREMEMORY;
940  }
941 
942  /* The phone sends an entry id. We store it as phone number because
943  * entry->Entries doesn't retain order. */
944 
947  CopyUnicodeString(entry->Entries[entry->EntriesNum].Text,entry->Entries[favorite_messaging_numbers[i] - 1].Text);
948  smprintf(s,"Marked entry #%i (%s) as favorite messaging number\n",
949  favorite_messaging_numbers[i],
950  DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
951  entry->EntriesNum ++;
952  }
953  return ERR_NONE;
954 }
gboolean DefaultRingtone
Definition: gammu-bitmap.h:134
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
void DumpMessage(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
Definition: debug.c:314
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
Definition: coding.c:1192
GSM_MemoryType MemoryType
Definition: gammu-memory.h:415
#define GSM_PHONEBOOK_TEXT_LENGTH
Definition: gammu-limits.h:91
GSM_EntryLocation
Definition: gammu-memory.h:348
gboolean FileSystemRingtone
Definition: gammu-bitmap.h:139
GSM_Debug_Info * GSM_GetDI(GSM_StateMachine *s)
Definition: gsmstate.c:70
#define GSM_PHONEBOOK_ENTRIES
Definition: gammu-limits.h:98
gboolean FileSystemPicture
Definition: gammu-bitmap.h:144
GSM_Debug_Info di
Definition: gsmstate.h:1412
void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:141
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
GSM_EntryType EntryType
Definition: gammu-memory.h:372
static gboolean N71_65_PB_CopyString(GSM_StateMachine *s, GSM_MemoryEntry *entry, const unsigned char *src, unsigned char length)
Definition: nfunc.c:336
unsigned char RingtoneID
Definition: gammu-bitmap.h:138
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
Definition: gammu-memory.h:399
int gboolean
Definition: gammu-types.h:23
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:301
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
gboolean BitmapEnabled
Definition: gammu-bitmap.h:122
GSM_MemoryType MemoryType
Definition: gammu-memory.h:447
gboolean DefaultBitmap
Definition: gammu-bitmap.h:130
GSM_DateTime Date
Definition: gammu-memory.h:380
GSM_Phone_Data Data
Definition: gsmstate.h:1369
gboolean GSM_IsPhoneFeatureAvailable(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1026
gboolean DefaultName
Definition: gammu-bitmap.h:126
GSM_EntryLocation Location
Definition: gammu-memory.h:376
unsigned char Text[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
Definition: gammu-bitmap.h:118
#define TRUE
Definition: gammu-types.h:28
void NOKIA_DecodeDateTime(GSM_StateMachine *s, unsigned char *buffer, GSM_DateTime *datetime, gboolean seconds, gboolean DayMonthReverse)
Definition: nfunc.c:976
GSM_EntryType
Definition: gammu-memory.h:144
gboolean CheckDate(GSM_DateTime *date)
Definition: misc.c:349
Debug_Level dl
Definition: debug.h:35
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]
Definition: gammu-memory.h:427

§ N71_65_EncodePhonebookFrame()

size_t N71_65_EncodePhonebookFrame ( GSM_StateMachine s,
unsigned char *  req,
GSM_MemoryEntry entry,
size_t *  block2,
gboolean  DCT4,
gboolean  VoiceTag 
)

Definition at line 54 of file nfunc.c.

References GSM_SubMemoryEntry::AddError, CopyUnicodeString(), GSM_Phone::Data, GSM_SubMemoryEntry::Date, GSM_MemoryEntry::Entries, GSM_MemoryEntry::EntriesNum, GSM_SubMemoryEntry::EntryType, ERR_DATACONVERTED, ERR_INVALIDDATA, ERR_NONE, ERR_NOTSUPPORTED, F_6230iCALLER, F_PBK35, F_PBKFAVORITEMESSAGE, F_PBKIMG, F_PBKNOPOSTAL, F_PBKUSER, F_SERIES40_30, FALSE, GSM_IsPhoneFeatureAvailable(), GSM_SubMemoryEntry::Location, MIN, GSM_Phone_Data::ModelInfo, mywstrncmp(), N2630_PBK_FAVMESSAGING, N6510_PBK_GROUP2_ID, N6510_PBK_PICTURE_ID, N6510_PBK_PUSHTOTALK_ID, N6510_PBK_SMSLIST_ID, N6510_PBK_URL, N6510_PBK_USER_ID, N6510_PBK_VOICETAG_ID, N7110_PBK_EMAIL, N7110_PBK_GROUP, N7110_PBK_NAME, N7110_PBK_NOTE, N7110_PBK_NUMBER, N7110_PBK_NUMBER_FAX, N7110_PBK_NUMBER_GENERAL, N7110_PBK_NUMBER_HOME, N7110_PBK_NUMBER_MOBILE, N7110_PBK_NUMBER_WORK, N7110_PBK_POSTAL, N7110_PBK_RINGTONE_ID, N71_65_PackPBKBlock(), NOKIA_EncodeDateTime(), GSM_SubMemoryEntry::Number, PBK_Caller_Group, PBK_Date, PBK_Location_Home, PBK_Location_Work, PBK_Number_Fax, PBK_Number_General, PBK_Number_Messaging, PBK_Number_Mobile, PBK_PictureID, PBK_PushToTalkID, PBK_RingtoneID, PBK_Text_Company, PBK_Text_Email, PBK_Text_Email2, PBK_Text_FirstName, PBK_Text_FormalName, PBK_Text_JobTitle, PBK_Text_LastName, PBK_Text_Name, PBK_Text_NickName, PBK_Text_Note, PBK_Text_Postal, PBK_Text_URL, PBK_Text_UserID, _GSM_StateMachine::Phone, S4030_PBK_BIRTHDAY, S4030_PBK_COMPANY, S4030_PBK_FIRSTNAME, S4030_PBK_FORMALNAME, S4030_PBK_JOBTITLE, S4030_PBK_LASTNAME, S4030_PBK_NICKNAME, smprintf(), GSM_SubMemoryEntry::SMSList, GSM_SubMemoryEntry::Text, TRUE, UnicodeLength(), and GSM_SubMemoryEntry::VoiceTag.

55 {
56  int count=0, len, i, block=0, j;
57  unsigned char string[500];
58  unsigned char type;
59  gboolean found;
60 
61  for (i = 0; i < entry->EntriesNum; i++) {
62  entry->Entries[i].AddError = ERR_NOTSUPPORTED;
63  }
64  memset(string,0,sizeof(string));
65  found = FALSE;
67  for (i = 0; i < entry->EntriesNum; i++) {
68  if (entry->Entries[i].EntryType == PBK_Text_LastName ||
69  entry->Entries[i].EntryType == PBK_Text_FirstName) {
70  if (entry->Entries[i].EntryType==PBK_Text_LastName) {
71  type = S4030_PBK_LASTNAME;
72  } else {
73  type = S4030_PBK_FIRSTNAME;
74  }
75  found = TRUE;
76  entry->Entries[i].AddError = ERR_NONE;
77  len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
78  string[0] = len*2+2;
79  CopyUnicodeString(string+1,entry->Entries[i].Text);
80  string[len*2+1] = 0;
81  count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
82  }
83  }
84  for (i = 0; i < entry->EntriesNum; i++) {
85  if(entry->Entries[i].EntryType==PBK_Text_Name) {
86  if (!found) {
87  entry->Entries[i].AddError = ERR_NONE;
88  type = N7110_PBK_NAME;
89  len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
90  string[0] = len*2+2;
91  CopyUnicodeString(string+1,entry->Entries[i].Text);
92  string[len*2+1] = 0;
93  count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
94  found = TRUE;
95  } else {
96  entry->Entries[i].AddError = ERR_INVALIDDATA;
97  }
98  }
99  }
100  } else {
101  for (i = 0; i < entry->EntriesNum; i++) {
102  if (entry->Entries[i].EntryType == PBK_Text_LastName ||
103  entry->Entries[i].EntryType == PBK_Text_FirstName) {
104  if (UnicodeLength(string+1) > 0) {
105  string[UnicodeLength(string+1)*2+1] = ' ';
106  }
107  CopyUnicodeString(string+UnicodeLength(string+1)*2+1,entry->Entries[i].Text);
108  entry->Entries[i].AddError = ERR_DATACONVERTED;
109  found=TRUE;
110  }
111  }
112  if (UnicodeLength(string+1) != 0) {
113  type = N7110_PBK_NAME;
114  len = MIN(UnicodeLength(string+1), 126);
115  string[0] = len*2+2;
116  string[len*2+1] = 0;
117  count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
118  }
119  for (i = 0; i < entry->EntriesNum; i++) {
120  if (entry->Entries[i].EntryType==PBK_Text_Name) {
121  if (!found) {
122  entry->Entries[i].AddError = ERR_NONE;
123  type = N7110_PBK_NAME;
124  len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
125  string[0] = len*2+2;
126  CopyUnicodeString(string+1,entry->Entries[i].Text);
127  string[len*2+1] = 0;
128  count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
129  found = TRUE;
130  } else {
131  entry->Entries[i].AddError = ERR_INVALIDDATA;
132  }
133  }
134  }
135  }
136  for (i = 0; i < entry->EntriesNum; i++) {
137  type = 0;
139  else if (entry->Entries[i].EntryType == PBK_Number_General && entry->Entries[i].Location == PBK_Location_Home) type = N7110_PBK_NUMBER_HOME;
140  else if (entry->Entries[i].EntryType == PBK_Number_General) type = N7110_PBK_NUMBER_GENERAL;
142  if (entry->Entries[i].EntryType == PBK_Number_Fax) type = N7110_PBK_NUMBER_FAX;
143  if (type != 0) {
144  entry->Entries[i].AddError = ERR_NONE;
145 
146  string[0] = type;
147  len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
148 
149  string[1] = 0;
150  string[2] = 0;
151 
152  /* DCT 3 */
153  if (!DCT4) string[2] = entry->Entries[i].VoiceTag;
154 
155  string[3] = 0;
156  string[4] = len*2+2;
157  CopyUnicodeString(string+5,entry->Entries[i].Text);
158  string[len * 2 + 5] = 0;
159  count += N71_65_PackPBKBlock(s, N7110_PBK_NUMBER, len*2+6, block++, string, req+count);
160 
161  /* DCT 4 */
162  if (DCT4 && VoiceTag) {
163  block++;
164  req[count++] = N6510_PBK_VOICETAG_ID;
165  req[count++] = 0;
166  req[count++] = 0;
167  req[count++] = 8;
168  req[count++] = 0x00;
169  req[count++] = i+1;
170  req[count++] = 0x00;
171  req[count++] = entry->Entries[i].VoiceTag;
172  }
173  if (DCT4) {
174  j = 0;
175  while (entry->Entries[i].SMSList[j] != 0) {
176  string[0] = i+1;
177  string[1] = 0x00;
178  string[2] = 0x02;
179  string[3] = 0x00;
180  string[4] = entry->Entries[i].SMSList[j];
181  string[5] = 0x00;
182  count += N71_65_PackPBKBlock(s, N6510_PBK_SMSLIST_ID, 6, block++, string, req+count);
183 
184  j++;
185  }
186  }
187  continue;
188  }
189  smprintf(s, "entry num %i %i\n",i,entry->EntriesNum);
190  if (entry->Entries[i].EntryType == PBK_Text_Note) type = N7110_PBK_NOTE;
191  if (entry->Entries[i].EntryType == PBK_Text_Postal) {
193  continue;
194  }
195  type = N7110_PBK_POSTAL;
196  }
197  if (entry->Entries[i].EntryType == PBK_Text_Email) type = N7110_PBK_EMAIL;
198  if (entry->Entries[i].EntryType == PBK_Text_Email2) type = N7110_PBK_EMAIL;
199  if (entry->Entries[i].EntryType == PBK_Text_URL) {
200  entry->Entries[i].AddError = ERR_DATACONVERTED;
201  type = N7110_PBK_NOTE;
202  if (DCT4) type = N6510_PBK_URL;
203  }
204  if (type != 0) {
205  if (entry->Entries[i].AddError==ERR_NOTSUPPORTED) entry->Entries[i].AddError = ERR_NONE;
206  len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
207  string[0] = len*2+2;
208  CopyUnicodeString(string+1,entry->Entries[i].Text);
209  string[len*2+1] = 0;
210  count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
211  continue;
212  }
213  if (entry->Entries[i].EntryType == PBK_Caller_Group) {
215  entry->Entries[i].AddError = ERR_NONE;
217  string[0] = 0;
218  string[1] = 0;
219  count += N71_65_PackPBKBlock(s, N6510_PBK_GROUP2_ID, 2, block++, string, req + count);
220  req[count-1] = entry->Entries[i].Number;
221  } else {
222  string[0] = entry->Entries[i].Number;
223  string[1] = 0;
224  count += N71_65_PackPBKBlock(s, N7110_PBK_GROUP, 2, block++, string, req + count);
225  }
226  }
227  continue;
228  }
229  if (entry->Entries[i].EntryType == PBK_RingtoneID) {
231  entry->Entries[i].AddError = ERR_NONE;
232  string[0] = 0x00;
233  string[1] = 0x00;
234  string[2] = entry->Entries[i].Number;
235  count += N71_65_PackPBKBlock(s, N7110_PBK_RINGTONE_ID, 3, block++, string, req + count);
236  count --;
237  req[count-5] = 8;
238  }
239  continue;
240  }
241  if (entry->Entries[i].EntryType == PBK_PictureID) {
243  entry->Entries[i].AddError = ERR_NONE;
244  string[0] = 0x00;
245  string[1] = 0x00;
246  string[2] = 0x00;
247  string[3] = 0x00;
248  string[4] = 0x01;
249  string[5] = entry->Entries[i].Number / 256;
250  string[6] = entry->Entries[i].Number % 256;
251  string[7] = 0x00;
252  string[8] = 0x00;
253  string[9] = 0x00;
254  count += N71_65_PackPBKBlock(s, N6510_PBK_PICTURE_ID, 10, block++, string, req + count);
255  req[count-1] = 0x01;
256  }
257  continue;
258  }
259  /* Maybe we should use separate feature for these new entries... */
261  type = 0;
263  if (entry->Entries[i].EntryType == PBK_Text_JobTitle) type = S4030_PBK_JOBTITLE;
264  if (entry->Entries[i].EntryType == PBK_Text_Company) type = S4030_PBK_COMPANY;
265  if (entry->Entries[i].EntryType == PBK_Text_NickName) type = S4030_PBK_NICKNAME;
266  if (type != 0) {
267  if (entry->Entries[i].AddError==ERR_NOTSUPPORTED) entry->Entries[i].AddError = ERR_NONE;
268  len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
269  string[0] = len*2+2;
270  CopyUnicodeString(string+1,entry->Entries[i].Text);
271  string[len*2+1] = 0;
272  count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
273  continue;
274  }
275  if (entry->Entries[i].EntryType == PBK_Date) {
276  entry->Entries[i].AddError = ERR_NONE;
277 
278  NOKIA_EncodeDateTime(s, string + 1, &(entry->Entries[i].Date));
279  count += N71_65_PackPBKBlock(s, S4030_PBK_BIRTHDAY, 6, block++, string, req + count);
280  continue;
281  }
282  }
283  if (entry->Entries[i].EntryType == PBK_Text_UserID) {
285  entry->Entries[i].AddError = ERR_NONE;
286  string[0] = UnicodeLength(entry->Entries[i].Text)*2;
287  CopyUnicodeString(string+1,entry->Entries[i].Text);
288  count += N71_65_PackPBKBlock(s, N6510_PBK_USER_ID, string[0]+2, block++, string, req+count);
289  req[count-1]--;
290  }
291  continue;
292  }
293  if (entry->Entries[i].EntryType == PBK_PushToTalkID) {
294  entry->Entries[i].AddError = ERR_NONE;
295  string[0] = UnicodeLength(entry->Entries[i].Text)*2;
296  CopyUnicodeString(string+1,entry->Entries[i].Text);
297  count += N71_65_PackPBKBlock(s, N6510_PBK_PUSHTOTALK_ID, string[0]+2, block++, string, req+count);
298  req[count-1]--;
299  continue;
300  }
301  if (entry->Entries[i].EntryType == PBK_Number_Messaging) {
303  entry->Entries[i].AddError = ERR_INVALIDDATA;
304  /* The favorite messaging number is stored as a phone number,
305  * the phone wants an id to a previously supplied entry, so we search for that.
306  * In case there was an error in the previous entries, we stop.
307  * Otherwise we would point past the supplied entries. */
308  for (j = 0; j < i && entry->Entries[j].AddError == ERR_NONE; j++) {
309  if (mywstrncmp(entry->Entries[i].Text, entry->Entries[j].Text, -1)) {
310  string[0] = j + 1;
311  string[1] = 0x00;
312  string[2] = 0x00;
313  count += N71_65_PackPBKBlock(s, N2630_PBK_FAVMESSAGING, 3, block++, string, req + count);
314  count --;
315  req[count-5] = 8;
316  entry->Entries[i].AddError = ERR_NONE;
317  break;
318  }
319 
320  }
321  }
322  continue;
323  }
324  }
325 
326  *block2=block;
327 
328  return count;
329 }
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
Definition: coding.c:1192
void NOKIA_EncodeDateTime(GSM_StateMachine *s UNUSED, unsigned char *buffer, GSM_DateTime *datetime)
Definition: nfunc.c:1007
size_t UnicodeLength(const unsigned char *str)
Definition: coding.c:186
GSM_PhoneModel * ModelInfo
Definition: gsmstate.h:449
GSM_EntryType EntryType
Definition: gammu-memory.h:372
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
Definition: gammu-memory.h:399
int gboolean
Definition: gammu-types.h:23
GSM_Phone Phone
Definition: gsmstate.h:1431
#define FALSE
Definition: gammu-types.h:25
size_t N71_65_PackPBKBlock(GSM_StateMachine *s, int id, size_t size, int no, unsigned char *buf, unsigned char *block)
Definition: nfunc.c:36
GSM_DateTime Date
Definition: gammu-memory.h:380
gboolean mywstrncmp(unsigned const char *a, unsigned const char *b, int num)
Definition: coding.c:1457
GSM_Phone_Data Data
Definition: gsmstate.h:1369
gboolean GSM_IsPhoneFeatureAvailable(GSM_PhoneModel *model, GSM_Feature feature)
Definition: gsmphones.c:1026
GSM_EntryLocation Location
Definition: gammu-memory.h:376
#define MIN(a, b)
Definition: gammu-misc.h:70
#define TRUE
Definition: gammu-types.h:28
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]
Definition: gammu-memory.h:427

§ N71_65_PackPBKBlock()

size_t N71_65_PackPBKBlock ( GSM_StateMachine s,
int  id,
size_t  size,
int  no,
unsigned char *  buf,
unsigned char *  block 
)

Definition at line 36 of file nfunc.c.

References smprintf().

Referenced by N71_65_EncodePhonebookFrame().

37 {
38  smprintf(s, "Packing phonebook block with ID = %i, block number = %i, block length = %ld\n",
39  id,
40  no+1,
41  (long)size+6);
42 
43  block[0] = id;
44  block[1] = 0;
45  block[2] = (size + 6) / 256;
46  block[3] = (size + 6) % 256;
47  block[4] = no + 1;
48  memcpy(block+5, buf, size);
49  block[5+size] = 0;
50 
51  return (size + 6);
52 }
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ N71_65_PB_CopyString()

static gboolean N71_65_PB_CopyString ( GSM_StateMachine s,
GSM_MemoryEntry entry,
const unsigned char *  src,
unsigned char  length 
)
static

Copy string to GSM_MemoryEntry

Return false on failure

Definition at line 336 of file nfunc.c.

References DecodeUnicodeString(), GSM_MemoryEntry::Entries, GSM_MemoryEntry::EntriesNum, FALSE, GSM_PHONEBOOK_TEXT_LENGTH, smprintf(), GSM_SubMemoryEntry::Text, and TRUE.

Referenced by N71_65_DecodePhonebook().

340 {
341  if ((length & 1) != 0) {
342  smprintf(s, "String length not even\n");
343  return FALSE;
344  }
345  if (length/2 > GSM_PHONEBOOK_TEXT_LENGTH) {
346  smprintf(s, "Too long text\n");
347  return FALSE;
348  }
349  memcpy(entry->Entries[entry->EntriesNum].Text, src, length);
350  /* Zero terminate the string */
351  entry->Entries[entry->EntriesNum].Text[length] = 0;
352  entry->Entries[entry->EntriesNum].Text[length + 1] = 0;
353 
354  smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
355 
356  return TRUE;
357 }
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
#define GSM_PHONEBOOK_TEXT_LENGTH
Definition: gammu-limits.h:91
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
Definition: gammu-memory.h:399
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]
Definition: gammu-memory.h:427

§ NOKIA_DecodeDateTime()

void NOKIA_DecodeDateTime ( GSM_StateMachine s,
unsigned char *  buffer,
GSM_DateTime datetime,
gboolean  seconds,
gboolean  DayMonthReverse 
)

Definition at line 976 of file nfunc.c.

References GSM_DateTime::Day, GSM_DateTime::Hour, GSM_DateTime::Minute, GSM_DateTime::Month, GSM_DateTime::Second, smprintf(), GSM_DateTime::Timezone, and GSM_DateTime::Year.

Referenced by N71_65_DecodePhonebook().

977 {
978  datetime->Year = buffer[0] * 256 + buffer[1];
979  /* Sometimes reversed */
980  if (datetime->Year > 3000) {
981  datetime->Year = buffer[1] * 256 + buffer[0];
982  }
983  if (DayMonthReverse) {
984  datetime->Month = buffer[3];
985  datetime->Day = buffer[2];
986  } else {
987  datetime->Month = buffer[2];
988  datetime->Day = buffer[3];
989  }
990 
991  datetime->Hour = buffer[4];
992  datetime->Minute = buffer[5];
993  if (seconds) {
994  datetime->Second = buffer[6];
995  } else {
996  datetime->Second = 0;
997  }
998  datetime->Timezone = 0;
999 
1000  smprintf(s, "Decoding date and time\n");
1001  smprintf(s, " Time: %02d:%02d:%02d\n",
1002  datetime->Hour, datetime->Minute, datetime->Second);
1003  smprintf(s, " Date: %4d/%02d/%02d\n",
1004  datetime->Year, datetime->Month, datetime->Day);
1005 }
int smprintf(GSM_StateMachine *s, const char *format,...)
Definition: debug.c:261

§ NOKIA_EncodeDateTime()

void NOKIA_EncodeDateTime ( GSM_StateMachine *s  UNUSED,
unsigned char *  buffer,
GSM_DateTime datetime 
)

Definition at line 1007 of file nfunc.c.

References _, GSM_MultiWAPSettings::Active, GSM_WAPBookmark::Address, GSM_Protocol_Message::Buffer, GSM_Phone_Data::Cal, CAL_PHONE, CAL_REPEAT_DAY, CAL_REPEAT_FREQUENCY, CAL_REPEAT_MONTH, CAL_SILENT_ALARM_DATETIME, CAL_START_DATETIME, CAL_TEXT, CAL_TONE_ALARM_DATETIME, GSM_Profile::CallerGroups, GSM_Call::CallID, GSM_Phone_Data::CallID, GSM_Call::CallIDAvailable, GSM_CallDivert::CallType, CopyUnicodeString(), D_TEXT, GSM_Phone::Data, GSM_SubCalendarEntry::Date, GSM_DateTime::Day, DCT3DCT4_AnswerCall(), DCT3DCT4_CancelAllDiverts(), DCT3DCT4_CancelCall(), DCT3DCT4_DeleteWAPBookmarkPart(), DCT3DCT4_DisableConnectionFunctions(), DCT3DCT4_EnableWAPFunctions(), DCT3DCT4_GetActiveConnectSet(), DCT3DCT4_GetCallDivert(), DCT3DCT4_GetFirmware(), DCT3DCT4_GetModel(), DCT3DCT4_GetWAPBookmarkPart(), DCT3DCT4_ReplyCallDivert(), DCT3DCT4_ReplyDelWAPBookmark(), DCT3DCT4_ReplyDisableConnectFunc(), DCT3DCT4_ReplyEnableConnectFunc(), DCT3DCT4_ReplyGetActiveConnectSet(), DCT3DCT4_ReplyGetModelFirmware(), DCT3DCT4_ReplyGetWAPBookmark(), DCT3DCT4_ReplySetActiveConnectSet(), DCT3DCT4_ReplySetWAPBookmark(), DCT3DCT4_SendDTMF(), DCT3DCT4_SetActiveConnectSet(), DCT3DCT4_SetCallDivert(), DecodeUnicodeString(), GSM_Profile::DefaultName, _GSM_StateMachine::di, GSM_Phone_Data::Divert, GSM_CallDivert::DivertType, GSM_Phone_Data::EnableIncomingCall, GSM_Phone_Data::EnableIncomingSMS, GSM_Phone_Data::EnableIncomingUSSD, EncodeUnicode(), GSM_MultiCallDivert::Entries, GSM_CalendarEntry::Entries, GSM_MultiCallDivert::EntriesNum, GSM_CalendarEntry::EntriesNum, GSM_MemoryEntry::EntriesNum, GSM_SubCalendarEntry::EntryType, ERR_BUG, ERR_BUSY, ERR_EMPTY, ERR_FULL, ERR_INSIDEPHONEMENU, ERR_INVALIDLOCATION, ERR_MEMORY, ERR_MOREMEMORY, ERR_NEEDANOTHERANSWER, ERR_NONE, ERR_NOTIMPLEMENTED, ERR_NOTSUPPORTED, ERR_PERMISSION, ERR_SECURITYERROR, ERR_UNKNOWN, ERR_UNKNOWNRESPONSE, ERR_WORKINPROGRESS, F_CAL35, F_CAL62, F_CAL65, F_NOCALLINFO, F_NODTMF, F_NOWAP, FALSE, GSM_Profile::FeatureID, GSM_Profile::FeaturesNumber, GSM_Profile::FeatureValue, Fill_Time_T(), FreeLines(), GSM_Protocol::Functions, GSM_Phone::Functions, GSM_Phone_Functions::GetDateTime, GetLineString(), GetModelData(), GetTimeDifference(), GSM_CAL_BIRTHDAY, GSM_CAL_CALL, GSM_CAL_MEETING, GSM_CAL_MEMO, GSM_CAL_REMINDER, GSM_CalendarFindDefaultTextTimeAlarmPhone(), GSM_CALL_CallEstablished, GSM_CALL_CallHeld, GSM_CALL_CallLocalEnd, GSM_CALL_CallRemoteEnd, GSM_CALL_CallResumed, GSM_CALL_CallStart, GSM_CALL_CallSwitched, GSM_CALL_IncomingCall, GSM_CALL_OutgoingCall, GSM_CreateFirmwareNumber(), GSM_DIVERT_AllCalls, GSM_DIVERT_AllTypes, GSM_DIVERT_Busy, GSM_DIVERT_DataCalls, GSM_DIVERT_FaxCalls, GSM_DIVERT_NoAnswer, GSM_DIVERT_OutOfReach, GSM_DIVERT_VoiceCalls, GSM_GetCalendarRecurranceRepeat(), GSM_GetCurrentDateTime(), GSM_IsPhoneFeatureAvailable(), GSM_MAXCALENDARTODONOTES, GSM_PackSemiOctetNumber(), GSM_SetCalendarRecurranceRepeat(), GSM_UnpackSemiOctetNumber(), GSM_WaitFor(), GSM_DateTime::Hour, GSM_Profile_PhoneTableValue::ID, ID_AnswerCall, ID_CancelCall, ID_DeleteCalendarNote, ID_DeleteWAPBookmark, ID_DialVoice, ID_DisableConnectFunc, ID_Divert, ID_EnableConnectFunc, ID_GetCalendarNote, ID_GetCalendarNotePos, ID_GetCalendarNotesInfo, ID_GetConnectSet, ID_GetFirmware, ID_GetModel, ID_GetWAPBookmark, ID_SendDTMF, ID_SetCalendarNote, ID_SetConnectSet, _GSM_User::IncomingCall, _GSM_User::IncomingCallUserData, _GSM_User::IncomingUSSD, _GSM_User::IncomingUSSDUserData, InitLines(), GSM_Protocol_Message::Length, GSM_WAPBookmark::Location, GSM_NOKIASMSFolder::Location, GSM_NOKIACalToDoLocations::Location, GSM_Profile::Location, GSM_MultiWAPSettings::Location, GSM_CalendarEntry::Location, GSM_Phone_Data::Manufacturer, MEM_ME, MEM_SM, GSM_Phone_Data::Memory, GSM_MemoryEntry::MemoryType, GSM_DateTime::Minute, GSM_Phone_Data::Model, GSM_Phone_Data::ModelInfo, GSM_DateTime::Month, N6110_FRAME_HEADER, N71_65_AddCalendar1(), N71_65_AddCalendar2(), N71_65_DelCalendar(), N71_65_EnableFunctions(), N71_65_FindCalendarType(), N71_65_GetCalendarInfo1(), N71_65_GetNextCalendar1(), N71_65_ReplyAddCalendar1(), N71_65_ReplyAddCalendar2(), N71_65_ReplyCallInfo(), N71_65_ReplyDelCalendar(), N71_65_ReplyGetCalendarInfo1(), N71_65_ReplyGetCalendarNotePos1(), N71_65_ReplyGetMemoryError(), N71_65_ReplyGetNextCalendar1(), N71_65_ReplySendDTMF(), N71_65_ReplyUSSDInfo(), N71_65_ReplyWritePhonebook(), GSM_Profile::Name, NOKIA_DecodeSMSState(), NOKIA_FindFeatureValue(), NOKIA_FindPhoneFeatureValue(), NOKIA_GetDefaultProfileName(), NOKIA_GetManufacturer(), NOKIA_GetMemoryType(), NOKIA_GetPhoneString(), NOKIA_GetUnicodeString(), NOKIA_ReplyGetPhoneString(), NOKIA_SetIncomingCall(), NOKIA_SetIncomingSMS(), NOKIA_SetIncomingUSSD(), NOKIA_SetUnicodeString(), NOKIA_SortSMSFolderStatus(), GSM_NOKIASMSFolder::Number, GSM_NOKIACalToDoLocations::Number, GSM_CallDivert::Number, GSM_SubCalendarEntry::Number, _GSM_StateMachine::Phone, GSM_Profile_PhoneTableValue::PhoneID, GSM_Call::PhoneNumber, GSM_Phone_Data::PhoneString, GSM_Profile_PhoneTableValue::PhoneValue, GSM_Phone_Data::Profile, Profile71_65, Profile_AutoAnswer, PROFILE_AUTOANSWER_OFF, PROFILE_AUTOANSWER_ON, Profile_CallAlert, PROFILE_CALLALERT_ASCENDING, PROFILE_CALLALERT_BEEPONCE, PROFILE_CALLALERT_OFF, PROFILE_CALLALERT_RINGING, PROFILE_CALLALERT_RINGONCE, Profile_CallerGroups, PROFILE_KEYPAD_LEVEL1, PROFILE_KEYPAD_LEVEL2, PROFILE_KEYPAD_LEVEL3, PROFILE_KEYPAD_OFF, Profile_KeypadTone, Profile_Lights, PROFILE_MESSAGE_ASCENDING, PROFILE_MESSAGE_BEEPONCE, PROFILE_MESSAGE_NOTONE, PROFILE_MESSAGE_SPECIAL, PROFILE_MESSAGE_STANDARD, Profile_MessageTone, Profile_RingtoneVolume, Profile_ScreenSaver, Profile_ScreenSaverTime, Profile_Vibration, PROFILE_VIBRATION_OFF, PROFILE_VIBRATION_ON, PROFILE_VOLUME_LEVEL1, PROFILE_VOLUME_LEVEL2, PROFILE_VOLUME_LEVEL3, PROFILE_VOLUME_LEVEL4, PROFILE_VOLUME_LEVEL5, PROFILE_WARNING_OFF, PROFILE_WARNING_ON, Profile_WarningTone, _GSM_StateMachine::Protocol, GSM_Phone_Data::RequestID, GSM_DateTime::Second, smprintf(), smprintf_level(), SMS_Read, SMS_Sent, SMS_UnRead, SMS_UnSent, SplitLines(), GSM_Phone_Data::StartPhoneString, GSM_SMSMessage::State, GSM_Call::Status, GSM_USSDMessage::Status, GSM_Call::StatusCode, GSM_USSDMessage::Text, GSM_SubCalendarEntry::Text, GSM_CallDivert::Timeout, GSM_WAPBookmark::Title, TRUE, GSM_CalendarEntry::Type, UnicodeLength(), UNUSED, _GSM_StateMachine::User, USSD_Unknown, GSM_Profile_PhoneTableValue::Value, GSM_Phone_Data::VerDate, GSM_Phone_Data::Version, GSM_Phone_Data::WAPBookmark, GSM_Phone_Data::WAPSettings, GSM_Protocol_Functions::WriteMessage, and GSM_DateTime::Year.

Referenced by N71_65_EncodePhonebookFrame().

1008 {
1009  buffer[0] = datetime->Year / 256;
1010  buffer[1] = datetime->Year % 256;
1011  buffer[2] = datetime->Month;
1012  buffer[3] = datetime->Day;
1013 
1014  buffer[4] = datetime->Hour;
1015  buffer[5] = datetime->Minute;
1016 }

Variable Documentation

§ N71_65_MEMORY_TYPES

unsigned char N71_65_MEMORY_TYPES[]
Initial value:
= {
MEM_DC, 0x01,
MEM_MC, 0x02,
MEM_RC, 0x03,
MEM_ME, 0x05,
MEM_SM, 0x06,
MEM_VM, 0x09,
MEM7110_SP, 0x0e,
MEM7110_CG, 0x10,
MEM_ON, 0x17,
MEM6510_CG2, 0x23,
MEM_SL, 0x27,
0x00, 0x00
}

Definition at line 21 of file nfunc.c.