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
@@ -17,6 +17,7 @@
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <montauk/string.h>
|
||||
#include <montauk/wifi.h>
|
||||
|
||||
using namespace montauk;
|
||||
|
||||
@@ -363,14 +364,30 @@ static int cmd_debug() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_connect(const char* ssid, const char* password) {
|
||||
static int cmd_connect(const char* ssid, const char* password, bool remember) {
|
||||
abi::WifiInfo info;
|
||||
if (!require_adapter(info)) return 1;
|
||||
|
||||
// No passphrase on the command line: fall back to the one the desktop or a
|
||||
// previous run saved, so "wifi connect Home" works on its own.
|
||||
char saved[montauk::wifi::PSK_CAP];
|
||||
if ((!password || !password[0])
|
||||
&& montauk::wifi::lookup(ssid, saved, sizeof(saved)) && saved[0]) {
|
||||
print("Using the saved passphrase for \""); print(ssid); print("\".\n");
|
||||
password = saved;
|
||||
remember = false; // already stored
|
||||
}
|
||||
|
||||
print("Connecting to \""); print(ssid); print("\"...\n");
|
||||
int rc = wifi_connect(ssid, password);
|
||||
|
||||
if (rc == 0) {
|
||||
if (remember && password && password[0]) {
|
||||
if (montauk::wifi::remember(ssid, password))
|
||||
print("Saved to 0:/config/wifi.toml for next time.\n");
|
||||
else
|
||||
print("wifi: could not write 0:/config/wifi.toml.\n");
|
||||
}
|
||||
print("Connected.\n");
|
||||
print("Run \"dhcp\" to get an address, then the network is usable\n");
|
||||
print("just like a wired connection.\n");
|
||||
@@ -410,6 +427,36 @@ static int cmd_connect(const char* ssid, const char* password) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cmd_saved() {
|
||||
montauk::wifi::SavedList list;
|
||||
montauk::wifi::saved_load(&list);
|
||||
|
||||
if (list.count == 0) {
|
||||
print("No saved networks.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
print("Saved networks (0:/config/wifi.toml):\n");
|
||||
for (int i = 0; i < list.count; i++) {
|
||||
print(" ");
|
||||
print(list.items[i].ssid);
|
||||
print("\n");
|
||||
}
|
||||
print("\nAutomatic reconnect is ");
|
||||
print(list.autoconnect ? "on" : "off");
|
||||
print(".\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_forget(const char* ssid) {
|
||||
if (montauk::wifi::forget(ssid)) {
|
||||
print("Forgot \""); print(ssid); print("\".\n");
|
||||
return 0;
|
||||
}
|
||||
print("wifi: \""); print(ssid); print("\" was not saved.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void usage() {
|
||||
print("usage: wifi [command]\n\n");
|
||||
print(" scan [seconds] scan and list nearby networks (default 5)\n");
|
||||
@@ -417,7 +464,11 @@ static void usage() {
|
||||
print(" debug diagnostics plus per-BSS scan detail\n");
|
||||
print(" connect <ssid> [key] join a network (open or WPA2/WPA3-PSK)\n");
|
||||
print(" status show the network currently joined\n");
|
||||
print(" disconnect leave the current network\n\n");
|
||||
print(" disconnect leave the current network\n");
|
||||
print(" saved list remembered networks\n");
|
||||
print(" forget <ssid> remove a remembered network\n\n");
|
||||
print("A passphrase given to connect is remembered, and one that was\n");
|
||||
print("remembered is used when connect is given only an SSID.\n\n");
|
||||
print("With no command, runs a 5 second scan.\n");
|
||||
}
|
||||
|
||||
@@ -454,7 +505,16 @@ extern "C" void _start() {
|
||||
while (p[n] && n < (int)sizeof(pass) - 1) { pass[n] = p[n]; n++; }
|
||||
while (n > 0 && pass[n - 1] == ' ') n--;
|
||||
pass[n] = '\0';
|
||||
exit(cmd_connect(ssid, pass));
|
||||
exit(cmd_connect(ssid, pass, true));
|
||||
} else if (streq(cmd, "saved")) {
|
||||
exit(cmd_saved());
|
||||
} else if (streq(cmd, "forget")) {
|
||||
char ssid[40];
|
||||
if (!next_token(&rest, ssid, sizeof(ssid))) {
|
||||
print("wifi: forget needs an SSID\n");
|
||||
exit(1);
|
||||
}
|
||||
exit(cmd_forget(ssid));
|
||||
} else if (streq(cmd, "disconnect")) {
|
||||
wifi_disconnect();
|
||||
print("Disconnected.\n");
|
||||
|
||||
Reference in new issue
Block a user