Exemple #1
0
/* phb */
extern phb_context_type phb_context[];
extern phb_context_type *phb_ptr;
#endif /* __GEMINI__ */
extern 

/*****************************************************************************
 * FUNCTION
 *  phb_main
 * DESCRIPTION
 *  This is main() function of PHB module.
 * PARAMETERS
 *  ilm_ptr     [IN]        The primitives
 * RETURNS
 *  void
 *****************************************************************************/
void phb_main(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 access_id = (kal_uint8) PHB_INVALID_VALUE;
    control_block_type *control_block = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (ilm_ptr == NULL)
    {
        return;
    }

    if ((ilm_ptr->msg_id == MSG_ID_NVRAM_READ_CNF) ||
        (ilm_ptr->msg_id == MSG_ID_NVRAM_WRITE_CNF) ||
    #ifdef __PHB_DELETE_ALL_TURBO__ 
        (ilm_ptr->msg_id == MSG_ID_NVRAM_RESET_CNF)||
    #endif
        (ilm_ptr->msg_id == MSG_ID_SIM_FILE_INFO_CNF) ||
        (ilm_ptr->msg_id == MSG_ID_SIM_READ_CNF) || 
        (ilm_ptr->msg_id == MSG_ID_SIM_WRITE_CNF))
    {

        if (phb_ptr->drop_cnf == KAL_TRUE)
        {
            phb_ptr->drop_cnf = KAL_FALSE;
            return;
        }

        switch (ilm_ptr->msg_id)
        {
            case MSG_ID_NVRAM_READ_CNF:
                access_id = ((nvram_read_cnf_struct*) ilm_ptr->local_para_ptr)->access_id;
                break;

            case MSG_ID_NVRAM_WRITE_CNF:
                access_id = ((nvram_write_cnf_struct*) ilm_ptr->local_para_ptr)->access_id;
                break;

            case MSG_ID_SIM_FILE_INFO_CNF:
                access_id = ((sim_file_info_req_struct*) ilm_ptr->local_para_ptr)->access_id;
                break;

            case MSG_ID_SIM_READ_CNF:
                access_id = ((sim_read_cnf_struct*) ilm_ptr->local_para_ptr)->access_id;
                break;

            case MSG_ID_SIM_WRITE_CNF:
                access_id = ((sim_write_cnf_struct*) ilm_ptr->local_para_ptr)->access_id;
                break;
        #ifdef __PHB_DELETE_ALL_TURBO__ 
            case MSG_ID_NVRAM_RESET_CNF:
                access_id = ((nvram_reset_cnf_struct*) ilm_ptr->local_para_ptr)->access_id;
                break;
        #endif /* __PHB_DELETE_ALL_TURBO__ */
        }

        if ((access_id < PHB_CONCURRENCY_DEGREE) &&
            ((control_block = &phb_ptr->control_block[access_id])->IO_cnf_receive != NULL))
            /* call control_block.IO_cnf_receive */
        {
            (*control_block->IO_cnf_receive) (ilm_ptr, control_block);
        }
        else
        {
            kal_trace(TRACE_ERROR, ERROR_PHB_ABNORMAL);
            /* consume abnormal_cnf */
            return;
        }
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_INIT_LN_REQ)
    {
        phb_ptr->state = PHB_STATE_LN_NOT_READY;
        //kal_trace(TRACE_STATE, STATE_PHB_NOT_READY);
        //reset all control blocks while receiving the first msg
        phb_reset_all_control_blocks();
    #ifdef __PHB_RECORD_LN_TYPE_SEQ__
        phb_startup_sync_ln_type_seq(NULL, NULL);
    #else 
        phb_startup_erase_ln(ilm_ptr, NULL);
    #endif 
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_STARTUP_REQ)
    {
        phb_ptr->state = PHB_STATE_NOT_READY;
        kal_trace(TRACE_STATE, STATE_PHB_NOT_READY);

        phb_startup_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_READ_REQ)
    {
        phb_read_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_WRITE_REQ)
    {
        phb_write_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_DELETE_REQ)
    {
        phb_delete_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_SEARCH_REQ)
    {
        phb_search_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_APPROVE_REQ)
    {
        phb_approve_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_SYNC_REQ)
    {
        phb_sync_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_WRITE_LN_REQ)
    {
        phb_write_ln_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_READ_LN_REQ)
    {
        phb_read_ln_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_DELETE_LN_REQ)
    {
        phb_delete_ln_handler(ilm_ptr, NULL);
    }
#ifdef __PHB_USIM_SUPPORT__
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_READ_EMAIL_REQ)
    {
        phb_read_email_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_WRITE_USIM_REQ)
    {
        phb_write_usim_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_SET_GRP_REQ)
    {
        phb_set_grp_handler(ilm_ptr, NULL);
    }
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_STARTUP_READ_NEXT_USIM_FIELD_REQ)
    {
        access_id = ((l4cphb_startup_read_next_usim_field_req_struct*) ilm_ptr->local_para_ptr)->access_id;

        if (access_id < PHB_CONCURRENCY_DEGREE)
        {
            control_block = &phb_ptr->control_block[access_id];
            phb_build_index_continue(control_block);
        }
        else
        {
            kal_trace(TRACE_ERROR, ERROR_PHB_ABNORMAL);
            /* consume abnormal_cnf */
            return;
        }
    }
