IMEIDownload.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:12k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * IMIEDownload.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * IMEI download/upload source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include <IniFiles.hpp>
- #pragma hdrstop
- #ifndef _IMEI_DOWNLOAD_H_
- #include "IMEIDownload.h"
- #endif
- #ifndef _MAN_ACTIVE_H_
- #include "man_active.h"
- #endif
- #ifndef _MAN_FDM_H_
- #include "man_fdm.h"
- #endif
- //===========================================================================
- static CIMEIDOWNLOAD* imei_download_ptr;
- static bool g_bIsRunning = false;
- //===========================================================================
- static void CNF_ReadFromNVRAM(void)
- {
- imei_download_ptr->CNF_ReadFromNVRAM();
- }
- //--------------------------------------------------------------------------
- static void CNF_WriteToNVRAM(void)
- {
- imei_download_ptr->CNF_WriteToNVRAM();
- }
- //--------------------------------------------------------------------------
- static void REQ_TimeOut(void)
- {
- imei_download_ptr->REQ_TimeOut();
- }
- //--------------------------------------------------------------------------
- static void REQ_Finish(void)
- {
- imei_download_ptr->REQ_Finish();
- }
- //===========================================================================
- CIMEIDOWNLOAD::CIMEIDOWNLOAD(void)
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- m_iIMEIBufSize = 0;
- m_cIMEIBuf = NULL;
- }
- //---------------------------------------------------------------------------
- CIMEIDOWNLOAD::~CIMEIDOWNLOAD()
- {
- if (m_cIMEIBuf)
- {
- delete [] m_cIMEIBuf;
- m_cIMEIBuf = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void CIMEIDOWNLOAD::REQ_Finish(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //---------------------------------------------------------------------------
- void CIMEIDOWNLOAD::REQ_Stop(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- Confirm(METAAPP_STOP);
- }
- //---------------------------------------------------------------------------
- void CIMEIDOWNLOAD::REQ_TimeOut(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
-
- Confirm(METAAPP_TIMEOUT);
- }
- //---------------------------------------------------------------------------
- void CIMEIDOWNLOAD::Confirm(E_METAAPP_RESULT_T confirm_state)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- g_bIsRunning = false;
- if (NULL == ConfirmCallback)
- {
- return;
- }
- m_eConfirmState = confirm_state;
- ActiveMan->SetActiveFunction(ConfirmCallback);
- }
- //===========================================================================
- void CIMEIDOWNLOAD::REQ_Read_From_NVRAM_Start(void)
- {
- imei_download_ptr = this;
- g_bIsRunning = true;
- m_bDownloadTrigger = false;
- REQ_Read_From_NVRAM();
- }
- //---------------------------------------------------------------------------
- void CIMEIDOWNLOAD::REQ_Read_From_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- if( NULL == m_cIMEIBuf )
- {
- META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_IMEI_IMEISV_LID",
- &m_iIMEIBufSize);
- if (MetaResult!=META_SUCCESS)
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- m_cIMEIBuf = new char[m_iIMEIBufSize];
- }
- NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
- NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_IMEI_IMEISV_LID",
- 1,
- m_iIMEIBufSize,
- m_cIMEIBuf );
- }
- //-------------------------------------
- void CIMEIDOWNLOAD::CNF_ReadFromNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- if (METAAPP_SUCCESS == state)
- {
- if (!Decompose_IMEI())
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- if (m_bDownloadTrigger)
- {
- for (int i=0; i<IMEI_ARRAY_LEN; i++)
- {
- m_sIMEISV.imei[i] = m_sIMEI.c_imei[i];
- }
- REQ_Write_To_NVRAM();
- }
- else
- {
- for (int i=0; i<IMEI_ARRAY_LEN; i++)
- {
- m_sIMEI.c_imei[i] = m_sIMEISV.imei[i];
- }
- ActiveMan->SetActiveFunction(::REQ_Finish);
- }
- }
- else
- {
- Confirm(state);
- }
- }
- //===========================================================================
- void CIMEIDOWNLOAD::REQ_Write_To_NVRAM_Start(bool check_checksum)
- {
- imei_download_ptr = this;
- g_bIsRunning = true;
- m_bCheckChecksum = check_checksum;
- m_bDownloadTrigger = true;
- REQ_Read_From_NVRAM();
- }
- //---------------------------------------------------------------------------
- void CIMEIDOWNLOAD::REQ_Write_To_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- if (NULL == m_cIMEIBuf)
- {
- META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_IMEI_IMEISV_LID", &m_iIMEIBufSize);
- if(MetaResult!=META_SUCCESS)
- {
- Confirm( METAAPP_FAIL );
- return;
- }
- m_cIMEIBuf = new char[m_iIMEIBufSize];
- }
- if (!Compose_IMEI(m_bCheckChecksum))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
- NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_IMEI_IMEISV_LID",
- 1,
- m_iIMEIBufSize,
- m_cIMEIBuf);
- }
- //-------------------------------------
- void CIMEIDOWNLOAD::CNF_WriteToNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
- Confirm(state);
- }
- //===========================================================================
- bool CIMEIDOWNLOAD::Compose_IMEI(bool check_checksum)
- {
- META_RESULT MetaResult;
- if (check_checksum)
- {
- MetaResult = META_NVRAM_Compose_IMEISV(&m_sIMEISV, m_cIMEIBuf, m_iIMEIBufSize);
- }
- else
- {
- MetaResult = META_NVRAM_Compose_IMEISV_NoCheck(&m_sIMEISV, m_cIMEIBuf, m_iIMEIBufSize);
- }
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- bool CIMEIDOWNLOAD::Decompose_IMEI(void)
- {
- META_RESULT MetaResult = META_NVRAM_Decompose_IMEISV(&m_sIMEISV, m_cIMEIBuf, m_iIMEIBufSize);
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- bool CIMEIDOWNLOAD::REQ_Read_From_File(char *filename)
- {
- TIniFile *ini_file;
- AnsiString as_IMEI;
- char *str_IMEI;
- int i;
- ini_file = new TIniFile(filename);
- if( ini_file == NULL ) return false;
- as_IMEI = ini_file->ReadString( "IMEI",
- "IMEI",
- "FFFFFFFF" );
- strcpy(m_sIMEISV.imei, as_IMEI.c_str());
- for (int i=0; i<IMEI_ARRAY_LEN; i++)
- {
- m_sIMEI.c_imei[i] = m_sIMEISV.imei[i];
- }
- delete ini_file;
- return true;
- }
- //===========================================================================
- bool CIMEIDOWNLOAD::REQ_Write_To_File(char *filename)
- {
- TIniFile *ini_file;
- ini_file = new TIniFile(filename);
- if(ini_file == NULL) return false;
- ini_file->WriteString("IMEI",
- "IMEI",
- m_sIMEISV.imei);
- delete ini_file;
- return true;
- }
- //---------------------------------------------------------------------------
- unsigned short CIMEIDOWNLOAD::REQ_NVRAM_Calcualte_IMEI_Spare(char *imei)
- {
- unsigned short p_spare;
- META_NVRAM_Calculate_IMEI_CD(imei, &p_spare);
- return p_spare;
- }
- //===========================================================================
- bool CIMEIDOWNLOAD::ImeiSectionExist(char *filename)
- {
- TIniFile *ini_file;
- ini_file = new TIniFile(filename);
- if (NULL == ini_file)
- {
- return false;
- }
- if (!ini_file->SectionExists("IMEI"))
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- //////////////////////////// Global information ///////////////////////////
- //===========================================================================
- E_METAAPP_RESULT_T CIMEIDOWNLOAD::Get_ConfirmState(void)
- {
- return m_eConfirmState;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- S_IMEI_T* CIMEIDOWNLOAD::Get_IMEI(void)
- {
- return &m_sIMEI;
- }
- //---------------------------------------------------------------------------
- void CIMEIDOWNLOAD::Set_IMEI(S_IMEI_T imei)
- {
- m_sIMEI = imei;
- for (int i=0; i<IMEI_ARRAY_LEN; i++)
- {
- m_sIMEISV.imei[i] = m_sIMEI.c_imei[i];
- }
- }