changeset 322:5d1e22505446

GPF: tif library sources imported from Leonardo version
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 13 Apr 2014 07:21:57 +0000
parents 439afc1139b2
children d278439e905d
files gsm-fw/gpf/tst_drv/mux.c gsm-fw/gpf/tst_drv/mux.h gsm-fw/gpf/tst_drv/mux_pei.c gsm-fw/gpf/tst_drv/ser.c gsm-fw/gpf/tst_drv/ser_sd.c gsm-fw/gpf/tst_drv/ser_tr.c gsm-fw/gpf/tst_drv/socket.c gsm-fw/gpf/tst_drv/socket.h gsm-fw/gpf/tst_drv/stack1_Serial.h gsm-fw/gpf/tst_drv/thif_link.c gsm-fw/gpf/tst_drv/thif_link.h gsm-fw/gpf/tst_drv/tif2.c gsm-fw/gpf/tst_drv/titrc.c gsm-fw/gpf/tst_drv/tr2.c gsm-fw/gpf/tst_drv/usart.c gsm-fw/gpf/tst_drv/usart.h gsm-fw/gpf/tst_pei/idle.h gsm-fw/gpf/tst_pei/idle_pei.c gsm-fw/gpf/tst_pei/tif_version.c gsm-fw/gpf/tst_pei/tst_pei.c gsm-fw/gpf/tst_pei/tst_primitives.h gsm-fw/gpf/tst_pei/tstdriver.c gsm-fw/gpf/tst_pei/tstdriver.h
diffstat 23 files changed, 11700 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/mux.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,394 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       mux.c
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Module defines the adaptation of the MUX_tr driver
+|             to the GDI.
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifdef __MUX_C__
+#define __MUX_C__
+#endif
+
+#include "stdlib.h"
+#include <stdio.h>
+#include "string.h"
+#include "typedefs.h"
+
+#include "tools.h"
+#include "os.h"
+#include "gdi.h"
+#include "vsi.h"
+#include "glob_defs.h"
+#undef VSI_CALLER
+#include "frame.h"
+#include "prim.h"       /* to get the definitions of used SAP and directions */
+#include "gsm.h"
+#include "pei.h"
+#include "route.h"
+#include "dti.h"        /* functionality of the dti library */
+#include "mux.h"        /* to get the global entity definitions */
+#include "frame.h"
+
+/*==== TYPES ======================================================*/
+
+/*==== CONSTANTS ==================================================*/
+
+#define VSI_CALLER        m_tst_handle,
+#define VSI_CALLER_SINGLE m_tst_handle
+
+#define ALLOWED_MUX_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT) 
+
+#define TST_NAME  "TST"
+/*==== EXTERNALS ==================================================*/
+
+extern T_HANDLE ext_data_pool_handle;
+extern T_QMSG QueueMsg;
+
+/*==== GLOBAL VARIABLES ==================================================*/
+
+/*==== LOCAL VARIABLES ==================================================*/
+static T_DRV_SIGNAL Signal;
+
+T_HANDLE  m_tst_handle;
+
+/*==== FUNCTIONS ==================================================*/
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : MUX                 |
+| STATE   : code                       ROUTINE : mux_Exit            |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+void mux_Exit ( void )
+{
+//vsi_p_delete (0, vsi_p_handle (0,"MTST"));
+  mux_data.Connected = FALSE;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : MUX                 |
+| STATE   : code                       ROUTINE : mux_Read            |
++--------------------------------------------------------------------+
+
+  PURPOSE : read data from driver
+
+*/
+USHORT mux_Read ( void *Buffer, ULONG *BytesToRead )
+{
+  T_desc2 *d;
+  T_desc2 *d_new;
+
+  /* copy data into buffer */
+  *BytesToRead=0;
+  d=mux_data.recv_data;
+  while (d)
+  {
+    d_new=(T_desc2 *)d->next;
+    *BytesToRead += d->len;
+    memcpy(Buffer, d->buffer, d->len);
+    /* free memory */
+    MFREE(d);
+
+    d=d_new;
+  }
+
+  if (mux_data.dti_state NEQ IDLE) /* not yet configured */
+  {
+    return DRV_NOTCONFIGURED;
+  } 
+  else
+  {
+    /* inform UART that we are ready to receive next data package */
+    dti_start
+    (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL
+    );
+  }
+
+  return DRV_OK;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : MUX                 |
+| STATE   : code                       ROUTINE : mux_Write           |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+USHORT mux_Write ( void *Buffer, ULONG *BytesToWrite )
+{
+  USHORT ret = DRV_OK;
+
+  if (mux_data.h_comm_mtst==VSI_ERROR) /* not yet configured */
+  {
+    ret=DRV_NOTCONFIGURED;
+  }
+  else 
+  {
+    T_desc2 *d;
+    T_QMSG *pMsg = &QueueMsg;
+
+    PALLOC(localPrimPtr, DTI2_DATA_IND);
+
+    /* fill in parameters */
+    localPrimPtr->parameters.p_id=DTI_PID_UOS;  /* protocol identifier  */
+       /* flow control state */
+    localPrimPtr->parameters.st_lines.st_flow=DTI_FLOW_ON;   
+       /* line state sa      */
+    localPrimPtr->parameters.st_lines.st_line_sa=DTI_SA_ON;  
+       /* line state sb      */       
+    localPrimPtr->parameters.st_lines.st_line_sb=DTI_SB_ON;
+       /* break length       */       
+    localPrimPtr->parameters.st_lines.st_break_len=DTI_BREAK_OFF;
+
+      /* list of generic data descriptors */
+    MALLOC(d,(ULONG)(sizeof(T_desc2)+*BytesToWrite-1));
+    localPrimPtr->desc_list2.first=(ULONG)d;
+    localPrimPtr->desc_list2.list_len= (USHORT)*BytesToWrite;
+    d->next   = 0;
+    d->len    = (USHORT)*BytesToWrite;
+    d->size   = *BytesToWrite;
+    d->offset =  0;
+    memcpy(d->buffer,Buffer,*BytesToWrite);
+
+    /* PSEND without tracing */
+    pMsg->Msg.Primitive.Prim = (T_VOID_STRUCT*)(D2P(localPrimPtr));
+    pMsg->Msg.Primitive.PrimLen = PSIZE(localPrimPtr);
+    pMsg->MsgType = MSG_PRIMITIVE;
+#ifdef MEMORY_SUPERVISION
+    vsi_c_send (VSI_CALLER mux_data.h_comm_mtst,pMsg,__FILE__,__LINE__);
+#else
+    vsi_c_send (VSI_CALLER mux_data.h_comm_mtst,pMsg);
+#endif
+  }
+
+  return ( ret );
+}
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : MUX                 |
+| STATE   : code                       ROUTINE : mux_SetSignal       |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+USHORT mux_SetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_MUX_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    mux_data.EnabledSignalType |= SignalType;
+  
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : MUX                 |
+| STATE   : code                       ROUTINE : mux_ResetSignal     |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+USHORT mux_ResetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_MUX_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    mux_data.EnabledSignalType &= ~SignalType;
+  
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : MUX                 |
+| STATE   : code                       ROUTINE : mux_SetConfig       |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+  PARAMS:   Buffer - configuration string ("<DTI-partner> <tui> <c_id>")
+           
+
+*/
+USHORT mux_SetConfig ( char *Buffer )
+{
+  char token [10];
+  char peer_name [10];
+  USHORT len;
+  ULONG link_id;
+
+  if ( !mux_data.Connected )
+  {
+    Signal.SignalType = DRV_SIGTYPE_CONNECT;
+	  Signal.DrvHandle = mux_data.Handle;
+    (mux_data.Callback)( &Signal );
+    mux_data.Connected = TRUE;
+
+    return DRV_OK;
+  }
+
+  /* interprete configuration string */
+  if (!(len = GetNextToken (Buffer, token, " #")))
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    Buffer += (len+1);
+  }
+  if (strcmp(token,"STOP")==0) 
+  {
+    dti_close
+    (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL,
+      FALSE
+    );
+
+    mux_data.dti_state=CLOSED;
+    mux_data.h_comm_mtst=VSI_ERROR;
+    /* xxxxx set m_uart_ready = 0 ?! */
+    if (mux_data.send_data_buf_count>0) {
+      /* xxxxx clear send_buffer ?! */
+      mux_data.send_data_buf_count=0;
+    }
+
+    return DRV_OK;
+  }
+  strcpy(peer_name, token);
+  
+  if (!(len = GetNextToken (Buffer, token, " #")))
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    Buffer += (len+1);
+  }
+  link_id=atoi(token);
+
+  if(
+    dti_open
+    (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL,
+      DTI_QUEUE_DISABLED, /* DTI_QUEUE_UNLIMITED in order to queue data */
+      DTI_CHANNEL_TO_LOWER_LAYER,
+      FLOW_CNTRL_ENABLED,
+      DTI_VERSION_10,
+      (U8*)peer_name,
+      link_id
+    ) EQ FALSE)
+    return DRV_INVALID_PARAMS;
+
+  /* reset send_data_buf counter */
+  mux_data.send_data_buf_count=0;
+
+  /* set internal communication handle */
+  while ( (mux_data.h_comm_mtst=vsi_c_open (0, "MTST")) == VSI_ERROR)
+  {
+    vsi_t_sleep(0,100);
+  };
+
+  /* inform UART that we are ready to receive next data package */
+  {
+    dti_start
+    (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL
+    );
+  }
+
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : MUX                 |
+| STATE   : code                       ROUTINE : mux_Init            |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+USHORT mux_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{ 
+  T_HANDLE mux_handle;
+
+static const T_DRV_EXPORT mux_Info =
+{
+  "MUX",
+  CALLED_FROM_ISR,
+  {
+    /*mux_Init,*/
+    mux_Exit,
+    mux_Read,
+    mux_Write,
+    NULL,
+    NULL,
+    NULL,
+    mux_SetSignal,
+    mux_ResetSignal,
+    mux_SetConfig,
+    NULL,
+    NULL,
+  }
+};
+
+  mux_data.Handle = DrvHandle;
+
+  mux_data.EnabledSignalType = 0;
+
+  mux_data.Callback = CallbackFunc;
+
+  mux_data.Connected = FALSE;
+
+  mux_data.dti_state = CLOSED;
+  mux_data.h_comm_mtst = VSI_ERROR;
+
+  mux_handle = vsi_p_create (0, mux_pei_create, NULL, ext_data_pool_handle);
+  if (vsi_p_start (0, mux_handle) != VSI_OK)
+  {
+    return DRV_INITFAILURE;
+  };
+
+  *DrvInfo = &mux_Info;
+
+  m_tst_handle=vsi_c_open (0,TST_NAME);
+
+  return DRV_OK;           
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/mux.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,182 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       mux.h
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  Definitions for the Protocol Stack Entity mux.
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef MUX_H
+#define MUX_H
+
+#ifndef _ENTITY_PREFIXED
+  #define _ENTITY_PREFIXED(N) tst_##N
+#endif
+
+/*==== INCLUDES =============================================================*/
+
+#ifndef SAP_DTI2
+#define SAP_DTI2
+#endif
+
+/*==== CONSTS ===============================================================*/
+
+#define ENCODE_OFFSET    0             /* Bitoffset for encoding/decoding */
+#define hCommYYY         mux_hCommYYY  /* Communication handle */
+
+/* Timer definitions */
+#define T001             0
+#define T002             1
+
+/* Timer durations */
+#define T001_VALUE       1000          /* 1 second */
+#define T002_VALUE       3000          /* 3 seconds */
+
+/*
+ * information for dti library
+ */
+#define MTST_DTI_DN_INTERFACE  0
+#define MTST_DTI_DN_CHANNEL    0
+#define MTST_DTI_DN_INSTANCE   0
+
+/* make the pei_create, .. functions unique */
+#define pei_create       mux_pei_create
+
+#define pei_dti_dti_connect_req    _ENTITY_PREFIXED(pei_dti_dti_connect_req)
+#define pei_dti_dti_connect_cnf    _ENTITY_PREFIXED(pei_dti_dti_connect_cnf)
+#define pei_dti_dti_connect_ind    _ENTITY_PREFIXED(pei_dti_dti_connect_ind)
+#define pei_dti_dti_connect_res    _ENTITY_PREFIXED(pei_dti_dti_connect_res)
+#define pei_dti_dti_disconnect_req _ENTITY_PREFIXED(pei_dti_dti_disconnect_req)
+#define pei_dti_dti_disconnect_ind _ENTITY_PREFIXED(pei_dti_dti_disconnect_ind)
+#define pei_dti_dti_ready_ind      _ENTITY_PREFIXED(pei_dti_dti_ready_ind)
+#define pei_dti_dti_data_req       _ENTITY_PREFIXED(pei_dti_dti_data_req)
+#define pei_dti_dti_data_ind       _ENTITY_PREFIXED(pei_dti_dti_data_ind)
+#define pei_dti_dti_getdata_req    _ENTITY_PREFIXED(pei_dti_dti_getdata_req)
+#ifdef _SIMULATION_
+#define pei_dti_dti_data_test_req  _ENTITY_PREFIXED(pei_dti_dti_data_test_req)
+#define pei_dti_dti_data_test_ind  _ENTITY_PREFIXED(pei_dti_dti_data_test_ind)
+#endif /* _SIMLUATION_ */
+
+#define pei_sig_callback                                    \
+        _ENTITY_PREFIXED(pei_sig_callback                 )
+#define sig_dti_pei_connection_opened_ind                   \
+        _ENTITY_PREFIXED(sig_dti_pei_connection_opened_ind)
+#define sig_dti_pei_connection_closed_ind                   \
+        _ENTITY_PREFIXED(sig_dti_pei_connection_closed_ind)
+#define sig_dti_pei_tx_buffer_full_ind                       \
+        _ENTITY_PREFIXED(sig_dti_pei_tx_buffer_full_ind    )
+#define sig_dti_pei_tx_buffer_ready_ind                      \
+        _ENTITY_PREFIXED(sig_dti_pei_tx_buffer_ready_ind   )
+#define sig_dti_pei_data_received_ind                        \
+        _ENTITY_PREFIXED(sig_dti_pei_data_received_ind     )
+        
+
+#ifdef MUX_PEI_C
+static const T_STR_IND tmr_name_to_ind[] = 
+{
+  { "T001",   T001 },
+  { "T002",   T002 },
+  { NULL,     0 }
+};
+#endif
+
+#define MAX_SEND_BUF_COUNT  40 
+
+/*==== TYPES =================================================================*/
+
+/* MUX global typedefs */
+
+typedef struct
+{
+  USHORT Handle;
+  UBYTE  dti_state; /* state variable for dti library */
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+  T_HANDLE h_comm_mtst;
+  char Connected;
+  T_desc2 *recv_data;
+  USHORT send_data_buf_count;
+} T_MUX_DATA;
+
+/*==== EXPORTS ===============================================================*/
+
+short pei_create (T_PEI_INFO const **info);
+
+/*
+ * wrapping functions for dtilib primitives
+ */
+
+EXTERN const void pei_dti_dti_connect_ind (
+              T_DTI2_CONNECT_IND   *dti_connect_ind);
+EXTERN const void pei_dti_dti_connect_cnf (
+              T_DTI2_CONNECT_CNF   *dti_connect_cnf);
+EXTERN const void pei_dti_dti_disconnect_ind (
+              T_DTI2_DISCONNECT_IND   *dti_disconnect_ind);
+EXTERN const void pei_dti_dti_data_ind (
+              T_DTI2_DATA_IND   *dti_data_ind);
+EXTERN const void pei_dti_dti_ready_ind (
+              T_DTI2_READY_IND   *dti_ready_ind);
+#ifdef _SIMULATION_
+EXTERN const void pei_dti_dti_data_test_ind (
+              T_DTI2_DATA_TEST_IND   *dti_data_test_ind);
+#endif  /* _SIMULATION_ */
+
+/*
+ * this function is called by DTILIB
+ */
+EXTERN void         pei_sig_callback
+                          (
+                            U8               instance,
+                            U8               interfac,
+                            U8               channel, 
+                            U8               reason,
+                            T_DTI2_DATA_IND *dti_data2_ind
+                          );
+
+/*
+ * these functions are called by pei_sig_callback
+ */
+
+EXTERN const void         sig_dti_pei_connection_opened_ind();
+EXTERN const void         sig_dti_pei_connection_closed_ind();
+
+EXTERN const void         sig_dti_pei_tx_buffer_full_ind();
+EXTERN const void         sig_dti_pei_tx_buffer_ready_ind();
+
+EXTERN const void         sig_dti_pei_data_received_ind
+                          (
+                            T_DTI2_DATA_IND *dti_data_req
+                          );
+
+
+
+#ifdef MUX_PEI_C
+
+/* Entity data base */
+T_MUX_DATA               mux_data;
+/* DTI connection handle for DTI library      */
+DTI_HANDLE               mtst_hDTI;
+
+/* Communication handles */
+
+#else  /* MUX_PEI_C */
+
+/* Entity data base */
+extern T_MUX_DATA        mux_data;
+/* DTI connection handle for DTI library      */
+EXTERN DTI_HANDLE        mtst_hDTI;
+
+#endif /* MUX_PEI_C */
+
+#endif /* !MUX_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/mux_pei.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,1038 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       mux_pei.c
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This module implements the process body interface
+|             for the entity mux (used by tst for multiplexer driver).
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef MUX_PEI_C
+#define MUX_PEI_C
+#endif
+
+#ifndef ENTITY_MUX
+#define ENTITY_MUX
+#endif
+
+#define ENTITY_UART /* test only */
+
+/*==== INCLUDES =============================================================*/
+
+
+#include "stdlib.h"
+#include <stdio.h>
+#include "string.h"
+#include "typedefs.h"
+
+#include "tools.h"
+#include "os.h"
+#include "gdi.h"
+#include "vsi.h"
+#include "glob_defs.h"
+#include "frame.h"
+#include "prim.h"       /* to get the definitions of used SAP and directions */
+#include "gsm.h"
+#include "pei.h"
+#include "route.h"
+#include "dti.h"        /* functionality of the dti library */
+#include "mux.h"        /* to get the global entity definitions */
+
+/*==== CONSTS ================================================================*/
+
+#undef VSI_CALLER
+#define VSI_CALLER        m_handle,
+
+/* 
+ * Wait as long as possible. This is the time in ms that is waited for a 
+ * message in the input queue in the active variant. 
+ * It can be decreased by the customer.  
+ */   
+#define MUX_TIMEOUT     0xffffffff   
+
+/*==== TYPES =================================================================*/
+
+typedef struct
+{
+  char              *version;
+} T_MONITOR;
+
+/*==== GLOBAL VARIABLES ======================================================*/
+/*==== LOCALS ================================================================*/
+
+static  int           m_first = 1;
+static  T_MONITOR     m_mon;
+
+static  int           m_uart_ready = 0;
+
+static  T_desc2 *      m_send_data=NULL;
+static  USHORT        m_send_len=0;
+
+T_HANDLE              m_handle;
+T_DRV_SIGNAL          m_signal;
+
+GLOBAL DTI_HANDLE     mtst_hDTI;         /* handle for DTI library */
+T_QMSG QueueMsg;
+/*==== EXTERNAL DEFINED FUNCTIONS ==========================================*/
+
+/*==== PRIMITIVE HANDLER FUNCTIONS ==========================================*/
+
+static void primitive_not_supported (T_PRIM_HEADER *data);
+static void dti_data_req (T_DTI2_DATA_REQ *ptr);
+
+/*
+ * Jumptables to primitive handler functions. One table per SAP.
+ *
+ * Use MAK_FUNC_0 for primitives which contains no SDU.
+ * Use MAK_FUNC_S for primitives which contains a SDU.
+ */
+
+LOCAL const T_FUNC dti_ul_table[] = {
+  MAK_FUNC_0( primitive_not_supported     ,    DTI2_CONNECT_REQ    ),  /* 3700x */
+  MAK_FUNC_0( primitive_not_supported     ,    DTI2_CONNECT_RES    ),  /* 3701x */
+  MAK_FUNC_0( primitive_not_supported     ,    DTI2_DISCONNECT_REQ ),  /* 3702x */
+  MAK_FUNC_0( primitive_not_supported     ,    DTI2_GETDATA_REQ    ),  /* 3703x */
+  MAK_FUNC_0( dti_data_req                ,    DTI2_DATA_REQ       )   /* 3704x */
+#if defined (_SIMULATION_)
+  ,
+  MAK_FUNC_S( primitive_not_supported     ,   DTI2_DATA_TEST_REQ )
+#endif  /* _SIMULATION_ */
+};
+
+LOCAL const T_FUNC dti_dl_table[] = {
+  MAK_FUNC_0( pei_dti_dti_connect_ind     ,    DTI2_CONNECT_IND    ),  /* 7700x */
+  MAK_FUNC_0( pei_dti_dti_connect_cnf     ,    DTI2_CONNECT_CNF    ),  /* 7701x */
+  MAK_FUNC_0( pei_dti_dti_disconnect_ind  ,    DTI2_DISCONNECT_IND ),  /* 7702x */
+  MAK_FUNC_0( pei_dti_dti_ready_ind       ,    DTI2_READY_IND      ),  /* 7703x */
+  MAK_FUNC_0( pei_dti_dti_data_ind        ,    DTI2_DATA_IND       )   /* 7704x */
+#if defined (_SIMULATION_)
+  ,
+  MAK_FUNC_S( pei_dti_dti_data_test_ind   ,    DTI2_DATA_TEST_IND )
+#endif  /* _SIMULATION_ */
+};
+
+
+/*==== PRIVATE FUNCTIONS ====================================================*/
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  primitive_not_supported
++------------------------------------------------------------------------------
+|  Description  :  This function handles unsupported primitives.
+|
+|  Parameters   :  data - not used
+|
+|  Return       :  void
++------------------------------------------------------------------------------
+*/
+static void primitive_not_supported (T_PRIM_HEADER *data)
+{
+  //TRACE_FUNCTION ("primitive_not_supported");
+
+  PFREE (data);
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  pei_primitive
++------------------------------------------------------------------------------
+|  Description  :  Process protocol specific primitive.
+|
+|  Parameters   :  prim      - pointer to the received primitive
+|
+|  Return       :  PEI_OK    - function succeeded
+|                  PEI_ERROR - function failed
++------------------------------------------------------------------------------
+
+                          |           |
+                         TST         UART               UPLINK
+                          |           |
+                   +------v-----------v-------+
+                   |                          |
+                   |            MUX           |
+                   |                          |
+                   +-------------^------------+
+                                 |
+                                UART                    DOWNLINK
+                                 |
+
+*/
+static short pei_primitive (void *ptr)
+{
+  /*
+   * the following line of code causes a warning on tms470 compiler, that cannot be avoided
+   * without changing the PEI interface. Warning will not cause a problem 
+   */
+  T_PRIM * prim=(T_PRIM*)ptr;
+  
+  //TRACE_FUNCTION ("pei_primitive");
+
+  if (prim != NULL)
+  {
+    unsigned short     opc = (unsigned short)prim->custom.opc;
+    unsigned short     n;
+    const T_FUNC       *table;
+
+    /*
+     * This must be called for Partition Pool supervision. Will be replaced
+     * by another macro some time.
+     */
+    VSI_PPM_REC (&prim->custom, __FILE__, __LINE__);
+
+    //PTRACE_IN (opc);
+
+    switch (opc & OPC_MASK)
+    {
+      case DTI_DL:                     /* defined in prim.h */
+        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;
+      case DTI_UL:                     /* defined in prim.h */
+        table = dti_ul_table;
+        n = TAB_SIZE (dti_ul_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 != NULL)
+    {
+      if ((opc & PRM_MASK) < n)
+      {
+        table += opc & PRM_MASK;
+        P_SDU(prim) = table->soff ? 
+          (T_sdu*) (((char*)&prim->data) + table->soff) : 0;
+        P_LEN(prim) = table->size + sizeof (T_PRIM_HEADER);
+        JUMP (table->func) (P2D(prim));
+      }
+      else
+      {
+        primitive_not_supported (P2D(prim));
+      }
+      return PEI_OK;
+    }
+
+    /*
+     * primitive is not a GSM primitive - forward it to the environment
+     */
+    if (opc & SYS_MASK)
+      vsi_c_primitive (VSI_CALLER prim);
+    else
+    {
+      PFREE (P2D(prim));
+      return PEI_ERROR;
+    }
+  }
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function     : pei_init
++------------------------------------------------------------------------------
+|  Description  :  Initialize Protocol Stack Entity
+|
+|  Parameters   :  handle    - task handle
+|
+|  Return       :  PEI_OK    - entity initialised
+|                  PEI_ERROR - entity not (yet) initialised
++------------------------------------------------------------------------------
+*/
+static short pei_init (T_HANDLE handle)
+{
+  /* Initialize task handle */
+  m_handle = handle;
+  mux_data.dti_state = CLOSED;
+
+  /*
+   * initialize dtilib for this entity
+   */
+  mtst_hDTI = dti_init(
+    1, /* max simultaneous connections */
+    handle,
+    DTI_NO_TRACE,
+    pei_sig_callback
+    );
+  if(!mtst_hDTI)
+    return PEI_ERROR;
+
+  /* set no suspend for us and TST */
+  vsi_trcsuspend ( VSI_CALLER vsi_c_open (0,"MTST"), 0);
+  vsi_trcsuspend ( VSI_CALLER vsi_c_open (0,"TST"), 0);
+
+  return (PEI_OK);
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  pei_timeout
++------------------------------------------------------------------------------
+|  Description  :  Process timeout.
+|
+|  Parameters   :  index     - timer index
+|
+|  Return       :  PEI_OK    - timeout processed
+|                  PEI_ERROR - timeout not processed
++------------------------------------------------------------------------------
+*/
+static short pei_timeout (unsigned short index)
+{
+  //TRACE_FUNCTION ("pei_timeout");
+
+  /* Process timeout */
+  switch (index)
+  {
+    case 0:
+      /* Call of timeout routine */
+      break;
+    default:
+      //TRACE_ERROR("Unknown Timeout");
+      return PEI_ERROR;
+  }
+
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  pei_signal
++------------------------------------------------------------------------------
+|  Description  :  Process signal.
+|
+|  Parameters   :  opc       - signal operation code
+|                  data      - pointer to primitive
+|
+|  Return       :  PEI_OK    - signal processed
+|                  PEI_ERROR - signal not processed
++------------------------------------------------------------------------------
+*/
+static short pei_signal (unsigned long opc, void* data)
+{
+  //TRACE_FUNCTION ("pei_signal");
+
+  /* Process signal */
+  switch (opc)
+  {
+    default:
+      //TRACE_ERROR("Unknown Signal OPC");
+      return PEI_ERROR;
+  }
+
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  pei_exit
++------------------------------------------------------------------------------
+|  Description  :  Close Resources and terminate.
+|
+|  Parameters   :            - 
+|
+|  Return       :  PEI_OK    - exit sucessful
++------------------------------------------------------------------------------
+*/
+static short pei_exit (void)
+{
+  //TRACE_FUNCTION ("pei_exit");
+
+  /*
+   * Close communication channels
+   */
+
+  if (mux_data.dti_state NEQ CLOSED)
+  {    
+    dti_close
+    (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL,
+      FALSE
+    );
+    mux_data.dti_state = CLOSED;
+  }
+
+  /*
+   * Shut down dtilib
+   */
+  dti_deinit(mtst_hDTI);
+
+  return PEI_OK;
+}
+
+
+/* for test only - begin */
+#define MTST_TRACE 0x4f20
+typedef struct {
+  char str[80];
+} T_MTST_TRACE;
+
+void trace_aci(const char* str) 
+{
+  PALLOC(ptr,MTST_TRACE);
+  strcpy(ptr->str,str);
+
+  PSEND(vsi_c_open(VSI_CALLER "MMI"), ptr);
+}
+/* for test only - end */
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  pei_config
++------------------------------------------------------------------------------
+|  Description  :  Dynamic Configuration.
+|
+|  Parameters   :  Buffer - configuration string (
+|                    to start: "<DTI-partner> <tui> <c_id>"
+|                    to stop:  "STOP")
+|
+|  Return       :  PEI_OK      - sucessful
+|                  PEI_ERROR   - not successful
++------------------------------------------------------------------------------
+*/
+static short pei_config (char *Buffer)
+{
+  char token [10];
+  char peer_name [10];
+
+  USHORT len;
+
+  ULONG link_id;
+
+  //TRACE_FUNCTION ("pei_config");
+  //TRACE_FUNCTION (Buffer);
+
+  if ( ConfigTimer ( VSI_CALLER Buffer, NULL ) == VSI_OK )
+    return PEI_OK;
+
+  /*
+  *  further dynamic configuration
+  */
+  
+  /* interprete configuration string */
+  if (!(len = GetNextToken (Buffer, token, " #")))
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    Buffer += (len+1);
+  }
+  if (strcmp(token,"STOP")==0) 
+  {
+    dti_close
+    (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL,
+      FALSE
+    );
+    mux_data.dti_state=CLOSED;
+    mux_data.h_comm_mtst=VSI_ERROR;
+    m_uart_ready=0;
+    if (mux_data.send_data_buf_count>0) {
+      /* clear send_buffer */
+      T_desc2 *d_new;
+      T_desc2 *d=m_send_data;
+      while (d)
+      {
+        d_new=(T_desc2 *)d->next;
+        MFREE(d);
+        d=d_new;
+      }
+
+      mux_data.send_data_buf_count=0;
+    }
+
+    return PEI_OK;
+  }
+  strcpy(peer_name, token);
+  
+  if (!(len = GetNextToken (Buffer, token, " #")))
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    Buffer += (len+1);
+  }
+  link_id=atoi(token);
+
+  if(
+    dti_open (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL,
+      0,
+      DTI_CHANNEL_TO_LOWER_LAYER,
+      DTI_QUEUE_UNUSED,
+      DTI_VERSION_10,
+      (U8*)peer_name,
+      link_id
+      ) EQ FALSE)
+    return DRV_INVALID_PARAMS;
+
+  /* reset send_data_buf counter */
+  mux_data.send_data_buf_count=0;
+
+  /* set internal communication handle */
+  while ( (mux_data.h_comm_mtst=vsi_c_open (0, "MTST")) == VSI_ERROR)
+  {
+    vsi_t_sleep(0,100);
+  };
+
+  /* inform UART that we are ready to receive next data package */
+  {
+    dti_start
+    (
+      mtst_hDTI,
+      MTST_DTI_DN_INSTANCE,
+      MTST_DTI_DN_INTERFACE,
+      MTST_DTI_DN_CHANNEL
+    );
+  }
+
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  pei_monitor
++------------------------------------------------------------------------------
+|  Description  :  Monitoring of physical Parameters.
+|
+|  Parameters   :  out_monitor - return the address of the data to be monitored
+|
+|  Return       :  PEI_OK      - sucessful (address in out_monitor is valid)
+|                  PEI_ERROR   - not successful
++------------------------------------------------------------------------------
+*/
+static short pei_monitor (void ** out_monitor)
+{
+  //TRACE_FUNCTION ("pei_monitor");
+
+  /*
+   * Version = "0.S" (S = Step).
+   */
+  m_mon.version = "MTST 1.0";
+  *out_monitor = &m_mon;
+
+  return PEI_OK;
+}
+
+/*==== PUBLIC FUNCTIONS =====================================================*/
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  pei_create
++------------------------------------------------------------------------------
+|  Description  :  Create the Protocol Stack Entity.
+|
+|  Parameters   :  info        - Pointer to the structure of entity parameters
+|
+|  Return       :  PEI_OK      - entity created successfully
+|                  
++------------------------------------------------------------------------------
+*/
+SHORT pei_create (T_PEI_INFO const **info)
+{
+  static T_PEI_INFO pei_info =
+  {
+    "MTST",         /* name */
+    {              /* pei-table */
+      pei_init,
+      pei_exit,
+      pei_primitive,
+      pei_timeout,
+      pei_signal,
+      0,
+      pei_config,
+      pei_monitor
+    },
+    1024,          /* stack size */
+    10,            /* queue entries */
+    100,           /* priority (1->low, 255->high) */
+    0,             /* number of timers */
+    PASSIVE_BODY|COPY_BY_REF|TRC_NO_SUSPEND
+                   /* flags: bit 0   active(0) body/passive(1) */
+  };               /*        bit 1   com by copy(0)/reference(1) */
+
+  //TRACE_FUNCTION ("pei_create");
+
+  /*
+   * Close Resources if open
+   */
+  if (!m_first) 
+  {
+    pei_exit();
+  }
+
+  m_first=0;
+
+  /*
+   * Export startup configuration data
+   */
+  *info = &pei_info;
+
+  return PEI_OK;
+}
+/***********+++++-----------------+++++++*******++----++**********/
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  sig_dti_pei_tx_buffer_ready_ind
++------------------------------------------------------------------------------
+|  Description  :  sent from UART to indicate that it is ready to
+|                  receive new data via DTI_DATA_REQ
+|
+|  Parameters   :
+|
+|  Return       :  
+|                  
++------------------------------------------------------------------------------
+*/
+GLOBAL const void sig_dti_pei_tx_buffer_ready_ind ()
+{
+  m_uart_ready++;
+}
+
+/***********+++++-----------------+++++++*******++----++**********/
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  dti_data_req
++------------------------------------------------------------------------------
+|  Description  :  sent from TST to deliver new data to MTST
+|
+|  Parameters   :  ptr         - Pointer to the structure of the primitive
+|
+|  Return       :  
+|                  
++------------------------------------------------------------------------------
+*/
+static void dti_data_req (T_DTI2_DATA_REQ *ptr)
+{
+  T_desc2 *d=0;
+
+  /* PPASS without traces */
+  T_DTI2_DATA_IND *prim = (T_DTI2_DATA_IND*)ptr;
+  D_OPC(prim) = (DTI2_DATA_IND);
+
+  if (!m_uart_ready)
+  {
+    if (mux_data.send_data_buf_count > MAX_SEND_BUF_COUNT-2) 
+    {
+      /* free data */
+      T_desc2 *d_new;
+      T_desc2 *d=(T_desc2 *)prim->desc_list2.first;
+      while (d)
+      {
+        d_new=(T_desc2 *)d->next;
+        MFREE(d);
+        d=d_new;
+      }
+
+      if (mux_data.send_data_buf_count == MAX_SEND_BUF_COUNT) 
+      {
+        /* buffer full -> free prim and exit */
+        PFREE(prim);
+        return; 
+      } 
+      else
+      {
+        /* buffer almost full -> send SYST information */
+        char infostr[]="\x02T0036001FMTSTPCO ERROR: SEND-BUFFER FULL\x0a"; 
+        USHORT len=sizeof(infostr)-1;
+        MALLOC(d,(USHORT)(sizeof(T_desc2)+len-1));
+        prim->desc_list2.first=(ULONG)d;
+        prim->desc_list2.list_len=len;
+        d->next = 0;
+        d->len = len;
+        d->size = len;
+        d->offset = 0;        
+        memcpy(d->buffer,infostr,len);
+      }
+    }
+
+    if (m_send_data)
+    {
+      /* find last send_data descriptor */
+      d=m_send_data;
+      while (d->next)
+      {
+        d=(T_desc2 *)d->next;
+      }
+      /* concat new data */
+      d->next=prim->desc_list2.first;
+      m_send_len+=prim->desc_list2.list_len;
+    } 
+    else 
+    {
+      m_send_data=(T_desc2 *)prim->desc_list2.first;
+      d=m_send_data;
+      while (d)
+      {
+        m_send_len+=d->len;
+        d=(T_desc2 *)d->next;
+      }
+    }
+    mux_data.send_data_buf_count++;
+
+    /* free prim */
+    PFREE(prim);
+    return;
+  }
+
+  m_uart_ready--;
+  mux_data.send_data_buf_count=0;
+
+  if (m_send_data)
+  {
+    /* find last data descriptor in stored data */
+    d=m_send_data;
+    while (d->next)
+    {
+      d=(T_desc2 *)d->next;
+    }
+    /* concat new data to stored data */
+    d->next=prim->desc_list2.first;
+    prim->desc_list2.first=(ULONG)m_send_data;
+    prim->desc_list2.list_len+=m_send_len;
+
+    /* clear send_data */
+    m_send_data=(T_desc2 *)0;
+    m_send_len=0;
+  }
+
+  /* send prim */
+  dti_send_data
+  (
+    mtst_hDTI,
+    MTST_DTI_DN_INSTANCE,
+    MTST_DTI_DN_INTERFACE,
+    MTST_DTI_DN_CHANNEL,
+    prim
+  );
+}
+
+/***********+++++-----------------+++++++*******++----++**********/
+
+/*
++------------------------------------------------------------------------------
+|  Function     :  sig_dti_pei_data_received_ind
++------------------------------------------------------------------------------
+|  Description  :  sent from UART to deliver new data
+|
+|  Parameters   :  ptr         - Pointer to the structure of the primitive
+|
+|  Return       :  
+|                  
++------------------------------------------------------------------------------
+*/
+GLOBAL const void sig_dti_pei_data_received_ind (T_DTI2_DATA_IND *ptr)
+{
+  T_DTI2_DATA_IND *prim = ptr;
+
+  /* prevent dtilib from automatically sending flow control primitives */
+  dti_stop
+  (
+    mtst_hDTI,
+    MTST_DTI_DN_INSTANCE,
+    MTST_DTI_DN_INTERFACE,
+    MTST_DTI_DN_CHANNEL
+  );
+
+  if ( mux_data.EnabledSignalType & DRV_SIGTYPE_READ )
+  {
+    m_signal.SignalType = DRV_SIGTYPE_READ;
+    m_signal.DrvHandle = mux_data.Handle;
+
+    mux_data.recv_data=(T_desc2 *)prim->desc_list2.first;
+
+    (mux_data.Callback)( &m_signal );
+  }
+  PFREE(prim);
+}
+
+/***********+++++-----------------+++++++*******++----++**********/
+
+/* 
+ * dtilib wrapping and support functions 
+ */
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_connect_req
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_connect_req
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_connect_req (
+                    T_DTI2_CONNECT_REQ   *dti_connect_req
+                  )
+{
+  dti_dti_connect_req (mtst_hDTI, dti_connect_req);
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_connect_cnf
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_connect_cnf
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_connect_cnf (
+                    T_DTI2_CONNECT_CNF   *dti_connect_cnf
+                  )
+{
+    dti_dti_connect_cnf(mtst_hDTI, dti_connect_cnf);  
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_connect_ind
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_connect_ind
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_connect_ind (
+                    T_DTI2_CONNECT_IND   *dti_connect_ind
+                  )
+{
+    dti_dti_connect_ind(mtst_hDTI, dti_connect_ind);  
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_connect_res
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_connect_res
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_connect_res (
+                    T_DTI2_CONNECT_RES   *dti_connect_res
+                  )
+{
+    dti_dti_connect_res(mtst_hDTI, dti_connect_res);  
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_disconnect_req
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_disconnect_req
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_disconnect_req (
+                    T_DTI2_DISCONNECT_REQ   *dti_disconnect_req
+                  )
+{
+    dti_dti_disconnect_req (mtst_hDTI, dti_disconnect_req);
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_disconnect_ind
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_disconnect_ind
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_disconnect_ind (
+                    T_DTI2_DISCONNECT_IND   *dti_disconnect_ind
+                  )
+{
+    dti_dti_disconnect_ind (mtst_hDTI, dti_disconnect_ind);
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_data_req
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_data_req
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_data_req (
+                    T_DTI2_DATA_REQ   *dti_data_req
+                  )
+{
+    dti_dti_data_req (mtst_hDTI, dti_data_req);
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_getdata_req
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_data_req
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_getdata_req (
+                    T_DTI2_GETDATA_REQ   *dti_getdata_req
+                  )
+{
+  dti_dti_getdata_req (mtst_hDTI, dti_getdata_req);
+}
+ 
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_data_ind
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_data_ind
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_data_ind (
+                    T_DTI2_DATA_IND   *dti_data_ind
+                  )
+{
+    dti_dti_data_ind (mtst_hDTI, dti_data_ind);
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_ready_ind
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_ready_ind
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_ready_ind (
+                    T_DTI2_READY_IND   *dti_ready_ind
+                  )
+{
+  dti_dti_ready_ind (mtst_hDTI, dti_ready_ind);
+}
+ 
+#ifdef _SIMULATION_
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_data_test_req
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_data_test_req
++------------------------------------------------------------------------------
+*/
+    
+GLOBAL const void pei_dti_dti_data_test_req (
+                    T_DTI2_DATA_TEST_REQ   *dti_data_test_req
+                  )
+{
+    dti_dti_data_test_req (mtst_hDTI, dti_data_test_req);
+}
+
+/*
++------------------------------------------------------------------------------
+|    Function    : pei_dti_dti_data_test_ind
++------------------------------------------------------------------------------
+|    PURPOSE : Call the process function dti_dti_data_test_ind
++------------------------------------------------------------------------------
+*/
+
+GLOBAL const void pei_dti_dti_data_test_ind (
+                    T_DTI2_DATA_TEST_IND   *dti_data_test_ind
+                  )
+{
+  dti_dti_data_test_ind (mtst_hDTI, dti_data_test_ind);   
+}
+
+#endif /* _SIMULATION_ */
+
+
+/*
++------------------------------------------------------------------------------
+|    Function: pei_sig_callback
++------------------------------------------------------------------------------
+|    PURPOSE : Callback function for DTILIB
++------------------------------------------------------------------------------
+*/
+
+GLOBAL void pei_sig_callback(U8 instance, U8 interfac, U8 channel, 
+                               U8 reason, T_DTI2_DATA_IND *dti_data_ind)
+{
+  TRACE_FUNCTION("pei_sig_callback");
+
+#ifdef _SIMULATION_
+  if(instance NEQ MTST_DTI_UP_INSTANCE || 
+     interfac NEQ MTST_DTI_UP_INTERFACE || 
+     channel  NEQ MTST_DTI_UP_CHANNEL) 
+  {
+    TRACE_ERROR("[PEI_SIG_CALLBACK] invalid parameters!");
+    return; /* error, not found */
+  }
+#endif /* _SIMULATION_ */
+
+  if (mtst_hDTI NEQ D_NO_DATA_BASE)
+  {
+    switch (reason)
+    {
+      case DTI_REASON_CONNECTION_OPENED:
+        sig_dti_pei_connection_opened_ind();
+        break;
+
+      case DTI_REASON_CONNECTION_CLOSED:
+        sig_dti_pei_connection_closed_ind();
+        break;
+
+      case DTI_REASON_DATA_RECEIVED:
+
+        /*
+         * DTI2_DATA_IND is interpreted as DTI2_DATA_REQ
+         */
+        PACCESS (dti_data_ind);
+        sig_dti_pei_data_received_ind(dti_data_ind);
+        break;
+
+      case DTI_REASON_TX_BUFFER_FULL:
+        sig_dti_pei_tx_buffer_full_ind();
+        break;
+      
+      case DTI_REASON_TX_BUFFER_READY:
+        sig_dti_pei_tx_buffer_ready_ind();
+        break;
+
+      default:
+        TRACE_ERROR("unknown DTILIB reason parameter");
+        break;
+    } /* end switch */
+  } /* end if */
+  else 
+  {
+    TRACE_ERROR("Pointer to DTILIB database not existing");
+  }
+} /* pei_sig_callback() */
+
+/*==== END OF FILE ==========================================================*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/ser.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,455 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       ser.c
++------------------------------------------------------------------------------
+|  Copyright 2004 Texas Instruments Deutschland, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Deutschland, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the serial driver adaptation
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __SER_C__
+#define __SER_C__
+#endif
+
+#include <windows.h>
+#include <stdio.h>
+#include "usart.h"
+#include "stdlib.h"
+#include "string.h"
+#include "tools.h"
+#include "typedefs.h"
+#include "tstheader.h"
+#include "os.h"
+#include "gdi.h"
+
+/*==== TYPES ======================================================*/
+
+typedef struct
+{
+  USHORT Handle;
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+#ifndef _TARGET_
+  OS_HANDLE TaskHandle;
+#endif
+  char Connected;
+} T_SER_DATA;
+
+/*==== CONSTANTS ==================================================*/
+
+#define ALLOWED_SER_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT)
+#define MAX_CONFIGSTR_LEN 50
+
+/*==== EXTERNALS ==================================================*/
+
+#ifndef _TARGET_
+extern OS_HANDLE ext_data_pool_handle;
+#endif
+
+/*==== VARIABLES ==================================================*/
+
+T_SER_DATA SER_Data;
+static T_DRV_SIGNAL Signal;
+GLOBAL int            extPort     = 1;
+
+#ifndef _TARGET_
+  static char m_last_config[MAX_CONFIGSTR_LEN+1];
+#endif
+
+#ifdef _TOOLS_
+  OS_TIME extr_creation_time = 0;
+#endif
+
+/*==== FUNCTIONS ==================================================*/
+
+#ifndef RUN_INT_RAM
+#ifdef _TOOLS_
+OS_TIME tst_get_init_time ( void )
+{
+  return extr_creation_time;
+}
+#endif
+#endif
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : Callback            |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+void Callback ( void )
+{
+	if ( SER_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+  {
+    Signal.SignalType = DRV_SIGTYPE_READ;
+	  Signal.DrvHandle = SER_Data.Handle;
+
+    (SER_Data.Callback)( &Signal );
+  }
+}
+
+#ifndef _TARGET_
+
+GLOBAL void SER_Receiver (void)
+{
+
+  for(;;)
+  {
+    UT_IsChar ();
+    Callback();
+  }
+}
+
+#endif
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_Exit            |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+void SER_Exit ( void )
+{
+  os_DestroyTask( 0, SER_Data.TaskHandle );
+  SER_Data.TaskHandle = OS_ERROR;
+  UT_Close();
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_Read            |
++--------------------------------------------------------------------+
+
+  PURPOSE : read data from driver
+
+*/
+USHORT SER_Read ( void *Buffer, ULONG *BytesToRead )
+{
+  *BytesToRead = (USHORT)UT_ReadNChars (UT_DEVICE_0, (BYTE *)Buffer, *BytesToRead);
+  return DRV_OK;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_Write           |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+USHORT SER_Write ( void *Buffer, ULONG *BytesToWrite )
+{
+ULONG ToWrite = *BytesToWrite & ~PRIM_FLAG_MASK;
+
+  UT_WriteNChars(UT_DEVICE_0, (void*)Buffer, ToWrite );
+  return ( DRV_OK );
+}
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SetSignal       |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+USHORT SER_SetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_SER_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    SER_Data.EnabledSignalType |= SignalType;
+
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_ResetSignal     |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+USHORT SER_ResetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_SER_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    SER_Data.EnabledSignalType &= ~SignalType;
+
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SetConfig       |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+*/
+USHORT SER_SetConfig ( char *Buffer )
+{
+/*lint -e813, suppress Info 813: auto variable 'osver' has size '148' */ 
+char token [MAX_PATH+1];
+/*lint +e813 */
+unsigned int baudrate=0;
+int mode;
+char flow_ctrl='N';
+unsigned int len;
+const char *fname=NULL;
+
+  if ( !SER_Data.Connected )
+  {
+    Signal.SignalType = DRV_SIGTYPE_CONNECT;
+	  Signal.DrvHandle = SER_Data.Handle;
+    Signal.UserData = NULL;
+    (SER_Data.Callback)( &Signal );
+    SER_Data.Connected = TRUE;
+    extPort=0;
+    return DRV_OK;
+  }
+
+  if (strlen(m_last_config))
+  {
+    /* check if we are already configured right */
+    if (strcmp(m_last_config,Buffer)==0)
+    {
+#ifdef _DEBUG
+      fprintf(stdout,"SER: keeping configuration\n");
+#endif
+      return DRV_OK;
+    }
+  }
+
+  if (!(strcmp(Buffer,"EXIT")))
+  {
+    SER_Exit();
+    return DRV_OK;
+  }
+  /* save configuration string */
+  strncpy(m_last_config,Buffer,MAX_CONFIGSTR_LEN);
+
+  /* interprete configuration string */
+  if ( (len = GetNextToken (Buffer, token, " #")) == 0 )
+    return DRV_INVALID_PARAMS;
+  else
+    Buffer += (len+1);
+
+  /* set mode */
+  if (!strcmp(token,"SIM")) 
+  {
+    mode=UT_MODE_SIM;
+    printf("TST: simulated USART mode selected\n");
+  } 
+  else if (!strcmp(token,"FILE")) 
+  {
+    if ( (len = GetNextToken (Buffer, token, "\"")) == 0 ) 
+    {
+      return DRV_INVALID_PARAMS;
+    } 
+    mode=UT_MODE_FILE;
+    fname=token;
+    printf("TST: file mode selected\n");
+    strcpy(m_last_config,""); /* don't store file-mode */
+  } 
+  else 
+  {
+    if (!strcmp(token,"NT")) {
+      mode=UT_MODE_NT;
+    } else if (!strcmp(token,"95")) {
+      mode=UT_MODE_95;
+    } else if (!strcmp(token,"REAL")) {
+      /*lint -e813, suppress Info 813: auto variable 'osver' has size '148' */ 
+      OSVERSIONINFO osver;
+      /*lint +e813 */
+      osver.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
+      GetVersionEx( &osver);
+      if (osver.dwPlatformId==VER_PLATFORM_WIN32_NT) {
+        mode=UT_MODE_NT;
+      } else {
+        mode=UT_MODE_95;
+      }
+    } else {
+      return DRV_INVALID_PARAMS;
+    }
+
+    if (mode==UT_MODE_NT) {
+      printf("TST: real USART mode for winNT selected\n");
+    } else {
+      printf("TST: real USART mode for win95 selected\n");
+    }
+
+    /* com port setting */
+    if ( (len = GetNextToken (Buffer, token, " #")) == 0 ) {
+      return DRV_INVALID_PARAMS;
+    } else {
+      Buffer += (len+1);
+    }
+
+    extPort=atoi(&token[3]);
+
+    /*
+     * Get baudrate from configuration string
+     */
+    if ( (len = GetNextToken (Buffer, token, " #")) == 0 ) {
+      return DRV_INVALID_PARAMS;
+    } else {
+      Buffer += (len+1);
+    }
+
+    printf("SER: requested baudrate: %s\n",token);
+    switch ( atoi(token) )
+    {
+      case 38400:
+        baudrate = UT_BAUD_38400;
+        break;
+      case 19200:
+        baudrate = UT_BAUD_19200;
+        break;
+      case 9600:
+        baudrate = UT_BAUD_9600;
+        break;
+      case 57600:
+        baudrate = UT_BAUD_57600;
+        break;
+      case 115200:
+        baudrate = UT_BAUD_115200;
+        break;
+      case 128000:
+        baudrate = UT_BAUD_128000;
+        break;
+      case 256000:
+        baudrate = UT_BAUD_256000;
+        break;
+      default:
+        printf("SER: no CBR_xxx constant found for requested baudrate\n");
+        baudrate = atoi(token);
+        break;
+    }
+
+    /*
+     * Get flow control from configuration string
+     */
+    if ( (len = GetNextToken (Buffer, token, " #")) == 0 ) {
+      return DRV_INVALID_PARAMS;
+    } else {
+      Buffer += (len+1);
+    }
+
+    flow_ctrl=token[0];
+    printf("SER: requested flow control: %c\n",flow_ctrl);
+  }
+
+  /* exit receiver task */ 
+  if ( SER_Data.TaskHandle != OS_ERROR )
+  {
+    os_DestroyTask( 0, SER_Data.TaskHandle );
+  }
+#ifdef _TOOLS_
+  os_GetTime ( 0, &extr_creation_time );
+#endif
+  UT_Close();
+  UT_set_mode(mode);
+  if (UT_Init (baudrate, 100, flow_ctrl, NULL, fname)!=0)
+  {
+    strcpy(m_last_config,"");
+    return DRV_INITFAILURE;
+  };
+  /* restart receiver task */
+  if ( os_CreateTask ( 0, (char*)"EXTR", (void (*)(OS_HANDLE, ULONG))(SER_Receiver), 2048, 1,
+                       &SER_Data.TaskHandle, ext_data_pool_handle) != OS_OK  ||
+                       os_StartTask ( 0, SER_Data.TaskHandle, 0 ) != OS_OK)
+  {
+    return DRV_INITFAILURE;
+  }
+
+  return DRV_OK;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_Init            |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+USHORT SER_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{
+static const T_DRV_EXPORT SER_Info =
+{
+  "SER",
+  CALLED_FROM_ISR,
+  {
+#ifdef _TOOLS_
+    SER_Init,
+#endif
+    SER_Exit,
+    SER_Read,
+    SER_Write,
+    NULL,
+    NULL,
+    NULL,
+    SER_SetSignal,
+    SER_ResetSignal,
+    SER_SetConfig,
+    NULL,
+    NULL,
+  }
+};
+
+  SER_Data.Handle = DrvHandle;
+
+  SER_Data.EnabledSignalType = 0;
+
+  SER_Data.Callback = CallbackFunc;
+
+  SER_Data.Connected = FALSE;
+
+  SER_Data.TaskHandle = OS_ERROR;
+
+#ifndef _TOOLS_
+  UT_set_mode(UT_MODE_SIM);
+  UT_Init (2, 100, 'N', NULL, NULL);
+  UT_SetFlowCtrl ('N');
+  if ( os_CreateTask ( 0, (char*)"EXTR", (void (*)(OS_HANDLE, ULONG))(SER_Receiver), 2048, 1,
+                       &SER_Data.TaskHandle, ext_data_pool_handle) == OS_OK )
+  {
+    if ( os_StartTask ( 0, SER_Data.TaskHandle, 0 ) != OS_OK)
+      printf ( "SYSTEM ERROR: Cannot start task EXTR" );
+  }
+  else
+    printf ( "SYSTEM ERROR: Cannot create task EXTR" );
+#endif
+
+  m_last_config[0]='\0';
+
+  *DrvInfo = &SER_Info;
+
+  return DRV_OK;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/ser_sd.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,226 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       ser_sd.c
++------------------------------------------------------------------------------
+|  Copyright 2004 Texas Instruments Deutschland, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Deutschland, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the serial driver adaptation
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __SER_SD_C__
+#define __SER_SD_C__
+#endif
+
+#include "typedefs.h"
+#include "stack1_serial.h"
+#include "gdi.h"
+#include "tstheader.h"
+
+/*==== TYPES ======================================================*/
+
+typedef struct
+{
+  USHORT Handle;
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+  char Connected;
+} T_SER_SD_DATA;
+
+/*==== CONSTANTS ==================================================*/
+
+#define ALLOWED_SER_SD_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT)
+
+/*==== EXTERNALS ==================================================*/
+
+
+/*==== VARIABLES ==================================================*/
+
+T_SER_SD_DATA SER_SD_Data;
+static T_DRV_SIGNAL Signal;
+
+/*==== FUNCTIONS ==================================================*/
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : Callback            |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+void Callback ( void )
+{
+	if ( SER_SD_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+  {
+    Signal.SignalType = DRV_SIGTYPE_READ;
+	  Signal.DrvHandle = SER_SD_Data.Handle;
+
+    (SER_SD_Data.Callback)( &Signal );
+  }
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SD_Exit         |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+void SER_SD_Exit ( void )
+{
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SD_Read         |
++--------------------------------------------------------------------+
+
+  PURPOSE : read data from driver
+
+*/
+USHORT SER_SD_Read ( void *Buffer, ULONG *BytesToRead )
+{
+  *BytesToRead = stack1_Serial_receiveData ( (unsigned char*)Buffer, *BytesToRead ); 
+  return DRV_OK;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SD_Write        |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+USHORT SER_SD_Write ( void *Buffer, ULONG *BytesToWrite )
+{
+ULONG ToWrite = *BytesToWrite & ~PRIM_FLAG_MASK;
+
+   /* stack1_Serial_sendData() returns TRUE/FALSE but not the number of written bytes */
+  stack1_Serial_sendData( (unsigned char*)Buffer, ToWrite );
+  return ( DRV_OK );
+}
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SD_SetSignal    |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+USHORT SER_SD_SetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_SER_SD_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    SER_SD_Data.EnabledSignalType |= SignalType;
+
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SD_ResetSignal  |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+USHORT SER_SD_ResetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_SER_SD_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    SER_SD_Data.EnabledSignalType &= ~SignalType;
+
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SD_SetConfig    |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+*/
+USHORT SER_SD_SetConfig ( char *Buffer )
+{
+
+  if ( !SER_SD_Data.Connected )
+  {
+    Signal.SignalType = DRV_SIGTYPE_CONNECT;
+	  Signal.DrvHandle = SER_SD_Data.Handle;
+    Signal.UserData = NULL;
+    (SER_SD_Data.Callback)( &Signal );
+    SER_SD_Data.Connected = TRUE;
+    return DRV_OK;
+  }
+  return DRV_OK;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_SD_Init         |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+USHORT SER_SD_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{
+static const T_DRV_EXPORT SER_SD_Info =
+{
+  "SER",
+  CALLED_FROM_ISR,
+  {
+#ifdef _TOOLS_
+    SER_SD_Init,
+#endif
+    SER_SD_Exit,
+    SER_SD_Read,
+    SER_SD_Write,
+    NULL,
+    NULL,
+    NULL,
+    SER_SD_SetSignal,
+    SER_SD_ResetSignal,
+    SER_SD_SetConfig,
+    NULL,
+    NULL,
+  }
+};
+
+  SER_SD_Data.Handle = DrvHandle;
+  SER_SD_Data.EnabledSignalType = 0;
+  SER_SD_Data.Callback = CallbackFunc;
+  SER_SD_Data.Connected = FALSE;
+   
+  stack1_Serial_PowerUp ( Callback );
+
+  *DrvInfo = &SER_SD_Info;
+
+  return DRV_OK;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/ser_tr.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,253 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       ser_tr.c
++------------------------------------------------------------------------------
+|  Copyright 2004 Texas Instruments Deutschland, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Deutschland, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the serial driver adaptation
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __SER_TR_C__
+#define __SER_TR_C__
+#endif
+
+#include "typedefs.h"
+#include "traceswitch.h"
+#include "serialswitch.h"
+#include "gdi.h"
+#include "tstheader.h"
+
+/*==== TYPES ======================================================*/
+
+typedef struct
+{
+  USHORT Handle;
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+  char Connected;
+} T_SER_TR_DATA;
+
+/*==== CONSTANTS ==================================================*/
+
+#define ALLOWED_SER_TR_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT)
+
+/*==== EXTERNALS ==================================================*/
+
+#ifdef RUN_FLASH
+ USHORT SER_TR_Write ( void *Buffer, ULONG *BytesToWrite );
+#endif
+
+/*==== VARIABLES ==================================================*/
+
+#ifndef RUN_INT_RAM
+T_SER_TR_DATA SER_TR_Data;
+#endif
+static T_DRV_SIGNAL Signal;
+
+/*==== FUNCTIONS ==================================================*/
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : Callback            |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+void Callback ( void )
+{
+	if ( SER_TR_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+  {
+    Signal.SignalType = DRV_SIGTYPE_READ;
+	  Signal.DrvHandle = SER_TR_Data.Handle;
+
+    (SER_TR_Data.Callback)( &Signal );
+  }
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_TR_Exit         |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+void SER_TR_Exit ( void )
+{
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_TR_Read         |
++--------------------------------------------------------------------+
+
+  PURPOSE : read data from driver
+
+*/
+USHORT SER_TR_Read ( void *Buffer, ULONG *BytesToRead )
+{
+  *BytesToRead = (USHORT)SER_tr_ReadNChars ( SER_LAYER_1, Buffer, *BytesToRead );
+  return DRV_OK;
+}
+#endif
+
+
+#ifndef RUN_FLASH
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_TR_Write        |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+USHORT SER_TR_Write ( void *Buffer, ULONG *BytesToWrite )
+{
+ULONG ToWrite = *BytesToWrite & ~PRIM_FLAG_MASK;
+ULONG BytesWritten;
+char *ptr = (char*)Buffer;
+
+  ptr--;
+  *ptr = 0x13;
+  ToWrite += 1;
+  BytesWritten = (ULONG)SER_tr_WriteNBytes (SER_LAYER_1, (SYS_UWORD8*)ptr, (SYS_UWORD32)ToWrite);
+  *BytesToWrite = BytesWritten;
+
+  return ( DRV_OK );
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_TR_SetSignal    |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+USHORT SER_TR_SetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_SER_TR_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    SER_TR_Data.EnabledSignalType |= SignalType;
+
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_TR_ResetSignal  |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+USHORT SER_TR_ResetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_SER_TR_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    SER_TR_Data.EnabledSignalType &= ~SignalType;
+
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_TR_SetConfig    |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+*/
+USHORT SER_TR_SetConfig ( char *Buffer )
+{
+
+  if ( !SER_TR_Data.Connected )
+  {
+    Signal.SignalType = DRV_SIGTYPE_CONNECT;
+	  Signal.DrvHandle = SER_TR_Data.Handle;
+    Signal.UserData = NULL;
+    (SER_TR_Data.Callback)( &Signal );
+    SER_TR_Data.Connected = TRUE;
+    return DRV_OK;
+  }
+  return DRV_OK;
+}
+#endif
+
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : SER                 |
+| STATE   : code                       ROUTINE : SER_TR_Init         |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+USHORT SER_TR_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{
+static const T_DRV_EXPORT SER_TR_Info =
+{
+  "SER",
+  CALLED_FROM_ISR,
+  {
+#ifdef _TOOLS_
+    SER_TR_TR_Init,
+#endif
+    SER_TR_Exit,
+    SER_TR_Read,
+    SER_TR_Write,
+    NULL,
+    NULL,
+    NULL,
+    SER_TR_SetSignal,
+    SER_TR_ResetSignal,
+    SER_TR_SetConfig,
+    NULL,
+    NULL,
+  }
+};
+
+  SER_TR_Data.Handle = DrvHandle;
+  SER_TR_Data.EnabledSignalType = 0;
+  SER_TR_Data.Callback = CallbackFunc;
+  SER_TR_Data.Connected = FALSE;
+
+  SER_tr_Init ( SER_LAYER_1, TR_BAUD_115200, Callback ); 
+  *DrvInfo = &SER_TR_Info;
+
+  return DRV_OK;
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/socket.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,1896 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       socket.c
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the socket driver adaptation
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifdef _VXWORKS_
+#define GNU_COMPILER
+#endif
+
+#undef SOCK_TRACE
+
+#undef SOCKET_DEBUG
+
+/*==== INCLUDES =============================================================*/
+
+#if defined _NUCLEUS_ || defined _TOOLS_   /* socket-driver running on windows OS */
+/*lint -e717 suppress info do...while(0); */
+/*lint -esym(550,rc) suppress info not accessed */
+/*lint -e813, suppress Info 813: auto variable has size > 100 -> uncritical in this context */
+/*lint -e801, suppress Info 801: Use of goto is deprecated */
+  #include <windows.h>
+  #include <winsock.h>
+  #include <stdio.h>
+  #ifdef SOCK_TRACE
+    #include <stdio.h>
+    #include <fcntl.h>
+    #include <io.h>
+  #endif  /* SOCK_TRACE */
+#endif  /* #ifdef _NUCLEUS_ */
+
+#ifdef _PSOS_                /* socket-driver running on pSOS */
+  #define _PNA_30_BACK
+  #include <psos.h>
+  #include "bsp.h"
+  #include <pna.h>
+  #include <prepc.h>
+  #include <rescfg.h>
+#endif /* #ifdef _PSOS_ */
+
+#ifdef _VXWORKS_
+  #include "vxWorks.h"
+  #include "sockLib.h"
+  #include "inetLib.h"
+  #include "ioLib.h"
+  #include "selectLib.h"
+  #include "errnoLib.h"
+  #include "logLib.h"
+/* undefine the MALLOC and FREE of VxWorks to avoid warnings */
+#undef MALLOC
+#undef FREE
+#endif  /* _VXWORKS_ */
+
+/* More operating systems go here */
+
+#ifdef _LINUX_
+  #include <sys/types.h>
+  #include <sys/socket.h>
+  #include <netinet/in.h>
+  #include <netinet/tcp.h>
+  #include <sys/ioctl.h>
+  #include <errno.h>
+  #include <netdb.h>
+#endif
+
+#ifdef _SOLARIS_
+  #include <sys/types.h>
+  #include <sys/socket.h>
+  #include <netinet/in.h>
+  #include <netinet/tcp.h>
+  #include <sys/ioctl.h>
+  #include <errno.h>
+  #include <netdb.h>
+  #include <sys/filio.h>
+#endif
+
+#ifndef OLD_FRAME
+  #include "typedefs.h"
+  #include "os.h"
+#endif
+
+#include "socket.h"
+#include "tools.h"
+#include "vsi.h"
+#include "drvconf.h"
+#include "tstheader.h"
+
+/*==== DEFINITIONS ==========================================================*/
+
+#define MAX_PENDING_CONNECTS  5          /* The backlog allowed for listen() */
+#define SEND_TIMEOUTUSEC      500        /* minimal timeout value for sending*/
+#define INVALID_HANDLE        NULL
+#define INVALID_SIGNALTYPE    0
+#define NO_FLAGS_SET          0          /* Used with recv()/send()          */
+#define MAX_ETH_LEN           (1500-40)  /* Maximum size of a Ethernet packet without IP headers */
+#define WRBUF_LEN             2048
+
+#define ALLOWED_SOCKET_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT|DRV_SIGTYPE_DISCONNECT)
+
+#if defined _NUCLEUS_ || defined _TOOLS_
+    typedef ULONG SIZETYPE;
+    #define GETTIME(t)           (t = GetTickCount())
+    #define GETREADSIZE(sok,psiz) ioctlsocket(sok, FIONREAD,(ULONG*)psiz)
+    #define READ_SOCKET(s,b,l)    recv((s),(b),(int)(l),NO_FLAGS_SET)
+    #define WRITE_SOCKET(s,b,l)   send((s),(const char*)(b),(l),NO_FLAGS_SET)
+    #define CLOSE_SOCKET(s)       closesocket(s)
+#endif /* #ifdef _NUCLEUS_ */
+
+#ifdef _PSOS_
+  typedef int SOCKET;
+  typedef int SIZETYPE;
+  typedef struct hostent HOSTENT;
+  #define h_addr  h_addr_list[0]
+  typedef HOSTENT *  PHOSTENT;
+  #define FAR /**/
+  #define SOCKADDR_IN struct sockaddr_in
+  #define SOCKET_ERROR   (-1)
+  #define INVALID_SOCKET (-1)
+  #define GETTIME(t)            os_GetTime (0, &(t))
+  #define GETREADSIZE(sok,psiz) ioctl(sok, FIOREAD,(char*)psiz)
+  #define READ_SOCKET(s,b,l)    recv((s),(b),(int)(l),NO_FLAGS_SET)
+  #define WRITE_SOCKET(s,b,l)   send((s),(char *)(b),(int)(l),NO_FLAGS_SET)
+  #define CLOSE_SOCKET(s)       close(s)
+#endif /* #ifdef _PSOS_ */
+
+#ifdef _VXWORKS_
+  #define SOCKADDR_IN    struct sockaddr_in
+  #define FAR /* nil */
+  #define SOCKET_ERROR   ERROR
+  #define INVALID_SOCKET ERROR
+  typedef int SOCKET;
+  typedef int SIZETYPE;
+  #define GETTIME(t)            os_GetTime (0, &(t))
+  #define GETREADSIZE(sok,psiz) ioctl(sok, FIONREAD, (int)psiz)
+  #define READ_SOCKET(s,b,l)    recv((s), (b), (int)(l), NO_FLAGS_SET)
+  #define WRITE_SOCKET(s,b,l)   send((s), (char *)(b), (int)(l), NO_FLAGS_SET)
+  #define CLOSE_SOCKET(s)       close(s)
+#endif /* _VXWORKS_ */
+
+#if defined (_LINUX_) || defined (_SOLARIS_)
+  #define SOCKADDR_IN    struct sockaddr_in
+  #define FAR /* nil */
+  #define SOCKET_ERROR   (-1)
+  #define INVALID_SOCKET (-1)
+  typedef int SIZETYPE;
+  #define GETTIME(t)            os_GetTime (0, &(t))
+  #define GETREADSIZE(sok,psiz) ioctl(sok, FIONREAD, (int)psiz)
+  #define READ_SOCKET(s,b,l)    recv((s), (b), (int)(l), NO_FLAGS_SET)
+  #define WRITE_SOCKET(s,b,l)   send((s), (char *)(b), (int)(l), NO_FLAGS_SET)
+  #define CLOSE_SOCKET(s)       close(s)
+#endif /* _VXWORKS_ */
+
+#define PORT_NO              6392
+#define TX_BUFFER_SIZE       8192
+#define RX_BUFFER_SIZE       8192
+#define TX_TIMEOUT_MSEC     10000
+#define RX_TIMEOUT_MSEC     10000
+
+#ifdef _VXWORKS_
+#define SOCKET_PRIO    115
+#define SOCKET_STACK  8192
+#elif defined _PSOS_
+#define SOCKET_PRIO    110
+#define SOCKET_STACK  1024
+#elif defined _TOOLS_
+#define SOCKET_PRIO      1
+#define SOCKET_STACK  1024
+#else
+#define SOCKET_PRIO      1
+#define SOCKET_STACK  1024
+#endif
+
+#define TI_MODE     0x0001
+
+/*==== TYPES ================================================================*/
+typedef enum
+{
+  SST_PL0,     /* 0 bytes of packet length read*/
+  SST_PL1,     /* 1 bytes of packet length read*/
+  SST_DATA0,   /* 0 bytes of data read*/
+  SST_DATAx    /* not all data read */
+} T_SOCK_STATE;
+
+typedef struct
+{
+  USHORT            Connect;
+  SOCKET            Listener;
+  SOCKET            Socket;
+  USHORT            EnabledSignals;
+  OS_HANDLE         ThreadID ;
+  USHORT            SocketHandle;
+  T_DRV_CB_FUNC     Callback;
+} Client_Type;
+
+/*==== EXTERNALS ============================================================*/
+EXTERN BOOL           socket_flush;
+
+/*==== LOCAL VARS ===========================================================*/
+
+LOCAL socket_DCB_Type L_DCB ;
+LOCAL Client_Type     L_ClientData ;
+LOCAL BOOL            L_ThreadActive ;
+LOCAL T_DRV_SIGNAL    SocketSignal;
+LOCAL UBYTE    wrbuf[WRBUF_LEN+2];
+LOCAL UBYTE   *wrbuf_pos = wrbuf;
+T_SOCK_STATE   sock_state = SST_PL0;
+
+#ifdef SOCK_TRACE
+ULONG                 fh_sock = -1;
+LOCAL char            stbuf[80];
+#endif
+
+LOCAL BOOL     isLittleEndian = TRUE;
+int tst_socket; /* for psos */
+int tst_socket_initialized; /* flag for pSOS */
+int tst_socket_in_TxLen;    /* for pSOS */
+
+
+/*==== DIAGNOSTICS ==========================================================*/
+
+#ifdef SOCKET_DEBUG
+#include <STDIO.H>
+static char *logfile = "socket.log";
+static char *bufferfullfile = "bufferfull.log";
+static char *inprocessfile = "inprogress.log";
+static char *noconnectfile1 = "noconnect1.log";
+static char *noconnectfile2 = "noconnect2.log";
+static char *noconnectfile3 = "noconnect3.log";
+static char *readerrorfile = "readerror.log";
+static FILE *fp = NULL;
+#endif /* SOCKET_DEBUG */
+
+/*==== END DIAGNOSTICS ======================================================*/
+
+extern USHORT ext_data_pool_handle;
+
+GLOBAL ULONG drv_socket_task_stack_size = SOCKET_STACK;
+GLOBAL USHORT drv_socket_task_prio = SOCKET_PRIO;
+
+/*==== PRIVATE FUNCTIONS ====================================================*/
+/*
++------------------------------------------------------------------------------
+|  Function    : L_CreateThread
++------------------------------------------------------------------------------
+|  Description : This function creates a thread.
+|
+|  Parameters  : ThreadFunc        - pointer to the function beeing a thread
+|
+|  Return      : FALSE             - Thread not created
+|                TRUE              - Thread create (Thread ID stored in
+|                                    L_ClientData.ThreadID
+|
++------------------------------------------------------------------------------
+*/
+#ifdef OLD_FRAME
+BOOL L_CreateThread (USHORT (*ThreadFunc)(USHORT,ULONG))
+{
+  return (CreateThread ((LPSECURITY_ATTRIBUTES) NULL,
+                0,
+                (LPTHREAD_START_ROUTINE)ThreadFunc,
+                (LPVOID) NULL,
+                0,
+                &L_ClientData.ThreadID) != NULL);
+}
+#else
+BOOL L_CreateThread (void (*ThreadFunc)(T_HANDLE,ULONG))
+{
+  if ( os_CreateTask (0, (char*)"SOCKET", ThreadFunc, drv_socket_task_stack_size, drv_socket_task_prio, &L_ClientData.ThreadID, ext_data_pool_handle) < 0L )
+    return FALSE;
+  if ( os_StartTask (0, L_ClientData.ThreadID, 0) < 0 )
+    return FALSE ;
+
+  return TRUE;
+}
+#endif
+
+/*
++------------------------------------------------------------------------------
+|  Function    : L_SetSocketBuffer
++------------------------------------------------------------------------------
+|  Description : This function sets the IP read and write buffer
+|
+|  Parameters  : in_TxLen          - size of transmission buffer
+|                in_RxLen          - size of receiver buffer
+|
+|  Return      : FALSE             - either the read or write buffer could not
+|                                    be set.
+|                TRUE              - OK
+|
++------------------------------------------------------------------------------
+*/
+LOCAL BOOL L_SetSocketBuffer (USHORT  in_TxLen, USHORT in_RxLen)
+{
+  int in_TxLen1 = (int) in_TxLen;
+  int in_RxLen1 = (int) in_RxLen;
+#ifndef _PSOS_
+  int nodelay = TRUE;
+#if defined (_VXWORKS_) || defined (_LINUX_) || defined (_SOLARIS_)
+  struct linger nolinger = {0, 0};
+#else
+  int linger = TRUE;
+#endif
+  int rc=0;
+
+  if (in_TxLen > 0)
+  {
+    if ( (rc=setsockopt(L_ClientData.Socket, SOL_SOCKET, SO_SNDBUF,
+                   (char*)&in_TxLen1, sizeof(in_TxLen1))) != 0)
+    {
+#ifdef _VXWORKS_
+      rc = errnoGet ();
+#else
+  #if defined (_LINUX_) || defined (_SOLARIS_)
+      rc = errno;
+  #else
+      rc = WSAGetLastError();
+  #endif
+#endif
+#if defined _NUCLEUS_ || defined _TOOLS_
+      printf("SOCKET: setsockopt() returned error code %d\n", rc); 
+#endif
+      return FALSE ;
+    }
+  }
+#if defined (_VXWORKS_) || defined (_LINUX_) || defined (_SOLARIS_)
+  if (setsockopt(L_ClientData.Socket, SOL_SOCKET, SO_LINGER,
+               (char*)&nolinger, sizeof(nolinger)))
+#else
+  if (setsockopt(L_ClientData.Socket, SOL_SOCKET, (int)SO_DONTLINGER,
+               (char*)&linger, sizeof(linger)))
+#endif
+    return FALSE ;
+  if (setsockopt(L_ClientData.Socket, IPPROTO_TCP, TCP_NODELAY,
+               (char*)&nodelay, sizeof(nodelay)))
+    return FALSE ;
+
+#else /* PSOS */
+  tst_socket_in_TxLen = in_TxLen;
+#endif /* PSOS */
+  if (in_RxLen > 0)
+  {
+    if (setsockopt(L_ClientData.Socket, SOL_SOCKET, SO_RCVBUF,
+                   (char *) &in_RxLen1, sizeof(in_RxLen1)))
+      return FALSE ;
+  }
+
+  return TRUE ;
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function    : L_Disconnect
++------------------------------------------------------------------------------
+|  Description : This function is called when the connection to the peer entity
+|                is lost. If the release signal is set a signal is generated.
+|
+|  Parameters  :  -
+|
+|  Return      :  -
+|
++------------------------------------------------------------------------------
+*/
+LOCAL void L_Disconnect (void)
+{
+
+  L_ClientData.Connect = FALSE;
+  if (L_ClientData.EnabledSignals != INVALID_SIGNALTYPE)
+  {
+    SocketSignal.SignalType = DRV_SIGTYPE_DISCONNECT;
+    SocketSignal.DrvHandle = L_ClientData.SocketHandle;
+    (*L_ClientData.Callback)(&SocketSignal) ;
+  }
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function    : L_AsyncSelect
++------------------------------------------------------------------------------
+|  Description : This function waits (blocking) for either something to read
+|                or an execption on the socket.
+|
+|  Parameters  : -
+|
+|  Return      : FALSE             - failure on the socket
+|                TRUE              - a read event was signalled
+|
++------------------------------------------------------------------------------
+*/
+LOCAL BOOL L_AsyncSelect (void)
+{
+  fd_set  fd_r ;
+  fd_set  fd_e ;
+  int     status, rc;
+
+  /* wait for possibility to read */
+  FD_ZERO(&fd_r);
+  FD_SET(L_ClientData.Socket, &fd_r);
+  FD_ZERO(&fd_e);
+  FD_SET(L_ClientData.Socket, &fd_e);
+
+  status = select(FD_SETSIZE, &fd_r, NULL, &fd_e, (struct timeval *) 0);
+
+  if (status > 0)
+  {
+    if (!FD_ISSET (L_ClientData.Socket, &fd_e))
+    {
+      if (L_ClientData.Callback != NULL)
+      {
+        if (FD_ISSET (L_ClientData.Socket, &fd_r))
+        {
+          SIZETYPE size ;
+
+          if ((rc = GETREADSIZE( L_ClientData.Socket, &size)) != 0 || !size)
+          {
+#ifdef SOCK_TRACE
+            if (fh_sock != -1)
+            {
+              char sstop[10];
+              ULONG stop = GetTickCount();
+
+              sprintf(sstop, "%03d:%03d",  (stop/1000) % 1000, stop % 1000);
+              sprintf(stbuf, "reset at %s rc=%d size=%d left %d \n",
+                              sstop, rc, size,
+                              wrbuf_pos-wrbuf);
+              write (fh_sock, stbuf, strlen(stbuf));
+/*              close(fh_sock);
+              fh_sock = -1; */
+            }
+#endif
+            os_SuspendTask ( 0, 2 );
+            CLOSE_SOCKET (L_ClientData.Socket);
+            L_ClientData.Socket = INVALID_SOCKET;
+            wrbuf_pos = wrbuf;
+            sock_state = SST_PL0;
+            return FALSE ;
+          }
+
+          /* Indicate that it is possible to read something */
+          if (L_ClientData.EnabledSignals & DRV_SIGTYPE_READ)
+          {
+            SocketSignal.SignalType = DRV_SIGTYPE_READ;
+            SocketSignal.DrvHandle = L_ClientData.SocketHandle;
+            (*L_ClientData.Callback)(&SocketSignal) ;
+          }
+        }
+      }
+      return TRUE ;
+    }
+  }
+  return FALSE;
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function    : L_ClientThread
++------------------------------------------------------------------------------
+|  Description : This function is a thread used if the driver is configured to
+|                be a client.
+|
+|  Parameters  : -
+|
+|  Return      : -
+|
++------------------------------------------------------------------------------
+*/
+void L_ClientThread (T_HANDLE Handle, ULONG Value )
+{
+  L_ThreadActive = TRUE ;
+
+  L_SetSocketBuffer (L_DCB.tx_buffer_size, L_DCB.rx_buffer_size) ;
+
+  /*-------------------------------------
+    Listen what's goning on on the socket
+    -------------------------------------*/
+  while (L_ThreadActive)
+    if (!L_AsyncSelect())
+    {
+      L_ThreadActive = FALSE ;
+      L_Disconnect() ;
+    }
+}
+
+
+/*
++------------------------------------------------------------------------------
+|  Function    : L_ServerThread
++------------------------------------------------------------------------------
+|  Description : This function is a thread used if the driver is configured to
+|                be a server. It serves only one client. It cycles between
+|                two modes, wait for a client to connect and listening on the
+|                connection for any further action.
+|                The thread exits when the flag L_ThreadActive is set to false.
+|
+|  Parameters  : -
+|
+|  Return      : -
+|
++------------------------------------------------------------------------------
+*/
+void L_ServerThread (T_HANDLE TaskHandle, ULONG Value)
+{
+  BOOL BufferSizeSet;
+  SOCKADDR_IN local_sin;                      /* Local socket - internet style */
+#ifdef _VXWORKS_
+  SOCKADDR_IN clientAddr;                     /* client */
+  int sockAddrSize = sizeof (struct sockaddr_in);
+
+  memset ((char *) &local_sin, 0, sockAddrSize);
+  local_sin.sin_len = (u_char) sockAddrSize;
+#endif/* _VXWORKS_ */
+  L_ClientData.Listener = socket (AF_INET, SOCK_STREAM, 0);
+  if (L_ClientData.Listener == INVALID_SOCKET)
+    goto error;
+
+  if (L_DCB.port == SOCKET_INVALID_PORT)
+    goto error;
+
+  local_sin.sin_addr.s_addr = htonl(INADDR_ANY);
+  local_sin.sin_family = AF_INET;
+  local_sin.sin_port = htons(L_DCB.port);      /* Convert to network ordering */
+
+  /*-------------------------------------------
+    Associate an address with a socket. (bind)
+    -------------------------------------------*/
+#ifdef _PSOS_
+  if (bind (L_ClientData.Listener, (struct sockaddr_in*) &local_sin, sizeof(local_sin)) != 0)
+#else
+#ifdef _VXWORKS_
+  /* Look at the following cast of local_sin.
+   * This is from VxWorks Network 5.4 Programmer’s Guide, example 7-1, page 131
+   */
+  if (bind (L_ClientData.Listener, (struct sockaddr*) &local_sin, sockAddrSize) == ERROR)
+#else /* _VXWORKS_ */
+  if (bind (L_ClientData.Listener, (const struct sockaddr FAR *) &local_sin, sizeof(local_sin)) != 0)
+#endif /* _VXWORKS_ */
+#endif
+  {
+    CLOSE_SOCKET (L_ClientData.Listener);
+    goto error;
+  }
+#ifdef _VXWORKS_
+  if (listen (L_ClientData.Listener, MAX_PENDING_CONNECTS) == ERROR)
+#else /* _VXWORKS_ */
+  if (listen (L_ClientData.Listener, MAX_PENDING_CONNECTS) != 0)
+#endif /* _VXWORKS_ */
+  {
+    CLOSE_SOCKET (L_ClientData.Listener);
+    goto error;
+  }
+
+  BufferSizeSet = FALSE ;
+  L_ThreadActive = TRUE ;
+
+  while (L_ThreadActive)
+  {
+    /*-------------------------------------
+      Wait for somebody to connect
+      -------------------------------------*/
+    if (L_ClientData.Socket != INVALID_SOCKET)
+    {
+#ifdef SOCK_TRACE
+      if (fh_sock != -1)
+      {
+        char sstop[10];
+        ULONG stop = GetTickCount();
+
+        sprintf(sstop, "%03d:%03d",  (stop/1000) % 1000, stop % 1000);
+        sprintf(stbuf, "close at %s socket=%d\n",
+                        sstop, L_ClientData.Socket);
+        write (fh_sock, stbuf, strlen(stbuf));
+/*      close(fh_sock);
+        fh_sock = -1;   */
+      }
+#endif
+      CLOSE_SOCKET (L_ClientData.Socket);
+      L_ClientData.Socket = INVALID_SOCKET;
+      wrbuf_pos = wrbuf;
+      sock_state = SST_PL0;
+    }
+#ifdef _VXWORKS_
+    if ((L_ClientData.Socket = accept (L_ClientData.Listener,
+                                       (struct sockaddr *) &clientAddr,
+                                       &sockAddrSize)) != ERROR)
+#else /* _VXWORKS_ */
+    L_ClientData.Socket = accept(L_ClientData.Listener, NULL, NULL) ;
+    if (L_ClientData.Socket != INVALID_SOCKET)
+#endif /* _VXWORKS_ */
+    {
+#ifdef SOCK_TRACE
+      if (fh_sock == -1)
+        fh_sock = open("SOCK_S.dbg", O_WRONLY| O_TEXT| O_TRUNC| O_CREAT, 0666);
+      if (fh_sock != -1)
+      {
+        char sstop[10];
+        ULONG stop = GetTickCount();
+
+        sprintf(sstop, "%03d:%03d",  (stop/1000) % 1000, stop % 1000);
+        sprintf(stbuf, "accept at %s socket=%d listener=%d\n",
+                        sstop, L_ClientData.Socket, L_ClientData.Listener);
+        write (fh_sock, stbuf, strlen(stbuf));
+      }
+#endif
+
+#ifdef _PSOS_
+      {
+        ULONG tid;
+        int err;
+        /* for pSOS */
+        /* wait for TST task */
+        while( t_ident( FRM_TST_NAME, 0, &tid ) != 0 )
+          tm_wkafter( 10 );
+
+        tst_socket = shr_socket( L_ClientData.Socket, (int)tid );
+        if( tst_socket < 0 )
+        {
+          err = errno;
+          goto error;
+        }
+      }
+#endif
+
+      if (!BufferSizeSet)
+        L_SetSocketBuffer (L_DCB.tx_buffer_size, L_DCB.rx_buffer_size) ;
+
+      /* Signalisiere Connect */
+      L_ClientData.Connect = TRUE;
+      if (L_ClientData.EnabledSignals & DRV_SIGTYPE_CONNECT)
+      {
+        SocketSignal.SignalType = DRV_SIGTYPE_CONNECT;
+        SocketSignal.DrvHandle = L_ClientData.SocketHandle;
+        (*L_ClientData.Callback)(&SocketSignal) ;
+      }
+
+      /*-------------------------------------
+        Listen what's goning on on the socket
+        -------------------------------------*/
+      while (L_ThreadActive)
+        if (!L_AsyncSelect())
+        {
+          L_Disconnect() ;
+          break ;
+        }
+    }
+  }
+
+error:
+#ifndef OLD_FRAME
+  for(;;)
+    os_SuspendTask( 0, 1000 );
+#endif
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function    : socket_Create
++------------------------------------------------------------------------------
+|  Description : This function is used to set up the driver to act as a
+|                server. The function tries to initialize the socket, creates
+|                a thread in which it awaits first awaits the establishement
+|                of a connection by a client. As soon as a client has
+|                connected a signal (SOCKET_CONNECTED) is generated (call
+|                socket_SetSignal() to activate a signal). From this time the
+|                driver is able to send data (socket_write()) to the client and
+|                to read received data (socket_read()). To get notified about
+|                the reception of data the apropriate signal has to be set.
+|                In the case of a successful completion the driver returns
+|                DRV_OK.
+|                If the driver is already busy DRV_INPROCESS is returned.
+|                If the driver is not configured, the function returns
+|                DRV_ NOTCONFIGURED.
+|
+|  Parameters  : -
+|
+|  Return      : DRV_OK             - Function successful
+|                DRV_INPROCESS      - The driver is currently reading data.
+|                                     The data is incomplete.
+|                DRV_NOTCONFIGURED  - The driver is not yet configured
+|                SOCKET_ERRORUNSPEC - Error occured during initialization
+|
++------------------------------------------------------------------------------
+*/
+LOCAL UBYTE L_CreateServer (void)
+{
+  if (!L_CreateThread (L_ServerThread))
+  {
+    CLOSE_SOCKET (L_ClientData.Listener);
+    return SOCKET_ERRUNSPEC;
+  }
+#ifdef _TOOLS_
+  printf("SOCKET: now listening on port %i ...\n",L_DCB.port); 
+#endif
+
+  return DRV_OK ;
+}
+/*
++------------------------------------------------------------------------------
+| Function    : socket_WriteToOS
++------------------------------------------------------------------------------
+| Description : This function is used to write data to the driver of operating
+|               system.
+|               The parameter thr_BufferSize contains the number of
+|               characters to write. In the case of a successful completion,
+|               the function returns DRV_OK.
+|
+| Parameters  : in_BufferPtr          - This parameter points to the buffer
+|                                       that is passed to the driver for
+|                                       further processing
+|               thr_BufferSize        - number of characters to write.
+|
+| Return      : DRV_OK            - Function successful
+|               DRV_INPROCESS     - Driver is busy writing data
+|               SOCKET_NOCONNECT  - Connection not available
+|
++------------------------------------------------------------------------------
+*/
+LOCAL UBYTE socket_WriteToOS (void*  in_BufferPtr, USHORT thr_BufferSize)
+{
+  int             err;
+  USHORT          c_written;
+#ifndef _PSOS_
+  fd_set          fd_w;
+  fd_set          fd_e;
+  struct timeval  tv;
+
+  if (L_ClientData.Socket == INVALID_SOCKET)
+    return SOCKET_NOCONNECT;
+
+  if ( L_ClientData.Connect == FALSE )
+    return SOCKET_NOCONNECT ;
+
+  tv.tv_sec = (int)(L_DCB.tx_timeout_msec / 1000) ;
+  tv.tv_usec = SEND_TIMEOUTUSEC ;
+
+  FD_ZERO(&fd_w);
+  FD_SET(L_ClientData.Socket, &fd_w);
+  FD_ZERO(&fd_e);
+  FD_SET(L_ClientData.Socket, &fd_e);
+
+  if (select(FD_SETSIZE, NULL, &fd_w, &fd_e, &tv) <= 0)
+  {
+#ifdef SOCKET_DEBUG
+    char buffer[200];
+    char *ptr = in_BufferPtr;
+    char c = ptr[21];
+    fp = fopen(inprocessfile, "at");
+    if ( *ptr == 'P' )
+      ptr[21] = 0;
+    else
+      ptr[thr_BufferSize] = 0;
+    strcpy (buffer, "errno:" );    
+    sprintf (&buffer[6], "%8d", WSAGetLastError() );
+    buffer[14] = ' ';
+    memcpy (&buffer[15], ptr, (thr_BufferSize)+1);
+    fprintf (fp, "%s\n", buffer );
+    ptr[21] = c;
+    fclose(fp);
+#endif  /* SOCKET_DEBUG */
+#ifdef _VXWORKS_
+    err = errnoGet ();
+#else /* _VXWORKS_ */
+    err = errno;
+    printf("SOCKET: socket write failed with error code: %d\n",err );
+#endif /* _VXWORKS_ */
+
+    return DRV_INPROCESS ;
+  }
+
+  if (FD_ISSET (L_ClientData.Socket, &fd_e))
+  {
+#ifdef SOCKET_DEBUG
+    char buffer[200];
+    char *ptr = in_BufferPtr;
+    char c = ptr[21];
+    fp = fopen(noconnectfile1, "at");
+    if ( *ptr == 'P' )
+      ptr[21] = 0;
+    else
+      ptr[thr_BufferSize] = 0;
+    strcpy (buffer, "errno:" );
+    sprintf (&buffer[6], "%8d", WSAGetLastError() );
+    buffer[14] = ' ';
+    memcpy (&buffer[15], ptr, (thr_BufferSize)+1);
+    fprintf (fp, "%s\n", buffer );
+    ptr[21] = c;
+    fclose(fp);
+#endif  /* SOCKET_DEBUG */
+    return SOCKET_NOCONNECT ;
+  }
+
+  /*---------------------------------
+    Send the data
+    ---------------------------------*/
+  c_written = (USHORT) WRITE_SOCKET(L_ClientData.Socket, in_BufferPtr, (USHORT)thr_BufferSize);
+
+  if (c_written == (USHORT)SOCKET_ERROR || c_written != thr_BufferSize)
+  {
+#ifdef SOCKET_DEBUG
+    char buffer[200];
+    char *ptr = in_BufferPtr;
+    char c = ptr[21];
+    fp = fopen(noconnectfile2, "at");
+    if ( *ptr == 'P' )
+      ptr[21] = 0;
+    else
+      ptr[thr_BufferSize] = 0;
+    strcpy (buffer, "errno:" );
+    sprintf (&buffer[6], "%8d", WSAGetLastError() );
+    buffer[14] = ' ';
+    memcpy (&buffer[15], ptr, (thr_BufferSize)+1);
+    fprintf (fp, "%s\n", buffer );
+    ptr[21] = c;
+    fclose(fp);
+#endif  /* SOCKET_DEBUG */
+    return SOCKET_NOCONNECT ;
+  }
+
+#ifdef SOCK_TRACE
+  if (fh_sock != -1)
+  {
+    char sstop[10];
+    ULONG stop = GetTickCount();
+
+    sprintf(sstop, "%03d:%03d",  (stop/1000) % 1000, stop % 1000);
+    sprintf(stbuf, "sent %d at %s\n",
+                 thr_BufferSize,
+                 sstop);
+    write (fh_sock, stbuf, strlen(stbuf));
+  }
+#endif
+  return DRV_OK ;
+
+#else
+
+  /* pSOS */
+
+  /*---------------------------------
+    Send the data
+    ---------------------------------*/
+  c_written = (USHORT) WRITE_SOCKET(tst_socket, in_BufferPtr, (USHORT)thr_BufferSize);
+
+  if (c_written == (USHORT)SOCKET_ERROR || c_written != thr_BufferSize)
+  {
+    err = errno;
+    return SOCKET_NOCONNECT ;
+  }
+
+  return DRV_OK ;
+#endif  /* _PSOS_ */
+}
+
+/*==== PUBLIC FUNCTIONS =====================================================*/
+
+/*
++------------------------------------------------------------------------------
+|  Function    : socket_Exit
++------------------------------------------------------------------------------
+|  Description : The function is called when the driver functionality is no
+|                longer required. The function "de-allocates" the resources
+|                and releases active connections. The driver terminates
+|                regardless of any outstanding data to be sent.
+|
+|  Parameters  : -
+|
+|  Return      : -
+|
++------------------------------------------------------------------------------
+*/
+void socket_Exit (void)
+{
+  os_DestroyTask ( 0, L_ClientData.ThreadID );
+  socket_Close() ;
+}
+
+
+/*
++------------------------------------------------------------------------------
+|  Function    : socket_Open
++------------------------------------------------------------------------------
+|  Description : This function is used to establish a connection to server or
+|                activate the driver to act as a server, using the settings of
+|                the socket_DCB. A hostname must be specified to open a
+|                connection to a server, in this case the driver runs in the
+|                client mode. If no hostname is specified the driver will run in
+|                server mode. In the server mode it serves a single client. As
+|                soon as a client is connected the CONNECT signal is generated.
+|                In case of a successful completion the driver is no able to send
+|                data (socket_write()) to the peer entity and to read data
+|                received from the peer entity (socket_read()). To get notified
+|                about the reception of data the appropriate signal has to be set
+|                (socket_SetSignal()).
+|                In the case of a successful completion the driver returns DRV_OK.
+|                If the driver is already busy DRV_INPROCESS is returned.
+|                If the driver is not configured, the function returns
+|                DRV_NOTCONFIGURED.
+|                If an error occurs while establishing the requested mode, the
+|                function returns SOCKET_ERRUNSPEC.
+|
+|  Parameters  : -
+|
+|  Return      : DRV_OK            - Function successful
+|                DRV_INPROCESS     - The driver is currently reading data.
+|                                    The data is incomplete.
+|                DRV_NOTCONFIGURED - The driver is not yet configured
+|                SOCKET_ERRUNSPEC  - Error occured during initialization
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_Open (void)
+{
+  SOCKADDR_IN dest_sin;  /* DESTination Socket INternet */
+  SOCKET      connectsocket;
+#ifdef _VXWORKS_
+  int sockAddrSize;
+#else /* _VXWORKS_ */
+  #if defined (_LINUX_) || defined (_SOLARIS_)
+    struct hostent* phe;
+  #else
+    PHOSTENT    phe;
+  #endif
+#endif /* _VXWORKS_ */
+  if (L_ThreadActive)
+  {
+    return DRV_INPROCESS ;
+  }
+
+  /*---------------------------------
+    if no hostname is specified we
+    open as a server
+    ---------------------------------*/
+  if (!*L_DCB.hostname)
+  {
+    return L_CreateServer() ;
+  }
+
+  connectsocket = socket (AF_INET, SOCK_STREAM, 0);
+  if (connectsocket == INVALID_SOCKET)
+  {
+    return SOCKET_ERRUNSPEC;
+  }
+
+#ifdef _PSOS_
+
+  if ( !gethostbyname(L_DCB.hostname, phe))
+  {
+    CLOSE_SOCKET(connectsocket);
+    return SOCKET_ERRUNSPEC;
+  }
+
+#else /* _PSOS_ */
+  #ifdef _VXWORKS_
+    sockAddrSize = sizeof (struct sockaddr_in);
+    memset((char *) &dest_sin, 0, sockAddrSize);
+    dest_sin.sin_len = (u_char) sockAddrSize;
+    dest_sin.sin_family = AF_INET;
+    dest_sin.sin_port = htons(L_DCB.port);
+    if (((dest_sin.sin_addr.s_addr = inet_addr (L_DCB.hostname)) == ERROR) &&
+    ((dest_sin.sin_addr.s_addr = hostGetByName (L_DCB.hostname)) == ERROR))
+    {
+      CLOSE_SOCKET(connectsocket);
+      return SOCKET_ERRUNSPEC;
+    }
+  #else /* _VXWORKS_ */
+  phe = gethostbyname(L_DCB.hostname);
+  if (!phe)
+  {
+#ifdef _TOOLS_
+    printf("SOCKET: host %s not found ;-(\n",L_DCB.hostname); 
+#endif
+    CLOSE_SOCKET(connectsocket);
+    return SOCKET_ERRUNSPEC;
+  }
+  #endif /* _VXWORKS_ */
+#endif  /* _PSOS_ */
+
+#ifndef _VXWORKS_
+  memset(&dest_sin, 0, sizeof(struct sockaddr_in));
+  memcpy((char*)&(dest_sin.sin_addr), phe->h_addr, (unsigned int)((int)(phe->h_length)));
+  dest_sin.sin_family = AF_INET;
+  if ( L_DCB.config & TI_MODE )
+    dest_sin.sin_port = L_DCB.port;
+  else
+    dest_sin.sin_port = htons(L_DCB.port);
+#endif /* _VXWORKS_ */
+
+#ifdef _PSOS_
+  if (connect (connectsocket, (struct sockaddr_in*) &dest_sin, sizeof(dest_sin)))
+#else /* _PSOS_ */
+  #ifdef _VXWORKS_
+  if (connect (connectsocket, (struct sockaddr*) &dest_sin, sockAddrSize) == ERROR)
+  #else /* _VXWORKS_ */
+    #if defined (_LINUX_) || defined (_SOLARIS_)
+      if (connect (connectsocket, (struct sockaddr*) &dest_sin,
+                   sizeof(dest_sin)))
+    #else
+      if (connect (connectsocket, (const PSOCKADDR) &dest_sin,
+                   sizeof(dest_sin)))
+    #endif
+  #endif /* _VXWORKS_ */
+#endif /* defined(_PSOS_) || defined(_VXWORKS_) */
+  {
+#ifdef _TOOLS_
+    printf("SOCKET: connection to %s on port %i failed ;-(\n",L_DCB.hostname,L_DCB.port); 
+#endif
+    CLOSE_SOCKET(connectsocket);
+    return SOCKET_ERRUNSPEC;
+  }
+#ifdef _TOOLS_
+  printf("SOCKET: successfully connected to %s on port %i\n",L_DCB.hostname,L_DCB.port); 
+#endif
+
+  if (!L_CreateThread (L_ClientThread))
+  {
+    CLOSE_SOCKET (L_ClientData.Listener);
+    return SOCKET_ERRUNSPEC;
+  }
+
+  L_ClientData.Socket = connectsocket ;
+  L_ClientData.Connect = TRUE;
+  if (L_ClientData.EnabledSignals & DRV_SIGTYPE_CONNECT)
+  {
+    SocketSignal.SignalType = DRV_SIGTYPE_CONNECT;
+    SocketSignal.DrvHandle = L_ClientData.SocketHandle;
+    (*L_ClientData.Callback)(&SocketSignal) ;
+  }
+  return DRV_OK ;
+}
+
+/*
++------------------------------------------------------------------------------
+|  Function    : socket_Close
++------------------------------------------------------------------------------
+|  Description : This function is used by a client to close the connection or
+|                by server to shut down the server functionality.
+|                In case of a successful completion the connection is shutdown
+|                and neither socket_Read nor socket_Write will be successful.
+|                To get notified about the termination of a connection the
+|                appropriate signal has to be set (socket_SetSignal()).
+|
+|  Parameters  : -
+|
+|  Return      : -
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_Close (void)
+{
+  L_ThreadActive = FALSE ;
+
+#ifdef SOCK_TRACE
+  if (fh_sock != -1)
+  {
+    char sstop[10];
+    ULONG stop = GetTickCount();
+
+    sprintf(sstop, "%03d:%03d",  (stop/1000) % 1000, stop % 1000);
+    sprintf(stbuf, "socket_Close at %s socket=%d listener=%d\n",
+                    sstop, L_ClientData.Socket, L_ClientData.Listener);
+    write (fh_sock, stbuf, strlen(stbuf));
+  }
+#endif
+  if (L_ClientData.Socket != INVALID_SOCKET)
+  {
+    CLOSE_SOCKET (L_ClientData.Socket);
+    L_ClientData.Socket = INVALID_SOCKET;
+  }
+
+  if (L_ClientData.Listener != INVALID_SOCKET)
+    CLOSE_SOCKET (L_ClientData.Listener);
+
+  L_ClientData.ThreadID = 0 ;
+  return DRV_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_Read_with_Timeout
++------------------------------------------------------------------------------
+| Description : This function is used to read data from the USART driver.
+|               For more details see socket_Read()
+|
+| Return:       >= 0         - Number of bytes read
+|               SOCKET_ERROR - error occurred
++------------------------------------------------------------------------------
+*/
+LOCAL ULONG socket_Read_with_Timeout( void* destBuf, ULONG reqLen )
+{
+  ULONG timeout,
+        totalBytes = 0,
+        stop_timeout ;
+  int readBytes,
+        attempts = 0;
+
+  /* calculate timeout time */
+  GETTIME( stop_timeout );
+  stop_timeout = stop_timeout + L_DCB.rx_timeout_msec ;
+
+  /* read nonblocking until requested data is read or timeout */
+  do
+  {
+    readBytes = (SHORT)READ_SOCKET( L_ClientData.Socket,
+                                    ((char *)destBuf) + totalBytes,
+                                    reqLen - totalBytes );
+
+    if( readBytes < 0 || readBytes == SOCKET_ERROR )
+    {
+#ifdef SOCKET_DEBUG
+#ifndef _PSOS_
+      fp = fopen(readerrorfile, "at");
+      fprintf (fp, "WSAGetLastError returned: %8d", WSAGetLastError() );
+      fclose(fp);
+#endif
+#endif  /* SOCKET_DEBUG */
+      return 0;
+    }
+    else
+    {
+      totalBytes += (unsigned int)readBytes;
+
+      GETTIME (timeout) ;
+
+      if( totalBytes < reqLen )
+      {
+        if (attempts++)   /* try to get data by two consecutive accesses
+                             then sleep (but this should not be necessary) */
+        {
+#ifdef OLD_FRAME
+          Sleep (1) ;
+#else
+          os_SuspendTask ( 0, 1 );
+#endif
+        }
+      }
+      else
+      {
+        return totalBytes;
+      }
+    }
+  } while (timeout < stop_timeout);
+
+  return 0;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_Read
++------------------------------------------------------------------------------
+| Description : This function is used to read data from the USART driver. The
+|               data is copied into the buffer to which out_BufferPtr points.
+|               The parameter *thr_BufferSizePtr contains the size of the
+|               buffer in characters.
+|               In the case of a successful completion, the driver's buffer
+|               is cleared. The driver keeps the data available when calling
+|               the function drv_Look().
+|               If the driver is not configured, the function returns
+|               DRV_NOTCONFIGURED.
+|
+|               NOTE: When calling the function with a buffer size of 0, the
+|                     function will return DRV_OK. The size of the buffer
+|                     needed to store the available data is stored in the
+|                     parameter *thr_BufferSizePtr. In this case, the
+|                     out_BufferPtr can be set to NULL.
+|
+|
+| Parameters  : out_BufferPtr         - This parameter points to the buffer
+|                                       wherein the data is to be copied
+|               thr_BufferSizePtr     - On call: number of characters to
+|                                       read. If the function returns DRV_OK,
+|                                       it contains the number of characters
+|                                       read. If the function returns
+|                                       DRV_INPROCESS, it contains 0.
+|
+| Return      : DRV_OK             - Function successful
+|               DRV_INPROCESS      - The driver is currently reading data.
+|                                    The data is incomplete.
+|               DRV_NOTCONFIGURED  - The driver is not yet configured
+|               SOCKET_NOCONNECT   - Connection not available
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_Read (void* out_BufferPtr, ULONG*  thr_BufferSizePtr)
+{
+#ifdef _VXWORKS_
+  SIZETYPE           pending_data_size = 0;
+#else
+  ULONG              pending_data_size = 0;
+#endif
+  ULONG              bytesToRead, bytesReq;
+  int                rc;
+  static USHORT      packet_size;
+  union
+  {
+    USHORT s;
+    UBYTE  b[2];
+  } conv;
+#ifdef SOCKET_DEBUG
+  static ULONG BytesRead = 0;
+#endif
+#ifdef SOCK_TRACE
+  static ULONG start;
+  static ULONG lasttime = 0;
+#endif
+
+  bytesReq = *thr_BufferSizePtr;
+  *thr_BufferSizePtr = 0;      /* no bytes returned yet */
+  while ( (rc = (GETREADSIZE( L_ClientData.Socket, &pending_data_size ))) == 0 &&
+          pending_data_size > 0 )
+  {
+    switch (sock_state)
+    {
+      case SST_PL0:
+#ifdef SOCK_TRACE
+        GETTIME (start) ;
+#endif
+        packet_size = 0;
+        if (pending_data_size >= 2)
+        {
+          bytesToRead = 2;
+          sock_state = SST_DATA0;
+        }
+        else
+        {
+          bytesToRead = 1;
+          sock_state = SST_PL1;
+        }
+        if ( !(L_DCB.config & TI_MODE) )
+        {
+          if (socket_Read_with_Timeout(&packet_size, bytesToRead) != bytesToRead)
+          {
+            sock_state = SST_PL0;
+            return SOCKET_NOCONNECT;
+          }
+        }
+        break;
+      case SST_PL1:
+        if (socket_Read_with_Timeout(((char*)&packet_size)+1, 1) != 1)
+        {
+          sock_state = SST_PL0;
+          return SOCKET_NOCONNECT;
+        }
+        sock_state = SST_DATA0;
+        break;
+      case SST_DATA0:
+        if ( !(L_DCB.config & TI_MODE) && isLittleEndian )
+        {
+          conv.b[0] = *(((UBYTE*)&packet_size)+1); /* LSB */
+          conv.b[1] = *  (UBYTE*)&packet_size;     /* MSB */
+          packet_size = conv.s;
+        }  
+        /*lint -fallthrough*/
+      case SST_DATAx:
+        /* now read the packet payload or a part of it */
+        if ( L_DCB.config & TI_MODE )
+        {
+          bytesToRead = (pending_data_size < bytesReq) ? pending_data_size : bytesReq;
+        }
+        else
+        {
+          bytesToRead = (packet_size < bytesReq) ? packet_size : bytesReq;
+          if (pending_data_size < bytesToRead)
+            bytesToRead = pending_data_size;
+        }
+        if( (*thr_BufferSizePtr =
+              socket_Read_with_Timeout( ((char *)out_BufferPtr), bytesToRead )) !=
+              bytesToRead )
+        {
+          *thr_BufferSizePtr = 0;
+          if ( !(L_DCB.config & TI_MODE) )
+            sock_state = SST_PL0;
+          return SOCKET_NOCONNECT;
+        }
+#ifdef SOCK_TRACE
+        if (fh_sock != -1 && sock_state == SST_DATA0 && bytesToRead >= 13)
+        {
+          char split[10+1];
+          char sstart[20], sstop[20];
+          static ULONG c_received = 0;
+          ULONG len = packet_size;
+          ULONG stop = GetTickCount();
+
+          if (((char*)out_BufferPtr)[13] == 'T')
+          {
+            memcpy(split, ((char*)out_BufferPtr)+9, 7);
+            split[7] = '\0';
+          }
+          else
+          {
+            memcpy(split, ((char*)out_BufferPtr)+9, 4);
+            split[4] = '\0';
+          }
+          if (start != lasttime)
+          {
+            if (lasttime - start > 11)
+              sprintf(sstart, "->%d %03d:%03d\n", c_received, (start/1000) % 1000, start % 1000);
+            else
+              sprintf(sstart, "%03d:%03d\n", (start/1000) % 1000, start % 1000);
+            c_received = 0;
+          }
+          c_received += packet_size + 2;
+          if (start != stop)
+          {
+            sprintf(sstop, "->%d %03d:%03d\n", c_received, (stop/1000) % 1000, stop % 1000);
+            c_received = 0;
+          }
+          sprintf(stbuf, "%s%d %s\n%s",
+                       (start != lasttime) ? sstart : "",
+                       packet_size + 2, split,
+                       (start != stop) ? sstop : "");
+          write (fh_sock, stbuf, strlen(stbuf));
+          lasttime = stop;
+        }
+#endif
+        if ( !(L_DCB.config & TI_MODE) )
+        {
+          if (*thr_BufferSizePtr == packet_size)
+            sock_state = SST_PL0;
+          else
+          {
+            packet_size -= (USHORT)*thr_BufferSizePtr;
+            sock_state = SST_DATAx;
+          }
+        }
+        return DRV_OK;
+    /*lint -e527 suppress Warning -- Unreachable */
+        break;
+    /*lint +e527 */
+    }  /* switch */
+  } /* while */
+  if (rc)
+  {
+    sock_state = SST_PL0;
+    return SOCKET_NOCONNECT;
+  }
+#ifdef SOCKET_DEBUG
+  {
+    static char Buffer[2000];
+    memcpy (Buffer+BytesRead,out_BufferPtr,*thr_BufferSizePtr);
+    BytesRead += *thr_BufferSizePtr;
+    if ( (Buffer[0] == 'P') )
+    {
+      OS_TIME time;
+      char c = Buffer[21];
+      fp = fopen(logfile, "at");
+      Buffer[21] = 0;
+      os_GetTime ( 0, &time );
+      fprintf (fp, "P%ld IN:  %s\n", time/10, &Buffer[9] );
+      Buffer[21] = c;
+      fclose(fp);
+    }
+  }
+
+#endif
+  return DRV_OK ;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_Write
++------------------------------------------------------------------------------
+| Description : This function is used to write data to the driver. The
+|               parameter *thr_BufferSizePtr contains the number of
+|               characters to write. In the case of a successful completion,
+|               the function returns DRV_OK.
+|               If the data cannot be written because the storage capacity of
+|               the driver has been exhausted, the function returns
+|               DRV_BUFFER_FULL and the maximum number of characters that can
+|               be written in *thr_BufferSizePtr.
+|               If the driver is currently busy writing data and therefore
+|               cannot accept further data to be written, it returns
+|               DRV_INPROCESS and sets the parameter *thr_BufferSizePtr to 0.
+|               If the driver is not configured, the function returns
+|               DRV_ NOTCONFIGURED.
+|
+|               NOTE:  When calling the function with a buffer size of 0, the
+|                     function will return the number of characters that can be
+|                     written in the parameter *thr_BufferSizePtr. In this
+|                     case, the in_BufferPtr can be set to NULL.
+|
+| Parameters  : in_BufferPtr          - This parameter points to the buffer
+|                                       that is passed to the driver for
+|                                       further processing
+|               thr_BufferSizePtr     - On call: number of characters to
+|                                       write. If the function returns
+|                                       DRV_BUFFER_FULL, it contains the
+|                                       maximum number of characters that can
+|                                       be written. If the function returns
+|                                       DRV_OK, it contains the number of
+|                                       characters written. If the function
+|                                       returns DRV_INPROCESS, it contains 0.
+|
+|
+| Return      : DRV_OK            - Function successful
+|               DRV_BUFFER_FULL   - Not enough space
+|               DRV_INPROCESS     - Driver is busy writing data
+|               DRV_NOTCONFIGURED - The driver is not yet configured
+|               SOCKET_NOCONNECT  - Connection not available
+|
++------------------------------------------------------------------------------
+*/
+/*lint -esym(613,auxb) suppress warning possibly use off NULL pointer auxb */
+/*lint -esym(644,auxb) suppress warning possibly not initialized */
+/*lint -e668           suppress warning possibly passing NULL pointer to memcpy */
+USHORT socket_Write (void*  in_BufferPtr, ULONG*  thr_BufferSizePtr)
+{
+  UBYTE    rc = DRV_OK;
+  int   max_len, rest;
+  char *   auxb;
+  ULONG buffer_size;
+  
+  buffer_size = *thr_BufferSizePtr & ~PRIM_FLAG_MASK;
+
+#ifndef _PSOS_
+#ifdef SOCKET_DEBUG
+  UBYTE Prim = 0;
+  {
+    char *ptr = in_BufferPtr;
+    if ( *ptr == 'P' )
+    {
+      OS_TIME time;
+      char c = ptr[21];
+      fp = fopen(logfile, "at");
+      ptr[21] = 0;
+      os_GetTime ( 0, &time );
+      fprintf (fp, "P%ld OUT: %s\n", time/10, &ptr[9] );
+      ptr[21] = c;
+      fclose(fp);
+      Prim = 1;
+    }
+  }
+#endif  /* SOCKET_DEBUG */
+#else /* _PSOS */
+  if( !tst_socket_initialized )
+  {
+    if (tst_socket_in_TxLen > 0)
+    {
+      int nodelay = TRUE;
+      if (setsockopt(tst_socket, SOL_SOCKET, SO_SNDBUF,
+                     (char*)&tst_socket_in_TxLen, sizeof(tst_socket_in_TxLen)))
+        return DRV_INITFAILURE;
+      if (setsockopt(tst_socket, IPPROTO_TCP, TCP_NODELAY,
+                   (char*)&nodelay, sizeof(nodelay)))
+        return DRV_INITFAILURE;
+    }
+    tst_socket_initialized = 1;
+  }
+#endif /* _PSOS_ */
+
+  if ( L_DCB.config & TI_MODE )
+  {
+    /* add TI-MUX header */
+    auxb=(char*)malloc(buffer_size+2);
+    memcpy((void*)(auxb+2),in_BufferPtr,buffer_size);
+    auxb[0]=19; /* assigned to L23 */
+    auxb[1]=(char)buffer_size;
+    in_BufferPtr=auxb;
+    buffer_size+=2;
+  }
+
+  max_len = (L_DCB.tx_buffer_size < WRBUF_LEN) ? L_DCB.tx_buffer_size : WRBUF_LEN;
+  if (max_len < (int)buffer_size)
+  {
+#ifndef _PSOS_
+#ifdef SOCKET_DEBUG
+    char buffer[200];
+    char *ptr = in_BufferPtr;
+    char c = ptr[21];
+    fp = fopen(bufferfullfile, "at");
+    if ( *ptr == 'P' )
+      ptr[21] = 0;
+    else
+      ptr[buffer_size] = 0;
+    strcpy (buffer, "errno:" );
+    sprintf (&buffer[6], "%8d", WSAGetLastError() );
+    buffer[14] = ' ';
+    memcpy (&buffer[15], ptr, (buffer_size)+1);
+    fprintf (fp, "%s\n", buffer );
+    ptr[21] = c;
+    fclose(fp);
+#endif  /* SOCKET_DEBUG */
+#endif  /* _PSOS_ */
+    if ( L_DCB.config & TI_MODE )
+      free(auxb);
+    *thr_BufferSizePtr = (unsigned int)max_len |
+                                      (*thr_BufferSizePtr & PRIM_FLAG_MASK) ;
+    return DRV_BUFFER_FULL ;
+  }
+
+  rest = MAX_ETH_LEN - (wrbuf_pos - wrbuf);
+  if (buffer_size + 2 >= (unsigned int)rest)    /* more than maximum ethernet packet size needed ?*/
+  {
+  /*---------------------------------
+    send the buffer
+    ---------------------------------*/
+    rc = socket_WriteToOS(wrbuf, (USHORT)(wrbuf_pos - wrbuf));
+    wrbuf_pos = wrbuf;
+
+    if (rc != DRV_OK)
+    {
+      if ( L_DCB.config & TI_MODE )
+        free(auxb);
+      *thr_BufferSizePtr = (*thr_BufferSizePtr & PRIM_FLAG_MASK) ;
+      return rc;
+    }
+  }
+
+  if ( !(L_DCB.config & TI_MODE) )
+  {
+    /*------------------------------------------------
+      put the size of the data into buffer (MSB first)
+      ------------------------------------------------*/
+    if (isLittleEndian)
+    {
+      *wrbuf_pos     = *(((UBYTE*)&buffer_size)+1); /* MSB */
+      *(wrbuf_pos+1) = *  (UBYTE*)&buffer_size;     /* LSB */
+    }
+    else
+      *((USHORT*)wrbuf_pos) = (USHORT)buffer_size;
+    wrbuf_pos += 2;
+  }
+  /*---------------------------------
+    put the data itself into buffer
+    ---------------------------------*/
+  memcpy(wrbuf_pos, in_BufferPtr, (size_t)buffer_size);
+  wrbuf_pos += buffer_size;
+
+  if (socket_flush)
+  {
+    /*---------------------------------
+      send the buffer
+      ---------------------------------*/
+    rc = socket_WriteToOS(wrbuf, (USHORT)(wrbuf_pos - wrbuf));
+    wrbuf_pos = wrbuf;
+    socket_flush = 0;
+
+    if (rc != DRV_OK)
+    {
+      *thr_BufferSizePtr = (*thr_BufferSizePtr & PRIM_FLAG_MASK) ;
+    }
+  }
+
+  if ( L_DCB.config & TI_MODE )
+  {
+    free(auxb);
+  }
+  return rc ;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_Flush
++------------------------------------------------------------------------------
+| Description : This function flushes the socket write buffer where data
+|               is stored until a complete packet can be sent or the
+|               transmission is forced by an external setting of the
+|               socket_flush flag. 
+|
+| Parameters  : ---
+|
+| Return      : DRV_OK                  - Function completed successfully
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_Flush ( void )
+{
+ULONG len = 0;
+
+  socket_flush = 1;
+  return ( socket_Write(NULL, &len) );
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_SetSignal
++------------------------------------------------------------------------------
+| Description : This function is used to define a single or multiple signals
+|               that is/are indicated to the process when the event identified
+|               in the signal information data type as SignalType occurs. The
+|               USART uses only the standard signals defined in [C_8415.0026].
+|               To remove a signal, call the function socket_ResetSignal().
+|               If one of the parameters of the signal information data is
+|               invalid, the function returns DRV_INVALID_PARAMS.
+|               If no signal call-back function has been defined at the time
+|               of initialization, the driver returns DRV_SIGFCT_NOTAVAILABLE.
+|
+| Parameters  : in_SignalIDPtr        - Pointer to the signal information
+|                                       data
+|
+| Return      : DRV_OK                  - Function completed successfully
+|               DRV_INVALID_PARAMS      - One or more parameters are out of
+|                                         range or invalid
+|               DRV_SIGFCT_NOTAVAILABLE - Event signaling functionality is
+|                                         not available
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_SetSignal (USHORT SignalType)
+{
+  if (L_ClientData.Callback == NULL)
+    return DRV_SIGFCT_NOTAVAILABLE ;
+
+  if (SignalType & ALLOWED_SOCKET_SIGNALS)
+    L_ClientData.EnabledSignals |= SignalType;
+  else
+    return DRV_INVALID_PARAMS ;
+  return DRV_OK ;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_ResetSignal
++------------------------------------------------------------------------------
+| Description : This function is used to remove previously set single or
+|               multiple signals. The signals that are removed are identified
+|               by the Signal Information Data element called SignalType. All
+|               other elements of the Signal Information Data must be
+|               identical to the signal(s) that are to be removed (process
+|               handle and signal value). If the SignalID provided cannot be
+|               located, the function returns DRV_INVALID_PARAMS.
+|               If no signal call-back function has been defined at the time
+|               of initialization, the driver returns DRV_SIGFCT_NOTAVAILABLE.
+|
+| Parameters  : in_SignalIDPtr        - Pointer to the signal information
+|                                       data
+|
+| Return      : DRV_OK                    - Function completed successfully
+|               DRV_INVALID_PARAMS        - One or more parameters are out of
+|                                           range or invalid
+|               DRV_SIGFCT_NOTAVAILABLE   - Event signaling functionality is
+|                                           not available
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_ResetSignal (USHORT SignalType)
+{
+  if (L_ClientData.Callback == NULL)
+    return DRV_SIGFCT_NOTAVAILABLE ;
+
+  if (SignalType & ALLOWED_SOCKET_SIGNALS)
+    L_ClientData.EnabledSignals &= ~SignalType;
+  else
+    return DRV_INVALID_PARAMS ;
+
+  return DRV_OK ;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_SetConfig
++------------------------------------------------------------------------------
+| Description : This function is used to configure the driver (port,
+|               transmission rate, flow control, etc). The driver can be
+|               configured at any one time before a connection is opened. The
+|               parameters that can be configured are included in the USART's
+|               device control block socket_DCB_Type. For detailed information
+|               about the contents of the device control block, refer to
+|               Chapter 2.1.1. If any value of the configuration is out of
+|               range or invalid in combination with any other value of the
+|               configuration, the function returns DRV_INVALID_PARAMS.
+|               Call the socket_GetConfig() function to retrieve the driver's
+|               configuration.
+|               The driver needs to be configured after initialization. Only
+|               the following functions can be called while the driver is not
+|               configured: socket_Clear, socket_SetSignal and socket_GetSignal.
+|               All other functions return DRV_NOTCONFIGURED.
+|
+| Parameters  : in_DCBPtr             - Pointer to the driver control block
+|
+| Return      : DRV_OK                    - Function completed successfully
+|               DRV_INVALID_PARAMS        - One or more parameters are out of
+|                                           range or invalid
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_SetConfig (char* in_DCBPtr)
+{
+char token [SOCKET_MAX_LEN_HOSTNAME+1];
+USHORT port;
+unsigned int len;
+
+  if ( (len = GetNextToken (in_DCBPtr, token, " #")) == 0)
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    in_DCBPtr += (len+1);
+  }
+
+  port = (USHORT)atoi(token);
+
+  if ( (len = GetNextToken (in_DCBPtr, token, " #")) == 0) 
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    in_DCBPtr += (len+1);
+  }
+
+  if ( !strcmp ( DRV_TI_MODE, token ) )
+  {
+    L_DCB.config = TI_MODE;
+    sock_state = SST_DATAx;
+  }
+  else if ( !strcmp ( DRV_DEFAULT, token ) )
+  {
+    L_DCB.config = 0;
+    sock_state = SST_PL0;
+  }
+  else
+    return DRV_INVALID_PARAMS;
+
+  if ( (len = GetNextToken (in_DCBPtr, token, " #")) == 0 ) 
+  {
+#ifdef _TOOLS_
+    gethostname (token,SOCKET_MAX_LEN_HOSTNAME);
+#endif /* _TOOLS_ */
+  }
+
+  if (L_ThreadActive)
+  {
+    /* check if host is already used */
+    if (strcmp(L_DCB.hostname, token)==0 && L_DCB.port==port) 
+    {
+#ifdef _TOOLS_
+      printf("SOCKET: keeping connection to host %s on port %u\n",L_DCB.hostname,L_DCB.port); 
+#endif
+      return DRV_OK;
+    }
+
+    socket_Close();
+  }
+  
+  L_DCB.port=port;
+  strcpy ( L_DCB.hostname, token);
+  
+  if (socket_Open () != DRV_OK)
+  {
+    return DRV_INVALID_PARAMS ;
+  }
+
+  return DRV_OK ;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_GetConfig
++------------------------------------------------------------------------------
+| Description : This function is used to retrieve the configuration of the
+|               driver. The configuration is returned in the driver control
+|               block to which the pointer provided out_DCBPtr points. For
+|               detailed information about the contents of the device control
+|               block, refer to Chapter 2.1.1. The configuration can be
+|               requested at any one time.
+|               If the driver is not configured, the function returns
+|               DRV_ NOTCONFIGURED.
+|
+| Parameters  : out_DCBPtr                - Pointer to the driver control block
+|
+| Return      : DRV_OK                    - Function completed successfully
+|               DRV_INVALID_PARAMS        - One or more parameters are out of
+|                                           range or invalid
+|
++------------------------------------------------------------------------------
+*/
+USHORT socket_GetConfig (socket_DCB_Type*  out_DCBPtr)
+{
+  if (out_DCBPtr == NULL)
+    return DRV_INVALID_PARAMS ;
+
+  memcpy (out_DCBPtr, &L_DCB, sizeof (L_DCB)) ;
+  return DRV_OK ;
+}
+
+/*
++------------------------------------------------------------------------------
+| Function    : socket_Init
++------------------------------------------------------------------------------
+| Description : The function initializes the internal data of the driver.
+|               The function returns DRV_INITIALIZED if the driver has
+|               already been initialized and is ready to be used or is
+|               already in use. In the case of an initialization failure,
+|               i.e. the driver cannot be used, the function returns
+|               DRV_INITFAILURE.
+|
+| Parameters  : in_SignalCBPtr    - This parameter points to the function that
+|                                   is called at the time an event that is to
+|                                   be signaled occurs. This value can be set
+|                                   to NULL if event signaling should not be
+|                                   possible.
+|
+| Return      : DRV_OK            - Initialization successful
+|               DRV_INITIALIZED   - Driver already initialized
+|               DRV_INITFAILURE   - Initialization failed
+|
++------------------------------------------------------------------------------
+*/
+GLOBAL USHORT socket_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{
+static const T_DRV_EXPORT Socket_Info =
+{
+  "SOCKET",
+  0,
+  {
+#ifdef _TOOLS_
+    socket_Init,
+#endif
+    socket_Exit,
+    socket_Read,
+    socket_Write,
+    NULL,
+    NULL,
+    socket_Flush,
+    socket_SetSignal,
+    socket_ResetSignal,
+    socket_SetConfig,
+    NULL,
+    NULL,
+  }
+};
+union
+{
+  USHORT s;
+  UBYTE b[2];
+} test;
+
+#ifndef _PSOS_
+#if defined (_VXWORKS_) || defined (_LINUX_) || defined (_SOLARIS_)
+/* ToDo: vxWorks-libs initiieren
+  sockLib
+  inetLib
+*/
+#else /* _VXWORKS_ */
+  WSADATA WSAData;
+  if (WSAStartup(MAKEWORD(1,1), &WSAData))
+    return DRV_INITFAILURE;
+#endif /* _VXWORKS_ */
+#endif
+
+  test.s = 1;
+  isLittleEndian = (test.b[0] == 1);
+
+  L_ThreadActive = FALSE ;
+  L_DCB.config = 0;
+  L_DCB.port = 6392;
+  L_DCB.tx_buffer_size = TX_BUFFER_SIZE;
+  L_DCB.rx_buffer_size = RX_BUFFER_SIZE ;
+  L_DCB.tx_timeout_msec = TX_TIMEOUT_MSEC;
+  L_DCB.rx_timeout_msec = RX_TIMEOUT_MSEC;
+  *L_DCB.hostname = 0 ;
+  L_ClientData.Connect = FALSE;
+  L_ClientData.SocketHandle = DrvHandle;
+  L_ClientData.Socket = INVALID_SOCKET ;
+  L_ClientData.Listener = INVALID_SOCKET ;
+#ifdef _PSOS_
+  tst_socket = INVALID_SOCKET ;
+  tst_socket_initialized = 0;
+  tst_socket_in_TxLen = 0;
+#endif
+
+  L_ClientData.Callback   = CallbackFunc ;
+  L_ClientData.EnabledSignals = ALLOWED_SOCKET_SIGNALS ;
+  *DrvInfo = &Socket_Info;
+#ifdef SOCKET_DEBUG
+  fp = fopen(logfile,"wt");
+  fclose(fp);
+  fp = fopen(inprocessfile,"wt");
+  fclose(fp);
+  fp = fopen(bufferfullfile,"wt");
+  fclose(fp);
+  fp = fopen(noconnectfile1,"wt");
+  fclose(fp);
+  fp = fopen(noconnectfile2,"wt");
+  fclose(fp);
+  fp = fopen(noconnectfile3,"wt");
+  fclose(fp);
+  fp = fopen(readerrorfile,"wt");
+  fclose(fp);
+#endif /* SOCKET_DEBUG */
+  return DRV_OK ;
+}
+
+/*==== END OF FILE ==========================================================*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/socket.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,70 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       socket.h
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the serial driver adaptation
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef  SOCKET_H
+#define  SOCKET_H
+
+/*==== INCLUDES =============================================================*/
+#include "typedefs.h"
+#include "gdi.h"
+
+#ifdef _VXWORKS_
+  /* wha!??? */
+  #define SO_DONTLINGER   (~SO_LINGER)  /* Older SunOS compat. hack */
+  #define TCP_NODELAY     1
+#endif
+
+/*==== DEFINITIONS ==========================================================*/
+#define SOCKET_SIGTYPE_CONNECT	DRV_SIGTYPE_USER    /* Connected event signal*/
+#define SOCKET_SIGTYPE_RELEASE	(DRV_SIGTYPE_USER+1)/* Released event signal */
+
+#define SOCKET_ERRUNSPEC        (DRV_RETVAL_USER+1)
+#define SOCKET_NOCONNECT        (DRV_RETVAL_USER+2)
+
+#define SOCKET_INVALID_PORT     0  
+#define SOCKET_MAX_LEN_HOSTNAME	64
+
+/*==== TYPES ================================================================*/
+typedef struct
+{
+	USHORT      port;
+  USHORT      tx_buffer_size ;
+  USHORT      rx_buffer_size ;
+  ULONG       tx_timeout_msec ;
+  ULONG       rx_timeout_msec ;
+	char        hostname[SOCKET_MAX_LEN_HOSTNAME+1] ;
+  USHORT      config;
+} socket_DCB_Type;
+
+/*==== FUNCTIONS ============================================================*/
+EXTERN USHORT socket_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo ) ;
+EXTERN void   socket_Exit (void) ;
+EXTERN USHORT socket_Open (void) ;
+EXTERN USHORT socket_Close (void) ;
+EXTERN USHORT socket_Read (void* out_BufferPtr, ULONG*	thr_BufferSizePtr) ;
+EXTERN USHORT socket_Write (void*	in_BufferPtr, ULONG*	thr_BufferSizePtr) ;
+EXTERN USHORT socket_Flush (void) ;
+EXTERN USHORT socket_SetSignal (USHORT SignalType) ;
+EXTERN USHORT socket_ResetSignal (USHORT	SignalType) ;
+EXTERN USHORT socket_SetConfig (char*	in_DCBPtr) ;
+EXTERN USHORT socket_GetConfig (socket_DCB_Type*	out_DCBPtr) ;
+
+/*==== END OF FILE ==========================================================*/
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/stack1_Serial.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,45 @@
+/*=============================================================================
+ *    Copyright 1996-2001 Texas Instruments Inc. All rights reserved.
+ */
+#ifndef STACK1_SERIAL_HEADER
+#define STACK1_SERIAL_HEADER
+
+//#include "puf_PrimHdr.h"
+
+/*=============================================================================
+ * Description:
+ */
+//typedef struct{
+//    Puf_PrimHdr primHdr;
+//}Stack1_Serial_RxInd;
+
+typedef void (*SERIAL_CALLBACK_FUNC)(void);
+
+/*===========================================================================
+ * Description:
+ *   Install the Uart interrupt handlers and initialize the Uart.
+ */
+int
+stack1_Serial_PowerUp( SERIAL_CALLBACK_FUNC callback );
+
+/*===========================================================================
+ * Description:
+ *   Copy the data from the Rx buffer into the passed in buffer. If there
+ *   aren't dataLen bytes in the Rx buffer all the bytes currently in the rx
+ *   buffer are returned.
+ */
+unsigned long
+stack1_Serial_receiveData( unsigned char  *dataPtr,
+                           unsigned long dataLen );
+
+/*===========================================================================
+ * Description:
+ *   Copy the data to be transmitted into the Tx Buffer and enable the Uart Tx
+ *   interrupt. If the Tx buffer is full, discard the data and return a buffer
+ *   full indication.
+ */
+int
+stack1_Serial_sendData( unsigned char  *dataPtr,
+                        unsigned long dataLen );
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/thif_link.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,533 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       thif_link.c
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the serial driver adaptation
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __THIF_LINK_C__
+#define __THIF_LINK_C__
+#endif
+
+/* these types are used in thif_socket.h */
+#define Char char
+#define Bool8 char
+#define Int8 signed char
+#define Uint8 unsigned char
+#define UInt16 unsigned short int 
+#define Uint16 unsigned short int 
+#define Uint32 unsigned long int
+#define Int32  long int
+
+
+#ifdef _TARGET_ 
+  #include "thif_link.h"
+  #include "\global_af\thif\thif_socket.h" 
+  #include "string.h"
+#else
+ #include <windows.h>
+ #include <stdio.h>
+ #include "usart.h"
+ #include "stdlib.h"
+ #include "string.h"
+ #include "tools.h"
+#endif
+
+#include "vsi.h"
+#include "drvconf.h"
+#include "tstheader.h"
+#include "os.h"
+
+
+
+
+
+/*==== TYPES ======================================================*/
+
+typedef struct
+{
+  USHORT Handle;
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+  char Connected;
+  Int8 thif_link;
+} T_THIF_LINK_DATA;
+
+
+typedef union {
+  USHORT scalar;
+  Uint8 array[2];
+} SWAPPER;
+
+/*==== CONSTANTS ==================================================*/
+
+#define ALLOWED_THIF_LINK_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT)
+#define MAX_CONFIGSTR_LEN 50
+#define NO_GOTDATA_CALLBACK 0
+#define rxBufSz 0x800
+#define txBufSz  0x800
+#define WAIT_FOR_RECONNECT 500
+
+/*==== EXTERNALS ==================================================*/
+
+
+/*==== VARIABLES ==================================================*/
+
+T_THIF_LINK_DATA THIF_LINK_Data;
+static T_DRV_SIGNAL Signal;
+
+
+Uint8 rxBuffer[rxBufSz];
+Uint8 txBuffer[txBufSz];
+Uint8 *prxBuffer = &rxBuffer[0];
+Uint8 *ptxBuffer = &txBuffer[0];
+
+GLOBAL OS_TIME WT;
+GLOBAL OS_TIME RT;
+
+/* static unsigned long int foolishSizeArgument = 0; */
+
+
+/*==== FUNCTIONS ==================================================*/
+
+#ifndef MIN
+#  define MIN(a,b)  (((a) < (b)) ? (a) : (b))
+#endif
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : swapUSHORT            |
++--------------------------------------------------------------------+
+
+  PURPOSE : byte sex handling
+
+*/
+void swapUSHORT(USHORT* candidate)
+{
+  SWAPPER source;
+  SWAPPER dest;
+  
+  source.scalar = *candidate;
+  dest.array[0] = source.array[1];
+  dest.array[1] = source.array[0];
+  *candidate = dest.scalar;
+  
+}
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : beSureToBeConnected            |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+
+void beSureToBeConnected()
+{
+  if (THIF_LINK_Data.thif_link < 0)
+  {
+    thif_link_Open();
+  }
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_binding_Callback            |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+void thif_binding_Callback (Int8 sockId) /* this is a bridge to connect the THIF binding callback to the TR-defined callback (see thif_link_Open) */
+{
+  if ( THIF_LINK_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+  {
+    Signal.SignalType = DRV_SIGTYPE_READ;
+    Signal.DrvHandle = THIF_LINK_Data.Handle;
+    (THIF_LINK_Data.Callback)( &Signal );
+  }
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Exit            |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+void thif_link_Exit ( void )
+{
+  thif_link_Close();
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Open            |
++--------------------------------------------------------------------+
+
+  PURPOSE : open connection to driver
+
+*/
+USHORT thif_link_Open(void)
+{
+  LONG result = -1;
+
+  while (result < 0)
+  {
+    result = thif_socket_open(THIF_LINK_NAME, thif_binding_Callback, prxBuffer, rxBufSz, ptxBuffer, txBufSz );
+    if (result < 0)
+    {
+      //os_SuspendTask ( 0, WAIT_FOR_RECONNECT);
+    }
+  }
+  THIF_LINK_Data.thif_link = result;
+  THIF_LINK_Data.EnabledSignalType = DRV_SIGTYPE_READ;
+
+  Signal.SignalType = DRV_SIGTYPE_CONNECT;
+  Signal.DrvHandle = THIF_LINK_Data.Handle;
+  Signal.UserData = NULL;
+  (THIF_LINK_Data.Callback)( &Signal );
+  
+  THIF_LINK_Data.Connected = TRUE;
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Close            |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+USHORT thif_link_Close(void )
+{
+  if (thif_socket_close(THIF_LINK_Data.thif_link)  < 0)
+  {
+    return DRV_INTERNAL_ERROR;
+  }
+  THIF_LINK_Data.thif_link = -1;
+  THIF_LINK_Data.EnabledSignalType = DRV_SIGTYPE_DISCONNECT;
+
+  Signal.DrvHandle = THIF_LINK_Data.Handle;
+  Signal.UserData = NULL;
+  (THIF_LINK_Data.Callback)( &Signal );
+
+  THIF_LINK_Data.Connected = FALSE;
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Read            |
++--------------------------------------------------------------------+
+
+  PURPOSE : read data from driver
+
+*/
+USHORT thif_link_Read ( void *Buffer, ULONG *SizeInBytes)
+{  
+
+  OS_TIME timeBefore;
+  OS_TIME timeAfter;
+  T_HANDLE caller;
+  USHORT retVal;
+
+/*  
+  ULONG to_read = *SizeInBytes;
+  Uint8* buff = (Uint8*) Buffer;
+  
+  beSureToBeConnected();
+  caller = os_MyHandle();
+
+  if (foolishSizeArgument == 0)
+  {
+    to_read = thif_socket_read(THIF_LINK_Data.thif_link, buff, 2);
+    foolishSizeArgument = buff[0]*0xff + buff[1];
+  }
+  to_read= foolishSizeArgument;
+
+  //os_GetTime (caller,  &timeBefore);
+  to_read = MIN(to_read, *SizeInBytes);
+  *SizeInBytes = thif_socket_read(THIF_LINK_Data.thif_link, buff, to_read);
+ 
+  if (*SizeInBytes <= foolishSizeArgument)
+  {
+    foolishSizeArgument -= *SizeInBytes;
+    retVal = DRV_OK;
+  }
+  else
+  {
+    foolishSizeArgument = 0;
+    retVal = DRV_INTERNAL_ERROR;
+  }
+  
+  //os_GetTime (caller,  &timeAfter);
+  //RT= timeAfter - timeBefore;
+  return retVal;
+*/
+  *SizeInBytes = thif_socket_read( THIF_LINK_Data.thif_link, Buffer, *SizeInBytes ); 
+  return DRV_OK;
+
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Write_to_socket           |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+void thif_link_Write_to_socket (void *Buffer, ULONG sizeInBytes )
+{
+  T_HANDLE caller;
+  Uint8* buff;
+
+  OS_TIME timeBefore;
+  OS_TIME timeAfter;
+  ULONG to_write;
+    
+  LONG written = -1;
+
+
+  buff = (Uint8*) Buffer;
+  to_write = sizeInBytes;
+  caller = os_MyHandle();
+  while (to_write > 0)
+  {
+    //os_GetTime (caller,  &timeBefore);
+    written = thif_socket_write(THIF_LINK_Data.thif_link, buff, to_write);
+    //os_GetTime (caller,  &timeAfter);
+    //WT = timeAfter - timeBefore;
+    if (written < 0)
+    {
+      //os_SuspendTask (caller, WAIT_FOR_RECONNECT);
+    }
+    else if (written == 0)
+    {
+      os_SuspendTask (caller, 2000);
+      //break;
+    }
+    else
+    {
+      to_write -= written;
+      buff += written;
+    }
+  }
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Write           |
++--------------------------------------------------------------------+
+
+  PURPOSE : relay 2 byte header & data to thif_link_Write_to_socket
+
+*/
+USHORT thif_link_Write ( void *Buffer, ULONG *SizeInBytes )
+{
+  USHORT TSTSocketMarker;
+  Uint8* buff;
+
+  beSureToBeConnected();
+
+  /* TST's socket interface expects a 2-byte header containing the length of the real message  to receive
+      in funtion socket_Read.  We just send that header, converting it to little endian in advance 
+  TSTSocketMarker = (USHORT) *SizeInBytes;
+  swapUSHORT(&TSTSocketMarker);
+
+  buff = (Uint8*) &TSTSocketMarker;
+  thif_link_Write_to_socket( buff, 2);
+  */
+  
+  buff = (Uint8*) Buffer;
+  thif_link_Write_to_socket(buff, *SizeInBytes);
+  
+  //thif_socket_flush(THIF_LINK_Data.thif_link);
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Flush           |
++--------------------------------------------------------------------+
+
+  PURPOSE : flush  data to driver
+
+*/
+USHORT thif_link_Flush (void)
+{
+  beSureToBeConnected();
+  return thif_socket_flush(THIF_LINK_Data.thif_link);
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_SetSignal       |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+USHORT thif_link_SetSignal ( USHORT SignalType )
+{
+  if ( !(SignalType & ALLOWED_THIF_LINK_SIGNALS) )
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    THIF_LINK_Data.EnabledSignalType |= SignalType;
+  }
+
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_ResetSignal     |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+USHORT thif_link_ResetSignal ( USHORT SignalType )
+{
+  if ( !(SignalType & ALLOWED_THIF_LINK_SIGNALS) )
+  {
+    return DRV_INVALID_PARAMS;
+  }
+  else
+  {
+    THIF_LINK_Data.EnabledSignalType &= ~SignalType;
+  }
+
+  return DRV_OK;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_SetConfig       |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+*/
+USHORT thif_link_SetConfig ( char *buffer )
+{
+  char token [64];
+  unsigned int len;
+  USHORT result;
+
+  result = DRV_OK;
+
+  if ( (len = GetNextToken (buffer, token, " #")) == 0) 
+  {
+    result = thif_link_Open();
+  }
+  else
+  {
+    buffer += (len+1);
+  }
+
+  if ( !strcmp ( "OPEN", token ) )
+  {
+    result = thif_link_Open();
+  }
+  else if ( !strcmp ( "CLOSE", token ) )
+  {
+    result = thif_link_Close();
+  }
+  else if ( !strcmp ( "EXIT", token ) )
+  {
+    thif_link_Exit();
+  }
+  else
+  {
+    result = DRV_INVALID_PARAMS;
+  }
+
+  if ((result != DRV_OK) && (result != DRV_INVALID_PARAMS))
+  {
+    result = DRV_NOTCONFIGURED;
+  }
+  
+  return  result;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : thif_link                 |
+| STATE   : code                       ROUTINE : thif_link_Init            |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+USHORT thif_link_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{
+static const T_DRV_EXPORT thif_link_Info =
+{
+  THIF_LINK_NAME,
+  0,
+  {
+#ifdef _WIN32_
+    thif_link_Init,
+#endif
+    thif_link_Exit,
+    thif_link_Read,
+    thif_link_Write,
+    NULL, /* Look */
+    NULL, /* Clear */
+    thif_link_Flush,
+    thif_link_SetSignal,
+    thif_link_ResetSignal,
+    thif_link_SetConfig,
+    NULL,
+    NULL,
+  }
+};
+
+  THIF_LINK_Data.Handle = DrvHandle;
+
+  THIF_LINK_Data.EnabledSignalType = 0;
+
+  THIF_LINK_Data.Callback = CallbackFunc;
+
+  THIF_LINK_Data.Connected = FALSE;
+
+  *DrvInfo = &thif_link_Info;
+
+  return DRV_OK;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/thif_link.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,54 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       thif_link.h
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the serial driver adaptation
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef  THIF_LINK_H
+#define  THIF_LINK_H
+
+/*==== INCLUDES =============================================================*/
+//#include "typedefs.h"
+#include "gdi.h"
+
+/*==== DEFINITIONS ==========================================================*/
+#define THIF_SOCK_SIGTYPE_CONNECT	DRV_SIGTYPE_USER    /* Connected event signal*/
+#define THIF_SOCK_SIGTYPE_RELEASE	(DRV_SIGTYPE_USER+1)/* Released event signal */
+
+#define THIF_SOCK_ERRUNSPEC        (DRV_RETVAL_USER+1)
+#define THIF_SOCK_NOCONNECT        (DRV_RETVAL_USER+2)
+
+#define THIF_SOCK_INVALID_PORT     0  
+#define THIF_SOCK_MAX_LEN_HOSTNAME	20
+
+/*==== TYPES ================================================================*/
+
+
+/*==== FUNCTIONS ============================================================*/
+EXTERN void thif_link_Exit (void) ;
+EXTERN USHORT thif_link_Open (void) ;
+EXTERN USHORT thif_link_Close (void) ;
+EXTERN USHORT thif_link_Read (void* Buffer, ULONG*	SizeInBytes) ;
+EXTERN USHORT thif_link_Write (void* Buffer, ULONG*	SizeInBytes) ;
+EXTERN USHORT thif_link_Flush (void) ;
+EXTERN USHORT thif_link_SetSignal (USHORT SignalType) ;
+EXTERN USHORT thif_link_ResetSignal (USHORT	SignalType) ;
+EXTERN USHORT thif_link_SetConfig (char*	in_DCBPtr) ;
+EXTERN USHORT thif_link_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo );
+
+/*==== END OF FILE ==========================================================*/
+#endif /* THIF_LINK_H */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/tif2.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,1102 @@
+/*
++------------------------------------------------------------------------------
+|  File:       tif.c
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG
+|                 All rights reserved.
+|
+|                 This file is confidential and a trade secret of Texas
+|                 Instruments Berlin, 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
+|                 Texas Instruments Berlin, AG.
++-----------------------------------------------------------------------------
+|  Purpose :  This Modul contains the TIF driver
++-----------------------------------------------------------------------------
+*/
+
+#ifndef __TIF_C__
+#define __TIF_C__
+#endif
+
+#include "typedefs.h"
+#include "string.h"
+#include "gdi.h"
+#include "vsi.h"
+#include "tools.h"
+#include "glob_defs.h"
+#include "ccdtable.h"
+#include "ccddata.h"
+#include "pcon.h"
+#include "p_mem.h"
+#include "drvconf.h"
+#include "tstheader.h"
+
+#ifdef _TOOLS_
+  #include "frame_const.h"
+  #include <stdio.h>
+#endif /* _TOOLS_ */
+#include "printtofile.h"
+
+#ifndef _TOOLS_
+#if !defined (_SOLARIS_) && !defined (_LINUX_)
+#pragma pack(4)
+#endif
+#endif
+
+/*lint -e545 */
+/*==== TYPES ======================================================*/
+
+typedef struct
+{
+  USHORT Handle;
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+  USHORT Config;
+} T_TIF_DATA;
+
+#ifdef _TOOLS_
+typedef struct
+{
+  unsigned int use_id;
+  char *name;
+} T_RIV_USEID_TO_NAME;
+#endif
+
+/*==== CONSTANTS ==================================================*/
+
+#define ALLOWED_TIF_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT|DRV_SIGTYPE_DISCONNECT)
+
+#define NAME_LENGTH           4
+
+#define TIF_RCV_CMD_SIZE    32
+#define TIF_MAX_CMD         (TIF_RCV_CMD_SIZE-1)
+
+#define STX                 0x02
+#define LF                  0x0a
+
+#define PCON_ENABLED   0x0001
+#define SYNC_MODE      0x0002
+
+#undef VSI_CALLER
+#define VSI_CALLER TST_Handle,
+
+#ifdef _TOOLS_
+const T_RIV_USEID_TO_NAME riv_use_id_to_name[] =
+{
+  { 0x00010001, "RVM" },
+  { 0x00010002, "RVT" },
+  { 0x000A0001, "R2D" },
+  { 0x000A0002, "RTC" },
+  { 0x000A0004, "FFS" },
+  { 0x000A0008, "KPD" },
+  { 0x000A0010, "SPI" },
+  { 0x000A0020, "PWR" },
+  { 0x000A0040, "RGUI" },
+  { 0x00140001, "HCI" },
+  { 0x00140002, "L2CA" },
+  { 0x00140004, "BTCT" },
+  { 0x00140008, "RFC" },
+  { 0x00140010, "SPP" },
+  { 0x00140020, "HS" },
+  { 0x00140040, "HSG" },
+  { 0x00140080, "SDP" },
+  { 0x00140100, "DUN" },
+  { 0x00140200, "FAX" },
+  { 0x00140400, "OBX" },
+  { 0x00140800, "OPP" },
+  { 0x00141000, "FTP" },
+  { 0x00142000, "SYN" },
+  { 0x001E0001, "EXPL" },
+  { 0x001E0010, "AUDIO" },
+  { 0x001E0020, "ETM" },
+  { 0x001E0040, "DAR" },
+  { 0x001E0080, "MKS" },
+  { 0x001E0100, "MPM" },
+  { 0x001E0200, "LLS" },
+  { 0x001E0400, "ATP" },
+  { 0x001E0800, "ATPUART" },
+  { 0x001E2000, "MDC" },
+  { 0x001E4000, "TTY" },
+  { 0x001E8000, "DCM" },
+  { 0x00280001, "TEST" },
+  { 0x00280002, "TUT" },
+  { 0x00320001, "KIL" },
+  { 0x00320002, "KGC" },
+  { 0x00320004, "KCL" },
+  { 0x00320008, "KMM" },
+  { 0x00320010, "KNM" },
+  { 0x00320020, "UVM" },
+  { 0x00320040, "KZP" },
+  { 0x00320080, "KPG" },
+  { 0x00320100, "JTM" },
+  { 0x003C0001, "DEV1" },
+  { 0x003C0002, "DEV2" },
+  { 0x003C0003, "DEV3" },
+  { 0x00460001, "RNET" },
+  { 0x00460002, "RNET_WS" },
+  { 0x00460004, "RNET_RT" },
+  { 0x00460008, "RNET_BR" },
+  { 0x00640001, "MSME" },
+  { 0x00640002, "MSFE" },
+  { 0x00640004, "STKE" },
+  { 0x00640008, "BRSE" },
+  { 0x00640010, "BRAE" },
+  { 0x00640020, "PHSE" },
+  { 0x00640040, "IBSE" },
+  { 0x00640080, "MMSE" },
+  { 0x00640100, "SLSE" },
+  { 0x00640200, "SMAE" },
+  { 0x00640400, "MEAE" },
+  { 0x00640800, "SECE" },
+  { 0x00641000, "SELE" },
+  { 0x00642000, "PRSE" },
+  { 0x00644000, "JAAE" },
+  { 0x00648000, "JASE" },
+  { 0x006E0001, "IT1E" },
+  { 0x006E0002, "IT2E" },
+  { 0x006E0004, "IT0E" },
+  { 0x0,        NULL}
+};
+#endif
+
+/*==== EXTERNALS ==================================================*/
+
+extern T_HANDLE TST_Handle;
+
+#ifndef _TOOLS_
+extern const T_PCON_PROPERTIES *pcon;
+extern ULONG MaxPrimPartSize;
+extern const T_MEM_PROPERTIES *mem;
+#endif
+
+#ifdef CTB
+  extern BOOL ctb_sent_to_tap;
+  extern BOOL ctb_tick_enabled;
+#endif
+
+/*==== VARIABLES ==================================================*/
+
+#ifndef RUN_INT_RAM
+char corruptWarning[] = "corrupt prim received: ";
+char wrongTSTWarning[] = "wrong (old) TST header used on toolside! ";
+T_TIF_DATA TIF_Data;
+static ULONG TIF_WrInd = 0;
+BOOL socket_flush = TRUE;
+#else
+extern T_TIF_DATA TIF_Data;
+extern BOOL socket_flush;
+#endif /* RUN_INT_RAM */
+
+#ifdef _TOOLS_
+char buffer[80];
+
+const T_PCON_PROPERTIES pcon_export =
+{
+  pcon_init_prim_coding,
+  pcon_decodePrim,
+  pcon_codePrim,
+  pcon_make_filter,
+  PCON_STACK_OFFSET
+};
+
+T_PCON_PROPERTIES const *pcon = &pcon_export;
+#endif
+
+/*==== FUNCTIONS ==================================================*/
+
+#ifndef RUN_INT_RAM
+USHORT TIF_Write ( void *Buffer, ULONG *BytesToWrite );
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TIF                 |
+| STATE   : code                       ROUTINE : TIF_Exit            |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+LOCAL void TIF_Exit ( void )
+{
+#ifdef _TOOLS_
+  ccddata_exit();
+#endif /* _TOOLS_ */
+}
+#endif
+
+#ifndef RUN_FLASH
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TIF                 |
+| STATE   : code                       ROUTINE : TIF_Write           |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+/* Lint is not able to analyze the program flow through if...else constructions
+   and therefor bring a bunch of warnings.*/
+/*lint -e645 suppress warning -- Symbol '...' may not have been initialized */
+/*lint -e644 suppress warning -- Symbol '...' may not have been initialized */
+/*lint -e613 suppress warning -- possibly use of NULL pointer '...' */
+USHORT TIF_Write ( void *Buffer, ULONG *BytesToWrite )
+{
+T_PRIM_HEADER *prim = (T_PRIM_HEADER*)Buffer;
+T_PRIM_HEADER *prim_ptr = NULL;
+TST_SMALL_HEADER *tst_header_ptr;
+T_S_HEADER *s_hdr;
+unsigned int bytes_to_write;
+unsigned int size;
+unsigned int name_len;
+unsigned int length;
+unsigned int org_rcv_len = 0; 
+unsigned int opc_len = 0;
+unsigned int bytes_written = 0;
+unsigned int write_flag = 0;
+char *write_ptr;
+char *tst_data_ptr;
+char trace_opc=0;
+char Sender[RESOURCE_NAMELEN] = {0};
+void *coded_prim;
+void *decoded_prim;
+int pcon_called = 0;
+int is_primitive = TRUE;
+int ret = DRV_OK;
+int sts;
+#ifdef _TOOLS_
+int is_generated_primitive = FALSE;
+#endif /* _TOOLS_ */
+
+
+  s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
+  if ( prim->opc & SYS_MASK )
+  {
+    size = prim->len - sizeof(T_PRIM_HEADER);
+    tst_data_ptr = (char*)P2D(prim);
+    tst_header_ptr = (TST_SMALL_HEADER*) tst_data_ptr - 1;
+    tst_header_ptr->combined[INFO_BYTE] = (~HDR_IDENT_MASK | IDENT_SYS_PRIM);
+    InsertString(s_hdr->rcv, (char*)&tst_header_ptr->receiver, 4);
+    is_primitive = FALSE;
+#ifdef _TOOLS_
+    if ( (length = GetNextToken (tst_data_ptr, buffer, " #")) > 0)
+    {
+      if ( !strcmp (buffer, FILTER) )
+      {
+        void *filter_prim;
+        if ( (pcon != NULL) && pcon->make_filter(tst_data_ptr+length+1, &filter_prim) == PCON_OK )
+        {
+          prim = D2P(filter_prim);
+          s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
+          is_primitive = TRUE;
+          is_generated_primitive = TRUE;
+        }
+      }
+    }
+#endif
+  }
+  else if ( (SAP_NR(prim->opc)==TRACE_SAP) || (prim->opc==TRACE_OPC) )
+  {
+    is_primitive = FALSE;
+    size = prim->len - sizeof(T_PRIM_HEADER);
+    tst_data_ptr = (char*)P2D(prim);
+    if (prim->opc!=TRACE_OPC)
+    {
+      /* we have a traceclass id */
+      trace_opc=(char)PRIM_NR(prim->opc);
+    }
+    tst_header_ptr = (TST_SMALL_HEADER*) tst_data_ptr - 1;
+    tst_header_ptr->combined[INFO_BYTE] = (~HDR_IDENT_MASK | IDENT_TRACE);
+    InsertString(FRM_PCO_NAME, (char*)&tst_header_ptr->receiver, 4);
+  }
+  if ( is_primitive == TRUE )
+  {
+    TST_BIG_HEADER tst_big_header;
+    TST_BIG_HEADER *tst_big_header_ptr;
+#ifdef _TOOLS_
+    /* on the tool side the primitive to be duplicated is copied when sent to TST */
+    prim_ptr = prim;
+#else
+    /* in the target a pointer to the primitive to be duplicated is transported in a carrier of type T_PRIM_X */
+    prim_ptr = (T_PRIM_HEADER*)((T_PRIM_X*)(prim))->prim_ptr;
+#endif
+
+    size = prim_ptr->len - sizeof(T_PRIM_HEADER);
+    tst_data_ptr = (char*)P2D(prim_ptr);
+    tst_big_header_ptr = &tst_big_header;
+    opc_len = 4;
+    org_rcv_len = 4;
+    if ( (pcon != NULL) && (TIF_Data.Config & PCON_ENABLED) && !(prim_ptr->opc & VIRTUAL_OPC) )
+    {
+      decoded_prim = P2D(prim_ptr);
+      if ( (sts = (int)(pcon->code_prim( prim_ptr->opc, decoded_prim, &coded_prim, (ULONG*)&size, 0, s_hdr->rcv ))) != PCON_OK )
+      {
+        vsi_o_ttrace (NO_TASK, TC_SYSTEM,"PCON Code Error %d, TIF_Write() aborted", sts );
+        return DRV_INTERNAL_ERROR;
+      }
+      else
+      {
+        prim_ptr = D2P(coded_prim);
+        tst_data_ptr = coded_prim;
+        pcon_called = 1;
+      }
+    }
+
+    EXCHANGE_4BYTES_ENDIANESS(&prim_ptr->opc);
+
+    tst_big_header_ptr->opc = prim_ptr->opc;
+    tst_big_header_ptr->combined[INFO_BYTE] = (~HDR_IDENT_MASK | IDENT_PS_PRIM);
+    InsertString(s_hdr->rcv, (char*) &tst_big_header_ptr->receiver, 4);
+    InsertString(s_hdr->org_rcv, (char*) &tst_big_header_ptr->orgreceiver, 4);
+    socket_flush = TRUE;
+    tst_header_ptr = (TST_SMALL_HEADER*) tst_big_header_ptr;
+  }
+
+  tst_header_ptr->combined[INFO_BYTE] = ((tst_header_ptr->combined[INFO_BYTE] & (~HDR_VERSION_MASK)) | HDR_VALID_VERSION_1);
+  tst_header_ptr->combined[INFO_BYTE] = ((tst_header_ptr->combined[INFO_BYTE] & (~HDR_TIME_MASK)) | HDR_TIME_MS);
+  tst_header_ptr->time = s_hdr->time;
+  EXCHANGE_4BYTES_ENDIANESS(&tst_header_ptr->time);
+  tst_header_ptr->sender[0] = 0;
+
+  if ( s_hdr->snd[0] == 0 )
+  {
+    if ( *tst_data_ptr == '~')
+    {
+      name_len = GetNextToken ((char*)(tst_data_ptr), Sender, "~");
+      InsertString(Sender, (char*) &tst_header_ptr->sender, 4);
+      size -= 2+name_len;
+      /* rub out a leading ~NAM~ in data field: */
+      memcpy ( tst_data_ptr, tst_data_ptr + 2 + name_len, size );
+    }
+    else
+    {
+      InsertString(FRM_SYST_NAME, (char*)&tst_header_ptr->sender, 4);
+    }
+  }
+  else
+  {
+    T_HANDLE TaskHandle;
+    if ( s_hdr->snd[0] & ~HANDLE_MASK )
+    {
+      TaskHandle = (T_HANDLE)(s_hdr->snd[0]&HANDLE_MASK);
+      vsi_e_name ( TST_Handle, TaskHandle, Sender );
+      InsertString(Sender, (char*)&tst_header_ptr->sender, 4);
+    }
+    else
+    {
+      InsertString(s_hdr->snd, (char*)&tst_header_ptr->sender, 4);
+    }
+  }
+
+  length = size + TST_HEADER_TRAILING_FIELDS + org_rcv_len + opc_len + (trace_opc ? 1 : 0);
+  tst_header_ptr->combined[FIRST_BYTE] = (UBYTE) (LOW_MASK & length);
+  tst_header_ptr->combined[SECOND_BYTE] = (UBYTE) (LOW_MASK & (length >> 8));
+  bytes_to_write = length + TST_HEADER_LEADING_FIELDS;
+  write_ptr = (char*)&tst_header_ptr->combined[INFO_BYTE];
+  if (trace_opc)
+  {
+    /* move small header 1 byte to the left and insert trace class id */
+    char *trace_opc_ptr=tst_data_ptr-1;
+    write_ptr = (char*)tst_header_ptr;
+    memcpy(write_ptr,(char*)tst_header_ptr+1,sizeof(TST_SMALL_HEADER)-1);
+    *trace_opc_ptr=trace_opc;
+    length++;
+  }
+  else if ( prim_ptr != NULL )
+  {
+    bytes_written = TST_BIG_HEADER_SIZE;
+    if ( vsi_d_write ( TIF_Data.Handle, 0, write_ptr, bytes_written | PRIM_HEADER_FLAG ) != VSI_OK )
+    {
+      ret = DRV_INTERNAL_ERROR;
+      *BytesToWrite = 0;
+    }
+    write_ptr = tst_data_ptr;
+    write_flag = PRIM_DATA_FLAG;
+  }
+
+  if (ret==DRV_OK)
+  {
+#if defined (_TOOLS_) || defined (_LINUX_) || defined (_SOLARIS_)
+    socket_flush = TRUE;  /* flush socket always on tool side */
+#endif
+
+    if ( vsi_d_write ( TIF_Data.Handle, 0, write_ptr, (bytes_to_write - bytes_written) | write_flag ) != VSI_OK )
+    {
+      ret = DRV_INTERNAL_ERROR;
+      *BytesToWrite = 0;
+    }
+  }
+  if ( pcon_called )
+  {
+    PFREE(P2D((T_VOID_STRUCT*)prim_ptr));
+  }
+#ifdef _TOOLS_
+  if ( is_generated_primitive == TRUE )
+  {
+    vsi_c_free ( TST_Handle, (T_VOID_STRUCT**)&prim );
+  }
+#else /* _TOOLS_ */
+  if (prim->opc & MEMHANDLE_OPC)
+  {
+    M_FREE(P_MEMHANDLE_SDU(((T_PRIM_X*)(prim))->prim_ptr));
+  }
+#endif /* _TOOLS_ */
+#if defined _NUCLEUS_ && !defined _TARGET_
+#ifdef CTB
+  if(ctb_tick_enabled && !ctb_sent_to_tap && !strncmp(tst_header_ptr->receiver,"TAP",3)) 
+  {
+    ctb_sent_to_tap = TRUE;
+  }
+#endif
+#endif
+
+  return ( (USHORT)ret );
+}
+/*lint +e645 */
+/*lint +e613 */
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TIF                 |
+| STATE   : code                       ROUTINE : TIF_SetSignal       |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+LOCAL USHORT TIF_SetSignal ( USHORT SignalType )
+{
+  if ( !(SignalType & ALLOWED_TIF_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    TIF_Data.EnabledSignalType |= SignalType;
+
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TIF                 |
+| STATE   : code                       ROUTINE : TIF_ResetSignal     |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+LOCAL USHORT TIF_ResetSignal ( USHORT SignalType )
+{
+  if ( !(SignalType & ALLOWED_TIF_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    TIF_Data.EnabledSignalType &= ~SignalType;
+
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TIF                 |
+| STATE   : code                       ROUTINE : TIF_SetConfig       |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+*/
+/*lint -esym(715,Buffer), suppress Info -- Symbol 'Buffer' not referenced) */
+LOCAL USHORT TIF_SetConfig ( char *Buffer )
+{
+  if ( !strcmp ( TIF_PCON_ENABLE, Buffer ) )
+  {
+    if ( TIF_Data.Config & PCON_ENABLED)
+    {
+      /* already in PCON mode */
+      return DRV_OK;
+    }
+
+#ifdef _TOOLS_
+    switch (ccddata_init(NULL,0,NULL,NULL))
+    {
+      case CCDDATA_DLL_OK:
+      case CCDDATA_DLL_ALREADY:
+        break;
+      default:
+        return DRV_INTERNAL_ERROR;
+    }
+#endif
+    TIF_Data.Config |= PCON_ENABLED;
+
+#ifdef _TOOLS_
+    printf("TIF: PCON mode selected\n");
+#endif
+    return DRV_OK;
+  }
+  else if ( !strcmp ( DRV_DEFAULT, Buffer ) )
+  {
+    if ( !(TIF_Data.Config & PCON_ENABLED))
+    {
+      /* already in default mode */
+      return DRV_OK;
+    }
+
+#ifdef _TOOLS_
+    ccddata_exit();
+#endif
+    TIF_Data.Config &= ~PCON_ENABLED;
+
+#ifdef _TOOLS_
+    printf("TIF: default mode selected\n");
+#endif
+    return DRV_OK;
+  }
+#ifdef _TOOLS_
+  else if ( !strcmp ( ENABLE_SYNC_MODE, Buffer ) )
+  {
+    TIF_Data.Config |= SYNC_MODE;
+    PrintToFile("TIF: sync mode enabled\n");
+    return DRV_OK;
+  }
+  else if ( !strcmp ( DISABLE_SYNC_MODE, Buffer ) )
+  {
+    TIF_Data.Config &= ~SYNC_MODE;
+    PrintToFile("TIF: sync mode disabled\n");
+    return DRV_OK;
+  }
+  return DRV_INVALID_PARAMS;
+#else
+  return DRV_OK;
+#endif
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TIF                 |
+| STATE   : code                       ROUTINE : Callback            |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+/* Lint is not able to analyze the program flow through if...else constructions
+   and therefor bring a bunch of warnings.*/
+/*lint -esym(645,opc_str) suppress warning -- Symbol 'opc_str' may not have been initialized */
+LOCAL void TIF_Callback ( T_DRV_SIGNAL *Signal )
+{
+T_PRIM_HEADER *prim;
+T_S_HEADER *s_hdr;
+T_PRIM_X *sys_prim;
+T_DRV_SIGNAL TIF_Signal;
+TST_BIG_HEADER tst_header;
+unsigned int CorruptByteOffset = 0;
+unsigned int length;
+unsigned int BytesToRead = 0;
+unsigned int BytesRead;
+unsigned int Bytes = 0;
+unsigned int i;
+unsigned int opc_len = 0;
+unsigned int org_rcv_len = 0;
+unsigned int alloc_size;
+int sts;
+int WrongTSTHeader = FALSE;
+char *target;
+void *decoded_prim;
+char opc_str[4];
+#ifdef _TOOLS_
+int l1_sigtype = 0;
+#endif
+
+  switch ( Signal->SignalType )
+  {
+#ifdef _TOOLS_
+    case DRV_SIGTYPE_READ_L1:
+      l1_sigtype = 1;
+      /*lint -fallthrough*/
+    case DRV_SIGTYPE_READ_RIV:
+
+      if ( vsi_d_read ( TIF_Data.Handle, 0, NULL, &BytesToRead ) != DRV_OK )
+        return;
+
+      alloc_size = S_ALLOC_SIZE(BytesToRead + 1);
+      if ( ( prim = (T_PRIM_HEADER*)vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO )) != NULL )
+      {
+        TIF_WrInd = 0;
+        Bytes = 0;
+        BytesRead = BytesToRead;
+        do
+        {
+          vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)P2D(prim)+TIF_WrInd), &BytesRead );
+          Bytes += BytesRead;
+          if ( Bytes < BytesToRead )
+          {
+            TIF_WrInd += BytesRead;
+            BytesRead = BytesToRead - BytesRead;
+          }
+        } while ( Bytes < BytesToRead );
+        prim->sh_offset = S_HDR_OFFSET(alloc_size - sizeof(T_S_HEADER));
+        s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
+        s_hdr->time = 0;
+        s_hdr->org_rcv[0] = 0;
+        if ( l1_sigtype == 1 )
+        {
+          strcpy ( s_hdr->snd, "L1" );
+        }
+        else
+        {
+          int i = 0;
+          unsigned int use_id = 0;
+          unsigned char *p = (unsigned char*)P2D(prim);
+          use_id = use_id | *p++ << 24;
+          use_id = use_id | *p++ << 16;
+          use_id = use_id | *p++ << 8;
+          use_id = use_id | *p;
+          do
+          {
+            if ( riv_use_id_to_name[i].use_id == use_id )
+            {
+              strcpy ( s_hdr->snd, riv_use_id_to_name[i].name );
+              break;
+            }
+            if ( riv_use_id_to_name[i+1].use_id == 0 )
+              strcpy ( s_hdr->snd, "RIV" );
+          } while ( riv_use_id_to_name[++i].use_id != 0 );
+          memcpy ( (char*)P2D(prim), (char*)P2D(prim)+5, BytesToRead);
+        }
+        strcpy ( s_hdr->rcv, FRM_PCO_NAME );
+
+        sys_prim = (T_PRIM_X*) vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO );
+        sys_prim->prim_ptr = prim;
+        prim->opc = 0;
+        prim->len = BytesToRead  + sizeof(T_PRIM_HEADER);
+
+        if ( TIF_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+        {
+          VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim, TST_Handle );
+          VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim->prim_ptr, TST_Handle );
+          TIF_Signal.SignalType = DRV_SIGTYPE_READ;
+          TIF_Signal.DrvHandle = TIF_Data.Handle;
+          TIF_Signal.UserData = (T_VOID_STRUCT*)sys_prim;
+          (TIF_Data.Callback)( &TIF_Signal );
+        }
+      }
+      break;
+#endif
+    case DRV_SIGTYPE_READ:
+      /*
+       * Get the size of the needed buffer to store the data
+       */
+
+      if ( vsi_d_read ( TIF_Data.Handle, 0, NULL, (ULONG*)&BytesToRead ) != DRV_OK )
+        return;
+
+      if ( BytesToRead )
+      {
+        if ( BytesToRead >= TST_SMALL_HEADER_SIZE )
+          BytesToRead -= TST_SMALL_HEADER_SIZE;
+        Bytes = 0;
+        TIF_WrInd = 0;
+        BytesRead = TST_SMALL_HEADER_SIZE;
+        do
+        {
+          vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)&tst_header.combined[INFO_BYTE]+TIF_WrInd), (ULONG*)&BytesRead );
+          Bytes += BytesRead;
+          if ( Bytes < TST_SMALL_HEADER_SIZE )
+          {
+            TIF_WrInd += BytesRead;
+            BytesRead = TST_SMALL_HEADER_SIZE - BytesRead;
+          }
+        } while ( Bytes < TST_SMALL_HEADER_SIZE );
+
+        alloc_size = ALIGN(sizeof(T_PRIM_X));
+        sys_prim = (T_PRIM_X*) vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO );
+
+        switch (tst_header.combined[INFO_BYTE] &  HDR_IDENT_MASK)
+        {
+          case IDENT_ABORT:
+            tst_header.combined[INFO_BYTE] = ((tst_header.combined[INFO_BYTE] & ~HDR_IDENT_MASK) | IDENT_TRACE);
+#ifdef _TOOLS_
+            /* TR did loose byte(s)! Primitive is corrupt, no header val can be
+            guaranteed to be valid.
+            Create a HUGE trace prim with zero time, sender tst, receiver pco,
+            org_receiver tst
+            TRACE DATA will contain: a "corrupt prim received: " string,
+            the already received part of the prim and all the rest */
+            CorruptByteOffset = TST_SMALL_HEADER_SIZE + strlen(corruptWarning) + 1;
+#else
+            /* TR did receive a prim from tool side old TST header format and swiched to new.
+            Now we have to TRACE the wrong tool side format, because the prim is lost. */
+            WrongTSTHeader = TRUE;
+            BytesToRead = 0;
+            CorruptByteOffset = strlen(wrongTSTWarning) + 1;
+#endif
+            break;
+          case IDENT_PS_PRIM:
+            opc_len = 4;
+            org_rcv_len = 4;
+            break;
+          default:
+            break;
+        }
+
+        if ( (BytesRead = org_rcv_len) > 0 )
+        {
+          if ( BytesToRead >= org_rcv_len )
+            BytesToRead -= org_rcv_len;
+          Bytes = 0;
+          TIF_WrInd = 0;
+          do
+          {
+            vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)&tst_header.orgreceiver+TIF_WrInd), (ULONG*)&BytesRead );
+            Bytes += BytesRead;
+            if ( Bytes < org_rcv_len )
+            {
+              TIF_WrInd += BytesRead;
+              BytesRead = org_rcv_len - BytesRead;
+            }
+          } while ( Bytes < org_rcv_len );
+        }
+
+        if ( (BytesRead = opc_len) > 0 )
+        {
+          if ( BytesToRead >= opc_len )
+            BytesToRead -= opc_len;
+          Bytes = 0;
+          TIF_WrInd = 0;
+          do
+          {
+            vsi_d_read ( TIF_Data.Handle, 0, (void*)(opc_str+TIF_WrInd), (ULONG*)&BytesRead );
+            Bytes += BytesRead;
+            if ( Bytes < opc_len )
+            {
+              TIF_WrInd += BytesRead;
+              BytesRead = opc_len - BytesRead;
+            }
+          } while ( Bytes < opc_len );
+        }
+
+        alloc_size = S_ALLOC_SIZE(CorruptByteOffset + BytesToRead + 1);
+#ifdef _TOOLS_
+        if ( alloc_size > MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER))
+          alloc_size = MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER);
+#else
+        if ( alloc_size > MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER) )
+          alloc_size = MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER);
+#endif
+        if ( ( prim = (T_PRIM_HEADER*)vsi_c_new ( TST_Handle, alloc_size, 0 FILE_LINE_MACRO )) != NULL )
+        {
+          TIF_WrInd = 0;
+          Bytes = 0;
+          if ((BytesToRead + CorruptByteOffset) > alloc_size)
+          {
+#ifdef _TOOLS_
+            PrintToFile("TIF: Reduced a new Prim's size\n");
+#endif
+            BytesToRead = alloc_size - CorruptByteOffset;
+          }
+          BytesRead = BytesToRead;
+
+          target = (char*) P2D(prim);
+
+          if (WrongTSTHeader)
+          {
+            memcpy(target, wrongTSTWarning, strlen(wrongTSTWarning));
+            target += strlen(wrongTSTWarning);
+          }
+          else if (CorruptByteOffset)
+          {
+#ifdef _TOOLS_
+            PrintToFile("TIF: Byte(s) lost\n");
+#endif
+            memcpy(target, corruptWarning, strlen(corruptWarning));
+            target += strlen(corruptWarning);
+            /*lint -e420, suppress Warning -- Apparent access beyond array for function 'memcpy(...*/
+            memcpy(target,&tst_header.combined[INFO_BYTE], TST_SMALL_HEADER_SIZE-1);
+            /*lint +e420 */
+            target += TST_SMALL_HEADER_SIZE - 1;
+          }
+
+
+          if (WrongTSTHeader == FALSE && BytesToRead)
+          {
+            if ( (tst_header.combined[INFO_BYTE] &  HDR_IDENT_MASK)==IDENT_TRACE )
+            {
+              /* we read the first bytes in advance in case the trace class is carried */
+              ULONG bread=1;
+              vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)target+TIF_WrInd), &bread );
+
+              if (bread==1 && *((char*)target)<0x20) /* no character -> assume traceclass id */
+              {
+                opc_str[0]=*((char*)target);
+                opc_len=1;
+
+                BytesToRead -= bread;
+              }
+              else
+              {
+                /* ok, we have no traceclass info :-( */
+                TIF_WrInd += bread;
+                Bytes += bread;
+              }
+              BytesRead = BytesToRead - Bytes;
+            }
+
+            do
+            {
+              vsi_d_read ( TIF_Data.Handle, 0, (void*)((char*)target+TIF_WrInd), (ULONG*)&BytesRead );
+              Bytes += BytesRead;
+              if ( Bytes < BytesToRead )
+              {
+                TIF_WrInd += BytesRead;
+                BytesRead = BytesToRead - Bytes;
+              }
+            } while ( Bytes < BytesToRead );
+          }
+
+          *((char*)target + Bytes) = 0;
+          prim->sh_offset = S_HDR_OFFSET(alloc_size - sizeof(T_S_HEADER));
+          s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
+          switch (tst_header.combined[INFO_BYTE] &  HDR_IDENT_MASK)
+          {
+            case IDENT_PS_PRIM:
+
+              EXCHANGE_4BYTES_ENDIANESS(opc_str);
+
+              memcpy((char*)&prim->opc, opc_str, 4);
+              if ( (pcon != NULL) && (TIF_Data.Config & PCON_ENABLED) )
+              {
+                if ( (sts = (int)pcon->decode_prim ( prim->opc, &decoded_prim, (void*)((char*)prim+sizeof(T_PRIM_HEADER)), (ULONG*)&length, 0 )) != PCON_OK )
+                {
+                  if ( sts != PCON_CONFIG_PRIM )
+                  {
+                    vsi_o_ttrace (NO_TASK, TC_SYSTEM,"PCON Deode Error %d, TIF_Callback() aborted", sts );
+                  }
+                  PFREE(P2D(sys_prim));
+                  PFREE(P2D(prim));
+                  return;
+                }
+                PFREE(P2D((T_VOID_STRUCT*)prim));
+                sys_prim->prim_ptr = D2P(decoded_prim);
+              }
+              else
+              {
+                sys_prim->prim_ptr = prim;
+                length = BytesToRead;
+              }
+              sys_prim->prim_ptr->sh_offset = S_HDR_OFFSET(length+sizeof(T_PRIM_HEADER));
+              sys_prim->prim_ptr->len = length + sizeof(T_PRIM_HEADER);
+              s_hdr = (T_S_HEADER*)((ULONG*)sys_prim->prim_ptr + sys_prim->prim_ptr->sh_offset);
+#ifndef _TOOLS_
+              /* evtl. convert aux sdu to mem handle */
+              if (sys_prim->prim_ptr->opc & MEMHANDLE_OPC && mem!=NULL)
+              {
+                if (P_MEMHANDLE_SDU(sys_prim->prim_ptr))
+                {
+                  U32 mem_handle;
+                  U8 buffer_handle;
+                  U8 user_handle;
+                  U8 *user_data;
+                  T_sdu *sdu;
+                  U16 len;
+
+                  sdu=(T_sdu *)P_MEMHANDLE_SDU(sys_prim->prim_ptr);
+                  len=(sdu->l_buf + 7)/8;
+
+                  buffer_handle=mem->create_buffer(MEM_UNORDERED_BUFFER, len);
+                  user_handle = mem->create_user(buffer_handle, 23, "TST");
+
+                  user_data=mem->alloc(user_handle,len,&mem_handle);
+                  memcpy(user_data,sdu->buf+(sdu->o_buf+7)/8,len);
+                  P_MEMHANDLE(sys_prim->prim_ptr)=mem_handle;
+
+                  mem->delete_user(user_handle);
+                  mem->delete_buffer(buffer_handle);
+                }
+              }
+#endif
+            break;
+
+            case IDENT_SYS_PRIM:
+              sys_prim->prim_ptr = prim;
+              prim->opc = SYS_MASK;
+              prim->len = BytesToRead  + sizeof(T_PRIM_HEADER);
+            break;
+
+            case IDENT_TRACE:
+              sys_prim->prim_ptr = prim;
+              if (opc_len)
+              {
+                /* nice, we found a traceclass info */
+                prim->opc = opc_str[0];
+                prim->opc = prim->opc << 16;
+                prim->opc |= EXTENDED_OPC | VIRTUAL_OPC | TRACE_SAP;
+              }
+              else
+              {
+                prim->opc = TRACE_OPC;
+              }
+              prim->len = CorruptByteOffset + BytesToRead  + sizeof(T_PRIM_HEADER);
+              break;
+
+            default:
+            break;
+          }
+
+          /*
+           * Extract Sender and Receiverfrom header
+           */
+          if (CorruptByteOffset)
+          {
+            s_hdr->time = NULL;
+#ifndef _TOOLS_
+            memcpy ( s_hdr->snd, "~TST", 4 );
+            memcpy ( s_hdr->rcv, FRM_TST_NAME, 4 );
+#else
+            memcpy ( s_hdr->snd, FRM_TST_NAME, 4 );
+            memcpy ( s_hdr->rcv, FRM_PCO_NAME, 4 );
+#endif
+            memcpy ( s_hdr->org_rcv, "TST", 4 );
+          }
+          else
+          {
+            s_hdr->time = tst_header.time;
+
+            i = 0;
+            do
+            {
+              s_hdr->snd[i] = tst_header.sender[i];
+              i++;
+            } while ( tst_header.sender[i] != 0x20 && i < 4 );
+            s_hdr->snd[i] = 0;
+
+            i = 0;
+            do
+            {
+              s_hdr->rcv[i] = tst_header.receiver[i];
+              i++;
+            } while ( tst_header.receiver[i] != 0x20 && i < 4 );
+            s_hdr->rcv[i] = 0;
+
+            if (org_rcv_len)
+            {
+              i = 0;
+              do
+              {
+                s_hdr->org_rcv[i] = tst_header.orgreceiver[i];
+                i++;
+              } while ( tst_header.orgreceiver[i] != 0x20 && i < 4 );
+              s_hdr->org_rcv[i] = 0;
+            }
+          }
+
+          if ( TIF_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+          {
+            VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim, TST_Handle );
+            VSI_PPM_SEND ( (T_PRIM_HEADER*)sys_prim->prim_ptr, TST_Handle );
+            TIF_Signal.SignalType = DRV_SIGTYPE_READ;
+            TIF_Signal.DrvHandle = TIF_Data.Handle;
+            TIF_Signal.UserData = (T_VOID_STRUCT*)sys_prim;
+            (TIF_Data.Callback)( &TIF_Signal );
+          }
+        }
+      } /* if ( BytesToRead ) */
+    break;
+    case DRV_SIGTYPE_CONNECT:
+    case DRV_SIGTYPE_DISCONNECT:
+      if ( TIF_Data.EnabledSignalType & Signal->SignalType )
+      {
+        TIF_Signal.SignalType = Signal->SignalType;
+        TIF_Signal.DrvHandle = TIF_Data.Handle;
+        TIF_Signal.UserData = NULL;
+        (TIF_Data.Callback)( &TIF_Signal );
+      }
+    break;
+    default:
+    break;
+  }
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TIF                 |
+| STATE   : code                       ROUTINE : TIF_Init            |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+GLOBAL USHORT TIF_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{
+static const T_DRV_EXPORT TIF_Info =
+{
+  TIF_NAME,
+  0,
+  {
+#ifdef _TOOLS_
+    TIF_Init,
+#endif
+    TIF_Exit,
+    NULL,
+    TIF_Write,
+    NULL,
+    NULL,
+    NULL,
+    TIF_SetSignal,
+    TIF_ResetSignal,
+    TIF_SetConfig,
+    NULL,
+    TIF_Callback,
+  }
+};
+
+#ifndef _TOOLS_
+union
+{
+  USHORT s;
+  UBYTE b[2];
+} test;
+#endif /* !_TOOLS_ */
+
+  TIF_Data.Handle = DrvHandle;
+  TIF_Data.EnabledSignalType = 0;
+  TIF_Data.Config = 0;
+  TIF_Data.Callback = CallbackFunc;
+
+#ifdef _TOOLS_
+  switch (ccddata_init(NULL,0,NULL,NULL))
+  {
+    case CCDDATA_DLL_OK:
+    case CCDDATA_DLL_ALREADY:
+      break;
+    default:
+      return DRV_INITFAILURE;
+  }
+#else /* _TOOLS_ */
+  test.s = 1;
+  if ( pcon != NULL )
+  {
+    ULONG sts = pcon->init_prim_coding ( TST_Handle,(UBYTE)((test.b[0]==1) ? PCON_LITTLE : PCON_BIG));
+#ifndef _TARGET_ 
+    vsi_pcheck_register (pcon->pcheck, PCON_OK);
+#endif /* !_TARGET_ */
+  }
+#endif /* !_TOOLS_ */
+
+  *DrvInfo = &TIF_Info;
+
+  return DRV_OK;
+}
+#endif
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/titrc.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,321 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       titrc.c
++------------------------------------------------------------------------------
+|  Copyright 2004 Texas Instruments Deutschland, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Deutschland, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Module defines the functionality of the TITRC driver
+|             to communicate with the TI trace task.
++----------------------------------------------------------------------------- 
+*/ 
+
+
+#ifndef __TITRC_C__
+#define __TITRC_C__
+#endif
+
+#include "typedefs.h"
+#include "string.h"
+#include "tstheader.h"
+#include "rvt_gen.h"
+#include "gdi.h"
+#include "serialswitch.h"
+
+/*==== TYPES ======================================================*/
+
+typedef struct
+{
+  USHORT Handle;
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+  T_RVT_USER_ID trc_id;
+  unsigned char connected;
+  T_RVT_BUFFER read_ptr;
+  unsigned int read_len;
+} T_TITRC_DATA;
+
+/*==== CONSTANTS ==================================================*/
+
+#define ALLOWED_TITRC_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT) 
+
+
+/*==== EXTERNALS ==================================================*/
+
+extern USHORT emergeny_trace;
+
+/*==== VARIABLES ==================================================*/
+
+#ifndef RUN_INT_RAM
+T_TITRC_DATA TITRC_Data;
+T_DRV_SIGNAL Signal;
+#else
+extern T_TITRC_DATA TITRC_Data;
+#endif
+
+#ifndef RUN_FLASH
+char header_buffer[TST_BIG_HEADER_SIZE];
+#endif
+
+/*==== FUNCTIONS ==================================================*/
+
+#ifndef RUN_INT_RAM
+extern USHORT TITRC_Write ( void *Buffer, ULONG *BytesToWrite ) ;
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TITRC               |
+| STATE   : code                       ROUTINE : TITRC_Read          |
++--------------------------------------------------------------------+
+
+  PURPOSE : read data from driver
+
+*/
+USHORT TITRC_Read ( void *Buffer, ULONG *BytesToRead )
+{
+
+  if ( TITRC_Data.read_ptr )
+  {
+    if ( *BytesToRead != 0 )
+    {
+      if ( *BytesToRead > TITRC_Data.read_len )
+        *BytesToRead = TITRC_Data.read_len;
+
+      memcpy ( Buffer, TITRC_Data.read_ptr, *BytesToRead );
+
+      if ( *BytesToRead < TITRC_Data.read_len )
+      {
+        TITRC_Data.read_ptr += *BytesToRead;
+        TITRC_Data.read_len -= *BytesToRead;
+      }
+      else
+        TITRC_Data.read_ptr = NULL;
+    }
+    else
+    {
+      *BytesToRead = TITRC_Data.read_len;
+    }
+  }
+  else
+  {
+    *BytesToRead = 0;
+  }
+
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_FLASH
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TITRC               |
+| STATE   : code                       ROUTINE : TITRC_Write         |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+USHORT TITRC_Write ( void *Buffer, ULONG *BytesToWrite )
+{
+T_RVT_FORMAT msg_format;
+char *ptr = (char*)Buffer;
+ULONG BytesWritten;
+ULONG ToWrite;
+T_RVT_BUFFER rvt_buffer;
+
+  msg_format = RVT_BINARY_FORMAT;
+
+  if ( emergeny_trace )
+  {
+    ptr--;
+    *ptr = 0x13;
+    ToWrite = (ULONG)*BytesToWrite;
+    ToWrite += 1;
+    BytesWritten = (ULONG)SER_tr_WriteNBytes (1, (SYS_UWORD8*)ptr, (SYS_UWORD32)ToWrite);
+    *BytesToWrite = BytesWritten;
+  }
+  else
+  {
+    if ( *BytesToWrite & PRIM_HEADER_FLAG )
+    {
+      memcpy ( header_buffer, (char*)Buffer, TST_BIG_HEADER_SIZE );
+      return DRV_OK;
+    }
+    if ( *BytesToWrite & PRIM_DATA_FLAG )
+    {
+      ToWrite = *BytesToWrite & ~PRIM_DATA_FLAG;
+      if ( rvt_mem_alloc(TITRC_Data.trc_id, ToWrite+TST_BIG_HEADER_SIZE, &rvt_buffer) != RVT_OK )
+        return DRV_BUFFER_FULL;
+      if ( rvt_buffer != NULL )
+      {
+        memcpy ( (char*)rvt_buffer, header_buffer, TST_BIG_HEADER_SIZE );
+        memcpy ( (char*)rvt_buffer+TST_BIG_HEADER_SIZE, (char*)Buffer, ToWrite );
+        if ( rvt_send_trace_no_cpy ( rvt_buffer, TITRC_Data.trc_id, (T_RVT_MSG_LG)ToWrite+TST_BIG_HEADER_SIZE, msg_format ) != RVT_OK )
+          return DRV_BUFFER_FULL;
+        else
+          return DRV_OK;
+      }
+    }
+    if ( rvt_send_trace_cpy ( (T_RVT_BUFFER)Buffer, TITRC_Data.trc_id, (T_RVT_MSG_LG)*BytesToWrite, msg_format ) != RVT_OK )
+      return DRV_BUFFER_FULL;
+  }
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TITRC               |
+| STATE   : code                       ROUTINE : TITRC_SetSignal     |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+USHORT TITRC_SetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_TITRC_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    TITRC_Data.EnabledSignalType |= SignalType;
+  
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TITRC               |
+| STATE   : code                       ROUTINE : TITRC_ResetSignal   |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+USHORT TITRC_ResetSignal ( USHORT SignalType )
+{
+	if ( !(SignalType & ALLOWED_TITRC_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    TITRC_Data.EnabledSignalType &= ~SignalType;
+  
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TITRC               |
+| STATE   : code                       ROUTINE : TITRC_SetConfig     |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+*/
+USHORT TITRC_SetConfig ( char *Buffer )
+{
+
+  if ( TITRC_Data.connected == FALSE )
+  {
+    Signal.SignalType = DRV_SIGTYPE_CONNECT;
+	  Signal.DrvHandle = TITRC_Data.Handle;
+    (TITRC_Data.Callback)( &Signal );
+    TITRC_Data.connected = TRUE;
+  }
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TITRC               |
+| STATE   : code                       ROUTINE : TITRC_Callback      |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+int callback_busy = 0;
+void TITRC_Callback ( T_RVT_BUFFER ptr, UINT16 len )
+{
+  if ( 	callback_busy == 1 )
+    for (;;)
+      ;
+
+	callback_busy = 1;
+  if ( TITRC_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+  {
+    TITRC_Data.read_ptr = ptr;
+    TITRC_Data.read_len = len;
+    Signal.SignalType = DRV_SIGTYPE_READ;
+	  Signal.DrvHandle = TITRC_Data.Handle;
+    (TITRC_Data.Callback)( &Signal );
+  }
+	callback_busy = 0;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TITRC               |
+| STATE   : code                       ROUTINE : TITRC_Init          |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+USHORT TITRC_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{                
+static const T_DRV_EXPORT TITRC_Info =
+{
+  "TITRC",
+  0,
+  {
+#ifdef _TOOLS_
+    TITRC_Init,
+#endif
+    NULL,
+    TITRC_Read,
+    TITRC_Write,
+    NULL,
+    NULL,
+    NULL,
+    TITRC_SetSignal,
+    TITRC_ResetSignal,
+    TITRC_SetConfig,
+    NULL,
+    NULL,
+  }
+};
+
+  TITRC_Data.connected = FALSE;
+    
+  TITRC_Data.Handle = DrvHandle;
+
+  TITRC_Data.EnabledSignalType = 0;
+
+  TITRC_Data.Callback = CallbackFunc;
+
+  if ( rvt_register_id ( (char*)"L23",&TITRC_Data.trc_id, TITRC_Callback ) == RVT_INVALID_PARAMETER )
+    return DRV_INITFAILURE;
+
+  *DrvInfo = &TITRC_Info;
+
+  return DRV_OK;           
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/tr2.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,1005 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       tr.c
++------------------------------------------------------------------------------
+|  Copyright 2004 Texas Instruments Deutschland, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Deutschland, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the TR driver
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __TR_C__
+#define __TR_C__
+#endif
+
+#include "string.h"
+#include "typedefs.h"
+#include "gdi.h"
+#include "vsi.h"
+#include "os.h"
+#ifdef _TOOLS_
+  #include <stdio.h>
+  #include "glob_defs.h"
+  #include "tstdriver.h"
+  #include "frame.h"
+  #include "frame_const.h"
+  #include "printtofile.h"
+#endif /* _TOOLS_ */
+#include "tstheader.h"
+#include "tst_mux.h"
+
+
+/*==== TYPES ======================================================*/
+
+typedef struct
+{
+  T_VOID_STRUCT *RcvBuffer;
+  USHORT Handle;
+  USHORT EnabledSignalType;
+  T_DRV_CB_FUNC Callback;
+  USHORT config;
+  UBYTE rcv_state;
+  UBYTE idle_state;
+} T_TR_DATA;
+
+
+/*==== CONSTANTS ==================================================*/
+
+#define ALLOWED_TR_SIGNALS   (DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT|DRV_SIGTYPE_DISCONNECT) 
+
+#define STX                 0x02
+#define TI_RIV_ID           0x11
+#define TI_L1_ID            0x12
+#define TI_L23_ID           0x13
+#define TI_STX              0x02
+#define TI_ESC              0x10
+#define CHAR_ABORT          'A'
+
+#define DATA_SEGMENT_SIZE   223
+
+#define WAIT_FOR_STX        0
+#define WAIT_FOR_IDENT      1
+#define WAIT_FOR_TIMESTAMP  2
+#define WAIT_FOR_LENGTH     3
+#define WAIT_FOR_SND        4
+#define WAIT_FOR_RCV        5
+#define WAIT_FOR_DATA       6
+#define WAIT_FOR_CR         7
+#define WAIT_FOR_TI_ID      8
+#define WAIT_FOR_TI_LEN_0   9
+#define WAIT_FOR_TI_LEN_1  10
+#define WAIT_FOR_TI_LEN_2  11
+#define WAIT_FOR_LENGTH1   12
+#define WAIT_FOR_LENGTH2   13
+#define WAIT_FOR_RAW_TI_S  14
+#define WAIT_FOR_RAW_TI_ID 15
+#define WAIT_FOR_RAW_TI_E  16
+
+#define WAIT_FOR_MUX_START_STX  1
+#define WAIT_FOR_MUX_CHAN_ID    2
+#define WAIT_FOR_MUX_END_STX    3
+
+#define STX_LF_MODE       0x0001
+#define TI_TRC_MODE       0x0002
+#define TI_RAW_TRC_MODE   0x0004
+
+/*==== EXTERNALS ==================================================*/
+
+extern ULONG TR_RcvBufferSize;
+extern ULONG TR_MaxInd;
+extern USHORT ext_data_pool_handle;
+extern T_TST_MUX_CHANNEL tst_mux_chan_struct[];
+
+/*==== VARIABLES ==================================================*/
+
+#ifndef RUN_INT_RAM
+#ifndef _TARGET_
+long int accessNum = 0;
+#endif
+T_TR_DATA TR_Data;
+static char *TR_RcvBuffer;
+static ULONG TR_EndInd;
+static ULONG TR_WrInd;
+static ULONG TR_RdInd;
+static ULONG MessageLength;
+static union {
+    unsigned short int val;
+    char part[2];
+}tst_trailer_size;
+#else
+extern T_TR_DATA TR_Data;
+#endif
+
+#ifdef _TOOLS_
+static int ti_id_not_found;
+static int ti_esc_skipped;
+extern int tst_message_received;
+#else
+extern ULONG MaxPrimPartSize;
+#endif
+
+/*==== FUNCTIONS ==================================================*/
+
+#ifndef RUN_INT_RAM
+USHORT TR_Write ( void *Buffer, ULONG *BytesToWrite ); 
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : TR_Exit             |
++--------------------------------------------------------------------+
+
+  PURPOSE : exit a driver
+
+*/
+LOCAL void TR_Exit ( void )
+{
+  os_DeallocateMemory ( 0, TR_Data.RcvBuffer );
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : TR_Read             |
++--------------------------------------------------------------------+
+
+  PURPOSE : read data from driver
+
+*/
+LOCAL USHORT TR_Read ( void *Buffer, ULONG *BytesToRead )
+{
+ULONG Space = TR_EndInd - (TR_RdInd & TR_MaxInd);
+static ULONG bytes_read;
+
+  if ( *BytesToRead == 0 )
+  {
+    *BytesToRead = MessageLength;
+    bytes_read = 0;
+  }
+  else
+  {
+    if ( Space > *BytesToRead ) 
+    {
+      memcpy ( Buffer, &TR_RcvBuffer[TR_RdInd&TR_MaxInd], *BytesToRead );
+      bytes_read += *BytesToRead;
+    }
+    else
+    {
+      memcpy ( Buffer, &TR_RcvBuffer[TR_RdInd&TR_MaxInd], (unsigned int)Space );
+      *BytesToRead = Space;
+      bytes_read += Space;
+    }
+    TR_RdInd += *BytesToRead;
+    if ( TR_Data.config & STX_LF_MODE )
+      if ( bytes_read == MessageLength )
+        TR_RdInd++;  /* skip th LF, its not read by the TIF driver */
+  }
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : TR_Write            |
++--------------------------------------------------------------------+
+
+  PURPOSE : write data to driver
+
+*/
+USHORT TR_Write ( void *Buffer, ULONG *BytesToWrite )
+{
+char *snd_ptr = (char*)Buffer;
+ULONG btw;
+char ti_mode_header[2];
+
+ti_mode_header[0] = TI_STX;
+ti_mode_header[1] = TI_L23_ID;
+
+#ifdef _TOOLS_
+btw=(*BytesToWrite) & ~PRIM_FLAG_MASK;
+#else
+btw=(*BytesToWrite);
+#endif
+
+#ifdef _TOOLS_
+  if (TR_Data.config & TI_RAW_TRC_MODE)
+  {
+    ULONG full_btw, segment_size;
+    /*lint -e813, suppress Info 813: auto variable 'osver' has size '148' */ 
+    char segment[DATA_SEGMENT_SIZE*2+3];
+    /*lint +e813 */
+    ULONG q;
+
+    full_btw=btw;
+    while (full_btw)
+    {
+      btw= (full_btw>DATA_SEGMENT_SIZE) ? DATA_SEGMENT_SIZE : full_btw;
+
+      /* fill in leading bytes */
+      segment_size=0;
+      segment[segment_size++]=TI_STX;
+      segment[segment_size++]=TI_L23_ID;
+
+      /* fill in payload bytes */
+      for (q=0; q<btw; q++)
+      {
+        /* evtl insert TI_ESC characters */
+        if (snd_ptr[q]==TI_STX || snd_ptr[q]==TI_ESC)
+        {
+          segment[segment_size++]=TI_ESC;
+        }
+        segment[segment_size++]=snd_ptr[q];
+      }
+
+      /* fill in trailing bytes */
+      segment[segment_size++]=TI_STX;
+
+      /* write segment */
+      if ( vsi_d_write ( TR_Data.Handle, 0, (void*)segment, segment_size) != VSI_OK )
+      {
+        return DRV_INTERNAL_ERROR;
+      }
+
+      full_btw=full_btw-btw;
+      if (full_btw)
+      {
+        snd_ptr=snd_ptr+btw;
+
+        /* let the ti driver on target handle the byte-block */
+        vsi_t_sleep ( 0, 100 );
+      }
+    }
+
+    return DRV_OK;
+  }
+#endif /* _TOOLS_ */
+
+  /*
+   * To avoid reallocation and memcpy() the STX is written in front of the passed 
+   * data. This works as long as the sizeof(T_SYST_HEADER) is bigger than the header
+   * sent via the test interface.
+   */
+  if ( TR_Data.config & STX_LF_MODE )
+  {
+    btw=(*BytesToWrite) & ~PRIM_FLAG_MASK;          /* not really generic, but we need to mask here */
+                                                    /* we assume that the TITRC driver is not below */
+    if ( *BytesToWrite & PRIM_DATA_FLAG )           /* primitive data -> LF at the end */
+    {
+      *(snd_ptr+btw) = '\n';
+      btw = btw + 1;
+    }
+    else if ( *BytesToWrite & PRIM_HEADER_FLAG )    /* primitive header -> add STX in front */
+    {
+      snd_ptr--;                                    /* it is posible to add STX because the first */
+      *snd_ptr = STX;                               /* byte of TST_SMALL_HEADER/TST_BIG_HEADER in unused */
+      btw = btw + 1;
+    }
+    else                                            /* trace -> STX in front, LF at the end */
+    {
+      *(snd_ptr+btw) = '\n';
+      snd_ptr--;
+      *snd_ptr = STX;
+      btw = btw + 2;
+    }
+  }
+
+  /* Add mux STX and channel id if not already in */
+  if (TR_Data.config & TI_RAW_TRC_MODE && *snd_ptr != TI_STX )
+  {
+    if ( vsi_d_write ( TR_Data.Handle, 0, (void*)ti_mode_header, 2) != VSI_OK )
+    {
+      return DRV_INTERNAL_ERROR;
+    }
+  }
+
+  if ( vsi_d_write ( TR_Data.Handle, 0, (void*)snd_ptr, btw) != VSI_OK )
+  {
+    return DRV_INTERNAL_ERROR;
+  }
+ 
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : TR_SetSignal        |
++--------------------------------------------------------------------+
+
+  PURPOSE : enable signal for the driver
+
+*/
+LOCAL USHORT TR_SetSignal ( USHORT SignalType )
+{
+  if ( !(SignalType & ALLOWED_TR_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    TR_Data.EnabledSignalType |= SignalType;
+  
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : TR_ResetSignal      |
++--------------------------------------------------------------------+
+
+  PURPOSE : disable signal for the driver
+
+*/
+LOCAL USHORT TR_ResetSignal ( USHORT SignalType )
+{
+  if ( !(SignalType & ALLOWED_TR_SIGNALS) )
+    return DRV_INVALID_PARAMS;
+  else
+    TR_Data.EnabledSignalType &= ~SignalType;
+  
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : TR_SetConfig        |
++--------------------------------------------------------------------+
+
+  PURPOSE : set configuration for the driver
+
+*/
+LOCAL USHORT TR_SetConfig ( char *Buffer )
+{
+  if ( !strcmp ( TR_STX_LF, Buffer ) )
+  {
+    TR_Data.config = STX_LF_MODE;
+    TR_Data.rcv_state = WAIT_FOR_STX;
+    TR_Data.idle_state = WAIT_FOR_STX;
+#ifdef _TOOLS_
+    printf ("TR: STX mode enabled\n");
+#endif /* _TOOLS_ */
+    return DRV_OK;
+  }
+#ifdef _TOOLS_
+  else if ( !strcmp ( DRV_TI_MODE, Buffer ) )
+  {
+    TR_Data.config = TI_TRC_MODE;
+    TR_Data.rcv_state = WAIT_FOR_TI_ID;
+    TR_Data.idle_state = WAIT_FOR_TI_ID;
+    printf ("TR: TI mode enabled\n");
+    return DRV_OK;
+  }
+#endif /* _TOOLS_ */
+  else if ( !strcmp ( DRV_RAW_TI_MODE, Buffer ) )
+  {
+    TR_Data.config = TI_RAW_TRC_MODE;
+    TR_Data.rcv_state = WAIT_FOR_RAW_TI_S;
+    TR_Data.idle_state = WAIT_FOR_RAW_TI_S;
+#ifdef _TOOLS_
+    printf ("TR: raw TI mode enabled\n");
+#endif
+    return DRV_OK;
+  }
+  else if ( !strcmp ( DRV_DEFAULT, Buffer ) )
+  {
+    TR_Data.config = 0;
+    TR_Data.rcv_state = WAIT_FOR_IDENT;
+    TR_Data.idle_state = WAIT_FOR_IDENT;
+#ifdef _TOOLS_
+    accessNum++;
+    PrintToFile("TR: default mode selected __________________________ (%d)\n", accessNum);
+#endif /* _TOOLS_ */
+    return DRV_OK;
+  }
+  else
+    return DRV_INVALID_PARAMS;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : Callback            |
++--------------------------------------------------------------------+
+
+  PURPOSE : callback function of the driver
+
+*/
+/*lint -esym(644,infoByteAddr) suppress warning -- Symbol 'infoByteAddr' may not have been initialized */
+LOCAL void TR_Callback ( T_DRV_SIGNAL *Signal )
+{
+static T_DRV_SIGNAL TR_Signal;
+static USHORT  counter   = 0;
+static char* infoByteAddr;
+int tr_abort_discard;
+int tr_abort;
+unsigned char           c;
+ULONG          i;
+ULONG BytesToRead;
+ULONG BytesRead = 0;
+ULONG TR_WorkInd;
+ULONG Bytes = 0;
+USHORT continue_read;
+//#ifdef _TOOLS_
+static unsigned int ti_len = 0;
+static char ti_id = 0;
+static int sigtype = 0;
+static int lf_found;
+static int crlf_found;
+static U8 mux_chan_id;
+static U8 mux_chan = 0;
+static U8 mux_status = WAIT_FOR_MUX_CHAN_ID;
+static int stuffed_byte;
+//#endif
+  
+  tr_abort_discard = 0;
+  tr_abort = 0;
+  TR_Signal.SignalType = 0;
+  switch ( Signal->SignalType )
+  {
+    case DRV_SIGTYPE_READ:
+      BytesToRead = TR_EndInd - TR_WrInd;
+      TR_WorkInd = TR_WrInd;
+
+      do
+      {
+        Bytes = 0;
+        do 
+        {
+          continue_read = 0;
+          /*
+           * write counter must not overtake the read counter. If more bytes to be read
+           * than space available, then process the bytes in the buffer first and then
+           * continue to store new data in the TR_RcvBuffer.
+           */
+          if ( TR_WrInd >= (TR_RdInd&TR_MaxInd) )
+            BytesToRead = TR_EndInd - TR_WrInd;
+          else
+            BytesToRead = (TR_RdInd&TR_MaxInd) - TR_WrInd; 
+          BytesRead = BytesToRead;
+          vsi_d_read ( TR_Data.Handle, 0, (void*)&TR_RcvBuffer[TR_WrInd], &BytesRead ); 
+          Bytes += BytesRead;
+          if ( BytesRead < BytesToRead )
+          {
+            TR_WrInd += BytesRead;
+          }
+          else 
+          {
+            if ( TR_WrInd >= (TR_RdInd&TR_MaxInd) )
+              TR_WrInd = 0;
+            else
+            {
+              TR_WrInd += BytesRead;
+              continue_read = 1;
+              break;
+            }
+          }
+        } while ( BytesRead != TR_RcvBufferSize && BytesRead == BytesToRead );
+
+        if ( Bytes )
+        {
+          UBYTE cMasked;
+
+          i=0;
+
+          while (i++ < Bytes)
+          {
+            c = TR_RcvBuffer[(TR_WorkInd++) & TR_MaxInd];
+
+#ifdef _TOOLS_
+            if (TR_Data.config & TI_RAW_TRC_MODE) /* we are receiving rawly in TI mode */
+            {
+              if (!ti_esc_skipped && c==TI_ESC)
+              {
+                /* the TI driver has inserted an TI_ESC -> skip it */
+                ULONG q;
+                for (q=TR_WorkInd-1; q>TR_RdInd; q--)
+                {
+                  TR_RcvBuffer[q & TR_MaxInd]=TR_RcvBuffer[(q-1) & TR_MaxInd];
+                }
+                TR_RdInd++;
+                ti_esc_skipped=1;
+                continue;
+              }
+              ti_esc_skipped=0;
+            }
+#endif /* _TOOLS_ */
+
+            if ( tr_abort_discard == 1 )
+            {
+              TR_RdInd++;
+              continue;
+            }
+            switch (TR_Data.rcv_state)
+            {
+              case WAIT_FOR_STX:
+                if (c == STX)
+                {
+#ifdef _TOOLS_ 
+                  ti_len=0;
+#endif 
+                  TR_Data.rcv_state = WAIT_FOR_IDENT;
+                  TR_RdInd = TR_WorkInd;                   /* do not pass the STX to TIF */
+                }
+                else
+                  TR_RdInd++;
+                break;
+//#ifdef _TOOLS_
+              case WAIT_FOR_RAW_TI_S:
+                if (c==TI_STX)
+                {
+                  TR_Data.rcv_state=WAIT_FOR_RAW_TI_ID;
+                  TR_RdInd = TR_WorkInd;  /* do not read TI_STX */
+                }
+                break;
+              case WAIT_FOR_RAW_TI_ID:
+                if (c==TI_STX)
+                {
+                  // last TI_STX was end ID -> ignore this start ID
+                }
+                else if (c==TI_L23_ID)
+                {
+                  ti_len = 0;
+                  ti_id = c;
+                  TR_Data.rcv_state=WAIT_FOR_IDENT;
+                }
+                else if (c == TI_L1_ID || c == TI_RIV_ID)
+                {
+                  ti_len = 0;
+                  ti_id = c;
+
+                  if (ti_id == TI_L1_ID)
+                    sigtype = DRV_SIGTYPE_READ_L1;
+                  if (ti_id == TI_RIV_ID)
+                    sigtype = DRV_SIGTYPE_READ_RIV;
+
+                  counter = 0;
+                  TR_RdInd = TR_WorkInd;  /* do not read ti_id */
+                  crlf_found = 0;
+                  lf_found = 0;
+                  TR_Data.rcv_state=WAIT_FOR_RAW_TI_E;
+                }
+                else
+                {
+                  mux_chan_id = c;
+                  if ( mux_status == WAIT_FOR_MUX_CHAN_ID )
+                  {
+                    for ( mux_chan = 0; mux_chan < MAX_TST_CHANNEL; mux_chan++ )
+                    {
+                      if ( tst_mux_chan_struct[mux_chan].channel_id == c )
+                      {
+                        mux_status = WAIT_FOR_MUX_END_STX;
+                        tst_mux_chan_struct[mux_chan].rcv_data_ptr  = &TR_RcvBuffer[(TR_WorkInd) & TR_MaxInd];
+                        tst_mux_chan_struct[mux_chan].rcv_data_size = 0;
+                        stuffed_byte = 0;
+                        TR_RdInd = TR_WorkInd;  /* do not read id */
+                        TR_Data.rcv_state=WAIT_FOR_RAW_TI_E;
+                        break;
+                      }
+                    }
+                  }
+                }
+                break;
+#ifdef _TOOLS_
+              case WAIT_FOR_TI_ID:
+                                      /* skip TI ID byte */
+                if (c == TI_L23_ID || c == TI_L1_ID || c == TI_RIV_ID)
+                {
+                  ti_len = 0;
+                  ti_id = c;
+                  TR_Data.rcv_state = WAIT_FOR_TI_LEN_0;
+                }
+                else
+                {
+                  ti_id_not_found = 1;
+                }
+                break;
+              case WAIT_FOR_TI_LEN_0:
+                                      /* 
+                 * skip length
+                 * if length byte == 0 then the next 2 bytes are the length
+                 * (patch to handle messages longer than 255 bytes)
+                 */
+                if ( c != 0 )
+                {
+                  if (ti_id == TI_L23_ID)
+                    TR_Data.rcv_state = WAIT_FOR_IDENT;
+
+                  if (ti_id == TI_L1_ID || ti_id == TI_RIV_ID)
+                  {
+                    if (ti_id == TI_L1_ID)
+                      sigtype = DRV_SIGTYPE_READ_L1;
+                    if (ti_id == TI_RIV_ID)
+                      sigtype = DRV_SIGTYPE_READ_RIV;
+
+                    TR_Data.rcv_state = WAIT_FOR_DATA;
+                    counter = 0;
+                    TR_RdInd += 2;  /* do not read ti_id and length */
+                    crlf_found = 0;
+                    lf_found = 0;
+                  }
+                  ti_len = c & 0xff;
+                }
+                else
+                  TR_Data.rcv_state = WAIT_FOR_TI_LEN_1;
+
+                break;
+              case WAIT_FOR_TI_LEN_1:
+                ti_len = c ;
+                TR_Data.rcv_state = WAIT_FOR_TI_LEN_2;
+                break;
+              case WAIT_FOR_TI_LEN_2:
+                ti_len |= c << 8;
+                TR_Data.rcv_state = WAIT_FOR_IDENT;
+                break;
+#endif /* ifdef _TOOLS_ */
+
+              case WAIT_FOR_IDENT:
+                infoByteAddr = &TR_RcvBuffer[(TR_WorkInd - 1) & TR_MaxInd];
+                /* analyze INFO  Byte */
+                cMasked = (c &  HDR_VERSION_MASK);
+#ifdef _TOOLS_
+                if (cMasked == HDR_VALID_VERSION_0) 
+                {
+                  i--; TR_WorkInd--;
+                  printf ("TR: changed to OLD header format automatically\n");
+//                    tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_GET_STACK_TIME );
+                  break;
+                }
+                /* check for lost bytes on interface */
+                if (TR_Data.config & TI_TRC_MODE ||
+                    TR_Data.config & TI_RAW_TRC_MODE) /* we are receiving from a arm 7 TARGET */
+                { /* TR_WorkInd refs position of first size byte now */
+                  if (ti_id_not_found) 
+                  {
+                    *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */
+                  }
+                }
+#endif /* ifdef _TOOLS_ */
+                cMasked = (c &  HDR_IDENT_MASK);
+                if (((cMasked == IDENT_PS_PRIM) || (cMasked == IDENT_SYS_PRIM) ||
+                    (cMasked == IDENT_ABORT)   || (cMasked == IDENT_TRACE))
+                    &&
+                    ((c != PROT_PRIM_ID) && (c != PROT_PRIM_ID_32BIT) &&
+                     (c != SYS_PRIM_ID) && (c != TRACE_ID))
+                    )
+                {
+                  /* Hey fine, everything went OK! */
+                  TR_Data.rcv_state = WAIT_FOR_LENGTH1;
+                }
+                else
+                { /* we have to fake a length for abort trace */
+                  tst_trailer_size.part[0] = TST_HEADER_LEADING_FIELDS;
+                  tst_trailer_size.part[1] = 0; 
+                  MessageLength = tst_trailer_size.val + TST_HEADER_TRAILING_FIELDS;
+
+                  *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */
+                  counter = tst_trailer_size.val; /* don't let us read all the following bytes before let TIF tracing ABORT */
+                  TR_Data.rcv_state = WAIT_FOR_DATA;
+                  tr_abort = 1;
+                }
+                TR_RdInd = TR_WorkInd - 1; /* skip all preceeding interface sync bytes before triggering TIF */
+                break;
+              case WAIT_FOR_LENGTH1:       
+                  /* the use of the union does rely on identical byte sex! */
+#ifdef _SOLARIS_
+                  /* temporary hack */
+                  tst_trailer_size.part[1] = c;
+#else
+                  tst_trailer_size.part[0] = c;
+#endif
+                  TR_Data.rcv_state = WAIT_FOR_LENGTH2;
+                  break;
+              case WAIT_FOR_LENGTH2:       
+#ifdef _SOLARIS_
+                  /* temporary hack */
+                  tst_trailer_size.part[0] = c;
+#else
+                  tst_trailer_size.part[1] = c;
+#endif
+                  /* Bytes after size + bytes till size (inclusive) */
+                  MessageLength = tst_trailer_size.val + TST_HEADER_LEADING_FIELDS;
+#ifdef _TOOLS_
+                  /* In case of a lost character the two length information elements mismatch. */
+                  if ( (ti_len != 0) && (tst_trailer_size.val != (ti_len - 3)) )
+                  {
+                    tst_trailer_size.val = ti_len - 3;
+                  }
+                  ti_len = 0;
+                  if ((tst_trailer_size.val - TST_HEADER_TRAILING_FIELDS) > (unsigned short int)(MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER)))
+                  {
+                    *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */
+                    tst_trailer_size.val = (MAX_PRIM_PARTITION_SIZE - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER) -TST_HEADER_TRAILING_FIELDS);
+                    counter = tst_trailer_size.val; /* don't let us read all the following bytes before let TIF tracing ABORT */
+                    tr_abort = 1;
+                  }
+#else
+                  if ((tst_trailer_size.val - TST_HEADER_TRAILING_FIELDS) > (unsigned short int)(MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER)))
+                  {
+                    *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */
+                    tst_trailer_size.val = (USHORT)(MaxPrimPartSize - sizeof(T_PRIM_HEADER) - sizeof(T_S_HEADER) -TST_HEADER_TRAILING_FIELDS);
+                    counter = tst_trailer_size.val; /* don't let us read all the following bytes before let TIF tracing ABORT */
+                    tr_abort = 1;
+                  }
+#endif
+                  TR_Data.rcv_state = WAIT_FOR_DATA;
+                  counter = 0;
+                  break;
+              case WAIT_FOR_RAW_TI_E:
+                if ( mux_status == WAIT_FOR_MUX_END_STX )
+                {
+                  if ( stuffed_byte )
+                  {
+                    stuffed_byte = 0;
+                    tst_mux_chan_struct[mux_chan].rcv_data_size++;
+                  }
+                  else
+                  {
+                    if ( c != TI_STX )
+                    {
+                      if ( c == 0x10 )
+                      {
+                        stuffed_byte = 1;
+                      }
+                      tst_mux_chan_struct[mux_chan].rcv_data_size++;
+                    }
+                    else
+                    {
+                      tst_mux_callback (mux_chan,tst_mux_chan_struct[mux_chan].rcv_data_ptr, tst_mux_chan_struct[mux_chan].rcv_data_size);
+                      mux_status = WAIT_FOR_MUX_CHAN_ID;
+                      MessageLength = tst_mux_chan_struct[mux_chan].rcv_data_size;
+                      TR_Data.rcv_state = WAIT_FOR_RAW_TI_S;
+                    }
+                  }
+                }
+#ifdef _TOOLS_
+                if (c!=TI_STX)
+                {
+                  if ( counter == 0 && c == 0x0a )
+                  {
+                    lf_found = 1;
+                  }
+                  if ( lf_found && counter == 1 && c == 0x0d)
+                  {
+                    crlf_found = 1;
+                  }
+                  counter++;
+                }
+                else
+                {
+                  if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+                  {
+                    ti_len=counter;
+                    if ( crlf_found == 1 )
+                    {
+                      ti_len -= 2;
+                      TR_RdInd += 2;  /* do not read CR and LF at the beginning */
+                    }
+                    MessageLength = ti_len;
+                    TR_Signal.SignalType = sigtype;
+                    TR_Signal.DrvHandle = TR_Data.Handle;
+                    (TR_Data.Callback)( &TR_Signal );
+                  }
+                  TR_Data.rcv_state = TR_Data.idle_state;
+                }
+#endif
+                break;
+              case WAIT_FOR_DATA:       
+#ifdef _TOOLS_
+                if ( ti_len )
+                { 
+                  if ( counter == 0 && c == 0x0a )
+                  {
+                    lf_found = 1;
+                  }
+                  if ( lf_found && counter == 1 && c == 0x0d)
+                  {
+                    crlf_found = 1;
+                  }
+                  if ( ++counter >= ti_len )
+                  {
+                    if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+                    {
+                      if ( crlf_found == 1 )
+                      {
+                        ti_len -= 2;
+                        TR_RdInd += 2;  /* do not read CR and LF at the beginning */
+                      }
+                      MessageLength = ti_len;
+                      TR_Signal.SignalType = sigtype;
+                      TR_Signal.DrvHandle = TR_Data.Handle;
+                      (TR_Data.Callback)( &TR_Signal );
+                    }
+                    TR_Data.rcv_state = TR_Data.idle_state;
+                  }
+                  break;
+                }
+#endif                  
+                if (++counter >= tst_trailer_size.val) /* If all went OK up to now we have to read all remaining bytes from the buffer each for each */
+                {
+                  if (TR_Data.config & STX_LF_MODE )
+                  {
+                    TR_Data.rcv_state = WAIT_FOR_CR;
+                    break;
+                  }
+                  else
+                  {
+                    if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+                    {
+#ifdef _TOOLS_
+                      tst_message_received = 1;
+#endif
+                      TR_Signal.SignalType = DRV_SIGTYPE_READ;
+                      TR_Signal.DrvHandle = TR_Data.Handle;
+                      (TR_Data.Callback)( &TR_Signal );
+                    }
+                    TR_Data.rcv_state = TR_Data.idle_state;
+                    tst_trailer_size.val = 0;
+                    if ( tr_abort == 1 ) /* marked as bad */
+                      tr_abort_discard = 1;
+#ifdef _TOOLS_
+                    ti_id_not_found = 0;
+#endif
+                  }
+                }
+                break;
+              case WAIT_FOR_CR:
+#ifdef _TOOLS_     /* check for lost bytes on interface */
+                if (TR_Data.config & STX_LF_MODE )  /* we are receiving from a arm 9 TARGET or Windows stack configured stx */
+                {
+                  if (c != '\n') 
+                  {
+                    *infoByteAddr = (( *infoByteAddr & ~HDR_IDENT_MASK) | IDENT_ABORT); /* mark as bad */
+                  }
+                }
+#endif /* _TOOLS_ check for lost bytes on interface */
+                if ( TR_Data.EnabledSignalType & DRV_SIGTYPE_READ )
+                {
+#ifdef _TOOLS_
+                  tst_message_received = 1;
+#endif
+                  TR_Signal.SignalType = DRV_SIGTYPE_READ;
+                  TR_Signal.DrvHandle = TR_Data.Handle;
+                  (TR_Data.Callback)( &TR_Signal );
+                }
+                TR_Data.rcv_state = TR_Data.idle_state;
+                tst_trailer_size.val = 0;
+                if ( tr_abort == 1 ) /* marked as bad */
+                  tr_abort_discard = 1;
+                break;
+              default:
+                break; 
+            }
+          } /*  while (i++ < Bytes) */
+        } /* if Bytes loop */
+      } while ( continue_read == 1 );
+    break;
+    case DRV_SIGTYPE_CONNECT:
+    case DRV_SIGTYPE_DISCONNECT:
+      if ( TR_Data.EnabledSignalType & Signal->SignalType )
+      {
+        TR_Signal.SignalType = Signal->SignalType;
+        TR_Signal.DrvHandle = TR_Data.Handle;
+        (TR_Data.Callback)( &TR_Signal );
+      }
+    break;
+    default: 
+    break;
+  }
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-Frame (8415)           MODULE  : TR                  |
+| STATE   : code                       ROUTINE : TR_Init             |
++--------------------------------------------------------------------+
+
+  PURPOSE : initialize driver
+
+*/
+USHORT TR_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{                
+USHORT j;
+ULONG size = 0;
+static const T_DRV_EXPORT TR_Info =
+{
+  "TR",
+  0,
+  {
+#ifdef _TOOLS_
+    TR_Init,
+#endif
+    TR_Exit,
+    TR_Read,
+    TR_Write,
+    NULL,
+    NULL,
+    NULL,
+    TR_SetSignal,
+    TR_ResetSignal,
+    TR_SetConfig,
+    NULL,
+    TR_Callback,
+  }
+};
+
+  TR_Data.Handle = DrvHandle;
+
+  TR_Data.EnabledSignalType = 0;
+
+  TR_Data.config = 0;
+
+  TR_Data.rcv_state = WAIT_FOR_IDENT;
+
+  TR_Data.idle_state = WAIT_FOR_IDENT;
+
+  TR_Data.Callback = CallbackFunc;
+
+  *DrvInfo = &TR_Info;
+
+  /* 
+   * TR_RcvBufferSize must be a power of 2 for proper wrap-around
+   */
+#ifndef _TOOLS_
+  TR_RcvBufferSize = MaxPrimPartSize;
+#endif
+  j = 0;
+  do
+  {
+    if ( (ULONG)(1 << j) >= TR_RcvBufferSize )  /* Size must be a power of 2 */
+    {
+      size = 1 << j;
+      break;
+    }
+    else
+      j++;
+  } while ( size < 0xffff );
+
+  TR_RcvBufferSize = size;
+  TR_MaxInd = TR_RcvBufferSize - 1;
+
+  if ( os_AllocateMemory ( NO_TASK, &TR_Data.RcvBuffer, (ULONG)TR_RcvBufferSize,
+                           OS_NO_SUSPEND, ext_data_pool_handle ) != OS_OK )
+  {
+      vsi_o_assert ( NO_TASK, OS_SYST_ERR_NO_MEMORY, __FILE__, __LINE__,
+                     "No memory available in TR driver, TR_RcvBufferSize = %d",
+                     TR_RcvBufferSize );
+    return DRV_INITFAILURE;
+  }
+
+  TR_RcvBuffer = (char*)TR_Data.RcvBuffer;
+  TR_EndInd = TR_RcvBufferSize;
+  TR_WrInd = 0;
+  TR_RdInd = 0;
+  tst_trailer_size.val = 0;
+#ifdef _TOOLS_
+  ti_id_not_found = 0;
+  ti_esc_skipped = 0;
+#endif
+
+  return DRV_OK;           
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/usart.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,1843 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       usart.c
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul defines functions for actual or simulated 
+|             USART comunication between two PS-Frames.
+|             Use US_set_mode() to select actual USART under windows95 or 
+|             under windowsNT, or to select simulated USART under win95/NT
++----------------------------------------------------------------------------- 
+*/ 
+
+
+
+#ifndef __USART_C__
+#define __USART_C__
+#endif
+
+/*==== INCLUDES ===================================================*/
+
+ #include <windows.h>
+#ifndef _VXWORKS_
+  #include <stdarg.h>
+#endif
+#include <stdio.h>
+#include "typedefs.h"
+#include "usart.h"
+#include "printtofile.h"
+
+/*==== CONSTANTS ==================================================*/
+
+#define COM_ERROR		(CE_FRAME | CE_IOE | CE_OVERRUN)
+#define XON				0x11
+#define XOFF			0x13
+
+#define READER_THREAD_EXIT_CODE 4711
+#define USART_BUFFER_SIZE       0x10000   /* 65536 */
+#define FILE_MAX_CHUNK          0x0ffff
+#define FILE_SLOW_DOWN          0x01
+
+#ifdef _TOOLS_ 
+  #define USART_SEND_TIMEOUT 60000
+  #define USART_RCV_TIMEOUT 120000
+#else  /* _TOOLS_ */
+  #define USART_SEND_TIMEOUT INFINITE
+  #define USART_RCV_TIMEOUT INFINITE
+#endif /* _TOOLS_ */
+
+/*==== TYPES ======================================================*/
+typedef struct
+{
+  UBYTE  Connects;
+  UBYTE  Type;
+  USHORT CH1_numOfBytes;
+  USHORT CH2_numOfBytes;
+  UBYTE  CH1_CTS;
+  UBYTE  CH2_CTS;
+  UBYTE  CH1_data[USART_BUFFER_SIZE];
+  UBYTE  CH2_data[USART_BUFFER_SIZE];
+} T_USARTStream;
+
+/*==== EXPORT =====================================================*/
+/*==== PRIVATE ====================================================*/
+/*==== VARIABLES ==================================================*/
+
+static int       m_mode=UT_MODE_NT;
+static long int  m_send_timeout=(long int)USART_SEND_TIMEOUT;
+static long int  m_rcv_timeout =(long int)USART_RCV_TIMEOUT;
+static int first_ut_init = 1;
+static FILE*     m_file=NULL;
+
+static OVERLAPPED gWriteOverLap;
+static OVERLAPPED gReadOverLap;
+
+static  int   ReaderThreadExitRequest = FALSE;
+
+
+LOCAL   void  (*ReceiveCallback)(void) = NULL;
+static  int   initialized = FALSE;
+
+#ifdef COM_AUTOSEARCH
+static  int   P  = 0;
+#endif
+
+#ifdef DEBUG_USART
+static  int   usart_in, usart_out;
+#endif
+
+T_USARTStream *Stream;
+
+HANDLE         SemCH1_full;
+HANDLE         SemCH2_full;
+HANDLE         SemCH1_empty;
+HANDLE         SemCH2_empty;
+HANDLE         USARTMemHandle;
+HANDLE         *semRCVFull=0, *semRCVEmpty=0;
+HANDLE         *semSNDFull=0, *semSNDEmpty=0;
+HANDLE         ut_sema_handle;
+
+UBYTE          *InBuffer, *OutBuffer, *readPointer;
+USHORT         *InCounter, *OutCounter;
+UBYTE          *CTS = NULL;
+
+
+static HANDLE hComDev = INVALID_HANDLE_VALUE;
+static HANDLE hThread = INVALID_HANDLE_VALUE;
+static int mem_closed = TRUE;
+static int cls_cnt = 0;
+static int snd_cnt = 0;
+
+/*==== FUNCTIONS ==================================================*/
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USART                  |
+| STATE   : code                    ROUTINE : US_set_mode            |
++--------------------------------------------------------------------+
+
+  PURPOSE : With this function you can select the UART mode 
+                #define US_MODE_95         1
+                #define US_MODE_NT         2
+                #define US_MODE_SIM        3  
+                #define US_MODE_FILE       4
+  
+*/
+void US_set_mode(int mode)
+{
+  m_mode=mode;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USART                  |
+| STATE   : code                    ROUTINE : US_set_mode            |
++--------------------------------------------------------------------+
+
+  PURPOSE : With this function get the seleced UART mode  
+                #define US_MODE_95         1
+                #define US_MODE_NT         2
+                #define US_MODE_SIM        3  
+                #define US_MODE_FILE       4
+*/
+int US_get_mode()
+{
+  return m_mode;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USARTSIM               |
+| STATE   : code                    ROUTINE : unlockUSARTMemory      |
++--------------------------------------------------------------------+
+
+  PURPOSE : unlocks the previously locked shared memory area.
+  
+*/
+LOCAL void markRCVBufferEmpty (void)
+{
+  ReleaseSemaphore (*semRCVEmpty,
+                    1,
+                    NULL);
+}
+
+LOCAL void markSNDBufferFull (void)
+{
+  ReleaseSemaphore (*semSNDFull,
+                    1,
+                    NULL);
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USARTSIM               |
+| STATE   : code                    ROUTINE : waitForSNDBufferEmpty  |
++--------------------------------------------------------------------+
+
+  PURPOSE : waits for send buffer becoming empty
+
+  RETURNS :  0 .. send buffer is empty
+            -1 .. given up
+
+*/
+LOCAL int waitForSNDBufferEmpty (void)
+{
+  if (WaitForSingleObject (*semSNDEmpty, m_send_timeout) NEQ WAIT_OBJECT_0)
+  {
+    int err = GetLastError();
+    PrintToFile("USART: error code %d\n", err);
+    PrintToFile("USART: giving up sending with %d ms timeout :-(\n", m_send_timeout);
+    return -1; /* give up */
+  }
+  return 0;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USARTSIM               |
+| STATE   : code                    ROUTINE : createUSARTMemory      |
++--------------------------------------------------------------------+
+
+  PURPOSE : Create two pipes for byte oriented data exchange
+            between two win32 processes
+
+*/
+
+LOCAL void *createUSARTMemory (char *name, ULONG size)
+{
+  char newname[40];
+
+  /*
+   * create two Semaphores pairs to protect the send data to be
+   * overwritten before they have read by the receiver
+   */
+
+  sprintf (newname, "%s_CH1empty", name);
+  
+  SemCH1_empty = CreateSemaphore (NULL,
+                                  1,                               
+                                  1,                           
+                                  newname);
+     
+  if (SemCH1_empty EQ NULL)
+    return NULL;
+
+  sprintf (newname, "%s_CH1full", name);
+  
+  SemCH1_full = CreateSemaphore (NULL,
+                                 0,                               
+                                 1,                           
+                                 newname);
+     
+  if (SemCH1_full EQ NULL)
+    return NULL;
+
+  sprintf (newname, "%s_CH2empty", name);
+  
+  SemCH2_empty = CreateSemaphore (NULL,
+                                  1,                               
+                                  1,                           
+                                  newname);
+     
+  if (SemCH2_empty EQ NULL)
+    return NULL;
+
+  sprintf (newname, "%s_CH2full", name);
+  
+  SemCH2_full = CreateSemaphore (NULL,
+                                 0,                               
+                                 1,                           
+                                 newname);
+     
+  if (SemCH2_full EQ NULL)
+    return NULL;
+
+  /*
+   * create a shared memory area
+   */
+  sprintf (newname, "UT_Mem_%s", name);
+
+  USARTMemHandle
+      = CreateFileMapping (
+                           (HANDLE) 0xffffffff,  /* memory-mapped     */
+                            NULL,                /* no security       */
+                            PAGE_READWRITE,      /* read/write access */
+                           (DWORD) 0,
+     /* memory size     */ (DWORD) size,
+                           newname           /* name of sh. mem */
+                          ); 
+  
+  if (USARTMemHandle EQ NULL)
+    return NULL;
+ 
+  /*
+   * map the shared memory area into the address space of the process
+   * and return the startaddress.
+   */
+  
+  return MapViewOfFile (USARTMemHandle,
+                        FILE_MAP_WRITE,
+                        0,
+                        0,
+                        0);
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USARTSIM               |
+| STATE   : code                    ROUTINE : openUSARTMemory        |
++--------------------------------------------------------------------+
+
+  PURPOSE : open a shared memory area for character exchange
+            between two WIN32 processes
+
+*/
+
+LOCAL void *openUSARTMemory (char *name, ULONG size)
+{
+  char newname[30];
+
+  /*
+   * open the Semaphores
+   */
+
+  sprintf (newname, "%s_CH1empty", name);
+
+  SemCH1_empty = OpenSemaphore (SEMAPHORE_MODIFY_STATE
+                                | SYNCHRONIZE,
+                                FALSE,
+                                newname);
+     
+  if (SemCH1_empty EQ NULL)
+    return NULL;
+
+  sprintf (newname, "%s_CH1full", name);
+
+  SemCH1_full =  OpenSemaphore (SEMAPHORE_MODIFY_STATE
+                                | SYNCHRONIZE,
+                                FALSE,
+                                newname);
+     
+  if (SemCH1_full EQ NULL)
+    return NULL;
+
+  sprintf (newname, "%s_CH2empty", name);
+
+  SemCH2_empty = OpenSemaphore (SEMAPHORE_MODIFY_STATE
+                                | SYNCHRONIZE,
+                                FALSE,
+                                newname);
+     
+  if (SemCH2_empty EQ NULL)
+    return NULL;
+
+  sprintf (newname, "%s_CH2full", name);
+
+  SemCH2_full =  OpenSemaphore (SEMAPHORE_MODIFY_STATE
+                                | SYNCHRONIZE,
+                                FALSE,
+                                newname);
+     
+  if (SemCH2_full EQ NULL)
+    return NULL;
+
+  /*
+   * open the shared memory area
+   */
+  
+  sprintf (newname, "UT_Mem_%s", name);
+
+  USARTMemHandle =
+    OpenFileMapping (FILE_MAP_WRITE,
+                     FALSE,
+                     newname);  /* name of sh. mem */
+                 
+  
+  if (USARTMemHandle EQ NULL)
+    return NULL;
+ 
+  /*
+   * map the shared memory area into the address space of the process
+   * and return the startaddress.
+   */
+  
+  return MapViewOfFile (USARTMemHandle,
+                        FILE_MAP_WRITE,
+                        0,
+                        0,
+                        0);
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USART                  |
+| STATE   : code                    ROUTINE : waitForRCVBufferFull   |
++--------------------------------------------------------------------+
+
+  PURPOSE : This function waits until an incoming character
+            is signaled with the EV_RXCHAR Event 
+  
+*/
+
+LOCAL void waitForRCVBufferFull (void)
+{
+  switch (m_mode) {
+    case US_MODE_95: {
+      static COMSTAT stComStat;
+      static DWORD   dwErrors;
+      static DWORD   EvtMask = 0;
+      BOOL    validReceive = FALSE;
+
+      do
+      {
+        SetCommMask (hComDev, EV_RXCHAR) ;
+        WaitCommEvent (hComDev, &EvtMask, NULL);
+        ClearCommError (hComDev, &dwErrors, &stComStat);
+  
+        if (dwErrors & COM_ERROR)
+          PurgeComm (hComDev, PURGE_RXCLEAR|PURGE_RXABORT);
+        else
+          validReceive = TRUE;
+
+      } while (!validReceive);
+      break;
+    }
+    case US_MODE_NT: {
+      static COMSTAT stComStat;
+      static DWORD   dwErrors;
+      static DWORD   EvtMask = 0;
+      BOOL    validReceive = FALSE;
+
+      do
+      {
+        SetCommMask (hComDev, EV_RXCHAR) ;
+        WaitCommEvent (hComDev, &EvtMask, NULL);
+        ClearCommError (hComDev, &dwErrors, &stComStat);
+
+        if (dwErrors & COM_ERROR)
+          PurgeComm (hComDev, PURGE_RXCLEAR|PURGE_RXABORT);
+        else
+          validReceive = TRUE;
+
+      } while (!validReceive && !ReaderThreadExitRequest);
+      break;
+    }
+    case US_MODE_SIM: {
+      if (WaitForSingleObject (*semRCVFull, m_rcv_timeout) NEQ WAIT_OBJECT_0)
+      {
+        PrintToFile("USART: no stack connected\n");
+      }
+      break;
+    }
+    default:
+      break;
+  }
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USART                  |
+| STATE   : code                    ROUTINE : _readerThread          |
++--------------------------------------------------------------------+
+
+  PURPOSE : This function is the central signal handling function. It is
+            installed as a thread and waits for the occurance of an
+            event and then calls the installed callback function
+            of the application.
+  
+*/
+
+LOCAL void _readerThread (void)
+{
+  while (ReaderThreadExitRequest == FALSE)
+  {
+    waitForRCVBufferFull ();
+    ReceiveCallback ();
+  } 
+  ReaderThreadExitRequest = FALSE;
+  ExitThread(READER_THREAD_EXIT_CODE);
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USART                  |
+| STATE   : code                    ROUTINE : convertBaudrate        |
++--------------------------------------------------------------------+
+
+  PURPOSE : This function convert the constants for the baudrates in
+            usart.h into the equvalent constants for WIN32 comm.
+        
+*/
+LOCAL DWORD convertBaudrate (DWORD br)
+{   
+  switch (br)
+  {
+    case US_BAUD_256000:
+      return CBR_256000;
+
+    case US_BAUD_128000:
+      return CBR_128000;
+
+    case US_BAUD_115200:
+      return CBR_115200;
+
+    case US_BAUD_57600:
+      return CBR_57600;
+
+    case US_BAUD_38400:
+      return CBR_38400;
+    
+    case US_BAUD_19200:
+      return CBR_19200;
+
+    case US_BAUD_14400:
+      return CBR_14400;
+
+    case US_BAUD_9600:
+      return CBR_9600;
+
+    case US_BAUD_4800:
+      return CBR_4800;
+
+    case US_BAUD_2400:
+      return CBR_2400;
+
+    case US_BAUD_1200:
+      return CBR_1200;
+
+    case US_BAUD_600:
+      return CBR_600;
+
+    case US_BAUD_300:
+      return CBR_300;
+
+    default:
+      /* no CBR_xxx constant found -> return value itsself */
+      return br;
+  }
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)           MODULE  : USART                  |
+| STATE   : code                    ROUTINE : sioInit                |
++--------------------------------------------------------------------+
+
+  PURPOSE : This function opens the given comm port and initiializes
+            the DCB with baudrate and flowcontrol parameters.
+        
+*/
+
+LOCAL BOOL sioInit (int  portNr,
+                    unsigned int  baudrate,
+                    unsigned int  bufSize,
+                    char flowCtrl)
+{
+  char         szPort[10];
+  DCB          stDCB;
+  COMMTIMEOUTS stTimeout ;
+  DWORD        dwErrorFlags;
+  COMSTAT      stComStat;
+
+  sprintf (szPort, "\\\\.\\COM%d", portNr) ;
+
+  // ------------------------------------
+  // open the communication device
+  // ------------------------------------
+  if (m_mode==UT_MODE_NT) {
+    hComDev = CreateFile
+            ( 
+              szPort,
+              GENERIC_READ | GENERIC_WRITE,
+              0,                       /* exclusive access  */
+              NULL,                    /* no security attrs */
+              OPEN_EXISTING,
+              FILE_FLAG_OVERLAPPED,
+              NULL
+            );
+  } else {
+    hComDev = CreateFile
+            ( 
+              szPort,
+              GENERIC_READ | GENERIC_WRITE,
+              0,                       // exclusive access
+              NULL,                    // no security attrs
+              OPEN_EXISTING,
+              0,
+              NULL
+            );
+  }
+
+  if (hComDev EQ INVALID_HANDLE_VALUE)
+    return FALSE;   // device not available
+
+  if (m_mode==UT_MODE_NT) {
+    gReadOverLap.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
+    if (!gReadOverLap.hEvent)
+	    return ( FALSE );
+
+    gReadOverLap.Offset = 0;
+    gReadOverLap.OffsetHigh = 0;
+
+    gWriteOverLap.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
+    if (!(gWriteOverLap.hEvent))
+	    return ( FALSE );
+
+    gWriteOverLap.Offset = 0;
+    gWriteOverLap.OffsetHigh = 0;
+  }
+
+  // ------------------------------------
+  // get any early notifications
+  // ------------------------------------
+  SetCommMask (hComDev, EV_RXCHAR);
+
+  // ------------------------------------
+  // setup device buffers
+  // ------------------------------------
+  SetupComm (hComDev,
+             bufSize,
+             bufSize
+            );
+
+  // ------------------------------------
+  // purge any information in the buffer
+  // ------------------------------------
+  PurgeComm (hComDev,
+             PURGE_TXABORT | PURGE_RXABORT |
+             PURGE_TXCLEAR | PURGE_RXCLEAR
+            );
+
+  // ------------------------------------
+  // setup up and enable communication
+  // device. If not possible close
+  // communication and abort function.
+  // ------------------------------------
+  if (!GetCommState (hComDev, &stDCB))
+  {
+    SetCommMask (hComDev, 0);
+    CloseHandle (hComDev);
+    return FALSE;
+  }
+
+  stDCB.DCBlength = sizeof (stDCB);  // sizeof(DCB) 
+
+  switch (flowCtrl)
+  {
+    case 'N':
+      stDCB.fOutxCtsFlow = FALSE;
+      stDCB.fOutxDsrFlow = FALSE;
+      stDCB.fDtrControl = DTR_CONTROL_DISABLE;
+      stDCB.fRtsControl = RTS_CONTROL_DISABLE;
+      break;
+    case 'D':
+      stDCB.fOutxCtsFlow = FALSE;
+      stDCB.fOutxDsrFlow = TRUE;
+      stDCB.fDtrControl = DTR_CONTROL_HANDSHAKE;
+      stDCB.fRtsControl = RTS_CONTROL_DISABLE;
+      stDCB.XonLim  = 0;
+      stDCB.XoffLim = 50;
+      break;
+    case 'R':
+      stDCB.fOutxCtsFlow = TRUE;
+      stDCB.fOutxDsrFlow = FALSE;
+      stDCB.fDtrControl = DTR_CONTROL_DISABLE;
+      stDCB.fRtsControl = RTS_CONTROL_HANDSHAKE;
+      stDCB.XonLim  = 0;
+      stDCB.XoffLim = 50;
+      break;
+    case 'P':
+      stDCB.fOutxCtsFlow = FALSE;
+      stDCB.fOutxDsrFlow = FALSE;
+      stDCB.fDtrControl = DTR_CONTROL_ENABLE;
+      stDCB.fRtsControl = RTS_CONTROL_DISABLE;
+      break;
+    case 'V':
+      if (m_mode==US_MODE_NT) {
+        stDCB.fOutxCtsFlow = FALSE;
+        stDCB.fOutxDsrFlow = FALSE;
+        stDCB.fDtrControl = DTR_CONTROL_ENABLE;
+        stDCB.fRtsControl = RTS_CONTROL_ENABLE;
+        break;
+      }
+      /*lint -fallthrough*/
+      /* go on if not US_MODE_NT */
+    default:
+      return FALSE;
+  }
+  fprintf (stdout,"flow control: %c ...", flowCtrl);
+
+  stDCB.BaudRate          = baudrate;  // current baud rate 
+  stDCB.fBinary           = TRUE;      // binary mode, no EOF check 
+  stDCB.fParity           = FALSE;     // enable parity checking 
+  stDCB.fDsrSensitivity   = FALSE;     // DSR sensitivity 
+  stDCB.fTXContinueOnXoff = FALSE;     // XOFF continues Tx 
+  stDCB.fOutX             = FALSE;     // XON/XOFF out flow control 
+  stDCB.fInX              = FALSE;     // XON/XOFF in flow control 
+  stDCB.fErrorChar        = FALSE;     // enable error replacement 
+  stDCB.fNull             = FALSE;     // enable null stripping 
+  stDCB.fAbortOnError     = FALSE;     // abort reads/writes on error 
+  stDCB.ByteSize          = 8;         // number of bits/byte, 4-8 
+  stDCB.Parity            = NOPARITY;  // 0-4=no,odd,even,mark,space 
+  stDCB.StopBits          = ONESTOPBIT;// 0,1,2 = 1, 1.5, 2 
+  stDCB.XonChar           = 0;         // Tx and Rx XON character 
+  stDCB.XoffChar          = 0;         // Tx and Rx XOFF character 
+  stDCB.ErrorChar         = 0;         // error replacement character 
+  stDCB.EofChar           = 0;         // end of input character 
+  stDCB.EvtChar           = 0;         // received event character 
+
+  if (!SetCommState (hComDev, &stDCB))
+  {
+    SetCommMask (hComDev, 0);
+    CloseHandle (hComDev);
+    return FALSE;
+  }
+
+  if (!GetCommTimeouts (hComDev, &stTimeout))
+    return FALSE;
+
+  stTimeout.WriteTotalTimeoutConstant   = 0xffff;
+  stTimeout.WriteTotalTimeoutMultiplier = 0xffff;
+  stTimeout.ReadTotalTimeoutConstant    = 0xffff;
+  stTimeout.ReadIntervalTimeout         = 0;
+  stTimeout.ReadTotalTimeoutMultiplier  = 0xffff;
+
+  if (!SetCommTimeouts (hComDev, &stTimeout))
+    return FALSE;
+
+  PurgeComm (hComDev, PURGE_RXCLEAR
+                     |PURGE_TXCLEAR
+                     |PURGE_TXABORT
+                     |PURGE_RXABORT);
+
+  ClearCommError (hComDev, &dwErrorFlags, &stComStat);
+
+  return TRUE;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : sioRead                    |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+LOCAL BOOL sioRead (BYTE  *bpRXBuffer, // RX Buffer
+                    DWORD *pdwLength)  // IN:  Bytes to read
+{
+  DWORD   dwBytesToRead = *pdwLength ;
+  DWORD   dwErrorFlags;
+  COMSTAT stComStat;
+
+  if (hComDev == INVALID_HANDLE_VALUE
+    OR *pdwLength == 0) 
+    return FALSE;  // device not available
+
+  if (m_mode==US_MODE_NT) {
+    if (!ReadFile (hComDev,
+                 bpRXBuffer,
+                 dwBytesToRead,
+                 pdwLength,
+                 &gReadOverLap))
+    {
+      // if there was a problem
+		  if (GetLastError() == ERROR_IO_PENDING)
+   	  {
+	  	  /* asynchronous i/o is still in progress         */
+		
+   			/* do something else for a while                 */
+	   		/* check on the results of the asynchronous read */
+	    	if (GetOverlappedResult(gReadOverLap.hEvent, &gReadOverLap, 
+	    		pdwLength, TRUE))
+			    return TRUE;
+      }
+
+      ClearCommError(hComDev, &dwErrorFlags, &stComStat);
+      return FALSE;
+    } else {
+      ClearCommError(hComDev, &dwErrorFlags, &stComStat);
+    }
+  } else {
+    if (!ReadFile (hComDev,
+                 bpRXBuffer,
+                 dwBytesToRead,
+                 pdwLength,
+                 NULL))
+    {
+      // if there was a problem
+      ClearCommError(hComDev, &dwErrorFlags, &stComStat);
+      return FALSE;
+    }
+  }
+#ifdef DEBUG_USART
+  {
+    char traceBuf[255];
+    unsigned int  i;
+
+    traceBuf[0] = '\0';
+
+    if (bpRXBuffer[0] EQ 0xff)
+    {
+      Sleep(1);
+    }
+
+    for (i=0; i<*pdwLength; i++)
+    {
+      if (!isprint (bpRXBuffer[i]))
+      {
+        sprintf (traceBuf+strlen(traceBuf),
+                 "[%02x]%c",
+                 (USHORT) bpRXBuffer[i],
+                 ((bpRXBuffer[i] EQ '\n') ? '\n' : ' ')
+                 );
+      }
+      else
+        sprintf (traceBuf+strlen(traceBuf),
+                 "%c",
+                 bpRXBuffer[i]);
+      if (strlen (traceBuf) > 200)
+      {
+        write (usart_in, traceBuf, strlen (traceBuf));
+        traceBuf[0] = '\0';
+      }
+    }
+    /*
+     * write the string to the tracefile
+     */
+    write (usart_in, traceBuf, strlen (traceBuf));
+  }
+#endif
+  return TRUE;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : sioWrite                   |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+LOCAL BOOL sioWrite (BYTE  *bpTXBuffer, // TX   Buffer
+                     DWORD *pdwLength)  // IN:  Bytes to read
+{
+  DWORD   dwBytesToSend = *pdwLength, toSend, realySend;
+  int     ret;
+  DWORD   dwErrorFlags;
+  COMSTAT stComStat;
+  DWORD   dwNumberOfBytesTransferred;   /* Windows 95:                                       */
+                                        /* The number of transferred bytes returned by the   */
+                                        /* GetOverlappedResult function is always zero, also */
+                                        /* if there are bytes received by the communication  */ 
+                                        /* partner via the serial line.                      */
+
+  if (hComDev EQ INVALID_HANDLE_VALUE
+    OR !bpTXBuffer
+    OR *pdwLength ==0)
+     return FALSE; // device not available
+
+  realySend = 0;
+  toSend    = dwBytesToSend;
+
+  while (toSend > 0)
+  {
+    if (m_mode==US_MODE_NT) {
+    	if (toSend > 20) {
+	    	ret = WriteFile (hComDev,
+                       bpTXBuffer+realySend,
+                       20,
+                       pdwLength,
+                       &gWriteOverLap);
+		    dwNumberOfBytesTransferred = 20;     
+  	  } else {
+  		  ret = WriteFile (hComDev,
+                       bpTXBuffer+realySend,
+                       toSend,
+                       pdwLength,
+                       &gWriteOverLap);
+		    dwNumberOfBytesTransferred = toSend;
+	    }
+    	/* if there was a problem, or the async. operation's still pending ... */
+	    if (!ret)
+  	  {
+  	  	/* deal with the error code */
+	  	  if (GetLastError() == ERROR_IO_PENDING)
+  	  	{
+	  	  	/* asynchronous i/o is still in progress         */
+		
+  		  	/* do something else for a while                 */
+	  		  /* check on the results of the asynchronous read */
+  		  	while (!GetOverlappedResult(gWriteOverLap.hEvent, &gWriteOverLap, pdwLength, TRUE))
+	    		{
+			    	if(GetLastError() == ERROR_IO_INCOMPLETE) {
+    					continue;
+            } else {
+				    	break ;
+            }
+      		}
+		    } else {
+			    ClearCommError(hComDev, &dwErrorFlags, &stComStat);
+    			return FALSE;
+		    }
+      }
+    } else {
+      if (toSend > 20) {
+        ret = WriteFile (hComDev,
+                       bpTXBuffer+realySend,
+                       20,
+                       pdwLength,
+                       NULL);
+        dwNumberOfBytesTransferred = 20; /* US_MODE_NT */
+      } else {
+        ret = WriteFile (hComDev,
+                       bpTXBuffer+realySend,
+                       toSend,
+                       pdwLength,
+                       NULL);
+  	    dwNumberOfBytesTransferred = toSend; /* US_MODE_NT */
+      }
+    }
+
+#ifdef DEBUG_USART
+    {
+      char traceBuf[255];
+      unsigned int  i;
+
+      traceBuf[0] = '\0';
+
+      for (i=0; i<*pdwLength; i++)
+      {
+        if (!isprint (bpTXBuffer[realySend+i]))
+        {
+          sprintf (traceBuf+strlen(traceBuf),
+                   "[%02x]%c",
+                   (USHORT) bpTXBuffer[realySend+i],
+                   ((bpTXBuffer[realySend+i] EQ '\n') ? '\n': ' ')
+                   );
+        }
+        else
+          sprintf (traceBuf+strlen(traceBuf),
+                   "%c",
+                   bpTXBuffer[realySend+i]);
+        if (strlen (traceBuf) > 200)
+        {
+          write (usart_out, traceBuf, strlen (traceBuf));
+          traceBuf[0] = '\0';
+        }
+      }
+      /*
+       * write the string to the tracefile
+       */
+      write (usart_out, traceBuf, strlen (traceBuf));
+    }
+#endif
+
+    switch (m_mode) {
+      case US_MODE_NT:
+       	realySend += dwNumberOfBytesTransferred;
+      	toSend    -= dwNumberOfBytesTransferred;
+        break;
+      case US_MODE_95:
+        realySend += *pdwLength;
+        toSend    -= *pdwLength;
+        break;
+      default:
+        break;
+    }
+  }
+
+  *pdwLength = dwBytesToSend;
+
+  return TRUE;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_Init                    |
++--------------------------------------------------------------------+
+
+  PURPOSE : initializes the USART driver
+
+  RETURNS : 0 ... initialization succeeded
+           -1 ... error
+
+*/
+
+
+int UT_Init (unsigned int baudRate, int fifoSize, char flow_ctrl, void (func(void)), const char* fname )
+{
+  if (initialized == TRUE)
+  {
+		return 0;
+  }
+
+  switch (m_mode) 
+  {
+    case US_MODE_FILE:
+      if (!fname || !strlen(fname) || (m_file=fopen(fname,"rb"))==NULL)
+      {
+        fprintf (stdout, "USART: failed to open %s :-(\n",fname);
+        return -1;
+      }
+      fprintf (stdout, "USART: \"%s\" opened\n",fname);
+      break;
+    case US_MODE_95:
+    case US_MODE_NT: {
+      BOOL   ret;
+      DWORD  dwThreadID;
+#ifdef COM_AUTOSEARCH
+      int    from, to;
+      int portNr;
+#else
+      EXTERN int extPort;
+#endif
+
+      ReceiveCallback = func;
+
+#ifdef COM_AUTOSEARCH
+      if (P NEQ 0) {
+        from = to = P;
+      } else {
+        from = 1;
+        to = 4;
+      }
+
+      /*
+       * try COMn: to COMm: where n is from and m is to
+      */
+      for (portNr = from; portNr <= to; portNr++)
+      {
+        fprintf (stdout,"USART: Trying COM%d ... ", portNr);
+
+        if ((ret = sioInit (portNr,
+                        convertBaudrate (baudRate),
+                        10000 /*fifoSize*/,
+                        flow_ctrl)) EQ FALSE) {
+          fprintf (stdout, "fail\n");
+        } else {
+          fprintf (stdout, "success!\n");
+          break;
+        }
+      }
+
+#else
+      fprintf (stdout, "USART: Trying COM%d ... ", extPort);
+
+      if ((ret = sioInit (extPort,
+                        convertBaudrate (baudRate),
+                        10000 /*fifoSize*/,
+                        flow_ctrl)) EQ FALSE) {
+        fprintf (stdout, "fail\n");
+      }
+#endif
+
+      if (ret)
+      {
+        fprintf (stdout, "success!\n");
+
+        if (ReceiveCallback NEQ NULL)
+        {
+          hThread = CreateThread ((LPSECURITY_ATTRIBUTES) NULL,
+                              0,
+                              (LPTHREAD_START_ROUTINE) _readerThread,
+                              (LPVOID) NULL,
+                               0,
+                              &dwThreadID
+                             );
+        }
+        initialized = TRUE;
+      }
+      else {
+        fprintf (stdout, "USART: COM-port not free or baudrate not supported !\n");
+        return -1;
+      }
+      break;  
+    }
+
+    case US_MODE_SIM: {
+      int    i;
+
+      if ( first_ut_init )
+      {
+        if ( (ut_sema_handle = OpenSemaphore (SEMAPHORE_MODIFY_STATE | SYNCHRONIZE, FALSE, "UT_SIM_SEMA")) == NULL )
+        {
+          ut_sema_handle = CreateSemaphore (NULL, 1, 1, "UT_SIM_SEMA");
+        }
+        first_ut_init = 0;
+      }
+
+      WaitForSingleObject (ut_sema_handle, INFINITE);
+
+      if ((Stream = (T_USARTStream *) openUSARTMemory
+                                      (
+                                        (char*)"GSM",
+                                        sizeof (T_USARTStream)
+                                      )) EQ NULL)
+      {
+        if ((Stream = (T_USARTStream *) createUSARTMemory
+                                      (
+                                        (char*)"GSM",
+                                        sizeof (T_USARTStream)
+                                      )) EQ NULL)
+        {
+          PrintToFile ("USART: simulation could not create a shared memory area\n");
+          return -1;
+        }
+        PrintToFile ("USART: shared memory area created\n");
+  
+        Stream->CH1_numOfBytes = 0;
+        Stream->CH2_numOfBytes = 0;
+
+        Stream->CH1_CTS = 0;
+        Stream->CH2_CTS = 0;
+  
+        for (i=0; i<USART_BUFFER_SIZE; i++)
+        {
+          Stream->CH1_data[i] = 0;
+          Stream->CH2_data[i] = 0;
+        }
+
+        Stream->Connects = 0;  /* init connection counter (!! CURRENTLY NOT USED !!) */
+        Stream->Type=1;        /* signaling new type */ 
+      }
+      else
+      {
+        PrintToFile ("USART: shared memory area opened\n");
+      }
+
+      /* set pointers to semaphores and data buffers */
+#ifdef _TOOLS_
+      if (Stream->Type==0) // shared mem created by old stack
+      {
+        PrintToFile ("USART: connecting to old stack !\n");
+
+        Stream->CH1_CTS = 1; // (baudRate NEQ -1); removed because baudrate never negative
+
+        InBuffer      = Stream->CH1_data;
+        OutBuffer     = Stream->CH2_data;
+        InCounter     = &Stream->CH1_numOfBytes;
+        OutCounter    = &Stream->CH2_numOfBytes;
+        semRCVFull    = &SemCH1_full;
+        semRCVEmpty   = &SemCH1_empty;
+        semSNDFull    = &SemCH2_full;
+        semSNDEmpty   = &SemCH2_empty;
+        CTS           = &Stream->CH2_CTS;
+      }
+      else // shared mem created by us or new stack
+      {
+        Stream->CH2_CTS  = 1;  // (baudRate NEQ -1); removed because baudrate never negative 
+
+        InBuffer      = Stream->CH2_data;
+        OutBuffer     = Stream->CH1_data;
+        InCounter     = &Stream->CH2_numOfBytes;
+        OutCounter    = &Stream->CH1_numOfBytes;
+        semRCVFull    = &SemCH2_full;
+        semRCVEmpty   = &SemCH2_empty;
+        semSNDFull    = &SemCH1_full;
+        semSNDEmpty   = &SemCH1_empty;
+        CTS           = &Stream->CH1_CTS;
+      }
+#else  /* _TOOLS_ */
+      Stream->CH1_CTS = 1;  // (baudRate NEQ -1); removed because baudrate never negative 
+
+      InBuffer      = Stream->CH1_data;
+      OutBuffer     = Stream->CH2_data;
+      InCounter     = &Stream->CH1_numOfBytes;
+      OutCounter    = &Stream->CH2_numOfBytes;
+      semRCVFull    = &SemCH1_full;
+      semRCVEmpty   = &SemCH1_empty;
+      semSNDFull    = &SemCH2_full;
+      semSNDEmpty   = &SemCH2_empty;
+      CTS           = &Stream->CH2_CTS;
+#endif /* _TOOLS_ */
+
+      readPointer = InBuffer;
+
+      ReceiveCallback = func;
+
+      Stream->Connects++;      /* mark connection (!! CURRENTLY NOT USED !!) */
+      }
+        
+      ReleaseSemaphore (ut_sema_handle, 1, NULL);
+
+      break;
+    default:
+      break;
+  }
+  initialized = TRUE;
+  mem_closed = FALSE;
+
+#ifdef DEBUG_USART
+  /*
+   * Open protocol file and initialize
+   */
+
+  usart_in  = open ("USART.IN", O_WRONLY| O_TEXT| O_TRUNC| O_CREAT, 0666);
+  usart_out = open ("USART.OUT", O_WRONLY| O_TEXT| O_TRUNC| O_CREAT, 0666);
+#endif
+
+  return 0;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USARTSIM                   |
+| STATE   : code                ROUTINE : UT_Close                   |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+GLOBAL BOOL UT_Close(void)
+{
+
+  if (initialized == FALSE)
+		return FALSE;
+
+  switch (m_mode) {
+    case US_MODE_FILE:
+      if (m_file)
+      {
+        fclose(m_file);
+        m_file=NULL;
+      }
+      break;
+    case US_MODE_95:
+    case US_MODE_NT: {
+    	DWORD ExitCode;
+    
+      if (ReceiveCallback != NULL) {
+    	  /* Initialize stop _readerThread */
+    	  ReaderThreadExitRequest = TRUE;
+    	  while (ReaderThreadExitRequest == TRUE)
+		      SetCommMask (hComDev, 0);
+      }
+
+    	/* Close Communication port. */
+    	PurgeComm (hComDev,
+			   PURGE_TXABORT | PURGE_RXABORT |
+			   PURGE_TXCLEAR | PURGE_RXCLEAR ) ;
+      if (m_mode==UT_MODE_NT) {
+      	CloseHandle (gReadOverLap.hEvent);
+    	  gReadOverLap.hEvent = INVALID_HANDLE_VALUE ;
+    	  CloseHandle (gWriteOverLap.hEvent);
+    	  gWriteOverLap.hEvent = INVALID_HANDLE_VALUE ;
+      }
+    	CloseHandle (hComDev);
+    	hComDev = INVALID_HANDLE_VALUE;
+	
+      if (ReceiveCallback != NULL) {
+      	/* Stop _readerThread */
+      	do {
+		      GetExitCodeThread(hThread, (LPDWORD) &ExitCode);
+    	  }
+    	  while (ExitCode == STILL_ACTIVE);
+      	CloseHandle (hThread);
+      	hThread = INVALID_HANDLE_VALUE;
+      }
+    
+      break;
+    }
+    case US_MODE_SIM: {
+      PrintToFile("USART: shared memory closed (%d)\n",cls_cnt);
+      mem_closed = TRUE;
+     /* mark disconnection  */
+      Stream->Connects=(Stream->Connects>1) ? 1 : 0; /* (!! CURRENTLY NOT USED !!) */
+
+#ifdef _TOOLS_
+      if (Stream->Type==0) /* shared mem created by old stack */
+      {
+        fprintf (stdout, "USART: disconnecting from old stack !\n");
+        Stream->CH1_CTS = 0; 
+      }
+      else /* shared mem created by us or new stack */
+      {
+        Stream->CH2_CTS = 0; 
+      }
+#else /* _TOOLS_ */
+      Stream->CH1_CTS = 0; 
+#endif /* _TOOLS_ */
+
+      CTS = NULL;
+      /* close all handles */
+      UnmapViewOfFile((void*)Stream);
+      CloseHandle(USARTMemHandle);
+      CloseHandle(SemCH1_full);
+      CloseHandle(SemCH2_full);
+      CloseHandle(SemCH1_empty);
+      CloseHandle(SemCH2_empty);
+      cls_cnt++;
+      break;
+    default:
+      break;
+    }
+  }
+
+#ifdef DEBUG_USART
+ 	/* close tracefiles for usart-in and out */
+ 	close(usart_in);
+ 	close(usart_out);
+#endif
+
+	/* Deinitialize */
+	ReceiveCallback = NULL;
+  initialized     = FALSE;
+
+	return TRUE;
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_InitBlk                 |
++--------------------------------------------------------------------+
+
+  PURPOSE : Initialize the USART for reading blocks
+
+*/
+
+int UT_InitBlk ( unsigned int baudRate, int fifoSize, char flow_ctrl, void *hP)
+{
+  return UT_Init (baudRate, fifoSize, flow_ctrl, NULL, NULL);
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_IsChar                  |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+GLOBAL int UT_IsChar (void)
+{
+  int ret;
+
+  switch (m_mode) {
+    case US_MODE_FILE:
+      Sleep(FILE_SLOW_DOWN);
+      while (feof(m_file))
+      {
+        Sleep(1000);
+        fseek(m_file,0,SEEK_CUR);
+      }
+      ret=1;
+      break;
+    case US_MODE_95:
+    case US_MODE_NT: {
+      static COMSTAT stComStat;
+      static DWORD   dwErrors;
+
+      if (!initialized)
+        return FALSE;
+
+      waitForRCVBufferFull ();
+
+      ClearCommError (hComDev, &dwErrors, &stComStat);
+
+      ret= (stComStat.cbInQue > 0);
+      break;
+    }
+    
+    case US_MODE_SIM: {
+      waitForRCVBufferFull ();
+      ret = (*InCounter NEQ 0);
+
+      if (ret EQ 0)
+        readPointer = InBuffer;
+      break;
+    default: 
+      ret = 0;
+      break;
+    }
+  }
+ 
+  return ret;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_ReadChar                |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+GLOBAL BYTE UT_ReadChar (void)
+{
+  BYTE ret=0;
+
+  switch (m_mode) {
+    case US_MODE_95:
+    case US_MODE_NT: {
+
+      BYTE  buffer[1];
+      ULONG bytesRead;
+
+      if (!initialized)
+        return 0;
+
+      sioRead (buffer, &bytesRead);
+
+      if (!bytesRead)
+        buffer[0] = 0xff;
+
+      ret=buffer[0];
+      break;
+    }
+
+    case US_MODE_SIM: {
+      if (*InCounter NEQ 0)
+      {
+        ret = *readPointer++;
+
+#ifdef DEBUG_USART
+        {
+          BYTE buf[20];
+          sprintf (buf, "R[1 of %d]: ", *InCounter);
+          write (usart_in,
+            buf,
+            strlen (buf));
+          if (isprint (ret))
+          {
+            sprintf (buf, "%c\n", ret);
+          }
+          else
+          {
+            sprintf (buf, "(%02X)\n", ret);
+          }
+          write (usart_in,
+            buf,
+            strlen (buf));
+		    }
+#endif
+
+        (*InCounter)--;
+
+        if (*InCounter EQ 0)
+        {
+          readPointer = InBuffer;
+          markRCVBufferEmpty ();
+        }
+      }
+      break;
+    default:
+      break;
+    }
+  }
+  return ret;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_ReadNChars              |
++--------------------------------------------------------------------+
+
+  PURPOSE : Called from the HISR - Reads a block of characters
+            Parameters : buffer for holding received characters,
+                         max. size of buffer
+            Returns the number of characters read
+
+*/
+
+GLOBAL ULONG UT_ReadNChars (int usart_id, BYTE *buffer, ULONG bufferSize)
+{
+  ULONG   bytes;
+
+  switch (m_mode) {
+    case US_MODE_FILE:
+      if (bufferSize>FILE_MAX_CHUNK)
+      {
+        bufferSize=FILE_MAX_CHUNK;
+      }
+      bytes=fread(buffer,1,bufferSize,m_file);
+      break;
+    case US_MODE_95:
+    case US_MODE_NT: {
+
+      COMSTAT stComStat;
+      DWORD   dwErrors;
+
+      if (!initialized)
+        return 0L;
+
+      ClearCommError (hComDev, &dwErrors, &stComStat);
+  
+      bytes = MINIMUM (stComStat.cbInQue, bufferSize);
+
+      if (bytes EQ 0)
+        return 0L;
+
+      sioRead (buffer, &bytes);
+      break;
+    }
+
+    case US_MODE_SIM: {
+      if ((bytes = MINIMUM (*InCounter, bufferSize)) NEQ 0)
+      {
+#ifdef DEBUG_USART
+        unsigned int i;
+        char buf[50];
+#endif
+    
+        memcpy (buffer, readPointer, bytes);
+
+#ifdef DEBUG_USART
+        sprintf (buf, "R[%d of %d]: ", bytes, *InCounter);
+        write (usart_in, buf, strlen (buf));
+
+        for (i=0; i<bytes; i++)
+        {
+          if (isprint (buffer[i]))
+            sprintf (buf, "%c", buffer[i]);
+          else
+            sprintf (buf, "(%02X)", buffer[i]);
+          write (usart_in,
+             buf,
+             strlen (buf));
+        }
+        write (usart_in, "\n", 1);
+#endif
+
+        (*InCounter) -= (USHORT)bytes;
+
+        if (*InCounter EQ 0)
+        {
+          readPointer = InBuffer;
+          markRCVBufferEmpty ();
+        }
+        else {
+          readPointer += bytes;
+        }
+      }
+      else {
+        markRCVBufferEmpty ();
+      }
+      break;
+    default: bytes = 0;
+      break;
+    }
+  }
+
+  return bytes;
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_WriteChar               |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+GLOBAL void UT_WriteChar (int usart_id, char ch)
+{
+  switch (m_mode) {
+    case US_MODE_95:
+    case US_MODE_NT: {
+      BYTE  buffer[1];
+      ULONG bytesWritten = 1;
+
+      if (!initialized)
+        return;
+
+      buffer[0] = (BYTE)ch;
+
+      sioWrite (buffer, &bytesWritten);
+      break;
+    }
+
+    case US_MODE_SIM: {
+#ifdef DEBUG_USART
+      char buf[50];
+#endif
+
+      if ( CTS == NULL || !*CTS)  /* no testtools connected */
+      {
+        return;
+      }
+
+      if (waitForSNDBufferEmpty () != 0)
+      {
+        markSNDBufferFull ();
+        return;   /* we gave up sending to avoid dead lock */
+      }
+      
+#ifdef DEBUG_USART
+      sprintf (buf, "W[1]: %02X", ch);
+      write (usart_out, buf, strlen (buf));
+#endif
+
+      *OutBuffer  = (UBYTE)ch;
+      *OutCounter = 1;
+   
+      markSNDBufferFull ();
+      break;
+    default:
+      break;
+    }
+  }
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_WriteString             |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+GLOBAL void UT_WriteString (int usart_id, char *s)
+{
+  switch (m_mode) {
+    case US_MODE_95:
+    case US_MODE_NT: {
+      ULONG bytesWritten = strlen (s);
+
+      if (!initialized)
+        return;
+
+      sioWrite ((BYTE *) s, &bytesWritten);
+      break;
+    }
+
+    case US_MODE_SIM: {
+      unsigned int numOfChars;
+#ifdef DEBUG_USART
+      int i;
+      char buf[50];
+#endif
+
+      if ( CTS == NULL || !*CTS)  /* no testtools connected */
+      {
+        return;
+      }
+
+      if (waitForSNDBufferEmpty () != 0)
+      {
+        markSNDBufferFull ();
+        return;   /* we gave up sending to avoid dead lock */
+      }
+
+      numOfChars = strlen (s);
+
+      memcpy (OutBuffer, s, numOfChars);
+      *OutCounter = numOfChars;
+
+#ifdef DEBUG_USART
+      sprintf (buf, "W[%d]:", numOfChars);
+      write (usart_out, buf, strlen (buf));
+
+      for (i=0; i<numOfChars; i++)
+      {
+        if (isprint (OutBuffer[i]))
+          sprintf (buf, "%c", OutBuffer[i]);
+        else
+          sprintf (buf, "(%02X)", OutBuffer[i]);
+        write (usart_out,
+               buf,
+               strlen (buf));
+
+      }
+      write (usart_out,"\n", 1);
+#endif
+
+      markSNDBufferFull ();
+      break;
+    default:
+      break;
+    }
+  }
+}
+
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_WriteNChars             |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+GLOBAL void UT_WriteNChars (int usart_id, BYTE *s, unsigned int n)
+{
+  switch (m_mode) {
+    case US_MODE_95:
+    case US_MODE_NT: {
+      ULONG bytesWritten = (ULONG) n;
+
+      if (!initialized)
+        return;
+
+      if (!sioWrite ((BYTE *) s, &bytesWritten))
+        fprintf (stderr, "USART: Error1\n");
+      if (bytesWritten NEQ (ULONG) n)
+        fprintf (stderr, "USART: Error2\n");
+      break;
+    }
+
+    case US_MODE_SIM: {
+#ifdef DEBUG_USART
+      int i;
+      char buf[50];
+#endif
+      
+      if ( CTS == NULL || !*CTS)  /* no testtools connected */
+      {
+#ifdef DEBUG_USART
+        printf("-");
+#endif
+        snd_cnt++;
+        return;
+      }
+
+      if ( mem_closed == TRUE )
+      {
+        PrintToFile("USART:tried to write on closed memory (%d)\n",snd_cnt);
+        return;
+      }
+      if (waitForSNDBufferEmpty () != 0)
+      {
+        markSNDBufferFull ();
+        PrintToFile("USART: gave up sending\n");
+        snd_cnt++;
+        return;   /* we gave up sending to avoid dead lock */
+      }
+      memcpy (OutBuffer, s, n);
+      *OutCounter = n;
+
+#ifdef DEBUG_USART
+      sprintf (buf, "W[%d]:", n);
+      write (usart_out, buf, strlen (buf));
+
+      for (i=0; i<n; i++)
+      {
+        if (isprint (OutBuffer[i]))
+          sprintf (buf, "%c", OutBuffer[i]);
+        else
+          sprintf (buf, "(%02X)", OutBuffer[i]);
+        write (usart_out,
+               buf,
+               strlen (buf));
+      }
+      write (usart_out,"\n", 1);
+#endif
+
+      if ( mem_closed == TRUE )
+      {
+        PrintToFile("USART: written on closed memory (%d)\n",snd_cnt);
+        snd_cnt++;
+        return;
+      }
+#ifdef DEBUG_USART
+      printf("+");
+#endif
+      markSNDBufferFull ();
+      snd_cnt++;
+      break;
+    default:
+      break;
+    }
+  }
+}
+
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-PS (6147)       MODULE  : USART                      |
+| STATE   : code                ROUTINE : UT_SetFlowCtrl             |
++--------------------------------------------------------------------+
+
+  PURPOSE : 
+
+*/
+
+GLOBAL void UT_SetFlowCtrl (char flowCtrl)
+{
+  switch (m_mode) {
+    case US_MODE_95:
+    case US_MODE_NT: {
+      DCB stDCB;
+
+      if (!GetCommState (hComDev, &stDCB))
+        return;
+
+      stDCB.DCBlength = sizeof (stDCB);  // sizeof(DCB) 
+
+      switch (flowCtrl)
+      {
+        case 'N':
+          stDCB.fOutxCtsFlow = FALSE;
+          stDCB.fOutxDsrFlow = FALSE;
+          stDCB.fDtrControl = DTR_CONTROL_DISABLE;
+          stDCB.fRtsControl = RTS_CONTROL_DISABLE;
+          break;
+        case 'D':
+          stDCB.fOutxCtsFlow = FALSE;
+          stDCB.fOutxDsrFlow = TRUE;
+          stDCB.fDtrControl = DTR_CONTROL_HANDSHAKE;
+          stDCB.fRtsControl = RTS_CONTROL_DISABLE;
+          stDCB.XonLim  = 0;
+          stDCB.XoffLim = 50;
+          break;
+        case 'R':
+          stDCB.fOutxCtsFlow = TRUE;
+          stDCB.fOutxDsrFlow = FALSE;
+          stDCB.fDtrControl = DTR_CONTROL_DISABLE;
+          stDCB.fRtsControl = RTS_CONTROL_HANDSHAKE;
+          stDCB.XonLim  = 0;
+          stDCB.XoffLim = 50;
+          break;
+        case 'P':
+          stDCB.fOutxCtsFlow = FALSE;
+          stDCB.fOutxDsrFlow = FALSE;
+          stDCB.fDtrControl = DTR_CONTROL_ENABLE;
+          stDCB.fRtsControl = RTS_CONTROL_DISABLE;
+          break;
+        default:
+          break;
+      }
+
+      SetCommState (hComDev, &stDCB);
+      break;
+    }
+
+    case US_MODE_SIM:
+      break;
+    default:
+      break;
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_drv/usart.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,215 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       usart.h
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul defines functions for actual or simulated 
+|             USART comunication between two PS-Frames.
+|             Use US_set_mode() to select actual USART under windows95 or 
+|             under windowsNT, or to select simulated USART under win95/NT
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef USART_H
+#define USART_H
+
+/*
+ * Device addresses 
+ */ 
+#define USART_DC	        (USART_BASE + 0x00)     /* Data Channel */   
+#define USART_CC            (USART_BASE + 0x04)     /* Control Channel */
+#define USART_CLK           (USART_BASE + 0x08)     /* Clock */         
+
+#define USART_CTL           (USART_BASE + 0x0C)     /* FIFO control */
+#define USART_FSTAT         (USART_BASE + 0x10)     /* FIFO status */
+#define USART_FTHR          (USART_BASE + 0x14)     /* FIFO threshold */ 
+
+/*
+ * USART_CLK bit definitions
+ */ 
+#define US_CLK_CLK_SEL  0x0001
+#define US_CLK_TXC_SEL  0x0002
+#define US_CLK_RXC_SEL  0x0004
+#define US_CLK_TXC_CTL  0x0100
+#define US_CLK_RXC_CTL  0x0200
+#define US_CLK_RESET    0x0400
+
+/*
+ * USART_MODE bit definitions
+ */ 
+/* Sync/Async and Baud rate */ 
+#define US_MODE_SYNC    0x00
+#define US_MODE_ASYNC   0x01
+#define US_MODE_ASYNC16 0x02
+#define US_MODE_SYNC64  0x03
+
+/* Character length */
+#define US_MODE_CHAR5   (0x00 << 2)
+#define US_MODE_CHAR6   (0x01 << 2)
+#define US_MODE_CHAR7   (0x02 << 2)
+#define US_MODE_CHAR8   (0x03 << 2)
+
+/* Parity */
+#define US_MODE_PEN     0x10
+#define US_MODE_EP      0x20
+
+/* Stop bits */
+#define US_MODE_STOP1   (0x01 << 6)
+#define US_MODE_STOP15  (0x02 << 6)
+#define US_MODE_STOP2   (0x03 << 6)
+
+/* Baud rates */
+#define US_BAUD_115200  0
+#define US_BAUD_57600   1
+#define US_BAUD_38400   2
+#define US_BAUD_33900   3
+#define US_BAUD_28800   4
+#define US_BAUD_19200   5
+#define US_BAUD_14400   6
+#define US_BAUD_9600    7
+#define US_BAUD_4800    8
+#define US_BAUD_2400    9
+#define US_BAUD_1200   10
+#define US_BAUD_600    11
+#define US_BAUD_300    12
+#define US_BAUD_150    13
+#define US_BAUD_75     14
+#define US_BAUD_128000 15
+#define US_BAUD_256000 16
+
+
+/*
+ * USART COMMAND bit definitions
+ */ 
+#define US_CMD_TXEN     0x01
+#define US_CMD_DTR      0x02
+#define US_CMD_RXE      0x04
+#define US_CMD_SBRK     0x08
+#define US_CMD_ER       0x10
+#define US_CMD_RTS      0x20
+#define US_CMD_IR       0x40
+#define US_CMD_EH       0x80
+
+
+/*
+ * USART STATUS bit definitions
+ */ 
+#define US_STAT_TXRDY    0x01
+#define US_STAT_RXRDY    0x02
+#define US_STAT_TXEMPTY  0x04
+#define US_STAT_PE       0x08
+#define US_STAT_OE       0x10
+#define US_STAT_FE       0x20
+#define US_STAT_SBDET    0x40
+#define US_STAT_DSR      0x80
+
+/* 
+ * FIFO control
+ */
+#define US_CTL_RST_FIFO    0x0001
+#define US_CTL_FIFOBYPASS  0x0002
+#define US_CTL_AUTOFC      0x0004
+#define US_CTL_MS_MSK      0x0008
+#define US_CTL_RDRY_MSK    0x0100
+#define US_CTL_TO_MSK      0x0200
+#define US_CTL_TDRY_MSK    0x1000
+#define US_CTL_TXE_MSK     0x2000
+
+#define US_FSTAT_GFE       0x0001
+#define US_FSTAT_GPE       0x0002
+#define US_FSTAT_MODSTAT   0x0008
+#define US_FSTAT_RXOE      0x0020
+#define US_FSTAT_RXFULL    0x0040
+#define US_FSTAT_RXEMPTY   0x0080 
+#define US_FSTAT_RDRY      0x0100
+#define US_FSTAT_TIMEOUT   0x0200
+#define US_FSTAT_TXFULL    0x0800
+#define US_FSTAT_TDRY      0x1000
+#define US_FSTAT_TXE       0x2000
+#define US_FSTAT_TXEMPTY   0x4000
+
+/*
+ * mode constants
+ */
+#define US_MODE_95         1
+#define US_MODE_NT         2
+#define US_MODE_SIM        3
+#define US_MODE_FILE       4
+
+/*
+ * Prototypes
+ */ 
+void US_set_mode(int mode);
+int  US_get_mode(void);
+
+int  US_Init(unsigned int baudRate, int fifoSize, char flow_ctrl, void (func(void)), const char* fname );
+BOOL US_Close(void);
+BYTE US_ReadChar(void);
+void US_Handler(void);
+void US_WriteChar(int usart_id, char ch);
+void US_WriteNChars(int usart_id, BYTE *s, unsigned int n);
+int  US_IsChar(void);
+void US_WriteString(int usart_id, char *s);
+void US_Handler(void);
+void US_SetFlowCtrl (char flowCtrl);
+/*
+int  US_InitBlk(int baudRate, int fifoSize, NU_HISR *hP );
+*/
+ULONG US_ReadNChars(int usart_id, BYTE *s, ULONG n);
+
+/*
+ defines for name_change US -> UT
+*/
+#ifndef _TARGET_
+#define UT_DEVICE_0 (0)
+
+#define UT_BAUD_256000 US_BAUD_256000 
+#define UT_BAUD_128000 US_BAUD_128000
+#define UT_BAUD_115200 US_BAUD_115200
+#define UT_BAUD_57600  US_BAUD_57600
+#define UT_BAUD_38400  US_BAUD_38400
+#define UT_BAUD_33900  US_BAUD_33900
+#define UT_BAUD_28800  US_BAUD_28800
+#define UT_BAUD_19200  US_BAUD_19200
+#define UT_BAUD_14400  US_BAUD_14400
+#define UT_BAUD_9600   US_BAUD_9600
+#define UT_BAUD_4800   US_BAUD_4800
+#define UT_BAUD_2400   US_BAUD_2400
+#define UT_BAUD_1200   US_BAUD_1200
+#define UT_BAUD_600    US_BAUD_600
+#define UT_BAUD_300    US_BAUD_300
+#define UT_BAUD_150    US_BAUD_150
+#define UT_BAUD_75     US_BAUD_75
+
+#define UT_MODE_95     US_MODE_95
+#define UT_MODE_NT     US_MODE_NT
+#define UT_MODE_SIM    US_MODE_SIM
+#define UT_MODE_FILE   US_MODE_FILE
+
+#define UT_set_mode    US_set_mode
+#define UT_get_mode    US_get_mode
+#define UT_Init        US_Init
+#define UT_Close       US_Close
+#define UT_ReadChar    US_ReadChar
+#define UT_ReadNChars  US_ReadNChars
+#define UT_Handler     US_Handler
+#define UT_WriteChar   US_WriteChar
+#define UT_WriteNChars US_WriteNChars
+#define UT_IsChar      US_IsChar
+#define UT_WriteString US_WriteString
+#define UT_SetFlowCtrl US_SetFlowCtrl 
+
+#endif
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_pei/idle.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,68 @@
+/*
++------------------------------------------------------------------------------
+|  File:       idle.h
++------------------------------------------------------------------------------
+|                 Copyright Texas Instruments 2002
+|                 All rights reserved.
+|
++------------------------------------------------------------------------------
+| Purpose:     Definitions for the IDLE entity.
+| $Identity:$
++------------------------------------------------------------------------------
+*/
+
+#ifndef IDLE_H
+#define IDLE_H
+
+/*==== INCLUDES ==============================================================*/
+
+/*==== CONSTS ================================================================*/
+
+#ifdef VSI_CALLER
+ #undef VSI_CALLER
+ #define VSI_CALLER        idle_handle,
+ #define VSI_CALLER_SINGLE idle_handle
+#endif
+
+#define hCommTST          idle_hCommTST   /* Communication handle to TST       */
+
+#define IDLE_REQ   0x00000010
+#define IDLE_CNF   0x00010010
+
+
+#ifndef __T_IDLE_CNF__
+#define __T_IDLE_CNF__
+typedef struct
+{
+  U8                        dummy;                       /*<  0:  1>                              */
+} T_IDLE_CNF;
+#endif
+
+#ifndef __T_IDLE_REQ__
+#define __T_IDLE_REQ__
+typedef struct
+{
+  U8                        dummy;                       /*<  0:  1>                              */
+} T_IDLE_REQ;
+#endif
+
+/*==== TYPES =================================================================*/
+
+/*==== EXPORTS ===============================================================*/
+
+#ifdef IDLE_PEI_C
+
+/* Communication handles */
+T_HANDLE                 idle_handle;
+T_HANDLE                 hCommTST = VSI_ERROR;
+
+#else /* IDLE_PEI_C */
+
+extern T_HANDLE          idle_handle;
+extern T_HANDLE          hCommTST;
+
+#endif /* IDLE_PEI_C */
+
+#endif /* IDLE_H */
+
+/*==== END OF FILE ===========================================================*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_pei/idle_pei.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,253 @@
+/*
++------------------------------------------------------------------------------
+|  File:       idle_pei.c
++------------------------------------------------------------------------------
+|                 Copyright Texas Instruments 2002
+|                 All rights reserved.
+|
++------------------------------------------------------------------------------
+| Purpose:     PEI interface for the IDLE entity.
+|
+| $Identity:$
++------------------------------------------------------------------------------
+*/
+
+#define IDLE_PEI_C
+
+/*==== INCLUDES ==============================================================*/
+
+#include "typedefs.h"
+#include "vsi.h"
+#include "pei.h" 
+#include "tools.h"
+#include "frame.h"
+#include "idle.h"
+
+/*==== CONSTS ================================================================*/
+
+/*==== TYPES =================================================================*/
+
+/*==== LOCALS ================================================================*/
+
+/*==== PRIVATE FUNCTIONS =====================================================*/
+
+/*
++------------------------------------------------------------------------------
+|	Function	:  pei_primitive
++------------------------------------------------------------------------------
+|   Description	:  This function is called by the frame when a primitive is
+|                  received and needs to be processed.
+|
+|   Parameters	:  prim      - Pointer to the received primitive
+|
+|   Return		:  PEI_OK    - function succeeded
+|                  PEI_ERROR - function failed
++------------------------------------------------------------------------------
+*/
+static short pei_primitive (void * prim)
+{
+  if (prim != NULL)
+  {
+    PFREE(P2D(prim));
+  }
+
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|   Function	:  pei_init
++------------------------------------------------------------------------------
+|   Description	:  This function is called by the frame. It is used to initialise
+|                  the entitiy.
+|
+|   Parameters	:  handle            - task handle
+|
+|   Return		:  PEI_OK            - entity initialised
+|                  PEI_ERROR         - entity not (yet) initialised
++------------------------------------------------------------------------------
+*/
+static short pei_init (T_HANDLE handle)
+{
+  /*
+   * Initialize task handle
+   */
+  TRACE_FUNCTION("pei_init");
+
+  idle_handle = handle;
+
+  /*
+   * Open communication channels
+   */
+  if (hCommTST < VSI_OK)
+  {
+    if ((hCommTST = vsi_c_open(VSI_CALLER "RCV")) < VSI_OK)
+      return PEI_ERROR;
+  }
+
+  return (PEI_OK);
+}
+
+/*
++------------------------------------------------------------------------------
+|   Function	:  pei_signal
++------------------------------------------------------------------------------
+|   Description :  This function is called by the frame when a signal has been 
+|                  received.
+|
+|   Parameters  :  opc            - signal operation code
+|                  *data          - pointer to primitive
+|
+|   Return      :  PEI_OK         - signal processed
+|                  PEI_ERROR      - signal not processed
+|
++------------------------------------------------------------------------------
+*/
+static short pei_signal (U32 opc, void *data)
+{
+  /*
+   * Process signal
+   */
+
+  //TRACE_FUNCTION("pei_signal");
+  /* Generate trig in TST */
+  PSIGNAL(hCommTST, IDLE_CNF, NULL);  
+
+  return PEI_OK;
+} 
+
+/*
++------------------------------------------------------------------------------
+|   Function    :  pei_exit
++------------------------------------------------------------------------------
+|   Description	:  This function is called by the frame when the entity is
+|                  terminated. All open resources are freed.
+|
+|   Parameters	:  -
+|
+|   Return		:  PEI_OK         - exit sucessful
+|                  PEI_ERROR      - exit not sueccessful
++------------------------------------------------------------------------------
+*/
+static short pei_exit (void)
+{
+  /*
+   * Close communication channels
+   */
+
+  TRACE_FUNCTION("pei_exit");
+
+  vsi_c_close(VSI_CALLER hCommTST);
+  hCommTST = VSI_ERROR;
+
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|   Function	:  pei_config
++------------------------------------------------------------------------------
+|   Description	:  This function is called by the frame when a primitive is
+|                  received indicating dynamic configuration.
+|
+|                  This function is not used in this entity.
+|
+|   Parameters  :  handle         - Communication handle
+|
+|   Return      :  PEI_OK         - sucessful
+|                  PEI_ERROR      - not successful
++------------------------------------------------------------------------------
+*/
+static short pei_config (char *inString)
+{
+  TRACE_FUNCTION(inString);
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|   Function    :  pei_monitor
++------------------------------------------------------------------------------
+|   Description	:  This function is called by the frame in case sudden entity
+|                  specific data is requested (e.g. entity Version).
+|
+|   Parameters	:  out_monitor    - return the address of the data to be
+|                                   monitoredCommunication handle
+|
+|   Return      :  PEI_OK         - sucessful (address in out_monitor is valid)
+|                  PEI_ERROR      - not successful
++------------------------------------------------------------------------------
+*/
+static short pei_monitor (void **out_monitor)
+{
+  TRACE_FUNCTION ("pei_monitor");
+  return PEI_OK;
+}
+
+/*
++------------------------------------------------------------------------------
+|   Function    :  pei_timeout
++------------------------------------------------------------------------------
+|   Description :  This function is called by the frame when a timer has expired.
+|
+|   Parameters  :  index          - timer index
+|
+|   Return      :  PEI_OK         - timeout processed
+|                  PEI_ERROR      - timeout not processed
+|
++------------------------------------------------------------------------------
+*/
+static short pei_timeout (USHORT index)
+{
+	TRACE_ERROR("Unknown Timeout");
+
+  return PEI_OK;
+}
+
+/*==== PUBLIC FUNCTIONS ======================================================*/
+
+/*
++------------------------------------------------------------------------------
+|   Function    :  idle_pei_create
++------------------------------------------------------------------------------
+|   Description	:  This function is called by the frame when the process is 
+|                  created.
+|
+|   Parameters	:  out_name          - Pointer to the buffer in which to locate
+|                                      the name of this entity
+|
+|   Return		:  PEI_OK            - entity created successfuly
+|                  PEI_ERROR         - entity could not be created
++------------------------------------------------------------------------------
+*/
+short idle_pei_create (T_PEI_INFO **info)
+{
+static T_PEI_INFO pei_info =
+              {
+               "IDLE",         /* name */
+               {              /* pei-table */
+                 pei_init,
+                 pei_exit,
+                 pei_primitive,
+                 pei_timeout,
+                 pei_signal,
+                 NULL,        /* no pei_run function */
+                 pei_config,
+                 pei_monitor
+               },
+               255,           /* stack size */
+               10,            /* queue entries */
+               2,             /* priority (1->low, 255->high) */
+               0,             /* number of timers */
+               0x03           /* flags: bit 0   active(0) body/passive(1) */
+              };              /*        bit 1   com by copy(0)/reference(1) */
+
+  /*
+   * Export startup configuration data
+   */
+  *info = &pei_info;
+
+  return PEI_OK;
+}
+
+/*==== END OF FILE ===========================================================*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_pei/tif_version.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,44 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       tif_version.c
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Module contain build date and time of TIF
+|             about the processes
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __TIF_VERSION_C__
+#define __TIF_VERSION_C__
+#endif
+
+
+/*==== INCLUDES ===================================================*/
+
+
+/*==== TYPES ======================================================*/
+
+
+/*==== CONSTANTS ==================================================*/
+
+#ifndef RUN_INT_RAM
+char const * const tif_version_date = __DATE__;
+char const * const tif_version_time = __TIME__;
+#endif
+
+/*==== EXTERNALS ==================================================*/
+
+
+/*==== FUNCTIONS ==================================================*/
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_pei/tst_pei.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,1157 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       tst_pei.c
++------------------------------------------------------------------------------
+|  Copyright 2004 Texas Instruments Deutschland, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Deutschland, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains the PEI interface of TST
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __TST_PEI_C__
+#define __TST_PEI_C__
+#endif
+ 
+#define ENTITY_TST
+
+/*==== INCLUDES ===================================================*/
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef _TOOLS_
+ #include "frame_const.h" 
+ #include <stdlib.h>
+#endif /* _TOOLS_ */
+
+#ifndef _TARGET_ 
+ #include "printtofile.h"
+#endif
+
+#include "typedefs.h"
+#include "vsi.h"
+#include "frame.h"
+#include "pei.h"
+#include "os.h"
+#include "tools.h"
+#include "gdi.h"
+#include "os.h"
+#include "frm_defs.h" 
+#include "frm_types.h"
+#include "frm_glob.h"
+#include "route.h"
+#include "drvconf.h"
+#include "tstdriver.h"
+#include "tstheader.h"
+#include "tst_mux.h"
+#include "pcon.h"
+
+#ifdef CTB
+ #include "tst_primitives.h"
+#endif
+
+#ifdef _PSOS_
+ #include "pna.h"
+#endif
+
+#ifdef _FF_RV_EXIST_
+ #include "ffs/ffs_api.h"
+#endif
+
+/*==== TYPES ======================================================*/
+
+#undef VSI_CALLER
+#ifdef _TOOLS_
+ #define VSI_CALLER TST_Handle,
+#else
+ #define VSI_CALLER e_running[os_MyHandle()],
+#endif
+
+/*==== CONSTANTS ==================================================*/
+
+#ifdef _VXWORKS_
+  #define TST_STACKSIZE  8192
+  #define TST_PRIORITY    190             /* priority (1->high, 255->low) */
+#else
+  #ifdef _TOOLS_
+    #define TST_STACKSIZE  4096
+    #define TST_PRIORITY     15             
+    #define TST_SND_PRIORITY 15		          /* priority (1->low, 255->high) */
+    #define TST_RCV_PRIORITY 15		          /* priority (1->low, 255->high) */
+  #else
+    #define TST_STACKSIZE  1024
+    #define TST_PRIORITY      2             
+    #define TST_SND_PRIORITY  6             /* priority (1->low, 255->high) */
+    #define TST_RCV_PRIORITY  7             /* priority (1->low, 255->high) */
+  #endif
+#endif
+
+#ifdef _TOOLS_
+ #define TST_TIMERS                        2
+ #define GET_STACK_TIME_TIMER_INDEX        0
+ #define GET_STACK_TIME_TIMER_DURATION 60000
+ #define TST_SYNC_TIMER_INDEX              1
+ #define TST_SYNC_TIMER_DURATION        2000
+#else
+ #define TST_TIMERS         0
+#endif
+
+#ifdef _FF_RV_EXIST_
+#define TRACEMASKFILE "/var/dbg/tracemask"
+#endif
+
+#define DRV_CALLBACK_OPC     0
+
+#ifdef _TOOLS_
+  #define TR_RCV_BUF_SIZE    (MAX_PRIM_PARTITION_SIZE)
+  #define TR_MAX_IND         (TR_RCV_BUF_SIZE-1)
+  USHORT MaxEntities = MAX_ENTITIES;
+#endif /* _TOOLS_ */
+
+/*==== EXTERNALS ==================================================*/
+
+#ifndef _TOOLS_
+extern const T_PCON_PROPERTIES *pcon;
+extern const USHORT TST_SndQueueEntries;
+extern const USHORT TST_RcvQueueEntries;
+extern const USHORT TST_SndStacksize;
+extern const USHORT TST_RcvStacksize;
+extern UBYTE FrameEnv;
+#endif
+
+#ifdef _TOOLS_
+__declspec (dllimport) UBYTE SuppressOK;
+#else
+extern char *str2ind_version;
+extern UBYTE SuppressOK;
+#endif
+
+#ifdef CTB
+  static T_HANDLE hCommIDLE = VSI_ERROR;
+  extern short idle_pei_create (T_PEI_INFO const ** info);
+#endif
+
+#ifdef _FF_RV_EXIST_
+  extern char TaskName[];
+#endif
+
+/*==== VARIABLES ==================================================*/
+
+#ifndef RUN_INT_RAM
+
+T_HANDLE TST_Handle;
+T_HANDLE RCV_Handle;
+T_HANDLE TIF_Handle;
+
+UBYTE TST_DrvState = TST_DRV_DISCONNECTED;
+static char const *ok_string = "OK";
+static UBYTE frmenv;
+
+#ifdef _TOOLS_ 
+ULONG TR_RcvBufferSize = TR_RCV_BUF_SIZE;
+ULONG TR_MaxInd = TR_MAX_IND;
+int tst_syncronized = 0;
+int tst_message_received = 0;
+int tst_sync_timeout_cnt = 0;
+int tst_max_sync_timeout = 0;
+int tst_sync_mode = 0;
+int tst_sync_sucess = 1;
+int tst_sync_started = 0;
+int tst_status_received = 0;
+T_HANDLE tst_sync_req_handle = VSI_ERROR;
+char sync_req_name[RESOURCE_NAMELEN];
+char sync_req_time[16];
+
+#endif /* _TOOLS_ */
+
+GLOBAL USHORT tst_task_priority = TST_PRIORITY;
+GLOBAL ULONG tst_task_stack_size = TST_STACKSIZE;
+
+extern SHORT tst_pei_primitive (void *primitive);
+
+#endif /* RUN_INT_RAM */
+
+#ifdef RUN_INT_RAM
+
+extern T_HANDLE TST_Handle;
+extern T_HANDLE RCV_Handle;
+extern T_HANDLE TIF_Handle;
+extern UBYTE TST_DrvState;
+
+#endif
+
+#ifdef CTB
+  static char ctb_rcv[4];
+  static U32 ctb_remaining_tick_time=0;
+  BOOL ctb_tick_enabled = FALSE;
+  BOOL ctb_sent_to_tap = FALSE;
+  T_HANDLE idle_handle;
+#endif
+
+/*==== FUNCTIONS ==================================================*/
+
+#ifndef RUN_FLASH
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-GPF (8415)             MODULE  : TST_PEI             |
+| STATE   : code                       ROUTINE : pei_primitive       |
++--------------------------------------------------------------------+ 
+*/
+
+SHORT tst_pei_primitive (void *primitive)
+{
+  T_PRIM_HEADER *prim = (T_PRIM_HEADER*)primitive;
+#ifndef _TOOLS_
+  T_VOID_STRUCT *prim_ptr = NULL;
+#endif
+  SHORT ret = PEI_OK;
+  
+#ifdef _TOOLS_
+  if ( ((SAP_NR(prim->opc)==TRACE_SAP) || (prim->opc==TRACE_OPC)) && (P_SHO(prim)!=0) )
+  {
+    prim->opc = SYS_MASK;
+  }
+#endif
+
+  if ( (SAP_NR(prim->opc)!=TRACE_SAP) && (prim->opc!=TRACE_OPC) && !(prim->opc & SYS_MASK) )
+  {
+#ifndef _TOOLS_
+    prim_ptr = (T_VOID_STRUCT*)(((T_PRIM_X*)prim)->prim_ptr);
+#endif
+    VSI_PPM_RCV(prim_ptr);
+    PTRACE_OUT(prim->opc );
+  }
+
+  if ( TST_DrvState == TST_DRV_CONNECTED )
+  {
+    if ( vsi_d_write ( TST_Handle, TIF_Handle, primitive, prim->len ) != VSI_OK )
+      ret = PEI_ERROR;
+#ifdef _TOOLS_
+    vsi_t_sleep(TST_Handle,10);
+#endif
+  }
+
+#ifndef _TOOLS_
+  if ( prim_ptr != NULL )
+  {
+    FREE(P2D(prim_ptr));
+  }
+#endif
+  vsi_trc_free (0, (T_VOID_STRUCT**)&prim);
+
+  return ( ret );
+}
+#endif
+    
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-GPF (8415)             MODULE  : TST_PEI             |
+| STATE   : code                       ROUTINE : pei_init            |
++--------------------------------------------------------------------+ 
+*/
+
+LOCAL SHORT pei_init ( T_HANDLE handle )
+{
+#ifdef _TOOLS_
+  T_HANDLE h_pco;
+#endif
+
+#ifdef _FF_RV_EXIST_
+  T_HANDLE entityTraceMask;
+  ULONG actual;
+  T_FFS_FD fd;
+  T_RV_RETURN retPath;
+  BOOL gotAll = TRUE;
+#endif
+
+  TST_Handle = handle;
+#ifdef _TOOLS_
+  while (vsi_c_open (0, FRM_RCV_NAME) < VSI_OK) 
+  {
+    vsi_t_sleep(0,100);
+  }
+  frmenv = (UBYTE) pf_get_frameenv ();
+  if ( os_OpenQueue (0, FRM_PCO_NAME, &h_pco) == OS_OK ||
+       os_create_extq (FRM_PCO_NAME, &h_pco) == OS_OK)
+  {
+    vsi_o_set_htrace (h_pco);
+#ifdef _DEBUG
+    fprintf (stdout,"TST: %s commH set to %d\n", FRM_PCO_NAME,h_pco);
+#endif
+  }
+  vsi_t_start ( handle, GET_STACK_TIME_TIMER_INDEX, GET_STACK_TIME_TIMER_DURATION );
+#else
+  if ( vsi_c_open (TST_Handle, FRM_RCV_NAME) < VSI_OK ) 
+    return PEI_ERROR;
+  RCV_Handle = vsi_e_handle ( TST_Handle, FRM_RCV_NAME );
+  frmenv = FrameEnv;
+#endif
+#ifndef _TARGET_ 
+  initPrintToFile();
+#endif
+  if ( vsi_d_init ( TST_Handle ) != VSI_OK )
+  {
+#ifndef _TARGET_
+    printf("SYSTEM ERROR: Driver initialization failed\n");
+    vsi_o_assert ( TST_Handle, OS_SYST_ERR, __FILE__, __LINE__, "SYSTEM ERROR: Testinterface driver initialization failed" );
+#else
+    ;
+#endif
+  }
+  TIF_Handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
+  vsi_d_setsignal ( TST_Handle, 0, DRV_SIGTYPE_READ|DRV_SIGTYPE_CONNECT|DRV_SIGTYPE_DISCONNECT); 
+  vsi_d_setconfig ( TST_Handle, 0, NULL ); 
+  vsi_trcsuspend ( TST_Handle, TST_Handle, OS_NO_SUSPEND );
+  SuppressOK = FALSE;
+  tst_mux_init();
+
+#ifdef _FF_RV_EXIST_
+  fd = ffs_open(TRACEMASKFILE,  FFS_O_RDWR);
+  if (fd < 0)
+  {
+    // could not open nor create /var/dbg/tracemask warning
+    vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_init: no trace mask in FFS");
+  }
+  else
+  {
+    InitializeTrace();
+    TraceMask[0] = 0;
+    TraceMask[0] |= TC_SYSTEM|TC_ERROR;
+    for (entityTraceMask = 0; entityTraceMask < (MaxEntities + 1); entityTraceMask++)
+    {
+      actual = TraceMask[entityTraceMask];
+      if (ffs_read(fd, (void*)&TraceMask[entityTraceMask], sizeof(ULONG) ) != sizeof(ULONG) )
+      {
+        gotAll = FALSE;
+      }
+      else
+      {
+        if (entityTraceMask == 0) // first element
+        {
+           TraceMask[0] = 0;
+           TraceMask[0] |= TC_SYSTEM|TC_ERROR;
+        }
+        if (actual != TraceMask[entityTraceMask])
+        {
+          // not the default trace mask, generate warning
+          if ( vsi_e_name ( 0, entityTraceMask, TaskName ) == VSI_OK )
+          {
+            vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_init: FFS trace mask gave 0x%08x for %s (default 0x%08x)", TraceMask[entityTraceMask], TaskName, actual);
+          }
+        }
+      }
+    }  
+  }
+  ffs_close(fd);
+  if (!gotAll)
+  {
+    vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_init: some trace masks can't be read from FFS");
+  }
+#endif
+
+  return PEI_OK;
+}
+#endif
+
+
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-GPF (8415)             MODULE  : TST_PEI             |
+| STATE   : code                       ROUTINE : pei_exit            |
++--------------------------------------------------------------------+ 
+*/
+
+static SHORT pei_exit (void)
+{
+#ifdef _TOOLS_
+  T_HANDLE rcvh=vsi_p_handle (0, FRM_RCV_NAME);
+  if (rcvh > VSI_OK) 
+  {
+    /* exit RCV process */
+    vsi_p_exit ( TST_Handle, vsi_p_handle (0, FRM_RCV_NAME));
+  }
+  /* exit all drivers */
+  vsi_d_exit ( TST_Handle, 0); 
+#endif /* _TOOLS_ */
+
+  return PEI_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+#ifdef _TOOLS_
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-GPF (8415)             MODULE  : TST_PEI             |
+| STATE   : code                       ROUTINE : pei_timeout         |
++--------------------------------------------------------------------+ 
+*/
+
+LOCAL SHORT pei_timeout (USHORT index)
+{
+
+  switch ( index )
+  {
+    case GET_STACK_TIME_TIMER_INDEX:
+#if 0
+      if ( tst_message_received == 1 )
+      {
+        tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_GET_STACK_TIME );
+      }
+      vsi_t_start ( VSI_CALLER GET_STACK_TIME_TIMER_INDEX, GET_STACK_TIME_TIMER_DURATION );
+#endif
+      break;
+    case TST_SYNC_TIMER_INDEX:
+      if ( tst_sync_timeout_cnt++ >= tst_max_sync_timeout-1 )
+      {
+        T_HANDLE tif_handle;
+        T_VOID_STRUCT *ptr;
+        
+        tst_status_received = 0;
+        tst_sync_timeout_cnt = 0;
+        tst_sync_mode = 0;
+        tst_sync_sucess = 0;
+        tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
+        vsi_d_setconfig ( TST_Handle, tif_handle, DISABLE_SYNC_MODE );
+        vsi_t_stop ( TST_Handle, TST_SYNC_TIMER_INDEX );
+        ptr = vsi_c_pnew ( sizeof(T_PRIM_HEADER)+strlen(SYSPRIM_TST_SYNC_REJ), 0x8000 FILE_LINE );
+        strcpy ( (char*)ptr, SYSPRIM_TST_SYNC_REJ );
+        vsi_c_psend ( tst_sync_req_handle, ptr );
+      }
+      else
+      {
+        if ( tst_syncronized == 0 )
+        {
+          T_HANDLE tif_handle;
+          tst_sync_sucess = 1;
+          tst_status_received = 0;
+          tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
+          vsi_d_setconfig ( TST_Handle, tif_handle, ENABLE_SYNC_MODE );
+          tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"TRACECLASS 0x10" );
+          vsi_t_sleep ( TST_Handle, 100 );
+          tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"STATUS TASK" );
+          vsi_t_start ( TST_Handle, TST_SYNC_TIMER_INDEX, TST_SYNC_TIMER_DURATION );
+          vsi_t_sleep ( TST_Handle, 200 );
+          tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"ROUTING" );
+        }
+      }
+      break;
+    default:
+      break;
+  }
+  return PEI_OK;
+}
+#endif
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-GPF (8415)             MODULE  : TST_PEI             |
+| STATE   : code                       ROUTINE : pei_signal          |
++--------------------------------------------------------------------+ 
+*/
+LOCAL SHORT pei_signal (ULONG SignalType, void *ptr)
+{
+/*
+ * the following line of code causes a warning on tms470 compiler, that cannot be avoided
+ * without changing the PEI interface. Warning will not cause a problem 
+ */
+T_VOID_STRUCT *sig_ptr = (T_VOID_STRUCT*)ptr;
+T_PRIM_HEADER *prim;
+T_S_HEADER *s_hdr;
+T_HANDLE DestTaskHandle, DestComHandle;
+T_HANDLE min, max, i;
+unsigned int Length;
+ULONG Suspend, TraceMask, OldTraceMask;
+unsigned int Offset = 0;
+char token[81];
+UBYTE FreePrim = 1;
+SHORT ret = PEI_OK;
+USHORT processed = FALSE;
+
+  switch ( SignalType )
+  {
+    case DRV_SIGTYPE_READ:
+    VSI_PPM_RCV(sig_ptr);
+    if ( (prim = ((T_PRIM_X*)sig_ptr)->prim_ptr) != NULL )
+    {
+      VSI_PPM_RCV (prim);
+      s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
+      DestTaskHandle = vsi_e_handle ( TST_Handle, s_hdr->rcv );
+      if ( DestTaskHandle == VSI_ERROR )
+      {
+        if ( !strcmp ( "IRQ", s_hdr->rcv ) )
+        {
+          DestTaskHandle = 0;
+          OldTraceMask = TC_SYSTEM;
+          TraceMask = 0;
+        }
+        else 
+        {
+          if ( !strcmp ( "SYST", s_hdr->rcv ) )
+          {
+            DestTaskHandle = 0;
+            vsi_gettracemask ( DestTaskHandle, 0, &OldTraceMask);
+            TraceMask = TC_SYSTEM;
+          }
+          else
+          {
+            OldTraceMask = 0;
+            TraceMask = 0;
+          }
+        }
+      }
+      else
+      {
+        /* to satisfy LINT */
+        OldTraceMask = 0;
+        TraceMask = 0;
+      }
+      if ( DestTaskHandle != VSI_ERROR )
+      {
+        if ( prim->opc & SYS_MASK )
+        {
+          Length = GetNextToken ((char*)(P2D(prim)), token, "  #");
+          Offset = Length+1;
+          if ( frmenv == ENV_STACK )
+          {
+            /* Set Traceclass for non-frame tasks/HISRs */
+            if ( DestTaskHandle == 0 && !strcmp (token, SYSPRIM_TRACECLASS_TOKEN) )
+            {
+              Length = GetNextToken ((char *)(P2D(prim))+Offset, token, " #");
+              TraceMask = ASCIIToHex(token, CHARS_FOR_32BIT);
+              vsi_settracemask ( DestTaskHandle, 0, TraceMask|OldTraceMask); /* it is not allowed to switch of system traces */
+              sprintf ( token, "%s (%s %s)", ok_string, (char*)(P2D(prim)), s_hdr->rcv );
+              tst_drv_write ( NO_TASK, 0, NULL, token );
+              processed = TRUE;
+            }
+            if (!strcmp (token, SYSPRIM_TRC_SUSPEND))
+            {
+              processed = TRUE;
+              /*
+               * set suspend for traces to SUSPEND or NO_SUSPEND
+               */
+              Length = GetNextToken ((char *)(P2D(prim))+Offset, token, " #");
+              Offset += (Length+1);
+ 
+              if ( !strcmp ( token, "ALL" ) )
+              {  
+                min = 1; 
+                max = MaxEntities;
+                GetNextToken ((char *)(P2D(prim))+Offset, token, " #");
+              }
+              else
+              { 
+                min = DestTaskHandle; 
+                max = min; 
+              }
+              if ( !strcmp ( token, "YES" ) )
+                Suspend = 0xffffffff;
+              else
+                Suspend = 0;
+     
+              for ( i = min; i <= max; i++ ) 
+                vsi_trcsuspend ( TST_Handle, i, Suspend );
+              sprintf ( token, "%s (%s %s)", ok_string, (char*)(P2D(prim)), s_hdr->rcv );
+              tst_drv_write ( NO_TASK, 0, NULL, token );
+            }
+            else if (!strcmp (token, SYSPRIM_MEMCHECK_TOKEN))
+            {
+              processed = TRUE;
+              /*
+               * Memory Check
+               */
+              for ( i = 1; i <= MaxEntities; i++ )
+              {
+                 if ( vsi_object_info (TST_Handle, OS_OBJTASK, (USHORT)i, token, sizeof(token)) != VSI_ERROR )
+                 {
+                   tst_drv_write ( NO_TASK, 0, NULL, token );
+                 }
+              }
+            }
+#ifdef CTB
+#ifndef _TOOLS_
+            else if (!strcmp (token, SYSPRIM_TIMER_TICK_REQ)) 
+            {
+               processed = TRUE;
+               ctb_sent_to_tap = FALSE;
+               if(strlen(ctb_rcv)<3)
+               {
+                  strcpy(ctb_rcv, P_SND(prim));
+               }
+               ctb_remaining_tick_time = P_TIME(prim);  //The time parameter is sent in the time stap.
+               /*sprintf ( token, "Requesting ticking for %d from %s", ctb_remaining_tick_time, ctb_rcv);
+               tst_drv_write ( NO_TASK, 0, NULL, token );*/
+               PSIGNAL(hCommIDLE, IDLE_REQ, NULL);
+            }
+            else if (!strcmp (token, SYSPRIM_INT_TICK_MODE_REQ)) 
+            {
+              processed = TRUE;
+              if(ctb_tick_enabled)
+              {               
+                vsi_p_delete (TST_Handle,idle_handle); 
+                ctb_tick_enabled = FALSE;
+                ctb_sent_to_tap = FALSE;
+                sprintf ( token, "Disabling Common Timer Base");
+                ctb_rcv[0]='\0';
+                os_StartTicking();
+              }
+              else
+                sprintf ( token, "Common Timer Base already disabled");
+              tst_drv_write ( NO_TASK, 0, NULL, token );
+              if(!strcmp(P_SND(prim), "TAP")) 
+              {
+                tst_drv_write ( NO_TASK, SYS_MASK, "TAP", "INT_TICK_MODE_CNF");
+              }
+            }
+            else if (!strcmp (token, SYSPRIM_EXT_TICK_MODE_REQ)) 
+            {
+              processed = TRUE;
+              if(!ctb_tick_enabled)
+              {
+                if ( (idle_handle = vsi_p_create (TST_Handle, idle_pei_create, NULL, 1)) == VSI_ERROR )
+                {
+                  vsi_o_assert ( TST_Handle, OS_SYST_ERR, __FILE__, __LINE__, "CTB: Cannot create IDLE task" );
+                }
+                vsi_p_start (TST_Handle, idle_handle);
+                while ( (hCommIDLE = vsi_e_handle ( TST_Handle, "IDLE" ))<VSI_OK)
+                {
+	                vsi_t_sleep(0,1000);
+                }
+                os_StopTicking();
+                sprintf ( token, "Enabling Common Timer Base");
+     	          ctb_tick_enabled = TRUE;
+              }
+              else
+                sprintf ( token, "Common Timer Base already enabled");
+   			      tst_drv_write ( NO_TASK, 0, NULL, token );
+				      if(!strcmp(P_SND(prim), "TAP")) 
+              {
+                char send_str[50];
+                char tmp_str[8];
+                //Get process id and put in this syst primitive.
+                strcpy(send_str,"EXT_TICK_MODE_CNF#");
+                _itoa(os_GetProcessId(), tmp_str, 10);
+                strcat(send_str, tmp_str);
+                tst_drv_write ( NO_TASK, SYS_MASK, "TAP", send_str);
+              }
+	          }
+#endif
+#endif //CTB
+
+#ifndef _TARGET_
+            else if (!strcmp (token, SYSPRIM_SUPPRESS_OK))
+            {
+              processed = TRUE;
+              SuppressOK = TRUE;
+            }  
+#endif
+            else if (!strcmp (token, SYSPRIM_GET_STACK_TIME))
+            {
+              processed = TRUE;
+              tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_IS_STACK_TIME );
+            }  
+            else if (!strcmp (token, SYSPRIM_READ_ROUTING))
+            {
+              processed = TRUE;
+              i = 0;
+              while ( rt_RouteRead ( DestTaskHandle, token ) != RT_ERROR )
+              {
+                tst_drv_write ( NO_TASK, 0, NULL, token );
+                i++;
+              }
+              if ( !i )
+              {
+                sprintf ( token, "NO %s ROUTINGS STORED", s_hdr->rcv );
+                tst_drv_write ( NO_TASK, 0, NULL, token );
+              }
+            }
+#ifndef _TOOLS_
+            else if (!strcmp (token, SYSPRIM_STR2IND_VERSION))
+            {
+              processed = TRUE;
+              tst_drv_write ( NO_TASK, 0, NULL, str2ind_version );
+            }
+#endif
+          }
+        }
+      }
+#ifdef _TOOLS_
+      else
+      {
+        /* synchronization with protocol stack */
+        if ( tst_sync_mode == 1 )
+        {
+          char *pos;
+          char task_status;
+          T_VOID_STRUCT *cmd_ptr;
+
+          pos = strstr ( (char*)(P2D(prim)), "Name:" );
+          if ( pos != NULL )
+          {
+            tst_sync_started = 1;
+            GetNextToken ((char *)(P2D(prim))+strlen("Name:"), token, " #");
+            if ( strcmp(token,FRM_RCV_NAME) && strcmp(token,FRM_TST_NAME) && strcmp(token,"EXTR") )
+            {
+              pos = strstr ( (char*)(P2D(prim)), "Stat:" );
+              if ( pos != NULL )
+              {
+                tst_status_received = 1;
+                task_status = atoi(pos+strlen("Stat:"));
+                if ( task_status != 6 )
+                {
+                  tst_sync_sucess = 0;
+                }
+              }
+            }
+          }
+          else
+          {
+            if ( tst_sync_started == 1 )
+            {
+              pos = strstr ( (char*)(P2D(prim)), "ROUTING" );
+              if ( pos != NULL )
+              {
+                if ( tst_sync_sucess == 1 && tst_status_received == 1 )
+                {
+                  T_HANDLE tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
+                  vsi_d_setconfig ( TST_Handle, tif_handle, DISABLE_SYNC_MODE );
+                  vsi_t_stop ( TST_Handle, TST_SYNC_TIMER_INDEX );
+                  cmd_ptr = vsi_c_pnew ( sizeof(T_PRIM_HEADER)+strlen(SYSPRIM_TST_SYNC_CNF), 0x8000 FILE_LINE );
+                  strcpy ( (char*)cmd_ptr, SYSPRIM_TST_SYNC_CNF );
+                  vsi_o_ttrace ( TST_Handle, TC_TIMER, "SYNC DONE") ;
+                  vsi_c_psend ( tst_sync_req_handle, cmd_ptr );
+                  tst_sync_mode = 0;
+                  tst_sync_timeout_cnt = 0;
+                  tst_syncronized = 1;
+                }
+              }
+            }
+          }
+        }
+      }
+#endif /* _TOOLS_ */
+      if ( processed == FALSE )
+      {
+        if ( ( DestComHandle = vsi_c_open ( TST_Handle, s_hdr->rcv ) ) != VSI_ERROR )
+        {
+          /* free carrier */
+          PFREE(P2D(sig_ptr));
+          FreePrim = 0;
+          vsi_c_psend (DestComHandle, (T_VOID_STRUCT*)P2D(prim) FILE_LINE_MACRO);
+        }
+        else 
+        {
+#ifndef _TOOLS_
+          if ( frmenv == ENV_STACK )
+          {
+            sprintf ( token, "SYSTEM WARNING: Receiver Process '%s' unknown", s_hdr->rcv );
+            tst_drv_write ( NO_TASK, 0, NULL, token );
+            ret = PEI_ERROR;
+          }
+#endif /* _TOOLS_ */
+          /* free dyn_ptr if unknown receiver */
+          FREE(P2D(prim));
+        }
+      }
+      else
+      {
+        /* free dyn_ptr if processed in TST */
+        FREE(P2D(prim));
+      }
+    }
+
+    if ( FreePrim ) 
+    {
+      /* free carrier */
+      PFREE(P2D(sig_ptr));
+    }
+    break;
+    case DRV_SIGTYPE_CONNECT:
+      TST_DrvState = TST_DRV_CONNECTED;
+#ifndef _TOOLS_
+      tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, (char*)SYSPRIM_IS_STACK_TIME );
+      tst_drv_write ( NO_TASK, 0, NULL, str2ind_version );
+#endif
+    break;
+    case DRV_SIGTYPE_DISCONNECT:
+      TST_DrvState = TST_DRV_DISCONNECTED;
+#ifdef _PSOS_
+      /* for pSOS: send empty message to TST */
+      if ( vsi_d_open ( TST_Handle, "SOCKET" ) != VSI_ERROR )
+      {
+        T_QMSG Message;
+        static T_HANDLE tst_handle = 0;
+
+        if( TST_Handle > 0 ) 
+        {
+          Message.MsgType = MSG_PRIMITIVE;
+          Message.Msg.Primitive.Prim = NULL;
+          Message.Msg.Primitive.PrimLen = 0;
+#ifdef MEMORY_SUPERVISION
+          vsi_c_send (TST_Handle, TST_Handle, &Message, __FILE__, __LINE__);
+#else
+          vsi_c_send (TST_Handle, TST_Handle, &Message);
+#endif
+        }
+      }
+#endif
+    break;
+#ifdef CTB
+    case IDLE_CNF:
+     if(ctb_remaining_tick_time > 0 && ctb_tick_enabled && !ctb_sent_to_tap) 
+     {
+       os_Tick();
+       PSIGNAL(hCommIDLE, IDLE_REQ, NULL);
+       ctb_remaining_tick_time = ctb_remaining_tick_time-50;
+     }
+     else
+     {
+       /*sprintf ( token, "Ticking finished - remaining time %d", ctb_remaining_tick_time);
+       tst_drv_write ( NO_TASK, 0, NULL, token );*/
+       if(!strcmp(ctb_rcv, "TAP"))
+         tst_drv_write ( NO_TASK, SYS_MASK, FRM_TST_NAME, SYSPRIM_IS_STACK_TIME ); //Synchronize time with tools
+       tst_drv_write ( NO_TASK, SYS_MASK, ctb_rcv, "TIMER_TICK_CNF");
+     }
+    break;
+#endif
+    default:
+        sprintf ( token, "Unhandled PSIGNAL");
+        tst_drv_write ( NO_TASK, 0, NULL, token );
+    break;
+  }
+  return ( ret );
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-GPF (8415)             MODULE  : TST_PEI             |
+| STATE   : code                       ROUTINE : pei_config          |
++--------------------------------------------------------------------+ 
+*/
+
+LOCAL SHORT pei_config (char * inString)
+{
+T_HANDLE drv_handle;
+char token[80];
+unsigned int length, offset;
+BOOL select = 0,config = 0;
+T_TST_DRV_ENTRY *tst_drv_info;
+
+  length = GetNextToken (inString, token, " #");
+  offset = length+1;
+  if ( !strcmp ( token, "DRIVER") )
+  {
+    length = GetNextToken (inString+offset, token, " #");
+    offset += (length+1);
+    if ( !strcmp ( token, "FLUSH") )
+    {
+     vsi_d_flush ( TST_Handle, 0 );
+    }
+    if ( !strcmp ( token, "SELECT") )
+    {
+     select = 1;
+    }
+    if ( !strcmp ( token, "CONFIG") )
+    {
+      config = 1;
+#ifdef _TOOLS_
+      tst_syncronized = 0;
+#endif
+    }
+    length = GetNextToken (inString+offset, token, " #");
+    offset += (length+1);
+    if ( select )
+    {
+#ifdef _TOOLS_
+      if ( !strcmp(NODRV_NAME,token) )
+      {
+        if ( tst_drv_open ( token, &tst_drv_info ) == VSI_ERROR ||
+             vsi_d_create ( TST_Handle, tst_drv_info ) == VSI_ERROR)
+        {
+          return PEI_ERROR;
+        }
+        PrintToFile("TST: all drivers unloaded\n");
+      }
+      else
+#endif
+      {
+        /* check if driver is already loaded */
+        if ( (drv_handle = vsi_d_open ( TST_Handle, token )) == VSI_ERROR )
+        {
+          if ( tst_drv_open ( token, &tst_drv_info ) == VSI_ERROR ||
+               vsi_d_create ( TST_Handle, tst_drv_info ) == VSI_ERROR )
+          {
+            return PEI_ERROR;
+          }
+        } 
+        else 
+        {
+#ifdef _TOOLS_
+#ifdef _DEBUG
+          PrintToFile("TST: keeping %s loaded\n",token);
+#endif
+#endif
+          vsi_d_close( TST_Handle, drv_handle );
+        }
+      }
+    }
+    if ( config )
+    {
+      if ( ( drv_handle = vsi_d_open ( TST_Handle, token ) ) == VSI_ERROR )
+      {
+        return PEI_ERROR;
+      }
+      if (vsi_d_setconfig ( TST_Handle, drv_handle, inString+offset) != VSI_OK)
+      {
+#ifdef _TOOLS_
+        char text[99];
+        _snprintf(text,98,"TST: Error configuring driver %s with \"%s\" :-(",token, inString+offset);
+        vsi_o_ttrace(NO_TASK, TC_SYSTEM, text);
+#endif /* _TOOLS_ */
+      }
+      vsi_d_close( TST_Handle, drv_handle );
+    }
+  }  
+  else if ( !strcmp ( token, "THIF") )
+  {
+    T_HANDLE tif_handle;
+    tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
+    length = GetNextToken (inString+offset, token, " #");
+    offset += (length+1);
+
+    if ( !strcmp ( token, "OPEN") )
+    {
+      vsi_d_setconfig ( TST_Handle, tif_handle, token );
+    }
+    else if ( !strcmp ( token, "CLOSE") )
+    {
+      vsi_d_setconfig ( TST_Handle, tif_handle, token );
+    }
+  }
+#ifdef _TOOLS_
+  else if ( !strcmp ( token, SYSPRIM_TST_SYNC_REQ) )
+  {
+    T_HANDLE tif_handle;
+    unsigned int len;
+
+    len = GetNextToken (inString+offset, sync_req_name, " #");
+    offset += len;
+    len = GetNextToken (inString+offset, sync_req_time, " #"); 
+    tst_max_sync_timeout = (atoi(sync_req_time) - 1000)/TST_SYNC_TIMER_DURATION;
+
+    tst_sync_req_handle = vsi_c_open ( TST_Handle, sync_req_name );
+    if ( tst_sync_req_handle != VSI_ERROR )
+    {
+      if ( tst_syncronized == 0 )
+      {
+        tst_sync_started = 0;
+        tst_status_received = 0;
+        tst_sync_mode = 1;
+        tst_sync_sucess = 1;
+        tif_handle = vsi_d_open ( TST_Handle, (char*)TIF_NAME );
+        vsi_d_setconfig ( TST_Handle, tif_handle, ENABLE_SYNC_MODE );
+        tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"TRACECLASS 0x10" );
+        vsi_t_sleep ( TST_Handle, 100 );
+        tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"STATUS TASK" );
+        vsi_t_start ( TST_Handle, TST_SYNC_TIMER_INDEX, TST_SYNC_TIMER_DURATION );
+        vsi_t_sleep ( TST_Handle, 200 );
+        tst_drv_write ( NO_TASK, SYS_MASK, FRM_RCV_NAME, (char*)"ROUTING" );
+      }
+    }
+  }
+#endif
+#ifdef _FF_RV_EXIST_
+  else if ( !strcmp ( token, "TRACEMASK_IN_FFS") )
+  {
+    int amount;
+    T_FFS_FD fd;
+    T_FFS_RET ret;
+    T_FFS_SIZE written;
+    T_FFS_DIR dir;
+    BOOL writeFailed = FALSE;
+    if (vsi_e_handle ( TST_Handle, FRM_RCV_NAME ) == e_running[os_MyHandle()]) // config prim processing only allowed in RCV, not TST!
+    {
+      fd = ffs_open(TRACEMASKFILE,  FFS_O_RDWR | FFS_O_CREATE | FFS_O_TRUNC);
+      if (fd < 0)
+      {
+        // could not open nor create /var/dbg/tracemask warning
+        vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: could not open/create FFS trace mask, reason is 0x%x", fd);
+      }
+      else
+      {
+        TraceMask[0] = 0;
+        TraceMask[0] |= TC_SYSTEM|TC_ERROR;
+        amount = sizeof(ULONG) * (MaxEntities + 1);
+        written = ffs_write(fd, (void*)&TraceMask[0], amount);
+        if (written != amount)
+        {
+          if (written >= 0)
+          {
+            amount -= written;
+            vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: writing to  FFS, second try");
+            written = ffs_write(fd, (void*)&TraceMask[0], amount);
+            if (written != amount) 
+            {
+              writeFailed = TRUE;
+            }
+          }
+          else
+          {
+            writeFailed = TRUE;
+          } 
+        }
+        if (writeFailed)
+        {
+          vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: ffs_write to FFS failed with 0x%x, did open with", written, fd);
+        }
+        else
+        {
+          if (ffs_fdatasync(fd) == EFFS_OK)
+          {
+            vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: successfully written trace mask to FFS");
+          }
+          else
+          {
+            vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: flushing FFS trace mask failed!");
+          }
+        }
+        ffs_close(fd);
+      }
+    }
+  }
+  else if ( !strcmp ( token, "NO_TRACEMASK_IN_FFS") )
+  {
+    T_FFS_RET ret;
+
+    InitializeTrace();
+    TraceMask[0] = 0;
+    TraceMask[0] |= TC_SYSTEM|TC_ERROR;
+    if (vsi_e_handle ( TST_Handle, FRM_RCV_NAME ) == e_running[os_MyHandle()]) // config prim processing only allowed in RCV, not TST!
+    {
+      ret = ffs_remove(TRACEMASKFILE);
+      if (ret != EFFS_OK)
+      {
+       vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: failed to remove FFS trace mask, reason is 0x%x", ret);
+      }
+      else
+      {
+        vsi_o_ttrace(NO_TASK, TC_SYSTEM, "pei_config: successfully removed FFS trace mask");
+      }
+    }
+  }
+#endif
+  return PEI_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+GLOBAL SHORT tstsnd_pei_create ( T_PEI_INFO ** info)
+{
+  static T_PEI_INFO data = 
+  { "TST",  
+    { 
+      pei_init,
+      pei_exit,
+      tst_pei_primitive,
+#ifdef _TOOLS_
+      pei_timeout,
+#else
+      NULL,
+#endif
+      NULL,
+      NULL,
+      pei_config,
+      NULL 
+    },
+    TST_STACKSIZE, 
+    0,
+    TST_SND_PRIORITY,
+    TST_TIMERS,
+    (PASSIVE_BODY|COPY_BY_REF|SYSTEM_PROCESS|TRC_NO_SUSPEND)
+  };
+
+#ifdef _TOOLS_
+  data.QueueEntries = TST_QUEUE_ENTRIES;
+#else
+  data.QueueEntries = TST_SndQueueEntries;
+  /* 
+   * This way of setting the TST and RCV stacksize is chosen to keep it backwardscompatible,
+   * i.e. not change the behavior if the stacksizes are not define in the configuration
+   * file xxxconst.h.
+   */
+  if ( TST_SndStacksize > 0 )
+  {
+    data.StackSize = TST_SndStacksize;
+  }
+  if ( pcon != NULL )
+  {
+    data.StackSize += pcon->stack_offset;
+  }
+#endif
+  *info = &data;
+  return PEI_OK;
+} 
+#endif
+
+#ifndef RUN_INT_RAM
+GLOBAL SHORT tstrcv_pei_create ( T_PEI_INFO ** info)
+{
+  static T_PEI_INFO data = 
+  { "RCV",  
+    { 
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      pei_signal,
+      NULL,
+      pei_config,
+      NULL 
+    },
+    TST_STACKSIZE, 
+    0,
+    TST_RCV_PRIORITY,
+    TST_TIMERS,
+    (PASSIVE_BODY|COPY_BY_REF|SYSTEM_PROCESS|TRC_NO_SUSPEND)
+  };
+
+#ifdef _TOOLS_
+  data.QueueEntries = TST_QUEUE_ENTRIES;
+#else
+  data.QueueEntries = TST_RcvQueueEntries;
+  /* 
+   * This way of setting the TST and RCV stacksize is chosen to keep it backwardscompatible,
+   * i.e. not change the behavior if the stacksizes are not define in the configuration
+   * file xxxconst.h.
+   */
+  if ( TST_RcvStacksize > 0 )
+  {
+    data.StackSize = TST_RcvStacksize;
+  }
+  if ( pcon != NULL )
+  {
+    data.StackSize += pcon->stack_offset;
+  }
+#endif
+  *info = &data;
+  return PEI_OK;
+} 
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_pei/tst_primitives.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,57 @@
+/*
++------------------------------------------------------------------------------
+|  File:       tst_primitives.h
++------------------------------------------------------------------------------
+|                 Copyright Texas Instruments 2002
+|                 All rights reserved.
+|
++------------------------------------------------------------------------------
+| Purpose:     Definitions for the IDLE entity.
+| $Identity:$
++------------------------------------------------------------------------------
+*/
+
+#ifndef TST_PRIMITIVES
+#define TST_PRIMITIVES
+
+/*==== INCLUDES ==============================================================*/
+
+/*==== CONSTS ================================================================*/
+
+#define IDLE_REQ   0x00000010
+#define IDLE_CNF   0x00010010
+
+#define SYSPRIM_EXT_TICK_MODE_REQ	"EXT_TICK_MODE_REQ"
+#define SYSPRIM_EXT_TICK_MODE_CNF	"EXT_TICK_MODE_CNF"
+#define SYSPRIM_INT_TICK_MODE_REQ	"INT_TICK_MODE_REQ"
+#define SYSPRIM_INT_TICK_MODE_CNF	"INT_TICK_MODE_CNF"
+#define SYSPRIM_TIMER_TICK_REQ		"TIMER_TICK_REQ"
+#define SYSPRIM_TIMER_TICK_CNF		"TIMER_TICK_CNF"
+
+#define SYSPRIM_IDLE_REQ			"IDLE_REQ"
+#define SYSPRIM_IDLE_CNF			"IDLE_CNF"
+
+
+/*==== TYPES =================================================================*/
+
+#ifndef __T_IDLE_CNF__
+#define __T_IDLE_CNF__
+typedef struct
+{
+  U8                        dummy;                       /*<  0:  1>                              */
+} T_IDLE_CNF;
+#endif
+
+#ifndef __T_IDLE_REQ__
+#define __T_IDLE_REQ__
+typedef struct
+{
+  U8                        dummy;                       /*<  0:  1>                              */
+} T_IDLE_REQ;
+#endif
+
+
+/*==== EXPORTS ===============================================================*/
+
+#endif /* TST_PRIMITIVES */
+/*==== END OF FILE ===========================================================*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_pei/tstdriver.c	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,448 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       tstdriver.c
++------------------------------------------------------------------------------
+|  Copyright 2004 Texas Instruments Deutschland, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Deutschland, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  This Modul contains a table of all the drivers that may be
+|             used for the test interface.
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef __TST_DRV_C__
+#define __TST_DRV_C__
+#endif
+ 
+/*==== INCLUDES ===================================================*/
+
+#include "string.h"
+
+#include "typedefs.h"
+#include "os.h"
+#include "vsi.h"
+#include "gdi.h"
+#include "drvconf.h"
+#include "tstdriver.h"
+#include "tst_mux.h"
+
+/*==== TYPES ======================================================*/
+
+
+/*==== VARIABLES ==================================================*/
+
+T_TST_MUX_CHANNEL tst_mux_chan_struct[ MAX_TST_CHANNEL ];
+T_HANDLE tst_mux_drv_handle;
+
+/*
+ * just a hack - clean up needed
+ */
+#define MAX_PROT_PRIM_SIZE 236
+ULONG DrvSndData[(MAX_PROT_PRIM_SIZE + sizeof(T_PRIM_HEADER) + 3) / 4];
+ULONG X_PrimData[(sizeof(T_PRIM_X) + sizeof(T_S_HEADER) + 3)  / 4 ]; 
+
+/*==== EXTERNALS ==================================================*/
+
+extern T_HANDLE TST_Handle;
+extern T_HANDLE TIF_Handle;
+extern UBYTE TST_DrvState;
+
+#ifndef _TARGET_
+extern USHORT TIF_Init      ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc,
+                              T_DRV_EXPORT const **DrvInfo );
+extern USHORT TR_Init       ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc,
+                              T_DRV_EXPORT const **DrvInfo );
+extern USHORT NODRV_Init    ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc,
+                              T_DRV_EXPORT const **DrvInfo );
+extern USHORT socket_Init   ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc,
+                              T_DRV_EXPORT const **DrvInfo );
+extern USHORT SER_Init      ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc,
+                              T_DRV_EXPORT const **DrvInfo );
+#endif
+
+/*==== CONSTANTS ==================================================*/
+#ifdef _TARGET_
+#ifndef RUN_INT_RAM
+const T_TST_DRV_ENTRY tst_drv_list[ MAX_AVAILABLE_DRV ] =
+{
+  { { NULL,            NULL,           NULL,   NULL }, 0 }
+};
+#endif /* RUN_INT_RAM */
+#else /* _TARGET_ */
+
+const T_TST_DRV_ENTRY tst_drv_list[ MAX_AVAILABLE_DRV ] =
+{
+  { { TIF_NAME,        TIF_Init,       "TST",  NULL }, 1 },
+  { { TR_NAME,         TR_Init,        NULL,   NULL }, 2 },
+  { { SOCKET_NAME,     socket_Init,    NULL,   NULL }, 3 },
+#if !defined (_LINUX_) && !defined (_SOLARIS_)
+  { { SER_NAME,        SER_Init,       NULL,   ""   }, 3 },
+#endif
+  { { NODRV_NAME,      NODRV_Init,     NULL,   NULL }, 3 },
+  { { NULL,            NULL,           NULL,   NULL }, 0 }
+};
+#endif /* _TARGET_ */
+
+
+/*==== VARIABLES ==================================================*/
+
+
+/*==== FUNCTIONS ==================================================*/
+
+
+#ifndef _TARGET_
+/*
++--------------------------------------------------------------------+
+| PROJECT : GPF                        MODULE  : TSTDRIVER           |
+| STATE   : code                       ROUTINE : NODRV_Init          |
++--------------------------------------------------------------------+ 
+
+  PURPOSE : initialize empty driver
+
+*/
+GLOBAL USHORT NODRV_Init ( USHORT DrvHandle, T_DRV_CB_FUNC CallbackFunc, T_DRV_EXPORT const **DrvInfo )
+{                
+static const T_DRV_EXPORT NODRV_Info =
+{
+  NODRV_NAME,
+  0,
+  {
+#ifdef _TOOLS_
+    NULL,
+#endif
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+  }
+};
+
+  *DrvInfo = &NODRV_Info;
+  return DRV_OK;           
+}
+#endif /* ndef _TARGET_ */
+
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GPF                        MODULE  : TSTDRIVER           |
+| STATE   : code                       ROUTINE : tst_drv_open        |
++--------------------------------------------------------------------+ 
+*/
+
+SHORT tst_drv_open (char *drv_name, T_TST_DRV_ENTRY **drv_info )
+{
+USHORT i;
+
+  for ( i = 0; i < MAX_AVAILABLE_DRV; i++ )
+  {
+    if ( tst_drv_list[i].entry.Name && drv_name 
+      && !strcmp ( drv_name, tst_drv_list[i].entry.Name ) )
+    {
+      *drv_info = (T_TST_DRV_ENTRY*)&tst_drv_list[i];
+      return VSI_OK;
+    }
+  }
+  return VSI_ERROR;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++--------------------------------------------------------------------+
+| PROJECT : GSM-GPF (8415)             MODULE  : TSTDRIVER           |
+| STATE   : code                       ROUTINE : tst_drv_write       |
++--------------------------------------------------------------------+ 
+
+  PURPOSE:  Send a message via the test interface 
+
+*/
+GLOBAL SHORT tst_drv_write ( T_HANDLE caller, ULONG opc, char *dest, char *Buffer )
+{
+T_PRIM_HEADER *prim;
+T_S_HEADER *s_hdr;
+T_VOID_STRUCT *ptr = (T_VOID_STRUCT*)Buffer;  /* just to reduce number of alignment warnings */
+T_VOID_STRUCT *snd_ptr;
+T_PRIM_X *x_prim = (T_PRIM_X*)X_PrimData;
+
+  x_prim->prim_ptr = NULL;
+  prim = (T_PRIM_HEADER*)DrvSndData;
+  prim->opc = opc;
+  if ( opc == 0 || opc == SYS_MASK )          /* opc = 0 -> trace -> to PCO */
+  {
+    prim->len = sizeof(T_PRIM_HEADER);
+    if ( Buffer != NULL )
+    {
+      prim->len += strlen(Buffer);
+      strcpy ((char*)P2D(prim), Buffer );
+    }
+  }
+  else
+  {
+    x_prim->prim_ptr = prim;
+    x_prim->p_hdr.opc = opc;
+    if ( D_LEN(ptr) <= MAX_PROT_PRIM_SIZE )
+    {
+      prim->len = D_LEN(ptr);
+      memcpy ((char*)P2D(prim), Buffer, (D_LEN(ptr)-sizeof(T_PRIM_HEADER)));
+    }
+    else
+    {
+      /*
+       * modify type to trace and send warning 
+       */ 
+      prim->opc = 0;
+      strcpy ((char*)P2D(prim), "Error: DirectDrvWrite -> Primitive to large to be transmitted");
+      prim->len = strlen((char*)P2D(prim)) + sizeof(T_PRIM_HEADER);
+    }
+  }
+  prim->sh_offset = S_HDR_OFFSET(prim->len);
+  s_hdr = (T_S_HEADER*)((ULONG*)prim + prim->sh_offset);
+  os_GetTime(TST_Handle,&s_hdr->time);
+  s_hdr->snd[0] = (char)caller;
+  if ( caller )
+    s_hdr->snd[0] |= (char)HANDLE_BIT;
+  if ( dest )
+    strcpy (s_hdr->rcv, dest);
+
+  if ( TST_DrvState == TST_DRV_CONNECTED )
+  {
+     if ( x_prim->prim_ptr != NULL )
+     {
+       /*lint -e419 suppress - Warning -- Apparent data overrun for function 'memcpy... */
+       memcpy ( ((char*)x_prim) + sizeof(T_PRIM_X), s_hdr, sizeof(T_S_HEADER) );
+       /*lint +e419 */
+       x_prim->p_hdr.sh_offset = sizeof(T_PRIM_X)>>2;
+       snd_ptr = (T_VOID_STRUCT*)x_prim;
+     }
+     else
+       snd_ptr = (T_VOID_STRUCT*)prim;
+     if ( vsi_d_write ( TST_Handle, TIF_Handle, (void*)snd_ptr, prim->len ) != VSI_OK )
+       return DRV_BUFFER_FULL;
+     else
+       return DRV_OK;
+  }
+  return DRV_OK;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++------------------------------------------------------------------------------
+|  Function     :  tst_mux_send
++------------------------------------------------------------------------------
+|  Description  :  send message via specified test interface channnel
+|
+|  Parameters   :  id     - channel ID
+|                  buffer - pointer to message
+|                  size   - message length 
+|
+|  Return       :  DRV_OK 
+|                  DRV_BUFFER_FULL
+|                  DRV_BUFFER_FULL
++------------------------------------------------------------------------------
+*/
+int tst_mux_send ( U8 id, void * buffer, int size )
+{
+int chan_id;
+int i;
+int snd_size;
+char *p_dst;
+char *p_src;
+ 
+  snd_size = size + 3;  /* 3 additional bytes for framing and chan id */
+  if ( size > MAX_TST_MUX_CMD_LEN-3)
+  {
+    return DRV_INVALID_PARAMS;
+  }
+
+  for ( chan_id = 0; chan_id < MAX_TST_CHANNEL; chan_id++ )
+  {
+    if ( tst_mux_chan_struct[chan_id].channel_id == id )
+    {
+      p_dst = (char*)tst_mux_chan_struct[chan_id].send_data;
+      p_src = (char*)buffer;
+      *p_dst++ = 0x02;
+      *p_dst++ = id;
+      for ( i = 0; i < size; i++ )
+      {
+        if ( *p_src == 0x10 || *p_src == 0x02 )
+        {
+          if ( snd_size < MAX_TST_MUX_CMD_LEN-1 )
+          {
+            *p_dst++ = 0x10;
+            snd_size++;
+          }
+        }
+        *p_dst++ = *p_src++;
+      }
+      *p_dst = 0x02;
+
+      if ( vsi_d_write ( 0, tst_mux_drv_handle, tst_mux_chan_struct[chan_id].send_data, snd_size) != VSI_OK )
+      {
+        return DRV_BUFFER_FULL;
+      }
+      return DRV_OK;
+    }
+  }
+  return DRV_INVALID_PARAMS;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++------------------------------------------------------------------------------
+|  Function     :  tst_mux_register
++------------------------------------------------------------------------------
+|  Description  :  register callback that is called if data is received on 
+|                  specified test interface channnel
+|
+|  Parameters   :  id       - channel ID
+|                  callback - callback function 
+|
+|  Return       :  DRV_OK 
+|                  DRV_INITFAILURE
++------------------------------------------------------------------------------
+*/
+int tst_mux_register ( U8 id, void (*callback)(void * buffer, int size))
+{
+int i;
+
+  for ( i = 0; i < MAX_TST_CHANNEL; i++ )
+  {
+    if ( tst_mux_chan_struct[i].channel_id == 0 )
+    {
+      tst_mux_chan_struct[i].channel_id = id;
+      tst_mux_chan_struct[i].rcv_callback   = callback;
+      MALLOC(tst_mux_chan_struct[i].send_data,MAX_TST_MUX_CMD_LEN);
+      return DRV_OK;
+    }
+  }
+  return DRV_INITFAILURE;
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++------------------------------------------------------------------------------
+|  Function     :  tst_mux_callback
++------------------------------------------------------------------------------
+|  Description  :  callback that is called if data is received on 
+|                  specified test interface channnel
+|
+|  Parameters   :  id       - channel ID
+|                  buffer   - data 
+|                  size     - number of received bytes
+|
+|  Return       :  DRV_OK 
+|                  DRV_INITFAILURE
++------------------------------------------------------------------------------
+*/
+void tst_mux_callback ( U8 id, void * buffer, int size )
+{
+  char * rcv_ptr;
+  char * dta_ptr;
+  char * p_rd;
+  char * p_wr;
+  int rd_bytes       = size;
+  int bytes_to_read  = size;
+  int total_wr_bytes = size;
+  int total_rd_bytes = 0;
+  int i;
+  int stuffed_byte = 0;
+  
+
+  MALLOC(rcv_ptr, size);
+  p_rd = rcv_ptr;
+  do
+  {
+    vsi_d_read ( 0, tst_mux_drv_handle, (void*)rcv_ptr, (ULONG*)&rd_bytes );
+    total_rd_bytes += rd_bytes;
+    if ( total_rd_bytes < bytes_to_read )
+    {
+      rcv_ptr += rd_bytes;
+      rd_bytes = bytes_to_read - total_rd_bytes;
+    }
+  } while ( total_rd_bytes < bytes_to_read );
+
+  
+  MALLOC(dta_ptr, size);
+  p_wr = dta_ptr;
+  for ( i = 0; i < size; i++ )
+  {
+    if ( stuffed_byte == 1 )
+    {
+      stuffed_byte = 0;
+      *p_wr++ = *p_rd++; 
+    }
+    if ( *p_rd == 0x10 )
+    {
+      stuffed_byte = 1;
+      p_rd++;
+      total_wr_bytes--;
+    }
+    else
+    {
+      *p_wr++ = *p_rd++; 
+    }
+  }
+  MFREE(rcv_ptr);
+
+  if ( tst_mux_chan_struct[id].rcv_callback != NULL )
+  {
+    (tst_mux_chan_struct[id].rcv_callback)(dta_ptr,total_wr_bytes); 
+  }
+  MFREE(dta_ptr);
+
+}
+#endif
+
+#ifndef RUN_INT_RAM
+/*
++------------------------------------------------------------------------------
+|  Function     :  tst_mux_init
++------------------------------------------------------------------------------
+|  Description  :  register callback that is called if data is received on 
+|                  specified test interface channnel
+|
+|  Parameters   :  id       - channel ID
+|                  callback - callback function 
+|
+|  Return       :  DRV_OK 
+|                  DRV_INITFAILURE
++------------------------------------------------------------------------------
+*/
+int tst_mux_init ( void )
+{
+int i;
+
+  if ( (tst_mux_drv_handle = vsi_d_open ( TST_Handle, (char*)TR_NAME )) == VSI_ERROR )
+  {
+    return DRV_INITFAILURE;
+  }
+  for ( i = 0; i < MAX_TST_CHANNEL; i++ )
+  {
+    tst_mux_chan_struct[i].channel_id = 0;
+    tst_mux_chan_struct[i].rcv_callback   = NULL;
+    tst_mux_chan_struct[i].rcv_data_ptr   = NULL;
+    tst_mux_chan_struct[i].rcv_data_size  = 0;
+  }
+  return DRV_OK;
+}
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/gpf/tst_pei/tstdriver.h	Sun Apr 13 07:21:57 2014 +0000
@@ -0,0 +1,41 @@
+/* 
++------------------------------------------------------------------------------
+|  File:       tstdriver.h
++------------------------------------------------------------------------------
+|  Copyright 2002 Texas Instruments Berlin, AG 
+|                 All rights reserved. 
+| 
+|                 This file is confidential and a trade secret of Texas 
+|                 Instruments Berlin, 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 
+|                 Texas Instruments Berlin, AG. 
++----------------------------------------------------------------------------- 
+|  Purpose :  Prototypes for direct driver access.
++----------------------------------------------------------------------------- 
+*/ 
+
+#ifndef TSTDRIVER_H
+#define TSTDRIVER_H
+
+/*==== INCLUDES =============================================================*/
+
+#include "typedefs.h"
+#include "vsi.h"
+
+/*==== CONSTS ===============================================================*/
+
+#define TST_DRV_CONNECTED    0x01
+#define TST_DRV_DISCONNECTED 0x02
+
+/*==== TYPES ================================================================*/
+
+
+/*==== EXPORTS ==============================================================*/
+
+SHORT tst_drv_write ( T_HANDLE caller, ULONG opc, char *dest, char *Buffer );
+
+
+#endif /* TSTDRIVER_H */