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

View file

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