Refactored the Networking package. D0.1B

This commit is contained in:
NeilClack
2026-06-18 11:46:46 -05:00
parent fe5543d50d
commit 26e84a4d23
+19 -9
View File
@@ -28,10 +28,6 @@ const (
nmDeviceTypeWifi uint32 = 2
nmDeviceStateActivated uint32 = 100
APFlagsPrivacy uint32 = 0x00000001 // Equivalent to NM_802_11_AP_FLAGS_PRIVACY
APSecKeyMgmtEAP uint32 = 0x00000020
APSecKeyMgmtPSK uint32 = 0x00000100
APSecKeyMgmtOWE uint32 = 0x00000200
APSecKeyMgmtSAE uint32 = 0x00000400
)
// ErrScanAborted is returned when a scan is cancelled via the stop channel.
@@ -88,8 +84,7 @@ type AccessPoint struct {
Strength byte
IsProtected bool
IsActive bool
WpaFlags uint32
RsnFlags uint32
KeyMgmt string
}
// New creates a new network Manager and connects to the system D-Bus.
@@ -277,13 +272,22 @@ func (m *Manager) scanAccessPoints(apPaths []dbus.ObjectPath) ([]AccessPoint, er
isProtected := (flags&APFlagsPrivacy != 0) || (wpaFlags != 0) || (rsnFlags != 0)
// Determine the key management type
var keyMgmt string
if wpaFlags != 0 {
keyMgmt = "wpa-psk"
} else if rsnFlags != 0 {
keyMgmt = "wpa-psk"
} else {
keyMgmt = "none"
}
currentAP := AccessPoint{
ObjectPath: apPath,
SSID: ssidStr,
Strength: strength,
IsProtected: isProtected,
WpaFlags: wpaFlags,
RsnFlags: rsnFlags,
KeyMgmt: keyMgmt,
}
if existingAP, ok := tempNetworkMap[ssidStr]; !ok || strength > existingAP.Strength {
tempNetworkMap[ssidStr] = currentAP
@@ -328,7 +332,7 @@ func (m *Manager) Connect(wifiDevice Device, ap AccessPoint, passphrase string)
if ap.IsProtected {
settings["802-11-wireless-security"] = map[string]dbus.Variant{
"key-mgmt": dbus.MakeVariant("wpa-psk"),
"key-mgmt": dbus.MakeVariant(ap.KeyMgmt),
"auth-alg": dbus.MakeVariant("open"),
"psk": dbus.MakeVariant(passphrase),
}
@@ -350,6 +354,12 @@ func (m *Manager) Connect(wifiDevice Device, ap AccessPoint, passphrase string)
}
log.Printf("Connection created: %s, Active path: %s", connectionPath, activeConnectionPath)
// Wait for the connection to be fully established
if _, err := m.WaitForInternet(30*time.Second, 5*time.Second); err != nil {
return fmt.Errorf("failed to establish internet connection: %w", err)
}
return nil
}