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

📄 phb_handler_approve.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 4 页
字号:
        phb_entry_struct *candidate_entry = (phb_entry_struct*) control_block->data;
        l4_addr_bcd_struct *candidate_pattern = &candidate_entry->tel_number;

        /* It's approving FDN now */
        if (control_block->proc_stage == APPROVE_FDN_ONE_CHARACTER)
        {
            if (!((given->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET] !=
                 candidate_pattern->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET]) &&
                !(given->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET] == 0x81 &&
                  candidate_pattern->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET] == 0xa1)))
            {
                ++control_block->actual_count;

                /* Give control back to controller */
                (*control_block->controller) (NULL, control_block);
                return;
            }
            /* Verification complete, finally control can be returned back to controller */
            if (!phb_se_is_next_also_candidate(
                    (name_num_index_type*) control_block->candidate_name_num_index,
                    control_block->candidate,
                    KAL_FALSE))
            {
                kal_bool is_more_candidates;
                name_num_index_type *name_num_index;
                data_entry_struct *data_entry;
                control_block->candidate_name_num_index = phb_se_search_by_tel_num(control_block->type, given, &control_block->candidate, &is_more_candidates);
                control_block->proc_stage = APPROVE_FDN;

                /* No candidates. Great! */
                if ((control_block->candidate == (kal_uint16) PHB_INVALID_VALUE) ||
                    (control_block->candidate_name_num_index == NULL))
                {
                    control_block->actual_count = 0;

                 /**
                  * Since this entry is not approved by FDN under
                  * FDN enabled condition, it is uncessary to search into PHB_PHONEBOOK
                  * for retrieving the entry that matches this phone number.
                  */
                    phb_approve_confirm(PHB_ERRNO_FAIL, control_block->type, control_block->src_id, control_block, NULL);
                    return;
                }
                /* Read specific record for verification. */
                phb_control_block_set_IO(control_block, control_block->type, (kal_uint16) PHB_INVALID_VALUE, 1);
                /* set storage, record_index, primary_ID, and secondary_ID */
                name_num_index = (name_num_index_type*) control_block->candidate_name_num_index;
                data_entry =
                    &name_num_index->data_entry_table.table[name_num_index->num_index.table[control_block->candidate].position];

                phb_se_set_control_block(
                    control_block,
                    OP_READ,
                    (phb_storage_enum) data_entry->storage,
                    data_entry->record_index);

                /**
                 * Since phb_se_set_control_block() modifies control_block->proc_stage,
                 * it has to be restored.
                 */
                control_block->proc_stage = APPROVE_FDN;

                control_block->data = (kal_uint8*) & control_block->temp_entry;
                phb_issue_IO_read(control_block);
                return;
            }

         /**
          * This iteration is not approved. Still others to verify.
          * Since index, total is in ensured to be in range, tested in handler(), it is uncessary
          * to test it here.
          */
            else
            {
                name_num_index_type *name_num_index;
                data_entry_struct *data_entry;

                /* Set index field of next entry to read */
                control_block->index = ++control_block->candidate;

            /**
             * Read specific record for verification.
             */
                phb_control_block_set_IO(control_block, control_block->type, (kal_uint16) PHB_INVALID_VALUE, 1);

                /* set storage, record_index, primary_ID, and secondary_ID */
                name_num_index = (name_num_index_type*) control_block->candidate_name_num_index;
                data_entry =
                    &name_num_index->data_entry_table.table[name_num_index->num_index.table[control_block->candidate].
                                                            position];

                if (phb_se_set_control_block(
                        control_block,
                        OP_READ,
                        (phb_storage_enum) data_entry->storage,
                        data_entry->record_index) == KAL_FALSE)
                {
                    phb_approve_err_handler(NULL, control_block);
                    return;
                }

                control_block->proc_stage = APPROVE_FDN_ONE_CHARACTER;
                control_block->data = (kal_uint8*) & control_block->temp_entry;
                control_block->length = phb_data_desc_get_record_size(phb_data_desc_get_desc_by_ID(control_block->primary_ID));

                phb_issue_IO_read(control_block);
                return;
            }
        }
        else if (control_block->proc_stage == APPROVE_FDN)
        {
            /* Finally, Approved by FDN!! */
            if (phb_compare_tel_number_prefix(given, candidate_pattern) == KAL_TRUE)
            {
                ++control_block->actual_count;

                /* Give control back to controller */
                (*control_block->controller) (NULL, control_block);
                return;
            }

            /* *Sigh*, Continue verification. */

            /* Verification complete, finally control can be returned back to controller */
            if (!phb_se_is_next_also_candidate(
                    (name_num_index_type*) control_block->candidate_name_num_index,
                    control_block->candidate,
                    KAL_FALSE))
            {
                (*control_block->controller) (NULL, control_block);
            }

         /**
          * This iteration is not approved. Still others to verify.
          * Since index, total is in ensured to be in range, tested in handler(), it is uncessary
          * to test it here.
          */
            else
            {
                name_num_index_type *name_num_index;
                data_entry_struct *data_entry;

                /* Set index field of next entry to read */
                control_block->index = ++control_block->candidate;

            /**
             * Read specific record for verification.
             */
                phb_control_block_set_IO(control_block, control_block->type, (kal_uint16) PHB_INVALID_VALUE, 1);

                /* set storage, record_index, primary_ID, and secondary_ID */
                name_num_index = (name_num_index_type*) control_block->candidate_name_num_index;
                data_entry =
                    &name_num_index->data_entry_table.table[name_num_index->num_index.table[control_block->candidate].
                                                            position];

                if (phb_se_set_control_block(
                        control_block,
                        OP_READ,
                        (phb_storage_enum) data_entry->storage,
                        data_entry->record_index) == KAL_FALSE)
                {
                    phb_approve_err_handler(NULL, control_block);
                    return;
                }

                control_block->proc_stage = APPROVE_FDN;
                control_block->data = (kal_uint8*) & control_block->temp_entry;
                control_block->length = phb_data_desc_get_record_size(phb_data_desc_get_desc_by_ID(control_block->primary_ID));

                phb_issue_IO_read(control_block);
                return;
            }
        }
        /* Abnormal: state error */
        else
        {
            phb_approve_err_handler(NULL, control_block);
            return;
        }
    }
}   /* end of phb_approve_continue */


