* Copyright (C) 2026 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
* network_manager.h — Vela network status helper
*
* managed by the system (netinit / board BSP). This module simply
* waits for any non-loopback interface to get an IPv4 address.
*/
#include "agent_compat.h"
bool network_is_connected(void);
* Block until connected (or timeout).
* @param timeout_ms 0 = check once, UINT32_MAX = wait forever.
* @return OK on success, ERROR otherwise.
*/
int network_wait_connected(uint32_t timeout_ms);
const char *network_get_ip(void);
* Connect to a WiFi network using the NuttX wapi tool.
* On QEMU this is a no-op (network is provided by virtio-net).
* Saves credentials to config_store for persistence across reboots.
* @param iface WiFi interface name e.g. "wlan0" (NULL = use "wlan0")
*/
int network_wifi_connect(const char *iface, const char *ssid, const char *pass);
int network_wifi_reconnect(void);
#ifdef CONFIG_AI_AGENT_NET_RPMSG
#include <arpa/inet.h>
typedef enum {
NET_STATE_DISCONNECTED = 0,
NET_STATE_CONNECTED = 1,
} net_state_t;
typedef void (*net_state_cb_t)(net_state_t state, void* arg);
typedef struct {
net_state_t state;
char ip_addr[INET_ADDRSTRLEN];
char iface_name[16];
bool ble_connected;
int active_conns;
int iob_usage_pct;
time_t last_check;
time_t connected_since;
} net_status_t;
#define NET_MAX_TCP_CONNS 8
#define NET_TLS_BUF_LIMIT (64 * 1024)
#define NET_IOB_HIGH_WATERMARK 75
#define NET_IOB_LOW_WATERMARK 50
#define NET_MSG_QUEUE_TIMEOUT 300
#define NET_POLL_INTERVAL_MS 5000
#define NET_MAX_LISTENERS 8
#define NET_STARTUP_TIMEOUT_MS 30000
#define NET_BLE_REACT_MS 1000
#define NET_IP_DETECT_MS 500
int network_register_listener(net_state_cb_t cb, void* arg);
net_state_t network_get_state(void);
int network_get_active_conns(void);
int network_get_iob_usage(void);
int network_rpmsg_init(void);
int network_reconnect(void);
int network_set_dns(const char* primary, const char* secondary);
int network_diag(int argc, char** argv);
int network_save_proxy_config(const char* mode, const char* cpu_name);
int network_get_connect_timeout(void);
int network_get_read_timeout(void);
int network_get_retry_max(void);
int network_get_retry_base_sec(void);
const char* network_get_proxy_mode(void);
const char* network_get_rpmsg_cpu(void);
int network_acquire_resource(uint32_t timeout_ms);
void network_release_resource(void);
#endif