yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | /***************************************************************************** |
| 2 | * Copyright Statement: |
| 3 | * -------------------- |
| 4 | * This software is protected by Copyright and the information contained |
| 5 | * herein is confidential. The software may not be copied and the information |
| 6 | * contained herein may not be used or disclosed except with the written |
| 7 | * permission of MediaTek Inc. (C) 2005 |
| 8 | * |
| 9 | * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 10 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 11 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON |
| 12 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 13 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 15 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 16 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 17 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH |
| 18 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO |
| 19 | * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S |
| 20 | * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM. |
| 21 | * |
| 22 | * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE |
| 23 | * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 24 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 25 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO |
| 26 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 27 | * |
| 28 | * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE |
| 29 | * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF |
| 30 | * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND |
| 31 | * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER |
| 32 | * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC). |
| 33 | * |
| 34 | *****************************************************************************/ |
| 35 | |
| 36 | /******************************************************************************* |
| 37 | * Filename: |
| 38 | * --------- |
| 39 | * phb_utils.h |
| 40 | * |
| 41 | * Project: |
| 42 | * -------- |
| 43 | * MT6208 |
| 44 | * |
| 45 | * Description: |
| 46 | * ------------ |
| 47 | * This file contains utility functions for PHB module. |
| 48 | * |
| 49 | * Author: |
| 50 | * ------- |
| 51 | * ------- |
| 52 | * |
| 53 | *============================================================================== |
| 54 | *******************************************************************************/ |
| 55 | #ifndef _PHB_UTILS_H |
| 56 | #define _PHB_UTILS_H |
| 57 | |
| 58 | #include "kal_general_types.h" |
| 59 | #include "ps_public_enum.h" |
| 60 | #include "kal_public_api.h" |
| 61 | #include "sim_ps_enum.h" |
| 62 | #include "phb_defs.h" |
| 63 | #include "l4c2phb_enums.h" |
| 64 | |
| 65 | #ifdef __cplusplus |
| 66 | extern "C" |
| 67 | { |
| 68 | #endif /* __cplusplus */ |
| 69 | |
| 70 | |
| 71 | /*#define PHB_TRACE(x,y) kal_trace y |
| 72 | */ |
| 73 | |
| 74 | #define PHB_UTILS_INVALID_VALUE ~0 |
| 75 | |
| 76 | #ifdef __TC10__ |
| 77 | #define MAX_KSC5601_NUM 12160 |
| 78 | #define KSC5601_PREFIX 0x81 |
| 79 | #endif |
| 80 | /** |
| 81 | * Number of bytes should be retained for SIM encoding: |
| 82 | * 1. 0x80: 1 byte coding, 2 bytes 0xFF. |
| 83 | * 2. 0x81: 1 byte coding, 1 byte length, 1 byte code page offset. |
| 84 | * 3. 0x82: 1 byte coding, 1 byte length, 2 bytes cod page. |
| 85 | * |
| 86 | * This constant could be used for allocating buffer when invoking phb_encode_to_sim() |
| 87 | * to enconde characters into SIM. |
| 88 | */ |
| 89 | #define SIM_ENCODE_MARGIN 4 |
| 90 | |
| 91 | typedef enum |
| 92 | { |
| 93 | shift_down, |
| 94 | shift_up |
| 95 | } shift_op_enum; |
| 96 | |
| 97 | /* The enumeration here uses values defined in 03.38 directly. */ |
| 98 | typedef enum |
| 99 | { |
| 100 | CHARSET_ASCII = 0x00, |
| 101 | CHARSET_KSC5601 = 0x05, |
| 102 | CHARSET_UCS2 = 0x08, |
| 103 | CHARSET_UCS2_81 = 0x09, /* Add for extra handle for UCS2 0x81 */ |
| 104 | CHARSET_UCS2_82 = 0x10 /* Add for extra handle for UCS2 0x82 */ |
| 105 | } istring_charset_enum; |
| 106 | |
| 107 | typedef struct |
| 108 | { |
| 109 | kal_uint8 length; |
| 110 | kal_uint8 charset; |
| 111 | kal_uint8 *data; |
| 112 | } istring_type; |
| 113 | |
| 114 | typedef enum |
| 115 | { |
| 116 | CODING_AUTO, |
| 117 | CODING_DEFAULT_7BITS, |
| 118 | CODING_UCS2_80 = 0x80, |
| 119 | CODING_UCS2_81 = 0x81, |
| 120 | CODING_UCS2_82 = 0x82 |
| 121 | } sim_alpha_id_coding_enum; |
| 122 | |
| 123 | /** |
| 124 | * Shall returns an integer greater than, equal to, or less than 0, according to `first' is |
| 125 | * greater than, equal to, or less than `second'. |
| 126 | */ |
| 127 | typedef int (*bin_search_cmp_func_type) (void *external_data, int external_pos, void *key); |
| 128 | |
| 129 | /* Generic array shift functions */ |
| 130 | extern void table_shift( |
| 131 | kal_uint16 *used_count, |
| 132 | kal_uint16 *slots, |
| 133 | void *array, |
| 134 | kal_uint16 element_size, |
| 135 | shift_op_enum op, |
| 136 | kal_uint16 from); |
| 137 | extern void table_range_shift( |
| 138 | kal_uint16 *used_count, |
| 139 | kal_uint16 *slots, |
| 140 | void *array, |
| 141 | kal_uint16 element_size, |
| 142 | shift_op_enum op, |
| 143 | kal_uint16 from, |
| 144 | kal_uint16 to); |
| 145 | |
| 146 | /* istring functions */ |
| 147 | #define phb_more_significant_char(x) (x >> 8 & 0xFF) |
| 148 | #define phb_less_significant_char(x) (x & 0xFF) |
| 149 | extern kal_uint8 istring_encode_to_sim( |
| 150 | sim_alpha_id_coding_enum coding, |
| 151 | istring_type *istr, |
| 152 | kal_uint8 buffer_len, |
| 153 | kal_uint8 *buffer); |
| 154 | extern kal_uint8 istring_decode_from_sim(kal_uint8 raw_data_len, kal_uint8 *raw_data, istring_type *decoded_str); |
| 155 | extern kal_uint8 istring_decode_0x81_to_0x80( |
| 156 | kal_uint8 raw_data_len, |
| 157 | kal_uint8 *raw_data, |
| 158 | istring_type *decoded_str); |
| 159 | extern kal_uint8 istring_decode_0x82_to_0x80( |
| 160 | kal_uint8 raw_data_len, |
| 161 | kal_uint8 *raw_data, |
| 162 | istring_type *decoded_str); |
| 163 | extern kal_uint8 istring_len(istring_type *istr); |
| 164 | extern kal_uint16 istring_char_at(istring_type *istr, kal_uint8 offset); |
| 165 | |
| 166 | extern kal_bool is_chars_equal(kal_uint16 char1, kal_uint16 char2); |
| 167 | extern kal_int32 compare_chars(kal_uint16 char1, kal_uint16 char2); |
| 168 | |
| 169 | /* BCD functions */ |
| 170 | #define phb_more_significant_nibble(x) (x >> 4 & 0x0F) |
| 171 | #define phb_less_significant_nibble(x) (x & 0x0F) |
| 172 | |
| 173 | extern kal_uint16 bcd2string(kal_uint8 length, kal_uint8 *tel_number, char *bcd_array); |
| 174 | extern kal_uint8 bcd2char(kal_uint8 bcd); |
| 175 | extern kal_uint16 get_next_bcd_digit( |
| 176 | kal_uint8 *bcd_array, |
| 177 | kal_uint16 offset, |
| 178 | kal_bool *is_first, |
| 179 | kal_uint8 *digit); |
| 180 | extern kal_int8 compare_n_string_bcd(char const *str, kal_uint8 *bcd_array, kal_uint16 len); |
| 181 | extern kal_int8 compare_n_bcd(kal_uint8 *first_bcd_array, kal_uint8 *second_bcd_array, kal_uint16 n); |
| 182 | extern kal_int8 compare_n_bcd_for_wild_char(kal_uint8 *first_bcd_array, kal_uint8 *second_bcd_array, kal_uint16 n); |
| 183 | extern kal_bool phb_compare_bcd_for_wild_char(kal_uint8 length1, kal_uint8 length2, kal_uint8 *bcd1, kal_uint8 *bcd2); |
| 184 | extern kal_int16 bcd_len(kal_uint8 *bcd_array, kal_uint16 n); |
| 185 | extern kal_int16 bcd_exact_len(kal_uint8 *bcd_array, kal_uint16 n); |
| 186 | |
| 187 | /* Check whether each byte of ptr are all 0x0F */ |
| 188 | extern kal_bool is_empty(kal_uint8 *ptr, kal_uint16 len); |
| 189 | |
| 190 | extern kal_uint32 phb_abs(kal_int32 val); |
| 191 | |
| 192 | extern int binary_search(void *collection[], int low, int high, void *key, bin_search_cmp_func_type compare_func); |
| 193 | |
| 194 | extern char *find_pinying_str_for_ucs2(kal_uint16 ucs2_code); |
| 195 | |
| 196 | extern kal_bool find_pinyin_str_for_ucs2_with_tone(kal_uint8 *inputString, kal_uint8 *outputString); |
| 197 | |
| 198 | extern kal_bool find_pinyin_str_for_ucs2_without_tone(kal_uint8 *inputString, kal_uint8 *outputString); |
| 199 | /* End MTK */ |
| 200 | |
| 201 | extern kal_bool phb_is_prefix(alpha_id_type *target, alpha_id_type *candidate); |
| 202 | |
| 203 | extern kal_uint8 phb_which_sim_ex(void); |
| 204 | extern phb_storage_enum phb_which_sim_storage(void); |
| 205 | extern kal_uint8 phb_util_is_usim(kal_uint8 sim_num); |
| 206 | extern phb_type_enum phb_util_get_type(kal_uint16 file_idx); |
| 207 | #ifdef __CDMA2000_RAT__ |
| 208 | extern kal_bool phb_util_is_csim(kal_uint8 sim_num); |
| 209 | extern kal_bool phb_util_is_cdma_card(void); |
| 210 | extern kal_bool phb_UIM_service_table_Query(kal_uint8 sst_id); |
| 211 | extern kal_bool phb_UIM_service_table_Query_by_ps_id(kal_uint8 sst_id, protocol_id_enum ps_id); |
| 212 | extern sim_dn_enum phb_UIM_get_dial_mode(void); |
| 213 | extern sim_dn_enum phb_UIM_get_dial_mode_by_ps_id(protocol_id_enum ps_id); |
| 214 | #endif |
| 215 | |
| 216 | kal_uint8 phb_map_sim(kal_uint8 sim); |
| 217 | |
| 218 | /* 03.38 encodes charset information into bit 3 and 2 */ |
| 219 | #define get_0338_charset_bits(x) (x & 0x1C) |
| 220 | |
| 221 | void phb_get_mcc_mnc_from_imsi(kal_uint8 *dest_ptr, kal_uint8 *imsi); |
| 222 | |
| 223 | #if defined(__CDMA2000_RAT__) |
| 224 | extern kal_bool phb_try_csim_fdn(sim_file_index_enum file_idx);//, kal_uint8 ctrl_block_id); |
| 225 | extern kal_bool phb_try_csim_fdn_by_ps_id(sim_file_index_enum file_idx, protocol_id_enum ps_id); |
| 226 | extern kal_bool phb_util_is_usim_csim(kal_uint8 sim_num); |
| 227 | #endif |
| 228 | |
| 229 | #ifdef __cplusplus |
| 230 | } |
| 231 | #endif |
| 232 | |
| 233 | #endif /* _PHB_UTILS_H */ |
| 234 | |