|
PebbleOS v4.48.0-75-g7416f78a1
|
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. | |
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.
| 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. |
| struct pbl_net_stats |
Counters of the interface.
| 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.
| result | 0 on the reply, or -ETIMEDOUT without one. |
| rtt_ms | Round-trip time, in milliseconds with the resolution of a tick, on the reply. |
| arg | Argument given with the request. |
| int pbl_net_clear_ipv4 | ( | void | ) |
Clear the IPv4 configuration of the interface.
The stack then takes a link-local address again.
-ENETDOWN before pbl_net_init(). | 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.
| [out] | cfg | Configuration. |
-EADDRNOTAVAIL without one. | 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.
| [out] | addrs | Addresses. |
| max | Room in addrs. |
| void pbl_net_get_stats | ( | struct pbl_net_stats * | stats | ) |
Get the counters of the interface.
| [out] | stats | Counters, zero before pbl_net_init(). |
| int pbl_net_init | ( | void | ) |
Start the stack on the board's Ethernet controller.
-EALREADY if started, -ENODEV without a controller, or another negative errno, as without a random number generator. | 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.
| dst | Destination. |
| len | Bytes of data in the request. |
| timeout_ms | Time to wait for the reply. |
| cb | Called with the outcome. |
| arg | Argument of cb. |
-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(). | 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.
| 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.
| cfg | Configuration. |
-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().