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

📄 wap_codec.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 3 页
字号:
 $Description:	Check whether the buffered events should be sent to MMI or not.

 $Returns:		TRUE if events are to be sent, FALSE otherwise
 
 $Arguments:	None.
 
*******************************************************************************/

UBYTE	wap_coder_check_send()
{
	trace("wap_coder_check_send");

	/* Can't send if MMI is busy */
	if (codec_data.send_forbidden)
		return FALSE;
		
	return TRUE;
}

/*******************************************************************************

 $Function:    	wap_coder_free_packed_event

 $Description:	Frees memory allocated for a specific block

 $Returns:		None
 
 $Arguments:	event_store	- Pointer to the data block of the event
 				size		- The size of the block in bytes

*******************************************************************************/

void wap_coder_free_packed_event(UBYTE* event_store, USHORT size)
{
	trace("wap_coder_free_packed_event");

	wip_free(event_store);
	
	return;
}


/*******************************************************************************

 $Function:    	wap_decoder

 $Description:	Decode an event received from MMI

 $Returns:		None
 
 $Arguments:	event_id	- ID of the event
 				parameter	- Pointer to the data block of the event

*******************************************************************************/


void wap_decoder(UBYTE event_id, void *parameter)
{
	WAP_TRACE_EVENT(("wap_decoder:%d", event_id) );

	/* Intercept MMI READY event */

	if (event_id==WAP_READY_IND_ID)
	{
		codec_data.send_forbidden = FALSE;
		wap_coder_send_buffered_list();
		return;	/* Don't need to tell WAP about this event */
	}

	/* Intercept TERMINATE event before passing to WAP */

#ifdef MMS_WAP_ENABLED
	if (event_id==WAP_TERMINATE_IND_ID || event_id==WAP_MMSTERMINATE_IND_ID)
#else
	if (event_id==WAP_TERMINATE_IND_ID)
#endif
	{
		wap_coder_clear_elements();
		codec_initialised = FALSE;
		/* This event will be passed on to WAP */
	}

	/* Process normal events */
	
	wap_decoder_unpack_event(event_id, parameter);
	
	return;

}


#else /* WAP_TASK */
/*******************************************************************************

 $Function:    	mmi_coder

 $Description:	Encode an event and send it to WAP

 $Returns:		None
 
 $Arguments:	event_id	- The ID of the event to be buffered
 				parameter	- Pointer to the data block of the event

*******************************************************************************/

void mmi_coder(UBYTE event_id, void* parameter)
{
	UBYTE *event_store;
	USHORT size;
trace("mmi_coder"); 
	//TRACE_EVENTUART("mmi_coder");
	//WAP_TRACE_QUEUE();

	/* Pack the event into allocated memory */
	
	event_store = mmi_coder_pack_event(event_id, parameter, &size);

	/* Only send event if created correctly */

	if (event_store)
	{
		WAP_TRACE_EVENT(("hyl,mmi send event to wap- size:%d",size));
    		psaMMI_WAP_IND(event_id, (void*)event_store, size);
		WAP_TRACE_EVENT(("hyl,mmi send event to wap end"));

		mmi_coder_free_packed_event(event_store, size);
	}
	//TRACE_EVENTUART("end mmi_coder");
	return;
}


/*******************************************************************************

 $Function:    	[wap_coder/mmi_coder]_free_packed_event

 $Description:	Frees memory allocated for a specific block

 $Returns:		None
 
 $Arguments:	event_store	- Pointer to the data block of the event
 				size		- The size of the block in bytes

*******************************************************************************/

void mmi_coder_free_packed_event(UBYTE* event_store, USHORT size)
{
	trace("mmi_coder_free_packed_event");
	mfwFree(event_store, size);

	return;
}


/*******************************************************************************

 $Function:    	mmi_decoder

 $Description:	Decode an event received from WAP

 $Returns:		None
 
 $Arguments:	 event_id	- ID of the event
 				parameter	- Pointer to the data block of the event

*******************************************************************************/


void mmi_decoder(UBYTE  event_id, void *parameter)
{
	T_MMI_WAP_READY_IND ready;
	
	trace("mmi_decoder"); 
	
	mmi_decoder_unpack_event(event_id, parameter);

	/* Inform WAP that MMI is ready again */

	ready.dummy = 0;
	M_MMI_WAP_READY_IND(&ready);
	
	return;
}
#endif

/* SHARED FUNCTIONS */

/*******************************************************************************

 $Function:    	[wap_coder/mmi_coder]_pack_event

 $Description:	Allocates memory for the event, then packs all its components together
 				in this memory.

 $Returns:		A pointer to the allocated memory
 
 $Arguments:	event_id	- The ID of the event to be buffered
 				parameter	- Pointer to the data block of the event
 				size		- Pointer to USHORT where the size of the block will be returned

*******************************************************************************/

