Documentation
¶
Overview ¶
Package spiderw provides a safe, strongly typed Go API for interacting with the iwd daemon (net.connman.iwd) over D-Bus.
Public callers start with Client, then reach the daemon, adapters, devices, stations, access points, networks, known networks, and basic service sets through typed wrappers. The package normalizes raw D-Bus values, avoids exposing D-Bus types in the public API, and maps lower-level failures into stable public error categories.
State can be observed as events rather than polled: every object with properties offers a generic SubscribePropertiesChanged plus typed convenience subscriptions. An absent value arrives as nil - iwd signals that an object is gone by invalidating the property rather than sending a null path - so a disconnected station reports a nil connected network, and a forgotten network a nil known network. Watching a station's connected access point is the only way to observe a roam: the associated BSS changes while the state stays StationStateConnected and the connected network does not change at all.
Credentials are supplied by registering an Agent (Client.RegisterAgent), and RSSI thresholds by a signal-level agent (Station.MonitorSignalLevel).
Example (ErrorHandling) ¶
Example_errorHandling shows how to classify a failure with the public error sentinels and inspect its structured fields.
package main
import (
"context"
"errors"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
_, err = client.Daemon().Info(ctx)
if err != nil {
// Match a category with the sentinel.
if errors.Is(err, spiderw.ErrUnavailable) {
fmt.Println("iwd is unavailable")
}
// Inspect the structured fields with errors.AsType.
if swErr, ok := errors.AsType[*spiderw.Error](err); ok && swErr.Resource == spiderw.ResourceDaemon {
fmt.Printf("daemon error in %s: %v\n", swErr.Op, err)
}
}
}
Output:
Index ¶
- Variables
- type AccessPoint
- func (a *AccessPoint) Frequency(ctx context.Context) (*uint32, error)
- func (a *AccessPoint) GroupCipher(ctx context.Context) (*string, error)
- func (a *AccessPoint) Name() string
- func (a *AccessPoint) OrderedNetworks(ctx context.Context) ([]AccessPointOrderedNetwork, error)
- func (a *AccessPoint) PairwiseCiphers(ctx context.Context) ([]string, error)
- func (a *AccessPoint) Path() string
- func (a *AccessPoint) Properties(ctx context.Context) (*AccessPointProperties, error)
- func (a *AccessPoint) SSID(ctx context.Context) (*string, error)
- func (a *AccessPoint) Scan(ctx context.Context) error
- func (a *AccessPoint) Scanning(ctx context.Context) (bool, error)
- func (a *AccessPoint) Start(ctx context.Context, ssid, psk string) error
- func (a *AccessPoint) StartProfile(ctx context.Context, ssid string) error
- func (a *AccessPoint) Started(ctx context.Context) (bool, error)
- func (a *AccessPoint) Stop(ctx context.Context) error
- func (a *AccessPoint) SubscribePropertiesChanged(ctx context.Context, fn func(AccessPointPropertiesChanged)) (UnsubscribeFunc, error)
- func (a *AccessPoint) SubscribeScanningChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- func (a *AccessPoint) SubscribeStartedChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- type AccessPointOrderedNetwork
- type AccessPointProperties
- type AccessPointPropertiesChanged
- type AccessPointRef
- type Adapter
- func (a *Adapter) Model(ctx context.Context) (*string, error)
- func (a *Adapter) Name(ctx context.Context) (string, error)
- func (a *Adapter) Path() string
- func (a *Adapter) Powered(ctx context.Context) (bool, error)
- func (a *Adapter) Properties(ctx context.Context) (*AdapterProperties, error)
- func (a *Adapter) SetPowered(ctx context.Context, powered bool) error
- func (a *Adapter) SubscribePoweredChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- func (a *Adapter) SubscribePropertiesChanged(ctx context.Context, fn func(AdapterPropertiesChanged)) (UnsubscribeFunc, error)
- func (a *Adapter) SupportedModes(ctx context.Context) ([]Mode, error)
- func (a *Adapter) SupportsAP(ctx context.Context) (bool, error)
- func (a *Adapter) SupportsAdHoc(ctx context.Context) (bool, error)
- func (a *Adapter) SupportsMode(ctx context.Context, mode Mode) (bool, error)
- func (a *Adapter) SupportsStation(ctx context.Context) (bool, error)
- func (a *Adapter) Vendor(ctx context.Context) (*string, error)
- type AdapterProperties
- type AdapterPropertiesChanged
- type AdapterRef
- type Agent
- type AgentConfig
- type BasicServiceSet
- type BasicServiceSetProperties
- type BasicServiceSetRef
- type Bus
- type Client
- func (c *Client) AccessPoint(ctx context.Context, path string) (*AccessPoint, error)
- func (c *Client) Adapter(ctx context.Context, path string) (*Adapter, error)
- func (c *Client) AllAccessPoints(ctx context.Context) ([]*AccessPoint, error)
- func (c *Client) AllAdapters(ctx context.Context) ([]*Adapter, error)
- func (c *Client) AllBasicServiceSets(ctx context.Context) ([]*BasicServiceSet, error)
- func (c *Client) AllDevices(ctx context.Context) ([]*Device, error)
- func (c *Client) AllKnownNetworks(ctx context.Context) ([]*KnownNetwork, error)
- func (c *Client) AllNetworks(ctx context.Context) ([]*Network, error)
- func (c *Client) AllStations(ctx context.Context) ([]*Station, error)
- func (c *Client) BasicServiceSet(ctx context.Context, path string) (*BasicServiceSet, error)
- func (c *Client) Close() error
- func (c *Client) Daemon() *Daemon
- func (c *Client) Device(ctx context.Context, path string) (*Device, error)
- func (c *Client) KnownNetwork(ctx context.Context, path string) (*KnownNetwork, error)
- func (c *Client) Network(ctx context.Context, path string) (*Network, error)
- func (c *Client) RegisterAgent(ctx context.Context, cfg AgentConfig) (*Agent, error)
- func (c *Client) Station(ctx context.Context, path string) (*Station, error)
- type Daemon
- func (d *Daemon) AccessPoints(ctx context.Context) ([]AccessPointRef, error)
- func (d *Daemon) Adapters(ctx context.Context) ([]AdapterRef, error)
- func (d *Daemon) BasicServiceSets(ctx context.Context) ([]BasicServiceSetRef, error)
- func (d *Daemon) Devices(ctx context.Context) ([]DeviceRef, error)
- func (d *Daemon) Info(ctx context.Context) (*DaemonInfo, error)
- func (d *Daemon) KnownNetworks(ctx context.Context) ([]KnownNetworkRef, error)
- func (d *Daemon) NetworkConfigurationEnabled(ctx context.Context) (bool, error)
- func (d *Daemon) Networks(ctx context.Context) ([]NetworkRef, error)
- func (d *Daemon) StateDirectory(ctx context.Context) (string, error)
- func (d *Daemon) Stations(ctx context.Context) ([]StationRef, error)
- func (d *Daemon) Version(ctx context.Context) (string, error)
- type DaemonInfo
- type Device
- func (d *Device) Adapter(ctx context.Context) (string, error)
- func (d *Device) Address(ctx context.Context) (string, error)
- func (d *Device) Mode(ctx context.Context) (Mode, error)
- func (d *Device) Name(ctx context.Context) (string, error)
- func (d *Device) Path() string
- func (d *Device) Powered(ctx context.Context) (bool, error)
- func (d *Device) Properties(ctx context.Context) (*DeviceProperties, error)
- func (d *Device) SetMode(ctx context.Context, mode Mode) error
- func (d *Device) SetPowered(ctx context.Context, powered bool) error
- func (d *Device) SubscribeModeChanged(ctx context.Context, fn func(Mode)) (UnsubscribeFunc, error)
- func (d *Device) SubscribePoweredChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- func (d *Device) SubscribePropertiesChanged(ctx context.Context, fn func(DevicePropertiesChanged)) (UnsubscribeFunc, error)
- type DeviceProperties
- type DevicePropertiesChanged
- type DeviceRef
- type Error
- type HiddenAccessPoint
- type Kind
- type KnownNetwork
- func (k *KnownNetwork) AutoConnect(ctx context.Context) (bool, error)
- func (k *KnownNetwork) Forget(ctx context.Context) error
- func (k *KnownNetwork) Hidden(ctx context.Context) (bool, error)
- func (k *KnownNetwork) LastConnectedTime(ctx context.Context) (*string, error)
- func (k *KnownNetwork) Name(ctx context.Context) (string, error)
- func (k *KnownNetwork) Path() string
- func (k *KnownNetwork) Properties(ctx context.Context) (*KnownNetworkProperties, error)
- func (k *KnownNetwork) SetAutoConnect(ctx context.Context, autoConnect bool) error
- func (k *KnownNetwork) SubscribeAutoConnectChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- func (k *KnownNetwork) SubscribeHiddenChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- func (k *KnownNetwork) SubscribeLastConnectedTimeChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
- func (k *KnownNetwork) SubscribePropertiesChanged(ctx context.Context, fn func(KnownNetworkPropertiesChanged)) (UnsubscribeFunc, error)
- func (k *KnownNetwork) Type(ctx context.Context) (NetworkType, error)
- type KnownNetworkProperties
- type KnownNetworkPropertiesChanged
- type KnownNetworkRef
- type Mode
- type Network
- func (n *Network) Connect(ctx context.Context) error
- func (n *Network) Connected(ctx context.Context) (bool, error)
- func (n *Network) Device(ctx context.Context) (string, error)
- func (n *Network) ExtendedServiceSet(ctx context.Context) ([]string, error)
- func (n *Network) KnownNetwork(ctx context.Context) (*string, error)
- func (n *Network) Name(ctx context.Context) (string, error)
- func (n *Network) Path() string
- func (n *Network) Properties(ctx context.Context) (*NetworkProperties, error)
- func (n *Network) SubscribeConnectedChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- func (n *Network) SubscribeExtendedServiceSetChanged(ctx context.Context, fn func([]string)) (UnsubscribeFunc, error)
- func (n *Network) SubscribeKnownNetworkChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
- func (n *Network) SubscribePropertiesChanged(ctx context.Context, fn func(NetworkPropertiesChanged)) (UnsubscribeFunc, error)
- func (n *Network) Type(ctx context.Context) (NetworkType, error)
- type NetworkProperties
- type NetworkPropertiesChanged
- type NetworkRef
- type NetworkType
- type OrderedNetwork
- type Resource
- type SignalLevelAgent
- type SignalLevelConfig
- type SimpleConfiguration
- type Station
- func (s *Station) Affinities(ctx context.Context) ([]string, error)
- func (s *Station) ConnectHiddenNetwork(ctx context.Context, name string) error
- func (s *Station) ConnectedAccessPoint(ctx context.Context) (*string, error)
- func (s *Station) ConnectedNetwork(ctx context.Context) (*string, error)
- func (s *Station) Disconnect(ctx context.Context) error
- func (s *Station) HiddenAccessPoints(ctx context.Context) ([]HiddenAccessPoint, error)
- func (s *Station) MonitorSignalLevel(ctx context.Context, cfg SignalLevelConfig) (*SignalLevelAgent, error)
- func (s *Station) Name() string
- func (s *Station) OrderedNetworks(ctx context.Context) ([]OrderedNetwork, error)
- func (s *Station) Path() string
- func (s *Station) Properties(ctx context.Context) (*StationProperties, error)
- func (s *Station) Scan(ctx context.Context) error
- func (s *Station) Scanning(ctx context.Context) (bool, error)
- func (s *Station) SetAffinities(ctx context.Context, paths []string) error
- func (s *Station) SimpleConfiguration(ctx context.Context) (*SimpleConfiguration, error)
- func (s *Station) State(ctx context.Context) (StationState, error)
- func (s *Station) SubscribeAffinitiesChanged(ctx context.Context, fn func([]string)) (UnsubscribeFunc, error)
- func (s *Station) SubscribeConnectedAccessPointChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
- func (s *Station) SubscribeConnectedNetworkChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
- func (s *Station) SubscribePropertiesChanged(ctx context.Context, fn func(StationPropertiesChanged)) (UnsubscribeFunc, error)
- func (s *Station) SubscribeScanningChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
- func (s *Station) SubscribeStateChanged(ctx context.Context, fn func(StationState)) (UnsubscribeFunc, error)
- type StationProperties
- type StationPropertiesChanged
- type StationRef
- type StationState
- type UnsubscribeFunc
Examples ¶
- Package (ErrorHandling)
- Adapter.Properties
- Adapter.SubscribePoweredChanged
- Adapter.SupportsMode
- Client.Adapter
- Client.AllAdapters
- Client.AllBasicServiceSets
- Client.BasicServiceSet
- Client.Device
- Client.KnownNetwork
- Client.Network
- Client.RegisterAgent
- Client.Station
- Daemon.Adapters
- Daemon.Info
- KnownNetwork.SetAutoConnect
- Network.Connect
- Network.ExtendedServiceSet
- NewClient
- Station.ConnectHiddenNetwork
- Station.Scan
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnavailable = errors.New("unavailable") // ErrInvalidState matches errors whose public kind is KindInvalidState. ErrInvalidState = errors.New("invalid state") // ErrInternal matches errors whose public kind is KindInternal. ErrInternal = errors.New("internal error") // ErrInvalidArgument matches errors whose public kind is KindInvalidArgument. ErrInvalidArgument = errors.New("invalid argument") // ErrSpiderw matches all structured errors returned by the public API. ErrSpiderw = errors.New("spiderw api error") // ErrNoAgent matches errors caused by iwd rejecting an operation because no // credentials agent is registered. Connecting to a secured network that is // not already known requires a registered agent; until then, Network.Connect // returns an error matching ErrNoAgent. ErrNoAgent = core.ErrNoAgent // The following sentinels match named iwd D-Bus errors surfaced by operations // such as Network.Connect. Use errors.Is to react to a specific iwd outcome // (for example, retry on ErrInProgress, give up on ErrNotSupported) without // parsing error text. Note: current iwd reports a busy/in-progress condition // as ErrInProgress; ErrBusy and ErrTimeout are retained for compatibility but // are not emitted by iwd today. ErrAborted = core.ErrAborted ErrBusy = core.ErrBusy ErrFailed = core.ErrFailed ErrNotSupported = core.ErrNotSupported ErrTimeout = core.ErrTimeout ErrInProgress = core.ErrInProgress ErrNotConfigured = core.ErrNotConfigured // ErrNotFound and ErrAlreadyExists are surfaced by the agent manager // (UnregisterAgent on an unregistered agent; RegisterAgent when another agent // already owns the connection), among other operations. ErrNotFound = core.ErrNotFound ErrAlreadyExists = core.ErrAlreadyExists // ErrInvalidArguments matches iwd's named net.connman.iwd.InvalidArguments // error. It is distinct from ErrInvalidArgument (singular), which matches any // public KindInvalidArgument error spiderw itself raises. ErrInvalidArguments = core.ErrInvalidArguments ErrInvalidFormat = core.ErrInvalidFormat ErrNotConnected = core.ErrNotConnected ErrNotImplemented = core.ErrNotImplemented ErrServiceSetOverlap = core.ErrServiceSetOverlap ErrAlreadyProvisioned = core.ErrAlreadyProvisioned ErrNotHidden = core.ErrNotHidden ErrNotAvailable = core.ErrNotAvailable // ErrPermissionDenied matches iwd's net.connman.iwd.PermissionDenied, returned // when the caller lacks permission for a privileged operation. ErrPermissionDenied = core.ErrPermissionDenied // The following match iwd's WSC (SimpleConfiguration) enrollment errors, so a // caller can react to a specific WSC outcome with errors.Is. ErrWSCSessionOverlap // means more than one access point was in PushButton mode; ErrWSCWalkTimeExpired // and ErrWSCTimeExpired mean no access point was found in PushButton / PIN mode // within the allotted time. ErrWSCSessionOverlap = core.ErrWSCSessionOverlap ErrWSCNoCredentials = core.ErrWSCNoCredentials ErrWSCNotReachable = core.ErrWSCNotReachable ErrWSCWalkTimeExpired = core.ErrWSCWalkTimeExpired ErrWSCTimeExpired = core.ErrWSCTimeExpired )
Error sentinels support errors.Is checks against public error categories.
Functions ¶
This section is empty.
Types ¶
type AccessPoint ¶ added in v0.13.0
type AccessPoint struct {
// contains filtered or unexported fields
}
AccessPoint is a device running in AP mode, hosting a network. Obtain one with Client.AccessPoint or Client.AllAccessPoints.
func (*AccessPoint) Frequency ¶ added in v0.13.0
func (a *AccessPoint) Frequency(ctx context.Context) (*uint32, error)
Frequency returns the operating frequency in MHz, or nil when not running.
func (*AccessPoint) GroupCipher ¶ added in v0.13.0
func (a *AccessPoint) GroupCipher(ctx context.Context) (*string, error)
GroupCipher returns the broadcast/multicast cipher, or nil when not running.
func (*AccessPoint) Name ¶ added in v0.13.0
func (a *AccessPoint) Name() string
Name returns the underlying device's name (e.g. "wlan1"). This is the device identity, not the hosted network's SSID - see SSID.
func (*AccessPoint) OrderedNetworks ¶ added in v0.13.0
func (a *AccessPoint) OrderedNetworks(ctx context.Context) ([]AccessPointOrderedNetwork, error)
OrderedNetworks returns the networks from the most recent access-point scan, ordered by signal strength.
func (*AccessPoint) PairwiseCiphers ¶ added in v0.13.0
func (a *AccessPoint) PairwiseCiphers(ctx context.Context) ([]string, error)
PairwiseCiphers returns the negotiated unicast ciphers, or nil when not running.
func (*AccessPoint) Path ¶ added in v0.13.0
func (a *AccessPoint) Path() string
Path returns the access point's D-Bus object path (a device path).
func (*AccessPoint) Properties ¶ added in v0.13.0
func (a *AccessPoint) Properties(ctx context.Context) (*AccessPointProperties, error)
Properties returns a snapshot of every access-point property in one call.
func (*AccessPoint) SSID ¶ added in v0.13.0
func (a *AccessPoint) SSID(ctx context.Context) (*string, error)
SSID returns the hosted network's SSID (iwd's "Name" property), or nil when the access point is not running.
func (*AccessPoint) Scan ¶ added in v0.13.0
func (a *AccessPoint) Scan(ctx context.Context) error
Scan schedules an access-point scan. It is asynchronous; the Scanning property tracks progress.
func (*AccessPoint) Scanning ¶ added in v0.13.0
func (a *AccessPoint) Scanning(ctx context.Context) (bool, error)
Scanning reports whether the access point is scanning.
func (*AccessPoint) Start ¶ added in v0.13.0
func (a *AccessPoint) Start(ctx context.Context, ssid, psk string) error
Start starts a PSK-secured access point advertising ssid with passphrase psk (SSID 1-32 bytes, passphrase 8-63 characters). It blocks until iwd reports the outcome. iwd returns an error matching ErrAlreadyExists when an AP is already running.
func (*AccessPoint) StartProfile ¶ added in v0.13.0
func (a *AccessPoint) StartProfile(ctx context.Context, ssid string) error
StartProfile starts an access point from the stored profile named ssid, which may configure security modes beyond PSK. iwd returns an error matching ErrNotFound when no such profile exists.
func (*AccessPoint) Started ¶ added in v0.13.0
func (a *AccessPoint) Started(ctx context.Context) (bool, error)
Started reports whether the access point is running.
func (*AccessPoint) Stop ¶ added in v0.13.0
func (a *AccessPoint) Stop(ctx context.Context) error
Stop stops the running access point.
func (*AccessPoint) SubscribePropertiesChanged ¶ added in v0.13.0
func (a *AccessPoint) SubscribePropertiesChanged(ctx context.Context, fn func(AccessPointPropertiesChanged)) (UnsubscribeFunc, error)
SubscribePropertiesChanged registers fn for access-point property changes.
func (*AccessPoint) SubscribeScanningChanged ¶ added in v0.13.0
func (a *AccessPoint) SubscribeScanningChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribeScanningChanged registers fn for changes to the Scanning state.
func (*AccessPoint) SubscribeStartedChanged ¶ added in v0.13.0
func (a *AccessPoint) SubscribeStartedChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribeStartedChanged registers fn for changes to the Started state.
type AccessPointOrderedNetwork ¶ added in v0.13.0
type AccessPointOrderedNetwork struct {
// Name is the scanned network's SSID.
Name string
// SignalStrength is the signal strength in dBm (e.g. -60.5). iwd reports it in
// units of 100 * dBm; spiderw exposes it as dBm here.
SignalStrength float64
// Type is the network security type.
Type NetworkType
}
AccessPointOrderedNetwork is one network an access point heard while scanning.
type AccessPointProperties ¶ added in v0.13.0
type AccessPointProperties struct {
// Started reports whether the access point is running.
Started bool
// Scanning reports whether the access point is scanning. iwd only exposes this
// while the AP is started, so it reads false when the AP is not running.
Scanning bool
// SSID is the hosted network's SSID (iwd's "Name" property), or nil when the
// AP is not running.
SSID *string
// Frequency is the operating frequency in MHz, or nil when not running.
Frequency *uint32
// PairwiseCiphers are the negotiated unicast ciphers (e.g. "CCMP"), or nil.
PairwiseCiphers []string
// GroupCipher is the broadcast/multicast cipher, or nil.
GroupCipher *string
}
AccessPointProperties is a snapshot of an access point's state. Started is always present; the rest are absent (nil, or false for Scanning) while the AP is not running.
type AccessPointPropertiesChanged ¶ added in v0.13.0
type AccessPointPropertiesChanged struct {
// Changed holds the changed property values keyed by name.
Changed map[string]any
// Invalidated names properties whose values should be re-read if needed.
Invalidated []string
}
AccessPointPropertiesChanged is a normalized access-point property-change event.
type AccessPointRef ¶ added in v0.13.0
type AccessPointRef struct {
// Path is the canonical D-Bus object path for the access point (a device
// path).
Path string
// Name is the co-located device's Name (best-effort; empty if unavailable).
Name string
}
AccessPointRef is a lightweight reference to an access point (a device in AP mode). Name is the co-located device's Name (e.g. "wlan1"), not the hosted network's SSID.
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter provides high-level operations for a specific iwd adapter object.
func (*Adapter) Path ¶ added in v0.2.0
Path returns the D-Bus object path the adapter was constructed from.
Path is static adapter identity, not an iwd property: it requires no D-Bus round-trip and never fails. Path returns "" for a nil receiver.
func (*Adapter) Properties ¶ added in v0.2.0
func (a *Adapter) Properties(ctx context.Context) (*AdapterProperties, error)
Properties reads every adapter property in a single D-Bus call (Properties.GetAll) instead of one call per property. Prefer it when you need several properties at once, such as building an overview of an adapter.
Example ¶
ExampleAdapter_Properties reads every adapter property in a single Properties.GetAll call instead of one D-Bus call per property.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Adapters(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no adapters found")
}
adapter, err := client.Adapter(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
// One round-trip fetches Powered, Name, Model, Vendor, and SupportedModes
// together. Model and Vendor are nil when iwd does not report them.
props, err := adapter.Properties(ctx)
if err != nil {
log.Fatal(err)
}
model := "unknown"
if props.Model != nil {
model = *props.Model
}
fmt.Printf("%s powered=%t model=%s modes=%v\n",
props.Name, props.Powered, model, props.SupportedModes)
}
Output:
func (*Adapter) SetPowered ¶
SetPowered changes whether the adapter is powered.
func (*Adapter) SubscribePoweredChanged ¶
func (a *Adapter) SubscribePoweredChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribePoweredChanged registers fn for adapter powered-state changes and returns a handle that unregisters the callback.
Example ¶
ExampleAdapter_SubscribePoweredChanged registers a callback for powered-state changes and unsubscribes when finished.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Adapters(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no adapters found")
}
adapter, err := client.Adapter(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
unsubscribe, err := adapter.SubscribePoweredChanged(ctx, func(powered bool) {
fmt.Println("powered changed:", powered)
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = unsubscribe.Unsubscribe() }()
// ... do work while the subscription is active ...
}
Output:
func (*Adapter) SubscribePropertiesChanged ¶
func (a *Adapter) SubscribePropertiesChanged(ctx context.Context, fn func(AdapterPropertiesChanged)) (UnsubscribeFunc, error)
SubscribePropertiesChanged registers fn for adapter property-change signals and returns a handle that unregisters the callback.
func (*Adapter) SupportedModes ¶
SupportedModes returns the adapter modes currently reported by iwd.
func (*Adapter) SupportsAP ¶
SupportsAP reports whether the adapter supports access point mode.
func (*Adapter) SupportsAdHoc ¶
SupportsAdHoc reports whether the adapter supports ad-hoc mode.
func (*Adapter) SupportsMode ¶
SupportsMode reports whether the adapter supports the provided mode.
Example ¶
ExampleAdapter_SupportsMode checks whether an adapter supports station mode.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Adapters(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no adapters found")
}
adapter, err := client.Adapter(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
ok, err := adapter.SupportsMode(ctx, spiderw.ModeStation)
if err != nil {
log.Fatal(err)
}
fmt.Println("supports station mode:", ok)
}
Output:
func (*Adapter) SupportsStation ¶
SupportsStation reports whether the adapter supports station mode.
type AdapterProperties ¶ added in v0.2.0
type AdapterProperties struct {
// Powered reports whether the adapter is currently powered.
Powered bool
// Name is the adapter's human-friendly Name property.
Name string
// Model is the adapter's Model property, or nil when not reported.
Model *string
// Vendor is the adapter's Vendor property, or nil when not reported.
Vendor *string
// SupportedModes lists the adapter's supported operating modes.
SupportedModes []Mode
}
AdapterProperties is a snapshot of all adapter properties read in a single D-Bus call. Model and Vendor are nil when iwd does not report them.
type AdapterPropertiesChanged ¶
type AdapterPropertiesChanged struct {
// Changed contains new property values keyed by property name.
Changed map[string]any
// Invalidated contains property names whose values should be re-read if needed.
Invalidated []string
}
AdapterPropertiesChanged describes adapter properties reported by a D-Bus PropertiesChanged signal. Changed contains the new values by property name; Invalidated contains property names whose values should be re-read if needed.
type AdapterRef ¶
type AdapterRef struct {
// Path is the canonical D-Bus object path for the adapter.
Path string
// Name is the adapter's human-friendly Name property.
Name string
}
AdapterRef is a lightweight reference to an adapter discovered by the iwd daemon.
type Agent ¶ added in v0.6.0
type Agent struct {
// contains filtered or unexported fields
}
Agent is a registered credentials agent handle returned by Client.RegisterAgent. Call Unregister when the agent is no longer needed; the owning Client also unregisters it on Close.
type AgentConfig ¶ added in v0.6.0
type AgentConfig struct {
// Passphrase supplies the passphrase for a PSK network.
Passphrase func(ctx context.Context, networkPath string) (string, error)
// PrivateKeyPassphrase supplies the passphrase protecting an 802.1x private
// key.
PrivateKeyPassphrase func(ctx context.Context, networkPath string) (string, error)
// UserNameAndPassword supplies the username and password for an 802.1x
// network.
UserNameAndPassword func(ctx context.Context, networkPath string) (user, password string, err error)
// UserPassword supplies the password for an 802.1x network whose username iwd
// already knows.
UserPassword func(ctx context.Context, networkPath, user string) (string, error)
// OnCancel is called when iwd aborts a pending request. reason is one of
// iwd's cancel reasons (for example "out-of-range", "user-canceled",
// "timed-out").
OnCancel func(reason string)
// OnRelease is called when iwd no longer needs the agent (it was unregistered
// or replaced).
OnRelease func()
}
AgentConfig supplies the callbacks iwd invokes when it needs credentials to connect to a secured network that is not already known. Register it with Client.RegisterAgent.
Each request callback returns the requested credential, or a non-nil error to decline; a nil callback also declines (iwd receives a Canceled reply). At least one request callback (Passphrase, PrivateKeyPassphrase, UserNameAndPassword, or UserPassword) must be set, or RegisterAgent returns an invalid-argument error.
networkPath is the iwd Network object path the request concerns; resolve it to a handle with Client.Network if you need network details. The supplied context is canceled if the request is aborted (for example by iwd's Cancel or by Agent.Unregister), so long-running callbacks such as interactive prompts should honor it. OnCancel and OnRelease are optional notifications.
Testing status: the Passphrase (PSK) path is tested end to end against the iwd mock. The 802.1x callbacks (PrivateKeyPassphrase, UserNameAndPassword, UserPassword) are wired through every layer but are not yet exercised against the mock or validated on hardware; treat them as experimental.
type BasicServiceSet ¶ added in v0.4.0
type BasicServiceSet struct {
// contains filtered or unexported fields
}
BasicServiceSet provides high-level operations for a specific iwd basic service set (BSS) object.
A BSS is a single access point or peer that the radio can see; iwd exposes it as a read-only object whose only property is its Address (BSSID).
func (*BasicServiceSet) Address ¶ added in v0.4.0
func (b *BasicServiceSet) Address(ctx context.Context) (string, error)
Address returns the BSS's hardware (BSSID) address.
func (*BasicServiceSet) Path ¶ added in v0.4.0
func (b *BasicServiceSet) Path() string
Path returns the D-Bus object path the BSS was constructed from.
Path is static object identity, not an iwd property: it requires no D-Bus round-trip and never fails. Path returns "" for a nil receiver.
func (*BasicServiceSet) Properties ¶ added in v0.4.0
func (b *BasicServiceSet) Properties(ctx context.Context) (*BasicServiceSetProperties, error)
Properties reads every BSS property in a single D-Bus call (Properties.GetAll). The iwd BasicServiceSet interface exposes only Address.
type BasicServiceSetProperties ¶ added in v0.4.0
type BasicServiceSetProperties struct {
// Address is the BSS's hardware (BSSID) address.
Address string
}
BasicServiceSetProperties is a snapshot of all BSS properties read in a single D-Bus call. The iwd BasicServiceSet interface exposes only Address.
type BasicServiceSetRef ¶ added in v0.4.0
type BasicServiceSetRef struct {
// Path is the canonical D-Bus object path for the BSS.
Path string
// Address is the BSS's hardware (BSSID) address.
Address string
}
BasicServiceSetRef is a lightweight reference to a basic service set (BSS) discovered by the iwd daemon.
type Bus ¶
type Bus bool
Bus selects which D-Bus message bus a Client connects to.
Bus is a defined boolean type, so call sites may pass the named constants (SystemBus / SessionBus) for clarity or a bare bool literal interchangeably. The zero value is SystemBus.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the root of the public spiderw API.
A Client owns one D-Bus connection and the wiring derived from it. Call Close when the client is no longer needed.
func NewClient ¶
NewClient connects to iwd over D-Bus and initializes a Client.
By default NewClient connects to the system bus (SystemBus), which is what real iwd deployments use. Pass SessionBus to connect to the session bus instead, which is primarily useful for tests and mocks.
Example ¶
ExampleNewClient connects to iwd and reads the daemon version.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
// SystemBus is the default and is what real iwd deployments use; pass
// spiderw.SessionBus to talk to an iwd mock on the session bus instead.
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
version, err := client.Daemon().Version(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(version)
}
Output:
func (*Client) AccessPoint ¶ added in v0.13.0
AccessPoint resolves the access point (a device in AP mode) at the given iwd object path (a device path).
func (*Client) Adapter ¶
Adapter creates an Adapter wrapper for a specific iwd adapter object path.
Use Daemon.Adapters to discover valid adapter paths.
Example ¶
ExampleClient_Adapter discovers an adapter and reads its powered state.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Adapters(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no adapters found")
}
adapter, err := client.Adapter(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
powered, err := adapter.Powered(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s powered: %t\n", refs[0].Name, powered)
}
Output:
func (*Client) AllAccessPoints ¶ added in v0.13.0
func (c *Client) AllAccessPoints(ctx context.Context) ([]*AccessPoint, error)
AllAccessPoints returns every access point (device currently in AP mode) exposed by iwd.
func (*Client) AllAdapters ¶ added in v0.2.0
AllAdapters mints live Adapter handles for every adapter iwd currently exposes.
It enumerates adapters via the daemon, then constructs a handle for each, preserving the daemon's enumeration order. Use Adapter to obtain a single adapter by path, or Daemon.Adapters for lightweight references without constructing handles.
Example ¶
ExampleClient_AllAdapters constructs a handle for every adapter iwd exposes and reports each one's powered state.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
// AllAdapters enumerates via the daemon and returns a live handle per
// adapter, in enumeration order. Use it when you want to operate on every
// adapter; use Daemon.Adapters for lightweight references only.
adapters, err := client.AllAdapters(ctx)
if err != nil {
log.Fatal(err)
}
for _, adapter := range adapters {
name, err := adapter.Name(ctx)
if err != nil {
log.Fatal(err)
}
powered, err := adapter.Powered(ctx)
if err != nil {
log.Fatal(err)
}
// Path is static identity and needs no D-Bus call.
fmt.Printf("%s (%s) powered: %t\n", name, adapter.Path(), powered)
}
}
Output:
func (*Client) AllBasicServiceSets ¶ added in v0.4.0
func (c *Client) AllBasicServiceSets(ctx context.Context) ([]*BasicServiceSet, error)
AllBasicServiceSets mints live BasicServiceSet handles for every BSS iwd currently exposes.
It enumerates BSSes via the daemon, then constructs a handle for each, preserving the daemon's enumeration order. Use BasicServiceSet to obtain a single BSS by path, or Daemon.BasicServiceSets for lightweight references without constructing handles.
Example ¶
ExampleClient_AllBasicServiceSets constructs a handle for every basic service set iwd exposes and prints each one's address. A device typically sees many BSSes - one per access point/radio heard during a scan.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
// AllBasicServiceSets enumerates via the daemon and returns a live handle per
// BSS, in enumeration order. Use Daemon.BasicServiceSets for lightweight
// references only.
bsses, err := client.AllBasicServiceSets(ctx)
if err != nil {
log.Fatal(err)
}
for _, bss := range bsses {
address, err := bss.Address(ctx)
if err != nil {
log.Fatal(err)
}
// Path is static identity and needs no D-Bus call.
fmt.Printf("%s (%s)\n", address, bss.Path())
}
}
Output:
func (*Client) AllDevices ¶ added in v0.3.0
AllDevices mints live Device handles for every device iwd currently exposes.
It enumerates devices via the daemon, then constructs a handle for each, preserving the daemon's enumeration order. Use Device to obtain a single device by path, or Daemon.Devices for lightweight references without constructing handles.
func (*Client) AllKnownNetworks ¶ added in v0.5.0
func (c *Client) AllKnownNetworks(ctx context.Context) ([]*KnownNetwork, error)
AllKnownNetworks mints live KnownNetwork handles for every known network iwd currently exposes.
It enumerates known networks via the daemon, then constructs a handle for each, preserving the daemon's enumeration order. Use KnownNetwork to obtain a single known network by path, or Daemon.KnownNetworks for lightweight references without constructing handles.
func (*Client) AllNetworks ¶ added in v0.4.0
AllNetworks mints live Network handles for every network iwd currently exposes.
It enumerates networks via the daemon, then constructs a handle for each, preserving the daemon's enumeration order. Use Network to obtain a single network by path, or Daemon.Networks for lightweight references without constructing handles.
func (*Client) AllStations ¶ added in v0.7.0
AllStations mints live Station handles for every station iwd currently exposes.
It enumerates stations via the daemon, then constructs a handle for each, preserving the daemon's enumeration order. Use Station to obtain a single station by path, or Daemon.Stations for lightweight references without constructing handles.
func (*Client) BasicServiceSet ¶ added in v0.4.0
BasicServiceSet creates a BasicServiceSet wrapper for a specific iwd BSS object path.
Use Daemon.BasicServiceSets to discover valid BSS paths.
Example ¶
ExampleClient_BasicServiceSet discovers a basic service set (BSS) and reads its address. A BSS is a single access point/radio the device can see; iwd reports one per detected AP.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().BasicServiceSets(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no basic service sets found")
}
bss, err := client.BasicServiceSet(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
address, err := bss.Address(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(address)
}
Output:
func (*Client) Close ¶
Close releases resources owned by the client.
Close is idempotent. After Close, Daemon returns nil and Adapter returns an invalid-state error.
func (*Client) Daemon ¶
Daemon returns the singleton iwd daemon wrapper for this client.
Daemon returns nil after the client has been closed.
func (*Client) Device ¶ added in v0.3.0
Device creates a Device wrapper for a specific iwd device object path.
Use Daemon.Devices to discover valid device paths.
Example ¶
ExampleClient_Device discovers a device and reads its current status.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Devices(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no devices found")
}
device, err := client.Device(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
props, err := device.Properties(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s (%s) mode=%s powered=%t adapter=%s\n",
props.Name, props.Address, props.Mode, props.Powered, props.Adapter)
}
Output:
func (*Client) KnownNetwork ¶ added in v0.5.0
KnownNetwork creates a KnownNetwork wrapper for a specific iwd known-network object path.
Use Daemon.KnownNetworks to discover valid known-network paths.
Example ¶
ExampleClient_KnownNetwork discovers a saved (known) network and reads its properties.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().KnownNetworks(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no known networks found")
}
known, err := client.KnownNetwork(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
props, err := known.Properties(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s type=%s autoConnect=%t\n", props.Name, props.Type, props.AutoConnect)
}
Output:
func (*Client) Network ¶ added in v0.4.0
Network creates a Network wrapper for a specific iwd network object path.
Use Daemon.Networks to discover valid network paths.
Example ¶
ExampleClient_Network discovers a network and reads its properties.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Networks(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no networks found")
}
network, err := client.Network(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
props, err := network.Properties(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s type=%s connected=%t\n", props.Name, props.Type, props.Connected)
}
Output:
func (*Client) RegisterAgent ¶ added in v0.6.0
RegisterAgent registers a credentials agent so iwd can request credentials when connecting to a secured network that is not already known. Without a registered agent, Network.Connect on such a network fails (ErrUnavailable, with iwd's ErrNoAgent in the chain).
At least one request callback in cfg must be set, or RegisterAgent returns an invalid-argument error. A Client owns a single agent: RegisterAgent returns an invalid-state error if one is already registered, so Unregister the previous agent first. The returned Agent is also unregistered automatically on Close.
Example ¶
ExampleClient_RegisterAgent connects to a secured (PSK) network by registering a credentials agent that supplies the passphrase when iwd asks for it.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
// iwd calls Passphrase only when it actually needs credentials (a secured
// network that is not already known). networkPath identifies the network;
// resolve it with client.Network if you need its details.
agent, err := client.RegisterAgent(ctx, spiderw.AgentConfig{
Passphrase: func(ctx context.Context, networkPath string) (string, error) {
return lookupPassphraseFor(networkPath), nil
},
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = agent.Unregister(ctx) }()
refs, err := client.Daemon().Networks(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no networks found")
}
network, err := client.Network(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
if err := network.Connect(ctx); err != nil {
log.Fatal(err)
}
fmt.Println("connected")
}
// lookupPassphraseFor stands in for however an application supplies credentials
// (a keyring, a config file, an interactive prompt, ...). It is used by
// ExampleClient_RegisterAgent.
func lookupPassphraseFor(networkPath string) string {
return networkPath + ": correct horse battery staple"
}
Output:
func (*Client) Station ¶ added in v0.7.0
Station creates a Station wrapper for a specific iwd station object path.
A station shares its object with a device (a device in station mode), so path is a device object path. Use Daemon.Stations to discover valid station paths.
Example ¶
ExampleClient_Station discovers a station (a device in station mode) and reads its read-only connection state. ConnectedNetwork is nil when the station is not connected.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
stations, err := client.AllStations(ctx)
if err != nil {
log.Fatal(err)
}
if len(stations) == 0 {
log.Fatal("no stations found")
}
station := stations[0]
props, err := station.Properties(ctx)
if err != nil {
log.Fatal(err)
}
connected := "<none>"
if props.ConnectedNetwork != nil {
connected = props.ConnectedNetwork.Name // resolved SSID
}
fmt.Printf("%s: state=%s scanning=%t connected=%s\n",
station.Path(), props.State, props.Scanning, connected)
}
Output:
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon provides high-level operations for the singleton iwd daemon object.
func (*Daemon) AccessPoints ¶ added in v0.13.0
func (d *Daemon) AccessPoints(ctx context.Context) ([]AccessPointRef, error)
AccessPoints returns lightweight references to the access points (devices in AP mode) currently exposed by iwd. Resolve one with Client.AccessPoint.
func (*Daemon) Adapters ¶
func (d *Daemon) Adapters(ctx context.Context) ([]AdapterRef, error)
Adapters returns lightweight references to the adapters currently exposed by iwd.
Example ¶
ExampleDaemon_Adapters lists the adapters iwd currently exposes.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Adapters(ctx)
if err != nil {
log.Fatal(err)
}
for _, ref := range refs {
fmt.Printf("%s (%s)\n", ref.Name, ref.Path)
}
}
Output:
func (*Daemon) BasicServiceSets ¶ added in v0.4.0
func (d *Daemon) BasicServiceSets(ctx context.Context) ([]BasicServiceSetRef, error)
BasicServiceSets returns lightweight references to the basic service sets currently exposed by iwd.
func (*Daemon) Devices ¶ added in v0.3.0
Devices returns lightweight references to the devices currently exposed by iwd.
func (*Daemon) Info ¶
func (d *Daemon) Info(ctx context.Context) (*DaemonInfo, error)
Info returns the daemon metadata reported by iwd.
Example ¶
ExampleDaemon_Info reads the iwd daemon metadata.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
info, err := client.Daemon().Info(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("version=%s stateDir=%s netConfig=%t\n",
info.Version, info.StateDirectory, info.NetworkConfigurationEnabled)
}
Output:
func (*Daemon) KnownNetworks ¶ added in v0.5.0
func (d *Daemon) KnownNetworks(ctx context.Context) ([]KnownNetworkRef, error)
KnownNetworks returns lightweight references to the known networks currently exposed by iwd.
func (*Daemon) NetworkConfigurationEnabled ¶
NetworkConfigurationEnabled reports whether iwd manages network configuration.
func (*Daemon) Networks ¶ added in v0.4.0
func (d *Daemon) Networks(ctx context.Context) ([]NetworkRef, error)
Networks returns lightweight references to the networks currently exposed by iwd.
func (*Daemon) StateDirectory ¶
StateDirectory returns the daemon's persistent state directory.
type DaemonInfo ¶
type DaemonInfo struct {
// Version is the iwd daemon version string.
Version string
// StateDirectory is the daemon's persistent state directory.
StateDirectory string
// NetworkConfigurationEnabled reports whether iwd manages network configuration.
NetworkConfigurationEnabled bool
}
DaemonInfo is the public API view of the iwd daemon metadata.
This intentionally mirrors core.DaemonInfo but is separate to avoid leaking internal types into the API surface. Future evolution of the internal/core types will not affect public clients.
func (*DaemonInfo) String ¶
func (d *DaemonInfo) String() string
String returns a human-readable multiline representation of the daemon info.
type Device ¶ added in v0.3.0
type Device struct {
// contains filtered or unexported fields
}
Device provides high-level operations for a specific iwd device object.
func (*Device) Adapter ¶ added in v0.3.0
Adapter returns the object path of the adapter that owns this device.
Resolve it to a handle with Client.Adapter.
func (*Device) Path ¶ added in v0.3.0
Path returns the D-Bus object path the device was constructed from.
Path is static device identity, not an iwd property: it requires no D-Bus round-trip and never fails. Path returns "" for a nil receiver.
func (*Device) Properties ¶ added in v0.3.0
func (d *Device) Properties(ctx context.Context) (*DeviceProperties, error)
Properties reads every device property in a single D-Bus call (Properties.GetAll) instead of one call per property. Prefer it when you need several properties at once, such as building an overview of a device.
func (*Device) SetMode ¶ added in v0.3.0
SetMode changes the device's operating mode. An unrecognized mode is rejected at the public boundary as an invalid argument.
func (*Device) SetPowered ¶ added in v0.3.0
SetPowered changes whether the device is powered.
func (*Device) SubscribeModeChanged ¶ added in v0.3.0
SubscribeModeChanged registers fn for device operating-mode changes and returns a handle that unregisters the callback.
func (*Device) SubscribePoweredChanged ¶ added in v0.3.0
func (d *Device) SubscribePoweredChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribePoweredChanged registers fn for device powered-state changes and returns a handle that unregisters the callback.
func (*Device) SubscribePropertiesChanged ¶ added in v0.3.0
func (d *Device) SubscribePropertiesChanged(ctx context.Context, fn func(DevicePropertiesChanged)) (UnsubscribeFunc, error)
SubscribePropertiesChanged registers fn for device property-change signals and returns a handle that unregisters the callback.
type DeviceProperties ¶ added in v0.3.0
type DeviceProperties struct {
// Name is the device's human-friendly Name property.
Name string
// Address is the device's hardware (MAC) address.
Address string
// Powered reports whether the device is currently powered.
Powered bool
// Mode is the device's current operating mode.
Mode Mode
// Adapter references the adapter that owns this device (Path + resolved Name).
Adapter AdapterRef
}
DeviceProperties is a snapshot of all device properties read in a single D-Bus call. iwd reports all of these for every device.
type DevicePropertiesChanged ¶ added in v0.3.0
type DevicePropertiesChanged struct {
// Changed contains new property values keyed by property name.
Changed map[string]any
// Invalidated contains property names whose values should be re-read if needed.
Invalidated []string
}
DevicePropertiesChanged describes device properties reported by a D-Bus PropertiesChanged signal. Changed contains the new values by property name; Invalidated contains property names whose values should be re-read if needed.
type DeviceRef ¶ added in v0.3.0
type DeviceRef struct {
// Path is the canonical D-Bus object path for the device.
Path string
// Name is the device's human-friendly Name property.
Name string
}
DeviceRef is a lightweight reference to a device discovered by the iwd daemon.
type Error ¶
type Error struct {
Kind Kind // stable API category
Resource Resource // public object/subsystem involved, when known
Op string // public-facing operation name (for example, "Daemon.Version")
Details string // optional human-friendly text
Err error // wrapped core.Error or raw error
}
Error is the structured error type returned by the public API.
Underlying core and D-Bus errors remain discoverable via errors.Is, errors.As, and errors.AsType.
Example:
v, err := client.Daemon().Version(ctx)
if errors.Is(err, spiderw.ErrUnavailable) { ... }
type HiddenAccessPoint ¶ added in v0.9.0
type HiddenAccessPoint struct {
// Address is the BSS hardware (BSSID) address.
Address string
// SignalStrength is the signal strength in dBm (e.g. -60.5). iwd reports it in
// units of 100 * dBm; spiderw exposes it as dBm here.
SignalStrength float64
// Type is the network security type.
Type NetworkType
}
HiddenAccessPoint is one hidden access point found in the last scan, as returned by HiddenAccessPoints.
type Kind ¶
type Kind string
Kind identifies a stable public spiderw error category.
const ( // not be reached or did not expose the expected API. KindUnavailable Kind = Kind(failure.KindUnavailable) // KindInvalidState indicates that spiderw observed an invalid or // inconsistent state from iwd or its own wrappers. KindInvalidState Kind = Kind(failure.KindInvalidState) // KindInvalidArgument indicates that a caller supplied an invalid argument // to the public API. KindInvalidArgument Kind = Kind(failure.KindInvalidArgument) // KindInternal indicates an uncategorized internal spiderw failure. KindInternal Kind = Kind(failure.KindInternal) )
Kind constants are stable public error categories.
type KnownNetwork ¶ added in v0.5.0
type KnownNetwork struct {
// contains filtered or unexported fields
}
KnownNetwork provides high-level operations for a specific iwd known-network object.
A known network is one iwd has stored configuration for (a previously connected or provisioned network).
func (*KnownNetwork) AutoConnect ¶ added in v0.5.0
func (k *KnownNetwork) AutoConnect(ctx context.Context) (bool, error)
AutoConnect reports whether the known network is a candidate for automatic connection.
func (*KnownNetwork) Forget ¶ added in v0.5.0
func (k *KnownNetwork) Forget(ctx context.Context) error
Forget removes the known network from iwd, disconnecting it first if currently connected.
func (*KnownNetwork) Hidden ¶ added in v0.5.0
func (k *KnownNetwork) Hidden(ctx context.Context) (bool, error)
Hidden reports whether the known network is hidden.
func (*KnownNetwork) LastConnectedTime ¶ added in v0.5.0
func (k *KnownNetwork) LastConnectedTime(ctx context.Context) (*string, error)
LastConnectedTime returns the ISO 8601 timestamp of the last successful connection, or nil when the network has never been connected to.
func (*KnownNetwork) Name ¶ added in v0.5.0
func (k *KnownNetwork) Name(ctx context.Context) (string, error)
Name returns the known network's name (usually the SSID).
func (*KnownNetwork) Path ¶ added in v0.5.0
func (k *KnownNetwork) Path() string
Path returns the D-Bus object path the known network was constructed from.
Path is static object identity, not an iwd property: it requires no D-Bus round-trip and never fails. Path returns "" for a nil receiver.
func (*KnownNetwork) Properties ¶ added in v0.5.0
func (k *KnownNetwork) Properties(ctx context.Context) (*KnownNetworkProperties, error)
Properties reads every known-network property in a single D-Bus call (Properties.GetAll) instead of one call per property.
func (*KnownNetwork) SetAutoConnect ¶ added in v0.5.0
func (k *KnownNetwork) SetAutoConnect(ctx context.Context, autoConnect bool) error
SetAutoConnect changes whether the known network is a candidate for automatic connection.
Example ¶
ExampleKnownNetwork_SetAutoConnect disables automatic connection for a saved network without forgetting it.
package main
import (
"context"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().KnownNetworks(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no known networks found")
}
known, err := client.KnownNetwork(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
if err := known.SetAutoConnect(ctx, false); err != nil {
log.Fatal(err)
}
// Use known.Forget(ctx) to remove the saved network entirely.
}
Output:
func (*KnownNetwork) SubscribeAutoConnectChanged ¶ added in v0.5.0
func (k *KnownNetwork) SubscribeAutoConnectChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribeAutoConnectChanged registers fn for known-network auto-connect changes and returns a handle that unregisters the callback.
func (*KnownNetwork) SubscribeHiddenChanged ¶ added in v0.13.0
func (k *KnownNetwork) SubscribeHiddenChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribeHiddenChanged registers fn for changes to the Hidden property.
func (*KnownNetwork) SubscribeLastConnectedTimeChanged ¶ added in v0.13.0
func (k *KnownNetwork) SubscribeLastConnectedTimeChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
SubscribeLastConnectedTimeChanged registers fn for changes to LastConnectedTime, an ISO 8601 timestamp. iwd updates it on each successful connection, so this fires once per connect to the network.
func (*KnownNetwork) SubscribePropertiesChanged ¶ added in v0.5.0
func (k *KnownNetwork) SubscribePropertiesChanged(ctx context.Context, fn func(KnownNetworkPropertiesChanged)) (UnsubscribeFunc, error)
SubscribePropertiesChanged registers fn for known-network property-change signals and returns a handle that unregisters the callback.
func (*KnownNetwork) Type ¶ added in v0.5.0
func (k *KnownNetwork) Type(ctx context.Context) (NetworkType, error)
Type returns the known network's type.
type KnownNetworkProperties ¶ added in v0.5.0
type KnownNetworkProperties struct {
// Name is the known network's name (usually the SSID).
Name string
// Type is the known network's type.
Type NetworkType
// Hidden reports whether the network is hidden.
Hidden bool
// LastConnectedTime is the ISO 8601 timestamp of the last successful
// connection, or nil when the network has never been connected to.
LastConnectedTime *string
// AutoConnect reports whether the network is a candidate for automatic
// connection.
AutoConnect bool
}
KnownNetworkProperties is a snapshot of all known-network properties read in a single D-Bus call. LastConnectedTime is nil when the network has never been successfully connected to.
type KnownNetworkPropertiesChanged ¶ added in v0.5.0
type KnownNetworkPropertiesChanged struct {
// Changed contains new property values keyed by property name.
Changed map[string]any
// Invalidated contains property names whose values should be re-read if needed.
Invalidated []string
}
KnownNetworkPropertiesChanged describes known-network properties reported by a D-Bus PropertiesChanged signal. Changed contains the new values by property name; Invalidated contains property names whose values should be re-read if needed.
type KnownNetworkRef ¶ added in v0.5.0
type KnownNetworkRef struct {
// Path is the canonical D-Bus object path for the known network.
Path string
// Name is the known network's name (usually the SSID).
Name string
}
KnownNetworkRef is a lightweight reference to a known network discovered by the iwd daemon.
type Mode ¶ added in v0.3.0
type Mode string
Mode identifies an iwd operating mode exposed by spiderw.
const ( // ModeUnknown represents an invalid or unrecognized mode. ModeUnknown Mode = Mode(iwdvalue.ModeUnknown) // ModeStation is the iwd station mode. ModeStation Mode = Mode(iwdvalue.ModeStation) // ModeAP is the iwd access point mode. ModeAP Mode = Mode(iwdvalue.ModeAP) // ModeAdHoc is the iwd ad-hoc mode. ModeAdHoc Mode = Mode(iwdvalue.ModeAdHoc) )
Mode constants identify the supported iwd modes. ModeUnknown is reserved for invalid or unrecognized values.
type Network ¶ added in v0.4.0
type Network struct {
// contains filtered or unexported fields
}
Network provides high-level operations for a specific iwd network object.
A network represents an SSID the owning device can see. Its ExtendedServiceSet lists the basic service sets (access points) that serve it.
func (*Network) Connect ¶ added in v0.4.0
Connect requests that the owning device connect to this network.
Open networks and networks iwd already knows connect without a credentials agent. Connecting to a secured network that is not already known fails with an error matching ErrNoAgent until an agent is registered to supply credentials.
Example ¶
ExampleNetwork_Connect connects to a network. Open and already-known networks connect without a credentials agent; a not-yet-known secured network fails with an error matching spiderw.ErrNoAgent.
package main
import (
"context"
"errors"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Networks(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no networks found")
}
network, err := client.Network(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
switch err := network.Connect(ctx); {
case err == nil:
fmt.Println("connected")
case errors.Is(err, spiderw.ErrNoAgent):
// Connecting to this secured network needs a credentials agent.
fmt.Println("a credentials agent is required to connect to this network")
default:
log.Fatal(err)
}
}
Output:
func (*Network) Connected ¶ added in v0.4.0
Connected reports whether the network is currently connected or connecting.
func (*Network) Device ¶ added in v0.4.0
Device returns the object path of the device/station the network belongs to.
Resolve it to a handle with Client.Device.
func (*Network) ExtendedServiceSet ¶ added in v0.4.0
ExtendedServiceSet returns the object paths of the basic service sets (BSSes) that make up this network. Resolve each with Client.BasicServiceSet.
Example ¶
ExampleNetwork_ExtendedServiceSet lists the basic service sets (access points) that make up a network and resolves each path to a live BasicServiceSet handle.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
refs, err := client.Daemon().Networks(ctx)
if err != nil {
log.Fatal(err)
}
if len(refs) == 0 {
log.Fatal("no networks found")
}
network, err := client.Network(ctx, refs[0].Path)
if err != nil {
log.Fatal(err)
}
// ExtendedServiceSet returns BSS object paths; resolve each with
// Client.BasicServiceSet. A single network may be served by several BSSes
// (for example a 2.4 GHz and a 5 GHz radio).
paths, err := network.ExtendedServiceSet(ctx)
if err != nil {
log.Fatal(err)
}
for _, path := range paths {
bss, err := client.BasicServiceSet(ctx, path)
if err != nil {
log.Fatal(err)
}
address, err := bss.Address(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(address)
}
}
Output:
func (*Network) KnownNetwork ¶ added in v0.4.0
KnownNetwork returns the object path of the network's known-network record, or nil when the network is not known/provisioned.
Resolve it to a handle with Client.KnownNetwork.
func (*Network) Path ¶ added in v0.4.0
Path returns the D-Bus object path the network was constructed from.
Path is static object identity, not an iwd property: it requires no D-Bus round-trip and never fails. Path returns "" for a nil receiver.
func (*Network) Properties ¶ added in v0.4.0
func (n *Network) Properties(ctx context.Context) (*NetworkProperties, error)
Properties reads every network property in a single D-Bus call (Properties.GetAll) instead of one call per property.
func (*Network) SubscribeConnectedChanged ¶ added in v0.4.0
func (n *Network) SubscribeConnectedChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribeConnectedChanged registers fn for network connected-state changes and returns a handle that unregisters the callback.
func (*Network) SubscribeExtendedServiceSetChanged ¶ added in v0.13.0
func (n *Network) SubscribeExtendedServiceSetChanged(ctx context.Context, fn func([]string)) (UnsubscribeFunc, error)
SubscribeExtendedServiceSetChanged registers fn for changes to the network's BSS list. fn receives the BSS object paths, which change as access points for the network come and go across scans.
func (*Network) SubscribeKnownNetworkChanged ¶ added in v0.13.0
func (n *Network) SubscribeKnownNetworkChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
SubscribeKnownNetworkChanged registers fn for changes to the network's known-network association. fn receives the known-network object path, or nil when the network is not known.
This is how a network being saved or forgotten is observed: provisioning gives the network a known-network record, and forgetting it takes it away.
func (*Network) SubscribePropertiesChanged ¶ added in v0.4.0
func (n *Network) SubscribePropertiesChanged(ctx context.Context, fn func(NetworkPropertiesChanged)) (UnsubscribeFunc, error)
SubscribePropertiesChanged registers fn for network property-change signals and returns a handle that unregisters the callback.
type NetworkProperties ¶ added in v0.4.0
type NetworkProperties struct {
// Name is the network's SSID.
Name string
// Connected reports whether the network is currently connected or connecting.
Connected bool
// Device references the device/station the network belongs to (Path + resolved
// Name).
Device DeviceRef
// Type is the network's network type.
Type NetworkType
// KnownNetwork is the object path of the network's known-network record, or
// nil when the network is not known/provisioned. Unlike the other bundle
// cross-references this stays a bare path: a known network's Name is always
// this network's own SSID, so resolving it would be redundant. Resolve it to a
// handle with Client.KnownNetwork.
KnownNetwork *string
// ExtendedServiceSet references the basic service sets (BSSes) that make up
// this network (Path + resolved Address).
ExtendedServiceSet []BasicServiceSetRef
}
NetworkProperties is a snapshot of all network properties read in a single D-Bus call. KnownNetwork is nil when the network has no known-network record.
type NetworkPropertiesChanged ¶ added in v0.4.0
type NetworkPropertiesChanged struct {
// Changed contains new property values keyed by property name.
Changed map[string]any
// Invalidated contains property names whose values should be re-read if needed.
Invalidated []string
}
NetworkPropertiesChanged describes network properties reported by a D-Bus PropertiesChanged signal. Changed contains the new values by property name; Invalidated contains property names whose values should be re-read if needed.
type NetworkRef ¶ added in v0.4.0
type NetworkRef struct {
// Path is the canonical D-Bus object path for the network.
Path string
// Name is the network's SSID.
Name string
}
NetworkRef is a lightweight reference to a network discovered by the iwd daemon.
type NetworkType ¶ added in v0.5.0
type NetworkType string
NetworkType identifies the network type of an iwd network.
const ( // NetworkTypeUnknown represents an invalid or unrecognized network type. NetworkTypeUnknown NetworkType = NetworkType(iwdvalue.NetworkTypeUnknown) // NetworkTypeOpen is an open (unsecured) network. NetworkTypeOpen NetworkType = NetworkType(iwdvalue.NetworkTypeOpen) // NetworkTypeWEP is a WEP network. NetworkTypeWEP NetworkType = NetworkType(iwdvalue.NetworkTypeWEP) // NetworkTypePSK is a pre-shared-key (WPA-Personal) network. NetworkTypePSK NetworkType = NetworkType(iwdvalue.NetworkTypePSK) // NetworkType8021x is an 802.1x (EAP / WPA-Enterprise) network. NetworkType8021x NetworkType = NetworkType(iwdvalue.NetworkType8021x) // NetworkTypeHotspot is a hotspot network (reported only for a KnownNetwork). NetworkTypeHotspot NetworkType = NetworkType(iwdvalue.NetworkTypeHotspot) )
NetworkType constants identify the supported iwd network types. NetworkTypeUnknown is reserved for invalid or unrecognized values.
func (NetworkType) String ¶ added in v0.5.0
func (s NetworkType) String() string
String returns the canonical iwd string for the network type.
type OrderedNetwork ¶ added in v0.8.0
type OrderedNetwork struct {
NetworkRef
// SignalStrength is the signal strength in dBm (e.g. -60.5). iwd reports it in
// units of 100 * dBm; spiderw exposes it as dBm here.
SignalStrength float64
}
OrderedNetwork is one scanned network and its signal strength, as returned by OrderedNetworks. It embeds NetworkRef, so Path is the network object path and Name is its resolved SSID.
type Resource ¶
type Resource string
Resource identifies which public spiderw object or subsystem an error applies to.
const ( // ResourceUnknown indicates that no specific resource is known. ResourceUnknown Resource = Resource(failure.ResourceUnknown) // ResourceClient identifies client-level failures. ResourceClient Resource = Resource(failure.ResourceClient) // ResourceDaemon identifies failures involving the iwd daemon object. ResourceDaemon Resource = Resource(failure.ResourceDaemon) // ResourceAdapter identifies failures involving an iwd adapter object. ResourceAdapter Resource = Resource(failure.ResourceAdapter) // ResourceDevice identifies failures involving an iwd device object. ResourceDevice Resource = Resource(failure.ResourceDevice) // ResourceBasicServiceSet identifies failures involving an iwd basic service // set (BSS) object. ResourceBasicServiceSet Resource = Resource(failure.ResourceBasicServiceSet) // ResourceStation identifies failures involving an iwd station object. ResourceStation Resource = Resource(failure.ResourceStation) // ResourceSimpleConfiguration identifies failures involving iwd's WSC (Wi-Fi // Simple Configuration / WPS) interface, reached via Station.SimpleConfiguration. ResourceSimpleConfiguration Resource = Resource(failure.ResourceSimpleConfiguration) // ResourceNetwork identifies failures involving an iwd network object. ResourceNetwork Resource = Resource(failure.ResourceNetwork) // ResourceKnownNetwork identifies failures involving an iwd known-network // object. ResourceKnownNetwork Resource = Resource(failure.ResourceKnownNetwork) // ResourceAgent identifies failures involving the iwd credentials agent or // agent manager. ResourceAgent Resource = Resource(failure.ResourceAgent) // ResourceAccessPoint identifies failures involving an iwd access point (a // device running in AP mode). ResourceAccessPoint Resource = Resource(failure.ResourceAccessPoint) )
Resource constants classify public errors by target object/subsystem.
type SignalLevelAgent ¶ added in v0.11.0
type SignalLevelAgent struct {
// contains filtered or unexported fields
}
SignalLevelAgent is a handle to an active signal-level monitor registered on a station. Call Unregister to stop monitoring and release it.
func (*SignalLevelAgent) Unregister ¶ added in v0.11.0
func (a *SignalLevelAgent) Unregister(ctx context.Context) error
Unregister stops the monitor: it unregisters the agent from iwd and removes the exported object. It is idempotent.
type SignalLevelConfig ¶ added in v0.11.0
type SignalLevelConfig struct {
// Thresholds are RSSI levels in dBm that trigger Changed when crossed. They
// must be non-empty and in strictly descending order (for example
// []int{-60, -70, -80}). Required.
Thresholds []int
// Changed is called with the signal band index each time the connected
// network's RSSI crosses a threshold. N thresholds define N+1 bands, so level
// ranges over [0, N]: 0 is the strongest band (above the first threshold) and
// N is the weakest (below the last). Required.
//
// The band is derived entirely by iwd from its own RSSI measurement, which is
// averaged and driver-dependent. It will not match an instantaneous reading
// such as "iw dev link" exactly: transitions can occur several dBm away from
// the nominal thresholds, more so while the signal is actively changing. iwd
// reports a band only when the index changes, so a band the signal passes
// through quickly may be skipped, and some drivers (notably brcmfmac) support
// only coarse threshold monitoring. Treat level as a coarse, hysteresis-
// smoothed indicator rather than an exact dBm boundary.
Changed func(level int)
// Released is called when iwd releases the agent (the monitor was
// unregistered or the station went away). Optional.
Released func()
}
SignalLevelConfig configures signal-strength monitoring for a station. iwd invokes Changed whenever the connected network's RSSI crosses one of the configured thresholds.
type SimpleConfiguration ¶ added in v0.12.0
type SimpleConfiguration struct {
// contains filtered or unexported fields
}
SimpleConfiguration is a handle to a station's WSC (Wi-Fi Simple Configuration, formerly WPS) enrollment interface, obtained from Station.SimpleConfiguration. It joins the station to an access point without a passphrase, via either PushButton (PBC) or a PIN.
func (*SimpleConfiguration) Cancel ¶ added in v0.12.0
func (c *SimpleConfiguration) Cancel(ctx context.Context) error
Cancel aborts an in-progress PushButton or StartPin enrollment.
func (*SimpleConfiguration) GeneratePin ¶ added in v0.12.0
func (c *SimpleConfiguration) GeneratePin(ctx context.Context) (string, error)
GeneratePin returns a fresh 8-digit WSC PIN (with a valid check digit) to enter at the access point's registrar, for use with StartPin.
func (*SimpleConfiguration) PushButton ¶ added in v0.12.0
func (c *SimpleConfiguration) PushButton(ctx context.Context) error
PushButton starts WSC enrollment in PushButton (PBC) mode: press the WPS button on the access point, then call this within its walk window. It blocks until iwd reports the outcome, so pass a context with a deadline. If more than one access point is in PushButton mode the target is ambiguous and iwd returns an error matching ErrWSCSessionOverlap.
func (*SimpleConfiguration) StartPin ¶ added in v0.12.0
func (c *SimpleConfiguration) StartPin(ctx context.Context, pin string) error
StartPin starts WSC enrollment in PIN mode using pin (typically one from GeneratePin, entered at the access point's registrar). Spaces and hyphens are ignored; the PIN must be 4 or 8 digits, and iwd validates the 8-digit check digit (surfaced as an error matching ErrInvalidFormat). It blocks until iwd reports the outcome.
type Station ¶ added in v0.7.0
type Station struct {
// contains filtered or unexported fields
}
Station provides high-level operations for a specific iwd station object.
A station is a device operating in station (client) mode; it shares its object path with the Device. Station covers connection state and scanning; connecting to a network is done through Network.Connect.
func (*Station) Affinities ¶ added in v0.7.0
Affinities returns the object paths of the BSSes the station has a roaming affinity for, or nil when unreported. iwd marks this property experimental.
func (*Station) ConnectHiddenNetwork ¶ added in v0.9.0
ConnectHiddenNetwork connects to a hidden network by SSID. A secured hidden network requires a registered credentials agent (register one with Client.RegisterAgent before calling); without one, iwd surfaces an error matching ErrNoAgent.
Example ¶
ExampleStation_ConnectHiddenNetwork connects to a secured hidden network. iwd invokes the registered agent's Passphrase callback for the credentials, so register an agent before connecting.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Supply the passphrase for a secured hidden network via a credentials agent.
agent, err := client.RegisterAgent(ctx, spiderw.AgentConfig{
Passphrase: func(ctx context.Context, networkPath string) (string, error) {
return "hunter2", nil
},
})
if err != nil {
log.Fatal(err)
}
defer func() { _ = agent.Unregister(ctx) }()
stations, err := client.AllStations(ctx)
if err != nil {
log.Fatal(err)
}
if len(stations) == 0 {
log.Fatal("no stations found")
}
if err := stations[0].ConnectHiddenNetwork(ctx, "MyHiddenSSID"); err != nil {
log.Fatal(err)
}
fmt.Println("connected")
}
Output:
func (*Station) ConnectedAccessPoint ¶ added in v0.7.0
ConnectedAccessPoint returns the object path of the BSS the station is connected to, or nil when disconnected or unreported.
Resolve it to a handle with Client.BasicServiceSet. iwd marks this property experimental.
func (*Station) ConnectedNetwork ¶ added in v0.7.0
ConnectedNetwork returns the object path of the network the station is connected to, or nil when the station is not connected.
Resolve it to a handle with Client.Network.
func (*Station) Disconnect ¶ added in v0.9.0
Disconnect disconnects the station from its current network.
func (*Station) HiddenAccessPoints ¶ added in v0.9.0
func (s *Station) HiddenAccessPoints(ctx context.Context) ([]HiddenAccessPoint, error)
HiddenAccessPoints returns the hidden access points found in the most recent scan. It is an experimental iwd operation: hardware that cannot provide it makes iwd reject the call, and the returned error matches ErrNotSupported via errors.Is.
func (*Station) MonitorSignalLevel ¶ added in v0.11.0
func (s *Station) MonitorSignalLevel(ctx context.Context, cfg SignalLevelConfig) (*SignalLevelAgent, error)
MonitorSignalLevel starts monitoring the station's connected-network signal strength, invoking cfg.Changed whenever the RSSI crosses one of cfg.Thresholds (dBm, strictly descending). It returns a handle whose Unregister stops monitoring. iwd supports a single signal-level monitor per station.
func (*Station) Name ¶ added in v0.10.0
Name returns the station's human-friendly name - the Name of the device it shares an object with (e.g. "wlan0"). A station has no Name property of its own, so this is resolved when the station is constructed (best-effort) and may be "" if it could not be resolved or for a nil receiver. Like Path, it is cached identity: no D-Bus round-trip and never fails.
func (*Station) OrderedNetworks ¶ added in v0.8.0
func (s *Station) OrderedNetworks(ctx context.Context) ([]OrderedNetwork, error)
OrderedNetworks returns the networks from the most recent scan, ordered by iwd with the strongest signal first. No scan is required to read the last results.
func (*Station) Path ¶ added in v0.7.0
Path returns the D-Bus object path the station was constructed from.
Path is static station identity, not an iwd property: it requires no D-Bus round-trip and never fails. Path returns "" for a nil receiver.
func (*Station) Properties ¶ added in v0.7.0
func (s *Station) Properties(ctx context.Context) (*StationProperties, error)
Properties reads every station property in a single D-Bus call (Properties.GetAll) instead of one call per property. Prefer it when you need several properties at once, such as building an overview of a station.
func (*Station) Scan ¶ added in v0.8.0
Scan schedules a network scan on the station. It is asynchronous: the call returns once the scan is scheduled, and the station's Scanning property tracks progress. Subscribe with SubscribeScanningChanged to observe completion, then read results with OrderedNetworks.
Example ¶
ExampleStation_Scan triggers a scan and lists the resulting networks by signal strength. Scan is asynchronous; subscribe to Scanning (or poll it) to know when results are ready. This example reads the last results immediately.
package main
import (
"context"
"fmt"
"log"
"github.com/chrispypip/spiderw"
)
func main() {
ctx := context.Background()
client, err := spiderw.NewClient(ctx, spiderw.SystemBus)
if err != nil {
log.Fatal(err)
}
defer client.Close()
stations, err := client.AllStations(ctx)
if err != nil {
log.Fatal(err)
}
if len(stations) == 0 {
log.Fatal("no stations found")
}
station := stations[0]
if err := station.Scan(ctx); err != nil {
log.Fatal(err)
}
networks, err := station.OrderedNetworks(ctx)
if err != nil {
log.Fatal(err)
}
for _, n := range networks {
fmt.Printf("%s: %.0f dBm\n", n.Name, n.SignalStrength) // n.Name is the SSID
}
}
Output:
func (*Station) Scanning ¶ added in v0.7.0
Scanning reports whether the station is currently scanning for networks.
func (*Station) SetAffinities ¶ added in v0.8.0
SetAffinities sets the BSS object paths the station should stay affine to (an experimental iwd property). Each path must be a non-empty absolute object path, and should be a BSS of the currently connected network (see Network.ExtendedServiceSet). Passing an empty slice clears all affinities.
Affinities depends on driver support: on hardware that cannot honor it, iwd rejects the write and the returned error matches ErrNotSupported via errors.Is.
func (*Station) SimpleConfiguration ¶ added in v0.12.0
func (s *Station) SimpleConfiguration(ctx context.Context) (*SimpleConfiguration, error)
SimpleConfiguration returns a handle to the station's WSC (WPS) enrollment interface, for joining an access point without a passphrase via PushButton or PIN. It is available only when the device is in station mode and the driver supports WSC.
func (*Station) State ¶ added in v0.7.0
func (s *Station) State(ctx context.Context) (StationState, error)
State returns the station's current connection state.
func (*Station) SubscribeAffinitiesChanged ¶ added in v0.13.0
func (s *Station) SubscribeAffinitiesChanged(ctx context.Context, fn func([]string)) (UnsubscribeFunc, error)
SubscribeAffinitiesChanged registers fn for changes to the station's roaming affinities. Affinities are writable, so they can change without this process doing anything: another client may set them, or iwd may clear them. This is the only way to observe that.
func (*Station) SubscribeConnectedAccessPointChanged ¶ added in v0.13.0
func (s *Station) SubscribeConnectedAccessPointChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
SubscribeConnectedAccessPointChanged registers fn for changes to the BSS the station is associated with. fn receives the BSS object path, or nil when not associated.
This is how a roam is observed: the station moves between access points of the same network, so the BSS changes while State stays StationStateConnected and the connected network does not change at all.
func (*Station) SubscribeConnectedNetworkChanged ¶ added in v0.13.0
func (s *Station) SubscribeConnectedNetworkChanged(ctx context.Context, fn func(*string)) (UnsubscribeFunc, error)
SubscribeConnectedNetworkChanged registers fn for changes to the network the station is connected to. fn receives the network's object path, or nil when the station is not connected to one.
func (*Station) SubscribePropertiesChanged ¶ added in v0.7.0
func (s *Station) SubscribePropertiesChanged(ctx context.Context, fn func(StationPropertiesChanged)) (UnsubscribeFunc, error)
SubscribePropertiesChanged registers fn for station property-change signals and returns a handle that unregisters the callback.
func (*Station) SubscribeScanningChanged ¶ added in v0.7.0
func (s *Station) SubscribeScanningChanged(ctx context.Context, fn func(bool)) (UnsubscribeFunc, error)
SubscribeScanningChanged registers fn for station scanning-state changes and returns a handle that unregisters the callback.
func (*Station) SubscribeStateChanged ¶ added in v0.7.0
func (s *Station) SubscribeStateChanged(ctx context.Context, fn func(StationState)) (UnsubscribeFunc, error)
SubscribeStateChanged registers fn for station connection-state changes and returns a handle that unregisters the callback.
type StationProperties ¶ added in v0.7.0
type StationProperties struct {
// State is the station's current connection state.
State StationState
// Scanning reports whether the station is currently scanning.
Scanning bool
// ConnectedNetwork references the network the station is connected to (Path +
// resolved SSID Name), or nil when not connected.
ConnectedNetwork *NetworkRef
// ConnectedAccessPoint references the BSS the station is connected to (Path +
// resolved Address), or nil when disconnected or unreported. iwd marks this
// property experimental.
ConnectedAccessPoint *BasicServiceSetRef
// Affinities references the BSSes the station has a roaming affinity for (Path
// + resolved Address), or nil when unreported. iwd marks this property
// experimental.
Affinities []BasicServiceSetRef
}
StationProperties is a snapshot of all station properties read in a single D-Bus call. State and Scanning are always reported; the remaining fields are nil when absent.
type StationPropertiesChanged ¶ added in v0.7.0
type StationPropertiesChanged struct {
// Changed contains new property values keyed by property name.
Changed map[string]any
// Invalidated contains property names whose values should be re-read if needed.
Invalidated []string
}
StationPropertiesChanged describes station properties reported by a D-Bus PropertiesChanged signal. Changed contains the new values by property name; Invalidated contains property names whose values should be re-read if needed.
type StationRef ¶ added in v0.7.0
type StationRef struct {
// Path is the canonical D-Bus object path for the station (a device path).
Path string
// Name is the co-located device's Name (best-effort; empty if unavailable).
Name string
}
StationRef is a lightweight reference to a station discovered by the iwd daemon. A station shares its object with a device and has no Name of its own, so Name is the co-located device's Name (e.g. "wlan0"), resolved best-effort. Resolve the handle with Client.Station.
type StationState ¶ added in v0.7.0
type StationState string
StationState identifies an iwd station's connection state exposed by spiderw.
const ( // StationStateUnknown represents an invalid or unrecognized station state. StationStateUnknown StationState = StationState(iwdvalue.StationStateUnknown) // StationStateConnected means the station is connected to a network. StationStateConnected StationState = StationState(iwdvalue.StationStateConnected) // StationStateDisconnected means the station is not connected. StationStateDisconnected StationState = StationState(iwdvalue.StationStateDisconnected) // StationStateConnecting means the station is establishing a connection. StationStateConnecting StationState = StationState(iwdvalue.StationStateConnecting) // StationStateDisconnecting means the station is tearing down a connection. StationStateDisconnecting StationState = StationState(iwdvalue.StationStateDisconnecting) // StationStateRoaming means the station is roaming between access points. StationStateRoaming StationState = StationState(iwdvalue.StationStateRoaming) )
StationState constants identify the station connection states. StationStateUnknown is reserved for invalid or unrecognized values.
func (StationState) String ¶ added in v0.7.0
func (s StationState) String() string
String returns the canonical iwd string for the station state.
type UnsubscribeFunc ¶
type UnsubscribeFunc func() error
UnsubscribeFunc unregisters a previously registered subscription callback.
It is safe for implementations to make repeated calls no-ops.
func (UnsubscribeFunc) Unsubscribe ¶
func (u UnsubscribeFunc) Unsubscribe() error
Unsubscribe unregisters the subscription callback.
Calling Unsubscribe on a nil UnsubscribeFunc is a no-op.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
spiderw
command
Command spiderw is a small CLI for interacting with iwd through the spiderw public API.
|
Command spiderw is a small CLI for interacting with iwd through the spiderw public API. |
|
spiderw/cli
Package cli implements the spiderw command-line interface for interacting with iwd through the spiderw public API.
|
Package cli implements the spiderw command-line interface for interacting with iwd through the spiderw public API. |
|
examples
|
|
|
access-point-start
command
Command access-point-start runs a device in AP mode as a PSK-secured access point using AccessPoint.Start, where you supply the SSID and passphrase inline.
|
Command access-point-start runs a device in AP mode as a PSK-secured access point using AccessPoint.Start, where you supply the SSID and passphrase inline. |
|
access-point-start-profile
command
Command access-point-start-profile runs a device in AP mode from a stored iwd provisioning profile using AccessPoint.StartProfile.
|
Command access-point-start-profile runs a device in AP mode from a stored iwd provisioning profile using AccessPoint.StartProfile. |
|
bring-up
command
Command bring-up takes a wireless device from cold to ready for station work: it powers on the device's adapter, powers on the device, switches it to station mode, then scans to confirm the station is usable.
|
Command bring-up takes a wireless device from cold to ready for station work: it powers on the device's adapter, powers on the device, switches it to station mode, then scans to confirm the station is usable. |
|
connect-hidden
command
Command connect-hidden joins a hidden network - one that does not broadcast its SSID and so never appears in scan results.
|
Command connect-hidden joins a hidden network - one that does not broadcast its SSID and so never appears in scan results. |
|
known-networks
command
Command known-networks lists the networks iwd has stored credentials for and can optionally manage one: toggle its autoconnect flag or forget it entirely.
|
Command known-networks lists the networks iwd has stored credentials for and can optionally manage one: toggle its autoconnect flag or forget it entirely. |
|
monitor
command
Command monitor watches the first station and prints its state, scanning, connected-network, and associated-access-point changes live, until interrupted with Ctrl-C. It demonstrates the subscription API and how signals flow through spiderw.
|
Command monitor watches the first station and prints its state, scanning, connected-network, and associated-access-point changes live, until interrupted with Ctrl-C. It demonstrates the subscription API and how signals flow through spiderw. |
|
scan-and-connect
command
Command scan-and-connect runs the full "join a network" flow against the first station: trigger a scan, wait for it to finish, list the visible networks by signal strength, and - if -ssid is given - connect to one, supplying a passphrase through a credentials agent when needed.
|
Command scan-and-connect runs the full "join a network" flow against the first station: trigger a scan, wait for it to finish, list the visible networks by signal strength, and - if -ssid is given - connect to one, supplying a passphrase through a credentials agent when needed. |
|
signal-monitor
command
Command signal-monitor watches the connected network's signal strength on the first station and prints a line each time the RSSI crosses one of the given dBm thresholds, until interrupted with Ctrl-C. It demonstrates the SignalLevelAgent (Station.MonitorSignalLevel) and changes nothing.
|
Command signal-monitor watches the connected network's signal strength on the first station and prints a line each time the RSSI crosses one of the given dBm thresholds, until interrupted with Ctrl-C. It demonstrates the SignalLevelAgent (Station.MonitorSignalLevel) and changes nothing. |
|
status
command
Command status prints a read-only overview of the local iwd state: daemon metadata plus every adapter, device, station, and known network.
|
Command status prints a read-only overview of the local iwd state: daemon metadata plus every adapter, device, station, and known network. |
|
wsc-pin
command
Command wsc-pin joins the first station to an access point via WSC (Wi-Fi Simple Configuration, formerly WPS) PIN mode, without typing a passphrase.
|
Command wsc-pin joins the first station to an access point via WSC (Wi-Fi Simple Configuration, formerly WPS) PIN mode, without typing a passphrase. |
|
wsc-push-button
command
Command wsc-push-button joins the first station to an access point via WSC (Wi-Fi Simple Configuration, formerly WPS) PushButton mode, without typing a passphrase.
|
Command wsc-push-button joins the first station to an access point via WSC (Wi-Fi Simple Configuration, formerly WPS) PushButton mode, without typing a passphrase. |
|
internal
|
|
|
connect
Package connect wires together the layered spiderw implementation.
|
Package connect wires together the layered spiderw implementation. |
|
core
Package core normalizes raw D-Bus data from internal/iwdbus into strongly typed domain values and enforces invariants.
|
Package core normalizes raw D-Bus data from internal/iwdbus into strongly typed domain values and enforces invariants. |
|
core/testutil
Package testutil provides core-layer test fakes and embeddable stubs.
|
Package testutil provides core-layer test fakes and embeddable stubs. |
|
failure
Package failure defines shared error kinds and resource labels used at spiderw layer boundaries.
|
Package failure defines shared error kinds and resource labels used at spiderw layer boundaries. |
|
iwdbus
Package iwdbus is the low-level D-Bus boundary for spiderw.
|
Package iwdbus is the low-level D-Bus boundary for spiderw. |
|
iwdbus/testutil
Package testutil provides iwdbus test fakes and embeddable stubs.
|
Package testutil provides iwdbus test fakes and embeddable stubs. |
|
iwdvalue
Package iwdvalue defines canonical iwd values shared across spiderw layers.
|
Package iwdvalue defines canonical iwd values shared across spiderw layers. |
|
logging
Package logging defines the internal logging abstractions used throughout spiderw.
|
Package logging defines the internal logging abstractions used throughout spiderw. |
|
tests
|
|
|
integration
Package integration documents the conventions for the spiderw integration test suite.
|
Package integration documents the conventions for the spiderw integration test suite. |
|
integration/iwdbus
Package integration contains the spiderw integration test suite.
|
Package integration contains the spiderw integration test suite. |
|
testutil/iwdmock
Package iwdmock provides helpers for integration tests that need a deterministic mock of the iwd D-Bus API.
|
Package iwdmock provides helpers for integration tests that need a deterministic mock of the iwd D-Bus API. |
|
tools
|
|
|
test-mocks/iwdmock
command
The iwdmock command is a minimal, Go-based mock of enough of the net.connman.iwd D-Bus API to support spiderw's integration tests.
|
The iwdmock command is a minimal, Go-based mock of enough of the net.connman.iwd D-Bus API to support spiderw's integration tests. |
|
test-mocks/iwdmock/internal/mock
Package mock implements the D-Bus objects exported by the iwdmock test service.
|
Package mock implements the D-Bus objects exported by the iwdmock test service. |