📄 socket.h
字号:
/**
* \addtogroup t4socket T4 Socket API Layer
* @{
*/
/**
* \addtogroup sockch Socket Channel Configuration and API Functions
* @{
*/
/**
* \file Socket.h
* \brief The T4 Socket API Layer Header File.
* \author Xiaofei Rui <xfrui@fameg.com>
*/
/*
******************************************************************************
*
Copyright (c) 2006 FameG Shanghai, Inc. All rights reserved.
*
This is unpublished proprietary source code of FameG Shanghai, Inc.
*
The copyright notice above does not evidence any actual or intended
*
publication of such source code.
******************************************************************************
*/
/*
******************************************************************************
*
Project: T4 Hardware TCP/IP
*
Filename: socket.h
*
Date: 28/02/06
*
Purpose: IP Layer Function Declaration
*
Author: Xiaofei Rui
******************************************************************************
*/
#ifndef __SOCKET_H__
#define __SOCKET_H__
//#include "arch/system.h"
#include "kernel/ip.h"
/*****************************************************************************
* CONSTANT DEFINES *
*****************************************************************************/
/// @cond DOXYGEN_SKIP
#define SOCK_STREAM 1
#define SOCK_DGRAM 0
#define SERVER 1
#define CLIENT 0
/// @endcond
#if 0
#define FG_MAC_TCIA 0x01 /**< Enable MAC transmit complete interrupt assert
*\hideinitializer*/
#define FG_PKT_8023 0x02 /**< Packet encapsulated in IEEE 802.3 packet
* \hideinitializer */
#define FG_PKT_TAG 0x04 /**< A Qtag header is inserted into the sent packet
* \hideinitializer */
#define FG_PKT_PPPOE 0x08 /**< A PPPOE header is inserted into the sent packet
* \hideinitializer */
#define FG_CH_TCIA 0x10 /**< Enable channel transmit complete interrupt assert
* \hideinitializer */
#define FG_IP_LBK 0x20 /**< Enable IP loopback, the destination IP is 127.0.0.1
*\hideinitializer */
#endif
/**
* TCP State Definition
*/
#define TCP_STATE_CLOSED 0x00
#define TCP_STATE_OPENED 0x01
#define TCP_STATE_LISTEN 0x02
#define TCP_STATE_SYNCSENT 0x03
#define TCP_STATE_SYNCRECEIVE 0x04
#define TCP_STATE_EST 0x05
#define TCP_STATE_FINISHWAIT1 0x06
#define TCP_STATE_FINISHWAIT2 0x07
#define TCP_STATE_CLOSING 0x08
#define TCP_STATE_TIMEWAIT 0x09
#define TCP_STATE_CLOSEWAIT 0x0a
#define TCP_STATE_LASTACK 0x0b
/*****************************************************************************
* MACROS *
*****************************************************************************/
//#define TCP_STATUS(ch) (inb(SOCK_TCPSMS1(ch))&CUR_TCPST_MASK)
#define CH_STATUS(ch) inb(SOCK_CHCTRL0(ch))
#define TCP_COMMAND(ch, v) outb(v, SOCK_TCPCMD(ch))
/*****************************************************************************
* DATA TYPES *
*****************************************************************************/
/**
* A socket structure to store Socket pair information.
*/
struct socket_t
{
UINT8 chen; /**< Channel Enable */
UINT8 type; /**< SOCK_STREAM or SOCK_DGRAM */
UINT8 mode; /**< CLIENT or SERVER */
union ip_addr_u srcip; /**< Source IP address */
UINT16 srcport; /**< Source Port */
union ip_addr_u destip; /**< Destination IP address */
UINT16 destport; /**< Destination Port */
UINT8 grpvalid; /**< Join a multicast group or not */
UINT8 grpid; /**< Multicast group ID joined to */
UINT16 destmss; /**< Peer's Max Segment Size(MSS) */
//UINT8 flag; /**< Socket flag, see socket() */
#if IP_REASSEMBLY
UINT8 recvfrag; /**< Receive a fragmented packet or not */
#endif /* IP_REASSEMBLY */
#if IPOPTION
UINT8 optvalid; /**< Have IP option or not */
UINT8 optlen; /**< IP option length */
UINT8 XDATA *optptr; /**< A pointer to IP option data */
#endif /* IPOPTION */
#if URGENT
UINT8 urgvalid; /**< TCP has urgent data or not. */
UINT16 urglen; /**< Urgent data length */
UINT8 XDATA *urgptr; /**< A pointer to TCP urgent data */
#endif /* URGENT */
};
//#if TCP_KEEPALIVE_ENABLE
struct keep_alive_timer_t
{
//attributions
BOOL connected; /* TCP connection establish or not */
BOOL breakbyme; /* Connection break by keep-alive-timer or not */
UINT8 timer; /* timer handle */
//Operations
INT8 (* Check)(UINT8 ch); /* Call for socket API */
void (* Restart)(UINT8 ch); /* Call for socket API, if active, restart the timer */
void (* Reset)(UINT8 ch); /* Call for socket API, if reinitial socket, reset the timer */
};
//#endif
/*****************************************************************************
* FUNCTIONS DECLARATION *
*****************************************************************************/
/* socket attribution setting function */
extern void sock_CH_Reset(UINT8 ch);
extern void sock_UDP_Filter(UINT8 ch, UINT32 ipaddr, UINT16 rport,UINT8 acceptip);
extern void sock_UDP_TxAbort(UINT8 ch);
extern void sock_UDP_JoinGrp(UINT8 ch, UINT32 grpip);
extern void sock_TCP_RetranCtrl(UINT8 ch, UINT8 initval, BOOL infinity, BOOL fastretran);
extern void sock_TCP_SetR1R2(UINT8 ch, UINT8 r1, UINT8 r2);
extern void sock_TCP_DACKCtrl(UINT8 ch, BOOL enable, UINT8 timer);
extern void sock_TCP_PersisTimer(UINT8 ch, UINT8 initval);
extern void sock_TCP_2MSL(UINT8 ch, UINT8 life);
//extern void sock_TCP_SetSeqNo(UINT8 ch, UINT32 seqno);
extern void sock_TCP_SetMSS(UINT8 ch, UINT16 mss);
extern UINT16 sock_TCP_GetRMSS(UINT8 ch);
extern UINT8 sock_TCP_GetState(UINT8 ch);
extern void sock_TCP_SetWin(UINT8 ch, UINT16 win);
//void sock_CH_Ctrl(UINT8 ch);
extern void sock_TCP_DestSocket(UINT8 ch, UINT32 ipaddr, UINT16 rport);
extern void sock_Init(void);
extern void sock_release(UINT8 ch);
//void sock_Int_Init(UINT8 ch);
extern void sock_SetTOS(UINT8 ch, UINT8 tosval);
extern void sock_SetTTL(UINT8 ch, UINT8 ttlval);
#if IPOPTION
extern void sock_SetIPOpt(UINT8 ch, UINT8 len, UINT8 *optbuf);
#endif /* IPOPTION */
#if URGENT
extern void sock_SetUrgent(UINT8 ch, UINT16 len, UINT8 *urgbuf);
#endif /* URGENT */
/* socket API call */
//INT8 socket(UINT8 ch, UINT8 type, UINT8 flag); //flag--UDP/TCP different
extern INT8 socket(UINT8 ch, UINT8 type); //flag--UDP/TCP different
extern INT8 connect(UINT8 ch, UINT32 XDATA * dip, UINT16 dport);
extern INT8 bind(UINT8 ch, UINT16 srcport);
extern INT8 listen(UINT8 ch);
extern void close(UINT8 ch);
extern void disconnect(UINT8 ch);
extern void reset(UINT8 ch);
//INT16 write_to_fifo(UINT8 ch, struct tx_descriptor_t XDATA *txd, const void *buf, UINT16 len);
//INT16 read_from_fifo(UINT8 ch, struct rx_descriptor_t XDATA *rxd, void *buf, UINT16 len);
extern INT16 send(UINT8 ch, const void *buf, UINT16 len);//, UINT8 flag);
extern INT16 recv(UINT8 ch, void *buf, UINT16 len);
extern INT16 sendto(UINT8 ch, const void *buf, UINT16 len, UINT32 XDATA * dip, UINT16 dport);//, UINT8 flag);
extern INT16 recvfrom(UINT8 ch, void *buf, UINT16 len, UINT32 XDATA * dip, UINT16 XDATA *sport);
extern void sock_sendTcpRst(UINT8 *rxbuf, UINT8 *txbuf, UINT16 len);
/* Interrupt handler */
extern void sock_Int_handler(UINT8 ch);
//#if TCP_KEEPALIVE_ENABLE
//void Init_KeepAlive(UINT8 ch);
//INT8 pri_kal_check(UINT8 ch);
//void pri_kal_restart(UINT8 ch);
//void pri_kal_reset(UINT8 ch);
//#endif
extern UINT16 getanyport(void);
extern UINT8 getanych(void);
/*****************************************************************************
* GLOBAL VARIABLES DECLARATION *
*****************************************************************************/
extern struct socket_t sock[4];
#endif /* __SOCKET_H__ */
/** @} */
/** @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -