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

📄 mfw_sms.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
+--------------------------------------------------------------------+
| PROJECT: MMI-Framework (8417)         $Workfile:: mfw_sms.c       $|
| $Author: zkc $Revision: 1.3 $|
| CREATED: 21.12.98                     $Modtime:: 24.03.00 10:25   $|
| STATE  : code                                                      |
+--------------------------------------------------------------------+

   MODULE  : MFW_SMS

   PURPOSE : This module contains SMS management functions.

   SPR 2260:  Merged in bugfixes 1833, 1669, 872,1830, 1828, 2031, and 2007 
   fom the 1.6.3 branch into this file.

*/

#define ENTITY_MFW

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#if defined (NEW_FRAME)

#include "typedefs.h"
#include "vsi.h"
#include "custom.h"
#include "gsm.h"

#else

#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"

#endif

#include "cus_aci.h"
#include "message.h"
#include "prim.h"
#include "aci_cmh.h"
#include "ksd.h"
#include "p_sim.h"
#include "pcm.h"
#include "P_MNSMS.val"

#include "psa.h"
#include "psa_sim.h"

#include "mfw_mfw.h"
#include "mfw_nm.h"
#include "mfw_sima.h"
#include "mfw_nmi.h"
#include "mfw_phb.h"
#include "mfw_cm.h"
#include "mfw_cmi.h"
#include "mfw_sim.h"
#include "mfw_simi.h"
#include "mfw_phbi.h"
#include "mfw_sms.h"
#include "mfw_smsi.h"
#include "mfw_win.h"
#include "mfw_cphs.h"
#include "mfw_cphsi.h"
#include "aci_lst.h"
#include "conc_sms.h"


#ifdef SIM_TOOLKIT
#include "mfw_sat.h"
#endif

#include <string.h>
#include <stdio.h>

/* robert.chen add, 2004-08-10, integrated MMS module */
#if _MMS_ENABLE_	
#include "mmiutilapi.h"
#include "ffs.h"

#define _PUSH_DETECT_ENABLE_  1
#endif




/********* current define *******************************************/
/*SPR 2260 added definitions*/
/* glowing,2004-06-11, import from TCS2112 */
#define FIRST_READ_OF_MEMORY_USE 1
#define POST_DELETE_CHECK        2
/* glowing,2004-06-11, end of import */
static T_MFW_SMS_MSG msg_info[MAX_MESSAGES]; /* message table */

static T_MFW_SMS_MO sms_mo;
static T_MFW_SMS_MT sms_mt;
static T_MFW_SMS_CB sms_cb;
static T_MFW_SMS_ID sms_id, sms_id_wait;

/* glowing,2004-06-12,modify */
//static T_MFW_MEM_INFO     memory;
T_MFW_MEM_INFO     memory;
/*glowing,2004-06-12, end of modify */

static SHORT              first_id;
static SHORT              flag;
static SHORT			 status_change_index;
static SHORT			 deleting_index;
static SHORT			 storage_index;
static SHORT              mt_flag;
static UBYTE              f_update;
static UBYTE              int_req;
static UBYTE              smsReady;
static UBYTE              phbReady;
static UBYTE              sentStatus;
static UBYTE              sms_update = FALSE;

static UBYTE              coll_sms_send;   /* mt sms during send process */
static UBYTE              coll_sms_read;   /* mt sms during read process */
static UBYTE              coll_sms_delete; /* mt sms during delete process */
static UBYTE              coll_sms_req;    /* mt sms during request process */

static UBYTE              data[30];

static UBYTE			initialising_flag;

UBYTE     sms_type;
UBYTE     mt_type;
UBYTE     int_init_req;
CHAR     *wr_addr;
UBYTE Delete_1_2_1_vm_icon=FALSE;
UBYTE Display_1_2_1_vm_icon =FALSE;
static UBYTE     cb_mid[10];  /* cell broadcast message identifier */
static UBYTE     fg;
EXTERN MfwHdr * current_mfw_elem;

static BOOL cmgr_awaiting_ok = FALSE; // Marcus: Issue 2260: 03/10/2002
/*********************Prototypes****************************************/

/*SPR2260 added prototype for new function*/
BOOL delete_sms_from_table (SHORT index); //glowing,2004-06-11, import from TCS2112

