Skip to main content

abi_application/
network_types.rs

1#[cfg(feature = "network")]
2use ::network::{Manager, TcpSocket, UdpSocket};
3
4pub const XILA_NETWORK_CONNECT: u32 = 1;
5pub const XILA_NETWORK_LISTEN: u32 = 2;
6pub const XILA_NETWORK_RESOLVE: u32 = 4;
7pub const XILA_ADDRESS_IPV4: u32 = 4;
8pub const XILA_ADDRESS_IPV6: u32 = 6;
9pub const XILA_SHUTDOWN_WRITE: u32 = 1;
10
11/// Fixed-width address. Bytes are in network order; integer fields are host order.
12/// IPv4 uses the first four bytes and requires the remaining bytes to be zero.
13/// Scope must be zero: Core does not support scoped IPv6 endpoints.
14#[repr(C)]
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub struct NetworkAddress {
17    pub family: u32,
18    pub bytes: [u8; 16],
19    pub port: u16,
20    pub reserved: u16,
21    pub scope_id: u32,
22}
23/// Host-granted network authority. Future host/port restrictions belong here.
24pub struct Network {
25    #[cfg(not(feature = "network"))]
26    _unavailable: core::convert::Infallible,
27    #[cfg(feature = "network")]
28    pub(crate) manager: &'static Manager,
29    #[cfg(feature = "network")]
30    pub(crate) rights: u8,
31}
32/// Owned TCP connection. Its creation grants bidirectional I/O authority.
33pub struct Tcp {
34    #[cfg(not(feature = "network"))]
35    _unavailable: core::convert::Infallible,
36    #[cfg(feature = "network")]
37    pub(crate) inner: TcpSocket,
38}
39/// One pending connection, with no additional backlog. Accept replenishes the socket.
40pub struct TcpListener {
41    #[cfg(not(feature = "network"))]
42    _unavailable: core::convert::Infallible,
43    #[cfg(feature = "network")]
44    pub(crate) network: Network,
45    #[cfg(feature = "network")]
46    pub(crate) address: NetworkAddress,
47    #[cfg(feature = "network")]
48    pub(crate) inner: TcpSocket,
49    /// Embassy-time tick by which the last reset that a poll left pending must have been
50    /// sent; the listener listens again after it even if the reset is still pending.
51    /// Stale afterwards. Behind a mutex because concurrent poll waits are allowed and
52    /// 64-bit atomics are not available on every target.
53    #[cfg(feature = "network")]
54    pub(crate) reset_deadline: synchronization::blocking_mutex::Mutex<
55        synchronization::blocking_mutex::raw::CriticalSectionRawMutex,
56        core::cell::Cell<u64>,
57    >,
58}
59/// Owned UDP socket. Sending additionally requires CONNECT on its parent capability.
60pub struct Udp {
61    #[cfg(not(feature = "network"))]
62    _unavailable: core::convert::Infallible,
63    #[cfg(feature = "network")]
64    pub(crate) inner: UdpSocket,
65    #[cfg(feature = "network")]
66    pub(crate) rights: u8,
67    /// `XILA_ADDRESS_IPV4` or `XILA_ADDRESS_IPV6`: the family it was bound with, the
68    /// only one it sends to and receives from.
69    #[cfg(feature = "network")]
70    pub(crate) family: u32,
71}