Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains ioctl functions |
| 3 | */ |
| 4 | #include <linux/ctype.h> |
| 5 | #include <linux/delay.h> |
| 6 | #include <linux/if.h> |
| 7 | #include <linux/if_arp.h> |
| 8 | #include <linux/wireless.h> |
| 9 | #include <linux/bitops.h> |
| 10 | |
| 11 | #include <net/ieee80211.h> |
| 12 | #include <net/iw_handler.h> |
| 13 | |
| 14 | #include "host.h" |
| 15 | #include "radiotap.h" |
| 16 | #include "decl.h" |
| 17 | #include "defs.h" |
| 18 | #include "dev.h" |
| 19 | #include "join.h" |
| 20 | #include "version.h" |
| 21 | #include "wext.h" |
| 22 | #include "assoc.h" |
| 23 | |
| 24 | |
| 25 | /** |
| 26 | * @brief Convert mw value to dbm value |
| 27 | * |
| 28 | * @param mw the value of mw |
| 29 | * @return the value of dbm |
| 30 | */ |
| 31 | static int mw_to_dbm(int mw) |
| 32 | { |
| 33 | if (mw < 2) |
| 34 | return 0; |
| 35 | else if (mw < 3) |
| 36 | return 3; |
| 37 | else if (mw < 4) |
| 38 | return 5; |
| 39 | else if (mw < 6) |
| 40 | return 7; |
| 41 | else if (mw < 7) |
| 42 | return 8; |
| 43 | else if (mw < 8) |
| 44 | return 9; |
| 45 | else if (mw < 10) |
| 46 | return 10; |
| 47 | else if (mw < 13) |
| 48 | return 11; |
| 49 | else if (mw < 16) |
| 50 | return 12; |
| 51 | else if (mw < 20) |
| 52 | return 13; |
| 53 | else if (mw < 25) |
| 54 | return 14; |
| 55 | else if (mw < 32) |
| 56 | return 15; |
| 57 | else if (mw < 40) |
| 58 | return 16; |
| 59 | else if (mw < 50) |
| 60 | return 17; |
| 61 | else if (mw < 63) |
| 62 | return 18; |
| 63 | else if (mw < 79) |
| 64 | return 19; |
| 65 | else if (mw < 100) |
| 66 | return 20; |
| 67 | else |
| 68 | return 21; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @brief Find the channel frequency power info with specific channel |
| 73 | * |
| 74 | * @param adapter A pointer to wlan_adapter structure |
| 75 | * @param band it can be BAND_A, BAND_G or BAND_B |
| 76 | * @param channel the channel for looking |
| 77 | * @return A pointer to struct chan_freq_power structure or NULL if not find. |
| 78 | */ |
| 79 | struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter, |
| 80 | u8 band, u16 channel) |
| 81 | { |
| 82 | struct chan_freq_power *cfp = NULL; |
| 83 | struct region_channel *rc; |
| 84 | int count = sizeof(adapter->region_channel) / |
| 85 | sizeof(adapter->region_channel[0]); |
| 86 | int i, j; |
| 87 | |
| 88 | for (j = 0; !cfp && (j < count); j++) { |
| 89 | rc = &adapter->region_channel[j]; |
| 90 | |
| 91 | if (adapter->enable11d) |
| 92 | rc = &adapter->universal_channel[j]; |
| 93 | if (!rc->valid || !rc->CFP) |
| 94 | continue; |
| 95 | if (rc->band != band) |
| 96 | continue; |
| 97 | for (i = 0; i < rc->nrcfp; i++) { |
| 98 | if (rc->CFP[i].channel == channel) { |
| 99 | cfp = &rc->CFP[i]; |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | if (!cfp && channel) |
| 106 | lbs_pr_debug(1, "libertas_find_cfp_by_band_and_channel(): cannot find " |
| 107 | "cfp by band %d & channel %d\n", band, channel); |
| 108 | |
| 109 | return cfp; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @brief Find the channel frequency power info with specific frequency |
| 114 | * |
| 115 | * @param adapter A pointer to wlan_adapter structure |
| 116 | * @param band it can be BAND_A, BAND_G or BAND_B |
| 117 | * @param freq the frequency for looking |
| 118 | * @return A pointer to struct chan_freq_power structure or NULL if not find. |
| 119 | */ |
| 120 | static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter, |
| 121 | u8 band, u32 freq) |
| 122 | { |
| 123 | struct chan_freq_power *cfp = NULL; |
| 124 | struct region_channel *rc; |
| 125 | int count = sizeof(adapter->region_channel) / |
| 126 | sizeof(adapter->region_channel[0]); |
| 127 | int i, j; |
| 128 | |
| 129 | for (j = 0; !cfp && (j < count); j++) { |
| 130 | rc = &adapter->region_channel[j]; |
| 131 | |
| 132 | if (adapter->enable11d) |
| 133 | rc = &adapter->universal_channel[j]; |
| 134 | if (!rc->valid || !rc->CFP) |
| 135 | continue; |
| 136 | if (rc->band != band) |
| 137 | continue; |
| 138 | for (i = 0; i < rc->nrcfp; i++) { |
| 139 | if (rc->CFP[i].freq == freq) { |
| 140 | cfp = &rc->CFP[i]; |
| 141 | break; |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (!cfp && freq) |
| 147 | lbs_pr_debug(1, "find_cfp_by_band_and_freql(): cannot find cfp by " |
| 148 | "band %d & freq %d\n", band, freq); |
| 149 | |
| 150 | return cfp; |
| 151 | } |
| 152 | |
| 153 | static int updatecurrentchannel(wlan_private * priv) |
| 154 | { |
| 155 | int ret; |
| 156 | |
| 157 | /* |
| 158 | ** the channel in f/w could be out of sync, get the current channel |
| 159 | */ |
| 160 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel, |
| 161 | cmd_opt_802_11_rf_channel_get, |
| 162 | cmd_option_waitforrsp, 0, NULL); |
| 163 | |
| 164 | lbs_pr_debug(1, "Current channel = %d\n", |
| 165 | priv->adapter->curbssparams.channel); |
| 166 | |
| 167 | return ret; |
| 168 | } |
| 169 | |
| 170 | static int setcurrentchannel(wlan_private * priv, int channel) |
| 171 | { |
| 172 | lbs_pr_debug(1, "Set channel = %d\n", channel); |
| 173 | |
| 174 | /* |
| 175 | ** Current channel is not set to adhocchannel requested, set channel |
| 176 | */ |
| 177 | return (libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel, |
| 178 | cmd_opt_802_11_rf_channel_set, |
| 179 | cmd_option_waitforrsp, 0, &channel)); |
| 180 | } |
| 181 | |
| 182 | static int changeadhocchannel(wlan_private * priv, int channel) |
| 183 | { |
| 184 | int ret = 0; |
| 185 | wlan_adapter *adapter = priv->adapter; |
| 186 | |
| 187 | adapter->adhocchannel = channel; |
| 188 | |
| 189 | updatecurrentchannel(priv); |
| 190 | |
| 191 | if (adapter->curbssparams.channel == adapter->adhocchannel) { |
| 192 | /* adhocchannel is set to the current channel already */ |
| 193 | LEAVE(); |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | lbs_pr_debug(1, "Updating channel from %d to %d\n", |
| 198 | adapter->curbssparams.channel, adapter->adhocchannel); |
| 199 | |
| 200 | setcurrentchannel(priv, adapter->adhocchannel); |
| 201 | |
| 202 | updatecurrentchannel(priv); |
| 203 | |
| 204 | if (adapter->curbssparams.channel != adapter->adhocchannel) { |
| 205 | lbs_pr_debug(1, "failed to updated channel to %d, channel = %d\n", |
| 206 | adapter->adhocchannel, adapter->curbssparams.channel); |
| 207 | LEAVE(); |
| 208 | return -1; |
| 209 | } |
| 210 | |
| 211 | if (adapter->connect_status == libertas_connected) { |
| 212 | int i; |
| 213 | struct WLAN_802_11_SSID curadhocssid; |
| 214 | |
| 215 | lbs_pr_debug(1, "channel Changed while in an IBSS\n"); |
| 216 | |
| 217 | /* Copy the current ssid */ |
| 218 | memcpy(&curadhocssid, &adapter->curbssparams.ssid, |
| 219 | sizeof(struct WLAN_802_11_SSID)); |
| 220 | |
| 221 | /* Exit Adhoc mode */ |
| 222 | lbs_pr_debug(1, "In changeadhocchannel(): Sending Adhoc Stop\n"); |
| 223 | ret = libertas_stop_adhoc_network(priv); |
| 224 | |
| 225 | if (ret) { |
| 226 | LEAVE(); |
| 227 | return ret; |
| 228 | } |
| 229 | /* Scan for the network, do not save previous results. Stale |
| 230 | * scan data will cause us to join a non-existant adhoc network |
| 231 | */ |
| 232 | libertas_send_specific_SSID_scan(priv, &curadhocssid, 0); |
| 233 | |
| 234 | // find out the BSSID that matches the current SSID |
| 235 | i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL, |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 236 | IW_MODE_ADHOC); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 237 | |
| 238 | if (i >= 0) { |
| 239 | lbs_pr_debug(1, "SSID found at %d in List," |
| 240 | "so join\n", i); |
| 241 | libertas_join_adhoc_network(priv, &adapter->scantable[i]); |
| 242 | } else { |
| 243 | // else send START command |
| 244 | lbs_pr_debug(1, "SSID not found in list, " |
| 245 | "so creating adhoc with ssid = %s\n", |
| 246 | curadhocssid.ssid); |
| 247 | libertas_start_adhoc_network(priv, &curadhocssid); |
| 248 | } // end of else (START command) |
| 249 | } |
| 250 | |
| 251 | LEAVE(); |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @brief Set Radio On/OFF |
| 257 | * |
| 258 | * @param priv A pointer to wlan_private structure |
| 259 | * @option Radio Option |
| 260 | * @return 0 --success, otherwise fail |
| 261 | */ |
| 262 | int wlan_radio_ioctl(wlan_private * priv, u8 option) |
| 263 | { |
| 264 | int ret = 0; |
| 265 | wlan_adapter *adapter = priv->adapter; |
| 266 | |
| 267 | ENTER(); |
| 268 | |
| 269 | if (adapter->radioon != option) { |
| 270 | lbs_pr_debug(1, "Switching %s the Radio\n", option ? "On" : "Off"); |
| 271 | adapter->radioon = option; |
| 272 | |
| 273 | ret = libertas_prepare_and_send_command(priv, |
| 274 | cmd_802_11_radio_control, |
| 275 | cmd_act_set, |
| 276 | cmd_option_waitforrsp, 0, NULL); |
| 277 | } |
| 278 | |
| 279 | LEAVE(); |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * @brief Copy rates |
| 285 | * |
| 286 | * @param dest A pointer to Dest Buf |
| 287 | * @param src A pointer to Src Buf |
| 288 | * @param len The len of Src Buf |
| 289 | * @return Number of rates copyed |
| 290 | */ |
| 291 | static inline int copyrates(u8 * dest, int pos, u8 * src, int len) |
| 292 | { |
| 293 | int i; |
| 294 | |
| 295 | for (i = 0; i < len && src[i]; i++, pos++) { |
| 296 | if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES) |
| 297 | break; |
| 298 | dest[pos] = src[i]; |
| 299 | } |
| 300 | |
| 301 | return pos; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * @brief Get active data rates |
| 306 | * |
| 307 | * @param adapter A pointer to wlan_adapter structure |
| 308 | * @param rate The buf to return the active rates |
| 309 | * @return The number of rates |
| 310 | */ |
| 311 | static int get_active_data_rates(wlan_adapter * adapter, |
| 312 | u8* rates) |
| 313 | { |
| 314 | int k = 0; |
| 315 | |
| 316 | ENTER(); |
| 317 | |
| 318 | if (adapter->connect_status != libertas_connected) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 319 | if (adapter->mode == IW_MODE_INFRA) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 320 | lbs_pr_debug(1, "Infra\n"); |
| 321 | k = copyrates(rates, k, libertas_supported_rates, |
| 322 | sizeof(libertas_supported_rates)); |
| 323 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 324 | lbs_pr_debug(1, "Adhoc G\n"); |
| 325 | k = copyrates(rates, k, libertas_adhoc_rates_g, |
| 326 | sizeof(libertas_adhoc_rates_g)); |
| 327 | } |
| 328 | } else { |
| 329 | k = copyrates(rates, 0, adapter->curbssparams.datarates, |
| 330 | adapter->curbssparams.numofrates); |
| 331 | } |
| 332 | |
| 333 | LEAVE(); |
| 334 | |
| 335 | return k; |
| 336 | } |
| 337 | |
| 338 | static int wlan_get_name(struct net_device *dev, struct iw_request_info *info, |
| 339 | char *cwrq, char *extra) |
| 340 | { |
| 341 | const char *cp; |
| 342 | char comm[6] = { "COMM-" }; |
| 343 | char mrvl[6] = { "MRVL-" }; |
| 344 | int cnt; |
| 345 | |
| 346 | ENTER(); |
| 347 | |
| 348 | strcpy(cwrq, mrvl); |
| 349 | |
| 350 | cp = strstr(libertas_driver_version, comm); |
| 351 | if (cp == libertas_driver_version) //skip leading "COMM-" |
| 352 | cp = libertas_driver_version + strlen(comm); |
| 353 | else |
| 354 | cp = libertas_driver_version; |
| 355 | |
| 356 | cnt = strlen(mrvl); |
| 357 | cwrq += cnt; |
| 358 | while (cnt < 16 && (*cp != '-')) { |
| 359 | *cwrq++ = toupper(*cp++); |
| 360 | cnt++; |
| 361 | } |
| 362 | *cwrq = '\0'; |
| 363 | |
| 364 | LEAVE(); |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info, |
| 370 | struct iw_freq *fwrq, char *extra) |
| 371 | { |
| 372 | wlan_private *priv = dev->priv; |
| 373 | wlan_adapter *adapter = priv->adapter; |
| 374 | struct chan_freq_power *cfp; |
| 375 | |
| 376 | ENTER(); |
| 377 | |
| 378 | cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, |
| 379 | adapter->curbssparams.channel); |
| 380 | |
| 381 | if (!cfp) { |
| 382 | if (adapter->curbssparams.channel) |
| 383 | lbs_pr_debug(1, "Invalid channel=%d\n", |
| 384 | adapter->curbssparams.channel); |
| 385 | return -EINVAL; |
| 386 | } |
| 387 | |
| 388 | fwrq->m = (long)cfp->freq * 100000; |
| 389 | fwrq->e = 1; |
| 390 | |
| 391 | lbs_pr_debug(1, "freq=%u\n", fwrq->m); |
| 392 | |
| 393 | LEAVE(); |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info, |
| 398 | struct sockaddr *awrq, char *extra) |
| 399 | { |
| 400 | wlan_private *priv = dev->priv; |
| 401 | wlan_adapter *adapter = priv->adapter; |
| 402 | |
| 403 | ENTER(); |
| 404 | |
| 405 | if (adapter->connect_status == libertas_connected) { |
| 406 | memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN); |
| 407 | } else { |
| 408 | memset(awrq->sa_data, 0, ETH_ALEN); |
| 409 | } |
| 410 | awrq->sa_family = ARPHRD_ETHER; |
| 411 | |
| 412 | LEAVE(); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info, |
| 417 | struct iw_point *dwrq, char *extra) |
| 418 | { |
| 419 | wlan_private *priv = dev->priv; |
| 420 | wlan_adapter *adapter = priv->adapter; |
| 421 | |
| 422 | ENTER(); |
| 423 | |
| 424 | /* |
| 425 | * Check the size of the string |
| 426 | */ |
| 427 | |
| 428 | if (dwrq->length > 16) { |
| 429 | return -E2BIG; |
| 430 | } |
| 431 | |
| 432 | mutex_lock(&adapter->lock); |
| 433 | memset(adapter->nodename, 0, sizeof(adapter->nodename)); |
| 434 | memcpy(adapter->nodename, extra, dwrq->length); |
| 435 | mutex_unlock(&adapter->lock); |
| 436 | |
| 437 | LEAVE(); |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info, |
| 442 | struct iw_point *dwrq, char *extra) |
| 443 | { |
| 444 | wlan_private *priv = dev->priv; |
| 445 | wlan_adapter *adapter = priv->adapter; |
| 446 | |
| 447 | ENTER(); |
| 448 | |
| 449 | /* |
| 450 | * Get the Nick Name saved |
| 451 | */ |
| 452 | |
| 453 | mutex_lock(&adapter->lock); |
| 454 | strncpy(extra, adapter->nodename, 16); |
| 455 | mutex_unlock(&adapter->lock); |
| 456 | |
| 457 | extra[16] = '\0'; |
| 458 | |
| 459 | /* |
| 460 | * If none, we may want to get the one that was set |
| 461 | */ |
| 462 | |
| 463 | /* |
| 464 | * Push it out ! |
| 465 | */ |
| 466 | dwrq->length = strlen(extra) + 1; |
| 467 | |
| 468 | LEAVE(); |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info, |
| 473 | struct iw_param *vwrq, char *extra) |
| 474 | { |
| 475 | int ret = 0; |
| 476 | wlan_private *priv = dev->priv; |
| 477 | wlan_adapter *adapter = priv->adapter; |
| 478 | int rthr = vwrq->value; |
| 479 | |
| 480 | ENTER(); |
| 481 | |
| 482 | if (vwrq->disabled) { |
| 483 | adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE; |
| 484 | } else { |
| 485 | if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE) |
| 486 | return -EINVAL; |
| 487 | adapter->rtsthsd = rthr; |
| 488 | } |
| 489 | |
| 490 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 491 | cmd_act_set, cmd_option_waitforrsp, |
| 492 | OID_802_11_RTS_THRESHOLD, &rthr); |
| 493 | |
| 494 | LEAVE(); |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info, |
| 499 | struct iw_param *vwrq, char *extra) |
| 500 | { |
| 501 | int ret = 0; |
| 502 | wlan_private *priv = dev->priv; |
| 503 | wlan_adapter *adapter = priv->adapter; |
| 504 | |
| 505 | ENTER(); |
| 506 | |
| 507 | adapter->rtsthsd = 0; |
| 508 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 509 | cmd_act_get, cmd_option_waitforrsp, |
| 510 | OID_802_11_RTS_THRESHOLD, NULL); |
| 511 | if (ret) { |
| 512 | LEAVE(); |
| 513 | return ret; |
| 514 | } |
| 515 | |
| 516 | vwrq->value = adapter->rtsthsd; |
| 517 | vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE) |
| 518 | || (vwrq->value > MRVDRV_RTS_MAX_VALUE)); |
| 519 | vwrq->fixed = 1; |
| 520 | |
| 521 | LEAVE(); |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info, |
| 526 | struct iw_param *vwrq, char *extra) |
| 527 | { |
| 528 | int ret = 0; |
| 529 | int fthr = vwrq->value; |
| 530 | wlan_private *priv = dev->priv; |
| 531 | wlan_adapter *adapter = priv->adapter; |
| 532 | |
| 533 | ENTER(); |
| 534 | |
| 535 | if (vwrq->disabled) { |
| 536 | adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE; |
| 537 | } else { |
| 538 | if (fthr < MRVDRV_FRAG_MIN_VALUE |
| 539 | || fthr > MRVDRV_FRAG_MAX_VALUE) |
| 540 | return -EINVAL; |
| 541 | adapter->fragthsd = fthr; |
| 542 | } |
| 543 | |
| 544 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 545 | cmd_act_set, cmd_option_waitforrsp, |
| 546 | OID_802_11_FRAGMENTATION_THRESHOLD, &fthr); |
| 547 | LEAVE(); |
| 548 | return ret; |
| 549 | } |
| 550 | |
| 551 | static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info, |
| 552 | struct iw_param *vwrq, char *extra) |
| 553 | { |
| 554 | int ret = 0; |
| 555 | wlan_private *priv = dev->priv; |
| 556 | wlan_adapter *adapter = priv->adapter; |
| 557 | |
| 558 | ENTER(); |
| 559 | |
| 560 | adapter->fragthsd = 0; |
| 561 | ret = libertas_prepare_and_send_command(priv, |
| 562 | cmd_802_11_snmp_mib, |
| 563 | cmd_act_get, cmd_option_waitforrsp, |
| 564 | OID_802_11_FRAGMENTATION_THRESHOLD, NULL); |
| 565 | if (ret) { |
| 566 | LEAVE(); |
| 567 | return ret; |
| 568 | } |
| 569 | |
| 570 | vwrq->value = adapter->fragthsd; |
| 571 | vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE) |
| 572 | || (vwrq->value > MRVDRV_FRAG_MAX_VALUE)); |
| 573 | vwrq->fixed = 1; |
| 574 | |
| 575 | LEAVE(); |
| 576 | return ret; |
| 577 | } |
| 578 | |
| 579 | static int wlan_get_mode(struct net_device *dev, |
| 580 | struct iw_request_info *info, u32 * uwrq, char *extra) |
| 581 | { |
| 582 | wlan_private *priv = dev->priv; |
| 583 | wlan_adapter *adapter = priv->adapter; |
| 584 | |
| 585 | ENTER(); |
| 586 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 587 | *uwrq = adapter->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 588 | |
| 589 | LEAVE(); |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int wlan_get_txpow(struct net_device *dev, |
| 594 | struct iw_request_info *info, |
| 595 | struct iw_param *vwrq, char *extra) |
| 596 | { |
| 597 | int ret = 0; |
| 598 | wlan_private *priv = dev->priv; |
| 599 | wlan_adapter *adapter = priv->adapter; |
| 600 | |
| 601 | ENTER(); |
| 602 | |
| 603 | ret = libertas_prepare_and_send_command(priv, |
| 604 | cmd_802_11_rf_tx_power, |
| 605 | cmd_act_tx_power_opt_get, |
| 606 | cmd_option_waitforrsp, 0, NULL); |
| 607 | |
| 608 | if (ret) { |
| 609 | LEAVE(); |
| 610 | return ret; |
| 611 | } |
| 612 | |
| 613 | lbs_pr_debug(1, "TXPOWER GET %d dbm.\n", adapter->txpowerlevel); |
| 614 | vwrq->value = adapter->txpowerlevel; |
| 615 | vwrq->fixed = 1; |
| 616 | if (adapter->radioon) { |
| 617 | vwrq->disabled = 0; |
| 618 | vwrq->flags = IW_TXPOW_DBM; |
| 619 | } else { |
| 620 | vwrq->disabled = 1; |
| 621 | } |
| 622 | |
| 623 | LEAVE(); |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info, |
| 628 | struct iw_param *vwrq, char *extra) |
| 629 | { |
| 630 | int ret = 0; |
| 631 | wlan_private *priv = dev->priv; |
| 632 | wlan_adapter *adapter = priv->adapter; |
| 633 | |
| 634 | ENTER(); |
| 635 | |
| 636 | if (vwrq->flags == IW_RETRY_LIMIT) { |
| 637 | /* The MAC has a 4-bit Total_Tx_Count register |
| 638 | Total_Tx_Count = 1 + Tx_Retry_Count */ |
| 639 | #define TX_RETRY_MIN 0 |
| 640 | #define TX_RETRY_MAX 14 |
| 641 | if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX) |
| 642 | return -EINVAL; |
| 643 | |
| 644 | /* Adding 1 to convert retry count to try count */ |
| 645 | adapter->txretrycount = vwrq->value + 1; |
| 646 | |
| 647 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib, |
| 648 | cmd_act_set, |
| 649 | cmd_option_waitforrsp, |
| 650 | OID_802_11_TX_RETRYCOUNT, NULL); |
| 651 | |
| 652 | if (ret) { |
| 653 | LEAVE(); |
| 654 | return ret; |
| 655 | } |
| 656 | } else { |
| 657 | return -EOPNOTSUPP; |
| 658 | } |
| 659 | |
| 660 | LEAVE(); |
| 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info, |
| 665 | struct iw_param *vwrq, char *extra) |
| 666 | { |
| 667 | wlan_private *priv = dev->priv; |
| 668 | wlan_adapter *adapter = priv->adapter; |
| 669 | int ret = 0; |
| 670 | |
| 671 | ENTER(); |
| 672 | adapter->txretrycount = 0; |
| 673 | ret = libertas_prepare_and_send_command(priv, |
| 674 | cmd_802_11_snmp_mib, |
| 675 | cmd_act_get, cmd_option_waitforrsp, |
| 676 | OID_802_11_TX_RETRYCOUNT, NULL); |
| 677 | if (ret) { |
| 678 | LEAVE(); |
| 679 | return ret; |
| 680 | } |
| 681 | vwrq->disabled = 0; |
| 682 | if (!vwrq->flags) { |
| 683 | vwrq->flags = IW_RETRY_LIMIT; |
| 684 | /* Subtract 1 to convert try count to retry count */ |
| 685 | vwrq->value = adapter->txretrycount - 1; |
| 686 | } |
| 687 | |
| 688 | LEAVE(); |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | static inline void sort_channels(struct iw_freq *freq, int num) |
| 693 | { |
| 694 | int i, j; |
| 695 | struct iw_freq temp; |
| 696 | |
| 697 | for (i = 0; i < num; i++) |
| 698 | for (j = i + 1; j < num; j++) |
| 699 | if (freq[i].i > freq[j].i) { |
| 700 | temp.i = freq[i].i; |
| 701 | temp.m = freq[i].m; |
| 702 | |
| 703 | freq[i].i = freq[j].i; |
| 704 | freq[i].m = freq[j].m; |
| 705 | |
| 706 | freq[j].i = temp.i; |
| 707 | freq[j].m = temp.m; |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | /* data rate listing |
| 712 | MULTI_BANDS: |
| 713 | abg a b b/g |
| 714 | Infra G(12) A(8) B(4) G(12) |
| 715 | Adhoc A+B(12) A(8) B(4) B(4) |
| 716 | |
| 717 | non-MULTI_BANDS: |
| 718 | b b/g |
| 719 | Infra B(4) G(12) |
| 720 | Adhoc B(4) B(4) |
| 721 | */ |
| 722 | /** |
| 723 | * @brief Get Range Info |
| 724 | * |
| 725 | * @param dev A pointer to net_device structure |
| 726 | * @param info A pointer to iw_request_info structure |
| 727 | * @param vwrq A pointer to iw_param structure |
| 728 | * @param extra A pointer to extra data buf |
| 729 | * @return 0 --success, otherwise fail |
| 730 | */ |
| 731 | static int wlan_get_range(struct net_device *dev, struct iw_request_info *info, |
| 732 | struct iw_point *dwrq, char *extra) |
| 733 | { |
| 734 | int i, j; |
| 735 | wlan_private *priv = dev->priv; |
| 736 | wlan_adapter *adapter = priv->adapter; |
| 737 | struct iw_range *range = (struct iw_range *)extra; |
| 738 | struct chan_freq_power *cfp; |
| 739 | u8 rates[WLAN_SUPPORTED_RATES]; |
| 740 | |
| 741 | u8 flag = 0; |
| 742 | |
| 743 | ENTER(); |
| 744 | |
| 745 | dwrq->length = sizeof(struct iw_range); |
| 746 | memset(range, 0, sizeof(struct iw_range)); |
| 747 | |
| 748 | range->min_nwid = 0; |
| 749 | range->max_nwid = 0; |
| 750 | |
| 751 | memset(rates, 0, sizeof(rates)); |
| 752 | range->num_bitrates = get_active_data_rates(adapter, rates); |
| 753 | |
| 754 | for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i]; |
| 755 | i++) { |
| 756 | range->bitrate[i] = (rates[i] & 0x7f) * 500000; |
| 757 | } |
| 758 | range->num_bitrates = i; |
| 759 | lbs_pr_debug(1, "IW_MAX_BITRATES=%d num_bitrates=%d\n", IW_MAX_BITRATES, |
| 760 | range->num_bitrates); |
| 761 | |
| 762 | range->num_frequency = 0; |
| 763 | if (priv->adapter->enable11d && |
| 764 | adapter->connect_status == libertas_connected) { |
| 765 | u8 chan_no; |
| 766 | u8 band; |
| 767 | |
| 768 | struct parsed_region_chan_11d *parsed_region_chan = |
| 769 | &adapter->parsed_region_chan; |
| 770 | |
| 771 | if (parsed_region_chan == NULL) { |
| 772 | lbs_pr_debug(1, "11D:parsed_region_chan is NULL\n"); |
| 773 | LEAVE(); |
| 774 | return 0; |
| 775 | } |
| 776 | band = parsed_region_chan->band; |
| 777 | lbs_pr_debug(1, "band=%d NoOfChan=%d\n", band, |
| 778 | parsed_region_chan->nr_chan); |
| 779 | |
| 780 | for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES) |
| 781 | && (i < parsed_region_chan->nr_chan); i++) { |
| 782 | chan_no = parsed_region_chan->chanpwr[i].chan; |
| 783 | lbs_pr_debug(1, "chan_no=%d\n", chan_no); |
| 784 | range->freq[range->num_frequency].i = (long)chan_no; |
| 785 | range->freq[range->num_frequency].m = |
| 786 | (long)libertas_chan_2_freq(chan_no, band) * 100000; |
| 787 | range->freq[range->num_frequency].e = 1; |
| 788 | range->num_frequency++; |
| 789 | } |
| 790 | flag = 1; |
| 791 | } |
| 792 | if (!flag) { |
| 793 | for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES) |
| 794 | && (j < sizeof(adapter->region_channel) |
| 795 | / sizeof(adapter->region_channel[0])); j++) { |
| 796 | cfp = adapter->region_channel[j].CFP; |
| 797 | for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES) |
| 798 | && adapter->region_channel[j].valid |
| 799 | && cfp |
| 800 | && (i < adapter->region_channel[j].nrcfp); i++) { |
| 801 | range->freq[range->num_frequency].i = |
| 802 | (long)cfp->channel; |
| 803 | range->freq[range->num_frequency].m = |
| 804 | (long)cfp->freq * 100000; |
| 805 | range->freq[range->num_frequency].e = 1; |
| 806 | cfp++; |
| 807 | range->num_frequency++; |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | lbs_pr_debug(1, "IW_MAX_FREQUENCIES=%d num_frequency=%d\n", |
| 813 | IW_MAX_FREQUENCIES, range->num_frequency); |
| 814 | |
| 815 | range->num_channels = range->num_frequency; |
| 816 | |
| 817 | sort_channels(&range->freq[0], range->num_frequency); |
| 818 | |
| 819 | /* |
| 820 | * Set an indication of the max TCP throughput in bit/s that we can |
| 821 | * expect using this interface |
| 822 | */ |
| 823 | if (i > 2) |
| 824 | range->throughput = 5000 * 1000; |
| 825 | else |
| 826 | range->throughput = 1500 * 1000; |
| 827 | |
| 828 | range->min_rts = MRVDRV_RTS_MIN_VALUE; |
| 829 | range->max_rts = MRVDRV_RTS_MAX_VALUE; |
| 830 | range->min_frag = MRVDRV_FRAG_MIN_VALUE; |
| 831 | range->max_frag = MRVDRV_FRAG_MAX_VALUE; |
| 832 | |
| 833 | range->encoding_size[0] = 5; |
| 834 | range->encoding_size[1] = 13; |
| 835 | range->num_encoding_sizes = 2; |
| 836 | range->max_encoding_tokens = 4; |
| 837 | |
| 838 | range->min_pmp = 1000000; |
| 839 | range->max_pmp = 120000000; |
| 840 | range->min_pmt = 1000; |
| 841 | range->max_pmt = 1000000; |
| 842 | range->pmp_flags = IW_POWER_PERIOD; |
| 843 | range->pmt_flags = IW_POWER_TIMEOUT; |
| 844 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R; |
| 845 | |
| 846 | /* |
| 847 | * Minimum version we recommend |
| 848 | */ |
| 849 | range->we_version_source = 15; |
| 850 | |
| 851 | /* |
| 852 | * Version we are compiled with |
| 853 | */ |
| 854 | range->we_version_compiled = WIRELESS_EXT; |
| 855 | |
| 856 | range->retry_capa = IW_RETRY_LIMIT; |
| 857 | range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 858 | |
| 859 | range->min_retry = TX_RETRY_MIN; |
| 860 | range->max_retry = TX_RETRY_MAX; |
| 861 | |
| 862 | /* |
| 863 | * Set the qual, level and noise range values |
| 864 | */ |
| 865 | range->max_qual.qual = 100; |
| 866 | range->max_qual.level = 0; |
| 867 | range->max_qual.noise = 0; |
| 868 | range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
| 869 | |
| 870 | range->avg_qual.qual = 70; |
| 871 | /* TODO: Find real 'good' to 'bad' threshold value for RSSI */ |
| 872 | range->avg_qual.level = 0; |
| 873 | range->avg_qual.noise = 0; |
| 874 | range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
| 875 | |
| 876 | range->sensitivity = 0; |
| 877 | |
| 878 | /* |
| 879 | * Setup the supported power level ranges |
| 880 | */ |
| 881 | memset(range->txpower, 0, sizeof(range->txpower)); |
| 882 | range->txpower[0] = 5; |
| 883 | range->txpower[1] = 7; |
| 884 | range->txpower[2] = 9; |
| 885 | range->txpower[3] = 11; |
| 886 | range->txpower[4] = 13; |
| 887 | range->txpower[5] = 15; |
| 888 | range->txpower[6] = 17; |
| 889 | range->txpower[7] = 19; |
| 890 | |
| 891 | range->num_txpower = 8; |
| 892 | range->txpower_capa = IW_TXPOW_DBM; |
| 893 | range->txpower_capa |= IW_TXPOW_RANGE; |
| 894 | |
| 895 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 896 | IW_EVENT_CAPA_MASK(SIOCGIWAP) | |
| 897 | IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); |
| 898 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
| 899 | |
| 900 | if (adapter->fwcapinfo & FW_CAPINFO_WPA) { |
| 901 | range->enc_capa = IW_ENC_CAPA_WPA |
| 902 | | IW_ENC_CAPA_WPA2 |
| 903 | | IW_ENC_CAPA_CIPHER_TKIP |
| 904 | | IW_ENC_CAPA_CIPHER_CCMP; |
| 905 | } |
| 906 | |
| 907 | LEAVE(); |
| 908 | return 0; |
| 909 | } |
| 910 | |
| 911 | static int wlan_set_power(struct net_device *dev, struct iw_request_info *info, |
| 912 | struct iw_param *vwrq, char *extra) |
| 913 | { |
| 914 | wlan_private *priv = dev->priv; |
| 915 | wlan_adapter *adapter = priv->adapter; |
| 916 | |
| 917 | ENTER(); |
| 918 | |
| 919 | /* PS is currently supported only in Infrastructure mode |
| 920 | * Remove this check if it is to be supported in IBSS mode also |
| 921 | */ |
| 922 | |
| 923 | if (vwrq->disabled) { |
| 924 | adapter->psmode = wlan802_11powermodecam; |
| 925 | if (adapter->psstate != PS_STATE_FULL_POWER) { |
| 926 | libertas_ps_wakeup(priv, cmd_option_waitforrsp); |
| 927 | } |
| 928 | |
| 929 | return 0; |
| 930 | } |
| 931 | |
| 932 | if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { |
| 933 | lbs_pr_debug(1, |
| 934 | "Setting power timeout command is not supported\n"); |
| 935 | return -EINVAL; |
| 936 | } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) { |
| 937 | lbs_pr_debug(1, "Setting power period command is not supported\n"); |
| 938 | return -EINVAL; |
| 939 | } |
| 940 | |
| 941 | if (adapter->psmode != wlan802_11powermodecam) { |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | adapter->psmode = wlan802_11powermodemax_psp; |
| 946 | |
| 947 | if (adapter->connect_status == libertas_connected) { |
| 948 | libertas_ps_sleep(priv, cmd_option_waitforrsp); |
| 949 | } |
| 950 | |
| 951 | LEAVE(); |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | static int wlan_get_power(struct net_device *dev, struct iw_request_info *info, |
| 956 | struct iw_param *vwrq, char *extra) |
| 957 | { |
| 958 | wlan_private *priv = dev->priv; |
| 959 | wlan_adapter *adapter = priv->adapter; |
| 960 | int mode; |
| 961 | |
| 962 | ENTER(); |
| 963 | |
| 964 | mode = adapter->psmode; |
| 965 | |
| 966 | if ((vwrq->disabled = (mode == wlan802_11powermodecam)) |
| 967 | || adapter->connect_status == libertas_disconnected) { |
| 968 | LEAVE(); |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | vwrq->value = 0; |
| 973 | |
| 974 | LEAVE(); |
| 975 | return 0; |
| 976 | } |
| 977 | |
| 978 | /* |
| 979 | * iwpriv settable callbacks |
| 980 | */ |
| 981 | |
| 982 | static const iw_handler wlan_private_handler[] = { |
| 983 | NULL, /* SIOCIWFIRSTPRIV */ |
| 984 | }; |
| 985 | |
| 986 | static const struct iw_priv_args wlan_private_args[] = { |
| 987 | /* |
| 988 | * { cmd, set_args, get_args, name } |
| 989 | */ |
| 990 | { |
| 991 | WLANSCAN_TYPE, |
| 992 | IW_PRIV_TYPE_CHAR | 8, |
| 993 | IW_PRIV_TYPE_CHAR | 8, |
| 994 | "scantype"}, |
| 995 | |
| 996 | { |
| 997 | WLAN_SETINT_GETINT, |
| 998 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 999 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1000 | ""}, |
| 1001 | { |
| 1002 | WLANNF, |
| 1003 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1004 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1005 | "getNF"}, |
| 1006 | { |
| 1007 | WLANRSSI, |
| 1008 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1009 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1010 | "getRSSI"}, |
| 1011 | { |
| 1012 | WLANENABLE11D, |
| 1013 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1014 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1015 | "enable11d"}, |
| 1016 | { |
| 1017 | WLANADHOCGRATE, |
| 1018 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1019 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1020 | "adhocgrate"}, |
| 1021 | |
| 1022 | { |
| 1023 | WLAN_SUBCMD_SET_PRESCAN, |
| 1024 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1025 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1026 | "prescan"}, |
| 1027 | { |
| 1028 | WLAN_SETONEINT_GETONEINT, |
| 1029 | IW_PRIV_TYPE_INT | 1, |
| 1030 | IW_PRIV_TYPE_INT | 1, |
| 1031 | ""}, |
| 1032 | { |
| 1033 | WLAN_BEACON_INTERVAL, |
| 1034 | IW_PRIV_TYPE_INT | 1, |
| 1035 | IW_PRIV_TYPE_INT | 1, |
| 1036 | "bcninterval"}, |
| 1037 | { |
| 1038 | WLAN_LISTENINTRVL, |
| 1039 | IW_PRIV_TYPE_INT | 1, |
| 1040 | IW_PRIV_TYPE_INT | 1, |
| 1041 | "lolisteninter"}, |
| 1042 | { |
| 1043 | WLAN_TXCONTROL, |
| 1044 | IW_PRIV_TYPE_INT | 1, |
| 1045 | IW_PRIV_TYPE_INT | 1, |
| 1046 | "txcontrol"}, |
| 1047 | { |
| 1048 | WLAN_NULLPKTINTERVAL, |
| 1049 | IW_PRIV_TYPE_INT | 1, |
| 1050 | IW_PRIV_TYPE_INT | 1, |
| 1051 | "psnullinterval"}, |
| 1052 | /* Using iwpriv sub-command feature */ |
| 1053 | { |
| 1054 | WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */ |
| 1055 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1056 | IW_PRIV_TYPE_NONE, |
| 1057 | ""}, |
| 1058 | |
| 1059 | { |
| 1060 | WLAN_SUBCMD_SETRXANTENNA, |
| 1061 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1062 | IW_PRIV_TYPE_NONE, |
| 1063 | "setrxant"}, |
| 1064 | { |
| 1065 | WLAN_SUBCMD_SETTXANTENNA, |
| 1066 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1067 | IW_PRIV_TYPE_NONE, |
| 1068 | "settxant"}, |
| 1069 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1070 | WLANSETENCRYPTIONMODE, |
| 1071 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1072 | IW_PRIV_TYPE_NONE, |
| 1073 | "encryptionmode", |
| 1074 | }, |
| 1075 | { |
| 1076 | WLANSETREGION, |
| 1077 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1078 | IW_PRIV_TYPE_NONE, |
| 1079 | "setregioncode"}, |
| 1080 | { |
| 1081 | WLAN_SET_LISTEN_INTERVAL, |
| 1082 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1083 | IW_PRIV_TYPE_NONE, |
| 1084 | "setlisteninter"}, |
| 1085 | { |
| 1086 | WLAN_SET_MULTIPLE_DTIM, |
| 1087 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1088 | IW_PRIV_TYPE_NONE, |
| 1089 | "setmultipledtim"}, |
| 1090 | { |
| 1091 | WLAN_SET_ATIM_WINDOW, |
| 1092 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1093 | IW_PRIV_TYPE_NONE, |
| 1094 | "atimwindow"}, |
| 1095 | { |
| 1096 | WLANSETBCNAVG, |
| 1097 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1098 | IW_PRIV_TYPE_NONE, |
| 1099 | "setbcnavg"}, |
| 1100 | { |
| 1101 | WLANSETDATAAVG, |
| 1102 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1103 | IW_PRIV_TYPE_NONE, |
| 1104 | "setdataavg"}, |
| 1105 | { |
| 1106 | WLAN_SET_LINKMODE, |
| 1107 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1108 | IW_PRIV_TYPE_NONE, |
| 1109 | "linkmode"}, |
| 1110 | { |
| 1111 | WLAN_SET_RADIOMODE, |
| 1112 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1113 | IW_PRIV_TYPE_NONE, |
| 1114 | "radiomode"}, |
| 1115 | { |
| 1116 | WLAN_SET_DEBUGMODE, |
| 1117 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1118 | IW_PRIV_TYPE_NONE, |
| 1119 | "debugmode"}, |
| 1120 | { |
| 1121 | WLAN_SUBCMD_MESH_SET_TTL, |
| 1122 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1123 | IW_PRIV_TYPE_NONE, |
| 1124 | "mesh_set_ttl"}, |
| 1125 | { |
| 1126 | WLAN_SETNONE_GETONEINT, |
| 1127 | IW_PRIV_TYPE_NONE, |
| 1128 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1129 | ""}, |
| 1130 | { |
| 1131 | WLANGETREGION, |
| 1132 | IW_PRIV_TYPE_NONE, |
| 1133 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1134 | "getregioncode"}, |
| 1135 | { |
| 1136 | WLAN_GET_LISTEN_INTERVAL, |
| 1137 | IW_PRIV_TYPE_NONE, |
| 1138 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1139 | "getlisteninter"}, |
| 1140 | { |
| 1141 | WLAN_GET_MULTIPLE_DTIM, |
| 1142 | IW_PRIV_TYPE_NONE, |
| 1143 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1144 | "getmultipledtim"}, |
| 1145 | { |
| 1146 | WLAN_GET_TX_RATE, |
| 1147 | IW_PRIV_TYPE_NONE, |
| 1148 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1149 | "gettxrate"}, |
| 1150 | { |
| 1151 | WLANGETBCNAVG, |
| 1152 | IW_PRIV_TYPE_NONE, |
| 1153 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1154 | "getbcnavg"}, |
| 1155 | { |
| 1156 | WLAN_GET_LINKMODE, |
| 1157 | IW_PRIV_TYPE_NONE, |
| 1158 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1159 | "get_linkmode"}, |
| 1160 | { |
| 1161 | WLAN_GET_RADIOMODE, |
| 1162 | IW_PRIV_TYPE_NONE, |
| 1163 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1164 | "get_radiomode"}, |
| 1165 | { |
| 1166 | WLAN_GET_DEBUGMODE, |
| 1167 | IW_PRIV_TYPE_NONE, |
| 1168 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1169 | "get_debugmode"}, |
| 1170 | { |
| 1171 | WLAN_SUBCMD_FWT_CLEANUP, |
| 1172 | IW_PRIV_TYPE_NONE, |
| 1173 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1174 | "fwt_cleanup"}, |
| 1175 | { |
| 1176 | WLAN_SUBCMD_FWT_TIME, |
| 1177 | IW_PRIV_TYPE_NONE, |
| 1178 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1179 | "fwt_time"}, |
| 1180 | { |
| 1181 | WLAN_SUBCMD_MESH_GET_TTL, |
| 1182 | IW_PRIV_TYPE_NONE, |
| 1183 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1184 | "mesh_get_ttl"}, |
| 1185 | { |
| 1186 | WLAN_SETNONE_GETTWELVE_CHAR, |
| 1187 | IW_PRIV_TYPE_NONE, |
| 1188 | IW_PRIV_TYPE_CHAR | 12, |
| 1189 | ""}, |
| 1190 | { |
| 1191 | WLAN_SUBCMD_GETRXANTENNA, |
| 1192 | IW_PRIV_TYPE_NONE, |
| 1193 | IW_PRIV_TYPE_CHAR | 12, |
| 1194 | "getrxant"}, |
| 1195 | { |
| 1196 | WLAN_SUBCMD_GETTXANTENNA, |
| 1197 | IW_PRIV_TYPE_NONE, |
| 1198 | IW_PRIV_TYPE_CHAR | 12, |
| 1199 | "gettxant"}, |
| 1200 | { |
| 1201 | WLAN_GET_TSF, |
| 1202 | IW_PRIV_TYPE_NONE, |
| 1203 | IW_PRIV_TYPE_CHAR | 12, |
| 1204 | "gettsf"}, |
| 1205 | { |
| 1206 | WLAN_SETNONE_GETNONE, |
| 1207 | IW_PRIV_TYPE_NONE, |
| 1208 | IW_PRIV_TYPE_NONE, |
| 1209 | ""}, |
| 1210 | { |
| 1211 | WLANDEAUTH, |
| 1212 | IW_PRIV_TYPE_NONE, |
| 1213 | IW_PRIV_TYPE_NONE, |
| 1214 | "deauth"}, |
| 1215 | { |
| 1216 | WLANADHOCSTOP, |
| 1217 | IW_PRIV_TYPE_NONE, |
| 1218 | IW_PRIV_TYPE_NONE, |
| 1219 | "adhocstop"}, |
| 1220 | { |
| 1221 | WLANRADIOON, |
| 1222 | IW_PRIV_TYPE_NONE, |
| 1223 | IW_PRIV_TYPE_NONE, |
| 1224 | "radioon"}, |
| 1225 | { |
| 1226 | WLANRADIOOFF, |
| 1227 | IW_PRIV_TYPE_NONE, |
| 1228 | IW_PRIV_TYPE_NONE, |
| 1229 | "radiooff"}, |
| 1230 | { |
| 1231 | WLANWLANIDLEON, |
| 1232 | IW_PRIV_TYPE_NONE, |
| 1233 | IW_PRIV_TYPE_NONE, |
| 1234 | "wlanidle-on"}, |
| 1235 | { |
| 1236 | WLANWLANIDLEOFF, |
| 1237 | IW_PRIV_TYPE_NONE, |
| 1238 | IW_PRIV_TYPE_NONE, |
| 1239 | "wlanidle-off"}, |
| 1240 | { |
| 1241 | WLAN_SUBCMD_FWT_RESET, |
| 1242 | IW_PRIV_TYPE_NONE, |
| 1243 | IW_PRIV_TYPE_NONE, |
| 1244 | "fwt_reset"}, |
| 1245 | { |
| 1246 | WLAN_SUBCMD_BT_RESET, |
| 1247 | IW_PRIV_TYPE_NONE, |
| 1248 | IW_PRIV_TYPE_NONE, |
| 1249 | "bt_reset"}, |
| 1250 | { |
| 1251 | WLAN_SET128CHAR_GET128CHAR, |
| 1252 | IW_PRIV_TYPE_CHAR | 128, |
| 1253 | IW_PRIV_TYPE_CHAR | 128, |
| 1254 | ""}, |
| 1255 | /* BT Management */ |
| 1256 | { |
| 1257 | WLAN_SUBCMD_BT_ADD, |
| 1258 | IW_PRIV_TYPE_CHAR | 128, |
| 1259 | IW_PRIV_TYPE_CHAR | 128, |
| 1260 | "bt_add"}, |
| 1261 | { |
| 1262 | WLAN_SUBCMD_BT_DEL, |
| 1263 | IW_PRIV_TYPE_CHAR | 128, |
| 1264 | IW_PRIV_TYPE_CHAR | 128, |
| 1265 | "bt_del"}, |
| 1266 | { |
| 1267 | WLAN_SUBCMD_BT_LIST, |
| 1268 | IW_PRIV_TYPE_CHAR | 128, |
| 1269 | IW_PRIV_TYPE_CHAR | 128, |
| 1270 | "bt_list"}, |
| 1271 | /* FWT Management */ |
| 1272 | { |
| 1273 | WLAN_SUBCMD_FWT_ADD, |
| 1274 | IW_PRIV_TYPE_CHAR | 128, |
| 1275 | IW_PRIV_TYPE_CHAR | 128, |
| 1276 | "fwt_add"}, |
| 1277 | { |
| 1278 | WLAN_SUBCMD_FWT_DEL, |
| 1279 | IW_PRIV_TYPE_CHAR | 128, |
| 1280 | IW_PRIV_TYPE_CHAR | 128, |
| 1281 | "fwt_del"}, |
| 1282 | { |
| 1283 | WLAN_SUBCMD_FWT_LOOKUP, |
| 1284 | IW_PRIV_TYPE_CHAR | 128, |
| 1285 | IW_PRIV_TYPE_CHAR | 128, |
| 1286 | "fwt_lookup"}, |
| 1287 | { |
| 1288 | WLAN_SUBCMD_FWT_LIST_NEIGHBOR, |
| 1289 | IW_PRIV_TYPE_CHAR | 128, |
| 1290 | IW_PRIV_TYPE_CHAR | 128, |
| 1291 | "fwt_list_neigh"}, |
| 1292 | { |
| 1293 | WLAN_SUBCMD_FWT_LIST, |
| 1294 | IW_PRIV_TYPE_CHAR | 128, |
| 1295 | IW_PRIV_TYPE_CHAR | 128, |
| 1296 | "fwt_list"}, |
| 1297 | { |
| 1298 | WLAN_SUBCMD_FWT_LIST_ROUTE, |
| 1299 | IW_PRIV_TYPE_CHAR | 128, |
| 1300 | IW_PRIV_TYPE_CHAR | 128, |
| 1301 | "fwt_list_route"}, |
| 1302 | { |
| 1303 | WLANSCAN_MODE, |
| 1304 | IW_PRIV_TYPE_CHAR | 128, |
| 1305 | IW_PRIV_TYPE_CHAR | 128, |
| 1306 | "scanmode"}, |
| 1307 | { |
| 1308 | WLAN_GET_ADHOC_STATUS, |
| 1309 | IW_PRIV_TYPE_CHAR | 128, |
| 1310 | IW_PRIV_TYPE_CHAR | 128, |
| 1311 | "getadhocstatus"}, |
| 1312 | { |
| 1313 | WLAN_SETNONE_GETWORDCHAR, |
| 1314 | IW_PRIV_TYPE_NONE, |
| 1315 | IW_PRIV_TYPE_CHAR | 128, |
| 1316 | ""}, |
| 1317 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1318 | WLANGETLOG, |
| 1319 | IW_PRIV_TYPE_NONE, |
| 1320 | IW_PRIV_TYPE_CHAR | GETLOG_BUFSIZE, |
| 1321 | "getlog"}, |
| 1322 | { |
| 1323 | WLAN_SET_GET_SIXTEEN_INT, |
| 1324 | IW_PRIV_TYPE_INT | 16, |
| 1325 | IW_PRIV_TYPE_INT | 16, |
| 1326 | ""}, |
| 1327 | { |
| 1328 | WLAN_TPCCFG, |
| 1329 | IW_PRIV_TYPE_INT | 16, |
| 1330 | IW_PRIV_TYPE_INT | 16, |
| 1331 | "tpccfg"}, |
| 1332 | { |
| 1333 | WLAN_POWERCFG, |
| 1334 | IW_PRIV_TYPE_INT | 16, |
| 1335 | IW_PRIV_TYPE_INT | 16, |
| 1336 | "powercfg"}, |
| 1337 | { |
| 1338 | WLAN_AUTO_FREQ_SET, |
| 1339 | IW_PRIV_TYPE_INT | 16, |
| 1340 | IW_PRIV_TYPE_INT | 16, |
| 1341 | "setafc"}, |
| 1342 | { |
| 1343 | WLAN_AUTO_FREQ_GET, |
| 1344 | IW_PRIV_TYPE_INT | 16, |
| 1345 | IW_PRIV_TYPE_INT | 16, |
| 1346 | "getafc"}, |
| 1347 | { |
| 1348 | WLAN_SCANPROBES, |
| 1349 | IW_PRIV_TYPE_INT | 16, |
| 1350 | IW_PRIV_TYPE_INT | 16, |
| 1351 | "scanprobes"}, |
| 1352 | { |
| 1353 | WLAN_LED_GPIO_CTRL, |
| 1354 | IW_PRIV_TYPE_INT | 16, |
| 1355 | IW_PRIV_TYPE_INT | 16, |
| 1356 | "ledgpio"}, |
| 1357 | { |
| 1358 | WLAN_ADAPT_RATESET, |
| 1359 | IW_PRIV_TYPE_INT | 16, |
| 1360 | IW_PRIV_TYPE_INT | 16, |
| 1361 | "rateadapt"}, |
| 1362 | { |
| 1363 | WLAN_INACTIVITY_TIMEOUT, |
| 1364 | IW_PRIV_TYPE_INT | 16, |
| 1365 | IW_PRIV_TYPE_INT | 16, |
| 1366 | "inactivityto"}, |
| 1367 | { |
| 1368 | WLANSNR, |
| 1369 | IW_PRIV_TYPE_INT | 16, |
| 1370 | IW_PRIV_TYPE_INT | 16, |
| 1371 | "getSNR"}, |
| 1372 | { |
| 1373 | WLAN_GET_RATE, |
| 1374 | IW_PRIV_TYPE_INT | 16, |
| 1375 | IW_PRIV_TYPE_INT | 16, |
| 1376 | "getrate"}, |
| 1377 | { |
| 1378 | WLAN_GET_RXINFO, |
| 1379 | IW_PRIV_TYPE_INT | 16, |
| 1380 | IW_PRIV_TYPE_INT | 16, |
| 1381 | "getrxinfo"}, |
| 1382 | }; |
| 1383 | |
| 1384 | static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev) |
| 1385 | { |
| 1386 | enum { |
| 1387 | POOR = 30, |
| 1388 | FAIR = 60, |
| 1389 | GOOD = 80, |
| 1390 | VERY_GOOD = 90, |
| 1391 | EXCELLENT = 95, |
| 1392 | PERFECT = 100 |
| 1393 | }; |
| 1394 | wlan_private *priv = dev->priv; |
| 1395 | wlan_adapter *adapter = priv->adapter; |
| 1396 | u32 rssi_qual; |
| 1397 | u32 tx_qual; |
| 1398 | u32 quality = 0; |
| 1399 | int stats_valid = 0; |
| 1400 | u8 rssi; |
| 1401 | u32 tx_retries; |
| 1402 | |
| 1403 | ENTER(); |
| 1404 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 1405 | priv->wstats.status = adapter->mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1406 | |
| 1407 | /* If we're not associated, all quality values are meaningless */ |
| 1408 | if (adapter->connect_status != libertas_connected) |
| 1409 | goto out; |
| 1410 | |
| 1411 | /* Quality by RSSI */ |
| 1412 | priv->wstats.qual.level = |
| 1413 | CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG], |
| 1414 | adapter->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 1415 | |
| 1416 | if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) { |
| 1417 | priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE; |
| 1418 | } else { |
| 1419 | priv->wstats.qual.noise = |
| 1420 | CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]); |
| 1421 | } |
| 1422 | |
| 1423 | lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level); |
| 1424 | lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise); |
| 1425 | |
| 1426 | rssi = priv->wstats.qual.level - priv->wstats.qual.noise; |
| 1427 | if (rssi < 15) |
| 1428 | rssi_qual = rssi * POOR / 10; |
| 1429 | else if (rssi < 20) |
| 1430 | rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR; |
| 1431 | else if (rssi < 30) |
| 1432 | rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR; |
| 1433 | else if (rssi < 40) |
| 1434 | rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) / |
| 1435 | 10 + GOOD; |
| 1436 | else |
| 1437 | rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) / |
| 1438 | 10 + VERY_GOOD; |
| 1439 | quality = rssi_qual; |
| 1440 | |
| 1441 | /* Quality by TX errors */ |
| 1442 | priv->wstats.discard.retries = priv->stats.tx_errors; |
| 1443 | |
| 1444 | tx_retries = adapter->logmsg.retry; |
| 1445 | |
| 1446 | if (tx_retries > 75) |
| 1447 | tx_qual = (90 - tx_retries) * POOR / 15; |
| 1448 | else if (tx_retries > 70) |
| 1449 | tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR; |
| 1450 | else if (tx_retries > 65) |
| 1451 | tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR; |
| 1452 | else if (tx_retries > 50) |
| 1453 | tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) / |
| 1454 | 15 + GOOD; |
| 1455 | else |
| 1456 | tx_qual = (50 - tx_retries) * |
| 1457 | (PERFECT - VERY_GOOD) / 50 + VERY_GOOD; |
| 1458 | quality = min(quality, tx_qual); |
| 1459 | |
| 1460 | priv->wstats.discard.code = adapter->logmsg.wepundecryptable; |
| 1461 | priv->wstats.discard.fragment = adapter->logmsg.fcserror; |
| 1462 | priv->wstats.discard.retries = tx_retries; |
| 1463 | priv->wstats.discard.misc = adapter->logmsg.ackfailure; |
| 1464 | |
| 1465 | /* Calculate quality */ |
| 1466 | priv->wstats.qual.qual = max(quality, (u32)100); |
| 1467 | priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
| 1468 | stats_valid = 1; |
| 1469 | |
| 1470 | /* update stats asynchronously for future calls */ |
| 1471 | libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0, |
| 1472 | 0, 0, NULL); |
| 1473 | libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0, |
| 1474 | 0, 0, NULL); |
| 1475 | out: |
| 1476 | if (!stats_valid) { |
| 1477 | priv->wstats.miss.beacon = 0; |
| 1478 | priv->wstats.discard.retries = 0; |
| 1479 | priv->wstats.qual.qual = 0; |
| 1480 | priv->wstats.qual.level = 0; |
| 1481 | priv->wstats.qual.noise = 0; |
| 1482 | priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED; |
| 1483 | priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID | |
| 1484 | IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID; |
| 1485 | } |
| 1486 | |
| 1487 | LEAVE (); |
| 1488 | return &priv->wstats; |
| 1489 | |
| 1490 | |
| 1491 | } |
| 1492 | |
| 1493 | static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info, |
| 1494 | struct iw_freq *fwrq, char *extra) |
| 1495 | { |
| 1496 | int ret = 0; |
| 1497 | wlan_private *priv = dev->priv; |
| 1498 | wlan_adapter *adapter = priv->adapter; |
| 1499 | int rc = -EINPROGRESS; /* Call commit handler */ |
| 1500 | struct chan_freq_power *cfp; |
| 1501 | |
| 1502 | ENTER(); |
| 1503 | |
| 1504 | /* |
| 1505 | * If setting by frequency, convert to a channel |
| 1506 | */ |
| 1507 | if (fwrq->e == 1) { |
| 1508 | |
| 1509 | long f = fwrq->m / 100000; |
| 1510 | int c = 0; |
| 1511 | |
| 1512 | cfp = find_cfp_by_band_and_freq(adapter, 0, f); |
| 1513 | if (!cfp) { |
| 1514 | lbs_pr_debug(1, "Invalid freq=%ld\n", f); |
| 1515 | return -EINVAL; |
| 1516 | } |
| 1517 | |
| 1518 | c = (int)cfp->channel; |
| 1519 | |
| 1520 | if (c < 0) |
| 1521 | return -EINVAL; |
| 1522 | |
| 1523 | fwrq->e = 0; |
| 1524 | fwrq->m = c; |
| 1525 | } |
| 1526 | |
| 1527 | /* |
| 1528 | * Setting by channel number |
| 1529 | */ |
| 1530 | if (fwrq->m > 1000 || fwrq->e > 0) { |
| 1531 | rc = -EOPNOTSUPP; |
| 1532 | } else { |
| 1533 | int channel = fwrq->m; |
| 1534 | |
| 1535 | cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel); |
| 1536 | if (!cfp) { |
| 1537 | rc = -EINVAL; |
| 1538 | } else { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 1539 | if (adapter->mode == IW_MODE_ADHOC) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1540 | rc = changeadhocchannel(priv, channel); |
| 1541 | /* If station is WEP enabled, send the |
| 1542 | * command to set WEP in firmware |
| 1543 | */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1544 | if (adapter->secinfo.wep_enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1545 | lbs_pr_debug(1, "set_freq: WEP enabled\n"); |
| 1546 | ret = libertas_prepare_and_send_command(priv, |
| 1547 | cmd_802_11_set_wep, |
| 1548 | cmd_act_add, |
| 1549 | cmd_option_waitforrsp, |
| 1550 | 0, |
| 1551 | NULL); |
| 1552 | |
| 1553 | if (ret) { |
| 1554 | LEAVE(); |
| 1555 | return ret; |
| 1556 | } |
| 1557 | |
| 1558 | adapter->currentpacketfilter |= |
| 1559 | cmd_act_mac_wep_enable; |
| 1560 | |
| 1561 | libertas_set_mac_packet_filter(priv); |
| 1562 | } |
| 1563 | } else { |
| 1564 | rc = -EOPNOTSUPP; |
| 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | LEAVE(); |
| 1570 | return rc; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * @brief use index to get the data rate |
| 1575 | * |
| 1576 | * @param index The index of data rate |
| 1577 | * @return data rate or 0 |
| 1578 | */ |
| 1579 | u32 libertas_index_to_data_rate(u8 index) |
| 1580 | { |
| 1581 | if (index >= sizeof(libertas_wlan_data_rates)) |
| 1582 | index = 0; |
| 1583 | |
| 1584 | return libertas_wlan_data_rates[index]; |
| 1585 | } |
| 1586 | |
| 1587 | /** |
| 1588 | * @brief use rate to get the index |
| 1589 | * |
| 1590 | * @param rate data rate |
| 1591 | * @return index or 0 |
| 1592 | */ |
| 1593 | u8 libertas_data_rate_to_index(u32 rate) |
| 1594 | { |
| 1595 | u8 *ptr; |
| 1596 | |
| 1597 | if (rate) |
| 1598 | if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate, |
| 1599 | sizeof(libertas_wlan_data_rates)))) |
| 1600 | return (ptr - libertas_wlan_data_rates); |
| 1601 | |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info, |
| 1606 | struct iw_param *vwrq, char *extra) |
| 1607 | { |
| 1608 | wlan_private *priv = dev->priv; |
| 1609 | wlan_adapter *adapter = priv->adapter; |
| 1610 | u32 data_rate; |
| 1611 | u16 action; |
| 1612 | int ret = 0; |
| 1613 | u8 rates[WLAN_SUPPORTED_RATES]; |
| 1614 | u8 *rate; |
| 1615 | |
| 1616 | ENTER(); |
| 1617 | |
| 1618 | lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value); |
| 1619 | |
| 1620 | if (vwrq->value == -1) { |
| 1621 | action = cmd_act_set_tx_auto; // Auto |
| 1622 | adapter->is_datarate_auto = 1; |
| 1623 | adapter->datarate = 0; |
| 1624 | } else { |
| 1625 | if (vwrq->value % 100000) { |
| 1626 | return -EINVAL; |
| 1627 | } |
| 1628 | |
| 1629 | data_rate = vwrq->value / 500000; |
| 1630 | |
| 1631 | memset(rates, 0, sizeof(rates)); |
| 1632 | get_active_data_rates(adapter, rates); |
| 1633 | rate = rates; |
| 1634 | while (*rate) { |
| 1635 | lbs_pr_debug(1, "Rate=0x%X Wanted=0x%X\n", *rate, |
| 1636 | data_rate); |
| 1637 | if ((*rate & 0x7f) == (data_rate & 0x7f)) |
| 1638 | break; |
| 1639 | rate++; |
| 1640 | } |
| 1641 | if (!*rate) { |
| 1642 | lbs_pr_alert( "The fixed data rate 0x%X is out " |
| 1643 | "of range.\n", data_rate); |
| 1644 | return -EINVAL; |
| 1645 | } |
| 1646 | |
| 1647 | adapter->datarate = data_rate; |
| 1648 | action = cmd_act_set_tx_fix_rate; |
| 1649 | adapter->is_datarate_auto = 0; |
| 1650 | } |
| 1651 | |
| 1652 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate, |
| 1653 | action, cmd_option_waitforrsp, 0, NULL); |
| 1654 | |
| 1655 | LEAVE(); |
| 1656 | return ret; |
| 1657 | } |
| 1658 | |
| 1659 | static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info, |
| 1660 | struct iw_param *vwrq, char *extra) |
| 1661 | { |
| 1662 | wlan_private *priv = dev->priv; |
| 1663 | wlan_adapter *adapter = priv->adapter; |
| 1664 | |
| 1665 | ENTER(); |
| 1666 | |
| 1667 | if (adapter->is_datarate_auto) { |
| 1668 | vwrq->fixed = 0; |
| 1669 | } else { |
| 1670 | vwrq->fixed = 1; |
| 1671 | } |
| 1672 | |
| 1673 | vwrq->value = adapter->datarate * 500000; |
| 1674 | |
| 1675 | LEAVE(); |
| 1676 | return 0; |
| 1677 | } |
| 1678 | |
| 1679 | static int wlan_set_mode(struct net_device *dev, |
| 1680 | struct iw_request_info *info, u32 * uwrq, char *extra) |
| 1681 | { |
| 1682 | int ret = 0; |
| 1683 | wlan_private *priv = dev->priv; |
| 1684 | wlan_adapter *adapter = priv->adapter; |
| 1685 | struct assoc_request * assoc_req; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1686 | |
| 1687 | ENTER(); |
| 1688 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 1689 | if ( (*uwrq != IW_MODE_ADHOC) |
| 1690 | && (*uwrq != IW_MODE_INFRA) |
| 1691 | && (*uwrq != IW_MODE_AUTO)) { |
| 1692 | lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq); |
| 1693 | ret = -EINVAL; |
| 1694 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1695 | } |
| 1696 | |
| 1697 | mutex_lock(&adapter->lock); |
| 1698 | assoc_req = wlan_get_association_request(adapter); |
| 1699 | if (!assoc_req) { |
| 1700 | ret = -ENOMEM; |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 1701 | wlan_cancel_association_work(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1702 | } else { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 1703 | assoc_req->mode = *uwrq; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1704 | set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); |
| 1705 | wlan_postpone_association_work(priv); |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 1706 | lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1707 | } |
| 1708 | mutex_unlock(&adapter->lock); |
| 1709 | |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 1710 | out: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1711 | LEAVE(); |
| 1712 | return ret; |
| 1713 | } |
| 1714 | |
| 1715 | |
| 1716 | /** |
| 1717 | * @brief Get Encryption key |
| 1718 | * |
| 1719 | * @param dev A pointer to net_device structure |
| 1720 | * @param info A pointer to iw_request_info structure |
| 1721 | * @param vwrq A pointer to iw_param structure |
| 1722 | * @param extra A pointer to extra data buf |
| 1723 | * @return 0 --success, otherwise fail |
| 1724 | */ |
| 1725 | static int wlan_get_encode(struct net_device *dev, |
| 1726 | struct iw_request_info *info, |
| 1727 | struct iw_point *dwrq, u8 * extra) |
| 1728 | { |
| 1729 | wlan_private *priv = dev->priv; |
| 1730 | wlan_adapter *adapter = priv->adapter; |
| 1731 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 1732 | |
| 1733 | ENTER(); |
| 1734 | |
| 1735 | lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n", |
| 1736 | dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx); |
| 1737 | |
| 1738 | dwrq->flags = 0; |
| 1739 | |
| 1740 | /* Authentication method */ |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1741 | switch (adapter->secinfo.auth_mode) { |
| 1742 | case IW_AUTH_ALG_OPEN_SYSTEM: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1743 | dwrq->flags = IW_ENCODE_OPEN; |
| 1744 | break; |
| 1745 | |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1746 | case IW_AUTH_ALG_SHARED_KEY: |
| 1747 | case IW_AUTH_ALG_LEAP: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1748 | dwrq->flags = IW_ENCODE_RESTRICTED; |
| 1749 | break; |
| 1750 | default: |
| 1751 | dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN; |
| 1752 | break; |
| 1753 | } |
| 1754 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1755 | if ( adapter->secinfo.wep_enabled |
| 1756 | || adapter->secinfo.WPAenabled |
| 1757 | || adapter->secinfo.WPA2enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1758 | dwrq->flags &= ~IW_ENCODE_DISABLED; |
| 1759 | } else { |
| 1760 | dwrq->flags |= IW_ENCODE_DISABLED; |
| 1761 | } |
| 1762 | |
| 1763 | memset(extra, 0, 16); |
| 1764 | |
| 1765 | mutex_lock(&adapter->lock); |
| 1766 | |
| 1767 | /* Default to returning current transmit key */ |
| 1768 | if (index < 0) |
| 1769 | index = adapter->wep_tx_keyidx; |
| 1770 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1771 | if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1772 | memcpy(extra, adapter->wep_keys[index].key, |
| 1773 | adapter->wep_keys[index].len); |
| 1774 | dwrq->length = adapter->wep_keys[index].len; |
| 1775 | |
| 1776 | dwrq->flags |= (index + 1); |
| 1777 | /* Return WEP enabled */ |
| 1778 | dwrq->flags &= ~IW_ENCODE_DISABLED; |
| 1779 | } else if ((adapter->secinfo.WPAenabled) |
| 1780 | || (adapter->secinfo.WPA2enabled)) { |
| 1781 | /* return WPA enabled */ |
| 1782 | dwrq->flags &= ~IW_ENCODE_DISABLED; |
| 1783 | } else { |
| 1784 | dwrq->flags |= IW_ENCODE_DISABLED; |
| 1785 | } |
| 1786 | |
| 1787 | mutex_unlock(&adapter->lock); |
| 1788 | |
| 1789 | dwrq->flags |= IW_ENCODE_NOKEY; |
| 1790 | |
| 1791 | lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n", |
| 1792 | extra[0], extra[1], extra[2], |
| 1793 | extra[3], extra[4], extra[5], dwrq->length); |
| 1794 | |
| 1795 | lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags); |
| 1796 | |
| 1797 | LEAVE(); |
| 1798 | return 0; |
| 1799 | } |
| 1800 | |
| 1801 | /** |
| 1802 | * @brief Set Encryption key (internal) |
| 1803 | * |
| 1804 | * @param priv A pointer to private card structure |
| 1805 | * @param key_material A pointer to key material |
| 1806 | * @param key_length length of key material |
| 1807 | * @param index key index to set |
| 1808 | * @param set_tx_key Force set TX key (1 = yes, 0 = no) |
| 1809 | * @return 0 --success, otherwise fail |
| 1810 | */ |
| 1811 | static int wlan_set_wep_key(struct assoc_request *assoc_req, |
| 1812 | const char *key_material, |
| 1813 | u16 key_length, |
| 1814 | u16 index, |
| 1815 | int set_tx_key) |
| 1816 | { |
| 1817 | struct WLAN_802_11_KEY *pkey; |
| 1818 | |
| 1819 | ENTER(); |
| 1820 | |
| 1821 | /* Paranoid validation of key index */ |
| 1822 | if (index > 3) { |
| 1823 | LEAVE(); |
| 1824 | return -EINVAL; |
| 1825 | } |
| 1826 | |
| 1827 | /* validate max key length */ |
| 1828 | if (key_length > KEY_LEN_WEP_104) { |
| 1829 | LEAVE(); |
| 1830 | return -EINVAL; |
| 1831 | } |
| 1832 | |
| 1833 | pkey = &assoc_req->wep_keys[index]; |
| 1834 | |
| 1835 | if (key_length > 0) { |
| 1836 | memset(pkey, 0, sizeof(struct WLAN_802_11_KEY)); |
| 1837 | pkey->type = KEY_TYPE_ID_WEP; |
| 1838 | |
| 1839 | /* Standardize the key length */ |
| 1840 | pkey->len = (key_length > KEY_LEN_WEP_40) ? |
| 1841 | KEY_LEN_WEP_104 : KEY_LEN_WEP_40; |
| 1842 | memcpy(pkey->key, key_material, key_length); |
| 1843 | } |
| 1844 | |
| 1845 | if (set_tx_key) { |
| 1846 | /* Ensure the chosen key is valid */ |
| 1847 | if (!pkey->len) { |
| 1848 | lbs_pr_debug(1, "key not set, so cannot enable it\n"); |
| 1849 | LEAVE(); |
| 1850 | return -EINVAL; |
| 1851 | } |
| 1852 | assoc_req->wep_tx_keyidx = index; |
| 1853 | } |
| 1854 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1855 | assoc_req->secinfo.wep_enabled = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1856 | |
| 1857 | LEAVE(); |
| 1858 | return 0; |
| 1859 | } |
| 1860 | |
| 1861 | static int validate_key_index(u16 def_index, u16 raw_index, |
| 1862 | u16 *out_index, u16 *is_default) |
| 1863 | { |
| 1864 | if (!out_index || !is_default) |
| 1865 | return -EINVAL; |
| 1866 | |
| 1867 | /* Verify index if present, otherwise use default TX key index */ |
| 1868 | if (raw_index > 0) { |
| 1869 | if (raw_index > 4) |
| 1870 | return -EINVAL; |
| 1871 | *out_index = raw_index - 1; |
| 1872 | } else { |
| 1873 | *out_index = def_index; |
| 1874 | *is_default = 1; |
| 1875 | } |
| 1876 | return 0; |
| 1877 | } |
| 1878 | |
| 1879 | static void disable_wep(struct assoc_request *assoc_req) |
| 1880 | { |
| 1881 | int i; |
| 1882 | |
| 1883 | /* Set Open System auth mode */ |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1884 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1885 | |
| 1886 | /* Clear WEP keys and mark WEP as disabled */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1887 | assoc_req->secinfo.wep_enabled = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1888 | for (i = 0; i < 4; i++) |
| 1889 | assoc_req->wep_keys[i].len = 0; |
| 1890 | |
| 1891 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 1892 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 1893 | } |
| 1894 | |
| 1895 | /** |
| 1896 | * @brief Set Encryption key |
| 1897 | * |
| 1898 | * @param dev A pointer to net_device structure |
| 1899 | * @param info A pointer to iw_request_info structure |
| 1900 | * @param vwrq A pointer to iw_param structure |
| 1901 | * @param extra A pointer to extra data buf |
| 1902 | * @return 0 --success, otherwise fail |
| 1903 | */ |
| 1904 | static int wlan_set_encode(struct net_device *dev, |
| 1905 | struct iw_request_info *info, |
| 1906 | struct iw_point *dwrq, char *extra) |
| 1907 | { |
| 1908 | int ret = 0; |
| 1909 | wlan_private *priv = dev->priv; |
| 1910 | wlan_adapter *adapter = priv->adapter; |
| 1911 | struct assoc_request * assoc_req; |
| 1912 | u16 is_default = 0, index = 0, set_tx_key = 0; |
| 1913 | |
| 1914 | ENTER(); |
| 1915 | |
| 1916 | mutex_lock(&adapter->lock); |
| 1917 | assoc_req = wlan_get_association_request(adapter); |
| 1918 | if (!assoc_req) { |
| 1919 | ret = -ENOMEM; |
| 1920 | goto out; |
| 1921 | } |
| 1922 | |
| 1923 | if (dwrq->flags & IW_ENCODE_DISABLED) { |
| 1924 | disable_wep (assoc_req); |
| 1925 | goto out; |
| 1926 | } |
| 1927 | |
| 1928 | ret = validate_key_index(assoc_req->wep_tx_keyidx, |
| 1929 | (dwrq->flags & IW_ENCODE_INDEX), |
| 1930 | &index, &is_default); |
| 1931 | if (ret) { |
| 1932 | ret = -EINVAL; |
| 1933 | goto out; |
| 1934 | } |
| 1935 | |
| 1936 | /* If WEP isn't enabled, or if there is no key data but a valid |
| 1937 | * index, set the TX key. |
| 1938 | */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 1939 | if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1940 | set_tx_key = 1; |
| 1941 | |
| 1942 | ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key); |
| 1943 | if (ret) |
| 1944 | goto out; |
| 1945 | |
| 1946 | if (dwrq->length) |
| 1947 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 1948 | if (set_tx_key) |
| 1949 | set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags); |
| 1950 | |
| 1951 | if (dwrq->flags & IW_ENCODE_RESTRICTED) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1952 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1953 | } else if (dwrq->flags & IW_ENCODE_OPEN) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 1954 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | out: |
| 1958 | if (ret == 0) { |
| 1959 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 1960 | wlan_postpone_association_work(priv); |
| 1961 | } else { |
| 1962 | wlan_cancel_association_work(priv); |
| 1963 | } |
| 1964 | mutex_unlock(&adapter->lock); |
| 1965 | |
| 1966 | LEAVE(); |
| 1967 | return ret; |
| 1968 | } |
| 1969 | |
| 1970 | /** |
| 1971 | * @brief Get Extended Encryption key (WPA/802.1x and WEP) |
| 1972 | * |
| 1973 | * @param dev A pointer to net_device structure |
| 1974 | * @param info A pointer to iw_request_info structure |
| 1975 | * @param vwrq A pointer to iw_param structure |
| 1976 | * @param extra A pointer to extra data buf |
| 1977 | * @return 0 on success, otherwise failure |
| 1978 | */ |
| 1979 | static int wlan_get_encodeext(struct net_device *dev, |
| 1980 | struct iw_request_info *info, |
| 1981 | struct iw_point *dwrq, |
| 1982 | char *extra) |
| 1983 | { |
| 1984 | int ret = -EINVAL; |
| 1985 | wlan_private *priv = dev->priv; |
| 1986 | wlan_adapter *adapter = priv->adapter; |
| 1987 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 1988 | int index, max_key_len; |
| 1989 | |
| 1990 | ENTER(); |
| 1991 | |
| 1992 | max_key_len = dwrq->length - sizeof(*ext); |
| 1993 | if (max_key_len < 0) |
| 1994 | goto out; |
| 1995 | |
| 1996 | index = dwrq->flags & IW_ENCODE_INDEX; |
| 1997 | if (index) { |
| 1998 | if (index < 1 || index > 4) |
| 1999 | goto out; |
| 2000 | index--; |
| 2001 | } else { |
| 2002 | index = adapter->wep_tx_keyidx; |
| 2003 | } |
| 2004 | |
| 2005 | if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY && |
| 2006 | ext->alg != IW_ENCODE_ALG_WEP) { |
Dan Williams | 0dc5a29 | 2007-05-10 22:58:02 -0400 | [diff] [blame^] | 2007 | if (index != 0 || adapter->mode != IW_MODE_INFRA) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2008 | goto out; |
| 2009 | } |
| 2010 | |
| 2011 | dwrq->flags = index + 1; |
| 2012 | memset(ext, 0, sizeof(*ext)); |
| 2013 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2014 | if ( !adapter->secinfo.wep_enabled |
| 2015 | && !adapter->secinfo.WPAenabled |
| 2016 | && !adapter->secinfo.WPA2enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2017 | ext->alg = IW_ENCODE_ALG_NONE; |
| 2018 | ext->key_len = 0; |
| 2019 | dwrq->flags |= IW_ENCODE_DISABLED; |
| 2020 | } else { |
| 2021 | u8 *key = NULL; |
| 2022 | |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2023 | if ( adapter->secinfo.wep_enabled |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2024 | && !adapter->secinfo.WPAenabled |
| 2025 | && !adapter->secinfo.WPA2enabled) { |
| 2026 | ext->alg = IW_ENCODE_ALG_WEP; |
| 2027 | ext->key_len = adapter->wep_keys[index].len; |
| 2028 | key = &adapter->wep_keys[index].key[0]; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2029 | } else if ( !adapter->secinfo.wep_enabled |
| 2030 | && (adapter->secinfo.WPAenabled || |
| 2031 | adapter->secinfo.WPA2enabled)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2032 | /* WPA */ |
| 2033 | ext->alg = IW_ENCODE_ALG_TKIP; |
| 2034 | ext->key_len = 0; |
| 2035 | } else { |
| 2036 | goto out; |
| 2037 | } |
| 2038 | |
| 2039 | if (ext->key_len > max_key_len) { |
| 2040 | ret = -E2BIG; |
| 2041 | goto out; |
| 2042 | } |
| 2043 | |
| 2044 | if (ext->key_len) |
| 2045 | memcpy(ext->key, key, ext->key_len); |
| 2046 | else |
| 2047 | dwrq->flags |= IW_ENCODE_NOKEY; |
| 2048 | dwrq->flags |= IW_ENCODE_ENABLED; |
| 2049 | } |
| 2050 | ret = 0; |
| 2051 | |
| 2052 | out: |
| 2053 | LEAVE(); |
| 2054 | return ret; |
| 2055 | } |
| 2056 | |
| 2057 | /** |
| 2058 | * @brief Set Encryption key Extended (WPA/802.1x and WEP) |
| 2059 | * |
| 2060 | * @param dev A pointer to net_device structure |
| 2061 | * @param info A pointer to iw_request_info structure |
| 2062 | * @param vwrq A pointer to iw_param structure |
| 2063 | * @param extra A pointer to extra data buf |
| 2064 | * @return 0 --success, otherwise fail |
| 2065 | */ |
| 2066 | static int wlan_set_encodeext(struct net_device *dev, |
| 2067 | struct iw_request_info *info, |
| 2068 | struct iw_point *dwrq, |
| 2069 | char *extra) |
| 2070 | { |
| 2071 | int ret = 0; |
| 2072 | wlan_private *priv = dev->priv; |
| 2073 | wlan_adapter *adapter = priv->adapter; |
| 2074 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 2075 | int alg = ext->alg; |
| 2076 | struct assoc_request * assoc_req; |
| 2077 | |
| 2078 | ENTER(); |
| 2079 | |
| 2080 | mutex_lock(&adapter->lock); |
| 2081 | assoc_req = wlan_get_association_request(adapter); |
| 2082 | if (!assoc_req) { |
| 2083 | ret = -ENOMEM; |
| 2084 | goto out; |
| 2085 | } |
| 2086 | |
| 2087 | if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) { |
| 2088 | disable_wep (assoc_req); |
| 2089 | } else if (alg == IW_ENCODE_ALG_WEP) { |
| 2090 | u16 is_default = 0, index, set_tx_key = 0; |
| 2091 | |
| 2092 | ret = validate_key_index(assoc_req->wep_tx_keyidx, |
| 2093 | (dwrq->flags & IW_ENCODE_INDEX), |
| 2094 | &index, &is_default); |
| 2095 | if (ret) |
| 2096 | goto out; |
| 2097 | |
| 2098 | /* If WEP isn't enabled, or if there is no key data but a valid |
| 2099 | * index, or if the set-TX-key flag was passed, set the TX key. |
| 2100 | */ |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2101 | if ( !assoc_req->secinfo.wep_enabled |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2102 | || (dwrq->length == 0 && !is_default) |
| 2103 | || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) |
| 2104 | set_tx_key = 1; |
| 2105 | |
| 2106 | /* Copy key to driver */ |
| 2107 | ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index, |
| 2108 | set_tx_key); |
| 2109 | if (ret) |
| 2110 | goto out; |
| 2111 | |
| 2112 | if (dwrq->flags & IW_ENCODE_RESTRICTED) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2113 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2114 | } else if (dwrq->flags & IW_ENCODE_OPEN) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2115 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | /* Mark the various WEP bits as modified */ |
| 2119 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 2120 | if (dwrq->length) |
| 2121 | set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags); |
| 2122 | if (set_tx_key) |
| 2123 | set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags); |
| 2124 | |
| 2125 | } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) { |
| 2126 | struct WLAN_802_11_KEY * pkey; |
| 2127 | |
| 2128 | /* validate key length */ |
| 2129 | if (((alg == IW_ENCODE_ALG_TKIP) |
| 2130 | && (ext->key_len != KEY_LEN_WPA_TKIP)) |
| 2131 | || ((alg == IW_ENCODE_ALG_CCMP) |
| 2132 | && (ext->key_len != KEY_LEN_WPA_AES))) { |
| 2133 | lbs_pr_debug(1, "Invalid size %d for key of alg" |
| 2134 | "type %d.\n", |
| 2135 | ext->key_len, |
| 2136 | alg); |
| 2137 | ret = -EINVAL; |
| 2138 | goto out; |
| 2139 | } |
| 2140 | |
| 2141 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) |
| 2142 | pkey = &assoc_req->wpa_mcast_key; |
| 2143 | else |
| 2144 | pkey = &assoc_req->wpa_unicast_key; |
| 2145 | |
| 2146 | memset(pkey, 0, sizeof (struct WLAN_802_11_KEY)); |
| 2147 | memcpy(pkey->key, ext->key, ext->key_len); |
| 2148 | pkey->len = ext->key_len; |
| 2149 | pkey->flags = KEY_INFO_WPA_ENABLED; |
| 2150 | |
| 2151 | if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { |
| 2152 | pkey->flags |= KEY_INFO_WPA_MCAST; |
| 2153 | set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags); |
| 2154 | } else { |
| 2155 | pkey->flags |= KEY_INFO_WPA_UNICAST; |
| 2156 | set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags); |
| 2157 | } |
| 2158 | |
| 2159 | if (alg == IW_ENCODE_ALG_TKIP) |
| 2160 | pkey->type = KEY_TYPE_ID_TKIP; |
| 2161 | else if (alg == IW_ENCODE_ALG_CCMP) |
| 2162 | pkey->type = KEY_TYPE_ID_AES; |
| 2163 | |
| 2164 | /* If WPA isn't enabled yet, do that now */ |
| 2165 | if ( assoc_req->secinfo.WPAenabled == 0 |
| 2166 | && assoc_req->secinfo.WPA2enabled == 0) { |
| 2167 | assoc_req->secinfo.WPAenabled = 1; |
| 2168 | assoc_req->secinfo.WPA2enabled = 1; |
| 2169 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 2170 | } |
| 2171 | |
| 2172 | disable_wep (assoc_req); |
| 2173 | } |
| 2174 | |
| 2175 | out: |
| 2176 | if (ret == 0) { |
| 2177 | wlan_postpone_association_work(priv); |
| 2178 | } else { |
| 2179 | wlan_cancel_association_work(priv); |
| 2180 | } |
| 2181 | mutex_unlock(&adapter->lock); |
| 2182 | |
| 2183 | LEAVE(); |
| 2184 | return ret; |
| 2185 | } |
| 2186 | |
| 2187 | |
| 2188 | static int wlan_set_genie(struct net_device *dev, |
| 2189 | struct iw_request_info *info, |
| 2190 | struct iw_point *dwrq, |
| 2191 | char *extra) |
| 2192 | { |
| 2193 | wlan_private *priv = dev->priv; |
| 2194 | wlan_adapter *adapter = priv->adapter; |
| 2195 | int ret = 0; |
| 2196 | struct assoc_request * assoc_req; |
| 2197 | |
| 2198 | ENTER(); |
| 2199 | |
| 2200 | mutex_lock(&adapter->lock); |
| 2201 | assoc_req = wlan_get_association_request(adapter); |
| 2202 | if (!assoc_req) { |
| 2203 | ret = -ENOMEM; |
| 2204 | goto out; |
| 2205 | } |
| 2206 | |
| 2207 | if (dwrq->length > MAX_WPA_IE_LEN || |
| 2208 | (dwrq->length && extra == NULL)) { |
| 2209 | ret = -EINVAL; |
| 2210 | goto out; |
| 2211 | } |
| 2212 | |
| 2213 | if (dwrq->length) { |
| 2214 | memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length); |
| 2215 | assoc_req->wpa_ie_len = dwrq->length; |
| 2216 | } else { |
| 2217 | memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie)); |
| 2218 | assoc_req->wpa_ie_len = 0; |
| 2219 | } |
| 2220 | |
| 2221 | out: |
| 2222 | if (ret == 0) { |
| 2223 | set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags); |
| 2224 | wlan_postpone_association_work(priv); |
| 2225 | } else { |
| 2226 | wlan_cancel_association_work(priv); |
| 2227 | } |
| 2228 | mutex_unlock(&adapter->lock); |
| 2229 | |
| 2230 | LEAVE(); |
| 2231 | return ret; |
| 2232 | } |
| 2233 | |
| 2234 | static int wlan_get_genie(struct net_device *dev, |
| 2235 | struct iw_request_info *info, |
| 2236 | struct iw_point *dwrq, |
| 2237 | char *extra) |
| 2238 | { |
| 2239 | wlan_private *priv = dev->priv; |
| 2240 | wlan_adapter *adapter = priv->adapter; |
| 2241 | |
| 2242 | ENTER(); |
| 2243 | |
| 2244 | if (adapter->wpa_ie_len == 0) { |
| 2245 | dwrq->length = 0; |
| 2246 | LEAVE(); |
| 2247 | return 0; |
| 2248 | } |
| 2249 | |
| 2250 | if (dwrq->length < adapter->wpa_ie_len) { |
| 2251 | LEAVE(); |
| 2252 | return -E2BIG; |
| 2253 | } |
| 2254 | |
| 2255 | dwrq->length = adapter->wpa_ie_len; |
| 2256 | memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len); |
| 2257 | |
| 2258 | LEAVE(); |
| 2259 | return 0; |
| 2260 | } |
| 2261 | |
| 2262 | |
| 2263 | static int wlan_set_auth(struct net_device *dev, |
| 2264 | struct iw_request_info *info, |
| 2265 | struct iw_param *dwrq, |
| 2266 | char *extra) |
| 2267 | { |
| 2268 | wlan_private *priv = dev->priv; |
| 2269 | wlan_adapter *adapter = priv->adapter; |
| 2270 | struct assoc_request * assoc_req; |
| 2271 | int ret = 0; |
| 2272 | int updated = 0; |
| 2273 | |
| 2274 | ENTER(); |
| 2275 | |
| 2276 | mutex_lock(&adapter->lock); |
| 2277 | assoc_req = wlan_get_association_request(adapter); |
| 2278 | if (!assoc_req) { |
| 2279 | ret = -ENOMEM; |
| 2280 | goto out; |
| 2281 | } |
| 2282 | |
| 2283 | switch (dwrq->flags & IW_AUTH_INDEX) { |
| 2284 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 2285 | case IW_AUTH_CIPHER_PAIRWISE: |
| 2286 | case IW_AUTH_CIPHER_GROUP: |
| 2287 | case IW_AUTH_KEY_MGMT: |
| 2288 | /* |
| 2289 | * libertas does not use these parameters |
| 2290 | */ |
| 2291 | break; |
| 2292 | |
| 2293 | case IW_AUTH_WPA_VERSION: |
| 2294 | if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) { |
| 2295 | assoc_req->secinfo.WPAenabled = 0; |
| 2296 | assoc_req->secinfo.WPA2enabled = 0; |
| 2297 | } |
| 2298 | if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) { |
| 2299 | assoc_req->secinfo.WPAenabled = 1; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2300 | assoc_req->secinfo.wep_enabled = 0; |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2301 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2302 | } |
| 2303 | if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) { |
| 2304 | assoc_req->secinfo.WPA2enabled = 1; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2305 | assoc_req->secinfo.wep_enabled = 0; |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2306 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2307 | } |
| 2308 | updated = 1; |
| 2309 | break; |
| 2310 | |
| 2311 | case IW_AUTH_DROP_UNENCRYPTED: |
| 2312 | if (dwrq->value) { |
| 2313 | adapter->currentpacketfilter |= |
| 2314 | cmd_act_mac_strict_protection_enable; |
| 2315 | } else { |
| 2316 | adapter->currentpacketfilter &= |
| 2317 | ~cmd_act_mac_strict_protection_enable; |
| 2318 | } |
| 2319 | updated = 1; |
| 2320 | break; |
| 2321 | |
| 2322 | case IW_AUTH_80211_AUTH_ALG: |
| 2323 | if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2324 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2325 | } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2326 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2327 | } else if (dwrq->value & IW_AUTH_ALG_LEAP) { |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2328 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2329 | } else { |
| 2330 | ret = -EINVAL; |
| 2331 | } |
| 2332 | updated = 1; |
| 2333 | break; |
| 2334 | |
| 2335 | case IW_AUTH_WPA_ENABLED: |
| 2336 | if (dwrq->value) { |
| 2337 | if (!assoc_req->secinfo.WPAenabled && |
| 2338 | !assoc_req->secinfo.WPA2enabled) { |
| 2339 | assoc_req->secinfo.WPAenabled = 1; |
| 2340 | assoc_req->secinfo.WPA2enabled = 1; |
Dan Williams | 889c05b | 2007-05-10 22:57:23 -0400 | [diff] [blame] | 2341 | assoc_req->secinfo.wep_enabled = 0; |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2342 | assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2343 | } |
| 2344 | } else { |
| 2345 | assoc_req->secinfo.WPAenabled = 0; |
| 2346 | assoc_req->secinfo.WPA2enabled = 0; |
| 2347 | } |
| 2348 | updated = 1; |
| 2349 | break; |
| 2350 | |
| 2351 | default: |
| 2352 | ret = -EOPNOTSUPP; |
| 2353 | break; |
| 2354 | } |
| 2355 | |
| 2356 | out: |
| 2357 | if (ret == 0) { |
| 2358 | if (updated) |
| 2359 | set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags); |
| 2360 | wlan_postpone_association_work(priv); |
| 2361 | } else if (ret != -EOPNOTSUPP) { |
| 2362 | wlan_cancel_association_work(priv); |
| 2363 | } |
| 2364 | mutex_unlock(&adapter->lock); |
| 2365 | |
| 2366 | LEAVE(); |
| 2367 | return ret; |
| 2368 | } |
| 2369 | |
| 2370 | static int wlan_get_auth(struct net_device *dev, |
| 2371 | struct iw_request_info *info, |
| 2372 | struct iw_param *dwrq, |
| 2373 | char *extra) |
| 2374 | { |
| 2375 | wlan_private *priv = dev->priv; |
| 2376 | wlan_adapter *adapter = priv->adapter; |
| 2377 | |
| 2378 | ENTER(); |
| 2379 | |
| 2380 | switch (dwrq->flags & IW_AUTH_INDEX) { |
| 2381 | case IW_AUTH_WPA_VERSION: |
| 2382 | dwrq->value = 0; |
| 2383 | if (adapter->secinfo.WPAenabled) |
| 2384 | dwrq->value |= IW_AUTH_WPA_VERSION_WPA; |
| 2385 | if (adapter->secinfo.WPA2enabled) |
| 2386 | dwrq->value |= IW_AUTH_WPA_VERSION_WPA2; |
| 2387 | if (!dwrq->value) |
| 2388 | dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED; |
| 2389 | break; |
| 2390 | |
| 2391 | case IW_AUTH_DROP_UNENCRYPTED: |
| 2392 | dwrq->value = 0; |
| 2393 | if (adapter->currentpacketfilter & |
| 2394 | cmd_act_mac_strict_protection_enable) |
| 2395 | dwrq->value = 1; |
| 2396 | break; |
| 2397 | |
| 2398 | case IW_AUTH_80211_AUTH_ALG: |
Dan Williams | 6affe78 | 2007-05-10 22:56:42 -0400 | [diff] [blame] | 2399 | dwrq->value = adapter->secinfo.auth_mode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 2400 | break; |
| 2401 | |
| 2402 | case IW_AUTH_WPA_ENABLED: |
| 2403 | if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled) |
| 2404 | dwrq->value = 1; |
| 2405 | break; |
| 2406 | |
| 2407 | default: |
| 2408 | LEAVE(); |
| 2409 | return -EOPNOTSUPP; |
| 2410 | } |
| 2411 | |
| 2412 | LEAVE(); |
| 2413 | return 0; |
| 2414 | } |
| 2415 | |
| 2416 | |
| 2417 | static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info, |
| 2418 | struct iw_param *vwrq, char *extra) |
| 2419 | { |
| 2420 | int ret = 0; |
| 2421 | wlan_private *priv = dev->priv; |
| 2422 | wlan_adapter *adapter = priv->adapter; |
| 2423 | |
| 2424 | u16 dbm; |
| 2425 | |
| 2426 | ENTER(); |
| 2427 | |
| 2428 | if (vwrq->disabled) { |
| 2429 | wlan_radio_ioctl(priv, RADIO_OFF); |
| 2430 | return 0; |
| 2431 | } |
| 2432 | |
| 2433 | adapter->preamble = cmd_type_auto_preamble; |
| 2434 | |
| 2435 | wlan_radio_ioctl(priv, RADIO_ON); |
| 2436 | |
| 2437 | if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) { |
| 2438 | dbm = (u16) mw_to_dbm(vwrq->value); |
| 2439 | } else |
| 2440 | dbm = (u16) vwrq->value; |
| 2441 | |
| 2442 | /* auto tx power control */ |
| 2443 | |
| 2444 | if (vwrq->fixed == 0) |
| 2445 | dbm = 0xffff; |
| 2446 | |
| 2447 | lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm); |
| 2448 | |
| 2449 | ret = libertas_prepare_and_send_command(priv, |
| 2450 | cmd_802_11_rf_tx_power, |
| 2451 | cmd_act_tx_power_opt_set_low, |
| 2452 | cmd_option_waitforrsp, 0, (void *)&dbm); |
| 2453 | |
| 2454 | LEAVE(); |
| 2455 | return ret; |
| 2456 | } |
| 2457 | |
| 2458 | static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info, |
| 2459 | struct iw_point *dwrq, char *extra) |
| 2460 | { |
| 2461 | wlan_private *priv = dev->priv; |
| 2462 | wlan_adapter *adapter = priv->adapter; |
| 2463 | |
| 2464 | ENTER(); |
| 2465 | /* |
| 2466 | * Note : if dwrq->flags != 0, we should get the relevant SSID from |
| 2467 | * the SSID list... |
| 2468 | */ |
| 2469 | |
| 2470 | /* |
| 2471 | * Get the current SSID |
| 2472 | */ |
| 2473 | if (adapter->connect_status == libertas_connected) { |
| 2474 | memcpy(extra, adapter->curbssparams.ssid.ssid, |
| 2475 | adapter->curbssparams.ssid.ssidlength); |
| 2476 | extra[adapter->curbssparams.ssid.ssidlength] = '\0'; |
| 2477 | } else { |
| 2478 | memset(extra, 0, 32); |
| 2479 | extra[adapter->curbssparams.ssid.ssidlength] = '\0'; |
| 2480 | } |
| 2481 | /* |
| 2482 | * If none, we may want to get the one that was set |
| 2483 | */ |
| 2484 | |
| 2485 | /* To make the driver backward compatible with WPA supplicant v0.2.4 */ |
| 2486 | if (dwrq->length == 32) /* check with WPA supplicant buffer size */ |
| 2487 | dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength, |
| 2488 | IW_ESSID_MAX_SIZE); |
| 2489 | else |
| 2490 | dwrq->length = adapter->curbssparams.ssid.ssidlength + 1; |
| 2491 | |
| 2492 | dwrq->flags = 1; /* active */ |
| 2493 | |
| 2494 | LEAVE(); |
| 2495 | return 0; |
| 2496 | } |
| 2497 | |
| 2498 | static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info, |
| 2499 | struct iw_point *dwrq, char *extra) |
| 2500 | { |
| 2501 | wlan_private *priv = dev->priv; |
| 2502 | wlan_adapter *adapter = priv->adapter; |
| 2503 | int ret = 0; |
| 2504 | struct WLAN_802_11_SSID ssid; |
| 2505 | struct assoc_request * assoc_req; |
| 2506 | int ssid_len = dwrq->length; |
| 2507 | |
| 2508 | ENTER(); |
| 2509 | |
| 2510 | /* |
| 2511 | * WE-20 and earlier NULL pad the end of the SSID and increment |
| 2512 | * SSID length so it can be used like a string. WE-21 and later don't, |
| 2513 | * but some userspace tools aren't able to cope with the change. |
| 2514 | */ |
| 2515 | if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0')) |
| 2516 | ssid_len--; |
| 2517 | |
| 2518 | /* Check the size of the string */ |
| 2519 | if (ssid_len > IW_ESSID_MAX_SIZE) { |
| 2520 | ret = -E2BIG; |
| 2521 | goto out; |
| 2522 | } |
| 2523 | |
| 2524 | memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID)); |
| 2525 | |
| 2526 | if (!dwrq->flags || !ssid_len) { |
| 2527 | /* "any" SSID requested; leave SSID blank */ |
| 2528 | } else { |
| 2529 | /* Specific SSID requested */ |
| 2530 | memcpy(&ssid.ssid, extra, ssid_len); |
| 2531 | ssid.ssidlength = ssid_len; |
| 2532 | } |
| 2533 | |
| 2534 | lbs_pr_debug(1, "Requested new SSID = %s\n", |
| 2535 | (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any"); |
| 2536 | |
| 2537 | out: |
| 2538 | mutex_lock(&adapter->lock); |
| 2539 | if (ret == 0) { |
| 2540 | /* Get or create the current association request */ |
| 2541 | assoc_req = wlan_get_association_request(adapter); |
| 2542 | if (!assoc_req) { |
| 2543 | ret = -ENOMEM; |
| 2544 | } else { |
| 2545 | /* Copy the SSID to the association request */ |
| 2546 | memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID)); |
| 2547 | set_bit(ASSOC_FLAG_SSID, &assoc_req->flags); |
| 2548 | wlan_postpone_association_work(priv); |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | /* Cancel the association request if there was an error */ |
| 2553 | if (ret != 0) { |
| 2554 | wlan_cancel_association_work(priv); |
| 2555 | } |
| 2556 | |
| 2557 | mutex_unlock(&adapter->lock); |
| 2558 | |
| 2559 | LEAVE(); |
| 2560 | return ret; |
| 2561 | } |
| 2562 | |
| 2563 | /** |
| 2564 | * @brief Connect to the AP or Ad-hoc Network with specific bssid |
| 2565 | * |
| 2566 | * @param dev A pointer to net_device structure |
| 2567 | * @param info A pointer to iw_request_info structure |
| 2568 | * @param awrq A pointer to iw_param structure |
| 2569 | * @param extra A pointer to extra data buf |
| 2570 | * @return 0 --success, otherwise fail |
| 2571 | */ |
| 2572 | static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info, |
| 2573 | struct sockaddr *awrq, char *extra) |
| 2574 | { |
| 2575 | wlan_private *priv = dev->priv; |
| 2576 | wlan_adapter *adapter = priv->adapter; |
| 2577 | struct assoc_request * assoc_req; |
| 2578 | int ret = 0; |
| 2579 | |
| 2580 | ENTER(); |
| 2581 | |
| 2582 | if (awrq->sa_family != ARPHRD_ETHER) |
| 2583 | return -EINVAL; |
| 2584 | |
| 2585 | lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data)); |
| 2586 | |
| 2587 | mutex_lock(&adapter->lock); |
| 2588 | |
| 2589 | /* Get or create the current association request */ |
| 2590 | assoc_req = wlan_get_association_request(adapter); |
| 2591 | if (!assoc_req) { |
| 2592 | wlan_cancel_association_work(priv); |
| 2593 | ret = -ENOMEM; |
| 2594 | } else { |
| 2595 | /* Copy the BSSID to the association request */ |
| 2596 | memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN); |
| 2597 | set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags); |
| 2598 | wlan_postpone_association_work(priv); |
| 2599 | } |
| 2600 | |
| 2601 | mutex_unlock(&adapter->lock); |
| 2602 | |
| 2603 | return ret; |
| 2604 | } |
| 2605 | |
| 2606 | void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen) |
| 2607 | { |
| 2608 | union { |
| 2609 | u32 l; |
| 2610 | u8 c[4]; |
| 2611 | } ver; |
| 2612 | char fwver[32]; |
| 2613 | |
| 2614 | mutex_lock(&adapter->lock); |
| 2615 | ver.l = adapter->fwreleasenumber; |
| 2616 | mutex_unlock(&adapter->lock); |
| 2617 | |
| 2618 | if (ver.c[3] == 0) |
| 2619 | sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]); |
| 2620 | else |
| 2621 | sprintf(fwver, "%u.%u.%u.p%u", |
| 2622 | ver.c[2], ver.c[1], ver.c[0], ver.c[3]); |
| 2623 | |
| 2624 | snprintf(fwversion, maxlen, fwver); |
| 2625 | } |
| 2626 | |
| 2627 | |
| 2628 | /* |
| 2629 | * iwconfig settable callbacks |
| 2630 | */ |
| 2631 | static const iw_handler wlan_handler[] = { |
| 2632 | (iw_handler) NULL, /* SIOCSIWCOMMIT */ |
| 2633 | (iw_handler) wlan_get_name, /* SIOCGIWNAME */ |
| 2634 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 2635 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 2636 | (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */ |
| 2637 | (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */ |
| 2638 | (iw_handler) wlan_set_mode, /* SIOCSIWMODE */ |
| 2639 | (iw_handler) wlan_get_mode, /* SIOCGIWMODE */ |
| 2640 | (iw_handler) NULL, /* SIOCSIWSENS */ |
| 2641 | (iw_handler) NULL, /* SIOCGIWSENS */ |
| 2642 | (iw_handler) NULL, /* SIOCSIWRANGE */ |
| 2643 | (iw_handler) wlan_get_range, /* SIOCGIWRANGE */ |
| 2644 | (iw_handler) NULL, /* SIOCSIWPRIV */ |
| 2645 | (iw_handler) NULL, /* SIOCGIWPRIV */ |
| 2646 | (iw_handler) NULL, /* SIOCSIWSTATS */ |
| 2647 | (iw_handler) NULL, /* SIOCGIWSTATS */ |
| 2648 | iw_handler_set_spy, /* SIOCSIWSPY */ |
| 2649 | iw_handler_get_spy, /* SIOCGIWSPY */ |
| 2650 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ |
| 2651 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ |
| 2652 | (iw_handler) wlan_set_wap, /* SIOCSIWAP */ |
| 2653 | (iw_handler) wlan_get_wap, /* SIOCGIWAP */ |
| 2654 | (iw_handler) NULL, /* SIOCSIWMLME */ |
| 2655 | (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */ |
| 2656 | (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */ |
| 2657 | (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */ |
| 2658 | (iw_handler) wlan_set_essid, /* SIOCSIWESSID */ |
| 2659 | (iw_handler) wlan_get_essid, /* SIOCGIWESSID */ |
| 2660 | (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */ |
| 2661 | (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */ |
| 2662 | (iw_handler) NULL, /* -- hole -- */ |
| 2663 | (iw_handler) NULL, /* -- hole -- */ |
| 2664 | (iw_handler) wlan_set_rate, /* SIOCSIWRATE */ |
| 2665 | (iw_handler) wlan_get_rate, /* SIOCGIWRATE */ |
| 2666 | (iw_handler) wlan_set_rts, /* SIOCSIWRTS */ |
| 2667 | (iw_handler) wlan_get_rts, /* SIOCGIWRTS */ |
| 2668 | (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */ |
| 2669 | (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */ |
| 2670 | (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */ |
| 2671 | (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */ |
| 2672 | (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */ |
| 2673 | (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */ |
| 2674 | (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */ |
| 2675 | (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */ |
| 2676 | (iw_handler) wlan_set_power, /* SIOCSIWPOWER */ |
| 2677 | (iw_handler) wlan_get_power, /* SIOCGIWPOWER */ |
| 2678 | (iw_handler) NULL, /* -- hole -- */ |
| 2679 | (iw_handler) NULL, /* -- hole -- */ |
| 2680 | (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */ |
| 2681 | (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */ |
| 2682 | (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */ |
| 2683 | (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */ |
| 2684 | (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */ |
| 2685 | (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */ |
| 2686 | (iw_handler) NULL, /* SIOCSIWPMKSA */ |
| 2687 | }; |
| 2688 | |
| 2689 | struct iw_handler_def libertas_handler_def = { |
| 2690 | .num_standard = sizeof(wlan_handler) / sizeof(iw_handler), |
| 2691 | .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler), |
| 2692 | .num_private_args = sizeof(wlan_private_args) / |
| 2693 | sizeof(struct iw_priv_args), |
| 2694 | .standard = (iw_handler *) wlan_handler, |
| 2695 | .private = (iw_handler *) wlan_private_handler, |
| 2696 | .private_args = (struct iw_priv_args *)wlan_private_args, |
| 2697 | .get_wireless_stats = wlan_get_wireless_stats, |
| 2698 | }; |