Skip to content

File syn_tcp.h

FileList > net > syn_tcp.h

Go to the source code of this file

Zero-Alloc Native TCP State Machine & Segment Engine.

  • #include "syntropic/common/syn_defs.h"
  • #include "syntropic/net/syn_eth.h"
  • #include "syntropic/pt/syn_pt.h"
  • #include "syntropic/sched/syn_task.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_TCP
Top-level TCP stack instance container.
struct SYN_TcpConn
Single TCP socket connection control block.
struct SYN_TcpHeader
TCP packet header structure.

Public Types

Type Name
enum SYN_TcpState

Public Functions

Type Name
uint16_t syn_tcp_checksum (uint32_t src_ip, uint32_t dst_ip, const uint8_t * tcp_seg, size_t len)
Compute TCP 16-bit 1's complement checksum over pseudo-header and segment.
SYN_Status syn_tcp_init (SYN_TCP * tcp, SYN_ETH * eth)
Initialize TCP Stack.
SYN_Status syn_tcp_listen (SYN_TCP * tcp, uint16_t port)
Bind TCP listener to port.
SYN_Status syn_tcp_process_packet (SYN_TCP * tcp, const uint8_t * ip_packet, size_t len, uint8_t * tx_out, size_t * tx_len)
Process incoming TCP IPv4 segment.

Macros

Type Name
define PT_TCP_BLOCK_READ (pt, task, conn, buf, max_len, bytes_read) /* multi line expression */
Protothread helper macro to block task until TCP data is available.
define SYN_TCP_BUF_SIZE 512
define SYN_TCP_FLAG_ACK 0x10
define SYN_TCP_FLAG_FIN 0x01
define SYN_TCP_FLAG_PSH 0x08
define SYN_TCP_FLAG_RST 0x04
define SYN_TCP_FLAG_SYN 0x02
define SYN_TCP_MAX_CONNS 1

Public Types Documentation

enum SYN_TcpState

enum SYN_TcpState {
    SYN_TCP_CLOSED = 0,
    SYN_TCP_LISTEN = 1,
    SYN_TCP_SYN_RCVD = 2,
    SYN_TCP_ESTABLISHED = 3,
    SYN_TCP_FIN_WAIT = 4,
    SYN_TCP_CLOSE_WAIT = 5
};

TCP Connection State Machine Enum.


Public Functions Documentation

function syn_tcp_checksum

Compute TCP 16-bit 1's complement checksum over pseudo-header and segment.

uint16_t syn_tcp_checksum (
    uint32_t src_ip,
    uint32_t dst_ip,
    const uint8_t * tcp_seg,
    size_t len
) 

Parameters:

  • src_ip Source 32-bit IPv4 address.
  • dst_ip Destination 32-bit IPv4 address.
  • tcp_seg Pointer to raw TCP segment bytes.
  • len TCP segment length in bytes.

Returns:

Computed 16-bit TCP checksum.


function syn_tcp_init

Initialize TCP Stack.

SYN_Status syn_tcp_init (
    SYN_TCP * tcp,
    SYN_ETH * eth
) 

Parameters:

  • tcp Pointer to TCP stack container.
  • eth Pointer to Ethernet interface engine instance.

Returns:

SYN_OK on success.


function syn_tcp_listen

Bind TCP listener to port.

SYN_Status syn_tcp_listen (
    SYN_TCP * tcp,
    uint16_t port
) 

Parameters:

  • tcp Pointer to TCP stack container.
  • port Port number to listen on.

Returns:

SYN_OK on success.


function syn_tcp_process_packet

Process incoming TCP IPv4 segment.

SYN_Status syn_tcp_process_packet (
    SYN_TCP * tcp,
    const uint8_t * ip_packet,
    size_t len,
    uint8_t * tx_out,
    size_t * tx_len
) 

Parameters:

  • tcp Pointer to TCP stack container.
  • ip_packet Pointer to raw IPv4 packet.
  • len IPv4 packet byte length.
  • tx_out Output buffer for immediate TCP reply segment if generated.
  • tx_len Pointer to receive output segment byte length.

Returns:

SYN_OK on success.


Macro Definition Documentation

define PT_TCP_BLOCK_READ

Protothread helper macro to block task until TCP data is available.

#define PT_TCP_BLOCK_READ (
    pt,
    task,
    conn,
    buf,
    max_len,
    bytes_read
) `/* multi line expression */`

Parameters:

  • pt Protothread state.
  • task Task instance.
  • conn TCP connection pointer.
  • buf Destination read buffer.
  • max_len Maximum bytes to read.
  • bytes_read Output variable receiving count of read bytes.

define SYN_TCP_BUF_SIZE

#define SYN_TCP_BUF_SIZE `512`

TCP RX/TX internal payload buffer size in bytes


define SYN_TCP_FLAG_ACK

#define SYN_TCP_FLAG_ACK `0x10`

Acknowledgment field significant flag


define SYN_TCP_FLAG_FIN

#define SYN_TCP_FLAG_FIN `0x01`

TCP Header Flags Finish flag: No more data from sender


define SYN_TCP_FLAG_PSH

#define SYN_TCP_FLAG_PSH `0x08`

Push function flag


define SYN_TCP_FLAG_RST

#define SYN_TCP_FLAG_RST `0x04`

Reset connection flag


define SYN_TCP_FLAG_SYN

#define SYN_TCP_FLAG_SYN `0x02`

Synchronize sequence numbers flag


define SYN_TCP_MAX_CONNS

#define SYN_TCP_MAX_CONNS `1`

Maximum concurrent TCP connections



The documentation for this class was generated from the following file src/syntropic/net/syn_tcp.h