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

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.  * NITZ.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements interface and message handler for NITZ.
  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.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  *------------------------------------------------------------------------------
  168.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  169.  *============================================================================
  170.  ****************************************************************************/
  171. /**
  172.  * Copyright Notice
  173.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  174.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  175.  *  (It is illegal to remove this copyright notice from this software or any
  176.  *  portion of it)
  177.  */
  178. /**************************************************************
  179.    FILENAME : NITZ.c
  180.    PURPOSE     : NITZ Source File
  181.    REMARKS     : nil
  182.    AUTHOR      : Restructured by Gurinder
  183.    DATE     : Restructured on Dec-01-2003
  184. **************************************************************/
  185. #ifndef _MMI_NITZ_C
  186. #define _MMI_NITZ_C
  187. #include "MMI_features.h"
  188. #if defined(__MMI_NITZ__)
  189. #include "NITZ.h"
  190. #include "Stdc.h"
  191. #include "L4Dr1.h"
  192. #include "L4Dr.h"
  193. #include "EventsGprot.h"
  194. #include "CustDataRes.h"
  195. #include "HistoryGprot.h"
  196. #include "wgui_categories.h"
  197. #include "Unicodexdcl.h"
  198. #include "DateTimeGprot.h"
  199. #include "GlobalDefs.h"
  200. #include "ProtocolEvents.h"
  201. #include "SettingGprots.h"
  202. #include "NVRAMType.h"
  203. #include "NVRAMProt.h"
  204. #include "NVRAMEnum.h"
  205. #include "KeyBrd.h"
  206. #include "SettingProfile.h"
  207. #include "gpioInc.h"
  208. #include "SettingProt.h"
  209. #include "IdleAppDef.h"
  210. #include "PhoneSetupGprots.h"
  211. #include "SimDetectionDef.h"
  212. #include "SimDetectionGexdcl.h"
  213. #include "CallsDefs.h"
  214. #ifdef __MMI_NITZ_TZ_SUPPORT__
  215. #include "worldclock.h"
  216. #include "app_datetime.h"
  217. #include "DatetimeGprot.h"
  218. #endif /* __MMI_NITZ_TZ_SUPPORT__ */ 
  219. /* 
  220.  * Define
  221.  */
  222. #define NITZ_SIGN_BIT   0x08
  223. #define NITZ_HIGH_BIT   0xF0
  224. #define NITZ_LOW_BIT 0x0F
  225. #define NITZ_TZ_BIT  0x07
  226. #define NITZ_TIME_LEN      20*ENCODING_LENGTH
  227. #define NITZ_MAX_ALLOW_DIFF   15
  228. /* 
  229.  * Typedef 
  230.  */
  231. /* 
  232.  * Local Variable
  233.  */
  234. nitz_context_struct g_nitz_cntx;
  235. static S16 nitzTempTZ;
  236. #ifdef __MMI_NITZ_TZ_SUPPORT__
  237. static S16 nitzTempDST;
  238. #endif /* __MMI_NITZ_TZ_SUPPORT__ */ 
  239. /* 
  240.  * Local Function
  241.  */
  242. /* 
  243.  * Global Variable
  244.  */
  245. extern wgui_inline_item wgui_inline_items[];
  246. extern MYTIME MyTime;
  247. extern rtc_format_struct gclockData;
  248. /* 
  249.  * Global Function
  250.  */
  251. extern void PhnsetSetDT(void);
  252. extern void EntryPhnsetTimeAndDate(void);
  253. extern void EntryIdleScreen(void);
  254. extern FLOAT GetTimeZone(U8 cityIndex);
  255. extern void EntryPhnsetSetDT(void);
  256. extern void mmi_idle_update_opname_from_nitz(void);
  257. /*****************************************************************************
  258.  * FUNCTION
  259.  *  NITZHandlerInit
  260.  * DESCRIPTION
  261.  *  NITZ Initlization function,
  262.  *  Set the global variable of NITZ to default and register NITZ indication handler.
  263.  * PARAMETERS
  264.  *  void
  265.  * RETURNS
  266.  *  void
  267.  *****************************************************************************/
  268. void NITZHandlerInit(void)
  269. {
  270.     /*----------------------------------------------------------------*/
  271.     /* Local Variables                                                */
  272.     /*----------------------------------------------------------------*/
  273.     S16 error;
  274.     
  275.     /*----------------------------------------------------------------*/
  276.     /* Code Body                                                      */
  277.     /*----------------------------------------------------------------*/
  278.     SetProtocolEventHandler(NITZHandler, PRT_MSG_ID_MMI_NW_TIME_ZONE_IND);
  279.     memset(&g_nitz_cntx, 0, sizeof(nitz_context_struct));
  280.     g_nitz_cntx.NITZTimeZone = (S16) 0xffff;
  281.     /* init PLMN */
  282.     mmi_nitz_get_nitz_nw_name(NULL, g_nitz_cntx.NWShortName, MAX_NW_LEN *ENCODING_LENGTH, NULL);
  283. #ifdef __MMI_NITZ_TZ_SUPPORT__    
  284.     /* init timezone */
  285.     ReadValue(NVRAM_TIMEZONE, &(g_nitz_cntx.NITZTimeZone), DS_SHORT, &error);
  286.     
  287.     /* init dst */
  288.     ReadValue(NVRAM_SETTING_DT_DST, &(g_nitz_cntx.NITZDST), DS_BYTE, &error);
  289. #endif /* __MMI_NITZ_TZ_SUPPORT__ */    
  290. }
  291. /*****************************************************************************
  292.  * FUNCTION
  293.  *  NITZHandler
  294.  * DESCRIPTION
  295.  *  NITZ Inidcation Handler, Thi function checks the diffrence in time zone,
  296.  *  if diffrence is not zero, it set NITZ occurance to true and entry NITZ screen.
  297.  * PARAMETERS
  298.  *  msg     [?]     
  299.  * RETURNS
  300.  *  void
  301.  *****************************************************************************/
  302. void NITZHandler(void *msg)
  303. {
  304.     /*----------------------------------------------------------------*/
  305.     /* Local Variables                                                */
  306.     /*----------------------------------------------------------------*/
  307.     mmi_nw_time_zone_ind_struct *msgReq;
  308.     MYTIME refTime1;
  309.     FLOAT NetTimeZone;
  310.     U8 updateShortNW = 0, updateFullNW = 0;
  311.     /*----------------------------------------------------------------*/
  312.     /* Code Body                                                      */
  313.     /*----------------------------------------------------------------*/
  314.     memset(&refTime1, 0, sizeof(MYTIME));
  315.     if (!PhnsetGetNITZFuncStatus())
  316.     {
  317.         return;
  318.     }
  319.     msgReq = (mmi_nw_time_zone_ind_struct*) msg;
  320.     if (msgReq->nw_time_zone_timeP)
  321.     {
  322.         /* compare network timezone and last recevied timezone */
  323.         refTime1.nYear = NITZConvertTime(msgReq->nw_time_zone_time.year) + YEARFORMATE;
  324.         refTime1.nMonth = NITZConvertTime(msgReq->nw_time_zone_time.month);
  325.         refTime1.nDay = NITZConvertTime(msgReq->nw_time_zone_time.day);
  326.         refTime1.nHour = NITZConvertTime(msgReq->nw_time_zone_time.hour);
  327.         refTime1.nMin = NITZConvertTime(msgReq->nw_time_zone_time.min);
  328.         refTime1.nSec = NITZConvertTime(msgReq->nw_time_zone_time.sec);
  329.         nitzTempTZ = NITZGetTimeZone(msgReq->nw_time_zone_time.time_zone);
  330.         NetTimeZone = (FLOAT) nitzTempTZ;
  331.         NetTimeZone /= 4;
  332.         mmi_dt_utc_to_rtc(NetTimeZone, refTime1, g_nitz_cntx.NITZTime);
  333.     }
  334. #ifdef __MMI_NITZ_TZ_SUPPORT__
  335.     /* Time Zone Support */
  336.     if (msgReq->nw_time_zoneP)
  337.     {
  338.         g_nitz_cntx.TimeZoneP = MMI_TRUE;
  339.         nitzTempTZ = NITZGetTimeZone(msgReq->nw_time_zone);
  340.     }
  341.     else
  342.     {
  343.         g_nitz_cntx.TimeZoneP = MMI_FALSE;
  344.     }
  345.     /* DST Support */
  346.     if (msgReq->nw_day_light_saving_timeP)
  347.     {
  348.         nitzTempDST = msgReq->nw_day_light_saving_time & 0x03;
  349.     }
  350.     else
  351.     {
  352.         nitzTempDST = 0;
  353.     }
  354. #endif
  355.     if (msgReq->short_nw_nameP)
  356.     {
  357.         updateShortNW = mmi_nitz_get_nw_name(
  358.                             msgReq->short_nw_name_dcs,
  359.                             msgReq->short_nw_name_len,
  360.                             (BOOL) msgReq->short_nw_name_add_ci,
  361.                             (S8*) g_nitz_cntx.NWShortName,
  362.                             (S8*) msgReq->short_nw_name);
  363.     }
  364.     else    /* no time information, return */
  365.     {
  366.         memset(g_nitz_cntx.NWShortName, 0, MAX_NW_LEN * ENCODING_LENGTH);
  367.     }
  368.     if (msgReq->short_nw_name_len == 0 && msgReq->full_nw_nameP)
  369.     {
  370.         updateFullNW = mmi_nitz_get_nw_name(
  371.                         msgReq->full_nw_name_dcs,
  372.                         msgReq->full_nw_name_len,
  373.                         (BOOL) msgReq->full_nw_name_add_ci,
  374.                         (S8*) g_nitz_cntx.NWFullName,
  375.                         (S8*) msgReq->full_nw_name);
  376.     }
  377.     else
  378.     {
  379.         memset(g_nitz_cntx.NWFullName, 0, MAX_NW_LEN * ENCODING_LENGTH);
  380.     }
  381.     
  382.     DTGetRTCTime(&g_nitz_cntx.RecvTime);
  383.         
  384.     /* if the nitz does not include information we support, return directly */
  385.     if (!mmi_nitz_check_dt()
  386. #ifdef __MMI_NITZ_TZ_SUPPORT__
  387.         && !mmi_nitz_check_tz()
  388. #endif 
  389.         )
  390.     {
  391.         /* if short name matched, it means short name has been displayed in idle screen */
  392.         if (updateShortNW == MMI_FALSE && updateFullNW == MMI_FALSE)
  393.         {
  394.             return;
  395.         }        
  396.         
  397.     }
  398.     g_nitz_cntx.IsNITZPending = MMI_TRUE;
  399.     if (g_idle_context.IsOnIdleScreen)
  400.     {
  401. EntryIdleScreen();
  402.     }
  403. }
  404. /*****************************************************************************
  405.  * FUNCTION
  406.  *  mmi_nitz_get_nw_name
  407.  * DESCRIPTION
  408.  *  This function is used to get NITZ network name.
  409.  * PARAMETERS
  410.  *  dcs         [IN]        
  411.  *  len         [IN]        
  412.  *  add_ci      [IN]        
  413.  *  dstStr      [?]         
  414.  *  srcStr      [?]         
  415.  * RETURNS
  416.  *  void
  417.  *****************************************************************************/
  418. U8 mmi_nitz_get_nw_name(U8 dcs, U8 len, BOOL add_ci, S8 *dstStr, S8 *srcStr)
  419. {
  420.     /*----------------------------------------------------------------*/
  421.     /* Local Variables                                                */
  422.     /*----------------------------------------------------------------*/
  423.     S8 *nwStr, *tmpStr, *tempStr2;
  424.     U8 count = 0;
  425.     /*----------------------------------------------------------------*/
  426.     /* Code Body                                                      */
  427.     /*----------------------------------------------------------------*/
  428.     if (len == 0)
  429.     {
  430. if (pfnUnicodeStrlen((S8*)dstStr) > 0)
  431.         {
  432.             memset(dstStr, 0, MAX_NW_LEN * ENCODING_LENGTH);
  433.             return MMI_TRUE;
  434.         }
  435.         else
  436.         {
  437.             return MMI_FALSE;
  438.         }
  439.     }
  440.     nwStr = OslMalloc(MAX_NW_LEN * ENCODING_LENGTH);
  441.     memset(nwStr, 0, MAX_NW_LEN * ENCODING_LENGTH);
  442.     switch (dcs)
  443.     {
  444.         case SMSAL_DEFAULT_DCS:
  445.             AnsiiNToUnicodeString(nwStr, srcStr, (U32) MAX_NW_LEN);
  446.             break;
  447.         case SMSAL_UCS2_DCS:
  448.             memcpy(nwStr, srcStr, MAX_NW_LEN * ENCODING_LENGTH);
  449.         default:
  450.             break;
  451.     }
  452.     g_nitz_cntx.AddCI = add_ci;
  453.     /* compare PLMN name */
  454.     tmpStr = dstStr;
  455.     tempStr2 = nwStr;
  456.     while (count < MAX_NW_LEN)
  457.     {
  458.         count++;
  459.         if ((*tmpStr == *tempStr2) && (*(tmpStr + 1) == *(tempStr2 + 1)))
  460.         {
  461.             tmpStr += 2;
  462.             tempStr2 += 2;
  463.         }
  464.         else
  465.         {
  466.             break;
  467.         }
  468.     }   /* End of while */
  469.     if (count < MAX_NW_LEN)
  470.     {
  471.         memcpy(dstStr, nwStr, MAX_NW_LEN * ENCODING_LENGTH);
  472.         OslMfree(nwStr);
  473.         return MMI_TRUE;
  474.     }
  475.     else
  476.     {
  477.         OslMfree(nwStr);
  478.         return MMI_FALSE;
  479.     }
  480. }
  481. /*****************************************************************************
  482.  * FUNCTION
  483.  *  EntryNitzScreen
  484.  * DESCRIPTION
  485.  *  Show the NITZ chnage in time popup,
  486.  *  if NITZ happend and control is on the idle screen.
  487.  * PARAMETERS
  488.  *  void
  489.  * RETURNS
  490.  *  void
  491.  *****************************************************************************/
  492. void EntryNitzScreen(void)
  493. {
  494.     /*----------------------------------------------------------------*/
  495.     /* Local Variables                                                */
  496.     /*----------------------------------------------------------------*/
  497.     U8 *guiBuffer;
  498.     /*----------------------------------------------------------------*/
  499.     /* Code Body                                                      */
  500.     /*----------------------------------------------------------------*/
  501.     EntryNewScreen(SCR_ID_NITZ, ExitNitzScreen, NULL, NULL);
  502.     ClearKeyEvents();
  503.     guiBuffer = GetCurrGuiBuffer(SCR_ID_NITZ);
  504.     NITZMessageString();
  505.     if (g_keylock_context.gKeyPadLockFlag == 0)
  506.     {
  507.         /* start the back light */
  508.         TurnOnBacklight(1);
  509.         ShowCategory7Screen(
  510.             CHANGE_TIME_CAPTION,
  511.             CHANGE_TIME_IMAGE,
  512.             STR_GLOBAL_YES,
  513.             IMG_GLOBAL_YES,
  514.             STR_GLOBAL_NO,
  515.             IMG_GLOBAL_NO,
  516.             (U8*) g_nitz_cntx.Message,
  517.             guiBuffer);
  518.         playRequestedTone(GENERAL_TONE);
  519.         SetLeftSoftkeyFunction(NITZAccept, KEY_EVENT_UP);
  520.         SetRightSoftkeyFunction(NITZIgnore, KEY_EVENT_UP);
  521.         SetKeyHandler(NITZIgnore, KEY_END, KEY_EVENT_DOWN);
  522.     }
  523.     else
  524.     {
  525.         ShowCategory141Screen(
  526.             0,
  527.             0,
  528.             g_keylock_context.KeyLockLSKStringID,
  529.             g_keylock_context.KeyLockLSKIconID,
  530.             g_keylock_context.KeyLockRSKStringID,
  531.             g_keylock_context.KeyLockRSKIconID,
  532.             (U8*) g_nitz_cntx.Message,
  533.             0,
  534.             NULL);
  535.         OslMfree(g_nitz_cntx.Message);
  536.         g_nitz_cntx.Message = NULL;
  537.     }
  538. }
  539. /*****************************************************************************
  540.  * FUNCTION
  541.  *  ExitNitzScreen
  542.  * DESCRIPTION
  543.  *  Exit function of NITZ screen, free memory.
  544.  * PARAMETERS
  545.  *  void
  546.  * RETURNS
  547.  *  void
  548.  *****************************************************************************/
  549. void ExitNitzScreen(void)
  550. {
  551.     /*----------------------------------------------------------------*/
  552.     /* Local Variables                                                */
  553.     /*----------------------------------------------------------------*/
  554.     /*----------------------------------------------------------------*/
  555.     /* Code Body                                                      */
  556.     /*----------------------------------------------------------------*/
  557.     if (g_nitz_cntx.Message != NULL)
  558.     {
  559.         OslMfree(g_nitz_cntx.Message);
  560.         g_nitz_cntx.Message = NULL;
  561.     }
  562. }
  563. /*****************************************************************************
  564.  * FUNCTION
  565.  *  NITZIgnore
  566.  * DESCRIPTION
  567.  *  RSK handler of NITZ screen.
  568.  * PARAMETERS
  569.  *  void
  570.  * RETURNS
  571.  *  void
  572.  *****************************************************************************/
  573. void NITZIgnore(void)
  574. {
  575.     /*----------------------------------------------------------------*/
  576.     /* Local Variables                                                */
  577.     /*----------------------------------------------------------------*/
  578.     /*----------------------------------------------------------------*/
  579.     /* Code Body                                                      */
  580.     /*----------------------------------------------------------------*/
  581.     g_nitz_cntx.IsNITZPending = FALSE;
  582.     GoBackHistory();
  583. }
  584. /*****************************************************************************
  585.  * FUNCTION
  586.  *  NITZAccept
  587.  * DESCRIPTION
  588.  *  This API calls on pressing OK on NITZ indication screen.
  589.  *  This API fills the time and date set screen and passes control to the same screen.
  590.  * PARAMETERS
  591.  *  void
  592.  * RETURNS
  593.  *  void
  594.  *****************************************************************************/
  595. void NITZAccept(void)
  596. {
  597.     /*----------------------------------------------------------------*/
  598.     /* Local Variables                                                */
  599.     /*----------------------------------------------------------------*/
  600.     MYTIME currTime;
  601.     MYTIME incTime;
  602.     nitz_nw_name_struct nw_name; 
  603.     S16 error;
  604. #ifdef __MMI_NITZ_TZ_SUPPORT__
  605.     MYTIME resultTime;
  606.     FLOAT nitz_tz, diff_tz;    
  607. #endif 
  608.     /*----------------------------------------------------------------*/
  609.     /* Code Body                                                      */
  610.     /*----------------------------------------------------------------*/
  611.     DTGetRTCTime(&currTime);
  612.     memset(&nw_name, 0, sizeof(nitz_nw_name_struct));
  613.     if (mmi_nitz_check_dt())
  614.     {
  615.         g_nitz_cntx.NITZTimeZone = nitzTempTZ;
  616.     memset(&incTime, 0, sizeof(MYTIME));
  617.     GetTimeDifference(&currTime, &g_nitz_cntx.RecvTime, &incTime);
  618.     IncrementTime(g_nitz_cntx.NITZTime, incTime, &(g_nitz_cntx.NITZTime));
  619.     #ifdef __MMI_NITZ_TZ_SUPPORT__
  620.         /* set time zone */
  621.         mmi_wc_set_home_city_from_nitz((S16) (g_nitz_cntx.NITZTimeZone - (g_nitz_cntx.NITZDST * 4)));
  622.         mmi_dt_set_dst((U8) g_nitz_cntx.NITZDST);
  623.     #endif /* __MMI_NITZ_TZ_SUPPORT__ */ 
  624.         SetProtocolEventHandler(mmi_nitz_time_res_rsp, HW_SET_TIME_REQ_SUCCESS);
  625.         mmi_dt_set_rtc_dt(&g_nitz_cntx.NITZTime);
  626.     }
  627. #ifdef __MMI_NITZ_TZ_SUPPORT__
  628.     else if (mmi_nitz_check_tz())
  629.     {
  630.         g_nitz_cntx.NITZTimeZone = nitzTempTZ;
  631.         g_nitz_cntx.NITZDST = nitzTempDST;
  632.         nitz_tz = (FLOAT) nitzTempTZ;
  633.         nitz_tz /= 4;
  634.         diff_tz = nitz_tz - GetTimeZone(PhnsetGetHomeCity());
  635.         /* turn DST off */
  636.         if (applib_dt_is_dst_enabled() == MMI_TRUE && g_nitz_cntx.NITZDST == 0)
  637.         {
  638.             diff_tz -= 1;
  639.         }
  640. #ifndef MMI_ON_WIN32
  641.         applib_dt_utc_to_rtc(diff_tz, (applib_time_struct*) & currTime, (applib_time_struct*) &resultTime);
  642. #else
  643. resultTime = mmi_dt_utc_to_rtc(diff_tz,  currTime);
  644. #endif        
  645.         memcpy(&(g_nitz_cntx.NITZTime), &resultTime, sizeof(MYTIME));
  646.         /* set time zone */
  647.         mmi_wc_set_home_city_from_nitz((S16) (g_nitz_cntx.NITZTimeZone - (g_nitz_cntx.NITZDST * 4)));
  648.         mmi_dt_set_dst((U8) g_nitz_cntx.NITZDST);
  649.         mmi_dt_set_rtc_dt(&g_nitz_cntx.NITZTime);
  650.     }
  651. #endif /* __MMI_NITZ_TZ_SUPPORT__ */ 
  652.     if (strlen((S8*) g_nitz_cntx.NWShortName) != 0)
  653.     {
  654.         memcpy(&(nw_name.plmn),gPLMN, MAX_PLMN_LEN_MMI);
  655.         memcpy(&(nw_name.name), &g_nitz_cntx.NWShortName, MAX_NW_LEN *ENCODING_LENGTH);
  656.         nw_name.add_ci = (U8) g_nitz_cntx.AddCI;
  657.         WriteRecord(NVRAM_EF_NITZ_NW_NAME_LID, 1, &nw_name, sizeof(nitz_nw_name_struct), &error);
  658.         
  659.         mmi_idle_update_opname_from_nitz();
  660.     }
  661.     else if (strlen((S8*) g_nitz_cntx.NWFullName) != 0)
  662.     {
  663.         memcpy(&(nw_name.plmn),gPLMN, MAX_PLMN_LEN_MMI);    
  664.         memcpy(&nw_name.name, &g_nitz_cntx.NWFullName, MAX_NW_LEN *ENCODING_LENGTH);
  665.         nw_name.add_ci = (U8) g_nitz_cntx.AddCI;
  666.         WriteRecord(NVRAM_EF_NITZ_NW_NAME_LID, 1, &nw_name, sizeof(nitz_nw_name_struct), &error);
  667.         
  668.         mmi_idle_update_opname_from_nitz();
  669.     }
  670.     else
  671.     {
  672.         memset(&(nw_name.plmn),0, MAX_PLMN_LEN_MMI);    
  673.         memset(&nw_name.name, 0, MAX_NW_LEN *ENCODING_LENGTH);
  674.         nw_name.add_ci = 0;
  675.         WriteRecord(NVRAM_EF_NITZ_NW_NAME_LID, 1, &nw_name, sizeof(nitz_nw_name_struct), &error);
  676.         
  677.         mmi_idle_update_opname_from_nitz();
  678.     }
  679.     g_nitz_cntx.IsNITZPending = FALSE;
  680. GoBackHistory();
  681. }
  682. /*****************************************************************************
  683.  * FUNCTION
  684.  *  mmi_nitz_get_nitz_nw_name
  685.  * DESCRIPTION
  686.  *  This API read nitz netowrk name information from NVRAM
  687.  * PARAMETERS
  688.  *  void
  689.  * RETURNS
  690.  *  void
  691.  *****************************************************************************/
  692. void mmi_nitz_get_nitz_nw_name(U8* plmn, U8* nwname, U8 len, BOOL* add_ci)
  693. {
  694.     nitz_nw_name_struct nw_name; 
  695.     S16 error;
  696.     
  697.     ReadRecord(NVRAM_EF_NITZ_NW_NAME_LID, 1, &nw_name, sizeof(nitz_nw_name_struct), &error);
  698.     if (plmn != NULL)
  699.     {
  700.         memcpy(plmn, nw_name.plmn, MAX_PLMN_LEN_MMI);
  701.     }
  702.     if (nwname != NULL)
  703.     {
  704. pfnUnicodeStrncpy((S8*) nwname, (S8*)nw_name.name, len);
  705.     }
  706.     if (add_ci != NULL)
  707.     {
  708.         memcpy(add_ci, &(nw_name.add_ci), sizeof(U8));    
  709.     }
  710. }
  711. /*****************************************************************************
  712.  * FUNCTION
  713.  *  mmi_nitz_check_dt
  714.  * DESCRIPTION
  715.  *  
  716.  *  This function is used to check if the date/time need to be updated from NITZ.
  717.  * PARAMETERS
  718.  *  void
  719.  * RETURNS
  720.  *  void
  721.  *****************************************************************************/
  722. U8 mmi_nitz_check_dt()
  723. {
  724.     /*----------------------------------------------------------------*/
  725.     /* Local Variables                                                */
  726.     /*----------------------------------------------------------------*/
  727.     MYTIME refTime1, refTime2, incTime;
  728.     /*----------------------------------------------------------------*/
  729.     /* Code Body                                                      */
  730.     /*----------------------------------------------------------------*/
  731.     memset(&incTime, 0, sizeof(MYTIME));
  732.     memset(&refTime1, 0, sizeof(MYTIME));
  733.     memset(&refTime2, 0, sizeof(MYTIME));
  734.     incTime.nMin = NITZ_MAX_ALLOW_DIFF;
  735.     IncrementTime(g_nitz_cntx.RecvTime, incTime, &refTime1);
  736.     DecrementTime(g_nitz_cntx.RecvTime, incTime, &refTime2);
  737.     if (!mmi_dt_is_valid(&g_nitz_cntx.NITZTime))
  738.         return MMI_FALSE;
  739. else if ((CompareTime(g_nitz_cntx.NITZTime, refTime1, NULL) == TIME_LESS) &&
  740.              (CompareTime(g_nitz_cntx.NITZTime, refTime2, NULL) == TIME_GREATER))
  741.         return MMI_FALSE;
  742. #ifdef __MMI_CHECK_DUPLICATED_NITZ__
  743.     else if (nitzTempTZ == g_nitz_cntx.NITZTimeZone)
  744.         return MMI_FALSE;
  745. #endif    
  746.     else
  747.         return MMI_TRUE;
  748. }
  749. #ifdef __MMI_NITZ_TZ_SUPPORT__
  750. /*****************************************************************************
  751.  * FUNCTION
  752.  *  mmi_nitz_check_tz
  753.  * DESCRIPTION
  754.  *  
  755.  * PARAMETERS
  756.  *  void
  757.  * RETURNS
  758.  *  
  759.  *****************************************************************************/
  760. U8 mmi_nitz_check_tz(void)
  761. {
  762.     /*----------------------------------------------------------------*/
  763.     /* Local Variables                                                */
  764.     /*----------------------------------------------------------------*/
  765.     /*----------------------------------------------------------------*/
  766.     /* Code Body                                                      */
  767.     /*----------------------------------------------------------------*/
  768.     /* Need to update time zone */
  769.     if (g_nitz_cntx.TimeZoneP == MMI_TRUE)
  770.     {
  771.         if (nitzTempTZ != g_nitz_cntx.NITZTimeZone || nitzTempDST != g_nitz_cntx.NITZDST)
  772.         {
  773.             return MMI_TRUE;
  774.         }
  775.     }
  776.     return MMI_FALSE;
  777. }
  778. #endif /* __MMI_NITZ_TZ_SUPPORT__ */ 
  779. /*****************************************************************************
  780.  * FUNCTION
  781.  *  NITZMessageString
  782.  * DESCRIPTION
  783.  *  Return the new time zone string, need to be display using in IDLE screen.
  784.  * PARAMETERS
  785.  *  void
  786.  * RETURNS
  787.  *  void
  788.  *****************************************************************************/
  789. S8 *NITZMessageString(void)
  790. {
  791.     /*----------------------------------------------------------------*/
  792.     /* Local Variables                                                */
  793.     /*----------------------------------------------------------------*/
  794.     S8 *tmpStr;
  795.     /*----------------------------------------------------------------*/
  796.     /* Code Body                                                      */
  797.     /*----------------------------------------------------------------*/
  798.     if (g_nitz_cntx.Message == NULL)
  799.     {
  800.         g_nitz_cntx.Message = OslMalloc(NITZ_NOTIFY_LENGTH);
  801.     }
  802.     tmpStr = GetString(NITZTIMECHANGESTR);
  803.     pfnUnicodeStrncpy((S8*) g_nitz_cntx.Message, tmpStr, pfnUnicodeStrlen((S8*) tmpStr));
  804.     return g_nitz_cntx.Message;
  805. }
  806. /*****************************************************************************
  807.  * FUNCTION
  808.  *  NITZTimeZoneString
  809.  * DESCRIPTION
  810.  *  
  811.  * PARAMETERS
  812.  *  timezone        [IN]        
  813.  *  string          [?]         
  814.  * RETURNS
  815.  *  void
  816.  *****************************************************************************/
  817. void NITZTimeZoneString(S16 timezone, S8 *string)
  818. {
  819.     /*----------------------------------------------------------------*/
  820.     /* Local Variables                                                */
  821.     /*----------------------------------------------------------------*/
  822.     S8 tmpBuff[NITZ_TIME_LEN];
  823.     /*----------------------------------------------------------------*/
  824.     /* Code Body                                                      */
  825.     /*----------------------------------------------------------------*/
  826.     if (timezone < 0)
  827.     {
  828.         timezone = 0 - timezone;
  829.         sprintf(tmpBuff, "-%02d:%02d", (timezone / 4), (timezone % 4) * 15);
  830.     }
  831.     else
  832.     {
  833.         sprintf(tmpBuff, "+%02d:%02d", (timezone / 4), (timezone % 4) * 15);
  834.     }
  835.     AnsiiToUnicodeString(string, tmpBuff);
  836. }
  837. /*****************************************************************************
  838.  * FUNCTION
  839.  *  NITZConvertTime
  840.  * DESCRIPTION
  841.  *  Utility function require by NITZ to convert BCD Date to decimal.
  842.  * PARAMETERS
  843.  *  time        [IN]        
  844.  * RETURNS
  845.  *  void
  846.  *****************************************************************************/
  847. U8 NITZConvertTime(U8 time)
  848. {
  849.     /*----------------------------------------------------------------*/
  850.     /* Local Variables                                                */
  851.     /*----------------------------------------------------------------*/
  852.     U8 tmp1 = 0, tmp2 = 0;
  853.     /*----------------------------------------------------------------*/
  854.     /* Code Body                                                      */
  855.     /*----------------------------------------------------------------*/
  856.     tmp1 = time & NITZ_HIGH_BIT;
  857.     tmp1 = tmp1 >> 4;
  858.     tmp2 = time & NITZ_LOW_BIT;
  859.     return tmp2 * 10 + tmp1;
  860. }
  861. /*****************************************************************************
  862.  * FUNCTION
  863.  *  NITZGetTimeZone
  864.  * DESCRIPTION
  865.  *  Utility function require by NITZ to convert BCD Date to decimal.
  866.  * PARAMETERS
  867.  *  t       [IN]        
  868.  * RETURNS
  869.  *  void
  870.  *****************************************************************************/
  871. S16 NITZGetTimeZone(U8 t)
  872. {
  873.     /*----------------------------------------------------------------*/
  874.     /* Local Variables                                                */
  875.     /*----------------------------------------------------------------*/
  876.     U8 tmp;
  877.     U8 NegFlag;
  878.     S16 result;
  879.     U8 timezone = t;
  880.     /*----------------------------------------------------------------*/
  881.     /* Code Body                                                      */
  882.     /*----------------------------------------------------------------*/
  883.     tmp = (t & NITZ_HIGH_BIT) >> 4;
  884.     if (t & NITZ_SIGN_BIT)  /* negative */
  885.     {
  886.         NegFlag = TRUE;
  887.     }
  888.     else    /* positive */
  889.     {
  890.         NegFlag = FALSE;
  891.     }
  892.     timezone &= NITZ_TZ_BIT;
  893.     timezone = timezone * 10 + tmp;
  894.     result = (S16) timezone;
  895.     if (NegFlag)
  896.     {
  897.         result = 0 - result;
  898.     }
  899.     return result;
  900. }
  901. /*****************************************************************************
  902.  * FUNCTION
  903.  *  mmi_nitz_time_res_rsp
  904.  * DESCRIPTION
  905.  *  Response of set RTC request.
  906.  * PARAMETERS
  907.  *  t       [IN]        
  908.  * RETURNS
  909.  *  void
  910.  *****************************************************************************/   
  911. void mmi_nitz_time_res_rsp(void *info)
  912. {
  913.     /*----------------------------------------------------------------*/
  914.     /* Local Variables                                                */
  915.     /*----------------------------------------------------------------*/
  916.     RESULTSTRUCT *resp;
  917.     /*----------------------------------------------------------------*/
  918.     /* Code Body                                                      */
  919.     /*----------------------------------------------------------------*/
  920.     resp = (RESULTSTRUCT*) (info);
  921.     if (resp->result == 1)
  922.     {
  923.     #ifdef __MTK_TARGET__
  924.         gclockData.rtc_year = g_nitz_cntx.NITZTime.nYear- YEARFORMATE;
  925.         gclockData.rtc_mon = g_nitz_cntx.NITZTime.nMonth;
  926.         gclockData.rtc_day = g_nitz_cntx.NITZTime.nDay;
  927.         gclockData.rtc_hour = g_nitz_cntx.NITZTime.nHour;
  928.         gclockData.rtc_min = g_nitz_cntx.NITZTime.nMin;
  929.         mmi_dt_check_rtc_time();
  930.     #else /* __MTK_TARGET__ */ 
  931.         MyTime.nHour = g_nitz_cntx.NITZTime.nHour;
  932.         MyTime.nMin = g_nitz_cntx.NITZTime.nMin;
  933.         MyTime.nYear = g_nitz_cntx.NITZTime.nYear;
  934.         MyTime.nMonth = g_nitz_cntx.NITZTime.nMonth;
  935.         MyTime.nDay = g_nitz_cntx.NITZTime.nDay;
  936.         DateTimerProc();
  937.     #endif /* __MTK_TARGET__ */ 
  938.     
  939.         update_mainlcd_dt_display();
  940.         update_sublcd_dt_display();
  941.         AlmReInitialize();
  942.     }
  943. }
  944. #endif /* defined(__MMI_NITZ__) */ 
  945. #endif /* _MMI_NITZ_C */ // #ifndef _MMI_NITZ_C