📄 phb_handler_delete.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* phb_handler_delete.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
* This is write handler of PHB module.
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#include "kal_release.h" /* Basic data type */
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h" /* Task message communiction */
#include "app_buff_alloc.h"
#include "kal_trace.h"
#include "phb_trc.h"
#include "sim_common_enums.h"
// #include "nvram_editor_data_item.h"
#include "custom_nvram_editor_data_item.h"
#include "nvram_enums.h"
#include "nvram_struct.h"
#include "l4_common.h"
#include "ps2sim_struct.h"
#include "l4c2phb_enums.h"
#include "l4c2phb_struct.h"
/* Prerequisite of phb_context.h */
#include "phb_defs.h"
#include "phb_control_block.h"
#include "phb_data_desc.h"
#include "phb_data_entry_table.h"
#include "phb_pindex.h"
#include "phb_name_num_index.h"
#include "phb_context.h"
#include "phb_se.h"
#include "phb_sap.h"
/* ErrorStruct */
#include "asn-error.h"
#include "phb_common.h"
#include "phb_ilm.h"
#include "phb_handler_read.h"
#include "phb_handler_delete.h"
#include "phb_nvram_access.h"
#ifdef __PHB_RECORD_LN_TYPE_SEQ__
#include "phb_handler_write.h"
#endif
#undef _FILE_CODE_
#define _FILE_CODE_ _PHB_HANDLER_DELETE_C_
static void phb_delete_err_handler(ilm_struct *ilm_ptr, control_block_type *control_block);
static void phb_delete_continue(ilm_struct *ilm_ptr, control_block_type *control_block);
static void phb_delete_confirm(
phb_errno_enum result,
kal_uint16 actual_count,
kal_uint8 src_id,
control_block_type *control_block);
static void phb_delete_ln_confirm(phb_errno_enum result, kal_uint8 src_id, control_block_type *control_block);
static kal_bool phb_delete_ln(nvram_ef_phb_ln_struct *record, control_block_type *control_block);
static void phb_ln_delete_entry(kal_uint8 index, nvram_ef_phb_ln_struct *record);
#ifdef __PHB_RECORD_LN_TYPE_SEQ__
static void phb_delete_ln_type_seq(kal_uint8 del_seq_index, kal_uint8 type);
#endif
#if (MAX_PHB_LN_ENTRY > 20)
static kal_bool first_round;
#endif
#ifndef __PHB_SORT_ENABLE__
/*****************************************************************************
* FUNCTION
* phb_delete_find_next_deleted
* DESCRIPTION
* Find record index of next occupied record
* PARAMETERS
* storage [IN]
* data_desc(?) [IN] The data-descriptor
* RETURNS
* record index of next free record.
*****************************************************************************/
kal_uint16 phb_delete_find_next_deleted(phb_storage_enum storage)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
data_desc_enum type;
data_desc_type *data_desc_entry;
kal_uint16 byte_counter;
kal_uint16 bit_counter;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* kal_trace(TRACE_FUNC, FUNC_PHB_DATA_DESC_FIND_NEXT_FREE); */
if (storage == PHB_NVRAM)
{
type = DATA_DESC_PHB;
}
else
{
type = DATA_DESC_ADN;
}
data_desc_entry = &phb_ptr->data_desc[type];
ASSERT(data_desc_entry != NULL);
if ((data_desc_entry->is_support == KAL_FALSE) ||
(data_desc_entry->free_count == phb_data_desc_get_record_size(type)))
{
return (kal_uint16) PHB_INVALID_VALUE;
}
for (byte_counter = 0;
byte_counter < (data_desc_entry->free_bitmap_bits >> BYTE_SIZE_SHIFT_ARITHMETIC); ++byte_counter)
{
if (data_desc_entry->free_bitmap[byte_counter] != 0)
{
for (bit_counter = 0; (bit_counter < BYTE_SIZE) &&
(((byte_counter << BYTE_SIZE_SHIFT_ARITHMETIC) + bit_counter) < data_desc_entry->record_num);
++bit_counter)
{
if (!(data_desc_entry->free_bitmap[byte_counter] & (1 << bit_counter)))
{
return (byte_counter << BYTE_SIZE_SHIFT_ARITHMETIC) + bit_counter + 1;
}
}
}
}
return (kal_uint16) PHB_INVALID_VALUE;
} /* end of phb_delete_find_next_deleted */
#endif /* __PHB_SORT_ENABLE__ */
/*****************************************************************************
* FUNCTION
* phb_delete_handler
* DESCRIPTION
* This is phb_delete_handler function of PHB module.
* Handles write request from L4C.
* PARAMETERS
* ilm_ptr [IN] The primitives
* control_block [?]
* RETURNS
* void
*****************************************************************************/
void phb_delete_handler(ilm_struct *ilm_ptr, control_block_type *control_block)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
kal_trace(TRACE_FUNC, FUNC_PHB_DELETE);
if (ilm_ptr != NULL)
{
l4cphb_delete_req_struct *l4cphb_delete_req;
l4cphb_delete_req = (l4cphb_delete_req_struct*) ilm_ptr->local_para_ptr;
/**
* Delete should be exclusive from other operations, otherwise they could conflict.
* Current PHB implementation doesn't prevent such conditions.
* Such condition should happen at caller's own risk.
*/
/* Cannot allocate, means that PHB is still operating. Reject request! */
control_block = phb_alloc_control_block();
if (control_block == NULL)
{
phb_delete_confirm(PHB_ERRNO_BUSY, 0, l4cphb_delete_req->src_id, control_block);
return;
}
control_block->src_id = l4cphb_delete_req->src_id;
/* Retain msg_id */
control_block->cnf_msg_id = ilm_ptr->msg_id;
if (phb_ptr->state == PHB_STATE_READY)
{
if (control_block->proc_stage == DELETE_NONE)
{
/* Reset actual count to zero */
control_block->actual_count = 0;
/* Error: ECC and SDN are read only */
if (!phb_is_type_valid(l4cphb_delete_req->type) ||
(l4cphb_delete_req->type == PHB_ECC) ||
(l4cphb_delete_req->type == PHB_SDN) || (l4cphb_delete_req->type == PHB_GAS))
{
phb_delete_err_handler(NULL, control_block);
return;
}
/* Delete all!! */
if (l4cphb_delete_req->total == (kal_uint16) PHB_INVALID_VALUE)
{
if (l4cphb_delete_req->index != 1)
{
phb_delete_confirm(
PHB_ERRNO_FAIL,
control_block->actual_count,
control_block->src_id,
control_block);
return;
}
/* Ok, index = 1 and total = 0xFFFF, delete all! */
l4cphb_delete_req->total = phb_se_get_total_of_type(l4cphb_delete_req->type);
/* amanda add */
if (l4cphb_delete_req->type == PHB_PHONEBOOK)
{
control_block->storage = l4cphb_delete_req->storage;
#ifdef __PHB_SORT_ENABLE__
l4cphb_delete_req->index = phb_se_get_index_by_storage(control_block->storage);
#else
l4cphb_delete_req->index = phb_delete_find_next_deleted(control_block->storage);
#endif
if (l4cphb_delete_req->index == PHB_INVALID_VALUE)
{
phb_delete_confirm(PHB_ERRNO_SUCCESS, 0, l4cphb_delete_req->src_id, control_block);
return;
}
}
}
if (l4cphb_delete_req->index != (kal_uint16) PHB_INVALID_VALUE)
{
/* Since this is a delete operation, no need to prepare data for deletion. */
control_block->total = l4cphb_delete_req->total;
if (l4cphb_delete_req->type == PHB_PHONEBOOK ||
phb_se_is_in_range(
l4cphb_delete_req->type,
l4cphb_delete_req->index,
&l4cphb_delete_req->total) == KAL_TRUE)
{
/* This is for fectching necessary parameters from temp_entry */
l4cphb_delete_req->total = control_block->total;
phb_control_block_set_param(control_block, DELETE_CONTINUE, NULL, NULL);
phb_control_block_set(
control_block,
phb_delete_continue,
phb_delete_handler,
phb_delete_err_handler,
DELETE_CONTINUE);
phb_control_block_set_IO(
control_block,
l4cphb_delete_req->type,
l4cphb_delete_req->index,
l4cphb_delete_req->total);
/**
* Temporarily stores number of entries to be piggybacked.
* Don't forget to restore it back to control_block->total before
* read_fake(), if necessary.
*/
control_block->total_piggyback = l4cphb_delete_req->total_piggyback;
/* set storage, record_index, primary_ID, and secondary_ID */
if (phb_se_set_control_block(
control_block,
OP_DELETE,
l4cphb_delete_req->storage,
(kal_uint16) PHB_INVALID_VALUE) == KAL_FALSE)
{
phb_delete_err_handler(NULL, control_block);
return;
}
/* Since this is a delete operation, no need to set data. */
control_block->length = phb_data_desc_get_record_size(phb_data_desc_get_desc_by_ID(control_block->primary_ID));
/*
* If it is a MSISDN entry, need to read the data from SIM first to see if the MSISDN uses extenstion 1
* * So allocate buffer to store read data for phb_issue_IO_read() command here.
*/
if (l4cphb_delete_req->type == PHB_MSISDN)
{
control_block->data = get_ctrl_buffer(sizeof(phb_entry_struct));
}
phb_delete_continue(NULL, control_block);
}
else
{
phb_delete_confirm(
PHB_ERRNO_FAIL,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -