inet-mon/firmware/main/network.h
Ricardo (XenGi) Band 840909af66
nearly done
2026-07-17 00:08:48 +02:00

93 lines
2.7 KiB
C

#ifndef NETWORK_H
#define NETWORK_H
#include <stdint.h>
#include <stdbool.h>
#include "esp_eth.h"
#include "esp_netif.h"
#include "esp_event.h" // for esp_event_handler_register
#ifdef __cplusplus
extern "C" {
#endif
/// Initialize SPI2_HOST bus for W5500.
/// Must be called before network_eth_init().
void network_spi_init(void);
/// Explicitly start IPv6 SLAAC on the Ethernet interface.
/// Must be called after network_netif_init().
/// In ESP-IDF v6, IPv6 link-local is NOT automatic for Ethernet.
void network_start_ipv6(void);
/// Initialize W5500 Ethernet on SPI2_HOST.
/// Must be called after nvs_flash_init(), esp_netif_init(), esp_event_loop_create_default(),
/// and network_spi_init().
/// Returns the ethernet handle.
esp_eth_handle_t network_eth_init(void);
/// Create and attach a TCP/IP network interface for Ethernet.
/// Must be called after network_eth_init().
esp_netif_t *network_netif_init(esp_eth_handle_t eth_handle);
/// Start the Ethernet driver (begins PHY link negotiation + DHCP).
void network_eth_start(esp_eth_handle_t eth_handle);
/// Register Ethernet and IP event handlers with the default event loop.
/// Must be called before starting Ethernet.
void network_register_handlers(void);
/// Check if Ethernet link is up.
bool network_is_link_up(void);
/// Check if IPv4 address has been assigned via DHCP.
bool network_has_ipv4(void);
/// Get the IPv4 address string (e.g., "192.168.1.123").
const char *network_get_ipv4_str(void);
/// Get the IPv4 gateway string.
const char *network_get_gateway_str(void);
/// Get the IPv4 netmask string.
const char *network_get_netmask_str(void);
/// Get the IPv4 DNS server string (first DNS from DHCP).
const char *network_get_dns_str(void);
/// Get the IPv6 DNS server string (from RDNSS in RA).
const char *network_get_dns6_str(void);
/// Get the link-local IPv6 address (fe80::...).
const char *network_get_ipv6_ll_str(void);
/// Get the global IPv6 address (2xxx::... or ULA).
const char *network_get_ipv6_gua_str(void);
/// Get the primary IPv6 address string (GUA if available, else link-local).
const char *network_get_ipv6_str(void);
/// Get the IPv6 gateway string (router's link-local, from lwIP ND6 router list).
const char *network_get_gateway6_str(void);
/// Check if a link-local IPv6 address is available.
bool network_has_ipv6_ll(void);
/// Check if a global IPv6 address is available.
bool network_has_ipv6_gua(void);
/// Check if any IPv6 address is available.
bool network_has_ipv6(void);
/// Get the MAC address string (for display).
const char *network_get_mac_str(void);
/// Get the lwIP interface scope ID (index) for the Ethernet netif.
/// Used when sending packets to link-local IPv6 (fe80::) addresses.
int network_get_eth_scope_id(void);
#ifdef __cplusplus
}
#endif
#endif // NETWORK_H