Network module: Wi-Fi and wired status, connect to Wi-Fi networks, Wi-Fi and airplane switches
CI / test (push) Failing after 18s
CI / test (push) Failing after 18s
- New `network` panel module (in the default panel, before the battery and the clock): signal bars and the
Wi-Fi network's name, a plug when wired, crossed-out bars offline or in airplane mode. Its
popup shows the status and the last action's outcome ("Couldn't connect to X: wrong
password?"), switches for Wi-Fi and airplane mode, and the networks in range (strongest
access point per name, the one in use first). Click a saved or open network to connect, a new
secured one to type its password in a field under it (Enter or Connect), the one in use to
disconnect, or "Forget" on a saved one. Opening the popup asks for a scan.
- compositor/network: NetworkManager over D-Bus through a small D-Bus client of our own
(wire format, EXTERNAL auth, async calls) on the existing @sys socket calls, so neither host
needed new imports. One ObjectManager.GetManagedObjects + GetAll every 2 s; GetSettings once
per saved connection; RequestScan, Device.Disconnect, WirelessEnabled / WwanEnabled,
ActivateConnection (saved), AddAndActivateConnection (new: open, WPA/WPA2 PSK, WPA3 SAE) and
Settings.Connection.Delete. Without NetworkManager it falls back to read-only status from
/proc/net/dev, /proc/net/wireless and /sys/class/net (no network names there), and looks for
NetworkManager again every 30 s.
- New `network` capability (wit/capabilities.wit): status, wifi-networks, scan, connect,
disconnect, forget, set-wifi-enabled, set-airplane-mode. Served from host tables 8/9 and a
`network(network-request)` request by the wasmer/wasmtime stub (compositor/wasm), host-wasm
and the MoonBit wasmhost. The stub's build_list learned bool fields; request strings are
wiped after use (Wi-Fi passwords).
- Running out of module instances now says "too many modules loaded".
- Deferred: VPN, hotspot, hidden networks, WEP and 802.1X (enterprise) networks, IP settings,
mobile broadband beyond the airplane switch, D-Bus signals (state is polled).
- Tests: D-Bus wire format (incl. the well-known Hello bytes), NetworkManager objects -> status
and list, security settings, /proc parsing; the module through the shell against a fake
backend (list, connect/forget/disconnect, password entry, switches, read-only); a host-wasm
test; and scripts/test-network-dbus.sh, which runs the backend against python-dbusmock's
NetworkManager on a private bus.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hizqNXcNDuef3gxa7D
This commit is contained in:
43 files changed
+4101
-32
No files matched your search
@@ -0,0 +1,3 @@
|
||||
Network status and control (NetworkManager), for the network panel module. The shell talks to
|
||||
NetworkManager over D-Bus; without it, status comes read-only from /sys/class/net and
|
||||
/proc/net, `can-manage` is false and the actions do nothing.
|
||||
@@ -0,0 +1,57 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
|
||||
///|
|
||||
fn wasmImportStatus(p0 : Int) = "chandra:desktop/network@0.1.0" "status"
|
||||
|
||||
///|
|
||||
fn wasmImportWifiNetworks(p0 : Int) = "chandra:desktop/network@0.1.0" "wifi-networks"
|
||||
|
||||
///|
|
||||
fn wasmImportScan() = "chandra:desktop/network@0.1.0" "scan"
|
||||
|
||||
///|
|
||||
fn wasmImportConnect(p0 : Int, p1 : Int, p2 : Int, p3 : Int) = "chandra:desktop/network@0.1.0" "connect"
|
||||
|
||||
///|
|
||||
fn wasmImportDisconnect() = "chandra:desktop/network@0.1.0" "disconnect"
|
||||
|
||||
///|
|
||||
fn wasmImportForget(p0 : Int, p1 : Int) = "chandra:desktop/network@0.1.0" "forget"
|
||||
|
||||
///|
|
||||
fn wasmImportSetWifiEnabled(p0 : Int) = "chandra:desktop/network@0.1.0" "set-wifi-enabled"
|
||||
|
||||
///|
|
||||
fn wasmImportSetAirplaneMode(p0 : Int) = "chandra:desktop/network@0.1.0" "set-airplane-mode"
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#|(func (param i32) (result i32) (local i32)
|
||||
#| local.get 0 i32.const 4 i32.add call $moonbit.gc.malloc
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
#|(func (param i32) (param i32) (result i32)
|
||||
#| local.get 0
|
||||
#| local.get 1 call $moonbit.init_array16
|
||||
#| local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
warnings = "-44"
|
||||
@@ -0,0 +1,93 @@
|
||||
// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
|
||||
///|
|
||||
pub(all) struct NetStatus {
|
||||
state : UInt; signal : UInt; name : String; message : String; wifi_enabled : Bool; airplane : Bool; can_manage : Bool; has_wifi : Bool
|
||||
}
|
||||
///|
|
||||
pub(all) struct WifiNetwork {
|
||||
ssid : String; signal : UInt; secured : Bool; active : Bool; saved : Bool
|
||||
}
|
||||
///|
|
||||
pub fn status() -> NetStatus {
|
||||
|
||||
let return_area = mbt_ffi_malloc(28)
|
||||
wasmImportStatus(return_area);
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
|
||||
|
||||
let result0 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 16), mbt_ffi_load32((return_area) + 20))
|
||||
let ret = NetStatus::{state : (mbt_ffi_load32((return_area) + 0)).reinterpret_as_uint(), signal : (mbt_ffi_load32((return_area) + 4)).reinterpret_as_uint(), name : result, message : result0, wifi_enabled : (mbt_ffi_load8_u((return_area) + 24) != 0), airplane : (mbt_ffi_load8_u((return_area) + 25) != 0), can_manage : (mbt_ffi_load8_u((return_area) + 26) != 0), has_wifi : (mbt_ffi_load8_u((return_area) + 27) != 0)}
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// Wi-Fi networks in range, the one in use first, then by signal (empty with Wi-Fi off).
|
||||
pub fn wifi_networks() -> Array[WifiNetwork] {
|
||||
|
||||
let return_area = mbt_ffi_malloc(8)
|
||||
wasmImportWifiNetworks(return_area);
|
||||
|
||||
let array : Array[WifiNetwork] = [];
|
||||
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
|
||||
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 16)
|
||||
|
||||
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
|
||||
|
||||
array.push(WifiNetwork::{ssid : result, signal : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), secured : (mbt_ffi_load8_u((iter_base) + 12) != 0), active : (mbt_ffi_load8_u((iter_base) + 13) != 0), saved : (mbt_ffi_load8_u((iter_base) + 14) != 0)})
|
||||
}
|
||||
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
|
||||
let ret = array
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
}
|
||||
///|
|
||||
/// Ask the Wi-Fi device to look for networks (the list fills in over a few seconds).
|
||||
pub fn scan() -> Unit {
|
||||
|
||||
wasmImportScan();
|
||||
|
||||
}
|
||||
///|
|
||||
/// Connect to `ssid`: a saved network as saved, a new one with `password` ("" when open).
|
||||
/// WPA/WPA2/WPA3 personal and open networks; the outcome shows in `status.message`.
|
||||
pub fn connect(ssid : String, password : String) -> Unit {
|
||||
|
||||
let ptr = mbt_ffi_str2ptr(ssid)
|
||||
|
||||
let ptr0 = mbt_ffi_str2ptr(password)
|
||||
wasmImportConnect(ptr, ssid.length(), ptr0, password.length());
|
||||
mbt_ffi_free(ptr)
|
||||
mbt_ffi_free(ptr0)
|
||||
|
||||
}
|
||||
///|
|
||||
/// Disconnect the Wi-Fi device.
|
||||
pub fn disconnect() -> Unit {
|
||||
|
||||
wasmImportDisconnect();
|
||||
|
||||
}
|
||||
///|
|
||||
/// Delete the saved connection(s) for `ssid`.
|
||||
pub fn forget(ssid : String) -> Unit {
|
||||
|
||||
let ptr = mbt_ffi_str2ptr(ssid)
|
||||
wasmImportForget(ptr, ssid.length());
|
||||
mbt_ffi_free(ptr)
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn set_wifi_enabled(on : Bool) -> Unit {
|
||||
|
||||
wasmImportSetWifiEnabled((if on { 1 } else { 0 }));
|
||||
|
||||
}
|
||||
///|
|
||||
pub fn set_airplane_mode(on : Bool) -> Unit {
|
||||
|
||||
wasmImportSetAirplaneMode((if on { 1 } else { 0 }));
|
||||
|
||||
}
|
||||
|
||||
@@ -67,8 +67,12 @@ fn wasmImportPickerStart() -> Int = "chandra:host/plasmoids@0.1.0" "picker-start
|
||||
fn wasmImportPickerPoll(p0 : Int) = "chandra:host/plasmoids@0.1.0" "picker-poll"
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
|
||||
///|
|
||||
#owned(str)
|
||||
@@ -76,12 +80,8 @@ extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
|
||||
extern "wasm" fn mbt_ffi_store64(offset : Int, value : Int64) =
|
||||
#|(func (param i32) (param i64) local.get 0 local.get 1 i64.store)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
|
||||
@@ -96,12 +96,8 @@ extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
@@ -110,11 +106,15 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
|
||||
#| local.tee 1 i32.const 0 call $moonbit.init_array8
|
||||
#| local.get 1)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load64(offset : Int) -> Int64 =
|
||||
#|(func (param i32) (result i64) local.get 0 i64.load)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_free(position : Int) =
|
||||
#|(func (param i32) local.get 0 call $moonbit.decref)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
|
||||
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
|
||||
|
||||
///|
|
||||
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
|
||||
#|(func (param i32) (result i32) local.get 0 i32.load)
|
||||
|
||||
@@ -71,6 +71,12 @@ pub(all) struct Loaded {
|
||||
imports : Array[String]
|
||||
}
|
||||
|
||||
pub(all) struct NetworkRequest {
|
||||
action : Int32
|
||||
ssid : String
|
||||
password : String
|
||||
}
|
||||
|
||||
pub(all) enum PickerState {
|
||||
Open
|
||||
Cancelled
|
||||
@@ -97,6 +103,7 @@ pub(all) enum Request {
|
||||
SetScreenOff(Int32)
|
||||
SetSuspendAfter(Int32)
|
||||
PowerAction(Int32)
|
||||
Network(NetworkRequest)
|
||||
}
|
||||
|
||||
pub(all) struct SettingChange {
|
||||
|
||||
@@ -24,6 +24,12 @@ pub(all) struct WindowEntry {
|
||||
id : UInt64; title : String; app_id : String; focused : Bool
|
||||
}
|
||||
///|
|
||||
/// A network module's action: 0 scan, 1 disconnect, 2/3 Wi-Fi off/on, 4/5 airplane mode
|
||||
/// off/on, 6 connect (ssid, password), 7 forget (ssid).
|
||||
pub(all) struct NetworkRequest {
|
||||
action : Int; ssid : String; password : String
|
||||
}
|
||||
///|
|
||||
/// A module turning a session setting on or off.
|
||||
pub(all) struct SettingChange {
|
||||
index : Int; on : Bool
|
||||
@@ -45,6 +51,7 @@ pub(all) enum Request {
|
||||
SetScreenOff(Int)
|
||||
SetSuspendAfter(Int)
|
||||
PowerAction(Int)
|
||||
Network(NetworkRequest)
|
||||
}
|
||||
///|
|
||||
/// A native file-chooser dialog (zenity on the host session) for "Add widget".
|
||||
@@ -375,7 +382,9 @@ pub fn set_config(handle : UInt, key : String, value : String) -> Bool {
|
||||
/// i32 ('i') or a LE u32 byte length + UTF-8 ('s'). `which`: 0 apps (sssss: id name comment
|
||||
/// category glyph), 1 windows (isii: id title focused minimized), 2 layouts (s), 3 modules
|
||||
/// (sssi: id name path loaded), 4 instances (sss: slot module name), 5 wallpapers (s), 6 session
|
||||
/// settings (s), 7 icons (si: app id, raster image handle from `raster.load-image`) served by `icons.app-icon`.
|
||||
/// settings (s), 7 icons (si: app id, raster image handle from `raster.load-image`) served by `icons.app-icon`,
|
||||
/// 8 network status (one row, iissiiii: state signal name message wifi-enabled airplane
|
||||
/// can-manage has-wifi), 9 Wi-Fi networks (siiii: ssid signal secured active saved).
|
||||
pub fn publish_table(which : UInt, rows : FixedArray[Byte]) -> Unit {
|
||||
|
||||
let ptr = mbt_ffi_bytes2ptr(rows)
|
||||
@@ -465,10 +474,10 @@ pub fn publish_windows(wins : Array[WindowEntry]) -> Unit {
|
||||
/// The next pending request, oldest first.
|
||||
pub fn next_request() -> Request? {
|
||||
|
||||
let return_area = mbt_ffi_malloc(16)
|
||||
let return_area = mbt_ffi_malloc(28)
|
||||
wasmImportNextRequest(return_area);
|
||||
|
||||
let lifted2 : Request? = match mbt_ffi_load8_u((return_area) + 0) {
|
||||
let lifted4 : Request? = match mbt_ffi_load8_u((return_area) + 0) {
|
||||
0 => Option::None
|
||||
1 => {
|
||||
|
||||
@@ -535,6 +544,14 @@ pub fn next_request() -> Request? {
|
||||
|
||||
Request::PowerAction(mbt_ffi_load32((return_area) + 8))
|
||||
}
|
||||
14 => {
|
||||
|
||||
let result2 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 12), mbt_ffi_load32((return_area) + 16))
|
||||
|
||||
let result3 = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 20), mbt_ffi_load32((return_area) + 24))
|
||||
|
||||
Request::Network(NetworkRequest::{action : mbt_ffi_load32((return_area) + 8), ssid : result2, password : result3})
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
|
||||
@@ -542,7 +559,7 @@ pub fn next_request() -> Request? {
|
||||
}
|
||||
_ => panic()
|
||||
}
|
||||
let ret = lifted2
|
||||
let ret = lifted4
|
||||
mbt_ffi_free(return_area)
|
||||
return ret
|
||||
|
||||
|
||||
Reference in new issue
Block a user