3 Broadcom BCM43xx wireless driver
5 Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
6 Stefano Brivio <st3@riseup.net>
7 Michael Buesch <mbuesch@freenet.de>
8 Danny van Dyk <kugelfang@gentoo.org>
9 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11 Some parts of the code in this file are derived from the ipw2200
12 driver Copyright(c) 2003 - 2004 Intel Corporation.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
27 Boston, MA 02110-1301, USA.
31 #include <linux/wireless.h>
32 #include <net/iw_handler.h>
33 #include <net/ieee80211softmac.h>
34 #include <net/ieee80211softmac_wx.h>
35 #include <linux/capability.h>
36 #include <linux/delay.h>
39 #include "bcm43xx_wx.h"
40 #include "bcm43xx_main.h"
41 #include "bcm43xx_radio.h"
42 #include "bcm43xx_phy.h"
45 /* The WIRELESS_EXT version, which is implemented by this driver. */
46 #define BCM43xx_WX_VERSION 18
48 #define MAX_WX_STRING 80
50 static int bcm43xx_wx_get_name(struct net_device *net_dev,
51 struct iw_request_info *info,
52 union iwreq_data *data,
55 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
57 struct bcm43xx_phyinfo *phy;
58 char suffix[7] = { 0 };
59 int have_a = 0, have_b = 0, have_g = 0;
61 mutex_lock(&bcm->mutex);
62 for (i = 0; i < bcm->nr_80211_available; i++) {
63 phy = &(bcm->core_80211_ext[i].phy);
65 case BCM43xx_PHYTYPE_A:
68 case BCM43xx_PHYTYPE_G:
70 case BCM43xx_PHYTYPE_B:
77 mutex_unlock(&bcm->mutex);
95 snprintf(data->name, IFNAMSIZ, "IEEE 802.11%s", suffix);
100 static int bcm43xx_wx_set_channelfreq(struct net_device *net_dev,
101 struct iw_request_info *info,
102 union iwreq_data *data,
105 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
111 mutex_lock(&bcm->mutex);
112 spin_lock_irqsave(&bcm->irq_lock, flags);
114 if ((data->freq.m >= 0) && (data->freq.m <= 1000)) {
115 channel = data->freq.m;
116 freq = bcm43xx_channel_to_freq(bcm, channel);
118 channel = bcm43xx_freq_to_channel(bcm, data->freq.m);
121 if (!ieee80211_is_valid_channel(bcm->ieee, channel))
123 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
124 //ieee80211softmac_disassoc(softmac, $REASON);
125 bcm43xx_mac_suspend(bcm);
126 err = bcm43xx_radio_selectchannel(bcm, channel, 0);
127 bcm43xx_mac_enable(bcm);
129 bcm43xx_current_radio(bcm)->initial_channel = channel;
133 spin_unlock_irqrestore(&bcm->irq_lock, flags);
134 mutex_unlock(&bcm->mutex);
139 static int bcm43xx_wx_get_channelfreq(struct net_device *net_dev,
140 struct iw_request_info *info,
141 union iwreq_data *data,
144 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
145 struct bcm43xx_radioinfo *radio;
149 mutex_lock(&bcm->mutex);
150 radio = bcm43xx_current_radio(bcm);
151 channel = radio->channel;
152 if (channel == 0xFF) {
153 channel = radio->initial_channel;
157 assert(channel > 0 && channel <= 1000);
159 data->freq.m = bcm43xx_channel_to_freq(bcm, channel) * 100000;
160 data->freq.flags = 1;
164 mutex_unlock(&bcm->mutex);
169 static int bcm43xx_wx_set_mode(struct net_device *net_dev,
170 struct iw_request_info *info,
171 union iwreq_data *data,
174 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
179 if (mode == IW_MODE_AUTO)
180 mode = BCM43xx_INITIAL_IWMODE;
182 mutex_lock(&bcm->mutex);
183 spin_lock_irqsave(&bcm->irq_lock, flags);
184 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
185 if (bcm->ieee->iw_mode != mode)
186 bcm43xx_set_iwmode(bcm, mode);
188 bcm->ieee->iw_mode = mode;
189 spin_unlock_irqrestore(&bcm->irq_lock, flags);
190 mutex_unlock(&bcm->mutex);
195 static int bcm43xx_wx_get_mode(struct net_device *net_dev,
196 struct iw_request_info *info,
197 union iwreq_data *data,
200 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
202 mutex_lock(&bcm->mutex);
203 data->mode = bcm->ieee->iw_mode;
204 mutex_unlock(&bcm->mutex);
209 static int bcm43xx_wx_get_rangeparams(struct net_device *net_dev,
210 struct iw_request_info *info,
211 union iwreq_data *data,
214 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
215 struct iw_range *range = (struct iw_range *)extra;
216 const struct ieee80211_geo *geo;
218 struct bcm43xx_phyinfo *phy;
220 data->data.length = sizeof(*range);
221 memset(range, 0, sizeof(*range));
223 //TODO: What about 802.11b?
224 /* 54Mb/s == ~27Mb/s payload throughput (802.11g) */
225 range->throughput = 27 * 1000 * 1000;
227 range->max_qual.qual = 100;
228 range->max_qual.level = 146; /* set floor at -110 dBm (146 - 256) */
229 range->max_qual.noise = 146;
230 range->max_qual.updated = IW_QUAL_ALL_UPDATED;
232 range->avg_qual.qual = 50;
233 range->avg_qual.level = 0;
234 range->avg_qual.noise = 0;
235 range->avg_qual.updated = IW_QUAL_ALL_UPDATED;
237 range->min_rts = BCM43xx_MIN_RTS_THRESHOLD;
238 range->max_rts = BCM43xx_MAX_RTS_THRESHOLD;
239 range->min_frag = MIN_FRAG_THRESHOLD;
240 range->max_frag = MAX_FRAG_THRESHOLD;
242 range->encoding_size[0] = 5;
243 range->encoding_size[1] = 13;
244 range->num_encoding_sizes = 2;
245 range->max_encoding_tokens = WEP_KEYS;
247 range->we_version_compiled = WIRELESS_EXT;
248 range->we_version_source = BCM43xx_WX_VERSION;
250 range->enc_capa = IW_ENC_CAPA_WPA |
252 IW_ENC_CAPA_CIPHER_TKIP |
253 IW_ENC_CAPA_CIPHER_CCMP;
255 mutex_lock(&bcm->mutex);
256 phy = bcm43xx_current_phy(bcm);
258 range->num_bitrates = 0;
260 if (phy->type == BCM43xx_PHYTYPE_A ||
261 phy->type == BCM43xx_PHYTYPE_G) {
262 range->num_bitrates = 8;
263 range->bitrate[i++] = IEEE80211_OFDM_RATE_6MB * 500000;
264 range->bitrate[i++] = IEEE80211_OFDM_RATE_9MB * 500000;
265 range->bitrate[i++] = IEEE80211_OFDM_RATE_12MB * 500000;
266 range->bitrate[i++] = IEEE80211_OFDM_RATE_18MB * 500000;
267 range->bitrate[i++] = IEEE80211_OFDM_RATE_24MB * 500000;
268 range->bitrate[i++] = IEEE80211_OFDM_RATE_36MB * 500000;
269 range->bitrate[i++] = IEEE80211_OFDM_RATE_48MB * 500000;
270 range->bitrate[i++] = IEEE80211_OFDM_RATE_54MB * 500000;
272 if (phy->type == BCM43xx_PHYTYPE_B ||
273 phy->type == BCM43xx_PHYTYPE_G) {
274 range->num_bitrates += 4;
275 range->bitrate[i++] = IEEE80211_CCK_RATE_1MB * 500000;
276 range->bitrate[i++] = IEEE80211_CCK_RATE_2MB * 500000;
277 range->bitrate[i++] = IEEE80211_CCK_RATE_5MB * 500000;
278 range->bitrate[i++] = IEEE80211_CCK_RATE_11MB * 500000;
281 geo = ieee80211_get_geo(bcm->ieee);
282 range->num_channels = geo->a_channels + geo->bg_channels;
284 for (i = 0; i < geo->a_channels; i++) {
285 if (j == IW_MAX_FREQUENCIES)
287 range->freq[j].i = j + 1;
288 range->freq[j].m = geo->a[i].freq * 100000;
289 range->freq[j].e = 1;
292 for (i = 0; i < geo->bg_channels; i++) {
293 if (j == IW_MAX_FREQUENCIES)
295 range->freq[j].i = j + 1;
296 range->freq[j].m = geo->bg[i].freq * 100000;
297 range->freq[j].e = 1;
300 range->num_frequency = j;
302 mutex_unlock(&bcm->mutex);
307 static int bcm43xx_wx_set_nick(struct net_device *net_dev,
308 struct iw_request_info *info,
309 union iwreq_data *data,
312 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
315 mutex_lock(&bcm->mutex);
316 len = min((size_t)data->data.length, (size_t)IW_ESSID_MAX_SIZE);
317 memcpy(bcm->nick, extra, len);
318 bcm->nick[len] = '\0';
319 mutex_unlock(&bcm->mutex);
324 static int bcm43xx_wx_get_nick(struct net_device *net_dev,
325 struct iw_request_info *info,
326 union iwreq_data *data,
329 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
332 mutex_lock(&bcm->mutex);
333 len = strlen(bcm->nick);
334 memcpy(extra, bcm->nick, len);
335 data->data.length = (__u16)len;
336 data->data.flags = 1;
337 mutex_unlock(&bcm->mutex);
342 static int bcm43xx_wx_set_rts(struct net_device *net_dev,
343 struct iw_request_info *info,
344 union iwreq_data *data,
347 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
351 mutex_lock(&bcm->mutex);
352 spin_lock_irqsave(&bcm->irq_lock, flags);
353 if (data->rts.disabled) {
354 bcm->rts_threshold = BCM43xx_MAX_RTS_THRESHOLD;
357 if (data->rts.value >= BCM43xx_MIN_RTS_THRESHOLD &&
358 data->rts.value <= BCM43xx_MAX_RTS_THRESHOLD) {
359 bcm->rts_threshold = data->rts.value;
363 spin_unlock_irqrestore(&bcm->irq_lock, flags);
364 mutex_unlock(&bcm->mutex);
369 static int bcm43xx_wx_get_rts(struct net_device *net_dev,
370 struct iw_request_info *info,
371 union iwreq_data *data,
374 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
376 mutex_lock(&bcm->mutex);
377 data->rts.value = bcm->rts_threshold;
379 data->rts.disabled = (bcm->rts_threshold == BCM43xx_MAX_RTS_THRESHOLD);
380 mutex_unlock(&bcm->mutex);
385 static int bcm43xx_wx_set_frag(struct net_device *net_dev,
386 struct iw_request_info *info,
387 union iwreq_data *data,
390 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
394 mutex_lock(&bcm->mutex);
395 spin_lock_irqsave(&bcm->irq_lock, flags);
396 if (data->frag.disabled) {
397 bcm->ieee->fts = MAX_FRAG_THRESHOLD;
400 if (data->frag.value >= MIN_FRAG_THRESHOLD &&
401 data->frag.value <= MAX_FRAG_THRESHOLD) {
402 bcm->ieee->fts = data->frag.value & ~0x1;
406 spin_unlock_irqrestore(&bcm->irq_lock, flags);
407 mutex_unlock(&bcm->mutex);
412 static int bcm43xx_wx_get_frag(struct net_device *net_dev,
413 struct iw_request_info *info,
414 union iwreq_data *data,
417 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
419 mutex_lock(&bcm->mutex);
420 data->frag.value = bcm->ieee->fts;
421 data->frag.fixed = 0;
422 data->frag.disabled = (bcm->ieee->fts == MAX_FRAG_THRESHOLD);
423 mutex_unlock(&bcm->mutex);
428 static int bcm43xx_wx_set_xmitpower(struct net_device *net_dev,
429 struct iw_request_info *info,
430 union iwreq_data *data,
433 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
434 struct bcm43xx_radioinfo *radio;
435 struct bcm43xx_phyinfo *phy;
440 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
441 printk(PFX KERN_ERR "TX power not in dBm.\n");
445 mutex_lock(&bcm->mutex);
446 spin_lock_irqsave(&bcm->irq_lock, flags);
447 if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)
449 radio = bcm43xx_current_radio(bcm);
450 phy = bcm43xx_current_phy(bcm);
451 if (data->txpower.disabled != (!(radio->enabled))) {
452 if (data->txpower.disabled)
453 bcm43xx_radio_turn_off(bcm);
455 bcm43xx_radio_turn_on(bcm);
457 if (data->txpower.value > 0) {
458 /* desired and maxpower dBm values are in Q5.2 */
459 if (phy->type == BCM43xx_PHYTYPE_A)
460 maxpower = bcm->sprom.maxpower_aphy;
462 maxpower = bcm->sprom.maxpower_bgphy;
463 radio->txpower_desired = limit_value(data->txpower.value << 2,
465 bcm43xx_phy_xmitpower(bcm);
470 spin_unlock_irqrestore(&bcm->irq_lock, flags);
471 mutex_unlock(&bcm->mutex);
476 static int bcm43xx_wx_get_xmitpower(struct net_device *net_dev,
477 struct iw_request_info *info,
478 union iwreq_data *data,
481 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
482 struct bcm43xx_radioinfo *radio;
485 mutex_lock(&bcm->mutex);
486 if (bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)
488 radio = bcm43xx_current_radio(bcm);
489 /* desired dBm value is in Q5.2 */
490 data->txpower.value = radio->txpower_desired >> 2;
491 data->txpower.fixed = 1;
492 data->txpower.flags = IW_TXPOW_DBM;
493 data->txpower.disabled = !(radio->enabled);
497 mutex_unlock(&bcm->mutex);
502 static int bcm43xx_wx_set_encoding(struct net_device *net_dev,
503 struct iw_request_info *info,
504 union iwreq_data *data,
507 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
510 err = ieee80211_wx_set_encode(bcm->ieee, info, data, extra);
515 static int bcm43xx_wx_set_encodingext(struct net_device *net_dev,
516 struct iw_request_info *info,
517 union iwreq_data *data,
520 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
523 err = ieee80211_wx_set_encodeext(bcm->ieee, info, data, extra);
528 static int bcm43xx_wx_get_encoding(struct net_device *net_dev,
529 struct iw_request_info *info,
530 union iwreq_data *data,
533 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
536 err = ieee80211_wx_get_encode(bcm->ieee, info, data, extra);
541 static int bcm43xx_wx_get_encodingext(struct net_device *net_dev,
542 struct iw_request_info *info,
543 union iwreq_data *data,
546 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
549 err = ieee80211_wx_get_encodeext(bcm->ieee, info, data, extra);
554 static int bcm43xx_wx_set_interfmode(struct net_device *net_dev,
555 struct iw_request_info *info,
556 union iwreq_data *data,
559 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
563 mode = *((int *)extra);
566 mode = BCM43xx_RADIO_INTERFMODE_NONE;
569 mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
572 mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
575 mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
578 printk(KERN_ERR PFX "set_interfmode allowed parameters are: "
579 "0 => None, 1 => Non-WLAN, 2 => WLAN, "
584 mutex_lock(&bcm->mutex);
585 spin_lock_irqsave(&bcm->irq_lock, flags);
586 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
587 err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
589 printk(KERN_ERR PFX "Interference Mitigation not "
590 "supported by device\n");
593 if (mode == BCM43xx_RADIO_INTERFMODE_AUTOWLAN) {
594 printk(KERN_ERR PFX "Interference Mitigation mode Auto-WLAN "
595 "not supported while the interface is down.\n");
598 bcm43xx_current_radio(bcm)->interfmode = mode;
600 spin_unlock_irqrestore(&bcm->irq_lock, flags);
601 mutex_unlock(&bcm->mutex);
606 static int bcm43xx_wx_get_interfmode(struct net_device *net_dev,
607 struct iw_request_info *info,
608 union iwreq_data *data,
611 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
614 mutex_lock(&bcm->mutex);
615 mode = bcm43xx_current_radio(bcm)->interfmode;
616 mutex_unlock(&bcm->mutex);
619 case BCM43xx_RADIO_INTERFMODE_NONE:
620 strncpy(extra, "0 (No Interference Mitigation)", MAX_WX_STRING);
622 case BCM43xx_RADIO_INTERFMODE_NONWLAN:
623 strncpy(extra, "1 (Non-WLAN Interference Mitigation)", MAX_WX_STRING);
625 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
626 strncpy(extra, "2 (WLAN Interference Mitigation)", MAX_WX_STRING);
631 data->data.length = strlen(extra) + 1;
636 static int bcm43xx_wx_set_shortpreamble(struct net_device *net_dev,
637 struct iw_request_info *info,
638 union iwreq_data *data,
641 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
645 on = *((int *)extra);
646 mutex_lock(&bcm->mutex);
647 spin_lock_irqsave(&bcm->irq_lock, flags);
648 bcm->short_preamble = !!on;
649 spin_unlock_irqrestore(&bcm->irq_lock, flags);
650 mutex_unlock(&bcm->mutex);
655 static int bcm43xx_wx_get_shortpreamble(struct net_device *net_dev,
656 struct iw_request_info *info,
657 union iwreq_data *data,
660 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
663 mutex_lock(&bcm->mutex);
664 on = bcm->short_preamble;
665 mutex_unlock(&bcm->mutex);
668 strncpy(extra, "1 (Short Preamble enabled)", MAX_WX_STRING);
670 strncpy(extra, "0 (Short Preamble disabled)", MAX_WX_STRING);
671 data->data.length = strlen(extra) + 1;
676 static int bcm43xx_wx_set_swencryption(struct net_device *net_dev,
677 struct iw_request_info *info,
678 union iwreq_data *data,
681 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
685 on = *((int *)extra);
687 mutex_lock(&bcm->mutex);
688 spin_lock_irqsave(&bcm->irq_lock, flags);
689 bcm->ieee->host_encrypt = !!on;
690 bcm->ieee->host_decrypt = !!on;
691 bcm->ieee->host_build_iv = !on;
692 bcm->ieee->host_strip_iv_icv = !on;
693 spin_unlock_irqrestore(&bcm->irq_lock, flags);
694 mutex_unlock(&bcm->mutex);
699 static int bcm43xx_wx_get_swencryption(struct net_device *net_dev,
700 struct iw_request_info *info,
701 union iwreq_data *data,
704 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
707 mutex_lock(&bcm->mutex);
708 on = bcm->ieee->host_encrypt;
709 mutex_unlock(&bcm->mutex);
712 strncpy(extra, "1 (SW encryption enabled) ", MAX_WX_STRING);
714 strncpy(extra, "0 (SW encryption disabled) ", MAX_WX_STRING);
715 data->data.length = strlen(extra + 1);
720 /* Enough buffer to hold a hexdump of the sprom data. */
721 #define SPROM_BUFFERSIZE 512
723 static int sprom2hex(const u16 *sprom, char *dump)
727 for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
728 pos += snprintf(dump + pos, SPROM_BUFFERSIZE - pos - 1,
729 "%04X", swab16(sprom[i]) & 0xFFFF);
735 static int hex2sprom(u16 *sprom, const char *dump, unsigned int len)
739 unsigned long parsed;
741 if (len < BCM43xx_SPROM_SIZE * sizeof(u16) * 2)
743 while (cnt < BCM43xx_SPROM_SIZE) {
744 memcpy(tmp, dump, 4);
746 parsed = simple_strtoul(tmp, NULL, 16);
747 sprom[cnt++] = swab16((u16)parsed);
753 static int bcm43xx_wx_sprom_read(struct net_device *net_dev,
754 struct iw_request_info *info,
755 union iwreq_data *data,
758 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
763 if (!capable(CAP_SYS_RAWIO))
767 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
772 mutex_lock(&bcm->mutex);
773 spin_lock_irqsave(&bcm->irq_lock, flags);
775 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)
776 err = bcm43xx_sprom_read(bcm, sprom);
777 spin_unlock_irqrestore(&bcm->irq_lock, flags);
778 mutex_unlock(&bcm->mutex);
780 data->data.length = sprom2hex(sprom, extra);
786 static int bcm43xx_wx_sprom_write(struct net_device *net_dev,
787 struct iw_request_info *info,
788 union iwreq_data *data,
791 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
798 if (!capable(CAP_SYS_RAWIO))
802 sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
807 len = data->data.length;
808 extra[len - 1] = '\0';
809 input = strchr(extra, ':');
812 len -= input - extra;
815 err = hex2sprom(sprom, input, len);
819 mutex_lock(&bcm->mutex);
820 spin_lock_irqsave(&bcm->irq_lock, flags);
821 spin_lock(&bcm->leds_lock);
823 if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)
824 err = bcm43xx_sprom_write(bcm, sprom);
825 spin_unlock(&bcm->leds_lock);
826 spin_unlock_irqrestore(&bcm->irq_lock, flags);
827 mutex_unlock(&bcm->mutex);
834 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
836 static struct iw_statistics *bcm43xx_get_wireless_stats(struct net_device *net_dev)
838 struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
839 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
840 struct iw_statistics *wstats;
841 struct ieee80211_network *network = NULL;
842 static int tmp_level = 0;
843 static int tmp_qual = 0;
846 wstats = &bcm->stats.wstats;
847 if (!mac->associnfo.associated) {
848 wstats->miss.beacon = 0;
849 // bcm->ieee->ieee_stats.tx_retry_limit_exceeded = 0; // FIXME: should this be cleared here?
850 wstats->discard.retries = 0;
851 // bcm->ieee->ieee_stats.tx_discards_wrong_sa = 0; // FIXME: same question
852 wstats->discard.nwid = 0;
853 // bcm->ieee->ieee_stats.rx_discards_undecryptable = 0; // FIXME: ditto
854 wstats->discard.code = 0;
855 // bcm->ieee->ieee_stats.rx_fragments = 0; // FIXME: same here
856 wstats->discard.fragment = 0;
857 wstats->discard.misc = 0;
858 wstats->qual.qual = 0;
859 wstats->qual.level = 0;
860 wstats->qual.noise = 0;
861 wstats->qual.updated = 7;
862 wstats->qual.updated |= IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
865 /* fill in the real statistics when iface associated */
866 spin_lock_irqsave(&mac->ieee->lock, flags);
867 list_for_each_entry(network, &mac->ieee->network_list, list) {
868 if (!memcmp(mac->associnfo.bssid, network->bssid, ETH_ALEN)) {
869 if (!tmp_level) { /* get initial values */
870 tmp_level = network->stats.signal;
871 tmp_qual = network->stats.rssi;
872 } else { /* smooth results */
873 tmp_level = (15 * tmp_level + network->stats.signal)/16;
874 tmp_qual = (15 * tmp_qual + network->stats.rssi)/16;
879 spin_unlock_irqrestore(&mac->ieee->lock, flags);
880 wstats->qual.level = tmp_level;
881 wstats->qual.qual = 100 * tmp_qual / RX_RSSI_MAX;
882 wstats->qual.noise = bcm->stats.noise;
883 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
884 wstats->discard.code = bcm->ieee->ieee_stats.rx_discards_undecryptable;
885 wstats->discard.retries = bcm->ieee->ieee_stats.tx_retry_limit_exceeded;
886 wstats->discard.nwid = bcm->ieee->ieee_stats.tx_discards_wrong_sa;
887 wstats->discard.fragment = bcm->ieee->ieee_stats.rx_fragments;
888 wstats->discard.misc = 0; // FIXME
889 wstats->miss.beacon = 0; // FIXME
897 #define WX(ioctl) [(ioctl) - SIOCSIWCOMMIT]
898 static const iw_handler bcm43xx_wx_handlers[] = {
899 /* Wireless Identification */
900 WX(SIOCGIWNAME) = bcm43xx_wx_get_name,
901 /* Basic operations */
902 WX(SIOCSIWFREQ) = bcm43xx_wx_set_channelfreq,
903 WX(SIOCGIWFREQ) = bcm43xx_wx_get_channelfreq,
904 WX(SIOCSIWMODE) = bcm43xx_wx_set_mode,
905 WX(SIOCGIWMODE) = bcm43xx_wx_get_mode,
906 /* Informative stuff */
907 WX(SIOCGIWRANGE) = bcm43xx_wx_get_rangeparams,
908 /* Access Point manipulation */
909 WX(SIOCSIWAP) = ieee80211softmac_wx_set_wap,
910 WX(SIOCGIWAP) = ieee80211softmac_wx_get_wap,
911 WX(SIOCSIWSCAN) = ieee80211softmac_wx_trigger_scan,
912 WX(SIOCGIWSCAN) = ieee80211softmac_wx_get_scan_results,
913 /* 802.11 specific support */
914 WX(SIOCSIWESSID) = ieee80211softmac_wx_set_essid,
915 WX(SIOCGIWESSID) = ieee80211softmac_wx_get_essid,
916 WX(SIOCSIWNICKN) = bcm43xx_wx_set_nick,
917 WX(SIOCGIWNICKN) = bcm43xx_wx_get_nick,
918 /* Other parameters */
919 WX(SIOCSIWRATE) = ieee80211softmac_wx_set_rate,
920 WX(SIOCGIWRATE) = ieee80211softmac_wx_get_rate,
921 WX(SIOCSIWRTS) = bcm43xx_wx_set_rts,
922 WX(SIOCGIWRTS) = bcm43xx_wx_get_rts,
923 WX(SIOCSIWFRAG) = bcm43xx_wx_set_frag,
924 WX(SIOCGIWFRAG) = bcm43xx_wx_get_frag,
925 WX(SIOCSIWTXPOW) = bcm43xx_wx_set_xmitpower,
926 WX(SIOCGIWTXPOW) = bcm43xx_wx_get_xmitpower,
927 //TODO WX(SIOCSIWRETRY) = bcm43xx_wx_set_retry,
928 //TODO WX(SIOCGIWRETRY) = bcm43xx_wx_get_retry,
930 WX(SIOCSIWENCODE) = bcm43xx_wx_set_encoding,
931 WX(SIOCGIWENCODE) = bcm43xx_wx_get_encoding,
932 WX(SIOCSIWENCODEEXT) = bcm43xx_wx_set_encodingext,
933 WX(SIOCGIWENCODEEXT) = bcm43xx_wx_get_encodingext,
935 //TODO WX(SIOCSIWPOWER) = bcm43xx_wx_set_power,
936 //TODO WX(SIOCGIWPOWER) = bcm43xx_wx_get_power,
937 WX(SIOCSIWGENIE) = ieee80211softmac_wx_set_genie,
938 WX(SIOCGIWGENIE) = ieee80211softmac_wx_get_genie,
939 WX(SIOCSIWAUTH) = ieee80211_wx_set_auth,
940 WX(SIOCGIWAUTH) = ieee80211_wx_get_auth,
944 static const iw_handler bcm43xx_priv_wx_handlers[] = {
945 /* Set Interference Mitigation Mode. */
946 bcm43xx_wx_set_interfmode,
947 /* Get Interference Mitigation Mode. */
948 bcm43xx_wx_get_interfmode,
949 /* Enable/Disable Short Preamble mode. */
950 bcm43xx_wx_set_shortpreamble,
951 /* Get Short Preamble mode. */
952 bcm43xx_wx_get_shortpreamble,
953 /* Enable/Disable Software Encryption mode */
954 bcm43xx_wx_set_swencryption,
955 /* Get Software Encryption mode */
956 bcm43xx_wx_get_swencryption,
957 /* Write SRPROM data. */
958 bcm43xx_wx_sprom_write,
959 /* Read SPROM data. */
960 bcm43xx_wx_sprom_read,
963 #define PRIV_WX_SET_INTERFMODE (SIOCIWFIRSTPRIV + 0)
964 #define PRIV_WX_GET_INTERFMODE (SIOCIWFIRSTPRIV + 1)
965 #define PRIV_WX_SET_SHORTPREAMBLE (SIOCIWFIRSTPRIV + 2)
966 #define PRIV_WX_GET_SHORTPREAMBLE (SIOCIWFIRSTPRIV + 3)
967 #define PRIV_WX_SET_SWENCRYPTION (SIOCIWFIRSTPRIV + 4)
968 #define PRIV_WX_GET_SWENCRYPTION (SIOCIWFIRSTPRIV + 5)
969 #define PRIV_WX_SPROM_WRITE (SIOCIWFIRSTPRIV + 6)
970 #define PRIV_WX_SPROM_READ (SIOCIWFIRSTPRIV + 7)
972 #define PRIV_WX_DUMMY(ioctl) \
978 static const struct iw_priv_args bcm43xx_priv_wx_args[] = {
980 .cmd = PRIV_WX_SET_INTERFMODE,
981 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
982 .name = "set_interfmode",
985 .cmd = PRIV_WX_GET_INTERFMODE,
986 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
987 .name = "get_interfmode",
990 .cmd = PRIV_WX_SET_SHORTPREAMBLE,
991 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
992 .name = "set_shortpreamb",
995 .cmd = PRIV_WX_GET_SHORTPREAMBLE,
996 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
997 .name = "get_shortpreamb",
1000 .cmd = PRIV_WX_SET_SWENCRYPTION,
1001 .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1002 .name = "set_swencrypt",
1005 .cmd = PRIV_WX_GET_SWENCRYPTION,
1006 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
1007 .name = "get_swencrypt",
1010 .cmd = PRIV_WX_SPROM_WRITE,
1011 .set_args = IW_PRIV_TYPE_CHAR | SPROM_BUFFERSIZE,
1012 .name = "write_sprom",
1015 .cmd = PRIV_WX_SPROM_READ,
1016 .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | SPROM_BUFFERSIZE,
1017 .name = "read_sprom",
1021 const struct iw_handler_def bcm43xx_wx_handlers_def = {
1022 .standard = bcm43xx_wx_handlers,
1023 .num_standard = ARRAY_SIZE(bcm43xx_wx_handlers),
1024 .num_private = ARRAY_SIZE(bcm43xx_priv_wx_handlers),
1025 .num_private_args = ARRAY_SIZE(bcm43xx_priv_wx_args),
1026 .private = bcm43xx_priv_wx_handlers,
1027 .private_args = bcm43xx_priv_wx_args,
1028 .get_wireless_stats = bcm43xx_get_wireless_stats,