PebbleOS v4.48.0-75-g7416f78a1
Loading...
Searching...
No Matches
Networking

The TCP/IP stack. More...

Data Structures

struct  pbl_net_ipv4_addr
 IPv4 address, in network order. More...
 
struct  pbl_net_ipv6_addr
 IPv6 address, in network order. More...
 
struct  pbl_net_ipv4_config
 IPv4 configuration of the interface. More...
 
struct  pbl_net_stats
 Counters of the interface. More...
 

Typedefs

typedef void(* pbl_net_ping_cb_t) (int result, uint32_t rtt_ms, void *arg)
 Called with the outcome of an echo request.
 

Functions

int pbl_net_init (void)
 Start the stack on the board's Ethernet controller.
 
int pbl_net_set_ipv4 (const struct pbl_net_ipv4_config *cfg)
 Set the IPv4 configuration of the interface.
 
int pbl_net_clear_ipv4 (void)
 Clear the IPv4 configuration of the interface.
 
int pbl_net_get_ipv4 (struct pbl_net_ipv4_config *cfg)
 Get the IPv4 configuration of the interface.
 
size_t pbl_net_get_ipv6 (struct pbl_net_ipv6_addr *addrs, size_t max)
 Get the IPv6 addresses of the interface.
 
void pbl_net_get_stats (struct pbl_net_stats *stats)
 Get the counters of the interface.
 
int pbl_net_ping_ipv4 (const struct pbl_net_ipv4_addr *dst, size_t len, uint32_t timeout_ms, pbl_net_ping_cb_t cb, void *arg)
 Send an ICMP echo request.
 
int pbl_net_ping_ipv6 (const struct pbl_net_ipv6_addr *dst, size_t len, uint32_t timeout_ms, pbl_net_ping_cb_t cb, void *arg)
 Send an ICMPv6 echo request.
 

Detailed Description

The TCP/IP stack.

The stack runs on a thread of its own, over the board's Ethernet controller. pbl_net_init() starts it; the interface comes up with the link. Addresses are kept as bytes in network order.

IPv4 is configured by the caller. IPv6 configures itself whenever the link comes up: a link-local address, then one per prefix routers advertise, each checked for duplicates first.

const struct pbl_net_ipv4_config cfg = {
.addr = {{192, 168, 1, 2}},
.prefix_len = 24,
.gateway = {{192, 168, 1, 1}},
};
ret = pbl_net_init();
ret = pbl_net_set_ipv4(&cfg);
struct pbl_net_ipv4_addr addr
Address.
Definition net.h:49
IPv4 configuration of the interface.
Definition net.h:47
int pbl_net_init(void)
Start the stack on the board's Ethernet controller.
int pbl_net_set_ipv4(const struct pbl_net_ipv4_config *cfg)
Set the IPv4 configuration of the interface.

Data Structure Documentation

◆ pbl_net_ipv4_addr

struct pbl_net_ipv4_addr

IPv4 address, in network order.

Data Fields
uint8_t b[4] Bytes.

◆ pbl_net_ipv6_addr

struct pbl_net_ipv6_addr

IPv6 address, in network order.

Data Fields
uint8_t b[16] Bytes.

◆ pbl_net_ipv4_config

struct pbl_net_ipv4_config

IPv4 configuration of the interface.

Data Fields
struct pbl_net_ipv4_addr addr Address.
struct pbl_net_ipv4_addr gateway Default gateway, or 0.0.0.0 without one.
uint8_t prefix_len Length of the network prefix, 1 to 30.

◆ pbl_net_stats

struct pbl_net_stats

Counters of the interface.

Data Fields
uint32_t arp_conflicts Hosts found using our IPv4 address, or the one we checked to take.
uint32_t dad_failures IPv6 addresses found in use by another host.
uint32_t rx_dropped Frames received and dropped: malformed, unwanted, or without a free buffer.
uint32_t tx_dropped Packets to send dropped: without a free buffer, a route or a neighbor.

Typedef Documentation

◆ pbl_net_ping_cb_t

typedef void(* pbl_net_ping_cb_t) (int result, uint32_t rtt_ms, void *arg)

Called with the outcome of an echo request.

Runs on the network thread.

Parameters
result0 on the reply, or -ETIMEDOUT without one.
rtt_msRound-trip time, in milliseconds with the resolution of a tick, on the reply.
argArgument given with the request.

Function Documentation

◆ pbl_net_clear_ipv4()

int pbl_net_clear_ipv4 ( void  )

Clear the IPv4 configuration of the interface.

The stack then takes a link-local address again.

Returns
0, or -ENETDOWN before pbl_net_init().

◆ pbl_net_get_ipv4()

int pbl_net_get_ipv4 ( struct pbl_net_ipv4_config *  cfg)

Get the IPv4 configuration of the interface.

Without one set, it is the link-local address the stack took, in 169.254.0.0/16, once checked for conflicts on the link.

Parameters
[out]cfgConfiguration.
Returns
0, or -EADDRNOTAVAIL without one.

◆ pbl_net_get_ipv6()

size_t pbl_net_get_ipv6 ( struct pbl_net_ipv6_addr *  addrs,
size_t  max 
)

Get the IPv6 addresses of the interface.

Only addresses checked for duplicates are given: the link-local one first, then those from router advertisements.

Parameters
[out]addrsAddresses.
maxRoom in addrs.
Returns
Number of addresses written.

◆ pbl_net_get_stats()

void pbl_net_get_stats ( struct pbl_net_stats *  stats)

Get the counters of the interface.

Parameters
[out]statsCounters, zero before pbl_net_init().

◆ pbl_net_init()

int pbl_net_init ( void  )

Start the stack on the board's Ethernet controller.

Returns
0, -EALREADY if started, -ENODEV without a controller, or another negative errno, as without a random number generator.

◆ pbl_net_ping_ipv4()

int pbl_net_ping_ipv4 ( const struct pbl_net_ipv4_addr *  dst,
size_t  len,
uint32_t  timeout_ms,
pbl_net_ping_cb_t  cb,
void *  arg 
)

Send an ICMP echo request.

One request at a time awaits its reply; cb is called once, on the reply or after timeout_ms without one.

Parameters
dstDestination.
lenBytes of data in the request.
timeout_msTime to wait for the reply.
cbCalled with the outcome.
argArgument of cb.
Returns
0 once sent, -EBUSY while another request awaits its reply, -EMSGSIZE for data too large for a packet, -EADDRNOTAVAIL without an address to send from, -ENETUNREACH without a route, or -ENETDOWN before pbl_net_init().

◆ pbl_net_ping_ipv6()

int pbl_net_ping_ipv6 ( const struct pbl_net_ipv6_addr *  dst,
size_t  len,
uint32_t  timeout_ms,
pbl_net_ping_cb_t  cb,
void *  arg 
)

Send an ICMPv6 echo request.

As pbl_net_ping_ipv4().

◆ pbl_net_set_ipv4()

int pbl_net_set_ipv4 ( const struct pbl_net_ipv4_config *  cfg)

Set the IPv4 configuration of the interface.

It replaces the link-local address the stack takes while the interface has no other.

Parameters
cfgConfiguration.
Returns
0, -EINVAL for an address that cannot be a host's, a prefix out of range or a gateway off the network, or -ENETDOWN before pbl_net_init().