Create wifi backend abstraction

This commit is contained in:
nemunaire 2026-01-01 22:13:18 +07:00
commit 79c28da9c5
7 changed files with 401 additions and 174 deletions

View file

@ -0,0 +1,56 @@
package backend
// WiFiBackend is the interface that must be implemented by all WiFi backends (iwd, wpa_supplicant, etc.)
type WiFiBackend interface {
// Lifecycle Management
Initialize(interfaceName string) error
Close() error
// Network Discovery
ScanNetworks() error
GetOrderedNetworks() ([]BackendNetwork, error)
IsScanning() (bool, error)
// Connection Management
Connect(ssid, password string) error
Disconnect() error
GetConnectionState() (ConnectionState, error)
GetConnectedSSID() string
// Event Monitoring
StartEventMonitoring(callbacks EventCallbacks) error
StopEventMonitoring()
}
// BackendNetwork represents a WiFi network in a backend-agnostic format.
// Both iwd and wpa_supplicant backends convert their native representations to this type.
type BackendNetwork struct {
SSID string
SignalDBm int16 // Signal strength in dBm (-100 to 0)
SecurityType string // "open", "wep", "psk", "8021x"
BSSID string // MAC address of the access point
Frequency uint32 // Frequency in MHz (e.g., 2412 for channel 1, 5180 for channel 36)
}
// ConnectionState represents the WiFi connection state in a backend-agnostic way.
type ConnectionState string
const (
StateConnected ConnectionState = "connected"
StateDisconnected ConnectionState = "disconnected"
StateConnecting ConnectionState = "connecting"
StateDisconnecting ConnectionState = "disconnecting"
)
// EventCallbacks defines callback functions that backends use to notify the wifi package of events.
// This allows the wifi package to remain backend-agnostic while still receiving real-time updates.
type EventCallbacks struct {
// OnStateChange is called when the connection state changes
OnStateChange func(state ConnectionState, ssid string)
// OnScanComplete is called when a network scan completes
OnScanComplete func()
// OnSignalUpdate is called when signal strength changes for the connected network
OnSignalUpdate func(ssid string, signalDBm int16)
}