wireless

package
v0.0.0-...-2269899 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthOpen = "NONE"
	AuthPSK  = "WPA-PSK"
	AuthEAP  = "WPA-EAP"
)

wpa_supplicant key management options

View Source
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

func InterfaceNames() ([]string, error)

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

func (m *Manager) CaptivePortalCheck() (present bool, portalURL string, err error)

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) Close

func (m *Manager) Close() error

Close closes the Manager.

func (*Manager) Connect

func (m *Manager) Connect(conf NetworkConfiguration) (State, error)

Connect connects to a network using a specified configuration.

func (*Manager) CurrentSSID

func (m *Manager) CurrentSSID() string

CurrentSSID returns the SSID of the current network, if there is one.

func (*Manager) DisableInterface

func (m *Manager) DisableInterface() error

DisableInterface disables the interface managed by Manager.

func (*Manager) Disconnect

func (m *Manager) Disconnect() error

Disconnect disconnects the interface from the current network.

func (*Manager) EnableInterface

func (m *Manager) EnableInterface() error

EnableInterface enables the interface managed by Manager.

func (*Manager) IPAddress

func (m *Manager) IPAddress() string

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

func (m *Manager) IfaceName() string

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

func (m *Manager) ScanForNetworks(ctx context.Context)

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.

func (*Manager) State

func (m *Manager) State() State

State returns the current state of the interface managed by Manager.

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.

type State

type State int32

State represents a connection state

const (
	Disconnected State = iota
	Connected
	Connecting
	Failed
	InterfaceDisabled
)

Possible values of type State:

	Disconnected
	Connected
	Connecting
	Failed
     InterfaceDisabled

func (State) String

func (s State) String() string

String returns the string represetation of the state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL