1 /** 2 * \file gammu-memory.h 3 * \author Michal Čihař 4 * 5 * Memory data and functions. 6 */ 7 #ifndef __gammu_memory_h 8 #define __gammu_memory_h 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 14 /** 15 * \defgroup Memory Memory 16 * Memory entries manipulations. 17 */ 18 19 #include <gammu-datetime.h> 20 #include <gammu-limits.h> 21 #include <gammu-bitmap.h> 22 #include <gammu-debug.h> 23 24 /** 25 * Enum defines ID for various phone and SIM memories. 26 * Phone modules can translate them to values specific for concrete models. 27 * Two letter codes (excluding VM and SL) are from GSM 07.07. 28 * 29 * \ingroup Memory 30 */ 31 typedef enum { 32 /** 33 * Internal memory of the mobile equipment 34 */ 35 MEM_ME = 1, 36 /** 37 * SIM card memory 38 */ 39 MEM_SM, 40 /** 41 * Own numbers 42 */ 43 MEM_ON, 44 /** 45 * Dialled calls 46 */ 47 MEM_DC, 48 /** 49 * Received calls 50 */ 51 MEM_RC, 52 /** 53 * Missed calls 54 */ 55 MEM_MC, 56 /** 57 * Combined ME and SIM phonebook 58 */ 59 MEM_MT, 60 /** 61 * Fixed dial 62 */ 63 MEM_FD, 64 65 /** 66 * Voice mailbox 67 */ 68 MEM_VM, 69 70 /** 71 * Sent SMS logs 72 */ 73 MEM_SL, 74 75 /** 76 * Quick dialing choices. 77 */ 78 MEM_QD, 79 /** 80 * Status report memory 81 */ 82 MEM_SR, 83 84 /** 85 * Invalid memory type. 86 */ 87 MEM_INVALID 88 } GSM_MemoryType; 89 90 /** 91 * Returns string representation of a memory type. 92 * 93 * \param x Memory type to convert 94 * 95 * \return Static string. 96 * 97 * \ingroup Memory 98 */ 99 #define GSM_MemoryTypeToString(x) \ 100 ((x) == MEM_ME ? "ME" : \ 101 ((x) == MEM_SM ? "SM" : \ 102 ((x) == MEM_ON ? "ON" : \ 103 ((x) == MEM_DC ? "DC" : \ 104 ((x) == MEM_RC ? "RC" : \ 105 ((x) == MEM_MC ? "MC" : \ 106 ((x) == MEM_MT ? "MT" : \ 107 ((x) == MEM_FD ? "FD" : \ 108 ((x) == MEM_VM ? "VM" : \ 109 ((x) == MEM_QD ? "QD" : \ 110 ((x) == MEM_SL ? "SL" : \ 111 ((x) == MEM_SR ? "SR" : "XX")))))))))))) 112 113 /** 114 * Converts memory type from string. 115 * 116 * \param s String with memory type. 117 * 118 * \return Parsed memory type or 0 on failure. 119 */ 120 GSM_MemoryType GSM_StringToMemoryType(const char *s); 121 122 /** 123 * Structure contains info about number of used/free entries in phonebook 124 * memory. 125 * 126 * \ingroup Memory 127 */ 128 typedef struct { 129 /** 130 * Number of used entries 131 */ 132 int MemoryUsed; 133 /** 134 * Memory type 135 */ 136 GSM_MemoryType MemoryType; 137 /** 138 * Number of free entries 139 */ 140 int MemoryFree; 141 } GSM_MemoryStatus; 142 143 /** 144 * Type of specific phonebook entry. In parenthesis is specified in which 145 * member of @ref GSM_SubMemoryEntry value is stored. 146 * 147 * \ingroup Memory 148 */ 149 typedef enum { 150 /** 151 * General number. (Text) 152 */ 153 PBK_Number_General = 1, 154 /** 155 * Mobile number. (Text) 156 */ 157 PBK_Number_Mobile, 158 /** 159 * Fax number. (Text) 160 */ 161 PBK_Number_Fax, 162 /** 163 * Pager number. (Text) 164 */ 165 PBK_Number_Pager, 166 /** 167 * Other number. (Text) 168 */ 169 PBK_Number_Other, 170 /** 171 * Note. (Text) 172 */ 173 PBK_Text_Note, 174 /** 175 * Complete postal address. (Text) 176 */ 177 PBK_Text_Postal, 178 /** 179 * Email. (Text) 180 */ 181 PBK_Text_Email, 182 /* 183 * Second email. (Text) 184 */ 185 PBK_Text_Email2, 186 /** 187 * URL (Text) 188 */ 189 PBK_Text_URL, 190 /** 191 * Date and time of last call. (Date) 192 */ 193 PBK_Date, 194 /** 195 * Caller group. (Number) 196 */ 197 PBK_Caller_Group, 198 /** 199 * Name (Text) 200 */ 201 PBK_Text_Name, 202 /** 203 * Last name. (Text) 204 */ 205 PBK_Text_LastName, 206 /** 207 * First name. (Text) 208 */ 209 PBK_Text_FirstName, 210 /** 211 * Company. (Text) 212 */ 213 PBK_Text_Company, 214 /** 215 * Job title. (Text) 216 */ 217 PBK_Text_JobTitle, 218 /** 219 * Category. (Number, if -1 then text) 220 */ 221 PBK_Category, 222 /** 223 * Whether entry is private. (Number) 224 */ 225 PBK_Private, 226 /** 227 * Street address. (Text) 228 */ 229 PBK_Text_StreetAddress, 230 /** 231 * City. (Text) 232 */ 233 PBK_Text_City, 234 /** 235 * State. (Text) 236 */ 237 PBK_Text_State, 238 /** 239 * Zip code. (Text) 240 */ 241 PBK_Text_Zip, 242 /** 243 * Country. (Text) 244 */ 245 PBK_Text_Country, 246 /** 247 * Custom information 1. (Text) 248 */ 249 PBK_Text_Custom1, 250 /** 251 * Custom information 2. (Text) 252 */ 253 PBK_Text_Custom2, 254 /** 255 * Custom information 3. (Text) 256 */ 257 PBK_Text_Custom3, 258 /** 259 * Custom information 4. (Text) 260 */ 261 PBK_Text_Custom4, 262 /** 263 * Ringtone ID. (Number) 264 */ 265 PBK_RingtoneID, 266 /** 267 * Picture ID. (Number) 268 */ 269 PBK_PictureID, 270 /** 271 * User ID. (Text) 272 */ 273 PBK_Text_UserID, 274 /** 275 * Length of call (Number) 276 */ 277 PBK_CallLength, 278 /** 279 * LUID - Unique Identifier used for synchronisation (Text) 280 */ 281 PBK_Text_LUID, 282 /** 283 * Date of last modification (Date) 284 */ 285 PBK_LastModified, 286 /** 287 * Nick name (Text) 288 */ 289 PBK_Text_NickName, 290 /** 291 * Formal name (Text) 292 */ 293 PBK_Text_FormalName, 294 /** 295 * Picture name (on phone filesystem). (Text) 296 */ 297 PBK_Text_PictureName, 298 /** 299 * Push-to-talk ID (Text) 300 */ 301 PBK_PushToTalkID, 302 /** 303 * Favorite messaging number. (Text) 304 */ 305 PBK_Number_Messaging, 306 /** 307 * Photo (Picture). 308 */ 309 PBK_Photo, 310 /** 311 * Second name. (Text) 312 */ 313 PBK_Text_SecondName, 314 /** 315 * VOIP address (Text). 316 */ 317 PBK_Text_VOIP, 318 /** 319 * SIP address (Text). 320 */ 321 PBK_Text_SIP, 322 /** 323 * DTMF (Text). 324 */ 325 PBK_Text_DTMF, 326 /** 327 * Video number. (Text) 328 */ 329 PBK_Number_Video, 330 /** 331 * See What I See address. (Text) 332 */ 333 PBK_Text_SWIS, 334 /** 335 * Wireless Village user ID. (Text) 336 */ 337 PBK_Text_WVID, 338 /** 339 * Name prefix (Text) 340 */ 341 PBK_Text_NamePrefix, 342 /** 343 * Name suffix (Text) 344 */ 345 PBK_Text_NameSuffix, 346 } GSM_EntryType; 347 348 /** 349 * Location of memory contact. 350 * 351 * \ingroup Memory 352 */ 353 typedef enum { 354 /** 355 * No/Unknown location. 356 */ 357 PBK_Location_Unknown = 0, 358 /** 359 * Home 360 */ 361 PBK_Location_Home, 362 /** 363 * Work 364 */ 365 PBK_Location_Work, 366 } GSM_EntryLocation; 367 368 /** 369 * One value of phonebook memory entry. 370 * 371 * \ingroup Memory 372 */ 373 typedef struct { 374 /** 375 * Type of entry. 376 */ 377 GSM_EntryType EntryType; 378 /** 379 * Location for the entry. 380 */ 381 GSM_EntryLocation Location; 382 /** 383 * Text of entry (if applicable, see @ref GSM_EntryType). 384 */ 385 GSM_DateTime Date; 386 /** 387 * Number of entry (if applicable, see @ref GSM_EntryType). 388 */ 389 int Number; 390 /** 391 * Voice dialling tag. 392 */ 393 int VoiceTag; 394 int SMSList[20]; 395 int CallLength; 396 397 /** 398 * During adding SubEntry Gammu can return here info, if it was done OK 399 */ 400 GSM_Error AddError; 401 /** 402 * Text of entry (if applicable, see @ref GSM_EntryType). 403 */ 404 unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH + 1) * 2]; 405 /** 406 * Picture data. 407 */ 408 GSM_BinaryPicture Picture; 409 } GSM_SubMemoryEntry; 410 411 /** 412 * Structure for saving phonebook entries. 413 * 414 * \ingroup Memory 415 */ 416 typedef struct { 417 /** 418 * Used memory for phonebook entry 419 */ 420 GSM_MemoryType MemoryType; 421 /** 422 * Used location for phonebook entry 423 */ 424 int Location; 425 /** 426 * Number of SubEntries in Entries table. 427 */ 428 int EntriesNum; 429 /** 430 * Values of SubEntries. 431 */ 432 GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]; 433 } GSM_MemoryEntry; 434 435 /** 436 * Structure for saving speed dials. 437 * 438 * \ingroup Memory 439 */ 440 typedef struct { 441 /** 442 * Number of speed dial: 2,3..,8,9 443 */ 444 int Location; 445 /** 446 * ID of phone number used in phonebook entry 447 */ 448 int MemoryNumberID; 449 /** 450 * Memory, where is saved used phonebook entry 451 */ 452 GSM_MemoryType MemoryType; 453 /** 454 * Location in memory, where is saved used phonebook entry 455 */ 456 int MemoryLocation; 457 } GSM_SpeedDial; 458 459 /** 460 * Gets memory (phonebooks or calls) status (eg. number of used and 461 * free entries). 462 * 463 * \param s State machine pointer. 464 * \param status Storage for status information, MemoryType has to be 465 * set. 466 * 467 * \return Error code. 468 * 469 * \ingroup Memory 470 */ 471 GSM_Error GSM_GetMemoryStatus(GSM_StateMachine * s, GSM_MemoryStatus * status); 472 473 /** 474 * Reads entry from memory (phonebooks or calls). Which entry should 475 * be read is defined in entry. 476 * 477 * \param s State machine pointer. 478 * \param entry Storage for retrieved entry, MemoryType and Location has 479 * to be set. 480 * 481 * \return Error code. 482 * 483 * \ingroup Memory 484 */ 485 GSM_Error GSM_GetMemory(GSM_StateMachine * s, GSM_MemoryEntry * entry); 486 487 /** 488 * Reads entry from memory (phonebooks or calls). Which entry should 489 * be read is defined in entry. This can be easily used for reading all entries. 490 * 491 * \param s State machine pointer. 492 * \param entry Storage for retrieved entry. MemoryType has to be set 493 * for first call (with start set to TRUE), for subsequent calls 494 * Location has to stay intact from previous reading. 495 * \param start Whether we should start from beginning. 496 * 497 * \return Error code. 498 * 499 * \ingroup Memory 500 */ 501 GSM_Error GSM_GetNextMemory(GSM_StateMachine * s, GSM_MemoryEntry * entry, 502 gboolean start); 503 504 /** 505 * Sets memory (phonebooks or calls) entry. 506 * 507 * \param s State machine pointer. 508 * \param entry Entry to set, Location and MemoryType has to be set. 509 * 510 * \return Error code. 511 * 512 * \ingroup Memory 513 */ 514 GSM_Error GSM_SetMemory(GSM_StateMachine * s, GSM_MemoryEntry * entry); 515 516 /** 517 * Adds memory (phonebooks or calls) entry. 518 * 519 * \param s State machine pointer. 520 * \param entry Entry to add, Location is ignored, MemoryType has to be 521 * set. 522 * 523 * \return Error code. 524 * 525 * \ingroup Memory 526 */ 527 GSM_Error GSM_AddMemory(GSM_StateMachine * s, GSM_MemoryEntry * entry); 528 529 /** 530 * Deletes memory (phonebooks or calls) entry. 531 * 532 * \param s State machine pointer. 533 * \param entry Entry to delete, Location and MemoryType has to be set. 534 * 535 * \return Error code. 536 * 537 * \ingroup Memory 538 */ 539 GSM_Error GSM_DeleteMemory(GSM_StateMachine * s, GSM_MemoryEntry * entry); 540 541 /** 542 * Deletes all memory (phonebooks or calls) entries of specified type. 543 * 544 * \param s State machine pointer. 545 * \param MemoryType Where to delete all entries. 546 * 547 * \return Error code. 548 * 549 * \ingroup Memory 550 */ 551 GSM_Error GSM_DeleteAllMemory(GSM_StateMachine * s, GSM_MemoryType MemoryType); 552 553 /** 554 * Gets speed dial. 555 * 556 * \param s State machine pointer. 557 * \param Speed Storage for speed dial, Location has to be set. 558 * 559 * \return Error code. 560 * 561 * \ingroup Memory 562 */ 563 GSM_Error GSM_GetSpeedDial(GSM_StateMachine * s, GSM_SpeedDial * Speed); 564 565 /** 566 * Sets speed dial. 567 * 568 * \param s State machine pointer. 569 * \param Speed Sspeed dial to set. 570 * 571 * \return Error code. 572 * 573 * \ingroup Memory 574 */ 575 GSM_Error GSM_SetSpeedDial(GSM_StateMachine * s, GSM_SpeedDial * Speed); 576 577 /** 578 * Returns name of entry. It might be possibly concatenated from first 579 * and last names. 580 * 581 * \param entry Entry to process. 582 * 583 * \return Static unicode string containing name. 584 * 585 * \ingroup Memory 586 */ 587 unsigned char *GSM_PhonebookGetEntryName(const GSM_MemoryEntry * entry); 588 589 /** 590 * Finds default name, number and group for entry. 591 * 592 * \param entry Entry to process. 593 * \param Name Output index of name. 594 * \param Number Output index of number. 595 * \param Group Output index of group. 596 * 597 * \ingroup Memory 598 */ 599 void GSM_PhonebookFindDefaultNameNumberGroup(const GSM_MemoryEntry * entry, 600 int *Name, int *Number, 601 int *Group); 602 /** 603 * Types of vCard. 604 * 605 * \ingroup Memory 606 */ 607 typedef enum { 608 /** 609 * vCard 1.0 hacked for Nokia. 610 */ 611 Nokia_VCard10 = 1, 612 /** 613 * vCard 2.1 hacked for Nokia. 614 */ 615 Nokia_VCard21, 616 /** 617 * vCard 1.0 hacked for Sony-Ericsson (should be standard 618 * vCard). 619 */ 620 SonyEricsson_VCard10, 621 /** 622 * vCard 2.1 hacked for Sony-Ericsson (should be standard 623 * vCard). 624 */ 625 SonyEricsson_VCard21, 626 /** 627 * vCard 2.1 hacked for Sony-Ericsson (should be standard 628 * vCard) from phone (no parsing of location and memory type). 629 */ 630 SonyEricsson_VCard21_Phone, 631 } GSM_VCardVersion; 632 633 /** 634 * Encodes memory entry to vCard. 635 * 636 * \param di Pointer to debugging description. 637 * \param[out] Buffer Buffer to store vCard text. 638 * \param[in] buff_len Size of output buffer. 639 * \param[in,out] Pos Position in output buffer. 640 * \param[in,out] pbk Phonebook data, AddError will be set on non 641 * converted entries. 642 * \param[in] header Whether to include vCard header in output. 643 * \param[in] Version What vCard version to create. 644 * 645 * \return Error code. 646 * 647 * \ingroup Memory 648 */ 649 GSM_Error GSM_EncodeVCARD(GSM_Debug_Info * di, char *Buffer, 650 const size_t buff_len, size_t * Pos, 651 GSM_MemoryEntry * pbk, const gboolean header, 652 const GSM_VCardVersion Version); 653 654 /** 655 * Decodes memory entry from vCard. 656 * 657 * \param di Pointer to debugging description. 658 * \param[in] Buffer Buffer to readCard text. 659 * \param[in,out] Pos Position in output buffer. 660 * \param[out] Pbk Phonebook data read from vCard. 661 * \param[in] Version What vCard version to parse. 662 * 663 * \return Error code. 664 * 665 * \ingroup Memory 666 */ 667 GSM_Error GSM_DecodeVCARD(GSM_Debug_Info * di, char *Buffer, size_t * Pos, 668 GSM_MemoryEntry * Pbk, 669 const GSM_VCardVersion Version); 670 671 /** 672 * Frees any dynamically allocated memory inside memory 673 * entry structure. 674 * 675 * \param[in] Entry Pointer to memory entry to process. 676 */ 677 void GSM_FreeMemoryEntry(GSM_MemoryEntry * Entry); 678 #ifdef __cplusplus 679 } 680 #endif 681 #endif 682 683 /* Editor configuration 684 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: 685 */ 686