iotwifi

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2018 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunWifi

func RunWifi(log bunyan.Logger, messages chan CmdMessage, cfgLocation string)

RunWifi starts AP and Station modes.

Types

type CmdMessage

type CmdMessage struct {
	Id      string
	Command string
	Message string
	Error   bool
	Cmd     *exec.Cmd
	Stdin   *io.WriteCloser
}

CmdMessage structures command output.

type CmdRunner

type CmdRunner struct {
	Log      bunyan.Logger
	Messages chan CmdMessage
	Handlers map[string]func(CmdMessage)
	Commands map[string]*exec.Cmd
}

CmdRunner runs internal commands allows output handlers to be attached.

func (*CmdRunner) HandleFunc

func (c *CmdRunner) HandleFunc(cmdId string, handler func(cmdMessage CmdMessage))

HandleFunc is a function that gets all channel messages for a command id

func (*CmdRunner) ProcessCmd

func (c *CmdRunner) ProcessCmd(id string, cmd *exec.Cmd)

ProcessCmd processes an internal command.

type Command

type Command struct {
	Log      bunyan.Logger
	Runner   CmdRunner
	SetupCfg *SetupCfg
}

Command for device network commands.

func (*Command) AddApInterface

func (c *Command) AddApInterface()

AddApInterface adds the AP interface.

func (*Command) CheckApInterface

func (c *Command) CheckApInterface()

CheckInterface checks the AP interface.

func (*Command) ConfigureApInterface

func (c *Command) ConfigureApInterface()

ConfigureApInterface configured the AP interface.

func (*Command) RemoveApInterface

func (c *Command) RemoveApInterface()

RemoveApInterface removes the AP interface.

func (*Command) StartDnsmasq

func (c *Command) StartDnsmasq()

StartDnsmasq starts dnsmasq.

func (*Command) StartWpaSupplicant

func (c *Command) StartWpaSupplicant()

StartWpaSupplicant starts wpa_supplicant.

func (*Command) UpApInterface

func (c *Command) UpApInterface()

UpApInterface ups the AP Interface.

type DnsmasqCfg

type DnsmasqCfg struct {
	Address     string `json:"address"`      // --address=/#/192.168.27.1",
	DhcpRange   string `json:"dhcp_range"`   // "--dhcp-range=192.168.27.100,192.168.27.150,1h",
	VendorClass string `json:"vendor_class"` // "--dhcp-vendorclass=set:device,IoT",
}

DnsmasqCfg configures dnsmasq and is used by SetupCfg.

type HostApdCfg

type HostApdCfg struct {
	Ssid          string `json:"ssid"`           // ssid=iotwifi2
	WpaPassphrase string `json:"wpa_passphrase"` // wpa_passphrase=iotwifipass
	Channel       string `json:"channel"`        //  channel=6
	Ip            string `json:"ip"`             // 192.168.27.1
}

HostApdCfg configures hostapd and is used by SetupCfg.

type SetupCfg

type SetupCfg struct {
	DnsmasqCfg       DnsmasqCfg       `json:"dnsmasq_cfg"`
	HostApdCfg       HostApdCfg       `json:"host_apd_cfg"`
	WpaSupplicantCfg WpaSupplicantCfg `json:"wpa_supplicant_cfg"`
}

SetupCfg is the main configuration structure.

type WpaCfg

type WpaCfg struct {
	Log    bunyan.Logger
	WpaCmd []string
	WpaCfg *SetupCfg
}

WpaCfg for configuring wpa

func NewWpaCfg

func NewWpaCfg(log bunyan.Logger, cfgLocation string) *WpaCfg

NewWpaCfg produces WpaCfg configuration types.

func (*WpaCfg) ConfiguredNetworks

func (wpa *WpaCfg) ConfiguredNetworks() string

ConfiguredNetworks returns a list of configured wifi networks.

func (*WpaCfg) ConnectNetwork

func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error)

ConnectNetwork connects to a wifi network

func (*WpaCfg) ScanNetworks

func (wpa *WpaCfg) ScanNetworks() (map[string]WpaNetwork, error)

ScanNetworks returns a map of WpaNetwork data structures.

func (*WpaCfg) StartAP

func (wpa *WpaCfg) StartAP()

StartAP starts AP mode.

func (*WpaCfg) Status

func (wpa *WpaCfg) Status() (map[string]string, error)

Status returns the WPA wireless status.

type WpaConnection

type WpaConnection struct {
	Ssid    string `json:"ssid"`
	State   string `json:"state"`
	Ip      string `json:"ip"`
	Message string `json:"message"`
}

WpaConnection defines a WPA connection.

type WpaCredentials

type WpaCredentials struct {
	Ssid string `json:"ssid"`
	Psk  string `json:"psk"`
}

WpaCredentials defines wifi network credentials.

type WpaNetwork

type WpaNetwork struct {
	Bssid       string `json:"bssid"`
	Frequency   string `json:"frequency"`
	SignalLevel string `json:"signal_level"`
	Flags       string `json:"flags"`
	Ssid        string `json:"ssid"`
}

WpaNetwork defines a wifi network to connect to.

type WpaSupplicantCfg

type WpaSupplicantCfg struct {
	CfgFile string `json:"cfg_file"` // /etc/wpa_supplicant/wpa_supplicant.conf
}

WpaSupplicantCfg configures wpa_supplicant and is used by SetupCfg

Jump to

Keyboard shortcuts

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