📄 wap_udpf.c
字号:
/*
+-----------------------------------------------------------------------------
| File : wap_udpf.c
+-----------------------------------------------------------------------------
| Copyright Condat AG 1999-2000, Berlin
| All rights reserved.
|
| This file is confidential and a trade secret of Condat AG
| The receipt of or possession of this file does not convey
| any rights to reproduce or disclose its contents or to
| manufacture, use, or sell anything it may describe, in
| whole, or in part, without the specific written consent of
| Condat AG.
+-----------------------------------------------------------------------------
| Purpose : This Modul defines functions for the UDP interface of the
| entity wap
+-----------------------------------------------------------------------------
*/
#ifndef WAP_UDPF_C
#define WAP_UDPF_C
#endif
#define ENTITY_WAP
/*==== INCLUDES ===================================================*/
#if defined (NEW_FRAME)
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include "typedefs.h"
#include "pcm.h"
#include "pconst.cdg"
#include "mconst.cdg"
#include "message.h"
#include "ccdapi.h"
#include "vsi.h"
#include "custom.h"
#include "gsm.h"
#include "prim.h"
#include "cnf_wap.h"
#include "mon_wap.h"
#include "pei.h"
#include "tok.h"
#include "dti.h" /* functionality of the dti library */
#else
#include <string.h>
#include <stdlib.h>
#include "stddefs.h"
#include "pconst.cdg"
#include "message.h"
#include "ccdapi.h"
#include "custom.h"
#include "gsm.h"
#include "cnf_wap.h"
#include "mon_wap.h"
#include "prim.h"
#include "vsi.h"
#include "pei.h"
#include "tok.h"
#endif
/*XXX check XXX*/
#include "wap.h"
#include "Cus_wap.h"
#include "capiclnt.h"
#include "aapiudp.h"
#include "capiudp.h"
/**** ***/
/*==== CONST =======================================================*/
/*==== TYPES =======================================================*/
/*==== VAR EXPORT ==================================================*/
/*==== VAR LOCAL ===================================================*/
/*==== FUNCTIONS ===================================================*/
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_init |
+--------------------------------------------------------------------+
PURPOSE : initialize variables
*/
GLOBAL const void udp_init ()
{
int i;
TRACE_EVENT ("udp_init()");
for (i = 0; i < WAP_MAX_PORTS; i++)
wap_data->ports[i].state = WAP_PORT_IDLE;
wap_data->state[0] = 0;
wap_data->flow = FALSE;
wap_data->connection_done = FALSE;
wap_data->aus_runnable = TRUE;
wap_data->Tui = 0;
wap_data->last_bind_req = -1;
wap_data->dti_state = DTI_CLOSED;
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_send_ready |
+--------------------------------------------------------------------+
PURPOSE : send DTI_GETDATA_REQ to UDP
*/
GLOBAL const void udp_send_ready()
{
TRACE_EVENT("udp_send_ready()");
dti_start
(
wap_hDTI,
WAP_DTI_DN_DEF_INSTANCE,
WAP_DTI_DN_INTERFACE,
WAP_DTI_DN_CHANNEL
);
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_close_port_req |
+--------------------------------------------------------------------+
PURPOSE : called by wap-lib...
*/
GLOBAL void udp_close_port_req(
UBYTE id
)
{
int i;
TRACE_FUNCTION("udp_close_port_req()");
/* find matching entry in wap_data-ports */
for (i = 0; i < WAP_MAX_PORTS; i++)
{
if (wap_data->ports[i].id == id)
{
if (wap_data->ports[i].state == WAP_PORT_BOUND)
{
PALLOC(udp_closeport_req, UDP_CLOSEPORT_REQ);
udp_closeport_req->port = wap_data->ports[i].port;
wap_data->ports[i].state = WAP_PORT_WAIT_CLOSE_CNF;
PSENDX(UDP, udp_closeport_req)
}
break;
}
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_bind_req |
+--------------------------------------------------------------------+
PURPOSE : called by wap-lib...
*/
GLOBAL void udp_bind_req(
UBYTE id,
UBYTE channel
)
{
int i;
TRACE_EVENT("udp_bind_req()");
/* find an idle entry in wap_data->ports */
for (i = 0; i < WAP_MAX_PORTS; i++)
{
if (wap_data->ports[i].state EQ WAP_PORT_IDLE)
{
wap_data->ports[i].state = WAP_PORT_WAIT_BIND_CNF;
wap_data->ports[i].port = wap_data->port1;
wap_data->ports[i].id = id;
wap_data->ports[i].channel = channel;
wap_data->last_bind_req = i;
{
PALLOC(udp_bind_req, UDP_BIND_REQ);
udp_bind_req->port = wap_data->port1;
PSENDX(UDP,udp_bind_req);
}
return;
}
}
/*
* table is full
*/
TRACE_ERROR("WAP_MAX_PORTS exceeded");
wap_lib_bind_callback(id,channel, 0, 255); /*XXX change this XXX*/
return;
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_conv_str_to_IP |
+--------------------------------------------------------------------+
PURPOSE :
*/
GLOBAL const void udp_conv_str_to_IP(
const char* str,
UBYTE* ip
)
{
int i;
*ip = 0;
for (i=3;i>=0;i--)
{
ip[i] = (UBYTE)(*str);
str++;
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_conv_IP_to_str |
+--------------------------------------------------------------------+
PURPOSE :
*/
GLOBAL const void udp_conv_IP_to_str(
UBYTE* ip,
char* buf
)
{
int i;
for (i=3;i>=0;i--)
{
buf[i] = (char)(*ip);
ip++;
}
}
#if 0
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_conv_bin_to_hex |
+--------------------------------------------------------------------+
PURPOSE : convert binary array into a hexadecimal acscii respresentation
*/
BYTE hex_tab[] = {'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
'c', 'd', 'e','f'};
GLOBAL const void udp_conv_bin_to_hex(
T_desc2 *in,
T_desc2 **out
)
{
ULONG i,j;
/*
* alloc mem for out 2*in->len 'cause hex representation of a byte takes
* two chars
*/
*out = (T_desc2*)MALLOC ((USHORT)(sizeof(T_desc2) - 1 + (2*in->len)));
(*out)->next = 0;
(*out)->offset = 0;
(*out)->len = (USHORT) (2 * in->len);
(*out)->size = (USHORT) (2 * in->len);
for (i=0, j=0; i < in->len; i++) {
(*out)->buffer[j++] = hex_tab[(in->buffer[i] & 0xf0) >> 4];
(*out)->buffer[j++] = hex_tab[(in->buffer[i] & 0xf)];
}
}
/*
+--------------------------------------------------------------------+
| PROJECT : GSM-WAP (8444) MODULE : WAP_UDPF |
| STATE : code ROUTINE : udp_conv_hex_to_bin |
+--------------------------------------------------------------------+
PURPOSE : convert hexadecimal acscii array into byte reperenstation
*/
GLOBAL const void udp_conv_hex_to_bin (
T_desc2 *in,
T_desc2 **out
)
{
ULONG i,j;
BYTE high, low;
/*
* alloc mem for out (in->len)/2 'cause hex reperenstation of a byte takes
* two chars
*/
*out = (T_desc2*)MALLOC ((USHORT)(sizeof(T_desc2) - 1 + (in->len/2)));
(*out)->next = 0;
(*out)->offset = 0;
(*out)->len = (USHORT) (in->len / 2);
(*out)->size = (USHORT) (in->len / 2);
for (i=0, j=0; j < (*out)->len; j++) {
high = in->buffer[i++];
low = in->buffer[i++];
(*out)->buffer[j] = ((high <= '9')?high-'0':high-'a'+0x0a)<<4;
(*out)->buffer[j] += ((low <= '9')?low-'0':low-'a'+0x0a);
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -