Skip to content

Commit

Permalink
Change channel bandwidth valid values to '20MHz' and '40MHz' instead …
Browse files Browse the repository at this point in the history
…of 'HT20' and 'HT40'.
  • Loading branch information
patfair committed Jun 4, 2024
1 parent df61067 commit 2dc8238
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
6 changes: 3 additions & 3 deletions radio/configuration_request_ap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type ConfigurationRequest struct {
// 5GHz or 6GHz channel number for the radio to use. Set to 0 to leave unchanged.
Channel int `json:"channel"`

// Channel bandwidth mode for the radio to use. Valid values are "HT20" and "HT40". Set to an empty string to leave
// unchanged.
// Channel bandwidth mode for the radio to use. Valid values are "20MHz" and "40MHz". Set to an empty string to
// leave unchanged.
ChannelBandwidth string `json:"channelBandwidth"`

// SSID and WPA key for each team station, keyed by alliance and number (e.g. "red1", "blue3). If a station is not
Expand Down Expand Up @@ -63,7 +63,7 @@ func (request ConfigurationRequest) Validate(radio *Radio) error {
if radio.Type == TypeLinksys {
return fmt.Errorf("channel bandwidth cannot be changed on %s", radio.Type.String())
}
if request.ChannelBandwidth != "HT20" && request.ChannelBandwidth != "HT40" {
if request.ChannelBandwidth != "20MHz" && request.ChannelBandwidth != "40MHz" {
return fmt.Errorf("invalid channel bandwidth: %s", request.ChannelBandwidth)
}
}
Expand Down
6 changes: 3 additions & 3 deletions radio/configuration_request_ap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func TestConfigurationRequest_Validate(t *testing.T) {
assert.EqualError(t, err, "invalid channel for TypeVividHosting: 36")

// Invalid channel bandwidth.
request = ConfigurationRequest{ChannelBandwidth: "HT30"}
request = ConfigurationRequest{ChannelBandwidth: "30MHz"}
err = request.Validate(vividHostingRadio)
assert.EqualError(t, err, "invalid channel bandwidth: HT30")
assert.EqualError(t, err, "invalid channel bandwidth: 30MHz")

// Channel bandwidth not supported on Linksys.
request = ConfigurationRequest{ChannelBandwidth: "HT20"}
request = ConfigurationRequest{ChannelBandwidth: "20MHz"}
err = request.Validate(linksysRadio)
assert.EqualError(t, err, "channel bandwidth cannot be changed on TypeLinksys")

Expand Down
23 changes: 20 additions & 3 deletions radio/radio_ap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Radio struct {
// 5GHz or 6GHz channel number the radio is broadcasting on.
Channel int `json:"channel"`

// Channel bandwidth mode for the radio to use. Valid values are "HT20" and "HT40".
// Channel bandwidth mode for the radio to use. Valid values are "20MHz" and "40MHz".
ChannelBandwidth string `json:"channelBandwidth"`

// Enum representing the current configuration stage of the radio.
Expand Down Expand Up @@ -112,7 +112,15 @@ func (radio *Radio) isStarted() bool {
func (radio *Radio) setInitialState() {
channel, _ := uciTree.GetLast("wireless", radio.device, "channel")
radio.Channel, _ = strconv.Atoi(channel)
radio.ChannelBandwidth, _ = uciTree.GetLast("wireless", radio.device, "htmode")
htmode, _ := uciTree.GetLast("wireless", radio.device, "htmode")
switch htmode {
case "HT20":
radio.ChannelBandwidth = "20MHz"
case "HT40":
radio.ChannelBandwidth = "40MHz"
default:
radio.ChannelBandwidth = "INVALID"
}
_ = radio.updateStationStatuses()
}

Expand All @@ -123,7 +131,16 @@ func (radio *Radio) configure(request ConfigurationRequest) error {
radio.Channel = request.Channel
}
if request.ChannelBandwidth != "" {
uciTree.SetType("wireless", radio.device, "htmode", uci.TypeOption, request.ChannelBandwidth)
var htmode string
switch request.ChannelBandwidth {
case "20MHz":
htmode = "HT20"
case "40MHz":
htmode = "HT40"
default:
return fmt.Errorf("invalid channel bandwidth: %s", request.ChannelBandwidth)
}
uciTree.SetType("wireless", radio.device, "htmode", uci.TypeOption, htmode)
radio.ChannelBandwidth = request.ChannelBandwidth
}

Expand Down
2 changes: 2 additions & 0 deletions radio/radio_ap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func TestRadio_setInitialState(t *testing.T) {
radio := NewRadio()

fakeTree.valuesForGet["wireless.wifi1.channel"] = "23"
fakeTree.valuesForGet["wireless.wifi1.htmode"] = "HT20"
fakeShell.commandOutput["iwinfo ath1 info"] = "ath1\nESSID: \"1111\"\n"
fakeShell.commandOutput["iwinfo ath11 info"] = "ath11\nESSID: \"no-team-2\"\n"
fakeShell.commandOutput["iwinfo ath12 info"] = "ath12\nESSID: \"no-team-3\"\n"
Expand All @@ -109,6 +110,7 @@ func TestRadio_setInitialState(t *testing.T) {
fakeShell.commandOutput["iwinfo ath15 info"] = "ath15\nESSID: \"6666\"\n"
radio.setInitialState()
assert.Equal(t, 23, radio.Channel)
assert.Equal(t, "20MHz", radio.ChannelBandwidth)
assert.Equal(t, "1111", radio.StationStatuses["red1"].Ssid)
assert.Nil(t, radio.StationStatuses["red2"])
assert.Nil(t, radio.StationStatuses["red3"])
Expand Down
4 changes: 2 additions & 2 deletions web/configuration_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestWeb_configurationHandler(t *testing.T) {
`
{
"channel": 149,
"channelBandwidth": "HT20",
"channelBandwidth": "20MHz",
"stationConfigurations": {
"red1": {"ssid": "9991", "wpaKey": "11111111"},
"red2": {"ssid": "9992", "wpaKey": "22222222"},
Expand All @@ -58,7 +58,7 @@ func TestWeb_configurationHandler(t *testing.T) {
if assert.Equal(t, 1, len(ap.ConfigurationRequestChannel)) {
request := <-ap.ConfigurationRequestChannel
assert.Equal(t, 149, request.Channel)
assert.Equal(t, "HT20", request.ChannelBandwidth)
assert.Equal(t, "20MHz", request.ChannelBandwidth)
assert.Equal(t, 6, len(request.StationConfigurations))
assert.Equal(
t, radio.StationConfiguration{Ssid: "9991", WpaKey: "11111111"}, request.StationConfigurations["red1"],
Expand Down

0 comments on commit 2dc8238

Please sign in to comment.