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

📄 wap_pei.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
+-----------------------------------------------------------------------------
|  File     : wap_pei.c
+-----------------------------------------------------------------------------
|                 Copyright Condat AG 1999-2000, Berlin
|                 All rights reserved.
|
|                 This file is confidential and a trade secret of Condat AG
|                 The receipt of or possession of this file does not convey
|                 any rights to reproduce or disclose its contents or to
|                 manufacture, use, or sell anything it may describe, in
|                 whole, or in part, without the specific written consent of
|                 Condat AG.
+-----------------------------------------------------------------------------
|  Purpose  : This module implements the process body interface
|             for the entity wap.                         
|
|             Exported functions:
|              
|             pei_create    - Create the Protocol Stack Entity
|             pei_init      - Initialize Protocol Stack Entity
|             pei_primitive - Process Primitive
|             pei_timeout   - Process Timeout
|             pei_exit      - Close resources and terminate
|             pei_run       - Process Primitive
|             pei_config    - Dynamic Configuration
|             pei_monitor   - Monitoring of physical Parameters
|
| History    :  15/05/2003 - SPR#1983 - SH - Updated to latest from 1.6.3 version.
|
+-----------------------------------------------------------------------------
*/


#ifndef WAP_PEI_C
#define WAP_PEI_C
#endif

#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"
#include "dti.h"      /* functionality of the dti library */

#else

#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include "stddefs.h"
#include "pconst.cdg"
#include "mconst.cdg"
#include "message.h"
#include "ccdapi.h"
#include "custom.h"
#include "gsm.h"
#include "prim.h"
#include "cnf_wap.h"
#include "mon_wap.h"
#include "vsi.h"
#include "pei.h"
#include "tok.h"

#endif

#include "wap.h"

#define WAP_TRACE 1
#include "mmiutilapi.h"
#define TRACE_FUNCTION(f) WAP_TRACE_EVENT((f));
#define TRACE_EVENT(f) TRACE_FUNCTION(f)


/*==== CONST ======================================================*/
/*
 * instance management
 */
#ifdef OPTION_MULTIPLE_INSTANCE
#define GET_INSTANCE(p)           &wap_data_base[p->custom.route.inst_no]
#else
#define GET_INSTANCE(p)           &wap_data_base
#endif


/*==== VAR EXPORT =================================================*/
GLOBAL DTI_HANDLE wap_hDTI;     /* DTI connection for DTI library */
GLOBAL T_HANDLE hCommACI = VSI_ERROR;      /* ACI Communication */
GLOBAL T_HANDLE hCommUDP = VSI_ERROR;      /* UDP Communication */
GLOBAL T_HANDLE wap_handle;

/*==== VAR LOCAL ==================================================*/

#ifdef OPTION_RELATIVE
LOCAL ULONG offset;
#endif

LOCAL USHORT s_flag = 0;         /* signal flag        */
LOCAL BOOL exit_flag = FALSE;
LOCAL BOOL first_access = TRUE;

LOCAL T_MONITOR wap_mon;

#ifdef OPTION_SIGNALS
LOCAL UBYTE *signalDataTable[MAX_SIGNALS];
#endif


/*
 * static buffer for AUS wip_malloc
 */  
LOCAL UBYTE wip_mem[WIP_MEMSIZE]; /* AUS wip memory */

/*==== FUNCTIONS ==================================================*/


/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444)             MODULE  : WAP_PEI             |
| STATE   : code                       ROUTINE : pei_handle_signal   |
+--------------------------------------------------------------------+
 
  PURPOSE : Handle the next signal in the signal table
 
*/
LOCAL void pei_handle_signal (void)
{}



/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444)             MODULE  : WAP_PEI             |
| STATE   : code                       ROUTINE : pei_not_supported   |
+--------------------------------------------------------------------+
 
  PURPOSE : An unsupported primitive is received.
 
*/
LOCAL const void pei_not_supported (void *data)
{
  TRACE_FUNCTION ("wap pei_not_supported()")

  PFREE (data)
}

/*
 * Use MAK_FUNC_N for non supported opcodes.
 * This entries normally branches to pei_not_supported.
 *
 * Use MAK_FUNC_O for primitives which contains no SDU.
 *
 * Use MAK_FUNC_S for primitives which contains a SDU.
 */

