| 1 |
#include <sys/types.h> |
|---|
| 2 |
#include <sys/file.h> |
|---|
| 3 |
#include <sys/ioctl.h> |
|---|
| 4 |
#include <sys/socket.h> |
|---|
| 5 |
|
|---|
| 6 |
#include <netinet/ether.h> |
|---|
| 7 |
|
|---|
| 8 |
#include <linux/if.h> |
|---|
| 9 |
#include <iwlib.h> |
|---|
| 10 |
|
|---|
| 11 |
#include <stdio.h> |
|---|
| 12 |
#include <string.h> |
|---|
| 13 |
#include <unistd.h> |
|---|
| 14 |
|
|---|
| 15 |
#define IEEE80211_IOCTL_SETPARAM (SIOCIWFIRSTPRIV+0) |
|---|
| 16 |
#define IEEE80211_ADDR_LEN 6 |
|---|
| 17 |
#define IEEE80211_IOCTL_SETMLME (SIOCIWFIRSTPRIV+16) |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
struct ath_stats { |
|---|
| 21 |
u_int32_t ast_watchdog; |
|---|
| 22 |
u_int32_t ast_hardware; |
|---|
| 23 |
u_int32_t ast_bmiss; |
|---|
| 24 |
u_int32_t ast_rxorn; |
|---|
| 25 |
u_int32_t ast_rxeol; |
|---|
| 26 |
u_int32_t ast_txurn; |
|---|
| 27 |
u_int32_t ast_mib; |
|---|
| 28 |
u_int32_t ast_tx_packets; |
|---|
| 29 |
u_int32_t ast_tx_mgmt; |
|---|
| 30 |
u_int32_t ast_tx_discard; |
|---|
| 31 |
u_int32_t ast_tx_invalid; |
|---|
| 32 |
u_int32_t ast_tx_qstop; |
|---|
| 33 |
u_int32_t ast_tx_encap; |
|---|
| 34 |
u_int32_t ast_tx_nonode; |
|---|
| 35 |
u_int32_t ast_tx_nobuf; |
|---|
| 36 |
u_int32_t ast_tx_nobufmgt; |
|---|
| 37 |
u_int32_t ast_tx_xretries; |
|---|
| 38 |
u_int32_t ast_tx_fifoerr; |
|---|
| 39 |
u_int32_t ast_tx_filtered; |
|---|
| 40 |
u_int32_t ast_tx_shortretry; |
|---|
| 41 |
u_int32_t ast_tx_longretry; |
|---|
| 42 |
u_int32_t ast_tx_badrate; |
|---|
| 43 |
u_int32_t ast_tx_noack; |
|---|
| 44 |
u_int32_t ast_tx_rts; |
|---|
| 45 |
u_int32_t ast_tx_cts; |
|---|
| 46 |
u_int32_t ast_tx_shortpre; |
|---|
| 47 |
u_int32_t ast_tx_altrate; |
|---|
| 48 |
u_int32_t ast_tx_protect; |
|---|
| 49 |
u_int32_t ast_rx_orn; |
|---|
| 50 |
u_int32_t ast_rx_crcerr; |
|---|
| 51 |
u_int32_t ast_rx_fifoerr; |
|---|
| 52 |
u_int32_t ast_rx_badcrypt; |
|---|
| 53 |
u_int32_t ast_rx_badmic; |
|---|
| 54 |
u_int32_t ast_rx_phyerr; |
|---|
| 55 |
u_int32_t ast_rx_phy[32]; |
|---|
| 56 |
u_int32_t ast_rx_tooshort; |
|---|
| 57 |
u_int32_t ast_rx_toobig; |
|---|
| 58 |
u_int32_t ast_rx_nobuf; |
|---|
| 59 |
u_int32_t ast_rx_packets; |
|---|
| 60 |
u_int32_t ast_rx_mgt; |
|---|
| 61 |
u_int32_t ast_rx_ctl; |
|---|
| 62 |
int8_t ast_tx_rssi; |
|---|
| 63 |
int8_t ast_rx_rssi; |
|---|
| 64 |
u_int32_t ast_be_xmit; |
|---|
| 65 |
u_int32_t ast_be_nobuf; |
|---|
| 66 |
u_int32_t ast_per_cal; |
|---|
| 67 |
u_int32_t ast_per_calfail; |
|---|
| 68 |
u_int32_t ast_per_rfgain; |
|---|
| 69 |
u_int32_t ast_rate_calls; |
|---|
| 70 |
u_int32_t ast_rate_raise; |
|---|
| 71 |
u_int32_t ast_rate_drop; |
|---|
| 72 |
u_int32_t ast_ant_defswitch; |
|---|
| 73 |
u_int32_t ast_ant_txswitch; |
|---|
| 74 |
u_int32_t ast_ant_rx[8]; |
|---|
| 75 |
u_int32_t ast_ant_tx[8]; |
|---|
| 76 |
}; |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
struct ieee80211req_mlme { |
|---|
| 85 |
u_int8_t im_op; |
|---|
| 86 |
#define IEEE80211_MLME_ASSOC 1 |
|---|
| 87 |
#define IEEE80211_MLME_DISASSOC 2 |
|---|
| 88 |
#define IEEE80211_MLME_DEAUTH 3 |
|---|
| 89 |
#define IEEE80211_MLME_AUTHORIZE 4 |
|---|
| 90 |
#define IEEE80211_MLME_UNAUTHORIZE 5 |
|---|
| 91 |
u_int16_t im_reason; |
|---|
| 92 |
u_int8_t im_macaddr[IEEE80211_ADDR_LEN]; |
|---|
| 93 |
}; |
|---|
| 94 |
|
|---|
| 95 |
enum { |
|---|
| 96 |
IEEE80211_PARAM_TURBO = 1, |
|---|
| 97 |
IEEE80211_PARAM_MODE = 2, |
|---|
| 98 |
IEEE80211_PARAM_AUTHMODE = 3, |
|---|
| 99 |
IEEE80211_PARAM_PROTMODE = 4, |
|---|
| 100 |
IEEE80211_PARAM_MCASTCIPHER = 5, |
|---|
| 101 |
IEEE80211_PARAM_MCASTKEYLEN = 6, |
|---|
| 102 |
IEEE80211_PARAM_UCASTCIPHERS = 7, |
|---|
| 103 |
IEEE80211_PARAM_UCASTCIPHER = 8, |
|---|
| 104 |
IEEE80211_PARAM_UCASTKEYLEN = 9, |
|---|
| 105 |
IEEE80211_PARAM_WPA = 10, |
|---|
| 106 |
IEEE80211_PARAM_ROAMING = 12, |
|---|
| 107 |
IEEE80211_PARAM_PRIVACY = 13, |
|---|
| 108 |
IEEE80211_PARAM_COUNTERMEASURES = 14, |
|---|
| 109 |
IEEE80211_PARAM_DROPUNENCRYPTED = 15, |
|---|
| 110 |
IEEE80211_PARAM_DRIVER_CAPS = 16, |
|---|
| 111 |
IEEE80211_PARAM_MACCMD = 17, |
|---|
| 112 |
IEEE80211_PARAM_WMM = 18, |
|---|
| 113 |
IEEE80211_PARAM_HIDESSID = 19, |
|---|
| 114 |
IEEE80211_PARAM_APBRIDGE = 20, |
|---|
| 115 |
IEEE80211_PARAM_KEYMGTALGS = 21, |
|---|
| 116 |
IEEE80211_PARAM_RSNCAPS = 22, |
|---|
| 117 |
IEEE80211_PARAM_INACT = 23, |
|---|
| 118 |
IEEE80211_PARAM_INACT_AUTH = 24, |
|---|
| 119 |
IEEE80211_PARAM_INACT_INIT = 25, |
|---|
| 120 |
IEEE80211_PARAM_ABOLT = 26, |
|---|
| 121 |
IEEE80211_PARAM_DTIM_PERIOD = 28, |
|---|
| 122 |
IEEE80211_PARAM_BEACON_INTERVAL = 29, |
|---|
| 123 |
IEEE80211_PARAM_DOTH = 30, |
|---|
| 124 |
IEEE80211_PARAM_PWRTARGET = 31, |
|---|
| 125 |
IEEE80211_PARAM_GENREASSOC = 32, |
|---|
| 126 |
IEEE80211_PARAM_COMPRESSION = 33, |
|---|
| 127 |
IEEE80211_PARAM_FF = 34, |
|---|
| 128 |
IEEE80211_PARAM_XR = 35, |
|---|
| 129 |
IEEE80211_PARAM_BURST = 36, |
|---|
| 130 |
IEEE80211_PARAM_PUREG = 37, |
|---|
| 131 |
IEEE80211_PARAM_AR = 38, |
|---|
| 132 |
IEEE80211_PARAM_WDS = 39, |
|---|
| 133 |
IEEE80211_PARAM_BGSCAN = 40, |
|---|
| 134 |
IEEE80211_PARAM_BGSCAN_IDLE = 41, |
|---|
| 135 |
IEEE80211_PARAM_BGSCAN_INTERVAL = 42, |
|---|
| 136 |
IEEE80211_PARAM_MCAST_RATE = 43, |
|---|
| 137 |
IEEE80211_PARAM_COVERAGE_CLASS = 44, |
|---|
| 138 |
IEEE80211_PARAM_COUNTRY_IE = 45, |
|---|
| 139 |
IEEE80211_PARAM_SCANVALID = 46, |
|---|
| 140 |
IEEE80211_PARAM_ROAM_RSSI_11A = 47, |
|---|
| 141 |
IEEE80211_PARAM_ROAM_RSSI_11B = 48, |
|---|
| 142 |
IEEE80211_PARAM_ROAM_RSSI_11G = 49, |
|---|
| 143 |
IEEE80211_PARAM_ROAM_RATE_11A = 50, |
|---|
| 144 |
IEEE80211_PARAM_ROAM_RATE_11B = 51, |
|---|
| 145 |
IEEE80211_PARAM_ROAM_RATE_11G = 52, |
|---|
| 146 |
IEEE80211_PARAM_UAPSDINFO = 53, |
|---|
| 147 |
IEEE80211_PARAM_SLEEP = 54, |
|---|
| 148 |
IEEE80211_PARAM_QOSNULL = 55, |
|---|
| 149 |
IEEE80211_PARAM_PSPOLL = 56, |
|---|
| 150 |
IEEE80211_PARAM_EOSPDROP = 57, |
|---|
| 151 |
IEEE80211_PARAM_MARKDFS = 58, |
|---|
| 152 |
IEEE80211_PARAM_REGCLASS = 59, |
|---|
| 153 |
}; |
|---|
| 154 |
|
|---|
| 155 |
unsigned int ath_get_missed_beacon_count(int socket, char *device); |
|---|
| 156 |
int ath_associate(int socket, char *device, char *mac); |
|---|
| 157 |
int ath_disassoc(int socket, char *device, char *addr); |
|---|
| 158 |
|
|---|
| 159 |
#ifdef ATHEROS_SUPPORT |
|---|
| 160 |
static int set80211param(int socket, char *device, int op, int arg) |
|---|
| 161 |
{ |
|---|
| 162 |
struct iwreq iwr; |
|---|
| 163 |
|
|---|
| 164 |
memset(&iwr, 0, sizeof(iwr)); |
|---|
| 165 |
strncpy(iwr.ifr_name, device, IFNAMSIZ); |
|---|
| 166 |
iwr.u.mode = op; |
|---|
| 167 |
memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg)); |
|---|
| 168 |
|
|---|
| 169 |
if (ioctl(socket, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) { |
|---|
| 170 |
log_text(FATAL, "%s: ioctl() for atheros card (%s) failed (op: %d, arg: %d)\n", __FUNCTION__, device, op, arg); |
|---|
| 171 |
return -1; |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
return 0; |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
static int set80211priv(int socket, char *device, int op, void *data, int len) |
|---|
| 182 |
{ |
|---|
| 183 |
struct iwreq iwr; |
|---|
| 184 |
|
|---|
| 185 |
memset(&iwr, 0, sizeof(iwr)); |
|---|
| 186 |
strncpy(iwr.ifr_name, device, IFNAMSIZ); |
|---|
| 187 |
if (len < IFNAMSIZ) { |
|---|
| 188 |
|
|---|
| 189 |
memcpy(iwr.u.name, data, len); |
|---|
| 190 |
} else { |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
iwr.u.data.pointer = data; |
|---|
| 197 |
iwr.u.data.length = len; |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
if (ioctl(socket, op, &iwr) < 0) { |
|---|
| 201 |
log_text(FATAL, "%s: private ioctl() for atheros card (%s) failed (op: %d)\n", __FUNCTION__, device, op); |
|---|
| 202 |
return -1; |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
return 0; |
|---|
| 206 |
} |
|---|
| 207 |
#endif |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
int ath_associate(int socket, char *device, char *mac) |
|---|
| 211 |
{ |
|---|
| 212 |
#ifdef ATHEROS_SUPPORT |
|---|
| 213 |
struct ieee80211req_mlme mlme; |
|---|
| 214 |
struct ether_addr *bin_mac; |
|---|
| 215 |
int ret = 0; |
|---|
| 216 |
|
|---|
| 217 |
bin_mac = ether_aton(mac); |
|---|
| 218 |
memset(&mlme, 0, sizeof(mlme)); |
|---|
| 219 |
mlme.im_op = IEEE80211_MLME_ASSOC; |
|---|
| 220 |
memcpy(mlme.im_macaddr, bin_mac->ether_addr_octet, IEEE80211_ADDR_LEN); |
|---|
| 221 |
|
|---|
| 222 |
DBG_PRINT("%s(%02X:%02X:%02X:%02X:%02X:%02X)\n", |
|---|
| 223 |
__FUNCTION__, |
|---|
| 224 |
mlme.im_op[0] & 0xFF, |
|---|
| 225 |
mlme.im_op[1] & 0xFF, |
|---|
| 226 |
mlme.im_op[2] & 0xFF, |
|---|
| 227 |
mlme.im_op[3] & 0xFF, |
|---|
| 228 |
mlme.im_op[4] & 0xFF, |
|---|
| 229 |
mlme.im_op[5] & 0xFF); |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
if (set80211param(socket, device, IEEE80211_PARAM_PRIVACY, 0) < 0) |
|---|
| 233 |
ret = -1; |
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
if (set80211param(socket, device, IEEE80211_PARAM_ROAMING, 2) < 0) |
|---|
| 237 |
ret += -1; |
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
if (set80211priv(socket, device, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme)) < 0) |
|---|
| 241 |
ret += -1; |
|---|
| 242 |
|
|---|
| 243 |
return ret; |
|---|
| 244 |
#else |
|---|
| 245 |
|
|---|
| 246 |
return -99; |
|---|
| 247 |
#endif |
|---|
| 248 |
|
|---|
| 249 |
} |
|---|
| 250 |
|
|---|
| 251 |
int ath_disassoc(int socket, char *device, char *addr) |
|---|
| 252 |
{ |
|---|
| 253 |
#ifdef ATHEROS_SUPPORT |
|---|
| 254 |
struct ieee80211req_mlme mlme; |
|---|
| 255 |
struct ether_addr *bin_mac; |
|---|
| 256 |
|
|---|
| 257 |
bin_mac = ether_aton(addr); |
|---|
| 258 |
|
|---|
| 259 |
DBG_PRINT("%s(%02X:%02X:%02X:%02X:%02X:%02X)\n", |
|---|
| 260 |
__FUNCTION__, |
|---|
| 261 |
bin_mac->ether_addr_octet[0] & 0xFF, |
|---|
| 262 |
bin_mac->ether_addr_octet[1] & 0xFF, |
|---|
| 263 |
bin_mac->ether_addr_octet[2] & 0xFF, |
|---|
| 264 |
bin_mac->ether_addr_octet[3] & 0xFF, |
|---|
| 265 |
bin_mac->ether_addr_octet[4] & 0xFF, |
|---|
| 266 |
bin_mac->ether_addr_octet[5] & 0xFF); |
|---|
| 267 |
|
|---|
| 268 |
mlme.im_op = IEEE80211_MLME_DISASSOC; |
|---|
| 269 |
mlme.im_reason = 1; |
|---|
| 270 |
memcpy(mlme.im_macaddr, bin_mac->ether_addr_octet, IEEE80211_ADDR_LEN); |
|---|
| 271 |
return set80211priv(socket, device, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme)); |
|---|
| 272 |
#else |
|---|
| 273 |
|
|---|
| 274 |
return -99; |
|---|
| 275 |
#endif |
|---|
| 276 |
|
|---|
| 277 |
} |
|---|