diff options
Diffstat (limited to '')
-rw-r--r-- | wavemon.h | 162 |
1 files changed, 111 insertions, 51 deletions
@@ -25,6 +25,7 @@ #include <assert.h> #include <errno.h> #include <err.h> +#include <time.h> #include <sys/time.h> #include <sys/ioctl.h> @@ -40,14 +41,25 @@ #define CFNAME ".wavemonrc" /* * Minimum screen dimensions. - * The number of lines depends on the size requirements of scr_info(), which - * is 23 + 1 lines (1 line is needed for the menubar). The number of columns - * comes from the menubar length (10 items of length 6 plus the 'Fxx'). - * This value was also chosen since 24x80 is a very common screen size, so - * that wavemon can also be used without restrictions on the console. + * The number of lines depends on the size requirements of scr_info(). The + * number of columns comes from the menubar length (10 items of length 6 + * plus the 'Fxx'). This value was also chosen since 24x80 is a very common + * screen size, in particular allowing the use on the console. */ -#define MIN_SCREEN_LINES 24 -#define MIN_SCREEN_COLS 80 +enum info_screen_geometry { + WH_IFACE = 2, /* 'Interface' area at the top */ + WH_LEVEL = 9, /* Level meters (signal/noise/SNR) */ + WH_STATS = 3, /* WiFi statistics area */ + WH_INFO_MIN = 6, /* WiFi information area */ + WH_NET_MIN = 3, /* Network interface information area */ + WH_NET_MAX = 5, /* Network interface information area */ + WH_MENU = 1 /* Menu bar at the bottom */ +}; +#define WH_INFO_SCR_BASE (WH_IFACE + WH_LEVEL + WH_STATS + WH_MENU) +#define WH_INFO_SCR_MIN (WH_INFO_SCR_BASE + WH_INFO_MIN + WH_NET_MIN) + +#define MIN_SCREEN_LINES WH_INFO_SCR_MIN +#define MIN_SCREEN_COLS 80 /* * Screen layout constants. * @@ -91,7 +103,7 @@ static inline void threshold_action(enum threshold_action action) * Global in-memory representation of current wavemon configuration state */ extern struct wavemon_conf { - char ifname[LISTVAL_MAX]; + int if_idx; /* Index into interface list */ int stat_iv, info_iv; @@ -105,53 +117,42 @@ extern struct wavemon_conf { int slotsize, meter_decay; - /* Boolean values which are 'char' for consistency with item->dep */ - char random, - override_bounds; + /* Boolean values */ + int check_geometry, /* ensure window is large enough */ + cisco_mac, /* Cisco-style MAC addresses */ + random, /* random signals */ + override_bounds; /* override autodetection */ - char lthreshold_action, /* disabled|beep|flash|beep+flash */ - hthreshold_action; - - char startup_scr; /* info|histogram|aplist */ + /* Enumerated values */ + int lthreshold_action, /* disabled|beep|flash|beep+flash */ + hthreshold_action, /* disabled|beep|flash|beep+flash */ + startup_scr; /* info|histogram|aplist */ } conf; /* - * Initialisation & Configuration functions + * Initialisation & Configuration */ extern void getconf(int argc, char *argv[]); -extern void reinit_on_changes(void); -/* - * Configuration items to manipulate the current configuration - */ +/* Configuration items to manipulate the current configuration */ struct conf_item { char *name, /* name for preferences screen */ *cfname; /* name for ~/.wavemonrc */ enum { /* type of parameter */ - t_int, - t_string, - t_listval, - t_switch, - t_list, - t_sep, /* dummy */ + t_int, /* @v.i is interpreted as raw value */ + t_list, /* @v.i is an index into @list */ + t_sep, /* dummy, separator entry */ t_func /* void (*fp) (void) */ } type; union { /* type-dependent container for value */ - int *i; /* t_int */ - char *s; /* t_string, t_listval */ - char *b; /* - * t_switch: a boolean type - * t_list: an enum type where 0 means "off" - * A pointer is needed to propagate the changes. See - * the 'char' types in the above wavemon_conf struct. - */ + int *i; /* t_int and t_list index into @list */ void (*fp)(); /* t_func */ } v; - int list; /* list of available settings (for t_list) */ - char *dep; /* dependency (must be t_switch) */ + char **list; /* t_list: NULL-terminated array of strings */ + int *dep; /* dependency */ double min, /* value boundaries */ max, @@ -161,11 +162,6 @@ struct conf_item { }; /* - * Handling of Configuration Items - */ -extern int conf_items; - -/* * Screen functions */ enum wavemon_screen { @@ -181,12 +177,29 @@ enum wavemon_screen { SCR_QUIT /* F10 */ }; -extern enum wavemon_screen scr_info(WINDOW *w_menu); -extern enum wavemon_screen scr_lhist(WINDOW *w_menu); -extern enum wavemon_screen scr_aplst(WINDOW *w_menu); -extern enum wavemon_screen scr_conf(WINDOW *w_menu); -extern enum wavemon_screen scr_help(WINDOW *w_menu); -extern enum wavemon_screen scr_about(WINDOW *w_menu); +extern void scr_info_init(void); +extern int scr_info_loop(WINDOW *w_menu); +extern void scr_info_fini(void); + +extern void scr_lhist_init(void); +extern int scr_lhist_loop(WINDOW *w_menu); +extern void scr_lhist_fini(void); + +extern void scr_aplst_init(void); +extern int scr_aplst_loop(WINDOW *w_menu); +extern void scr_aplst_fini(void); + +extern void scr_conf_init(void); +extern int scr_conf_loop(WINDOW *w_menu); +extern void scr_conf_fini(void); + +extern void scr_help_init(void); +extern int scr_help_loop(WINDOW *w_menu); +extern void scr_help_fini(void); + +extern void scr_about_init(void); +extern int scr_about_loop(WINDOW *w_menu); +extern void scr_about_fini(void); /* * Ncurses definitions and functions @@ -220,7 +233,10 @@ enum colour_pair { CP_STATNOISE_S, CP_PREF_NORMAL, CP_PREF_SELECT, - CP_PREF_ARROW + CP_PREF_ARROW, + CP_SCAN_CRYPT, + CP_SCAN_UNENC, + CP_SCAN_NON_AP }; static inline int cp_from_scale(float value, const char *cscale, bool reverse) @@ -240,7 +256,9 @@ static inline int cp_from_scale(float value, const char *cscale, bool reverse) /* * Wireless interfaces */ -extern int iw_get_interface_list(void); +extern const char *conf_ifname(void); +extern void conf_get_interface_list(void); +extern char **iw_get_interface_list(void); extern void dump_parameters(void); /* @@ -257,6 +275,7 @@ extern int end_timer(struct timer *t); /* * Error handling */ +extern bool has_net_admin_capability(void); extern void err_msg(const char *format, ...); extern void err_quit(const char *format, ...); extern void err_sys(const char *format, ...); @@ -266,10 +285,51 @@ extern void err_sys(const char *format, ...); */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +static inline void (*xsignal(int signo, void (*handler)(int)))(int) +{ + struct sigaction old_sa, sa = { .sa_handler = handler, .sa_flags = 0 }; + + if (sigemptyset(&sa.sa_mask) < 0 || sigaction(signo, &sa, &old_sa) < 0) + err_sys("xsignal(%d) failed", signo); + return old_sa.sa_handler; +} + +static inline size_t argv_count(char **argv) +{ + int cnt = 0; + + assert(argv != NULL); + while (*argv++) + cnt++; + return cnt; +} + +static inline int argv_find(char **argv, const char *what) +{ + int cnt = argv_count(argv), len, i; + + assert(what != NULL); + for (i = 0, len = strlen(what); i < cnt; i++) + if (strncasecmp(argv[i], what, len) == 0) + return i; + return -1; +} + static inline void str_tolower(char *s) { - while (s && *s != '\0') - *s++ = tolower(*s); + for (; s && *s; s++) + *s = tolower(*s); +} + +/* Check if @str is printable (compare iw_essid_escape()) */ +static inline bool str_is_ascii(char *s) +{ + if (!s || !*s) + return false; + for (; *s; s++) + if (!isascii(*s) || iscntrl(*s)) + return false; + return true; } /* number of digits needed to display integer part of @val */ |