net: add IFF_SKB_TX_SHARED flag to priv_flags
[deliverable/linux.git] / drivers / net / wireless / hostap / hostap_main.c
CommitLineData
ff1d2767
JM
1/*
2 * Host AP (software wireless LAN access point) driver for
3 * Intersil Prism2/2.5/3 - hostap.o module, common routines
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
85d32e7b
JM
6 * <j@w1.fi>
7 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
ff1d2767
JM
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. See README and COPYING for
12 * more details.
13 */
14
ff1d2767
JM
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/slab.h>
18#include <linux/proc_fs.h>
19#include <linux/if_arp.h>
20#include <linux/delay.h>
21#include <linux/random.h>
22#include <linux/workqueue.h>
23#include <linux/kmod.h>
24#include <linux/rtnetlink.h>
25#include <linux/wireless.h>
5fad5a2e 26#include <linux/etherdevice.h>
457c4cbc 27#include <net/net_namespace.h>
ff1d2767 28#include <net/iw_handler.h>
274bfb8d 29#include <net/lib80211.h>
ff1d2767
JM
30#include <asm/uaccess.h>
31
32#include "hostap_wlan.h"
33#include "hostap_80211.h"
34#include "hostap_ap.h"
35#include "hostap.h"
ff1d2767
JM
36
37MODULE_AUTHOR("Jouni Malinen");
38MODULE_DESCRIPTION("Host AP common routines");
39MODULE_LICENSE("GPL");
40
ff1d2767
JM
41#define TX_TIMEOUT (2 * HZ)
42
43#define PRISM2_MAX_FRAME_SIZE 2304
44#define PRISM2_MIN_MTU 256
45/* FIX: */
46#define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 /* LLC */ + 8 /* WEP */))
47
48
ff1d2767
JM
49struct net_device * hostap_add_interface(struct local_info *local,
50 int type, int rtnl_locked,
51 const char *prefix,
52 const char *name)
53{
54 struct net_device *dev, *mdev;
55 struct hostap_interface *iface;
56 int ret;
57
58 dev = alloc_etherdev(sizeof(struct hostap_interface));
59 if (dev == NULL)
60 return NULL;
61
62 iface = netdev_priv(dev);
63 iface->dev = dev;
64 iface->local = local;
65 iface->type = type;
66 list_add(&iface->list, &local->hostap_interfaces);
67
68 mdev = local->dev;
69 memcpy(dev->dev_addr, mdev->dev_addr, ETH_ALEN);
70 dev->base_addr = mdev->base_addr;
71 dev->irq = mdev->irq;
72 dev->mem_start = mdev->mem_start;
73 dev->mem_end = mdev->mem_end;
74
09703f5e 75 hostap_setup_dev(dev, local, type);
ff1d2767
JM
76 dev->destructor = free_netdev;
77
78 sprintf(dev->name, "%s%s", prefix, name);
79 if (!rtnl_locked)
80 rtnl_lock();
81
43cb76d9 82 SET_NETDEV_DEV(dev, mdev->dev.parent);
1c5cae81 83 ret = register_netdevice(dev);
ff1d2767
JM
84
85 if (!rtnl_locked)
86 rtnl_unlock();
87
88 if (ret < 0) {
89 printk(KERN_WARNING "%s: failed to add new netdevice!\n",
90 dev->name);
91 free_netdev(dev);
92 return NULL;
93 }
94
95 printk(KERN_DEBUG "%s: registered netdevice %s\n",
96 mdev->name, dev->name);
97
98 return dev;
99}
100
101
102void hostap_remove_interface(struct net_device *dev, int rtnl_locked,
103 int remove_from_list)
104{
105 struct hostap_interface *iface;
106
107 if (!dev)
108 return;
109
110 iface = netdev_priv(dev);
111
112 if (remove_from_list) {
113 list_del(&iface->list);
114 }
115
116 if (dev == iface->local->ddev)
117 iface->local->ddev = NULL;
118 else if (dev == iface->local->apdev)
119 iface->local->apdev = NULL;
120 else if (dev == iface->local->stadev)
121 iface->local->stadev = NULL;
122
123 if (rtnl_locked)
124 unregister_netdevice(dev);
125 else
126 unregister_netdev(dev);
127
128 /* dev->destructor = free_netdev() will free the device data, including
129 * private data, when removing the device */
130}
131
132
133static inline int prism2_wds_special_addr(u8 *addr)
134{
135 if (addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5])
136 return 0;
137
138 return 1;
139}
140
141
5fad5a2e
AB
142int prism2_wds_add(local_info_t *local, u8 *remote_addr,
143 int rtnl_locked)
ff1d2767
JM
144{
145 struct net_device *dev;
146 struct list_head *ptr;
147 struct hostap_interface *iface, *empty, *match;
148
149 empty = match = NULL;
150 read_lock_bh(&local->iface_lock);
151 list_for_each(ptr, &local->hostap_interfaces) {
152 iface = list_entry(ptr, struct hostap_interface, list);
153 if (iface->type != HOSTAP_INTERFACE_WDS)
154 continue;
155
156 if (prism2_wds_special_addr(iface->u.wds.remote_addr))
157 empty = iface;
158 else if (memcmp(iface->u.wds.remote_addr, remote_addr,
159 ETH_ALEN) == 0) {
160 match = iface;
161 break;
162 }
163 }
164 if (!match && empty && !prism2_wds_special_addr(remote_addr)) {
165 /* take pre-allocated entry into use */
166 memcpy(empty->u.wds.remote_addr, remote_addr, ETH_ALEN);
167 read_unlock_bh(&local->iface_lock);
168 printk(KERN_DEBUG "%s: using pre-allocated WDS netdevice %s\n",
169 local->dev->name, empty->dev->name);
170 return 0;
171 }
172 read_unlock_bh(&local->iface_lock);
173
174 if (!prism2_wds_special_addr(remote_addr)) {
175 if (match)
176 return -EEXIST;
177 hostap_add_sta(local->ap, remote_addr);
178 }
179
180 if (local->wds_connections >= local->wds_max_connections)
181 return -ENOBUFS;
182
183 /* verify that there is room for wds# postfix in the interface name */
8b967e41 184 if (strlen(local->dev->name) >= IFNAMSIZ - 5) {
ff1d2767
JM
185 printk(KERN_DEBUG "'%s' too long base device name\n",
186 local->dev->name);
187 return -EINVAL;
188 }
189
190 dev = hostap_add_interface(local, HOSTAP_INTERFACE_WDS, rtnl_locked,
191 local->ddev->name, "wds%d");
192 if (dev == NULL)
193 return -ENOMEM;
194
195 iface = netdev_priv(dev);
196 memcpy(iface->u.wds.remote_addr, remote_addr, ETH_ALEN);
197
198 local->wds_connections++;
199
200 return 0;
201}
202
203
5fad5a2e
AB
204int prism2_wds_del(local_info_t *local, u8 *remote_addr,
205 int rtnl_locked, int do_not_remove)
ff1d2767
JM
206{
207 unsigned long flags;
208 struct list_head *ptr;
209 struct hostap_interface *iface, *selected = NULL;
210
211 write_lock_irqsave(&local->iface_lock, flags);
212 list_for_each(ptr, &local->hostap_interfaces) {
213 iface = list_entry(ptr, struct hostap_interface, list);
214 if (iface->type != HOSTAP_INTERFACE_WDS)
215 continue;
216
217 if (memcmp(iface->u.wds.remote_addr, remote_addr,
218 ETH_ALEN) == 0) {
219 selected = iface;
220 break;
221 }
222 }
223 if (selected && !do_not_remove)
224 list_del(&selected->list);
225 write_unlock_irqrestore(&local->iface_lock, flags);
226
227 if (selected) {
228 if (do_not_remove)
229 memset(selected->u.wds.remote_addr, 0, ETH_ALEN);
230 else {
231 hostap_remove_interface(selected->dev, rtnl_locked, 0);
232 local->wds_connections--;
233 }
234 }
235
236 return selected ? 0 : -ENODEV;
237}
238
239
240u16 hostap_tx_callback_register(local_info_t *local,
241 void (*func)(struct sk_buff *, int ok, void *),
242 void *data)
243{
244 unsigned long flags;
245 struct hostap_tx_callback_info *entry;
246
5cbded58 247 entry = kmalloc(sizeof(*entry),
ff1d2767
JM
248 GFP_ATOMIC);
249 if (entry == NULL)
250 return 0;
251
252 entry->func = func;
253 entry->data = data;
254
255 spin_lock_irqsave(&local->lock, flags);
256 entry->idx = local->tx_callback ? local->tx_callback->idx + 1 : 1;
257 entry->next = local->tx_callback;
258 local->tx_callback = entry;
259 spin_unlock_irqrestore(&local->lock, flags);
260
261 return entry->idx;
262}
263
264
265int hostap_tx_callback_unregister(local_info_t *local, u16 idx)
266{
267 unsigned long flags;
268 struct hostap_tx_callback_info *cb, *prev = NULL;
269
270 spin_lock_irqsave(&local->lock, flags);
271 cb = local->tx_callback;
272 while (cb != NULL && cb->idx != idx) {
273 prev = cb;
274 cb = cb->next;
275 }
276 if (cb) {
277 if (prev == NULL)
278 local->tx_callback = cb->next;
279 else
280 prev->next = cb->next;
281 kfree(cb);
282 }
283 spin_unlock_irqrestore(&local->lock, flags);
284
285 return cb ? 0 : -1;
286}
287
288
289/* val is in host byte order */
290int hostap_set_word(struct net_device *dev, int rid, u16 val)
291{
292 struct hostap_interface *iface;
8a9faf3c 293 __le16 tmp = cpu_to_le16(val);
ff1d2767
JM
294 iface = netdev_priv(dev);
295 return iface->local->func->set_rid(dev, rid, &tmp, 2);
296}
297
298
299int hostap_set_string(struct net_device *dev, int rid, const char *val)
300{
301 struct hostap_interface *iface;
302 char buf[MAX_SSID_LEN + 2];
303 int len;
304
305 iface = netdev_priv(dev);
306 len = strlen(val);
307 if (len > MAX_SSID_LEN)
308 return -1;
309 memset(buf, 0, sizeof(buf));
310 buf[0] = len; /* little endian 16 bit word */
311 memcpy(buf + 2, val, len);
312
313 return iface->local->func->set_rid(dev, rid, &buf, MAX_SSID_LEN + 2);
314}
315
316
317u16 hostap_get_porttype(local_info_t *local)
318{
319 if (local->iw_mode == IW_MODE_ADHOC && local->pseudo_adhoc)
320 return HFA384X_PORTTYPE_PSEUDO_IBSS;
321 if (local->iw_mode == IW_MODE_ADHOC)
322 return HFA384X_PORTTYPE_IBSS;
323 if (local->iw_mode == IW_MODE_INFRA)
324 return HFA384X_PORTTYPE_BSS;
325 if (local->iw_mode == IW_MODE_REPEAT)
326 return HFA384X_PORTTYPE_WDS;
327 if (local->iw_mode == IW_MODE_MONITOR)
328 return HFA384X_PORTTYPE_PSEUDO_IBSS;
329 return HFA384X_PORTTYPE_HOSTAP;
330}
331
332
333int hostap_set_encryption(local_info_t *local)
334{
335 u16 val, old_val;
336 int i, keylen, len, idx;
337 char keybuf[WEP_KEY_LEN + 1];
338 enum { NONE, WEP, OTHER } encrypt_type;
339
274bfb8d
JL
340 idx = local->crypt_info.tx_keyidx;
341 if (local->crypt_info.crypt[idx] == NULL ||
342 local->crypt_info.crypt[idx]->ops == NULL)
ff1d2767 343 encrypt_type = NONE;
274bfb8d 344 else if (strcmp(local->crypt_info.crypt[idx]->ops->name, "WEP") == 0)
ff1d2767
JM
345 encrypt_type = WEP;
346 else
347 encrypt_type = OTHER;
348
349 if (local->func->get_rid(local->dev, HFA384X_RID_CNFWEPFLAGS, &val, 2,
350 1) < 0) {
351 printk(KERN_DEBUG "Could not read current WEP flags.\n");
352 goto fail;
353 }
354 le16_to_cpus(&val);
355 old_val = val;
356
357 if (encrypt_type != NONE || local->privacy_invoked)
358 val |= HFA384X_WEPFLAGS_PRIVACYINVOKED;
359 else
360 val &= ~HFA384X_WEPFLAGS_PRIVACYINVOKED;
361
362 if (local->open_wep || encrypt_type == NONE ||
363 ((local->ieee_802_1x || local->wpa) && local->host_decrypt))
364 val &= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
365 else
366 val |= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
367
368 if ((encrypt_type != NONE || local->privacy_invoked) &&
369 (encrypt_type == OTHER || local->host_encrypt))
370 val |= HFA384X_WEPFLAGS_HOSTENCRYPT;
371 else
372 val &= ~HFA384X_WEPFLAGS_HOSTENCRYPT;
373 if ((encrypt_type != NONE || local->privacy_invoked) &&
374 (encrypt_type == OTHER || local->host_decrypt))
375 val |= HFA384X_WEPFLAGS_HOSTDECRYPT;
376 else
377 val &= ~HFA384X_WEPFLAGS_HOSTDECRYPT;
378
379 if (val != old_val &&
380 hostap_set_word(local->dev, HFA384X_RID_CNFWEPFLAGS, val)) {
381 printk(KERN_DEBUG "Could not write new WEP flags (0x%x)\n",
382 val);
383 goto fail;
384 }
385
386 if (encrypt_type != WEP)
387 return 0;
388
389 /* 104-bit support seems to require that all the keys are set to the
390 * same keylen */
391 keylen = 6; /* first 5 octets */
274bfb8d
JL
392 len = local->crypt_info.crypt[idx]->ops->get_key(keybuf, sizeof(keybuf), NULL,
393 local->crypt_info.crypt[idx]->priv);
ff1d2767
JM
394 if (idx >= 0 && idx < WEP_KEYS && len > 5)
395 keylen = WEP_KEY_LEN + 1; /* first 13 octets */
396
397 for (i = 0; i < WEP_KEYS; i++) {
398 memset(keybuf, 0, sizeof(keybuf));
274bfb8d
JL
399 if (local->crypt_info.crypt[i]) {
400 (void) local->crypt_info.crypt[i]->ops->get_key(
ff1d2767 401 keybuf, sizeof(keybuf),
274bfb8d 402 NULL, local->crypt_info.crypt[i]->priv);
ff1d2767
JM
403 }
404 if (local->func->set_rid(local->dev,
405 HFA384X_RID_CNFDEFAULTKEY0 + i,
406 keybuf, keylen)) {
407 printk(KERN_DEBUG "Could not set key %d (len=%d)\n",
408 i, keylen);
409 goto fail;
410 }
411 }
412 if (hostap_set_word(local->dev, HFA384X_RID_CNFWEPDEFAULTKEYID, idx)) {
413 printk(KERN_DEBUG "Could not set default keyid %d\n", idx);
414 goto fail;
415 }
416
417 return 0;
418
419 fail:
420 printk(KERN_DEBUG "%s: encryption setup failed\n", local->dev->name);
421 return -1;
422}
423
424
425int hostap_set_antsel(local_info_t *local)
426{
427 u16 val;
428 int ret = 0;
429
430 if (local->antsel_tx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
431 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
432 HFA386X_CR_TX_CONFIGURE,
433 NULL, &val) == 0) {
434 val &= ~(BIT(2) | BIT(1));
435 switch (local->antsel_tx) {
436 case HOSTAP_ANTSEL_DIVERSITY:
437 val |= BIT(1);
438 break;
439 case HOSTAP_ANTSEL_LOW:
440 break;
441 case HOSTAP_ANTSEL_HIGH:
442 val |= BIT(2);
443 break;
444 }
445
446 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
447 HFA386X_CR_TX_CONFIGURE, &val, NULL)) {
448 printk(KERN_INFO "%s: setting TX AntSel failed\n",
449 local->dev->name);
450 ret = -1;
451 }
452 }
453
454 if (local->antsel_rx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
455 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
456 HFA386X_CR_RX_CONFIGURE,
457 NULL, &val) == 0) {
458 val &= ~(BIT(1) | BIT(0));
459 switch (local->antsel_rx) {
460 case HOSTAP_ANTSEL_DIVERSITY:
461 break;
462 case HOSTAP_ANTSEL_LOW:
463 val |= BIT(0);
464 break;
465 case HOSTAP_ANTSEL_HIGH:
466 val |= BIT(0) | BIT(1);
467 break;
468 }
469
470 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
471 HFA386X_CR_RX_CONFIGURE, &val, NULL)) {
472 printk(KERN_INFO "%s: setting RX AntSel failed\n",
473 local->dev->name);
474 ret = -1;
475 }
476 }
477
478 return ret;
479}
480
481
482int hostap_set_roaming(local_info_t *local)
483{
484 u16 val;
485
486 switch (local->host_roaming) {
487 case 1:
488 val = HFA384X_ROAMING_HOST;
489 break;
490 case 2:
491 val = HFA384X_ROAMING_DISABLED;
492 break;
493 case 0:
494 default:
495 val = HFA384X_ROAMING_FIRMWARE;
496 break;
497 }
498
499 return hostap_set_word(local->dev, HFA384X_RID_CNFROAMINGMODE, val);
500}
501
502
503int hostap_set_auth_algs(local_info_t *local)
504{
505 int val = local->auth_algs;
506 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
507 * set to include both Open and Shared Key flags. It tries to use
508 * Shared Key authentication in that case even if WEP keys are not
509 * configured.. STA f/w v0.7.6 is able to handle such configuration,
510 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
511 if (local->sta_fw_ver < PRISM2_FW_VER(0,7,0) &&
512 val != PRISM2_AUTH_OPEN && val != PRISM2_AUTH_SHARED_KEY)
513 val = PRISM2_AUTH_OPEN;
514
515 if (hostap_set_word(local->dev, HFA384X_RID_CNFAUTHENTICATION, val)) {
516 printk(KERN_INFO "%s: cnfAuthentication setting to 0x%x "
517 "failed\n", local->dev->name, local->auth_algs);
518 return -EINVAL;
519 }
520
521 return 0;
522}
523
524
525void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
526{
527 u16 status, fc;
528
529 status = __le16_to_cpu(rx->status);
530
531 printk(KERN_DEBUG "%s: RX status=0x%04x (port=%d, type=%d, "
532 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
533 "jiffies=%ld\n",
534 name, status, (status >> 8) & 0x07, status >> 13, status & 1,
535 rx->silence, rx->signal, rx->rate, rx->rxflow, jiffies);
536
537 fc = __le16_to_cpu(rx->frame_control);
538 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
539 "data_len=%d%s%s\n",
1ea893fd
DW
540 fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
541 (fc & IEEE80211_FCTL_STYPE) >> 4,
ff1d2767
JM
542 __le16_to_cpu(rx->duration_id), __le16_to_cpu(rx->seq_ctrl),
543 __le16_to_cpu(rx->data_len),
b2f4a2e3
JM
544 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
545 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
ff1d2767 546
e174961c
JB
547 printk(KERN_DEBUG " A1=%pM A2=%pM A3=%pM A4=%pM\n",
548 rx->addr1, rx->addr2, rx->addr3, rx->addr4);
ff1d2767 549
e174961c
JB
550 printk(KERN_DEBUG " dst=%pM src=%pM len=%d\n",
551 rx->dst_addr, rx->src_addr,
ff1d2767
JM
552 __be16_to_cpu(rx->len));
553}
554
555
556void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
557{
558 u16 fc;
559
560 printk(KERN_DEBUG "%s: TX status=0x%04x retry_count=%d tx_rate=%d "
561 "tx_control=0x%04x; jiffies=%ld\n",
562 name, __le16_to_cpu(tx->status), tx->retry_count, tx->tx_rate,
563 __le16_to_cpu(tx->tx_control), jiffies);
564
565 fc = __le16_to_cpu(tx->frame_control);
566 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
567 "data_len=%d%s%s\n",
1ea893fd
DW
568 fc, (fc & IEEE80211_FCTL_FTYPE) >> 2,
569 (fc & IEEE80211_FCTL_STYPE) >> 4,
ff1d2767
JM
570 __le16_to_cpu(tx->duration_id), __le16_to_cpu(tx->seq_ctrl),
571 __le16_to_cpu(tx->data_len),
b2f4a2e3
JM
572 fc & IEEE80211_FCTL_TODS ? " [ToDS]" : "",
573 fc & IEEE80211_FCTL_FROMDS ? " [FromDS]" : "");
ff1d2767 574
e174961c
JB
575 printk(KERN_DEBUG " A1=%pM A2=%pM A3=%pM A4=%pM\n",
576 tx->addr1, tx->addr2, tx->addr3, tx->addr4);
ff1d2767 577
e174961c
JB
578 printk(KERN_DEBUG " dst=%pM src=%pM len=%d\n",
579 tx->dst_addr, tx->src_addr,
ff1d2767
JM
580 __be16_to_cpu(tx->len));
581}
582
583
1bcca3c4
PR
584static int hostap_80211_header_parse(const struct sk_buff *skb,
585 unsigned char *haddr)
ff1d2767 586{
b53a5dab 587 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
ff1d2767
JM
588 return ETH_ALEN;
589}
590
591
1ea893fd 592int hostap_80211_get_hdrlen(__le16 fc)
ff1d2767 593{
1ea893fd
DW
594 if (ieee80211_is_data(fc) && ieee80211_has_a4 (fc))
595 return 30; /* Addr4 */
596 else if (ieee80211_is_cts(fc) || ieee80211_is_ack(fc))
597 return 10;
598 else if (ieee80211_is_ctl(fc))
599 return 16;
600
601 return 24;
ff1d2767
JM
602}
603
604
ff1d2767
JM
605static int prism2_close(struct net_device *dev)
606{
607 struct hostap_interface *iface;
608 local_info_t *local;
609
610 PDEBUG(DEBUG_FLOW, "%s: prism2_close\n", dev->name);
611
612 iface = netdev_priv(dev);
613 local = iface->local;
614
615 if (dev == local->ddev) {
616 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
617 }
618#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
619 if (!local->hostapd && dev == local->dev &&
620 (!local->func->card_present || local->func->card_present(local)) &&
621 local->hw_ready && local->ap && local->iw_mode == IW_MODE_MASTER)
622 hostap_deauth_all_stas(dev, local->ap, 1);
623#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
624
ff1d2767
JM
625 if (dev == local->dev) {
626 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL);
627 }
628
629 if (netif_running(dev)) {
630 netif_stop_queue(dev);
631 netif_device_detach(dev);
632 }
633
4bb073c0
DM
634 cancel_work_sync(&local->reset_queue);
635 cancel_work_sync(&local->set_multicast_list_queue);
636 cancel_work_sync(&local->set_tim_queue);
637#ifndef PRISM2_NO_STATION_MODES
638 cancel_work_sync(&local->info_queue);
639#endif
640 cancel_work_sync(&local->comms_qual_update);
ff1d2767
JM
641
642 module_put(local->hw_module);
643
644 local->num_dev_open--;
645
646 if (dev != local->dev && local->dev->flags & IFF_UP &&
647 local->master_dev_auto_open && local->num_dev_open == 1) {
648 /* Close master radio interface automatically if it was also
649 * opened automatically and we are now closing the last
650 * remaining non-master device. */
651 dev_close(local->dev);
652 }
653
654 return 0;
655}
656
657
658static int prism2_open(struct net_device *dev)
659{
660 struct hostap_interface *iface;
661 local_info_t *local;
662
663 PDEBUG(DEBUG_FLOW, "%s: prism2_open\n", dev->name);
664
665 iface = netdev_priv(dev);
666 local = iface->local;
667
668 if (local->no_pri) {
669 printk(KERN_DEBUG "%s: could not set interface UP - no PRI "
670 "f/w\n", dev->name);
671 return 1;
672 }
673
674 if ((local->func->card_present && !local->func->card_present(local)) ||
675 local->hw_downloading)
676 return -ENODEV;
677
ff1d2767
JM
678 if (!try_module_get(local->hw_module))
679 return -ENODEV;
680 local->num_dev_open++;
681
682 if (!local->dev_enabled && local->func->hw_enable(dev, 1)) {
683 printk(KERN_WARNING "%s: could not enable MAC port\n",
684 dev->name);
685 prism2_close(dev);
686 return 1;
687 }
688 if (!local->dev_enabled)
689 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
690 local->dev_enabled = 1;
691
692 if (dev != local->dev && !(local->dev->flags & IFF_UP)) {
693 /* Master radio interface is needed for all operation, so open
694 * it automatically when any virtual net_device is opened. */
695 local->master_dev_auto_open = 1;
696 dev_open(local->dev);
697 }
698
699 netif_device_attach(dev);
700 netif_start_queue(dev);
701
702 return 0;
703}
704
705
706static int prism2_set_mac_address(struct net_device *dev, void *p)
707{
708 struct hostap_interface *iface;
709 local_info_t *local;
710 struct list_head *ptr;
711 struct sockaddr *addr = p;
712
713 iface = netdev_priv(dev);
714 local = iface->local;
715
716 if (local->func->set_rid(dev, HFA384X_RID_CNFOWNMACADDR, addr->sa_data,
717 ETH_ALEN) < 0 || local->func->reset_port(dev))
718 return -EINVAL;
719
720 read_lock_bh(&local->iface_lock);
721 list_for_each(ptr, &local->hostap_interfaces) {
722 iface = list_entry(ptr, struct hostap_interface, list);
723 memcpy(iface->dev->dev_addr, addr->sa_data, ETH_ALEN);
724 }
725 memcpy(local->dev->dev_addr, addr->sa_data, ETH_ALEN);
726 read_unlock_bh(&local->iface_lock);
727
728 return 0;
729}
730
731
732/* TODO: to be further implemented as soon as Prism2 fully supports
733 * GroupAddresses and correct documentation is available */
c4028958 734void hostap_set_multicast_list_queue(struct work_struct *work)
ff1d2767 735{
c4028958
DH
736 local_info_t *local =
737 container_of(work, local_info_t, set_multicast_list_queue);
738 struct net_device *dev = local->dev;
ff1d2767 739
ff1d2767
JM
740 if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
741 local->is_promisc)) {
742 printk(KERN_INFO "%s: %sabling promiscuous mode failed\n",
743 dev->name, local->is_promisc ? "en" : "dis");
744 }
745}
746
747
748static void hostap_set_multicast_list(struct net_device *dev)
749{
750#if 0
751 /* FIX: promiscuous mode seems to be causing a lot of problems with
752 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
753 * corrupted incoming frames). This code is now commented out while the
754 * problems are investigated. */
755 struct hostap_interface *iface;
756 local_info_t *local;
757
758 iface = netdev_priv(dev);
759 local = iface->local;
760 if ((dev->flags & IFF_ALLMULTI) || (dev->flags & IFF_PROMISC)) {
761 local->is_promisc = 1;
762 } else {
763 local->is_promisc = 0;
764 }
765
766 schedule_work(&local->set_multicast_list_queue);
767#endif
768}
769
770
771static int prism2_change_mtu(struct net_device *dev, int new_mtu)
772{
773 if (new_mtu < PRISM2_MIN_MTU || new_mtu > PRISM2_MAX_MTU)
774 return -EINVAL;
775
776 dev->mtu = new_mtu;
777 return 0;
778}
779
780
781static void prism2_tx_timeout(struct net_device *dev)
782{
783 struct hostap_interface *iface;
784 local_info_t *local;
785 struct hfa384x_regs regs;
786
787 iface = netdev_priv(dev);
788 local = iface->local;
789
790 printk(KERN_WARNING "%s Tx timed out! Resetting card\n", dev->name);
791 netif_stop_queue(local->dev);
792
793 local->func->read_regs(dev, &regs);
794 printk(KERN_DEBUG "%s: CMD=%04x EVSTAT=%04x "
795 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
796 dev->name, regs.cmd, regs.evstat, regs.offset0, regs.offset1,
797 regs.swsupport0);
798
799 local->func->schedule_reset(local);
800}
801
3b04ddde
SH
802const struct header_ops hostap_80211_ops = {
803 .create = eth_header,
804 .rebuild = eth_rebuild_header,
805 .cache = eth_header_cache,
806 .cache_update = eth_header_cache_update,
3b04ddde
SH
807 .parse = hostap_80211_header_parse,
808};
809EXPORT_SYMBOL(hostap_80211_ops);
ff1d2767 810
5ae4efbc
SH
811
812static const struct net_device_ops hostap_netdev_ops = {
813 .ndo_start_xmit = hostap_data_start_xmit,
814
815 .ndo_open = prism2_open,
816 .ndo_stop = prism2_close,
817 .ndo_do_ioctl = hostap_ioctl,
818 .ndo_set_mac_address = prism2_set_mac_address,
819 .ndo_set_multicast_list = hostap_set_multicast_list,
820 .ndo_change_mtu = prism2_change_mtu,
821 .ndo_tx_timeout = prism2_tx_timeout,
822 .ndo_validate_addr = eth_validate_addr,
823};
824
825static const struct net_device_ops hostap_mgmt_netdev_ops = {
826 .ndo_start_xmit = hostap_mgmt_start_xmit,
827
828 .ndo_open = prism2_open,
829 .ndo_stop = prism2_close,
830 .ndo_do_ioctl = hostap_ioctl,
831 .ndo_set_mac_address = prism2_set_mac_address,
832 .ndo_set_multicast_list = hostap_set_multicast_list,
833 .ndo_change_mtu = prism2_change_mtu,
834 .ndo_tx_timeout = prism2_tx_timeout,
835 .ndo_validate_addr = eth_validate_addr,
836};
837
838static const struct net_device_ops hostap_master_ops = {
839 .ndo_start_xmit = hostap_master_start_xmit,
840
841 .ndo_open = prism2_open,
842 .ndo_stop = prism2_close,
843 .ndo_do_ioctl = hostap_ioctl,
844 .ndo_set_mac_address = prism2_set_mac_address,
845 .ndo_set_multicast_list = hostap_set_multicast_list,
846 .ndo_change_mtu = prism2_change_mtu,
847 .ndo_tx_timeout = prism2_tx_timeout,
848 .ndo_validate_addr = eth_validate_addr,
849};
850
ff1d2767 851void hostap_setup_dev(struct net_device *dev, local_info_t *local,
09703f5e 852 int type)
ff1d2767
JM
853{
854 struct hostap_interface *iface;
855
856 iface = netdev_priv(dev);
857 ether_setup(dev);
858
859 /* kernel callbacks */
ff1d2767
JM
860 if (iface) {
861 /* Currently, we point to the proper spy_data only on
862 * the main_dev. This could be fixed. Jean II */
863 iface->wireless_data.spy_data = &iface->spy_data;
864 dev->wireless_data = &iface->wireless_data;
865 }
5ae4efbc 866 dev->wireless_handlers = &hostap_iw_handler_def;
ff1d2767
JM
867 dev->watchdog_timeo = TX_TIMEOUT;
868
5ae4efbc
SH
869 switch(type) {
870 case HOSTAP_INTERFACE_AP:
e484c16f 871 dev->tx_queue_len = 0; /* use main radio device queue */
5ae4efbc 872 dev->netdev_ops = &hostap_mgmt_netdev_ops;
09703f5e
DD
873 dev->type = ARPHRD_IEEE80211;
874 dev->header_ops = &hostap_80211_ops;
5ae4efbc
SH
875 break;
876 case HOSTAP_INTERFACE_MASTER:
5ae4efbc
SH
877 dev->netdev_ops = &hostap_master_ops;
878 break;
879 default:
e484c16f 880 dev->tx_queue_len = 0; /* use main radio device queue */
5ae4efbc 881 dev->netdev_ops = &hostap_netdev_ops;
09703f5e
DD
882 }
883
ff1d2767 884 dev->mtu = local->mtu;
5ae4efbc 885
ff1d2767
JM
886
887 SET_ETHTOOL_OPS(dev, &prism2_ethtool_ops);
888
ff1d2767
JM
889}
890
ff1d2767
JM
891static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked)
892{
893 struct net_device *dev = local->dev;
894
895 if (local->apdev)
896 return -EEXIST;
897
898 printk(KERN_DEBUG "%s: enabling hostapd mode\n", dev->name);
899
900 local->apdev = hostap_add_interface(local, HOSTAP_INTERFACE_AP,
901 rtnl_locked, local->ddev->name,
902 "ap");
903 if (local->apdev == NULL)
904 return -ENOMEM;
905
ff1d2767
JM
906 return 0;
907}
908
909
910static int hostap_disable_hostapd(local_info_t *local, int rtnl_locked)
911{
912 struct net_device *dev = local->dev;
913
914 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
915
916 hostap_remove_interface(local->apdev, rtnl_locked, 1);
917 local->apdev = NULL;
918
919 return 0;
920}
921
922
923static int hostap_enable_hostapd_sta(local_info_t *local, int rtnl_locked)
924{
925 struct net_device *dev = local->dev;
926
927 if (local->stadev)
928 return -EEXIST;
929
930 printk(KERN_DEBUG "%s: enabling hostapd STA mode\n", dev->name);
931
932 local->stadev = hostap_add_interface(local, HOSTAP_INTERFACE_STA,
933 rtnl_locked, local->ddev->name,
934 "sta");
935 if (local->stadev == NULL)
936 return -ENOMEM;
937
938 return 0;
939}
940
941
942static int hostap_disable_hostapd_sta(local_info_t *local, int rtnl_locked)
943{
944 struct net_device *dev = local->dev;
945
946 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
947
948 hostap_remove_interface(local->stadev, rtnl_locked, 1);
949 local->stadev = NULL;
950
951 return 0;
952}
953
954
955int hostap_set_hostapd(local_info_t *local, int val, int rtnl_locked)
956{
957 int ret;
958
959 if (val < 0 || val > 1)
960 return -EINVAL;
961
962 if (local->hostapd == val)
963 return 0;
964
965 if (val) {
966 ret = hostap_enable_hostapd(local, rtnl_locked);
967 if (ret == 0)
968 local->hostapd = 1;
969 } else {
970 local->hostapd = 0;
971 ret = hostap_disable_hostapd(local, rtnl_locked);
972 if (ret != 0)
973 local->hostapd = 1;
974 }
975
976 return ret;
977}
978
979
980int hostap_set_hostapd_sta(local_info_t *local, int val, int rtnl_locked)
981{
982 int ret;
983
984 if (val < 0 || val > 1)
985 return -EINVAL;
986
987 if (local->hostapd_sta == val)
988 return 0;
989
990 if (val) {
991 ret = hostap_enable_hostapd_sta(local, rtnl_locked);
992 if (ret == 0)
993 local->hostapd_sta = 1;
994 } else {
995 local->hostapd_sta = 0;
996 ret = hostap_disable_hostapd_sta(local, rtnl_locked);
997 if (ret != 0)
998 local->hostapd_sta = 1;
999 }
1000
1001
1002 return ret;
1003}
1004
1005
1006int prism2_update_comms_qual(struct net_device *dev)
1007{
1008 struct hostap_interface *iface;
1009 local_info_t *local;
1010 int ret = 0;
1011 struct hfa384x_comms_quality sq;
1012
1013 iface = netdev_priv(dev);
1014 local = iface->local;
1015 if (!local->sta_fw_ver)
1016 ret = -1;
1017 else if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1018 if (local->func->get_rid(local->dev,
1019 HFA384X_RID_DBMCOMMSQUALITY,
1020 &sq, sizeof(sq), 1) >= 0) {
1021 local->comms_qual = (s16) le16_to_cpu(sq.comm_qual);
1022 local->avg_signal = (s16) le16_to_cpu(sq.signal_level);
1023 local->avg_noise = (s16) le16_to_cpu(sq.noise_level);
1024 local->last_comms_qual_update = jiffies;
1025 } else
1026 ret = -1;
1027 } else {
1028 if (local->func->get_rid(local->dev, HFA384X_RID_COMMSQUALITY,
1029 &sq, sizeof(sq), 1) >= 0) {
1030 local->comms_qual = le16_to_cpu(sq.comm_qual);
1031 local->avg_signal = HFA384X_LEVEL_TO_dBm(
1032 le16_to_cpu(sq.signal_level));
1033 local->avg_noise = HFA384X_LEVEL_TO_dBm(
1034 le16_to_cpu(sq.noise_level));
1035 local->last_comms_qual_update = jiffies;
1036 } else
1037 ret = -1;
1038 }
1039
1040 return ret;
1041}
1042
1043
4339d328 1044int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u16 stype,
ff1d2767
JM
1045 u8 *body, size_t bodylen)
1046{
1047 struct sk_buff *skb;
1048 struct hostap_ieee80211_mgmt *mgmt;
1049 struct hostap_skb_tx_data *meta;
1050 struct net_device *dev = local->dev;
1051
1052 skb = dev_alloc_skb(IEEE80211_MGMT_HDR_LEN + bodylen);
1053 if (skb == NULL)
1054 return -ENOMEM;
1055
1056 mgmt = (struct hostap_ieee80211_mgmt *)
1057 skb_put(skb, IEEE80211_MGMT_HDR_LEN);
1058 memset(mgmt, 0, IEEE80211_MGMT_HDR_LEN);
4339d328 1059 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
ff1d2767
JM
1060 memcpy(mgmt->da, dst, ETH_ALEN);
1061 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1062 memcpy(mgmt->bssid, dst, ETH_ALEN);
1063 if (body)
1064 memcpy(skb_put(skb, bodylen), body, bodylen);
1065
1066 meta = (struct hostap_skb_tx_data *) skb->cb;
1067 memset(meta, 0, sizeof(*meta));
1068 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1069 meta->iface = netdev_priv(dev);
1070
1071 skb->dev = dev;
459a98ed 1072 skb_reset_mac_header(skb);
c1d2bbe1 1073 skb_reset_network_header(skb);
ff1d2767
JM
1074 dev_queue_xmit(skb);
1075
1076 return 0;
1077}
1078
1079
1080int prism2_sta_deauth(local_info_t *local, u16 reason)
1081{
1082 union iwreq_data wrqu;
1083 int ret;
8a9faf3c 1084 __le16 val = cpu_to_le16(reason);
ff1d2767
JM
1085
1086 if (local->iw_mode != IW_MODE_INFRA ||
1087 memcmp(local->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0 ||
1088 memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0)
1089 return 0;
1090
4339d328 1091 ret = prism2_sta_send_mgmt(local, local->bssid, IEEE80211_STYPE_DEAUTH,
8a9faf3c 1092 (u8 *) &val, 2);
ff1d2767
JM
1093 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1094 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
1095 return ret;
1096}
1097
1098
1099struct proc_dir_entry *hostap_proc;
1100
1101static int __init hostap_init(void)
1102{
457c4cbc
EB
1103 if (init_net.proc_net != NULL) {
1104 hostap_proc = proc_mkdir("hostap", init_net.proc_net);
ff1d2767
JM
1105 if (!hostap_proc)
1106 printk(KERN_WARNING "Failed to mkdir "
1107 "/proc/net/hostap\n");
1108 } else
1109 hostap_proc = NULL;
1110
1111 return 0;
1112}
1113
1114
1115static void __exit hostap_exit(void)
1116{
1117 if (hostap_proc != NULL) {
1118 hostap_proc = NULL;
457c4cbc 1119 remove_proc_entry("hostap", init_net.proc_net);
ff1d2767 1120 }
ff1d2767
JM
1121}
1122
1123
1124EXPORT_SYMBOL(hostap_set_word);
1125EXPORT_SYMBOL(hostap_set_string);
1126EXPORT_SYMBOL(hostap_get_porttype);
1127EXPORT_SYMBOL(hostap_set_encryption);
1128EXPORT_SYMBOL(hostap_set_antsel);
1129EXPORT_SYMBOL(hostap_set_roaming);
1130EXPORT_SYMBOL(hostap_set_auth_algs);
1131EXPORT_SYMBOL(hostap_dump_rx_header);
1132EXPORT_SYMBOL(hostap_dump_tx_header);
ff1d2767 1133EXPORT_SYMBOL(hostap_80211_get_hdrlen);
ff1d2767 1134EXPORT_SYMBOL(hostap_setup_dev);
ff1d2767
JM
1135EXPORT_SYMBOL(hostap_set_multicast_list_queue);
1136EXPORT_SYMBOL(hostap_set_hostapd);
1137EXPORT_SYMBOL(hostap_set_hostapd_sta);
1138EXPORT_SYMBOL(hostap_add_interface);
1139EXPORT_SYMBOL(hostap_remove_interface);
1140EXPORT_SYMBOL(prism2_update_comms_qual);
1141
1142module_init(hostap_init);
1143module_exit(hostap_exit);
This page took 1.081916 seconds and 5 git commands to generate.