forked from br101/horst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.c
148 lines (116 loc) · 2.96 KB
/
channel.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* horst - Highly Optimized Radio Scanning Tool
*
* Copyright (C) 2005-2011 Bruno Randolf ([email protected])
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <stdlib.h>
#include "main.h"
#include "util.h"
#include "ieee80211_util.h"
#include "wext.h"
#if defined(__APPLE__)
int
change_channel(int idx)
{
return 0;
}
int
auto_change_channel(int mon)
{
return 0;
}
int
find_channel_index(int c)
{
return -1;
}
void
get_current_channel(int mon)
{
}
#else
static struct timeval last_channelchange;
extern int mon; /* monitoring socket */
int
change_channel(int idx)
{
if (wext_set_freq(mon, conf.ifname, channels[idx].freq) == 0) {
printlog("ERROR: could not set channel %d", channels[idx].chan);
return 0;
}
conf.current_channel = idx;
return 1;
}
int
auto_change_channel(int mon)
{
int new_chan;
int ret = 1;
int start_chan;
if (the_time.tv_sec == last_channelchange.tv_sec &&
(the_time.tv_usec - last_channelchange.tv_usec) < conf.channel_time)
return 0; /* too early */
if (conf.do_change_channel) {
start_chan = new_chan = conf.current_channel;
do {
new_chan = new_chan + 1;
if (new_chan >= conf.num_channels ||
new_chan >= MAX_CHANNELS ||
(conf.channel_max && new_chan >= conf.channel_max))
new_chan = 0;
ret = change_channel(new_chan);
/* try setting different channels in case we get errors only
* on some channels (e.g. ipw2200 reports channel 14 but cannot
* be set to use it). stop if we tried all channels */
} while (ret != 1 && new_chan != start_chan);
}
last_channelchange = the_time;
return ret;
}
int
find_channel_index(int c)
{
int i = -1;
for (i = 0; i < conf.num_channels && i < MAX_CHANNELS; i++)
if (channels[i].chan == c)
return i;
return -1;
}
void
get_current_channel(int mon)
{
int freq, ch;
/* get current channel & map to our channel array */
freq = wext_get_freq(mon, conf.ifname);
if (freq == 0)
return;
ch = ieee80211_frequency_to_channel(freq);
ch = find_channel_index(ch);
if (ch >= 0)
conf.current_channel = ch;
DEBUG("***%d\n", conf.current_channel);
}
#endif
void
init_channels(void)
{
int i;
for (i = 0; i < conf.num_channels && i < MAX_CHANNELS; i++) {
INIT_LIST_HEAD(&spectrum[i].nodes);
ewma_init(&spectrum[i].signal_avg, 1024, 8);
ewma_init(&spectrum[i].durations_avg, 1024, 8);
}
}