#endif /* __PHB_USIM_SUPPORT__ */ /* __PHB_USIM_SUPPORT */

#ifdef __SAT__
    else if (ilm_ptr->msg_id == MSG_ID_SAT_FILE_CHANGE_IND)
    {
        phb_sat_file_change_handler(ilm_ptr, NULL);
    }
#endif /* __SAT__ */ 

    /*  
     *   If it a ADN record, wait for MMI response to continue to read next entry. 
     */
    else if (ilm_ptr->msg_id == MSG_ID_L4CPHB_STARTUP_READ_NEXT_REQ)
    {
        access_id = ((l4cphb_startup_read_next_req_struct*) ilm_ptr->local_para_ptr)->access_id;
        if (access_id < PHB_CONCURRENCY_DEGREE)
        {
            control_block = &phb_ptr->control_block[access_id];
            phb_build_index_continue_adn(control_block);
        }
        else
        {
            kal_trace(TRACE_ERROR, ERROR_PHB_ABNORMAL);
            /* consume abnormal_cnf */
            return;
        }

    }

    else
    {
        kal_trace(TRACE_ERROR, ERROR_PHB_ABNORMAL);
        /* consume abnormal primitives */
        return;
    }
}   /* end of module main function */
/*****************************************************************************
 * FUNCTION
 *  phb_sat_file_change_handler
 * DESCRIPTION
 *  In current implementation, all related EF's will be rescanned.
 *  Hence, actually the file_change request will be forwarded to
 *  startup_handler().
 * PARAMETERS
 *  ilm_ptr             [IN]        The primitives
 *  control_block       [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void phb_sat_file_change_handler(ilm_struct *ilm_ptr, control_block_type *control_block)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

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

    if (ilm_ptr != NULL)
    {
        kal_uint16 i;
        kal_bool need_reset_flag = KAL_FALSE;
        sat_file_change_ind_struct *sat_file_change_ind;

        sat_file_change_ind = (sat_file_change_ind_struct*) ilm_ptr->local_para_ptr;

      /**
       * Since sat_file_change is an implicit reset, there 2 ways to implement this:
       *
       * 1. Interrupts other being processed operations and forbids 
       *   other further requests to PHB, except approve and search:
       *   In this implementation, 
       *   startup handler should always uses the first control_block, 
       *   and lock all control_blocks are locked temporarily;
       *   thus prevent other operations, except approve and search, 
       *   from accessing PHB while it is busy.
       *
       * 2. Allow all other operations to provide maximum possible
       *   concurrency degrees.
       *
       * Curretly, solution 1 is implemented.
       * Control_blocks are all locked to interrupt all other in-processing
       * operations and reject all further requests, to prevent
       * multiple access to PHB when it is not ready.
       */
        /* LN not ready means phb haven't been inited yet */
        if (phb_ptr->state == PHB_STATE_LN_NOT_READY)
        {
        }
        else if (sat_file_change_ind->is_full_changed)
        {
            need_reset_flag = KAL_TRUE;
        }
        else
        {
            for (i = 0; i < sat_file_change_ind->num_of_file; i++)
            {
                switch (sat_file_change_ind->file_list[i])
                {
                    case FILE_ADN_IDX:
                    case FILE_ECC_IDX:
                    case FILE_EXT1_IDX:                       
                #ifdef __PHB_USIM_SUPPORT__
                       need_reset_flag = KAL_TRUE;
                       /* MUST: Break CAN'T BE REMOVED */
                       break;                   
                    case FILE_U_ECC_IDX:
                        
                    case FILE_G_ADN_IDX:
                    case FILE_U_ADN_IDX:
                        
                    case FILE_G_PBR_IDX:
                    case FILE_U_PBR_IDX:
                        
                    case FILE_G_EXT1_IDX:
                    case FILE_U_EXT1_IDX:
                        
                    case FILE_U_FDN_IDX:
                    case FILE_U_SDN_IDX:
                    case FILE_U_EXT2_IDX:
                    case FILE_U_EXT3_IDX:
                    case FILE_U_BDN_IDX:
                    case FILE_U_EXT4_IDX:
                    case FILE_U_MSISDN_IDX:
                    case FILE_U_EXT5_IDX:
                #ifdef __PHB_USIM_ADDITIONAL_SUPPORT__
                    case FILE_G_IAP_IDX:
                    case FILE_U_IAP_IDX:
                        
                    case FILE_G_ANR_IDX:
                    case FILE_U_ANR_IDX:
                        
                    case FILE_G_EMAIL_IDX:
                    case FILE_U_EMAIL_IDX:
                        
                    case FILE_G_SNE_IDX:
                    case FILE_U_SNE_IDX:
                        
                    case FILE_G_GAS_IDX:
                    case FILE_U_GAS_IDX:
                        
                    case FILE_G_AAS_IDX:
                    case FILE_U_AAS_IDX:
                        
                    case FILE_G_GRP_IDX:
                    case FILE_U_GRP_IDX:
                #endif /* __PHB_USIM_ADDITIONAL_SUPPORT__ */
                       ASSERT(is_usim_type(PHB_WHICH_SIM));
                #endif /* __PHB_USIM_SUPPORT__ */
                    case FILE_FDN_IDX:
                    case FILE_SDN_IDX:
                    case FILE_EXT2_IDX:
                    case FILE_EXT3_IDX:
                    case FILE_BDN_IDX:
                    case FILE_EXT4_IDX:
                    case FILE_MSISDN_IDX:
                        need_reset_flag = KAL_TRUE;
                        break;
                    default:
                        break;
                }
            }
        }
        if (need_reset_flag)
        {
            for (i = 0; i < PHB_CONCURRENCY_DEGREE; i++)
            {
                if (phb_ptr->control_block[i].is_allocated == KAL_TRUE)
                {
                    phb_ptr->control_block[i].err_handler(NULL, &(phb_ptr->control_block[i]));
                }
            }

            phb_reset_all_control_blocks();
            control_block = phb_alloc_control_block();
            
            ASSERT(control_block != NULL);

            control_block->src_id = sat_file_change_ind->src_id;
            /* Retain msg_id */
            control_block->cnf_msg_id = ilm_ptr->msg_id;

            phb_is_sim_file_support();
        }
        phb_ptr->dn_type = l4csmu_get_dial_mode();

        if (need_reset_flag == KAL_FALSE)
        {
            phb_sat_file_change_confirm(PHB_ERRNO_SUCCESS, sat_file_change_ind->src_id, NULL);
        }
        else if ((phb_ptr->state == PHB_STATE_READY) ||
                 (phb_ptr->state == PHB_STATE_NOT_READY_FDN_READY) || (phb_ptr->state == PHB_STATE_NOT_READY))
        {
         /** 
          * Assume data descriptor obtained from nvram_get_infor() and
          * sim_service_table_query() remains consistent, DO NOT reset it.
          * What needs to be reset is their free_count!
          */
            phb_data_desc_reset();
            
            phb_se_reset();

            /* Reset context */
            kal_mem_set(&phb_ptr->ecc, 0, sizeof(sim_ecc_struct));
            phb_ptr->state = PHB_STATE_NOT_READY;
        #ifdef __PHB_USIM_SUPPORT__
            phb_ptr->is_global = KAL_TRUE;
        #endif
            kal_trace(TRACE_STATE, STATE_PHB_NOT_READY);

            // TODO: need to be able to reload specific files
            /*  
             *  Since SIM file changed, need to reload file info, and MMI also need to reload
             *  send begin inication to MMI, MMI will clear it's variable and reload phonebook.
             */
            {
            #if !defined(__PHB_STORAGE_BY_MMI__)
                kal_uint16 phb_total, phb_size;

                if (nvram_get_info(NVRAM_EF_PHB_LID, &phb_total, &phb_size) == NVRAM_ERRNO_SUCCESS)
                {
                    phb_data_desc_set_is_support(DATA_DESC_PHB, KAL_TRUE);

                /*
                 * MAX_ENTRIES_COUNT must NOT be exceeded. See comment
                 * of phb_get_info_set_value() for detail.
                 */
                    if (phb_total > NVRAM_PHB_INDEX_MAX_ENTRIES_COUNT)
                    {
                        phb_total = NVRAM_PHB_INDEX_MAX_ENTRIES_COUNT;
                    }
                    phb_data_desc_set(DATA_DESC_PHB, phb_total, phb_size);
                }
                else
            #endif /* __PHB_STORAGE_BY_MMI__ */
                {
                    phb_data_desc_set_is_support(DATA_DESC_PHB, KAL_FALSE);
                }
            }
            /* phb_get_info() will return to startup_handler() */
            control_block->proc_stage = startup_none;

        #if defined(__GEMINI__) || defined(GEMINI_PLUS)
            l4csmu_get_chv_info_status(NULL, &chv_status[phb_current_mod - MOD_PHB]);
            phb_query_count[phb_current_mod - MOD_PHB] = 0;
        #else
            l4csmu_get_chv_info_status(NULL, &chv_status[0]);
            phb_query_count[0] = 0;
        #endif
        
            phb_send_ilm(MOD_L4C, MSG_ID_L4CPHB_STARTUP_BEGIN_IND, NULL, NULL);
            
            phb_get_info(ilm_ptr, control_block);
            
        }
        /* error */
        else
        {
            kal_trace(TRACE_ERROR, ERROR_PHB_STATE);

            phb_sat_file_change_confirm(PHB_ERRNO_FAIL, control_block->src_id, control_block);
            return;
        }

    }
    else
    {
        kal_trace(TRACE_ERROR, ERROR_PHB_STATE);

        control_block->cnf_msg_id = MSG_ID_SAT_FILE_CHANGE_IND;
        phb_sat_file_change_confirm(PHB_ERRNO_FAIL, control_block->src_id, control_block);
        return;
    }
}   /* end of phb_sat_file_change_handler function */