Commit 549ca604 authored by Bruno Randolf's avatar Bruno Randolf

Rework packet filters by using 802.11 frame types and subtypes

Use a filter map of 16 bit for subtypes. E.g. Beacon is MGMT frame subtype
8 (binary 1000), so when bit 8 of filter_stype[0] is set we will see beacons.

That way we can define the filters more exactly.

TODO: What's missing is to redefine the characters used for each frame type so
they are unique and can be selected in the filter window.
parent 022488eb
......@@ -24,6 +24,7 @@
#include "main.h"
#include "util.h"
#include "wlan_util.h"
#include "control.h"
struct conf_option {
......@@ -204,34 +205,26 @@ static int conf_filter_mode(const char* value) {
}
static int conf_filter_pkt(const char* value) {
if (conf.filter_pkt == PKT_TYPE_ALL)
int t, i;
if (conf.filter_pkt == PKT_TYPE_ALL) {
conf.filter_pkt = 0;
if (strcmp(value, "ALL") == 0)
conf.filter_stype[_FC_TYPE_MGMT] = 0;
conf.filter_stype[_FC_TYPE_CTRL] = 0;
conf.filter_stype[_FC_TYPE_DATA] = 0;
}
if (strcmp(value, "ALL") == 0) {
conf.filter_pkt = PKT_TYPE_ALL;
conf.filter_stype[_FC_TYPE_MGMT] = 0xffff;
conf.filter_stype[_FC_TYPE_CTRL] = 0xffff;
conf.filter_stype[_FC_TYPE_DATA] = 0xffff;
}
else if (strcmp(value, "CTRL") == 0 || strcmp(value, "CONTROL") == 0)
conf.filter_pkt |= PKT_TYPE_CTRL | PKT_TYPE_ALL_CTRL;
conf.filter_stype[_FC_TYPE_CTRL] = 0xffff;
else if (strcmp(value, "MGMT") == 0 || strcmp(value, "MANAGEMENT") == 0)
conf.filter_pkt |= PKT_TYPE_MGMT | PKT_TYPE_ALL_MGMT;
conf.filter_stype[_FC_TYPE_MGMT] = 0xffff;
else if (strcmp(value, "DATA") == 0)
conf.filter_pkt |= PKT_TYPE_DATA | PKT_TYPE_ALL_DATA;
else if (strcmp(value, "BADFCS") == 0)
conf.filter_pkt |= PKT_TYPE_BADFCS;
else if (strcmp(value, "BEACON") == 0)
conf.filter_pkt |= PKT_TYPE_BEACON;
else if (strcmp(value, "PROBE") == 0)
conf.filter_pkt |= PKT_TYPE_PROBE;
else if (strcmp(value, "ASSOC") == 0)
conf.filter_pkt |= PKT_TYPE_ASSOC;
else if (strcmp(value, "AUTH") == 0)
conf.filter_pkt |= PKT_TYPE_AUTH;
else if (strcmp(value, "RTS") == 0)
conf.filter_pkt |= PKT_TYPE_RTSCTS;
else if (strcmp(value, "ACK") == 0)
conf.filter_pkt |= PKT_TYPE_ACK;
else if (strcmp(value, "NULL") == 0)
conf.filter_pkt |= PKT_TYPE_NULL;
else if (strcmp(value, "QDATA") == 0)
conf.filter_pkt |= PKT_TYPE_QDATA;
conf.filter_stype[_FC_TYPE_DATA] = 0xffff;
else if (strcmp(value, "ARP") == 0)
conf.filter_pkt |= PKT_TYPE_ARP;
else if (strcmp(value, "IP") == 0)
......@@ -248,13 +241,15 @@ static int conf_filter_pkt(const char* value) {
conf.filter_pkt |= PKT_TYPE_BATMAN;
else if (strcmp(optarg, "MESHZ") == 0)
conf.filter_pkt |= PKT_TYPE_MESHZ;
/* if one of the individual subtype frames is selected we enable the general frame type */
if (conf.filter_pkt & PKT_TYPE_ALL_MGMT)
conf.filter_pkt |= PKT_TYPE_MGMT;
if (conf.filter_pkt & PKT_TYPE_ALL_CTRL)
conf.filter_pkt |= PKT_TYPE_CTRL;
if (conf.filter_pkt & PKT_TYPE_ALL_DATA)
conf.filter_pkt |= PKT_TYPE_DATA;
for (t = 0; t < 3; t++) {
for (i = 0; i < 16; i++) {
if (strcasecmp(pkt_names[t][i].name, value) == 0) {
conf.filter_stype[t] |= (1 << i);
return 1;
}
}
}
return 1;
}
......
......@@ -24,70 +24,78 @@
#include "display.h"
#include "main.h"
#include "util.h"
#include "wlan_util.h"
#include "wlan80211.h"
#include "network.h"
#define CHECKED(_x) (conf.filter_pkt & (_x)) ? '*' : ' '
#define CHECKED_PKT(_x) (conf.filter_pkt & (_x)) ? '*' : ' '
#define CHECKED_STYPE(_type, _x) (conf.filter_stype[_type] & (1 << _x)) ? '*' : ' '
#define CHECKED_STYPE_MASK(_type, _x) (conf.filter_stype[_type] & _x) ? '*' : ' '
#define CHECKED_MODE(_x) (conf.filter_mode & (_x)) ? '*' : ' '
#define CHECK_ETHER(_mac) MAC_NOT_EMPTY(_mac) ? '*' : ' '
#define CHECK_FILTER_EN(_i) conf.filtermac_enabled[_i] ? '*' : ' '
#define MAC_COL 30
#define FILTER_MAX 26
#define MAC_COL 2
#define MODE_COL 30
#define SECOND_ROW 19
#define THIRD_ROW 23
void
update_filter_win(WINDOW *win)
{
int l, i;
int l, i, t, col = 2;
box(win, 0 , 0);
print_centered(win, 0, 57, " Edit Filters ");
l = 2;
wattron(win, get_packet_type_color(WLAN_FRAME_TYPE_MGMT));
wattron(win, A_BOLD);
mvwprintw(win, l++, 2, "m: [%c] MANAGEMENT Frames", CHECKED(PKT_TYPE_MGMT));
wattroff(win, A_BOLD);
mvwprintw(win, l++, 2, "b: [%c] Beacons", CHECKED(PKT_TYPE_BEACON));
mvwprintw(win, l++, 2, "p: [%c] Probe Req/Resp", CHECKED(PKT_TYPE_PROBE));
mvwprintw(win, l++, 2, "a: [%c] Association", CHECKED(PKT_TYPE_ASSOC));
mvwprintw(win, l++, 2, "u: [%c] Authentication", CHECKED(PKT_TYPE_AUTH));
l++;
wattron(win, get_packet_type_color(WLAN_FRAME_TYPE_CTRL));
wattron(win, A_BOLD);
mvwprintw(win, l++, 2, "c: [%c] CONTROL Frames", CHECKED(PKT_TYPE_CTRL));
wattroff(win, A_BOLD);
mvwprintw(win, l++, 2, "r: [%c] CTS/RTS", CHECKED(PKT_TYPE_RTSCTS));
mvwprintw(win, l++, 2, "k: [%c] ACK", CHECKED(PKT_TYPE_ACK));
l++;
wattron(win, get_packet_type_color(WLAN_FRAME_TYPE_DATA));
for (t = 0; t < 3; t++) {
l = 2;
wattron(win, get_packet_type_color(_WLAN_FRAME_FC(t, 0)));
wattron(win, A_BOLD);
if (t == 0)
mvwprintw(win, l++, col, "m: [%c] Management", CHECKED_STYPE_MASK(t, 0xffff));
else if (t == 1)
mvwprintw(win, l++, col, "c: [%c] Control", CHECKED_STYPE_MASK(t, 0xffff));
else
mvwprintw(win, l++, col, "d: [%c] Data", CHECKED_STYPE_MASK(t, 0xffff));
wattroff(win, A_BOLD);
for (i = 0; i < 16; i++) {
if (pkt_names[t][i].c != '-')
mvwprintw(win, l++, col, "%c: [%c] %s", pkt_names[t][i].c,
CHECKED_STYPE(t, i), pkt_names[t][i].name);
}
col += 19;
}
l = 14;
wattron(win, A_BOLD);
mvwprintw(win, l++, 2, "d: [%c] DATA Frames", CHECKED(PKT_TYPE_DATA));
wattron(win, WHITE);
mvwprintw(win, l++, 21, "General");
wattroff(win, A_BOLD);
mvwprintw(win, l++, 2, "Q: [%c] QoS Data", CHECKED(PKT_TYPE_QDATA));
mvwprintw(win, l++, 2, "n: [%c] Null Data", CHECKED(PKT_TYPE_NULL));
mvwprintw(win, l++, 2, "R: [%c] ARP", CHECKED(PKT_TYPE_ARP));
mvwprintw(win, l++, 2, "P: [%c] ICMP/PING", CHECKED(PKT_TYPE_ICMP));
mvwprintw(win, l++, 2, "i: [%c] IP", CHECKED(PKT_TYPE_IP));
mvwprintw(win, l++, 2, "U: [%c] UDP", CHECKED(PKT_TYPE_UDP));
mvwprintw(win, l++, 2, "T: [%c] TCP", CHECKED(PKT_TYPE_TCP));
mvwprintw(win, l++, 2, "o: [%c] OLSR", CHECKED(PKT_TYPE_OLSR));
mvwprintw(win, l++, 2, "B: [%c] BATMAN", CHECKED(PKT_TYPE_BATMAN));
mvwprintw(win, l++, 2, "M: [%c] MeshCruzer", CHECKED(PKT_TYPE_MESHZ));
l++;
wattron(win, RED);
mvwprintw(win, l++, 2, "*: [%c] Bad FCS", CHECKED(PKT_TYPE_BADFCS));
mvwprintw(win, l++, 21, "*: [%c] Bad FCS", CHECKED_PKT(PKT_TYPE_BADFCS));
wattroff(win, RED);
l = 2;
wattron(win, WHITE);
wattron(win, A_BOLD);
mvwprintw(win, l++, MAC_COL, "BSSID");
mvwprintw(win, l++, 21, "0: [%c] All Off", conf.filter_off ? '*' : ' ' );
wattroff(win, A_BOLD);
mvwprintw(win, l++, MAC_COL, "s: [%c] %s",
CHECK_ETHER(conf.filterbssid), ether_sprintf(conf.filterbssid));
l++;
l = SECOND_ROW-1;
wattron(win, A_BOLD);
mvwprintw(win, l++, 2, "Higher Level Protocols");
wattroff(win, A_BOLD);
wattron(win, WHITE);
mvwprintw(win, l++, 2, "R: [%c] ARP", CHECKED_PKT(PKT_TYPE_ARP));
mvwprintw(win, l++, 2, "P: [%c] ICMP/PING", CHECKED_PKT(PKT_TYPE_ICMP));
mvwprintw(win, l++, 2, "i: [%c] IP", CHECKED_PKT(PKT_TYPE_IP));
l = SECOND_ROW;
mvwprintw(win, l++, 21, "U: [%c] UDP", CHECKED_PKT(PKT_TYPE_UDP));
mvwprintw(win, l++, 21, "T: [%c] TCP", CHECKED_PKT(PKT_TYPE_TCP));
l = SECOND_ROW;
mvwprintw(win, l++, 40, "o: [%c] OLSR", CHECKED_PKT(PKT_TYPE_OLSR));
mvwprintw(win, l++, 40, "B: [%c] BATMAN", CHECKED_PKT(PKT_TYPE_BATMAN));
mvwprintw(win, l++, 40, "M: [%c] Meshz", CHECKED_PKT(PKT_TYPE_MESHZ));
l = THIRD_ROW;
wattron(win, A_BOLD);
mvwprintw(win, l++, MAC_COL, "Source MAC Addresses");
wattroff(win, A_BOLD);
......@@ -97,23 +105,27 @@ update_filter_win(WINDOW *win)
CHECK_FILTER_EN(i), ether_sprintf(conf.filtermac[i]));
}
l++;
l = THIRD_ROW;
wattron(win, A_BOLD);
mvwprintw(win, l++, MAC_COL, "Mode");
mvwprintw(win, l++, MODE_COL, "BSSID");
wattroff(win, A_BOLD);
mvwprintw(win, l++, MAC_COL, "A: [%c] Access Point", CHECKED_MODE(WLAN_MODE_AP));
mvwprintw(win, l++, MAC_COL, "S: [%c] Station", CHECKED_MODE(WLAN_MODE_STA));
mvwprintw(win, l++, MAC_COL, "I: [%c] IBSS (Ad-hoc)", CHECKED_MODE(WLAN_MODE_IBSS));
mvwprintw(win, l++, MAC_COL, "O: [%c] Probe Request", CHECKED_MODE(WLAN_MODE_PROBE));
mvwprintw(win, l++, MAC_COL, "W: [%c] WDS/4ADDR", CHECKED_MODE(WLAN_MODE_4ADDR));
mvwprintw(win, l++, MAC_COL, "N: [%c] Unknown", CHECKED_MODE(WLAN_MODE_UNKNOWN));
mvwprintw(win, l++, MODE_COL, "s: [%c] %s",
CHECK_ETHER(conf.filterbssid), ether_sprintf(conf.filterbssid));
l++;
wattron(win, A_BOLD);
mvwprintw(win, l++, MAC_COL, "0: [%c] All Filters Off", conf.filter_off ? '*' : ' ' );
mvwprintw(win, l++, MODE_COL, "Mode");
wattroff(win, A_BOLD);
mvwprintw(win, l++, MODE_COL, "A: [%c] Access Point", CHECKED_MODE(WLAN_MODE_AP));
mvwprintw(win, l++, MODE_COL, "S: [%c] Station", CHECKED_MODE(WLAN_MODE_STA));
mvwprintw(win, l++, MODE_COL, "I: [%c] IBSS (Ad-hoc)", CHECKED_MODE(WLAN_MODE_IBSS));
mvwprintw(win, l++, MODE_COL, "O: [%c] Probe Request", CHECKED_MODE(WLAN_MODE_PROBE));
mvwprintw(win, l++, MODE_COL, "W: [%c] WDS/4ADDR", CHECKED_MODE(WLAN_MODE_4ADDR));
mvwprintw(win, l++, MODE_COL, "N: [%c] Unknown", CHECKED_MODE(WLAN_MODE_UNKNOWN));
print_centered(win, FILTER_MAX, 57, "[ Press key or ENTER ]");
wattroff(win, WHITE);
print_centered(win, ++l, FILTER_WIN_WIDTH, "[ Press key or ENTER ]");
wrefresh(win);
}
......@@ -122,38 +134,12 @@ int
filter_input(WINDOW *win, int c)
{
char buf[18];
int i;
int i, t;
switch (c) {
case 'm':
TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_MGMT);
if (conf.filter_pkt & PKT_TYPE_MGMT)
conf.filter_pkt |= PKT_TYPE_ALL_MGMT;
else
conf.filter_pkt &= ~PKT_TYPE_ALL_MGMT;
break;
case 'b': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_BEACON); break;
case 'p': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_PROBE); break;
case 'a': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ASSOC); break;
case 'u': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_AUTH); break;
case 'c':
TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_CTRL);
if (conf.filter_pkt & PKT_TYPE_CTRL)
conf.filter_pkt |= PKT_TYPE_ALL_CTRL;
else
conf.filter_pkt &= ~PKT_TYPE_ALL_CTRL;
break;
case 'r': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_RTSCTS); break;
case 'k': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ACK); break;
case 'd':
TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_DATA);
if (conf.filter_pkt & PKT_TYPE_DATA)
conf.filter_pkt |= PKT_TYPE_ALL_DATA;
else
conf.filter_pkt &= ~PKT_TYPE_ALL_DATA;
break;
case 'Q': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_QDATA); break;
case 'n': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_NULL); break;
case 'm': TOGGLE_BITSET(conf.filter_stype[_FC_TYPE_MGMT], 0xffff, u_int16_t); break;
case 'c': TOGGLE_BITSET(conf.filter_stype[_FC_TYPE_CTRL], 0xffff, u_int16_t); break;
case 'd': TOGGLE_BITSET(conf.filter_stype[_FC_TYPE_DATA], 0xffff, u_int16_t); break;
case 'R': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ARP); break;
case 'P': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_ICMP); break;
case 'i': TOGGLE_BIT(conf.filter_pkt, PKT_TYPE_IP); break;
......@@ -173,10 +159,10 @@ filter_input(WINDOW *win, int c)
case 's':
echo();
print_centered(win, FILTER_MAX, 57,
print_centered(win, FILTER_WIN_HEIGHT-1, FILTER_WIN_WIDTH,
"[ Enter new BSSID and ENTER ]");
mvwprintw(win, 3, MAC_COL + 4, ">");
mvwgetnstr(win, 3, MAC_COL + 7, buf, 17);
mvwprintw(win, THIRD_ROW + 1, MODE_COL + 4, ">");
mvwgetnstr(win, THIRD_ROW + 1, MODE_COL + 7, buf, 17);
noecho();
convert_string_to_mac(buf, conf.filterbssid);
break;
......@@ -188,10 +174,10 @@ filter_input(WINDOW *win, int c)
}
else {
echo();
print_centered(win, FILTER_MAX, 57,
print_centered(win, FILTER_WIN_HEIGHT-1, FILTER_WIN_WIDTH,
"[ Enter new MAC %d and ENTER ]", i+1);
mvwprintw(win, 6 + i, MAC_COL + 4, ">");
mvwgetnstr(win, 6 + i, MAC_COL + 7, buf, 17);
mvwprintw(win, THIRD_ROW + 1 + i, MAC_COL + 4, ">");
mvwgetnstr(win, THIRD_ROW + 1 + i, MAC_COL + 7, buf, 17);
noecho();
/* just enable old MAC if user pressed return only */
if (*buf == '\0' && MAC_NOT_EMPTY(conf.filtermac[i]))
......@@ -209,18 +195,18 @@ filter_input(WINDOW *win, int c)
break;
default:
return 0;
for (t = 0; t < 3; t++) {
for (i = 0; i < 16; i++) {
if (pkt_names[t][i].c == c) {
TOGGLE_BIT(conf.filter_stype[t], (1 << i));
goto out;
}
}
}
return 0; // not found
}
/* convenience: */
/* if one of the individual subtype frames is selected we enable the general frame type */
if (conf.filter_pkt & PKT_TYPE_ALL_MGMT)
conf.filter_pkt |= PKT_TYPE_MGMT;
if (conf.filter_pkt & PKT_TYPE_ALL_CTRL)
conf.filter_pkt |= PKT_TYPE_CTRL;
if (conf.filter_pkt & PKT_TYPE_ALL_DATA)
conf.filter_pkt |= PKT_TYPE_DATA;
out:
/* recalculate filter flag */
conf.do_macfilter = 0;
for (i = 0; i < MAX_FILTERMAC; i++) {
......
......@@ -297,7 +297,8 @@ show_conf_window(int key)
}
if (conf_win == NULL) {
if (key == 'f') {
conf_win = newwin(27, 57, LINES/2-13, COLS/2-28);
conf_win = newwin(FILTER_WIN_HEIGHT, FILTER_WIN_WIDTH,
LINES/2-13, COLS/2-28);
update_filter_win(conf_win);
}
else if (key == 'c') {
......
......@@ -37,6 +37,9 @@
#define ALLYELLOW COLOR_PAIR(13)
#define WHITEONRED COLOR_PAIR(14)
#define FILTER_WIN_WIDTH 56
#define FILTER_WIN_HEIGHT 35
struct packet_info;
struct node_info;
......
......@@ -218,7 +218,7 @@ update_spectrum_durations(void)
}
static void
static void
write_to_file(struct packet_info* p)
{
char buf[40];
......@@ -264,6 +264,12 @@ filter_packet(struct packet_info* p)
if (p->phy_flags & PHY_FLAG_BADFCS)
return 0;
/* filter by WLAN frame type */
if (!(conf.filter_stype[WLAN_FRAME_TYPE(p->wlan_type)] & (1 << WLAN_FRAME_STYPE(p->wlan_type)))) {
stats.filtered_packets++;
return 1;
}
if (conf.filter_mode != WLAN_MODE_ALL && ((p->wlan_mode & ~conf.filter_mode) || p->wlan_mode == 0)) {
/* this also filters out packets where we cannot associate a mode (ACK, RTS/CTS) */
stats.filtered_packets++;
......
......@@ -53,36 +53,20 @@
#define MAX_NODE_NAME_STRLEN 18
#define MAX_NODE_NAMES 64
/* packet types we actually care about, e.g filter */
#define PKT_TYPE_CTRL 0x000001
#define PKT_TYPE_MGMT 0x000002
#define PKT_TYPE_DATA 0x000004
#define PKT_TYPE_BADFCS 0x000008
#define PKT_TYPE_BEACON 0x000010
#define PKT_TYPE_PROBE 0x000020
#define PKT_TYPE_ASSOC 0x000040
#define PKT_TYPE_AUTH 0x000080
#define PKT_TYPE_RTSCTS 0x000100
#define PKT_TYPE_ACK 0x000200
#define PKT_TYPE_NULL 0x000400
#define PKT_TYPE_QDATA 0x000800
#define PKT_TYPE_ARP 0x001000
#define PKT_TYPE_IP 0x002000
#define PKT_TYPE_ICMP 0x004000
#define PKT_TYPE_UDP 0x008000
#define PKT_TYPE_TCP 0x010000
#define PKT_TYPE_OLSR 0x020000
#define PKT_TYPE_BATMAN 0x040000
#define PKT_TYPE_MESHZ 0x080000
#define PKT_TYPE_ALL_MGMT (PKT_TYPE_BEACON | PKT_TYPE_PROBE | PKT_TYPE_ASSOC | PKT_TYPE_AUTH)
#define PKT_TYPE_ALL_CTRL (PKT_TYPE_RTSCTS | PKT_TYPE_ACK)
#define PKT_TYPE_ALL_DATA (PKT_TYPE_NULL | PKT_TYPE_QDATA | PKT_TYPE_ARP | PKT_TYPE_ICMP | PKT_TYPE_IP | \
PKT_TYPE_UDP | PKT_TYPE_TCP | PKT_TYPE_OLSR | PKT_TYPE_BATMAN | PKT_TYPE_MESHZ)
#define PKT_TYPE_ALL (PKT_TYPE_CTRL | PKT_TYPE_MGMT | PKT_TYPE_DATA | PKT_TYPE_ALL_MGMT | PKT_TYPE_ALL_CTRL | PKT_TYPE_ALL_DATA | PKT_TYPE_BADFCS)
/* higher level packet types */
#define PKT_TYPE_BADFCS 0x000001
#define PKT_TYPE_ARP 0x000002
#define PKT_TYPE_IP 0x000004
#define PKT_TYPE_ICMP 0x000008
#define PKT_TYPE_UDP 0x000010
#define PKT_TYPE_TCP 0x000020
#define PKT_TYPE_OLSR 0x000040
#define PKT_TYPE_BATMAN 0x000080
#define PKT_TYPE_MESHZ 0x000100
#define PKT_TYPE_ALL (PKT_TYPE_ARP | PKT_TYPE_IP | PKT_TYPE_ICMP | \
PKT_TYPE_UDP | PKT_TYPE_TCP | \
PKT_TYPE_OLSR | PKT_TYPE_BATMAN | PKT_TYPE_MESHZ)
#define WLAN_MODE_AP 0x01
#define WLAN_MODE_IBSS 0x02
......@@ -318,6 +302,7 @@ struct config {
char filtermac_enabled[MAX_FILTERMAC];
unsigned char filterbssid[MAC_LEN];
unsigned int filter_pkt;
u_int16_t filter_stype[3]; /* one for MGMT, CTRL, DATA */
unsigned int filter_mode;
unsigned int filter_off:1,
do_change_channel:1,
......
......@@ -316,7 +316,6 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
DEBUG("%s\n", get_packet_type_name(fc));
if (WLAN_FRAME_IS_DATA(fc)) {
p->pkt_types |= PKT_TYPE_DATA;
hdrlen = 24;
if (WLAN_FRAME_IS_QOS(fc)) {
......@@ -376,8 +375,6 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
p->wlan_retry = 1;
} else if (WLAN_FRAME_IS_CTRL(fc)) {
p->pkt_types |= PKT_TYPE_CTRL;
if (p->wlan_type == WLAN_FRAME_CTS ||
p->wlan_type == WLAN_FRAME_ACK)
hdrlen = 10;
......@@ -388,8 +385,6 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
return -1;
} else if (WLAN_FRAME_IS_MGMT(fc)) {
p->pkt_types |= PKT_TYPE_MGMT;
hdrlen = 24;
if (fc & WLAN_FRAME_FC_ORDER)
hdrlen += 4;
......@@ -414,17 +409,14 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
switch (p->wlan_type) {
case WLAN_FRAME_NULL:
p->pkt_types |= PKT_TYPE_NULL;
break;
case WLAN_FRAME_QDATA:
p->pkt_types |= PKT_TYPE_QDATA;
p->wlan_qos_class = le16toh(wh->u.qos) & WLAN_FRAME_QOS_TID_MASK;
DEBUG("***QDATA %x\n", p->wlan_qos_class);
break;
case WLAN_FRAME_RTS:
p->pkt_types |= PKT_TYPE_RTSCTS;
p->wlan_nav = le16toh(wh->duration);
DEBUG("RTS NAV %d\n", p->wlan_nav);
ra = wh->addr1;
......@@ -432,14 +424,12 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
break;
case WLAN_FRAME_CTS:
p->pkt_types |= PKT_TYPE_RTSCTS;
p->wlan_nav = le16toh(wh->duration);
DEBUG("CTS NAV %d\n", p->wlan_nav);
ra = wh->addr1;
break;
case WLAN_FRAME_ACK:
p->pkt_types |= PKT_TYPE_ACK;
p->wlan_nav = le16toh(wh->duration);
DEBUG("ACK NAV %d\n", p->wlan_nav);
ra = wh->addr1;
......@@ -460,7 +450,6 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
case WLAN_FRAME_BLKACK:
case WLAN_FRAME_BLKACK_REQ:
p->pkt_types |= PKT_TYPE_ACK;
p->wlan_nav = le16toh(wh->duration);
ra = wh->addr1;
ta = wh->addr2;
......@@ -468,10 +457,7 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
case WLAN_FRAME_BEACON:
case WLAN_FRAME_PROBE_RESP:
if (p->wlan_type == WLAN_FRAME_BEACON)
p->pkt_types |= PKT_TYPE_BEACON;
else
p->pkt_types |= PKT_TYPE_PROBE;
;
struct wlan_frame_beacon* bc = (struct wlan_frame_beacon*)(*buf + hdrlen);
p->wlan_tsf = le64toh(bc->tsf);
p->wlan_bintval = le16toh(bc->bintval);
......@@ -491,7 +477,6 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
break;
case WLAN_FRAME_PROBE_REQ:
p->pkt_types |= PKT_TYPE_PROBE;
wlan_parse_information_elements((*buf + hdrlen),
len - hdrlen - 4 /* FCS */, p);
p->wlan_mode = WLAN_MODE_PROBE;
......@@ -502,7 +487,6 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
case WLAN_FRAME_REASSOC_REQ:
case WLAN_FRAME_REASSOC_RESP:
case WLAN_FRAME_DISASSOC:
p->pkt_types |= PKT_TYPE_ASSOC;
break;
case WLAN_FRAME_AUTH:
......@@ -510,7 +494,6 @@ parse_80211_header(unsigned char** buf, int len, struct packet_info* p)
p->wlan_wep = 1;
/* no break */
case WLAN_FRAME_DEAUTH:
p->pkt_types |= PKT_TYPE_AUTH;
break;
case WLAN_FRAME_ACTION:
......
......@@ -24,7 +24,8 @@
/* lists of packet names */
static struct pkt_name mgmt_names[] = {
struct pkt_name pkt_names[3][16] = {
{
{ 'a', "ASOCRQ", WLAN_FRAME_ASSOC_REQ, "Association request" },
{ 'A', "ASOCRP", WLAN_FRAME_ASSOC_RESP, "Association response" },
{ 'a', "REASRQ", WLAN_FRAME_REASSOC_REQ, "Reassociation request" },
......@@ -40,9 +41,15 @@ static struct pkt_name mgmt_names[] = {
{ 'U', "DEAUTH", WLAN_FRAME_DEAUTH, "Deauthentication" },
{ 'C', "ACTION", WLAN_FRAME_ACTION, "Action" },
{ 'c', "ACTNOA", WLAN_FRAME_ACTION_NOACK, "Action No Ack" },
};
static struct pkt_name ctrl_names[] = {
{ '-', "-RESV-", 0x0070, "RESERVED" },
}, {
{ '-', "-RESV-", 0x0004, "RESERVED" },
{ '-', "-RESV-", 0x0014, "RESERVED" },
{ '-', "-RESV-", 0x0024, "RESERVED" },
{ '-', "-RESV-", 0x0034, "RESERVED" },
{ '-', "-RESV-", 0x0044, "RESERVED" },
{ '-', "-RESV-", 0x0054, "RESERVED" },
{ '-', "-RESV-", 0x0064, "RESERVED" },
{ 'w', "CTWRAP", WLAN_FRAME_CTRL_WRAP, "Control Wrapper" },
{ 'b', "BACKRQ", WLAN_FRAME_BLKACK_REQ, "Block Ack Request" },
{ 'B', "BACK", WLAN_FRAME_BLKACK, "Block Ack" },
......@@ -52,9 +59,7 @@ static struct pkt_name ctrl_names[] = {
{ 'K', "ACK", WLAN_FRAME_ACK, "ACK" },
{ 'f', "CFEND", WLAN_FRAME_CF_END, "CF-End" },
{ 'f', "CFENDK", WLAN_FRAME_CF_END_ACK, "CF-End + CF-Ack" },
};
static struct pkt_name data_names[] = {
}, {
{ 'D', "DATA", WLAN_FRAME_DATA, "Data" },
{ 'F', "DCFACK", WLAN_FRAME_DATA_CF_ACK, "Data + CF-Ack" },
{ 'F', "DCFPLL", WLAN_FRAME_DATA_CF_POLL, "Data + CF-Poll" },
......@@ -71,42 +76,24 @@ static struct pkt_name data_names[] = {
{ '-', "-RESV-", 0x00D0, "RESERVED" },
{ 'f', "QCFPLL", WLAN_FRAME_QOS_CF_POLL, "QoS CF-Poll (no data)" },
{ 'f', "QCFKPL", WLAN_FRAME_QOS_CF_ACKPOLL, "QoS CF-Ack + CF-Poll (no data)" },
};
} };
static struct pkt_name unknow = { '?', "UNKNOW", 0 , "Unknown" };
static struct pkt_name badfcs = { '*', "BADFCS", 0 , "Bad FCS" };
#define DATA_NAME_INDEX(_i) (((_i) & WLAN_FRAME_FC_STYPE_MASK)>>4)
#define MGMT_NAME_INDEX(_i) (((_i) & WLAN_FRAME_FC_STYPE_MASK)>>4)
#define CTRL_NAME_INDEX(_i) ((((_i) & WLAN_FRAME_FC_STYPE_MASK)>>4)-7)
#define CTRL_NAME_INDEX(_i) ((((_i) & WLAN_FRAME_FC_STYPE_MASK)>>4))
struct pkt_name
get_packet_struct(u_int16_t type) {
u_int16_t index;
if (type == 1) /* special case for bad FCS */
return badfcs;
if (WLAN_FRAME_IS_MGMT(type)) {
index = MGMT_NAME_INDEX(type);
if (index < sizeof(mgmt_names)/sizeof(struct pkt_name)) {
if (mgmt_names[index].c)
return mgmt_names[index];
}
} else if (WLAN_FRAME_IS_CTRL(type)) {
index = CTRL_NAME_INDEX(type);
if (index < sizeof(ctrl_names)/sizeof(struct pkt_name)) {
if (ctrl_names[index].c)
return ctrl_names[index];
}
} else if (WLAN_FRAME_IS_DATA(type)) {
index = DATA_NAME_INDEX(type);
if (index < sizeof(data_names)/sizeof(struct pkt_name)) {
if (data_names[index].c)
return data_names[index];
}
}
if (pkt_names[WLAN_FRAME_TYPE(type)][WLAN_FRAME_STYPE(type)].c)
return pkt_names[WLAN_FRAME_TYPE(type)][WLAN_FRAME_STYPE(type)];
return unknow;
}
......
......@@ -27,6 +27,12 @@ struct pkt_name {
const char* desc;
};
/*
* Names and abbreviations for all WLAN frame types (2 bit, but only MGMT, CTRL
* and DATA defined) and subtypes (4 bit)
*/
struct pkt_name pkt_names[3][16];
struct pkt_name
get_packet_struct(u_int16_t type);
......
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