Documentation
¶
Overview ¶
Package wifi provides access to IEEE 802.11 WiFi device operations on Linux using nl80211.
Index ¶
- func ChannelToFreq2GHz(channel int) int
- func ChannelToFreq5GHz(channel int) int
- func FreqToChannel(freq int) int
- type AssocResp
- func (b *AssocResp) AppendExtendedSupportedRateIE(mandatory bool, rateMbps uint) error
- func (b *AssocResp) AppendSupportedRateIE(mandatory bool, rateMbps float64) error
- func (b AssocResp) Serialize() []byte
- func (b *AssocResp) SetBSSMaxIdlePeriod() error
- func (b *AssocResp) SetExtendedCapabilties() error
- type AssocResp2
- func (b *AssocResp2) AppendSupportedRateIE(mandatory bool, rateMbps float64) error
- func (b *AssocResp2) NinthElementIE() error
- func (b AssocResp2) Serialize() []byte
- func (b *AssocResp2) SetExtendedCapabilties() error
- func (b *AssocResp2) SetExtendedSupportedRates() error
- func (b *AssocResp2) SetHTCapabilties() error
- func (b *AssocResp2) SetHTOperation() error
- func (b *AssocResp2) SetTag90() error
- func (b *AssocResp2) SetTag191() error
- func (b *AssocResp2) SetTag192() error
- type AuthResp
- type BSS
- type BSSLoad
- type BSSStatus
- type BeaconHead
- type BeaconTail
- type BeaconTail2
- func (b *BeaconTail2) EighthElementIE() error
- func (b *BeaconTail2) NinthElementIE() error
- func (b *BeaconTail2) SecondElementIE() error
- func (b BeaconTail2) Serialize() []byte
- func (b *BeaconTail2) SetExtendedCapabilties() error
- func (b *BeaconTail2) SetExtendedSupportedRates() error
- func (b *BeaconTail2) SetHTCapabilties() error
- func (b *BeaconTail2) SetHTOperation() error
- func (b *BeaconTail2) SetRSN() error
- func (b *BeaconTail2) SetTag191() error
- func (b *BeaconTail2) SetTag192() error
- type Client
- func (c *Client) AddStation(ifi *Interface, mac net.HardwareAddr, aid uint16) error
- func (c *Client) AllBSS(ifi *Interface) ([]*BSS, error)
- func (c *Client) Associate(ifi *Interface, apMacAddr net.HardwareAddr, ssid string, freq uint32) error
- func (c *Client) Authenticate(ifi *Interface, apMacAddr net.HardwareAddr, ssid string, freq uint32) error
- func (c *Client) BSS(ifi *Interface) (*BSS, error)
- func (c *Client) CheckExtFeature(ifi *Interface, feature uint) (bool, error)
- func (c *Client) Close() error
- func (c *Client) Connect(ifi *Interface, ssid string) error
- func (c *Client) ConnectWPAPSK(ifi *Interface, ssid, psk string) error
- func (c *Client) DelStation(ifi *Interface, mac net.HardwareAddr) error
- func (c *Client) DeleteKey(ifi *Interface, keyIdx uint8) error
- func (c *Client) DeleteStation(ifi *Interface) error
- func (c *Client) Disconnect(ifi *Interface) error
- func (c *Client) GetInterface(ifi *Interface) ([]*Interface, error)
- func (c *Client) GetRegulatoryDomain(ifi *Interface) error
- func (c *Client) GetWiPhy(ifi *Interface) error
- func (c *Client) Interfaces() ([]*Interface, error)
- func (c *Client) JoinMulticastGroup(grp string) error
- func (c *Client) LeaveMulticastGroup(grp string) error
- func (c *Client) RegisterBeacons(ifi *Interface) error
- func (c *Client) RegisterFrame(ifi *Interface, frameType uint16, frameMatch []byte) error
- func (c *Client) RegisterUnexpectedFrames(ifi *Interface) error
- func (c *Client) SendAssocResponseFrame(ifi *Interface, dstMACAddr net.HardwareAddr, freq uint32, ...) error
- func (c *Client) SendAssocResponseFrame5GHz(ifi *Interface, dstMACAddr net.HardwareAddr, freq uint32, ...) error
- func (c *Client) SendAuthResponseFrame(ifi *Interface, dstMACAddr net.HardwareAddr, freq uint32, algo, status uint16) error
- func (c *Client) SendControlPortFrame(ifi *Interface, dstMACAddr net.HardwareAddr, freq uint32, data []byte) error
- func (c *Client) SendFrame(ifi *Interface, freq uint32, data []byte) error
- func (c *Client) SendProbeResponseFrame(ifi *Interface, dstMACAddr net.HardwareAddr, ssid string, freq uint32, ...) error
- func (c *Client) SendProbeResponseFrame5GHz(ifi *Interface, dstMACAddr net.HardwareAddr, ssid string, freq uint32, ...) error
- func (c *Client) SetBSS(ifi *Interface) error
- func (c *Client) SetBeacon(ifi *Interface, ssid string, freqChannel byte) error
- func (c *Client) SetDeadline(t time.Time) error
- func (c *Client) SetInterfaceToAPMode(ifi *Interface) error
- func (c *Client) SetInterfaceToStationMode(ifi *Interface) error
- func (c *Client) SetMulticastToUnicast(ifi *Interface) error
- func (c *Client) SetReadDeadline(t time.Time) error
- func (c *Client) SetRegulatoryDomain(alpha2 string) error
- func (c *Client) SetStation(ifi *Interface, mac net.HardwareAddr, aid, staCap, listenInterval uint16, ...) error
- func (c *Client) SetStation5GHz(ifi *Interface, mac net.HardwareAddr, aid, staCap, listenInterval uint16, ...) error
- func (c *Client) SetStationFlags(ifi *Interface, mac net.HardwareAddr, mask, set uint64) error
- func (c *Client) SetTXQParams(ifi *Interface, queue uint8, aifs uint8, cw_min, cw_max, burst_time uint16) error
- func (c *Client) SetWiPhy(ifi *Interface, freq, centreFreq, width uint32) error
- func (c *Client) SetWriteDeadline(t time.Time) error
- func (c *Client) StartAP(ifi *Interface, ssid string, freqChannel byte) error
- func (c *Client) StartAP5GHz(ifi *Interface, ssid string, freqChannel byte, rsnEnable bool) error
- func (c *Client) StartMulticastProcessing(ctx context.Context) <-chan []genetlink.Message
- func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error)
- func (c *Client) StopAP(ifi *Interface) error
- func (c *Client) TriggerScan(ifi *Interface) error
- type Interface
- type InterfaceType
- type RegDom
- type StationInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChannelToFreq2GHz ¶
func ChannelToFreq5GHz ¶
func FreqToChannel ¶
FreqToChannel returns the channel of the specified frequency (in MHz) for the 2.4GHz and 5GHz ranges.
Types ¶
type AssocResp ¶
type AssocResp struct {
ByteOrder binary.ByteOrder
// MAC Header
FC uint16 // Frame Control - length 2
Duration uint16 // length 2
DA net.HardwareAddr
SA net.HardwareAddr
BSSID net.HardwareAddr
SeqCtlr uint16 // len 2 -> Fragment number (4 bits) + Sequence number (12 bits)
CapabilityInfo uint16
Status uint16
AID uint16
SupportedRates []byte
ExtendedSupportedRates []byte
ExtendedCapabilties []byte
BSSMaxIdlePeriod []byte
}
func (*AssocResp) AppendExtendedSupportedRateIE ¶
rate in Mbps
func (*AssocResp) AppendSupportedRateIE ¶
rate in Mbps
func (*AssocResp) SetBSSMaxIdlePeriod ¶
func (*AssocResp) SetExtendedCapabilties ¶
type AssocResp2 ¶
type AssocResp2 struct {
ByteOrder binary.ByteOrder
// MAC Header
FC uint16 // Frame Control - length 2
Duration uint16 // length 2
DA net.HardwareAddr
SA net.HardwareAddr
BSSID net.HardwareAddr
SeqCtlr uint16 // len 2 -> Fragment number (4 bits) + Sequence number (12 bits)
CapabilityInfo uint16
Status uint16
AID uint16
SupportedRates []byte
ExtendedSupportedRates []byte
HTCapabilties []byte
HTOperation []byte
Tag191 []byte
Tag192 []byte
ExtendedCapabilties []byte
Tag90 []byte
NinthElement []byte // ID: 0xdd len: 24
}
5GHz VHT
func (*AssocResp2) AppendSupportedRateIE ¶
func (b *AssocResp2) AppendSupportedRateIE(mandatory bool, rateMbps float64) error
rate in Mbps
func (*AssocResp2) NinthElementIE ¶
func (b *AssocResp2) NinthElementIE() error
func (AssocResp2) Serialize ¶
func (b AssocResp2) Serialize() []byte
func (*AssocResp2) SetExtendedCapabilties ¶
func (b *AssocResp2) SetExtendedCapabilties() error
func (*AssocResp2) SetExtendedSupportedRates ¶
func (b *AssocResp2) SetExtendedSupportedRates() error
ExtendedSupportedRates
func (*AssocResp2) SetHTCapabilties ¶
func (b *AssocResp2) SetHTCapabilties() error
func (*AssocResp2) SetHTOperation ¶
func (b *AssocResp2) SetHTOperation() error
func (*AssocResp2) SetTag90 ¶
func (b *AssocResp2) SetTag90() error
func (*AssocResp2) SetTag191 ¶
func (b *AssocResp2) SetTag191() error
func (*AssocResp2) SetTag192 ¶
func (b *AssocResp2) SetTag192() error
type AuthResp ¶
type AuthResp struct {
ByteOrder binary.ByteOrder
// MAC Header
FC uint16 // Frame Control - length 2
Duration uint16 // length 2
DA net.HardwareAddr
SA net.HardwareAddr
BSSID net.HardwareAddr
SeqCtlr uint16 // len 2 -> Fragment number (4 bits) + Sequence number (12 bits)
Algorithm uint16
Sequence uint16
Status uint16
}
type BSS ¶
type BSS struct {
// The service set identifier, or "network name" of the BSS.
SSID string
// BSSID: 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
// Frequency: The frequency used by the BSS, in MHz.
Frequency int
// BeaconInterval: The time interval between beacon transmissions for this BSS.
BeaconInterval time.Duration
// LastSeen: The time since the client last scanned this BSS's information.
LastSeen time.Duration
// Status: The status of the client within the BSS.
Status BSSStatus
// Load: The load element of the BSS (contains StationCount, ChannelUtilization and AvailableAdmissionCapacity).
Load BSSLoad
}
A BSS is an 802.11 basic service set. It contains information about a wireless network associated with an Interface.
type BSSLoad ¶
type BSSLoad struct {
// Version: Indicates the version of the BSS Load Element. Can be 1 or 2.
Version int
// StationCount: total number of STA currently associated with this BSS.
StationCount uint16
// ChannelUtilization: Percentage of time (linearly scaled 0 to 255) that the AP sensed the medium was busy. Calculated only for the primary channel.
ChannelUtilization uint8
// AvailableAdmissionCapacity: remaining amount of medium time availible via explicit admission controll in units of 32 us/s.
AvailableAdmissionCapacity uint16
}
BSSLoad is an Information Element containing measurements of the load on the BSS.
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 // BSSStatusDisAssociated indicates that the current interface is not associated with the BSS BSSStatusDisAssociated // BSSStatusIBSSJoined indicates that a client has joined an independent BSS. BSSStatusIBSSJoined )
type BeaconHead ¶
type BeaconHead struct {
ByteOrder binary.ByteOrder
// MAC Header
FC uint16 // Frame Control - length 2
Duration uint16 // length 2
DA net.HardwareAddr
SA net.HardwareAddr
BSSID net.HardwareAddr
SeqCtlr uint16 // len 2 bytes -> Fragment number (4 bits) + Sequence number (12 bits)
// Frame Body
// Fixed Fields
Timestamp []byte // len 8
BeaconInterval uint16 // len 2
CapabilityInfo uint16 // len 2
// Information Elements (variable length)
SSID []byte
SupportedRates []byte // variable
DSParamSet []byte
}
func (*BeaconHead) AppendSupportedRateIE ¶
func (b *BeaconHead) AppendSupportedRateIE(mandatory bool, rateMbps float64) error
rate in Mbps
func (BeaconHead) Serialize ¶
func (b BeaconHead) Serialize() []byte
func (*BeaconHead) SetDSParamIE ¶
func (b *BeaconHead) SetDSParamIE(channel byte) error
used by the 2.4GHz channel. Possbile Channel values range from 1-14, with 7 being the default
func (*BeaconHead) SetSSIDIE ¶
func (b *BeaconHead) SetSSIDIE(ssid string) error
type BeaconTail ¶
type BeaconTail struct {
ERP []byte
ExtendedSupportedRates []byte
MDIE []byte // MDIE (Mobility Domain Information Element)
ExtendedCapabilties []byte
}
func (*BeaconTail) AppendExtendedSupportedRateIE ¶
func (b *BeaconTail) AppendExtendedSupportedRateIE(mandatory bool, rateMbps uint) error
rate in Mbps
func (BeaconTail) Serialize ¶
func (b BeaconTail) Serialize() []byte
func (*BeaconTail) SetERPIE ¶
func (b *BeaconTail) SetERPIE() error
func (*BeaconTail) SetExtendedCapabilties ¶
func (b *BeaconTail) SetExtendedCapabilties() error
func (*BeaconTail) SetMDIE ¶
func (b *BeaconTail) SetMDIE() error
MDIE (Mobility Domain Information Element)
type BeaconTail2 ¶
type BeaconTail2 struct {
ExtendedSupportedRates []byte // ID: 0x32 len: 2
RSN []byte // ID: 0x30 len: 20 Robust security network
SecondElement []byte // ID: 0x3b len: 2
HTCapabilties []byte // ID: 0x2d len: 26
HTOperation []byte // ID: 0x3d len: 22
ExtendedCapabilties []byte
Tag191 []byte // ID: 0xbf len: 12
Tag192 []byte // ID: 0xc0 len: 5
EighthElement []byte // ID: 0xc3 len: 4
NinthElement []byte // ID: 0xdd len: 24
}
func (*BeaconTail2) EighthElementIE ¶
func (b *BeaconTail2) EighthElementIE() error
func (*BeaconTail2) NinthElementIE ¶
func (b *BeaconTail2) NinthElementIE() error
func (*BeaconTail2) SecondElementIE ¶
func (b *BeaconTail2) SecondElementIE() error
func (BeaconTail2) Serialize ¶
func (b BeaconTail2) Serialize() []byte
func (*BeaconTail2) SetExtendedCapabilties ¶
func (b *BeaconTail2) SetExtendedCapabilties() error
func (*BeaconTail2) SetExtendedSupportedRates ¶
func (b *BeaconTail2) SetExtendedSupportedRates() error
func (*BeaconTail2) SetHTCapabilties ¶
func (b *BeaconTail2) SetHTCapabilties() error
func (*BeaconTail2) SetHTOperation ¶
func (b *BeaconTail2) SetHTOperation() error
func (*BeaconTail2) SetRSN ¶
func (b *BeaconTail2) SetRSN() error
func (*BeaconTail2) SetTag191 ¶
func (b *BeaconTail2) SetTag191() error
func (*BeaconTail2) SetTag192 ¶
func (b *BeaconTail2) SetTag192() error
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 (*Client) AddStation ¶
func (*Client) Authenticate ¶
func (*Client) CheckExtFeature ¶
func (*Client) ConnectWPAPSK ¶
Connect starts connecting the interface to the specified ssid using WPA.
func (*Client) DelStation ¶
func (c *Client) DelStation(ifi *Interface, mac net.HardwareAddr) error
func (*Client) DeleteStation ¶
func (*Client) Disconnect ¶
Dissconnect disconnects the interface.
func (*Client) GetRegulatoryDomain ¶
func (*Client) Interfaces ¶
Interfaces returns a list of the system's WiFi network interfaces.
func (*Client) JoinMulticastGroup ¶
func (*Client) LeaveMulticastGroup ¶
func (*Client) RegisterBeacons ¶
func (*Client) RegisterFrame ¶
func (*Client) RegisterUnexpectedFrames ¶
func (*Client) SendAssocResponseFrame ¶
func (*Client) SendAssocResponseFrame5GHz ¶
func (*Client) SendAuthResponseFrame ¶
func (*Client) SendControlPortFrame ¶
func (*Client) SendProbeResponseFrame ¶
func (*Client) SendProbeResponseFrame5GHz ¶
func (*Client) SetDeadline ¶
SetDeadline sets the read and write deadlines associated with the connection.
func (*Client) SetInterfaceToAPMode ¶
func (*Client) SetInterfaceToStationMode ¶
func (*Client) SetMulticastToUnicast ¶
func (*Client) SetReadDeadline ¶
SetReadDeadline sets the read deadline associated with the connection.
func (*Client) SetRegulatoryDomain ¶
func (*Client) SetStation ¶
func (*Client) SetStation5GHz ¶
func (*Client) SetStationFlags ¶
func (*Client) SetTXQParams ¶
func (*Client) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline associated with the connection.
func (*Client) StartAP5GHz ¶
func (*Client) StartMulticastProcessing ¶
func (*Client) StationInfo ¶
func (c *Client) StationInfo(ifi *Interface) ([]*StationInfo, error)
StationInfo retrieves all station statistics about a WiFi interface.
Since v0.2.0: if there are no stations, an empty slice is returned instead of an error.
func (*Client) TriggerScan ¶
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
// regulatory domain
RegDom RegDom
// power saver state 0x0 -> off 0x1 -> on
PowerSaver []byte
}
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 {
// 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 the last received PPDU, in dBm.
Signal int
// The average signal strength, in dBm.
SignalAverage 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.