[NET]: Introduce and use print_mac() and DECLARE_MAC_BUF()
[deliverable/linux.git] / net / ieee80211 / softmac / ieee80211softmac_wx.c
CommitLineData
370121e5
JB
1/*
2 * This file contains our _wx handlers. Make sure you EXPORT_SYMBOL_GPL them
4855d25b 3 *
79859051
JB
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>
4855d25b
JB
9 *
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.
13 *
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
17 * more details.
18 *
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
22 *
23 * The full GNU General Public License is included in this distribution in the
24 * file called COPYING.
370121e5
JB
25 */
26
27#include "ieee80211softmac_priv.h"
28
29#include <net/iw_handler.h>
818667f7
JB
30/* for is_broadcast_ether_addr and is_zero_ether_addr */
31#include <linux/etherdevice.h>
370121e5
JB
32
33int
34ieee80211softmac_wx_trigger_scan(struct net_device *net_dev,
35 struct iw_request_info *info,
36 union iwreq_data *data,
37 char *extra)
38{
39 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
40 return ieee80211softmac_start_scan(sm);
41}
42EXPORT_SYMBOL_GPL(ieee80211softmac_wx_trigger_scan);
43
44
ba2f8c18 45/* if we're still scanning, return -EAGAIN so that userspace tools
46 * can get the complete scan results, otherwise return 0. */
370121e5
JB
47int
48ieee80211softmac_wx_get_scan_results(struct net_device *net_dev,
49 struct iw_request_info *info,
50 union iwreq_data *data,
51 char *extra)
52{
ba2f8c18 53 unsigned long flags;
370121e5 54 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
ba2f8c18 55
56 spin_lock_irqsave(&sm->lock, flags);
57 if (sm->scanning) {
58 spin_unlock_irqrestore(&sm->lock, flags);
59 return -EAGAIN;
60 }
61 spin_unlock_irqrestore(&sm->lock, flags);
370121e5
JB
62 return ieee80211_wx_get_scan(sm->ieee, info, data, extra);
63}
64EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_scan_results);
65
66int
67ieee80211softmac_wx_set_essid(struct net_device *net_dev,
68 struct iw_request_info *info,
69 union iwreq_data *data,
70 char *extra)
71{
72 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
cb74c432 73 struct ieee80211softmac_auth_queue_item *authptr;
370121e5 74 int length = 0;
0795af57 75 DECLARE_MAC_BUF(mac);
7c28ad2d 76
fdc8f43b 77check_assoc_again:
7c28ad2d 78 mutex_lock(&sm->associnfo.mutex);
7c28ad2d 79 if((sm->associnfo.associating || sm->associnfo.associated) &&
b978d027 80 (data->essid.flags && data->essid.length)) {
efe870f9
LF
81 dprintk(KERN_INFO PFX "Canceling existing associate request!\n");
82 /* Cancel assoc work */
83 cancel_delayed_work(&sm->associnfo.work);
84 /* We don't have to do this, but it's a little cleaner */
85 list_for_each_entry(authptr, &sm->auth_queue, list)
86 cancel_delayed_work(&authptr->work);
87 sm->associnfo.bssvalid = 0;
88 sm->associnfo.bssfixed = 0;
89 sm->associnfo.associating = 0;
90 sm->associnfo.associated = 0;
91 /* We must unlock to avoid deadlocks with the assoc workqueue
92 * on the associnfo.mutex */
93 mutex_unlock(&sm->associnfo.mutex);
94 flush_scheduled_work();
95 /* Avoid race! Check assoc status again. Maybe someone started an
96 * association while we flushed. */
97 goto check_assoc_again;
cb74c432
JJ
98 }
99
370121e5 100 sm->associnfo.static_essid = 0;
cb74c432 101 sm->associnfo.assoc_wait = 0;
370121e5 102
b978d027
LF
103 if (data->essid.flags && data->essid.length) {
104 length = min((int)data->essid.length, IW_ESSID_MAX_SIZE);
370121e5
JB
105 if (length) {
106 memcpy(sm->associnfo.req_essid.data, extra, length);
107 sm->associnfo.static_essid = 1;
108 }
109 }
370121e5
JB
110
111 /* set our requested ESSID length.
112 * If applicable, we have already copied the data in */
113 sm->associnfo.req_essid.len = length;
114
7c28ad2d 115 sm->associnfo.associating = 1;
370121e5 116 /* queue lower level code to do work (if necessary) */
c4028958 117 schedule_delayed_work(&sm->associnfo.work, 0);
ee0a8169 118
7c28ad2d 119 mutex_unlock(&sm->associnfo.mutex);
370121e5 120
370121e5
JB
121 return 0;
122}
123EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_essid);
124
125int
126ieee80211softmac_wx_get_essid(struct net_device *net_dev,
127 struct iw_request_info *info,
128 union iwreq_data *data,
129 char *extra)
130{
131 struct ieee80211softmac_device *sm = ieee80211_priv(net_dev);
370121e5 132
7c28ad2d 133 mutex_lock(&sm->associnfo.mutex);
370121e5
JB
134 /* If all fails, return ANY (empty) */
135 data->essid.length = 0;
136 data->essid.flags = 0; /* active */
64265651 137
370121e5
JB
138 /* If we have a statically configured ESSID then return it */
139 if (sm->associnfo.static_essid) {
140 data->essid.length = sm->associnfo.req_essid.len;
141 data->essid.flags = 1; /* active */
142 memcpy(extra, sm->associnfo.req_essid.data, sm->associnfo.req_essid.len);
efe870f9
LF
143 dprintk(KERN_INFO PFX "Getting essid from req_essid\n");
144 } else if (sm->associnfo.associated || sm->associnfo.associating) {
370121e5 145 /* If we're associating/associated, return that */
370121e5
JB
146 data->essid.length = sm->associnfo.associate_essid.len;
147 data->essid.flags = 1; /* active */
148 memcpy(extra, sm->associnfo.associate_essid.data, sm->associnfo.associate_essid.len);
efe870f9 149 dprintk(KERN_INFO PFX "Getting essid from associate_essid\n");
370121e5 150 }
7c28ad2d
MB
151 mutex_unlock(&sm->associnfo.mutex);
152
370121e5
JB
153 return 0;
154}
155EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_essid);
156
157int
158ieee80211softmac_wx_set_rate(struct net_device *net_dev,
159 struct iw_request_info *info,
160 union iwreq_data *data,
161 char *extra)
162{
163 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
164 struct ieee80211_device *ieee = mac->ieee;
165 unsigned long flags;
166 s32 in_rate = data->bitrate.value;
167 u8 rate;
168 int is_ofdm = 0;
169 int err = -EINVAL;
170
171 if (in_rate == -1) {
bb52a653
LF
172 if (ieee->modulation & IEEE80211_OFDM_MODULATION)
173 in_rate = 24000000;
2638fed7 174 else
bb52a653 175 in_rate = 11000000;
370121e5
JB
176 }
177
178 switch (in_rate) {
179 case 1000000:
180 rate = IEEE80211_CCK_RATE_1MB;
181 break;
182 case 2000000:
183 rate = IEEE80211_CCK_RATE_2MB;
184 break;
185 case 5500000:
186 rate = IEEE80211_CCK_RATE_5MB;
187 break;
188 case 11000000:
189 rate = IEEE80211_CCK_RATE_11MB;
190 break;
191 case 6000000:
192 rate = IEEE80211_OFDM_RATE_6MB;
193 is_ofdm = 1;
194 break;
195 case 9000000:
196 rate = IEEE80211_OFDM_RATE_9MB;
197 is_ofdm = 1;
198 break;
199 case 12000000:
200 rate = IEEE80211_OFDM_RATE_12MB;
201 is_ofdm = 1;
202 break;
203 case 18000000:
204 rate = IEEE80211_OFDM_RATE_18MB;
205 is_ofdm = 1;
206 break;
207 case 24000000:
208 rate = IEEE80211_OFDM_RATE_24MB;
209 is_ofdm = 1;
210 break;
211 case 36000000:
212 rate = IEEE80211_OFDM_RATE_36MB;
213 is_ofdm = 1;
214 break;
215 case 48000000:
216 rate = IEEE80211_OFDM_RATE_48MB;
217 is_ofdm = 1;
218 break;
219 case 54000000:
220 rate = IEEE80211_OFDM_RATE_54MB;
221 is_ofdm = 1;
222 break;
223 default:
224 goto out;
225 }
226
227 spin_lock_irqsave(&mac->lock, flags);
228
229 /* Check if correct modulation for this PHY. */
230 if (is_ofdm && !(ieee->modulation & IEEE80211_OFDM_MODULATION))
231 goto out_unlock;
232
8462fe3c
DD
233 mac->txrates.user_rate = rate;
234 ieee80211softmac_recalc_txrates(mac);
370121e5
JB
235 err = 0;
236
64265651 237out_unlock:
370121e5
JB
238 spin_unlock_irqrestore(&mac->lock, flags);
239out:
240 return err;
241}
242EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_rate);
243
244int
245ieee80211softmac_wx_get_rate(struct net_device *net_dev,
246 struct iw_request_info *info,
247 union iwreq_data *data,
248 char *extra)
249{
250 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
251 unsigned long flags;
252 int err = -EINVAL;
253
254 spin_lock_irqsave(&mac->lock, flags);
6bbdce5a
JL
255
256 if (unlikely(!mac->running)) {
257 err = -ENODEV;
258 goto out_unlock;
259 }
260
370121e5
JB
261 switch (mac->txrates.default_rate) {
262 case IEEE80211_CCK_RATE_1MB:
263 data->bitrate.value = 1000000;
264 break;
265 case IEEE80211_CCK_RATE_2MB:
266 data->bitrate.value = 2000000;
267 break;
268 case IEEE80211_CCK_RATE_5MB:
269 data->bitrate.value = 5500000;
270 break;
271 case IEEE80211_CCK_RATE_11MB:
272 data->bitrate.value = 11000000;
273 break;
274 case IEEE80211_OFDM_RATE_6MB:
275 data->bitrate.value = 6000000;
276 break;
277 case IEEE80211_OFDM_RATE_9MB:
278 data->bitrate.value = 9000000;
279 break;
280 case IEEE80211_OFDM_RATE_12MB:
281 data->bitrate.value = 12000000;
282 break;
283 case IEEE80211_OFDM_RATE_18MB:
284 data->bitrate.value = 18000000;
285 break;
286 case IEEE80211_OFDM_RATE_24MB:
287 data->bitrate.value = 24000000;
288 break;
289 case IEEE80211_OFDM_RATE_36MB:
290 data->bitrate.value = 36000000;
291 break;
292 case IEEE80211_OFDM_RATE_48MB:
293 data->bitrate.value = 48000000;
294 break;
295 case IEEE80211_OFDM_RATE_54MB:
296 data->bitrate.value = 54000000;
297 break;
298 default:
299 assert(0);
300 goto out_unlock;
301 }
302 err = 0;
303out_unlock:
304 spin_unlock_irqrestore(&mac->lock, flags);
305
306 return err;
307}
308EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_rate);
309
310int
311ieee80211softmac_wx_get_wap(struct net_device *net_dev,
312 struct iw_request_info *info,
313 union iwreq_data *data,
314 char *extra)
315{
316 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
317 int err = 0;
370121e5 318
7c28ad2d 319 mutex_lock(&mac->associnfo.mutex);
370121e5
JB
320 if (mac->associnfo.bssvalid)
321 memcpy(data->ap_addr.sa_data, mac->associnfo.bssid, ETH_ALEN);
322 else
323 memset(data->ap_addr.sa_data, 0xff, ETH_ALEN);
324 data->ap_addr.sa_family = ARPHRD_ETHER;
7c28ad2d
MB
325 mutex_unlock(&mac->associnfo.mutex);
326
370121e5
JB
327 return err;
328}
329EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_wap);
330
331int
332ieee80211softmac_wx_set_wap(struct net_device *net_dev,
333 struct iw_request_info *info,
334 union iwreq_data *data,
335 char *extra)
336{
337 struct ieee80211softmac_device *mac = ieee80211_priv(net_dev);
370121e5
JB
338
339 /* sanity check */
340 if (data->ap_addr.sa_family != ARPHRD_ETHER) {
341 return -EINVAL;
342 }
343
7c28ad2d 344 mutex_lock(&mac->associnfo.mutex);
818667f7
JB
345 if (is_broadcast_ether_addr(data->ap_addr.sa_data)) {
346 /* the bssid we have is not to be fixed any longer,
347 * and we should reassociate to the best AP. */
348 mac->associnfo.bssfixed = 0;
349 /* force reassociation */
350 mac->associnfo.bssvalid = 0;
7c28ad2d 351 if (mac->associnfo.associated)
c4028958 352 schedule_delayed_work(&mac->associnfo.work, 0);
818667f7
JB
353 } else if (is_zero_ether_addr(data->ap_addr.sa_data)) {
354 /* the bssid we have is no longer fixed */
355 mac->associnfo.bssfixed = 0;
64265651 356 } else {
370121e5 357 if (!memcmp(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN)) {
7c28ad2d 358 if (mac->associnfo.associating || mac->associnfo.associated) {
370121e5
JB
359 /* bssid unchanged and associated or associating - just return */
360 goto out;
361 }
362 } else {
363 /* copy new value in data->ap_addr.sa_data to bssid */
364 memcpy(mac->associnfo.bssid, data->ap_addr.sa_data, ETH_ALEN);
818667f7
JB
365 }
366 /* tell the other code that this bssid should be used no matter what */
367 mac->associnfo.bssfixed = 1;
370121e5 368 /* queue associate if new bssid or (old one again and not associated) */
c4028958 369 schedule_delayed_work(&mac->associnfo.work, 0);
64265651 370 }
370121e5 371
818667f7 372 out:
7c28ad2d
MB
373 mutex_unlock(&mac->associnfo.mutex);
374
370121e5
JB
375 return 0;
376}
377EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_wap);
378
379int
380ieee80211softmac_wx_set_genie(struct net_device *dev,
381 struct iw_request_info *info,
382 union iwreq_data *wrqu,
383 char *extra)
384{
385 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
386 unsigned long flags;
387 int err = 0;
388 char *buf;
389 int i;
7c28ad2d
MB
390
391 mutex_lock(&mac->associnfo.mutex);
370121e5
JB
392 spin_lock_irqsave(&mac->lock, flags);
393 /* bleh. shouldn't be locked for that kmalloc... */
394
395 if (wrqu->data.length) {
396 if ((wrqu->data.length < 2) || (extra[1]+2 != wrqu->data.length)) {
397 /* this is an IE, so the length must be
398 * correct. Is it possible though that
399 * more than one IE is passed in?
400 */
401 err = -EINVAL;
402 goto out;
403 }
404 if (mac->wpa.IEbuflen <= wrqu->data.length) {
405 buf = kmalloc(wrqu->data.length, GFP_ATOMIC);
406 if (!buf) {
407 err = -ENOMEM;
408 goto out;
409 }
410 kfree(mac->wpa.IE);
411 mac->wpa.IE = buf;
412 mac->wpa.IEbuflen = wrqu->data.length;
413 }
414 memcpy(mac->wpa.IE, extra, wrqu->data.length);
415 dprintk(KERN_INFO PFX "generic IE set to ");
416 for (i=0;i<wrqu->data.length;i++)
7bd6b918 417 dprintk("%.2x", (u8)mac->wpa.IE[i]);
370121e5
JB
418 dprintk("\n");
419 mac->wpa.IElen = wrqu->data.length;
420 } else {
421 kfree(mac->wpa.IE);
422 mac->wpa.IE = NULL;
423 mac->wpa.IElen = 0;
424 mac->wpa.IEbuflen = 0;
425 }
426
64265651 427 out:
370121e5 428 spin_unlock_irqrestore(&mac->lock, flags);
7c28ad2d
MB
429 mutex_unlock(&mac->associnfo.mutex);
430
370121e5
JB
431 return err;
432}
433EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_genie);
434
435int
436ieee80211softmac_wx_get_genie(struct net_device *dev,
437 struct iw_request_info *info,
438 union iwreq_data *wrqu,
439 char *extra)
440{
441 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
442 unsigned long flags;
443 int err = 0;
444 int space = wrqu->data.length;
7c28ad2d
MB
445
446 mutex_lock(&mac->associnfo.mutex);
370121e5 447 spin_lock_irqsave(&mac->lock, flags);
64265651 448
370121e5 449 wrqu->data.length = 0;
64265651 450
370121e5
JB
451 if (mac->wpa.IE && mac->wpa.IElen) {
452 wrqu->data.length = mac->wpa.IElen;
453 if (mac->wpa.IElen <= space)
454 memcpy(extra, mac->wpa.IE, mac->wpa.IElen);
455 else
456 err = -E2BIG;
457 }
458 spin_unlock_irqrestore(&mac->lock, flags);
0c234ae6 459 mutex_unlock(&mac->associnfo.mutex);
7c28ad2d 460
370121e5
JB
461 return err;
462}
463EXPORT_SYMBOL_GPL(ieee80211softmac_wx_get_genie);
464
9a1771e8
JB
465int
466ieee80211softmac_wx_set_mlme(struct net_device *dev,
467 struct iw_request_info *info,
468 union iwreq_data *wrqu,
469 char *extra)
470{
471 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
472 struct iw_mlme *mlme = (struct iw_mlme *)extra;
473 u16 reason = cpu_to_le16(mlme->reason_code);
474 struct ieee80211softmac_network *net;
7c28ad2d
MB
475 int err = -EINVAL;
476
477 mutex_lock(&mac->associnfo.mutex);
9a1771e8
JB
478
479 if (memcmp(mac->associnfo.bssid, mlme->addr.sa_data, ETH_ALEN)) {
480 printk(KERN_DEBUG PFX "wx_set_mlme: requested operation on net we don't use\n");
7c28ad2d 481 goto out;
9a1771e8
JB
482 }
483
484 switch (mlme->cmd) {
485 case IW_MLME_DEAUTH:
486 net = ieee80211softmac_get_network_by_bssid_locked(mac, mlme->addr.sa_data);
487 if (!net) {
488 printk(KERN_DEBUG PFX "wx_set_mlme: we should know the net here...\n");
7c28ad2d 489 goto out;
9a1771e8 490 }
cc8ce997
MA
491 err = ieee80211softmac_deauth_req(mac, net, reason);
492 goto out;
9a1771e8 493 case IW_MLME_DISASSOC:
6d92f83f 494 ieee80211softmac_send_disassoc_req(mac, reason);
7c28ad2d
MB
495 mac->associnfo.associated = 0;
496 mac->associnfo.associating = 0;
497 err = 0;
498 goto out;
9a1771e8 499 default:
7c28ad2d 500 err = -EOPNOTSUPP;
9a1771e8 501 }
7c28ad2d
MB
502
503out:
504 mutex_unlock(&mac->associnfo.mutex);
505
506 return err;
9a1771e8
JB
507}
508EXPORT_SYMBOL_GPL(ieee80211softmac_wx_set_mlme);
This page took 0.197931 seconds and 5 git commands to generate.