… | |
… | |
40 | endwin if $initscr--; |
40 | endwin if $initscr--; |
41 | } |
41 | } |
42 | |
42 | |
43 | init_screen; |
43 | init_screen; |
44 | |
44 | |
|
|
45 | sub signal_quality { |
|
|
46 | open my $stats, "<", "$PROC/Status" |
|
|
47 | or return 0; |
|
|
48 | sysread $stats, $buf, 1024; |
|
|
49 | $buf =~ /Signal Quality: (\d+)/ && $1; |
|
|
50 | } |
|
|
51 | |
45 | my $refresh = Event->idle(nice => -5, parked => 1, min => 0.01, max => 1, repeat => 0, cb => sub { |
52 | my $refresh = Event->idle(nice => -5, parked => 1, min => 0.01, max => 1, repeat => 0, cb => sub { |
46 | @menu = (); |
53 | @menu = (); |
47 | &$curmenu; |
54 | &$curmenu; |
48 | |
55 | |
49 | $menu_idx += @menu if $menu_idx < 0; |
56 | $menu_idx += @menu if $menu_idx < 0; |
… | |
… | |
52 | erase; |
59 | erase; |
53 | |
60 | |
54 | my $data = $GPS ? $GPS->data : {}; |
61 | my $data = $GPS ? $GPS->data : {}; |
55 | |
62 | |
56 | move 0, 0; |
63 | move 0, 0; |
57 | addstr $frame++ . ": " . localtime($data->{time}) . " $data->{lat} $data->{long} $data->{alt}m"; |
64 | addstr $frame++ . ": " . signal_quality . " " . localtime($data->{time}) . " $data->{lat} $data->{long} $data->{alt}m"; |
58 | |
65 | |
59 | for my $idx (0 .. $#menu) { |
66 | for my $idx (0 .. $#menu) { |
60 | move 2 + $idx, 0; |
67 | move 2 + $idx, 0; |
61 | standout if $idx == $menu_idx; |
68 | standout if $idx == $menu_idx; |
62 | addstr $menu[$idx][0]; |
69 | addstr $menu[$idx][0]; |
… | |
… | |
161 | } |
168 | } |
162 | |
169 | |
163 | sub show_map { |
170 | sub show_map { |
164 | my ($map, $w, $h) = @_; |
171 | my ($map, $w, $h) = @_; |
165 | |
172 | |
|
|
173 | my $data = $GPS->data; |
|
|
174 | |
|
|
175 | local $map->{"$data->{lat};$data->{long}"} = 0; |
|
|
176 | |
166 | my @data = (("-" x $w) x $h); |
177 | my @data = (("-" x $w) x $h); |
167 | |
178 | |
168 | my ($x1, $y1, $x2, $y2) = (1e6, 1e6, 1e-6, 1e-6); |
179 | my ($x1, $y1, $x2, $y2) = (1e6, 1e6, 1e-6, 1e-6); |
|
|
180 | my $level = 1; |
169 | |
181 | |
170 | while (my ($k, $v) = each %$map) { |
182 | while (my ($k, $v) = each %$map) { |
171 | my ($y, $x) = split /;/, $k; |
183 | my ($y, $x) = split /;/, $k; |
172 | $x1 = $x if $x1 > $x; |
184 | $x1 = $x if $x1 > $x; |
173 | $x2 = $x if $x2 < $x; |
185 | $x2 = $x if $x2 < $x; |
174 | $y1 = $y if $y1 > $y; |
186 | $y1 = $y if $y1 > $y; |
175 | $y2 = $y if $y2 < $y; |
187 | $y2 = $y if $y2 < $y; |
|
|
188 | $level = $v if $level < $v; |
176 | } |
189 | } |
177 | |
190 | |
178 | $x2 = ($w - 1) / (($x2 - $x1) || 1e-6); |
191 | $x2 = ($w - 1) / (($x2 - $x1) || 1e-6); |
179 | $y2 = ($h - 1) / (($y2 - $y1) || 1e-6); |
192 | $y2 = ($h - 1) / (($y2 - $y1) || 1e-6); |
180 | |
193 | |
… | |
… | |
182 | my ($y, $x) = split /;/, $k; |
195 | my ($y, $x) = split /;/, $k; |
183 | |
196 | |
184 | $y = ($y - $y1) * $y2; |
197 | $y = ($y - $y1) * $y2; |
185 | $x = ($x - $x1) * $x2; |
198 | $x = ($x - $x1) * $x2; |
186 | |
199 | |
187 | substr $data[$y], $x, 1, "*"; |
200 | substr $data[$y], $x, 1, int($map->{$k} * 9 / $level); |
188 | } |
201 | } |
189 | |
202 | |
190 | for (@data) { |
203 | for (@data) { |
191 | addstr $_ . "\n"; |
204 | addstr $_ . "\n"; |
192 | } |
205 | } |
… | |
… | |
194 | |
207 | |
195 | sub display_bss { |
208 | sub display_bss { |
196 | my $bss = shift; |
209 | my $bss = shift; |
197 | |
210 | |
198 | addstr "TS: $bss->{ts}\n"; |
211 | addstr "TS: $bss->{ts}\n"; |
|
|
212 | addstr "WEP/Weak packets received: $bss->{wep}/$bss->{weak}\n"; |
199 | addstr "WEP/ARP/IP packets received: $bss->{wep}/$bss->{arp}/$bss->{ip}\n"; |
213 | addstr "ARP/IP packets received: $bss->{arp}/$bss->{ip}\n"; |
200 | |
214 | |
201 | addstr "\naccess points\n"; |
215 | addstr "\naccess points\n"; |
202 | |
216 | |
203 | while (my ($k, $v) = each %{$bss->{ap}}) { |
217 | while (my ($k, $v) = each %{$bss->{ap}}) { |
204 | addstr " " . e2h($k) . "\n"; |
218 | addstr " " . e2h($k) . "\n"; |
… | |
… | |
214 | } |
228 | } |
215 | addstr "\n"; |
229 | addstr "\n"; |
216 | } |
230 | } |
217 | |
231 | |
218 | if ($bss->{gps}) { |
232 | if ($bss->{gps}) { |
|
|
233 | my ($x, $y); getyx $y, $x; |
219 | addstr "\nmap\n"; |
234 | addstr "\nmap\n"; |
|
|
235 | my $h = (&getmaxy - $y) - 3; |
220 | show_map $bss->{gps}, 40, 20; |
236 | show_map $bss->{gps}, int($h*1.8), $h; |
221 | } |
237 | } |
222 | } |
238 | } |
223 | |
239 | |
224 | sub menu_bss_list { |
240 | sub menu_bss_list { |
225 | my @menu; |
241 | my @menu; |
… | |
… | |
237 | } |
253 | } |
238 | |
254 | |
239 | sub activity { |
255 | sub activity { |
240 | if ($GPS) { |
256 | if ($GPS) { |
241 | my $data = $GPS->data; |
257 | my $data = $GPS->data; |
242 | $db->{$_[0]}{gps}{"$data->{lat};$data->{long}"} = 1; |
258 | $db->{$_[0]}{gps}{"$data->{lat};$data->{long}"} = signal_quality; |
243 | } |
259 | } |
244 | $db->{$_[0]}->{ts} = time; |
260 | $db->{$_[0]}->{ts} = time; |
245 | $refresh->start; |
261 | $refresh->start; |
246 | } |
262 | } |
247 | |
263 | |
… | |
… | |
278 | activity $a3; |
294 | activity $a3; |
279 | } elsif ($fc1 == 0x08) { |
295 | } elsif ($fc1 == 0x08) { |
280 | my $bssid = ($a3, $a2, $a1)[$fc2 & 3]; |
296 | my $bssid = ($a3, $a2, $a1)[$fc2 & 3]; |
281 | |
297 | |
282 | if ($fc2 & 0x40) { |
298 | if ($fc2 & 0x40) { |
|
|
299 | my ($iv1, $iv2, $iv3, $ivopt, $byte) = unpack "C C C C C", $pkt; |
283 | $db->{$bssid}{wep}++; |
300 | $db->{$bssid}{wep}++; |
|
|
301 | if ($iv1 > 2 and $iv1 < 14 and $iv2 == 255) { |
|
|
302 | $db->{$bssid}{weak}++; |
|
|
303 | } |
284 | } else { |
304 | } else { |
285 | my ($llc, $et, $pkt) = unpack "a6 n a*", $pkt; |
305 | my ($llc, $et, $pkt) = unpack "a6 n a*", $pkt; |
286 | if ($llc eq "\xaa\xaa\x03\x00\x00\x00") { # SNAP/UI/ENCAP_ETHER |
306 | if ($llc eq "\xaa\xaa\x03\x00\x00\x00") { # SNAP/UI/ENCAP_ETHER |
287 | if ($et == 0x0800) { |
307 | if ($et == 0x0800) { |
288 | my ($vhl, $tos, $len, $id, $off, $ttl, $prot, $sum, $src, $dst, $pkt) |
308 | my ($vhl, $tos, $len, $id, $off, $ttl, $prot, $sum, $src, $dst, $pkt) |