2017-01-09 20:33:55 +01:00
|
|
|
package wifi
|
|
|
|
|
2017-01-12 18:41:35 +01:00
|
|
|
import (
|
|
|
|
"errors"
|
2017-01-17 06:54:18 +01:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2017-01-12 18:41:35 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// errNotStation is returned when attempting to query station info for
|
|
|
|
// an interface which is not a station.
|
|
|
|
errNotStation = errors.New("interface is not a station")
|
2017-01-17 06:54:18 +01:00
|
|
|
|
|
|
|
// errUnimplemented is returned by all functions on platforms that
|
|
|
|
// do not have package wifi implemented.
|
|
|
|
errUnimplemented = fmt.Errorf("package wifi not implemented on %s/%s",
|
|
|
|
runtime.GOOS, runtime.GOARCH)
|
2017-01-12 18:41:35 +01:00
|
|
|
)
|
|
|
|
|
2017-01-09 20:33:55 +01:00
|
|
|
// A Client is a type which can access WiFi device actions and statistics
|
|
|
|
// using operating system-specific operations.
|
|
|
|
type Client struct {
|
|
|
|
c osClient
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates a new Client.
|
|
|
|
func New() (*Client, error) {
|
|
|
|
c, err := newClient()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Client{
|
|
|
|
c: c,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-01-12 18:41:35 +01:00
|
|
|
// Close releases resources used by a Client.
|
|
|
|
func (c *Client) Close() error {
|
|
|
|
return c.c.Close()
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:33:55 +01:00
|
|
|
// Interfaces returns a list of the system's WiFi network interfaces.
|
|
|
|
func (c *Client) Interfaces() ([]*Interface, error) {
|
|
|
|
return c.c.Interfaces()
|
|
|
|
}
|
|
|
|
|
2017-01-17 06:54:18 +01:00
|
|
|
// BSS retrieves the BSS associated with a WiFi interface.
|
|
|
|
func (c *Client) BSS(ifi *Interface) (*BSS, error) {
|
|
|
|
return c.c.BSS(ifi)
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:33:55 +01:00
|
|
|
// StationInfo retrieves statistics about a WiFi interface operating in
|
|
|
|
// station mode.
|
|
|
|
func (c *Client) StationInfo(ifi *Interface) (*StationInfo, error) {
|
2017-01-12 18:41:35 +01:00
|
|
|
if ifi.Type != InterfaceTypeStation {
|
|
|
|
return nil, errNotStation
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:33:55 +01:00
|
|
|
return c.c.StationInfo(ifi)
|
|
|
|
}
|
|
|
|
|
|
|
|
// An osClient is the operating system-specific implementation of Client.
|
|
|
|
type osClient interface {
|
2017-01-12 18:41:35 +01:00
|
|
|
Close() error
|
2017-01-09 20:33:55 +01:00
|
|
|
Interfaces() ([]*Interface, error)
|
2017-01-17 06:54:18 +01:00
|
|
|
BSS(ifi *Interface) (*BSS, error)
|
2017-01-09 20:33:55 +01:00
|
|
|
StationInfo(ifi *Interface) (*StationInfo, error)
|
|
|
|
}
|