2 * This file contains our _wx handlers. Make sure you EXPORT_SYMBOL_GPL them
4 * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net>
5 * Joseph Jezak <josejx@gentoo.org>
6 * Larry Finger <Larry.Finger@lwfinger.net>
7 * Danny van Dyk <kugelfang@gentoo.org>
8 * Michael Buesch <mbuesch@freenet.de>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * The full GNU General Public License is included in this distribution in the
24 * file called COPYING.
27 #include "ieee80211softmac_priv.h"
29 #include <net/iw_handler.h>
30 /* for is_broadcast_ether_addr and is_zero_ether_addr */
31 #include <linux/etherdevice.h>
34 ieee80211softmac_wx_trigger_scan(struct net_device *net_dev,
35 struct iw_request_info *info,
36 union iwreq_data *data,
39 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
40 return ieee80211softmac_start_scan(sm);
42 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_trigger_scan);
45 /* if we're still scanning, return -EAGAIN so that userspace tools
46 * can get the complete scan results, otherwise return 0. */
48 ieee80211softmac_wx_get_scan_results(struct net_device *net_dev,
49 struct iw_request_info *info,
50 union iwreq_data *data,
54 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
56 spin_lock_irqsave(&sm->lock, flags);
58 spin_unlock_irqrestore(&sm->lock, flags);
61 spin_unlock_irqrestore(&sm->lock, flags);
62 return ieee80211_wx_get_scan(sm->ieee, info, data, extra);
64 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_scan_results);
67 ieee80211softmac_wx_set_essid(struct net_device *net_dev,
68 struct iw_request_info *info,
69 union iwreq_data *data,
72 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
76 spin_lock_irqsave(&sm->lock, flags);
78 sm->associnfo.static_essid = 0;
80 if (data->essid.flags && data->essid.length && extra /*required?*/) {
81 length = min(data->essid.length - 1, IW_ESSID_MAX_SIZE);
83 memcpy(sm->associnfo.req_essid.data, extra, length);
84 sm->associnfo.static_essid = 1;
88 /* set our requested ESSID length.
89 * If applicable, we have already copied the data in */
90 sm->associnfo.req_essid.len = length;
92 /* queue lower level code to do work (if necessary) */
93 schedule_work(&sm->associnfo.work);
95 spin_unlock_irqrestore(&sm->lock, flags);
98 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_essid);
101 ieee80211softmac_wx_get_essid(struct net_device *net_dev,
102 struct iw_request_info *info,
103 union iwreq_data *data,
106 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
109 /* avoid getting inconsistent information */
110 spin_lock_irqsave(&sm->lock, flags);
111 /* If all fails, return ANY (empty) */
112 data->essid.length = 0;
113 data->essid.flags = 0; /* active */
115 /* If we have a statically configured ESSID then return it */
116 if (sm->associnfo.static_essid) {
117 data->essid.length = sm->associnfo.req_essid.len;
118 data->essid.flags = 1; /* active */
119 memcpy(extra, sm->associnfo.req_essid.data, sm->associnfo.req_essid.len);
122 /* If we're associating/associated, return that */
123 if (sm->associated || sm->associnfo.associating) {
124 data->essid.length = sm->associnfo.associate_essid.len;
125 data->essid.flags = 1; /* active */
126 memcpy(extra, sm->associnfo.associate_essid.data, sm->associnfo.associate_essid.len);
128 spin_unlock_irqrestore(&sm->lock, flags);
131 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_essid);
134 ieee80211softmac_wx_set_rate(struct net_device *net_dev,
135 struct iw_request_info *info,
136 union iwreq_data *data,
139 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
140 struct ieee80211_device *ieee = mac->ieee;
142 s32 in_rate = data->bitrate.value;
148 /* FIXME: We don't correctly handle backing down to lower
149 rates, so 801.11g devices start off at 11M for now. People
150 can manually change it if they really need to, but 11M is
151 more reliable. Note similar logic in
152 ieee80211softmac_wx_set_rate() */
153 if (ieee->modulation & IEEE80211_CCK_MODULATION)
161 rate = IEEE80211_CCK_RATE_1MB;
164 rate = IEEE80211_CCK_RATE_2MB;
167 rate = IEEE80211_CCK_RATE_5MB;
170 rate = IEEE80211_CCK_RATE_11MB;
173 rate = IEEE80211_OFDM_RATE_6MB;
177 rate = IEEE80211_OFDM_RATE_9MB;
181 rate = IEEE80211_OFDM_RATE_12MB;
185 rate = IEEE80211_OFDM_RATE_18MB;
189 rate = IEEE80211_OFDM_RATE_24MB;
193 rate = IEEE80211_OFDM_RATE_36MB;
197 rate = IEEE80211_OFDM_RATE_48MB;
201 rate = IEEE80211_OFDM_RATE_54MB;
208 spin_lock_irqsave(&mac->lock, flags);
210 /* Check if correct modulation for this PHY. */
211 if (is_ofdm && !(ieee->modulation & IEEE80211_OFDM_MODULATION))
214 mac->txrates.default_rate = rate;
215 mac->txrates.default_fallback = lower_rate(mac, rate);
219 spin_unlock_irqrestore(&mac->lock, flags);
223 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_rate);
226 ieee80211softmac_wx_get_rate(struct net_device *net_dev,
227 struct iw_request_info *info,
228 union iwreq_data *data,
231 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
235 spin_lock_irqsave(&mac->lock, flags);
236 switch (mac->txrates.default_rate) {
237 case IEEE80211_CCK_RATE_1MB:
238 data->bitrate.value = 1000000;
240 case IEEE80211_CCK_RATE_2MB:
241 data->bitrate.value = 2000000;
243 case IEEE80211_CCK_RATE_5MB:
244 data->bitrate.value = 5500000;
246 case IEEE80211_CCK_RATE_11MB:
247 data->bitrate.value = 11000000;
249 case IEEE80211_OFDM_RATE_6MB:
250 data->bitrate.value = 6000000;
252 case IEEE80211_OFDM_RATE_9MB:
253 data->bitrate.value = 9000000;
255 case IEEE80211_OFDM_RATE_12MB:
256 data->bitrate.value = 12000000;
258 case IEEE80211_OFDM_RATE_18MB:
259 data->bitrate.value = 18000000;
261 case IEEE80211_OFDM_RATE_24MB:
262 data->bitrate.value = 24000000;
264 case IEEE80211_OFDM_RATE_36MB:
265 data->bitrate.value = 36000000;
267 case IEEE80211_OFDM_RATE_48MB:
268 data->bitrate.value = 48000000;
270 case IEEE80211_OFDM_RATE_54MB:
271 data->bitrate.value = 54000000;
279 spin_unlock_irqrestore(&mac->lock, flags);
283 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_rate);
286 ieee80211softmac_wx_get_wap(struct net_device *net_dev,
287 struct iw_request_info *info,
288 union iwreq_data *data,
291 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
295 spin_lock_irqsave(&mac->lock, flags);
296 if (mac->associnfo.bssvalid)
297 memcpy(data->ap_addr.sa_data, mac->associnfo.bssid, ETH_ALEN);
299 memset(data->ap_addr.sa_data, 0xff, ETH_ALEN);
300 data->ap_addr.sa_family = ARPHRD_ETHER;
301 spin_unlock_irqrestore(&mac->lock, flags);
304 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_wap);
307 ieee80211softmac_wx_set_wap(struct net_device *net_dev,
308 struct iw_request_info *info,
309 union iwreq_data *data,
312 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
316 if (data->ap_addr.sa_family != ARPHRD_ETHER) {
320 spin_lock_irqsave(&mac->lock, flags);
321 if (is_broadcast_ether_addr(data->ap_addr.sa_data)) {
322 /* the bssid we have is not to be fixed any longer,
323 * and we should reassociate to the best AP. */
324 mac->associnfo.bssfixed = 0;
325 /* force reassociation */
326 mac->associnfo.bssvalid = 0;
328 schedule_work(&mac->associnfo.work);
329 } else if (is_zero_ether_addr(data->ap_addr.sa_data)) {
330 /* the bssid we have is no longer fixed */
331 mac->associnfo.bssfixed = 0;
333 if (!memcmp(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN)) {
334 if (mac->associnfo.associating || mac->associated) {
335 /* bssid unchanged and associated or associating - just return */
339 /* copy new value in data->ap_addr.sa_data to bssid */
340 memcpy(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN);
342 /* tell the other code that this bssid should be used no matter what */
343 mac->associnfo.bssfixed = 1;
344 /* queue associate if new bssid or (old one again and not associated) */
345 schedule_work(&mac->associnfo.work);
349 spin_unlock_irqrestore(&mac->lock, flags);
352 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_wap);
355 ieee80211softmac_wx_set_genie(struct net_device *dev,
356 struct iw_request_info *info,
357 union iwreq_data *wrqu,
360 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
366 spin_lock_irqsave(&mac->lock, flags);
367 /* bleh. shouldn't be locked for that kmalloc... */
369 if (wrqu->data.length) {
370 if ((wrqu->data.length < 2) || (extra[1]+2 != wrqu->data.length)) {
371 /* this is an IE, so the length must be
372 * correct. Is it possible though that
373 * more than one IE is passed in?
378 if (mac->wpa.IEbuflen <= wrqu->data.length) {
379 buf = kmalloc(wrqu->data.length, GFP_ATOMIC);
386 mac->wpa.IEbuflen = wrqu->data.length;
388 memcpy(mac->wpa.IE, extra, wrqu->data.length);
389 dprintk(KERN_INFO PFX "generic IE set to ");
390 for (i=0;i<wrqu->data.length;i++)
391 dprintk("%.2x", mac->wpa.IE[i]);
393 mac->wpa.IElen = wrqu->data.length;
398 mac->wpa.IEbuflen = 0;
402 spin_unlock_irqrestore(&mac->lock, flags);
405 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_genie);
408 ieee80211softmac_wx_get_genie(struct net_device *dev,
409 struct iw_request_info *info,
410 union iwreq_data *wrqu,
413 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
416 int space = wrqu->data.length;
418 spin_lock_irqsave(&mac->lock, flags);
420 wrqu->data.length = 0;
422 if (mac->wpa.IE && mac->wpa.IElen) {
423 wrqu->data.length = mac->wpa.IElen;
424 if (mac->wpa.IElen <= space)
425 memcpy(extra, mac->wpa.IE, mac->wpa.IElen);
429 spin_unlock_irqrestore(&mac->lock, flags);
432 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_genie);
435 ieee80211softmac_wx_set_mlme(struct net_device *dev,
436 struct iw_request_info *info,
437 union iwreq_data *wrqu,
440 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
441 struct iw_mlme *mlme = (struct iw_mlme *)extra;
442 u16 reason = cpu_to_le16(mlme->reason_code);
443 struct ieee80211softmac_network *net;
445 if (memcmp(mac->associnfo.bssid, mlme->addr.sa_data, ETH_ALEN)) {
446 printk(KERN_DEBUG PFX "wx_set_mlme: requested operation on net we don't use\n");
452 net = ieee80211softmac_get_network_by_bssid_locked(mac, mlme->addr.sa_data);
454 printk(KERN_DEBUG PFX "wx_set_mlme: we should know the net here...\n");
457 return ieee80211softmac_deauth_req(mac, net, reason);
458 case IW_MLME_DISASSOC:
459 ieee80211softmac_disassoc(mac, reason);
465 EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_mlme);