/****************************************************************************
*
* (C) 2000 by BECK IPC GmbH
*
*  BECK IPC GmbH
*  Garbenheimerstr. 38
*  D-35578 Wetzlar
*
*  Phone : (49)-6441-905-240
*  Fax   : (49)-6441-905-245
*
* ---------------------------------------------------------------------------
* Module         : IPC@Chip SC12 API: tcpip.h
*
* Function       : prototypes, constants for TCPIP API functions
*                  Functions must be used with program memory model large!
*
* Author        : bartat
* Date          : 22.01.00
* ---------------------------------------------------------------------------

$Header: TCPIP.H, 23, 07.05.2002 14:50:51, Markus Bartat$


  $Log:
   23   IPC@CHIP  1.22        07.05.2002 14:50:51  Markus Bartat   added
        C-function for TCPAPI call 0x22 Get_tcp-socket_state
   22   IPC@CHIP  1.21        01.03.2002 18:49:25  Markus Bartat   added functions
        for API calls 0x45,0x44,0x55
   21   IPC@CHIP  1.20        26.02.2002 18:45:52  Christoph Stoidner Add
        PPPSetPPPOption
   20   IPC@CHIP  1.19        30.01.2002 12:52:07  Markus Bartat   added extendend
        dhcp_stat function 0x73
   19   IPC@CHIP  1.18        23.01.2002 16:40:46  Christoph Stoidner delete
        unused timeout variable
   18   IPC@CHIP  1.17        16.01.2002 11:45:07  Christoph Stoidner add starteam
        directives
   17   IPC@CHIP  1.16        14.01.2002 13:33:37  Christoph Stoidner add new
        functions (Set/get Idle timeout: 0x79)
   16   IPC@CHIP  1.15        14.01.2002 13:19:05  Christoph Stoidner add new
        functions
   15   IPC@CHIP  1.14        14.12.2001 11:55:08  Markus Bartat   Added C
        functions and define for TCPIP API calls 0x90-0x92
   14   IPC@CHIP  1.13        17.09.2001 12:40:22  Markus Bartat   added tcpip api
        call 0x67
   13   IPC@CHIP  1.12        21.06.2001 13:53:31  Markus Bartat   added tcpip api
        call 0x19
   12   IPC@CHIP  1.11        19.06.2001 13:35:09  Markus Bartat   start: Added
        comments to the c functions
   11   IPC@CHIP  1.10        01.06.2001 12:20:28  Markus Bartat   added new
        functions
   10   IPC@CHIP  1.9         31.05.2001 16:19:04  Christoph Stoidner
   9    IPC@CHIP  1.8         31.05.2001 14:27:47  Christoph Stoidner
   8    IPC@CHIP  1.7         29.05.2001 16:04:20  Markus Bartat   added aPI call
        0x60 Get access to internal snmp variables
   7    IPC@CHIP  1.6         15.05.2001 11:20:48  Markus Bartat   überarbeitet
        von Ali Senol
   6    IPC@CHIP  1.5         14.03.2001 16:56:22  Christoph Stoidner
   5    IPC@CHIP  1.4         14.03.2001 16:55:10  Christoph Stoidner convert
        datatypes to prevent compiler warnings
   4    IPC@CHIP  1.3         14.03.2001 16:52:43  Christoph Stoidner
   3    IPC@CHIP  1.2         08.03.2001 11:33:19  Ernest Schlösser Added a
        tcp_connect function to create a socket and connect to a server
   2    IPC@CHIP  1.1         15.02.2001 15:09:10  Christoph Stoidner
   1    IPC@CHIP  1.0         14.02.2001 16:09:59  Christoph Stoidner
  $

* History       :
*
*  Vx.yy                   Author  Changes
*
*             22.01.00      mb    Create
*             28.01.00      mb     add tcp API calls
*             26.06.00      mb     add ppp server API calls
*             14.07.00      mb     add reconfig, dhcp  and ip setting API calls
*             18.07.00      mb     add TCPIP statistics
*             24.08.00      mb     add PPP client API calls
*             06.09.00      mb     add set and getsockopt calls
              15.09.00      mb     add ping api calls
              07.11.00      mb     add memory information call
              08.12.00      mb     add routing calls
              22.12.00      mb     add blocking mode call for sockets
              30.05.01      mb     add API_SNMP_GET function
              01.06.01      mb     add telnet and ftp login functions
              20.06.01      mb     add register callback function
              10.12.01      mb     add IGMP functions calls for API calls 0x90-0x92
              30.01.02      mb     add dhcp_stat_ext function (requires BIOS 1.03B or higher)
              25.02.02      mb/cs  added new function PPP_GET_DNSIP 0x44 and pppsetoptions 0x45,0x55
              07.05.02      mb     added TCP API function 0x22, get state of tcp socket
************************************************************************************/
#ifndef __TCPIP_H__
#define __TCPIP_H__
/*************************************************************************/
#include "CLIB/TCPIPAPI.H"

/*************************************************************************/
#define TCPIPVECT  0xAC

#ifdef _MSC_VER /* If Microsoft C Compiler is used, define new FP_SEG and FP_OFF Macro */
	#ifdef FP_SEG
  		#undef FP_SEG
	#endif
	#define FP_SEG(ptr)    ((unsigned int)(((unsigned long)ptr)>>16))

	#ifdef FP_OFF
  		#undef FP_OFF
	#endif
	#define FP_OFF(ptr)    ((unsigned int)(((unsigned long)ptr)&0xFFFF))
#endif

/*************************************************************************/
//prototypes
/*************************************************************************/


