00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <include.h>
00029 #include <src/interface.h>
00030 #include <src/crt_io.h>
00031 #include <src/driver.h>
00032 #include <src/wlan-ng.h>
00033 #include <src/cisco.h>
00034 #include <src/atheros.h>
00035 #include <src/prism54g.h>
00036 #include <src/airjack.h>
00037 #include <src/hostap.h>
00038 #include <src/hermes.h>
00039 #include <src/ipw.h>
00040 #include <src/pcap_file.h>
00041 #include <src/madwifi-ng.h>
00042 #include <src/errmsg.h>
00043
00044 extern unsigned int DebugLevel;
00045 extern WINDOW *Sum_WND, *RealTime_WND;
00046 extern ScanResult_t Res;
00047 extern ConfigStruct config;
00048
00049
00050 #ifdef WITH_THREAD
00051 extern pthread_mutex_t screen_mutex;
00052 #endif
00053
00054 const UINT8 ListChannel[13][14] = {
00055 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},
00056 {1, 3, 5, 7, 9, 11, 13, 14, 2, 4, 6, 8, 10, 12},
00057 {1, 4, 7, 10, 13, 2, 5, 8, 11, 14, 3, 6, 9, 12},
00058 {1, 5, 9, 13, 3, 7, 11, 2, 6, 10, 14, 4, 8, 12},
00059 {1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 5, 10},
00060 {1, 7, 13, 5, 11, 3, 9, 2, 8, 14, 6, 12, 4, 10},
00061 {1, 8, 2, 9, 3, 10, 4, 11, 5, 12, 6, 13, 7, 14},
00062 {1, 7, 13, 5, 11, 3, 9, 2, 8, 14, 6, 12, 4, 10},
00063 {1, 6, 11, 2, 7, 12, 3, 8, 13, 4, 9, 14, 5, 10},
00064 {1, 5, 9, 13, 3, 7, 11, 2, 6, 10, 14, 4, 8, 12},
00065 {1, 4, 7, 10, 13, 2, 5, 8, 11, 14, 3, 6, 9, 12},
00066 {1, 3, 5, 7, 9, 11, 13, 14, 2, 4, 6, 8, 10, 12},
00067 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14},
00068 };
00069
00070 static UINT8 LockedBchan[14];
00071
00072
00073
00074
00075
00076 int NextChannel(char *devname, unsigned int NumberOfHop)
00077 {
00078 static UINT8 ChannelIndex = 0;
00079 int channel;
00080 int result;
00081 int TestsDone = 0;
00082
00083 do {
00084 if (NumberOfHop <= 7)
00085 channel = ListChannel[NumberOfHop - 1][ChannelIndex];
00086 else
00087 channel = ListChannel[NumberOfHop - 1][13 - ChannelIndex];
00088 ChannelIndex++;
00089 ChannelIndex = ChannelIndex % 14;
00090 TestsDone++;
00091 } while ((LockedBchan[channel - 1] != 0) && (TestsDone <= 14));
00092
00093 if (TestsDone > 14) {
00094 warning("%s\n", ErrorsMsg[ALL_CHANNEL_ARE_LOCKED]);
00095 return ALL_CHANNEL_ARE_LOCKED;
00096 } else {
00097
00098 result = selectChannel(devname, channel);
00099
00100 return 0;
00101 }
00102 }
00103
00104
00105
00106
00107 #ifdef HAVE_LIBNCURSES
00108 const UINT8 Posit[15] = { 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 14 };
00109 const char *Indic[15] =
00110 { "", "^-.", "-^-.", ".-^-.", ".-^-.", ".-^-.", ".-^-.", ".-^-.",
00111 ".-^-.",
00112 ".-^-.", ".-^-.", ".-^-.", ".-^-.", ".-^-.", ".-^"
00113 };
00114
00115 void PrintScaleChannel(int channel)
00116 {
00117 int i;
00118 #ifdef WITH_THREAD
00119 pthread_mutex_lock(&screen_mutex);
00120 #endif
00121 mvwprintw(Sum_WND, 12, 7, "%02d%01X", channel, channel);
00122 mvwprintw(Sum_WND, 13, 2, "|_____________ _|");
00123 for (i = 0; i < 14; i++) {
00124 if (LockedBchan[i] != 0)
00125 mvwprintw(Sum_WND, 13, 3 + i + ((i >= 13) << 1), "X");
00126 }
00127 mvwprintw(Sum_WND, 13, 2 + Posit[channel], (char *) Indic[channel]);
00128
00129
00130
00131 wrefresh(Sum_WND);
00132 #ifdef WITH_THREAD
00133 pthread_mutex_unlock(&screen_mutex);
00134 #endif
00135 }
00136 #else
00137 #define PrintScaleChannel(x)
00138 #endif
00139
00140 int selectChannel(char *devname, int channel)
00141
00142 {
00143 int ret = 1;
00144
00145 switch (config.TypeOfCard) {
00146 case WLAN_NG_CARD:
00147 case WLAN_NG_CARD_AVS_CFF2:
00148 ret = selectChannelWLAN(devname, channel);
00149 break;
00150 case CISCO_CARD:
00151 case CISCO_CVS_CARD:
00152 ret = selectChannelCISCO(devname, channel);
00153 break;
00154 case LUCENT_CARD:
00155 ret = selectChannelHERMES(devname, channel);
00156 break;
00157 case HOSTAP_CARD:
00158 ret = selectChannelHOSTAP(devname, channel);
00159 break;
00160 case ATHEROS_CARD:
00161 ret = selectChannelATHEROS(devname, channel);
00162 break;
00163 case PRISM54G_CARD:
00164 ret = selectChannelPRISM54g(devname, channel);
00165 break;
00166 case AIRJACK_CARD:
00167 ret = selectChannelAIRJACK(devname, channel);
00168 break;
00169 case IPW_CARD:
00170 ret = selectChannelIPW(devname, channel);
00171 break;
00172 case MADWIFI_NG_CARD:
00173 ret = selectChannelMADWIFI_NG(devname, channel);
00174 break;
00175 case PCAP_VIRTUAL_CARD:
00176
00177
00178 ret = 0;
00179 break;
00180 default:
00181 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00182 break;
00183 }
00184
00185 if (ret != 0) {
00186 LockedBchan[channel - 1] = 0xFF;
00187 warning
00188 ("This card do not support this Channel: %d, so it's now locked\n",
00189 channel - 1);
00190 } else {
00191 LockedBchan[channel - 1] = 0x00;
00192 Res.SChannel = channel;
00193 }
00194 PrintScaleChannel(channel);
00195
00196 return ret;
00197 }
00198
00199 int shutCard(char *devname)
00200 {
00201 int ret = FALSE;
00202
00203 switch (config.TypeOfCard) {
00204 case WLAN_NG_CARD:
00205 case WLAN_NG_CARD_AVS_CFF2:
00206 ret = shutCardWLAN(devname);
00207 break;
00208 case CISCO_CARD:
00209 case CISCO_CVS_CARD:
00210 ret = shutCardCISCO(devname);
00211 break;
00212 case LUCENT_CARD:
00213 ret = shutCardHERMES(devname);
00214 break;
00215 case HOSTAP_CARD:
00216 ret = shutCardHOSTAP(devname);
00217 break;
00218 case ATHEROS_CARD:
00219 ret = shutCardATHEROS(devname);
00220 break;
00221 case PRISM54G_CARD:
00222 ret = shutCardPRISM54g(devname);
00223 break;
00224 case AIRJACK_CARD:
00225 ret = shutCardAIRJACK(devname);
00226 break;
00227 case IPW_CARD:
00228 ret = shutCardIPW(devname);
00229 break;
00230 case MADWIFI_NG_CARD:
00231 ret = shutCardMADWIFI_NG(devname);
00232 break;
00233 case PCAP_VIRTUAL_CARD:
00234 ret = 0;
00235 break;
00236 default:
00237 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00238 break;
00239 }
00240 return ret;
00241 }
00242
00243 int openCard(char *devname)
00244 {
00245 int ret = FALSE;
00246
00247 switch (config.TypeOfCard) {
00248 case WLAN_NG_CARD:
00249 case WLAN_NG_CARD_AVS_CFF2:
00250 ret = openCardWLAN(devname);
00251 break;
00252 case CISCO_CARD:
00253 case CISCO_CVS_CARD:
00254 ret = openCardCISCO(devname);
00255 break;
00256 case LUCENT_CARD:
00257 ret = openCardHERMES(devname);
00258 break;
00259 case HOSTAP_CARD:
00260 ret = openCardHOSTAP(devname);
00261 break;
00262 case ATHEROS_CARD:
00263 ret = openCardATHEROS(devname);
00264 break;
00265 case PRISM54G_CARD:
00266 ret = openCardPRISM54g(devname);
00267 break;
00268 case AIRJACK_CARD:
00269 ret = openCardAIRJACK(devname);
00270 break;
00271 case IPW_CARD:
00272 ret = openCardIPW(devname);
00273 break;
00274 case MADWIFI_NG_CARD:
00275 ret = openCardMADWIFI_NG(devname);
00276 break;
00277 case PCAP_VIRTUAL_CARD:
00278 ret = 0;
00279 break;
00280 default:
00281 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00282 break;
00283 }
00284 return ret;
00285 }
00286
00287
00288
00289
00290
00291 int openPacket(char *devname)
00292 {
00293 int ret = 0;
00294
00295 switch (config.TypeOfCard) {
00296 case WLAN_NG_CARD:
00297 ret = openPacketWLAN(devname);
00298 break;
00299 case WLAN_NG_CARD_AVS_CFF2:
00300 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00301 break;
00302 case CISCO_CARD:
00303 case CISCO_CVS_CARD:
00304 ret = openPacketCISCO(devname);
00305 break;
00306 case LUCENT_CARD:
00307 ret = openPacketHERMES(devname);
00308 break;
00309 case HOSTAP_CARD:
00310 ret = openPacketHOSTAP(devname);
00311 break;
00312 case ATHEROS_CARD:
00313 ret = openPacketATHEROS(devname);
00314 break;
00315 case PRISM54G_CARD:
00316 ret = openPacketPRISM54g(devname);
00317 break;
00318 case AIRJACK_CARD:
00319 ret = openPacketAIRJACK(devname);
00320 break;
00321 case IPW_CARD:
00322 ret = openPacketIPW(devname);
00323 break;
00324 case MADWIFI_NG_CARD:
00325 ret = openPacketMADWIFI_NG(devname);
00326 break;
00327 case PCAP_VIRTUAL_CARD:
00328 ret = openPacketPCAP(devname);
00329 break;
00330 default:
00331 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00332 break;
00333 }
00334 return ret;
00335 }
00336
00337
00338
00339
00340 void closePacket(void)
00341 {
00342 switch (config.TypeOfCard) {
00343 case WLAN_NG_CARD:
00344 closePacketWLAN();
00345 break;
00346 case WLAN_NG_CARD_AVS_CFF2:
00347 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00348 break;
00349 case CISCO_CARD:
00350 case CISCO_CVS_CARD:
00351 closePacketCISCO();
00352 break;
00353 case LUCENT_CARD:
00354 closePacketHERMES();
00355 break;
00356 case HOSTAP_CARD:
00357 closePacketHOSTAP();
00358 break;
00359 case ATHEROS_CARD:
00360 closePacketATHEROS();
00361 break;
00362 case PRISM54G_CARD:
00363 closePacketPRISM54g();
00364 break;
00365 case AIRJACK_CARD:
00366 closePacketAIRJACK();
00367 break;
00368 case IPW_CARD:
00369 closePacketIPW();
00370 break;
00371 case MADWIFI_NG_CARD:
00372 closePacketMADWIFI_NG();
00373 break;
00374 case PCAP_VIRTUAL_CARD:
00375 closePacketPCAP();
00376 break;
00377 default:
00378 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00379 break;
00380 }
00381 }
00382
00383
00384 int getPacket(p80211_caphdr_t * wlan_header, UINT8 * buf, int maxlen)
00385 {
00386 int ret = 0;
00387
00388 switch (config.TypeOfCard) {
00389 case WLAN_NG_CARD:
00390 ret = getPacketWLAN(wlan_header, buf, maxlen);
00391 break;
00392 case WLAN_NG_CARD_AVS_CFF2:
00393 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00394 break;
00395 case CISCO_CARD:
00396 case CISCO_CVS_CARD:
00397 ret = getPacketCISCO(wlan_header, buf, maxlen);
00398 break;
00399 case LUCENT_CARD:
00400 ret = getPacketHERMES(wlan_header, buf, maxlen);
00401 break;
00402 case HOSTAP_CARD:
00403 ret = getPacketHOSTAP(wlan_header, buf, maxlen);
00404 break;
00405 case ATHEROS_CARD:
00406 ret = getPacketATHEROS(wlan_header, buf, maxlen);
00407 break;
00408 case PRISM54G_CARD:
00409 ret = getPacketPRISM54g(wlan_header, buf, maxlen);
00410 break;
00411 case AIRJACK_CARD:
00412 ret = getPacketAIRJACK(wlan_header, buf, maxlen);
00413 break;
00414 case IPW_CARD:
00415 ret = getPacketIPW(wlan_header, buf, maxlen);
00416 break;
00417 case MADWIFI_NG_CARD:
00418 ret = getPacketMADWIFI_NG(wlan_header, buf, maxlen);
00419 break;
00420 case PCAP_VIRTUAL_CARD:
00421 ret = getPacketPCAP(wlan_header, buf, maxlen);
00422 break;
00423 default:
00424 fatal(ERROR_PQT_TYPE_IS_UNKNOWN, "");
00425 break;
00426 }
00427 return ret;
00428 }