diff --git a/access_point_config.tar.gz b/access_point_config.tar.gz index 7679723..8e1531d 100644 Binary files a/access_point_config.tar.gz and b/access_point_config.tar.gz differ diff --git a/field/access_point.go b/field/access_point.go index 537bcd9..7d634be 100644 --- a/field/access_point.go +++ b/field/access_point.go @@ -6,15 +6,13 @@ package field import ( - "bytes" "fmt" "github.com/Team254/cheesy-arena/model" "golang.org/x/crypto/ssh" "log" "os" - "path/filepath" + "strings" "sync" - "text/template" "time" ) @@ -23,15 +21,6 @@ const accessPointConnectTimeoutSec = 1 const accessPointCommandTimeoutSec = 3 const accessPointRetryCount = 2 -const ( - red1Vlan = 10 - red2Vlan = 20 - red3Vlan = 30 - blue1Vlan = 40 - blue2Vlan = 50 - blue3Vlan = 60 -) - type AccessPoint struct { address string port int @@ -58,16 +47,22 @@ func (ap *AccessPoint) ConfigureTeamWifi(red1, red2, red3, blue1, blue2, blue3 * if err != nil { return err } - command := fmt.Sprintf("cat < /etc/config/wireless && wifi radio0\n%sENDCONFIG\n", config) + command := fmt.Sprintf("uci batch < /etc/config/wireless && wifi radio1\n%sENDCONFIG\n", config) + command := fmt.Sprintf("uci batch < 63 { return fmt.Errorf("Invalid WPA key '%s' configured for team %d.", team.WpaKey, team.Id) } - networks[vlan] = team + + *commands = append(*commands, fmt.Sprintf("set wireless.@wifi-iface[%d].ssid='%d'", position, team.Id), + fmt.Sprintf("set wireless.@wifi-iface[%d].key='%s'", position, team.WpaKey)) + return nil } diff --git a/field/access_point_test.go b/field/access_point_test.go index 5436482..5b203e4 100644 --- a/field/access_point_test.go +++ b/field/access_point_test.go @@ -7,80 +7,57 @@ import ( "github.com/Team254/cheesy-arena/model" "github.com/stretchr/testify/assert" "regexp" - "strconv" "testing" ) func TestConfigureAccessPoint(t *testing.T) { model.BaseDir = ".." - radioRe := regexp.MustCompile("option device 'radio0'") - ssidRe := regexp.MustCompile("option ssid '([-\\w ]+)'") - wpaKeyRe := regexp.MustCompile("option key '([-\\w ]+)'") - vlanRe := regexp.MustCompile("option network 'vlan(\\d+)'") - channelRe := regexp.MustCompile("option channel '(\\d+)'") + ssidRe := regexp.MustCompile("ssid='([-\\w ]+)'") + wpaKeyRe := regexp.MustCompile("key='([-\\w ]+)'") ap := AccessPoint{teamChannel: 1234, adminChannel: 4321, adminWpaKey: "blorpy"} // Should not configure any team SSIDs if there are no teams. config, _ := ap.generateAccessPointConfig(nil, nil, nil, nil, nil, nil) - assert.NotContains(t, config, "option device 'radio0'") + assert.NotContains(t, config, "set") ssids := ssidRe.FindAllStringSubmatch(config, -1) wpaKeys := wpaKeyRe.FindAllStringSubmatch(config, -1) - vlans := vlanRe.FindAllStringSubmatch(config, -1) - channels := channelRe.FindAllStringSubmatch(config, -1) - assert.Equal(t, "Cheesy Arena", ssids[0][1]) - assert.Equal(t, ap.adminWpaKey, wpaKeys[0][1]) - assert.Equal(t, "100", vlans[0][1]) - assert.Equal(t, strconv.Itoa(ap.adminChannel), channels[0][1]) - assert.Equal(t, strconv.Itoa(ap.teamChannel), channels[1][1]) + assert.Equal(t, 0, len(ssids)) + assert.Equal(t, 0, len(wpaKeys)) // Should configure two SSID for two teams. config, _ = ap.generateAccessPointConfig(&model.Team{Id: 254, WpaKey: "aaaaaaaa"}, nil, nil, nil, nil, &model.Team{Id: 1114, WpaKey: "bbbbbbbb"}) - assert.Equal(t, 2, len(radioRe.FindAllString(config, -1))) ssids = ssidRe.FindAllStringSubmatch(config, -1) wpaKeys = wpaKeyRe.FindAllStringSubmatch(config, -1) - vlans = vlanRe.FindAllStringSubmatch(config, -1) - assert.Equal(t, "Cheesy Arena", ssids[0][1]) - assert.Equal(t, ap.adminWpaKey, wpaKeys[0][1]) - assert.Equal(t, "100", vlans[0][1]) - assert.Equal(t, "254", ssids[1][1]) - assert.Equal(t, "aaaaaaaa", wpaKeys[1][1]) - assert.Equal(t, "10", vlans[1][1]) - assert.Equal(t, "1114", ssids[2][1]) - assert.Equal(t, "bbbbbbbb", wpaKeys[2][1]) - assert.Equal(t, "60", vlans[2][1]) + if assert.Equal(t, 2, len(ssids)) && assert.Equal(t, 2, len(wpaKeys)) { + assert.Equal(t, "254", ssids[0][1]) + assert.Equal(t, "aaaaaaaa", wpaKeys[0][1]) + assert.Equal(t, "1114", ssids[1][1]) + assert.Equal(t, "bbbbbbbb", wpaKeys[1][1]) + } // Should configure all SSIDs for six teams. config, _ = ap.generateAccessPointConfig(&model.Team{Id: 1, WpaKey: "11111111"}, &model.Team{Id: 2, WpaKey: "22222222"}, &model.Team{Id: 3, WpaKey: "33333333"}, &model.Team{Id: 4, WpaKey: "44444444"}, &model.Team{Id: 5, WpaKey: "55555555"}, &model.Team{Id: 6, WpaKey: "66666666"}) - assert.Equal(t, 6, len(radioRe.FindAllString(config, -1))) ssids = ssidRe.FindAllStringSubmatch(config, -1) wpaKeys = wpaKeyRe.FindAllStringSubmatch(config, -1) - vlans = vlanRe.FindAllStringSubmatch(config, -1) - assert.Equal(t, "Cheesy Arena", ssids[0][1]) - assert.Equal(t, ap.adminWpaKey, wpaKeys[0][1]) - assert.Equal(t, "100", vlans[0][1]) - assert.Equal(t, "1", ssids[1][1]) - assert.Equal(t, "11111111", wpaKeys[1][1]) - assert.Equal(t, "10", vlans[1][1]) - assert.Equal(t, "2", ssids[2][1]) - assert.Equal(t, "22222222", wpaKeys[2][1]) - assert.Equal(t, "20", vlans[2][1]) - assert.Equal(t, "3", ssids[3][1]) - assert.Equal(t, "33333333", wpaKeys[3][1]) - assert.Equal(t, "30", vlans[3][1]) - assert.Equal(t, "4", ssids[4][1]) - assert.Equal(t, "44444444", wpaKeys[4][1]) - assert.Equal(t, "40", vlans[4][1]) - assert.Equal(t, "5", ssids[5][1]) - assert.Equal(t, "55555555", wpaKeys[5][1]) - assert.Equal(t, "50", vlans[5][1]) - assert.Equal(t, "6", ssids[6][1]) - assert.Equal(t, "66666666", wpaKeys[6][1]) - assert.Equal(t, "60", vlans[6][1]) + if assert.Equal(t, 6, len(ssids)) && assert.Equal(t, 6, len(wpaKeys)) { + assert.Equal(t, "1", ssids[0][1]) + assert.Equal(t, "11111111", wpaKeys[0][1]) + assert.Equal(t, "2", ssids[1][1]) + assert.Equal(t, "22222222", wpaKeys[1][1]) + assert.Equal(t, "3", ssids[2][1]) + assert.Equal(t, "33333333", wpaKeys[2][1]) + assert.Equal(t, "4", ssids[3][1]) + assert.Equal(t, "44444444", wpaKeys[3][1]) + assert.Equal(t, "5", ssids[4][1]) + assert.Equal(t, "55555555", wpaKeys[4][1]) + assert.Equal(t, "6", ssids[5][1]) + assert.Equal(t, "66666666", wpaKeys[5][1]) + } // Should reject a missing WPA key. _, err := ap.generateAccessPointConfig(&model.Team{Id: 254}, nil, nil, nil, nil, nil) diff --git a/field/network_switch.go b/field/network_switch.go index f9c9160..2c43cbc 100644 --- a/field/network_switch.go +++ b/field/network_switch.go @@ -18,6 +18,15 @@ import ( const switchTelnetPort = 23 +const ( + red1Vlan = 10 + red2Vlan = 20 + red3Vlan = 30 + blue1Vlan = 40 + blue2Vlan = 50 + blue3Vlan = 60 +) + type NetworkSwitch struct { address string port int diff --git a/templates/access_point.cfg b/templates/access_point.cfg deleted file mode 100644 index 736dfc4..0000000 --- a/templates/access_point.cfg +++ /dev/null @@ -1,46 +0,0 @@ -config wifi-device 'radio1' - option type 'mac80211' - option channel '{{.AdminChannel}}' - option hwmode '11g' - option path 'soc/soc:pcie-controller/pci0000:00/0000:00:02.0/0000:02:00.0' - option htmode 'HT20' - option disabled '0' - option txpower '20' - option country 'US' - -config wifi-iface - option device 'radio1' - option mode 'ap' - option hidden '1' - option encryption 'psk2+ccmp' - option network 'vlan100' - option ssid 'Cheesy Arena' - option key '{{.AdminWpaKey}}' - option macaddr '62:38:e0:12:6b:17' - -config wifi-device 'radio0' - option type 'mac80211' - option hwmode '11a' - option path 'soc/soc:pcie-controller/pci0000:00/0000:00:01.0/0000:01:00.0' - option txpower '23' - option channel '{{.TeamChannel}}' - option country 'US' - option htmode 'HT20' - option basic_rates '6500,7200' - option short_gi_20 '0' - -{{range $vlan, $team := .Networks}} -config wifi-iface - option device 'radio0' - option mode 'ap' - option isolate '0' - option bgscan '0' - option wds '0' - option maxassoc '1' - option hidden '1' - option network 'vlan{{$vlan}}' - option encryption 'psk2+ccmp' - option ssid '{{$team.Id}}' - option key '{{$team.WpaKey}}' - option disabled '0' -{{end}}