/*
 * jumptable for the entity service access point. Contains
 * the processing-function addresses and opcodes of
 * request and response primitives.
 *
 */

#ifndef TAB_SIZE
#define TAB_SIZE(T) sizeof T / sizeof *T;
#endif

LOCAL const T_FUNC wap_table[] =
  {
    MAK_FUNC_S( mmi_wap_ind,     MMI_WAP_IND),  /* 0x3d00 */
    MAK_FUNC_S( mmi_wap_req,     MMI_WAP_REQ),  /* 0x3d01 */
    MAK_FUNC_S( mmi_wap_cnf,     MMI_WAP_CNF),  /* 0x3d02 */
    MAK_FUNC_0( mmi_wap_dti_req, WAP_DTI_REQ)   /* 0x3d03 */
  };

/*
 * jumptable for the service access point which are used by
 * the entity. Contains the processing-function addresses and
 * opcodes of indication and confirm primitives.
 *
 */
LOCAL const T_FUNC udp_table[] =
  {
    MAK_FUNC_0( udp_bind_cnf,       UDP_BIND_CNF),
    MAK_FUNC_0( udp_closeport_cnf,  UDP_CLOSEPORT_CNF),
    MAK_FUNC_0( udp_error_ind,      UDP_ERROR_IND),
    MAK_FUNC_0( udp_shutdown_ind,   UDP_SHUTDOWN_IND)
  };

LOCAL const T_FUNC dti_dl_table[] = {
  MAK_FUNC_0( pei_dti_dti_connect_ind     ,    DTI2_CONNECT_IND    ),
  MAK_FUNC_0( pei_dti_dti_connect_cnf     ,    DTI2_CONNECT_CNF    ),
  MAK_FUNC_0( pei_dti_dti_disconnect_ind  ,    DTI2_DISCONNECT_IND ),
  MAK_FUNC_0( pei_dti_dti_ready_ind       ,    DTI2_READY_IND      ),
  MAK_FUNC_0( pei_dti_dti_data_ind        ,    DTI2_DATA_IND       )

#if defined (_SIMULATION_)
  ,
  MAK_FUNC_S( pei_dti_dti_data_test_ind   ,    DTI2_DATA_TEST_IND )
#endif  /* _SIMULATION_ */
};

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444)             MODULE  : WAP_PEI             |
| STATE   : code                       ROUTINE : pei_primitive       |
+--------------------------------------------------------------------+
 
  PURPOSE : Process protocol specific primitive.
 
*/
#if defined (NEW_FRAME)
LOCAL SHORT pei_primitive (void * ptr)
#else
GLOBAL T_PEI_RETURN pei_primitive (T_PRIM *prim)
#endif
{
#if defined (NEW_FRAME)
  T_PRIM * prim = ptr;
#endif

  /*
   * @ADAPT@
   *                    |
   *                   MMI                   UPPER LAYER
   *                    |
   *                    v
   *      +-----------(wap)----------+
   *      |                          |
   *      |            WAP           |
   *      |                          |
   *      +-------------^------------+
   *                    |
   *                   UDP                   LOWER LAYER
   *                    |
   *
   */


  if (prim NEQ NULL)
  {
    ULONG            opc = prim->custom.opc;
    USHORT           n;
    const T_FUNC    *table;

    VSI_PPM_REC ((T_PRIM_HEADER *)prim, __FILE__, __LINE__);

    PTRACE_IN (opc);

    wap_data = GET_INSTANCE (prim);

    switch (SAP_NR(opc))
    {
      case WAP_UL:
        table = wap_table;
        n = TAB_SIZE (wap_table);
        break;
      case SAP_NR(UDP_DL):
        table = udp_table;
        n = TAB_SIZE (udp_table);
        break;
      case DTI2_DL:
        {
          table = dti_dl_table;
          n = TAB_SIZE (dti_dl_table);
          /* 
           * to be able to distinguish DTI1/DTI2 opcodes,
           * the ones for DTI2 start at 0x50
           */
          opc -= 0x50;
        }
        break;
      default :
        table = NULL;
        n = 0;
        break;
    }

    if (table NEQ NULL)
    {
      if (PRIM_NR(opc) < n)
      {
        table += PRIM_NR(opc);
#ifdef PALLOC_TRANSITION

        P_SDU(prim) = table->soff ? (T_sdu*) (((char*)&prim->data) + table->soff) : 0;

#ifndef NO_COPY_ROUTING
        P_LEN(prim) = table->size + sizeof (T_PRIM_HEADER);
#endif /* NO_COPY_ROUTING */

#endif /* PALLOC_TRANSITION */
        JUMP (table->func) (P2D(prim));
      }
      else
      {
        pei_not_supported (P2D(prim));
      }
      return PEI_OK;
    }
    /*
     * Primitive is no GSM Primitive
     * then forward to the environment
     */

#ifdef GSM_ONLY
    PFREE (P2D(prim))
    return PEI_ERROR;
#else
    if (opc & SYS_MASK)
      vsi_c_primitive (VSI_CALLER prim);
    else
    {
      PFREE (P2D(prim));
      return PEI_ERROR;
    }
#endif /* GSM_ONLY */
  }
  return PEI_OK;
}

