#include "nip_init.h"
#include "mem.h"
Go to the source code of this file.
Data Structures | |
struct | nip_tcp_sock_addr |
struct | nip_tcp_sock |
struct | nip_tcb |
Transmission Control Block, any TCP connection has to have one. More... | |
struct | nip_tcp_header |
Defines | |
#define | NIP_TCP_MAX_SOCKETS 2 |
Define maximum number of TCP sockets for static socket array. | |
#define | NIP_TCP_MAX_CONNECTIONS 5 |
Define maximum number of TCP sockets for dynamic connection array. | |
#define | NIP_TCP_MAX_UNACCEPTED 5 |
Define maximum number of unaccepted TCP connections. | |
#define | NIP_TCP_DEFAULT_RCV_WND 150 |
Default Receive Window Size. | |
#define | NIP_TCP_MSL 120 |
maximum segment lifetime | |
#define | NIP_TCP_RTO_UBOUND 60 |
Upper bound on retransmission timeout (RTO). | |
#define | NIP_TCP_RTO_LBOUND 1 |
Lower bound on retransmission timeout (RTO). | |
#define | NIP_TCP_RTO_ALPHA 1 |
Smoothing factor for round-trip-time. | |
#define | NIP_TCP_RTO_ALPHA_NEG 0 |
#define | NIP_TCP_RTO_BETA 2 |
Delay variance factor for RTO. | |
#define | NIP_TCP_NO_SOCKET 0xFF |
#define | NIP_TCP_SOCK_FLG_USED 0x01 |
set to mark socket as used | |
#define | NIP_TCP_SOCK_FLG_NON_BLOCK 0x02 |
set to mark non-blocking socket | |
#define | NIP_TCP_SOCK_FLG_LISTENING 0x04 |
wait for incoming connections? | |
#define | NIP_TCP_SOCK_FLG_ACCEPTED 0x08 |
user accepted connection | |
#define | NIP_TCP_SOCK_FLG_RECV 0x10 |
socket ready to receive | |
#define | NIP_TCP_SOCK_FLG_SEND 0x20 |
socket ready to send | |
#define | NIP_TCP_SOCK_FLG_SHUT_WR 0x40 |
quit writing data on socket | |
#define | NIP_TCP_SOCK_FLG_SHUT_RD 0x80 |
quit receiving data on socket | |
#define | NIP_TCP_SOCK_FLG_AUTOCLOSE (NIP_TCP_SOCK_FLG_SHUT_WR|NIP_TCP_SOCK_FLG_SHUT_RD) |
#define | NIP_TCP_MIN_HEADER_SIZE 20 |
minimum size of TCP header | |
#define | NIP_TCP_MIN_DATA_OFFSET 0x50 |
#define | NIP_TCP_RESET_ACK 0xFFFFFFFF |
#define | NIP_TCP_SHUT_RD NIP_TCP_SOCK_FLG_SHUT_RD |
shut down packet receival | |
#define | NIP_TCP_SHUT_WR NIP_TCP_SOCK_FLG_SHUT_WR |
shut down packet sending | |
#define | NIP_TCP_SHUT_RDWR (NIP_TCP_SHUT_RD|NIP_TCP_SHUT_WR) |
#define | NIP_TCP_FIN_FLAG 0x01 |
#define | NIP_TCP_SYN_FLAG 0x02 |
#define | NIP_TCP_RST_FLAG 0x04 |
#define | NIP_TCP_PSH_FLAG 0x08 |
#define | NIP_TCP_ACK_FLAG 0x10 |
#define | NIP_TCP_URG_FLAG 0x20 |
Typedefs | |
typedef uint8_t | nip_tcp_sock_id_t |
typedef uint8_t | nip_tcp_sock_cnt_t |
typedef enum nip_tcp_stat | nip_tcp_stat_t |
typedef uint32_t | nip_tcp_seq_t |
Enumerations | |
enum | nip_tcp_stat { NIP_TCP_STAT_CLOSED = 0, NIP_TCP_STAT_LISTEN = 1, NIP_TCP_STAT_SYN_RECEIVED = 2, NIP_TCP_STAT_SYN_SENT = 3, NIP_TCP_STAT_ESTABLISHED = 4, NIP_TCP_STAT_FIN_WAIT1 = 5, NIP_TCP_STAT_FIN_WAIT2 = 6, NIP_TCP_STAT_CLOSE_WAIT = 7, NIP_TCP_STAT_CLOSING = 8, NIP_TCP_STAT_LAST_ACK = 9, NIP_TCP_STAT_TIMEWAIT = 10 } |
enum | nip_tcp_conn_op_t { NIP_TCP_CONN_OP_ADD, NIP_TCP_CONN_OP_DEL, NIP_TCP_CONN_OP_FIND } |
Functions | |
nip_tcp_sock_id_t | nip_tcp_socket (struct nip_tcp_sock_addr *addr, uint8_t flags) |
Register TCP socket with given address and flags. | |
void | nip_tcp_close (nip_tcp_sock_id_t connid) |
Close connection or remove socket if not connected. | |
void | nip_tcp_disp_check (void) |
Dispatcher function to check TCP connection states/retransmissions/. | |
void | nip_tcp_disp_receive (void) |
Dispatcher function to receive TCP segment. | |
nip_tcp_sock_id_t | nip_tcp_accept (nip_tcp_sock_id_t sockid) |
Looks for incoming connections on given listening socket. | |
nip_mem_size_t | nip_tcp_read (nip_tcp_sock_id_t connid, uint8_t *buf, nip_mem_size_t size) |
Read data from connection into given buffer. | |
nip_mem_size_t | nip_tcp_write (nip_tcp_sock_id_t connid, uint8_t *buf, nip_mem_size_t size) |
Write data to connection. |
#define NIP_TCP_ACK_FLAG 0x10 |
Definition at line 220 of file tcp.h.
Referenced by nip_tcp_disp_receive(), and nip_tcp_disp_send().
#define NIP_TCP_DEFAULT_RCV_WND 150 |
Default Receive Window Size.
Every IP host should be able to receive 576 Byte long IP packets. Assuming standard headers, that results in 536 Byte for TCP payload.
Definition at line 58 of file tcp.h.
Referenced by nip_tcp_create_conn().
#define NIP_TCP_FIN_FLAG 0x01 |
Definition at line 216 of file tcp.h.
Referenced by nip_tcp_disp_receive(), and nip_tcp_disp_send().
#define NIP_TCP_MAX_CONNECTIONS 5 |
#define NIP_TCP_MAX_SOCKETS 2 |
Define maximum number of TCP sockets for static socket array.
Definition at line 40 of file tcp.h.
Referenced by nip_tcp_create_conn(), nip_tcp_del_conn(), nip_tcp_disp_receive(), and nip_tcp_socket().
#define NIP_TCP_MAX_UNACCEPTED 5 |
Define maximum number of unaccepted TCP connections.
Definition at line 50 of file tcp.h.
Referenced by nip_tcp_disp_receive().
#define NIP_TCP_MIN_DATA_OFFSET 0x50 |
#define NIP_TCP_MIN_HEADER_SIZE 20 |
minimum size of TCP header
Definition at line 115 of file tcp.h.
Referenced by nip_tcp_disp_receive(), and nip_tcp_disp_send().
#define NIP_TCP_MSL 120 |
#define NIP_TCP_NO_SOCKET 0xFF |
Definition at line 94 of file tcp.h.
Referenced by nip_tcp_accept(), nip_tcp_del_conn(), nip_tcp_disp_receive(), and nip_tcp_socket().
#define NIP_TCP_PSH_FLAG 0x08 |
#define NIP_TCP_RESET_ACK 0xFFFFFFFF |
#define NIP_TCP_RST_FLAG 0x04 |
#define NIP_TCP_RTO_ALPHA 1 |
#define NIP_TCP_RTO_BETA 2 |
Delay variance factor for RTO.
RFC 793 proposes 1.3 to 2.0
Definition at line 87 of file tcp.h.
Referenced by nip_tcp_disp_send().
#define NIP_TCP_RTO_LBOUND 1 |
Lower bound on retransmission timeout (RTO).
This value MUST NOT exceed 255, due to data type restrictions.
Definition at line 76 of file tcp.h.
Referenced by nip_tcp_disp_receive(), and nip_tcp_disp_send().
#define NIP_TCP_RTO_UBOUND 60 |
Upper bound on retransmission timeout (RTO).
This value MUST NOT exceed 255, due to data type restrictions.
Definition at line 70 of file tcp.h.
Referenced by nip_tcp_disp_send().
#define NIP_TCP_SHUT_RD NIP_TCP_SOCK_FLG_SHUT_RD |
#define NIP_TCP_SHUT_WR NIP_TCP_SOCK_FLG_SHUT_WR |
#define NIP_TCP_SOCK_FLG_ACCEPTED 0x08 |
#define NIP_TCP_SOCK_FLG_AUTOCLOSE (NIP_TCP_SOCK_FLG_SHUT_WR|NIP_TCP_SOCK_FLG_SHUT_RD) |
#define NIP_TCP_SOCK_FLG_LISTENING 0x04 |
wait for incoming connections?
Definition at line 107 of file tcp.h.
Referenced by nip_tcp_del_conn(), and nip_tcp_disp_receive().
#define NIP_TCP_SOCK_FLG_NON_BLOCK 0x02 |
#define NIP_TCP_SOCK_FLG_RECV 0x10 |
socket ready to receive
Definition at line 109 of file tcp.h.
Referenced by nip_tcp_disp_receive(), and nip_tcp_read().
#define NIP_TCP_SOCK_FLG_SEND 0x20 |
socket ready to send
Definition at line 110 of file tcp.h.
Referenced by nip_tcp_close(), nip_tcp_disp_receive(), and nip_tcp_disp_send().
#define NIP_TCP_SOCK_FLG_SHUT_RD 0x80 |
quit receiving data on socket
Definition at line 112 of file tcp.h.
Referenced by nip_tcp_disp_receive().
#define NIP_TCP_SOCK_FLG_SHUT_WR 0x40 |
#define NIP_TCP_SOCK_FLG_USED 0x01 |
#define NIP_TCP_SYN_FLAG 0x02 |
Definition at line 217 of file tcp.h.
Referenced by nip_tcp_disp_receive(), and nip_tcp_disp_send().
typedef uint32_t nip_tcp_seq_t |
typedef uint8_t nip_tcp_sock_cnt_t |
typedef uint8_t nip_tcp_sock_id_t |
typedef enum nip_tcp_stat nip_tcp_stat_t |
enum nip_tcp_conn_op_t |
enum nip_tcp_stat |
nip_tcp_sock_id_t nip_tcp_accept | ( | nip_tcp_sock_id_t | sockid | ) |
Looks for incoming connections on given listening socket.
Definition at line 392 of file tcp.c.
References nip_tcb::connid, nip_tcb::flags, nip_mem_release_block(), nip_memmove, nip_tcp_conns, nip_tcp_find_conn(), NIP_TCP_NO_SOCKET, NIP_TCP_SOCK_FLG_ACCEPTED, nip_tcp_unaccepted, nip_tcp_unaccepted_cnt, NULL, and nip_tcb::sockid.
void nip_tcp_close | ( | nip_tcp_sock_id_t | connid | ) |
Close connection or remove socket if not connected.
Definition at line 322 of file tcp.c.
References nip_tcb::flags, NIP_DISP_CHECK_TCP, nip_disp_notify, nip_dispatcher(), NIP_E_INVALID_SOCK, nip_error, nip_mem_buf_used(), nip_mem_release_block(), nip_tcp_conns, nip_tcp_del_conn(), nip_tcp_find_conn(), NIP_TCP_SHUT_WR, NIP_TCP_SOCK_FLG_SEND, NIP_TCP_STAT_CLOSE_WAIT, NIP_TCP_STAT_CLOSED, NIP_TCP_STAT_ESTABLISHED, NIP_TCP_STAT_FIN_WAIT1, NIP_TCP_STAT_LAST_ACK, NIP_TCP_STAT_LISTEN, NIP_TCP_STAT_SYN_RECEIVED, NIP_TCP_STAT_SYN_SENT, NULL, nip_tcb::snd_buf, nip_tcb::snd_nxt, and nip_tcb::status.
void nip_tcp_disp_check | ( | void | ) |
Dispatcher function to check TCP connection states/retransmissions/.
Definition at line 1260 of file tcp.c.
References nip_tcb::connid, nip_tcb::flags, nip_disp_params_t::flags, nip_disp_state_t::next, NIP_CURR_CMD, nip_disp, NIP_DISP_CHECK_TCP, nip_disp_notify, nip_mem_buf_used(), nip_mem_obtain_ptr(), nip_mem_release_block(), nip_tcp_conn_cnt, nip_tcp_conns, nip_tcp_disp_close(), nip_tcp_disp_send(), NIP_TCP_SOCK_FLG_AUTOCLOSE, NIP_TCP_STAT_CLOSED, NIP_TCP_STAT_FIN_WAIT1, NIP_TCP_STAT_LAST_ACK, NIP_TCP_STAT_TIMEWAIT, nip_tickcount, NULL, nip_tcb::rto, nip_tcb::snd_buf, nip_tcb::snd_nxt, nip_tcb::snd_una, nip_disp_params_t::sockid, nip_tcb::status, nip_disp_params_t::tcp, and nip_tcb::timeout.
void nip_tcp_disp_receive | ( | void | ) |
Dispatcher function to receive TCP segment.
Requires nip_disp.next.common.trans to point to valid transmission
update receive window?
Definition at line 804 of file tcp.c.
References nip_tcp_header::ack, nip_disp_params_t::common, nip_tcb::connid, nip_tcp_header::dataoffset, nip_net_if_trans_params_t::dst_nw_addr, nip_net_if_trans_params_t::dst_port, nip_tcp_header::dstport, nip_tcb::flags, nip_disp_params_t::flags, nip_net_if_trans_t::flags, nip_tcp_header::flags, nip_net_if_trans_flags_t::free_payload, nip_net_if_trans_t::header, nip_net_if_trans_t::header_size, htonl, nip_net_if_trans_params_t::ip, nip_tcb::irs, nip_disp_state_t::next, NIP_CURR_CMD, nip_disp, NIP_E_OK, nip_ip_disp_send(), nip_ip_null, NIP_IP_PROTO_TCP, nip_ip_route(), nip_mem_alloc(), nip_mem_buf_used(), nip_mem_move(), NIP_MEM_NULL, nip_mem_obtain_ptr(), nip_mem_read(), nip_mem_read_at_pos(), nip_mem_release_block(), nip_mem_set_used(), nip_mem_write(), nip_memcmp, nip_memcpy(), NIP_NET_IF_DONE, NIP_NET_IF_RESOLV_ADDR, NIP_NET_NO_IF, nip_reset_trans(), NIP_TCP_ACK_FLAG, nip_tcp_checksum(), nip_tcp_conns, nip_tcp_create_conn(), nip_tcp_disp_send(), NIP_TCP_FIN_FLAG, nip_tcp_find_conn(), NIP_TCP_MAX_SOCKETS, NIP_TCP_MAX_UNACCEPTED, NIP_TCP_MIN_DATA_OFFSET, NIP_TCP_MIN_HEADER_SIZE, NIP_TCP_MSL, NIP_TCP_NO_SOCKET, NIP_TCP_RESET_ACK, NIP_TCP_RST_FLAG, NIP_TCP_RTO_LBOUND, NIP_TCP_SOCK_FLG_LISTENING, NIP_TCP_SOCK_FLG_RECV, NIP_TCP_SOCK_FLG_SEND, NIP_TCP_SOCK_FLG_SHUT_RD, NIP_TCP_SOCKATTR, NIP_TCP_STAT_CLOSE_WAIT, NIP_TCP_STAT_CLOSED, NIP_TCP_STAT_CLOSING, NIP_TCP_STAT_ESTABLISHED, NIP_TCP_STAT_FIN_WAIT1, NIP_TCP_STAT_FIN_WAIT2, NIP_TCP_STAT_LAST_ACK, NIP_TCP_STAT_LISTEN, NIP_TCP_STAT_SYN_RECEIVED, NIP_TCP_STAT_SYN_SENT, NIP_TCP_STAT_TIMEWAIT, NIP_TCP_SYN_FLAG, nip_tcp_unaccepted, nip_tcp_unaccepted_cnt, nip_tickcount, ntohl, ntohs, NULL, nip_net_if_trans_t::params, nip_net_if_trans_t::payload, nip_net_if_trans_t::payload_size, nip_net_if_trans_params_t::protocol, nip_tcb::rcv_buf, nip_tcb::rcv_nxt, nip_tcb::rcv_wnd, nip_tcb::rt_una, nip_tcb::rto, nip_tcp_header::seq, nip_tcb::snd_buf, nip_tcb::snd_nxt, nip_tcb::snd_una, nip_tcb::snd_wl1, nip_tcb::snd_wl2, nip_tcb::snd_wnd, nip_disp_params_t::sockid, nip_tcb::sockid, nip_net_if_trans_params_t::src_nw_addr, nip_net_if_trans_params_t::src_port, nip_tcp_header::srcport, nip_net_if_trans_t::status, nip_tcb::status, nip_disp_params_t::tcp, nip_net_if_trans_params_t::tcp, nip_tcb::timeout, nip_disp_params_t::trans, and nip_tcp_header::window.
nip_mem_size_t nip_tcp_read | ( | nip_tcp_sock_id_t | connid, | |
uint8_t * | buf, | |||
nip_mem_size_t | size | |||
) |
Read data from connection into given buffer.
Definition at line 500 of file tcp.c.
References nip_tcb::flags, NIP_E_AGAIN, NIP_E_EOF, nip_error, nip_mem_read(), nip_mem_release_block(), nip_tcp_conns, nip_tcp_find_conn(), NIP_TCP_SHUT_RD, NIP_TCP_SOCK_FLG_RECV, NIP_TCP_STAT_ESTABLISHED, NULL, nip_tcb::rcv_buf, and nip_tcb::status.
nip_tcp_sock_id_t nip_tcp_socket | ( | struct nip_tcp_sock_addr * | addr, | |
uint8_t | flags | |||
) |
Register TCP socket with given address and flags.
addr | structure to be filled with address and port. If all address bytes are set to Zero, the socket will listen on all interfaces. If port is set to Zero, the implementation will choose a random port, which should be the usual way to go for sockets with the NIP_TCP_SOCK_FLG_LISTENING-flag set. | |
flags | possible flags are:
|
Definition at line 70 of file tcp.c.
References NIP_E_OUT_OF_RESSOURCES, nip_error, nip_memcpy(), NIP_TCP_MAX_SOCKETS, NIP_TCP_NO_SOCKET, NIP_TCP_SOCK_FLG_USED, NIP_TCP_SOCKATTR, and nip_tcp_sock::sockid.
nip_mem_size_t nip_tcp_write | ( | nip_tcp_sock_id_t | connid, | |
uint8_t * | buf, | |||
nip_mem_size_t | size | |||
) |
Write data to connection.
Definition at line 441 of file tcp.c.
References NIP_DISP_CHECK_TCP, nip_disp_notify, nip_dispatcher(), NIP_E_AGAIN, NIP_E_EOF, NIP_E_OK, nip_error, nip_mem_release_block(), nip_mem_write(), nip_tcp_conns, nip_tcp_find_conn(), NIP_TCP_STAT_CLOSING, NIP_TCP_STAT_FIN_WAIT1, NIP_TCP_STAT_FIN_WAIT2, NIP_TCP_STAT_LAST_ACK, NIP_TCP_STAT_TIMEWAIT, NULL, nip_tcb::snd_buf, and nip_tcb::status.