language
stringlengths
0
24
filename
stringlengths
9
214
code
stringlengths
99
9.93M
C
aircrack-ng/lib/libac/support/fragments.c
/* * Copyright (C) 2006-2018 Thomas d'Otreppe <[email protected]> * Copyright (C) 2006-2009 Martin Beck <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations * including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. * If you modify * file(s) with this exception, you may extend this exception to your * version of the file(s), but you are not obligated to do so. * If you * do not wish to do so, delete this exception statement from your * version. * If you delete this exception statement from all source * files in the program, then also delete it here. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <string.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <time.h> #include <sys/time.h> #include "aircrack-ng/defs.h" #include "aircrack-ng/support/common.h" #include "aircrack-ng/support/fragments.h" #include "aircrack-ng/crypto/crypto.h" extern pFrag_t rFragment; int addFrag(unsigned char * packet, unsigned char * smac, int len, int crypt, unsigned char * wepkey, int weplen) { pFrag_t cur = rFragment; int seq, frag, wep, z, i; unsigned char frame[4096]; unsigned char K[128]; if (packet == NULL) return (-1); if (smac == NULL) return (-1); if (len <= 32 || len > 2000) return (-1); if (rFragment == NULL) return (-1); memset(frame, 0, sizeof(frame)); memcpy(frame, packet, (size_t) len); z = ((frame[1] & 3) != 3) ? 24 : 30; frag = frame[22] & 0x0F; seq = (frame[22] >> 4) | (frame[23] << 4); wep = (frame[1] & 0x40) >> 6; ALLEGE(frag >= 0 && frag <= 15); //-V560 if (wep && crypt != CRYPT_WEP) return (-1); if (wep) { // decrypt it memcpy(K, frame + z, 3); memcpy(K + 3, wepkey, (size_t) weplen); if (decrypt_wep(frame + z + 4, len - z - 4, K, 3 + weplen) == 0 && (len - z - 4 > 8)) { printf("error decrypting... len: %d\n", len - z - 4); return (-1); } /* WEP data packet was successfully decrypted, * * remove the WEP IV & ICV and write the data */ len -= 8; memcpy(frame + z, frame + z + 4, (size_t) len - z); frame[1] &= 0xBF; } while (cur->next != NULL) { cur = cur->next; if ((memcmp(smac, cur->source, 6) == 0) && (seq == cur->sequence) && (wep == cur->wep)) { // entry already exists, update if (cur->fragment[frag] != NULL) return (0); if ((frame[1] & 0x04) == 0) { cur->fragnum = (char) frag; // no higher frag number possible } cur->fragment[frag] = (unsigned char *) malloc((size_t) len - z); ALLEGE(cur->fragment[frag] != NULL); memcpy(cur->fragment[frag], frame + z, (size_t) len - z); cur->fragmentlen[frag] = (short) (len - z); gettimeofday(&cur->access, NULL); return (0); } } // new entry, first fragment received // alloc mem cur->next = (pFrag_t) malloc(sizeof(struct Fragment_list)); ALLEGE(cur->next != NULL); cur = cur->next; for (i = 0; i < 16; i++) { cur->fragment[i] = NULL; cur->fragmentlen[i] = 0; } if ((frame[1] & 0x04) == 0) { cur->fragnum = (char) frag; // no higher frag number possible } else { cur->fragnum = 0; } // remove retry & more fragments flag frame[1] &= 0xF3; // set frag number to 0 frame[22] &= 0xF0; memcpy(cur->source, smac, 6); cur->sequence = (uint16_t) seq; cur->header = (unsigned char *) malloc((size_t) z); ALLEGE(cur->header != NULL); memcpy(cur->header, frame, (size_t) z); cur->headerlen = (int16_t) z; cur->fragment[frag] = (unsigned char *) malloc((size_t) len - z); ALLEGE(cur->fragment[frag] != NULL); memcpy(cur->fragment[frag], frame + z, len - z); cur->fragmentlen[frag] = (int16_t)(len - z); cur->wep = (int8_t) wep; gettimeofday(&cur->access, NULL); cur->next = NULL; return (0); } int timeoutFrag(void) { pFrag_t old, cur = rFragment; struct timeval tv; int64_t timediff; int i; if (rFragment == NULL) return (-1); gettimeofday(&tv, NULL); while (cur->next != NULL) { old = cur->next; timediff = (tv.tv_sec - old->access.tv_sec) * 1000000UL + (tv.tv_usec - old->access.tv_usec); if (timediff > FRAG_TIMEOUT) { // remove captured fragments if (old->header != NULL) free(old->header); for (i = 0; i < 16; i++) if (old->fragment[i] != NULL) free(old->fragment[i]); cur->next = old->next; free(old); } cur = cur->next; } return (0); } int delFrag(unsigned char * smac, int sequence) { pFrag_t old, cur = rFragment; int i; if (rFragment == NULL) return (-1); if (smac == NULL) return (-1); if (sequence < 0) return (-1); while (cur->next != NULL) { old = cur->next; if (memcmp(smac, old->source, 6) == 0 && old->sequence == sequence) { // remove captured fragments if (old->header != NULL) free(old->header); for (i = 0; i < 16; i++) if (old->fragment[i] != NULL) free(old->fragment[i]); cur->next = old->next; free(old); return (0); } cur = cur->next; } return (0); } unsigned char * getCompleteFrag(unsigned char * smac, int sequence, size_t * packetlen, int crypt, unsigned char * wepkey, int weplen) { pFrag_t old, cur = rFragment; int i, len = 0; unsigned char * packet = NULL; unsigned char K[128]; if (rFragment == NULL) return (NULL); if (smac == NULL) return (NULL); while (cur->next != NULL) { old = cur->next; if (memcmp(smac, old->source, 6) == 0 && old->sequence == sequence) { // check if all frags available if (old->fragnum == 0) return (NULL); for (i = 0; i <= old->fragnum; i++) { if (old->fragment[i] == NULL) return (NULL); len += old->fragmentlen[i]; } if (len > 2000) return (NULL); if (old->wep) { if (crypt == CRYPT_WEP) { packet = (unsigned char *) malloc( (size_t) len + old->headerlen + 8); ALLEGE(packet != NULL); K[0] = rand_u8(); K[1] = rand_u8(); K[2] = rand_u8(); K[3] = (uint8_t)(0x00); memcpy(packet, old->header, (size_t) old->headerlen); len = old->headerlen; memcpy(packet + len, K, 4); //-V512 len += 4; for (i = 0; i <= old->fragnum; i++) { memcpy(packet + len, old->fragment[i], (size_t) old->fragmentlen[i]); len += old->fragmentlen[i]; } /* write crc32 value behind data */ if (add_crc32(packet + old->headerlen + 4, len - old->headerlen - 4) != 0) return (NULL); len += 4; // icv memcpy(K + 3, wepkey, (size_t) weplen); encrypt_wep(packet + old->headerlen + 4, len - old->headerlen - 4, K, weplen + 3); packet[1] = (uint8_t)(packet[1] | 0x40); // delete captured fragments delFrag(smac, sequence); *packetlen = (size_t) len; return (packet); } else return (NULL); } else { packet = (unsigned char *) malloc((size_t) len + old->headerlen); ALLEGE(packet != NULL); memcpy(packet, old->header, (size_t) old->headerlen); len = old->headerlen; for (i = 0; i <= old->fragnum; i++) { memcpy(packet + len, old->fragment[i], (size_t) old->fragmentlen[i]); len += old->fragmentlen[i]; } // delete captured fragments delFrag(smac, sequence); *packetlen = (size_t) len; return (packet); } } cur = cur->next; } return (packet); }
C
aircrack-ng/lib/libac/support/mcs_index_rates.c
/* * Functions and macros to obtain 802.11n or ac rates based on MCS index * * Copyright (C) 2018 Thomas d'Otreppe <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and * NON-INFRINGEMENT. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * MA 02110-1301, USA. * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations * including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. If you modify * file(s) with this exception, you may extend this exception to your * version of the file(s), but you are not obligated to do so. If you * do not wish to do so, delete this exception statement from your * version. If you delete this exception statement from all source * files in the program, then also delete it here. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdint.h> #include "aircrack-ng/support/mcs_index_rates.h" // http://mcsindex.com/ // 20/40/80/160MHz -> (0, 1, 2, 3) // 0: long GI, 1: short GI // amount of spatial streams (minus 1) // MCS index const float MCS_index_rates[4][2][8][10] = { // 20MHz {// Long GI {// Spatial streams {6.5, 13.0, 19.5, 26, 39, 52, 58.5, 65, 78, 0}, {13, 26, 39, 52, 78, 104, 117, 130, 156, 0}, {19.5, 39, 58.5, 78, 117, 156, 175.5, 195, 234, 260}, {26, 52, 78, 104, 156, 208, 134, 260, 312, 0}}, // Short GI {{7.2, 14.4, 21.7, 28.9, 43.3, 57.8, 65, 72.2, 86.7, 0}, {14.4, 28.9, 43.3, 57.8, 86.7, 115.6, 130.3, 144.4, 173.3, 0}, {21.7, 43.3, 65, 86.7, 130, 173.3, 195, 216.7, 260, 288.9}, {28.9, 57.8, 56.7, 115.6, 173.3, 231.1, 260, 288.9, 346.7, 0}}}, // 40MHz {// Long GI {{13.5, 27, 40.5, 54, 81, 108, 121.5, 135, 162, 180}, {27, 54, 81, 108, 162, 216, 243, 270, 324, 360}, {40.5, 81, 121.5, 162, 243, 324, 364.5, 405, 486, 540}, {54, 108, 162, 216, 324, 432, 486, 540, 648, 720}}, // Short GI {{15, 30, 45, 60, 90, 120, 135, 150, 180, 200}, {30, 60, 90, 120, 180, 240, 270, 300, 360, 400}, {45, 90, 135, 180, 270, 360, 405, 450, 540, 600}, {60, 120, 180, 240, 360, 480, 540, 600, 720, 800}}}, // 80MHz {// Long GI {{29.3, 58.5, 87.8, 117, 175.5, 234, 263.3, 292.5, 351, 390}, {58.5, 117, 175.5, 234, 351, 468, 526.5, 585, 702, 780}, {87.8, 175.5, 263.3, 351, 526.5, 702, 0, 877.5, 1053, 1170}, {117, 234, 351, 468, 702, 936, 1053, 1170, 1404, 1560}, {146.3, 292.5, 438.8, 585, 877.5, 1170, 1316.3, 1462.5, 1755, 1950}, {175.5, 351, 526.5, 702, 1053, 1404, 1579.5, 1755, 2106, 0}, {204.8, 409.5, 614.3, 819, 1228.5, 1638, 0, 2047.5, 2457, 2730}, {234, 468, 702, 936, 1404, 1872, 2106, 2340, 2808, 3120}}, // Short GI {{32.5, 65, 97.5, 130, 195, 260, 292.5, 325, 390, 433.3}, {65, 130, 195, 260, 390, 520, 585, 650, 780, 866.7}, {97.5, 195, 292.5, 390, 585, 780, 0, 975, 1170, 1300}, {130, 260, 390, 520, 780, 1040, 1170, 1300, 1560, 1733.3}, {162.5, 325, 487.5, 650, 975, 1300, 1462.5, 1625, 1950, 2166.7}, {195, 390, 585, 780, 1170, 1560, 1755, 1950, 2340, 0}, {227.5, 455, 682.5, 910, 1365, 1820, 0, 2275, 2730, 3033.3}, {260, 520, 780, 1040, 1560, 2080, 2340, 2600, 3120, 3466.7}}}, // 160MHz {// Long GI {{58.5, 117, 175.5, 234, 351, 468, 526.5, 585, 702, 780}, {117, 234, 351, 468, 702, 936, 1053, 1170, 1404, 1560}, {175.5, 351, 526.5, 702, 1053, 1404, 1579.5, 1755, 2106, 0}, {234, 468, 702, 936, 1404, 1872, 2106, 2340, 2808, 3120}, {292.5, 585, 877.5, 1170, 1755, 2340, 2632.5, 2925, 3510, 3900}, {351, 702, 1053, 1404, 2106, 2808, 3159, 3510, 4212, 4680}, {409.5, 819, 1228.5, 1638, 2457, 3276, 3685.5, 4095, 4914, 5460}, {468, 936, 1404, 1872, 2808, 3744, 4212, 4680, 5616, 6240}}, // Short GI {{65, 130, 195, 260, 390, 520, 585, 650, 780, 866.7}, {130, 260, 390, 520, 780, 1040, 1170, 1300, 1560, 1733.3}, {195, 390, 585, 780, 1170, 1560, 1755, 1950, 2340, 0}, {260, 520, 780, 1040, 1560, 2080, 2340, 2600, 3120, 3466.7}, {325, 650, 975, 1300, 1950, 2600, 2925, 3250, 3900, 4333.3}, {390, 780, 1170, 1560, 2340, 3120, 3510, 3900, 4680, 5200}, {455, 910, 1365, 1820, 2730, 3640, 4095, 4550, 5460, 6066.7}, {520, 1040, 1560, 2080, 3120, 4160, 4680, 5200, 6240, 6933.3}}}}; float get_80211n_rate(const int width, const int is_short_GI, const int mcs_index) { // Check MCS Index if (mcs_index < 0 || mcs_index > 31) { return -1.0; } uint8_t amount_ss = mcs_index / 8; uint8_t mcs_idx = mcs_index % 8; // Rate index uint8_t width_idx = 0; switch (width) { case 20: width_idx = 0; break; case 40: width_idx = 1; break; default: return -1.0; } // Short GI? uint8_t sgi = !!is_short_GI; return MCS_index_rates[width_idx][sgi][amount_ss][mcs_idx]; } float get_80211ac_rate(const int width, const int is_short_GI, const int mcs_idx, const int amount_ss) { // Check MCS Index if (mcs_idx < 0 || mcs_idx > 9) { return -1.0; } // Rate index uint8_t width_idx = 0; switch (width) { case 20: width_idx = 0; break; case 40: width_idx = 1; break; case 80: width_idx = 2; break; case 160: width_idx = 3; break; default: return -1.0; } // Check amount of spatial streams if (amount_ss < 1 || amount_ss > 8) { return -1.0; } // Short GI? uint8_t sgi = !!is_short_GI; return MCS_index_rates[width_idx][sgi][amount_ss - 1][mcs_idx]; }
C
aircrack-ng/lib/libac/support/strlcat.c
/* $OpenBSD: strlcat.c,v 1.15 2015/03/02 21:41:08 millert Exp $ */ /* * Copyright (c) 1998, 2015 Todd C. Miller <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/types.h> #include <string.h> /* * Appends src to string dst of size dsize (unlike strncat, dsize is the * full size of dst, not space left). At most dsize-1 characters * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). * Returns strlen(src) + MIN(dsize, strlen(initial dst)). * If retval >= dsize, truncation occurred. */ size_t strlcat(char * dst, const char * src, size_t dsize) { const char * odst = dst; const char * osrc = src; size_t n = dsize; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end. */ while (n-- != 0 && *dst != '\0') dst++; dlen = dst - odst; n = dsize - dlen; if (n-- == 0) return (dlen + strlen(src)); while (*src != '\0') { if (n != 0) { *dst++ = *src; n--; } src++; } *dst = '\0'; return (dlen + (src - osrc)); /* count does not include NUL */ }
C
aircrack-ng/lib/libac/support/strlcpy.c
/* $OpenBSD: strlcpy.c,v 1.12 2015/01/15 03:54:12 millert Exp $ */ /* * Copyright (c) 1998, 2015 Todd C. Miller <[email protected]> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/types.h> #include <string.h> /* * Copy string src to buffer dst of size dsize. At most dsize-1 * chars will be copied. Always NUL terminates (unless dsize == 0). * Returns strlen(src); if retval >= dsize, truncation occurred. */ size_t strlcpy(char * dst, const char * src, size_t dsize) { const char * osrc = src; size_t nleft = dsize; /* Copy as many bytes as will fit. */ if (nleft != 0) { while (--nleft != 0) { if ((*dst++ = *src++) == '\0') break; } } /* Not enough room in dst, add NUL and traverse rest of src. */ if (nleft == 0) { if (dsize != 0) *dst = '\0'; /* NUL-terminate dst */ while (*src++) ; } return (src - osrc - 1); /* count does not include NUL */ }
C
aircrack-ng/lib/libac/tui/console.c
/* * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and * NON-INFRINGEMENT. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, * MA 02110-1301, USA. * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations * including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. If you modify * file(s) with this exception, you may extend this exception to your * version of the file(s), but you are not obligated to do so. If you * do not wish to do so, delete this exception statement from your * version. If you delete this exception statement from all source * files in the program, then also delete it here. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <assert.h> #include <stdio.h> #include <locale.h> #include <langinfo.h> #include <termios.h> #if !defined(TIOCGWINSZ) && !defined(linux) #include <sys/termios.h> #endif #include <string.h> #include <unistd.h> #include "aircrack-ng/tui/console.h" #define channel stdout void textcolor(int attr, int fg, int bg) { char command[64]; /* Command is the control command to the terminal */ snprintf( command, sizeof(command), "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40); fprintf(channel, "%s", command); fflush(channel); } void textcolor_fg(int fg) { char command[64]; /* Command is the control command to the terminal */ snprintf(command, sizeof(command), "\033[%dm", fg + 30); fprintf(channel, "%s", command); fflush(channel); } void textcolor_bg(int bg) { char command[64]; /* Command is the control command to the terminal */ snprintf(command, sizeof(command), "\033[%dm", bg + 40); fprintf(channel, "%s", command); fflush(channel); } void textstyle(int attr) { char command[13]; /* Command is the control command to the terminal */ snprintf(command, sizeof(command), "\033[%im", attr); fprintf(channel, "%s", command); fflush(channel); } void reset_term(void) { struct termios oldt, newt; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag |= (ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); } void moveto(int x, int y) { char command[64]; // clamp the X coordinate. if (x < 0) { x = 0; } // clamp the Y coordinate. if (y < 0) { y = 0; } // send ANSI sequence to move the cursor. snprintf(command, sizeof(command), "%c[%d;%dH", 0x1B, y, x); fprintf(channel, "%s", command); fflush(channel); } void move(int which, int n) { char command[13]; static const char movement[] = {'A', 'B', 'C', 'D'}; assert(which >= 0 && which < 4); snprintf(command, sizeof(command), "%c[%d%c", 0x1B, n, movement[which]); fprintf(channel, "%s", command); fflush(channel); } void erase_display(int n) { char command[13]; snprintf(command, sizeof(command), "%c[%dJ", 0x1B, n); fprintf(channel, "%s", command); fflush(channel); } void erase_line(int n) { char command[13]; snprintf(command, sizeof(command), "%c[%dK", 0x1B, n); fprintf(channel, "%s", command); fflush(channel); } void textcolor_normal(void) { char command[13]; snprintf(command, sizeof(command), "%c[22m", 0x1B); fprintf(channel, "%s", command); fflush(channel); } void hide_cursor(void) { char command[13]; snprintf(command, sizeof(command), "%c[?25l", 0x1B); fprintf(channel, "%s", command); fflush(channel); } void show_cursor(void) { char command[13]; snprintf(command, sizeof(command), "%c[?25h", 0x1B); fprintf(channel, "%s", command); fflush(channel); } int mygetch(void) { struct termios oldt, newt; int ch = EOF; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); newt.c_cc[VMIN] = 0; /* require no keypress */ newt.c_cc[VTIME] = 2; /* 20 ms delay */ tcsetattr(STDIN_FILENO, TCSANOW, &newt); char c; if (read(STDIN_FILENO, &c, sizeof(char)) > 0) ch = (int) c; tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return ch; } void console_utf8_enable(void) { setlocale(LC_CTYPE, ""); char * codepage = nl_langinfo(CODESET); if (codepage != NULL && strcmp(codepage, "UTF-8") != 0) { fprintf(stderr, "Warning: Detected you are using a non-UNICODE " "terminal character encoding.\n"); sleep(1); } }
C
aircrack-ng/lib/libac/utf8/verifyssid.c
/* * VerifySSID function (UTF-8 supported) * * Copyright (C) 2018 ZhaoChunsheng * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations * including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. * If you modify * file(s) with this exception, you may extend this exception to your * version of the file(s), but you are not obligated to do so. * If you * do not wish to do so, delete this exception statement from your * version. * If you delete this exception statement from all source * files in the program, then also delete it here. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "aircrack-ng/utf8/verifyssid.h" int verifyssid(const unsigned char * s) { int i; unsigned char c; if (!s || strlen((const char *) s) > 32) { // 32 characters return 0; } for (i = 0; (c = s[i++]);) { if ((c & 0x80) == 0) { // ascii flag if (c < 0x20 || c == 0x7f) { return 0; } } else if ((c & 0xe0) == 0xc0) { // utf8 flag if ((s[i++] & 0xc0) != 0x80) { return 0; } } else if ((c & 0xf0) == 0xe0) { // utf8 flag if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) { return 0; } } else if ((c & 0xf8) == 0xf0) { // utf8 flag if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) { return 0; } } else { return 0; } } return 1; }
C/C++
aircrack-ng/lib/osdep/aircrack_ng_airpcap.h
// Function to be used by cygwin void airpcap_close(void); int airpcap_get_mac(void * mac); int airpcap_set_mac(void * mac); int airpcap_sniff(void * buf, int len, struct rx_info * ri); int airpcap_inject(void * buf, int len, struct tx_info * ti); int airpcap_init(char * param); int airpcap_set_chan(int chan); int isAirpcapDevice(const char * iface); // int printErrorCloseAndReturn(const char * err, int retValue);
C
aircrack-ng/lib/osdep/airpcap.c
/* * Copyright (c) 2007-2018 Thomas d'Otreppe <[email protected]> * * Airpcap stuff * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations * including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. If you modify * file(s) with this exception, you may extend this exception to your * version of the file(s), but you are not obligated to do so. If you * do not wish to do so, delete this exception statement from your * version. If you delete this exception statement from all source * files in the program, then also delete it here. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_AIRPCAP #include <string.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> #include <windows.h> #if defined(__GNUC__) || defined(__llvm__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" #endif #include <airpcap.h> #if defined(__GNUC__) || defined(__llvm__) || defined(__clang__) #pragma GCC diagnostic pop #endif #include "osdep.h" //------------------ PPI --------------------- #define PPH_PH_VERSION ((uint8_t) 0x00) #define PPI_FIELD_TYPE_802_11_COMMON ((uint16_t) 0x02) typedef struct _PPI_PACKET_HEADER { uint8_t PphVersion; uint8_t PphFlags; uint16_t PphLength; uint32_t PphDlt; } PPI_PACKET_HEADER, *PPPI_PACKET_HEADER; typedef struct _PPI_FIELD_HEADER { uint16_t PfhType; uint16_t PfhLength; } PPI_FIELD_HEADER, *PPPI_FIELD_HEADER; typedef struct _PPI_FIELD_802_11_COMMON { uint64_t TsfTimer; uint16_t Flags; uint16_t Rate; uint16_t ChannelFrequency; uint16_t ChannelFlags; uint8_t FhssHopset; uint8_t FhssPattern; int8_t DbmAntSignal; int8_t DbmAntNoise; } PPI_FIELD_802_11_COMMON, *PPPI_FIELD_802_11_COMMON; #define DEVICE_PREFIX "\\\\.\\" #define DEVICE_COMMON_PART "airpcap" PAirpcapHandle airpcap_handle; /** * Check if the device is an Airpcap device * @param iface Interface name * @return 1 if it is an Airpcap device, 0 if not */ int isAirpcapDevice(const char * iface) { char * pos; int len; pos = strstr(iface, DEVICE_COMMON_PART); // Check if it contains "airpcap" if (!pos) return 0; if (pos != iface) { // Check if it begins with '\\.\' if (strstr(iface, AIRPCAP_DEVICE_NAME_PREFIX) != iface) return 0; } len = strlen(iface); // Checking that it contains 2 figures at the end. // No need to check for length, it was already done by the first check if (!(isdigit((int) iface[len - 1])) || !(isdigit((int) iface[len - 2]))) return 0; return 1; } /** * Parse information from a PPI packet (will be used later). * @param p packet * @param caplen Length of the packet * @param hdrlen Length of the header * @param power pointer that will contains the power of the packet * @return 0 if successful decoding, 1 if it failed to decode */ int ppi_decode(const u_char * p, int caplen, int * hdrlen, int * power) { PPPI_PACKET_HEADER pPpiPacketHeader; PPPI_FIELD_HEADER pFieldHeader; ULONG position = 0; // Sanity checks if (caplen < (int) sizeof(*pPpiPacketHeader)) { // Packet smaller than the PPI fixed header return (1); } pPpiPacketHeader = (PPPI_PACKET_HEADER) p; *hdrlen = pPpiPacketHeader->PphLength; if (caplen < *hdrlen) { // Packet smaller than the PPI fixed header return (1); } position = sizeof(*pPpiPacketHeader); if (pPpiPacketHeader->PphVersion != PPH_PH_VERSION) { fprintf(stderr, "Unknown PPI packet header version (%u)\n", pPpiPacketHeader->PphVersion); return (1); } do { // now we suppose to have an 802.11-Common header if (*hdrlen < (int) (sizeof(*pFieldHeader) + position)) { break; } pFieldHeader = (PPPI_FIELD_HEADER)(p + position); position += sizeof(*pFieldHeader); switch (pFieldHeader->PfhType) { case PPI_FIELD_TYPE_802_11_COMMON: if (pFieldHeader->PfhLength != sizeof(PPI_FIELD_802_11_COMMON) || caplen - position < sizeof(PPI_FIELD_802_11_COMMON)) { // the header is bogus, just skip it fprintf(stderr, "Bogus 802.11-Common Field. Skipping it.\n"); } else { PPPI_FIELD_802_11_COMMON pField = (PPPI_FIELD_802_11_COMMON)(p + position); if (pField->DbmAntSignal != -128) { *power = (int) pField->DbmAntSignal; } else { *power = 0; } } break; default: // we do not know this field. Just print type and length and // skip break; } position += pFieldHeader->PfhLength; } while (TRUE); return (0); } /** * Set MAC Address of the device * @param mac MAC Address * @return 0 (successful) */ int airpcap_set_mac(void * mac) { if (mac) { } return 0; } /** * Close device */ void airpcap_close(void) { // By default, when plugged in, the adapter is set in monitor mode; // Application may assume it's already in monitor mode and forget to set it // So, do not remove monitor mode. if (airpcap_handle != NULL) { AirpcapClose(airpcap_handle); airpcap_handle = NULL; } } /** * Get MAC Address of the device (not yet implemented) * @param mac It will contain the mac address * @return 0 (successful) */ int airpcap_get_mac(void * mac) { // Don't use the function from Airpcap if (mac) { } return 0; } /** * Capture one packet * @param buf Buffer for the packet * @param len Length of the buffer * @param ri Receive information * @return -1 if failure or the number of bytes received */ int airpcap_sniff(void * buf, int len, struct rx_info * ri) { // Use PPI headers to obtain the different information for ri // Use AirpcapConvertFrequencyToChannel() to get channel // Add an option to give frequency instead of channel UINT BytesReceived = 0; if (ri) { } // Wait for the next packet // Maybe add an event packets to read // WaitForSingleObject(ReadEvent, INFINITE); // Read a packet if (AirpcapRead(airpcap_handle, buf, len, &BytesReceived)) return (int) BytesReceived; return -1; } /** * Inject one packet * @param buf Buffer for the packet * @param len Length of the buffer * @param ti Transmit information * @return -1 if failure or the number of bytes sent */ int airpcap_inject(void * buf, int len, struct tx_info * ti) { if (ti) { } if (AirpcapWrite(airpcap_handle, buf, len) != 1) return -1; return len; } /** * Print the error message * @param err Contains the error message and a %s in order to show the Airpcap * error * @param retValue Value returned by the function * @return retValue */ int printErrorCloseAndReturn(const char * err, int retValue) { if (err && airpcap_handle) { if (strlen(err)) { if (airpcap_handle) fprintf(stderr, err, AirpcapGetLastError(airpcap_handle)); else fprintf(stderr, "%s", err); } } airpcap_close(); return retValue; } /** * Initialize the device * @param param Parameters for the initialization * @return 0 if successful, -1 in case of failure */ int airpcap_init(char * param) { // Later: if several interfaces are given, aggregate them. char * iface; char errbuf[AIRPCAP_ERRBUF_SIZE]; iface = (char *) calloc(1, strlen(param) + 100); if (param) { // if it's empty, use the default adapter if (*param != 0) { if (strstr(param, DEVICE_PREFIX) == NULL) { // Not found, add it strcpy(iface, DEVICE_PREFIX); strcat(iface, param); } else { // Already contains the adapter header strcpy(iface, param); } } } airpcap_handle = AirpcapOpen(iface, errbuf); if (airpcap_handle == NULL) { fprintf(stderr, "This adapter doesn't have wireless extensions. Quitting\n"); // pcap_close( winpcap_adapter ); return (-1); } /* Tell the adapter that the packets we'll send and receive don't include * the FCS */ if (!AirpcapSetFcsPresence(airpcap_handle, FALSE)) return printErrorCloseAndReturn("Error setting FCS presence: %s\n", -1); /* Set the link layer to bare 802.11 */ if (!AirpcapSetLinkType(airpcap_handle, AIRPCAP_LT_802_11)) return printErrorCloseAndReturn("Error setting the link type: %s\n", -1); /* Accept correct frames only */ if (!AirpcapSetFcsValidation(airpcap_handle, AIRPCAP_VT_ACCEPT_CORRECT_FRAMES)) return printErrorCloseAndReturn("Error setting FCS validation: %s\n", -1); /* Set a low mintocopy for better responsiveness */ if (!AirpcapSetMinToCopy(airpcap_handle, 1)) return printErrorCloseAndReturn("Error setting MinToCopy: %s\n", -1); return 0; } /** * Set device channel * @param chan Channel * @return 0 if successful, -1 if it failed */ int airpcap_set_chan(int chan) { // Make sure a valid channel is given if (chan <= 0) return -1; if (!AirpcapSetDeviceChannel(airpcap_handle, chan)) { printf("Error setting the channel to %d: %s\n", chan, AirpcapGetLastError(airpcap_handle)); return -1; } return 0; } #endif
C
aircrack-ng/lib/osdep/common.c
/* * Copyright (c) 2008-2018, Thomas d'Otreppe <[email protected]> * * Common OSdep stuff * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include "common.h" /** * Return the frequency in Mhz from a channel number */ EXPORT int getFrequencyFromChannel(int channel) { static int frequencies[] = { -1, // No channel 0 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive) 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225, 5230, 5235, 5240, 5245, 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305, 5310, 5315, 5320, 5325, 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385, 5390, 5395, 5400, 5405, 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465, 5470, 5475, 5480, 5485, 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545, 5550, 5555, 5560, 5565, 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625, 5630, 5635, 5640, 5645, 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705, 5710, 5715, 5720, 5725, 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785, 5790, 5795, 5800, 5805, 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865, 5870, 5875, 5880, 5885, 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945, 5950, 5955, 5960, 5965, 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025, 6030, 6035, 6040, 6045, 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100}; return (channel > 0 && channel <= HIGHEST_CHANNEL) ? frequencies[channel] : (channel >= LOWEST_CHANNEL && channel <= -4) ? 5000 - (channel * 5) : -1; } /** * Return the channel from the frequency (in Mhz) */ EXPORT int getChannelFromFrequency(int frequency) { if (frequency >= 2412 && frequency <= 2472) return (frequency - 2407) / 5; else if (frequency == 2484) return 14; else if (frequency >= 4920 && frequency <= 6100) return (frequency - 5000) / 5; else return -1; }
C/C++
aircrack-ng/lib/osdep/crctable_osdep.h
#ifndef _CRCTABLE_OSDEP_H #define _CRCTABLE_OSDEP_H const unsigned long int crc_tbl_osdep[256] = {0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D}; #endif /* crctable_osdep.h */
C
aircrack-ng/lib/osdep/cygwin.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for cygwin. It relies on an external * DLL to do the actual wifi stuff * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <pthread.h> #include <unistd.h> #include <assert.h> #include <stdlib.h> #include <dlfcn.h> #include <string.h> #include <stdio.h> #include <ctype.h> #include <windows.h> #include "osdep.h" #include "network.h" #include "cygwin.h" #ifdef HAVE_AIRPCAP #include "aircrack_ng_airpcap.h" #endif #define xstr(s) str(s) #define str(s) #s #define DLL_EXTENSION ".dll" struct priv_cygwin { pthread_t pc_reader; volatile int pc_running; int pc_pipe[2]; /* reader -> parent */ int pc_channel; int pc_frequency; struct wif * pc_wi; int pc_did_init; int isAirpcap; int useDll; int (*pc_init)(char * param); int (*pc_set_chan)(int chan); int (*pc_set_freq)(int freq); int (*pc_inject)(void * buf, int len, struct tx_info * ti); int (*pc_sniff)(void * buf, int len, struct rx_info * ri); int (*pc_get_mac)(void * mac); int (*pc_set_mac)(void * mac); void (*pc_close)(void); }; /** * strstr() function case insensitive * @param String C string to be scanned * @param Pattern C string containing the sequence of characters to match * @return Pointer to the first occurrence of Pattern in String, or a null * pointer if there Pattern is not part of String. */ char * stristr(const char * String, const char * Pattern) { char *pptr, *sptr, *start; unsigned slen, plen; for (start = (char *) String, pptr = (char *) Pattern, slen = strlen(String), plen = strlen(Pattern); /* while string length not shorter than pattern length */ slen >= plen; start++, slen--) { /* find start of pattern in string */ while (toupper((int) *start) != toupper((int) *Pattern)) { start++; slen--; /* if pattern longer than string */ if (slen < plen) return (NULL); } sptr = start; pptr = (char *) Pattern; while (toupper((int) *sptr) == toupper((int) *pptr)) { sptr++; pptr++; /* if end of pattern then pattern was found */ if ('\0' == *pptr) return (start); } } return (NULL); } /** * Get the different functions for to interact with the device: * - setting monitor mode * - changing channel * - capturing data * - injecting packets * @param iface The interface name */ static int do_cygwin_open(struct wif * wi, char * iface) { struct priv_cygwin * priv = wi_priv(wi); void * lib; char * file; char * parm; int rc = -1; if (!iface) return -1; if (*iface == 0) return -1; priv->useDll = 0; if (stristr(iface, DLL_EXTENSION)) priv->useDll = 1; if (priv->useDll) { file = strdup(iface); if (!file) return -1; parm = strchr(file, '|'); if (parm) *parm++ = 0; /* load lib */ lib = dlopen(file, RTLD_LAZY); if (!lib) goto errdll; #if defined(__GNUC__) || defined(__llvm__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" #endif priv->pc_init = dlsym(lib, xstr(CYGWIN_DLL_INIT)); priv->pc_set_chan = dlsym(lib, xstr(CYGWIN_DLL_SET_CHAN)); priv->pc_set_freq = dlsym(lib, xstr(CYGWIN_DLL_SET_FREQ)); priv->pc_get_mac = dlsym(lib, xstr(CYGWIN_DLL_GET_MAC)); priv->pc_set_mac = dlsym(lib, xstr(CYGWIN_DLL_SET_MAC)); priv->pc_close = dlsym(lib, xstr(CYGWIN_DLL_CLOSE)); priv->pc_inject = dlsym(lib, xstr(CYGWIN_DLL_INJECT)); priv->pc_sniff = dlsym(lib, xstr(CYGWIN_DLL_SNIFF)); #if defined(__GNUC__) || defined(__llvm__) || defined(__clang__) #pragma GCC diagnostic pop #endif if (!(priv->pc_init && priv->pc_set_chan && priv->pc_get_mac && priv->pc_inject && priv->pc_sniff && priv->pc_close)) goto errdll; /* init lib */ if ((rc = priv->pc_init(parm))) goto errdll; priv->pc_did_init = 1; rc = 0; errdll: free(file); } else { #ifdef HAVE_AIRPCAP // Check if it's an Airpcap device priv->isAirpcap = isAirpcapDevice(iface); if (priv->isAirpcap) { // Get functions priv->pc_init = airpcap_init; priv->pc_set_chan = airpcap_set_chan; priv->pc_get_mac = airpcap_get_mac; priv->pc_set_mac = airpcap_set_mac; priv->pc_close = airpcap_close; priv->pc_inject = airpcap_inject; priv->pc_sniff = airpcap_sniff; rc = 0; } #endif } if (rc == 0) { // Don't forget to initialize if (!priv->useDll) { rc = priv->pc_init(iface); if (rc == 0) priv->pc_did_init = 1; else fprintf(stderr, "Error initializing <%s>\n", iface); } } else { // Show an error message if the adapter is not supported fprintf(stderr, "Adapter <%s> not supported\n", iface); } return rc; } /** * Change channel * @param chan Channel * @return 0 if successful, -1 if it failed */ static int cygwin_set_channel(struct wif * wi, int chan) { struct priv_cygwin * priv = wi_priv(wi); if (priv->pc_set_chan(chan) == -1) return -1; priv->pc_channel = chan; return 0; } /** * Change frequency * @param freq Frequency * @return 0 if successful, -1 if it failed */ static int cygwin_set_freq(struct wif * wi, int freq) { struct priv_cygwin * priv = wi_priv(wi); if (!priv->pc_set_freq || priv->pc_set_freq(freq) == -1) return -1; priv->pc_frequency = freq; return 0; } /** * Capture a packet * @param buf Buffer for the packet (has to be already allocated) * @param len Length of the buffer * @param ri Receive information structure * @return -1 in case of failure or the number of bytes received */ static int cygwin_read_packet(struct priv_cygwin * priv, void * buf, int len, struct rx_info * ri) { int rd; memset(ri, 0, sizeof(*ri)); rd = priv->pc_sniff(buf, len, ri); if (rd == -1) return -1; if (!ri->ri_channel) ri->ri_channel = wi_get_channel(priv->pc_wi); return rd; } /** * Send a packet * @param h80211 The packet itself * @param len Length of the packet * @param ti Transmit information * @return -1 if failure or the number of bytes sent */ static int cygwin_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * h80211, int len, struct tx_info * ti) { struct priv_cygwin * priv = wi_priv(wi); int rc; (void) ts; (void) dlt; if ((rc = priv->pc_inject(h80211, len, ti)) == -1) return -1; return rc; } /** * Get device channel * @return channel */ static int cygwin_get_channel(struct wif * wi) { struct priv_cygwin * pc = wi_priv(wi); return pc->pc_channel; } static int cygwin_get_freq(struct wif * wi) { struct priv_cygwin * pc = wi_priv(wi); return pc->pc_frequency; } int cygwin_read_reader(int fd, int plen, void * dst, int len) { /* packet */ if (len > plen) len = plen; if (net_read_exact(fd, dst, len) == -1) return -1; plen -= len; /* consume packet */ while (plen) { char lame[1024]; int rd = sizeof(lame); if (rd > plen) rd = plen; if (net_read_exact(fd, lame, rd) == -1) return -1; plen -= rd; assert(plen >= 0); } return len; } static int cygwin_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * h80211, int len, struct rx_info * ri) { struct priv_cygwin * pc = wi_priv(wi); struct rx_info tmp; int plen; (void) ts; (void) dlt; if (pc->pc_running == -1) return -1; if (!ri) ri = &tmp; /* length */ if (net_read_exact(pc->pc_pipe[0], &plen, sizeof(plen)) == -1) return -1; /* ri */ if (net_read_exact(pc->pc_pipe[0], ri, sizeof(*ri)) == -1) return -1; plen -= sizeof(*ri); assert(plen > 0); return cygwin_read_reader(pc->pc_pipe[0], plen, h80211, len); } /** * Free allocated data */ static void do_free(struct wif * wi) { struct priv_cygwin * pc = wi_priv(wi); int tries = 3; /* wait for reader */ if (pc->pc_running == 1) { pc->pc_running = 0; while ((pc->pc_running != -1) && tries--) sleep(1); } if (pc->pc_pipe[0]) { close(pc->pc_pipe[0]); close(pc->pc_pipe[1]); } if (pc->pc_did_init) pc->pc_close(); assert(wi->wi_priv); free(wi->wi_priv); wi->wi_priv = 0; free(wi); } /** * Close the device and free data */ static void cygwin_close(struct wif * wi) { do_free(wi); } /** * Get the file descriptor for the device */ static int cygwin_fd(struct wif * wi) { struct priv_cygwin * pc = wi_priv(wi); if (pc->pc_running == -1) return -1; return pc->pc_pipe[0]; } /** * Get MAC Address of the device * @param mac It will contain the mac address * @return 0 if successful */ static int cygwin_get_mac(struct wif * wi, unsigned char * mac) { struct priv_cygwin * pc = wi_priv(wi); return pc->pc_get_mac(mac); } /** * Set MAC Address of the device * @param mac MAC Address * @return 0 if successful */ static int cygwin_set_mac(struct wif * wi, unsigned char * mac) { struct priv_cygwin * pc = wi_priv(wi); return pc->pc_set_mac(mac); } static int cygwin_get_monitor(struct wif * wi) { if (wi) { } /* XXX unused */ return 0; } static int cygwin_get_rate(struct wif * wi) { if (wi) { } /* XXX unused */ return 1000000; } /** * Set (injection) rate of the device * @param rate Rate to be used * @return 0 (successful) */ static int cygwin_set_rate(struct wif * wi, int rate) { if (wi || rate) { } /* XXX unused */ return 0; } static void * cygwin_reader(void * arg) { struct priv_cygwin * priv = arg; unsigned char buf[2048]; int len; struct rx_info ri; while (priv->pc_running) { /* read one packet */ /* a potential problem: the cygwin_read_packet will never return * if there no packet sniffered, so the thread cannot be closed * correctly. */ len = cygwin_read_packet(priv, buf, sizeof(buf), &ri); if (len == -1) break; /* len */ len += sizeof(ri); if (write(priv->pc_pipe[1], &len, sizeof(len)) != sizeof(len)) break; len -= sizeof(ri); /* ri */ if (write(priv->pc_pipe[1], &ri, sizeof(ri)) != sizeof(ri)) break; /* packet */ if (write(priv->pc_pipe[1], buf, len) != len) break; } priv->pc_running = -1; return NULL; } static struct wif * cygwin_open(char * iface) { struct wif * wi; struct priv_cygwin * priv; /* setup wi struct */ wi = wi_alloc(sizeof(*priv)); if (!wi) return NULL; wi->wi_read = cygwin_read; wi->wi_write = cygwin_write; wi->wi_set_channel = cygwin_set_channel; wi->wi_get_channel = cygwin_get_channel; wi->wi_set_freq = cygwin_set_freq; wi->wi_get_freq = cygwin_get_freq; wi->wi_close = cygwin_close; wi->wi_fd = cygwin_fd; wi->wi_get_mac = cygwin_get_mac; wi->wi_set_mac = cygwin_set_mac; wi->wi_get_rate = cygwin_get_rate; wi->wi_set_rate = cygwin_set_rate; wi->wi_get_monitor = cygwin_get_monitor; /* setup iface */ if (do_cygwin_open(wi, iface) == -1) goto err; /* setup private state */ priv = wi_priv(wi); priv->pc_wi = wi; /* setup reader */ if (pipe(priv->pc_pipe) == -1) goto err; priv->pc_running = 2; if (pthread_create(&priv->pc_reader, NULL, cygwin_reader, priv)) goto err; priv->pc_running = 1; return wi; err: do_free(wi); return NULL; } struct wif * wi_open_osdep(char * iface) { return cygwin_open(iface); } /** * Return remaining battery time in seconds. * @return Battery time in seconds or 0 if no battery (or connected to power) */ EXPORT int get_battery_state(void) { SYSTEM_POWER_STATUS powerStatus; int batteryTime = 0; if (GetSystemPowerStatus(&powerStatus) == TRUE) { if (powerStatus.ACLineStatus == 0) batteryTime = (int) powerStatus.BatteryLifeTime; } return batteryTime; }
C/C++
aircrack-ng/lib/osdep/cygwin.h
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for cygwin. It relies on an external * DLL to do the actual wifi stuff * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ // DLL function that have to be exported #define CYGWIN_DLL_INIT cygwin_init #define CYGWIN_DLL_SET_CHAN cygwin_set_chan #define CYGWIN_DLL_SET_FREQ cygwin_set_freq #define CYGWIN_DLL_INJECT cygwin_inject #define CYGWIN_DLL_SNIFF cygwin_sniff #define CYGWIN_DLL_GET_MAC cygwin_get_mac #define CYGWIN_DLL_SET_MAC cygwin_set_mac #define CYGWIN_DLL_CLOSE cygwin_close /* * Prototypes: * int CYGWIN_DLL_INIT (char *param); * int CYGWIN_DLL_SET_CHAN (int chan); * int CYGWIN_DLL_INJECT (void *buf, int len, struct tx_info *ti); * int CYGWIN_DLL_SNIFF (void *buf, int len, struct rx_info *ri); * int CYGWIN_DLL_GET_MAC (unsigned char *mac); * int CYGWIN_DLL_SET_MAC (unsigned char *mac); * void CYGWIN_DLL_CLOSE (void); * * Notes: * - sniff can block and inject can be called by another thread. * - return -1 for error. * */ /* XXX the interface is broken. init() should return a void* that is passed to * each call. This way multiple instances can be open by a single process. * -sorbo * */
C
aircrack-ng/lib/osdep/cygwin_tap.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for cygwin. TAP routines * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <pthread.h> #include <assert.h> #include "osdep.h" #include <windows.h> #include <winioctl.h> #include <ipexport.h> #include <iptypes.h> #include <initguid.h> #include <devguid.h> #include <setupapi.h> #include "network.h" #include "tap-win32/common.h" extern DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen); extern DWORD WINAPI AddIPAddress(IPAddr Address, IPMask IpMask, DWORD IfIndex, PULONG NTEContext, PULONG NTEInstance); extern DWORD WINAPI DeleteIPAddress(ULONG NTEContext); extern int cygwin_read_reader(int fd, int plen, void * dst, int len); static void * ti_reader(void * arg); struct tip_cygwin { char tc_name[256]; HANDLE tc_h; pthread_t tc_reader; volatile int tc_running; int tc_pipe[2]; /* reader -> parent */ pthread_mutex_t tc_mtx; HKEY tc_key; char tc_guid[256]; }; /** * Stop the reader thread (if it is running) * @return 0 if stopped or -1 if it failed to stop it */ static int stop_reader(struct tip_cygwin * priv) { if (priv->tc_running == 1) { int tries = 3; priv->tc_running = 0; while ((priv->tc_running != -1) && tries--) sleep(1); if (tries <= 0) return -1; } return 0; } /** * Start reader thread * @return -1 if failed to start thread or 0 if it is successful */ static int start_reader(struct tip_cygwin * priv) { priv->tc_running = 2; if (pthread_create(&priv->tc_reader, NULL, ti_reader, priv)) return -1; priv->tc_running = 1; return 0; } /** * Change status (enable/disable) of the device */ static int ti_media_status(struct tip_cygwin * priv, int on) { ULONG s = on; DWORD len; if (!DeviceIoControl(priv->tc_h, TAP_IOCTL_SET_MEDIA_STATUS, &s, sizeof(s), &s, sizeof(s), &len, NULL)) return -1; return 0; } /** * Try opening device */ static int ti_try_open(struct tip_cygwin * priv, char * guid) { int any = priv->tc_guid[0] == 0; char device[256]; HANDLE h; if (!any && strcmp(priv->tc_guid, guid) != 0) return 0; /* open the device */ const ssize_t device_len = snprintf( device, sizeof(device), "%s%s%s", USERMODEDEVICEDIR, guid, TAPSUFFIX); if (device_len == -1 || (size_t) device_len >= sizeof(device)) return -1; h = CreateFile(device, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); if (h == INVALID_HANDLE_VALUE) { if (any) return 0; else return -1; } priv->tc_h = h; /* XXX check tap version */ /* bring iface up */ if (ti_media_status(priv, 1) == -1) goto out_err; /* grab printable name */ ssize_t err = snprintf(priv->tc_name, sizeof(priv->tc_name) - 1, "%s", guid); if (err == -1 || (size_t) err >= sizeof(priv->tc_name)) goto out_err; if (any) { err = snprintf(priv->tc_guid, sizeof(priv->tc_guid), "%s", guid); if (err == -1 || (size_t) err >= sizeof(priv->tc_guid)) goto out_err; } return 1; out_err: CloseHandle(priv->tc_h); priv->tc_h = INVALID_HANDLE_VALUE; return -1; } /** * Read registry value * @param key Registry key * @return 0 if successful, -1 if it failed */ static int ti_read_reg(struct tip_cygwin * priv, char * key, char * res, int len) { DWORD dt, l = len; if (RegQueryValueEx(priv->tc_key, key, NULL, &dt, (unsigned char *) res, &l) != ERROR_SUCCESS) return -1; if (dt != REG_SZ) return -1; if ((int) l > len) return -1; return 0; } static int ti_get_devs_component(struct tip_cygwin * priv, char * name) { char key[256]; int rc = 0; const ssize_t key_len = snprintf(key, sizeof(key) - 1, "%s\\%s", ADAPTER_KEY, name); if (key_len == -1 || (size_t) key_len >= sizeof(key)) return -1; if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, key, 0, KEY_READ | KEY_WRITE, &priv->tc_key) != ERROR_SUCCESS) return -1; if (ti_read_reg(priv, "ComponentId", key, sizeof(key)) == -1) goto out; /* make sure component id matches */ if (strcmp(key, TAP_COMPONENT_ID) != 0) goto out; /* get guid */ if (ti_read_reg(priv, "NetCfgInstanceId", key, sizeof(key)) == -1) goto out; rc = ti_try_open(priv, key); out: if (rc != 1) { RegCloseKey(priv->tc_key); priv->tc_key = 0; } return rc; } static int ti_do_open_cygwin(struct tip_cygwin * priv) { int rc = -1; HKEY ak47; int i; char name[256]; DWORD len; /* open network driver key */ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, ADAPTER_KEY, 0, KEY_READ, &ak47) != ERROR_SUCCESS) return -1; /* find tap */ for (i = 0;; i++) { len = sizeof(name); if (RegEnumKeyEx(ak47, i, name, &len, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) break; rc = ti_get_devs_component(priv, name); if (rc) break; rc = -1; } RegCloseKey(ak47); if (rc == 1) rc = 0; return rc; } static void ti_do_free(struct tif * ti) { struct tip_cygwin * priv = ti_priv(ti); /* stop reader */ stop_reader(priv); if (priv->tc_pipe[0]) { close(priv->tc_pipe[0]); close(priv->tc_pipe[1]); } /* close card */ if (priv->tc_h) { ti_media_status(priv, 0); CloseHandle(priv->tc_h); } if (priv->tc_key) RegCloseKey(priv->tc_key); free(priv); free(ti); } static void ti_close_cygwin(struct tif * ti) { ti_do_free(ti); } static char * ti_name_cygwin(struct tif * ti) { struct tip_cygwin * priv = ti_priv(ti); return priv->tc_name; } /* XXX */ static int ti_is_us(struct tip_cygwin * priv, HDEVINFO * hdi, SP_DEVINFO_DATA * did) { char buf[256]; DWORD len = sizeof(buf), dt; if (priv) { } /* XXX unused */ if (!SetupDiGetDeviceRegistryProperty( *hdi, did, SPDRP_DEVICEDESC, &dt, (unsigned char *) buf, len, &len)) return 0; if (dt != REG_SZ) return 0; return strstr(buf, "TAP-Win32") != NULL; } static int ti_reset_state(HDEVINFO * hdi, SP_DEVINFO_DATA * did, DWORD state) { SP_PROPCHANGE_PARAMS parm; parm.ClassInstallHeader.cbSize = sizeof(parm.ClassInstallHeader); parm.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE; parm.Scope = DICS_FLAG_GLOBAL; parm.StateChange = state; if (!SetupDiSetClassInstallParams( *hdi, did, (SP_CLASSINSTALL_HEADER *) &parm, sizeof(parm))) return -1; if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, *hdi, did)) return -1; return 0; } /** * Reset the device * @return 0 if successful, -1 if it failed */ static int ti_do_reset(HDEVINFO * hdi, SP_DEVINFO_DATA * did) { int rc; rc = ti_reset_state(hdi, did, DICS_DISABLE); if (rc) return rc; return ti_reset_state(hdi, did, DICS_ENABLE); } static int ti_restart(struct tip_cygwin * priv) { /* kill handle to if */ if (priv->tc_h) CloseHandle(priv->tc_h); /* stop reader */ if (stop_reader(priv)) return -1; /* reopen dev */ if (ti_do_open_cygwin(priv)) return -1; return start_reader(priv); } static int ti_reset(struct tip_cygwin * priv) { HDEVINFO hdi; SP_DEVINFO_DATA did; int i; int rc = -1; hdi = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT); if (hdi == INVALID_HANDLE_VALUE) return -1; /* find device */ for (i = 0;; i++) { did.cbSize = sizeof(did); if (!SetupDiEnumDeviceInfo(hdi, i, &did)) break; if (!ti_is_us(priv, &hdi, &did)) continue; rc = ti_do_reset(&hdi, &did); if (rc) break; rc = ti_restart(priv); break; } SetupDiDestroyDeviceInfoList(hdi); return rc; } static int ti_set_mtu_cygwin(struct tif * ti, int mtu) { struct tip_cygwin * priv = ti_priv(ti); char m[16]; char mold[sizeof(m)]; char * key = "MTU"; /* check if reg remains unchanged to avoid reset */ const ssize_t m_len = snprintf(m, sizeof(m) - 1, "%d", mtu); if (m_len == -1 || (size_t) m_len >= sizeof(m)) return -1; if (ti_read_reg(priv, key, mold, sizeof(mold)) != -1) { if (strcmp(m, mold) == 0) return 0; } /* change */ if (RegSetValueEx( priv->tc_key, key, 0, REG_SZ, (unsigned char *) m, strlen(m) + 1) != ERROR_SUCCESS) return -1; if (ti_reset(priv) == -1) return -1; return 0; } /** * Set device MAC address * @param mac New MAC address * @return -1 if it failed, 0 on success */ static int ti_set_mac_cygwin(struct tif * ti, unsigned char * mac) { struct tip_cygwin * priv = ti_priv(ti); char str[2 * 6 + 1]; char strold[sizeof(str)]; int i; char * key = "MAC"; /* convert */ str[0] = 0; for (i = 0; i < 6; i++) { char tmp[3]; if (sprintf(tmp, "%.2X", *mac++) != 2) return -1; strcat(str, tmp); } /* check if changed */ if (ti_read_reg(priv, key, strold, sizeof(strold)) != -1) { if (strcmp(str, strold) == 0) return 0; } /* own */ if (RegSetValueEx(priv->tc_key, key, 0, REG_SZ, (unsigned char *) str, strlen(str) + 1) != ERROR_SUCCESS) return -1; if (ti_reset(priv) == -1) return -1; return 0; } /** * Set device IP address * @param ip New IP address * @return -1 if it failed, 0 on success */ static int ti_set_ip_cygwin(struct tif * ti, struct in_addr * ip) { struct tip_cygwin * priv = ti_priv(ti); ULONG ctx, inst; IP_ADAPTER_INFO ai[16]; DWORD len = sizeof(ai); PIP_ADAPTER_INFO p; PIP_ADDR_STRING ips; if (GetAdaptersInfo(ai, &len) != ERROR_SUCCESS) return -1; p = ai; while (p) { if (strcmp(priv->tc_guid, p->AdapterName) != 0) { p = p->Next; continue; } /* delete ips */ ips = &p->IpAddressList; while (ips) { DeleteIPAddress(ips->Context); ips = ips->Next; } /* add ip */ if (AddIPAddress(ip->s_addr, htonl(0xffffff00), p->Index, &ctx, &inst) != NO_ERROR) return -1; break; } return 0; } static int ti_fd_cygwin(struct tif * ti) { struct tip_cygwin * priv = ti_priv(ti); return priv->tc_pipe[0]; } static int ti_read_cygwin(struct tif * ti, void * buf, int len) { struct tip_cygwin * priv = ti_priv(ti); int plen; if (priv->tc_running != 1) return -1; /* read len */ if (net_read_exact(priv->tc_pipe[0], &plen, sizeof(plen)) == -1) return -1; return cygwin_read_reader(priv->tc_pipe[0], plen, buf, len); } static int ti_wait_complete(struct tip_cygwin * priv, OVERLAPPED * o) { DWORD sz; if (!GetOverlappedResult(priv->tc_h, o, &sz, TRUE)) return -1; return sz; } static int ti_do_io(struct tip_cygwin * priv, void * buf, int len, OVERLAPPED * o, int wr) { BOOL rc; DWORD sz; int err; /* setup overlapped */ memset(o, 0, sizeof(*o)); /* do io */ if (wr) rc = WriteFile(priv->tc_h, buf, len, &sz, o); else rc = ReadFile(priv->tc_h, buf, len, &sz, o); /* done */ if (rc) return sz; if ((err = GetLastError()) != ERROR_IO_PENDING) return -1; return 0; /* pending */ } static int ti_do_io_lock( struct tip_cygwin * priv, void * buf, int len, OVERLAPPED * o, int wr) { int rc; if (pthread_mutex_lock(&priv->tc_mtx)) return -1; rc = ti_do_io(priv, buf, len, o, wr); if (pthread_mutex_unlock(&priv->tc_mtx)) return -1; /* done */ if (rc) return rc; return ti_wait_complete(priv, o); } static int ti_write_cygwin(struct tif * ti, void * buf, int len) { struct tip_cygwin * priv = ti_priv(ti); OVERLAPPED o; return ti_do_io_lock(priv, buf, len, &o, 1); } static int ti_read_packet(struct tip_cygwin * priv, void * buf, int len) { OVERLAPPED o; int rc; while (priv->tc_running) { rc = ti_do_io_lock(priv, buf, len, &o, 0); if (rc) return rc; } return -1; } static void * ti_reader(void * arg) { struct tip_cygwin * priv = arg; unsigned char buf[2048]; int len; while (priv->tc_running) { /* read a packet */ if ((len = ti_read_packet(priv, buf, sizeof(buf))) == -1) break; assert(len > 0); /* write it's length */ if (write(priv->tc_pipe[1], &len, sizeof(len)) != sizeof(len)) break; /* write payload */ if (write(priv->tc_pipe[1], buf, len) != len) break; } priv->tc_running = -1; return NULL; } static struct tif * ti_open_cygwin(char * iface) { struct tif * ti; struct tip_cygwin * priv; /* setup ti struct */ ti = ti_alloc(sizeof(*priv)); if (!ti) return NULL; priv = ti_priv(ti); ti->ti_name = ti_name_cygwin; ti->ti_set_mtu = ti_set_mtu_cygwin; ti->ti_close = ti_close_cygwin; ti->ti_fd = ti_fd_cygwin; ti->ti_read = ti_read_cygwin; ti->ti_write = ti_write_cygwin; ti->ti_set_mac = ti_set_mac_cygwin; ti->ti_set_ip = ti_set_ip_cygwin; /* setup iface */ if (iface) { const ssize_t err = snprintf(priv->tc_guid, sizeof(priv->tc_guid), "%s", iface); if (err == -1 || (size_t) err >= sizeof(priv->tc_guid)) goto err; } if (ti_do_open_cygwin(priv) == -1) goto err; /* setup reader */ if (pipe(priv->tc_pipe) == -1) goto err; if (pthread_mutex_init(&priv->tc_mtx, NULL)) goto err; /* launch reader */ if (start_reader(priv)) goto err; return ti; err: ti_do_free(ti); return NULL; } EXPORT struct tif * ti_open(char * iface) { return ti_open_cygwin(iface); }
C
aircrack-ng/lib/osdep/darwin.c
/* * Copyright (c) 2009, Kyle Fuller <[email protected]>, based upon * freebsd.c by Andrea Bittau <[email protected]> * * OS dependent API for Darwin. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <errno.h> #include <stdio.h> #include "osdep.h" struct wif * wi_open_osdep(char * iface) { if (iface) { } /* XXX unused parameter */ errno = EOPNOTSUPP; return NULL; } EXPORT int get_battery_state(void) { errno = EOPNOTSUPP; return -1; } int create_tap(void) { errno = EOPNOTSUPP; return -1; }
C
aircrack-ng/lib/osdep/darwin_tap.c
/* * Copyright (c) 2009, Kyle Fuller <[email protected]>, based upon * freebsd_tap.c by Andrea Bittau <[email protected]> * * OS dependent API for Darwin. TAP routines * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/socket.h> #include <net/if.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include "osdep.h" #define MAX_TAP_DEVS 16 struct tip_darwin { int tf_fd; int tf_ioctls; struct ifreq tf_ifr; char tf_name[IFNAMSIZ - 1]; int tf_destroy; }; static int ti_do_open_darwin(struct tif * ti, char * name) { int fd = -1; char iface[IFNAMSIZ]; struct stat st; struct tip_darwin * priv = ti_priv(ti); int s; unsigned int flags; struct ifreq * ifr; int i; /* open tap */ if (name) { fd = open(name, O_RDWR); } else { priv->tf_destroy = 1; /* we create, we destroy */ for (i = 0; i < MAX_TAP_DEVS; i++) { snprintf(iface, sizeof(iface), "/dev/tap%d", i); fd = open(iface, O_RDWR); if (fd != -1) { break; } } } if (fd == -1) { return -1; } /* get name */ if (fstat(fd, &st) == -1) goto err; snprintf(priv->tf_name, sizeof(priv->tf_name) - 1, "%s", devname(st.st_rdev, S_IFCHR)); /* bring iface up */ s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) goto err; priv->tf_ioctls = s; /* get flags */ ifr = &priv->tf_ifr; memset(ifr, 0, sizeof(*ifr)); snprintf(ifr->ifr_name, sizeof(ifr->ifr_name) - 1, "%s", priv->tf_name); if (ioctl(s, SIOCGIFFLAGS, ifr) == -1) goto err2; flags = (ifr->ifr_flags & 0xffff); /* set flags */ flags |= IFF_UP; ifr->ifr_flags = flags & 0xffff; if (ioctl(s, SIOCSIFFLAGS, ifr) == -1) goto err2; return fd; err: /* XXX destroy */ close(fd); return -1; err2: close(s); goto err; } static void ti_do_free(struct tif * ti) { struct tip_darwin * priv = ti_priv(ti); free(priv); free(ti); } static void ti_destroy(struct tip_darwin * priv) { ioctl(priv->tf_ioctls, SIOCIFDESTROY, &priv->tf_ifr); } static void ti_close_darwin(struct tif * ti) { struct tip_darwin * priv = ti_priv(ti); if (priv->tf_destroy) ti_destroy(priv); close(priv->tf_fd); close(priv->tf_ioctls); ti_do_free(ti); } static char * ti_name_darwin(struct tif * ti) { struct tip_darwin * priv = ti_priv(ti); return priv->tf_name; } static int ti_set_mtu_darwin(struct tif * ti, int mtu) { struct tip_darwin * priv = ti_priv(ti); priv->tf_ifr.ifr_mtu = mtu; return ioctl(priv->tf_ioctls, SIOCSIFMTU, &priv->tf_ifr); } static int ti_set_mac_darwin(struct tif * ti, unsigned char * mac) { struct tip_darwin * priv = ti_priv(ti); struct ifreq * ifr = &priv->tf_ifr; ifr->ifr_addr.sa_family = AF_LINK; ifr->ifr_addr.sa_len = 6; memcpy(ifr->ifr_addr.sa_data, mac, 6); return ioctl(priv->tf_ioctls, SIOCSIFLLADDR, ifr); } static int ti_set_ip_darwin(struct tif * ti, struct in_addr * ip) { struct tip_darwin * priv = ti_priv(ti); struct ifaliasreq ifra; struct sockaddr_in * s_in; /* assume same size */ memset(&ifra, 0, sizeof(ifra)); strcpy(ifra.ifra_name, priv->tf_ifr.ifr_name); s_in = (struct sockaddr_in *) &ifra.ifra_addr; s_in->sin_family = PF_INET; s_in->sin_addr = *ip; s_in->sin_len = sizeof(*s_in); return ioctl(priv->tf_ioctls, SIOCAIFADDR, &ifra); } static int ti_fd_darwin(struct tif * ti) { struct tip_darwin * priv = ti_priv(ti); return priv->tf_fd; } static int ti_read_darwin(struct tif * ti, void * buf, int len) { return read(ti_fd(ti), buf, len); } static int ti_write_darwin(struct tif * ti, void * buf, int len) { return write(ti_fd(ti), buf, len); } static struct tif * ti_open_darwin(char * iface) { struct tif * ti; struct tip_darwin * priv; int fd; /* setup ti struct */ ti = ti_alloc(sizeof(*priv)); if (!ti) return NULL; ti->ti_name = ti_name_darwin; ti->ti_set_mtu = ti_set_mtu_darwin; ti->ti_close = ti_close_darwin; ti->ti_fd = ti_fd_darwin; ti->ti_read = ti_read_darwin; ti->ti_write = ti_write_darwin; ti->ti_set_mac = ti_set_mac_darwin; ti->ti_set_ip = ti_set_ip_darwin; /* setup iface */ fd = ti_do_open_darwin(ti, iface); if (fd == -1) { ti_do_free(ti); return NULL; } /* setup private state */ priv = ti_priv(ti); priv->tf_fd = fd; return ti; } EXPORT struct tif * ti_open(char * iface) { return ti_open_darwin(iface); }
C
aircrack-ng/lib/osdep/dummy.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for unsupported APIs. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <errno.h> #include <stdio.h> #include "osdep.h" struct wif * wi_open_osdep(char * iface) { if (iface) { } /* XXX unused parameter */ errno = EOPNOTSUPP; return NULL; } EXPORT int get_battery_state(void) { errno = EOPNOTSUPP; return -1; } int create_tap(void) { errno = EOPNOTSUPP; return -1; }
C
aircrack-ng/lib/osdep/dummy_tap.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for unsupported APIs. TAP routines * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <stdlib.h> #include "osdep.h" static struct tif * ti_open_dummy(char * iface) { if (iface) { } /* XXX unused parameter */ return NULL; } EXPORT struct tif * ti_open(char * iface) { return ti_open_dummy(iface); }
C
aircrack-ng/lib/osdep/file.c
/* * Copyright (c) 2010 Andrea Bittau <[email protected]> * * OS dependent API for using card via a pcap file. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <assert.h> #include <sys/select.h> #include <errno.h> #include <fcntl.h> #include <err.h> #include "osdep.h" #include "aircrack-ng/support/pcap_local.h" #include "radiotap/radiotap_iter.h" #include "common.h" struct priv_file { int pf_fd; int pf_chan; int pf_rate; int pf_dtl; uint32_t pf_magic; unsigned char pf_mac[6]; }; static int file_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * h80211, int len, struct rx_info * ri) { struct priv_file * pf = wi_priv(wi); struct pcap_pkthdr pkh; int rc; int got_signal = 0; int got_noise = 0; unsigned char buf[4096] __attribute__((aligned(8))); int off = 0; struct ieee80211_radiotap_header * rh; struct ieee80211_radiotap_iterator iterator; memset(&iterator, 0, sizeof(iterator)); rc = read(pf->pf_fd, &pkh, sizeof(pkh)); if (rc != sizeof(pkh)) return -1; if (pf->pf_magic == TCPDUMP_CIGAM) { pkh.caplen = ___my_swab32(pkh.caplen); pkh.len = ___my_swab32(pkh.len); } if (pkh.caplen > sizeof(buf)) { printf("Bad caplen %lu\n", (unsigned long) pkh.caplen); return 0; } assert(pkh.caplen <= sizeof(buf)); //-V547 rc = read(pf->pf_fd, buf, pkh.caplen); if (rc != (int) pkh.caplen) return -1; if (ri) memset(ri, 0, sizeof(*ri)); switch (pf->pf_dtl) { case LINKTYPE_IEEE802_11: off = 0; break; case LINKTYPE_RADIOTAP_HDR: rh = (struct ieee80211_radiotap_header *) buf; off = le16_to_cpu(rh->it_len); if (ieee80211_radiotap_iterator_init(&iterator, rh, rc, NULL) < 0) return -1; while (ieee80211_radiotap_iterator_next(&iterator) >= 0) { switch (iterator.this_arg_index) { case IEEE80211_RADIOTAP_TSFT: if (ri) ri->ri_mactime = le64_to_cpu( *((uint64_t *) iterator.this_arg)); break; case IEEE80211_RADIOTAP_DB_ANTSIGNAL: case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: if (ri && !got_signal) { if (*iterator.this_arg < 127) ri->ri_power = *iterator.this_arg; else ri->ri_power = *iterator.this_arg - 255; got_signal = 1; } break; case IEEE80211_RADIOTAP_DB_ANTNOISE: case IEEE80211_RADIOTAP_DBM_ANTNOISE: if (ri && !got_noise) { if (*iterator.this_arg < 127) ri->ri_noise = *iterator.this_arg; else ri->ri_noise = *iterator.this_arg - 255; got_noise = 1; } break; case IEEE80211_RADIOTAP_ANTENNA: if (ri) ri->ri_antenna = *iterator.this_arg; break; case IEEE80211_RADIOTAP_CHANNEL: if (ri) ri->ri_channel = getChannelFromFrequency( le16toh(*(uint16_t *) iterator.this_arg)); break; case IEEE80211_RADIOTAP_RATE: if (ri) ri->ri_rate = (*iterator.this_arg) * 500000; break; case IEEE80211_RADIOTAP_FLAGS: if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) rc -= 4; break; } } break; case LINKTYPE_PRISM_HEADER: if (buf[7] == 0x40) { off = 0x40; if (ri) { ri->ri_power = -((int32_t) load32_le(buf + 0x33)); ri->ri_noise = (int32_t) load32_le(buf + 0x33 + 12); ri->ri_rate = load32_le(buf + 0x33 + 24) * 500000; // got_signal = 1; // got_noise = 1; } } else { off = load32_le(buf + 4); if (ri) { ri->ri_mactime = load64_le(buf + 0x5C - 48); ri->ri_channel = load32_le(buf + 0x5C - 36); ri->ri_power = -((int32_t) load32_le(buf + 0x5C)); ri->ri_noise = (int32_t) load32_le(buf + 0x5C + 12); ri->ri_rate = load32_le(buf + 0x5C + 24) * 500000; } } rc -= 4; break; case LINKTYPE_PPI_HDR: off = load16_le(buf + 2); /* for a while Kismet logged broken PPI headers */ if (off == 24 && load16_le(buf + 8) == 2) off = 32; break; case LINKTYPE_ETHERNET: printf("Ethernet packets\n"); return 0; default: errx(1, "Unknown DTL %d", pf->pf_dtl); break; } rc -= off; assert(rc >= 0); if (off < 0 || rc < 0) return -1; if (rc > len) rc = len; if (dlt) { *dlt = LINKTYPE_IEEE802_11; } if (ts) { ts->tv_sec = pkh.tv_sec; ts->tv_nsec = pkh.tv_usec * 1000UL; } if (off < 0 || off >= len) return -1; //-V560 memcpy(h80211, &buf[off], rc); return rc; } static int file_get_mac(struct wif * wi, unsigned char * mac) { struct priv_file * pn = wi_priv(wi); memcpy(mac, pn->pf_mac, sizeof(pn->pf_mac)); return 0; } static int file_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * h80211, int len, struct tx_info * ti) { struct priv_file * pn = wi_priv(wi); if (h80211 && ti && pn && ts && dlt) { } return len; } static int file_set_channel(struct wif * wi, int chan) { struct priv_file * pf = wi_priv(wi); pf->pf_chan = chan; return 0; } static int file_get_channel(struct wif * wi) { struct priv_file * pf = wi_priv(wi); return pf->pf_chan; } static int file_set_rate(struct wif * wi, int rate) { struct priv_file * pf = wi_priv(wi); pf->pf_rate = rate; return 0; } static int file_get_rate(struct wif * wi) { struct priv_file * pf = wi_priv(wi); return pf->pf_rate; } static int file_get_monitor(struct wif * wi) { if (wi) { } return 1; } static void file_close(struct wif * wi) { struct priv_file * pn = wi_priv(wi); if (pn) { if (pn->pf_fd) { close(pn->pf_fd); } free(pn); } free(wi); } static int file_fd(struct wif * wi) { struct priv_file * pf = wi_priv(wi); return pf->pf_fd; } struct wif * file_open(char * iface) { struct wif * wi; struct priv_file * pf; int fd; struct pcap_file_header pfh; int rc; if (iface == NULL || strncmp(iface, "file://", 7) != 0) return NULL; /* setup wi struct */ wi = wi_alloc(sizeof(*pf)); if (!wi) return NULL; wi->wi_read = file_read; wi->wi_write = file_write; wi->wi_set_channel = file_set_channel; wi->wi_get_channel = file_get_channel; wi->wi_set_rate = file_set_rate; wi->wi_get_rate = file_get_rate; wi->wi_close = file_close; wi->wi_fd = file_fd; wi->wi_get_mac = file_get_mac; wi->wi_get_monitor = file_get_monitor; pf = wi_priv(wi); fd = open(iface + 7, O_RDONLY); if (fd == -1) err(1, "open()"); pf->pf_fd = fd; if ((rc = read(fd, &pfh, sizeof(pfh))) != sizeof(pfh)) goto __err; if (pfh.magic != TCPDUMP_MAGIC && pfh.magic != TCPDUMP_CIGAM) goto __err; if (pfh.magic == TCPDUMP_CIGAM) { pfh.version_major = ___my_swab16(pfh.version_major); pfh.version_minor = ___my_swab16(pfh.version_minor); pfh.linktype = ___my_swab32(pfh.linktype); } if (pfh.version_major != PCAP_VERSION_MAJOR || pfh.version_minor != PCAP_VERSION_MINOR) goto __err; pf->pf_dtl = pfh.linktype; pf->pf_magic = pfh.magic; return wi; __err: wi_close(wi); return (struct wif *) -1; }
C
aircrack-ng/lib/osdep/freebsd.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for FreeBSD. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/endian.h> #include <errno.h> #include <fcntl.h> #include <sys/types.h> #include <sys/sysctl.h> #include <net/bpf.h> #include <sys/socket.h> #include <net/if.h> #include <net/if_media.h> #include <sys/ioctl.h> #include <net/if_dl.h> #ifdef __DragonFly__ #include <netproto/802_11/ieee80211_ioctl.h> #include <netproto/802_11/ieee80211_radiotap.h> #include <netproto/802_11/ieee80211_dragonfly.h> #else #include <net80211/ieee80211_ioctl.h> #include <net80211/ieee80211_radiotap.h> #include <net80211/ieee80211_freebsd.h> #endif #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/uio.h> #include <assert.h> #include <ifaddrs.h> #include "osdep.h" #ifndef LINKTYPE_IEEE802_11 #define LINKTYPE_IEEE802_11 105 #endif struct priv_fbsd { /* iface */ int pf_fd; /* rx */ int pf_nocrc; /* tx */ unsigned char pf_buf[4096]; unsigned char * pf_next; int pf_totlen; struct ieee80211_bpf_params pf_txparams; /* setchan */ int pf_s; struct ifreq pf_ifr; struct ieee80211req pf_ireq; int pf_chan; }; /* from ifconfig */ static __inline int mapgsm(u_int freq, u_int flags) { freq *= 10; if (flags & IEEE80211_CHAN_QUARTER) freq += 5; else if (flags & IEEE80211_CHAN_HALF) freq += 10; else freq += 20; /* NB: there is no 907/20 wide but leave room */ return (freq - 906 * 10) / 5; } static __inline int mappsb(u_int freq) { return 37 + ((freq * 10) + ((freq % 5) == 2 ? 5 : 0) - 49400) / 5; } /* * Convert MHz frequency to IEEE channel number. */ static u_int ieee80211_mhz2ieee(u_int freq, u_int flags) { if ((flags & IEEE80211_CHAN_GSM) || (907 <= freq && freq <= 922)) return mapgsm(freq, flags); if (freq == 2484) return 14; if (freq < 2484) return (freq - 2407) / 5; if (freq < 5000) { if (flags & (IEEE80211_CHAN_HALF | IEEE80211_CHAN_QUARTER)) return mappsb(freq); else if (freq > 4900) return (freq - 4000) / 5; else return 15 + ((freq - 2512) / 20); } return (freq - 5000) / 5; } /* end of ifconfig */ static void get_radiotap_info(struct priv_fbsd * pf, struct ieee80211_radiotap_header * rth, int * plen, struct rx_info * ri) { uint32_t present; uint8_t rflags = 0; int i; unsigned char * body = (unsigned char *) (rth + 1); int dbm_power = 0, db_power = 0; /* reset control info */ if (ri) memset(ri, 0, sizeof(*ri)); /* get info */ present = le32toh(rth->it_present); for (i = IEEE80211_RADIOTAP_TSFT; i <= IEEE80211_RADIOTAP_EXT; i++) { if (!(present & (1 << i))) continue; switch (i) { case IEEE80211_RADIOTAP_TSFT: body += sizeof(uint64_t); break; case IEEE80211_RADIOTAP_FLAGS: rflags = *((uint8_t *) body); /* fall through */ case IEEE80211_RADIOTAP_RATE: body += sizeof(uint8_t); break; case IEEE80211_RADIOTAP_CHANNEL: if (ri) { uint16_t * p = (uint16_t *) body; int c = ieee80211_mhz2ieee(*p, *(p + 1)); ri->ri_channel = c; } body += sizeof(uint16_t) * 2; break; case IEEE80211_RADIOTAP_FHSS: body += sizeof(uint16_t); break; case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: dbm_power = *body++; break; case IEEE80211_RADIOTAP_DBM_ANTNOISE: dbm_power -= *body++; break; case IEEE80211_RADIOTAP_DB_ANTSIGNAL: db_power = *body++; break; case IEEE80211_RADIOTAP_DB_ANTNOISE: db_power -= *body++; break; default: i = IEEE80211_RADIOTAP_EXT + 1; break; } } /* set power */ if (ri) { if (dbm_power) ri->ri_power = dbm_power; else ri->ri_power = db_power; } /* XXX cache; drivers won't change this per-packet */ /* check if FCS/CRC is included in packet */ if (pf->pf_nocrc || (rflags & IEEE80211_RADIOTAP_F_FCS)) { *plen -= IEEE80211_CRC_LEN; pf->pf_nocrc = 1; } } static unsigned char * get_80211(struct priv_fbsd * pf, int * plen, struct rx_info * ri) { struct bpf_hdr * bpfh; struct ieee80211_radiotap_header * rth; void * ptr; unsigned char ** data; int * totlen; data = &pf->pf_next; totlen = &pf->pf_totlen; assert(*totlen); /* bpf hdr */ bpfh = (struct bpf_hdr *) (*data); assert(bpfh->bh_caplen == bpfh->bh_datalen); /* XXX */ *totlen -= bpfh->bh_hdrlen; /* check if more packets */ if ((int) bpfh->bh_caplen < *totlen) { int tot = bpfh->bh_hdrlen + bpfh->bh_caplen; int offset = BPF_WORDALIGN(tot); *data = (unsigned char *) bpfh + offset; *totlen -= offset - tot; /* take into account align bytes */ } else if ((int) bpfh->bh_caplen > *totlen) abort(); *plen = bpfh->bh_caplen; *totlen -= bpfh->bh_caplen; assert(*totlen >= 0); /* radiotap */ rth = (struct ieee80211_radiotap_header *) ((char *) bpfh + bpfh->bh_hdrlen); get_radiotap_info(pf, rth, plen, ri); *plen -= rth->it_len; assert(*plen > 0); /* data */ ptr = (char *) rth + rth->it_len; return ptr; } static int fbsd_get_channel(struct wif * wi) { struct priv_fbsd * pf = wi_priv(wi); if (ioctl(pf->pf_s, SIOCG80211, &pf->pf_ireq) != 0) return -1; return pf->pf_ireq.i_val; } static int fbsd_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * h80211, int len, struct rx_info * ri) { struct priv_fbsd * pf = wi_priv(wi); unsigned char * wh; int plen; assert(len > 0); /* need to read more */ if (pf->pf_totlen == 0) { pf->pf_totlen = read(pf->pf_fd, pf->pf_buf, sizeof(pf->pf_buf)); if (pf->pf_totlen == -1) { pf->pf_totlen = 0; return -1; } pf->pf_next = pf->pf_buf; } /* read 802.11 packet */ wh = get_80211(pf, &plen, ri); if (plen > len) plen = len; assert(plen > 0); memcpy(h80211, wh, plen); if (dlt) { *dlt = LINKTYPE_IEEE802_11; } if (ts) { clock_gettime(CLOCK_REALTIME, ts); } if (ri && !ri->ri_channel) ri->ri_channel = wi_get_channel(wi); return plen; } static int fbsd_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * h80211, int len, struct tx_info * ti) { struct iovec iov[2]; struct priv_fbsd * pf = wi_priv(wi); int rc; (void) ts; (void) dlt; /* XXX make use of ti */ if (ti) { } iov[0].iov_base = &pf->pf_txparams; iov[0].iov_len = pf->pf_txparams.ibp_len; iov[1].iov_base = h80211; iov[1].iov_len = len; rc = writev(pf->pf_fd, iov, 2); if (rc == -1) return rc; if (rc < (int) iov[0].iov_len) return 0; return rc - iov[0].iov_len; } static int fbsd_set_channel(struct wif * wi, int chan) { struct priv_fbsd * pf = wi_priv(wi); pf->pf_ireq.i_val = chan; if (ioctl(pf->pf_s, SIOCS80211, &pf->pf_ireq) != 0) return -1; pf->pf_chan = chan; return 0; } static void do_free(struct wif * wi) { assert(wi->wi_priv); free(wi->wi_priv); wi->wi_priv = 0; free(wi); } static void fbsd_close(struct wif * wi) { struct priv_fbsd * pf = wi_priv(wi); close(pf->pf_fd); close(pf->pf_s); do_free(wi); } static int do_fbsd_open(struct wif * wi, char * iface) { int i; char buf[64]; int fd = -1; struct ifreq ifr; unsigned int dlt = DLT_IEEE802_11_RADIO; int s; unsigned int flags; struct ifmediareq ifmr; int * mwords; struct priv_fbsd * pf = wi_priv(wi); /* basic sanity check */ if (strlen(iface) >= sizeof(ifr.ifr_name)) return -1; /* open wifi */ s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) return -1; pf->pf_s = s; /* set iface up and promisc */ memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, iface); if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) goto close_sock; flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16); flags |= IFF_UP | IFF_PPROMISC; memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, iface); ifr.ifr_flags = flags & 0xffff; ifr.ifr_flagshigh = flags >> 16; if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) goto close_sock; /* monitor mode */ memset(&ifmr, 0, sizeof(ifmr)); strcpy(ifmr.ifm_name, iface); if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) goto close_sock; assert(ifmr.ifm_count != 0); mwords = (int *) malloc(ifmr.ifm_count * sizeof(int)); if (!mwords) goto close_sock; ifmr.ifm_ulist = mwords; if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) { free(mwords); goto close_sock; } free(mwords); memset(&ifr, 0, sizeof(ifr)); strcpy(ifr.ifr_name, iface); ifr.ifr_media = ifmr.ifm_current; if (ioctl(s, SIOCSIFMEDIA, &ifr) == -1) goto close_sock; /* setup ifreq for chan that may be used in future */ strcpy(pf->pf_ireq.i_name, iface); pf->pf_ireq.i_type = IEEE80211_IOC_CHANNEL; /* same for ifreq [mac addr] */ strcpy(pf->pf_ifr.ifr_name, iface); /* open bpf */ for (i = 0; i < 256; i++) { sprintf(buf, "/dev/bpf%d", i); fd = open(buf, O_RDWR); if (fd < 0) { if (errno != EBUSY) return -1; continue; } else break; } if (fd < 0) goto close_sock; strcpy(ifr.ifr_name, iface); if (ioctl(fd, BIOCSETIF, &ifr) < 0) goto close_bpf; if (ioctl(fd, BIOCSDLT, &dlt) < 0) goto close_bpf; dlt = 1; if (ioctl(fd, BIOCIMMEDIATE, &dlt) == -1) goto close_bpf; return fd; close_sock: close(s); return -1; close_bpf: close(fd); goto close_sock; } static int fbsd_fd(struct wif * wi) { struct priv_fbsd * pf = wi_priv(wi); return pf->pf_fd; } static int fbsd_get_mac(struct wif * wi, unsigned char * mac) { struct ifaddrs *ifa, *p; char * name = wi_get_ifname(wi); int rc = -1; struct sockaddr_dl * sdp; if (getifaddrs(&ifa) == -1) return -1; p = ifa; while (p) { if (p->ifa_addr->sa_family == AF_LINK && strcmp(name, p->ifa_name) == 0) { sdp = (struct sockaddr_dl *) p->ifa_addr; memcpy(mac, sdp->sdl_data + sdp->sdl_nlen, 6); rc = 0; break; } p = p->ifa_next; } freeifaddrs(ifa); return rc; } static int fbsd_get_monitor(struct wif * wi) { if (wi) { } /* XXX unused */ /* XXX */ return 0; } static int fbsd_get_rate(struct wif * wi) { if (wi) { } /* XXX unused */ /* XXX */ return 1000000; } static int fbsd_set_rate(struct wif * wi, int rate) { if (wi || rate) { } /* XXX unused */ /* XXX */ return 0; } static int fbsd_set_mac(struct wif * wi, unsigned char * mac) { struct priv_fbsd * priv = wi_priv(wi); struct ifreq * ifr = &priv->pf_ifr; ifr->ifr_addr.sa_family = AF_LINK; ifr->ifr_addr.sa_len = 6; memcpy(ifr->ifr_addr.sa_data, mac, 6); return ioctl(priv->pf_s, SIOCSIFLLADDR, ifr); } static int fbsd_set_mtu(struct wif * wi, int mtu) { struct priv_fbsd * priv = wi_priv(wi); struct ifreq * ifr = &priv->pf_ifr; memset(ifr, 0, sizeof(struct ifreq)); strncpy(ifr->ifr_name, wi_get_ifname(wi), sizeof(ifr->ifr_name)); ifr->ifr_mtu = mtu; if (ioctl(priv->pf_s, SIOCSIFMTU, ifr) < 0) return -1; return 0; } static int fbsd_get_mtu(struct wif * wi) { struct priv_fbsd * priv = wi_priv(wi); struct ifreq ifr; memset(&ifr, 0, sizeof(struct ifreq)); ifr.ifr_addr.sa_family = AF_INET; strncpy(ifr.ifr_name, wi_get_ifname(wi), sizeof(ifr.ifr_name)); if (ioctl(priv->pf_s, SIOCGIFMTU, (caddr_t) &ifr) < 0) return -1; return ifr.ifr_mtu; } static struct wif * fbsd_open(char * iface) { struct wif * wi; struct priv_fbsd * pf; int fd; /* setup wi struct */ wi = wi_alloc(sizeof(*pf)); if (!wi) return NULL; wi->wi_read = fbsd_read; wi->wi_write = fbsd_write; wi->wi_set_channel = fbsd_set_channel; wi->wi_get_channel = fbsd_get_channel; wi->wi_close = fbsd_close; wi->wi_fd = fbsd_fd; wi->wi_get_mac = fbsd_get_mac; wi->wi_set_mac = fbsd_set_mac; wi->wi_get_rate = fbsd_get_rate; wi->wi_set_rate = fbsd_set_rate; wi->wi_get_monitor = fbsd_get_monitor; wi->wi_get_mtu = fbsd_get_mtu; wi->wi_set_mtu = fbsd_set_mtu; /* setup iface */ fd = do_fbsd_open(wi, iface); if (fd == -1) { do_free(wi); return NULL; } /* setup private state */ pf = wi_priv(wi); pf->pf_fd = fd; pf->pf_txparams.ibp_vers = IEEE80211_BPF_VERSION; pf->pf_txparams.ibp_len = sizeof(struct ieee80211_bpf_params) - 6; pf->pf_txparams.ibp_rate0 = 2; /* 1 MB/s XXX */ pf->pf_txparams.ibp_try0 = 1; /* no retransmits */ pf->pf_txparams.ibp_rate1 = 2; /* 1 MB/s XXX */ pf->pf_txparams.ibp_try1 = 1; /* no retransmits */ pf->pf_txparams.ibp_flags = IEEE80211_BPF_NOACK; pf->pf_txparams.ibp_power = 100; /* nominal max */ pf->pf_txparams.ibp_pri = WME_AC_VO; /* high priority */ return wi; } struct wif * wi_open_osdep(char * iface) { return fbsd_open(iface); } EXPORT int get_battery_state(void) { #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__MidnightBSD__) int value; size_t len; len = 4; value = 0; sysctlbyname("hw.acpi.acline", &value, &len, NULL, 0); if (value == 0) { sysctlbyname("hw.acpi.battery.time", &value, &len, NULL, 0); value = value * 60; } else { value = 0; } return (value); #elif defined(_BSD_SOURCE) struct apm_power_info api; int apmfd; if ((apmfd = open("/dev/apm", O_RDONLY)) < 0) return 0; if (ioctl(apmfd, APM_IOC_GETPOWER, &api) < 0) { close(apmfd); return 0; } close(apmfd); if (api.battery_state == APM_BATT_UNKNOWN || api.battery_state == APM_BATTERY_ABSENT || api.battery_state == APM_BATT_CHARGING || api.ac_state == APM_AC_ON) { return 0; } return ((int) (api.minutes_left)) * 60; #else return 0; #endif }
C
aircrack-ng/lib/osdep/freebsd_tap.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for FreeBSD. TAP routines * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/socket.h> #include <net/if.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include "aircrack-ng/defs.h" #include "osdep.h" struct tip_fbsd { int tf_fd; int tf_ioctls; struct ifreq tf_ifr; char tf_name[IFNAMSIZ]; int tf_destroy; }; static int ti_do_open_fbsd(struct tif * ti, char * name) { int fd; char * iface = "/dev/tap"; struct stat st; struct tip_fbsd * priv = ti_priv(ti); int s; unsigned int flags; struct ifreq * ifr; /* open tap */ if (name) iface = name; else priv->tf_destroy = 1; /* we create, we destroy */ fd = open(iface, O_RDWR); if (fd == -1) return -1; /* get name */ if (fstat(fd, &st) == -1) goto err; snprintf(priv->tf_name, sizeof(priv->tf_name) - 1, "%s", devname(st.st_rdev, S_IFCHR)); /* bring iface up */ s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) goto err; priv->tf_ioctls = s; /* get flags */ ifr = &priv->tf_ifr; memset(ifr, 0, sizeof(*ifr)); snprintf(ifr->ifr_name, sizeof(ifr->ifr_name), "%s", priv->tf_name); if (ioctl(s, SIOCGIFFLAGS, ifr) == -1) goto err2; flags = (ifr->ifr_flags & 0xffff) | (ifr->ifr_flagshigh << 16); /* set flags */ flags |= IFF_UP; ifr->ifr_flags = flags & 0xffff; ifr->ifr_flagshigh = flags >> 16; if (ioctl(s, SIOCSIFFLAGS, ifr) == -1) goto err2; return fd; err: /* XXX destroy */ close(fd); return -1; err2: close(s); goto err; } static void ti_do_free(struct tif * ti) { struct tip_fbsd * priv = ti_priv(ti); free(priv); free(ti); } static void ti_destroy(struct tip_fbsd * priv) { ioctl(priv->tf_ioctls, SIOCIFDESTROY, &priv->tf_ifr); } static void ti_close_fbsd(struct tif * ti) { struct tip_fbsd * priv = ti_priv(ti); if (priv->tf_destroy) ti_destroy(priv); close(priv->tf_fd); close(priv->tf_ioctls); ti_do_free(ti); } static char * ti_name_fbsd(struct tif * ti) { struct tip_fbsd * priv = ti_priv(ti); return priv->tf_name; } static int ti_set_mtu_fbsd(struct tif * ti, int mtu) { struct tip_fbsd * priv = ti_priv(ti); priv->tf_ifr.ifr_mtu = mtu; return ioctl(priv->tf_ioctls, SIOCSIFMTU, &priv->tf_ifr); } static int ti_set_mac_fbsd(struct tif * ti, unsigned char * mac) { struct tip_fbsd * priv = ti_priv(ti); struct ifreq * ifr = &priv->tf_ifr; ifr->ifr_addr.sa_family = AF_LINK; ifr->ifr_addr.sa_len = 6; memcpy(ifr->ifr_addr.sa_data, mac, 6); return ioctl(priv->tf_ioctls, SIOCSIFLLADDR, ifr); } static int ti_set_ip_fbsd(struct tif * ti, struct in_addr * ip) { struct tip_fbsd * priv = ti_priv(ti); struct ifaliasreq ifra; struct sockaddr_in * s_in; /* assume same size */ memset(&ifra, 0, sizeof(ifra)); strcpy(ifra.ifra_name, priv->tf_ifr.ifr_name); s_in = (struct sockaddr_in *) &ifra.ifra_addr; s_in->sin_family = PF_INET; s_in->sin_addr = *ip; s_in->sin_len = sizeof(*s_in); return ioctl(priv->tf_ioctls, SIOCAIFADDR, &ifra); } static int ti_fd_fbsd(struct tif * ti) { struct tip_fbsd * priv = ti_priv(ti); return priv->tf_fd; } static int ti_read_fbsd(struct tif * ti, void * buf, int len) { return read(ti_fd(ti), buf, len); } static int ti_write_fbsd(struct tif * ti, void * buf, int len) { return write(ti_fd(ti), buf, len); } static struct tif * ti_open_fbsd(char * iface) { struct tif * ti; struct tip_fbsd * priv; int fd; /* setup ti struct */ ti = ti_alloc(sizeof(*priv)); if (!ti) return NULL; ti->ti_name = ti_name_fbsd; ti->ti_set_mtu = ti_set_mtu_fbsd; ti->ti_close = ti_close_fbsd; ti->ti_fd = ti_fd_fbsd; ti->ti_read = ti_read_fbsd; ti->ti_write = ti_write_fbsd; ti->ti_set_mac = ti_set_mac_fbsd; ti->ti_set_ip = ti_set_ip_fbsd; /* setup iface */ fd = ti_do_open_fbsd(ti, iface); if (fd == -1) { ti_do_free(ti); return NULL; } /* setup private state */ priv = ti_priv(ti); priv->tf_fd = fd; return ti; } EXPORT struct tif * ti_open(char * iface) { return ti_open_fbsd(iface); }
C
aircrack-ng/lib/osdep/linux.c
/* * OS dependent APIs for Linux * * Copyright (C) 2006-2018 Thomas d'Otreppe <[email protected]> * Copyright (C) 2004, 2005 Christophe Devine * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/time.h> #include <sys/stat.h> #include <netpacket/packet.h> #include <linux/if_ether.h> #include <linux/if.h> #include <linux/wireless.h> #include <netinet/in.h> #include <linux/if_tun.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <dirent.h> #include <sys/utsname.h> #include <net/if_arp.h> #include <limits.h> #ifdef CONFIG_LIBNL #include <linux/nl80211.h> #include <netlink/genl/genl.h> #include <netlink/genl/family.h> #include <netlink/genl/ctrl.h> #include <netlink/msg.h> #include <netlink/attr.h> #include <linux/genetlink.h> #endif // CONFIG_LIBNL #include "radiotap/radiotap.h" #include "radiotap/radiotap_iter.h" /* radiotap-parser defines types like u8 that * ieee80211_radiotap.h needs * * we use our local copy of ieee80211_radiotap.h * * - since we can't support extensions we don't understand * - since linux does not include it in userspace headers */ #include "osdep.h" #include "aircrack-ng/support/pcap_local.h" #include "crctable_osdep.h" #include "common.h" #include "channel.h" #include "aircrack-ng/defs.h" #ifdef CONFIG_LIBNL struct nl80211_state state; static int chan; #endif // CONFIG_LIBNL /* if_nametoindex is defined in net/if.h but that conflicts with linux/if.h */ extern unsigned int if_nametoindex(const char * __ifname); extern char * if_indextoname(unsigned int __ifindex, char * __ifname); typedef enum { DT_NULL = 0, DT_WLANNG, DT_HOSTAP, DT_MADWIFI, DT_MADWIFING, DT_BCM43XX, DT_ORINOCO, DT_ZD1211RW, DT_ACX, DT_MAC80211_RT, DT_AT76USB, DT_IPW2200 } DRIVER_TYPE; /* * XXX need to have a different read/write/open function for each Linux driver. */ struct priv_linux { int fd_in, arptype_in; int fd_out, arptype_out; int fd_main; int fd_rtc; DRIVER_TYPE drivertype; /* inited to DT_UNKNOWN on allocation by wi_alloc */ FILE * f_cap_in; struct pcap_file_header pfh_in; int sysfs_inject; int channel; int freq; int rate; int tx_power; char * wlanctlng; /* XXX never set */ char * iwpriv; char * iwconfig; char * ifconfig; char * wl; char * main_if; unsigned char pl_mac[6]; int inject_wlanng; }; #ifndef ETH_P_80211_RAW #define ETH_P_80211_RAW 25 #endif #define ARPHRD_ETHERNET 1 #define ARPHRD_IEEE80211 801 #define ARPHRD_IEEE80211_PRISM 802 #define ARPHRD_IEEE80211_FULL 803 #ifndef NULL_MAC #define NULL_MAC "\x00\x00\x00\x00\x00\x00" #endif static unsigned long calc_crc_osdep(unsigned char * buf, int len) { unsigned long crc = 0xFFFFFFFF; for (; len > 0; len--, buf++) crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8); return (~crc); } /* CRC checksum verification routine */ static int check_crc_buf_osdep(unsigned char * buf, int len) { unsigned long crc; if (len < 0) return 0; crc = calc_crc_osdep(buf, len); buf += len; return (((crc) &0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]); } // Check if the driver is ndiswrapper */ static int is_ndiswrapper(const char * iface, const char * path) { int n, pid; if (!path || !iface || strlen(iface) >= IFNAMSIZ) { return 0; } if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execl(path, "iwpriv", iface, "ndis_reset", NULL); exit(1); } waitpid(pid, &n, 0); return ((WIFEXITED(n) && WEXITSTATUS(n) == 0)); } /* Search a file recursively */ static char * searchInside(const char * dir, const char * filename) { char * ret; char * curfile; struct stat sb; int len, lentot; DIR * dp; struct dirent * ep; dp = opendir(dir); if (dp == NULL) { return NULL; } len = strlen(filename); lentot = strlen(dir) + 256 + 2; curfile = (char *) calloc(1, lentot); if (curfile == NULL) { (void) closedir(dp); return (NULL); } while ((ep = readdir(dp)) != NULL) { memset(curfile, 0, lentot); sprintf(curfile, "%s/%s", dir, ep->d_name); // Checking if it's the good file if ((int) strlen(ep->d_name) == len && !strcmp(ep->d_name, filename)) { (void) closedir(dp); return curfile; } // If it's a directory and not a link, try to go inside to search if (lstat(curfile, &sb) == 0 && S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode)) { // Check if the directory isn't "." or ".." if (strcmp(".", ep->d_name) && strcmp("..", ep->d_name)) { // Recursive call ret = searchInside(curfile, filename); if (ret != NULL) { (void) closedir(dp); free(curfile); return ret; } } } } (void) closedir(dp); free(curfile); return NULL; } /* Search a wireless tool and return its path */ static char * wiToolsPath(const char * tool) { char * path /*, *found, *env */; int i, nbelems; static const char * paths[] = {"/sbin", "/usr/sbin", "/usr/local/sbin", "/bin", "/usr/bin", "/usr/local/bin", "/tmp"}; // Also search in other known location just in case we haven't found it yet nbelems = sizeof(paths) / sizeof(char *); for (i = 0; i < nbelems; i++) { path = searchInside(paths[i], tool); if (path != NULL) return path; } return NULL; } /* nl80211 */ #ifdef CONFIG_LIBNL struct nl80211_state { #if !defined(CONFIG_LIBNL30) && !defined(CONFIG_LIBNL20) struct nl_handle * nl_sock; #else struct nl_sock * nl_sock; #endif struct nl_cache * nl_cache; struct genl_family * nl80211; }; #if !defined(CONFIG_LIBNL30) && !defined(CONFIG_LIBNL20) static inline struct nl_handle * nl_socket_alloc(void) { return nl_handle_alloc(); } static inline void nl_socket_free(struct nl_handle * h) { nl_handle_destroy(h); } static inline int __genl_ctrl_alloc_cache(struct nl_handle * h, struct nl_cache ** cache) { struct nl_cache * tmp = genl_ctrl_alloc_cache(h); if (!tmp) return -ENOMEM; *cache = tmp; return 0; } #define genl_ctrl_alloc_cache __genl_ctrl_alloc_cache #endif static int linux_nl80211_init(struct nl80211_state * state) { int err; state->nl_sock = nl_socket_alloc(); if (!state->nl_sock) { fprintf(stderr, "Failed to allocate netlink socket.\n"); return -ENOMEM; } if (genl_connect(state->nl_sock)) { fprintf(stderr, "Failed to connect to generic netlink.\n"); err = -ENOLINK; goto out_handle_destroy; } if (genl_ctrl_alloc_cache(state->nl_sock, &state->nl_cache)) { fprintf(stderr, "Failed to allocate generic netlink cache.\n"); err = -ENOMEM; goto out_handle_destroy; } state->nl80211 = genl_ctrl_search_by_name(state->nl_cache, "nl80211"); if (!state->nl80211) { fprintf(stderr, "nl80211 not found.\n"); err = -ENOENT; goto out_cache_free; } return 0; out_cache_free: nl_cache_free(state->nl_cache); out_handle_destroy: nl_socket_free(state->nl_sock); return err; } static void nl80211_cleanup(struct nl80211_state * state) { genl_family_put(state->nl80211); nl_cache_free(state->nl_cache); nl_socket_free(state->nl_sock); } /* Callbacks */ /* static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) { if (nla) { } printf("\n\n\nERROR"); int *ret = arg; *ret = err->error; return NL_STOP; } */ /* static void test_callback(struct nl_msg *msg, void *arg) { if (msg || arg) { } } */ #endif /* End nl80211 */ static int linux_get_channel(struct wif * wi) { struct priv_linux * dev = wi_priv(wi); struct iwreq wrq; int fd, frequency; int chan = 0; memset(&wrq, 0, sizeof(struct iwreq)); if (dev->main_if) strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ); else strncpy(wrq.ifr_name, wi_get_ifname(wi), IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; fd = dev->fd_in; if (dev->drivertype == DT_IPW2200) fd = dev->fd_main; if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0) return (-1); frequency = wrq.u.freq.m; if (frequency > 100000000) frequency /= 100000; else if (frequency > 1000000) frequency /= 1000; if (frequency > 1000) chan = getChannelFromFrequency(frequency); else chan = frequency; return chan; } static int linux_get_freq(struct wif * wi) { struct priv_linux * dev = wi_priv(wi); struct iwreq wrq; int fd, frequency; memset(&wrq, 0, sizeof(struct iwreq)); if (dev->main_if) strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ); else strncpy(wrq.ifr_name, wi_get_ifname(wi), IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; fd = dev->fd_in; if (dev->drivertype == DT_IPW2200) fd = dev->fd_main; if (ioctl(fd, SIOCGIWFREQ, &wrq) < 0) return (-1); frequency = wrq.u.freq.m; if (frequency > 100000000) frequency /= 100000; else if (frequency > 1000000) frequency /= 1000; if (frequency < 500) // it's not a freq, but the actual channel frequency = getFrequencyFromChannel(frequency); return frequency; } static int linux_set_rate(struct wif * wi, int rate) { struct priv_linux * dev = wi_priv(wi); struct ifreq ifr; struct iwreq wrq; char s[32]; int pid, status; memset(s, 0, sizeof(s)); switch (dev->drivertype) { case DT_MADWIFING: memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, wi_get_ifname(wi), sizeof(ifr.ifr_name) - 1); if (ioctl(dev->fd_in, SIOCGIFINDEX, &ifr) < 0) { printf("Interface %s: \n", wi_get_ifname(wi)); perror("ioctl(SIOCGIFINDEX) failed"); return (1); } /* Bring interface down*/ ifr.ifr_flags = 0; if (ioctl(dev->fd_in, SIOCSIFFLAGS, &ifr) < 0) { perror("ioctl(SIOCSIFFLAGS) failed"); return (1); } usleep(100000); snprintf(s, sizeof(s) - 1, "%.1fM", (rate / 1000000.0)); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwconfig, "iwconfig", wi_get_ifname(wi), "rate", s, NULL); exit(1); } waitpid(pid, &status, 0); return 0; break; case DT_MAC80211_RT: dev->rate = (rate / 500000); // return 0; // Newer mac80211 stacks (2.6.31 and up) // don't care about Radiotap header anymore, so ioctl below must // also be done! //[see Documentation/networking/mac80211-injection.txt] break; default: break; } /* ELSE */ memset(&wrq, 0, sizeof(struct iwreq)); if (dev->main_if) strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ); else strncpy(wrq.ifr_name, wi_get_ifname(wi), IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; wrq.u.bitrate.value = rate; wrq.u.bitrate.fixed = 1; if (ioctl(dev->fd_in, SIOCSIWRATE, &wrq) < 0) { return (-1); } return 0; } static int linux_get_rate(struct wif * wi) { struct priv_linux * dev = wi_priv(wi); struct iwreq wrq; memset(&wrq, 0, sizeof(struct iwreq)); if (dev->drivertype == DT_MAC80211_RT) return (dev->rate * 500000); if (dev->main_if) strncpy(wrq.ifr_name, dev->main_if, IFNAMSIZ); else strncpy(wrq.ifr_name, wi_get_ifname(wi), IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; if (ioctl(dev->fd_in, SIOCGIWRATE, &wrq) < 0) { return (-1); } return wrq.u.bitrate.value; } static int linux_set_mtu(struct wif * wi, int mtu) { struct priv_linux * dev = wi_priv(wi); struct ifreq ifr; memset(&ifr, 0, sizeof(struct ifreq)); if (dev->main_if) strncpy(ifr.ifr_name, dev->main_if, sizeof(ifr.ifr_name) - 1); else strncpy(ifr.ifr_name, wi_get_ifname(wi), sizeof(ifr.ifr_name) - 1); ifr.ifr_mtu = mtu; if (ioctl(dev->fd_in, SIOCSIFMTU, &ifr) < 0) { return (-1); } return 0; } static int linux_get_mtu(struct wif * wi) { struct priv_linux * dev = wi_priv(wi); struct ifreq ifr; memset(&ifr, 0, sizeof(struct ifreq)); if (dev->main_if) strncpy(ifr.ifr_name, dev->main_if, sizeof(ifr.ifr_name) - 1); else strncpy(ifr.ifr_name, wi_get_ifname(wi), sizeof(ifr.ifr_name) - 1); if (ioctl(dev->fd_in, SIOCGIFMTU, &ifr) < 0) { return (-1); } return ifr.ifr_mtu; } static int linux_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * buf, int count, struct rx_info * ri) { struct priv_linux * dev = wi_priv(wi); unsigned char tmpbuf[4096] __attribute__((aligned(8))); int caplen, n, got_signal, got_noise, got_channel, fcs_removed; n = got_signal = got_noise = got_channel = fcs_removed = 0; if ((unsigned) count > sizeof(tmpbuf)) return (-1); caplen = read(dev->fd_in, tmpbuf, count); if (caplen < 0 && errno == EAGAIN) return (-1); else if (caplen < 0) { perror("read failed"); return (-1); } switch (dev->drivertype) { case DT_MADWIFI: caplen -= 4; /* remove the FCS for madwifi-old! only (not -ng)*/ break; default: break; } if (dlt) { // TODO(jbenden): Future code could receive the actual linktype received. *dlt = LINKTYPE_IEEE802_11; } if (ts) { clock_gettime(CLOCK_REALTIME, ts); } if (dev->arptype_in == ARPHRD_IEEE80211_PRISM) { /* skip the prism header */ if (tmpbuf[7] == 0x40) { /* prism54 uses a different format */ if (ri) { ri->ri_power = (int32_t) load32_le(tmpbuf + 0x33); ri->ri_noise = (int32_t) load32_le(tmpbuf + 0x33 + 12); ri->ri_rate = load32_le(tmpbuf + 0x33 + 24) * 500000; got_signal = 1; got_noise = 1; } n = 0x40; } else { if (ri) { ri->ri_mactime = load64_le(tmpbuf + 0x5C - 48); ri->ri_channel = load32_le(tmpbuf + 0x5C - 36); ri->ri_power = (int32_t) load32_le(tmpbuf + 0x5C); ri->ri_noise = (int32_t) load32_le(tmpbuf + 0x5C + 12); ri->ri_rate = load32_le(tmpbuf + 0x5C + 24) * 500000; if (dev->drivertype == DT_MADWIFI || dev->drivertype == DT_MADWIFING) ri->ri_power -= (int32_t) load32_le(tmpbuf + 0x68); got_channel = 1; got_signal = 1; got_noise = 1; } n = load32_le(tmpbuf + 4); } if (n < 8 || n >= caplen) return (0); } if (dev->arptype_in == ARPHRD_IEEE80211_FULL) { struct ieee80211_radiotap_iterator iterator; struct ieee80211_radiotap_header * rthdr; rthdr = (struct ieee80211_radiotap_header *) tmpbuf; //-V1032 if (ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen, NULL) < 0) return (0); /* go through the radiotap arguments we have been given * by the driver */ while (ri && (ieee80211_radiotap_iterator_next(&iterator) >= 0)) { switch (iterator.this_arg_index) { case IEEE80211_RADIOTAP_TSFT: ri->ri_mactime = le64_to_cpu(*((uint64_t *) iterator.this_arg)); break; case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: case IEEE80211_RADIOTAP_DB_ANTSIGNAL: if (!got_signal) { if (*iterator.this_arg < 127) ri->ri_power = *iterator.this_arg; else ri->ri_power = *iterator.this_arg - 255; got_signal = 1; } break; case IEEE80211_RADIOTAP_DBM_ANTNOISE: case IEEE80211_RADIOTAP_DB_ANTNOISE: if (!got_noise) { if (*iterator.this_arg < 127) ri->ri_noise = *iterator.this_arg; else ri->ri_noise = *iterator.this_arg - 255; got_noise = 1; } break; case IEEE80211_RADIOTAP_ANTENNA: ri->ri_antenna = *iterator.this_arg; break; case IEEE80211_RADIOTAP_CHANNEL: ri->ri_channel = getChannelFromFrequency( le16toh(*(uint16_t *) iterator.this_arg)); got_channel = 1; break; case IEEE80211_RADIOTAP_RATE: ri->ri_rate = (*iterator.this_arg) * 500000; break; case IEEE80211_RADIOTAP_FLAGS: /* is the CRC visible at the end? * remove */ if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { fcs_removed = 1; caplen -= 4; } if (*iterator.this_arg & IEEE80211_RADIOTAP_F_BADFCS) return (0); break; } } n = le16_to_cpu(rthdr->it_len); if (n <= 0 || n >= caplen) return (0); } caplen -= n; // detect fcs at the end, even if the flag wasn't set and remove it if (fcs_removed == 0 && check_crc_buf_osdep(tmpbuf + n, caplen - 4) == 1) { caplen -= 4; } memcpy(buf, tmpbuf + n, caplen); if (ri && !got_channel) ri->ri_channel = wi_get_channel(wi); return (caplen); } static int linux_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * buf, int count, struct tx_info * ti) { struct priv_linux * dev = wi_priv(wi); unsigned char maddr[6]; int ret, usedrtap = 0; unsigned char tmpbuf[4096]; unsigned char rate; unsigned short int * p_rtlen; unsigned char u8aRadiotap[] __attribute__((aligned(8))) = { 0x00, 0x00, // <-- radiotap version 0x0c, 0x00, // <- radiotap header length 0x04, 0x80, 0x00, 0x00, // <-- bitmap 0x00, // <-- rate 0x00, // <-- padding for natural alignment 0x18, 0x00, // <-- TX flags }; /* Pointer to the radiotap header length field for later use. */ p_rtlen = (unsigned short int *) (u8aRadiotap + 2); //-V1032 if ((unsigned) count > sizeof(tmpbuf) - 22) return -1; /* XXX honor ti */ if (ti) { } (void) ts; (void) dlt; rate = dev->rate; u8aRadiotap[8] = rate; switch (dev->drivertype) { case DT_MAC80211_RT: memcpy(tmpbuf, u8aRadiotap, sizeof(u8aRadiotap)); memcpy(tmpbuf + sizeof(u8aRadiotap), buf, count); count += sizeof(u8aRadiotap); buf = tmpbuf; usedrtap = 1; break; case DT_WLANNG: /* Wlan-ng isn't able to inject on kernel > 2.6.11 */ if (dev->inject_wlanng == 0) { perror("write failed"); return (-1); } if (count >= 24) { /* for some reason, wlan-ng requires a special header */ if ((((unsigned char *) buf)[1] & 3) != 3) { memcpy(tmpbuf, buf, 24); memset(tmpbuf + 24, 0, 22); tmpbuf[30] = (count - 24) & 0xFF; tmpbuf[31] = (count - 24) >> 8; memcpy(tmpbuf + 46, buf + 24, count - 24); count += 22; } else { memcpy(tmpbuf, buf, 30); memset(tmpbuf + 30, 0, 16); tmpbuf[30] = (count - 30) & 0xFF; tmpbuf[31] = (count - 30) >> 8; //-V610 memcpy(tmpbuf + 46, buf + 30, count - 30); count += 16; } buf = tmpbuf; } fallthrough; case DT_HOSTAP: if ((((unsigned char *) buf)[1] & 3) == 2) { /* Prism2 firmware swaps the dmac and smac in FromDS packets */ memcpy(maddr, buf + 4, 6); memcpy(buf + 4, buf + 16, 6); memcpy(buf + 16, maddr, 6); } break; default: break; } ret = write(dev->fd_out, buf, count); if (ret < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || errno == ENOMEM) { usleep(10000); return (0); } perror("write failed"); return (-1); } /* radiotap header length is stored little endian on all systems */ if (usedrtap) ret -= letoh16(*p_rtlen); return (ret); } #if defined(CONFIG_LIBNL) static int ieee80211_channel_to_frequency(int chan) { if (chan < 14) return 2407 + chan * 5; if (chan == 14) return 2484; /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */ return (chan + 1000) * 5; } static int linux_set_ht_channel_nl80211(struct wif * wi, int channel, unsigned int htval) { struct priv_linux * dev = wi_priv(wi); char s[32]; int pid, status; unsigned int devid; struct nl_msg * msg; unsigned int freq; memset(s, 0, sizeof(s)); switch (dev->drivertype) { case DT_WLANNG: snprintf(s, sizeof(s) - 1, "channel=%d", channel); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execl(dev->wlanctlng, "wlanctl-ng", wi_get_ifname(wi), "lnxreq_wlansniff", s, NULL); exit(1); } waitpid(pid, &status, 0); if (WIFEXITED(status)) { dev->channel = channel; return (WEXITSTATUS(status)); } else return (1); break; case DT_ORINOCO: snprintf(s, sizeof(s) - 1, "%d", channel); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwpriv, "iwpriv", wi_get_ifname(wi), "monitor", "1", s, NULL); exit(1); } waitpid(pid, &status, 0); dev->channel = channel; return 0; break; // yeah ;) case DT_ZD1211RW: snprintf(s, sizeof(s) - 1, "%d", channel); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwconfig, "iwconfig", wi_get_ifname(wi), "channel", s, NULL); exit(1); } waitpid(pid, &status, 0); dev->channel = channel; chan = channel; return 0; break; // yeah ;) default: break; } /* libnl stuff */ chan = channel; devid = if_nametoindex(wi->wi_interface); freq = ieee80211_channel_to_frequency(channel); msg = nlmsg_alloc(); if (!msg) { fprintf(stderr, "failed to allocate netlink message\n"); return 2; } genlmsg_put(msg, 0, 0, genl_family_get_id(state.nl80211), 0, 0, NL80211_CMD_SET_WIPHY, 0); NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, devid); NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); unsigned ht = NL80211_CHAN_NO_HT; switch (htval) { case CHANNEL_HT20: ht = NL80211_CHAN_HT20; break; case CHANNEL_HT40_PLUS: ht = NL80211_CHAN_HT40PLUS; break; case CHANNEL_HT40_MINUS: ht = NL80211_CHAN_HT40MINUS; break; } NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ht); nl_send_auto_complete(state.nl_sock, msg); nlmsg_free(msg); dev->channel = channel; return (0); nla_put_failure: return -ENOBUFS; } static int linux_set_channel_nl80211(struct wif * wi, int channel) { return linux_set_ht_channel_nl80211(wi, channel, CHANNEL_NO_HT); } #else // CONFIG_LIBNL static int linux_set_channel(struct wif * wi, int channel) { struct priv_linux * dev = wi_priv(wi); char s[32]; int pid, status; struct iwreq wrq; memset(s, 0, sizeof(s)); switch (dev->drivertype) { case DT_WLANNG: snprintf(s, sizeof(s) - 1, "channel=%d", channel); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execl(dev->wlanctlng, "wlanctl-ng", wi_get_ifname(wi), "lnxreq_wlansniff", s, NULL); exit(1); } waitpid(pid, &status, 0); if (WIFEXITED(status)) { dev->channel = channel; return (WEXITSTATUS(status)); } else return (1); break; case DT_ORINOCO: snprintf(s, sizeof(s) - 1, "%d", channel); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwpriv, "iwpriv", wi_get_ifname(wi), "monitor", "1", s, NULL); exit(1); } waitpid(pid, &status, 0); dev->channel = channel; return 0; break; // yeah ;) case DT_ZD1211RW: snprintf(s, sizeof(s) - 1, "%d", channel); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwconfig, "iwconfig", wi_get_ifname(wi), "channel", s, NULL); exit(1); } waitpid(pid, &status, 0); dev->channel = channel; return 0; break; // yeah ;) default: break; } memset(&wrq, 0, sizeof(struct iwreq)); strncpy(wrq.ifr_name, wi_get_ifname(wi), IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; wrq.u.freq.m = (double) channel; wrq.u.freq.e = (double) 0; if (ioctl(dev->fd_in, SIOCSIWFREQ, &wrq) < 0) { usleep(10000); /* madwifi needs a second chance */ if (ioctl(dev->fd_in, SIOCSIWFREQ, &wrq) < 0) { /* perror( "ioctl(SIOCSIWFREQ) failed" ); */ return (1); } } dev->channel = channel; return (0); } #endif static int linux_set_freq(struct wif * wi, int freq) { struct priv_linux * dev = wi_priv(wi); char s[32]; int pid, status; struct iwreq wrq; memset(s, 0, sizeof(s)); switch (dev->drivertype) { case DT_WLANNG: case DT_ORINOCO: case DT_ZD1211RW: snprintf(s, sizeof(s) - 1, "%dM", freq); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwconfig, "iwconfig", wi_get_ifname(wi), "freq", s, NULL); exit(1); } waitpid(pid, &status, 0); dev->freq = freq; return 0; break; // yeah ;) default: break; } memset(&wrq, 0, sizeof(struct iwreq)); strncpy(wrq.ifr_name, wi_get_ifname(wi), IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; wrq.u.freq.m = (double) freq * 100000; wrq.u.freq.e = (double) 1; if (ioctl(dev->fd_in, SIOCSIWFREQ, &wrq) < 0) { usleep(10000); /* madwifi needs a second chance */ if (ioctl(dev->fd_in, SIOCSIWFREQ, &wrq) < 0) { /* perror( "ioctl(SIOCSIWFREQ) failed" ); */ return (1); } } dev->freq = freq; return (0); } static int opensysfs(struct priv_linux * dev, char * iface, int fd) { int fd2; char buf[256]; if (iface == NULL || strlen(iface) >= IFNAMSIZ) { return 1; } /* ipw2200 injection */ snprintf(buf, 256, "/sys/class/net/%s/device/inject", iface); fd2 = open(buf, O_WRONLY); /* bcm43xx injection */ if (fd2 == -1) { snprintf(buf, 256, "/sys/class/net/%s/device/inject_nofcs", iface); fd2 = open(buf, O_WRONLY); } if (fd2 == -1) return -1; dup2(fd2, fd); close(fd2); dev->sysfs_inject = 1; return 0; } static int linux_get_monitor(struct wif * wi) { struct priv_linux * dev = wi_priv(wi); struct ifreq ifr; struct iwreq wrq; /* find the interface index */ if (dev->drivertype == DT_IPW2200) return (0); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, wi_get_ifname(wi), sizeof(ifr.ifr_name) - 1); // if( ioctl( fd, SIOCGIFINDEX, &ifr ) < 0 ) // { // printf("Interface %s: \n", iface); // perror( "ioctl(SIOCGIFINDEX) failed" ); // return( 1 ); // } /* lookup the hardware type */ if (ioctl(wi_fd(wi), SIOCGIFHWADDR, &ifr) < 0) { printf("Interface %s: \n", wi_get_ifname(wi)); perror("ioctl(SIOCGIFHWADDR) failed"); return (1); } /* lookup iw mode */ memset(&wrq, 0, sizeof(struct iwreq)); strncpy(wrq.ifr_name, wi_get_ifname(wi), IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; if (ioctl(wi_fd(wi), SIOCGIWMODE, &wrq) < 0) { /* most probably not supported (ie for rtap ipw interface) * * so just assume its correctly set... */ wrq.u.mode = IW_MODE_MONITOR; } if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211 && ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL) || (wrq.u.mode != IW_MODE_MONITOR && (dev->drivertype != DT_ORINOCO))) { return (1); } return (0); } __attribute__((unused)) static char * get_linux_driver(const char * iface) { char path[PATH_MAX]; char link[PATH_MAX]; if (iface == NULL || strlen(iface) >= IFNAMSIZ) { return NULL; } // Read the link path memset(path, 0, sizeof(path)); snprintf(path, sizeof(path), "/sys/class/net/%s/device/driver", iface); // Read the link path ssize_t len = readlink(path, link, sizeof(link)); if (len < 1 || len >= PATH_MAX) { return NULL; } memset(link + len, 0, sizeof(link) - len); // Get driver name const char * drv_idx = strrchr(link, '/'); if (drv_idx == NULL) { return NULL; } // Copy it to a new char * and return ssize_t drv_len = len - (drv_idx - link); if (drv_len <= 1) { return NULL; } char * ret = (char *) calloc(1, drv_len); // includes / if (ret == NULL) { return NULL; } memcpy(ret, drv_idx + 1, drv_len - 1); return ret; } static int set_monitor(struct priv_linux * dev, char * iface, int fd) { int pid, status; struct iwreq wrq; if (iface == NULL || strlen(iface) >= IFNAMSIZ) { return (1); } if (strcmp(iface, "prism0") == 0) { dev->wl = wiToolsPath("wl"); if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); ALLEGE(dev->wl != NULL); execl(dev->wl, "wl", "monitor", "1", NULL); exit(1); } waitpid(pid, &status, 0); if (WIFEXITED(status)) return (WEXITSTATUS(status)); return (1); } else if (strncmp(iface, "rtap", 4) == 0) { return 0; } else { switch (dev->drivertype) { case DT_WLANNG: if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execl(dev->wlanctlng, "wlanctl-ng", iface, "lnxreq_wlansniff", "enable=true", "prismheader=true", "wlanheader=false", "stripfcs=true", "keepwepflags=true", "6", NULL); exit(1); } waitpid(pid, &status, 0); if (WIFEXITED(status)) return (WEXITSTATUS(status)); return (1); break; case DT_ORINOCO: if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwpriv, "iwpriv", iface, "monitor", "1", "1", NULL); exit(1); } waitpid(pid, &status, 0); if (WIFEXITED(status)) return (WEXITSTATUS(status)); return 1; break; case DT_ACX: if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp(dev->iwpriv, "iwpriv", iface, "monitor", "2", "1", NULL); exit(1); } waitpid(pid, &status, 0); if (WIFEXITED(status)) return (WEXITSTATUS(status)); return 1; break; default: break; } memset(&wrq, 0, sizeof(struct iwreq)); strncpy(wrq.ifr_name, iface, IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; wrq.u.mode = IW_MODE_MONITOR; if (ioctl(fd, SIOCSIWMODE, &wrq) < 0) { perror("ioctl(SIOCSIWMODE) failed"); return (1); } if (dev->drivertype == DT_AT76USB) { sleep(3); } } /* couple of iwprivs to enable the prism header */ if (!fork()) /* hostap */ { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp("iwpriv", "iwpriv", iface, "monitor_type", "1", NULL); exit(1); } wait(NULL); if (!fork()) /* r8180 */ { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp("iwpriv", "iwpriv", iface, "prismhdr", "1", NULL); exit(1); } wait(NULL); if (!fork()) /* prism54 */ { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp("iwpriv", "iwpriv", iface, "set_prismhdr", "1", NULL); exit(1); } wait(NULL); return (0); } static int openraw(struct priv_linux * dev, char * iface, int fd, int * arptype, unsigned char * mac) { REQUIRE(iface != NULL); struct ifreq ifr; struct ifreq ifr2; struct iwreq wrq; struct iwreq wrq2; struct packet_mreq mr; struct sockaddr_ll sll; struct sockaddr_ll sll2; if (strlen(iface) >= sizeof(ifr.ifr_name)) { printf("Interface name too long: %s\n", iface); return (1); } /* find the interface index */ memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1); if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) { printf("Interface %s: \n", iface); perror("ioctl(SIOCGIFINDEX) failed"); return (1); } memset(&sll, 0, sizeof(sll)); sll.sll_family = AF_PACKET; sll.sll_ifindex = ifr.ifr_ifindex; switch (dev->drivertype) { case DT_IPW2200: /* find the interface index */ if (dev->main_if == NULL) { perror("Missing interface name"); return 1; } memset(&ifr2, 0, sizeof(ifr)); strncpy(ifr2.ifr_name, dev->main_if, sizeof(ifr2.ifr_name) - 1); if (ioctl(dev->fd_main, SIOCGIFINDEX, &ifr2) < 0) { printf("Interface %s: \n", dev->main_if); perror("ioctl(SIOCGIFINDEX) failed"); return (1); } /* set iw mode to managed on main interface */ memset(&wrq2, 0, sizeof(struct iwreq)); strncpy(wrq2.ifr_name, dev->main_if, IFNAMSIZ); wrq2.ifr_name[IFNAMSIZ - 1] = 0; if (ioctl(dev->fd_main, SIOCGIWMODE, &wrq2) < 0) { perror("SIOCGIWMODE"); return 1; } wrq2.u.mode = IW_MODE_INFRA; if (ioctl(dev->fd_main, SIOCSIWMODE, &wrq2) < 0) { perror("SIOCSIWMODE"); return 1; } /* bind the raw socket to the interface */ memset(&sll2, 0, sizeof(sll2)); sll2.sll_family = AF_PACKET; sll2.sll_ifindex = ifr2.ifr_ifindex; sll2.sll_protocol = htons(ETH_P_ALL); if (bind(dev->fd_main, //-V641 (struct sockaddr *) &sll2, //-V641 sizeof(sll2)) //-V641 < 0) { printf("Interface %s: \n", dev->main_if); perror("bind(ETH_P_ALL) failed"); return (1); } opensysfs(dev, dev->main_if, dev->fd_in); break; case DT_BCM43XX: opensysfs(dev, iface, dev->fd_in); break; case DT_WLANNG: sll.sll_protocol = htons(ETH_P_80211_RAW); break; default: sll.sll_protocol = htons(ETH_P_ALL); break; } /* lookup the hardware type */ if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { printf("Interface %s: \n", iface); perror("ioctl(SIOCGIFHWADDR) failed"); return (1); } /* lookup iw mode */ memset(&wrq, 0, sizeof(struct iwreq)); strncpy(wrq.ifr_name, iface, IFNAMSIZ); wrq.ifr_name[IFNAMSIZ - 1] = 0; if (ioctl(fd, SIOCGIWMODE, &wrq) < 0) { /* most probably not supported (ie for rtap ipw interface) * * so just assume its correctly set... */ wrq.u.mode = IW_MODE_MONITOR; } if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211 && ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL) || (wrq.u.mode != IW_MODE_MONITOR)) { if (set_monitor(dev, iface, fd) && dev->drivertype != DT_ORINOCO) { ifr.ifr_flags &= ~(IFF_UP | IFF_BROADCAST | IFF_RUNNING); if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { perror("ioctl(SIOCSIFFLAGS) failed"); return (1); } if (set_monitor(dev, iface, fd)) { printf("Error setting monitor mode on %s\n", iface); return (1); } } } /* Is interface st to up, broadcast & running ? */ if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags) { /* Bring interface up*/ ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { perror("ioctl(SIOCSIFFLAGS) failed"); return (1); } } /* bind the raw socket to the interface */ if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0) //-V641 { printf("Interface %s: \n", iface); perror("bind(ETH_P_ALL) failed"); return (1); } /* lookup the hardware type */ if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { printf("Interface %s: \n", iface); perror("ioctl(SIOCGIFHWADDR) failed"); return (1); } memcpy(mac, (unsigned char *) ifr.ifr_hwaddr.sa_data, 6); //-V512 *arptype = ifr.ifr_hwaddr.sa_family; if (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211 && ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM && ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL) { if (ifr.ifr_hwaddr.sa_family == ARPHRD_ETHERNET) fprintf(stderr, "\nARP linktype is set to 1 (Ethernet) "); else fprintf(stderr, "\nUnsupported hardware link type %4d ", ifr.ifr_hwaddr.sa_family); fprintf(stderr, "- expected ARPHRD_IEEE80211,\nARPHRD_IEEE80211_" "FULL or ARPHRD_IEEE80211_PRISM instead. Make\n" "sure RFMON is enabled: run 'airmon-ng start %s" " <#>'\nSysfs injection support was not found " "either.\n\n", iface); return (1); } /* enable promiscuous mode */ memset(&mr, 0, sizeof(mr)); mr.mr_ifindex = sll.sll_ifindex; mr.mr_type = PACKET_MR_PROMISC; if (setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) < 0) { perror("setsockopt(PACKET_MR_PROMISC) failed"); return (1); } return (0); } /* * Open the interface and set mode monitor * Return 1 on failure and 0 on success */ static int do_linux_open(struct wif * wi, char * iface) { int kver; struct utsname checklinuxversion; struct priv_linux * dev = wi_priv(wi); char strbuf[512]; FILE * f; char athXraw[] = "athXraw"; pid_t pid; int n; DIR * net_ifaces; struct dirent * this_iface; FILE * acpi = NULL; char buf[128]; char * r_file = NULL; struct ifreq ifr; int iface_malloced = 0; size_t iface_len = 0; if (iface == NULL || strlen(iface) >= IFNAMSIZ) { return (1); } dev->inject_wlanng = 1; dev->rate = 2; /* default to 1Mbps if nothing is set */ /* open raw socks */ if ((dev->fd_in = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { perror("socket(PF_PACKET) failed"); if (getuid() != 0) fprintf(stderr, "This program requires root privileges.\n"); return (1); } if ((dev->fd_main = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { perror("socket(PF_PACKET) failed"); if (getuid() != 0) fprintf(stderr, "This program requires root privileges.\n"); return (1); } #ifndef CONFIG_LIBNL dev->iwpriv = wiToolsPath("iwpriv"); dev->iwconfig = wiToolsPath("iwconfig"); dev->ifconfig = wiToolsPath("ifconfig"); if (!(dev->iwpriv)) { fprintf(stderr, "Required wireless tools when compiled without libnl " "could not be found, exiting.\n"); goto close_in; } #endif /* Exit if ndiswrapper : check iwpriv ndis_reset */ if (is_ndiswrapper(iface, dev->iwpriv)) { fprintf(stderr, "Ndiswrapper doesn't support monitor mode.\n"); goto close_in; } if ((dev->fd_out = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { perror("socket(PF_PACKET) failed"); goto close_in; } /* figure out device type */ /* mac80211 radiotap injection * detected based on interface called mon... * since mac80211 allows multiple virtual interfaces * * note though that the virtual interfaces are ultimately using a * single physical radio: that means for example they must all * operate on the same channel */ /* mac80211 stack detection */ memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "ls /sys/class/net/%s/phy80211/subsystem >/dev/null 2>/dev/null", iface); if (system(strbuf) == 0) dev->drivertype = DT_MAC80211_RT; /* IPW2200 detection */ memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "ls /sys/class/net/%s/device/inject >/dev/null 2>/dev/null", iface); if (system(strbuf) == 0) dev->drivertype = DT_IPW2200; /* BCM43XX detection */ memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "ls /sys/class/net/%s/device/inject_nofcs >/dev/null 2>/dev/null", iface); if (system(strbuf) == 0) dev->drivertype = DT_BCM43XX; /* check if wlan-ng or hostap or r8180 */ if (strlen(iface) == 5 && memcmp(iface, "wlan", 4) == 0) { memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "wlancfg show %s 2>/dev/null | " "grep p2CnfWEPFlags >/dev/null", iface); if (system(strbuf) == 0) { if (uname(&checklinuxversion) >= 0) { /* uname succeeded */ if (strncmp(checklinuxversion.release, "2.6.", 4) == 0 && strncasecmp(checklinuxversion.sysname, "linux", 5) == 0) { /* Linux kernel 2.6 */ kver = atoi(checklinuxversion.release + 4); if (kver > 11) { /* That's a kernel > 2.6.11, cannot inject */ dev->inject_wlanng = 0; } } } dev->drivertype = DT_WLANNG; dev->wlanctlng = wiToolsPath("wlanctl-ng"); } memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "iwpriv %s 2>/dev/null | " "grep antsel_rx >/dev/null", iface); if (system(strbuf) == 0) dev->drivertype = DT_HOSTAP; memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "iwpriv %s 2>/dev/null | " "grep GetAcx111Info >/dev/null", iface); if (system(strbuf) == 0) dev->drivertype = DT_ACX; } /* enable injection on ralink */ if (strcmp(iface, "ra0") == 0 || strcmp(iface, "ra1") == 0 || strcmp(iface, "rausb0") == 0 || strcmp(iface, "rausb1") == 0) { memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "iwpriv %s rfmontx 1 >/dev/null 2>/dev/null", iface); IGNORE_NZ(system(strbuf)); } /* check if newer athXraw interface available */ if ((strlen(iface) >= 4 && strlen(iface) <= 6) //-V804 && memcmp(iface, "ath", 3) == 0) { dev->drivertype = DT_MADWIFI; memset(strbuf, 0, sizeof(strbuf)); snprintf( strbuf, sizeof(strbuf) - 1, "/proc/sys/net/%s/%%parent", iface); f = fopen(strbuf, "r"); if (f != NULL) { // It is madwifi-ng dev->drivertype = DT_MADWIFING; fclose(f); /* should we force prism2 header? */ sprintf((char *) strbuf, "/proc/sys/net/%s/dev_type", iface); f = fopen((char *) strbuf, "w"); if (f != NULL) { fprintf(f, "802\n"); fclose(f); } /* Force prism2 header on madwifi-ng */ } else { // Madwifi-old memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "sysctl -w dev.%s.rawdev=1 >/dev/null 2>/dev/null", iface); if (system(strbuf) == 0) { athXraw[3] = iface[3]; memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "ifconfig %s up", athXraw); IGNORE_NZ(system(strbuf)); #if 0 /* some people reported problems when prismheader is enabled */ memset( strbuf, 0, sizeof( strbuf ) ); snprintf( strbuf, sizeof( strbuf ) - 1, "sysctl -w dev.%s.rawdev_type=1 >/dev/null 2>/dev/null", iface ); IGNORE_NZ(system( strbuf )); #endif iface = athXraw; } } } if (memcmp(iface, "eth", 3) == 0) { /* test if orinoco */ if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp("iwpriv", "iwpriv", iface, "get_port3", NULL); exit(1); } waitpid(pid, &n, 0); if (WIFEXITED(n) && WEXITSTATUS(n) == 0) dev->drivertype = DT_ORINOCO; memset(strbuf, 0, sizeof(strbuf)); snprintf(strbuf, sizeof(strbuf) - 1, "iwpriv %s 2>/dev/null | " "grep get_scan_times >/dev/null", iface); if (system(strbuf) == 0) dev->drivertype = DT_AT76USB; /* test if zd1211rw */ if ((pid = fork()) == 0) { close(0); close(1); close(2); IGNORE_NZ(chdir("/")); execlp("iwpriv", "iwpriv", iface, "get_regdomain", NULL); exit(1); } waitpid(pid, &n, 0); if (WIFEXITED(n) && WEXITSTATUS(n) == 0) dev->drivertype = DT_ZD1211RW; } if (dev->drivertype == DT_IPW2200) { r_file = (char *) calloc(33 + strlen(iface) + 1, sizeof(char)); if (!r_file) { goto close_out; } snprintf(r_file, 33 + strlen(iface) + 1, "/sys/class/net/%s/device/rtap_iface", iface); if ((acpi = fopen(r_file, "r")) == NULL) goto close_out; memset(buf, 0, 128); IGNORE_ZERO(fgets(buf, 128, acpi)); buf[127] = '\x00'; // rtap iface doesn't exist if (strncmp(buf, "-1", 2) == 0) { // repoen for writing fclose(acpi); if ((acpi = fopen(r_file, "w")) == NULL) goto close_out; fputs("1", acpi); // reopen for reading fclose(acpi); if ((acpi = fopen(r_file, "r")) == NULL) goto close_out; IGNORE_ZERO(fgets(buf, 128, acpi)); } fclose(acpi); acpi = NULL; // use name in buf as new iface and set original iface as main iface iface_len = strlen(iface) + 1; dev->main_if = (char *) malloc(iface_len); if (dev->main_if == NULL) goto close_out; memset(dev->main_if, 0, iface_len); memcpy(dev->main_if, iface, iface_len); iface_len = strlen(buf) + 1; iface = (char *) malloc(iface_len); if (iface == NULL) goto close_out; iface_malloced = 1; memset(iface, 0, iface_len); memcpy(iface, buf, iface_len); } /* test if rtap interface and try to find real interface */ if (memcmp(iface, "rtap", 4) == 0 && dev->main_if == NULL) { memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name) - 1); n = 0; if (ioctl(dev->fd_out, SIOCGIFINDEX, &ifr) < 0) { // create rtap interface n = 1; } net_ifaces = opendir("/sys/class/net"); while (net_ifaces != NULL && (this_iface = readdir(net_ifaces)) != NULL) { if (this_iface->d_name[0] == '.') continue; char * new_r_file = (char *) realloc( r_file, (33 + strlen(this_iface->d_name) + 1) * sizeof(char)); if (!new_r_file) { continue; } r_file = new_r_file; snprintf(r_file, 33 + strlen(this_iface->d_name) + 1, "/sys/class/net/%s/device/rtap_iface", this_iface->d_name); if ((acpi = fopen(r_file, "r")) == NULL) continue; dev->drivertype = DT_IPW2200; memset(buf, 0, 128); IGNORE_ZERO(fgets(buf, 128, acpi)); if (n == 0) // interface exists { if (strncmp(buf, iface, 5) == 0) { fclose(acpi); acpi = NULL; closedir(net_ifaces); net_ifaces = NULL; dev->main_if = (char *) malloc(strlen(this_iface->d_name) + 1); if (dev->main_if == NULL) continue; strcpy(dev->main_if, this_iface->d_name); break; } } else // need to create interface { if (strncmp(buf, "-1", 2) == 0) { // repoen for writing fclose(acpi); if ((acpi = fopen(r_file, "w")) == NULL) continue; fputs("1", acpi); // reopen for reading fclose(acpi); if ((acpi = fopen(r_file, "r")) == NULL) continue; IGNORE_ZERO(fgets(buf, 128, acpi)); if (strncmp(buf, iface, 5) == 0) { closedir(net_ifaces); net_ifaces = NULL; dev->main_if = (char *) malloc(strlen(this_iface->d_name) + 1); if (dev->main_if == NULL) continue; strcpy(dev->main_if, this_iface->d_name); fclose(acpi); acpi = NULL; break; } } } fclose(acpi); acpi = NULL; } if (net_ifaces != NULL) closedir(net_ifaces); } if (openraw(dev, iface, dev->fd_out, &dev->arptype_out, dev->pl_mac) != 0) { goto close_out; } /* don't use the same file descriptor for in and out on bcm43xx, as you read from the interface, but write into a file in /sys/... */ if (!(dev->drivertype == DT_BCM43XX) && !(dev->drivertype == DT_IPW2200)) { close(dev->fd_in); dev->fd_in = dev->fd_out; } else { /* if bcm43xx or ipw2200, swap both fds */ n = dev->fd_out; dev->fd_out = dev->fd_in; dev->fd_in = n; } dev->arptype_in = dev->arptype_out; if (iface_malloced) free(iface); if (r_file) { free(r_file); } return 0; close_out: close(dev->fd_out); if (r_file) { free(r_file); } close_in: close(dev->fd_in); if (acpi) fclose(acpi); if (iface_malloced) free(iface); return 1; } static void do_free(struct wif * wi) { struct priv_linux * pl = wi_priv(wi); if (pl->wlanctlng) free(pl->wlanctlng); if (pl->iwpriv) free(pl->iwpriv); if (pl->iwconfig) free(pl->iwconfig); if (pl->ifconfig) free(pl->ifconfig); if (pl->wl) free(pl->wl); if (pl->main_if) free(pl->main_if); free(pl); free(wi); } #ifndef CONFIG_LIBNL static void linux_close(struct wif * wi) { struct priv_linux * pl = wi_priv(wi); if (pl->fd_in && pl->fd_out && pl->fd_in == pl->fd_out) { // Only close one if both are the same close(pl->fd_in); } else { if (pl->fd_in) close(pl->fd_in); if (pl->fd_out) close(pl->fd_out); } if (pl->fd_main) close(pl->fd_main); do_free(wi); } #else static void linux_close_nl80211(struct wif * wi) { struct priv_linux * pl = wi_priv(wi); nl80211_cleanup(&state); if (pl->fd_in) close(pl->fd_in); if (pl->fd_out) close(pl->fd_out); do_free(wi); } #endif static int linux_fd(struct wif * wi) { struct priv_linux * pl = wi_priv(wi); return pl->fd_in; } static int linux_get_mac(struct wif * wi, unsigned char * mac) { struct priv_linux * pl = wi_priv(wi); struct ifreq ifr; int fd; fd = wi_fd(wi); /* find the interface index */ /* ipw2200 got a file opened as fd */ if (pl->drivertype == DT_IPW2200) { memcpy(mac, pl->pl_mac, 6); return 0; } memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, wi_get_ifname(wi), sizeof(ifr.ifr_name) - 1); if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) { printf("Interface %s: \n", wi_get_ifname(wi)); perror("ioctl(SIOCGIFINDEX) failed"); return (1); } if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { printf("Interface %s: \n", wi_get_ifname(wi)); perror("ioctl(SIOCGIFHWADDR) failed"); return (1); } memcpy(pl->pl_mac, (unsigned char *) ifr.ifr_hwaddr.sa_data, 6); /* XXX */ memcpy(mac, pl->pl_mac, 6); return 0; } static int linux_set_mac(struct wif * wi, unsigned char * mac) { struct priv_linux * pl = wi_priv(wi); struct ifreq ifr; int fd, ret; fd = wi_fd(wi); /* find the interface index */ memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, wi_get_ifname(wi), sizeof(ifr.ifr_name) - 1); if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { printf("Interface %s: \n", wi_get_ifname(wi)); perror("ioctl(SIOCGIFHWADDR) failed"); return (1); } // if down ifr.ifr_flags &= ~(IFF_UP | IFF_BROADCAST | IFF_RUNNING); if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { perror("ioctl(SIOCSIFFLAGS) failed"); return (1); } ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; memcpy(ifr.ifr_hwaddr.sa_data, mac, 6); //-V512 memcpy(pl->pl_mac, mac, 6); // set mac ret = ioctl(fd, SIOCSIFHWADDR, &ifr); // if up ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { perror("ioctl(SIOCSIFFLAGS) failed"); return (1); } return ret; } static struct wif * linux_open(char * iface) { struct wif * wi; struct priv_linux * pl; if (iface == NULL || strlen(iface) >= IFNAMSIZ) { return NULL; } wi = wi_alloc(sizeof(*pl)); if (!wi) return NULL; wi->wi_read = linux_read; wi->wi_write = linux_write; #ifdef CONFIG_LIBNL linux_nl80211_init(&state); wi->wi_set_ht_channel = linux_set_ht_channel_nl80211; wi->wi_set_channel = linux_set_channel_nl80211; #else wi->wi_set_channel = linux_set_channel; #endif // CONFIG_LIBNL wi->wi_get_channel = linux_get_channel; wi->wi_set_freq = linux_set_freq; wi->wi_get_freq = linux_get_freq; #ifdef CONFIG_LIBNL wi->wi_close = linux_close_nl80211; #else wi->wi_close = linux_close; #endif wi->wi_fd = linux_fd; wi->wi_get_mac = linux_get_mac; wi->wi_set_mac = linux_set_mac; wi->wi_get_monitor = linux_get_monitor; wi->wi_get_rate = linux_get_rate; wi->wi_set_rate = linux_set_rate; wi->wi_get_mtu = linux_get_mtu; wi->wi_set_mtu = linux_set_mtu; if (do_linux_open(wi, iface)) { do_free(wi); return NULL; } return wi; } struct wif * wi_open_osdep(char * iface) { return linux_open(iface); } EXPORT int get_battery_state(void) { char buf[128]; int batteryTime = 0; FILE * apm; unsigned flag; char units[32]; int ret; static int linux_apm = 1; static int linux_acpi = 1; if (linux_apm == 1) { char * battery_data = NULL; if ((apm = fopen("/proc/apm", "r")) != NULL) { battery_data = fgets(buf, 128, apm); fclose(apm); } if (battery_data != NULL) { unsigned charging, ac; ret = sscanf(battery_data, "%*s %*d.%*d %*x %x %x %x %*d%% %d %31s\n", &ac, &charging, &flag, &batteryTime, units); if (!ret) return 0; if ((flag & 0x80) == 0 && charging != 0xFF && ac != 1 && batteryTime == -1) { if (!strncmp(units, "min", 3)) batteryTime *= 60; } else return 0; linux_acpi = 0; return batteryTime; } linux_apm = 0; } if (linux_acpi && !linux_apm) { DIR *batteries, *ac_adapters; struct dirent *this_battery, *this_adapter; FILE *acpi, *info; char battery_state[28 + sizeof(this_adapter->d_name) + 1]; char battery_info[24 + sizeof(this_battery->d_name) + 1]; int rate = 1, remain = 0; int batno = 0; static int info_timer = 0; int batt_full_capacity[3]; linux_acpi = 1; ac_adapters = opendir("/proc/acpi/ac_adapter"); if (ac_adapters == NULL) return 0; while ((this_adapter = readdir(ac_adapters)) != NULL) { if (this_adapter->d_name[0] == '.') { continue; } /* safe overloaded use of battery_state path var */ snprintf(battery_state, sizeof(battery_state), "/proc/acpi/ac_adapter/%s/state", this_adapter->d_name); if ((acpi = fopen(battery_state, "r")) == NULL) { continue; } while (fgets(buf, 128, acpi)) { if (strstr(buf, "on-line") != NULL) { fclose(acpi); closedir(ac_adapters); return 0; } } fclose(acpi); } closedir(ac_adapters); batteries = opendir("/proc/acpi/battery"); if (batteries == NULL) { return 0; } while ((this_battery = readdir(batteries)) != NULL) { if (this_battery->d_name[0] == '.') continue; snprintf(battery_info, sizeof(battery_info), "/proc/acpi/battery/%s/info", this_battery->d_name); info = fopen(battery_info, "r"); batt_full_capacity[batno] = 0; if (info != NULL) { while (fgets(buf, sizeof(buf), info) != NULL) if (sscanf(buf, "last full capacity: %d mWh", &batt_full_capacity[batno]) == 1) continue; fclose(info); } snprintf(battery_state, sizeof(battery_state), "/proc/acpi/battery/%s/state", this_battery->d_name); if ((acpi = fopen(battery_state, "r")) == NULL) continue; while (fgets(buf, 128, acpi)) { if (strncmp(buf, "present:", 8) == 0) { /* No information for this battery */ if (strstr(buf, "no")) continue; } else if (strncmp(buf, "charging state:", 15) == 0) { /* the space makes it different than discharging */ if (strstr(buf, " charging")) { closedir(batteries); fclose(acpi); return 0; } } else if (strncmp(buf, "present rate:", 13) == 0) rate = atoi(buf + 25); else if (strncmp(buf, "remaining capacity:", 19) == 0) { remain = atoi(buf + 25); } } fclose(acpi); if (rate != 0) batteryTime += (int) ((((float) remain) / rate) * 3600); batno++; } info_timer++; closedir(batteries); } return batteryTime; }
C
aircrack-ng/lib/osdep/linux_tap.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for Linux. TAP routines * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/time.h> #include <linux/if.h> #include <linux/if_ether.h> #include <netinet/in.h> #include <linux/if_tun.h> #include <net/if_arp.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include "osdep.h" struct tip_linux { int tl_fd; struct ifreq tl_ifr; int tl_ioctls; char tl_name[IFNAMSIZ]; }; static int ti_do_open_linux(struct tif * ti, char * name) { int fd_tap; struct ifreq if_request; struct tip_linux * priv = ti_priv(ti); fd_tap = open(name ? name : "/dev/net/tun", O_RDWR); if (fd_tap < 0) { printf("error opening tap device: %s\n", strerror(errno)); printf("try \"modprobe tun\"\n"); return -1; } memset(&if_request, 0, sizeof(if_request)); if_request.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(if_request.ifr_name, "at%d", IFNAMSIZ); if (ioctl(fd_tap, TUNSETIFF, (void *) &if_request) < 0) { printf("error creating tap interface: %s\n", strerror(errno)); close(fd_tap); return -1; } memcpy(priv->tl_name, if_request.ifr_name, IFNAMSIZ); memcpy(priv->tl_ifr.ifr_name, priv->tl_name, IFNAMSIZ); if ((priv->tl_ioctls = socket(PF_INET, SOCK_DGRAM, 0)) == -1) { priv->tl_ioctls = 0; close(fd_tap); return -1; } return fd_tap; } static void ti_do_free(struct tif * ti) { struct tip_fbsd * priv = ti_priv(ti); free(priv); free(ti); } static void ti_close_linux(struct tif * ti) { struct tip_linux * priv = ti_priv(ti); close(priv->tl_fd); close(priv->tl_ioctls); ti_do_free(ti); } static char * ti_name_linux(struct tif * ti) { struct tip_linux * priv = ti_priv(ti); return priv->tl_name; } static int ti_set_mtu_linux(struct tif * ti, int mtu) { struct tip_linux * priv = ti_priv(ti); priv->tl_ifr.ifr_mtu = mtu; return ioctl(priv->tl_ioctls, SIOCSIFMTU, &priv->tl_ifr); } static int ti_get_mtu_linux(struct tif * ti) { int mtu; struct tip_linux * priv = ti_priv(ti); if (ioctl(priv->tl_ioctls, SIOCSIFMTU, &priv->tl_ifr) != -1) { mtu = priv->tl_ifr.ifr_mtu; } else { mtu = 1500; } return mtu; } static int ti_set_mac_linux(struct tif * ti, unsigned char * mac) { struct tip_linux * priv = ti_priv(ti); memcpy(priv->tl_ifr.ifr_hwaddr.sa_data, mac, 6); //-V512 priv->tl_ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; return ioctl(priv->tl_ioctls, SIOCSIFHWADDR, &priv->tl_ifr); } static int ti_set_ip_linux(struct tif * ti, struct in_addr * ip) { struct tip_linux * priv = ti_priv(ti); struct sockaddr_in * s_in; s_in = (struct sockaddr_in *) &priv->tl_ifr.ifr_addr; s_in->sin_family = AF_INET; s_in->sin_addr = *ip; return ioctl(priv->tl_ioctls, SIOCSIFADDR, &priv->tl_ifr); } static int ti_fd_linux(struct tif * ti) { struct tip_linux * priv = ti_priv(ti); return priv->tl_fd; } static int ti_read_linux(struct tif * ti, void * buf, int len) { return read(ti_fd(ti), buf, len); } static int ti_write_linux(struct tif * ti, void * buf, int len) { return write(ti_fd(ti), buf, len); } static struct tif * ti_open_linux(char * iface) { struct tif * ti; struct tip_linux * priv; int fd; /* setup ti struct */ ti = ti_alloc(sizeof(*priv)); if (!ti) return NULL; ti->ti_name = ti_name_linux; ti->ti_set_mtu = ti_set_mtu_linux; ti->ti_get_mtu = ti_get_mtu_linux; ti->ti_close = ti_close_linux; ti->ti_fd = ti_fd_linux; ti->ti_read = ti_read_linux; ti->ti_write = ti_write_linux; ti->ti_set_mac = ti_set_mac_linux; ti->ti_set_ip = ti_set_ip_linux; /* setup iface */ fd = ti_do_open_linux(ti, iface); if (fd == -1) { ti_do_free(ti); return NULL; } /* setup private state */ priv = ti_priv(ti); priv->tl_fd = fd; return ti; } EXPORT struct tif * ti_open(char * iface) { return ti_open_linux(iface); }
Include
aircrack-ng/lib/osdep/Makefile.inc
# Aircrack-ng # # Copyright (C) 2018 Joseph Benden <[email protected]> # # Autotool support was written by: Joseph Benden <[email protected]> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the # OpenSSL library under certain conditions as described in each # individual source file, and distribute linked combinations # including the two. # # You must obey the GNU General Public License in all respects # for all of the code used other than OpenSSL. # # If you modify file(s) with this exception, you may extend this # exception to your dnl version of the file(s), but you are not obligated # to do so. # # If you dnl do not wish to do so, delete this exception statement from your # version. # # If you delete this exception statement from all source files in the # program, then also delete it here. SRCS_COMMON = %D%/network.c %D%/file.c SRCS = %D%/osdep.c $(SRCS_COMMON) SRCS_APCAP = %D%/airpcap.c SRCS_OBSD = $(SRCS) %D%/openbsd.c %D%/openbsd_tap.c %D%/common.c SRCS_NBSD = $(SRCS) %D%/netbsd.c %D%/netbsd_tap.c %D%/common.c SRCS_FBSD = $(SRCS) %D%/freebsd.c %D%/freebsd_tap.c %D%/common.c SRCS_LINUX = $(SRCS) %D%/linux.c %D%/linux_tap.c %D%/common.c SRCS_DUMMY = $(SRCS) %D%/dummy.c %D%/dummy_tap.c %D%/common.c SRCS_CYGWIN = $(SRCS) %D%/cygwin.c %D%/cygwin_tap.c %D%/common.c SRCS_DARWIN = $(SRCS) %D%/darwin.c %D%/darwin_tap.c %D%/common.c if AIRPCAP SRCS_CYGWIN += $(SRCS_APCAP) endif if CYGWIN if AIRPCAP libaircrack_osdep_la_SOURCES = $(SRCS_CYGWIN) libaircrack_osdep_la_CFLAGS = $(AIRPCAP_CFLAGS) libaircrack_osdep_la_LIBADD = $(AIRPCAP_LIBS) $(LIBRADIOTAP_LIBS) -lsetupapi -liphlpapi else libaircrack_osdep_la_SOURCES = $(SRCS_CYGWIN) endif endif if DARWIN libaircrack_osdep_la_SOURCES = $(SRCS_DARWIN) endif if DUMMY libaircrack_osdep_la_SOURCES = $(SRCS_DUMMY) endif if FREEBSD libaircrack_osdep_la_SOURCES = $(SRCS_FBSD) endif if LINUX libaircrack_osdep_la_SOURCES = $(SRCS_LINUX) libaircrack_osdep_la_CFLAGS = $(LIBNL_CFLAGS) libaircrack_osdep_la_LIBADD = $(LIBNL_LIBS) $(LIBRADIOTAP_LIBS) endif if NETBSD libaircrack_osdep_la_SOURCES = $(SRCS_NBSD) endif if OPENBSD libaircrack_osdep_la_SOURCES = $(SRCS_OBSD) endif if !AIRPCAP libaircrack_osdep_la_LIBADD = $(LIBRADIOTAP_LIBS) if CYGWIN libaircrack_osdep_la_LIBADD += -lsetupapi -liphlpapi endif endif lib_LTLIBRARIES += libaircrack-osdep.la libaircrack_osdep_la_LDFLAGS = -release $(LT_VER) -no-undefined libaircrack_osdep_la_CPPFLAGS = -I$(top_srcdir)/include/aircrack-ng/osdep $(AM_CPPFLAGS) EXTRA_DIST += %D%/openbsd.c \ %D%/darwin.c \ %D%/common.c \ %D%/darwin_tap.c \ %D%/cygwin.c \ %D%/linux.c \ %D%/file.c \ %D%/linux_tap.c \ %D%/airpcap.c \ %D%/netbsd.c \ %D%/freebsd_tap.c \ %D%/freebsd.c \ %D%/osdep.c \ %D%/dummy_tap.c \ %D%/openbsd_tap.c \ %D%/dummy.c \ %D%/netbsd_tap.c \ %D%/network.c \ %D%/cygwin_tap.c
C
aircrack-ng/lib/osdep/netbsd.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for NetBSD. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/endian.h> #include <errno.h> #include <fcntl.h> #include <sys/param.h> #include <sys/sysctl.h> #include <net/bpf.h> #include <sys/socket.h> #include <net/if.h> #include <net/if_media.h> #include <sys/ioctl.h> #include <net/if_dl.h> #include <net80211/ieee80211.h> #include <net80211/ieee80211_crypto.h> #include <net80211/ieee80211_ioctl.h> #include <net80211/ieee80211_radiotap.h> #include <net80211/ieee80211_proto.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/uio.h> #include <assert.h> #include <ifaddrs.h> #include "osdep.h" #ifndef LINKTYPE_IEEE802_11 #define LINKTYPE_IEEE802_11 105 #endif #ifndef IEEE80211_RADIOTAP_F_FCS #define IEEE80211_RADIOTAP_F_FCS 0x10 /* Frame includes FCS */ #endif #ifndef IEEE80211_IOC_CHANNEL #define IEEE80211_IOC_CHANNEL 0 #endif #ifndef le32toh #define le32toh(x) htole32(x) #endif struct priv_nbsd { /* iface */ int pn_fd; /* rx */ int pn_nocrc; /* tx */ unsigned char pn_buf[4096]; unsigned char * pn_next; int pn_totlen; /* setchan */ int pn_s; struct ifreq pn_ifr; struct ieee80211chanreq pn_ireq; int pn_chan; }; static void get_radiotap_info(struct priv_nbsd * pn, struct ieee80211_radiotap_header * rth, int * plen, struct rx_info * ri) { uint32_t present; uint8_t rflags = 0; int i; unsigned char * body = (unsigned char *) (rth + 1); int dbm_power = 0, db_power = 0; /* reset control info */ if (ri) memset(ri, 0, sizeof(*ri)); /* get info */ present = le32toh(rth->it_present); for (i = IEEE80211_RADIOTAP_TSFT; i <= IEEE80211_RADIOTAP_EXT; i++) { if (!(present & (1 << i))) continue; switch (i) { case IEEE80211_RADIOTAP_TSFT: body += sizeof(uint64_t); break; case IEEE80211_RADIOTAP_FLAGS: rflags = *((uint8_t *) body); /* fall through */ case IEEE80211_RADIOTAP_RATE: body += sizeof(uint8_t); break; case IEEE80211_RADIOTAP_CHANNEL: if (ri) { ri->ri_channel = 1; } body += sizeof(uint16_t) * 2; break; case IEEE80211_RADIOTAP_FHSS: body += sizeof(uint16_t); break; case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: dbm_power = *body++; break; case IEEE80211_RADIOTAP_DBM_ANTNOISE: dbm_power -= *body++; break; case IEEE80211_RADIOTAP_DB_ANTSIGNAL: db_power = *body++; break; case IEEE80211_RADIOTAP_DB_ANTNOISE: db_power -= *body++; break; default: i = IEEE80211_RADIOTAP_EXT + 1; break; } } /* set power */ if (ri) { if (dbm_power) ri->ri_power = dbm_power; else ri->ri_power = db_power; } /* XXX cache; drivers won't change this per-packet */ /* check if FCS/CRC is included in packet */ if (pn->pn_nocrc || (rflags & IEEE80211_RADIOTAP_F_FCS)) { *plen -= IEEE80211_CRC_LEN; pn->pn_nocrc = 1; } } static unsigned char * get_80211(struct priv_nbsd * pn, int * plen, struct rx_info * ri) { struct bpf_hdr * bpfh; struct ieee80211_radiotap_header * rth; void * ptr; unsigned char ** data; int * totlen; data = &pn->pn_next; totlen = &pn->pn_totlen; assert(*totlen); /* bpf hdr */ bpfh = (struct bpf_hdr *) (*data); assert(bpfh->bh_caplen == bpfh->bh_datalen); /* XXX */ *totlen -= bpfh->bh_hdrlen; /* check if more packets */ if ((int) bpfh->bh_caplen < *totlen) { int tot = bpfh->bh_hdrlen + bpfh->bh_caplen; int offset = BPF_WORDALIGN(tot); *data = (unsigned char *) bpfh + offset; *totlen -= offset - tot; /* take into account align bytes */ } else if ((int) bpfh->bh_caplen > *totlen) abort(); *plen = bpfh->bh_caplen; *totlen -= bpfh->bh_caplen; assert(*totlen >= 0); /* radiotap */ rth = (struct ieee80211_radiotap_header *) ((char *) bpfh + bpfh->bh_hdrlen); get_radiotap_info(pn, rth, plen, ri); *plen -= rth->it_len; assert(*plen > 0); /* data */ ptr = (char *) rth + rth->it_len; return ptr; } static int nbsd_get_channel(struct wif * wi) { struct priv_nbsd * pn = wi_priv(wi); struct ieee80211chanreq channel; memset(&channel, 0, sizeof(channel)); strlcpy(channel.i_name, wi_get_ifname(wi), sizeof(channel.i_name)); if (ioctl(pn->pn_s, SIOCG80211CHANNEL, (caddr_t) &channel) < 0) return -1; return channel.i_channel; } static int nbsd_set_channel(struct wif * wi, int chan) { struct priv_nbsd * pn = wi_priv(wi); struct ieee80211chanreq channel; memset(&channel, 0, sizeof(channel)); strlcpy(channel.i_name, wi_get_ifname(wi), sizeof(channel.i_name)); channel.i_channel = chan; if (ioctl(pn->pn_s, SIOCS80211CHANNEL, (caddr_t) &channel) < 0) return -1; pn->pn_chan = chan; return 0; } static int nbsd_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * h80211, int len, struct rx_info * ri) { struct priv_nbsd * pn = wi_priv(wi); unsigned char * wh; int plen; assert(len > 0); /* need to read more */ if (pn->pn_totlen == 0) { pn->pn_totlen = read(pn->pn_fd, pn->pn_buf, sizeof(pn->pn_buf)); if (pn->pn_totlen == -1) { pn->pn_totlen = 0; return -1; } pn->pn_next = pn->pn_buf; } /* read 802.11 packet */ wh = get_80211(pn, &plen, ri); if (plen > len) plen = len; assert(plen > 0); memcpy(h80211, wh, plen); if (dlt) { *dlt = LINKTYPE_IEEE802_11; } if (ts) { clock_gettime(CLOCK_REALTIME, ts); } if (ri && !ri->ri_channel) ri->ri_channel = wi_get_channel(wi); return plen; } static int nbsd_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * h80211, int len, struct tx_info * ti) { struct priv_nbsd * pn = wi_priv(wi); int rc; (void) ts; (void) dlt; /* XXX make use of ti */ if (ti) { } rc = write(pn->pn_fd, h80211, len); if (rc == -1) return rc; return 0; } static void do_free(struct wif * wi) { assert(wi->wi_priv); free(wi->wi_priv); wi->wi_priv = 0; free(wi); } static void nbsd_close(struct wif * wi) { struct priv_nbsd * pn = wi_priv(wi); close(pn->pn_fd); close(pn->pn_s); do_free(wi); } static int do_nbsd_open(struct wif * wi, char * iface) { int i; char buf[64]; int fd = -1; struct ifreq ifr; unsigned int dlt = DLT_IEEE802_11_RADIO; int s; unsigned int flags; struct ifmediareq ifmr; int * mwords; struct priv_nbsd * pn = wi_priv(wi); unsigned int size = sizeof(pn->pn_buf); /* basic sanity check */ if (strlen(iface) >= sizeof(ifr.ifr_name)) return -1; /* open wifi */ s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) return -1; pn->pn_s = s; /* set iface up and promisc */ memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, IFNAMSIZ); if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) goto close_sock; flags = ifr.ifr_flags; flags |= IFF_UP | IFF_PROMISC; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, IFNAMSIZ); ifr.ifr_flags = flags & 0xffff; if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) goto close_sock; /* monitor mode */ memset(&ifmr, 0, sizeof(ifmr)); strncpy(ifmr.ifm_name, iface, IFNAMSIZ); if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) goto close_sock; assert(ifmr.ifm_count != 0); mwords = (int *) malloc(ifmr.ifm_count * sizeof(int)); if (!mwords) goto close_sock; ifmr.ifm_ulist = mwords; if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) { free(mwords); goto close_sock; } free(mwords); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, IFNAMSIZ); ifr.ifr_media = ifmr.ifm_current | IFM_IEEE80211_MONITOR; if (ioctl(s, SIOCSIFMEDIA, &ifr) == -1) goto close_sock; /* setup ifreq for chan that may be used in future */ strncpy(pn->pn_ireq.i_name, iface, IFNAMSIZ); /* same for ifreq [mac addr] */ strncpy(pn->pn_ifr.ifr_name, iface, IFNAMSIZ); /* open bpf */ for (i = 0; i < 256; i++) { snprintf(buf, sizeof(buf), "/dev/bpf%d", i); fd = open(buf, O_RDWR); if (fd < 0) { if (errno != EBUSY) return -1; continue; } else break; } if (fd < 0) goto close_sock; if (ioctl(fd, BIOCSBLEN, &size) < 0) goto close_bpf; strncpy(ifr.ifr_name, iface, IFNAMSIZ); if (ioctl(fd, BIOCSETIF, &ifr) < 0) goto close_bpf; if (ioctl(fd, BIOCSDLT, &dlt) < 0) goto close_bpf; if (ioctl(fd, BIOCPROMISC, NULL) < 0) goto close_bpf; dlt = 1; if (ioctl(fd, BIOCIMMEDIATE, &dlt) == -1) goto close_bpf; return fd; close_sock: close(s); return -1; close_bpf: close(fd); goto close_sock; } static int nbsd_fd(struct wif * wi) { struct priv_nbsd * pn = wi_priv(wi); return pn->pn_fd; } static int nbsd_get_mac(struct wif * wi, unsigned char * mac) { struct ifaddrs *ifa, *p; char * name = wi_get_ifname(wi); int rc = -1; struct sockaddr_dl * sdp; if (getifaddrs(&ifa) == -1) return -1; p = ifa; while (p) { if (p->ifa_addr->sa_family == AF_LINK && strcmp(name, p->ifa_name) == 0) { sdp = (struct sockaddr_dl *) p->ifa_addr; memcpy(mac, sdp->sdl_data + sdp->sdl_nlen, 6); rc = 0; break; } p = p->ifa_next; } freeifaddrs(ifa); return rc; } static int nbsd_get_monitor(struct wif * wi) { if (wi) { } /* XXX unused */ /* XXX */ return 0; } static int nbsd_get_rate(struct wif * wi) { if (wi) { } /* XXX unused */ /* XXX */ return 1000000; } static int nbsd_set_rate(struct wif * wi, int rate) { if (wi || rate) { } /* XXX unused */ /* XXX */ return 0; } static int nbsd_set_mac(struct wif * wi, unsigned char * mac) { struct priv_nbsd * pn = wi_priv(wi); struct ifreq * ifr = &pn->pn_ifr; ifr->ifr_addr.sa_family = AF_LINK; ifr->ifr_addr.sa_len = 6; memcpy(ifr->ifr_addr.sa_data, mac, 6); return ioctl(pn->pn_s, SIOCSIFADDR, ifr); } static struct wif * nbsd_open(char * iface) { struct wif * wi; struct priv_nbsd * pn; int fd; /* setup wi struct */ wi = wi_alloc(sizeof(*pn)); if (!wi) return NULL; wi->wi_read = nbsd_read; wi->wi_write = nbsd_write; wi->wi_set_channel = nbsd_set_channel; wi->wi_get_channel = nbsd_get_channel; wi->wi_close = nbsd_close; wi->wi_fd = nbsd_fd; wi->wi_get_mac = nbsd_get_mac; wi->wi_set_mac = nbsd_set_mac; wi->wi_get_rate = nbsd_get_rate; wi->wi_set_rate = nbsd_set_rate; wi->wi_get_monitor = nbsd_get_monitor; /* setup iface */ fd = do_nbsd_open(wi, iface); if (fd == -1) { do_free(wi); return NULL; } /* setup private state */ pn = wi_priv(wi); pn->pn_fd = fd; return wi; } struct wif * wi_open_osdep(char * iface) { return nbsd_open(iface); } EXPORT int get_battery_state(void) { #if defined(__FreeBSD__) int value; size_t len; len = 1; value = 0; sysctlbyname("hw.acpi.acline", &value, &len, NULL, 0); if (value == 0) { sysctlbyname("hw.acpi.battery.time", &value, &len, NULL, 0); value = value * 60; } else { value = 0; } return (value); #elif defined(_BSD_SOURCE) struct apm_power_info api; int apmfd; if ((apmfd = open("/dev/apm", O_RDONLY)) < 0) return 0; if (ioctl(apmfd, APM_IOC_GETPOWER, &api) < 0) { close(apmfd); return 0; } close(apmfd); if (api.battery_state == APM_BATT_UNKNOWN || api.battery_state == APM_BATTERY_ABSENT || api.battery_state == APM_BATT_CHARGING || api.ac_state == APM_AC_ON) { return 0; } return ((int) (api.minutes_left)) * 60; #else return 0; #endif }
C
aircrack-ng/lib/osdep/netbsd_tap.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for NetBSD. TAP routines * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/socket.h> #include <net/if.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include "osdep.h" struct tip_nbsd { int tn_fd; int tn_ioctls; struct ifreq tn_ifr; char tn_name[IFNAMSIZ]; int tn_destroy; }; static int ti_do_open_nbsd(struct tif * ti, char * name) { int fd; char * iface = "/dev/tap"; struct stat st; struct tip_nbsd * priv = ti_priv(ti); int s; unsigned int flags; struct ifreq * ifr; /* open tap */ if (name) iface = name; else priv->tn_destroy = 1; /* we create, we destroy */ fd = open(iface, O_RDWR); if (fd == -1) return -1; /* get name */ if (fstat(fd, &st) == -1) goto err; snprintf(priv->tn_name, sizeof(priv->tn_name) - 1, "%s", devname(st.st_rdev, S_IFCHR)); /* bring iface up */ s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) goto err; priv->tn_ioctls = s; /* get flags */ ifr = &priv->tn_ifr; memset(ifr, 0, sizeof(*ifr)); snprintf(ifr->ifr_name, sizeof(ifr->ifr_name), "%s", priv->tn_name); if (ioctl(s, SIOCGIFFLAGS, ifr) == -1) goto err2; flags = ifr->ifr_flags; /* set flags */ flags |= IFF_UP; ifr->ifr_flags = flags & 0xffff; if (ioctl(s, SIOCSIFFLAGS, ifr) == -1) goto err2; return fd; err: /* XXX destroy */ close(fd); return -1; err2: close(s); goto err; } static void ti_do_free(struct tif * ti) { struct tip_nbsd * priv = ti_priv(ti); free(priv); free(ti); } static void ti_destroy(struct tip_nbsd * priv) { ioctl(priv->tn_ioctls, SIOCIFDESTROY, &priv->tn_ifr); } static void ti_close_nbsd(struct tif * ti) { struct tip_nbsd * priv = ti_priv(ti); if (priv->tn_destroy) ti_destroy(priv); close(priv->tn_fd); close(priv->tn_ioctls); ti_do_free(ti); } static char * ti_name_nbsd(struct tif * ti) { struct tip_nbsd * priv = ti_priv(ti); return priv->tn_name; } static int ti_set_mtu_nbsd(struct tif * ti, int mtu) { struct tip_nbsd * priv = ti_priv(ti); priv->tn_ifr.ifr_mtu = mtu; return ioctl(priv->tn_ioctls, SIOCSIFMTU, &priv->tn_ifr); } static int ti_set_mac_nbsd(struct tif * ti, unsigned char * mac) { struct tip_nbsd * priv = ti_priv(ti); struct ifreq * ifr = &priv->tn_ifr; ifr->ifr_addr.sa_family = AF_LINK; ifr->ifr_addr.sa_len = 6; memcpy(ifr->ifr_addr.sa_data, mac, 6); return ioctl(priv->tn_ioctls, SIOCSIFADDR, ifr); } static int ti_set_ip_nbsd(struct tif * ti, struct in_addr * ip) { struct tip_nbsd * priv = ti_priv(ti); struct ifaliasreq ifra; struct sockaddr_in * s_in; /* assume same size */ memset(&ifra, 0, sizeof(ifra)); strncpy(ifra.ifra_name, priv->tn_ifr.ifr_name, IFNAMSIZ); s_in = (struct sockaddr_in *) &ifra.ifra_addr; s_in->sin_family = PF_INET; s_in->sin_addr = *ip; s_in->sin_len = sizeof(*s_in); return ioctl(priv->tn_ioctls, SIOCAIFADDR, &ifra); } static int ti_fd_nbsd(struct tif * ti) { struct tip_nbsd * priv = ti_priv(ti); return priv->tn_fd; } static int ti_read_nbsd(struct tif * ti, void * buf, int len) { return read(ti_fd(ti), buf, len); } static int ti_write_nbsd(struct tif * ti, void * buf, int len) { return write(ti_fd(ti), buf, len); } static struct tif * ti_open_nbsd(char * iface) { struct tif * ti; struct tip_nbsd * priv; int fd; /* setup ti struct */ ti = ti_alloc(sizeof(*priv)); if (!ti) return NULL; ti->ti_name = ti_name_nbsd; ti->ti_set_mtu = ti_set_mtu_nbsd; ti->ti_close = ti_close_nbsd; ti->ti_fd = ti_fd_nbsd; ti->ti_read = ti_read_nbsd; ti->ti_write = ti_write_nbsd; ti->ti_set_mac = ti_set_mac_nbsd; ti->ti_set_ip = ti_set_ip_nbsd; /* setup iface */ fd = ti_do_open_nbsd(ti, iface); if (fd == -1) { ti_do_free(ti); return NULL; } /* setup private state */ priv = ti_priv(ti); priv->tn_fd = fd; return ti; } EXPORT struct tif * ti_open(char * iface) { return ti_open_nbsd(iface); }
C
aircrack-ng/lib/osdep/network.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for using card via network. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <assert.h> #include <sys/select.h> #include <errno.h> #include "aircrack-ng/support/communications.h" #include "osdep.h" #include "network.h" #define QUEUE_MAX 666 struct netqueue { unsigned char q_buf[2048]; int q_len; struct netqueue * q_next; struct netqueue * q_prev; }; struct priv_net { int pn_s; struct netqueue pn_queue; struct netqueue pn_queue_free; int pn_queue_len; }; EXPORT int net_send(int s, int command, void * arg, int len) { struct net_hdr * pnh; char * pktbuf; size_t pktlen; // Validate command value assert(command >= NET_RC && command <= HIGHEST_NET_COMMAND); if (command < NET_RC || command > HIGHEST_NET_COMMAND) { return -1; } if (arg == NULL) return -1; pktlen = sizeof(struct net_hdr) + len; pktbuf = (char *) calloc(sizeof(char), pktlen); if (pktbuf == NULL) { perror("calloc"); goto net_send_error; } pnh = (struct net_hdr *) pktbuf; pnh->nh_type = command; pnh->nh_len = htonl(len); memcpy(pktbuf + sizeof(struct net_hdr), arg, len); for (;;) { ssize_t rc = send(s, pktbuf, pktlen, 0); if ((size_t) rc == pktlen) break; if (rc == EAGAIN || rc == EWOULDBLOCK || rc == EINTR) continue; if (rc == ECONNRESET) printf("Connection reset while sending packet!\n"); goto net_send_error; } free(pktbuf); return 0; net_send_error: free(pktbuf); return -1; } EXPORT int net_read_exact(int s, void * arg, int len) { ssize_t rc; int rlen = 0; char * buf = (char *) arg; while (rlen < len) { rc = recv(s, buf, (len - rlen), 0); if (rc < 1) { if (rc == -1 && (errno == EAGAIN || errno == EINTR)) { usleep(100); continue; } return -1; } buf += rc; rlen += rc; } return 0; } EXPORT int net_get(int s, void * arg, int * len) { struct net_hdr nh; int plen; if (net_read_exact(s, &nh, sizeof(nh)) == -1) { return -1; } plen = ntohl(nh.nh_len); assert(plen <= *len && plen >= 0); *len = plen; if ((*len) && (net_read_exact(s, arg, *len) == -1)) { return -1; } return nh.nh_type; } static void queue_del(struct netqueue * q) { q->q_prev->q_next = q->q_next; q->q_next->q_prev = q->q_prev; } static void queue_add(struct netqueue * head, struct netqueue * q) { struct netqueue * pos = head->q_prev; q->q_prev = pos; q->q_next = pos->q_next; q->q_next->q_prev = q; pos->q_next = q; } #if 0 static int queue_len(struct netqueue *head) { struct netqueue *q = head->q_next; int i = 0; while (q != head) { i++; q = q->q_next; } return i; } #endif static struct netqueue * queue_get_slot(struct priv_net * pn) { struct netqueue * q = pn->pn_queue_free.q_next; if (q != &pn->pn_queue_free) { queue_del(q); return q; } if (pn->pn_queue_len++ > QUEUE_MAX) return NULL; return malloc(sizeof(*q)); } static void net_enque(struct priv_net * pn, void * buf, int len) { struct netqueue * q; q = queue_get_slot(pn); if (!q) return; q->q_len = len; assert((int) sizeof(q->q_buf) >= q->q_len); memcpy(q->q_buf, buf, q->q_len); queue_add(&pn->pn_queue, q); } static int net_get_nopacket(struct priv_net * pn, void * arg, int * len) { unsigned char buf[2048]; int l = sizeof(buf); int c = 0; while (1) { l = sizeof(buf); c = net_get(pn->pn_s, buf, &l); if (c < 0) return c; if (c != NET_PACKET && c > 0) break; if (c > 0) net_enque(pn, buf, l); } assert(l <= *len); memcpy(arg, buf, l); *len = l; return c; } static int net_cmd(struct priv_net * pn, int command, void * arg, int alen) { uint32_t rc = 0; int len; int cmd; if (net_send(pn->pn_s, command, arg, alen) == -1) { return -1; } len = sizeof(rc); cmd = net_get_nopacket(pn, &rc, &len); if (cmd == -1) { return -1; } assert(cmd == NET_RC); //-V547 assert(len == sizeof(rc)); return ntohl(rc); } static int queue_get(struct priv_net * pn, void * buf, int len) { struct netqueue * head = &pn->pn_queue; struct netqueue * q = head->q_next; if (q == head) return 0; #ifdef NDEBUG (void) len; #endif assert(q->q_len <= len); memcpy(buf, q->q_buf, q->q_len); queue_del(q); queue_add(&pn->pn_queue_free, q); return q->q_len; } static int net_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * h80211, int len, struct rx_info * ri) { struct priv_net * pn = wi_priv(wi); uint32_t buf[512] = {0}; // 512 * 4 = 2048 unsigned char * bufc = (unsigned char *) buf; int cmd; int sz = sizeof(*ri); int l; int ret; /* try queue */ l = queue_get(pn, buf, sizeof(buf)); if (!l) { /* try reading form net */ l = sizeof(buf); cmd = net_get(pn->pn_s, buf, &l); if (cmd == -1) return -1; if (cmd == NET_RC) { ret = ntohl((buf[0])); return ret; } assert(cmd == NET_PACKET); } /* XXX */ if (ri) { // re-assemble 64-bit integer uint64_t hi = buf[0]; ri->ri_mactime = __be64_to_cpu(((hi) << 32U) | buf[1]); ri->ri_power = __be32_to_cpu(buf[2]); ri->ri_noise = __be32_to_cpu(buf[3]); ri->ri_channel = __be32_to_cpu(buf[4]); ri->ri_freq = __be32_to_cpu(buf[5]); ri->ri_rate = __be32_to_cpu(buf[6]); ri->ri_antenna = __be32_to_cpu(buf[7]); } l -= sz; assert(l > 0); if (l > len) l = len; memcpy(h80211, &bufc[sz], l); if (dlt) { *dlt = LINKTYPE_IEEE802_11; } if (ts) { clock_gettime(CLOCK_REALTIME, ts); } return l; } static int net_get_mac(struct wif * wi, unsigned char * mac) { struct priv_net * pn = wi_priv(wi); uint32_t buf[2]; // only need 6 bytes, this provides 8 int cmd; int sz = 6; if (net_send(pn->pn_s, NET_GET_MAC, NULL, 0) == -1) return -1; cmd = net_get_nopacket(pn, buf, &sz); if (cmd == -1) return -1; if (cmd == NET_RC) return ntohl(buf[0]); //-V547 assert(cmd == NET_MAC); assert(sz == 6); memcpy(mac, buf, 6); //-V512 return 0; } static int net_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * h80211, int len, struct tx_info * ti) { struct priv_net * pn = wi_priv(wi); int sz = sizeof(*ti); unsigned char buf[2048]; unsigned char * ptr = buf; (void) ts; (void) dlt; /* XXX */ if (ti) memcpy(ptr, ti, sz); //-V512 else memset(ptr, 0, sizeof(*ti)); //-V512 ptr += sz; memcpy(ptr, h80211, len); sz += len; return net_cmd(pn, NET_WRITE, buf, sz); } static int net_set_channel(struct wif * wi, int chan) { uint32_t c = htonl(chan); return net_cmd(wi_priv(wi), NET_SET_CHAN, &c, sizeof(c)); } static int net_get_channel(struct wif * wi) { struct priv_net * pn = wi_priv(wi); return net_cmd(pn, NET_GET_CHAN, NULL, 0); } static int net_set_rate(struct wif * wi, int rate) { uint32_t c = htonl(rate); return net_cmd(wi_priv(wi), NET_SET_RATE, &c, sizeof(c)); } static int net_get_rate(struct wif * wi) { struct priv_net * pn = wi_priv(wi); return net_cmd(pn, NET_GET_RATE, NULL, 0); } static int net_get_monitor(struct wif * wi) { return net_cmd(wi_priv(wi), NET_GET_MONITOR, NULL, 0); } static void do_net_free(struct wif * wi) { assert(wi->wi_priv); free(wi->wi_priv); wi->wi_priv = 0; free(wi); } static void net_close(struct wif * wi) { struct priv_net * pn = wi_priv(wi); close(pn->pn_s); do_net_free(wi); } static int handshake(int s) { if (s) { } /* XXX unused */ /* XXX do a handshake */ return 0; } static int do_net_open(char * iface) { int s, port; char ip[16]; struct sockaddr_in s_in; port = get_ip_port(iface, ip, sizeof(ip) - 1); if (port == -1) return -1; memset(&s_in, 0, sizeof(struct sockaddr_in)); s_in.sin_family = PF_INET; s_in.sin_port = htons(port); if (!inet_aton(ip, &s_in.sin_addr)) return -1; if ((s = socket(s_in.sin_family, SOCK_STREAM, IPPROTO_TCP)) == -1) return -1; printf("Connecting to %s port %d...\n", ip, port); if (connect(s, (struct sockaddr *) &s_in, sizeof(s_in)) == -1) { close(s); printf("Failed to connect\n"); return -1; } if (handshake(s) == -1) { close(s); printf("Failed to connect - handshake failed\n"); return -1; } printf("Connection successful\n"); return s; } static int net_fd(struct wif * wi) { struct priv_net * pn = wi_priv(wi); return pn->pn_s; } EXPORT struct wif * net_open(char * iface) { struct wif * wi; struct priv_net * pn; int s; /* setup wi struct */ wi = wi_alloc(sizeof(*pn)); if (!wi) return NULL; wi->wi_read = net_read; wi->wi_write = net_write; wi->wi_set_channel = net_set_channel; wi->wi_get_channel = net_get_channel; wi->wi_set_rate = net_set_rate; wi->wi_get_rate = net_get_rate; wi->wi_close = net_close; wi->wi_fd = net_fd; wi->wi_get_mac = net_get_mac; wi->wi_get_monitor = net_get_monitor; /* setup iface */ s = do_net_open(iface); if (s == -1) { do_net_free(wi); return NULL; } /* setup private state */ pn = wi_priv(wi); pn->pn_s = s; pn->pn_queue.q_next = pn->pn_queue.q_prev = &pn->pn_queue; pn->pn_queue_free.q_next = pn->pn_queue_free.q_prev = &pn->pn_queue_free; return wi; }
C
aircrack-ng/lib/osdep/openbsd.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for OpenBSD. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/endian.h> #include <errno.h> #include <fcntl.h> #include <sys/param.h> #include <sys/sysctl.h> #include <net/bpf.h> #include <sys/socket.h> #include <net/if.h> #include <net/if_media.h> #include <sys/ioctl.h> #include <net/if_dl.h> #include <sys/queue.h> #include <net/if_var.h> #include <sys/mbuf.h> #define _KERNEL #include <net80211/ieee80211.h> #include <net80211/ieee80211_crypto.h> #include <frame.h> #include <sys/timeout.h> #undef _KERNEL #include <net80211/ieee80211_node.h> #include <net80211/ieee80211_ioctl.h> #include <net80211/ieee80211_radiotap.h> #include <net80211/ieee80211_proto.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/uio.h> #include <assert.h> #include <ifaddrs.h> #include "osdep.h" #ifndef LINKTYPE_IEEE802_11 #define LINKTYPE_IEEE802_11 105 #endif #ifndef IEEE80211_RADIOTAP_F_FCS #define IEEE80211_RADIOTAP_F_FCS 0x10 /* Frame includes FCS */ #endif #ifndef IEEE80211_IOC_CHANNEL #define IEEE80211_IOC_CHANNEL 0 #endif #ifndef le32toh #define le32toh(x) htole32(x) #endif struct priv_obsd { /* iface */ int po_fd; /* rx */ int po_nocrc; /* tx */ unsigned char po_buf[4096]; unsigned char * po_next; int po_totlen; /* setchan */ int po_s; struct ifreq po_ifr; struct ieee80211chanreq po_ireq; int po_chan; }; static void get_radiotap_info(struct priv_obsd * po, struct ieee80211_radiotap_header * rth, int * plen, struct rx_info * ri) { uint32_t present; uint8_t rflags = 0; int i; unsigned char * body = (unsigned char *) (rth + 1); int dbm_power = 0, db_power = 0; /* reset control info */ if (ri) memset(ri, 0, sizeof(*ri)); /* get info */ present = le32toh(rth->it_present); for (i = IEEE80211_RADIOTAP_TSFT; i <= IEEE80211_RADIOTAP_EXT; i++) { if (!(present & (1 << i))) continue; switch (i) { case IEEE80211_RADIOTAP_TSFT: body += sizeof(uint64_t); break; case IEEE80211_RADIOTAP_FLAGS: rflags = *((uint8_t *) body); /* fall through */ case IEEE80211_RADIOTAP_RATE: body += sizeof(uint8_t); break; case IEEE80211_RADIOTAP_CHANNEL: if (ri) { ri->ri_channel = 1; } body += sizeof(uint16_t) * 2; break; case IEEE80211_RADIOTAP_FHSS: body += sizeof(uint16_t); break; case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: dbm_power = *body++; break; case IEEE80211_RADIOTAP_DBM_ANTNOISE: dbm_power -= *body++; break; case IEEE80211_RADIOTAP_DB_ANTSIGNAL: db_power = *body++; break; case IEEE80211_RADIOTAP_DB_ANTNOISE: db_power -= *body++; break; default: i = IEEE80211_RADIOTAP_EXT + 1; break; } } /* set power */ if (ri) { if (dbm_power) ri->ri_power = dbm_power; else ri->ri_power = db_power; } /* XXX cache; drivers won't change this per-packet */ /* check if FCS/CRC is included in packet */ if (po->po_nocrc || (rflags & IEEE80211_RADIOTAP_F_FCS)) { *plen -= IEEE80211_CRC_LEN; po->po_nocrc = 1; } } static unsigned char * get_80211(struct priv_obsd * po, int * plen, struct rx_info * ri) { struct bpf_hdr * bpfh; struct ieee80211_radiotap_header * rth; void * ptr; unsigned char ** data; int * totlen; data = &po->po_next; totlen = &po->po_totlen; assert(*totlen); /* bpf hdr */ bpfh = (struct bpf_hdr *) (*data); assert(bpfh->bh_caplen == bpfh->bh_datalen); /* XXX */ *totlen -= bpfh->bh_hdrlen; /* check if more packets */ if ((int) bpfh->bh_caplen < *totlen) { int tot = bpfh->bh_hdrlen + bpfh->bh_caplen; int offset = BPF_WORDALIGN(tot); *data = (unsigned char *) bpfh + offset; *totlen -= offset - tot; /* take into account align bytes */ } else if ((int) bpfh->bh_caplen > *totlen) abort(); *plen = bpfh->bh_caplen; *totlen -= bpfh->bh_caplen; assert(*totlen >= 0); /* radiotap */ rth = (struct ieee80211_radiotap_header *) ((char *) bpfh + bpfh->bh_hdrlen); get_radiotap_info(po, rth, plen, ri); *plen -= rth->it_len; assert(*plen > 0); /* data */ ptr = (char *) rth + rth->it_len; return ptr; } static int obsd_get_channel(struct wif * wi) { struct priv_obsd * po = wi_priv(wi); struct ieee80211chanreq channel; memset(&channel, 0, sizeof(channel)); strlcpy(channel.i_name, wi_get_ifname(wi), sizeof(channel.i_name)); if (ioctl(po->po_s, SIOCG80211CHANNEL, (caddr_t) &channel) < 0) return -1; return channel.i_channel; } static int obsd_set_channel(struct wif * wi, int chan) { struct priv_obsd * po = wi_priv(wi); struct ieee80211chanreq channel; memset(&channel, 0, sizeof(channel)); strlcpy(channel.i_name, wi_get_ifname(wi), sizeof(channel.i_name)); channel.i_channel = chan; if (ioctl(po->po_s, SIOCS80211CHANNEL, (caddr_t) &channel) < 0) return -1; po->po_chan = chan; return 0; } static int obsd_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * h80211, int len, struct rx_info * ri) { struct priv_obsd * po = wi_priv(wi); unsigned char * wh; int plen; assert(len > 0); /* need to read more */ while (po->po_totlen == 0) { po->po_totlen = read(po->po_fd, po->po_buf, sizeof(po->po_buf)); if (po->po_totlen == -1) { po->po_totlen = 0; return -1; } po->po_next = po->po_buf; } /* read 802.11 packet */ wh = get_80211(po, &plen, ri); if (plen > len) plen = len; assert(plen > 0); memcpy(h80211, wh, plen); if (dlt) { *dlt = LINKTYPE_IEEE802_11; } if (ts) { clock_gettime(CLOCK_REALTIME, ts); } if (ri && !ri->ri_channel) ri->ri_channel = wi_get_channel(wi); return plen; } static int obsd_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * h80211, int len, struct tx_info * ti) { struct priv_obsd * po = wi_priv(wi); int rc; (void) ts; (void) dlt; /* XXX make use of ti */ if (ti) { } rc = write(po->po_fd, h80211, len); if (rc == -1) return rc; return 0; } static void do_free(struct wif * wi) { assert(wi->wi_priv); free(wi->wi_priv); wi->wi_priv = 0; free(wi); } static void obsd_close(struct wif * wi) { struct priv_obsd * po = wi_priv(wi); close(po->po_fd); close(po->po_s); do_free(wi); } static int do_obsd_open(struct wif * wi, char * iface) { int i; char buf[64]; int fd = -1; struct ifreq ifr; unsigned int dlt = DLT_IEEE802_11_RADIO; int s; unsigned int flags; struct ifmediareq ifmr; uint64_t * mwords; struct priv_obsd * po = wi_priv(wi); unsigned int size = sizeof(po->po_buf); /* basic sanity check */ if (strlen(iface) >= sizeof(ifr.ifr_name)) return -1; /* open wifi */ s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) return -1; po->po_s = s; /* set iface up and promisc */ memset(&ifr, 0, sizeof(ifr)); memcpy(ifr.ifr_name, iface, IFNAMSIZ); if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) goto close_sock; flags = ifr.ifr_flags; flags |= IFF_UP | IFF_PROMISC; memset(&ifr, 0, sizeof(ifr)); memcpy(ifr.ifr_name, iface, IFNAMSIZ); ifr.ifr_flags = flags & 0xffff; if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) goto close_sock; /* monitor mode */ memset(&ifmr, 0, sizeof(ifmr)); memcpy(ifmr.ifm_name, iface, IFNAMSIZ); if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) goto close_sock; assert(ifmr.ifm_count != 0); mwords = (uint64_t *) malloc(ifmr.ifm_count * sizeof(uint64_t)); if (!mwords) goto close_sock; ifmr.ifm_ulist = mwords; if (ioctl(s, SIOCGIFMEDIA, &ifmr) == -1) { free(mwords); goto close_sock; } free(mwords); memset(&ifr, 0, sizeof(ifr)); memcpy(ifr.ifr_name, iface, IFNAMSIZ); ifr.ifr_media = ifmr.ifm_current | IFM_IEEE80211_MONITOR; if (ioctl(s, SIOCSIFMEDIA, &ifr) == -1) goto close_sock; /* setup ifreq for chan that may be used in future */ memcpy(po->po_ireq.i_name, iface, IFNAMSIZ); /* same for ifreq [mac addr] */ memcpy(po->po_ifr.ifr_name, iface, IFNAMSIZ); /* open bpf */ for (i = 0; i < 256; i++) { snprintf(buf, sizeof(buf), "/dev/bpf%d", i); fd = open(buf, O_RDWR); if (fd < 0) { if (errno != EBUSY) return -1; continue; } else break; } if (fd < 0) goto close_sock; if (ioctl(fd, BIOCSBLEN, &size) < 0) goto close_bpf; memcpy(ifr.ifr_name, iface, IFNAMSIZ); if (ioctl(fd, BIOCSETIF, &ifr) < 0) goto close_bpf; if (ioctl(fd, BIOCSDLT, &dlt) < 0) goto close_bpf; if (ioctl(fd, BIOCPROMISC, NULL) < 0) goto close_bpf; dlt = 1; if (ioctl(fd, BIOCIMMEDIATE, &dlt) == -1) goto close_bpf; return fd; close_sock: close(s); return -1; close_bpf: close(fd); goto close_sock; } static int obsd_fd(struct wif * wi) { struct priv_obsd * po = wi_priv(wi); return po->po_fd; } static int obsd_get_mac(struct wif * wi, unsigned char * mac) { struct ifaddrs *ifa, *p; char * name = wi_get_ifname(wi); int rc = -1; struct sockaddr_dl * sdp; if (getifaddrs(&ifa) == -1) return -1; p = ifa; while (p) { if (p->ifa_addr->sa_family == AF_LINK && strcmp(name, p->ifa_name) == 0) { sdp = (struct sockaddr_dl *) p->ifa_addr; memcpy(mac, sdp->sdl_data + sdp->sdl_nlen, 6); rc = 0; break; } p = p->ifa_next; } freeifaddrs(ifa); return rc; } static int obsd_get_monitor(struct wif * wi) { if (wi) { } /* XXX unused */ /* XXX */ return 0; } static int obsd_get_rate(struct wif * wi) { if (wi) { } /* XXX unused */ /* XXX */ return 1000000; } static int obsd_set_rate(struct wif * wi, int rate) { if (wi || rate) { } /* XXX unused */ /* XXX */ return 0; } static int obsd_set_mac(struct wif * wi, unsigned char * mac) { struct priv_obsd * po = wi_priv(wi); struct ifreq * ifr = &po->po_ifr; ifr->ifr_addr.sa_family = AF_LINK; ifr->ifr_addr.sa_len = 6; memcpy(ifr->ifr_addr.sa_data, mac, 6); return ioctl(po->po_s, SIOCSIFLLADDR, ifr); } static struct wif * obsd_open(char * iface) { struct wif * wi; struct priv_obsd * po; int fd; /* setup wi struct */ wi = wi_alloc(sizeof(*po)); if (!wi) return NULL; wi->wi_read = obsd_read; wi->wi_write = obsd_write; wi->wi_set_channel = obsd_set_channel; wi->wi_get_channel = obsd_get_channel; wi->wi_close = obsd_close; wi->wi_fd = obsd_fd; wi->wi_get_mac = obsd_get_mac; wi->wi_set_mac = obsd_set_mac; wi->wi_get_rate = obsd_get_rate; wi->wi_set_rate = obsd_set_rate; wi->wi_get_monitor = obsd_get_monitor; /* setup iface */ fd = do_obsd_open(wi, iface); if (fd == -1) { do_free(wi); return NULL; } /* setup private state */ po = wi_priv(wi); po->po_fd = fd; return wi; } struct wif * wi_open_osdep(char * iface) { return obsd_open(iface); } EXPORT int get_battery_state(void) { #if defined(__FreeBSD__) int value; size_t len; len = 1; value = 0; sysctlbyname("hw.acpi.acline", &value, &len, NULL, 0); if (value == 0) { sysctlbyname("hw.acpi.battery.time", &value, &len, NULL, 0); value = value * 60; } else { value = 0; } return (value); #elif defined(_BSD_SOURCE) struct apm_power_info api; int apmfd; if ((apmfd = open("/dev/apm", O_RDONLY)) < 0) return 0; if (ioctl(apmfd, APM_IOC_GETPOWER, &api) < 0) { close(apmfd); return 0; } close(apmfd); if (api.battery_state == APM_BATT_UNKNOWN || api.battery_state == APM_BATTERY_ABSENT || api.battery_state == APM_BATT_CHARGING || api.ac_state == APM_AC_ON) { return 0; } return ((int) (api.minutes_left)) * 60; #else return 0; #endif }
C
aircrack-ng/lib/osdep/openbsd_tap.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API for OpenBSD. TAP routines * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/socket.h> #include <net/if.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include "osdep.h" struct tip_obsd { int to_fd; int to_ioctls; struct ifreq to_ifr; char to_name[IFNAMSIZ]; int to_destroy; }; static int ti_do_open_obsd(struct tif * ti, char * name) { int fd; char * iface = "/dev/tap"; struct stat st; struct tip_obsd * priv = ti_priv(ti); int s; unsigned int flags; struct ifreq * ifr; /* open tap */ if (name) iface = name; else priv->to_destroy = 1; /* we create, we destroy */ fd = open(iface, O_RDWR); if (fd == -1) return -1; /* get name */ if (fstat(fd, &st) == -1) goto err; snprintf(priv->to_name, sizeof(priv->to_name) - 1, "%s", devname(st.st_rdev, S_IFCHR)); /* bring iface up */ s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) goto err; priv->to_ioctls = s; /* get flags */ ifr = &priv->to_ifr; memset(ifr, 0, sizeof(*ifr)); memcpy(ifr->ifr_name, priv->to_name, sizeof(ifr->ifr_name)); if (ioctl(s, SIOCGIFFLAGS, ifr) == -1) goto err2; flags = ifr->ifr_flags; /* set flags */ flags |= IFF_UP; ifr->ifr_flags = flags & 0xffff; if (ioctl(s, SIOCSIFFLAGS, ifr) == -1) goto err2; return fd; err: /* XXX destroy */ close(fd); return -1; err2: close(s); goto err; } static void ti_do_free(struct tif * ti) { struct tip_obsd * priv = ti_priv(ti); free(priv); free(ti); } static void ti_destroy(struct tip_obsd * priv) { ioctl(priv->to_ioctls, SIOCIFDESTROY, &priv->to_ifr); } static void ti_close_obsd(struct tif * ti) { struct tip_obsd * priv = ti_priv(ti); if (priv->to_destroy) ti_destroy(priv); close(priv->to_fd); close(priv->to_ioctls); ti_do_free(ti); } static char * ti_name_obsd(struct tif * ti) { struct tip_obsd * priv = ti_priv(ti); return priv->to_name; } static int ti_set_mtu_obsd(struct tif * ti, int mtu) { struct tip_obsd * priv = ti_priv(ti); priv->to_ifr.ifr_mtu = mtu; return ioctl(priv->to_ioctls, SIOCSIFMTU, &priv->to_ifr); } static int ti_set_mac_obsd(struct tif * ti, unsigned char * mac) { struct tip_obsd * priv = ti_priv(ti); struct ifreq * ifr = &priv->to_ifr; ifr->ifr_addr.sa_family = AF_LINK; ifr->ifr_addr.sa_len = 6; memcpy(ifr->ifr_addr.sa_data, mac, 6); return ioctl(priv->to_ioctls, SIOCSIFLLADDR, ifr); } static int ti_set_ip_obsd(struct tif * ti, struct in_addr * ip) { struct tip_obsd * priv = ti_priv(ti); struct ifaliasreq ifra; struct sockaddr_in * s_in; /* assume same size */ memset(&ifra, 0, sizeof(ifra)); strncpy(ifra.ifra_name, priv->to_ifr.ifr_name, IFNAMSIZ); s_in = (struct sockaddr_in *) &ifra.ifra_addr; s_in->sin_family = PF_INET; s_in->sin_addr = *ip; s_in->sin_len = sizeof(*s_in); return ioctl(priv->to_ioctls, SIOCAIFADDR, &ifra); } static int ti_fd_obsd(struct tif * ti) { struct tip_obsd * priv = ti_priv(ti); return priv->to_fd; } static int ti_read_obsd(struct tif * ti, void * buf, int len) { return read(ti_fd(ti), buf, len); } static int ti_write_obsd(struct tif * ti, void * buf, int len) { return write(ti_fd(ti), buf, len); } static struct tif * ti_open_obsd(char * iface) { struct tif * ti; struct tip_obsd * priv; int fd; /* setup ti struct */ ti = ti_alloc(sizeof(*priv)); if (!ti) return NULL; ti->ti_name = ti_name_obsd; ti->ti_set_mtu = ti_set_mtu_obsd; ti->ti_close = ti_close_obsd; ti->ti_fd = ti_fd_obsd; ti->ti_read = ti_read_obsd; ti->ti_write = ti_write_obsd; ti->ti_set_mac = ti_set_mac_obsd; ti->ti_set_ip = ti_set_ip_obsd; /* setup iface */ fd = ti_do_open_obsd(ti, iface); if (fd == -1) { ti_do_free(ti); return NULL; } /* setup private state */ priv = ti_priv(ti); priv->to_fd = fd; return ti; } EXPORT struct tif * ti_open(char * iface) { return ti_open_obsd(iface); }
C
aircrack-ng/lib/osdep/osdep.c
/* * Copyright (c) 2007, 2008, Andrea Bittau <[email protected]> * * OS dependent API. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdlib.h> #include <assert.h> #include <string.h> #include "osdep.h" #include "network.h" extern struct wif * file_open(char * iface); EXPORT int wi_read(struct wif * wi, struct timespec * ts, int * dlt, unsigned char * h80211, int len, struct rx_info * ri) { assert(wi->wi_read); return wi->wi_read(wi, ts, dlt, h80211, len, ri); } EXPORT int wi_write(struct wif * wi, struct timespec * ts, int dlt, unsigned char * h80211, int len, struct tx_info * ti) { assert(wi->wi_write); return wi->wi_write(wi, ts, dlt, h80211, len, ti); } EXPORT int wi_set_ht_channel(struct wif * wi, int chan, unsigned int htval) { assert(wi->wi_set_ht_channel); return wi->wi_set_ht_channel(wi, chan, htval); } EXPORT int wi_set_channel(struct wif * wi, int chan) { assert(wi->wi_set_channel); return wi->wi_set_channel(wi, chan); } EXPORT int wi_get_channel(struct wif * wi) { assert(wi->wi_get_channel); return wi->wi_get_channel(wi); } EXPORT int wi_set_freq(struct wif * wi, int freq) { assert(wi->wi_set_freq); return wi->wi_set_freq(wi, freq); } EXPORT int wi_get_freq(struct wif * wi) { assert(wi->wi_get_freq); return wi->wi_get_freq(wi); } EXPORT int wi_get_monitor(struct wif * wi) { assert(wi->wi_get_monitor); return wi->wi_get_monitor(wi); } EXPORT char * wi_get_ifname(struct wif * wi) { return wi->wi_interface; } EXPORT void wi_close(struct wif * wi) { assert(wi->wi_close); wi->wi_close(wi); } EXPORT int wi_fd(struct wif * wi) { assert(wi->wi_fd); return wi->wi_fd(wi); } struct wif * wi_alloc(int sz) { struct wif * wi; void * priv; /* Allocate wif & private state */ wi = malloc(sizeof(*wi)); if (!wi) return NULL; memset(wi, 0, sizeof(*wi)); priv = malloc(sz); if (!priv) { free(wi); return NULL; } memset(priv, 0, sz); wi->wi_priv = priv; return wi; } void * wi_priv(struct wif * wi) { return wi->wi_priv; } EXPORT int wi_get_mac(struct wif * wi, unsigned char * mac) { assert(wi->wi_get_mac); return wi->wi_get_mac(wi, mac); } EXPORT int wi_set_mac(struct wif * wi, unsigned char * mac) { assert(wi->wi_set_mac); return wi->wi_set_mac(wi, mac); } EXPORT int wi_get_rate(struct wif * wi) { assert(wi->wi_get_rate); return wi->wi_get_rate(wi); } EXPORT int wi_set_rate(struct wif * wi, int rate) { assert(wi->wi_set_rate); return wi->wi_set_rate(wi, rate); } EXPORT int wi_get_mtu(struct wif * wi) { assert(wi->wi_get_mtu); return wi->wi_get_mtu(wi); } EXPORT int wi_set_mtu(struct wif * wi, int mtu) { assert(wi->wi_set_mtu); return wi->wi_set_mtu(wi, mtu); } EXPORT struct wif * wi_open(char * iface) { struct wif * wi; if (iface == NULL || iface[0] == 0) { return NULL; } wi = file_open(iface); if (wi == (struct wif *) -1) return NULL; if (!wi) wi = net_open(iface); if (!wi) wi = wi_open_osdep(iface); if (!wi) return NULL; strncpy(wi->wi_interface, iface, sizeof(wi->wi_interface) - 1); wi->wi_interface[sizeof(wi->wi_interface) - 1] = 0; return wi; } /* tap stuff */ EXPORT char * ti_name(struct tif * ti) { assert(ti->ti_name); return ti->ti_name(ti); } EXPORT int ti_set_mtu(struct tif * ti, int mtu) { assert(ti->ti_set_mtu); return ti->ti_set_mtu(ti, mtu); } EXPORT int ti_get_mtu(struct tif * ti) { assert(ti->ti_get_mtu); return ti->ti_get_mtu(ti); } EXPORT void ti_close(struct tif * ti) { assert(ti->ti_close); ti->ti_close(ti); } EXPORT int ti_fd(struct tif * ti) { assert(ti->ti_fd); return ti->ti_fd(ti); } EXPORT int ti_read(struct tif * ti, void * buf, int len) { assert(ti->ti_read); return ti->ti_read(ti, buf, len); } EXPORT int ti_write(struct tif * ti, void * buf, int len) { assert(ti->ti_write); return ti->ti_write(ti, buf, len); } EXPORT int ti_set_mac(struct tif * ti, unsigned char * mac) { assert(ti->ti_set_mac); return ti->ti_set_mac(ti, mac); } EXPORT int ti_set_ip(struct tif * ti, struct in_addr * ip) { assert(ti->ti_set_ip); return ti->ti_set_ip(ti, ip); } struct tif * ti_alloc(int sz) { struct tif * ti; void * priv; /* Allocate tif & private state */ ti = malloc(sizeof(*ti)); if (!ti) return NULL; memset(ti, 0, sizeof(*ti)); priv = malloc(sz); if (!priv) { free(ti); return NULL; } memset(priv, 0, sz); ti->ti_priv = priv; return ti; } void * ti_priv(struct tif * ti) { return ti->ti_priv; }
C/C++
aircrack-ng/lib/osdep/tap-win32/common.h
/* * TAP-Win32 -- A kernel driver to provide virtual tap device functionality * on Windows. Originally derived from the CIPE-Win32 * project by Damion K. Wilson, with extensive modifications by * James Yonan. * * All source code which derives from the CIPE-Win32 project is * Copyright (C) Damion K. Wilson, 2003, and is released under the * GPL version 2 (see below). * * All other source code is Copyright (C) 2002-2005 OpenVPN Solutions LLC, * and is released under the GPL version 2 (see below). * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file COPYING included with this * distribution); if not, write to the Free Software Foundation, Inc., * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ //=============================================== // This file is included both by OpenVPN and // the TAP-Win32 driver and contains definitions // common to both. //=============================================== //============= // TAP IOCTLs //============= #define TAP_CONTROL_CODE(request, method) \ CTL_CODE(FILE_DEVICE_UNKNOWN, request, method, FILE_ANY_ACCESS) // Present in 8.1 #define TAP_IOCTL_GET_MAC TAP_CONTROL_CODE(1, METHOD_BUFFERED) #define TAP_IOCTL_GET_VERSION TAP_CONTROL_CODE(2, METHOD_BUFFERED) #define TAP_IOCTL_GET_MTU TAP_CONTROL_CODE(3, METHOD_BUFFERED) #define TAP_IOCTL_GET_INFO TAP_CONTROL_CODE(4, METHOD_BUFFERED) #define TAP_IOCTL_CONFIG_POINT_TO_POINT TAP_CONTROL_CODE(5, METHOD_BUFFERED) #define TAP_IOCTL_SET_MEDIA_STATUS TAP_CONTROL_CODE(6, METHOD_BUFFERED) #define TAP_IOCTL_CONFIG_DHCP_MASQ TAP_CONTROL_CODE(7, METHOD_BUFFERED) #define TAP_IOCTL_GET_LOG_LINE TAP_CONTROL_CODE(8, METHOD_BUFFERED) #define TAP_IOCTL_CONFIG_DHCP_SET_OPT TAP_CONTROL_CODE(9, METHOD_BUFFERED) // Added in 8.2 /* obsoletes TAP_IOCTL_CONFIG_POINT_TO_POINT */ #define TAP_IOCTL_CONFIG_TUN TAP_CONTROL_CODE(10, METHOD_BUFFERED) //================= // Registry keys //================= #define ADAPTER_KEY \ "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-" \ "08002BE10318}" #define NETWORK_CONNECTIONS_KEY \ "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-" \ "08002BE10318}" //====================== // Filesystem prefixes //====================== #define USERMODEDEVICEDIR "\\\\.\\Global\\" #define SYSDEVICEDIR "\\Device\\" #define USERDEVICEDIR "\\DosDevices\\Global\\" #define TAPSUFFIX ".tap" //========================================================= // TAP_COMPONENT_ID -- This string defines the TAP driver // type -- different component IDs can reside in the system // simultaneously. //========================================================= #define TAP_COMPONENT_ID "tap0801"
C
aircrack-ng/lib/ptw/aircrack-ptw-lib.c
/* * Copyright (c) 2007-2009 Erik Tews, Andrei Pychkine and Ralf-Philipp * Weinmann. * 2013 Ramiro Polla * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * * * In addition, as a special exception, the copyright holders give * permission to link the code of portions of this program with the * OpenSSL library under certain conditions as described in each * individual source file, and distribute linked combinations * including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. * If you modify * file(s) with this exception, you may extend this exception to your * version of the file(s), but you are not obligated to do so. * If you * do not wish to do so, delete this exception statement from your * version. * If you delete this exception statement from all source * files in the program, then also delete it here. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <string.h> #include <stdio.h> #include <stdlib.h> #include <pthread.h> #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif #if defined(__sun__) #include <alloca.h> #endif #include <limits.h> #include <math.h> #include <float.h> #include "aircrack-ng/support/pcap_local.h" #include "aircrack-ng/defs.h" #include "aircrack-ng/ptw/aircrack-ptw-lib.h" #include "aircrack-ng/aircrack-ng.h" #include <aircrack-ng/support/common.h> #define n PTW_n #define CONTROLSESSIONS PTW_CONTROLSESSIONS #define KSBYTES PTW_KSBYTES #define IVBYTES PTW_IVBYTES #define TESTBYTES 6 static struct options opt; // Internal state of rc4 typedef struct { uint32_t s[n]; uint8_t i; uint8_t j; } rc4state; // Helper structures for sorting typedef struct { int keybyte; uint8_t value; int distance; } sorthelper; typedef struct { int keybyte; double difference; } doublesorthelper; // The rc4 initial state, the idendity permutation static const uint32_t rc4initial[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}; // Values for p_correct_i static const double eval[] = {0.00534392069257663, 0.00531787585068872, 0.00531345769225911, 0.00528812219217898, 0.00525997750378221, 0.00522647312237696, 0.00519132541143668, 0.0051477139367225, 0.00510438884847959, 0.00505484662057323, 0.00500502783556246, 0.00495094196451801, 0.0048983441590402}; static int tried, max_tries; static int depth[KEYHSBYTES]; static PTW_tableentry keytable[KEYHSBYTES][n]; // Check if optmizied RC4 for AMD64 has to be compiled #if defined(__amd64) && defined(__SSE2__) \ && (!defined(__clang__) \ || (defined(__clang__) \ && (__clang_major__ >= 4 \ || (__clang_major__ == 3 && __clang_minor__ >= 9)))) #define USE_AMD64_RC4_OPTIMIZED #endif // For sorting static int compare(const void * ina, const void * inb) { REQUIRE(ina != NULL); REQUIRE(inb != NULL); PTW_tableentry * a = (PTW_tableentry *) ina; PTW_tableentry * b = (PTW_tableentry *) inb; return b->votes - a->votes; } // For sorting static int comparedoublesorthelper(const void * ina, const void * inb) { REQUIRE(ina != NULL); REQUIRE(inb != NULL); doublesorthelper * a = (doublesorthelper *) ina; doublesorthelper * b = (doublesorthelper *) inb; if (a->difference > b->difference) { return 1; } else if (fabs(a->difference - b->difference) < FLT_EPSILON) { return 0; } else { return -1; } } #ifdef USE_AMD64_RC4_OPTIMIZED static const uint32_t __attribute__((used)) __attribute__((aligned(16))) x0123[4] = {0, 1, 2, 3}; static const uint32_t __attribute__((used)) __attribute__((aligned(16))) x4444[4] = {4, 4, 4, 4}; static int rc4test_amd64_sse2(uint8_t * key, int keylen, uint8_t * iv, uint8_t * keystream) { int idx, i, j; int scratch1, scratch2; __asm__ volatile( #define state "%%rsp" #define keybuf "0x400(%%rsp)" #define keystream_ "0x428(%%rsp)" // setup stack "movq %%rsp, %q0 \n\t" "subq $0x430, %%rsp \n\t" "andq $-16, %%rsp \n\t" "movq %q0, -8(%%rsp) \n\t" // save keystream variable "movq %q6, " keystream_ " \n\t" // keylen += IVBYTES "addl $3, %k4 \n\t" // memcpy(keybuf, iv, IVBYTES); "movl (%q5), %k1 \n\t" "movl %k1 , " keybuf " \n\t" // memcpy(&keybuf[IVBYTES], key, keylen); "movdqa (%q3), %%xmm0 \n\t" "cmpl $16, %k4 \n\t" "movdqu %%xmm0, 3+" keybuf " \n\t" "jng .Lsmall_key1 \n\t" "movdqa 16(%q3), %%xmm1 \n\t" "movdqu %%xmm1,19+" keybuf " \n\t" ".Lsmall_key1: \n\t" // key = keybuf "lea " keybuf ", %q3 \n\t" // load xmm registers "movdqa %q9, %%xmm0 \n\t" "movdqa %q10, %%xmm1 \n\t" // clear some registers "xorq %q0, %q0 \n\t" // idx "xorq %q1, %q1 \n\t" // i "xorq %q2, %q2 \n\t" // j // build identity array ".p2align 4 \n\t" ".Lidentity_loop: \n\t" "movdqa %%xmm0, (" state ",%q1,4)\n\t" "addb $4, %b1 \n\t" "paddd %%xmm1, %%xmm0 \n\t" "jnc .Lidentity_loop \n\t" // load state into register "movq " state ", %q1 \n\t" // %q4 = and mask for idx "movq %q4, %q8 \n\t" "cmpq $16, %q8 \n\t" "movq $15, %q4 \n\t" "je .Lsmall_key2 \n\t" "shrq $1, %q4 \n\t" ".Lsmall_key2: \n\t" // init array with key ".p2align 4 \n\t" ".init_loop: \n\t" "movl %k0, %k8 \n\t" /* scratch2 = idx */ "movl (%q1), %k5 \n\t" /* s1 = state[i] */ "leal 1(%q0,1), %k0 \n\t" /* idx++ */ "movzbl (%q3,%q8,1), %k6 \n\t" /* key_n = key[scratch2] */ "leal (%q5,%q6,1), %k8 \n\t" /* scratch2 = s1 + key_n */ "addl %k8, %k2 \n\t" /* j += scratch2 */ "andl %k4, %k0 \n\t" /* idx &= mask */ "movzbl %b2, %k8 \n\t" /* scratch2 = j */ "movl (" state ",%q8,4), %k7 \n\t" /* s2 = state[scratch2] */ "movl %k7, (%q1) \n\t" /* state[i] = s2 */ "addq $4, %q1 \n\t" /* i++ */ "movl %k5, (" state ",%q8,4) \n\t" /* state[scratch2] = s1 */ "cmpq %q1, %q3 \n\t" /* state == &state[0x100] */ "jne .init_loop \n\t" // restore keystream variable "movq " keystream_ ", %q6 \n\t" // clear some registers "xorq %q2, %q2 \n\t" // j = 0 "xorq %q0, %q0 \n\t" // result #define RC4TEST_LOOP(offset) \ "movl 4*" offset "(" state "), %k5\n\t" /* s1 = state[i] */ \ "leal (%q5,%q2,1), %k4 \n\t" /* */ \ "movzbl %b4, %k2 \n\t" /* j += s1 */ \ "movl (" state ",%q2,4), %k1 \n\t" /* s2 = state[j] */ \ "movl %k1, 4*" offset "(" state ")\n\t" /* state[i] = s2 */ \ "movl %k5, (" state ",%q2,4) \n\t" /* state[j] = s1 */ \ "addb %b1, %b5 \n\t" /* s1 += s2; */ \ "movb (" state ",%q5,4), %b3 \n\t" /* ret = state[s1] */ \ "cmpb %b3, " offset "-1(%q6) \n\t" /* ret == keystream[i-1] */ \ "jne .ret \n\t" RC4TEST_LOOP("1") RC4TEST_LOOP("2") RC4TEST_LOOP("3") RC4TEST_LOOP("4") RC4TEST_LOOP("5") RC4TEST_LOOP("6") #undef RC4TEST_LOOP "addb $1, %b0 \n\t" ".ret: \n\t" // restore stack "movq -8(%%rsp), %%rsp \n\t" : "=&r"(idx), "=&r"(i), "=&r"(j), "+r"(key), "+r"(keylen), "+r"(iv), "+r"(keystream), "=&r"(scratch1), "=&r"(scratch2) : "m"(x0123[0]), "m"(x4444[0]) : "xmm0", "xmm1"); #undef state #undef keybuf #undef keystream_ return idx; } #endif // RC4 key setup static void rc4init(uint8_t * key, int keylen, rc4state * state) { REQUIRE(key != NULL); REQUIRE(keylen > 0 && keylen < INT_MAX); REQUIRE(state != NULL); int i; unsigned char j; uint8_t tmp; int idx = 0; memcpy(state->s, &rc4initial, sizeof(rc4initial)); j = 0; for (i = 0; i < n; i++) { /* this should be: j = (j + state->s[i] + key[i % keylen]) % n; but as "j" is declared as unsigned char and n equals 256, we can "optimize" it */ j = (j + state->s[i] + key[idx]); if (++idx == keylen) idx = 0; tmp = state->s[i]; state->s[i] = state->s[j]; state->s[j] = tmp; } state->i = 0; state->j = 0; } // RC4 key stream generation static uint8_t rc4update(rc4state * state) { REQUIRE(state != NULL); uint8_t tmp; uint8_t k; state->i++; state->j += state->s[state->i]; tmp = state->s[state->i]; state->s[state->i] = state->s[state->j]; state->s[state->j] = tmp; k = state->s[state->i] + state->s[state->j]; return state->s[k]; } static int rc4test(uint8_t * key, int keylen, uint8_t * iv, uint8_t * keystream) { REQUIRE(key != NULL); REQUIRE(keylen > 0); REQUIRE(iv != NULL); REQUIRE(keystream != NULL); uint8_t keybuf[PTW_KSBYTES]; rc4state rc4state; int j; memcpy(&keybuf[IVBYTES], key, keylen); memcpy(keybuf, iv, IVBYTES); //-V512 rc4init(keybuf, keylen + IVBYTES, &rc4state); for (j = 0; j < TESTBYTES; j++) { if ((rc4update(&rc4state) ^ keystream[j]) != 0) { return 0; } } return 1; } // For sorting static int comparesorthelper(const void * ina, const void * inb) { REQUIRE(ina != NULL); REQUIRE(inb != NULL); sorthelper * a = (sorthelper *) ina; sorthelper * b = (sorthelper *) inb; return a->distance - b->distance; } /* * Guess the values for sigma_i * ivlen - how long was the iv (is used differently in original klein attack) * iv - IV which was used for this packet * keystream - keystream recovered * result - buffer for the values of sigma_i * kb - how many keybytes should be guessed */ static void guesskeybytes( int ivlen, uint8_t * iv, uint8_t * keystream, uint8_t * result, int kb) { REQUIRE(iv != NULL); REQUIRE(keystream != NULL); REQUIRE(result != NULL); uint32_t state[n]; uint8_t j = 0; uint8_t tmp; int i; int jj = ivlen; uint8_t ii; uint8_t s = 0; memcpy(state, &rc4initial, sizeof(rc4initial)); for (i = 0; i < ivlen; i++) { j += state[i] + iv[i]; tmp = state[i]; state[i] = state[j]; state[j] = tmp; } for (i = 0; i < kb; i++) { tmp = jj - keystream[jj - 1]; ii = 0; while (tmp != state[ii]) { ii++; } s += state[jj]; ii -= (j + s); result[i] = ii; jj++; } return; } /* * Is a guessed key correct? */ static int correct(PTW_attackstate * state, uint8_t * key, int keylen) { REQUIRE(state != NULL); REQUIRE(key != NULL && keylen > 0); int i; int k; // We need at least 3 sessions to be somehow certain if (state->sessions_collected < 3) { return 0; } tried++; k = rand_u32() % (state->sessions_collected - 10); for (i = k; i < k + 10; i++) { if (!state->rc4test(key, keylen, state->sessions[i].iv, state->sessions[i].keystream)) return 0; } return 1; } /* * Calculate the squaresum of the errors for both distributions */ static void getdrv(PTW_tableentry orgtable[][n], int keylen, double * normal, double * ausreiser) { int i, j; int numvotes = 0; double e; double e2; double emax; double help = 0.0; double maxhelp = 0; double maxi = 0; for (i = 0; i < n; i++) { numvotes += orgtable[0][i].votes; } e = (double) (numvotes) / n; for (i = 0; i < keylen; i++) { emax = eval[i] * numvotes; e2 = ((1.0 - eval[i]) / 255.0) * numvotes; normal[i] = 0; ausreiser[i] = 0; maxhelp = 0; maxi = 0; for (j = 0; j < n; j++) { if (orgtable[i][j].votes > maxhelp) { maxhelp = orgtable[i][j].votes; maxi = j; } } for (j = 0; j < n; j++) { if (fabs(maxi - j) < FLT_EPSILON) { help = (1.0 - orgtable[i][j].votes / emax); } else { help = (1.0 - orgtable[i][j].votes / e2); } help = help * help; ausreiser[i] += help; help = (1.0 - orgtable[i][j].votes / e); help = help * help; normal[i] += help; } } } /* * Guess a single keybyte */ static int doRound(PTW_tableentry sortedtable[][n], int keybyte, int fixat, uint8_t fixvalue, int * searchborders, uint8_t * key, int keylen, PTW_attackstate * state, uint8_t sum, int * strongbytes, int * bf, int validchars[][n]) { int i; uint8_t tmp; if (!opt.is_quiet && keybyte < 4) show_wep_stats(keylen - 1, 0, keytable, searchborders, depth, tried); if (keybyte > 0) { if (!validchars[keybyte - 1][key[keybyte - 1]]) { return 0; } } if (keybyte == keylen) { return correct(state, key, keylen); } else if (bf[keybyte] == 1) { for (i = 0; i < n; i++) { key[keybyte] = i; if (doRound(sortedtable, keybyte + 1, fixat, fixvalue, searchborders, key, keylen, state, sum + i % n, strongbytes, bf, validchars)) { return 1; } } return 0; } else if (keybyte == fixat) { key[keybyte] = fixvalue - sum; return doRound(sortedtable, keybyte + 1, fixat, fixvalue, searchborders, key, keylen, state, fixvalue, strongbytes, bf, validchars); } else if (strongbytes[keybyte] == 1) { // printf("assuming byte %d to be strong\n", keybyte); tmp = 3 + keybyte; for (i = keybyte - 1; i >= 1; i--) { tmp += 3 + key[i] + i; key[keybyte] = n - tmp; if (doRound(sortedtable, keybyte + 1, fixat, fixvalue, searchborders, key, keylen, state, (n - tmp + sum) % n, strongbytes, bf, validchars) == 1) { printf("hit with strongbyte for keybyte %d\n", keybyte); return 1; } } return 0; } else { REQUIRE(searchborders != NULL); REQUIRE(keybyte >= 0); for (i = 0; i < searchborders[keybyte]; i++) { key[keybyte] = sortedtable[keybyte][i].b - sum; if (!opt.is_quiet) { depth[keybyte] = i; keytable[keybyte][i].b = key[keybyte]; } if (doRound(sortedtable, keybyte + 1, fixat, fixvalue, searchborders, key, keylen, state, sortedtable[keybyte][i].b, strongbytes, bf, validchars)) { return 1; } } return 0; } } /* * Do the actual computation of the key */ static int doComputation(PTW_attackstate * state, uint8_t * key, int keylen, PTW_tableentry table[][n], sorthelper * sh2, int * strongbytes, int keylimit, int * bf, int validchars[][n]) { int i, j; int choices[KEYHSBYTES]; int prod; int fixat; int fixvalue; if (!opt.is_quiet) memcpy(keytable, table, sizeof(PTW_tableentry) * n * keylen); for (i = 0; i < keylen; i++) { if (strongbytes[i] == 1) { choices[i] = i; } else { choices[i] = 1; } } i = 0; prod = 0; fixat = -1; fixvalue = 0; max_tries = keylimit; while (prod < keylimit) { if (doRound(table, 0, fixat, fixvalue, choices, key, keylen, state, 0, strongbytes, bf, validchars) == 1) { // printf("hit with %d choices\n", prod); if (!opt.is_quiet) show_wep_stats(keylen - 1, 1, keytable, choices, depth, tried); return 1; } while ((i < keylen * (n - 1)) && ((strongbytes[sh2[i].keybyte] == 1) || (bf[sh2[i].keybyte] == 1))) { i++; } if (i >= (keylen * (n - 1))) { break; } choices[sh2[i].keybyte]++; fixat = sh2[i].keybyte; // printf("choices[%d] is now %d\n", sh2[i].keybyte, // choices[sh2[i].keybyte]); fixvalue = sh2[i].value; prod = 1; for (j = 0; j < keylen; j++) { prod *= choices[j]; if (bf[j] == 1) { prod *= n; } } /* do { i++; } while (strongbytes[sh2[i].keybyte] == 1); */ i++; if (!opt.is_quiet) show_wep_stats(keylen - 1, 0, keytable, choices, depth, tried); } if (!opt.is_quiet) show_wep_stats(keylen - 1, 1, keytable, choices, depth, tried); return 0; } /* * Guess which key bytes could be strong and start actual computation of the key */ int PTW_computeKey(PTW_attackstate * state, uint8_t * keybuf, int keylen, int testlimit, int * bf, int validchars[][n], int attacks) { REQUIRE(state != NULL); int strongbytes[KEYHSBYTES]; double normal[KEYHSBYTES]; double ausreisser[KEYHSBYTES]; doublesorthelper helper[KEYHSBYTES]; int simple, onestrong, twostrong; int i, j; #ifdef USE_AMD64_RC4_OPTIMIZED /* * The 64-bit SSE2-optimized rc4test() requires this buffer to be * aligned at 3 bytes. */ uint8_t fullkeybuf_unaligned[PTW_KSBYTES + 13] __attribute__((aligned(16))); uint8_t * fullkeybuf = &fullkeybuf_unaligned[13]; #else uint8_t fullkeybuf[PTW_KSBYTES]; #endif uint8_t guessbuf[PTW_KSBYTES]; sorthelper(*sh)[n - 1]; PTW_tableentry(*table)[n] = alloca(sizeof(PTW_tableentry) * n * keylen); ALLEGE(table != NULL); #ifdef USE_AMD64_RC4_OPTIMIZED /* * sse2-optimized rc4test() function for amd64 only works * for keylen == 5 or keylen == 13 */ if (keylen == 5 || keylen == 13) state->rc4test = rc4test_amd64_sse2; else #endif state->rc4test = rc4test; tried = 0; sh = NULL; if (!(attacks & NO_KLEIN)) { // Try the original klein attack first for (i = 0; i < keylen; i++) { memset(&table[i][0], 0, sizeof(PTW_tableentry) * n); for (j = 0; j < n; j++) { table[i][j].b = j; } for (j = 0; j < state->packets_collected; j++) { // fullkeybuf[0] = state->allsessions[j].iv[0]; memcpy( fullkeybuf, state->allsessions[j].iv, 3 * sizeof(uint8_t)); guesskeybytes(i + 3, fullkeybuf, state->allsessions[j].keystream, guessbuf, 1); table[i][guessbuf[0]].votes += state->allsessions[j].weight; } qsort(&table[i][0], n, sizeof(PTW_tableentry), &compare); j = 0; while (!validchars[i][table[i][j].b]) { j++; } // printf("guessing i = %d, b = %d\n", i, table[0][0].b); fullkeybuf[i + 3] = table[i][j].b; } if (correct(state, &fullkeybuf[3], keylen)) { memcpy(keybuf, &fullkeybuf[3], keylen * sizeof(uint8_t)); // printf("hit without correction\n"); return (FAILURE); } } if (!(attacks & NO_PTW)) { memcpy(table, state->table, sizeof(PTW_tableentry) * n * keylen); onestrong = (testlimit / 10) * 2; twostrong = (testlimit / 10) * 1; simple = testlimit - onestrong - twostrong; // now, sort the table for (i = 0; i < keylen; i++) { qsort(&table[i][0], n, sizeof(PTW_tableentry), &compare); strongbytes[i] = 0; } sh = alloca(sizeof(sorthelper) * (n - 1) * keylen); ALLEGE(sh != NULL); for (i = 0; i < keylen; i++) { for (j = 1; j < n; j++) { sh[i][j - 1].distance = table[i][0].votes - table[i][j].votes; sh[i][j - 1].value = table[i][j].b; sh[i][j - 1].keybyte = i; } } qsort(sh, (n - 1) * keylen, sizeof(sorthelper), &comparesorthelper); if (doComputation(state, keybuf, keylen, table, (sorthelper *) sh, strongbytes, simple, bf, validchars)) { return (FAILURE); } // Now one strong byte getdrv(state->table, keylen, normal, ausreisser); for (i = 0; i < keylen - 1; i++) { helper[i].keybyte = i + 1; helper[i].difference = normal[i + 1] - ausreisser[i + 1]; } qsort(helper, keylen - 1, sizeof(doublesorthelper), &comparedoublesorthelper); // do not use bf-bytes as strongbytes i = 0; while (bf[helper[i].keybyte] == 1) { i++; } strongbytes[helper[i].keybyte] = 1; if (doComputation(state, keybuf, keylen, table, (sorthelper *) sh, strongbytes, onestrong, bf, validchars)) { return (FAILURE); } // two strong bytes i++; while (bf[helper[i].keybyte] == 1) { i++; } strongbytes[helper[i].keybyte] = 1; if (doComputation(state, keybuf, keylen, table, (sorthelper *) sh, strongbytes, twostrong, bf, validchars)) { return (FAILURE); } } return (SUCCESS); } /* * Add a new session to the attack * state - state of attack * iv - IV used in the session * keystream - recovered keystream from the session */ int PTW_addsession(PTW_attackstate * state, uint8_t * iv, uint8_t * keystream, int * weight, int total) { REQUIRE(state != NULL); REQUIRE(iv != NULL); REQUIRE(keystream != NULL); REQUIRE(weight != NULL); int i, j; int il; int ir; uint8_t buf[PTW_KEYHSBYTES]; i = (iv[0] << 16) | (iv[1] << 8) | (iv[2]); il = i / 8; ir = 1 << (i % 8); if ((state->seen_iv[il] & ir) == 0) { state->seen_iv[il] |= ir; for (j = 0; j < total; j++) { state->packets_collected++; guesskeybytes( IVBYTES, iv, &keystream[KSBYTES * j], buf, PTW_KEYHSBYTES); for (i = 0; i < KEYHSBYTES; i++) { state->table[i][buf[i]].votes += weight[j]; } if (state->allsessions_size < state->packets_collected) { state->allsessions_size = state->allsessions_size << 1; PTW_session * tmp_allsessions = realloc(state->allsessions, state->allsessions_size * sizeof(PTW_session)); ALLEGE(tmp_allsessions != NULL); state->allsessions = tmp_allsessions; } memcpy(state->allsessions[state->packets_collected - 1].iv, iv, IVBYTES); memcpy(state->allsessions[state->packets_collected - 1].keystream, &keystream[KSBYTES * j], KSBYTES); state->allsessions[state->packets_collected - 1].weight = weight[j]; } if ((state->sessions_collected < CONTROLSESSIONS)) { memcpy(state->sessions[state->sessions_collected].iv, iv, IVBYTES); memcpy(state->sessions[state->sessions_collected].keystream, keystream, KSBYTES); state->sessions_collected++; } return (FAILURE); } else { return (SUCCESS); } } /* * Allocate a new attackstate */ PTW_attackstate * PTW_newattackstate(void) { int i, k; PTW_attackstate * state = NULL; state = malloc(sizeof(PTW_attackstate)); ALLEGE(state != NULL); memset(state, 0, sizeof(PTW_attackstate)); for (i = 0; i < PTW_KEYHSBYTES; i++) { for (k = 0; k < n; k++) { state->table[i][k].b = k; } } state->allsessions = malloc(4096 * sizeof(PTW_session)); ALLEGE(state->allsessions != NULL); state->allsessions_size = 4096; return state; } /* * Free an allocated attackstate */ void PTW_freeattackstate(PTW_attackstate * state) { free(state->allsessions); free(state); return; }
Text
aircrack-ng/lib/radiotap/CMakeLists.txt
cmake_minimum_required(VERSION 2.6) project(radiotap) add_definitions("-D_BSD_SOURCE -DRADIOTAP_SUPPORT_OVERRIDES") add_library(radiotap SHARED radiotap.c) set_target_properties(radiotap PROPERTIES COMPILE_FLAGS "-Wall -Wextra") install(TARGETS radiotap DESTINATION lib) install(FILES radiotap.h radiotap_iter.h DESTINATION include) add_executable(parse parse.c) set_target_properties(parse PROPERTIES COMPILE_FLAGS "-Wall -Wextra") target_link_libraries(parse radiotap) add_custom_target(radiotap_check ALL COMMAND ${CMAKE_SOURCE_DIR}/check/check.sh ${CMAKE_BINARY_DIR} DEPENDS ${CMAKE_SOURCE_DIR}/check/* WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/check/ COMMENT "Check examples") add_dependencies(radiotap_check parse)
aircrack-ng/lib/radiotap/COPYING
Copyright (c) 2007-2009 Andy Green <[email protected]> Copyright (c) 2007-2009 Johannes Berg <[email protected]> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
C
aircrack-ng/lib/radiotap/parse.c
#include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <errno.h> #include <string.h> #if defined(__APPLE__) #include <machine/endian.h> #else #include <endian.h> #endif #include "radiotap_iter.h" static int fcshdr = 0; static const struct radiotap_align_size align_size_000000_00[] = { [0] = { .align = 1, .size = 4, }, [52] = { .align = 1, .size = 4, }, }; static const struct ieee80211_radiotap_namespace vns_array[] = { { .oui = 0x000000, .subns = 0, .n_bits = sizeof(align_size_000000_00), .align_size = align_size_000000_00, }, }; static const struct ieee80211_radiotap_vendor_namespaces vns = { .ns = vns_array, .n_ns = sizeof(vns_array)/sizeof(vns_array[0]), }; static void print_radiotap_namespace(struct ieee80211_radiotap_iterator *iter) { switch (iter->this_arg_index) { case IEEE80211_RADIOTAP_TSFT: printf("\tTSFT: %llu\n", le64toh(*(unsigned long long *)iter->this_arg)); break; case IEEE80211_RADIOTAP_FLAGS: printf("\tflags: %02x\n", *iter->this_arg); break; case IEEE80211_RADIOTAP_RATE: printf("\trate: %lf\n", (double)*iter->this_arg/2); break; case IEEE80211_RADIOTAP_CHANNEL: case IEEE80211_RADIOTAP_FHSS: case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: case IEEE80211_RADIOTAP_DBM_ANTNOISE: case IEEE80211_RADIOTAP_LOCK_QUALITY: case IEEE80211_RADIOTAP_TX_ATTENUATION: case IEEE80211_RADIOTAP_DB_TX_ATTENUATION: case IEEE80211_RADIOTAP_DBM_TX_POWER: case IEEE80211_RADIOTAP_ANTENNA: case IEEE80211_RADIOTAP_DB_ANTSIGNAL: case IEEE80211_RADIOTAP_DB_ANTNOISE: case IEEE80211_RADIOTAP_TX_FLAGS: break; case IEEE80211_RADIOTAP_RX_FLAGS: if (fcshdr) { printf("\tFCS in header: %.8x\n", le32toh(*(uint32_t *)iter->this_arg)); break; } printf("\tRX flags: %#.4x\n", le16toh(*(uint16_t *)iter->this_arg)); break; case IEEE80211_RADIOTAP_RTS_RETRIES: case IEEE80211_RADIOTAP_DATA_RETRIES: break; default: printf("\tBOGUS DATA\n"); break; } } static void print_test_namespace(struct ieee80211_radiotap_iterator *iter) { switch (iter->this_arg_index) { case 0: case 52: printf("\t00:00:00-00|%d: %.2x/%.2x/%.2x/%.2x\n", iter->this_arg_index, *iter->this_arg, *(iter->this_arg + 1), *(iter->this_arg + 2), *(iter->this_arg + 3)); break; default: printf("\tBOGUS DATA - vendor ns %d\n", iter->this_arg_index); break; } } static const struct radiotap_override overrides[] = { { .field = 14, .align = 4, .size = 4, } }; int main(int argc, char *argv[]) { struct ieee80211_radiotap_iterator iter; struct stat statbuf; int fd, err, fnidx = 1, i; void *data; if (argc != 2 && argc != 3) { fprintf(stderr, "usage: parse [--fcshdr] <file>\n"); fprintf(stderr, " --fcshdr: read bit 14 as FCS\n"); return 2; } if (strcmp(argv[1], "--fcshdr") == 0) { fcshdr = 1; fnidx++; } fd = open(argv[fnidx], O_RDONLY); if (fd < 0) { fprintf(stderr, "cannot open file %s\n", argv[fnidx]); return 2; } if (fstat(fd, &statbuf)) { perror("fstat"); return 2; } data = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); err = ieee80211_radiotap_iterator_init(&iter, data, statbuf.st_size, &vns); if (err) { printf("malformed radiotap header (init returns %d)\n", err); return 3; } if (fcshdr) { iter.overrides = overrides; iter.n_overrides = sizeof(overrides)/sizeof(overrides[0]); } while (!(err = ieee80211_radiotap_iterator_next(&iter))) { if (iter.this_arg_index == IEEE80211_RADIOTAP_VENDOR_NAMESPACE) { printf("\tvendor NS (%.2x-%.2x-%.2x:%d, %d bytes)\n", iter.this_arg[0], iter.this_arg[1], iter.this_arg[2], iter.this_arg[3], iter.this_arg_size - 6); for (i = 6; i < iter.this_arg_size; i++) { if (i % 8 == 6) printf("\t\t"); else printf(" "); printf("%.2x", iter.this_arg[i]); } printf("\n"); } else if (iter.is_radiotap_ns) print_radiotap_namespace(&iter); else if (iter.current_namespace == &vns_array[0]) print_test_namespace(&iter); } if (err != -ENOENT) { printf("malformed radiotap data\n"); return 3; } return 0; }
C/C++
aircrack-ng/lib/radiotap/platform.h
#include <stddef.h> #include <errno.h> #include <string.h> #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) \ || defined(__gnu_linux__) #include <endian.h> #if defined(__UCLIBC__) #include <asm/byteorder.h> #ifndef le16toh #define le16toh __le16_to_cpu #endif #ifndef le32toh #define le32toh __le32_to_cpu #endif #endif #endif #if defined(__CYGWIN32__) || defined(CYGWIN) #include <asm/byteorder.h> #include <endian.h> #endif #if defined(__APPLE__) #include <machine/endian.h> #endif #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__MidnightBSD__) || defined(__NetBSD__) #include <sys/endian.h> #include <sys/types.h> #endif #if defined(__SVR4) && defined(__sun__) #include <sys/byteorder.h> #include <sys/types.h> #endif #ifndef le16_to_cpu #define le16_to_cpu le16toh #endif #ifndef le32_to_cpu #define le32_to_cpu le32toh #endif #if defined(_MSC_VER) // Microsoft #define EXPORT __declspec(dllexport) #define IMPORT __declspec(dllimport) #elif defined(__GNUC__) || defined(__llvm__) || defined(__clang__) || defined(__INTEL_COMPILER) #define EXPORT __attribute__((visibility("default"))) #define IMPORT #else // do nothing and hope for the best? #define EXPORT #define IMPORT #pragma warning Unknown dynamic link import/export semantics. #endif #if defined(RADIOTAP_FAST_UNALIGNED_ACCESS) #define get_unaligned(p) \ __extension__({ \ struct packed_dummy_struct { \ typeof(*(p)) __val; \ } __attribute__((packed)) *__ptr = (void *) (p); \ \ __ptr->__val; \ }) #else #define get_unaligned(p) \ __extension__({ \ typeof(*(p)) __tmp; \ memmove(&__tmp, (p), sizeof(*(p))); \ __tmp; \ }) #endif #define get_unaligned_le16(p) le16_to_cpu(get_unaligned((uint16_t *)(p))) #define get_unaligned_le32(p) le32_to_cpu(get_unaligned((uint32_t *)(p))) #define UNALIGNED_ADDRESS(x) ((void*)(x))
C
aircrack-ng/lib/radiotap/radiotap.c
/* * Radiotap parser * * Copyright 2007 Andy Green <[email protected]> * Copyright 2009 Johannes Berg <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Alternatively, this software may be distributed under the terms of ISC * license, see COPYING for more details. */ #include "radiotap_iter.h" #include "platform.h" /* function prototypes and related defs are in radiotap_iter.h */ static const struct radiotap_align_size rtap_namespace_sizes[] = { [IEEE80211_RADIOTAP_TSFT] = { .align = 8, .size = 8, }, [IEEE80211_RADIOTAP_FLAGS] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_RATE] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_CHANNEL] = { .align = 2, .size = 4, }, [IEEE80211_RADIOTAP_FHSS] = { .align = 2, .size = 2, }, [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_DBM_ANTNOISE] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_LOCK_QUALITY] = { .align = 2, .size = 2, }, [IEEE80211_RADIOTAP_TX_ATTENUATION] = { .align = 2, .size = 2, }, [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = { .align = 2, .size = 2, }, [IEEE80211_RADIOTAP_DBM_TX_POWER] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_ANTENNA] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_DB_ANTNOISE] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_RX_FLAGS] = { .align = 2, .size = 2, }, [IEEE80211_RADIOTAP_TX_FLAGS] = { .align = 2, .size = 2, }, [IEEE80211_RADIOTAP_RTS_RETRIES] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_DATA_RETRIES] = { .align = 1, .size = 1, }, [IEEE80211_RADIOTAP_MCS] = { .align = 1, .size = 3, }, [IEEE80211_RADIOTAP_AMPDU_STATUS] = { .align = 4, .size = 8, }, [IEEE80211_RADIOTAP_VHT] = { .align = 2, .size = 12, }, [IEEE80211_RADIOTAP_TIMESTAMP] = { .align = 8, .size = 12, }, /* * add more here as they are defined in radiotap.h */ }; static const struct ieee80211_radiotap_namespace radiotap_ns = { .n_bits = sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]), .align_size = rtap_namespace_sizes, }; /** * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization * @iterator: radiotap_iterator to initialize * @radiotap_header: radiotap header to parse * @max_length: total length we can parse into (eg, whole packet length) * * Returns: 0 or a negative error code if there is a problem. * * This function initializes an opaque iterator struct which can then * be passed to ieee80211_radiotap_iterator_next() to visit every radiotap * argument which is present in the header. It knows about extended * present headers and handles them. * * How to use: * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator * struct ieee80211_radiotap_iterator (no need to init the struct beforehand) * checking for a good 0 return code. Then loop calling * __ieee80211_radiotap_iterator_next()... it returns either 0, * -ENOENT if there are no more args to parse, or -EINVAL if there is a problem. * The iterator's @this_arg member points to the start of the argument * associated with the current argument index that is present, which can be * found in the iterator's @this_arg_index member. This arg index corresponds * to the IEEE80211_RADIOTAP_... defines. * * Radiotap header length: * You can find the CPU-endian total radiotap header length in * iterator->max_length after executing ieee80211_radiotap_iterator_init() * successfully. * * Alignment Gotcha: * You must take care when dereferencing iterator.this_arg * for multibyte types... the pointer is not aligned. Use * get_unaligned((type *)iterator.this_arg) to dereference * iterator.this_arg for type "type" safely on all arches. * * Example code: parse.c */ EXPORT int ieee80211_radiotap_iterator_init( struct ieee80211_radiotap_iterator *iterator, struct ieee80211_radiotap_header *radiotap_header, int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns) { /* must at least have the radiotap header */ if (max_length < (int)sizeof(struct ieee80211_radiotap_header)) return -EINVAL; /* Linux only supports version 0 radiotap format */ if (radiotap_header->it_version) return -EINVAL; /* sanity check for allowed length and radiotap length field */ if (max_length < get_unaligned_le16(UNALIGNED_ADDRESS(&radiotap_header->it_len))) return -EINVAL; iterator->_rtheader = radiotap_header; iterator->_max_length = get_unaligned_le16(UNALIGNED_ADDRESS(&radiotap_header->it_len)); iterator->_arg_index = 0; iterator->_bitmap_shifter = get_unaligned_le32(UNALIGNED_ADDRESS(&radiotap_header->it_present)); iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header); iterator->_reset_on_ext = 0; #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Waddress-of-packed-member" #endif iterator->_next_bitmap = UNALIGNED_ADDRESS(&radiotap_header->it_present); #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9 #pragma GCC diagnostic pop #endif iterator->_next_bitmap++; iterator->_vns = vns; iterator->current_namespace = &radiotap_ns; iterator->is_radiotap_ns = 1; #ifdef RADIOTAP_SUPPORT_OVERRIDES iterator->n_overrides = 0; iterator->overrides = NULL; #endif /* find payload start allowing for extended bitmap(s) */ if (iterator->_bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT)) { if ((unsigned long)iterator->_arg - (unsigned long)iterator->_rtheader + sizeof(uint32_t) > (unsigned long)iterator->_max_length) return -EINVAL; while (get_unaligned_le32(iterator->_arg) & (1 << IEEE80211_RADIOTAP_EXT)) { iterator->_arg += sizeof(uint32_t); /* * check for insanity where the present bitmaps * keep claiming to extend up to or even beyond the * stated radiotap header length */ if ((unsigned long)iterator->_arg - (unsigned long)iterator->_rtheader + sizeof(uint32_t) > (unsigned long)iterator->_max_length) return -EINVAL; } iterator->_arg += sizeof(uint32_t); /* * no need to check again for blowing past stated radiotap * header length, because ieee80211_radiotap_iterator_next * checks it before it is dereferenced */ } iterator->this_arg = iterator->_arg; /* we are all initialized happily */ return 0; } static void find_ns(struct ieee80211_radiotap_iterator *iterator, uint32_t oui, uint8_t subns) { int i; iterator->current_namespace = NULL; if (!iterator->_vns) return; for (i = 0; i < iterator->_vns->n_ns; i++) { if (iterator->_vns->ns[i].oui != oui) continue; if (iterator->_vns->ns[i].subns != subns) continue; iterator->current_namespace = &iterator->_vns->ns[i]; break; } } #ifdef RADIOTAP_SUPPORT_OVERRIDES static int find_override(struct ieee80211_radiotap_iterator *iterator, int *align, int *size) { int i; if (!iterator->overrides) return 0; for (i = 0; i < iterator->n_overrides; i++) { if (iterator->_arg_index == iterator->overrides[i].field) { *align = iterator->overrides[i].align; *size = iterator->overrides[i].size; if (!*align) /* erroneous override */ return 0; return 1; } } return 0; } #endif /** * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg * @iterator: radiotap_iterator to move to next arg (if any) * * Returns: 0 if there is an argument to handle, * -ENOENT if there are no more args or -EINVAL * if there is something else wrong. * * This function provides the next radiotap arg index (IEEE80211_RADIOTAP_*) * in @this_arg_index and sets @this_arg to point to the * payload for the field. It takes care of alignment handling and extended * present fields. @this_arg can be changed by the caller (eg, * incremented to move inside a compound argument like * IEEE80211_RADIOTAP_CHANNEL). The args pointed to are in * little-endian format whatever the endianness of your CPU. * * Alignment Gotcha: * You must take care when dereferencing iterator.this_arg * for multibyte types... the pointer is not aligned. Use * get_unaligned((type *)iterator.this_arg) to dereference * iterator.this_arg for type "type" safely on all arches. */ EXPORT int ieee80211_radiotap_iterator_next( struct ieee80211_radiotap_iterator *iterator) { while (1) { int hit = 0; int pad, align, size, subns; uint32_t oui; /* if no more EXT bits, that's it */ if ((iterator->_arg_index % 32) == IEEE80211_RADIOTAP_EXT && !(iterator->_bitmap_shifter & 1)) return -ENOENT; if (!(iterator->_bitmap_shifter & 1)) goto next_entry; /* arg not present */ /* get alignment/size of data */ switch (iterator->_arg_index % 32) { case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE: case IEEE80211_RADIOTAP_EXT: align = 1; size = 0; break; case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: align = 2; size = 6; break; default: #ifdef RADIOTAP_SUPPORT_OVERRIDES if (find_override(iterator, &align, &size)) { /* all set */ } else #endif if (!iterator->current_namespace || iterator->_arg_index >= iterator->current_namespace->n_bits) { if (iterator->current_namespace == &radiotap_ns) return -ENOENT; align = 0; } else { align = iterator->current_namespace->align_size[iterator->_arg_index].align; size = iterator->current_namespace->align_size[iterator->_arg_index].size; } if (!align) { /* skip all subsequent data */ iterator->_arg = iterator->_next_ns_data; /* give up on this namespace */ iterator->current_namespace = NULL; goto next_entry; } break; } /* * arg is present, account for alignment padding * * Note that these alignments are relative to the start * of the radiotap header. There is no guarantee * that the radiotap header itself is aligned on any * kind of boundary. * * The above is why get_unaligned() is used to dereference * multibyte elements from the radiotap area. */ pad = ((unsigned long)iterator->_arg - (unsigned long)iterator->_rtheader) & (align - 1); if (pad) iterator->_arg += align - pad; if (iterator->_arg_index % 32 == IEEE80211_RADIOTAP_VENDOR_NAMESPACE) { int vnslen; if ((unsigned long)iterator->_arg + size - (unsigned long)iterator->_rtheader > (unsigned long)iterator->_max_length) return -EINVAL; oui = (*iterator->_arg << 16) | (*(iterator->_arg + 1) << 8) | *(iterator->_arg + 2); subns = *(iterator->_arg + 3); find_ns(iterator, oui, subns); vnslen = get_unaligned_le16(iterator->_arg + 4); iterator->_next_ns_data = iterator->_arg + size + vnslen; if (!iterator->current_namespace) size += vnslen; } /* * this is what we will return to user, but we need to * move on first so next call has something fresh to test */ iterator->this_arg_index = iterator->_arg_index; iterator->this_arg = iterator->_arg; iterator->this_arg_size = size; /* internally move on the size of this arg */ iterator->_arg += size; /* * check for insanity where we are given a bitmap that * claims to have more arg content than the length of the * radiotap section. We will normally end up equalling this * max_length on the last arg, never exceeding it. */ if ((unsigned long)iterator->_arg - (unsigned long)iterator->_rtheader > (unsigned long)iterator->_max_length) return -EINVAL; /* these special ones are valid in each bitmap word */ switch (iterator->_arg_index % 32) { case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: iterator->_reset_on_ext = 1; iterator->is_radiotap_ns = 0; /* * If parser didn't register this vendor * namespace with us, allow it to show it * as 'raw. Do do that, set argument index * to vendor namespace. */ iterator->this_arg_index = IEEE80211_RADIOTAP_VENDOR_NAMESPACE; if (!iterator->current_namespace) hit = 1; goto next_entry; case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE: iterator->_reset_on_ext = 1; iterator->current_namespace = &radiotap_ns; iterator->is_radiotap_ns = 1; goto next_entry; case IEEE80211_RADIOTAP_EXT: /* * bit 31 was set, there is more * -- move to next u32 bitmap */ iterator->_bitmap_shifter = get_unaligned_le32(iterator->_next_bitmap); iterator->_next_bitmap++; if (iterator->_reset_on_ext) iterator->_arg_index = 0; else iterator->_arg_index++; iterator->_reset_on_ext = 0; break; default: /* we've got a hit! */ hit = 1; next_entry: iterator->_bitmap_shifter >>= 1; iterator->_arg_index++; } /* if we found a valid arg earlier, return it now */ if (hit) return 0; } }
C/C++
aircrack-ng/lib/radiotap/radiotap.h
/* * Copyright (c) 2017 Intel Deutschland GmbH * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __RADIOTAP_H #define __RADIOTAP_H #if defined(__APPLE__) #include <libkern/OSByteOrder.h> #define bswap_16 OSSwapInt16 #define bswap_32 OSSwapInt32 #define bswap_64 OSSwapInt64 #include <machine/endian.h> #ifndef le16toh #define le16toh(x) OSSwapLittleToHostInt16(x) #endif #ifndef le32toh #define le32toh(x) OSSwapLittleToHostInt32(x) #endif #ifndef le64toh #define le64toh(x) OSSwapLittleToHostInt64(x) #endif #endif /** * struct ieee82011_radiotap_header - base radiotap header */ struct ieee80211_radiotap_header { /** * @it_version: radiotap version, always 0 */ uint8_t it_version; /** * @it_pad: padding (or alignment) */ uint8_t it_pad; /** * @it_len: overall radiotap header length */ uint16_t it_len; /** * @it_present: (first) present word */ uint32_t it_present; } __attribute__((__packed__)); /* version is always 0 */ #define PKTHDR_RADIOTAP_VERSION 0 /* see the radiotap website for the descriptions */ enum ieee80211_radiotap_presence { IEEE80211_RADIOTAP_TSFT = 0, IEEE80211_RADIOTAP_FLAGS = 1, IEEE80211_RADIOTAP_RATE = 2, IEEE80211_RADIOTAP_CHANNEL = 3, IEEE80211_RADIOTAP_FHSS = 4, IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, IEEE80211_RADIOTAP_LOCK_QUALITY = 7, IEEE80211_RADIOTAP_TX_ATTENUATION = 8, IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, IEEE80211_RADIOTAP_DBM_TX_POWER = 10, IEEE80211_RADIOTAP_ANTENNA = 11, IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, IEEE80211_RADIOTAP_DB_ANTNOISE = 13, IEEE80211_RADIOTAP_RX_FLAGS = 14, IEEE80211_RADIOTAP_TX_FLAGS = 15, IEEE80211_RADIOTAP_RTS_RETRIES = 16, IEEE80211_RADIOTAP_DATA_RETRIES = 17, /* 18 is XChannel, but it's not defined yet */ IEEE80211_RADIOTAP_MCS = 19, IEEE80211_RADIOTAP_AMPDU_STATUS = 20, IEEE80211_RADIOTAP_VHT = 21, IEEE80211_RADIOTAP_TIMESTAMP = 22, /* valid in every it_present bitmap, even vendor namespaces */ IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29, IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30, IEEE80211_RADIOTAP_EXT = 31 }; /* for IEEE80211_RADIOTAP_FLAGS */ enum ieee80211_radiotap_flags { IEEE80211_RADIOTAP_F_CFP = 0x01, IEEE80211_RADIOTAP_F_SHORTPRE = 0x02, IEEE80211_RADIOTAP_F_WEP = 0x04, IEEE80211_RADIOTAP_F_FRAG = 0x08, IEEE80211_RADIOTAP_F_FCS = 0x10, IEEE80211_RADIOTAP_F_DATAPAD = 0x20, IEEE80211_RADIOTAP_F_BADFCS = 0x40, }; /* for IEEE80211_RADIOTAP_CHANNEL */ enum ieee80211_radiotap_channel_flags { IEEE80211_CHAN_CCK = 0x0020, IEEE80211_CHAN_OFDM = 0x0040, IEEE80211_CHAN_2GHZ = 0x0080, IEEE80211_CHAN_5GHZ = 0x0100, IEEE80211_CHAN_DYN = 0x0400, IEEE80211_CHAN_HALF = 0x4000, IEEE80211_CHAN_QUARTER = 0x8000, }; /* for IEEE80211_RADIOTAP_RX_FLAGS */ enum ieee80211_radiotap_rx_flags { IEEE80211_RADIOTAP_F_RX_BADPLCP = 0x0002, }; /* for IEEE80211_RADIOTAP_TX_FLAGS */ enum ieee80211_radiotap_tx_flags { IEEE80211_RADIOTAP_F_TX_FAIL = 0x0001, IEEE80211_RADIOTAP_F_TX_CTS = 0x0002, IEEE80211_RADIOTAP_F_TX_RTS = 0x0004, IEEE80211_RADIOTAP_F_TX_NOACK = 0x0008, }; /* for IEEE80211_RADIOTAP_MCS "have" flags */ enum ieee80211_radiotap_mcs_have { IEEE80211_RADIOTAP_MCS_HAVE_BW = 0x01, IEEE80211_RADIOTAP_MCS_HAVE_MCS = 0x02, IEEE80211_RADIOTAP_MCS_HAVE_GI = 0x04, IEEE80211_RADIOTAP_MCS_HAVE_FMT = 0x08, IEEE80211_RADIOTAP_MCS_HAVE_FEC = 0x10, IEEE80211_RADIOTAP_MCS_HAVE_STBC = 0x20, }; enum ieee80211_radiotap_mcs_flags { IEEE80211_RADIOTAP_MCS_BW_MASK = 0x03, IEEE80211_RADIOTAP_MCS_BW_20 = 0, IEEE80211_RADIOTAP_MCS_BW_40 = 1, IEEE80211_RADIOTAP_MCS_BW_20L = 2, IEEE80211_RADIOTAP_MCS_BW_20U = 3, IEEE80211_RADIOTAP_MCS_SGI = 0x04, IEEE80211_RADIOTAP_MCS_FMT_GF = 0x08, IEEE80211_RADIOTAP_MCS_FEC_LDPC = 0x10, IEEE80211_RADIOTAP_MCS_STBC_MASK = 0x60, IEEE80211_RADIOTAP_MCS_STBC_1 = 1, IEEE80211_RADIOTAP_MCS_STBC_2 = 2, IEEE80211_RADIOTAP_MCS_STBC_3 = 3, IEEE80211_RADIOTAP_MCS_STBC_SHIFT = 5, }; /* for IEEE80211_RADIOTAP_AMPDU_STATUS */ enum ieee80211_radiotap_ampdu_flags { IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN = 0x0001, IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN = 0x0002, IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN = 0x0004, IEEE80211_RADIOTAP_AMPDU_IS_LAST = 0x0008, IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR = 0x0010, IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN = 0x0020, }; /* for IEEE80211_RADIOTAP_VHT */ enum ieee80211_radiotap_vht_known { IEEE80211_RADIOTAP_VHT_KNOWN_STBC = 0x0001, IEEE80211_RADIOTAP_VHT_KNOWN_TXOP_PS_NA = 0x0002, IEEE80211_RADIOTAP_VHT_KNOWN_GI = 0x0004, IEEE80211_RADIOTAP_VHT_KNOWN_SGI_NSYM_DIS = 0x0008, IEEE80211_RADIOTAP_VHT_KNOWN_LDPC_EXTRA_OFDM_SYM = 0x0010, IEEE80211_RADIOTAP_VHT_KNOWN_BEAMFORMED = 0x0020, IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH = 0x0040, IEEE80211_RADIOTAP_VHT_KNOWN_GROUP_ID = 0x0080, IEEE80211_RADIOTAP_VHT_KNOWN_PARTIAL_AID = 0x0100, }; enum ieee80211_radiotap_vht_flags { IEEE80211_RADIOTAP_VHT_FLAG_STBC = 0x01, IEEE80211_RADIOTAP_VHT_FLAG_TXOP_PS_NA = 0x02, IEEE80211_RADIOTAP_VHT_FLAG_SGI = 0x04, IEEE80211_RADIOTAP_VHT_FLAG_SGI_NSYM_M10_9 = 0x08, IEEE80211_RADIOTAP_VHT_FLAG_LDPC_EXTRA_OFDM_SYM = 0x10, IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED = 0x20, }; enum ieee80211_radiotap_vht_coding { IEEE80211_RADIOTAP_CODING_LDPC_USER0 = 0x01, IEEE80211_RADIOTAP_CODING_LDPC_USER1 = 0x02, IEEE80211_RADIOTAP_CODING_LDPC_USER2 = 0x04, IEEE80211_RADIOTAP_CODING_LDPC_USER3 = 0x08, }; /* for IEEE80211_RADIOTAP_TIMESTAMP */ enum ieee80211_radiotap_timestamp_unit_spos { IEEE80211_RADIOTAP_TIMESTAMP_UNIT_MASK = 0x000F, IEEE80211_RADIOTAP_TIMESTAMP_UNIT_MS = 0x0000, IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US = 0x0001, IEEE80211_RADIOTAP_TIMESTAMP_UNIT_NS = 0x0003, IEEE80211_RADIOTAP_TIMESTAMP_SPOS_MASK = 0x00F0, IEEE80211_RADIOTAP_TIMESTAMP_SPOS_BEGIN_MDPU = 0x0000, IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ = 0x0010, IEEE80211_RADIOTAP_TIMESTAMP_SPOS_EO_PPDU = 0x0020, IEEE80211_RADIOTAP_TIMESTAMP_SPOS_EO_MPDU = 0x0030, IEEE80211_RADIOTAP_TIMESTAMP_SPOS_UNKNOWN = 0x00F0, }; enum ieee80211_radiotap_timestamp_flags { IEEE80211_RADIOTAP_TIMESTAMP_FLAG_64BIT = 0x00, IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT = 0x01, IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY = 0x02, }; #endif /* __RADIOTAP_H */
C/C++
aircrack-ng/lib/radiotap/radiotap_iter.h
#ifndef __RADIOTAP_ITER_H #define __RADIOTAP_ITER_H #include <stdint.h> #include "radiotap.h" #include "platform.h" /* Radiotap header iteration * implemented in radiotap.c */ struct radiotap_override { uint8_t field; uint8_t align:4, size:4; }; struct radiotap_align_size { uint8_t align:4, size:4; }; struct ieee80211_radiotap_namespace { const struct radiotap_align_size *align_size; int n_bits; uint32_t oui; uint8_t subns; }; struct ieee80211_radiotap_vendor_namespaces { const struct ieee80211_radiotap_namespace *ns; int n_ns; }; /** * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args * @this_arg_index: index of current arg, valid after each successful call * to ieee80211_radiotap_iterator_next() * @this_arg: pointer to current radiotap arg; it is valid after each * call to ieee80211_radiotap_iterator_next() but also after * ieee80211_radiotap_iterator_init() where it will point to * the beginning of the actual data portion * @this_arg_size: length of the current arg, for convenience * @current_namespace: pointer to the current namespace definition * (or internally %NULL if the current namespace is unknown) * @is_radiotap_ns: indicates whether the current namespace is the default * radiotap namespace or not * * @overrides: override standard radiotap fields * @n_overrides: number of overrides * * @_rtheader: pointer to the radiotap header we are walking through * @_max_length: length of radiotap header in cpu byte ordering * @_arg_index: next argument index * @_arg: next argument pointer * @_next_bitmap: internal pointer to next present u32 * @_bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present * @_vns: vendor namespace definitions * @_next_ns_data: beginning of the next namespace's data * @_reset_on_ext: internal; reset the arg index to 0 when going to the * next bitmap word * * Describes the radiotap parser state. Fields prefixed with an underscore * must not be used by users of the parser, only by the parser internally. */ struct ieee80211_radiotap_iterator { struct ieee80211_radiotap_header *_rtheader; const struct ieee80211_radiotap_vendor_namespaces *_vns; const struct ieee80211_radiotap_namespace *current_namespace; unsigned char *_arg, *_next_ns_data; uint32_t *_next_bitmap; unsigned char *this_arg; const struct radiotap_override *overrides; /* Only for RADIOTAP_SUPPORT_OVERRIDES */ int n_overrides; /* Only for RADIOTAP_SUPPORT_OVERRIDES */ int this_arg_index; int this_arg_size; int is_radiotap_ns; int _max_length; int _arg_index; uint32_t _bitmap_shifter; int _reset_on_ext; }; #ifdef __cplusplus #define CALLING_CONVENTION "C" #else #define CALLING_CONVENTION #endif IMPORT extern CALLING_CONVENTION int ieee80211_radiotap_iterator_init( struct ieee80211_radiotap_iterator *iterator, struct ieee80211_radiotap_header *radiotap_header, int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns); IMPORT extern CALLING_CONVENTION int ieee80211_radiotap_iterator_next( struct ieee80211_radiotap_iterator *iterator); #endif /* __RADIOTAP_ITER_H */
aircrack-ng/lib/radiotap/check/0v0-3.out
TSFT: 9833440827789222417 vendor NS (00-00-00:1, 4 bytes) ff ee dd cc TSFT: 1225260500033256362
Shell Script
aircrack-ng/lib/radiotap/check/check.sh
#!/bin/sh bin="$1/parse" for t in *.bin ; do echo -n "Checking $t: " args="" base="$(basename "$t" .bin)" if [ -f "$base.args" ] ; then args="$(cat "$base.args")" fi "$bin" $args $t | diff "$base.out" - && echo "OK" || echo "FAIL" done
aircrack-ng/lib/radiotap/check/unparsed-vendor.out
flags: 10 rate: 1.000000 RX flags: 0000 vendor NS (ff-ff-ff:255, 2 bytes) de ad rate: 2.000000
Inno Setup Script
aircrack-ng/manpages/airbase-ng.8.in
.TH AIRBASE-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airbase-ng - multi-purpose tool aimed at attacking clients as opposed to the Access Point (AP) itself .SH SYNOPSIS .B airbase-ng [options] <interface name> .SH DESCRIPTION .BI airbase-ng is multi-purpose tool aimed at attacking clients as opposed to the Access Point (AP) itself. Since it is so versatile and flexible, summarizing it is a challenge. Here are some of the feature highlights: .PP - Implements the Caffe Latte WEP client attack .br - Implements the Hirte WEP client attack .br - Ability to cause the WPA/WPA2 handshake to be captured .br - Ability to act as an ad-hoc Access Point .br - Ability to act as a full Access Point .br - Ability to filter by SSID or client MAC addresses .br - Ability to manipulate and resend packets .br - Ability to encrypt sent packets and decrypt received packets .PP The main idea is of the implementation is that it should encourage clients to associate with the fake AP, not prevent them from accessing the real AP. A tap interface (atX) is created when airbase-ng is run. This can be used to receive decrypted packets or to send encrypted packets. As real clients will most probably send probe requests for common/configured networks, these frames are important for binding a client to our softAP. In this case, the AP will respond to any probe request with a proper probe response, which tells the client to authenticate to the airbase-ng BSSID. That being said, this mode could possibly disrupt the correct functionality of many APs on the same channel. .SH OPTIONS .PP .TP .I -H, --help Shows the help screen. .TP .I -a <bssid> If the BSSID is not explicitly specified by using "-a <BSSID>", then the current MAC of the specified interface is used. .TP .I -i <iface> Also capture and process from this interface in addition to the replay interface. .TP .I -w <WEP key> If WEP should be used as encryption, then the parameter "-w <WEP key>" sets the en-/decryption key. This is sufficient to let airbase-ng set all the appropriate flags by itself. If the softAP operates with WEP encryption, the client can choose to use open system authentication or shared key authentication. Both authentication methods are supported by airbase-ng. But to get a keystream, the user can try to force the client to use shared key authentication. "-s" forces a shared key auth and "-S <len>" sets the challenge length. .TP .I -h <MAC> This is the source MAC for the man-in-the-middle attack. The "-M" must also be specified. .TP .I -f <disallow> If this option is not specified, it defaults to "-f allow". This means the various client MAC filters (-d and -D) define which clients to accept. By using the "-f disallow" option, this reverses selection and causes airbase-ng to ignore the clients specified by the filters. .TP .I -W <0|1> This sets the beacon WEP flag. Remember that clients will normally only connect to APs which are the same as themselves. Meaning WEP to WEP, open to open. The "auto" option is to allow airbase-ng to automatically set the flag based on context of the other options specified. For example, if you set a WEP key with -w, then the beacon flag would be set to WEP. One other use of "auto" is to deal with clients which can automatically adjust their connection type. However, these are few and far between. In practice, it is best to set the value to the type of clients you are dealing with. .TP .I -q This suppresses printing any statistics or status information. .TP .I -v This prints additional messages and details to assist in debugging. .TP .I -M This option is not implemented yet. It is a man-in-the-middle attack between specified clients and BSSIDs. .TP .I -A, --ad-hoc This causes airbase-ng to act as an ad-hoc client instead of a normal Access Point. In ad-hoc mode airbase-ng also sends beacons, but doesn\(aqt need any authentication/association. It can be activated by using "-A". The soft AP will adjust all flags needed to simulate a station in ad-hoc mode automatically and generate a random MAC, which is used as CELL MAC instead of the BSSID. This can be overwritten by the "-a <BSSID>" tag. The interface MAC will then be used as source mac, which can be changed with "-h <sourceMAC>". .TP .I -Y <in|out|both> The parameter "-Y" enables the "external processing" Mode. This creates a second interface "atX", which is used to replay/modify/drop or inject packets at will. This interface must also be brought up with ifconfig and an external tool is needed to create a loop on that interface. The packet structure is rather simple: the ethernet header (14 bytes) is ignored and right after that follows the complete ieee80211 frame the same way it is going to be processed by airbase-ng (for incoming packets) or before the packets will be sent out of the wireless card (outgoing packets). This mode intercepts all data packets and loops them through an external application, which decides what happens with them. The MAC and IP of the second tap interface doesn\(aqt matter, as real ethernet frames on this interface are dropped anyway. There are 3 arguments for "-Y": "in", "out" and "both", which specify the direction of frames to loop through the external application. Obviously "in" redirects only incoming (through the wireless NIC) frames, while outgoing frames aren\(aqt touched. "out" does the opposite, it only loops outgoing packets and "both" sends all both directions through the second tap interface. There is a small and simple example application to replay all frames on the second interface. The tool is called "replay.py" and is located in "./test". It\(aqs written in python, but the language doesn\(aqt matter. It uses pcapy to read the frames and scapy to possibly alter/show and reinject the frames. The tool as it is, simply replays all frames and prints a short summary of the received frames. The variable "packet" contains the complete ieee80211 packet, which can easily be dissected and modified using scapy. This can be compared to ettercap filters, but is more powerful, as a real programming language can be used to build complex logic for filtering and packet customization. The downside on using python is, that it adds a delay of around 100ms and the cpu utilizations is rather large on a high speed network, but its perfect for a demonstration with only a few lines of code. .TP .I -c <channel> This is used to specify the channel on which to run the Access Point. .TP .I -X, --hidden This causes the Access Point to hide the SSID and to not broadcast the value. .TP .I -s When specified, this forces shared key authentication for all clients. The soft AP will send an "authentication method unsupported" rejection to any open system authentication request if "-s" is specified. .TP .I -S It sets the shared key challenge length, which can be anything from 16 to 1480. The default is 128 bytes. It is the number of bytes used in the random challenge. Since one tag can contain a maximum size of 255 bytes, any value above 255 creates several challenge tags until all specified bytes are written. Many clients ignore values different than 128 bytes so this option may not always work. .TP .I -L, --caffe-latte Airbase-ng also contains the new caffe-latte attack, which is also implemented in aireplay-ng as attack "-6". It can be used with "-L" or "caffe-latte". This attack specifically works against clients, as it waits for a broadcast arp request, which happens to be a gratuitous arp. See this for an explanation of what a gratuitous arp is. It then flips a few bits in the sender MAC and IP, corrects the ICV (crc32) value and sends it back to the client, where it came from. The point why this attack works in practice is, that at least windows sends gratuitous arps after a connection on layer 2 is established and a static ip is set, or dhcp fails and windows assigned an IP out of 169.254.X.X. "-x <pps>" sets the number of packets per second to send when performing the caffe-latte attack. At the moment, this attack doesn\(aqt stop, it continuously sends arp requests. Airodump-ng is needed to capture the replies. .TP .I -N, --cfrag This attack listens for an ARP request or IP packet from the client. Once one is received, a small amount of PRGA is extracted and then used to create an ARP request packet targeted to the client. This ARP request is actually made of up of multiple packet fragments such that when received, the client will respond. This attack works especially well against ad-hoc networks. As well it can be used against softAP clients and normal AP clients. .TP .I -x <nbpps> This sets the number of packets per second that packets will be sent (default: 100). .TP .I -y When using this option, the fake AP will not respond to broadcast probes. A broadcast probe is where the specific AP is not identified uniquely. Typically, most APs will respond with probe responses to a broadcast probe. This flag will prevent this happening. It will only respond when the specific AP is uniquely requested. .TP .I -0 This enables all WPA/WPA2/WEP Tags to be enabled in the beacons sent. It cannot be specified when also using -z or -Z. .TP .I -z <type> This specifies the WPA beacon tags. The valid values are: 1=WEP40 2=TKIP 3=WRAP 4=CCMP 5=WEP104. .TP .I -Z <type> same as -z, but for WPA2 .TP .I -V <type> This specifies the valid EAPOL types. The valid values are: 1=MD5 2=SHA1 3=auto .TP .I -F <prefix> This option causes airbase-ng to write all sent and received packets to a pcap file on disk. This is the file prefix (like airodump-ng -w). .TP .I -P This causes the fake access point to respond to all probes regardless of the ESSIDs specified. .TP .I -I <interval> This sets the time in milliseconds between each beacon. .TP .I -C <seconds> The wildcard ESSIDs will also be beaconed this number of seconds. A good typical value to use is "-C 60" (require -P). .TP .I -n <hex> ANonce (nonce from the AP) to use instead of a randomized one. It must be 64 hexadecimal characters. .PP .TP .B Filter options: .TP .I --bssid <MAC>, -b <MAC> BSSID to filter/use. .TP .I --bssids <file>, -B <file> Read a list of BSSIDs out of that file. .TP .I --client <MAC>, -d <MAC> MAC of client to accept. .TP .I --clients <file>, -D <file> Read a list of client\(aqs MACs out of that file. .TP .I --essid <ESSID>, -e <ESSID> Specify a single ESSID. For SSID containing special characters, see https://www.aircrack-ng.org/doku.php?id=faq#how_to_use_spaces_double_quote_and_single_quote_etc_in_ap_names .TP .I --essids <file>, -E <file> Read a list of ESSIDs out of that file. It will use the same BSSID for all AP which can generate some interesting output in Airodump-ng like: http://www.chimplabs.com/blog/2015/09/24/unintentional-fun-with-aircrack-ng-at-derbycon-5-0/ .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .PP .SH SEE ALSO .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/aircrack-ng.1.in
.TH AIRCRACK-NG 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME aircrack-ng - a 802.11 WEP / WPA-PSK key cracker .SH SYNOPSIS .B aircrack-ng [options] <input file(s)> .SH DESCRIPTION .BI aircrack-ng is an 802.11 WEP, 802.11i WPA/WPA2, and 802.11w WPA2 key cracking program. .PP It can recover the WEP key once enough encrypted packets have been captured with airodump-ng. This part of the aircrack-ng suite determines the WEP key using two fundamental methods. The first method is via the PTW approach (Pyshkin, Tews, Weinmann). The main advantage of the PTW approach is that very few data packets are required to crack the WEP key. The second method is the FMS/KoreK method. The FMS/KoreK method incorporates various statistical attacks to discover the WEP key and uses these in combination with brute forcing. .PP Additionally, the program offers a dictionary method for determining the WEP key. For cracking WPA/WPA2 pre-shared keys, a wordlist (file or stdin) or an airolib-ng has to be used. .SH INPUT FILES .TP Capture files (.cap, .pcap), IVS (.ivs) or Hashcat HCCAPX files (.hccapx) .SH OPTIONS .TP .B Common options: .TP .I -a <amode> Force the attack mode: 1 or wep for WEP (802.11) and 2 or wpa for WPA/WPA2 PSK (802.11i and 802.11w). .TP .I -e <essid> Select the target network based on the ESSID. This option is also required for WPA cracking if the SSID is cloaked. For SSID containing special characters, see https://www.aircrack-ng.org/doku.php?id=faq#how_to_use_spaces_double_quote_and_single_quote_etc_in_ap_names .TP .I -b <bssid> or --bssid <bssid> Select the target network based on the access point MAC address. .TP .I -p <nbcpu> Set this option to the number of CPUs to use (only available on SMP systems) for cracking the key/passphrase. By default, it uses all available CPUs .TP .I -q If set, no status information is displayed. .TP .I -C <macs> or --combine <macs> Merges all those APs MAC (separated by a comma) into a virtual one. .TP .I -l <file> Write the key into a file. Overwrites the file if it already exists. .PP .TP .B Static WEP cracking options: .TP .I -c Search alphanumeric characters only. .TP .I -t Search binary coded decimal characters only. .TP .I -h Search the numeric key for Fritz!BOX .TP .I -d <mask> or --debug <mask> Specify mask of the key. For example: A1:XX:CF .TP .I -m <maddr> Only keep the IVs coming from packets that match this MAC address. Alternatively, use \-m ff:ff:ff:ff:ff:ff to use all and every IVs, regardless of the network (this disables ESSID and BSSID filtering). .TP .I -n <nbits> Specify the length of the key: 64 for 40-bit WEP, 128 for 104-bit WEP, etc., until 512 bits of length. The default value is 128. .TP .I -i <index> Only keep the IVs that have this key index (1 to 4). The default behavior is to ignore the key index in the packet, and use the IV regardless. .TP .I -f <fudge> By default, this parameter is set to 2. Use a higher value to increase the bruteforce level: cracking will take more time, but with a higher likelihood of success. .TP .I -k <korek> There are 17 KoreK attacks. Sometimes one attack creates a huge false positive that prevents the key from being found, even with lots of IVs. Try \-k 1, \-k 2, ... \-k 17 to disable each attack selectively. .TP .I -x or -x0 Disable last keybytes bruteforce (not advised). .TP .I -x1 Enable last keybyte bruteforcing (default) .TP .I -x2 Enable last two keybytes bruteforcing. .TP .I -X Disable bruteforce multithreading (SMP only). .TP .I -s Shows ASCII version of the key at the right of the screen. .TP .I -y This is an experimental single brute-force attack which should only be used when the standard attack mode fails with more than one million IVs. .TP .I -z Uses PTW (Andrei Pyshkin, Erik Tews and Ralf-Philipp Weinmann) attack (default attack). .TP .I -P <num> or --ptw-debug <num> PTW debug: 1 Disable klein, 2 PTW. .TP .I -K Use KoreK attacks instead of PTW. .TP .I -D or --wep-decloak WEP decloak mode. .TP .I -1 or --oneshot Run only 1 try to crack key with PTW. .TP .I -M <num> Specify maximum number of IVs to use. .TP .I -V or --visual-inspection Run in visual inspection mode. Can only be used when using KoreK. .PP .TP .B WEP and WPA-PSK cracking options .TP .I -w <words> Path to a dictionary file for wpa cracking. Separate filenames with comma when using multiple dictionaries. Specify "-" to use stdin. Here is a list of wordlists: https://www.aircrack-ng.org/doku.php?id=faq#where_can_i_find_good_wordlists In order to use a dictionary with hexadecimal values, prefix the dictionary with "h:". Each byte in each key must be separated by ':'. When using with WEP, key length should be specified using -n. .TP .I -N <file> or --new-session <file> Create a new cracking session. It allows one to interrupt cracking session and restart at a later time (using -R or --restore-session). Status files are saved every 10 minutes. It does not overwrite existing session file. .TP .I -R <file> or --restore-session <file> Restore and continue a previously saved cracking session. This parameter is to be used alone, no other parameter should be specified when starting aircrack-ng (all the required information is in the session file). .PP .TP .B WPA-PSK options: .TP .I -E <file> Create Elcomsoft Wireless Security Auditor (EWSA) Project file v3.02. .TP .I -j <file> Create Hashcat v3.6+ Capture file (HCCAPX). .TP .I -J <file> Create Hashcat Capture file (HCCAP). .TP .I -S WPA cracking speed test. .TP .I -Z <sec> WPA cracking speed test execution length in seconds. .TP .I -r <database> Path to the airolib-ng database. Cannot be used with \(aq-w\(aq. .PP .TP .B SIMD selection: .TP .I --simd=<option> Aircrack-ng automatically loads and uses the fastest optimization based on instructions available for your CPU. This options allows one to force another optimization. Choices depend on the CPU and the following are all the possibilities that may be compiled regardless of the CPU type: generic, sse2, avx, avx2, avx512, neon, asimd, altivec, power8. .TP .I --simd-list Shows a list of the available SIMD architectures, separated by a space character. Aircrack-ng automatically selects the fastest optimization and thus it is rarely needed to use this option. Use case would be for testing purposes or when a "lower" optimization, such as "generic", is faster than the automatically selected one. Before forcing a SIMD architecture, verify that the instruction is supported by your CPU, using \-u. .PP .TP .B Other options: .TP .I -H or --help Show help screen .TP .I -u or --cpu-detect Provide information on the number of CPUs and SIMD support .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airdecap-ng.1.in
.TH AIRDECAP-NG 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airdecap-ng - decrypt a WEP/WPA encrypted pcap file .SH SYNOPSIS .B airdecap-ng [options] <pcap file> .SH DESCRIPTION .BI airdecap-ng decrypts a WEP/WPA encrypted pcap file to a unencrypted one by using the right WEP/WPA keys. .SH OPTIONS .TP .I -H, --help Shows the help screen. .TP .I -l Do not remove the 802.11 header. .TP .I -b <bssid> Access point MAC address filter. .TP .I -k <pmk> WPA Pairwise Master Key in hex. .TP .I -e <essid> Target network SSID. For SSID containing special characters, see https://www.aircrack-ng.org/doku.php?id=faq#how_to_use_spaces_double_quote_and_single_quote_etc_in_ap_names .TP .I -p <pass> Target network WPA passphrase. .TP .I -w <key> Target network WEP key in hex. .SH EXAMPLES airdecap-ng \-b 00:09:5B:10:BC:5A open-network.cap .br airdecap-ng \-w 11A3E229084349BC25D97E2939 wep.cap .br airdecap-ng \-e my_essid \-p my_passphrase tkip.cap .br .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airdecloak-ng.1.in
.TH AIRDECLOAK-NG 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airuncloak-ng - Removes wep cloaked framed from a pcap file. .SH SYNOPSIS .B airuncloak-ng <options> .SH DESCRIPTION .BI airuncloak-ng is a tool that removes wep cloaking from a pcap file. Some WIPS (actually one) can actively "prevent" cracking a WEP key by inserting chaff (fake wep frames) in the air to fool aircrack-ng. In some rare cases, cloaking fails and the key can be recovered without removing this chaff. In the cases where the key cannot be recovered, use this tool to filter out chaff. The program works by reading the input file and selecting packets from a specific network. Each selected packet is put into a list and classified (default status is "unknown"). Filters are then applied (in the order specified by the user) on this list. They will change the status of the packets (unknown, uncloaked, potentially cloaked or cloaked). The order of the filters is really important since each filter will base its analysis amongst other things on the status of the packets and different orders will give different results. Important requirement: The pcap file needs to have all packets (including beacons and all other "useless" packets) for the analysis (and if possible, prism/radiotap headers). .SH OPTIONS .PP .TP .I -h, --help Shows the help screen. .TP .I -i <file> Path to the capture file. .TP .I --ssid <ESSID> Essid of the network (not yet implemented) to filter. .TP .I --bssid <BSSID> BSSID of the network to filter. .TP .I --null-packets Assume that null packets can be cloaked (not yet implemented). .TP .I --disable-base-filter Do not apply base filter. .TP .I --drop-frag Drop fragmented packets. .TP .I --filters <filters> Apply different filters (separated by a comma). See below. .SH FILTERS .PP .TP .I signal Try to filter based on signal (prism or radiotap headers in the pcap file). .TP .I duplicate_sn Remove all duplicate sequence numbers for both the AP and the client (that are close to each other). .TP .I duplicate_sn_ap Remove duplicate sequence number for the AP only (that are close to each other). .TP .I duplicate_sn_client Remove duplicate sequence number for the client only (that are close to each other). .TP .I consecutive_sn Filter based on the fact that IV should be consecutive (only for AP). .TP .I duplicate_iv Filter out all duplicate IV. .TP .I signal_dup_consec_sn Use signal (if available), duplicate and consecutive sequence number (filtering is much more precise than using all these filters one by one). .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/aireplay-ng.8.in
.TH AIREPLAY-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME aireplay-ng - inject packets into a wireless network to generate traffic .SH SYNOPSIS .B aireplay-ng [options] <replay interface> .SH DESCRIPTION .B aireplay-ng is used to inject/replay frames. The primary function is to generate traffic for the later use in aircrack-ng for cracking the WEP and WPA-PSK keys. There are different attacks which can cause deauthentications for the purpose of capturing WPA handshake data, fake authentications, Interactive packet replay, hand-crafted ARP request injection and ARP-request reinjection. With the packetforge-ng tool it\(aqs possible to create arbitrary frames. .br .PP .B aireplay-ng supports single-NIC injection/monitor. .PP This feature needs driver patching. .PP .SH OPTIONS .TP .I -H, --help Shows the help screen. .PP .TP .B Filter options: .TP .I -b <bssid> MAC address of access point. .TP .I -d <dmac> MAC address of destination. .TP .I -s <smac> MAC address of source. .TP .I -m <len> Minimum packet length. .TP .I -n <len> Maximum packet length. .TP .I -u <type> Frame control, type field. .TP .I -v <subt> Frame control, subtype field. .TP .I -t <tods> Frame control, "To" DS bit (0 or 1). .TP .I -f <fromds> Frame control, "From" DS bit (0 or 1). .TP .I -w <iswep> Frame control, WEP bit (0 or 1). .TP .I -D Disable AP Detection. .PP .TP .B Replay options: .TP .I -x <nbpps> Number of packets per second. .TP .I -p <fctrl> Set frame control word (hex). .TP .I -a <bssid> Set Access Point MAC address. .TP .I -c <dmac> Set destination MAC address. .TP .I -h <smac> Set source MAC address. .TP .I -g <nb_packets> Change ring buffer size (default: 8 packets). The minimum is 1. .TP .I -F Choose first matching packet. .TP .I -e <essid> Fake Authentication attack: Set target SSID (see below). For SSID containing special characters, see https://www.aircrack-ng.org/doku.php?id=faq#how_to_use_spaces_double_quote_and_single_quote_etc_in_ap_names .TP .I -o <npackets> Fake Authentication attack: Set the number of packets for every authentication and association attempt (Default: 1). 0 means auto .TP .I -q <seconds> Fake Authentication attack: Set the time between keep-alive packets in fake authentication mode. .TP .I -Q Fake Authentication attack: Sends reassociation requests instead of performing a complete authentication and association after each delay period. .TP .I -y <prga> Fake Authentication attack: Specifies the keystream file for fake shared key authentication. .TP .I -T n Fake Authentication attack: Exit if fake authentication fails \(aqn\(aq time(s). .TP .I -j ARP Replay attack : inject FromDS packets (see below). .TP .I -k <IP> Fragmentation attack: Set destination IP in fragments. .TP .I -l <IP> Fragmentation attack: Set source IP in fragments. .TP .I -B Test option: bitrate test. .PP .TP .B Source options: .TP .I -i <iface> Capture packets from this interface. .TP .I -r <file> Extract packets from this pcap file. .PP .TP .B Miscellaneous options: .TP .I -R disable /dev/rtc usage. .PP .I --ignore-negative-one if the interface\(aqs channel can\(aqt be determined ignore the mismatch, needed for unpatched cfg80211 .PP .I --deauth-rc <rc>, -Z <rc> Provide a reason code when doing deauthication (between 0 and 255). By default, 7 is used: Class 3 frame received from unassociated STA. 0 is a reserved value. Reason codes explanations can be found in the IEEE802.11 standard or in https://mrncciew.com/2014/10/11/802-11-mgmt-deauth-disassociation-frames/ .PP .TP .B Attack modes: .TP .I -0 <count>, --deauth=<count> This attack sends deauthentication packets to one or more clients which are currently associated with a particular access point. Deauthenticating clients can be done for a number of reasons: Recovering a hidden ESSID. This is an ESSID which is not being broadcast. Another term for this is "cloaked" or Capturing WPA/WPA2 handshakes by forcing clients to reauthenticate or Generate ARP requests (Windows clients sometimes flush their ARP cache when disconnected). Of course, this attack is totally useless if there are no associated wireless client or on fake authentications. .TP .I -1 <delay>, --fakeauth=<delay> The fake authentication attack allows you to perform the two types of WEP authentication (Open System and Shared Key) plus associate with the access point (AP). This is only useful when you need an associated MAC address in various aireplay-ng attacks and there is currently no associated client. It should be noted that the fake authentication attack does NOT generate any ARP packets. Fake authentication cannot be used to authenticate/associate with WPA/WPA2 Access Points. .TP .I -2, --interactive This attack allows you to choose a specific packet for replaying (injecting). The attack can obtain packets to replay from two sources. The first being a live flow of packets from your wireless card. The second being from a pcap file. Reading from a file is an often overlooked feature of aireplay-ng. This allows you read packets from other capture sessions or quite often, various attacks generate pcap files for easy reuse. A common use of reading a file containing a packet your created with packetforge-ng. .TP .I -3, --arpreplay The classic ARP request replay attack is the most effective way to generate new initialization vectors (IVs), and works very reliably. The program listens for an ARP packet then retransmits it back to the access point. This, in turn, causes the access point to repeat the ARP packet with a new IV. The program retransmits the same ARP packet over and over. However, each ARP packet repeated by the access point has a new IVs. It is all these new IVs which allow you to determine the WEP key. .TP .I -4, --chopchop This attack, when successful, can decrypt a WEP data packet without knowing the key. It can even work against dynamic WEP. This attack does not recover the WEP key itself, but merely reveals the plaintext. However, some access points are not vulnerable to this attack. Some may seem vulnerable at first but actually drop data packets shorter than 60 bytes. If the access point drops packets shorter than 42 bytes, aireplay-ng tries to guess the rest of the missing data, as far as the headers are predictable. If an IP packet is captured, it additionally checks if the checksum of the header is correct after guessing the missing parts of it. This attack requires at least one WEP data packet. .TP .I -5, --fragment This attack, when successful, can obtain 1500 bytes of PRGA (pseudo random generation algorithm). This attack does not recover the WEP key itself, but merely obtains the PRGA. The PRGA can then be used to generate packets with packetforge-ng which are in turn used for various injection attacks. It requires at least one data packet to be received from the access point in order to initiate the attack. .TP .I -6, --caffe-latte In general, for an attack to work, the attacker has to be in the range of an AP and a connected client (fake or real). Caffe Latte attacks allows one to gather enough packets to crack a WEP key without the need of an AP, it just need a client to be in range. .TP .I -7, --cfrag This attack turns IP or ARP packets from a client into ARP request against the client. This attack works especially well against ad-hoc networks. As well it can be used against softAP clients and normal AP clients. .TP .I -8, --migmode This attack works against Cisco Aironet access points configured in WPA Migration Mode, which enables both WPA and WEP clients to associate to an access point using the same Service Set Identifier (SSID). The program listens for a WEP-encapsulated broadcast ARP packet, bitflips it to make it into an ARP coming from the attacker\(aqs MAC address and retransmits it to the access point. This, in turn, causes the access point to repeat the ARP packet with a new IV and also to forward the ARP reply to the attacker with a new IV. The program retransmits the same ARP packet over and over. However, each ARP packet repeated by the access point has a new IV as does the ARP reply forwarded to the attacker by the access point. It is all these new IVs which allow you to determine the WEP key. .TP .I -9, --test Tests injection and quality. .SH FRAGMENTATION VERSUS CHOPCHOP .PP .PP .B Fragmentation: .TP .PP .I Pros .br - Can obtain the full packet length of 1500 bytes XOR. This means you can subsequently pretty well create any size of packet. .br - May work where chopchop does not .br - Is extremely fast. It yields the XOR stream extremely quickly when successful. .TP .PP .I Cons .br - Setup to execute the attack is more subject to the device drivers. For example, Atheros does not generate the correct packets unless the wireless card is set to the mac address you are spoofing. .br - You need to be physically closer to the access point since if any packets are lost then the attack fails. .PP .B Chopchop .TP .PP .I Pro .br - May work where frag does not work. .TP .PP .I Cons .br - Cannot be used against every access point. .br - The maximum XOR bits is limited to the length of the packet you chopchop against. .br - Much slower then the fragmentation attack. .br .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airmon-ng.8.in
.TH AIRMON-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airmon-ng - POSIX sh script designed to turn wireless cards into monitor mode. .SH SYNOPSIS .B airmon-ng <start|stop> <interface> [channel] .B airmon-ng <check> [kill] .SH DESCRIPTION .BI airmon-ng This script can be used to enable monitor mode on wireless interfaces. It may also be used to go back from monitor mode to managed mode. Entering the airmon-ng command without parameters will show the interfaces status. It can also list/kill programs that can interfere with the wireless card operation. .SH OPTIONAL PARAMETERS .PP .TP .I start <interface> [channel] Enable monitor mode on an interface (and specify a channel). Note: Madwifi-ng is a special case, \(aqstart\(aq has to be used on wifi interfaces and \(aqstop\(aq on ath interfaces. .TP .I start <interface> [frequency] Enable monitor mode on an interface (and specify a frequency in MHz). Note: Madwifi-ng is a special case, \(aqstart\(aq has to be used on wifi interfaces and \(aqstop\(aq on ath interfaces. .TP .I stop <interface> Disable monitor mode and go back to managed mode (except for madwifi-ng where it kills the ath VAP). .TP .I check [kill] List all possible programs that could interfere with the wireless card. If \(aqkill\(aq is specified, it will try to kill all of them. .TP .I --verbose This flag must precede start/stop/check and can be combined with other parameters or used alone. This flag will increase the verbosity to provide additional useful information which may not be needed for normal operation. .TP .I --debug This flag must precede start/stop/check and can be combined with other parameters or used alone. This flag will increase the verbosity to debug level to assist in troubleshooting errors in airmon-ng. Use this flag when opening a bug, but only use --verbose when requesting support in irc. .TP .I --elite WARNING: DO NOT USE: This flag must precede start or stop and will prevent airmon-ng from removing interfaces. WARNING: Use of this flag will immediately disqualify receiving any support from the aircrack-ng team, due to the fact that this behavior is known to be broken. WARNING! .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). And modified to fit airmon-ng by David Francos Cuartero <[email protected]>. Most recently modified by Zero_Chaos to update for the airmon-zc rewrite. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1)
Inno Setup Script
aircrack-ng/manpages/airodump-ng-oui-update.8.in
.TH AIRODUMP-NG-OUI-UPDATE 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airodump-ng-oui-updater - IEEE oui list updater for airodump-ng .SH SYNOPSIS .B airodump-ng-oui-updater .SH DESCRIPTION .BI airodump-ng-oui-updater downloads and parses IEEE OUI list. .SH AUTHOR This manual page was written by David Francos Cuartero. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .PP .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airodump-ng.8.in
.TH AIRODUMP-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airodump-ng - a wireless packet capture tool for aircrack-ng .SH SYNOPSIS .B airodump-ng [options] <interface name>[,<interface name>,...] .SH DESCRIPTION .BI airodump-ng is used for packet capturing of raw 802.11 frames for the intent of using them with aircrack-ng. If you have a GPS receiver connected to the computer, airodump-ng is capable of logging the coordinates of the found access points. Additionally, airodump-ng writes out a text file containing the details of all access points and clients seen. .SH OPTIONS .PP .TP .I -H, --help Shows the help screen. .TP .I -i, --ivs It only saves IVs (only useful for cracking). If this option is specified, you have to give a dump prefix (\-\-write option) .TP .I -g, --gpsd Indicate that airodump-ng should try to use GPSd to get coordinates. .TP .I -w <prefix>, --write <prefix> Is the dump file prefix to use. If this option is not given, it will only show data on the screen. Beside this file a CSV file with the same filename as the capture will be created. .TP .I -e, --beacons It will record all beacons into the cap file. By default it only records one beacon for each network. .TP .I -u <secs>, --update <secs> Delay <secs> seconds delay between display updates (default: 1 second). Useful for slow CPU. .TP .I -A, --showack Prints ACK/CTS/RTS statistics. Helps in debugging and general injection optimization. It is indication if you inject, inject too fast, reach the AP, the frames are valid encrypted frames. Allows one to detect "hidden" stations, which are too far away to capture high bitrate frames, as ACK frames are sent at 1Mbps. .TP .I -h Hides known stations for \-\-showack. .TP .I -f <msecs> Time in milliseconds between hopping channels. .TP .I -B <secs>, --berlin <secs> Time before removing the AP/client from the screen when no more frames are received (Default: 120 seconds). See airodump-ng source for the history behind this option ;). .TP .I -c <channel>[,<channel>[,...]], --channel <channel>[,<channel>[,...]] Indicate the channel(s) to listen to. By default airodump-ng hops on all 2.4GHz channels. .TP .I -O, --ignore-other-chans Ignore access points on channels other than the selected one(s). Requires \-\-channel (or \-c). .TP .I -C <freq>[,<freq>[,...]] Indicates the frequencies to listen to. By default airodump-ng hops on all 2.4GHz channels. .TP .I -b <abg>, --band <abg> Indicate the band on which airodump-ng should hop. It can be a combination of \(aqa\(aq, \(aqb\(aq and \(aqg\(aq letters (\(aqb\(aq and \(aqg\(aq uses 2.4GHz and \(aqa\(aq uses 5GHz). Incompatible with --channel option. .TP .I -s <method>, --cswitch <method> Defines the way airodump-ng sets the channels when using more than one card. Valid values: 0 (FIFO, default value), 1 (Round Robin) or 2 (Hop on last). .TP .I -2, --ht20 Set the channel to be in HT20 (802.11n). .TP .I -3, --ht40+ Set the channel to be in HT40+ (802.11n). It requires the frequency 20MHz above to be available (4 channels above) and thus some channels are not usable in HT40+. Only channels up to 7 are available in HT40+ in the US (and 9 in most of Europe). .TP .I -5, --ht40- Set the channel to be in HT40- (802.11n). It requires the frequency 20MHz below to be available (4 channels be)low and thus some channels are not usable in HT40-. In 2.4GHz, HT40- channels start at channel 5. .TP .I -r <file> Reads packet from a file. .TP .I -T, --real-time While reading frames from a file specified with \(aq-r <file>\(aq, simulate the arrival rate of them, as if they were "live". .TP .I -x <msecs> Active Scanning Simulation (send probe requests and parse the probe responses). .TP .I -M, --manufacturer Display a manufacturer column with the information obtained from the IEEE OUI list. See airodump-ng-oui-update(8) .TP .I -U, --uptime Display APs uptime obtained from its beacon timestamp. .TP .I -W, --wps Display a WPS column with WPS version, config method(s), AP Setup Locked obtained from APs beacon or probe response (if any). .TP .I -o <formats>, --output-format <formats> Define the formats to use (separated by a comma). Possible values are: pcap, ivs, csv, gps, kismet, netxml. The default values are: pcap, csv, kismet, kismet-newcore. \(aqpcap\(aq is for recording a capture in pcap format, \(aqivs\(aq is for ivs format (it is a shortcut for --ivs). \(aqcsv\(aq will create an airodump-ng CSV file, \(aqkismet\(aq will create a kismet csv file and \(aqkismet-newcore\(aq will create the kismet netxml file. \(aqgps\(aq is a shortcut for --gps. .br These values can be combined with the exception of ivs and pcap. .TP .I -I <seconds>, --write-interval <seconds> Output file(s) write interval for CSV, Kismet CSV and Kismet NetXML in seconds (minimum: 1 second). By default: 5 seconds. Note that an interval too small might slow down airodump\-ng. .TP .I -K <enable>, --background <enable> Override automatic background detection. Use "0" to force foreground settings and "1" to force background settings. It will not make airodump-ng run as a daemon, it will skip background autodetection and force enable/disable of interactive mode and display updates. .TP .I --ignore-negative-one Removes the message that says \(aqfixed channel <interface>: -1\(aq. .PP .B Filter options: .TP .I -t <OPN|WEP|WPA|WPA1|WPA2|WPA3|OWE>, --encrypt <OPN|WEP|WPA|WPA1|WPA2|WPA3|OWE> It will only show networks matching the given encryption. Note that WPA is a shortcut for WPA1, WPA2 and WPA3. May be specified more than once: \(aq\-t OPN \-t WPA2\(aq .TP .I -d <bssid>, --bssid <bssid> It will only show networks, matching the given bssid. May be specified more than once: \(aq\-d 0D:F7:E2:61:C6:6D \-d 5B:62:A1:83:00:A8\(aq .TP .I -m <mask>, --netmask <mask> It will only show networks, matching the given bssid ^ netmask combination. Need \-\-bssid (or \-d) to be specified. .TP .I -a It will only show associated stations. Using in combination with -z won't display any of the stations. .TP .I -z It will only show unassociated stations. Using in combination with -a won't display any of the stations. .TP .I -n <int>, --min-packets <int> The minimum number of packets received by an AP before displaying it. Default value: 2. .TP .I -p <int>, --min-power <int> Filter out APs with PWR less than the specified value (default value: -120). .TP .I -q <int>, --min-rxq <int> Filter out APs with RXQ less than the specified value (default value: 0). Valid range: 0..100. Requires --channel (or -c) or -C. .TP .I -N <essid>, --essid <essid> Filter APs by ESSID. May be specified more than once: \(aq\-N AP1 \-N AP2\(aq .TP .I -R <regex>, --essid-regex <regex> Filter APs by ESSID using a regular expression. .SH INTERACTION .PP .BI airodump-ng can receive and interpret key strokes while running. The following list describes the currently assigned keys and supposed actions: .TP .I a Select active areas by cycling through these display options: AP+STA; AP+STA+ACK; AP only; STA only .TP .I d Reset sorting to defaults (Power) .TP .I i Invert sorting algorithm .TP .I m Mark the selected AP or cycle through different colors if the selected AP is already marked .TP .I o Enable colored display of APs and their stations. .TP .I p Disable colored display. .TP .I q Quit program. .TP .I r (De-)Activate realtime sorting - applies sorting algorithm every time the display will be redrawn .TP .I s Change column to sort by, which currently includes: First seen; BSSID; PWR level; Beacons; Data packets; Packet rate; Channel; Max. data rate; Encryption; Strongest Ciphersuite; Strongest Authentication; ESSID .TP .I SPACE Pause display redrawing/ Resume redrawing .TP .I TAB Enable/Disable scrolling through AP list .TP .I UP Select the AP prior to the currently marked AP in the displayed list if available .TP .I DOWN Select the AP after the currently marked AP if available .PP If an AP is selected or marked, all the connected stations will also be selected or marked with the same color as the corresponding Access Point. .SH EXAMPLES .B airodump-ng \-c 9 wlan0mon .PP Here is an example screenshot: .PP ----------------------------------------------------------------------- .br CH 9 ][ Elapsed: 1 min ][ 2007-04-26 17:41 ][ BAT: 2 hours 10 mins ][ WPA handshake: 00:14:6C:7E:40:80 .br .PP BSSID PWR RXQ Beacons #Data, #/s CH MB ENC CIPHER AUTH ESSID .br .PP 00:09:5B:1C:AA:1D 11 16 10 0 0 11 54. OPN <length: 7> .br 00:14:6C:7A:41:81 34 100 57 14 1 9 11 WEP WEP bigbear .br 00:14:6C:7E:40:80 32 100 752 73 2 9 54 WPA TKIP PSK teddy .br .PP BSSID STATION PWR Rate Lost Frames Notes Probes .br .PP 00:14:6C:7A:41:81 00:0F:B5:32:31:31 51 11-11 2 14 bigbear .br (not associated) 00:14:A4:3F:8D:13 19 11-11 0 4 mossy .br 00:14:6C:7A:41:81 00:0C:41:52:D1:D1 \-1 11-2 0 5 bigbear .br 00:14:6C:7E:40:80 00:0F:B5:FD:FB:C2 35 36-24 0 99 teddy .br ----------------------------------------------------------------------- .br .PP .TP .I BSSID MAC address of the access point. In the Client section, a BSSID of "(not associated)" means that the client is not associated with any AP. In this unassociated state, it is searching for an AP to connect with. .TP .I PWR Signal level reported by the Wi-Fi adapter. Its signification depends on the driver, but as you get closer to the AP or the station, the signal gets higher. It usually is the RSSI (https://en.wikipedia.org/wiki/Received_signal_strength_indication). If the BSSID PWR is -1, then the driver doesn\(aqt support signal level reporting. If PWR is -1 for some access points, it means the access point is out of range, however airodump-ng got at least a frame sent to it. If the PWR is -1 for a limited number of stations then this is for a packet which came from the AP to the client but the client transmissions are out of range for your Wi-Fi adapter. Meaning you are hearing only 1/2 of the communication. If all clients have PWR as -1 then it is likely that the driver doesn\(aqt support signal level reporting. A strong signal is around -40. An average one is around -55, and a weak one starts around -70. Wi-Fi adapters lower limit (aka receive sensitivity) is often around -80/-90. .TP .I RXQ Only shown when on a fixed channel. Receive Quality as measured by the percentage of frames (management and data frames) successfully received over the last 10 seconds. It\(aqs measured over all management and data frames. That\(aqs the clue, this allows you to read more things out of this value. Lets say you got 100 percent RXQ and all 10 (or whatever the rate) beacons per second coming in. Now all of a sudden the RXQ drops below 90, but you still capture all sent beacons. Thus you know that the AP is sending frames to a client but you can\(aqt hear the client nor the AP sending to the client (need to get closer). Another thing would be, that you got a 11MB card to monitor and capture frames (say a prism2.5) and you have a very good position to the AP. The AP is set to 54MBit and then again the RXQ drops, so you know that there is at least one 54MBit client connected to the AP. .TP .I Beacons Number of beacons sent by the AP. Each access point sends about ten beacons per second at the lowest rate (1M), so they can usually be picked up from very far. .TP .I #Data Number of captured data packets (if WEP, unique IV count), including data broadcast packets. .TP .I #/s Number of data packets per second measure over the last 10 seconds. .TP .I CH Channel number (taken from beacon frames). Note: sometimes frames from other channels are captured even if airodump-ng is not hopping, because of radio interference. .TP .I MB Maximum speed supported by the AP. If MB = 11, it\(aqs 802.11b, if MB = 22 it\(aqs 802.11b+ and higher rates are 802.11g. The dot (after 54 above) indicates short preamble is supported. \(aqe\(aq indicates that the network has QoS (802.11e) enabled. .TP .I ENC Encryption algorithm in use. OPN = no encryption,"WEP?" = WEP or higher (not enough data to choose between WEP and WPA/WPA2), WEP (without the question mark) indicates static or dynamic WEP, and WPA or WPA2 if TKIP or CCMP or MGT is present. .TP .I CIPHER The cipher detected. One of CCMP, WRAP, TKIP, WEP, WEP40, or WEP104. Not mandatory, but TKIP is typically used with WPA and CCMP is typically used with WPA2. WEP40 is displayed when the key index is greater than 0. The standard states that the index can be 0-3 for 40bit and should be 0 for 104 bit. .TP .I AUTH The authentication protocol used. One of MGT (WPA/WPA2 using a separate authentication server), SKA (shared key for WEP), PSK (pre-shared key for WPA/WPA2), or OPN (open for WEP). .TP .I WPS This is only displayed when --wps (or -W) is specified. If the AP supports WPS, the first field of the column indicates version supported. The second field indicates WPS config methods (can be more than one method, separated by comma): USB = USB method, ETHER = Ethernet, LAB = Label, DISP = Display, EXTNFC = External NFC, INTNFC = Internal NFC, NFCINTF = NFC Interface, PBC = Push Button, KPAD = Keypad. Locked is displayed when AP setup is locked. .TP .I ESSID The so-called "SSID", which can be empty if SSID hiding is activated. In this case, airodump-ng will try to recover the SSID from probe responses and association requests. .TP .I STATION MAC address of each associated station or stations searching for an AP to connect with. Clients not currently associated with an AP have a BSSID of "(not associated)". .TP .I Rate This is only displayed when using a single channel. The first number is the last data rate from the AP (BSSID) to the Client (STATION). The second number is the last data rate from Client (STATION) to the AP (BSSID). .TP .I Lost It means lost frames coming from the client. To determine the number of frames lost, there is a sequence field on every non-control frame, so you can subtract the second last sequence number from the last sequence number and you know how many frames you have lost. .TP .I Notes Additional information about the client, such as captured EAPOL or PMKID. .TP .I Frames The number of data packets sent by the client. .TP .I Probes The ESSIDs probed by the client. These are the networks the client is trying to connect to if it is not currently connected. .PP The first part is the detected access points. The second part is a list of detected wireless clients, stations. By relying on the signal power, one can even physically pinpoint the location of a given station. .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airolib-ng.1.in
.TH AIROLIB-NG 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airolib-ng - manage and create a WPA/WPA2 pre-computed hashes tables .SH SYNOPSIS .B airolib-ng <database> <operation> [options] .SH DESCRIPTION .BI airolib-ng is a tool for the aircrack-ng suite to store and manage essid and password lists, compute their Pairwise Master Keys (PMKs) and use them in WPA/WPA2 cracking. The program uses the lightweight SQLite3 database as the storage mechanism which is available on most platforms. The SQLite3 database was selected taking in consideration platform availability plus management, memory and disk overhead. .SH DATABASE .TP .I database It is name of the database file. Optionally specify the full path. .SH OPERATION .TP .I --stats Output information about the database. .TP .I --sql <sql> Execute specified SQL statement. .TP .I --clean [all] Clean the database from old junk. When specifying \(aqall\(aq, it will also reduce filesize if possible and run an integrity check. .TP .I --batch Start/Restart batch-processing all combinations of ESSIDs and passwords. To pause, hit Ctrl-C. .TP .I --verify [all] Verify a set of randomly chosen PMKs. If \(aqall\(aq is given, all invalid PMK in the database will be deleted. .TP .I --import [essid|passwd] <file> Import a flat file as a list of ESSIDs or passwords. .TP .I import cowpatty <file> Import a coWPAtty file. .TP .I --export cowpatty <essid> <file> Export to a cowpatty file. .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airserv-ng.8.in
.TH AIRSERV-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airserv-ng - a wireless card server .SH SYNOPSIS .B airserv-ng <options> .SH DESCRIPTION .BI airserv-ng is a wireless card server which allows multiple wireless application programs to independently use a wireless card via a client-server TCP network connection. All operating system and wireless card driver specific code is incorporated into the server. This eliminates the need for each wireless application to contain the complex wireless card and driver logic. It is also supports multiple operating systems. .SH OPTIONS .PP .TP .I -h Shows the help screen. .TP .I -p <port> TCP port to listen on (by default: 666). .TP .I -d <iface> Wifi interface to use. .TP .I -c <chan> Lock interface to this channel. .TP .I -v <level> Debug level. There are 3 debug levels. Debug level of 1 shows client connection/disconnection (default). Debug level of 2 shows channel change requests and invalid client command requests in addition to the debug level 1 messages. Debug level of 3 displays a message each time a packet (and its length) is sent to the client. It also include messages from level 2 (and 1). .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airtun-ng.8.in
.TH AIRTUN-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airtun-ng - a virtual tunnel interface creator for aircrack-ng .SH SYNOPSIS .B airtun-ng [options] <interface name> .SH DESCRIPTION .BI airtun-ng creates a virtual tunnel interface (atX) for sending arbitrary IP packets by using raw ieee802.11 packet injection. .SH OPTIONS .PP .TP .I -H, --help Shows the help screen. .TP .I -x <pps> Sets maximum number of packets per second. .TP .I -a <BSSID> Specifies the BSSID for the iee802.11 header. In WDS Mode this sets the Receiver. .TP .I -h <SMAC> Specifies the source MAC for the iee802.11 header. .TP .I -i <iface> Sets the capture interface. .TP .I -r <file> Specifies a file to read 802.11 frames. .TP .I -y <PRGA-file> Is the name of the file, which provides the keystream for WEP encoding. (No receiving, just transmitting of IP packets.) .TP .I -w <WEP-key> This is the WEP key to en-/decrypt all traffic going through the tunnel. .TP .I -e <ESSID> Sets the target network SSID (use with -p). .TP .I -p <passphrase> Use this WPA passphrase to decrypt packets (use with -a and -e). .TP .I -t <tods> Defines the ToDS and FromDS bit in the ieee802.11 header. For tods=1, the ToDS bit is set to 1 and FromDS to 0, while tods=0 sets them the other way around. If set to 2, it will be tunneled in a WDS/bridge. .TP .I -m <netmask>, --netmask <netmask> Filters networks based on bssid ^ netmask combination. Needs \-d, used in replay mode. .TP .I -d <BSSID>, --bssid <BSSID> Filters networks based on the <BSSID>. Used in replay mode. .TP .I -f, --repeat Enables replay mode. All read frames, filtered by bssid and netmask (if specified), will be replayed. .TP .I -s <transmitter> Set Transmitter MAC address for WDS Mode. .TP .I -b Bidirectional mode. This enables communication in Transmitter\(aqs AND Receiver\(aqs networks. Works only if you can see both stations. .SH EXAMPLES .B airtun-ng \-a 00:14:22:56:F3:4E \-t 0 \-y keystream.xor wlan0 .PP .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/airventriloquist-ng.8.in
.TH AIRVENTRILOQUIST-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME airventriloquist-ng - encrypted WiFi packet injection .SH SYNOPSIS .B airventriloquist-ng [options] .SH DESCRIPTION .BI airventriloquist-ng injects on encrypted WiFi packet and circumvents wireless intrusion prevention systems. .SH OPTIONS .PP .TP .I --help Shows the help screen. .TP .I -i <replay interface> Interface to capture and inject. Mandatory option. .TP .I -d, --deauth Sends active deauthentications frames to encrypted stations. .TP .I -e <value>, --essid <value> ESSID of target network. For SSID containing special characters, see https://www.aircrack-ng.org/doku.php?id=faq#how_to_use_spaces_double_quote_and_single_quote_etc_in_ap_names .TP .I -p <value>, --passphrase <value> WPA Passphrase of the target network. Passphrase is between 8 and 63 characters long. .TP .I -c, --icmp Respond to all ICMP frames (Debug). .TP .I -n, --dns IP to resolve all DNS queries to. .TP .I -s <URL>, --hijack <URL> URL to look for in HTTP requests when hijacking connections. The URL can have wildcards characters. Example: *jquery*.js* .TP .I -r <URL>, --redirect <URL> URL to redirect hijacked connections to. .TP .I -v, --verbose Verbose output. .PP .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airtun-ng(8)
Inno Setup Script
aircrack-ng/manpages/besside-ng-crawler.1.in
.TH BESSIDE-NG-CRAWLER 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME besside-ng-crawler - filter EAPOL frames from a directory of capture files. .SH SYNOPSIS .B besside-ng-crawler <Input Directory> <Output File> .SH DESCRIPTION .BI besside-ng-crawler Scans recursively on input directory looking for pcap dumpfiles and filters out one beacon and all EAPOL frames for the WPA networks if finds in them. .SH AUTHOR This manual page was written by David Francos Cuartero. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/besside-ng.8.in
.TH BESSIDE-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME besside-ng - crack a WEP or WPA key without user intervention and collaborate with WPA cracking statistics .SH SYNOPSIS .B besside-ng [options] <interface> .SH DESCRIPTION .BI besside-ng is a tool which will crack all the WEP networks in range and log all the WPA handshakes. WPA handshakes can be uploaded to the online cracking service at wpa.darkircop.org. .BR Wpa.darkircop.com also provides useful statistics based on user-submitted capture files about the feasibility of WPA cracking. .PP .TP .I -b <target mac> Specifies the target's BSSID .TP .I -s <WPA server> Where to upload capture file for cracking. A good choice is wpa.darkircop.org .TP .I -c <chan> Channel lock .TP .I -p <pps> Packages per second to send (flood rate). .TP .I -W Crack only WPA networks .TP .I -v Verbose mode. Use -vv for more verbose, -vv for even more and so on. .TP .I -h Help screen .SH AUTHOR This manual page was written by David Francos Cuartero. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/buddy-ng.1.in
.TH BUDDY-NG 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME buddy-ng - a tool to work with easside-ng .SH SYNOPSIS .B buddy-ng <options> .SH DESCRIPTION .BI buddy-ng server echoes back the decrypted packets to the system running easside-ng in order to access the wireless network without knowing the WEP key. It is done by having the AP itself decrypt the packets. When ran, it automatically starts and listen to port 6969. .SH OPTIONS .PP .TP .I -h Shows the help screen. .TP .I -p Don\(aqt drop privileges .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/easside-ng.8.in
.TH EASSIDE-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME easside-ng - an auto-magic tool which allows you to communicate via an WEP-encrypted AP without knowing the key .SH SYNOPSIS .B easside-ng <options> .SH DESCRIPTION .BI easside-ng is an auto-magic tool which allows you to communicate via an WEP-encrypted access point (AP) without knowing the WEP key. It first identifies a network, then proceeds to associate with it, obtain PRGA (pseudo random generation algorithm) xor data, determine the network IP scheme and then setup a TAP interface so that you can communicate with the AP without requiring the WEP key. All this is done without your intervention. .SH OPTIONS .PP .TP .I -h Shows the help screen. .TP .I -v <victim mac> Victim BSSID (Optional). .TP .I -m <src mac> Source MAC address to be used (Optional). .TP .I -i <ip> Source IP address to be used on the wireless LAN. Defaults to the decoded network plus \(aq.123\(aq (Optional). .TP .I -r <router ip> IP address of the AP router. This could be the WAN IP of the AP or an actual router IP depending on the topology. Defaults to the decoded network plus \(aq.1\(aq (Optional). .TP .I -s <buddy ip> IP address of Buddy-ng server (Mandatory) .TP .I -f <iface> Wireless interface to use (Mandatory) .TP .I -c <channel> Lock interface to this channel (Optional). .TP .I -n Determine Internet IP only. .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/ivstools.1.in
.TH IVSTOOLS 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME ivstools - extract IVs from a pcap file or merges several .ivs files into one .SH SYNOPSIS .B ivstools --convert <pcap file> <ivs output file> .B ivstools --merge <ivs file 1> <ivs file 2> .. <output file> .SH DESCRIPTION .BI ivstools is a tool designed to extract ivs (initialization vectors) from a pcap dump to an ivs file and it can also merge several ivs (initialization vectors) files into one.. .SH EXAMPLE .B ivstools --convert wep_dump.cap out.ivs .br .B ivstools --merge myivs1.ivs myivs2.ivs myivs3.ivs allivs.ivs .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/kstats.1.in
.TH KSTATS 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME kstats - show statistical FMS algorithm votes for an ivs dump and a specified WEP key .SH SYNOPSIS .B kstats <ivs file> <104-bit key> .SH DESCRIPTION .BI kstats is a tool designed to show the FMS algorithm votes for an ivs dump (initialization vectors) with a specified WEP key. The ivs dump can be get by using the combination of both airodump(1) and ivstools(1). .SH EXAMPLE .B kstats kstats out.ivs 123456789ABCDEF123456789AB .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
aircrack-ng/manpages/Makefile.am
# Aircrack-ng # # Copyright (C) 2017 Joseph Benden <[email protected]> # # Autotool support was written by: Joseph Benden <[email protected]> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the # OpenSSL library under certain conditions as described in each # individual source file, and distribute linked combinations # including the two. # # You must obey the GNU General Public License in all respects # for all of the code used other than OpenSSL. # # If you modify file(s) with this exception, you may extend this # exception to your dnl version of the file(s), but you are not obligated # to do so. # # If you dnl do not wish to do so, delete this exception statement from your # version. # # If you delete this exception statement from all source files in the # program, then also delete it here. dist_man1_MANS = aircrack-ng.1 \ airdecap-ng.1 \ packetforge-ng.1 \ ivstools.1 \ kstats.1 \ makeivs-ng.1 \ airdecloak-ng.1 dist_man8_MANS = airodump-ng-oui-update.8 if LINUX dist_man8_MANS += airmon-ng.8 endif if FREEBSD dist_man8_MANS += airmon-ng.8 endif if HAVE_AIRPCAP_OR_PCAP if HAVE_PCAP dist_man1_MANS += besside-ng-crawler.1 endif dist_man1_MANS += wpaclean.1 dist_man8_MANS += airbase-ng.8 \ aireplay-ng.8 \ airodump-ng.8 \ airserv-ng.8 \ airtun-ng.8 endif if HAVE_SQLITE3 dist_man1_MANS += airolib-ng.1 endif if EXPERIMENTAL dist_man1_MANS += buddy-ng.1 if HAVE_AIRPCAP_OR_PCAP dist_man8_MANS += airventriloquist-ng.8 \ besside-ng.8 \ easside-ng.8 \ tkiptun-ng.8 \ wesside-ng.8 endif endif EXTRA_DIST = airmon-ng.8.in \ airolib-ng.1.in \ besside-ng-crawler.1.in \ buddy-ng.1.in \ airventriloquist-ng.8.in \ besside-ng.8.in \ easside-ng.8.in \ tkiptun-ng.8.in \ wesside-ng.8.in \ wpaclean.1.in \ airbase-ng.8.in \ aireplay-ng.8.in \ airodump-ng.8.in \ airserv-ng.8.in \ airtun-ng.8.in
Inno Setup Script
aircrack-ng/manpages/makeivs-ng.1.in
.TH MAKEIVS-NG 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME makeivs - generate a dummy IVS dump file with a specific WEP key .SH SYNOPSIS .B makeivs <ivs file> <104-bit key> .SH DESCRIPTION .BI makeivs-ng is a tool designed to generate an IVS dump file with an inputted WEP key. The aim of is tools is to provide a way to create dumps with a known encryption key for tests. .SH OPTIONS .TP .B Common options: .TP .I -b <bssid> or --bssid <bssid> Set the BSSID (Access Point MAC) .TP .I -f <num> or --first <num> Value for the first IV generated. .TP .I -k <key> or --key <key> Target network WEP key in hex. Separator between bytes is accepted but not necessary. .TP .I -s <num> or --seed <num> Seed used to setup random generator. May be used in combination with \-p or \-\-prng. .TP .I -w <file> or --write <file> Filename to write IVs into. .TP .I -c <num> or --count <num> Amount of IVs to generate. Default value is 100000. .TP .I -d <num> or --dupe <num> Percentage of duplicate IVs. .TP .I -e <num> or --error <num> Percentage of erroneous keystreams. .TP .I -l <num> or --length <num> Size of keystreams. Default: 16 bytes. .TP .I -n or --nofms Ignores weak IVs. .TP .I -p or --prng Use random values when generating IVs. Default is to use sequential values. .TP .I --help Show help screen. .SH EXAMPLE .B makeivs makeivs -w out.ivs -k 123456789ABCDEF123456789AB .SH AUTHOR This manual page was written by Adam Cecile <[email protected]> for the Debian system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/packetforge-ng.1.in
.TH PACKETFORGE-NG 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME packetforge-ng - forge packets: ARP, UDP, ICMP or custom packets. .SH SYNOPSIS .B packetforge-ng <mode> <options> .SH DESCRIPTION .BI packetforge-ng is a tool to create encrypted packets that can subsequently be used for injection. You may create various types of packets such as arp requests, UDP, ICMP and custom packets. The most common use is to create ARP requests for subsequent injection. .PP To create an encrypted packet, you must have a PRGA (pseudo random generation algorithm) file. This is used to encrypt the packet you create. This is typically obtained from aireplay-ng chopchop or fragmentation attacks. .SH OPTIONS .PP .TP .I -H, --help Shows the help screen. .TP .I -p <fctrl> Set frame control word (hex) .TP .I -a <bssid> Set Access Point MAC address .TP .I -c <dmac> Set Destination MAC address .TP .I -h <smac> Set Source MAC address .TP .I -j set FromDS bit .TP .I -o clear ToDS bit .TP .I -e disable WEP encryption .TP .I -k <ip:[port]> Set destination IP (and port) .TP .I -l <ip:[port]> Set source IP (and port) .TP .I -w <file> Write packet to this pcap file .TP .I -r <file> Read packet from this pcap file .TP .I -y <file> Read PRGA from this file .TP .I -t <ttl> Set Time To Live in IP-Header .TP .I -s <size> Set size of the generated null packet. .TP .I -0, --arp Forge an ARP packet .TP .I -1, --udp Forge an UDP packet .TP .I -2, --icmp Forge an ICMP packet .TP .I -3, --null Forge a llc null packet .TP .I -9, --custom Build a custom packet, requires \-r to read an unencrypted frame out of a pcap file. .SH EXAMPLE .B packetforge-ng \-y test.xor \-a 00:09:5b:12:40:cc \-h 00:10:2a:cb:30:14 \-k 192.168.1.100 \-l 192.168.1.1 \-w arp-request.cap .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/tkiptun-ng.8.in
.TH TKIPTUN-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME tkiptun-ng - inject a few frames into a WPA TKIP network with QoS .SH SYNOPSIS .B tkiptun-ng [options] <replay interface> .SH DESCRIPTION .BI tkiptun-ng is a tool created by Martin Beck aka hirte, a member of aircrack-ng team. This tool is able to inject a few frames into a WPA TKIP network with QoS. He worked with Erik Tews (who created PTW attack) for a conference in PacSec 2008: "Gone in 900 Seconds, Some Crypto Issues with WPA". .SH OPERATION .PP .TP .I -H, --help Shows the help screen. .TP .B Filter options: .TP .I -d <dmac> MAC address of destination. .TP .I -s <smac> MAC address of source. .TP .I -m <len> Minimum packet length. .TP .I -n <len> Maximum packet length. .TP .I -t <tods> Frame control, "To" DS bit. .TP .I -f <fromds> Frame control, "From" DS bit. .TP .I -D Disable AP Detection. .PP .TP .B Replay options: .TP .I -x <nbpps> Number of packets per second. .TP .I -p <fctrl> Set frame control word (hex). .TP .I -a <bssid> Set Access Point MAC address. .TP .I -c <dmac> Set destination MAC address. .TP .I -h <smac> Set source MAC address. .TP .I -e <essid> Set target SSID. .TP .I -M <sec> MIC error timeout in seconds. Default: 60 seconds .PP .TP .B Debug options: .TP .I -K <prga> Keystream for continuation. .TP .I -y <file> Keystream file for continuation. .TP .I -j Inject FromFS packets. .TP .I -P <PMK> Pairwise Master key (PMK) for verification or vulnerability testing. .TP .I -p <PSK> Preshared key (PSK) to calculate PMK with essid. .PP .TP .B Source options: .TP .I -i <iface> Capture packets from this interface. .TP .I -r <file> Extract packets from this pcap file. .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/wesside-ng.8.in
.TH WESSIDE-NG 8 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME wesside-ng - crack a WEP key of an open network without user intervention .SH SYNOPSIS .B wesside-ng <options> .SH DESCRIPTION .BI wesside-ng is an auto-magic tool which incorporates a number of techniques to seamlessly obtain a WEP key in minutes. It first identifies a network, then proceeds to associate with it, obtain PRGA (pseudo random generation algorithm) xor data, determine the network IP scheme, reinject ARP requests and finally determine the WEP key. All this is done without your intervention. .SH OPTIONS .PP .TP .I -h Shows the help screen. .TP .I -i <iface> Wireless interface name. (Mandatory) .TP .I -n <network ip> Network IP as in \(aqwho has destination IP (netip) tell source IP (myip)\(aq. Defaults to the source IP on the ARP request which is captured and decrypted. (Optional) .TP .I -m <my ip> \(aqwho has destination IP (netip) tell source IP (myip)\(aq. Defaults to the network.123 on the ARP request captured (Optional). .TP .I -a <source mac> Source MAC address (Optional) .TP .I -c Do not crack the key. Simply capture the packets until control-C is hit to stop the program! (Optional) .TP .I -p <min PRGA> Determines the minimum number of bytes of PRGA which is gathered. Defaults to 128 bytes. (Optional). .TP .I -v <victim MAC> Wireless access point MAC address (Optional). .TP .I -t <threshold> For each number of IVs specified, restart the airecrack-ng PTW engine (Optional). It will restart PTW every <threshold> IVs. .TP .I -f <channel> Allows the highest channel for scanning to be defined. Defaults to channel 11 (Optional). .SH AUTHOR This manual page was written by Thomas d\(aqOtreppe. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B wpaclean(1) .br .B airventriloquist(8)
Inno Setup Script
aircrack-ng/manpages/wpaclean.1.in
.TH WPACLEAN 1 "@MAN_RELEASE_DATE@" "@MAN_RELEASE_VERSION@" .SH NAME wpaclean - clean wpa capture files .SH SYNOPSIS .B wpaclean <out.cap> <in.cap> [in2.cap] [...] .SH DESCRIPTION .BI wpaclean Cleans capture files to get only the 4-way handshake and a beacon. .SH AUTHOR This manual page was written by David Francos Cuartero <[email protected]>. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or any later version published by the Free Software Foundation On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. .PP .SH SEE ALSO .br .B airbase-ng(8) .br .B aireplay-ng(8) .br .B airmon-ng(8) .br .B airodump-ng(8) .br .B airodump-ng-oui-update(8) .br .B airserv-ng(8) .br .B airtun-ng(8) .br .B besside-ng(8) .br .B easside-ng(8) .br .B tkiptun-ng(8) .br .B wesside-ng(8) .br .B aircrack-ng(1) .br .B airdecap-ng(1) .br .B airdecloak-ng(1) .br .B airolib-ng(1) .br .B besside-ng-crawler(1) .br .B buddy-ng(1) .br .B ivstools(1) .br .B kstats(1) .br .B makeivs-ng(1) .br .B packetforge-ng(1) .br .B airventriloquist(8)
Patch
aircrack-ng/patches/acx-20070101.patch
diff -Naur acx_orig/common.c acx_rawtx/common.c --- acx_orig/common.c 2007-01-10 22:15:27.000000000 +0100 +++ acx_rawtx/common.c 2007-05-20 12:58:55.000000000 +0200 @@ -3180,6 +3180,14 @@ goto end; } + if(unlikely(skb->len < 24)) { + /* silently drop the packet, since fw won't send it */ + txresult = OK; + /* ...but indicate an error nevertheless */ + adev->stats.tx_errors++; + goto end; + } + tx = acx_l_alloc_tx(adev); if (unlikely(!tx)) { printk_ratelimited("%s: start_xmit: txdesc ring is full, " diff -Naur acx_orig/pci.c acx_rawtx/pci.c --- acx_orig/pci.c 2007-01-10 13:27:16.000000000 +0100 +++ acx_rawtx/pci.c 2007-05-20 12:58:55.000000000 +0200 @@ -1992,7 +1992,12 @@ acx_set_status(adev, ACX_STATUS_1_SCANNING); break; case ACX_MODE_3_AP: case ACX_MODE_MONITOR: - acx_set_status(adev, ACX_STATUS_4_ASSOCIATED); break; + acx_set_status(adev, ACX_STATUS_4_ASSOCIATED); + adev->msdu_lifetime = 0;/* no lifetime at all */ + adev->short_retry = 0; /* no retries for (short) non-RTS packets */ + adev->long_retry = 0; /* no retries for long (RTS) packets */ + + break; } acx_s_start(adev); @@ -3387,12 +3392,14 @@ break; } adev->stats.tx_errors++; +#if 0 if (adev->stats.tx_errors <= 20) printk("%s: tx error 0x%02X, buf %02u! (%s)\n", adev->ndev->name, error, finger, err); else printk("%s: tx error 0x%02X, buf %02u!\n", adev->ndev->name, error, finger); +#endif }
Patch
aircrack-ng/patches/ar9170_regdomain_override.patch
PaulFertser> Get _your_ country code from regd.h, add 32768 and supply as a parameter. [email protected] --- linux-2.6.32-gentoo-r1-orig/drivers/net/wireless/ath/ar9170/main.c 2009-12-03 06:51:21.000000000 +0300 +++ linux-2.6.32-gentoo-r1/drivers/net/wireless/ath/ar9170/main.c 2010-01-16 02:20:36.000000000 +0300 @@ -53,6 +53,11 @@ module_param_named(ht, modparam_ht, bool, S_IRUGO); MODULE_PARM_DESC(ht, "enable MPDU aggregation."); +static int modparam_override_eeprom_regdomain = -1; +module_param_named(override_eeprom_regdomain, + modparam_override_eeprom_regdomain, int, S_IRUGO); +MODULE_PARM_DESC(override_eeprom_regdomain, "Override regdomain hardcoded in EEPROM with this value (DANGEROUS)."); + #define RATE(_bitrate, _hw_rate, _txpidx, _flags) { \ .bitrate = (_bitrate), \ .flags = (_flags), \ @@ -2687,6 +2692,14 @@ if (err) goto err_out; + if (modparam_override_eeprom_regdomain != -1) { + dev_err(pdev, "DANGER! You're overriding EEPROM-defined regulatory domain.\n"); + dev_err(pdev, "Your card was not certified to operate on the domain you choosed.\n"); + dev_err(pdev, "This might result in a violation of your local regulatory rules.\n"); + dev_err(pdev, "Do not ever do that unless you really know what you do!\n"); + regulatory->current_rd = modparam_override_eeprom_regdomain; + } + err = ath_regd_init(regulatory, ar->hw->wiphy, ar9170_reg_notifier); if (err)
Patch
aircrack-ng/patches/ath5k-frequency-chaos-2.6.28.patch
diff -Naur linux-2.6.28/drivers/net/wireless/ath5k/base.c linux-2.6.28-chaos/drivers/net/wireless/ath5k/base.c --- linux-2.6.28/drivers/net/wireless/ath5k/base.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-chaos/drivers/net/wireless/ath5k/base.c 2009-02-06 21:38:43.000000000 -0500 @@ -272,7 +272,7 @@ static void ath5k_detach(struct pci_dev *pdev, struct ieee80211_hw *hw); /* Channel/mode setup */ -static inline short ath5k_ieee2mhz(short chan); +static inline short ath5k_ieee2mhz(int chan, unsigned int chfreq); static unsigned int ath5k_copy_channels(struct ath5k_hw *ah, struct ieee80211_channel *channels, unsigned int mode, @@ -848,12 +848,16 @@ * Convert IEEE channel number to MHz frequency. */ static inline short -ath5k_ieee2mhz(short chan) +ath5k_ieee2mhz(int chan, unsigned int chfreq) { - if (chan <= 14 || chan >= 27) - return ieee80211chan2mhz(chan); + if (chfreq == CHANNEL_5GHZ) + return (chan + 1000) * 5; else - return 2212 + chan * 20; +// XXX: This part needs to be fixed + if (chan <= 14 || chan >= 27) + return ieee80211chan2mhz(chan); + else + return 2212 + chan * 20; } static unsigned int @@ -862,22 +866,25 @@ unsigned int mode, unsigned int max) { - unsigned int i, count, size, chfreq, freq, ch; + unsigned int i, count, size, chfreq, freq; + int ch; if (!test_bit(mode, ah->ah_modes)) return 0; switch (mode) { + /* I don't even like channel numbers */ case AR5K_MODE_11A: case AR5K_MODE_11A_TURBO: - /* 1..220, but 2GHz frequencies are filtered by check_channel */ - size = 220 ; + size = 241 ; // going over 6.0GHz may be dangerous so I am limiting it + ch = -40; // might be able to push this to -201 or so, needs more testing chfreq = CHANNEL_5GHZ; break; case AR5K_MODE_11B: case AR5K_MODE_11G: case AR5K_MODE_11G_TURBO: - size = 26; + size = 70; + ch = -43; chfreq = CHANNEL_2GHZ; break; default: @@ -885,9 +892,8 @@ return 0; } - for (i = 0, count = 0; i < size && max > 0; i++) { - ch = i + 1 ; - freq = ath5k_ieee2mhz(ch); + for (i = 0, count = 0; i < size && max > 0; i++,ch++) { + freq = ath5k_ieee2mhz(ch,chfreq); /* Check if channel is supported by the chipset */ if (!ath5k_channel_ok(ah, freq, chfreq)) diff -Naur linux-2.6.28/drivers/net/wireless/ath5k/base.h linux-2.6.28-chaos/drivers/net/wireless/ath5k/base.h --- linux-2.6.28/drivers/net/wireless/ath5k/base.h 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-chaos/drivers/net/wireless/ath5k/base.h 2009-02-06 21:38:43.000000000 -0500 @@ -93,11 +93,7 @@ }; -#if CHAN_DEBUG -#define ATH_CHAN_MAX (26+26+26+200+200) -#else -#define ATH_CHAN_MAX (14+14+14+252+20) -#endif +#define ATH_CHAN_MAX (70+70+70+240+240) // b+g+gT+a+aT XXX: This is probably excessive /* Software Carrier, keeps track of the driver state * associated with an instance of a device */ diff -Naur linux-2.6.28/drivers/net/wireless/ath5k/caps.c linux-2.6.28-chaos/drivers/net/wireless/ath5k/caps.c --- linux-2.6.28/drivers/net/wireless/ath5k/caps.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-chaos/drivers/net/wireless/ath5k/caps.c 2009-02-06 21:38:43.000000000 -0500 @@ -69,9 +69,9 @@ if (AR5K_EEPROM_HDR_11A(ee_header)) { /* 4920 */ - ah->ah_capabilities.cap_range.range_5ghz_min = 5005; - ah->ah_capabilities.cap_range.range_5ghz_max = 6100; - + ah->ah_capabilities.cap_range.range_5ghz_min = 4800; + ah->ah_capabilities.cap_range.range_5ghz_max = 6000; /* 6100 is what the code said but */ + /* it fried my Ubiquiti SRC */ /* Set supported modes */ __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode); @@ -87,7 +87,7 @@ if (AR5K_EEPROM_HDR_11B(ee_header) || AR5K_EEPROM_HDR_11G(ee_header)) { /* 2312 */ - ah->ah_capabilities.cap_range.range_2ghz_min = 2412; + ah->ah_capabilities.cap_range.range_2ghz_min = 2192; /* this is the bottom of the registers */ ah->ah_capabilities.cap_range.range_2ghz_max = 2732; if (AR5K_EEPROM_HDR_11B(ee_header)) diff -Naur linux-2.6.28/net/mac80211/tx.c linux-2.6.28-chaos/net/mac80211/tx.c --- linux-2.6.28/net/mac80211/tx.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-chaos/net/mac80211/tx.c 2009-02-06 21:38:53.000000000 -0500 @@ -1378,10 +1378,32 @@ struct net_device *dev) { struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); + struct ieee80211_channel *chan = local->hw.conf.channel; struct ieee80211_radiotap_header *prthdr = (struct ieee80211_radiotap_header *)skb->data; u16 len_rthdr; + /* + * Frame injection is not allowed if beaconing is not allowed + * or if we need radar detection. Beaconing is usually not allowed when + * the mode or operation (Adhoc, AP, Mesh) does not support DFS. + * Passive scan is also used in world regulatory domains where + * your country is not known and as such it should be treated as + * NO TX unless the channel is explicitly allowed in which case + * your current regulatory domain would not have the passive scan + * flag. + * + * Since AP mode uses monitor interfaces to inject/TX management + * frames we can make AP mode the exception to this rule once it + * supports radar detection as its implementation can deal with + * radar detection by itself. We can do that later by adding a + * monitor flag interfaces used for AP support. + */ + if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR | + IEEE80211_CHAN_PASSIVE_SCAN))) + return TX_DROP; + /* This was intended for the kernel patch but it didn't work; goto fail; */ + /* check for not even having the fixed radiotap header part */ if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) goto fail; /* too short to be possibly valid */
Patch
aircrack-ng/patches/ath5k-injection-2.6.27-rc2.patch
diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c index 217d506..4e7a949 100644 --- a/drivers/net/wireless/ath5k/base.c +++ b/drivers/net/wireless/ath5k/base.c @@ -1219,7 +1219,9 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf) bf->skbaddr = pci_map_single(sc->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); - if (info->flags & IEEE80211_TX_CTL_NO_ACK) + if (info->flags & IEEE80211_TX_CTL_NO_ACK || + (info->flags & IEEE80211_TX_CTL_INJECTED && + !(ieee80211_has_morefrags(((struct ieee80211_hdr *)skb->data)->frame_control)))) flags |= AR5K_TXDESC_NOACK; pktlen = skb->len;
Patch
aircrack-ng/patches/ath5k-pass-failed-crc.patch
diff -Naur linux-2.6.28/drivers/net/wireless/ath5k/base.c linux-2.6.28-chaos/drivers/net/wireless/ath5k/base.c --- linux-2.6.28/drivers/net/wireless/ath5k/base.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-chaos/drivers/net/wireless/ath5k/base.c 2009-02-06 21:38:43.000000000 -0500 @@ -1732,6 +1738,11 @@ goto accept; } + /* Allow CRC errors through */ + if (rs.rs_status & AR5K_RXERR_CRC) { + goto accept; + } + /* let crypto-error packets fall through in MNTR */ if ((rs.rs_status & ~(AR5K_RXERR_DECRYPT|AR5K_RXERR_MIC)) ||
Patch
aircrack-ng/patches/ath5k-radiotap-fragfix-2.6.28-rc8-wl.patch
diff --git a/drivers/net/wireless/ath5k/attach.c b/drivers/net/wireless/ath5k/attach.c index 51d5698..49d82d7 100644 --- a/drivers/net/wireless/ath5k/attach.c +++ b/drivers/net/wireless/ath5k/attach.c @@ -317,9 +317,16 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version) goto err_free; } + /* Set MAC address */ + ret = ath5k_eeprom_read_mac(ah, mac); + if (ret) { + ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n", + sc->pdev->device); + goto err_free; + } + - /* MAC address is cleared until add_interface */ ath5k_hw_set_lladdr(ah, mac); /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */ memset(ah->ah_bssid, 0xff, ETH_ALEN); ath5k_hw_set_associd(ah, ah->ah_bssid, 0); diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c index 9eb9871..ec0104f 100644 --- a/drivers/net/wireless/ath5k/base.c +++ b/drivers/net/wireless/ath5k/base.c @@ -1182,7 +1182,9 @@ ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf) bf->skbaddr = pci_map_single(sc->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); - if (info->flags & IEEE80211_TX_CTL_NO_ACK) + if ((info->flags & IEEE80211_TX_CTL_NO_ACK) && + !((info->flags & IEEE80211_TX_CTL_INJECTED) && + (ieee80211_has_morefrags(((struct ieee80211_hdr *)skb->data)->frame_control)))) flags |= AR5K_TXDESC_NOACK; pktlen = skb->len;
Patch
aircrack-ng/patches/ath5k_regdomain_override.patch
PaulFertser> Get _your_ country code from regd.h, add 32768 and supply as a parameter. [email protected] --- linux-2.6.32-gentoo-r1-orig/drivers/net/wireless/ath/ath5k/base.c 2009-12-03 06:51:21.000000000 +0300 +++ linux-2.6.32-gentoo-r1/drivers/net/wireless/ath/ath5k/base.c 2010-01-16 00:02:51.000000000 +0300 @@ -68,6 +68,11 @@ module_param_named(all_channels, modparam_all_channels, bool, S_IRUGO); MODULE_PARM_DESC(all_channels, "Expose all channels the device can use."); +static int modparam_override_eeprom_regdomain = -1; +module_param_named(override_eeprom_regdomain, + modparam_override_eeprom_regdomain, int, S_IRUGO); +MODULE_PARM_DESC(override_eeprom_regdomain, "Override regdomain hardcoded in EEPROM with this value (DANGEROUS)."); + /******************\ * Internal defines * @@ -572,6 +577,15 @@ goto err_irq; } + if (modparam_override_eeprom_regdomain != -1) { + ATH5K_ERR(sc, "DANGER! You're overriding EEPROM-defined regulatory domain.\n"); + ATH5K_ERR(sc, "Your card was not certified to operate on the domain you choosed.\n"); + ATH5K_ERR(sc, "This might result in a violation of your local regulatory rules.\n"); + ATH5K_ERR(sc, "Do not ever do that unless you really know what you do!\n"); + sc->ah->ah_capabilities.cap_eeprom.ee_regdomain = + modparam_override_eeprom_regdomain; + } + /* set up multi-rate retry capabilities */ if (sc->ah->ah_version == AR5K_AR5212) { hw->max_rates = 4;
Patch
aircrack-ng/patches/ath9k_regdomain_override.patch
PaulFertser> Get _your_ country code from regd.h, add 32768 and supply as a parameter. [email protected] --- linux-2.6.32-gentoo-r1-orig/drivers/net/wireless/ath/ath9k/main.c 2009-12-03 06:51:21.000000000 +0300 +++ linux-2.6.32-gentoo-r1/drivers/net/wireless/ath/ath9k/main.c 2010-01-16 02:04:00.000000000 +0300 @@ -28,6 +28,11 @@ module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444); MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption"); +static int modparam_override_eeprom_regdomain = -1; +module_param_named(override_eeprom_regdomain, + modparam_override_eeprom_regdomain, int, S_IRUGO); +MODULE_PARM_DESC(override_eeprom_regdomain, "Override regdomain hardcoded in EEPROM with this value (DANGEROUS)."); + /* We use the hw_value as an index into our private channel structure */ #define CHAN2G(_freq, _idx) { \ @@ -1588,6 +1593,14 @@ if (error != 0) return error; + if (modparam_override_eeprom_regdomain != -1) { + printk(KERN_ERR "ath9k: DANGER! You're overriding EEPROM-defined regulatory domain.\n"); + printk(KERN_ERR "ath9k: Your card was not certified to operate on the domain you choosed.\n"); + printk(KERN_ERR "ath9k: This might result in a violation of your local regulatory rules.\n"); + printk(KERN_ERR "ath9k: Do not ever do that unless you really know what you do!\n"); + sc->common.regulatory.current_rd = modparam_override_eeprom_regdomain; + } + /* get mac address from hardware and set in mac80211 */ SET_IEEE80211_PERM_ADDR(hw, sc->sc_ah->macaddr);
Patch
aircrack-ng/patches/b43-injection-2.6.24.4.patch
# Kernel >= 2.6.24.1 highly recommended # Fixes injection speed (up to 350 pps) # Fixes fragmented injection (requires mac80211 patch too) diff -bBur linux-2.6.24.4/drivers/net/wireless/b43/main.c linux-2.6.24.4-sud/drivers/net/wireless/b43/main.c --- linux-2.6.24.4/drivers/net/wireless/b43/main.c 2008-04-05 16:25:11.000000000 +0200 +++ linux-2.6.24.4-sud/drivers/net/wireless/b43/main.c 2008-04-05 16:45:11.000000000 +0200 @@ -2516,6 +2516,11 @@ goto out; if (unlikely(b43_status(dev) < B43_STAT_STARTED)) goto out; + + if (ctl->type == IEEE80211_IF_TYPE_MNTR) { + ctl->flags |= IEEE80211_TXCTL_NO_ACK; + } + /* DMA-TX is done without a global lock. */ if (b43_using_pio(dev)) { spin_lock_irqsave(&wl->irq_lock, flags); diff -bBur linux-2.6.24.4/drivers/net/wireless/b43/xmit.c linux-2.6.24.4-sud/drivers/net/wireless/b43/xmit.c --- linux-2.6.24.4/drivers/net/wireless/b43/xmit.c 2008-04-05 16:25:11.000000000 +0200 +++ linux-2.6.24.4-sud/drivers/net/wireless/b43/xmit.c 2008-04-05 16:48:51.000000000 +0200 @@ -295,7 +295,8 @@ /* MAC control */ if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK)) mac_ctl |= B43_TX4_MAC_ACK; - if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && + if ( (txctl->type != IEEE80211_IF_TYPE_MNTR) && + !(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL))) mac_ctl |= B43_TX4_MAC_HWSEQ; if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT) diff -bBur linux-2.6.24.4/drivers/net/wireless/b43legacy/main.c linux-2.6.24.4-sud/drivers/net/wireless/b43legacy/main.c --- linux-2.6.24.4/drivers/net/wireless/b43legacy/main.c 2008-04-05 16:25:11.000000000 +0200 +++ linux-2.6.24.4-sud/drivers/net/wireless/b43legacy/main.c 2008-04-05 16:45:11.000000000 +0200 @@ -2379,6 +2379,11 @@ goto out; if (unlikely(b43legacy_status(dev) < B43legacy_STAT_STARTED)) goto out; + + if (ctl->type == IEEE80211_IF_TYPE_MNTR) { + ctl->flags |= IEEE80211_TXCTL_NO_ACK; + } + /* DMA-TX is done without a global lock. */ if (b43legacy_using_pio(dev)) { spin_lock_irqsave(&wl->irq_lock, flags); diff -bBur linux-2.6.24.4/drivers/net/wireless/b43legacy/xmit.c linux-2.6.24.4-sud/drivers/net/wireless/b43legacy/xmit.c --- linux-2.6.24.4/drivers/net/wireless/b43legacy/xmit.c 2008-04-05 16:25:11.000000000 +0200 +++ linux-2.6.24.4-sud/drivers/net/wireless/b43legacy/xmit.c 2008-04-05 16:49:02.000000000 +0200 @@ -290,7 +290,8 @@ /* MAC control */ if (!(txctl->flags & IEEE80211_TXCTL_NO_ACK)) mac_ctl |= B43legacy_TX4_MAC_ACK; - if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && + if ( (txctl->type != IEEE80211_IF_TYPE_MNTR) && + !(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL))) mac_ctl |= B43legacy_TX4_MAC_HWSEQ; if (txctl->flags & IEEE80211_TXCTL_FIRST_FRAGMENT)
Patch
aircrack-ng/patches/b43-injection-2.6.26-rc8-wl.patch
diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c index bf6f6c1..735f2d0 100644 --- a/drivers/net/wireless/b43/xmit.c +++ b/drivers/net/wireless/b43/xmit.c @@ -315,9 +315,15 @@ int b43_generate_txhdr(struct b43_wldev *dev, } /* MAC control */ - if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) + /* dev->wl->if_type returns IEEE80211_IF_TYPE_INVALID instead of + * IEEE80211_IF_TYPE_MNTR for monitor interfaces, as monitor mode + * is not considered "operating" by mac80211. + */ + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + !(info->flags & IEEE80211_TX_CTL_NO_ACK)) mac_ctl |= B43_TXH_MAC_ACK; - if (!ieee80211_is_pspoll(fctl)) + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + !ieee80211_is_pspoll(fctl)) mac_ctl |= B43_TXH_MAC_HWSEQ; if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) mac_ctl |= B43_TXH_MAC_STMSDU; diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c index a354078..d4d6e61 100644 --- a/drivers/net/wireless/b43legacy/xmit.c +++ b/drivers/net/wireless/b43legacy/xmit.c @@ -293,9 +293,15 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev, } /* MAC control */ - if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) + /* dev->wl->if_type returns IEEE80211_IF_TYPE_INVALID instead of + * IEEE80211_IF_TYPE_MNTR for monitor interfaces, as monitor mode + * is not considered "operating" by mac80211. + */ + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + !(info->flags & IEEE80211_TX_CTL_NO_ACK)) mac_ctl |= B43legacy_TX4_MAC_ACK; - if (!(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + !(((fctl & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) && ((fctl & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL))) mac_ctl |= B43legacy_TX4_MAC_HWSEQ; if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
Patch
aircrack-ng/patches/b43-injection-2.6.26-wl.patch
diff --git a/drivers/net/wireless/b43/xmit.c b/drivers/net/wireless/b43/xmit.c index 8d54502..3e0e088 100644 --- a/drivers/net/wireless/b43/xmit.c +++ b/drivers/net/wireless/b43/xmit.c @@ -315,10 +315,16 @@ int b43_generate_txhdr(struct b43_wldev *dev, } /* MAC control */ - if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) + /* dev->wl->if_type returns IEEE80211_IF_TYPE_INVALID instead of + * IEEE80211_IF_TYPE_MNTR for monitor interfaces, as monitor mode + * is not considered "operating" by mac80211. + */ + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + !(info->flags & IEEE80211_TX_CTL_NO_ACK)) mac_ctl |= B43_TXH_MAC_ACK; /* use hardware sequence counter as the non-TID counter */ - if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) mac_ctl |= B43_TXH_MAC_HWSEQ; if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) mac_ctl |= B43_TXH_MAC_STMSDU; diff --git a/drivers/net/wireless/b43legacy/xmit.c b/drivers/net/wireless/b43legacy/xmit.c index e969ed8..c19409e 100644 --- a/drivers/net/wireless/b43legacy/xmit.c +++ b/drivers/net/wireless/b43legacy/xmit.c @@ -293,9 +293,15 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev, } /* MAC control */ - if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) + /* dev->wl->if_type returns IEEE80211_IF_TYPE_INVALID instead of + * IEEE80211_IF_TYPE_MNTR for monitor interfaces, as monitor mode + * is not considered "operating" by mac80211. + */ + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + !(info->flags & IEEE80211_TX_CTL_NO_ACK)) mac_ctl |= B43legacy_TX4_MAC_ACK; - if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) + if (dev->wl->if_type != 5 && dev->wl->if_type != 0 && + info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) mac_ctl |= B43legacy_TX4_MAC_HWSEQ; if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) mac_ctl |= B43legacy_TX4_MAC_STMSDU;
Patch
aircrack-ng/patches/bcm43xx-injection-linux-2.6.20.patch
--- linux/drivers/net/wireless/bcm43xx/bcm43xx_main.c 2007-04-17 16:39:08.000000000 +0200 +++ linux-bcm43xx-patch/drivers/net/wireless/bcm43xx/bcm43xx_main.c 2007-04-20 00:09:09.000000000 +0200 @@ -104,6 +104,13 @@ #endif /* CONFIG_BCM43XX_DEBUG*/ +static ssize_t bcm43xx_inject_nofcs(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t cnt); +static DEVICE_ATTR(inject_nofcs, 0200, + NULL, bcm43xx_inject_nofcs); + /* If you want to debug with just a single device, enable this, * where the string is the pci device ID (as given by the kernel's * pci_name function) of the device to be used. @@ -3365,6 +3372,8 @@ static void bcm43xx_free_board(struct bcm43xx_private *bcm) { bcm43xx_rng_exit(bcm); + + device_remove_file(&bcm->pci_dev->dev, &dev_attr_inject_nofcs); bcm43xx_sysfs_unregister(bcm); bcm43xx_periodic_tasks_delete(bcm); @@ -3636,6 +3645,10 @@ err = bcm43xx_rng_init(bcm); if (err) goto err_sysfs_unreg; + + err = device_create_file(&bcm->pci_dev->dev, &dev_attr_inject_nofcs); + if (err) + goto err_inject_if; bcm43xx_periodic_tasks_setup(bcm); /*FIXME: This should be handled by softmac instead. */ @@ -3645,7 +3658,8 @@ mutex_unlock(&(bcm)->mutex); return err; - +err_inject_if: + device_remove_file(&bcm->pci_dev->dev, &dev_attr_inject_nofcs); err_sysfs_unreg: bcm43xx_sysfs_unregister(bcm); err_wlshutdown: @@ -3892,6 +3906,48 @@ return err; } +static ssize_t bcm43xx_inject_nofcs(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t cnt) +{ + struct bcm43xx_private *bcm = dev_to_bcm(dev); + struct ieee80211_txb *faketxb; + struct sk_buff *skb; + unsigned long flags; + int err = -ENODEV; + + faketxb = kzalloc(sizeof(struct ieee80211_txb) + sizeof(void *), GFP_KERNEL); + if (!faketxb) + return -ENOMEM; + faketxb->nr_frags = 1; + faketxb->frag_size = cnt; + faketxb->payload_size = cnt; + skb = __dev_alloc_skb(cnt + bcm->ieee->tx_headroom, GFP_KERNEL); + if (!skb) { + kfree(faketxb); + return -ENOMEM; + } + skb_reserve(skb, bcm->ieee->tx_headroom); + memcpy(skb_put(skb, cnt), buf, cnt); + faketxb->fragments[0] = skb; + + spin_lock_irqsave(&bcm->irq_lock, flags); + + if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) + err = bcm43xx_tx(bcm, faketxb); + + spin_unlock_irqrestore(&bcm->irq_lock, flags); + + if (unlikely(err)) { + dev_kfree_skb(skb); + kfree(faketxb); + return err; + } + + return cnt; +} + static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev, u8 channel) {
Patch
aircrack-ng/patches/bcm43xx-injection-linux-2.6.22-v2.patch
--- linux-source-2.6.22/drivers/net/wireless/bcm43xx/bcm43xx_main.c 2007-10-08 10:14:25.000000000 +1300 +++ linux-source-2.6.22-bcm43xx-patch/drivers/net/wireless/bcm43xx/bcm43xx_main.c 2007-10-08 10:13:12.000000000 +1300 @@ -3324,9 +3324,17 @@ } /* This is the opposite of bcm43xx_init_board() */ + +static ssize_t bcm43xx_inject_nofcs(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t cnt); +static DEVICE_ATTR(inject_nofcs, 0200, + NULL, bcm43xx_inject_nofcs); static void bcm43xx_free_board(struct bcm43xx_private *bcm) { bcm43xx_rng_exit(bcm); + device_remove_file(&bcm->pci_dev->dev, &dev_attr_inject_nofcs); bcm43xx_sysfs_unregister(bcm); mutex_lock(&(bcm)->mutex); @@ -3581,6 +3589,9 @@ return err; } + + + static int bcm43xx_init_board(struct bcm43xx_private *bcm) { int err; @@ -3603,6 +3614,9 @@ err = bcm43xx_rng_init(bcm); if (err) goto err_sysfs_unreg; + err = device_create_file(&bcm->pci_dev->dev, &dev_attr_inject_nofcs); + if (err) + goto err_inject_if; bcm43xx_periodic_tasks_setup(bcm); /*FIXME: This should be handled by softmac instead. */ @@ -3613,6 +3627,9 @@ return err; +err_inject_if: + device_remove_file(&bcm->pci_dev->dev, &dev_attr_inject_nofcs); + err_sysfs_unreg: bcm43xx_sysfs_unregister(bcm); err_wlshutdown: @@ -3866,6 +3883,49 @@ return err; } +static ssize_t bcm43xx_inject_nofcs(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t cnt) +{ + struct bcm43xx_private *bcm = dev_to_bcm(dev); + struct ieee80211_txb *faketxb; + struct sk_buff *skb; + unsigned long flags; + int err = -ENODEV; + + faketxb = kzalloc(sizeof(struct ieee80211_txb) + sizeof(void *), GFP_KERNEL); + if (!faketxb) + return -ENOMEM; + faketxb->nr_frags = 1; + faketxb->frag_size = cnt; + faketxb->payload_size = cnt; + skb = __dev_alloc_skb(cnt + bcm->ieee->tx_headroom, GFP_KERNEL); + if (!skb) { + kfree(faketxb); + return -ENOMEM; + } + skb_reserve(skb, bcm->ieee->tx_headroom); + memcpy(skb_put(skb, cnt), buf, cnt); + faketxb->fragments[0] = skb; + + spin_lock_irqsave(&bcm->irq_lock, flags); + + if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) + err = bcm43xx_tx(bcm, faketxb); + + spin_unlock_irqrestore(&bcm->irq_lock, flags); + + if (unlikely(err)) { + dev_kfree_skb(skb); + kfree(faketxb); + return err; + } + + return cnt; +} + + static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev, u8 channel) { diff -ur linux/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c linux-bcm43xx-patch2/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c --- linux/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c 2007-02-04 19:44:54.000000000 +0100 +++ linux-bcm43xx-patch2/drivers/net/wireless/bcm43xx/bcm43xx_xmit.c 2008-03-01 16:24:43.000000000 +0100 -352,7 +352,8 @@ /* Set the FLAGS field */ if (!is_multicast_ether_addr(wireless_header->addr1) && - !is_broadcast_ether_addr(wireless_header->addr1)) + !is_broadcast_ether_addr(wireless_header->addr1) && + (bcm->ieee->iw_mode != IW_MODE_MONITOR)) flags |= BCM43xx_TXHDRFLAG_EXPECTACK; if (1 /* FIXME: PS poll?? */) flags |= 0x10; // FIXME: unknown meaning.
Patch
aircrack-ng/patches/build_compat_wireless_2.6.33.patch
See http://marc.info/?l=linux-wireless&m=126909721011922&w=2 Index: compat-wireless-2010-03-19/scripts/gen-compat-autoconf.sh =================================================================== --- compat-wireless-2010-03-19.orig/scripts/gen-compat-autoconf.sh 2010-03-20 15:26:22.604720545 +0100 +++ compat-wireless-2010-03-19/scripts/gen-compat-autoconf.sh 2010-03-20 15:27:49.212236531 +0100 @@ -145,7 +145,11 @@ kernel_version_req $OLDEST_KERNEL_SUPPORTED # Handle core kernel wireless depenencies here +echo '#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)' +define_config_req CONFIG_CFG80211_WEXT +echo '#else' define_config_req CONFIG_WIRELESS_EXT +echo '#endif' # For each CONFIG_FOO=x option for i in $(grep '^CONFIG_' $COMPAT_CONFIG); do
Patch
aircrack-ng/patches/channel-negative-one-maxim.patch
commit fffd6e63ea75850dafbf2ccfb38a4189f43c0282 Author: Maxim Levitsky <maximlevitsky@xxxxxxxxx> Date: Tue Jun 1 15:43:21 2010 +0300 wireless: allow to retrieve the channel set on monitor interface This will allow to preserve compatibility with userspace Signed-off-by: Maxim Levitsky <maximlevitsky@xxxxxxxxx> diff --git a/net/wireless/chan.c b/net/wireless/chan.c index b01a6f6..09d979b 100644 --- a/net/wireless/chan.c +++ b/net/wireless/chan.c @@ -49,9 +49,12 @@ int cfg80211_set_freq(struct cfg80211_registered_device *rdev, { struct ieee80211_channel *chan; int result; + struct wireless_dev *mon_dev = NULL; - if (wdev && wdev->iftype == NL80211_IFTYPE_MONITOR) + if (wdev && wdev->iftype == NL80211_IFTYPE_MONITOR) { + mon_dev = wdev; wdev = NULL; + } if (wdev) { ASSERT_WDEV_LOCK(wdev); @@ -76,5 +79,8 @@ int cfg80211_set_freq(struct cfg80211_registered_device *rdev, if (wdev) wdev->channel = chan; + if (mon_dev) + mon_dev->channel = chan; + return 0; }
Patch
aircrack-ng/patches/fix_ath5k_no_data_in_monitor_mode.patch
Thanks to Weedy who did an awesome work tracking this down diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c index c4adf98..5056410 100644 --- a/drivers/net/wireless/ath/ath5k/base.c +++ b/drivers/net/wireless/ath/ath5k/base.c @@ -2918,8 +2918,6 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw, struct ath5k_hw *ah = sc->ah; u32 mfilt[2], rfilt; - mutex_lock(&sc->lock); - mfilt[0] = multicast; mfilt[1] = multicast >> 32; @@ -2970,25 +2968,22 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw, /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */ - switch (sc->opmode) { - case NL80211_IFTYPE_MESH_POINT: - case NL80211_IFTYPE_MONITOR: - rfilt |= AR5K_RX_FILTER_CONTROL | - AR5K_RX_FILTER_BEACON | - AR5K_RX_FILTER_PROBEREQ | - AR5K_RX_FILTER_PROM; - break; - case NL80211_IFTYPE_AP: - case NL80211_IFTYPE_ADHOC: - rfilt |= AR5K_RX_FILTER_PROBEREQ | - AR5K_RX_FILTER_BEACON; - break; - case NL80211_IFTYPE_STATION: - if (sc->assoc) - rfilt |= AR5K_RX_FILTER_BEACON; - default: - break; - } + if (sc->opmode == NL80211_IFTYPE_MONITOR) + rfilt |= AR5K_RX_FILTER_CONTROL | AR5K_RX_FILTER_BEACON | + AR5K_RX_FILTER_PROBEREQ | AR5K_RX_FILTER_PROM; + if (sc->opmode != NL80211_IFTYPE_STATION) + rfilt |= AR5K_RX_FILTER_PROBEREQ; + if (sc->opmode != NL80211_IFTYPE_AP && + sc->opmode != NL80211_IFTYPE_MESH_POINT && + test_bit(ATH_STAT_PROMISC, sc->status)) + rfilt |= AR5K_RX_FILTER_PROM; + if ((sc->opmode == NL80211_IFTYPE_STATION && sc->assoc) || + sc->opmode == NL80211_IFTYPE_ADHOC || + sc->opmode == NL80211_IFTYPE_AP) + rfilt |= AR5K_RX_FILTER_BEACON; + if (sc->opmode == NL80211_IFTYPE_MESH_POINT) + rfilt |= AR5K_RX_FILTER_CONTROL | AR5K_RX_FILTER_BEACON | + AR5K_RX_FILTER_PROBEREQ | AR5K_RX_FILTER_PROM; /* Set filters */ ath5k_hw_set_rx_filter(ah, rfilt); @@ -2998,8 +2993,6 @@ static void ath5k_configure_filter(struct ieee80211_hw *hw, /* Set the cached hw filter flags, this will alter actually * be set in HW */ sc->filter_flags = rfilt; - - mutex_unlock(&sc->lock); } static int
Patch
aircrack-ng/patches/hostap-driver-0.4.7.patch
diff -ur hostap-driver-0.4.7/driver/etc/hostap_cs.conf hostap-driver-0.4.7-aircrack-ng/driver/etc/hostap_cs.conf --- hostap-driver-0.4.7/driver/etc/hostap_cs.conf 2005-11-06 14:01:09.000000000 -0500 +++ hostap-driver-0.4.7-aircrack-ng/driver/etc/hostap_cs.conf 2006-03-20 14:45:13.000000000 -0500 @@ -102,17 +102,17 @@ card "Level-One WPC-0100" version "Digital Data Communications", "WPC-0100", "Version 00.00" - manfid 0x0156, 0x0002 +# manfid 0x0156, 0x0002 bind "hostap_cs" card "Belkin 802.11b WLAN PCMCIA" version "Belkin", "11Mbps Wireless Notebook Network Adapter", "Version 01.02" - manfid 0x0156, 0x0002 +# manfid 0x0156, 0x0002 bind "hostap_cs" card "Senao SL-2011CD/SL-2011CDPLUS" version "INTERSIL", "HFA384x/IEEE", "Version 01.02" - manfid 0x0156, 0x0002 +# manfid 0x0156, 0x0002 bind "hostap_cs" card "Fulbond Airbond XI-300B" diff -ur hostap-driver-0.4.7/driver/modules/hostap_80211_tx.c hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_80211_tx.c --- hostap-driver-0.4.7/driver/modules/hostap_80211_tx.c 2005-08-06 13:55:14.000000000 -0400 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_80211_tx.c 2006-03-20 14:45:13.000000000 -0500 @@ -51,6 +51,9 @@ int to_assoc_ap = 0; struct hostap_skb_tx_data *meta; + if (local->iw_mode == IW_MODE_MONITOR) + goto xmit; + if (skb->len < ETH_HLEN) { printk(KERN_DEBUG "%s: hostap_data_start_xmit: short skb " "(len=%d)\n", dev->name, skb->len); @@ -216,6 +219,7 @@ memcpy(skb_put(skb, ETH_ALEN), &hdr.addr4, ETH_ALEN); } +xmit: iface->stats.tx_packets++; iface->stats.tx_bytes += skb->len; @@ -377,8 +381,6 @@ } if (skb->len < 24) { - printk(KERN_DEBUG "%s: hostap_master_start_xmit: short skb " - "(len=%d)\n", dev->name, skb->len); ret = 0; iface->stats.tx_dropped++; goto fail; diff -ur hostap-driver-0.4.7/driver/modules/hostap.c hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap.c --- hostap-driver-0.4.7/driver/modules/hostap.c 2005-08-06 13:47:10.000000000 -0400 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap.c 2006-03-20 14:45:13.000000000 -0500 @@ -407,7 +407,7 @@ if (local->iw_mode == IW_MODE_REPEAT) return HFA384X_PORTTYPE_WDS; if (local->iw_mode == IW_MODE_MONITOR) - return HFA384X_PORTTYPE_PSEUDO_IBSS; + return 5; /*HFA384X_PORTTYPE_PSEUDO_IBSS;*/ return HFA384X_PORTTYPE_HOSTAP; } diff -ur hostap-driver-0.4.7/driver/modules/hostap_config.h hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_config.h --- hostap-driver-0.4.7/driver/modules/hostap_config.h 2005-11-20 20:42:12.000000000 -0500 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_config.h 2006-03-20 14:45:13.000000000 -0500 @@ -59,7 +59,7 @@ * In addition, please note that it is possible to kill your card with * non-volatile download if you are using incorrect image. This feature has not * been fully tested, so please be careful with it. */ -/* #define PRISM2_NON_VOLATILE_DOWNLOAD */ +#define PRISM2_NON_VOLATILE_DOWNLOAD #endif /* PRISM2_DOWNLOAD_SUPPORT */ /* Include wireless extensions sub-ioctl support even if wireless extensions diff -ur hostap-driver-0.4.7/driver/modules/hostap_cs.c hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_cs.c --- hostap-driver-0.4.7/driver/modules/hostap_cs.c 2005-11-06 14:01:09.000000000 -0500 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_cs.c 2006-03-20 15:11:53.000000000 -0500 @@ -929,53 +929,98 @@ #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,67) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)) static struct pcmcia_device_id hostap_cs_ids[] = { - PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), - PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), - PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), - PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000), - PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), - PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), - PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002), - PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612), - PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613), - PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002), - PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002), - PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001), - PCMCIA_DEVICE_MANF_CARD(0x1668, 0x0101), - PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001), - PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300), - PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), - PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), - PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), - PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010), - PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus", - 0x7a954bd9, 0x74be00c6), - PCMCIA_DEVICE_PROD_ID1234( - "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P", - "Eval-RevA", - 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e), - PCMCIA_DEVICE_PROD_ID123( - "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02", - 0xe6ec52ce, 0x08649af2, 0x4b74baa0), - PCMCIA_DEVICE_PROD_ID123( - "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02", - 0x71b18589, 0xb6f1b0ab, 0x4b74baa0), - PCMCIA_DEVICE_PROD_ID123( - "Instant Wireless ", " Network PC CARD", "Version 01.02", - 0x11d901af, 0x6e9bd926, 0x4b74baa0), - PCMCIA_DEVICE_PROD_ID123( - "SMC", "SMC2632W", "Version 01.02", - 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0), - PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card", - 0x54f7c49c, 0x15a75e5b), - PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", - 0x74c5e40d, 0xdb472a18), - PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card", - 0x0733cc81, 0x0c52f395), - PCMCIA_DEVICE_PROD_ID12( - "ZoomAir 11Mbps High", "Rate wireless Networking", - 0x273fe3db, 0x32a1eaee), - PCMCIA_DEVICE_NULL + PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), // SonicWALL Long Range Wireless Card + PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7110), // D-Link DWL-650 rev P 802.11b WLAN card + PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), // Sohoware NCP110, Philips 802.11b +// PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0001), // Intel PRO/Wireless 2011 (Symbol24) + PCMCIA_DEVICE_MANF_CARD(0x0089, 0x0002), // AnyPoint(TM) Wireless II PC Card + PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), // 3Com AirConnect PCI 777A + PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000), // PROXIM RangeLAN-DS/LAN PC CARD + PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), // Compaq WL100 11 Mbps Wireless Adapter +// PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), // Mostly Lucent Orinoco (HermesI), but also some Prism2 :( +// PCMCIA_DEVICE_MANF_CARD(0x016b, 0x0001), // Ericsson WLAN Card C11 (Symbol24) +// PCMCIA_DEVICE_MANF_CARD(0x01eb, 0x080a), // Nortel eMobility 802.11 Wireless Adapter (Symbol24) + PCMCIA_DEVICE_MANF_CARD(0x01ff, 0x0008), // Intermec MobileLAN 11Mbps 802.11b WLAN Card + PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002), // Samsung SWL2000-N 11Mb/s WLAN Card +// PCMCIA_DEVICE_MANF_CARD(0x0261, 0x0002), // AirWay 802.11 Adapter (HermesI) +// PCMCIA_DEVICE_MANF_CARD(0x0268, 0x0001), // ARtem Onair (HermesI) +// PCMCIA_DEVICE_MANF_CARD(0x026c, 0x0001), // Symbol Technologies LA4111 (Symbol24) + PCMCIA_DEVICE_MANF_CARD(0x026f, 0x0305), // Buffalo WLI-PCM-S11 + PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612), // Linksys WPC11 Version 2.5 + PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613), // Linksys WPC11 Version 3 + PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002), // Compaq HNW-100 11 Mbps Wireless Adapter + PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0673), // Linksys WCF12 11Mbps 802.11b WLAN Card (Prism 3) + PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002), // ASUS SpaceLink WL-100 + PCMCIA_DEVICE_MANF_CARD(0x02ac, 0x0002), // SpeedStream SS1021 Wireless Adapter + PCMCIA_DEVICE_MANF_CARD(0x02ac, 0x3021), // SpeedStream SS1021 Wireless Adapter (newer) + PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001), // Microsoft Wireless Notebook Adapter MN-520 + PCMCIA_DEVICE_MANF_CARD(0x14ea, 0xb001), // PLANEX RoadLannerWave GW-NS11H + PCMCIA_DEVICE_MANF_CARD(0x1668, 0x0101), // ActionTec 802CI2/HCW01170-01 + PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001), // Airvast ? + PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300), // Airvast WN-100 + PCMCIA_DEVICE_MANF_CARD(0x9005, 0x0021), // Adaptec Ultra Wireless ANW-8030 + PCMCIA_DEVICE_MANF_CARD(0xc001, 0x0008), // CONTEC FLEXSCAN/FX-DDS110-PCC + PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), // Corega KK Wireless LAN PCC-11 + PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002), // Conceptronic CON11Cpro, EMTAC A2424i + PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), // Safeway 802.11b, ZCOMAX AirRunner/XI-300 + PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), // D-Link DCF660, ZCOMAX XI-325HP 200mw + PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010), // SMC2532W-B V2 + + PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus", 0x7a954bd9, 0x74be00c6), + PCMCIA_DEVICE_PROD_ID12(" ", "IEEE 802.11 Wireless LAN/PC Card", 0x3b6e20c8, 0xefccafe9), +// PCMCIA_DEVICE_PROD_ID12("3Com", "3CRWE737A AirConnect Wireless LAN PC Card", 0x41240e5b, 0x56010af3), // Symbol24 + PCMCIA_DEVICE_PROD_ID12("ACTIONTEC", "PRISM Wireless LAN PC Card", 0x393089da, 0xa71e69d5), + PCMCIA_DEVICE_PROD_ID123("Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02", 0xe6ec52ce, 0x08649af2, 0x4b74baa0), + PCMCIA_DEVICE_PROD_ID123("AIRVAST", "IEEE 802.11b Wireless PCMCIA Card", "HFA3863", 0xea569531, 0x4bcb9645, 0x355cb092), + PCMCIA_DEVICE_PROD_ID12("Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio", 0x5cd01705, 0x4271660f), + PCMCIA_DEVICE_PROD_ID12("ASUS", "802_11b_PC_CARD_25", 0x78fc06ee, 0xdb9aa842), + PCMCIA_DEVICE_PROD_ID12("ASUS", "802_11B_CF_CARD_25", 0x78fc06ee, 0x45a50c1e), +// PCMCIA_DEVICE_PROD_ID12("Avaya Communication", "Avaya Wireless PC Card", 0xd8a43b78, 0x0d341169), // HermesI + PCMCIA_DEVICE_PROD_ID12("BENQ", "AWL100 PCMCIA ADAPTER", 0x35dadc74, 0x01f7fedb), +// PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-PCM-L11G", 0x2decece3, 0xf57ca4b3), // HermesI + PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", 0x2decece3, 0x82067c18), +// PCMCIA_DEVICE_PROD_ID12("Cabletron", "RoamAbout 802.11 DS", 0x32d445f5, 0xedeffd90), // HermesI + PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card", 0x54f7c49c, 0x15a75e5b), + PCMCIA_DEVICE_PROD_ID123("corega", "WL PCCL-11", "ISL37300P", 0x0a21501a, 0x59868926, 0xc9049a39), + PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCC-11", 0x5261440f, 0xa6405584), + PCMCIA_DEVICE_PROD_ID12("corega K.K.", "Wireless LAN PCCA-11", 0x5261440f, 0xdf6115f9), + PCMCIA_DEVICE_PROD_ID12("D", "Link DRC-650 11Mbps WLAN Card", 0x71b18589, 0xf144e3ac), + PCMCIA_DEVICE_PROD_ID123("D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02", 0x71b18589, 0xb6f1b0ab, 0x4b74baa0), +// PCMCIA_DEVICE_PROD_ID12("D-Link Corporation", "D-Link DWL-650H 11Mbps WLAN Adapter", 0xef544d24, 0xcd8ea916), // Symbol24 + PCMCIA_DEVICE_PROD_ID12("Digital Data Communications", "WPC-0100", 0xfdd73470, 0xe0b6f146), +// PCMCIA_DEVICE_PROD_ID12("ELSA", "AirLancer MC-11", 0x4507a33a, 0xef54f0e3), // HermesI + PCMCIA_DEVICE_PROD_ID12("HyperLink", "Wireless PC Card 11Mbps", 0x56cc3f1a, 0x0bcf220c), + PCMCIA_DEVICE_PROD_ID123("Instant Wireless ", " Network PC CARD", "Version 01.02", 0x11d901af, 0x6e9bd926, 0x4b74baa0), +// PCMCIA_DEVICE_PROD_ID12("Intel", "PRO/Wireless 2011 LAN PC Card", 0x816cc815, 0x07f58077), // HermesI + PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", 0x74c5e40d, 0xdb472a18), + PCMCIA_DEVICE_PROD_ID12("INTERSIL", "I-GATE 11M PC Card / PC Card plus", 0x74c5e40d, 0x8304ff77), + PCMCIA_DEVICE_PROD_ID1234("Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P", "Eval-RevA", 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e), + PCMCIA_DEVICE_PROD_ID123("Intersil", "PRISM Freedom PCMCIA Adapter", "ISL37100P", 0x4b801a17, 0xf222ec2d, 0x630d52b2), + PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", 0x74c5e40d, 0xdb472a18), + PCMCIA_DEVICE_PROD_ID12("LeArtery", "SYNCBYAIR 11Mbps Wireless LAN PC Card", 0x7e3b326a, 0x49893e92), + PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card", 0x0733cc81, 0x0c52f395), +// PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/IEEE", 0x23eb9949, 0xc562e72a), // HermesI +// PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11", 0x481e0094, 0x7360e410), // HermesI +// PCMCIA_DEVICE_PROD_ID12("MELCO", "WLI-PCM-L11G", 0x481e0094, 0xf57ca4b3), // HermesI + PCMCIA_DEVICE_PROD_ID12("Microsoft", "Wireless Notebook Adapter MN-520", 0x5961bf85, 0x6eec8c01), +// PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/IEEE", 0x24358cd4, 0xc562e72a), // HermesI + PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401 Wireless PC", "Card", 0xa37434e9, 0x9762e8f1), + PCMCIA_DEVICE_PROD_ID12("NETGEAR MA401RA Wireless PC", "Card", 0x0306467f, 0x9762e8f1), +// PCMCIA_DEVICE_PROD_ID12("Nortel Networks", "emobility 802.11 Wireless LAN PC Card", 0x2d617ea0, 0x88cd5767), // Symbol24 + PCMCIA_DEVICE_PROD_ID12("OEM", "PRISM2 IEEE 802.11 PC-Card", 0xfea54c90, 0x48f2bdd6), + PCMCIA_DEVICE_PROD_ID12("OTC", "Wireless AirEZY 2411-PCC WLAN Card", 0x4ac44287, 0x235a6bed), + PCMCIA_DEVICE_PROD_ID123("PCMCIA", "11M WLAN Card v2.5", "ISL37300P", 0x281f1c5d, 0x6e440487, 0xc9049a39), + PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-CF110", 0x209f40ab, 0xd9715264), + PCMCIA_DEVICE_PROD_ID12("PLANEX", "GeoWave/GW-NS110", 0x209f40ab, 0x46263178), + PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PC CARD HARMONY 80211B", 0xc6536a5e, 0x090c3cd9), + PCMCIA_DEVICE_PROD_ID12("PROXIM", "LAN PCI CARD HARMONY 80211B", 0xc6536a5e, 0x9f494e26), + PCMCIA_DEVICE_PROD_ID12("SAMSUNG", "11Mbps WLAN Card", 0x43d74cb4, 0x579bd91b), +// PCMCIA_DEVICE_PROD_ID1("Symbol Technologies", 0x3f02b4d6), // Symbol24 +// PCMCIA_DEVICE_PROD_ID12("Symbol Technologies", "LA4111 Spectrum24 Wireless LAN PC Card", 0x3f02b4d6, 0x3663cb0e), // Symbol24 + PCMCIA_DEVICE_PROD_ID123("SMC", "SMC2632W", "Version 01.02", 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0), + PCMCIA_DEVICE_PROD_ID123("The Linksys Group, Inc.", "Instant Wireless Network PC Card", "ISL37300P", 0xa5f472c2, 0x590eb502, 0xc9049a39), + PCMCIA_DEVICE_PROD_ID12("ZoomAir 11Mbps High", "Rate wireless Networking", 0x273fe3db, 0x32a1eaee), + PCMCIA_DEVICE_NULL }; MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids); #endif /* >= 2.6.13 */ Only in hostap-driver-0.4.7-aircrack-ng/driver/modules: .hostap_cs.c.swp diff -ur hostap-driver-0.4.7/driver/modules/hostap_hw.c hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_hw.c --- hostap-driver-0.4.7/driver/modules/hostap_hw.c 2005-08-20 12:32:34.000000000 -0400 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_hw.c 2006-03-20 14:45:13.000000000 -0500 @@ -1005,6 +1005,35 @@ return fid; } +static int prism2_monitor_enable(struct net_device *dev) +{ + if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, 5)) { + printk(KERN_DEBUG "Port type setting for monitor mode " + "failed\n"); + return -EOPNOTSUPP; + } + + if (hfa384x_cmd(dev, HFA384X_CMDCODE_TEST | (0x0a << 8), + 0, NULL, NULL)) { + printk(KERN_DEBUG "Could not enter testmode 0x0a\n"); + return -EOPNOTSUPP; + } + + if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS, + HFA384X_WEPFLAGS_PRIVACYINVOKED | + HFA384X_WEPFLAGS_HOSTENCRYPT | + HFA384X_WEPFLAGS_HOSTDECRYPT)) { + printk(KERN_DEBUG "WEP flags setting failed\n"); + return -EOPNOTSUPP; + } + + if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE, 1)) { + printk(KERN_DEBUG "Could not set promiscuous mode\n"); + return -EOPNOTSUPP; + } + + return 0; +} static int prism2_reset_port(struct net_device *dev) { @@ -1028,6 +1057,10 @@ "port\n", dev->name); } + if (local->iw_mode == IW_MODE_MONITOR) + /* force mode 0x0a after port 0 reset */ + return prism2_monitor_enable(dev); + /* It looks like at least some STA firmware versions reset * fragmentation threshold back to 2346 after enable command. Restore * the configured value, if it differs from this default. */ @@ -1444,6 +1477,10 @@ return 1; } + if (local->iw_mode == IW_MODE_MONITOR) + /* force mode 0x0a after port 0 reset */ + prism2_monitor_enable(dev); + local->hw_ready = 1; local->hw_reset_tries = 0; local->hw_resetting = 0; @@ -3260,6 +3297,7 @@ local->func->hw_config = prism2_hw_config; local->func->hw_reset = prism2_hw_reset; local->func->hw_shutdown = prism2_hw_shutdown; + local->func->monitor_enable = prism2_monitor_enable; local->func->reset_port = prism2_reset_port; local->func->schedule_reset = prism2_schedule_reset; #ifdef PRISM2_DOWNLOAD_SUPPORT diff -ur hostap-driver-0.4.7/driver/modules/hostap_ioctl.c hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_ioctl.c --- hostap-driver-0.4.7/driver/modules/hostap_ioctl.c 2005-09-18 21:51:47.000000000 -0400 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_ioctl.c 2006-03-20 14:45:13.000000000 -0500 @@ -1068,33 +1068,7 @@ printk(KERN_DEBUG "Enabling monitor mode\n"); hostap_monitor_set_type(local); - - if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, - HFA384X_PORTTYPE_PSEUDO_IBSS)) { - printk(KERN_DEBUG "Port type setting for monitor mode " - "failed\n"); - return -EOPNOTSUPP; - } - - /* Host decrypt is needed to get the IV and ICV fields; - * however, monitor mode seems to remove WEP flag from frame - * control field */ - if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS, - HFA384X_WEPFLAGS_HOSTENCRYPT | - HFA384X_WEPFLAGS_HOSTDECRYPT)) { - printk(KERN_DEBUG "WEP flags setting failed\n"); - return -EOPNOTSUPP; - } - - if (local->func->reset_port(dev) || - local->func->cmd(dev, HFA384X_CMDCODE_TEST | - (HFA384X_TEST_MONITOR << 8), - 0, NULL, NULL)) { - printk(KERN_DEBUG "Setting monitor mode failed\n"); - return -EOPNOTSUPP; - } - - return 0; + return local->func->reset_port(dev); } @@ -1160,7 +1134,7 @@ local->iw_mode = *mode; if (local->iw_mode == IW_MODE_MONITOR) - hostap_monitor_mode_enable(local); + return hostap_monitor_mode_enable(local); else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt && !local->fw_encrypt_ok) { printk(KERN_DEBUG "%s: defaulting to host-based encryption as " diff -ur hostap-driver-0.4.7/driver/modules/hostap_pci.c hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_pci.c --- hostap-driver-0.4.7/driver/modules/hostap_pci.c 2005-09-17 17:05:08.000000000 -0400 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_pci.c 2006-03-20 14:45:13.000000000 -0500 @@ -48,6 +48,8 @@ { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID }, /* Samsung MagicLAN SWL-2210P */ { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID }, + /* NETGEAR MA311 */ + { 0x1385, 0x3872, PCI_ANY_ID, PCI_ANY_ID }, { 0 } }; diff -ur hostap-driver-0.4.7/driver/modules/hostap_plx.c hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_plx.c --- hostap-driver-0.4.7/driver/modules/hostap_plx.c 2005-09-17 17:05:08.000000000 -0400 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_plx.c 2006-03-20 14:45:13.000000000 -0500 @@ -98,6 +98,7 @@ { 0xc250, 0x0002 } /* EMTAC A2424i */, { 0xd601, 0x0002 } /* Z-Com XI300 */, { 0xd601, 0x0005 } /* Zcomax XI-325H 200mW */, + { 0xd601, 0x0010 } /* Zcomax XI-325H 100mW */, { 0, 0} }; diff -ur hostap-driver-0.4.7/driver/modules/hostap_wlan.h hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_wlan.h --- hostap-driver-0.4.7/driver/modules/hostap_wlan.h 2005-08-06 13:55:14.000000000 -0400 +++ hostap-driver-0.4.7-aircrack-ng/driver/modules/hostap_wlan.h 2006-03-20 14:45:13.000000000 -0500 @@ -591,6 +591,7 @@ int (*hw_config)(struct net_device *dev, int initial); void (*hw_reset)(struct net_device *dev); void (*hw_shutdown)(struct net_device *dev, int no_disable); + int (*monitor_enable)(struct net_device *dev); int (*reset_port)(struct net_device *dev); void (*schedule_reset)(local_info_t *local); int (*download)(local_info_t *local,
Patch
aircrack-ng/patches/hostap-kernel-2.6.18.patch
diff -ur linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_80211_tx.c linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_80211_tx.c --- linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_80211_tx.c 2006-09-21 01:26:27.000000000 -0400 +++ linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_80211_tx.c 2006-09-21 01:30:18.000000000 -0400 @@ -69,6 +69,9 @@ iface = netdev_priv(dev); local = iface->local; + if (local->iw_mode == IW_MODE_MONITOR) + goto xmit; + if (skb->len < ETH_HLEN) { printk(KERN_DEBUG "%s: hostap_data_start_xmit: short skb " "(len=%d)\n", dev->name, skb->len); @@ -234,6 +237,7 @@ memcpy(skb_put(skb, ETH_ALEN), &hdr.addr4, ETH_ALEN); } +xmit: iface->stats.tx_packets++; iface->stats.tx_bytes += skb->len; @@ -404,8 +408,6 @@ } if (skb->len < 24) { - printk(KERN_DEBUG "%s: hostap_master_start_xmit: short skb " - "(len=%d)\n", dev->name, skb->len); ret = 0; iface->stats.tx_dropped++; goto fail; Only in linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap: hostap_cs.c.orig Only in linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap: hostap_cs.c.rej diff -ur linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_hw.c linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_hw.c --- linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_hw.c 2006-09-21 01:26:27.000000000 -0400 +++ linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_hw.c 2006-09-21 01:30:18.000000000 -0400 @@ -1005,6 +1005,35 @@ return fid; } +static int prism2_monitor_enable(struct net_device *dev) +{ + if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, 5)) { + printk(KERN_DEBUG "Port type setting for monitor mode " + "failed\n"); + return -EOPNOTSUPP; + } + + if (hfa384x_cmd(dev, HFA384X_CMDCODE_TEST | (0x0a << 8), + 0, NULL, NULL)) { + printk(KERN_DEBUG "Could not enter testmode 0x0a\n"); + return -EOPNOTSUPP; + } + + if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS, + HFA384X_WEPFLAGS_PRIVACYINVOKED | + HFA384X_WEPFLAGS_HOSTENCRYPT | + HFA384X_WEPFLAGS_HOSTDECRYPT)) { + printk(KERN_DEBUG "WEP flags setting failed\n"); + return -EOPNOTSUPP; + } + + if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE, 1)) { + printk(KERN_DEBUG "Could not set promiscuous mode\n"); + return -EOPNOTSUPP; + } + + return 0; +} static int prism2_reset_port(struct net_device *dev) { @@ -1031,6 +1060,10 @@ "port\n", dev->name); } + if (local->iw_mode == IW_MODE_MONITOR) + /* force mode 0x0a after port 0 reset */ + return prism2_monitor_enable(dev); + /* It looks like at least some STA firmware versions reset * fragmentation threshold back to 2346 after enable command. Restore * the configured value, if it differs from this default. */ @@ -1466,6 +1499,10 @@ return 1; } + if (local->iw_mode == IW_MODE_MONITOR) + /* force mode 0x0a after port 0 reset */ + prism2_monitor_enable(dev); + local->hw_ready = 1; local->hw_reset_tries = 0; local->hw_resetting = 0; @@ -3156,6 +3193,7 @@ local->func->hw_config = prism2_hw_config; local->func->hw_reset = prism2_hw_reset; local->func->hw_shutdown = prism2_hw_shutdown; + local->func->monitor_enable = prism2_monitor_enable; local->func->reset_port = prism2_reset_port; local->func->schedule_reset = prism2_schedule_reset; #ifdef PRISM2_DOWNLOAD_SUPPORT Only in linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap: hostap_hw.c.orig diff -ur linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_ioctl.c linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_ioctl.c --- linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_ioctl.c 2006-09-21 01:26:27.000000000 -0400 +++ linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_ioctl.c 2006-09-21 01:30:18.000000000 -0400 @@ -1104,33 +1104,7 @@ printk(KERN_DEBUG "Enabling monitor mode\n"); hostap_monitor_set_type(local); - - if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, - HFA384X_PORTTYPE_PSEUDO_IBSS)) { - printk(KERN_DEBUG "Port type setting for monitor mode " - "failed\n"); - return -EOPNOTSUPP; - } - - /* Host decrypt is needed to get the IV and ICV fields; - * however, monitor mode seems to remove WEP flag from frame - * control field */ - if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS, - HFA384X_WEPFLAGS_HOSTENCRYPT | - HFA384X_WEPFLAGS_HOSTDECRYPT)) { - printk(KERN_DEBUG "WEP flags setting failed\n"); - return -EOPNOTSUPP; - } - - if (local->func->reset_port(dev) || - local->func->cmd(dev, HFA384X_CMDCODE_TEST | - (HFA384X_TEST_MONITOR << 8), - 0, NULL, NULL)) { - printk(KERN_DEBUG "Setting monitor mode failed\n"); - return -EOPNOTSUPP; - } - - return 0; + return local->func->reset_port(dev); } @@ -1199,7 +1173,7 @@ local->iw_mode = *mode; if (local->iw_mode == IW_MODE_MONITOR) - hostap_monitor_mode_enable(local); + return hostap_monitor_mode_enable(local); else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt && !local->fw_encrypt_ok) { printk(KERN_DEBUG "%s: defaulting to host-based encryption as " diff -ur linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_main.c linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_main.c --- linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_main.c 2006-09-21 01:26:27.000000000 -0400 +++ linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_main.c 2006-09-21 01:30:18.000000000 -0400 @@ -331,7 +331,7 @@ if (local->iw_mode == IW_MODE_REPEAT) return HFA384X_PORTTYPE_WDS; if (local->iw_mode == IW_MODE_MONITOR) - return HFA384X_PORTTYPE_PSEUDO_IBSS; + return 5; /*HFA384X_PORTTYPE_PSEUDO_IBSS;*/ return HFA384X_PORTTYPE_HOSTAP; } Only in linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap: hostap_main.c.orig diff -ur linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_pci.c linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_pci.c --- linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_pci.c 2006-09-21 01:26:27.000000000 -0400 +++ linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_pci.c 2006-09-21 01:30:18.000000000 -0400 @@ -48,6 +48,8 @@ { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID }, /* Samsung MagicLAN SWL-2210P */ { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID }, + /* NETGEAR MA311 */ + { 0x1385, 0x3872, PCI_ANY_ID, PCI_ANY_ID }, { 0 } }; Only in linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap: hostap_pci.c.orig diff -ur linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_plx.c linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_plx.c --- linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_plx.c 2006-09-21 01:26:27.000000000 -0400 +++ linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_plx.c 2006-09-21 01:30:18.000000000 -0400 @@ -101,6 +101,7 @@ { 0xc250, 0x0002 } /* EMTAC A2424i */, { 0xd601, 0x0002 } /* Z-Com XI300 */, { 0xd601, 0x0005 } /* Zcomax XI-325H 200mW */, + { 0xd601, 0x0010 } /* Zcomax XI-325H 100mW */, { 0, 0} }; Only in linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap: hostap_plx.c.orig diff -ur linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_wlan.h linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_wlan.h --- linux-2.6.18-gentoo/drivers/net/wireless/hostap/hostap_wlan.h 2006-09-21 01:26:27.000000000 -0400 +++ linux-2.6.18-gentoo-rawtx/drivers/net/wireless/hostap/hostap_wlan.h 2006-09-21 01:30:18.000000000 -0400 @@ -575,6 +575,7 @@ int (*hw_config)(struct net_device *dev, int initial); void (*hw_reset)(struct net_device *dev); void (*hw_shutdown)(struct net_device *dev, int no_disable); + int (*monitor_enable)(struct net_device *dev); int (*reset_port)(struct net_device *dev); void (*schedule_reset)(local_info_t *local); int (*download)(local_info_t *local,
Patch
aircrack-ng/patches/ieee80211_inject-2.6.22.patch
--- linux-2.6.23_orig/net/ieee80211/ieee80211_tx.c 2007-10-09 22:31:38.000000000 +0200 +++ linux-2.6.23/net/ieee80211/ieee80211_tx.c 2007-10-14 19:39:49.000000000 +0200 @@ -293,6 +293,23 @@ ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto); + if(ieee->iw_mode == IW_MODE_MONITOR) + { + txb = ieee80211_alloc_txb(1, skb->len, + ieee->tx_headroom, GFP_ATOMIC); + if (unlikely(!txb)) { + printk(KERN_WARNING "%s: Could not allocate TXB\n", + ieee->dev->name); + goto failed; + } + + txb->encrypted = 0; + txb->payload_size = skb->len; + skb_copy_from_linear_data(skb, skb_put(txb->fragments[0],skb->len), skb->len); + + goto success; + } + crypt = ieee->crypt[ieee->tx_keyidx]; encrypt = !(ether_type == ETH_P_PAE && ieee->ieee802_1x) &&
Patch
aircrack-ng/patches/ieee80211_inject.patch
diff -Naur linux-source-2.6.17-orig/net/ieee80211/ieee80211_tx.c linux-source-2.6.17-rawtx/net/ieee80211/ieee80211_tx.c --- linux-source-2.6.17-orig/net/ieee80211/ieee80211_tx.c 2006-10-13 14:18:10.000000000 +0200 +++ linux-source-2.6.17-rawtx/net/ieee80211/ieee80211_tx.c 2007-04-09 17:07:45.000000000 +0200 @@ -291,6 +291,23 @@ goto success; } + if(ieee->iw_mode == IW_MODE_MONITOR) + { + txb = ieee80211_alloc_txb(1, skb->len, + ieee->tx_headroom, GFP_ATOMIC); + if (unlikely(!txb)) { + printk(KERN_WARNING "%s: Could not allocate TXB\n", + ieee->dev->name); + goto failed; + } + + txb->encrypted = 0; + txb->payload_size = skb->len; + memcpy(skb_put(txb->fragments[0],skb->len), skb->data, skb->len); + + goto success; + } + ether_type = ntohs(((struct ethhdr *)skb->data)->h_proto); crypt = ieee->crypt[ieee->tx_keyidx];
Patch
aircrack-ng/patches/ieee80211_softmac_adjust_bitrate.patch
diff -Naur linux-2.6.21.1_orig/net/ieee80211/softmac/ieee80211softmac_module.c linux-2.6.21.1_rawtx/net/ieee80211/softmac/ieee80211softmac_module.c --- linux-2.6.21.1_orig/net/ieee80211/softmac/ieee80211softmac_module.c 2007-04-27 23:49:26.000000000 +0200 +++ linux-2.6.21.1_rawtx/net/ieee80211/softmac/ieee80211softmac_module.c 2007-12-03 23:38:51.000000000 +0100 @@ -238,18 +238,34 @@ struct ieee80211softmac_txrates *txrates = &mac->txrates; u32 change = 0; - change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT; - txrates->default_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 0); + if (mac->ieee->iw_mode == IW_MODE_MONITOR) + { + change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT; + txrates->default_rate = mac->txrates.user_rate; - change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK; - txrates->default_fallback = lower_rate(mac, txrates->default_rate); + change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK; + txrates->default_fallback = mac->txrates.user_rate; - change |= IEEE80211SOFTMAC_TXRATECHG_MCAST; - txrates->mcast_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 1); + change |= IEEE80211SOFTMAC_TXRATECHG_MCAST; + txrates->mcast_rate = mac->txrates.user_rate; - if (mac->txrates_change) - mac->txrates_change(mac->dev, change); + if (mac->txrates_change) + mac->txrates_change(mac->dev, change); + } + else + { + change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT; + txrates->default_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 0); + + change |= IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK; + txrates->default_fallback = lower_rate(mac, txrates->default_rate); + change |= IEEE80211SOFTMAC_TXRATECHG_MCAST; + txrates->mcast_rate = ieee80211softmac_highest_supported_rate(mac, &mac->bssinfo.supported_rates, 1); + + if (mac->txrates_change) + mac->txrates_change(mac->dev, change); + } } void ieee80211softmac_init_bss(struct ieee80211softmac_device *mac)
Patch
aircrack-ng/patches/ipw2200-1.1.4-inject.patch
diff -ur ipw2200-1.1.4/ipw2200.c ipw2200-1.1.4-inject/ipw2200.c --- ipw2200-1.1.4/ipw2200.c 2006-08-21 04:38:32.000000000 +0200 +++ ipw2200-1.1.4-inject/ipw2200.c 2006-08-23 14:20:31.000000000 +0200 @@ -30,6 +30,8 @@ ******************************************************************************/ +#include <linux/version.h> + #include "ipw2200.h" @@ -1945,6 +1945,66 @@ static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO, show_net_stats, store_net_stats); +static int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb, int pri); + +/* SYSFS INJECT */ +static ssize_t store_inject(struct device *d, +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,12) + struct device_attribute *attr, +#endif + const char *buf, size_t count) +{ + struct ipw_priv *priv = (struct ipw_priv *)d->driver_data; + struct ieee80211_device *ieee = priv->ieee; + struct ieee80211_txb * txb; + struct sk_buff *skb_frag; + unsigned char * newbuf; + unsigned long flags; + + // should test (ieee->is_queue_full) + + // Fw only accepts data, so avoid accidental fw errors. + if ( (buf[0]&0x0c) != '\x08') { + //printk("ipw2200: inject: discarding non-data frame (type=%02X)\n",(int)(unsigned char)buf[0]); + return count; + } + + if (count>1500) { + count=1500; + printk("ipw2200: inject: cutting down frame to 1500 bytes\n"); + } + + spin_lock_irqsave(&priv->lock, flags); + + // Create a txb with one skb + txb = kmalloc(sizeof(struct ieee80211_txb) + sizeof(u8 *), GFP_ATOMIC); + if (!txb) + goto nosepuede; + txb->nr_frags=1; + txb->frag_size = ieee->tx_headroom; + txb->fragments[0]=__dev_alloc_skb(count + ieee->tx_headroom, GFP_ATOMIC); + if (!txb->fragments[0]) { + kfree(txb); + goto nosepuede; + } + skb_reserve(txb->fragments[0], ieee->tx_headroom); + txb->encrypted=0; + txb->payload_size=count; + skb_frag = txb->fragments[0]; + newbuf=skb_put(skb_frag, count); + + // copy data into txb->skb and send it + memcpy(newbuf, buf, count); + + ipw_tx_skb(priv, txb, 0); + +nosepuede: + spin_unlock_irqrestore(&priv->lock, flags); + return count; +} + +static DEVICE_ATTR(inject, S_IWUSR, NULL, store_inject); + static void notify_wx_assoc_event(struct ipw_priv *priv) { union iwreq_data wrqu; @@ -11478,6 +11538,7 @@ #ifdef CONFIG_IPW2200_PROMISCUOUS &dev_attr_rtap_iface.attr, &dev_attr_rtap_filter.attr, + &dev_attr_inject.attr, #endif NULL }; diff -ur ipw2200-1.1.4/Makefile ipw2200-1.1.4-inject/Makefile --- ipw2200-1.1.4/Makefile 2006-08-21 04:38:29.000000000 +0200 +++ ipw2200-1.1.4-inject/Makefile 2006-08-23 14:22:06.000000000 +0200 @@ -30,14 +30,14 @@ # simply uncomment: # # NOTE: To use RADIOTAP you must also enable MONITOR above. -#CONFIG_IPW2200_RADIOTAP=y +CONFIG_IPW2200_RADIOTAP=y # The above monitor mode provides standard monitor mode. The following # will create a new interface (named rtap%d) which will be sent all # 802.11 frames received on the interface # # NOTE: To use PROMISCUOUS you must also enable MONITOR above. -#CONFIG_IPW2200_PROMISCUOUS=y +CONFIG_IPW2200_PROMISCUOUS=y endif
Patch
aircrack-ng/patches/linux-wlanng-0.2.8.patch
diff -ur linux-wlan-ng-0.2.8/src/p80211/p80211netdev.c linux-wlan-ng-0.2.8-patched/src/p80211/p80211netdev.c --- linux-wlan-ng-0.2.8/src/p80211/p80211netdev.c 2007-03-19 16:37:00.000000000 +0100 +++ linux-wlan-ng-0.2.8-patched/src/p80211/p80211netdev.c 2007-05-19 13:57:58.000000000 +0200 @@ -511,7 +511,7 @@ * and return success . * TODO: we need a saner way to handle this */ - if(skb->protocol != ETH_P_80211_RAW) { + if(skb->protocol != htons(ETH_P_80211_RAW)) { p80211netdev_start_queue(wlandev); WLAN_LOG_NOTICE( "Tx attempt prior to association, frame dropped.\n"); @@ -523,7 +523,7 @@ } /* Check for raw transmits */ - if(skb->protocol == ETH_P_80211_RAW) { + if(skb->protocol == htons(ETH_P_80211_RAW)) { if (!capable(CAP_NET_ADMIN)) { result = 1; goto failed; @@ -951,8 +951,9 @@ dev->set_mac_address = p80211knetdev_set_mac_address; #endif #ifdef HAVE_TX_TIMEOUT - dev->tx_timeout = &p80211knetdev_tx_timeout; - dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000; +// korek: still not implemented +// dev->tx_timeout = &p80211knetdev_tx_timeout; +// dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000; #endif netif_carrier_off(dev); } diff -ur linux-wlan-ng-0.2.8/src/prism2/driver/hfa384x.c linux-wlan-ng-0.2.8-patched/src/prism2/driver/hfa384x.c --- linux-wlan-ng-0.2.8/src/prism2/driver/hfa384x.c 2007-03-19 16:37:00.000000000 +0100 +++ linux-wlan-ng-0.2.8-patched/src/prism2/driver/hfa384x.c 2007-05-19 13:57:58.000000000 +0200 @@ -1873,8 +1873,16 @@ DBFENTER; - cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | - HFA384x_CMD_AINFO_SET(enable); +// cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | +// HFA384x_CMD_AINFO_SET(enable); + if (enable == HFA384x_MONITOR_ENABLE) { + // KoreK: get into test mode 0x0a + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(0x0a); + } else { + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(enable); + } cmd.parm0 = 0; cmd.parm1 = 0; cmd.parm2 = 0; @@ -3114,12 +3122,33 @@ #endif /* if we're using host WEP, increase size by IV+ICV */ - if (p80211_wep->data) { - txdesc.data_len = host2hfa384x_16(skb->len+8); - // txdesc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); - } else { - txdesc.data_len = host2hfa384x_16(skb->len); - } +// if (p80211_wep->data) { +// txdesc.data_len = host2hfa384x_16(skb->len+8); +// // txdesc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); +// } else { +// txdesc.data_len = host2hfa384x_16(skb->len); +// } + + if (skb->protocol != htons(ETH_P_80211_RAW)) { + /* if we're using host WEP, increase size by IV+ICV */ + if (p80211_wep->data) { + txdesc.data_len = host2hfa384x_16(skb->len+8); + // txdesc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); + } else { + txdesc.data_len = host2hfa384x_16(skb->len); + } + } else { + /* KoreK: raw injection (monitor mode): pull the rest of + the header and ssanity check on txdesc.data_len */ + memcpy(&(txdesc.data_len), skb->data, 16); + skb_pull(skb,16); + if (txdesc.data_len != host2hfa384x_16(skb->len)) { + printk(KERN_DEBUG "mismatch frame_len, drop frame\n"); + return 0; + } + + txdesc.tx_control |= HFA384x_TX_RETRYSTRAT_SET(1); + } txdesc.tx_control = host2hfa384x_16(txdesc.tx_control); /* copy the header over to the txdesc */ @@ -3142,7 +3171,8 @@ spin_lock(&hw->cmdlock); /* Copy descriptor+payload to FID */ - if (p80211_wep->data) { +// if (p80211_wep->data) { + if (p80211_wep->data && (skb->protocol != htons(ETH_P_80211_RAW))) { result = hfa384x_copy_to_bap4(hw, HFA384x_BAP_PROC, fid, 0, &txdesc, sizeof(txdesc), p80211_wep->iv, sizeof(p80211_wep->iv), @@ -3587,6 +3617,17 @@ switch( HFA384x_RXSTATUS_MACPORT_GET(rxdesc.status) ) { case 0: + + /* KoreK: this testmode uses macport 0 */ + if ((wlandev->netdev->type == ARPHRD_IEEE80211) || + (wlandev->netdev->type == ARPHRD_IEEE80211_PRISM)) { + if ( ! HFA384x_RXSTATUS_ISFCSERR(rxdesc.status) ) { + hfa384x_int_rxmonitor( wlandev, rxfid, &rxdesc); + } else { + WLAN_LOG_DEBUG(3,"Received monitor frame: FCSerr set\n"); + } + goto done; + } fc = ieee2host16(rxdesc.frame_control); Only in linux-wlan-ng-0.2.8-patched/src/prism2/driver: hfa384x.c.orig diff -ur linux-wlan-ng-0.2.8/src/prism2/driver/hfa384x_usb.c linux-wlan-ng-0.2.8-patched/src/prism2/driver/hfa384x_usb.c --- linux-wlan-ng-0.2.8/src/prism2/driver/hfa384x_usb.c 2007-03-19 16:37:00.000000000 +0100 +++ linux-wlan-ng-0.2.8-patched/src/prism2/driver/hfa384x_usb.c 2007-05-19 13:57:58.000000000 +0200 @@ -1430,8 +1430,16 @@ DBFENTER; - cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | - HFA384x_CMD_AINFO_SET(enable); + // cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + // HFA384x_CMD_AINFO_SET(enable); + if (enable == HFA384x_MONITOR_ENABLE) { + // KoreK: get into test mode 0x0a + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(0x0a); + } else { + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(enable); + } cmd.parm0 = 0; cmd.parm1 = 0; cmd.parm2 = 0; @@ -3431,37 +3439,71 @@ HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0); #endif - hw->txbuff.txfrm.desc.tx_control = - host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); - - /* copy the header over to the txdesc */ - memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, sizeof(p80211_hdr_t)); + // hw->txbuff.txfrm.desc.tx_control = + // host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); - /* if we're using host WEP, increase size by IV+ICV */ - if (p80211_wep->data) { - hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8); - // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); - usbpktlen+=8; - } else { - hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len); + // /* copy the header over to the txdesc */ + // memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, sizeof(p80211_hdr_t)); + if (skb->protocol != htons(ETH_P_80211_RAW)) { + hw->txbuff.txfrm.desc.tx_control = + host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); + + /* copy the header over to the txdesc */ + memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, + sizeof(p80211_hdr_t)); + + /* if we're using host WEP, increase size by IV+ICV */ + if (p80211_wep->data) { + hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8); + // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); + usbpktlen+=8; + } else { + hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len); + } + } else { + /* KoreK: raw injection (monitor mode): pull the rest of + the header and ssanity check on txdesc.data_len */ + memcpy(&(hw->txbuff.txfrm.desc.data_len), skb->data, 16); + skb_pull(skb,16); + if (hw->txbuff.txfrm.desc.data_len != host2hfa384x_16(skb->len)) { + printk(KERN_DEBUG "mismatch frame_len, drop frame\n"); + return 0; + } + // /* if we're using host WEP, increase size by IV+ICV */ + // if (p80211_wep->data) { + // hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8); + // // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); + // usbpktlen+=8; + // } else { + // hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len); + hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_RETRYSTRAT_SET(1); + hw->txbuff.txfrm.desc.tx_control = + host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); + + /* copy the header over to the txdesc */ + memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, + sizeof(p80211_hdr_t)); } usbpktlen += skb->len; /* copy over the WEP IV if we are using host WEP */ ptr = hw->txbuff.txfrm.data; - if (p80211_wep->data) { + // if (p80211_wep->data) { + if (p80211_wep->data && skb->protocol != htons(ETH_P_80211_RAW)) { memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv)); ptr+= sizeof(p80211_wep->iv); memcpy(ptr, p80211_wep->data, skb->len); } else { memcpy(ptr, skb->data, skb->len); } + /* copy over the packet data */ ptr+= skb->len; /* copy over the WEP ICV if we are using host WEP */ - if (p80211_wep->data) { + // if (p80211_wep->data) { + if (p80211_wep->data && skb->protocol != htons(ETH_P_80211_RAW)) { memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv)); } @@ -4223,6 +4265,17 @@ switch( HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status) ) { case 0: + /* KoreK: this testmode uses macport 0 */ + if ((wlandev->netdev->type == ARPHRD_IEEE80211) || + (wlandev->netdev->type == ARPHRD_IEEE80211_PRISM)) { + if ( ! HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status) ) { + hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm); + } else { + WLAN_LOG_DEBUG(3,"Received monitor frame: FCSerr set\n"); + } + goto done; + } + fc = ieee2host16(usbin->rxfrm.desc.frame_control); /* If exclude and we receive an unencrypted, drop it */ Only in linux-wlan-ng-0.2.8-patched/src/prism2/driver: hfa384x_usb.c.orig diff -ur linux-wlan-ng-0.2.8/src/prism2/driver/prism2mgmt.c linux-wlan-ng-0.2.8-patched/src/prism2/driver/prism2mgmt.c --- linux-wlan-ng-0.2.8/src/prism2/driver/prism2mgmt.c 2007-01-30 19:12:42.000000000 +0100 +++ linux-wlan-ng-0.2.8-patched/src/prism2/driver/prism2mgmt.c 2007-05-19 13:57:58.000000000 +0200 @@ -2860,9 +2860,12 @@ } /* Now if we're already sniffing, we can skip the rest */ - if (wlandev->netdev->type != ARPHRD_ETHER) { + // if (wlandev->netdev->type != ARPHRD_ETHER) { + if ((wlandev->netdev->type != ARPHRD_IEEE80211) && + (wlandev->netdev->type != ARPHRD_IEEE80211_PRISM)) { /* Set the port type to pIbss */ - word = HFA384x_PORTTYPE_PSUEDOIBSS; + // word = HFA384x_PORTTYPE_PSUEDOIBSS; + word = 5; // HFA384x_PORTTYPE_PSUEDOIBSS; result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, word); if ( result ) { @@ -2874,6 +2877,8 @@ } if ((msg->keepwepflags.status == P80211ENUM_msgitem_status_data_ok) && (msg->keepwepflags.data != P80211ENUM_truth_true)) { /* Set the wepflags for no decryption */ + /* doesn't work - done from the CLI */ + /* Fix? KoreK */ word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT | HFA384x_WEPFLAGS_DISABLE_RXCRYPT; result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFWEPFLAGS, word); @@ -2919,7 +2924,9 @@ goto failed; } - if (wlandev->netdev->type == ARPHRD_ETHER) { + // if (wlandev->netdev->type == ARPHRD_ETHER) { + if ((wlandev->netdev->type != ARPHRD_IEEE80211) && + (wlandev->netdev->type != ARPHRD_IEEE80211_PRISM)) { WLAN_LOG_INFO("monitor mode enabled\n"); } diff -ur linux-wlan-ng-0.2.8/src/prism2/driver/prism2sta.c linux-wlan-ng-0.2.8-patched/src/prism2/driver/prism2sta.c --- linux-wlan-ng-0.2.8/src/prism2/driver/prism2sta.c 2007-03-19 16:37:00.000000000 +0100 +++ linux-wlan-ng-0.2.8-patched/src/prism2/driver/prism2sta.c 2007-05-19 13:57:58.000000000 +0200 @@ -411,7 +411,9 @@ DBFENTER; /* If necessary, set the 802.11 WEP bit */ - if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) { + // if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) { + if (((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) + && (skb->protocol != htons(ETH_P_80211_RAW))) { p80211_hdr->a3.fc |= host2ieee16(WLAN_SET_FC_ISWEP(1)); } Only in linux-wlan-ng-0.2.8-patched/src/prism2/driver: prism2sta.c.orig
Patch
aircrack-ng/patches/linux-wlanng-kernel-2.6.28.patch
diff -Naur linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/hfa384x.c linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/hfa384x.c --- linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/hfa384x.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/hfa384x.c 2009-04-04 22:53:46.000000000 -0400 @@ -1873,8 +1873,16 @@ DBFENTER; - cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | - HFA384x_CMD_AINFO_SET(enable); +// cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | +// HFA384x_CMD_AINFO_SET(enable); + if (enable == HFA384x_MONITOR_ENABLE) { + // KoreK: get into test mode 0x0a + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(0x0a); + } else { + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(enable); + } cmd.parm0 = 0; cmd.parm1 = 0; cmd.parm2 = 0; @@ -3114,11 +3122,32 @@ #endif /* if we're using host WEP, increase size by IV+ICV */ - if (p80211_wep->data) { - txdesc.data_len = host2hfa384x_16(skb->len+8); - // txdesc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); - } else { - txdesc.data_len = host2hfa384x_16(skb->len); +// if (p80211_wep->data) { +// txdesc.data_len = host2hfa384x_16(skb->len+8); +// // txdesc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); +// } else { +// txdesc.data_len = host2hfa384x_16(skb->len); +// } + + if (skb->protocol != htons(ETH_P_80211_RAW)) { + /* if we're using host WEP, increase size by IV+ICV */ + if (p80211_wep->data) { + txdesc.data_len = host2hfa384x_16(skb->len+8); + // txdesc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); + } else { + txdesc.data_len = host2hfa384x_16(skb->len); + } + } else { + /* KoreK: raw injection (monitor mode): pull the rest of + the header and ssanity check on txdesc.data_len */ + memcpy(&(txdesc.data_len), skb->data, 16); + skb_pull(skb,16); + if (txdesc.data_len != host2hfa384x_16(skb->len)) { + printk(KERN_DEBUG "mismatch frame_len, drop frame\n"); + return 0; + } + + txdesc.tx_control |= HFA384x_TX_RETRYSTRAT_SET(1); } txdesc.tx_control = host2hfa384x_16(txdesc.tx_control); @@ -3142,7 +3171,8 @@ spin_lock(&hw->cmdlock); /* Copy descriptor+payload to FID */ - if (p80211_wep->data) { +// if (p80211_wep->data) { + if (p80211_wep->data && (skb->protocol != htons(ETH_P_80211_RAW))) { result = hfa384x_copy_to_bap4(hw, HFA384x_BAP_PROC, fid, 0, &txdesc, sizeof(txdesc), p80211_wep->iv, sizeof(p80211_wep->iv), @@ -3588,6 +3618,17 @@ { case 0: + /* KoreK: this testmode uses macport 0 */ + if ((wlandev->netdev->type == ARPHRD_IEEE80211) || + (wlandev->netdev->type == ARPHRD_IEEE80211_PRISM)) { + if ( ! HFA384x_RXSTATUS_ISFCSERR(rxdesc.status) ) { + hfa384x_int_rxmonitor( wlandev, rxfid, &rxdesc); + } else { + WLAN_LOG_DEBUG(3,"Received monitor frame: FCSerr set\n"); + } + goto done; + } + fc = ieee2host16(rxdesc.frame_control); /* If exclude and we receive an unencrypted, drop it */ diff -Naur linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/hfa384x_usb.c linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/hfa384x_usb.c --- linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/hfa384x_usb.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/hfa384x_usb.c 2009-04-04 23:13:53.000000000 -0400 @@ -1430,8 +1430,17 @@ DBFENTER; - cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | - HFA384x_CMD_AINFO_SET(enable); +// cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | +// HFA384x_CMD_AINFO_SET(enable); + if (enable == HFA384x_MONITOR_ENABLE) { + // KoreK: get into test mode 0x0a + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(0x0a); + } else { + cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | + HFA384x_CMD_AINFO_SET(enable); + } + cmd.parm0 = 0; cmd.parm1 = 0; cmd.parm2 = 0; @@ -3431,37 +3440,71 @@ HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0); #endif - hw->txbuff.txfrm.desc.tx_control = - host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); +// hw->txbuff.txfrm.desc.tx_control = +// host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); - /* copy the header over to the txdesc */ - memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, sizeof(p80211_hdr_t)); - - /* if we're using host WEP, increase size by IV+ICV */ - if (p80211_wep->data) { - hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8); - // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); - usbpktlen+=8; - } else { - hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len); +// /* copy the header over to the txdesc */ +// memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, sizeof(p80211_hdr_t)); + if (skb->protocol != htons(ETH_P_80211_RAW)) { + hw->txbuff.txfrm.desc.tx_control = + host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); + + /* copy the header over to the txdesc */ + memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, + sizeof(p80211_hdr_t)); + + /* if we're using host WEP, increase size by IV+ICV */ + if (p80211_wep->data) { + hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8); + // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); + usbpktlen+=8; + } else { + hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len); + } + } else { + /* KoreK: raw injection (monitor mode): pull the rest of + the header and ssanity check on txdesc.data_len */ + memcpy(&(hw->txbuff.txfrm.desc.data_len), skb->data, 16); + skb_pull(skb,16); + if (hw->txbuff.txfrm.desc.data_len != host2hfa384x_16(skb->len)) { + printk(KERN_DEBUG "mismatch frame_len, drop frame\n"); + return 0; + } +// /* if we're using host WEP, increase size by IV+ICV */ +// if (p80211_wep->data) { +// hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len+8); +// // hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_NOENCRYPT_SET(1); +// usbpktlen+=8; +// } else { +// hw->txbuff.txfrm.desc.data_len = host2hfa384x_16(skb->len); + hw->txbuff.txfrm.desc.tx_control |= HFA384x_TX_RETRYSTRAT_SET(1); + hw->txbuff.txfrm.desc.tx_control = + host2hfa384x_16(hw->txbuff.txfrm.desc.tx_control); + + /* copy the header over to the txdesc */ + memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr, + sizeof(p80211_hdr_t)); } usbpktlen += skb->len; /* copy over the WEP IV if we are using host WEP */ ptr = hw->txbuff.txfrm.data; - if (p80211_wep->data) { +// if (p80211_wep->data) { + if (p80211_wep->data && skb->protocol != htons(ETH_P_80211_RAW)) { memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv)); ptr+= sizeof(p80211_wep->iv); memcpy(ptr, p80211_wep->data, skb->len); } else { memcpy(ptr, skb->data, skb->len); } + /* copy over the packet data */ ptr+= skb->len; /* copy over the WEP ICV if we are using host WEP */ - if (p80211_wep->data) { +// if (p80211_wep->data) { + if (p80211_wep->data && skb->protocol != htons(ETH_P_80211_RAW)) { memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv)); } @@ -4223,6 +4266,17 @@ switch( HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status) ) { case 0: + /* KoreK: this testmode uses macport 0 */ + if ((wlandev->netdev->type == ARPHRD_IEEE80211) || + (wlandev->netdev->type == ARPHRD_IEEE80211_PRISM)) { + if ( ! HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status) ) { + hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm); + } else { + WLAN_LOG_DEBUG(3,"Received monitor frame: FCSerr set\n"); + } + goto done; + } + fc = ieee2host16(usbin->rxfrm.desc.frame_control); /* If exclude and we receive an unencrypted, drop it */ diff -Naur linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/p80211netdev.c linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/p80211netdev.c --- linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/p80211netdev.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/p80211netdev.c 2009-04-04 22:42:15.000000000 -0400 @@ -512,7 +512,7 @@ * and return success . * TODO: we need a saner way to handle this */ - if(skb->protocol != ETH_P_80211_RAW) { + if(skb->protocol != htons(ETH_P_80211_RAW)) { p80211netdev_start_queue(wlandev); WLAN_LOG_NOTICE( "Tx attempt prior to association, frame dropped.\n"); @@ -524,7 +524,7 @@ } /* Check for raw transmits */ - if(skb->protocol == ETH_P_80211_RAW) { + if(skb->protocol == htons(ETH_P_80211_RAW)) { if (!capable(CAP_NET_ADMIN)) { result = 1; goto failed; @@ -952,8 +952,9 @@ dev->set_mac_address = p80211knetdev_set_mac_address; #endif #ifdef HAVE_TX_TIMEOUT - dev->tx_timeout = &p80211knetdev_tx_timeout; - dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000; +// korek: still not implemented (XXX: Why exactly do we remove this???) +// dev->tx_timeout = &p80211knetdev_tx_timeout; +// dev->watchdog_timeo = (wlan_watchdog * HZ) / 1000; #endif netif_carrier_off(dev); } diff -Naur linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/prism2mgmt.c linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/prism2mgmt.c --- linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/prism2mgmt.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/prism2mgmt.c 2009-04-04 23:18:35.000000000 -0400 @@ -2860,9 +2860,12 @@ } /* Now if we're already sniffing, we can skip the rest */ - if (wlandev->netdev->type != ARPHRD_ETHER) { +// if (wlandev->netdev->type != ARPHRD_ETHER) { + if ((wlandev->netdev->type != ARPHRD_IEEE80211) && + (wlandev->netdev->type != ARPHRD_IEEE80211_PRISM)) { /* Set the port type to pIbss */ - word = HFA384x_PORTTYPE_PSUEDOIBSS; +// word = HFA384x_PORTTYPE_PSUEDOIBSS; + word = 5; // HFA384x_PORTTYPE_PSUEDOIBSS; result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, word); if ( result ) { @@ -2874,6 +2877,8 @@ } if ((msg->keepwepflags.status == P80211ENUM_msgitem_status_data_ok) && (msg->keepwepflags.data != P80211ENUM_truth_true)) { /* Set the wepflags for no decryption */ + /* doesn't work - done from the CLI */ + /* Fix? KoreK */ word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT | HFA384x_WEPFLAGS_DISABLE_RXCRYPT; result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFWEPFLAGS, word); @@ -2919,7 +2924,9 @@ goto failed; } - if (wlandev->netdev->type == ARPHRD_ETHER) { +// if (wlandev->netdev->type == ARPHRD_ETHER) { + if ((wlandev->netdev->type != ARPHRD_IEEE80211) && + (wlandev->netdev->type != ARPHRD_IEEE80211_PRISM)) { WLAN_LOG_INFO("monitor mode enabled\n"); } diff -Naur linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/prism2sta.c linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/prism2sta.c --- linux-2.6.28-pentoo-r4/drivers/staging/wlan-ng/prism2sta.c 2008-12-24 18:26:37.000000000 -0500 +++ linux-2.6.28-pentoo-r4-fauxpas/drivers/staging/wlan-ng/prism2sta.c 2009-04-04 23:20:58.000000000 -0400 @@ -411,7 +411,9 @@ DBFENTER; /* If necessary, set the 802.11 WEP bit */ - if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) { +// if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) { + if (((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == HOSTWEP_PRIVACYINVOKED) + && (skb->protocol != htons(ETH_P_80211_RAW))) { p80211_hdr->a3.fc |= host2ieee16(WLAN_SET_FC_ISWEP(1)); }
Patch
aircrack-ng/patches/mac80211-2.6.29-fix-tx-ctl-no-ack-retry-count.patch
tx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index b47435d..751934b 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -539,7 +539,8 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) if (tx->sta) tx->sta->last_tx_rate = txrc.reported_rate; - if (unlikely(!info->control.rates[0].count)) + if (unlikely(!info->control.rates[0].count) || + info->flags & IEEE80211_TX_CTL_NO_ACK) info->control.rates[0].count = 1; if (is_multicast_ether_addr(hdr->addr1)) {
Patch
aircrack-ng/patches/mac80211.compat08082009.wl_frag+ack_v1.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 0855cac..221bed6 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -677,11 +677,19 @@ int tid; /* * Packet injection may want to control the sequence - * number, if we have no matching interface then we - * neither assign one ourselves nor ask the driver to. + * number, so if an injected packet is found, skip + * renumbering it. Also make the packet NO_ACK to avoid + * excessive retries (ACKing and retrying should be + * handled by the injecting application). + * FIXME This may break hostapd and some other injectors. + * This should be done using a radiotap flag. */ - if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR)) + if (unlikely((info->flags & IEEE80211_TX_CTL_INJECTED) && + !(tx->sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))) { + if (!ieee80211_has_morefrags(hdr->frame_control)) + info->flags |= IEEE80211_TX_CTL_NO_ACK; return TX_CONTINUE; + } if (unlikely(ieee80211_is_ctl(hdr->frame_control))) return TX_CONTINUE;
Patch
aircrack-ng/patches/mac80211_2.6.24.4_frag.patch
# Patch to prevent mac80211 to clobber injected sequence numbers diff -bBur linux-2.6.24.4/net/mac80211/tx.c linux-2.6.24.4-sud/net/mac80211/tx.c --- linux-2.6.24.4/net/mac80211/tx.c 2008-01-24 23:58:37.000000000 +0100 +++ linux-2.6.24.4-sud/net/mac80211/tx.c 2008-04-05 16:43:19.000000000 +0200 @@ -281,6 +281,9 @@ { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; + if (unlikely(tx->flags & IEEE80211_TXRXD_TX_INJECTED)) + return TXRX_CONTINUE; + if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24) ieee80211_include_sequence(tx->sdata, hdr);
Patch
aircrack-ng/patches/mac80211_2.6.26-rc8-wl_frag.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 345d6ff..20c604d 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -278,6 +278,15 @@ static ieee80211_tx_result ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); + + /* + * don't touch sequence numbers on raw monitor interfaces + */ + if (unlikely((info->flags & IEEE80211_TX_CTL_INJECTED) && + (tx->sdata->vif.type == IEEE80211_IF_TYPE_MNTR) && + !(tx->sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))) + return TX_CONTINUE; if (ieee80211_hdrlen(hdr->frame_control) >= 24) ieee80211_include_sequence(tx->sdata, hdr);
Patch
aircrack-ng/patches/mac80211_2.6.26-wl_frag.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 2b912cf..aaa086f 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -636,6 +636,11 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) if (ieee80211_hdrlen(hdr->frame_control) < 24) return TX_CONTINUE; + if (unlikely((info->flags & IEEE80211_TX_CTL_INJECTED) && + (tx->sdata->vif.type == IEEE80211_IF_TYPE_MNTR) && + !(tx->sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))) + return TX_CONTINUE; + if (!ieee80211_is_data_qos(hdr->frame_control)) { info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; return TX_CONTINUE;
Patch
aircrack-ng/patches/mac80211_2.6.26_frag.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index f35eaea..e5e8483 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -292,6 +292,9 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) { struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; + if (unlikely(tx->flags & IEEE80211_TX_INJECTED)) + return TX_CONTINUE; + if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24) ieee80211_include_sequence(tx->sdata, hdr);
Patch
aircrack-ng/patches/mac80211_2.6.27_frag+ack.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 0855cac..221bed6 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -630,6 +630,13 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) int tid; /* only for injected frames */ + if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED) && + !(tx->sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) { + if (!ieee80211_has_morefrags(hdr->frame_control)) + info->flags |= IEEE80211_TX_CTL_NO_ACK; + return TX_CONTINUE; + } + if (unlikely(ieee80211_is_ctl(hdr->frame_control))) return TX_CONTINUE;
Patch
aircrack-ng/patches/mac80211_2.6.27_frag+ack_v2.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 0855cac..221bed6 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -630,6 +630,13 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) int tid; /* only for injected frames */ + if (unlikely((info->flags & IEEE80211_TX_CTL_INJECTED) && + !(tx->sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))) { + if (!ieee80211_has_morefrags(hdr->frame_control)) + info->flags |= IEEE80211_TX_CTL_NO_ACK; + return TX_CONTINUE; + } + if (unlikely(ieee80211_is_ctl(hdr->frame_control))) return TX_CONTINUE;
Patch
aircrack-ng/patches/mac80211_2.6.28-rc4-wl_frag+ack_v2.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 0855cac..221bed6 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -611,11 +611,19 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) /* * Packet injection may want to control the sequence - * number, if we have no matching interface then we - * neither assign one ourselves nor ask the driver to. + * number, so if an injected packet is found, skip + * renumbering it. Also make the packet NO_ACK to avoid + * excessive retries (ACKing and retrying should be + * handled by the injecting application). + * FIXME This may break hostapd and some other injectors. + * This should be done using a radiotap flag. */ - if (unlikely(!info->control.vif)) + if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED) && + !(tx->sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) { + if (!ieee80211_has_morefrags(hdr->frame_control)) + info->flags |= IEEE80211_TX_CTL_NO_ACK; return TX_CONTINUE; + } if (unlikely(ieee80211_is_ctl(hdr->frame_control))) return TX_CONTINUE;
Patch
aircrack-ng/patches/mac80211_2.6.28-rc4-wl_frag+ack_v3.patch
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 0855cac..221bed6 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -611,11 +611,19 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) /* * Packet injection may want to control the sequence - * number, if we have no matching interface then we - * neither assign one ourselves nor ask the driver to. + * number, so if an injected packet is found, skip + * renumbering it. Also make the packet NO_ACK to avoid + * excessive retries (ACKing and retrying should be + * handled by the injecting application). + * FIXME This may break hostapd and some other injectors. + * This should be done using a radiotap flag. */ - if (unlikely(!info->control.vif)) + if (unlikely((info->flags & IEEE80211_TX_CTL_INJECTED) && + !(tx->sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))) { + if (!ieee80211_has_morefrags(hdr->frame_control)) + info->flags |= IEEE80211_TX_CTL_NO_ACK; return TX_CONTINUE; + } if (unlikely(ieee80211_is_ctl(hdr->frame_control))) return TX_CONTINUE;
Patch
aircrack-ng/patches/mac80211_2.6.28-rc8-wl_frag+ack_radiotap.patch
diff --git a/include/net/ieee80211_radiotap.h b/include/net/ieee80211_radiotap.h index d364fd5..4e28c0c 100644 --- a/include/net/ieee80211_radiotap.h +++ b/include/net/ieee80211_radiotap.h @@ -247,6 +247,9 @@ enum ieee80211_radiotap_type { * retries */ #define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ #define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ +#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */ +#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled + * by userspace */ /* Ugly macro to convert literal channel numbers into their mhz equivalents * There are certianly some conditions that will break this (like feeding it '30') diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 22702e7..b397aed 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -609,6 +609,10 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) u8 *qc; int tid; + if (unlikely(!(info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ))) + return TX_CONTINUE; + info->flags &= ~IEEE80211_TX_CTL_ASSIGN_SEQ; + /* * Packet injection may want to control the sequence * number, if we have no matching interface then we @@ -867,6 +871,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx, struct ieee80211_radiotap_header *rthdr = (struct ieee80211_radiotap_header *) skb->data; struct ieee80211_supported_band *sband; + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); sband = tx->local->hw.wiphy->bands[tx->channel->band]; @@ -913,6 +918,12 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx, if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG) tx->flags |= IEEE80211_TX_FRAGMENTED; break; + case IEEE80211_RADIOTAP_TX_FLAGS: + if (*iterator.this_arg & IEEE80211_RADIOTAP_F_TX_NOACK) + info->flags |= IEEE80211_TX_CTL_NO_ACK; + if (*iterator.this_arg & IEEE80211_RADIOTAP_F_TX_NOSEQ) + info->flags &= ~IEEE80211_TX_CTL_ASSIGN_SEQ; + break; /* * Please update the file @@ -965,6 +976,8 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx, * it will be cleared/left by radiotap as desired. */ tx->flags |= IEEE80211_TX_FRAGMENTED; + /* Same here, controlled by radiotap and the stack */ + info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; /* process and remove the injection radiotap header */ sdata = IEEE80211_DEV_TO_SUB_IF(dev); @@ -992,13 +1005,10 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx, info->flags |= IEEE80211_TX_CTL_AMPDU; } - if (is_multicast_ether_addr(hdr->addr1)) { - tx->flags &= ~IEEE80211_TX_UNICAST; + if (is_multicast_ether_addr(hdr->addr1)) info->flags |= IEEE80211_TX_CTL_NO_ACK; - } else { + else tx->flags |= IEEE80211_TX_UNICAST; - info->flags &= ~IEEE80211_TX_CTL_NO_ACK; - } if (tx->flags & IEEE80211_TX_FRAGMENTED) { if ((tx->flags & IEEE80211_TX_UNICAST) &&