#include "nip_init.h"
#include "dispatcher.h"
#include "inet.h"
#include "os_core.h"
#include "nip_error.h"
#include "net/net_if.h"
#include "net/tcp.h"
#include "net/numbers.h"
Go to the source code of this file.
Defines | |
#define | NIP_TCP_SOCKATTR(sockid, attr) nip_tcp_sockets[sockid].attr |
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_del_conn (nip_tcp_sock_id_t connid) |
Remove connection TCB and entry in socket list. | |
struct nip_tcb * | nip_tcp_find_conn (nip_tcp_sock_id_t sockid, uint8_t *rem_ip, uint16_t rem_port) |
Find transmission control block (tcb) for connection with matching address. | |
struct nip_tcb * | nip_tcp_create_conn (nip_tcp_sock_id_t sockid, uint8_t *rem_ip, uint16_t rem_port, nip_tcp_stat_t init_status) |
Create new transmission control block (tcb) with given parameters. | |
void | nip_tcp_close (nip_tcp_sock_id_t connid) |
Close connection or remove socket if not connected. | |
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_write (nip_tcp_sock_id_t connid, uint8_t *buf, nip_mem_size_t size) |
Write data to connection. | |
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. | |
uint16_t | nip_tcp_checksum (nip_net_if_trans_t *trans) |
Calculate TCP checksum. | |
void | nip_tcp_disp_send (void) |
Dispatcher function to send TCP segment. | |
void | nip_tcp_disp_receive (void) |
Dispatcher function to receive TCP segment. | |
void | nip_tcp_disp_close (void) |
dispatcher function to remove closed connection | |
void | nip_tcp_disp_check (void) |
Dispatcher function to check TCP connection states/retransmissions/. | |
Variables | |
struct nip_tcp_sock | nip_tcp_sockets [NIP_TCP_MAX_SOCKETS] |
nip_tcp_sock_cnt_t | nip_tcp_unaccepted_cnt |
nip_tcp_sock_id_t | nip_tcp_unaccepted [NIP_TCP_MAX_UNACCEPTED] |
nip_tcp_sock_cnt_t | nip_tcp_conn_cnt |
number of connections in nip_tcp_conns | |
nip_mem_handle_t | nip_tcp_conns = NIP_MEM_NULL |
dynamic memory for connection array |
#define NIP_TCP_SOCKATTR | ( | sockid, | |||
attr | ) | nip_tcp_sockets[sockid].attr |
Definition at line 49 of file tcp.c.
Referenced by nip_tcp_del_conn(), nip_tcp_disp_receive(), nip_tcp_disp_send(), and nip_tcp_socket().
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.
uint16_t nip_tcp_checksum | ( | nip_net_if_trans_t * | trans | ) |
Calculate TCP checksum.
If trans->header is set the checksum will be inserted there. Make sure neither trans->header nor trans->payload are locked
Definition at line 547 of file tcp.c.
References nip_tcp_header::checksum, nip_net_if_trans_params_t::dst_nw_addr, nip_net_if_trans_t::header, nip_net_if_trans_t::header_size, htons, nip_net_if_trans_params_t::ip, NIP_IP_PROTO_TCP, nip_mem_obtain_ptr(), nip_mem_release_block(), ntohs, NULL, nip_net_if_trans_t::params, nip_net_if_trans_t::payload, nip_net_if_trans_t::payload_size, and nip_net_if_trans_params_t::src_nw_addr.
Referenced by nip_tcp_disp_receive(), and nip_tcp_disp_send().
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.
struct nip_tcb* nip_tcp_create_conn | ( | nip_tcp_sock_id_t | sockid, | |
uint8_t * | rem_ip, | |||
uint16_t | rem_port, | |||
nip_tcp_stat_t | init_status | |||
) | [read] |
Create new transmission control block (tcb) with given parameters.
Definition at line 228 of file tcp.c.
References nip_tcb::connid, nip_tcp_sock_addr::ip, nip_tcb::iss, NIP_E_OK, nip_mem_alloc(), nip_mem_free(), NIP_MEM_NULL, nip_mem_obtain_ptr(), nip_mem_release_block(), nip_mem_set_used(), nip_mem_write(), nip_memcpy(), nip_memset, nip_tcp_conn_cnt, nip_tcp_conns, NIP_TCP_DEFAULT_RCV_WND, NIP_TCP_MAX_SOCKETS, NIP_TCP_STAT_LISTEN, nip_tickcount, NULL, nip_tcp_sock_addr::port, nip_tcb::rcv_buf, nip_tcb::rcv_wnd, nip_tcb::rem_addr, nip_tcb::snd_buf, nip_tcb::snd_nxt, nip_tcb::snd_una, nip_tcb::sockid, and nip_tcb::status.
Referenced by nip_tcp_disp_receive().
void nip_tcp_del_conn | ( | nip_tcp_sock_id_t | connid | ) |
Remove connection TCB and entry in socket list.
Definition at line 99 of file tcp.c.
References nip_tcb::connid, nip_tcb::flags, nip_mem_free(), nip_mem_obtain_ptr(), nip_mem_release_block(), nip_mem_set_used(), nip_memcpy(), nip_tcp_conn_cnt, nip_tcp_conns, NIP_TCP_MAX_SOCKETS, NIP_TCP_NO_SOCKET, NIP_TCP_SOCK_FLG_AUTOCLOSE, NIP_TCP_SOCK_FLG_LISTENING, NIP_TCP_SOCKATTR, NULL, nip_tcb::rcv_buf, nip_tcb::snd_buf, and nip_tcb::sockid.
Referenced by nip_tcp_close(), and nip_tcp_disp_close().
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_close | ( | void | ) |
dispatcher function to remove closed connection
Definition at line 1251 of file tcp.c.
References nip_disp_state_t::next, nip_disp, nip_tcp_del_conn(), nip_disp_params_t::sockid, and nip_disp_params_t::tcp.
Referenced by nip_tcp_disp_check().
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.
void nip_tcp_disp_send | ( | void | ) |
Dispatcher function to send TCP segment.
The following dispatcher parameters are expected to be configured:
make sure it's multiples of 4
Definition at line 620 of file tcp.c.
References nip_tcp_header::ack, nip_tcp_header::checksum, nip_disp_params_t::common, nip_tcp_header::dataoffset, nip_tcp_header::dstport, nip_tcb::flags, nip_disp_params_t::flags, nip_tcp_header::flags, nip_net_if_trans_t::flags, nip_net_if_trans_flags_t::free_payload, nip_net_if_trans_t::header, nip_net_if_trans_t::header_size, htonl, htons, nip_net_if_trans_params_t::ip, nip_tcp_sock_addr::ip, nip_disp_state_t::next, NIP_CURR_CMD, nip_disp, NIP_E_OK, nip_ip_disp_send(), NIP_IP_PROTO_TCP, nip_ip_route(), nip_mem_alloc(), nip_mem_buf_used(), NIP_MEM_NULL, nip_mem_obtain_ptr(), nip_mem_release_block(), nip_mem_write(), NIP_NET_IF_RESOLV_ADDR, NIP_NET_NO_IF, nip_reset_trans(), NIP_TCP_ACK_FLAG, nip_tcp_checksum(), nip_tcp_conns, NIP_TCP_FIN_FLAG, nip_tcp_find_conn(), NIP_TCP_MIN_HEADER_SIZE, NIP_TCP_PSH_FLAG, NIP_TCP_RTO_BETA, NIP_TCP_RTO_LBOUND, NIP_TCP_RTO_UBOUND, NIP_TCP_SOCK_FLG_SEND, NIP_TCP_SOCKATTR, NIP_TCP_STAT_CLOSING, NIP_TCP_STAT_FIN_WAIT1, NIP_TCP_STAT_LAST_ACK, NIP_TCP_STAT_SYN_RECEIVED, NIP_TCP_STAT_SYN_SENT, NIP_TCP_SYN_FLAG, nip_tickcount, NULL, nip_net_if_trans_t::params, nip_net_if_trans_t::payload, nip_net_if_trans_t::payload_off, nip_net_if_trans_t::payload_size, nip_tcp_sock_addr::port, nip_net_if_trans_params_t::protocol, nip_tcb::push_ptr, nip_tcb::rcv_nxt, nip_tcb::rcv_wnd, nip_tcb::rem_addr, nip_net_if_trans_flags_t::reset_status, nip_tcb::rt_count, 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::sockid, nip_disp_params_t::sockid, nip_tcp_header::srcport, nip_tcb::srtt, nip_net_if_trans_t::status, nip_tcb::status, nip_disp_params_t::tcp, nip_disp_params_t::trans, and nip_tcp_header::window.
Referenced by nip_tcp_disp_check(), and nip_tcp_disp_receive().
struct nip_tcb* nip_tcp_find_conn | ( | nip_tcp_sock_id_t | sockid, | |
uint8_t * | rem_ip, | |||
uint16_t | rem_port | |||
) | [read] |
Find transmission control block (tcb) for connection with matching address.
If rem_ip is not NULL the given sockid will be matched against the Ids of the socket-array, otherwise sockid will be matched against connection IDs.
Definition at line 182 of file tcp.c.
References nip_tcb::connid, nip_tcp_sock_addr::ip, NIP_E_AGAIN, NIP_E_INVALID_SOCK, nip_error, nip_mem_obtain_ptr(), nip_mem_release_block(), nip_memcmp, nip_tcp_conn_cnt, nip_tcp_conns, NIP_TCP_STAT_CLOSED, NULL, nip_tcp_sock_addr::port, nip_tcb::rem_addr, nip_tcb::sockid, and nip_tcb::status.
Referenced by nip_tcp_accept(), nip_tcp_close(), nip_tcp_disp_receive(), nip_tcp_disp_send(), nip_tcp_read(), and nip_tcp_write().
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.
number of connections in nip_tcp_conns
Definition at line 54 of file tcp.c.
Referenced by nip_tcp_create_conn(), nip_tcp_del_conn(), nip_tcp_disp_check(), and nip_tcp_find_conn().
nip_mem_handle_t nip_tcp_conns = NIP_MEM_NULL |
dynamic memory for connection array
Definition at line 55 of file tcp.c.
Referenced by nip_tcp_accept(), nip_tcp_close(), nip_tcp_create_conn(), nip_tcp_del_conn(), nip_tcp_disp_check(), nip_tcp_disp_receive(), nip_tcp_disp_send(), nip_tcp_find_conn(), nip_tcp_read(), and nip_tcp_write().
struct nip_tcp_sock nip_tcp_sockets[NIP_TCP_MAX_SOCKETS] |
nip_tcp_sock_id_t nip_tcp_unaccepted[NIP_TCP_MAX_UNACCEPTED] |