wifi

package
v0.0.0-...-19fda0b Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IE_SSID = 0
)

List of 802.11 Information Element types.

Variables

View Source
var NanClients = map[uint32]*Nan{}

Functions

This section is empty.

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 Client

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

A client is the Linux implementation of osClient, which makes use of netlink, generic netlink, and nl80211 to provide access to WiFi device actions and statistics.

func New

func New() (*Client, error)

New creates a new Client.

func (*Client) BSS

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

BSS requests that nl80211 return the BSS for the specified Interface.

func (*Client) Close

func (c *Client) Close() error

Close closes the client's generic netlink connection.

func (*Client) Conn

func (c *Client) Conn() *genetlink.Conn

func (*Client) Interfaces

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

Interfaces requests that nl80211 return a list of all WiFi interfaces present on this system.

func (*Client) NewMon

func (c *Client) NewMon(phy int) error

WIP

func (*Client) Phys

func (c *Client) Phys() ([]*Phy, error)

Call 'CMD_GET_WIPHY' to list phy interfaces.

func (*Client) RegisterFrame

func (c *Client) RegisterFrame(ifi *Interface, t uint16, match []byte) error

RegisterFrame will ask netlink to deliver frames matching a pattern. Note that wpa_supplicant also registers for frames - and may prevent us from getting registered.

This must be called on the receiving connection (cr), before the read loop.

func (*Client) RemainOnChannel

func (c *Client) RemainOnChannel(ifi *Interface, freq, dur int) error

func (*Client) Scan

func (c *Client) Scan() error

Close releases resources used by a Client.

func (*Client) StartReceive

func (c *Client) StartReceive()

Separate client thread receiving frames and messages. Send and 'stay on channel' using the primary channel, to avoid locking issues.

func (*Client) StationInfo

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

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

type IE

type IE struct {
	ID uint8
	// Length field implied by length of data
	Data []byte
}

An IE is an 802.11 information element.

func ParseATTs

func ParseATTs(b []byte) ([]IE, error)

func ParseIEs

func ParseIEs(b []byte) ([]IE, error)

ParseIEs parses zero or more ies from a byte slice. Reference:

https://www.safaribooksonline.com/library/view/80211-wireless-networks/0596100523/ch04.html#wireless802dot112-CHP-4-FIG-31

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 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 Nan

type Nan struct {
	IFace *Interface

	SendErrors   int
	LastSent     time.Time
	LastSentTime time.Duration
	LastSentSeq  uint32
	// contains filtered or unexported fields
}

func NewNan

func NewNan(c *Client, i *Interface) *Nan

func (*Nan) SendBeacon

func (c *Nan) SendBeacon(syncFrame bool) error

Send NAN beacon frame

func (*Nan) SendDiscovery

func (c *Nan) SendDiscovery(ifi *Interface, sdu []byte, dwelltime int) error

Send NAN Publish or Subscribe frame

func (*Nan) SendFollowup

func (c *Nan) SendFollowup(to []byte, toPort byte, freq int, sdu []byte) error

Send data using NAN "FollowUp" function, in a SDF

func (*Nan) SendFrameRaw

func (c *Nan) SendFrameRaw(ifi *Interface, outBuf []byte,
	freq, dwelltime int) error

SendFrameRaw sends a raw frame, starting with 802.11 type/subtype Will fill in this station hardware address

type NanClient

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

func (*NanClient) Close

func (c *NanClient) Close()

type Phy

type Phy 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
}

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.

Jump to

Keyboard shortcuts

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