#ifndef OPENUF_SYSINFO_H #define OPENUF_SYSINFO_H /* * openuf - sysinfo.h * * Reads system statistics (CPU, RAM, interfaces, radios). * All readings come directly from the Linux kernel: * * /proc/stat → CPU usage (deltas between two snapshots) * /proc/meminfo → total/free/buffer/cache memory * /proc/net/dev → rx/tx counters per interface * /sys/class/net/ → speed, duplex, operstate, MAC * iw dev info → current channel, TX power * iw dev survey dump → channel utilization */ #include /* ── Memory ─────────────────────────────────────────────────────── */ typedef struct { long total_kb; long free_kb; long buffer_kb; long cached_kb; } mem_stats_t; int sysinfo_mem(mem_stats_t *out); /* ── CPU ─────────────────────────────────────────────────────────── */ /* Returns % CPU usage (0-100). The first call returns 0 (takes a snapshot). * Subsequent calls compute the delta relative to the previous one. * With a 10s interval this gives a good average of usage. */ int sysinfo_cpu_percent(void); /* ── Network interface ─────────────────────────────────────────────── */ typedef struct { char name[32]; char mac[32]; char ip[64]; bool up; int speed; /* Mbps: 10/100/1000; -1 if not available */ bool full_duplex; long long rx_bytes; long long tx_bytes; long long rx_packets; long long tx_packets; long long rx_errors; long long tx_errors; long long rx_dropped; long long tx_dropped; long long rx_frame; long long rx_multicast; } iface_stats_t; int sysinfo_iface(const char *ifname, iface_stats_t *out); /* ── Radio WiFi ─────────────────────────────────────────────────── */ typedef struct { char name[32]; char iface[32]; int channel; int tx_power; int cu_total; /* % total channel usage */ int cu_self_tx; /* % time spent transmitting */ int cu_self_rx; /* % time spent receiving */ int num_sta; int noise; /* dBm */ int nss; /* usable spatial streams */ int tx_antennas; /* configured TX chains */ int rx_antennas; /* configured RX chains */ long long tx_packets; long long tx_retries; long long tx_failed; long long tx_duration; /* microseconds */ long long rx_duration; /* microseconds */ } radio_stats_t; /* iface: "wlan0", "wlan1" */ int sysinfo_radio(const char *iface, radio_stats_t *out); #define MAX_SCAN_RESULTS 128 typedef struct { char bssid[32]; char essid[64]; int frequency; int channel; int signal; /* dBm */ int rssi; /* controller-compatible quality, 0-100 */ int age; /* seconds since last seen */ bool secured; } wifi_scan_t; /* Read the kernel's cached BSS list without starting a disruptive scan. */ int sysinfo_wifi_scan_cache(const char *iface, wifi_scan_t *out, int max_out); #endif /* OPENUF_SYSINFO_H */