From: hackbard Date: Sun, 12 Jun 2005 12:40:42 +0000 (+0000) Subject: fixed signal quality output X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c189dbc1ce419a70c8a91ba275dbdf57c4de2ec6;p=my-code%2Fhdw-sniff.git fixed signal quality output --- diff --git a/main.c b/main.c index dee4596..e3cb85c 100644 --- a/main.c +++ b/main.c @@ -7,8 +7,6 @@ #include "main.h" -// void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package); - /* functions */ int display_console(t_info *info,char *string) { @@ -38,6 +36,7 @@ int display_console(t_info *info,char *string) { display_string(display,GUI_OFFSET_CTRL,1,"| ctrl",6); display_string(display,GUI_OFFSET_DATA,1,"| data",6); display_string(display,GUI_OFFSET_ACTIVE,1,"| act",5); + display_string(display,GUI_OFFSET_SIGNAL,1,"| sq",4); display_line(display,0,2,x,2,'-'); list_reset(&(info->sniffed_sta)); @@ -67,6 +66,8 @@ int display_console(t_info *info,char *string) { display_string(display,GUI_OFFSET_MGMT,3+i,help,20); snprintf(help,5,"| %c",sta->active); display_string(display,GUI_OFFSET_ACTIVE,3+i,help,4); + snprintf(help,5,"| %02u",sta->sq); + display_string(display,GUI_OFFSET_SIGNAL,3+i,help,4); list_next(&(info->sniffed_sta)); } } @@ -193,7 +194,7 @@ int react_on_event(t_event *event,void *ptr) { int usage(void) { puts("usage: hdw-sniff "); puts("\toptions:"); - puts("\t\t-m \tmonitor and/or wlanng"); + puts("\t\t-m \tieee80211 or prism"); puts("\t\t-d \twlan0,eth0"); puts("\t\t-l "); puts("\t\t-k \t(string)"); @@ -244,13 +245,13 @@ int main(int argc, char **argv) { case 'h': usage(); case 'm': - if(!strncmp(argv[i+1],"monitor",7)) { - info.mode|=MODE_MONITOR; - puts("will go to monitor mode."); + if(!strncmp(argv[i+1],"ieee80211",9)) { + info.mode|=MODE_IEEE80211; + puts("expecting ieee802.11 header in package"); } - else if(!strncmp(argv[i+1],"wlanng",6)) { - info.mode|=MODE_WLANNG; - puts("expecting wlanng header in package."); + else if(!strncmp(argv[i+1],"prism",5)) { + info.mode|=MODE_PRISM; + puts("expecting prism header in package."); } else { printf("unknown mode: %s\n",argv[1]); @@ -287,11 +288,14 @@ int main(int argc, char **argv) { } /* setting up device */ - if(info.mode&MODE_MONITOR) { - sprintf(sys_call,"iwconfig %s mode monitor",info.device); - puts("set monitoring mode ..."); - system(sys_call); - } + if(info.mode&MODE_IEEE80211) + sprintf(sys_call,"iwpriv %s monitor 2",info.device); + else if(info.mode&MODE_PRISM) + sprintf(sys_call,"iwpriv %s monitor 3",info.device); + + puts("set monitoring mode ..."); + system(sys_call); + sprintf(sys_call,"ifconfig %s up",info.device); puts("setting up device ..."); system(sys_call); diff --git a/main.h b/main.h index 9f4a350..d89d90e 100644 --- a/main.h +++ b/main.h @@ -39,9 +39,6 @@ #define MAX_DEV_CHARS 6 #define MAX_SYSCALL_CHARS 128 -#define HDW_SNIFF_MAX_WIDTH 80 -#define HDW_SNIFF_MAX_HEIGHT 8 - #define HOP_SEC 0 #define HOP_USEC 200000 @@ -53,10 +50,14 @@ #define GUI_OFFSET_CTRL 57 #define GUI_OFFSET_DATA 64 #define GUI_OFFSET_ACTIVE 71 +#define GUI_OFFSET_SIGNAL 77 + +#define HDW_SNIFF_MAX_WIDTH (GUI_OFFSET_SIGNAL+5) +#define HDW_SNIFF_MAX_HEIGHT 8 /* modes */ -#define MODE_MONITOR (1<<0) -#define MODE_WLANNG (1<<1) +#define MODE_IEEE80211 (1<<0) +#define MODE_PRISM (1<<1) #define MODE_QUIT (1<<2) #define MODE_HEXOUT (1<<3) #define MODE_ASCIIOUT (1<<4) @@ -78,7 +79,7 @@ typedef struct s_info { int count_m; int count_c; int count_d; - unsigned char mode; /* monitoring/managed mode */ + unsigned char mode; /* ieee802.11/prism mode */ char device[MAX_DEV_CHARS]; /* sniffed devie */ int log_fd; /* file descriptor for logfile */ int pcap_fd; /* fd for reading pcap events */ diff --git a/parse.c b/parse.c index 151c9f5..3dc4301 100644 --- a/parse.c +++ b/parse.c @@ -13,6 +13,18 @@ * different protocols should get to seperated files though ... */ +unsigned int int_s(unsigned int val) { + + unsigned int swapped; + + swapped=(val&0x000000ff)<<24; + swapped|=(val&0x0000ff00)<<8; + swapped|=(val&0x00ff0000)>>8; + swapped|=(val&0xff000000)>>24; + + return swapped; +} + int switch_active_state(char *state) { switch(*state) { @@ -33,17 +45,19 @@ int switch_active_state(char *state) { return 23; } -void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *package) { +void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,const unsigned char *pkg) { t_info *info; int i; t_sta new_sta; t_sta *sta; + unsigned char *package=NULL; //t_frame4_hdr *f4hdr; t_frame3_hdr *f3hdr; //t_frame2_hdr *f2hdr; //t_frame1_hdr *f1hdr; t_beacon_fb *beacon_fb; + t_prism_hdr *prismhdr=NULL; int ret; char string[MESSAGE_MAX]; char sc[MAX_SYSCALL_CHARS]; @@ -68,6 +82,14 @@ void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,cons /* maybe there is offset to the actual ieee802.11 frame, for example prism header ... in that case, hack the source! */ + if(info->mode&MODE_IEEE80211) { + package=(unsigned char *)pkg; + prismhdr=NULL; + } + else if(info->mode&MODE_PRISM) { + package=(unsigned char *)pkg+sizeof(t_prism_hdr); + prismhdr=(t_prism_hdr *)pkg; + } /* management */ if(FCTL_TYPE(package[0])==FCTL_TYPE_MGMT) { @@ -93,6 +115,9 @@ void parse_package(unsigned char *ptr,const struct pcap_pkthdr *pcap_header,cons if(CAP_INFO_PRIVACY(beacon_fb->cap_info)) sta->wep=WEP; sta->count_mgmt++; switch_active_state(&(sta->active)); + if(info->mode&MODE_IEEE80211) sta->sq=0; + else if(info->mode&MODE_PRISM) + sta->sq=(prismhdr->signal.data)-(prismhdr->noise.data); strncpy(string,"last: beacon, source: ",MESSAGE_MAX); for(i=0;iaddr[i], diff --git a/parse.h b/parse.h index 3d1d290..384e65c 100644 --- a/parse.h +++ b/parse.h @@ -47,6 +47,29 @@ typedef struct s_frame1_hdr { u16 seq_ctrl; } __attribute__ ((packed)) t_frame1_hdr; +typedef struct s_prism_val { + u32 did; + u16 status; + u16 len; + u32 data; +} __attribute__ ((packed)) t_prism_val; + +typedef struct s_prism_hdr { + u32 msg_code; + u32 msg_len; + char device[16]; + t_prism_val hosttime; + t_prism_val mactime; + t_prism_val channel; + t_prism_val rssi; + t_prism_val sq; + t_prism_val signal; + t_prism_val noise; + t_prism_val rate; + t_prism_val istx; + t_prism_val frame_len; +} __attribute__ ((packed)) t_prism_hdr; + #define FCTL_VER(X) ((X&0x0003)) #define FCTL_TYPE(X) ((X&0x000c)>>2) #define FCTL_STYPE(X) ((X&0x00f0)>>4) @@ -124,6 +147,7 @@ typedef struct s_sta { int count_data; char active; char key[WEP_MAX_DIGITS]; + int sq; } t_sta; /* function prototypes */