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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
|
/* horst - Highly Optimized Radio Scanning Tool
*
* Copyright (C) 2005-2014 Bruno Randolf (br1@einfach.org)
*
* 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include <signal.h>
#include <sys/time.h>
#include <errno.h>
#include <err.h>
#include <sys/socket.h>
#include "main.h"
#include "util.h"
#include "capture.h"
#include "protocol_parser.h"
#include "network.h"
#include "display.h"
#include "wlan_util.h"
#include "ieee80211_util.h"
#include "control.h"
#include "channel.h"
#include "node.h"
#include "essid.h"
struct list_head nodes;
struct essid_meta_info essids;
struct history hist;
struct statistics stats;
struct channel_info spectrum[MAX_CHANNELS];
struct config conf = {
.node_timeout = NODE_TIMEOUT,
.channel_time = CHANNEL_TIME,
.ifname = INTERFACE_NAME,
.display_interval = DISPLAY_UPDATE_INTERVAL,
.recv_buffer_size = RECV_BUFFER_SIZE,
.port = DEFAULT_PORT,
.control_pipe = DEFAULT_CONTROL_PIPE,
.filter_pkt = PKT_TYPE_ALL,
.filter_mode = WLAN_MODE_ALL,
};
struct timeval the_time;
int mon; /* monitoring socket */
static FILE* DF = NULL;
/* receive packet buffer
*
* due to the way we receive packets the network (TCP connection) we have to
* expect the reception of partial packet as well as the reception of several
* packets at one. thus we implement a buffered receive where partially received
* data stays in the buffer.
*
* we need two buffers: one for packet capture or receiving from the server and
* another one for data the clients sends to the server.
*
* not sure if this is also an issue with local packet capture, but it is not
* implemented there.
*
* size: max 80211 frame (2312) + space for prism2 header (144)
* or radiotap header (usually only 26) + some extra */
static unsigned char buffer[2312 + 200];
static size_t buflen;
/* for packets from client to server */
static unsigned char cli_buffer[500];
static size_t cli_buflen;
/* for select */
static fd_set read_fds;
static fd_set write_fds;
static fd_set excpt_fds;
static struct timeval tv;
void __attribute__ ((format (printf, 1, 2)))
printlog(const char *fmt, ...)
{
char buf[128];
va_list ap;
va_start(ap, fmt);
vsnprintf(&buf[1], 127, fmt, ap);
va_end(ap);
if (conf.quiet || conf.debug || !conf.display_initialized)
printf("%s\n", &buf[1]);
else {
/* fix up string for display log */
buf[0] = '\n';
display_log(buf);
}
}
static void
update_history(struct packet_info* p)
{
if (p->phy_signal == 0)
return;
hist.signal[hist.index] = p->phy_signal;
hist.rate[hist.index] = p->phy_rate;
hist.type[hist.index] = (p->phy_flags & PHY_FLAG_BADFCS) ? 1 : p->wlan_type;
hist.retry[hist.index] = p->wlan_retry;
hist.index++;
if (hist.index == MAX_HISTORY)
hist.index = 0;
}
static void
update_statistics(struct packet_info* p)
{
int type = (p->phy_flags & PHY_FLAG_BADFCS) ? 1 : p->wlan_type;
if (p->phy_rate_idx == 0)
return;
stats.packets++;
stats.bytes += p->wlan_len;
if (p->wlan_retry)
stats.retries++;
if (p->phy_rate_idx > 0 && p->phy_rate_idx < MAX_RATES) {
stats.duration += p->pkt_duration;
stats.packets_per_rate[p->phy_rate_idx]++;
stats.bytes_per_rate[p->phy_rate_idx] += p->wlan_len;
stats.duration_per_rate[p->phy_rate_idx] += p->pkt_duration;
}
if (type >= 0 && type < MAX_FSTYPE) {
stats.packets_per_type[type]++;
stats.bytes_per_type[type] += p->wlan_len;
if (p->phy_rate_idx > 0 && p->phy_rate_idx < MAX_RATES)
stats.duration_per_type[type] += p->pkt_duration;
}
}
static void
update_spectrum(struct packet_info* p, struct node_info* n)
{
struct channel_info* chan;
struct chan_node* cn;
if (p->pkt_chan_idx < 0)
return; /* chan not found */
chan = &spectrum[p->pkt_chan_idx];
chan->signal = p->phy_signal;
chan->packets++;
chan->bytes += p->wlan_len;
chan->durations += p->pkt_duration;
ewma_add(&chan->signal_avg, -chan->signal);
if (!n) {
DEBUG("spec no node\n");
return;
}
/* add node to channel if not already there */
list_for_each(&chan->nodes, cn, chan_list) {
if (cn->node == n) {
DEBUG("SPEC node found %p\n", cn->node);
break;
}
}
if (cn->node != n) {
DEBUG("SPEC node adding %p\n", n);
cn = malloc(sizeof(struct chan_node));
cn->node = n;
cn->chan = chan;
ewma_init(&cn->sig_avg, 1024, 8);
list_add_tail(&chan->nodes, &cn->chan_list);
list_add_tail(&n->on_channels, &cn->node_list);
chan->num_nodes++;
n->num_on_channels++;
}
/* keep signal of this node as seen on this channel */
cn->sig = p->phy_signal;
ewma_add(&cn->sig_avg, -cn->sig);
cn->packets++;
}
void
update_spectrum_durations(void)
{
/* also if channel was not changed, keep stats only for every channel_time.
* display code uses durations_last to get a more stable view */
if (conf.channel_idx >= 0) {
spectrum[conf.channel_idx].durations_last =
spectrum[conf.channel_idx].durations;
spectrum[conf.channel_idx].durations = 0;
ewma_add(&spectrum[conf.channel_idx].durations_avg,
spectrum[conf.channel_idx].durations_last);
}
}
static void
write_to_file(struct packet_info* p)
{
fprintf(DF, "%s, %s, ",
get_packet_type_name(p->wlan_type), ether_sprintf(p->wlan_src));
fprintf(DF, "%s, ", ether_sprintf(p->wlan_dst));
fprintf(DF, "%s, ", ether_sprintf(p->wlan_bssid));
fprintf(DF, "%x, %d, %d, %d, %d, %d, %d, ",
p->pkt_types, p->phy_signal, 0, 0,
p->wlan_len, p->phy_rate, p->phy_freq);
fprintf(DF, "%016llx, ", (unsigned long long)p->wlan_tsf);
fprintf(DF, "%s, %d, %d, %d, %d, %d, ",
p->wlan_essid, p->wlan_mode, p->wlan_channel,
p->wlan_wep, p->wlan_wpa, p->wlan_rsn);
fprintf(DF, "%s, ", ip_sprintf(p->ip_src));
fprintf(DF, "%s, ", ip_sprintf(p->ip_dst));
fprintf(DF, "%d, %d\n", p->olsr_type, p->olsr_neigh);
fflush(DF);
}
/* return 1 if packet is filtered */
static int
filter_packet(struct packet_info* p)
{
int i;
if (conf.filter_off)
return 0;
if (conf.filter_pkt != PKT_TYPE_ALL && (p->pkt_types & ~conf.filter_pkt)) {
stats.filtered_packets++;
return 1;
}
/* cannot trust anything if FCS is bad */
if (p->phy_flags & PHY_FLAG_BADFCS)
return 0;
if (conf.filter_mode != WLAN_MODE_ALL && ((p->wlan_mode & ~conf.filter_mode) || p->wlan_mode == 0)) {
/* this also filters out packets where we cannot associate a mode (ACK, RTS/CTS) */
stats.filtered_packets++;
return 1;
}
if (MAC_NOT_EMPTY(conf.filterbssid) &&
memcmp(p->wlan_bssid, conf.filterbssid, MAC_LEN) != 0) {
stats.filtered_packets++;
return 1;
}
if (conf.do_macfilter) {
for (i = 0; i < MAX_FILTERMAC; i++) {
if (MAC_NOT_EMPTY(p->wlan_src) &&
conf.filtermac_enabled[i] &&
memcmp(p->wlan_src, conf.filtermac[i], MAC_LEN) == 0) {
return 0;
}
}
stats.filtered_packets++;
return 1;
}
return 0;
}
void
handle_packet(struct packet_info* p)
{
struct node_info* n = NULL;
int i = -1;
/* filter on server side only */
if (!conf.serveraddr && filter_packet(p)) {
if (!conf.quiet && !conf.paused && !conf.debug)
update_display_clock();
return;
}
if (cli_fd != -1)
net_send_packet(p);
if (conf.dumpfile != NULL && !conf.paused && DF != NULL)
write_to_file(p);
if (conf.paused)
return;
DEBUG("handle %s\n", get_packet_type_name(p->wlan_type));
/* get channel index for packet */
if (p->phy_freq) {
i = channel_find_index_from_freq(p->phy_freq);
}
/* not found from pkt, best guess from config but it might be
* unknown (-1) too */
if (i < 0)
p->pkt_chan_idx = conf.channel_idx;
else
p->pkt_chan_idx = i;
/* wlan_channel is only known for beacons and probe response,
* otherwise we set it from the physical channel */
if (p->wlan_channel == 0 && p->pkt_chan_idx >= 0)
p->wlan_channel = channel_get_chan_from_idx(p->pkt_chan_idx);
/* if current channel is unknown (this is a mac80211 bug), guess it from
* the packet */
if (conf.channel_idx < 0 && p->pkt_chan_idx >= 0)
conf.channel_idx = p->pkt_chan_idx;
if (!(p->phy_flags & PHY_FLAG_BADFCS)) {
/* we can't trust any fields except phy_* of packets with bad FCS,
* so we can't do all this here */
n = node_update(p);
if (n)
p->wlan_retries = n->wlan_retries_last;
p->pkt_duration = ieee80211_frame_duration(
p->phy_flags & PHY_FLAG_MODE_MASK,
p->wlan_len, p->phy_rate,
p->phy_flags & PHY_FLAG_SHORTPRE,
0 /*shortslot*/, p->wlan_type,
p->wlan_qos_class,
p->wlan_retries);
}
update_history(p);
update_statistics(p);
update_spectrum(p, n);
update_essids(p, n);
if (!conf.quiet && !conf.debug)
update_display(p);
}
static void
local_receive_packet(int fd, unsigned char* buffer, size_t bufsize)
{
int len;
struct packet_info p;
DEBUG("\n===============================================================================\n");
len = recv_packet(fd, buffer, bufsize);
#if DO_DEBUG
if (conf.debug) {
dump_packet(buffer, len);
DEBUG("\n");
}
#endif
memset(&p, 0, sizeof(p));
if (!parse_packet(buffer, len, &p)) {
DEBUG("parsing failed\n");
return;
}
handle_packet(&p);
}
static void
receive_any(void)
{
int ret, mfd;
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
FD_ZERO(&excpt_fds);
if (!conf.quiet && !conf.debug)
FD_SET(0, &read_fds);
FD_SET(mon, &read_fds);
if (srv_fd != -1)
FD_SET(srv_fd, &read_fds);
if (cli_fd != -1)
FD_SET(cli_fd, &read_fds);
if (ctlpipe != -1)
FD_SET(ctlpipe, &read_fds);
tv.tv_sec = 0;
tv.tv_usec = min(conf.channel_time, 1000000);
mfd = max(mon, srv_fd);
mfd = max(mfd, ctlpipe);
mfd = max(mfd, cli_fd) + 1;
ret = select(mfd, &read_fds, &write_fds, &excpt_fds, &tv);
if (ret == -1 && errno == EINTR) /* interrupted */
return;
if (ret == 0) { /* timeout */
if (!conf.quiet && !conf.debug)
update_display_clock();
return;
}
else if (ret < 0) /* error */
err(1, "select()");
/* stdin */
if (FD_ISSET(0, &read_fds) && !conf.quiet && !conf.debug)
handle_user_input();
/* local packet or client */
if (FD_ISSET(mon, &read_fds)) {
if (conf.serveraddr)
net_receive(mon, buffer, &buflen, sizeof(buffer));
else
local_receive_packet(mon, buffer, sizeof(buffer));
}
/* server */
if (srv_fd > -1 && FD_ISSET(srv_fd, &read_fds))
net_handle_server_conn();
/* from client to server */
if (cli_fd > -1 && FD_ISSET(cli_fd, &read_fds))
net_receive(cli_fd, cli_buffer, &cli_buflen, sizeof(cli_buffer));
/* named pipe */
if (ctlpipe > -1 && FD_ISSET(ctlpipe, &read_fds))
control_receive_command();
}
void
free_lists(void)
{
int i;
struct essid_info *e, *f;
struct node_info *ni, *mi;
struct chan_node *cn, *cn2;
/* free node list */
list_for_each_safe(&nodes, ni, mi, list) {
DEBUG("free node %s\n", ether_sprintf(ni->last_pkt.wlan_src));
list_del(&ni->list);
free(ni);
}
/* free essids */
list_for_each_safe(&essids.list, e, f, list) {
DEBUG("free essid '%s'\n", e->essid);
list_del(&e->list);
free(e);
}
/* free channel nodes */
for (i = 0; i < conf.num_channels; i++) {
list_for_each_safe(&spectrum[i].nodes, cn, cn2, chan_list) {
DEBUG("free chan_node %p\n", cn);
list_del(&cn->chan_list);
cn->chan->num_nodes--;
free(cn);
}
}
}
static void
finish_all(void)
{
free_lists();
if (!conf.serveraddr)
close_packet_socket(mon, conf.ifname);
if (DF != NULL) {
fclose(DF);
DF = NULL;
}
if (conf.allow_control)
control_finish();
if (!conf.debug)
net_finish();
if (!conf.quiet && !conf.debug)
finish_display();
}
static void
exit_handler(void)
{
finish_all();
}
static void
sigint_handler(__attribute__((unused)) int sig)
{
exit(0);
}
static void
sigpipe_handler(__attribute__((unused)) int sig)
{
/* ignore signal here - we will handle it after write failed */
}
static void
get_options(int argc, char** argv)
{
int c;
static int n;
while((c = getopt(argc, argv, "hqDsCi:t:c:p:e:f:d:o:b:X::x:m:u:a:")) > 0) {
switch (c) {
case 'p':
conf.port = optarg;
break;
case 'q':
conf.quiet = 1;
break;
case 'D':
#if DO_DEBUG
conf.debug = 1;
#else
printf("Please compile with DEBUG=1 to use the -D option!\n");
exit(1);
#endif
break;
case 'i':
conf.ifname = optarg;
break;
case 'o':
conf.dumpfile = optarg;
break;
case 't':
conf.node_timeout = atoi(optarg);
break;
case 'b':
conf.recv_buffer_size = atoi(optarg);
break;
case 's':
conf.do_change_channel = 1;
break;
case 'd':
conf.display_interval = atoi(optarg) * 1000;
break;
case 'e':
if (n >= MAX_FILTERMAC)
break;
conf.do_macfilter = 1;
convert_string_to_mac(optarg, conf.filtermac[n]);
conf.filtermac_enabled[n] = 1;
n++;
break;
case 'c':
conf.serveraddr = optarg;
break;
case 'C':
conf.allow_client = 1;
break;
case 'u':
conf.channel_max = atoi(optarg);
break;
case 'X':
if (optarg != NULL)
conf.control_pipe = optarg;
conf.allow_control = 1;
break;
case 'x':
control_send_command(optarg);
exit(0);
case 'm':
if (conf.filter_mode == WLAN_MODE_ALL)
conf.filter_mode = 0;
if (strcmp(optarg, "AP") == 0)
conf.filter_mode |= WLAN_MODE_AP;
else if (strcmp(optarg, "STA") == 0)
conf.filter_mode |= WLAN_MODE_STA;
else if (strcmp(optarg, "ADH") == 0 || strcmp(optarg, "IBSS") == 0)
conf.filter_mode |= WLAN_MODE_IBSS;
else if (strcmp(optarg, "PRB") == 0)
conf.filter_mode |= WLAN_MODE_PROBE;
else if (strcmp(optarg, "WDS") == 0)
conf.filter_mode |= WLAN_MODE_4ADDR;
else if (strcmp(optarg, "UNKNOWN") == 0)
conf.filter_mode |= WLAN_MODE_UNKNOWN;
break;
case 'f':
if (conf.filter_pkt == PKT_TYPE_ALL)
conf.filter_pkt = 0;
if (strcmp(optarg, "CTRL") == 0 || strcmp(optarg, "CONTROL") == 0)
conf.filter_pkt |= PKT_TYPE_CTRL | PKT_TYPE_ALL_CTRL;
else if (strcmp(optarg, "MGMT") == 0 || strcmp(optarg, "MANAGEMENT") == 0)
conf.filter_pkt |= PKT_TYPE_MGMT | PKT_TYPE_ALL_MGMT;
else if (strcmp(optarg, "DATA") == 0)
conf.filter_pkt |= PKT_TYPE_DATA | PKT_TYPE_ALL_DATA;
else if (strcmp(optarg, "BADFCS") == 0)
conf.filter_pkt |= PKT_TYPE_BADFCS;
else if (strcmp(optarg, "BEACON") == 0)
conf.filter_pkt |= PKT_TYPE_BEACON;
else if (strcmp(optarg, "PROBE") == 0)
conf.filter_pkt |= PKT_TYPE_PROBE;
else if (strcmp(optarg, "ASSOC") == 0)
conf.filter_pkt |= PKT_TYPE_ASSOC;
else if (strcmp(optarg, "AUTH") == 0)
conf.filter_pkt |= PKT_TYPE_AUTH;
else if (strcmp(optarg, "RTS") == 0)
conf.filter_pkt |= PKT_TYPE_RTSCTS;
else if (strcmp(optarg, "ACK") == 0)
conf.filter_pkt |= PKT_TYPE_ACK;
else if (strcmp(optarg, "NULL") == 0)
conf.filter_pkt |= PKT_TYPE_NULL;
else if (strcmp(optarg, "QDATA") == 0)
conf.filter_pkt |= PKT_TYPE_QDATA;
else if (strcmp(optarg, "ARP") == 0)
conf.filter_pkt |= PKT_TYPE_ARP;
else if (strcmp(optarg, "IP") == 0)
conf.filter_pkt |= PKT_TYPE_IP;
else if (strcmp(optarg, "ICMP") == 0)
conf.filter_pkt |= PKT_TYPE_ICMP;
else if (strcmp(optarg, "UDP") == 0)
conf.filter_pkt |= PKT_TYPE_UDP;
else if (strcmp(optarg, "TCP") == 0)
conf.filter_pkt |= PKT_TYPE_TCP;
else if (strcmp(optarg, "OLSR") == 0)
conf.filter_pkt |= PKT_TYPE_OLSR;
else if (strcmp(optarg, "BATMAN") == 0)
conf.filter_pkt |= PKT_TYPE_BATMAN;
else if (strcmp(optarg, "MESHZ") == 0)
conf.filter_pkt |= PKT_TYPE_MESHZ;
/* if one of the individual subtype frames is selected we enable the general frame type */
if (conf.filter_pkt & PKT_TYPE_ALL_MGMT)
conf.filter_pkt |= PKT_TYPE_MGMT;
if (conf.filter_pkt & PKT_TYPE_ALL_CTRL)
conf.filter_pkt |= PKT_TYPE_CTRL;
if (conf.filter_pkt & PKT_TYPE_ALL_DATA)
conf.filter_pkt |= PKT_TYPE_DATA;
break;
case 'h':
default:
printf("\nUsage: %s [-h] [-q] [-D ] [-i interface] [-t sec] [-d ms] [-b bytes]\n"
"\t\t[-s] [-u] [-C] [-c IP] [-p port] [-o file] [-X[name]] [-x command]\n"
"\t\t[-e MAC] [-f PKT_NAME] [-m MODE]\n\n"
"General Options: Description (default value)\n"
" -h\t\tHelp\n"
" -q\t\tQuiet, no output\n"
#if DO_DEBUG
" -D\t\tShow lots of debug output, no UI\n"
#endif
" -i <intf>\tInterface name (wlan0)\n"
" -t <sec>\tNode timeout in seconds (60)\n"
" -d <ms>\tDisplay update interval in ms (100)\n"
" -b <bytes>\tReceive buffer size in bytes (not set)\n"
"\nFeature Options:\n"
" -s\t\t(Poor mans) Spectrum analyzer mode\n"
" -u\t\tUpper channel limit\n\n"
" -C\t\tAllow client connection, server mode (off)\n"
" -c <IP>\tConnect to server with <IP>, client mode (off)\n"
" -p <port>\tPort number of server (4444)\n\n"
" -o <filename>\tWrite packet info into 'filename'\n\n"
" -X[filename]\tAllow control socket on 'filename' (/tmp/horst)\n"
" -x <command>\tSend control command\n"
"\nFilter Options:\n"
" Filters are generally 'positive' or 'inclusive' which means you define\n"
" what you want to see, and everything else is getting filtered out.\n"
" If a filter is not set it is inactive and nothing is filtered.\n"
" All filter options can be specified multiple times.\n"
" -e <MAC>\tSource MAC addresses (xx:xx:xx:xx:xx:xx), up to 9 times\n"
" -f <PKT_NAME>\tFilter packet types\n"
" -m <MODE>\tOperating mode: AP|STA|ADH|PRB|WDS|UNKNOWN\n"
"\n",
argv[0]);
exit(0);
break;
}
}
}
void
init_spectrum(void)
{
int i;
for (i = 0; i < conf.num_channels && i < MAX_CHANNELS; i++) {
list_head_init(&spectrum[i].nodes);
ewma_init(&spectrum[i].signal_avg, 1024, 8);
ewma_init(&spectrum[i].durations_avg, 1024, 8);
}
}
int
main(int argc, char** argv)
{
list_head_init(&essids.list);
list_head_init(&nodes);
get_options(argc, argv);
signal(SIGINT, sigint_handler);
signal(SIGTERM, sigint_handler);
signal(SIGHUP, sigint_handler);
signal(SIGPIPE, sigpipe_handler);
atexit(exit_handler);
gettimeofday(&stats.stats_time, NULL);
gettimeofday(&the_time, NULL);
conf.channel_idx = -1;
if (conf.allow_control) {
printlog("Allowing control socket");
control_init_pipe();
}
if (conf.serveraddr)
mon = net_open_client_socket(conf.serveraddr, conf.port);
else {
mon = open_packet_socket(conf.ifname, conf.recv_buffer_size);
if (mon <= 0)
err(1, "Couldn't open packet socket");
conf.arphrd = device_get_hwinfo(mon, conf.ifname, conf.my_mac_addr);
if (conf.arphrd != ARPHRD_IEEE80211_PRISM &&
conf.arphrd != ARPHRD_IEEE80211_RADIOTAP) {
printf("You need to put your interface into monitor mode!\n");
printf("(e.g. 'iw %s interface add mon0 type monitor' and 'horst -i mon0')\n", conf.ifname);
exit(1);
}
channel_init();
init_spectrum();
}
if (!conf.quiet && !conf.debug)
init_display();
if (conf.dumpfile != NULL)
dumpfile_open(conf.dumpfile);
if (!conf.serveraddr && conf.port && conf.allow_client)
net_init_server_socket(conf.port);
for ( /* ever */ ;;)
{
receive_any();
gettimeofday(&the_time, NULL);
timeout_nodes();
if (!conf.serveraddr) { /* server */
if (channel_auto_change()) {
net_send_channel_config();
update_spectrum_durations();
if (!conf.quiet && !conf.debug)
update_display(NULL);
}
}
}
/* will never */
return 0;
}
void
main_pause(int pause)
{
conf.paused = pause;
printlog(conf.paused ? "- PAUSED -" : "- RESUME -");
}
void
dumpfile_open(char* name)
{
if (DF != NULL) {
fclose(DF);
DF = NULL;
}
if (name == NULL || strlen(name) == 0) {
printlog("- Not writing outfile");
conf.dumpfile = NULL;
return;
}
conf.dumpfile = name;
DF = fopen(conf.dumpfile, "w");
if (DF == NULL)
err(1, "Couldn't open dump file");
printlog("- Writing to outfile %s", conf.dumpfile);
}
#if 0
void print_rate_duration_table(void)
{
int i;
printf("LEN\t1M l\t1M s\t2M l\t2M s\t5.5M l\t5.5M s\t11M l\t11M s\t");
printf("6M\t9\t12M\t18M\t24M\t36M\t48M\t54M\n");
for (i=10; i<=2304; i+=10) {
printf("%d:\t%d\t%d\t", i,
ieee80211_frame_duration(PHY_FLAG_G, i, 10, 0, 0, IEEE80211_FTYPE_DATA, 0, 0),
ieee80211_frame_duration(PHY_FLAG_G, i, 10, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
printf("%d\t%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 20, 0, 0, IEEE80211_FTYPE_DATA, 0, 0),
ieee80211_frame_duration(PHY_FLAG_G, i, 20, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
printf("%d\t%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 55, 0, 0, IEEE80211_FTYPE_DATA, 0, 0),
ieee80211_frame_duration(PHY_FLAG_G, i, 55, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
printf("%d\t%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 110, 0, 0, IEEE80211_FTYPE_DATA, 0, 0),
ieee80211_frame_duration(PHY_FLAG_G, i, 110, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
printf("%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 60, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
printf("%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 90, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
printf("%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 120, 1, 0, IEEE80211_FTYPE_DATA, 0, 0)),
printf("%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 180, 1, 0, IEEE80211_FTYPE_DATA, 0, 0)),
printf("%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 240, 1, 0, IEEE80211_FTYPE_DATA, 0, 0)),
printf("%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 360, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
printf("%d\t",
ieee80211_frame_duration(PHY_FLAG_G, i, 480, 1, 0, IEEE80211_FTYPE_DATA, 0, 0)),
printf("%d\n",
ieee80211_frame_duration(PHY_FLAG_G, i, 540, 1, 0, IEEE80211_FTYPE_DATA, 0, 0));
}
}
#endif
|