📄 atbcommon.c
字号:
/*******************************************************************************
CONDAT (UK)
********************************************************************************
This software product is the property of Condat (UK) Ltd and may not be
disclosed to any third party without the express permission of the owner.
********************************************************************************
$Project name:
$Project code:
$Module:
$File: ATBCommon.c
$Revision:
$Author: SH - Condat(UK)
$Date:
********************************************************************************
Description: ATB Common functions and definitions.
********************************************************************************
$History: ATBCommon.c
$End
*******************************************************************************/
/* includes */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#if defined (NEW_FRAME)
#include "typedefs.h"
#include "vsi.h"
#include "pei.h"
#include "custom.h"
#include "gsm.h"
#else
#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"
#endif
#include "mfw_mfw.h"
#include "mfw_win.h"
#include "mfw_kbd.h"
#include "mfw_tim.h"
#include "mfw_phb.h"
#include "mfw_sms.h"
#include "mfw_ss.h"
#include "mfw_icn.h"
#include "mfw_mnu.h"
#include "mfw_lng.h"
#include "mfw_sat.h"
#include "mfw_kbd.h"
#include "mfw_nm.h"
#include "mfw_cm.h"
#include "ATBCommon.h"
/*SPR2175, Added macro and tables for string conversion routines*/
#define MAX_STRING_LEN (5+MFW_NUM_LEN+MAX_MSG_LEN+4)
/*SPR 1508, changed codes 128, 129 and 130 to 129, 130, and 131 respectively.*/
static const char g_translation_ascii_table[128] = { 64, 156, 36, 157, 138, 131, 151, 141, 149, 129,
10, 2 , 7, 32, 143, 134, 4, 95, 232, 226, 239, 234, 227, 5, 228,
233, 240, 32, 146, 145, 225, 144, 32, 33, 34, 35, 1, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 173, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
85, 86, 87, 88, 89, 90, 142, 153, 165, 154, 168, 06, 97, 98, 99,
100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
115, 116, 117, 118, 119, 120, 121, 122, 132, 148, 164, 130, 133};
static const int g_translation_unicode[128] = { 0x0040, 0x00A3, 0x0024, 0x00A5, 0x00E8, 0x00E9, 0x00F9, 0x00EC, 0x00F2, 0x00C7, 0x000A, 0x00D8, 0x00F8,
0x000D, 0x00C5, 0x00E5, 0x0394, 0x005F, 0x03A6, 0x0393, 0x039B, 0x03A9, 0x03A0, 0x03A8, 0x03A3, 0x0398,
0x039E, 0x03A2, 0x00C6, 0x00E6, 0x00DF, 0x00C9, 0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 0x0025, 0x0026,
0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, 0x0031, 0x0032, 0x0033,
0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, 0x00A1,
0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D,
0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A,
0x00C4, 0x00D6, 0x00D1, 0x00DC, 0x00A7, 0x00BF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074,
0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00F1, 0x00FC, 0x00E0};
/*SPR 1508, added conversion table*/
static const int translation_ascii_2_unicode[256] = {
0x0000, 0x00A4, 0x00d8, 0xFFFF, 0x0394, 0x03A8, 0x00BF, 0x00F8, 0xFFFF, 0xFFFF, 0x000A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026,0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x0040,0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x005F,
0xFFFF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0x00C7, 0x00FC, 0x00E9, 0x00E4, 0x00E0, 0x00E5, 0xFFFF, 0xFFFF, 0xFFFF, 0x00E8, 0xFFFF, 0xFFFF, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0xFFFF, 0x00F6, 0x00F2, 0xFFFF, 0x00F9, 0xFFFF, 0x00D6, 0x00DC, 0xFFFF, 0x00A3, 0x00A5, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00F1, 0x00D1, 0xFFFF, 0xFFFF, 0x00A7, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x00A1, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
0xFFFF, 0x00DF, 0x0393, 0x03A0, 0x03A3, 0xFFFF, 0xFFFF, 0xFFFF, 0x03A6, 0x0398, 0x03A9, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x039B,
0x039E, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF
};
static char convertUCS2_2_ascii_char(char* ipString);
static char convertUCS2_2_gsm_char(char* ipString);
static USHORT ATB_swap_bytes(USHORT character);
/*******************************************************************************
$Function: convertUCS2_2_ascii_char
$Description: convert unicode char to ASCII char. Added for SPR 1508.
moved here for SPR 2175
$Returns: ASCII char
$Arguments: pointer to first byte of unicode char
*******************************************************************************/
static char convertUCS2_2_ascii_char(char* ipString)
{
U16 word_code;
BOOL match_found= FALSE;
int k;
char debug[60];
word_code = ipString[0]*0x100 + ipString[1];
sprintf(debug, "Word code: %d", word_code);
TRACE_EVENT(debug);
if (word_code <= 0xFF)
if (translation_ascii_2_unicode[word_code] == word_code)
return word_code;
for (k=0; k < 256; k++)
{ if(translation_ascii_2_unicode[k] == word_code)
{ sprintf(debug, "Match found: %d, %d", word_code, k);
TRACE_EVENT(debug);
match_found = TRUE;
return k;
}
}
if (!match_found)
{ TRACE_EVENT("No match");
return 0x3F;/*question mark*/
}
}
/*******************************************************************************
$Function: convertUCS2_2_ascii_char
$Description: convert unicode char to GSM char. Added for SPR 1508.
moved here for SPR 2175
$Returns: GSM char
$Arguments: pointer to first byte of unicode char
*******************************************************************************/
static char convertUCS2_2_gsm_char(char* ipString)
{
U16 word_code;
BOOL match_found= FALSE;
int k;
word_code = ipString[0]*0x100 + ipString[1];
if ( word_code > 0x7F || g_translation_unicode[word_code] != word_code)
{
for (k=0; k < 256; k++)
{ if(g_translation_unicode[k] == word_code)
{
match_found = TRUE;
return k;
}
}
}
else
return word_code;
if (!match_found)
{ return '?';
}
}
/*******************************************************************************
$Function: ATB_convert_String
$Description: Convert a string into an ascii string with 0x80 as first word if data is unicode
moved here and renamed for SPR 2175
$Returns: execution status
$Arguments: ipString - input byte array
ipDataType - type of input data
ipLength - length of input string (in bytes)
opString - output byte array
opDataType - type of output data
opLength - length of output string (in bytes)
*******************************************************************************/
/* MC, SPR 1257, merged in b-sample version of this function*/
int ATB_convert_String( char * ipString, UBYTE ipDataType, int ipLength,
char * opString, UBYTE opDataType, int opLength, UBYTE addNull)
{
int i;/*SPR 1946, changed from byte to int*/
int j;/*SPR 1946, changed from byte to int*/
/*JVJ SPR1298 Converted to dynamic variable */
UBYTE* text_8bit = NULL;/*SPR1991, don't alloacte this till it's needed*/
int len;/*SPR 1946, changed from byte to int*/
#ifdef TRACE_SMSREAD
char buf[150];
sprintf(buf, "opString%x ipString%x ipLength%d opLength%d",opString, ipString, ipLength, opLength);
TRACE_EVENT(buf);
#endif
if ((opString == NULL) || (ipString==NULL) || (opLength ==0))
return (FALSE);
if (ipLength>MAX_STRING_LEN)
{
TRACE_EVENT("Too long, returning.");
return;
}
opString[0] = 'X';
opString[1] = '?';
opString[2] = 0x00;
#ifdef TRACE_SMSREAD
sprintf(buf,"iDT: %d,iL:%d, oDT:%d, oL:%d, A0:%d",ipDataType,ipLength,opDataType,opLength,addNull);
TRACE_EVENT(buf);
#endif
switch (ipDataType)
{
case MFW_DCS_UCS2:
if (opDataType == MFW_DCS_UCS2)
{ //Copy array and add 0x80, 0x7F as first word
if (ipLength < opLength)
len = ipLength;
else
len = opLength;
/*SPR 1507, copy the bytes in pairs*/
for (i=0;i<len;i+=2)
{ opString[i] = ipString[i];
opString[i+1] = ipString[i+1];
}
if (i+1<opLength)
{
opString[i ] = 0x00;
opString[i+1] = 0x00;
}
}
else if ((opDataType == MFW_DCS_8bits) ||
(opDataType == MFW_ASCII))
{
if ((ipLength/2 ) < opLength)
len = ipLength/2;
else
len = opLength;
for (i=0;i<len;i++)
{ /*SPR 1508, use new functions to convert to ASCII/GSM*/
if (opDataType == MFW_ASCII)
opString[i] = convertUCS2_2_ascii_char(&ipString[i*2]);
else
opString[i] = convertUCS2_2_gsm_char(&ipString[i*2]);
}
if (len<opLength)
{
opString[len ] = 0x00;
}
}
else //Output data type is 7 bits - not implemented
{
}
break;
case MFW_DCS_8bits:
if (opDataType == MFW_DCS_UCS2)
{ //Convert data to unicode
if (ipLength*2 < opLength)
len = ipLength;
else
len = opLength/2;
#ifdef TRACE_SMSREAD
sprintf(buf, "8->UCS2, len:%d", len);
TRACE_EVENT(buf);
#endif
for (i = 0; i < len; i++)
{ /*SPR 1508 use table to convert to Unicode*/
opString[i*2] = (g_translation_unicode[ipString[i]]>>8)&0x00FF;
opString[i*2+1] = (g_translation_unicode[ipString[i]])&0x00FF;
}
if (len*2+1 < opLength)
{
opString[len*2] = 0x00;
opString[len*2+1] = 0x00;
}
}
else if (opDataType == MFW_DCS_8bits)
{ //Data already in correct format - copy
if (ipLength < opLength)
len = ipLength;
else
len = opLength;
for (i=0;i<len;i++)
opString[i] = ipString[i];
if (len<opLength)
opString[len] = 0x00;
}
else if (opDataType == MFW_ASCII) // SH - translate characters, don't change bit width
{
len = ipLength;
if (len > opLength)
len = opLength;
for (i=0;i<len;i++)
{
opString[i] = g_translation_ascii_table[ipString[i]];
#ifdef TRACE_SMSREAD
if (opString[i]!=ipString[i])
{
sprintf(buf, "Converted %x to %x (%c)", ipString[i], opString[i], (char)opString[i]);
TRACE_EVENT(buf);
}
#endif
}
if (len<opLength)
opString[len] = 0x00;
}
else // convert data to 7bit
{
len = utl_cvt8To7 ((UBYTE *)ipString , ipLength, (UBYTE*)opString, 0);
}
break;
case MFW_DCS_7bits:
default:
/*SPR 1991, allocate memory to conversion buffer*/
text_8bit = (UBYTE*)mfwAlloc(MAX_STRING_LEN+1);
if (opDataType == MFW_DCS_7bits) //text string is already in this format
{
//Data already in correct format - copy
if (ipLength < opLength)
len = ipLength;
else
len = opLength;
for (i=0;i<len;i++)
opString[i] = ipString[i];
if (len<opLength)
opString[len] = 0x00;
}
else if (opDataType == MFW_DCS_8bits)
{
len = utl_cvt7To8 ((UBYTE *)ipString , ipLength, (UBYTE *)opString, 0 );
if (len <opLength)
opString[len] = 0x00;
else
opString[opLength]=0x00;
}
else if (opDataType == MFW_ASCII) // SH - expand to 8 bit and convert chars
{
len = utl_cvt7To8 ((UBYTE *)ipString , ipLength, text_8bit, 0 );
if (len > opLength)
len = opLength;
for (i = 0; i < len; i++)
{
opString[i] = g_translation_ascii_table[UBYTEToChar(text_8bit[i])];
}
if (len <opLength)
opString[len] = 0x00;
}
else
{ //Convert to unicode
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -