Refactored the Networking package. D0.1B
This commit is contained in:
@@ -28,10 +28,6 @@ const (
|
|||||||
nmDeviceTypeWifi uint32 = 2
|
nmDeviceTypeWifi uint32 = 2
|
||||||
nmDeviceStateActivated uint32 = 100
|
nmDeviceStateActivated uint32 = 100
|
||||||
APFlagsPrivacy uint32 = 0x00000001 // Equivalent to NM_802_11_AP_FLAGS_PRIVACY
|
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.
|
// ErrScanAborted is returned when a scan is cancelled via the stop channel.
|
||||||
@@ -88,8 +84,7 @@ type AccessPoint struct {
|
|||||||
Strength byte
|
Strength byte
|
||||||
IsProtected bool
|
IsProtected bool
|
||||||
IsActive bool
|
IsActive bool
|
||||||
WpaFlags uint32
|
KeyMgmt string
|
||||||
RsnFlags uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new network Manager and connects to the system D-Bus.
|
// 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)
|
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{
|
currentAP := AccessPoint{
|
||||||
ObjectPath: apPath,
|
ObjectPath: apPath,
|
||||||
SSID: ssidStr,
|
SSID: ssidStr,
|
||||||
Strength: strength,
|
Strength: strength,
|
||||||
IsProtected: isProtected,
|
IsProtected: isProtected,
|
||||||
WpaFlags: wpaFlags,
|
KeyMgmt: keyMgmt,
|
||||||
RsnFlags: rsnFlags,
|
|
||||||
}
|
}
|
||||||
if existingAP, ok := tempNetworkMap[ssidStr]; !ok || strength > existingAP.Strength {
|
if existingAP, ok := tempNetworkMap[ssidStr]; !ok || strength > existingAP.Strength {
|
||||||
tempNetworkMap[ssidStr] = currentAP
|
tempNetworkMap[ssidStr] = currentAP
|
||||||
@@ -328,7 +332,7 @@ func (m *Manager) Connect(wifiDevice Device, ap AccessPoint, passphrase string)
|
|||||||
|
|
||||||
if ap.IsProtected {
|
if ap.IsProtected {
|
||||||
settings["802-11-wireless-security"] = map[string]dbus.Variant{
|
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"),
|
"auth-alg": dbus.MakeVariant("open"),
|
||||||
"psk": dbus.MakeVariant(passphrase),
|
"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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user