Commit 12038906 authored by Bruno Randolf's avatar Bruno Randolf

Formatting

parent 550d7f1c
......@@ -26,20 +26,16 @@
#include "capture.h"
#include "util.h"
void __attribute__ ((format (printf, 1, 2)))
printlog(const char *fmt, ...);
#define PCAP_TIMEOUT 200
static unsigned char* pcap_buffer;
static size_t pcap_bufsize;
static pcap_t *pcap_fp = NULL;
static void
handler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
static void handler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
{
*((int *)user) = h->len;
if (pcap_bufsize < h->len) {
......@@ -50,9 +46,7 @@ handler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
memmove(pcap_buffer, bytes, *((int *)user));
}
int
open_packet_socket(char* devname, __attribute__((unused)) int recv_buffer_size)
int open_packet_socket(char* devname, __attribute__((unused)) int recv_buffer_size)
{
char error[PCAP_ERRBUF_SIZE];
int ret;
......@@ -81,11 +75,9 @@ open_packet_socket(char* devname, __attribute__((unused)) int recv_buffer_size)
return pcap_fileno(pcap_fp);
}
int
device_get_hwinfo(__attribute__((unused)) int fd,
__attribute__((unused)) char* ifname,
__attribute__((unused)) unsigned char* mac)
int device_get_hwinfo(__attribute__((unused)) int fd,
__attribute__((unused)) char* ifname,
__attribute__((unused)) unsigned char* mac)
{
if (pcap_fp != NULL) {
switch (pcap_datalink(pcap_fp)) {
......@@ -101,10 +93,8 @@ device_get_hwinfo(__attribute__((unused)) int fd,
return -1;
}
int
recv_packet(__attribute__((unused)) int fd,
unsigned char* buffer, size_t bufsize)
int recv_packet(__attribute__((unused)) int fd,
unsigned char* buffer, size_t bufsize)
{
int ret = 0;
pcap_buffer = buffer;
......@@ -115,8 +105,7 @@ recv_packet(__attribute__((unused)) int fd,
}
void
close_packet_socket(__attribute__((unused)) int fd)
void close_packet_socket(__attribute__((unused)) int fd)
{
if (pcap_fp != NULL)
pcap_close(pcap_fp);
......
......@@ -37,8 +37,7 @@
/*
* Get the hardware type of the given interface as ARPHRD_xxx constant.
*/
int
device_get_hwinfo(int fd, char* ifname, unsigned char* mac)
int device_get_hwinfo(int fd, char* ifname, unsigned char* mac)
{
struct ifreq ifr;
......@@ -54,9 +53,7 @@ device_get_hwinfo(int fd, char* ifname, unsigned char* mac)
return ifr.ifr_hwaddr.sa_family;
}
static void
set_receive_buffer(int fd, int sockbufsize)
static void set_receive_buffer(int fd, int sockbufsize)
{
int ret;
......@@ -79,9 +76,7 @@ set_receive_buffer(int fd, int sockbufsize)
#endif
}
int
open_packet_socket(char* devname, int recv_buffer_size)
int open_packet_socket(char* devname, int recv_buffer_size)
{
int ret;
int mon_fd;
......@@ -112,16 +107,12 @@ open_packet_socket(char* devname, int recv_buffer_size)
return mon_fd;
}
inline int
recv_packet(int fd, unsigned char* buffer, size_t bufsize)
inline int recv_packet(int fd, unsigned char* buffer, size_t bufsize)
{
return recv(fd, buffer, bufsize, MSG_DONTWAIT);
}
void
close_packet_socket(int fd)
void close_packet_socket(int fd)
{
if (fd > 0)
close(fd);
......
......@@ -22,16 +22,12 @@
#include <stddef.h>
int
open_packet_socket(char* devname, int recv_buffer_size);
int open_packet_socket(char* devname, int recv_buffer_size);
int
recv_packet(int fd, unsigned char* buffer, size_t bufsize);
int recv_packet(int fd, unsigned char* buffer, size_t bufsize);
void
close_packet_socket(int fd);
void close_packet_socket(int fd);
int
device_get_hwinfo(int fd, char* ifname, unsigned char* mac);
int device_get_hwinfo(int fd, char* ifname, unsigned char* mac);
#endif // _CAPTURE_H_
......@@ -29,8 +29,7 @@
static struct timeval last_channelchange;
static struct channel_list channels;
long
channel_get_remaining_dwell_time(void)
long channel_get_remaining_dwell_time(void)
{
if (!conf.do_change_channel)
return LONG_MAX;
......@@ -43,14 +42,15 @@ channel_get_remaining_dwell_time(void)
}
static struct band_info
channel_get_band_from_idx(int idx) {
static struct band_info channel_get_band_from_idx(int idx)
{
int b = idx - channels.band[0].num_channels < 0 ? 0 : 1;
return channels.band[b];
}
static int get_center_freq_ht40(unsigned int freq, bool upper) {
static int get_center_freq_ht40(unsigned int freq, bool upper)
{
unsigned int center = 0;
/*
* For HT40 we have a channel offset of 20 MHz, and the
......@@ -65,7 +65,8 @@ static int get_center_freq_ht40(unsigned int freq, bool upper) {
}
static int get_center_freq_vht(unsigned int freq, enum chan_width width) {
static int get_center_freq_vht(unsigned int freq, enum chan_width width)
{
unsigned int center1 = 0;
switch(width) {
case CHAN_WIDTH_80:
......@@ -105,7 +106,8 @@ static int get_center_freq_vht(unsigned int freq, enum chan_width width) {
}
const char* channel_width_string(enum chan_width w, int ht40p) {
const char* channel_width_string(enum chan_width w, int ht40p)
{
switch (w) {
case CHAN_WIDTH_UNSPEC: return "?";
case CHAN_WIDTH_20_NOHT: return "20 (no HT)";
......@@ -118,7 +120,8 @@ const char* channel_width_string(enum chan_width w, int ht40p) {
return "";
}
const char* channel_width_string_short(enum chan_width w, int ht40p) {
const char* channel_width_string_short(enum chan_width w, int ht40p)
{
switch (w) {
case CHAN_WIDTH_UNSPEC: return "?";
case CHAN_WIDTH_20_NOHT: return "20g";
......@@ -133,8 +136,7 @@ const char* channel_width_string_short(enum chan_width w, int ht40p) {
/* Note: ht40plus is only used for HT40 channel width, to distinguish between
* HT40+ and HT40- */
bool
channel_change(int idx, enum chan_width width, bool ht40plus)
bool channel_change(int idx, enum chan_width width, bool ht40plus)
{
unsigned int center1 = 0;
......@@ -183,9 +185,7 @@ channel_change(int idx, enum chan_width width, bool ht40plus)
return true;
}
bool
channel_auto_change(void)
bool channel_auto_change(void)
{
int new_idx;
bool ret = true;
......@@ -245,7 +245,8 @@ channel_auto_change(void)
return ret;
}
char* channel_get_string(int idx) {
char* channel_get_string(int idx)
{
static char buf[32];
struct chan_freq* c = &channels.chan[idx];
snprintf(buf, sizeof(buf), "%-3d: %d HT40%s%s", c->chan, c->freq,
......@@ -254,8 +255,8 @@ char* channel_get_string(int idx) {
return buf;
}
bool
channel_init(void) {
bool channel_init(void)
{
/* get available channels */
ifctrl_iwget_freqlist(conf.if_phy, &channels);
conf.channel_initialized = 1;
......@@ -292,9 +293,7 @@ channel_init(void) {
return true;
}
int
channel_find_index_from_chan(int c)
int channel_find_index_from_chan(int c)
{
int i = -1;
for (i = 0; i < channels.num_channels && i < MAX_CHANNELS; i++)
......@@ -303,9 +302,7 @@ channel_find_index_from_chan(int c)
return -1;
}
int
channel_find_index_from_freq(unsigned int f)
int channel_find_index_from_freq(unsigned int f)
{
int i = -1;
for (i = 0; i < channels.num_channels && i < MAX_CHANNELS; i++)
......@@ -314,27 +311,24 @@ channel_find_index_from_freq(unsigned int f)
return -1;
}
int
channel_get_chan(int i) {
int channel_get_chan(int i)
{
if (i >= 0 && i < channels.num_channels && i < MAX_CHANNELS)
return channels.chan[i].chan;
else
return -1;
}
int
channel_get_freq(int idx) {
int channel_get_freq(int idx)
{
if (idx >= 0 && idx < channels.num_channels && idx < MAX_CHANNELS)
return channels.chan[idx].freq;
else
return -1;
}
bool
channel_list_add(int freq) {
bool channel_list_add(int freq)
{
if (channels.num_channels >= MAX_CHANNELS)
return false;
......@@ -344,18 +338,18 @@ channel_list_add(int freq) {
return true;
}
int
channel_get_num_channels() {
int channel_get_num_channels()
{
return channels.num_channels;
}
int
channel_get_num_bands() {
int channel_get_num_bands()
{
return channels.num_bands;
}
int
channel_get_idx_from_band_idx(int band, int idx) {
int channel_get_idx_from_band_idx(int band, int idx)
{
if (band < 0 || band >= channels.num_bands)
return -1;
......@@ -368,15 +362,16 @@ channel_get_idx_from_band_idx(int band, int idx) {
return idx;
}
const struct band_info* channel_get_band(int b) {
const struct band_info* channel_get_band(int b)
{
if (b < 0 || b > channels.num_bands)
return NULL;
return &channels.band[b];
}
bool
channel_band_add(int num_channels, enum chan_width max_chan_width,
unsigned char streams_rx, unsigned char streams_tx) {
bool channel_band_add(int num_channels, enum chan_width max_chan_width,
unsigned char streams_rx, unsigned char streams_tx)
{
if (channels.num_bands >= MAX_BANDS)
return false;
......
......@@ -55,57 +55,25 @@ struct channel_list {
int num_bands;
};
bool
channel_change(int idx, enum chan_width width, bool ht40plus);
bool
channel_auto_change(void);
int
channel_find_index_from_chan(int c);
int
channel_find_index_from_freq(unsigned int f);
int
channel_get_chan(int idx);
int
channel_get_freq(int idx);
int
channel_get_num_channels();
bool
channel_init(void);
bool
channel_list_add(int freq);
long
channel_get_remaining_dwell_time(void);
char*
channel_get_string(int idx);
bool channel_change(int idx, enum chan_width width, bool ht40plus);
bool channel_auto_change(void);
int channel_find_index_from_chan(int c);
int channel_find_index_from_freq(unsigned int f);
int channel_get_chan(int idx);
int channel_get_freq(int idx);
int channel_get_num_channels();
bool channel_init(void);
bool channel_list_add(int freq);
long channel_get_remaining_dwell_time(void);
char* channel_get_string(int idx);
/* Note: ht40p is used only for HT40 channels. If it should not be shown use -1 */
const char*
channel_width_string(enum chan_width w, int ht40p);
const char* channel_width_string(enum chan_width w, int ht40p);
/* Note: ht40p is used only for HT40 channels. If it should not be shown use -1 */
const char*
channel_width_string_short(enum chan_width w, int ht40p);
int
channel_get_num_bands();
int
channel_get_idx_from_band_idx(int band, int idx);
const char* channel_width_string_short(enum chan_width w, int ht40p);
int channel_get_num_bands();
int channel_get_idx_from_band_idx(int band, int idx);
const struct band_info* channel_get_band(int b);
bool
channel_band_add(int num_channels, enum chan_width max_chan_width,
unsigned char streams_rx, unsigned char streams_tx);
bool channel_band_add(int num_channels, enum chan_width max_chan_width,
unsigned char streams_rx, unsigned char streams_tx);
#endif
......@@ -293,7 +293,6 @@ static bool conf_mac_names(const char* value) {
return true;
}
static struct conf_option conf_options[] = {
/* C , NAME VALUE REQUIRED, DEFAULT CALLBACK */
{ 'q', "quiet", 0, NULL, conf_quiet }, // NOT dynamic
......@@ -323,7 +322,6 @@ static struct conf_option conf_options[] = {
{ 'M', "mac_names", 2, NULL, conf_mac_names },
};
/*
* More possible config options:
*
......@@ -340,8 +338,8 @@ static struct conf_option conf_options[] = {
* In the second case 'c' is 0 and name is set
* Value may be null in all cases
*/
bool
config_handle_option(int c, const char* name, const char* value) {
bool config_handle_option(int c, const char* name, const char* value)
{
unsigned int i;
char* end;
......@@ -372,9 +370,8 @@ config_handle_option(int c, const char* name, const char* value) {
return false;
}
static void
config_read_file(const char* filename) {
static void config_read_file(const char* filename)
{
FILE* fp ;
char line[255];
char name[MAX_CONF_NAME_STRLEN + 1];
......@@ -411,8 +408,8 @@ config_read_file(const char* filename) {
fclose(fp);
}
static void
config_apply_defaults(void) {
static void config_apply_defaults(void)
{
unsigned int i;
for (i=0; i < sizeof(conf_options)/sizeof(struct conf_option); i++) {
if (conf_options[i].default_value != NULL) {
......@@ -421,9 +418,8 @@ config_apply_defaults(void) {
}
}
static char*
config_get_getopt_string(char* buf, size_t maxlen, const char* add) {
static char* config_get_getopt_string(char* buf, size_t maxlen, const char* add)
{
unsigned int pos = 0;
unsigned int i;
maxlen = maxlen - 1; // we use it as string index
......@@ -453,8 +449,8 @@ config_get_getopt_string(char* buf, size_t maxlen, const char* add) {
return buf;
}
void print_usage(const char* name) {
void print_usage(const char* name)
{
printf("\nUsage: %s [-v] [-h] [-q] [-D] [-a] [-c file] [-i interface] [-t sec] [-d ms] [-V view] [-b bytes]\n"
"\t\t[-s] [-u] [-N] [-n IP] [-p port] [-o file] [-X[name]] [-x command]\n"
"\t\t[][-e MAC] [-f PKT_NAME] [-m MODE] [-B BSSID]\n\n"
......@@ -502,9 +498,7 @@ void print_usage(const char* name) {
name);
}
void
config_parse_file_and_cmdline(int argc, char** argv)
void config_parse_file_and_cmdline(int argc, char** argv)
{
char getopt_str[(sizeof(conf_options)/sizeof(struct conf_option))*2 + 10];
char* conf_filename = CONFIG_FILE;
......
......@@ -35,16 +35,13 @@
int ctlpipe = -1;
void
control_init_pipe(void)
void control_init_pipe(void)
{
mkfifo(conf.control_pipe, 0666);
ctlpipe = open(conf.control_pipe, O_RDWR|O_NONBLOCK);
}
void
control_send_command(const char* cmd)
void control_send_command(const char* cmd)
{
int len = strlen(cmd);
char new[len + 2];
......@@ -80,9 +77,7 @@ control_send_command(const char* cmd)
close(ctlpipe);
}
static void
parse_command(char* in) {
static void parse_command(char* in) {
char* cmd;
char* val;
......@@ -107,9 +102,8 @@ parse_command(char* in) {
}
}
void
control_receive_command(void) {
void control_receive_command(void)
{
char buf[MAX_CMD];
char *pos = buf;
char *end;
......@@ -127,9 +121,7 @@ control_receive_command(void) {
}
}
void
control_finish(void)
void control_finish(void)
{
if (ctlpipe == -1)
return;
......
......@@ -24,16 +24,9 @@
extern int ctlpipe;
void
control_init_pipe();
void
control_send_command(const char* cmd);
void
control_receive_command();
void
control_finish(void);
void control_init_pipe();
void control_send_command(const char* cmd);
void control_receive_command();
void control_finish(void);
#endif
......@@ -26,11 +26,9 @@
#include "channel.h"
#include "network.h"
#define COL_BAND2 23
void
update_channel_win(WINDOW *win)
void update_channel_win(WINDOW *win)
{
int l = 2;
......@@ -94,9 +92,7 @@ update_channel_win(WINDOW *win)
wrefresh(win);
}
bool
channel_input(WINDOW *win, int c)
bool channel_input(WINDOW *win, int c)
{
char buf[6];
int x;
......
......@@ -25,9 +25,7 @@
#include "main.h"
#include "util.h"
void
update_essid_win(WINDOW *win)
void update_essid_win(WINDOW *win)
{
int i;
int line = 1;
......
......@@ -33,8 +33,7 @@
#define SECOND_ROW 19
#define THIRD_ROW 23
void
update_filter_win(WINDOW *win)
void update_filter_win(WINDOW *win)
{
int l, i, t, col = 2;
......@@ -122,8 +121,7 @@ update_filter_win(WINDOW *win)
wrefresh(win);
}
bool
filter_input(WINDOW *win, int c)
bool filter_input(WINDOW *win, int c)
{
char buf[18];
int i, t;
......
......@@ -25,9 +25,7 @@
#include "main.h"
#include "wlan_util.h"
void
update_help_win(WINDOW *win)
void update_help_win(WINDOW *win)
{
int i, t, col, l;
......
......@@ -30,9 +30,7 @@
#define TYPE_POS SIGN_POS+1
#define RATE_POS LINES-2
void
update_history_win(WINDOW *win)
void update_history_win(WINDOW *win)
{
int i;
int col = COLS-2;
......@@ -85,8 +83,7 @@ update_history_win(WINDOW *win)
i = hist.index - 1;
while (col > 4 && hist.signal[i] != 0)
{
while (col > 4 && hist.signal[i] != 0) {
sig = normalize_db(-hist.signal[i], SIGN_POS - 1);
wattron(win, ALLGREEN);
......
......@@ -32,7 +32,6 @@
#include "listsort.h"
#include "channel.h"
static WINDOW *sort_win = NULL;
static WINDOW *dump_win = NULL;
static WINDOW *list_win = NULL;
......@@ -49,11 +48,9 @@ static int stat_height;
static struct ewma usen_avg;
static struct ewma bpsn_avg;
/******************* UTIL *******************/
void
print_dump_win(const char *str, int refresh)
void print_dump_win(const char *str, int refresh)
{
wattron(dump_win, RED);
wprintw(dump_win, str);
......@@ -64,11 +61,9 @@ print_dump_win(const char *str, int refresh)
wnoutrefresh(dump_win);
}
/******************* SORTING *******************/
static int
compare_nodes_signal(const struct list_node *p1, const struct list_node *p2)
static int compare_nodes_signal(const struct list_node *p1, const struct list_node *p2)
{
struct node_info* n1 = list_entry(p1, struct node_info, list);
struct node_info* n2 = list_entry(p2, struct node_info, list);
......@@ -81,9 +76,7 @@ compare_nodes_signal(const struct list_node *p1, const struct list_node *p2)
return 1;
}
static int
compare_nodes_time(const struct list_node *p1, const struct list_node *p2)
static int compare_nodes_time(const struct list_node *p1, const struct list_node *p2)
{
struct node_info* n1 = list_entry(p1, struct node_info, list);
struct node_info* n2 = list_entry(p2, struct node_info, list);
......@@ -96,9 +89,7 @@ compare_nodes_time(const struct list_node *p1, const struct list_node *p2)
return 1;
}
static int
compare_nodes_channel(const struct list_node *p1, const struct list_node *p2)
static int compare_nodes_channel(const struct list_node *p1, const struct list_node *p2)
{
struct node_info* n1 = list_entry(p1, struct node_info, list);
struct node_info* n2 = list_entry(p2, struct node_info, list);
......@@ -111,9 +102,7 @@ compare_nodes_channel(const struct list_node *p1, const struct list_node *p2)
return -1;
}
static int
compare_nodes_bssid(const struct list_node *p1, const struct list_node *p2)
static int compare_nodes_bssid(const struct list_node *p1, const struct list_node *p2)
{
struct node_info* n1 = list_entry(p1, struct node_info, list);
struct node_info* n2 = list_entry(p2, struct node_info, list);
......@@ -121,9 +110,7 @@ compare_nodes_bssid(const struct list_node *p1, const struct list_node *p2)
return -memcmp(n1->wlan_bssid, n2->wlan_bssid, MAC_LEN);
}
static bool
sort_input(int c)
static bool sort_input(int c)
{
switch (c) {
case 'n': case 'N': sortfunc = NULL; break;
......@@ -150,9 +137,7 @@ sort_input(int c)
return false;
}
static void
show_sort_win(void)
static void show_sort_win(void)
{
if (sort_win == NULL) {
sort_win = newwin(1, COLS-2, win_split - 2, 1);
......@@ -163,14 +148,12 @@ show_sort_win(void)
}
}
/******************* WINDOWS *******************/
#define STAT_WIDTH 11
#define STAT_START 4
static void
update_status_win(struct packet_info* p)
static void update_status_win(struct packet_info* p)
{
int sig, siga, bps, dps, pps, rps, bpsn, usen;
float use, rpsp = 0.0;
......@@ -232,7 +215,6 @@ update_status_win(struct packet_info* p)
wnoutrefresh(stat_win);