/* robert.chen add, 2004-08-10, integrated MMS module */
#if (_PUSH_DETECT_ENABLE_ == 1)

	#define MAX_MMS_SI		6
	#define MAX_SEG_NUM		5
	#define MAX_DEL_STORE	20

	#define MERGE_STA_CONTINUE		0
	#define MERGE_STA_COMPLETE		1
	#define MERGE_STA_ERROR			2

typedef struct pushSeg
{
	UBYTE   seq;	/* sequence number */
	UBYTE   idx;	/* index in memory storage */
	UBYTE   len;	/* length of the segment */
	UBYTE   *data;	/* pointer to seg data buffer */
	struct pushSeg *next;
} T_PUSH_SEG;

typedef struct pushSegBug
{
	UBYTE   fuse;		/* occupying flag */
	UBYTE   idx_num;    
	UBYTE   mem_idx[MAX_SEG_NUM];
	//	UBYTE	seg_seq[MAX_SEG_NUM];
	USHORT  ref_num;	/* reference number of the segments */
	T_PUSH_SEG *list;	/* segments list of the same reference number */
} T_PUSH_SEGBUF;

typedef struct pushMergeBuf
{
	UBYTE   fuse;		/* occupying flag */
	UBYTE   next_seg;	/* number of next seg to be added to data buffer */
	UBYTE   total;		/* total nuber of segs */
	UBYTE   left;		/* number of left segs to be assembly */
	USHORT  ref_num;	/* ref number of the segs */
	USHORT  len;		/* length of concatenated seg data */
	UBYTE   *data;		/* concatenated seg data */
} T_PUSH_MERGE;

typedef struct delStore
{
	UBYTE   rd;
	UBYTE   wr;
	UBYTE   mem_idx[MAX_DEL_STORE]; 
	MfwHnd  t_post;		/* timer for deleting SMS carrying PUSH PDU in background */
} T_DEL_STORE;

	#define PUSH_DET_TRACE(msg) MI_dbgPrintf msg

/* if a specific IE included in the SMS UDH */
UBYTE* is_ie_include(UBYTE iei, UBYTE *udh, UBYTE udh_len);

/* if a SMS carrying WAP PUSH message */
UBYTE* is_push(UBYTE *udh, UBYTE udh_len);

/* when a WAP PUSH message detected, remove the port addressing IE from UDH */
UBYTE  udh_adjust(UBYTE index, T_ACI_CMGL_SM *sm);

/* route PUSH PDU to destination application, at present only MMS agent available */
UBYTE*  push_appli_dispatch(UBYTE *data, USHORT* retLen, USHORT len);

/* notice the MMS application a MMS PDU from PUSH incoming */
UBYTE  MMS_SI_ind(UBYTE *data, USHORT len, UBYTE index);

/* get a existing entry for SMS concatenating in process */
T_PUSH_MERGE *push_mbuf_getSlot(USHORT ref_num);

/* get a new merge entry for a new concatenation */
T_PUSH_MERGE *push_mbuf_getNewSlot(USHORT ref_num, UBYTE max_num);

/* add a piece of concatenated SMS data to concatenating data block */
T_PUSH_MERGE *push_mbuf_addData(USHORT ref_num, UBYTE max_num, UBYTE len, UBYTE * data);

/* clear a merge buffer entry */
void push_mbuf_clear(T_PUSH_MERGE *mergeBuf_slot, UBYTE startup, UBYTE idx);

/* get a existing segment buffer entry identified by reference number */
T_PUSH_SEGBUF *push_sbuf_getSlot(USHORT ref_num);

/* allocate and init a new segment buffer entry */
T_PUSH_SEGBUF *push_sbuf_getNewSlot(USHORT ref_num);

/* add a SMS segments to the segment entry identified by reference number */
UBYTE push_sbuf_addSeg(USHORT ref_num, UBYTE seq_num, UBYTE mem_idx, UBYTE len, UBYTE * data);

/* remove the SMS segment specified by reference number and sequence number from segments list */
T_PUSH_SEG *push_sbuf_removeSeg(USHORT ref_num, UBYTE seq_num);

/* clear a segments buffer entry */
void push_sbuf_clear(T_PUSH_SEGBUF *segbuf_slot, UBYTE startup, UBYTE idx);

/* init data for push detection */
void push_init(void);

/* merge segmented SMS to a PUSH PDU */
UBYTE  push_merge_sms(T_ACI_CMGL_SM *sm, T_PUSH_MERGE **idx);

