Skip to content

Commit

Permalink
Update wpacfg.go
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinLoeper authored Sep 11, 2019
1 parent b7bc836 commit 8894fbe
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions iotwifi/wpacfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (wpa *WpaCfg) StartAP() {
SetupCfg: wpa.WpaCfg,
}

// note: we use wlan1 as ap instead
command.RemoveApInterface()
command.AddApInterface()
command.UpApInterface()
Expand Down Expand Up @@ -130,7 +129,8 @@ rsn_pairwise=CCMP`

// ConfiguredNetworks returns a list of configured wifi networks.
func (wpa *WpaCfg) ConfiguredNetworks() string {
netOut, err := exec.Command("wpa_cli", "-i", "wlan0", "scan").Output()
netOut, err := exec.Command("wpa_cli", "-i", "
", "scan").Output()
if err != nil {
wpa.Log.Fatal(err)
}
Expand All @@ -143,7 +143,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) {
connection := WpaConnection{}

// 1. Add a network
addNetOut, err := exec.Command("wpa_cli", "-i", "wlan0", "add_network").Output()
addNetOut, err := exec.Command("wpa_cli", "-i", "wlan1", "add_network").Output()
if err != nil {
wpa.Log.Fatal(err)
return connection, err
Expand All @@ -152,7 +152,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) {
wpa.Log.Info("WPA add network got: %s", net)

// 2. Set the ssid for the new network
addSsidOut, err := exec.Command("wpa_cli", "-i", "wlan0", "set_network", net, "ssid", "\""+creds.Ssid+"\"").Output()
addSsidOut, err := exec.Command("wpa_cli", "-i", "wlan1", "set_network", net, "ssid", "\""+creds.Ssid+"\"").Output()
if err != nil {
wpa.Log.Fatal(err)
return connection, err
Expand All @@ -161,7 +161,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) {
wpa.Log.Info("WPA add ssid got: %s", ssidStatus)

// 3. Set the psk for the new network
addPskOut, err := exec.Command("wpa_cli", "-i", "wlan0", "set_network", net, "psk", "\""+creds.Psk+"\"").Output()
addPskOut, err := exec.Command("wpa_cli", "-i", "wlan1", "set_network", net, "psk", "\""+creds.Psk+"\"").Output()
if err != nil {
wpa.Log.Fatal(err.Error())
return connection, err
Expand All @@ -170,7 +170,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) {
wpa.Log.Info("WPA psk got: %s", pskStatus)

// 4. Enable the new network
enableOut, err := exec.Command("wpa_cli", "-i", "wlan0", "enable_network", net).Output()
enableOut, err := exec.Command("wpa_cli", "-i", "wlan1", "enable_network", net).Output()
if err != nil {
wpa.Log.Fatal(err.Error())
return connection, err
Expand All @@ -185,7 +185,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) {
for i := 0; i < 5; i++ {
wpa.Log.Info("WPA Checking wifi state")

stateOut, err := exec.Command("wpa_cli", "-i", "wlan0", "status").Output()
stateOut, err := exec.Command("wpa_cli", "-i", "wlan1", "status").Output()
if err != nil {
wpa.Log.Fatal("Got error checking state: %s", err.Error())
return connection, err
Expand All @@ -198,7 +198,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) {
// see https://developer.android.com/reference/android/net/wifi/SupplicantState.html
if state == "COMPLETED" {
// save the config
saveOut, err := exec.Command("wpa_cli", "-i", "wlan0", "save_config").Output()
saveOut, err := exec.Command("wpa_cli", "-i", "wlan1", "save_config").Output()
if err != nil {
wpa.Log.Fatal(err.Error())
return connection, err
Expand All @@ -225,7 +225,7 @@ func (wpa *WpaCfg) ConnectNetwork(creds WpaCredentials) (WpaConnection, error) {
func (wpa *WpaCfg) Status() (map[string]string, error) {
cfgMap := make(map[string]string, 0)

stateOut, err := exec.Command("wpa_cli", "-i", "wlan0", "status").Output()
stateOut, err := exec.Command("wpa_cli", "-i", "wlan1", "status").Output()
if err != nil {
wpa.Log.Fatal("Got error checking state: %s", err.Error())
return cfgMap, err
Expand Down Expand Up @@ -256,7 +256,7 @@ func cfgMapper(data []byte) map[string]string {
func (wpa *WpaCfg) ScanNetworks() (map[string]WpaNetwork, error) {
wpaNetworks := make(map[string]WpaNetwork, 0)

scanOut, err := exec.Command("wpa_cli", "-i", "wlan0", "scan").Output()
scanOut, err := exec.Command("wpa_cli", "-i", "wlan1", "scan").Output()
if err != nil {
wpa.Log.Fatal(err)
return wpaNetworks, err
Expand All @@ -267,7 +267,7 @@ func (wpa *WpaCfg) ScanNetworks() (map[string]WpaNetwork, error) {
time.Sleep(1 * time.Second)

if scanOutClean == "OK" {
networkListOut, err := exec.Command("wpa_cli", "-i", "wlan0", "scan_results").Output()
networkListOut, err := exec.Command("wpa_cli", "-i", "wlan1", "scan_results").Output()
if err != nil {
wpa.Log.Fatal(err)
return wpaNetworks, err
Expand Down

0 comments on commit 8894fbe

Please sign in to comment.