#ifdef WAP_TASK
UBYTE * wap_coder_pack_event(UBYTE event_id, void* parameter, USHORT *size) {
#else
UBYTE * mmi_coder_pack_event(UBYTE event_id, void* parameter, USHORT *size){
#endif
	UBYTE				offsetIndex;
	UBYTE 				*memSrc;
	UBYTE				*memDest;
	UBYTE				*event_store;
	UBYTE				**blockSrcPtr;
	UBYTE				*blockSrc;
	USHORT				block_length;
	UBYTE				unit_size;
	USHORT				block_size;
	USHORT				param_size;
	USHORT				total_size;			/* Total size of packet in bytes */
	USHORT				offset_table[6][2];

#ifdef WAP_TASK
	trace("wap_coder_pack_event");
#else
	trace("mmi_coder_pack_event");
#endif
	
	/* Get the offset index for this event type, and set the total size so far to the structure size */
	
#ifdef WAP_TASK
	wap_offset_table(event_id, offset_table, &param_size);
#else
	mmi_offset_table(event_id, offset_table, &param_size);
#endif

	/* Calculate the total size in bytes, for memory allocation */

	total_size = param_size+sizeof(U32);	/* Total size of parameter block */
	
	for (offsetIndex = 0; offset_table[offsetIndex][0] != 0xFFFF; offsetIndex++)  /* Find all pointers to memory blocks using offsets */
	{
		memSrc = (UBYTE*)parameter+offset_table[offsetIndex][0];				/* Point to size of next block */
		block_length = *memSrc+256*(*(memSrc+1))+1;								/* Find the length of the block in units */
		unit_size = offset_table[offsetIndex][1];								/* Find the unit size in bytes */
		total_size += block_length*(USHORT)unit_size+sizeof(U32);				/* Add to total size, including initial size U32 */
	}

	WAP_TRACE_EVENT(("Alloc memory for event, size: %d", total_size));
	
	/* Allocate the memory and fill it */
	
#ifdef WAP_TASK
	event_store = (UBYTE*)wip_malloc(total_size);	/* Allocate memory using wip_mem */

	/* Do not continue if memory allocation fails */
	
#else
    event_store = (UBYTE*)mfwAlloc(total_size);		/* Allocate memory in MFW */
#endif

	if (!event_store)
	{
		TRACE_EVENT("*** WAP memory allocation failed ***");
		return NULL;
	}
	
	memDest = event_store;							/*  Pointer for writing data (destination) */
	memSrc	= (UBYTE*)parameter;					/*  Pointer for reading data (source) */

	memcpy(memDest, &param_size, sizeof(USHORT));	/*  Store size of data structure in first word */
	memDest += sizeof(USHORT);
	*(memDest++) = 0;
	*(memDest++) = 0;
	
    memcpy(memDest, memSrc, param_size);			/* Copy the data structure */
    memDest += param_size;

	for (offsetIndex = 0; offset_table[offsetIndex][0] != 0xFFFF; offsetIndex++)  /*  Copy each additional block of data (strings etc) */
	{
		WAP_TRACE_EVENT(("Copying block of data #%d", offsetIndex));
		
		memSrc = (UBYTE*)parameter+offset_table[offsetIndex][0];		/* Point to block length */

		block_length = *memSrc+256*(*(memSrc+1))+1;						/* Find the length of the block in units */

		WAP_TRACE_EVENT(( "Block length at %8x is %d",memSrc, block_length));	
		
		memSrc += sizeof(U32);											/* Point to pointer to block */
		
		unit_size = offset_table[offsetIndex][1];						/* Find the unit size in bytes */
		block_size = block_length*(USHORT)unit_size;					/* Find the block size in bytes */

		memcpy(memDest, &block_size, sizeof(USHORT));					/* Store size of block */
		memDest += sizeof(U32);											/* Point to where block is to be stored */

		if (block_size!=0)												/* If the block isn't empty */
		{
			blockSrcPtr = (UBYTE**)memSrc;										
			blockSrc = *blockSrcPtr;									/* Get the pointer to the block */
			
			WAP_TRACE_EVENT(( "Old block pointer is at: %x", blockSrcPtr));
			WAP_TRACE_EVENT(( "Old block at: %x", blockSrc));		

	 		memcpy(memDest, blockSrc, block_size);						/* Copy block */

			WAP_TRACE_EVENT(( "Copy block: %x to %x, offset %d", blockSrc, memDest, memDest-event_store));
			WAP_TRACE_EVENT(( "New block: %x", memDest));		
			
	 		memDest += block_size;										/* Point to next free block */
		}
	}

#ifdef TRACE_WAP_CODEC
	trace_P1( "Size of packed event: %d", total_size);
	trace("Memory dump - packed event");
	
	for (offsetIndex = 0; (offsetIndex<total_size && offsetIndex<80); offsetIndex++)
	{
		trace_P4("%8x %2x %3d %c", event_store+offsetIndex, *(event_store+offsetIndex), *(event_store+offsetIndex), *(event_store+offsetIndex));
	}
#endif /*TRACE_WAP_CODEC */

	/* Store the size of the block */

	*size = total_size;

	return event_store;
}


/*******************************************************************************

 $Function:    	[wap/mmi]_decoder_unpack_event
 
 $Description:	Using the offset table, this function corrects all the pointers in the block
 				of data received (see wap_offset_table for an explanation of the offset
 				table).

 $Returns:		None.
 
 $Arguments:	event_id	- the id of the event
 				data		- the data received with the primitive

*******************************************************************************/

#ifdef WAP_TASK	
void wap_decoder_unpack_event(UBYTE event_id, void* data) {
#else
void mmi_decoder_unpack_event(UBYTE event_id, void* data) {
#endif

	UBYTE 					*parameter;
	UBYTE					*event_store = (UBYTE *) data;
	UBYTE					*destPtr;
	UBYTE					*srcPtr;
	UBYTE					**ptrPtr;
	USHORT					block_size;
	USHORT					param_size;
	USHORT					total_size;
	UBYTE					offsetIndex;
	USHORT					offset_table[6][2];
    UBYTE                  tempLcdStatus;
#ifdef WAP_TASK	
	static T_WAP_FUNCTION	functionList[] = {
	(T_WAP_FUNCTION)W_MMI_WAP_READY_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_START_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_NEW_VIEW_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_TERMINATE_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_CLOSE_VIEW_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_CONFIGURE_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_CONNECTION_CONFIGURE_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_DOWNLOAD_URL_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_BROWSE_CONTROL_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_KEY_SELECTED_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_INPUT_DIALOG_CNF,
	(T_WAP_FUNCTION)W_MMI_WAP_PASSWORD_DIALOG_CNF,
	(T_WAP_FUNCTION)W_MMI_WAP_CONFIRM_DIALOG_CNF,
	(T_WAP_FUNCTION)W_MMI_WAP_INFO_DIALOG_CNF,
	(T_WAP_FUNCTION)W_MMI_WAP_DRAW_CARD_REQ,
	(T_WAP_FUNCTION)W_MMI_WAP_CONNECT_CNF,
	(T_WAP_FUNCTION)W_MMI_WAP_DISCONNECT_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_CACHE_PREPARE_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_CONTROL_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_NEW_KEY_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_INPUT_DIALOG_REQ	,
	(T_WAP_FUNCTION)W_WAP_MMI_PASSWORD_DIALOG_REQ,
	(T_WAP_FUNCTION)W_WAP_MMI_CONFIRM_DIALOG_REQ,
	(T_WAP_FUNCTION)W_WAP_MMI_INFO_DIALOG_REQ,
	(T_WAP_FUNCTION)W_WAP_MMI_NEW_CARD_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_DRAW_CARD_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_CLEAR_CARD_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_SEND_TEXT_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_SEND_IMAGE_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_SEND_TABLE_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_CARD_DRAW_COMPLETED_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_CONNECT_REQ,
	(T_WAP_FUNCTION)W_WAP_MMI_DISCONNECTED_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_READY_CNF
	/*talcon add for mms*/
#ifdef MMS_WAP_ENABLED
	,
	(T_WAP_FUNCTION)W_MMI_WAP_MMSSTART_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_MMSTERMINATE_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_POSTCONTENT_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_CONTENT_REQ,
	(T_WAP_FUNCTION)W_MMI_WAP_POSTMORECONTENT_IND,
	(T_WAP_FUNCTION)W_WAP_MMI_ACKPOSTCONTENT_REQ,
	(T_WAP_FUNCTION)W_MMI_WAP_GETCONTENT_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_ACKCONTENT_IND,
	(T_WAP_FUNCTION)W_MMI_WAP_CANCELCONTENT_IND
#endif
	};
#else
	static T_WAP_FUNCTION		functionList[] = {
	(T_WAP_FUNCTION)M_MMI_WAP_READY_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_START_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_NEW_VIEW_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_TERMINATE_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_CLOSE_VIEW_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_CONFIGURE_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_CONNECTION_CONFIGURE_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_DOWNLOAD_URL_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_BROWSE_CONTROL_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_KEY_SELECTED_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_INPUT_DIALOG_CNF,
	(T_WAP_FUNCTION)M_MMI_WAP_PASSWORD_DIALOG_CNF,
	(T_WAP_FUNCTION)M_MMI_WAP_CONFIRM_DIALOG_CNF,
	(T_WAP_FUNCTION)M_MMI_WAP_INFO_DIALOG_CNF,
	(T_WAP_FUNCTION)M_MMI_WAP_DRAW_CARD_REQ,
	(T_WAP_FUNCTION)M_MMI_WAP_CONNECT_CNF,
	(T_WAP_FUNCTION)M_MMI_WAP_DISCONNECT_IND,
	(T_WAP_FUNCTION)M_MMI_WAP_CACHE_PREPARE_IND,
	(T_WAP_FUNCTION)M_WAP_MMI_CONTROL_IND,

⌨️ 快捷键说明

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