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

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *  VoIPUtil.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *  MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  Coding Template header file
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  *------------------------------------------------------------------------------
  136.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  137.  *============================================================================
  138.  ****************************************************************************/
  139. #ifndef __MTK_TARGET__
  140. #include <windows.h>
  141. #endif
  142. #include "MMI_features.h"
  143. #ifdef __MMI_VOIP__
  144. #include "stdC.h"
  145. #include "L4Dr1.h"
  146. #include "DebugInitDef.h"
  147. #include "mmi_trc.h"    /* debug info */
  148. #include "GlobalMenuItems.h"
  149. #include "GlobalScrEnum.h"
  150. #include "CustMenuRes.h"
  151. #include "CustDataRes.h"
  152. #include "ProtocolEvents.h"
  153. #include "CommonScreens.h"
  154. #include "SettingProfile.h"
  155. #include "EventsGprot.h"
  156. #include "wgui_categories_popup.h"
  157. #include "wgui_categories_inputs.h"
  158. #include "wgui_categories_util.h"
  159. #include "NVRAMEnum.h"
  160. #include "NVRAMProt.h"
  161. #include "NVRAMType.h"
  162. #include "custom_nvram_editor_data_item.h"
  163. #include "custom_data_account.h"
  164. #include "CallManagementGprot.h"
  165. #include "CallsGProts.h"
  166. #include "Conversions.h"
  167. #include "DateTimeGprot.h"
  168. #include "FileManagerGProt.h"
  169. #include "gpioInc.h"
  170. #include "mdi_datatype.h"
  171. #include "mdi_audio.h"
  172. #include "ProfilesDefs.h"
  173. #include "ProfileGprots.h"
  174. #include "PhoneBookGprot.h"
  175. #include "TimerEvents.h"
  176. #include "app2soc_struct.h"
  177. #include "soc_api.h"
  178. #include "med_struct.h"
  179. #include "rtp_api.h"
  180. #include "VoIPDef.h"
  181. #include "VoIPGProt.h"
  182. #include "VoIPProt.h"
  183. const U8 sipUri[10] = { 's', '', 'i', '', 'p', '', ':', '', '', '' }; /* sip: */
  184. const U8 telUri[10] = { 't', '', 'e', '', 'l', '', ':', '', '', '' }; /* tel: */
  185. const U8 sos112[8] = { '1', '', '1', '', '2', '', '', '' }; /* 112 */
  186. const U8 sos911[8] = { '9', '', '1', '', '1', '', '', '' }; /* 911 */
  187. const U8 zeroIp[8] = { '0', '', '0', '', '0', '', '', '' }; /* 000 */
  188. const U16 VoIPDTMFDigits[MMI_VOIP_MAX_NUM_DIGITS] = 
  189. {
  190.     KEY_1, KEY_2, KEY_3,
  191.     KEY_4, KEY_5, KEY_6,
  192.     KEY_7, KEY_8, KEY_9,
  193.     KEY_STAR, KEY_0, KEY_POUND
  194. };
  195. const mmi_voip_error_string_struct g_voip_error_table[] = 
  196. {
  197.     {VOIP_UNSPECIFIED_ERROR, STR_ID_VOIP_UNKNOWN_ERROR},
  198.     {VOIP_NOT_REGISTERED, STR_ID_VOIP_NOT_REGISTER},
  199.     {VOIP_ALREADY_REGISTERED, STR_ID_VOIP_ALREADY_REGISTER},
  200.     {VOIP_INVALID_PARAM, STR_ID_VOIP_INVALID_PARAMETER},
  201.     {VOIP_CREATE_UAC_ERROR, STR_ID_VOIP_SIP_ERROR},
  202.     {VOIP_GET_ADDR_FAILED, STR_ID_VOIP_INVALID_URI},
  203.     {VOIP_CALL_ABORT_LOCALLY, STR_ID_VOIP_CALL_END},
  204.     {VOIP_RECV_BYE, STR_ID_VOIP_CALL_END},
  205.     {VOIP_INCORRECT_CALL_STATE, STR_ID_VOIP_ACTION_INVALID},
  206.     {VOIP_BEARER_DISCONNECTED, STR_ID_VOIP_NETWORK_DOWN},
  207.     {VOIP_ABORT_FAILED, STR_ID_VOIP_CALL_END},
  208.     {VOIP_CALL_NOT_EXIST, STR_ID_VOIP_CALL_NOT_EXIST},
  209.     {VOIP_INVALID_URI, STR_ID_VOIP_INVALID_URI},
  210.     {VOIP_SWAP_FAILED, STR_ID_VOIP_SWAP_FAIL},
  211.     {VOIP_SWAP_PARTIAL_FAILED, STR_ID_VOIP_SWAP_FAIL},
  212.     {VOIP_TRANSFER_FAILED, STR_ID_VOIP_TRANSFER_FAIL},
  213.     {VOIP_MERGE_FAILED, STR_ID_VOIP_CONFERENCE_FAIL},
  214.     {VOIP_MERGE_PARTIAL_FAILED, STR_ID_VOIP_CONFERENCE_FAIL},
  215.     {VOIP_NAT_FAILED, STR_ID_VOIP_NAT_ERROR},
  216.     {VOIP_TEMPORARY_BUSY, STR_ID_VOIP_ACTION_CONFLICT},
  217.     {VOIP_UNSUPPORTED_NAT_TYPE, STR_ID_VOIP_NAT_ERROR},
  218.     {VOIP_NETWORK_ERROR, STR_ID_VOIP_NETWORK_ERROR},
  219.     {VOIP_BUSY, STR_ID_VOIP_ACTION_CONFLICT},
  220.     {VOIP_INVALID_CALL_REQ, STR_ID_VOIP_ACTION_INVALID},
  221.     {VOIP_PARTIAL_FAILED, STR_ID_VOIP_UNKNOWN_ERROR},
  222.     {VOIP_REREGISTER_FAILED, STR_ID_VOIP_REGISTER_FAIL},
  223.     {VOIP_SDP_MISMATCHED, STR_ID_VOIP_SDP_ERROR},
  224.     {VOIP_DNS_ERROR, STR_ID_VOIP_DNS_ERROR},
  225.     {VOIP_NO_RESOURCE, STR_ID_VOIP_UNKNOWN_ERROR},
  226.     {VOIP_SIP_FS_ERROR, STR_ID_VOIP_UNKNOWN_ERROR},
  227.     {VOIP_SIP_300_MULTIPLE_CHOICES, STR_ID_VOIP_NETWORK_ERROR},
  228.     {VOIP_SIP_301_MOVED_PERMANENTLY, STR_ID_VOIP_NETWORK_ERROR},
  229.     {VOIP_SIP_302_MOVED_TEMPORARILY, STR_ID_VOIP_NETWORK_ERROR},
  230.     {VOIP_SIP_305_USE_PROXY, STR_ID_VOIP_SIP_ERROR},
  231.     {VOIP_SIP_400_BAD_REQUEST, STR_ID_VOIP_ACTION_INVALID},
  232.     {VOIP_SIP_401_UNAUTHORIZED, STR_ID_VOIP_AUTHENTICATION_FAIL},
  233.     {VOIP_SIP_403_FORBIDDEN, STR_ID_VOIP_ACTION_FORBIDDEN},
  234.     {VOIP_SIP_404_NOT_FOUND, STR_ID_VOIP_USER_NOT_FOUND},
  235.     {VOIP_SIP_405_METHOD_NOT_ALLOW, STR_ID_VOIP_SIP_ERROR},
  236.     {VOIP_SIP_406_NOT_ACCEPTABLE, STR_ID_VOIP_USER_BUSY},
  237.     {VOIP_SIP_407_PROXY_AUTH_REQUIRED, STR_ID_VOIP_AUTHENTICATION_FAIL},
  238.     {VOIP_SIP_408_REQUEST_TIMEOUT, STR_ID_VOIP_REQUEST_TIMEOUT},
  239.     {VOIP_SIP_412_CONDITIONAL_REQ_FAIL, STR_ID_VOIP_SIP_ERROR},
  240.     {VOIP_SIP_422_INTERVAL_TOO_BRIEF, STR_ID_VOIP_SIP_ERROR},
  241.     {VOIP_SIP_423_INTERVAL_TOO_BRIEF, STR_ID_VOIP_SIP_ERROR},
  242.     {VOIP_SIP_478_UNRESOLVEABLE_DEST, STR_ID_VOIP_USER_NOT_FOUND},
  243.     {VOIP_SIP_480_TEMP_UNAVAILABLE, STR_ID_VOIP_USER_BUSY},
  244.     {VOIP_SIP_481_CALL_TRANS_NOT_EXIST, STR_ID_VOIP_CALL_NOT_EXIST},
  245.     {VOIP_SIP_486_BUSY_HERE, STR_ID_VOIP_USER_BUSY},
  246.     {VOIP_SIP_487_REQ_TERMINATED, STR_ID_VOIP_CALL_END},
  247.     {VOIP_SIP_488_NOT_ACCEPTABLE_HERE, STR_ID_VOIP_USER_BUSY},
  248.     {VOIP_SIP_491_REQUEST_PENDING, STR_ID_VOIP_USER_BUSY},
  249.     {VOIP_SIP_499_UNRESOLVEABLE_DEST, STR_ID_VOIP_USER_NOT_FOUND},
  250.     {VOIP_SIP_500_SERVER_INT_ERROR, STR_ID_VOIP_NETWORK_ERROR},
  251.     {VOIP_SIP_503_SERVICE_UNAVAILABLE, STR_ID_VOIP_NETWORK_ERROR},
  252.     {VOIP_SIP_600_BUSY_EVERYWHERE, STR_ID_VOIP_USER_BUSY},
  253.     {VOIP_SIP_603_DECLINE, STR_ID_VOIP_USER_BUSY},
  254.     {VOIP_SIP_606_NOT_ACCEPTABLE, STR_ID_VOIP_USER_BUSY},
  255.     {0, STR_ID_VOIP_UNKNOWN_ERROR}
  256. };
  257. /*****************************************************************************
  258.  * FUNCTION
  259.  *  mmi_voip_set_processing_parameter
  260.  * DESCRIPTION
  261.  *  Set processing screen parameter.
  262.  * PARAMETERS
  263.  *  titleStr            [IN]        Title string
  264.  *  bodyStr             [IN]        Body string
  265.  *  animationImg        [IN]        Animation image
  266.  *  lskStr              [IN]        LSK display string
  267.  *  lskFunc             [IN]        LSK function pointer
  268.  *  rskStr              [IN]        RSK display string
  269.  *  rskFunc             [IN]        RSK function pointer
  270.  *  sendFunc            [IN]        SEND key function pointer
  271.  *  endFunc             [IN]        END key function pointer
  272.  * RETURNS
  273.  *  void
  274.  *****************************************************************************/
  275. void mmi_voip_set_processing_parameter(
  276.         U16 titleStr,
  277.         U16 bodyStr,
  278.         U16 animationImg,
  279.         U16 lskStr,
  280.         FuncPtr lskFunc,
  281.         U16 rskStr,
  282.         FuncPtr rskFunc,
  283.         FuncPtr sendFunc,
  284.         FuncPtr endFunc)
  285. {
  286.     /*----------------------------------------------------------------*/
  287.     /* Local Variables                                                */
  288.     /*----------------------------------------------------------------*/
  289.     /*----------------------------------------------------------------*/
  290.     /* Code Body                                                      */
  291.     /*----------------------------------------------------------------*/
  292.     g_voip_cntx_p->proc_scr_info.title_string = titleStr;
  293.     g_voip_cntx_p->proc_scr_info.body_string = bodyStr;
  294.     g_voip_cntx_p->proc_scr_info.animation_image = animationImg;
  295.     g_voip_cntx_p->proc_scr_info.lsk_string = lskStr;
  296.     g_voip_cntx_p->proc_scr_info.lsk_funcPtr = lskFunc;
  297.     g_voip_cntx_p->proc_scr_info.rsk_string = rskStr;
  298.     g_voip_cntx_p->proc_scr_info.rsk_funcPtr = rskFunc;
  299.     g_voip_cntx_p->proc_scr_info.send_funcPtr = sendFunc;
  300.     g_voip_cntx_p->proc_scr_info.end_funcPtr = endFunc;
  301. }
  302. /*****************************************************************************
  303.  * FUNCTION
  304.  *  mmi_voip_entry_processing_screen
  305.  * DESCRIPTION
  306.  *  General entry function of processing screen.
  307.  * PARAMETERS
  308.  *  void
  309.  * RETURNS
  310.  *  void
  311.  *****************************************************************************/
  312. void mmi_voip_entry_processing_screen(void)
  313. {
  314.     /*----------------------------------------------------------------*/
  315.     /* Local Variables                                                */
  316.     /*----------------------------------------------------------------*/
  317.     U8 *guiBuffer = NULL;
  318.     /*----------------------------------------------------------------*/
  319.     /* Code Body                                                      */
  320.     /*----------------------------------------------------------------*/
  321.     EntryNewScreen(SCR_ID_VOIP_PROCESSING, NULL, mmi_voip_entry_processing_screen, NULL);
  322.     guiBuffer = GetCurrGuiBuffer(SCR_ID_VOIP_PROCESSING);
  323.     ShowCategory66Screen(
  324.         g_voip_cntx_p->proc_scr_info.title_string,
  325.         GetRootTitleIcon(MENU_ID_VOIP_MAIN),
  326.         g_voip_cntx_p->proc_scr_info.lsk_string,
  327.         IMG_GLOBAL_OK,
  328.         g_voip_cntx_p->proc_scr_info.rsk_string,
  329.         IMG_GLOBAL_BACK,
  330.         (U8*) GetString(g_voip_cntx_p->proc_scr_info.body_string),
  331.         g_voip_cntx_p->proc_scr_info.animation_image,
  332.         NULL);
  333.     SetLeftSoftkeyFunction(g_voip_cntx_p->proc_scr_info.lsk_funcPtr, KEY_EVENT_UP);
  334.     SetRightSoftkeyFunction(g_voip_cntx_p->proc_scr_info.rsk_funcPtr, KEY_EVENT_UP);
  335.     SetKeyHandler(g_voip_cntx_p->proc_scr_info.send_funcPtr, KEY_SEND, KEY_EVENT_DOWN);
  336.     SetKeyHandler(g_voip_cntx_p->proc_scr_info.end_funcPtr, KEY_END, KEY_EVENT_DOWN);
  337. }
  338. /*****************************************************************************
  339.  * FUNCTION
  340.  *  mmi_voip_validate_port
  341.  * DESCRIPTION
  342.  *  Validate port. 0~65535 is a valid range of port.
  343.  * PARAMETERS
  344.  *  unicodePort     [IN]        Port string in unicode
  345.  * RETURNS
  346.  *  TRUE means port number is valid; FALSE means port number is invalid.
  347.  *****************************************************************************/
  348. BOOL mmi_voip_validate_port(U8 *unicodePort)
  349. {
  350.     /*----------------------------------------------------------------*/
  351.     /* Local Variables                                                */
  352.     /*----------------------------------------------------------------*/
  353.     S32 portNumber = 0;
  354.     /*----------------------------------------------------------------*/
  355.     /* Code Body                                                      */
  356.     /*----------------------------------------------------------------*/
  357.     portNumber = gui_atoi((UI_string_type) unicodePort);
  358.     if ((portNumber >= 0) && (portNumber <= 65535))
  359.     {
  360.         return TRUE;
  361.     }
  362.     return FALSE;
  363. }
  364. /*****************************************************************************
  365.  * FUNCTION
  366.  *  mmi_voip_validate_uri
  367.  * DESCRIPTION
  368.  *  Validate uri. Only one @ can appear in the uri.
  369.  *  The @ cannot in the beginning of the uri,
  370.  *  and cannot in the end of the uri, either.
  371.  * PARAMETERS
  372.  *  unicodeUri      [IN]        Uri string in unicode
  373.  * RETURNS
  374.  *  TRUE means uri is valid; FALSE means uri is invalid.
  375.  *****************************************************************************/
  376. BOOL mmi_voip_validate_uri(U8 *unicodeUri)
  377. {
  378.     /*----------------------------------------------------------------*/
  379.     /* Local Variables                                                */
  380.     /*----------------------------------------------------------------*/
  381.     U8 *lowercaseUri = OslMalloc(VOIP_URI_LEN * ENCODING_LENGTH);
  382.     S32 sipLen = 0, telLen = 0, count = 0;
  383.     S8 foundAt = 0;
  384.     U8 charUnit;
  385.     /*----------------------------------------------------------------*/
  386.     /* Code Body                                                      */
  387.     /*----------------------------------------------------------------*/
  388.     memset(lowercaseUri, 0, (VOIP_URI_LEN * ENCODING_LENGTH));
  389.     mmi_voip_convert_uri_lower_case(unicodeUri, lowercaseUri);
  390.     sipLen = pfnUnicodeStrlen((S8*)sipUri);    /* number of characters */
  391.     telLen = pfnUnicodeStrlen((S8*)telUri);    /* number of characters */
  392.     if ((pfnUnicodeStrlen((S8*)lowercaseUri) == 0) ||
  393.         (!pfnUnicodeStrncmp((S8*)lowercaseUri, (S8*)sipUri, sipLen)) ||
  394.         (!pfnUnicodeStrncmp((S8*)lowercaseUri, (S8*)telUri, telLen)))
  395.     {
  396.         OslMfree(lowercaseUri);
  397.         return TRUE;
  398.     }
  399.     while (unicodeUri[count] != '' || unicodeUri[count + 1] != '')
  400.     {
  401.         if (unicodeUri[count] > 0x7e || unicodeUri[count + 1] > 0x7e)
  402.         {
  403.             OslMfree(lowercaseUri);
  404.             return FALSE;
  405.         }
  406.         charUnit = unicodeUri[count];
  407.         switch (charUnit)
  408.         {
  409.             case '@':
  410.             {
  411.                 foundAt++;
  412.                 if (count == 0) /* @xxxxx */
  413.                 {
  414.                     OslMfree(lowercaseUri);
  415.                     return FALSE;
  416.                 }
  417.                 else if (foundAt > 1)
  418.                 {
  419.                     OslMfree(lowercaseUri);
  420.                     return FALSE;
  421.                 }
  422.                 else if (unicodeUri[count + 2] == '' && unicodeUri[count + 3] == '')
  423.                 {
  424.                     OslMfree(lowercaseUri);
  425.                     return FALSE; /* xxxx@ */
  426.                 }
  427.                 else
  428.                 {
  429.                     break;
  430.                 }
  431.             }
  432.             case ',':
  433.             case ';':
  434.             case '<':
  435.             case '>':
  436.             case '[':
  437.             case ']':
  438.             case '"':
  439.             case ')':
  440.             case '(':
  441.                 OslMfree(lowercaseUri);
  442.                 return FALSE;
  443.             default:
  444.                 break;
  445.         }
  446.         count += 2;
  447.     }
  448.     if (foundAt == 1)
  449.     {
  450.         OslMfree(lowercaseUri);
  451.         return TRUE;
  452.     }
  453.     OslMfree(lowercaseUri);
  454.     return FALSE;
  455. }
  456. /*****************************************************************************
  457.  * FUNCTION
  458.  *  mmi_voip_validate_ip
  459.  * DESCRIPTION
  460.  *  Validate ip. 0.0.0.0 is not a valid ip.
  461.  * PARAMETERS
  462.  *  ip1     [IN]        First number in the ip format
  463.  *  ip2     [IN]        Second number in the ip format
  464.  *  ip3     [IN]        Third number in the ip format
  465.  *  ip4     [IN]        Fourth number in the ip format
  466.  * RETURNS
  467.  *  TRUE means ip address is valid; FALSE means ip address is invalid.
  468.  *****************************************************************************/
  469. BOOL mmi_voip_validate_ip(U8 *ip1, U8 *ip2, U8 *ip3, U8 *ip4)
  470. {
  471.     /*----------------------------------------------------------------*/
  472.     /* Local Variables                                                */
  473.     /*----------------------------------------------------------------*/
  474.     /*----------------------------------------------------------------*/
  475.     /* Code Body                                                      */
  476.     /*----------------------------------------------------------------*/
  477.     if ((gui_atoi((UI_string_type) ip1) != 0) ||
  478.         (gui_atoi((UI_string_type) ip2) != 0) ||
  479.         (gui_atoi((UI_string_type) ip3) != 0) || 
  480.         (gui_atoi((UI_string_type) ip4) != 0))
  481.     {
  482.         return TRUE;
  483.     }
  484.     return FALSE;
  485. }
  486. /*****************************************************************************
  487.  * FUNCTION
  488.  *  mmi_voip_validate_dtmf
  489.  * DESCRIPTION
  490.  *  Validate dtmf key. Valide dtmf key is defined in VoIPDTMFDigits array.
  491.  * PARAMETERS
  492.  *  dtmfKey     [IN]        
  493.  * RETURNS
  494.  *  TRUE means dtmf key is valid; FALSE means dtmf key is invalid.
  495.  *****************************************************************************/
  496. BOOL mmi_voip_validate_dtmf(U16 dtmfKey)
  497. {
  498.     /*----------------------------------------------------------------*/
  499.     /* Local Variables                                                */
  500.     /*----------------------------------------------------------------*/
  501.     S32 i = 0;
  502.     /*----------------------------------------------------------------*/
  503.     /* Code Body                                                      */
  504.     /*----------------------------------------------------------------*/
  505.     for (i = 0; i < MMI_VOIP_MAX_NUM_DIGITS; i++)
  506.     {
  507.         if (dtmfKey == VoIPDTMFDigits[i])
  508.         {
  509.             return TRUE;
  510.         }
  511.     }
  512.     return FALSE;
  513. }
  514. /*****************************************************************************
  515.  * FUNCTION
  516.  *  mmi_voip_parse_uri
  517.  * DESCRIPTION
  518.  *  Make sure the uri has sip: and domain name.
  519.  * PARAMETERS
  520.  *  unicodeUri      [IN]        Uri string in unicode
  521.  * RETURNS
  522.  *  void
  523.  *****************************************************************************/
  524. void mmi_voip_parse_uri(U8 *unicodeUri)
  525. {
  526.     /*----------------------------------------------------------------*/
  527.     /* Local Variables                                                */
  528.     /*----------------------------------------------------------------*/
  529.     U8 *lowercaseUri = OslMalloc(VOIP_URI_LEN * ENCODING_LENGTH);
  530.     S32 sipLen = 0, telLen = 0, count = 0;
  531.     S8 foundAt = 0;
  532.     /*----------------------------------------------------------------*/
  533.     /* Code Body                                                      */
  534.     /*----------------------------------------------------------------*/
  535.     memset(lowercaseUri, 0, (VOIP_URI_LEN * ENCODING_LENGTH));
  536.     mmi_voip_convert_uri_lower_case(unicodeUri, lowercaseUri);
  537.     sipLen = pfnUnicodeStrlen((S8*)sipUri);    /* number of characters */
  538.     telLen = pfnUnicodeStrlen((S8*)telUri);    /* number of characters */
  539.     if ((pfnUnicodeStrncmp((S8*)lowercaseUri, (S8*)sipUri, sipLen)) && (pfnUnicodeStrncmp((S8*)lowercaseUri, (S8*)telUri, telLen)))     /* no prefix sip: and tel: */
  540.     {
  541.         mmi_voip_append_uri_prefix(unicodeUri);
  542.     }
  543.     while (unicodeUri[count] != '' || unicodeUri[count + 1] != '')
  544.     {
  545.         if (unicodeUri[count] == '@')
  546.         {
  547.             foundAt = 1;
  548.             break;
  549.         }
  550.         count += 2;
  551.     }
  552.     if (foundAt == 0)
  553.     {
  554.         mmi_voip_append_uri_domain(unicodeUri);
  555.     }
  556.     OslMfree(lowercaseUri);
  557. }
  558. /*****************************************************************************
  559.  * FUNCTION
  560.  *  mmi_voip_convert_uri_lower_case
  561.  * DESCRIPTION
  562.  *  Convert uri string to lower case.
  563.  * PARAMETERS
  564.  *  unicodeSrc      [IN]            Source uri string in unicode
  565.  *  unicodeDest     [IN/OUT]        Destination uri string in unicode
  566.  * RETURNS
  567.  *  void
  568.  *****************************************************************************/
  569. void mmi_voip_convert_uri_lower_case(U8 *unicodeSrc, U8 *unicodeDest)
  570. {
  571.     /*----------------------------------------------------------------*/
  572.     /* Local Variables                                                */
  573.     /*----------------------------------------------------------------*/
  574.     S32 count = 0;
  575.     /*----------------------------------------------------------------*/
  576.     /* Code Body                                                      */
  577.     /*----------------------------------------------------------------*/
  578.     while (unicodeSrc[count] != '' || unicodeSrc[count + 1] != '')
  579.     {
  580.         if ((unicodeSrc[count] >= 'A') && (unicodeSrc[count] <= 'Z'))
  581.         {
  582.             unicodeDest[count] = unicodeSrc[count] + ('a' - 'A');
  583.         }
  584.         else
  585.         {
  586.             unicodeDest[count] = unicodeSrc[count];
  587.         }
  588.         count += 2;
  589.     }
  590. }
  591. /*****************************************************************************
  592.  * FUNCTION
  593.  *  mmi_voip_append_uri_prefix
  594.  * DESCRIPTION
  595.  *  Append sip: in front of the uri.
  596.  * PARAMETERS
  597.  *  unicodeUri      [IN]        Uri string in unicode
  598.  * RETURNS
  599.  *  void
  600.  *****************************************************************************/
  601. void mmi_voip_append_uri_prefix(U8 *unicodeUri)
  602. {
  603.     /*----------------------------------------------------------------*/
  604.     /* Local Variables                                                */
  605.     /*----------------------------------------------------------------*/
  606.     S32 sipLen = 0;
  607.     U8 *noprefixUri = OslMalloc(VOIP_URI_LEN * ENCODING_LENGTH);
  608.     /*----------------------------------------------------------------*/
  609.     /* Code Body                                                      */
  610.     /*----------------------------------------------------------------*/
  611.     memset(noprefixUri, 0, (VOIP_URI_LEN * ENCODING_LENGTH));
  612.     pfnUnicodeStrncpy((S8*)noprefixUri, (S8*)unicodeUri, VOIP_URI_LEN);
  613.     memset(unicodeUri, 0, (VOIP_URI_LEN * ENCODING_LENGTH));
  614.     sipLen = pfnUnicodeStrlen((S8*)sipUri);
  615.     pfnUnicodeStrncpy((S8*)unicodeUri, (S8*)sipUri, sipLen);
  616.     pfnUnicodeStrncpy((S8*)unicodeUri + sipLen * ENCODING_LENGTH, (S8*)noprefixUri, ((VOIP_URI_LEN - 1) - sipLen));
  617.     OslMfree(noprefixUri);
  618. }
  619. /*****************************************************************************
  620.  * FUNCTION
  621.  *  mmi_voip_append_uri_domain
  622.  * DESCRIPTION
  623.  *  Append domain name in back of the uri.
  624.  * PARAMETERS
  625.  *  unicodeUri      [IN]        Uri string in unicode
  626.  * RETURNS
  627.  *  void
  628.  *****************************************************************************/
  629. void mmi_voip_append_uri_domain(U8 *unicodeUri)
  630. {
  631.     /*----------------------------------------------------------------*/
  632.     /* Local Variables                                                */
  633.     /*----------------------------------------------------------------*/
  634.     U8 *unicodeProf = OslMalloc(VOIP_URI_LEN * ENCODING_LENGTH);
  635.     S32 profIndex = g_voip_cntx_p->prof_setting_info.actprofIndex;
  636.     S8 foundAt = 0;
  637.     S32 count = 0, uriLen = 0;
  638.     /*----------------------------------------------------------------*/
  639.     /* Code Body                                                      */
  640.     /*----------------------------------------------------------------*/
  641.     memset(unicodeProf, 0, (VOIP_URI_LEN * ENCODING_LENGTH));
  642.     AnsiiNToUnicodeString(
  643.         (S8*)unicodeProf,
  644.         (S8*)g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].acct_info.username,
  645.         VOIP_URI_LEN);
  646.     while (unicodeProf[count] != '' || unicodeProf[count + 1] != '')
  647.     {
  648.         if (unicodeProf[count] == '@')
  649.         {
  650.             foundAt = 1;
  651.             break;
  652.         }
  653.         count += 2;
  654.     }
  655.     if (foundAt == 1)
  656.     {
  657.         uriLen = pfnUnicodeStrlen((S8*)unicodeUri);
  658.         pfnUnicodeStrncpy(
  659.             (S8*)unicodeUri + uriLen * ENCODING_LENGTH,
  660.             (S8*)unicodeProf + count,
  661.             ((VOIP_URI_LEN - 1) - uriLen));
  662.     }
  663.     OslMfree(unicodeProf);
  664. }
  665. /*****************************************************************************
  666.  * FUNCTION
  667.  *  mmi_voip_add_to_call_list
  668.  * DESCRIPTION
  669.  *  Add specific call to call list.
  670.  * PARAMETERS
  671.  *  fileName            [IN]            Voip cc call list file, path included
  672.  *  callId              [IN]            Call id
  673.  *  dialogId            [IN]            Dialog id
  674.  *  currState           [IN]            Current state, either MMI_VOIP_OUTGOING_STATE or MMI_VOIP_INCOMING_STATE
  675.  * RETURNS
  676.  *  void
  677.  *****************************************************************************/
  678. void mmi_voip_add_to_call_list(U16 *fileName, S32 callId, S32 dialogId, mmi_voip_call_state_enum currState)
  679. {
  680.     /*----------------------------------------------------------------*/
  681.     /* Local Variables                                                */
  682.     /*----------------------------------------------------------------*/
  683.     FS_HANDLE fileHandle = 0;
  684.     U32 fileLen = 0;
  685.     S32 i = 0, result = 0;
  686.     voip_call_struct callList;
  687.     S32 freeTab = g_voip_cntx_p->call_misc_info.currfreeTab;
  688.     /*----------------------------------------------------------------*/
  689.     /* Code Body                                                      */
  690.     /*----------------------------------------------------------------*/
  691.     fileHandle = FS_Open(fileName, FS_READ_ONLY);
  692.     if (fileHandle < 0)
  693.     {
  694.         MMI_ASSERT(fileHandle >= 0);
  695.     }
  696.     for (i = 0; i <= callId; i++)
  697.     {
  698.         result = FS_Read(fileHandle, &callList, sizeof(voip_call_struct), &fileLen);
  699.         if (result != FS_NO_ERROR)
  700.         {
  701.             MMI_ASSERT(result == FS_NO_ERROR);
  702.         }
  703.     }
  704.     FS_Close(fileHandle);
  705.     if (freeTab != -1)
  706.     {
  707.         g_voip_cntx_p->call_list_info.call_info[freeTab].callId = callId;
  708.         g_voip_cntx_p->call_list_info.call_info[freeTab].currState = currState;
  709.         if (g_voip_cntx_p->call_list_info.call_info[freeTab].currState == MMI_VOIP_OUTGOING_STATE)
  710.         {
  711.             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].callOrigin = MMI_VOIP_MO_ORIGIN;
  712.         }
  713.         else if (g_voip_cntx_p->call_list_info.call_info[freeTab].currState == MMI_VOIP_INCOMING_STATE)
  714.         {
  715.             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].callOrigin = MMI_VOIP_MT_ORIGIN;
  716.         }
  717.         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].dialogId = dialogId;
  718.         memset(
  719.             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].appName,
  720.             0,
  721.             (VOIP_DISP_NAME_LEN * sizeof(U16)));
  722.         if (g_voip_cntx_p->call_list_info.call_info[freeTab].currState == MMI_VOIP_OUTGOING_STATE)
  723.         {
  724.             mmi_voip_get_outgoing_disp_name(
  725.                 MMI_VOIP_PHB|MMI_VOIP_HISTORY|MMI_VOIP_SOS, 
  726.                 g_voip_cntx_p->call_misc_info.dispUri, /* for display emergency number string */
  727.                 (U8*)g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].appName, 
  728.                 VOIP_DISP_NAME_LEN);
  729.         }
  730.         memset(
  731.             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].dispName,
  732.             0,
  733.             (VOIP_DISP_NAME_LEN * sizeof(U16)));
  734.         mmi_chset_convert(
  735.             MMI_CHSET_UTF8,
  736.             MMI_CHSET_UCS2,
  737.             (char*)callList.dialog[dialogId].user_addr.disp_name,
  738.             (char*)g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].dispName,
  739.             (S32)(VOIP_DISP_NAME_LEN * sizeof(U16)));
  740.         memset(g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].remoteUri, 0, VOIP_URI_LEN);
  741.         memcpy(
  742.             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].remoteUri,
  743.             callList.dialog[dialogId].user_addr.uri,
  744.             VOIP_URI_LEN);
  745.         /* copy sdp info */
  746.         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].rtpHandle = -1; /* rtp is not created yet */
  747.         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].isMixer = FALSE;
  748.         memcpy(
  749.             &g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].sdp_info,
  750.             &callList.dialog[dialogId].sdp_info,
  751.             sizeof(voip_sdp_struct));
  752.         g_voip_cntx_p->call_list_info.call_info[freeTab].numDialog++;
  753.         g_voip_cntx_p->call_list_info.numTotal++;
  754.         g_voip_cntx_p->call_misc_info.currfreeTab++;
  755.         if (g_voip_cntx_p->call_misc_info.currfreeTab == MMI_VOIP_MAX_NUM_CALL)
  756.         {
  757.             g_voip_cntx_p->call_misc_info.currfreeTab = -1; /* call capacity full */
  758.         }
  759.     }
  760.     else
  761.     {
  762.         MMI_ASSERT(0);  /* no available call entry */
  763.     }
  764. }
  765. /*****************************************************************************
  766.  * FUNCTION
  767.  *  mmi_voip_del_from_call_list
  768.  * DESCRIPTION
  769.  *  Delete specific call from call list.
  770.  * PARAMETERS
  771.  *  callId              [IN]            Call id
  772.  *  dialogId            [IN]            Dialog id
  773.  * RETURNS
  774.  *  void
  775.  *****************************************************************************/
  776. void mmi_voip_del_from_call_list(S32 callId, S32 dialogId)
  777. {
  778.     /*----------------------------------------------------------------*/
  779.     /* Local Variables                                                */
  780.     /*----------------------------------------------------------------*/
  781.     S32 callIndex = 0, dialogIndex = 0, i = 0, j = 0;
  782.     /*----------------------------------------------------------------*/
  783.     /* Code Body                                                      */
  784.     /*----------------------------------------------------------------*/
  785.     callIndex = mmi_voip_get_call_index(callId);
  786.     if (callIndex != -1)
  787.     {
  788.         dialogIndex = mmi_voip_get_dialog_index(callIndex, dialogId);
  789.         if (dialogIndex == 0)
  790.         {
  791.             g_voip_cntx_p->call_list_info.call_info[callIndex].numDialog--;
  792.             if (g_voip_cntx_p->call_list_info.call_info[callIndex].numDialog == 0)
  793.             {
  794.                 /* reset call info */
  795.                 mmi_voip_remove_mixer_before_close(callIndex);
  796.                 if (g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle != -1)
  797.                 {
  798.                     mmi_voip_close_rtp(g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle);
  799.                 }
  800.                 memset(&g_voip_cntx_p->call_list_info.call_info[callIndex], 0, sizeof(mmi_voip_call_struct));
  801.                 g_voip_cntx_p->call_list_info.call_info[callIndex].callId = -1;
  802.                 for (i = 0; i < VOIP_MAX_NUM_DIALOG; i++)
  803.                 {
  804.                     g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[i].dialogId = -1;
  805.                     g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[i].rtpHandle = -1;
  806.                 }
  807.                 g_voip_cntx_p->call_list_info.numTotal--;
  808.                 /* if currfreeTab is 0 already, it means the call was not connected but is disconnected now.
  809.                    therefore, no need to decrease currfreeTab */
  810.                 if (g_voip_cntx_p->call_misc_info.currfreeTab > 0)
  811.                 {
  812.                     g_voip_cntx_p->call_misc_info.currfreeTab--;
  813.                 }
  814.                 /* when reaching call capacity, currfreeTab is set to -1 already.
  815.                    therefore, currfreeTab has to set to 3 when call entry is available */
  816.                 else if (g_voip_cntx_p->call_misc_info.currfreeTab == -1)
  817.                 {
  818.                     g_voip_cntx_p->call_misc_info.currfreeTab = MMI_VOIP_MAX_NUM_CALL - 1;
  819.                 }
  820.             }
  821.             else    /* g_voip_cntx_p->call_list_info.call_info[callIndex].numDialog == 1 */
  822.             {
  823.                 /* move dialog 1 to dialog 0 */
  824.                 mmi_voip_remove_mixer_before_close(callIndex);
  825.                 if (g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle != -1)
  826.                 {
  827.                     mmi_voip_close_rtp(g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle);
  828.                 }
  829.                 memcpy(
  830.                     &g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[0],
  831.                     &g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[1],
  832.                     sizeof(mmi_voip_dialog_struct));
  833.                 memset(
  834.                     &g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[1],
  835.                     0,
  836.                     sizeof(mmi_voip_dialog_struct));
  837.                 g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[1].dialogId = -1;
  838.                 g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[1].rtpHandle = -1;
  839.             }
  840.         }
  841.         else if (dialogIndex == 1)
  842.         {
  843.             g_voip_cntx_p->call_list_info.call_info[callIndex].numDialog--;
  844.             if (g_voip_cntx_p->call_list_info.call_info[callIndex].numDialog == 0)
  845.             {
  846.                 /* reset call info */
  847.                 mmi_voip_remove_mixer_before_close(callIndex);
  848.                 if (g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle != -1)
  849.                 {
  850.                     mmi_voip_close_rtp(g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle);
  851.                 }
  852.                 memset(&g_voip_cntx_p->call_list_info.call_info[callIndex], 0, sizeof(mmi_voip_call_struct));
  853.                 g_voip_cntx_p->call_list_info.call_info[callIndex].callId = -1;
  854.                 for (i = 0; i < VOIP_MAX_NUM_DIALOG; i++)
  855.                 {
  856.                     g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[i].dialogId = -1;
  857.                     g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[i].rtpHandle = -1;
  858.                 }
  859.                 g_voip_cntx_p->call_list_info.numTotal--;
  860.                 /* if currfreeTab is 0 already, it means the call was not connected but is disconnected now.
  861.                    therefore, no need to decrease currfreeTab */
  862.                 if (g_voip_cntx_p->call_misc_info.currfreeTab > 0)
  863.                 {
  864.                     g_voip_cntx_p->call_misc_info.currfreeTab--;
  865.                 }
  866.                 /* when reaching call capacity, currfreeTab is set to -1 already.
  867.                    therefore, currfreeTab has to set to 3 when call entry is available */
  868.                 else if (g_voip_cntx_p->call_misc_info.currfreeTab == -1)
  869.                 {
  870.                     g_voip_cntx_p->call_misc_info.currfreeTab = MMI_VOIP_MAX_NUM_CALL - 1;
  871.                 }
  872.             }
  873.             else    /* numDialog == 1 */
  874.             {
  875.                 /* reset dialog info */
  876.                 mmi_voip_remove_mixer_before_close(callIndex);
  877.                 if (g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle != -1)
  878.                 {
  879.                     mmi_voip_close_rtp(g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle);
  880.                 }
  881.                 memset(
  882.                     &g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex],
  883.                     0,
  884.                     sizeof(mmi_voip_dialog_struct));
  885.                 g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].dialogId = -1;
  886.                 g_voip_cntx_p->call_list_info.call_info[callIndex].dialog_info[dialogIndex].rtpHandle = -1;
  887.             }
  888.         }
  889.         /* rearrange call list */
  890.         if (g_voip_cntx_p->call_list_info.call_info[callIndex].numDialog == 0)
  891.         {
  892.             for (i = callIndex; i < (MMI_VOIP_MAX_NUM_CALL - 1); i++)
  893.             {
  894.                 memcpy(
  895.                     &g_voip_cntx_p->call_list_info.call_info[i],
  896.                     &g_voip_cntx_p->call_list_info.call_info[i + 1],
  897.                     sizeof(mmi_voip_call_struct));
  898.                 memset(&g_voip_cntx_p->call_list_info.call_info[i + 1], 0, sizeof(mmi_voip_call_struct));
  899.                 g_voip_cntx_p->call_list_info.call_info[i + 1].callId = -1;
  900.                 for (j = 0; j < VOIP_MAX_NUM_DIALOG; j++)
  901.                 {
  902.                     g_voip_cntx_p->call_list_info.call_info[i + 1].dialog_info[j].dialogId = -1;
  903.                     g_voip_cntx_p->call_list_info.call_info[i + 1].dialog_info[j].rtpHandle = -1;
  904.                 }
  905.             }
  906.         }
  907.     }
  908. }
  909. /*****************************************************************************
  910.  * FUNCTION
  911.  *  mmi_voip_update_call_list
  912.  * DESCRIPTION
  913.  *  Update mmi call list.
  914.  * PARAMETERS
  915.  *  fileName            [IN]            Voip cc call list file, path included
  916.  *  isConf              [IN]            Display popup or not
  917.  * RETURNS
  918.  *  void
  919.  *****************************************************************************/
  920. void mmi_voip_update_call_list(U16 *fileName, BOOL isConf)
  921. {
  922.     /*----------------------------------------------------------------*/
  923.     /* Local Variables                                                */
  924.     /*----------------------------------------------------------------*/
  925.     
  926.     /*----------------------------------------------------------------*/
  927.     /* Code Body                                                      */
  928.     /*----------------------------------------------------------------*/
  929.     g_voip_cntx_p->call_list_info.numHeld = 0;  /* re-calculate number of held call */
  930.     mmi_voip_update_to_del_call_list(fileName, isConf);
  931.     mmi_voip_update_to_add_call_list(fileName, isConf);
  932.     mmi_voip_switch_session(MMI_VOIP_IDLE_STATE);
  933.     FS_Delete(fileName);
  934. }
  935. /*****************************************************************************
  936.  * FUNCTION
  937.  *  mmi_voip_update_to_del_call_list
  938.  * DESCRIPTION
  939.  *  First pass of updating call list from voip cc to mmi.
  940.  *  Delete mmi call list entry that voip cc call list does not have.
  941.  * PARAMETERS
  942.  *  fileName            [IN]            Voip cc call list file, path included
  943.  *  isConf              [IN]            Display popup or not
  944.  * RETURNS
  945.  *  void
  946.  *****************************************************************************/
  947. void mmi_voip_update_to_del_call_list(U16 *fileName, BOOL isConf)
  948. {
  949.     /*----------------------------------------------------------------*/
  950.     /* Local Variables                                                */
  951.     /*----------------------------------------------------------------*/
  952.     FS_HANDLE fileHandle = 0;
  953.     U32 fileLen = 0;
  954.     S32 result = 0;
  955.     voip_call_struct callList;
  956.     S32 i = 0, j = 0, m = 0, n = 0, callId = 0, dialogId = 0;
  957.     MYTIME currTime, duration;
  958.     U8 popupStr[MAX_SUB_MENU_SIZE];
  959.     /*----------------------------------------------------------------*/
  960.     /* Code Body                                                      */
  961.     /*----------------------------------------------------------------*/
  962.     while (i < MMI_VOIP_MAX_NUM_CALL)
  963.     {
  964.         callId = g_voip_cntx_p->call_list_info.call_info[i].callId;
  965.         if (callId != -1)
  966.         {
  967.             fileHandle = FS_Open(fileName, FS_READ_ONLY);
  968.             if (fileHandle < 0)
  969.             {
  970.                 MMI_ASSERT(fileHandle >= 0);
  971.             }
  972.             for (j = 0; j < g_voip_cntx_p->call_list_info.maxnumCall; j++)
  973.             {
  974.                 result = FS_Read(fileHandle, &callList, sizeof(voip_call_struct), &fileLen);
  975.                 if (result != FS_NO_ERROR)
  976.                 {
  977.                     MMI_ASSERT(result == FS_NO_ERROR);
  978.                 }
  979.                 if ((callList.is_bk_call == FALSE) && (callList.call_state != VOIP_CALL_STATE_TERMINATED) &&
  980.                     (callList.call_id == callId))
  981.                 {
  982.                     while (m < VOIP_MAX_NUM_DIALOG)
  983.                     {
  984.                         dialogId = g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dialogId;
  985.                         if (dialogId != -1)
  986.                         {
  987.                             for (n = 0; n < VOIP_MAX_NUM_DIALOG; n++)
  988.                             {
  989.                                 if ((callList.dialog[n].in_use == TRUE) && (callList.dialog[n].dialog_id == dialogId))
  990.                                 {
  991.                                     /* update call info */
  992.                                     g_voip_cntx_p->call_list_info.call_info[i].currState = mmi_voip_get_call_state_enum(callList.dialog[n].dialog_state);
  993.                                     if ((g_voip_cntx_p->call_list_info.call_info[i].currState == MMI_VOIP_HOLD_STATE) && (m == 0))      /* only update held call count according to the first dialog */
  994.                                     {
  995.                                         g_voip_cntx_p->call_list_info.numHeld++;
  996.                                     }
  997.                                     else if (g_voip_cntx_p->call_list_info.call_info[i].currState ==
  998.                                              MMI_VOIP_OUTGOING_STATE)
  999.                                     {
  1000.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].callOrigin =
  1001.                                             MMI_VOIP_MO_ORIGIN;
  1002.                                     }
  1003.                                     else if (g_voip_cntx_p->call_list_info.call_info[i].currState ==
  1004.                                              MMI_VOIP_INCOMING_STATE)
  1005.                                     {
  1006.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].callOrigin =
  1007.                                             MMI_VOIP_MT_ORIGIN;
  1008.                                     }
  1009.                                     /* outgoing call or incoming call doesn't have the info of sdp yet */
  1010.                                     if ((g_voip_cntx_p->call_list_info.call_info[i].currState == MMI_VOIP_ACTIVE_STATE) || 
  1011.                                         (g_voip_cntx_p->call_list_info.call_info[i].currState == MMI_VOIP_HOLD_STATE))
  1012.                                     {
  1013.                                         if (g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].rtpHandle == -1)
  1014.                                         {
  1015.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].rtpHandle = mmi_voip_create_rtp(&callList.dialog[n].sdp_info);
  1016.                                         }
  1017.                                         else if (mmi_voip_is_addr_change
  1018.                                                  (&g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].sdp_info,
  1019.                                                   &callList.dialog[n].sdp_info))
  1020.                                         {
  1021.                                             mmi_voip_remove_mixer_before_close(i);
  1022.                                             mmi_voip_close_rtp(g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].rtpHandle);
  1023.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].rtpHandle = mmi_voip_create_rtp(&callList.dialog[n].sdp_info);
  1024.                                         }
  1025.                                         memcpy(
  1026.                                             &g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].sdp_info,
  1027.                                             &callList.dialog[n].sdp_info,
  1028.                                             sizeof(voip_sdp_struct));
  1029.                                         mmi_voip_switch_rtp(FALSE, callId, dialogId);
  1030.                                         if (!mmi_dt_is_valid(&g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].startTime))
  1031.                                         {
  1032.                                             DTGetRTCTime(&currTime);
  1033.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].startTime = currTime;
  1034.                                         }
  1035.                                     }
  1036.                                     memset(
  1037.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dispName,
  1038.                                         0,
  1039.                                         (VOIP_DISP_NAME_LEN * sizeof(U16)));
  1040.                                     mmi_chset_convert(
  1041.                                         MMI_CHSET_UTF8,
  1042.                                         MMI_CHSET_UCS2,
  1043.                                         (char*)callList.dialog[n].user_addr.disp_name,
  1044.                                         (char*)g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dispName,
  1045.                                         (S32)(VOIP_DISP_NAME_LEN * sizeof(U16)));
  1046.                                     /* it could be a transfer case if uri changes, need to update appName */
  1047.                                     if (strncmp(
  1048.                                         (S8*)g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].remoteUri, 
  1049.                                         (S8*)callList.dialog[n].user_addr.uri, 
  1050.                                         VOIP_URI_LEN))
  1051.                                     {
  1052.                                         memset(
  1053.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].appName, 
  1054.                                             0, 
  1055.                                             (VOIP_DISP_NAME_LEN * sizeof(U16)));
  1056.                                     }
  1057.                                     memset(
  1058.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].remoteUri,
  1059.                                         0,
  1060.                                         VOIP_URI_LEN);
  1061.                                     memcpy(
  1062.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].remoteUri,
  1063.                                         callList.dialog[n].user_addr.uri,
  1064.                                         VOIP_URI_LEN);
  1065.                                     break;
  1066.                                 }
  1067.                             }
  1068.                             m++;
  1069.                             if (n == VOIP_MAX_NUM_DIALOG)   /* delete dialog entry */
  1070.                             {
  1071.                                 if (mmi_dt_is_valid(&g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m - 1].startTime))
  1072.                                 {
  1073.                                     memset(&duration, 0, sizeof(MYTIME));
  1074.                                     mmi_voip_log_call_end_time(callId, dialogId, &duration);
  1075.                                     memset(popupStr, 0, MAX_SUB_MENU_SIZE);
  1076.                                     mmi_voip_get_call_end_string(&duration, popupStr);
  1077.                                 }
  1078.                                 else
  1079.                                 {
  1080.                                     memset(popupStr, 0, MAX_SUB_MENU_SIZE);
  1081.                                     pfnUnicodeStrcpy((S8*)popupStr, GetString(STR_ID_VOIP_CALL_END));
  1082.                                     MMI_ASSERT(popupStr[MAX_SUB_MENU_SIZE - 2] == '' && popupStr[MAX_SUB_MENU_SIZE - 1] == '');
  1083.                                 }
  1084.                                 if (isConf == TRUE)
  1085.                                 {
  1086.                                     /* store actual call origin and actual start time for merge call or split call */
  1087.                                     g_voip_cntx_p->call_misc_info.actualOrigin =
  1088.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m - 1].callOrigin;
  1089.                                     g_voip_cntx_p->call_misc_info.actualTime =
  1090.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m - 1].startTime;
  1091.                                 }
  1092.                                 else    /* isConf == FALSE */
  1093.                                 {
  1094.                                     /* do not log background reject call to call history and popup call end */
  1095.                                     if ((g_voip_cntx_p->call_list_info.bkrejCId != callId) &&
  1096.                                         (g_voip_cntx_p->call_list_info.bkrejDId != dialogId))
  1097.                                     {
  1098.                                         /* outgoing call or incoming call doesn't have call duration */
  1099.                                         if (!mmi_dt_is_valid(&g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m - 1].startTime))
  1100.                                         {
  1101.                                             mmi_voip_log_call_history(
  1102.                                                 callId,
  1103.                                                 dialogId,
  1104.                                                 g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m - 1].callOrigin,
  1105.                                                 FALSE);
  1106.                                         }
  1107.                                         else
  1108.                                         {
  1109.                                             mmi_voip_log_call_duration(
  1110.                                                 callId,
  1111.                                                 dialogId,
  1112.                                                 g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m - 1].callOrigin);
  1113.                                         }
  1114.                                         mmi_voip_entry_popup(popupStr, IMG_ID_VOIP_CALL_ENDED);
  1115.                                     #if 0
  1116. /* under construction !*/
  1117. /* under construction !*/
  1118. /* under construction !*/
  1119. /* under construction !*/
  1120. /* under construction !*/
  1121. /* under construction !*/
  1122.                                     #endif
  1123.                                     }
  1124.                                     else
  1125.                                     {
  1126.                                         PRINT_INFORMATION(("n[mmi_voip_update_to_del_call_list] It is possiblen"));
  1127.                                     }
  1128.                                 }
  1129.                                 mmi_voip_del_from_call_list(callId, dialogId);
  1130.                                 m--;
  1131.                             }
  1132.                         }
  1133.                         else    /* dialogId == -1, break the loop because mmi call list is sorted */
  1134.                         {
  1135.                             break;
  1136.                         }
  1137.                     }
  1138.                     m = 0;  /* reset m to check next call id's dialog */
  1139.                     break;
  1140.                 }
  1141.             }
  1142.             i++;
  1143.             if (j == g_voip_cntx_p->call_list_info.maxnumCall)  /* delete call entry */
  1144.             {
  1145.                 /* dialogId is invalid at the moment, so get the first dialog id to show call end popup */
  1146.                 dialogId = g_voip_cntx_p->call_list_info.call_info[i - 1].dialog_info[m].dialogId;
  1147.                 if (mmi_dt_is_valid(&g_voip_cntx_p->call_list_info.call_info[i - 1].dialog_info[m].startTime))
  1148.                 {
  1149.                     memset(&duration, 0, sizeof(MYTIME));
  1150.                     mmi_voip_log_call_end_time(callId, dialogId, &duration);
  1151.                     memset(popupStr, 0, MAX_SUB_MENU_SIZE);
  1152.                     mmi_voip_get_call_end_string(&duration, popupStr);
  1153.                 }
  1154.                 else    /* outgoing call or incoming call */
  1155.                 {
  1156.                     memset(popupStr, 0, MAX_SUB_MENU_SIZE);
  1157.                     pfnUnicodeStrcpy((S8*)popupStr, GetString(STR_ID_VOIP_CALL_END));
  1158.                     MMI_ASSERT(popupStr[MAX_SUB_MENU_SIZE - 2] == '' && popupStr[MAX_SUB_MENU_SIZE - 1] == '');
  1159.                 }
  1160.                 if (isConf == TRUE)
  1161.                 {
  1162.                     /* store actual call origin and actual start time for merge call or split call */
  1163.                     g_voip_cntx_p->call_misc_info.actualOrigin =
  1164.                         g_voip_cntx_p->call_list_info.call_info[i - 1].dialog_info[m].callOrigin;
  1165.                     g_voip_cntx_p->call_misc_info.actualTime =
  1166.                         g_voip_cntx_p->call_list_info.call_info[i - 1].dialog_info[m].startTime;
  1167.                 }
  1168.                 else    /* isConf == FALSE */
  1169.                 {
  1170.                     /* do not log background reject call to call history and popup call end */
  1171.                     if ((g_voip_cntx_p->call_list_info.bkrejCId != callId) &&
  1172.                         (g_voip_cntx_p->call_list_info.bkrejDId != dialogId))
  1173.                     {
  1174.                         /* outgoing call or incoming call doesn't have call duration */
  1175.                         if (!mmi_dt_is_valid(&g_voip_cntx_p->call_list_info.call_info[i - 1].dialog_info[m].startTime))
  1176.                         {
  1177.                             mmi_voip_log_call_history(
  1178.                                 callId,
  1179.                                 dialogId,
  1180.                                 g_voip_cntx_p->call_list_info.call_info[i - 1].dialog_info[m].callOrigin,
  1181.                                 FALSE);
  1182.                         }
  1183.                         else
  1184.                         {
  1185.                             mmi_voip_log_call_duration(
  1186.                                 callId,
  1187.                                 dialogId,
  1188.                                 g_voip_cntx_p->call_list_info.call_info[i - 1].dialog_info[m].callOrigin);
  1189.                         }
  1190.                         mmi_voip_entry_popup(popupStr, IMG_ID_VOIP_CALL_ENDED);
  1191.                     #if 0
  1192. /* under construction !*/
  1193. /* under construction !*/
  1194. /* under construction !*/
  1195. /* under construction !*/
  1196. /* under construction !*/
  1197. /* under construction !*/
  1198.                     #endif
  1199.                     }
  1200.                     else
  1201.                     {
  1202.                         PRINT_INFORMATION(("n[mmi_voip_update_to_del_call_list] It is possiblen"));
  1203.                     }
  1204.                 }
  1205.                 mmi_voip_del_from_call_list(callId, dialogId);
  1206.                 i--;
  1207.             }
  1208.             FS_Close(fileHandle);
  1209.         }
  1210.         else    /* callId == -1, break the loop because mmi call list is sorted */
  1211.         {
  1212.             break;
  1213.         }
  1214.     }
  1215.     i = 0;  /* reset i */
  1216. }
  1217. /*****************************************************************************
  1218.  * FUNCTION
  1219.  *  mmi_voip_update_to_add_call_list
  1220.  * DESCRIPTION
  1221.  *  Second pass of updating call list from voip cc to mmi.
  1222.  *  Add mmi call list entry that mmi call list does not have.
  1223.  * PARAMETERS
  1224.  *  fileName            [IN]            Voip cc call list file, path included
  1225.  *  isConf              [IN]            Display popup or not
  1226.  * RETURNS
  1227.  *  void
  1228.  *****************************************************************************/
  1229. void mmi_voip_update_to_add_call_list(U16 *fileName, BOOL isConf)
  1230. {
  1231.     /*----------------------------------------------------------------*/
  1232.     /* Local Variables                                                */
  1233.     /*----------------------------------------------------------------*/
  1234.     FS_HANDLE fileHandle = 0;
  1235.     U32 fileLen = 0;
  1236.     S32 result = 0;
  1237.     voip_call_struct callList;
  1238.     S32 i = 0, j = 0, m = 0, n = 0, callId = 0, dialogId = 0, freeTab = 0;
  1239.     MYTIME currTime;
  1240.     /*----------------------------------------------------------------*/
  1241.     /* Code Body                                                      */
  1242.     /*----------------------------------------------------------------*/
  1243.     fileHandle = FS_Open(fileName, FS_READ_ONLY);
  1244.     if (fileHandle < 0)
  1245.     {
  1246.         MMI_ASSERT(fileHandle >= 0);
  1247.     }
  1248.     for (j = 0; j < g_voip_cntx_p->call_list_info.maxnumCall; j++)
  1249.     {
  1250.         result = FS_Read(fileHandle, &callList, sizeof(voip_call_struct), &fileLen);
  1251.         if (result != FS_NO_ERROR)
  1252.         {
  1253.             MMI_ASSERT(result == FS_NO_ERROR);
  1254.         }
  1255.         if ((callList.is_bk_call == FALSE) && 
  1256.             ((callList.call_state == VOIP_CALL_STATE_CONFIRMED) ||  
  1257.             (callList.call_state == VOIP_CALL_STATE_ACCEPTING))) /* accept call complete before remote ack */
  1258.         {
  1259.             for (i = 0; i < MMI_VOIP_MAX_NUM_CALL; i++)
  1260.             {
  1261.                 callId = g_voip_cntx_p->call_list_info.call_info[i].callId;
  1262.                 if (callList.call_id == callId)
  1263.                 {
  1264.                     for (n = 0; n < VOIP_MAX_NUM_DIALOG; n++)
  1265.                     {
  1266.                         if (callList.dialog[n].in_use == TRUE)
  1267.                         {
  1268.                             for (m = 0; m < VOIP_MAX_NUM_DIALOG; m++)
  1269.                             {
  1270.                                 dialogId = g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dialogId;
  1271.                                 if (callList.dialog[n].dialog_id == dialogId)
  1272.                                 {
  1273.                                     break;
  1274.                                 }
  1275.                             }
  1276.                             if (m == VOIP_MAX_NUM_DIALOG)   /* add dialog entry */
  1277.                             {
  1278.                                 for (m = 0; m < VOIP_MAX_NUM_DIALOG; m++)
  1279.                                 {
  1280.                                     if (g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dialogId == -1)
  1281.                                     {
  1282.                                         g_voip_cntx_p->call_list_info.call_info[i].numDialog++;
  1283.                                         g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dialogId =
  1284.                                             callList.dialog[n].dialog_id;
  1285.                                         if ((g_voip_cntx_p->call_list_info.call_info[i].currState == MMI_VOIP_ACTIVE_STATE) || 
  1286.                                             (g_voip_cntx_p->call_list_info.call_info[i].currState == MMI_VOIP_HOLD_STATE))
  1287.                                         {
  1288.                                             if (g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].rtpHandle == -1)
  1289.                                             {
  1290.                                                 g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].rtpHandle = mmi_voip_create_rtp(&callList.dialog[n].sdp_info);
  1291.                                             }
  1292.                                             memcpy(
  1293.                                                 &g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].sdp_info,
  1294.                                                 &callList.dialog[n].sdp_info,
  1295.                                                 sizeof(voip_sdp_struct));
  1296.                                             mmi_voip_switch_rtp(FALSE, callList.call_id, callList.dialog[n].dialog_id);
  1297.                                             if (!mmi_dt_is_valid(&g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].startTime))
  1298.                                             {
  1299.                                                 DTGetRTCTime(&currTime);
  1300.                                                 g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].startTime = currTime;
  1301.                                             }
  1302.                                         }
  1303.                                         memset(
  1304.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dispName,
  1305.                                             0,
  1306.                                             (VOIP_DISP_NAME_LEN * sizeof(U16)));
  1307.                                         mmi_chset_convert(
  1308.                                             MMI_CHSET_UTF8,
  1309.                                             MMI_CHSET_UCS2,
  1310.                                             (char*)callList.dialog[n].user_addr.disp_name,
  1311.                                             (char*)g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].dispName,
  1312.                                             (S32)(VOIP_DISP_NAME_LEN * sizeof(U16)));
  1313.                                         /* it could be a transfer case if uri changes, need to update appName */
  1314.                                         if (strncmp(
  1315.                                             (S8*)g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].remoteUri, 
  1316.                                             (S8*)callList.dialog[n].user_addr.uri, 
  1317.                                             VOIP_URI_LEN))
  1318.                                         {
  1319.                                             memset(
  1320.                                                 g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].appName, 
  1321.                                                 0, 
  1322.                                                 (VOIP_DISP_NAME_LEN * sizeof(U16)));
  1323.                                         }
  1324.                                         memset(
  1325.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].remoteUri,
  1326.                                             0,
  1327.                                             VOIP_URI_LEN);
  1328.                                         memcpy(
  1329.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].remoteUri,
  1330.                                             callList.dialog[n].user_addr.uri,
  1331.                                             VOIP_URI_LEN);
  1332.                                         if (isConf == TRUE)
  1333.                                         {
  1334.                                             /* update mixer's information for the other dialog */
  1335.                                             mmi_voip_switch_rtp(
  1336.                                                 FALSE,
  1337.                                                 g_voip_cntx_p->call_list_info.call_info[i].callId,
  1338.                                                 g_voip_cntx_p->call_list_info.call_info[i].dialog_info[0].dialogId);
  1339.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].callOrigin =
  1340.                                                 g_voip_cntx_p->call_misc_info.actualOrigin;
  1341.                                             g_voip_cntx_p->call_misc_info.actualOrigin = MMI_VOIP_NONE_ORIGIN;
  1342.                                             g_voip_cntx_p->call_list_info.call_info[i].dialog_info[m].startTime =
  1343.                                                 g_voip_cntx_p->call_misc_info.actualTime;
  1344.                                             memset(&g_voip_cntx_p->call_misc_info.actualTime, 0, sizeof(MYTIME));
  1345.                                         }
  1346.                                         break;
  1347.                                     }
  1348.                                 }
  1349.                                 if (m == VOIP_MAX_NUM_DIALOG)
  1350.                                 {
  1351.                                     MMI_ASSERT(0);  /* no available dialog entry */
  1352.                                 }
  1353.                             }
  1354.                         }
  1355.                     }
  1356.                     break;
  1357.                 }
  1358.             }
  1359.             if (i == MMI_VOIP_MAX_NUM_CALL) /* add call entry */
  1360.             {
  1361.                 freeTab = g_voip_cntx_p->call_misc_info.currfreeTab;
  1362.                 if (freeTab != -1)
  1363.                 {
  1364.                     for (n = 0; n < VOIP_MAX_NUM_DIALOG; n++)
  1365.                     {
  1366.                         if (callList.dialog[n].in_use == TRUE)
  1367.                         {
  1368.                             g_voip_cntx_p->call_list_info.call_info[freeTab].callId = callList.call_id;
  1369.                             g_voip_cntx_p->call_list_info.call_info[freeTab].currState = mmi_voip_get_call_state_enum(callList.dialog[n].dialog_state);
  1370.                             for (m = 0; m < VOIP_MAX_NUM_DIALOG; m++)
  1371.                             {
  1372.                                 if ((g_voip_cntx_p->call_list_info.call_info[freeTab].currState == MMI_VOIP_HOLD_STATE) && (m == 0))    /* only update held call count according to the first dialog */
  1373.                                 {
  1374.                                     g_voip_cntx_p->call_list_info.numHeld++;
  1375.                                 }
  1376.                                 if (g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].dialogId == -1)
  1377.                                 {
  1378.                                     g_voip_cntx_p->call_list_info.call_info[freeTab].numDialog++;
  1379.                                     g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].dialogId =
  1380.                                         callList.dialog[n].dialog_id;
  1381.                                     if ((g_voip_cntx_p->call_list_info.call_info[freeTab].currState == MMI_VOIP_ACTIVE_STATE) ||
  1382.                                         (g_voip_cntx_p->call_list_info.call_info[freeTab].currState == MMI_VOIP_HOLD_STATE))
  1383.                                     {
  1384.                                         if (g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].rtpHandle == -1)
  1385.                                         {
  1386.                                             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].rtpHandle = mmi_voip_create_rtp(&callList.dialog[n].sdp_info);
  1387.                                         }
  1388.                                         memcpy(
  1389.                                             &g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].sdp_info,
  1390.                                             &callList.dialog[n].sdp_info,
  1391.                                             sizeof(voip_sdp_struct));
  1392.                                         mmi_voip_switch_rtp(FALSE, callList.call_id, callList.dialog[n].dialog_id);
  1393.                                         if (!mmi_dt_is_valid(&g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].startTime))
  1394.                                         {
  1395.                                             DTGetRTCTime(&currTime);
  1396.                                             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].startTime = currTime;
  1397.                                         }
  1398.                                     }
  1399.                                     memset(
  1400.                                         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].dispName,
  1401.                                         0,
  1402.                                         (VOIP_DISP_NAME_LEN * sizeof(U16)));
  1403.                                     mmi_chset_convert(
  1404.                                         MMI_CHSET_UTF8,
  1405.                                         MMI_CHSET_UCS2,
  1406.                                         (char*)callList.dialog[n].user_addr.disp_name,
  1407.                                         (char*)g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].dispName,
  1408.                                         (S32)(VOIP_DISP_NAME_LEN * sizeof(U16)));
  1409.                                     /* it could be a transfer case if uri changes, need to update appName */
  1410.                                     if (strncmp(
  1411.                                         (S8*)g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].remoteUri, 
  1412.                                         (S8*)callList.dialog[n].user_addr.uri, 
  1413.                                         VOIP_URI_LEN))
  1414.                                     {
  1415.                                         memset(
  1416.                                             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].appName, 
  1417.                                             0, 
  1418.                                             (VOIP_DISP_NAME_LEN * sizeof(U16)));
  1419.                                     }
  1420.                                     memset(
  1421.                                         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].remoteUri,
  1422.                                         0,
  1423.                                         VOIP_URI_LEN);
  1424.                                     memcpy(
  1425.                                         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].remoteUri,
  1426.                                         callList.dialog[n].user_addr.uri,
  1427.                                         VOIP_URI_LEN);
  1428.                                     if (isConf == TRUE)
  1429.                                     {
  1430.                                         /* update mixer's information for the other dialog */
  1431.                                         mmi_voip_switch_rtp(
  1432.                                             FALSE,
  1433.                                             g_voip_cntx_p->call_list_info.call_info[freeTab].callId,
  1434.                                             g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[0].dialogId);
  1435.                                         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].callOrigin =
  1436.                                             g_voip_cntx_p->call_misc_info.actualOrigin;
  1437.                                         g_voip_cntx_p->call_misc_info.actualOrigin = MMI_VOIP_NONE_ORIGIN;
  1438.                                         g_voip_cntx_p->call_list_info.call_info[freeTab].dialog_info[m].startTime =
  1439.                                             g_voip_cntx_p->call_misc_info.actualTime;
  1440.                                         memset(&g_voip_cntx_p->call_misc_info.actualTime, 0, sizeof(MYTIME));
  1441.                                     }
  1442.                                     break;
  1443.                                 }
  1444.                             }
  1445.                             if (m == VOIP_MAX_NUM_DIALOG)
  1446.                             {
  1447.                                 MMI_ASSERT(0);  /* no available dialog entry */
  1448.                             }
  1449.                             g_voip_cntx_p->call_list_info.numTotal++;
  1450.                             g_voip_cntx_p->call_misc_info.currfreeTab++;
  1451.                             if (g_voip_cntx_p->call_misc_info.currfreeTab == MMI_VOIP_MAX_NUM_CALL)
  1452.                             {
  1453.                                 g_voip_cntx_p->call_misc_info.currfreeTab = -1; /* call capacity full */
  1454.                             }
  1455.                         }
  1456.                     }
  1457.                 }
  1458.                 else
  1459.                 {
  1460.                     /* do not assert in case four calls + one will-be-bk-reject call */
  1461.                     PRINT_INFORMATION(("n[mmi_voip_update_to_add_call_list] No Available Call Entry, Ignore and Wait to Background Rejectn"));
  1462.                 }
  1463.             }
  1464.         }
  1465.     }
  1466.     FS_Close(fileHandle);
  1467. }
  1468. /*****************************************************************************
  1469.  * FUNCTION
  1470.  *  mmi_voip_get_summary_string
  1471.  * DESCRIPTION
  1472.  *  Prepare current status display string.
  1473.  * PARAMETERS
  1474.  *  unicodeStr          [IN/OUT]            Current status string in unicode
  1475.  * RETURNS
  1476.  *  void
  1477.  *****************************************************************************/
  1478. void mmi_voip_get_summary_string(U8 *unicodeStr)
  1479. {
  1480.     /*----------------------------------------------------------------*/
  1481.     /* Local Variables                                                */
  1482.     /*----------------------------------------------------------------*/    
  1483.     S32 profIndex = 0;
  1484.     U8 colon[4] = { ':', '', '', '' }; /* : */
  1485.     U8 newline[4] = { 'n', '', '', '' }; /* n */
  1486.     U8 slash[4] = { '/', '', '', '' }; /* / */
  1487.     
  1488.     /*----------------------------------------------------------------*/
  1489.     /* Code Body                                                      */
  1490.     /*----------------------------------------------------------------*/
  1491.     /* Login/Logout: */
  1492.     pfnUnicodeStrcpy((S8*)unicodeStr, GetString(STR_ID_VOIP_LOGIN));
  1493.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*)slash);
  1494.     pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_LOGOUT));
  1495.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*)colon);
  1496.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1497.     
  1498.     profIndex = g_voip_cntx_p->prof_setting_info.actprofIndex;
  1499.     if (profIndex != -1)
  1500.     {
  1501.         if (g_voip_cntx_p->reg_state_info == MMI_VOIP_REG_STATE)
  1502.         {
  1503.             pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_REGISTER));
  1504.             pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1505.             pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1506.         }
  1507.         else
  1508.         {
  1509.             pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_NOT_REGISTER));
  1510.             pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1511.             pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1512.         }
  1513.         
  1514.         mmi_voip_update_prof_common_cache_to_disp(profIndex);
  1515.         /* Profile Name: */
  1516.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_PROF_COMMON_PROFNAME));
  1517.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)colon);
  1518.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1519.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.profileName);
  1520.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1521.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1522.         mmi_voip_update_prof_acct_cache_to_disp(profIndex);
  1523.         /* SIP Server/SIP Port: */
  1524.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_PROF_ACCOUNT_SIPSERVER));
  1525.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)slash);
  1526.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_PROF_ACCOUNT_SIPPORT));
  1527.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)colon);
  1528.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1529.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.serverName);
  1530.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)colon);
  1531.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.portNumber);
  1532.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1533.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1534.         /* Username: */
  1535.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_PROF_USERNAME));
  1536.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)colon);
  1537.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1538.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.username);
  1539.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1540.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1541.         /* Display Name: */
  1542.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_PROF_ACCOUNT_DISPNAME));
  1543.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)colon);
  1544.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1545.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.displayName);
  1546.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1547.     }
  1548.     else
  1549.     {
  1550.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_NO_ACTIVATED_PROFILE));
  1551.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1552.     }    
  1553.     
  1554.     MMI_ASSERT(unicodeStr[MAX_SUB_MENUS * MAX_SUB_MENU_SIZE - 1] == '');
  1555. }
  1556. /*****************************************************************************
  1557.  * FUNCTION
  1558.  *  mmi_voip_get_call_state_enum
  1559.  * DESCRIPTION
  1560.  *  Map voip cc dialog state to mmi call state.
  1561.  * PARAMETERS
  1562.  *  state           [IN]            Voip cc dialog state
  1563.  * RETURNS
  1564.  *  MMI call state.
  1565.  *****************************************************************************/
  1566. mmi_voip_call_state_enum mmi_voip_get_call_state_enum(voip_dlg_state_enum state)
  1567. {
  1568.     /*----------------------------------------------------------------*/
  1569.     /* Local Variables                                                */
  1570.     /*----------------------------------------------------------------*/
  1571.     
  1572.     /*----------------------------------------------------------------*/
  1573.     /* Code Body                                                      */
  1574.     /*----------------------------------------------------------------*/
  1575.     switch (state)
  1576.     {
  1577.         case VOIP_DLG_STATE_TERMINATED:
  1578.             return MMI_VOIP_IDLE_STATE;
  1579.         case VOIP_DLG_STATE_MO:
  1580.             return MMI_VOIP_OUTGOING_STATE;
  1581.         case VOIP_DLG_STATE_MT:
  1582.             return MMI_VOIP_INCOMING_STATE;
  1583.         case VOIP_DLG_STATE_WAIT_ACT: /* accept call complete before remote ack */
  1584.         case VOIP_DLG_STATE_ACTIVE:
  1585.             return MMI_VOIP_ACTIVE_STATE;
  1586.         case VOIP_DLG_STATE_HOLD:
  1587.             return MMI_VOIP_HOLD_STATE;
  1588.         case VOIP_DLG_STATE_TRANSFERING:
  1589.         case VOIP_DLG_STATE_TRANSFEREE:
  1590.             return MMI_VOIP_TRANSFER_STATE;
  1591.         case VOIP_DLG_STATE_TERMINATING:
  1592.             return MMI_VOIP_DISCONNECTING_STATE;
  1593.         default:
  1594.             return MMI_VOIP_CALL_STATE_TOTAL;
  1595.     }
  1596. }
  1597. /*****************************************************************************
  1598.  * FUNCTION
  1599.  *  mmi_voip_get_call_end_string
  1600.  * DESCRIPTION
  1601.  *  Append string "Call End" in front of call duration.
  1602.  * PARAMETERS
  1603.  *  duration            [IN]            Duration of the call
  1604.  *  unicodeStr          [IN/OUT]        Call end string
  1605.  * RETURNS
  1606.  *  void
  1607.  *****************************************************************************/
  1608. void mmi_voip_get_call_end_string(MYTIME *duration, U8 *unicodeStr)
  1609. {
  1610.     /*----------------------------------------------------------------*/
  1611.     /* Local Variables                                                */
  1612.     /*----------------------------------------------------------------*/
  1613.     U8 newline[4] = { 'n', '', '', '' }; /* n */
  1614.     U8 *timeStr = OslMalloc(32);
  1615.     /*----------------------------------------------------------------*/
  1616.     /* Code Body                                                      */
  1617.     /*----------------------------------------------------------------*/
  1618.     pfnUnicodeStrcpy((S8*) unicodeStr, GetString(STR_ID_VOIP_CALL_END));
  1619.     pfnUnicodeStrcat((S8*) unicodeStr, (S8*) newline);
  1620.     duration_string(duration, (UI_string_type) timeStr, DT_ACTIVE_CALL_SCREEN);
  1621.     pfnUnicodeStrcat((S8*) unicodeStr, (S8*) timeStr);
  1622.     OslMfree(timeStr);
  1623.     MMI_ASSERT(unicodeStr[MAX_SUB_MENU_SIZE - 2] == '' && unicodeStr[MAX_SUB_MENU_SIZE - 1] == '');
  1624. }
  1625. /*****************************************************************************
  1626.  * FUNCTION
  1627.  *  mmi_voip_get_dtmf_keycode_enum
  1628.  * DESCRIPTION
  1629.  *  Map mmi dtmf key to rtp dtmf key.
  1630.  * PARAMETERS
  1631.  *  keyCode         [IN]            Mmi dtmf key
  1632.  * RETURNS
  1633.  *  RTP dtmf key.
  1634.  *****************************************************************************/
  1635. rtp_dtmf_code_enum mmi_voip_get_dtmf_keycode_enum(U16 *keyCode)
  1636. {
  1637.     /*----------------------------------------------------------------*/
  1638.     /* Local Variables                                                */
  1639.     /*----------------------------------------------------------------*/
  1640.     
  1641.     /*----------------------------------------------------------------*/
  1642.     /* Code Body                                                      */
  1643.     /*----------------------------------------------------------------*/
  1644.     switch (*keyCode)
  1645.     {
  1646.         case KEY_0:
  1647.             return RTP_DTMF_CODE_0;
  1648.         case KEY_1:
  1649.             return RTP_DTMF_CODE_1;
  1650.         case KEY_2:
  1651.             return RTP_DTMF_CODE_2;
  1652.         case KEY_3:
  1653.             return RTP_DTMF_CODE_3;
  1654.         case KEY_4:
  1655.             return RTP_DTMF_CODE_4;
  1656.         case KEY_5:
  1657.             return RTP_DTMF_CODE_5;
  1658.         case KEY_6:
  1659.             return RTP_DTMF_CODE_6;
  1660.         case KEY_7:
  1661.             return RTP_DTMF_CODE_7;
  1662.         case KEY_8:
  1663.             return RTP_DTMF_CODE_8;
  1664.         case KEY_9:
  1665.             return RTP_DTMF_CODE_9;
  1666.         case KEY_STAR:
  1667.             return RTP_DTMF_CODE_STAR;
  1668.         case KEY_POUND:
  1669.             return RTP_DTMF_CODE_HASH;
  1670.         default:
  1671.             return RTP_DTMF_CODE_TOTAL;
  1672.     }
  1673. }
  1674. /*****************************************************************************
  1675.  * FUNCTION
  1676.  *  mmi_voip_get_error_cause
  1677.  * DESCRIPTION
  1678.  *  Map voip cc error cause to mmi error string.
  1679.  * PARAMETERS
  1680.  *  result          [IN]            Major result
  1681.  *  cause           [IN]            Minor cause
  1682.  * RETURNS
  1683.  *  String id of the error.
  1684.  *****************************************************************************/
  1685. U16 mmi_voip_get_error_cause(U8 result, S32 cause)
  1686. {
  1687.     /*----------------------------------------------------------------*/
  1688.     /* Local Variables                                                */
  1689.     /*----------------------------------------------------------------*/
  1690.     
  1691.     /*----------------------------------------------------------------*/
  1692.     /* Code Body                                                      */
  1693.     /*----------------------------------------------------------------*/
  1694.     switch (result)
  1695.     {
  1696.         case VOIP_ERROR:        /* failure happens in VoIP task */
  1697.         case VOIP_SIP_ERROR:    /* failure happens in SIP task */
  1698.         case VOIP_NAT_ERROR:    /* NAT related error */
  1699.             return mmi_voip_get_error_string(cause);
  1700.         case VOIP_FS_ERROR:     /* file system related error */
  1701.             return GetFileSystemErrorString(cause);
  1702.         default:
  1703.             return STR_ID_VOIP_UNKNOWN_ERROR;
  1704.     }
  1705. }
  1706. /*****************************************************************************
  1707.  * FUNCTION
  1708.  *  mmi_voip_get_error_string
  1709.  * DESCRIPTION
  1710.  *  Look up error table to get corresponding error string.
  1711.  * PARAMETERS
  1712.  *  cause           [IN]            Error cause
  1713.  * RETURNS
  1714.  *  String id of the error.
  1715.  *****************************************************************************/
  1716. U16 mmi_voip_get_error_string(S32 cause)
  1717. {
  1718.     /*----------------------------------------------------------------*/
  1719.     /* Local Variables                                                */
  1720.     /*----------------------------------------------------------------*/
  1721.     S32 i = 0, totalEntry = 0;
  1722.     /*----------------------------------------------------------------*/
  1723.     /* Code Body                                                      */
  1724.     /*----------------------------------------------------------------*/
  1725.     totalEntry = sizeof(g_voip_error_table) / sizeof(mmi_voip_error_string_struct);
  1726.     for (i = 0; i < totalEntry; i++)
  1727.     {
  1728.         if (g_voip_error_table[i].errorNo == cause)
  1729.         {
  1730.             return g_voip_error_table[i].errorStr;
  1731.         }
  1732.     }
  1733.     return STR_ID_VOIP_UNKNOWN_ERROR;
  1734. }
  1735. /*****************************************************************************
  1736.  * FUNCTION
  1737.  *  mmi_voip_set_outgoing_origin_app
  1738.  * DESCRIPTION
  1739.  *  Put phonebook or call history structure to g_voip_cntx_p->call_originapp_info.
  1740.  * PARAMETERS
  1741.  *  moOrigin        [IN]            Outgoing call origin, either MMI_VOIP_PHB or MMI_VOIP_HISTORY
  1742.  * RETURNS
  1743.  *  TRUE means outgoing call does dial from phonebook or call history; 
  1744.  *  FALSE means outgoing call neither dial from phonebook nor call history.
  1745.  *****************************************************************************/
  1746. BOOL mmi_voip_set_outgoing_origin_app(mmi_voip_mo_origin_enum moOrigin)
  1747. {
  1748.     /*----------------------------------------------------------------*/
  1749.     /* Local Variables                                                */
  1750.     /*----------------------------------------------------------------*/
  1751.     PHB_VOIP_INTERFACE phbData;
  1752.     LOG_CALL logData;
  1753.     S32 uriLen = 0;
  1754.     /*----------------------------------------------------------------*/
  1755.     /* Code Body                                                      */
  1756.     /*----------------------------------------------------------------*/
  1757.     switch (moOrigin)
  1758.     {
  1759.         case MMI_VOIP_PHB:
  1760.             phbData = mmi_phb_call_get_data_for_voip(g_voip_cntx_p->call_misc_info.dispUri, TRUE);
  1761.             if (phbData.dialInList == MMI_PHB_PHONEBOOK)
  1762.             {
  1763.                 memset(&g_voip_cntx_p->call_originapp_info, 0, sizeof(mmi_voip_call_originapp_struct));
  1764.                 g_voip_cntx_p->call_originapp_info.moOrgin = MMI_VOIP_PHB;
  1765.                 uriLen = (VOIP_DISP_NAME_LEN > pfnUnicodeStrlen((S8*)phbData.name)) ?
  1766.                     (pfnUnicodeStrlen((S8*)phbData.name)) : (VOIP_DISP_NAME_LEN - 1);
  1767.                 pfnUnicodeStrncpy((S8*)g_voip_cntx_p->call_originapp_info.dispName, (S8*)phbData.name, uriLen);
  1768.                 UnicodeNToAnsii((S8*)g_voip_cntx_p->call_originapp_info.remoteUri, (S8*)phbData.uri, (VOIP_URI_LEN * ENCODING_LENGTH));
  1769.                 return TRUE;
  1770.             }
  1771.             break;
  1772.         case MMI_VOIP_HISTORY:
  1773.             if (CHISTGetDialFromCallLogFlag() != 0)
  1774.             {
  1775.                 memset(&g_voip_cntx_p->call_originapp_info, 0, sizeof(mmi_voip_call_originapp_struct));
  1776.                 CHISTGetCallLogName(&logData);
  1777.                 g_voip_cntx_p->call_originapp_info.moOrgin = MMI_VOIP_HISTORY;
  1778.                 uriLen = (VOIP_DISP_NAME_LEN > pfnUnicodeStrlen((S8*)logData.pbName)) ?
  1779.                     (pfnUnicodeStrlen((S8*)logData.pbName)) : (VOIP_DISP_NAME_LEN - 1);
  1780.                 pfnUnicodeStrncpy((S8*)g_voip_cntx_p->call_originapp_info.dispName, (S8*)logData.pbName, uriLen);
  1781.                 UnicodeNToAnsii((S8*)g_voip_cntx_p->call_originapp_info.remoteUri, (S8*)logData.number, (VOIP_URI_LEN * ENCODING_LENGTH));
  1782.                 return TRUE;
  1783.             }
  1784.             break;
  1785.         default:
  1786.             return FALSE;
  1787.     }
  1788.     return FALSE;
  1789. }
  1790. /*****************************************************************************
  1791.  * FUNCTION
  1792.  *  mmi_voip_get_outgoing_disp_name
  1793.  * DESCRIPTION
  1794.  *  Determine to show display name or not for outgoing call.
  1795.  * PARAMETERS
  1796.  *  moOrigin        [IN]            Outgoing call origin
  1797.  *  unicodeSrc      [IN]            Source uri string in unicode
  1798.  *  unicodeDest     [IN/OUT]        Destination uri string in unicode
  1799.  *  destLen         [IN]            Destination uri string length
  1800.  * RETURNS
  1801.  *  TRUE means outgoing call should show display name; 
  1802.  *  FALSE means outgoing call should not show display name.
  1803.  *****************************************************************************/
  1804. BOOL mmi_voip_get_outgoing_disp_name(U8 moOrigin, U8* unicodeSrc, U8* unicodeDest, U8 destLen)
  1805. {
  1806.     /*----------------------------------------------------------------*/
  1807.     /* Local Variables                                                */
  1808.     /*----------------------------------------------------------------*/
  1809.     S32 uriLen = 0;
  1810.     BOOL ret = FALSE;
  1811.     /*----------------------------------------------------------------*/
  1812.     /* Code Body                                                      */
  1813.     /*----------------------------------------------------------------*/
  1814.     if ((moOrigin & MMI_VOIP_SOS) == MMI_VOIP_SOS)
  1815.     {
  1816.         if ((!pfnUnicodeStrcmp((S8*)unicodeSrc, (S8*)sos112)) || 
  1817.             (!pfnUnicodeStrcmp((S8*)unicodeSrc, (S8*)sos911)) ||
  1818.             (!pfnUnicodeStrcmp((S8*)unicodeSrc, (S8*)GetString(STR_ID_VOIP_EMERGENCY_NUM))))
  1819.         {
  1820.             uriLen = (destLen > pfnUnicodeStrlen((S8*)GetString(STR_ID_VOIP_EMERGENCY_NUM))) ? 
  1821.                 (pfnUnicodeStrlen((S8*)GetString(STR_ID_VOIP_EMERGENCY_NUM))) : (destLen - 1);
  1822.             
  1823.             memset(unicodeDest, 0, (destLen * ENCODING_LENGTH));
  1824.             pfnUnicodeStrncpy((S8*)unicodeDest, (S8*)GetString(STR_ID_VOIP_EMERGENCY_NUM), uriLen);
  1825.             ret = TRUE;
  1826.         }
  1827.     }
  1828.     if ((moOrigin & MMI_VOIP_HISTORY) == MMI_VOIP_HISTORY)
  1829.     {
  1830.         /* ensure the name from call history is not empty */
  1831.         if ((g_voip_cntx_p->call_originapp_info.moOrgin == MMI_VOIP_HISTORY) && 
  1832.             (pfnUnicodeStrlen((S8*)g_voip_cntx_p->call_originapp_info.dispName)))
  1833.         {
  1834.             uriLen = (destLen >= VOIP_DISP_NAME_LEN) ? (VOIP_DISP_NAME_LEN) : (destLen - 1);
  1835.             memset(unicodeDest, 0, (destLen * ENCODING_LENGTH));
  1836.             pfnUnicodeStrncpy((S8*)unicodeDest, (S8*)g_voip_cntx_p->call_originapp_info.dispName, uriLen);
  1837.             ret = TRUE;
  1838.         }
  1839.     }
  1840.     if ((moOrigin & MMI_VOIP_PHB) == MMI_VOIP_PHB)
  1841.     {        
  1842.         /* ensure the name from phonebook is not empty */
  1843.         if ((g_voip_cntx_p->call_originapp_info.moOrgin == MMI_VOIP_PHB) && 
  1844.             (pfnUnicodeStrlen((S8*)g_voip_cntx_p->call_originapp_info.dispName)))
  1845.         {
  1846.             uriLen = (destLen >= VOIP_DISP_NAME_LEN) ? (VOIP_DISP_NAME_LEN) : (destLen - 1);
  1847.             memset(unicodeDest, 0, (destLen * ENCODING_LENGTH));
  1848.             pfnUnicodeStrncpy((S8*)unicodeDest, (S8*)g_voip_cntx_p->call_originapp_info.dispName, uriLen);
  1849.             ret = TRUE;
  1850.         }
  1851.     }
  1852.     return ret;
  1853. }
  1854. /*****************************************************************************
  1855.  * FUNCTION
  1856.  *  mmi_voip_get_redial_string
  1857.  * DESCRIPTION
  1858.  *  Prepare redial display string.
  1859.  * PARAMETERS
  1860.  *  unicodeStr          [IN/OUT]            Redial string in unicode
  1861.  * RETURNS
  1862.  *  void
  1863.  *****************************************************************************/
  1864. void mmi_voip_get_redial_string(U8 *unicodeStr)
  1865. {
  1866.     /*----------------------------------------------------------------*/
  1867.     /* Local Variables                                                */
  1868.     /*----------------------------------------------------------------*/
  1869.     U8 newline[4] = { 'n', '', '', '' }; /* n */
  1870.     U8 *asciinumStr = OslMalloc(16);
  1871.     U8 *unicodenumStr = OslMalloc(32);
  1872.     /*----------------------------------------------------------------*/
  1873.     /* Code Body                                                      */
  1874.     /*----------------------------------------------------------------*/
  1875.     memset(asciinumStr, 0, 16);
  1876.     sprintf((S8*)asciinumStr, "%d / %d", (g_voip_cntx_p->call_redial_info.currAttempt + 1), g_voip_cntx_p->call_redial_info.maxAttempt);
  1877.     memset(unicodenumStr, 0, 32);
  1878.     AnsiiToUnicodeString((S8*)unicodenumStr, (S8*)asciinumStr);
  1879.     pfnUnicodeStrcpy((S8*)unicodeStr, (S8*)unicodenumStr);
  1880.     pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_TIME_UNIT));
  1881.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1882.     
  1883.     OslMfree(asciinumStr);
  1884.     OslMfree(unicodenumStr);
  1885.     MMI_ASSERT(unicodeStr[MMI_VOIP_MAX_STRING_LEN - 1] == '');
  1886. }
  1887. /*****************************************************************************
  1888.  * FUNCTION
  1889.  *  mmi_voip_get_mwi_state_enum
  1890.  * DESCRIPTION
  1891.  *  Map voip cc message waiting type to mmi message waiting string.
  1892.  * PARAMETERS
  1893.  *  state           [IN]            Message waiting type
  1894.  * RETURNS
  1895.  *  String id of message waiting.
  1896.  *****************************************************************************/
  1897. U16 mmi_voip_get_mwi_state_enum(voip_mwi_type_enum state)
  1898. {
  1899.     /*----------------------------------------------------------------*/
  1900.     /* Local Variables                                                */
  1901.     /*----------------------------------------------------------------*/
  1902.     
  1903.     /*----------------------------------------------------------------*/
  1904.     /* Code Body                                                      */
  1905.     /*----------------------------------------------------------------*/
  1906.     switch (state)
  1907.     {
  1908.         case VOIP_MWI_VOICE:
  1909.             return STR_ID_VOIP_VOICE_MESSAGE;
  1910.         case VOIP_MWI_FAX:
  1911.             return STR_ID_VOIP_FAX_MESSAGE;
  1912.         case VOIP_MWI_PAGER:
  1913.             return STR_ID_VOIP_PAGER_MESSAGE;
  1914.         case VOIP_MWI_MM:
  1915.             return STR_ID_VOIP_MULTIMEDIA_MESSAGE;
  1916.         case VOIP_MWI_TEXT:
  1917.             return STR_ID_VOIP_TEXT_MESSAGE;
  1918.         default:
  1919.             return STR_ID_VOIP_UNKNOWN_MESSAGE;
  1920.     }
  1921. }
  1922. /*****************************************************************************
  1923.  * FUNCTION
  1924.  *  mmi_voip_get_mwi_string
  1925.  * DESCRIPTION
  1926.  *  Prepare message waiting display string.
  1927.  * PARAMETERS
  1928.  *  unicodeStr          [IN/OUT]            Message waiting string in unicode
  1929.  * RETURNS
  1930.  *  void
  1931.  *****************************************************************************/
  1932. void mmi_voip_get_mwi_string(U8 *unicodeStr)
  1933. {
  1934.     /*----------------------------------------------------------------*/
  1935.     /* Local Variables                                                */
  1936.     /*----------------------------------------------------------------*/
  1937.     U8 newline[4] = { 'n', '', '', '' }; /* n */
  1938.     U8 *asciinumStr = OslMalloc(16);
  1939.     U8 *unicodenumStr = OslMalloc(32);
  1940.     U32 newMsg = 0, totalMsg = 0;
  1941.     /*----------------------------------------------------------------*/
  1942.     /* Code Body                                                      */
  1943.     /*----------------------------------------------------------------*/
  1944.     pfnUnicodeStrcpy((S8*)unicodeStr, GetString(STR_ID_VOIP_NEW_MESSAGE));
  1945.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*) newline);
  1946.     newMsg = g_voip_cntx_p->msg_waiting_info.mwiMsg.newmsgs;
  1947.     totalMsg = g_voip_cntx_p->msg_waiting_info.mwiMsg.newmsgs + g_voip_cntx_p->msg_waiting_info.mwiMsg.oldmsgs;
  1948.     memset(asciinumStr, 0, 16);
  1949.     sprintf((S8*)asciinumStr, "%d / %d", newMsg, totalMsg);
  1950.     memset(unicodenumStr, 0, 32);
  1951.     AnsiiToUnicodeString((S8*)unicodenumStr, (S8*)asciinumStr);
  1952.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*)unicodenumStr);
  1953.     pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_MSG_UNIT));
  1954.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1955.     pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_URGENT_MESSAGE));
  1956.     pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1957.     if (g_voip_cntx_p->msg_waiting_info.mwiMsg.is_urgent_present == TRUE)
  1958.     {
  1959.         newMsg = g_voip_cntx_p->msg_waiting_info.mwiMsg.new_urgentmsgs;
  1960.         totalMsg =
  1961.             g_voip_cntx_p->msg_waiting_info.mwiMsg.new_urgentmsgs +
  1962.             g_voip_cntx_p->msg_waiting_info.mwiMsg.old_urgentmsgs;
  1963.         memset(asciinumStr, 0, 16);
  1964.         sprintf((S8*)asciinumStr, "%d / %d", newMsg, totalMsg);
  1965.         memset(unicodenumStr, 0, 32);
  1966.         AnsiiToUnicodeString((S8*)unicodenumStr, (S8*)asciinumStr);
  1967.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)unicodenumStr);
  1968.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_MSG_UNIT));
  1969.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1970.     }
  1971.     else
  1972.     {
  1973.         pfnUnicodeStrcat((S8*)unicodeStr, GetString(STR_ID_VOIP_NOT_SUPPORT));
  1974.         pfnUnicodeStrcat((S8*)unicodeStr, (S8*)newline);
  1975.     }
  1976.     
  1977.     OslMfree(asciinumStr);
  1978.     OslMfree(unicodenumStr);
  1979.     
  1980.     MMI_ASSERT(unicodeStr[MMI_VOIP_MAX_STRING_LEN - 1] == '');
  1981. }
  1982. /*****************************************************************************
  1983.  * FUNCTION
  1984.  *  mmi_voip_is_idle_state
  1985.  * DESCRIPTION
  1986.  *  Check if it is in the idle screen or screen saver.
  1987.  * PARAMETERS
  1988.  *  void
  1989.  * RETURNS
  1990.  *  TRUE means it is in idle screen or screen saver;
  1991.  *  FALSE means it is not in idle screen or screen saver.
  1992.  *****************************************************************************/
  1993. BOOL mmi_voip_is_idle_state(void)
  1994. {
  1995.     /*----------------------------------------------------------------*/
  1996.     /* Local Variables                                                */
  1997.     /*----------------------------------------------------------------*/
  1998.     
  1999.     /*----------------------------------------------------------------*/
  2000.     /* Code Body                                                      */
  2001.     /*----------------------------------------------------------------*/
  2002.     if (g_idle_context.IsOnIdleScreen || g_idle_context.ScreenSaverRunFlag)
  2003.     {
  2004.         return TRUE;
  2005.     }
  2006.     else
  2007.     {
  2008.         return FALSE;
  2009.     }
  2010. }
  2011. /*****************************************************************************
  2012.  * FUNCTION
  2013.  *  mmi_voip_is_keypad_lock_state
  2014.  * DESCRIPTION
  2015.  *  Check if keypad is locked.
  2016.  * PARAMETERS
  2017.  *  void
  2018.  * RETURNS
  2019.  *  TRUE means it is in keypad lock; FALSE means it is not in keypad lock.
  2020.  *****************************************************************************/
  2021. BOOL mmi_voip_is_keypad_lock_state(void)
  2022. {
  2023.     /*----------------------------------------------------------------*/
  2024.     /* Local Variables                                                */
  2025.     /*----------------------------------------------------------------*/
  2026.     
  2027.     /*----------------------------------------------------------------*/
  2028.     /* Code Body                                                      */
  2029.     /*----------------------------------------------------------------*/
  2030.     if (g_keylock_context.gKeyPadLockFlag)
  2031.     {
  2032.         return TRUE;
  2033.     }
  2034.     else
  2035.     {
  2036.         return FALSE;
  2037.     }
  2038. }
  2039. /*****************************************************************************
  2040.  * FUNCTION
  2041.  *  mmi_voip_is_empty_profile
  2042.  * DESCRIPTION
  2043.  *  Check if the specific profile is empty.
  2044.  * PARAMETERS
  2045.  *  profIndex       [IN]        Index of intended to check profile
  2046.  * RETURNS
  2047.  *  TRUE means the specific profile is empty;
  2048.  *  FALSE means the specific profile is not empty.
  2049.  *****************************************************************************/
  2050. BOOL mmi_voip_is_empty_profile(S32 profIndex)
  2051. {
  2052.     /*----------------------------------------------------------------*/
  2053.     /* Local Variables                                                */
  2054.     /*----------------------------------------------------------------*/
  2055.     
  2056.     /*----------------------------------------------------------------*/
  2057.     /* Code Body                                                      */
  2058.     /*----------------------------------------------------------------*/
  2059.     mmi_voip_update_prof_common_cache_to_disp(profIndex);
  2060.     /* profile name is not default profile name, the profile is not empty */
  2061.     if (pfnUnicodeStrcmp(
  2062.             (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.profileName, 
  2063.             (S8*)GetString(STR_ID_VOIP_PROF_COMMON_PROF1 + profIndex)))
  2064.     {
  2065.         return FALSE;
  2066.     }
  2067.     /* voice mail server is not empty and is not "sip:", the profile is not empty */
  2068.     if (pfnUnicodeStrcmp(
  2069.             (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.serverName, 
  2070.             (S8*)sipUri))
  2071.     {
  2072.         return FALSE;
  2073.     }
  2074.     mmi_voip_update_prof_acct_cache_to_disp(profIndex);
  2075.     if ((pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.serverName)) || 
  2076.         (pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.displayName)) || 
  2077.         (pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.password)) || 
  2078.         (pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.authName)))
  2079.     {
  2080.         return FALSE;
  2081.     }
  2082.     /* port is not 5060, the profile is not empty */
  2083.     if (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].acct_info.sipPort != 5060)
  2084.     {
  2085.         return FALSE;
  2086.     }
  2087.     /* username is not empty and is not "sip:", the profile is not empty */
  2088.     if (pfnUnicodeStrcmp(
  2089.             (S8*)g_voip_cntx_p->prof_setting_info.disp_prof.username, 
  2090.             (S8*)sipUri))
  2091.     {
  2092.         return FALSE;
  2093.     }
  2094.     
  2095.     mmi_voip_update_prof_outbound_cache_to_disp(profIndex);
  2096.     if ((pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.serverName)) || 
  2097.         (pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.username)) || 
  2098.         (pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.password)))
  2099.     {
  2100.         return FALSE;
  2101.     }
  2102.     if (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].out_server_info.port != 0)
  2103.     {
  2104.         return FALSE;
  2105.     }
  2106.     mmi_voip_update_prof_register_cache_to_disp(profIndex);
  2107.     if ((pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.serverName)) || 
  2108.         (pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.username)) || 
  2109.         (pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.password)))
  2110.     {
  2111.         return FALSE;
  2112.     }
  2113.     if (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].reg_server_info.port != 0)
  2114.     {
  2115.         return FALSE;
  2116.     }
  2117.     mmi_voip_update_prof_nat_cache_to_disp(profIndex);
  2118.     if ((pfnUnicodeStrlen((S8*)g_voip_cntx_p->prof_setting_info.disp_prof.serverName)))
  2119.     {
  2120.         return FALSE;
  2121.     }
  2122.     if ((g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].nat_info.natFirewall[0] != 0) || 
  2123.         (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].nat_info.natFirewall[1] != 0) || 
  2124.         (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].nat_info.natFirewall[2] != 0) || 
  2125.         (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].nat_info.natFirewall[3] != 0))
  2126.     {
  2127.         return FALSE;
  2128.     }
  2129.     if (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].nat_info.stunPort != 3478)
  2130.     {
  2131.         return FALSE;
  2132.     }
  2133.     if (g_voip_cntx_p->prof_setting_info.saved_prof[profIndex].nat_info.refInterval != 0)
  2134.     {
  2135.         return FALSE;
  2136.     }
  2137.     return TRUE;
  2138. }
  2139. /*****************************************************************************
  2140.  * FUNCTION
  2141.  *  mmi_voip_is_owner_number
  2142.  * DESCRIPTION
  2143.  *  Check if two strings are the same, regardless of the difference of capital or lowercase.
  2144.  * PARAMETERS
  2145.  *  unicodeSrc1         [IN]            String 1 in unicode
  2146.  *  unicodeSrc2         [IN]            String 2 in unicode
  2147.  * RETURNS
  2148.  *  TRUE means lowercase of the two strings are the same;
  2149.  *  FALSE means lowercase of the two strings are different.
  2150.  *****************************************************************************/
  2151. BOOL mmi_voip_is_owner_number(U8 *unicodeSrc1, U8 *unicodeSrc2)
  2152. {
  2153.     /*----------------------------------------------------------------*/
  2154.     /* Local Variables                                                */
  2155.     /*----------------------------------------------------------------*/
  2156.     U8 *lowercaseSrc1 = OslMalloc(VOIP_URI_LEN * ENCODING_LENGTH);
  2157.     U8 *lowercaseSrc2 = OslMalloc(VOIP_URI_LEN * ENCODING_LENGTH);
  2158.     /*----------------------------------------------------------------*/
  2159.     /* Code Body                                                      */
  2160.     /*----------------------------------------------------------------*/
  2161.     memset(lowercaseSrc1, 0, (VOIP_URI_LEN * ENCODING_LENGTH));
  2162.     mmi_voip_convert_uri_lower_case(unicodeSrc1, lowercaseSrc1);
  2163.     memset(lowercaseSrc2, 0, (VOIP_URI_LEN * ENCODING_LENGTH));
  2164.     mmi_voip_convert_uri_lower_case(unicodeSrc2, lowercaseSrc2);
  2165.     if (!pfnUnicodeStrcmp((S8*)lowercaseSrc1, (S8*)lowercaseSrc2))
  2166.     {
  2167.         OslMfree(lowercaseSrc1);
  2168.         OslMfree(lowercaseSrc2);
  2169.         return TRUE;
  2170.     }
  2171.     else
  2172.     {
  2173.         OslMfree(lowercaseSrc1);
  2174.         OslMfree(lowercaseSrc2);
  2175.         return FALSE;
  2176.     }
  2177. }
  2178. /*****************************************************************************
  2179.  * FUNCTION
  2180.  *  mmi_voip_is_codec_compatible
  2181.  * DESCRIPTION
  2182.  *  Check if held call's codec is allowed to merge to active call before merging call.
  2183.  * PARAMETERS
  2184.  *  codecList               [IN]            Supported codec list of the held call.
  2185.  *  firstcodecOnly          [IN]            Only compare to the first codec in codec list.
  2186.  * RETURNS
  2187.  *  TRUE means the codecs are compatible to merge;
  2188.  *  FALSE means the codecs are not compatible to merge.
  2189.  *****************************************************************************/
  2190. BOOL mmi_voip_is_codec_compatible(voip_codec_enum *codecList, BOOL firstcodecOnly)
  2191. {
  2192. #ifdef __MMI_TARGET__
  2193.     /*----------------------------------------------------------------*/
  2194.     /* Local Variables                                                */
  2195.     /*----------------------------------------------------------------*/
  2196.     U16 codecSupport = 0, localCodec = 0;
  2197.     med_voip_codec_cap_struct codecDetail;
  2198.     S32 i = 0;
  2199.     /*----------------------------------------------------------------*/
  2200.     /* Code Body                                                      */
  2201.     /*----------------------------------------------------------------*/
  2202.     voip_get_codec_cap(VOIP_ENCODE_DECODE, &codecSupport, &codecDetail);
  2203.     if (firstcodecOnly == TRUE)
  2204.     {
  2205.         /* current held call in-use codec must in the codec support list 
  2206.            so that two calls can be merged */
  2207.         if ((codecSupport & codecList[0]) != 0)
  2208.         {
  2209.             return TRUE;
  2210.         }
  2211.     }
  2212.     else
  2213.     {
  2214.         for (i = 0; i < VOIP_MAX_NUM_CODEC; i++)
  2215.         {
  2216.             localCodec |= codecList[i];
  2217.         }
  2218.         if ((codecSupport & localCodec) != 0)
  2219.         {
  2220.             return TRUE;
  2221.         }
  2222.     }
  2223.     return FALSE;
  2224. #else
  2225.     /* always return true for modis and pc simulator */
  2226.     return TRUE;
  2227. #endif /* __MMI_TARGET__ */
  2228. }
  2229. /*****************************************************************************
  2230.  * FUNCTION
  2231.  *  mmi_voip_is_addr_change
  2232.  * DESCRIPTION
  2233.  *  Check if sdp address or port is changed.
  2234.  * PARAMETERS
  2235.  *  mmiSdp          [IN]            Sdp in mmi, which represents last sdp info.
  2236.  *  voipSdp         [IN]            Sdp in voip cc, which represents current sdp info.
  2237.  * RETURNS
  2238.  *  TRUE means the sdp addr or port is changed;
  2239.  *  FALSE means the sdp addr and port is not changed.
  2240.  *****************************************************************************/
  2241. BOOL mmi_voip_is_addr_change(voip_sdp_struct *mmiSdp, voip_sdp_struct *voipSdp)
  2242. {
  2243.     /*----------------------------------------------------------------*/
  2244.     /* Local Variables                                                */
  2245.     /*----------------------------------------------------------------*/
  2246.     
  2247.     /*----------------------------------------------------------------*/
  2248.     /* Code Body                                                      */
  2249.     /*----------------------------------------------------------------*/
  2250.     if ((strncmp((S8*) mmiSdp->local_addr, (S8*) voipSdp->local_addr, VOIP_MAX_IP_SEG_LEN)) ||
  2251.         (strncmp((S8*) mmiSdp->remote_addr, (S8*) voipSdp->remote_addr, VOIP_MAX_IP_SEG_LEN)) ||
  2252.         (mmiSdp->local_rtp_port != voipSdp->local_rtp_port) ||
  2253.         (mmiSdp->remote_rtp_port != voipSdp->remote_rtp_port) ||
  2254.         (mmiSdp->local_rtcp_port != voipSdp->local_rtcp_port) ||
  2255.         (mmiSdp->remote_rtcp_port != voipSdp->remote_rtcp_port))
  2256.     {
  2257.         return TRUE;
  2258.     }
  2259.     return FALSE;
  2260. }
  2261. /*****************************************************************************
  2262.  * FUNCTION
  2263.  *  mmi_voip_play_inbandtone
  2264.  * DESCRIPTION
  2265.  *  Start playing inband tone for outgoing call.
  2266.  *  It should be called after outgoing call screen displays.
  2267.  * PARAMETERS
  2268.  *  void
  2269.  * RETURNS
  2270.  *  void
  2271.  *****************************************************************************/
  2272. void mmi_voip_play_inbandtone(void)
  2273. {
  2274.     /*----------------------------------------------------------------*/
  2275.     /* Local Variables                                                */
  2276.     /*----------------------------------------------------------------*/
  2277.     
  2278.     /*----------------------------------------------------------------*/
  2279.     /* Code Body                                                      */
  2280.     /*----------------------------------------------------------------*/
  2281.     mdi_audio_suspend_background_play();
  2282.     AudioPlayReq(TONE_RINGING_CALL_GSM, DEVICE_AUDIO_PLAY_INFINITE);
  2283. }
  2284. /*****************************************************************************
  2285.  * FUNCTION
  2286.  *  mmi_voip_stop_inbandtone
  2287.  * DESCRIPTION
  2288.  *  Stop playing inband tone for outgoing call.
  2289.  *  It should be called before outgoing call screen disappears.
  2290.  * PARAMETERS
  2291.  *  void
  2292.  * RETURNS
  2293.  *  void
  2294.  *****************************************************************************/
  2295. void mmi_voip_stop_inbandtone(void)
  2296. {
  2297.     /*----------------------------------------------------------------*/
  2298.     /* Local Variables                                                */
  2299.     /*----------------------------------------------------------------*/
  2300.     
  2301.     /*----------------------------------------------------------------*/
  2302.     /* Code Body                                                      */
  2303.     /*----------------------------------------------------------------*/
  2304.     AudioStopReq(TONE_RINGING_CALL_GSM);
  2305. }
  2306. /*****************************************************************************
  2307.  * FUNCTION
  2308.  *  mmi_voip_play_incoming_tone
  2309.  * DESCRIPTION
  2310.  *  Determine to play ring tone or waiting tone for incoming call.
  2311.  *  It should be called after incoming call screen displays.
  2312.  * PARAMETERS
  2313.  *  void
  2314.  * RETURNS
  2315.  *  void
  2316.  *****************************************************************************/
  2317. void mmi_voip_play_incoming_tone(void)
  2318. {
  2319.     /*----------------------------------------------------------------*/
  2320.     /* Local Variables                                                */
  2321.     /*----------------------------------------------------------------*/
  2322.     S32 callId = 0;
  2323.     
  2324.     /*----------------------------------------------------------------*/
  2325.     /* Code Body                                                      */
  2326.     /*----------------------------------------------------------------*/
  2327.     callId = mmi_voip_get_incoming_call_id();
  2328.     if (callId != -1)
  2329.     {
  2330.         if ((g_voip_cntx_p->call_list_info.numTotal == 1) && (GetTotalCallCount() == 0))
  2331.         {
  2332.             mdi_audio_suspend_background_play();
  2333.             mmi_voip_play_ringtone();
  2334.         }
  2335.         else
  2336.         {
  2337.             mdi_audio_suspend_background_play();
  2338.             mmi_voip_play_waitingtone();
  2339.         }
  2340.     }
  2341. }
  2342. /*****************************************************************************
  2343.  * FUNCTION
  2344.  *  mmi_voip_stop_incoming_tone
  2345.  * DESCRIPTION
  2346.  *  Determine to stop ring tone or waiting tone for incoming call.
  2347.  *  It should be called after incoming call screen disappears.
  2348.  * PARAMETERS
  2349.  *  void
  2350.  * RETURNS
  2351.  *  void
  2352.  *****************************************************************************/
  2353. void mmi_voip_stop_incoming_tone(void)
  2354. {
  2355.     /*----------------------------------------------------------------*/
  2356.     /* Local Variables                                                */
  2357.     /*----------------------------------------------------------------*/
  2358.     
  2359.     /*----------------------------------------------------------------*/
  2360.     /* Code Body                                                      */
  2361.     /*----------------------------------------------------------------*/
  2362.     mmi_voip_stop_ringtone();
  2363.     mmi_voip_stop_waitingtone();
  2364. }
  2365. /*****************************************************************************
  2366.  * FUNCTION
  2367.  *  mmi_voip_play_ringtone
  2368.  * DESCRIPTION
  2369.  *  Start playing ring tone for incoming call.
  2370.  *  It should be called after incoming call screen displays.
  2371.  * PARAMETERS
  2372.  *  void
  2373.  * RETURNS
  2374.  *  void
  2375.  *****************************************************************************/
  2376. void mmi_voip_play_ringtone(void)
  2377. {
  2378.     /*----------------------------------------------------------------*/
  2379.     /* Local Variables                                                */
  2380.     /*----------------------------------------------------------------*/
  2381.     /*----------------------------------------------------------------*/
  2382.     /* Code Body                                                      */
  2383.     /*----------------------------------------------------------------*/
  2384.     /* store alert type in playing ringtone for stopping ringtone later on. 
  2385.        it is to prevent alert type change in-call by bluetooth profile */
  2386.     g_voip_cntx_p->call_alert_info.alertType = GetMtCallAlertTypeEnum();
  2387.     g_voip_cntx_p->call_alert_info.ringtoneId = GetRingToneID();
  2388.     switch (g_voip_cntx_p->call_alert_info.alertType)
  2389.     {
  2390.         case MMI_RING:
  2391.             AudioPlayToneWithCallBack(g_voip_cntx_p->call_alert_info.ringtoneId, GetRingTypeEnum(), INCOMING_CALL_TONE);
  2392.             break;
  2393.         case MMI_VIBRATION_ONLY:
  2394.             VibratorOn();
  2395.             break;
  2396.         case MMI_VIBRATION_AND_RING:
  2397.             VibratorOn();
  2398.             AudioPlayToneWithCallBack(g_voip_cntx_p->call_alert_info.ringtoneId, GetRingTypeEnum(), INCOMING_CALL_TONE);
  2399.             break;
  2400.         case MMI_VIBRATION_THEN_RING:
  2401.             VibratorOn();
  2402.             StartTimer(CM_ALERT_NOTIFYDURATION_TIMER, VIB_THEN_RING_DURATION, mmi_voip_play_vibration_then_ring);
  2403.             break;
  2404.         case MMI_ALERT_NONE:
  2405.         case MMI_SILENT:
  2406.             break;
  2407.         default: /* set default as MMI_RING */
  2408.             AudioPlayToneWithCallBack(g_voip_cntx_p->call_alert_info.ringtoneId, GetRingTypeEnum(), INCOMING_CALL_TONE);
  2409.             break;
  2410.     }
  2411. }
  2412. /*****************************************************************************
  2413.  * FUNCTION
  2414.  *  mmi_voip_stop_ringtone
  2415.  * DESCRIPTION
  2416.  *  Stop playing ring tone for incoming call.
  2417.  *  It should be called before incoming call screen disappears.
  2418.  * PARAMETERS
  2419.  *  void
  2420.  * RETURNS
  2421.  *  void
  2422.  *****************************************************************************/
  2423. void mmi_voip_stop_ringtone(void)
  2424. {
  2425.     /*----------------------------------------------------------------*/
  2426.     /* Local Variables                                                */
  2427.     /*----------------------------------------------------------------*/
  2428.     /*----------------------------------------------------------------*/
  2429.     /* Code Body                                                      */
  2430.     /*----------------------------------------------------------------*/
  2431.     switch (g_voip_cntx_p->call_alert_info.alertType)
  2432.     {
  2433.         case MMI_RING:
  2434.             if (g_voip_cntx_p->call_alert_info.ringtoneId < MAX_TONE_ID)
  2435.             {
  2436.                 AudioStopReq(g_voip_cntx_p->call_alert_info.ringtoneId);
  2437.             }
  2438.             else
  2439.             {
  2440.                 mdi_audio_stop_all();
  2441.             }
  2442.             break;
  2443.         case MMI_VIBRATION_ONLY:
  2444.             VibratorOff();
  2445.             break;
  2446.         case MMI_VIBRATION_AND_RING:
  2447.             VibratorOff();
  2448.             if (g_voip_cntx_p->call_alert_info.ringtoneId < MAX_TONE_ID)
  2449.             {
  2450.                 AudioStopReq(g_voip_cntx_p->call_alert_info.ringtoneId);
  2451.             }
  2452.             else
  2453.             {
  2454.                 mdi_audio_stop_all();
  2455.             }
  2456.             break;
  2457.         case MMI_VIBRATION_THEN_RING:
  2458.             StopTimer(CM_ALERT_NOTIFYDURATION_TIMER);
  2459.             VibratorOff();
  2460.             if (g_voip_cntx_p->call_alert_info.ringtoneId < MAX_TONE_ID)
  2461.             {
  2462.                 AudioStopReq(g_voip_cntx_p->call_alert_info.ringtoneId);
  2463.             }
  2464.             else
  2465.             {
  2466.                 mdi_audio_stop_all();
  2467.             }
  2468.             break;
  2469.         case MMI_ALERT_NONE:
  2470.         case MMI_SILENT:
  2471.             break;
  2472.         default: /* set default as MMI_RING */
  2473.             if (g_voip_cntx_p->call_alert_info.ringtoneId < MAX_TONE_ID)
  2474.             {
  2475.                 AudioStopReq(g_voip_cntx_p->call_alert_info.ringtoneId);
  2476.             }
  2477.             else
  2478.             {
  2479.                 mdi_audio_stop_all();
  2480.             }            
  2481.             break;
  2482.     }
  2483. }
  2484. /*****************************************************************************
  2485.  * FUNCTION
  2486.  *  mmi_voip_play_vibration_then_ring
  2487.  * DESCRIPTION
  2488.  *  Start playing ring tone after vibration timer is expired.
  2489.  * PARAMETERS
  2490.  *  void
  2491.  * RETURNS
  2492.  *  void
  2493.  *****************************************************************************/
  2494. void mmi_voip_play_vibration_then_ring(void)
  2495. {
  2496.     /*----------------------------------------------------------------*/
  2497.     /* Local Variables                                                */
  2498.     /*----------------------------------------------------------------*/
  2499.     
  2500.     /*----------------------------------------------------------------*/
  2501.     /* Code Body                                                      */
  2502.     /*----------------------------------------------------------------*/
  2503.     StopTimer(CM_ALERT_NOTIFYDURATION_TIMER);
  2504.     VibratorOff();
  2505.     AudioPlayToneWithCallBack(g_voip_cntx_p->call_alert_info.ringtoneId, GetRingTypeEnum(), INCOMING_CALL_TONE);
  2506. }
  2507. /*****************************************************************************
  2508.  * FUNCTION
  2509.  *  mmi_voip_play_waitingtone
  2510.  * DESCRIPTION
  2511.  *  Start playing waiting tone for incoming call.
  2512.  *  It should be called after incoming call screen displays.
  2513.  * PARAMETERS
  2514.  *  void
  2515.  * RETURNS
  2516.  *  void
  2517.  *****************************************************************************/
  2518. void mmi_voip_play_waitingtone(void)
  2519. {
  2520.     /*----------------------------------------------------------------*/
  2521.     /* Local Variables                                                */
  2522.     /*----------------------------------------------------------------*/
  2523.     
  2524.     /*----------------------------------------------------------------*/
  2525.     /* Code Body                                                      */
  2526.     /*----------------------------------------------------------------*/
  2527.     AudioPlayToneWithCallBack(TONE_CALL_WAITING, GetRingTypeEnum(), INCOMING_CALL_TONE);
  2528. }
  2529. /*****************************************************************************
  2530.  * FUNCTION
  2531.  *  mmi_voip_stop_waitingtone
  2532.  * DESCRIPTION
  2533.  *  Stop playing waiting tone for incoming call.
  2534.  *  It should be called before incoming call screen disappears.
  2535.  * PARAMETERS
  2536.  *  void
  2537.  * RETURNS
  2538.  *  void
  2539.  *****************************************************************************/
  2540. void mmi_voip_stop_waitingtone(void)
  2541. {
  2542.     /*----------------------------------------------------------------*/
  2543.     /* Local Variables                                                */
  2544.     /*----------------------------------------------------------------*/
  2545.     
  2546.     /*----------------------------------------------------------------*/
  2547.     /* Code Body                                                      */
  2548.     /*----------------------------------------------------------------*/
  2549.     AudioStopReq(TONE_CALL_WAITING);
  2550. }
  2551. #endif /* __MMI_VOIP__ */