3 files changed, 53 insertions, 32 deletions
diff --git a/noncore/net/wellenreiter/daemon/source/daemon.cc b/noncore/net/wellenreiter/daemon/source/daemon.cc index 8471efc..46a50ed 100644 --- a/noncore/net/wellenreiter/daemon/source/daemon.cc +++ b/noncore/net/wellenreiter/daemon/source/daemon.cc | |||
@@ -1,36 +1,36 @@ | |||
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 700000 | 12 | #define CHANINTERVAL 500000 |
13 | 13 | ||
14 | /* Main function of wellenreiterd */ | 14 | /* Main function of wellenreiterd */ |
15 | int main(int argc, char **argv) | 15 | int main(int argc, char **argv) |
16 | { | 16 | { |
17 | int sock, maxfd, retval; | 17 | int sock, maxfd, retval; |
18 | char buffer[WL_SOCKBUF]; | 18 | char buffer[WL_SOCKBUF]; |
19 | struct pcap_pkthdr header; | 19 | struct pcap_pkthdr header; |
20 | struct sockaddr_in saddr; | 20 | struct sockaddr_in saddr; |
21 | pcap_t *handletopcap; | 21 | pcap_t *handletopcap; |
22 | wl_cardtype_t cardtype; | 22 | wl_cardtype_t cardtype; |
23 | pthread_t sub; | 23 | pthread_t sub; |
24 | const unsigned char *packet; | 24 | const unsigned char *packet; |
25 | 25 | ||
26 | fd_set rset; | 26 | fd_set rset; |
27 | 27 | ||
28 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); | 28 | fprintf(stderr, "wellenreiterd %s\n\n", VERSION); |
29 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); | 29 | fprintf(stderr, "(c) 2002 by M-M-M\n\n"); |
30 | 30 | ||
31 | if(argc < 3) | 31 | if(argc < 3) |
32 | usage(); | 32 | usage(); |
33 | 33 | ||
34 | /* Set sniffer device */ | 34 | /* Set sniffer device */ |
35 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); | 35 | memset(cardtype.iface, 0, sizeof(cardtype.iface)); |
36 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); | 36 | strncpy(cardtype.iface, (char *)argv[1], sizeof(cardtype.iface) - 1); |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index 0c23922..9e0a772 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -25,78 +25,76 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | |||
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[62]; | 48 | char wlanngcmd[62]; |
49 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); | 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 | wl_logerr("Got a host-ap card, nothing is implemented now"); | 58 | wl_logerr("Got a host-ap card, nothing is implemented now"); |
59 | char hostapcmd[250]; | 59 | char hostapcmd[250]; |
60 | snprintf(hostapcmd, sizeof(hostapcmd) -1, "%s %s monitor 2", IWPRIV_PATH, device); | 60 | snprintf(hostapcmd, sizeof(hostapcmd) -1, "$(which iwpriv) %s monitor 2 %d", device,1); |
61 | if (system(hostapcmd) !=0) | 61 | if (system(hostapcmd) !=0) |
62 | { | 62 | { |
63 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 63 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
64 | return 0; | 64 | return 0; |
65 | } | 65 | } |
66 | } | 66 | } |
67 | else if (cardtype == CARD_TYPE_ORINOCCO) | 67 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) |
68 | { | 68 | { |
69 | char lucentcmd[62]; | 69 | if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) |
70 | snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, 1); | 70 | { |
71 | if (system(lucentcmd) != 0) | 71 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
72 | { | 72 | return 0; |
73 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | ||
74 | return 0; | ||
75 | } | 73 | } |
76 | else | 74 | else |
77 | { | 75 | { |
78 | wl_loginfo("Successfully set %s into raw mode",device); | 76 | wl_loginfo("Successfully set %s into raw mode",device); |
79 | } | 77 | } |
80 | } | 78 | } |
81 | 79 | ||
82 | /* Setting the promiscous and up flag to the interface */ | 80 | /* Setting the promiscous and up flag to the interface */ |
83 | if (!card_check_rfmon_datalink(device)) | 81 | if (!card_check_rfmon_datalink(device)) |
84 | { | 82 | { |
85 | wl_logerr("Cannot set interface to rfmon mode"); | 83 | wl_logerr("Cannot set interface to rfmon mode"); |
86 | return 0; | 84 | return 0; |
87 | } | 85 | } |
88 | else | 86 | else |
89 | { | 87 | { |
90 | wl_loginfo("Interface set to rfmon mode"); | 88 | wl_loginfo("Interface set to rfmon mode"); |
91 | } | 89 | } |
92 | return 1; | 90 | return 1; |
93 | } | 91 | } |
94 | 92 | ||
95 | /* Check card is in the rfmon mode */ | 93 | /* Check card is in the rfmon mode */ |
96 | int card_check_rfmon_datalink (char *device) | 94 | int card_check_rfmon_datalink (char *device) |
97 | { | 95 | { |
98 | int datalinktype=0; | 96 | int datalinktype=0; |
99 | pcap_t *phandle; | 97 | pcap_t *phandle; |
100 | phandle = pcap_open_live(device, 65,0,0,NULL); | 98 | phandle = pcap_open_live(device, 65,0,0,NULL); |
101 | datalinktype = pcap_datalink (phandle); | 99 | datalinktype = pcap_datalink (phandle); |
102 | pcap_close(phandle); | 100 | pcap_close(phandle); |
@@ -145,48 +143,68 @@ int card_set_promisc_up (const char *device) | |||
145 | return 0; | 143 | return 0; |
146 | } | 144 | } |
147 | 145 | ||
148 | if(ifr.ifr_flags && IFF_UP) | 146 | if(ifr.ifr_flags && IFF_UP) |
149 | { | 147 | { |
150 | printf("%s is ok\n", device); | 148 | printf("%s is ok\n", device); |
151 | return 1; | 149 | return 1; |
152 | } | 150 | } |
153 | else | 151 | else |
154 | { | 152 | { |
155 | printf("%s flags could not be set", device); | 153 | printf("%s flags could not be set", device); |
156 | return 0; | 154 | return 0; |
157 | } | 155 | } |
158 | } | 156 | } |
159 | 157 | ||
160 | /* Set channel (Wireless frequency) of the device */ | 158 | /* Set channel (Wireless frequency) of the device */ |
161 | int card_set_channel (const char *device, int channel, int cardtype) | 159 | int card_set_channel (const char *device, int channel, int cardtype) |
162 | { | 160 | { |
163 | if (cardtype == CARD_TYPE_CISCO) | 161 | if (cardtype == CARD_TYPE_CISCO) |
164 | { | 162 | { |
165 | /* Cisco cards don't need channelswitching */ | 163 | /* Cisco cards don't need channelswitching */ |
166 | return 1; | 164 | return 1; |
167 | } | 165 | } |
168 | /* If it is a lucent orinocco card */ | 166 | /* If it is a lucent orinocco card */ |
169 | else if (cardtype == CARD_TYPE_ORINOCCO) | 167 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) |
170 | { | 168 | { |
171 | char lucentreset[63]; | 169 | int fd; |
172 | char lucentcmd[62]; | 170 | //Wireless tools structure for the iocalls |
173 | snprintf(lucentreset, sizeof(lucentreset) -1,"$(which iwpriv) %s force_reset", device); | 171 | struct iwreq ireq; |
174 | if (system(lucentreset) != 0) | 172 | int *ptr; |
175 | { | 173 | /* Socket needed to use the iocall to */ |
176 | wl_logerr("Could not reset the card %s",device); | 174 | fd = socket(AF_INET, SOCK_STREAM, 0); |
177 | return 0; | 175 | if ( fd == -1 ) { |
178 | } | 176 | return -1; |
179 | snprintf(lucentcmd, sizeof(lucentcmd) - 1, "$(which iwpriv) %s monitor 2 %d", device, channel); | 177 | } |
180 | if (system(lucentcmd) != 0) | 178 | ptr = (int *) ireq.u.name; |
181 | { | 179 | // This is the monitor mode for 802.11 non-prism header |
182 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 180 | ptr[0] = 2; |
183 | return 0; | 181 | ptr[1] = channel; |
184 | } | 182 | strcpy(ireq.ifr_ifrn.ifrn_name, device); |
185 | wl_loginfo("Channel %d set on interface %s",channel,device); | 183 | if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) |
186 | return 1; | 184 | { |
185 | /* All was fine... */ | ||
186 | // close(fd); | ||
187 | wl_loginfo("Set channel %d on interface %s",channel, device); | ||
188 | return 1; | ||
189 | } | ||
190 | else | ||
191 | { /* iocall does not work */ | ||
192 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); | ||
193 | return 0; | ||
194 | } | ||
187 | } | 195 | } |
188 | 196 | else if (cardtype == CARD_TYPE_NG) | |
197 | { | ||
198 | char wlanngcmd[62]; | ||
199 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, channel); | ||
200 | if (system(wlanngcmd) != 0) | ||
201 | { | ||
202 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); | ||
203 | return 0; | ||
204 | } | ||
205 | |||
206 | } | ||
189 | /* For undefined situations */ | 207 | /* For undefined situations */ |
190 | return 0; | 208 | return 0; |
191 | } | 209 | } |
192 | 210 | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index 3a1991b..242d8c5 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -1,44 +1,47 @@ | |||
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 <linux/if.h> | 15 | #include <linux/if.h> |
16 | #include <linux/wireless.h> | ||
17 | |||
18 | #ifndef SIOCIWFIRSTPRIV | ||
19 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE | ||
20 | #endif | ||
21 | |||
16 | 22 | ||
17 | extern "C" | 23 | extern "C" |
18 | { | 24 | { |
19 | #include <net/bpf.h> | 25 | #include <net/bpf.h> |
20 | #include <pcap.h> | 26 | #include <pcap.h> |
21 | } | 27 | } |
22 | 28 | ||
23 | /* Defines, used for the card setup */ | 29 | /* Defines, used for the card setup */ |
24 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 30 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
25 | #define CISCO_STATUS "/proc/driver/aironet/%s/Status" | 31 | #define CISCO_STATUS "/proc/driver/aironet/%s/Status" |
26 | #define CARD_TYPE_CISCO 1 | 32 | #define CARD_TYPE_CISCO 1 |
27 | #define CARD_TYPE_NG 2 | 33 | #define CARD_TYPE_NG 2 |
28 | #define CARD_TYPE_HOSTAP3 | 34 | #define CARD_TYPE_HOSTAP3 |
29 | #define CARD_TYPE_ORINOCCO 4 | 35 | #define CARD_TYPE_ORINOCCO 4 |
30 | 36 | ||
31 | /* only for now, until we have the daemon running */ | 37 | /* only for now, until we have the daemon running */ |
32 | /*the config file should provide these information */ | 38 | /*the config file should provide these information */ |
33 | #define CARD_TYPE CARD_TYPE_HOSTAP | 39 | #define CARD_TYPE CARD_TYPE_HOSTAP |
34 | #define SBIN_PATH "/sbin/ifconfig %s promisc up" | ||
35 | #define WLANCTL_PATH "/sbin/wlanctl-ng" | ||
36 | #define IWPRIV_PATH "/sbin/iwpriv" | ||
37 | 40 | ||
38 | /* Prototypes */ | 41 | /* Prototypes */ |
39 | int card_check_rfmon_datalink (char *device); | 42 | int card_check_rfmon_datalink (char *device); |
40 | int card_into_monitormode (pcap_t **, char *, int); | 43 | int card_into_monitormode (pcap_t **, char *, int); |
41 | int card_set_promisc_up (const char *); | 44 | int card_set_promisc_up (const char *); |
42 | int card_set_channel (const char *device, int channel,int cardtype); | 45 | int card_set_channel (const char *device, int channel,int cardtype); |
43 | 46 | ||
44 | #endif /* CARDMODE_HH */ | 47 | #endif /* CARDMODE_HH */ |