/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444)             MODULE  : WAP_PEI             |
| STATE   : code                       ROUTINE : pei_init            |
+--------------------------------------------------------------------+
 
  PURPOSE : Initialize Protocol Stack Entity
 
*/
#if defined (NEW_FRAME)
LOCAL SHORT pei_init (T_HANDLE handle)
#else
GLOBAL T_PEI_RETURN pei_init (void)
#endif
{
  USHORT wip_initmalloc (void *, ULONG); /* care about this */

#ifdef WAP_USECACHE
#ifndef WAP_CCACHESIZE
  extern const memSizeType cCacheSize;       /* is initialized in capimem.h*/
#else
const memSizeType cCacheSize = WAP_CCACHESIZE;
#endif
#endif

#if defined (NEW_FRAME)
  wap_handle = handle;
#endif
  TRACE_FUNCTION ("wap pei_init()");

  vsi_t_sleep (VSI_CALLER 1);

  if (hCommACI < VSI_OK)
  {
    if ((hCommACI = vsi_c_open (VSI_CALLER ACI_NAME)) < VSI_OK)
      return PEI_ERROR;
  }

  if (hCommUDP < VSI_OK)
  {
    if ((hCommUDP = vsi_c_open (VSI_CALLER UDP_NAME)) < VSI_OK)
      return PEI_ERROR;
  }


  exit_flag = FALSE;

  /*
   * initialize dtilib for this entity
   */
  wap_hDTI = dti_init (
    MAX_INSTANCES,
    handle,
    DTI_DEFAULT_OPTIONS,
    pei_sig_callback
    );
  if(!wap_hDTI)
    return PEI_ERROR;

  /*
   * timer initialization
   */
  if (! wap_init_timer())
    return PEI_ERROR;

  /*
   *  initialize wip_memory for the AUS browser
   */

	wip_initmalloc(wip_mem, WIP_MEMSIZE);

 
  /* initialize wap_data */
#ifdef OPTION_MULTIPLE_INSTANCE
  {
    UBYTE i;  
    for (i = 0 ; i < MAX_INSTANCES; i++)
    {
      wap_data = &wap_data_base[i];
      udp_init(); 
    }
  }
#else
  wap_data = &wap_data_base;
  udp_init();
#endif 
  return PEI_OK;
}



/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444)             MODULE  : WAP_PEI             |
| STATE   : code                       ROUTINE : pei_timeout         |
+--------------------------------------------------------------------+
 
  PURPOSE : Process timeout
 
*/
#if defined (NEW_FRAME)
LOCAL SHORT pei_timeout (USHORT index)
#else
GLOBAL T_PEI_RETURN pei_timeout (T_VSI_THANDLE handle)
#endif
{
  wap_timer_expired ();
  return PEI_OK;
}



/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444)             MODULE  : WAP_PEI             |
| STATE   : code                       ROUTINE : pei_signal          |
+--------------------------------------------------------------------+
 
  PURPOSE : Process a signal
 
*/
GLOBAL T_PEI_RETURN pei_signal (UBYTE signalNumber,
                                void *signalData)
{

⌨️ 快捷键说明

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