⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phb_sim_access.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
}   /* end of phb_sim_write_segmented_record */


/*****************************************************************************
 * FUNCTION
 *  phb_sim_write_first_record
 * DESCRIPTION
 *  This function prepares data content for the first part of telephone numbers then
 *  invokes sim_write_record() to write a record.
 *  
 *  Prerequisites:
 *  control_block->phb_entry must not be NULL.
 *  primary_ID and its data_desc_type must no be PHB_INVALID_VALUE
 *  control_block->data and length must be setup.
 * PARAMETERS
 *  control_block       [?]         
 *  chained_id          [IN]        
 * RETURNS
 *  KAL_TRUE if success, KAL_FALSE otherwise.
 *****************************************************************************/
kal_bool phb_sim_write_first_record(
            control_block_type *control_block,
            /* data_desc_enum type, */ kal_uint8 chained_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 *ef_buffer = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SIM_WRITE_FIRST_RECORD);

    ASSERT(control_block != NULL);

    control_block->IO_stage = IO_WAIT;
    control_block->IO_cnf_receive = phb_sim_write_cnf;

    ef_buffer = (kal_uint8*) get_ctrl_buffer(control_block->length);

    if (phb_sim_prepare_data_to_write(control_block, ef_buffer, chained_id) == KAL_FALSE)
    {
        return KAL_FALSE;
    }

    /* Perparation of data content complete! */
    phb_sim_write_record(
        control_block->primary_ID,
        control_block->record_index,
        ef_buffer,
        control_block->length,
        control_block->ID);

    if (ef_buffer != NULL)
    {
        free_ctrl_buffer(ef_buffer);
    }

    return KAL_TRUE;
}   /* end of phb_sim_write_first_record */


/*****************************************************************************
 * FUNCTION
 *  phb_sim_write
 * DESCRIPTION
 *  This function issues SIM_WRITE_REQ to sim.
 *  
 *  Prerequisite:
 *  control_block must be constructed, phb_control_block_set_IO(), and phb_se_set_control_block().
 *  So that primary_ID, secondary_ID, index and record_index are all set.
 *  
 *  Assumption:
 *  control_block->type, control_block->primary_ID is assumed to be valid.
 * PARAMETERS
 *  control_block       [?]         
 *  ilm_ptr(?)          [IN]        The primitives
 * RETURNS
 *  KAL_TRUE if success, KAL_FALSE otherwise.
 *****************************************************************************/
kal_bool phb_sim_write(control_block_type *control_block)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_bool result = KAL_FALSE;
    kal_uint8 ext1_need_num = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SIM_WRITE);

    ASSERT(control_block != NULL);

    if (control_block->IO_stage == IO_NONE)
    {
        data_desc_enum type = DATA_DESC_PHB;
        phb_entry_struct *phb_entry;

    #ifdef __PHB_USIM_SUPPORT__
        if (phb_data_desc_get_desc_by_ID(control_block->primary_ID) == DATA_DESC_ANRA)
        {
            control_block->ext1_parent_type = PHB_ANRA; // TODO: another type?
        }
        else
    #endif /* __PHB_USIM_SUPPORT__ */ 
        {
            control_block->ext1_parent_type = PHB_PHONEBOOK;
        }
        /* Nothing to write? error! */
        if ((phb_entry = (phb_entry_struct*) control_block->data) == NULL)
        {
            return KAL_FALSE;
        }

        /* check if enough EXT1 */
        /* First, find out whether free records in EFext suffice */
        if (phb_se_get_ext_index(control_block->ext1_parent_type, phb_entry) == (kal_uint8) PHB_INVALID_VALUE)
        {
        #ifdef __PHB_USIM_SUPPORT__
            if (control_block->ext1_parent_type == PHB_PHONEBOOK)
        #endif 
            {
                ext1_need_num +=
                    ((phb_entry->tel_number.addr_length - PHB_EF_MAX_TON_NPI_TEL_NUMBER_LEN + EF_TEL_NUMBER_SIZE -
                      1) / EF_TEL_NUMBER_SIZE);
            }
        }
        if ((control_block->secondary_ID != (kal_uint16) PHB_INVALID_VALUE) &&
            ((type = phb_data_desc_get_desc_by_ID(control_block->secondary_ID)) !=
             (data_desc_enum) PHB_INVALID_VALUE) && phb_data_desc_get_free_count(type) < ext1_need_num)
        {
            /* SIM has no more space to chain long numbers */
            control_block->cause = SIM_EF_RECORD_FULL;
            result = KAL_FALSE;
        }

    #ifdef __PHB_USIM_SUPPORT__
        else if (phb_data_desc_get_desc_by_ID(control_block->primary_ID) == DATA_DESC_ANRA)
        {
            control_block->seg_total = 0;
            if (control_block->ext1_parent_type == PHB_ANRA &&
                ((control_block->temp_anra.tel_number.addr_length - TON_NPI_SIZE) > EF_TEL_NUMBER_SIZE))
            {
                /* ext1_need_num += ((control_block->temp_anra.tel_number.addr_length - PHB_EF_MAX_TON_NPI_TEL_NUMBER_LEN + EF_TEL_NUMBER_SIZE - 1) / EF_TEL_NUMBER_SIZE); */
                if ((control_block->seg_len =
                     (control_block->temp_anra.tel_number.addr_length - TON_NPI_SIZE) % EF_TEL_NUMBER_SIZE) == 0)
                {
                    control_block->seg_len = EF_TEL_NUMBER_SIZE;
                }

                result = phb_sim_write_anr_segmented_record(
                            control_block,
                            &(control_block->temp_anra),
                            control_block->ext1_parent_type,
                            (kal_uint8) PHB_INVALID_VALUE);

            }
            else if (control_block->ext1_parent_type == PHB_ANRB)
            {
            }
            else if (control_block->ext1_parent_type == PHB_ANRC)
            {
            }
            /* Segmentation is not needed */
            /* control_block->type, control_block->primary_ID is assumed to be valid. */
            else
            {
                control_block->seg_total = 0;
                result = phb_sim_write_first_record(control_block, /* type, */ (kal_uint8) PHB_INVALID_VALUE);
            }
            return result;
        }
    #endif /* __PHB_USIM_SUPPORT__ */ 

        /* Need segmentation */
        else if ((type != (data_desc_enum) PHB_INVALID_VALUE) &&
                 ((phb_entry->tel_number.addr_length - TON_NPI_SIZE) > EF_TEL_NUMBER_SIZE))
        {
            control_block->seg_total = 0;

            /* Each write iteration writes a segment of data from tail to head */
         /** 
          * Because first segment stored in ADN-like EF could store 1 byte 
          * more than EXT-like EF, decrement length to retain that byte to
          * be written in first segment.
          */
            if ((control_block->seg_len = (phb_entry->tel_number.addr_length - TON_NPI_SIZE) % EF_TEL_NUMBER_SIZE) == 0)
            {
                control_block->seg_len = EF_TEL_NUMBER_SIZE;
            }

            result = phb_sim_write_segmented_record(control_block, type, (kal_uint8) PHB_INVALID_VALUE);
        }

        /* Segmentation is not needed */
        /* control_block->type, control_block->primary_ID is assumed to be valid. */
        else
        {
            control_block->seg_total = 0;
            result = phb_sim_write_first_record(control_block, /* type, */ (kal_uint8) PHB_INVALID_VALUE);
        }
    }
    /* Error */
    else
    {
        result = KAL_FALSE;
    }

    return result;
}   /* end of phb_sim_write */


