Commit c95cba49 authored by Bruno Randolf's avatar Bruno Randolf

use rate index for all rates

parent 68b99df7
...@@ -107,21 +107,8 @@ update_history_win(WINDOW *win) ...@@ -107,21 +107,8 @@ update_history_win(WINDOW *win)
if (hist.retry[i]) if (hist.retry[i])
mvwprintw(win, TYPE_POS+1, col, "r"); mvwprintw(win, TYPE_POS+1, col, "r");
switch (hist.rate[i]/2) { rat = hist.rate[i];
case 54: rat = 12; break;
case 48: rat = 11; break;
case 36: rat = 10; break;
case 24: rat = 9; break;
case 18: rat = 8; break;
case 12: rat = 7; break;
case 11: rat = 6; break;
case 9: rat = 5; break;
case 6: rat = 4; break;
case 5: rat = 3; break;
case 2: rat = 2; break;
case 1: rat = 1; break;
default: rat = 0;
}
wattron(win, A_BOLD); wattron(win, A_BOLD);
wattron(win, BLUE); wattron(win, BLUE);
mvwvline(win, RATE_POS - rat, col, 'x', rat); mvwvline(win, RATE_POS - rat, col, 'x', rat);
......
...@@ -86,7 +86,10 @@ update_statistics_win(WINDOW *win) ...@@ -86,7 +86,10 @@ update_statistics_win(WINDOW *win)
for (i = 1; i < MAX_RATES && line < LINES - 2; i++) { for (i = 1; i < MAX_RATES && line < LINES - 2; i++) {
if (stats.packets_per_rate[i] > 0) { if (stats.packets_per_rate[i] > 0) {
wattron(win, A_BOLD); wattron(win, A_BOLD);
mvwprintw(win, line, 2, "%3dM", i/2); if (i<12)
mvwprintw(win, line, 2, "%3dM", rate_index_to_rate(i)/10);
else
mvwprintw(win, line, 2, "MCS%d", i - 12);
wattroff(win, A_BOLD); wattroff(win, A_BOLD);
mvwprintw(win, line, STAT_PACK_POS, "%8d", mvwprintw(win, line, STAT_PACK_POS, "%8d",
stats.packets_per_rate[i]); stats.packets_per_rate[i]);
......
...@@ -349,3 +349,87 @@ ieee80211_frequency_to_channel(int freq) ...@@ -349,3 +349,87 @@ ieee80211_frequency_to_channel(int freq)
base = 5000; base = 5000;
return (freq - base) / 5; return (freq - base) / 5;
} }
/* rate in 100kbps */
int
rate_to_index(int rate)
{
switch (rate) {
case 540: return 12;
case 480: return 11;
case 360: return 10;
case 240: return 9;
case 180: return 8;
case 120: return 7;
case 110: return 6;
case 90: return 5;
case 60: return 4;
case 50: return 3;
case 20: return 2;
case 10: return 1;
default: return 0;
}
}
/* return rate in 100kbps */
int
rate_index_to_rate(int idx)
{
switch (idx) {
case 12: return 540;
case 11: return 480;
case 10: return 360;
case 9: return 240;
case 8: return 180;
case 7: return 120;
case 6: return 110;
case 5: return 90;
case 4: return 60;
case 3: return 50;
case 2: return 20;
case 1: return 10;
default: return 0;
}
}
/* return rate in 100kbps */
int
mcs_index_to_rate(int mcs, int ht20, int lgi)
{
/* MCS Index, http://en.wikipedia.org/wiki/IEEE_802.11n-2009#Data_rates */
switch (mcs) {
case 0: return ht20 ? (lgi ? 65 : 72) : (lgi ? 135 : 150);
case 1: return ht20 ? (lgi ? 130 : 144) : (lgi ? 270 : 300);
case 2: return ht20 ? (lgi ? 195 : 217) : (lgi ? 405 : 450);
case 3: return ht20 ? (lgi ? 260 : 289) : (lgi ? 540 : 600);
case 4: return ht20 ? (lgi ? 390 : 433) : (lgi ? 810 : 900);
case 5: return ht20 ? (lgi ? 520 : 578) : (lgi ? 1080 : 1200);
case 6: return ht20 ? (lgi ? 585 : 650) : (lgi ? 1215 : 1350);
case 7: return ht20 ? (lgi ? 650 : 722) : (lgi ? 1350 : 1500);
case 8: return ht20 ? (lgi ? 130 : 144) : (lgi ? 270 : 300);
case 9: return ht20 ? (lgi ? 260 : 289) : (lgi ? 540 : 600);
case 10: return ht20 ? (lgi ? 390 : 433) : (lgi ? 810 : 900);
case 11: return ht20 ? (lgi ? 520 : 578) : (lgi ? 1080 : 1200);
case 12: return ht20 ? (lgi ? 780 : 867) : (lgi ? 1620 : 1800);
case 13: return ht20 ? (lgi ? 1040 : 1156) : (lgi ? 2160 : 2400);
case 14: return ht20 ? (lgi ? 1170 : 1300) : (lgi ? 2430 : 2700);
case 15: return ht20 ? (lgi ? 1300 : 1444) : (lgi ? 2700 : 3000);
case 16: return ht20 ? (lgi ? 195 : 217) : (lgi ? 405 : 450);
case 17: return ht20 ? (lgi ? 39 : 433) : (lgi ? 810 : 900);
case 18: return ht20 ? (lgi ? 585 : 650) : (lgi ? 1215 : 1350);
case 19: return ht20 ? (lgi ? 78 : 867) : (lgi ? 1620 : 1800);
case 20: return ht20 ? (lgi ? 1170 : 1300) : (lgi ? 2430 : 2700);
case 21: return ht20 ? (lgi ? 1560 : 1733) : (lgi ? 3240 : 3600);
case 22: return ht20 ? (lgi ? 1755 : 1950) : (lgi ? 3645 : 4050);
case 23: return ht20 ? (lgi ? 1950 : 2167) : (lgi ? 4050 : 4500);
case 24: return ht20 ? (lgi ? 260 : 288) : (lgi ? 540 : 600);
case 25: return ht20 ? (lgi ? 520 : 576) : (lgi ? 1080 : 1200);
case 26: return ht20 ? (lgi ? 780 : 868) : (lgi ? 1620 : 1800);
case 27: return ht20 ? (lgi ? 1040 : 1156) : (lgi ? 2160 : 2400);
case 28: return ht20 ? (lgi ? 1560 : 1732) : (lgi ? 3240 : 3600);
case 29: return ht20 ? (lgi ? 2080 : 2312) : (lgi ? 4320 : 4800);
case 30: return ht20 ? (lgi ? 2340 : 2600) : (lgi ? 4860 : 5400);
case 31: return ht20 ? (lgi ? 2600 : 2888) : (lgi ? 5400 : 6000);
}
return 0;
}
\ No newline at end of file
...@@ -37,4 +37,13 @@ ieee80211_frame_duration(int phymode, size_t len, int rate, int short_preamble, ...@@ -37,4 +37,13 @@ ieee80211_frame_duration(int phymode, size_t len, int rate, int short_preamble,
int int
ieee80211_frequency_to_channel(int freq); ieee80211_frequency_to_channel(int freq);
int
rate_to_index(int rate);
int
rate_index_to_rate(int idx);
int
mcs_index_to_rate(int mcs, int ht20, int lgi);
#endif #endif
...@@ -125,7 +125,7 @@ update_history(struct packet_info* p) ...@@ -125,7 +125,7 @@ update_history(struct packet_info* p)
hist.signal[hist.index] = p->phy_signal; hist.signal[hist.index] = p->phy_signal;
hist.noise[hist.index] = p->phy_noise; hist.noise[hist.index] = p->phy_noise;
hist.rate[hist.index] = p->phy_rate; hist.rate[hist.index] = p->phy_rate_idx;
hist.type[hist.index] = p->wlan_type; hist.type[hist.index] = p->wlan_type;
hist.retry[hist.index] = p->wlan_retry; hist.retry[hist.index] = p->wlan_retry;
...@@ -138,7 +138,7 @@ update_history(struct packet_info* p) ...@@ -138,7 +138,7 @@ update_history(struct packet_info* p)
static void static void
update_statistics(struct packet_info* p) update_statistics(struct packet_info* p)
{ {
if (p->phy_rate == 0) if (p->phy_rate_idx == 0)
return; return;
stats.packets++; stats.packets++;
...@@ -146,16 +146,17 @@ update_statistics(struct packet_info* p) ...@@ -146,16 +146,17 @@ update_statistics(struct packet_info* p)
if (p->wlan_retry) if (p->wlan_retry)
stats.retries++; stats.retries++;
if (p->phy_rate > 0 && p->phy_rate < MAX_RATES) { if (p->phy_rate_idx > 0 && p->phy_rate_idx < MAX_RATES) {
stats.duration += p->pkt_duration; stats.duration += p->pkt_duration;
stats.packets_per_rate[p->phy_rate]++; stats.packets_per_rate[p->phy_rate_idx]++;
stats.bytes_per_rate[p->phy_rate] += p->wlan_len; stats.bytes_per_rate[p->phy_rate_idx] += p->wlan_len;
stats.duration_per_rate[p->phy_rate] += p->pkt_duration; stats.duration_per_rate[p->phy_rate_idx] += p->pkt_duration;
} }
if (p->wlan_type >= 0 && p->wlan_type < MAX_FSTYPE) { if (p->wlan_type >= 0 && p->wlan_type < MAX_FSTYPE) {
stats.packets_per_type[p->wlan_type]++; stats.packets_per_type[p->wlan_type]++;
stats.bytes_per_type[p->wlan_type] += p->wlan_len; stats.bytes_per_type[p->wlan_type] += p->wlan_len;
if (p->phy_rate > 0 && p->phy_rate < MAX_RATES) if (p->phy_rate_idx > 0 && p->phy_rate_idx < MAX_RATES)
stats.duration_per_type[p->wlan_type] += p->pkt_duration; stats.duration_per_type[p->wlan_type] += p->pkt_duration;
} }
} }
...@@ -326,7 +327,7 @@ handle_packet(struct packet_info* p) ...@@ -326,7 +327,7 @@ handle_packet(struct packet_info* p)
p->pkt_duration = ieee80211_frame_duration( p->pkt_duration = ieee80211_frame_duration(
p->phy_flags & PHY_FLAG_MODE_MASK, p->phy_flags & PHY_FLAG_MODE_MASK,
p->wlan_len, p->phy_rate * 5, p->wlan_len, p->phy_rate,
p->phy_flags & PHY_FLAG_SHORTPRE, p->phy_flags & PHY_FLAG_SHORTPRE,
0 /*shortslot*/, p->wlan_type, p->wlan_qos_class, 0 /*shortslot*/, p->wlan_type, p->wlan_qos_class,
p->wlan_retries); p->wlan_retries);
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#define MAX_HISTORY 255 #define MAX_HISTORY 255
#define MAX_CHANNELS 64 #define MAX_CHANNELS 64
#define MAX_ESSID_LEN 32 #define MAX_ESSID_LEN 32
#define MAX_RATES 109 /* in 500kbps steps: 54 * 2 + 1 for array index */ #define MAX_RATES 44 /* 12 legacy rates and 32 MCS */
#define MAX_FSTYPE 0xff #define MAX_FSTYPE 0xff
#define MAX_FILTERMAC 9 #define MAX_FILTERMAC 9
...@@ -115,6 +115,8 @@ struct packet_info { ...@@ -115,6 +115,8 @@ struct packet_info {
int phy_noise; /* noise level (usually dBm) */ int phy_noise; /* noise level (usually dBm) */
unsigned int phy_snr; /* signal to noise ratio */ unsigned int phy_snr; /* signal to noise ratio */
unsigned int phy_rate; /* physical rate * 10 (=in 100kbps) */ unsigned int phy_rate; /* physical rate * 10 (=in 100kbps) */
unsigned char phy_rate_idx; /* MCS index */
unsigned char phy_rate_flags; /* MCS flags */
unsigned int phy_freq; /* frequency from driver */ unsigned int phy_freq; /* frequency from driver */
unsigned char phy_chan; /* channel from driver */ unsigned char phy_chan; /* channel from driver */
unsigned int phy_flags; /* A, B, G, shortpre */ unsigned int phy_flags; /* A, B, G, shortpre */
......
...@@ -90,7 +90,7 @@ struct net_chan_list { ...@@ -90,7 +90,7 @@ struct net_chan_list {
} __attribute__ ((packed)); } __attribute__ ((packed));
#define PKT_INFO_VERSION 1 #define PKT_INFO_VERSION 2
struct net_packet_info { struct net_packet_info {
struct net_header proto; struct net_header proto;
...@@ -138,6 +138,8 @@ struct net_packet_info { ...@@ -138,6 +138,8 @@ struct net_packet_info {
unsigned int olsr_neigh; unsigned int olsr_neigh;
unsigned int olsr_tc; unsigned int olsr_tc;
unsigned char phy_rate_idx;
unsigned char phy_rate_flags;
} __attribute__ ((packed)); } __attribute__ ((packed));
...@@ -176,6 +178,8 @@ net_send_packet(struct packet_info *p) ...@@ -176,6 +178,8 @@ net_send_packet(struct packet_info *p)
np.phy_noise = htole32(p->phy_noise); np.phy_noise = htole32(p->phy_noise);
np.phy_snr = htole32(p->phy_snr); np.phy_snr = htole32(p->phy_snr);
np.phy_rate = htole32(p->phy_rate); np.phy_rate = htole32(p->phy_rate);
np.phy_rate_idx = p->phy_rate_idx;
np.phy_rate_flags = p->phy_rate_flags;
np.phy_freq = htole32(p->phy_freq); np.phy_freq = htole32(p->phy_freq);
np.phy_chan = p->phy_chan; np.phy_chan = p->phy_chan;
np.phy_flags = htole32(p->phy_flags); np.phy_flags = htole32(p->phy_flags);
...@@ -233,6 +237,8 @@ net_receive_packet(unsigned char *buffer, int len) ...@@ -233,6 +237,8 @@ net_receive_packet(unsigned char *buffer, int len)
p.phy_noise = le32toh(np->phy_noise); p.phy_noise = le32toh(np->phy_noise);
p.phy_snr = le32toh(np->phy_snr); p.phy_snr = le32toh(np->phy_snr);
p.phy_rate = le32toh(np->phy_rate); p.phy_rate = le32toh(np->phy_rate);
p.phy_rate_idx = np->phy_rate_idx;
p.phy_rate_flags= np->phy_rate_flags;
p.phy_freq = le32toh(np->phy_freq); p.phy_freq = le32toh(np->phy_freq);
p.phy_chan = np->phy_chan; p.phy_chan = np->phy_chan;
p.phy_flags = le32toh(np->phy_flags); p.phy_flags = le32toh(np->phy_flags);
......
...@@ -141,6 +141,8 @@ parse_prism_header(unsigned char** buf, int len, struct packet_info* p) ...@@ -141,6 +141,8 @@ parse_prism_header(unsigned char** buf, int len, struct packet_info* p)
p->phy_rate = 20; /* 1 * 2 */ p->phy_rate = 20; /* 1 * 2 */
} }
p->phy_rate_idx = rate_to_index(p->phy_rate);
/* guess phy mode */ /* guess phy mode */
if (ph->channel.data > 14) if (ph->channel.data > 14)
p->phy_flags |= PHY_FLAG_A; p->phy_flags |= PHY_FLAG_A;
...@@ -227,7 +229,8 @@ parse_radiotap_header(unsigned char** buf, int len, struct packet_info* p) ...@@ -227,7 +229,8 @@ parse_radiotap_header(unsigned char** buf, int len, struct packet_info* p)
/* we are only interrested in these: */ /* we are only interrested in these: */
case IEEE80211_RADIOTAP_RATE: case IEEE80211_RADIOTAP_RATE:
DEBUG("[rate %0x]", *b); DEBUG("[rate %0x]", *b);
p->phy_rate = (*b)*10; p->phy_rate = (*b)*5; /* rate is in 500kbps */
p->phy_rate_idx = rate_to_index(p->phy_rate);
b++; b++;
break; break;
case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
...@@ -305,41 +308,11 @@ parse_radiotap_header(unsigned char** buf, int len, struct packet_info* p) ...@@ -305,41 +308,11 @@ parse_radiotap_header(unsigned char** buf, int len, struct packet_info* p)
} else } else
lgi = 1; /* assume long GI if not present */ lgi = 1; /* assume long GI if not present */
/* MCS Index, http://en.wikipedia.org/wiki/IEEE_802.11n-2009#Data_rates */ p->phy_rate_idx = 12 + *b;
switch (*b) { p->phy_rate_flags = flags;
case 0: p->phy_rate = ht20 ? (lgi ? 65 : 72) : (lgi ? 135 : 150); break;
case 1: p->phy_rate = ht20 ? (lgi ? 130 : 144) : (lgi ? 270 : 300); break; p->phy_rate = mcs_index_to_rate(*b, ht20, lgi);
case 2: p->phy_rate = ht20 ? (lgi ? 195 : 217) : (lgi ? 405 : 450); break;
case 3: p->phy_rate = ht20 ? (lgi ? 260 : 289) : (lgi ? 540 : 600); break;
case 4: p->phy_rate = ht20 ? (lgi ? 390 : 433) : (lgi ? 810 : 900); break;
case 5: p->phy_rate = ht20 ? (lgi ? 520 : 578) : (lgi ? 1080 : 1200); break;
case 6: p->phy_rate = ht20 ? (lgi ? 585 : 650) : (lgi ? 1215 : 1350); break;
case 7: p->phy_rate = ht20 ? (lgi ? 650 : 722) : (lgi ? 1350 : 1500); break;
case 8: p->phy_rate = ht20 ? (lgi ? 130 : 144) : (lgi ? 270 : 300); break;
case 9: p->phy_rate = ht20 ? (lgi ? 260 : 289) : (lgi ? 540 : 600); break;
case 10: p->phy_rate = ht20 ? (lgi ? 390 : 433) : (lgi ? 810 : 900); break;
case 11: p->phy_rate = ht20 ? (lgi ? 520 : 578) : (lgi ? 1080 : 1200); break;
case 12: p->phy_rate = ht20 ? (lgi ? 780 : 867) : (lgi ? 1620 : 1800); break;
case 13: p->phy_rate = ht20 ? (lgi ? 1040 : 1156) : (lgi ? 2160 : 2400); break;
case 14: p->phy_rate = ht20 ? (lgi ? 1170 : 1300) : (lgi ? 2430 : 2700); break;
case 15: p->phy_rate = ht20 ? (lgi ? 1300 : 1444) : (lgi ? 2700 : 3000); break;
case 16: p->phy_rate = ht20 ? (lgi ? 195 : 217) : (lgi ? 405 : 450); break;
case 17: p->phy_rate = ht20 ? (lgi ? 39 : 433) : (lgi ? 810 : 900); break;
case 18: p->phy_rate = ht20 ? (lgi ? 585 : 650) : (lgi ? 1215 : 1350); break;
case 19: p->phy_rate = ht20 ? (lgi ? 78 : 867) : (lgi ? 1620 : 1800); break;
case 20: p->phy_rate = ht20 ? (lgi ? 1170 : 1300) : (lgi ? 2430 : 2700); break;
case 21: p->phy_rate = ht20 ? (lgi ? 1560 : 1733) : (lgi ? 3240 : 3600); break;
case 22: p->phy_rate = ht20 ? (lgi ? 1755 : 1950) : (lgi ? 3645 : 4050); break;
case 23: p->phy_rate = ht20 ? (lgi ? 1950 : 2167) : (lgi ? 4050 : 4500); break;
case 24: p->phy_rate = ht20 ? (lgi ? 260 : 288) : (lgi ? 540 : 600); break;
case 25: p->phy_rate = ht20 ? (lgi ? 520 : 576) : (lgi ? 1080 : 1200); break;
case 26: p->phy_rate = ht20 ? (lgi ? 780 : 868) : (lgi ? 1620 : 1800); break;
case 27: p->phy_rate = ht20 ? (lgi ? 1040 : 1156) : (lgi ? 2160 : 2400); break;
case 28: p->phy_rate = ht20 ? (lgi ? 1560 : 1732) : (lgi ? 3240 : 3600); break;
case 29: p->phy_rate = ht20 ? (lgi ? 2080 : 2312) : (lgi ? 4320 : 4800); break;
case 30: p->phy_rate = ht20 ? (lgi ? 2340 : 2600) : (lgi ? 4860 : 5400); break;
case 31: p->phy_rate = ht20 ? (lgi ? 2600 : 2888) : (lgi ? 5400 : 6000); break;
}
DEBUG(" RATE %d ", p->phy_rate); DEBUG(" RATE %d ", p->phy_rate);
b++; b++;
break; break;
...@@ -381,6 +354,7 @@ parse_radiotap_header(unsigned char** buf, int len, struct packet_info* p) ...@@ -381,6 +354,7 @@ parse_radiotap_header(unsigned char** buf, int len, struct packet_info* p)
} }
DEBUG("\nrate: %.2f\n", (float)p->phy_rate/10); DEBUG("\nrate: %.2f\n", (float)p->phy_rate/10);
DEBUG("rate_idx: %d\n", p->phy_rate_idx);
DEBUG("signal: %d\n", p->phy_signal); DEBUG("signal: %d\n", p->phy_signal);
DEBUG("noise: %d\n", p->phy_noise); DEBUG("noise: %d\n", p->phy_noise);
DEBUG("snr: %d\n", p->phy_snr); DEBUG("snr: %d\n", p->phy_snr);
......
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