From 2d03782fe1169789a30dbf0bad642c85a12c964f Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Sat, 17 Aug 2024 13:37:48 +0200 Subject: [PATCH] fix: make sure that wifi channels are unique and sorted --- modules/wifi/wifi.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/wifi/wifi.go b/modules/wifi/wifi.go index 4b50bb86..c25d5866 100644 --- a/modules/wifi/wifi.go +++ b/modules/wifi/wifi.go @@ -5,6 +5,8 @@ import ( "fmt" "net" "regexp" + "slices" + "sort" "strconv" "sync" "time" @@ -485,8 +487,13 @@ func (mod *WiFiModule) setFrequencies(freqs []int) { mod.frequencies = freqs channels := []int{} for _, freq := range freqs { - channels = append(channels, network.Dot11Freq2Chan(freq)) + channel := network.Dot11Freq2Chan(freq) + if !slices.Contains(channels, channel) { + channels = append(channels, channel) + } } + sort.Ints(channels) + mod.State.Store("channels", channels) mod.Info("channels: %v", channels)