// Copyright 2017 Team 254. All Rights Reserved. // Author: pat@patfairbank.com (Patrick Fairbank) // // Methods for configuring a Linksys WRT1900ACS access point running OpenWRT for team SSIDs and VLANs. package field import ( "fmt" "github.com/Team254/cheesy-arena/model" "golang.org/x/crypto/ssh" "os" "strings" "sync" "time" ) const accessPointSshPort = 22 const accessPointConnectTimeoutSec = 1 const accessPointCommandTimeoutSec = 3 type AccessPoint struct { address string port int username string password string teamChannel int adminChannel int adminWpaKey string mutex sync.Mutex } func NewAccessPoint(address, username, password string, teamChannel, adminChannel int, adminWpaKey string) *AccessPoint { return &AccessPoint{address: address, port: accessPointSshPort, username: username, password: password, teamChannel: teamChannel, adminChannel: adminChannel, adminWpaKey: adminWpaKey} } // Sets up wireless networks for the given set of teams. func (ap *AccessPoint) ConfigureTeamWifi(red1, red2, red3, blue1, blue2, blue3 *model.Team) error { // Make sure multiple configurations aren't being set at the same time. ap.mutex.Lock() defer ap.mutex.Unlock() config, err := ap.generateAccessPointConfig(red1, red2, red3, blue1, blue2, blue3) if err != nil { return err } command := fmt.Sprintf("uci batch < 63 { return fmt.Errorf("Invalid WPA key '%s' configured for team %d.", team.WpaKey, team.Id) } *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 }