Skip to content

Commit

Permalink
Merge pull request bettercap#882 from syylari/ch177-fix
Browse files Browse the repository at this point in the history
WiFi frequency and channel mapping enchancements
  • Loading branch information
evilsocket authored Jun 3, 2021
2 parents 6c2c0da + 9404620 commit 118a348
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions network/wifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func Dot11Freq2Chan(freq int) int {
return 14
} else if freq >= 5035 && freq <= 5865 {
return ((freq - 5035) / 5) + 7
} else if freq >= 5875 && freq <= 5895 {
return 177
}
return 0
}
Expand All @@ -34,6 +36,8 @@ func Dot11Chan2Freq(channel int) int {
return 2484
} else if channel <= 173 {
return ((channel - 7) * 5) + 5035
} else if channel == 177 {
return 5885
}

return 0
Expand Down
33 changes: 23 additions & 10 deletions network/wifi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,39 @@ import (
"github.com/evilsocket/islazy/data"
)

// Define test data for dot11 frequency <-> channel tests
type dot11pair struct {
frequency int
channel int
}

var dot11TestVector = []dot11pair{
{2472, 13},
{2484, 14},
{5825, 165},
{5885, 177},
}

func buildExampleWiFi() *WiFi {
aliases := &data.UnsortedKV{}
return NewWiFi(buildExampleEndpoint(), aliases, func(ap *AccessPoint) {}, func(ap *AccessPoint) {})
}

func TestDot11Freq2Chan(t *testing.T) {
exampleFreq := 2472
exp := 13
got := Dot11Freq2Chan(exampleFreq)
if got != exp {
t.Fatalf("expected '%v', got '%v'", exp, got)
for _, entry := range dot11TestVector {
gotChannel := Dot11Freq2Chan(entry.frequency)
if gotChannel != entry.channel {
t.Fatalf("expected '%v', got '%v'", entry.channel, gotChannel)
}
}
}

func TestDot11Chan2Freq(t *testing.T) {
exampleChan := 13
exp := 2472
got := Dot11Chan2Freq(exampleChan)
if got != exp {
t.Fatalf("expected '%v', got '%v'", exp, got)
for _, entry := range dot11TestVector {
gotFrequency := Dot11Chan2Freq(entry.channel)
if gotFrequency != entry.frequency {
t.Fatalf("expected '%v', got '%v'", entry.frequency, gotFrequency)
}
}
}

Expand Down

0 comments on commit 118a348

Please sign in to comment.