📄 wap_codec.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: wap_codec.c
$Revision:
$Author: Condat(UK)
$Date:
********************************************************************************
Description:
Encodes and decodes events sent between the MMI task and the WAP task.
This file is compiled twice: one object file lives in the bmi directory, the other
in the wapaus directory.
********************************************************************************
$History: wap_codec.c
15/05/2003 - SPR#1983 - SH - Updated to latest from 1.6.3 version.
$End
*******************************************************************************/
#ifdef WAP_TASK
#define ENTITY_WAP
/*==== INCLUDES ===================================================*/
#if defined (NEW_FRAME)
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include "typedefs.h"
#include "pcm.h"
#include "pconst.cdg"
#include "mconst.cdg"
#include "message.h"
#include "ccdapi.h"
#include "vsi.h"
#include "custom.h"
#include "gsm.h"
#include "prim.h"
#include "cnf_wap.h"
#include "mon_wap.h"
#include "pei.h"
#include "tok.h"
#else /* NEW_FRAME */
#include <string.h>
#include "stddefs.h"
#include "pconst.cdg"
#include "message.h"
#include "ccdapi.h"
#include "custom.h"
#include "gsm.h"
#include "cnf_wap.h"
#include "mon_wap.h"
#include "prim.h"
#include "vsi.h"
#include "pei.h"
#include "tok.h"
#endif /* NEW_FRAME */
#include "dti.h"
#include "wap.h"
#include "cus_wap.h"
#include "capigle.h"
#include "wap_types.h"
#include "wap_codec.h"
#include "wap_wapmmi.h"
#include "psa_waps.h"
#else /* WAP_TASK */
#include <stdio.h>
#include <string.h>
#if defined (NEW_FRAME)
#include "typedefs.h"
#include "vsi.h"
#include "pei.h"
#include "custom.h"
#include "gsm.h"
#else /* NEW_FRAME */
#include "stddefs.h"
#include "custom.h"
#include "gsm.h"
#include "vsi.h"
#endif /* NEW_FRAME */
#include "cus_aci.h"
#include "p_sim.h"
#include "pcm.h"
#include "wap_types.h"
#include "wap_codec.h"
#include "ATBWapACI.h"
#endif /* WAP_TASK */
/* Header files necessary for memory allocation */
#ifdef WAP_TASK
#include "wip_mem.h"
#else
#include "Mfw_mfw.h"
#endif
/* Tracing macros */
#ifdef TRACE_WAP_CODEC
#define trace(x) TRACE_EVENT(x)
#define trace_P1(x,a) TRACE_EVENT_P1(x,a)
#define trace_P2(x,a,b) TRACE_EVENT_P2(x,a,b)
#define trace_P3(x,a,b,c) TRACE_EVENT_P3(x,a,b,c)
#define trace_P4(x,a,b,c,d) TRACE_EVENT_P4(x,a,b,c,d)
#define trace_P5(x,a,b,c,d,e) TRACE_EVENT_P5(x,a,b,c,d,e)
#else
#define trace(x) /* */
#define trace_P1(x,a) /* */
#define trace_P2(x,a,b) /* */
#define trace_P3(x,a,b,c) /* */
#define trace_P4(x,a,b,c,d) /* */
#define trace_P5(x,a,b,c,d,e) /* */
#endif
#define WAP_TRACE 0
//#define TRACE_ATBWAPACI
#include "mmiutilapi.h"
#ifdef WAP_TASK
#define TRACE_EVENT(f) WAP_TRACE_EVENT(("wapaus-wap_codec.c<<<talcon,%s",f));
#define TRACE_FUNCTION(f) TRACE_EVENT(f)
#define trace(f) TRACE_FUNCTION(f)
#else
#define TRACE_EVENT(f) WAP_TRACE_EVENT(("bmi-wap_codec.c<<<talcon,%s",f));
#define TRACE_EVENTUART(f) WAP_TRACE_EVENT(("bmi-wap_codec.c<<<talcon,%s",f));
#define TRACE_FUNCTION(f) TRACE_EVENT(f)
#define trace(f) TRACE_FUNCTION(f)
#endif
/*==== LOCAL TYPE DEFINITIONS ==========================================*/
typedef void (*T_WAP_FUNCTION) (void *parameter);
#ifdef WAP_TASK
typedef struct T_WAP_EVENT_INFO_X
{
UBYTE event_id; /* The ID of the event */
void *parameter; /* Pointer to the event data */
USHORT size; /* The size of the event */
struct T_WAP_EVENT_INFO_X *next;
}
T_WAP_EVENT_INFO;
typedef struct T_WAP_CODEC_DATA_X
{
UBYTE send_forbidden; /* TRUE if MMI is busy */
UBYTE element_count; /* Number of elements that are currently buffered */
USHORT size; /* Total size of buffered elements in bytes */
T_WAP_EVENT_INFO *first_element; /* Start of a linked list containing element info */
}
T_WAP_CODEC_DATA;
/*==== LOCAL VARIABLES ===============================================*/
static UBYTE codec_initialised = FALSE; /* FALSE until codec_data has been initialised */
static T_WAP_CODEC_DATA codec_data; /* Main data for wap coder */
/*******************************************************************************
$Function: wap_coder/mmi_coder
$Description: Encode an event to send to either WAP or MMI
$Returns: None
$Arguments: event_id - The identifier of the event
parameter - The data block
*******************************************************************************/
void wap_coder(UBYTE event_id, void* parameter)
{
/* - Call wap_coder_pack_event() to pack the event into a memory block
- Call wap_coder_add_element() to add this event to the list
- Call wap_coder_check_send() to see if the event is to be sent.
- If so, call wap_coder_send_buffered_list()
*/
UBYTE *event_store;
USHORT size;
trace("wap_coder");
//WAP_TRACE_TASK("wap_coder");
/* Check if codec_data needs to be initialised, i.e. when starting a new buffer */
if (!codec_initialised)
{
memset(&codec_data, 0, sizeof(codec_data));
codec_initialised = TRUE;
}
/* Pack the event into allocated memory */
event_store = wap_coder_pack_event(event_id, parameter, &size);
/* Only add event to list if created correctly */
if (event_store)
{
wap_coder_add_element(event_id, size, event_store);
if (wap_coder_check_send())
{
wap_coder_send_buffered_list();
}
}
return;
}
/*******************************************************************************
$Function: wap_coder_add_element
$Description: Adds the supplied event as an element to the buffer.
$Returns: None
$Arguments: event_id - The ID of the event to be buffered
parameter - Pointer to the data block of the event
*******************************************************************************/
void wap_coder_add_element(UBYTE event_id, USHORT size, UBYTE* parameter)
{
/* - Increment the total number of elements
- Create a new element in the event list
- Store the event_id, size and pointer
*/
T_WAP_EVENT_INFO *new_element;
T_WAP_EVENT_INFO *element;
USHORT offsetIndex;
trace("wap_coder_add_element");
new_element = (T_WAP_EVENT_INFO *)wip_malloc(sizeof(T_WAP_EVENT_INFO));
/* If memory allocation fails, don't continue */
if (!new_element)
{
TRACE_EVENT("*** WAP memory allocation failed ***");
return;
}
if (codec_data.element_count==0)
{
codec_data.first_element = new_element;
}
else
{
element = codec_data.first_element;
while (element->next!=NULL)
{
element = element->next;
}
element->next = new_element;
}
codec_data.element_count++;
codec_data.size += size;
new_element->event_id = event_id;
new_element->size = size;
new_element->parameter = parameter;
new_element->next = NULL;
return;
}
/*******************************************************************************
$Function: wap_coder_clear_elements
$Description: Clears all memory associated with the buffering of events before
sending, with the exception of the block to be sent itself.
- Destroys blocks associated with each individual event
- Destroys linked list containing event info
$Returns: None.
$Arguments: None.
*******************************************************************************/
void wap_coder_clear_elements()
{
/* - Loop through the elements linked list
- For each element, free the associated memory
- Then free the memory of the link itself
*/
T_WAP_EVENT_INFO *element;
T_WAP_EVENT_INFO *next_element;
trace("wap_coder_clear_elements");
element = codec_data.first_element;
while (element!=NULL)
{
wap_coder_free_packed_event(element->parameter, element->size);
next_element = element->next;
wip_free((void *)element);
element = next_element;
}
codec_data.element_count = 0;
codec_data.size = 0;
codec_data.first_element = NULL;
return;
}
/*******************************************************************************
$Function: wap_coder_send_buffered_list
$Description: Send the first item in the events list
$Returns: None.
$Arguments: None.
*******************************************************************************/
void wap_coder_send_buffered_list()
{
USHORT event_index;
T_WAP_EVENT_INFO *element;
USHORT offsetIndex;
UBYTE event_id;
UBYTE *data;
USHORT size;
trace("wap_coder_send_buffered_list");
/* Check that there are events to send */
if (!codec_initialised || !codec_data.element_count)
return;
element = codec_data.first_element;
event_id = element->event_id;
data = (UBYTE *)element->parameter;
size = element->size;
trace_P1("Number of elements in list: %d", codec_data.element_count);
trace_P2("Sending first element, event_id = %d, size = %d", event_id, size);
/* The second element becomes the first element */
codec_data.first_element = element->next;
codec_data.element_count--;
/* Destroy the first element */
wip_free((void *)element);
#ifdef TRACE_WAP_CODEC
trace("Sending event:");
for (offsetIndex = 0; (offsetIndex<size && offsetIndex<200); offsetIndex++)
{
trace_P4("%8x %2x %3d %c", data+offsetIndex, *(data+offsetIndex), *(data+offsetIndex), *(data+offsetIndex));
}
#endif
codec_data.send_forbidden = TRUE; /* Don't send anything else until MMI response */
wap_WAP_MMI_IND (event_id, (void*)data, size);
/* Free the memory */
wip_free(data);
return;
}
/*******************************************************************************
$Function: wap_coder_check_send
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -