wifi

package module
v0.0.3-beta Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 6 Imported by: 0

README

LinuxWifi

Work in progress

Forked from mdlayher/wifi.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WifiChannel = map[int]uint32{
	1:   2412,
	2:   2417,
	3:   2422,
	4:   2427,
	5:   2432,
	6:   2437,
	7:   2442,
	8:   2447,
	9:   2452,
	10:  2457,
	11:  2462,
	12:  2467,
	13:  2472,
	14:  2484,
	36:  5180,
	38:  5190,
	40:  5200,
	42:  5210,
	44:  5220,
	46:  5230,
	48:  5240,
	50:  5250,
	52:  5260,
	54:  5270,
	56:  5280,
	58:  5290,
	60:  5300,
	62:  5310,
	64:  5320,
	100: 5500,
	102: 5510,
	104: 5520,
	106: 5530,
	108: 5540,
	110: 5550,
	112: 5560,
	114: 5570,
	116: 5580,
	118: 5590,
	120: 5600,
	122: 5610,
	124: 5620,
	126: 5630,
	128: 5640,
	130: 5650,
	132: 5660,
	134: 5670,
	136: 5680,
	138: 5690,
	140: 5700,
	149: 5745,
	151: 5755,
	153: 5765,
	155: 5775,
	157: 5785,
	159: 5795,
	161: 5805,
	165: 5825,
}

Functions

func NewAttributeFactory

func NewAttributeFactory[T any](typ uint16) func(T) *Attribute[T]

NewAttributeFactory takes an attribute type as an argument and returns a function which takes an attribute value and returns a pointer to an Attribute object

func NewNl80211Message

func NewNl80211Message(cmd int, lst []AttributeEncoder) (*genetlink.Message, error)

NewNl80211Message takes a command and a list of attributes and returns a generic netlink message containing the encoded attributes.

Types

type Attribute

type Attribute[T any] struct {
	// contains filtered or unexported fields
}

Attributes have a type (ex NL80211_ATTR_IFTYPE) and a value. They are encoded by passing a netlink.AttributeEncoder to their EncodeAttribute method.

func InterfaceIndexAttribute

func InterfaceIndexAttribute(val uint32) *Attribute[uint32]

InterfaceIndexAttribute returns a pointer to an *Attribute[uint32] containing a valid NL80211_ATTR_IFINDEX value

func InterfaceNameAttribute

func InterfaceNameAttribute(name string) *Attribute[string]

InterfaceNameAttribute returns a pointer to an *Attribute[string] containing a valid NL80211_ATTR_IFNAME value

func InterfaceTypeAttribute

func InterfaceTypeAttribute(val uint32) *Attribute[uint32]

InterfaceTypeAttribute returns a pointer to an *Attribute[uint32] containing a valid NL80211_ATTR_IFTYPE value

func MacAttribute

func MacAttribute(val []byte) *Attribute[[]byte]

MacAttribute returns a pointer to an *Attribute[uint32] containing a valid NL80211_ATTR_MAC value

func WiphyAttribute

func WiphyAttribute(id uint32) *Attribute[uint32]

WiphyAttribute returns a pointer to an *Attribute[uint32] containing a valid NL80211_ATTR_WIPHY value

func WiphyFrequencyAttribute

func WiphyFrequencyAttribute(val uint32) *Attribute[uint32]

WiphyFrequencyAttribute returns a pointer to an *Attribute[uint32] containing a valid NL80211_ATTR_WIPHY_FREQ value

func (*Attribute[T]) EncodeAttribute

func (a *Attribute[T]) EncodeAttribute(ae *netlink.AttributeEncoder)

type AttributeEncoder

type AttributeEncoder interface {
	EncodeAttribute(*netlink.AttributeEncoder)
}

type Client

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

Client objects handle communication with the nl80211 kernel interface.

func NewClient

func NewClient() (*Client, error)

NewClient opens a generic netlink connection and sets the nl80211 family ID

func (*Client) Close

func (c *Client) Close() error

Close closes the client's generic netlink connection.

func (*Client) DeleteInterface

func (c *Client) DeleteInterface(w *WifiInterface) error

DeleteInterface deletes a wireless interface

func (*Client) DumpInterfaces

func (c *Client) DumpInterfaces() ([]*WifiInterface, error)

DumpInterfaces returns a list of all wifi interfaces present on the system.

func (*Client) InterfaceById

func (c *Client) InterfaceById(ifindex uint32) (*WifiInterface, error)

InterfaceById returns the interface that matches the given interface index.

func (*Client) InterfaceByName

func (c *Client) InterfaceByName(name string) (*WifiInterface, error)

InterfaceByName takes an interface name and returns a pointer to the corresponding WifiInterface

func (*Client) NewInterface

func (c *Client) NewInterface(w *WifiInterface, ifname string, iftype InterfaceType) error

NewInterface creates a new wifi interface using the underlying PHY of the provided interface

func (*Client) Reset

func (c *Client) Reset() error

Reset closes and reopens the Client's netlink connection

func (*Client) SetChannel

func (c *Client) SetChannel(w *WifiInterface, channel int) error

SetChannel sets the wifi channel of a given interface

func (*Client) SetInterfaceType

func (c *Client) SetInterfaceType(w *WifiInterface, iftype InterfaceType) error

SetInterfaceType sets the interface type of the given interface

type InterfaceType

type InterfaceType int

An InterfaceType is the operating mode of an Interface.

const (
	InterfaceTypeUnspecified InterfaceType = iota
	InterfaceTypeAdHoc
	InterfaceTypeStation
	InterfaceTypeAP
	InterfaceTypeAPVLAN
	InterfaceTypeWDS
	InterfaceTypeMonitor
	InterfaceTypeMeshPoint
	InterfaceTypeP2PClient
	InterfaceTypeP2PGroupOwner
	InterfaceTypeP2PDevice
	InterfaceTypeOCB
	InterfaceTypeNAN
)

func (InterfaceType) String

func (t InterfaceType) String() string

String returns the string representation of an InterfaceType.

type Nl80211Request

type Nl80211Request struct {
	RequestMessage *genetlink.Message
	Flags          netlink.HeaderFlags
	// contains filtered or unexported fields
}

func (Nl80211Request) Response

func (r Nl80211Request) Response(c *Client) ([]genetlink.Message, error)

Response sends a Netlink request and returns a list of generic netlink messages (the response)

type WifiInterface

type WifiInterface struct {
	Index        uint32
	Name         string
	HardwareAddr net.HardwareAddr
	Phy          uint32
	Type         InterfaceType
	Device       uint64
	Frequency    uint32
}

func (*WifiInterface) String

func (c *WifiInterface) String() string

Jump to

Keyboard shortcuts

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