picturemsg.c 56.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 * pictruemsg.c
 *
 * Project:
 * --------
 * PDG1
 *
 * Description:
 * ------------
 * This file implements Picture Message back end application.
 *
 * Author:
 * -------
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 */
#include "MMI_include.h"

#if defined(__MMI_SMART_MESSAGE_MT__) || (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__))

#ifndef _MMI_PICMSG_C
#define _MMI_PICMSG_C

// #ifdef __MMI_PICMSG__

/*  Include: MMI header file */
#include "picturemsg.h"
#include "PicMsgApiToOthers.h"
#include "CommonNSM.h"
#include "ems.h"
#include "customer_ps_inc.h"

#include "smsguiinterfacetype.h"

/*  Include: PS header file */
/* ... Add More PS header */

/* 
 ************************* Define ****************************
 */
#define MODULUS                  241
#define ONE_BYTE_SIZE            8
#define MMI_EXTRA_BMP_HEADER_SIZE   6
#define PIC_MSG_SIGNATURE        "0504158A"
#define RING_TONE_MSG_SIGNATURE     "05041581"
#define BMP_HEADER_SIZE          (sizeof(BmpFileHeader_sturct)-2)
#define MAX_PIC_HIEGHT_PIXEL     32
#define MAX_PIC_WIDTH_PIXEL         96 / ONE_BYTE_SIZE  /* We store 8 bits in one bytes */
#define MAX_BMP_HDR_SIZE         64

/* Start JP */
#define     MAX_NSM_PIC_WIDTH    72
#define     MAX_NSM_PIC_HEIGHT      28
/* End JP */

/* 
 *************************** Typedef  *******************************
 */
typedef enum
{
    SMRT_NORMAL_SMS_0,
    SMRT_PICTURE_SMS_1,
    SMRT_RING_TONE_SMS_2
} smrt_sms_type_enum;

typedef enum
{
    PMSG_FIRST_FOUR_BITS = 1,
    PMSG_SECOND_FOUR_BITS = 2
} pmsg_bits_position_enum;

/* 
 *************** Function Declaration *****************************
 */

S16 mmi_smrt_message_type(U8 *SmsData);

#if (0)
/* under construction !*/
/* under construction !*/
#endif /* (0) */ 

U8 *mmi_pmsg_convert_ota_to_bmp(U8 *otaData);
U8 *mmi_pmsg_convert_bmp_to_ota(U8 *BmpBuffer);
U8 mmi_pmsg_convert_ascii_hex_to_dec(S8 character);
U8 mmi_pmsg_convert_binary_dec_to_hex(const U8 DecimalVal, U8 part);

void mmi_pmsg_convert_ascii_hex_string_2_dec_string(U8 *DecStr, U8 *AsciiStr);
void mmi_pmsg_convert_dec_string_2_ascii_hex_string(U8 *AsciiStr, U8 *DecStr);

U8 *mmi_pmsg_create_ota_data(U8 *BinaryData, S16 H, S16 W);
U8 *mmi_pmsg_create_bmp_data(void);
void mmi_pmsg_set_default_values_bmp_header(void);
S16 mmi_pmsg_read_picture_header(U8 *OtaPattern);
S16 mmi_pmsg_read_bmp_data(U8 *RawData, U8 *BmpData, S16 *H, S16 *W);
U16 mmi_pmsg_get_size_bmp_data(U8 *BmpData);
U16 mmi_pmsg_get_size_ota_data(U8 *OtaBuffer);
BOOL mmi_pmsg_is_smart_picture(U8 *BmpData);

S16 mmi_pmsg_add_bmp_header_info(U8 *BmpData);
U16 mmi_pmsg_add_picture_text(U8 *OtaData, U8 *TextBuffer);
void mmi_pmsg_add_nokia_header(U8 *PictureMessage, U8 TotalSegment, U8 CurrentSegment);
void mmi_pmsg_add_header(U8 *header, U16 HeaderLen, U8 *Data, U16 DataLen);

void mmi_pmsg_shift_n_bytes(S8 *Data, S16 offset, S16 nBytes, S16 length);
U8 mmi_pmsg_get_n_bits(U8 *Data, U16 Offset, U16 Bits);
U8 mmi_pmsg_get_next_byte(void);
void mmi_pmsg_fskip(FS_HANDLE fp, S16 num_bytes);

S16 mmi_pmsg_string_search(S8 *Pattern, S8 *Text);
S16 mmi_pmsg_hash(S8 *str);
S16 mmi_pmsg_HashN(S8 *Str, S16 PatternLength);
S16 mmi_pmsg_HashIncrement(S8 *str, S16 PrevIndex, S16 PrevHash, S16 PatternLength);

/* 
 ************************ Global Variables ****************************
 */
/* This is a BMP Header which strored the information of file */
static BmpFileHeader_sturct g_pmsg_BmpHeader;

/*  This var shall store the pointer of OTA data to retrieve the values */
static U8 *OTAdata = NULL;

/*  This var shall store the pointer index of OTA data to retrieve the values */
static U16 g_pmsg_ota_index = 0;

/* This var shall store the Text of Picture message and shall be used by Category screen to show the text */
S8 g_pmsg_TextInMessage[MAX_PICTEXT_BUFF_SIZE + (TEXT_BUFF_PADDING)];

/* This var shall store the Ota Picture len */
static U16 gOtaDataLen = 0;

#if (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__))
extern nsm_msg_struct g_nsm_msg_context;
#endif 