/* timer callback for delete PUSH SMS in background */
int push_sms_del_timCB(MfwEvt e, MfwHnd h);

/* add one or more index to delete waiting list (ring buffer) */ 
void push_delLst_add(UBYTE* idx, UBYTE len);

/* remove the first index from delete waiting list */
void push_delLst_remove(void);

/* get current index to be delete from waiting list */
UBYTE push_delLst_get(void);

#endif

#if (_PUSH_DETECT_ENABLE_ == 1)

/* buffer array for segmented SMS concatenation */
T_PUSH_MERGE    pMergeBuf[MAX_MMS_SI];  

/* buffer array for uncontinuous SMS segments */
T_PUSH_SEGBUF   pSegBuf[MAX_MMS_SI];

/* the array carrying SMS that should be delete after PUSH PDU merge */
T_DEL_STORE pushDelList;    

/****
* Check if a specific IE is included in UDH, if found return 
* the pointer to the IE position in UDH, otherwise return NULL
*/
UBYTE* is_ie_include(UBYTE iei, UBYTE * udh, UBYTE udh_len)
{
	UBYTE len;
	UBYTE *p_udh;

	PUSH_DET_TRACE(("is_ie_include():iei=%d, udh=%d", iei, (UINT32)udh));
	p_udh   = udh;

	if (udh_len == 0)
		return NULL;	/* normal SM */

	
	while ((UINT32)p_udh < (UINT32)(udh + udh_len))	/* searching */
	{
		PUSH_DET_TRACE(("is_ie_include():searching ie..."));
		if (*p_udh == iei)
		{
			PUSH_DET_TRACE(("is_ie_include():iei=%d included!", iei));
			return p_udh;
		}
		else
		{
			len = *(p_udh+1);
			p_udh += len + 2;
			PUSH_DET_TRACE(("is_ie_include():next, udh=%d", (UINT32)p_udh));
		}
	}

	PUSH_DET_TRACE(("is_ie_include():NO"));
	return NULL;
}

/****
* Check the UDH to see if a SMS is a WAP PUSH message, if so, return 
* a pointer to the position in UDH where the IE located, otherwise 
* return NULL.
*/
UBYTE* is_push(UBYTE *udh, UBYTE udh_len)
{
	USHORT srcPort, desPort;
	UBYTE  *pIE;

	PUSH_DET_TRACE(("is_push():udh_len=%d", udh_len));

	if ((pIE = is_ie_include(0x05, udh, udh_len)) != NULL)
	{
		//16 bit application port addressing scheme
		desPort = (*(pIE+2)<<8) | (*(pIE+3));
		srcPort = (*(pIE+4)<<8) | (*(pIE+5));
		PUSH_DET_TRACE(("is_push():dP=%d,sP=%d", desPort, srcPort));

		if (desPort == 0x0b84 && srcPort == 0x23f0)	//0x0b80 is push port
		{
			PUSH_DET_TRACE(("is_push():YES"));
			return pIE;
		}
	}

	return NULL;
}

/****
* Check if the SMS carrying WAP PUSH PDU, if yes, adjust the UDH header by
* removing the port addressing IE for following SMS concatenation process
* if need, and return 1 indicating the SMS is a WAP PUSH PDU, otherwise 
* the SMS will be remained as the original and return 0.
* refer to GSM 03.40 for detail of UDH structure.
*/
UBYTE udh_adjust(UBYTE index, T_ACI_CMGL_SM * sm)
{
	UBYTE *pIE, *concIE;
	UBYTE ie_len;
	UBYTE i;

	PUSH_DET_TRACE(("udh_adjust():idx=%d, uL=%d", index, sm->udh.len));

	if (sm->udh.len == 0)
		return 0;	// no adjust

	pIE = sm->udh.data;
	//PUSH_DET_TRACE(("udh_adjust():u0=%d, u1=%d, u2=%d, u3=%d, u4=%d, u5=%d, u6=%d", *pIE++,*pIE++,*pIE++,*pIE++,*pIE++,*pIE++,*pIE++));

	if ((pIE = is_push(sm->udh.data, sm->udh.len)) != NULL)
	{
		// it is a SMS carrying push information, we adjust the udh so that MFW can do concatenate if need
		ie_len = *(pIE+1) +2;	//total IE len including IEI and IE length field
		sm->udh.len -= ie_len;	// calculate left udh length

		// adjust udh data buffer to remove port addressing IE
		for (i = 0; i < sm->udh.len; i ++)
		{
			sm->udh.data[i] = sm->udh.data[i + ie_len];
		}

		pIE = sm->udh.data;
		//PUSH_DET_TRACE(("udh_adjust():finish!uL=%d, u0=%d,u1=%d,u2=%d,u3=%d,u4=%d,u5=%d,u6=%d", sm->udh.len,*pIE++,*pIE++,*pIE++,*pIE++,*pIE++,*pIE++,*pIE++));
		return 1;
	}
	return 0;
}

