2 * Host AP (software wireless LAN access point) driver for
3 * Intersil Prism2/2.5/3 - hostap.o module, common routines
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
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
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>
26 #include <linux/etherdevice.h>
27 #include <net/net_namespace.h>
28 #include <net/iw_handler.h>
29 #include <net/lib80211.h>
30 #include <asm/uaccess.h>
32 #include "hostap_wlan.h"
33 #include "hostap_80211.h"
34 #include "hostap_ap.h"
37 MODULE_AUTHOR("Jouni Malinen");
38 MODULE_DESCRIPTION("Host AP common routines");
39 MODULE_LICENSE("GPL");
41 #define TX_TIMEOUT (2 * HZ)
43 #define PRISM2_MAX_FRAME_SIZE 2304
44 #define PRISM2_MIN_MTU 256
46 #define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 /* LLC */ + 8 /* WEP */))
49 struct net_device
* hostap_add_interface(struct local_info
*local
,
50 int type
, int rtnl_locked
,
54 struct net_device
*dev
, *mdev
;
55 struct hostap_interface
*iface
;
58 dev
= alloc_etherdev(sizeof(struct hostap_interface
));
62 iface
= netdev_priv(dev
);
66 list_add(&iface
->list
, &local
->hostap_interfaces
);
69 eth_hw_addr_inherit(dev
, mdev
);
70 dev
->base_addr
= mdev
->base_addr
;
72 dev
->mem_start
= mdev
->mem_start
;
73 dev
->mem_end
= mdev
->mem_end
;
75 hostap_setup_dev(dev
, local
, type
);
76 dev
->destructor
= free_netdev
;
78 sprintf(dev
->name
, "%s%s", prefix
, name
);
82 SET_NETDEV_DEV(dev
, mdev
->dev
.parent
);
83 ret
= register_netdevice(dev
);
89 printk(KERN_WARNING
"%s: failed to add new netdevice!\n",
95 printk(KERN_DEBUG
"%s: registered netdevice %s\n",
96 mdev
->name
, dev
->name
);
102 void hostap_remove_interface(struct net_device
*dev
, int rtnl_locked
,
103 int remove_from_list
)
105 struct hostap_interface
*iface
;
110 iface
= netdev_priv(dev
);
112 if (remove_from_list
) {
113 list_del(&iface
->list
);
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
;
124 unregister_netdevice(dev
);
126 unregister_netdev(dev
);
128 /* dev->destructor = free_netdev() will free the device data, including
129 * private data, when removing the device */
133 static inline int prism2_wds_special_addr(u8
*addr
)
135 if (addr
[0] || addr
[1] || addr
[2] || addr
[3] || addr
[4] || addr
[5])
142 int prism2_wds_add(local_info_t
*local
, u8
*remote_addr
,
145 struct net_device
*dev
;
146 struct list_head
*ptr
;
147 struct hostap_interface
*iface
, *empty
, *match
;
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
)
156 if (prism2_wds_special_addr(iface
->u
.wds
.remote_addr
))
158 else if (memcmp(iface
->u
.wds
.remote_addr
, remote_addr
,
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
);
172 read_unlock_bh(&local
->iface_lock
);
174 if (!prism2_wds_special_addr(remote_addr
)) {
177 hostap_add_sta(local
->ap
, remote_addr
);
180 if (local
->wds_connections
>= local
->wds_max_connections
)
183 /* verify that there is room for wds# postfix in the interface name */
184 if (strlen(local
->dev
->name
) >= IFNAMSIZ
- 5) {
185 printk(KERN_DEBUG
"'%s' too long base device name\n",
190 dev
= hostap_add_interface(local
, HOSTAP_INTERFACE_WDS
, rtnl_locked
,
191 local
->ddev
->name
, "wds%d");
195 iface
= netdev_priv(dev
);
196 memcpy(iface
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
198 local
->wds_connections
++;
204 int prism2_wds_del(local_info_t
*local
, u8
*remote_addr
,
205 int rtnl_locked
, int do_not_remove
)
208 struct list_head
*ptr
;
209 struct hostap_interface
*iface
, *selected
= NULL
;
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
)
217 if (memcmp(iface
->u
.wds
.remote_addr
, remote_addr
,
223 if (selected
&& !do_not_remove
)
224 list_del(&selected
->list
);
225 write_unlock_irqrestore(&local
->iface_lock
, flags
);
229 memset(selected
->u
.wds
.remote_addr
, 0, ETH_ALEN
);
231 hostap_remove_interface(selected
->dev
, rtnl_locked
, 0);
232 local
->wds_connections
--;
236 return selected
? 0 : -ENODEV
;
240 u16
hostap_tx_callback_register(local_info_t
*local
,
241 void (*func
)(struct sk_buff
*, int ok
, void *),
245 struct hostap_tx_callback_info
*entry
;
247 entry
= kmalloc(sizeof(*entry
), GFP_KERNEL
);
254 spin_lock_irqsave(&local
->lock
, flags
);
255 entry
->idx
= local
->tx_callback
? local
->tx_callback
->idx
+ 1 : 1;
256 entry
->next
= local
->tx_callback
;
257 local
->tx_callback
= entry
;
258 spin_unlock_irqrestore(&local
->lock
, flags
);
264 int hostap_tx_callback_unregister(local_info_t
*local
, u16 idx
)
267 struct hostap_tx_callback_info
*cb
, *prev
= NULL
;
269 spin_lock_irqsave(&local
->lock
, flags
);
270 cb
= local
->tx_callback
;
271 while (cb
!= NULL
&& cb
->idx
!= idx
) {
277 local
->tx_callback
= cb
->next
;
279 prev
->next
= cb
->next
;
282 spin_unlock_irqrestore(&local
->lock
, flags
);
288 /* val is in host byte order */
289 int hostap_set_word(struct net_device
*dev
, int rid
, u16 val
)
291 struct hostap_interface
*iface
;
292 __le16 tmp
= cpu_to_le16(val
);
293 iface
= netdev_priv(dev
);
294 return iface
->local
->func
->set_rid(dev
, rid
, &tmp
, 2);
298 int hostap_set_string(struct net_device
*dev
, int rid
, const char *val
)
300 struct hostap_interface
*iface
;
301 char buf
[MAX_SSID_LEN
+ 2];
304 iface
= netdev_priv(dev
);
306 if (len
> MAX_SSID_LEN
)
308 memset(buf
, 0, sizeof(buf
));
309 buf
[0] = len
; /* little endian 16 bit word */
310 memcpy(buf
+ 2, val
, len
);
312 return iface
->local
->func
->set_rid(dev
, rid
, &buf
, MAX_SSID_LEN
+ 2);
316 u16
hostap_get_porttype(local_info_t
*local
)
318 if (local
->iw_mode
== IW_MODE_ADHOC
&& local
->pseudo_adhoc
)
319 return HFA384X_PORTTYPE_PSEUDO_IBSS
;
320 if (local
->iw_mode
== IW_MODE_ADHOC
)
321 return HFA384X_PORTTYPE_IBSS
;
322 if (local
->iw_mode
== IW_MODE_INFRA
)
323 return HFA384X_PORTTYPE_BSS
;
324 if (local
->iw_mode
== IW_MODE_REPEAT
)
325 return HFA384X_PORTTYPE_WDS
;
326 if (local
->iw_mode
== IW_MODE_MONITOR
)
327 return HFA384X_PORTTYPE_PSEUDO_IBSS
;
328 return HFA384X_PORTTYPE_HOSTAP
;
332 int hostap_set_encryption(local_info_t
*local
)
335 int i
, keylen
, len
, idx
;
336 char keybuf
[WEP_KEY_LEN
+ 1];
337 enum { NONE
, WEP
, OTHER
} encrypt_type
;
339 idx
= local
->crypt_info
.tx_keyidx
;
340 if (local
->crypt_info
.crypt
[idx
] == NULL
||
341 local
->crypt_info
.crypt
[idx
]->ops
== NULL
)
343 else if (strcmp(local
->crypt_info
.crypt
[idx
]->ops
->name
, "WEP") == 0)
346 encrypt_type
= OTHER
;
348 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_CNFWEPFLAGS
, &val
, 2,
350 printk(KERN_DEBUG
"Could not read current WEP flags.\n");
356 if (encrypt_type
!= NONE
|| local
->privacy_invoked
)
357 val
|= HFA384X_WEPFLAGS_PRIVACYINVOKED
;
359 val
&= ~HFA384X_WEPFLAGS_PRIVACYINVOKED
;
361 if (local
->open_wep
|| encrypt_type
== NONE
||
362 ((local
->ieee_802_1x
|| local
->wpa
) && local
->host_decrypt
))
363 val
&= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED
;
365 val
|= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED
;
367 if ((encrypt_type
!= NONE
|| local
->privacy_invoked
) &&
368 (encrypt_type
== OTHER
|| local
->host_encrypt
))
369 val
|= HFA384X_WEPFLAGS_HOSTENCRYPT
;
371 val
&= ~HFA384X_WEPFLAGS_HOSTENCRYPT
;
372 if ((encrypt_type
!= NONE
|| local
->privacy_invoked
) &&
373 (encrypt_type
== OTHER
|| local
->host_decrypt
))
374 val
|= HFA384X_WEPFLAGS_HOSTDECRYPT
;
376 val
&= ~HFA384X_WEPFLAGS_HOSTDECRYPT
;
378 if (val
!= old_val
&&
379 hostap_set_word(local
->dev
, HFA384X_RID_CNFWEPFLAGS
, val
)) {
380 printk(KERN_DEBUG
"Could not write new WEP flags (0x%x)\n",
385 if (encrypt_type
!= WEP
)
388 /* 104-bit support seems to require that all the keys are set to the
390 keylen
= 6; /* first 5 octets */
391 len
= local
->crypt_info
.crypt
[idx
]->ops
->get_key(keybuf
, sizeof(keybuf
), NULL
,
392 local
->crypt_info
.crypt
[idx
]->priv
);
393 if (idx
>= 0 && idx
< WEP_KEYS
&& len
> 5)
394 keylen
= WEP_KEY_LEN
+ 1; /* first 13 octets */
396 for (i
= 0; i
< WEP_KEYS
; i
++) {
397 memset(keybuf
, 0, sizeof(keybuf
));
398 if (local
->crypt_info
.crypt
[i
]) {
399 (void) local
->crypt_info
.crypt
[i
]->ops
->get_key(
400 keybuf
, sizeof(keybuf
),
401 NULL
, local
->crypt_info
.crypt
[i
]->priv
);
403 if (local
->func
->set_rid(local
->dev
,
404 HFA384X_RID_CNFDEFAULTKEY0
+ i
,
406 printk(KERN_DEBUG
"Could not set key %d (len=%d)\n",
411 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFWEPDEFAULTKEYID
, idx
)) {
412 printk(KERN_DEBUG
"Could not set default keyid %d\n", idx
);
419 printk(KERN_DEBUG
"%s: encryption setup failed\n", local
->dev
->name
);
424 int hostap_set_antsel(local_info_t
*local
)
429 if (local
->antsel_tx
!= HOSTAP_ANTSEL_DO_NOT_TOUCH
&&
430 local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_READMIF
,
431 HFA386X_CR_TX_CONFIGURE
,
433 val
&= ~(BIT(2) | BIT(1));
434 switch (local
->antsel_tx
) {
435 case HOSTAP_ANTSEL_DIVERSITY
:
438 case HOSTAP_ANTSEL_LOW
:
440 case HOSTAP_ANTSEL_HIGH
:
445 if (local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_WRITEMIF
,
446 HFA386X_CR_TX_CONFIGURE
, &val
, NULL
)) {
447 printk(KERN_INFO
"%s: setting TX AntSel failed\n",
453 if (local
->antsel_rx
!= HOSTAP_ANTSEL_DO_NOT_TOUCH
&&
454 local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_READMIF
,
455 HFA386X_CR_RX_CONFIGURE
,
457 val
&= ~(BIT(1) | BIT(0));
458 switch (local
->antsel_rx
) {
459 case HOSTAP_ANTSEL_DIVERSITY
:
461 case HOSTAP_ANTSEL_LOW
:
464 case HOSTAP_ANTSEL_HIGH
:
465 val
|= BIT(0) | BIT(1);
469 if (local
->func
->cmd(local
->dev
, HFA384X_CMDCODE_WRITEMIF
,
470 HFA386X_CR_RX_CONFIGURE
, &val
, NULL
)) {
471 printk(KERN_INFO
"%s: setting RX AntSel failed\n",
481 int hostap_set_roaming(local_info_t
*local
)
485 switch (local
->host_roaming
) {
487 val
= HFA384X_ROAMING_HOST
;
490 val
= HFA384X_ROAMING_DISABLED
;
494 val
= HFA384X_ROAMING_FIRMWARE
;
498 return hostap_set_word(local
->dev
, HFA384X_RID_CNFROAMINGMODE
, val
);
502 int hostap_set_auth_algs(local_info_t
*local
)
504 int val
= local
->auth_algs
;
505 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
506 * set to include both Open and Shared Key flags. It tries to use
507 * Shared Key authentication in that case even if WEP keys are not
508 * configured.. STA f/w v0.7.6 is able to handle such configuration,
509 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
510 if (local
->sta_fw_ver
< PRISM2_FW_VER(0,7,0) &&
511 val
!= PRISM2_AUTH_OPEN
&& val
!= PRISM2_AUTH_SHARED_KEY
)
512 val
= PRISM2_AUTH_OPEN
;
514 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFAUTHENTICATION
, val
)) {
515 printk(KERN_INFO
"%s: cnfAuthentication setting to 0x%x "
516 "failed\n", local
->dev
->name
, local
->auth_algs
);
524 void hostap_dump_rx_header(const char *name
, const struct hfa384x_rx_frame
*rx
)
528 status
= __le16_to_cpu(rx
->status
);
530 printk(KERN_DEBUG
"%s: RX status=0x%04x (port=%d, type=%d, "
531 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
533 name
, status
, (status
>> 8) & 0x07, status
>> 13, status
& 1,
534 rx
->silence
, rx
->signal
, rx
->rate
, rx
->rxflow
, jiffies
);
536 fc
= __le16_to_cpu(rx
->frame_control
);
537 printk(KERN_DEBUG
" FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
539 fc
, (fc
& IEEE80211_FCTL_FTYPE
) >> 2,
540 (fc
& IEEE80211_FCTL_STYPE
) >> 4,
541 __le16_to_cpu(rx
->duration_id
), __le16_to_cpu(rx
->seq_ctrl
),
542 __le16_to_cpu(rx
->data_len
),
543 fc
& IEEE80211_FCTL_TODS
? " [ToDS]" : "",
544 fc
& IEEE80211_FCTL_FROMDS
? " [FromDS]" : "");
546 printk(KERN_DEBUG
" A1=%pM A2=%pM A3=%pM A4=%pM\n",
547 rx
->addr1
, rx
->addr2
, rx
->addr3
, rx
->addr4
);
549 printk(KERN_DEBUG
" dst=%pM src=%pM len=%d\n",
550 rx
->dst_addr
, rx
->src_addr
,
551 __be16_to_cpu(rx
->len
));
555 void hostap_dump_tx_header(const char *name
, const struct hfa384x_tx_frame
*tx
)
559 printk(KERN_DEBUG
"%s: TX status=0x%04x retry_count=%d tx_rate=%d "
560 "tx_control=0x%04x; jiffies=%ld\n",
561 name
, __le16_to_cpu(tx
->status
), tx
->retry_count
, tx
->tx_rate
,
562 __le16_to_cpu(tx
->tx_control
), jiffies
);
564 fc
= __le16_to_cpu(tx
->frame_control
);
565 printk(KERN_DEBUG
" FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
567 fc
, (fc
& IEEE80211_FCTL_FTYPE
) >> 2,
568 (fc
& IEEE80211_FCTL_STYPE
) >> 4,
569 __le16_to_cpu(tx
->duration_id
), __le16_to_cpu(tx
->seq_ctrl
),
570 __le16_to_cpu(tx
->data_len
),
571 fc
& IEEE80211_FCTL_TODS
? " [ToDS]" : "",
572 fc
& IEEE80211_FCTL_FROMDS
? " [FromDS]" : "");
574 printk(KERN_DEBUG
" A1=%pM A2=%pM A3=%pM A4=%pM\n",
575 tx
->addr1
, tx
->addr2
, tx
->addr3
, tx
->addr4
);
577 printk(KERN_DEBUG
" dst=%pM src=%pM len=%d\n",
578 tx
->dst_addr
, tx
->src_addr
,
579 __be16_to_cpu(tx
->len
));
583 static int hostap_80211_header_parse(const struct sk_buff
*skb
,
584 unsigned char *haddr
)
586 memcpy(haddr
, skb_mac_header(skb
) + 10, ETH_ALEN
); /* addr2 */
591 int hostap_80211_get_hdrlen(__le16 fc
)
593 if (ieee80211_is_data(fc
) && ieee80211_has_a4 (fc
))
594 return 30; /* Addr4 */
595 else if (ieee80211_is_cts(fc
) || ieee80211_is_ack(fc
))
597 else if (ieee80211_is_ctl(fc
))
604 static int prism2_close(struct net_device
*dev
)
606 struct hostap_interface
*iface
;
609 PDEBUG(DEBUG_FLOW
, "%s: prism2_close\n", dev
->name
);
611 iface
= netdev_priv(dev
);
612 local
= iface
->local
;
614 if (dev
== local
->ddev
) {
615 prism2_sta_deauth(local
, WLAN_REASON_DEAUTH_LEAVING
);
617 #ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
618 if (!local
->hostapd
&& dev
== local
->dev
&&
619 (!local
->func
->card_present
|| local
->func
->card_present(local
)) &&
620 local
->hw_ready
&& local
->ap
&& local
->iw_mode
== IW_MODE_MASTER
)
621 hostap_deauth_all_stas(dev
, local
->ap
, 1);
622 #endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
624 if (dev
== local
->dev
) {
625 local
->func
->hw_shutdown(dev
, HOSTAP_HW_ENABLE_CMDCOMPL
);
628 if (netif_running(dev
)) {
629 netif_stop_queue(dev
);
630 netif_device_detach(dev
);
633 cancel_work_sync(&local
->reset_queue
);
634 cancel_work_sync(&local
->set_multicast_list_queue
);
635 cancel_work_sync(&local
->set_tim_queue
);
636 #ifndef PRISM2_NO_STATION_MODES
637 cancel_work_sync(&local
->info_queue
);
639 cancel_work_sync(&local
->comms_qual_update
);
641 module_put(local
->hw_module
);
643 local
->num_dev_open
--;
645 if (dev
!= local
->dev
&& local
->dev
->flags
& IFF_UP
&&
646 local
->master_dev_auto_open
&& local
->num_dev_open
== 1) {
647 /* Close master radio interface automatically if it was also
648 * opened automatically and we are now closing the last
649 * remaining non-master device. */
650 dev_close(local
->dev
);
657 static int prism2_open(struct net_device
*dev
)
659 struct hostap_interface
*iface
;
662 PDEBUG(DEBUG_FLOW
, "%s: prism2_open\n", dev
->name
);
664 iface
= netdev_priv(dev
);
665 local
= iface
->local
;
668 printk(KERN_DEBUG
"%s: could not set interface UP - no PRI "
673 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
674 local
->hw_downloading
)
677 if (!try_module_get(local
->hw_module
))
679 local
->num_dev_open
++;
681 if (!local
->dev_enabled
&& local
->func
->hw_enable(dev
, 1)) {
682 printk(KERN_WARNING
"%s: could not enable MAC port\n",
687 if (!local
->dev_enabled
)
688 prism2_callback(local
, PRISM2_CALLBACK_ENABLE
);
689 local
->dev_enabled
= 1;
691 if (dev
!= local
->dev
&& !(local
->dev
->flags
& IFF_UP
)) {
692 /* Master radio interface is needed for all operation, so open
693 * it automatically when any virtual net_device is opened. */
694 local
->master_dev_auto_open
= 1;
695 dev_open(local
->dev
);
698 netif_device_attach(dev
);
699 netif_start_queue(dev
);
705 static int prism2_set_mac_address(struct net_device
*dev
, void *p
)
707 struct hostap_interface
*iface
;
709 struct list_head
*ptr
;
710 struct sockaddr
*addr
= p
;
712 iface
= netdev_priv(dev
);
713 local
= iface
->local
;
715 if (local
->func
->set_rid(dev
, HFA384X_RID_CNFOWNMACADDR
, addr
->sa_data
,
716 ETH_ALEN
) < 0 || local
->func
->reset_port(dev
))
719 read_lock_bh(&local
->iface_lock
);
720 list_for_each(ptr
, &local
->hostap_interfaces
) {
721 iface
= list_entry(ptr
, struct hostap_interface
, list
);
722 memcpy(iface
->dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
724 memcpy(local
->dev
->dev_addr
, addr
->sa_data
, ETH_ALEN
);
725 read_unlock_bh(&local
->iface_lock
);
731 /* TODO: to be further implemented as soon as Prism2 fully supports
732 * GroupAddresses and correct documentation is available */
733 void hostap_set_multicast_list_queue(struct work_struct
*work
)
735 local_info_t
*local
=
736 container_of(work
, local_info_t
, set_multicast_list_queue
);
737 struct net_device
*dev
= local
->dev
;
739 if (hostap_set_word(dev
, HFA384X_RID_PROMISCUOUSMODE
,
740 local
->is_promisc
)) {
741 printk(KERN_INFO
"%s: %sabling promiscuous mode failed\n",
742 dev
->name
, local
->is_promisc
? "en" : "dis");
747 static void hostap_set_multicast_list(struct net_device
*dev
)
750 /* FIX: promiscuous mode seems to be causing a lot of problems with
751 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
752 * corrupted incoming frames). This code is now commented out while the
753 * problems are investigated. */
754 struct hostap_interface
*iface
;
757 iface
= netdev_priv(dev
);
758 local
= iface
->local
;
759 if ((dev
->flags
& IFF_ALLMULTI
) || (dev
->flags
& IFF_PROMISC
)) {
760 local
->is_promisc
= 1;
762 local
->is_promisc
= 0;
765 schedule_work(&local
->set_multicast_list_queue
);
770 static int prism2_change_mtu(struct net_device
*dev
, int new_mtu
)
772 if (new_mtu
< PRISM2_MIN_MTU
|| new_mtu
> PRISM2_MAX_MTU
)
780 static void prism2_tx_timeout(struct net_device
*dev
)
782 struct hostap_interface
*iface
;
784 struct hfa384x_regs regs
;
786 iface
= netdev_priv(dev
);
787 local
= iface
->local
;
789 printk(KERN_WARNING
"%s Tx timed out! Resetting card\n", dev
->name
);
790 netif_stop_queue(local
->dev
);
792 local
->func
->read_regs(dev
, ®s
);
793 printk(KERN_DEBUG
"%s: CMD=%04x EVSTAT=%04x "
794 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
795 dev
->name
, regs
.cmd
, regs
.evstat
, regs
.offset0
, regs
.offset1
,
798 local
->func
->schedule_reset(local
);
801 const struct header_ops hostap_80211_ops
= {
802 .create
= eth_header
,
803 .rebuild
= eth_rebuild_header
,
804 .cache
= eth_header_cache
,
805 .cache_update
= eth_header_cache_update
,
806 .parse
= hostap_80211_header_parse
,
808 EXPORT_SYMBOL(hostap_80211_ops
);
811 static const struct net_device_ops hostap_netdev_ops
= {
812 .ndo_start_xmit
= hostap_data_start_xmit
,
814 .ndo_open
= prism2_open
,
815 .ndo_stop
= prism2_close
,
816 .ndo_do_ioctl
= hostap_ioctl
,
817 .ndo_set_mac_address
= prism2_set_mac_address
,
818 .ndo_set_rx_mode
= hostap_set_multicast_list
,
819 .ndo_change_mtu
= prism2_change_mtu
,
820 .ndo_tx_timeout
= prism2_tx_timeout
,
821 .ndo_validate_addr
= eth_validate_addr
,
824 static const struct net_device_ops hostap_mgmt_netdev_ops
= {
825 .ndo_start_xmit
= hostap_mgmt_start_xmit
,
827 .ndo_open
= prism2_open
,
828 .ndo_stop
= prism2_close
,
829 .ndo_do_ioctl
= hostap_ioctl
,
830 .ndo_set_mac_address
= prism2_set_mac_address
,
831 .ndo_set_rx_mode
= hostap_set_multicast_list
,
832 .ndo_change_mtu
= prism2_change_mtu
,
833 .ndo_tx_timeout
= prism2_tx_timeout
,
834 .ndo_validate_addr
= eth_validate_addr
,
837 static const struct net_device_ops hostap_master_ops
= {
838 .ndo_start_xmit
= hostap_master_start_xmit
,
840 .ndo_open
= prism2_open
,
841 .ndo_stop
= prism2_close
,
842 .ndo_do_ioctl
= hostap_ioctl
,
843 .ndo_set_mac_address
= prism2_set_mac_address
,
844 .ndo_set_rx_mode
= hostap_set_multicast_list
,
845 .ndo_change_mtu
= prism2_change_mtu
,
846 .ndo_tx_timeout
= prism2_tx_timeout
,
847 .ndo_validate_addr
= eth_validate_addr
,
850 void hostap_setup_dev(struct net_device
*dev
, local_info_t
*local
,
853 struct hostap_interface
*iface
;
855 iface
= netdev_priv(dev
);
857 dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
859 /* kernel callbacks */
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
;
866 dev
->wireless_handlers
= &hostap_iw_handler_def
;
867 dev
->watchdog_timeo
= TX_TIMEOUT
;
870 case HOSTAP_INTERFACE_AP
:
871 dev
->tx_queue_len
= 0; /* use main radio device queue */
872 dev
->netdev_ops
= &hostap_mgmt_netdev_ops
;
873 dev
->type
= ARPHRD_IEEE80211
;
874 dev
->header_ops
= &hostap_80211_ops
;
876 case HOSTAP_INTERFACE_MASTER
:
877 dev
->netdev_ops
= &hostap_master_ops
;
880 dev
->tx_queue_len
= 0; /* use main radio device queue */
881 dev
->netdev_ops
= &hostap_netdev_ops
;
884 dev
->mtu
= local
->mtu
;
887 SET_ETHTOOL_OPS(dev
, &prism2_ethtool_ops
);
891 static int hostap_enable_hostapd(local_info_t
*local
, int rtnl_locked
)
893 struct net_device
*dev
= local
->dev
;
898 printk(KERN_DEBUG
"%s: enabling hostapd mode\n", dev
->name
);
900 local
->apdev
= hostap_add_interface(local
, HOSTAP_INTERFACE_AP
,
901 rtnl_locked
, local
->ddev
->name
,
903 if (local
->apdev
== NULL
)
910 static int hostap_disable_hostapd(local_info_t
*local
, int rtnl_locked
)
912 struct net_device
*dev
= local
->dev
;
914 printk(KERN_DEBUG
"%s: disabling hostapd mode\n", dev
->name
);
916 hostap_remove_interface(local
->apdev
, rtnl_locked
, 1);
923 static int hostap_enable_hostapd_sta(local_info_t
*local
, int rtnl_locked
)
925 struct net_device
*dev
= local
->dev
;
930 printk(KERN_DEBUG
"%s: enabling hostapd STA mode\n", dev
->name
);
932 local
->stadev
= hostap_add_interface(local
, HOSTAP_INTERFACE_STA
,
933 rtnl_locked
, local
->ddev
->name
,
935 if (local
->stadev
== NULL
)
942 static int hostap_disable_hostapd_sta(local_info_t
*local
, int rtnl_locked
)
944 struct net_device
*dev
= local
->dev
;
946 printk(KERN_DEBUG
"%s: disabling hostapd mode\n", dev
->name
);
948 hostap_remove_interface(local
->stadev
, rtnl_locked
, 1);
949 local
->stadev
= NULL
;
955 int hostap_set_hostapd(local_info_t
*local
, int val
, int rtnl_locked
)
959 if (val
< 0 || val
> 1)
962 if (local
->hostapd
== val
)
966 ret
= hostap_enable_hostapd(local
, rtnl_locked
);
971 ret
= hostap_disable_hostapd(local
, rtnl_locked
);
980 int hostap_set_hostapd_sta(local_info_t
*local
, int val
, int rtnl_locked
)
984 if (val
< 0 || val
> 1)
987 if (local
->hostapd_sta
== val
)
991 ret
= hostap_enable_hostapd_sta(local
, rtnl_locked
);
993 local
->hostapd_sta
= 1;
995 local
->hostapd_sta
= 0;
996 ret
= hostap_disable_hostapd_sta(local
, rtnl_locked
);
998 local
->hostapd_sta
= 1;
1006 int prism2_update_comms_qual(struct net_device
*dev
)
1008 struct hostap_interface
*iface
;
1009 local_info_t
*local
;
1011 struct hfa384x_comms_quality sq
;
1013 iface
= netdev_priv(dev
);
1014 local
= iface
->local
;
1015 if (!local
->sta_fw_ver
)
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
;
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
;
1044 int prism2_sta_send_mgmt(local_info_t
*local
, u8
*dst
, u16 stype
,
1045 u8
*body
, size_t bodylen
)
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
;
1052 skb
= dev_alloc_skb(IEEE80211_MGMT_HDR_LEN
+ bodylen
);
1056 mgmt
= (struct hostap_ieee80211_mgmt
*)
1057 skb_put(skb
, IEEE80211_MGMT_HDR_LEN
);
1058 memset(mgmt
, 0, IEEE80211_MGMT_HDR_LEN
);
1059 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
| stype
);
1060 memcpy(mgmt
->da
, dst
, ETH_ALEN
);
1061 memcpy(mgmt
->sa
, dev
->dev_addr
, ETH_ALEN
);
1062 memcpy(mgmt
->bssid
, dst
, ETH_ALEN
);
1064 memcpy(skb_put(skb
, bodylen
), body
, bodylen
);
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
);
1072 skb_reset_mac_header(skb
);
1073 skb_reset_network_header(skb
);
1074 dev_queue_xmit(skb
);
1080 int prism2_sta_deauth(local_info_t
*local
, u16 reason
)
1082 union iwreq_data wrqu
;
1084 __le16 val
= cpu_to_le16(reason
);
1086 if (local
->iw_mode
!= IW_MODE_INFRA
||
1087 is_zero_ether_addr(local
->bssid
) ||
1088 memcmp(local
->bssid
, "\x44\x44\x44\x44\x44\x44", ETH_ALEN
) == 0)
1091 ret
= prism2_sta_send_mgmt(local
, local
->bssid
, IEEE80211_STYPE_DEAUTH
,
1093 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
1094 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1099 struct proc_dir_entry
*hostap_proc
;
1101 static int __init
hostap_init(void)
1103 if (init_net
.proc_net
!= NULL
) {
1104 hostap_proc
= proc_mkdir("hostap", init_net
.proc_net
);
1106 printk(KERN_WARNING
"Failed to mkdir "
1107 "/proc/net/hostap\n");
1115 static void __exit
hostap_exit(void)
1117 if (hostap_proc
!= NULL
) {
1119 remove_proc_entry("hostap", init_net
.proc_net
);
1124 EXPORT_SYMBOL(hostap_set_word
);
1125 EXPORT_SYMBOL(hostap_set_string
);
1126 EXPORT_SYMBOL(hostap_get_porttype
);
1127 EXPORT_SYMBOL(hostap_set_encryption
);
1128 EXPORT_SYMBOL(hostap_set_antsel
);
1129 EXPORT_SYMBOL(hostap_set_roaming
);
1130 EXPORT_SYMBOL(hostap_set_auth_algs
);
1131 EXPORT_SYMBOL(hostap_dump_rx_header
);
1132 EXPORT_SYMBOL(hostap_dump_tx_header
);
1133 EXPORT_SYMBOL(hostap_80211_get_hdrlen
);
1134 EXPORT_SYMBOL(hostap_setup_dev
);
1135 EXPORT_SYMBOL(hostap_set_multicast_list_queue
);
1136 EXPORT_SYMBOL(hostap_set_hostapd
);
1137 EXPORT_SYMBOL(hostap_set_hostapd_sta
);
1138 EXPORT_SYMBOL(hostap_add_interface
);
1139 EXPORT_SYMBOL(hostap_remove_interface
);
1140 EXPORT_SYMBOL(prism2_update_comms_qual
);
1142 module_init(hostap_init
);
1143 module_exit(hostap_exit
);