#if defined(__MMI_SMART_MESSAGE_MT__)
#include "MessagesExDcl.h"
extern nsm_picmsg_text_struct picmsg_text_struct;
#endif /* defined(__MMI_SMART_MESSAGE_MT__) */ 
/* 
 ************************ Global Functions ****************************
 */
extern EMSData *GetEMSDataForView(EMSData **p, U8 force);

/* 
 ************************ Temp Var for testing and debugging the code ********
 */
// Assh..whole data.
//S8  OTAdata[] = "0B0504158A000000030103013000000002010000481C01FF5C0151C104555FFFFEAA00278A00AAAFFFFF5C00001500155FFFBEB8000802002AAFFF7FD8005D04000557FFBFF800012800DAAFFF5FF0000E40001557FFBEF80000A0008AABFF5FD0000100001555FFAFF8000080000AABFF55D8000000000555FFAAB8800000000AAAFF557DC000001505557F0B0504158A00000003010302AAAAF80002EFA22AFF555C100015F554457FA0A80A802FA0AA22FF405801405500151474A028E880AA280280BE4015DC01557F00047EA029FE002AFFA802BE4015FF4055FFF4007C800BAC80AAACF800BE00101440151C14015D80A88800AB382800BA415841005110540155AAA82000A80B8000AA555801005415000150AAA80B0504158A000000030103030200A8000002A8";
// Line S8  OTAdata[] = "00480E01803804020300C01800600C06030100400C002006020301806006001802010080C030010008030180C0600800C0060180C040300600600200C040201003003001806020301801801800802030100C00800C006030101806004006002018180C030060030018080C060100200000080C040301803000000606020100801000";
// Chess Data.
//S8  OTAdata[] = "0040400100FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF0000FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF0000FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF0000FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FFFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00";
// PMT data.
//S8  OTAdata[] = "00481C01FFFFFFFFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFF000000FFFFFFFFFFFFFFFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF5FFFAFFAFFFAFFFF000000FF57FFAFFAFFFAFFFF000000FF59FFAF7AFFFAFFFF000000FF5E0FAEBAFFFAFFFF000000FF5FEFADDAFFFAFFFF000000FF5FEFADDAFFFAFFFF000000FF5FEFBBEEFFFAFFFF000000FF5F0FB7F6FFFAFFFF000000";
// Function Spec data.
//S8  OTAdata[] = "00480E01FFFFFFFFFFFFFFFFFF000000000000000000FFFFFFFFFFFFFFFFFF00000000000000000010F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001";

