-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index 29dcc75..8c94cb1 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -24,50 +24,51 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | |||
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[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 | printf ("\n %s",wlanngcmd); | ||
50 | if (system(wlanngcmd) != 0) | 51 | if (system(wlanngcmd) != 0) |
51 | { | 52 | { |
52 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 53 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
53 | return 0; | 54 | return 0; |
54 | } | 55 | } |
55 | } | 56 | } |
56 | else if (cardtype == CARD_TYPE_HOSTAP) | 57 | else if (cardtype == CARD_TYPE_HOSTAP) |
57 | { | 58 | { |
58 | wl_logerr("Got a host-ap card, nothing is implemented now"); | 59 | wl_logerr("Got a host-ap card, nothing is implemented now"); |
59 | char hostapcmd[250]; | 60 | char hostapcmd[250]; |
60 | snprintf(hostapcmd, sizeof(hostapcmd) -1, "$(which iwpriv) %s monitor 2 %d", device,1); | 61 | snprintf(hostapcmd, sizeof(hostapcmd) -1, "$(which iwpriv) %s monitor 2 %d", device,1); |
61 | if (system(hostapcmd) !=0) | 62 | if (system(hostapcmd) !=0) |
62 | { | 63 | { |
63 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 64 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
64 | return 0; | 65 | return 0; |
65 | } | 66 | } |
66 | } | 67 | } |
67 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) | 68 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) |
68 | { | 69 | { |
69 | if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) | 70 | if (!card_set_channel (device, 1, CARD_TYPE_ORINOCCO)) |
70 | { | 71 | { |
71 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 72 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
72 | return 0; | 73 | return 0; |
73 | } | 74 | } |
@@ -140,77 +141,66 @@ int card_set_promisc_up (const char *device) | |||
140 | ioctl(fd, SIOCGIFFLAGS, &ifr); | 141 | ioctl(fd, SIOCGIFFLAGS, &ifr); |
141 | if (err < 0) | 142 | if (err < 0) |
142 | { | 143 | { |
143 | perror("Could not access the interface, "); | 144 | perror("Could not access the interface, "); |
144 | close(fd); | 145 | close(fd); |
145 | return 0; | 146 | return 0; |
146 | } | 147 | } |
147 | 148 | ||
148 | if(ifr.ifr_flags && IFF_UP) | 149 | if(ifr.ifr_flags && IFF_UP) |
149 | { | 150 | { |
150 | close(fd); | 151 | close(fd); |
151 | return 1; | 152 | return 1; |
152 | } | 153 | } |
153 | else | 154 | else |
154 | { | 155 | { |
155 | wl_logerr("Could not set promisc flag on %d", device); | 156 | wl_logerr("Could not set promisc flag on %d", device); |
156 | close(fd); | 157 | close(fd); |
157 | return 0; | 158 | return 0; |
158 | } | 159 | } |
159 | } | 160 | } |
160 | 161 | ||
161 | /* Set channel (Wireless frequency) of the device */ | 162 | /* Set channel (Wireless frequency) of the device */ |
162 | int card_set_channel (const char *device, int channel, int cardtype) | 163 | int card_set_channel (const char *device, int channel, int cardtype) |
163 | { | 164 | { |
164 | if (cardtype == CARD_TYPE_CISCO) | 165 | if (cardtype == CARD_TYPE_CISCO || cardtype == CARD_TYPE_NG) |
165 | { | 166 | { |
166 | /* Cisco cards don't need channelswitching */ | 167 | /* Cisco and wlan-ng drivers don't need channelswitching */ |
167 | return 1; | 168 | return 1; |
168 | } | 169 | } |
169 | /* If it is a lucent orinocco card */ | 170 | /* If it is a lucent orinocco card */ |
170 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) | 171 | else if (cardtype == CARD_TYPE_ORINOCCO || cardtype == CARD_TYPE_HOSTAP) |
171 | { | 172 | { |
172 | int fd; | 173 | int fd; |
173 | //Wireless tools structure for the iocalls | 174 | //Wireless tools structure for the iocalls |
174 | struct iwreq ireq; | 175 | struct iwreq ireq; |
175 | int *ptr; | 176 | int *ptr; |
176 | /* Socket needed to use the iocall to */ | 177 | /* Socket needed to use the iocall to */ |
177 | fd = socket(AF_INET, SOCK_STREAM, 0); | 178 | fd = socket(AF_INET, SOCK_STREAM, 0); |
178 | 179 | ||
179 | if ( fd == -1 ) { | 180 | if ( fd == -1 ) { |
180 | return -1; | 181 | return -1; |
181 | } | 182 | } |
182 | ptr = (int *) ireq.u.name; | 183 | ptr = (int *) ireq.u.name; |
183 | // This is the monitor mode for 802.11 non-prism header | 184 | // This is the monitor mode for 802.11 non-prism header |
184 | ptr[0] = 2; | 185 | ptr[0] = 2; |
185 | ptr[1] = channel; | 186 | ptr[1] = channel; |
186 | strcpy(ireq.ifr_ifrn.ifrn_name, device); | 187 | strcpy(ireq.ifr_ifrn.ifrn_name, device); |
187 | if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) | 188 | if (ioctl( fd, SIOCIWFIRSTPRIV + 0x8, &ireq)==0) |
188 | { | 189 | { |
189 | /* All was fine... */ | 190 | /* All was fine... */ |
190 | close(fd); | 191 | close(fd); |
191 | wl_loginfo("Set channel %d on interface %s",channel, device); | 192 | wl_loginfo("Set channel %d on interface %s",channel, device); |
192 | return 1; | 193 | return 1; |
193 | } | 194 | } |
194 | else | 195 | else |
195 | { | 196 | { |
196 | /* iocall does not work */ | 197 | /* iocall does not work */ |
197 | close(fd); | 198 | close(fd); |
198 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); | 199 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); |
199 | return 0; | 200 | return 0; |
200 | } | 201 | } |
201 | } | 202 | } |
202 | else if (cardtype == CARD_TYPE_NG) | ||
203 | { | ||
204 | char wlanngcmd[62]; | ||
205 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=true", device, channel); | ||
206 | if (system(wlanngcmd) != 0) | ||
207 | { | ||
208 | wl_logerr("Could not set channel %d on %s, check cardtype",channel, device); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | } | ||
213 | /* For undefined situations */ | 203 | /* For undefined situations */ |
214 | return 0; | 204 | return 0; |
215 | } | 205 | } |
216 | 206 | ||