/* * wavemon - a wireless network monitoring aplication * * Copyright (c) 2001-2002 Jan Morgenstern * * wavemon 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, or (at your option) any later * version. * * wavemon 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 wavemon; see the file COPYING. If not, write to the Free Software * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "iw_if.h" /* GLOBALS */ static WINDOW *w_levels, *w_stats, *w_if, *w_info, *w_net; static struct timer dyn_updates; static struct iw_stat cur; void sampling_init(void (*sampling_handler)(int)) { struct itimerval i; div_t d = div(conf.stat_iv, 1000); /* conf.stat_iv in msec */ xsignal(SIGALRM, SIG_IGN); iw_getinf_range(conf_ifname(), &cur.range); i.it_interval.tv_sec = i.it_value.tv_sec = d.quot; i.it_interval.tv_usec = i.it_value.tv_usec = d.rem * 1000; xsignal(SIGALRM, sampling_handler); (*sampling_handler)(0); setitimer(ITIMER_REAL, &i, NULL); } void sampling_do_poll(void) { iw_getstat(&cur); iw_cache_update(&cur); } static void display_levels(void) { char nscale[2] = { cur.dbm.signal - 20, cur.dbm.signal }, lvlscale[2] = { -40, -20}, snrscale[2] = { 6, 12 }; char tmp[0x100]; static float qual, signal, noise, ssnr; int line; for (line = 1; line <= WH_LEVEL; line++) mvwclrtoborder(w_levels, line, 1); if ((cur.stat.qual.updated & IW_QUAL_ALL_INVALID) == IW_QUAL_ALL_INVALID) { wattron(w_levels, A_BOLD); waddstr_center(w_levels, (WH_LEVEL + 1)/2, "NO INTERFACE DATA"); goto done_levels; } line = 1; /* Noise data is rare. Use the space for spreading out. */ if (cur.stat.qual.updated & IW_QUAL_NOISE_INVALID) line++; if (cur.stat.qual.updated & IW_QUAL_QUAL_INVALID) { line++; } else { qual = ewma(qual, cur.stat.qual.qual, conf.meter_decay / 100.0); mvwaddstr(w_levels, line++, 1, "link quality: "); sprintf(tmp, "%0.f/%d ", qual, cur.range.max_qual.qual); waddstr_b(w_levels, tmp); waddbar(w_levels, line++, qual, 0, cur.range.max_qual.qual, lvlscale, true); } if (cur.stat.qual.updated & IW_QUAL_NOISE_INVALID) line++; if (cur.stat.qual.updated & IW_QUAL_LEVEL_INVALID) { line++; } else { signal = ewma(signal, cur.dbm.signal, conf.meter_decay / 100.0); mvwaddstr(w_levels, line++, 1, "signal level: "); sprintf(tmp, "%.0f dBm (%s) ", signal, dbm2units(signal)); waddstr_b(w_levels, tmp); waddbar(w_levels, line, signal, conf.sig_min, conf.sig_max, lvlscale, true); if (conf.lthreshold_action) waddthreshold(w_levels, line, signal, conf.lthreshold, conf.sig_min, conf.sig_max, lvlscale, '>'); if (conf.hthreshold_action) waddthreshold(w_levels, line, signal, conf.hthreshold, conf.sig_min, conf.sig_max, lvlscale, '<'); line++; } if (! (cur.stat.qual.updated & IW_QUAL_NOISE_INVALID)) { noise = ewma(noise, cur.dbm.noise, conf.meter_decay / 100.0); mvwaddstr(w_levels, line++, 1, "noise level: "); sprintf(tmp, "%.0f dBm (%s) ", noise, dbm2units(noise)); waddstr_b(w_levels, tmp); waddbar(w_levels, line++, noise, conf.noise_min, conf.noise_max, nscale, false); /* * Since we make sure (in iw_if.c) that invalid signal levels always * imply invalid noise levels, we can display a valid SNR here. */ ssnr = ewma(ssnr, cur.dbm.signal - cur.dbm.noise, conf.meter_decay / 100.0); mvwaddstr(w_levels, line++, 1, "signal-to-noise ratio: "); if (ssnr > 0) waddstr_b(w_levels, "+"); sprintf(tmp, "%.0f dB ", ssnr); waddstr_b(w_levels, tmp); waddbar(w_levels, line, ssnr, 0, 110, snrscale, true); } done_levels: wrefresh(w_levels); } static void display_stats(void) { struct if_stat nstat; char tmp[0x100]; if_getstat(conf_ifname(), &nstat); /* * Interface RX stats */ mvwaddstr(w_stats, 1, 1, "RX: "); sprintf(tmp, "%'llu (%s)", nstat.rx_packets, byte_units(nstat.rx_bytes)); waddstr_b(w_stats, tmp); waddstr(w_stats, ", invalid: "); sprintf(tmp, "%'u", cur.stat.discard.nwid); waddstr_b(w_stats, tmp); waddstr(w_stats, " nwid, "); sprintf(tmp, "%'u", cur.stat.discard.code); waddstr_b(w_stats, tmp); waddstr(w_stats, " crypt, "); sprintf(tmp, "%'u", cur.stat.discard.fragment); waddstr_b(w_stats, tmp); waddstr(w_stats, " frag, "); sprintf(tmp, "%'u", cur.stat.discard.misc); waddstr_b(w_stats, tmp); waddstr(w_stats, " misc"); wclrtoborder(w_stats); /* * Interface TX stats */ mvwaddstr(w_stats, 2, 1, "TX: "); sprintf(tmp, "%'llu (%s)", nstat.tx_packets, byte_units(nstat.tx_bytes)); waddstr_b(w_stats, tmp); waddstr(w_stats, ", mac retries: "); sprintf(tmp, "%'u", cur.stat.discard.retries); waddstr_b(w_stats, tmp); waddstr(w_stats, ", missed beacons: "); sprintf(tmp, "%'u", cur.stat.miss.beacon); waddstr_b(w_stats, tmp); wclrtoborder(w_stats); wrefresh(w_stats); } static void display_info(WINDOW *w_if, WINDOW *w_info) { struct iw_dyn_info info; char tmp[0x100]; int i; dyn_info_get(&info, conf_ifname(), &cur.range); wmove(w_if, 1, 1); waddstr_b(w_if, con
/*
 * wavemon - a wireless network monitoring aplication
 *
 * Copyright (c) 2001-2002 Jan Morgenstern <jan@jm-music.de>
 *
 * wavemon 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, or (at your option) any later
 * version.
 *
 * wavemon 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 wavemon; see the file COPYING.  If not, write to the Free Software
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#include "wavemon.h"

/* GLOBALS */
static WINDOW *w_about;

static char *about_lines[] = {
	"wavemon - status monitor for wireless network devices",
	"version " PACKAGE_VERSION " (built " BUILD_DATE ")",
	"",
	"original by jan morgenstern <jan@jm-music.de>",
	"distributed under the GNU general public license v3",
	"",
	"wavemon uses the wireless extensions by",
	"jean tourrilhes <jt@hpl.hp.com>",
	"",
	"please send suggestions and bug reports to ",
	PACKAGE_BUGREPORT,
	"",
	PACKAGE_URL
};

static int *linecd[ARRAY_SIZE(about_lines)], i, j;

void scr_about_init(void)
{
	w_about = newwin_title(0, WAV_HEIGHT, "About", false);

	for (i = 0; i < ARRAY_SIZE(about_lines); i++) {
		linecd[i] = malloc(strlen(about_lines[i]) * sizeof(int));
		for (j = 0; j < strlen(about_lines[i]); j++)
			linecd[i][j] = (rand() / (float)RAND_MAX) * 120 + 60;
	}
}

int scr_about_loop(WINDOW *w_menu)
{
	char buf[0x100];

	for (i = 0; i < ARRAY_SIZE(about_lines); i++) {
		for (j = 0; j < strlen(about_lines[i]); j++) {
			if (linecd[i][j] > 60) {
				buf[j] = ' ';
				linecd[i][j]--;
			} else if (linecd[i][j]) {
				buf[j] = (rand() / (float)RAND_MAX) * 54 + 65;
				linecd[i][j]--;
			} else {
				buf[j] = about_lines[i][j];
			}
		}
		buf[j] = '\0';
		waddstr_center(w_about, (WAV_HEIGHT - ARRAY_SIZE(about_lines))/2 + i, buf);
	}
	wrefresh(w_about);
	return wgetch(w_menu);
}

void scr_about_fini(void)
{
	delwin(w_about);
	for (i = 0; i < ARRAY_SIZE(about_lines); i++)
		free(linecd[i]);
}