blob: 068c57a0c40aea25e198c0cedb1cf5052f2d8d0d [file] [log] [blame]
/*****************************************************************************
* 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) 2018
*
* 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:
* ---------
* mcf_if.c
*
* Project:
* --------
* UMOLYA
*
* Description:
* ------------
* MD Configuration Framework public interface implementation.
*
* 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!
* 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_public_api.h"
#include "fs_general_api.h"
#include <math.h>
#include "md_sap.h"
#include "md_svc_sap.h"
#include "em_msgid.h"
#include "em_l4_common_public_struct.h"
#include "em_mcf_public_struct.h"
#include "nvram_interface.h"
#include "mcf_nvram_editor.h"
#include "mcf_msgid.h"
#include "mcf_custom.h"
#include "mcf_defs.h"
#include "mcf_if.h"
#include "mcf_debug.h"
#include "mcf_util.h"
#include "mcf_object.h"
#include "mcf_utfwk.h"
/*------------------------------------------------------------------------------
* Global variables.
*----------------------------------------------------------------------------*/
extern MCF_DB_LID_MAPPING mcf_db_lid_mapping_tbl[];
extern mcf_dump_param_struct mcf_dump_param_tbl[];
extern kal_uint32 mcf_dump_param_tbl_num;
kal_uint8 mcf_dump_buffer[MCF_MAX_DUMP_SIZE + MCF_MAX_RECORD_CNT * MCF_DUMP_LID_HEADER_SIZE];
nvram_mcf_lid_info_struct mcf_last_mod_lid_g = {0};
nvram_mcf_lid_info_struct mcf_curr_mod_lid_g = {0};
nvram_mcf_lid_info_struct mcf_tlvota_last_mod_lid_g[MAX_SIM_NUM] = {0};
nvram_mcf_lid_info_struct mcf_tlvota_curr_mod_lid_g[MAX_SIM_NUM] = {0};
nvram_mcf_lid_info_struct mcf_general_tlvota_last_mod_lid_g[MAX_SIM_NUM] = {0};
nvram_mcf_lid_info_struct mcf_general_tlvota_curr_mod_lid_g[MAX_SIM_NUM] = {0};
kal_char txt_buff[64];
kal_bool is_read_tlvota[MAX_SIM_NUM] = {0};
kal_bool is_read_general_tlvota[MAX_SIM_NUM] = {0};
kal_bool is_update_tlvota[MAX_SIM_NUM];
nvram_ef_mcf_internal_info_struct nv_int_info;
kal_char mcf_gid_buff[256];
mcf_ota_result_e set_op_read_ret[MAX_SIM_NUM];
#ifdef __MCF_COMBINE_FILE_SUPPORT__
kal_uint8 mcf_merge_buffer[MCF_MAX_FILE_SIZE];
kal_uint8 mcf_file_buffer[MCF_MAX_FILE_SIZE];
kal_wchar merge_ota_name[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
#endif
kal_uint8 dsbp_ret = 0;
/*------------------------------------------------------------------------------
* Helper macro.
*----------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Private data structure.
*----------------------------------------------------------------------------*/
typedef struct tm MCF_TIME_STRUCT;
/*------------------------------------------------------------------------------
* Private variables.
*----------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
* Extern fucntions.
*----------------------------------------------------------------------------*/
extern kal_char* release_verno(void);
extern kal_char* build_date_time(void);
extern sim_interface_enum l4c_gemini_get_actual_sim_id(sim_interface_enum simId);
extern sim_interface_enum l4c_gemini_get_switched_sim_id(sim_interface_enum simId);
extern void mcf_merge_make_ota_file_header(mcf_tool_file_info_t *output_header, mcf_tool_file_info_t *copy_header);
/*------------------------------------------------------------------------------
* Private fucntions.
*----------------------------------------------------------------------------*/
_STATIC kal_bool mcf_check_tag_match(
mcf_tool_tlvota_file_item_t *pItem,
mcf_tlvota_tag_t *tag_entry,
kal_uint32 tag_num,
kal_uint32 *match_idx)
{
kal_uint32 tag_cnt = 0;
ASSERT(pItem);
ASSERT(tag_entry);
ASSERT(tag_num >= 0);
while(tag_cnt < tag_num) {
if ( (pItem->tag_type == tag_entry[tag_cnt].tag_type) && (strncmp(&(pItem->buff_start), tag_entry[tag_cnt].tag, pItem->tag_len) == 0) ) {
*match_idx = tag_cnt;
return KAL_TRUE;
}
tag_cnt++;
}
return KAL_FALSE;
}
_STATIC kal_bool mcf_v2_check_tag_match(
mcf_tool_gid_tlvota_file_item_t *pItem,
mcf_tlvota_tag_t *tag_entry,
kal_uint32 tag_num,
kal_uint32 *match_idx)
{
kal_uint32 tag_cnt = 0;
ASSERT(pItem);
ASSERT(tag_entry);
ASSERT(tag_num >= 0);
while(tag_cnt < tag_num) {
if ( (pItem->tag_type == tag_entry[tag_cnt].tag_type) && (strncmp(&(pItem->buff_start), tag_entry[tag_cnt].tag, pItem->tag_len) == 0) ) {
*match_idx = tag_cnt;
return KAL_TRUE;
}
tag_cnt++;
}
return KAL_FALSE;
}
_STATIC mcf_ota_result_e mcf_fill_tag_entry(mcf_tlvota_sbp_tag_t sbp_tag, kal_bool is_general, mcf_tlvota_tag_t *tag_entry, kal_uint32 *tag_num)
{
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
static kal_char tag[4][MCF_MAX_TAG_LEN];
kal_int32 ret_snprintf;
kal_mem_set(tag, 0, sizeof(kal_char) * 4 * MCF_MAX_TAG_LEN);
*tag_num = 0;
/* Fill tag entry */
if (sbp_tag.sbp_id != SBP_ID_INVALID) {
if (strcmp((kal_char *)sbp_tag.mcc, "") != 0) {
if (strcmp((kal_char *)sbp_tag.mnc, "") != 0) { // sbpid_mcc_mnc case
/* NA_mcc_NA and NA_mcc_mnc case should be updated first */
if (is_general == KAL_TRUE){
/* NA_mcc_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* NA_mcc_mnc */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_%s_%s", (kal_char *)sbp_tag.mcc, (kal_char *)sbp_tag.mnc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}else{
/* Reuse tag_entry */
*tag_num = 0;
/* NA_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* sbpid_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "%d_NA_NA", sbp_tag.sbp_id);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "SBP_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* sbpid_mcc_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "%d_%s_NA", sbp_tag.sbp_id, sbp_tag.mcc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "SBP_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* sbpid_mcc_mnc */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "%d_%s_%s", sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "SBP_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}
} else { // sbpid_mcc_NA case
/* NA_mcc_NA case should be updated first */
if (is_general == KAL_TRUE){
/* NA_mcc_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}else{
/* Reuse tag_entry */
*tag_num = 0;
/* NA_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* sbpid_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "%d_NA_NA", sbp_tag.sbp_id);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "SBP_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* sbpid_mcc_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "%d_%s_NA", sbp_tag.sbp_id, sbp_tag.mcc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "SBP_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}
}
} else {
if (strcmp((kal_char *)sbp_tag.mnc, "") == 0) { // sbpid_NA_NA case
if (is_general == KAL_FALSE){
/* NA_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* sbpid_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "%d_NA_NA", sbp_tag.sbp_id);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "SBP_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}
} else { // sbpid_NA_mnc case is not allowed!!
MD_TRC_MCF_TR_FILL_TAG_ENTRY_INVALID_SBP_TAG(sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
ret = MCF_OTA_R_INVALID_SBP_TAG;
return ret;
}
}
} else {
if (strcmp((kal_char *)sbp_tag.mcc, "") != 0) {
if (strcmp((kal_char *)sbp_tag.mnc, "") != 0) { // NA_mcc_mnc case
/* NA_mcc_NA and NA_mcc_mnc case should be updated first */
if (is_general == KAL_TRUE){
/* NA_mcc_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
/* NA_mcc_mnc */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_%s_%s", (kal_char *)sbp_tag.mcc, (kal_char *)sbp_tag.mnc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}else{
/* Reuse tag_entry */
*tag_num = 0;
/* NA_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}
} else { // NA_mcc_NA case
/* NA_mcc_NA and NA_mcc_mnc case should be updated first */
if (is_general == KAL_TRUE){
/* NA_mcc_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}else{
/* Reuse tag_entry */
*tag_num = 0;
/* NA_NA_NA */
tag_entry[*tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[*tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[*tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_FILL_TAG_ENTRY_SNPRINTF_FAIL(tag[*tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[*tag_num].tag_len = strlen(tag[*tag_num]);
tag_entry[*tag_num].tag = tag[*tag_num];
*tag_num = *tag_num +1;
}
}
} else { // NA_NA_mnc cases is not allowed!!
MD_TRC_MCF_TR_FILL_TAG_ENTRY_INVALID_SBP_TAG(sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
ret = MCF_OTA_R_INVALID_SBP_TAG;
return ret;
}
}
return ret;
}
_STATIC void mcf_v1_read_tlvota_buffer_tag_update_flow(mcf_tlvota_file_t *tlvota_file, mcf_tlvota_tag_t *tag_entry, kal_uint32 tag_num, nvram_lid_enum lid, kal_uint8 *buffer)
{
mcf_tool_file_info_t *pFile;
mcf_tool_tlvota_file_item_t *pItem;
kal_uint16 item_cnt = 0;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_uint32 match_idx;
kal_char item_tag[MCF_FILE_MAX_TAG_LEN] = {0};
mcf_tag_info_struct unuse = {0};
MCF_DB_STRUCT_VARIABLE const *unuse_db_ptr = NULL;
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
pItem = (mcf_tool_tlvota_file_item_t *)(tlvota_file->buff + pFile->total_len);
/* Read changed items from TLV-OTA file */
while (item_cnt < pFile->item_num) {
/* Check if LID and tag match */
if ( (pItem->lid != lid) || (mcf_check_tag_match(pItem, tag_entry, tag_num, &match_idx) == KAL_FALSE) ) {
goto next;
}
/* Check if item_tag_len is valid */
if ( (pItem->item_tag_len <= 0) || (pItem->item_tag_len >= MCF_FILE_MAX_TAG_LEN-1) ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_TAG_LEN(pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
mcf_utfwk_printf("Invalid item_tag_len(%d)!! max item_tag_len(%d) \r\n", pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
goto next;
}
/* Update LID item */
if (pItem->is_bit_op == 0) {
strncpy(item_tag, &(pItem->buff_start) + pItem->tag_len, pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if (pItem->op.byte.value_len > item_size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_LARGE_VAL_LEN(pItem->op.byte.value_len, item_size);
mcf_utfwk_printf("Invalid value len(%d)!! larger than current item len(%d) \r\n", pItem->op.byte.value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_BYTE_UPDATE(lid, tag_entry[match_idx].tag, item_byte_offset, pItem->op.byte.value_len);
mcf_dump_data(KAL_FALSE, &(pItem->buff_start) + pItem->tag_len + pItem->item_tag_len, pItem->op.byte.value_len);
kal_mem_cpy( (buffer + item_byte_offset), &(pItem->buff_start) + pItem->tag_len + pItem->item_tag_len, pItem->op.byte.value_len);
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(pItem->op.bit.len);
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->tag_len + pItem->item_tag_len, pItem->op.bit.value_len);
strncpy(item_tag, &(pItem->buff_start) + pItem->tag_len, pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if ( (pItem->op.bit.value_len > 4) || (pItem->op.bit.len > item_size) ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_BIT_LEN(pItem->op.bit.len, item_size, pItem->op.bit.value_len);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_BIT_UPDATE(lid, tag_entry[match_idx].tag, item_byte_offset, item_bit_offset, pItem->op.bit.len, pItem->op.bit.value_len, bit_value);
if (pItem->op.bit.value_len == 1) {
kal_uint8 *val_tmp = (kal_uint8 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 2) {
kal_uint16 *val_tmp = (kal_uint16 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 4) {
kal_uint32 *val_tmp = (kal_uint32 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
}
}
next:
pItem = (mcf_tool_tlvota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
_STATIC mcf_ota_result_e mcf_read_tlvota_buffer_multi_tag(
kal_uint8 ps_id,
mcf_tlvota_tag_t *tag_entry,
kal_uint32 tag_num,
nvram_lid_enum lid,
kal_uint8 *buffer,
kal_uint32 size)
{
mcf_t *pMcf = mcf_get_instance();
mcf_tool_file_info_t *pFile;
mcf_tool_gid_tlvota_file_item_t *pItem;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
mcf_tlvota_file_t *tlvota_file = &(pMcf->general_tlvota_file);
nvram_ltable_entry_struct lid_info;
kal_uint16 item_cnt = 0;
kal_uint32 match_idx;
nvram_errno_enum nvram_api_ret;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_bool item_is_bit = KAL_FALSE;
kal_uint16 item_lid;
ASSERT(buffer);
ASSERT(size > 0);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_START(ps_id, sim_id, tag_num);
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
nvram_api_ret = nvram_external_get_lid_info(lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_GET_LID_INFO_FAIL(lid, nvram_api_ret);
mcf_utfwk_printf("Fail to get LID information!! LID(%d), nvram_api_ret(%d) \r\n", lid, nvram_api_ret);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if (size != lid_info.size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_SIZE(size, lid, lid_info.size);
mcf_utfwk_printf("Invalid buffer_size(%d)!! LID(%d), record_size(%d) \r\n", size, lid, lid_info.size);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if ( (lid_info.attr & NVRAM_ATTR_MCF_OTA_BY_OP) == 0 ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_ATTR_NOT_SET(lid, lid_info.attr);
mcf_utfwk_printf("ERROR!! OTA by op attribute is not set! LID(%d), attribute(%x) \r\n", lid, lid_info.attr);
ret = MCF_OTA_R_INVALID_ATTR;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if (pFile->file_version == 2){
mcf_v1_read_tlvota_buffer_tag_update_flow(tlvota_file, tag_entry, tag_num, lid, buffer);
}else if (pFile->file_version == 3){
pItem = (mcf_tool_gid_tlvota_file_item_t *)(tlvota_file->buff + pFile->total_len);
/* Read changed items from TLV-OTA file */
while (item_cnt < pFile->item_num) {
/* Check if array_index_len is valid */
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_ARRAY_INDEX_LEN(pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
mcf_utfwk_printf("Invalid array_index_len(%d)!! max array_index_len(%d) \r\n", pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start)+pItem->tag_len, pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
/* Check if LID and tag match */
if ( (item_lid != lid) || (mcf_v2_check_tag_match(pItem, tag_entry, tag_num, &match_idx) == KAL_FALSE) ) {
goto next;
}
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &item_byte_offset, &item_bit_offset, &item_size, &item_is_bit) == KAL_FALSE){
goto next;
}
/* Update LID item */
if (item_is_bit == 0) {
if (pItem->value_len > item_size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_LARGE_VAL_LEN(pItem->value_len, item_size);
mcf_utfwk_printf("Invalid value len(%d)!! larger than current item len(%d) \r\n", pItem->value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_BYTE_UPDATE(lid, tag_entry[match_idx].tag, item_byte_offset, pItem->value_len);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_TLVOTA_BUFFER_MULTI_TAG_BYTE_UPDATE, lid, tag_entry[match_idx].tag, item_byte_offset, pItem->value_len);
mcf_dump_data(KAL_TRUE, &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
kal_mem_cpy( (buffer + item_byte_offset), &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
nv_int_info.update_general_tlvota_result = KAL_TRUE;
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_uint32 offset = 0;
kal_uint32 var_size = 1;
kal_uint32 val_tmp = 0;
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
if (pItem->value_len > 4) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_BIT_LEN(pItem->value_len, item_size, pItem->value_len);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_BIT_UPDATE(lid, tag_entry[match_idx].tag, item_byte_offset, item_bit_offset, item_size, pItem->value_len, bit_value);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_TLVOTA_BUFFER_MULTI_TAG_BIT_UPDATE, lid, tag_entry[match_idx].tag, item_byte_offset, item_bit_offset, item_size, pItem->value_len, bit_value);
if (item_size > 8 && item_size <= 16) {
var_size = 2;
}else if (item_size > 16 && item_size <= 24) {
var_size = 3;
}else if (item_size > 24 && item_size <= 32) {
var_size = 4;
}
if (item_bit_offset > 0 && item_bit_offset < 8) {
offset = 0;
}else if (item_bit_offset >= 8 && item_bit_offset < 16) {
offset = 1;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
offset = 2;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
offset = 3;
}else if (item_bit_offset >= 32){
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_BIT_OFFSET(item_bit_offset, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset > 0) {
if ((item_bit_offset) / 8 != (item_size + item_bit_offset) / 8) {
var_size += ((item_size + item_bit_offset) / 8 - item_bit_offset / 8);
}
}
if(var_size > 4){
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_INVALID_BIT_LEN(var_size, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset >= 8 && item_bit_offset < 16) {
item_bit_offset -= 8;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
item_bit_offset -= 16;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
item_bit_offset -= 24;
}
kal_mem_cpy(&val_tmp, buffer + item_byte_offset + offset, var_size);
val_tmp &= ~(bit_mask << item_bit_offset);
val_tmp |= (bit_value << item_bit_offset);
kal_mem_cpy(buffer + item_byte_offset + offset, &val_tmp, var_size);
nv_int_info.update_general_tlvota_result = KAL_TRUE;
}
next:
pItem = (mcf_tool_gid_tlvota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
} else {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_MULTI_TAG_TAKE_READ_LOCK_FAIL();
mcf_utfwk_printf("Fail to take read lock!! \r\n");
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_read_tlvota_buffer_sbp_multi_tag(
kal_uint8 ps_id,
mcf_tlvota_tag_t *tag_entry,
kal_uint32 tag_num,
nvram_lid_enum lid,
kal_uint8 *buffer,
kal_uint32 size)
{
mcf_t *pMcf = mcf_get_instance();
mcf_tool_file_info_t *pFile;
mcf_tool_gid_tlvota_file_item_t *pItem;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
mcf_tlvota_file_t *tlvota_file;
nvram_ltable_entry_struct lid_info;
kal_uint16 item_cnt = 0;
kal_uint32 match_idx;
nvram_errno_enum nvram_api_ret;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_bool item_is_bit = KAL_FALSE;
kal_uint16 item_lid;
ASSERT(buffer);
ASSERT(size > 0);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_START(ps_id, sim_id, tag_num);
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_INVALID_SIM_ID(ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
nvram_api_ret = nvram_external_get_lid_info(lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_GET_LID_INFO_FAIL(lid, nvram_api_ret);
mcf_utfwk_printf("Fail to get LID information!! LID(%d), nvram_api_ret(%d) \r\n", lid, nvram_api_ret);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if (size != lid_info.size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_INVALID_SIZE(size, lid, lid_info.size);
mcf_utfwk_printf("Invalid buffer_size(%d)!! LID(%d), record_size(%d) \r\n", size, lid, lid_info.size);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if ( (lid_info.attr & NVRAM_ATTR_MCF_OTA_BY_OP) == 0 ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_ATTR_NOT_SET(lid, lid_info.attr);
mcf_utfwk_printf("ERROR!! OTA by op attribute is not set! LID(%d), attribute(%x) \r\n", lid, lid_info.attr);
ret = MCF_OTA_R_INVALID_ATTR;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if (pFile->file_version == 2){
mcf_v1_read_tlvota_buffer_tag_update_flow(tlvota_file, tag_entry, tag_num, lid, buffer);
}else if (pFile->file_version == 3){
pItem = (mcf_tool_gid_tlvota_file_item_t *)(tlvota_file->buff + pFile->total_len);
/* Read changed items from TLV-OTA file */
while (item_cnt < pFile->item_num) {
/* Check if array_index_len is valid */
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_INVALID_ARRAY_INDEX_LEN(pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start)+pItem->tag_len, pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
/* Check if LID and tag match */
if ( (item_lid != lid) || (mcf_v2_check_tag_match(pItem, tag_entry, tag_num, &match_idx) == KAL_FALSE) ) {
goto next;
}
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &item_byte_offset, &item_bit_offset, &item_size, &item_is_bit) == KAL_FALSE){
goto next;
}
/* Update LID item */
if (item_is_bit == 0) {
if (pItem->value_len > item_size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_LARGE_VAL_LEN(pItem->value_len, item_size);
mcf_utfwk_printf("Invalid value len(%d)!! larger than current item len(%d) \r\n", pItem->value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_BYTE_UPDATE(lid, tag_entry[match_idx].tag, item_byte_offset, pItem->value_len);
mcf_dump_data(KAL_FALSE, &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
kal_mem_cpy( (buffer + item_byte_offset), &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
nv_int_info.update_tlvota_result[sim_id] = KAL_TRUE;
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_uint32 offset = 0;
kal_uint32 var_size = 1;
kal_uint32 val_tmp = 0;
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
if (pItem->value_len > 4) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_INVALID_BIT_LEN(pItem->value_len, item_size, pItem->value_len);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_BIT_UPDATE(lid, tag_entry[match_idx].tag, item_byte_offset, item_bit_offset, item_size, pItem->value_len, bit_value);
if (item_size > 8 && item_size <= 16) {
var_size = 2;
}else if (item_size > 16 && item_size <= 24) {
var_size = 3;
}else if (item_size > 24 && item_size <= 32) {
var_size = 4;
}
if (item_bit_offset > 0 && item_bit_offset < 8) {
offset = 0;
}else if (item_bit_offset >= 8 && item_bit_offset < 16) {
offset = 1;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
offset = 2;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
offset = 3;
}else if (item_bit_offset >= 32){
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_INVALID_BIT_OFFSET(item_bit_offset, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset > 0) {
if ((item_bit_offset) / 8 != (item_size + item_bit_offset) / 8) {
var_size += ((item_size + item_bit_offset) / 8 - item_bit_offset / 8);
}
}
if(var_size > 4){
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_INVALID_BIT_LEN(var_size, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset >= 8 && item_bit_offset < 16) {
item_bit_offset -= 8;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
item_bit_offset -= 16;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
item_bit_offset -= 24;
}
kal_mem_cpy(&val_tmp, buffer + item_byte_offset + offset, var_size);
val_tmp &= ~(bit_mask << item_bit_offset);
val_tmp |= (bit_value << item_bit_offset);
kal_mem_cpy(buffer + item_byte_offset + offset, &val_tmp, var_size);
nv_int_info.update_tlvota_result[sim_id] = KAL_TRUE;
}
next:
pItem = (mcf_tool_gid_tlvota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
} else {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_MULTI_TAG_TAKE_READ_LOCK_FAIL();
mcf_utfwk_printf("Fail to take read lock!! \r\n");
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_set_dsbp_mode(kal_bool is_ignore_dsbp, kal_bool is_general, sim_interface_enum sim_id)
{
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
MD_TRC_MCF_TR_SET_DSBP_MODE_START(is_ignore_dsbp, is_general, sim_id);
if(sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_SET_DSBP_MODE_INVALID_SIM_ID(sim_id);
}
kal_mem_set(&nv_int_info, 0, sizeof(nvram_ef_mcf_internal_info_struct));
/* Read MCF SW information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_SET_DSBP_MODE_READ_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
if (is_general == KAL_FALSE){
if(sim_id >= 0 && sim_id < MAX_SIM_NUM){
nv_int_info.tlvota_is_ignore_dsbp[sim_id] = is_ignore_dsbp;
}
}else{
nv_int_info.general_is_ignore_dsbp = is_ignore_dsbp;
}
/* Write MCF SW information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_SET_DSBP_MODE_WRITE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_set_not_reset(kal_bool not_reset, l4c_mcf_config_type_enum config_type, sim_interface_enum sim_id)
{
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_SET_NOT_RESET_INVALID_SIM_ID(sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
kal_mem_set(&nv_int_info, 0, sizeof(nvram_ef_mcf_internal_info_struct));
/* Read MCF SW information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_SET_NOT_RESET_READ_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
switch (config_type)
{
case L4C_MCF_CONFIG_TYPE_DEFAULT_BIN:
nv_int_info.not_reset_ota = not_reset;
break;
case L4C_MCF_CONFIG_TYPE_CARRIER_BIN:
nv_int_info.not_reset_tlvota[sim_id] = not_reset;
break;
case L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN:
nv_int_info.not_reset_general_tlvota = not_reset;
break;
default:
MD_TRC_MCF_TR_SET_NOT_RESET_INVALID_CONFIG_TYPE(config_type);
ret = KAL_FALSE;
break;
}
/* Write MCF SW information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_SET_NOT_RESET_WRITE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
return ret;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
_STATIC mcf_ota_result_e mcf_store_tlvota_modified_lid(sim_interface_enum sim_id, mcf_tlvota_sbp_tag_t sbp_tag, kal_bool is_general)
#else
_STATIC mcf_ota_result_e mcf_store_tlvota_modified_lid(sim_interface_enum sim_id, mcf_tlvota_sbp_tag_t sbp_tag, kal_bool is_general, kal_bool not_reset, kal_bool set_combined)
#endif
{
mcf_t *pMcf = mcf_get_instance();
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_tlvota_tag_t tag_entry[4];
kal_uint32 tag_num = 0;
kal_uint16 pre_LID = 0;
kal_int16 pos = -1;
kal_uint16 in_pos = 0;
mcf_tool_file_info_t *pFile;
mcf_tool_gid_tlvota_file_item_t *pItem;
nvram_ltable_entry_struct lid_info;
kal_uint16 item_cnt = 0;
kal_uint32 match_idx;
nvram_errno_enum nvram_api_ret;
kal_uint16 dummy_byte_offset;
kal_uint16 dummy_bit_offset;
kal_uint32 dummy_size;
kal_bool dummy_is_bit;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_uint16 item_lid = 65535;
mcf_tlvota_file_t *tlvota_file;
mcf_tlvota_tag_t iccid_tag;
kal_char iccid[21];
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_START(sim_id, sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc, is_general);
#if defined(__MCF_COMBINE_FILE_SUPPORT__)
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_NOT_RESET(not_reset);
#endif
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_INVALID_SIM_ID(sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
kal_mem_set(tag_entry, 0, sizeof(mcf_tlvota_tag_t) * 4);
kal_mem_set(&mcf_tlvota_curr_mod_lid_g[sim_id], 0, sizeof(nvram_ef_mcf_tlvota_file_info_struct));
kal_mem_set(&mcf_general_tlvota_curr_mod_lid_g[sim_id], 0, sizeof(nvram_ef_mcf_tlvota_file_info_struct));
kal_mem_set(&iccid_tag, 0, sizeof(mcf_tlvota_tag_t));
ret = mcf_fill_tag_entry(sbp_tag, is_general, tag_entry, &tag_num);
if (ret != MCF_OTA_R_SUCCESS){
return ret;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
if (is_general == KAL_TRUE){
if (com_Mcf.is_iccid == KAL_TRUE){
kal_mem_set(&iccid_tag, 0, sizeof(mcf_tlvota_tag_t));
iccid_tag.tag_type = MCF_TLVOTA_TAG_ICCID;
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
kal_mem_cpy(&iccid, tlvota_file->iccid, 21);
iccid_tag.tag = iccid;
iccid_tag.tag_len = strlen((kal_char *)tlvota_file->iccid);
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_TAKE_READ_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return ret;
}
}
tlvota_file = &(pMcf->general_tlvota_file);
}
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
if (pFile->file_version == 3){
pItem = (mcf_tool_gid_tlvota_file_item_t *)(tlvota_file->buff + pFile->total_len);
/* Read changed LID from TLV-OTA file */
while (item_cnt < pFile->item_num) {
/* Check if array_index_len is valid */
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_INVALID_ARRAY_INDEX_LEN(pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start)+pItem->tag_len, pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
if ( (item_lid == pre_LID)){
goto next;
}
/* Check if LID and tag match */
if ((mcf_v2_check_tag_match(pItem, tag_entry, tag_num, &match_idx) == KAL_FALSE) ) {
if (com_Mcf.is_iccid == KAL_TRUE){
if ((pItem->tag_type != iccid_tag.tag_type) || (strncmp(&(pItem->buff_start), iccid_tag.tag, pItem->tag_len) != 0) ) {
goto next;
}
}else{
goto next;
}
}
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &dummy_byte_offset, &dummy_bit_offset, &dummy_size, &dummy_is_bit) == KAL_FALSE){
goto next;
}
/* Store last time modified LID */
nvram_api_ret = nvram_external_get_lid_info(item_lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_GET_LID_INFO_FAIL(item_lid, nvram_api_ret);
ret = KAL_FALSE;
goto next;
}
if ( ((lid_info.attr & NVRAM_ATTR_MCF_OTA_BY_OP) != 0)) {
if (((lid_info.attr & NVRAM_ATTR_OTA_RESET) == 0)){
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_RESET_ATTR_NOT_SET(item_lid, lid_info.attr);
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
if (is_general == KAL_FALSE){
if (mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid(item_lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &in_pos);
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID(item_lid, pos);
if (pos == -1) {
if(mcf_insert_lid(item_lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt, in_pos) != KAL_TRUE){
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID_FAIL(item_lid);
}else{
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_STORE_LID(item_lid, in_pos, sim_id);
}
mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt++;
}
}
}else{
if (mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid(item_lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &in_pos);
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID(item_lid, pos);
if (pos == -1) {
if(mcf_insert_lid(item_lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt, in_pos) != KAL_TRUE){
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID_FAIL(item_lid);
}else{
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_STORE_LID(item_lid, in_pos, sim_id);
}
mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt++;
}
}
}
#else
if (is_general == KAL_FALSE){
if (mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid_struct(item_lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid_conf, mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &in_pos);
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID(item_lid, pos);
if (pos == -1) {
if(mcf_insert_lid_struct(item_lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid_conf, mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt, in_pos, not_reset, set_combined) != KAL_TRUE){
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID_FAIL(item_lid);
}else{
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_STORE_LID(item_lid, in_pos, sim_id);
}
mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt++;
}
}
}else{
if (mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid_struct(item_lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_conf, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &in_pos);
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID(item_lid, pos);
if (pos == -1) {
if(mcf_insert_lid_struct(item_lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_conf, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt, in_pos, not_reset, set_combined) != KAL_TRUE){
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_SEARCH_STORE_LID_FAIL(item_lid);
}else{
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_STORE_LID(item_lid, in_pos, sim_id);
}
mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt++;
}
}
}
#endif
}
next:
pre_LID = item_lid;
pItem = (mcf_tool_gid_tlvota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
}else{
//File version is not 3
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_INVALID_FILE_VERSION(pFile->file_version);
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
} else {
MD_TRC_MCF_TR_STORE_TLVOTA_MODIFIED_LID_TAKE_READ_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
return ret;
}
_STATIC void mcf_em_send_ota_file_info(em_mcf_read_ota_file_info_struct *read_file_info)
{
ilm_struct ilm;
em_mcf_ota_file_info_ind_struct *em_para_ptr = NULL;
if (com_Mcf.is_em_on == KAL_TRUE) {
em_para_ptr = (em_mcf_ota_file_info_ind_struct *)construct_local_para(sizeof(em_mcf_ota_file_info_ind_struct), TD_RESET);
em_para_ptr->em_info = MCF_EM_OTA_FILE_INFO;
kal_mem_cpy(&(em_para_ptr->read_file_info), read_file_info, sizeof(em_mcf_read_ota_file_info_struct));
ilm.src_mod_id = MOD_MCF;
ilm.dest_mod_id = MOD_DHL;
ilm.msg_id = MSG_ID_EM_MCF_OTA_FILE_INFO_IND;
ilm.sap_id = EM_PS_SAP;
ilm.local_para_ptr = (local_para_struct *)em_para_ptr;
ilm.peer_buff_ptr = NULL;
dhl_EM_logger(&ilm);
destroy_ilm(&ilm);
} else {
#ifdef __MT_FRAMEWORK_SUPPORT__
if (kal_query_systemInit() == KAL_TRUE) {
/* EM switch may not be ON in init stage */
em_para_ptr = (em_mcf_ota_file_info_ind_struct *)construct_local_para(sizeof(em_mcf_ota_file_info_ind_struct), TD_RESET);
em_para_ptr->em_info = MCF_EM_OTA_FILE_INFO;
kal_mem_cpy(&(em_para_ptr->read_file_info), read_file_info, sizeof(em_mcf_read_ota_file_info_struct));
msg_send6(MOD_MCF, /* src_mod_id */
MOD_MT, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_EM_MCF_OTA_FILE_INFO_IND, /* msg_id */
(local_para_struct*)em_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
}
#endif
}
}
#ifdef __MCF_COMBINE_FILE_SUPPORT__
_STATIC mcf_ota_result_e mcf_combined_ota_file(l4c_mcf_set_config_req_struct *req)
{
mcf_t *pMcf = mcf_get_instance();
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
kal_uint32 i;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
mcf_tool_file_info_t *pFile;
kal_int32 fs_ret = FS_NO_ERROR;
static nvram_ef_mcf_ota_file_info_struct nv_ota_file;
static nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
static kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
static kal_char curr_filename[MCF_FILE_MAX_NAME_LEN];
static kal_wchar filename[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
kal_int32 fs_api_ret;
static kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type;
em_mcf_read_ota_file_info_struct read_file_info;
kal_bool read_file_fail = KAL_FALSE;
kal_mem_set(mcf_file_buffer, 0, MCF_MAX_FILE_SIZE);
kal_mem_set(mcf_merge_buffer, 0, MCF_MAX_FILE_SIZE);
kal_mem_set(curr_filename, 0, MCF_FILE_MAX_NAME_LEN);
kal_mem_set(fs_root_path, 0, MCF_FILE_MAX_MD_PATH_LEN);
switch (req->config_type)
{
case L4C_MCF_CONFIG_TYPE_DEFAULT_BIN:
{
mcf_ota_file_t *ota_file = &(pMcf->ota_file);
kal_uint16 pre_LID = 0;
kal_int16 pos = -1;
kal_uint16 in_pos = 0;
mcf_tool_gid_ota_file_item_t *pItem;
nvram_ltable_entry_struct lid_info;
kal_uint16 item_cnt = 0;
nvram_errno_enum nvram_api_ret;
kal_uint16 dummy_byte_offset;
kal_uint16 dummy_bit_offset;
kal_uint32 dummy_size;
kal_bool dummy_is_bit;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_uint16 item_lid;
if (strcmp((kal_char *)req->config1, "") != 0) {
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_MD_PATH_LEN - 1);
/* Check if file is existed */
kal_wsprintf(filename, "%s\\%s\0", fs_root_path, curr_filename);
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_FILE_NOT_EXIST(fs_root_path, curr_filename);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
}
/* Write MCF OTA file information to NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
if(req->reset == KAL_TRUE){
//Need to reset LID
nv_int_info.not_reset_ota = KAL_FALSE;
//Clear LIDs which is add due to combine
if(mcf_clear_last_modified_lid(nv_int_info.last_mod_lid.lid_conf, &nv_int_info.last_mod_lid.lid_cnt) != KAL_TRUE){
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
/* Combine OTA file - Only apply one OTA file */
ret = mcf_read_ota_file(KAL_FALSE, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
/*Store LID which need to reset into last modified buffer*/
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
/* Check if file type is OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_OTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
if (pFile->file_version == 3){
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
pItem = (mcf_tool_gid_ota_file_item_t *)(ota_file->buff + pFile->total_len);
/* Read changed items from OTA file */
while (item_cnt < pFile->item_num) {
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_ARRAY_INDEX_LEN(pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start), pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
if ( (item_lid == pre_LID)){
goto next;
}
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &dummy_byte_offset, &dummy_bit_offset, &dummy_size, &dummy_is_bit) == KAL_FALSE){
goto next;
}
/* Store last time modified LID */
nvram_api_ret = nvram_external_get_lid_info(item_lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_GET_LID_INFO_FAIL(item_lid, nvram_api_ret);
ret = MCF_OTA_R_INVALID_PARAMETER;
goto next;
}
/* Store reset LIDs into last time modified LID */
if ( ((lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0)
&& (((lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) || ((lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0)) ) {
if (nv_int_info.last_mod_lid.lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid_struct(item_lid, nv_int_info.last_mod_lid.lid_conf, nv_int_info.last_mod_lid.lid_cnt, &in_pos);
MD_TRC_MCF_TR_COMBINED_OTA_FILE_SEARCH_STORE_LID(item_lid, pos);
if (pos == -1) {
if(mcf_insert_lid_struct(item_lid, nv_int_info.last_mod_lid.lid_conf, nv_int_info.last_mod_lid.lid_cnt, in_pos, KAL_FALSE, KAL_TRUE) != KAL_TRUE){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_STORE_LID_FAIL(item_lid);
}else{
MD_TRC_MCF_TR_COMBINED_OTA_FILE_STORE_LID(item_lid, in_pos);
}
nv_int_info.last_mod_lid.lid_cnt++;
}
}
}
next:
pre_LID = item_lid;
pItem = (mcf_tool_gid_ota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}
}else{
//Do not Need to reset LID
nv_int_info.not_reset_ota = KAL_TRUE;
/* Combine OTA file - Append OTA file*/
for(i = 0; i < nv_int_info.last_mod_lid.lid_cnt; i++){
if(nv_int_info.last_mod_lid.lid_conf[i].not_reset == KAL_FALSE && nv_int_info.last_mod_lid.lid_conf[i].set_combined == KAL_FALSE){
nv_int_info.last_mod_lid.lid_conf[i].not_reset = KAL_TRUE;
}
}
ret = mcf_read_ota_file(KAL_FALSE, nv_ota_file.path, nv_ota_file.name, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(nv_ota_file.path, nv_ota_file.name);
read_file_fail = KAL_TRUE;
}
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
/* Check if file type is OTA file */ //If not OTA file, Construct empty file header
if (read_file_fail == KAL_TRUE || strcmp(pFile->file_type, MCF_FILE_TYPE_OTA) != 0) {
mcf_tool_file_info_t copy_header = {0};
mcf_tool_file_info_t *output_header = (mcf_tool_file_info_t *)mcf_file_buffer;
MD_TRC_MCF_TR_COMBINED_OTA_FILE_MERGE_OTA_FILE();
kal_mem_set(mcf_file_buffer, 0, MCF_MAX_FILE_SIZE);
copy_header.file_version = 3;
copy_header.operation_mask = 0;
mcf_merge_make_ota_file_header(output_header, &copy_header); // copy first header to output header
kal_mem_set(output_header->file_type, 0, 8);
strncpy(output_header->file_type, MCF_FILE_TYPE_OTA, 7);
output_header->item_num = 0;
output_header->file_size = (kal_uint32)((kal_uint8 *)mcf_file_buffer + output_header->total_len - (kal_uint8 *)output_header);
}else{
kal_mem_cpy(mcf_file_buffer, ota_file->buff, MCF_MAX_OTA_FILE_SIZE);
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
}
ret = mcf_read_ota_file(KAL_FALSE, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
/* Check if file type is OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_OTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
if(mcf_merge_ota_buffer(mcf_file_buffer, ota_file->buff, mcf_merge_buffer, MCF_MAX_OTA_FILE_SIZE) != KAL_TRUE){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_MERGE_OTA_FILE_FAIL();
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
}
strncpy(fs_root_path, nv_ota_file.merged_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(curr_filename, nv_ota_file.merged_name, MCF_FILE_MAX_NAME_LEN - 1);
/* Before create merged OTA file, need to delete last time merged OTA file */
kal_wsprintf(merge_ota_name, "%s\\%s\0", fs_root_path, curr_filename);
fs_ret = FS_Delete(merge_ota_name);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_DELETE_FILE_FAIL(fs_ret);
ret = MCF_OTA_R_WRITE_DISK_FAIL;
return ret;
}
pFile = (mcf_tool_file_info_t *)(mcf_merge_buffer);
if(pFile->file_size > MCF_MAX_OTA_FILE_SIZE){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE_SIZE(pFile->file_size, MCF_MAX_OTA_FILE_SIZE);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
ret = mcf_write_buffer(fs_root_path, curr_filename, (kal_uint8 *)mcf_merge_buffer, pFile->file_size);
if (ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}
strncpy(nv_ota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
}else{
/*Deactivate Combine OTA setting */
kal_mem_set(fs_root_path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(curr_filename, 0, MCF_FILE_MAX_NAME_LEN);
kal_mem_set(nv_ota_file.path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(nv_ota_file.name, 0, MCF_FILE_MAX_NAME_LEN);
kal_mem_set(nv_ota_file.merged_path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(nv_ota_file.merged_name, 0, MCF_FILE_MAX_NAME_LEN);
nv_int_info.is_combined_ota = KAL_FALSE;
//Need to reset LID
nv_int_info.not_reset_ota = KAL_FALSE;
for(i = 0; i < nv_int_info.last_mod_lid.lid_cnt; i++){
if(nv_int_info.last_mod_lid.lid_conf[i].not_reset == KAL_TRUE){
nv_int_info.last_mod_lid.lid_conf[i].not_reset = KAL_FALSE;
}
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_TYPE_CARRIER_BIN:
{
mcf_tlvota_file_t *tlvota_file;
mcf_tlvota_sbp_tag_t sbp_tag;
MD_TRC_MCF_TR_COMBINED_OTA_FILE_TLVOTA_START(sim_id);
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_SIM_ID(req->ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
if (strcmp((kal_char *)req->config1, "") != 0) {
if (pMcf->is_ignore_dsbp[sim_id] == KAL_FALSE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
ret = mcf_set_dsbp_mode(KAL_TRUE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_TRUE;
}
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_MD_PATH_LEN - 1);
/* Check if file is existed */
kal_wsprintf(filename, "%s\\%s\0", fs_root_path, curr_filename);
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_FILE_NOT_EXIST(fs_root_path, curr_filename);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
if(req->reset == KAL_TRUE){
//Need to reset LID
nv_int_info.not_reset_tlvota[sim_id] = KAL_FALSE;
//Clear LIDs which is add due to combine
if(mcf_clear_last_modified_lid(nv_int_info.tlvota_last_mod_lid[sim_id].lid_conf, &nv_int_info.tlvota_last_mod_lid[sim_id].lid_cnt) != KAL_TRUE){
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
/* Combine OTA file - Only apply one OTA file */
ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
sbp_tag.sbp_id = tlvota_file->sbp_id;
kal_mem_cpy(sbp_tag.mcc, tlvota_file->mcc, MAX_MCC_STR_LEN);
kal_mem_cpy(sbp_tag.mnc, tlvota_file->mnc, MAX_MNC_STR_LEN);
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_TAKE_READ_LOCK_FAIL();
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
ret = mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_FALSE, KAL_FALSE, KAL_TRUE);
kal_mem_cpy(&mcf_tlvota_last_mod_lid_g[sim_id], &nv_int_info.tlvota_last_mod_lid[sim_id], sizeof(nvram_mcf_lid_info_struct));
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_STORE_LAST_LID_FAIL();
return ret;
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}else{
//Do not need to reset LID
nv_int_info.not_reset_tlvota[sim_id] = KAL_TRUE;
/* Combine OTA file - Append OTA file*/
for(i = 0; i < nv_int_info.tlvota_last_mod_lid[sim_id].lid_cnt; i++){
if(nv_int_info.tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset == KAL_FALSE && nv_int_info.tlvota_last_mod_lid[sim_id].lid_conf[i].set_combined == KAL_FALSE){
nv_int_info.tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset = KAL_TRUE;
}
}
ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, nv_tlvota_file.path, nv_tlvota_file.name, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(nv_tlvota_file.path, nv_tlvota_file.name);
read_file_fail = KAL_TRUE;
}
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */ //If not TLVOTA file, Construct empty file header
if (read_file_fail == KAL_TRUE || strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
mcf_tool_file_info_t copy_header = {0};
mcf_tool_file_info_t *output_header = (mcf_tool_file_info_t *)mcf_file_buffer;
MD_TRC_MCF_TR_COMBINED_OTA_FILE_MERGE_OTA_FILE();
kal_mem_set(mcf_file_buffer, 0, MCF_MAX_FILE_SIZE);
copy_header.file_version = 3;
copy_header.operation_mask = 0;
mcf_merge_make_ota_file_header(output_header, &copy_header); // copy first header to output header
kal_mem_set(output_header->file_type, 0, 8);
strncpy(output_header->file_type, MCF_FILE_TYPE_TLVOTA, 7);
output_header->item_num = 0;
output_header->file_size = (kal_uint32)((kal_uint8 *)mcf_file_buffer + output_header->total_len - (kal_uint8 *)output_header);
}else{
kal_mem_cpy(mcf_file_buffer, tlvota_file->buff, MCF_MAX_TLVOTA_FILE_SIZE);
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if(mcf_merge_ota_buffer(mcf_file_buffer, tlvota_file->buff, mcf_merge_buffer, MCF_MAX_TLVOTA_FILE_SIZE) != KAL_TRUE){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_MERGE_OTA_FILE_FAIL();
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
strncpy(fs_root_path, nv_tlvota_file.merged_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(curr_filename, nv_tlvota_file.merged_name, MCF_FILE_MAX_NAME_LEN - 1);
/* Before create merged OTA file, need to delete last time merged OTA file */
kal_wsprintf(merge_ota_name, "%s\\%s\0", fs_root_path, curr_filename);
fs_ret = FS_Delete(merge_ota_name);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_DELETE_FILE_FAIL(fs_ret);
ret = MCF_OTA_R_WRITE_DISK_FAIL;
return ret;
}
pFile = (mcf_tool_file_info_t *)(mcf_merge_buffer);
if(pFile->file_size > MCF_MAX_TLVOTA_FILE_SIZE){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE_SIZE(pFile->file_size, MCF_MAX_TLVOTA_FILE_SIZE);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
ret = mcf_write_buffer(fs_root_path, curr_filename, (kal_uint8 *)mcf_merge_buffer, pFile->file_size);
if (ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}
if (req->trigger_dsbp == 1) {
/* Read TLV-OTA file */
kal_mem_set(&read_file_info, 0, sizeof(em_mcf_read_ota_file_info_struct));
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_AP;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_CARRIER_BIN;
read_file_info.ps_id = req->ps_id;
read_file_info.start_time = kal_get_systicks();
ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
// Store Read TLV-OTA file result for dsbp urc use
set_op_read_ret[sim_id] = ret;
if (ret == MCF_OTA_R_SUCCESS) {
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
read_file_info.path_type = tlvota_file->path_type;
strncpy(read_file_info.file_name, (kal_char *)&(tlvota_file->relative_path_name), MCF_FILE_MAX_NAME_LEN - 1);
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
is_read_tlvota[sim_id] = KAL_TRUE;
} else {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
}
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
}
strncpy(nv_tlvota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
}else{
/*Deactivate Combine OTA setting */
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
ret = mcf_set_dsbp_mode(KAL_FALSE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_FALSE;
}
kal_mem_set(fs_root_path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(curr_filename, 0, MCF_FILE_MAX_NAME_LEN);
kal_mem_set(nv_tlvota_file.path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(nv_tlvota_file.name, 0, MCF_FILE_MAX_NAME_LEN);
/* Deactivate TLV-OTA setting, reset combined setting */
nv_int_info.is_combined_tlvota[sim_id] = KAL_FALSE;
kal_mem_set(nv_tlvota_file.merged_path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(nv_tlvota_file.merged_name, 0, MCF_FILE_MAX_NAME_LEN);
//Need to reset LID
nv_int_info.not_reset_tlvota[sim_id] = KAL_FALSE;
for(i = 0; i < nv_int_info.tlvota_last_mod_lid[sim_id].lid_cnt; i++){
if(nv_int_info.tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset == KAL_TRUE){
nv_int_info.tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset = KAL_FALSE;
}
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if (req->trigger_dsbp == 1) {
/* Deactivate TLV-OTA setting, reset TLV-OTA buffer */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
kal_mem_set(tlvota_file->buff, 0, sizeof(kal_uint8) * MCF_MAX_TLVOTA_FILE_SIZE);
tlvota_file->path_type = req->path_type;
strncpy(tlvota_file->relative_path_name, "", MCF_FILE_MAX_NAME_LEN - 1);
kal_mem_set(&(tlvota_file->last_file), 0, sizeof(mcf_file_info_t));
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_RESET_BUFFER_FAIL();
}
is_read_tlvota[sim_id] = KAL_TRUE;
}
}
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN:
{
mcf_tlvota_file_t *tlvota_file = &(pMcf->general_tlvota_file);
mcf_tlvota_sbp_tag_t sbp_tag;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_SIM_ID(req->ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
if (pMcf->general_is_ignore_dsbp == KAL_FALSE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
ret = mcf_set_dsbp_mode(KAL_TRUE, KAL_TRUE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->general_is_ignore_dsbp = KAL_TRUE;
}
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_MD_PATH_LEN - 1);
/* Check if file is existed */
kal_wsprintf(filename, "%s\\%s\0", fs_root_path, curr_filename);
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_FILE_NOT_EXIST(fs_root_path, curr_filename);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
if(req->reset == KAL_TRUE){
//Need to reset LID
nv_int_info.not_reset_general_tlvota = KAL_FALSE;
//Clear LIDs which is add due to combine
if(mcf_clear_last_modified_lid(nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_conf, &nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_cnt) != KAL_TRUE){
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
/* Combine OTA file - Only apply one OTA file */
ret = mcf_read_general_tlvota_file(KAL_FALSE, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
sbp_tag.sbp_id = tlvota_file->sbp_id;
kal_mem_cpy(sbp_tag.mcc, tlvota_file->mcc, MAX_MCC_STR_LEN);
kal_mem_cpy(sbp_tag.mnc, tlvota_file->mnc, MAX_MNC_STR_LEN);
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_TAKE_READ_LOCK_FAIL();
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
tlvota_file = &(pMcf->general_tlvota_file);
ret = mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_TRUE, KAL_FALSE, KAL_TRUE);
kal_mem_cpy(&mcf_general_tlvota_last_mod_lid_g[sim_id], &nv_int_info.general_tlvota_last_mod_lid[sim_id], sizeof(nvram_mcf_lid_info_struct));
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_STORE_LAST_LID_FAIL();
return ret;
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}else{
//Do not need to reset LID
nv_int_info.not_reset_general_tlvota = KAL_TRUE;
/* Combine OTA file - Append OTA file*/
for(i = 0; i < nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_cnt; i++){
if(nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset == KAL_FALSE && nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_conf[i].set_combined == KAL_FALSE){
nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset = KAL_TRUE;
}
}
ret = mcf_read_general_tlvota_file(KAL_FALSE, nv_tlvota_file.path, nv_tlvota_file.name, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(nv_tlvota_file.path, nv_tlvota_file.name);
read_file_fail = KAL_TRUE;
}
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */ //If not TLVOTA file, Construct empty file header
if (read_file_fail == KAL_TRUE || strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
mcf_tool_file_info_t copy_header = {0};
mcf_tool_file_info_t *output_header = (mcf_tool_file_info_t *)mcf_file_buffer;
MD_TRC_MCF_TR_COMBINED_OTA_FILE_MERGE_OTA_FILE();
kal_mem_set(mcf_file_buffer, 0, MCF_MAX_FILE_SIZE);
copy_header.file_version = 3;
copy_header.operation_mask = 0;
mcf_merge_make_ota_file_header(output_header, &copy_header); // copy first header to output header
kal_mem_set(output_header->file_type, 0, 8);
strncpy(output_header->file_type, MCF_FILE_TYPE_TLVOTA, 7);
output_header->item_num = 0;
output_header->file_size = (kal_uint32)((kal_uint8 *)mcf_file_buffer + output_header->total_len - (kal_uint8 *)output_header);
}else{
kal_mem_cpy(mcf_file_buffer, tlvota_file->buff, MCF_MAX_TLVOTA_FILE_SIZE);
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
ret = mcf_read_general_tlvota_file(KAL_FALSE, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
if(ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if(mcf_merge_ota_buffer(mcf_file_buffer, tlvota_file->buff, mcf_merge_buffer, MCF_MAX_TLVOTA_FILE_SIZE) != KAL_TRUE){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_MERGE_OTA_FILE_FAIL();
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
strncpy(fs_root_path, nv_tlvota_file.merged_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(curr_filename, nv_tlvota_file.merged_name, MCF_FILE_MAX_NAME_LEN - 1);
/* Before create merged OTA file, need to delete last time merged OTA file */
kal_wsprintf(merge_ota_name, "%s\\%s\0", fs_root_path, curr_filename);
fs_ret = FS_Delete(merge_ota_name);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_DELETE_FILE_FAIL(fs_ret);
ret = MCF_OTA_R_WRITE_DISK_FAIL;
return ret;
}
pFile = (mcf_tool_file_info_t *)(mcf_merge_buffer);
if(pFile->file_size > MCF_MAX_TLVOTA_FILE_SIZE){
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_FILE_SIZE(pFile->file_size, MCF_MAX_TLVOTA_FILE_SIZE);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
ret = mcf_write_buffer(fs_root_path, curr_filename, (kal_uint8 *)mcf_merge_buffer, pFile->file_size);
if (ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_FAIL(fs_root_path, curr_filename);
return ret;
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}
if (req->trigger_dsbp == 1) {
/* Read general TLV-OTA file */
kal_mem_set(&read_file_info, 0, sizeof(em_mcf_read_ota_file_info_struct));
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_AP;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN;
read_file_info.ps_id = req->ps_id;
read_file_info.start_time = kal_get_systicks();
ret = mcf_read_general_tlvota_file(KAL_FALSE, fs_root_path, curr_filename, &apply_path_type, apply_filename, pMcf);
if (ret == MCF_OTA_R_SUCCESS) {
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
read_file_info.path_type = tlvota_file->path_type;
strncpy(read_file_info.file_name, (kal_char *)&(tlvota_file->relative_path_name), MCF_FILE_MAX_NAME_LEN - 1);
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
for(i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
}
} else {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_READ_FILE_FAIL(fs_root_path, curr_filename);
}
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
}
strncpy(nv_tlvota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
}else{
/*Deactivate Combine OTA setting */
if (pMcf->general_is_ignore_dsbp == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_dsbp_mode(KAL_FALSE, KAL_TRUE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->general_is_ignore_dsbp = KAL_FALSE;
}
kal_mem_set(fs_root_path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(curr_filename, 0, MCF_FILE_MAX_NAME_LEN);
kal_mem_set(nv_tlvota_file.path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(nv_tlvota_file.name, 0, MCF_FILE_MAX_NAME_LEN);
/* Deactivate TLV-OTA setting, reset combined setting */
nv_int_info.is_combined_general_tlvota = KAL_FALSE;
kal_mem_set(nv_tlvota_file.merged_path, 0, MCF_FILE_MAX_MD_PATH_LEN);
kal_mem_set(nv_tlvota_file.merged_name, 0, MCF_FILE_MAX_NAME_LEN);
//Need to reset LID
nv_int_info.not_reset_general_tlvota = KAL_FALSE;
for(i = 0; i < nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_cnt; i++){
if(nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset == KAL_TRUE){
nv_int_info.general_tlvota_last_mod_lid[sim_id].lid_conf[i].not_reset = KAL_FALSE;
}
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if (req->trigger_dsbp == 1) {
/* Deactivate general TLV-OTA setting, reset general TLV-OTA buffer */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
kal_mem_set(tlvota_file->buff, 0, sizeof(kal_uint8) * MCF_MAX_TLVOTA_FILE_SIZE);
tlvota_file->path_type = req->path_type;
strncpy(tlvota_file->relative_path_name, "", MCF_FILE_MAX_NAME_LEN - 1);
tlvota_file->last_mod_time = 0;
kal_mem_set(&(tlvota_file->last_file), 0, sizeof(mcf_file_info_t));
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_RESET_BUFFER_FAIL();
}
for(i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
}
}
}
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_COMBINED_OTA_FILE_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
default:
{
MD_TRC_MCF_TR_COMBINED_OTA_FILE_INVALID_CONFIG_TYPE(req->config_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
}
return ret;
}
#endif
_STATIC mcf_ota_result_e mcf_set_file_path(l4c_mcf_set_config_req_struct *req)
{
mcf_t *pMcf = mcf_get_instance();
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_tool_file_info_t *pFile;
kal_uint32 i = 0;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_SIM_ID(req->ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
switch (req->op)
{
case L4C_MCF_CONFIG_SET_OTA_AND_OPOTA_FILE_PATH:
{
nvram_ef_mcf_ota_file_info_struct nv_ota_file;
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_dsbp_mode(KAL_FALSE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_FALSE;
}
/* Read MCF OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
MD_TRC_MCF_TR_SET_OTA_FILE_PATH_AP((kal_char *)req->config1, (kal_char *)req->config2);
if (strcmp((kal_char *)req->config1, "") != 0) {
strncpy(nv_ota_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, (kal_char *)req->config2, MCF_FILE_MAX_NAME_LEN - 1);
} else {
strncpy(nv_ota_file.path, "", MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, "", MCF_FILE_MAX_NAME_LEN - 1);
}
MD_TRC_MCF_TR_SET_OTA_FILE_PATH_MD((kal_char *)nv_ota_file.path, (kal_char *)nv_ota_file.name);
/* Write MCF OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = KAL_FALSE;
return MCF_OTA_R_READ_NVRAM_FAIL;
}
MD_TRC_MCF_TR_SET_TLVOTA_FILE_PATH_AP((kal_char *)req->config3, (kal_char *)req->config4, req->ps_id);
if (strcmp((kal_char *)req->config3, "") != 0) {
strncpy(nv_tlvota_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, (kal_char *)req->config4, MCF_FILE_MAX_NAME_LEN - 1);
} else {
strncpy(nv_tlvota_file.path, "", MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, "", MCF_FILE_MAX_NAME_LEN - 1);
}
MD_TRC_MCF_TR_SET_TLVOTA_FILE_PATH_MD((kal_char *)nv_tlvota_file.path, (kal_char *)nv_tlvota_file.name, sim_id);
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_SET_OTA_FILE_PATH:
{
nvram_ef_mcf_ota_file_info_struct nv_ota_file;
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_dsbp_mode(KAL_FALSE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_FALSE;
}
/* Read MCF OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
MD_TRC_MCF_TR_SET_OTA_FILE_PATH_AP((kal_char *)req->config1, (kal_char *)req->config2);
if (strcmp((kal_char *)req->config1, "") != 0) {
strncpy(nv_ota_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, (kal_char *)req->config2, MCF_FILE_MAX_NAME_LEN - 1);
} else {
strncpy(nv_ota_file.path, "", MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, "", MCF_FILE_MAX_NAME_LEN - 1);
}
MD_TRC_MCF_TR_SET_OTA_FILE_PATH_MD((kal_char *)nv_ota_file.path, (kal_char *)nv_ota_file.name);
/* Write MCF OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_SET_OPOTA_FILE_PATH:
{
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_dsbp_mode(KAL_FALSE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_FALSE;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
MD_TRC_MCF_TR_SET_TLVOTA_FILE_PATH_AP((kal_char *)req->config1, (kal_char *)req->config2, req->ps_id);
if (strcmp((kal_char *)req->config1, "") != 0) {
strncpy(nv_tlvota_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, (kal_char *)req->config2, MCF_FILE_MAX_NAME_LEN - 1);
} else {
strncpy(nv_tlvota_file.path, "", MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, "", MCF_FILE_MAX_NAME_LEN - 1);
}
MD_TRC_MCF_TR_SET_TLVOTA_FILE_PATH_MD((kal_char *)nv_tlvota_file.path, (kal_char *)nv_tlvota_file.name, sim_id);
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_SET_FILE_PATH_IN_MCF_DSBP_ACTIVE_MODE:
{
if (pMcf->is_ignore_dsbp[sim_id] == KAL_FALSE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
ret = mcf_set_dsbp_mode(KAL_TRUE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_TRUE;
}
pMcf->dsbp_cnf_ret = KAL_TRUE;
pMcf->dsbp_ind_ret = KAL_TRUE;
switch (req->config_type)
{
case L4C_MCF_CONFIG_TYPE_DEFAULT_BIN:
{
nvram_ef_mcf_ota_file_info_struct nv_ota_file;
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char curr_filename[MCF_FILE_MAX_NAME_LEN];
kal_wchar filename[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
kal_bool is_get_custom_filename = KAL_FALSE;
kal_int32 fs_api_ret;
kal_uint8 path_type;
if (nv_int_info.not_reset_ota == KAL_TRUE) {
/* If MCF is in not reset mode, change to reset mode */
ret = mcf_set_not_reset(KAL_FALSE, req->config_type, 0);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
nv_int_info.not_reset_ota = KAL_FALSE;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
is_get_custom_filename = mcf_get_custom_file_path_name(&path_type, curr_filename);
if (is_get_custom_filename == KAL_TRUE) {
if (path_type >= L4C_MCF_PATH_TYPE_MAX) {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if (path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
}
} else {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(curr_filename, MCF_FS_DEFAULT_OTA_FILE_NAME, MCF_FILE_MAX_MD_PATH_LEN - 1);
}
}
/* Check if file is existed */
kal_wsprintf(filename, "%s\\%s\0", fs_root_path, curr_filename);
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_SET_FILE_PATH_FILE_NOT_EXIST(fs_root_path, curr_filename);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Write MCF OTA file information to NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_ota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_TYPE_CARRIER_BIN:
{
mcf_tlvota_file_t *tlvota_file;
mcf_tool_file_info_t *pFile;
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
em_mcf_read_ota_file_info_struct read_file_info;
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_wchar filename[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type;
kal_int32 fs_api_ret;
if (nv_int_info.not_reset_tlvota[sim_id] == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_not_reset(KAL_FALSE, req->config_type, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
nv_int_info.not_reset_tlvota[sim_id] = KAL_FALSE;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
if (strcmp((kal_char *)req->config1, "") != 0) {
/* Check if file is existed */
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
kal_wsprintf(filename, "%s\\%s\0", MCF_FS_DEFAULT_FOLDER_PATH, req->config1);
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
kal_wsprintf(filename, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, req->config1);
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_SET_FILE_PATH_FILE_NOT_EXIST(fs_root_path, req->config1);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_tlvota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, (kal_char *)req->config1, MCF_FILE_MAX_NAME_LEN - 1);
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
kal_mem_set(&read_file_info, 0, sizeof(em_mcf_read_ota_file_info_struct));
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_AP;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_CARRIER_BIN;
read_file_info.ps_id = req->ps_id;
read_file_info.start_time = kal_get_systicks();
/* Read TLV-OTA file */
ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, fs_root_path, (kal_char *)req->config1, &apply_path_type, apply_filename, pMcf);
// Store Read TLV-OTA file result for dsbp urc use
set_op_read_ret[sim_id] = ret;
if (ret == MCF_OTA_R_SUCCESS) {
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Do not trigger DSBP if the same file as last one */
if ( (tlvota_file->last_file.path_type == apply_path_type) &&
(strncmp(tlvota_file->last_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN) == 0) &&
(strncmp(tlvota_file->last_file.sw_version, &(pFile->buff_start), pFile->sw_version_len) == 0) &&
(strncmp(tlvota_file->last_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len) == 0) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_FILE_NOT_CHANGE(0, tlvota_file->last_file.path_type);
dhl_print_string(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_MCF, tlvota_file->last_file.name);
dhl_print_string(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_MCF, tlvota_file->last_file.sw_version);
dhl_print_string(TRACE_INFO, DHL_USER_FLAG_NONE, MOD_MCF, tlvota_file->last_file.gen_time);
ret = MCF_OTA_R_FILE_NOT_CHANGE;
} else {
/* Store temp updated file informantion */
kal_mem_set(&(tlvota_file->temp_file), 0, sizeof(mcf_file_info_t));
tlvota_file->temp_file.path_type = apply_path_type;
strncpy(tlvota_file->temp_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(tlvota_file->temp_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
tlvota_file->temp_file.sw_version[pFile->sw_version_len] = '\0';
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_SW_VERSION(pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(tlvota_file->temp_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len);
tlvota_file->temp_file.gen_time[pFile->gen_time_len] = '\0';
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_SW_GEN_TIME(pFile->gen_time_len);
}
read_file_info.path_type = tlvota_file->path_type;
strncpy(read_file_info.file_name, (kal_char *)&(tlvota_file->relative_path_name), MCF_FILE_MAX_NAME_LEN - 1);
}
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_FILE(str_tmp);
com_Mcf.tlvota_result[sim_id] = MCF_OTA_R_INVALID_FILE;
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MD_TRC_MCF_TR_SET_FILE_PATH_TAKE_WRITE_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return ret;
}
is_read_tlvota[sim_id] = KAL_TRUE;
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_FAIL(req->config_type);
}
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
} else {
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_tlvota_file.path, "", MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, "", MCF_FILE_MAX_NAME_LEN - 1);
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
/* Deactivate TLV-OTA setting, reset TLV-OTA buffer */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
kal_mem_set(tlvota_file->buff, 0, sizeof(kal_uint8) * MCF_MAX_TLVOTA_FILE_SIZE);
tlvota_file->path_type = req->path_type;
strncpy(tlvota_file->relative_path_name, "", MCF_FILE_MAX_NAME_LEN - 1);
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_RESET_BUFFER_FAIL();
}
/* Do not trigger DSBP if no last file */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
if (strncmp(tlvota_file->last_file.name, "", MCF_FILE_MAX_NAME_LEN) == 0) {
MD_TRC_MCF_TR_SET_FILE_PATH_FILE_NOT_CHANGE(1, tlvota_file->last_file.path_type);
ret = MCF_OTA_R_FILE_NOT_CHANGE;
} else {
/* Clear last updated file informantion */
kal_mem_set(&(tlvota_file->temp_file), 0, sizeof(mcf_file_info_t));
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_TAKE_WRITE_LOCK_FAIL();
}
is_read_tlvota[sim_id] = KAL_TRUE;
}
break;
}
default:
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_CONFIG_TYPE(req->config_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
break;
}
case L4C_MCF_CONFIG_SET_FILE_PATH_AND_AUTO_SELECT_BIN:
{
kal_bool is_combine = KAL_FALSE;
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
pMcf->dsbp_cnf_ret = KAL_TRUE;
pMcf->dsbp_ind_ret = KAL_TRUE;
switch (req->config_type)
{
case L4C_MCF_CONFIG_TYPE_DEFAULT_BIN:
{
nvram_ef_mcf_ota_file_info_struct nv_ota_file;
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char curr_filename[MCF_FILE_MAX_NAME_LEN];
kal_wchar filename[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
kal_int32 fs_api_ret;
is_combine = nv_int_info.is_combined_ota;
if(is_combine == KAL_FALSE){
if (nv_int_info.not_reset_ota == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_not_reset(KAL_FALSE, req->config_type, 0);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
nv_int_info.not_reset_ota = KAL_FALSE;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_MD_PATH_LEN - 1);
/* Check if file is existed */
kal_wsprintf(filename, "%s\\%s\0", fs_root_path, curr_filename);
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_SET_FILE_PATH_FILE_NOT_EXIST(fs_root_path, curr_filename);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Write MCF OTA file information to NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_ota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
} else {
/* Write MCF OTA file information to NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
kal_mem_set(nv_ota_file.path, 0, MCF_FILE_MAX_MD_PATH_LEN - 1);
kal_mem_set(nv_ota_file.name, 0, MCF_FILE_MAX_NAME_LEN - 1);
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
}
}else{
#ifdef __MCF_COMBINE_FILE_SUPPORT__
ret = mcf_combined_ota_file(req);
if(ret != MCF_OTA_R_SUCCESS){
return ret;
}
#else
ret = MCF_OTA_R_MCF_NOT_SUPPORT;
return ret;
#endif
}
break;
}
case L4C_MCF_CONFIG_TYPE_CARRIER_BIN:
{
mcf_tlvota_file_t *tlvota_file;
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
em_mcf_read_ota_file_info_struct read_file_info;
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_wchar filename[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type;
kal_int32 fs_api_ret;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_SIM_ID(req->ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
is_combine = nv_int_info.is_combined_tlvota[sim_id];
if(is_combine == KAL_FALSE){
if (nv_int_info.not_reset_tlvota[sim_id] == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_not_reset(KAL_FALSE, req->config_type, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
nv_int_info.not_reset_tlvota[sim_id] = KAL_FALSE;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
if (pMcf->is_ignore_dsbp[sim_id] == KAL_FALSE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
ret = mcf_set_dsbp_mode(KAL_TRUE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_TRUE;
}
/* Check if file is existed */
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
kal_wsprintf(filename, "%s\\%s\0", MCF_FS_DEFAULT_FOLDER_PATH, req->config1);
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
kal_wsprintf(filename, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, req->config1);
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_SET_FILE_PATH_FILE_NOT_EXIST(fs_root_path, req->config1);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_tlvota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, (kal_char *)req->config1, MCF_FILE_MAX_NAME_LEN - 1);
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if (req->trigger_dsbp == 1) {
/* Read TLV-OTA file */
kal_mem_set(&read_file_info, 0, sizeof(em_mcf_read_ota_file_info_struct));
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_AP;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_CARRIER_BIN;
read_file_info.ps_id = req->ps_id;
read_file_info.start_time = kal_get_systicks();
ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, fs_root_path, (kal_char *)req->config1, &apply_path_type, apply_filename, pMcf);
// Store Read TLV-OTA file result for dsbp urc use
set_op_read_ret[sim_id] = ret;
if (ret == MCF_OTA_R_SUCCESS) {
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Store last updated file informantion */
tlvota_file->last_file.path_type = apply_path_type;
strncpy(tlvota_file->last_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(tlvota_file->last_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
tlvota_file->last_file.sw_version[pFile->sw_version_len] = '\0';
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_SW_VERSION(pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(tlvota_file->last_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len);
tlvota_file->last_file.gen_time[pFile->gen_time_len] = '\0';
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_SW_GEN_TIME(pFile->gen_time_len);
}
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_FILE(str_tmp);
com_Mcf.tlvota_result[sim_id] = MCF_OTA_R_INVALID_FILE;
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MD_TRC_MCF_TR_SET_FILE_PATH_TAKE_WRITE_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return ret;
}
read_file_info.path_type = tlvota_file->path_type;
strncpy(read_file_info.file_name, (kal_char *)&(tlvota_file->relative_path_name), MCF_FILE_MAX_NAME_LEN - 1);
is_read_tlvota[sim_id] = KAL_TRUE;
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_FAIL(req->config_type);
}
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
}
} else {
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_dsbp_mode(KAL_FALSE, KAL_FALSE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_FALSE;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_tlvota_file.path, "", MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, "", MCF_FILE_MAX_NAME_LEN - 1);
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if (req->trigger_dsbp == 1) {
/* Deactivate TLV-OTA setting, reset TLV-OTA buffer */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
kal_mem_set(tlvota_file->buff, 0, sizeof(kal_uint8) * MCF_MAX_TLVOTA_FILE_SIZE);
tlvota_file->path_type = req->path_type;
strncpy(tlvota_file->relative_path_name, "", MCF_FILE_MAX_NAME_LEN - 1);
tlvota_file->last_mod_time = 0;
/* Clear last updated file informantion */
kal_mem_set(&(tlvota_file->last_file), 0, sizeof(mcf_file_info_t));
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_RESET_BUFFER_FAIL();
}
is_read_tlvota[sim_id] = KAL_TRUE;
}
}
}else{
#ifdef __MCF_COMBINE_FILE_SUPPORT__
ret = mcf_combined_ota_file(req);
if(ret != MCF_OTA_R_SUCCESS){
return ret;
}
#else
ret = MCF_OTA_R_MCF_NOT_SUPPORT;
return ret;
#endif
}
break;
}
case L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN:
{
mcf_tlvota_file_t *tlvota_file = &(pMcf->general_tlvota_file);
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
em_mcf_read_ota_file_info_struct read_file_info;
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_wchar filename[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type;
kal_int32 fs_api_ret;
is_combine = nv_int_info.is_combined_general_tlvota;
if(is_combine == KAL_FALSE){
if (nv_int_info.not_reset_general_tlvota == KAL_TRUE) {
/* If MCF is in DSBP active mode, change to DSBP passive mode */
ret = mcf_set_not_reset(KAL_FALSE, req->config_type, 0);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
nv_int_info.not_reset_general_tlvota = KAL_FALSE;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
if (pMcf->general_is_ignore_dsbp == KAL_FALSE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
ret = mcf_set_dsbp_mode(KAL_TRUE, KAL_TRUE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->general_is_ignore_dsbp = KAL_TRUE;
}
/* Check if file is existed */
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
kal_wsprintf(filename, "%s\\%s\0", MCF_FS_DEFAULT_FOLDER_PATH, req->config1);
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
kal_wsprintf(filename, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, req->config1);
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
fs_api_ret = FS_GetAttributes(filename);
if (fs_api_ret < FS_NO_ERROR) {
MD_TRC_MCF_TR_SET_FILE_PATH_FILE_NOT_EXIST(fs_root_path, req->config1);
ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
return ret;
}
/* Read MCF general TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_tlvota_file.path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, (kal_char *)req->config1, MCF_FILE_MAX_NAME_LEN - 1);
/* Write MCF general TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if (req->trigger_dsbp == 1) {
/* Read general TLV-OTA file */
kal_mem_set(&read_file_info, 0, sizeof(em_mcf_read_ota_file_info_struct));
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_AP;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN;
read_file_info.ps_id = req->ps_id;
read_file_info.start_time = kal_get_systicks();
ret = mcf_read_general_tlvota_file(KAL_FALSE, fs_root_path, (kal_char *)req->config1, &apply_path_type, apply_filename, pMcf);
if (ret == MCF_OTA_R_SUCCESS) {
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Store last updated file informantion */
tlvota_file->last_file.path_type = apply_path_type;
strncpy(tlvota_file->last_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(tlvota_file->last_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
tlvota_file->last_file.sw_version[pFile->sw_version_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(tlvota_file->last_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len);
tlvota_file->last_file.gen_time[pFile->gen_time_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
}
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_FILE(str_tmp);
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MD_TRC_MCF_TR_SET_FILE_PATH_TAKE_WRITE_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return ret;
}
read_file_info.path_type = tlvota_file->path_type;
strncpy(read_file_info.file_name, (kal_char *)&(tlvota_file->relative_path_name), MCF_FILE_MAX_NAME_LEN - 1);
for(i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
}
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_FAIL(req->config_type);
}
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
}
} else {
if (pMcf->general_is_ignore_dsbp == KAL_TRUE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
ret = mcf_set_dsbp_mode(KAL_FALSE, KAL_TRUE, sim_id);
if (ret != MCF_OTA_R_SUCCESS) {
return ret;
}
pMcf->general_is_ignore_dsbp = KAL_FALSE;
}
/* Read MCF general TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_tlvota_file.path, "", MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, "", MCF_FILE_MAX_NAME_LEN - 1);
/* Write MCF general TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if (req->trigger_dsbp == 1) {
/* Deactivate general TLV-OTA setting, reset general TLV-OTA buffer */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
kal_mem_set(tlvota_file->buff, 0, sizeof(kal_uint8) * MCF_MAX_TLVOTA_FILE_SIZE);
tlvota_file->path_type = req->path_type;
strncpy(tlvota_file->relative_path_name, "", MCF_FILE_MAX_NAME_LEN - 1);
tlvota_file->last_mod_time = 0;
/* Clear last updated file informantion */
kal_mem_set(&(tlvota_file->last_file), 0, sizeof(mcf_file_info_t));
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_SET_FILE_PATH_RESET_BUFFER_FAIL();
}
for(i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
}
}
}
}else{
#ifdef __MCF_COMBINE_FILE_SUPPORT__
ret = mcf_combined_ota_file(req);
if(ret != MCF_OTA_R_SUCCESS){
return ret;
}
#else
ret = MCF_OTA_R_MCF_NOT_SUPPORT;
return ret;
#endif
}
break;
}
default:
MD_TRC_MCF_TR_SET_FILE_PATH_INVALID_CONFIG_TYPE(req->config_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
break;
}
default:
ASSERT(0);
ret = MCF_OTA_R_INVALID_PARAMETER;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_get_applied_file_path(
l4c_mcf_get_config_req_struct *req,
l4c_mcf_get_config_cnf_struct *resp)
{
mcf_t *pMcf = mcf_get_instance();
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
switch (req->op)
{
case L4C_MCF_CONFIG_GET_APPLIED_FILE_PATH:
switch (req->config_type)
{
case L4C_MCF_CONFIG_TYPE_DEFAULT_BIN:
{
mcf_ota_file_t *ota_file = &(pMcf->ota_file);
resp->config_type = req->config_type;
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
resp->path_type = ota_file->path_type;
strncpy((kal_char *)resp->config1, ota_file->relative_path_name, MCF_FILE_MAX_NAME_LEN - 1);
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_GET_APPLIED_FILE_PATH_TAKE_READ_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
break;
}
case L4C_MCF_CONFIG_TYPE_CARRIER_BIN:
{
mcf_tlvota_file_t *tlvota_file = &(pMcf->tlvota_file[sim_id]);
resp->config_type = req->config_type;
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
resp->path_type = tlvota_file->path_type;
strncpy((kal_char *)resp->config1, tlvota_file->relative_path_name, MCF_FILE_MAX_NAME_LEN - 1);
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_GET_APPLIED_FILE_PATH_TAKE_READ_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
break;
}
case L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN:
{
mcf_tlvota_file_t *tlvota_file = &(pMcf->general_tlvota_file);
resp->config_type = req->config_type;
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
resp->path_type = tlvota_file->path_type;
strncpy((kal_char *)resp->config1, tlvota_file->relative_path_name, MCF_FILE_MAX_NAME_LEN - 1);
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_GET_APPLIED_FILE_PATH_TAKE_READ_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
break;
}
default:
MD_TRC_MCF_TR_GET_APPLIED_FILE_PATH_UNSUPPORTED_CONFIG_TYPE(req->config_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
MD_TRC_MCF_TR_GET_APPLIED_FILE_PATH(ret, req->ps_id, sim_id, req->config_type, resp->path_type, resp->config1);
break;
default:
ASSERT(0);
ret = MCF_OTA_R_INVALID_PARAMETER;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_dump_all_lid_data(l4c_mcf_dump_data_req_struct *req_ptr)
{
mcf_t *pMcf = mcf_get_instance();
mcf_custom_dump_param_struct dump_para[MAX_SIM_NUM];
mcf_dump_lid_header_struct dump_lid_header;
mcf_dump_lid_header_struct *dump_header_ptr = NULL;
nvram_ltable_entry_struct lid_info = {0};
time_t time_sec;
MCF_TIME_STRUCT curr_time;
kal_wchar foldername[MCF_FILE_MAX_MD_PATH_LEN];
kal_char folder_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char file_name[MCF_FILE_MAX_MD_PATH_LEN];
kal_uint32 total_size;
kal_uint32 lid_size;
kal_uint32 padding;
kal_uint32 i, j, k;
kal_bool is_found = KAL_FALSE;
kal_bool ret;
nvram_errno_enum nvram_api_ret;
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
kal_uint32 dump_lid_cnt = 0;
kal_uint32 m;
kal_char last_dump_folder_name[MCF_FILE_MAX_MD_PATH_LEN];
kal_int32 fs_ret = FS_NO_ERROR;
kal_wchar pathname[MCF_FILE_MAX_MD_PATH_LEN];
kal_int32 ret_snprintf;
kal_int32 ret_sprintf;
time_t time_ret;
/* Create dump folder */
time_ret = time(&time_sec);
if (time_ret == (time_t)(-1)){
time_sec = 0;
}
#if __MTK_TARGET__
localtime_r(&time_sec, &curr_time);
#else
curr_time.tm_year = 12;
curr_time.tm_mon = 3;
curr_time.tm_mday = 4;
curr_time.tm_hour = 5;
curr_time.tm_min = 6;
curr_time.tm_sec = 7;
#endif
mcf_snprintf(folder_path, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s\\%s_%.4d%.2d%.2d_%.2d%.2d%.2d%c", MCF_FS_CUSTOM_FOLDER_PATH, MCF_DUMP_FOLDER_PREFIX, curr_time.tm_year + 1900, curr_time.tm_mon + 1, curr_time.tm_mday, curr_time.tm_hour, curr_time.tm_min, curr_time.tm_sec, '\0');
kal_wsprintf(foldername, "%s\0", folder_path);
FS_CreateDir(foldername);
/* Support MCF Tool Read/Write - Delete txt */
kal_wsprintf(pathname, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_DUMP_FOLDER_NAME);
fs_ret = FS_Delete(pathname);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_DUMP_ALL_LID_DELETE_FILE_FAIL(fs_ret);
mcf_ret = MCF_OTA_R_WRITE_DISK_FAIL;
return mcf_ret;
}
MD_TRC_MCF_TR_DUMP_ALL_LID_START(folder_path);
kal_mem_set(dump_para, 0, sizeof(mcf_custom_dump_param_struct) * MAX_SIM_NUM);
for (k = 0; k < MAX_SIM_NUM; k++) {
dump_para[k].ps_id = l4c_gemini_get_switched_sim_id(k);
dump_para[k].sbp_id = pMcf->tlvota_file[k].sbp_id;
kal_mem_cpy(&(dump_para[k].mcc), &(pMcf->tlvota_file[k].mcc), MAX_MCC_STR_LEN);
kal_mem_cpy(&(dump_para[k].mnc), &(pMcf->tlvota_file[k].mnc), MAX_MNC_STR_LEN);
kal_mem_cpy(&(dump_para[k].iccid), &(pMcf->tlvota_file[k].iccid), 21);
dump_para[k].size = &lid_size;
}
dump_lid_cnt = req_ptr->lid_cnt;
MD_TRC_MCF_TR_DUMP_ALL_LID_NUMBER(dump_lid_cnt);
/* Dump all LIDs */
if(dump_lid_cnt == 0){
for (i = 0; i < MCF_LID_MAPPING_TBL_SIZE; i++) {
is_found = KAL_FALSE;
nvram_api_ret = nvram_external_get_lid_info(mcf_db_lid_mapping_tbl[i].lid_num, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_DUMP_ALL_LID_GET_LID_INFO_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, nvram_api_ret);
continue;
}
if ((lid_info.size % 4) == 0) {
padding = 0;
} else {
padding = 4 - (lid_info.size % 4);
MD_TRC_MCF_TR_DUMP_ALL_LID_SIZE_NOT_ALIGNMENT(lid_info.LID, lid_info.size, padding);
}
for (j = 0; j < mcf_dump_param_tbl_num; j++) {
if ( (mcf_dump_param_tbl[j].lid == mcf_db_lid_mapping_tbl[i].lid_num) ) {
is_found = KAL_TRUE;
if (mcf_db_lid_mapping_tbl[i].is_ota == KAL_TRUE) {
total_size = 0;
if ((mcf_dump_param_tbl[j].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA) != 0) {
for (k = 0; k < lid_info.total_records; k++) {
dump_header_ptr = (mcf_dump_lid_header_struct *)(mcf_dump_buffer + (sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding) * k);
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[0].lid = mcf_dump_param_tbl[j].lid;
dump_para[0].type = MCF_TYPE_OTA;
dump_para[0].record_idx = k + 1;
dump_para[0].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
*(dump_para[0].size) = 0;
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_CALLBACK(dump_para[0].lid, dump_para[0].type, dump_para[0].record_idx, dump_para[0].buffer);
ret = mcf_dump_param_tbl[j].dump_func_ptr(&dump_para[0]);
if ( (ret == KAL_FALSE) || (*(dump_para[0].size) != lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_DUMP_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, ret, lid_info.size, *(dump_para[0].size));
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = k + 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
}
} else {
/* If not register callback */
for (k = 0; k < lid_info.total_records; k++) {
dump_header_ptr = (mcf_dump_lid_header_struct *)(mcf_dump_buffer + (sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding) * k);
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[0].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = k + 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
}
}
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_default%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "default_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_DEFAULT_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
if (mcf_db_lid_mapping_tbl[i].is_ota_by_op == KAL_TRUE) {
if ((mcf_dump_param_tbl[j].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA_BY_OP) != 0) {
for (k = 0; k < MAX_SIM_NUM; k++) {
if ( (strncmp((kal_char *)(dump_para[k].mcc), "", MAX_MCC_STR_LEN) == 0) || (strncmp((kal_char *)(dump_para[k].mnc), "", MAX_MNC_STR_LEN) == 0) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_NULL_MCC_MNC((kal_char *)(dump_para[k].mcc), (kal_char *)(dump_para[k].mnc));
continue;
}
total_size = 0;
dump_header_ptr = (mcf_dump_lid_header_struct *)mcf_dump_buffer;
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[k].lid = mcf_dump_param_tbl[j].lid;
dump_para[k].type = MCF_TYPE_OTA_BY_OP;
dump_para[k].record_idx = 1;
dump_para[k].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
*(dump_para[k].size) = 0;
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_BY_OP_CALLBACK_1_USIR(dump_para[k].ps_id, dump_para[k].sbp_id, dump_para[k].mcc, dump_para[k].mnc, dump_para[k].iccid);
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_BY_OP_CALLBACK_2(dump_para[k].lid, dump_para[k].type, dump_para[k].record_idx, dump_para[k].buffer);
ret = mcf_dump_param_tbl[j].dump_func_ptr(&dump_para[k]);
if ( (ret == KAL_FALSE) || (*(dump_para[k].size) != lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_BY_OP_DUMP_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, ret, lid_info.size, *(dump_para[k].size));
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA_BY_OP;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_SIM%d%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, k + 1, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "SIM_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_SIM_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
} else {
/* If not register callback */
for (k = 0; k < MAX_SIM_NUM; k++) {
if ( (strncmp((kal_char *)(dump_para[k].mcc), "", MAX_MCC_STR_LEN) == 0) || (strncmp((kal_char *)(dump_para[k].mnc), "", MAX_MNC_STR_LEN) == 0) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_NULL_MCC_MNC((kal_char *)(dump_para[k].mcc), (kal_char *)(dump_para[k].mnc));
continue;
}
total_size = 0;
dump_header_ptr = (mcf_dump_lid_header_struct *)mcf_dump_buffer;
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[k].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA_BY_OP;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_SIM%d%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, k + 1, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "SIM_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_SIM_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
}
}
break;
}
}
/* If not register callback */
if (is_found == KAL_FALSE) {
if (mcf_db_lid_mapping_tbl[i].is_ota == KAL_TRUE) {
total_size = 0;
for (k = 0; k < lid_info.total_records; k++) {
dump_header_ptr = (mcf_dump_lid_header_struct *)(mcf_dump_buffer + (sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding) * k);
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[0].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = k + 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
}
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_default%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "default_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_DEFAULT_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
if (mcf_db_lid_mapping_tbl[i].is_ota_by_op == KAL_TRUE) {
for (k = 0; k < MAX_SIM_NUM; k++) {
if ( (strncmp((kal_char *)(dump_para[k].mcc), "", MAX_MCC_STR_LEN) == 0) || (strncmp((kal_char *)(dump_para[k].mnc), "", MAX_MNC_STR_LEN) == 0) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_NULL_MCC_MNC((kal_char *)(dump_para[k].mcc), (kal_char *)(dump_para[k].mnc));
continue;
}
total_size = 0;
dump_header_ptr = (mcf_dump_lid_header_struct *)mcf_dump_buffer;
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[k].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA_BY_OP;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_SIM%d%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, k + 1, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "SIM_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_SIM_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
}
}
}
}else if (dump_lid_cnt > 0)
{
/* Only dump dump_lid_cnt LIDs */
for(m = 0; m < dump_lid_cnt; m++){
is_found = KAL_FALSE;
for (i = 0; i < MCF_LID_MAPPING_TBL_SIZE; i++) {
if (req_ptr->lid[m] == mcf_db_lid_mapping_tbl[i].lid_num){
is_found = KAL_TRUE;
}
}
if (is_found == KAL_FALSE)
{
MD_TRC_MCF_TR_DUMP_ALL_LID_CANNOT_FIND_LID(req_ptr->lid[m]);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}
for(m = 0; m < dump_lid_cnt; m++){
is_found = KAL_FALSE;
for (i = 0; i < MCF_LID_MAPPING_TBL_SIZE; i++) {
if (req_ptr->lid[m] == mcf_db_lid_mapping_tbl[i].lid_num){
is_found = KAL_FALSE;
nvram_api_ret = nvram_external_get_lid_info(mcf_db_lid_mapping_tbl[i].lid_num, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_DUMP_ALL_LID_GET_LID_INFO_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, nvram_api_ret);
continue;
}
if ((lid_info.size % 4) == 0) {
padding = 0;
} else {
padding = 4 - (lid_info.size % 4);
MD_TRC_MCF_TR_DUMP_ALL_LID_SIZE_NOT_ALIGNMENT(lid_info.LID, lid_info.size, padding);
}
for (j = 0; j < mcf_dump_param_tbl_num; j++) {
if ( (mcf_dump_param_tbl[j].lid == mcf_db_lid_mapping_tbl[i].lid_num) ) {
is_found = KAL_TRUE;
if (mcf_db_lid_mapping_tbl[i].is_ota == KAL_TRUE) {
total_size = 0;
if ((mcf_dump_param_tbl[j].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA) != 0) {
for (k = 0; k < lid_info.total_records; k++) {
dump_header_ptr = (mcf_dump_lid_header_struct *)(mcf_dump_buffer + (sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding) * k);
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[0].lid = mcf_dump_param_tbl[j].lid;
dump_para[0].type = MCF_TYPE_OTA;
dump_para[0].record_idx = k + 1;
dump_para[0].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
*(dump_para[0].size) = 0;
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_CALLBACK(dump_para[0].lid, dump_para[0].type, dump_para[0].record_idx, dump_para[0].buffer);
ret = mcf_dump_param_tbl[j].dump_func_ptr(&dump_para[0]);
if ( (ret == KAL_FALSE) || (*(dump_para[0].size) != lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_DUMP_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, ret, lid_info.size, *(dump_para[0].size));
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = k + 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
}
} else {
/* If not register callback */
for (k = 0; k < lid_info.total_records; k++) {
dump_header_ptr = (mcf_dump_lid_header_struct *)(mcf_dump_buffer + (sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding) * k);
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[0].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = k + 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
}
}
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_default%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "default_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_DEFAULT_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
if (mcf_db_lid_mapping_tbl[i].is_ota_by_op == KAL_TRUE) {
if ((mcf_dump_param_tbl[j].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA_BY_OP) != 0) {
for (k = 0; k < MAX_SIM_NUM; k++) {
if ( (strncmp((kal_char *)(dump_para[k].mcc), "", MAX_MCC_STR_LEN) == 0) || (strncmp((kal_char *)(dump_para[k].mnc), "", MAX_MNC_STR_LEN) == 0) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_NULL_MCC_MNC((kal_char *)(dump_para[k].mcc), (kal_char *)(dump_para[k].mnc));
continue;
}
total_size = 0;
dump_header_ptr = (mcf_dump_lid_header_struct *)mcf_dump_buffer;
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[k].lid = mcf_dump_param_tbl[j].lid;
dump_para[k].type = MCF_TYPE_OTA_BY_OP;
dump_para[k].record_idx = 1;
dump_para[k].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
*(dump_para[k].size) = 0;
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_BY_OP_CALLBACK_1_USIR(dump_para[k].ps_id, dump_para[k].sbp_id, dump_para[k].mcc, dump_para[k].mnc, dump_para[k].iccid);
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_BY_OP_CALLBACK_2(dump_para[k].lid, dump_para[k].type, dump_para[k].record_idx, dump_para[k].buffer);
ret = mcf_dump_param_tbl[j].dump_func_ptr(&dump_para[k]);
if ( (ret == KAL_FALSE) || (*(dump_para[k].size) != lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_OTA_BY_OP_DUMP_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, ret, lid_info.size, *(dump_para[k].size));
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA_BY_OP;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_SIM%d%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, k + 1, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "SIM_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_SIM_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
} else {
/* If not register callback */
for (k = 0; k < MAX_SIM_NUM; k++) {
if ( (strncmp((kal_char *)(dump_para[k].mcc), "", MAX_MCC_STR_LEN) == 0) || (strncmp((kal_char *)(dump_para[k].mnc), "", MAX_MNC_STR_LEN) == 0) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_NULL_MCC_MNC((kal_char *)(dump_para[k].mcc), (kal_char *)(dump_para[k].mnc));
continue;
}
total_size = 0;
dump_header_ptr = (mcf_dump_lid_header_struct *)mcf_dump_buffer;
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[k].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA_BY_OP;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_SIM%d%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, k + 1, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "SIM_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_SIM_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
}
}
break;
}
}
/* If not register callback */
if (is_found == KAL_FALSE) {
if (mcf_db_lid_mapping_tbl[i].is_ota == KAL_TRUE) {
total_size = 0;
for (k = 0; k < lid_info.total_records; k++) {
dump_header_ptr = (mcf_dump_lid_header_struct *)(mcf_dump_buffer + (sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding) * k);
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[0].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, dump_para[0].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = k + 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
}
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_default%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "default_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_DEFAULT_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
if (mcf_db_lid_mapping_tbl[i].is_ota_by_op == KAL_TRUE) {
for (k = 0; k < MAX_SIM_NUM; k++) {
if ( (strncmp((kal_char *)(dump_para[k].mcc), "", MAX_MCC_STR_LEN) == 0) || (strncmp((kal_char *)(dump_para[k].mnc), "", MAX_MNC_STR_LEN) == 0) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_NULL_MCC_MNC((kal_char *)(dump_para[k].mcc), (kal_char *)(dump_para[k].mnc));
continue;
}
total_size = 0;
dump_header_ptr = (mcf_dump_lid_header_struct *)mcf_dump_buffer;
kal_mem_set(dump_header_ptr, 0, sizeof(mcf_dump_lid_header_struct) + lid_info.size + padding);
dump_para[k].buffer = (kal_uint8 *)dump_header_ptr + sizeof(mcf_dump_lid_header_struct);
if ( !nvram_external_read_data(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size) ) {
MD_TRC_MCF_TR_DUMP_ALL_LID_READ_NVRAM_FAIL(mcf_db_lid_mapping_tbl[i].lid_num, dump_para[k].ps_id + 1, dump_para[k].buffer, lid_info.size);
break;
}
/* Add header */
kal_mem_set(&dump_lid_header, 0, sizeof(mcf_dump_lid_header_struct));
strncpy(dump_lid_header.sync_token, MCF_DUMP_LID_SYNC_TOKEN, 7);
dump_lid_header.header_version = MCF_DUMP_LID_HEADER_VERSION;
dump_lid_header.content_type = MCF_TYPE_OTA_BY_OP;
dump_lid_header.operation_mask = MCF_FILE_OP_NONE;
dump_lid_header.content_len = lid_info.size;
dump_lid_header.lid = mcf_db_lid_mapping_tbl[i].lid_num;
dump_lid_header.record_idx = 1;
strncpy(dump_lid_header.lid_version, lid_info.fileverno, FILE_VERNO_LEN);
dump_lid_header.lid_version[FILE_VERNO_LEN] = '\0';
dump_lid_header.checksum = 0; /* unused */
kal_mem_cpy(dump_header_ptr, &dump_lid_header, sizeof(mcf_dump_lid_header_struct));
total_size += sizeof(mcf_dump_lid_header_struct) + dump_lid_header.content_len + padding;
ret_snprintf = kal_snprintf(file_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%d_SIM%d%s%c", MCF_DUMP_FILE_PREFIX, mcf_db_lid_mapping_tbl[i].lid_num, k + 1, MCF_DUMP_FILE_POSTFIX, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_name, "SIM_error.dump", MCF_FILE_MAX_MD_PATH_LEN - 1);
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_SIM_FILENAME_ERROR(mcf_db_lid_mapping_tbl[i].lid_num, k + 1, ret_snprintf);
}
mcf_ret = mcf_write_buffer(folder_path, file_name, mcf_dump_buffer, total_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
}
}
}
}
}
}
/* Support MCF Tool Read/Write - Write dump folder name into txt */
kal_mem_set(last_dump_folder_name, 0, MCF_FILE_MAX_MD_PATH_LEN);
ret_sprintf = kal_snprintf(last_dump_folder_name, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s_%.4d%.2d%.2d_%.2d%.2d%.2d%c", MCF_DUMP_FOLDER_PREFIX, curr_time.tm_year + 1900, curr_time.tm_mon + 1, curr_time.tm_mday, curr_time.tm_hour, curr_time.tm_min, curr_time.tm_sec, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(last_dump_folder_name, "unknown_error", MCF_FILE_MAX_MD_PATH_LEN - 1);
}
MD_TRC_MCF_TR_DUMP_ALL_LID_DUMP_FOLDER_NAME(last_dump_folder_name);
if(mcf_ret == MCF_OTA_R_SUCCESS){
mcf_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_DUMP_FOLDER_NAME, (kal_uint8 *)last_dump_folder_name, sizeof(kal_char) * strlen(last_dump_folder_name));
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
}
return mcf_ret;
}
_STATIC mcf_ota_result_e mcf_config_ini_info(
l4c_mcf_config_req_struct *req,
l4c_mcf_config_cnf_struct *resp)
{
mcf_t *pMcf = mcf_get_instance();
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type = L4C_MCF_PATH_TYPE_RUNTIME;
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
mcf_ini_file_t *ini_file = &(pMcf->ini_file);
kal_char *buffer = (kal_char *)ini_file->tmp_buff;
kal_char orign_value[MCF_MAX_INI_ITEM_VALUE_LEN];
kal_uint64 ini_path_ota_file_last_mod_time = 0;
kal_uint64 ini_path_runtime_file_last_mod_time = 0;
kal_uint64 ini_last_read_mod_time = 0;
kal_char ini_root_path[20];
if(strcmp((kal_char *)req->item,"") == 0){
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if(strlen((kal_char *)req->item) > 63){
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
kal_mem_set((kal_char *)resp->item,0,MCF_MAX_INI_ITEM_LEN);
kal_mem_set((kal_char *)resp->value,0,MCF_MAX_INI_ITEM_VALUE_LEN);
strncpy((kal_char *)resp->item, (kal_char *)req->item, MCF_MAX_INI_ITEM_LEN-1);
switch (req->mode)
{
case L4C_MCF_CONFIG_MODE_READ:
ini_last_read_mod_time = ini_file->last_mod_time;
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ini_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ini_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ini_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ini_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
}
MD_TRC_MCF_TR_CONFIG_INI_LAST_MOD_TIME(ini_path_ota_file_last_mod_time, ini_path_runtime_file_last_mod_time, ini_last_read_mod_time);
kal_mem_set(ini_root_path,0,20);
if (ini_path_ota_file_last_mod_time > ini_path_runtime_file_last_mod_time){
strncpy(ini_root_path,MCF_FS_DEFAULT_FOLDER_PATH, 19);
}else{
strncpy(ini_root_path,MCF_FS_CUSTOM_FOLDER_PATH, 19);
}
MD_TRC_MCF_TR_CONFIG_INI_READ(ini_root_path);
if (mcf_read_ini_file(ini_root_path, MCF_FS_DEFAULT_INI_FILE_NAME, &apply_path_type, apply_filename, pMcf) == MCF_OTA_R_SUCCESS) {
} else {
/* Cannot do OTA if fail to read ini file */
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
if (mcf_find_ini_item((kal_char *)ini_file->buff, (kal_char *)resp->item, (kal_char *)resp->value, pMcf) == KAL_TRUE) {
} else {
/* Cannot do OTA if fail to read ini file */
mcf_ret = MCF_OTA_R_INVALID_INI_ITEM;
return mcf_ret;
}
break;
case L4C_MCF_CONFIG_MODE_WRITE:
strncpy((kal_char *)resp->value, (kal_char *)req->value, MCF_MAX_INI_ITEM_VALUE_LEN-1);
ini_last_read_mod_time = ini_file->last_mod_time;
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ini_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ini_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ini_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ini_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_CONFIG_INI_READ_INI_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
}
MD_TRC_MCF_TR_CONFIG_INI_LAST_MOD_TIME(ini_path_ota_file_last_mod_time, ini_path_runtime_file_last_mod_time, ini_last_read_mod_time);
kal_mem_set(ini_root_path,0,20);
if (ini_path_ota_file_last_mod_time > ini_path_runtime_file_last_mod_time){
strncpy(ini_root_path,MCF_FS_DEFAULT_FOLDER_PATH, 19);
}else{
strncpy(ini_root_path,MCF_FS_CUSTOM_FOLDER_PATH, 19);
}
MD_TRC_MCF_TR_CONFIG_INI_READ(ini_root_path);
if (mcf_read_ini_file(ini_root_path, MCF_FS_DEFAULT_INI_FILE_NAME, &apply_path_type, apply_filename, pMcf) == MCF_OTA_R_SUCCESS) {
} else {
/* Cannot do OTA if fail to read ini file */
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
kal_mem_set(orign_value, 0, MCF_MAX_INI_ITEM_VALUE_LEN);
kal_mem_set((kal_char *)resp->value, 0, MCF_MAX_INI_ITEM_VALUE_LEN);
mcf_find_ini_item((kal_char *)ini_file->buff, (kal_char *)resp->item, orign_value, pMcf);
kal_mem_set(buffer,0,MCF_MAX_INI_FILE_SIZE);
if (mcf_compose_ini_item((kal_char *)ini_file->buff, buffer, (kal_char *)resp->item, orign_value, (kal_char *)resp->value) == KAL_TRUE) {
mcf_ret = mcf_write_buffer(ini_root_path, MCF_FS_DEFAULT_INI_FILE_NAME, (kal_uint8 *)buffer, strlen(buffer));
if (mcf_ret != MCF_OTA_R_SUCCESS){
return mcf_ret;
}
} else {
/* Cannot do OTA if fail to read ini file */
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
break;
default:
ASSERT(0);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
}
return mcf_ret;
}
_STATIC mcf_ota_result_e mcf_update_ota_file(
l4c_mcf_update_ota_file_req_struct *req,
l4c_mcf_update_ota_file_cnf_struct *resp,
module_type src_mod_id,
kal_bool *reset_MD)
{
mcf_t *pMcf = mcf_get_instance();
//sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
//nvram_ef_mcf_ini_file_info_struct ini_file;
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type = L4C_MCF_PATH_TYPE_RUNTIME;
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
mcf_ini_file_t *ini_file = &(pMcf->ini_file);
kal_uint32 sbp_id_arr[MCF_MAX_TAG_NUM];
kal_char tag_str[MCF_MAX_INI_ITEM_VALUE_LEN];
kal_uint16 sbp_id_num = 0;
mcf_ota_file_t *ota_file = &(pMcf->ota_file);
mcf_tlvota_file_t *tlvota_file;
kal_int32 i = 0;
kal_int32 j = 0;
kal_char ota_path_name[MCF_FILE_MAX_NAME_LEN];
kal_uint64 ota_last_read_mod_time = 0;
kal_uint64 ota_path_ota_file_last_mod_time = 0;
kal_uint64 ota_path_runtime_file_last_mod_time = 0;
kal_uint32 sbp_id = SBP_ID_INVALID;
protocol_id_enum ps_id = 0;
kal_char tlvota_path_name[MCF_FILE_MAX_NAME_LEN];
kal_uint64 tlvota_last_read_mod_time = 0;
kal_uint64 tlvota_path_ota_file_last_mod_time = 0;
kal_uint64 tlvota_path_runtime_file_last_mod_time = 0;
mcf_l4bsbp_trigger_dsbp_ind_struct *ind_ptr = NULL;
kal_bool apply_general_tlv;
kal_char tag_name[10];
kal_bool trigger_ps_id[MAX_SIM_NUM];
kal_uint64 ini_last_read_mod_time = 0;
kal_uint64 ini_path_ota_file_last_mod_time = 0;
kal_uint64 ini_path_runtime_file_last_mod_time = 0;
kal_char ini_root_path[20];
kal_uint32 ret_sprintf;
MD_TRC_MCF_TR_UPDATE_OTA_START();
pMcf->dsbp_cnf_ret = KAL_TRUE;
pMcf->dsbp_ind_ret = KAL_TRUE;
apply_general_tlv = KAL_FALSE;
kal_mem_set(trigger_ps_id,0,MAX_SIM_NUM);
/* Compare modified time of OTA file to know whether update OTA file */
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
kal_mem_set(ota_path_name,0,MCF_FILE_MAX_NAME_LEN);
strncpy(ota_path_name, ota_file->relative_path_name, MCF_FILE_MAX_NAME_LEN - 1);
ota_last_read_mod_time = ota_file->last_mod_time;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
} else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_OTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_OTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_OTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_DEFAULT_OTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_OTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_OTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_OTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_OTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_OTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_OTA_LAST_MOD_TIME(ota_path_ota_file_last_mod_time, ota_path_runtime_file_last_mod_time, ota_last_read_mod_time);
if (ota_path_ota_file_last_mod_time > ota_path_runtime_file_last_mod_time){
if(ota_path_ota_file_last_mod_time > ota_last_read_mod_time){
/* If OTA file is updated, need to reset MD to apply OTA */
MD_TRC_MCF_TR_UPDATE_OTA_RESET_MD(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((ota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(ota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((ota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(ota_last_read_mod_time & 0xFFFFFFFF));
mcf_ret = MCF_OTA_R_SUCCESS;
*reset_MD = KAL_TRUE;
return mcf_ret;
}
}else{
if(ota_path_runtime_file_last_mod_time > ota_last_read_mod_time){
/* If OTA file is updated, need to reset MD to apply OTA */
MD_TRC_MCF_TR_UPDATE_OTA_RESET_MD(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((ota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(ota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((ota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(ota_last_read_mod_time & 0xFFFFFFFF));
mcf_ret = MCF_OTA_R_SUCCESS;
*reset_MD = KAL_TRUE;
return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_NO_UPDATE_OTA();
switch (req->action)
{
case L4C_MCF_CONFIG_ACT_NO_READ_INI:
/* Update OTA file without reading ini file */
MD_TRC_MCF_TR_UPDATE_OTA_NO_READ_INI();
/* If general_tlvota_file update, every sim card should apply */
tlvota_file = &(pMcf->general_tlvota_file);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_GTLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if (tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP with retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_GENERAL_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_GENERAL_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
for (i = 0; i < MAX_SIM_NUM; i++){
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 1;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + i, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
}
MD_TRC_MCF_TR_UPDATE_OTA_UPDATE_GENERAL_TLVOTA();
apply_general_tlv = KAL_TRUE;
return mcf_ret;
}
MD_TRC_MCF_TR_UPDATE_OTA_NO_UPDATE_GENERAL_TLVOTA();
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
tlvota_last_read_mod_time = 0;
/* Compare modified time of TLV OTA file to know whether update TLV OTA file */
for (i = 0; i < MAX_SIM_NUM; i++){
tlvota_file = &(pMcf->tlvota_file[i]);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
sbp_id = tlvota_file->sbp_id;
ps_id = tlvota_file->ps_id;
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
if (ps_id < 0 || ps_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_INVALID_SIM_ID(ps_id, i);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_PS_ID(ps_id);
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_SBP_ID(sbp_id);
/* If have not read tlv ota file, trigger DSBP */
if(sbp_id == SBP_ID_INVALID){
mcf_ret = MCF_OTA_R_SUCCESS;
}else{
kal_mem_set(tlvota_path_name,0,MCF_FILE_MAX_NAME_LEN);
ret_sprintf = kal_snprintf(tlvota_path_name, MCF_FILE_MAX_NAME_LEN - 1, "%s_%d.mcfopota%c", MCF_FS_TLVOTA_FILE_PREFIX, sbp_id, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_NAME_LEN){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FILENAME_ERROR(sbp_id, ret_sprintf);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_PATH_NAME(tlvota_path_name);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if (tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP with retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 1;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
}
}
}
break;
case L4C_MCF_CONFIG_ACT_READ_INI:
MD_TRC_MCF_TR_UPDATE_OTA_READ_INI();
/* Update OTA file with reading ini file */
ini_last_read_mod_time = ini_file->last_mod_time;
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ini_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_INI_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ini_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_INI_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &ini_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_INI_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_DEFAULT_INI_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &ini_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
ini_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_INI_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_INI_LAST_MOD_TIME(ini_path_ota_file_last_mod_time, ini_path_runtime_file_last_mod_time, ini_last_read_mod_time);
kal_mem_set(ini_root_path,0,20);
if (ini_path_ota_file_last_mod_time > ini_path_runtime_file_last_mod_time){
strncpy(ini_root_path,MCF_FS_DEFAULT_FOLDER_PATH, 19);
}else{
strncpy(ini_root_path,MCF_FS_CUSTOM_FOLDER_PATH, 19);
}
MD_TRC_MCF_TR_UPDATE_OTA_INI_READ(ini_root_path);
if (mcf_read_ini_file(ini_root_path, MCF_FS_DEFAULT_INI_FILE_NAME, &apply_path_type, apply_filename, pMcf) != MCF_OTA_R_SUCCESS) {
mcf_ret = MCF_OTA_R_READ_INI_FILE_FAIL;
return mcf_ret;
}
kal_mem_set(tag_name,0,10);
strncpy(tag_name,"TagName", 9);
mcf_find_ini_item((kal_char *)ini_file->buff, tag_name, tag_str, pMcf);
if(strcmp(tag_str,"") == 0){
/* Normal TLV OTA apply */
/* Compare modified time of TLV OTA file to know whether update TLV OTA file */
MD_TRC_MCF_TR_UPDATE_OTA_FIND_INI_TAGNAME_NULL();
/* If general_tlvota_file update, every sim card should apply */
tlvota_file = &(pMcf->general_tlvota_file);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if (tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP with retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_GENERAL_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_GENERAL_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
for (i = 0; i < MAX_SIM_NUM; i++){
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 1;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + i, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
}
MD_TRC_MCF_TR_UPDATE_OTA_UPDATE_GENERAL_TLVOTA();
apply_general_tlv = KAL_TRUE;
return mcf_ret;
}
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
tlvota_last_read_mod_time = 0;
/* Compare modified time of TLV OTA file to know whether update TLV OTA file */
MD_TRC_MCF_TR_UPDATE_OTA_NO_UPDATE_GENERAL_TLVOTA();
for (i = 0; i < MAX_SIM_NUM; i++){
tlvota_file = &(pMcf->tlvota_file[i]);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
sbp_id = tlvota_file->sbp_id;
ps_id = tlvota_file->ps_id;
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if (ps_id < 0 || ps_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_INVALID_SIM_ID(ps_id, i);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_PATH_NAME(tlvota_path_name);
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_PS_ID(ps_id);
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_SBP_ID(sbp_id);
/* If have not read tlv ota file, trigger DSBP */
if(sbp_id == SBP_ID_INVALID){
mcf_ret = MCF_OTA_R_SUCCESS;
}else{
kal_mem_set(tlvota_path_name,0,MCF_FILE_MAX_NAME_LEN);
ret_sprintf = kal_snprintf(tlvota_path_name, MCF_FILE_MAX_NAME_LEN - 1, "%s_%d.mcfopota%c", MCF_FS_TLVOTA_FILE_PREFIX, sbp_id, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_NAME_LEN){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FILENAME_ERROR(sbp_id, ret_sprintf);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if (tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP with retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 1;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
}
}
}
}else{
/* If critical tag is not null */
MD_TRC_MCF_TR_UPDATE_OTA_FIND_INI_TAGNAME(tag_str);
if(mcf_find_ini_sbp_id (tag_str,sbp_id_arr,&sbp_id_num,&apply_general_tlv) == KAL_TRUE){
/*If general tlvota case is critical, every sim card need to apply general tlv ota */
if (apply_general_tlv == KAL_TRUE){
tlvota_file = &(pMcf->general_tlvota_file);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_CGTLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if(tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP with retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_CRITICAL_GTLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_CRITICAL_GTLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
for (i = 0; i < MAX_SIM_NUM; i++){
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 0;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + i, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
}
MD_TRC_MCF_TR_UPDATE_OTA_UPDATE_GENERAL_TLVOTA();
return mcf_ret;
}
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
tlvota_last_read_mod_time = 0;
}
MD_TRC_MCF_TR_UPDATE_OTA_NO_UPDATE_GENERAL_TLVOTA();
for (i = 0; i < MAX_SIM_NUM; i++){
tlvota_file = &(pMcf->tlvota_file[i]);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
sbp_id = tlvota_file->sbp_id;
ps_id = tlvota_file->ps_id;
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if (ps_id < 0 || ps_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_INVALID_SIM_ID(ps_id, i);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
kal_mem_set(tlvota_path_name,0,MCF_FILE_MAX_NAME_LEN);
ret_sprintf = kal_snprintf(tlvota_path_name, MCF_FILE_MAX_NAME_LEN - 1, "%s_%d.mcfopota%c", MCF_FS_TLVOTA_FILE_PREFIX, sbp_id, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_NAME_LEN){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FILENAME_ERROR(sbp_id, ret_sprintf);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_PATH_NAME(tlvota_path_name);
for (j = 0; j < sbp_id_num; j++){
if (sbp_id == sbp_id_arr[j]){
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if (tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP without retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_CRITICAL_TLVOTA_TRIGGER_DSBP(tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_CRITICAL_TLVOTA_TRIGGER_DSBP(tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 0;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
trigger_ps_id[ps_id] = KAL_TRUE;
}
}
}
}
/* If no critical OP OTA trigger DSBP, check if general OTA whether updated */
if(pMcf->dsbp_cnf_cnt < MAX_SIM_NUM){
MD_TRC_MCF_TR_UPDATE_OTA_NO_CRITICAL_CASE();
/* If general_tlvota_file update, every sim card should apply */
tlvota_file = &(pMcf->general_tlvota_file);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if (mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (MCF_FS_GENERAL_TLVOTA_FILE_NAME, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_GENERAL_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if (tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP with retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_GENERAL_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_GENERAL_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
for (i = 0; i < MAX_SIM_NUM; i++){
if (trigger_ps_id[i] != KAL_TRUE){
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 1;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + i, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
}
}
apply_general_tlv = KAL_TRUE;
MD_TRC_MCF_TR_UPDATE_OTA_UPDATE_GENERAL_TLVOTA();
return mcf_ret;
}
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
tlvota_last_read_mod_time = 0;
/* Compare modified time of TLV OTA file to know whether update TLV OTA file */
MD_TRC_MCF_TR_UPDATE_OTA_NO_UPDATE_GENERAL_TLVOTA();
for (i = 0; i < MAX_SIM_NUM; i++){
tlvota_file = &(pMcf->tlvota_file[i]);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
sbp_id = tlvota_file->sbp_id;
ps_id = tlvota_file->ps_id;
tlvota_last_read_mod_time = tlvota_file->last_mod_time;
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return mcf_ret;
}
if (ps_id < 0 || ps_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_INVALID_SIM_ID(ps_id, i);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
tlvota_path_ota_file_last_mod_time = 0;
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_PATH_NAME(tlvota_path_name);
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_PS_ID(ps_id);
/* If have not read tlv ota file, trigger DSBP */
if(sbp_id == SBP_ID_INVALID){
mcf_ret = MCF_OTA_R_SUCCESS;
}else{
kal_mem_set(tlvota_path_name,0,MCF_FILE_MAX_NAME_LEN);
ret_sprintf = kal_snprintf(tlvota_path_name, MCF_FILE_MAX_NAME_LEN - 1, "%s_%d.mcfopota%c", MCF_FS_TLVOTA_FILE_PREFIX, sbp_id, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_NAME_LEN){
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FILENAME_ERROR(sbp_id, ret_sprintf);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_OTA, &tlvota_path_ota_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_ota_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_OTA, MCF_OTA_R_READ_OTA_FILE_FAIL);
if(mcf_get_file_last_mod_time (tlvota_path_name, L4C_MCF_PATH_TYPE_RUNTIME, &tlvota_path_runtime_file_last_mod_time) == MCF_OTA_R_READ_OTA_FILE_FAIL){
tlvota_path_runtime_file_last_mod_time = 0;
MD_TRC_MCF_TR_UPDATE_OTA_READ_TLVOTA_FILE_FAIL(L4C_MCF_PATH_TYPE_RUNTIME, MCF_OTA_R_READ_OTA_FILE_FAIL);
//return mcf_ret;
}
}
MD_TRC_MCF_TR_UPDATE_OTA_TLVOTA_LAST_MOD_TIME(tlvota_path_ota_file_last_mod_time, tlvota_path_runtime_file_last_mod_time, tlvota_last_read_mod_time);
if (tlvota_path_ota_file_last_mod_time > tlvota_last_read_mod_time || tlvota_path_runtime_file_last_mod_time > tlvota_last_read_mod_time){
/* If TLV OTA file is updated, trigger DSBP with retry */
if (tlvota_path_ota_file_last_mod_time > tlvota_path_runtime_file_last_mod_time){
MD_TRC_MCF_TR_UPDATE_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_OTA, (kal_uint32)((tlvota_path_ota_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_ota_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}else{
MD_TRC_MCF_TR_UPDATE_TLVOTA_TRIGGER_DSBP(L4C_MCF_PATH_TYPE_RUNTIME, (kal_uint32)((tlvota_path_runtime_file_last_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_path_runtime_file_last_mod_time & 0xFFFFFFFF),
(kal_uint32)((tlvota_last_read_mod_time >> 32) & 0xFFFFFFFF), (kal_uint32)(tlvota_last_read_mod_time & 0xFFFFFFFF));
}
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
if(trigger_ps_id[ps_id] != KAL_TRUE){
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
mcf_ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return mcf_ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->src_mod_id = src_mod_id;
ind_ptr->config_op = L4C_MCF_CONFIG_UPDATE_OPOTA_FILE;
ind_ptr->is_dsbp_retry = 1;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
mcf_ret = MCF_OTA_R_SUCCESS;
}
}
}
}
}
}
}
break;
default:
ASSERT(0);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
}
MD_TRC_MCF_TR_UPDATE_OTA_RETURN_VALUE(pMcf->dsbp_cnf_cnt);
return mcf_ret;
}
_STATIC mcf_ota_result_e mcf_config_LID_variable(
l4c_mcf_config_lid_variable_operation_req_struct *req,
l4c_mcf_config_lid_variable_operation_cnf_struct *resp)
{
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
#ifdef __MCF_FIND_TAG_SUPPORT__
mcf_t *pMcf = mcf_get_instance();
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
kal_bool ret = KAL_TRUE;
nvram_ltable_entry_struct lid_info = {0};
nvram_errno_enum nvram_api_ret;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
mcf_custom_dump_param_struct dump_para;
kal_uint32 lid_size;
kal_uint32 i;
mcf_tag_info_struct query_tag = {0};
kal_uint8 lid_value[512];
kal_uint32 j = 0;
kal_uint32 n = 1;
MCF_DB_STRUCT_VARIABLE const *db_ptr = NULL;
kal_uint32 read_len = 0;
kal_bool invalid_arr_size = KAL_FALSE;
kal_bool next_level_array = KAL_FALSE;
kal_bool is_found = KAL_FALSE;
kal_uint8 hex_value[512];
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_START(req->lid_num, req->rec_id, req->tag_name);
kal_mem_set(&dump_para, 0, sizeof(mcf_custom_dump_param_struct));
kal_mem_set(hex_value, 0, 512);
resp->len = req->len;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_INVALID_SIM_ID(req->ps_id, sim_id);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
nvram_api_ret = nvram_external_get_lid_info(req->lid_num, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_GET_LID_INFO_FAIL(req->lid_num, nvram_api_ret);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
kal_mem_set(mcf_dump_buffer, 0, lid_info.size);
if(req->rec_id > lid_info.total_records){
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_INVALID_REC_ID(req->rec_id, lid_info.total_records);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}else if (req->rec_id == 0){
req->rec_id = 1;
}
dump_para.ps_id = req->ps_id;
dump_para.sbp_id = pMcf->tlvota_file[sim_id].sbp_id;
kal_mem_cpy(&(dump_para.mcc), &(pMcf->tlvota_file[sim_id].mcc), MAX_MCC_STR_LEN);
kal_mem_cpy(&(dump_para.mnc), &(pMcf->tlvota_file[sim_id].mnc), MAX_MNC_STR_LEN);
kal_mem_cpy(&(dump_para.iccid), &(pMcf->tlvota_file[sim_id].iccid), 21);
dump_para.size = &lid_size;
for (i = 0; i < mcf_dump_param_tbl_num; i++) {
if ( (mcf_dump_param_tbl[i].lid == req->lid_num) ) {
is_found = KAL_TRUE;
if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OTA){
dump_para.type = MCF_TYPE_OTA;
dump_para.record_idx = req->rec_id;
if ((mcf_dump_param_tbl[i].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA) != 0) {
dump_para.lid = mcf_dump_param_tbl[i].lid;
dump_para.buffer = mcf_dump_buffer;
*(dump_para.size) = 0;
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OTA_CALLBACK(dump_para.lid, mcf_dump_param_tbl[i].ntfy_type, dump_para.record_idx);
ret = mcf_dump_param_tbl[i].dump_func_ptr(&dump_para);
if ( (ret == KAL_FALSE) || (*(dump_para.size) != lid_info.size) ) {
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OTA_DUMP_ERROR(mcf_dump_param_tbl[i].lid, ret, lid_info.size, *(dump_para.size));
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
} else {
/* If not register callback */
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OTA_NVRAM(lid_info.LID, mcf_dump_param_tbl[i].ntfy_type, dump_para.record_idx);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OTA_NVRAM_FAIL(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
}
}else if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OPOTA){
dump_para.type = MCF_TYPE_OTA_BY_OP;
dump_para.record_idx = 1;
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OPOTA_USIR(dump_para.lid, dump_para.record_idx, dump_para.ps_id, dump_para.sbp_id, dump_para.mnc, dump_para.mcc, dump_para.iccid);
if ((mcf_dump_param_tbl[i].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA_BY_OP) != 0) {
dump_para.lid = mcf_dump_param_tbl[i].lid;
dump_para.buffer = mcf_dump_buffer;
*(dump_para.size) = 0;
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OPOTA_CALLBACK_USIR(dump_para.lid, dump_para.type, dump_para.record_idx, dump_para.sbp_id, dump_para.mnc, dump_para.mcc, dump_para.iccid);
ret = mcf_dump_param_tbl[i].dump_func_ptr(&dump_para);
if ( (ret == KAL_FALSE) || (*(dump_para.size) != lid_info.size) ) {
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OPOTA_DUMP_FAIL(mcf_dump_param_tbl[i].lid, ret, lid_info.size, *(dump_para.size));
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
} else {
/* If not register callback */
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OPOTA_NVRAM(dump_para.lid, mcf_dump_param_tbl[i].ntfy_type);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OPOTA_NVRAM_FAIL(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
}
}
break;
}
}
if (is_found == KAL_FALSE){
/* If not register callback */
if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OTA){
dump_para.type = MCF_TYPE_OTA;
dump_para.record_idx = req->rec_id;
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OTA_NVRAM_NOT_CALLBACK(req->lid_num, req->rec_id);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OTA_NVRAM_FAIL_NOT_CALLBACK(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}else if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OPOTA){
dump_para.type = MCF_TYPE_OTA_BY_OP;
dump_para.record_idx = 1;
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OPOTA_NVRAM_NOT_CALLBACK_USIR(req->lid_num, dump_para.ps_id, dump_para.sbp_id, dump_para.mcc, dump_para.mnc, dump_para.iccid);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_OPOTA_NVRAM_FAIL_NOT_CALLBACK(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}
}
if (mcf_ret == MCF_OTA_R_INVALID_PARAMETER){
return mcf_ret;
}
mcf_toupper((char *)req->tag_name);
if (mcf_find_tag_offset(req->lid_num, (char *)req->tag_name, &item_byte_offset, &item_bit_offset, &item_size, &db_ptr, &query_tag) == KAL_FALSE) {
//Cannot find the tag
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_FIND_TAG_FAIL(req->lid_num, req->tag_name);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
for(i = 0; i < query_tag.arr_cnt; i++){
if (db_ptr->array_size[i]-1 < query_tag.array_size[i])
{
invalid_arr_size = KAL_TRUE;
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_INVALID_ARR_SIZE(db_ptr->array_size[i]-1, query_tag.array_size[i]);
break;
}
}
if (invalid_arr_size == KAL_TRUE){
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
resp->len = req->len;
read_len = req->len * db_ptr->variable_size;
if (read_len == 0)
{
read_len = 1 * db_ptr->variable_size;
}
if (read_len > db_ptr->total_size){
read_len = db_ptr->total_size;
}
if (read_len > 255){
read_len = 255;
}
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_LENGTH(read_len, db_ptr->variable_size, db_ptr->total_size);
kal_mem_set(lid_value, 0, 512);
if (query_tag.is_bit == KAL_FALSE){
j = query_tag.arr_cnt;
while(db_ptr->array_size[j] != 0){
n *= (db_ptr->array_size[j]);
j++;
next_level_array = KAL_TRUE;
}
if(req->len == 0)
{
read_len *= n;
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_TOTAL_ARRAY_SIZE(n, db_ptr->variable_size);
}
if(next_level_array == KAL_FALSE && read_len > item_size){
read_len = item_size;
}
if(next_level_array == KAL_TRUE && read_len > n*db_ptr->variable_size){
read_len = n*db_ptr->variable_size;
}
if (read_len > 255){
read_len = 255;
}
kal_mem_cpy(lid_value, (mcf_dump_buffer + item_byte_offset), read_len);
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_VARIABLE_BYTE(lid_value, read_len);
mcf_bytes_to_hex(lid_value, read_len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 512);
if (db_ptr->variable_size <= read_len){
resp->len = read_len / db_ptr->variable_size;
}else{
resp->len = read_len;
}
}else{
if (query_tag.upper_vsize == 1){
resp->len = 1;
}else if(query_tag.upper_vsize == 2){
resp->len = 2;
}else if(query_tag.upper_vsize == 4){
resp->len = 4;
}else{
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_VARIABLE_BIT_INVALID_BIT_LEN(query_tag.upper_vsize);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_VARIABLE_BIT_SIZE(query_tag.upper_vsize, resp->len);
if (db_ptr->is_bit == KAL_TRUE){
kal_mem_cpy(lid_value, (mcf_dump_buffer + item_byte_offset), resp->len);
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_VARIABLE_BIT_WHOLE(lid_value, resp->len);
mcf_bytes_to_hex(lid_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 512);
}else{
if (query_tag.upper_vsize == 1){
kal_uint8 bit_value = *(mcf_dump_buffer + item_byte_offset);
kal_uint8 bit_mask = (kal_uint8)MCF_GEN_BIT_MASK(item_size);
bit_value &= (bit_mask << item_bit_offset);
bit_value = ((kal_uint8)bit_value >> item_bit_offset);
resp->len = item_size/8+1;
mcf_bytes_to_hex(&bit_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 512);
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_VARIABLE_BIT(bit_value, resp->len);
}else if(query_tag.upper_vsize == 2){
kal_uint16 bit_value = 0;
kal_uint16 bit_mask = (kal_uint16)MCF_GEN_BIT_MASK(item_size);
kal_mem_cpy(&bit_value,(mcf_dump_buffer + item_byte_offset),2);
bit_value &= (bit_mask << item_bit_offset);
bit_value = ((kal_uint16)bit_value >> item_bit_offset);
resp->len = item_size/8+1;
mcf_bytes_to_hex(&bit_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 512);
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_VARIABLE_BIT(bit_value, resp->len);
}else if(query_tag.upper_vsize == 4){
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_mem_cpy(&bit_value,(mcf_dump_buffer + item_byte_offset),4);
bit_value &= (bit_mask << item_bit_offset);
bit_value = ((kal_uint32)bit_value >> item_bit_offset);
resp->len = item_size/8+1;
mcf_bytes_to_hex(&bit_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 512);
MD_TRC_MCF_TR_CONFIG_LID_VARIABLE_READ_VARIABLE_BIT(bit_value, resp->len);
}
}
}
#else
resp->len = req->len;
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
#endif
return mcf_ret;
}
_STATIC mcf_ota_result_e mcf_query_variable_value(
l4c_mcf_variable_value_operation_req_struct *req,
l4c_mcf_variable_value_operation_cnf_struct *resp)
{
mcf_t *pMcf = mcf_get_instance();
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
kal_bool ret = KAL_TRUE;
nvram_ltable_entry_struct lid_info = {0};
nvram_errno_enum nvram_api_ret;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
mcf_custom_dump_param_struct dump_para;
kal_uint32 lid_size;
kal_uint32 i;
kal_uint8 lid_value[512];
kal_uint32 read_len = 0;
kal_bool is_found = KAL_FALSE;
kal_uint16 lid = 0;
kal_bool is_bit;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_char hex_value[512];
#if defined(__MCF_FIND_TAG_SUPPORT__)
kal_bool invalid_arr_size = KAL_FALSE;
kal_bool next_level_array = KAL_FALSE;
kal_uint32 j = 0;
kal_uint32 n = 1;
MCF_DB_STRUCT_VARIABLE const *db_ptr = NULL;
mcf_tag_info_struct query_tag = {0};
#endif
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_START(req->format, req->action, req->num, req->rec_id);
kal_mem_set(&dump_para, 0, sizeof(mcf_custom_dump_param_struct));
resp->len = req->len;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_INVALID_SIM_ID(req->ps_id, sim_id);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if (req->format == L4C_MCF_QUERY_VARIABLE_FORM_PATH){
lid = req->num;
}else if(req->format == L4C_MCF_QUERY_VARIABLE_FORM_GID){
lid = mcf_find_gid_return_lid_num(req->num);
if (lid == 65535){
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_GET_LID_NUM_FAIL(req->num);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}
nvram_api_ret = nvram_external_get_lid_info(lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_GET_LID_INFO_FAIL(lid, nvram_api_ret);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
kal_mem_set(mcf_dump_buffer, 0, lid_info.size);
if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OTA){
if(req->rec_id > lid_info.total_records || req->rec_id == 0){
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_INVALID_REC_ID(req->rec_id, lid_info.total_records);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}
dump_para.ps_id = req->ps_id;
dump_para.sbp_id = pMcf->tlvota_file[sim_id].sbp_id;
kal_mem_cpy(&(dump_para.mcc), &(pMcf->tlvota_file[sim_id].mcc), MAX_MCC_STR_LEN);
kal_mem_cpy(&(dump_para.mnc), &(pMcf->tlvota_file[sim_id].mnc), MAX_MNC_STR_LEN);
kal_mem_cpy(&(dump_para.iccid), &(pMcf->tlvota_file[sim_id].iccid), 21);
dump_para.size = &lid_size;
for (i = 0; i < mcf_dump_param_tbl_num; i++) {
if ( (mcf_dump_param_tbl[i].lid == lid) ) {
is_found = KAL_TRUE;
if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OTA){
dump_para.type = MCF_TYPE_OTA;
dump_para.record_idx = req->rec_id;
if ((mcf_dump_param_tbl[i].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA) != 0) {
dump_para.lid = mcf_dump_param_tbl[i].lid;
dump_para.buffer = mcf_dump_buffer;
*(dump_para.size) = 0;
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OTA_CALLBACK(dump_para.lid, mcf_dump_param_tbl[i].ntfy_type, dump_para.record_idx);
ret = mcf_dump_param_tbl[i].dump_func_ptr(&dump_para);
if ( (ret == KAL_FALSE) || (*(dump_para.size) != lid_info.size) ) {
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OTA_DUMP_ERROR(mcf_dump_param_tbl[i].lid, ret, lid_info.size, *(dump_para.size));
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
} else {
/* If not register callback */
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OTA_NVRAM(lid_info.LID, mcf_dump_param_tbl[i].ntfy_type, dump_para.record_idx);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OTA_NVRAM_FAIL(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
}
}else if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OPOTA){
dump_para.type = MCF_TYPE_OTA_BY_OP;
dump_para.record_idx = 1;
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OPOTA_USIR(dump_para.lid, dump_para.record_idx, dump_para.ps_id, dump_para.sbp_id, dump_para.mnc, dump_para.mcc, dump_para.iccid);
if ((mcf_dump_param_tbl[i].ntfy_type & MCF_DUMP_NTFY_TYPE_OTA_BY_OP) != 0) {
dump_para.lid = mcf_dump_param_tbl[i].lid;
dump_para.buffer = mcf_dump_buffer;
*(dump_para.size) = 0;
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OPOTA_CALLBACK_USIR(dump_para.lid, dump_para.type, dump_para.record_idx, dump_para.sbp_id, dump_para.mnc, dump_para.mcc, dump_para.iccid);
ret = mcf_dump_param_tbl[i].dump_func_ptr(&dump_para);
if ( (ret == KAL_FALSE) || (*(dump_para.size) != lid_info.size) ) {
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OPOTA_DUMP_FAIL(mcf_dump_param_tbl[i].lid, ret, lid_info.size, *(dump_para.size));
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
} else {
/* If not register callback */
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OPOTA_NVRAM(dump_para.lid, mcf_dump_param_tbl[i].ntfy_type);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OPOTA_NVRAM_FAIL(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
}
}
break;
}
}
if (is_found == KAL_FALSE){
/* If not register callback */
if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OTA){
dump_para.type = MCF_TYPE_OTA;
dump_para.record_idx = req->rec_id;
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OTA_NVRAM_NOT_CALLBACK(lid, req->rec_id);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OTA_NVRAM_FAIL_NOT_CALLBACK(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}else if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OPOTA){
dump_para.type = MCF_TYPE_OTA_BY_OP;
dump_para.record_idx = 1;
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OPOTA_NVRAM_NOT_CALLBACK_USIR(lid, dump_para.ps_id, dump_para.sbp_id, dump_para.mcc, dump_para.mnc, dump_para.iccid);
dump_para.buffer = mcf_dump_buffer;
if ( !nvram_external_read_data(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size) ) {
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_OPOTA_NVRAM_FAIL_NOT_CALLBACK(lid_info.LID, dump_para.record_idx, dump_para.buffer, lid_info.size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}
}
if (mcf_ret == MCF_OTA_R_INVALID_PARAMETER){
return mcf_ret;
}
if (req->format == L4C_MCF_QUERY_VARIABLE_FORM_PATH){
#if defined(__MCF_FIND_TAG_SUPPORT__)
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_TAG(req->config);
mcf_toupper((char *)req->config);
if (mcf_find_tag_offset(lid, (char *)req->config, &item_byte_offset, &item_bit_offset, &item_size, &db_ptr, &query_tag) == KAL_FALSE) {
//Cannot find the tag
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_FIND_TAG_FAIL(lid, req->config);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
for(i = 0; i < query_tag.arr_cnt; i++){
if (db_ptr->array_size[i]-1 < query_tag.array_size[i])
{
invalid_arr_size = KAL_TRUE;
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_INVALID_ARR_SIZE(db_ptr->array_size[i]-1, query_tag.array_size[i]);
break;
}
}
if (invalid_arr_size == KAL_TRUE){
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
resp->len = req->len;
read_len = req->len * db_ptr->variable_size;
if (read_len == 0)
{
read_len = 1 * db_ptr->variable_size;
}
if (read_len > db_ptr->total_size){
read_len = db_ptr->total_size;
}
if (read_len > 255){
read_len = 255;
}
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_LENGTH(read_len, db_ptr->variable_size, db_ptr->total_size);
kal_mem_set(lid_value, 0, 512);
if (query_tag.is_bit == KAL_FALSE){
j = query_tag.arr_cnt;
while(db_ptr->array_size[j] != 0){
n *= (db_ptr->array_size[j]);
j++;
next_level_array = KAL_TRUE;
}
if(req->len == 0)
{
read_len *= n;
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_TOTAL_ARRAY_SIZE(n, db_ptr->variable_size);
}
if(next_level_array == KAL_FALSE && read_len > item_size){
read_len = item_size;
}
if(next_level_array == KAL_TRUE && read_len > n*db_ptr->variable_size){
read_len = n*db_ptr->variable_size;
}
if (read_len > 255){
read_len = 255;
}
kal_mem_cpy(lid_value, (mcf_dump_buffer + item_byte_offset), read_len);
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BYTE(lid_value, read_len);
mcf_bytes_to_hex(lid_value, read_len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 511);
if (db_ptr->variable_size <= read_len){
resp->len = read_len / db_ptr->variable_size;
}else{
resp->len = read_len;
}
}else{
if (query_tag.upper_vsize == 1){
resp->len = 1;
}else if(query_tag.upper_vsize == 2){
resp->len = 2;
}else if(query_tag.upper_vsize == 4){
resp->len = 4;
}else{
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT_INVALID_BIT_LEN(query_tag.upper_vsize);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT_SIZE(query_tag.upper_vsize, resp->len);
if (db_ptr->is_bit == KAL_TRUE){
kal_mem_cpy(lid_value, (mcf_dump_buffer + item_byte_offset), resp->len);
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT_WHOLE(lid_value, resp->len);
mcf_bytes_to_hex(lid_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 511);
}else{
if (query_tag.upper_vsize == 1){
kal_uint8 bit_value = *(mcf_dump_buffer + item_byte_offset);
kal_uint8 bit_mask = (kal_uint8)MCF_GEN_BIT_MASK(item_size);
bit_value &= (bit_mask << item_bit_offset);
bit_value = ((kal_uint8)bit_value >> item_bit_offset);
resp->len = item_size/8+1;
mcf_bytes_to_hex(&bit_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 511);
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT(bit_value, resp->len);
}else if(query_tag.upper_vsize == 2){
kal_uint16 bit_value = 0;
kal_uint16 bit_mask = (kal_uint16)MCF_GEN_BIT_MASK(item_size);
kal_mem_cpy(&bit_value,(mcf_dump_buffer + item_byte_offset),2);
bit_value &= (bit_mask << item_bit_offset);
bit_value = ((kal_uint16)bit_value >> item_bit_offset);
resp->len = item_size/8+1;
mcf_bytes_to_hex(&bit_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 511);
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT(bit_value, resp->len);
}else if(query_tag.upper_vsize == 4){
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_mem_cpy(&bit_value,(mcf_dump_buffer + item_byte_offset),4);
bit_value &= (bit_mask << item_bit_offset);
bit_value = ((kal_uint32)bit_value >> item_bit_offset);
resp->len = item_size/8+1;
mcf_bytes_to_hex(&bit_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(kal_char *)(resp->value), hex_value, 511);
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT(bit_value, resp->len);
}
}
}
#else
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
#endif
}else if(req->format == L4C_MCF_QUERY_VARIABLE_FORM_GID){
kal_mem_set(array_tag, 0, MCF_FILE_MAX_ARRAY_TAG_LEN);
if(strcmp((kal_char *)req->config, "") != 0){
strncpy(array_tag, (kal_char *)req->config, MCF_FILE_MAX_ARRAY_TAG_LEN-1);
array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN-1] = '\0';
if (strlen((kal_char *)req->config) >= MCF_FILE_MAX_ARRAY_TAG_LEN){
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_INVALID_ARRAY_INDEX_LEN(MCF_FILE_MAX_ARRAY_TAG_LEN, strlen((kal_char *)req->config));
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
mcf_replace_char(array_tag, ',', '$');
if (strlen(array_tag) != 0 && array_tag[strlen(array_tag)] != '$'){
array_tag[strlen(array_tag)] = '$';
}
}
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_ARRAY_INDEX(req->num, array_tag);
if (mcf_find_gid_offset(req->num, array_tag, &lid, &item_byte_offset, &item_bit_offset, &item_size, &is_bit) == KAL_FALSE) {
//Cannot find the gid
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_FIND_GID_FAIL(lid, req->config);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if(req->len == 0){
read_len = item_size;
}else{
read_len = req->len;
}
if(read_len > (lid_info.size-item_byte_offset)){
read_len = lid_info.size-item_byte_offset;
}
if(read_len > 255){
read_len = 255;
}
if (is_bit == KAL_FALSE){
kal_mem_cpy(lid_value, (mcf_dump_buffer + item_byte_offset), read_len);
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BYTE(lid_value, read_len);
mcf_bytes_to_hex(lid_value, read_len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 511);
resp->len = read_len;
}else{
kal_uint32 align_addr;
kal_uint32 bit_value;
kal_uint32 *ptr = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
MCF_READ_ADDR_GET_ALIGN((kal_uint32)(mcf_dump_buffer + item_byte_offset),align_addr);
ptr = (kal_uint32 *)align_addr;
bit_value = *(ptr);
bit_value = bit_value >> ((((kal_uint32)(mcf_dump_buffer + item_byte_offset))-align_addr)*8);
bit_value = (bit_value >> item_bit_offset);
bit_value &= bit_mask;
if (item_size <= 8){
resp->len = 1;
}else if(item_size > 8 && item_size <= 16){
resp->len = 2;
}else if(item_size > 16 && item_size <= 32){
if (item_size % 8 == 0){
resp->len = item_size/8;
}else{
resp->len = item_size/8+1;
}
}else if (item_size > 32){
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT_INVALID_BIT_LEN(item_size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_READ_VARIABLE_BIT(bit_value, resp->len);
mcf_bytes_to_hex(&bit_value, resp->len, KAL_TRUE, hex_value);
strncpy((kal_char *)(resp->value), hex_value, 511);
}
}
return mcf_ret;
}
#ifdef __MCF_COMBINE_FILE_SUPPORT__
_STATIC mcf_ota_result_e mcf_set_variable_value(
l4c_mcf_variable_value_operation_req_struct *req,
l4c_mcf_variable_value_operation_cnf_struct *resp)
{
mcf_t *pMcf = mcf_get_instance();
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_uint16 lid = 0;
static kal_char lid_value[512];
kal_bool is_bit;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_int32 value_len;
kal_uint32 operation_mask = 0;
mcf_tool_file_info_t *pFile;
kal_uint32 align_len = 0;
kal_int32 fs_ret = FS_NO_ERROR;
static kal_char hex_value[512];
nvram_ltable_entry_struct lid_info = {0};
nvram_errno_enum nvram_api_ret;
static kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type;
kal_bool read_file_fail = KAL_FALSE;
kal_int32 ret_snprintf;
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_START(req->format, req->action, req->num, req->rec_id);
resp->len = req->len;
if(req->format == L4C_MCF_QUERY_VARIABLE_FORM_GID){
kal_mem_set(array_tag, 0, MCF_FILE_MAX_ARRAY_TAG_LEN);
if(strcmp((kal_char *)req->config, "") != 0){
strncpy(array_tag, (kal_char *)req->config, MCF_FILE_MAX_ARRAY_TAG_LEN-1);
array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN-1] = '\0';
if (strlen((kal_char *)req->config) >= MCF_FILE_MAX_ARRAY_TAG_LEN){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_ARRAY_INDEX_LEN(MCF_FILE_MAX_ARRAY_TAG_LEN, strlen((kal_char *)req->config));
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
mcf_replace_char(array_tag, ',', '$');
if (strlen(array_tag) != 0 && array_tag[strlen(array_tag)] != '$'){
array_tag[strlen(array_tag)] = '$';
}
}
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_ARRAY_INDEX(req->num, array_tag);
kal_mem_set(lid_value, 0, 512);
kal_mem_set(hex_value, 0, 512);
kal_mem_cpy(hex_value, req->value, 511);
/* If value length is odd, need to add '0'*/
kal_mem_cpy(hex_value, req->value, 511);
value_len = strlen(hex_value);
if(strlen(hex_value) % 2 != 0){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_VALUE_LEN(strlen(hex_value));
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
mcf_hex_to_bytes(hex_value, &value_len, lid_value);
if(req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_WRITE_OTA){
mcf_tool_gid_ota_file_item_t pItem;
mcf_ota_file_t *ota_file = &(pMcf->ota_file);
nvram_ef_mcf_ota_file_info_struct nv_ota_file;
kal_mem_set(&pItem, 0, sizeof(mcf_tool_gid_ota_file_item_t));
/*Compose a file content*/
pItem.global_id = req->num;
pItem.record_idx = req->rec_id;
pItem.array_index_len = strlen(array_tag);
if (mcf_find_gid_offset(req->num, array_tag, &lid, &item_byte_offset, &item_bit_offset, &item_size, &is_bit) == KAL_FALSE) {
//Cannot find the gid
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_FIND_GID_FAIL(lid, req->config);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
nvram_api_ret = nvram_external_get_lid_info(lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_GET_LID_INFO_FAIL(lid, nvram_api_ret);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if(req->rec_id > lid_info.total_records || req->rec_id == 0){
MD_TRC_MCF_TR_QUERY_VARIABLE_VALUE_INVALID_REC_ID(req->rec_id, lid_info.total_records);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if (pItem.array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_ARRAY_INDEX_LEN(MCF_FILE_MAX_ARRAY_TAG_LEN, pItem.array_index_len);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if(value_len > item_size){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_VAL_LEN(value_len, item_size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
pItem.total_len = 16;
if(is_bit == KAL_TRUE){
pItem.value_len = item_size/8+1;
item_size = item_size/8+1;
}else{
pItem.value_len = item_size;
}
pItem.total_len += item_size;
pItem.total_len += pItem.array_index_len;
if (pItem.total_len % 4 != 0){
align_len = (4-(pItem.total_len % 4));
pItem.total_len += align_len;
}
resp->len = pItem.value_len;
if (pItem.array_index_len > 0){
strncpy(&(pItem.buff_start), array_tag, 1);
}else{
strncpy(&(pItem.buff_start), lid_value, 1);
}
kal_mem_set(mcf_gid_buff, 0, 128);
kal_mem_cpy(mcf_gid_buff, &pItem, pItem.total_len);
strncpy(mcf_gid_buff+16, array_tag, strlen(array_tag));
kal_mem_cpy(mcf_gid_buff+16+strlen(array_tag), lid_value, value_len);
kal_mem_set(mcf_gid_buff+16+strlen(array_tag)+value_len, 0, item_size-value_len);
kal_mem_set(mcf_gid_buff+16+strlen(array_tag)+item_size, 0, align_len);
operation_mask |= MCF_FILE_OP_CHECKSUM;
kal_mem_set(mcf_file_buffer, 0, MCF_MAX_FILE_SIZE);
/* Read MCF OTA file information to NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_READ_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
mcf_ret = MCF_OTA_R_READ_NVRAM_FAIL;
return mcf_ret;
}
if (strcmp(nv_ota_file.merged_path,"") == 0){
strncpy(nv_ota_file.merged_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
}
if (strcmp(nv_ota_file.merged_name,"") == 0){
strncpy(nv_ota_file.merged_name, MCF_FS_DEFAULT_OTA_MERGED_FILE_NAME, MCF_FILE_MAX_NAME_LEN - 1);
}
if(mcf_merge_one_gid(mcf_gid_buff, MCF_TYPE_OTA, mcf_file_buffer, MCF_MAX_OTA_FILE_SIZE, operation_mask) != KAL_TRUE){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_MERGE_GID_TO_FILE_FAIL(MCF_TYPE_OTA);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
mcf_ret = mcf_read_ota_file(KAL_FALSE, nv_ota_file.path, nv_ota_file.name, &apply_path_type, apply_filename, pMcf);
//Read fail return fail
if(mcf_ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_READ_FILE_FAIL(nv_ota_file.path, nv_ota_file.name, mcf_ret);
read_file_fail = KAL_TRUE;
}
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
/* Check if file type is OTA file */
if (read_file_fail == KAL_TRUE || strcmp(pFile->file_type, MCF_FILE_TYPE_OTA) != 0) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_MERGE_FILE();
kal_mem_cpy(mcf_merge_buffer, mcf_file_buffer, MCF_MAX_OTA_FILE_SIZE);
}else{
if (mcf_merge_ota_buffer(ota_file->buff, mcf_file_buffer, mcf_merge_buffer, MCF_MAX_OTA_FILE_SIZE) != KAL_TRUE){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_MERGE_OTA_FILE_FAIL();
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
}else{
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAKE_READ_LOCK_FAIL();
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return mcf_ret;
}
/* Before create merged OTA file, need to delete last time merged OTA file */
kal_wsprintf(merge_ota_name, "%s\\%s\0", nv_ota_file.merged_path, nv_ota_file.merged_name);
fs_ret = FS_Delete(merge_ota_name);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_DELETE_FILE_FAIL(fs_ret);
mcf_ret = MCF_OTA_R_WRITE_DISK_FAIL;
return mcf_ret;
}
pFile = (mcf_tool_file_info_t *)mcf_merge_buffer;
if(pFile->file_size > MCF_MAX_OTA_FILE_SIZE){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_FILE_SIZE(pFile->file_size, MCF_MAX_OTA_FILE_SIZE);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
/*Write Merged OTA file*/
mcf_ret = mcf_write_buffer(nv_ota_file.merged_path, nv_ota_file.merged_name, (kal_uint8 *)mcf_merge_buffer, pFile->file_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_WRITE_FILE_FAIL(nv_ota_file.merged_path, nv_ota_file.merged_name);
return mcf_ret;
}
strncpy(nv_ota_file.path, nv_ota_file.merged_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.name, nv_ota_file.merged_name, MCF_FILE_MAX_NAME_LEN - 1);
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_WRITE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
mcf_ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return mcf_ret;
}
}else if (req->action == L4C_MCF_CONFIG_LID_VARIABLE_ACT_WRITE_OPOTA){
mcf_tool_gid_tlvota_file_item_t pItem_op;
mcf_tlvota_file_t *tlvota_file;
kal_char tag[MCF_MAX_TAG_LEN];
kal_bool is_general = KAL_FALSE;
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_SIM_ID(req->ps_id, sim_id);
return KAL_FALSE;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
/*Compose a file content*/
pItem_op.global_id = req->num;
pItem_op.array_index_len = strlen(array_tag);
if (mcf_find_gid_offset(req->num, array_tag, &lid, &item_byte_offset, &item_bit_offset, &item_size, &is_bit) == KAL_FALSE) {
//Cannot find the gid
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_FIND_GID_FAIL(lid, req->config);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if (pItem_op.array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_ARRAY_INDEX_LEN(MCF_FILE_MAX_ARRAY_TAG_LEN, pItem_op.array_index_len);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
if(value_len > item_size){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_VAL_LEN(value_len, item_size);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
pItem_op.tag_type = MCF_TLVOTA_TAG_SBPID;
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TLVOTA_SBPID(tlvota_file->sbp_id, tlvota_file->mcc, tlvota_file->mnc);
if (tlvota_file->sbp_id != SBP_ID_INVALID) {
is_general = KAL_FALSE;
if (strcmp((kal_char *)tlvota_file->mcc, "") != 0) {
if (strcmp((kal_char *)tlvota_file->mnc, "") != 0){
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "%d_%s_%s%c", tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "SBP_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}else{
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "%d_%s_NA%c", tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "SBP_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}
}else{
if (strcmp((kal_char *)tlvota_file->mnc, "") != 0){
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "%d_NA_%s%c", tlvota_file->sbp_id, (kal_char *)tlvota_file->mnc, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "SBP_NA_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}else{
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "%d_NA_NA%c", tlvota_file->sbp_id, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "SBP_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}
}
}else{
is_general = KAL_TRUE;
if (strcmp((kal_char *)tlvota_file->mcc, "") != 0) {
if (strcmp((kal_char *)tlvota_file->mnc, "") != 0){
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "NA_%s_%s%c", (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "NA_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}else{
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "NA_%s_NA%c", (kal_char *)tlvota_file->mcc, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}
}else{
if (strcmp((kal_char *)tlvota_file->mnc, "") != 0){
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "NA_NA_%s%c", (kal_char *)tlvota_file->mnc, '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "NA_NA_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}else{
is_general = KAL_FALSE;
ret_snprintf = kal_snprintf(tag, MCF_MAX_TAG_LEN, "NA_NA_NA%c", '\0');
if (ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag, "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAG_SNPRINTF_FAIL(tag, tlvota_file->sbp_id, (kal_char *)tlvota_file->mcc, (kal_char *)tlvota_file->mnc);
}
}
}
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAKE_READ_LOCK_FAIL();
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return mcf_ret;
}
if(is_general == KAL_TRUE){
tlvota_file = &(pMcf->general_tlvota_file);
}
pItem_op.tag_len = strlen(tag);
pItem_op.total_len = 16;
if(is_bit == KAL_TRUE){
pItem_op.value_len = item_size/8+1;
item_size = item_size/8+1;
}else{
pItem_op.value_len = item_size;
}
pItem_op.total_len += pItem_op.value_len;
pItem_op.total_len += pItem_op.array_index_len;
pItem_op.total_len += pItem_op.tag_len;
if (pItem_op.total_len % 4 != 0){
align_len = (4-(pItem_op.total_len % 4));
pItem_op.total_len += align_len;
}
resp->len = pItem_op.value_len;
strncpy(&(pItem_op.buff_start), tag, 1);
kal_mem_set(mcf_gid_buff, 0, 128);
kal_mem_cpy(mcf_gid_buff, &pItem_op, pItem_op.total_len);
strncpy(mcf_gid_buff+16, tag, strlen(tag));
strncpy(mcf_gid_buff+16+strlen(tag), array_tag, strlen(array_tag));
kal_mem_cpy(mcf_gid_buff+16+strlen(tag)+strlen(array_tag), lid_value, value_len);
kal_mem_set(mcf_gid_buff+16+strlen(tag)+strlen(array_tag)+value_len, 0, item_size-value_len);
kal_mem_set(mcf_gid_buff+16+strlen(tag)+strlen(array_tag)+item_size, 0, align_len);
operation_mask |= MCF_FILE_OP_CHECKSUM;
kal_mem_set(mcf_file_buffer, 0, MCF_MAX_FILE_SIZE);
if(is_general == KAL_FALSE){
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_READ_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
mcf_ret = MCF_OTA_R_READ_NVRAM_FAIL;
return mcf_ret;
}
mcf_ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, nv_tlvota_file.path, nv_tlvota_file.name, &apply_path_type, apply_filename, pMcf);
if(mcf_ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_READ_FILE_FAIL(nv_tlvota_file.path, nv_tlvota_file.name, mcf_ret);
read_file_fail = KAL_TRUE;
}
}else{
/* Read MCF general TLV-OTA file into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_READ_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
mcf_ret = MCF_OTA_R_READ_NVRAM_FAIL;
return mcf_ret;
}
mcf_ret = mcf_read_general_tlvota_file(KAL_FALSE, nv_tlvota_file.path, nv_tlvota_file.name, &apply_path_type, apply_filename, pMcf);
if(mcf_ret != MCF_OTA_R_SUCCESS){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_READ_FILE_FAIL(nv_tlvota_file.path, nv_tlvota_file.name, mcf_ret);
read_file_fail = KAL_TRUE;
}
}
if (strcmp(nv_tlvota_file.merged_path,"") == 0){
strncpy(nv_tlvota_file.merged_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
}
if (strcmp(nv_tlvota_file.merged_name,"") == 0){
if(is_general == KAL_FALSE){
mcf_snprintf(nv_tlvota_file.merged_name, MCF_FILE_MAX_NAME_LEN, "%s_%d.mcfopota%c", MCF_FS_DEFAULT_TLVOTA_MERGED_FILE_PREFIX, sim_id, '\0');
}else{
strncpy(nv_tlvota_file.merged_name, MCF_FS_GENERAL_TLVOTA_MERGED_FILE_NAME, MCF_FILE_MAX_NAME_LEN - 1);
}
}
if(mcf_merge_one_gid(mcf_gid_buff, MCF_TYPE_OTA_BY_OP, mcf_file_buffer, MCF_MAX_TLVOTA_FILE_SIZE, operation_mask) != KAL_TRUE){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_MERGE_GID_TO_FILE_FAIL(MCF_TYPE_OTA_BY_OP);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is OTA file */
if (read_file_fail == KAL_TRUE || strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_MERGE_FILE();
kal_mem_cpy(mcf_merge_buffer, mcf_file_buffer, MCF_MAX_TLVOTA_FILE_SIZE);
}else{
if(mcf_merge_ota_buffer(tlvota_file->buff, mcf_file_buffer, mcf_merge_buffer, MCF_MAX_TLVOTA_FILE_SIZE) != KAL_TRUE){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_MERGE_OTA_FILE_FAIL();
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
mcf_ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_TAKE_READ_LOCK_FAIL();
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return mcf_ret;
}
/* Before create merged OTA file, need to delete last time merged OTA file */
kal_wsprintf(merge_ota_name, "%s\\%s\0", nv_tlvota_file.merged_path, nv_tlvota_file.merged_name);
fs_ret = FS_Delete(merge_ota_name);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_DELETE_FILE_FAIL(fs_ret);
mcf_ret = MCF_OTA_R_WRITE_DISK_FAIL;
return mcf_ret;
}
pFile = (mcf_tool_file_info_t *)mcf_merge_buffer;
if(pFile->file_size > MCF_MAX_TLVOTA_FILE_SIZE){
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_INVALID_FILE_SIZE(pFile->file_size, MCF_MAX_TLVOTA_FILE_SIZE);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
/*Write Merged OTA file*/
mcf_ret = mcf_write_buffer(nv_tlvota_file.merged_path, nv_tlvota_file.merged_name, (kal_uint8 *)mcf_merge_buffer, pFile->file_size);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_WRITE_FILE_FAIL(nv_tlvota_file.merged_path, nv_tlvota_file.merged_name);
return mcf_ret;
}
strncpy(nv_tlvota_file.path, nv_tlvota_file.merged_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.name, nv_tlvota_file.merged_name, MCF_FILE_MAX_NAME_LEN - 1);
if(is_general == KAL_FALSE){
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_WRITE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
mcf_ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return mcf_ret;
}
}else{
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_SET_VARIABLE_VALUE_WRITE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
mcf_ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return mcf_ret;
}
}
if (pMcf->is_ignore_dsbp[sim_id] == KAL_FALSE) {
/* If MCF is in DSBP passive mode, change to DSBP active mode */
mcf_ret = mcf_set_dsbp_mode(KAL_TRUE, KAL_FALSE, sim_id);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
return mcf_ret;
}
pMcf->is_ignore_dsbp[sim_id] = KAL_TRUE;
}
}
}
return mcf_ret;
}
#endif
#ifdef __MCF_COMBINE_FILE_SUPPORT__
_STATIC mcf_ota_result_e mcf_assign_combined_file_path(l4c_mcf_set_config_req_struct *req)
{
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
switch (req->config_type)
{
case L4C_MCF_CONFIG_TYPE_DEFAULT_BIN:
{
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char curr_filename[MCF_FILE_MAX_NAME_LEN];
kal_char *file_extension1 = NULL;
kal_char *file_extension2 = NULL;
nvram_ef_mcf_ota_file_info_struct nv_ota_file;
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
file_extension1 = strstr((kal_char *)req->config1, ".mcfota");
if (file_extension1 == NULL){
file_extension2 = strstr((kal_char *)req->config1, ".bin");
if (file_extension2 == NULL) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_FILE_TYPE((kal_char *)req->config1);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_NAME_LEN - 1);
} else {
strncpy(curr_filename, MCF_FS_DEFAULT_OTA_MERGED_FILE_NAME, MCF_FILE_MAX_NAME_LEN - 1);
}
/* Read MCF OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_ota_file.merged_path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_ota_file.merged_name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
nv_int_info.is_combined_ota = KAL_TRUE;
/* Write MCF OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_OTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_TYPE_CARRIER_BIN:
{
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char curr_filename[MCF_FILE_MAX_NAME_LEN];
kal_char *file_extension1 = NULL;
kal_char *file_extension2 = NULL;
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_SIM_ID(req->ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
file_extension1 = strstr((kal_char *)req->config1, ".mcfopota");
if (file_extension1 == NULL){
file_extension2 = strstr((kal_char *)req->config1, ".bin");
if (file_extension2 == NULL) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_FILE_TYPE((kal_char *)req->config1);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_NAME_LEN - 1);
} else {
strncpy(curr_filename, MCF_FS_DEFAULT_TLVOTA_MERGED_FILE_NAME, MCF_FILE_MAX_NAME_LEN - 1);
}
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
/* Read MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = KAL_FALSE;
return MCF_OTA_R_READ_NVRAM_FAIL;
}
strncpy(nv_tlvota_file.merged_path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.merged_name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
nv_int_info.is_combined_tlvota[sim_id] = KAL_TRUE;
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
/* Write MCF TLV-OTA file information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, sim_id + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct)) ) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_TLVOTA_FILE_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
break;
}
case L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN:
{
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char curr_filename[MCF_FILE_MAX_NAME_LEN];
kal_char *file_extension1 = NULL;
kal_char *file_extension2 = NULL;
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
if (req->path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (req->path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_PATH_TYPE(req->path_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if (strcmp((kal_char *)req->config1, "") != 0) {
file_extension1 = strstr((kal_char *)req->config1, ".mcfopota");
if (file_extension1 == NULL){
file_extension2 = strstr((kal_char *)req->config1, ".bin");
if (file_extension2 == NULL) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_FILE_TYPE((kal_char *)req->config1);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
}
strncpy(curr_filename, (kal_char *)req->config1, MCF_FILE_MAX_NAME_LEN - 1);
} else {
strncpy(curr_filename, MCF_FS_GENERAL_TLVOTA_MERGED_FILE_NAME, MCF_FILE_MAX_NAME_LEN - 1);
}
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
/* Read MCF general TLV-OTA file into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_READ_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
strncpy(nv_tlvota_file.merged_path, fs_root_path, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_tlvota_file.merged_name, curr_filename, MCF_FILE_MAX_NAME_LEN - 1);
nv_int_info.is_combined_general_tlvota = KAL_TRUE;
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
return ret;
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_WRITE_FILE_NVRAM_FAIL(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
break;
}
default:
{
MD_TRC_MCF_TR_ASSIGN_COMBINED_FILE_PATH_INVALID_CONFIG_TYPE(req->config_type);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
}
return ret;
}
#endif
_STATIC mcf_ota_result_e mcf_l4_set_config(ilm_struct *ilm)
{
l4c_mcf_set_config_req_struct *req = (l4c_mcf_set_config_req_struct *)ilm->local_para_ptr;
l4c_mcf_set_config_cnf_struct *local_para_ptr = NULL;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_ota_result_e write_ret;
kal_int32 fs_ret = FS_NO_ERROR;
kal_wchar pathname[MCF_FILE_MAX_MD_PATH_LEN];
kal_uint32 ret_sprintf;
switch (req->op)
{
case L4C_MCF_CONFIG_SET_OTA_AND_OPOTA_FILE_PATH:
case L4C_MCF_CONFIG_SET_OTA_FILE_PATH:
case L4C_MCF_CONFIG_SET_OPOTA_FILE_PATH:
ret = mcf_set_file_path(req);
break;
case L4C_MCF_CONFIG_SET_FILE_PATH_IN_MCF_DSBP_ACTIVE_MODE:
{
mcf_t *pMcf = mcf_get_instance();
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(req->ps_id);
mcf_l4bsbp_trigger_dsbp_ind_struct *ind_ptr = NULL;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_L4_SET_CONFIG_INVALID_SIM_ID(req->ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if (pMcf->is_dsbp_ongoing[sim_id] == KAL_TRUE) {
MD_TRC_MCF_TR_L4_SET_CONFIG_DSBP_ONGOING(req->ps_id, sim_id);
/* Send process result to ATCI */
local_para_ptr = (l4c_mcf_set_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_set_config_cnf_struct), TD_RESET);
if (!local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
local_para_ptr->src_id = req->src_id;
local_para_ptr->op = L4C_MCF_CONFIG_SET_FILE_PATH_IN_MCF_DSBP_ACTIVE_MODE;
local_para_ptr->dsbp_result = MCF_TRIGGER_DSBP_R_FAIL_MCF_DSBP_ONGOING;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_SET_CONFIG_CNF, /* msg_id */
(local_para_struct*)local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
goto out;
}
ret = mcf_set_file_path(req);
if (ret == MCF_OTA_R_SUCCESS) {
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->config_op = L4C_MCF_CONFIG_SET_FILE_PATH_IN_MCF_DSBP_ACTIVE_MODE;
ind_ptr->src_mod_id = ilm->src_mod_id;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + req->ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->is_dsbp_ongoing[sim_id] = KAL_TRUE;
/* Support MCF Tool Send AT cmd - delete txt */
kal_wsprintf(pathname, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT);
fs_ret = FS_Delete(pathname);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_L4_SET_CONFIG_DELETE_FILE_FAIL(fs_ret);
ret = MCF_OTA_R_WRITE_DISK_FAIL;
return ret;
}
/* Support MCF Tool Send AT cmd - Write AT cmd result in txt */
kal_mem_set(txt_buff, 0, 64);
ret_sprintf = kal_sprintf(txt_buff, "EMCFC=%d,%d,%d%c", L4C_MCF_CONFIG_SET_FILE_PATH_IN_MCF_DSBP_ACTIVE_MODE, 0, MCF_TRIGGER_DSBP_R_FAIL_MCF_DSBP_ONGOING, '\0');
if (ret_sprintf < 0 || ret_sprintf > 64){
strncpy(txt_buff, "EMCFC unknown error", 63);
}
MD_TRC_MCF_TR_L4_SET_CONFIG_CMD_RESULT(txt_buff);
write_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, strlen(txt_buff));
if (write_ret != MCF_OTA_R_SUCCESS) {
return write_ret;
}
goto out;
}else {
/* Send process result to ATCI */
local_para_ptr = (l4c_mcf_set_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_set_config_cnf_struct), TD_RESET);
if (!local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
local_para_ptr->src_id = req->src_id;
local_para_ptr->op = L4C_MCF_CONFIG_SET_FILE_PATH_IN_MCF_DSBP_ACTIVE_MODE;
local_para_ptr->mcf_result = ret;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_SET_CONFIG_CNF, /* msg_id */
(local_para_struct*)local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
goto out;
}
break;
}
case L4C_MCF_CONFIG_SET_FILE_PATH_AND_AUTO_SELECT_BIN:
{
mcf_l4bsbp_trigger_dsbp_ind_struct *ind_ptr = NULL;
kal_uint32 i = 0;
mcf_t *pMcf = mcf_get_instance();
ret = mcf_set_file_path(req);
if ( (req->trigger_dsbp == 1) && (ret == MCF_OTA_R_SUCCESS) ) {
/*
* Trigger DSBP and do not respond to AP immediately.
* Wait DSBP response, and then respond to AP.
*/
if (req->config_type == L4C_MCF_CONFIG_TYPE_GENERAL_CARRIER_BIN){
//General OP-OTA need to trigger dsbp all sims
dsbp_ret = 0;
for (i = 0; i < MAX_SIM_NUM; i++){
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->config_op = req->op;
ind_ptr->src_mod_id = ilm->src_mod_id;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + i, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
pMcf->dsbp_cnf_cnt ++;
pMcf->dsbp_ind_cnt ++;
pMcf->dsbp_cnf_ret = KAL_TRUE;
ret = MCF_OTA_R_SUCCESS;
}
}else{
//OTA and OP-OTA only need to by sim trigger dsbp
ind_ptr = (mcf_l4bsbp_trigger_dsbp_ind_struct *)construct_local_para(sizeof(mcf_l4bsbp_trigger_dsbp_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->src_id = req->src_id;
ind_ptr->config_op = req->op;
ind_ptr->src_mod_id = ilm->src_mod_id;
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4BSBP + req->ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
}
/* Support MCF Tool Send AT cmd - delete txt */
kal_wsprintf(pathname, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT);
fs_ret = FS_Delete(pathname);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_L4_SET_CONFIG_DELETE_FILE_FAIL(fs_ret);
ret = MCF_OTA_R_WRITE_DISK_FAIL;
return ret;
}
/* Support MCF Tool Send AT cmd - Write AT cmd result in txt */
kal_mem_set(txt_buff, 0, 64);
ret_sprintf = kal_sprintf(txt_buff, "EMCFC=%d,%d,%d%c", L4C_MCF_CONFIG_SET_FILE_PATH_AND_AUTO_SELECT_BIN, 0, MCF_TRIGGER_DSBP_R_FAIL_MCF_DSBP_ONGOING, '\0');
if (ret_sprintf < 0 || ret_sprintf > 64){
strncpy(txt_buff, "EMCFC unknown error", 63);
}
MD_TRC_MCF_TR_L4_SET_CONFIG_CMD_RESULT(txt_buff);
write_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, strlen(txt_buff));
if (write_ret != MCF_OTA_R_SUCCESS) {
return write_ret;
}
goto out;
} else {
/* Send process result to ATCI */
local_para_ptr = (l4c_mcf_set_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_set_config_cnf_struct), TD_RESET);
if (!local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
local_para_ptr->src_id = req->src_id;
local_para_ptr->op = req->op;
local_para_ptr->mcf_result = ret;
local_para_ptr->dsbp_result = 0;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_SET_CONFIG_CNF, /* msg_id */
(local_para_struct*)local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
/* Support MCF Tool Send AT cmd - delete txt */
kal_wsprintf(pathname, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT);
fs_ret = FS_Delete(pathname);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_L4_SET_CONFIG_DELETE_FILE_FAIL(fs_ret);
ret = MCF_OTA_R_WRITE_DISK_FAIL;
return ret;
}
/* Support MCF Tool Send AT cmd - Write AT cmd result in txt */
kal_mem_set(txt_buff, 0, 64);
ret_sprintf = kal_sprintf(txt_buff, "EMCFC=%d,%d,%d%c", L4C_MCF_CONFIG_SET_FILE_PATH_AND_AUTO_SELECT_BIN, ret, 0, '\0');
if (ret_sprintf < 0 || ret_sprintf > 64){
strncpy(txt_buff, "EMCFC unknown error", 63);
}
MD_TRC_MCF_TR_L4_SET_CONFIG_CMD_RESULT(txt_buff);
write_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, strlen(txt_buff));
if (write_ret != MCF_OTA_R_SUCCESS) {
return write_ret;
}
goto out;
}
break;
}
default:
MD_TRC_MCF_TR_L4_SET_CONFIG_UNKNOWN_OP(req->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
/* Send process result to ATCI */
local_para_ptr = (l4c_mcf_set_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_set_config_cnf_struct), TD_RESET);
if (!local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
local_para_ptr->src_id = req->src_id;
if (ret == MCF_OTA_R_SUCCESS) {
local_para_ptr->result = KAL_TRUE;
} else {
local_para_ptr->result = KAL_FALSE;
}
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_SET_CONFIG_CNF, /* msg_id */
(local_para_struct*)local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
out:
return ret;
}
_STATIC mcf_ota_result_e mcf_l4_get_config(ilm_struct *ilm)
{
l4c_mcf_get_config_req_struct *req = (l4c_mcf_get_config_req_struct *)ilm->local_para_ptr;
l4c_mcf_get_config_cnf_struct *local_para_ptr = NULL;
mcf_ota_result_e ret;
local_para_ptr = (l4c_mcf_get_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_get_config_cnf_struct), TD_RESET);
if (!local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
switch (req->op)
{
case L4C_MCF_CONFIG_GET_APPLIED_FILE_PATH:
ret = mcf_get_applied_file_path(req, local_para_ptr);
break;
default:
MD_TRC_MCF_TR_L4_GET_CONFIG_UNKNOWN_OP(req->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
local_para_ptr->src_id = req->src_id;
if (ret == MCF_OTA_R_SUCCESS) {
local_para_ptr->result = KAL_TRUE;
} else {
local_para_ptr->result = KAL_FALSE;
}
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_GET_CONFIG_CNF, /* msg_id */
(local_para_struct*)local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
return ret;
}
_STATIC mcf_ota_result_e mcf_l4_dump_data(ilm_struct *ilm)
{
l4c_mcf_dump_data_req_struct *req_ptr = (l4c_mcf_dump_data_req_struct *)ilm->local_para_ptr;
l4c_mcf_dump_data_cnf_struct *cnf_ptr = NULL;
mcf_l4c_report_state_ind_struct *ind_ptr = NULL;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_ota_result_e write_ret = MCF_OTA_R_SUCCESS;
kal_char urc_result[16];
kal_uint32 at_len;
kal_int32 fs_ret = FS_NO_ERROR;
kal_wchar pathname[MCF_FILE_MAX_MD_PATH_LEN];
kal_uint32 ret_sprintf;
switch (req_ptr->op)
{
case L4C_MCF_CONFIG_DUMP_LID_DATA:
cnf_ptr = (l4c_mcf_dump_data_cnf_struct *)construct_local_para(sizeof(l4c_mcf_dump_data_cnf_struct), TD_RESET);
if (!cnf_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
cnf_ptr->src_id = req_ptr->src_id;
cnf_ptr->op = req_ptr->op;
cnf_ptr->result = ret;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_DUMP_DATA_CNF, /* msg_id */
(local_para_struct*)cnf_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
/* Support MCF Tool Open Dump File - delete txt */
kal_wsprintf(pathname, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT);
fs_ret = FS_Delete(pathname);
if(fs_ret != FS_NO_ERROR && fs_ret != FS_FILE_NOT_FOUND){
MD_TRC_MCF_TR_L4_DUMP_DATA_DELETE_FILE_FAIL(fs_ret);
ret = MCF_OTA_R_WRITE_DISK_FAIL;
return ret;
}
/* Support MCF Tool Open Dump File - Write AT cmd result in txt */
kal_mem_set(txt_buff, 0, 64);
ret_sprintf = kal_snprintf(txt_buff, 63, "EMCFC=%d,%d%c", req_ptr->op, ret, '\0');
if (ret_sprintf < 0 || ret_sprintf > 64){
strncpy(txt_buff, "EMCFC unknown error", 63);
}
MD_TRC_MCF_TR_L4_DUMP_DATA_CMD_RESULT(txt_buff);
write_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, strlen(txt_buff));
if (write_ret != MCF_OTA_R_SUCCESS) {
return write_ret;
}
ret = mcf_dump_all_lid_data(req_ptr);
break;
default:
MD_TRC_MCF_TR_L4_DUMP_DATA_UNKNOWN_OP(req_ptr->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
ind_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->type = MCF_L4C_REPORT_MCF_DUMP_RESULT;
ind_ptr->result = ret;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
/* Support MCF Tool Open Dump File - Write Urc result in txt */
kal_mem_set(urc_result,0,16);
ret_sprintf = kal_snprintf(urc_result, 15, "%cEMCFRPT=%d,%d%c", '\n', ind_ptr->type, ret, '\0');
if (ret_sprintf < 0 || ret_sprintf > 16){
strncpy(urc_result, "EMCFRPT error", 15);
}
at_len = strlen(txt_buff);
strncat(txt_buff, urc_result, 15);
MD_TRC_MCF_TR_L4_DUMP_DATA_CMD_RESULT(txt_buff);
write_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, at_len+strlen(urc_result));
if (write_ret != MCF_OTA_R_SUCCESS) {
return write_ret;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_l4_update_ota(ilm_struct *ilm)
{
l4c_mcf_update_ota_file_req_struct *req = (l4c_mcf_update_ota_file_req_struct *)ilm->local_para_ptr;
l4c_mcf_update_ota_file_cnf_struct *local_para_ptr1 = NULL;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_l4c_report_state_ind_struct *ind_ptr = NULL;
mcf_t *pMcf = mcf_get_instance();
module_type src_mod_id = ilm->src_mod_id;
kal_bool reset_MD = KAL_FALSE;
switch (req->op)
{
case L4C_MCF_CONFIG_UPDATE_OPOTA_FILE:
/* If DSBP is busy when receive AT cmd, send AT cmd to ask AP retry */
if (pMcf->dsbp_cnf_cnt != 0 || pMcf->dsbp_ind_cnt != 0){
MD_TRC_MCF_TR_L4_UPDATE_OTA_DSBP_IS_ONGOING(pMcf->dsbp_cnf_cnt);
MD_TRC_MCF_TR_L4_UPDATE_OTA_DSBP_IS_ONGOING(pMcf->dsbp_ind_cnt);
local_para_ptr1 = (l4c_mcf_update_ota_file_cnf_struct *)construct_local_para(sizeof(l4c_mcf_update_ota_file_cnf_struct), TD_RESET);
if (!local_para_ptr1) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
/* Send AT cmd back & send URC to ask AP retry */
local_para_ptr1->src_id = req->src_id;
local_para_ptr1->op = req->op;
local_para_ptr1->mcf_result = MCF_OTA_R_FAIL_MCF_DSBP_ONGOING;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_UPDATE_OTA_FILE_CNF, /* msg_id */
(local_para_struct*)local_para_ptr1, /* local_para_ptr */
NULL); /* peer_buff_ptr */
ind_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
ind_ptr->result = MCF_L4C_REPORT_R_AP_RETRY;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
return ret;
}
MD_TRC_MCF_TR_L4_UPDATE_OPOTA_FILE_UPDATE_OTA();
ret = mcf_update_ota_file(req, local_para_ptr1, src_mod_id, &reset_MD);
if (ret == MCF_OTA_R_ALLOCATE_BUFFER_FAIL){
return ret;
}else if(ret == MCF_OTA_R_READ_OTA_FILE_FAIL || ret == MCF_OTA_R_READ_INI_FILE_FAIL){
local_para_ptr1 = (l4c_mcf_update_ota_file_cnf_struct *)construct_local_para(sizeof(l4c_mcf_update_ota_file_cnf_struct), TD_RESET);
if (!local_para_ptr1) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
local_para_ptr1->src_id = req->src_id;
local_para_ptr1->op = req->op;
local_para_ptr1->mcf_result = ret;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_UPDATE_OTA_FILE_CNF, /* msg_id */
(local_para_struct*)local_para_ptr1, /* local_para_ptr */
NULL); /* peer_buff_ptr */
ind_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
ind_ptr->result = MCF_L4C_REPORT_R_AP_RETRY;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
return ret;
}
if(reset_MD == KAL_TRUE){
//ret = MCF_OTA_R_SUCCESS;
local_para_ptr1 = (l4c_mcf_update_ota_file_cnf_struct *)construct_local_para(sizeof(l4c_mcf_update_ota_file_cnf_struct), TD_RESET);
if (!local_para_ptr1) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
local_para_ptr1->src_id = req->src_id;
local_para_ptr1->op = req->op;
local_para_ptr1->mcf_result = ret;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_UPDATE_OTA_FILE_CNF, /* msg_id */
(local_para_struct*)local_para_ptr1, /* local_para_ptr */
NULL); /* peer_buff_ptr */
ind_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
ind_ptr->result = MCF_L4C_REPORT_R_RESET_MD;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
return ret;
}
if (pMcf->dsbp_cnf_cnt == 0){
local_para_ptr1 = (l4c_mcf_update_ota_file_cnf_struct *)construct_local_para(sizeof(l4c_mcf_update_ota_file_cnf_struct), TD_RESET);
if (!local_para_ptr1) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
local_para_ptr1->src_id = req->src_id;
local_para_ptr1->op = req->op;
local_para_ptr1->mcf_result = ret;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_UPDATE_OTA_FILE_CNF, /* msg_id */
(local_para_struct*)local_para_ptr1, /* local_para_ptr */
NULL); /* peer_buff_ptr */
if (ret == MCF_OTA_R_SUCCESS){
ind_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
ind_ptr->result = MCF_L4C_REPORT_R_SUCCESS;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
}
return ret;
}
break;
default:
MD_TRC_MCF_TR_L4_UPDATE_OPOTA_FILE_UNKNOWN_OP(req->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_l4_config(ilm_struct *ilm)
{
l4c_mcf_config_req_struct *req = (l4c_mcf_config_req_struct *)ilm->local_para_ptr;
l4c_mcf_config_cnf_struct *local_para_ptr = NULL;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
local_para_ptr = (l4c_mcf_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_config_cnf_struct), TD_RESET);
if (!local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
switch (req->op)
{
case L4C_MCF_CONFIG_INI_OPERATION:
ret = mcf_config_ini_info(req, local_para_ptr);
break;
default:
MD_TRC_MCF_TR_L4_CONFIG_UNKNOWN_OP(req->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
break;
}
local_para_ptr->src_id = req->src_id;
local_para_ptr->op = req->op;
local_para_ptr->mcf_result = ret;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_CONFIG_CNF, /* msg_id */
(local_para_struct*)local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
return ret;
}
_STATIC mcf_ota_result_e mcf_l4_query_lid(ilm_struct *ilm)
{
l4c_mcf_config_lid_variable_operation_req_struct *req_ptr = (l4c_mcf_config_lid_variable_operation_req_struct *)ilm->local_para_ptr;
l4c_mcf_config_lid_variable_operation_cnf_struct *cnf_ptr = NULL;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
switch (req_ptr->op)
{
case L4C_MCF_CONFIG_LID_VARIABLE_OPERATION:
cnf_ptr = (l4c_mcf_config_lid_variable_operation_cnf_struct *)construct_local_para(sizeof(l4c_mcf_config_lid_variable_operation_cnf_struct), TD_RESET);
if (!cnf_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ret = mcf_config_LID_variable(req_ptr, cnf_ptr);
cnf_ptr->src_id = req_ptr->src_id;
cnf_ptr->op = req_ptr->op;
cnf_ptr->action = req_ptr->action;
cnf_ptr->mcf_result = ret;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_CONFIG_LID_VARIABLE_OPERATION_CNF, /* msg_id */
(local_para_struct*)cnf_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
break;
default:
MD_TRC_MCF_TR_L4_QUERY_LID_UNKNOWN_OP(req_ptr->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
return ret;
}
_STATIC mcf_ota_result_e mcf_l4_variable_operation(ilm_struct *ilm)
{
l4c_mcf_variable_value_operation_req_struct *req_ptr = (l4c_mcf_variable_value_operation_req_struct *)ilm->local_para_ptr;
l4c_mcf_variable_value_operation_cnf_struct *cnf_ptr = NULL;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
switch (req_ptr->op)
{
case L4C_MCF_CONFIG_VARIABLE_VALUE_OPERATION:
cnf_ptr = (l4c_mcf_variable_value_operation_cnf_struct *)construct_local_para(sizeof(l4c_mcf_variable_value_operation_cnf_struct), TD_RESET);
if (!cnf_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
switch (req_ptr->action)
{
case L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OTA:
case L4C_MCF_CONFIG_LID_VARIABLE_ACT_READ_OPOTA:
ret = mcf_query_variable_value(req_ptr, cnf_ptr);
break;
#ifdef __MCF_COMBINE_FILE_SUPPORT__
case L4C_MCF_CONFIG_LID_VARIABLE_ACT_WRITE_OTA:
case L4C_MCF_CONFIG_LID_VARIABLE_ACT_WRITE_OPOTA:
ret = mcf_set_variable_value(req_ptr, cnf_ptr);
break;
#endif
default:
MD_TRC_MCF_TR_L4_VARIABLE_OPERATION_UNKOWN_ACTION(req_ptr->action);
break;
}
cnf_ptr->src_id = req_ptr->src_id;
cnf_ptr->op = req_ptr->op;
cnf_ptr->format = req_ptr->format;
cnf_ptr->action = req_ptr->action;
cnf_ptr->mcf_result = ret;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_VARIABLE_VALUE_OPERATION_CNF, /* msg_id */
(local_para_struct*)cnf_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
break;
default:
MD_TRC_MCF_TR_L4_VARIABLE_OPERATION_UNKNOWN_OP(req_ptr->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
return ret;
}
#ifdef __MCF_COMBINE_FILE_SUPPORT__
_STATIC mcf_ota_result_e mcf_l4_assign_combined_file_path(ilm_struct *ilm)
{
l4c_mcf_set_config_req_struct *req_ptr = (l4c_mcf_set_config_req_struct *)ilm->local_para_ptr;
l4c_mcf_set_config_cnf_struct *cnf_ptr = NULL;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
switch (req_ptr->op)
{
case L4C_MCF_CONFIG_ASSIGN_COMBINED_PATH:
cnf_ptr = (l4c_mcf_set_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_set_config_cnf_struct), TD_RESET);
if (!cnf_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ret = mcf_assign_combined_file_path(req_ptr);
cnf_ptr->src_id = req_ptr->src_id;
cnf_ptr->op = req_ptr->op;
cnf_ptr->mcf_result = ret;
msg_send6(MOD_MCF, /* src_mod_id */
ilm->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_ASSIGN_COMBINED_FILE_PATH_CNF, /* msg_id */
(local_para_struct*)cnf_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
break;
default:
MD_TRC_MCF_TR_L4_ASSIGN_COMBINED_FILE_PATH_UNKNOWN_OP(req_ptr->op);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
return ret;
}
#endif
_STATIC void mcf_respond_dsbp_result(local_para_struct *local_para_ptr)
{
mcf_t *pMcf = mcf_get_instance();
mcf_l4bsbp_trigger_dsbp_cnf_struct *cnf = (mcf_l4bsbp_trigger_dsbp_cnf_struct *)local_para_ptr;
l4c_mcf_set_config_cnf_struct *cnf_local_para_ptr = NULL;
l4c_mcf_update_ota_file_cnf_struct *cnf_update_ota_local_para_ptr = NULL;
mcf_l4c_report_state_ind_struct *ind_ptr = NULL;
mcf_ota_result_e write_ret = MCF_OTA_R_SUCCESS;
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
kal_uint32 ret_sprintf;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(cnf->ps_id);
mcf_tlvota_file_t *tlvota_file;
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type = L4C_MCF_PATH_TYPE_OTA;
if (cnf->config_op == L4C_MCF_CONFIG_UPDATE_OPOTA_FILE){
pMcf->dsbp_cnf_cnt--;
if (cnf->result != MCF_TRIGGER_DSBP_R_SUCCESS && cnf->result != MCF_TRIGGER_DSBP_R_FAIL_NO_SIM){
pMcf->dsbp_ind_cnt--;
pMcf->dsbp_ind_ret = KAL_FALSE;
pMcf->dsbp_cnf_ret = KAL_FALSE;
}
if (cnf->result == MCF_TRIGGER_DSBP_R_FAIL_NO_SIM){
pMcf->dsbp_ind_cnt--;
MD_TRC_MCF_TR_RESPOND_DSBP_RESULT_IND_NO_SIM(cnf->ps_id);
}
if (cnf->is_dsbp_retry == 0){
pMcf->is_critical = KAL_TRUE;
}
/* When critical OTA is fail to trigger DSBP, Send AT cmd response and send URC to reset MD */
if (pMcf->dsbp_cnf_cnt == 0)
{
if (pMcf->is_critical == KAL_TRUE){
cnf_update_ota_local_para_ptr = (l4c_mcf_update_ota_file_cnf_struct *)construct_local_para(sizeof(l4c_mcf_update_ota_file_cnf_struct), TD_RESET);
if (!cnf_update_ota_local_para_ptr) {
ASSERT(0);
return;
}
cnf_update_ota_local_para_ptr->src_id = cnf->src_id;
cnf_update_ota_local_para_ptr->op = cnf->config_op;
if (pMcf->dsbp_cnf_ret == KAL_TRUE){
cnf_update_ota_local_para_ptr->mcf_result = MCF_OTA_R_SUCCESS;
}else{
cnf_update_ota_local_para_ptr->mcf_result = MCF_OTA_R_DSBP_FAIL;
}
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
cnf->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_UPDATE_OTA_FILE_CNF, /* msg_id */
(local_para_struct*)cnf_update_ota_local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
MD_TRC_MCF_TR_RESPOND_DSBP_RESULT_IND_CNT(pMcf->dsbp_ind_cnt);
if(pMcf->dsbp_ind_cnt == 0 && pMcf->dsbp_cnf_ret == KAL_FALSE){
ind_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
return;
}
ind_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
ind_ptr->result = MCF_L4C_REPORT_R_RESET_MD;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
cnf->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
}
}else{
cnf_update_ota_local_para_ptr = (l4c_mcf_update_ota_file_cnf_struct *)construct_local_para(sizeof(l4c_mcf_update_ota_file_cnf_struct), TD_RESET);
if (!cnf_update_ota_local_para_ptr) {
ASSERT(0);
return;
}
cnf_update_ota_local_para_ptr->src_id = cnf->src_id;
cnf_update_ota_local_para_ptr->op = cnf->config_op;
if (pMcf->dsbp_cnf_ret == KAL_TRUE){
cnf_update_ota_local_para_ptr->mcf_result = MCF_OTA_R_SUCCESS;
}else{
cnf_update_ota_local_para_ptr->mcf_result = MCF_OTA_R_DSBP_FAIL;
}
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
cnf->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_UPDATE_OTA_FILE_CNF, /* msg_id */
(local_para_struct*)cnf_update_ota_local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
if(pMcf->dsbp_ind_cnt == 0 && pMcf->dsbp_ind_ret == KAL_FALSE){
ind_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_ptr) {
ASSERT(0);
return;
}
ind_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
ind_ptr->result = MCF_L4C_REPORT_R_AP_RETRY;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
cnf->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
}
}
}
}else{
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_RESPOND_DSBP_INVALID_SIM_ID(cnf->ps_id, sim_id);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
goto out;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
if (cnf->result != MCF_TRIGGER_DSBP_R_SUCCESS) {
/* Read last updated file */
if (tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_RESPOND_DSBP_INVALID_FILE_PATH(cnf->result, tlvota_file->last_file.path_type);
pMcf->is_dsbp_ongoing[sim_id] = KAL_FALSE;
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
goto out;
}
mcf_ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, fs_root_path, tlvota_file->last_file.name, &apply_path_type, apply_filename, pMcf);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_RESPOND_DSBP_READ_FILE_FAIL(cnf->result, mcf_ret);
}
pMcf->is_dsbp_ongoing[sim_id] = KAL_FALSE;
}
out:
if(pMcf->dsbp_cnf_cnt > 0){
pMcf->dsbp_cnf_cnt--;
}
if (cnf->result != MCF_TRIGGER_DSBP_R_SUCCESS && cnf->result != MCF_TRIGGER_DSBP_R_FAIL_NO_SIM){
if(pMcf->dsbp_ind_cnt > 0){
pMcf->dsbp_ind_cnt--;
}
pMcf->dsbp_ind_ret = KAL_FALSE;
pMcf->dsbp_cnf_ret = KAL_FALSE;
dsbp_ret = cnf->result;
}
if (cnf->result == MCF_TRIGGER_DSBP_R_FAIL_NO_SIM){
if(pMcf->dsbp_ind_cnt > 0){
pMcf->dsbp_ind_cnt--;
}
MD_TRC_MCF_TR_RESPOND_DSBP_RESULT_IND_NO_SIM(cnf->ps_id);
}
if (pMcf->dsbp_cnf_cnt == 0)
{
cnf_local_para_ptr = (l4c_mcf_set_config_cnf_struct *)construct_local_para(sizeof(l4c_mcf_set_config_cnf_struct), TD_RESET);
if (!cnf_local_para_ptr) {
ASSERT(0);
return;
}
if (pMcf->dsbp_cnf_ret != KAL_TRUE){
mcf_ret = MCF_OTA_R_DSBP_FAIL;
}
cnf_local_para_ptr->src_id = cnf->src_id;
cnf_local_para_ptr->op = cnf->config_op;
cnf_local_para_ptr->mcf_result = mcf_ret;
cnf_local_para_ptr->dsbp_result = dsbp_ret;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
cnf->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_L4C_MCF_SET_CONFIG_CNF, /* msg_id */
(local_para_struct*)cnf_local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
/* Support MCF Tool Send AT cmd - clear txt */
kal_mem_set(txt_buff, 0, 64);
write_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, 0);
if (write_ret != MCF_OTA_R_SUCCESS) {
return;
}
/* Support MCF Tool Send AT cmd - Write AT cmd result in txt */
ret_sprintf = kal_sprintf(txt_buff, "EMCFC=%d,%d,%d%c", cnf->config_op, mcf_ret, dsbp_ret, '\0');
if (ret_sprintf < 0 || ret_sprintf > 64){
strncpy(txt_buff, "EMCFC unknown error", 63);
}
MD_TRC_MCF_TR_RESPOND_DSBP_CMD_RESULT(txt_buff);
write_ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, strlen(txt_buff));
if (write_ret != MCF_OTA_R_SUCCESS) {
return;
}
}
}
return;
}
_STATIC kal_bool mcf_report_dsbp_result(local_para_struct *local_para_ptr)
{
mcf_t *pMcf = mcf_get_instance();
mcf_l4bsbp_trigger_dsbp_result_ind_struct *ind = (mcf_l4bsbp_trigger_dsbp_result_ind_struct *)local_para_ptr;
kal_bool ret = KAL_TRUE;
kal_char urc_result[16];
kal_uint32 at_len;
kal_uint32 ret_sprintf;
switch (ind->config_op)
{
case L4C_MCF_CONFIG_SET_FILE_PATH_IN_MCF_DSBP_ACTIVE_MODE:
{
mcf_l4c_report_state_ind_struct *ind_local_para_ptr = NULL;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ind->ps_id);
mcf_tlvota_file_t *tlvota_file;
kal_char fs_root_path[MCF_FILE_MAX_MD_PATH_LEN];
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type = L4C_MCF_PATH_TYPE_OTA;
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_REPORT_STATE_INVALID_SIM_ID(ind->ps_id, sim_id);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
goto out;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
if (ind->result == MCF_TRIGGER_DSBP_R_SUCCESS) {
/* Store last updated file informantion */
kal_mem_cpy(&(tlvota_file->last_file), &(tlvota_file->temp_file), sizeof(mcf_file_info_t));
} else {
/* Read last updated file */
if (tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(fs_root_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else if (tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(fs_root_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
} else {
MD_TRC_MCF_TR_REPORT_STATE_INVALID_FILE_PATH(ind->result, tlvota_file->last_file.path_type);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
goto out;
}
/* Read last updated file */
mcf_ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, fs_root_path, tlvota_file->last_file.name, &apply_path_type, apply_filename, pMcf);
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_REPORT_STATE_READ_FILE_FAIL(ind->result, mcf_ret);
}
}
out:
if (sim_id >= 0 && sim_id < MAX_SIM_NUM){
pMcf->is_dsbp_ongoing[sim_id] = KAL_FALSE;
}
ind_local_para_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_local_para_ptr) {
ASSERT(0);
ret = KAL_FALSE;
return ret;
}
ind_local_para_ptr->type = MCF_L4C_REPORT_DSBP_RESULT_OF_MCF_DSBP_ACTIVE_MODE;
ind_local_para_ptr->result = ind->result;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4C + ind->ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
/* Support MCF Tool Send AT cmd - Write Urc result in txt */
kal_mem_set(urc_result,0,16);
ret_sprintf = kal_snprintf(urc_result, 15, "%cEMCFRPT=%d,%d%c", '\n', MCF_L4C_REPORT_DSBP_RESULT_OF_MCF_DSBP_ACTIVE_MODE, ind->result, '\0');
if (ret_sprintf < 0 || ret_sprintf > 16){
strncpy(urc_result, "EMCFRPT error", 15);
}
at_len = strlen(txt_buff);
strncat(txt_buff, urc_result, 15);
MD_TRC_MCF_TR_REPORT_STATE_CMD_RESULT(txt_buff);
ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, at_len+strlen(urc_result));
if (ret != KAL_TRUE) {
return ret;
}
break;
}
case L4C_MCF_CONFIG_SET_FILE_PATH_AND_AUTO_SELECT_BIN:
{
mcf_l4c_report_state_ind_struct *ind_local_para_ptr = NULL;
if (pMcf->dsbp_ind_cnt > 0){
pMcf->dsbp_ind_cnt --;
}
if (ind->result != MCF_TRIGGER_DSBP_R_SUCCESS){
pMcf->dsbp_ind_ret = KAL_FALSE;
}
if(pMcf->dsbp_ind_cnt == 0){
ind_local_para_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_local_para_ptr) {
ASSERT(0);
ret = KAL_FALSE;
return ret;
}
ind_local_para_ptr->type = MCF_L4C_REPORT_MCF_DUMP_RESULT_OF_AUTO_SELECT_BIN;
ind_local_para_ptr->result = ind->result;
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
MOD_L4C + ind->ps_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
/* Support MCF Tool Send AT cmd - Write Urc result in txt */
kal_mem_set(urc_result,0,16);
ret_sprintf = kal_snprintf(urc_result, 15, "%cEMCFRPT=%d,%d%c", '\n', MCF_L4C_REPORT_MCF_DUMP_RESULT_OF_AUTO_SELECT_BIN, ind->result, '\0');
if (ret_sprintf < 0 || ret_sprintf > 16){
strncpy(urc_result, "EMCFRPT error", 15);
}
at_len = strlen(txt_buff);
strncat(txt_buff, urc_result, 15);
MD_TRC_MCF_TR_REPORT_STATE_CMD_RESULT(txt_buff);
ret = mcf_write_buffer(MCF_FS_CUSTOM_FOLDER_PATH, MCF_FS_DEFAULT_AT_CMD_RESULT, (kal_uint8 *)txt_buff, at_len+strlen(urc_result));
if (ret != KAL_TRUE) {
return ret;
}
}
break;
}
case L4C_MCF_CONFIG_UPDATE_OPOTA_FILE:
{
mcf_l4c_report_state_ind_struct *ind_local_para_ptr = NULL;
mcf_t *pMcf = mcf_get_instance();
pMcf->dsbp_ind_cnt --;
if (ind->result != MCF_TRIGGER_DSBP_R_SUCCESS){
pMcf->dsbp_ind_ret = KAL_FALSE;
}
if(pMcf->dsbp_ind_cnt == 0){
if (pMcf->is_critical == KAL_TRUE){
pMcf->is_critical = KAL_FALSE;
ind_local_para_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_local_para_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
if (pMcf->dsbp_ind_ret == KAL_TRUE){
ind_local_para_ptr->result = MCF_L4C_REPORT_R_SUCCESS;
}else{
ind_local_para_ptr->result = MCF_L4C_REPORT_R_RESET_MD;
}
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ind->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
}else{
ind_local_para_ptr = (mcf_l4c_report_state_ind_struct *)construct_local_para(sizeof(mcf_l4c_report_state_ind_struct), TD_RESET);
if (!ind_local_para_ptr) {
ASSERT(0);
ret = MCF_OTA_R_ALLOCATE_BUFFER_FAIL;
return ret;
}
ind_local_para_ptr->type = MCF_L4C_REPORT_UPDATE_FILE_RESULT;
if (pMcf->dsbp_ind_ret == KAL_TRUE){
ind_local_para_ptr->result = MCF_L4C_REPORT_R_SUCCESS;
}else{
ind_local_para_ptr->result = MCF_L4C_REPORT_R_AP_RETRY;
}
/* Send process result to ATCI */
msg_send6(MOD_MCF, /* src_mod_id */
ind->src_mod_id, /* dest_mod_id */
MCF_SAP, /* sap_id */
MSG_ID_MCF_L4C_REPORT_STATE_IND, /* msg_id */
(local_para_struct*)ind_local_para_ptr, /* local_para_ptr */
NULL); /* peer_buff_ptr */
}
}
break;
}
default:
MD_TRC_MCF_TR_REPORT_STATE_INVALID_OP(ind->config_op);
ret = KAL_FALSE;
break;
}
return ret;
}
_STATIC kal_bool mcf_em_update_req_hdlr(local_para_struct *local_para_ptr)
{
l4cps_em_update_req_struct *req = (l4cps_em_update_req_struct *)local_para_ptr;
kal_bool ret = KAL_TRUE;
/*
* Only process Tool source, ignore AP.
*/
if (req->em_src == EM_FROM_ELT) {
switch (req->info_request[MCF_EM_OTA_FILE_INFO]) {
case EM_ON:
com_Mcf.is_em_on = KAL_TRUE;
break;
case EM_OFF:
com_Mcf.is_em_on = KAL_FALSE;
break;
case EM_NC:
/* No change */
break;
default:
ret = KAL_FALSE;
MD_TRC_MCF_TR_EM_UPDATE_INVALID_INFO(req->info_request[MCF_EM_OTA_FILE_INFO]);
break;
}
} else {
ret = KAL_FALSE;
MD_TRC_MCF_TR_EM_UPDATE_INVALID_SOURCE(req->em_src);
}
return ret;
}
_STATIC void mcf_v1_do_ota_full(mcf_ota_file_t *ota_file)
{
mcf_tool_file_info_t *pFile;
mcf_tool_ota_file_item_t *pItem;
kal_uint16 item_cnt = 0;
nvram_errno_enum nvram_api_ret;
kal_bool is_read_nvram = KAL_FALSE;
nvram_ltable_entry_struct lid_info = {0};
kal_uint8 *lid_buffer = NULL;
nvram_ltable_entry_struct pre_lid_info = {0};
kal_uint16 pre_record_idx = 0xFFFF;
kal_uint8 *pre_lid_buffer = NULL;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_char item_tag[MCF_FILE_MAX_TAG_LEN] = {0};
kal_uint32 item_size;
kal_int16 pos = -1;
kal_uint16 in_pos = 0;
mcf_tag_info_struct unuse = {0};
MCF_DB_STRUCT_VARIABLE const *unuse_db_ptr = NULL;
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
pItem = (mcf_tool_ota_file_item_t *)(ota_file->buff + pFile->total_len);
/* Read changed items from OTA file */
while (item_cnt < pFile->item_num) {
if ( (is_read_nvram == KAL_FALSE) || (pItem->lid != pre_lid_info.LID) || (pItem->record_idx != pre_record_idx) ) {
nvram_api_ret = nvram_external_get_lid_info(pItem->lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_GET_LID_INFO_FAIL, pItem->lid, nvram_api_ret);
mcf_utfwk_printf("Fail to get LID information!! lid(%d), nvram_ret(%d)", pItem->lid, nvram_api_ret);
goto next;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
/* Store last time modified LID */
if ( (pItem->lid != pre_lid_info.LID) && ((lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0)
&& (((lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) || ((lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0)) ) {
if (nv_int_info.last_mod_lid.lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid(pItem->lid, nv_int_info.last_mod_lid.lid, nv_int_info.last_mod_lid.lid_cnt, &in_pos);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_SEARCH_STORE_LID, pItem->lid, pos);
if (pos == -1) {
if(mcf_insert_lid(pItem->lid, nv_int_info.last_mod_lid.lid, nv_int_info.last_mod_lid.lid_cnt, in_pos) != KAL_TRUE){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID_FAIL, pItem->lid);
mcf_utfwk_printf("Save Last modified LID fail!!! LID buffer is full(%d)", pItem->lid);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID, pItem->lid, in_pos);
}
nv_int_info.last_mod_lid.lid_cnt++;
}
}
}
#else
/* Store last time modified LID */
if ( (pItem->lid != pre_lid_info.LID) && ((lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0)
&& (((lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) || ((lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0)) ) {
if (nv_int_info.last_mod_lid.lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid_struct(pItem->lid, nv_int_info.last_mod_lid.lid_conf, nv_int_info.last_mod_lid.lid_cnt, &in_pos);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_SEARCH_STORE_LID, pItem->lid, pos);
if (pos == -1) {
if(mcf_insert_lid_struct(pItem->lid, nv_int_info.last_mod_lid.lid_conf, nv_int_info.last_mod_lid.lid_cnt, in_pos, nv_int_info.not_reset_ota, KAL_FALSE) != KAL_TRUE){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID_FAIL, pItem->lid);
mcf_utfwk_printf("Save Last modified LID fail!!! LID buffer is full(%d)", pItem->lid);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID, pItem->lid, in_pos);
}
nv_int_info.last_mod_lid.lid_cnt++;
}
}
}
#endif
/* Do not update LID if OTA attribute is not set */
if ( (lid_info.attr & NVRAM_ATTR_MCF_OTA) == 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR, lid_info.LID, lid_info.attr);
mcf_utfwk_printf("OTA attribute is not set, do not write to NVRAM. lid(%d), attribute(%x)", lid_info.LID, lid_info.attr);
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE && (pItem->lid != pre_lid_info.LID)) {
if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0 ) {
if ( !nvram_external_write_data(pre_lid_info.LID, pre_record_idx, pre_lid_buffer, pre_lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_FAIL, pre_lid_info.LID, pre_record_idx);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_ITEM_LID_FAIL;
mcf_utfwk_printf("Fail to write item LID(%d), record(%d)\r\n", pre_lid_info.LID, pre_record_idx);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_SUCCESS, pre_lid_info.LID, pre_record_idx);
}
} else if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_QUERY_ATTR_SET, pre_lid_info.LID, pre_lid_info.attr);
} else if ( ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) && ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR2, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR3, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are not set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
}
mcf_utfwk_printf("OTA query attribute is set, do not write to NVRAM. lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
free_ctrl_buffer_set_null(pre_lid_buffer);
}
is_read_nvram = KAL_FALSE;
goto next;
}
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0 ) {
if ( !nvram_external_write_data(pre_lid_info.LID, pre_record_idx, pre_lid_buffer, pre_lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_FAIL, pre_lid_info.LID, pre_record_idx);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_ITEM_LID_FAIL;
mcf_utfwk_printf("Fail to write item LID(%d), record(%d)", pre_lid_info.LID, pre_record_idx);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_SUCCESS, pre_lid_info.LID, pre_record_idx);
}
} else if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_QUERY_ATTR_SET, pre_lid_info.LID, pre_lid_info.attr);
} else if ( ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) && ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR2, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are set! lid(%d), attribute(%x)", pre_lid_info.LID, pre_lid_info.attr);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR3, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are not set! lid(%d), attribute(%x)", pre_lid_info.LID, pre_lid_info.attr);
}
free_ctrl_buffer_set_null(pre_lid_buffer);
is_read_nvram = KAL_FALSE;
}
/* Do not reset LID if same with previos one */
if (pItem->lid != pre_lid_info.LID) {
if ( (lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0 ) {
if ( !nvram_external_reset_data(pItem->lid, 1, lid_info.total_records) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_RESET_LID_FAIL, pItem->lid, lid_info.total_records);
mcf_utfwk_printf("Reset LID(%d) FAIL!!, total_record(%d)", pItem->lid, lid_info.total_records);
}
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_RESET_ATTR_NOT_SET, lid_info.LID, lid_info.attr);
mcf_utfwk_printf("OTA reset attribute is not set!! lid(%d), attribute(%x)", lid_info.LID, lid_info.attr);
}
}
lid_buffer = (kal_uint8 *)get_ctrl_buffer(lid_info.size);
/* Read NVRAM LID */
if ( !nvram_external_read_data(pItem->lid, pItem->record_idx, lid_buffer, lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_ITEM_LID_FAIL, pItem->lid, pItem->record_idx);
mcf_utfwk_printf("Fail to read item LID(%d), record(%d)", pItem->lid, pItem->record_idx);
is_read_nvram = KAL_FALSE;
free_ctrl_buffer_set_null(lid_buffer);
goto next;
} else {
is_read_nvram = KAL_TRUE;
}
}
/* Check if item_tag_len is valid */
if ( (pItem->item_tag_len <= 0) || (pItem->item_tag_len >= MCF_FILE_MAX_TAG_LEN-1) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_TAG_LEN, pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
mcf_utfwk_printf("Invalid item_tag_len(%d)!! max item_tag_len(%d)", pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
goto next;
}
/* Update LID item */
if (pItem->is_bit_op == 0) {
strncpy(item_tag, &(pItem->buff_start), pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ITEM_TAG, item_tag);
if (mcf_find_tag_offset(pItem->lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if (pItem->op.byte.value_len > item_size) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_LARGE_VAL_LEN, pItem->op.byte.value_len, item_size);
mcf_utfwk_printf("Invalid value len(%d)!! larger than current item len(%d)", pItem->op.byte.value_len, item_size);
goto next;
}
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_BYTE_UPDATE, pItem->lid, item_byte_offset, pItem->op.byte.value_len);
mcf_dump_data(KAL_TRUE, &(pItem->buff_start) + pItem->item_tag_len, pItem->op.byte.value_len);
kal_mem_cpy( (lid_buffer + item_byte_offset), &(pItem->buff_start) + pItem->item_tag_len, pItem->op.byte.value_len);
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(pItem->op.bit.len);
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->item_tag_len, pItem->op.bit.value_len);
strncpy(item_tag, &(pItem->buff_start), pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ITEM_TAG, item_tag);
if (mcf_find_tag_offset(pItem->lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if ( (pItem->op.bit.value_len > 4) || (pItem->op.bit.len > item_size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_BIT_LEN, pItem->op.bit.len, item_size, pItem->op.bit.value_len);
mcf_utfwk_printf("Invalid bit_len(%d)!! current item len(%d), bit_value_len(%d)", pItem->op.bit.len, item_size, pItem->op.bit.value_len);
goto next;
}
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_BIT_UPDATE, pItem->lid, item_byte_offset, item_bit_offset, pItem->op.bit.len, bit_value);
if (pItem->op.bit.value_len == 1) {
kal_uint8 *val_tmp = (kal_uint8 *)(lid_buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 2) {
kal_uint16 *val_tmp = (kal_uint16 *)(lid_buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 4) {
kal_uint32 *val_tmp = (kal_uint32 *)(lid_buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
}
}
next:
pre_lid_info = lid_info;
pre_record_idx = pItem->record_idx;
pre_lid_buffer = lid_buffer;
pItem = (mcf_tool_ota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
if (item_cnt > 0) {
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0 ) {
if ( !nvram_external_write_data(pre_lid_info.LID, pre_record_idx, pre_lid_buffer, pre_lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_FAIL, pre_lid_info.LID, pre_record_idx);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_ITEM_LID_FAIL;
mcf_utfwk_printf("Fail to write item LID(%d), record(%d)", pre_lid_info.LID, pre_record_idx);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_SUCCESS, pre_lid_info.LID, pre_record_idx);
}
} else if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_QUERY_ATTR_SET, pre_lid_info.LID, pre_lid_info.attr);
} else if ( ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) && ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR2, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are set! lid(%d), attribute(%x)", pre_lid_info.LID, pre_lid_info.attr);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR3, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are not set! lid(%d), attribute(%x)", pre_lid_info.LID, pre_lid_info.attr);
}
free_ctrl_buffer_set_null(pre_lid_buffer);
}
}
return;
}
_STATIC mcf_ota_result_e mcf_v1_do_ota_by_lid(mcf_ota_file_t *ota_file, nvram_lid_enum lid, kal_uint16 record_idx, kal_uint16 record_amount, nvram_ltable_entry_struct *lid_info)
{
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_tool_file_info_t *pFile;
mcf_tool_ota_file_item_t *pItem;
kal_bool is_read_nvram = KAL_FALSE;
kal_uint16 pre_record_idx = 0xFFFF;
kal_bool is_found_target = KAL_FALSE;
kal_uint8 *pre_lid_buffer = NULL;
kal_uint8 *lid_buffer = NULL;
kal_uint16 item_cnt = 0;
kal_char item_tag[MCF_FILE_MAX_TAG_LEN] = {0};
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
mcf_tag_info_struct unuse = {0};
MCF_DB_STRUCT_VARIABLE const *unuse_db_ptr = NULL;
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
pItem = (mcf_tool_ota_file_item_t *)(ota_file->buff + pFile->total_len);
/* Read changed items from OTA file */
while (item_cnt < pFile->item_num) {
if ( (pItem->lid != lid) || (pItem->record_idx < record_idx) || (pItem->record_idx > (record_idx + record_amount - 1)) ) {
if (is_found_target == KAL_FALSE) {
goto next;
} else {
// Item in file has been sorted. If target has been found, stop searching while next item is not the one we are searching
break;
}
}
if ( (is_read_nvram == KAL_FALSE) || (pItem->record_idx != pre_record_idx) ) {
is_found_target = KAL_TRUE;
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( !nvram_external_write_data(lid, pre_record_idx, pre_lid_buffer, lid_info->size) ) {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_FAIL(lid, pre_record_idx);
} else {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_SUCCESS(lid, pre_record_idx);
}
free_ctrl_buffer_set_null(pre_lid_buffer);
is_read_nvram = KAL_FALSE;
}
lid_buffer = (kal_uint8 *)get_ctrl_buffer(lid_info->size);
/* Read NVRAM LID */
if ( !nvram_external_read_data(pItem->lid, pItem->record_idx, lid_buffer, lid_info->size) ) {
MD_TRC_MCF_TR_LID_OTA_READ_ITEM_NVRAM_FAIL(lid, pItem->record_idx);
is_read_nvram = KAL_FALSE;
free_ctrl_buffer_set_null(lid_buffer);
goto next;
} else {
is_read_nvram = KAL_TRUE;
}
}
/* Check if item_tag_len is valid */
if ( (pItem->item_tag_len <= 0) || (pItem->item_tag_len >= MCF_FILE_MAX_TAG_LEN-1) ) {
MD_TRC_MCF_TR_LID_OTA_INVALID_TAG_LEN(pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
goto next;
}
/* Update LID item */
if (pItem->is_bit_op == 0) {
strncpy(item_tag, &(pItem->buff_start), pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if (pItem->op.byte.value_len > item_size) {
MD_TRC_MCF_TR_LID_OTA_LARGE_VAL_LEN(pItem->op.byte.value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_LID_OTA_BYTE_UPDATE(lid, item_byte_offset, pItem->op.byte.value_len);
mcf_dump_data(KAL_FALSE, &(pItem->buff_start) + pItem->item_tag_len, pItem->op.byte.value_len);
kal_mem_cpy( (lid_buffer + item_byte_offset), &(pItem->buff_start) + pItem->item_tag_len, pItem->op.byte.value_len);
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(pItem->op.bit.len);
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->item_tag_len, pItem->op.bit.value_len);
strncpy(item_tag, &(pItem->buff_start), pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if ( (pItem->op.bit.value_len > 4) || (pItem->op.bit.len > item_size) ) {
MD_TRC_MCF_TR_LID_OTA_INVALID_BIT_LEN(pItem->op.bit.len, item_size, pItem->op.bit.value_len);
goto next;
}
MD_TRC_MCF_TR_LID_OTA_BIT_UPDATE(lid, item_byte_offset, item_bit_offset, pItem->op.bit.len, bit_value);
if (pItem->op.bit.value_len == 1) {
kal_uint8 *val_tmp = (kal_uint8 *)(lid_buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 2) {
kal_uint16 *val_tmp = (kal_uint16 *)(lid_buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 4) {
kal_uint32 *val_tmp = (kal_uint32 *)(lid_buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
}
}
next:
pre_record_idx = pItem->record_idx;
pre_lid_buffer = lid_buffer;
pItem = (mcf_tool_ota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
if (item_cnt > 0) {
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( !nvram_external_write_data(lid, pre_record_idx, pre_lid_buffer, lid_info->size) ) {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_FAIL(lid, pre_record_idx);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
} else {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_SUCCESS(lid, pre_record_idx);
}
free_ctrl_buffer_set_null(pre_lid_buffer);
}
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
_STATIC void mcf_v1_read_ota_buffer(mcf_ota_file_t *ota_file, nvram_lid_enum lid, kal_uint16 record_idx, kal_uint8 *buffer)
{
mcf_tool_file_info_t *pFile;
mcf_tool_ota_file_item_t *pItem;
kal_uint16 item_cnt = 0;
kal_bool is_found_target = KAL_FALSE;
kal_char item_tag[MCF_FILE_MAX_TAG_LEN] = {0};
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
mcf_tag_info_struct unuse = {0};
MCF_DB_STRUCT_VARIABLE const *unuse_db_ptr = NULL;
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
pItem = (mcf_tool_ota_file_item_t *)(ota_file->buff + pFile->total_len);
/* Read changed items from OTA file */
while (item_cnt < pFile->item_num) {
if ( (pItem->lid != lid) || (pItem->record_idx != record_idx) ) {
if (is_found_target == KAL_FALSE) {
goto next;
} else {
// Item in file has been sorted. If target has been found, stop searching while next item is not the one we are searching
break;
}
}
is_found_target = KAL_TRUE;
/* Check if item_tag_len is valid */
if ( (pItem->item_tag_len <= 0) || (pItem->item_tag_len >= MCF_FILE_MAX_TAG_LEN-1) ) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_TAG_LEN(pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
mcf_utfwk_printf("Invalid item_tag_len(%d)!! max item_tag_len(%d) \r\n", pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
goto next;
}
/* Update LID item */
if (pItem->is_bit_op == 0) {
strncpy(item_tag, &(pItem->buff_start), pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if (pItem->op.byte.value_len > item_size) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_LARGE_VAL_LEN(pItem->op.byte.value_len, item_size);
mcf_utfwk_printf("Invalid value len(%d)!! larger than current item len(%d) \r\n", pItem->op.byte.value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_READ_OTA_BUFFER_BYTE_UPDATE(lid, item_byte_offset, pItem->op.byte.value_len);
mcf_dump_data(KAL_FALSE, &(pItem->buff_start) + pItem->item_tag_len, pItem->op.byte.value_len);
kal_mem_cpy( (buffer + item_byte_offset), &(pItem->buff_start) + pItem->item_tag_len, pItem->op.byte.value_len);
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(pItem->op.bit.len);
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->item_tag_len, pItem->op.bit.value_len);
strncpy(item_tag, &(pItem->buff_start), pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if ( (pItem->op.bit.value_len > 4) || (pItem->op.bit.len > item_size) ) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_BIT_LEN(pItem->op.bit.len, item_size, pItem->op.bit.value_len);
mcf_utfwk_printf("Invalid bit_len(%d)!! current item len(%d), bit_value_len(%d) \r\n", pItem->op.bit.len, item_size, pItem->op.bit.value_len);
goto next;
}
MD_TRC_MCF_TR_READ_OTA_BUFFER_BIT_UPDATE(lid, item_byte_offset, item_bit_offset, pItem->op.bit.len, bit_value);
if (pItem->op.bit.value_len == 1) {
kal_uint8 *val_tmp = (kal_uint8 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 2) {
kal_uint16 *val_tmp = (kal_uint16 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 4) {
kal_uint32 *val_tmp = (kal_uint32 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
}
}
next:
pItem = (mcf_tool_ota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
}
_STATIC void mcf_v1_read_tlvota_buffer(mcf_tlvota_file_t *tlvota_file, mcf_tlvota_tag_t tag, nvram_lid_enum lid, kal_uint8 *buffer)
{
mcf_tool_file_info_t *pFile;
mcf_tool_tlvota_file_item_t *pItem;
kal_uint16 item_cnt = 0;
kal_char item_tag[MCF_FILE_MAX_TAG_LEN] = {0};
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
mcf_tag_info_struct unuse = {0};
MCF_DB_STRUCT_VARIABLE const *unuse_db_ptr = NULL;
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
pItem = (mcf_tool_tlvota_file_item_t *)(tlvota_file->buff + pFile->total_len);
/* Read changed items from TLV-OTA file */
while (item_cnt < pFile->item_num) {
/* Check if LID and tag match */
if ( (pItem->lid != lid) || (pItem->tag_type != tag.tag_type) || (strncmp(&(pItem->buff_start), tag.tag, pItem->tag_len) != 0) ) {
goto next;
}
/* Check if item_tag_len is valid */
if ( (pItem->item_tag_len <= 0) || (pItem->item_tag_len >= MCF_FILE_MAX_TAG_LEN-1) ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_TAG_LEN(pItem->item_tag_len, MCF_FILE_MAX_TAG_LEN);
goto next;
}
/* Update LID item */
if (pItem->is_bit_op == 0) {
strncpy(item_tag, &(pItem->buff_start) + pItem->tag_len, pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if (pItem->op.byte.value_len > item_size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_LARGE_VAL_LEN(pItem->op.byte.value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_BYTE_UPDATE_USIR(lid, tag.tag, item_byte_offset, pItem->op.byte.value_len);
mcf_dump_data(KAL_FALSE, &(pItem->buff_start) + pItem->tag_len + pItem->item_tag_len, pItem->op.byte.value_len);
kal_mem_cpy( (buffer + item_byte_offset), &(pItem->buff_start) + pItem->tag_len + pItem->item_tag_len, pItem->op.byte.value_len);
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(pItem->op.bit.len);
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->tag_len + pItem->item_tag_len, pItem->op.bit.value_len);
strncpy(item_tag, &(pItem->buff_start) + pItem->tag_len, pItem->item_tag_len);
item_tag[pItem->item_tag_len] = '\0';
if (mcf_find_tag_offset(lid, item_tag, &item_byte_offset, &item_bit_offset, &item_size, &unuse_db_ptr, &unuse) == KAL_FALSE) {
goto next;
}
if ( (pItem->op.bit.value_len > 4) || (pItem->op.bit.len > item_size) ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_BIT_LEN(pItem->op.bit.len, item_size, pItem->op.bit.value_len);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_BIT_UPDATE_USIR(lid, tag.tag, item_byte_offset, item_bit_offset, pItem->op.bit.len, bit_value);
if (pItem->op.bit.value_len == 1) {
kal_uint8 *val_tmp = (kal_uint8 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 2) {
kal_uint16 *val_tmp = (kal_uint16 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
} else if (pItem->op.bit.value_len == 4) {
kal_uint32 *val_tmp = (kal_uint32 *)(buffer + item_byte_offset);
*val_tmp &= ~(bit_mask << item_bit_offset);
*val_tmp |= (bit_value << item_bit_offset);
}
}
next:
pItem = (mcf_tool_tlvota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
/*------------------------------------------------------------------------------
* Public fucntions.
*----------------------------------------------------------------------------*/
void mcf_on_ilm(ilm_struct *ilm)
{
switch (ilm->msg_id)
{
case MSG_ID_L4C_MCF_SET_CONFIG_REQ:
mcf_l4_set_config(ilm);
break;
case MSG_ID_L4C_MCF_GET_CONFIG_REQ:
mcf_l4_get_config(ilm);
break;
case MSG_ID_L4C_MCF_DUMP_DATA_REQ:
mcf_l4_dump_data(ilm);
break;
case MSG_ID_L4C_MCF_CONFIG_LID_VARIABLE_OPERATION_REQ:
mcf_l4_query_lid(ilm);
break;
case MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_CNF:
mcf_respond_dsbp_result(ilm->local_para_ptr);
break;
case MSG_ID_MCF_L4BSBP_TRIGGER_DSBP_RESULT_IND:
mcf_report_dsbp_result(ilm->local_para_ptr);
break;
case MSG_ID_L4CPS_EM_UPDATE_REQ:
mcf_em_update_req_hdlr(ilm->local_para_ptr);
break;
case MSG_ID_TIMER_EXPIRY:
evshed_timer_handler(mcf_timer_es_g);
break;
case MSG_ID_L4C_MCF_UPDATE_OTA_FILE_REQ:
mcf_l4_update_ota(ilm);
break;
case MSG_ID_L4C_MCF_CONFIG_REQ:
mcf_l4_config(ilm);
break;
case MSG_ID_L4C_MCF_VARIABLE_VALUE_OPERATION_REQ:
mcf_l4_variable_operation(ilm);
break;
#ifdef __MCF_COMBINE_FILE_SUPPORT__
case MSG_ID_L4C_MCF_ASSIGN_COMBINED_FILE_PATH_REQ:
mcf_l4_assign_combined_file_path(ilm);
break;
#endif
#if defined(__MCF_UT_FRAMEWORK_SUPPORT__)
case MSG_ID_MCF_UTFWK_INITIAL_ENV_REQ:
mcf_utfwk_ilm_initial_env(ilm);
break;
case MSG_ID_MCF_UTFWK_INITIAL_DSBP_CALLBACK_REQ:
mcf_utfwk_ilm_initial_dsbp_callback(ilm);
break;
case MSG_ID_MCF_UTFWK_EXECUTE_REQ:
mcf_utfwk_ilm_execute(ilm);
break;
case MSG_ID_MCF_UTFWK_DUMP_RESULT_REQ:
mcf_utfwk_ilm_dump_result(ilm);
break;
case MSG_ID_MCF_UTFWK_RESET_REQ:
mcf_utfwk_ilm_reset(ilm);
break;
#endif
default:
MD_TRC_MCF_TR_ILM_UNKNOWN_MSG(ilm->msg_id);
break;
}
}
mcf_ota_result_e mcf_do_ota_full(void)
{
mcf_t *pMcf = mcf_get_instance();
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_tool_file_info_t *pFile;
mcf_tool_gid_ota_file_item_t *pItem;
mcf_ota_file_t *ota_file = &(pMcf->ota_file);
mcf_tlvota_file_t *tlvota_file;
kal_uint16 item_cnt = 0;
nvram_ef_mcf_ota_file_info_struct nv_ota_file;
nvram_ef_mcf_tlvota_file_info_struct nv_tlvota_file;
nvram_ef_mcf_sw_info_struct nv_sw_info;
nvram_ltable_entry_struct lid_info = {0};
em_mcf_read_ota_file_info_struct read_file_info;
kal_uint8 *lid_buffer = NULL;
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
l4c_mcf_path_type_enum apply_path_type;
kal_uint32 i;
nvram_errno_enum nvram_api_ret;
kal_bool is_read_nvram = KAL_FALSE;
kal_uint32 start_time;
kal_int16 pos = -1;
kal_uint16 in_pos = 0;
nvram_ltable_entry_struct pre_lid_info = {0};
kal_uint16 pre_record_idx = 0xFFFF;
kal_uint8 *pre_lid_buffer = NULL;
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_bool item_is_bit = KAL_FALSE;
kal_uint16 item_lid;
kal_char tool_version[MCF_FILE_MAX_TOOL_VERSION_LEN]={0};
kal_uint32 total_start_time = GET_CURRENT_TIME();
mcf_ota_result_e tlvota_ret;
/* This API can only be used by NVRAM while init */
MCF_UT_DUMMY_ASSERT(kal_query_systemInit() == KAL_TRUE);
mcf_create_custom_folder(pMcf);
kal_mem_set(&nv_int_info, 0, sizeof(nvram_ef_mcf_internal_info_struct));
/* Read MCF SW information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_SW_INFO_LID, 1, (kal_uint8 *)&nv_sw_info, sizeof(nvram_ef_mcf_sw_info_struct))) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_LID_FAIL, NVRAM_EF_MCF_SW_INFO_LID, 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_READ_SW_INFO_LID_FAIL;
mcf_utfwk_printf("Fail to read MCF LID(%d)!! record_idx(%d) \r\n", NVRAM_EF_MCF_SW_INFO_LID, 1);
}
/* Read MCF Internal information in NVRAM */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_LID_FAIL, NVRAM_EF_MCF_INTERNAL_INFO_LID, 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_READ_INT_INFO_LID_FAIL;
mcf_utfwk_printf("Fail to read MCF LID(%d)!! record_idx(%d) \r\n", NVRAM_EF_MCF_INTERNAL_INFO_LID, 1);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_NOT_RESET, nv_int_info.not_reset_ota);
kal_mem_cpy(&mcf_general_tlvota_last_mod_lid_g, &nv_int_info.general_tlvota_last_mod_lid, sizeof(nvram_mcf_lid_info_struct)*MAX_SIM_NUM);
kal_mem_cpy(&mcf_tlvota_last_mod_lid_g, &nv_int_info.tlvota_last_mod_lid, sizeof(nvram_mcf_lid_info_struct)*MAX_SIM_NUM);
for (i = 0; i < MAX_SIM_NUM; i++) {
pMcf->is_ignore_dsbp[i] = nv_int_info.tlvota_is_ignore_dsbp[i];
}
pMcf->general_is_ignore_dsbp = nv_int_info.general_is_ignore_dsbp;
/* Read general TLV-OTA file into cache buffer */
apply_path_type = L4C_MCF_PATH_TYPE_OTA;
kal_mem_set(apply_filename, 0, MCF_FILE_MAX_NAME_LEN);
/* Read MCF general TLV-OTA file into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_LID_FAIL, NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_READ_FILE_LID_FAIL;
mcf_utfwk_printf("Fail to read MCF LID(%d)!! record_idx(%d) \r\n", NVRAM_EF_MCF_GENERAL_TLVOTA_FILE_LID, 1);
}
ret = mcf_read_general_tlvota_file(KAL_TRUE, nv_tlvota_file.path, nv_tlvota_file.name, &apply_path_type, apply_filename, pMcf);
// Set General OPOTA - Get tlvota result
if (pMcf->general_is_ignore_dsbp == KAL_TRUE){
for(i = 0; i < MAX_SIM_NUM; i++){
com_Mcf.tlvota_result[i] = ret;
}
/* Check if file type is TLV-OTA file */
tlvota_file = &(pMcf->general_tlvota_file);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_FILE, str_tmp);
for(i = 0; i < MAX_SIM_NUM; i++){
com_Mcf.tlvota_result[i] = MCF_OTA_R_INVALID_FILE;
}
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_TLVOTA_FILE_TAKE_READ_LOCK_FAIL);
}
}
if (ret == MCF_OTA_R_SUCCESS) {
tlvota_file = &(pMcf->general_tlvota_file);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Store last updated file informantion */
tlvota_file->last_file.path_type = apply_path_type;
strncpy(tlvota_file->last_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(tlvota_file->last_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
tlvota_file->last_file.sw_version[pFile->sw_version_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(tlvota_file->last_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len);
tlvota_file->last_file.gen_time[pFile->gen_time_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
}
/*
* No need to Update TLV-OTA information if
* 1. SW version and generated time in OTA file and NVRAM are same
* 2. Current SW version and build time are the same as last MCF OTA SW
*/
if (apply_path_type == L4C_MCF_PATH_TYPE_OTA) {
if ( (strncmp(tlvota_file->last_file.sw_version, nv_sw_info.last_update_general_tlvota_file.sw_version, pFile->sw_version_len) != 0) ||
(strncmp(tlvota_file->last_file.gen_time, nv_sw_info.last_update_general_tlvota_file.gen_time, pFile->gen_time_len) != 0) ||
(strncmp(nv_sw_info.last_update_general_tlvota_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN) != 0) ||
(strncmp(nv_sw_info.last_update_general_tlvota_file.path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) != 0)) {
/* Write updated MCF TLV-OTA file information to NVRAM */
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(nv_sw_info.last_update_general_tlvota_file.sw_version, tlvota_file->last_file.sw_version, pFile->sw_version_len);
nv_sw_info.last_update_general_tlvota_file.sw_version[pFile->sw_version_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(nv_sw_info.last_update_general_tlvota_file.gen_time, tlvota_file->last_file.gen_time, pFile->gen_time_len);
nv_sw_info.last_update_general_tlvota_file.gen_time[pFile->gen_time_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
}
strncpy(nv_sw_info.last_update_general_tlvota_file.path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_sw_info.last_update_general_tlvota_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
for(i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
}
}
}else if (apply_path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
if ( (strncmp(tlvota_file->last_file.sw_version, nv_sw_info.last_update_general_tlvota_file.sw_version, pFile->sw_version_len) != 0) ||
(strncmp(tlvota_file->last_file.gen_time, nv_sw_info.last_update_general_tlvota_file.gen_time, pFile->gen_time_len) != 0) ||
(strncmp(nv_sw_info.last_update_general_tlvota_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN) != 0) ||
(strncmp(nv_sw_info.last_update_general_tlvota_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) != 0)) {
/* Write updated MCF TLV-OTA file information to NVRAM */
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(nv_sw_info.last_update_general_tlvota_file.sw_version, tlvota_file->last_file.sw_version, pFile->sw_version_len);
nv_sw_info.last_update_general_tlvota_file.sw_version[pFile->sw_version_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(nv_sw_info.last_update_general_tlvota_file.gen_time, tlvota_file->last_file.gen_time, pFile->gen_time_len);
nv_sw_info.last_update_general_tlvota_file.gen_time[pFile->gen_time_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
}
strncpy(nv_sw_info.last_update_general_tlvota_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_sw_info.last_update_general_tlvota_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
for(i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
}
}
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_GENERAL_TLVOTA_FILE_TAKE_READ_LOCK_FAIL);
}
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_GENERAL_TLVOTA_FILE_INFO, apply_path_type, apply_filename);
}
/* Read TLV-OTA file into cache buffer */
for (i = 0; i < MAX_SIM_NUM; i++) {
apply_path_type = L4C_MCF_PATH_TYPE_OTA;
kal_mem_set(apply_filename, 0, MCF_FILE_MAX_NAME_LEN);
kal_mem_set(&read_file_info, 0, sizeof(em_mcf_read_ota_file_info_struct));
com_Mcf.update_tlvota[i] = KAL_FALSE;
com_Mcf.update_general_tlvota[i] = KAL_FALSE;
tlvota_file = &(pMcf->tlvota_file[i]);
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_BOOT_UP;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_CARRIER_BIN;
read_file_info.ps_id = l4c_gemini_get_switched_sim_id(i);
/* Read MCF TLV-OTA file into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_TLVOTA_FILE_LID, i + 1, (kal_uint8 *)&nv_tlvota_file, sizeof(nvram_ef_mcf_tlvota_file_info_struct))) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_LID_FAIL, NVRAM_EF_MCF_TLVOTA_FILE_LID, i + 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_READ_FILE_LID_FAIL;
mcf_utfwk_printf("Fail to read MCF LID(%d)!! record_idx(%d) \r\n", NVRAM_EF_MCF_TLVOTA_FILE_LID, i + 1);
}
read_file_info.start_time = kal_get_systicks();
ret = mcf_read_tlvota_file(KAL_TRUE, i, nv_tlvota_file.path, nv_tlvota_file.name, &apply_path_type, apply_filename, pMcf);
tlvota_ret = ret;
if (ret == MCF_OTA_R_SUCCESS) {
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Store last updated file informantion */
tlvota_file->last_file.path_type = apply_path_type;
strncpy(tlvota_file->last_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(tlvota_file->last_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
tlvota_file->last_file.sw_version[pFile->sw_version_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(tlvota_file->last_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len);
tlvota_file->last_file.gen_time[pFile->gen_time_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
}
/*
* No need to Update TLV-OTA information if
* 1. SW version and generated time in OTA file and NVRAM are same
* 2. Current SW version and build time are the same as last MCF OTA SW
*/
if (apply_path_type == L4C_MCF_PATH_TYPE_OTA) {
if ( (strncmp(tlvota_file->last_file.sw_version, nv_sw_info.last_update_tlvota_file[i].sw_version, pFile->sw_version_len) != 0) ||
(strncmp(tlvota_file->last_file.gen_time, nv_sw_info.last_update_tlvota_file[i].gen_time, pFile->gen_time_len) != 0) ||
(strncmp(nv_sw_info.last_update_tlvota_file[i].name, apply_filename, MCF_FILE_MAX_NAME_LEN) != 0) ||
(strncmp(nv_sw_info.last_update_tlvota_file[i].path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) != 0)){
/* Write updated MCF TLV-OTA file information to NVRAM */
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(nv_sw_info.last_update_tlvota_file[i].sw_version, tlvota_file->last_file.sw_version, pFile->sw_version_len);
nv_sw_info.last_update_tlvota_file[i].sw_version[pFile->sw_version_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(nv_sw_info.last_update_tlvota_file[i].gen_time, tlvota_file->last_file.gen_time, pFile->gen_time_len);
nv_sw_info.last_update_tlvota_file[i].gen_time[pFile->gen_time_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
}
strncpy(nv_sw_info.last_update_tlvota_file[i].path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_sw_info.last_update_tlvota_file[i].name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
is_read_tlvota[i] = KAL_TRUE;
}
}else if(apply_path_type == L4C_MCF_PATH_TYPE_RUNTIME){
if ( (strncmp(tlvota_file->last_file.sw_version, nv_sw_info.last_update_tlvota_file[i].sw_version, pFile->sw_version_len) != 0) ||
(strncmp(tlvota_file->last_file.gen_time, nv_sw_info.last_update_tlvota_file[i].gen_time, pFile->gen_time_len) != 0) ||
(strncmp(nv_sw_info.last_update_tlvota_file[i].name, apply_filename, MCF_FILE_MAX_NAME_LEN) != 0) ||
(strncmp(nv_sw_info.last_update_tlvota_file[i].path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) != 0)){
/* Write updated MCF TLV-OTA file information to NVRAM */
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(nv_sw_info.last_update_tlvota_file[i].sw_version, tlvota_file->last_file.sw_version, pFile->sw_version_len);
nv_sw_info.last_update_tlvota_file[i].sw_version[pFile->sw_version_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(nv_sw_info.last_update_tlvota_file[i].gen_time, tlvota_file->last_file.gen_time, pFile->gen_time_len);
nv_sw_info.last_update_tlvota_file[i].gen_time[pFile->gen_time_len] = '\0';
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
}
strncpy(nv_sw_info.last_update_tlvota_file[i].path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_sw_info.last_update_tlvota_file[i].name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
is_read_tlvota[i] = KAL_TRUE;
}
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_TLVOTA_FILE_TAKE_READ_LOCK_FAIL);
}
read_file_info.path_type = apply_path_type;
strncpy(read_file_info.file_name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_TLVOTA_FILE_INFO, i, apply_path_type, apply_filename);
}else{
/* Copy last updated file informantion */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
if ((strncmp(nv_sw_info.last_update_tlvota_file[i].path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) == 0)) {
tlvota_file->last_file.path_type = L4C_MCF_PATH_TYPE_OTA;
}else if ((strncmp(nv_sw_info.last_update_tlvota_file[i].path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) == 0)) {
tlvota_file->last_file.path_type = L4C_MCF_PATH_TYPE_RUNTIME;
}
strncpy(tlvota_file->last_file.name, nv_sw_info.last_update_tlvota_file[i].name, MCF_FILE_MAX_NAME_LEN - 1);
strncpy(tlvota_file->last_file.sw_version, nv_sw_info.last_update_tlvota_file[i].sw_version, MCF_FILE_MAX_SW_VERSION_LEN-1);
strncpy(tlvota_file->last_file.gen_time, nv_sw_info.last_update_tlvota_file[i].gen_time, MCF_FILE_MAX_GEN_TIME_LEN - 1);
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_TLVOTA_FILE_TAKE_READ_LOCK_FAIL);
}
}
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
if (pMcf->is_ignore_dsbp[i] == KAL_TRUE){
set_op_read_ret[i] = tlvota_ret;
/* Check if file type is TLV-OTA file */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_FILE, str_tmp);
com_Mcf.tlvota_result[i] = MCF_OTA_R_INVALID_FILE;
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_TLVOTA_FILE_TAKE_READ_LOCK_FAIL);
}
}
}
kal_mem_set(&read_file_info, 0, sizeof(em_mcf_read_ota_file_info_struct));
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_BOOT_UP;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_DEFAULT_BIN;
/* Read MCF OTA file into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct))) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_LID_FAIL, NVRAM_EF_MCF_OTA_FILE_LID, 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_READ_FILE_LID_FAIL;
mcf_utfwk_printf("Fail to read MCF LID(%d)!! record_idx(%d) \r\n", NVRAM_EF_MCF_OTA_FILE_LID, 1);
}
nv_int_info.update_ota_result = KAL_FALSE;
apply_path_type = L4C_MCF_PATH_TYPE_OTA;
kal_mem_set(apply_filename, 0, MCF_FILE_MAX_NAME_LEN);
read_file_info.start_time = kal_get_systicks();
ret = mcf_read_ota_file(KAL_TRUE, nv_ota_file.path, nv_ota_file.name, &apply_path_type, apply_filename, pMcf);
if (ret == MCF_OTA_R_SUCCESS) {
read_file_info.path_type = apply_path_type;
strncpy(read_file_info.file_name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_OTA_FILE_INFO, apply_path_type, apply_filename);
} else {
/* Cannot do OTA if fail to read OTA file */
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_OTA_FILE_FAIL);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_FULL_OTA_FAIL;
mcf_utfwk_printf("Fail to read OTA file, cannot do full OTA!! \r\n");
return ret;
}
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
/* Check if file type is OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_OTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
ret = MCF_OTA_R_INVALID_FILE;
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
mcf_em_send_ota_file_info(&read_file_info);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_FILE, str_tmp);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_INVALID_FILE;
mcf_utfwk_printf("Invalid file type(%s)!! \r\n", str_tmp);
return ret;
}
/*
* No need to do OTA if
* 1. SW version and generated time in OTA file and NVRAM are same
* 2. Current SW version and build time are the same as last MCF OTA SW
*/
if ( (strncmp(nv_sw_info.last_update_file.sw_version, &(pFile->buff_start), pFile->sw_version_len) == 0) &&
(strncmp(nv_sw_info.last_update_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len) == 0) &&
(strncmp(nv_sw_info.version, release_verno(), MCF_SW_VERNO_LEN) == 0) &&
(strncmp(nv_sw_info.build_time, build_date_time(), MCF_SW_BUILD_TIME_LEN) == 0) ) {
if (apply_path_type == L4C_MCF_PATH_TYPE_OTA) {
if ((strncmp(nv_sw_info.last_update_file.path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) == 0) &&
(strncmp(nv_sw_info.last_update_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN) == 0) ) {
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_NO_NEED1);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_NO_NEED2, nv_sw_info.last_update_file.sw_version, nv_sw_info.last_update_file.gen_time);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_NO_NEED3, nv_sw_info.version, nv_sw_info.build_time);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_TOTAL_RESET_TIME, CALCULATE_LETENCY_DURATION(total_start_time, GET_CURRENT_TIME()));
com_Mcf.boot_trace_flag |= (MCF_BOOT_TRACE_F_NO_NEED | MCF_BOOT_TRACE_F_FULL_OTA_SUCCESS);
mcf_utfwk_printf("MD version is not changed, no need to do full OTA!!\r\n");
return ret;
}
} else if (apply_path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
if ((strncmp(nv_sw_info.last_update_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN) == 0) &&
(strncmp(nv_sw_info.last_update_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN) == 0) ) {
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_NO_NEED1);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_NO_NEED2, nv_sw_info.last_update_file.sw_version, nv_sw_info.last_update_file.gen_time);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_NO_NEED3, nv_sw_info.version, nv_sw_info.build_time);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_TOTAL_RESET_TIME, CALCULATE_LETENCY_DURATION(total_start_time, GET_CURRENT_TIME()));
com_Mcf.boot_trace_flag |= (MCF_BOOT_TRACE_F_NO_NEED | MCF_BOOT_TRACE_F_FULL_OTA_SUCCESS);
mcf_utfwk_printf("MD version is not changed, no need to do full OTA!!\r\n");
return ret;
}
}
}
/* Reset LID to default value */
if((pFile->operation_mask & MCF_FILE_OP_NOT_RESET_LID) == 0) {
/* Copy last modified LID list to global variable */
kal_mem_cpy(&mcf_last_mod_lid_g, &nv_int_info.last_mod_lid, sizeof(nvram_mcf_lid_info_struct));
start_time = GET_CURRENT_TIME();
if (nv_int_info.last_mod_lid.lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
for(i = 0; i < nv_int_info.last_mod_lid.lid_cnt; i++){
nvram_api_ret = nvram_external_get_lid_info(MCF_LAST_MODIFIED_LID, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
mcf_utfwk_printf("is_reset_all(%d). Fail to get all LID information!! lid(%d), nvram_ret(%d)\r\n", 0, MCF_LAST_MODIFIED_LID, nvram_api_ret);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_GET_ALL_LID_INFO_FAIL, 0, MCF_LAST_MODIFIED_LID, nvram_api_ret);
continue;
}
if((lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) {
if ( (lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0) {
#ifdef __MCF_COMBINE_FILE_SUPPORT__
if(nv_int_info.not_reset_ota == KAL_FALSE || nv_int_info.last_mod_lid.lid_conf[i].not_reset == KAL_FALSE)
#endif
{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ALL_RESET_LID, 0, MCF_LAST_MODIFIED_LID);
if ( !nvram_external_reset_data(MCF_LAST_MODIFIED_LID, 1, lid_info.total_records) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ALL_RESET_LID_FAIL, 0, MCF_LAST_MODIFIED_LID, lid_info.total_records);
mcf_utfwk_printf("is_reset_all(%d). Reset All LID(%d) FAIL!!, total_record(%d)\r\n", 0, MCF_LAST_MODIFIED_LID, lid_info.total_records);
}
}
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ALL_RESET_ATTR_NOT_SET, 0, lid_info.LID, lid_info.attr);
mcf_utfwk_printf("is_reset_all(%d). OTA all reset LID attribute is not set!! lid(%d), attribute(%x)\r\n", 0, lid_info.LID, lid_info.attr);
}
}
}
}else{
for(i = 0; i < MCF_LID_MAPPING_TBL_SIZE; i++){
nvram_api_ret = nvram_external_get_lid_info(mcf_db_lid_mapping_tbl[i].lid_num, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_GET_ALL_LID_INFO_FAIL, 1, mcf_db_lid_mapping_tbl[i].lid_num, nvram_api_ret);
mcf_utfwk_printf("is_reset_all(%d). Fail to get all LID information!! lid(%d), nvram_ret(%d)\r\n", 1, mcf_db_lid_mapping_tbl[i].lid_num, nvram_api_ret);
continue;
}
if((lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) {
if ( (lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ALL_RESET_LID, 1, mcf_db_lid_mapping_tbl[i].lid_num);
if ( !nvram_external_reset_data(mcf_db_lid_mapping_tbl[i].lid_num, 1, lid_info.total_records) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ALL_RESET_LID_FAIL, 1, mcf_db_lid_mapping_tbl[i].lid_num, lid_info.total_records);
mcf_utfwk_printf("is_reset_all(%d). Reset All LID(%d) FAIL!!, total_record(%d)\r\n", 1, mcf_db_lid_mapping_tbl[i].lid_num, lid_info.total_records);
}
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_ALL_RESET_ATTR_NOT_SET, 1, lid_info.LID, lid_info.attr);
mcf_utfwk_printf("is_reset_all(%d). OTA all reset LID attribute is not set!! lid(%d), attribute(%x)\r\n", 1, lid_info.LID, lid_info.attr);
}
}
}
}
kal_mem_set(&nv_int_info.last_mod_lid, 0, sizeof(nvram_mcf_lid_info_struct));
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_RESET_TIME, CALCULATE_LETENCY_DURATION(start_time, GET_CURRENT_TIME()));
}
/* Update MCF OTA file flow - MCF2.0 */
if (pFile->file_version == 3) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
pItem = (mcf_tool_gid_ota_file_item_t *)(ota_file->buff + pFile->total_len);
/* Read changed items from OTA file */
while (item_cnt < pFile->item_num) {
/* Check if array_tag_len is valid */
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ARRAY_INDEX_LEN, pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
mcf_utfwk_printf("Invalid array_index_len(%d)!! max array_index_len(%d)\r\n", pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start), pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_GID_ARRAY_INDEX, pItem->global_id, array_tag);
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
if ( (is_read_nvram == KAL_FALSE) || (item_lid != pre_lid_info.LID) || (pItem->record_idx != pre_record_idx) ) {
nvram_api_ret = nvram_external_get_lid_info(item_lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_GET_LID_INFO_FAIL, item_lid, nvram_api_ret);
mcf_utfwk_printf("Fail to get LID information!! lid(%d), nvram_ret(%d)\r\n", item_lid, nvram_api_ret);
goto next;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
/* Store last time modified LID */
if ( (item_lid != pre_lid_info.LID) && ((lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0)
&& (((lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) || ((lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0)) ) {
if (nv_int_info.last_mod_lid.lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid(item_lid, nv_int_info.last_mod_lid.lid, nv_int_info.last_mod_lid.lid_cnt, &in_pos);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_SEARCH_STORE_LID, item_lid, pos);
if (pos == -1) {
if(mcf_insert_lid(item_lid, nv_int_info.last_mod_lid.lid, nv_int_info.last_mod_lid.lid_cnt, in_pos) != KAL_TRUE){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID_FAIL, item_lid);
mcf_utfwk_printf("Save Last modified LID fail!!! LID buffer is full(%d)\r\n", item_lid);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID, item_lid, in_pos);
}
nv_int_info.last_mod_lid.lid_cnt++;
}
}
}
#else
/* Store last time modified LID */
if ( (item_lid != pre_lid_info.LID) && ((lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0)
&& (((lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) || ((lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0)) ) {
if (nv_int_info.last_mod_lid.lid_cnt < NVRAM_MCF_SAVE_LAST_LID_CNT){
pos = mcf_binary_search_lid_struct(item_lid, nv_int_info.last_mod_lid.lid_conf, nv_int_info.last_mod_lid.lid_cnt, &in_pos);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_SEARCH_STORE_LID, item_lid, pos);
if (pos == -1) {
if(mcf_insert_lid_struct(item_lid, nv_int_info.last_mod_lid.lid_conf, nv_int_info.last_mod_lid.lid_cnt, in_pos, nv_int_info.not_reset_ota, KAL_FALSE) != KAL_TRUE){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID_FAIL, item_lid);
mcf_utfwk_printf("Save Last modified LID fail!!! LID buffer is full(%d)\r\n", item_lid);
}else{
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_STORE_LID, item_lid, in_pos);
}
nv_int_info.last_mod_lid.lid_cnt++;
}
}
}
#endif
/* Do not update LID if OTA attribute is not set */
if ( (lid_info.attr & NVRAM_ATTR_MCF_OTA) == 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR, lid_info.LID, lid_info.attr);
mcf_utfwk_printf("OTA attribute is not set, do not write to NVRAM. lid(%d), attribute(%x)\r\n", lid_info.LID, lid_info.attr);
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE && (item_lid != pre_lid_info.LID)) {
if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0 ) {
if ( !nvram_external_write_data(pre_lid_info.LID, pre_record_idx, pre_lid_buffer, pre_lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_FAIL, pre_lid_info.LID, pre_record_idx);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_ITEM_LID_FAIL;
mcf_utfwk_printf("Fail to write item LID(%d), record(%d)\r\n", pre_lid_info.LID, pre_record_idx);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_SUCCESS, pre_lid_info.LID, pre_record_idx);
}
} else if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_QUERY_ATTR_SET, pre_lid_info.LID, pre_lid_info.attr);
} else if ( ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) && ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR2, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR3, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are not set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
}
mcf_utfwk_printf("OTA query attribute is set, do not write to NVRAM. lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
free_ctrl_buffer_set_null(pre_lid_buffer);
}
is_read_nvram = KAL_FALSE;
goto next;
}
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0 ) {
if ( !nvram_external_write_data(pre_lid_info.LID, pre_record_idx, pre_lid_buffer, pre_lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_FAIL, pre_lid_info.LID, pre_record_idx);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_ITEM_LID_FAIL;
mcf_utfwk_printf("Fail to write item LID(%d), record(%d)\r\n", pre_lid_info.LID, pre_record_idx);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_SUCCESS, pre_lid_info.LID, pre_record_idx);
}
} else if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_QUERY_ATTR_SET, pre_lid_info.LID, pre_lid_info.attr);
} else if ( ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) && ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR2, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR3, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are not set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
}
mcf_utfwk_printf("OTA query attribute is set, do not write to NVRAM. lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
free_ctrl_buffer_set_null(pre_lid_buffer);
is_read_nvram = KAL_FALSE;
}
/* Do not reset LID if same with previos one */
if (item_lid != pre_lid_info.LID) {
if ( (lid_info.attr & NVRAM_ATTR_OTA_RESET) != 0 ) {
if(nv_int_info.not_reset_ota == KAL_FALSE){
if ( !nvram_external_reset_data(item_lid, 1, lid_info.total_records) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_RESET_LID_FAIL, item_lid, lid_info.total_records);
mcf_utfwk_printf("Reset LID(%d) FAIL!!, total_record(%d)\r\n", item_lid, lid_info.total_records);
}
}
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_RESET_ATTR_NOT_SET, lid_info.LID, lid_info.attr);
mcf_utfwk_printf("OTA reset attribute is not set!! lid(%d), attribute(%x)\r\n", lid_info.LID, lid_info.attr);
}
}
lid_buffer = (kal_uint8 *)get_ctrl_buffer(lid_info.size);
/* Read NVRAM LID */
if ( !nvram_external_read_data(item_lid, pItem->record_idx, lid_buffer, lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_READ_ITEM_LID_FAIL, item_lid, pItem->record_idx);
mcf_utfwk_printf("Fail to read item LID(%d), record(%d)\r\n", item_lid, pItem->record_idx);
is_read_nvram = KAL_FALSE;
free_ctrl_buffer_set_null(lid_buffer);
goto next;
} else {
is_read_nvram = KAL_TRUE;
}
}
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &item_byte_offset, &item_bit_offset, &item_size, &item_is_bit) == KAL_FALSE){
goto next;
}
/* Update LID item */
if (item_is_bit == 0) {
if (pItem->value_len > item_size) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_LARGE_VAL_LEN, pItem->value_len, item_size);
mcf_utfwk_printf("Invalid value len(%d)!! larger than current item len(%d)\r\n", pItem->value_len, item_size);
goto next;
}
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_BYTE_UPDATE, item_lid, item_byte_offset, pItem->value_len);
mcf_dump_data(KAL_TRUE, &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
kal_mem_cpy( (lid_buffer + item_byte_offset), &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
nv_int_info.update_ota_result = KAL_TRUE;
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_uint32 offset = 0;
kal_uint32 var_size = 1;
kal_uint32 val_tmp = 0;
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
if (pItem->value_len > 4) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_BIT_LEN, pItem->value_len, item_size, pItem->value_len);
mcf_utfwk_printf("Invalid bit_len(%d)!! current item len(%d), bit_value_len(%d)\r\n", item_size, item_size, pItem->value_len);
goto next;
}
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_BIT_UPDATE, item_lid, item_byte_offset, item_bit_offset, item_size, bit_value);
if (item_size > 8 && item_size <= 16) {
var_size = 2;
}else if (item_size > 16 && item_size <= 24) {
var_size = 3;
}else if (item_size > 24 && item_size <= 32) {
var_size = 4;
}
if (item_bit_offset > 0 && item_bit_offset < 8){
offset = 0;
}else if(item_bit_offset >= 8 && item_bit_offset < 16){
offset = 1;
}else if(item_bit_offset >= 16 && item_bit_offset < 24){
offset = 2;
}else if(item_bit_offset >= 24 && item_bit_offset < 32){
offset = 3;
}else if (item_bit_offset >= 32){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_BIT_OFFSET, item_bit_offset, item_size, pItem->value_len);
mcf_utfwk_printf("Invalid item_bit_offset(%d)!! current item len(%d), bit_value_len(%d) \r\n", item_bit_offset, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset > 0) {
if ((item_bit_offset) / 8 != (item_size + item_bit_offset) / 8) {
var_size+=((item_size + item_bit_offset) / 8 - item_bit_offset / 8);
}
}
if (var_size > 4) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_BIT_LEN, var_size, item_size, pItem->value_len);
mcf_utfwk_printf("Invalid bit_len(%d)!! current item len(%d), bit_value_len(%d)\r\n", var_size, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset >= 8 && item_bit_offset < 16) {
item_bit_offset -= 8;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
item_bit_offset -= 16;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
item_bit_offset -= 24;
}
kal_mem_cpy(&val_tmp, lid_buffer + item_byte_offset + offset, var_size);
val_tmp &= ~(bit_mask << item_bit_offset);
val_tmp |= (bit_value << item_bit_offset);
kal_mem_cpy(lid_buffer + item_byte_offset + offset, &val_tmp, var_size);
nv_int_info.update_ota_result = KAL_TRUE;
}
next:
pre_lid_info = lid_info;
pre_record_idx = pItem->record_idx;
pre_lid_buffer = lid_buffer;
pItem = (mcf_tool_gid_ota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
if (item_cnt > 0) {
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0 ) {
if ( !nvram_external_write_data(pre_lid_info.LID, pre_record_idx, pre_lid_buffer, pre_lid_info.size) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_FAIL, pre_lid_info.LID, pre_record_idx);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_ITEM_LID_FAIL;
mcf_utfwk_printf("Fail to write item LID(%d), record(%d)\r\n", pre_lid_info.LID, pre_record_idx);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_ITEM_NVRAM_SUCCESS, pre_lid_info.LID, pre_record_idx);
}
} else if ( (pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0 ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_QUERY_ATTR_SET, pre_lid_info.LID, pre_lid_info.attr);
} else if ( ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA) != 0) && ((pre_lid_info.attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR2, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_ATTR3, pre_lid_info.LID, pre_lid_info.attr);
mcf_utfwk_printf("ERROR!! Both OTA normal and query attribute are not set! lid(%d), attribute(%x)\r\n", pre_lid_info.LID, pre_lid_info.attr);
}
free_ctrl_buffer_set_null(pre_lid_buffer);
}
}
if (ret != MCF_OTA_R_SUCCESS){
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
}else if (pFile->file_version == 2){
mcf_v1_do_ota_full(ota_file);
}
/* Write updated MCF OTA file information to NVRAM */
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(nv_sw_info.last_update_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
nv_sw_info.last_update_file.sw_version[pFile->sw_version_len] = '\0';
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_FILE_SW_VERSION, nv_sw_info.last_update_file.sw_version);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_VERSION, pFile->sw_version_len);
mcf_utfwk_printf("Invalid OTA file SW version!! file_version_len(%d)!!\r\n", pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(nv_sw_info.last_update_file.gen_time, (&(pFile->buff_start) + pFile->sw_version_len), pFile->gen_time_len);
nv_sw_info.last_update_file.gen_time[pFile->gen_time_len] = '\0';
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_FILE_GEN_TIME, nv_sw_info.last_update_file.gen_time);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_INVALID_SW_GEN_TIME, pFile->gen_time_len);
mcf_utfwk_printf("Invalid OTA file SW gen time!! file_gen_time_len(%d)!!\r\n", pFile->gen_time_len);
}
if (pFile->tool_version_len < MCF_FILE_MAX_TOOL_VERSION_LEN && pFile->tool_version_len > 0) {
strncpy(tool_version, (&(pFile->buff_start) + pFile->sw_version_len + pFile->gen_time_len), pFile->tool_version_len);
tool_version[pFile->tool_version_len] = '\0';
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_FILE_TOOL_VERSION, tool_version);
} else if (pFile->tool_version_len >= MCF_FILE_MAX_TOOL_VERSION_LEN){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_FILE_INVALID_TOOL_VERSION, pFile->tool_version_len);
mcf_utfwk_printf("Invalid OTA file tool version!! file_tool_version_len(%d)!!\r\n", pFile->tool_version_len);
}
if (apply_path_type == L4C_MCF_PATH_TYPE_OTA) {
strncpy(nv_sw_info.last_update_file.path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_sw_info.last_update_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
} else if (apply_path_type == L4C_MCF_PATH_TYPE_RUNTIME) {
strncpy(nv_sw_info.last_update_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
strncpy(nv_sw_info.last_update_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
}
if ( !nvram_external_write_data(NVRAM_EF_MCF_OTA_FILE_LID, 1, (kal_uint8 *)&nv_ota_file, sizeof(nvram_ef_mcf_ota_file_info_struct)) ) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_LID_FAIL, NVRAM_EF_MCF_OTA_FILE_LID, 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_FILE_LID_FAIL;
mcf_utfwk_printf("Fail to write MCF LID(%d)!! record_idx(%d)\r\n", NVRAM_EF_MCF_OTA_FILE_LID, 1);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
return ret;
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
} else {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_TAKE_READ_LOCK_FAIL);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_TAKE_READ_LOCK_FAIL;
mcf_utfwk_printf("Read OTA, Fail to take read lock!!\r\n");
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
return ret;
}
/* Copy current modified LID list to global variable */
kal_mem_cpy(&mcf_curr_mod_lid_g, &nv_int_info.last_mod_lid, sizeof(nvram_mcf_lid_info_struct));
/* Write updated MCF SW information in NVRAM */
strncpy(nv_sw_info.version, release_verno(), MCF_SW_VERNO_LEN - 1);
strncpy(nv_sw_info.build_time, build_date_time(), MCF_SW_BUILD_TIME_LEN - 1);
if ( !nvram_external_write_data(NVRAM_EF_MCF_SW_INFO_LID, 1, (kal_uint8 *)&nv_sw_info, sizeof(nvram_ef_mcf_sw_info_struct))) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_LID_FAIL, NVRAM_EF_MCF_SW_INFO_LID, 1);
mcf_utfwk_printf("Fail to write MCF LID(%d)!! record_idx(%d)\r\n", NVRAM_EF_MCF_SW_INFO_LID, 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_SW_INFO_LID_FAIL;
}
/* Write updated MCF internal information in NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_WRITE_LID_FAIL, NVRAM_EF_MCF_INTERNAL_INFO_LID, 1);
mcf_utfwk_printf("Fail to write MCF LID(%d)!! record_idx(%d)\r\n", NVRAM_EF_MCF_INTERNAL_INFO_LID, 1);
com_Mcf.boot_trace_flag |= MCF_BOOT_TRACE_F_WRITE_INT_INFO_LID_FAIL;
}
read_file_info.result = ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_TOTAL_RESET_TIME, CALCULATE_LETENCY_DURATION(total_start_time, GET_CURRENT_TIME()));
return ret;
}
mcf_ota_result_e mcf_do_ota_by_lid(
nvram_lid_enum lid,
kal_uint16 record_idx,
kal_uint16 record_amount,
nvram_ltable_entry_struct *lid_info)
{
mcf_t *pMcf = mcf_get_instance();
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
mcf_tool_file_info_t *pFile;
mcf_tool_gid_ota_file_item_t *pItem;
mcf_ota_file_t *ota_file = &(pMcf->ota_file);
kal_bool is_read_nvram = KAL_FALSE;
kal_uint16 pre_record_idx = 0xFFFF;
kal_bool is_found_target = KAL_FALSE;
kal_uint8 *pre_lid_buffer = NULL;
kal_uint8 *lid_buffer = NULL;
kal_uint16 item_cnt = 0;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_bool item_is_bit = KAL_FALSE;
kal_uint16 item_lid;
DEBUG_ASSERT(lid_info);
if (!lid_info) {
MD_TRC_MCF_TR_LID_OTA_LID_INVALID_PARA(lid, lid_info);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
MD_TRC_MCF_TR_LID_OTA_START(lid, record_idx, record_amount);
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
/* Check if file type is OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_OTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_LID_OTA_LID_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
/* If NVRAM_ATTR_MCF_OTA is not set, do not OTA */
if ( (lid_info->attr & NVRAM_ATTR_MCF_OTA) == 0 ) {
MD_TRC_MCF_TR_LID_OTA_INVALID_ATTR(lid, lid_info->attr);
ret = MCF_OTA_R_INVALID_ATTR;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
/* Not allow to set both NVRAM_ATTR_MCF_OTA and NVRAM_ATTR_MCF_OTA_FOR_QUERY */
if ( (lid_info->attr & NVRAM_ATTR_MCF_OTA_FOR_QUERY) != 0 ) {
MD_TRC_MCF_TR_LID_OTA_DOUBLE_ATTR(lid, lid_info->attr);
ret = MCF_OTA_R_INVALID_ATTR;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
/* MCF 1.0 update flow */
if (pFile->file_version == 2){
ret = mcf_v1_do_ota_by_lid (ota_file, lid, record_idx, record_amount, lid_info);
if(ret != MCF_OTA_R_SUCCESS)
{
return ret;
}
}else if (pFile->file_version == 3){
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
pItem = (mcf_tool_gid_ota_file_item_t *)(ota_file->buff + pFile->total_len);
/* Read changed items from OTA file */
while (item_cnt < pFile->item_num) {
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MD_TRC_MCF_TR_LID_OTA_INVALID_ARRAY_INDEX_LEN(pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start), pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
if ( (item_lid != lid) || (pItem->record_idx < record_idx) || (pItem->record_idx > (record_idx + record_amount - 1)) ) {
if (is_found_target == KAL_FALSE) {
goto next;
} else {
// Item in file has been sorted. If target has been found, stop searching while next item is not the one we are searching
break;
}
}
if ( (is_read_nvram == KAL_FALSE) || (pItem->record_idx != pre_record_idx) ) {
is_found_target = KAL_TRUE;
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( !nvram_external_write_data(lid, pre_record_idx, pre_lid_buffer, lid_info->size) ) {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_FAIL(lid, pre_record_idx);
} else {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_SUCCESS(lid, pre_record_idx);
}
free_ctrl_buffer_set_null(pre_lid_buffer);
is_read_nvram = KAL_FALSE;
}
lid_buffer = (kal_uint8 *)get_ctrl_buffer(lid_info->size);
/* Read NVRAM LID */
if ( !nvram_external_read_data(item_lid, pItem->record_idx, lid_buffer, lid_info->size) ) {
MD_TRC_MCF_TR_LID_OTA_READ_ITEM_NVRAM_FAIL(lid, pItem->record_idx);
is_read_nvram = KAL_FALSE;
free_ctrl_buffer_set_null(lid_buffer);
goto next;
} else {
is_read_nvram = KAL_TRUE;
}
}
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &item_byte_offset, &item_bit_offset, &item_size, &item_is_bit) == KAL_FALSE){
goto next;
}
/* Update LID item */
if (item_is_bit == 0) {
if (pItem->value_len > item_size) {
MD_TRC_MCF_TR_LID_OTA_LARGE_VAL_LEN(pItem->value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_LID_OTA_BYTE_UPDATE(lid, item_byte_offset, pItem->value_len);
mcf_dump_data(KAL_FALSE, &(pItem->buff_start)+pItem->array_index_len, pItem->value_len);
kal_mem_cpy( (lid_buffer + item_byte_offset), &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_uint32 offset = 0;
kal_uint32 var_size = 1;
kal_uint32 val_tmp = 0;
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
if (pItem->value_len > 4) {
MD_TRC_MCF_TR_LID_OTA_INVALID_BIT_LEN(pItem->value_len, item_size, pItem->value_len);
goto next;
}
MD_TRC_MCF_TR_LID_OTA_BIT_UPDATE(lid, item_byte_offset, item_bit_offset, item_size, bit_value);
if (item_size > 8 && item_size <= 16) {
var_size = 2;
}else if (item_size > 16 && item_size <= 24) {
var_size = 3;
}else if (item_size > 24 && item_size <= 32) {
var_size = 4;
}
if (item_bit_offset > 0 && item_bit_offset < 8) {
offset = 0;
}else if (item_bit_offset >= 8 && item_bit_offset < 16) {
offset = 1;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
offset = 2;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
offset = 3;
}else if (item_bit_offset >= 32){
MD_TRC_MCF_TR_LID_OTA_INVALID_BIT_OFFSET(item_bit_offset, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset > 0) {
if ((item_bit_offset) / 8 != (item_size + item_bit_offset) / 8) {
var_size += ((item_size + item_bit_offset) / 8 - item_bit_offset / 8);
}
}
if (var_size > 4) {
MD_TRC_MCF_TR_LID_OTA_INVALID_BIT_LEN(var_size, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset >= 8 && item_bit_offset < 16) {
item_bit_offset -= 8;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
item_bit_offset -= 16;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
item_bit_offset -= 24;
}
kal_mem_cpy(&val_tmp, lid_buffer + item_byte_offset + offset, var_size);
val_tmp &= ~(bit_mask << item_bit_offset);
val_tmp |= (bit_value << item_bit_offset);
kal_mem_cpy(lid_buffer + item_byte_offset + offset, &val_tmp, var_size);
}
next:
pre_record_idx = pItem->record_idx;
pre_lid_buffer = lid_buffer;
pItem = (mcf_tool_gid_ota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
if (item_cnt > 0) {
/* Write previous LID record */
if (is_read_nvram == KAL_TRUE) {
if ( !nvram_external_write_data(lid, pre_record_idx, pre_lid_buffer, lid_info->size) ) {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_FAIL(lid, pre_record_idx);
ret = MCF_OTA_R_WRITE_NVRAM_FAIL;
} else {
MD_TRC_MCF_TR_LID_OTA_WRITE_ITEM_NVRAM_SUCCESS(lid, pre_record_idx);
}
free_ctrl_buffer_set_null(pre_lid_buffer);
}
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
}
} else {
MD_TRC_MCF_TR_LID_OTA_TAKE_READ_LOCK_FAIL(lid);
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
return ret;
}
mcf_ota_result_e mcf_read_ota_buffer(
nvram_lid_enum lid,
kal_uint16 record_idx,
kal_uint8 *buffer,
kal_uint32 size)
{
mcf_t *pMcf = mcf_get_instance();
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
nvram_ltable_entry_struct lid_info = {0};
mcf_tool_file_info_t *pFile;
mcf_tool_gid_ota_file_item_t *pItem;
mcf_ota_file_t *ota_file = &(pMcf->ota_file);
kal_uint16 item_cnt = 0;
nvram_errno_enum nvram_api_ret;
kal_bool is_found_target = KAL_FALSE;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_bool item_is_bit = KAL_FALSE;
kal_uint16 item_lid;
kal_uint32 start_time = GET_CURRENT_TIME();
if (!(buffer && (size > 0))) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_PARA(lid, buffer, size);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_INVALID_PARA, lid, buffer, size);
mcf_utfwk_printf("Invalid parameters!! LID(%d), buffer(%x), size(%d) \r\n", lid, buffer, size);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
MD_TRC_MCF_TR_READ_OTA_BUFFER_START(lid, record_idx, buffer, size);
MCF_R_LOCK_OBJECT(ota_file, mcf_enhmutex_g);
if (ota_file) {
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
/* Check if file type is OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_OTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_INVALID_FILE, str_tmp);
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
nvram_api_ret = nvram_external_get_lid_info(lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_GET_LID_INFO_FAIL(lid, nvram_api_ret);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_GET_LID_INFO_FAIL, lid, nvram_api_ret);
mcf_utfwk_printf("Fail to get LID information!! LID(%d), nvram_api_ret(%d) \r\n", lid, nvram_api_ret);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
if (size != lid_info.size) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_SIZE(size, lid_info.size);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_INVALID_SIZE, size, lid_info.size);
mcf_utfwk_printf("Invalid buffer_size(%d)!! record_size(%d) \r\n", size, lid_info.size);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
return ret;
}
#if 0 //Bypass attribute check because NVRAM_ATTR_MCF_OTA will also use this API
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
/*MCF 1.0 Read OTA buffer Update flow */
if (pFile->file_version == 2){
mcf_v1_read_ota_buffer(ota_file, lid, record_idx, buffer);
}
else if (pFile->file_version == 3){
pFile = (mcf_tool_file_info_t *)(ota_file->buff);
pItem = (mcf_tool_gid_ota_file_item_t *)(ota_file->buff + pFile->total_len);
/* Read changed items from OTA file */
while (item_cnt < pFile->item_num) {
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_ARRAY_INDEX_LEN(pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_INVALID_ARRAY_INDEX_LEN, pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
mcf_utfwk_printf("Invalid array_index_len(%d)!! max array_index_len(%d) \r\n", pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start), pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
if ( (item_lid != lid) || (pItem->record_idx != record_idx) ) {
if (is_found_target == KAL_FALSE) {
goto next;
} else {
// Item in file has been sorted. If target has been found, stop searching while next item is not the one we are searching
break;
}
}
is_found_target = KAL_TRUE;
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &item_byte_offset, &item_bit_offset, &item_size, &item_is_bit) == KAL_FALSE){
goto next;
}
/* Update LID item */
if (item_is_bit == 0) {
if (pItem->value_len > item_size) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_LARGE_VAL_LEN(pItem->value_len, item_size);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_LARGE_VAL_LEN, pItem->value_len, item_size);
mcf_utfwk_printf("Invalid value len(%d)!! larger than current item len(%d) \r\n", pItem->value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_READ_OTA_BUFFER_BYTE_UPDATE(lid, item_byte_offset, pItem->value_len);
if (kal_query_systemInit() == KAL_TRUE){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_GID_ARRAY_INDEX, pItem->global_id, array_tag);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_BYTE_UPDATE, lid, item_byte_offset, pItem->value_len);
mcf_dump_data(KAL_TRUE, &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
}
mcf_dump_data(KAL_FALSE, &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
kal_mem_cpy( (buffer + item_byte_offset), &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
nv_int_info.update_general_tlvota_result = KAL_TRUE;
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_uint32 offset = 0;
kal_uint32 var_size = 1;
kal_uint32 val_tmp = 0;
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->array_index_len, pItem->value_len);
if (pItem->value_len > 4) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_BIT_LEN(pItem->value_len, item_size, pItem->value_len);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_INVALID_BIT_LEN, item_size, item_size, pItem->value_len);
mcf_utfwk_printf("Invalid bit_len(%d)!! current item len(%d), bit_value_len(%d) \r\n", item_size, item_size, pItem->value_len);
goto next;
}
MD_TRC_MCF_TR_READ_OTA_BUFFER_BIT_UPDATE(lid, item_byte_offset, item_bit_offset, item_size, bit_value);
if (kal_query_systemInit() == KAL_TRUE){
MCF_BOOT_TRACE(MCF_BOOT_TR_DO_OTA_FULL_GID_ARRAY_INDEX, pItem->global_id, array_tag);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_BIT_UPDATE, lid, item_byte_offset, item_bit_offset, item_size, bit_value);
}
if (item_size > 8 && item_size <= 16) {
var_size = 2;
}else if (item_size > 16 && item_size <= 24) {
var_size = 3;
}else if (item_size > 24 && item_size <= 32) {
var_size = 4;
}
if (item_bit_offset > 0 && item_bit_offset < 8) {
offset = 0;
}else if (item_bit_offset >= 8 && item_bit_offset < 16) {
offset = 1;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
offset = 2;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
offset = 3;
}else if (item_bit_offset >= 32){
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_BIT_OFFSET(item_bit_offset, item_size, pItem->value_len);
mcf_utfwk_printf("Invalid item_bit_offset(%d)!! current item len(%d), bit_value_len(%d) \r\n", item_bit_offset, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset > 0) {
if ((item_bit_offset) / 8 != (item_size + item_bit_offset) / 8) {
var_size += ((item_size + item_bit_offset) / 8 - item_bit_offset / 8);
}
}
if (var_size > 4) {
MD_TRC_MCF_TR_READ_OTA_BUFFER_INVALID_BIT_LEN(var_size, item_size, pItem->value_len);
mcf_utfwk_printf("Invalid bit_len(%d)!! current item len(%d), bit_value_len(%d) \r\n", var_size, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset >= 8 && item_bit_offset < 16) {
item_bit_offset -= 8;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
item_bit_offset -= 16;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
item_bit_offset -= 24;
}
kal_mem_cpy(&val_tmp, buffer + item_byte_offset + offset, var_size);
val_tmp &= ~(bit_mask << item_bit_offset);
val_tmp |= (bit_value << item_bit_offset);
kal_mem_cpy(buffer + item_byte_offset + offset, &val_tmp, var_size);
nv_int_info.update_general_tlvota_result = KAL_TRUE;
}
next:
pItem = (mcf_tool_gid_ota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
MCF_R_UNLOCK_OBJECT(ota_file, mcf_enhmutex_g);
}
} else {
MD_TRC_MCF_TR_READ_OTA_BUFFER_TAKE_READ_LOCK_FAIL(lid);
MCF_BOOT_TRACE(MCF_BOOT_TR_READ_OTA_BUFFER_TAKE_READ_LOCK_FAIL, lid);
mcf_utfwk_printf("Fail to take read lock!! LID(%d)!! \r\n", lid);
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
// calculate total duration when boot up
if (kal_query_systemInit() == KAL_TRUE){
com_Mcf.ota_api_duration += CALCULATE_LETENCY_DURATION(start_time, GET_CURRENT_TIME());
}
MD_TRC_MCF_TR_READ_OTA_BUFFER_DURATION(lid, record_idx, CALCULATE_LETENCY_DURATION(start_time, GET_CURRENT_TIME()));
return ret;
}
mcf_ota_result_e mcf_read_tlvota_buffer(
kal_uint8 ps_id,
mcf_tlvota_tag_t tag,
nvram_lid_enum lid,
kal_uint8 *buffer,
kal_uint32 size)
{
mcf_t *pMcf = mcf_get_instance();
mcf_tool_file_info_t *pFile;
mcf_tool_gid_tlvota_file_item_t *pItem;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
mcf_tlvota_file_t *tlvota_file = &(pMcf->general_tlvota_file);
nvram_ltable_entry_struct lid_info = {0};
nvram_errno_enum nvram_api_ret;
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
kal_char array_tag[MCF_FILE_MAX_ARRAY_TAG_LEN]={0};
kal_uint16 item_byte_offset;
kal_uint16 item_bit_offset;
kal_uint32 item_size;
kal_bool item_is_bit = KAL_FALSE;
kal_uint16 item_lid;
kal_uint16 item_cnt = 0;
if (!buffer || (size < 0) || !tag.tag) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_PARA(ps_id, lid, buffer, size, tag.tag);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_START_USIR(ps_id, sim_id, lid, buffer, size, tag.tag);
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_FILE(str_tmp);
ret = MCF_OTA_R_INVALID_FILE;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
nvram_api_ret = nvram_external_get_lid_info(lid, &lid_info);
if (nvram_api_ret != NVRAM_ERRNO_SUCCESS) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_GET_LID_INFO_FAIL(lid, nvram_api_ret);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if (size != lid_info.size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_SIZE(size, lid, lid_info.size);
ret = MCF_OTA_R_INVALID_PARAMETER;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
if ( (lid_info.attr & NVRAM_ATTR_MCF_OTA_BY_OP) == 0 ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_ATTR_NOT_SET(lid, lid_info.attr);
ret = MCF_OTA_R_INVALID_ATTR;
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
return ret;
}
/*MCF 1.0 read tlvota buffer update flow */
if (pFile->file_version == 2){
mcf_v1_read_tlvota_buffer(tlvota_file, tag, lid, buffer);
}
else if (pFile->file_version == 3){
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
pItem = (mcf_tool_gid_tlvota_file_item_t *)(tlvota_file->buff + pFile->total_len);
/* Read changed items from TLV-OTA file */
while (item_cnt < pFile->item_num) {
/* Check if array_index_len is valid */
if ( (pItem->array_index_len < 0) || (pItem->array_index_len >= MCF_FILE_MAX_ARRAY_TAG_LEN-1) ) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_ARRAY_INDEX_LEN(pItem->array_index_len, MCF_FILE_MAX_ARRAY_TAG_LEN);
goto next;
}
strncpy(array_tag, &(pItem->buff_start)+pItem->tag_len, pItem->array_index_len);
array_tag[pItem->array_index_len] = '\0';
/* Find GID corresponding LID */
item_lid = mcf_find_gid_return_lid_num(pItem->global_id);
if (item_lid == 65535){
//-1(65535) means not found
goto next;
}
/* Check if LID and tag match */
if ( (item_lid != lid) || (pItem->tag_type != tag.tag_type) || (strncmp(&(pItem->buff_start), tag.tag, pItem->tag_len) != 0) ) {
goto next;
}
if(mcf_find_gid_offset(pItem->global_id, array_tag, &item_lid, &item_byte_offset, &item_bit_offset, &item_size, &item_is_bit) == KAL_FALSE){
goto next;
}
/* Update LID item */
if (item_is_bit == 0) {
if (pItem->value_len > item_size) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_LARGE_VAL_LEN(pItem->value_len, item_size);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_BYTE_UPDATE_USIR(lid, tag.tag, item_byte_offset, pItem->value_len);
mcf_dump_data(KAL_FALSE, &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
kal_mem_cpy( (buffer + item_byte_offset), &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
} else {
kal_uint32 bit_value = 0;
kal_uint32 bit_mask = (kal_uint32)MCF_GEN_BIT_MASK(item_size);
kal_uint32 offset = 0;
kal_uint32 var_size = 1;
kal_uint32 val_tmp = 0;
kal_mem_cpy(&bit_value, &(pItem->buff_start) + pItem->tag_len + pItem->array_index_len, pItem->value_len);
if (pItem->value_len > 4) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_BIT_LEN(pItem->value_len, item_size, pItem->value_len);
goto next;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_BIT_UPDATE_USIR(lid, tag.tag, item_byte_offset, item_bit_offset, item_size, bit_value);
if (item_size > 8 && item_size <= 16) {
var_size = 2;
}else if (item_size > 16 && item_size <= 24) {
var_size = 3;
}else if (item_size > 24 && item_size <= 32) {
var_size = 4;
}
if (item_bit_offset > 0 && item_bit_offset < 8) {
offset = 0;
}else if (item_bit_offset >= 8 && item_bit_offset < 16) {
offset = 1;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
offset = 2;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
offset = 3;
}else if (item_bit_offset >= 32){
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_BIT_OFFSET(item_bit_offset, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset > 0) {
if ((item_bit_offset) / 8 != (item_size + item_bit_offset) / 8) {
var_size += ((item_size + item_bit_offset) / 8 - item_bit_offset / 8);
}
}
if(var_size > 4){
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_INVALID_BIT_LEN(var_size, item_size, pItem->value_len);
goto next;
}
if (item_bit_offset >= 8 && item_bit_offset < 16) {
item_bit_offset -= 8;
}else if (item_bit_offset >= 16 && item_bit_offset < 24) {
item_bit_offset -= 16;
}else if (item_bit_offset >= 24 && item_bit_offset < 32) {
item_bit_offset -= 24;
}
kal_mem_cpy(&val_tmp, buffer + item_byte_offset + offset, var_size);
val_tmp &= ~(bit_mask << item_bit_offset);
val_tmp |= (bit_value << item_bit_offset);
kal_mem_cpy(buffer + item_byte_offset + offset, &val_tmp, var_size);
}
next:
pItem = (mcf_tool_gid_tlvota_file_item_t *)((kal_uint8 *)pItem + pItem->total_len);
item_cnt++;
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
} else {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_TAKE_READ_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
}
return ret;
}
mcf_ota_result_e mcf_read_tlvota_buffer_sbp_tag(
kal_uint8 ps_id,
mcf_tlvota_sbp_tag_t sbp_tag,
nvram_lid_enum lid,
kal_uint8 *buffer,
kal_uint32 size)
{
mcf_ota_result_e tlvota_ret = MCF_OTA_R_MAX;
mcf_ota_result_e ret = MCF_OTA_R_MAX;
mcf_tlvota_tag_t tag_entry[6];
kal_uint32 tag_num = 0;
kal_char tag[6][MCF_MAX_TAG_LEN];
mcf_t *pMcf = mcf_get_instance();
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
mcf_tlvota_file_t *tlvota_file = &(pMcf->tlvota_file[sim_id]);
mcf_tlvota_tag_t iccid_tag;
kal_char iccid[21];
kal_int32 ret_snprintf;
kal_uint32 start_time = GET_CURRENT_TIME();
kal_mem_set(tag, 0, sizeof(kal_char) * 6 * MCF_MAX_TAG_LEN);
if (!(buffer && (size > 0))) {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_INVALID_PARA(ps_id, lid, buffer, size);
ret = MCF_OTA_R_INVALID_PARAMETER;
mcf_utfwk_printf("Invalid parameters!! ps_id(%d), LID(%d), buffer(%x), size(%d) \r\n", ps_id, lid, buffer, size);
return ret;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_START(ps_id, lid, buffer, size, sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
/* Fill tag entry */
if (sbp_tag.sbp_id != SBP_ID_INVALID) {
if (strcmp((kal_char *)sbp_tag.mcc, "") != 0) {
if (strcmp((kal_char *)sbp_tag.mnc, "") != 0) { // sbpid_mcc_mnc case
/* NA_NA_NA, NA_mcc_NA and NA_mcc_mnc case should be updated first */
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* NA_mcc_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* NA_mcc_mnc */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_%s_%s", (kal_char *)sbp_tag.mcc, (kal_char *)sbp_tag.mnc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
tlvota_ret = mcf_read_tlvota_buffer_multi_tag(ps_id, tag_entry, tag_num, lid, buffer, size);
/* Reuse tag_entry */
tag_num = 0;
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* sbpid_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "%d_NA_NA", sbp_tag.sbp_id);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "SBP_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* sbpid_mcc_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "%d_%s_NA", sbp_tag.sbp_id, sbp_tag.mcc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "SBP_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* sbpid_mcc_mnc */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "%d_%s_%s", sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "SBP_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
} else { // sbpid_mcc_NA case
/* NA_NA_NA and NA_mcc_NA case should be updated first */
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* NA_mcc_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
tlvota_ret = mcf_read_tlvota_buffer_multi_tag(ps_id, tag_entry, tag_num, lid, buffer, size);
/* Reuse tag_entry */
tag_num = 0;
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* sbpid_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "%d_NA_NA", sbp_tag.sbp_id);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "SBP_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* sbpid_mcc_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "%d_%s_NA", sbp_tag.sbp_id, sbp_tag.mcc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "SBP_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
}
} else {
if (strcmp((kal_char *)sbp_tag.mnc, "") == 0) { // sbpid_NA_NA case
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
tlvota_ret = mcf_read_tlvota_buffer_multi_tag(ps_id, tag_entry, tag_num, lid, buffer, size);
/* Reuse tag_entry */
tag_num = 0;
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* sbpid_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "%d_NA_NA", sbp_tag.sbp_id);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "SBP_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
} else { // sbpid_NA_mnc case is not allowed!!
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_INVALID_SBP_TAG(sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
ret = MCF_OTA_R_INVALID_SBP_TAG;
return ret;
}
}
} else {
if (strcmp((kal_char *)sbp_tag.mcc, "") != 0) {
if (strcmp((kal_char *)sbp_tag.mnc, "") != 0) { // NA_mcc_mnc case
/* NA_NA_NA, NA_mcc_NA and NA_mcc_mnc case should be updated first */
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* NA_mcc_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* NA_mcc_mnc */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_%s_%s", (kal_char *)sbp_tag.mcc, (kal_char *)sbp_tag.mnc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_mcc_mnc", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
tlvota_ret = mcf_read_tlvota_buffer_multi_tag(ps_id, tag_entry, tag_num, lid, buffer, size);
/* Reuse tag_entry */
tag_num = 0;
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
} else { // NA_mcc_NA case
/* NA_mcc_NA and NA_mcc_mnc case should be updated first */
/* NA_mcc_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
/* NA_mcc_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_%s_NA", (kal_char *)sbp_tag.mcc);
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_mcc_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
tlvota_ret = mcf_read_tlvota_buffer_multi_tag(ps_id, tag_entry, tag_num, lid, buffer, size);
/* Reuse tag_entry */
tag_num = 0;
/* NA_NA_NA */
tag_entry[tag_num].tag_type = MCF_TLVOTA_TAG_SBPID;
ret_snprintf = kal_snprintf(tag[tag_num], MCF_MAX_TAG_LEN, "NA_NA_NA");
if(ret_snprintf < 0 || ret_snprintf > MCF_MAX_TAG_LEN){
strncpy(tag[tag_num], "NA_NA_NA", MCF_MAX_TAG_LEN - 1);
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_SNPRINTF_FAIL(tag[tag_num], sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
}
tag_entry[tag_num].tag_len = strlen(tag[tag_num]);
tag_entry[tag_num].tag = tag[tag_num];
tag_num++;
}
} else { // NA_NA_mnc cases is not allowed!!
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_INVALID_SBP_TAG(sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
mcf_utfwk_printf("Invalid SBP tag!! sbp_id(%d), mcc(%s), mnc(%d) \r\n", sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
ret = MCF_OTA_R_INVALID_SBP_TAG;
return ret;
}
}
ret = mcf_read_tlvota_buffer_sbp_multi_tag(ps_id, tag_entry, tag_num, lid, buffer, size);
/*If general TLV-OTA is iccid tag, need to call read_tlv_ota_buffer to update OTA file with iccid tag*/
if (com_Mcf.is_iccid == KAL_TRUE){
kal_mem_set(&iccid_tag, 0, sizeof(mcf_tlvota_tag_t));
iccid_tag.tag_type = MCF_TLVOTA_TAG_ICCID;
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
kal_mem_cpy(&iccid, tlvota_file->iccid, 21);
iccid_tag.tag = iccid;
iccid_tag.tag_len = strlen((kal_char *)tlvota_file->iccid);
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else {
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_TAKE_READ_LOCK_FAIL();
ret = MCF_OTA_R_TAKE_READ_LOCK_FAIL;
return ret;
}
ret = mcf_read_tlvota_buffer(ps_id, iccid_tag, lid, buffer, size);
}
if ( (tlvota_ret == MCF_OTA_R_SUCCESS) || (ret == MCF_OTA_R_SUCCESS) ) {
ret = MCF_OTA_R_SUCCESS;
}
MD_TRC_MCF_TR_READ_TLVOTA_BUFFER_SBP_DURATION(lid, ps_id, CALCULATE_LETENCY_DURATION(start_time, GET_CURRENT_TIME()));
return ret;
}
mcf_ota_result_e mcf_read_nvram_and_tlvota_buffer_sbp_tag(
kal_uint8 ps_id,
mcf_tlvota_sbp_tag_t sbp_tag,
nvram_lid_enum lid,
kal_uint16 record_idx,
kal_uint8 *buffer,
kal_uint32 size)
{
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
if (!(buffer && (size > 0))) {
MD_TRC_MCF_TR_READ_NVRAM_TLVOTA_BUFFER_SBP_INVALID_PARA(ps_id, lid, buffer, size);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
MD_TRC_MCF_TR_READ_NVRAM_TLVOTA_BUFFER_SBP_START(ps_id, lid, record_idx, buffer, size, sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
if ( !nvram_external_read_data(lid, record_idx, buffer, size)) {
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
ret = mcf_read_tlvota_buffer_sbp_tag(ps_id, sbp_tag, lid, buffer, size);
return ret;
}
kal_bool mcf_custom_dump_mcf_data(mcf_custom_dump_param_struct *param_ptr)
{
kal_bool ret = KAL_TRUE;
sim_interface_enum sim_slot_id = 0;
switch (param_ptr->lid)
{
case NVRAM_EF_MCF_TEST_OTA_LID:
{
mcf_tlvota_sbp_tag_t sbp_tag = {0};
mcf_ota_result_e mcf_ret;
if (param_ptr->type == MCF_TYPE_OTA_BY_OP) {
*(param_ptr->size) = sizeof(nvram_ef_mcf_test_struct);
sbp_tag.sbp_id = param_ptr->sbp_id;
kal_mem_cpy(sbp_tag.mcc, param_ptr->mcc, MAX_MCC_STR_LEN);
kal_mem_cpy(sbp_tag.mnc, param_ptr->mnc, MAX_MNC_STR_LEN);
/* Record_id = sim_id + 1 */
sim_slot_id = l4c_gemini_get_actual_sim_id(param_ptr->ps_id);
if (!nvram_external_read_data(param_ptr->lid, sim_slot_id + 1, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct))) {
MD_TRC_MCF_TR_DUMP_MCF_LID_READ_NVRAM_FAIL(param_ptr->lid, sim_slot_id + 1, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
ret = KAL_FALSE;
return ret;
}
mcf_ret = mcf_read_tlvota_buffer_sbp_tag(param_ptr->ps_id, sbp_tag, param_ptr->lid, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_DUMP_MCF_LID_FAIL(param_ptr->lid, mcf_ret);
}
} else {
MD_TRC_MCF_TR_DUMP_MCF_LID_INVALID_TYPE(param_ptr->lid, param_ptr->type);
ret = KAL_FALSE;
}
break;
}
case NVRAM_EF_MCF_TEST_OTA_QUERY_LID:
{
mcf_tlvota_sbp_tag_t sbp_tag = {0};
mcf_ota_result_e mcf_ret;
switch (param_ptr->type)
{
case MCF_TYPE_OTA:
*(param_ptr->size) = sizeof(nvram_ef_mcf_test_struct);
if (!nvram_external_read_data(param_ptr->lid, param_ptr->record_idx, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct))) {
MD_TRC_MCF_TR_DUMP_MCF_LID_READ_NVRAM_FAIL(param_ptr->lid, param_ptr->record_idx, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
ret = KAL_FALSE;
return ret;
}
mcf_ret = mcf_read_ota_buffer(param_ptr->lid, param_ptr->record_idx, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_DUMP_MCF_LID_QUERY_MCF_FAIL(param_ptr->lid, param_ptr->record_idx, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
}
break;
case MCF_TYPE_OTA_BY_OP:
*(param_ptr->size) = sizeof(nvram_ef_mcf_test_struct);
sbp_tag.sbp_id = param_ptr->sbp_id;
kal_mem_cpy(sbp_tag.mcc, param_ptr->mcc, MAX_MCC_STR_LEN);
kal_mem_cpy(sbp_tag.mnc, param_ptr->mnc, MAX_MNC_STR_LEN);
if (!nvram_external_read_data(param_ptr->lid, param_ptr->ps_id + 1, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct))) {
MD_TRC_MCF_TR_DUMP_MCF_LID_READ_NVRAM_FAIL(param_ptr->lid, param_ptr->ps_id + 1, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
ret = KAL_FALSE;
return ret;
}
/* Record_id = sim_id + 1 */
sim_slot_id = l4c_gemini_get_actual_sim_id(param_ptr->ps_id);
mcf_ret = mcf_read_ota_buffer(param_ptr->lid, sim_slot_id+1, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_DUMP_MCF_LID_QUERY_MCF_FAIL(param_ptr->lid, sim_slot_id+1, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
}
mcf_ret = mcf_read_tlvota_buffer_sbp_tag(param_ptr->ps_id, sbp_tag, param_ptr->lid, param_ptr->buffer, sizeof(nvram_ef_mcf_test_struct));
if (mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_DUMP_MCF_LID_FAIL(param_ptr->lid, mcf_ret);
}
break;
default:
MD_TRC_MCF_TR_DUMP_MCF_LID_INVALID_TYPE(param_ptr->lid, param_ptr->type);
ret = KAL_FALSE;
break;
}
break;
}
default:
MD_TRC_MCF_TR_DUMP_MCF_LID_UNKNOWN_LID(param_ptr->lid);
ret = KAL_FALSE;
break;
}
return ret;
}
kal_bool mcf_auto_select_tlvota_file(sbp_reconfig_custom_param_struct *param_ptr)
{
mcf_t *pMcf = &mcf_inst_g;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(param_ptr->ps_id);
mcf_tlvota_file_t *tlvota_file;
kal_char file_name[MCF_FILE_MAX_NAME_LEN];
kal_char apply_filename[MCF_FILE_MAX_NAME_LEN];
kal_wchar fs_filename[MCF_FILE_MAX_MD_PATH_LEN + MCF_FILE_MAX_NAME_LEN];
kal_char file_path[MCF_FILE_MAX_MD_PATH_LEN];
l4c_mcf_path_type_enum apply_path_type = L4C_MCF_PATH_TYPE_OTA;
em_mcf_read_ota_file_info_struct read_file_info = {0};
FS_FileDetail fs_file_detail[L4C_MCF_PATH_TYPE_MAX] = {0};
mcf_ota_result_e mcf_ret;
mcf_ota_result_e gen_mcf_ret;
kal_bool ret = KAL_TRUE;
kal_bool gen_ret = KAL_TRUE;
kal_int32 fs_api_ret[L4C_MCF_PATH_TYPE_MAX];
kal_uint32 i;
kal_uint32 ret_sprintf;
mcf_tool_file_info_t *pFile;
mcf_tlvota_sbp_tag_t sbp_tag;
kal_bool is_read_nvram = KAL_FALSE;
kal_char tool_version[MCF_FILE_MAX_TOOL_VERSION_LEN]={0};
mcf_ota_result_e tlvota_ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
kal_uint64 last_mod_time = 0;
kal_uint32 start_time = GET_CURRENT_TIME();
MD_TRC_MCF_TR_AUTO_SELECT_BIN_START(param_ptr->ps_id, sim_id, param_ptr->sbp_id, param_ptr->mcc, param_ptr->mnc);
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_INVALID_SIM_ID(param_ptr->ps_id, sim_id);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
ret = KAL_FALSE;
return ret;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
sbp_tag.sbp_id = param_ptr->sbp_id;
kal_mem_cpy(sbp_tag.mcc, param_ptr->mcc, MAX_MCC_STR_LEN);
kal_mem_cpy(sbp_tag.mnc, param_ptr->mnc, MAX_MNC_STR_LEN);
kal_mem_set(&mcf_tlvota_last_mod_lid_g[sim_id], 0, sizeof(nvram_mcf_lid_info_struct));
kal_mem_set(&mcf_tlvota_curr_mod_lid_g[sim_id], 0, sizeof(nvram_mcf_lid_info_struct));
kal_mem_set(&mcf_general_tlvota_last_mod_lid_g[sim_id], 0, sizeof(nvram_mcf_lid_info_struct));
kal_mem_set(&mcf_general_tlvota_curr_mod_lid_g[sim_id], 0, sizeof(nvram_mcf_lid_info_struct));
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
/* Read MCF General TLV-OTA info into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_LID_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = KAL_FALSE;
}
is_read_nvram = KAL_TRUE;
if(is_read_tlvota[sim_id] == KAL_TRUE){
kal_mem_cpy(&mcf_tlvota_last_mod_lid_g[sim_id], &nv_int_info.tlvota_last_mod_lid[sim_id], sizeof(nvram_mcf_lid_info_struct));
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_FALSE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#else
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_FALSE, nv_int_info.not_reset_tlvota[sim_id], KAL_FALSE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#endif
is_update_tlvota[sim_id] = KAL_TRUE;
}
}
if (pMcf->general_is_ignore_dsbp == KAL_TRUE) {
/* Read MCF General TLV-OTA info into cache buffer */
if(is_read_nvram == KAL_FALSE){
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_LID_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = KAL_FALSE;
}
is_read_nvram = KAL_TRUE;
}
if(is_read_general_tlvota[sim_id] == KAL_TRUE){
kal_mem_cpy(&mcf_general_tlvota_last_mod_lid_g[sim_id], &nv_int_info.general_tlvota_last_mod_lid[sim_id], sizeof(nvram_mcf_lid_info_struct));
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_TRUE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#else
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_TRUE, nv_int_info.not_reset_general_tlvota, KAL_FALSE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#endif
is_update_tlvota[sim_id] = KAL_TRUE;
}
}
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
tlvota_file->sbp_id = param_ptr->sbp_id;
tlvota_file->ps_id = param_ptr->ps_id;
kal_mem_cpy(tlvota_file->mcc, param_ptr->mcc, MAX_MCC_STR_LEN);
kal_mem_cpy(tlvota_file->mnc, param_ptr->mnc, MAX_MNC_STR_LEN);
kal_mem_cpy(tlvota_file->iccid, param_ptr->iccid, 21);
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
// Check if need to auto select TLV-OTA file
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_NO_NEED(pMcf->is_ignore_dsbp[sim_id]);
com_Mcf.tlvota_result[sim_id] = set_op_read_ret[sim_id];
goto read_gengeral_opota;
}
}else {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_TLVOTA_FILE_TAKE_WRITE_LOCK_FAIL();
ret = KAL_FALSE;
// Check if need to auto select TLV-OTA file
if (pMcf->is_ignore_dsbp[sim_id] == KAL_TRUE) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_NO_NEED(pMcf->is_ignore_dsbp[sim_id]);
com_Mcf.tlvota_result[sim_id] = set_op_read_ret[sim_id];
goto read_gengeral_opota;
}
goto read_gengeral_opota;
}
ret_sprintf = kal_snprintf(file_name, MCF_FILE_MAX_NAME_LEN - 1, "%s_%d.mcfopota%c", MCF_FS_TLVOTA_FILE_PREFIX, tlvota_file->sbp_id, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_NAME_LEN){
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_TLVOTA_FILE_FILENAME_ERROR(tlvota_file->sbp_id, ret_sprintf);
ret = KAL_FALSE;
return ret;
}
/* Compare modified time of OP-OTA file to select which file to be applied */
kal_wsprintf(fs_filename, "%s\\%s\0", MCF_FS_DEFAULT_FOLDER_PATH, file_name);
fs_api_ret[L4C_MCF_PATH_TYPE_OTA] = FS_GetFileDetail(fs_filename, &fs_file_detail[L4C_MCF_PATH_TYPE_OTA]);
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_FILE_MODIFIED_TIME(tlvota_file->sbp_id, L4C_MCF_PATH_TYPE_OTA, fs_api_ret[L4C_MCF_PATH_TYPE_OTA],
(kal_uint32)((fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime >> 32) & 0xFFFFFFFF), (kal_uint32)(fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime & 0xFFFFFFFF));
if (fs_api_ret[L4C_MCF_PATH_TYPE_OTA] != FS_NO_ERROR) {
kal_mem_set(&fs_file_detail[L4C_MCF_PATH_TYPE_OTA], 0, sizeof(FS_FileDetail));
}
kal_wsprintf(fs_filename, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, file_name);
fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME] = FS_GetFileDetail(fs_filename, &fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME]);
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_FILE_MODIFIED_TIME(tlvota_file->sbp_id, L4C_MCF_PATH_TYPE_RUNTIME, fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME],
(kal_uint32)((fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime >> 32) & 0xFFFFFFFF), (kal_uint32)(fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime & 0xFFFFFFFF));
if (fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME] != FS_NO_ERROR) {
kal_mem_set(&fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME], 0, sizeof(FS_FileDetail));
}
if ( (fs_api_ret[L4C_MCF_PATH_TYPE_OTA] == FS_NO_ERROR) || (fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME] == FS_NO_ERROR) ) {
if (fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime > fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime) {
ret_sprintf = kal_snprintf(file_path, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s%c", MCF_FS_DEFAULT_FOLDER_PATH, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN-1);
file_path[MCF_FILE_MAX_MD_PATH_LEN-1] = '\0';
}
last_mod_time = fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime;
} else {
ret_sprintf = kal_snprintf(file_path, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s%c", MCF_FS_CUSTOM_FOLDER_PATH, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN-1);
file_path[MCF_FILE_MAX_MD_PATH_LEN-1] = '\0';
}
last_mod_time = fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime;
}
} else {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_FILE_COMPARE_FAIL();
ret = KAL_FALSE;
tlvota_ret = MCF_OTA_R_READ_OTA_FILE_FAIL;
goto read_gengeral_opota;
}
read_file_info.trigger_type = EM_MCF_TRIGGER_TYPE_BY_SIM;
read_file_info.config_type = L4C_MCF_CONFIG_TYPE_CARRIER_BIN;
read_file_info.ps_id = tlvota_file->ps_id;
read_file_info.start_time = kal_get_systicks();
// last updated file information
mcf_make_file_info(&old_file_info, tlvota_file->last_file.path_type, tlvota_file->last_file.name, tlvota_file->last_file.sw_version, tlvota_file->last_file.sw_version_len, tlvota_file->last_file.gen_time, tlvota_file->last_file.gen_time_len, tlvota_file->last_file.last_mod_time, tlvota_file->last_file.checksum);
mcf_ret = mcf_read_tlvota_file(KAL_FALSE, sim_id, file_path, file_name, &apply_path_type, apply_filename, pMcf);
tlvota_ret = mcf_ret;
if (mcf_ret == MCF_OTA_R_SUCCESS) {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
// current updated file information
mcf_make_file_info(&new_file_info, apply_path_type, apply_filename, &(pFile->buff_start), pFile->sw_version_len, (&(pFile->buff_start) + pFile->sw_version_len), pFile->gen_time_len, last_mod_time, pFile->checksum);
/* Check TLV-OTA is need update */
if (mcf_compare_file_info(&old_file_info, &new_file_info) == KAL_FALSE){
// Need to update TLV-OTA file
com_Mcf.update_tlvota[sim_id] = KAL_TRUE;
/* Do not reset LIDs if the same file as last one */
is_read_tlvota[sim_id] = KAL_TRUE;
/* Store last updated file informantion */
/* Store TLV-OTA file information */
tlvota_file->last_file.path_type = apply_path_type;
strncpy(tlvota_file->last_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(tlvota_file->last_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
tlvota_file->last_file.sw_version[pFile->sw_version_len] = '\0';
tlvota_file->last_file.sw_version_len = pFile->sw_version_len;
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_SW_VERSION(tlvota_file->last_file.sw_version);
} else {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_SW_VERSION(pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(tlvota_file->last_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len);
tlvota_file->last_file.gen_time[pFile->gen_time_len] = '\0';
tlvota_file->last_file.gen_time_len = pFile->gen_time_len;
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_GEN_TIME(tlvota_file->last_file.gen_time);
} else {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_GEN_TIME(pFile->gen_time_len);
}
if (pFile->tool_version_len < MCF_FILE_MAX_TOOL_VERSION_LEN && pFile->tool_version_len > 0) {
strncpy(tool_version, (&(pFile->buff_start) + pFile->sw_version_len + pFile->gen_time_len), pFile->tool_version_len);
tool_version[pFile->tool_version_len] = '\0';
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_TOOL_VERSION(tool_version);
} else if (pFile->tool_version_len >= MCF_FILE_MAX_TOOL_VERSION_LEN){
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_TOOL_VERSION(pFile->tool_version_len);
}
tlvota_file->last_file.checksum = pFile->checksum;
tlvota_file->last_file.last_mod_time = last_mod_time;
tlvota_file->last_file.sw_version_len = pFile->sw_version_len;
tlvota_file->last_file.gen_time_len = pFile->gen_time_len;
}else{
if (com_Mcf.update_tlvota[sim_id] != KAL_TRUE){
tlvota_ret = mcf_ret;
//TLV-OTA file does not change. No need to trigger dsbp.
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_TLVOTA_FILE_NOT_CHANGE(apply_path_type, com_Mcf.update_tlvota[sim_id]);
}
}
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_FILE(str_tmp);
tlvota_ret = MCF_OTA_R_INVALID_FILE;
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
read_file_info.path_type = apply_path_type;
strncpy(read_file_info.file_name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
} else {
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Store last updated file informantion */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
mcf_make_file_info(&new_file_info, apply_path_type, apply_filename, &(pFile->buff_start), pFile->sw_version_len, (&(pFile->buff_start) + pFile->sw_version_len), pFile->gen_time_len, last_mod_time, pFile->checksum);
/* Check TLV-OTA is need update */
if (mcf_compare_file_info(&old_file_info, &new_file_info) == KAL_FALSE){
com_Mcf.update_tlvota[sim_id] = KAL_TRUE;
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_FILE_FAIL(mcf_ret);
ret = KAL_FALSE;
}
read_file_info.result = mcf_ret;
read_file_info.end_time = kal_get_systicks();
mcf_em_send_ota_file_info(&read_file_info);
com_Mcf.tlvota_result[sim_id] = tlvota_ret;
read_gengeral_opota:
// TODO: general OP-OTA file CHR implementation
// Check if need to auto select TLV-OTA file
if (pMcf->general_is_ignore_dsbp == KAL_TRUE) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_GENERAL_TLVOTA_FILE_NO_NEED(pMcf->general_is_ignore_dsbp);
return ret;
}
tlvota_file = &(pMcf->general_tlvota_file);
ret_sprintf = kal_snprintf(file_name, MCF_FILE_MAX_NAME_LEN - 1, "%s%c", MCF_FS_GENERAL_TLVOTA_FILE_NAME, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_NAME_LEN){
strncpy(file_name, MCF_FS_GENERAL_TLVOTA_FILE_NAME, MCF_FILE_MAX_NAME_LEN-1);
file_name[MCF_FILE_MAX_NAME_LEN-1] = '\0';
}
/* Compare modified time of general OP-OTA file to select which file to be applied */
kal_wsprintf(fs_filename, "%s\\%s\0", MCF_FS_DEFAULT_FOLDER_PATH, file_name);
fs_api_ret[L4C_MCF_PATH_TYPE_OTA] = FS_GetFileDetail(fs_filename, &fs_file_detail[L4C_MCF_PATH_TYPE_OTA]);
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_GENERAL_FILE_MODIFIED_TIME(L4C_MCF_PATH_TYPE_OTA, fs_api_ret[L4C_MCF_PATH_TYPE_OTA],
(kal_uint32)((fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime >> 32) & 0xFFFFFFFF), (kal_uint32)(fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime & 0xFFFFFFFF));
if (fs_api_ret[L4C_MCF_PATH_TYPE_OTA] != FS_NO_ERROR) {
kal_mem_set(&fs_file_detail[L4C_MCF_PATH_TYPE_OTA], 0, sizeof(FS_FileDetail));
}
kal_wsprintf(fs_filename, "%s\\%s\0", MCF_FS_CUSTOM_FOLDER_PATH, file_name);
fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME] = FS_GetFileDetail(fs_filename, &fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME]);
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_GENERAL_FILE_MODIFIED_TIME(L4C_MCF_PATH_TYPE_RUNTIME, fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME],
(kal_uint32)((fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime >> 32) & 0xFFFFFFFF), (kal_uint32)(fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime & 0xFFFFFFFF));
if (fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME] != FS_NO_ERROR) {
kal_mem_set(&fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME], 0, sizeof(FS_FileDetail));
}
if ( (fs_api_ret[L4C_MCF_PATH_TYPE_OTA] == FS_NO_ERROR) || (fs_api_ret[L4C_MCF_PATH_TYPE_RUNTIME] == FS_NO_ERROR) ) {
if (fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime > fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime) {
if (tlvota_file->last_mod_time == fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime) {
// General TLV-OTA file does not change. No need to read again.
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_GENERAL_FILE_NOT_CHANGE(L4C_MCF_PATH_TYPE_OTA);
goto out;
} else {
ret_sprintf = kal_snprintf(file_path, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s%c", MCF_FS_DEFAULT_FOLDER_PATH, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN-1);
file_path[MCF_FILE_MAX_MD_PATH_LEN-1] = '\0';
}
last_mod_time = fs_file_detail[L4C_MCF_PATH_TYPE_OTA].LastStatusChangeTime;
}
} else {
if (tlvota_file->last_mod_time == fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime) {
// General TLV-OTA file does not change. No need to read again.
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_GENERAL_FILE_NOT_CHANGE(L4C_MCF_PATH_TYPE_RUNTIME);
goto out;
} else {
ret_sprintf = kal_snprintf(file_path, MCF_FILE_MAX_MD_PATH_LEN - 1, "%s%c", MCF_FS_CUSTOM_FOLDER_PATH, '\0');
if (ret_sprintf < 0 || ret_sprintf > MCF_FILE_MAX_MD_PATH_LEN){
strncpy(file_path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN-1);
file_path[MCF_FILE_MAX_MD_PATH_LEN-1] = '\0';
}
last_mod_time = fs_file_detail[L4C_MCF_PATH_TYPE_RUNTIME].LastStatusChangeTime;
}
}
} else {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_GENERAL_FILE_COMPARE_FAIL();
gen_ret = KAL_FALSE;
goto out;
}
mcf_make_file_info(&old_file_info, tlvota_file->last_file.path_type, tlvota_file->last_file.name, tlvota_file->last_file.sw_version, tlvota_file->last_file.sw_version_len, tlvota_file->last_file.gen_time, tlvota_file->last_file.gen_time_len, tlvota_file->last_file.last_mod_time, tlvota_file->last_file.checksum);
gen_mcf_ret = mcf_read_general_tlvota_file(KAL_FALSE, file_path, file_name, &apply_path_type, apply_filename, pMcf);
if (gen_mcf_ret != MCF_OTA_R_SUCCESS) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_GENERAL_FILE_FAIL(gen_mcf_ret);
gen_ret = KAL_FALSE;
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Store last updated file informantion */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
mcf_make_file_info(&new_file_info, apply_path_type, apply_filename, &(pFile->buff_start), pFile->sw_version_len, (&(pFile->buff_start) + pFile->sw_version_len), pFile->gen_time_len, last_mod_time, pFile->checksum);
if (mcf_compare_file_info(&old_file_info, &new_file_info) == KAL_FALSE){
//If General TLV-OTA update, every SIM need to update
for (i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
com_Mcf.update_general_tlvota[i] = KAL_TRUE;
}
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
}else{
pFile = (mcf_tool_file_info_t *)(tlvota_file->buff);
/* Store last updated file informantion */
MCF_W_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file){
mcf_make_file_info(&new_file_info, apply_path_type, apply_filename, &(pFile->buff_start), pFile->sw_version_len, (&(pFile->buff_start) + pFile->sw_version_len), pFile->gen_time_len, last_mod_time, pFile->checksum);
/* Check TLV-OTA is need update */
if (mcf_compare_file_info(&old_file_info, &new_file_info) == KAL_FALSE){
//If General TLV-OTA update, every SIM need to update
for (i = 0; i < MAX_SIM_NUM; i++){
is_read_general_tlvota[i] = KAL_TRUE;
com_Mcf.update_general_tlvota[i] = KAL_TRUE;
}
//Store file information
tlvota_file->last_file.path_type = apply_path_type;
strncpy(tlvota_file->last_file.name, apply_filename, MCF_FILE_MAX_NAME_LEN - 1);
if (pFile->sw_version_len < MCF_FILE_MAX_SW_VERSION_LEN) {
strncpy(tlvota_file->last_file.sw_version, &(pFile->buff_start), pFile->sw_version_len);
tlvota_file->last_file.sw_version[pFile->sw_version_len] = '\0';
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_SW_VERSION(tlvota_file->last_file.sw_version);
} else {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_SW_VERSION(pFile->sw_version_len);
}
if (pFile->gen_time_len < MCF_FILE_MAX_GEN_TIME_LEN) {
strncpy(tlvota_file->last_file.gen_time, &(pFile->buff_start) + pFile->sw_version_len, pFile->gen_time_len);
tlvota_file->last_file.gen_time[pFile->gen_time_len] = '\0';
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_GEN_TIME(tlvota_file->last_file.gen_time);
} else {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_GEN_TIME(pFile->gen_time_len);
}
if (pFile->tool_version_len < MCF_FILE_MAX_TOOL_VERSION_LEN && pFile->tool_version_len > 0) {
strncpy(tool_version, (&(pFile->buff_start) + pFile->sw_version_len + pFile->gen_time_len), pFile->tool_version_len);
tool_version[pFile->tool_version_len] = '\0';
MD_TRC_MCF_TR_AUTO_SELECT_BIN_FILE_TOOL_VERSION(tool_version);
} else if (pFile->tool_version_len >= MCF_FILE_MAX_TOOL_VERSION_LEN){
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_TOOL_VERSION(pFile->tool_version_len);
}
tlvota_file->last_file.checksum = pFile->checksum;
tlvota_file->last_file.last_mod_time = last_mod_time;
tlvota_file->last_file.sw_version_len = pFile->sw_version_len;
tlvota_file->last_file.gen_time_len = pFile->gen_time_len;
}else{
//General TLV-OTA file does not change. No need to read again.
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_GENERAL_FILE_NOT_CHANGE(apply_path_type);
}
/* Check if file type is TLV-OTA file */
if (strcmp(pFile->file_type, MCF_FILE_TYPE_TLVOTA) != 0) {
kal_char str_tmp[MCF_MAX_DHL_LOGGING_LEN] = {0};
mcf_snprintf(str_tmp, MCF_MAX_DHL_LOGGING_LEN - 1, "%s", pFile->file_type);
MD_TRC_MCF_TR_AUTO_SELECT_BIN_INVALID_FILE(str_tmp);
gen_mcf_ret = MCF_OTA_R_INVALID_FILE;
}
MCF_W_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}
}
out:
if ( (ret == KAL_TRUE) || (gen_ret == KAL_TRUE) ) {
ret = KAL_TRUE;
} else {
ret = KAL_FALSE;
}
/* If have updated, store modified LIDs */
if (com_Mcf.update_tlvota[sim_id] == KAL_TRUE){
nv_int_info.update_tlvota_result[sim_id] = KAL_FALSE;
if(is_read_nvram == KAL_FALSE){
/* Read MCF TLV-OTA file info into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_LID_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = KAL_FALSE;
}
is_read_nvram = KAL_TRUE;
}
kal_mem_cpy(&mcf_tlvota_last_mod_lid_g[sim_id], &nv_int_info.tlvota_last_mod_lid[sim_id], sizeof(nvram_mcf_lid_info_struct));
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_FALSE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#else
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_FALSE, nv_int_info.not_reset_tlvota[sim_id], KAL_FALSE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#endif
is_update_tlvota[sim_id] = KAL_TRUE;
}
if (is_read_general_tlvota[sim_id] == KAL_TRUE){
nv_int_info.update_general_tlvota_result = KAL_FALSE;
if(is_read_nvram == KAL_FALSE){
/* Read MCF TLV-OTA file info into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_AUTO_SELECT_BIN_READ_LID_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = KAL_FALSE;
}
is_read_nvram = KAL_TRUE;
}
kal_mem_cpy(&mcf_general_tlvota_last_mod_lid_g[sim_id], &nv_int_info.general_tlvota_last_mod_lid[sim_id], sizeof(nvram_mcf_lid_info_struct));
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_TRUE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#else
if(mcf_store_tlvota_modified_lid(sim_id, sbp_tag, KAL_TRUE, nv_int_info.not_reset_general_tlvota, KAL_FALSE) != MCF_OTA_R_SUCCESS){
ret = KAL_FALSE;
}
#endif
is_update_tlvota[sim_id] = KAL_TRUE;
}
MD_TRC_MCF_TR_AUTO_SELECT_BIN_DURATION(CALCULATE_LETENCY_DURATION(start_time, GET_CURRENT_TIME()));
return ret;
}
kal_bool mcf_set_config_after_dsbp(protocol_id_enum ps_id)
{
kal_bool ret = KAL_TRUE;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
nvram_ef_mcf_sw_info_struct nv_sw_info;
mcf_t *pMcf = mcf_get_instance();
mcf_tlvota_file_t *tlvota_file;
kal_uint32 start_time = GET_CURRENT_TIME();
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_INVALID_SIM_ID(ps_id, sim_id);
return KAL_FALSE;
}
tlvota_file = &(pMcf->tlvota_file[sim_id]);
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_START(ps_id, is_update_tlvota[sim_id]);
// When SIM have updated, need to reset to FALSE
if(com_Mcf.update_tlvota[sim_id] == KAL_TRUE){
com_Mcf.update_tlvota[sim_id] = KAL_FALSE;
}
if (com_Mcf.update_general_tlvota[sim_id] == KAL_TRUE){
com_Mcf.update_general_tlvota[sim_id] = KAL_FALSE;
}
if (is_update_tlvota[sim_id] == KAL_TRUE){
kal_mem_set(&nv_int_info, 0, sizeof(nvram_ef_mcf_internal_info_struct));
/* Read MCF internal info into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct))) {
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_READ_LID_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = KAL_FALSE;
return ret;
}
/* Read MCF sw info into cache buffer */
if ( !nvram_external_read_data(NVRAM_EF_MCF_SW_INFO_LID, 1, (kal_uint8 *)&nv_sw_info, sizeof(nvram_ef_mcf_sw_info_struct))) {
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_READ_LID_FAIL(NVRAM_EF_MCF_SW_INFO_LID);
ret = KAL_FALSE;
return ret;
}
if(is_read_tlvota[sim_id] == KAL_TRUE){
kal_mem_cpy(&nv_int_info.tlvota_last_mod_lid[sim_id], &mcf_tlvota_curr_mod_lid_g[sim_id], sizeof(nvram_mcf_lid_info_struct));
is_read_tlvota[sim_id] = KAL_FALSE;
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
/* Write updated MCF TLV-OTA file information to NVRAM */
strncpy(nv_sw_info.last_update_tlvota_file[sim_id].sw_version, tlvota_file->last_file.sw_version, MCF_FILE_MAX_SW_VERSION_LEN - 1);
strncpy(nv_sw_info.last_update_tlvota_file[sim_id].gen_time, tlvota_file->last_file.gen_time, MCF_FILE_MAX_GEN_TIME_LEN - 1);
strncpy(nv_sw_info.last_update_tlvota_file[sim_id].name, tlvota_file->last_file.name, MCF_FILE_MAX_NAME_LEN - 1);
if (tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_OTA){
strncpy(nv_sw_info.last_update_tlvota_file[sim_id].path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
}else if(tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_RUNTIME){
strncpy(nv_sw_info.last_update_tlvota_file[sim_id].path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_TAKE_READ_LOCK_FAIL();
}
}
if (is_read_general_tlvota[sim_id] == KAL_TRUE){
kal_mem_cpy(&nv_int_info.general_tlvota_last_mod_lid[sim_id], &mcf_general_tlvota_curr_mod_lid_g[sim_id], sizeof(nvram_mcf_lid_info_struct));
is_read_general_tlvota[sim_id] = KAL_FALSE;
tlvota_file = &(pMcf->general_tlvota_file);
MCF_R_LOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
if (tlvota_file) {
/* Write updated MCF TLV-OTA file information to NVRAM */
strncpy(nv_sw_info.last_update_general_tlvota_file.sw_version, tlvota_file->last_file.sw_version, MCF_FILE_MAX_SW_VERSION_LEN - 1);
strncpy(nv_sw_info.last_update_general_tlvota_file.gen_time, tlvota_file->last_file.gen_time, MCF_FILE_MAX_GEN_TIME_LEN - 1);
strncpy(nv_sw_info.last_update_general_tlvota_file.name, tlvota_file->last_file.name, MCF_FILE_MAX_NAME_LEN - 1);
if (tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_OTA){
strncpy(nv_sw_info.last_update_general_tlvota_file.path, MCF_FS_DEFAULT_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
}else if(tlvota_file->last_file.path_type == L4C_MCF_PATH_TYPE_RUNTIME){
strncpy(nv_sw_info.last_update_general_tlvota_file.path, MCF_FS_CUSTOM_FOLDER_PATH, MCF_FILE_MAX_MD_PATH_LEN - 1);
}
MCF_R_UNLOCK_OBJECT(tlvota_file, mcf_enhmutex_g);
}else{
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_TAKE_READ_LOCK_FAIL();
}
}
/* Write MCF internal info into NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_INTERNAL_INFO_LID, 1, (kal_uint8 *)&nv_int_info, sizeof(nvram_ef_mcf_internal_info_struct)) ) {
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_WRITE_LID_FAIL(NVRAM_EF_MCF_INTERNAL_INFO_LID);
ret = KAL_FALSE;
return ret;
}
/* Write MCF sw info into NVRAM */
if ( !nvram_external_write_data(NVRAM_EF_MCF_SW_INFO_LID, 1, (kal_uint8 *)&nv_sw_info, sizeof(nvram_ef_mcf_sw_info_struct))) {
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_WRITE_LID_FAIL(NVRAM_EF_MCF_SW_INFO_LID);
ret = KAL_FALSE;
return ret;
}
is_update_tlvota[sim_id] = KAL_FALSE;
}
MD_TRC_MCF_TR_SET_CONFIG_AFTER_DSBP_DURATION(CALCULATE_LETENCY_DURATION(start_time, GET_CURRENT_TIME()));
return ret;
}
kal_bool mcf_check_lid_need_reset(nvram_lid_enum lid)
{
kal_int16 pos1 = -1;
kal_int16 pos2 = -1;
kal_uint16 new_pos = 0;
#ifdef __MCF_COMBINE_FILE_SUPPORT__
kal_bool reset = KAL_FALSE;
#endif
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_START(lid);
/* Search last modified LID list */
if (mcf_last_mod_lid_g.lid_cnt >= NVRAM_MCF_SAVE_LAST_LID_CNT) {
/* If last modified LID list is full, all LIDs are needed to be reset */
return KAL_TRUE;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
pos1 = mcf_binary_search_lid(lid, mcf_last_mod_lid_g.lid, mcf_last_mod_lid_g.lid_cnt, &new_pos);
#else
pos1 = mcf_binary_search_lid_struct(lid, mcf_last_mod_lid_g.lid_conf, mcf_last_mod_lid_g.lid_cnt, &new_pos);
if(pos1 != -1 && pos1 >= 0){
if(nv_int_info.not_reset_ota == KAL_FALSE || mcf_last_mod_lid_g.lid_conf[pos1].not_reset == KAL_FALSE){
reset = KAL_TRUE;
}
}
#endif
/* Search current modified LID list */
if (mcf_curr_mod_lid_g.lid_cnt >= NVRAM_MCF_SAVE_LAST_LID_CNT) {
/* If current modified LID list is full, all LIDs are needed to be reset */
return KAL_TRUE;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
pos2 = mcf_binary_search_lid(lid, mcf_curr_mod_lid_g.lid, mcf_curr_mod_lid_g.lid_cnt, &new_pos);
#else
pos2 = mcf_binary_search_lid_struct(lid, mcf_curr_mod_lid_g.lid_conf, mcf_curr_mod_lid_g.lid_cnt, &new_pos);
if(pos2 != -1 && pos2 >= 0){
if(nv_int_info.not_reset_ota == KAL_FALSE || mcf_curr_mod_lid_g.lid_conf[pos2].not_reset == KAL_FALSE){
reset = KAL_TRUE;
}
}
#endif
if ( (pos1 != -1) || (pos2 != -1) ) {
#ifdef __MCF_COMBINE_FILE_SUPPORT__
if (reset == KAL_TRUE)
#endif
{
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_FOUND(pos1, pos2);
return KAL_TRUE;
}
}
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_NOT_FOUND(lid, pos1, pos2);
return KAL_FALSE;
}
kal_bool mcf_check_lid_need_reset_by_psid(nvram_lid_enum lid, kal_uint8 ps_id)
{
kal_int16 pos1 = -1;
kal_int16 pos2 = -1;
kal_uint16 new_pos = 0;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
#ifdef __MCF_COMBINE_FILE_SUPPORT__
kal_bool reset = KAL_FALSE;
#endif
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_BY_PSID_START(lid, ps_id);
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_BY_PSID_INVALID_SIM_ID(ps_id, sim_id);
return KAL_FALSE;
}
/* Search tlvota last modified LID list */
if (mcf_tlvota_last_mod_lid_g[sim_id].lid_cnt >= NVRAM_MCF_SAVE_LAST_LID_CNT) {
/* If last modified LID list is full, all LIDs are needed to be reset */
return KAL_TRUE;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
pos1 = mcf_binary_search_lid(lid, mcf_tlvota_last_mod_lid_g[sim_id].lid, mcf_tlvota_last_mod_lid_g[sim_id].lid_cnt, &new_pos);
#else
pos1 = mcf_binary_search_lid_struct(lid, mcf_tlvota_last_mod_lid_g[sim_id].lid_conf, mcf_tlvota_last_mod_lid_g[sim_id].lid_cnt, &new_pos);
if(pos1 != -1 && pos1 >= 0){
if(nv_int_info.not_reset_tlvota[sim_id] == KAL_FALSE || mcf_tlvota_last_mod_lid_g[sim_id].lid_conf[pos1].not_reset == KAL_FALSE){
reset = KAL_TRUE;
}
}
#endif
/* Search tlvota current modified LID list */
if (mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt >= NVRAM_MCF_SAVE_LAST_LID_CNT) {
/* If current modified LID list is full, all LIDs are needed to be reset */
return KAL_TRUE;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
pos2 = mcf_binary_search_lid(lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &new_pos);
#else
pos2 = mcf_binary_search_lid_struct(lid, mcf_tlvota_curr_mod_lid_g[sim_id].lid_conf, mcf_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &new_pos);
if(pos2 != -1 && pos2 >= 0){
if(nv_int_info.not_reset_tlvota[sim_id] == KAL_FALSE || mcf_tlvota_curr_mod_lid_g[sim_id].lid_conf[pos2].not_reset == KAL_FALSE){
reset = KAL_TRUE;
}
}
#endif
if ( (pos1 != -1) || (pos2 != -1) ) {
#ifdef __MCF_COMBINE_FILE_SUPPORT__
if (reset == KAL_TRUE)
#endif
{
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_BY_PSID_TLVOTA_FOUND(lid);
return KAL_TRUE;
}
}
pos1 = -1;
pos2 = -1;
/* Search general tlvota last modified LID list */
if (mcf_general_tlvota_last_mod_lid_g[sim_id].lid_cnt >= NVRAM_MCF_SAVE_LAST_LID_CNT) {
/* If last modified LID list is full, all LIDs are needed to be reset */
return KAL_TRUE;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
pos1 = mcf_binary_search_lid(lid, mcf_general_tlvota_last_mod_lid_g[sim_id].lid, mcf_general_tlvota_last_mod_lid_g[sim_id].lid_cnt, &new_pos);
#else
pos1 = mcf_binary_search_lid_struct(lid, mcf_general_tlvota_last_mod_lid_g[sim_id].lid_conf, mcf_general_tlvota_last_mod_lid_g[sim_id].lid_cnt, &new_pos);
if(pos1 != -1 && pos1 >= 0){
if(nv_int_info.not_reset_general_tlvota == KAL_FALSE || mcf_general_tlvota_last_mod_lid_g[sim_id].lid_conf[pos1].not_reset == KAL_FALSE){
reset = KAL_TRUE;
}
}
#endif
/* Search general tlvota current modified LID list */
if (mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt >= NVRAM_MCF_SAVE_LAST_LID_CNT) {
/* If current modified LID list is full, all LIDs are needed to be reset */
return KAL_TRUE;
}
#if !defined(__MCF_COMBINE_FILE_SUPPORT__)
pos2 = mcf_binary_search_lid(lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &new_pos);
#else
pos2 = mcf_binary_search_lid_struct(lid, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_conf, mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_cnt, &new_pos);
if(pos2 != -1 && pos2 >= 0){
if(nv_int_info.not_reset_general_tlvota == KAL_FALSE || mcf_general_tlvota_curr_mod_lid_g[sim_id].lid_conf[pos2].not_reset == KAL_FALSE){
reset = KAL_TRUE;
}
}
#endif
if ( (pos1 != -1) || (pos2 != -1) ) {
#ifdef __MCF_COMBINE_FILE_SUPPORT__
if (reset == KAL_TRUE)
#endif
{
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_BY_PSID_GENERAL_TLVOTA_FOUND(lid);
return KAL_TRUE;
}
}
MD_TRC_MCF_TR_CHECK_LID_NEED_RESET_BY_PSID_NOT_FOUND(lid);
return KAL_FALSE;
}
mcf_ota_result_e mcf_check_reset_and_tlvota_buffer_sbp_tag(kal_uint8 ps_id, mcf_tlvota_sbp_tag_t sbp_tag, nvram_lid_enum lid , kal_uint8 *buffer, kal_uint32 size, kal_uint16 record_idx)
{
mcf_ota_result_e ret = MCF_OTA_R_SUCCESS;
if (!(buffer && (size > 0))) {
MD_TRC_MCF_TR_CHECK_RESET_AND_TLVOTA_BUFFER_SBP_TAG_INVALID_PARA(ps_id, lid, buffer, size);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
if(mcf_check_lid_need_reset_by_psid(lid, ps_id) == KAL_TRUE){
if (NVRAM_DEFAULT_VALUE_POINT != nvram_get_default_value(lid, ps_id, &buffer))
{
MD_TRC_MCF_TR_CHECK_RESET_AND_TLVOTA_BUFFER_SBP_TAG_GET_DEFAULT_VALUE_FAIL(lid);
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
}else{
if ( !nvram_external_read_data(lid, record_idx, buffer, size)) {
ret = MCF_OTA_R_READ_NVRAM_FAIL;
return ret;
}
}
ret = mcf_read_ota_buffer(lid, record_idx, buffer, size);
if (ret != MCF_OTA_R_SUCCESS){
return ret;
}
ret = mcf_read_tlvota_buffer_sbp_tag(ps_id, sbp_tag, lid, buffer, size);
return ret;
}
kal_bool mcf_check_ota_need_update(protocol_id_enum ps_id, mcf_tlvota_sbp_tag_t sbp_tag, kal_uint8* iccid)
{
kal_bool is_need_update = KAL_FALSE;
kal_bool ret = KAL_FALSE;
sbp_reconfig_custom_param_struct param_ptr;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_CHECK_OTA_NEED_UPDATE_INVALID_SIM_ID(ps_id, sim_id);
ret = MCF_OTA_R_INVALID_PARAMETER;
return ret;
}
MD_TRC_MCF_TR_CHECK_OTA_NEED_UPDATE_START(ps_id, sbp_tag.sbp_id, sbp_tag.mcc, sbp_tag.mnc);
param_ptr.ps_id = ps_id;
param_ptr.sbp_id = sbp_tag.sbp_id;
kal_mem_cpy(param_ptr.mcc, sbp_tag.mcc, MAX_MCC_STR_LEN);
kal_mem_cpy(param_ptr.mnc, sbp_tag.mnc, MAX_MNC_STR_LEN);
kal_mem_cpy(param_ptr.iccid, iccid, 21);
ret = mcf_auto_select_tlvota_file(&param_ptr);
if (ret == KAL_FALSE){
is_need_update = KAL_FALSE;
MD_TRC_MCF_TR_CHECK_OTA_NEED_UPDATE_FAIL(ps_id, ret);
}
if (com_Mcf.update_tlvota[sim_id] == KAL_TRUE || com_Mcf.update_general_tlvota[sim_id] == KAL_TRUE){
is_need_update = KAL_TRUE;
}
MD_TRC_MCF_TR_CHECK_OTA_NEED_UPDATE_RESULT(ps_id, is_need_update);
return is_need_update;
}
mcf_ota_result_e mcf_get_tlvota_file_result(protocol_id_enum ps_id){
mcf_ota_result_e mcf_ret = MCF_OTA_R_SUCCESS;
sim_interface_enum sim_id = l4c_gemini_get_actual_sim_id(ps_id);
MD_TRC_MCF_TR_GET_TLVOTA_FILE_RESULT_START(ps_id);
if (sim_id < 0 || sim_id >= MAX_SIM_NUM){
MD_TRC_MCF_TR_GET_TLVOTA_FILE_RESULT_INVALID_SIM_ID(ps_id, sim_id);
mcf_ret = MCF_OTA_R_INVALID_PARAMETER;
return mcf_ret;
}
mcf_ret = com_Mcf.tlvota_result[sim_id];
com_Mcf.tlvota_result[sim_id] = MCF_OTA_R_INVALID_PARAMETER;
MD_TRC_MCF_TR_GET_TLVOTA_FILE_RESULT_RETURN_RESULT(ps_id, mcf_ret);
return mcf_ret;
}