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

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.  * EONS.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file is created for EONS support (3GPP 51.11 EF OPL/PNN)
  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.  *------------------------------------------------------------------------------
  88.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  89.  *==============================================================================
  90.  *******************************************************************************/
  91. #include "MMI_features.h"
  92. #include "StdC.h"
  93. #include "L4Dr.h"
  94. #include "L4Dr1.h"
  95. #include "ProtocolEvents.h"
  96. #include "PixtelDataTypes.h"
  97. #include "EventsGprot.h"
  98. #include "SimDetectionDef.h"
  99. #include "QueueGProt.h"
  100. #include "GSM7BitDefaultAlphabet.h"
  101. #include "sim_common_enums.h"
  102. #include "DebugInitDef.h"
  103. #include "NVRAMType.h"
  104. #include "NVRAMProt.h"
  105. #include "NVRAMEnum.h"
  106. #include "IdleAppDef.h" /* for g_idle_context */
  107. #include "SimDetectionGexdcl.h" /* for g_pwr_context */
  108. /**************************************************************************
  109.    Pre-definition
  110. **************************************************************************/
  111. #if ( (defined __MMI_EONS_SUPPORT__) && (defined MMI_ON_HARDWARE_P) )
  112. /**************************************************************************
  113.    Definitions
  114. **************************************************************************/
  115. #define MAX_MCC_MNC_LENGTH 3    /* Do not modify this definition */
  116. #define MAX_OPN_PNN_RECORD 24   /* Modify this definition to support more records in EF OPL/PNN */
  117.             /* If this value is larger than 24, NVRAM size should also be modified */
  118. /**************************************************************************
  119.    Structure
  120. **************************************************************************/
  121. typedef struct _eons_plmn_info
  122. {
  123.     S8 pnn_plmn_num[MAX_MCC_MNC_LENGTH + 1];
  124.     U8 pnn_identifier;
  125. } EONSPLMNINFO;
  126. /**************************************************************************
  127.    Global variables
  128. **************************************************************************/
  129. static U8 opl_record_number = 0;    /* total records read from EF OPL */
  130. static U8 opl_record_count = 1;     /* count for how many records which have been read */
  131. static MMI_BOOL opl_read_finish = MMI_FALSE;
  132. static EONSPLMNINFO g_eons_plmn_info[MAX_OPN_PNN_RECORD];
  133. /* diamond, 2006/06/01 Prevent from sending this message twice before get the response */
  134. static U8 eons_got_read_pnn_rsp = 1;
  135. extern U8 gNWProviderName[MAX_LENGTH_DISPLAY_NAME * ENCODING_LENGTH];   /* in SimDetection.c */
  136. extern U8 gPLMN[MAX_PLMN_LEN_MMI];
  137. extern S8 gHomePLMNNum[MAX_PLMN_LEN_MMI + 1];
  138. extern S8 gOperatorName[MAX_LENGTH_OPERATOR_NAME * ENCODING_LENGTH];
  139. extern U8 gOpNameValid;
  140. /**************************************************************************
  141.    Function Prototypes
  142. **************************************************************************/
  143. extern void smsal_gsm7_unpack(
  144.                 kal_uint8 *old_data_ptr,
  145.                 kal_uint8 *new_data_ptr,
  146.                 kal_uint16 data_len,
  147.                 kal_uint16 offset);
  148. extern kal_uint16 smsal_msg_len_in_character(kal_uint8 dcs, kal_uint16 len, kal_uint8 last_byte);
  149. extern kal_bool is_sim_replaced(void);
  150. extern ChangeRoamingState(void);
  151. extern void EntryIdleScreen(void);
  152. extern void RefreshNwProviderName(U8 *);
  153. void eons_convert_plmn_bcd_format_to_string(U8 *, U8 *);
  154. void eons_get_opl_record_req(U8);
  155. void eons_write_opn_to_nvram(void);
  156. void eons_reset_nvram(void);
  157. U8 eons_check_if_plmn_present(U8 *);
  158. /**************************************************************************
  159.    Get records of PNN:
  160.       void eons_retrieve_name_from_table(U8 *data)
  161.       void eons_retrieve_name_from_pnn(U16 length, U8 *data)
  162.       void eons_get_pnn_record_rsp(void *msgPtr)
  163.       void eons_get_pnn_record_req(U8 recordNo)
  164.       void eons_replace_opn_by_pnn_for_hplmn_rsp(void *msgPtr)
  165.       void eons_replace_opn_by_pnn_for_hplmn_req(void)
  166. **************************************************************************/
  167. /*****************************************************************************
  168.  * FUNCTION
  169.  *  eons_retrieve_name_from_table
  170.  * DESCRIPTION
  171.  *  
  172.  * PARAMETERS
  173.  *  buffer      [?]     
  174.  * RETURNS
  175.  *  void
  176.  *****************************************************************************/
  177. void eons_retrieve_name_from_table(U8 *buffer)
  178. {
  179.     /*----------------------------------------------------------------*/
  180.     /* Local Variables                                                */
  181.     /*----------------------------------------------------------------*/
  182.     /*----------------------------------------------------------------*/
  183.     /* Code Body                                                      */
  184.     /*----------------------------------------------------------------*/
  185.     /*
  186.      * U16 count;
  187.      * for(count = 0; count < MAX_PLMN_NO_LIST_LENGTH; ++count)
  188.      * {
  189.      * if(memcmp(sPlmnsToDisplayName[count],gPLMN,strlen((PS8) sPlmnsToDisplayName[count])) == 0)
  190.      * break;
  191.      * }
  192.      * if(count < MAX_PLMN_NO_LIST_LENGTH)
  193.      * memcpy((S8*)gNWProviderName,GetCurrentPLMNName((S8*)sPlmnsToDisplayName[count]),MAX_LENGTH_DISPLAY_NAME * ENCODING_LENGTH);
  194.      * else
  195.      * AnsiiToUnicodeString((S8*)gNWProviderName,(S8*)gPLMN);
  196.      */
  197.     *buffer = 0;    /* null string */
  198. }
  199. /*****************************************************************************
  200.  * FUNCTION
  201.  *  eons_retrieve_name_from_pnn
  202.  * DESCRIPTION
  203.  *  
  204.  * PARAMETERS
  205.  *  length      [IN]        
  206.  *  data        [?]         
  207.  *  buffer      [?]         
  208.  * RETURNS
  209.  *  void
  210.  *****************************************************************************/
  211. void eons_retrieve_name_from_pnn(U16 length, U8 *data, U8 *buffer)
  212. {
  213.     /*----------------------------------------------------------------*/
  214.     /* Local Variables                                                */
  215.     /*----------------------------------------------------------------*/
  216.     /* data[0]: Network IEI */
  217.     /* data[1]: Length   */
  218.     /* data[2]-[n]: Name */
  219.     U8 coding_scheme;
  220.     U8 pnnDecode[MAX_LENGTH_DISPLAY_NAME];
  221.     U8 pnnBuffer[MAX_LENGTH_DISPLAY_NAME];
  222.     /*----------------------------------------------------------------*/
  223.     /* Code Body                                                      */
  224.     /*----------------------------------------------------------------*/
  225.     //U8* pnnDecode = OslMalloc(data[1]*8/7 +1);
  226.     //U8* pnnBuffer = OslMalloc(data[1]);
  227.     memcpy(pnnBuffer, data + 3, data[1] - 1);
  228.     *(pnnBuffer + data[1] - 1) = 0; /* set null-terminated char */
  229.     coding_scheme = (data[2] & 0x70) >> 4;
  230.     if (coding_scheme == 0)
  231.     {
  232.         /* Octets (packed GSM 7-bit default alphabet) in EF PNN  */
  233.         /* smsal_gsm7_unpack(pnnBuffer, pnnDecode, data[1], 0); */
  234.         smsal_gsm7_unpack(pnnBuffer, pnnDecode, smsal_msg_len_in_character(0, data[1], pnnBuffer[data[1]]), 0);
  235.         /* Unicode in display buffer */
  236.         AnsiiToUnicodeString((PS8) buffer, (PS8) pnnDecode);
  237.     }
  238.     else if (coding_scheme == 1)
  239.     {
  240.         /* Octets (UCS2) in EF PNN */
  241.         U8 *convertedData = NULL;
  242.         U8 dcs;
  243.         switch (*pnnBuffer)
  244.         {
  245.             case 0x80:
  246.                 dcs = MMI_UCS2_DCS;
  247.                 break;
  248.             case 0x81:
  249.                 dcs = MMI_UCS2_81;
  250.                 break;
  251.             case 0x82:
  252.                 dcs = MMI_UCS2_82;
  253.                 break;
  254.             default:
  255.                 dcs = 0;
  256.                 break;
  257.         }
  258.         if (dcs == 0)
  259.         {
  260.             eons_retrieve_name_from_table(buffer);
  261.         }
  262.         else
  263.         {
  264.             convertedData = CovertStringForPlatform(pnnBuffer + 1, data[1] - 2, dcs, NULL);
  265.             pfnUnicodeStrcpy((PS8) buffer, (PS8) convertedData);
  266.             OslMfree(convertedData);
  267.         }
  268.     }
  269.     else
  270.     {
  271.         /* unknown format */
  272.         eons_retrieve_name_from_table(buffer);
  273.     }
  274.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[EONS] PNN: %s", pnnDecode));
  275.     //OslMfree(pnnDecode);
  276.     //OslMfree(pnnBuffer);
  277. }
  278. /*****************************************************************************
  279.  * FUNCTION
  280.  *  eons_replace_opn_by_pnn_for_hplmn_rsp
  281.  * DESCRIPTION
  282.  *  
  283.  * PARAMETERS
  284.  *  msgPtr      [?]     
  285.  * RETURNS
  286.  *  void
  287.  *****************************************************************************/
  288. void eons_replace_opn_by_pnn_for_hplmn_rsp(void *msgPtr)
  289. {
  290.     /*----------------------------------------------------------------*/
  291.     /* Local Variables                                                */
  292.     /*----------------------------------------------------------------*/
  293.     mmi_smu_read_sim_rsp_struct *pnnReadSimRes;
  294.     /*----------------------------------------------------------------*/
  295.     /* Code Body                                                      */
  296.     /*----------------------------------------------------------------*/
  297.     pnnReadSimRes = (mmi_smu_read_sim_rsp_struct*) msgPtr;
  298.     ClearProtocolEventHandler(PRT_MMI_SMU_READ_SIM_RSP);
  299.     /* EONS: Get the PLMN name string successfully, and save it to display buffer */
  300.     if (pnnReadSimRes->result.flag == 0)
  301.     {
  302.         eons_retrieve_name_from_pnn(pnnReadSimRes->length, pnnReadSimRes->data, (PU8) gOperatorName);
  303.     }
  304.     /* EONS: To prevent from too many OPL records will delay the time of update NW provider name */
  305.     if (is_sim_replaced() && g_idle_context.IsOnIdleScreen)
  306.     {
  307.         RefreshNwProviderName(gPLMN);
  308.     }
  309. }
  310. /*****************************************************************************
  311.  * FUNCTION
  312.  *  eons_replace_opn_by_pnn_for_hplmn_req
  313.  * DESCRIPTION
  314.  *  
  315.  * PARAMETERS
  316.  *  void
  317.  * RETURNS
  318.  *  void
  319.  *****************************************************************************/
  320. void eons_replace_opn_by_pnn_for_hplmn_req(void)
  321. {
  322.     /*----------------------------------------------------------------*/
  323.     /* Local Variables                                                */
  324.     /*----------------------------------------------------------------*/
  325.     /* U8 recordnum = eons_check_if_plmn_present(gPLMN); */
  326.     U8 homePLMN[MAX_PLMN_LEN_MMI + 1];
  327.     U8 recordnum5digit, recordnum6digit;
  328.     /*----------------------------------------------------------------*/
  329.     /* Code Body                                                      */
  330.     /*----------------------------------------------------------------*/
  331.     memset(homePLMN, 0, MAX_PLMN_LEN_MMI + 1);
  332.     memcpy(homePLMN, gHomePLMNNum, MAX_PLMN_LEN_MMI - 1);
  333.     recordnum5digit = eons_check_if_plmn_present(homePLMN);
  334.     memcpy(homePLMN, gHomePLMNNum, MAX_PLMN_LEN_MMI);
  335.     recordnum6digit = eons_check_if_plmn_present(homePLMN);
  336.     /* if(gOpNameValid && recordnum) */
  337.     if (gOpNameValid == 1 && (recordnum5digit != 0 || recordnum6digit != 0))
  338.     {
  339.         /* EONS: Get the record of EF PNN for Home PLMN */
  340.         MYQUEUE Message;
  341.         mmi_smu_read_sim_req_struct *dataPtr;
  342.         SetProtocolEventHandler(eons_replace_opn_by_pnn_for_hplmn_rsp, PRT_MMI_SMU_READ_SIM_RSP);
  343.         Message.oslSrcId = MOD_MMI;
  344.         Message.oslDestId = MOD_L4C;
  345.         Message.oslMsgId = PRT_MMI_SMU_READ_SIM_REQ;
  346.         dataPtr = (mmi_smu_read_sim_req_struct*) OslConstructDataPtr(sizeof(mmi_smu_read_sim_req_struct));
  347.         dataPtr->file_idx = (U8) FILE_PNN_IDX;  /* PNN...FILE_PNN_IDX */
  348.         /* dataPtr->para=recordnum; */
  349.         dataPtr->para = (recordnum5digit == 0) ? recordnum6digit : recordnum5digit;
  350.         dataPtr->length = MAX_LENGTH_DISPLAY_NAME + 2;
  351.         Message.oslDataPtr = (oslParaType*) dataPtr;
  352.         Message.oslPeerBuffPtr = NULL;
  353.         OslMsgSendExtQueue(&Message);
  354.     }
  355. }
  356. /*****************************************************************************
  357.  * FUNCTION
  358.  *  eons_get_pnn_record_rsp
  359.  * DESCRIPTION
  360.  *  
  361.  * PARAMETERS
  362.  *  msgPtr      [?]     
  363.  * RETURNS
  364.  *  void
  365.  *****************************************************************************/
  366. void eons_get_pnn_record_rsp(void *msgPtr)
  367. {
  368.     /*----------------------------------------------------------------*/
  369.     /* Local Variables                                                */
  370.     /*----------------------------------------------------------------*/
  371.     mmi_smu_read_sim_rsp_struct *pnnReadSimRes;
  372.     /*----------------------------------------------------------------*/
  373.     /* Code Body                                                      */
  374.     /*----------------------------------------------------------------*/
  375.     pnnReadSimRes = (mmi_smu_read_sim_rsp_struct*) msgPtr;
  376.     ClearProtocolEventHandler(PRT_MMI_SMU_READ_SIM_RSP);
  377.     eons_got_read_pnn_rsp = 1;
  378.     /* EONS: Get the PLMN name string successfully, and save it to display buffer */
  379.     if (pnnReadSimRes->result.flag == 0)
  380.     {
  381.         memset(gNWProviderName, 0, MAX_LENGTH_DISPLAY_NAME * ENCODING_LENGTH);
  382.         eons_retrieve_name_from_pnn(pnnReadSimRes->length, pnnReadSimRes->data, (PU8) gNWProviderName);
  383.         ChangeRoamingState();
  384.         if (g_idle_context.IsOnIdleScreen && g_pwr_context.testRoaming == 3)
  385.         {
  386.             EntryIdleScreen();
  387.         }
  388.     }
  389. }
  390. /*****************************************************************************
  391.  * FUNCTION
  392.  *  eons_get_pnn_record_req
  393.  * DESCRIPTION
  394.  *  
  395.  * PARAMETERS
  396.  *  recordNo        [IN]        
  397.  * RETURNS
  398.  *  void
  399.  *****************************************************************************/
  400. void eons_get_pnn_record_req(U8 recordNo)
  401. {
  402.     /*----------------------------------------------------------------*/
  403.     /* Local Variables                                                */
  404.     /*----------------------------------------------------------------*/
  405.     /* EONS: Get the record of EF PNN for camp on PLMN */
  406.     MYQUEUE Message;
  407.     mmi_smu_read_sim_req_struct *dataPtr;
  408.     /*----------------------------------------------------------------*/
  409.     /* Code Body                                                      */
  410.     /*----------------------------------------------------------------*/
  411.     if (eons_got_read_pnn_rsp == 0)
  412.     {
  413.         /* diamond, 2006/06/01 Prevent from sending this message twice before get the response */
  414.         return;
  415.     }
  416.     SetProtocolEventHandler(eons_get_pnn_record_rsp, PRT_MMI_SMU_READ_SIM_RSP);
  417.     eons_got_read_pnn_rsp = 0;
  418.     Message.oslSrcId = MOD_MMI;
  419.     Message.oslDestId = MOD_L4C;
  420.     Message.oslMsgId = PRT_MMI_SMU_READ_SIM_REQ;
  421.     dataPtr = (mmi_smu_read_sim_req_struct*) OslConstructDataPtr(sizeof(mmi_smu_read_sim_req_struct));
  422.     dataPtr->file_idx = (U8) FILE_PNN_IDX;  /* PNN...FILE_PNN_IDX */
  423.     dataPtr->para = (U8) recordNo;
  424.     dataPtr->length = MAX_LENGTH_DISPLAY_NAME + 2;
  425.     Message.oslDataPtr = (oslParaType*) dataPtr;
  426.     Message.oslPeerBuffPtr = NULL;
  427.     OslMsgSendExtQueue(&Message);
  428. }
  429. /**************************************************************************
  430.    Get records of OPL:
  431.       void eons_retrieve_plmn_from_opl(U16 length, U8 *data)
  432.       void eons_get_opl_record_rsp(void *msgPtr)
  433.       void eons_get_opl_record_req(U8 recordNo)
  434. **************************************************************************/
  435. /*****************************************************************************
  436.  * FUNCTION
  437.  *  eons_retrieve_plmn_from_opl
  438.  * DESCRIPTION
  439.  *  
  440.  * PARAMETERS
  441.  *  length      [IN]        
  442.  *  data        [?]         
  443.  * RETURNS
  444.  *  void
  445.  *****************************************************************************/
  446. void eons_retrieve_plmn_from_opl(U16 length, U8 *data)
  447. {
  448.     /*----------------------------------------------------------------*/
  449.     /* Local Variables                                                */
  450.     /*----------------------------------------------------------------*/
  451.     U8 PnnPlmn[MAX_MCC_MNC_LENGTH * 2 + 1];
  452.     /*----------------------------------------------------------------*/
  453.     /* Code Body                                                      */
  454.     /*----------------------------------------------------------------*/
  455.     if (data[7] == 0)
  456.     {
  457.         /* The name shall be taken from other sources, like the list in ME */
  458.         /* Ignore this record and read next */
  459.         opl_record_count--;
  460.         opl_record_number--;
  461.         return;
  462.     }
  463.     /* data[0]-[6]: Location Area Identity (3-byte PLMN + 2-byte LAC * 2) */
  464.     /* data[7]: PLMN Network Name Record Identifier (use this id to search the name in EF PNN */
  465.     g_eons_plmn_info[opl_record_count - 1].pnn_plmn_num[0] = data[0];
  466.     g_eons_plmn_info[opl_record_count - 1].pnn_plmn_num[1] = data[1];
  467.     g_eons_plmn_info[opl_record_count - 1].pnn_plmn_num[2] = data[2];
  468.     /* data[3]-[6] not necessary for MMI */
  469.     g_eons_plmn_info[opl_record_count - 1].pnn_identifier = data[7];
  470.     eons_convert_plmn_bcd_format_to_string((U8*) g_eons_plmn_info[opl_record_count - 1].pnn_plmn_num, PnnPlmn);
  471.     PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[EONS] OPL %02d: %s", opl_record_count, PnnPlmn));
  472. }
  473. /*****************************************************************************
  474.  * FUNCTION
  475.  *  eons_get_opl_record_rsp
  476.  * DESCRIPTION
  477.  *  
  478.  * PARAMETERS
  479.  *  msgPtr      [?]     
  480.  * RETURNS
  481.  *  void
  482.  *****************************************************************************/
  483. void eons_get_opl_record_rsp(void *msgPtr)
  484. {
  485.     /*----------------------------------------------------------------*/
  486.     /* Local Variables                                                */
  487.     /*----------------------------------------------------------------*/
  488.     mmi_smu_read_sim_rsp_struct *oplReadSimRes;
  489.     /*----------------------------------------------------------------*/
  490.     /* Code Body                                                      */
  491.     /*----------------------------------------------------------------*/
  492.     oplReadSimRes = (mmi_smu_read_sim_rsp_struct*) msgPtr;
  493.     ClearProtocolEventHandler(PRT_MMI_SMU_READ_SIM_RSP);
  494.     if (oplReadSimRes->data[0] != 0xFF && opl_record_count < opl_record_number)
  495.     {
  496.         /* EONS: Get the BCD-formated PLMN successfully, and save it to memory */
  497.         if (oplReadSimRes->result.flag == 0)
  498.         {
  499.             eons_retrieve_plmn_from_opl(oplReadSimRes->length, oplReadSimRes->data);
  500.         }
  501.         /* EONS: Get next one */
  502.         eons_get_opl_record_req(++opl_record_count);
  503.     }
  504.     else
  505.     {
  506.         /* EONS: following records are invalid */
  507.         opl_read_finish = MMI_TRUE;
  508.         if (oplReadSimRes->data[0] == 0xFF)
  509.         {
  510.             opl_record_count--; /* invalid one */
  511.         }
  512.         if (opl_record_count == opl_record_number && oplReadSimRes->result.flag == 0)
  513.         {
  514.             eons_retrieve_plmn_from_opl(oplReadSimRes->length, oplReadSimRes->data);    /* the max supported record */
  515.         }
  516.         eons_write_opn_to_nvram();
  517.         if (is_sim_replaced())
  518.         {
  519.             eons_replace_opn_by_pnn_for_hplmn_req();    /* replace opn string */
  520.         }
  521.     }
  522. }
  523. /*****************************************************************************
  524.  * FUNCTION
  525.  *  eons_get_opl_record_req
  526.  * DESCRIPTION
  527.  *  
  528.  * PARAMETERS
  529.  *  recordNo        [IN]        
  530.  * RETURNS
  531.  *  void
  532.  *****************************************************************************/
  533. void eons_get_opl_record_req(U8 recordNo)
  534. {
  535.     /*----------------------------------------------------------------*/
  536.     /* Local Variables                                                */
  537.     /*----------------------------------------------------------------*/
  538.     /* EONS: Get the record of EF OPL */
  539.     MYQUEUE Message;
  540.     mmi_smu_read_sim_req_struct *dataPtr;
  541.     /*----------------------------------------------------------------*/
  542.     /* Code Body                                                      */
  543.     /*----------------------------------------------------------------*/
  544.     SetProtocolEventHandler(eons_get_opl_record_rsp, PRT_MMI_SMU_READ_SIM_RSP);
  545.     Message.oslSrcId = MOD_MMI;
  546.     Message.oslDestId = MOD_L4C;
  547.     Message.oslMsgId = PRT_MMI_SMU_READ_SIM_REQ;
  548.     dataPtr = (mmi_smu_read_sim_req_struct*) OslConstructDataPtr(sizeof(mmi_smu_read_sim_req_struct));
  549.     dataPtr->file_idx = (U8) FILE_OPL_IDX;  /* OPL...FILE_OPL_IDX */
  550.     dataPtr->para = (U8) recordNo;
  551.     dataPtr->length = 8;
  552.     Message.oslDataPtr = (oslParaType*) dataPtr;
  553.     Message.oslPeerBuffPtr = NULL;
  554.     OslMsgSendExtQueue(&Message);
  555. }
  556. /**************************************************************************
  557.    Get File Info of PNN and OPL:
  558.       void eons_get_pnn_file_info_rsp(void *info)
  559.       void eons_get_pnn_file_info_req(void)
  560.       void eons_get_opl_file_info_rsp(void *info)
  561.       void eons_get_opl_file_info_req(void)
  562. **************************************************************************/
  563. /*****************************************************************************
  564.  * FUNCTION
  565.  *  eons_get_pnn_file_info_rsp
  566.  * DESCRIPTION
  567.  *  
  568.  * PARAMETERS
  569.  *  info        [?]     
  570.  * RETURNS
  571.  *  void
  572.  *****************************************************************************/
  573. void eons_get_pnn_file_info_rsp(void *info)
  574. {
  575.     /*----------------------------------------------------------------*/
  576.     /* Local Variables                                                */
  577.     /*----------------------------------------------------------------*/
  578.     /* EONS: If PNN is also present, then try to get OPN first record */
  579.     mmi_smu_read_file_info_rsp_struct *resp;
  580.     /*----------------------------------------------------------------*/
  581.     /* Code Body                                                      */
  582.     /*----------------------------------------------------------------*/
  583.     resp = (mmi_smu_read_file_info_rsp_struct*) (info);
  584.     ClearProtocolEventHandler(PRT_MMI_SMU_READ_FILE_INFO_RSP);
  585.     if (resp->result.flag == 0)
  586.     {
  587.         eons_get_opl_record_req(opl_record_count);
  588.     }
  589. }
  590. /*****************************************************************************
  591.  * FUNCTION
  592.  *  eons_get_pnn_file_info_req
  593.  * DESCRIPTION
  594.  *  
  595.  * PARAMETERS
  596.  *  void
  597.  * RETURNS
  598.  *  void
  599.  *****************************************************************************/
  600. void eons_get_pnn_file_info_req(void)
  601. {
  602.     /*----------------------------------------------------------------*/
  603.     /* Local Variables                                                */
  604.     /*----------------------------------------------------------------*/
  605.     /* EONS: Get the file info of EF PNN */
  606.     MYQUEUE msgStruct;
  607.     mmi_smu_read_file_info_req_struct *pnnstatus;
  608.     /*----------------------------------------------------------------*/
  609.     /* Code Body                                                      */
  610.     /*----------------------------------------------------------------*/
  611.     SetProtocolEventHandler(eons_get_pnn_file_info_rsp, PRT_MMI_SMU_READ_FILE_INFO_RSP);
  612.     pnnstatus = OslConstructDataPtr(sizeof(mmi_smu_read_file_info_req_struct));
  613.     pnnstatus->file_idx = (U8) FILE_PNN_IDX;    /* PNN...FILE_PNN_IDX */
  614.     msgStruct.oslSrcId = MOD_MMI;
  615.     msgStruct.oslDestId = MOD_L4C;
  616.     msgStruct.oslMsgId = PRT_MMI_SMU_READ_FILE_INFO_REQ;
  617.     msgStruct.oslSapId = INVALID_SAP;
  618.     msgStruct.oslDataPtr = (oslParaType*) pnnstatus;
  619.     msgStruct.oslPeerBuffPtr = NULL;
  620.     OslMsgSendExtQueue(&msgStruct);
  621. }
  622. /*****************************************************************************
  623.  * FUNCTION
  624.  *  eons_get_opn_file_info_rsp
  625.  * DESCRIPTION
  626.  *  
  627.  * PARAMETERS
  628.  *  info        [?]     
  629.  * RETURNS
  630.  *  void
  631.  *****************************************************************************/
  632. void eons_get_opn_file_info_rsp(void *info)
  633. {
  634.     /*----------------------------------------------------------------*/
  635.     /* Local Variables                                                */
  636.     /*----------------------------------------------------------------*/
  637.     /* EONS: If OPL is present, then try to get PNN */
  638.     mmi_smu_read_file_info_rsp_struct *resp;
  639.     /*----------------------------------------------------------------*/
  640.     /* Code Body                                                      */
  641.     /*----------------------------------------------------------------*/
  642.     resp = (mmi_smu_read_file_info_rsp_struct*) (info);
  643.     ClearProtocolEventHandler(PRT_MMI_SMU_READ_FILE_INFO_RSP);
  644.     if (resp->result.flag == 0)
  645.     {
  646.         opl_record_number = (resp->num_of_rec < MAX_OPN_PNN_RECORD) ? resp->num_of_rec : MAX_OPN_PNN_RECORD;
  647.         eons_get_pnn_file_info_req();
  648.     }
  649.     else
  650.     {
  651.         if (is_sim_replaced())
  652.         {
  653.             eons_reset_nvram();
  654.         }
  655.     }
  656. }
  657. /*****************************************************************************
  658.  * FUNCTION
  659.  *  eons_get_opn_file_info_req
  660.  * DESCRIPTION
  661.  *  
  662.  * PARAMETERS
  663.  *  void
  664.  * RETURNS
  665.  *  void
  666.  *****************************************************************************/
  667. void eons_get_opn_file_info_req(void)
  668. {
  669.     /*----------------------------------------------------------------*/
  670.     /* Local Variables                                                */
  671.     /*----------------------------------------------------------------*/
  672.     /* EONS: Get the file info of EF OPL */
  673.     MYQUEUE msgStruct;
  674.     mmi_smu_read_file_info_req_struct *oplstatus;
  675.     /*----------------------------------------------------------------*/
  676.     /* Code Body                                                      */
  677.     /*----------------------------------------------------------------*/
  678.     SetProtocolEventHandler(eons_get_opn_file_info_rsp, PRT_MMI_SMU_READ_FILE_INFO_RSP);
  679.     oplstatus = OslConstructDataPtr(sizeof(mmi_smu_read_file_info_req_struct));
  680.     oplstatus->file_idx = (U8) FILE_OPL_IDX;    /* OPL...FILE_OPL_IDX */
  681.     msgStruct.oslSrcId = MOD_MMI;
  682.     msgStruct.oslDestId = MOD_L4C;
  683.     msgStruct.oslMsgId = PRT_MMI_SMU_READ_FILE_INFO_REQ;
  684.     msgStruct.oslSapId = INVALID_SAP;
  685.     msgStruct.oslDataPtr = (oslParaType*) oplstatus;
  686.     msgStruct.oslPeerBuffPtr = NULL;
  687.     OslMsgSendExtQueue(&msgStruct);
  688. }
  689. /**************************************************************************
  690.    Check if camp on PLMN is the same as anyone in OPL:
  691.       void eons_convert_plmn_bcd_format_to_string(U8* PlmnBcd, U8* PlmnString)
  692.       U8 eons_check_if_plmn_present(U8 *UpdatePlmn)
  693. **************************************************************************/
  694. /*****************************************************************************
  695.  * FUNCTION
  696.  *  eons_convert_plmn_bcd_format_to_string
  697.  * DESCRIPTION
  698.  *  
  699.  * PARAMETERS
  700.  *  PlmnBcd         [?]     
  701.  *  PlmnString      [?]     
  702.  * RETURNS
  703.  *  void
  704.  *****************************************************************************/
  705. void eons_convert_plmn_bcd_format_to_string(U8 *PlmnBcd, U8 *PlmnString)
  706. {
  707.     /*----------------------------------------------------------------*/
  708.     /* Local Variables                                                */
  709.     /*----------------------------------------------------------------*/
  710.     /*----------------------------------------------------------------*/
  711.     /* Code Body                                                      */
  712.     /*----------------------------------------------------------------*/
  713.     PlmnString[0] = 0x30 + (PlmnBcd[0] & 0x0F);
  714.     PlmnString[1] = 0x30 + ((PlmnBcd[0] & 0xF0) >> 4);
  715.     PlmnString[2] = 0x30 + (PlmnBcd[1] & 0x0F);
  716.     PlmnString[3] = 0x30 + (PlmnBcd[2] & 0x0F);
  717.     PlmnString[4] = 0x30 + ((PlmnBcd[2] & 0xF0) >> 4);
  718.     if ((PlmnBcd[1] & 0xF0) == 0xF0)    /* 5-digit MCC/MNC */
  719.     {
  720.         PlmnString[5] = 0;
  721.     }
  722.     else    /* 6-digit MCC/MNC */
  723.     {
  724.         PlmnString[5] = 0x30 + ((PlmnBcd[1] & 0xF0) >> 4);
  725.         PlmnString[6] = 0;
  726.     }
  727. }
  728. /*****************************************************************************
  729.  * FUNCTION
  730.  *  eons_check_if_plmn_present
  731.  * DESCRIPTION
  732.  *  
  733.  * PARAMETERS
  734.  *  UpdatePlmn      [?]     
  735.  * RETURNS
  736.  *  
  737.  *****************************************************************************/
  738. U8 eons_check_if_plmn_present(U8 *UpdatePlmn)
  739. {
  740.     /*----------------------------------------------------------------*/
  741.     /* Local Variables                                                */
  742.     /*----------------------------------------------------------------*/
  743.     U8 i = 0, rtn = 0;
  744.     U8 PnnPlmn[MAX_MCC_MNC_LENGTH * 2 + 1];
  745.     /*----------------------------------------------------------------*/
  746.     /* Code Body                                                      */
  747.     /*----------------------------------------------------------------*/
  748.     if (strlen((PS8) UpdatePlmn) == 0)
  749.     {
  750.         return rtn;
  751.     }
  752.     for (i = 0; i < MAX_OPN_PNN_RECORD; i++)
  753.     {
  754.         eons_convert_plmn_bcd_format_to_string((U8*) g_eons_plmn_info[i].pnn_plmn_num, PnnPlmn);
  755.         /* Compare camp on PLMN with PLMN in OPL, need to notice that the first parameter is camp on PLMN */
  756.         if (strncmp((PS8) UpdatePlmn, (PS8) PnnPlmn, strlen((PS8) UpdatePlmn)) == 0)
  757.         {
  758.             /* return which record in opl */
  759.             rtn = g_eons_plmn_info[i].pnn_identifier;
  760.             break;
  761.         }
  762.     }
  763.     return rtn;
  764. }
  765. /**************************************************************************
  766.    Update OPL to NVRAM:
  767.       void eons_write_opn_to_nvram(void)
  768.       void eons_read_opn_to_nvram(void)
  769.       void eons_reset_nvram(void)
  770. **************************************************************************/
  771. /*****************************************************************************
  772.  * FUNCTION
  773.  *  eons_write_opn_to_nvram
  774.  * DESCRIPTION
  775.  *  
  776.  * PARAMETERS
  777.  *  void
  778.  * RETURNS
  779.  *  void
  780.  *****************************************************************************/
  781. void eons_write_opn_to_nvram(void)
  782. {
  783.     /*----------------------------------------------------------------*/
  784.     /* Local Variables                                                */
  785.     /*----------------------------------------------------------------*/
  786.     U8 nvram_buf[NVRAM_EF_EONS_INFO_SIZE];
  787.     U8 i;
  788.     S16 error;
  789.     /*----------------------------------------------------------------*/
  790.     /* Code Body                                                      */
  791.     /*----------------------------------------------------------------*/
  792.     memset(nvram_buf, 0xFF, NVRAM_EF_EONS_INFO_SIZE);
  793.     for (i = 0; i < opl_record_count; i++)
  794.     {
  795.         nvram_buf[i * 4] = g_eons_plmn_info[i].pnn_plmn_num[0];
  796.         nvram_buf[i * 4 + 1] = g_eons_plmn_info[i].pnn_plmn_num[1];
  797.         nvram_buf[i * 4 + 2] = g_eons_plmn_info[i].pnn_plmn_num[2];
  798.         nvram_buf[i * 4 + 3] = g_eons_plmn_info[i].pnn_identifier;
  799.     }
  800.     WriteRecord(NVRAM_EF_EONS_INFO_LID, 1, (void*)nvram_buf, NVRAM_EF_EONS_INFO_SIZE, &error);
  801. }
  802. /*****************************************************************************
  803.  * FUNCTION
  804.  *  eons_read_opn_from_nvram
  805.  * DESCRIPTION
  806.  *  
  807.  * PARAMETERS
  808.  *  void
  809.  * RETURNS
  810.  *  void
  811.  *****************************************************************************/
  812. void eons_read_opn_from_nvram(void)
  813. {
  814.     /*----------------------------------------------------------------*/
  815.     /* Local Variables                                                */
  816.     /*----------------------------------------------------------------*/
  817.     U8 nvram_buf[NVRAM_EF_EONS_INFO_SIZE];
  818.     U8 PnnPlmn[MAX_MCC_MNC_LENGTH * 2 + 1];
  819.     U8 i;
  820.     S16 error;
  821.     /*----------------------------------------------------------------*/
  822.     /* Code Body                                                      */
  823.     /*----------------------------------------------------------------*/
  824.     ReadRecord(NVRAM_EF_EONS_INFO_LID, 1, (void*)nvram_buf, NVRAM_EF_EONS_INFO_SIZE, &error);
  825.     for (i = 0; i < MAX_OPN_PNN_RECORD; i++)
  826.     {
  827.         g_eons_plmn_info[i].pnn_plmn_num[0] = nvram_buf[i * 4];
  828.         g_eons_plmn_info[i].pnn_plmn_num[1] = nvram_buf[i * 4 + 1];
  829.         g_eons_plmn_info[i].pnn_plmn_num[2] = nvram_buf[i * 4 + 2];
  830.         g_eons_plmn_info[i].pnn_identifier = nvram_buf[i * 4 + 3];
  831.         eons_convert_plmn_bcd_format_to_string((U8*) g_eons_plmn_info[i].pnn_plmn_num, PnnPlmn);
  832.         PRINT_INFORMATION_2((MMI_TRACE_G7_MISC, "[EONS] OPL %02d: %s", i + 1, PnnPlmn));
  833.     }
  834. }
  835. /*****************************************************************************
  836.  * FUNCTION
  837.  *  eons_reset_nvram
  838.  * DESCRIPTION
  839.  *  
  840.  * PARAMETERS
  841.  *  void
  842.  * RETURNS
  843.  *  void
  844.  *****************************************************************************/
  845. void eons_reset_nvram(void)
  846. {
  847.     /*----------------------------------------------------------------*/
  848.     /* Local Variables                                                */
  849.     /*----------------------------------------------------------------*/
  850.     U8 nvram_buf[NVRAM_EF_EONS_INFO_SIZE];
  851.     S16 error;
  852.     /*----------------------------------------------------------------*/
  853.     /* Code Body                                                      */
  854.     /*----------------------------------------------------------------*/
  855.     memset(nvram_buf, 0xFF, NVRAM_EF_EONS_INFO_SIZE);
  856.     WriteRecord(NVRAM_EF_EONS_INFO_LID, 1, (void*)nvram_buf, NVRAM_EF_EONS_INFO_SIZE, &error);
  857. }
  858. /**************************************************************************
  859.    Utility:
  860.       MMI_BOOL eons_check_roaming(void)
  861.       MMI_BOOL eons_check_opl_read(void)
  862. **************************************************************************/
  863. /*****************************************************************************
  864.  * FUNCTION
  865.  *  eons_check_roaming
  866.  * DESCRIPTION
  867.  *  
  868.  * PARAMETERS
  869.  *  void
  870.  * RETURNS
  871.  *  
  872.  *****************************************************************************/
  873. MMI_BOOL eons_check_roaming(void)
  874. {
  875.     /*----------------------------------------------------------------*/
  876.     /* Local Variables                                                */
  877.     /*----------------------------------------------------------------*/
  878.     U8 rtn1, rtn2;
  879.     /*----------------------------------------------------------------*/
  880.     /* Code Body                                                      */
  881.     /*----------------------------------------------------------------*/
  882.     rtn1 = eons_check_if_plmn_present(gPLMN);
  883.     rtn2 = eons_check_if_plmn_present((PU8) gHomePLMNNum);
  884.     if (rtn1 == 0 && rtn2 == 0)
  885.     {
  886.         return MMI_FALSE;
  887.     }
  888.     else if (rtn1 != rtn2)
  889.     {
  890.         return MMI_FALSE;
  891.     }
  892.     else    /* rtn1=rtn2: the same name string for camp on PLMN and home PLMN */
  893.     {
  894.         return MMI_TRUE;
  895.     }
  896. }
  897. /*****************************************************************************
  898.  * FUNCTION
  899.  *  eons_check_opl_read
  900.  * DESCRIPTION
  901.  *  
  902.  * PARAMETERS
  903.  *  void
  904.  * RETURNS
  905.  *  
  906.  *****************************************************************************/
  907. MMI_BOOL eons_check_opl_read(void)
  908. {
  909.     /*----------------------------------------------------------------*/
  910.     /* Local Variables                                                */
  911.     /*----------------------------------------------------------------*/
  912.     /*----------------------------------------------------------------*/
  913.     /* Code Body                                                      */
  914.     /*----------------------------------------------------------------*/
  915.     return opl_read_finish;
  916. }
  917. /**************************************************************************
  918.    Pre-definition
  919. **************************************************************************/
  920. #endif /* ( (defined __MMI_EONS_SUPPORT__) && (defined MMI_ON_HARDWARE_P) ) */