feat: wi-fi - expand support and fix issues, add GUI components
This commit is contained in:
1 parent
bbe1df62fd
commit
9eb21eb3e3
67 files changed
+4573
-245
No files matched your search
@@ -12,4 +12,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MONTAUK_BUILD_NUMBER 69
|
||||
#define MONTAUK_BUILD_NUMBER 84
|
||||
@@ -160,6 +160,38 @@ namespace montauk::abi {
|
||||
}
|
||||
}
|
||||
|
||||
// List the registered link-layer interfaces. The panel needs this to keep
|
||||
// wired and wireless status apart: the IP configuration is global, so the
|
||||
// only way to say which interface owns it is `active`.
|
||||
static int Sys_NetIfs(NetIfInfo* out, int maxCount) {
|
||||
if (out == nullptr || maxCount <= 0) return -1;
|
||||
|
||||
const auto* active = ::Net::NetIf::Active();
|
||||
int count = ::Net::NetIf::Count();
|
||||
int n = 0;
|
||||
|
||||
for (int i = 0; i < count && n < maxCount; i++) {
|
||||
const auto* iface = ::Net::NetIf::At(i);
|
||||
if (iface == nullptr) continue;
|
||||
|
||||
NetIfInfo& info = out[n];
|
||||
for (uint64_t k = 0; k < sizeof(info.name); k++) info.name[k] = '\0';
|
||||
for (uint64_t k = 0; k + 1 < sizeof(info.name) && iface->Name && iface->Name[k]; k++)
|
||||
info.name[k] = iface->Name[k];
|
||||
|
||||
const uint8_t* mac = iface->GetMac ? iface->GetMac() : nullptr;
|
||||
for (int k = 0; k < 6; k++) info.mac[k] = mac ? mac[k] : 0;
|
||||
|
||||
info.kind = iface->Type == ::Net::NetIf::Kind::Wireless
|
||||
? NETIF_KIND_WIRELESS : NETIF_KIND_ETHERNET;
|
||||
info.linkUp = (iface->IsLinkUp && iface->IsLinkUp()) ? 1 : 0;
|
||||
info.active = iface == active ? 1 : 0;
|
||||
info._pad[0] = info._pad[1] = info._pad[2] = 0;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static int Sys_SetNetCfg(const NetCfg* in) {
|
||||
if (in == nullptr) return -1;
|
||||
Net::SetIpAddress(in->ipAddress);
|
||||
|
||||
@@ -457,6 +457,20 @@ namespace montauk::abi {
|
||||
return Sys_WifiConnect((const char*)frame->arg1, (const char*)frame->arg2);
|
||||
case SYS_WIFI_DISCONNECT:
|
||||
return Sys_WifiDisconnect();
|
||||
case SYS_WIFI_SCAN_START:
|
||||
return Sys_WifiScanStart((uint32_t)frame->arg1);
|
||||
case SYS_WIFI_RESULTS:
|
||||
if ((int64_t)frame->arg2 < 0) return -1;
|
||||
if (!UserMemory::Range(frame->arg1, (uint64_t)frame->arg2 * sizeof(WifiNetwork), true)) return -1;
|
||||
return Sys_WifiResults((WifiNetwork*)frame->arg1, (int)frame->arg2);
|
||||
case SYS_WIFI_CONNECT_ASYNC:
|
||||
if (!UserMemory::String(frame->arg1, 64)) return -1;
|
||||
if (frame->arg2 != 0 && !UserMemory::String(frame->arg2, 128)) return -1;
|
||||
return Sys_WifiConnectAsync((const char*)frame->arg1, (const char*)frame->arg2);
|
||||
case SYS_NETIFS:
|
||||
if ((int64_t)frame->arg2 < 0) return -1;
|
||||
if (!UserMemory::Range(frame->arg1, (uint64_t)frame->arg2 * sizeof(NetIfInfo), true)) return -1;
|
||||
return Sys_NetIfs((NetIfInfo*)frame->arg1, (int)frame->arg2);
|
||||
case SYS_SUSPEND:
|
||||
return Sys_Suspend();
|
||||
case SYS_SETTZ:
|
||||
|
||||
@@ -302,6 +302,10 @@ namespace montauk::abi {
|
||||
static constexpr uint64_t SYS_WIFI_INFO = 159; // (WifiInfo*) -> 0, -1 if absent
|
||||
static constexpr uint64_t SYS_WIFI_CONNECT = 160; // (ssid, password) -> 0, <0 on error
|
||||
static constexpr uint64_t SYS_WIFI_DISCONNECT = 161; // () -> 0
|
||||
static constexpr uint64_t SYS_WIFI_SCAN_START = 162; // (timeoutMs) -> 0 started, 1 busy, -1 no adapter
|
||||
static constexpr uint64_t SYS_WIFI_RESULTS = 163; // (WifiNetwork*, maxCount) -> count, no radio work
|
||||
static constexpr uint64_t SYS_WIFI_CONNECT_ASYNC = 164; // (ssid, password) -> 0 accepted, <0 on error
|
||||
static constexpr uint64_t SYS_NETIFS = 165; // (NetIfInfo*, maxCount) -> count
|
||||
|
||||
// Tunable parameters (for SYS_SDR_SETPARAM / SYS_SDR_GETPARAM).
|
||||
static constexpr int SDR_PARAM_FREQ = 0; // center frequency, Hz
|
||||
@@ -708,6 +712,26 @@ namespace montauk::abi {
|
||||
uint8_t bssid[6];
|
||||
uint8_t connected; // 1 once the link can carry IP traffic
|
||||
uint8_t channel;
|
||||
int32_t lastError; // WIFI_ERR_* from the last async join, 0 = none
|
||||
uint32_t scanGeneration; // bumped every time a scan finishes
|
||||
uint8_t joining; // 1 while an async join is in flight
|
||||
uint8_t _pad[3];
|
||||
};
|
||||
|
||||
// Link-layer interface kinds reported in NetIfInfo.kind.
|
||||
static constexpr uint8_t NETIF_KIND_ETHERNET = 0;
|
||||
static constexpr uint8_t NETIF_KIND_WIRELESS = 1;
|
||||
|
||||
// One registered link-layer interface (returned by SYS_NETIFS). The IP
|
||||
// configuration is global to the stack, so it belongs to whichever
|
||||
// interface reports active = 1.
|
||||
struct NetIfInfo {
|
||||
char name[16]; // "eth0", "wlan0"
|
||||
uint8_t mac[6];
|
||||
uint8_t kind; // NETIF_KIND_*
|
||||
uint8_t linkUp;
|
||||
uint8_t active; // 1 if this is the interface carrying traffic
|
||||
uint8_t _pad[3];
|
||||
};
|
||||
|
||||
struct ThermalInfo {
|
||||
|
||||
@@ -23,11 +23,26 @@ namespace montauk::abi {
|
||||
return (int64_t)Drivers::Net::Wifi::GetInfo(buf);
|
||||
}
|
||||
|
||||
static int64_t Sys_WifiScanStart(uint32_t timeoutMs) {
|
||||
return (int64_t)Drivers::Net::Wifi::StartScan(timeoutMs);
|
||||
}
|
||||
|
||||
static int64_t Sys_WifiResults(WifiNetwork* buf, int maxCount) {
|
||||
if (!buf || maxCount <= 0) return -1;
|
||||
if (maxCount > 64) maxCount = 64;
|
||||
return (int64_t)Drivers::Net::Wifi::GetResults(buf, maxCount);
|
||||
}
|
||||
|
||||
static int64_t Sys_WifiConnect(const char* ssid, const char* password) {
|
||||
if (!ssid) return -1;
|
||||
return (int64_t)Drivers::Net::Wifi::Connect(ssid, password);
|
||||
}
|
||||
|
||||
static int64_t Sys_WifiConnectAsync(const char* ssid, const char* password) {
|
||||
if (!ssid) return -1;
|
||||
return (int64_t)Drivers::Net::Wifi::ConnectAsync(ssid, password);
|
||||
}
|
||||
|
||||
static int64_t Sys_WifiDisconnect() {
|
||||
return (int64_t)Drivers::Net::Wifi::Disconnect();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user