author | max <max> | 2002-11-23 20:12:57 (UTC) |
---|---|---|
committer | max <max> | 2002-11-23 20:12:57 (UTC) |
commit | 2f11392ab9292df21a6e1374800954a6b405ee9b (patch) (unidiff) | |
tree | 4a3b90822b3cfe18ee95165f45b9fc4d46ea4385 | |
parent | 19a08a4585abf1d6f66101d41374dd5441c5754e (diff) | |
download | opie-2f11392ab9292df21a6e1374800954a6b405ee9b.zip opie-2f11392ab9292df21a6e1374800954a6b405ee9b.tar.gz opie-2f11392ab9292df21a6e1374800954a6b405ee9b.tar.bz2 |
*** empty log message ***
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/Makefile | 5 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/cardmode.cc | 89 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/cardmode.hh | 36 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.cc | 95 | ||||
-rw-r--r-- | noncore/net/wellenreiter/daemon/source/sniffer.hh | 13 |
5 files changed, 137 insertions, 101 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/Makefile b/noncore/net/wellenreiter/daemon/source/Makefile index f6efa3d..bcbc799 100644 --- a/noncore/net/wellenreiter/daemon/source/Makefile +++ b/noncore/net/wellenreiter/daemon/source/Makefile | |||
@@ -1,28 +1,33 @@ | |||
1 | # $Id$ | 1 | # $Id$ |
2 | 2 | ||
3 | CPP = g++ | 3 | CPP = g++ |
4 | 4 | ||
5 | OPTIMFLAGS= -g | 5 | OPTIMFLAGS= -g |
6 | WARNFLAGS= -Wall -pedantic -DDEBUG | 6 | WARNFLAGS= -Wall -pedantic -DDEBUG |
7 | LDFLAGS = | 7 | LDFLAGS = |
8 | LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a | 8 | LIBS = -lpcap ../../libwellenreiter/source/libwellenreiter.a |
9 | OBJ = daemon.o | 9 | OBJ = daemon.o |
10 | 10 | ||
11 | .SUFFIXES: | 11 | .SUFFIXES: |
12 | .PHONY: all wellenreiterd clean distclean realclean | 12 | .PHONY: all wellenreiterd clean distclean realclean |
13 | 13 | ||
14 | %.o : %.cc | 14 | %.o : %.cc |
15 | $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@ | 15 | $(CPP) $(WARNFLAGS) $(OPTIMFLAGS) -c $< -o $@ |
16 | 16 | ||
17 | all:wellenreiterd | 17 | all:wellenreiterd |
18 | 18 | ||
19 | wellenreiterd:$(OBJ) | 19 | wellenreiterd:$(OBJ) |
20 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@ | 20 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) $(OBJ) $(LDFLAGS) $(LIBS) -o $@ |
21 | @echo Build wellenreiterd | 21 | @echo Build wellenreiterd |
22 | 22 | ||
23 | sniffer: sniffer.o cardmode.o | ||
24 | $(CPP) $(OPTIMFLAGS) $(WARNFLAGS) sniffer.o cardmode.o $(LDFLAGS) $(LIBS) -o $@ | ||
25 | @echo Build sniffer | ||
26 | |||
27 | |||
23 | clean distclean realclean: | 28 | clean distclean realclean: |
24 | @rm -rf wellenreiterd *~ *.o | 29 | @rm -rf wellenreiterd *~ *.o |
25 | @echo All dependent files have been removed. | 30 | @echo All dependent files have been removed. |
26 | 31 | ||
27 | daemon.o:config.hh | 32 | daemon.o:config.hh |
28 | 33 | ||
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.cc b/noncore/net/wellenreiter/daemon/source/cardmode.cc new file mode 100644 index 0000000..ae32af4 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/cardmode.cc | |||
@@ -0,0 +1,89 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | #include "cardmode.hh" | ||
4 | |||
5 | int card_into_monitormode (char *device, int cardtype) | ||
6 | { | ||
7 | |||
8 | int datalink; /* used for getting the pcap datalink type */ | ||
9 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | ||
10 | FILE *CISCO_CONFIG_FILE; | ||
11 | char errbuf[PCAP_ERRBUF_SIZE]; | ||
12 | pcap_t *handle; | ||
13 | |||
14 | /* Checks if we have a device to sniff on */ | ||
15 | if(device == NULL) | ||
16 | { | ||
17 | printf ("Fatal error i did not have any interfaces to sniff on\n"); | ||
18 | return 0; | ||
19 | } | ||
20 | |||
21 | /* Setting the prmiscous and up flag to the interface */ | ||
22 | if (card_set_promisc_up (device) == 0) | ||
23 | { | ||
24 | printf ("Interface flags correctly set using ifconfig\n"); | ||
25 | } | ||
26 | |||
27 | /* Check the cardtype and executes the commands to go into monitor mode */ | ||
28 | if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ | ||
29 | { | ||
30 | /* bring the sniffer into rfmon mode */ | ||
31 | snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); | ||
32 | CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); | ||
33 | fputs ("Mode: r",CISCO_CONFIG_FILE); | ||
34 | fputs ("Mode: y",CISCO_CONFIG_FILE); | ||
35 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | ||
36 | fclose(CISCO_CONFIG_FILE); | ||
37 | } | ||
38 | else if (cardtype == CARD_TYPE_NG) | ||
39 | { | ||
40 | char wlanngcmd[62]; | ||
41 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); | ||
42 | if (system (wlanngcmd) != 0) | ||
43 | { | ||
44 | printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); | ||
45 | return 0; | ||
46 | } | ||
47 | } | ||
48 | else if (cardtype == CARD_TYPE_HOSTAP) | ||
49 | { | ||
50 | printf ("Got a host-ap card, nothing is implemented now\n"); | ||
51 | } | ||
52 | |||
53 | |||
54 | /* Check the interface if it is in the correct raw mode */ | ||
55 | handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf); | ||
56 | |||
57 | /* getting the datalink type */ | ||
58 | datalink = pcap_datalink(handle); | ||
59 | |||
60 | if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | ||
61 | { | ||
62 | printf ("Your successfully listen on %s in 802.11 raw mode\n",device); | ||
63 | pcap_close(handle); | ||
64 | return 0; | ||
65 | |||
66 | } | ||
67 | else | ||
68 | { | ||
69 | printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); | ||
70 | pcap_close(handle); | ||
71 | return 0; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | |||
76 | |||
77 | int card_set_promisc_up (char * device) | ||
78 | { | ||
79 | int ret; | ||
80 | char ifconfigcmd[32]; | ||
81 | snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device); | ||
82 | ret = system (ifconfigcmd); | ||
83 | if (ret > 0) | ||
84 | { | ||
85 | printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); | ||
86 | return 0; | ||
87 | } | ||
88 | return 1; | ||
89 | } | ||
diff --git a/noncore/net/wellenreiter/daemon/source/cardmode.hh b/noncore/net/wellenreiter/daemon/source/cardmode.hh new file mode 100644 index 0000000..87284a1 --- a/dev/null +++ b/noncore/net/wellenreiter/daemon/source/cardmode.hh | |||
@@ -0,0 +1,36 @@ | |||
1 | /* $Id$ */ | ||
2 | |||
3 | #ifndef CARDMODE_HH | ||
4 | #define CARDMODE_HH | ||
5 | |||
6 | #include <string.h> | ||
7 | #include <stdio.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <pcap.h> | ||
10 | #include <errno.h> | ||
11 | #include <sys/socket.h> | ||
12 | #include <netinet/in.h> | ||
13 | #include <arpa/inet.h> | ||
14 | #include <net/bpf.h> | ||
15 | |||
16 | #endif /* CARDMODE_HH */ | ||
17 | |||
18 | /* Defines, used for the card setup */ | ||
19 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | ||
20 | #define CARD_TYPE_CISCO1 | ||
21 | #define CARD_TYPE_NG2 | ||
22 | #define CARD_TYPE_HOSTAP3 | ||
23 | |||
24 | /* only for now, until we have the daemon running */ | ||
25 | /*the config file should provide these information */ | ||
26 | #define SNIFFER_DEVICE "wlan0" | ||
27 | #define CARD_TYPE CARD_TYPE_CISCO | ||
28 | #define SBIN_PATH"/sbin/ifconfig %s promisc up" | ||
29 | #define WLANCTL_PATH "/sbin/wlanctl-ng" | ||
30 | |||
31 | /* Prototypes */ | ||
32 | |||
33 | int card_into_monitormode (char * device, int cardtype); | ||
34 | int card_set_promisc_up (char * device); | ||
35 | |||
36 | |||
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.cc b/noncore/net/wellenreiter/daemon/source/sniffer.cc index c837505..65c8579 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.cc +++ b/noncore/net/wellenreiter/daemon/source/sniffer.cc | |||
@@ -1,223 +1,141 @@ | |||
1 | /* | 1 | /* |
2 | * rfmon mode sniffer | 2 | * rfmon mode sniffer |
3 | * This works only with cisco wireless cards with an rfmon | 3 | * This works only with cisco wireless cards with an rfmon |
4 | * able driver and not with wifi stuff. | 4 | * able driver and not with wifi stuff. |
5 | * | 5 | * |
6 | * $Id$ | 6 | * $Id$ |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "config.hh" | 9 | #include "config.hh" |
10 | #include "cardmode.hh" | ||
10 | #include "sniffer.hh" | 11 | #include "sniffer.hh" |
11 | #include "ieee802_11.hh" | 12 | #include "ieee802_11.hh" |
12 | #include "extract.hh" | 13 | #include "extract.hh" |
13 | 14 | ||
14 | int sniffer(void) | 15 | int main(void) |
15 | { | 16 | { |
16 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) | 17 | if(card_into_monitormode (SNIFFER_DEVICE, CARD_TYPE_NG) < 0) |
17 | return 0; | 18 | return 0; |
18 | start_sniffing (SNIFFER_DEVICE); | 19 | start_sniffing (SNIFFER_DEVICE); |
19 | 20 | ||
20 | return 1; | 21 | return 1; |
21 | } | 22 | } |
22 | 23 | ||
23 | int card_into_monitormode (char *device, int cardtype) | ||
24 | { | ||
25 | |||
26 | int datalink; /* used for getting the pcap datalink type */ | ||
27 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | ||
28 | FILE *CISCO_CONFIG_FILE; | ||
29 | char errbuf[PCAP_ERRBUF_SIZE]; | ||
30 | pcap_t *handle; | ||
31 | |||
32 | /* Checks if we have a device to sniff on */ | ||
33 | if(device == NULL) | ||
34 | { | ||
35 | printf ("Fatal error i did not have any interfaces to sniff on\n"); | ||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | /* Setting the prmiscous and up flag to the interface */ | ||
40 | if (card_set_promisc_up (device) == 0) | ||
41 | { | ||
42 | printf ("Interface flags correctly set using ifconfig\n"); | ||
43 | } | ||
44 | |||
45 | /* Check the cardtype and executes the commands to go into monitor mode */ | ||
46 | if (cardtype == CARD_TYPE_CISCO) /* I got a cisco card */ | ||
47 | { | ||
48 | /* bring the sniffer into rfmon mode */ | ||
49 | snprintf(CiscoRFMON, sizeof(CiscoRFMON),DEFAULT_PATH, device); | ||
50 | CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w"); | ||
51 | fputs ("Mode: r",CISCO_CONFIG_FILE); | ||
52 | fputs ("Mode: y",CISCO_CONFIG_FILE); | ||
53 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | ||
54 | fclose(CISCO_CONFIG_FILE); | ||
55 | } | ||
56 | else if (cardtype == CARD_TYPE_NG) | ||
57 | { | ||
58 | char wlanngcmd[62]; | ||
59 | snprintf(wlanngcmd, sizeof(wlanngcmd),"%s %s lnxreq_wlansniff channel=1 enable=true",WLANCTL_PATH,device); | ||
60 | if (system (wlanngcmd) != 0) | ||
61 | { | ||
62 | printf ("\n Fatal error could not set %s in raw mode, check cardtype\n",device); | ||
63 | return 0; | ||
64 | } | ||
65 | } | ||
66 | else if (cardtype == CARD_TYPE_HOSTAP) | ||
67 | { | ||
68 | printf ("Got a host-ap card, nothing is implemented now\n"); | ||
69 | } | ||
70 | |||
71 | |||
72 | /* Check the interface if it is in the correct raw mode */ | ||
73 | handle = pcap_open_live(device, BUFSIZ, 1, 0, errbuf); | ||
74 | |||
75 | /* getting the datalink type */ | ||
76 | datalink = pcap_datalink(handle); | ||
77 | |||
78 | if (datalink == DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | ||
79 | { | ||
80 | printf ("Your successfully listen on %s in 802.11 raw mode\n",device); | ||
81 | pcap_close(handle); | ||
82 | return 0; | ||
83 | |||
84 | } | ||
85 | else | ||
86 | { | ||
87 | printf ("Fatal error, cannot continue, your interface %s does not work in the correct 802.11 raw mode, check you driver please\n",device); | ||
88 | pcap_close(handle); | ||
89 | return 0; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | int card_set_promisc_up (char * device) | ||
94 | { | ||
95 | int ret; | ||
96 | char ifconfigcmd[32]; | ||
97 | snprintf(ifconfigcmd,sizeof(ifconfigcmd),SBIN_PATH, device); | ||
98 | ret = system (ifconfigcmd); | ||
99 | if (ret > 0) | ||
100 | { | ||
101 | printf ("\nFatal error, could not execute %s please check your card,binary location and permission\n",ifconfigcmd); | ||
102 | return 0; | ||
103 | } | ||
104 | return 1; | ||
105 | } | ||
106 | |||
107 | int start_sniffing (char * device) | 24 | int start_sniffing (char * device) |
108 | { | 25 | { |
109 | 26 | ||
110 | pcap_t *handletopcap; | 27 | pcap_t *handletopcap; |
111 | char errbuf[PCAP_ERRBUF_SIZE]; | 28 | char errbuf[PCAP_ERRBUF_SIZE]; |
112 | 29 | ||
113 | /* opening the pcap for sniffing */ | 30 | /* opening the pcap for sniffing */ |
114 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); | 31 | handletopcap = pcap_open_live(device, BUFSIZ, 1, 1000, errbuf); |
115 | 32 | ||
116 | /* Next few lines a taken out of kismet */ | ||
117 | #ifdef HAVE_PCAP_NONBLOCK | 33 | #ifdef HAVE_PCAP_NONBLOCK |
118 | pcap_setnonblock(handletopcap, 1, errstr); | 34 | pcap_setnonblock(handletopcap, 1, errstr); |
119 | #endif | 35 | #endif |
120 | |||
121 | /*start scanning */ | 36 | /*start scanning */ |
122 | pcap_loop(handletopcap,-1,process_packets,NULL); | 37 | pcap_loop(handletopcap,-1,process_packets,NULL); |
123 | 38 | ||
124 | printf("\nDone processing packets... wheew!\n"); | 39 | printf("\nDone processing packets... wheew!\n"); |
125 | return 1; | 40 | return 1; |
126 | } | 41 | } |
127 | 42 | ||
128 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) | 43 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) |
129 | { | 44 | { |
130 | u_int caplen = pkthdr->caplen; | 45 | u_int caplen = pkthdr->caplen; |
131 | u_int length = pkthdr->len; | 46 | u_int length = pkthdr->len; |
132 | u_int16_t fc; | 47 | u_int16_t fc; |
133 | u_int HEADER_LENGTH; | 48 | u_int HEADER_LENGTH; |
134 | 49 | ||
135 | /* pinfo holds all interresting information for us */ | 50 | /* pinfo holds all interresting information for us */ |
136 | struct packetinfo pinfo; | 51 | struct packetinfo pinfo; |
137 | struct packetinfo *pinfoptr; | 52 | struct packetinfo *pinfoptr; |
138 | pinfoptr=&pinfo; | 53 | pinfoptr=&pinfo; |
139 | 54 | ||
140 | pinfoptr->isvalid = 0; | 55 | pinfoptr->isvalid = 0; |
141 | pinfoptr->pktlen = pkthdr->len; | 56 | pinfoptr->pktlen = pkthdr->len; |
57 | |||
142 | if (caplen < IEEE802_11_FC_LEN) | 58 | if (caplen < IEEE802_11_FC_LEN) |
143 | { | 59 | { |
144 | /* This is a garbage packet, because is does not long enough | 60 | /* This is a garbage packet, because is does not long enough |
145 | to hold a 802.11b header */ | 61 | to hold a 802.11b header */ |
146 | pinfoptr->isvalid = 0; | 62 | pinfoptr->isvalid = 0; |
147 | return; | 63 | return; |
148 | } | 64 | } |
149 | 65 | ||
150 | /* Gets the framecontrol bits (2bytes long) */ | 66 | /* Gets the framecontrol bits (2bytes long) */ |
151 | fc = EXTRACT_LE_16BITS(packet); | 67 | fc = EXTRACT_LE_16BITS(packet); |
152 | 68 | ||
153 | HEADER_LENGTH = GetHeaderLength(fc); | 69 | HEADER_LENGTH = GetHeaderLength(fc); |
154 | 70 | ||
155 | if (caplen < HEADER_LENGTH) | 71 | if (caplen < HEADER_LENGTH) |
156 | { | 72 | { |
157 | /* This is a garbage packet, because it is not long enough | 73 | /* This is a garbage packet, because it is not long enough |
158 | to hold a correct header of its type */ | 74 | to hold a correct header of its type */ |
159 | pinfoptr->isvalid = 0; | 75 | pinfoptr->isvalid = 0; |
160 | return; | 76 | return; |
161 | } | 77 | } |
162 | 78 | ||
163 | /* Decode 802.11b header out of the packet */ | 79 | /* Decode 802.11b header out of the packet */ |
164 | if (decode_80211b_hdr(packet,pinfoptr) == 0) | 80 | if (decode_80211b_hdr(packet,pinfoptr) == 0) |
165 | { | 81 | { |
166 | /* Justification of the ofset to further process the packet */ | 82 | /* Justification of the ofset to further process the packet */ |
167 | length -= HEADER_LENGTH; | 83 | length -= HEADER_LENGTH; |
168 | caplen -= HEADER_LENGTH; | 84 | caplen -= HEADER_LENGTH; |
169 | packet += HEADER_LENGTH; | 85 | packet += HEADER_LENGTH; |
170 | } | 86 | } |
171 | else | 87 | else |
172 | { /* Something is wrong,could not be a correct packet */ | 88 | { /* Something is wrong,could not be a correct packet */ |
173 | return; | 89 | return; |
174 | } | 90 | } |
175 | 91 | ||
176 | switch (FC_TYPE(fc)) | 92 | switch (FC_TYPE(fc)) |
177 | { | 93 | { |
178 | /* Is it a managemnet frame? */ | 94 | /* Is it a managemnet frame? */ |
179 | case T_MGMT: | 95 | case T_MGMT: |
180 | switch (FC_SUBTYPE(fc)) | 96 | switch (FC_SUBTYPE(fc)) |
181 | { /* Is it a beacon frame? */ | 97 | { /* Is it a beacon frame? */ |
182 | case ST_BEACON: | 98 | case ST_BEACON: |
183 | if (handle_beacon(fc, packet,pinfoptr) ==0) | 99 | if (handle_beacon(fc, packet,pinfoptr) ==0) |
184 | { | 100 | { |
101 | printf ("\n\tOn network : %s",pinfoptr->ssid); | ||
185 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) | 102 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) |
186 | { | 103 | { |
187 | /* Every beacon must have the broadcast as destination | 104 | /* Every beacon must have the broadcast as destination |
188 | so it must be a shitti packet */ | 105 | so it must be a shitti packet */ |
189 | pinfoptr->isvalid = 0; | 106 | pinfoptr->isvalid = 0; |
190 | return; | 107 | return; |
191 | } | 108 | } |
109 | |||
192 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) | 110 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) |
193 | { | 111 | { |
194 | /* Only one of both are possible, so must be | 112 | /* Only one of both are possible, so must be |
195 | a noise packet, if this comes up */ | 113 | a noise packet, if this comes up */ |
196 | pinfoptr->isvalid = 0; | 114 | pinfoptr->isvalid = 0; |
197 | return; | 115 | return; |
198 | } | 116 | } |
199 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) | 117 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) |
200 | { | 118 | { |
201 | /* Only channels between 1 and 14 are possible | 119 | /* Only channels between 1 and 14 are possible |
202 | others must be noise packets */ | 120 | others must be noise packets */ |
203 | pinfoptr->isvalid = 0; | 121 | pinfoptr->isvalid = 0; |
204 | return; | 122 | return; |
205 | } | 123 | } |
206 | 124 | ||
207 | /* Here should be the infos to the gui issued */ | 125 | /* Here should be the infos to the gui issued */ |
208 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) | 126 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) |
209 | { | 127 | { |
210 | printf ("\nHave found an accesspoint:"); | 128 | printf ("\nHave found an accesspoint:"); |
211 | } | 129 | } |
212 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1) | 130 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 1) |
213 | { | 131 | { |
214 | printf ("\nHave found an AD-HOC station:"); | 132 | printf ("\nHave found an AD-HOC station:"); |
215 | 133 | ||
216 | } | 134 | } |
217 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) | 135 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) |
218 | { | 136 | { |
219 | printf ("\n\tOn a non-broadcasting network"); | 137 | printf ("\n\tOn a non-broadcasting network"); |
220 | } | 138 | } |
221 | else | 139 | else |
222 | { | 140 | { |
223 | printf ("\n\tOn network : %s",pinfoptr->ssid); | 141 | printf ("\n\tOn network : %s",pinfoptr->ssid); |
@@ -299,101 +217,102 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
299 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); | 217 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); |
300 | offset += 2; | 218 | offset += 2; |
301 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); | 219 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); |
302 | offset += 2; | 220 | offset += 2; |
303 | 221 | ||
304 | /* Gets the different flags out of the capabilities */ | 222 | /* Gets the different flags out of the capabilities */ |
305 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); | 223 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); |
306 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); | 224 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); |
307 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); | 225 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); |
308 | 226 | ||
309 | /* Gets the tagged elements out of the packets */ | 227 | /* Gets the tagged elements out of the packets */ |
310 | while (offset + 1 < ppinfo->pktlen) | 228 | while (offset + 1 < ppinfo->pktlen) |
311 | { | 229 | { |
312 | switch (*(p + offset)) | 230 | switch (*(p + offset)) |
313 | { | 231 | { |
314 | case E_SSID: | 232 | case E_SSID: |
315 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; | 233 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; |
316 | if (pbody.ssid.length > 0) | 234 | if (pbody.ssid.length > 0) |
317 | { | 235 | { |
318 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; | 236 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; |
319 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | 237 | pbody.ssid.ssid[pbody.ssid.length]='\0'; |
320 | if (strcmp((char *)pbody.ssid.ssid,"")==0) | 238 | if (strcmp((char *)pbody.ssid.ssid,"")==0) |
321 | { | 239 | { |
322 | ppinfo->ssid = NONBROADCASTING; | 240 | ppinfo->ssid = NONBROADCASTING; |
323 | } | 241 | } |
324 | else | 242 | else |
325 | { | 243 | { |
326 | ppinfo->ssid = (char *)pbody.ssid.ssid; | 244 | ppinfo->ssid = (char *)pbody.ssid.ssid; |
327 | } | 245 | } |
328 | ppinfo->ssid_len = pbody.ssid.length; | 246 | ppinfo->ssid_len = pbody.ssid.length; |
329 | } | 247 | } |
330 | break; | 248 | break; |
249 | |||
331 | case E_CHALLENGE: | 250 | case E_CHALLENGE: |
332 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | 251 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; |
333 | if (pbody.challenge.length > 0) | 252 | if (pbody.challenge.length > 0) |
334 | { | 253 | { |
335 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; | 254 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; |
336 | pbody.challenge.text[pbody.challenge.length]='\0'; | 255 | pbody.challenge.text[pbody.challenge.length]='\0'; |
337 | } | 256 | } |
338 | break; | 257 | break; |
339 | case E_RATES: | 258 | case E_RATES: |
340 | memcpy(&(pbody.rates),p+offset,2); offset += 2; | 259 | memcpy(&(pbody.rates),p+offset,2); offset += 2; |
341 | if (pbody.rates.length > 0) { | 260 | if (pbody.rates.length > 0) { |
342 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; | 261 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; |
343 | } | 262 | } |
344 | break; | 263 | break; |
345 | case E_DS: | 264 | case E_DS: |
346 | memcpy(&(pbody.ds),p+offset,3); offset +=3; | 265 | memcpy(&(pbody.ds),p+offset,3); offset +=3; |
347 | ppinfo->channel = pbody.ds.channel; | 266 | ppinfo->channel = pbody.ds.channel; |
348 | break; | 267 | break; |
349 | case E_CF: | 268 | case E_CF: |
350 | memcpy(&(pbody.cf),p+offset,8); offset +=8; | 269 | memcpy(&(pbody.cf),p+offset,8); offset +=8; |
351 | break; | 270 | break; |
352 | case E_TIM: | 271 | case E_TIM: |
353 | memcpy(&(pbody.tim),p+offset,2); offset +=2; | 272 | memcpy(&(pbody.tim),p+offset,2); offset +=2; |
354 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; | 273 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; |
355 | if ((pbody.tim.length -3) > 0) | 274 | if ((pbody.tim.length -3) > 0) |
356 | { | 275 | { |
357 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); | 276 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); |
358 | offset += pbody.tim.length -3; | 277 | offset += pbody.tim.length -3; |
359 | } | 278 | } |
360 | break; | 279 | break; |
361 | default: | 280 | default: |
362 | 281 | ||
363 | offset+= *(p+offset+1) + 2; | 282 | offset+= *(p+offset+1) + 2; |
364 | break; | 283 | break; |
365 | } /* end of switch*/ | 284 | } /* end of switch*/ |
366 | } /* end of for loop */ | 285 | } /* end of for loop */ |
367 | return 1; | 286 | return 0; |
368 | 287 | ||
369 | } /* End of handle_beacon */ | 288 | } /* End of handle_beacon */ |
370 | 289 | ||
371 | 290 | ||
372 | static int GetHeaderLength(u_int16_t fc) | 291 | static int GetHeaderLength(u_int16_t fc) |
373 | { | 292 | { |
374 | int iLength=0; | 293 | int iLength=0; |
375 | 294 | ||
376 | switch (FC_TYPE(fc)) { | 295 | switch (FC_TYPE(fc)) { |
377 | case T_MGMT: | 296 | case T_MGMT: |
378 | iLength = MGMT_HEADER_LEN; | 297 | iLength = MGMT_HEADER_LEN; |
379 | break; | 298 | break; |
380 | case T_CTRL: | 299 | case T_CTRL: |
381 | switch (FC_SUBTYPE(fc)) { | 300 | switch (FC_SUBTYPE(fc)) { |
382 | case CTRL_PS_POLL: | 301 | case CTRL_PS_POLL: |
383 | iLength = CTRL_PS_POLL_LEN; | 302 | iLength = CTRL_PS_POLL_LEN; |
384 | break; | 303 | break; |
385 | case CTRL_RTS: | 304 | case CTRL_RTS: |
386 | iLength = CTRL_RTS_LEN; | 305 | iLength = CTRL_RTS_LEN; |
387 | break; | 306 | break; |
388 | case CTRL_CTS: | 307 | case CTRL_CTS: |
389 | iLength = CTRL_CTS_LEN; | 308 | iLength = CTRL_CTS_LEN; |
390 | break; | 309 | break; |
391 | case CTRL_ACK: | 310 | case CTRL_ACK: |
392 | iLength = CTRL_ACK_LEN; | 311 | iLength = CTRL_ACK_LEN; |
393 | break; | 312 | break; |
394 | case CTRL_CF_END: | 313 | case CTRL_CF_END: |
395 | iLength = CTRL_END_LEN; | 314 | iLength = CTRL_END_LEN; |
396 | break; | 315 | break; |
397 | case CTRL_END_ACK: | 316 | case CTRL_END_ACK: |
398 | iLength = CTRL_END_ACK_LEN; | 317 | iLength = CTRL_END_ACK_LEN; |
399 | break; | 318 | break; |
diff --git a/noncore/net/wellenreiter/daemon/source/sniffer.hh b/noncore/net/wellenreiter/daemon/source/sniffer.hh index 7f45be6..d262353 100644 --- a/noncore/net/wellenreiter/daemon/source/sniffer.hh +++ b/noncore/net/wellenreiter/daemon/source/sniffer.hh | |||
@@ -1,83 +1,70 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef SNIFFER_HH | 3 | #ifndef SNIFFER_HH |
4 | #define SNIFFER_HH | 4 | #define SNIFFER_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <pcap.h> | 9 | #include <pcap.h> |
10 | #include <errno.h> | 10 | #include <errno.h> |
11 | #include <sys/socket.h> | 11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
13 | #include <arpa/inet.h> | 13 | #include <arpa/inet.h> |
14 | #include <net/bpf.h> | 14 | #include <net/bpf.h> |
15 | 15 | ||
16 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | ||
17 | #define CARD_TYPE_CISCO1 | ||
18 | #define CARD_TYPE_NG2 | ||
19 | #define CARD_TYPE_HOSTAP3 | ||
20 | 16 | ||
21 | #define NONBROADCASTING "non-broadcasting" | 17 | #define NONBROADCASTING "non-broadcasting" |
22 | 18 | ||
23 | /* only for now, until we have the daemon running */ | ||
24 | /*the config file should provide these information */ | ||
25 | #define SNIFFER_DEVICE "wlan0" | ||
26 | #define CARD_TYPE CARD_TYPE_CISCO | ||
27 | #define SBIN_PATH"/sbin/ifconfig %s promisc up" | ||
28 | #define WLANCTL_PATH "/sbin/wlanctl-ng" | ||
29 | 19 | ||
30 | /* holds all the interresting data */ | 20 | /* holds all the interresting data */ |
31 | struct packetinfo | 21 | struct packetinfo |
32 | { | 22 | { |
33 | int isvalid; | 23 | int isvalid; |
34 | int pktlen; | 24 | int pktlen; |
35 | int fctype; | 25 | int fctype; |
36 | int fcsubtype; | 26 | int fcsubtype; |
37 | int fc_wep; | 27 | int fc_wep; |
38 | int cap_WEP; | 28 | int cap_WEP; |
39 | int cap_IBSS; | 29 | int cap_IBSS; |
40 | int cap_ESS; | 30 | int cap_ESS; |
41 | int channel; | 31 | int channel; |
42 | char bssid[sizeof("00:00:00:00:00:00")]; | 32 | char bssid[sizeof("00:00:00:00:00:00")]; |
43 | char desthwaddr[sizeof("00:00:00:00:00:00")]; | 33 | char desthwaddr[sizeof("00:00:00:00:00:00")]; |
44 | char sndhwaddr[sizeof("00:00:00:00:00:00")]; | 34 | char sndhwaddr[sizeof("00:00:00:00:00:00")]; |
45 | char *ssid; | 35 | char *ssid; |
46 | int ssid_len; | 36 | int ssid_len; |
47 | }; | 37 | }; |
48 | 38 | ||
49 | 39 | ||
50 | /* Prototypes */ | 40 | /* Prototypes */ |
51 | |||
52 | int sniffer(void); | 41 | int sniffer(void); |
53 | int card_into_monitormode (char * device, int cardtype); | ||
54 | int card_set_promisc_up (char * device); | ||
55 | int start_sniffing (char * device); | 42 | int start_sniffing (char * device); |
56 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); | 43 | void process_packets(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet); |
57 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); | 44 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); |
58 | void etheraddr_string(register const u_char *ep,char * text); | 45 | void etheraddr_string(register const u_char *ep,char * text); |
59 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | 46 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); |
60 | 47 | ||
61 | static int GetHeaderLength(u_int16_t fc); | 48 | static int GetHeaderLength(u_int16_t fc); |
62 | 49 | ||
63 | /* | 50 | /* |
64 | * True if "l" bytes of "var" were captured. | 51 | * True if "l" bytes of "var" were captured. |
65 | * | 52 | * |
66 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large | 53 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large |
67 | * that "snapend - (l)" underflows. | 54 | * that "snapend - (l)" underflows. |
68 | * | 55 | * |
69 | * The check is for <= rather than < because "l" might be 0. | 56 | * The check is for <= rather than < because "l" might be 0. |
70 | */ | 57 | */ |
71 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ | 58 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ |
72 | (const u_char *)&(var) <= snapend - (l)) | 59 | (const u_char *)&(var) <= snapend - (l)) |
73 | 60 | ||
74 | /* True if "var" was captured */ | 61 | /* True if "var" was captured */ |
75 | #define TTEST(var) TTEST2(var, sizeof(var)) | 62 | #define TTEST(var) TTEST2(var, sizeof(var)) |
76 | 63 | ||
77 | /* Bail if "l" bytes of "var" were not captured */ | 64 | /* Bail if "l" bytes of "var" were not captured */ |
78 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc | 65 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc |
79 | 66 | ||
80 | /* Bail if "var" was not captured */ | 67 | /* Bail if "var" was not captured */ |
81 | #define TCHECK(var) TCHECK2(var, sizeof(var)) | 68 | #define TCHECK(var) TCHECK2(var, sizeof(var)) |
82 | 69 | ||
83 | #endif /* SNIFFER_HH */ | 70 | #endif /* SNIFFER_HH */ |