1 /* 2 * Driver for KeyStream 11b/g wireless LAN 3 * 4 * Copyright (C) 2005-2008 KeyStream Corp. 5 * Copyright (C) 2009 Renesas Technology Corp. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 12 #include <linux/module.h> 13 #include <linux/kernel.h> 14 #include <linux/compiler.h> 15 #include <linux/init.h> 16 #include <linux/ioport.h> 17 #include <linux/netdevice.h> 18 #include <linux/etherdevice.h> 19 #include <linux/if_arp.h> 20 #include <linux/rtnetlink.h> 21 #include <linux/delay.h> 22 #include <linux/completion.h> 23 #include <linux/mii.h> 24 #include <linux/pci.h> 25 #include <linux/ctype.h> 26 #include <linux/timer.h> 27 #include <linux/atomic.h> 28 #include <linux/io.h> 29 #include <linux/uaccess.h> 30 31 static int wep_on_off; 32 #define WEP_OFF 0 33 #define WEP_ON_64BIT 1 34 #define WEP_ON_128BIT 2 35 36 #include "ks_wlan.h" 37 #include "ks_hostif.h" 38 #include "ks_wlan_ioctl.h" 39 40 /* Include Wireless Extension definition and check version */ 41 #include <linux/wireless.h> 42 #define WIRELESS_SPY /* enable iwspy support */ 43 #include <net/iw_handler.h> /* New driver API */ 44 45 /* Frequency list (map channels to frequencies) */ 46 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, 47 2447, 2452, 2457, 2462, 2467, 2472, 2484 48 }; 49 50 /* A few details needed for WEP (Wireless Equivalent Privacy) */ 51 #define MAX_KEY_SIZE 13 /* 128 (?) bits */ 52 #define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */ 53 struct wep_key { 54 u16 len; 55 u8 key[16]; /* 40-bit and 104-bit keys */ 56 }; 57 58 /* Backward compatibility */ 59 #ifndef IW_ENCODE_NOKEY 60 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */ 61 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN) 62 #endif /* IW_ENCODE_NOKEY */ 63 64 /* List of Wireless Handlers (new API) */ 65 static const struct iw_handler_def ks_wlan_handler_def; 66 67 #define KSC_OPNOTSUPP /* Operation Not Support */ 68 69 /* 70 * function prototypes 71 */ 72 static int ks_wlan_open(struct net_device *dev); 73 static void ks_wlan_tx_timeout(struct net_device *dev); 74 static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev); 75 static int ks_wlan_close(struct net_device *dev); 76 static void ks_wlan_set_multicast_list(struct net_device *dev); 77 static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev); 78 static int ks_wlan_set_mac_address(struct net_device *dev, void *addr); 79 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, 80 int cmd); 81 82 static atomic_t update_phyinfo; 83 static struct timer_list update_phyinfo_timer; 84 static 85 int ks_wlan_update_phy_information(struct ks_wlan_private *priv) 86 { 87 struct iw_statistics *wstats = &priv->wstats; 88 89 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt()); 90 91 if (priv->dev_state < DEVICE_STATE_READY) 92 return -1; /* not finished initialize */ 93 94 if (atomic_read(&update_phyinfo)) 95 return 1; 96 97 /* The status */ 98 wstats->status = priv->reg.operation_mode; /* Operation mode */ 99 100 /* Signal quality and co. But where is the noise level ??? */ 101 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST); 102 103 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */ 104 if (!wait_for_completion_interruptible_timeout 105 (&priv->confirm_wait, HZ / 2)) { 106 DPRINTK(1, "wait time out!!\n"); 107 } 108 109 atomic_inc(&update_phyinfo); 110 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */ 111 add_timer(&update_phyinfo_timer); 112 113 return 0; 114 } 115 116 static 117 void ks_wlan_update_phyinfo_timeout(unsigned long ptr) 118 { 119 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt()); 120 atomic_set(&update_phyinfo, 0); 121 } 122 123 int ks_wlan_setup_parameter(struct ks_wlan_private *priv, 124 unsigned int commit_flag) 125 { 126 DPRINTK(2, "\n"); 127 128 hostif_sme_enqueue(priv, SME_STOP_REQUEST); 129 130 if (commit_flag & SME_RTS) 131 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST); 132 if (commit_flag & SME_FRAG) 133 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST); 134 135 if (commit_flag & SME_WEP_INDEX) 136 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST); 137 if (commit_flag & SME_WEP_VAL1) 138 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST); 139 if (commit_flag & SME_WEP_VAL2) 140 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST); 141 if (commit_flag & SME_WEP_VAL3) 142 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST); 143 if (commit_flag & SME_WEP_VAL4) 144 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST); 145 if (commit_flag & SME_WEP_FLAG) 146 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST); 147 148 if (commit_flag & SME_RSN) { 149 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST); 150 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST); 151 } 152 if (commit_flag & SME_RSN_MULTICAST) 153 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST); 154 if (commit_flag & SME_RSN_UNICAST) 155 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST); 156 if (commit_flag & SME_RSN_AUTH) 157 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST); 158 159 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST); 160 161 hostif_sme_enqueue(priv, SME_START_REQUEST); 162 163 return 0; 164 } 165 166 /* 167 * Initial Wireless Extension code for Ks_Wlannet driver by : 168 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00 169 * Conversion to new driver API by : 170 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02 171 * Javier also did a good amount of work here, adding some new extensions 172 * and fixing my code. Let's just say that without him this code just 173 * would not work at all... - Jean II 174 */ 175 176 /*------------------------------------------------------------------*/ 177 /* Wireless Handler : get protocol name */ 178 static int ks_wlan_get_name(struct net_device *dev, 179 struct iw_request_info *info, char *cwrq, 180 char *extra) 181 { 182 struct ks_wlan_private *priv = 183 (struct ks_wlan_private *)netdev_priv(dev); 184 185 if (priv->sleep_mode == SLP_SLEEP) 186 return -EPERM; 187 188 /* for SLEEP MODE */ 189 if (priv->dev_state < DEVICE_STATE_READY) 190 strcpy(cwrq, "NOT READY!"); 191 else if (priv->reg.phy_type == D_11B_ONLY_MODE) 192 strcpy(cwrq, "IEEE 802.11b"); 193 else if (priv->reg.phy_type == D_11G_ONLY_MODE) 194 strcpy(cwrq, "IEEE 802.11g"); 195 else 196 strcpy(cwrq, "IEEE 802.11b/g"); 197 198 return 0; 199 } 200 201 /*------------------------------------------------------------------*/ 202 /* Wireless Handler : set frequency */ 203 static int ks_wlan_set_freq(struct net_device *dev, 204 struct iw_request_info *info, struct iw_freq *fwrq, 205 char *extra) 206 { 207 struct ks_wlan_private *priv = 208 (struct ks_wlan_private *)netdev_priv(dev); 209 int rc = -EINPROGRESS; /* Call commit handler */ 210 211 if (priv->sleep_mode == SLP_SLEEP) 212 return -EPERM; 213 214 /* for SLEEP MODE */ 215 /* If setting by frequency, convert to a channel */ 216 if ((fwrq->e == 1) && 217 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) { 218 int f = fwrq->m / 100000; 219 int c = 0; 220 221 while ((c < 14) && (f != frequency_list[c])) 222 c++; 223 /* Hack to fall through... */ 224 fwrq->e = 0; 225 fwrq->m = c + 1; 226 } 227 /* Setting by channel number */ 228 if ((fwrq->m > 1000) || (fwrq->e > 0)) 229 rc = -EOPNOTSUPP; 230 else { 231 int channel = fwrq->m; 232 /* We should do a better check than that, 233 * based on the card capability !!! */ 234 if ((channel < 1) || (channel > 14)) { 235 netdev_dbg(dev, 236 "%s: New channel value of %d is invalid!\n", 237 dev->name, fwrq->m); 238 rc = -EINVAL; 239 } else { 240 /* Yes ! We can set it !!! */ 241 priv->reg.channel = (u8) (channel); 242 priv->need_commit |= SME_MODE_SET; 243 } 244 } 245 246 return rc; 247 } 248 249 /*------------------------------------------------------------------*/ 250 /* Wireless Handler : get frequency */ 251 static int ks_wlan_get_freq(struct net_device *dev, 252 struct iw_request_info *info, struct iw_freq *fwrq, 253 char *extra) 254 { 255 struct ks_wlan_private *priv = 256 (struct ks_wlan_private *)netdev_priv(dev); 257 int f; 258 259 if (priv->sleep_mode == SLP_SLEEP) 260 return -EPERM; 261 262 /* for SLEEP MODE */ 263 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) 264 f = (int)priv->current_ap.channel; 265 else 266 f = (int)priv->reg.channel; 267 fwrq->m = frequency_list[f - 1] * 100000; 268 fwrq->e = 1; 269 270 return 0; 271 } 272 273 /*------------------------------------------------------------------*/ 274 /* Wireless Handler : set ESSID */ 275 static int ks_wlan_set_essid(struct net_device *dev, 276 struct iw_request_info *info, 277 struct iw_point *dwrq, char *extra) 278 { 279 struct ks_wlan_private *priv = 280 (struct ks_wlan_private *)netdev_priv(dev); 281 size_t len; 282 283 DPRINTK(2, " %d\n", dwrq->flags); 284 285 if (priv->sleep_mode == SLP_SLEEP) 286 return -EPERM; 287 288 /* for SLEEP MODE */ 289 /* Check if we asked for `any' */ 290 if (dwrq->flags == 0) { 291 /* Just send an empty SSID list */ 292 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body)); 293 priv->reg.ssid.size = 0; 294 } else { 295 #if 1 296 len = dwrq->length; 297 /* iwconfig uses nul termination in SSID.. */ 298 if (len > 0 && extra[len - 1] == '\0') 299 len--; 300 301 /* Check the size of the string */ 302 if (len > IW_ESSID_MAX_SIZE) 303 return -EINVAL; 304 305 #else 306 /* Check the size of the string */ 307 if (dwrq->length > IW_ESSID_MAX_SIZE + 1) 308 return -E2BIG; 309 310 #endif 311 312 /* Set the SSID */ 313 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body)); 314 315 #if 1 316 memcpy(priv->reg.ssid.body, extra, len); 317 priv->reg.ssid.size = len; 318 #else 319 memcpy(priv->reg.ssid.body, extra, dwrq->length); 320 priv->reg.ssid.size = dwrq->length; 321 #endif 322 } 323 /* Write it to the card */ 324 priv->need_commit |= SME_MODE_SET; 325 326 // return -EINPROGRESS; /* Call commit handler */ 327 ks_wlan_setup_parameter(priv, priv->need_commit); 328 priv->need_commit = 0; 329 return 0; 330 } 331 332 /*------------------------------------------------------------------*/ 333 /* Wireless Handler : get ESSID */ 334 static int ks_wlan_get_essid(struct net_device *dev, 335 struct iw_request_info *info, 336 struct iw_point *dwrq, char *extra) 337 { 338 struct ks_wlan_private *priv = 339 (struct ks_wlan_private *)netdev_priv(dev); 340 341 if (priv->sleep_mode == SLP_SLEEP) 342 return -EPERM; 343 344 /* for SLEEP MODE */ 345 /* Note : if dwrq->flags != 0, we should 346 * get the relevant SSID from the SSID list... */ 347 if (priv->reg.ssid.size) { 348 /* Get the current SSID */ 349 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size); 350 #if 0 351 extra[priv->reg.ssid.size] = '\0'; 352 #endif 353 /* If none, we may want to get the one that was set */ 354 355 /* Push it out ! */ 356 #if 1 357 dwrq->length = priv->reg.ssid.size; 358 #else 359 dwrq->length = priv->reg.ssid.size + 1; 360 #endif 361 dwrq->flags = 1; /* active */ 362 } else { 363 #if 1 364 dwrq->length = 0; 365 #else 366 extra[0] = '\0'; 367 dwrq->length = 1; 368 #endif 369 dwrq->flags = 0; /* ANY */ 370 } 371 372 return 0; 373 } 374 375 /*------------------------------------------------------------------*/ 376 /* Wireless Handler : set AP address */ 377 static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info, 378 struct sockaddr *ap_addr, char *extra) 379 { 380 struct ks_wlan_private *priv = 381 (struct ks_wlan_private *)netdev_priv(dev); 382 383 DPRINTK(2, "\n"); 384 385 if (priv->sleep_mode == SLP_SLEEP) 386 return -EPERM; 387 388 /* for SLEEP MODE */ 389 if (priv->reg.operation_mode == MODE_ADHOC || 390 priv->reg.operation_mode == MODE_INFRASTRUCTURE) { 391 memcpy(priv->reg.bssid, &ap_addr->sa_data, ETH_ALEN); 392 393 if (is_valid_ether_addr((u8 *)priv->reg.bssid)) 394 priv->need_commit |= SME_MODE_SET; 395 396 } else { 397 eth_zero_addr(priv->reg.bssid); 398 return -EOPNOTSUPP; 399 } 400 401 DPRINTK(2, "bssid = %pM\n", priv->reg.bssid); 402 403 /* Write it to the card */ 404 if (priv->need_commit) { 405 priv->need_commit |= SME_MODE_SET; 406 return -EINPROGRESS; /* Call commit handler */ 407 } 408 return 0; 409 } 410 411 /*------------------------------------------------------------------*/ 412 /* Wireless Handler : get AP address */ 413 static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info, 414 struct sockaddr *awrq, char *extra) 415 { 416 struct ks_wlan_private *priv = 417 (struct ks_wlan_private *)netdev_priv(dev); 418 419 if (priv->sleep_mode == SLP_SLEEP) 420 return -EPERM; 421 422 /* for SLEEP MODE */ 423 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) 424 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN); 425 else 426 eth_zero_addr(awrq->sa_data); 427 428 awrq->sa_family = ARPHRD_ETHER; 429 430 return 0; 431 } 432 433 /*------------------------------------------------------------------*/ 434 /* Wireless Handler : set Nickname */ 435 static int ks_wlan_set_nick(struct net_device *dev, 436 struct iw_request_info *info, struct iw_point *dwrq, 437 char *extra) 438 { 439 struct ks_wlan_private *priv = 440 (struct ks_wlan_private *)netdev_priv(dev); 441 442 if (priv->sleep_mode == SLP_SLEEP) 443 return -EPERM; 444 445 /* for SLEEP MODE */ 446 /* Check the size of the string */ 447 if (dwrq->length > 16 + 1) 448 return -E2BIG; 449 450 memset(priv->nick, 0, sizeof(priv->nick)); 451 memcpy(priv->nick, extra, dwrq->length); 452 453 return -EINPROGRESS; /* Call commit handler */ 454 } 455 456 /*------------------------------------------------------------------*/ 457 /* Wireless Handler : get Nickname */ 458 static int ks_wlan_get_nick(struct net_device *dev, 459 struct iw_request_info *info, struct iw_point *dwrq, 460 char *extra) 461 { 462 struct ks_wlan_private *priv = 463 (struct ks_wlan_private *)netdev_priv(dev); 464 465 if (priv->sleep_mode == SLP_SLEEP) 466 return -EPERM; 467 468 /* for SLEEP MODE */ 469 strncpy(extra, priv->nick, 16); 470 extra[16] = '\0'; 471 dwrq->length = strlen(extra) + 1; 472 473 return 0; 474 } 475 476 /*------------------------------------------------------------------*/ 477 /* Wireless Handler : set Bit-Rate */ 478 static int ks_wlan_set_rate(struct net_device *dev, 479 struct iw_request_info *info, struct iw_param *vwrq, 480 char *extra) 481 { 482 struct ks_wlan_private *priv = 483 (struct ks_wlan_private *)netdev_priv(dev); 484 int i = 0; 485 486 if (priv->sleep_mode == SLP_SLEEP) 487 return -EPERM; 488 489 /* for SLEEP MODE */ 490 if (priv->reg.phy_type == D_11B_ONLY_MODE) { 491 if (vwrq->fixed == 1) { 492 switch (vwrq->value) { 493 case 11000000: 494 case 5500000: 495 priv->reg.rate_set.body[0] = 496 (uint8_t) (vwrq->value / 500000); 497 break; 498 case 2000000: 499 case 1000000: 500 priv->reg.rate_set.body[0] = 501 ((uint8_t) (vwrq->value / 500000)) | 502 BASIC_RATE; 503 break; 504 default: 505 return -EINVAL; 506 } 507 priv->reg.tx_rate = TX_RATE_FIXED; 508 priv->reg.rate_set.size = 1; 509 } else { /* vwrq->fixed == 0 */ 510 if (vwrq->value > 0) { 511 switch (vwrq->value) { 512 case 11000000: 513 priv->reg.rate_set.body[3] = 514 TX_RATE_11M; 515 i++; 516 case 5500000: 517 priv->reg.rate_set.body[2] = TX_RATE_5M; 518 i++; 519 case 2000000: 520 priv->reg.rate_set.body[1] = 521 TX_RATE_2M | BASIC_RATE; 522 i++; 523 case 1000000: 524 priv->reg.rate_set.body[0] = 525 TX_RATE_1M | BASIC_RATE; 526 i++; 527 break; 528 default: 529 return -EINVAL; 530 } 531 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO; 532 priv->reg.rate_set.size = i; 533 } else { 534 priv->reg.rate_set.body[3] = TX_RATE_11M; 535 priv->reg.rate_set.body[2] = TX_RATE_5M; 536 priv->reg.rate_set.body[1] = 537 TX_RATE_2M | BASIC_RATE; 538 priv->reg.rate_set.body[0] = 539 TX_RATE_1M | BASIC_RATE; 540 priv->reg.tx_rate = TX_RATE_FULL_AUTO; 541 priv->reg.rate_set.size = 4; 542 } 543 } 544 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */ 545 if (vwrq->fixed == 1) { 546 switch (vwrq->value) { 547 case 54000000: 548 case 48000000: 549 case 36000000: 550 case 18000000: 551 case 9000000: 552 priv->reg.rate_set.body[0] = 553 (uint8_t) (vwrq->value / 500000); 554 break; 555 case 24000000: 556 case 12000000: 557 case 11000000: 558 case 6000000: 559 case 5500000: 560 case 2000000: 561 case 1000000: 562 priv->reg.rate_set.body[0] = 563 ((uint8_t) (vwrq->value / 500000)) | 564 BASIC_RATE; 565 break; 566 default: 567 return -EINVAL; 568 } 569 priv->reg.tx_rate = TX_RATE_FIXED; 570 priv->reg.rate_set.size = 1; 571 } else { /* vwrq->fixed == 0 */ 572 if (vwrq->value > 0) { 573 switch (vwrq->value) { 574 case 54000000: 575 priv->reg.rate_set.body[11] = 576 TX_RATE_54M; 577 i++; 578 case 48000000: 579 priv->reg.rate_set.body[10] = 580 TX_RATE_48M; 581 i++; 582 case 36000000: 583 priv->reg.rate_set.body[9] = 584 TX_RATE_36M; 585 i++; 586 case 24000000: 587 case 18000000: 588 case 12000000: 589 case 11000000: 590 case 9000000: 591 case 6000000: 592 if (vwrq->value == 24000000) { 593 priv->reg.rate_set.body[8] = 594 TX_RATE_18M; 595 i++; 596 priv->reg.rate_set.body[7] = 597 TX_RATE_9M; 598 i++; 599 priv->reg.rate_set.body[6] = 600 TX_RATE_24M | BASIC_RATE; 601 i++; 602 priv->reg.rate_set.body[5] = 603 TX_RATE_12M | BASIC_RATE; 604 i++; 605 priv->reg.rate_set.body[4] = 606 TX_RATE_6M | BASIC_RATE; 607 i++; 608 priv->reg.rate_set.body[3] = 609 TX_RATE_11M | BASIC_RATE; 610 i++; 611 } else if (vwrq->value == 18000000) { 612 priv->reg.rate_set.body[7] = 613 TX_RATE_18M; 614 i++; 615 priv->reg.rate_set.body[6] = 616 TX_RATE_9M; 617 i++; 618 priv->reg.rate_set.body[5] = 619 TX_RATE_12M | BASIC_RATE; 620 i++; 621 priv->reg.rate_set.body[4] = 622 TX_RATE_6M | BASIC_RATE; 623 i++; 624 priv->reg.rate_set.body[3] = 625 TX_RATE_11M | BASIC_RATE; 626 i++; 627 } else if (vwrq->value == 12000000) { 628 priv->reg.rate_set.body[6] = 629 TX_RATE_9M; 630 i++; 631 priv->reg.rate_set.body[5] = 632 TX_RATE_12M | BASIC_RATE; 633 i++; 634 priv->reg.rate_set.body[4] = 635 TX_RATE_6M | BASIC_RATE; 636 i++; 637 priv->reg.rate_set.body[3] = 638 TX_RATE_11M | BASIC_RATE; 639 i++; 640 } else if (vwrq->value == 11000000) { 641 priv->reg.rate_set.body[5] = 642 TX_RATE_9M; 643 i++; 644 priv->reg.rate_set.body[4] = 645 TX_RATE_6M | BASIC_RATE; 646 i++; 647 priv->reg.rate_set.body[3] = 648 TX_RATE_11M | BASIC_RATE; 649 i++; 650 } else if (vwrq->value == 9000000) { 651 priv->reg.rate_set.body[4] = 652 TX_RATE_9M; 653 i++; 654 priv->reg.rate_set.body[3] = 655 TX_RATE_6M | BASIC_RATE; 656 i++; 657 } else { /* vwrq->value == 6000000 */ 658 priv->reg.rate_set.body[3] = 659 TX_RATE_6M | BASIC_RATE; 660 i++; 661 } 662 case 5500000: 663 priv->reg.rate_set.body[2] = 664 TX_RATE_5M | BASIC_RATE; 665 i++; 666 case 2000000: 667 priv->reg.rate_set.body[1] = 668 TX_RATE_2M | BASIC_RATE; 669 i++; 670 case 1000000: 671 priv->reg.rate_set.body[0] = 672 TX_RATE_1M | BASIC_RATE; 673 i++; 674 break; 675 default: 676 return -EINVAL; 677 } 678 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO; 679 priv->reg.rate_set.size = i; 680 } else { 681 priv->reg.rate_set.body[11] = TX_RATE_54M; 682 priv->reg.rate_set.body[10] = TX_RATE_48M; 683 priv->reg.rate_set.body[9] = TX_RATE_36M; 684 priv->reg.rate_set.body[8] = TX_RATE_18M; 685 priv->reg.rate_set.body[7] = TX_RATE_9M; 686 priv->reg.rate_set.body[6] = 687 TX_RATE_24M | BASIC_RATE; 688 priv->reg.rate_set.body[5] = 689 TX_RATE_12M | BASIC_RATE; 690 priv->reg.rate_set.body[4] = 691 TX_RATE_6M | BASIC_RATE; 692 priv->reg.rate_set.body[3] = 693 TX_RATE_11M | BASIC_RATE; 694 priv->reg.rate_set.body[2] = 695 TX_RATE_5M | BASIC_RATE; 696 priv->reg.rate_set.body[1] = 697 TX_RATE_2M | BASIC_RATE; 698 priv->reg.rate_set.body[0] = 699 TX_RATE_1M | BASIC_RATE; 700 priv->reg.tx_rate = TX_RATE_FULL_AUTO; 701 priv->reg.rate_set.size = 12; 702 } 703 } 704 } 705 706 priv->need_commit |= SME_MODE_SET; 707 708 return -EINPROGRESS; /* Call commit handler */ 709 } 710 711 /*------------------------------------------------------------------*/ 712 /* Wireless Handler : get Bit-Rate */ 713 static int ks_wlan_get_rate(struct net_device *dev, 714 struct iw_request_info *info, struct iw_param *vwrq, 715 char *extra) 716 { 717 struct ks_wlan_private *priv = 718 (struct ks_wlan_private *)netdev_priv(dev); 719 720 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n", 721 in_interrupt(), atomic_read(&update_phyinfo)); 722 723 if (priv->sleep_mode == SLP_SLEEP) 724 return -EPERM; 725 726 /* for SLEEP MODE */ 727 if (!atomic_read(&update_phyinfo)) 728 ks_wlan_update_phy_information(priv); 729 730 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000; 731 if (priv->reg.tx_rate == TX_RATE_FIXED) 732 vwrq->fixed = 1; 733 else 734 vwrq->fixed = 0; 735 736 return 0; 737 } 738 739 /*------------------------------------------------------------------*/ 740 /* Wireless Handler : set RTS threshold */ 741 static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info, 742 struct iw_param *vwrq, char *extra) 743 { 744 struct ks_wlan_private *priv = 745 (struct ks_wlan_private *)netdev_priv(dev); 746 int rthr = vwrq->value; 747 748 if (priv->sleep_mode == SLP_SLEEP) 749 return -EPERM; 750 751 /* for SLEEP MODE */ 752 if (vwrq->disabled) 753 rthr = 2347; 754 if ((rthr < 0) || (rthr > 2347)) 755 return -EINVAL; 756 757 priv->reg.rts = rthr; 758 priv->need_commit |= SME_RTS; 759 760 return -EINPROGRESS; /* Call commit handler */ 761 } 762 763 /*------------------------------------------------------------------*/ 764 /* Wireless Handler : get RTS threshold */ 765 static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info, 766 struct iw_param *vwrq, char *extra) 767 { 768 struct ks_wlan_private *priv = 769 (struct ks_wlan_private *)netdev_priv(dev); 770 771 if (priv->sleep_mode == SLP_SLEEP) 772 return -EPERM; 773 774 /* for SLEEP MODE */ 775 vwrq->value = priv->reg.rts; 776 vwrq->disabled = (vwrq->value >= 2347); 777 vwrq->fixed = 1; 778 779 return 0; 780 } 781 782 /*------------------------------------------------------------------*/ 783 /* Wireless Handler : set Fragmentation threshold */ 784 static int ks_wlan_set_frag(struct net_device *dev, 785 struct iw_request_info *info, struct iw_param *vwrq, 786 char *extra) 787 { 788 struct ks_wlan_private *priv = 789 (struct ks_wlan_private *)netdev_priv(dev); 790 int fthr = vwrq->value; 791 792 if (priv->sleep_mode == SLP_SLEEP) 793 return -EPERM; 794 795 /* for SLEEP MODE */ 796 if (vwrq->disabled) 797 fthr = 2346; 798 if ((fthr < 256) || (fthr > 2346)) 799 return -EINVAL; 800 801 fthr &= ~0x1; /* Get an even value - is it really needed ??? */ 802 priv->reg.fragment = fthr; 803 priv->need_commit |= SME_FRAG; 804 805 return -EINPROGRESS; /* Call commit handler */ 806 } 807 808 /*------------------------------------------------------------------*/ 809 /* Wireless Handler : get Fragmentation threshold */ 810 static int ks_wlan_get_frag(struct net_device *dev, 811 struct iw_request_info *info, struct iw_param *vwrq, 812 char *extra) 813 { 814 struct ks_wlan_private *priv = 815 (struct ks_wlan_private *)netdev_priv(dev); 816 817 if (priv->sleep_mode == SLP_SLEEP) 818 return -EPERM; 819 820 /* for SLEEP MODE */ 821 vwrq->value = priv->reg.fragment; 822 vwrq->disabled = (vwrq->value >= 2346); 823 vwrq->fixed = 1; 824 825 return 0; 826 } 827 828 /*------------------------------------------------------------------*/ 829 /* Wireless Handler : set Mode of Operation */ 830 static int ks_wlan_set_mode(struct net_device *dev, 831 struct iw_request_info *info, __u32 *uwrq, 832 char *extra) 833 { 834 struct ks_wlan_private *priv = 835 (struct ks_wlan_private *)netdev_priv(dev); 836 837 DPRINTK(2, "mode=%d\n", *uwrq); 838 839 if (priv->sleep_mode == SLP_SLEEP) 840 return -EPERM; 841 842 /* for SLEEP MODE */ 843 switch (*uwrq) { 844 case IW_MODE_ADHOC: 845 priv->reg.operation_mode = MODE_ADHOC; 846 priv->need_commit |= SME_MODE_SET; 847 break; 848 case IW_MODE_INFRA: 849 priv->reg.operation_mode = MODE_INFRASTRUCTURE; 850 priv->need_commit |= SME_MODE_SET; 851 break; 852 case IW_MODE_AUTO: 853 case IW_MODE_MASTER: 854 case IW_MODE_REPEAT: 855 case IW_MODE_SECOND: 856 case IW_MODE_MONITOR: 857 default: 858 return -EINVAL; 859 } 860 861 return -EINPROGRESS; /* Call commit handler */ 862 } 863 864 /*------------------------------------------------------------------*/ 865 /* Wireless Handler : get Mode of Operation */ 866 static int ks_wlan_get_mode(struct net_device *dev, 867 struct iw_request_info *info, __u32 *uwrq, 868 char *extra) 869 { 870 struct ks_wlan_private *priv = 871 (struct ks_wlan_private *)netdev_priv(dev); 872 873 if (priv->sleep_mode == SLP_SLEEP) 874 return -EPERM; 875 876 /* for SLEEP MODE */ 877 /* If not managed, assume it's ad-hoc */ 878 switch (priv->reg.operation_mode) { 879 case MODE_INFRASTRUCTURE: 880 *uwrq = IW_MODE_INFRA; 881 break; 882 case MODE_ADHOC: 883 *uwrq = IW_MODE_ADHOC; 884 break; 885 default: 886 *uwrq = IW_MODE_ADHOC; 887 } 888 889 return 0; 890 } 891 892 /*------------------------------------------------------------------*/ 893 /* Wireless Handler : set Encryption Key */ 894 static int ks_wlan_set_encode(struct net_device *dev, 895 struct iw_request_info *info, 896 struct iw_point *dwrq, char *extra) 897 { 898 struct ks_wlan_private *priv = 899 (struct ks_wlan_private *)netdev_priv(dev); 900 901 struct wep_key key; 902 int index = (dwrq->flags & IW_ENCODE_INDEX); 903 int current_index = priv->reg.wep_index; 904 int i; 905 906 DPRINTK(2, "flags=%04X\n", dwrq->flags); 907 908 if (priv->sleep_mode == SLP_SLEEP) 909 return -EPERM; 910 911 /* for SLEEP MODE */ 912 /* index check */ 913 if ((index < 0) || (index > 4)) 914 return -EINVAL; 915 else if (index == 0) 916 index = current_index; 917 else 918 index--; 919 920 /* Is WEP supported ? */ 921 /* Basic checking: do we have a key to set ? */ 922 if (dwrq->length > 0) { 923 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */ 924 return -EINVAL; 925 } 926 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */ 927 key.len = MAX_KEY_SIZE; 928 priv->reg.privacy_invoked = 0x01; 929 priv->need_commit |= SME_WEP_FLAG; 930 wep_on_off = WEP_ON_128BIT; 931 } else { 932 if (dwrq->length > 0) { 933 key.len = MIN_KEY_SIZE; 934 priv->reg.privacy_invoked = 0x01; 935 priv->need_commit |= SME_WEP_FLAG; 936 wep_on_off = WEP_ON_64BIT; 937 } else { /* Disable the key */ 938 key.len = 0; 939 } 940 } 941 /* Check if the key is not marked as invalid */ 942 if (!(dwrq->flags & IW_ENCODE_NOKEY)) { 943 /* Cleanup */ 944 memset(key.key, 0, MAX_KEY_SIZE); 945 /* Copy the key in the driver */ 946 if (copy_from_user 947 (key.key, dwrq->pointer, dwrq->length)) { 948 key.len = 0; 949 return -EFAULT; 950 } 951 /* Send the key to the card */ 952 priv->reg.wep_key[index].size = key.len; 953 for (i = 0; i < (priv->reg.wep_key[index].size); i++) 954 priv->reg.wep_key[index].val[i] = key.key[i]; 955 956 priv->need_commit |= (SME_WEP_VAL1 << index); 957 priv->reg.wep_index = index; 958 priv->need_commit |= SME_WEP_INDEX; 959 } 960 } else { 961 if (dwrq->flags & IW_ENCODE_DISABLED) { 962 priv->reg.wep_key[0].size = 0; 963 priv->reg.wep_key[1].size = 0; 964 priv->reg.wep_key[2].size = 0; 965 priv->reg.wep_key[3].size = 0; 966 priv->reg.privacy_invoked = 0x00; 967 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) 968 priv->need_commit |= SME_MODE_SET; 969 970 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; 971 wep_on_off = WEP_OFF; 972 priv->need_commit |= SME_WEP_FLAG; 973 } else { 974 /* Do we want to just set the transmit key index ? */ 975 if ((index >= 0) && (index < 4)) { 976 /* set_wep_key(priv, index, 0, 0, 1); xxx */ 977 if (priv->reg.wep_key[index].size) { 978 priv->reg.wep_index = index; 979 priv->need_commit |= SME_WEP_INDEX; 980 } else 981 return -EINVAL; 982 } 983 } 984 } 985 986 /* Commit the changes if needed */ 987 if (dwrq->flags & IW_ENCODE_MODE) 988 priv->need_commit |= SME_WEP_FLAG; 989 990 if (dwrq->flags & IW_ENCODE_OPEN) { 991 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) 992 priv->need_commit |= SME_MODE_SET; 993 994 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; 995 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) { 996 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) 997 priv->need_commit |= SME_MODE_SET; 998 999 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY; 1000 } 1001 // return -EINPROGRESS; /* Call commit handler */ 1002 if (priv->need_commit) { 1003 ks_wlan_setup_parameter(priv, priv->need_commit); 1004 priv->need_commit = 0; 1005 } 1006 return 0; 1007 } 1008 1009 /*------------------------------------------------------------------*/ 1010 /* Wireless Handler : get Encryption Key */ 1011 static int ks_wlan_get_encode(struct net_device *dev, 1012 struct iw_request_info *info, 1013 struct iw_point *dwrq, char *extra) 1014 { 1015 struct ks_wlan_private *priv = 1016 (struct ks_wlan_private *)netdev_priv(dev); 1017 char zeros[16]; 1018 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; 1019 1020 if (priv->sleep_mode == SLP_SLEEP) 1021 return -EPERM; 1022 1023 /* for SLEEP MODE */ 1024 dwrq->flags = IW_ENCODE_DISABLED; 1025 1026 /* Check encryption mode */ 1027 switch (priv->reg.authenticate_type) { 1028 case AUTH_TYPE_OPEN_SYSTEM: 1029 dwrq->flags = IW_ENCODE_OPEN; 1030 break; 1031 case AUTH_TYPE_SHARED_KEY: 1032 dwrq->flags = IW_ENCODE_RESTRICTED; 1033 break; 1034 } 1035 1036 memset(zeros, 0, sizeof(zeros)); 1037 1038 /* Which key do we want ? -1 -> tx index */ 1039 if ((index < 0) || (index >= 4)) 1040 index = priv->reg.wep_index; 1041 if (priv->reg.privacy_invoked) { 1042 dwrq->flags &= ~IW_ENCODE_DISABLED; 1043 /* dwrq->flags |= IW_ENCODE_NOKEY; */ 1044 } 1045 dwrq->flags |= index + 1; 1046 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags); 1047 /* Copy the key to the user buffer */ 1048 if ((index >= 0) && (index < 4)) 1049 dwrq->length = priv->reg.wep_key[index].size; 1050 if (dwrq->length > 16) 1051 dwrq->length = 0; 1052 #if 1 /* IW_ENCODE_NOKEY; */ 1053 if (dwrq->length) { 1054 if ((index >= 0) && (index < 4)) 1055 memcpy(extra, priv->reg.wep_key[index].val, 1056 dwrq->length); 1057 } else 1058 memcpy(extra, zeros, dwrq->length); 1059 #endif 1060 return 0; 1061 } 1062 1063 #ifndef KSC_OPNOTSUPP 1064 /*------------------------------------------------------------------*/ 1065 /* Wireless Handler : set Tx-Power */ 1066 static int ks_wlan_set_txpow(struct net_device *dev, 1067 struct iw_request_info *info, 1068 struct iw_param *vwrq, char *extra) 1069 { 1070 return -EOPNOTSUPP; /* Not Support */ 1071 } 1072 1073 /*------------------------------------------------------------------*/ 1074 /* Wireless Handler : get Tx-Power */ 1075 static int ks_wlan_get_txpow(struct net_device *dev, 1076 struct iw_request_info *info, 1077 struct iw_param *vwrq, char *extra) 1078 { 1079 if (priv->sleep_mode == SLP_SLEEP) 1080 return -EPERM; 1081 1082 /* for SLEEP MODE */ 1083 /* Not Support */ 1084 vwrq->value = 0; 1085 vwrq->disabled = (vwrq->value == 0); 1086 vwrq->fixed = 1; 1087 return 0; 1088 } 1089 1090 /*------------------------------------------------------------------*/ 1091 /* Wireless Handler : set Retry limits */ 1092 static int ks_wlan_set_retry(struct net_device *dev, 1093 struct iw_request_info *info, 1094 struct iw_param *vwrq, char *extra) 1095 { 1096 return -EOPNOTSUPP; /* Not Support */ 1097 } 1098 1099 /*------------------------------------------------------------------*/ 1100 /* Wireless Handler : get Retry limits */ 1101 static int ks_wlan_get_retry(struct net_device *dev, 1102 struct iw_request_info *info, 1103 struct iw_param *vwrq, char *extra) 1104 { 1105 if (priv->sleep_mode == SLP_SLEEP) 1106 return -EPERM; 1107 1108 /* for SLEEP MODE */ 1109 /* Not Support */ 1110 vwrq->value = 0; 1111 vwrq->disabled = (vwrq->value == 0); 1112 vwrq->fixed = 1; 1113 return 0; 1114 } 1115 #endif /* KSC_OPNOTSUPP */ 1116 1117 /*------------------------------------------------------------------*/ 1118 /* Wireless Handler : get range info */ 1119 static int ks_wlan_get_range(struct net_device *dev, 1120 struct iw_request_info *info, 1121 struct iw_point *dwrq, char *extra) 1122 { 1123 struct ks_wlan_private *priv = 1124 (struct ks_wlan_private *)netdev_priv(dev); 1125 struct iw_range *range = (struct iw_range *)extra; 1126 int i, k; 1127 1128 DPRINTK(2, "\n"); 1129 1130 if (priv->sleep_mode == SLP_SLEEP) 1131 return -EPERM; 1132 1133 /* for SLEEP MODE */ 1134 dwrq->length = sizeof(struct iw_range); 1135 memset(range, 0, sizeof(*range)); 1136 range->min_nwid = 0x0000; 1137 range->max_nwid = 0x0000; 1138 range->num_channels = 14; 1139 /* Should be based on cap_rid.country to give only 1140 * what the current card support */ 1141 k = 0; 1142 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */ 1143 range->freq[k].i = i + 1; /* List index */ 1144 range->freq[k].m = frequency_list[i] * 100000; 1145 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ 1146 } 1147 range->num_frequency = k; 1148 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */ 1149 range->freq[13].i = 14; /* List index */ 1150 range->freq[13].m = frequency_list[13] * 100000; 1151 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */ 1152 range->num_frequency = 14; 1153 } 1154 1155 /* Hum... Should put the right values there */ 1156 range->max_qual.qual = 100; 1157 range->max_qual.level = 256 - 128; /* 0 dBm? */ 1158 range->max_qual.noise = 256 - 128; 1159 range->sensitivity = 1; 1160 1161 if (priv->reg.phy_type == D_11B_ONLY_MODE) { 1162 range->bitrate[0] = 1e6; 1163 range->bitrate[1] = 2e6; 1164 range->bitrate[2] = 5.5e6; 1165 range->bitrate[3] = 11e6; 1166 range->num_bitrates = 4; 1167 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */ 1168 range->bitrate[0] = 1e6; 1169 range->bitrate[1] = 2e6; 1170 range->bitrate[2] = 5.5e6; 1171 range->bitrate[3] = 11e6; 1172 1173 range->bitrate[4] = 6e6; 1174 range->bitrate[5] = 9e6; 1175 range->bitrate[6] = 12e6; 1176 if (IW_MAX_BITRATES < 9) { 1177 range->bitrate[7] = 54e6; 1178 range->num_bitrates = 8; 1179 } else { 1180 range->bitrate[7] = 18e6; 1181 range->bitrate[8] = 24e6; 1182 range->bitrate[9] = 36e6; 1183 range->bitrate[10] = 48e6; 1184 range->bitrate[11] = 54e6; 1185 1186 range->num_bitrates = 12; 1187 } 1188 } 1189 1190 /* Set an indication of the max TCP throughput 1191 * in bit/s that we can expect using this interface. 1192 * May be use for QoS stuff... Jean II */ 1193 if (i > 2) 1194 range->throughput = 5000 * 1000; 1195 else 1196 range->throughput = 1500 * 1000; 1197 1198 range->min_rts = 0; 1199 range->max_rts = 2347; 1200 range->min_frag = 256; 1201 range->max_frag = 2346; 1202 1203 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */ 1204 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */ 1205 range->num_encoding_sizes = 2; 1206 range->max_encoding_tokens = 4; 1207 1208 /* power management not support */ 1209 range->pmp_flags = IW_POWER_ON; 1210 range->pmt_flags = IW_POWER_ON; 1211 range->pm_capa = 0; 1212 1213 /* Transmit Power - values are in dBm( or mW) */ 1214 range->txpower[0] = -256; 1215 range->num_txpower = 1; 1216 range->txpower_capa = IW_TXPOW_DBM; 1217 /* range->txpower_capa = IW_TXPOW_MWATT; */ 1218 1219 range->we_version_source = 21; 1220 range->we_version_compiled = WIRELESS_EXT; 1221 1222 range->retry_capa = IW_RETRY_ON; 1223 range->retry_flags = IW_RETRY_ON; 1224 range->r_time_flags = IW_RETRY_ON; 1225 1226 /* Experimental measurements - boundary 11/5.5 Mb/s */ 1227 /* Note : with or without the (local->rssi), results 1228 * are somewhat different. - Jean II */ 1229 range->avg_qual.qual = 50; 1230 range->avg_qual.level = 186; /* -70 dBm */ 1231 range->avg_qual.noise = 0; 1232 1233 /* Event capability (kernel + driver) */ 1234 range->event_capa[0] = (IW_EVENT_CAPA_K_0 | 1235 IW_EVENT_CAPA_MASK(SIOCGIWAP) | 1236 IW_EVENT_CAPA_MASK(SIOCGIWSCAN)); 1237 range->event_capa[1] = IW_EVENT_CAPA_K_1; 1238 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) | 1239 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE)); 1240 1241 /* encode extension (WPA) capability */ 1242 range->enc_capa = (IW_ENC_CAPA_WPA | 1243 IW_ENC_CAPA_WPA2 | 1244 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP); 1245 return 0; 1246 } 1247 1248 /*------------------------------------------------------------------*/ 1249 /* Wireless Handler : set Power Management */ 1250 static int ks_wlan_set_power(struct net_device *dev, 1251 struct iw_request_info *info, 1252 struct iw_param *vwrq, char *extra) 1253 { 1254 struct ks_wlan_private *priv = 1255 (struct ks_wlan_private *)netdev_priv(dev); 1256 short enabled; 1257 1258 if (priv->sleep_mode == SLP_SLEEP) 1259 return -EPERM; 1260 1261 /* for SLEEP MODE */ 1262 enabled = vwrq->disabled ? 0 : 1; 1263 if (enabled == 0) { /* 0 */ 1264 priv->reg.powermgt = POWMGT_ACTIVE_MODE; 1265 } else if (enabled) { /* 1 */ 1266 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) 1267 priv->reg.powermgt = POWMGT_SAVE1_MODE; 1268 else 1269 return -EINVAL; 1270 } else if (enabled) { /* 2 */ 1271 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) 1272 priv->reg.powermgt = POWMGT_SAVE2_MODE; 1273 else 1274 return -EINVAL; 1275 } else 1276 return -EINVAL; 1277 1278 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST); 1279 1280 return 0; 1281 } 1282 1283 /*------------------------------------------------------------------*/ 1284 /* Wireless Handler : get Power Management */ 1285 static int ks_wlan_get_power(struct net_device *dev, 1286 struct iw_request_info *info, 1287 struct iw_param *vwrq, char *extra) 1288 { 1289 struct ks_wlan_private *priv = 1290 (struct ks_wlan_private *)netdev_priv(dev); 1291 1292 if (priv->sleep_mode == SLP_SLEEP) 1293 return -EPERM; 1294 /* for SLEEP MODE */ 1295 if (priv->reg.powermgt > 0) 1296 vwrq->disabled = 0; 1297 else 1298 vwrq->disabled = 1; 1299 1300 return 0; 1301 } 1302 1303 /*------------------------------------------------------------------*/ 1304 /* Wireless Handler : get wirless statistics */ 1305 static int ks_wlan_get_iwstats(struct net_device *dev, 1306 struct iw_request_info *info, 1307 struct iw_quality *vwrq, char *extra) 1308 { 1309 struct ks_wlan_private *priv = 1310 (struct ks_wlan_private *)netdev_priv(dev); 1311 1312 if (priv->sleep_mode == SLP_SLEEP) 1313 return -EPERM; 1314 /* for SLEEP MODE */ 1315 vwrq->qual = 0; /* not supported */ 1316 vwrq->level = priv->wstats.qual.level; 1317 vwrq->noise = 0; /* not supported */ 1318 vwrq->updated = 0; 1319 1320 return 0; 1321 } 1322 1323 #ifndef KSC_OPNOTSUPP 1324 /*------------------------------------------------------------------*/ 1325 /* Wireless Handler : set Sensitivity */ 1326 static int ks_wlan_set_sens(struct net_device *dev, 1327 struct iw_request_info *info, struct iw_param *vwrq, 1328 char *extra) 1329 { 1330 return -EOPNOTSUPP; /* Not Support */ 1331 } 1332 1333 /*------------------------------------------------------------------*/ 1334 /* Wireless Handler : get Sensitivity */ 1335 static int ks_wlan_get_sens(struct net_device *dev, 1336 struct iw_request_info *info, struct iw_param *vwrq, 1337 char *extra) 1338 { 1339 /* Not Support */ 1340 vwrq->value = 0; 1341 vwrq->disabled = (vwrq->value == 0); 1342 vwrq->fixed = 1; 1343 return 0; 1344 } 1345 #endif /* KSC_OPNOTSUPP */ 1346 1347 /*------------------------------------------------------------------*/ 1348 /* Wireless Handler : get AP List */ 1349 /* Note : this is deprecated in favor of IWSCAN */ 1350 static int ks_wlan_get_aplist(struct net_device *dev, 1351 struct iw_request_info *info, 1352 struct iw_point *dwrq, char *extra) 1353 { 1354 struct ks_wlan_private *priv = 1355 (struct ks_wlan_private *)netdev_priv(dev); 1356 struct sockaddr *address = (struct sockaddr *)extra; 1357 struct iw_quality qual[LOCAL_APLIST_MAX]; 1358 1359 int i; 1360 1361 if (priv->sleep_mode == SLP_SLEEP) 1362 return -EPERM; 1363 /* for SLEEP MODE */ 1364 for (i = 0; i < priv->aplist.size; i++) { 1365 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]), 1366 ETH_ALEN); 1367 address[i].sa_family = ARPHRD_ETHER; 1368 qual[i].level = 256 - priv->aplist.ap[i].rssi; 1369 qual[i].qual = priv->aplist.ap[i].sq; 1370 qual[i].noise = 0; /* invalid noise value */ 1371 qual[i].updated = 7; 1372 } 1373 if (i) { 1374 dwrq->flags = 1; /* Should be define'd */ 1375 memcpy(extra + sizeof(struct sockaddr) * i, 1376 &qual, sizeof(struct iw_quality) * i); 1377 } 1378 dwrq->length = i; 1379 1380 return 0; 1381 } 1382 1383 /*------------------------------------------------------------------*/ 1384 /* Wireless Handler : Initiate Scan */ 1385 static int ks_wlan_set_scan(struct net_device *dev, 1386 struct iw_request_info *info, 1387 union iwreq_data *wrqu, char *extra) 1388 { 1389 struct ks_wlan_private *priv = 1390 (struct ks_wlan_private *)netdev_priv(dev); 1391 struct iw_scan_req *req = NULL; 1392 1393 DPRINTK(2, "\n"); 1394 1395 if (priv->sleep_mode == SLP_SLEEP) 1396 return -EPERM; 1397 1398 /* for SLEEP MODE */ 1399 /* specified SSID SCAN */ 1400 if (wrqu->data.length == sizeof(struct iw_scan_req) 1401 && wrqu->data.flags & IW_SCAN_THIS_ESSID) { 1402 req = (struct iw_scan_req *)extra; 1403 priv->scan_ssid_len = req->essid_len; 1404 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len); 1405 } else { 1406 priv->scan_ssid_len = 0; 1407 } 1408 1409 priv->sme_i.sme_flag |= SME_AP_SCAN; 1410 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST); 1411 1412 /* At this point, just return to the user. */ 1413 1414 return 0; 1415 } 1416 1417 /*------------------------------------------------------------------*/ 1418 /* 1419 * Translate scan data returned from the card to a card independent 1420 * format that the Wireless Tools will understand - Jean II 1421 */ 1422 static inline char *ks_wlan_translate_scan(struct net_device *dev, 1423 struct iw_request_info *info, 1424 char *current_ev, char *end_buf, 1425 struct local_ap_t *ap) 1426 { 1427 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */ 1428 struct iw_event iwe; /* Temporary buffer */ 1429 u16 capabilities; 1430 char *current_val; /* For rates */ 1431 int i; 1432 static const char rsn_leader[] = "rsn_ie="; 1433 static const char wpa_leader[] = "wpa_ie="; 1434 char buf0[RSN_IE_BODY_MAX * 2 + 30]; 1435 char buf1[RSN_IE_BODY_MAX * 2 + 30]; 1436 char *pbuf; 1437 /* First entry *MUST* be the AP MAC address */ 1438 iwe.cmd = SIOCGIWAP; 1439 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 1440 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN); 1441 current_ev = 1442 iwe_stream_add_event(info, current_ev, end_buf, &iwe, 1443 IW_EV_ADDR_LEN); 1444 1445 /* Other entries will be displayed in the order we give them */ 1446 1447 /* Add the ESSID */ 1448 iwe.u.data.length = ap->ssid.size; 1449 if (iwe.u.data.length > 32) 1450 iwe.u.data.length = 32; 1451 iwe.cmd = SIOCGIWESSID; 1452 iwe.u.data.flags = 1; 1453 current_ev = 1454 iwe_stream_add_point(info, current_ev, end_buf, &iwe, 1455 &(ap->ssid.body[0])); 1456 1457 /* Add mode */ 1458 iwe.cmd = SIOCGIWMODE; 1459 capabilities = le16_to_cpu(ap->capability); 1460 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) { 1461 if (capabilities & BSS_CAP_ESS) 1462 iwe.u.mode = IW_MODE_INFRA; 1463 else 1464 iwe.u.mode = IW_MODE_ADHOC; 1465 current_ev = 1466 iwe_stream_add_event(info, current_ev, end_buf, &iwe, 1467 IW_EV_UINT_LEN); 1468 } 1469 1470 /* Add frequency */ 1471 iwe.cmd = SIOCGIWFREQ; 1472 iwe.u.freq.m = ap->channel; 1473 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000; 1474 iwe.u.freq.e = 1; 1475 current_ev = 1476 iwe_stream_add_event(info, current_ev, end_buf, &iwe, 1477 IW_EV_FREQ_LEN); 1478 1479 /* Add quality statistics */ 1480 iwe.cmd = IWEVQUAL; 1481 iwe.u.qual.level = 256 - ap->rssi; 1482 iwe.u.qual.qual = ap->sq; 1483 iwe.u.qual.noise = 0; /* invalid noise value */ 1484 current_ev = 1485 iwe_stream_add_event(info, current_ev, end_buf, &iwe, 1486 IW_EV_QUAL_LEN); 1487 1488 /* Add encryption capability */ 1489 iwe.cmd = SIOCGIWENCODE; 1490 if (capabilities & BSS_CAP_PRIVACY) 1491 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; 1492 else 1493 iwe.u.data.flags = IW_ENCODE_DISABLED; 1494 iwe.u.data.length = 0; 1495 current_ev = 1496 iwe_stream_add_point(info, current_ev, end_buf, &iwe, 1497 &(ap->ssid.body[0])); 1498 1499 /* Rate : stuffing multiple values in a single event require a bit 1500 * more of magic - Jean II */ 1501 current_val = current_ev + IW_EV_LCP_LEN; 1502 1503 iwe.cmd = SIOCGIWRATE; 1504 /* Those two flags are ignored... */ 1505 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; 1506 1507 /* Max 16 values */ 1508 for (i = 0; i < 16; i++) { 1509 /* NULL terminated */ 1510 if (i >= ap->rate_set.size) 1511 break; 1512 /* Bit rate given in 500 kb/s units (+ 0x80) */ 1513 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000); 1514 /* Add new value to event */ 1515 current_val = 1516 iwe_stream_add_value(info, current_ev, current_val, end_buf, 1517 &iwe, IW_EV_PARAM_LEN); 1518 } 1519 /* Check if we added any event */ 1520 if ((current_val - current_ev) > IW_EV_LCP_LEN) 1521 current_ev = current_val; 1522 1523 #define GENERIC_INFO_ELEM_ID 0xdd 1524 #define RSN_INFO_ELEM_ID 0x30 1525 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) { 1526 pbuf = &buf0[0]; 1527 memset(&iwe, 0, sizeof(iwe)); 1528 iwe.cmd = IWEVCUSTOM; 1529 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1); 1530 iwe.u.data.length += sizeof(rsn_leader) - 1; 1531 pbuf += sizeof(rsn_leader) - 1; 1532 1533 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id); 1534 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size); 1535 iwe.u.data.length += 4; 1536 1537 for (i = 0; i < ap->rsn_ie.size; i++) 1538 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]); 1539 iwe.u.data.length += (ap->rsn_ie.size) * 2; 1540 1541 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size); 1542 1543 current_ev = 1544 iwe_stream_add_point(info, current_ev, end_buf, &iwe, 1545 &buf0[0]); 1546 } 1547 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) { 1548 pbuf = &buf1[0]; 1549 memset(&iwe, 0, sizeof(iwe)); 1550 iwe.cmd = IWEVCUSTOM; 1551 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1); 1552 iwe.u.data.length += sizeof(wpa_leader) - 1; 1553 pbuf += sizeof(wpa_leader) - 1; 1554 1555 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id); 1556 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size); 1557 iwe.u.data.length += 4; 1558 1559 for (i = 0; i < ap->wpa_ie.size; i++) 1560 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]); 1561 iwe.u.data.length += (ap->wpa_ie.size) * 2; 1562 1563 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size); 1564 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length); 1565 1566 current_ev = 1567 iwe_stream_add_point(info, current_ev, end_buf, &iwe, 1568 &buf1[0]); 1569 } 1570 1571 /* The other data in the scan result are not really 1572 * interesting, so for now drop it - Jean II */ 1573 return current_ev; 1574 } 1575 1576 /*------------------------------------------------------------------*/ 1577 /* Wireless Handler : Read Scan Results */ 1578 static int ks_wlan_get_scan(struct net_device *dev, 1579 struct iw_request_info *info, struct iw_point *dwrq, 1580 char *extra) 1581 { 1582 struct ks_wlan_private *priv = 1583 (struct ks_wlan_private *)netdev_priv(dev); 1584 int i; 1585 char *current_ev = extra; 1586 1587 DPRINTK(2, "\n"); 1588 1589 if (priv->sleep_mode == SLP_SLEEP) 1590 return -EPERM; 1591 /* for SLEEP MODE */ 1592 if (priv->sme_i.sme_flag & SME_AP_SCAN) { 1593 DPRINTK(2, "flag AP_SCAN\n"); 1594 return -EAGAIN; 1595 } 1596 1597 if (priv->aplist.size == 0) { 1598 /* Client error, no scan results... 1599 * The caller need to restart the scan. */ 1600 DPRINTK(2, "aplist 0\n"); 1601 return -ENODATA; 1602 } 1603 #if 0 1604 /* current connect ap */ 1605 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) { 1606 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) { 1607 dwrq->length = 0; 1608 return -E2BIG; 1609 } 1610 current_ev = ks_wlan_translate_scan(dev, current_ev, 1611 // extra + IW_SCAN_MAX_DATA, 1612 extra + dwrq->length, 1613 &(priv->current_ap)); 1614 } 1615 #endif 1616 /* Read and parse all entries */ 1617 for (i = 0; i < priv->aplist.size; i++) { 1618 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) { 1619 dwrq->length = 0; 1620 return -E2BIG; 1621 } 1622 /* Translate to WE format this entry */ 1623 current_ev = ks_wlan_translate_scan(dev, info, current_ev, 1624 // extra + IW_SCAN_MAX_DATA, 1625 extra + dwrq->length, 1626 &(priv->aplist.ap[i])); 1627 } 1628 /* Length of data */ 1629 dwrq->length = (current_ev - extra); 1630 dwrq->flags = 0; 1631 1632 return 0; 1633 } 1634 1635 /*------------------------------------------------------------------*/ 1636 /* Commit handler : called after a bunch of SET operations */ 1637 static int ks_wlan_config_commit(struct net_device *dev, 1638 struct iw_request_info *info, void *zwrq, 1639 char *extra) 1640 { 1641 struct ks_wlan_private *priv = 1642 (struct ks_wlan_private *)netdev_priv(dev); 1643 1644 if (!priv->need_commit) 1645 return 0; 1646 1647 ks_wlan_setup_parameter(priv, priv->need_commit); 1648 priv->need_commit = 0; 1649 return 0; 1650 } 1651 1652 /*------------------------------------------------------------------*/ 1653 /* Wireless handler : set association ie params */ 1654 static int ks_wlan_set_genie(struct net_device *dev, 1655 struct iw_request_info *info, 1656 struct iw_point *dwrq, char *extra) 1657 { 1658 struct ks_wlan_private *priv = 1659 (struct ks_wlan_private *)netdev_priv(dev); 1660 1661 DPRINTK(2, "\n"); 1662 1663 if (priv->sleep_mode == SLP_SLEEP) 1664 return -EPERM; 1665 /* for SLEEP MODE */ 1666 return 0; 1667 // return -EOPNOTSUPP; 1668 } 1669 1670 /*------------------------------------------------------------------*/ 1671 /* Wireless handler : set authentication mode params */ 1672 static int ks_wlan_set_auth_mode(struct net_device *dev, 1673 struct iw_request_info *info, 1674 struct iw_param *vwrq, char *extra) 1675 { 1676 struct ks_wlan_private *priv = 1677 (struct ks_wlan_private *)netdev_priv(dev); 1678 int index = (vwrq->flags & IW_AUTH_INDEX); 1679 int value = vwrq->value; 1680 1681 DPRINTK(2, "index=%d:value=%08X\n", index, value); 1682 1683 if (priv->sleep_mode == SLP_SLEEP) 1684 return -EPERM; 1685 /* for SLEEP MODE */ 1686 switch (index) { 1687 case IW_AUTH_WPA_VERSION: /* 0 */ 1688 switch (value) { 1689 case IW_AUTH_WPA_VERSION_DISABLED: 1690 priv->wpa.version = value; 1691 if (priv->wpa.rsn_enabled) 1692 priv->wpa.rsn_enabled = 0; 1693 priv->need_commit |= SME_RSN; 1694 break; 1695 case IW_AUTH_WPA_VERSION_WPA: 1696 case IW_AUTH_WPA_VERSION_WPA2: 1697 priv->wpa.version = value; 1698 if (!(priv->wpa.rsn_enabled)) 1699 priv->wpa.rsn_enabled = 1; 1700 priv->need_commit |= SME_RSN; 1701 break; 1702 default: 1703 return -EOPNOTSUPP; 1704 } 1705 break; 1706 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */ 1707 switch (value) { 1708 case IW_AUTH_CIPHER_NONE: 1709 if (priv->reg.privacy_invoked) { 1710 priv->reg.privacy_invoked = 0x00; 1711 priv->need_commit |= SME_WEP_FLAG; 1712 } 1713 break; 1714 case IW_AUTH_CIPHER_WEP40: 1715 case IW_AUTH_CIPHER_TKIP: 1716 case IW_AUTH_CIPHER_CCMP: 1717 case IW_AUTH_CIPHER_WEP104: 1718 if (!priv->reg.privacy_invoked) { 1719 priv->reg.privacy_invoked = 0x01; 1720 priv->need_commit |= SME_WEP_FLAG; 1721 } 1722 priv->wpa.pairwise_suite = value; 1723 priv->need_commit |= SME_RSN_UNICAST; 1724 break; 1725 default: 1726 return -EOPNOTSUPP; 1727 } 1728 break; 1729 case IW_AUTH_CIPHER_GROUP: /* 2 */ 1730 switch (value) { 1731 case IW_AUTH_CIPHER_NONE: 1732 if (priv->reg.privacy_invoked) { 1733 priv->reg.privacy_invoked = 0x00; 1734 priv->need_commit |= SME_WEP_FLAG; 1735 } 1736 break; 1737 case IW_AUTH_CIPHER_WEP40: 1738 case IW_AUTH_CIPHER_TKIP: 1739 case IW_AUTH_CIPHER_CCMP: 1740 case IW_AUTH_CIPHER_WEP104: 1741 if (!priv->reg.privacy_invoked) { 1742 priv->reg.privacy_invoked = 0x01; 1743 priv->need_commit |= SME_WEP_FLAG; 1744 } 1745 priv->wpa.group_suite = value; 1746 priv->need_commit |= SME_RSN_MULTICAST; 1747 break; 1748 default: 1749 return -EOPNOTSUPP; 1750 } 1751 break; 1752 case IW_AUTH_KEY_MGMT: /* 3 */ 1753 switch (value) { 1754 case IW_AUTH_KEY_MGMT_802_1X: 1755 case IW_AUTH_KEY_MGMT_PSK: 1756 case 0: /* NONE or 802_1X_NO_WPA */ 1757 case 4: /* WPA_NONE */ 1758 priv->wpa.key_mgmt_suite = value; 1759 priv->need_commit |= SME_RSN_AUTH; 1760 break; 1761 default: 1762 return -EOPNOTSUPP; 1763 } 1764 break; 1765 case IW_AUTH_80211_AUTH_ALG: /* 6 */ 1766 switch (value) { 1767 case IW_AUTH_ALG_OPEN_SYSTEM: 1768 priv->wpa.auth_alg = value; 1769 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM; 1770 break; 1771 case IW_AUTH_ALG_SHARED_KEY: 1772 priv->wpa.auth_alg = value; 1773 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY; 1774 break; 1775 case IW_AUTH_ALG_LEAP: 1776 default: 1777 return -EOPNOTSUPP; 1778 } 1779 priv->need_commit |= SME_MODE_SET; 1780 break; 1781 case IW_AUTH_WPA_ENABLED: /* 7 */ 1782 priv->wpa.wpa_enabled = value; 1783 break; 1784 case IW_AUTH_PRIVACY_INVOKED: /* 10 */ 1785 if ((value && !priv->reg.privacy_invoked) || 1786 (!value && priv->reg.privacy_invoked)) { 1787 priv->reg.privacy_invoked = value ? 0x01 : 0x00; 1788 priv->need_commit |= SME_WEP_FLAG; 1789 } 1790 break; 1791 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */ 1792 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */ 1793 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */ 1794 case IW_AUTH_ROAMING_CONTROL: /* 9 */ 1795 default: 1796 break; 1797 } 1798 1799 /* return -EINPROGRESS; */ 1800 if (priv->need_commit) { 1801 ks_wlan_setup_parameter(priv, priv->need_commit); 1802 priv->need_commit = 0; 1803 } 1804 return 0; 1805 } 1806 1807 /*------------------------------------------------------------------*/ 1808 /* Wireless handler : get authentication mode params */ 1809 static int ks_wlan_get_auth_mode(struct net_device *dev, 1810 struct iw_request_info *info, 1811 struct iw_param *vwrq, char *extra) 1812 { 1813 struct ks_wlan_private *priv = 1814 (struct ks_wlan_private *)netdev_priv(dev); 1815 int index = (vwrq->flags & IW_AUTH_INDEX); 1816 1817 DPRINTK(2, "index=%d\n", index); 1818 1819 if (priv->sleep_mode == SLP_SLEEP) 1820 return -EPERM; 1821 1822 /* for SLEEP MODE */ 1823 /* WPA (not used ?? wpa_supplicant) */ 1824 switch (index) { 1825 case IW_AUTH_WPA_VERSION: 1826 vwrq->value = priv->wpa.version; 1827 break; 1828 case IW_AUTH_CIPHER_PAIRWISE: 1829 vwrq->value = priv->wpa.pairwise_suite; 1830 break; 1831 case IW_AUTH_CIPHER_GROUP: 1832 vwrq->value = priv->wpa.group_suite; 1833 break; 1834 case IW_AUTH_KEY_MGMT: 1835 vwrq->value = priv->wpa.key_mgmt_suite; 1836 break; 1837 case IW_AUTH_80211_AUTH_ALG: 1838 vwrq->value = priv->wpa.auth_alg; 1839 break; 1840 case IW_AUTH_WPA_ENABLED: 1841 vwrq->value = priv->wpa.rsn_enabled; 1842 break; 1843 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */ 1844 case IW_AUTH_TKIP_COUNTERMEASURES: 1845 case IW_AUTH_DROP_UNENCRYPTED: 1846 default: 1847 /* return -EOPNOTSUPP; */ 1848 break; 1849 } 1850 return 0; 1851 } 1852 1853 /*------------------------------------------------------------------*/ 1854 /* Wireless Handler : set encoding token & mode (WPA)*/ 1855 static int ks_wlan_set_encode_ext(struct net_device *dev, 1856 struct iw_request_info *info, 1857 struct iw_point *dwrq, char *extra) 1858 { 1859 struct ks_wlan_private *priv = 1860 (struct ks_wlan_private *)netdev_priv(dev); 1861 struct iw_encode_ext *enc; 1862 int index = dwrq->flags & IW_ENCODE_INDEX; 1863 unsigned int commit = 0; 1864 1865 enc = (struct iw_encode_ext *)extra; 1866 1867 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags, 1868 enc->ext_flags); 1869 1870 if (priv->sleep_mode == SLP_SLEEP) 1871 return -EPERM; 1872 1873 /* for SLEEP MODE */ 1874 if (index < 1 || index > 4) 1875 return -EINVAL; 1876 else 1877 index--; 1878 1879 if (dwrq->flags & IW_ENCODE_DISABLED) 1880 priv->wpa.key[index].key_len = 0; 1881 1882 if (enc) { 1883 priv->wpa.key[index].ext_flags = enc->ext_flags; 1884 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { 1885 priv->wpa.txkey = index; 1886 commit |= SME_WEP_INDEX; 1887 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { 1888 memcpy(&priv->wpa.key[index].rx_seq[0], 1889 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE); 1890 } 1891 1892 memcpy(&priv->wpa.key[index].addr.sa_data[0], 1893 &enc->addr.sa_data[0], ETH_ALEN); 1894 1895 switch (enc->alg) { 1896 case IW_ENCODE_ALG_NONE: 1897 if (priv->reg.privacy_invoked) { 1898 priv->reg.privacy_invoked = 0x00; 1899 commit |= SME_WEP_FLAG; 1900 } 1901 priv->wpa.key[index].key_len = 0; 1902 1903 break; 1904 case IW_ENCODE_ALG_WEP: 1905 case IW_ENCODE_ALG_CCMP: 1906 if (!priv->reg.privacy_invoked) { 1907 priv->reg.privacy_invoked = 0x01; 1908 commit |= SME_WEP_FLAG; 1909 } 1910 if (enc->key_len) { 1911 memcpy(&priv->wpa.key[index].key_val[0], 1912 &enc->key[0], enc->key_len); 1913 priv->wpa.key[index].key_len = enc->key_len; 1914 commit |= (SME_WEP_VAL1 << index); 1915 } 1916 break; 1917 case IW_ENCODE_ALG_TKIP: 1918 if (!priv->reg.privacy_invoked) { 1919 priv->reg.privacy_invoked = 0x01; 1920 commit |= SME_WEP_FLAG; 1921 } 1922 if (enc->key_len == 32) { 1923 memcpy(&priv->wpa.key[index].key_val[0], 1924 &enc->key[0], enc->key_len - 16); 1925 priv->wpa.key[index].key_len = 1926 enc->key_len - 16; 1927 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */ 1928 memcpy(&priv->wpa.key[index]. 1929 tx_mic_key[0], &enc->key[16], 8); 1930 memcpy(&priv->wpa.key[index]. 1931 rx_mic_key[0], &enc->key[16], 8); 1932 } else { 1933 memcpy(&priv->wpa.key[index]. 1934 tx_mic_key[0], &enc->key[16], 8); 1935 memcpy(&priv->wpa.key[index]. 1936 rx_mic_key[0], &enc->key[24], 8); 1937 } 1938 commit |= (SME_WEP_VAL1 << index); 1939 } 1940 break; 1941 default: 1942 return -EINVAL; 1943 } 1944 priv->wpa.key[index].alg = enc->alg; 1945 } else 1946 return -EINVAL; 1947 1948 if (commit) { 1949 if (commit & SME_WEP_INDEX) 1950 hostif_sme_enqueue(priv, SME_SET_TXKEY); 1951 if (commit & SME_WEP_VAL_MASK) 1952 hostif_sme_enqueue(priv, SME_SET_KEY1 + index); 1953 if (commit & SME_WEP_FLAG) 1954 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST); 1955 } 1956 1957 return 0; 1958 } 1959 1960 /*------------------------------------------------------------------*/ 1961 /* Wireless Handler : get encoding token & mode (WPA)*/ 1962 static int ks_wlan_get_encode_ext(struct net_device *dev, 1963 struct iw_request_info *info, 1964 struct iw_point *dwrq, char *extra) 1965 { 1966 struct ks_wlan_private *priv = 1967 (struct ks_wlan_private *)netdev_priv(dev); 1968 1969 if (priv->sleep_mode == SLP_SLEEP) 1970 return -EPERM; 1971 1972 /* for SLEEP MODE */ 1973 /* WPA (not used ?? wpa_supplicant) 1974 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 1975 struct iw_encode_ext *enc; 1976 enc = (struct iw_encode_ext *)extra; 1977 int index = dwrq->flags & IW_ENCODE_INDEX; 1978 WPA (not used ?? wpa_supplicant) */ 1979 return 0; 1980 } 1981 1982 /*------------------------------------------------------------------*/ 1983 /* Wireless Handler : PMKSA cache operation (WPA2) */ 1984 static int ks_wlan_set_pmksa(struct net_device *dev, 1985 struct iw_request_info *info, 1986 struct iw_point *dwrq, char *extra) 1987 { 1988 struct ks_wlan_private *priv = 1989 (struct ks_wlan_private *)netdev_priv(dev); 1990 struct iw_pmksa *pmksa; 1991 int i; 1992 struct pmk_t *pmk; 1993 struct list_head *ptr; 1994 1995 DPRINTK(2, "\n"); 1996 1997 if (priv->sleep_mode == SLP_SLEEP) 1998 return -EPERM; 1999 2000 /* for SLEEP MODE */ 2001 if (!extra) 2002 return -EINVAL; 2003 2004 pmksa = (struct iw_pmksa *)extra; 2005 DPRINTK(2, "cmd=%d\n", pmksa->cmd); 2006 2007 switch (pmksa->cmd) { 2008 case IW_PMKSA_ADD: 2009 if (list_empty(&priv->pmklist.head)) { /* new list */ 2010 for (i = 0; i < PMK_LIST_MAX; i++) { 2011 pmk = &priv->pmklist.pmk[i]; 2012 if (!memcmp 2013 ("\x00\x00\x00\x00\x00\x00", pmk->bssid, 2014 ETH_ALEN)) 2015 break; 2016 } 2017 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); 2018 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); 2019 list_add(&pmk->list, &priv->pmklist.head); 2020 priv->pmklist.size++; 2021 } else { /* search cache data */ 2022 list_for_each(ptr, &priv->pmklist.head) { 2023 pmk = list_entry(ptr, struct pmk_t, list); 2024 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */ 2025 memcpy(pmk->pmkid, pmksa->pmkid, 2026 IW_PMKID_LEN); 2027 list_move(&pmk->list, 2028 &priv->pmklist.head); 2029 break; 2030 } 2031 } 2032 if (ptr == &priv->pmklist.head) { /* not find address. */ 2033 if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */ 2034 for (i = 0; i < PMK_LIST_MAX; i++) { 2035 pmk = &priv->pmklist.pmk[i]; 2036 if (!memcmp 2037 ("\x00\x00\x00\x00\x00\x00", 2038 pmk->bssid, ETH_ALEN)) 2039 break; 2040 } 2041 memcpy(pmk->bssid, pmksa->bssid.sa_data, 2042 ETH_ALEN); 2043 memcpy(pmk->pmkid, pmksa->pmkid, 2044 IW_PMKID_LEN); 2045 list_add(&pmk->list, 2046 &priv->pmklist.head); 2047 priv->pmklist.size++; 2048 } else { /* overwrite old cache data */ 2049 pmk = 2050 list_entry(priv->pmklist.head.prev, 2051 struct pmk_t, list); 2052 memcpy(pmk->bssid, pmksa->bssid.sa_data, 2053 ETH_ALEN); 2054 memcpy(pmk->pmkid, pmksa->pmkid, 2055 IW_PMKID_LEN); 2056 list_move(&pmk->list, 2057 &priv->pmklist.head); 2058 } 2059 } 2060 } 2061 break; 2062 case IW_PMKSA_REMOVE: 2063 if (list_empty(&priv->pmklist.head)) { /* list empty */ 2064 return -EINVAL; 2065 } else { /* search cache data */ 2066 list_for_each(ptr, &priv->pmklist.head) { 2067 pmk = list_entry(ptr, struct pmk_t, list); 2068 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */ 2069 eth_zero_addr(pmk->bssid); 2070 memset(pmk->pmkid, 0, IW_PMKID_LEN); 2071 list_del_init(&pmk->list); 2072 break; 2073 } 2074 } 2075 if (ptr == &priv->pmklist.head) { /* not find address. */ 2076 return 0; 2077 } 2078 } 2079 break; 2080 case IW_PMKSA_FLUSH: 2081 memset(&(priv->pmklist), 0, sizeof(priv->pmklist)); 2082 INIT_LIST_HEAD(&priv->pmklist.head); 2083 for (i = 0; i < PMK_LIST_MAX; i++) 2084 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list); 2085 break; 2086 default: 2087 return -EINVAL; 2088 } 2089 2090 hostif_sme_enqueue(priv, SME_SET_PMKSA); 2091 return 0; 2092 } 2093 2094 static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev) 2095 { 2096 struct ks_wlan_private *priv = 2097 (struct ks_wlan_private *)netdev_priv(dev); 2098 struct iw_statistics *wstats = &priv->wstats; 2099 2100 if (!atomic_read(&update_phyinfo)) { 2101 if (priv->dev_state < DEVICE_STATE_READY) 2102 return NULL; /* not finished initialize */ 2103 else 2104 return wstats; 2105 } 2106 2107 /* Packets discarded in the wireless adapter due to wireless 2108 * specific problems */ 2109 wstats->discard.nwid = 0; /* Rx invalid nwid */ 2110 wstats->discard.code = 0; /* Rx invalid crypt */ 2111 wstats->discard.fragment = 0; /* Rx invalid frag */ 2112 wstats->discard.retries = 0; /* Tx excessive retries */ 2113 wstats->discard.misc = 0; /* Invalid misc */ 2114 wstats->miss.beacon = 0; /* Missed beacon */ 2115 2116 return wstats; 2117 } 2118 2119 /*------------------------------------------------------------------*/ 2120 /* Private handler : set stop request */ 2121 static int ks_wlan_set_stop_request(struct net_device *dev, 2122 struct iw_request_info *info, __u32 *uwrq, 2123 char *extra) 2124 { 2125 struct ks_wlan_private *priv = 2126 (struct ks_wlan_private *)netdev_priv(dev); 2127 DPRINTK(2, "\n"); 2128 2129 if (priv->sleep_mode == SLP_SLEEP) 2130 return -EPERM; 2131 2132 /* for SLEEP MODE */ 2133 if (!(*uwrq)) 2134 return -EINVAL; 2135 2136 hostif_sme_enqueue(priv, SME_STOP_REQUEST); 2137 return 0; 2138 } 2139 2140 /*------------------------------------------------------------------*/ 2141 /* Wireless Handler : set MLME */ 2142 #include <linux/ieee80211.h> 2143 static int ks_wlan_set_mlme(struct net_device *dev, 2144 struct iw_request_info *info, struct iw_point *dwrq, 2145 char *extra) 2146 { 2147 struct ks_wlan_private *priv = 2148 (struct ks_wlan_private *)netdev_priv(dev); 2149 struct iw_mlme *mlme = (struct iw_mlme *)extra; 2150 __u32 mode; 2151 2152 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code); 2153 2154 if (priv->sleep_mode == SLP_SLEEP) 2155 return -EPERM; 2156 2157 /* for SLEEP MODE */ 2158 switch (mlme->cmd) { 2159 case IW_MLME_DEAUTH: 2160 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) 2161 return 0; 2162 case IW_MLME_DISASSOC: 2163 mode = 1; 2164 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL); 2165 default: 2166 return -EOPNOTSUPP; /* Not Support */ 2167 } 2168 } 2169 2170 /*------------------------------------------------------------------*/ 2171 /* Private handler : get firemware version */ 2172 static int ks_wlan_get_firmware_version(struct net_device *dev, 2173 struct iw_request_info *info, 2174 struct iw_point *dwrq, char *extra) 2175 { 2176 struct ks_wlan_private *priv = 2177 (struct ks_wlan_private *)netdev_priv(dev); 2178 strcpy(extra, &(priv->firmware_version[0])); 2179 dwrq->length = priv->version_size + 1; 2180 return 0; 2181 } 2182 2183 #if 0 2184 /*------------------------------------------------------------------*/ 2185 /* Private handler : set force disconnect status */ 2186 static int ks_wlan_set_detach(struct net_device *dev, 2187 struct iw_request_info *info, __u32 *uwrq, 2188 char *extra) 2189 { 2190 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2191 2192 if (priv->sleep_mode == SLP_SLEEP) 2193 return -EPERM; 2194 2195 /* for SLEEP MODE */ 2196 if (*uwrq == CONNECT_STATUS) { /* 0 */ 2197 priv->connect_status &= ~FORCE_DISCONNECT; 2198 if ((priv->connect_status & CONNECT_STATUS_MASK) == 2199 CONNECT_STATUS) 2200 netif_carrier_on(dev); 2201 } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */ 2202 priv->connect_status |= FORCE_DISCONNECT; 2203 netif_carrier_off(dev); 2204 } else 2205 return -EINVAL; 2206 return 0; 2207 } 2208 2209 /*------------------------------------------------------------------*/ 2210 /* Private handler : get force disconnect status */ 2211 static int ks_wlan_get_detach(struct net_device *dev, 2212 struct iw_request_info *info, __u32 *uwrq, 2213 char *extra) 2214 { 2215 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2216 2217 if (priv->sleep_mode == SLP_SLEEP) 2218 return -EPERM; 2219 2220 /* for SLEEP MODE */ 2221 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0); 2222 return 0; 2223 } 2224 2225 /*------------------------------------------------------------------*/ 2226 /* Private handler : get connect status */ 2227 static int ks_wlan_get_connect(struct net_device *dev, 2228 struct iw_request_info *info, __u32 *uwrq, 2229 char *extra) 2230 { 2231 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2232 2233 if (priv->sleep_mode == SLP_SLEEP) 2234 return -EPERM; 2235 2236 /* for SLEEP MODE */ 2237 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK); 2238 return 0; 2239 } 2240 #endif 2241 2242 /*------------------------------------------------------------------*/ 2243 /* Private handler : set preamble */ 2244 static int ks_wlan_set_preamble(struct net_device *dev, 2245 struct iw_request_info *info, __u32 *uwrq, 2246 char *extra) 2247 { 2248 struct ks_wlan_private *priv = 2249 (struct ks_wlan_private *)netdev_priv(dev); 2250 2251 if (priv->sleep_mode == SLP_SLEEP) 2252 return -EPERM; 2253 2254 /* for SLEEP MODE */ 2255 if (*uwrq == LONG_PREAMBLE) { /* 0 */ 2256 priv->reg.preamble = LONG_PREAMBLE; 2257 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */ 2258 priv->reg.preamble = SHORT_PREAMBLE; 2259 } else 2260 return -EINVAL; 2261 2262 priv->need_commit |= SME_MODE_SET; 2263 return -EINPROGRESS; /* Call commit handler */ 2264 } 2265 2266 /*------------------------------------------------------------------*/ 2267 /* Private handler : get preamble */ 2268 static int ks_wlan_get_preamble(struct net_device *dev, 2269 struct iw_request_info *info, __u32 *uwrq, 2270 char *extra) 2271 { 2272 struct ks_wlan_private *priv = 2273 (struct ks_wlan_private *)netdev_priv(dev); 2274 2275 if (priv->sleep_mode == SLP_SLEEP) 2276 return -EPERM; 2277 2278 /* for SLEEP MODE */ 2279 *uwrq = priv->reg.preamble; 2280 return 0; 2281 } 2282 2283 /*------------------------------------------------------------------*/ 2284 /* Private handler : set power save mode */ 2285 static int ks_wlan_set_powermgt(struct net_device *dev, 2286 struct iw_request_info *info, __u32 *uwrq, 2287 char *extra) 2288 { 2289 struct ks_wlan_private *priv = 2290 (struct ks_wlan_private *)netdev_priv(dev); 2291 2292 if (priv->sleep_mode == SLP_SLEEP) 2293 return -EPERM; 2294 2295 /* for SLEEP MODE */ 2296 if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */ 2297 priv->reg.powermgt = POWMGT_ACTIVE_MODE; 2298 } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */ 2299 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) 2300 priv->reg.powermgt = POWMGT_SAVE1_MODE; 2301 else 2302 return -EINVAL; 2303 } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */ 2304 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) 2305 priv->reg.powermgt = POWMGT_SAVE2_MODE; 2306 else 2307 return -EINVAL; 2308 } else 2309 return -EINVAL; 2310 2311 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST); 2312 2313 return 0; 2314 } 2315 2316 /*------------------------------------------------------------------*/ 2317 /* Private handler : get power save made */ 2318 static int ks_wlan_get_powermgt(struct net_device *dev, 2319 struct iw_request_info *info, __u32 *uwrq, 2320 char *extra) 2321 { 2322 struct ks_wlan_private *priv = 2323 (struct ks_wlan_private *)netdev_priv(dev); 2324 2325 if (priv->sleep_mode == SLP_SLEEP) 2326 return -EPERM; 2327 2328 /* for SLEEP MODE */ 2329 *uwrq = priv->reg.powermgt; 2330 return 0; 2331 } 2332 2333 /*------------------------------------------------------------------*/ 2334 /* Private handler : set scan type */ 2335 static int ks_wlan_set_scan_type(struct net_device *dev, 2336 struct iw_request_info *info, __u32 *uwrq, 2337 char *extra) 2338 { 2339 struct ks_wlan_private *priv = 2340 (struct ks_wlan_private *)netdev_priv(dev); 2341 2342 if (priv->sleep_mode == SLP_SLEEP) 2343 return -EPERM; 2344 /* for SLEEP MODE */ 2345 if (*uwrq == ACTIVE_SCAN) { /* 0 */ 2346 priv->reg.scan_type = ACTIVE_SCAN; 2347 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */ 2348 priv->reg.scan_type = PASSIVE_SCAN; 2349 } else 2350 return -EINVAL; 2351 2352 return 0; 2353 } 2354 2355 /*------------------------------------------------------------------*/ 2356 /* Private handler : get scan type */ 2357 static int ks_wlan_get_scan_type(struct net_device *dev, 2358 struct iw_request_info *info, __u32 *uwrq, 2359 char *extra) 2360 { 2361 struct ks_wlan_private *priv = 2362 (struct ks_wlan_private *)netdev_priv(dev); 2363 2364 if (priv->sleep_mode == SLP_SLEEP) 2365 return -EPERM; 2366 /* for SLEEP MODE */ 2367 *uwrq = priv->reg.scan_type; 2368 return 0; 2369 } 2370 2371 #if 0 2372 /*------------------------------------------------------------------*/ 2373 /* Private handler : write raw data to device */ 2374 static int ks_wlan_data_write(struct net_device *dev, 2375 struct iw_request_info *info, 2376 struct iw_point *dwrq, char *extra) 2377 { 2378 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2379 unsigned char *wbuff = NULL; 2380 2381 if (priv->sleep_mode == SLP_SLEEP) 2382 return -EPERM; 2383 /* for SLEEP MODE */ 2384 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC); 2385 if (!wbuff) 2386 return -EFAULT; 2387 memcpy(wbuff, extra, dwrq->length); 2388 2389 /* write to device */ 2390 ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL); 2391 2392 return 0; 2393 } 2394 2395 /*------------------------------------------------------------------*/ 2396 /* Private handler : read raw data form device */ 2397 static int ks_wlan_data_read(struct net_device *dev, 2398 struct iw_request_info *info, 2399 struct iw_point *dwrq, char *extra) 2400 { 2401 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2402 unsigned short read_length; 2403 2404 if (priv->sleep_mode == SLP_SLEEP) 2405 return -EPERM; 2406 /* for SLEEP MODE */ 2407 if (!atomic_read(&priv->event_count)) { 2408 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */ 2409 read_length = 4; 2410 memset(extra, 0xff, read_length); 2411 dwrq->length = read_length; 2412 return 0; 2413 } 2414 read_length = 0; 2415 memset(extra, 0, 1); 2416 dwrq->length = 0; 2417 return 0; 2418 } 2419 2420 if (atomic_read(&priv->event_count) > 0) 2421 atomic_dec(&priv->event_count); 2422 2423 spin_lock(&priv->dev_read_lock); /* request spin lock */ 2424 2425 /* Copy length max size 0x07ff */ 2426 if (priv->dev_size[priv->dev_count] > 2047) 2427 read_length = 2047; 2428 else 2429 read_length = priv->dev_size[priv->dev_count]; 2430 2431 /* Copy data */ 2432 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length); 2433 2434 spin_unlock(&priv->dev_read_lock); /* release spin lock */ 2435 2436 /* Initialize */ 2437 priv->dev_data[priv->dev_count] = 0; 2438 priv->dev_size[priv->dev_count] = 0; 2439 2440 priv->dev_count++; 2441 if (priv->dev_count == DEVICE_STOCK_COUNT) 2442 priv->dev_count = 0; 2443 2444 /* Set read size */ 2445 dwrq->length = read_length; 2446 2447 return 0; 2448 } 2449 #endif 2450 2451 #if 0 2452 /*------------------------------------------------------------------*/ 2453 /* Private handler : get wep string */ 2454 #define WEP_ASCII_BUFF_SIZE (17 + 64 * 4 + 1) 2455 static int ks_wlan_get_wep_ascii(struct net_device *dev, 2456 struct iw_request_info *info, 2457 struct iw_point *dwrq, char *extra) 2458 { 2459 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2460 int i, j, len = 0; 2461 char tmp[WEP_ASCII_BUFF_SIZE]; 2462 2463 if (priv->sleep_mode == SLP_SLEEP) 2464 return -EPERM; 2465 /* for SLEEP MODE */ 2466 strcpy(tmp, " WEP keys ASCII \n"); 2467 len += strlen(" WEP keys ASCII \n"); 2468 2469 for (i = 0; i < 4; i++) { 2470 strcpy(tmp + len, "\t["); 2471 len += strlen("\t["); 2472 tmp[len] = '1' + i; 2473 len++; 2474 strcpy(tmp + len, "] "); 2475 len += strlen("] "); 2476 if (priv->reg.wep_key[i].size) { 2477 strcpy(tmp + len, 2478 (priv->reg.wep_key[i].size < 2479 6 ? "(40bits) [" : "(104bits) [")); 2480 len += 2481 strlen((priv->reg.wep_key[i].size < 2482 6 ? "(40bits) [" : "(104bits) [")); 2483 for (j = 0; j < priv->reg.wep_key[i].size; j++, len++) 2484 tmp[len] = 2485 (isprint(priv->reg.wep_key[i].val[j]) ? 2486 priv->reg.wep_key[i].val[j] : ' '); 2487 2488 strcpy(tmp + len, "]\n"); 2489 len += strlen("]\n"); 2490 } else { 2491 strcpy(tmp + len, "off\n"); 2492 len += strlen("off\n"); 2493 } 2494 } 2495 2496 memcpy(extra, tmp, len); 2497 dwrq->length = len + 1; 2498 return 0; 2499 } 2500 #endif 2501 2502 /*------------------------------------------------------------------*/ 2503 /* Private handler : set beacon lost count */ 2504 static int ks_wlan_set_beacon_lost(struct net_device *dev, 2505 struct iw_request_info *info, __u32 *uwrq, 2506 char *extra) 2507 { 2508 struct ks_wlan_private *priv = 2509 (struct ks_wlan_private *)netdev_priv(dev); 2510 2511 if (priv->sleep_mode == SLP_SLEEP) 2512 return -EPERM; 2513 /* for SLEEP MODE */ 2514 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) 2515 priv->reg.beacon_lost_count = *uwrq; 2516 else 2517 return -EINVAL; 2518 2519 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) { 2520 priv->need_commit |= SME_MODE_SET; 2521 return -EINPROGRESS; /* Call commit handler */ 2522 } else 2523 return 0; 2524 } 2525 2526 /*------------------------------------------------------------------*/ 2527 /* Private handler : get beacon lost count */ 2528 static int ks_wlan_get_beacon_lost(struct net_device *dev, 2529 struct iw_request_info *info, __u32 *uwrq, 2530 char *extra) 2531 { 2532 struct ks_wlan_private *priv = 2533 (struct ks_wlan_private *)netdev_priv(dev); 2534 2535 if (priv->sleep_mode == SLP_SLEEP) 2536 return -EPERM; 2537 /* for SLEEP MODE */ 2538 *uwrq = priv->reg.beacon_lost_count; 2539 return 0; 2540 } 2541 2542 /*------------------------------------------------------------------*/ 2543 /* Private handler : set phy type */ 2544 static int ks_wlan_set_phy_type(struct net_device *dev, 2545 struct iw_request_info *info, __u32 *uwrq, 2546 char *extra) 2547 { 2548 struct ks_wlan_private *priv = 2549 (struct ks_wlan_private *)netdev_priv(dev); 2550 2551 if (priv->sleep_mode == SLP_SLEEP) 2552 return -EPERM; 2553 /* for SLEEP MODE */ 2554 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */ 2555 priv->reg.phy_type = D_11B_ONLY_MODE; 2556 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */ 2557 priv->reg.phy_type = D_11G_ONLY_MODE; 2558 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */ 2559 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE; 2560 } else 2561 return -EINVAL; 2562 2563 priv->need_commit |= SME_MODE_SET; 2564 return -EINPROGRESS; /* Call commit handler */ 2565 } 2566 2567 /*------------------------------------------------------------------*/ 2568 /* Private handler : get phy type */ 2569 static int ks_wlan_get_phy_type(struct net_device *dev, 2570 struct iw_request_info *info, __u32 *uwrq, 2571 char *extra) 2572 { 2573 struct ks_wlan_private *priv = 2574 (struct ks_wlan_private *)netdev_priv(dev); 2575 2576 if (priv->sleep_mode == SLP_SLEEP) 2577 return -EPERM; 2578 /* for SLEEP MODE */ 2579 *uwrq = priv->reg.phy_type; 2580 return 0; 2581 } 2582 2583 /*------------------------------------------------------------------*/ 2584 /* Private handler : set cts mode */ 2585 static int ks_wlan_set_cts_mode(struct net_device *dev, 2586 struct iw_request_info *info, __u32 *uwrq, 2587 char *extra) 2588 { 2589 struct ks_wlan_private *priv = 2590 (struct ks_wlan_private *)netdev_priv(dev); 2591 2592 if (priv->sleep_mode == SLP_SLEEP) 2593 return -EPERM; 2594 /* for SLEEP MODE */ 2595 if (*uwrq == CTS_MODE_FALSE) { /* 0 */ 2596 priv->reg.cts_mode = CTS_MODE_FALSE; 2597 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */ 2598 if (priv->reg.phy_type == D_11G_ONLY_MODE || 2599 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) 2600 priv->reg.cts_mode = CTS_MODE_TRUE; 2601 else 2602 priv->reg.cts_mode = CTS_MODE_FALSE; 2603 } else 2604 return -EINVAL; 2605 2606 priv->need_commit |= SME_MODE_SET; 2607 return -EINPROGRESS; /* Call commit handler */ 2608 } 2609 2610 /*------------------------------------------------------------------*/ 2611 /* Private handler : get cts mode */ 2612 static int ks_wlan_get_cts_mode(struct net_device *dev, 2613 struct iw_request_info *info, __u32 *uwrq, 2614 char *extra) 2615 { 2616 struct ks_wlan_private *priv = 2617 (struct ks_wlan_private *)netdev_priv(dev); 2618 2619 if (priv->sleep_mode == SLP_SLEEP) 2620 return -EPERM; 2621 /* for SLEEP MODE */ 2622 *uwrq = priv->reg.cts_mode; 2623 return 0; 2624 } 2625 2626 /*------------------------------------------------------------------*/ 2627 /* Private handler : set sleep mode */ 2628 static int ks_wlan_set_sleep_mode(struct net_device *dev, 2629 struct iw_request_info *info, 2630 __u32 *uwrq, char *extra) 2631 { 2632 struct ks_wlan_private *priv = 2633 (struct ks_wlan_private *)netdev_priv(dev); 2634 2635 DPRINTK(2, "\n"); 2636 2637 if (*uwrq == SLP_SLEEP) { 2638 priv->sleep_mode = *uwrq; 2639 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode); 2640 2641 hostif_sme_enqueue(priv, SME_STOP_REQUEST); 2642 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST); 2643 2644 } else if (*uwrq == SLP_ACTIVE) { 2645 priv->sleep_mode = *uwrq; 2646 netdev_info(dev, "SET_SLEEP_MODE %d\n", priv->sleep_mode); 2647 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST); 2648 } else { 2649 netdev_err(dev, "SET_SLEEP_MODE %d errror\n", *uwrq); 2650 return -EINVAL; 2651 } 2652 2653 return 0; 2654 } 2655 2656 /*------------------------------------------------------------------*/ 2657 /* Private handler : get sleep mode */ 2658 static int ks_wlan_get_sleep_mode(struct net_device *dev, 2659 struct iw_request_info *info, 2660 __u32 *uwrq, char *extra) 2661 { 2662 struct ks_wlan_private *priv = 2663 (struct ks_wlan_private *)netdev_priv(dev); 2664 2665 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode); 2666 *uwrq = priv->sleep_mode; 2667 2668 return 0; 2669 } 2670 2671 #if 0 2672 /*------------------------------------------------------------------*/ 2673 /* Private handler : set phy information timer */ 2674 static int ks_wlan_set_phy_information_timer(struct net_device *dev, 2675 struct iw_request_info *info, 2676 __u32 *uwrq, char *extra) 2677 { 2678 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2679 2680 if (priv->sleep_mode == SLP_SLEEP) 2681 return -EPERM; 2682 /* for SLEEP MODE */ 2683 if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */ 2684 priv->reg.phy_info_timer = (uint16_t)*uwrq; 2685 else 2686 return -EINVAL; 2687 2688 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST); 2689 2690 return 0; 2691 } 2692 2693 /*------------------------------------------------------------------*/ 2694 /* Private handler : get phy information timer */ 2695 static int ks_wlan_get_phy_information_timer(struct net_device *dev, 2696 struct iw_request_info *info, 2697 __u32 *uwrq, char *extra) 2698 { 2699 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2700 2701 if (priv->sleep_mode == SLP_SLEEP) 2702 return -EPERM; 2703 /* for SLEEP MODE */ 2704 *uwrq = priv->reg.phy_info_timer; 2705 return 0; 2706 } 2707 #endif 2708 2709 #ifdef WPS 2710 /*------------------------------------------------------------------*/ 2711 /* Private handler : set WPS enable */ 2712 static int ks_wlan_set_wps_enable(struct net_device *dev, 2713 struct iw_request_info *info, __u32 *uwrq, 2714 char *extra) 2715 { 2716 struct ks_wlan_private *priv = 2717 (struct ks_wlan_private *)netdev_priv(dev); 2718 DPRINTK(2, "\n"); 2719 2720 if (priv->sleep_mode == SLP_SLEEP) 2721 return -EPERM; 2722 /* for SLEEP MODE */ 2723 if (*uwrq == 0 || *uwrq == 1) 2724 priv->wps.wps_enabled = *uwrq; 2725 else 2726 return -EINVAL; 2727 2728 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST); 2729 2730 return 0; 2731 } 2732 2733 /*------------------------------------------------------------------*/ 2734 /* Private handler : get WPS enable */ 2735 static int ks_wlan_get_wps_enable(struct net_device *dev, 2736 struct iw_request_info *info, __u32 *uwrq, 2737 char *extra) 2738 { 2739 struct ks_wlan_private *priv = 2740 (struct ks_wlan_private *)netdev_priv(dev); 2741 DPRINTK(2, "\n"); 2742 2743 if (priv->sleep_mode == SLP_SLEEP) 2744 return -EPERM; 2745 /* for SLEEP MODE */ 2746 *uwrq = priv->wps.wps_enabled; 2747 netdev_info(dev, "return=%d\n", *uwrq); 2748 2749 return 0; 2750 } 2751 2752 /*------------------------------------------------------------------*/ 2753 /* Private handler : set WPS probe req */ 2754 static int ks_wlan_set_wps_probe_req(struct net_device *dev, 2755 struct iw_request_info *info, 2756 struct iw_point *dwrq, char *extra) 2757 { 2758 uint8_t *p = extra; 2759 unsigned char len; 2760 struct ks_wlan_private *priv = 2761 (struct ks_wlan_private *)netdev_priv(dev); 2762 2763 DPRINTK(2, "\n"); 2764 2765 if (priv->sleep_mode == SLP_SLEEP) 2766 return -EPERM; 2767 /* for SLEEP MODE */ 2768 DPRINTK(2, "dwrq->length=%d\n", dwrq->length); 2769 2770 /* length check */ 2771 if (p[1] + 2 != dwrq->length || dwrq->length > 256) 2772 return -EINVAL; 2773 2774 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */ 2775 len = p[1] + 2; /* IE header + IE */ 2776 2777 memcpy(priv->wps.ie, &len, sizeof(len)); 2778 p = memcpy(priv->wps.ie + 1, p, len); 2779 2780 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n", 2781 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3], 2782 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2], 2783 p[priv->wps.ielen - 1]); 2784 2785 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST); 2786 2787 return 0; 2788 } 2789 2790 #if 0 2791 /*------------------------------------------------------------------*/ 2792 /* Private handler : get WPS probe req */ 2793 static int ks_wlan_get_wps_probe_req(struct net_device *dev, 2794 struct iw_request_info *info, 2795 __u32 *uwrq, char *extra) 2796 { 2797 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2798 2799 DPRINTK(2, "\n"); 2800 2801 if (priv->sleep_mode == SLP_SLEEP) 2802 return -EPERM; 2803 /* for SLEEP MODE */ 2804 return 0; 2805 } 2806 #endif 2807 #endif /* WPS */ 2808 2809 /*------------------------------------------------------------------*/ 2810 /* Private handler : set tx gain control value */ 2811 static int ks_wlan_set_tx_gain(struct net_device *dev, 2812 struct iw_request_info *info, __u32 *uwrq, 2813 char *extra) 2814 { 2815 struct ks_wlan_private *priv = 2816 (struct ks_wlan_private *)netdev_priv(dev); 2817 2818 if (priv->sleep_mode == SLP_SLEEP) 2819 return -EPERM; 2820 /* for SLEEP MODE */ 2821 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */ 2822 priv->gain.TxGain = (uint8_t)*uwrq; 2823 else 2824 return -EINVAL; 2825 2826 if (priv->gain.TxGain < 0xFF) 2827 priv->gain.TxMode = 1; 2828 else 2829 priv->gain.TxMode = 0; 2830 2831 hostif_sme_enqueue(priv, SME_SET_GAIN); 2832 return 0; 2833 } 2834 2835 /*------------------------------------------------------------------*/ 2836 /* Private handler : get tx gain control value */ 2837 static int ks_wlan_get_tx_gain(struct net_device *dev, 2838 struct iw_request_info *info, __u32 *uwrq, 2839 char *extra) 2840 { 2841 struct ks_wlan_private *priv = 2842 (struct ks_wlan_private *)netdev_priv(dev); 2843 2844 if (priv->sleep_mode == SLP_SLEEP) 2845 return -EPERM; 2846 /* for SLEEP MODE */ 2847 *uwrq = priv->gain.TxGain; 2848 hostif_sme_enqueue(priv, SME_GET_GAIN); 2849 return 0; 2850 } 2851 2852 /*------------------------------------------------------------------*/ 2853 /* Private handler : set rx gain control value */ 2854 static int ks_wlan_set_rx_gain(struct net_device *dev, 2855 struct iw_request_info *info, __u32 *uwrq, 2856 char *extra) 2857 { 2858 struct ks_wlan_private *priv = 2859 (struct ks_wlan_private *)netdev_priv(dev); 2860 2861 if (priv->sleep_mode == SLP_SLEEP) 2862 return -EPERM; 2863 /* for SLEEP MODE */ 2864 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */ 2865 priv->gain.RxGain = (uint8_t)*uwrq; 2866 else 2867 return -EINVAL; 2868 2869 if (priv->gain.RxGain < 0xFF) 2870 priv->gain.RxMode = 1; 2871 else 2872 priv->gain.RxMode = 0; 2873 2874 hostif_sme_enqueue(priv, SME_SET_GAIN); 2875 return 0; 2876 } 2877 2878 /*------------------------------------------------------------------*/ 2879 /* Private handler : get rx gain control value */ 2880 static int ks_wlan_get_rx_gain(struct net_device *dev, 2881 struct iw_request_info *info, __u32 *uwrq, 2882 char *extra) 2883 { 2884 struct ks_wlan_private *priv = 2885 (struct ks_wlan_private *)netdev_priv(dev); 2886 2887 if (priv->sleep_mode == SLP_SLEEP) 2888 return -EPERM; 2889 /* for SLEEP MODE */ 2890 *uwrq = priv->gain.RxGain; 2891 hostif_sme_enqueue(priv, SME_GET_GAIN); 2892 return 0; 2893 } 2894 2895 #if 0 2896 /*------------------------------------------------------------------*/ 2897 /* Private handler : set region value */ 2898 static int ks_wlan_set_region(struct net_device *dev, 2899 struct iw_request_info *info, __u32 *uwrq, 2900 char *extra) 2901 { 2902 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; 2903 2904 if (priv->sleep_mode == SLP_SLEEP) 2905 return -EPERM; 2906 /* for SLEEP MODE */ 2907 if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */ 2908 priv->region = (uint8_t)*uwrq; 2909 else 2910 return -EINVAL; 2911 2912 hostif_sme_enqueue(priv, SME_SET_REGION); 2913 return 0; 2914 } 2915 #endif 2916 2917 /*------------------------------------------------------------------*/ 2918 /* Private handler : get eeprom checksum result */ 2919 static int ks_wlan_get_eeprom_cksum(struct net_device *dev, 2920 struct iw_request_info *info, __u32 *uwrq, 2921 char *extra) 2922 { 2923 struct ks_wlan_private *priv = 2924 (struct ks_wlan_private *)netdev_priv(dev); 2925 2926 *uwrq = priv->eeprom_checksum; 2927 return 0; 2928 } 2929 2930 static void print_hif_event(struct net_device *dev, int event) 2931 { 2932 switch (event) { 2933 case HIF_DATA_REQ: 2934 netdev_info(dev, "HIF_DATA_REQ\n"); 2935 break; 2936 case HIF_DATA_IND: 2937 netdev_info(dev, "HIF_DATA_IND\n"); 2938 break; 2939 case HIF_MIB_GET_REQ: 2940 netdev_info(dev, "HIF_MIB_GET_REQ\n"); 2941 break; 2942 case HIF_MIB_GET_CONF: 2943 netdev_info(dev, "HIF_MIB_GET_CONF\n"); 2944 break; 2945 case HIF_MIB_SET_REQ: 2946 netdev_info(dev, "HIF_MIB_SET_REQ\n"); 2947 break; 2948 case HIF_MIB_SET_CONF: 2949 netdev_info(dev, "HIF_MIB_SET_CONF\n"); 2950 break; 2951 case HIF_POWERMGT_REQ: 2952 netdev_info(dev, "HIF_POWERMGT_REQ\n"); 2953 break; 2954 case HIF_POWERMGT_CONF: 2955 netdev_info(dev, "HIF_POWERMGT_CONF\n"); 2956 break; 2957 case HIF_START_REQ: 2958 netdev_info(dev, "HIF_START_REQ\n"); 2959 break; 2960 case HIF_START_CONF: 2961 netdev_info(dev, "HIF_START_CONF\n"); 2962 break; 2963 case HIF_CONNECT_IND: 2964 netdev_info(dev, "HIF_CONNECT_IND\n"); 2965 break; 2966 case HIF_STOP_REQ: 2967 netdev_info(dev, "HIF_STOP_REQ\n"); 2968 break; 2969 case HIF_STOP_CONF: 2970 netdev_info(dev, "HIF_STOP_CONF\n"); 2971 break; 2972 case HIF_PS_ADH_SET_REQ: 2973 netdev_info(dev, "HIF_PS_ADH_SET_REQ\n"); 2974 break; 2975 case HIF_PS_ADH_SET_CONF: 2976 netdev_info(dev, "HIF_PS_ADH_SET_CONF\n"); 2977 break; 2978 case HIF_INFRA_SET_REQ: 2979 netdev_info(dev, "HIF_INFRA_SET_REQ\n"); 2980 break; 2981 case HIF_INFRA_SET_CONF: 2982 netdev_info(dev, "HIF_INFRA_SET_CONF\n"); 2983 break; 2984 case HIF_ADH_SET_REQ: 2985 netdev_info(dev, "HIF_ADH_SET_REQ\n"); 2986 break; 2987 case HIF_ADH_SET_CONF: 2988 netdev_info(dev, "HIF_ADH_SET_CONF\n"); 2989 break; 2990 case HIF_AP_SET_REQ: 2991 netdev_info(dev, "HIF_AP_SET_REQ\n"); 2992 break; 2993 case HIF_AP_SET_CONF: 2994 netdev_info(dev, "HIF_AP_SET_CONF\n"); 2995 break; 2996 case HIF_ASSOC_INFO_IND: 2997 netdev_info(dev, "HIF_ASSOC_INFO_IND\n"); 2998 break; 2999 case HIF_MIC_FAILURE_REQ: 3000 netdev_info(dev, "HIF_MIC_FAILURE_REQ\n"); 3001 break; 3002 case HIF_MIC_FAILURE_CONF: 3003 netdev_info(dev, "HIF_MIC_FAILURE_CONF\n"); 3004 break; 3005 case HIF_SCAN_REQ: 3006 netdev_info(dev, "HIF_SCAN_REQ\n"); 3007 break; 3008 case HIF_SCAN_CONF: 3009 netdev_info(dev, "HIF_SCAN_CONF\n"); 3010 break; 3011 case HIF_PHY_INFO_REQ: 3012 netdev_info(dev, "HIF_PHY_INFO_REQ\n"); 3013 break; 3014 case HIF_PHY_INFO_CONF: 3015 netdev_info(dev, "HIF_PHY_INFO_CONF\n"); 3016 break; 3017 case HIF_SLEEP_REQ: 3018 netdev_info(dev, "HIF_SLEEP_REQ\n"); 3019 break; 3020 case HIF_SLEEP_CONF: 3021 netdev_info(dev, "HIF_SLEEP_CONF\n"); 3022 break; 3023 case HIF_PHY_INFO_IND: 3024 netdev_info(dev, "HIF_PHY_INFO_IND\n"); 3025 break; 3026 case HIF_SCAN_IND: 3027 netdev_info(dev, "HIF_SCAN_IND\n"); 3028 break; 3029 case HIF_INFRA_SET2_REQ: 3030 netdev_info(dev, "HIF_INFRA_SET2_REQ\n"); 3031 break; 3032 case HIF_INFRA_SET2_CONF: 3033 netdev_info(dev, "HIF_INFRA_SET2_CONF\n"); 3034 break; 3035 case HIF_ADH_SET2_REQ: 3036 netdev_info(dev, "HIF_ADH_SET2_REQ\n"); 3037 break; 3038 case HIF_ADH_SET2_CONF: 3039 netdev_info(dev, "HIF_ADH_SET2_CONF\n"); 3040 } 3041 } 3042 3043 /*------------------------------------------------------------------*/ 3044 /* Private handler : get host command history */ 3045 static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info, 3046 __u32 *uwrq, char *extra) 3047 { 3048 int i, event; 3049 struct ks_wlan_private *priv = 3050 (struct ks_wlan_private *)netdev_priv(dev); 3051 3052 for (i = 63; i >= 0; i--) { 3053 event = 3054 priv->hostt.buff[(priv->hostt.qtail - 1 - i) % 3055 SME_EVENT_BUFF_SIZE]; 3056 print_hif_event(dev, event); 3057 } 3058 return 0; 3059 } 3060 3061 /* Structures to export the Wireless Handlers */ 3062 3063 static const struct iw_priv_args ks_wlan_private_args[] = { 3064 /*{ cmd, set_args, get_args, name[16] } */ 3065 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE, 3066 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"}, 3067 #ifdef WPS 3068 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3069 IW_PRIV_TYPE_NONE, "SetWPSEnable"}, 3070 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE, 3071 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"}, 3072 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE, 3073 "SetWPSProbeReq"}, 3074 #endif /* WPS */ 3075 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3076 IW_PRIV_TYPE_NONE, "SetPreamble"}, 3077 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE, 3078 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"}, 3079 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3080 IW_PRIV_TYPE_NONE, "SetPowerSave"}, 3081 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE, 3082 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"}, 3083 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3084 IW_PRIV_TYPE_NONE, "SetScanType"}, 3085 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE, 3086 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"}, 3087 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3088 IW_PRIV_TYPE_NONE, "SetRxGain"}, 3089 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE, 3090 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"}, 3091 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1), 3092 "hostt"}, 3093 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3094 IW_PRIV_TYPE_NONE, "SetBeaconLost"}, 3095 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE, 3096 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"}, 3097 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3098 IW_PRIV_TYPE_NONE, "SetSleepMode"}, 3099 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE, 3100 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"}, 3101 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3102 IW_PRIV_TYPE_NONE, "SetTxGain"}, 3103 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE, 3104 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"}, 3105 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3106 IW_PRIV_TYPE_NONE, "SetPhyType"}, 3107 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE, 3108 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"}, 3109 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 3110 IW_PRIV_TYPE_NONE, "SetCtsMode"}, 3111 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE, 3112 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"}, 3113 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE, 3114 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"}, 3115 }; 3116 3117 static const iw_handler ks_wlan_handler[] = { 3118 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */ 3119 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */ 3120 (iw_handler) NULL, /* SIOCSIWNWID */ 3121 (iw_handler) NULL, /* SIOCGIWNWID */ 3122 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */ 3123 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */ 3124 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */ 3125 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */ 3126 #ifndef KSC_OPNOTSUPP 3127 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */ 3128 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */ 3129 #else /* KSC_OPNOTSUPP */ 3130 (iw_handler) NULL, /* SIOCSIWSENS */ 3131 (iw_handler) NULL, /* SIOCGIWSENS */ 3132 #endif /* KSC_OPNOTSUPP */ 3133 (iw_handler) NULL, /* SIOCSIWRANGE */ 3134 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */ 3135 (iw_handler) NULL, /* SIOCSIWPRIV */ 3136 (iw_handler) NULL, /* SIOCGIWPRIV */ 3137 (iw_handler) NULL, /* SIOCSIWSTATS */ 3138 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */ 3139 (iw_handler) NULL, /* SIOCSIWSPY */ 3140 (iw_handler) NULL, /* SIOCGIWSPY */ 3141 (iw_handler) NULL, /* SIOCSIWTHRSPY */ 3142 (iw_handler) NULL, /* SIOCGIWTHRSPY */ 3143 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */ 3144 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */ 3145 // (iw_handler) NULL, /* SIOCSIWMLME */ 3146 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */ 3147 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */ 3148 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */ 3149 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */ 3150 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */ 3151 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */ 3152 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */ 3153 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */ 3154 (iw_handler) NULL, /* -- hole -- */ 3155 (iw_handler) NULL, /* -- hole -- */ 3156 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */ 3157 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */ 3158 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */ 3159 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */ 3160 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */ 3161 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */ 3162 #ifndef KSC_OPNOTSUPP 3163 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */ 3164 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */ 3165 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */ 3166 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */ 3167 #else /* KSC_OPNOTSUPP */ 3168 (iw_handler) NULL, /* SIOCSIWTXPOW */ 3169 (iw_handler) NULL, /* SIOCGIWTXPOW */ 3170 (iw_handler) NULL, /* SIOCSIWRETRY */ 3171 (iw_handler) NULL, /* SIOCGIWRETRY */ 3172 #endif /* KSC_OPNOTSUPP */ 3173 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */ 3174 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */ 3175 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */ 3176 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */ 3177 (iw_handler) NULL, /* -- hole -- */ 3178 (iw_handler) NULL, /* -- hole -- */ 3179 // (iw_handler) NULL, /* SIOCSIWGENIE */ 3180 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */ 3181 (iw_handler) NULL, /* SIOCGIWGENIE */ 3182 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */ 3183 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */ 3184 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */ 3185 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */ 3186 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */ 3187 (iw_handler) NULL, /* -- hole -- */ 3188 }; 3189 3190 /* private_handler */ 3191 static const iw_handler ks_wlan_private_handler[] = { 3192 (iw_handler) NULL, /* 0 */ 3193 (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */ 3194 (iw_handler) NULL, /* 2 */ 3195 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */ 3196 #ifdef WPS 3197 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */ 3198 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */ 3199 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */ 3200 #else 3201 (iw_handler) NULL, /* 4 */ 3202 (iw_handler) NULL, /* 5 */ 3203 (iw_handler) NULL, /* 6 */ 3204 #endif /* WPS */ 3205 3206 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */ 3207 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */ 3208 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */ 3209 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */ 3210 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */ 3211 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */ 3212 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */ 3213 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */ 3214 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */ 3215 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */ 3216 (iw_handler) NULL, /* 17 */ 3217 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */ 3218 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */ 3219 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */ 3220 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */ 3221 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */ 3222 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */ 3223 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */ 3224 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */ 3225 (iw_handler) NULL, /* 26 */ 3226 (iw_handler) NULL, /* 27 */ 3227 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */ 3228 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */ 3229 (iw_handler) NULL, /* 30 */ 3230 (iw_handler) NULL, /* 31 */ 3231 }; 3232 3233 static const struct iw_handler_def ks_wlan_handler_def = { 3234 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler), 3235 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler), 3236 .num_private_args = 3237 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args), 3238 .standard = (iw_handler *) ks_wlan_handler, 3239 .private = (iw_handler *) ks_wlan_private_handler, 3240 .private_args = (struct iw_priv_args *)ks_wlan_private_args, 3241 .get_wireless_stats = ks_get_wireless_stats, 3242 }; 3243 3244 static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, 3245 int cmd) 3246 { 3247 int rc = 0; 3248 struct iwreq *wrq = (struct iwreq *)rq; 3249 3250 switch (cmd) { 3251 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */ 3252 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL); 3253 break; 3254 // All other calls are currently unsupported 3255 default: 3256 rc = -EOPNOTSUPP; 3257 } 3258 3259 DPRINTK(5, "return=%d\n", rc); 3260 return rc; 3261 } 3262 3263 static 3264 struct net_device_stats *ks_wlan_get_stats(struct net_device *dev) 3265 { 3266 struct ks_wlan_private *priv = netdev_priv(dev); 3267 3268 if (priv->dev_state < DEVICE_STATE_READY) 3269 return NULL; /* not finished initialize */ 3270 3271 return &priv->nstats; 3272 } 3273 3274 static 3275 int ks_wlan_set_mac_address(struct net_device *dev, void *addr) 3276 { 3277 struct ks_wlan_private *priv = netdev_priv(dev); 3278 struct sockaddr *mac_addr = (struct sockaddr *)addr; 3279 3280 if (netif_running(dev)) 3281 return -EBUSY; 3282 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len); 3283 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN); 3284 3285 priv->mac_address_valid = 0; 3286 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST); 3287 netdev_info(dev, "ks_wlan: MAC ADDRESS = %pM\n", priv->eth_addr); 3288 return 0; 3289 } 3290 3291 static 3292 void ks_wlan_tx_timeout(struct net_device *dev) 3293 { 3294 struct ks_wlan_private *priv = netdev_priv(dev); 3295 3296 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead, 3297 priv->tx_dev.qtail); 3298 if (!netif_queue_stopped(dev)) 3299 netif_stop_queue(dev); 3300 priv->nstats.tx_errors++; 3301 netif_wake_queue(dev); 3302 } 3303 3304 static 3305 int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev) 3306 { 3307 struct ks_wlan_private *priv = netdev_priv(dev); 3308 int rc = 0; 3309 3310 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt()); 3311 3312 if (!skb) { 3313 netdev_err(dev, "ks_wlan: skb == NULL!!!\n"); 3314 return 0; 3315 } 3316 if (priv->dev_state < DEVICE_STATE_READY) { 3317 dev_kfree_skb(skb); 3318 return 0; /* not finished initialize */ 3319 } 3320 3321 if (netif_running(dev)) 3322 netif_stop_queue(dev); 3323 3324 rc = hostif_data_request(priv, skb); 3325 netif_trans_update(dev); 3326 3327 DPRINTK(4, "rc=%d\n", rc); 3328 if (rc) 3329 rc = 0; 3330 3331 return rc; 3332 } 3333 3334 void send_packet_complete(void *arg1, void *arg2) 3335 { 3336 struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1; 3337 struct sk_buff *packet = (struct sk_buff *)arg2; 3338 3339 DPRINTK(3, "\n"); 3340 3341 priv->nstats.tx_packets++; 3342 3343 if (netif_queue_stopped(priv->net_dev)) 3344 netif_wake_queue(priv->net_dev); 3345 3346 if (packet) { 3347 priv->nstats.tx_bytes += packet->len; 3348 dev_kfree_skb(packet); 3349 packet = NULL; 3350 } 3351 } 3352 3353 /* Set or clear the multicast filter for this adaptor. 3354 This routine is not state sensitive and need not be SMP locked. */ 3355 static 3356 void ks_wlan_set_multicast_list(struct net_device *dev) 3357 { 3358 struct ks_wlan_private *priv = netdev_priv(dev); 3359 3360 DPRINTK(4, "\n"); 3361 if (priv->dev_state < DEVICE_STATE_READY) 3362 return; /* not finished initialize */ 3363 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST); 3364 } 3365 3366 static 3367 int ks_wlan_open(struct net_device *dev) 3368 { 3369 struct ks_wlan_private *priv = netdev_priv(dev); 3370 3371 priv->cur_rx = 0; 3372 3373 if (!priv->mac_address_valid) { 3374 netdev_err(dev, "ks_wlan : %s Not READY !!\n", dev->name); 3375 return -EBUSY; 3376 } 3377 netif_start_queue(dev); 3378 3379 return 0; 3380 } 3381 3382 static 3383 int ks_wlan_close(struct net_device *dev) 3384 { 3385 netif_stop_queue(dev); 3386 3387 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n", 3388 dev->name, 0x00); 3389 3390 return 0; 3391 } 3392 3393 /* Operational parameters that usually are not changed. */ 3394 /* Time in jiffies before concluding the transmitter is hung. */ 3395 #define TX_TIMEOUT (3 * HZ) 3396 static const unsigned char dummy_addr[] = { 3397 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 3398 }; 3399 3400 static const struct net_device_ops ks_wlan_netdev_ops = { 3401 .ndo_start_xmit = ks_wlan_start_xmit, 3402 .ndo_open = ks_wlan_open, 3403 .ndo_stop = ks_wlan_close, 3404 .ndo_do_ioctl = ks_wlan_netdev_ioctl, 3405 .ndo_set_mac_address = ks_wlan_set_mac_address, 3406 .ndo_get_stats = ks_wlan_get_stats, 3407 .ndo_tx_timeout = ks_wlan_tx_timeout, 3408 .ndo_set_rx_mode = ks_wlan_set_multicast_list, 3409 }; 3410 3411 int ks_wlan_net_start(struct net_device *dev) 3412 { 3413 struct ks_wlan_private *priv; 3414 /* int rc; */ 3415 3416 priv = netdev_priv(dev); 3417 priv->mac_address_valid = 0; 3418 priv->need_commit = 0; 3419 3420 priv->device_open_status = 1; 3421 3422 /* phy information update timer */ 3423 atomic_set(&update_phyinfo, 0); 3424 setup_timer(&update_phyinfo_timer, ks_wlan_update_phyinfo_timeout, 3425 (unsigned long)priv); 3426 3427 /* dummy address set */ 3428 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN); 3429 dev->dev_addr[0] = priv->eth_addr[0]; 3430 dev->dev_addr[1] = priv->eth_addr[1]; 3431 dev->dev_addr[2] = priv->eth_addr[2]; 3432 dev->dev_addr[3] = priv->eth_addr[3]; 3433 dev->dev_addr[4] = priv->eth_addr[4]; 3434 dev->dev_addr[5] = priv->eth_addr[5]; 3435 dev->dev_addr[6] = 0x00; 3436 dev->dev_addr[7] = 0x00; 3437 3438 /* The ks_wlan-specific entries in the device structure. */ 3439 dev->netdev_ops = &ks_wlan_netdev_ops; 3440 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def; 3441 dev->watchdog_timeo = TX_TIMEOUT; 3442 3443 netif_carrier_off(dev); 3444 3445 return 0; 3446 } 3447 3448 int ks_wlan_net_stop(struct net_device *dev) 3449 { 3450 struct ks_wlan_private *priv = netdev_priv(dev); 3451 3452 priv->device_open_status = 0; 3453 del_timer_sync(&update_phyinfo_timer); 3454 3455 if (netif_running(dev)) 3456 netif_stop_queue(dev); 3457 3458 return 0; 3459 } 3460