Commit 43460354 authored by Bruno Randolf's avatar Bruno Randolf

safer packet type name handling

parent 8e868208
......@@ -27,9 +27,9 @@ buildstamp=.build_debug$(DEBUG)
all: $(buildstamp) $(NAME)
protocol_parser.o: ieee80211.h ieee80211_radiotap.h prism_header.h olsr_header.h
protocol_parser.o: ieee80211.h ieee80211_radiotap.h prism_header.h olsr_header.h util.h
main.o: main.h ieee80211.h
display.o: display.h main.h
display.o: display.h main.h util.h
network.o: network.h
$(NAME): $(OBJS)
......
......@@ -604,7 +604,7 @@ update_hist_win(void)
wattron(show_win, CYAN);
mvwprintw(show_win, TYPE_POS, col, "%c", \
get_paket_type_char(hist.type[i]));
get_packet_type_char(hist.type[i]));
/* make rate table smaller by joining some values */
switch (hist.rate[i]) {
......@@ -665,7 +665,7 @@ update_dump_win(struct packet_info* pkt)
wprintw(dump_win,"%-7s%s ", "IP", ip_sprintf(pkt->ip_src));
}
else {
wprintw(dump_win,"%-7s", get_paket_type_name(pkt->wlan_type));
wprintw(dump_win,"%-7s", get_packet_type_name(pkt->wlan_type));
switch (pkt->wlan_type & IEEE80211_FCTL_FTYPE) {
case IEEE80211_FTYPE_DATA:
......
......@@ -23,6 +23,11 @@
#include "ieee80211.h"
struct pkt_names {
char c;
char* name;
};
/* a list of packet type names for easier indexing with padding */
struct pkt_names mgmt_names[] = {
{ 'a', "ASOCRQ" }, /* IEEE80211_STYPE_ASSOC_REQ 0x0000 */
......@@ -40,8 +45,7 @@ struct pkt_names mgmt_names[] = {
{ 'T', "ACTION" }, /* IEEE80211_STYPE_ACTION 0x00D0 */
};
struct pkt_names ctl_names[] = {
{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, /* let's waste some memory ;) */
struct pkt_names ctrl_names[] = {
{ 's', "PSPOLL" }, /* IEEE80211_STYPE_PSPOLL 0x00A0 */
{ 'R', "RTS" }, /* IEEE80211_STYPE_RTS 0x00B0 */
{ 'C', "CTS" }, /* IEEE80211_STYPE_CTS 0x00C0 */
......@@ -69,6 +73,10 @@ struct pkt_names data_names[] = {
{ 'f', "QCFACKPOLL" }, /* IEEE80211_STYPE_QOS_CFACKPOLL 0x00F0 */
};
#define DATA_NAME_INDEX(_i) (((_i) & IEEE80211_FCTL_STYPE)>>4)
#define MGMT_NAME_INDEX(_i) (((_i) & IEEE80211_FCTL_STYPE)>>4)
#define CTRL_NAME_INDEX(_i) ((((_i) & IEEE80211_FCTL_STYPE)>>4)-10)
inline int
normalize(int oval, float max_val, int max) {
......@@ -138,40 +146,54 @@ convert_string_to_mac(const char* string, unsigned char* mac)
char
get_paket_type_char(int type)
get_packet_type_char(int type)
{
switch (type & IEEE80211_FCTL_FTYPE) {
case IEEE80211_FTYPE_MGMT:
if (MGMT_NAME(type & IEEE80211_FCTL_STYPE).c)
return MGMT_NAME(type & IEEE80211_FCTL_STYPE).c;
if (MGMT_NAME_INDEX(type) < sizeof(mgmt_names)/sizeof(struct pkt_names)) {
if (mgmt_names[MGMT_NAME_INDEX(type)].c)
return mgmt_names[MGMT_NAME_INDEX(type)].c;
}
break;
case IEEE80211_FTYPE_CTL:
if (CTL_NAME(type & IEEE80211_FCTL_STYPE).c)
return CTL_NAME(type & IEEE80211_FCTL_STYPE).c;
if (CTRL_NAME_INDEX(type) < sizeof(ctrl_names)/sizeof(struct pkt_names)) {
if (ctrl_names[CTRL_NAME_INDEX(type)].c)
return ctrl_names[CTRL_NAME_INDEX(type)].c;
}
break;
case IEEE80211_FTYPE_DATA:
if (DATA_NAME(type & IEEE80211_FCTL_STYPE).c)
return DATA_NAME(type & IEEE80211_FCTL_STYPE).c;
if (DATA_NAME_INDEX(type) < sizeof(data_names)/sizeof(struct pkt_names)) {
if (data_names[DATA_NAME_INDEX(type)].c)
return data_names[DATA_NAME_INDEX(type)].c;
}
break;
}
return '?';
}
char*
get_paket_type_name(int type)
get_packet_type_name(int type)
{
switch (type & IEEE80211_FCTL_FTYPE) {
case IEEE80211_FTYPE_MGMT:
if (MGMT_NAME(type & IEEE80211_FCTL_STYPE).name)
return MGMT_NAME(type & IEEE80211_FCTL_STYPE).name;
if (MGMT_NAME_INDEX(type) < sizeof(mgmt_names)/sizeof(struct pkt_names)) {
if (mgmt_names[MGMT_NAME_INDEX(type)].c)
return mgmt_names[MGMT_NAME_INDEX(type)].name;
}
break;
case IEEE80211_FTYPE_CTL:
if (CTL_NAME(type & IEEE80211_FCTL_STYPE).name)
return CTL_NAME(type & IEEE80211_FCTL_STYPE).name;
if (CTRL_NAME_INDEX(type) < sizeof(ctrl_names)/sizeof(struct pkt_names)) {
if (ctrl_names[CTRL_NAME_INDEX(type)].c)
return ctrl_names[CTRL_NAME_INDEX(type)].name;
}
break;
case IEEE80211_FTYPE_DATA:
if (DATA_NAME(type & IEEE80211_FCTL_STYPE).name)
return DATA_NAME(type & IEEE80211_FCTL_STYPE).name;
if (DATA_NAME_INDEX(type) < sizeof(data_names)/sizeof(struct pkt_names)) {
if (data_names[DATA_NAME_INDEX(type)].c)
return data_names[DATA_NAME_INDEX(type)].name;
}
break;
}
return "UNKNOW";
}
......@@ -41,24 +41,8 @@ convert_string_to_mac(const char* string, unsigned char* mac);
inline int
normalize(int val, float max_val, int max);
char get_paket_type_char(int type);
char* get_paket_type_name(int type);
/* a list of packet type names defined in main.c */
struct pkt_names {
char c;
char* name;
};
extern struct pkt_names mgmt_names[];
extern struct pkt_names ctl_names[];
extern struct pkt_names data_names[];
#define DATA_NAME(_i) data_names[(_i)>>4]
#define MGMT_NAME(_i) mgmt_names[(_i)>>4]
#define CTL_NAME(_i) ctl_names[(_i)>>4]
char get_packet_type_char(int type);
char* get_packet_type_name(int type);
#endif
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