Commit 9e5efc1c authored by Bruno Randolf's avatar Bruno Randolf

Update display for channel widths

parent f641f9a6
TODO: TODO:
----- -----
* extend network protocol for new chan and filters
* calculate available bandwidth for info bars (Usage%) based on channel width
* Detect 802.11n and 802.11ac and respective channel widths (40, 80 160) * Detect 802.11n and 802.11ac and respective channel widths (40, 80 160)
Later:
* Integrate 'iw survey dump' info (noise) * Integrate 'iw survey dump' info (noise)
...@@ -98,13 +98,13 @@ static int get_center_freq_vht(unsigned int freq, enum chan_width width) { ...@@ -98,13 +98,13 @@ static int get_center_freq_vht(unsigned int freq, enum chan_width width) {
printlog("VHT80+80 not supported"); printlog("VHT80+80 not supported");
break; break;
default: default:
printlog("%s is not VHT", get_chan_width_string(width)); printlog("%s is not VHT", channel_get_width_string(width));
} }
return center1; return center1;
} }
const char* get_chan_width_string(enum chan_width w) { const char* channel_get_width_string(enum chan_width w) {
switch (w) { switch (w) {
case CHAN_WIDTH_UNSPEC: return "Unspecified"; case CHAN_WIDTH_UNSPEC: return "Unspecified";
case CHAN_WIDTH_20: return "HT20"; case CHAN_WIDTH_20: return "HT20";
...@@ -116,6 +116,17 @@ const char* get_chan_width_string(enum chan_width w) { ...@@ -116,6 +116,17 @@ const char* get_chan_width_string(enum chan_width w) {
return ""; return "";
} }
const char* channel_get_width_string_short(enum chan_width w, bool ht40p) {
switch (w) {
case CHAN_WIDTH_UNSPEC: return "UNS";
case CHAN_WIDTH_20: return "20";
case CHAN_WIDTH_40: return ht40p ? "40+" : "40-";
case CHAN_WIDTH_80: return "80";
case CHAN_WIDTH_160: return "160";
case CHAN_WIDTH_8080: return "80+80";
}
return "";
}
/* Note: ht40plus is only used for HT40 channel width, to distinguish between /* Note: ht40plus is only used for HT40 channel width, to distinguish between
* HT40+ and HT40- */ * HT40+ and HT40- */
...@@ -138,7 +149,7 @@ channel_change(int idx, enum chan_width width, bool ht40plus) ...@@ -138,7 +149,7 @@ channel_change(int idx, enum chan_width width, bool ht40plus)
center1 = get_center_freq_vht(channels.chan[idx].freq, width); center1 = get_center_freq_vht(channels.chan[idx].freq, width);
break; break;
default: default:
printlog("%s not implemented", get_chan_width_string(width)); printlog("%s not implemented", channel_get_width_string(width));
break; break;
} }
...@@ -150,7 +161,7 @@ channel_change(int idx, enum chan_width width, bool ht40plus) ...@@ -150,7 +161,7 @@ channel_change(int idx, enum chan_width width, bool ht40plus)
if (!ifctrl_iwset_freq(conf.ifname, channels.chan[idx].freq, width, center1)) { if (!ifctrl_iwset_freq(conf.ifname, channels.chan[idx].freq, width, center1)) {
printlog("ERROR: Failed to set CH %d (%d MHz) %s%c center %d", printlog("ERROR: Failed to set CH %d (%d MHz) %s%c center %d",
channels.chan[idx].chan, channels.chan[idx].freq, channels.chan[idx].chan, channels.chan[idx].freq,
get_chan_width_string(width), channel_get_width_string(width),
center1 > channels.chan[idx].freq ? '+' : '-', center1 > channels.chan[idx].freq ? '+' : '-',
center1); center1);
return false; return false;
...@@ -158,7 +169,7 @@ channel_change(int idx, enum chan_width width, bool ht40plus) ...@@ -158,7 +169,7 @@ channel_change(int idx, enum chan_width width, bool ht40plus)
printlog("Set CH %d (%d MHz) %s%c center %d", printlog("Set CH %d (%d MHz) %s%c center %d",
channels.chan[idx].chan, channels.chan[idx].freq, channels.chan[idx].chan, channels.chan[idx].freq,
get_chan_width_string(width), channel_get_width_string(width),
center1 > channels.chan[idx].freq ? '+' : '-', center1 > channels.chan[idx].freq ? '+' : '-',
center1); center1);
...@@ -230,6 +241,14 @@ channel_get_current_chan() { ...@@ -230,6 +241,14 @@ channel_get_current_chan() {
return channel_get_chan_from_idx(conf.channel_idx); return channel_get_chan_from_idx(conf.channel_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,
get_center_freq_ht40(c->freq, true) ? "+" : "",
get_center_freq_ht40(c->freq, false) ? "-" : "");
return buf;
}
bool bool
channel_init(void) { channel_init(void) {
...@@ -237,12 +256,8 @@ channel_init(void) { ...@@ -237,12 +256,8 @@ channel_init(void) {
ifctrl_iwget_freqlist(conf.if_phy, &channels); ifctrl_iwget_freqlist(conf.if_phy, &channels);
printf("Got %d Bands, %d Channels:\n", channels.num_bands, channels.num_channels); printf("Got %d Bands, %d Channels:\n", channels.num_bands, channels.num_channels);
for (int i = 0; i < channels.num_channels && i < MAX_CHANNELS; i++) { for (int i = 0; i < channels.num_channels && i < MAX_CHANNELS; i++)
struct chan_freq* c = &channels.chan[i]; printf("%s\n", channel_get_string(i));
printf("%-3d: %d HT40%s%s\n", c->chan, c->freq,
get_center_freq_ht40(c->freq, true) ? "+" : "",
get_center_freq_ht40(c->freq, false) ? "-" : "");
}
conf.channel_idx = channel_find_index_from_freq(conf.if_freq); conf.channel_idx = channel_find_index_from_freq(conf.if_freq);
...@@ -312,3 +327,29 @@ int ...@@ -312,3 +327,29 @@ int
channel_get_num_channels() { channel_get_num_channels() {
return channels.num_channels; return channels.num_channels;
} }
int
channel_get_num_bands() {
return channels.num_bands;
}
int
channel_get_idx_from_band_idx(int band, int idx) {
if (band < 0 || band >= channels.num_bands)
return -1;
if (idx < 0 || idx >= channels.band[band].num_channels)
return -1;
if (band > 0)
idx = idx + channels.band[0].num_channels;
return idx;
}
const char* channel_get_band_width_string(int b) {
if (b < 0 || b > channels.num_bands)
return NULL;
return channel_get_width_string(channels.band[b].max_chan_width);
}
...@@ -88,7 +88,22 @@ channel_list_add(int chan, int freq); ...@@ -88,7 +88,22 @@ channel_list_add(int chan, int freq);
long long
channel_get_remaining_dwell_time(void); channel_get_remaining_dwell_time(void);
char*
channel_get_string(int idx);
const char*
channel_get_width_string(enum chan_width w);
const char*
channel_get_width_string_short(enum chan_width w, bool ht40p);
const char* const char*
get_chan_width_string(enum chan_width w); channel_get_band_width_string(int b);
int
channel_get_num_bands();
int
channel_get_idx_from_band_idx(int band, int idx);
#endif #endif
...@@ -32,27 +32,31 @@ ...@@ -32,27 +32,31 @@
void void
update_channel_win(WINDOW *win) update_channel_win(WINDOW *win)
{ {
int l = 2, c = 2; int l = 2, c, col;
box(win, 0 , 0); box(win, 0 , 0);
print_centered(win, 0, 39, " Channel Settings "); print_centered(win, 0, 39, " Channel Settings ");
wattron(win, WHITE); wattron(win, WHITE);
for (int b = 0; b < channel_get_num_bands(); b++) { for (int b = 0; b < channel_get_num_bands(); b++) {
l = 2; c = channel_get_idx_from_band_idx(b, 0);
col = channel_get_chan_from_idx(c) > 14 ? COL_BAND2 : 2;
wattron(win, A_BOLD); wattron(win, A_BOLD);
mvwprintw(win, l++, b ? COL_BAND2 : 2, "Band %d (%s)", b + 1, mvwprintw(win, 2, col, "%s: (%s)",
channel_get_band_width_string(b)); col == 2 ? "2.4GHz" : "5GHz",
channel_get_band_width_string(b));
wattroff(win, A_BOLD); wattroff(win, A_BOLD);
l = 3;
for (int i = 0; (c = channel_get_idx_from_band_idx(b, i)) != -1; i++) { for (int i = 0; (c = channel_get_idx_from_band_idx(b, i)) != -1; i++) {
if (c == conf.channel_idx) if (c == conf.channel_idx)
wattron(win, CYAN); wattron(win, CYAN);
else else
wattron(win, WHITE); wattron(win, WHITE);
mvwprintw(win, l++, b ? COL_BAND2 : 2, "%s", channel_get_string(c)); mvwprintw(win, l++,
col,
"%s", channel_get_string(c));
} }
} }
wattroff(win, WHITE); wattroff(win, WHITE);
l = 17; l = 17;
...@@ -79,9 +83,8 @@ update_channel_win(WINDOW *win) ...@@ -79,9 +83,8 @@ update_channel_win(WINDOW *win)
mvwprintw(win, l++, 2, "6: [%c] VHT160", mvwprintw(win, l++, 2, "6: [%c] VHT160",
CHECKED(conf.channel_width == CHAN_WIDTH_160)); CHECKED(conf.channel_width == CHAN_WIDTH_160));
l++; print_centered(win, CHANNEL_WIN_HEIGHT-1, CHANNEL_WIN_WIDTH,
print_centered(win, l++, 39, "[ Press key or ENTER ]"); "[ Press key or ENTER ]");
wrefresh(win); wrefresh(win);
} }
......
...@@ -204,12 +204,14 @@ static void ...@@ -204,12 +204,14 @@ static void
update_mini_status(void) update_mini_status(void)
{ {
wattron(stdscr, BLACKONWHITE); wattron(stdscr, BLACKONWHITE);
mvwprintw(stdscr, LINES-1, COLS-27, conf.paused ? "|=" : "|>"); mvwprintw(stdscr, LINES-1, COLS-31, conf.paused ? "|=" : "|>");
if (!conf.filter_off && (conf.do_macfilter || conf.filter_pkt != PKT_TYPE_ALL || conf.filter_mode != WLAN_MODE_ALL)) if (!conf.filter_off && (conf.do_macfilter || conf.filter_pkt != PKT_TYPE_ALL || conf.filter_mode != WLAN_MODE_ALL))
mvwprintw(stdscr, LINES-1, COLS-25, "|F"); mvwprintw(stdscr, LINES-1, COLS-29, "|F");
else else
mvwprintw(stdscr, LINES-1, COLS-25, "| "); mvwprintw(stdscr, LINES-1, COLS-29, "| ");
mvwprintw(stdscr, LINES-1, COLS-23, "|Ch%03d", channel_get_current_chan()); mvwprintw(stdscr, LINES-1, COLS-27, "|Ch%03d@%s", channel_get_current_chan(),
channel_get_width_string_short(conf.channel_width, conf.channel_ht40plus));
wattroff(stdscr, BLACKONWHITE); wattroff(stdscr, BLACKONWHITE);
wnoutrefresh(stdscr); wnoutrefresh(stdscr);
} }
...@@ -299,11 +301,14 @@ show_conf_window(int key) ...@@ -299,11 +301,14 @@ show_conf_window(int key)
if (conf_win == NULL) { if (conf_win == NULL) {
if (key == 'f') { if (key == 'f') {
conf_win = newwin(FILTER_WIN_HEIGHT, FILTER_WIN_WIDTH, conf_win = newwin(FILTER_WIN_HEIGHT, FILTER_WIN_WIDTH,
LINES/2-13, COLS/2-28); LINES/2-FILTER_WIN_HEIGHT/2,
COLS/2-FILTER_WIN_WIDTH/2);
update_filter_win(conf_win); update_filter_win(conf_win);
} }
else if (key == 'c') { else if (key == 'c') {
conf_win = newwin(9, 39, LINES/2-6, COLS/2-20); conf_win = newwin(CHANNEL_WIN_HEIGHT, CHANNEL_WIN_WIDTH,
LINES/2-CHANNEL_WIN_HEIGHT/2,
COLS/2-CHANNEL_WIN_WIDTH/2);
update_channel_win(conf_win); update_channel_win(conf_win);
} }
scrollok(conf_win, FALSE); scrollok(conf_win, FALSE);
......
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
#define FILTER_WIN_WIDTH 56 #define FILTER_WIN_WIDTH 56
#define FILTER_WIN_HEIGHT 35 #define FILTER_WIN_HEIGHT 35
#define CHANNEL_WIN_WIDTH 41
#define CHANNEL_WIN_HEIGHT 30
struct packet_info; struct packet_info;
struct node_info; struct node_info;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment