wifi

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package wifi uses the nl80211 interface to gather information about connected WiFi clients and receive events when they connect or disconnect from the AP.

Its intended purpose is presence detection. As a result, the intended target is a WiFi AP which, likely a router running OpenWRT/LEDE.

This package is a modification of the excellent package of the same name https://github.com/mdlayher/wifi. That package is designed for use on an individual WiFi client, whereas this package is intended to be used on a WiFi AP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides access to WiFi client actions and statistics.

func NewClient

func NewClient() (*Client, error)

NewClient dials a generic netlink connection and verifies that nl80211 is available for use by this package.

func (*Client) Close

func (c *Client) Close() error

Close closes the client's generic netlink connection.

func (*Client) DumpStations

func (c *Client) DumpStations() ([]*StationInfo, error)

DumpStations returns station info for all connected clients for each of the host's network interfaces.

func (*Client) StationEvents

func (c *Client) StationEvents(ctx context.Context, handler func(added bool, station *StationInfo)) error

StationEvents registers a handler for all station add/del (connect/disconnect) events. The method blocks until the context is canceled or a read error occurs.

func (*Client) StationInfo

func (c *Client) StationInfo(addr mac.MAC) (*StationInfo, error)

StationInfo requests that nl80211 return all station info for the specified client.

type Interface

type Interface struct {
	// The index of the interface.
	Index int `json:"index"`

	// The name of the interface.
	Name string `json:"name"`

	// The hardware address of the interface.
	HardwareAddr mac.MAC `json:"mac"`

	// The physical device that this interface belongs to.
	PHY int `json:"phy"`

	// The virtual device number of this interface within a PHY.
	Device int `json:"device"`

	// The operating mode of the interface.
	Type InterfaceType `json:"type"`

	// The interface's wireless frequency in MHz.
	Frequency int `json:"frequency"`
}

An Interface is a WiFi network interface.

type InterfaceType

type InterfaceType int

An InterfaceType is the operating mode of an Interface.

const (
	// InterfaceTypeUnspecified indicates that an interface's type is unspecified
	// and the driver determines its function.
	InterfaceTypeUnspecified InterfaceType = iota

	// InterfaceTypeAdHoc indicates that an interface is part of an independent
	// basic service set (BSS) of client devices without a controlling access
	// point.
	InterfaceTypeAdHoc

	// InterfaceTypeStation indicates that an interface is part of a managed
	// basic service set (BSS) of client devices with a controlling access point.
	InterfaceTypeStation

	// InterfaceTypeAP indicates that an interface is an access point.
	InterfaceTypeAP

	// InterfaceTypeAPVLAN indicates that an interface is a VLAN interface
	// associated with an access point.
	InterfaceTypeAPVLAN

	// InterfaceTypeWDS indicates that an interface is a wireless distribution
	// interface, used as part of a network of multiple access points.
	InterfaceTypeWDS

	// InterfaceTypeMonitor indicates that an interface is a monitor interface,
	// receiving all frames from all clients in a given network.
	InterfaceTypeMonitor

	// InterfaceTypeMeshPoint indicates that an interface is part of a wireless
	// mesh network.
	InterfaceTypeMeshPoint

	// InterfaceTypeP2PClient indicates that an interface is a client within
	// a peer-to-peer network.
	InterfaceTypeP2PClient

	// InterfaceTypeP2PGroupOwner indicates that an interface is the group
	// owner within a peer-to-peer network.
	InterfaceTypeP2PGroupOwner

	// InterfaceTypeP2PDevice indicates that an interface is a device within
	// a peer-to-peer client network.
	InterfaceTypeP2PDevice

	// InterfaceTypeOCB indicates that an interface is outside the context
	// of a basic service set (BSS).
	InterfaceTypeOCB

	// InterfaceTypeNAN indicates that an interface is part of a near-me
	// area network (NAN).
	InterfaceTypeNAN
)

func (InterfaceType) String

func (t InterfaceType) String() string

String returns the string representation of an InterfaceType.

type StationInfo

type StationInfo struct {
	// Interface (index) the station is connected to.
	Iface Interface `json:"interface"`

	// The hardware address of the station.
	HardwareAddr mac.MAC `json:"mac"`

	// The time since the station last connected.
	Connected time.Duration `json:"connected"`

	// The time since wireless activity last occurred.
	Inactive time.Duration `json:"inactive"`

	// The number of bytes received by this station.
	ReceivedBytes int `json:"received-bytes"`

	// The number of bytes transmitted by this station.
	TransmittedBytes int `json:"transmitted-bytes"`

	// The number of packets received by this station.
	ReceivedPackets int `json:"received-packets"`

	// The number of packets transmitted by this station.
	TransmittedPackets int `json:"transmitted-packets"`

	// The current data receive bitrate, in bits/second.
	ReceiveBitrate int `json:"received-bitrate"`

	// The current data transmit bitrate, in bits/second.
	TransmitBitrate int `json:"transmit-bitrate"`

	// The signal strength of this station's connection, in dBm.
	Signal int `json:"signal"`

	// The number of times the station has had to retry while sending a packet.
	TransmitRetries int `json:"transmit-retries"`

	// The number of times a packet transmission failed.
	TransmitFailed int `json:"transmit-failed"`

	// The number of times a beacon loss was detected.
	BeaconLoss int `json:"beacon-loss"`
}

StationInfo contains statistics about a WiFi client.

Directories

Path Synopsis
internal
nl80211
Package nl80211 is an auto-generated package which contains constants and types used to access nl80211 information using generic netlink.
Package nl80211 is an auto-generated package which contains constants and types used to access nl80211 information using generic netlink.

Jump to

Keyboard shortcuts

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