SMSUtil.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:225k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*******************************************************************************
  36.  * Filename:
  37.  * ---------
  38.  *  SMSUtil.c
  39.  *
  40.  * Project:
  41.  * --------
  42.  *  MAUI
  43.  *
  44.  * Description:
  45.  * ------------
  46.  *  
  47.  *
  48.  * Author:
  49.  * -------
  50.  *  
  51.  *
  52.  *==============================================================================
  53.  *             HISTORY
  54.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  55.  *------------------------------------------------------------------------------
  56.  * removed!
  57.  *
  58.  * removed!
  59.  * removed!
  60.  * removed!
  61.  *
  62.  * removed!
  63.  * removed!
  64.  * removed!
  65.  *
  66.  * removed!
  67.  * removed!
  68.  * removed!
  69.  *
  70.  * removed!
  71.  * removed!
  72.  * removed!
  73.  *
  74.  * removed!
  75.  * removed!
  76.  * removed!
  77.  *
  78.  * removed!
  79.  * removed!
  80.  * removed!
  81.  *
  82.  * removed!
  83.  * removed!
  84.  * removed!
  85.  *
  86.  * removed!
  87.  * removed!
  88.  * removed!
  89.  *
  90.  * removed!
  91.  * removed!
  92.  * removed!
  93.  *
  94.  * removed!
  95.  * removed!
  96.  * removed!
  97.  *
  98.  * removed!
  99.  * removed!
  100.  * removed!
  101.  *
  102.  * removed!
  103.  * removed!
  104.  * removed!
  105.  *
  106.  * removed!
  107.  * removed!
  108.  * removed!
  109.  *
  110.  * removed!
  111.  * removed!
  112.  * removed!
  113.  *
  114.  * removed!
  115.  * removed!
  116.  * removed!
  117.  *
  118.  * removed!
  119.  * removed!
  120.  * removed!
  121.  *
  122.  * removed!
  123.  * removed!
  124.  * removed!
  125.  *
  126.  * removed!
  127.  * removed!
  128.  * removed!
  129.  *
  130.  * removed!
  131.  * removed!
  132.  * removed!
  133.  *
  134.  * removed!
  135.  * removed!
  136.  * removed!
  137.  *
  138.  * removed!
  139.  * removed!
  140.  * removed!
  141.  *
  142.  * removed!
  143.  * removed!
  144.  * removed!
  145.  *
  146.  * removed!
  147.  * removed!
  148.  * removed!
  149.  *
  150.  * removed!
  151.  * removed!
  152.  * removed!
  153.  *
  154.  * removed!
  155.  * removed!
  156.  * removed!
  157.  *
  158.  * removed!
  159.  * removed!
  160.  * removed!
  161.  *
  162.  * removed!
  163.  * removed!
  164.  * removed!
  165.  *
  166.  * removed!
  167.  * removed!
  168.  * removed!
  169.  *
  170.  * removed!
  171.  * removed!
  172.  * removed!
  173.  *
  174.  * removed!
  175.  * removed!
  176.  * removed!
  177.  *
  178.  * removed!
  179.  * removed!
  180.  * removed!
  181.  *
  182.  * removed!
  183.  * removed!
  184.  * removed!
  185.  *
  186.  * removed!
  187.  * removed!
  188.  * removed!
  189.  *
  190.  * removed!
  191.  * removed!
  192.  * removed!
  193.  *
  194.  * removed!
  195.  * removed!
  196.  * removed!
  197.  *
  198.  * removed!
  199.  * removed!
  200.  * removed!
  201.  *
  202.  * removed!
  203.  * removed!
  204.  * removed!
  205.  *
  206.  * removed!
  207.  * removed!
  208.  * removed!
  209.  *
  210.  *------------------------------------------------------------------------------
  211.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  212.  *==============================================================================
  213.  *******************************************************************************/
  214. #ifdef __MOD_SMSAL__
  215. #include "MMI_features.h"
  216. #include "stdC.h"
  217. #include "L4Dr1.h"
  218. #include "PixtelDataTypes.h"
  219. /* ... Add More MMI header */
  220. #include "EventsGprot.h"
  221. #include "HistoryGprot.h"
  222. #include "GlobalMenuItems.h"
  223. #include "GlobalConstants.h"
  224. #include "Globaldefs.h"
  225. #include "wgui_categories.h"
  226. #include "CustMenuRes.h"
  227. #include "CommonScreens.h"
  228. #include "Unicodexdcl.h"
  229. #include "TimerEvents.h"
  230. #include "DebugInitDef.h"
  231. #include "ProtocolEvents.h"
  232. /* ...Add MSG header */
  233. #include "customer_ps_inc.h"
  234. #include "mmi_msg_context.h"
  235. #include "MessagesL4Def.h"
  236. #include "MessagesResourceData.h"
  237. #include "MessagesMiscell.h"
  238. #include "MessagesExDcl.h"
  239. #include "SmsGuiInterfaceProt.h"
  240. #include "SMsGuiInterfaceType.h"
  241. #include "SmsPsHandler.h"
  242. #include "CellBroadcastType.h"
  243. #ifdef __MMI_MESSAGES_CHAT__
  244. #include "ChatAppGprot.h"
  245. #include "ChatAppDef.h"
  246. #endif /* __MMI_MESSAGES_CHAT__ */ 
  247. /*  */
  248. #include "customer_ps_inc.h"
  249. #include "l4c2smsal_struct.h"
  250. #include "smsal_l4c_enum.h"
  251. #include "ems.h"
  252. /*  */
  253. #include "Gui_ems.h"
  254. #include "wgui_ems.h"
  255. #include "GSM7BitDefaultAlphabet.h"
  256. /*  */
  257. #include "PhoneBookGprot.h"
  258. #include "CallHistoryGProts.h"
  259. #include "IdleAppProt.h"
  260. #include "SettingProfile.h"
  261. #include "ProfileGprots.h"
  262. #include "AlarmFrameworkProt.h"
  263. #include "PhoneBookTypes.h"
  264. #include "SimDetectionGexdcl.h"
  265. #include "SettingDefs.h"
  266. #include "SettingsGdcl.h"
  267. /*  */
  268. #include "wgui_status_icons.h"
  269. #include "KeyBrd.h"
  270. #include "DateTimeGprot.h"
  271. #include "SMSApi.h"
  272. #include "SMSStruct.h"
  273. #include "SMSFunc.h"
  274. #ifdef __MMI_UNIFIED_MESSAGE__
  275. #include "UnifiedMessageGProt.h"
  276. #endif 
  277. #define smstest
  278. #define MMI_FRM_SMS_INVALID_INDEX   0xffff
  279. #ifndef MMI_FRM_SMS_INVALID_NUM
  280. #define MMI_FRM_SMS_INVALID_NUM     0xff
  281. #endif 
  282. #ifndef MMI_FRM_SMS_MSG_LEN
  283. #define MMI_FRM_SMS_MSG_LEN         160
  284. #endif 
  285. #ifndef MMI_FRM_SMS_MSG_CONTENT_NUM
  286. #define MMI_FRM_SMS_MSG_CONTENT_NUM 20
  287. #endif 
  288. #ifndef MMI_FRM_SMS_ACTION_SIZE
  289. #define MMI_FRM_SMS_ACTION_SIZE     10
  290. #endif 
  291. static U16 mmi_frm_sms_msgbox_size = 0;
  292. static U16 mmi_frm_sms_inbox_size = 0;
  293. static U16 mmi_frm_sms_outbox_size = 0;
  294. #ifdef __MMI_MESSAGES_DRAFT_BOX__
  295. static U16 mmi_frm_sms_drafts_size = 0;
  296. #endif 
  297. static U8 mmi_frm_sms_list_done = FALSE;
  298. static mmi_frm_sms_deliver_msg_struct mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE + 1];
  299. static mmi_frm_sms_deliver_data_struct mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE + 1];
  300. static mmi_frm_sms_content_struct mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM + 1];
  301. #ifdef __MMI_MESSAGES_SINGLE_DELIVERY_REPORT__
  302. static mmi_frm_sms_delivery_report_list_struct mmi_frm_sms_delivery_report_awaited[MMI_FRM_SMS_ACTION_SIZE];
  303. #endif 
  304. static U8 mmi_frm_sms_awaited_counter[MMI_FRM_SMS_ACTION_SIZE];
  305. static U8 mmi_frm_sms_awaited_counting = FALSE;
  306. static U8 mmi_frm_sms_data_counter[MMI_FRM_SMS_ACTION_SIZE];
  307. static U8 mmi_frm_sms_data_counting = FALSE;
  308. static U16 mmi_frm_sms_data_checked = 0;
  309. #ifdef __MMI_MESSAGES_SINGLE_DELIVERY_REPORT__
  310. static U8 mmi_frm_sms_delivery_report_awaited_next_available = 0;
  311. #endif 
  312. #define ONE_DIGIT(value)                  ((value) % 10)
  313. #ifdef __MMI_MESSAGES_MOSES_FEATURE__
  314. const U8 MMI_FRM_SMS_MOSES_PATTERN[6] = {0xa1, 0x1a, 0x5f, 0x20, 0x0a,0x00};
  315. #endif /* __MMI_MESSAGES_MOSES_FEATURE__ */
  316. extern U8 GetSecondSemiOctetTarget(U8 ch);
  317. extern U8 GetFirstSemiOctetTarget(U8 ch);
  318. extern void EMS_ConvertGSM7BitDefaultEncodingToAsciiWithoutEMSlib(EMSData *data);
  319. #define MMI_SMS_EURO_SIGN (0x20AC)
  320. #define MMI_SMS_TEST_GSM7BIT_EXTENDED(c)     
  321. (     (c==MMI_SMS_EURO_SIGN)                     
  322.    || (c=='^')                      
  323.    || (c=='{')                      
  324.    || (c=='}')                      
  325.    || (c=='\')                     
  326.    || (c=='[')                      
  327.    || (c=='~')                      
  328.    || (c==']')                      
  329.    || (c=='|')                      
  330. )                                   
  331. /*****************************************************************************
  332.  * FUNCTION
  333.  *  ComparePhoneNum
  334.  * DESCRIPTION
  335.  *  It Compares phone numbers
  336.  * PARAMETERS
  337.  *  src     [IN]        
  338.  *  dst     [IN]        
  339.  *  Source and destination phone number(?)
  340.  * RETURNS
  341.  *  status
  342.  *****************************************************************************/
  343. pBOOL ComparePhoneNum(PU8 src, PU8 dst)
  344. {
  345.     /*----------------------------------------------------------------*/
  346.     /* Local Variables                                                */
  347.     /*----------------------------------------------------------------*/
  348.     long num1 = 0, num2 = 0;
  349.     U8 temp1, temp2;
  350.     /*----------------------------------------------------------------*/
  351.     /* Code Body                                                      */
  352.     /*----------------------------------------------------------------*/
  353.     num1 = mmi_phb_util_convert_number_to_int(src);
  354.     num2 = mmi_phb_util_convert_number_to_int(dst);
  355.     if (num1 == num2)
  356.     {
  357.         if (src[0] == '+')
  358.         {
  359.             src++;
  360.         }
  361.         if (dst[0] == '+')
  362.         {
  363.             dst++;
  364.         }
  365.         temp1 = strcspn((PS8) src, "+pw*#");
  366.         temp2 = strcspn((PS8) dst, "+pw*#");
  367.         if (temp1 && temp2)
  368.         {
  369.             src = src + temp1;
  370.             dst = dst + temp2;
  371.         }
  372.         if (!strcmp((PS8) src, (PS8) dst))
  373.         {
  374.             return TRUE;
  375.         }
  376.         else
  377.         {
  378.             return FALSE;
  379.         }
  380.     }
  381.     else
  382.     {
  383.         return FALSE;
  384.     }
  385. }
  386. /*****************************************************************************
  387.  * FUNCTION
  388.  *  mmi_frm_sms_convert_time_stamp
  389.  * DESCRIPTION
  390.  *  convert time stamp
  391.  * PARAMETERS
  392.  *  scts            [?]     Scts
  393.  *  timestamp       [?]     Timestamp
  394.  * RETURNS
  395.  *  void
  396.  *****************************************************************************/
  397. void mmi_frm_sms_convert_time_stamp(U8 *scts, U8 *timestamp)
  398. {
  399.     /*----------------------------------------------------------------*/
  400.     /* Local Variables                                                */
  401.     /*----------------------------------------------------------------*/
  402.     /*----------------------------------------------------------------*/
  403.     /* Code Body                                                      */
  404.     /*----------------------------------------------------------------*/
  405.     /* No Timestamp */
  406.     if (scts[0] == MMI_FRM_SMS_INVALID_NUM)
  407.     {
  408.         memset((S8*) timestamp, 0, 7);
  409.         return;
  410.     }
  411.     /* year */
  412.     timestamp[0] = ONE_DIGIT(GetSecondSemiOctetTarget(scts[0])) * 10 + ONE_DIGIT(GetFirstSemiOctetTarget(scts[0]));
  413.     /* month */
  414.     timestamp[1] = ONE_DIGIT(GetSecondSemiOctetTarget(scts[1])) * 10 + ONE_DIGIT(GetFirstSemiOctetTarget(scts[1]));
  415.     /* day */
  416.     timestamp[2] = ONE_DIGIT(GetSecondSemiOctetTarget(scts[2])) * 10 + ONE_DIGIT(GetFirstSemiOctetTarget(scts[2]));
  417.     /* hour */
  418.     timestamp[3] = ONE_DIGIT(GetSecondSemiOctetTarget(scts[3])) * 10 + ONE_DIGIT(GetFirstSemiOctetTarget(scts[3]));
  419.     /* minute */
  420.     timestamp[4] = ONE_DIGIT(GetSecondSemiOctetTarget(scts[4])) * 10 + ONE_DIGIT(GetFirstSemiOctetTarget(scts[4]));
  421.     /* second */
  422.     timestamp[5] = ONE_DIGIT(GetSecondSemiOctetTarget(scts[5])) * 10 + ONE_DIGIT(GetFirstSemiOctetTarget(scts[5]));
  423.       /**timezone, convert date/time to one variable */
  424.     timestamp[6] = ONE_DIGIT(GetSecondSemiOctetTarget(scts[6])) * 10 + ONE_DIGIT(GetFirstSemiOctetTarget(scts[6]));
  425. }
  426. /*****************************************************************************
  427.  * FUNCTION
  428.  *  mmi_frm_sms_convert_mytime
  429.  * DESCRIPTION
  430.  *  convert MYTIME to scts
  431.  * PARAMETERS
  432.  *  scts        [?]     Scts
  433.  *  time        [?]     
  434.  *  b  timestamp      timestamp(?)
  435.  * RETURNS
  436.  *  void
  437.  *****************************************************************************/
  438. void mmi_frm_sms_convert_mytime(U8 *scts, MYTIME *time)
  439. {
  440.     /*----------------------------------------------------------------*/
  441.     /* Local Variables                                                */
  442.     /*----------------------------------------------------------------*/
  443.     U8 year = 0;
  444.     /*----------------------------------------------------------------*/
  445.     /* Code Body                                                      */
  446.     /*----------------------------------------------------------------*/
  447.     if (time->nYear > 2000)
  448.     {
  449.         year = (U8)(time->nYear - 2000);
  450.     }
  451.     else
  452.     {
  453.         year = (U8)(time->nYear - 1900);
  454.     }
  455.     scts[0] = ((year % 10) << 4) | (year / 10);
  456.     scts[1] = ((time->nMonth % 10) << 4) | (time->nMonth / 10);
  457.     scts[2] = ((time->nDay % 10) << 4) | (time->nDay / 10);
  458.     scts[3] = ((time->nHour % 10) << 4) | (time->nHour / 10);
  459.     scts[4] = ((time->nMin % 10) << 4) | (time->nMin / 10);
  460.     scts[5] = ((time->nSec % 10) << 4) | (time->nSec / 10);
  461. }
  462. /*****************************************************************************
  463.  * FUNCTION
  464.  *  mmi_frm_sms_add_new_sms
  465.  * DESCRIPTION
  466.  *  free new sms buff
  467.  * PARAMETERS
  468.  *  entry       [IN]        Entry
  469.  *  length      [IN]        
  470.  *  data        [?]         
  471.  * RETURNS
  472.  *  void
  473.  *****************************************************************************/
  474. void mmi_frm_sms_add_new_sms(mmi_frm_sms_deliver_msg_struct *entry, U16 length, U8 *data)
  475. {
  476.     /*----------------------------------------------------------------*/
  477.     /* Local Variables                                                */
  478.     /*----------------------------------------------------------------*/
  479.     mmi_frm_sms_concat_struct *concatinfo = (mmi_frm_sms_concat_struct*) & (entry->concat_info);
  480.     U16 index = entry->index;
  481.     U8 segment = 1;
  482.     /*----------------------------------------------------------------*/
  483.     /* Code Body                                                      */
  484.     /*----------------------------------------------------------------*/
  485.     if ((concatinfo->seg > concatinfo->total_seg) || (concatinfo->seg == 0) || (concatinfo->total_seg == 0))
  486.     {
  487.         concatinfo->seg = 1;
  488.         concatinfo->total_seg = 1;
  489.     }
  490.     if (((concatinfo->seg) % g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) == 0)
  491.     {
  492.         segment = (U8) g_frm_sms_cntx.mmi_frm_sms_msg_seg_size;
  493.     }
  494.     else
  495.     {
  496.         segment = (concatinfo->seg) % g_frm_sms_cntx.mmi_frm_sms_msg_seg_size;
  497.     }
  498.     /* change seg info to start seg */
  499.     concatinfo->seg =
  500.         ((concatinfo->seg - 1) / g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) * g_frm_sms_cntx.mmi_frm_sms_msg_seg_size + 1;
  501.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].dcs = entry->dcs;
  502.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].display_type = entry->display_type;
  503. #ifdef __MMI_MESSAGES_COPY__
  504.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].storageType = entry->storageType;
  505. #endif 
  506.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].fo = entry->fo;
  507.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].index = entry->index;
  508.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].mti = entry->mti;
  509.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].pid = entry->pid;
  510.     memcpy(&(mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].concat_info), concatinfo, sizeof(smsal_concat_struct));
  511.     memcpy(
  512.         (S8*) & (mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].addr_number),
  513.         (S8*) & (entry->addr_number),
  514.         sizeof(l4c_number_struct));
  515.     memcpy(
  516.         (S8*) & (mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].sca_number),
  517.         (S8*) & (entry->sca_number),
  518.         sizeof(l4c_number_struct));
  519.     memcpy((S8*) (mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].scts), (S8*) (entry->scts), 7);
  520.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].msg_data[0] = MMI_FRM_SMS_MSG_CONTENT_NUM;
  521.     mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].no_msg_data = entry->no_msg_data;
  522.     /* handle message content part */
  523.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].segment = segment;
  524.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].msglen = length;
  525.     if (mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data != NULL)
  526.     {
  527.         OslMfree(mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data);
  528.     }
  529.     if (length)
  530.     {
  531.         mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data = OslMalloc(length);
  532.         memcpy(mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data, (S8*) data, length);
  533.     }
  534.     /* class 0 message */
  535.     if (index == MMI_FRM_SMS_INVALID_INDEX)
  536.     {
  537.         return;
  538.     }
  539.     /* used index list entry, replace the old entry with the new one */
  540.     if (mmi_frm_sms_index_list[index].segment != MMI_FRM_SMS_INVALID_NUM)
  541.     {
  542.         PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  543.                              "*-------[SmsUtil.c] mmi_frm_sms_add_new_sms remove used L4 list entry %d-------*n",
  544.                              index));        
  545.         /* Free awaited list entry and content list entry if the replaced msg is in awaited list */
  546.         /* The replaced segment is the first segment of awaited msg */
  547.         if (mmi_frm_sms_index_list[index].prevtype == MMI_FRM_SMS_AWAITS)
  548.         {
  549.             U16 awaited_index = (U16) mmi_frm_sms_index_list[index].previndex;
  550.             PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  551.                                  "*-------[SmsUtil.c] first segment in awaited list ------*n"));
  552.                 
  553.             /* Only one segment in the awaited msg. Just delete the awaited msg. */
  554.             if (mmi_frm_sms_index_list[index].nextindex == MMI_FRM_SMS_INVALID_INDEX)
  555.             {            
  556.                 PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  557.                                      "*-------[SmsUtil.c] free awaited list %d-------*n",
  558.                                      awaited_index));
  559.                 /* Stop the timer counter of the awaited list entry to be deleted */
  560.                 mmi_frm_sms_awaited_counter[awaited_index] = MMI_FRM_SMS_INVALID_NUM;
  561.                 mmi_frm_sms_free_awaited(awaited_index);
  562.             }
  563.             /* More than one segment in the awaited msg. Modify awaited msg and free content list entry. */
  564.             else
  565.             {
  566.                 U8 content_index = mmi_frm_sms_awaited[awaited_index].msg_data[0];
  567.                 MMI_ASSERT(mmi_frm_sms_awaited[awaited_index].no_msg_data >= mmi_frm_sms_content[content_index].msglen);
  568.             
  569.                 mmi_frm_sms_awaited[awaited_index].no_msg_data -= mmi_frm_sms_content[content_index].msglen;
  570.                 mmi_frm_sms_awaited[awaited_index].msg_data[0] = mmi_frm_sms_content[content_index].nextindex;
  571.                 
  572.                 if (mmi_frm_sms_content[content_index].data != NULL)
  573.                 {
  574.                     OslMfree(mmi_frm_sms_content[content_index].data);
  575.                     mmi_frm_sms_content[content_index].data = NULL;
  576.                 }
  577.                 mmi_frm_sms_content[content_index].msglen = 0;
  578.                 mmi_frm_sms_content[content_index].nextindex = MMI_FRM_SMS_INVALID_NUM;
  579.                 mmi_frm_sms_content[content_index].segment = MMI_FRM_SMS_INVALID_NUM;            
  580.                 PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  581.                      "*-------[SmsUtil.c] modify awaited list %d-------*n",
  582.                      awaited_index));
  583.                 mmi_frm_sms_remove_sms_entry(index);                
  584.             }
  585.         }
  586.         else if (mmi_frm_sms_index_list[index].prevtype == MMI_FRM_SMS_NOBOX)
  587.         {
  588.             U16 L4index = mmi_frm_sms_index_list[index].previndex;
  589.             PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  590.                                  "*-------[SmsUtil.c] type of segment is NOBOX ------*n"));
  591.             
  592.             while (mmi_frm_sms_index_list[L4index].prevtype == MMI_FRM_SMS_NOBOX)
  593.             {
  594.                 L4index = mmi_frm_sms_index_list[L4index].previndex;
  595.             }
  596.             /* The replaced segment is in the awaited list */
  597.             if (mmi_frm_sms_index_list[L4index].prevtype == MMI_FRM_SMS_AWAITS)
  598.             {
  599.                 U16 awaited_index = (U16) mmi_frm_sms_index_list[L4index].previndex;            
  600.                 U8 content_index = mmi_frm_sms_awaited[awaited_index].msg_data[0];
  601.                 U8 pre_content_index = MMI_FRM_SMS_INVALID_NUM;
  602.                 U8 segment = mmi_frm_sms_index_list[index].segment;
  603.                 
  604.                 PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  605.                                      "*-------[SmsUtil.c] non-first segment in awaited list -------*n"));       
  606.                 while(content_index != MMI_FRM_SMS_INVALID_NUM)
  607.                 {
  608.                     if (mmi_frm_sms_content[content_index].segment == segment)
  609.                     {
  610.                         break;
  611.                     }
  612.                     pre_content_index = content_index;
  613.                     content_index = mmi_frm_sms_content[content_index].nextindex;
  614.                 }
  615.                 
  616.                 PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  617.                                      "[SmsUtil.c] After search for content entry, segment=%d content_index=%d pre_content_index=%d n",
  618.                                      segment, content_index, pre_content_index));
  619.                 if (content_index != MMI_FRM_SMS_INVALID_NUM && pre_content_index != MMI_FRM_SMS_INVALID_NUM)
  620.                 {
  621.                     MMI_ASSERT(mmi_frm_sms_awaited[awaited_index].no_msg_data >= mmi_frm_sms_content[content_index].msglen);
  622.                 
  623.                     mmi_frm_sms_awaited[awaited_index].no_msg_data -= mmi_frm_sms_content[content_index].msglen;
  624.                     mmi_frm_sms_content[pre_content_index].nextindex = mmi_frm_sms_content[content_index].nextindex;
  625.                     
  626.                     if (mmi_frm_sms_content[content_index].data != NULL)
  627.                     {
  628.                         OslMfree(mmi_frm_sms_content[content_index].data);
  629.                         mmi_frm_sms_content[content_index].data = NULL;
  630.                     }
  631.                     mmi_frm_sms_content[content_index].msglen = 0;
  632.                     mmi_frm_sms_content[content_index].nextindex = MMI_FRM_SMS_INVALID_NUM;
  633.                     mmi_frm_sms_content[content_index].segment = MMI_FRM_SMS_INVALID_NUM;            
  634.                     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  635.                                          "*-------[SmsUtil.c] modify awaited list -------*n"));                    
  636.                     mmi_frm_sms_remove_sms_entry(index);
  637.                 }
  638.                 else
  639.                 {
  640.                     MMI_ASSERT(0);
  641.                 }
  642.                 
  643.             }
  644.             
  645.             /* The replaced segment is in the message box  */
  646.             else
  647.             {
  648.                 PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  649.                                      "*-------[SmsUtil.c] The replaced segment is in the message box -------*n"));                    
  650.                 mmi_frm_sms_remove_sms_entry(index);
  651.             }
  652.         }
  653.         
  654.         /* The replaced segment is in the message box  */
  655.         else
  656.         {
  657.             PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  658.                                  "*-------[SmsUtil.c] The replaced segment is in the message box-------*n"));       
  659.             mmi_frm_sms_remove_sms_entry(index);
  660.         }
  661.     }
  662.     mmi_frm_sms_index_list[index].segment = mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].segment;
  663.     mmi_frm_sms_index_list[index].nextindex = MMI_FRM_SMS_INVALID_INDEX;
  664.     mmi_frm_sms_index_list[index].previndex = MMI_FRM_SMS_ACTION_SIZE;;
  665.     mmi_frm_sms_index_list[index].prevtype = MMI_FRM_SMS_AWAITS;
  666. }
  667. /*****************************************************************************
  668.  * FUNCTION
  669.  *  mmi_frm_sms_free_new_sms
  670.  * DESCRIPTION
  671.  *  free new sms buff
  672.  * PARAMETERS
  673.  *  void
  674.  *  entry(?)        [IN]        Entry
  675.  * RETURNS
  676.  *  void
  677.  *****************************************************************************/
  678. void mmi_frm_sms_free_new_sms(void)
  679. {
  680.     /*----------------------------------------------------------------*/
  681.     /* Local Variables                                                */
  682.     /*----------------------------------------------------------------*/
  683.     /*----------------------------------------------------------------*/
  684.     /* Code Body                                                      */
  685.     /*----------------------------------------------------------------*/
  686.     if (mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data != NULL)
  687.     {
  688.         OslMfree(mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data);
  689.         mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data = NULL;
  690.     }
  691.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].msglen = 0;
  692.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].nextindex = MMI_FRM_SMS_INVALID_NUM;
  693.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].segment = MMI_FRM_SMS_INVALID_NUM;
  694.     memset(
  695.         (S8*) & mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE],
  696.         MMI_FRM_SMS_INVALID_NUM,
  697.         sizeof(mmi_frm_sms_deliver_msg_struct));
  698. }
  699. /*****************************************************************************
  700.  * FUNCTION
  701.  *  mmi_frm_sms_free_awaited
  702.  * DESCRIPTION
  703.  *  Free awaited message by index
  704.  * PARAMETERS
  705.  *  index       [IN]        Index
  706.  * RETURNS
  707.  *  void
  708.  *****************************************************************************/
  709. void mmi_frm_sms_free_awaited(U8 index)
  710. {
  711.     /*----------------------------------------------------------------*/
  712.     /* Local Variables                                                */
  713.     /*----------------------------------------------------------------*/
  714.     U8 i = mmi_frm_sms_awaited[index].msg_data[0];
  715.     /*----------------------------------------------------------------*/
  716.     /* Code Body                                                      */
  717.     /*----------------------------------------------------------------*/
  718.     while (i != MMI_FRM_SMS_INVALID_NUM)
  719.     {
  720.         U8 nextindex = mmi_frm_sms_content[i].nextindex;
  721.         if (mmi_frm_sms_content[i].data != NULL)
  722.         {
  723.             OslMfree(mmi_frm_sms_content[i].data);
  724.             mmi_frm_sms_content[i].data = NULL;
  725.         }
  726.         mmi_frm_sms_content[i].msglen = 0;
  727.         mmi_frm_sms_content[i].nextindex = MMI_FRM_SMS_INVALID_NUM;
  728.         mmi_frm_sms_content[i].segment = MMI_FRM_SMS_INVALID_NUM;
  729.         i = nextindex;
  730.     }
  731.     memset((S8*) & mmi_frm_sms_awaited[index], MMI_FRM_SMS_INVALID_NUM, sizeof(mmi_frm_sms_deliver_msg_struct));
  732. }
  733. /*****************************************************************************
  734.  * FUNCTION
  735.  *  mmi_frm_sms_add_new_data
  736.  * DESCRIPTION
  737.  *  free new sms buff
  738.  * PARAMETERS
  739.  *  entry       [IN]        Entry
  740.  *  length      [IN]        
  741.  *  data        [?]         
  742.  * RETURNS
  743.  *  void
  744.  *****************************************************************************/
  745. void mmi_frm_sms_add_new_data(mmi_frm_sms_deliver_data_struct *entry, U16 length, U8 *data)
  746. {
  747.     /*----------------------------------------------------------------*/
  748.     /* Local Variables                                                */
  749.     /*----------------------------------------------------------------*/
  750.     mmi_frm_sms_concat_struct *concatinfo = (mmi_frm_sms_concat_struct*) & (entry->concat_info);
  751.     U8 segment = 1;
  752.     /*----------------------------------------------------------------*/
  753.     /* Code Body                                                      */
  754.     /*----------------------------------------------------------------*/
  755.     if ((concatinfo->seg > concatinfo->total_seg) || (concatinfo->seg == 0) || (concatinfo->total_seg == 0))
  756.     {
  757.         concatinfo->seg = 1;
  758.         concatinfo->total_seg = 1;
  759.     }
  760.     if (((concatinfo->seg) % g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) == 0)
  761.     {
  762.         segment = (U8) g_frm_sms_cntx.mmi_frm_sms_msg_seg_size;
  763.     }
  764.     else
  765.     {
  766.         segment = (concatinfo->seg) % g_frm_sms_cntx.mmi_frm_sms_msg_seg_size;
  767.     }
  768.     /* change seg info to start seg */
  769.     concatinfo->seg =
  770.         ((concatinfo->seg - 1) / g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) * g_frm_sms_cntx.mmi_frm_sms_msg_seg_size + 1;
  771.     mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].dest_mod_id = entry->dest_mod_id;
  772.     mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].dest_port = entry->dest_port;
  773.     mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].dcs = entry->dcs;
  774.     mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].mti = entry->mti;
  775.     memcpy(&(mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].concat_info), concatinfo, sizeof(smsal_concat_struct));
  776.     memcpy((S8*) & (mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].oa), (S8*) & (entry->oa), sizeof(l4c_number_struct));
  777.     memcpy((S8*) (mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].scts), (S8*) (entry->scts), 7);
  778.     mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].data[0] = MMI_FRM_SMS_MSG_CONTENT_NUM;
  779.     mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE].message_len = entry->message_len;
  780.     /* handle message content part */
  781.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].segment = segment;
  782.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].msglen = length;
  783.     if (mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data != NULL)
  784.     {
  785.         OslMfree(mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data);
  786.     }
  787.     if (length)
  788.     {
  789.         mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data = OslMalloc(length);
  790.         memcpy(mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data, (S8*) data, length);
  791.     }
  792. }
  793. /*****************************************************************************
  794.  * FUNCTION
  795.  *  mmi_frm_sms_free_new_data
  796.  * DESCRIPTION
  797.  *  free new sms buff
  798.  * PARAMETERS
  799.  *  void
  800.  *  entry(?)        [IN]        Entry
  801.  * RETURNS
  802.  *  void
  803.  *****************************************************************************/
  804. void mmi_frm_sms_free_new_data(void)
  805. {
  806.     /*----------------------------------------------------------------*/
  807.     /* Local Variables                                                */
  808.     /*----------------------------------------------------------------*/
  809.     /*----------------------------------------------------------------*/
  810.     /* Code Body                                                      */
  811.     /*----------------------------------------------------------------*/
  812.     if (mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data != NULL)
  813.     {
  814.         OslMfree(mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data);
  815.         mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data = NULL;
  816.     }
  817.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].msglen = 0;
  818.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].nextindex = MMI_FRM_SMS_INVALID_NUM;
  819.     mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].segment = MMI_FRM_SMS_INVALID_NUM;
  820.     memset(
  821.         (S8*) & mmi_frm_sms_data[MMI_FRM_SMS_ACTION_SIZE],
  822.         MMI_FRM_SMS_INVALID_NUM,
  823.         sizeof(mmi_frm_sms_deliver_data_struct));
  824. }
  825. /*****************************************************************************
  826.  * FUNCTION
  827.  *  mmi_frm_sms_free_data
  828.  * DESCRIPTION
  829.  *  Free SMS with port number by index
  830.  * PARAMETERS
  831.  *  index       [IN]        Index
  832.  * RETURNS
  833.  *  void
  834.  *****************************************************************************/
  835. void mmi_frm_sms_free_data(U8 index)
  836. {
  837.     /*----------------------------------------------------------------*/
  838.     /* Local Variables                                                */
  839.     /*----------------------------------------------------------------*/
  840.     U8 i = mmi_frm_sms_data[index].data[0];
  841.     /*----------------------------------------------------------------*/
  842.     /* Code Body                                                      */
  843.     /*----------------------------------------------------------------*/
  844.     while (i != MMI_FRM_SMS_INVALID_NUM)
  845.     {
  846.         U8 nextindex = mmi_frm_sms_content[i].nextindex;
  847.         if (mmi_frm_sms_content[i].data != NULL)
  848.         {
  849.             OslMfree(mmi_frm_sms_content[i].data);
  850.             mmi_frm_sms_content[i].data = NULL;
  851.         }
  852.         mmi_frm_sms_content[i].msglen = 0;
  853.         mmi_frm_sms_content[i].nextindex = MMI_FRM_SMS_INVALID_NUM;
  854.         mmi_frm_sms_content[i].segment = MMI_FRM_SMS_INVALID_NUM;
  855.         i = nextindex;
  856.     }
  857.     memset((S8*) & mmi_frm_sms_data[index], MMI_FRM_SMS_INVALID_NUM, sizeof(mmi_frm_sms_deliver_data_struct));
  858. }
  859. /*****************************************************************************
  860.  * FUNCTION
  861.  *  mmi_frm_sms_convert_new_data
  862.  * DESCRIPTION
  863.  *  convert mt structure to entry structure
  864.  * PARAMETERS
  865.  *  data        [?]     New data
  866.  *  entry       [?]     Message entry
  867.  * RETURNS
  868.  *  void
  869.  *****************************************************************************/
  870. void mmi_frm_sms_convert_new_data(MMI_FRM_SMS_APP_DATA_IND_STRUCT *data, mmi_frm_sms_deliver_data_struct *entry)
  871. {
  872.     /*----------------------------------------------------------------*/
  873.     /* Local Variables                                                */
  874.     /*----------------------------------------------------------------*/
  875.     /*----------------------------------------------------------------*/
  876.     /* Code Body                                                      */
  877.     /*----------------------------------------------------------------*/
  878.     entry->dest_mod_id = data->dest_mod_id;
  879.     entry->dest_port = data->dest_port;
  880.     entry->src_port = data->src_port;
  881.     entry->dcs = data->dcs;
  882.     entry->mti = data->mti;
  883.     entry->message_len = data->message_len;
  884.     entry->concat_info = data->concat_info[0];
  885.     memcpy(&entry->oa, &data->oa, sizeof(l4_addr_bcd_struct));
  886.     memcpy(entry->scts, data->scts, 7);
  887.     entry->data[0] = MMI_FRM_SMS_MSG_CONTENT_NUM;
  888. }
  889. /*****************************************************************************
  890.  * FUNCTION
  891.  *  mmi_frm_sms_convert_new_sms
  892.  * DESCRIPTION
  893.  *  convert mt structure to entry structure
  894.  * PARAMETERS
  895.  *  data        [?]     Data
  896.  *  entry       [?]     
  897.  *  a  index    index(?)
  898.  *  b  type     type(?)
  899.  * RETURNS
  900.  *  void
  901.  *****************************************************************************/
  902. void mmi_frm_sms_convert_new_sms(MMI_FRM_SMS_DELIVER_MSG_IND_STRUCT *data, mmi_frm_sms_deliver_msg_struct *entry)
  903. {
  904.     /*----------------------------------------------------------------*/
  905.     /* Local Variables                                                */
  906.     /*----------------------------------------------------------------*/
  907.     /*----------------------------------------------------------------*/
  908.     /* Code Body                                                      */
  909.     /*----------------------------------------------------------------*/
  910.     entry->fo = data->fo;
  911.     memcpy(entry->scts, data->scts, 7);
  912.     memcpy(&entry->sca_number, &data->sca_number, sizeof(l4c_number_struct));
  913.     memcpy(&entry->addr_number, &data->oa_number, sizeof(l4c_number_struct));
  914.     entry->pid = data->pid;
  915.     entry->dcs = data->dcs;
  916.     entry->ori_dcs = data->ori_dcs;
  917.     entry->index = data->index; /* for awaited message, this is the start index */
  918.     entry->mti = data->mti;
  919.     entry->display_type = data->display_type;
  920. #ifdef __MMI_MESSAGES_COPY__
  921.     entry->storageType = data->storage_type;
  922. #endif 
  923.     entry->concat_info = data->concat_info;
  924.     entry->no_msg_data = data->no_msg_data;
  925.     entry->msg_data[0] = MMI_FRM_SMS_MSG_CONTENT_NUM;
  926. }
  927. /*****************************************************************************
  928.  * FUNCTION
  929.  *  mmi_frm_sms_convert_mt_to_entry
  930.  * DESCRIPTION
  931.  *  convert mt structure to entry structure
  932.  * PARAMETERS
  933.  *  data        [?]     Data
  934.  *  entry       [?]     
  935.  *  a  index    index(?)
  936.  *  b  type     type(?)
  937.  * RETURNS
  938.  *  void
  939.  *****************************************************************************/
  940. void mmi_frm_sms_convert_mt_to_entry(mmi_frm_sms_deliver_msg_struct *data, mmi_frm_sms_msgbox_struct *entry)
  941. {
  942.     /*----------------------------------------------------------------*/
  943.     /* Local Variables                                                */
  944.     /*----------------------------------------------------------------*/
  945.     U8 type;
  946.     U8 numbertype = (data->addr_number.type == CSMCC_INTERNATIONAL_ADDR ||
  947.                      (data->addr_number.type & 0xf0) == 0x90) ? 1 : 0;
  948.     mmi_frm_sms_concat_struct *concat = (mmi_frm_sms_concat_struct*) & (data->concat_info);
  949.     MMI_BOOL is_compress = MMI_FALSE;
  950.     /*----------------------------------------------------------------*/
  951.     /* Code Body                                                      */
  952.     /*----------------------------------------------------------------*/
  953.     memset((S8*) entry->number, 0, MAX_DIGITS_SMS);
  954.     if (numbertype)
  955.     {
  956.         entry->number[0] = '+';
  957.     }
  958.     memcpy(entry->number + numbertype, data->addr_number.number, data->addr_number.length);
  959. #ifdef __MMI_MESSAGES_MOSES_FEATURE__    
  960.     if ((data->addr_number.type & 0xd0) == 0xd0)
  961.     {
  962.         /* Support ORANGE MOSES requirement */
  963.         if (data->addr_number.length == 5 &&
  964.             strcmp((S8*)data->addr_number.number,(S8*)MMI_FRM_SMS_MOSES_PATTERN) == 0)
  965.         {
  966.             if (gOpNameValid && (pfnUnicodeStrlen(gOperatorName) != 0))
  967.             {
  968.                 memset((S8*) entry->number, 0, sizeof(entry->number));
  969.                 UnicodeNToAnsii((S8*) entry->number, (S8*) gOperatorName, sizeof(entry->number));
  970.             }            
  971.         }
  972.     }
  973. #endif /* __MMI_MESSAGES_MOSES_FEATURE__ */    
  974.     
  975.     type = MMI_FRM_SMS_UNREAD;
  976. #ifdef __MMI_UNIFIED_MESSAGE__
  977. #ifdef __MMI_MESSAGES_NOT_DISPLAY_8BIT_DCS_SMS_CONTENT__
  978.     if (data->dcs == SMSAL_8BIT_DCS)
  979.     {
  980.         entry->msgtype = (SMSAL_MTI_UNSPECIFIED << 4) | type;
  981.     }
  982.     else
  983. #endif /* __MMI_MESSAGES_NOT_DISPLAY_8BIT_DCS_SMS_CONTENT__ */ 
  984. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  985.     {
  986.         entry->msgtype = (data->mti << 4) | type;
  987.     }
  988.     
  989.     /* Compress dcs SMS is not supported. */
  990.     ems_decode_dcs(data->ori_dcs, &is_compress);
  991.     if (is_compress)
  992.     {
  993.         entry->msgtype = (SMSAL_MTI_UNSPECIFIED << 4) | type;
  994.     }
  995.     entry->startseg =
  996.         ((concat->seg - 1) / g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) * g_frm_sms_cntx.mmi_frm_sms_msg_seg_size + 1;
  997.     entry->totalseg = concat->total_seg;
  998.     entry->startindex = data->index;
  999. #ifdef __MMI_MESSAGES_COPY__
  1000.     entry->storageType = data->storageType;
  1001. #endif 
  1002.     entry->ref = concat->ref;
  1003.     mmi_frm_sms_convert_time_stamp(data->scts, entry->timestamp);
  1004. }
  1005. /*****************************************************************************
  1006.  * FUNCTION
  1007.  *  mmi_frm_sms_convert_mo_to_entry
  1008.  * DESCRIPTION
  1009.  *  convert mo structure to entry structure
  1010.  * PARAMETERS
  1011.  *  data                [?]         Data
  1012.  *  entry               [?]         
  1013.  *  index               [IN]        Index
  1014.  *  status              [IN]        
  1015.  *  totalsegment        [IN]        
  1016.  *  reference           [IN]        
  1017.  *  storagetype         [IN]        
  1018.  *  time                [?]         
  1019.  *  b  type     type(?)
  1020.  * RETURNS
  1021.  *  void
  1022.  *****************************************************************************/
  1023. void mmi_frm_sms_convert_mo_to_entry(
  1024.         mmi_frm_sms_send_struct *data,
  1025.         mmi_frm_sms_msgbox_struct *entry,
  1026.         U16 index,
  1027.         U8 status,
  1028.         U8 totalsegment,
  1029.         U16 reference,
  1030.         U8 storagetype,
  1031.         MYTIME *time)
  1032. {
  1033.     /*----------------------------------------------------------------*/
  1034.     /* Local Variables                                                */
  1035.     /*----------------------------------------------------------------*/
  1036.     U8 type = 0;
  1037.     /*----------------------------------------------------------------*/
  1038.     /* Code Body                                                      */
  1039.     /*----------------------------------------------------------------*/
  1040.     switch (status)
  1041.     {
  1042.         case SMSAL_REC_UNREAD:
  1043.             type = MMI_FRM_SMS_UNREAD;
  1044.             break;
  1045.         case SMSAL_REC_READ:
  1046.             type = MMI_FRM_SMS_INBOX;
  1047.             break;
  1048.         case SMSAL_STO_SENT:
  1049.             type = MMI_FRM_SMS_OUTBOX;
  1050.             break;
  1051.         case SMSAL_STO_UNSENT:
  1052.             type = MMI_FRM_SMS_DRAFTS;
  1053.             break;
  1054.     }
  1055.     entry->msgtype = (SMSAL_MTI_SUBMIT << 4) | type;
  1056.     entry->startindex = index;
  1057.     entry->startseg = 1;
  1058.     entry->totalseg = totalsegment;
  1059.     memset((S8*) entry->timestamp, 0, 7);
  1060.     memset((S8*) entry->number, 0, 21);
  1061.     memcpy((S8*) entry->number, (S8*) data->number, strlen((S8*) data->number));
  1062.     entry->ref = reference;
  1063. #ifdef __MMI_MESSAGES_COPY__
  1064.     entry->storageType = storagetype;
  1065. #endif 
  1066.     if (storagetype == SMSAL_SM)
  1067.     {
  1068.         memset((S8*) entry->timestamp, 0, 7);
  1069.     }
  1070.     else
  1071.     {
  1072.         /* Add timestamp information  */
  1073.         if (time->nYear > 2000)
  1074.         {
  1075.             entry->timestamp[0] = (U8) (time->nYear - 2000);
  1076.         }
  1077.         else
  1078.         {
  1079.             entry->timestamp[0] = (U8) (time->nYear - 1900);
  1080.         }
  1081.         entry->timestamp[1] = time->nMonth;
  1082.         entry->timestamp[2] = time->nDay;
  1083.         entry->timestamp[3] = time->nHour;
  1084.         entry->timestamp[4] = time->nMin;
  1085.         entry->timestamp[5] = time->nSec;
  1086.     }
  1087. }
  1088. /*****************************************************************************
  1089.  * FUNCTION
  1090.  *  mmi_frm_sms_convert_read_to_entry
  1091.  * DESCRIPTION
  1092.  *  convert read structure to entry structure
  1093.  * PARAMETERS
  1094.  *  data        [?]         Data
  1095.  *  entry       [?]         
  1096.  *  index       [IN]        Index
  1097.  *  b  type     type(?)
  1098.  * RETURNS
  1099.  *  void
  1100.  *****************************************************************************/
  1101. void mmi_frm_sms_convert_read_to_entry(
  1102.         MMI_FRM_SMS_GET_MSG_RSP_STRUCT *data,
  1103.         mmi_frm_sms_msgbox_struct *entry,
  1104.         U16 index)
  1105. {
  1106.     /*----------------------------------------------------------------*/
  1107.     /* Local Variables                                                */
  1108.     /*----------------------------------------------------------------*/
  1109.     U8 type;
  1110.     mmi_frm_sms_concat_struct *concat = (mmi_frm_sms_concat_struct*) & (data->concat_info);
  1111.     /*----------------------------------------------------------------*/
  1112.     /* Code Body                                                      */
  1113.     /*----------------------------------------------------------------*/
  1114.     switch (data->status)
  1115.     {
  1116.         case SMSAL_REC_UNREAD:
  1117.             type = MMI_FRM_SMS_UNREAD;
  1118.             break;
  1119.         case SMSAL_REC_READ:
  1120.             type = MMI_FRM_SMS_INBOX;
  1121.             break;
  1122.         case SMSAL_STO_SENT:
  1123.             type = MMI_FRM_SMS_OUTBOX;
  1124.             break;
  1125.         case SMSAL_STO_UNSENT:
  1126.             type = MMI_FRM_SMS_DRAFTS;
  1127.             break;
  1128.         default:
  1129.             type = MMI_FRM_SMS_NOBOX;
  1130.             break;
  1131.     }
  1132.     entry->msgtype = (data->mti << 4) | type;
  1133.     entry->startseg =
  1134.         ((concat->seg - 1) / g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) * g_frm_sms_cntx.mmi_frm_sms_msg_seg_size + 1;
  1135.     entry->totalseg = concat->total_seg;
  1136.     memset((S8*) entry->number, 0, MAX_DIGITS_SMS);
  1137.     type = (data->addr_number.type == CSMCC_INTERNATIONAL_ADDR ||
  1138.             (data->addr_number.type & 0xf0) == 0x90) ? 1 : 0;
  1139.     if (type)
  1140.     {
  1141.         entry->number[0] = '+';
  1142.     }
  1143.     memcpy((S8*) & (entry->number[type]), (S8*) data->addr_number.number, data->addr_number.length);
  1144.     
  1145. #ifdef __MMI_MESSAGES_MOSES_FEATURE__    
  1146.     if ((data->addr_number.type & 0xd0) == 0xd0)
  1147.     {
  1148.         /* Support ORANGE MOSES requirement */
  1149.         if (data->addr_number.length == 5 &&
  1150.             strcmp((S8*)data->addr_number.number,(S8*)MMI_FRM_SMS_MOSES_PATTERN) == 0)
  1151.         {
  1152.             if (gOpNameValid && (pfnUnicodeStrlen(gOperatorName) != 0))
  1153.             {
  1154.                 memset((S8*) entry->number, 0, sizeof(entry->number));
  1155.                 UnicodeNToAnsii((S8*) entry->number, (S8*) gOperatorName, sizeof(entry->number));
  1156.             }            
  1157.         }
  1158.     }
  1159. #endif /* __MMI_MESSAGES_MOSES_FEATURE__ */    
  1160.     entry->ref = concat->ref;
  1161.     entry->startindex = index;
  1162. #ifdef __MMI_MESSAGES_COPY__
  1163.     entry->storageType = data->storage_type;
  1164. #endif 
  1165. #ifdef __MMI_UNIFIED_MESSAGE__
  1166.     {
  1167.         U8 *content = NULL;
  1168.         content = OslMalloc(MMI_FRM_SMS_MSG_LEN);
  1169.         memset(content, 0, MMI_FRM_SMS_MSG_LEN);
  1170.         memset(entry->content, 0, sizeof(entry->content));
  1171.         mmi_frm_sms_get_read_sms_content(data, content);
  1172.         if (pfnUnicodeStrlen((S8*) content))
  1173.         {
  1174.             mmi_frm_sms_add_content_to_entry(entry, content);
  1175.         }
  1176.         OslMfree(content);
  1177.     }
  1178. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  1179.     mmi_frm_sms_convert_time_stamp(data->scts, entry->timestamp);
  1180. }
  1181. /*****************************************************************************
  1182.  * FUNCTION
  1183.  *  mmi_frm_sms_convert_startup_read_to_entry
  1184.  * DESCRIPTION
  1185.  *  convert startup read structure to entry structure
  1186.  * PARAMETERS
  1187.  *  data        [?]     Data
  1188.  *  entry       [?]     
  1189.  *  a  index    index(?)
  1190.  *  b  type     type(?)
  1191.  * RETURNS
  1192.  *  void
  1193.  *****************************************************************************/
  1194. void mmi_frm_sms_convert_startup_read_to_entry(
  1195.         MMI_FRM_SMS_STARTUP_READ_MSG_IND_STRUCT *data,
  1196.         mmi_frm_sms_msgbox_struct *entry)
  1197. {
  1198.     /*----------------------------------------------------------------*/
  1199.     /* Local Variables                                                */
  1200.     /*----------------------------------------------------------------*/
  1201.     U8 type;
  1202.     mmi_frm_sms_concat_struct concat;
  1203.     MMI_BOOL is_compress = MMI_FALSE;
  1204.     /*----------------------------------------------------------------*/
  1205.     /* Code Body                                                      */
  1206.     /*----------------------------------------------------------------*/
  1207.     concat.seg = (data->concat_info & 0xff000000) >> 24;
  1208.     concat.total_seg = (data->concat_info & 0x00ff0000) >> 16;
  1209.     concat.ref = (data->concat_info & 0x0000ffff);
  1210.     switch (data->status)
  1211.     {
  1212.         case SMSAL_REC_UNREAD:
  1213.             type = MMI_FRM_SMS_UNREAD;
  1214.             break;
  1215.         case SMSAL_REC_READ:
  1216.             type = MMI_FRM_SMS_INBOX;
  1217.             break;
  1218.         case SMSAL_STO_SENT:
  1219.             type = MMI_FRM_SMS_OUTBOX;
  1220.             break;
  1221.         case SMSAL_STO_UNSENT:
  1222.             type = MMI_FRM_SMS_DRAFTS;
  1223.             break;
  1224.         default:
  1225.             type = MMI_FRM_SMS_NOBOX;
  1226.             break;
  1227.     }
  1228. #ifdef __MMI_UNIFIED_MESSAGE__
  1229. #ifdef __MMI_MESSAGES_NOT_DISPLAY_8BIT_DCS_SMS_CONTENT__
  1230.     if (data->dcs == SMSAL_8BIT_DCS)
  1231.     {
  1232.         entry->msgtype = (SMSAL_MTI_UNSPECIFIED << 4) | type;
  1233.     }
  1234.     else
  1235. #endif /* __MMI_MESSAGES_NOT_DISPLAY_8BIT_DCS_SMS_CONTENT__ */ 
  1236. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  1237.     {
  1238.         entry->msgtype = (data->mti << 4) | type;
  1239.     }
  1240.     
  1241.     /* Compress dcs SMS is not supported. */
  1242.     ems_decode_dcs(data->ori_dcs, &is_compress);
  1243.     if (is_compress)
  1244.     {
  1245.         entry->msgtype = (SMSAL_MTI_UNSPECIFIED << 4) | type;
  1246.     }
  1247.     entry->startseg =
  1248.         ((concat.seg - 1) / g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) * g_frm_sms_cntx.mmi_frm_sms_msg_seg_size + 1;
  1249.     entry->totalseg = concat.total_seg;
  1250.     memset((S8*) entry->number, 0, MAX_DIGITS_SMS);
  1251.     type = (data->addr_number.type == CSMCC_INTERNATIONAL_ADDR ||
  1252.             (data->addr_number.type & 0xf0) == 0x90) ? 1 : 0;
  1253.     if (type)
  1254.     {
  1255.         entry->number[0] = '+';
  1256.     }
  1257.     memcpy((S8*) & (entry->number[type]), (S8*) data->addr_number.number, data->addr_number.length);
  1258. #ifdef __MMI_MESSAGES_MOSES_FEATURE__    
  1259.     if ((data->addr_number.type & 0xd0) == 0xd0)
  1260.     {
  1261.         /* Support ORANGE MOSES requirement */
  1262.         if (data->addr_number.length == 5 &&
  1263.             strcmp((S8*)data->addr_number.number,(S8*)MMI_FRM_SMS_MOSES_PATTERN) == 0)
  1264.         {
  1265.             if (gOpNameValid && (pfnUnicodeStrlen(gOperatorName) != 0))
  1266.             {
  1267.                 memset((S8*) entry->number, 0, sizeof(entry->number));
  1268.                 UnicodeNToAnsii((S8*) entry->number, (S8*) gOperatorName, sizeof(entry->number));
  1269.             }            
  1270.         }
  1271.     }
  1272. #endif /* __MMI_MESSAGES_MOSES_FEATURE__ */
  1273.     entry->ref = concat.ref;
  1274.     entry->startindex = data->index;
  1275.     mmi_frm_sms_convert_time_stamp(data->scts, entry->timestamp);
  1276. #ifdef __MMI_MESSAGES_COPY__
  1277.     entry->storageType = data->storage_type;
  1278. #endif 
  1279. #ifdef __MMI_UNIFIED_MESSAGE__
  1280.     {
  1281.         U8 *content = NULL;
  1282.         memset(entry->content, 0, sizeof(entry->content));
  1283.         content = OslMalloc(MMI_FRM_SMS_MSG_LEN);
  1284.         memset(content, 0, MMI_FRM_SMS_MSG_LEN);
  1285.         mmi_frm_sms_get_startup_sms_content(data, content);
  1286.         if (pfnUnicodeStrlen((S8*) content))
  1287.         {
  1288.             mmi_frm_sms_add_content_to_entry(entry, content);
  1289.         }
  1290.         OslMfree(content);
  1291.     }
  1292. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  1293. }
  1294. /*****************************************************************************
  1295.  * FUNCTION
  1296.  *  mmi_frm_sms_compare_entry
  1297.  * DESCRIPTION
  1298.  *  convert mo structure to entry structure
  1299.  * PARAMETERS
  1300.  *  index           [IN]        Index
  1301.  *  data            [?]         Data
  1302.  *  thissegment     [IN]        
  1303.  *  b  type     type(?)
  1304.  * RETURNS
  1305.  *  void
  1306.  *****************************************************************************/
  1307. U8 mmi_frm_sms_compare_entry(U16 index, mmi_frm_sms_msgbox_struct *data, U8 thissegment)
  1308. {
  1309.     /*----------------------------------------------------------------*/
  1310.     /* Local Variables                                                */
  1311.     /*----------------------------------------------------------------*/
  1312.     /*----------------------------------------------------------------*/
  1313.     /* Code Body                                                      */
  1314.     /*----------------------------------------------------------------*/
  1315.     /* concatenate class0 message will have a MMI_FRM_SMS_INVALID_INDEX startindex */
  1316.     if ((data->startindex != MMI_FRM_SMS_INVALID_INDEX) && (mmi_frm_sms_msg_box[index].startindex == data->startindex))
  1317.     {
  1318.         return TRUE;
  1319.     }
  1320.     if ((mmi_frm_sms_msg_box[index].msgtype & 0xf0) == (data->msgtype & 0xf0))
  1321.         if (mmi_frm_sms_msg_box[index].ref == data->ref)
  1322.             if (mmi_frm_sms_msg_box[index].totalseg == data->totalseg)
  1323.                 if (mmi_frm_sms_msg_box[index].startseg == data->startseg)
  1324.                     if (ComparePhoneNum((U8*) data->number, (U8*) mmi_frm_sms_msg_box[index].number) == TRUE)
  1325.                     {
  1326.                         U16 i = mmi_frm_sms_msg_box[index].startindex;
  1327.                         U16 previndex = MMI_FRM_SMS_INVALID_INDEX;
  1328.                         while (i != MMI_FRM_SMS_INVALID_INDEX)
  1329.                         {
  1330.                             if (mmi_frm_sms_index_list[i].segment == thissegment)
  1331.                             {
  1332.                                 return FALSE;
  1333.                             }
  1334.                             else if (mmi_frm_sms_index_list[i].segment > thissegment)
  1335.                             {
  1336.                                 return TRUE;
  1337.                             }
  1338.                             previndex = i;
  1339.                             i = mmi_frm_sms_index_list[i].nextindex;
  1340.                         }
  1341.                         if ((previndex != MMI_FRM_SMS_INVALID_INDEX) &&
  1342.                             (mmi_frm_sms_index_list[previndex].segment < thissegment))
  1343.                         {
  1344.                             return TRUE;
  1345.                         }
  1346.                     }
  1347.     return FALSE;
  1348. }
  1349. /*****************************************************************************
  1350.  * FUNCTION
  1351.  *  mmi_frm_sms_add_sms_to_list
  1352.  * DESCRIPTION
  1353.  *  mmi_frm_sms_add_sms_to_list
  1354.  * PARAMETERS
  1355.  *  data        [?]         Data
  1356.  *  index       [IN]        Index
  1357.  *  b  type     type(?)
  1358.  * RETURNS
  1359.  *  void
  1360.  *****************************************************************************/
  1361. void mmi_frm_sms_add_sms_to_list(mmi_frm_sms_msgbox_struct *data, U16 index)
  1362. {
  1363.     /*----------------------------------------------------------------*/
  1364.     /* Local Variables                                                */
  1365.     /*----------------------------------------------------------------*/
  1366.     U8 type = MMI_FRM_SMS_NOBOX;
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Code Body                                                      */
  1369.     /*----------------------------------------------------------------*/
  1370.     if ((data->msgtype & MMI_FRM_SMS_UNREAD) == MMI_FRM_SMS_UNREAD)
  1371.     {
  1372.         type = MMI_FRM_SMS_UNREAD;
  1373.     }
  1374.     else if ((data->msgtype & MMI_FRM_SMS_INBOX) == MMI_FRM_SMS_INBOX)
  1375.     {
  1376.         type = MMI_FRM_SMS_INBOX;
  1377.     }
  1378.     else if ((data->msgtype & MMI_FRM_SMS_OUTBOX) == MMI_FRM_SMS_OUTBOX)
  1379.     {
  1380.         type = MMI_FRM_SMS_OUTBOX;
  1381.     }
  1382.     else if ((data->msgtype & MMI_FRM_SMS_DRAFTS) == MMI_FRM_SMS_DRAFTS)
  1383. #ifdef __MMI_MESSAGES_DRAFT_BOX__
  1384.         type = MMI_FRM_SMS_DRAFTS;
  1385. #else 
  1386.         type = MMI_FRM_SMS_OUTBOX;
  1387. #endif 
  1388.     switch (type)
  1389.     {
  1390.         case MMI_FRM_SMS_INBOX:
  1391.         case MMI_FRM_SMS_UNREAD:
  1392.         {
  1393.             U16 i = 0;
  1394.             U16 j;
  1395.             while (i < mmi_frm_sms_inbox_size)
  1396.             {
  1397.                 if (mmi_frm_sms_inbox_list[i] == index)
  1398.                 {
  1399.                     return;
  1400.                 }
  1401.                 if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[0] < data->timestamp[0])
  1402.                 {
  1403.                     break;
  1404.                 }
  1405.                 else if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[0] > data->timestamp[0])
  1406.                 {
  1407.                     i++;
  1408.                     continue;
  1409.                 }
  1410.                 if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[1] < data->timestamp[1])
  1411.                 {
  1412.                     break;
  1413.                 }
  1414.                 else if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[1] > data->timestamp[1])
  1415.                 {
  1416.                     i++;
  1417.                     continue;
  1418.                 }
  1419.                 if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[2] < data->timestamp[2])
  1420.                 {
  1421.                     break;
  1422.                 }
  1423.                 else if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[2] > data->timestamp[2])
  1424.                 {
  1425.                     i++;
  1426.                     continue;
  1427.                 }
  1428.                 if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[3] < data->timestamp[3])
  1429.                 {
  1430.                     break;
  1431.                 }
  1432.                 else if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[3] > data->timestamp[3])
  1433.                 {
  1434.                     i++;
  1435.                     continue;
  1436.                 }
  1437.                 if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[4] < data->timestamp[4])
  1438.                 {
  1439.                     break;
  1440.                 }
  1441.                 else if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[4] > data->timestamp[4])
  1442.                 {
  1443.                     i++;
  1444.                     continue;
  1445.                 }
  1446.                 if (mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[i]].timestamp[5] <= data->timestamp[5])
  1447.                 {
  1448.                     break;
  1449.                 }
  1450.                 i++;
  1451.                 continue;
  1452.             }
  1453.             if (mmi_frm_sms_inbox_size > 0)
  1454.             {
  1455.                 for (j = mmi_frm_sms_inbox_size; j > i; j--)
  1456.                 {
  1457.                     mmi_frm_sms_inbox_list[j] = mmi_frm_sms_inbox_list[j - 1];
  1458.                 }
  1459.             }
  1460.             mmi_frm_sms_inbox_list[i] = index;
  1461.             mmi_frm_sms_inbox_size++;
  1462.         }
  1463.             break;
  1464.         case MMI_FRM_SMS_OUTBOX:
  1465.     #ifndef __MMI_MESSAGES_DRAFT_BOX__
  1466.         case MMI_FRM_SMS_DRAFTS:
  1467.     #endif 
  1468.         {
  1469.             U16 i = 0;
  1470.             U16 j = 0;
  1471.             U16 k = 0;
  1472.             for (k = 0; k < mmi_frm_sms_outbox_size; k++)
  1473.             {
  1474.                 if (mmi_frm_sms_outbox_list[k] == index)
  1475.                 {
  1476.                     return;
  1477.                 }
  1478.             }
  1479.             /* No timestamp */
  1480.             if (data->timestamp[1] == 0)
  1481.             {
  1482.                 mmi_frm_sms_outbox_list[mmi_frm_sms_outbox_size] = index;
  1483.                 mmi_frm_sms_outbox_size++;
  1484.             }
  1485.             else
  1486.             {
  1487.                 while (i < mmi_frm_sms_outbox_size)
  1488.                 {
  1489.                     if (mmi_frm_sms_outbox_list[i] == index)
  1490.                     {
  1491.                         return;
  1492.                     }
  1493.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[0] < data->timestamp[0])
  1494.                     {
  1495.                         break;
  1496.                     }
  1497.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[0] > data->timestamp[0])
  1498.                     {
  1499.                         i++;
  1500.                         continue;
  1501.                     }
  1502.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[1] < data->timestamp[1])
  1503.                     {
  1504.                         break;
  1505.                     }
  1506.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[1] > data->timestamp[1])
  1507.                     {
  1508.                         i++;
  1509.                         continue;
  1510.                     }
  1511.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[2] < data->timestamp[2])
  1512.                     {
  1513.                         break;
  1514.                     }
  1515.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[2] > data->timestamp[2])
  1516.                     {
  1517.                         i++;
  1518.                         continue;
  1519.                     }
  1520.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[3] < data->timestamp[3])
  1521.                     {
  1522.                         break;
  1523.                     }
  1524.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[3] > data->timestamp[3])
  1525.                     {
  1526.                         i++;
  1527.                         continue;
  1528.                     }
  1529.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[4] < data->timestamp[4])
  1530.                     {
  1531.                         break;
  1532.                     }
  1533.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[4] > data->timestamp[4])
  1534.                     {
  1535.                         i++;
  1536.                         continue;
  1537.                     }
  1538.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[i]].timestamp[5] <= data->timestamp[5])
  1539.                     {
  1540.                         break;
  1541.                     }
  1542.                     i++;
  1543.                     continue;
  1544.                 }
  1545.                 if (mmi_frm_sms_outbox_size > 0)
  1546.                 {
  1547.                     for (j = mmi_frm_sms_outbox_size; j > i; j--)
  1548.                     {
  1549.                         mmi_frm_sms_outbox_list[j] = mmi_frm_sms_outbox_list[j - 1];
  1550.                     }
  1551.                 }
  1552.                 mmi_frm_sms_outbox_list[i] = index;
  1553.                 mmi_frm_sms_outbox_size++;
  1554.             }
  1555.         }
  1556.             break;
  1557.     #ifdef __MMI_MESSAGES_DRAFT_BOX__
  1558.         case MMI_FRM_SMS_DRAFTS:
  1559.         {
  1560.             U16 i = 0;
  1561.             U16 j = 0;
  1562.             U16 k = 0;
  1563.             for (k = 0; k < mmi_frm_sms_drafts_size; k++)
  1564.             {
  1565.                 if (mmi_frm_sms_drafts_list[k] == index)
  1566.                 {
  1567.                     return;
  1568.                 }
  1569.             }
  1570.             /* No timestamp */
  1571.             if (data->timestamp[1] == 0)
  1572.             {
  1573.                 mmi_frm_sms_drafts_list[mmi_frm_sms_drafts_size] = index;
  1574.                 mmi_frm_sms_drafts_size++;
  1575.             }
  1576.             else
  1577.             {
  1578.                 while (i < mmi_frm_sms_drafts_size)
  1579.                 {
  1580.                     if (mmi_frm_sms_drafts_list[i] == index)
  1581.                     {
  1582.                         return;
  1583.                     }
  1584.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[0] < data->timestamp[0])
  1585.                     {
  1586.                         break;
  1587.                     }
  1588.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[0] > data->timestamp[0])
  1589.                     {
  1590.                         i++;
  1591.                         continue;
  1592.                     }
  1593.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[1] < data->timestamp[1])
  1594.                     {
  1595.                         break;
  1596.                     }
  1597.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[1] > data->timestamp[1])
  1598.                     {
  1599.                         i++;
  1600.                         continue;
  1601.                     }
  1602.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[2] < data->timestamp[2])
  1603.                     {
  1604.                         break;
  1605.                     }
  1606.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[2] > data->timestamp[2])
  1607.                     {
  1608.                         i++;
  1609.                         continue;
  1610.                     }
  1611.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[3] < data->timestamp[3])
  1612.                     {
  1613.                         break;
  1614.                     }
  1615.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[3] > data->timestamp[3])
  1616.                     {
  1617.                         i++;
  1618.                         continue;
  1619.                     }
  1620.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[4] < data->timestamp[4])
  1621.                     {
  1622.                         break;
  1623.                     }
  1624.                     else if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[4] > data->timestamp[4])
  1625.                     {
  1626.                         i++;
  1627.                         continue;
  1628.                     }
  1629.                     if (mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[i]].timestamp[5] <= data->timestamp[5])
  1630.                     {
  1631.                         break;
  1632.                     }
  1633.                     i++;
  1634.                     continue;
  1635.                 }
  1636.                 if (mmi_frm_sms_drafts_size > 0)
  1637.                 {
  1638.                     for (j = mmi_frm_sms_drafts_size; j > i; j--)
  1639.                     {
  1640.                         mmi_frm_sms_drafts_list[j] = mmi_frm_sms_drafts_list[j - 1];
  1641.                     }
  1642.                 }
  1643.                 mmi_frm_sms_drafts_list[i] = index;
  1644.                 mmi_frm_sms_drafts_size++;
  1645.             }
  1646.         }
  1647.             break;
  1648.     #endif /* __MMI_MESSAGES_DRAFT_BOX__ */ 
  1649.     }
  1650. }
  1651. /*****************************************************************************
  1652.  * FUNCTION
  1653.  *  mmi_frm_sms_remove_sms_from_list
  1654.  * DESCRIPTION
  1655.  *  mmi_frm_sms_remove_sms_from_list
  1656.  * PARAMETERS
  1657.  *  index       [IN]        Index
  1658.  *  type        [IN]        Type
  1659.  * RETURNS
  1660.  *  void
  1661.  *****************************************************************************/
  1662. void mmi_frm_sms_remove_sms_from_list(U16 index, U8 type)
  1663. {
  1664.     /*----------------------------------------------------------------*/
  1665.     /* Local Variables                                                */
  1666.     /*----------------------------------------------------------------*/
  1667.     U16 i = 0;
  1668.     U16 j = 0;
  1669.     /*----------------------------------------------------------------*/
  1670.     /* Code Body                                                      */
  1671.     /*----------------------------------------------------------------*/
  1672.     if (mmi_frm_sms_get_sms_list_size(MMI_FRM_SMS_NOBOX) == MMI_FRM_SMS_INVALID_INDEX)
  1673.     {
  1674.         PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  1675.                              "*-------[SmsUtil.c] mmi_frm_sms_remove_sms_from_list DO NOTHING -------*n"));
  1676.         return;
  1677.     }
  1678.     switch (type)
  1679.     {
  1680.         case MMI_FRM_SMS_INBOX:
  1681.         case MMI_FRM_SMS_UNREAD:
  1682.             while (i < mmi_frm_sms_inbox_size)
  1683.             {
  1684.                 if (mmi_frm_sms_inbox_list[i] == index)
  1685.                 {
  1686.                     break;
  1687.                 }
  1688.                 i++;
  1689.             }
  1690.             for (j = i; j < (mmi_frm_sms_inbox_size - 1); j++)
  1691.             {
  1692.                 mmi_frm_sms_inbox_list[j] = mmi_frm_sms_inbox_list[j + 1];
  1693.             }
  1694.             mmi_frm_sms_inbox_list[j] = MMI_FRM_SMS_INVALID_INDEX;
  1695.             mmi_frm_sms_inbox_size--;
  1696.             break;
  1697.         case MMI_FRM_SMS_OUTBOX:
  1698.         #ifndef __MMI_MESSAGES_DRAFT_BOX__
  1699.         case MMI_FRM_SMS_DRAFTS:
  1700.         #endif 
  1701.             while (i < mmi_frm_sms_outbox_size)
  1702.             {
  1703.                 if (mmi_frm_sms_outbox_list[i] == index)
  1704.                 {
  1705.                     break;
  1706.                 }
  1707.                 i++;
  1708.             }
  1709.             for (j = i; j < (mmi_frm_sms_outbox_size - 1); j++)
  1710.             {
  1711.                 mmi_frm_sms_outbox_list[j] = mmi_frm_sms_outbox_list[j + 1];
  1712.             }
  1713.             mmi_frm_sms_outbox_list[j] = MMI_FRM_SMS_INVALID_INDEX;
  1714.             mmi_frm_sms_outbox_size--;
  1715.             break;
  1716.         #ifdef __MMI_MESSAGES_DRAFT_BOX__
  1717.         case MMI_FRM_SMS_DRAFTS:
  1718.             while (i < mmi_frm_sms_drafts_size)
  1719.             {
  1720.                 if (mmi_frm_sms_drafts_list[i] == index)
  1721.                 {
  1722.                     break;
  1723.                 }
  1724.                 i++;
  1725.             }
  1726.             for (j = i; j < (mmi_frm_sms_drafts_size - 1); j++)
  1727.             {
  1728.                 mmi_frm_sms_drafts_list[j] = mmi_frm_sms_drafts_list[j + 1];
  1729.             }
  1730.             mmi_frm_sms_drafts_list[j] = MMI_FRM_SMS_INVALID_INDEX;
  1731.             mmi_frm_sms_drafts_size--;
  1732.             break;
  1733.         #endif /* __MMI_MESSAGES_DRAFT_BOX__ */ 
  1734.     }
  1735. }
  1736. /*****************************************************************************
  1737.  * FUNCTION
  1738.  *  mmi_frm_sms_add_sms_segment
  1739.  * DESCRIPTION
  1740.  *  add one segment to sms entry
  1741.  * PARAMETERS
  1742.  *  index           [IN]        Index
  1743.  *  addindex        [IN]        Addindex
  1744.  *  segment         [IN]        Segment
  1745.  * RETURNS
  1746.  *  void
  1747.  *****************************************************************************/
  1748. void mmi_frm_sms_add_sms_segment(U16 index, U16 addindex, U8 segment)
  1749. {
  1750.     /*----------------------------------------------------------------*/
  1751.     /* Local Variables                                                */
  1752.     /*----------------------------------------------------------------*/
  1753.     U16 thisindex = mmi_frm_sms_msg_box[index].startindex;
  1754.     U8 islast = TRUE;
  1755.     /*----------------------------------------------------------------*/
  1756.     /* Code Body                                                      */
  1757.     /*----------------------------------------------------------------*/
  1758.     mmi_frm_sms_index_list[addindex].segment = segment;
  1759.     /* thisindex is the current smallest segment index of this message */
  1760.     if (mmi_frm_sms_index_list[thisindex].segment > segment)
  1761.     {
  1762.         islast = FALSE;
  1763.         /* addindex is inserted in the head, now addindex is the current smallest segment index of this message */
  1764.         mmi_frm_sms_msg_box[index].startindex = addindex;
  1765.     }
  1766.     else
  1767.     {
  1768.         while (mmi_frm_sms_index_list[thisindex].nextindex != MMI_FRM_SMS_INVALID_INDEX)
  1769.         {
  1770.             thisindex = mmi_frm_sms_index_list[thisindex].nextindex;
  1771.             if (mmi_frm_sms_index_list[thisindex].segment > segment)
  1772.             {
  1773.                 islast = FALSE;
  1774.                 break;
  1775.             }
  1776.         }
  1777.     }
  1778.     if (islast == TRUE)
  1779.     {
  1780.         /* addindex is inserted in the tail, now addindex is the current largest segment index of this message */
  1781.         mmi_frm_sms_index_list[thisindex].nextindex = addindex;
  1782.         mmi_frm_sms_index_list[addindex].nextindex = MMI_FRM_SMS_INVALID_INDEX;
  1783.         mmi_frm_sms_index_list[addindex].previndex = thisindex;
  1784.         mmi_frm_sms_index_list[addindex].prevtype = MMI_FRM_SMS_NOBOX;
  1785.     }
  1786.     else
  1787.     {
  1788.         /* addindex is inserted in the middle */
  1789.         mmi_frm_sms_index_list[addindex].nextindex = thisindex;
  1790.         mmi_frm_sms_index_list[addindex].previndex = mmi_frm_sms_index_list[thisindex].previndex;
  1791.         mmi_frm_sms_index_list[addindex].prevtype = mmi_frm_sms_index_list[thisindex].prevtype;
  1792.         if (mmi_frm_sms_index_list[thisindex].prevtype == MMI_FRM_SMS_NOBOX)
  1793.         {
  1794.             mmi_frm_sms_index_list[mmi_frm_sms_index_list[thisindex].previndex].nextindex = addindex;
  1795.         }
  1796.         mmi_frm_sms_index_list[thisindex].previndex = addindex;
  1797.         mmi_frm_sms_index_list[thisindex].prevtype = MMI_FRM_SMS_NOBOX;
  1798.     }
  1799. }
  1800. /*****************************************************************************
  1801.  * FUNCTION
  1802.  *  mmi_frm_sms_add_sms_entry
  1803.  * DESCRIPTION
  1804.  *  add sms entry:
  1805.  * PARAMETERS
  1806.  *  data            [?]         
  1807.  *  L4index         [IN]        
  1808.  *  thissegment     [IN]        
  1809.  *  a  index       index(?)
  1810.  *  b  addindex    addindex(?)
  1811.  *  c  segment     segment(?)
  1812.  * RETURNS
  1813.  *  index
  1814.  *****************************************************************************/
  1815. U16 mmi_frm_sms_add_sms_entry(mmi_frm_sms_msgbox_struct *data, U16 L4index, U8 thissegment)
  1816. {
  1817.     /*----------------------------------------------------------------*/
  1818.     /* Local Variables                                                */
  1819.     /*----------------------------------------------------------------*/
  1820.     U16 addindex = g_frm_sms_cntx.mmi_frm_sms_msg_box_size;
  1821.     U16 emptyindex = g_frm_sms_cntx.mmi_frm_sms_msg_box_size;
  1822.     U8 found = FALSE;
  1823.     /*----------------------------------------------------------------*/
  1824.     /* Code Body                                                      */
  1825.     /*----------------------------------------------------------------*/
  1826.     while ((found == FALSE) && (addindex > 0))
  1827.     {
  1828.         addindex--;
  1829.         if (mmi_frm_sms_msg_box[addindex].startindex == MMI_FRM_SMS_INVALID_INDEX)
  1830.         {
  1831.             emptyindex = addindex;
  1832.             continue;
  1833.         }
  1834.         if (mmi_frm_sms_compare_entry(addindex, data, thissegment) == TRUE)
  1835.         {
  1836.             found = TRUE;
  1837.             break;
  1838.         }
  1839.     }
  1840.     if (found == FALSE)
  1841.     {
  1842.         U8 type;
  1843.         if ((data->msgtype & MMI_FRM_SMS_INBOX) == MMI_FRM_SMS_INBOX)
  1844.         {
  1845.             type = MMI_FRM_SMS_INBOX;
  1846.         }
  1847.         else if ((data->msgtype & MMI_FRM_SMS_UNREAD) == MMI_FRM_SMS_UNREAD)
  1848.         {
  1849.             type = MMI_FRM_SMS_UNREAD;
  1850.         }
  1851.         else if ((data->msgtype & MMI_FRM_SMS_OUTBOX) == MMI_FRM_SMS_OUTBOX)
  1852.         {
  1853.             type = MMI_FRM_SMS_OUTBOX;
  1854.         }
  1855.         else
  1856.         {
  1857.             type = MMI_FRM_SMS_DRAFTS;
  1858.         }
  1859.         memcpy((S8*) & mmi_frm_sms_msg_box[emptyindex], (S8*) data, sizeof(mmi_frm_sms_msgbox_struct));
  1860.         mmi_frm_sms_index_list[L4index].segment = thissegment;
  1861.         /* mmi_frm_sms_index_list[L4index].nextindex=MMI_FRM_SMS_INVALID_INDEX; */
  1862.         mmi_frm_sms_index_list[L4index].previndex = emptyindex;
  1863.         mmi_frm_sms_index_list[L4index].prevtype = type;
  1864.         mmi_frm_sms_msgbox_size++;
  1865.         addindex = emptyindex;
  1866.     }
  1867.     else
  1868.     {
  1869.     #ifdef __MMI_MESSAGES_COPY__
  1870.         if (mmi_frm_sms_msg_box[addindex].storageType != MMI_FRM_SMS_PREFER_STORAGE)
  1871.         {
  1872.             mmi_frm_sms_msg_box[addindex].storageType = data->storageType;
  1873.         }
  1874.     #endif /* __MMI_MESSAGES_COPY__ */ 
  1875.     #ifdef __MMI_UNIFIED_MESSAGE__
  1876.         if (mmi_frm_sms_index_list[mmi_frm_sms_msg_box[addindex].startindex].segment == thissegment - 1)
  1877.         {
  1878.             if (pfnUnicodeStrlen((S8*) data->content))
  1879.             {
  1880.                 if (pfnUnicodeStrlen((S8*) mmi_frm_sms_msg_box[addindex].content) <
  1881.                     (mmi_msg_get_max_content_size() - 1))
  1882.                 {
  1883.                     /* append data->content to mmi_frm_sms_msg_box[addindex].content */
  1884.                     U16 *temp_content;
  1885.                     U16 temp_content_size = (U16) (mmi_msg_get_max_content_size() + 1) * ENCODING_LENGTH;
  1886.                     temp_content = OslMalloc(temp_content_size);
  1887.                     memset((S8*) temp_content, 0, temp_content_size);
  1888.                     pfnUnicodeStrncpy(
  1889.                         (S8*) temp_content,
  1890.                         (S8*) mmi_frm_sms_msg_box[addindex].content,
  1891.                         mmi_msg_get_max_content_size());
  1892.                     pfnUnicodeStrncat(
  1893.                         (S8*) temp_content,
  1894.                         (S8*) data->content,
  1895.                         (mmi_msg_get_max_content_size() - pfnUnicodeStrlen((S8*) temp_content)));
  1896.                     mmi_frm_sms_add_content_to_entry(
  1897.                         (mmi_frm_sms_msgbox_struct*) & mmi_frm_sms_msg_box[addindex],
  1898.                         (U8*) temp_content);
  1899.                     OslMfree(temp_content);
  1900.                 }
  1901.             }
  1902.         }
  1903.         else if (mmi_frm_sms_index_list[mmi_frm_sms_msg_box[addindex].startindex].segment == thissegment + 1)
  1904.         {
  1905.             if (pfnUnicodeStrlen((S8*) data->content))
  1906.             {
  1907.                 /* copy data->content to the beginning of  mmi_frm_sms_msg_box[addindex].content */
  1908.                 U16 *temp_content;
  1909.                 U16 temp_content_size = (U16) (mmi_msg_get_max_content_size() + 1) * ENCODING_LENGTH;
  1910.                 temp_content = OslMalloc(temp_content_size);
  1911.                 memset((S8*) temp_content, 0, temp_content_size);
  1912.                 pfnUnicodeStrncpy((S8*) temp_content, (S8*) data->content, mmi_msg_get_max_content_size());
  1913.                 if (mmi_msg_get_max_content_size() > pfnUnicodeStrlen((S8*) temp_content))
  1914.                 {
  1915.                     pfnUnicodeStrncat(
  1916.                         (S8*) temp_content,
  1917.                         (S8*) mmi_frm_sms_msg_box[addindex].content,
  1918.                         (mmi_msg_get_max_content_size() - pfnUnicodeStrlen((S8*) temp_content)));
  1919.                 }
  1920.                 mmi_frm_sms_add_content_to_entry(
  1921.                     (mmi_frm_sms_msgbox_struct*) & mmi_frm_sms_msg_box[addindex],
  1922.                     (U8*) temp_content);
  1923.                 OslMfree(temp_content);
  1924.             }
  1925.         }
  1926.         else if (mmi_frm_sms_index_list[mmi_frm_sms_msg_box[addindex].startindex].segment > thissegment)
  1927.         {
  1928.             if (pfnUnicodeStrlen((S8*) data->content))
  1929.             {
  1930.                 mmi_frm_sms_add_content_to_entry(
  1931.                     (mmi_frm_sms_msgbox_struct*) & mmi_frm_sms_msg_box[addindex],
  1932.                     (U8*) data->content);
  1933.             }
  1934.         }
  1935.         else
  1936.         {
  1937.             /* thissegment > start_segment + 1 */
  1938.             /* If thissegment is the last segment of received segments, append the content */
  1939.             if (pfnUnicodeStrlen((S8*) mmi_frm_sms_msg_box[addindex].content) <
  1940.                 (mmi_msg_get_max_content_size() - 1))
  1941.             {
  1942.                 U16 l4_index = mmi_frm_sms_index_list[mmi_frm_sms_msg_box[addindex].startindex].nextindex;
  1943.                 if (l4_index == MMI_FRM_SMS_INVALID_INDEX)
  1944.                 {
  1945.                     /* Do nothing */
  1946.                     ;
  1947.                 }
  1948.                 else
  1949.                 {
  1950.                     for (;;)
  1951.                     {
  1952.                         /* Received segments are continuous */
  1953.                         if (mmi_frm_sms_index_list[l4_index].nextindex == MMI_FRM_SMS_INVALID_INDEX)
  1954.                         {
  1955.                             if ((mmi_frm_sms_index_list[l4_index].segment - 1 ) != 
  1956.                                 mmi_frm_sms_index_list[mmi_frm_sms_index_list[l4_index].previndex].segment)
  1957.                             {
  1958.                                 /* Do nothing if received segments are not continuous */
  1959.                                 break;
  1960.                             }                
  1961.                             /* thissegment is the last segment of received segments */
  1962.                             if (thissegment == (mmi_frm_sms_index_list[l4_index].segment + 1 ))
  1963.                             {
  1964.                                 /* Append the content */
  1965.                                 if (pfnUnicodeStrlen((S8*) data->content))
  1966.                                 {
  1967.                                     /* append data->content to mmi_frm_sms_msg_box[addindex].content */
  1968.                                     U16 *temp_content;
  1969.                                     U16 temp_content_size = (U16) (mmi_msg_get_max_content_size() + 1) * ENCODING_LENGTH;
  1970.                                     temp_content = OslMalloc(temp_content_size);
  1971.                                     memset((S8*) temp_content, 0, temp_content_size);
  1972.                                     pfnUnicodeStrncpy(
  1973.                                         (S8*) temp_content,
  1974.                                         (S8*) mmi_frm_sms_msg_box[addindex].content,
  1975.                                         mmi_msg_get_max_content_size());
  1976.                                     pfnUnicodeStrncat(
  1977.                                         (S8*) temp_content,
  1978.                                         (S8*) data->content,
  1979.                                         (mmi_msg_get_max_content_size() - pfnUnicodeStrlen((S8*) temp_content)));
  1980.                                     mmi_frm_sms_add_content_to_entry(
  1981.                                         (mmi_frm_sms_msgbox_struct*) & mmi_frm_sms_msg_box[addindex],
  1982.                                         (U8*) temp_content);
  1983.                                     OslMfree(temp_content);
  1984.                                     
  1985.                                 }
  1986.                             }
  1987.                             break;
  1988.                         }   
  1989.                         if ((mmi_frm_sms_index_list[l4_index].segment - 1 ) != 
  1990.                             mmi_frm_sms_index_list[mmi_frm_sms_index_list[l4_index].previndex].segment)
  1991.                         {
  1992.                             /* Do nothing if received segments are not continuous */
  1993.                             break;
  1994.                         } 
  1995.                         l4_index = mmi_frm_sms_index_list[l4_index].nextindex;
  1996.                     }                
  1997.                 }
  1998.             }
  1999.         }
  2000.     #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  2001.         mmi_frm_sms_add_sms_segment(addindex, L4index, thissegment);
  2002.         /* If one segment of the message is unread, the message shall be unread. */
  2003.         if ((data->msgtype & MMI_FRM_SMS_UNREAD) == MMI_FRM_SMS_UNREAD)
  2004.         {
  2005.             mmi_frm_sms_msg_box[addindex].msgtype = ((mmi_frm_sms_msg_box[addindex].msgtype & 0xf0) | 
  2006.                                                      (MMI_FRM_SMS_UNREAD));
  2007.         }
  2008.     }
  2009.     return addindex;
  2010. }
  2011. /*****************************************************************************
  2012.  * FUNCTION
  2013.  *  mmi_frm_sms_remove_sms_entry
  2014.  * DESCRIPTION
  2015.  *  remove sms entry:
  2016.  * PARAMETERS
  2017.  *  index       [IN]        Index
  2018.  *  b  addindex    addindex(?)
  2019.  *  c  segment     segment(?)
  2020.  * RETURNS
  2021.  *  index(?)
  2022.  *****************************************************************************/
  2023. void mmi_frm_sms_remove_sms_entry(U16 index)
  2024. {
  2025.     /*----------------------------------------------------------------*/
  2026.     /* Local Variables                                                */
  2027.     /*----------------------------------------------------------------*/
  2028.     U16 previndex, nextindex;
  2029.     U8 type = mmi_frm_sms_index_list[index].prevtype;
  2030.     /*----------------------------------------------------------------*/
  2031.     /* Code Body                                                      */
  2032.     /*----------------------------------------------------------------*/
  2033.     previndex = mmi_frm_sms_index_list[index].previndex;
  2034.     nextindex = mmi_frm_sms_index_list[index].nextindex;
  2035.     /* chat message is not in message box, so message box should remain unchanged and only delete index list entry */
  2036.     /* For message with only one segment, also update msg box and inbox/outbox/draft list */
  2037.     if ((type != MMI_FRM_SMS_NOBOX && type != MMI_FRM_SMS_AWAITS && type != MMI_FRM_SMS_DATA) &&
  2038.         (nextindex == MMI_FRM_SMS_INVALID_INDEX))
  2039.     {
  2040.         mmi_frm_sms_remove_sms_from_list(previndex, type);
  2041.         memset((S8*) & mmi_frm_sms_msg_box[previndex], 0xff, sizeof(mmi_frm_sms_msgbox_struct));
  2042.     }
  2043.     else
  2044.     {
  2045.         /* the first segment of message */
  2046.         if (type != MMI_FRM_SMS_NOBOX)
  2047.         {
  2048.             /* for message in awaited list, ex. chat msg,  modify start index of awaitd list entry to next index */
  2049.             if (type == MMI_FRM_SMS_AWAITS || type == MMI_FRM_SMS_DATA)
  2050.             {
  2051.                 mmi_frm_sms_awaited[previndex].index = nextindex;
  2052.             }
  2053.             /* for message in msg box, ex. inbox/outbox/draft  message, modify start index of msg box entry to next index  */
  2054.             else
  2055.             {
  2056.                 mmi_frm_sms_msg_box[previndex].startindex = nextindex;
  2057.             }
  2058.         }
  2059.         /* the 2nd or after segment of message */
  2060.         else
  2061.         {
  2062.             mmi_frm_sms_index_list[previndex].nextindex = nextindex;
  2063.         }
  2064.         if (nextindex != MMI_FRM_SMS_INVALID_INDEX)
  2065.         {
  2066.             mmi_frm_sms_index_list[nextindex].prevtype = type;
  2067.             mmi_frm_sms_index_list[nextindex].previndex = previndex;
  2068.         }
  2069.     }
  2070.     memset((S8*) & mmi_frm_sms_index_list[index], 0xff, sizeof(mmi_frm_sms_index_struct));
  2071. }
  2072. /*****************************************************************************
  2073.  * FUNCTION
  2074.  *  mmi_frm_sms_add_sms_to_msgbox
  2075.  * DESCRIPTION
  2076.  *  add sms to msgbox
  2077.  * PARAMETERS
  2078.  *  entry       [?]         
  2079.  *  index       [IN]        
  2080.  *  thisseg     [IN]        
  2081.  *  a  data     data(?)
  2082.  * RETURNS
  2083.  *  void
  2084.  *****************************************************************************/
  2085. U16 mmi_frm_sms_add_sms_to_msgbox(mmi_frm_sms_msgbox_struct *entry, U16 index, U8 thisseg)
  2086. {
  2087.     /*----------------------------------------------------------------*/
  2088.     /* Local Variables                                                */
  2089.     /*----------------------------------------------------------------*/
  2090.     U16 entryindex;
  2091.     /*----------------------------------------------------------------*/
  2092.     /* Code Body                                                      */
  2093.     /*----------------------------------------------------------------*/
  2094.     /* add to msg entry */
  2095.     entryindex = mmi_frm_sms_add_sms_entry(entry, index, thisseg);
  2096.     /* update msg list */
  2097.     if (mmi_frm_sms_list_done)
  2098.     {
  2099.         mmi_frm_sms_add_sms_to_list(entry, entryindex);
  2100.     }
  2101.     return entryindex;
  2102. }
  2103. /*****************************************************************************
  2104.  * FUNCTION
  2105.  *  mmi_frm_sms_get_index
  2106.  * DESCRIPTION
  2107.  *  get sms index from bitmap
  2108.  * PARAMETERS
  2109.  *  index               [IN]        Index
  2110.  *  index_bitmap        [?]         Index_bitmap
  2111.  * RETURNS
  2112.  *  void
  2113.  *****************************************************************************/
  2114. U16 mmi_frm_sms_get_index(U16 index, U8 *index_bitmap)
  2115. {
  2116.     /*----------------------------------------------------------------*/
  2117.     /* Local Variables                                                */
  2118.     /*----------------------------------------------------------------*/
  2119.     U16 start_byte_idx, i;
  2120.     U8 start_bit_idx, j, mapping_byte;
  2121.     /*----------------------------------------------------------------*/
  2122.     /* Code Body                                                      */
  2123.     /*----------------------------------------------------------------*/
  2124.     start_byte_idx = (index >> 3);  /* divide 8 */
  2125.     start_bit_idx = (index & 0x7);  /* reminder */
  2126.     for (i = start_byte_idx; i < ((g_frm_sms_cntx.mmi_frm_sms_msg_box_size >> 3) + 1); i++)
  2127.     {
  2128.         mapping_byte = index_bitmap[i];
  2129.         for (j = start_bit_idx; j < 8; j++)
  2130.         {
  2131.             if (((mapping_byte >> j) & 0x01) == 0x01)
  2132.             {
  2133.                 return (i * 8 + j);
  2134.             }
  2135.         }
  2136.         start_bit_idx = 0;
  2137.     }
  2138.     return MMI_FRM_SMS_INVALID_INDEX;
  2139. }
  2140. /*****************************************************************************
  2141.  * FUNCTION
  2142.  *  mmi_frm_sms_set_bitmap
  2143.  * DESCRIPTION
  2144.  *  set bitmap from index
  2145.  * PARAMETERS
  2146.  *  index               [IN]        Index
  2147.  *  index_bitmap        [?]         Index_bitmap
  2148.  * RETURNS
  2149.  *  void
  2150.  *****************************************************************************/
  2151. void mmi_frm_sms_set_bitmap(U16 index, U8 *index_bitmap)
  2152. {
  2153.     /*----------------------------------------------------------------*/
  2154.     /* Local Variables                                                */
  2155.     /*----------------------------------------------------------------*/
  2156.     U16 byte_index;
  2157.     U8 bit_index;
  2158.     /*----------------------------------------------------------------*/
  2159.     /* Code Body                                                      */
  2160.     /*----------------------------------------------------------------*/
  2161.     byte_index = (index >> 3);  /* divide 8 */
  2162.     bit_index = (index & 0x7);  /* reminder */
  2163.     index_bitmap[byte_index] |= (0x01 << bit_index);
  2164. }
  2165. /*****************************************************************************
  2166.  * FUNCTION
  2167.  *  mmi_frm_sms_remove_sms_from_msgbox
  2168.  * DESCRIPTION
  2169.  *  mmi_frm_sms_remove_sms_from_msgbox
  2170.  * PARAMETERS
  2171.  *  data        [?]     Data
  2172.  * RETURNS
  2173.  *  void
  2174.  *****************************************************************************/
  2175. void mmi_frm_sms_remove_sms_from_msgbox(U8 *data)
  2176. {
  2177.     /*----------------------------------------------------------------*/
  2178.     /* Local Variables                                                */
  2179.     /*----------------------------------------------------------------*/
  2180.     U8 *index_bitmap = (U8*) data;
  2181.     U16 index = mmi_frm_sms_get_index(0, index_bitmap);
  2182.     /*----------------------------------------------------------------*/
  2183.     /* Code Body                                                      */
  2184.     /*----------------------------------------------------------------*/
  2185.     while (index != MMI_FRM_SMS_INVALID_INDEX)
  2186.     {
  2187.         mmi_frm_sms_remove_sms_entry(index);
  2188.         index++;
  2189.         index = mmi_frm_sms_get_index(index, index_bitmap);
  2190.     }
  2191.     return;
  2192. }
  2193. /*****************************************************************************
  2194.  * FUNCTION
  2195.  *  mmi_frm_sms_create_sms_list
  2196.  * DESCRIPTION
  2197.  *  mmi_frm_sms_create_sms_list
  2198.  * PARAMETERS
  2199.  *  void
  2200.  *  a  data     data(?)
  2201.  * RETURNS
  2202.  *  void
  2203.  *****************************************************************************/
  2204. void mmi_frm_sms_create_sms_list(void)
  2205. {
  2206.     /*----------------------------------------------------------------*/
  2207.     /* Local Variables                                                */
  2208.     /*----------------------------------------------------------------*/
  2209.     U16 i;
  2210.     /*----------------------------------------------------------------*/
  2211.     /* Code Body                                                      */
  2212.     /*----------------------------------------------------------------*/
  2213.     if (mmi_frm_sms_list_done != TRUE)
  2214.     {
  2215.         for (i = 0; i < g_frm_sms_cntx.mmi_frm_sms_msg_box_size; i++)
  2216.         {
  2217.             if (mmi_frm_sms_msg_box[i].startindex == MMI_FRM_SMS_INVALID_INDEX)
  2218.             {
  2219.                 continue;
  2220.             }
  2221.             mmi_frm_sms_add_sms_to_list(&mmi_frm_sms_msg_box[i], i);
  2222.         }
  2223.         mmi_frm_sms_list_done = TRUE;
  2224.     }
  2225. }
  2226. /*****************************************************************************
  2227.  * FUNCTION
  2228.  *  mmi_frm_sms_get_sms_list_index
  2229.  * DESCRIPTION
  2230.  *  map message box index to message list index
  2231.  * PARAMETERS
  2232.  *  type                [?]         Type
  2233.  *  index               [?]         Index
  2234.  *  msgbox_index        [IN]        Msgbox_index
  2235.  * RETURNS
  2236.  *  void
  2237.  *****************************************************************************/
  2238. void mmi_frm_sms_get_sms_list_index(U8 *type, U16 *index, U16 msgbox_index)
  2239. {
  2240.     /*----------------------------------------------------------------*/
  2241.     /* Local Variables                                                */
  2242.     /*----------------------------------------------------------------*/
  2243.     U16 i = 0;
  2244.     /*----------------------------------------------------------------*/
  2245.     /* Code Body                                                      */
  2246.     /*----------------------------------------------------------------*/
  2247.     while (i < mmi_frm_sms_inbox_size)
  2248.     {
  2249.         if (mmi_frm_sms_inbox_list[i] == msgbox_index)
  2250.         {
  2251.             *type = MMI_FRM_SMS_INBOX;
  2252.             *index = i;
  2253.             return;
  2254.         }
  2255.         i++;
  2256.     }
  2257.     i = 0;
  2258.     while (i < mmi_frm_sms_outbox_size)
  2259.     {
  2260.         if (mmi_frm_sms_outbox_list[i] == msgbox_index)
  2261.         {
  2262.             *type = MMI_FRM_SMS_OUTBOX;
  2263.             *index = i;
  2264.             return;
  2265.         }
  2266.         i++;
  2267.     }
  2268. #ifdef __MMI_MESSAGES_DRAFT_BOX__
  2269.     i = 0;
  2270.     while (i < mmi_frm_sms_drafts_size)
  2271.     {
  2272.         if (mmi_frm_sms_drafts_list[i] == msgbox_index)
  2273.         {
  2274.             *type = MMI_FRM_SMS_DRAFTS;
  2275.             *index = i;
  2276.             return;
  2277.         }
  2278.         i++;
  2279.     }
  2280. #endif /* __MMI_MESSAGES_DRAFT_BOX__ */ 
  2281. }
  2282. /*****************************************************************************
  2283.  * FUNCTION
  2284.  *  mmi_frm_sms_get_sms_index
  2285.  * DESCRIPTION
  2286.  *  get sms index array, in sequence
  2287.  * PARAMETERS
  2288.  *  type            [IN]        Type
  2289.  *  index           [IN]        Index
  2290.  *  l4_index        [?]         L4_index
  2291.  * RETURNS
  2292.  *  void
  2293.  *****************************************************************************/
  2294. void mmi_frm_sms_get_sms_index(mmi_frm_sms_msgbox_enum type, U16 index, U16 *l4_index)
  2295. {
  2296.     /*----------------------------------------------------------------*/
  2297.     /* Local Variables                                                */
  2298.     /*----------------------------------------------------------------*/
  2299.     U16 i = 0;
  2300.     U16 L4index = 0;
  2301.     /*----------------------------------------------------------------*/
  2302.     /* Code Body                                                      */
  2303.     /*----------------------------------------------------------------*/
  2304.     for (i = 0; i < g_frm_sms_cntx.mmi_frm_sms_msg_seg_size; i++)
  2305.     {
  2306.         l4_index[i] = MMI_FRM_SMS_INVALID_INDEX;
  2307.     }
  2308.     switch (type)
  2309.     {
  2310.         case MMI_FRM_SMS_NOBOX:
  2311.         {
  2312.             L4index = mmi_frm_sms_msg_box[index].startindex;
  2313.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2314.             {
  2315.                 l4_index[mmi_frm_sms_index_list[L4index].segment - 1] = L4index;
  2316.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2317.             }
  2318.         }
  2319.             break;
  2320.         case MMI_FRM_SMS_INBOX:
  2321.         case MMI_FRM_SMS_UNREAD:
  2322.         {
  2323.             L4index = mmi_frm_sms_msg_box[mmi_frm_sms_inbox_list[index]].startindex;
  2324.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2325.             {
  2326.                 l4_index[mmi_frm_sms_index_list[L4index].segment - 1] = L4index;
  2327.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2328.             }
  2329.         }
  2330.             break;
  2331.         case MMI_FRM_SMS_OUTBOX:
  2332.     #ifndef __MMI_MESSAGES_DRAFT_BOX__
  2333.         case MMI_FRM_SMS_DRAFTS:
  2334.     #endif 
  2335.         {
  2336.             L4index = mmi_frm_sms_msg_box[mmi_frm_sms_outbox_list[index]].startindex;
  2337.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2338.             {
  2339.                 l4_index[mmi_frm_sms_index_list[L4index].segment - 1] = L4index;
  2340.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2341.             }
  2342.         }
  2343.             break;
  2344.     #ifdef __MMI_MESSAGES_DRAFT_BOX__
  2345.         case MMI_FRM_SMS_DRAFTS:
  2346.         {
  2347.             L4index = mmi_frm_sms_msg_box[mmi_frm_sms_drafts_list[index]].startindex;
  2348.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2349.             {
  2350.                 l4_index[mmi_frm_sms_index_list[L4index].segment - 1] = L4index;
  2351.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2352.             }
  2353.         }
  2354.             break;
  2355.     #endif /* __MMI_MESSAGES_DRAFT_BOX__ */ 
  2356.     }
  2357. }
  2358. /*****************************************************************************
  2359.  * FUNCTION
  2360.  *  mmi_frm_sms_get_sms_msgbox_index
  2361.  * DESCRIPTION
  2362.  *  map L4 index to message box index
  2363.  * PARAMETERS
  2364.  *  l4_index            [IN]        L4 index
  2365.  *  msgbox_index        [?]         Msgbox_index
  2366.  * RETURNS
  2367.  *  void
  2368.  *****************************************************************************/
  2369. void mmi_frm_sms_get_sms_msgbox_index(U16 l4_index, U16 *msgbox_index)
  2370. {
  2371.     /*----------------------------------------------------------------*/
  2372.     /* Local Variables                                                */
  2373.     /*----------------------------------------------------------------*/
  2374.     U16 L4index = l4_index;
  2375.     /*----------------------------------------------------------------*/
  2376.     /* Code Body                                                      */
  2377.     /*----------------------------------------------------------------*/
  2378.     *msgbox_index = MMI_FRM_SMS_INVALID_INDEX;
  2379.     while (mmi_frm_sms_index_list[L4index].prevtype == MMI_FRM_SMS_NOBOX)
  2380.     {
  2381.         L4index = mmi_frm_sms_index_list[L4index].previndex;
  2382.     }
  2383.     if (mmi_frm_sms_index_list[L4index].prevtype != MMI_FRM_SMS_AWAITS &&
  2384.         mmi_frm_sms_index_list[L4index].prevtype != MMI_FRM_SMS_DATA)
  2385.     {
  2386.         *msgbox_index = mmi_frm_sms_index_list[L4index].previndex;
  2387.     }
  2388.     return;
  2389. }
  2390. /*****************************************************************************
  2391.  * FUNCTION
  2392.  *  mmi_frm_sms_get_sms_bitmap
  2393.  * DESCRIPTION
  2394.  *  get sms index in bitmap
  2395.  * PARAMETERS
  2396.  *  type            [IN]        Type
  2397.  *  index           [IN]        Index
  2398.  *  l4_index        [?]         L4_index
  2399.  * RETURNS
  2400.  *  void
  2401.  *****************************************************************************/
  2402. U8 mmi_frm_sms_get_sms_bitmap(U8 type, U16 index, U8 *l4_index)
  2403. {
  2404.     /*----------------------------------------------------------------*/
  2405.     /* Local Variables                                                */
  2406.     /*----------------------------------------------------------------*/
  2407.     U16 i = 0;
  2408.     U16 startindex = index;
  2409.     U16 endindex = index + 1;
  2410.     U16 entryindex = 0;
  2411.     U16 L4index = 0;
  2412.     /*----------------------------------------------------------------*/
  2413.     /* Code Body                                                      */
  2414.     /*----------------------------------------------------------------*/
  2415.     if (mmi_frm_sms_list_done == FALSE)
  2416.     {
  2417.         return FALSE;
  2418.     }
  2419.     if (type & MMI_FRM_SMS_NOBOX)
  2420.     {
  2421.         mmi_frm_sms_set_bitmap(index, l4_index);
  2422.     }
  2423.     if (type & MMI_FRM_SMS_AWAITS)
  2424.     {
  2425.         for (i = startindex; i < endindex; i++)
  2426.         {
  2427.             entryindex = index;
  2428.             L4index = entryindex;
  2429.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2430.             {
  2431.                 mmi_frm_sms_set_bitmap(L4index, l4_index);
  2432.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2433.             }
  2434.         }
  2435.     }
  2436.     if ((type & MMI_FRM_SMS_INBOX) || (type & MMI_FRM_SMS_UNREAD))
  2437.     {
  2438.         if (index == MMI_FRM_SMS_INVALID_INDEX)
  2439.         {
  2440.             startindex = 0;
  2441.             endindex = mmi_frm_sms_inbox_size;
  2442.         }
  2443.         for (i = startindex; i < endindex; i++)
  2444.         {
  2445.             entryindex = mmi_frm_sms_inbox_list[i];
  2446.             L4index = mmi_frm_sms_msg_box[entryindex].startindex;
  2447.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2448.             {
  2449.                 mmi_frm_sms_set_bitmap(L4index, l4_index);
  2450.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2451.             }
  2452.         }
  2453.     }
  2454.     if ((type & MMI_FRM_SMS_OUTBOX)
  2455. #ifndef __MMI_MESSAGES_DRAFT_BOX__
  2456.         || (type & MMI_FRM_SMS_DRAFTS)
  2457. #endif 
  2458.         )
  2459.     {
  2460.         if (index == MMI_FRM_SMS_INVALID_INDEX)
  2461.         {
  2462.             startindex = 0;
  2463.             endindex = mmi_frm_sms_outbox_size;
  2464.         }
  2465.         for (i = startindex; i < endindex; i++)
  2466.         {
  2467.             entryindex = mmi_frm_sms_outbox_list[i];
  2468.             L4index = mmi_frm_sms_msg_box[entryindex].startindex;
  2469.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2470.             {
  2471.                 mmi_frm_sms_set_bitmap(L4index, l4_index);
  2472.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2473.             }
  2474.         }
  2475.     }
  2476. #ifdef __MMI_MESSAGES_DRAFT_BOX__
  2477.     if ((type & MMI_FRM_SMS_DRAFTS)
  2478. #ifdef __MMI_UNIFIED_MESSAGE__
  2479.         || (type & MMI_FRM_SMS_UNSENT)
  2480. #endif 
  2481.         )
  2482.     {
  2483.         if (index == MMI_FRM_SMS_INVALID_INDEX)
  2484.         {
  2485.             startindex = 0;
  2486.             endindex = mmi_frm_sms_drafts_size;
  2487.         }
  2488.         for (i = startindex; i < endindex; i++)
  2489.         {
  2490.             entryindex = mmi_frm_sms_drafts_list[i];
  2491.             L4index = mmi_frm_sms_msg_box[entryindex].startindex;
  2492.             while (L4index != MMI_FRM_SMS_INVALID_INDEX)
  2493.             {
  2494.                 mmi_frm_sms_set_bitmap(L4index, l4_index);
  2495.                 L4index = mmi_frm_sms_index_list[L4index].nextindex;
  2496.             }
  2497.         }
  2498.     }
  2499. #endif /* __MMI_MESSAGES_DRAFT_BOX__ */ 
  2500.     return TRUE;
  2501. }
  2502. /*****************************************************************************
  2503.  * FUNCTION
  2504.  *  mmi_frm_sms_add_awaited_segment
  2505.  * DESCRIPTION
  2506.  *  add one segment to awaited entry
  2507.  * PARAMETERS
  2508.  *  index           [IN]        The index found in mmi_frm_sms_awaited that matches the last entry
  2509.  *  addindex        [IN]        Addindex
  2510.  *  segment         [IN]        The current segment of the last entry in mmi_frm_sms_awaited
  2511.  *  entry           [?]         
  2512.  * RETURNS
  2513.  *  add success or fail
  2514.  *****************************************************************************/
  2515. U8 mmi_frm_sms_add_awaited_segment(U8 index, U16 addindex, U8 segment, mmi_frm_sms_deliver_msg_struct *entry)
  2516. {
  2517.     /*----------------------------------------------------------------*/
  2518.     /* Local Variables                                                */
  2519.     /*----------------------------------------------------------------*/
  2520.     U16 thisindex = mmi_frm_sms_awaited[index].index;
  2521.     U8 islast = TRUE;
  2522.     U8 dataindex = 0;
  2523.     U8 thisdataindex = mmi_frm_sms_awaited[index].msg_data[0];
  2524.     U8 prevdataindex = MMI_FRM_SMS_INVALID_NUM;
  2525.     /*----------------------------------------------------------------*/
  2526.     /* Code Body                                                      */
  2527.     /*----------------------------------------------------------------*/
  2528.     /* find an empty entry in the mmi_frm_sms_content in order to move the last entry to that entry */
  2529.     while (dataindex < MMI_FRM_SMS_MSG_CONTENT_NUM)
  2530.     {
  2531.         if (mmi_frm_sms_content[dataindex].msglen == 0)
  2532.         {
  2533.             break;  /* found empty entry */
  2534.         }
  2535.         dataindex++;
  2536.     }
  2537.     /* if mmi_frm_sms_content is full and cannot find any empty entry, don't have to move */
  2538.     if (dataindex != MMI_FRM_SMS_MSG_CONTENT_NUM)
  2539.     {
  2540.         /* move the actual data of the last entry to the entry with the index dataindex in mmi_frm_sms_content */
  2541.         if (entry->no_msg_data)
  2542.         {
  2543.             mmi_frm_sms_content[dataindex].data = OslMalloc(entry->no_msg_data);
  2544.             memcpy(
  2545.                 (S8*) mmi_frm_sms_content[dataindex].data,
  2546.                 (S8*) mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data,
  2547.                 entry->no_msg_data);
  2548.         }
  2549.         mmi_frm_sms_content[dataindex].msglen = entry->no_msg_data;
  2550.         mmi_frm_sms_content[dataindex].segment = segment;
  2551.     }
  2552.     mmi_frm_sms_awaited[index].no_msg_data += entry->no_msg_data;
  2553.     MMI_ASSERT(mmi_frm_sms_awaited[index].no_msg_data <= MMI_SMS_MAX_MSG_SEG * MMI_FRM_SMS_MSG_LEN);
  2554.     if (addindex != MMI_FRM_SMS_INVALID_INDEX)
  2555.     {
  2556.         mmi_frm_sms_index_list[addindex].segment = segment;
  2557.     }
  2558.     /* thisdataindex is the current smallest segment index of this message */
  2559.     if (mmi_frm_sms_content[thisdataindex].segment > segment)
  2560.     {
  2561.         islast = FALSE;
  2562.         /* dataindex is inserted in the head, now dataindex is the current smallest segment index of this message */
  2563.         mmi_frm_sms_content[dataindex].nextindex = thisdataindex;
  2564.         mmi_frm_sms_awaited[index].msg_data[0] = dataindex;
  2565.         if (addindex != MMI_FRM_SMS_INVALID_INDEX)
  2566.         {
  2567.             mmi_frm_sms_awaited[index].index = addindex;
  2568.         }
  2569.     }
  2570.     else
  2571.     {
  2572.         while (mmi_frm_sms_content[thisdataindex].nextindex != MMI_FRM_SMS_INVALID_NUM)
  2573.         {
  2574.             if (addindex != MMI_FRM_SMS_INVALID_INDEX)
  2575.             {
  2576.                 thisindex = mmi_frm_sms_index_list[thisindex].nextindex;
  2577.             }
  2578.             prevdataindex = thisdataindex;
  2579.             thisdataindex = mmi_frm_sms_content[thisdataindex].nextindex;
  2580.             if (mmi_frm_sms_content[thisdataindex].segment > segment)
  2581.             {
  2582.                 islast = FALSE;
  2583.                 break;
  2584.             }
  2585.         }
  2586.     }
  2587.     if (islast == TRUE)
  2588.     {
  2589.         /* dataindex is inserted in the tail, now dataindex is the current largest segment index of this message */
  2590.         mmi_frm_sms_content[thisdataindex].nextindex = dataindex;
  2591.         mmi_frm_sms_content[dataindex].nextindex = MMI_FRM_SMS_INVALID_NUM;
  2592.         if (addindex != MMI_FRM_SMS_INVALID_INDEX)
  2593.         {
  2594.             mmi_frm_sms_index_list[thisindex].nextindex = addindex;
  2595.             mmi_frm_sms_index_list[addindex].nextindex = MMI_FRM_SMS_INVALID_INDEX;
  2596.             mmi_frm_sms_index_list[addindex].previndex = thisindex;
  2597.             mmi_frm_sms_index_list[addindex].prevtype = MMI_FRM_SMS_NOBOX;
  2598.         }
  2599.     }
  2600.     else
  2601.     {
  2602.         /* dataindex is inserted in the middle */
  2603.         if (prevdataindex != MMI_FRM_SMS_INVALID_NUM)
  2604.         {
  2605.             mmi_frm_sms_content[prevdataindex].nextindex = dataindex;
  2606.         }
  2607.         mmi_frm_sms_content[dataindex].nextindex = thisdataindex;
  2608.         if (addindex != MMI_FRM_SMS_INVALID_INDEX)
  2609.         {
  2610.             mmi_frm_sms_index_list[addindex].nextindex = thisindex;
  2611.             mmi_frm_sms_index_list[addindex].previndex = mmi_frm_sms_index_list[thisindex].previndex;
  2612.             mmi_frm_sms_index_list[addindex].prevtype = mmi_frm_sms_index_list[thisindex].prevtype;
  2613.             if (mmi_frm_sms_index_list[thisindex].prevtype == MMI_FRM_SMS_NOBOX)
  2614.             {
  2615.                 mmi_frm_sms_index_list[mmi_frm_sms_index_list[thisindex].previndex].nextindex = addindex;
  2616.             }
  2617.             mmi_frm_sms_index_list[thisindex].previndex = addindex;
  2618.             mmi_frm_sms_index_list[thisindex].prevtype = MMI_FRM_SMS_NOBOX;
  2619.         }
  2620.     }
  2621.     /* mmi_frm_sms_content is full and cannot handle other new segment coming anymore */
  2622.     if (dataindex == MMI_FRM_SMS_MSG_CONTENT_NUM)
  2623.     {
  2624.         return FALSE;
  2625.     }
  2626.     else
  2627.     {
  2628.         return TRUE;
  2629.     }
  2630. }
  2631. /*****************************************************************************
  2632.  * FUNCTION
  2633.  *  mmi_frm_sms_add_awaited_entry
  2634.  * DESCRIPTION
  2635.  *  add sms to awaited list
  2636.  * PARAMETERS
  2637.  *  void
  2638.  *  a  type        type(?)
  2639.  *  b  index       index(?)
  2640.  *  c  l4_index    l4_index(?)
  2641.  * RETURNS
  2642.  *  TRUE: inserted, FALSE: not inserted
  2643.  *****************************************************************************/
  2644. U8 mmi_frm_sms_add_awaited_entry(void)
  2645. {
  2646.     /*----------------------------------------------------------------*/
  2647.     /* Local Variables                                                */
  2648.     /*----------------------------------------------------------------*/
  2649.     U8 i = 0;
  2650.     U8 dataindex = 0;
  2651.     U16 index = mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE].index;
  2652.     U16 length = mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].msglen;
  2653.     /*----------------------------------------------------------------*/
  2654.     /* Code Body                                                      */
  2655.     /*----------------------------------------------------------------*/
  2656.     while (dataindex < MMI_FRM_SMS_MSG_CONTENT_NUM)
  2657.     {
  2658.         if (mmi_frm_sms_content[dataindex].segment == MMI_FRM_SMS_INVALID_NUM)
  2659.         {
  2660.             break;  /* found empty entry */
  2661.         }
  2662.         dataindex++;
  2663.     }
  2664.     /* cannot find any empty entry in mmi_frm_sms_content */
  2665.     if (dataindex == MMI_FRM_SMS_MSG_CONTENT_NUM)
  2666.     {
  2667.         return MMI_FRM_SMS_INVALID_NUM;
  2668.     }
  2669.     mmi_frm_sms_content[dataindex].msglen = mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].msglen;
  2670.     mmi_frm_sms_content[dataindex].nextindex = mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].nextindex;
  2671.     mmi_frm_sms_content[dataindex].segment = mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].segment;
  2672.     // mmi_frm_sms_content[dataindex].data=mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data;
  2673.     // mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data=NULL;
  2674.     if (length)
  2675.     {
  2676.         mmi_frm_sms_content[dataindex].data = OslMalloc(length);
  2677.         memcpy(mmi_frm_sms_content[dataindex].data, mmi_frm_sms_content[MMI_FRM_SMS_MSG_CONTENT_NUM].data, length);
  2678.     }
  2679.     while (i < MMI_FRM_SMS_ACTION_SIZE)
  2680.     {
  2681.         if (mmi_frm_sms_awaited[i].msg_data[0] == MMI_FRM_SMS_INVALID_NUM)
  2682.         {
  2683.             memcpy(
  2684.                 &(mmi_frm_sms_awaited[i]),
  2685.                 &(mmi_frm_sms_awaited[MMI_FRM_SMS_ACTION_SIZE]),
  2686.                 sizeof(mmi_frm_sms_deliver_msg_struct));
  2687.             mmi_frm_sms_awaited[i].msg_data[0] = dataindex;
  2688.             /* non-class 0 message!!!!!!! */
  2689.             if (index != MMI_FRM_SMS_INVALID_INDEX)
  2690.                 mmi_frm_sms_index_list[index].previndex = i;;
  2691.             return i;
  2692.         }
  2693.         i++;
  2694.     }
  2695.     /* cannot find any empty entry in mmi_frm_sms_awaited */
  2696.     return MMI_FRM_SMS_INVALID_NUM;
  2697. }
  2698. /*****************************************************************************
  2699.  * FUNCTION
  2700.  *  mmi_frm_sms_get_awaited_sms
  2701.  * DESCRIPTION
  2702.  *  Get awaited SMS by index
  2703.  * PARAMETERS
  2704.  *  index       [IN]        Index
  2705.  *  entry       [?]         Message entry info
  2706.  *  content     [?]         Message content
  2707.  * RETURNS
  2708.  *  object present
  2709.  *****************************************************************************/
  2710. U8 mmi_frm_sms_get_awaited_sms(U8 index, mmi_frm_sms_deliver_msg_struct *entry, U8 *content)
  2711. {
  2712.     /*----------------------------------------------------------------*/
  2713.     /* Local Variables                                                */
  2714.     /*----------------------------------------------------------------*/
  2715.     U8 i = 0;
  2716.     U8 nextindex = mmi_frm_sms_awaited[index].msg_data[0];
  2717.     EMSData *pEMSdata = NULL;
  2718.     U8 *textBuff;
  2719.     U8 *TPUD[10];
  2720.     U8 TPUDLEN[10];
  2721.     U8 is_obj_present = 0;
  2722.     U16 buffLen = mmi_frm_sms_awaited[index].no_msg_data;
  2723.     U16 textLen = 0;
  2724.     U8 totalseg = 0;
  2725.     EMSTATUS result;
  2726.     /*----------------------------------------------------------------*/
  2727.     /* Code Body                                                      */
  2728.     /*----------------------------------------------------------------*/
  2729.     memcpy((S8*) entry, (S8*) & mmi_frm_sms_awaited[index], sizeof(mmi_frm_sms_deliver_msg_struct));
  2730.     for (i = 0; i < 10; i++)
  2731.     {
  2732.         TPUDLEN[i] = 0;
  2733.         TPUD[i] = NULL;
  2734.     }
  2735.     i = 0;
  2736.     while (nextindex != MMI_FRM_SMS_INVALID_NUM && i < 10)
  2737.     {
  2738.         totalseg = i + 1;   /* total segment that the TPUD is not NULL */
  2739.         TPUDLEN[i] = (U8) mmi_frm_sms_content[nextindex].msglen;
  2740.         TPUD[i] = (U8*) mmi_frm_sms_content[nextindex].data;
  2741.         nextindex = mmi_frm_sms_content[nextindex].nextindex;
  2742.         i++;
  2743.     }
  2744.     if (mmi_frm_sms_awaited[index].dcs == SMSAL_DEFAULT_DCS || mmi_frm_sms_awaited[index].dcs == SMSAL_8BIT_DCS)
  2745.     {
  2746.         buffLen *= 2;
  2747.     }
  2748.     if (buffLen)
  2749.     {
  2750.         pEMSdata = OslMalloc(sizeof(EMSData));
  2751.         /* MMI could only allocate 2K control buffer, so limit the max allocate buffer to 1600 here */
  2752.         buffLen = (buffLen < (MMI_FRM_SMS_MSG_LEN * 10)) ? buffLen : (MMI_FRM_SMS_MSG_LEN * 10);
  2753.         textBuff = OslMalloc(buffLen);
  2754.         result = EMSMsgPreview(
  2755.                     totalseg,
  2756.                     mmi_frm_sms_awaited[index].dcs,
  2757.                     (U8) GetUDHIBit(mmi_frm_sms_awaited[index].fo),
  2758.                     TPUD,
  2759.                     TPUDLEN,
  2760.                     buffLen,
  2761.                     textBuff,
  2762.                     &is_obj_present,
  2763.                     &textLen);
  2764.         if (result == EMS_OK)
  2765.         {
  2766.             pEMSdata->textBuffer = textBuff;
  2767.             pEMSdata->textBufferSize = mmi_frm_sms_awaited[index].no_msg_data;
  2768.             pEMSdata->textLength = textLen;
  2769.             pEMSdata->dcs = mmi_frm_sms_awaited[index].dcs;
  2770.             EMS_ConvertGSM7BitDefaultEncodingToAsciiWithoutEMSlib(pEMSdata);
  2771.             entry->no_msg_data = pEMSdata->textLength;
  2772.             if (mmi_frm_sms_awaited[index].dcs == SMSAL_UCS2_DCS)
  2773.             {
  2774.                 memcpy((S8*) content, (S8*) pEMSdata->textBuffer, pEMSdata->textLength);
  2775.             }
  2776.             else
  2777.             {
  2778.                 S8 *pOutBuffer = (S8*) content;
  2779.                 S8 *pInBuffer = (S8*) pEMSdata->textBuffer;
  2780.                 U32 len = pEMSdata->textLength;
  2781.                 /* 34.2.5.1 test case contains a null terminator in the message content but actually it is not the end of the message */
  2782.                 /* UnicodeNToAnsii((S8*)content, (S8*)pEMSdata->textBuffer, pEMSdata->textLength); */
  2783.                 while (len)
  2784.                 {
  2785.                     *pOutBuffer = *(pInBuffer);
  2786.                     pInBuffer += 2;
  2787.                     pOutBuffer++;
  2788.                     len -= 2;
  2789.                 }
  2790.             }
  2791.         }
  2792.         else
  2793.         {
  2794.             entry->no_msg_data = 0;
  2795.             memset((S8*) content, 0, ENCODING_LENGTH);
  2796.         }
  2797.         OslMfree(textBuff);
  2798.         OslMfree(pEMSdata);
  2799.     }
  2800.     else
  2801.     {
  2802.         memset((S8*) content, 0, ENCODING_LENGTH);
  2803.     }
  2804.     return is_obj_present;
  2805. }
  2806. /*****************************************************************************
  2807.  * FUNCTION
  2808.  *  mmi_frm_sms_check_awaited_complete
  2809.  * DESCRIPTION
  2810.  *  Check awaited message completeness
  2811.  * PARAMETERS
  2812.  *  index       [IN]        Index
  2813.  * RETURNS
  2814.  *  void
  2815.  *****************************************************************************/
  2816. U8 mmi_frm_sms_check_awaited_complete(U8 index)
  2817. {
  2818.     /*----------------------------------------------------------------*/
  2819.     /* Local Variables                                                */
  2820.     /*----------------------------------------------------------------*/
  2821.     U8 i = 0;
  2822.     mmi_frm_sms_concat_struct *concat_info = (mmi_frm_sms_concat_struct*) & (mmi_frm_sms_awaited[index].concat_info);
  2823.     U8 total_seg = ((concat_info->total_seg - concat_info->seg + 1) > g_frm_sms_cntx.mmi_frm_sms_msg_seg_size) ?
  2824.         g_frm_sms_cntx.mmi_frm_sms_msg_seg_size : (concat_info->total_seg - concat_info->seg + 1);
  2825.     U8 dataindex = mmi_frm_sms_awaited[index].msg_data[0];
  2826.     /*----------------------------------------------------------------*/
  2827.     /* Code Body                                                      */
  2828.     /*----------------------------------------------------------------*/
  2829.     /* if the message has only one segment */
  2830.     if (index == MMI_FRM_SMS_ACTION_SIZE)
  2831.     {