hostapd

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 29 Imported by: 0

Documentation

Overview

Package hostapd provides utilities for controlling hostapd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChannelToFrequency

func ChannelToFrequency(target int) (int, error)

ChannelToFrequency maps channel id to its center frequency (in MHz).

func FrequencyToChannel

func FrequencyToChannel(freq int) (int, error)

FrequencyToChannel maps center frequency (in MHz) to the corresponding channel.

func KillAll

func KillAll(ctx context.Context, host *ssh.Conn) error

KillAll kills all running hostapd on host, useful for environment setup/cleanup.

func RandomMAC

func RandomMAC() (net.HardwareAddr, error)

RandomMAC returns a random MAC address for WiFi device. The MAC address is a locally administered unicast address. This can also be used as BSSID.

func RandomSSID

func RandomSSID(prefix string) string

RandomSSID returns a random SSID of length 30 and given prefix.

Types

type AdditionalBSS

type AdditionalBSS struct {
	IfaceName string
	SSID      string
	BSSID     string
}

AdditionalBSS is the type for specifying parameters of additional BSSs to be advertised on the same phy. All fields are required, and must be distinct from the corresponding fields of the primary network.

type BSSTMReqParams

type BSSTMReqParams struct {
	// Neighbors is the list of neighboring APs
	Neighbors []string
	// DisassocImminent indicates whether or not the AP will disassociate the STA soon.
	DisassocImminent bool
	// DisassocTimer is the time (in 100ms) before the AP will disassoc the STA.
	DisassocTimer time.Duration
	// ReassocDelay is the delay (in seconds) before the STA is permitted to reassociate to the AP.
	ReassocDelay time.Duration
	// BSSTerm is the time before the AP will be terminated
	BSSTerm time.Duration
}

BSSTMReqParams defines the parameters for a BSS Transition Management Request.

type BeaconReqParams

type BeaconReqParams struct {
	// OpClass is the operating class.
	OpClass uint8
	// Channel specifies the channel to scan on.
	Channel uint8
	// Duration is the measurement time limit.
	Duration uint16
	// Mode is the measurement mode to be used.
	Mode MeasurementMode
	// BSSID is the BSSID to scan for.
	BSSID net.HardwareAddr
	// SSID is the SSID to scan for.
	SSID string
	// ReportingDetail specifies which IEs to include in the report.
	ReportingDetail Detail
	// ReportChannels specifies which channels to report on.
	ReportChannels []uint8
	// Request lists IEs expected in the report.
	Request []layers.Dot11InformationElementID
	// LastFrame indicates whether or not we should indicate that the last report frame is the last frame.
	LastFrame bool
}

BeaconReqParams defines the parameters for a beacon request.

func (BeaconReqParams) Serialize

func (b BeaconReqParams) Serialize() (string, error)

Serialize serializes the beacon request parameters into a hex string recognizable by hostapd.

type CSOption

type CSOption func(*csaConfig)

CSOption is the function signature used to specify options of CSA command.

func CSAMode

func CSAMode(m string) CSOption

CSAMode returns an Option which sets mode in CSA.

type Config

type Config struct {
	SSID               string
	Mode               ModeEnum
	Channel            int
	HTCaps             HTCap
	VHTCaps            []VHTCap
	VHTCenterChannel   int
	VHTChWidth         VHTChWidthEnum
	Hidden             bool
	SpectrumManagement bool
	BeaconInterval     int
	SecurityConfig     security.Config
	PMF                PMFEnum
	DTIMPeriod         int
	BSSID              string
	OBSSInterval       uint16
	Bridge             string
	MobilityDomain     string
	NASIdentifier      string
	R1KeyHolder        string
	R0KHs              []string
	R1KHs              []string
	MBO                bool
	RRMBeaconReport    bool
	AdditionalBSSs     []AdditionalBSS
	SupportedRates     []float32
	BasicRates         []float32
	EnvironmentVars    map[string]string
}

Config is the configuration to start hostapd on a router.

func NewConfig

func NewConfig(ops ...Option) (*Config, error)

NewConfig creates a Config with given options. Default value of Ssid is a random generated string with prefix "TAST_TEST_" and total length 30.

func (*Config) Format

func (c *Config) Format(iface, ctrlPath string) (string, error)

Format composes a hostapd.conf based on the given Config, iface and ctrlPath. iface is the network interface for the hostapd to run. ctrlPath is the control file path for hostapd to communicate with hostapd_cli.

func (*Config) PcapFreqOptions

func (c *Config) PcapFreqOptions() ([]iw.SetFreqOption, error)

PcapFreqOptions returns the options for the caller to set frequency with iw for preparing interface for packet capturing.

func (*Config) PerfDesc

func (c *Config) PerfDesc() string

PerfDesc returns the description of this config. Useful for reporting perf metrics.

type Detail

type Detail uint8

Detail specifies which IEs to include in the report.

const (
	// DetailNone omits all IEs from report.
	DetailNone Detail = 0
	// DetailRequestedOnly includes only the IEs specified in the request subelement in the report.
	DetailRequestedOnly Detail = 1
	// DetailAllFields includes all IEs.
	DetailAllFields Detail = 2
)

type HTCap

type HTCap int

HTCap is the type for specifying HT capabilities in hostapd config (ht_capab=).

const (
	HTCapHT20      HTCap = 1 << iota // HTCaps string "" means HT20.
	HTCapHT40                        // auto-detect supported "[HT40-]" or "[HT40+]"
	HTCapHT40Minus                   // "[HT40-]"
	HTCapHT40Plus                    // "[HT40+]"
	HTCapSGI20                       // "[SHORT-GI-20]"
	HTCapSGI40                       // "[SHORT-GI-40]"

)

HTCap enums, use bitmask for ease of checking existence.

type MeasurementMode

type MeasurementMode uint8

MeasurementMode is the beacon request measurement mode to be used.

const (
	// ModePassive scan on selected channels.
	ModePassive MeasurementMode = 0
	// ModeActive scan on selected channels.
	ModeActive MeasurementMode = 1
	// ModeTable uses the cached scan results.
	ModeTable MeasurementMode = 2
)

type ModeEnum

type ModeEnum string

ModeEnum is the type for specifying hostap mode.

const (
	Mode80211a       ModeEnum = "a"
	Mode80211b       ModeEnum = "b"
	Mode80211g       ModeEnum = "g"
	Mode80211nMixed  ModeEnum = "n-mixed"
	Mode80211nPure   ModeEnum = "n-only"
	Mode80211acMixed ModeEnum = "ac-mixed"
	Mode80211acPure  ModeEnum = "ac-only"
)

Mode enums.

type Option

type Option func(*Config)

Option is the function signature used to specify options of Config.

func AdditionalBSSs

func AdditionalBSSs(bssids ...AdditionalBSS) Option

AdditionalBSSs returns an Option which sets AdditionalBSSs in hostapd config. Each AdditionalBSS should have a unique interface name, SSID, and BSSID. The number of AdditionalBSSs is limited by the phy. See the 'valid interface combinations' section of `iw phy` for more.

func BSSID

func BSSID(bssid string) Option

BSSID returns an Option which sets bssid in hostapd config.

func BasicRates

func BasicRates(r ...float32) Option

BasicRates returns an Option which sets the basic rates in hostapd config.

func BeaconInterval

func BeaconInterval(bi int) Option

BeaconInterval returns an Option which sets the beacon interval in hostapd config. The unit is 1kus = 1.024ms. The value should be in 15..65535.

func Bridge

func Bridge(br string) Option

Bridge returns an Option which sets bridge in hostapd config.

func Channel

func Channel(ch int) Option

Channel returns an Option which sets channel in hostapd config.

func DTIMPeriod

func DTIMPeriod(period int) Option

DTIMPeriod returns an Option which sets the DTIM period in hostapd config.

func EnvironmentVars

func EnvironmentVars(envVars map[string]string) Option

EnvironmentVars returns an Option which sets the env vars map in hostapd config.

func HTCaps

func HTCaps(caps ...HTCap) Option

HTCaps returns an Option which sets HT capabilities in hostapd config.

func Hidden

func Hidden() Option

Hidden returns an Option which sets that it is a hidden network in hostapd config.

func MBO

func MBO() Option

MBO returns an Option which enables MBO in hostapd config.

func MobilityDomain

func MobilityDomain(mdID string) Option

MobilityDomain returns an Option which sets mobility domain in hostapd config.

func Mode

func Mode(mode ModeEnum) Option

Mode returns an Option which sets mode in hostapd config.

func NASIdentifier

func NASIdentifier(id string) Option

NASIdentifier returns an Option which sets nas_identifier in hostapd config.

func OBSSInterval

func OBSSInterval(interval uint16) Option

OBSSInterval returns an Option which sets the interval in seconds between overlapping BSS scans. Default value is 0 (disabled).

func PMF

func PMF(p PMFEnum) Option

PMF returns an Options which sets whether protected management frame is enabled or required.

func R0KHs

func R0KHs(r0KHs ...string) Option

R0KHs returns an Option which sets R0KHs in hostapd config. Each R0KH should be in format: <MAC address> <NAS Identifier> <256-bit key as hex string>

func R1KHs

func R1KHs(r1KHs ...string) Option

R1KHs returns an Option which sets R1KHs in hostapd config. Each R1KH should be in format: <MAC address> <R1KH-ID> <256-bit key as hex string>

func R1KeyHolder

func R1KeyHolder(r1khID string) Option

R1KeyHolder returns an Option which sets r1 key holder identifier in hostapd config.

func RRMBeaconReport

func RRMBeaconReport() Option

RRMBeaconReport returns an Option which enables RRM Beacon Report in hostapd config.

func SSID

func SSID(ssid string) Option

SSID returns an Option which sets ssid in hostapd config.

func SecurityConfig

func SecurityConfig(conf security.Config) Option

SecurityConfig returns an Option which sets the security config in hostapd config.

func SpectrumManagement

func SpectrumManagement() Option

SpectrumManagement returns an Option which enables spectrum management in hostapd config.

func SupportedRates

func SupportedRates(r ...float32) Option

SupportedRates returns an Option which sets the supported rates in hostapd config.

func VHTCaps

func VHTCaps(caps ...VHTCap) Option

VHTCaps returns an Option which sets VHT capabilities in hostapd config.

func VHTCenterChannel

func VHTCenterChannel(ch int) Option

VHTCenterChannel returns an Option which sets VHT center channel in hostapd config.

func VHTChWidth

func VHTChWidth(chw VHTChWidthEnum) Option

VHTChWidth returns an Option which sets VHT operating channel width in hostapd config.

type PMFEnum

type PMFEnum int

PMFEnum is the type for specifying the setting of "Protected Management Frames" (IEEE802.11w).

const (
	PMFDisabled PMFEnum = iota
	PMFOptional
	PMFRequired
)

PMF enums.

type Property

type Property string

Property is the property name of a hostapd property

const (
	// PropertyMBOAssocDisallow prevents association to hostapd if set to 1.
	PropertyMBOAssocDisallow Property = "mbo_assoc_disallow"
)

type STAInfo

type STAInfo struct {
	// RxPackets is the count of Rx packets.
	RxPackets int
	// RxPackets is the count of Tx packets.
	TxPackets int
	// RxPackets is the size of Rx data.
	RxBytes int
	// RxPackets is the size of Tx data.
	TxBytes int
	// ConnectedTime is the connected time of the STA.
	ConnectedTime time.Duration
	// InactiveTime is the inactive time of the STA.
	InactiveTime time.Duration
}

STAInfo contains the information of a connected STA.

type Server

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

Server controls a hostapd on router.

func StartServer

func StartServer(ctx context.Context, host *ssh.Conn, name, iface, workDir string, config *Config) (server *Server, retErr error)

StartServer creates a new Server object and runs hostapd on iface of the given host with settings specified in config. workDir is the dir on host for the server to put temporary files. name is the identifier used for log filenames in OutDir. After getting a Server instance, s, the caller should call s.Close() at the end, and use the shortened ctx (provided by s.ReserveForClose()) before s.Close() to reserve time for it to run.

func (*Server) Close

func (s *Server) Close(ctx context.Context) error

Close stops hostapd and cleans up related resources.

func (*Server) Config

func (s *Server) Config() *Config

Config returns the config used by the hostapd. NOTE: Caller should not modify the returned object.

func (*Server) DeauthClient

func (s *Server) DeauthClient(ctx context.Context, clientMAC string) error

DeauthClient deauthenticates the client with specified MAC address.

func (*Server) Interface

func (s *Server) Interface() string

Interface returns the interface used by the hostapd.

func (*Server) ListSTA

func (s *Server) ListSTA(ctx context.Context) ([]string, error)

ListSTA lists the MAC addresses of connected STAs.

func (*Server) Name

func (s *Server) Name() string

Name returns the name used by the hostapd.

func (*Server) ReserveForClose

func (s *Server) ReserveForClose(ctx context.Context) (context.Context, context.CancelFunc)

ReserveForClose returns a shortened ctx with cancel function. The shortened ctx is used for running things before s.Close() to reserve time for it to run.

func (*Server) STAInfo

func (s *Server) STAInfo(ctx context.Context, staMAC string) (*STAInfo, error)

STAInfo queries the information of the connected STA.

func (*Server) SendBSSTMRequest

func (s *Server) SendBSSTMRequest(ctx context.Context, clientMAC string, params BSSTMReqParams) error

SendBSSTMRequest sends a BSS Transition Management Request to the specified client.

func (*Server) SendBeaconRequest

func (s *Server) SendBeaconRequest(ctx context.Context, clientMAC string, param BeaconReqParams) error

SendBeaconRequest sends a Beacon Request to the specified client.

func (*Server) Set

func (s *Server) Set(ctx context.Context, prop Property, val string) error

Set sets a hostapd property prop to value val

func (*Server) StartChannelSwitch

func (s *Server) StartChannelSwitch(ctx context.Context, csCount, csChannel int, options ...CSOption) error

StartChannelSwitch initiates a channel switch in the AP.

type SubelemID

type SubelemID uint8

SubelemID are the element IDs in beacon reports.

const (
	SubelemSSID           SubelemID = 0
	SubelemInfo           SubelemID = 1
	SubelemDetail         SubelemID = 2
	SubelemRequest        SubelemID = 10
	SubelemChannelReport  SubelemID = 51
	SubelemLastIndication SubelemID = 164
)

Some commonly used sub-elements in beacon reports.

type VHTCap

type VHTCap string

VHTCap is the type for specifying VHT capabilities in hostapd config (vht_capab=).

const (
	VHTCapVHT160             VHTCap = "[VHT160]"
	VHTCapVHT16080Plus80     VHTCap = "[VHT160-80PLUS80]"
	VHTCapRXLDPC             VHTCap = "[RXLDPC]"
	VHTCapSGI80              VHTCap = "[SHORT-GI-80]"
	VHTCapSGI160             VHTCap = "[SHORT-GI-160]"
	VHTCapTxSTBC2BY1         VHTCap = "[TX-STBC-2BY1]"
	VHTCapRxSTBC1            VHTCap = "[RX-STBC-1]"
	VHTCapRxSTBC12           VHTCap = "[RX-STBC-12]"
	VHTCapRxSTBC123          VHTCap = "[RX-STBC-123]"
	VHTCapRxSTBC1234         VHTCap = "[RX-STBC-1234]"
	VHTCapSUBeamformer       VHTCap = "[SU-BEAMFORMER]"
	VHTCapSUBeamformee       VHTCap = "[SU-BEAMFORMEE]"
	VHTCapBFAntenna2         VHTCap = "[BF-ANTENNA-2]"
	VHTCapSoundingDimension2 VHTCap = "[SOUNDING-DIMENSION-2]"
	VHTCapMUBeamformer       VHTCap = "[MU-BEAMFORMER]"
	VHTCapMUBeamformee       VHTCap = "[MU-BEAMFORMEE]"
	VHTCapVHTTXOPPS          VHTCap = "[VHT-TXOP-PS]"
	VHTCapHTCVHT             VHTCap = "[HTC-VHT]"
	VHTCapMaxAMPDULenExp0    VHTCap = "[MAX-A-MPDU-LEN-EXP0]"
	VHTCapMaxAMPDULenExp1    VHTCap = "[MAX-A-MPDU-LEN-EXP1]"
	VHTCapMaxAMPDULenExp2    VHTCap = "[MAX-A-MPDU-LEN-EXP2]"
	VHTCapMaxAMPDULenExp3    VHTCap = "[MAX-A-MPDU-LEN-EXP3]"
	VHTCapMaxAMPDULenExp4    VHTCap = "[MAX-A-MPDU-LEN-EXP4]"
	VHTCapMaxAMPDULenExp5    VHTCap = "[MAX-A-MPDU-LEN-EXP5]"
	VHTCapMaxAMPDULenExp6    VHTCap = "[MAX-A-MPDU-LEN-EXP6]"
	VHTCapMaxAMPDULenExp7    VHTCap = "[MAX-A-MPDU-LEN-EXP7]"
	VHTCapVHTLinkADAPT2      VHTCap = "[VHT-LINK-ADAPT2]"
	VHTCapVHTLinkADAPT3      VHTCap = "[VHT-LINK-ADAPT3]"
	VHTCapRxAntennaPattern   VHTCap = "[RX-ANTENNA-PATTERN]"
	VHTCapTxAntennaPattern   VHTCap = "[TX-ANTENNA-PATTERN]"
)

Each capability can be simply mapped to a string.

type VHTChWidthEnum

type VHTChWidthEnum int

VHTChWidthEnum is the type for specifying operating channel width in hostapd config (vht_oper_chwidth=).

const (
	// VHTChWidth20Or40 is the default value when none of VHTChWidth* specified.
	VHTChWidth20Or40 VHTChWidthEnum = iota
	VHTChWidth80
	VHTChWidth160
	VHTChWidth80Plus80
)

VHTChWidth enums.

Jump to

Keyboard shortcuts

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