wpasupplicant

package module
v0.0.0-...-79b5da0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

README

pifke.org/wpasupplicant

GoDoc Build Status Test Coverage

Golang interface for talking to wpa_supplicant.

At the moment, this simply provides an interface for fetching wifi scan results. More functionality (probably) coming soon.

Example

import (
	"fmt"

	"pifke.org/wpasupplicant"
)

// Prints the BSSID (MAC address) and SSID of each access point in range:
w, err := wpasupplicant.Unixgram("wlan0")
if err != nil {
	panic(err)
}
for _, bss := range w.ScanResults() {
	fmt.Fprintf("%s\t%s\n", bss.BSSID(), bss.SSID())
}

Downloading

If you use this library in your own code, please use the canonical URL in your Go code, instead of Github:

go get pifke.org/wpasupplicant

Or (until I finish setting up the self-hosted repository):

# From the root of your project:
git submodule add https://github.com/dpifke/golang-wpasupplicant vendor/pifke.org/wpasupplicant

Then:

import (
        "pifke.org/wpasupplicant"
)

As opposed to the pifke.org URL, I make no guarantee this Github repository will exist or be up-to-date in the future.

Documentation

Available on godoc.org.

License

Three-clause BSD. See LICENSE.txt.

Contact me if you want to use this code under different terms.

Author

Dave Pifke. My email address is my first name "at" my last name "dot org."

I'm @dpifke on Twitter. My PGP key is available on Keybase.

Documentation

Overview

Package wpasupplicant provides an interface for talking to the wpa_supplicant daemon.

At the moment, this simply provides an interface for fetching wifi scan results. More functionality is (probably) coming soon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Algorithm

type Algorithm int

type Cipher

type Cipher int

Cipher is one of the WPA_CIPHER constants from the wpa_supplicant source.

const (
	CIPHER_NONE Cipher = 1 << iota
	WEP40
	WEP104
	TKIP
	CCMP
	AES_128_CMAC
	GCMP
	SMS4
	GCMP_256
	CCMP_256

	BIP_GMAC_128
	BIP_GMAC_256
	BIP_CMAC_256
	GTK_NOT_USED
)

type ConfiguredNetwork

type ConfiguredNetwork interface {
	NetworkID() string
	SSID() string
	BSSID() string
	Flags() []string
}

ConfiguredNetwork is a configured network (from LIST_NETWORKS)

type Conn

type Conn interface {
	// Close closes the unixgram connection
	Close() error

	// Ping tests the connection.  It returns nil if wpa_supplicant is
	// responding.
	Ping() error

	// AddNetwork creates an empty network configuration. Returns the network
	// ID.
	AddNetwork() (int, error)

	// SetNetwork configures a network property. Returns error if the property
	// configuration failed.
	SetNetwork(int, string, string) error

	// EnableNetwork enables a network. Returns error if the command fails.
	EnableNetwork(int) error

	// EnableAllNetworks enables all configured networks. Returns error if the command fails.
	EnableAllNetworks() error

	// SelectNetwork selects a network (and disables the others).
	SelectNetwork(int) error

	// DisableNetwork disables a network.
	DisableNetwork(int) error

	// RemoveNetwork removes a network from the configuration.
	RemoveNetwork(int) error

	// RemoveAllNetworks removes all networks (basically running `REMOVE_NETWORK all`).
	// Returns error if command fails.
	RemoveAllNetworks() error

	// SaveConfig stores the current network configuration to disk.
	SaveConfig() error

	// Reconfigure sends a RECONFIGURE command to the wpa_supplicant. Returns error when
	// command fails.
	Reconfigure() error

	// Reassociate sends a REASSOCIATE command to the wpa_supplicant. Returns error when
	// command fails.
	Reassociate() error

	// Reconnect sends a RECONNECT command to the wpa_supplicant. Returns error when
	// command fails.
	Reconnect() error

	// ListNetworks returns the currently configured networks.
	ListNetworks() ([]ConfiguredNetwork, error)

	// Status returns current wpa_supplicant status
	Status() (StatusResult, error)

	// Scan triggers a new scan. Returns error if the wpa_supplicant does not
	// return OK.
	Scan() error

	// ScanResult returns the latest scanning results.  It returns a slice
	// of scanned BSSs, and/or a slice of errors representing problems
	// communicating with wpa_supplicant or parsing its output.
	ScanResults() ([]ScanResult, []error)

	EventQueue() chan WPAEvent
}

Conn is a connection to wpa_supplicant over one of its communication channels.

func Unixgram

func Unixgram(ifName string) (Conn, error)

Unixgram returns a connection to wpa_supplicant for the specified interface, using the socket-based control interface.

type KeyMgmt

type KeyMgmt int

KeyMgmt is one of the WPA_KEY_MGMT constants from the wpa_supplicant source.

const (
	IEEE8021X KeyMgmt = 1 << iota
	PSK
	KEY_MGMT_NONE
	IEEE8021X_NO_WPA
	WPA_NONE
	FT_IEEE8021X
	FT_PSK
	IEEE8021X_SHA256
	PSK_SHA256
	WPS
	SAE
	FT_SAE
	WAPI_PSK
	WAPI_CERT
	CCKM
	OSEN
	IEEE8021X_SUITE_B
	IEEE8021X_SUITE_B_192
)

type ParseError

type ParseError struct {
	// Line is the line of output from wpa_supplicant which we couldn't
	// parse.
	Line string

	// Err is any nested error.
	Err error
}

ParseError is returned when we can't parse the wpa_supplicant response. Some functions may return multiple ParseErrors.

func (*ParseError) Error

func (err *ParseError) Error() string

type ScanResult

type ScanResult interface {
	// BSSID is the MAC address of the BSS.
	BSSID() net.HardwareAddr

	// SSID is the SSID of the BSS.
	SSID() string

	// Frequency is the frequency, in Mhz, of the BSS.
	Frequency() int

	// RSSI is the received signal strength, in dB, of the BSS.
	RSSI() int

	// Flags is an array of flags, in string format, returned by the
	// wpa_supplicant SCAN_RESULTS command.  Future versions of this code
	// will parse these into something more meaningful.
	Flags() []string
}

ScanResult is a scanned BSS.

type StatusResult

type StatusResult interface {
	WPAState() string
	KeyMgmt() string
	IPAddr() string
	SSID() string
	Address() string
	BSSID() string
	Freq() string
}

type WPAEvent

type WPAEvent struct {
	Event     string
	Arguments map[string]string
	Line      string
}

Jump to

Keyboard shortcuts

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