wifi

package module
v0.0.0-...-0106fb4 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: MIT Imports: 13 Imported by: 0

README

wifi Build Status GoDoc Go Report Card

Package wifi provides access to IEEE 802.11 WiFi device actions and statistics. MIT Licensed.

At this time, package wifi supports the following operating systems:

  • Linux: using netlink, generic netlink, and nl80211.

If you would like to contribute support for another operating system, your contributions would be very welcome! Feel free to file an issue to discuss your plans.

Documentation

Overview

Package wifi provides access to IEEE 802.11 WiFi device actions and statistics.

Index

Constants

View Source
const (
	Band2GHz  = nl80211.Band2ghz
	Band5GHz  = nl80211.Band5ghz
	Band60GHz = nl80211.Band60ghz
)

Constants representing the standard WiFi frequency bands.

Variables

This section is empty.

Functions

func ChannelToFrequency

func ChannelToFrequency(channel int, band int) int

ChannelToFrequency returns the frequency given the channel number and the band, as there are overlapping channel numbers between bands.

func FrequencyToChannel

func FrequencyToChannel(freq int) int

FrequencyToChannel returns the channel number given the frequency in MHz, as defined by IEEE802.11-2007, 17.3.8.3.2 and Annex J.

Types

type BSS

type BSS struct {
	// The service set identifier, or "network name" of the BSS.
	SSID string

	// The BSS service set identifier.  In infrastructure mode, this is the
	// hardware address of the wireless access point that a client is associated
	// with.
	BSSID net.HardwareAddr

	// The frequency used by the BSS, in MHz.
	Frequency int

	// The interval between beacon transmissions for this BSS.
	BeaconInterval time.Duration

	// The time since the client last scanned this BSS's information.
	LastSeen time.Duration

	// The status of the client within the BSS.
	Status BSSStatus
}

A BSS is an 802.11 basic service set. It contains information about a wireless network associated with an Interface.

type BSSStatus

type BSSStatus int

A BSSStatus indicates the current status of client within a BSS.

const (
	// BSSStatusAuthenticated indicates that a client is authenticated with a BSS.
	BSSStatusAuthenticated BSSStatus = iota

	// BSSStatusAssociated indicates that a client is associated with a BSS.
	BSSStatusAssociated

	// BSSStatusIBSSJoined indicates that a client has joined an independent BSS.
	BSSStatusIBSSJoined
)

func (BSSStatus) String

func (s BSSStatus) String() string

String returns the string representation of a BSSStatus.

type BandAttributes

type BandAttributes struct {
	// High Throughput (802.11n) device capabilities (nil if not supported).
	HTCapabilities *HTCapabilities

	// Minimum spacing between A-MPDU frames.  Used for both HT and VHT
	// capable devices.
	MinRxAMPDUSpacing time.Duration

	// Per-frequency (channel) attributes.
	FrequencyAttributes []FrequencyAttrs

	// Per-bitrate attributes.
	BitrateAttributes []BitrateAttrs
}

BandAttributes represent the RF band-specific attributes.

type BitrateAttrs

type BitrateAttrs struct {
	// Bitrate is the bitrate in units of 100kbps.
	Bitrate float32

	// ShortPreamble indicates that a short preamble is supported in the
	// 2.4GHz band.
	ShortPreamble bool
}

BitrateAttrs represents the attributes of a bitrate.

type Client

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

A Client is a type which can access WiFi device actions and statistics using operating system-specific operations.

func New

func New() (*Client, error)

func (*Client) BSS

func (c *Client) BSS(ifi *Interface) (*BSS, error)

BSS retrieves the BSS associated with a WiFi interface.

func (*Client) Close

func (c *Client) Close() error

Close releases resources used by a Client.

func (*Client) CreateNewInterface

func (c *Client) CreateNewInterface(PHY int, ifaceType InterfaceType, name string) (err error)

func (*Client) Interfaces

func (c *Client) Interfaces() ([]*Interface, error)

Interfaces returns a list of the system's WiFi network interfaces.

func (*Client) PHY

func (c *Client) PHY(index int) (*PHY, error)

PHY returns the WiFi device corresponding to the specified index.

func (*Client) PHYs

func (c *Client) PHYs() ([]*PHY, error)

PHYs returns a list of the system's WiFi devices.

func (*Client) StationInfo

func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error)

StationInfo retrieves all station statistics about a WiFi interface.

type FrequencyAttrs

type FrequencyAttrs struct {
	// Frequency is the radio frequency in MHz.
	Frequency int

	// Disabled indicates that the channel is disabled due to regulatory
	// requirements.
	Disabled bool

	// NoIR indicates that no mechanisms that initiate radiation are
	// permitted on this channel.
	NoIR bool

	// RadarDetection indicates that radar detection is mandatory on this
	// channel.
	RadarDetection bool

	// MaxTxPower gives the maximum transmission power in mBm (100 * dBm).
	MaxTxPower float32
}