/*********************************************************************************
 ************************* Funtion Definition Starts *****************************
 *********************************************************************************/


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_set_default_values_bmp_header
 * DESCRIPTION
 *  Set default values in BMP Header.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_pmsg_set_default_values_bmp_header(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(&g_pmsg_BmpHeader, 0x00, BMP_HEADER_SIZE + 2);
    g_pmsg_BmpHeader.BmpBMPFileHeader.Signature = (U16) 19778;
    g_pmsg_BmpHeader.BmpBMPFileHeader.DataOffset = (U32) BMP_HEADER_SIZE;
    g_pmsg_BmpHeader.BmpBMPInfoHeader.HeaderSize = (U32) 40;
    g_pmsg_BmpHeader.BmpBMPInfoHeader.Bits = (U16) 1;
    g_pmsg_BmpHeader.BmpBMPInfoHeader.Planes = (U16) 1;
    g_pmsg_BmpHeader.BmpColors1.Blue = (U8) 255;
    g_pmsg_BmpHeader.BmpColors1.Green = (U8) 255;
    g_pmsg_BmpHeader.BmpColors1.Red = (U8) 255;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_convert_ota_to_bmp
 * DESCRIPTION
 *  Converter of OTA format to BMP format.
 * PARAMETERS
 *  Data        [?]     
 *  S8 *, OTA data.(?)
 * RETURNS
 *  void
 *****************************************************************************/
U8 *mmi_pmsg_convert_ota_to_bmp(U8 *Data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 PictureHeaderLen = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    g_pmsg_ota_index = 0;

    PictureHeaderLen = mmi_pmsg_read_picture_header(Data);

    if (PictureHeaderLen == -1)
    {
        return NULL;
    }

    mmi_pmsg_shift_n_bytes((S8*) Data, 0, (S16) PictureHeaderLen, gOtaDataLen);        /* Remove the Picture Message Header */

    OTAdata = Data;

    mmi_pmsg_set_default_values_bmp_header();

    return mmi_pmsg_create_bmp_data();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_convert_bmp_to_ota
 * DESCRIPTION
 *  Convets the BMP file format to OTA format
 * PARAMETERS
 *  BmpBuffer       [?]     
 *  Bmp Buffer.(?)
 * RETURNS
 *  Pointer to OTA data.
 *****************************************************************************/
U8 *mmi_pmsg_convert_bmp_to_ota(U8 *BmpBuffer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 Hight = 0;
    S16 Width = 0;

    /* U8 BmpBinaryData[(PIC_BUFF_MAX_LEN)]; */
    U8 *BmpBinaryData;
    U8 *ptr_OtaData = NULL;
    U8 *BmpDataPtr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* AshBmpDataHex */
    BmpBinaryData = OslMalloc(PIC_BUFF_MAX_LEN);
    BmpDataPtr = BmpBuffer + MMI_EXTRA_BMP_HEADER_SIZE; /* removed the MMI header information */

    memset(BmpBinaryData, '\0', (PIC_BUFF_MAX_LEN));

    if (mmi_pmsg_read_bmp_data(BmpBinaryData, BmpDataPtr, &Hight, &Width) != 0)
    {
        return NULL;
    }

    ptr_OtaData = mmi_pmsg_create_ota_data(BmpBinaryData, Hight, Width);
    OslMfree(BmpBinaryData);
    /* return mmi_pmsg_create_ota_data(BmpBinaryData, Hight,Width); */
    return ptr_OtaData;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_read_bmp_data
 * DESCRIPTION
 *  Read the whole bits format of Bmp file.
 * PARAMETERS
 *  RawData     [?]     
 *  BmpData     [?]     
 *  H           [?]     
 *  W           [?]     
 *  File Name with Path of Bmp file and pointe of data to store picture data.(?)
 * RETURNS
 *  -1 if any error.
 *****************************************************************************/
S16 mmi_pmsg_read_bmp_data(U8 *RawData, U8 *BmpData, S16 *H, S16 *W)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 RotatedData[MAX_PIC_HIEGHT_PIXEL][MAX_PIC_WIDTH_PIXEL];
    S16 i = 0, j = 0;
    S16 width = 0;
    S16 height = 0;
    S16 num_colors = 0;
    S16 index = 0;
    S16 x = 0;
    BOOL complement_flag = FALSE;   /* JP for predefined NSM Pictures */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(RotatedData, '\0', MAX_PIC_HIEGHT_PIXEL * MAX_PIC_WIDTH_PIXEL);

    /* check to see if it is a valid bitmap file */

    if ((BmpData[index++] != 'B') || (BmpData[index++] != 'M'))
    {
        return -1;
    }

    /* read in the width and height of the image, and the number of colors used; ignore the rest */
    index += 16;

    width = BmpData[index++];
    width |= BmpData[index++] << ONE_BYTE_SIZE;

    index += 2;

    height = BmpData[index++];
    height |= BmpData[index++] << ONE_BYTE_SIZE;

    index += 22;

    num_colors = BmpData[index++];
    num_colors |= BmpData[index++] << ONE_BYTE_SIZE;

    if (num_colors > 1)
    {
        complement_flag = TRUE;
        /* return -1; *//* JP commented for tracker issue 396 */
    }

    /* First Header end. */
    index += 6;

    /* Skip the color table */
    index += 8;

    if (width / ONE_BYTE_SIZE > 8)
    {
        j = 12;
    }
    else
    {
        j = 8;
    }

    for (x = 0; x < height; x++)
    {
        for (i = 0; i < j; i++)
        {
            /* 
             * JP 20050629
             * We have to complement Predfined NSM
             * Picture data
             */
            if (complement_flag)
            {
                RotatedData[x][i] = (~BmpData[index++]);
            }
            else
            {
                RotatedData[x][i] = (BmpData[index++]);
            }

        }
    }

    index = 0;

    for (i = x - 1; i >= 0; i--)
    {
        for (j = 0; j < width / ONE_BYTE_SIZE; j++)
        {
            RawData[index++] = RotatedData[i][j];
        }
    }

    *H = height;
    *W = width;

    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_create_bmp_data
 * DESCRIPTION
 *  Prepared the BMP file format based on OTA data.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
U8 *mmi_pmsg_create_bmp_data()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 BmpDataHeader[MAX_BMP_HDR_SIZE];
    U8 RotatedData[MAX_PIC_HIEGHT_PIXEL][MAX_PIC_WIDTH_PIXEL];
    U8 *BmpData = NULL;
    S16 HeaderLen = 0;
    S16 TotalSizeOfBmp = 0;
    S16 index = 0;
    S16 x = 0, i = 0, j = 0, k = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(RotatedData, '\0', MAX_PIC_HIEGHT_PIXEL * MAX_PIC_WIDTH_PIXEL);
    memset(BmpDataHeader, '\0', MAX_BMP_HDR_SIZE);

    /* this is info field. */
    mmi_pmsg_get_next_byte();

    /* this is width field. */
    g_pmsg_BmpHeader.BmpBMPInfoHeader.Width = (U32) mmi_pmsg_get_next_byte();

    /* this is height field. */
    g_pmsg_BmpHeader.BmpBMPInfoHeader.Height = (U32) mmi_pmsg_get_next_byte();

    /* this is Depth field. */
    mmi_pmsg_get_next_byte();

    HeaderLen = (S16) g_pmsg_BmpHeader.BmpBMPInfoHeader.Width / ONE_BYTE_SIZE;

    for (i = 0; i < gOtaDataLen; i++)
    {
        RotatedData[j][k] = mmi_pmsg_get_next_byte();
        k++;
        if (k >= HeaderLen)
        {
            k = 0;
            j++;
        }
    }

    if (HeaderLen > 8)
    {
        HeaderLen = 12;
    }
    else if (HeaderLen > 4)
    {
        HeaderLen = 8;
    }
    else
    {
        HeaderLen = 4;
    }

    /* Six extra bytes added for MMI support */
    TotalSizeOfBmp = BMP_HEADER_SIZE + (HeaderLen * j) + MMI_EXTRA_BMP_HEADER_SIZE;

    /* Put the real size of BMP */
    g_pmsg_BmpHeader.BmpBMPFileHeader.FileSize = (U32) TotalSizeOfBmp - MMI_EXTRA_BMP_HEADER_SIZE;

    memcpy(&BmpDataHeader, &g_pmsg_BmpHeader, BMP_HEADER_SIZE + 2);

    BmpData = (U8*) OslMalloc(TotalSizeOfBmp);
    /* memset((S8*)BmpData,'\0',TotalSizeOfBmp); */

    BmpData[index++] = 0x1;
    BmpData[index++] = 0x0;
    BmpData[index++] = (U8) ((g_pmsg_BmpHeader.BmpBMPFileHeader.FileSize & 0x000000FF));
    BmpData[index++] = (U8) ((g_pmsg_BmpHeader.BmpBMPFileHeader.FileSize & 0x0000FF00) >> 8);
    BmpData[index++] = (U8) ((g_pmsg_BmpHeader.BmpBMPFileHeader.FileSize & 0x00FF0000) >> 16);
    BmpData[index++] = (U8) ((g_pmsg_BmpHeader.BmpBMPFileHeader.FileSize & 0xFF000000) >> 24);

    for (i = 0; i < BMP_HEADER_SIZE; i++)
    {
        BmpData[index++] = BmpDataHeader[i + 2];
    }

    for (i = j - 1; i >= 0; i--)
    {
        for (x = 0; x < HeaderLen; x++)
        {
            BmpData[index++] = RotatedData[i][x];
        }
    }

    return (U8*) BmpData;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_get_next_byte
 * DESCRIPTION
 *  Combine the two Hex value
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
U8 mmi_pmsg_get_next_byte(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 value;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    value = OTAdata[g_pmsg_ota_index];
    g_pmsg_ota_index++;

    return value;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_get_n_bits
 * DESCRIPTION
 *  Find out the required bits in given data.
 * PARAMETERS
 *  Data        [?]         Offset and req bits.
 *  Offset      [IN]        
 *  Bits        [IN]        
 * RETURNS
 *  Bits value.
 *****************************************************************************/
U8 mmi_pmsg_get_n_bits(U8 *Data, U16 Offset, U16 Bits)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 index = Offset / ONE_BYTE_SIZE;
    U8 BitsfromFirstIndex = ONE_BYTE_SIZE - (Offset % ONE_BYTE_SIZE);
    U8 firstByte = Data[index];
    U8 secondByte = Data[index + 1];
    U8 result = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (Bits > ONE_BYTE_SIZE)
    {
        return 0;
    }

    result = (firstByte << (ONE_BYTE_SIZE - BitsfromFirstIndex)) | (secondByte >> BitsfromFirstIndex);

    result = result >> (ONE_BYTE_SIZE - Bits);

    return result;

}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_convert_ascii_hex_to_dec
 * DESCRIPTION
 *  Converts Ascii value to Decimal value
 * PARAMETERS
 *  character       [IN]        
 *  S8 ascii values(?)
 * RETURNS
 *  U8 Decimal value.
 *****************************************************************************/
U8 mmi_pmsg_convert_ascii_hex_to_dec(S8 character)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (character > 47 && character < 58)   /* Digits 0..9 */
    {
        return (character - 48);
    }
    else if (character > 64 && character < 71)  /* Characters A..F */
    {
        return (character - 55);
    }
    else if (character > 96 && character < 103) /* Characters a..f */
    {
        return (character - 87);
    }
    else
    {
        return (0xFF);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_convert_binary_dec_to_hex
 * DESCRIPTION
 *  Converts Binary value to Hex value.
 * PARAMETERS
 *  DecimalVal      [IN]        
 *  part            [IN]        Which says about first byte or second byte data needed.
 * RETURNS
 *  U8 Hex value.
 *****************************************************************************/
U8 mmi_pmsg_convert_binary_dec_to_hex(const U8 DecimalVal, U8 part)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 Firstpart = 0xf0 & DecimalVal;
    U8 Secondpart = 0xf & DecimalVal;
    U8 ReturnVal = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    Firstpart >>= 4;

    ReturnVal = Secondpart;
    if (part == PMSG_FIRST_FOUR_BITS)
    {
        ReturnVal = Firstpart;
    }

    if (ReturnVal < 10)
    {
        ReturnVal += 48;
    }
    else
    {
        ReturnVal += 55;
    }

    return ReturnVal;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_fskip
 * DESCRIPTION
 *  Skip the file pointer of num bytes.
 * PARAMETERS
 *  fp              [IN]        
 *  num_bytes       [IN]        
 *  file pointer and skip times.(?)
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_pmsg_fskip(FS_HANDLE fp, S16 num_bytes)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 errorCode = 0;
    S8 Data[64];
    U32 read_len = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    FS_Read( fp, (void*)Data, num_bytes, &read_len);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_create_ota_data
 * DESCRIPTION
 *  Creates OTA file.
 * PARAMETERS
 *  BinaryData      [?]         
 *  H               [IN]        
 *  W               [IN]        
 *  Pointer to OTA data,Pointer of binary data, Hieght and width.(?)
 * RETURNS
 *  void
 *****************************************************************************/
U8 *mmi_pmsg_create_ota_data(U8 *BinaryData, S16 H, S16 W)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 i = 0;
    S16 index = 0;
    U8 *OtaData = NULL;
    U16 DataSize = (H * W / ONE_BYTE_SIZE) + 4; /* infofield, width, height, and depth */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    gOtaDataLen = DataSize;
    OtaData = (U8*) OslMalloc(MAX_DATA_SIZE);
    memset(OtaData, '\0', MAX_DATA_SIZE);

    /* Put OTA tyep field */
    OtaData[index++] = 0x02;

    /* Put OTA Size field */
    OtaData[index++] = (U8) ((DataSize & 0xff00) >> ONE_BYTE_SIZE);
    OtaData[index++] = (U8) (DataSize & 0x00ff);

    /* Put Info field */
    OtaData[index++] = 0x00;

    /* Put width */
    OtaData[index++] = (U8) W;

    /* Put Hieght */
    OtaData[index++] = (U8) H;

    /* Put Color */
    OtaData[index++] = 0x01;

    /* Put Data */
    for (i = 0; i < W * H / ONE_BYTE_SIZE; i++)
    {
        OtaData[index++] = BinaryData[i];
    }

    return OtaData;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_string_search
 * DESCRIPTION
 *  This algorithm uses hashing to implement string searching in linear time.
 * PARAMETERS
 *  Pattern     [?]     
 *  Text        [?]     In which pattern is to be search.
 * RETURNS
 *  if success then starting location of pattern else -1 if pattern not found.
 *****************************************************************************/
S16 mmi_pmsg_string_search(S8 *Pattern, S8 *Text)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 num_iteration = 0;
    S16 PatternLength = 0;
    S16 PatternHash = 0;
    S16 TextHash = 0;
    S16 i = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (Pattern == NULL || Text == NULL)
    {
        return -1;
    }
    else
    {

        PatternLength = strlen((S8*) Pattern);
        num_iteration = strlen((S8*) Text) - PatternLength + 1;

        /* Find initial hash values for Pattern and Text */
        /* These are called FINGERPRINT */
        PatternHash = mmi_pmsg_hash(Pattern);
        TextHash = mmi_pmsg_HashN(Text, PatternLength);

        for (i = 0; i < num_iteration; i++)
        {
            if ((PatternHash == TextHash) && !(strncmp(Pattern, (Text + i), PatternLength)))
            {
                return i;
            }
            TextHash = mmi_pmsg_HashIncrement(Text, i, TextHash, PatternLength);
        }
    }

    return -1;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_hash
 * DESCRIPTION
 *  Calculate the hash of given string.
 * PARAMETERS
 *  str     [?]     
 *  Pointer to given string.(?)
 * RETURNS
 *  Hash value.
 *****************************************************************************/
S16 mmi_pmsg_hash(S8 *str)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 sum = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (; *str; str++)
    {
        sum += *str;
    }

    return sum % MODULUS;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_HashN
 * DESCRIPTION
 *  Calculate the hash value of given number of bytes.
 * PARAMETERS
 *  Str                 [?]         
 *  PatternLength       [IN]        
 *  Pointer to Data, Length of Pattern which hash value to be needed.(?)
 * RETURNS
 *  Calculated hash value.
 *****************************************************************************/
S16 mmi_pmsg_HashN(S8 *Str, S16 PatternLength)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 ch = Str[PatternLength];
    S16 HashValue;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    Str[PatternLength] = '\0';
    HashValue = mmi_pmsg_hash(Str);
    Str[PatternLength] = ch;

    return HashValue;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_HashIncrement
 * DESCRIPTION
 *  Increment the hash values by removing previous value and adding next value.
 * PARAMETERS
 *  str                 [?]         
 *  PrevIndex           [IN]        
 *  PrevHash            [IN]        
 *  PatternLength       [IN]        
 *  Pointer to given String, Previous Index, Previous hash value, Pattern Length.(?)
 * RETURNS
 *  New hash value.
 *****************************************************************************/
S16 mmi_pmsg_HashIncrement(S8 *str, S16 PrevIndex, S16 PrevHash, S16 PatternLength)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 val;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    val = (PrevHash - (S16) str[PrevIndex]) + (str[PrevIndex + PatternLength]);

    return val < 0 ? val + MODULUS : val % MODULUS;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_shift_n_bytes
 * DESCRIPTION
 *  Remove the specified N byte from the given Data and shift the whole values.
 * PARAMETERS
 *  Data        [?]         Location from Data to be removed, Number of byte to be removed.
 *  offset      [IN]        
 *  nBytes      [IN]        
 *  length      [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_pmsg_shift_n_bytes(S8 *Data, S16 offset, S16 nBytes, S16 length)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 index = offset, j = 0;
    S8 *DataPtr = Data + offset + nBytes;
    S16 len = length;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    while (len > 0)
    {
        Data[index++] = *DataPtr++;
        len--;
    }

    for (j = 0; j < nBytes; j++)
    {
        Data[index++] = '\0';
    }

}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_add_header
 * DESCRIPTION
 *  Add the Header into given data. ( Data must be big enought to add header buffer)
 * PARAMETERS
 *  header          [?]         
 *  HeaderLen       [IN]        
 *  Data            [?]         & Data Size.
 *  DataLen         [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_pmsg_add_header(U8 *header, U16 HeaderLen, U8 *Data, U16 DataLen)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *DataBackUp = NULL;
    U16 i = 0, j = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    DataBackUp = (U8*) OslMalloc(DataLen + HeaderLen + 4);
    memset(DataBackUp, 0x00, (DataLen + HeaderLen + 4));

    while (j < HeaderLen)
    {
        DataBackUp[i++] = header[j];
        j++;
    }

    j = 0;
    while (j < DataLen)
    {
        DataBackUp[i++] = Data[j];
        j++;
    }

    memset(Data, 0x00, i + 1);

    j = 0;
    while (j < i)
    {
        Data[j] = DataBackUp[j];
        j++;
    }
    OslMfree(DataBackUp);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_read_picture_header
 * DESCRIPTION
 *  Read the Picture Header information and put the checks.
 * PARAMETERS
 *  OtaPattern      [?]     
 *  Pointer to OtaData.(?)
 * RETURNS
 *  If error return -1 else len of picture message header.
 *****************************************************************************/
S16 mmi_pmsg_read_picture_header(U8 *OtaPattern)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 RecvVal = 0;
    U16 index = 0;
    S16 i = 0;
    U16 OtaDataLen = 0;

    /* S8 tempTextBuffer[MAX_PICTEXT_BUFF_SIZE+(TEXT_BUFF_PADDING)]; */
    S8 *tempTextBuffer = NULL;
    U16 charType = 0;
    EMSData *pEms;
    U16 EmsDataLen = 0;
    U8 missSegStr[] = EMS_MISS_SEG_DELIMIT_STR;
    U16 missSegStrLen = strlen((const char*)missSegStr);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    GetEMSDataForView(&pEms, 0);
    EmsDataLen = pEms->textLength / 2;
    memset(g_pmsg_TextInMessage, '\0', MAX_PICTEXT_BUFF_SIZE + (TEXT_BUFF_PADDING));

    /* Version Information */
    RecvVal = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
    index += ONE_BYTE_SIZE;

    if (RecvVal != 48)
    {
        return -1;
    }

    /* Type */
    RecvVal = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
    index += ONE_BYTE_SIZE;
    charType = RecvVal;

    if (RecvVal == 0 || RecvVal == 1)   /* Message Text */
    {
        /* Item Len */
        OtaDataLen = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
        index += ONE_BYTE_SIZE;

        RecvVal = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
        index += ONE_BYTE_SIZE;

        OtaDataLen <<= ONE_BYTE_SIZE;
        OtaDataLen = OtaDataLen | RecvVal;

        /* tempTextBuffer = OslMalloc((MAX_PICTEXT_BUFF_SIZE+TEXT_BUFF_PADDING)); */
        tempTextBuffer = OslMalloc((OtaDataLen) + TEXT_BUFF_PADDING);

        /* memset(tempTextBuffer, '\0',(MAX_PICTEXT_BUFF_SIZE+TEXT_BUFF_PADDING)); */
        memset(tempTextBuffer, '\0', ((OtaDataLen) + TEXT_BUFF_PADDING));

        /* Read the Text */
        for (i = 0; i < OtaDataLen; i++)
        {
            tempTextBuffer[i] = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
            index += ONE_BYTE_SIZE;
        }

        if (charType == 0)
        {
            mmi_asc_to_ucs2((S8*) g_pmsg_TextInMessage, (S8*) tempTextBuffer);
        }
        else
        {
            /* For Unicode character : JP */
            {
                S32 count = 0;
                U8 temp = 0;

                while (count < OtaDataLen)
                {
                    temp = tempTextBuffer[count];
                    tempTextBuffer[count] = tempTextBuffer[count + 1];
                    tempTextBuffer[count + 1] = temp;
                    count = count + 2;
                }

                mmi_ucs2cpy((S8*) g_pmsg_TextInMessage, (S8*) (tempTextBuffer));
            }
        }
        OslMfree(tempTextBuffer);

        /* Read the OTA bitmat type : 02 */
        RecvVal = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
        index += ONE_BYTE_SIZE;

        if (RecvVal != 2)
        {
            return -1;
        }
    }
    else if (RecvVal == 2)
    {
        /* There is not text part in message */
    }
    else
    {
        return -1;
    }

    OtaDataLen = 0;

    /* Read the len of OTA data */
    OtaDataLen = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
    index += ONE_BYTE_SIZE;

    RecvVal = mmi_pmsg_get_n_bits(OtaPattern, index, ONE_BYTE_SIZE);
    index += ONE_BYTE_SIZE;

    OtaDataLen <<= ONE_BYTE_SIZE;
    gOtaDataLen = OtaDataLen | RecvVal;

    /* Incomplete message content */
    if (((EmsDataLen - (index / ONE_BYTE_SIZE)) < gOtaDataLen) ||
        !strncmp((const char*)(OtaPattern + (EmsDataLen - missSegStrLen)), (const char*)missSegStr, missSegStrLen))
    {
        return -1;
    }

    return (index / ONE_BYTE_SIZE);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_smrt_message_type
 * DESCRIPTION
 *  Find Out the type of Message.
 * PARAMETERS
 *  SmsData     [?]     
 *  Pointer to SMS data.(?)
 * RETURNS
 *  TYPE of SMS ( Normal, Picture or Ring Tone)
 *****************************************************************************/
S16 mmi_smrt_message_type(U8 *SmsData)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 IsFindPattern = -1;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* search the picture message signature */
    IsFindPattern = mmi_pmsg_string_search((S8*) PIC_MSG_SIGNATURE, (S8*) SmsData);
    if (IsFindPattern >= 0)
    {
        return SMRT_PICTURE_SMS_1;
    }

    /* search the ring tone message signature */
    IsFindPattern = mmi_pmsg_string_search((S8*) RING_TONE_MSG_SIGNATURE, (S8*) SmsData);
    if (IsFindPattern >= 0)
    {
        return SMRT_RING_TONE_SMS_2;
    }

    /* search the ring tone message signature */
    IsFindPattern = mmi_pmsg_string_search((S8*) RING_TONE_MELODY_SIGNATURE, (S8*) SmsData);
    if (IsFindPattern >= 0)
    {
        return SMRT_RING_TONE_SMS_2;
    }

    /* It is neither Picture massage nor Rong tone */
    return SMRT_NORMAL_SMS_0;
}

#if (0)
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif /* (0) */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_add_picture_text
 * DESCRIPTION
 *  Prepared the Picture message format and add the picture text.
 * PARAMETERS
 *  OtaData         [?]     
 *  TextBuffer      [?]     
 *  OTA data & text buffer.(?)
 * RETURNS
 *  Length of OTA data with header.
 *****************************************************************************/
U16 mmi_pmsg_add_picture_text(U8 *OtaData, U8 *TextBuffer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 TextLen;                    /* = (mmi_ucs2strlen((S8*)TextBuffer)*2); */
    U16 DataLen = gOtaDataLen + 3;  /* type (02 for OTA-bitmap), length ( 2 bytes) */

    /* U8  OtaText[MAX_PICTEXT_BUFF_SIZE+TEXT_BUFF_PADDING]; */
    U8 *OtaText = NULL;
    U16 index = 0, i = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    OtaText = OslMalloc((MAX_PICTEXT_BUFF_SIZE + TEXT_BUFF_PADDING));
    memset(OtaText, 0x00, MAX_PICTEXT_BUFF_SIZE + TEXT_BUFF_PADDING);

    /* Version */
    OtaText[index++] = 0x30;

#if (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__))

    if (g_nsm_msg_context.UCS2_count > 0)
    {
        /* text type */
        OtaText[index++] = 0x01;
        TextLen = (mmi_ucs2strlen((S8*) TextBuffer) * 2); /* JP */
    }
    else
    {
        /* text type */
        OtaText[index++] = 0x00;
        TextLen = strlen((S8*) TextBuffer); /* JP */
    }

#elif defined(__MMI_SMART_MESSAGE_MT__)

    if (picmsg_text_struct.ucs2_count > 0)
    {
        /* text type */
        OtaText[index++] = 0x01;
        TextLen = (mmi_ucs2strlen((S8*) TextBuffer) * 2); /* JP */
    }
    else
    {
        /* text type */
        OtaText[index++] = 0x00;
        TextLen = strlen((S8*) TextBuffer); /* JP */
    }
#endif 

    /* text length */
    OtaText[index++] = (U8) ((TextLen & 0xff00) >> ONE_BYTE_SIZE);
    OtaText[index++] = (U8) (TextLen & 0x00ff);

#if defined(__MMI_SMART_MESSAGE_MT__)
    if (picmsg_text_struct.ucs2_count > 0)
    {
#elif (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__))
    if (g_nsm_msg_context.UCS2_count > 0)
    {
#endif 
        /* For Unicode text : Reverse bytes order for Nokia chinese problem */
        {
            U8 temp1 = 0;
            U8 temp2 = 0;
            U8 temparr[3] = {0, 0, 0};
            U16 count = 0;

            while (i < TextLen)
            {
                temp1 = TextBuffer[i];
                i++;
                temp2 = TextBuffer[i];
                i++;
                temparr[0] = temp2;
                temparr[1] = temp1;
                for (count = 0; count < 2; count++)
                {
                    OtaText[index++] = (U8) temparr[count];
                }

                /* Reset all temp variables */
                temp1 = 0;
                temp2 = 0;
                memset(temparr, 0x00, sizeof(temparr));
            }
        }
    }
    else
    {
        /* Only ascii text : DO not change bytes order */
        while (i < TextLen)
        {
            OtaText[index++] = (U8) TextBuffer[i];
            i++;
        }
    }

    mmi_pmsg_add_header(OtaText, index, OtaData, DataLen);
    OslMfree(OtaText);

    return (U16) (index + DataLen);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_add_nokia_header
 * DESCRIPTION
 *  Prefix the Nokia Header on given Picture Message.
 * PARAMETERS
 *  PictureMessage      [?]         
 *  TotalSegment        [IN]        
 *  CurrentSegment      [IN]        
 *  OTA data ,Total Part & Part of Header (first, second or third ..)(?)
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_pmsg_add_nokia_header(U8 *PictureMessage, U8 TotalSegment, U8 CurrentSegment)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    const S16 NokiaTotalSegmentLocation = 21;
    const S16 NokiaCurrectSegmentLocation = 23;
    const S16 NokiaHeaderSize = 24;
    const S16 NokiaMaxSegments = 4;

    U8 NokiaHeader[MAX_NOKIA_HEADER_SIZE];
    U8 SegmentNumber[] = { '0', '1', '2', '3', '4' };
    U16 DataSize = strlen((S8*) PictureMessage);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((PictureMessage == NULL)
        || (TotalSegment > NokiaMaxSegments) || (CurrentSegment > NokiaMaxSegments) || (DataSize > 296))
    {
        return;
    }

    memset(NokiaHeader, 0x00, MAX_NOKIA_HEADER_SIZE);

    strcpy((S8*) NokiaHeader, (S8*) "0B0504158A00000003010301");

    NokiaHeader[NokiaTotalSegmentLocation] = SegmentNumber[TotalSegment];

    NokiaHeader[NokiaCurrectSegmentLocation] = SegmentNumber[CurrentSegment];

    mmi_pmsg_add_header(NokiaHeader, NokiaHeaderSize, PictureMessage, DataSize);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_convert_ascii_hex_string_2_dec_string
 * DESCRIPTION
 *  Convert the ascii string into Decimal string.
 * PARAMETERS
 *  DecStr          [?]     
 *  AsciiStr        [?]     
 *  Pointer to Dec string & Pointer to Ascii string.Ascii len must be even number.(?)
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_pmsg_convert_ascii_hex_string_2_dec_string(U8 *DecStr, U8 *AsciiStr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *AsciiStrPtr = AsciiStr;
    U8 *DecStrPtr = DecStr;
    U8 FirstVal = 0;
    U8 SecondVal = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (AsciiStrPtr == NULL)
    {
        return;
    }

    while (*AsciiStrPtr != '\0')
    {
        FirstVal = mmi_pmsg_convert_ascii_hex_to_dec(*AsciiStrPtr++);
        SecondVal = mmi_pmsg_convert_ascii_hex_to_dec(*AsciiStrPtr++);
        *DecStrPtr++ = ((FirstVal << 4) | (SecondVal));
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_convert_dec_string_2_ascii_hex_string
 * DESCRIPTION
 *  Convert the Decimal string into ascii string.
 * PARAMETERS
 *  AsciiStr        [?]     
 *  DecStr          [?]     
 *  Pointer to Ascii string & Pointer to Dec string. Ascii string len must be double of Dec string.(?)
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_pmsg_convert_dec_string_2_ascii_hex_string(U8 *AsciiStr, U8 *DecStr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 *AsciiStrPtr = AsciiStr;
    U8 *DecStrPtr = DecStr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (DecStrPtr == NULL)
    {
        return;
    }

    while (*DecStrPtr != '\0')
    {
        *AsciiStrPtr++ = mmi_pmsg_convert_binary_dec_to_hex(*DecStrPtr, PMSG_FIRST_FOUR_BITS);
        *AsciiStrPtr++ = mmi_pmsg_convert_binary_dec_to_hex(*DecStrPtr, PMSG_SECOND_FOUR_BITS);
        DecStrPtr++;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_get_size_bmp_data
 * DESCRIPTION
 *  This fun find out the real size of Bmp data.
 * PARAMETERS
 *  BmpData     [?]     
 *  Pointer of BMP data MMI format.(?)
 * RETURNS
 *  Size of Bmp file.
 *****************************************************************************/
U16 mmi_pmsg_get_size_bmp_data(U8 *BmpData)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 BmpDataSize = 0;
    S16 index = 2;
    U16 val[4];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    val[0] = (U16) BmpData[index++];
    val[1] = (U16) BmpData[index++];
    val[2] = (U16) BmpData[index++];
    val[3] = (U16) BmpData[index++];

    BmpDataSize = (U16) (val[3] << 24 | val[2] << 16 | val[1] << 8 | val[0]);

    return (BmpDataSize + MMI_EXTRA_BMP_HEADER_SIZE);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_get_size_ota_data
 * DESCRIPTION
 *  This fun find out the real size of Ota Picture data.
 * PARAMETERS
 *  OtaBuffer       [?]     
 *  Pointer of Ota data .(?)
 * RETURNS
 *  Size of Ota Data.
 *****************************************************************************/
U16 mmi_pmsg_get_size_ota_data(U8 *OtaBuffer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 OtaHeaderLen = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    OtaHeaderLen = mmi_pmsg_read_picture_header(OtaBuffer);

    if (OtaHeaderLen == -1)
    {
        return 0;
    }

    return (U16) (gOtaDataLen + OtaHeaderLen) * 2 + 8;

}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_add_bmp_header_info
 * DESCRIPTION
 *  This fun added the BMP extra header info to show the Picture in UI.Prepared MMI format.
 * PARAMETERS
 *  BmpData     [?]     
 *  Pointer of BMP data .(?)
 * RETURNS
 *  void
 *****************************************************************************/
S16 mmi_pmsg_add_bmp_header_info(U8 *BmpData)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S8 HeaderInfo[16];
    U16 BmpDataSize = 0;
    U16 index = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (mmi_pmsg_is_smart_picture(BmpData) == FALSE)
    {
        return -1;
    }

    memset(HeaderInfo, 0x00, 16);

    BmpDataSize = ((BmpData[2]) | (BmpData[3] << 8) | (BmpData[4] << 16) | (BmpData[5] << 24));
    HeaderInfo[index++] = 0x1;
    HeaderInfo[index++] = 0x0;
    HeaderInfo[index++] = (S8) ((BmpDataSize & 0x000000FF));
    HeaderInfo[index++] = (S8) ((BmpDataSize & 0x0000FF00) >> 8);
    HeaderInfo[index++] = (S8) ((BmpDataSize & 0x00FF0000) >> 16);
    HeaderInfo[index++] = (S8) ((BmpDataSize & 0xFF000000) >> 24);

    mmi_pmsg_add_header((U8*) HeaderInfo, index, (U8*) BmpData, BmpDataSize);

    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_pmsg_is_smart_picture
 * DESCRIPTION
 *  
 * PARAMETERS
 *  BmpData     [?]     
 * RETURNS
 *  
 *****************************************************************************/
BOOL mmi_pmsg_is_smart_picture(U8 *BmpData)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 index = 0, num_colors = 0;
    U8 height;
    U8 width;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((BmpData[index++] != 'B') || (BmpData[index++] != 'M'))
    {
        return FALSE;
    }

    /* Start : JP check of height and width NSM picture */
    index += 16;    /* Hack */

    width = BmpData[index];

    if ((width > MAX_NSM_PIC_WIDTH) || (width == 0))    /* Width is greater then 72 */
    {
        return FALSE;
    }

    index += 4; /* Hack */
    height = BmpData[index];

    if ((height > MAX_NSM_PIC_HEIGHT) || (height == 0)) /* Height is greater then 72 */
    {
        return FALSE;
    }
    /* index += 40; */
    /* End : JP check of height and width NSM picture */
    index += 20;

    num_colors = BmpData[index++];
    num_colors |= BmpData[index++] << ONE_BYTE_SIZE;

    if (num_colors > 1)
    {
        num_colors = 1; /* JP for tracker issue 20050628 */
        /* return FALSE; */
    }
    return TRUE;
}
#endif /* _MMI_PICMSG_C */ /* if include picmsg_c */
#endif /* defined(__MMI_SMART_MESSAGE_MT__) || (defined(__MMI_SMART_MESSAGE_MO__) && !defined(__MMI_MESSAGES_EMS__)) */