This repository has been archived by the owner on Jan 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
/
commands.go
81 lines (68 loc) · 1.87 KB
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package iotwifi
import (
"os/exec"
"github.com/bhoriuchi/go-bunyan/bunyan"
)
// Command for device network commands.
type Command struct {
Log bunyan.Logger
Runner CmdRunner
SetupCfg *SetupCfg
}
// RemoveApInterface removes the AP interface.
func (c *Command) RemoveApInterface() {
cmd := exec.Command("iw", "dev", "uap0", "del")
cmd.Start()
cmd.Wait()
}
// ConfigureApInterface configured the AP interface.
func (c *Command) ConfigureApInterface() {
cmd := exec.Command("ifconfig", "uap0", c.SetupCfg.HostApdCfg.Ip)
cmd.Start()
cmd.Wait()
}
// UpApInterface ups the AP Interface.
func (c *Command) UpApInterface() {
cmd := exec.Command("ifconfig", "uap0", "up")
cmd.Start()
cmd.Wait()
}
// AddApInterface adds the AP interface.
func (c *Command) AddApInterface() {
cmd := exec.Command("iw", "phy", "phy0", "interface", "add", "uap0", "type", "__ap")
cmd.Start()
cmd.Wait()
}
// CheckInterface checks the AP interface.
func (c *Command) CheckApInterface() {
cmd := exec.Command("ifconfig", "uap0")
go c.Runner.ProcessCmd("ifconfig_uap0", cmd)
}
// StartWpaSupplicant starts wpa_supplicant.
func (c *Command) StartWpaSupplicant() {
args := []string{
"-d",
"-Dnl80211",
"-iwlan0",
"-c/etc/wpa_supplicant/wpa_supplicant.conf",
}
cmd := exec.Command("wpa_supplicant", args...)
go c.Runner.ProcessCmd("wpa_supplicant", cmd)
}
// StartDnsmasq starts dnsmasq.
func (c *Command) StartDnsmasq() {
// hostapd is enabled, fire up dnsmasq
args := []string{
"--no-hosts", // Don't read the hostnames in /etc/hosts.
"--keep-in-foreground",
"--log-queries",
"--no-resolv",
"--address=" + c.SetupCfg.DnsmasqCfg.Address,
"--dhcp-range=" + c.SetupCfg.DnsmasqCfg.DhcpRange,
"--dhcp-vendorclass=" + c.SetupCfg.DnsmasqCfg.VendorClass,
"--dhcp-authoritative",
"--log-facility=-",
}
cmd := exec.Command("dnsmasq", args...)
go c.Runner.ProcessCmd("dnsmasq", cmd)
}