/*****************************************************************************
*
*	open a tcp connection
*
*	DestIPStr: destionation IP address format xxx.xxx.xxx.xxx
*	ClientPort: local port (0=random port)
*	HostPort: remote port
*	error: TCP/IP error
*
*	return: socket descriptor (-1 = error)
*  close connection using closesocket()
******************************************************************************/
int tcp_connect(char *DestIPStr, unsigned int ClientPort, unsigned int HostPort, int *error);


int accept(int sd, struct sockaddr * addressPtr, int *error);

void api_sleep(unsigned int howlong);

int bind(int sd, struct sockaddr * addressPtr, int *error);

int connect(int sd, struct sockaddr * addressPtr, int *error);

int closesocket(int sd, int *error);

int GetWaitingBytes(int sd, int *error);

unsigned int htons(unsigned int value);

int listen(int sd,int backlog, int *error);

int inet_addr(char * IPAddressStringPtr, unsigned long * IPAddress);

int InetToAscii(unsigned long * IPAddress, char * IPAddressStringPtr);

int recvfrom(int sd, char * bufptr, int bufLen, int flags,
				 unsigned long timeout,struct sockaddr * fromPtr, int *error);

int recv(int sd, char * bufptr, int bufLen, int flags, unsigned long timeout,
			int *error);

int ResetConnection(int sd, int *error);

int sendto(int sd, char * bufptr, int bufLen, int flags,
			  const struct sockaddr * toPtr, int *error);

int send(int sd, char * bufptr, int bufLen, int flags, int *error);

int setlinger(int sd, int seconds, int *error);

int setreuse(int sd,int *error);

int Set_IP_Type_Of_Service(int sd, unsigned char TOS, int *error);

int opensocket(unsigned char type, int *error);

int setsockopt(int sd, SetSocketOption *sockoptptr, int *error);

int getsockopt(int sd, GetSocketOption *sockoptptr, int *error);

int Set_Blocking_Mode(int sd, unsigned char mode, int *error);

int RegisterCallbackFunction(int sd, void * funcptr, int eventflagmask ,int *error);

int GetRegisterCallbackFunction(int sd, void * funcptr, int eventflagmask ,int *error);

int get_socketerror(int sd);

unsigned char Get_TCP_Socket_State(unsigned int localPort, unsigned long * remoteIP, unsigned int * remotePort);



//ppp client prototypes
int PPP_Client_Installed(void);
int PPP_Client_Open(PPPClient_Init * ptr, int *error);
int PPP_Client_Close(int *error);
int PPP_Client_GetStatus(int *error);
int PPP_Client_SetOptions(PPP_Option *ptr);
int PPP_Client_Get_DNSIP(unsigned long * IPaddress, int primary_sec, int *error);



//ppp server prototypes
int PPP_Server_Installed(void);
int PPP_Server_Suspend(int timeoutsecs, int *error);
int PPP_Server_Activate(int timeoutsecs,int *error);
int PPP_Server_GetStatus(void);
int PPP_Server_Get_Cfg(PPP_IPCfg_Data *ptr , int *error);
int PPP_Server_SetOptions(PPP_Option *ptr);

//Get pointer to internal TCIP SNMP mib structures
int Get_SNMP_Data(unsigned char which , void * * snmp_mib_ptr);

//Login counter
int Get_FTP_Login_Counters(unsigned long * * FTP_Login_Count,unsigned long * * FTP_Login_failCount);
int Get_Telnet_Login_Counters(unsigned long * * Telnet_Login_Count,unsigned long * * Telnet_Login_failCount);

//telnet state
int Get_Telnet_State(int *error);

//system
void Get_Installed_Servers(unsigned int * AX, unsigned int *DX);
int  Reconfigure_ethernet(void);
int  DHCP_use(unsigned char dhcp_use);
void Get_DHCP_Status(unsigned int * dhcp_use, unsigned int *dhcp_stat);
void Get_DHCP_Status_Ext(unsigned int * dhcp_use, unsigned int *dhcp_stat, UserEthDhcp_Entry * * dhcpptr);

void Get_IPConfig(char *IP, char * Mask, char *Gateway);
void Set_IPConfig(char *IP, char * Mask, char *Gateway);
void Get_TCPIP_Statistics(Packet_Count * * Packet_Count_Pointer);
int  Set_FTPServer_Idle_Timeout( unsigned timeout );
int  Set_TelnetServer_Idle_Timeout( unsigned timeout );
unsigned Get_FTPServer_Idle_Timeout(void);
unsigned Get_TelnetServer_Idle_Timeout(void);

//ping api
int Ping_Open(Ping * pingptr, int * errorcode);
int Ping_Close(int sd);
int Ping_Statistics(Ping * pingptr);

//memory
void Get_TCPIP_Memory_Status(unsigned long * total, unsigned long * used);

//route
int  AddDefaultGateway( int interface , unsigned long * Gateway, int * errorcode);
int  DelDefaultGateway(unsigned long * Gateway, int * errorcode);
int  GetDefaultGateway(unsigned long * Gateway, int * errorcode);
int  AddStaticRoute(int interface, Route_Entry * route, int * errorcode);
int  DelStaticRoute(int interface, Route_Entry * route, int * errorcode);

//IGMP
int  Add_IGMP_Membership(unsigned long * MulticastIP, unsigned char * MacAddress, int * errorcode);
int  Drop_IGMP_Membership(unsigned long * MulticastIP, int * errorcode);
int  IPMulticast_to_MacAddr(unsigned long * MulticastIP, unsigned char * MacAddress, int * errorcode);

/*************************************************************************/
#endif /* __TCPIP_H__*/
/*************************************************************************/
//end tcpip.h
/*************************************************************************/
