6 files changed, 135 insertions, 34 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 3a28217..b840f17 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -1,206 +1,195 @@ | |||
1 | /* | 1 | /* |
2 | * Startup functions of wellenreiter | 2 | * Startup functions of wellenreiter |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "config.hh" | 7 | #include "config.hh" |
8 | #include "daemon.hh" | 8 | #include "daemon.hh" |
9 | 9 | ||
10 | /* should be parsed from cfg-file */ | 10 | /* should be parsed from cfg-file */ |
11 | #define MAXCHANNEL 13 | 11 | #define MAXCHANNEL 13 |
12 | #define CHANINTERVAL 500000 | 12 | #define CHANINTERVAL 500000 |
13 | 13 | ||
14 | |||
14 | /* Main function of wellenreiterd */ | 15 | /* Main function of wellenreiterd */ |
15 | int main(int argc, char **argv) | 16 | int main(int argc, char **argv) |
16 | { | 17 | { |
17 | int sock, maxfd, retval; | 18 | int sock, maxfd, retval; |
18 | char buffer[WL_SOCKBUF]; | 19 | char buffer[WL_SOCKBUF]; |
19 | struct pcap_pkthdr header; | 20 | struct pcap_pkthdr header; |
20 | struct sockaddr_in saddr; | 21 | struct sockaddr_in saddr; |
21 | pcap_t *handletopcap; | 22 | // pcap_t *handletopcap; |
22 | wl_cardtype_t cardtype; | 23 | wl_cardtype_t cardtype; |
23 | pthread_t sub; | 24 | pthread_t sub; |
24 | const unsigned char *packet; | 25 | const unsigned char *packet; |
25 | 26 | ||
26 | fd_set rset; | 27 | fd_set rset; |
27 | 28 | ||
28 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 29 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
29 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); | 30 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); |
30 | 31 | ||
31 | if(argc < 3) | 32 | if(argc < 3) |
32 | usage(); | 33 | usage(); |
33 | 34 | ||
34 | /* Set sniffer device */ | 35 | /* Set sniffer device */ |
35 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); | 36 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); |
36 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); | 37 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); |
37 | 38 | ||
38 | /* Set card type */ | 39 | /* Set card type */ |
39 | cardtype.type = atoi(argv[2]); | 40 | cardtype.type = atoi(argv[2]); |
40 | if(cardtype.type < 1 || cardtype.type > 4) | 41 | if(cardtype.type < 1 || cardtype.type > 4) |
41 | usage(); | 42 | usage(); |
42 | 43 | ||
43 | /* set card into monitor mode */ | 44 | /* Until we do not act as a read daemon, it starts the sniffer |
44 | if(!card_into_monitormode(&handletopcap, cardtype.iface, | 45 | right after startup */ |
45 | cardtype.type)) | 46 | if (!start_sniffer(cardtype.iface,cardtype.type)) |
46 | { | 47 | { |
47 | wl_logerr("Cannot initialize the wireless-card, aborting"); | 48 | wl_logerr("daemon, start_sniff did not return proper, aborting"); |
48 | exit(EXIT_FAILURE); | 49 | exit(EXIT_FAILURE); |
49 | } | 50 | } |
50 | wl_loginfo("Set card into monitor mode"); | 51 | wl_loginfo ("daemon, wireless card prepared for sniffing"); |
51 | |||
52 | /* setup pcap */ | ||
53 | if((handletopcap = pcap_open_live(cardtype.iface, | ||
54 | BUFSIZ, 1, 0, NULL)) == NULL) | ||
55 | { | ||
56 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); | ||
57 | exit(EXIT_FAILURE); | ||
58 | } | ||
59 | |||
60 | #ifdef HAVE_PCAP_NONBLOCK | ||
61 | pcap_setnonblock(handletopcap, 1, NULL); | ||
62 | #endif | ||
63 | 52 | ||
64 | /* Setup socket for incoming commands */ | 53 | /* Setup socket for incoming commands */ |
65 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) | 54 | if((sock=wl_setupsock(DAEMONADDR, DAEMONPORT, saddr)) < 0) |
66 | { | 55 | { |
67 | wl_logerr("Cannot setup socket"); | 56 | wl_logerr("Cannot setup socket"); |
68 | exit(EXIT_FAILURE); | 57 | exit(EXIT_FAILURE); |
69 | } | 58 | } |
70 | wl_loginfo("Set up socket '%d' for GUI communication", sock); | 59 | wl_loginfo("Set up socket '%d' for GUI communication", sock); |
71 | 60 | ||
72 | /* Create channelswitching thread */ | 61 | /* Create channelswitching thread */ |
73 | if(pthread_create(&sub, NULL, channel_switcher, | 62 | if(pthread_create(&sub, NULL, channel_switcher, |
74 | (void *)&cardtype) != 0) | 63 | (void *)&cardtype) != 0) |
75 | { | 64 | { |
76 | wl_logerr("Cannot create thread: %s", strerror(errno)); | 65 | wl_logerr("Cannot create thread: %s", strerror(errno)); |
77 | close(sock); | 66 | close(sock); |
78 | exit(EXIT_FAILURE); | 67 | exit(EXIT_FAILURE); |
79 | } | 68 | } |
80 | if(pthread_detach(sub)) | 69 | if(pthread_detach(sub)) |
81 | { | 70 | { |
82 | wl_logerr("Error detaching thread"); | 71 | wl_logerr("Error detaching thread"); |
83 | close(sock); | 72 | close(sock); |
84 | pthread_exit((pthread_t *)sub); | 73 | pthread_exit((pthread_t *)sub); |
85 | exit(EXIT_FAILURE); | 74 | exit(EXIT_FAILURE); |
86 | } | 75 | } |
87 | wl_loginfo("Created and detached channel switching thread"); | 76 | wl_loginfo("Created and detached channel switching thread"); |
88 | 77 | ||
89 | FD_ZERO(&rset); | 78 | FD_ZERO(&rset); |
90 | 79 | ||
91 | /* Start main loop */ | 80 | /* Start main loop */ |
92 | wl_loginfo("Starting main loop"); | 81 | wl_loginfo("Starting main loop"); |
93 | while(1) | 82 | while(1) |
94 | { | 83 | { |
95 | 84 | ||
96 | FD_SET(sock, &rset); | 85 | FD_SET(sock, &rset); |
97 | FD_SET(pcap_fileno(handletopcap), &rset); | 86 | FD_SET(pcap_fileno(handletopcap), &rset); |
98 | 87 | ||
99 | /* maxfd = biggest filefd */ | 88 | /* maxfd = biggest filefd */ |
100 | maxfd = (sock > pcap_fileno(handletopcap) ? | 89 | maxfd = (sock > pcap_fileno(handletopcap) ? |
101 | sock + 1 : pcap_fileno(handletopcap)) + 1; | 90 | sock + 1 : pcap_fileno(handletopcap)) + 1; |
102 | 91 | ||
103 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) | 92 | if(select(maxfd, &rset, NULL, NULL, NULL) < 0) |
104 | { | 93 | { |
105 | wl_logerr("Error calling select: %s", strerror(errno)); | 94 | wl_logerr("Error calling select: %s", strerror(errno)); |
106 | break; | 95 | break; |
107 | } | 96 | } |
108 | 97 | ||
109 | /* Got data on local socket from GUI */ | 98 | /* Got data on local socket from GUI */ |
110 | if(FD_ISSET(sock, &rset)) | 99 | if(FD_ISSET(sock, &rset)) |
111 | { | 100 | { |
112 | /* Receive data from socket */ | 101 | /* Receive data from socket */ |
113 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) | 102 | if((retval=wl_recv(&sock, saddr, buffer, sizeof(buffer))) < 0) |
114 | { | 103 | { |
115 | wl_logerr("Error trying to read: %s", strerror(errno)); | 104 | wl_logerr("Error trying to read: %s", strerror(errno)); |
116 | break; | 105 | break; |
117 | } | 106 | } |
118 | else | 107 | else |
119 | { | 108 | { |
120 | /* check type of packet and start function according to it */ | 109 | /* check type of packet and start function according to it */ |
121 | switch(retval) | 110 | switch(retval) |
122 | { | 111 | { |
123 | case STARTSNIFF: | 112 | case STARTSNIFF: |
124 | wl_loginfo("Received STARTSNIFF command"); | 113 | wl_loginfo("Received STARTSNIFF command"); |
125 | if(!send_ok(GUIADDR, GUIPORT, STARTSNIFF)) | 114 | if(!send_ok(GUIADDR, GUIPORT, STARTSNIFF)) |
126 | wl_logerr("Cannot set OK_CMD to GUI"); | 115 | wl_logerr("Cannot set OK_CMD to GUI"); |
127 | break; | 116 | break; |
128 | case STOPSNIFF: | 117 | case STOPSNIFF: |
129 | wl_loginfo("Received STOPSNIFF command"); | 118 | wl_loginfo("Received STOPSNIFF command"); |
130 | if(!send_ok(GUIADDR, GUIPORT, STOPSNIFF)) | 119 | if(!send_ok(GUIADDR, GUIPORT, STOPSNIFF)) |
131 | wl_logerr("Cannot set FAIL_CMD to GUI"); | 120 | wl_logerr("Cannot set FAIL_CMD to GUI"); |
132 | break; | 121 | break; |
133 | default: | 122 | default: |
134 | wl_logerr("Received unknown command: %d", retval); | 123 | wl_logerr("Received unknown command: %d", retval); |
135 | break; | 124 | break; |
136 | } | 125 | } |
137 | } | 126 | } |
138 | } /* FD_ISSET */ | 127 | } /* FD_ISSET */ |
139 | 128 | ||
140 | /* Check pcap lib for packets */ | 129 | /* Check pcap lib for packets */ |
141 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) | 130 | if(FD_ISSET(pcap_fileno(handletopcap), &rset)) |
142 | { | 131 | { |
143 | 132 | ||
144 | /* Grab one single packet */ | 133 | /* Grab one single packet */ |
145 | packet = pcap_next(handletopcap, &header); | 134 | packet = pcap_next(handletopcap, &header); |
146 | 135 | ||
147 | /* process the packet */ | 136 | /* process the packet */ |
148 | process_packets(&header,*&packet, GUIADDR, GUIPORT); | 137 | process_packets(&header,*&packet, GUIADDR, GUIPORT); |
149 | } | 138 | } |
150 | 139 | ||
151 | } /* while(1) */ | 140 | } /* while(1) */ |
152 | 141 | ||
153 | close(sock); | 142 | close(sock); |
154 | exit(EXIT_SUCCESS); | 143 | exit(EXIT_SUCCESS); |
155 | } | 144 | } |
156 | 145 | ||
157 | void | 146 | void |
158 | usage(void) | 147 | usage(void) |
159 | { | 148 | { |
160 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ | 149 | fprintf(stderr, "Usage: wellenreiter <device> <cardtype>\n" \ |
161 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ | 150 | "\t<device> = Wirelessdevice (e.g. wlan0)\n" \ |
162 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ | 151 | "\t<cardtype> = Cardtype:\tCisco\t= 1\n" \ |
163 | "\t\t\t\tNG\t= 2\n" \ | 152 | "\t\t\t\tNG\t= 2\n" \ |
164 | "\t\t\t\tHOSTAP\t= 3\n" \ | 153 | "\t\t\t\tHOSTAP\t= 3\n" \ |
165 | "\t\t\t\tLUCENT\t= 4\n"); | 154 | "\t\t\t\tLUCENT\t= 4\n"); |
166 | exit(EXIT_FAILURE); | 155 | exit(EXIT_FAILURE); |
167 | } | 156 | } |
168 | 157 | ||
169 | void * | 158 | void * |
170 | channel_switcher(void *cardtypeptr) | 159 | channel_switcher(void *cardtypeptr) |
171 | { | 160 | { |
172 | wl_cardtype_t *cardtype; | 161 | wl_cardtype_t *cardtype; |
173 | int maxchan=0; | 162 | int maxchan=0; |
174 | int channel=1; | 163 | int channel=1; |
175 | /* Get card info struct */ | 164 | /* Get card info struct */ |
176 | cardtype = (wl_cardtype_t *)cardtypeptr; | 165 | cardtype = (wl_cardtype_t *)cardtypeptr; |
177 | /* Get from the wireless extension the amount of available channels | 166 | /* Get from the wireless extension the amount of available channels |
178 | this prevents a fail in switching on us cards */ | 167 | this prevents a fail in switching on us cards */ |
179 | maxchan = card_detect_channels(cardtype->iface); | 168 | maxchan = card_detect_channels(cardtype->iface); |
180 | 169 | ||
181 | if (maxchan < MAXCHANNEL) | 170 | if (maxchan < MAXCHANNEL) |
182 | { | 171 | { |
183 | #undef MAXCHANNEL | 172 | #undef MAXCHANNEL |
184 | #define MAXCHANNEL maxchan | 173 | #define MAXCHANNEL maxchan |
185 | } | 174 | } |
186 | 175 | ||
187 | while(1) | 176 | while(1) |
188 | { | 177 | { |
189 | 178 | ||
190 | /* If channel bigger than maxchannel, set to 1 */ | 179 | /* If channel bigger than maxchannel, set to 1 */ |
191 | if(channel > MAXCHANNEL) | 180 | if(channel > MAXCHANNEL) |
192 | channel=1; | 181 | channel=1; |
193 | 182 | ||
194 | /* Set channel */ | 183 | /* Set channel */ |
195 | if(!card_set_channel(cardtype->iface, channel, cardtype->type)) | 184 | if(!card_set_channel(cardtype->iface, channel, cardtype->type)) |
196 | { | 185 | { |
197 | wl_logerr("Cannot set channel, thread exiting"); | 186 | wl_logerr("Cannot set channel, thread exiting"); |
198 | pthread_exit(NULL); | 187 | pthread_exit(NULL); |
199 | } | 188 | } |
200 | 189 | ||
201 | /* sleep */ | 190 | /* sleep */ |
202 | usleep(CHANINTERVAL); | 191 | usleep(CHANINTERVAL); |
203 | 192 | ||
204 | channel++; | 193 | channel++; |
205 | } /* while */ | 194 | } /* while */ |
206 | } | 195 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index 7c9fbc4..4f187c0 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -1,416 +1,451 @@ | |||
1 | /* | 1 | /* |
2 | * Set card modes for sniffing | 2 | * Set card modes for sniffing |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "cardmode.hh" | 7 | #include "cardmode.hh" |
8 | #include "wl_log.hh" | 8 | #include "wl_log.hh" |
9 | 9 | pcap_t *handletopcap; | |
10 | /* main card into monitor function */ | 10 | /* main card into monitor function */ |
11 | int card_into_monitormode (pcap_t **orighandle, const char *device, int cardtype) | 11 | int card_into_monitormode (const char *device, int cardtype) |
12 | { | 12 | { |
13 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | 13 | char CiscoRFMON[35] = "/proc/driver/aironet/"; |
14 | FILE *CISCO_CONFIG_FILE; | 14 | FILE *CISCO_CONFIG_FILE; |
15 | 15 | ||
16 | /* Checks if we have a device to sniff on */ | 16 | /* Checks if we have a device to sniff on */ |
17 | if(device == NULL) | 17 | if(device == NULL) |
18 | { | 18 | { |
19 | wl_logerr("No device given"); | 19 | wl_logerr("No device given"); |
20 | return 0; | 20 | return 0; |
21 | } | 21 | } |
22 | 22 | ||
23 | /* Setting the promiscous and up flag to the interface */ | 23 | /* Setting the promiscous and up flag to the interface */ |
24 | if (!card_set_promisc_up(device)) | 24 | if (!card_set_promisc_up(device)) |
25 | { | 25 | { |
26 | wl_logerr("Cannot set interface to promisc mode"); | 26 | wl_logerr("Cannot set interface to promisc mode"); |
27 | return 0; | 27 | return 0; |
28 | } | 28 | } |
29 | wl_loginfo("Interface set to promisc mode"); | 29 | wl_loginfo("Interface set to promisc mode"); |
30 | 30 | ||
31 | /* Check the cardtype and executes the commands to go into monitor mode */ | 31 | /* Check the cardtype and executes the commands to go into monitor mode */ |
32 | if (cardtype == CARD_TYPE_CISCO) | 32 | if (cardtype == CARD_TYPE_CISCO) |
33 | { | 33 | { |
34 | /* bring the sniffer into rfmon mode */ | 34 | /* bring the sniffer into rfmon mode */ |
35 | snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device); | 35 | snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device); |
36 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) | 36 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) |
37 | { | 37 | { |
38 | wl_logerr("Cannot open config file: %s", strerror(errno)); | 38 | wl_logerr("Cannot open config file: %s", strerror(errno)); |
39 | return 0; | 39 | return 0; |
40 | } | 40 | } |
41 | fputs ("Mode: r",CISCO_CONFIG_FILE); | 41 | fputs ("Mode: r",CISCO_CONFIG_FILE); |
42 | fputs ("Mode: y",CISCO_CONFIG_FILE); | 42 | fputs ("Mode: y",CISCO_CONFIG_FILE); |
43 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | 43 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); |
44 | fclose(CISCO_CONFIG_FILE); | 44 | fclose(CISCO_CONFIG_FILE); |
45 | } | 45 | } |
46 | else if (cardtype == CARD_TYPE_NG) | 46 | else if (cardtype == CARD_TYPE_NG) |
47 | { | 47 | { |
48 | char wlanngcmd[80]; | 48 | char wlanngcmd[80]; |
49 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, 1); | 49 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, 1); |
50 | if (system(wlanngcmd) != 0) | 50 | if (system(wlanngcmd) != 0) |
51 | { | 51 | { |
52 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 52 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
53 | return 0; | 53 | return 0; |
54 | } | 54 | } |
55 | } | 55 | } |
56 | else if (cardtype == CARD_TYPE_HOSTAP) | 56 | else if (cardtype == CARD_TYPE_HOSTAP) |
57 | { | 57 | { |
58 | #if WIRELESS_EXT > 14 | 58 | #if WIRELESS_EXT > 14 |
59 | // IW_MODE_MONITOR was implemented in Wireless Extensions Version 15 | 59 | // IW_MODE_MONITOR was implemented in Wireless Extensions Version 15 |
60 | int skfd; | 60 | int skfd; |
61 | skfd = socket(AF_INET, SOCK_STREAM, 0); | 61 | skfd = socket(AF_INET, SOCK_STREAM, 0); |
62 | struct iwreq wrq; | 62 | struct iwreq wrq; |
63 | wrq.u.mode = IW_MODE_MONITOR; | 63 | wrq.u.mode = IW_MODE_MONITOR; |
64 | 64 | ||
65 | if(iw_set_ext(skfd,(char *) device,SIOCSIWMODE,&wrq)<0) | 65 | if(iw_set_ext(skfd,(char *) device,SIOCSIWMODE,&wrq)<0) |
66 | { | 66 | { |
67 | wl_logerr("Could not set hostap card %s to raw mode, check cardtype", device); | 67 | wl_logerr("Could not set hostap card %s to raw mode, check cardtype", device); |
68 | return 0; | 68 | return 0; |
69 | } | 69 | } |
70 | else | 70 | else |
71 | { | 71 | { |
72 | wl_loginfo("Successfully set hostap card %s into raw mode",device); | 72 | wl_loginfo("Successfully set hostap card %s into raw mode",device); |
73 | return 1; | 73 | return 1; |
74 | } | 74 | } |
75 | return 1; | 75 | return 1; |
76 | #else | 76 | #else |
77 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 77 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
78 | int fd; | 78 | int fd; |
79 | //Wireless tools structure for the iocalls | 79 | //Wireless tools structure for the iocalls |
80 | struct iwreq ireq; | 80 | struct iwreq ireq; |
81 | int *ptr; | 81 | int *ptr; |
82 | /* Socket needed to use the iocall to */ | 82 | /* Socket needed to use the iocall to */ |
83 | fd = socket(AF_INET, SOCK_STREAM, 0); | 83 | fd = socket(AF_INET, SOCK_STREAM, 0); |
84 | 84 | ||
85 | if ( fd == -1 ) { | 85 | if ( fd == -1 ) { |
86 | return -1; | 86 | return -1; |
87 | } | 87 | } |
88 | 88 | ||
89 | ptr = (int *) ireq.u.name; | 89 | ptr = (int *) ireq.u.name; |
90 | // This is the monitor mode for 802.11 non-prism header | 90 | // This is the monitor mode for 802.11 non-prism header |
91 | ptr[0] = 2; | 91 | ptr[0] = 2; |
92 | strcpy(ireq.ifr_ifrn.ifrn_name, device); | 92 | strcpy(ireq.ifr_ifrn.ifrn_name, device); |
93 | if (ioctl( fd, SIOCDEVPRIVATE, &ireq)==0) | 93 | if (ioctl( fd, SIOCDEVPRIVATE, &ireq)==0) |
94 | { | 94 | { |
95 | /* All was fine... */ | 95 | /* All was fine... */ |
96 | close(fd); | 96 | close(fd); |
97 | wl_loginfo("Set hostap card %s into monitormode",device); | 97 | wl_loginfo("Set hostap card %s into monitormode",device); |
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | else | 100 | else |
101 | { | 101 | { |
102 | /* iocall does not work */ | 102 | /* iocall does not work */ |
103 | close(fd); | 103 | close(fd); |
104 | wl_logerr("Could not set hostap card %s into monitormode, check cardtype",device); | 104 | wl_logerr("Could not set hostap card %s into monitormode, check cardtype",device); |
105 | return 0; | 105 | return 0; |
106 | } | 106 | } |
107 | #endif | 107 | #endif |
108 | } | 108 | } |
109 | else if (cardtype == CARD_TYPE_ORINOCCO ) | 109 | else if (cardtype == CARD_TYPE_ORINOCCO ) |
110 | { | 110 | { |
111 | if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) | 111 | if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) |
112 | { | 112 | { |
113 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 113 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
114 | return 0; | 114 | return 0; |
115 | } | 115 | } |
116 | else | 116 | else |
117 | { | 117 | { |
118 | wl_loginfo("Successfully set %s into raw mode",device); | 118 | wl_loginfo("Successfully set %s into raw mode",device); |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | /* Setting the promiscous and up flag to the interface */ | 122 | /* Setting the promiscous and up flag to the interface */ |
123 | if (!card_check_rfmon_datalink(device)) | 123 | if (!card_check_rfmon_datalink(device)) |
124 | { | 124 | { |
125 | wl_logerr("Cannot set interface to rfmon mode"); | 125 | wl_logerr("Cannot set interface to rfmon mode"); |
126 | return 0; | 126 | return 0; |
127 | } | 127 | } |
128 | else | 128 | else |
129 | { | 129 | { |
130 | wl_loginfo("Interface set to rfmon mode"); | 130 | wl_loginfo("Interface set to rfmon mode"); |
131 | } | 131 | } |
132 | return 1; | 132 | return 1; |
133 | } | 133 | } |
134 | 134 | ||
135 | /* Check card is in the rfmon mode */ | 135 | /* Check card is in the rfmon mode */ |
136 | int card_check_rfmon_datalink (const char *device) | 136 | int card_check_rfmon_datalink (const char *device) |
137 | { | 137 | { |
138 | int datalinktype=0; | 138 | int datalinktype=0; |
139 | pcap_t *phandle; | 139 | pcap_t *phandle; |
140 | phandle = pcap_open_live((char *)device, 65,0,0,NULL); | 140 | phandle = pcap_open_live((char *)device, 65,0,0,NULL); |
141 | datalinktype = pcap_datalink (phandle); | 141 | datalinktype = pcap_datalink (phandle); |
142 | pcap_close(phandle); | 142 | pcap_close(phandle); |
143 | 143 | ||
144 | if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | 144 | if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ |
145 | { | 145 | { |
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | else | 148 | else |
149 | { | 149 | { |
150 | wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); | 150 | wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); |
151 | return 1; | 151 | return 1; |
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | /* Ipaq running familiar does not have a loopback device, we need one */ | ||
156 | int check_loopback() | ||
157 | { | ||
158 | /* Checking for a loopback interface with 127.0.0.1, otherwise the other stuff seems to fail on | ||
159 | familiar linux on ipaq's */ | ||
160 | int err; | ||
161 | /* First generate a socket to use with iocalls */ | ||
162 | int fd = socket(AF_INET, SOCK_DGRAM, 0); | ||
163 | if (fd < 0) | ||
164 | { | ||
165 | /* In case of an error */ | ||
166 | wl_logerr("check_loopback, generation of a socket failed, cannot continue"); | ||
167 | return 0; | ||
168 | } | ||
169 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | ||
170 | struct ifreq ifr; | ||
171 | strncpy(ifr.ifr_name, "lo",3); | ||
172 | |||
173 | /* Get the interface flags, loopback interfaces can be detected that way */ | ||
174 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); | ||
175 | if (err < 0) | ||
176 | { | ||
177 | wl_logerr("check_loopback, could not get the flags of lo, check if you got a lo loopback interface, cannot continue"); | ||
178 | close(fd); | ||
179 | return 0; | ||
180 | } | ||
181 | /* Checking the flags for IFF_LOOPBACK flags */ | ||
182 | if(ifr.ifr_flags && IFF_LOOPBACK) | ||
183 | { | ||
184 | /* Yes, we do have a loopback interface....sup! */ | ||
185 | close(fd); | ||
186 | wl_loginfo ("check_loopback, check for loopback interface lo successful"); | ||
187 | return 1; | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | wl_logerr("check_loopback, did not found an interface lo with the IFF_LOOPBACK flag set, cannot continue"); | ||
192 | close(fd); | ||
193 | return 0; | ||
194 | } | ||
195 | /* Should never be reached */ | ||
196 | return 0; | ||
197 | } /*check_loopback */ | ||
198 | |||
199 | |||
155 | /* Set card into promisc mode */ | 200 | /* Set card into promisc mode */ |
156 | int card_set_promisc_up (const char *device) | 201 | int card_set_promisc_up (const char *device) |
157 | { | 202 | { |
158 | int err; | 203 | int err; |
159 | /* First generate a socket to use with iocalls */ | 204 | /* First generate a socket to use with iocalls */ |
160 | int fd = socket(AF_INET, SOCK_DGRAM, 0); | 205 | int fd = socket(AF_INET, SOCK_DGRAM, 0); |
161 | if (fd < 0) | 206 | if (fd < 0) |
162 | { | 207 | { |
163 | /* In case of an error */ | 208 | /* In case of an error */ |
164 | perror("socket"); | 209 | perror("socket"); |
165 | return 0; | 210 | return 0; |
166 | } | 211 | } |
167 | 212 | ||
168 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | 213 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ |
169 | struct ifreq ifr; | 214 | struct ifreq ifr; |
170 | strncpy(ifr.ifr_name, device,10); | 215 | strncpy(ifr.ifr_name, device,10); |
171 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; | 216 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; |
172 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); | 217 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); |
173 | if (err < 0) | 218 | if (err < 0) |
174 | { | 219 | { |
175 | perror("Could not access the interface, "); | 220 | perror("Could not access the interface, "); |
176 | close(fd); | 221 | close(fd); |
177 | return 0; | 222 | return 0; |
178 | } | 223 | } |
179 | 224 | ||
180 | /* Get the informations back from the interface to check if the flags are correct */ | 225 | /* Get the informations back from the interface to check if the flags are correct */ |
181 | strncpy(ifr.ifr_name, device,10); | 226 | strncpy(ifr.ifr_name, device,10); |
182 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); | 227 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); |
183 | if (err < 0) | 228 | if (err < 0) |
184 | { | 229 | { |
185 | perror("Could not access the interface, "); | 230 | perror("Could not access the interface, "); |
186 | close(fd); | 231 | close(fd); |
187 | return 0; | 232 | return 0; |
188 | } | 233 | } |
189 | 234 | ||
190 | if(ifr.ifr_flags && IFF_UP) | 235 | if(ifr.ifr_flags && IFF_UP) |
191 | { | 236 | { |
192 | close(fd); | 237 | close(fd); |
193 | return 1; | 238 | return 1; |
194 | } | 239 | } |
195 | else | 240 | else |
196 | { | 241 | { |
197 | wl_logerr("Could not set promisc flag on %d", device); | 242 | wl_logerr("Could not set promisc flag on %d", device); |
198 | close(fd); | 243 | close(fd); |
199 | return 0; | 244 | return 0; |
200 | } | 245 | } |
201 | } | 246 | } |
202 | 247 | ||
203 | /* Remove card from promisc mode */ | 248 | /* Remove card from promisc mode */ |
204 | int card_remove_promisc (const char *device) | 249 | int card_remove_promisc (const char *device) |
205 | { | 250 | { |
206 | int err; | 251 | int err; |
207 | /* First generate a socket to use with iocalls */ | 252 | /* First generate a socket to use with iocalls */ |
208 | int fd = socket(AF_INET, SOCK_DGRAM, 0); | 253 | int fd = socket(AF_INET, SOCK_DGRAM, 0); |
209 | if (fd < 0) | 254 | if (fd < 0) |
210 | { | 255 | { |
211 | /* In case of an error */ | 256 | /* In case of an error */ |
212 | perror("socket"); | 257 | perror("socket"); |
213 | return 0; | 258 | return 0; |
214 | } | 259 | } |
215 | 260 | ||
216 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | 261 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ |
217 | struct ifreq ifr; | 262 | struct ifreq ifr; |
218 | /* strncpy(ifr.ifr_name, device,10); | ||
219 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; | ||
220 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); | ||
221 | if (err < 0) | ||
222 | { | ||
223 | perror("Could not access the interface, "); | ||
224 | close(fd); | ||
225 | return 0; | ||
226 | } | ||
227 | */ | ||
228 | /* Get the flags from the interface*/ | 263 | /* Get the flags from the interface*/ |
229 | strncpy(ifr.ifr_name, device,10); | 264 | strncpy(ifr.ifr_name, device,10); |
230 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); | 265 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); |
231 | if (err < 0) | 266 | if (err < 0) |
232 | { | 267 | { |
233 | perror("Could not access the interface, "); | 268 | perror("Could not access the interface, "); |
234 | close(fd); | 269 | close(fd); |
235 | return 0; | 270 | return 0; |
236 | } | 271 | } |
237 | /* Remove the IFF_PROMISC flag */ | 272 | /* Remove the IFF_PROMISC flag */ |
238 | ifr.ifr_flags = ifr.ifr_flags - IFF_PROMISC; | 273 | ifr.ifr_flags = ifr.ifr_flags - IFF_PROMISC; |
239 | /*Set the new flags to the interface*/ | 274 | /*Set the new flags to the interface*/ |
240 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); | 275 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); |
241 | if (err < 0) | 276 | if (err < 0) |
242 | { | 277 | { |
243 | perror("Could not access the interface, "); | 278 | perror("Could not access the interface, "); |
244 | close(fd); | 279 | close(fd); |
245 | return 0; | 280 | return 0; |
246 | } | 281 | } |
247 | 282 | ||
248 | /* Get the flags again to check if IFF_PROMISC is removed */ | 283 | /* Get the flags again to check if IFF_PROMISC is removed */ |
249 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); | 284 | err = ioctl(fd, SIOCGIFFLAGS, &ifr); |
250 | if (err < 0) | 285 | if (err < 0) |
251 | { | 286 | { |
252 | perror("Could not access the interface, "); | 287 | perror("Could not access the interface, "); |
253 | close(fd); | 288 | close(fd); |
254 | return 0; | 289 | return 0; |
255 | } | 290 | } |
256 | if(ifr.ifr_flags && IFF_PROMISC) | 291 | if(ifr.ifr_flags && IFF_PROMISC) |
257 | { | 292 | { |
258 | wl_logerr("Could not remove the promisc flag on %d", device); | 293 | wl_logerr("Could not remove the promisc flag on %d", device); |
259 | close(fd); | 294 | close(fd); |
260 | return 0; | 295 | return 0; |
261 | } | 296 | } |
262 | else | 297 | else |
263 | { | 298 | { |
264 | /* Successfully removed the promisc flags */ | 299 | /* Successfully removed the promisc flags */ |
265 | close(fd); | 300 | close(fd); |
266 | return 1; | 301 | return 1; |
267 | } | 302 | } |
268 | } | 303 | } |
269 | 304 | ||
270 | 305 | ||
271 | 306 | ||
272 | 307 | ||
273 | /* Set channel (Wireless frequency) of the device */ | 308 | /* Set channel (Wireless frequency) of the device */ |
274 | int card_set_channel (const char *device, int channel, int cardtype) | 309 | int card_set_channel (const char *device, int channel, int cardtype) |
275 | { | 310 | { |
276 | if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG) | 311 | if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG) |
277 | { | 312 | { |
278 | /* Cisco and wlan-ng drivers don't need channelswitching */ | 313 | /* Cisco and wlan-ng drivers don't need channelswitching */ |
279 | return 1; | 314 | return 1; |
280 | } | 315 | } |
281 | /* If it is a lucent orinocco card */ | 316 | /* If it is a lucent orinocco card */ |
282 | else if (cardtype == CARD_TYPE_ORINOCCO) | 317 | else if (cardtype == CARD_TYPE_ORINOCCO) |
283 | { | 318 | { |
284 | int fd; | 319 | int fd; |
285 | //Wireless tools structure for the iocalls | 320 | //Wireless tools structure for the iocalls |
286 | struct iwreq ireq; | 321 | struct iwreq ireq; |
287 | int *ptr; | 322 | int *ptr; |
288 | /* Socket needed to use the iocall to */ | 323 | /* Socket needed to use the iocall to */ |
289 | fd = socket(AF_INET, SOCK_STREAM, 0); | 324 | fd = socket(AF_INET, SOCK_STREAM, 0); |
290 | 325 | ||
291 | if ( fd == -1 ) { | 326 | if ( fd == -1 ) { |
292 | return -1; | 327 | return -1; |
293 | } | 328 | } |
294 | 329 | ||
295 | ptr = (int *) ireq.u.name; | 330 | ptr = (int *) ireq.u.name; |
296 | // This is the monitor mode for 802.11 non-prism header | 331 | // This is the monitor mode for 802.11 non-prism header |
297 | ptr[0] = 2; | 332 | ptr[0] = 2; |
298 | ptr[1] = channel; | 333 | ptr[1] = channel; |
299 | strcpy(ireq.ifr_ifrn.ifrn_name, device); | 334 | strcpy(ireq.ifr_ifrn.ifrn_name, device); |
300 | if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) | 335 | if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) |
301 | { | 336 | { |
302 | /* All was fine... */ | 337 | /* All was fine... */ |
303 | close(fd); | 338 | close(fd); |
304 | wl_loginfo("Set channel %d on interface %s",channel, device); | 339 | wl_loginfo("Set channel %d on interface %s",channel, device); |
305 | return 1; | 340 | return 1; |
306 | } | 341 | } |
307 | else | 342 | else |
308 | { | 343 | { |
309 | /* iocall does not work */ | 344 | /* iocall does not work */ |
310 | close(fd); | 345 | close(fd); |
311 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); | 346 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); |
312 | return 0; | 347 | return 0; |
313 | } | 348 | } |
314 | } | 349 | } |
315 | /* when it is an hostap card you need another iocall for channel switching */ | 350 | /* when it is an hostap card you need another iocall for channel switching */ |
316 | else if (cardtype == CARD_TYPE_HOSTAP) | 351 | else if (cardtype == CARD_TYPE_HOSTAP) |
317 | { | 352 | { |
318 | int skfd; | 353 | int skfd; |
319 | skfd = socket(AF_INET, SOCK_STREAM, 0); | 354 | skfd = socket(AF_INET, SOCK_STREAM, 0); |
320 | struct iwreq wrq; | 355 | struct iwreq wrq; |
321 | iw_float2freq((double) channel, &wrq.u.freq); | 356 | iw_float2freq((double) channel, &wrq.u.freq); |
322 | 357 | ||
323 | if(iw_set_ext(skfd,(char *) device,SIOCSIWFREQ,&wrq)<0) | 358 | if(iw_set_ext(skfd,(char *) device,SIOCSIWFREQ,&wrq)<0) |
324 | { | 359 | { |
325 | wl_logerr("Could not set hostap card %s to channel %d", device, channel); | 360 | wl_logerr("Could not set hostap card %s to channel %d", device, channel); |
326 | return 0; | 361 | return 0; |
327 | } | 362 | } |
328 | else | 363 | else |
329 | { | 364 | { |
330 | wl_loginfo("Successfully set hostap card %s to channel %d", device, channel); | 365 | wl_loginfo("Successfully set hostap card %s to channel %d", device, channel); |
331 | return 1; | 366 | return 1; |
332 | } | 367 | } |
333 | } | 368 | } |
334 | /* For undefined situations */ | 369 | /* For undefined situations */ |
335 | return 0; | 370 | return 0; |
336 | } | 371 | } |
337 | 372 | ||
338 | 373 | ||
339 | int card_detect_channels (char * device) | 374 | int card_detect_channels (char * device) |
340 | { | 375 | { |
341 | int skfd; | 376 | int skfd; |
342 | skfd = socket(AF_INET, SOCK_STREAM, 0); | 377 | skfd = socket(AF_INET, SOCK_STREAM, 0); |
343 | struct iw_rangerange; | 378 | struct iw_rangerange; |
344 | /* Get list of frequencies / channels */ | 379 | /* Get list of frequencies / channels */ |
345 | printf ("\n hostap card get the frequencies"); | 380 | printf ("\n hostap card get the frequencies"); |
346 | /* Get list of frequencies / channels */ | 381 | /* Get list of frequencies / channels */ |
347 | if(iw_get_range_info(skfd, device, &range) < 0) | 382 | if(iw_get_range_info(skfd, device, &range) < 0) |
348 | { /* We are failsave if something went wrong, asume only 11 channels */ | 383 | { /* We are failsave if something went wrong, asume only 11 channels */ |
349 | return 11; | 384 | return 11; |
350 | } | 385 | } |
351 | else | 386 | else |
352 | { | 387 | { |
353 | if(range.num_frequency > 0) | 388 | if(range.num_frequency > 0) |
354 | { | 389 | { |
355 | return range.num_frequency; | 390 | return range.num_frequency; |
356 | } | 391 | } |
357 | else | 392 | else |
358 | { /* We are failsave asume only 11 channels */ | 393 | { /* We are failsave asume only 11 channels */ |
359 | return 11; | 394 | return 11; |
360 | } | 395 | } |
361 | } | 396 | } |
362 | 397 | ||
363 | } /* End of card_detect_channels */ | 398 | } /* End of card_detect_channels */ |
364 | 399 | ||
365 | int iw_get_range_info(int skfd, const char * ifname, iw_range * range) | 400 | int iw_get_range_info(int skfd, const char * ifname, iw_range * range) |
366 | { | 401 | { |
367 | struct iwreq wrq2; | 402 | struct iwreq wrq2; |
368 | char buffer[sizeof(iw_range) * 2];/* Large enough */ | 403 | char buffer[sizeof(iw_range) * 2];/* Large enough */ |
369 | 404 | ||
370 | /* Cleanup */ | 405 | /* Cleanup */ |
371 | memset(buffer, 0, sizeof(buffer)); | 406 | memset(buffer, 0, sizeof(buffer)); |
372 | wrq2.u.data.pointer = (caddr_t) buffer; | 407 | wrq2.u.data.pointer = (caddr_t) buffer; |
373 | wrq2.u.data.length = sizeof(buffer); | 408 | wrq2.u.data.length = sizeof(buffer); |
374 | wrq2.u.data.flags = 0; | 409 | wrq2.u.data.flags = 0; |
375 | 410 | ||
376 | if(iw_get_ext(skfd, (char *)ifname, SIOCGIWRANGE, &wrq2) < 0) | 411 | if(iw_get_ext(skfd, (char *)ifname, SIOCGIWRANGE, &wrq2) < 0) |
377 | { | 412 | { |
378 | wl_logerr("Could not get the range from the interface"); | 413 | wl_logerr("Could not get the range from the interface"); |
379 | return(-1); | 414 | return(-1); |
380 | } | 415 | } |
381 | else | 416 | else |
382 | { | 417 | { |
383 | /* Copy stuff at the right place, ignore extra */ | 418 | /* Copy stuff at the right place, ignore extra */ |
384 | memcpy((char *) range, buffer, sizeof(iw_range)); | 419 | memcpy((char *) range, buffer, sizeof(iw_range)); |
385 | return 0; | 420 | return 0; |
386 | } | 421 | } |
387 | } | 422 | } |
388 | 423 | ||
389 | /*------------------------------------------------------------------*/ | 424 | /*------------------------------------------------------------------*/ |
390 | /* | 425 | /* |
391 | * Convert our internal representation of frequencies to a floating point. | 426 | * Convert our internal representation of frequencies to a floating point. |
392 | */ | 427 | */ |
393 | double iw_freq2float(iw_freq * in) | 428 | double iw_freq2float(iw_freq * in) |
394 | { | 429 | { |
395 | int i; | 430 | int i; |
396 | double res = (double) in->m; | 431 | double res = (double) in->m; |
397 | for(i = 0; i < in->e; i++) | 432 | for(i = 0; i < in->e; i++) |
398 | res *= 10; | 433 | res *= 10; |
399 | return(res); | 434 | return(res); |
400 | } | 435 | } |
401 | 436 | ||
402 | 437 | ||
403 | void iw_float2freq(double in, iw_freq *out) | 438 | void iw_float2freq(double in, iw_freq *out) |
404 | { | 439 | { |
405 | /* Version without libm : slower */ | 440 | /* Version without libm : slower */ |
406 | out->e = 0; | 441 | out->e = 0; |
407 | while(in > 1e9) | 442 | while(in > 1e9) |
408 | { | 443 | { |
409 | in /= 10; | 444 | in /= 10; |
410 | out->e++; | 445 | out->e++; |
411 | } | 446 | } |
412 | out->m = (long) in; | 447 | out->m = (long) in; |
413 | } | 448 | } |
414 | 449 | ||
415 | 450 | ||
416 | 451 | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index 58e99ac..73e0ae1 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -1,105 +1,107 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef CARDMODE_HH | 3 | #ifndef CARDMODE_HH |
4 | #define CARDMODE_HH | 4 | #define CARDMODE_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <errno.h> | 8 | #include <errno.h> |
9 | #include <sys/types.h> | 9 | #include <sys/types.h> |
10 | #include <sys/time.h> | 10 | #include <sys/time.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 <sys/ioctl.h> | 14 | #include <sys/ioctl.h> |
15 | #include <unistd.h> | 15 | #include <unistd.h> |
16 | #include <linux/if.h> | 16 | #include <linux/if.h> |
17 | 17 | ||
18 | /* Following typedefs are needed here, because linux/wireless.h | 18 | /* Following typedefs are needed here, because linux/wireless.h |
19 | includes linux/ethertool.h which is using them */ | 19 | includes linux/ethertool.h which is using them */ |
20 | typedef signed char s8; | 20 | typedef signed char s8; |
21 | typedef unsigned char u8; | 21 | typedef unsigned char u8; |
22 | typedef signed short s16; | 22 | typedef signed short s16; |
23 | typedef unsigned short u16; | 23 | typedef unsigned short u16; |
24 | typedef signed int s32; | 24 | typedef signed int s32; |
25 | typedef unsigned int u32; | 25 | typedef unsigned int u32; |
26 | typedef signed long long s64; | 26 | typedef signed long long s64; |
27 | typedef unsigned long long u64; | 27 | typedef unsigned long long u64; |
28 | 28 | ||
29 | #include <linux/wireless.h> | 29 | #include <linux/wireless.h> |
30 | 30 | ||
31 | #ifndef SIOCIWFIRSTPRIV | 31 | #ifndef SIOCIWFIRSTPRIV |
32 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE | 32 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | extern "C" | 35 | extern "C" |
36 | { | 36 | { |
37 | #include <net/bpf.h> | 37 | #include <net/bpf.h> |
38 | #include <pcap.h> | 38 | #include <pcap.h> |
39 | } | 39 | } |
40 | 40 | ||
41 | extern pcap_t *handletopcap; | ||
42 | |||
41 | /* Defines, used for the card setup */ | 43 | /* Defines, used for the card setup */ |
42 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 44 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
43 | #define CISCO_STATUS "/proc/driver/aironet/%s/Status" | 45 | #define CISCO_STATUS "/proc/driver/aironet/%s/Status" |
44 | #define CARD_TYPE_CISCO 1 | 46 | #define CARD_TYPE_CISCO 1 |
45 | #define CARD_TYPE_NG 2 | 47 | #define CARD_TYPE_NG 2 |
46 | #define CARD_TYPE_HOSTAP 3 | 48 | #define CARD_TYPE_HOSTAP 3 |
47 | #define CARD_TYPE_ORINOCCO 4 | 49 | #define CARD_TYPE_ORINOCCO 4 |
48 | 50 | ||
49 | /* Some usefull constants for frequencies */ | 51 | /* Some usefull constants for frequencies */ |
50 | #define KILO 1e3 | 52 | #define KILO 1e3 |
51 | #define MEGA 1e6 | 53 | #define MEGA 1e6 |
52 | #define GIGA 1e9 | 54 | #define GIGA 1e9 |
53 | 55 | ||
54 | 56 | ||
55 | /* only for now, until we have the daemon running */ | 57 | /* only for now, until we have the daemon running */ |
56 | /*the config file should provide these information */ | 58 | /*the config file should provide these information */ |
57 | #define CARD_TYPE CARD_TYPE_HOSTAP | 59 | #define CARD_TYPE CARD_TYPE_HOSTAP |
58 | 60 | ||
59 | /* Prototypes */ | 61 | /* Prototypes */ |
60 | int card_check_rfmon_datalink (const char *device); | 62 | int card_check_rfmon_datalink (const char *device); |
61 | int card_into_monitormode (pcap_t **, const char *, int); | 63 | int card_into_monitormode (const char *, int); |
64 | int check_loopback(); | ||
62 | int card_set_promisc_up (const char *device); | 65 | int card_set_promisc_up (const char *device); |
63 | int card_remove_promisc (const char *device); | 66 | int card_remove_promisc (const char *device); |
64 | int card_set_channel (const char *device, int channel,int cardtype); | 67 | int card_set_channel (const char *device, int channel,int cardtype); |
65 | int iw_get_range_info(int skfd, const char * ifname, struct iw_range * range); | 68 | int iw_get_range_info(int skfd, const char * ifname, struct iw_range * range); |
66 | double iw_freq2float(iw_freq * in); | 69 | double iw_freq2float(iw_freq * in); |
67 | void iw_float2freq(double in, iw_freq *out); | 70 | void iw_float2freq(double in, iw_freq *out); |
68 | int card_detect_channels (char * device); | 71 | int card_detect_channels (char * device); |
69 | 72 | ||
70 | |||
71 | /*------------------------------------------------------------------*/ | 73 | /*------------------------------------------------------------------*/ |
72 | /* | 74 | /* |
73 | * Wrapper to push some Wireless Parameter in the driver | 75 | * Wrapper to push some Wireless Parameter in the driver |
74 | */ | 76 | */ |
75 | static inline int | 77 | static inline int |
76 | iw_set_ext(int skfd, /* Socket to the kernel */ | 78 | iw_set_ext(int skfd, /* Socket to the kernel */ |
77 | char * ifname, /* Device name */ | 79 | char * ifname, /* Device name */ |
78 | int request,/* WE ID */ | 80 | int request,/* WE ID */ |
79 | struct iwreq * pwrq) /* Fixed part of the request */ | 81 | struct iwreq * pwrq) /* Fixed part of the request */ |
80 | { | 82 | { |
81 | /* Set device name */ | 83 | /* Set device name */ |
82 | strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); | 84 | strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); |
83 | /* Do the request */ | 85 | /* Do the request */ |
84 | return(ioctl(skfd, request, pwrq)); | 86 | return(ioctl(skfd, request, pwrq)); |
85 | } | 87 | } |
86 | 88 | ||
87 | /*------------------------------------------------------------------*/ | 89 | /*------------------------------------------------------------------*/ |
88 | /* | 90 | /* |
89 | * Wrapper to extract some Wireless Parameter out of the driver | 91 | * Wrapper to extract some Wireless Parameter out of the driver |
90 | */ | 92 | */ |
91 | static inline int | 93 | static inline int |
92 | iw_get_ext(int skfd, /* Socket to the kernel */ | 94 | iw_get_ext(int skfd, /* Socket to the kernel */ |
93 | char * ifname, /* Device name */ | 95 | char * ifname, /* Device name */ |
94 | int request,/* WE ID */ | 96 | int request,/* WE ID */ |
95 | struct iwreq * pwrq) /* Fixed part of the request */ | 97 | struct iwreq * pwrq) /* Fixed part of the request */ |
96 | { | 98 | { |
97 | /* Set device name */ | 99 | /* Set device name */ |
98 | strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); | 100 | strncpy(pwrq->ifr_name, ifname, IFNAMSIZ); |
99 | /* Do the request */ | 101 | /* Do the request */ |
100 | return(ioctl(skfd, request, pwrq)); | 102 | return(ioctl(skfd, request, pwrq)); |
101 | } | 103 | } |
102 | 104 | ||
103 | 105 | ||
104 | 106 | ||
105 | #endif /* CARDMODE_HH */ | 107 | #endif /* CARDMODE_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc index 6e512c4..0616a7e 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc | |||
@@ -1,268 +1,339 @@ | |||
1 | /* | 1 | /* |
2 | * rfmon mode sniffer | 2 | * rfmon mode sniffer |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "sniff.hh" | 7 | #include "sniff.hh" |
8 | #include "ieee802_11.hh" | 8 | #include "ieee802_11.hh" |
9 | #include "extract.hh" | 9 | #include "extract.hh" |
10 | #include "wl_log.hh" | 10 | #include "wl_log.hh" |
11 | #include "wl_types.hh" | 11 | #include "wl_types.hh" |
12 | #include "wl_proto.hh" | 12 | #include "wl_proto.hh" |
13 | #include "cardmode.hh" | ||
14 | |||
15 | int start_sniffer(const char *device, int cardtype ) | ||
16 | { | ||
17 | |||
18 | /* This function initialize the sniffing | ||
19 | 1. Check for lo interface | ||
20 | 2. bring it into promsicous mode and UP | ||
21 | 3. bring device into rfmon mode | ||
22 | start the pcap sniffing process. | ||
23 | */ | ||
24 | |||
25 | /* Do we have the device name ? */ | ||
26 | if(device == NULL) | ||
27 | { | ||
28 | wl_logerr("start_sniffer, parameter \"device\" is empty, please check your config"); | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | /* Some Linux System does not have a loopback device lo with 127.0.0.1 so sockets could | ||
33 | not made correctly, let the proggie check that and proceed only if it exists. */ | ||
34 | if (!check_loopback()) | ||
35 | { | ||
36 | wl_logerr("start_sniffer, check_loopback failed, cannot continue without a loopback"); | ||
37 | return 0; | ||
38 | } | ||
39 | |||
40 | /* Set the card into regulary promiscous mode first and set the UP flag, in case no ip | ||
41 | was given. It would work without the promisc flags but i dont like this */ | ||
42 | if (!card_set_promisc_up(device)) | ||
43 | { | ||
44 | wl_logerr("start_sniffer, card_set_promisc_up failed, cannot continue"); | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | /* Set card into the rfmon/monitoring mode */ | ||
49 | if (!card_into_monitormode(device,cardtype)) | ||
50 | { | ||
51 | wl_logerr("start_sniffer, cannot put wireless card into monitoring mode, aborting"); | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | /* setup pcap handle, used for the packet decoding etc. */ | ||
56 | if((handletopcap = pcap_open_live((char *) device, BUFSIZ, 1, 0, NULL)) == NULL) | ||
57 | { | ||
58 | wl_logerr("pcap_open_live() failed: %s", strerror(errno)); | ||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | #ifdef HAVE_PCAP_NONBLOCK | ||
63 | pcap_setnonblock(handletopcap, 1, NULL); | ||
64 | #endif | ||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | |||
69 | int stop_sniffer(const char *device, int cardtype) | ||
70 | { | ||
71 | /* This function terminates the sniffing | ||
72 | 1. get the device state | ||
73 | 2. remove the rfmon state | ||
74 | 3. Remove the promisc state | ||
75 | start the pcap sniffing process. | ||
76 | |||
77 | */ | ||
78 | |||
79 | /* Do we really have at least a lo interface with the 127.0.0.1 ? */ | ||
80 | return 0; | ||
81 | |||
82 | } | ||
83 | |||
13 | 84 | ||
14 | /* Main function, checks packets */ | 85 | /* Main function, checks packets */ |
15 | void process_packets(const struct pcap_pkthdr *pkthdr, | 86 | void process_packets(const struct pcap_pkthdr *pkthdr, |
16 | const unsigned char *packet, | 87 | const unsigned char *packet, |
17 | char *guihost, | 88 | char *guihost, |
18 | int guiport) | 89 | int guiport) |
19 | { | 90 | { |
20 | unsigned int caplen = pkthdr->caplen; | 91 | unsigned int caplen = pkthdr->caplen; |
21 | unsigned int length = pkthdr->len; | 92 | unsigned int length = pkthdr->len; |
22 | u_int16_t fc; | 93 | u_int16_t fc; |
23 | unsigned int HEADER_LENGTH; | 94 | unsigned int HEADER_LENGTH; |
24 | 95 | ||
25 | /* pinfo holds all interresting information for us */ | 96 | /* pinfo holds all interresting information for us */ |
26 | struct packetinfo pinfo; | 97 | struct packetinfo pinfo; |
27 | struct packetinfo *pinfoptr; | 98 | struct packetinfo *pinfoptr; |
28 | 99 | ||
29 | /* wl_network_t will finally be set and send to the ui */ | 100 | /* wl_network_t will finally be set and send to the ui */ |
30 | wl_network_t wl_net; | 101 | wl_network_t wl_net; |
31 | 102 | ||
32 | pinfoptr=&pinfo; | 103 | pinfoptr=&pinfo; |
33 | 104 | ||
34 | pinfoptr->isvalid = 0; | 105 | pinfoptr->isvalid = 0; |
35 | pinfoptr->pktlen = pkthdr->len; | 106 | pinfoptr->pktlen = pkthdr->len; |
36 | 107 | ||
37 | if (caplen < IEEE802_11_FC_LEN) | 108 | if (caplen < IEEE802_11_FC_LEN) |
38 | { | 109 | { |
39 | /* This is a garbage packet, because is does not long enough | 110 | /* This is a garbage packet, because is does not long enough |
40 | to hold a 802.11b header */ | 111 | to hold a 802.11b header */ |
41 | pinfoptr->isvalid = 0; | 112 | pinfoptr->isvalid = 0; |
42 | return; | 113 | return; |
43 | } | 114 | } |
44 | 115 | ||
45 | /* Gets the framecontrol bits (2bytes long) */ | 116 | /* Gets the framecontrol bits (2bytes long) */ |
46 | fc = EXTRACT_LE_16BITS(packet); | 117 | fc = EXTRACT_LE_16BITS(packet); |
47 | 118 | ||
48 | HEADER_LENGTH = GetHeaderLength(fc); | 119 | HEADER_LENGTH = GetHeaderLength(fc); |
49 | 120 | ||
50 | if (caplen < HEADER_LENGTH) | 121 | if (caplen < HEADER_LENGTH) |
51 | { | 122 | { |
52 | /* This is a garbage packet, because it is not long enough | 123 | /* This is a garbage packet, because it is not long enough |
53 | to hold a correct header of its type */ | 124 | to hold a correct header of its type */ |
54 | pinfoptr->isvalid = 0; | 125 | pinfoptr->isvalid = 0; |
55 | return; | 126 | return; |
56 | } | 127 | } |
57 | 128 | ||
58 | /* Decode 802.11b header out of the packet */ | 129 | /* Decode 802.11b header out of the packet */ |
59 | if (decode_80211b_hdr(packet,pinfoptr) == 0) | 130 | if (decode_80211b_hdr(packet,pinfoptr) == 0) |
60 | { | 131 | { |
61 | /* Justification of the ofset to further process the packet */ | 132 | /* Justification of the ofset to further process the packet */ |
62 | length -= HEADER_LENGTH; | 133 | length -= HEADER_LENGTH; |
63 | caplen -= HEADER_LENGTH; | 134 | caplen -= HEADER_LENGTH; |
64 | packet += HEADER_LENGTH; | 135 | packet += HEADER_LENGTH; |
65 | } | 136 | } |
66 | else /* Something is wrong,could not be a correct packet */ | 137 | else /* Something is wrong,could not be a correct packet */ |
67 | return; | 138 | return; |
68 | 139 | ||
69 | switch (FC_TYPE(fc)) | 140 | switch (FC_TYPE(fc)) |
70 | { | 141 | { |
71 | /* Is it a managemnet frame? */ | 142 | /* Is it a managemnet frame? */ |
72 | case T_MGMT: | 143 | case T_MGMT: |
73 | switch (FC_SUBTYPE(fc)) | 144 | switch (FC_SUBTYPE(fc)) |
74 | { | 145 | { |
75 | case ST_BEACON: | 146 | case ST_BEACON: |
76 | if (handle_beacon(fc, packet,pinfoptr) ==0) | 147 | if (handle_beacon(fc, packet,pinfoptr) ==0) |
77 | { | 148 | { |
78 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) | 149 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) |
79 | { | 150 | { |
80 | /* Every beacon must have the broadcast as destination | 151 | /* Every beacon must have the broadcast as destination |
81 | so it must be a shitti packet */ | 152 | so it must be a shitti packet */ |
82 | pinfoptr->isvalid = 0; | 153 | pinfoptr->isvalid = 0; |
83 | return; | 154 | return; |
84 | } | 155 | } |
85 | 156 | ||
86 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) | 157 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) |
87 | { | 158 | { |
88 | /* Only one of both are possible, so must be | 159 | /* Only one of both are possible, so must be |
89 | a noise packet, if this comes up */ | 160 | a noise packet, if this comes up */ |
90 | pinfoptr->isvalid = 0; | 161 | pinfoptr->isvalid = 0; |
91 | return; | 162 | return; |
92 | } | 163 | } |
93 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) | 164 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) |
94 | { | 165 | { |
95 | /* Only channels between 1 and 14 are possible | 166 | /* Only channels between 1 and 14 are possible |
96 | others must be noise packets */ | 167 | others must be noise packets */ |
97 | pinfoptr->isvalid = 0; | 168 | pinfoptr->isvalid = 0; |
98 | return; | 169 | return; |
99 | } | 170 | } |
100 | 171 | ||
101 | /* Here should be the infos to the gui issued */ | 172 | /* Here should be the infos to the gui issued */ |
102 | if (pinfoptr->cap_ESS == 1 && pinfoptr->cap_IBSS ==0) | 173 | if (pinfoptr->cap_ESS == 1 && pinfoptr->cap_IBSS ==0) |
103 | { | 174 | { |
104 | wl_loginfo("Found an access point"); | 175 | wl_loginfo("Found an access point"); |
105 | wl_net.net_type=1; | 176 | wl_net.net_type=1; |
106 | } | 177 | } |
107 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) | 178 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) |
108 | { | 179 | { |
109 | wl_loginfo("Found an ad-hoc network"); | 180 | wl_loginfo("Found an ad-hoc network"); |
110 | wl_net.net_type=2; | 181 | wl_net.net_type=2; |
111 | } | 182 | } |
112 | 183 | ||
113 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) | 184 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) |
114 | wl_loginfo("Net is a non-broadcasting network"); | 185 | wl_loginfo("Net is a non-broadcasting network"); |
115 | else | 186 | else |
116 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 187 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
117 | 188 | ||
118 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 189 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
119 | memset(wl_net.bssid, 0, sizeof(wl_net.bssid)); | 190 | memset(wl_net.bssid, 0, sizeof(wl_net.bssid)); |
120 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); | 191 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); |
121 | 192 | ||
122 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); | 193 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); |
123 | wl_net.ssid_len=pinfoptr->ssid_len; | 194 | wl_net.ssid_len=pinfoptr->ssid_len; |
124 | 195 | ||
125 | wl_loginfo("Channel is: %d", pinfoptr->channel); | 196 | wl_loginfo("Channel is: %d", pinfoptr->channel); |
126 | wl_net.channel=pinfoptr->channel; | 197 | wl_net.channel=pinfoptr->channel; |
127 | wl_net.wep=pinfoptr->cap_WEP; | 198 | wl_net.wep=pinfoptr->cap_WEP; |
128 | 199 | ||
129 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); | 200 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); |
130 | memset(wl_net.mac, 0, sizeof(wl_net.mac)); | 201 | memset(wl_net.mac, 0, sizeof(wl_net.mac)); |
131 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1); | 202 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1); |
132 | 203 | ||
133 | if(!send_network_found((char *)guihost, guiport, &wl_net)) | 204 | if(!send_network_found((char *)guihost, guiport, &wl_net)) |
134 | { | 205 | { |
135 | wl_logerr("Error sending data to UI: %s", strerror(errno)); | 206 | wl_logerr("Error sending data to UI: %s", strerror(errno)); |
136 | break; | 207 | break; |
137 | } | 208 | } |
138 | wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); | 209 | wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); |
139 | } | 210 | } |
140 | break; | 211 | break; |
141 | 212 | ||
142 | default: | 213 | default: |
143 | wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); | 214 | wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); |
144 | break; | 215 | break; |
145 | } /* End of switch over different mgt frame types */ | 216 | } /* End of switch over different mgt frame types */ |
146 | 217 | ||
147 | break; | 218 | break; |
148 | 219 | ||
149 | case T_CTRL: | 220 | case T_CTRL: |
150 | wl_loginfo("Received control frame, not implemented yet"); | 221 | wl_loginfo("Received control frame, not implemented yet"); |
151 | break; | 222 | break; |
152 | 223 | ||
153 | case T_DATA: | 224 | case T_DATA: |
154 | wl_loginfo("Received date frame, not implemented yet"); | 225 | wl_loginfo("Received date frame, not implemented yet"); |
155 | break; | 226 | break; |
156 | 227 | ||
157 | default: | 228 | default: |
158 | wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); | 229 | wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); |
159 | break; | 230 | break; |
160 | } | 231 | } |
161 | } | 232 | } |
162 | 233 | ||
163 | /* This decodes the 802.11b frame header out of the 802.11b packet | 234 | /* This decodes the 802.11b frame header out of the 802.11b packet |
164 | all the infos is placed into the packetinfo structure */ | 235 | all the infos is placed into the packetinfo structure */ |
165 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) | 236 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) |
166 | { | 237 | { |
167 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; | 238 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; |
168 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); | 239 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); |
169 | 240 | ||
170 | /* Get the sender, bssid and dest mac address */ | 241 | /* Get the sender, bssid and dest mac address */ |
171 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); | 242 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); |
172 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); | 243 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); |
173 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); | 244 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); |
174 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); | 245 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); |
175 | return 0; | 246 | return 0; |
176 | } | 247 | } |
177 | 248 | ||
178 | 249 | ||
179 | void etheraddr_string(register const u_char *ep, char *text) | 250 | void etheraddr_string(register const u_char *ep, char *text) |
180 | { | 251 | { |
181 | static char hex[] = "0123456789abcdef"; | 252 | static char hex[] = "0123456789abcdef"; |
182 | register unsigned int i, j; | 253 | register unsigned int i, j; |
183 | register char *cp; | 254 | register char *cp; |
184 | char buf[sizeof("00:00:00:00:00:00\0")]; | 255 | char buf[sizeof("00:00:00:00:00:00\0")]; |
185 | cp = buf; | 256 | cp = buf; |
186 | if ((j = *ep >> 4) != 0) | 257 | if ((j = *ep >> 4) != 0) |
187 | { | 258 | { |
188 | *cp++ = hex[j]; | 259 | *cp++ = hex[j]; |
189 | } | 260 | } |
190 | else | 261 | else |
191 | { | 262 | { |
192 | *cp++ = '0'; | 263 | *cp++ = '0'; |
193 | } | 264 | } |
194 | *cp++ = hex[*ep++ & 0xf]; | 265 | *cp++ = hex[*ep++ & 0xf]; |
195 | 266 | ||
196 | for (i = 5; (int)--i >= 0;) | 267 | for (i = 5; (int)--i >= 0;) |
197 | { | 268 | { |
198 | *cp++ = ':'; | 269 | *cp++ = ':'; |
199 | if ((j = *ep >> 4) != 0) | 270 | if ((j = *ep >> 4) != 0) |
200 | { | 271 | { |
201 | *cp++ = hex[j]; | 272 | *cp++ = hex[j]; |
202 | } | 273 | } |
203 | else | 274 | else |
204 | { | 275 | { |
205 | *cp++ = '0'; | 276 | *cp++ = '0'; |
206 | } | 277 | } |
207 | 278 | ||
208 | *cp++ = hex[*ep++ & 0xf]; | 279 | *cp++ = hex[*ep++ & 0xf]; |
209 | } | 280 | } |
210 | *cp = '\0'; | 281 | *cp = '\0'; |
211 | strcpy(text,buf); | 282 | strcpy(text,buf); |
212 | } | 283 | } |
213 | 284 | ||
214 | /* beacon handler */ | 285 | /* beacon handler */ |
215 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | 286 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) |
216 | { | 287 | { |
217 | struct mgmt_body_t pbody; | 288 | struct mgmt_body_t pbody; |
218 | int offset = 0; | 289 | int offset = 0; |
219 | 290 | ||
220 | /* Get the static informations out of the packet */ | 291 | /* Get the static informations out of the packet */ |
221 | memset(&pbody, 0, sizeof(pbody)); | 292 | memset(&pbody, 0, sizeof(pbody)); |
222 | memcpy(&pbody.timestamp, p, 8); | 293 | memcpy(&pbody.timestamp, p, 8); |
223 | offset += 8; | 294 | offset += 8; |
224 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); | 295 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); |
225 | offset += 2; | 296 | offset += 2; |
226 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); | 297 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); |
227 | offset += 2; | 298 | offset += 2; |
228 | 299 | ||
229 | /* Gets the different flags out of the capabilities */ | 300 | /* Gets the different flags out of the capabilities */ |
230 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); | 301 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); |
231 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); | 302 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); |
232 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); | 303 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); |
233 | 304 | ||
234 | /* Gets the tagged elements out of the packets */ | 305 | /* Gets the tagged elements out of the packets */ |
235 | while (offset + 1 < ppinfo->pktlen) | 306 | while (offset + 1 < ppinfo->pktlen) |
236 | { | 307 | { |
237 | switch (*(p + offset)) | 308 | switch (*(p + offset)) |
238 | { | 309 | { |
239 | case E_SSID: | 310 | case E_SSID: |
240 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; | 311 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; |
241 | if (pbody.ssid.length > 0) | 312 | if (pbody.ssid.length > 0) |
242 | { | 313 | { |
243 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); | 314 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); |
244 | offset += pbody.ssid.length; | 315 | offset += pbody.ssid.length; |
245 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | 316 | pbody.ssid.ssid[pbody.ssid.length]='\0'; |
246 | if (strcmp((char *)pbody.ssid.ssid,"")==0) | 317 | if (strcmp((char *)pbody.ssid.ssid,"")==0) |
247 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); | 318 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); |
248 | else | 319 | else |
249 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); | 320 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); |
250 | ppinfo->ssid_len = pbody.ssid.length; | 321 | ppinfo->ssid_len = pbody.ssid.length; |
251 | } | 322 | } |
252 | break; | 323 | break; |
253 | 324 | ||
254 | case E_CHALLENGE: | 325 | case E_CHALLENGE: |
255 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | 326 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; |
256 | if (pbody.challenge.length > 0) | 327 | if (pbody.challenge.length > 0) |
257 | { | 328 | { |
258 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); | 329 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); |
259 | offset += pbody.challenge.length; | 330 | offset += pbody.challenge.length; |
260 | pbody.challenge.text[pbody.challenge.length]='\0'; | 331 | pbody.challenge.text[pbody.challenge.length]='\0'; |
261 | } | 332 | } |
262 | break; | 333 | break; |
263 | case E_RATES: | 334 | case E_RATES: |
264 | memcpy(&(pbody.rates),p+offset,2); offset += 2; | 335 | memcpy(&(pbody.rates),p+offset,2); offset += 2; |
265 | if (pbody.rates.length > 0) | 336 | if (pbody.rates.length > 0) |
266 | { | 337 | { |
267 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); | 338 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); |
268 | offset += pbody.rates.length; | 339 | offset += pbody.rates.length; |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh index c7108ac..a4cf4b7 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh | |||
@@ -1,70 +1,73 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef SNIFF_HH | 3 | #ifndef SNIFF_HH |
4 | #define SNIFF_HH | 4 | #define SNIFF_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 <errno.h> | 9 | #include <errno.h> |
10 | #include <sys/types.h> | 10 | #include <sys/types.h> |
11 | #include <sys/time.h> | 11 | #include <sys/time.h> |
12 | #include <sys/socket.h> | 12 | #include <sys/socket.h> |
13 | #include <netinet/in.h> | 13 | #include <netinet/in.h> |
14 | #include <arpa/inet.h> | 14 | #include <arpa/inet.h> |
15 | 15 | ||
16 | extern "C" | 16 | extern "C" |
17 | { | 17 | { |
18 | #include <net/bpf.h> | 18 | #include <net/bpf.h> |
19 | #include <pcap.h> | 19 | #include <pcap.h> |
20 | } | 20 | } |
21 | 21 | ||
22 | #define NONBROADCASTING "non-broadcasting" | 22 | #define NONBROADCASTING "non-broadcasting" |
23 | 23 | ||
24 | /* holds all the interresting data */ | 24 | /* holds all the interresting data */ |
25 | struct packetinfo | 25 | struct packetinfo |
26 | { | 26 | { |
27 | int isvalid; | 27 | int isvalid; |
28 | int pktlen; | 28 | int pktlen; |
29 | int fctype; | 29 | int fctype; |
30 | int fcsubtype; | 30 | int fcsubtype; |
31 | int fc_wep; | 31 | int fc_wep; |
32 | int cap_WEP; | 32 | int cap_WEP; |
33 | int cap_IBSS; | 33 | int cap_IBSS; |
34 | int cap_ESS; | 34 | int cap_ESS; |
35 | int channel; | 35 | int channel; |
36 | char bssid[sizeof("00:00:00:00:00:00") + 1]; | 36 | char bssid[sizeof("00:00:00:00:00:00") + 1]; |
37 | char desthwaddr[sizeof("00:00:00:00:00:00") + 1]; | 37 | char desthwaddr[sizeof("00:00:00:00:00:00") + 1]; |
38 | char sndhwaddr[sizeof("00:00:00:00:00:00") + 1]; | 38 | char sndhwaddr[sizeof("00:00:00:00:00:00") + 1]; |
39 | char ssid[128]; | 39 | char ssid[128]; |
40 | int ssid_len; | 40 | int ssid_len; |
41 | }; | 41 | }; |
42 | 42 | ||
43 | /* Function definitions */ | ||
44 | /* Used for stoping and starting the sniffer process */ | ||
45 | int start_sniffer(const char *device, int cardtype); | ||
46 | int stop_sniffer(const char *device, int cardtype); | ||
43 | void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int); | 47 | void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int); |
44 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); | 48 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); |
45 | void etheraddr_string(register const u_char *ep,char * text); | 49 | void etheraddr_string(register const u_char *ep,char * text); |
46 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | 50 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); |
47 | |||
48 | int GetHeaderLength(u_int16_t fc); | 51 | int GetHeaderLength(u_int16_t fc); |
49 | 52 | ||
50 | /* | 53 | /* |
51 | * True if "l" bytes of "var" were captured. | 54 | * True if "l" bytes of "var" were captured. |
52 | * | 55 | * |
53 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large | 56 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large |
54 | * that "snapend - (l)" underflows. | 57 | * that "snapend - (l)" underflows. |
55 | * | 58 | * |
56 | * The check is for <= rather than < because "l" might be 0. | 59 | * The check is for <= rather than < because "l" might be 0. |
57 | */ | 60 | */ |
58 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ | 61 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ |
59 | (const u_char *)&(var) <= snapend - (l)) | 62 | (const u_char *)&(var) <= snapend - (l)) |
60 | 63 | ||
61 | /* True if "var" was captured */ | 64 | /* True if "var" was captured */ |
62 | #define TTEST(var) TTEST2(var, sizeof(var)) | 65 | #define TTEST(var) TTEST2(var, sizeof(var)) |
63 | 66 | ||
64 | /* Bail if "l" bytes of "var" were not captured */ | 67 | /* Bail if "l" bytes of "var" were not captured */ |
65 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc | 68 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc |
66 | 69 | ||
67 | /* Bail if "var" was not captured */ | 70 | /* Bail if "var" was not captured */ |
68 | #define TCHECK(var) TCHECK2(var, sizeof(var)) | 71 | #define TCHECK(var) TCHECK2(var, sizeof(var)) |
69 | 72 | ||
70 | #endif /* SNIFF_HH */ | 73 | #endif /* SNIFF_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh index cd482fe..afc105c 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh | |||
@@ -1,42 +1,43 @@ | |||
1 | /* | 1 | /* |
2 | * Global bufffer size and type definitions | 2 | * Global bufffer size and type definitions |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | * | 5 | * |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef WL_TYPES_HH | 8 | #ifndef WL_TYPES_HH |
9 | #define WL_TYPES_HH | 9 | #define WL_TYPES_HH |
10 | 10 | ||
11 | /* Type definitions, to be continued */ | 11 | /* Type definitions, to be continued */ |
12 | #define WL_NETFOUND 01 | 12 | #define WL_NETFOUND 01 |
13 | #define WL_NETLOST 02 | 13 | #define WL_NETLOST 02 |
14 | #define WL_STARTSNIFF 98 | 14 | #define WL_STARTSNIFF 98 |
15 | #define WL_STOPSNIFF 99 | 15 | #define WL_STOPSNIFF 99 |
16 | 16 | ||
17 | /* Socket specific */ | 17 | /* Socket specific */ |
18 | #define WL_SOCKBUF 512 /* Buffer for wl_send and wl_recv calls */ | 18 | #define WL_SOCKBUF 512 /* Buffer for wl_send and wl_recv calls */ |
19 | 19 | ||
20 | /* Channelswitching */ | 20 | /* Channelswitching */ |
21 | typedef struct { | 21 | typedef struct { |
22 | int type; /* Type of card (chip) */ | 22 | int type; /* Type of card (chip) */ |
23 | char iface[6]; /* Interface of card */ | 23 | char iface[6]; /* Interface of card */ |
24 | } wl_cardtype_t; | 24 | } wl_cardtype_t; |
25 | 25 | ||
26 | 26 | ||
27 | /* WL network structure */ | 27 | /* WL network structure */ |
28 | typedef struct { | 28 | typedef struct { |
29 | int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ | 29 | int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ |
30 | int ssid_len; /* Length of SSID */ | 30 | int ssid_len; /* Length of SSID */ |
31 | int channel; /* Channel */ | 31 | int channel; /* Channel */ |
32 | int wep; /* 1 = WEP enabled ; 0 = disabled */ | 32 | int wep; /* 1 = WEP enabled ; 0 = disabled */ |
33 | char mac[64]; /* MAC address of Accesspoint */ | 33 | char mac[64]; /* MAC address of Accesspoint */ |
34 | char bssid[128]; /* BSSID of Net */ | 34 | char bssid[128]; /* BSSID of Net */ |
35 | } wl_network_t; | 35 | } wl_network_t; |
36 | 36 | ||
37 | /* Config specific */ | 37 | /* Config specific */ |
38 | #define WL_CONFFILE "sample.conf" | 38 | #define WL_CONFFILE "sample.conf" |
39 | #define WL_CONFBUFF 128 | 39 | #define WL_CONFBUFF 128 |
40 | 40 | ||
41 | |||
41 | #endif /* WL_TYPES_HH */ | 42 | #endif /* WL_TYPES_HH */ |
42 | 43 | ||