diff options
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/gpxe/tcp.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/include/gpxe/tcp.h b/src/include/gpxe/tcp.h index fb0c89a7e..cc7d666c2 100644 --- a/src/include/gpxe/tcp.h +++ b/src/include/gpxe/tcp.h @@ -11,6 +11,8 @@ #include <stddef.h> #include <gpxe/in.h> +#include <gpxe/list.h> +#include <gpxe/pkbuff.h> struct tcp_connection; @@ -87,6 +89,8 @@ struct tcp_operations { size_t len ); }; +#if USE_UIP + /** * A TCP connection * @@ -104,4 +108,106 @@ extern void tcp_send ( struct tcp_connection *conn, const void *data, extern void tcp_kick ( struct tcp_connection *conn ); extern void tcp_close ( struct tcp_connection *conn ); +#else + +#define TCP_NOMSG "" +#define TCP_NOMSG_LEN 0 + +/* Smallest port number on which a TCP connection can listen */ +#define TCP_MIN_PORT 1 + +/* Some PKB constants */ +#define MAX_HDR_LEN 100 +#define MAX_PKB_LEN 1500 +#define MIN_PKB_LEN MAX_HDR_LEN + 100 /* To account for padding by LL */ + +/** + * TCP states + */ +#define TCP_CLOSED 0 +#define TCP_LISTEN 1 +#define TCP_SYN_SENT 2 +#define TCP_SYN_RCVD 3 +#define TCP_ESTABLISHED 4 +#define TCP_FIN_WAIT_1 5 +#define TCP_FIN_WAIT_2 6 +#define TCP_CLOSING 7 +#define TCP_TIME_WAIT 8 +#define TCP_CLOSE_WAIT 9 +#define TCP_LAST_ACK 10 + +#define TCP_INVALID 11 + +/** + * A TCP connection + */ +struct tcp_connection { + struct sockaddr sa; /* Remote socket address */ + struct sockaddr_in sin; /* Internet socket address */ + uint16_t local_port; /* Local port, in network byte order */ + int tcp_state; /* TCP state */ + int tcp_lstate; /* Last TCP state */ + uint32_t snd_una; /* Lowest unacked byte on snd stream */ + uint32_t snd_win; /* Offered by remote end */ + uint32_t rcv_nxt; /* Next expected byte on rcv stream */ + uint32_t rcv_win; /* Advertised to receiver */ + uint8_t tcp_flags; /* TCP header flags */ + struct list_head list; /* List of TCP connections */ + struct pk_buff *tx_pkb; /* Transmit packet buffer */ + struct tcp_operations *tcp_op; /* Operations table for connection */ +}; + +/** + * Connection closed status codes + */ +#define CONN_SNDCLOSE 0 +#define CONN_RESTART 1 +#define CONN_TIMEOUT 2 +#define CONN_RCVCLOSE 3 + +/** + * A TCP header + */ +struct tcp_header { + uint16_t src; /* Source port */ + uint16_t dest; /* Destination port */ + uint32_t seq; /* Sequence number */ + uint32_t ack; /* Acknowledgement number */ + uint8_t hlen; /* Header length (4), Reserved (4) */ + uint8_t flags; /* Reserved (2), Flags (6) */ + uint16_t win; /* Advertised window */ + uint16_t csum; /* Checksum */ + uint16_t urg; /* Urgent pointer */ +}; + +/** + * TCP masks + */ +#define TCP_MASK_HLEN 0xf0 +#define TCP_MASK_FLAGS 0x3f + +/** + * TCP flags + */ +#define TCP_RST 0x20 +#define TCP_ACK 0x10 +#define TCP_PSH 0x08 +#define TCP_URG 0x04 +#define TCP_SYN 0x02 +#define TCP_FIN 0x01 + +extern struct tcpip_protocol tcp_protocol; + +extern void tcp_init_conn ( struct tcp_connection *conn ); +extern int tcp_connect ( struct tcp_connection *conn ); +extern int tcp_connectto ( struct tcp_connection *conn, struct sockaddr *peer ); +extern int tcp_listen ( struct tcp_connection *conn, uint16_t port ); +extern int tcp_senddata ( struct tcp_connection *conn ); +extern int tcp_close ( struct tcp_connection *conn ); + +extern int tcp_send ( struct tcp_connection *conn, const void *data, + size_t len ); + +#endif /* USE_UIP */ + #endif /* _GPXE_TCP_H */ |