/*****************************************************************************
 * FUNCTION
 *  phb_approve_confirm
 * DESCRIPTION
 *  This is phb_approve_confirm function of PHB module.
 * PARAMETERS
 *  result                          [IN]        
 *  type                            [IN]        
 *  src_id                          [IN]        
 *  control_block                   [?]         
 *  phb_entry_weird_approved        [?]         
 *  ilm_ptr(?)                      [IN]        The primitives
 * RETURNS
 *  void
 *****************************************************************************/
static void phb_approve_confirm(
                phb_errno_enum result,
                phb_type_enum type,
                kal_uint8 src_id,
                control_block_type *control_block,
                phb_entry_struct *phb_entry_weird_approved)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    local_para_struct *local_param_ptr = NULL;
    peer_buff_struct *peer_buf_ptr = NULL;

    l4cphb_approve_cnf_struct *l4cphb_approve_cnf;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_trace(TRACE_FUNC, FUNC_PHB_APPROVE_CNF, result, type, src_id);

    l4cphb_approve_cnf = (l4cphb_approve_cnf_struct*) construct_local_para(sizeof(l4cphb_approve_cnf_struct), TD_CTRL);
    l4cphb_approve_cnf->type = type;
    l4cphb_approve_cnf->src_id = src_id;

    local_param_ptr = (local_para_struct*) l4cphb_approve_cnf;

    /* If result is PHB_ERRNO_BUSY, reject newly received request */
    l4cphb_approve_cnf->result = result;

    /* Confirm to in-processing operation */
    if (result != PHB_ERRNO_BUSY)
    {
        if (control_block != NULL)
        {
            /* Field 'cause' is meaningful when I/O occured by using control blocks */
            l4cphb_approve_cnf->cause = control_block->cause;

            /* First we release local parameter. */
            if (control_block->local_param_ptr != NULL)
            {
                free_ctrl_buffer(control_block->local_param_ptr);
            }

            /* A hit is stored in temp_entry, it must be packed into peer buffer */
            if ((result == PHB_ERRNO_SUCCESS) && (control_block->actual_count > 0))
            {
                phb_entry_struct *phb_entry = &control_block->temp_entry;
                l4cphb_phb_entry_array_struct *phb_entry_array;

                phb_entry_array =
                    (l4cphb_phb_entry_array_struct*) l4cphb_alloc_peer_buf(&peer_buf_ptr, control_block->total);
                phb_entry_array->no_array = control_block->actual_count;
                kal_mem_cpy(&phb_entry_array->array[0], (void const*)phb_entry, sizeof(phb_entry_struct));
                control_block->peer_buf_ptr = NULL;
            }

            phb_free_control_block(control_block);
        }

        /* Only approval when PHB is not ready should reach here. */
        else if (phb_entry_weird_approved != NULL)
        {
            /* A hit is passed from phb_entry */
            if (result == PHB_ERRNO_SUCCESS)
            {
                l4cphb_phb_entry_array_struct *phb_entry_array;

                phb_entry_array = (l4cphb_phb_entry_array_struct*) l4cphb_alloc_peer_buf(&peer_buf_ptr, 1);
                phb_entry_array->no_array = 1;
                kal_mem_cpy(
                    &phb_entry_array->array[0],
                    (void const*)phb_entry_weird_approved,
                    sizeof(phb_entry_struct));
            }
        }
    }

    phb_send_ilm(MOD_L4C, MSG_ID_L4CPHB_APPROVE_CNF, local_param_ptr, peer_buf_ptr);
}   /* end of phb_approve_confirm */


