Skip to content

Commit

Permalink
Adding team wifi, fixing large FW upload, fixing DHCP scope removal
Browse files Browse the repository at this point in the history
  • Loading branch information
kiet committed Jan 1, 2024
1 parent 7563507 commit c0091b6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
9 changes: 9 additions & 0 deletions radio/configuration_request_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type ConfigurationRequest struct {

// Team-specific WPA key. Must be at least eight characters long.
WpaKey string `json:"wpaKey"`

// Team-specific WPA 2.4 key. Must be at least eight characters long.
WpaTeamKey string `json:"wpaTeamKey"`
}

// Validate checks that all parameters within the configuration request have valid values.
Expand All @@ -46,5 +49,11 @@ func (request ConfigurationRequest) Validate(radio *Radio) error {
)
}

if len(request.WpaTeamKey) < minWpaKeyLength || len(request.WpaTeamKey) > maxWpaKeyLength {
return fmt.Errorf(
"invalid WPA Team key length: %d (expecting %d-%d)", len(request.WpaTeamKey), minWpaKeyLength, maxWpaKeyLength,
)
}

return nil
}
2 changes: 1 addition & 1 deletion radio/radio_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (radio *Radio) determineAndSetVersion() {
var version string
var err error
if strings.Contains(model, "VH") {
version, err = shell.runCommand("cat", "/etc/config/vh_firmware")
version, err = shell.runCommand("cat", "/etc/vh_firmware")
} else {
version, err = shell.runCommand("sh", "-c", "source /etc/openwrt_release && echo $DISTRIB_DESCRIPTION")
}
Expand Down
28 changes: 22 additions & 6 deletions radio/radio_robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ import (
)

const (
// Name of the radio's Wi-Fi device.
radioDevice = "wifi0"
// Name of the 2.4GHz radio's Wi-Fi device.
radioTeamDevice = "wifi0"

// Name of the radio's Wi-Fi interface.
radioInterface = "ath0"
// Name of the 2.4GHz radio's Wi-Fi interface.
radioTeamInterface = "ath0"

// Index of the radio's Wi-Fi interface section in the UCI configuration.
radioInterfaceIndex = 0
// Index of the 2.4GHz radio's Wi-Fi interface section in the UCI configuration.
radioTeamInterfaceIndex = 0

// Name of the 6GHz radio's Wi-Fi device.
radioDevice = "wifi1"

// Name of the 6GHz radio's Wi-Fi interface.
radioInterface = "ath1"

// Index of the 6GHz radio's Wi-Fi interface section in the UCI configuration.
radioInterfaceIndex = 1
)

// Radio holds the current state of the access point's configuration and any robot radios connected to it.
Expand Down Expand Up @@ -110,11 +119,16 @@ func (radio *Radio) configure(request ConfigurationRequest) error {
// Handle Wi-Fi.
ssid := strconv.Itoa(request.TeamNumber)
wifiInterface := fmt.Sprintf("@wifi-iface[%d]", radioInterfaceIndex)
wifiTeamInterface := fmt.Sprintf("@wifi-iface[%d]", radioTeamInterfaceIndex)
uciTree.SetType("wireless", wifiInterface, "ssid", uci.TypeOption, ssid)
uciTree.SetType("wireless", wifiTeamInterface, "ssid", uci.TypeOption, fmt.Sprintf("FRC-%d",request.TeamNumber))
uciTree.SetType("wireless", wifiInterface, "key", uci.TypeOption, request.WpaKey)
uciTree.SetType("wireless", wifiTeamInterface, "key", uci.TypeOption, request.WpaTeamKey)
if request.Mode == modeTeamRobotRadio {
radio.Channel = ""
uciTree.SetType("wireless", wifiInterface, "mode", uci.TypeOption, "sta")
uciTree.SetType("wireless", wifiTeamInterface, "mode", uci.TypeOption, "ap")
uciTree.SetType("wireless", radioTeamDevice, "channel", uci.TypeOption, "auto")
uciTree.Del("wireless", radioDevice, "channel")
} else {
uciTree.SetType("wireless", wifiInterface, "mode", uci.TypeOption, "ap")
Expand All @@ -129,6 +143,8 @@ func (radio *Radio) configure(request ConfigurationRequest) error {

// Handle DHCP.
teamPartialIp := fmt.Sprintf("%d.%d", request.TeamNumber/100, request.TeamNumber%100)
uciTree.DelSection("dhcp", "@host[-1]")
uciTree.AddSection("dhcp", "@host[0]","")
uciTree.SetType("dhcp", "lan", "dhcp_option", uci.TypeList, fmt.Sprintf("3,10.%s.4", teamPartialIp))
uciTree.SetType("dhcp", "@host[0]", "name", uci.TypeOption, fmt.Sprintf("roboRIO-%d-FRC", request.TeamNumber))
uciTree.SetType("dhcp", "@host[0]", "ip", uci.TypeOption, fmt.Sprintf("10.%s.2", teamPartialIp))
Expand Down
13 changes: 11 additions & 2 deletions web/firmware_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import (

const (
// Maximum size of the firmware file that can be uploaded.
maxRequestSizeBytes = 10 * 1024 * 1024 // 10 MB
maxRequestSizeBytes = 60 * 1024 * 1024 // 60 MB

// Maximum chunk size for multipart
maxMultipartFormChunk = (2 << 20)

// Path to the optional file containing the private key for decrypting new firmware.
firmwareDecryptionKeyFilePath = "/root/frc-radio-api-firmware-key.txt"
Expand All @@ -43,8 +46,14 @@ func (web *WebServer) firmwareHandler(w http.ResponseWriter, r *http.Request) {
// Prevent a malicious client from uploading a huge file and filling up the disk.
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSizeBytes)

err := r.ParseMultipartForm(maxMultipartFormChunk)
if err != nil {
handleWebErr(w, fmt.Errorf("Multipart file error: %v", err), http.StatusBadRequest)
return
}

file, _, err := r.FormFile("file")
if err != nil {
if err != nil {
handleWebErr(w, fmt.Errorf("missing or invalid firmware file: %v", err), http.StatusBadRequest)
return
}
Expand Down

0 comments on commit c0091b6

Please sign in to comment.