23#ifndef PROTOCORE_STACK_NET_H
24#define PROTOCORE_STACK_NET_H
29#include "embed_compiler_directives.h"
30#include "embed_types.h"
38#define PROTOCORE_NET_OK 0
39#define PROTOCORE_NET_ERR_MEM (-1)
40#define PROTOCORE_NET_ERR_BUF (-2)
41#define PROTOCORE_NET_ERR_VAL (-6)
42#define PROTOCORE_NET_ERR_USE (-8)
43#define PROTOCORE_NET_ERR_CONN (-11)
44#define PROTOCORE_NET_ERR_ABRT (-13)
45#define PROTOCORE_NET_ERR_RST (-14)
46#define PROTOCORE_NET_ERR_CLSD (-15)
47#define PROTOCORE_NET_ERR_ARG (-16)
48#define PROTOCORE_NET_ERR_INPROGRESS (-5)
52#define PROTOCORE_NET_TYPE_ANY 0
53#define PROTOCORE_NET_TYPE_V4 4
54#define PROTOCORE_NET_TYPE_V6 6
55#define PROTOCORE_NET_HAS_IGMP 1
56#define PROTOCORE_NET_HAS_IPV6 0
72#define PROTOCORE_NET_ADDR_ANY (&protocore_stack_net_any)
73#define PROTOCORE_NET_ADDR_ANY4 (&protocore_stack_net_any)
74#define PROTOCORE_NET_ADDR_ANY4_P (&protocore_stack_net_any)
76#define protocore_net_ip_is_v4(a) ((a) != NULL && (a)->type == PROTOCORE_NET_TYPE_V4)
77#define protocore_net_ip_is_v6(a) ((a) != NULL && (a)->type == PROTOCORE_NET_TYPE_V6)
78#define protocore_net_ip_as_v4(a) (a)
79#define protocore_net_ip_as_v6(a) (a)
80#define protocore_net_ip6_bytes(a) ((const uint8_t *)(a)->bytes)
81#define protocore_net_ip6_wbytes(a) ((uint8_t *)(a)->bytes)
82#define protocore_net_ip6_mark(a) ((a)->type = PROTOCORE_NET_TYPE_V6)
97#define PROTOCORE_NET_PBUF_TRANSPORT 0
98#define PROTOCORE_NET_PBUF_RAM 0
125#define PROTOCORE_NET_WRITE_COPY 0x01
126#define PROTOCORE_NET_OPT_REUSEADDR 0x04
201#define PROTOCORE_STACK_NET_NONE 0xFFu
protocore_net_err protocore_net_bind(protocore_pcb *p, const protocore_net_ip *a, uint16_t port)
void protocore_net_on_err(protocore_pcb *p, protocore_net_err_fn fn)
protocore_net_err protocore_net_write(protocore_pcb *p, const void *data, uint16_t len, uint8_t flags)
protocore_net_err(* protocore_net_recv_fn)(void *, protocore_pcb *, protocore_pbuf *, protocore_net_err)
protocore_net_err protocore_net_igmp_leave(const protocore_net_ip *nif, const protocore_net_ip *grp)
void protocore_net_udp_recv(protocore_udp_pcb *p, protocore_net_udp_recv_fn fn, void *arg)
protocore_net_err protocore_net_udp_sendto(const protocore_udp_pcb *p, const protocore_pbuf *b, const protocore_net_ip *a, uint16_t port)
protocore_net_err(* protocore_net_sent_fn)(void *, protocore_pcb *, uint16_t)
uint32_t protocore_net_ip4_u32(const protocore_net_ip *a)
The IPv4 address of a as the word that lwIP keeps: the four octets in network order in memory.
protocore_net_err protocore_net_close(protocore_pcb *p)
void(* protocore_net_udp_recv_fn)(void *, protocore_udp_pcb *, protocore_pbuf *, const protocore_net_ip *, uint16_t)
void protocore_net_recved(const protocore_pcb *p, uint16_t len)
void protocore_net_on_recv(protocore_pcb *p, protocore_net_recv_fn fn)
protocore_pcb * protocore_net_new(int type)
void protocore_stack_net_pass(uint32_t now_ms, uint32_t random_word)
One pass of the stack, under its lock: the units of idemIP, then each event of the TCP as a callback.
protocore_pbuf * protocore_net_pbuf_alloc(int layer, uint16_t len, int type)
A packet buffer of len octets from the pool, or NULL when the pool is spent.
void(* protocore_net_err_fn)(void *, protocore_net_err)
protocore_net_err protocore_net_connect(protocore_pcb *p, const protocore_net_ip *a, uint16_t port, protocore_net_connect_fn connected)
uint16_t protocore_net_pbuf_copy(const protocore_pbuf *p, void *dst, uint16_t len, uint16_t off)
Copy at most len octets of p, from off, to dst. The octets copied.
int protocore_net_ip4_is_multicast(const protocore_net_ip *a)
1 when a is an IPv4 host group, 224.0.0.0/4.
void protocore_net_on_sent(protocore_pcb *p, protocore_net_sent_fn fn)
const protocore_net_ip protocore_stack_net_any
The any address, which a bind takes for each local address.
protocore_net_err protocore_net_igmp_join(const protocore_net_ip *nif, const protocore_net_ip *grp)
char * protocore_net_ip_print(const protocore_net_ip *a, char *buf, int cap)
The dotted quad of a in buf, of cap octets.
protocore_pcb * protocore_net_listen(protocore_pcb *p, uint8_t backlog)
void protocore_net_nagle_disable(const protocore_pcb *p)
protocore_net_err protocore_net_dns_resolve(const char *host, protocore_net_ip *addr, protocore_net_dns_found_fn found, void *arg)
Resolve host to addr, as dns_gethostbyname of lwIP does.
int protocore_stack_net_start(void)
Start the task of the stack, which runs protocore_stack_net_pass once each tick of the platform.
void protocore_net_ip4_set(protocore_net_ip *a, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3)
Set a to the IPv4 address b0.b1.b2.b3.
int protocore_net_ip_parse(const char *s, protocore_net_ip *out)
Parse the dotted quad s into out. 1 on success, and 0 otherwise.
protocore_net_err(* protocore_net_accept_fn)(void *, protocore_pcb *, protocore_net_err)
protocore_net_err protocore_net_call_marshal(protocore_net_err(*fn)(protocore_net_call *), protocore_net_call *c)
Run fn on c under the lock of the stack, and return what it returns.
protocore_udp_pcb * protocore_net_udp_new(void)
void(* protocore_net_dns_found_fn)(const char *, const protocore_net_ip *, void *)
The callback of a name that the resolver of the stack found, with a NULL address for none.
uint8_t protocore_net_pbuf_free(const protocore_pbuf *p)
Give a packet buffer back to the pool.
protocore_net_err(* protocore_net_connect_fn)(void *, protocore_pcb *, protocore_net_err)
EMBED_BEGIN_DECLS typedef int8_t protocore_net_err
The result of a call of the stack, as lwIP numbers it.
protocore_net_err protocore_net_udp_bind(protocore_udp_pcb *p, const protocore_net_ip *a, uint16_t port)
void protocore_net_udp_remove(protocore_udp_pcb *p)
void protocore_stack_net_udp_input(const uint8_t *frame, uint16_t entry, size_t ip_off, size_t payload_off, size_t payload_len)
One UDP datagram that Dispatch delivered to a UdpPcb entry, to the callback of its control block.
uint16_t protocore_net_sndbuf(const protocore_pcb *p)
void protocore_net_rcv_wnd_update(const protocore_pcb *p, uint16_t len)
protocore_net_err protocore_net_output(const protocore_pcb *p)
void protocore_net_on_accept(protocore_pcb *p, protocore_net_accept_fn fn)
void protocore_net_abort(protocore_pcb *p)
void protocore_net_arg(protocore_pcb *p, void *arg)
void protocore_net_opt_set(void *p, uint32_t opt)
The record that a call of the stack carries, as the transport embeds it.
struct protocore_pbuf * next
protocore_net_accept_fn on_accept
protocore_net_sent_fn on_sent
protocore_net_recv_fn on_recv
protocore_net_connect_fn on_connect
protocore_net_ip local_ip
protocore_net_ip remote_ip
protocore_net_err_fn on_err
StackNetConnectWait connect_wait
protocore_net_udp_recv_fn on_recv