fix: fixed a bug which made the wifi channel hopper react slowly to wifi.recon.channel N commands

This commit is contained in:
evilsocket 2019-02-08 12:45:04 +01:00
commit a3d6b353fe
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
2 changed files with 14 additions and 3 deletions

View file

@ -28,6 +28,7 @@ type WiFiModule struct {
source string
channel int
hopPeriod time.Duration
hopChanges chan bool
frequencies []int
ap *network.AccessPoint
stickChan int
@ -55,6 +56,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
channel: 0,
stickChan: 0,
hopPeriod: 250 * time.Millisecond,
hopChanges: make(chan bool),
ap: nil,
skipBroken: true,
apRunning: false,
@ -101,6 +103,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
w.ap = nil
w.stickChan = 0
w.frequencies, err = network.GetSupportedFrequencies(w.Session.Interface.Name())
w.hopChanges <- true
return err
}))
@ -232,6 +235,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
}
w.frequencies = freqs
w.hopChanges <- true
return nil
}))

View file

@ -41,6 +41,8 @@ func (w *WiFiModule) channelHopper() {
}
frequencies := w.frequencies
loopCurrentChannels:
for _, frequency := range frequencies {
channel := network.Dot11Freq2Chan(frequency)
// stick to the access point channel as long as it's selected
@ -57,9 +59,14 @@ func (w *WiFiModule) channelHopper() {
}
w.chanLock.Unlock()
time.Sleep(delay)
if !w.Running() {
return
select {
case _ = <-w.hopChanges:
log.Debug("hop changed")
break loopCurrentChannels
case <-time.After(delay):
if !w.Running() {
return
}
}
}
}