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

MTK

开发平台:

C/C++

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