FrequencyAttrs represents the attributes of a WiFi frequency/channel.

type HTCapabilities

type HTCapabilities struct {
	// Device supports Low Density Parity Check codes.
	RxLDPC bool

	// Device supports 40MHz channels (in addition to 20MHz channels).
	CW40 bool

	// Device supports HT Greenfield (802.11n-only) mode, in which a/b/g
	// frames will be ignored.
	HTGreenfield bool

	// Device supports short guard intervals in 20MHz channels.
	SGI20 bool

	// Device supports short guard intervals in 40MHz channels.
	SGI40 bool

	// Device supports Space-Time Block Coding transmission.
	TxSTBC bool

	// Number of STBC receive streams supported by the device.  Valid values
	// are 0-3.
	RxSTBCStreams uint8

	// Device supports delayed Block Ack frames when acknowledging an
	// A-MPDU.
	HTDelayedBlockAck bool

	// Device supports long (7935 bytes) maximum A-MSDU length, compared to
	// standard 3839 bytes.
	LongMaxAMSDULength bool

	// Device supports DSSS/CCK in 40MHz channels.
	DSSSCCKHT40 bool

	// (2.4GHz) Band cannot tolerate 40MHz channels because someone has
	// requested it support 20MHz channels.
	FortyMhzIntolerant bool

	// Device supports L-SIG (non-HT) Transmit Oppportunity protection.
	LSIGTxOPProtection bool

	// Maximum receivable A-MPDU (Aggregated MAC Protocol Data Unit) frame
	// size.
	MaxRxAMPDULength int
}

HTCapabilities represents 802.11n (High Throughput) capabilities. This group of attributes is specific to each band of frequencies. Failure to support any given attribute may be due to lack support in the driver or the firmware, not only in the hardware. Some of them may also be overridden during station association.

The fields represent those in the HT Capabilities element (802.11-2016, 9.4.2.56). Notably missing is information about the device's Spatial Multiplexing Power Save (SMPS) capability. SMPS support must be determined by retrieving the device feature flags (not yet supported).

type Interface

type Interface struct {
	// The index of the interface.
	Index int

	// The name of the interface.
	Name string

	// The hardware address of the interface.
	HardwareAddr net.HardwareAddr

	// The physical device that this interface belongs to.
	PHY int

	// The virtual device number of this interface within a PHY.
	Device int

	// The operating mode of the interface.
	Type InterfaceType

	// The interface's wireless frequency in MHz.
	Frequency int
}

An Interface is a WiFi network interface.

type InterfaceCombination

type InterfaceCombination struct {
	CombinationLimits []InterfaceCombinationLimit

	// Total is the maximum number of interfaces that can be created in this
	// group.
	Total int

	// NumChannels is the number of different channels which may be used in
	// this group.
	NumChannels int

	// StaApBiMatch indicates that beacon intervals within this group must
	// all be the same, regardless of interface type.
	StaApBiMatch bool
}

InterfaceCombination represents a group of valid combinations of interface types which can be simultaneously supported on a device.

type InterfaceCombinationLimit

type InterfaceCombinationLimit struct {
	InterfaceTypes []InterfaceType

	// Max is the maximum number of interfaces that can be chosen from the
	// set of interface types in InterfaceTypes.
	Max int
}

InterfaceCombinationLimit represents a single combination of interface types which may be run simultaneously on a device.

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 PHY

type PHY struct {
	// The index of the interface.
	Index int

	// The name of the interface.
	Name string

	// The interface types this device supports.
	SupportedIftypes []InterfaceType

	// The software-only interface types this device supports.
	SoftwareIftypes []InterfaceType

	// An array of attributes related to each radio frequency band.
	BandAttributes []BandAttributes

	// A description of what combinations of interfaces the device can
	// support running simultaneously, on virtual MACs.
	InterfaceCombinations []InterfaceCombination

	// All the attributes the kernel has told us about, but we haven't
	// parsed.
	Extra map[uint16][]byte
}

A PHY represents the physical attributes of a wireless device.

type StationInfo

type StationInfo struct {
	// The hardware address of the station.
	HardwareAddr net.HardwareAddr

	// The time since the station last connected.
	Connected time.Duration

	// The time since wireless activity last occurred.
	Inactive time.Duration

	// The number of bytes received by this station.
	ReceivedBytes int

	// The number of bytes transmitted by this station.
	TransmittedBytes int

	// The number of packets received by this station.
	ReceivedPackets int

	// The number of packets transmitted by this station.
	TransmittedPackets int

	// The current data receive bitrate, in bits/second.
	ReceiveBitrate int

	// The current data transmit bitrate, in bits/second.
	TransmitBitrate int

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

	// The number of times the station has had to retry while sending a packet.
	TransmitRetries int

	// The number of times a packet transmission failed.
	TransmitFailed int

	// The number of times a beacon loss was detected.
	BeaconLoss int
}

StationInfo contains statistics about a WiFi interface operating in station mode.

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