Documentation
¶
Index ¶
- Constants
- func InterfaceNames() ([]string, error)
- type Manager
- func (m *Manager) AvailableNetworks() []ScanResult
- func (m *Manager) CaptivePortalCheck() (present bool, portalURL string, err error)
- func (m *Manager) Close() error
- func (m *Manager) Connect(conf NetworkConfiguration) (State, error)
- func (m *Manager) CurrentSSID() string
- func (m *Manager) DisableInterface() error
- func (m *Manager) Disconnect() error
- func (m *Manager) EnableInterface() error
- func (m *Manager) IPAddress() string
- func (m *Manager) IfaceName() string
- func (m *Manager) Notify(ctx context.Context, c chan Notification)
- func (m *Manager) ScanForNetworks(ctx context.Context)
- func (m *Manager) SearchAndConnect(ctx context.Context, confs ...NetworkConfiguration) error
- func (m *Manager) SignalStrength() SignalStrength
- func (m *Manager) State() State
- type ManagerOption
- type NetworkConfiguration
- type Notification
- type NotificationType
- type ScanResult
- type SignalStrength
- type State
Constants ¶
const ( AuthOpen = "NONE" AuthPSK = "WPA-PSK" AuthEAP = "WPA-EAP" )
wpa_supplicant key management options
const ( EAPMethodTLS = "TLS" // EAPMethodPEAP refers to PEAPv0, i.e. PEAP with // MSCHAPv2 phase2 authenticatiaon. EAPMethodPEAP = "PEAP" )
EAP methods
Variables ¶
This section is empty.
Functions ¶
func InterfaceNames ¶
InterfaceNames returns a list of wireless interface names known to wpa_supplicant.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is used to manage a wireless network interface.
func NewManager ¶
func NewManager(iface string, opts ...ManagerOption) (*Manager, error)
NewManager returns a Manager for a specified wireless interface.
func (*Manager) AvailableNetworks ¶
func (m *Manager) AvailableNetworks() []ScanResult
AvailableNetworks returns the currently known networks from the latest successful AP scan. AP scans happen periodically, so ScanResults may change frequently.
func (*Manager) CaptivePortalCheck ¶
CaptivePortalCheck tries to determine if a captive portal is present. When `err` is nil, `present` indicates if a captive portal is present. When possible, non-empty `portalURL` is returned to indicate the URL of the captive portal.
func (*Manager) Connect ¶
func (m *Manager) Connect(conf NetworkConfiguration) (State, error)
Connect connects to a network using a specified configuration.
func (*Manager) CurrentSSID ¶
CurrentSSID returns the SSID of the current network, if there is one.
func (*Manager) DisableInterface ¶
DisableInterface disables the interface managed by Manager.
func (*Manager) Disconnect ¶
Disconnect disconnects the interface from the current network.
func (*Manager) EnableInterface ¶
EnableInterface enables the interface managed by Manager.
func (*Manager) IPAddress ¶
IPAddress returns a dotted decimal string representation of the Interface's IP address. If it has no IP, an empty string is returned.
func (*Manager) IfaceName ¶
IfaceName returns the name of the network interface managed by a Manager
func (*Manager) Notify ¶
func (m *Manager) Notify(ctx context.Context, c chan Notification)
Notify will send all notification to c, and will stop when ctx is done.
func (*Manager) ScanForNetworks ¶
ScanForNetworks begins scanning for available wireless networks, and does so until Manager is Close()'d, or the provided ctx is cancelled.
The default behavior is for the manager to scan frequently while the interface is in a Disconnected state, and to scan less frequently when the interface state is Connected. These intervals can be set with the WithConnectedScanInterval and WithDisconnectedScanInterval ManagerOption's.
func (*Manager) SearchAndConnect ¶
func (m *Manager) SearchAndConnect(ctx context.Context, confs ...NetworkConfiguration) error
SearchAndConnect searches for the provided in the list of available SSIDs, and connects to the first one found. SearchAndConnect keeps looking until a successful connection is made (possibly by another caller to Connect), or the supplied context finishes, whichever happens first.
func (*Manager) SignalStrength ¶
func (m *Manager) SignalStrength() SignalStrength
SignalStrength returns the signal strength of the current network, if associated.
type ManagerOption ¶
type ManagerOption interface {
// contains filtered or unexported methods
}
ManagerOption is used to configure a Manager.
func WithAutoPortalCheck ¶
func WithAutoPortalCheck(enable bool) ManagerOption
WithAutoPortalCheck enables/disables automatic captive portal checking when a new network is connected.
func WithConnectedScanInterval ¶
func WithConnectedScanInterval(interval time.Duration) ManagerOption
WithConnectedScanInterval sets the interval at which AP scans should be performed when the Manager's interface is in a Connected state.
func WithDisconnectedScanInterval ¶
func WithDisconnectedScanInterval(interval time.Duration) ManagerOption
WithDisconnectedScanInterval sets the interval at which AP scans should be performed when the Manager's interface is in a Disconnected state.
func WithPortalCheckURL ¶
func WithPortalCheckURL(url string) ManagerOption
WithPortalCheckURL sets the URL that Manager uses to perform captive portal checks. If this is not specified, a suitable default will be used.
type NetworkConfiguration ¶
type NetworkConfiguration struct { SSID string PSK string KeyManagement string Identity string Password string EAP string Phase1 string Phase2 string CaCert []byte ClientCert []byte PrivKey []byte PrivKeyPasswd string ScanSSID int32 }
NetworkConfiguration represents a network configuration as described in wpa_supplicant.conf(5). Fields that have type []byte are treated as "configuration blobs."
type Notification ¶
type Notification struct { Type NotificationType Value interface{} }
Notification is a notification for some wireless networking event. Examples include, scan results updated, connection state change, and signal strength change.
type NotificationType ¶
type NotificationType uint32
NotificationType indicates the information given by the notification.
const ( // StateChanged indicates that the connection state has changed. StateChanged NotificationType = iota + 1 // SignalStrengthChanged indicates that the signal strength of the // associated AP (if any) has changed. SignalStrengthChanged // ScanResultsChanged indicates that the list of available networks/ // scan results has changed. ScanResultsChanged // SSIDChanged indicates that the current network SSID has changed, // possibly to empty. SSIDChanged // IPChanged indicates that the IP address of the interface has changed. IPChanged // PortalDetected indicates that a captive portal has been detected. PortalDetected // PortalResolved indicates that a captive portal has been resolved. PortalResolved )
type ScanResult ¶
type ScanResult struct { SSID string // Name of the network KeyManagement []string // Key management suite SignalStrength SignalStrength // Signal strength of the BSS }
ScanResult contains information about an available AP.
type SignalStrength ¶
type SignalStrength int16
SignalStrength represents the strength of a signal in -dBm.
func (SignalStrength) String ¶
func (s SignalStrength) String() string
String returns a string description of SignalStrength.