📄 phb_utils.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_utils.c
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
* This files contains utility functions for PHB.
*
* 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!
*
* 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 "nvram_editor_data_item.h"
#include "custom_nvram_editor_data_item.h"
#include "phb_utils.h"
#include "phb_defs.h"
#ifdef __PHB_RECORD_LN_TYPE_SEQ__
#include "l4c2phb_enums.h"
#endif
#if defined(__PINYIN_SORTING_ZI__)
#include "zi8api.h"
#elif defined(__PINYIN_SORTING_KA__)
extern const signed char *GetPYString(unsigned char *HZ);
#endif
#ifdef __PHB_RECORD_LN_TYPE_SEQ__
extern kal_uint8 phb_ln_type_seq[PHB_TOTAL_LN_ENTRIES];
#endif
#undef _FILE_CODE_
#define _FILE_CODE_ _PHB_UTILS_C_
/*****************************************************************************
* FUNCTION
* table_shift
* DESCRIPTION
* A generic shift function that shifts content of an array by one slot.
* PARAMETERS
* used_count [IN/OUT] Used count of the array
* slots [IN/OUT] Total slots of the array
* array [IN] The array to be shifted
* element_size [IN] Size of each element in `array'
* op [IN] Shift down or up
* from [IN] `from', while for shift-up, shift each slot up from `from'.
* RETURNS
* KAL_TRUE if success, KAL_FALSE else.(?)
*****************************************************************************/
void table_shift(
kal_uint16 *used_count,
kal_uint16 *slots,
void *array,
kal_uint16 element_size,
shift_op_enum op,
kal_uint16 from)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 *table = (kal_uint8*) array;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ASSERT(array != NULL);
/* shift down */
/**
* [] [] [] ... []
* from -> -> -> used_count
*/
if (op == shift_down)
{
kal_uint16 i;
if ((from >= *used_count) || (*used_count >= *slots))
{
return;
}
for (i = *used_count; (i > from); --i)
{
kal_mem_cpy(table + (i * element_size), (void const*)(table + ((i - 1) * element_size)), element_size);
}
}
/* shift up */
/**
* [] [] [] ... []
* (from - 1) <- from <- <- (used_count - 1)
*/
else
{
kal_uint16 i;
if ((from >= *used_count) || (*used_count < 1))
{
return;
}
for (i = from - 1; i < (*used_count - 1); ++i)
{
kal_mem_cpy(table + (i * element_size), (void const*)(table + (i + 1) * element_size), element_size);
}
}
} /* end of table_shift */
/*****************************************************************************
* FUNCTION
* table_range_shift
* DESCRIPTION
* A generic shift function that shifts some elements of an array by one slot.
* PARAMETERS
* used_count [IN/OUT] Used count of the array
* slots [IN/OUT] Total slots of the array
* array [IN] The array to be shifted
* element_size [IN] Size of each element in `array'
* op [IN] Shift down or up
* from [IN] Ranges to shift
* to [IN] Ranges to shift
* RETURNS
* KAL_TRUE if success, KAL_FALSE else.(?)
*****************************************************************************/
void table_range_shift(
kal_uint16 *used_count,
kal_uint16 *slots,
void *array,
kal_uint16 element_size,
shift_op_enum op,
kal_uint16 from,
kal_uint16 to)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 *table = (kal_uint8*) array;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ASSERT(array != NULL);
/* shift down */
if (op == shift_down)
{
kal_uint16 i;
for (i = to + 1; (i > from) && (i >= 1) && (i < *used_count) && (i < *slots); --i)
{
if (i >= (*slots - 1))
{
continue;
}
else
{
kal_mem_cpy(table + (i * element_size), (void const*)(table + (i - 1) * element_size), element_size);
}
}
}
/* shift up */
else
{
kal_uint16 i;
for (i = from - 1; (i < to) &&
// amanda remove
// (i >= 1) &&
(i < *used_count) && (i < *slots); ++i)
{
if (i >= (*slots - 1))
{
continue;
}
else
{
kal_mem_cpy(table + (i * element_size), (void const*)(table + (i + 1) * element_size), element_size);
}
}
}
} /* end of table_range_shift */
/*****************************************************************************
* FUNCTION
* istring_encode_to_sim
* DESCRIPTION
* Encode input `istr' string to the format of alpha id stored in SIM
* (see 3GPP TS 11.11 SIM-ME interface Annex B) into buffer with byte size of
* `buffer_len'.
*
* Currently, only CODING_AUTO is supported.
*
* This function assumes caller ensures the correctness of raw content stored in `istr', thus
* this function behaves in a best-effort manner. Ie, it encodes each character in `istr'
* one by one; once an error is encountered, returns 0. However, the returned `buffer'
* may not be correct.
* PARAMETERS
* coding [IN] Will be DEFAULT_7BITS or CODING_UCS2_80.
* istr [IN] The input istring
* buffer_len [IN] Byte size of buffer
* buffer [OUT] Where decoded bytes are stored.
* RETURNS
* Number of bytes encoded into buffer
*****************************************************************************/
kal_uint8 istring_encode_to_sim(
sim_alpha_id_coding_enum coding,
istring_type *istr,
kal_uint8 buffer_len,
kal_uint8 *buffer)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 count;
kal_uint8 buf_offset = 0;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ASSERT(istr != NULL);
if (get_0338_charset_bits(istr->charset) == CHARSET_ASCII)
{
kal_uint16 ch;
for (count = 0; count < istring_len(istr); ++count)
{
ch = istring_char_at(istr, count);
/* The character doesn't conform to ASCII charset */
if (ch >= 0x80)
{
return 0;
}
/* Exceeds capacity */
if (buf_offset >= buffer_len)
{
break;
}
buffer[buf_offset++] = (kal_uint8) ch;
}
/* Complement all reset bytes to 0xF */
for (; buf_offset < buffer_len; ++buf_offset)
{
buffer[buf_offset] = (kal_uint8) PHB_UTILS_INVALID_VALUE;
}
return count;
}
#ifdef __PHB_0x81_SUPPORT__ /* support maximum length of 0x81 UCS2 */
/* Handle 0x81 case first */
else if (istr->charset == CHARSET_UCS2_81 || istr->charset == CHARSET_UCS2_82)
{
for (count = 0; count < istr->length; ++count)
{
/* Exceeds capacity */
if ((buf_offset + 1) > (buffer_len))
{
break;
}
buffer[buf_offset++] = istr->data[count];
}
/* Complement all rest of bytes to 0xF */
for (; buf_offset < buffer_len; ++buf_offset)
{
buffer[buf_offset] = (kal_uint8) PHB_UTILS_INVALID_VALUE;
}
if (istr->charset == CHARSET_UCS2_81)
{
buffer[1] = count - 3; /* correct the data string size of 0x81 */
}
else
{
buffer[1] = count - 4; /* correct the data string size of 0x82 */
}
return count;
}
#endif /* __PHB_0x81_SUPPORT__ */
else if (get_0338_charset_bits(istr->charset) == CHARSET_UCS2)
{
kal_uint16 ch;
buffer[buf_offset++] = CODING_UCS2_80;
if (buffer_len % 2 == 0)
{
buffer_len--;
buffer[buffer_len] = (kal_uint8) PHB_UTILS_INVALID_VALUE;
}
for (count = 0; count < istring_len(istr); ++count)
{
ch = istring_char_at(istr, count);
/* Exceeds capacity */
if ((buf_offset + 1) > (buffer_len - 1))
{
break;
}
buffer[buf_offset++] = (ch >> 8) & 0xFF;
buffer[buf_offset++] = ch & 0xFF;
}
/* Complement all rest of bytes to 0xF */
for (; buf_offset < buffer_len; ++buf_offset)
{
buffer[buf_offset] = (kal_uint8) PHB_UTILS_INVALID_VALUE;
}
return count;
}
else
{
return 0;
}
} /* istring_encode_to_sim */
/*****************************************************************************
* FUNCTION
* istring_decode_from_sim
* DESCRIPTION
* Decode raw data of alpha id stored in SIM (see 3GPP TS 11.11 SIM-ME interface Annex B)
* into a `istring'.
*
* This function behaves in a best-effort manner. Ie, it decodes each byte in
* `raw_data' one by one; once an error is encountered, returns 0.
* Since this is a decode function, caller can assume the returned `istring' is always
* correct, though it could be truncated.
*
* NOTE: Passed in istring->length must be set to the length of buffer being decoded.
* Before this function is returned, it will be filled with 0xFF for unused bytes.
* PARAMETERS
* raw_data_len [IN] Length of raw data
* raw_data [IN] Raw data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -