Documentation
¶
Overview ¶
Package hostapd provides utilities for controlling hostapd.
Index ¶
- func ChannelToFrequency(target int) (int, error)
- func FrequencyToChannel(freq int) (int, error)
- func KillAll(ctx context.Context, host *ssh.Conn) error
- func RandomMAC() (net.HardwareAddr, error)
- func RandomSSID(prefix string) string
- type AdditionalBSS
- type BSSTMReqParams
- type BeaconReqParams
- type CSOption
- type Config
- type Detail
- type HTCap
- type MeasurementMode
- type ModeEnum
- type Option
- func AdditionalBSSs(bssids ...AdditionalBSS) Option
- func BSSID(bssid string) Option
- func BasicRates(r ...float32) Option
- func BeaconInterval(bi int) Option
- func Bridge(br string) Option
- func Channel(ch int) Option
- func DTIMPeriod(period int) Option
- func EnvironmentVars(envVars map[string]string) Option
- func HTCaps(caps ...HTCap) Option
- func Hidden() Option
- func MBO() Option
- func MobilityDomain(mdID string) Option
- func Mode(mode ModeEnum) Option
- func NASIdentifier(id string) Option
- func OBSSInterval(interval uint16) Option
- func PMF(p PMFEnum) Option
- func R0KHs(r0KHs ...string) Option
- func R1KHs(r1KHs ...string) Option
- func R1KeyHolder(r1khID string) Option
- func RRMBeaconReport() Option
- func SSID(ssid string) Option
- func SecurityConfig(conf security.Config) Option
- func SpectrumManagement() Option
- func SupportedRates(r ...float32) Option
- func VHTCaps(caps ...VHTCap) Option
- func VHTCenterChannel(ch int) Option
- func VHTChWidth(chw VHTChWidthEnum) Option
- type PMFEnum
- type Property
- type STAInfo
- type Server
- func (s *Server) Close(ctx context.Context) error
- func (s *Server) Config() *Config
- func (s *Server) DeauthClient(ctx context.Context, clientMAC string) error
- func (s *Server) Interface() string
- func (s *Server) ListSTA(ctx context.Context) ([]string, error)
- func (s *Server) Name() string
- func (s *Server) ReserveForClose(ctx context.Context) (context.Context, context.CancelFunc)
- func (s *Server) STAInfo(ctx context.Context, staMAC string) (*STAInfo, error)
- func (s *Server) SendBSSTMRequest(ctx context.Context, clientMAC string, params BSSTMReqParams) error
- func (s *Server) SendBeaconRequest(ctx context.Context, clientMAC string, param BeaconReqParams) error
- func (s *Server) Set(ctx context.Context, prop Property, val string) error
- func (s *Server) StartChannelSwitch(ctx context.Context, csCount, csChannel int, options ...CSOption) error
- type SubelemID
- type VHTCap
- type VHTChWidthEnum
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChannelToFrequency ¶
ChannelToFrequency maps channel id to its center frequency (in MHz).
func FrequencyToChannel ¶
FrequencyToChannel maps center frequency (in MHz) to the corresponding channel.
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 ¶
RandomSSID returns a random SSID of length 30 and given prefix.
Types ¶
type AdditionalBSS ¶
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.
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 ¶
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 ¶
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.
type HTCap ¶
type HTCap int
HTCap is the type for specifying HT capabilities in hostapd config (ht_capab=).
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 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 BasicRates ¶
BasicRates returns an Option which sets the basic rates in hostapd config.
func BeaconInterval ¶
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 DTIMPeriod ¶
DTIMPeriod returns an Option which sets the DTIM period in hostapd config.
func EnvironmentVars ¶
EnvironmentVars returns an Option which sets the env vars map in hostapd config.
func Hidden ¶
func Hidden() Option
Hidden returns an Option which sets that it is a hidden network in hostapd config.
func MobilityDomain ¶
MobilityDomain returns an Option which sets mobility domain in hostapd config.
func NASIdentifier ¶
NASIdentifier returns an Option which sets nas_identifier in hostapd config.
func OBSSInterval ¶
OBSSInterval returns an Option which sets the interval in seconds between overlapping BSS scans. Default value is 0 (disabled).
func PMF ¶
PMF returns an Options which sets whether protected management frame is enabled or required.
func R0KHs ¶
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 ¶
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 ¶
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 SecurityConfig ¶
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 ¶
SupportedRates returns an Option which sets the supported rates in hostapd config.
func VHTCenterChannel ¶
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).
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) Config ¶
Config returns the config used by the hostapd. NOTE: Caller should not modify the returned object.
func (*Server) DeauthClient ¶
DeauthClient deauthenticates the client with specified MAC address.
func (*Server) ReserveForClose ¶
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) 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.
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.