-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | 18 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | 1 |
2 files changed, 13 insertions, 6 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index 9e0a772..29dcc75 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -6,205 +6,211 @@ | |||
6 | 6 | ||
7 | #include "cardmode.hh" | 7 | #include "cardmode.hh" |
8 | #include "wl_log.hh" | 8 | #include "wl_log.hh" |
9 | 9 | ||
10 | /* main card into monitor function */ | 10 | /* main card into monitor function */ |
11 | int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | 11 | int card_into_monitormode (pcap_t **orighandle, 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[62]; | 48 | char wlanngcmd[62]; |
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 | 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, "$(which iwpriv) %s monitor 2 %d", device,1); | 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 || cardtype == CARD_TYPE_HOSTAP) | 67 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) |
68 | { | 68 | { |
69 | if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) | 69 | if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) |
70 | { | 70 | { |
71 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 71 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
72 | return 0; | 72 | return 0; |
73 | } | 73 | } |
74 | else | 74 | else |
75 | { | 75 | { |
76 | wl_loginfo("Successfully set %s into raw mode",device); | 76 | wl_loginfo("Successfully set %s into raw mode",device); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | /* Setting the promiscous and up flag to the interface */ | 80 | /* Setting the promiscous and up flag to the interface */ |
81 | if (!card_check_rfmon_datalink(device)) | 81 | if (!card_check_rfmon_datalink(device)) |
82 | { | 82 | { |
83 | wl_logerr("Cannot set interface to rfmon mode"); | 83 | wl_logerr("Cannot set interface to rfmon mode"); |
84 | return 0; | 84 | return 0; |
85 | } | 85 | } |
86 | else | 86 | else |
87 | { | 87 | { |
88 | wl_loginfo("Interface set to rfmon mode"); | 88 | wl_loginfo("Interface set to rfmon mode"); |
89 | } | 89 | } |
90 | return 1; | 90 | return 1; |
91 | } | 91 | } |
92 | 92 | ||
93 | /* Check card is in the rfmon mode */ | 93 | /* Check card is in the rfmon mode */ |
94 | int card_check_rfmon_datalink (char *device) | 94 | int card_check_rfmon_datalink (char *device) |
95 | { | 95 | { |
96 | int datalinktype=0; | 96 | int datalinktype=0; |
97 | pcap_t *phandle; | 97 | pcap_t *phandle; |
98 | phandle = pcap_open_live(device, 65,0,0,NULL); | 98 | phandle = pcap_open_live(device, 65,0,0,NULL); |
99 | datalinktype = pcap_datalink (phandle); | 99 | datalinktype = pcap_datalink (phandle); |
100 | pcap_close(phandle); | 100 | pcap_close(phandle); |
101 | 101 | ||
102 | if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ | 102 | if (datalinktype != DLT_IEEE802_11) /* Rawmode is IEEE802_11 */ |
103 | { | 103 | { |
104 | return 0; | 104 | return 0; |
105 | } | 105 | } |
106 | else | 106 | else |
107 | { | 107 | { |
108 | wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); | 108 | wl_loginfo("Your successfully listen on %s in 802.11 raw mode", device); |
109 | return 1; | 109 | return 1; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | /* Set card into promisc mode */ | 113 | /* Set card into promisc mode */ |
114 | int card_set_promisc_up (const char *device) | 114 | int card_set_promisc_up (const char *device) |
115 | { | 115 | { |
116 | int err; | 116 | int err; |
117 | /* First generate a socket to use with iocalls */ | 117 | /* First generate a socket to use with iocalls */ |
118 | int fd = socket(AF_INET, SOCK_DGRAM, 0); | 118 | int fd = socket(AF_INET, SOCK_DGRAM, 0); |
119 | if (fd < 0) | 119 | if (fd < 0) |
120 | { | 120 | { |
121 | /* In case of an error */ | 121 | /* In case of an error */ |
122 | perror("socket"); | 122 | perror("socket"); |
123 | return 0; | 123 | return 0; |
124 | } | 124 | } |
125 | 125 | ||
126 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ | 126 | /* Fill an empty an interface structure with the right flags (UP and Promsic) */ |
127 | struct ifreq ifr; | 127 | struct ifreq ifr; |
128 | strncpy(ifr.ifr_name, device,10); | 128 | strncpy(ifr.ifr_name, device,10); |
129 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; | 129 | ifr.ifr_flags = IFF_UP + IFF_PROMISC; |
130 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); | 130 | err = ioctl(fd, SIOCSIFFLAGS, &ifr); |
131 | if (err < 0) | 131 | if (err < 0) |
132 | { | 132 | { |
133 | perror("Could not access the interface, "); | 133 | perror("Could not access the interface, "); |
134 | close(fd); | ||
134 | return 0; | 135 | return 0; |
135 | } | 136 | } |
136 | 137 | ||
137 | /* Get the informations back from the interface to check if the flags are correct */ | 138 | /* Get the informations back from the interface to check if the flags are correct */ |
138 | strncpy(ifr.ifr_name, device,10); | 139 | strncpy(ifr.ifr_name, device,10); |
139 | ioctl(fd, SIOCGIFFLAGS, &ifr); | 140 | ioctl(fd, SIOCGIFFLAGS, &ifr); |
140 | if (err < 0) | 141 | if (err < 0) |
141 | { | 142 | { |
142 | perror("Could not access the interface, "); | 143 | perror("Could not access the interface, "); |
144 | close(fd); | ||
143 | return 0; | 145 | return 0; |
144 | } | 146 | } |
145 | 147 | ||
146 | if(ifr.ifr_flags && IFF_UP) | 148 | if(ifr.ifr_flags && IFF_UP) |
147 | { | 149 | { |
148 | printf("%s is ok\n", device); | 150 | close(fd); |
149 | return 1; | 151 | return 1; |
150 | } | 152 | } |
151 | else | 153 | else |
152 | { | 154 | { |
153 | printf("%s flags could not be set", device); | 155 | wl_logerr("Could not set promisc flag on %d", device); |
154 | return 0; | 156 | close(fd); |
157 | return 0; | ||
155 | } | 158 | } |
156 | } | 159 | } |
157 | 160 | ||
158 | /* Set channel (Wireless frequency) of the device */ | 161 | /* Set channel (Wireless frequency) of the device */ |
159 | int card_set_channel (const char *device, int channel, int cardtype) | 162 | int card_set_channel (const char *device, int channel, int cardtype) |
160 | { | 163 | { |
161 | if (cardtype == CARD_TYPE_CISCO) | 164 | if (cardtype == CARD_TYPE_CISCO) |
162 | { | 165 | { |
163 | /* Cisco cards don't need channelswitching */ | 166 | /* Cisco cards don't need channelswitching */ |
164 | return 1; | 167 | return 1; |
165 | } | 168 | } |
166 | /* If it is a lucent orinocco card */ | 169 | /* If it is a lucent orinocco card */ |
167 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) | 170 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) |
168 | { | 171 | { |
169 | int fd; | 172 | int fd; |
170 | //Wireless tools structure for the iocalls | 173 | //Wireless tools structure for the iocalls |
171 | struct iwreq ireq; | 174 | struct iwreq ireq; |
172 | int *ptr; | 175 | int *ptr; |
173 | /* Socket needed to use the iocall to */ | 176 | /* Socket needed to use the iocall to */ |
174 | fd = socket(AF_INET, SOCK_STREAM, 0); | 177 | fd = socket(AF_INET, SOCK_STREAM, 0); |
178 | |||
175 | if ( fd == -1 ) { | 179 | if ( fd == -1 ) { |
176 | return -1; | 180 | return -1; |
177 | } | 181 | } |
178 | ptr = (int *) ireq.u.name; | 182 | ptr = (int *) ireq.u.name; |
179 | // This is the monitor mode for 802.11 non-prism header | 183 | // This is the monitor mode for 802.11 non-prism header |
180 | ptr[0] = 2; | 184 | ptr[0] = 2; |
181 | ptr[1] = channel; | 185 | ptr[1] = channel; |
182 | strcpy(ireq.ifr_ifrn.ifrn_name, device); | 186 | strcpy(ireq.ifr_ifrn.ifrn_name, device); |
183 | if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) | 187 | if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) |
184 | { | 188 | { |
185 | /* All was fine... */ | 189 | /* All was fine... */ |
186 | // close(fd); | 190 | close(fd); |
187 | wl_loginfo("Set channel %d on interface %s",channel, device); | 191 | wl_loginfo("Set channel %d on interface %s",channel, device); |
188 | return 1; | 192 | return 1; |
189 | } | 193 | } |
190 | else | 194 | else |
191 | { /* iocall does not work */ | 195 | { |
196 | /* iocall does not work */ | ||
197 | close(fd); | ||
192 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); | 198 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); |
193 | return 0; | 199 | return 0; |
194 | } | 200 | } |
195 | } | 201 | } |
196 | else if (cardtype == CARD_TYPE_NG) | 202 | else if (cardtype == CARD_TYPE_NG) |
197 | { | 203 | { |
198 | char wlanngcmd[62]; | 204 | char wlanngcmd[62]; |
199 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, channel); | 205 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, channel); |
200 | if (system(wlanngcmd) != 0) | 206 | if (system(wlanngcmd) != 0) |
201 | { | 207 | { |
202 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); | 208 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); |
203 | return 0; | 209 | return 0; |
204 | } | 210 | } |
205 | 211 | ||
206 | } | 212 | } |
207 | /* For undefined situations */ | 213 | /* For undefined situations */ |
208 | return 0; | 214 | return 0; |
209 | } | 215 | } |
210 | 216 | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index 242d8c5..4a95956 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -1,47 +1,48 @@ | |||
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 <linux/if.h> | 16 | #include <linux/if.h> |
16 | #include <linux/wireless.h> | 17 | #include <linux/wireless.h> |
17 | 18 | ||
18 | #ifndef SIOCIWFIRSTPRIV | 19 | #ifndef SIOCIWFIRSTPRIV |
19 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE | 20 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE |
20 | #endif | 21 | #endif |
21 | 22 | ||
22 | 23 | ||
23 | extern "C" | 24 | extern "C" |
24 | { | 25 | { |
25 | #include <net/bpf.h> | 26 | #include <net/bpf.h> |
26 | #include <pcap.h> | 27 | #include <pcap.h> |
27 | } | 28 | } |
28 | 29 | ||
29 | /* Defines, used for the card setup */ | 30 | /* Defines, used for the card setup */ |
30 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 31 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
31 | #define CISCO_STATUS "/proc/driver/aironet/%s/Status" | 32 | #define CISCO_STATUS "/proc/driver/aironet/%s/Status" |
32 | #define CARD_TYPE_CISCO 1 | 33 | #define CARD_TYPE_CISCO 1 |
33 | #define CARD_TYPE_NG 2 | 34 | #define CARD_TYPE_NG 2 |
34 | #define CARD_TYPE_HOSTAP3 | 35 | #define CARD_TYPE_HOSTAP3 |
35 | #define CARD_TYPE_ORINOCCO 4 | 36 | #define CARD_TYPE_ORINOCCO 4 |
36 | 37 | ||
37 | /* only for now, until we have the daemon running */ | 38 | /* only for now, until we have the daemon running */ |
38 | /*the config file should provide these information */ | 39 | /*the config file should provide these information */ |
39 | #define CARD_TYPE CARD_TYPE_HOSTAP | 40 | #define CARD_TYPE CARD_TYPE_HOSTAP |
40 | 41 | ||
41 | /* Prototypes */ | 42 | /* Prototypes */ |
42 | int card_check_rfmon_datalink (char *device); | 43 | int card_check_rfmon_datalink (char *device); |
43 | int card_into_monitormode (pcap_t **, char *, int); | 44 | int card_into_monitormode (pcap_t **, char *, int); |
44 | int card_set_promisc_up (const char *); | 45 | int card_set_promisc_up (const char *); |
45 | int card_set_channel (const char *device, int channel,int cardtype); | 46 | int card_set_channel (const char *device, int channel,int cardtype); |
46 | 47 | ||
47 | #endif /* CARDMODE_HH */ | 48 | #endif /* CARDMODE_HH */ |