/****
* Dispathing push data to destination application, at preset only MMS
* application desires PUSH.
* Return: NULL failed, else return a pointer to PUSH data for MMS
*/
UBYTE* push_appli_dispatch(UBYTE *data, USHORT* retLen, USHORT len)
{
	UBYTE   *pData, tmp;
	UBYTE   vintLen = 0;
	UINT32  nHdLen = 0;	//PDU header length preset in UINT32 format

	pData = data;
	PUSH_DET_TRACE(("push_appli_dispatch():DP=%d,L=%d,d0-7:0x%2X,0x%2X,0x%2X,0x%2X,0x%2X,0x%2X,0x%2X,0x%2X", (UINT32)data,len,*pData++,*pData++,*pData++,*pData++,*pData++,*pData++,*pData++,*pData));

	pData = data + 1;	//skip TID field

	/* check PDU type */
	if (*pData != 0x06)
	{
		PUSH_DET_TRACE(("push_appli_dispatch():failed, not a push PDU, type=0x%X", *pData));
		return NULL;
	}

	pData ++;	//skip PDU type octet

	/* extract PDU header length */
	do
	{
		if (vintLen > 4)
		{
			PUSH_DET_TRACE(("push_appli_dispatch():failed, vint length overflow!"));
			return NULL;
		}

		tmp = *pData++;
		nHdLen = (nHdLen << 7) | (tmp & 0x7f);
		vintLen ++;
	}
	while (tmp > 0x7f);

	*retLen = len - nHdLen - vintLen - 2; 

	PUSH_DET_TRACE(("push_appli_dispatch():hdLen=%d", nHdLen));

	/* check content-type, only a simple implementation for MMS agent acceptable content type */
	if (*pData == 0xBE)/* content-type presents as a Constrained-media */
	{
		PUSH_DET_TRACE(("push_appli_dispatch():content-type=0x%X", *pData & 0x7f));
		pData ++;
		nHdLen--;  
	}
	else if (*pData > 31 && *pData < 127) //content-type presents as a string
	{
		if (strcmp((void*)pData, "application/vnd.wap.mms-message") != 0)
		{
			PUSH_DET_TRACE(("push_appli_dispatch():failed!"));
			return NULL;
		}
		else
		{
			nHdLen  -= (strlen((void*)pData) + 1); 
			pData   += strlen((void*)pData) + 1;	//shift to PUSH header			
			PUSH_DET_TRACE(("push_appli_dispatch():content-type=\"mms-message\""));
		}
	}
	else
	{
		PUSH_DET_TRACE(("push_appli_dispatch():failed, content-type=0x%X", *pData));
		return NULL;
	}

	/* check Application-ID field */        
	return(pData + nHdLen);
}

/****
* Save PUSH data desired by MMS application to a FFS file, and
* indicating the MMS application
*/
UBYTE MMS_SI_ind(UBYTE * data, USHORT len, UBYTE index)
{
extern void MMS_Content_REQ(
						UBYTE urlID,
						char *Data,
						ULONG data_length,
						BOOL moreData,
						ULONG totalSize,
						SHORT errorNo);
	UBYTE i;
	char fname[15];
	T_FFS_RET error;
	T_FFS_STAT stat;

	PUSH_DET_TRACE(("MMS_SI_ind():len=%d", len));
#ifdef MMS_WAP_ENABLED	
	MMS_Content_REQ(230,(char*)data,len,FALSE,0,0);
#else
	for (i = 0; i < MAX_MMS_SI; i ++)
	{
		sprintf(fname, "/mmi/mms_si%d", i); 
		if ((error = ffs_stat(fname, &stat)) == EFFS_NOTFOUND)
		{
			/* here we find a entry for writing the SI data */

⌨️ 快捷键说明

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