From e22679bd9cad167cb800fec87dc3480a0f2db1b8 Mon Sep 17 00:00:00 2001 From: Craig Johnston Date: Mon, 12 Feb 2018 06:41:13 +0000 Subject: [PATCH] updates --- dev/configs/interfaces | 17 +++++++ dev/configs/wpa_supplicant.conf | 3 ++ iotwifi/commands.go | 81 +++++++++++++++++++++++++++++++++ main.go | 1 + 4 files changed, 102 insertions(+) create mode 100644 dev/configs/interfaces create mode 100644 dev/configs/wpa_supplicant.conf create mode 100644 iotwifi/commands.go diff --git a/dev/configs/interfaces b/dev/configs/interfaces new file mode 100644 index 0000000..02caff9 --- /dev/null +++ b/dev/configs/interfaces @@ -0,0 +1,17 @@ +auto lo +auto wlan0 +auto uap0 + +iface lo inet loopback + +allow-hotplug wlan0 + +iface wlan0 inet dhcp + wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf + +iface uap0 inet static + address 192.168.27.1 + netmask 255.255.255.0 + network 192.168.27.0 + broadcast 192.168.27.255 + gateway 192.168.27.1 diff --git a/dev/configs/wpa_supplicant.conf b/dev/configs/wpa_supplicant.conf new file mode 100644 index 0000000..a0b21e8 --- /dev/null +++ b/dev/configs/wpa_supplicant.conf @@ -0,0 +1,3 @@ +country=US +ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev +update_config=1 diff --git a/iotwifi/commands.go b/iotwifi/commands.go new file mode 100644 index 0000000..3678840 --- /dev/null +++ b/iotwifi/commands.go @@ -0,0 +1,81 @@ +package iotwifi + +import ( + "os/exec" +// "time" +// "fmt" + +) +/* +func ConnectWifi(cmdRunner CmdRunner) { + + ssid := "straylight-g" + password := "participate621601}fontanelles" + + wifi.SetDebugMode() + if conn, err := wifi.ConnectManager.Connect(ssid, password, time.Second * 60); err == nil { + fmt.Println("Connected", conn.NetInterface, conn.SSID, conn.IP4.String(), conn.IP6.String()) + } else { + fmt.Println(err) + } +} +*/ +// StartWpaSupplicant +func StartWpaSupplicant(cmdRunner CmdRunner) { + args := []string{ + "-dd", + "-Dnl80211", + "-iwlan0", + "-c/etc/wpa_supplicant.conf", + } + + cmd := exec.Command("wpa_supplicant", args...) + go cmdRunner.ProcessCmd("wpa_supplicant", cmd) +} + +// StartDnsmasq +func StartDnsmasq(cmdRunner CmdRunner) { + // 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=/#/192.168.27.1", + "--dhcp-range=192.168.27.100,192.168.27.150,1h", + "--dhcp-vendorclass=set:device,IoT", + "--dhcp-authoritative", + "--log-facility=-", + } + + cmd := exec.Command("dnsmasq", args...) + go cmdRunner.ProcessCmd("dnsmasq", cmd) +} + + +// StartHostapd +func StartHostapd(cmdRunner CmdRunner) { + + cmdRunner.Log.Info("Starting hostapd."); + + cmd := exec.Command("hostapd", "-d", "/dev/stdin") + hostapdPipe, _ := cmd.StdinPipe() + cmdRunner.ProcessCmd("hostapd", cmd) + + cfg := `interface=uap0 +ssid=iotwifi2 +hw_mode=g +channel=6 +macaddr_acl=0 +auth_algs=1 +ignore_broadcast_ssid=0 +wpa=2 +wpa_passphrase=iotwifipass +wpa_key_mgmt=WPA-PSK +wpa_pairwise=TKIP +rsn_pairwise=CCMP` + + hostapdPipe.Write([]byte(cfg)) + hostapdPipe.Close() + +} diff --git a/main.go b/main.go index d2cf81c..ecf2921 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ func main() { panic(err) } + messages := make(chan iotwifi.CmdMessage, 1) go iotwifi.RunWifi(bunyanLogger, messages)