/*****************************************************************************
 * FUNCTION
 *  phb_compare_tel_number_prefix
 * DESCRIPTION
 *  This is phb_compare_tel_number_prefix function of PHB module.
 *  Try prefix matching `given' to `candidate'.
 *  
 *  Algorightm:
 * PARAMETERS
 *  given           [?]         
 *  candidate       [?]         
 *  ilm_ptr(?)      [IN]        The primitives
 * RETURNS
 *  void
 *****************************************************************************/
static kal_bool phb_compare_tel_number_prefix(l4_addr_bcd_struct *given, l4_addr_bcd_struct *candidate)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 len;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* Recover the wrong length from SIM */
    //if (candidate->addr_bcd[candidate->addr_length - 1] == 0xff)
    //    candidate->addr_length--;
    candidate->addr_length = (bcd_exact_len((kal_uint8*)candidate->addr_bcd, candidate->addr_length)+1)/2;
   /**
    * Since attempting phone number is only allowed to be extended from
    * an FDN entry, if attempting phone number is shorter than candidate,
    * then it must not be an extension of candidate.
    */
    if (given->addr_length < candidate->addr_length)
    {
        return KAL_FALSE;
    }

    /* First, compare TON/NPI. If requested TON is 000, 010(national call) is allowed */
    if ((given->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET] !=
         candidate->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET]) &&
        !(given->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET] == 0x81 &&
          candidate->addr_bcd[L4_ADDR_BCD_TON_NPI_OFFSET] == 0xa1))
    {
        return KAL_FALSE;
    }

    len = bcd_len(
            &candidate->addr_bcd[L4_ADDR_BCD_TEL_NUM_OFFSET],
            (kal_uint16) (candidate->addr_length - L4_ADDR_BCD_TON_NPI_SIZE));

    /* Next, compare digits */
    /* Currently, PERFECT MATCHING is implemented, no wildcard supported */
    if (compare_n_bcd(
            &candidate->addr_bcd[L4_ADDR_BCD_TEL_NUM_OFFSET],
            &given->addr_bcd[L4_ADDR_BCD_TEL_NUM_OFFSET],
            len) == 0)
    {
        return KAL_TRUE;
    }

    return KAL_FALSE;
}   /* end of phb_compare_tel_number_prefix */

⌨️ 快捷键说明

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