| /***************************************************************************** |
| * 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: |
| * --------- |
| * nvram_handler_reset.c |
| * |
| * Project: |
| * -------- |
| * MAUI |
| * |
| * Description: |
| * ------------ |
| * This is reset handler function of NVRAM module. |
| * |
| * Author: |
| * ------- |
| * ------- |
| * |
| *============================================================================ |
| * HISTORY |
| * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *------------------------------------------------------------------------------ |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| * removed! |
| * removed! |
| * removed! |
| * |
| *------------------------------------------------------------------------------ |
| * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! |
| *============================================================================ |
| ****************************************************************************/ |
| #include "kal_general_types.h" |
| #include "kal_public_api.h" |
| #include "kal_public_defs.h" |
| #include "kal_trace.h" |
| #include "nvram_msgid.h" |
| #include "mcf_if.h" |
| |
| #ifdef __NVRAM_OTP__ |
| #include "fs_gprot.h" |
| #include "fs_iprot.h" |
| #endif |
| |
| //MSBB remove #include "fctycomp_config.h" /* MOD_FT */ |
| |
| #include "nvram_main.h" |
| #include "ex_public.h" |
| #include "stdio.h" |
| #include "stdarg.h" |
| #include "us_timer.h" |
| |
| |
| extern kal_mutexid g_nvram_impt_mutex; |
| extern nvram_access_trace_information nvram_access_trace; |
| extern kal_mutexid g_nvram_trace_mutex; |
| |
| extern nvram_ee_info_type* nvram_ee_info; |
| extern kal_char nvram_trace_dump_temp_buffer[]; |
| extern kal_char nvram_trace_dump_buffer[]; |
| extern kal_mutexid g_nvram_dump_trace_mutex; |
| extern kal_wchar nvram_trace_filename[]; |
| extern FS_HANDLE nvram_trace_file_hdl; |
| extern kal_uint32 nvram_trace_dump_buffer_offset; |
| |
| |
| static void nvram_reset_confirm(module_type dest_id, nvram_errno_enum result, nvram_reset_req_struct *nvram_reset_req); |
| |
| static void nvram_set_lock_confirm( |
| module_type dest_id, |
| nvram_errno_enum result, |
| nvram_set_lock_req_struct *nvram_set_lock_req); |
| |
| extern module_type stack_get_active_module_id( void ); |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_reset_handler |
| * DESCRIPTION |
| * This is nvram_reset_handler() function of NVRAM module. |
| * PARAMETERS |
| * ilm_ptr [IN] The primitives |
| * RETURNS |
| * void |
| *****************************************************************************/ |
| void nvram_reset_handler(ilm_struct *ilm_ptr) |
| { |
| /*----------------------------------------------------------------*/ |
| /* Local Variables */ |
| /*----------------------------------------------------------------*/ |
| nvram_ltable_entry_struct *ldi; |
| nvram_ltable_entry_struct tmp_ldi = {0}; |
| nvram_reset_req_struct *nvram_reset_req = (nvram_reset_req_struct*) ilm_ptr->local_para_ptr; |
| kal_uint32 nvram_trace_index = 0; |
| /*----------------------------------------------------------------*/ |
| /* Code Body */ |
| /*----------------------------------------------------------------*/ |
| nvram_util_take_mutex(g_nvram_trace_mutex); |
| nvram_trace_index = nvram_access_trace.reset_trace_index; |
| nvram_access_trace.reset_trace_index = (nvram_access_trace.reset_trace_index + 1) % MAX_TRACE_NUM; |
| nvram_util_give_mutex(g_nvram_trace_mutex); |
| |
| MD_TRC_FUNC_NVRAM_RESET(); |
| NVRAM_EXT_ASSERT(nvram_reset_req != NULL,(kal_uint32)nvram_reset_req, NVRAM_LOC_RESET_REQ_PTR_IS_NULL_1, 0); |
| kal_mem_set((void *)&(nvram_access_trace.reset_trace[nvram_trace_index]), 0, sizeof(trace_info)); |
| nvram_access_trace.reset_trace[nvram_trace_index].access_way = NVRAM_ACCESS_BY_MSG; |
| nvram_access_trace.reset_trace[nvram_trace_index].LID = nvram_reset_req->LID; |
| nvram_access_trace.reset_trace[nvram_trace_index].start_time = ust_get_current_time(); |
| if (nvram_ptr->dev_broken) |
| { |
| nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time(); |
| nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_DRV_BROKEN; |
| nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_reset_req); |
| } |
| else |
| { |
| |
| if (nvram_ptr->state == NVRAM_STATE_READY) |
| { |
| if (!(nvram_reset_req->reset_category & NVRAM_RESET_CERTAIN)) |
| { |
| nvram_reset_req->LID = 0; |
| } |
| |
| nvram_util_get_data_item(&ldi, nvram_reset_req->LID); |
| |
| if (nvram_reset_req->reset_category == NVRAM_RESET_CERTAIN) |
| { |
| if (!NVRAM_IS_LID_VALID(nvram_reset_req->LID)) |
| { |
| nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time(); |
| nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_INVALID_LID; |
| NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_IO_ERRNO_INVALID_LID \r\n",__FUNCTION__,nvram_reset_req->LID); |
| nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_INVALID_LID, nvram_reset_req); |
| return; |
| } |
| |
| /* In Meta mode, we cannot access the data belongs to custom sensitve area |
| we also cannot reset the important data to prevent security problem */ |
| |
| |
| if (NVRAM_IS_CATEGORY_IMPORTANT(ldi->category) |
| || NVRAM_IS_CATEGORY_IMPORTANT_L4(ldi->category) |
| #if defined(__NVRAM_CUSTOM_SENSITIVE__) || defined(__NVRAM_CUSTOM_DISK__) |
| || NVRAM_IS_CATEGORY_CUSTOM_SENSITIVE(ldi->category) |
| || NVRAM_IS_CATEGORY_CUSTOM_DISK(ldi->category) |
| #endif |
| ) |
| { |
| if (FACTORY_BOOT == kal_query_boot_mode() && ilm_ptr->src_mod_id == MOD_FT) |
| { |
| nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time(); |
| nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_IO_ERRNO_ACCESS_DENIED; |
| NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s LID 0x%04X NVRAM_IO_ERRNO_ACCESS_DENIED \r\n",__FUNCTION__,nvram_reset_req->LID); |
| nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_IO_ERRNO_ACCESS_DENIED, nvram_reset_req); |
| return; |
| } |
| } |
| } |
| |
| if (nvram_reset_data_items(nvram_reset_req->reset_category, nvram_reset_req->app_id, ldi, nvram_reset_req->rec_index, nvram_reset_req->rec_amount) == KAL_TRUE) |
| { |
| if(nvram_ptr->state == NVRAM_STATE_READY) |
| { |
| memcpy(&tmp_ldi,ldi,sizeof(nvram_ltable_entry_struct)); |
| mcf_do_ota_by_lid(nvram_reset_req->LID,nvram_reset_req->rec_index, nvram_reset_req->rec_amount,&tmp_ldi); |
| } |
| nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time(); |
| nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_SUCCESS; |
| nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_reset_req); |
| } |
| else |
| { |
| nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time(); |
| nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_FAIL; |
| nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_reset_req); |
| } |
| } |
| /* State error */ |
| else |
| { |
| MD_TRC_ERROR_NVRAM_STATE(); |
| nvram_access_trace.reset_trace[nvram_trace_index].end_time = ust_get_current_time(); |
| nvram_access_trace.reset_trace[nvram_trace_index].ret_value = NVRAM_ERRNO_NOT_READY; |
| NVRAM_DEBUG_DUMP(NVRAM_CRITICAL_DUMP,"[Error]%s->LID 0x%04X NVRAM_ERRNO_NOT_READY \r\n",__FUNCTION__,nvram_reset_req->LID); |
| nvram_reset_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_reset_req); |
| } |
| } |
| } /* end of nvram_reset_handler */ |
| |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_reset_confirm |
| * DESCRIPTION |
| * This is nvram_reset_confirm() function of NVRAM module. |
| * PARAMETERS |
| * dest_id [IN] |
| * result [IN] |
| * nvram_reset_req [?] |
| * ilm_ptr(?) [IN] The primitives |
| * RETURNS |
| * void |
| *****************************************************************************/ |
| static void nvram_reset_confirm(module_type dest_id, nvram_errno_enum result, nvram_reset_req_struct *nvram_reset_req) |
| { |
| /*----------------------------------------------------------------*/ |
| /* Local Variables */ |
| /*----------------------------------------------------------------*/ |
| nvram_reset_cnf_struct *nvram_reset_cnf; |
| |
| /*----------------------------------------------------------------*/ |
| /* Code Body */ |
| /*----------------------------------------------------------------*/ |
| MD_TRC_FUNC_NVRAM_RESET_CNF(result); |
| nvram_reset_cnf = (nvram_reset_cnf_struct*) construct_local_para(sizeof(nvram_reset_cnf_struct), TD_CTRL); |
| |
| |
| nvram_reset_cnf->result = result; |
| nvram_reset_cnf->access_id = nvram_reset_req->access_id; |
| |
| nvram_send_ilm(dest_id, MSG_ID_NVRAM_RESET_CNF, nvram_reset_cnf, NULL); |
| |
| return; |
| } /* end of nvram_reset_confirm */ |
| |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_set_lock_handler |
| * DESCRIPTION |
| * This is nvram_set_lock_handler() function of NVRAM module. |
| * PARAMETERS |
| * ilm_ptr [IN] The primitives |
| * RETURNS |
| * void |
| *****************************************************************************/ |
| void nvram_set_lock_handler(ilm_struct *ilm_ptr) |
| { |
| /*----------------------------------------------------------------*/ |
| /* Local Variables */ |
| /*----------------------------------------------------------------*/ |
| kal_bool lock_state = nvram_ptr->lock; |
| nvram_set_lock_req_struct *nvram_set_lock_req = (nvram_set_lock_req_struct*) ilm_ptr->local_para_ptr; |
| #ifdef __NVRAM_OTP__ |
| kal_int32 result = 0; |
| #endif |
| /*----------------------------------------------------------------*/ |
| /* Code Body */ |
| /*----------------------------------------------------------------*/ |
| if (nvram_ptr->dev_broken) |
| { |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_INVALID, nvram_set_lock_req); |
| } |
| else |
| { |
| if ((nvram_set_lock_req->lock_en == NVRAM_LOCK_ENABLE && lock_state == KAL_TRUE) || |
| (nvram_set_lock_req->lock_en == NVRAM_LOCK_DISABLE && lock_state == KAL_FALSE)) |
| { |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req); |
| return; |
| } |
| else if (nvram_set_lock_req->lock_en == NVRAM_LOCK_TEMP_DISABLE) |
| { |
| #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__ |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_set_lock_req); |
| #else |
| nvram_ptr->lock = KAL_FALSE; |
| if(nvram_ee_info != NULL){ |
| nvram_ee_info->nvram_init_context.lock = nvram_ptr->lock; |
| } |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req); |
| return; |
| #endif |
| } |
| #ifdef __NVRAM_OTP__ |
| else if (nvram_set_lock_req->lock_en == NVRAM_LOCK_OTP) |
| { |
| NVRAM_FS_START(FS_OP_OTPLOCK); |
| result = FS_OTPLock(FS_DEVICE_TYPE_NOR); |
| NVRAM_FS_END(FS_OP_OTPLOCK,result); |
| if(result == FS_NO_ERROR) |
| { |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req); |
| } |
| else |
| { |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_set_lock_req); |
| } |
| return; |
| } |
| #endif /* __NVRAM_OTP__ */ |
| |
| if (nvram_set_lock_req->lock_en == NVRAM_LOCK_ENABLE) |
| { |
| nvram_write_system_record(NVRAM_LOCK_ENABLE); |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req); |
| } |
| else if (nvram_set_lock_req->lock_en == NVRAM_LOCK_DISABLE) |
| { |
| #ifdef __NVRAM_IMEI_UNLOCK_DISABLE__ |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_FAIL, nvram_set_lock_req); |
| #else |
| nvram_write_system_record(NVRAM_LOCK_DISABLE); |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_SUCCESS, nvram_set_lock_req); |
| #endif |
| } |
| else |
| { |
| /* Invalid parameter */ |
| nvram_set_lock_confirm(ilm_ptr->src_mod_id, NVRAM_ERRNO_INVALID, nvram_set_lock_req); |
| return; |
| } |
| |
| } |
| } |
| |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_set_lock_confirm |
| * DESCRIPTION |
| * This is nvram_set_lock_confirm() function of NVRAM module. |
| * PARAMETERS |
| * dest_id [IN] |
| * result [IN] |
| * nvram_set_lock_req [?] |
| * ilm_ptr(?) [IN] The primitives |
| * RETURNS |
| * void |
| *****************************************************************************/ |
| static void nvram_set_lock_confirm(module_type dest_id, |
| nvram_errno_enum result, |
| nvram_set_lock_req_struct *nvram_set_lock_req) |
| { |
| /*----------------------------------------------------------------*/ |
| /* Local Variables */ |
| /*----------------------------------------------------------------*/ |
| nvram_set_lock_cnf_struct *nvram_set_lock_cnf; |
| |
| /*----------------------------------------------------------------*/ |
| /* Code Body */ |
| /*----------------------------------------------------------------*/ |
| nvram_set_lock_cnf = (nvram_set_lock_cnf_struct*) construct_local_para(sizeof(nvram_set_lock_cnf_struct), TD_CTRL); |
| |
| nvram_set_lock_cnf->result = result; |
| |
| nvram_send_ilm(dest_id, MSG_ID_NVRAM_SET_LOCK_CNF, nvram_set_lock_cnf, NULL); |
| |
| return; |
| |
| } |
| |
| |
| /***************************************************************************** |
| * FUNCTION |
| * nvram_suspend_handler |
| * DESCRIPTION |
| * This is the handler to handle MSG_ID_NVRAM_SUSPEND_REQ |
| * After nvram receive this request, it will be suspend forever now. |
| * PARAMETERS |
| * ilm_ptr [IN] the message content |
| * RETURNS |
| * void |
| *****************************************************************************/ |
| void nvram_suspend_handler(ilm_struct *ilm_ptr) |
| { |
| /*----------------------------------------------------------------*/ |
| /* Local Variables */ |
| /*----------------------------------------------------------------*/ |
| nvram_suspend_req_struct *nvram_suspend_req = (nvram_suspend_req_struct*) ilm_ptr->local_para_ptr; |
| nvram_suspend_cnf_struct *nvram_suspend_cnf; |
| |
| /*----------------------------------------------------------------*/ |
| /* Code Body */ |
| /*----------------------------------------------------------------*/ |
| |
| nvram_suspend_cnf = (nvram_suspend_cnf_struct*) construct_local_para(sizeof(nvram_suspend_cnf_struct), TD_CTRL); |
| |
| nvram_suspend_cnf->result = NVRAM_ERRNO_SUCCESS; |
| |
| nvram_send_ilm(ilm_ptr->src_mod_id, MSG_ID_NVRAM_SUSPEND_CNF, nvram_suspend_cnf, NULL); |
| |
| if (nvram_suspend_req == NULL || nvram_suspend_req->suspend_time == 0) |
| { |
| while(1) |
| { |
| kal_sleep_task(kal_milli_secs_to_ticks(500)); |
| } |
| } |
| else |
| { |
| kal_sleep_task(kal_milli_secs_to_ticks(5*nvram_suspend_req->suspend_time)); |
| } |
| |
| return; |
| } |