/*****************************************************************************
 * FUNCTION
 *  phb_sim_write_cnf
 * DESCRIPTION
 *  This function issues SIM_FILE_INFO_REQ to sim.
 * PARAMETERS
 *  ilm_ptr             [IN]        The primitives
 *  control_block       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
static void phb_sim_write_cnf(ilm_struct *ilm_ptr, control_block_type *control_block)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    sim_write_cnf_struct *sim_write_cnf;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_SIM_WRITE_CNF);

    ASSERT(control_block != NULL);

    sim_write_cnf = (sim_write_cnf_struct*) ilm_ptr->local_para_ptr;

    if (sim_write_cnf->result == SIM_CMD_SUCCESS)
    {
        /* Success */
        if (control_block->IO_stage == IO_WAIT)
        {
            control_block->IO_stage = IO_NONE;
            control_block->IO_cnf_receive = NULL;
            (*control_block->return_location) (ilm_ptr, control_block);
        }
        /* In segmentation ? */
        else if ((control_block->IO_stage == IO_SEGMENTATION) &&
                 (sim_write_cnf->file_idx == control_block->secondary_ID))
        {
            data_desc_enum type;
            phb_entry_struct *phb_entry;

            phb_entry = (phb_entry_struct*) control_block->data;

            control_block->seg_total += control_block->seg_len;

            /* Since segmented data is written, that record must be marked */
            phb_data_desc_mark_free(
                phb_data_desc_get_desc_by_ID(control_block->secondary_ID),
                control_block->seg_record_index,
                KAL_FALSE);

            /* Still need segmentation */
            if ((control_block->secondary_ID != (kal_uint16) PHB_INVALID_VALUE) &&
                ((type = phb_data_desc_get_desc_by_ID(control_block->secondary_ID)) !=
                 (data_desc_enum) PHB_INVALID_VALUE) &&
                ((phb_entry->tel_number.addr_length - TON_NPI_SIZE - control_block->seg_total) > EF_TEL_NUMBER_SIZE))
            {
                control_block->seg_len = EF_TEL_NUMBER_SIZE;

                /* Error: cannot find a free record to write */
                if (phb_sim_write_segmented_record(control_block, type, control_block->seg_record_index) == KAL_FALSE)
                {
                    phb_IO_return(control_block, ilm_ptr, KAL_FALSE);
                    return;
                }
            }
            /* Finally, segmentation is not needed. First record now can be written */
            else if ((control_block->primary_ID != (kal_uint16) PHB_INVALID_VALUE) &&
                     ((type = phb_data_desc_get_desc_by_ID(control_block->primary_ID)) !=
                      (data_desc_enum) PHB_INVALID_VALUE))
            {
                /* Error: cannot write first record */
                if (phb_sim_write_first_record(control_block, /* type, */ control_block->seg_record_index) ==
                    KAL_FALSE)
                {
                    phb_IO_return(control_block, ilm_ptr, KAL_FALSE);
                    return;
                }
            }
         /** 
          * Wrong state: this CNF is not for us. 
          * Abnormal, consume message.
          */
            else
            {
                kal_trace(TRACE_ERROR, ERROR_PHB_SIM_IO_STATE_WRITE);
                return;
            }
        }
    #ifdef __PHB_USIM_SUPPORT__
        else if ((control_block->IO_stage == IO_ANR_SEGMENTATION) &&
                 (sim_write_cnf->file_idx == control_block->secondary_ID))
        {
            data_desc_enum type;
            phb_anr_struct *anr_entry = &(control_block->temp_anra);

            control_block->seg_total += control_block->seg_len;

            //set ext_index_table
            //phb_se_ext_index_set(control_block->record_index, 
            //                        control_block->seg_record_index, 
            //                        control_block->ext1_parent_type);
            /* Since segmented data is written, that record must be marked *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -